Input:
def main():

    s = int(input())

    mod = 10**9 + 7

    dp = [0] * (s+1)

    dp[0] = 1

    for i in range(1, s+1):

        for j in range(0, (i-3)+1):

            dp[i] += dp[j]

            dp[i] %= mod

    print((dp[-1]))

if __name__ == "__main__":

    main()

def main():

    s = int(input())

    mod = 10**9 + 7

    dp = [0] * (s+1)

    dp[0] = 1

#    for i in range(1, s+1):

#        for j in range(0, (i-3)+1):

#            dp[i] += dp[j]

#            dp[i] %= mod

    for i in range(1, s+1):

        if i < 3:

            dp[i] = 0

        else:

            dp[i] = dp[i-1] + dp[i-3]

            dp[i] %= mod

    print((dp[-1]))

if __name__ == "__main__":

    main()

def main():
    s = int(input())
    mod = 10**9 + 7
    dp = [0] * (s + 1)
    dp[0] = 1
    for i in range(1, s + 1):
        for j in range(0, (i - 3) + 1):
            dp[i] += dp[j]
            dp[i] %= mod
    print((dp[-1]))

if __name__ == "__main__":
    main()

def main():
    s = int(input())
    mod = 10**9 + 7
    dp = [0] * (s + 1)
    dp[0] = 1
    #    for i in range(1, s+1):
    #        for j in range(0, (i-3)+1):
    #            dp[i] += dp[j]
    #            dp[i] %= mod
    for i in range(1, s + 1):
        if i < 3:
            dp[i] = 0
        else:
            dp[i] = dp[i - 1] + dp[i - 3]
            dp[i] %= mod
    print((dp[-1]))

if __name__ == "__main__":
    main()

-        for j in range(0, (i - 3) + 1):


Input:
# temp

n,w = list(map(int,input().split()))

wv = [tuple(map(int,input().split())) for i in range(n)]

dp = [0] + [float("inf")]*(10**5)

for i in range(n):

    for j in range(10**5,wv[i][1]-1,-1):

        dp[j] = min(dp[j],dp[j-wv[i][1]]+wv[i][0])

res = 0

for v,e in enumerate(dp):

    if e <= w:

        res = v

print(res)

# dpE - Knapsack 2

import sys

input = sys.stdin.readline

def main():

    n, W = tuple(map(int, input().rstrip().split()))

    A = tuple(tuple(map(int, input().rstrip().split())) for _ in range(n))

    _, v = list(zip(*A))

    lim = sum(v)

    dp = [0] + [float("inf")] * lim

    for i in range(n):

        for j in range(lim, A[i][1] - 1, -1):

            dp[j] = min(dp[j], dp[j - A[i][1]] + A[i][0])

    ans = max(v for v, w in enumerate(dp) if w <= W)

    print(ans)

if __name__ == "__main__":

    main()

# temp
n, w = list(map(int, input().split()))
wv = [tuple(map(int, input().split())) for i in range(n)]
dp = [0] + [float("inf")] * (10**5)
for i in range(n):
    for j in range(10**5, wv[i][1] - 1, -1):
        dp[j] = min(dp[j], dp[j - wv[i][1]] + wv[i][0])
res = 0
for v, e in enumerate(dp):
    if e <= w:
        res = v
print(res)

-wv = [tuple(map(int, input().split())) for i in range(n)]

+    n, W = tuple(map(int, input().rstrip().split()))

+    A = tuple(tuple(map(int, input().rstrip().split())) for _ in range(n))

+        for j in range(lim, A[i][1] - 1, -1):

+    ans = max(v for v, w in enumerate(dp) if w <= W)


Input:
# 2019-11-12 22:21:08(JST)

import sys

# import collections

# import math

# from string import ascii_lowercase, ascii_uppercase, digits

# from bisect import bisect_left as bi_l, bisect_right as bi_r

import itertools

# from functools import reduce

# import operator as op

# from scipy.misc import comb # float

# import numpy as np

def main():

    s = sys.stdin.readline().rstrip()

    all_words = []

    for i in range(1, len(s) + 1):

        for letters in itertools.product('ATCG', repeat=i):

            word = ''.join(letters)

            all_words.append(word)

    for i in range(len(all_words)-1, 0-1, -1):

        if all_words[i] in s:

            print((len(all_words[i])))

            sys.exit()

    print((0))

if __name__ == "__main__":

    main()

# 2019-11-12 22:21:08(JST)

import sys

# import collections

# import math

# from string import ascii_lowercase, ascii_uppercase, digits

# from bisect import bisect_left as bi_l, bisect_right as bi_r

# import itertools

# from functools import reduce

# import operator as op

# from scipy.misc import comb # float

# import numpy as np

def main():

    s = sys.stdin.readline().rstrip()

    permitted = 'ACGT'

    continuous_count = []

    count = 0

    for i in range(len(s)):

        char = s[i]

        if char in permitted:

            count += 1

        else:

            continuous_count.append(count)

            count = 0

        if i == len(s) - 1:

            continuous_count.append(count)

    if not continuous_count:

        print((len(s)))

    else:

        print((max(continuous_count)))

if __name__ == "__main__":

    main()

# 2019-11-12 22:21:08(JST)
import sys

# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
import itertools

# from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np
def main():
    s = sys.stdin.readline().rstrip()
    all_words = []
    for i in range(1, len(s) + 1):
        for letters in itertools.product("ATCG", repeat=i):
            word = "".join(letters)
            all_words.append(word)
    for i in range(len(all_words) - 1, 0 - 1, -1):
        if all_words[i] in s:
            print((len(all_words[i])))
            sys.exit()
    print((0))

if __name__ == "__main__":
    main()

# 2019-11-12 22:21:08(JST)
import sys

# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np
def main():
    s = sys.stdin.readline().rstrip()
    permitted = "ACGT"
    continuous_count = []
    count = 0
    for i in range(len(s)):
        char = s[i]
        if char in permitted:
            count += 1
        else:
            continuous_count.append(count)
            count = 0
        if i == len(s) - 1:
            continuous_count.append(count)
    if not continuous_count:
        print((len(s)))
    else:
        print((max(continuous_count)))

if __name__ == "__main__":
    main()

-        for letters in itertools.product("ATCG", repeat=i):

-    for i in range(len(all_words) - 1, 0 - 1, -1):

+            continuous_count.append(count)

+            continuous_count.append(count)


Input:
n=int(input())

a=[list(map(int,input().split()))for _ in range(n)]

def f():

 for i in range(n-1):

  d=a[i][:];d[3],d[4]=d[4],d[3]

  for j in range(i+1,n):

   e=a[j][:];e[3],e[4]=e[4],e[3]

   for p in([0,1,2,3,4,5],[1,5,2,0,4,3],[2,1,5,3,0,4],[3,0,2,5,4,1],[4,1,0,3,5,2],[5,1,4,3,2,0]):

    f=[d[k]for k in p]

    if f[0]==e[0]and f[5]==e[5]:

     f=f[1:5]*2

     for k in range(4):

      if f[k:k+4]==e[1:5]:return'No'

 return'Yes'

print((f()))

-a = [list(map(int, input().split())) for _ in range(n)]

+a = [[int(s) for s in input().split()] for _ in range(n)]


Input:
N = int(input())

S = list(map(int, input().split()))

Q = int(input())

T = list(map(int, input().split()))

def binary_search(target_num, head, tail):

    idx = int((head+tail)/2)

    if target_num == S[idx]:

        return True

    elif target_num < S[idx]:

        if head == idx:

            return False

        return binary_search(target_num, head, idx-1)

    else:

        if tail == idx:

            return False

        return binary_search(target_num, idx+1, tail)

match_count = 0

for target_num in T:

    if binary_search(target_num, 0, len(S)-1):

        match_count += 1

print((str(match_count)))

N = int(input())

S = list(map(int, input().split()))

Q = int(input())

T = list(map(int, input().split()))

def binary_search(target_num, head, tail):

    while head <= tail:

        idx = int((head+tail)/2)

        if target_num == S[idx]:

            return True

        elif target_num < S[idx]:

            tail = idx - 1

        else:

            head = idx + 1

    return False

match_count = 0

for target_num in T:

    if binary_search(target_num, 0, len(S)-1):

        match_count += 1

print((str(match_count)))

N = int(input())
S = list(map(int, input().split()))
Q = int(input())
T = list(map(int, input().split()))

def binary_search(target_num, head, tail):
    idx = int((head + tail) / 2)
    if target_num == S[idx]:
        return True
    elif target_num < S[idx]:
        if head == idx:
            return False
        return binary_search(target_num, head, idx - 1)
    else:
        if tail == idx:
            return False
        return binary_search(target_num, idx + 1, tail)

match_count = 0
for target_num in T:
    if binary_search(target_num, 0, len(S) - 1):
        match_count += 1
print((str(match_count)))

N = int(input())
S = list(map(int, input().split()))
Q = int(input())
T = list(map(int, input().split()))

def binary_search(target_num, head, tail):
    while head <= tail:
        idx = int((head + tail) / 2)
        if target_num == S[idx]:
            return True
        elif target_num < S[idx]:
            tail = idx - 1
        else:
            head = idx + 1
    return False

match_count = 0
for target_num in T:
    if binary_search(target_num, 0, len(S) - 1):
        match_count += 1
print((str(match_count)))

-        return binary_search(target_num, head, idx - 1)

-        return binary_search(target_num, idx + 1, tail)


Input:
import re

ptn = re.compile(r"(A|C|G|T)*")

S = input()

ans = 0

for i in range(len(S)):

  for j in range(len(S)):

    x = ptn.match(S[i:i+j+1]).group(0)

    if(x):

      ans = max(ans, len(x))

print(ans)

import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()

ni = lambda : int(ns())

na = lambda : list(map(int, stdin.readline().split()))

sys.setrecursionlimit(10 ** 7)

def check(In):

    return In != "A" and In != "C" and In != "G" and In != "T"

def main():

    s = ns()

    count = 0

    ans = 0

    for i in range(len(s)):

        if check(s[i]):

            count = 0

        else:

            count += 1

            ans = max(ans, count)

    print(ans)

if __name__ == '__main__':

    main()

import re

ptn = re.compile(r"(A|C|G|T)*")
S = input()
ans = 0
for i in range(len(S)):
    for j in range(len(S)):
        x = ptn.match(S[i : i + j + 1]).group(0)
        if x:
            ans = max(ans, len(x))
print(ans)

import sys

stdin = sys.stdin
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sys.setrecursionlimit(10**7)

def check(In):
    return In != "A" and In != "C" and In != "G" and In != "T"

def main():
    s = ns()
    count = 0
    ans = 0
    for i in range(len(s)):
        if check(s[i]):
            count = 0
        else:
            count += 1
            ans = max(ans, count)
    print(ans)

if __name__ == "__main__":
    main()

-        x = ptn.match(S[i : i + j + 1]).group(0)

+na = lambda: list(map(int, stdin.readline().split()))

+    return In != "A" and In != "C" and In != "G" and In != "T"


Input:
a, b, c, x, y = list(map(int, input().split()))

ab = c * 2

res = float("inf")

if a + b <= ab:

    res = x * a + y * b

else:

    if x == y:

        res = x * ab

    elif x > y:

        for i in range(y, x + 1):

            cost = i * ab + (x - i) * a

            res = min(res, cost)

    else:

        for i in range(x, y + 1):

            cost = i * ab + (y - i) * b

            res = min(res, cost)

print(res)

import sys

sys.setrecursionlimit(10 ** 7)

input = sys.stdin.readline

f_inf = float('inf')

mod = 10 ** 9 + 7

def resolve():

    a, b, c, x, y = list(map(int, input().split()))

    c *= 2

    if a + b > c:

        cost1 = max(x, y) * c

        cost2 = min(x, y) * c

        plus = ((y - x) * b) if x < y else (x - y) * a

        res = min(cost1, cost2 + plus)

    else:

        res = x * a + y * b

    print(res)

if __name__ == '__main__':

    resolve()

import sys

sys.setrecursionlimit(10**7)
input = sys.stdin.readline
f_inf = float("inf")
mod = 10**9 + 7

def resolve():
    a, b, c, x, y = list(map(int, input().split()))
    c *= 2
    if a + b > c:
        cost1 = max(x, y) * c
        cost2 = min(x, y) * c
        plus = ((y - x) * b) if x < y else (x - y) * a
        res = min(cost1, cost2 + plus)
    else:
        res = x * a + y * b
    print(res)

if __name__ == "__main__":
    resolve()

-a, b, c, x, y = list(map(int, input().split()))

-            cost = i * ab + (x - i) * a

+    a, b, c, x, y = list(map(int, input().split()))

+        plus = ((y - x) * b) if x < y else (x - y) * a

-            cost = i * ab + (y - i) * b


Input:
N, K = list(map(int, input().split()))

S = input()

nums = []

now = 1

cnt = 0

for i in range(N):

    if S[i] == str(now):

        cnt += 1

    else:

        nums.append(cnt)

        now = 1 - now

        cnt = 1

if cnt != 0:

    nums.append(cnt)

if len(nums) % 2 == 0:

    nums.append(0)

add = 2 * K + 1

ans = 0

left = 0

right = 0

tmp = 0

for i in range(0, len(nums), 2):

    next_left = i

    next_right = min(i + add, len(nums))

    while next_left > left:

        tmp -= nums[left]

        left += 1

    while next_right > right:

        tmp += nums[right]

        right += 1

    ans = max(ans, tmp)

