Harryxun/stf_run huggingface dataset:
n = int(raw_input())
A = map(int, raw_input().strip().split(' '))
q = int(raw_input())
M = map(int, raw_input().strip().split(' '))

def ans(i, m):
    if m == 0:
        return 1
    if i  >= n or m > sum(A):
        return 0
    res = ans(i + 1, M) or ans(i + 1, M - A[i])
    return res
           
for j in range(0, q):
    if ans(0, M[j]):
        print "yes"
    else:
        print"no"

### FIXED CODE ###

n = int(raw_input())
A = map(int, raw_input().strip().split(' '))
q = int(raw_input())
M = map(int, raw_input().strip().split(' '))

def ans(i, m):
    if m == 0:
        return 1
    if i  >= n or m > sum(A):
        return 0
    res = ans(i + 1, m) or ans(i + 1, m - A[i])
    return res
           
for j in range(0, q):
    if ans(0, M[j]):
        print "yes"
    else:
        print"no"
N = int(input())
A = list(map(int, input().split()))
cnt = 0
for i, a in enumerate(A, 1):
  if a == i:
    x = a[i - 1]
    y = a[i]
    a[i - 1] = y
    a[i] = x    
    cnt += 1
print(cnt)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
cnt = 0
for i, a in enumerate(A, 1):
  if a == i:
    if i != len(A):
      x = A[i - 1]
      y = A[i]
      A[i - 1] = y
      A[i] = x    
      cnt += 1
    else:
      x = A[i - 2]
      y = A[i - 1]
      A[i - 2] = y
      A[i - 1] = x    
      cnt += 1
print(cnt)
a=int(input())
if a=1:
  print(a)
elif a//2=0:
  print((a/2)/a)
else:
  print((int(a/2)+1)/a)


### FIXED CODE ###

import math
a=int(input())
b=math.floor(float(a/2))
print(float((a-b)/a))
s = input()

def count_removal(c):
  if '01' in c:
    return count_removal(c.replace('01', '')) + c.count('01')*2
  else:
    return 0

print(count_removal(s))

### FIXED CODE ###

s = input()

if s.count('1') > 0 and s.count('0') > 0:
  print(min(s.count('1'), s.count('0')) * 2)
else:
  print(0)
