Input:
#!usr/bin/env python3

from collections import defaultdict

from collections import deque

from heapq import heappush, heappop

import sys

import math

import bisect

import random

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

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

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

def S(): return list(sys.stdin.readline())[:-1]

def IR(n):

    l = [None for i in range(n)]

    for i in range(n):l[i] = I()

    return l

def LIR(n):

    l = [None for i in range(n)]

    for i in range(n):l[i] = LI()

    return l

def SR(n):

    l = [None for i in range(n)]

    for i in range(n):l[i] = S()

    return l

def LSR(n):

    l = [None for i in range(n)]

    for i in range(n):l[i] = SR()

    return l

mod = 1000000007

#A

"""

def gcd(a,b):

    if a == 0:

        return b

    return gcd(b%a,a)

n = I()

a = IR(n)

l = a[0]

for i in range(1,n):

    g = gcd(l,a[i])

    l *= a[i]//g

print(l)

"""

#B

n = I()

v = [[] for i in range(n)]

for i in range(n-1):

    a,b,c = LI()

    a -= 1

    b -= 1

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

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

Q,k = LI()

d = [-1 for i in range(n)]

d[k-1] = 0

q = deque()

q.append(k-1)

while q:

    x = q.pop()

    for y,c in v[x]:

        if d[y] == -1:

            d[y] = d[x]+c

            q.append(y)

for i in range(Q):

    x,y = LI()

    x -= 1

    y -= 1

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

#C

#D

#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T


Input:
import string

w = input()

for a in string.ascii_lowercase:

    cnt = 0

    for t in w:

        if t == a:

            cnt = cnt + 1

    if cnt % 2 == 1:

        print("No")

        exit()

print("Yes")


Input:
mod = 10**9+7

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

l = [0]*n

for _ in range(m):

  l[int(input())-1] = 1

s = 0

t = 1

for i in range(n):

  if l[i] > 0:

    t, s = 0, t

  else:

    t, s = (s+t)%mod, t

print(t)


Input:
N,M = [int(c) for c in input().split()]

ab = [list(map(int,input().split())) for c in range(N)]

cd = [list(map(int,input().split())) for c in range(M)]

for i in range(N):

    mi = 2*10**9

    for j in range(M):

        tmp = abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1])

        if mi > tmp:

            mi = tmp

            ans = j+1

    print(ans)


Input:
def test():

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

    count = 0

    for i in range(a,b+1):

        j = list(map(int,list(str(i))))

        if j[0] == j[4] and j[1] == j[3]:

            count += 1

    print(count)

if __name__ == "__main__":

    test()


Input:
from bisect import bisect_left

from bisect import bisect_right

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

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

a = sorted(a)

a_count = [0]*100010

a_sum = [0]*100010

for i in range(n):

    a_count[a[i]] += 1

    a_sum[a[i]] += a[i]

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

    a_count[i] += a_count[i+1]

    a_sum[i] += a_sum[i+1]

def chk(x):

    case = 0

    for i in range(n):

        if 0<= x-a[i]<= 10**5+5:

            case += a_count[x-a[i]]

        elif x-a[i] < 0:

            case += n

    if case >= m:

        ch = True

    else:

        ch = False

    return ch

l = 2*a[-1]+1    #NG

r = 1 #OK

while abs(r-l) > 1:

    kk = (r+l)//2

    if chk(kk):

        r = kk

    else:

        l = kk

ans = 0

sm = sum(a)

l = r

case = 0

for i in range(n):

    num = n-bisect_right(a,l-a[i]-1)

    case += num

    ans += num*a[i]*2

ans -= (case-m)*l

print(ans)


Input:
X, Y, Z = list(map(int, input().split()))

for n in range(10 ** 5, 0, -1):

    if X >= n * (Y + Z) + Z:

        break

print(n)


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

if array[0] % array[1] > 0:

    print(((array[0] // array[1] + 1) * array[2]))

else:

    print(((array[0] // array[1]) * array[2]))


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)))


Input:
n=input()

n=int(n)

a=1

for i in range(n):

    a=a*(i+1)

    if a>=pow(10,9)+7:

        a=a%(pow(10,9)+7)

print(a)


Input:
import sys

r = []

n = int(input())

l = sys.stdin.readlines()

for i in l:

  x, y, z = sorted([x*x for x in list(map(int, i.split()))])

  if x + y == z:

      print("YES")

  else:

      print("NO")


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)


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)


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

ans=a*x+b*y

for ci in range(max(x,y)+1):

    sumc = 2*ci*c

    sumc += (x-ci)*a if (x-ci)>0 else 0

    sumc += (y-ci)*b if (y-ci)>0 else 0

    ans=min(ans,sumc)

print(ans)


Input:
a=65280; b=61680; c=52428; d=43690; e=65535

from heapq import heappush, heappop

base = [a, b, c, d, e, 0]

Q = [(1, el) for el in base]

L = {el: 1 for el in base}

H = []

get = L.get

push = H.append

while Q:

    l, p = heappop(Q)

    if L[p] < l: continue

    if l+1 < get(p ^ e, 17):

        L[p ^ e] = l+1

        if l+1 < 16: heappush(Q, (l+1, p ^ e))

    if l+3 < 16:

        for q, r in H:

            if l+r+3 <= 16:

                if l+r+3 < get(p & q, 17):

                    L[p & q] = l+r+3

                    if l+r+3 < 16: heappush(Q, (l+r+3, p & q))

                if l+r+3 < get(p ^ q, 17):

                    L[p ^ q] = l+r+3

                    if l+r+3 < 16: heappush(Q, (l+r+3, p ^ q))

            else: break

    if l < 7: push((p, l))

print(*map(L.__getitem__, eval("e&%s"%",e&".join(open(0).read().replace(*"-~").replace(*"*&").replace(*"1e").split()[:-1]))),sep='\n')


Input:
def examB():

    N = I(); A = [I() for _ in range(N)]

    ans = 0; cur= 0

    for i in A:

        if i==0:

            ans += cur//2

            cur = 0

        else:

            cur += i

    ans += cur // 2

    print(ans)

    return

import sys,copy,bisect,itertools,heapq,math

from heapq import heappop,heappush,heapify

from collections import Counter,defaultdict,deque

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

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

def LSI(): return list(map(str,sys.stdin.readline().split()))

def LS(): return sys.stdin.readline().split()

def SI(): return sys.stdin.readline().strip()

mod = 10**9 + 7

inf = float('inf')

if __name__ == '__main__':

    examB()


Input:
N = int(input())

L = [ 0 ] * 1000000

L[0] = 2

L[1] = 1

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

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

print((L[N]))


Input:
import sys

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

S=set(map(int,sys.stdin))

a,b=0,1

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

    if i in S:

        a,b=b,0

    else:

        a,b=b,a+b

print((b%(10**9+7)))


Input:
import re

while True:

    n = int(input())

    if n == 0:

        break

    l = [0] * (24*60*60+1)

    for _ in range(n):

        h1,m1,s1,h2,m2,s2 = list(map(int, re.split(':| ', input())))

        l[h1*60*60 + m1*60 + s1] += 1

        l[h2*60*60 + m2*60 + s2] -= 1

    r = 0

    for i in range(24*60*60):

        l[i+1] += l[i]

        r = max(r, l[i+1])

    print(r)


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)


Input:
n=int(input())

s=list(map(str,input().split()))

total=[]

for i in range(n):

    if s[i] not in total:

        total.append(s[i])

print(('Three' if len(total)==3 else 'Four'))


Input:
import sys

from collections import Counter, deque, defaultdict

from itertools import accumulate, permutations, combinations, takewhile, compress, cycle

from functools import reduce

from math import ceil, floor, log10, log2, factorial

from pprint import pprint

sys.setrecursionlimit(1000000)

# MOD = 10 ** 9 + 7

# N = int(input())

# A = [int(x) for x in input().split()]

# V = [[0] * 100 for _ in range(100)]

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

N, W = [int(x) for x in input().split()]

dp = [float('inf')] * 1000 * 100*10

vs = set()

vs.add(0)

dp[0] = 0

for i in range(N):

    w, v = [int(x) for x in input().split()]

    tmpDP = dp.copy()

    for vv in list(vs):

        if dp[vv + v] > dp[vv] + w:

            tmpDP[vv + v] = dp[vv] + w

            vs.add(vv + v)

    dp = tmpDP

ans = 0

for v in list(vs):

    if dp[v] <= W:

        ans = max(ans, v)

print(ans)


Input:
from math import factorial

N = int(input())

print((factorial(N) % (10**9 + 7)))


Input:
import math

while True:

	try:

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

		print('%d %d' % (math.gcd(x,y),x/math.gcd(x,y)*y))

	except EOFError:

		break


Input:
n = int(input())

r = int(n**.5)