print(ans)

N, K = list(map(int, input().split()))

S = input()

nums = []

now = 1

cnt = 0

for i in range(N):

    if S[i] == str(now):

        cnt += 1

    else:

        nums.append(cnt)

        now = 1 - now

        cnt = 1

if cnt != 0:

    nums.append(cnt)

if len(nums) % 2 == 0:

    nums.append(0)

csum = [0] * (len(nums) + 1)

for i in range(len(nums)):

    csum[i + 1] = csum[i] + nums[i]

add = 2 * K + 1

ans = 0

tmp = 0

for i in range(0, len(nums), 2):

    left = i

    right = min(i + add, len(nums))

    tmp = csum[right] - csum[left]

    ans = max(ans, tmp)

print(ans)

-    next_right = min(i + add, len(nums))


Input:
from collections import Counter

def factorization(n) -> list:

	if n==1:

		return [1]

	ret = []

	i = 2

	while i*i<=n:

		while n%i==0:

			n //= i

			ret.append(i)

		i += 1

	if n!=1:

		ret.append(n)

	return ret

n,m = list(map(int,input().split()))

mod = 10**9+7

if m==1:

	print((1));exit()

factors = Counter(factorization(m))

mx = n+max(factors.values())

fac = [1]*(mx+1)

inv = [1]*(mx+1)

for i in range(1,mx+1):

	fac[i] = fac[i-1] * i % mod

inv[-1] = pow(fac[-1], mod - 2, mod)

for i in range(mx-1, -1, -1):

	inv[i] = inv[i+1] * (i+1) % mod

def cmb(n,r):

	assert n >= r >= 0

	return fac[n] * inv[n-r] * inv[r] % mod

ans=1

for v in list(factors.values()):

	ans*=cmb(n+v-1,v)

	ans%=mod

print(ans)

from collections import Counter

def factorization(n) -> list:

	if n==1:return [1]

	ret = []

	i = 2

	while i*i<=n:

		while n%i==0:

			n //= i

			ret.append(i)

		i += 1

	if n!=1:ret.append(n)

	return ret

from operator import mul

from functools import reduce

def cmb(n,r):

	if n < r:return 0

	r = min(n-r,r)

	if r==0:return 1

	u = reduce(mul, list(range(n, n-r, -1)))

	d = reduce(mul, list(range(1,r+1)))

	return u//d

def main():

	n,m = list(map(int,input().split()))

	mod = 10**9+7

	if m==1:

		print((1))

		exit()

	ans=1

	for v in list(Counter(factorization(m)).values()):

		ans*=cmb(n+v-1,v)

		ans%=mod

	print(ans)

if __name__=="__main__":main()

from collections import Counter

def factorization(n) -> list:
    if n == 1:
        return [1]
    ret = []
    i = 2
    while i * i <= n:
        while n % i == 0:
            n //= i
            ret.append(i)
        i += 1
    if n != 1:
        ret.append(n)
    return ret

n, m = list(map(int, input().split()))
mod = 10**9 + 7
if m == 1:
    print((1))
    exit()
factors = Counter(factorization(m))
mx = n + max(factors.values())
fac = [1] * (mx + 1)
inv = [1] * (mx + 1)
for i in range(1, mx + 1):
    fac[i] = fac[i - 1] * i % mod
inv[-1] = pow(fac[-1], mod - 2, mod)
for i in range(mx - 1, -1, -1):
    inv[i] = inv[i + 1] * (i + 1) % mod

def cmb(n, r):
    assert n >= r >= 0
    return fac[n] * inv[n - r] * inv[r] % mod

ans = 1
for v in list(factors.values()):
    ans *= cmb(n + v - 1, v)
    ans %= mod
print(ans)

from collections import Counter

def factorization(n) -> list:
    if n == 1:
        return [1]
    ret = []
    i = 2
    while i * i <= n:
        while n % i == 0:
            n //= i
            ret.append(i)
        i += 1
    if n != 1:
        ret.append(n)
    return ret

from operator import mul
from functools import reduce

def cmb(n, r):
    if n < r:
        return 0
    r = min(n - r, r)
    if r == 0:
        return 1
    u = reduce(mul, list(range(n, n - r, -1)))
    d = reduce(mul, list(range(1, r + 1)))
    return u // d

def main():
    n, m = list(map(int, input().split()))
    mod = 10**9 + 7
    if m == 1:
        print((1))
        exit()
    ans = 1
    for v in list(Counter(factorization(m)).values()):
        ans *= cmb(n + v - 1, v)
        ans %= mod
    print(ans)

if __name__ == "__main__":
    main()

-    return fac[n] * inv[n - r] * inv[r] % mod

+    u = reduce(mul, list(range(n, n - r, -1)))

+    d = reduce(mul, list(range(1, r + 1)))

+    n, m = list(map(int, input().split()))

+    for v in list(Counter(factorization(m)).values()):


Input:
s = input()

t = ""

while len(t) < len(s):

    target_len = len(s) - len(t)

    if s[len(t)] == 'd':

        if target_len == 5:

            t += "dream"

        elif target_len == 7:

            t += "dreamer"

        elif target_len > 7:

            if s[len(t) + 5] != 'd' and s[len(t) + 5:len(t) + 7 + 1] != "era":

                t += "dreamer"

            else:

                t += "dream"

        else:

            break

    else:

        if target_len == 5:

            t += "erase"

        elif target_len == 6:

            t += "eraser"

        elif target_len > 6:

            if s[len(t) + 5] != 'd' and s[len(t) + 5:len(t) + 6 + 2] != "era":

                t += "eraser"

            else:

                t += "erase"

        else:

            break

    if s[0:len(t)] != t:

        break

print(("YES" if s == t else "NO"))

s = input()

div = ["dream", "dreamer", "erase", "eraser"]

rev = []

t = ""

s_rev = s[::-1]

for d in div:

    rev.append(d[::-1])

result = True

i = 0

while i < len(s):

    can_divide = False

    for d in rev:

        if len(s_rev) - i >= len(d) and s_rev[i:i + len(d)] == d:

            can_divide = True

            i += len(d)

            break

    if not can_divide:

        result = False

        break

print(("YES" if result else "NO"))

s = input()
t = ""
while len(t) < len(s):
    target_len = len(s) - len(t)
    if s[len(t)] == "d":
        if target_len == 5:
            t += "dream"
        elif target_len == 7:
            t += "dreamer"
        elif target_len > 7:
            if s[len(t) + 5] != "d" and s[len(t) + 5 : len(t) + 7 + 1] != "era":
                t += "dreamer"
            else:
                t += "dream"
        else:
            break
    else:
        if target_len == 5:
            t += "erase"
        elif target_len == 6:
            t += "eraser"
        elif target_len > 6:
            if s[len(t) + 5] != "d" and s[len(t) + 5 : len(t) + 6 + 2] != "era":
                t += "eraser"
            else:
                t += "erase"
        else:
            break
    if s[0 : len(t)] != t:
        break
print(("YES" if s == t else "NO"))

s = input()
div = ["dream", "dreamer", "erase", "eraser"]
rev = []
t = ""
s_rev = s[::-1]
for d in div:
    rev.append(d[::-1])
result = True
i = 0
while i < len(s):
    can_divide = False
    for d in rev:
        if len(s_rev) - i >= len(d) and s_rev[i : i + len(d)] == d:
            can_divide = True
            i += len(d)
            break
    if not can_divide:
        result = False
        break
print(("YES" if result else "NO"))

+div = ["dream", "dreamer", "erase", "eraser"]

+        if len(s_rev) - i >= len(d) and s_rev[i : i + len(d)] == d:


Input:
from collections import Counter,defaultdict,deque

from heapq import heappop,heappush,heapify

import sys,bisect,math,itertools,math,pprint

sys.setrecursionlimit(10**8)

mod = 10**9+7

INF = float('inf')

def inp(): return int(sys.stdin.readline())

def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()

A = sorted(inpl())

B = sorted(inpl())

C = sorted(inpl())

cnt = [0] * n

res = 0

for i,b in enumerate(B):

    c = bisect.bisect_left(C,b+1)

    cnt[i] = n-c

acc = [0]

for x in cnt:

    acc += [acc[-1] + x]

su = sum(cnt)

for i,a in enumerate(A):

    c = bisect.bisect_left(B,a+1)

    res += su - acc[c]

print(res)

from collections import Counter,defaultdict,deque

from heapq import heappop,heappush,heapify

import sys,bisect,math,itertools,math,pprint

sys.setrecursionlimit(10**8)

mod = 10**9+7

INF = float('inf')

def inp(): return int(sys.stdin.readline())

def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()

a = inpl()

b = inpl()

c = inpl()

a.sort()

b.sort()

c.sort()

lb = [0] * n

res = 0

for i in range(n):

    tmp = bisect.bisect_right(b,a[i])

    if tmp == n: continue

    lb[tmp] += 1

llb = list(itertools.accumulate(lb))

# print(lb,llb)

rr = [0] * n

for i in range(n):

    tmp = bisect.bisect_right(c,b[i])

    if tmp == n: continue

    rr[tmp] += llb[i]

print((sum(list(itertools.accumulate(rr)))))

from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heapify
import sys, bisect, math, itertools, math, pprint

sys.setrecursionlimit(10**8)
mod = 10**9 + 7
INF = float("inf")

def inp():
    return int(sys.stdin.readline())

def inpl():
    return list(map(int, sys.stdin.readline().split()))

n = inp()
A = sorted(inpl())
B = sorted(inpl())
C = sorted(inpl())
cnt = [0] * n
res = 0
for i, b in enumerate(B):
    c = bisect.bisect_left(C, b + 1)
    cnt[i] = n - c
acc = [0]
for x in cnt:
    acc += [acc[-1] + x]
su = sum(cnt)
for i, a in enumerate(A):
    c = bisect.bisect_left(B, a + 1)
    res += su - acc[c]
print(res)

from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heapify
import sys, bisect, math, itertools, math, pprint

sys.setrecursionlimit(10**8)
mod = 10**9 + 7
INF = float("inf")

def inp():
    return int(sys.stdin.readline())

def inpl():
    return list(map(int, sys.stdin.readline().split()))

n = inp()
a = inpl()
b = inpl()
c = inpl()
a.sort()
b.sort()
c.sort()
lb = [0] * n
res = 0
for i in range(n):
    tmp = bisect.bisect_right(b, a[i])
    if tmp == n:
        continue
    lb[tmp] += 1
llb = list(itertools.accumulate(lb))
# print(lb,llb)
rr = [0] * n
for i in range(n):
    tmp = bisect.bisect_right(c, b[i])
    if tmp == n:
        continue
    rr[tmp] += llb[i]
print((sum(list(itertools.accumulate(rr)))))


Input:
import sys

from math import gcd

read = sys.stdin.read

readline = sys.stdin.readline

readlines = sys.stdin.readlines

sys.setrecursionlimit(10 ** 9)

INF = 1 << 60

def lcm(x, y):

    return x * y // gcd(x, y)