n=int(input())
A=[]
for i in range(n):
  A.append(int(input())
A.sort()
print(sum(A)-A[-1]/2)

### FIXED CODE ###

n=int(input())
A=[]
for i in range(n):
  A.append(int(input()))
A.sort()
print(int(sum(A)-A[-1]/2))
import sys

W, H, N = map(int, input().split())
l = d = 0
u = H
r = W
for i in range(N):
    x, y, a = list(map(int, input().split()))
    if a == 1:
        l = max(x, l)
    if a == 2:
        r = min(x, r)
    if a == 3:
        d = max(y, d)
    if a == 4:
        u = min(y, u)

ans = (r - l) * (u - d)
if r - l < 0 or u - d < 0
    ans = 0 
print(max(ans, 0))


### FIXED CODE ###

import sys

W, H, N = map(int, input().split())
l = d = 0
u = H
r = W
for i in range(N):
    x, y, a = list(map(int, input().split()))
    if a == 1:
        l = max(x, l)
    if a == 2:
        r = min(x, r)
    if a == 3:
        d = max(y, d)
    if a == 4:
        u = min(y, u)

ans = (r - l) * (u - d)
if r - l < 0 or u - d < 0:
    ans = 0
print(max(ans, 0))
s = str(input())[::-1]
while True:
    if s[:5]=="maerd" or s[:5]=="esare":
        s=s[5:]
        if len(s)==0:
            print("YES")
            exit()
    elif s[:6]=="resare"
        s=s[6:]
        if len(s)==0:
            print("YES")
            exit()
    elif s[:7]=="remaerd":
        s=s[7:]
        if len(s)==0:
            print("YES")
            exit()
    else:
        print("NO")
        exit()

### FIXED CODE ###

s = str(input())[::-1]
while True:
    if s[:5]=="maerd" or s[:5]=="esare":
        s=s[5:]
        if len(s)==0:
            print("YES")
            exit()
    elif s[:6]=="resare":
        s=s[6:]
        if len(s)==0:
            print("YES")
            exit()
    elif s[:7]=="remaerd":
        s=s[7:]
        if len(s)==0:
            print("YES")
            exit()
    else:
        print("NO")
        exit()
import fractions

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

N=int(input())
A=list(map(int,input().split()))
a_lcm=A[0]

for i in range(1,N):
    a_lcm=lcm(a_lcm,A[i])

result=0
for i in range(N):
    result+=a_lcm//A[i]
    result%=1000000007
print(result%1000000007)

### FIXED CODE ###

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

 #最小公倍数
def lcm(a,b):
    return a*b//gcd(a,b)

N=int(input())
A=list(map(int,input().split()))
a_lcm=A[0]
Mod=10**9+7

for i in range(1,N):
    a_lcm=lcm(a_lcm,A[i])

a_lcm%=Mod

result=0
for i in range(N):
    result+=a_lcm*pow(A[i],Mod-2,Mod)
print(result%1000000007)
from math import *
 
n=int(raw_input())
arr=list(map(int,raw_input().split()))
dict1={}
for i in range(n):
    val=arr[i]
    try:
        dict1[val]+=1
    except:
        KeyError
        dict1[val]=1
#print(dict1)
ans=0
arr.sort(reverse=True)
for i in range(n):
    val2=int(ceil(log(arr[i],2)))
        xd=2**val2
        if(xd!=2*arr[i]):
            try:
                if(dict1[xd-arr[i]]>0):
                    ans+=1
                    dict1[xd-arr[i]]-=1
                    dict1[arr[i]]-=1
                    break
            except:
                KeyError
        else:
            if(dict1[arr[i]]>1):
                ans+=1
                dict1[arr[i]]-=2
                break
print(ans)

### FIXED CODE ###

from math import *
 
n=int(raw_input())
arr=list(map(int,raw_input().split()))
dict1={}
for i in range(n):
    val=arr[i]
    try:
        dict1[val]+=1
    except:
        KeyError
        dict1[val]=1
#print(dict1)
ans=0
arr.sort(reverse=True)
for i in range(n):
    if(dict1[arr[i]]>0):
        xd=2**(len(bin(arr[i]))-2)
        if(xd-arr[i]!=arr[i]):
            try:
                if(dict1[xd-arr[i]]>0):
                    ans+=1
                    dict1[xd-arr[i]]-=1
                    dict1[arr[i]]-=1
            except:
                KeyError
        else:
            if(dict1[arr[i]]>1):
                ans+=1
                dict1[arr[i]]-=2
print(ans)
import math
n,x=map(int,input().split())
a=list(map(int,input().split()))
dis1=x-min(a)
dis2=max(a)-x
print(math.gcd(dis1,dis2))


### FIXED CODE ###

from functools import reduce
from fractions import gcd
n,x=map(int,input().split())
a=list(map(int,input().split()))
dist=[]
for i in range(n):
    dist.append(abs(x-a[i]))
print(reduce(gcd,dist))
from collections import deque
plusQ = deque([]) 
minsQ = deque([])

N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)

for itr, val in enumerate(A):
  if itr + 1 <= (len(A) + 1) // 2 and val > 0:
    plusQ.append(val)
  else:
    minsQ.append(val)

# print(plusQ, minsQ)
p1 = plusQ.popleft()

ans = deque([])
while len(minsQ) > 0:
  if len(plusQ) > 0:
    p, m = plusQ.popleft(), minsQ.popleft()
    ans.append([m, p])
    minsQ.append(m - p)    
  else:
    m = minsQ.popleft()
    ans.append([p1, m])
    p1 = p1 - m

print(p1)
while len(ans) > 0:
  hoge = ans.popleft()
  print(hoge[0],hoge[1])

### FIXED CODE ###