for i in range(r):

  if n % (r-i) == 0:

    print(( (r-i) + n//(r-i) - 2 ))

    break


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)


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

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

diff = A[0] + K - A[-1]

ans = A[-1] - A[0]

for i in range(1, N):

    dist = K - A[i] + A[i - 1]

    if dist < ans:

        ans = dist

print(ans)


Input:
import sys

input = lambda: sys.stdin.readline().rstrip()

def resolve():

    A, B, C, X, Y = list(map(int, input().split()))

    ans = float('inf')

    for i in range(0, max(X, Y)*2+1, 2):

        ans = min(A*max(X-i//2, 0)+B*max(Y-i//2, 0)+C*i, ans)

    print(ans)

if __name__ == '__main__':

    resolve()


Input:
A,B = list(map(int,input().split()))

ans = 0

for i in range(A,B+1):

    i = str(i)

    if i[0] == i[4]:

        if i[1] == i[3]:

            ans += 1

        else:

            ans += 0

    else:

        ans += 0

print(ans)


Input:
def main():

    N = int(input())

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

    if N == 1:

        return print(1 if A[0] % 2 == 0 else 2)

    ans = 0

    d = (-1, 0, 1)

    from itertools import product

    for i in product(range(3), repeat=N):

        cur = 1

        for j in range(N):

            cur *= (A[j] + d[i[j]])

        if cur % 2 == 0:

            ans += 1

    print(ans)

if __name__ == '__main__':

    main()


Input:
# -*- coding: utf-8 -*-

from collections import defaultdict

from itertools import combinations

N = int(input())

C = [0, 0, 0, 0, 0, 0]

D = defaultdict(int)

for i, m in enumerate("MARCH", start=1):

    D[m] = i

for _ in range(N):

    C[D[input()[0]]] += 1

ans = 0

for a, b, c in combinations(list(range(1, 6)), r=3):

    ans += C[a]*C[b]*C[c]

print(ans)


Input:
import math

N = int(input())

print((math.factorial(N) % (1000000000 + 7)))


Input:
def main():

    from statistics import median

    n, *a, = list(map(int, open(0).read().split()))

    a = [x - i for i, x in enumerate(a, 1)]

    a.sort()

    m = int(median(a))

    ans = sum([abs(x - m) for x in a])

    print(ans)

if __name__ == '__main__':

    main()


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

L, R = [], []

low = -float('INF')

high = float('INF')

for i in range(M):

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

    L.append(l)

    R.append(r)

    if l > low:

        low = l

    if r < high:

        high = r

print((max(0, high - low + 1)))


Input:
a,b,c=1,0,0

exec('a,b,c=b,c,(a+c)%(10**9+7);'*(int(input())-2))

print(c)


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

z = max(x,y) * 2

min_sum = c * z

for i in range(z):

    r = max(0, y - i) * b

    t = max(0, x - i) * a

    sum = c * i * 2 + r + t

    if sum < min_sum:

        min_sum = sum

print(min_sum)


Input:
N = int(input())

a = 1

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

    a = a*n % (10**9+7)

print(a)


Input:
import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

from operator import xor

from functools import reduce

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

a = reduce(xor,(1<<a for a in A))

dp = 0 # bitset

for n in range(K):

    if not(dp&(1<<n)):

        dp |= (a<<n)

answer = 'First' if dp&(1<<K) else 'Second'

print(answer)


Input:
n = int(input())

ans = 0

SQRT = int(n ** 0.5)

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

    b = int(n/m)

    ans += m * (m + b) * (b + 1 - m)

ans -= SQRT * (SQRT+1) * (2*SQRT+1) // 6

print(ans)


Input:
import math

import collections

N = int(input())

a = math.factorial(N)

check = []

ans = 1

i = 2

while a != 1:

    if a % i == 0:

        a //= i

        check.append(i)

    else:

        i += 1

check = list(collections.Counter(check).values())

for i in check:

    ans *= (i+1)

    ans %= 10**9+7

print(ans)


Input:
A,B,C,X,Y=list(map(int,input().split()))

K=10**9

for i in range(10**5+1):

    S=i*2*C+max(0,X-i)*A+max(0,Y-i)*B

    K=min(K,S)

print(K)


Input:
S = int(input())

if S >= 3600:

    h=S//3600

    m=S%3600//60

    s=S%60

elif 3600 > S >= 60:

    h=0

    m=S//60

    s=S%60

else:

    h=m=0

    s=S

print(h, m, s, sep=":")


Input:
def main():

	n, ma, mb, *L = list(map(int, open(0).read().split()))

	M = 1<<30

	dp = [[M] * 420 for _ in range(420)]

	dp[0][0] = 0

	for a, b, c in zip(*[iter(L)] * 3):

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

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

				t = dp[i][j] + c

				if dp[i + a][j + b] > t:

					dp[i + a][j + b] = t

	ans = M

	_ma, _mb = ma, mb

	while _ma < 410 > _mb:

		ans = min(ans, dp[_ma][_mb])

		_ma += ma

		_mb += mb

	print((ans if ans < M else -1))

if __name__=="__main__":

	main()


Input:
_,s=open(c:=0)

for a in sorted(map(int,s.split())):c=a-c

print(c)


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"))


Input:
from statistics import mean

inputCount = int(input())

prices = [int(input()) for lp in range(inputCount)]

average = mean(prices)

print((int(average)))


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)


Input:
x = int(input())

print((0 if x==1 else 1))


Input:
def binarySearch():

    n = int(input())

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

    q = int(input())

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

    print((len(S.intersection(T))))

binarySearch()


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

ans=0

for i in range(a,b+1):

    buf=str(i)

    #print(buf[0:int(len(buf)/2)],buf[int(len(buf)/2+1):])

    str1=buf[0:int(len(buf)/2)]

    str2=buf[int(len(buf)/2+1):]

    if str1[0]==str2[1] and str1[1]==str2[0]:

        ans+=1

print(ans)


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

RD = list(list(map(int, input().split())) for _ in range(m))

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

    ans = 0

    for j in RD:

        ans += j.count(i)

    print(ans)


Input:
N = int(input())

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

cnt = 0

for i in x:

  while i % 2 == 0:

    cnt += 1

    i /= 2

print(cnt)


Input:
def popcount(x):

    x = x - ((x >> 1) & 0x55555555)

    x = (x & 0x33333333) + ((x >> 2) & 0x33333333)

    x = (x + (x >> 4)) & 0x0f0f0f0f

    x = x + (x >> 8)

    x = x + (x >> 16)

    return x & 0x0000007f

cmb=[[0 for i in range(51)] for j in range(51)]

cmb[0][0]=1

for i in range(51):

    for j in range(51):

        if i!=50 and j!=50:

            cmb[i+1][j+1]+=cmb[i][j]

        if i!=50:

            cmb[i+1][j]+=cmb[i][j]

for i in range(1,51):

    for j in range(2,51):

        cmb[i][j]+=cmb[i][j-1]

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

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

must0=[i for i in range(18) if S>>i &1==0]

must1=[i for i in range(18) if T>>i &1==1]

A=[]

for val in a:

    check=True

    for j in must0:

        check=check&(val>>j &1==0)

    for j in must1:

        check=check&(val>>j &1==1)

    if check:

        A.append(val)

if not A:

    print((0))

    exit()

bit=[]

for i in range(18):

    if i not in must0 and i not in must1:

        bit.append(i)

for i in range(len(A)):

    temp=0

    for j in range(len(bit)):

        temp+=(A[i]>>bit[j] &1==1)*2**j

    A[i]=temp

ans=0

n=len(bit)

data=[0]*(2**n)

for i in range(2**n):

    t=set([])

    for a in A:

        data[a&i]+=1

        t.add(a&i)

    temp=0

    for val in t:

        temp+=cmb[data[val]][min(K,data[val])]

    ans+=temp*(-1)**popcount(i)

    for val in t:

        data[val]=0

print(ans)


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()


Input:
import sys

sys.setrecursionlimit(10**6)

def dfs(v,p,d):

    for i, j in tree[v]:

        if i != p:

            depth[i] = d + j

            dfs(i,v,d+j)

N = int(input())

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

for i in range(N-1):

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

    a -= 1

    b -= 1

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

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

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

depth = [0 for i in range(N)]

depth[K-1] = 0

dfs(K-1,-1,0)

for _ in range(Q):

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

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


Input:
import math

n = int(input())

power = math.factorial(n)

print((power % (10**9 + 7)))


Input:
#!/usr/bin/env python3

import sys

INF = float("inf")

from bisect import bisect_left

def solve(N: int, K: int, A: "List[int]", F: "List[int]"):

    A.sort()

    F.sort(reverse=True)

    h = []

    for a, f in zip(A, F):

        h.append((a*f, a, f))

    h.sort()

    maxtime = h[-1][0]

    def isOK(y):

        i = bisect_left(h, (y+1, -1, -1))

        counter = 0

        # print(h[i:])

        for p, a, f in h[i:]:

            counter += a-y//f

        return counter <= K

    def binary_search(x):

        ng = -1

        ok = len(x)

        while abs(ok - ng) > 1:

            mid = (ok + ng)//2

            # print("mid: {}, in ({}, {})".format(mid, ng, ok))

            if isOK(mid):

                ok = mid

            else:

                ng = mid

        return ng, ok

    ng, ok = binary_search(list(range(maxtime)))

    print(ok)

    # while k > 0:

    #     p1, a1, f1 = heapq.heappop(h)

    #     p2, a2, f2 = heapq.heappop(h)

    #     p1, p2 = -p1, -p2

    #     sub = min(a1 - math.ceil((p2/f1)-1), k)

    #     a1 -= sub

    #     k -= sub

    #     heapq.heappush(h, (-a1*f1, a1, f1))

    #     heapq.heappush(h, (-a2*f2, a2, f2))

    # # print(h)

    # p, a, f = heapq.heappop(h)

    # print(-p)

    return

def main():

    def iterate_tokens():

        for line in sys.stdin:

            for word in line.split():

                yield word

    tokens = iterate_tokens()

    N = int(next(tokens))  # type: int

    K = int(next(tokens))  # type: int

    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"

    F = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"

    solve(N, K, A, F)

if __name__ == '__main__':

    main()


Input:
import math

n = int(input())

print((math.factorial(n)%(10**9+7)))


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]))


Input:
A,B = list(map(int,input().split()))

def kaibun(n):

	key = 0

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

		if str(i) == str(i)[::-1]:

			key += 1

	return key

print((kaibun(B)-kaibun(A-1)))


Input:
from sys import stdin

def solve():

    s = int(stdin.readline())

    mod = 10**9+7

    if s < 3: return 0

    dp = [0]*(s+1)

    dp[0] = 1

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

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

            if x in [i-1,i-2]:

                continue

            dp[i] += dp[i-x]

    return dp[s]%mod

print((solve()))


Input:
N = int(input())

s_list = {}

for i in range(N):

  S = input()

  if S in list(s_list.keys()):

    s_list[S] += 1

  else:

    s_list[S] = 0

max = 0

maxs = []