def main():

    N, M = list(map(int, input().split()))

    A = list(set(map(int, input().split(" "))))

    A = [a // 2 for a in A]

    semi_lcm = 1

    for a in A:

        semi_lcm = lcm(semi_lcm, a)

        if semi_lcm > M:

            print((0))

            return

    for a in A:

        if semi_lcm // a % 2 == 0:

            print((0))

            return

    print(((M // semi_lcm + 1) // 2))

    return

if __name__ == '__main__':

    main()

import sys

read = sys.stdin.read

readline = sys.stdin.readline

readlines = sys.stdin.readlines

sys.setrecursionlimit(10 ** 9)

INF = 1 << 60

def gcd(a, b):

    while b:

        a, b = b, a % b

    return a

def lcm(a, b):

    return a * b // gcd(a, b)

def main():

    N, M, *A = list(map(int, read().split()))

    A = list(set(A))

    B = A.copy()

    while not any(b % 2 for b in B):

        B = [b // 2 for b in B]

    if not all(b % 2 for b in B):

        print((0))

        return

    semi_lcm = 1

    for a in A:

        semi_lcm = lcm(semi_lcm, a // 2)

    print(((M // semi_lcm + 1) // 2))

    return

if __name__ == '__main__':

    main()

import sys
from math import gcd

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60

def lcm(x, y):
    return x * y // gcd(x, y)

def main():
    N, M = list(map(int, input().split()))
    A = list(set(map(int, input().split(" "))))
    A = [a // 2 for a in A]
    semi_lcm = 1
    for a in A:
        semi_lcm = lcm(semi_lcm, a)
        if semi_lcm > M:
            print((0))
            return
    for a in A:
        if semi_lcm // a % 2 == 0:
            print((0))
            return
    print(((M // semi_lcm + 1) // 2))
    return

if __name__ == "__main__":
    main()

import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a * b // gcd(a, b)

def main():
    N, M, *A = list(map(int, read().split()))
    A = list(set(A))
    B = A.copy()
    while not any(b % 2 for b in B):
        B = [b // 2 for b in B]
    if not all(b % 2 for b in B):
        print((0))
        return
    semi_lcm = 1
    for a in A:
        semi_lcm = lcm(semi_lcm, a // 2)
    print(((M // semi_lcm + 1) // 2))
    return

if __name__ == "__main__":
    main()

-    N, M = list(map(int, input().split()))

-    A = list(set(map(int, input().split(" "))))

+    N, M, *A = list(map(int, read().split()))

+        semi_lcm = lcm(semi_lcm, a // 2)


Input:
import heapq

N = int(input())

abc = [list(map(int,input().split())) for _ in range(N-1)]

Q,K = list(map(int,input().split()))

xy = [list(map(int,input().split())) for _ in range(Q)]

connect = [[] for _ in range(N)]

INFTY = 10**15

for a,b,c in abc:

    connect[a-1].append([b-1,c])

    connect[b-1].append([a-1,c])

cost = [[INFTY,False] for _  in range(N)]

cost[K-1][0] = 0

q = [(0,K-1)]

while q:

    _,i = heapq.heappop(q)

    if cost[i][1]:

        continue

    cost[i][1] = True

    ci0 = cost[i][0]

    for j,c in connect[i]:

        if cost[j][1]:

            continue

        tmp_cost = ci0+c

        if tmp_cost < cost[j][0]:

            cost[j][0] = tmp_cost

            heapq.heappush(q,(tmp_cost,j))

for x,y in xy:

    print((cost[x-1][0] + cost[y-1][0]))

N = int(input())

ABC = [list(map(int,input().split())) for _ in [0]*(N-1)]

Q,K = list(map(int,input().split()))

XY = [list(map(int,input().split())) for _ in [0]*Q]

E = [{} for _ in [0]*N]

for a,b,c in ABC:

    E[a-1][b-1] = c

    E[b-1][a-1] = c

def dist_dfs_tree(N,E,start):

    d = [-1]*N

    d[start] = 0

    q = [start]

    while q:

        i = q.pop()

        ci = d[i]

        for j,cj in list(E[i].items()):

            if d[j] !=-1:continue

            d[j] = ci+cj

            q.append(j)

    return d

d = dist_dfs_tree(N,E,K-1)

for x,y in XY:

    print((d[x-1]+d[y-1]))

import heapq

N = int(input())
abc = [list(map(int, input().split())) for _ in range(N - 1)]
Q, K = list(map(int, input().split()))
xy = [list(map(int, input().split())) for _ in range(Q)]
connect = [[] for _ in range(N)]
INFTY = 10**15
for a, b, c in abc:
    connect[a - 1].append([b - 1, c])
    connect[b - 1].append([a - 1, c])
cost = [[INFTY, False] for _ in range(N)]
cost[K - 1][0] = 0
q = [(0, K - 1)]
while q:
    _, i = heapq.heappop(q)
    if cost[i][1]:
        continue
    cost[i][1] = True
    ci0 = cost[i][0]
    for j, c in connect[i]:
        if cost[j][1]:
            continue
        tmp_cost = ci0 + c
        if tmp_cost < cost[j][0]:
            cost[j][0] = tmp_cost
            heapq.heappush(q, (tmp_cost, j))
for x, y in xy:
    print((cost[x - 1][0] + cost[y - 1][0]))

N = int(input())
ABC = [list(map(int, input().split())) for _ in [0] * (N - 1)]
Q, K = list(map(int, input().split()))
XY = [list(map(int, input().split())) for _ in [0] * Q]
E = [{} for _ in [0] * N]
for a, b, c in ABC:
    E[a - 1][b - 1] = c
    E[b - 1][a - 1] = c

def dist_dfs_tree(N, E, start):
    d = [-1] * N
    d[start] = 0
    q = [start]
    while q:
        i = q.pop()
        ci = d[i]
        for j, cj in list(E[i].items()):
            if d[j] != -1:
                continue
            d[j] = ci + cj
            q.append(j)
    return d

d = dist_dfs_tree(N, E, K - 1)
for x, y in XY:
    print((d[x - 1] + d[y - 1]))

+ABC = [list(map(int, input().split())) for _ in [0] * (N - 1)]

+XY = [list(map(int, input().split())) for _ in [0] * Q]

-abc = [list(map(int, input().split())) for _ in range(N - 1)]

-xy = [list(map(int, input().split())) for _ in range(Q)]

-cost = [[INFTY, False] for _ in range(N)]

-            heapq.heappush(q, (tmp_cost, j))

+        for j, cj in list(E[i].items()):


Input:
import sys

import itertools

# import numpy as np

import time

import math

sys.setrecursionlimit(10 ** 7)

from collections import defaultdict

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

from functools import reduce

# from math import *

from math import *

N, M = list(map(int, readline().split()))

A = list(sorted([int(x) // 2 for x in readline().split()]))

min_cm = reduce(lambda a, b: (a * b) // gcd(a, b), A)

# print(all(map(lambda x: (min_cm // x) % 2 == 1, A)))

if not all([(min_cm // x) % 2 == 1 for x in A]):

    print((0))

    exit(0)

if min_cm > M:

    print((0))

    exit(0)

ans = (M // min_cm + 1) // 2

print(ans)

import sys

import itertools

# import numpy as np

import time

import math

import heapq

from collections import defaultdict

sys.setrecursionlimit(10 ** 7)

INF = 10 ** 9 + 7

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

# map(int, input().split())

N, M = list(map(int, input().split()))

A = list([int(x) // 2 for x in input().split()])

def f(n):

    res = 0

    while n % 2 == 0:

        n //= 2

        res += 1

    return res

def gcd(a, b):

    if b == 0:

        return a

    return gcd(b, a % b)

x = f(A[0])

for a in A:

    y = f(a)

    if y != x:

        print((0))

        exit()

lcm = A[0]

for i in range(1, N):

    lcm = lcm * A[i] //  gcd(lcm, A[i])

print(((M // lcm + 1) // 2))

import sys
import itertools

# import numpy as np
import time
import math

sys.setrecursionlimit(10**7)
from collections import defaultdict

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from functools import reduce

# from math import *
from math import *

N, M = list(map(int, readline().split()))
A = list(sorted([int(x) // 2 for x in readline().split()]))
min_cm = reduce(lambda a, b: (a * b) // gcd(a, b), A)
# print(all(map(lambda x: (min_cm // x) % 2 == 1, A)))
if not all([(min_cm // x) % 2 == 1 for x in A]):
    print((0))
    exit(0)
if min_cm > M:
    print((0))
    exit(0)
ans = (M // min_cm + 1) // 2
print(ans)

import sys
import itertools

# import numpy as np
import time
import math
import heapq
from collections import defaultdict

sys.setrecursionlimit(10**7)
INF = 10**9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
# map(int, input().split())
N, M = list(map(int, input().split()))
A = list([int(x) // 2 for x in input().split()])

def f(n):
    res = 0
    while n % 2 == 0:
        n //= 2
        res += 1
    return res

def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)

x = f(A[0])
for a in A:
    y = f(a)
    if y != x:
        print((0))
        exit()
lcm = A[0]
for i in range(1, N):
    lcm = lcm * A[i] // gcd(lcm, A[i])
print(((M // lcm + 1) // 2))

+A = list([int(x) // 2 for x in input().split()])

-N, M = list(map(int, readline().split()))

-A = list(sorted([int(x) // 2 for x in readline().split()]))

-min_cm = reduce(lambda a, b: (a * b) // gcd(a, b), A)

-# print(all(map(lambda x: (min_cm // x) % 2 == 1, A)))

-if not all([(min_cm // x) % 2 == 1 for x in A]):


Input:
# ABC150 D

si = lambda: input()

ni = lambda: int(input())

nm = lambda: list(map(int, input().split()))

nl = lambda: list(map(int, input().split()))

from math import gcd

from math import ceil

def lcm(x, y):

    return (x * y) // gcd(x, y)

n,m=nm()

a=nl()

ans=0

a=[x//2 for x in a]

lcm_v=a[0]

for i in range(n):

    lcm_v=lcm(lcm_v,a[i])

ok_flg=[(lcm_v//i)%2==1 for i in a]

if all(ok_flg):

    ans=((m//lcm_v)+1)//2

print(ans)

from math import gcd, ceil

def lcm(a, b):

    return (a*b)//gcd(a, b)

n, m = list(map(int, input().split()))

a = list(map(int, input().split()))

for i in range(n):

    a[i] = a[i]//2

lcm_v = a[0]

for i in range(1, n):

    lcm_v = lcm(lcm_v, a[i])

ok = True

for aa in a:

    if (lcm_v//aa) % 2 != 1:

        ok = False

        break

ans = 0

if ok:

    ans = ((m//lcm_v)+1)//2

print(ans)

# ABC150 D
si = lambda: input()
ni = lambda: int(input())
nm = lambda: list(map(int, input().split()))
nl = lambda: list(map(int, input().split()))
from math import gcd
from math import ceil

def lcm(x, y):
    return (x * y) // gcd(x, y)

n, m = nm()
a = nl()
ans = 0
a = [x // 2 for x in a]
lcm_v = a[0]
for i in range(n):
    lcm_v = lcm(lcm_v, a[i])
ok_flg = [(lcm_v // i) % 2 == 1 for i in a]
if all(ok_flg):
    ans = ((m // lcm_v) + 1) // 2
print(ans)

from math import gcd, ceil

def lcm(a, b):
    return (a * b) // gcd(a, b)

n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
for i in range(n):
    a[i] = a[i] // 2
lcm_v = a[0]
for i in range(1, n):
    lcm_v = lcm(lcm_v, a[i])
ok = True
for aa in a:
    if (lcm_v // aa) % 2 != 1:
        ok = False
        break
ans = 0
if ok:
    ans = ((m // lcm_v) + 1) // 2
print(ans)

-nm = lambda: list(map(int, input().split()))

-nl = lambda: list(map(int, input().split()))

-ok_flg = [(lcm_v // i) % 2 == 1 for i in a]


Input:
def main():

    while True:

        n, x = tuple(map(int, input().split()))

        pattern = 0

        if n == x == 0:

            break

        else:

            for a in range(1, n+1):

                for b in range(1, a):

                    for c in range(1, b):

                        pattern += 1 if a + b + c == x and a > b > c else 0

            print(pattern)

if __name__ == '__main__':

    main()

def divide_two(c, z):

    min_b = z // 2 + 1

    max_b = min(c-1, z-1)

    return max(max_b-min_b+1, 0)

num_set = []

cnt = 0

while True:

    n, x = list(map(int, input().split()))

    if (n, x) == (0, 0):

        break

    else:

        num_set.append((n, x))

        cnt += 1

for i in range(cnt):

    num_count = 0

    (n, x) = num_set[i]

    for c in range(x//3, n+1):

        num_count += divide_two(c, x-c)

    print(num_count)

def main():
    while True:
        n, x = tuple(map(int, input().split()))
        pattern = 0
        if n == x == 0:
            break
        else:
            for a in range(1, n + 1):
                for b in range(1, a):
                    for c in range(1, b):
                        pattern += 1 if a + b + c == x and a > b > c else 0
            print(pattern)

if __name__ == "__main__":
    main()

def divide_two(c, z):
    min_b = z // 2 + 1
    max_b = min(c - 1, z - 1)
    return max(max_b - min_b + 1, 0)

num_set = []
cnt = 0
while True:
    n, x = list(map(int, input().split()))
    if (n, x) == (0, 0):
        break
    else:
        num_set.append((n, x))
        cnt += 1
for i in range(cnt):
    num_count = 0
    (n, x) = num_set[i]
    for c in range(x // 3, n + 1):
        num_count += divide_two(c, x - c)
    print(num_count)

-        n, x = tuple(map(int, input().split()))

-                    for c in range(1, b):

-                        pattern += 1 if a + b + c == x and a > b > c else 0

+    n, x = list(map(int, input().split()))

+        num_count += divide_two(c, x - c)


Input:
import sys

from operator import itemgetter

from heapq import heapify, heappop, heappush

MAX_INT = int(10e15)

MIN_INT = -MAX_INT

mod = 1000000007

sys.setrecursionlimit(1000000)

def IL(): return list(map(int,input().split()))

def SL(): return input().split()

def I(): return int(sys.stdin.readline())

def S(): return input()

N, T = IL()

ab = [IL() for i in range(N)]

ab.sort(key=itemgetter(0))

#print(ab)

dp = [[0]*(T+1+3000+1) for _ in range(N+1)]

ans = 0

for i in range(N):

  for j in range(T+1+3000+1):

    time, deli = ab[i]

    if 0 <= j-time < T:

      dp[i + 1][j] = max(dp[i][j], dp[i][j - time] + deli)

    else:

      dp[i + 1][j] = dp[i][j]

    ans = max(ans, dp[i + 1][j])

print(ans)

#print(dp)

import sys

from collections import deque

MAX_INT = int(10e10)

MIN_INT = -MAX_INT

mod = 1000000007

sys.setrecursionlimit(1000000)

def IL(): return list(map(int,input().split()))

def SL(): return input().split()

def I(): return int(sys.stdin.readline())

def S(): return input()

N,T = IL()

ab = [IL() for i in range(N)]

ab.sort()

ans = 0

dp = [[0]*T for i in range(N+1)]

for i in range(1,N+1):

  a,b = ab[i-1]

  for j in range(T):

    if 0 <= j-a < T:

      dp[i][j] = max(dp[i-1][j], dp[i-1][j-a] + b)

    else:

      dp[i][j] = dp[i-1][j]

  else:

    ans = max(ans, dp[i-1][-1] + b)

print(ans)

import sys
from operator import itemgetter
from heapq import heapify, heappop, heappush

MAX_INT = int(10e15)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)

def IL():
    return list(map(int, input().split()))

def SL():
    return input().split()

def I():
    return int(sys.stdin.readline())

def S():
    return input()

N, T = IL()
ab = [IL() for i in range(N)]
ab.sort(key=itemgetter(0))
# print(ab)
dp = [[0] * (T + 1 + 3000 + 1) for _ in range(N + 1)]
ans = 0
for i in range(N):
    for j in range(T + 1 + 3000 + 1):
        time, deli = ab[i]
        if 0 <= j - time < T:
            dp[i + 1][j] = max(dp[i][j], dp[i][j - time] + deli)
        else:
            dp[i + 1][j] = dp[i][j]
        ans = max(ans, dp[i + 1][j])
print(ans)
# print(dp)

import sys
from collections import deque

MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)

def IL():
    return list(map(int, input().split()))

def SL():
    return input().split()

def I():
    return int(sys.stdin.readline())

def S():
    return input()

N, T = IL()
ab = [IL() for i in range(N)]
ab.sort()
ans = 0
dp = [[0] * T for i in range(N + 1)]
for i in range(1, N + 1):
    a, b = ab[i - 1]
    for j in range(T):
        if 0 <= j - a < T:
            dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - a] + b)
        else:
            dp[i][j] = dp[i - 1][j]
    else:
        ans = max(ans, dp[i - 1][-1] + b)
print(ans)

-from heapq import heapify, heappop, heappush

-            dp[i + 1][j] = max(dp[i][j], dp[i][j - time] + deli)


Input:
n = int(input())

a = list(map(int, input().split()))

tmp = [[e, n - i] for i, e in enumerate(a)]

tmp.sort(reverse=True)

aa = [[e, n - i] for e, i in tmp] + [[0, -1]]

v_prev, i_prev = aa[0]

i = 0

ans = [0] * n

sm = 0

while i < n:

    while aa[i][1] >= i_prev:

        sm += aa[i][0]

        i += 1

    ans[i_prev] += sm - aa[i][0] * i

    sm = aa[i][0] * i

    v_prev, i_prev = aa[i]

print(*ans, sep="\n")

from bisect import bisect_right

n = int(input())

a = list(map(int, input().split()))

li = [[0, -1]]

for i, e in enumerate(a):

    if e > li[-1][0]:

        li.append([e, i])

li = li[::-1]

a.sort()

acc = [0] * (n + 1)

for i in range(n - 1, -1, -1):

    acc[i] = acc[i+1] + a[i]

ans = [0] * n

sub = 0

ans_prev = 0

for (ep, ip), (e, i) in zip(li, li[1:]):

    j = bisect_right(a, e)

    ans[ip] = acc[j] - e * (n - j)

i_prev = 0

for i in range(1, n):

    if ans[i]:

        ans[i_prev] -= ans[i]

        i_prev = i

print(*ans, sep="\n")

from bisect import bisect_right

n = int(input())
a = list(map(int, input().split()))
li = [[0, -1]]
for i, e in enumerate(a):
    if e > li[-1][0]:
        li.append([e, i])
li = li[::-1]
a.sort()
acc = [0] * (n + 1)
for i in range(n - 1, -1, -1):
    acc[i] = acc[i + 1] + a[i]
ans = [0] * n
sub = 0
ans_prev = 0
for (ep, ip), (e, i) in zip(li, li[1:]):
    j = bisect_right(a, e)
    ans[ip] = acc[j] - e * (n - j)
i_prev = 0
for i in range(1, n):
    if ans[i]:
        ans[i_prev] -= ans[i]
        i_prev = i
print(*ans, sep="\n")

-tmp = [[e, n - i] for i, e in enumerate(a)]

+for (ep, ip), (e, i) in zip(li, li[1:]):


Input:
N, M = list(map(int, input().split()))

A_ = [int(input()) for _ in range(M)]

A = [0] * (N+3)

for a in A_:

    A[a] = 1

dp = [0] * (N+3)

dp[0] = 1

mod = 10**9+7

for i in range(1, N+1):

    if A[i-1] == 0:

        dp[i] += dp[i-1]

    if A[i-2] == 0:

        dp[i] += dp[i-2]

    dp[i] %= mod

print((dp[N]))

n,m=list(map(int,input().split()))

dp=[0]*(n+3)

a=[int(input()) for i in range(m)]

mod=10**9+7

for i in range(m):

    dp[a[i]]=-1

dp[0]=1

if dp[1]!=-1:

    dp[1]+=dp[0]

for i in range(n+1):

    if dp[i+2]==-1:

        continue

    if dp[i]!=-1:

        dp[i+2]+=dp[i]

    if dp[i+1]!=-1:

        dp[i+2]+=dp[i+1]

    dp[i+2]%=mod

print((dp[n]%mod))

n, m = list(map(int, input().split()))
dp = [0] * (n + 3)
a = [int(input()) for i in range(m)]
mod = 10**9 + 7
for i in range(m):
    dp[a[i]] = -1
dp[0] = 1
if dp[1] != -1:
    dp[1] += dp[0]
for i in range(n + 1):
    if dp[i + 2] == -1:
        continue
    if dp[i] != -1:
        dp[i + 2] += dp[i]
    if dp[i + 1] != -1:
        dp[i + 2] += dp[i + 1]
    dp[i + 2] %= mod
print((dp[n] % mod))


Input:
import sys

input = sys.stdin.readline

def I(): return int(input())

def MI(): return list(map(int, input().split()))

def LI(): return list(map(int, input().split()))

def main():

    mod=10**9+7

    N,M=MI()

    A=LI()

    CB=[[0,0]for _ in range(M)]

    A.sort()

    for i in range(M):

        CB[i][1],CB[i][0]=MI()

    CB.sort(reverse=True)

    now=0

    for i in range(N):

        if CB[now][1]<=0:

            now+=1

        if now>=M:

            break

        ch=CB[now][0]

        if A[i]<ch:

            A[i]=ch

            CB[now][1]-=1

        else:

            break

    print((sum(A)))

main()

import sys

input = sys.stdin.readline

def I(): return int(input())

def MI(): return list(map(int, input().split()))

def LI(): return list(map(int, input().split()))

def main():

    mod=10**9+7

    N,M=MI()

    A=LI()

    B=[0]*M

    C=[0]*M

    for i in range(M):

        B[i],C[i]=MI()

    C,B=list(zip(*sorted(zip(C,B))))

    B=B[::-1]

    C=C[::-1]

    import heapq

    heapq.heapify(A)

    for i in range(M):

        b=B[i]

        c=C[i]

        for _ in range(b):

            a=heapq.heappop(A)

            if a>=c:

                heapq.heappush(A,a)

                break

            else:

                heapq.heappush(A,c)

    ans=0

    for i in range(N):

        a=heapq.heappop(A)

        ans+=a

    print(ans)

main()

import sys

input = sys.stdin.readline

def I():
    return int(input())

def MI():
    return list(map(int, input().split()))

def LI():
    return list(map(int, input().split()))

def main():
    mod = 10**9 + 7
    N, M = MI()
    A = LI()
    CB = [[0, 0] for _ in range(M)]
    A.sort()
    for i in range(M):
        CB[i][1], CB[i][0] = MI()
    CB.sort(reverse=True)
    now = 0
    for i in range(N):
        if CB[now][1] <= 0:
            now += 1
        if now >= M:
            break
        ch = CB[now][0]
        if A[i] < ch:
            A[i] = ch
            CB[now][1] -= 1
        else:
            break
    print((sum(A)))

main()

import sys

input = sys.stdin.readline

def I():
    return int(input())

def MI():
    return list(map(int, input().split()))

def LI():
    return list(map(int, input().split()))

def main():
    mod = 10**9 + 7
    N, M = MI()
    A = LI()
    B = [0] * M
    C = [0] * M
    for i in range(M):
        B[i], C[i] = MI()
    C, B = list(zip(*sorted(zip(C, B))))
    B = B[::-1]
    C = C[::-1]
    import heapq

    heapq.heapify(A)
    for i in range(M):
        b = B[i]
        c = C[i]
        for _ in range(b):
            a = heapq.heappop(A)
            if a >= c:
                heapq.heappush(A, a)
                break
            else:
                heapq.heappush(A, c)
    ans = 0
    for i in range(N):
        a = heapq.heappop(A)
        ans += a
    print(ans)

main()

+    C, B = list(zip(*sorted(zip(C, B))))


Input:
from math import factorial

n = int(input())

f = factorial(n)

mod = 10 ** 9 + 7

def primes(n):

    is_prime = [True] * (n + 1)

    is_prime[0] = False

    is_prime[1] = False

    for i in range(2, int(n ** 0.5) + 1):

        if not is_prime[i]:

            continue

        for j in range(i * 2, n + 1, i):

            is_prime[j] = False

    return [i for i in range(n + 1) if is_prime[i]]

ans = 1

for p in primes(n):

    temp = 1

    while f % p == 0:

        temp += 1

        f //= p

    ans = (ans * temp) % mod

print(ans)

n=int(input())

m=10**9+7

p=[1 for i in range(10000)]

p[0]=0

p[1]=0

for i in range(2,n+1):

  if p[i]==1:

    for j in range(i*i,n+1,i):

        p[j]=0

ans=1

for i in range(2,n+1):

  if p[i]:

    c=0

    k=i

    while n//k>0:

      c=c+(n//k)%m

      k=k*i

    ans=(ans*((c+1)%m))%m

print((ans%m))

from math import factorial

n = int(input())
f = factorial(n)
mod = 10**9 + 7

def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]

ans = 1
for p in primes(n):
    temp = 1
    while f % p == 0:
        temp += 1
        f //= p
    ans = (ans * temp) % mod
print(ans)

n = int(input())
m = 10**9 + 7
p = [1 for i in range(10000)]
p[0] = 0
p[1] = 0
for i in range(2, n + 1):
    if p[i] == 1:
        for j in range(i * i, n + 1, i):
            p[j] = 0
ans = 1
for i in range(2, n + 1):
    if p[i]:
        c = 0
        k = i
        while n // k > 0:
            c = c + (n // k) % m
            k = k * i
        ans = (ans * ((c + 1) % m)) % m
print((ans % m))

-    for i in range(2, int(n**0.5) + 1):

-        for j in range(i * 2, n + 1, i):

-    return [i for i in range(n + 1) if is_prime[i]]

+        for j in range(i * i, n + 1, i):


Input:
from collections import defaultdict

from bisect import bisect_left

s = input()

n = len(s)

s = s + s

t = input()

if set(t) - set(s):

	print((-1))

	exit()

d = defaultdict(list)

for i in range(2 * n):

	d[s[i]] += [i]

cur = tot = 0

for c in t:

	x = d[c][bisect_left(d[c], cur)]

	if x < n:

		cur = x + 1

	else:

		cur = x - n + 1

		tot += n

tot += cur

print(tot)

from collections import defaultdict

from bisect import bisect_left

def main():

	s = input()

	n = len(s)

	s = s + s

	t = input()

	if set(t) - set(s):

		print((-1))

		exit()

	d = defaultdict(list)

	for i in range(2 * n):

		d[s[i]] += [i]

	cur = ncnt = 0

	for c in t:

		x = d[c][bisect_left(d[c], cur)]

		if x < n:

			cur = x + 1

		else:

			cur = x - n + 1

			ncnt += 1

	print((ncnt*n + cur))

if __name__ == "__main__":

	main()

from collections import defaultdict
from bisect import bisect_left

def main():
    s = input()
    n = len(s)
    s = s + s
    t = input()
    if set(t) - set(s):
        print((-1))
        exit()
    d = defaultdict(list)
    for i in range(2 * n):
        d[s[i]] += [i]
    cur = ncnt = 0
    for c in t:
        x = d[c][bisect_left(d[c], cur)]
        if x < n:
            cur = x + 1
        else:
            cur = x - n + 1
            ncnt += 1
    print((ncnt * n + cur))

if __name__ == "__main__":
    main()

+        x = d[c][bisect_left(d[c], cur)]


Input:
import sys

stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return list(map(int, stdin.readline().split()))

def li_(): return [int(x) - 1 for x in stdin.readline().split()]

def lf(): return list(map(float, stdin.readline().split()))

def ls(): return stdin.readline().split()

def ns(): return stdin.readline().rstrip()

def lc(): return list(ns())

def ni(): return int(stdin.readline())

def nf(): return float(stdin.readline())

n = ni()

ab = [list(li()) for _ in range(n)]

ab.sort(key=lambda x: x[1])

cur = 0

ans = True

for ai, bi in ab:

    cur += ai

    if cur > bi:

        ans = False

print(("Yes" if ans else "No"))

import sys

stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return list(map(int, stdin.readline().split()))

def li_(): return [int(x) - 1 for x in stdin.readline().split()]

def lf(): return list(map(float, stdin.readline().split()))

def ls(): return stdin.readline().split()

def ns(): return stdin.readline().rstrip()

def lc(): return list(ns())

def ni(): return int(stdin.readline())

def nf(): return float(stdin.readline())

n = ni()

ab = [tuple(li()) for _ in range(n)]

ab.sort(key=lambda x: x[1])

cur = 0

ok = True

for ai, bi in ab:

    cur += ai

    if cur > bi:

        ok = False

        break

print(("Yes" if ok else "No"))

import sys

stdin = sys.stdin
sys.setrecursionlimit(10**7)

def li():
    return list(map(int, stdin.readline().split()))

def li_():
    return [int(x) - 1 for x in stdin.readline().split()]

def lf():
    return list(map(float, stdin.readline().split()))

def ls():
    return stdin.readline().split()

def ns():
    return stdin.readline().rstrip()

def lc():
    return list(ns())

def ni():
    return int(stdin.readline())

def nf():
    return float(stdin.readline())

n = ni()
ab = [list(li()) for _ in range(n)]
ab.sort(key=lambda x: x[1])
cur = 0
ans = True
for ai, bi in ab:
    cur += ai
    if cur > bi:
        ans = False
print(("Yes" if ans else "No"))

import sys

stdin = sys.stdin
sys.setrecursionlimit(10**7)

def li():
    return list(map(int, stdin.readline().split()))

def li_():
    return [int(x) - 1 for x in stdin.readline().split()]

def lf():
    return list(map(float, stdin.readline().split()))

def ls():
    return stdin.readline().split()

def ns():
    return stdin.readline().rstrip()

def lc():
    return list(ns())

def ni():
    return int(stdin.readline())

def nf():
    return float(stdin.readline())

n = ni()
ab = [tuple(li()) for _ in range(n)]
ab.sort(key=lambda x: x[1])
cur = 0
ok = True
for ai, bi in ab:
    cur += ai
    if cur > bi:
        ok = False
        break
print(("Yes" if ok else "No"))

-ab = [list(li()) for _ in range(n)]
+ab = [tuple(li()) for _ in range(n)]
-ans = True
+ok = True
-        ans = False
-print(("Yes" if ans else "No"))
+        ok = False
+        break
+print(("Yes" if ok else "No"))


Input:
def main():

	x, y, z, k = list(map(int, input().split()))

	a = list(map(int, input().split()))

	b = list(map(int, input().split()))

	c = list(map(int, input().split()))

	d = [0]*x*y

	for i in range(x):

		for j in range(y):

			d[i*y+j] = a[i]+b[j]

	d.sort(reverse=True)

	c.sort(reverse=True)

	c_len = min(k, z)

	d_len = min(k, x*y)

	e = [0]*d_len*c_len

	for i in range(d_len):

		for j in range(c_len):

			e[i*c_len+j] = d[i] + c[j]

	e.sort(reverse=True)

	for i in range(k):

		print((e[i]))

if __name__ == '__main__':

    main()

def main():

	x, y, z, k = list(map(int, input().split()))

	a = list(map(int, input().split()))

	b = list(map(int, input().split()))

	c = list(map(int, input().split()))

	solve(a, b, c, x, y, z, k)

def solve(a, b, c, x, y, z, k):

	a.sort(reverse=True)

	b.sort(reverse=True)

	c.sort(reverse=True)

	stack = list()

	for p in range(x):

		for q in range(y):

			if (p+1)*(q+1) > k:

				break

			for r in range(z):

				if (p+1)*(q+1)*(r+1) > k:

					break

				stack.append(a[p]+b[q]+c[r])

	stack.sort(reverse=True)

	for i in range(k):

		print((stack[i]))

if __name__ == '__main__':

    main()

def main():
    x, y, z, k = list(map(int, input().split()))
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    c = list(map(int, input().split()))
    d = [0] * x * y
    for i in range(x):
        for j in range(y):
            d[i * y + j] = a[i] + b[j]
    d.sort(reverse=True)
    c.sort(reverse=True)
    c_len = min(k, z)
    d_len = min(k, x * y)
    e = [0] * d_len * c_len
    for i in range(d_len):
        for j in range(c_len):
            e[i * c_len + j] = d[i] + c[j]
    e.sort(reverse=True)
    for i in range(k):
        print((e[i]))

if __name__ == "__main__":
    main()

def main():
    x, y, z, k = list(map(int, input().split()))
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    c = list(map(int, input().split()))
    solve(a, b, c, x, y, z, k)

def solve(a, b, c, x, y, z, k):
    a.sort(reverse=True)
    b.sort(reverse=True)
    c.sort(reverse=True)
    stack = list()
    for p in range(x):
        for q in range(y):
            if (p + 1) * (q + 1) > k:
                break
            for r in range(z):
                if (p + 1) * (q + 1) * (r + 1) > k:
                    break
                stack.append(a[p] + b[q] + c[r])
    stack.sort(reverse=True)
    for i in range(k):
        print((stack[i]))

if __name__ == "__main__":
    main()

+                stack.append(a[p] + b[q] + c[r])


Input:
def solve():

  N, K = list(map(int, input().split()))

  _S = input()

  S = []

  b = _S[0]

  s = 0

  if b == '0': S.append(0)

  for _s in _S:

    if b == _s:

      s = s + 1

    else:

      b = _s

      S.append(s)

      s = 1

  S.append(s)

  if b == '0': S.append(0)

  num = min(len(S), 2 * K + 1)

  # n = sum(S[0:num if _S[0] == '1' else (num - 1)])

  n = sum(S[0:num])

  m = n

  # for i in range(0 if _S[0] == '1' else -1, len(S) - num, 2):

  for i in range(0, len(S) - num, 2):

    n = n - sum(S[i:i+2])

    n = n + sum(S[i + num:i + num + 2])

    m = max(m, n)

  return m

print((solve()))

def solve():

  N, K = list(map(int, input().split()))

  s = input()

  S = []

  b = s[0]

  cnt = 0

  if s[0] == '0': S.append(0)

  for c in s:

    if b == c: cnt = cnt + 1

    else:

      b = c

      S.append(cnt)

      cnt = 1

  S.append(cnt)

  if s[-1] == '0': S.append(0)

  num = min(len(S), 2 * K + 1)

  part = sum(S[0:num])

  ans = part

  for i in range(0, len(S) - num, 2):

    part = part - sum(S[i:i+2]) + sum(S[i + num:i + num + 2])

    ans = max(ans, part)

  return ans

print((solve()))

def solve():
    N, K = list(map(int, input().split()))
    _S = input()
    S = []
    b = _S[0]
    s = 0
    if b == "0":
        S.append(0)
    for _s in _S:
        if b == _s:
            s = s + 1
        else:
            b = _s
            S.append(s)
            s = 1
    S.append(s)
    if b == "0":
        S.append(0)
    num = min(len(S), 2 * K + 1)
    # n = sum(S[0:num if _S[0] == '1' else (num - 1)])
    n = sum(S[0:num])
    m = n
    # for i in range(0 if _S[0] == '1' else -1, len(S) - num, 2):
    for i in range(0, len(S) - num, 2):
        n = n - sum(S[i : i + 2])
        n = n + sum(S[i + num : i + num + 2])
        m = max(m, n)
    return m

print((solve()))

def solve():
    N, K = list(map(int, input().split()))
    s = input()
    S = []
    b = s[0]
    cnt = 0
    if s[0] == "0":
        S.append(0)
    for c in s:
        if b == c:
            cnt = cnt + 1
        else:
            b = c
            S.append(cnt)
            cnt = 1
    S.append(cnt)
    if s[-1] == "0":
        S.append(0)
    num = min(len(S), 2 * K + 1)
    part = sum(S[0:num])
    ans = part
    for i in range(0, len(S) - num, 2):
        part = part - sum(S[i : i + 2]) + sum(S[i + num : i + num + 2])
        ans = max(ans, part)
    return ans

print((solve()))

-    # for i in range(0 if _S[0] == '1' else -1, len(S) - num, 2):

-        n = n + sum(S[i + num : i + num + 2])

+        part = part - sum(S[i : i + 2]) + sum(S[i + num : i + num + 2])


Input:
from functools import reduce

N = int(input())

prime_table = [1] * (N+1)

for x in range(2, N+1):

    for t in range(2, x+1):

        while x % t == 0:

            prime_table[t] += 1

            x //= t

print((reduce(lambda x, y: x * y % (int(1e9) + 7), prime_table)))

def prime_factorize(n):

    while n % 2 == 0:

        a[2] += 1

        n //= 2

    f = 3

    while f * f <= n:

        if n % f == 0:

            a[f] += 1

            n //= f

        else:

            f += 2

    if n != 1:

        a[n] += 1

N = int(input())

a = [0]*(N+1)

for i in range(2, N+1):

    prime_factorize(i)

ans = 1

for i in a:

    if i > 0:

        ans *= (i+1)

big = 10**9 + 7

print((ans % big))

from functools import reduce

N = int(input())
prime_table = [1] * (N + 1)
for x in range(2, N + 1):
    for t in range(2, x + 1):
        while x % t == 0:
            prime_table[t] += 1
            x //= t
print((reduce(lambda x, y: x * y % (int(1e9) + 7), prime_table)))

def prime_factorize(n):
    while n % 2 == 0:
        a[2] += 1
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a[f] += 1
            n //= f
        else:
            f += 2
    if n != 1:
        a[n] += 1

N = int(input())
a = [0] * (N + 1)
for i in range(2, N + 1):
    prime_factorize(i)
ans = 1
for i in a:
    if i > 0:
        ans *= i + 1
big = 10**9 + 7
print((ans % big))

-print((reduce(lambda x, y: x * y % (int(1e9) + 7), prime_table)))


Input:
import sys

sys.setrecursionlimit(10 ** 6)

def solve():

    S = input()

    # print(S, len(S))

    words = {0: "dream", 1: "dreamer", 2: "erase", 3: "eraser"}

    TABLE = [[-1 for x in range(len(S) + 1)] for y in range(len(words) + 1)]

    def recur(i, w):

        if not TABLE[w][i] == -1:

            return TABLE[w][i]

        if i >= len(S):

            # print("jey", log)

            return True

        r1, r2, r3, r4 = False, False, False, False

        if S[i:i + 5] == words[0]:

            r1 = recur(i + 5, 0)

        if S[i:i + 7] == words[1]:

            r2 = recur(i + 7, 1)

        if S[i:i + 5] == words[2]:

            r3 = recur(i + 5, 2)

        if S[i:i + 6] == words[3]:

            r4 = recur(i + 6, 3)

        TABLE[w][i] = r1 or r2 or r3 or r4 or False

        return TABLE[w][i]

    ans = recur(0, 0)

    return ans

if __name__ == '__main__':

    res = solve()

    if res:

        print("YES")

    else:

        print("NO")

import sys

sys.setrecursionlimit(10 ** 6)

def solve():

    S = input()

    # print(S, len(S))

    S = S[::-1]

    words = ("dream"[::-1], "dreamer"[::-1], "erase"[::-1], "eraser"[::-1])

    def recur(i):

        if i >= len(S):

            return True

        for word in words:

            if S[i:i + len(word)] == word:

                if recur(i + len(word)):

                    return True

        return False

    ans = recur(0)

    return ans

if __name__ == '__main__':

    res = solve()

    if res:

        print("YES")

    else:

        print("NO")

import sys

sys.setrecursionlimit(10**6)

def solve():
    S = input()
    # print(S, len(S))
    words = {0: "dream", 1: "dreamer", 2: "erase", 3: "eraser"}
    TABLE = [[-1 for x in range(len(S) + 1)] for y in range(len(words) + 1)]

    def recur(i, w):
        if not TABLE[w][i] == -1:
            return TABLE[w][i]
        if i >= len(S):
            # print("jey", log)
            return True
        r1, r2, r3, r4 = False, False, False, False
        if S[i : i + 5] == words[0]:
            r1 = recur(i + 5, 0)
        if S[i : i + 7] == words[1]:
            r2 = recur(i + 7, 1)
        if S[i : i + 5] == words[2]:
            r3 = recur(i + 5, 2)
        if S[i : i + 6] == words[3]:
            r4 = recur(i + 6, 3)
        TABLE[w][i] = r1 or r2 or r3 or r4 or False
        return TABLE[w][i]

    ans = recur(0, 0)
    return ans

if __name__ == "__main__":
    res = solve()
    if res:
        print("YES")
    else:
        print("NO")

import sys

sys.setrecursionlimit(10**6)

def solve():
    S = input()
    # print(S, len(S))
    S = S[::-1]
    words = ("dream"[::-1], "dreamer"[::-1], "erase"[::-1], "eraser"[::-1])

    def recur(i):
        if i >= len(S):
            return True
        for word in words:
            if S[i : i + len(word)] == word:
                if recur(i + len(word)):
                    return True
        return False

    ans = recur(0)
    return ans

if __name__ == "__main__":
    res = solve()
    if res:
        print("YES")
    else:
        print("NO")

-    words = {0: "dream", 1: "dreamer", 2: "erase", 3: "eraser"}

-    TABLE = [[-1 for x in range(len(S) + 1)] for y in range(len(words) + 1)]

-        r1, r2, r3, r4 = False, False, False, False

-        TABLE[w][i] = r1 or r2 or r3 or r4 or False

+            if S[i : i + len(word)] == word:

+                if recur(i + len(word)):


Input:
from collections import Counter

N = int(input())

inputs = [int(i) for i in input().split()]

ans = 0

ruisekiwa = [0] * (N+1)

for i in range(N):

    ruisekiwa[i+1] = ruisekiwa[i] + inputs[i]

ruisekiwa = ruisekiwa[1:]

ruisekiwa.sort()

counter_ruiseki = Counter(ruisekiwa)

for key, value in list(counter_ruiseki.items()):

    if key == 0 and value == 1:

        ans += value

        continue

    elif key == 0 and value > 1:

        ans += value

    if value > 1:

        ans += sum(list(range(value)))

print(ans)

from collections import Counter

from itertools import accumulate

N = int(input())

inputs = [int(i) for i in input().split()]

ans = 0

ruisekiwa = list(accumulate(inputs))

ruisekiwa.sort()

counter_ruiseki = Counter(ruisekiwa)

for key, value in list(counter_ruiseki.items()):

    if key == 0 and value == 1:

        ans += value

        continue

    elif key == 0 and value > 1:

        ans += value

    if value > 1:

        ans += sum(list(range(value)))

print(ans)

from collections import Counter

N = int(input())
inputs = [int(i) for i in input().split()]
ans = 0
ruisekiwa = [0] * (N + 1)
for i in range(N):
    ruisekiwa[i + 1] = ruisekiwa[i] + inputs[i]
ruisekiwa = ruisekiwa[1:]
ruisekiwa.sort()
counter_ruiseki = Counter(ruisekiwa)
for key, value in list(counter_ruiseki.items()):
    if key == 0 and value == 1:
        ans += value
        continue
    elif key == 0 and value > 1:
        ans += value
    if value > 1:
        ans += sum(list(range(value)))
print(ans)

-    ruisekiwa[i + 1] = ruisekiwa[i] + inputs[i]


Input:
import sys

_input = sys.stdin.readline

def resolve():

    N = int(_input())

    T = [list(map(int, _input().split())) for _ in range(N)]

    t, x, y = 0, 0, 0

    for next_t, next_x, next_y in T:

        diff_xy = abs(x - next_x) + abs(y - next_y)

        diff_t = next_t - t

        if diff_xy > diff_t or (diff_xy % 2 != diff_t % 2):

            print('No')

            exit(0)

    print('Yes')

if __name__ == '__main__':

    resolve()

import sys

_input = sys.stdin.readline

def resolve():

    N = int(_input())

    t, x, y = 0, 0, 0

    for _ in range(N):

        next_t, next_x, next_y = list(map(int, _input().split()))

        diff_xy = abs(x - next_x) + abs(y - next_y)

        diff_t = next_t - t

        if diff_xy > diff_t or (diff_xy % 2 != diff_t % 2):

            print('No')

            exit(0)

    print('Yes')

if __name__ == '__main__':

    resolve()

import sys

_input = sys.stdin.readline

def resolve():
    N = int(_input())
    T = [list(map(int, _input().split())) for _ in range(N)]
    t, x, y = 0, 0, 0
    for next_t, next_x, next_y in T:
        diff_xy = abs(x - next_x) + abs(y - next_y)
        diff_t = next_t - t
        if diff_xy > diff_t or (diff_xy % 2 != diff_t % 2):
            print("No")
            exit(0)
    print("Yes")

if __name__ == "__main__":
    resolve()

import sys

_input = sys.stdin.readline

def resolve():
    N = int(_input())
    t, x, y = 0, 0, 0
    for _ in range(N):
        next_t, next_x, next_y = list(map(int, _input().split()))
        diff_xy = abs(x - next_x) + abs(y - next_y)
        diff_t = next_t - t
        if diff_xy > diff_t or (diff_xy % 2 != diff_t % 2):
            print("No")
            exit(0)
    print("Yes")

if __name__ == "__main__":
    resolve()

-    T = [list(map(int, _input().split())) for _ in range(N)]

+        next_t, next_x, next_y = list(map(int, _input().split()))


Input:
import sys

sys.setrecursionlimit(202020)

N = int(input())

won = [[] for i in range(N)]

for i in range(1,N):

    a = int(input()) - 1

    won[a].append(i)

def height(v):

    if not won[v]: return 0

    hs = [height(op) for op in won[v]]

    ret = 0

    for i,h in enumerate(sorted(hs)):

        ret = max(ret, h + len(hs) - i)

    return ret

print((height(0)))

import sys

sys.setrecursionlimit(10**8)

N = int(input())

A = [int(input())-1 for i in range(N-1)]

wins = [[] for _ in range(N)]

for i,a in enumerate(A):

    wins[a].append(i+1)

depth = [-1] * N

def dep(v):

    if len(wins[v])==0: return 0

    if depth[v] >= 0:

        return depth[v]

    ds = []

    for w in wins[v]:

        ds.append(dep(w))

    ds.sort(reverse=True)

    ret = 0

    for i,d in enumerate(ds):

        ret = max(ret, i+d+1)

    depth[v] = ret

    return ret

print((dep(0)))

import sys

sys.setrecursionlimit(202020)
N = int(input())
won = [[] for i in range(N)]
for i in range(1, N):
    a = int(input()) - 1
    won[a].append(i)

def height(v):
    if not won[v]:
        return 0
    hs = [height(op) for op in won[v]]
    ret = 0
    for i, h in enumerate(sorted(hs)):
        ret = max(ret, h + len(hs) - i)
    return ret

print((height(0)))

import sys

sys.setrecursionlimit(10**8)
N = int(input())
A = [int(input()) - 1 for i in range(N - 1)]
wins = [[] for _ in range(N)]
for i, a in enumerate(A):
    wins[a].append(i + 1)
depth = [-1] * N

def dep(v):
    if len(wins[v]) == 0:
        return 0
    if depth[v] >= 0:
        return depth[v]
    ds = []
    for w in wins[v]:
        ds.append(dep(w))
    ds.sort(reverse=True)
    ret = 0
    for i, d in enumerate(ds):
        ret = max(ret, i + d + 1)
    depth[v] = ret
    return ret

print((dep(0)))

+A = [int(input()) - 1 for i in range(N - 1)]

-        ret = max(ret, h + len(hs) - i)


Input:
#python3

from collections import defaultdict

from collections import namedtuple

P = namedtuple('P', ['front', 'end'])

def f(x):

    return P(str(x)[0], str(x)[-1])

def main():

    n = int(input())

    freq = defaultdict(int)

    for i in range(1, n+1):

        p = f(i)

        freq[p]+=1

    ans = 0

    for i in range(1, n + 1):

        p = f(i)

        q = (p.end, p.front)

        ans += freq[q]

    print(ans)

main()

import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

from collections import defaultdict

def f(x):

    return (int(str(x)[0]), int(str(x)[-1]))

def main():

    N = int(readline())

    df = defaultdict(int)

    for i in range(1, N+1):

        df[f(i)] += 1

    ans = 0

    for i in range(1, 10):

        for j in range(1, 10):

            ans +=  df[(i, j)]*df[(j, i)]

    print(ans)

if __name__ == '__main__':

    main()

# python3
from collections import defaultdict
from collections import namedtuple

P = namedtuple("P", ["front", "end"])

def f(x):
    return P(str(x)[0], str(x)[-1])

def main():
    n = int(input())
    freq = defaultdict(int)
    for i in range(1, n + 1):
        p = f(i)
        freq[p] += 1
    ans = 0
    for i in range(1, n + 1):
        p = f(i)
        q = (p.end, p.front)
        ans += freq[q]
    print(ans)

main()

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import defaultdict

def f(x):
    return (int(str(x)[0]), int(str(x)[-1]))

def main():
    N = int(readline())
    df = defaultdict(int)
    for i in range(1, N + 1):
        df[f(i)] += 1
    ans = 0
    for i in range(1, 10):
        for j in range(1, 10):
            ans += df[(i, j)] * df[(j, i)]
    print(ans)

if __name__ == "__main__":
    main()

+    return (int(str(x)[0]), int(str(x)[-1]))


Input:
def f(s):

    s=list(map(int,s.split(':')))

    return (s[0]*60+s[1])*60+s[2]

a=86401

while 1:

    t=[0]*a

    n=int(input())

    if n==0:break

    for _ in range(n):

        b,c=input().split()

        t[f(b)]+=1;t[f(c)]-=1

    d=0

    for i in range(1,a):

        t[i]+=t[i-1]

        d=max(d,t[i])

    print(d)

def f(s):

    return (s[0]*60+s[1])*60+s[2]

a=86400

while 1:

    t=[0]*a

    n=int(input())

    if n==0:break

    for _ in range(n):

        b,c = [list(map(int,x.split(':'))) for x in input().split()]

        t[f(b)]+=1;t[f(c)]-=1

    d=0

    for i in range(1,a):

        t[i]+=t[i-1]

        if d<t[i]:d=t[i]

    print(d)

def f(s):
    s = list(map(int, s.split(":")))
    return (s[0] * 60 + s[1]) * 60 + s[2]

a = 86401
while 1:
    t = [0] * a
    n = int(input())
    if n == 0:
        break
    for _ in range(n):
        b, c = input().split()
        t[f(b)] += 1
        t[f(c)] -= 1
    d = 0
    for i in range(1, a):
        t[i] += t[i - 1]
        d = max(d, t[i])
    print(d)

def f(s):
    return (s[0] * 60 + s[1]) * 60 + s[2]

a = 86400
while 1:
    t = [0] * a
    n = int(input())
    if n == 0:
        break
    for _ in range(n):
        b, c = [list(map(int, x.split(":"))) for x in input().split()]
        t[f(b)] += 1
        t[f(c)] -= 1
    d = 0
    for i in range(1, a):
        t[i] += t[i - 1]
        if d < t[i]:
            d = t[i]
    print(d)

+        b, c = [list(map(int, x.split(":"))) for x in input().split()]


Input:
import sys

readline = sys.stdin.readline

N,M = list(map(int,readline().split()))

INF = 10 ** 10

dp = [INF] * (2 ** N)

dp[0] = 0

for i in range(M):

  a,b = list(map(int,readline().split()))

  c = list(map(int,readline().split()))

  key = 0

  for j in range(len(c)):

    key += (1 << (c[j] - 1))

  for j in range(len(dp)):

    if dp[j] == INF:

      continue

    if j | key == j:

      continue

    dp[j | key] = min(dp[j | key], dp[j] + a)

if dp[-1] == INF:

  print((-1))

else:

  print((dp[-1]))

import sys

readline = sys.stdin.readline

N,M = list(map(int,readline().split()))

INF = 10 ** 10

dp = [INF] * (2 ** N)

dp[0] = 0

for i in range(M):

  a,b = list(map(int,readline().split()))

  c = list(map(int,readline().split()))

  key = 0

  for j in range(len(c)):

    key += (1 << (c[j] - 1))

  for j in range(len(dp)):

    if dp[j] == INF:

      continue

    if j | key == j:

      continue

    if dp[j | key] > dp[j] + a:

      dp[j | key] = dp[j] + a

if dp[-1] == INF:

  print((-1))

else:

  print((dp[-1]))

import sys

readline = sys.stdin.readline
N, M = list(map(int, readline().split()))
INF = 10**10
dp = [INF] * (2**N)
dp[0] = 0
for i in range(M):
    a, b = list(map(int, readline().split()))
    c = list(map(int, readline().split()))
    key = 0
    for j in range(len(c)):
        key += 1 << (c[j] - 1)
    for j in range(len(dp)):
        if dp[j] == INF:
            continue
        if j | key == j:
            continue
        dp[j | key] = min(dp[j | key], dp[j] + a)
if dp[-1] == INF:
    print((-1))
else:
    print((dp[-1]))

import sys

readline = sys.stdin.readline
N, M = list(map(int, readline().split()))
INF = 10**10
dp = [INF] * (2**N)
dp[0] = 0
for i in range(M):
    a, b = list(map(int, readline().split()))
    c = list(map(int, readline().split()))
    key = 0
    for j in range(len(c)):
        key += 1 << (c[j] - 1)
    for j in range(len(dp)):
        if dp[j] == INF:
            continue
        if j | key == j:
            continue
        if dp[j | key] > dp[j] + a:
            dp[j | key] = dp[j] + a
if dp[-1] == INF:
    print((-1))
else:
    print((dp[-1]))

-        dp[j | key] = min(dp[j | key], dp[j] + a)


Input:
N, K, C = list(map(int, input().split()))

S = input()

latest = [None]*K

i = len(S)+C

for j in range(K-1, -1, -1):

  i = S.rindex("o", 0, i-C)

  latest[j] = i

if i<=C or "o" not in S[:i-C]:

  i = -C-1

  for j in latest:

    i = S.index("o", i+C+1)

    if i == j:

      print((i+1))

def solve():

  N, K, C = list(map(int, input().split()))

  workable = [i for i, s in enumerate(input()) if s=="o"]

  if len(workable) == K:

    return workable

  prev = workable[-1]

  latest = {prev}

  i = len(workable)-1

  while i > 0:

    i -= 1

    if prev - workable[i] > C:

      latest.add(workable[i])

      prev = workable[i]

      if len(latest) > K:

        return []

  must = []

  i = -1

  prev = -C-1

  while i < len(workable)-1:

    i += 1

    if workable[i] - prev > C:

      if workable[i] in latest:

        must.append(workable[i])

      prev = workable[i]

  return must

for i in solve():

  print((i+1))

N, K, C = list(map(int, input().split()))
S = input()
latest = [None] * K
i = len(S) + C
for j in range(K - 1, -1, -1):
    i = S.rindex("o", 0, i - C)
    latest[j] = i
if i <= C or "o" not in S[: i - C]:
    i = -C - 1
    for j in latest:
        i = S.index("o", i + C + 1)
        if i == j:
            print((i + 1))

def solve():
    N, K, C = list(map(int, input().split()))
    workable = [i for i, s in enumerate(input()) if s == "o"]
    if len(workable) == K:
        return workable
    prev = workable[-1]
    latest = {prev}
    i = len(workable) - 1
    while i > 0:
        i -= 1
        if prev - workable[i] > C:
            latest.add(workable[i])
            prev = workable[i]
            if len(latest) > K:
                return []
    must = []
    i = -1
    prev = -C - 1
    while i < len(workable) - 1:
        i += 1
        if workable[i] - prev > C:
            if workable[i] in latest:
                must.append(workable[i])
            prev = workable[i]
    return must

for i in solve():
    print((i + 1))

-N, K, C = list(map(int, input().split()))

+    N, K, C = list(map(int, input().split()))

+    workable = [i for i, s in enumerate(input()) if s == "o"]

+                must.append(workable[i])


Input:
import sys

input = sys.stdin.readline

def main():

  n, m = map(int, input().split())

  LR = [list(map(int, input().split())) for _ in range(n)]

  BIT = [0]*(m+2)

  def add(i, a):

    while i <= m+1:

      BIT[i] += a

      i += i&(-i)

  def bit_sum(i):

    res = 0

    while i > 0:

      res += BIT[i]

      i -= i&(-i)

    return res

  S = sorted([(r-l+1, l, r) for l, r in LR], reverse=True)

  cnt = n

  L = []

  for i in range(1, m+1):

    while S and S[-1][0] == i:

      c, l, r = S.pop()

      cnt -= 1

      add(l, 1)

      add(r+1, -1)

    res = cnt

    for j in range(0, m+1, i):

      res += bit_sum(j)

    L.append(res)

  print(*L, sep="\n")

if __name__ == "__main__":

  main()

import sys

input = sys.stdin.readline

def main():

  n, m = list(map(int, input().split()))

  S = [[] for _ in range(m+1)]

  for _ in range(n):

    l, r = list(map(int, input().split()))

    S[r-l+1].append((l, r))

  BIT = [0]*(m+2)

  def add(i, a):

    while i <= m+1:

      BIT[i] += a

      i += i&(-i)

  def bit_sum(i):

    res = 0

    while i > 0:

      res += BIT[i]

      i -= i&(-i)

    return res

  cnt = n

  for i in range(1, m+1):

    for l, r in S[i]:

      cnt -= 1

      add(l, 1)

      add(r+1, -1)

    res = cnt

    for j in range(0, m+1, i):

      res += bit_sum(j)

    print(res)

if __name__ == "__main__":

  main()

import sys

input = sys.stdin.readline

def main():
    n, m = map(int, input().split())
    LR = [list(map(int, input().split())) for _ in range(n)]
    BIT = [0] * (m + 2)

    def add(i, a):
        while i <= m + 1:
            BIT[i] += a
            i += i & (-i)

    def bit_sum(i):
        res = 0
        while i > 0:
            res += BIT[i]
            i -= i & (-i)
        return res

    S = sorted([(r - l + 1, l, r) for l, r in LR], reverse=True)
    cnt = n
    L = []
    for i in range(1, m + 1):
        while S and S[-1][0] == i:
            c, l, r = S.pop()
            cnt -= 1
            add(l, 1)
            add(r + 1, -1)
        res = cnt
        for j in range(0, m + 1, i):
            res += bit_sum(j)
        L.append(res)
    print(*L, sep="\n")

if __name__ == "__main__":
    main()

import sys

input = sys.stdin.readline

def main():
    n, m = list(map(int, input().split()))
    S = [[] for _ in range(m + 1)]
    for _ in range(n):
        l, r = list(map(int, input().split()))
        S[r - l + 1].append((l, r))
    BIT = [0] * (m + 2)

    def add(i, a):
        while i <= m + 1:
            BIT[i] += a
            i += i & (-i)

    def bit_sum(i):
        res = 0
        while i > 0:
            res += BIT[i]
            i -= i & (-i)
        return res

    cnt = n
    for i in range(1, m + 1):
        for l, r in S[i]:
            cnt -= 1
            add(l, 1)
            add(r + 1, -1)
        res = cnt
        for j in range(0, m + 1, i):
            res += bit_sum(j)
        print(res)

if __name__ == "__main__":
    main()

-    LR = [list(map(int, input().split())) for _ in range(n)]

+    n, m = list(map(int, input().split()))

+        l, r = list(map(int, input().split()))

-    S = sorted([(r - l + 1, l, r) for l, r in LR], reverse=True)


Input:
#!/usr/bin/env python3

# coding=utf-8

import sys

s = sys.stdin.readline().strip()

l = [_s is "1" for _s in list(s)]

l_r = l[::-1]

index = 0

for i, (c, n, c_r, n_r) in enumerate(

        zip(l[:len(s) // 2], l[1:len(s) // 2 + 1], l_r[:len(s) // 2], l_r[1:len(s) // 2 + 1])):

    if c ^ n or c_r ^ n_r:

        index = i + 1

print((len(s) - index))

def solve(string):

    l = [s == "1" for s in string]

    l_r = l[::-1]

    index = 0

    h = len(string) // 2

    for i, (c, n, c_r, n_r) in enumerate(zip(l[:h], l[1:h + 1], l_r[:h], l_r[1:h + 1])):

        if c ^ n or c_r ^ n_r:

            index = i + 1

    return str(len(string) - index)

if __name__ == '__main__':

    print((solve(input())))

#!/usr/bin/env python3
# coding=utf-8
import sys

s = sys.stdin.readline().strip()
l = [_s is "1" for _s in list(s)]
l_r = l[::-1]
index = 0
for i, (c, n, c_r, n_r) in enumerate(
    zip(
        l[: len(s) // 2],
        l[1 : len(s) // 2 + 1],
        l_r[: len(s) // 2],
        l_r[1 : len(s) // 2 + 1],
    )
):
    if c ^ n or c_r ^ n_r:
        index = i + 1
print((len(s) - index))

def solve(string):
    l = [s == "1" for s in string]
    l_r = l[::-1]
    index = 0
    h = len(string) // 2
    for i, (c, n, c_r, n_r) in enumerate(
        zip(l[:h], l[1 : h + 1], l_r[:h], l_r[1 : h + 1])
    ):
        if c ^ n or c_r ^ n_r:
            index = i + 1
    return str(len(string) - index)

if __name__ == "__main__":
    print((solve(input())))

+    for i, (c, n, c_r, n_r) in enumerate(


Input:
# coding: utf-8

import sys

input = sys.stdin.readline

def f(n, abc):

    dp = [[0] * 3 for _ in range(n + 1)]

    for i in range(1, n + 1):

        for j in range(3):

            dp[i][j] = max(dp[i - 1][k] + abc[i - 1][j] \

                for k in range(3) if k != j)

    return(max(dp[n]))

n = int(input())    # 1 <= n <= 10^5

abc = [list(map(int, input().rstrip().split())) for _ in range(n)]

print((f(n, abc)))

# coding: utf-8

import sys

input = sys.stdin.readline

def f(n, abc):

    dp = [0] * 3

    for i in range(1, n + 1):

        a, b, c = abc[i - 1]

        dp = [ max(dp[1] + a, dp[2] + a), \

               max(dp[0] + b, dp[2] + b), \

               max(dp[0] + c, dp[1] + c) ]

    return(max(dp))

n = int(input())    # 1 <= n <= 10^5

abc = [list(map(int, input().rstrip().split())) for _ in range(n)]

print((f(n, abc)))

# coding: utf-8
import sys

input = sys.stdin.readline

def f(n, abc):
    dp = [[0] * 3 for _ in range(n + 1)]
    for i in range(1, n + 1):
        for j in range(3):
            dp[i][j] = max(dp[i - 1][k] + abc[i - 1][j] for k in range(3) if k != j)
    return max(dp[n])

n = int(input())  # 1 <= n <= 10^5
abc = [list(map(int, input().rstrip().split())) for _ in range(n)]
print((f(n, abc)))

# coding: utf-8
import sys

input = sys.stdin.readline

def f(n, abc):
    dp = [0] * 3
    for i in range(1, n + 1):
        a, b, c = abc[i - 1]
        dp = [
            max(dp[1] + a, dp[2] + a),
            max(dp[0] + b, dp[2] + b),
            max(dp[0] + c, dp[1] + c),
        ]
    return max(dp)

n = int(input())  # 1 <= n <= 10^5
abc = [list(map(int, input().rstrip().split())) for _ in range(n)]
print((f(n, abc)))

-            dp[i][j] = max(dp[i - 1][k] + abc[i - 1][j] for k in range(3) if k != j)


Input:
import heapq

x, y, z, k = list(map(int, input().split()))

a = list(map(int, input().split()))

b = list(map(int, input().split()))

c = list(map(int, input().split()))

def diff(l):

    m = max(l)

    return sorted(m - v for v in l)[1:]

s = sum(map(max, [a, b, c]))

sa, sb, sc = list(map(diff, [a, b, c]))

da, db, dc = [0], [0], [0]

q = [0]

while k > 0:

    while True:

        if len(sa) > 0 and (len(q) == 0 or q[0] > sa[0]):

            for v in [sa[0] + bb + cc for bb in db for cc in dc]:

                heapq.heappush(q, v)

            da.append(sa[0])

            sa = sa[1:]

        elif len(sb) > 0 and (len(q) == 0 or q[0] > sb[0]):

            for v in [sb[0] + aa + cc for aa in da for cc in dc]:

                heapq.heappush(q, v)

            db.append(sb[0])

            sb = sb[1:]

        elif len(sc) > 0 and (len(q) == 0 or q[0] > sc[0]):

            for v in [sc[0] + aa + bb for aa in da for bb in db]:

                heapq.heappush(q, v)

            dc.append(sc[0])

            sc = sc[1:]

        else:

            break

    v = heapq.heappop(q)

    print(s - v)

    k -= 1

import heapq

x, y, z, k = list(map(int, input().split()))

a = sorted(map(int, input().split()))

b = sorted(map(int, input().split()))

c = sorted(map(int, input().split()))

q = []

memo = set()

def qpush(q, ai, bi, ci):

    t = (-(a[ai] + b[bi] + c[ci]), ai, bi, ci)

    if not t in memo:

        memo.add(t)

        heapq.heappush(q, t)

qpush(q, len(a) - 1, len(b) - 1, len(c) - 1)

for _ in range(k):

    s, ai, bi, ci = heapq.heappop(q)

    if ai > 0:

        qpush(q, ai - 1, bi, ci)

    if bi > 0:

        qpush(q, ai, bi - 1, ci)

    if ci > 0:

        qpush(q, ai, bi, ci - 1)

    print(-s)

-    return sorted(m - v for v in l)[1:]

-sa, sb, sc = list(map(diff, [a, b, c]))

-            for v in [sa[0] + bb + cc for bb in db for cc in dc]:

-        elif len(sb) > 0 and (len(q) == 0 or q[0] > sb[0]):

-            for v in [sb[0] + aa + cc for aa in da for cc in dc]:

-        elif len(sc) > 0 and (len(q) == 0 or q[0] > sc[0]):

-            for v in [sc[0] + aa + bb for aa in da for bb in db]:

+qpush(q, len(a) - 1, len(b) - 1, len(c) - 1)


Input:
N = int(input())

A = [0]*N

X = []

Y = []

for i in range(N):

    A[i] = int(input())

    X.append([])

    Y.append([])

    for j in range(A[i]):

        x, y = list(map(int, input().split()))

        X[i].append(x-1)

        Y[i].append(y)

ans = 0

for bit in range(1<<N):

    honest = 0

    ok = True

    for i in range(N):

        if bit&(1<<i):

            honest += 1

            for j in range(A[i]):

                if Y[i][j] == 0:

                    if bit&(1<<X[i][j]):

                        ok = False

                        break

                else:

                    if not bit&(1<<X[i][j]):

                        ok = False

                        break

            if not ok:

                break

    if ok:

        ans = max(ans, honest)

print(ans)

N = int(input())

XY = [[] for _ in range(N)]

for i in range(N):

    A = int(input())

    for _ in range(A):

        x, y = list(map(int, input().split()))

        XY[i].append((x-1,y))

ans = 0

for bit in range(1<<N):

    cnt = bin(bit).count('1')

    ok = True

    for i in range(N):

        if bit&(1<<i):

            for x,y in XY[i]:

                if y == 1:

                    if not bit&(1<<x):

                        ok = False

                        break

                else:

                    if bit&(1<<x):

                        ok = False

                        break

            if not ok:

                break

    if ok:

        ans = max(ans, cnt)

print(ans)

N = int(input())
A = [0] * N
X = []
Y = []
for i in range(N):
    A[i] = int(input())
    X.append([])
    Y.append([])
    for j in range(A[i]):
        x, y = list(map(int, input().split()))
        X[i].append(x - 1)
        Y[i].append(y)
ans = 0
for bit in range(1 << N):
    honest = 0
    ok = True
    for i in range(N):
        if bit & (1 << i):
            honest += 1
            for j in range(A[i]):
                if Y[i][j] == 0:
                    if bit & (1 << X[i][j]):
                        ok = False
                        break
                else:
                    if not bit & (1 << X[i][j]):
                        ok = False
                        break
            if not ok:
                break
    if ok:
        ans = max(ans, honest)
print(ans)

N = int(input())
XY = [[] for _ in range(N)]
for i in range(N):
    A = int(input())
    for _ in range(A):
        x, y = list(map(int, input().split()))
        XY[i].append((x - 1, y))
ans = 0
for bit in range(1 << N):
    cnt = bin(bit).count("1")
    ok = True
    for i in range(N):
        if bit & (1 << i):
            for x, y in XY[i]:
                if y == 1:
                    if not bit & (1 << x):
                        ok = False
                        break
                else:
                    if bit & (1 << x):
                        ok = False
                        break
            if not ok:
                break
    if ok:
        ans = max(ans, cnt)
print(ans)

+                    if not bit & (1 << x):


Input:
"""Minimum cost Sort."""

def min_cost_sort(A):

    """Sort list A in ascending order.

    And return the switching cost in sorting.

    """

    B = list(A)

    B.sort()

    cost = 0

    min_w = B[0]

    for i, b in enumerate(B):

        tmp_cost = 0

        bi = A.index(b)

        n = 1

        while bi != i:

            n += 1

            st = B[bi]

            si = A.index(st)

            tmp_cost += b + st

            A[bi], A[si] = st, b

            bi = si

        dec = (n - 1) * (b - min_w)

        inc = 2 * (min_w + b)

        if dec < inc:

            cost += tmp_cost

        else:

            cost += tmp_cost - dec + inc

    return cost

n = input()

A = list(map(int, input().split()))

ans = min_cost_sort(A)

print(ans)

"""Minimum cost Sort."""

def min_cost_sort(A):

    """Sort list A in ascending order.

    And return the switching cost in sorting.

    """

    B = list(A)

    B.sort()

    cost = 0

    min_w = B[0]

    for i, b in enumerate(B):

        tmp_cost = 0

        bi = A.index(b)

        cnt = 0

        while bi != i:

            cnt += 1

            st = B[bi]

            si = A.index(st)

            tmp_cost += b + st

            A[bi], A[si] = st, b

            bi = si

        if cnt:

            dec = cnt * (b - min_w)

            inc = 2 * (min_w + b)

            if dec < inc:

                cost += tmp_cost

            else:

                cost += tmp_cost - dec + inc

    return cost

n = input()

A = list(map(int, input().split()))

ans = min_cost_sort(A)

print(ans)

-            cost += tmp_cost - dec + inc

+                cost += tmp_cost - dec + inc


Input:
import sys

input = sys.stdin.readline

from collections import *

def dfs(x, y):

    if x==0 and y==0:

        t[x][y] = False

        return False

    if x>=1:

        t[x][y] |= not dfs(x-1, y)

    if y>=1:

        t[x][y] |= not dfs(x, y-1)

    if min(x, y)>=1:

        t[x][y] |= not dfs(x-1, y-1)

    return t[x][y]

t = [[False]*7 for _ in range(7)]

for i in range(7):

    for j in range(7):

        dfs(i, j)

"""

for ti in t:

    print(*ti)

"""

N = int(input())

flag = True

for _ in range(N):

    a = int(input())

    if a%2==1:

        flag = False

if flag:

    print('second')

else:

    print('first')

import sys

input = sys.stdin.readline

"""

def dfs(x, y):

    if x==0 and y==0:

        return False

    res = False

    if x>0:

        res |= not dfs(x-1, y)

    if y>0:

        res |= not dfs(x, y-1)

    if min(x, y)>0:

        res |= not dfs(x-1, y-1)

    return res

t = [[False]*5 for _ in range(5)]

for i in range(5):

    for j in range(5):

        t[i][j] = dfs(i, j)

for ti in t:

    print(*ti)

"""

N = int(input())

a = [int(input()) for _ in range(N)]

for ai in a:

    if ai%2==1:

        print('first')

        exit()

print('second')

import sys

input = sys.stdin.readline
from collections import *

def dfs(x, y):
    if x == 0 and y == 0:
        t[x][y] = False
        return False
    if x >= 1:
        t[x][y] |= not dfs(x - 1, y)
    if y >= 1:
        t[x][y] |= not dfs(x, y - 1)
    if min(x, y) >= 1:
        t[x][y] |= not dfs(x - 1, y - 1)
    return t[x][y]

t = [[False] * 7 for _ in range(7)]
for i in range(7):
    for j in range(7):
        dfs(i, j)
"""
for ti in t:
    print(*ti)
"""
N = int(input())
flag = True
for _ in range(N):
    a = int(input())
    if a % 2 == 1:
        flag = False
if flag:
    print("second")
else:
    print("first")

import sys

input = sys.stdin.readline
"""
def dfs(x, y):
    if x==0 and y==0:
        return False
    res = False
    if x>0:
        res |= not dfs(x-1, y)
    if y>0:
        res |= not dfs(x, y-1)
    if min(x, y)>0:
        res |= not dfs(x-1, y-1)
    return res
t = [[False]*5 for _ in range(5)]
for i in range(5):
    for j in range(5):
        t[i][j] = dfs(i, j)
for ti in t:
    print(*ti)
"""
N = int(input())
a = [int(input()) for _ in range(N)]
for ai in a:
    if ai % 2 == 1:
        print("first")
        exit()
print("second")


Input:
import sys

input = sys.stdin.readline

s = input().rstrip()

k = int(input())

def check_count(s):

    cnt_list = [1]

    cnt = 1

    for i in range(1, len(s)):

        if s[i-1] == s[i]:

            cnt_list[-1] += 1

        else:

            cnt_list.append(1)

    return cnt_list

def calc_ans(cnt_list, k):

    _ans = 0

    for c in cnt_list:

        _ans += c//2

    return(_ans * k)

if len(s)==1:

    ans = k//2

else:

    cnt_list = check_count(s)

    if len(cnt_list)==1:

        ans = (len(s)*k)//2

    else:

        ans = calc_ans(cnt_list, k)

        if s[0]==s[-1]:

            if cnt_list[0]%2==1 and cnt_list[-1]%2==1:

                ans += k - 1

print(ans)

import sys

input = sys.stdin.readline

s = input().rstrip()

k = int(input())

def check_count(s):

    cnt_list = []

    cnt = 1

    for i in range(1, len(s)):

        if s[i-1] == s[i]:

            cnt += 1

        else:

            cnt_list.append(cnt)

            cnt = 1

    if cnt>1:

        cnt_list.append(cnt)

    return cnt_list

def calc_ans(cnt_list, k):

    _ans = 0

    for c in cnt_list:

        _ans += c//2

    return(_ans * k)

if len(s)==1:

    ans = k//2

else:

    cnt_list = check_count(s)

    if len(cnt_list)==1:

        ans = (len(s)*k)//2

    else:

        ans = calc_ans(cnt_list, k)

        if s[0]==s[-1]:

            if cnt_list[0]%2==1 and cnt_list[-1]%2==1:

                ans += k - 1

print(ans)

import sys

input = sys.stdin.readline
s = input().rstrip()
k = int(input())

def check_count(s):
    cnt_list = [1]
    cnt = 1
    for i in range(1, len(s)):
        if s[i - 1] == s[i]:
            cnt_list[-1] += 1
        else:
            cnt_list.append(1)
    return cnt_list

def calc_ans(cnt_list, k):
    _ans = 0
    for c in cnt_list:
        _ans += c // 2
    return _ans * k

if len(s) == 1:
    ans = k // 2
else:
    cnt_list = check_count(s)
    if len(cnt_list) == 1:
        ans = (len(s) * k) // 2
    else:
        ans = calc_ans(cnt_list, k)
        if s[0] == s[-1]:
            if cnt_list[0] % 2 == 1 and cnt_list[-1] % 2 == 1:
                ans += k - 1
print(ans)

import sys

input = sys.stdin.readline
s = input().rstrip()
k = int(input())

def check_count(s):
    cnt_list = []
    cnt = 1
    for i in range(1, len(s)):
        if s[i - 1] == s[i]:
            cnt += 1
        else:
            cnt_list.append(cnt)
            cnt = 1
    if cnt > 1:
        cnt_list.append(cnt)
    return cnt_list

def calc_ans(cnt_list, k):
    _ans = 0
    for c in cnt_list:
        _ans += c // 2
    return _ans * k

if len(s) == 1:
    ans = k // 2
else:
    cnt_list = check_count(s)
    if len(cnt_list) == 1:
        ans = (len(s) * k) // 2
    else:
        ans = calc_ans(cnt_list, k)
        if s[0] == s[-1]:
            if cnt_list[0] % 2 == 1 and cnt_list[-1] % 2 == 1:
                ans += k - 1
print(ans)

-    cnt_list = [1]
+    cnt_list = []
-            cnt_list[-1] += 1
+            cnt += 1
-            cnt_list.append(1)
+            cnt_list.append(cnt)
+            cnt = 1
+    if cnt > 1:
+        cnt_list.append(cnt)


Input:
import sys

sys.setrecursionlimit(10**7)

def lmi(): return list(map(int, input().split()))

n, m = lmi()

l = [0] * (n+1)

l[0] = 1

a = 0

if m != 0:

    a = int(input())

k = 1

for i in range(n+1):

    if i != a:

        if i == 1:

            l[i] = 1

        elif i >= 2:

            l[i] = l[i-1] + l[i-2]

            l[i] %= 1000000007

    else:

        k += 1

        if k <= m:

            a = int(input())

#print(l)

print((l[n] % 1000000007))

import sys

sys.setrecursionlimit(10**7)

def lmi(): return list(map(int, input().split()))

n, m = lmi()

a = [1] * (n+1)

for i in range(m):

    a[int(input())] = 0

k = [0] * (n+1)

k[0] = 1

for i in range(1,n+1):

    if i == 1 and a[1]:

        k[1] = 1

    elif i >= 2 and a[i]:

        k[i] = k[i-1] + k[i-2]

        k[i] %= 10 ** 9 + 7

print((k[n]))

import sys

sys.setrecursionlimit(10**7)

def lmi():
    return list(map(int, input().split()))

n, m = lmi()
l = [0] * (n + 1)
l[0] = 1
a = 0
if m != 0:
    a = int(input())
k = 1
for i in range(n + 1):
    if i != a:
        if i == 1:
            l[i] = 1
        elif i >= 2:
            l[i] = l[i - 1] + l[i - 2]
            l[i] %= 1000000007
    else:
        k += 1
        if k <= m:
            a = int(input())
# print(l)
print((l[n] % 1000000007))

import sys

sys.setrecursionlimit(10**7)

def lmi():
    return list(map(int, input().split()))

n, m = lmi()
a = [1] * (n + 1)
for i in range(m):
    a[int(input())] = 0
k = [0] * (n + 1)
k[0] = 1
for i in range(1, n + 1):
    if i == 1 and a[1]:
        k[1] = 1
    elif i >= 2 and a[i]:
        k[i] = k[i - 1] + k[i - 2]
        k[i] %= 10**9 + 7
print((k[n]))


Input:
import queue

n = int(input())

abc = [[] for i in range(n+1)]

for i in range(n-1):

    a,b,c = list(map(int,input().split()))

    abc[a].append([b,c])

    abc[b].append([a,c])

Q,k = list(map(int,input().split()))

xy = [[int(i) for i in input().split()] for j in range(Q)]

q = queue.Queue()

q.put(k)

path = [-1]*(n+1)

path[k] = 0

while not q.empty():

    tmp = q.get()

    for i in range(len(abc[tmp])):

        #print(abc[tmp])

        #exit()

        num = abc[tmp][i][0]

        if path[num] != -1:

            continue

        else:

            path[num] = path[tmp] + abc[tmp][i][1]

            q.put(num)

for i in range(Q):

    print((path[xy[i][0]]+path[xy[i][1]]))

import queue

import sys

sys.setrecursionlimit(10**7)

n = int(input())

abc = [[] for i in range(n+1)]

for i in range(n-1):

    a,b,c = list(map(int,input().split()))

    abc[a].append([b,c])

    abc[b].append([a,c])

Q,k = list(map(int,input().split()))

xy = [[int(i) for i in input().split()] for j in range(Q)]

q = queue.Queue()

q.put(k)

path = [-1]*(n+1)

path[k] = 0

def dfs(p):

    for i in range(len(abc[p])):

        num = abc[p][i][0]

        if path[num] != -1:

            continue

        else:

            path[num] = path[p] + abc[p][i][1]

            dfs(num)

dfs(k)

for i in range(Q):

    print((path[xy[i][0]]+path[xy[i][1]]))

import queue

n = int(input())
abc = [[] for i in range(n + 1)]
for i in range(n - 1):
    a, b, c = list(map(int, input().split()))
    abc[a].append([b, c])
    abc[b].append([a, c])
Q, k = list(map(int, input().split()))
xy = [[int(i) for i in input().split()] for j in range(Q)]
q = queue.Queue()
q.put(k)
path = [-1] * (n + 1)
path[k] = 0
while not q.empty():
    tmp = q.get()
    for i in range(len(abc[tmp])):
        # print(abc[tmp])
        # exit()
        num = abc[tmp][i][0]
        if path[num] != -1:
            continue
        else:
            path[num] = path[tmp] + abc[tmp][i][1]
            q.put(num)
for i in range(Q):
    print((path[xy[i][0]] + path[xy[i][1]]))

import queue
import sys

sys.setrecursionlimit(10**7)
n = int(input())
abc = [[] for i in range(n + 1)]
for i in range(n - 1):
    a, b, c = list(map(int, input().split()))
    abc[a].append([b, c])
    abc[b].append([a, c])
Q, k = list(map(int, input().split()))
xy = [[int(i) for i in input().split()] for j in range(Q)]
q = queue.Queue()
q.put(k)
path = [-1] * (n + 1)
path[k] = 0

def dfs(p):
    for i in range(len(abc[p])):
        num = abc[p][i][0]
        if path[num] != -1:
            continue
        else:
            path[num] = path[p] + abc[p][i][1]
            dfs(num)

dfs(k)
for i in range(Q):
    print((path[xy[i][0]] + path[xy[i][1]]))

-            path[num] = path[tmp] + abc[tmp][i][1]

+            path[num] = path[p] + abc[p][i][1]