from collections import deque
plusQ = deque([]) 
minsQ = deque([])
 
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
 
for itr, val in enumerate(A):
  if itr == 0:
    plusQ.append(val)
  elif itr != len(A) - 1 and val > 0:
    plusQ.append(val)
  else:
    minsQ.append(val)
    
p1 = plusQ.popleft()
 
ans = deque([])
while len(minsQ) > 0:
  if len(plusQ) > 0:
    p, m = plusQ.popleft(), minsQ.popleft()
    ans.append([m, p])
    minsQ.append(m - p)    
  else:
    m = minsQ.popleft()
    ans.append([p1, m])
    p1 = p1 - m

print(p1)
while len(ans) > 0:
  hoge = ans.popleft()
  print(hoge[0],hoge[1])
a, tmp = map(str, input().split())
b = list(tmp)
del b[1]
bb = "".join(b)
abb = int(a) * int(bb)
ans = list(str(abb))
del ans[-2:]
print(int("".join(ans)))

### FIXED CODE ###

import math
import sys

a, b = map(str, input().split())
if a == "0" or b == "0.00":
  print(0)
  exit()
ans = 0
ans += int(a) * int(b[0]) * 100
ans += int(a) * int(b[2]) * 10
ans += int(a) * int(b[3])
tmp = list(str(ans))
if len(tmp) == 1 or len(tmp) == 2:
  print(0)
  exit()
tmp.pop(-1)
tmp.pop(-1)
print(int("".join(tmp)))
N=int(input())
A=list(map(int,input().split()))
 
flg=1
count=0
while True:
    for i in A: #全て偶数か確かめる
        if i%2==1:
            flg=0
            break

    if flg==1:
        for i in A:
            i=i//2
        count+=1
    else:
        break
print(count)

### FIXED CODE ###

input_line=input()
s=list(map(int,input_line))
print(sum(s))
def main():
        s = raw_input().split()

        if s[0][-1] == s[1][0] && s[1][-1] == s[2][0]:
            print("YES")
        else:
            print("NO")
main()


### FIXED CODE ###

def main():
        s = input().split()

        if s[0][-1] == s[1][0] and s[1][-1] == s[2][0]:
            print("YES")
        else:
            print("NO")
main()
A, B, K =map(int, input().split())
tmp = []
for i in range(2,min(A,B)+1):
    if A%i == 0 and B%i == 0:
        tmp.append(i)
tmp.sort(reverse=True)
print(tmp[K-1])

### FIXED CODE ###

A, B, K =map(int, input().split())
tmp = []
try:
    for i in range(2,min(A,B)+1):
        if A%i == 0 and B%i == 0:
            tmp.append(i)
    tmp.sort(reverse=True)
    print(tmp[K-1])
except:
    print(1)
a, b, x = map(int, input.split())

if a > x:
	print("NO")
elif x - a > b:
	print("YES")
else:
	print("NO")


### FIXED CODE ###

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

if a > x:
	print("NO")
elif x - a > b:
	print("NO")
else:
	print("YES")