for s,c in list(s_list.items()):

  if c > max:

    maxs = [s]

    max = c

  elif c == max:

    maxs.append(s)

maxs.sort()

for m in maxs:

  print(m)


Input:
import math

x = int(input())

print((math.factorial(x) % (10**9 + 7)))


Input:
S = input()

N = len(S)

left = S[:int(N/2)]

right = S[int((N+2)/2):]

S_reversed = "".join(reversed(list(S)))

left_reversed = "".join(reversed(list(left)))

right_reversed = "".join(reversed(list(right)))

if S == S_reversed and left == left_reversed and right == right_reversed:

    print("Yes")

else:

    print("No")


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

ans=0

for i in range(b+1)[a:]:

  if len(str(i))%2==0:

    p=list(str(i))[:len(str(i))//2]

    q=list(reversed(list(str(i))[len(str(i))//2:]))

    if p==q:

      ans+=1

  else:

    s=list(str(i))[:len(str(i))//2+1]

    d=list(reversed(list(str(i))[len(str(i))//2:]))

    if s==d:

      ans += 1

print(ans)


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)


Input:
while int(input()) > 0:

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

    print((min(abs(a - b) for (a, b) in zip(s, s[1:]))))


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)


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()


Input:
A, B = list(map(int, input().split()))

numbers = list(range(A, B+1))

count = 0

for i in numbers:

    m = str(i)

    rm = ''.join(list(reversed(m)))

    if m == rm:

        count += 1

print(count)


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)


Input:
import sys

read = sys.stdin.read

readline = sys.stdin.readline

readlines = sys.stdin.readlines

sys.setrecursionlimit(10 ** 9)

INF = 1 << 60

MOD = 1000000007

# Reference: https://www.geeksforgeeks.org/queries-number-distinct-elements-subarray/

# Python3 code to find number of

# distinct numbers in a subarray

MAX = 1000001

# structure to store queries

class Query:

    def __init__(self, l, r, idx):

        self.l = l

        self.r = r

        self.idx = idx

# updating the bit array

def update(idx, val, bit, n):

    while idx <= n:

        bit[idx] += val

        idx += idx & -idx

# querying the bit array

def query(idx, bit, n):

    summ = 0

    while idx:

        summ += bit[idx]

        idx -= idx & -idx

    return summ

def answeringQueries(arr, n, queries, q):

    # initialising bit array

    bit = [0] * (n + 1)

    # holds the rightmost index of

    # any number as numbers of a[i]

    # are less than or equal to 10^6

    last_visit = [-1] * MAX

    # answer for each query

    ans = [0] * q

    query_counter = 0

    for i in range(n):

        # If last visit is not -1 update -1 at the

        # idx equal to last_visit[arr[i]]

        if last_visit[arr[i]] != -1:

            update(last_visit[arr[i]] + 1, -1, bit, n)

        # Setting last_visit[arr[i]] as i and

        # updating the bit array accordingly

        last_visit[arr[i]] = i

        update(i + 1, 1, bit, n)

        # If i is equal to r of any query store answer

        # for that query in ans[]

        while query_counter < q and queries[query_counter].r == i:

            ans[queries[query_counter].idx] = query(queries[query_counter].r + 1, bit, n) - query(

                queries[query_counter].l, bit, n

            )

            query_counter += 1

    # print answer for each query

    for i in range(q):

        print((ans[i]))

# This code is contributed by

# sanjeev2552

def main():

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

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

    (*LR,) = list(map(int, read().split()))

    queries = [0] * Q

    for i, (l, r) in enumerate(zip(*[iter(LR)] * 2)):

        queries[i] = Query(l - 1, r - 1, i)

    queries.sort(key=lambda x: x.r)

    answeringQueries(C, N, queries, Q)

    return

if __name__ == '__main__':

    main()


Input:
k = int(input())

num = 0

if not k%2:

    print((-1))

else:

    for i in range(k):

        num = (num*10+7)%k

        if num == 0:

            print((i+1))

            break

    else:

        print((-1))


Input:
k = int(input())

count = 1

n = 0

if k % 2 == 0 or k % 5 == 0:

    print((-1))

else:

  while 1:

      n = (n * 10 + 7) % k

      if n == 0:

        break

      count += 1

  print(count)


Input:
a, b, c = sorted(map(int, input().split()))

print((c*10 + b + a))


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

ans = float('inf')

for i in range(200005):

    tmp = i * 2 * c

    tmp += max(0, x-i) * a

    tmp += max(0, y-i) * b

    ans = min(ans, tmp)

print(ans)


Input:
N = int(input())

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

def dfs(A_s, index,Bss):

    if index == N:

        tmp = 1

        for b in Bss:

            tmp *= b

        return 1 if tmp % 2 == 0 else 0

    b_mi = Bss.copy()

    b_mi.append(A_s[index] - 1)

    b = Bss.copy()

    b.append(A_s[index])

    b_pl = Bss.copy()

    b_pl.append(A_s[index] + 1)

    return dfs(A_s,index + 1, b_mi) + dfs(A_s,index + 1,b) + dfs(A_s,index + 1,b_pl)

print((dfs(As,0,[])))


Input:
import math

n=int(input())

print((math.factorial(n)%(10**9+7)))


Input:
from sys import stdin

from math import factorial

def combinations_count(n, r):

    return factorial(n) // (factorial(n - r) * factorial(r))

def combinations_with_replacement_count(n, r):

    return combinations_count(n + r - 1, r)

def main():

    _in = [_.rstrip() for _ in stdin.readlines()]

    S = int(_in[0])  # type:int

    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

    min_ = 1

    max_ = S // 3

    ans = 0

    for i in range(min_, max_ + 1):

        mod = S - i * 3

        ans += combinations_with_replacement_count(mod + 1, i - 1) % (10**9 + 7)

    ans %= (10**9 + 7)

    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

    print(ans)

if __name__ == "__main__":

    main()


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")


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]))


Input:
n=int(input())

D={}

DD={}

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

   s=(str(i)[0],str(i)[-1])

   t=(str(i)[-1],str(i)[0])

   if s not in D:

      D[s]=1

   else:

      D[s]+=1

   if t not in DD:

      DD[t]=1

   else:

      DD[t]+=1

ans=0

for i in D:

   if i in DD:

      ans+=D[i]*DD[i]

print(ans)


Input:
import math

N = int(input())

ans = 0

ans =math.factorial(N) % (10**9 +7)

print(ans)


Input:
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()))

asort,bsort,csort = sorted(A,reverse=True),sorted(B,reverse=True),sorted(C,reverse=True)

print((asort[0] + bsort[0] + csort[0]))

already = [[0,0,0]]

x,y,z = 0,0,0

place_sum = []

check = []

for k in range(K - 1):

    if [x + 1,y,z] not in already and x + 1 < X:

        already.append([x + 1,y,z])

        place_sum.append([x + 1,y,z])

        check.append(asort[x + 1] + bsort[y] + csort[z])

    if [x,y + 1,z] not in already and y + 1 < Y:

        already.append([x,y + 1,z])

        place_sum.append([x,y + 1,z])

        check.append(asort[x] + bsort[y + 1] + csort[z])

    if [x,y,z + 1] not in already and z + 1 < Z:

        already.append([x,y,z + 1])

        place_sum.append([x,y,z + 1])

        check.append(asort[x] + bsort[y] + csort[z + 1])

    print((max(check)))

    x,y,z = place_sum[check.index(max(check))][0],place_sum[check.index(max(check))][1],place_sum[check.index(max(check))][2]

    place_sum.pop(check.index(max(check)))

    check.remove(max(check))


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

ans=a*x+b*y

n=max(x,y)

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

  ans=min(ans,2*i*c+a*max(0,x-i)+b*max(0,y-i))

print(ans)


Input:
answer = 0

N = int(input())

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

for i in range(N) :

    while A[i] % 2 == 0 :

        A[i] = A[i] / 2

        answer += 1

print(answer)


Input:
import sys

def main():

    input = sys.stdin.readline

    N = int(input())

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

    ans = 0

    for C in range(1, N//2):

        n = N // C

        point = 0

        used = set([0])

        for k in range(1, n):

            A = N - 1 - k*C

            if A in used or k*C in used or A == k*C:

                break

            used.add(A)

            used.add(k*C)

            point += S[A] + S[k*C]

            ans = max(ans, point)

    return ans

if __name__ == '__main__':

    print((main()))


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()


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)


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)


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"))


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

ans = 0

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

    if str(i)[0]+str(i)[1] == str(i)[-1]+str(i)[-2]: ans += 1

print(ans)


Input:
ans=[]

for i in range (0,10):

    ans.append(int(input()))

ans.sort(reverse=True)

for i in range (0,3):

    print((ans[i]))


Input:
# -*- coding: utf-8 -*-

import sys

def main():

    S = int( sys.stdin.readline() )

    dp = [0]*(S+1)

    dp[0] = 1

    mod = 10**9 + 7

    for i in range(3, S+1):

        cnt = 0

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

            cnt += dp[i-j]

            cnt %= mod

        dp[i] = cnt

    print((dp[-1]))

if __name__ == "__main__":

    main()


Input:
def solve():

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

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

  if K>=N:

    return 0

  H.sort()

  ans = sum(H[:N-K])

  return ans

print((solve()))


Input:
k, s = list(map(int, input().split()))

ans = 0

for x in range(k+1):

  for y in range(k+1):

    if 0<=s-x-y<=k:

      ans += 1

print(ans)


Input:
import sys

N = int(input())

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

l = 1

p = a[0] - 1

if a[0] == 2:

    print(l)

    sys.exit()

while l < int(1e6):

    l += 1

    if a[p] == 2:

        print(l)

        break

    else:

        p = a[p] - 1

else:

    print((-1))


Input:
import math

def main():

    N = int(input())

    power = math.factorial(N)

    print((power % (10 ** 9 + 7)))

if __name__ == "__main__":

    main()