N=int(input())
if N%2==0:
  print(N//2,N,N)
else:
  for i in range(1,3501):
    for j in range(1,3501):
      if 4*i*j-N*i-N*j>0:
        if N*i*j/(4*i*j-N*i-N*j).is_integer():
          print(i,j,int(w))
          exit()

### FIXED CODE ###

N=int(input())
if N%2==0:
  print(N//2,N,N)
else:
  for i in range(1,3501):
    for j in range(1,3501):
      if 4*i*j-N*i-N*j!=0:
        w=(N*i*j)/(4*i*j-N*i-N*j)
        if w>0 and w.is_integer():
          print(i,j,int(w))
          exit()
s = input()
k = int(input())


# alphabet順に探査する
# 探査順序配列
search_seq = sorted(list(set(s)))

count = 0
previous = 0

for key in search_seq:
    previous = count
    indexes = [i for i, x in enumerate(s) if x == key]
    sublist = []
    for index in indexes:
        stop = min(len(s) - index, k)
        for end in range(index+1, index + stop + 1):
            sublist.append(s[index:end])
    count += len(sublist)
    if k-1 < count:
        list_uq = list(set(sublist))
        list_sorted = sorted(list_uq)
        print(list_sorted[k-previous-1])
        exit()




### FIXED CODE ###

s = input()
k = int(input())


sublist = []
for start in range(len(s)):
    end = min(start + k, len(s))
    for end in range(start+1, end + 1):
        sublist.append(s[start:end])

unique = sorted(list(set(sublist)))
print(unique[k-1])
ret = []
while True:
    n = input()
    if n == 0:
        break
    ret += [n]

for i, x in enumerate(ret):
    print 'Case %d: %d' % (i+1, x)

### FIXED CODE ###

i = 0
while True:
    i, n = i+1, input()               
    if n == 0:
        break
    print 'Case %d: %d' % (i, n)
from itertools import groupby

R = lambda: map(int, input().split())
n, k = R()
a = list(R())
w = [0] * n

def merge(b, e):
    m = b + (e - b) // 2
    i, j = b, mid
    r = 0
    while i < m and j < e:
        if a[i] <= a[j]:
            w[i + j] = a[i]
            i += 1
        else:
            r += m - i
            w[i + j] = a[j]
            j += 1
    a[e - m + i: e] = a[i: m]
    a[b: b + i + j] = w[:i + j]
    return r        
    
def mergesort(b, e):
    if e - b < 2:
        return 0
    mid = b + (e - b) // 2
    return mergesort(b, mid) + mergesort(mid, e) + merge(b, e)


r = k * mergesort(0, n)
print(a)
c = n * (n - 1) // 2
for _, g in groupby(a):
    x = sum(1 for _ in g)
    c -= x * (x - 1) // 2
print((r + c * k * (k - 1) // 2) % (10**9 + 7))


### FIXED CODE ###

from collections import Counter
R = lambda: map(int, input().split())
n, k = R()
a = list(R())
r = k * sum(a[i] < a[j] for i in range(n) for j in range(i))
r = n*(n-1)//2 - sum(x*(x-1)//2 for x in Counter(a).values())
r = r * k*(k-1)//2 + k * sum(a[i] < a[j] for i in range(n) for j in range(i))
print(r % (10**9 + 7))
if __name__ == '__main__':
    h, w = map(int, input().split())
    n = int(input())
    a = list(map(int, input().split()))

    c = [[0 for i in range(w)] for j in range(h)]
    vx = [1, -1, 0, 0]
    vy = [0, 0, 1, -1]
    color = 0

    def draw(x, y, num):
        sx, sy = x, y
        cnt = num
        queue = [(sx, sy)]
        while(len(queue)):
            if(not cnt):
                break
            cnt -= 1
            pos = queue.pop()
            c[pos[0]][pos[1]] = color + 1
            for i in range(4):
                if(pos[0]+vx[i]>=0 and pos[0]+vx[i]<h and
                   pos[1]+vy[i]>=0 and pos[1]+vy[i]<w and
                   c[pos[0]+vx[i]][pos[1]+vy[i]] == 0):
                    queue.append((pos[0]+vx[i], pos[1]+vy[i]))

    for i in range(h):
        for j in range(w):
            if(c[i][j] == 0):
                draw(i, j, a[color])
                color+=1

    print('\n'.join(' '.join([str(j) for j in i]) for i in c))


### FIXED CODE ###

if __name__ == '__main__':
    h, w = map(int, input().split())
    n = int(input())
    a = list(map(int, input().split()))

    c = [0] * (h*w)
    
    focus = 0
    for i in range(n):
        for j in range(a[i]):
            c[focus] = i+1
            focus += 1

    for i in range(h):
        for j in range(w):
            if(i%2 == 0):
                if(j + 1 != w):
                    print(c[i*w+j],end=" ")
                else:
                    print(c[i*w+j])
            else:
                if(j + 1 != w):
                    print(c[(i+1)*w-1-j],end=" ")
                else:
                    print(c[(i+1)*w-1-j])
# -*- coding: utf-8 -*-

import sys
import os
import math
PI = math.pi

r = int(input())

s = r * r * PI
l = 2 * PI * r

print(s, l)

### FIXED CODE ###

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

import sys
import os
import math
PI = math.pi

r = float(input())

s = r * r * PI
l = 2 * PI * r

print(s, l)
o = input()
e = input()
list = []
for i in range(len(o)-1):
  list.append(o[i] + e[i])
  
if len(e) == len(o):
  list.append(o[len(o)] + e[len(e)])
else:
  list.append(o[len(o)])
  
 
print(*list, sep='')

### FIXED CODE ###

a, b, c = map(int, input().split())
if b-a == c-b:
  print('YES')
else:
  print('NO')
n=int(input())
k=n
keta=1
x=26
while k>x:
    k-=x
    keta+=1
    x*=26

book=['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
l=[]
for i in reversed(range(keta)):
    s=(k//(26**i))+1
    k-=(s-1)*(26**i)
    if i>0:
        l.append(book[s-1])
    else:
        l.append(book[s-2])
print("".join(l))


### FIXED CODE ###

n=int(input())
k=n
keta=1
x=26
while k>x:
    k-=x
    keta+=1
    x*=26

book=['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
l=[]

for i in reversed(range(1,keta)):
    s=(k-1)//(26**i)
    k-=s*(26**i)
    l.append(book[s])

l.append(book[k-1])
print("".join(l))
def main()
    n = int(input(),10)
    sort_list = list()
    
    for i in range(0,n):
        sort_list.append(int(input(),10))
    
    for i in range(1,n):
        
        for j in range(0,n):
            print(sort_list[j])
            if j is not n - 1:
                print(" ")
            else:
                print("\n")
        
        tmp = sort_list[i]
        int j = i - 1
        while j >= 0 and sort_list[i] > v:
            sort_list[j+1] = sort_list[j]
            j--
        sort_list[j+1] = v
        
if __name__ == '__main__':
    main()
    


### FIXED CODE ###

import sys

n = input()
sort_list = list()

sort_list = map(int, raw_input().split())

for i in range(0,n):
    
    
    tmp = sort_list[i]
    j = i - 1
    while j >= 0 and sort_list[j] > tmp:
        sort_list[j+1] = sort_list[j]
        j = j - 1

    sort_list[j+1] = tmp


    for k in range(0,n):
        sys.stdout.write(str(sort_list[k]))
        if k is not n - 1:
            sys.stdout.write(" ")
        elif i is not n - 1:
            sys.stdout.write("\n")
            
print("")
import sys

for i in sys.stdin:
    i = i.split(" ")
    x, y = int(i[0]),int(i[1])
    if x == y == 0:
       break
    elif x <= y:
       print('{0} {1}'.format(x, y))
    else:
       pritn('{0} {1}').format(y, x)

### FIXED CODE ###

import sys
 
for i in sys.stdin:
    i = i.split(" ")
    x, y = int(i[0]), int(i[1])
    if x == y == 0:
       break
    elif x <= y:
       print("{0} {1}".format(x, y))
    else:
       print("{0} {1}".format(y, x))
# C MP消費を抑えるにはABCとの差が小さけれは良い
n, A, B, C = map(int, input().split())
l = [int(input()) for _ in range(n)]
INF = 10**9


def dfs(now, a, b, c):
    if now == n:
        return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF
    # 方法１　１つ飛ばす
    way1 = dfs(now + 1, a, b, c)
    # 方法２　合成魔法(MP10)
    way2 = dfs(now + 1, a + l[now], b, c)+10
    way3 = dfs(now + 1, a, b + l[now], c)+10
    way4 = dfs(now + 1, a, b, c + l[now])+10
    return min(way1, way2, way3, way4)


print(dfs(0, 0, 0, 0))
# C MP消費を抑えるにはABCとの差が小さけれは良い
n, A, B, C = map(int, input().split())
l = [int(input()) for _ in range(n)]
INF = 10**9


def dfs(now, a, b, c):
    if now == n:
        return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF
    # 方法１　１つ飛ばす
    way1 = dfs(now + 1, a, b, c)
    # 方法２　合成魔法(MP10)
    way2 = dfs(now + 1, a + l[now], b, c)+10
    way3 = dfs(now + 1, a, b + l[now], c)+10
    way4 = dfs(now + 1, a, b, c + l[now])+10
    return min(way1, way2, way3, way4)


print(dfs(0, 0, 0, 0))


### FIXED CODE ###

# C MP消費を抑えるにはABCとの差が小さけれは良い
n, A, B, C = map(int, input().split())
l = [int(input()) for _ in range(n)]
INF = 10**9


def dfs(now, a, b, c):
    if now == n:
        return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF
    # 方法１　１つ飛ばす
    way1 = dfs(now + 1, a, b, c)
    # 方法２　合成魔法(MP10)
    way2 = dfs(now + 1, a + l[now], b, c)+10
    way3 = dfs(now + 1, a, b + l[now], c)+10
    way4 = dfs(now + 1, a, b, c + l[now])+10
    return min(way1, way2, way3, way4)


print(dfs(0, 0, 0, 0))
def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))

    towns = [1]
    i = 0
    while a[i] not in towns and len(towns) < k:
        towns.append(a[i])
        i = a[i] - 1
    ti = towns.index(a[i])
    if ti+1 > k:
        print(towns[ti])
    else:
        print(towns[(k - ti)%(len(towns) - ti) + ti])

if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys

def main():
    n, k = map(int, sys.stdin.buffer.readline().split())
    a = [0] + list(map(int, sys.stdin.buffer.readline().split()))

    visited = [0]*(n+1)
    town = 1
    for i in range(1, k+1):
        town = a[town]
        if visited[town] == 0:
            visited[town] = i
        else:
            cyc = (k - visited[town])%(i - visited[town]) + visited[town]
            print(visited.index(cyc))
            exit()
    print(town)

if __name__ == "__main__":
    main()
import math

A, B, N = map(int,input().split())

if N < B:
    temp1 = math.floor(A*1/B) - A*math.floor(1/B)
    temp2 = math.floor(A*N/B) - A*math.floor(N/B)
    ans = max(temp1, temp2)

if N > B:
    temp1 = math.floor(A*1/B) - A*math.floor(1/B)
    temp2 = math.floor(A*(B-1)/B) - A*math.floor((B-1)/B)
    ans = max(temp1, temp2)

print(ans)

### FIXED CODE ###

import math

A, B, N = map(int,input().split())

if N < B:
    temp1 = math.floor(A*1/B) - A*math.floor(1/B)
    temp2 = math.floor(A*N/B) - A*math.floor(N/B)
    ans = max(temp1, temp2)

if N >= B:
    temp1 = math.floor(A*1/B) - A*math.floor(1/B)
    temp2 = math.floor(A*(B-1)/B) - A*math.floor((B-1)/B)
    ans = max(temp1, temp2)

print(ans)
a, b = map(int, input().split())
s = input()
for i in len(s):
  if (i == a) != (s[i] == '-'):
    print('No')
    break
else:
  print('Yes')


### FIXED CODE ###

a, b = map(int, input().split())
s = input()
for i in range(len(s)):
  if (i == a) != (s[i] == '-'):
    print('No')
    break
else:
  print('Yes')
p_num = int(input())
p = list(map(int,input().split()))

count = 1
min = p[0]


for i in p[1:]:
    if i < min_num:
        min_num = i
        count += 1
        

print(count)


### FIXED CODE ###

p_num = int(input())
p = list(map(int,input().split()))

count = 1
min_num = p[0]


for i in p[1:]:
    if i < min_num:
        min_num = i
        count += 1
        

print(count)
import math
a,b = map(int,input().split())

g = a*b/math.gcd(a,b)
print(g)


### FIXED CODE ###

import fractions
a,b = map(int,input().split())

g = a*b/fractions.gcd(a,b)
print(int(g))
a = int(input())

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

for i in range(1,a):
  aa[i] += a[i-1]
  
su = 10**20

for i in range(a):
  su = min(su,abs(aa[a-1]-2*a[i]))
print(sU)

### FIXED CODE ###

a = int(input())

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

for i in range(1,a):
  aa[i] += aa[i-1]
  
su = 10**20

for i in range(a-1):
  su = min(su,abs(aa[a-1]-2*aa[i]))
print(su)
l,r = map(int, input().split())
L = []
for i in range(l,r-1):
  for j in range(i+1,r):
    a = i*j
    b = a%2019
    L.append(b)
print(min(L))


### FIXED CODE ###

l,r = map(int, input().split())
if r-l+1>2019:
  print(0)
  exit()
L = []
for i in range(l,r):
  for j in range(i+1,r+1):
    a = i*j
    b = a%2019
    L.append(b)
print(min(L))
x = int(input())
ret = 0
for b in range(1,int(sqrt(x))+2):
    for p in range(2,10):
        if b**p <= x and ret < b**p: ret = b**p
print(ret)

### FIXED CODE ###

x = int(input())
ret = 0
for b in range(1,int(x**0.5)+2):
    for p in range(2,11):
        if b**p <= x and ret < b**p: ret = b**p
print(ret)
input();*A,=map(int,input());print(sum(A[a]==i for i,a in enumerate(A))//2)

### FIXED CODE ###

input();*A,=map(int,input().split());print(sum(A[a-1]==i+1for i,a in enumerate(A))//2)
n,k = map(int,input().split())
lst = list(map(int,input().split()))
lst_com = collections.Counter(lst).most_common()
if len(lst_com)<=k:
    print(0)
    exit()
ans=n
for i in range(k):
    ans -= lst_com[i][1]
print(ans)

### FIXED CODE ###

import collections

n,k = map(int,input().split())
lst = list(map(int,input().split()))
lst_com = collections.Counter(lst).most_common()
if len(lst_com)<=k:
    print(0)
    exit()
ans=n
for i in range(k):
    ans -= lst_com[i][1]
print(ans)
import itertools
import math

n = input()
p = input()
q = input()

counter = 1
base = list(range(1,n+1))

i = 0
for x in itertools.permutations(range(n), n):
	i += 1
    if p == x:
    	a = i
    elif q == x:
    	b = i
print(math.abs(a-b))


### FIXED CODE ###

import itertools
#import math

n = int(input())
#n = 2
#p = tuple(map(int,input().split(" ")))
#q = tuple(map(int,input().split(" ")))

p = input()
q = input()
#print(n)
#print(p)
i = 0
#a = 0 
#b = 0

for x in itertools.permutations(range(1,n+1), n):
	#print(x)
	x = " ".join(map(str,x))
	#print(x)
	i += 1
	if x == p:
		a = i
		#print(i)
	if x == q:
		b = i
		#print(i)

print(abs(a-b))
def check_key(S, key_length):
    for i,k in enumerate(S):
        if k == S[i+1]:
            return 'bad'
        if i == key_length - 1:
            return 'Good'
        else:
            continue
S = input()
key_length = len(S)
print(check_key(S, key_length))


### FIXED CODE ###

a,b,c,d = [int(s) for s in input()]
print('Bad') if a == b or b == c or c == d else print('Good')
n,x = map(int, input().split())
l = [0] + list(map(int, input().split()))
m = 0
d = 0
i = 1
while d <= x:
  d += l[i]
  i += 1
  if n+1 <= i:
    i = None
    break
if i = None:
  print(n+1)
else:
  print(i-1)

### FIXED CODE ###

n,x = map(int, input().split())
l = [0] + list(map(int, input().split()))
d = 0
i = 0
c = 0
while d <= x:
  d += l[i]
  i += 1
  if n+1 == i and d <= x:
    c = 1
    break
if c == 1:
  print(n+1)
else:
  print(i-1)