Input:
def post_from_pre_in(preorder_elements, inorder_elements):

    if preorder_elements:

        global cnt

        root = preorder_elements[0]

        root_index = inorder_elements.index(root)

        preorder_left = preorder_elements[1:root_index+1]

        inorder_left = inorder_elements[:root_index]

        preorder_right = preorder_elements[root_index+1:]

        inorder_right = inorder_elements[root_index+1:]

        post_from_pre_in(preorder_left, inorder_left)

        post_from_pre_in(preorder_right, inorder_right)

        if cnt:

            print(root, end = ' ')

            cnt -= 1

        else:

            print(root)

cnt = int(input()) - 1

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

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

post_from_pre_in(a, b)


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()


Input:
from math import sqrt

from bisect import bisect_left

def circle_center(x1, y1, x2, y2):

    xd = x2 - x1; yd = y2 - y1

    d = xd**2 + yd**2

    k = sqrt((4.0 - d) / d) / 2.0

    xc = (x1 + x2) / 2.0

    yc = (y1 + y2) / 2.0

    return [[xc - k*yd, yc + k*xd], [xc + k*yd, yc - k*xd]]

while 1:

    n = int(input())

    if n==0: break

    p = [list(map(float, input().split())) for i in range(n)]

    p.sort()

    prev = 0

    ans = 1

    for i in range(n):

        bx, by = p[i]

        while bx - p[prev][0] >= 2.0: prev += 1

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

            cx, cy = p[j]

            if cx - bx >= 2.0: break

            if (bx - cx)**2 + (by - cy)**2 <= 4.0:

                for ex, ey in circle_center(bx, by, cx, cy):

                    count = 2

                    for k in range(prev, n):

                        if k==i or k==j: continue

                        dx, dy = p[k]

                        if dx - bx >= 2.0: break

                        if (ex - dx)**2 + (ey - dy)**2 <= 1.0:

                            count += 1

                    ans = max(ans, count)

    print(ans)


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()))


Input:
import math

N = int(input())

ans = math.factorial(N) % (10 ** 9 + 7)

print(ans)


Input:
#python3

INF = int(1e9)

def main():

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

    ans = INF

    for i in range(2*10**5+100):

        t = 2*c*i + max(x-i, 0) * a + max(y-i, 0) * b

        ans = min(ans, t)

    print(ans)

main()


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)))


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

ans = 0

for i in range(K+1):

	for j in range(K+1):

		if (S - i - j) <= K and (S-i-j) >= 0:

			ans += 1

print(ans)


Input:
while 1:

    ans=0

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

    if n:

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

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

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

                    if i+j+k==x:ans+=1

    else:break

    print(ans)


Input:
def main():

  from statistics import mean

  from math import floor,ceil

  n = int(input())

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

  x_mean = mean(x)

  if x_mean == 0.5:

      greater_than_x = len([i for i in x if i > x_mean])

      if greater_than_x * 2 >= n:

          x_mean = ceil(x_mean)

      else:

          x_mean = floor(x_mean)

  elif x_mean % 1 > 0.5:

      x_mean = ceil(x_mean)

  else:

      x_mean = floor(x_mean)

  x2 = [(num - x_mean)**2 for num in x]

  print((sum(x2)))

main()


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")


Input:
from collections import defaultdict

N = int(input())

A = [input() for _ in range(N)]

A.sort()

d = defaultdict(int)

for a in A:

    d[a] += 1

l = sorted(d.items())

max_v = 0

for _, v in l:

    if v > max_v:

        max_v = v

for k, v in l:

    if v == max_v:

        print(k)

    else:

        continue


Input:
n = int(input())

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

a_index = []

for i in range(n):

    a_index.append((i, a[i]))

dic1 = {}

dic2 = {}

for i in range(n):

    one = a_index[i][0] + a_index[i][1]

    two = a_index[i][0] - a_index[i][1]

    if one not in dic1:

        dic1[one] = 1

    else:

        dic1[one] += 1

    if two not in dic2:

        dic2[two] = 1

    else:

        dic2[two] += 1

ans = 0

for i in list(dic1.keys()):

    if i in dic2:

        ans += dic2[i] * dic1[i]

for i in list(dic2.keys()):

    if i in dic1:

        ans += dic1[i] * dic2[i]

        #print(i)

print((ans // 2))


Input:
k,s=list(map(int,input().split()))

ans=chk=0

for i in range(k+1):

    for j in range(k+1):

        if (0<=s-i-j<=k): ans+=1

print(ans)


Input:
N,K = int(input()), int(input())

now = 1

for i in range(N):

    if now*2 < now + K:

        now *= 2

    else:

        now += K

print(now)


Input:
import math

n=int(input())

ans=n

i=1

while(i<=math.sqrt(n)):

    if n%i==0:

        d=i+n/i-2

        ans=min(ans,d)

    i+=1

print((int(ans)))


Input:
import math

N = int(input())

power = math.factorial(N)

print((power % 1000000007))


Input:
n, k = list(map(int, input().split()))

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

dp = ["Second"] * (k + 1)

for i in range(k + 1):

    if dp[i] == "Second":

        for a in a_s:

            ii = i + a

            if ii <= k:

                dp[ii] = "First"

print((dp[-1]))


Input:
S, T = [list(input()) for _ in range(2)]

cnt = 0

for i in range(len(S)):

    if S[i] != T[i]:

        cnt += 1

print(cnt)


Input:
N = int(input())

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

cnt = 0

for i in range(N-1):

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

        cnt += D[i]*D[j]

print(cnt)


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

mn = [0]*N

for i in range(N):

  mn[i] = int(input())

ans = N

x = X - sum(mn)

while(x >= min(mn)):

  if x // min(mn) == 0:

    mn[mn.index(min(mn))] = 1000000

  else:

    if x >= min(mn):

      x -= min(mn)

      ans += 1

print(ans)


Input:
#! /usr/bin/env python3

import sys

int1 = lambda x: int(x) - 1

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

sys.setrecursionlimit(500000)

def isMultiple(s, m):

    tmp = 0

    for i in range(len(s)):

        tmp = (tmp * 10 + int(s[i])) % m

        if tmp == 0:

            return i

    return -1

k = int(readline())

acc = "7" * 50000000

if k % 2 == 0:

    ans = -1

else:

    ans = isMultiple(acc, k)

    if ans != -1:

        ans += 1

print(ans)


Input: n,*l=list(map(int,open(0).read().split()));print((sum(sorted(l*2)[-2:~n:-1])))


Input:
import math

N = int(input())

for i in range(int(math.sqrt(N))):

    if N % (int(math.sqrt(N))-i) == 0:

        print((int(N/(int(math.sqrt(N))-i)+int(math.sqrt(N))-i-2)))

        break


Input:
N, L = [int(i) for i in input().split()]

min_ = L

max_ = L + N -1

def eat_apple():

    if max_<0:

        return max_

    if L < 0:

        return 0

    return L

print(((min_+max_)*(max_-min_+1)//2 - eat_apple()))


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)


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()


Input:
S = [int(_) for _ in input()]

length = len(S)

temp = [S[0]]

for x in S[1:]:

    if(len(temp) == 0):

        temp.append(x)

    elif( temp[-1] == x):

        temp.append(x)

    else:

        temp.pop(-1)

print((length-len(temp)))


Input:
K = int(input())

flg = [False]*K

tmp = 7 % K

cnt = 1

if tmp == 0:

    print(cnt)

    exit()

while True:

    tmp = (tmp*10+7)%K

    if flg[tmp]:

        print((-1))

        break

    else:

        cnt += 1

        if tmp == 0:

            print(cnt)

            break

        flg[tmp] = True


Input:
from math import factorial

print((factorial(int(input())) % (10**9+7)))


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)))


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

count = 0

for i in range(N):

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

    if (a**2 + b**2) <= D**2:

        count += 1

print(count)


Input:
# ABC102C - Linear Approximation (ARC100C)

from statistics import median

def main():

    n = int(input())

    A = tuple(map(int, input().rstrip().split()))

    A = tuple(j - i for i, j in enumerate(A, start=1))

    b = median(A)

    ans = sum(abs(a - b) for a in A)

    print((int(ans)))

if __name__ == "__main__":

    main()


Input:
a=65280; b=61680; c=52428; d=43690; e=65535

L = {el: 1 for el in [a, b, c, d, e, 0]}

for i in range(6):

    R = sorted(L.items(), key=lambda x: x[1])

    for p, l in R:

        if l < 16:

            L[p ^ e] = min(L.get(p ^ e, 16), l+1)

            if l+3 < 16:

                for q, r in R:

                    if l+r+3 <= 16:

                        L[p & q] = min(L.get(p & q, 16), l+r+3)

                        L[p ^ q] = min(L.get(p ^ q, 16), l+r+3)

                    else: break

        else: break

print(*(L[e & eval(s)] for s in open(0).read().replace(*"-~").replace(*"*&").replace(*"1e").split()[:-1]),sep='\n')


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()


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

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

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

bc.sort(key=lambda x: x[1], reverse=True)

a.sort()

i = 0

for b, c in bc:

    for _ in range(b):

        if i < n and a[i] < c:

            a[i] = c

            i += 1

        else:

            break

ans = sum(a)

print(ans)


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)


Input:
import math

n = int(input())

print((math.factorial(n)%(10**9+7)))


Input:
S = list(input())

num_one = S.count("1")

num_zero = S.count("0")

ans = min(num_one, num_zero) *2

print(ans)


Input:
import sys

can = True; input()

e = [[0, 0, 0]] + [list(map(int, e.split())) for e in sys.stdin]

for a, b in zip(e[1:], e):

    t = a[0] - b[0] - abs(a[1] - b[1]) - abs(a[2] - b[2])

    if t < 0 or t % 2 == 1: can = False; break

print((['No', 'Yes'][can]))


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]))


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))


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

sunuke = [True]*N

for i in range(K):

    d = int(input())

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

    for a in A:

        sunuke[a-1] = False

ans = 0

for i in range(N):

    if sunuke[i]:

        ans += 1

print(ans)


Input:
import sys

def input(): return sys.stdin.readline().strip()

def resolve():

    import math

    n=int(input())

    print((math.factorial(n)%(10**9+7)))

resolve()


Input:
A,B = list(map(int,input().split()))

j = 0

for i in range(A,B+1):

  l = list(str(i))

  l_reverse = list(reversed(l))

  if l == l_reverse:

    j += 1

print(j)


Input:
s = int(input())

m, s = s // 60, s % 60

h, m = m // 60, m % 60

print((':'.join(map(str, [h,m,s]))))


Input:
import math

N = int(input())

print((math.factorial(N)%(10**9+7)))


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()


Input:
import functools

print((len(functools.reduce(lambda x, y: x&y,[set(input().split()[1:]) for _ in [0]*int(input().split()[0])]))))


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))


Input:
N = int(input())

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

SUM = 0

for i in A:

    count = 0

    while i%2 == 0:

        i//=2

        count += 1

    SUM+=count

print(SUM)


Input:
n = int(input())

INF = 10**9 + 7

ans = [0] * (10**5 + 1)

ans[0] = 1

for i in range(1,10**5 + 1):

    ans[i] = ans[i-1] * i % INF

print((ans[n]))


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

ans = a * x + b * y

m = max(x, y)

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

  x -= 1

  y -= 1

  if x < 0:

    x = 0

  if y < 0:

    y = 0

  temp = c*(i*2) + x*a + y*b

  if temp < ans:

    ans = temp

print(ans)


Input:
n=int(input())

s=input()

x=["SS","SW","WS","WW"]

def check0(i):

    if x[i][0]=="S":

        if s[0]=="o":

            if x[i][-1]=="S":

                return x[i][1]=="S"

            else:

                return x[i][1]=="W"

        else:

            if x[i][-1]=="S":

                return x[i][1]=="W"

            else:

                return x[i][1]=="S"

    else:

        if s[0]=="o":

            if x[i][-1]=="S":

                return x[i][1]=="W"

            else:

                return x[i][1]=="S"

        else:

            if x[i][-1]=="S":

                return x[i][1]=="S"

            else:

                return x[i][1]=="W"

def check1(i):

    if x[i][n-1]=="S":

        if s[n-1]=="o":

            if x[i][n-2]=="S":

                return x[i][0]=="S"

            else:

                return x[i][0]=="W"

        else:

            if x[i][n-2]=="S":

                return x[i][0]=="W"

            else:

                return x[i][0]=="S"

    else:

        if s[n-1]=="o":

            if x[i][n-2]=="S":

                return x[i][0]=="W"

            else:

                return x[i][0]=="S"

        else:

            if x[i][n-2]=="S":

                return x[i][0]=="S"

            else:

                return x[i][0]=="W"

for i in range(4):

    for j in range(n-2):

        if x[i][j+1]=="S":

            if s[j+1]=="o":

                if x[i][j]=="S":

                    x[i]+="S"

                else:

                    x[i]+="W"

            else:

                if x[i][j]=="S":

                    x[i]+="W"

                else:

                    x[i]+="S"

        else:

            if s[j+1]=="o":

                if x[i][j]=="S":

                    x[i]+="W"

                else:

                    x[i]+="S"

            else:

                if x[i][j]=="S":

                    x[i]+="S"

                else:

                    x[i]+="W"

    #print(x[i])

    if check0(i) and check1(i):

        print((x[i]))

        break

else:

    print((-1))


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)))


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

point = []

for i in range(N):

    point.append(list(map(int, input().split())))

ct = 0

D2 = D * D

for i in point:

    if (i[0]**2 + i[1]**2) <= D2:

        ct += 1

print(ct)


Input:
from math import factorial

mod = 10**9 + 7

n = int(input())

ans = factorial(n) % mod

print(ans)


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


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)


Input:
from collections import Counter

import sys

input = sys.stdin.readline

def solve():

    N = int(input())

    Sss = [input().rstrip() for _ in range(N)]

    cnt = Counter(Sss)

    #print('cnt:', cnt)

    maxNum = max(cnt.values())

    #print('maxNum:', maxNum)

    anss = []

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

        if value == maxNum:

            anss.append(key)

    #print('anss:', anss)

    anss.sort()

    print(('\n'.join(anss)))

solve()


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)


Input:
from functools import lru_cache

import sys

sys.setrecursionlimit(2000)

s = int(input())

mod = 10 ** 9 + 7

@lru_cache(maxsize=None)

def dfs(n):

    if n <= 2:

        return 0

    elif 3<=n<=5:

        return 1

    else:

        count = 1

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

            count += dfs(n - i)

            count %= mod

        return count % mod

ans = dfs(s)

print(ans)


Input:
n,k = list(map(int,input().split()))

num = 0

q = []

for i in range(n):

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

    q.append((a,b))

q.sort()

for i in range(n):

    a, b = q[i][0], q[i][1]

    num += b

    if num >= k:

        print(a)

        exit()


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')


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

cnt=0

for i in range(a,b+1):

    n=list(str(i))

    if n==list(reversed(n)):

        cnt+=1

print(cnt)


Input:
a, b = list(map(int, input().strip().split(" ")))

count = 0

for i in range(a, b + 1):

    if str(i) == str(i)[::-1]:

        count += 1

print(count)


Input:
import math

N = int(input())

p = math.factorial(N)

print((p % 1000000007))


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)


Input:
N = int(input())

def dist(i, j):

    return i + j - 2

min = 10 ** 24

i = 1

while (i ** 2) <= N:

    if 0 == N % i:

        j = N // i

        d = dist(i, j)

        if min > d:

            min = d

    i += 1

print(d)


Input:
n = int(input())

print((1 if n == 0 else 0))


Input:
import sys

readline = sys.stdin.readline

sys.setrecursionlimit(10**8)

mod = 10**9+7

#mod = 998244353

INF = 10**18

eps = 10**-7

m,n,k = list(map(int,readline().split()))

def comb(n, r, mod):

    r = min(r, n-r)

    mol = 1

    deno = 1

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

        mol = mol * (n-r+i) % mod

        deno = deno * i % mod

    ret = mol * pow(deno, mod-2, mod) % mod

    return ret

def f1(x,y,a,b):

    return (a+b-x-y)*(a-x+1)*(b-y+1)//2

def f2(x,a):

    return (a-x)*(a-x+1)//2

ans = 0

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

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

        ans += f1(x,y,n,m)+f1(1,1,x,y)+f1(1,y,x,m)+f1(x,1,n,y)

        ans -= f2(x,n) + f2(1,x) + f2(1,y) + f2(y,m)

        ans %= mod

ans = (ans * comb(m*n-2,k-2,mod))%mod

ans = ans*pow(2,mod-2,mod)%mod

print(ans)


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))


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

MOD = 10**9+7

dp = [0]*(N+1)

dp[0]=1

A = [int(input()) for i in range(M)]

ban = [1]*(N+1)

for a in A:

    ban[a]=0

for i in range(N):

    if i-1>=0:

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

    else:

        dp[i+1]=dp[i]*ban[i]

    dp[i+1] %= MOD

print((dp[N]))


Input:
def main():

    A, B, AB, X, Y = list(map(int, input().split()))

    M = max(X, Y)

    k = 0

    ans = A * X + B * Y

    while True:

        ans = min(

            ans,

            AB * k * 2 + max(0, X - k) * A + max(0, Y - k) * B

        )

        if k >= M: break

        k += 1

    print(ans)

if __name__ == '__main__':

    main()


Input:
import sys

init = ''.join(sys.stdin.read().split())

# Bidirectional search using breadth-first search

def solve(start, goal):

    if start == goal:

        return 0

    generated_state = {start: 0, goal: 1}   # 0: foreward, 1: backward

    step = {start: 0, goal: 0}

    s = 0

    c_d = [(start, 0), (goal, 1)] # configure and direction

    while True:

        q = iter(c_d)

        c_d = []

        s += 1

        for c, d in q:

            i = c.find('0')

            if 0 <= i <= 5:

                t = str.maketrans('0' + c[i+3], c[i+3] + '0')

                t_c = c.translate(t)

                if t_c in generated_state:

                    if generated_state[t_c] != d:

                        return s + step[t_c]

                else:

                    generated_state[t_c] = d

                    step[t_c] = s

                    c_d.append((t_c, d))

            if i >= 3:

                t = str.maketrans('0' + c[i-3], c[i-3] + '0')

                t_c = c.translate(t)

                if t_c in generated_state:

                    if generated_state[t_c] != d:

                        return s + step[t_c]

                else:

                    generated_state[t_c] = d

                    step[t_c] = s

                    c_d.append((t_c, d))

            if i == 0 or i == 1 or i == 3 or i == 4 or i == 6 or i == 7:

                t = str.maketrans('0' + c[i+1], c[i+1] + '0')

                t_c = c.translate(t)

                if t_c in generated_state:

                    if generated_state[t_c] != d:

                        return s + step[t_c]

                else:

                    generated_state[t_c] = d

                    step[t_c] = s

                    c_d.append((t_c, d))

            if i == 1 or i == 2 or i == 4 or i == 5 or i == 7 or i == 8:

                t = str.maketrans('0' + c[i-1], c[i-1] + '0')

                t_c = c.translate(t)

                if t_c in generated_state:

                    if generated_state[t_c] != d:

                        return s + step[t_c]

                else:

                    generated_state[t_c] = d

                    step[t_c] = s

                    c_d.append((t_c, d))

print((solve(init, '123456780')))


Input:
def popcount(x):

  r, q = 0, x

  while x:

    r += 1

    x &= x - 1

  return r, q

n = int(input())

r = list(range(n))

a = [[0, 0] for _ in r]

for i in r:

  for _ in range(int(input())):

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

    a[i][y] |= 1 << (x - 1)

l = (1 << n) - 1

b = sorted(map(popcount, list(range(1, l + 1))))

ans = next((i for i, x in reversed(b)

           if all(a[j][0] & x == a[j][1] & l - x == 0 for j in r if x >> j & 1)), 0)

print(ans)


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]]))


Input:
W,H,x,y,r = [int(i) for i in input().split()]

if x - r >= 0 and x + r <= W and y - r >= 0 and y + r <= H:

    print("Yes")

else:

    print("No")


Input:
from math import log2

n = int(input())

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

ans = 0

for _a in a:

    if _a%2 == 0:

        cnt =0

        while _a%2 == 0:

            _a //= 2

            cnt += 1

        ans += cnt

print((int(ans)))


Input:
# coding: utf-8

def solve(*args: str) -> str:

    n, m, k = list(map(int, args[0].split()))

    mod = 998244353

    if m == 1 and n-1 == k:

        return str(1)

    ncr = 1

    p = m*pow(m-1, n-1, mod) % mod

    ret = p

    inv = pow(m-1, mod-2, mod)

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

        ncr = (ncr * (n-i)*pow(i, mod-2, mod)) % mod

        p = (p*inv) % mod

        ret += p*ncr % mod

    return str(ret % mod)

if __name__ == "__main__":

    print((solve(*(open(0).read().splitlines()))))


Input:
import collections as col

def prime(n):

    ans = []

    num = n

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

        if i%2==0 and i!=2: continue

        while num%i == 0: num //= i ; ans.append(i)

    return ans

n = int(input())

mod = 10**9 + 7

primes = []

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

cnt = col.Counter(primes)

ans = 1

for key,val in list(cnt.items()): ans *= (val + 1) ; ans %= mod

print(ans)


Input:
import sys

def main():

    input = sys.stdin.readline

    N = int(input())

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

    for i in range(N-1):

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

        a, b = a-1, b-1

        E[a].append((b,i))

        E[b].append((a,i))

    def dfs(s, g):

        par = [(-1,-1)] * N

        par[s] = (s,-1)

        stack = [s]

        while stack:

            v = stack.pop()

            for to, i in E[v]:

                if par[to][0] >= 0: continue

                par[to] = (v, i)

                if to == g: break

                stack.append(to)

        r = set()

        v = g

        while v != s:

            v, i = par[v]

            r.add(i)

        return r

    M = int(input())

    path = [None] * M

    for i in range(M):

        u, v = list(map(int, input().split()))

        u, v = u-1, v-1

        path[i] = dfs(u, v)

    def calc(s): return 1<<(N-1-len(s))

    i_ans = 0

    for p in range(1, 1<<M):

        is_odd = bin(p).count('1') & 1

        s = set()

        for i in range(M):

            if p&1: s |= path[i]

            p >>= 1

        if is_odd: i_ans += calc(s)

        else: i_ans -= calc(s)

    print(((1<<(N-1)) - i_ans))

if __name__ == '__main__':

    main()


Input:
'''

    Auther: ghoshashis545 Ashis Ghosh

    College: jalpaiguri Govt Enggineering College

'''

from os import path

import sys

from functools import cmp_to_key as ctk

from collections import deque,defaultdict as dd

from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right

from itertools import permutations

from datetime import datetime

from math import ceil,sqrt,log,gcd

def ii():return int(input())

def si():return input()

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

def li():return list(mi())

abc='abcdefghijklmnopqrstuvwxyz'

mod=1000000007

#mod=998244353

inf = float("inf")

vow=['a','e','i','o','u']

dx,dy=[-1,1,0,0],[0,0,1,-1]

def bo(i):

    return ord(i)-ord('a')

file = 0

def solve():

    # for _ in range(ii()):

    n=ii()

    n%=1000

    if n!=0:

        n=1000-n

    print(n)

if __name__ =="__main__":

    if(file):

        if path.exists('input1.txt'):

            sys.stdin=open('input1.txt', 'r')

            sys.stdout=open('output1.txt','w')

        else:

            input=sys.stdin.readline

    solve()


Input:
M=998244353

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

a=0

c=1

for i in range(k+1):

  a+=c*m*pow(m-1,n-i-1,M)

  c=c*(n-i-1)*pow(i+1,M-2,M)%M

print((a%M))


Input:
N = int(input())

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

cnt, i = 0, 0

for j in range(10 ** 6):

    cnt += 1

    if a[i] == 2:

        print(cnt)

        #break

        quit()

    else:

        i = a[i] - 1

print((-1))


Input:
import math

def combinations_count(n, r):

    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def combinations_with_replacement_count(n, r):

    return combinations_count(n + r - 1, r)

def main():

    s = int(input())

    ans = 0

    n = s // 3

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

        ans += combinations_with_replacement_count(i, 3*(n-i)+s % 3)

    print((ans % (10**9 + 7)))

if __name__ == '__main__':

    main()


Input:
G_MAX = 40*10

N_MAX = 40

INF = float('inf')

dp = [[[INF]*(G_MAX+1) for _ in range(G_MAX+1)]

      for _ in range(N_MAX+1)]

N,Ma,Mb = list(map(int, input().split()))

a,b,c = [],[],[]

for _ in range(N):

    ai,bi,ci = list(map(int, input().split()))

    a.append(ai)

    b.append(bi)

    c.append(ci)

dp[0][0][0] = 0

from math import isinf

for i in range(N):

    for ca in range(G_MAX+1):

        for cb in range(G_MAX+1):

            if isinf(dp[i][ca][cb]): continue

            dp[i+1][ca][cb] = min(dp[i+1][ca][cb],

                                 dp[i][ca][cb])

            dp[i+1][ca+a[i]][cb+b[i]] = min(dp[i+1][ca+a[i]][cb+b[i]],

                                           dp[i][ca][cb]+c[i])

ans = INF

for ca in range(1,G_MAX+1):

    for cb in range(1,G_MAX+1):

        if ca*Mb==cb*Ma:

            ans = min(ans, dp[N][ca][cb])

if isinf(ans): ans = -1

print(ans)


Input:
from itertools import product

n = int(input())

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

count = 0

for C in product((-1, 0, 1), repeat=n):

  total = 1

  for a, c in zip(A, C):

    total *= (a + c)

  if total % 2 == 0:

    count += 1

print(count)


Input:
import sys

sys.setrecursionlimit(2147483647)

INF=float("inf")

MOD=10**9+7

input=lambda :sys.stdin.readline().rstrip()

def resolve():

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

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

    V=100000

    dp=[INF]*(V+1)

    dp[0]=0

    for w,v in WV:

        for x in range(V,-1,-1):

            if(x+v<=V):

                dp[x+v]=min(dp[x+v],dp[x]+w)

    for x in range(V,-1,-1):

        if(dp[x]<=W):

            print(x)

            return

resolve()


Input:
from collections import defaultdict

def main():

    _ = int(input())

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

    """

    for j>i, j-i = Ai + Aj

    i + Ai = j -Aj

    """

    L = defaultdict(int)

    R = defaultdict(int)

    for i, height in enumerate(heights):

        L[i + height] += 1

        R[i - height] += 1

    total_count = 0

    for x, count_l in list(L.items()):

        if x in R:

            count_r = R[x]

            total_count += count_l * count_r

    print(total_count)

if __name__ == "__main__":

    main()


Input:
import sys

readline = sys.stdin.readline

sys.setrecursionlimit(10**8)

mod = 10**9+7

#mod = 998244353

INF = 10**18

eps = 10**-7

m,n,k = list(map(int,readline().split()))

def comb(n, r, mod):

    r = min(r, n-r)

    mol = 1

    deno = 1

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

        mol = mol * (n-r+i) % mod

        deno = deno * i % mod

    ret = mol * pow(deno, mod-2, mod) % mod

    return ret

def f1(x,y,a,b):

    return (a+b-x-y)*(a-x+1)*(b-y+1)//2

def f2(x,a):

    return (a-x)*(a-x+1)//2

ans = 0

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

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

        a = n-x+1

        b = m-y+1

        c = m*(a*(a-1)+x*(x-1))

        d = n*(b*(b-1)+y*(y-1))

        ans += (c+d)//2

        ans %= mod

ans = (ans * comb(m*n-2,k-2,mod))%mod

ans = ans*pow(2,mod-2,mod)%mod

print(ans)


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

div =[]

for i in range(2,int(M**(1/2))+2):

    cur = 0

    while M%i==0:

        M = M//i

        cur += 1

    if cur >=1:

        div.append(cur)

if M>1: div.append(1)

div.sort()

mod = 10**9+7

frac = [1]*(N+50)

num = len(frac)

for i in range(len(frac)-1):

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

finv = [1] * (N+50)

finv[-1] = pow(frac[-1], mod-2, mod)

for i in range(1, num):

  finv[num-1-i] = finv[num-i] * (num-i) % mod

ans = 1

for i in div:

    ans = ans * frac[N+i-1]*finv[N-1]*finv[i]%mod

print(ans)


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

# print(a, b, c, x, y)

ans = 10000 * (10 **5) + 7

c_max = 0

if x > y:

  c_max = x * 2

else:

  c_max = y * 2

for cc in range(c_max+1):

  ac = x - (cc // 2)

  bc = y - (cc // 2)

  if ac < 0:

    ac = 0

  if bc < 0:

    bc = 0

  price = ac * a + bc * b + cc * c

  # print('price: {}, ac: {}, bc: {}, cc: {}'.format(price, ac, bc, cc))

  ans = min(ans, price)

print(ans)


Input:
N = int(input())

name = {'M':0, 'A':0, 'R':0, 'C':0, 'H':0}

march = "MARCH"

for _ in range(N):

  S = input()

  if(S[0] in name):

    name[S[0]] += 1

ans = 0

for i in range(3):

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

    for k in range(j+1,5):

      ans += name[march[i]] * name[march[j]] * name[march[k]]

print(ans)


Input:
n = int(input())

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

ans = [i for i in range(n)]

a1 = sorted(a)

for i in range(n):

    num = a[i]

    ans[num - 1] = str(i + 1)

print((' '.join(ans)))


Input:
INF = 2*10**7

def main():

    N, M = (int(i) for i in input().split())

    A = []

    B = []

    C = []

    for _ in range(M):

        a, b = (int(i) for i in input().split())

        A.append(a)

        B.append(b)

        bit = 0

        for i in input().split():

            bit |= (1 << (int(i)-1))

        C.append(bit)

    dp = [[INF]*(1 << N) for _ in range(M+1)]

    dp[0][0] = 0

    for i in range(M):

        for j in range(1 << N):

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

            if dp[i][j] != INF:

                next_bit = j | C[i]

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

    ans = dp[-1][-1]

    if ans == INF:

        print((-1))

    else:

        print(ans)

    # print(*dp, sep="\n")

if __name__ == '__main__':

    main()


Input:
def prime_factorize(num):

    """

    This function performs prime factorization on the input natural number.

    The result is returned in the form of a dictionary with the prime number as the key

    and its number as the value.

    :param num:

    :return prime_factor: Dictionary with the prime number as the key and its number as the value.

    """

    prime_factor = {}

    i = 2

    while i ** 2 <= num:

        while num % i == 0:

            num //= i

            if i in list(prime_factor.keys()):

                prime_factor[i] += 1

            else:

                prime_factor[i] = 1

        i += 1

    if num > 1:

        prime_factor[num] = 1

    return prime_factor

from math import factorial

def comb(n, r, R):

    if n not in R:

        a = factorial(n)

        R[n] = a

    else:

        a = R[n]

    if n - r not in R:

        b = factorial(n - r)

        R[n - r] = b

    else:

        b = R[n - r]

    if r not in R:

        c = factorial(r)

        R[r] = c

    else:

        c = R[r]

    return a // (b * c)

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

r = 1

R = dict()

prime_fac = prime_factorize(m)

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

    r *= comb(v + n - 1, v, R)

mod = 1000000000 + 7

print((r % mod))


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

if a < b + c:

    print((b+c-a))

else:

    print((0))


Input:
from collections import Counter

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

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

X = Counter(A)

for i in range(M):

    B, C = list(map(int, input().split()))

    X[C] += B

Z = []

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

    Z.append((key, value))

Z.sort(key=lambda x: x[0], reverse=True)

ans = 0

cnt = 0

for value, key in Z:

    if cnt + key <= N:

        ans += key * value

        cnt += key

    else:

        ans += (N - cnt) * value

        break

print(ans)


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

if any(i % 2 != 0 for i in [a, b, c]):

    print((0))

    exit()

if a == b and b == c:

    print((-1))

    exit()

cnt = 0

a_list = [0]*(1001001)

b_list = [0]*(1001001)

c_list = [0]*(1001001)

a_list[0] = a

b_list[0] = b

c_list[0] = c

for i in range(1, 1001001):

    a_list[i] = (b_list[i-1] + c_list[i-1]) // 2

    b_list[i] = (c_list[i-1] + a_list[i-1]) // 2

    c_list[i] = (a_list[i-1] + b_list[i-1]) // 2

    cnt += 1

    if a_list[i] % 2 != 0 or b_list[i] % 2 != 0 or c_list[i] % 2 != 0:

        break

print(cnt)


Input:
from functools import lru_cache

import sys

sys.setrecursionlimit(30000)

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

a = list(int(input()) for _ in range(M))

MOD = pow(10, 9) + 7

isOk = True

for i in range(M-1):

    if a[i] + 1 == a[i+1]:

        isOk = False

funcb = [-1] * 100001

def func(n):

    if n <= 0:

        return 1

    cnt = funcb[n]

    if cnt > 0:

        return cnt

    cnt = 0

    if n >= 2:

        cnt += func(n-2)

    if n >= 1:

        cnt += func(n-1)

    funcb[n] = cnt % MOD

    return funcb[n]

func(30000)

func(50000)

func(80000)

func(100000)

if not isOk:

    print((0))

else:

    ans = 1

    s = 0

    for i in range(M+1):

        if i >= M:

            e = N

        else:

            e = a[i] - 1

        ans = ans * func(e-s) % MOD

        if i >= M:

            break

        s = a[i] + 1

    print(ans)


Input:
# 2019-11-17 20:44:23(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

# import re

# import heapq

# import array

# from scipy.misc import comb # (default: exact=False)

# import numpy as np

def main():

    s, t = sys.stdin.read().split()

    count = 0

    for i in range(3):

        if s[i] == t[i]:

            count += 1

    print(count)

if __name__ == "__main__":

    main()


Input:
#                         author:  kagemeka

#                         created: 2019-11-06 21:30:22(JST)

import sys

# import collections

# import math

# import string

# import bisect

# import re

# import itertools

# import statistics

# import functools

# import operator

def main():

    a, b = (int(x) for x in sys.stdin.read().split())

    count = 0

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

        n = str(n)

        if n == n[::-1]:

            count += 1

    print(count)

if __name__ == "__main__":

    # execute only if run as a script

    main()


Input:
N = int(input())

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

X = list(sorted(X))

if N == 1:

  print((0))

  exit()

ans = float('inf')

for p in range(X[0], X[N - 1] + 1):

  sum = 0

  for x in X:

    sum += (x - p) ** 2

  ans = min(sum, ans)

print(ans)


Input:
k, n = list(map(int, input().split()))

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

d = [0] * n

d_max = 0

for i in range(n - 1):

    d[i] = a[i + 1] - a[i]

    d_max = max(d_max, d[i])

d[-1] = (k - a[-1]) + a[0]

d_max = max(d_max, d[-1])

print((k - d_max))


Input:
import sys

input = sys.stdin.readline

from collections import deque

N = int(input())

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

for i in range(N-1):

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

    X[x-1].append(y-1)

    X[y-1].append(x-1)

i0 = min([i for i in range(N) if len(X[i]) == 1])

P = [-1] * N

Q = deque([i0])

R = []

while Q:

    i = deque.popleft(Q)

    R.append(i)

    for a in X[i]:

        if a != P[i]:

            P[a] = i

            X[a].remove(i)

            deque.append(Q, a)

mod = 10 ** 9 + 7

inv2 = (mod + 1) // 2

A = [1] * N

for i in R[::-1]:

    s = 0

    for j in X[i]:

        A[i] += A[j]

ans = 0

for i in range(N):

    s = pow(inv2, N - A[i], mod)

    t = 1 + (1-pow(inv2, N - A[i], mod)) * pow(2, N - A[i], mod)

    for j in X[i]:

        s = (s * pow(inv2, A[j], mod)) % mod

        t = (t + (1-pow(inv2, A[j], mod)) * pow(2, A[j], mod)) % mod

    ans = (ans + 1 - s * t) % mod

print((ans * inv2 % mod))


Input:
from math import factorial

def myAnswer(N:int) ->int:

   ans =factorial(N)

   return ans % (10**9 + 7)

def modelAnswer():

   tmp=1

def main():

   N = int(input())

   print((myAnswer(N)))

if __name__ == '__main__':

   main()


Input:
s = input()[::-1]

while True:

    if len(s) == 0:

        break

    if s[:7] == "remaerd":

        s = s[7:]

    elif s[:6] == "resare":

        s = s[6:]

    elif s[:5] == "maerd" or s[:5] == "esare":

        s = s[5:]

    else:

        print("NO")

        exit()

print("YES")


Input:
import sys

stdin = sys.stdin

ni = lambda: int(ns())

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

ns = lambda: stdin.readline()

def Solve():

    N,K=na()

    S=[int(d) for d in input()]

    l=[]

    N=len(S)

    if(S[0]==0):

        l.append(0)

    b=S[0]

    ct=1

    for i in S[1:]:

        if(b!=i):

            l.append(ct)

            ct=1

            b=i

        else:

            ct+=1

    l.append(ct)

    len_l=len(l)

    if(len_l//2 <= K):

        return sum(l)

    ans = res = sum(l[:2*K+1])

    if(len_l%2==0):

        l.append(0)

        len_l+=1

    g = K * 2 + 1

    for i in range(K*2+1,len_l-1,2):

        ans -= l[i-g] + l[i-g+1]

        ans += l[i] + l[1+i]

        if(res<ans):

            res=ans

    #print(S)

    #print(l)

    #print(len_l)

    return res

print((Solve()))


Input:
def check(x, y):

    for a, b in zip(x, y):

        if a != b and b != -1:

            return False

    else:

        return True

n = int(input())

remarks = []

cnt_max = 0

for _ in range(n):

    a = int(input())

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

    r = [-1] * n

    for i, j in x:

        r[i - 1] = j

    remarks.append(r)

for r in range(2 ** n):

    r = list(bin(r)[2:].zfill(n))

    r = [int(i) for i in r[:]]

    cnt = 0

    for i in range(n):

        if r[i] == 1:

            flag = check(r, remarks[i])

            cnt += 1

            if not flag:

                cnt = 0

                break

    cnt_max = max(cnt, cnt_max)

print(cnt_max)


Input:
A, B = list(map(int, input().split()))

count_target = 0

for i in range(A, B + 1):

    str_i = str(i)

    reversed_i = ''

    for n_th_i in reversed(list(range(len(str_i)))):

        reversed_i += str_i[n_th_i]

    if str_i == reversed_i:

        count_target += 1

print(count_target)


Input:
from collections import Counter,defaultdict,deque

import sys,bisect,math,itertools,string,queue

from heapq import heappop, heappush

sys.setrecursionlimit(10**8)

mod = 10**9+7

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

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

def inpl_str(): return list(sys.stdin.readline().split())

def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()

res = float('inf')

for i in range(1,2*10**6):

    if (n/i).is_integer():

        res = min(res, i + n/i)

print((int(res-2)))


Input:
S = int(input())

dp = [0] * (S + 1)

dp[0] = 1

M = 10 ** 9 + 7

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

    num = 0

    for j in range(i - 2):

        num += dp[j]

        dp[i] = num % M

print((dp[S]))


Input:
import random, math

random.seed()

def gen(a, b, num):

    result = set()

    while 1:

        while 1:

            v = random.randint(a, b)//2*2+1

            if v not in result:

                break

        for x in range(3, int(math.sqrt(v))+1, 2):

            if v % x == 0:

                break

        else:

            result.add(v)

            if len(result) == num:

                break

    return result

class RH():

    def __init__(self, s, base, mod):

        self.base = base

        self.mod = mod

        self.rev = pow(base, mod-2, mod)

        l = len(s)

        self.h = h = [0]*(l+1)

        tmp = 0

        for i in range(l):

            num = ord(s[i])

            tmp = (tmp*base + num) % mod

            h[i+1] = tmp

    def calc(self, l, r):

        return (self.h[r] - self.h[l] * pow(self.base, r-l, self.mod)) % self.mod

    def fixed(self, length):

        v = pow(self.base, length, self.mod)

        h = self.h; mod = self.mod

        def fixed_calc(l):

            return (h[length+l] - h[l] * v) % mod

        return fixed_calc

class RRH():

    def __init__(self, s, num=10, primes=None):

        primes = primes or gen(2, 10**3, num)

        MOD = 10**9+7

        self.rhs = [RH(s, p, MOD) for p in primes]

    def calc(self, l, r):

        return [rh.calc(l, r) for rh in self.rhs]

    def fixed(self, length):

        fs = [rh.fixed(length) for rh in self.rhs]

        def multi_fixed_calc(l):

            return list(f(l) for f in fs)

        return multi_fixed_calc

T = input(); P = input()

primes = gen(2, 10**3, 2)

HT = RRH(T, primes=primes)

HP = RRH(P, primes=primes)

pv = HP.calc(0, len(P))

calc = HT.fixed(len(P))

for i in range(len(T)-len(P)+1):

    if calc(i) == pv:

        print(i)


Input:
a = int(input())

h = int(a / 3600)

m = int((a - h * 3600) / 60)

s = int(a - h * 3600 - m * 60)

print((":" .join(map(str, [h, m, s]))))


Input:
n = int(input())

a = [int(x) for x in input().split()]

ans = list(range(n))

for i in range(n):

    ans[a[i]-1] = i+1

print((' '.join(map(str,ans))))


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

cnt = 0

for x in range(a, b + 1):

    s = str(x)

    l = len(s)

    flg = True

    for i in range(l // 2):

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

            flg = False

            break

    if flg:

        cnt += 1

print(cnt)


Input:
N = int(input())

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

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

a.reverse()

b.reverse()

ans = 0

capacity = 0

for i in range(N):

    ans += min(b[i] + capacity, a[i])

    capacity = max(b[i] - max(a[i] - capacity, 0), 0)

ans += min(a[-1], capacity)

print(ans)


Input:
#coding:utf-8

import bisect

import sys

sys.setrecursionlimit(10**6)

write = sys.stdout.write

dbg = lambda *something : print(*something) if DEBUG else 0

DEBUG = True

def main(given = sys.stdin.readline):

    input = lambda : given().rstrip()

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

    II = lambda : int(input())

    XLMIIS = lambda x : [LMIIS() for _ in range(x)]

    n, t = LMIIS()

    ab = XLMIIS(n)

    dp1 = [[0]*t for _ in range(n)]

    for i in range(1, n):

        for j in range(1, t):

            if j < ab[i-1][0]:

                dp1[i][j] = dp1[i-1][j]

            else:

                dp1[i][j] = max(dp1[i-1][j], dp1[i-1][j-ab[i-1][0]] + ab[i-1][1])

    dp2 = [[0]*t for _ in range(n)]

    for i in range(1, n):

        for j in range(1, t):

            if j < ab[n - i][0]:

                dp2[i][j] = dp2[i-1][j]

            else:

                dp2[i][j] = max(dp2[i-1][j], dp2[i-1][j-ab[n-i][0]] + ab[n-i][1])

    ans = 0

    for i in range(n):

        for j in range(t - 1):

            ans = max(ans, dp1[i][j] + dp2[n - i - 1][t - j - 1] + ab[i][1])

    print(ans)

if __name__ == '__main__':

    main()


Input:
import sys

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

S = input()

def nexti(n):

    while S[n] == '1':

        n += 1

    while S[n] == '0':

        n += 1

    return n

def nextj(n):

    while S[n] == '0':

        n += 1

        if n == N:

            return N

    while S[n] == '1':

        n += 1

        if n == N:

            return N

    return n

i = 0

j = 0

while S[j] == '1':

    j += 1

    if j == N:

        print(N)

        sys.exit(0)

for _ in range(K):

    j = nextj(j)

    if j == N:

        print(N)

        sys.exit(0)

ans = j - i

while True:

    i = nexti(i)

    j = nextj(j)

    ans = max(ans, j - i)

    if j == N:

        break

print(ans)


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

S = list(input() for i in range(N))

str = ""

for i in range(N-1):

    for j in range(N-1):

        if S[j+1] + S[j] <= S[j] + S[j+1]:

            S[j], S[j+1] = S[j+1], S[j]

for i in S:

    str += i

print(str)


Input:
while True:

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

	if k[0]==k[1]==0:

		break

	ct=0

	a=0

	b=0

	c=0

	max=k[0]

	sum=k[1]

	a=max+1

	while True:

		a-=1

		b=a-1

		c=sum-a-b

		if not a>b>c:

			print(ct)

			break

		while a>b>c:

			if a>b>c>0:

				ct+=1

			b-=1

			c+=1


Input:
n, l = list(map(int, input().split()))

S = [input() for i in range(n)]

S.sort()

print(("".join(S)))


Input:
N = int(input())

if N < 2:

  print(N)

elif 2<=N<4:

  print((2))

elif 4<=N<8:

  print((4))

elif 8<=N<16:

  print((8))

elif 16<=N<32:

  print((16))

elif 32<=N<64:

  print((32))

elif 64<=N:

  print((64))


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

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

left = 1

right = N

for l, r in LR:

    if left < l:

        left = l

    if right > r:

        right = r

ans = right - left

print((ans + 1 if ans >= 0 else 0))


Input:
s = input()

t = input()

for i in range(len(s)):

        if s[i:]+s[:i]==t:

                print('Yes')

                exit()

print('No')


Input:
n = int(input())

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

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

result = 0

for i in range(n):

  if v[i] > c[i]:

    result += v[i] - c[i]

print(result)


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

answer = 0

for i in range(a,b+1) :

    j = str(i)

    p1 = j[4]

    p2 = j[3]

    p3 = j[2]

    p4 = j[1]

    p5 = j[0]

    k = int(p1+p2+p3+p4+p5)

    if i == k :

        answer += 1

print(answer)


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

dic={}

for i in range(N):

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

  if a in dic:

    dic[a]+=b

  else:

    dic[a]=b

dic=sorted(list(dic.items()),key=lambda x:x[0])

for d in range(len(dic)):

  amount=dic[d][1]

  if amount>=K:

    print((dic[d][0]))

    exit(0)

  else:

    K-=amount


Input:
# Problem https://atcoder.jp/contests/abc053/tasks/abc053_b

# Python 1st Try

import copy

class Problem:

    def __init__(self, stringdata):

        self.stringdata = stringdata

    def solver(self):

        strcont = copy.copy(self.stringdata)

        result = 0

        rightposition = 0

        leftposition = len(strcont)

        j = 0

        while True:

            if strcont[j] == 'A':

                rightposition = j

                break

            else:

                j = j + 1

        j = leftposition - 1

        while True:

            if strcont[j] == 'Z':

                leftposition = j

                break

            else:

                j = j - 1

        result = leftposition - rightposition + 1

        return result

if __name__ == "__main__":

    s = input()

    print(("{}".format(Problem(s).solver())))


Input:
from itertools import accumulate

from bisect import *

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

L = list(tuple(map(int, input().split())))

acc = sorted(list(accumulate(L)) + [0])

n = bisect_right(acc,X)

print(n)


Input:
A, B = list(map(int, input().split()))

cnt = 0

for n in range(A, B+1):

    n_s = str(n)

    n_s_rvs = n_s[::-1]

    if n_s == n_s_rvs:

        cnt += 1

print(cnt)


Input:
import math

N=int(input())

print((math.factorial(N)%(10**9+7)))


Input:
# ABC95 C -Half and Half

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

ans = 0

if a+b > 2*c:

    while x != 0.0 and y != 0.0:

        ans += 2*c

        x -= 1.0

        y -= 1.0

        if y == 0.0:

            while x != 0.0:

                if a > 2*c:

                    ans += 2*c

                    x -= 1.0

                else:

                    ans += a

                    x -= 1.0

        if x == 0.0:

            while y != 0.0:

                if b > 2*c:

                    ans += 2*c

                    y -= 1.0

                else:

                    ans += b

                    y -= 1.0

else:

    ans += a*x + b*y

print((int(ans)))


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

cnt = 0

for _ in range(N):

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

    if x ** 2 + y ** 2 <= D ** 2:

        cnt += 1

print(cnt)


Input:
from math import gcd

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

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

a=list(set(a))

a=list([x//2 for x in a])

def lcm(q):

  x = q[0]

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

    x = (x * q[i]) // gcd(x, q[i])

  return x

lcma=lcm(a)

if (lcma//a[0])%2==0:

  print((0))

else:

  flg=0

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

    if (lcma//a[i])%2==0:

      print((0))

      flg=1

      break

  if flg==0:

    temp=m//lcma

    print((temp//2 if temp%2==0 else temp//2+1))


Input:
S = int(input())

a = 0

count = 0

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

while count == 0:

    a += S

    if n <= a and m >= a:

        count = 1

    if a >= 1000:

        break

if count == 0:

    print("NG")

else:

    print("OK")