Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
from itertools import combinations
n=int(input())
s=[input() for i in range(n)]
cnt=defaultdict(lambda :0)
cnt['M']=0
for i in range(n):
    if s[i][0] in 'MARCH':
        cnt[s[i][0]]+=1

if len(cnt)<=2:print(0)
else:
    num=len(cnt)
    ans=0
    for x,y,z in combinations(list(cnt.values()), 3):
        ans+=x*y*z
print(ans)


Fixed submission:
from collections import defaultdict
from itertools import combinations

n=int(input())
s=[input() for i in range(n)]
name=['M','A','R','C','H']

cnt=defaultdict(lambda:0)
for i in range(n):
    if s[i][0] in name:
        cnt[s[i][0]]+=1

cnt=cnt.values()
if len(cnt)<3:
    print(0)
    exit()
ans=0

# listから２つ選ぶ組み合わせ
for x,y,z in combinations(cnt,3):
    ans+=x*y*z

print(ans)
Buggy python submission (verdict: Runtime Error):
n=input()
s=list(map(int,input().split()))
sp=0
for i in s:
    if i%2==0:
        sp+=1
        continue
    else:
        break
print(sp)

Fixed submission:
print(input().count('1'))

Buggy python submission (verdict: Runtime Error):
s=list(input())
A=0　　　　　　　　　　
for i in range(3):
    if int(s[i])==1:   
        A+=1
print(A)


Fixed submission:
print(input().count('1'))
Buggy python submission (verdict: Runtime Error):
n=input()
s=list(input())
sp=0
for i in int(n):
    if s[i]%2==0:
        sp+=1
        continue
    else:
        break
print(sp)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
count=0
ans=0
for i in range(30):
    for i in range(n):
        if a[i]%2==0:
            a[i]=a[i]//2
            count+=1
        else:
            count=0
            break
    
    if count!=0:
        ans=count//n
    
print(ans)
Buggy python submission (verdict: Runtime Error):
h, w = map(int,input().split())
c = [list(map(int,input().split())) for i in range(10)]
a = [list(map(int,input().split())) for i in range(h)]

'''重み0の辺は自動で消されてしまうので注意'''
from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
inf = 10 ** 10
G = csgraph_from_dense(c, null_value = 0)
d = floyd_warshall(G)
cost = 0

for i in range(h):
    for j in range(w):
        temp = a[i][j]
        if temp == -1:continue
        cost += d[temp][1]
print(int(cost))

Fixed submission:
h, w = map(int,input().split())
c = [list(map(int,input().split())) for i in range(10)]
a = [list(map(int,input().split())) for i in range(h)]

for k in range(10):
    for i in range(10):
        for j in range(10):
            if i == j:continue
            c[i][j] = min(c[i][j], c[i][k] + c[k][j])

cost = 0
for i in range(h):
    for j in range(w):
        temp = a[i][j]
        if temp == -1:continue
        cost += c[temp][1]
print(cost)

Buggy python submission (verdict: Runtime Error):
h, w = map(int,input().split())
c = [list(map(int,input().split())) for i in range(10)]
a = [list(map(int,input().split())) for i in range(h)]

'''重み0の辺は自動で消されてしまうので注意'''
from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
inf = 10 ** 10
G = csgraph_from_dense(c, null_value = 10 ** 10)
d = floyd_warshall(G)
cost = 0

for i in range(h):
    for j in range(w):
        temp = a[i][j]
        if temp == -1:continue
        cost += d[temp][1]
print(int(cost))

Fixed submission:
h, w = map(int,input().split())
c = [list(map(int,input().split())) for i in range(10)]
a = [list(map(int,input().split())) for i in range(h)]

for k in range(10):
    for i in range(10):
        for j in range(10):
            if i == j:continue
            c[i][j] = min(c[i][j], c[i][k] + c[k][j])

cost = 0
for i in range(h):
    for j in range(w):
        temp = a[i][j]
        if temp == -1:continue
        cost += c[temp][1]
print(cost)
Buggy python submission (verdict: Runtime Error):
n=int(input())
l=list(range(1,n+1))
l=sorted(l,reverse=True)
ans=0
for i in l:
    if pow(i,0.5)%1==0:
        ans=i
        break
        
print(ans)

Fixed submission:
n=int(input())
sq=n**0.5//1
print(int(sq**2))
Buggy python submission (verdict: Runtime Error):
#WA
s = input()
ns = ''
cnt = 0
cnt1 = 0
for i in range(len(s)):
    if s[i] != 'x':
        ns += s[i]
    else:cnt += 1

if ns != ns[::-1]:
    print(-1)
    exit()

mid = len(ns) // 2
mid_str = ns[mid]
mid_ind = s.index(mid_str)
#print(mid_ind)

count = 0
for i in range(len(s)):
    if s[i] != 'x':continue
    temp_ind = 2 * mid_ind - i
    if temp_ind >= len(s) or temp_ind < 0:continue
    if s[temp_ind] == 'x':
        count += 1

#print(cnt, count)
print(cnt - count * 2)

Fixed submission:
from collections import deque
s = list(input())
s = deque(s)
cnt = 0
while len(s) > 1:
    left = s.popleft()
    right = s.pop()
    if left == right:continue
    if left != 'x' and right != 'x':
        print(-1)
        exit()

    if left == 'x':
        s.append(right)
    else:
        s.appendleft(left)
    cnt += 1
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
from scipy.sparse.csgraph import csgraph_from_dense, dijkstra
inf = 10 ** 10

n = int(input())
edge = [[inf] * n for i in range(n)]
for _  in range(n - 1):
    a, b, c = map(int,input().split())
    edge[a - 1][b - 1] = c

G = csgraph_from_dense(edge, null_value = inf)
q, k = map(int,input().split())
d = dijkstra(G, False, indices= k - 1)
for _ in range(q):
    x, y = map(int,input().split())
    dis = d[x - 1] + d[y - 1]
    print(int(dis))


Fixed submission:
#BFS
from collections import deque
def bfs(G):
    q=deque()
    q.append((k - 1, -1, 0))

    while q:
        #qの先頭を取り出す
        V, P, C = q.popleft()
        for new, cost in G[V]:
            if new == P:continue
            temp = C + cost
            q.append((new, V, temp))
            stand[new] = temp

n = int(input())
route_list = [[] for i in range(n)]  # 辺の移動の際のコスト
for i in range(n - 1):
    s, t, d = map(int, input().split())
    route_list[s - 1].append((t - 1, d))
    route_list[t - 1].append((s - 1, d))
# print(route_list)
q, k = map(int,input().split())


stand = [0] * n
bfs(route_list)
for i in range(q):
    x, y = map(int,input().split())
    temp = stand[x - 1] + stand[y - 1]
    print(temp)

Buggy python submission (verdict: Time Limit Exceeded):
from heapq import *
def dijkstra(s, n, w, cost):
    # s:始点,n:頂点数,w:辺の数,cost:辺ijの重み
    ans = [float('inf')] * n  # 最短距離の記録
    d = [[float('inf'), i] for i in range(n)]
    used = [False] * n  # 一度最短距離を確定した頂点はもう見ない
    ans[s] = 0
    d[s][0] = 0
    heapify(d)

    while d:
        D, V = heappop(d)
        if used[V]: continue
        used[V] = True

        for t, distance in cost[V]:
            ans[t] = min(ans[t], D + distance)
            heappush(d, [ans[t], t])
    return ans

n = int(input())
route_list = [[] for i in range(n)]  # 辺の移動の際のコスト
for i in range(n - 1):
    s, t, d = map(int, input().split())
    route_list[s - 1].append((t - 1, d))
    route_list[t - 1].append((s - 1, d))
# print(route_list)
q, k = map(int,input().split())

stand = dijkstra(k - 1, n, n - 1, route_list)
#print(stand)

for i in range(q):
    x, y = map(int,input().split())
    temp = stand[x - 1] + stand[y - 1]
    print(temp)

Fixed submission:
#BFS
from collections import deque
def bfs(G):
    q=deque()
    q.append((k - 1, -1, 0))

    while q:
        #qの先頭を取り出す
        V, P, C = q.popleft()
        for new, cost in G[V]:
            if new == P:continue
            temp = C + cost
            q.append((new, V, temp))
            stand[new] = temp

n = int(input())
route_list = [[] for i in range(n)]  # 辺の移動の際のコスト
for i in range(n - 1):
    s, t, d = map(int, input().split())
    route_list[s - 1].append((t - 1, d))
    route_list[t - 1].append((s - 1, d))
# print(route_list)
q, k = map(int,input().split())


stand = [0] * n
bfs(route_list)
for i in range(q):
    x, y = map(int,input().split())
    temp = stand[x - 1] + stand[y - 1]
    print(temp)
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n)]
cnt=defaultdict(lambda :0)

for i in range(m):
    for j in range(2):
        cnt[ab[i][j]]+=1

for i in cnt.values():
    if i%2!=0:
        print('NO')
        exit()
print('YES')

Fixed submission:
from collections import defaultdict
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(m)]
cnt=defaultdict(lambda :0)

for i in range(m):
    for j in range(2):
        cnt[ab[i][j]]+=1

for i in cnt.values():
    if i%2!=0:
        print('NO')
        exit()
print('YES')
Buggy python submission (verdict: Runtime Error):
n,c,k=map(int,input().split())
t=[int(input()) for i in range(n)]
t=sorted(t)
ans=0
cnt=0
first_time=t[0]
for i in range(n):
    time=t[i]-first_time
    cnt+=1
    if time==0:
        if i<=n-2 and t[i+1]-first_time>k:
            ans+=1
            first_time=t[i+1]
            cnt=0
        elif cnt==c:
            ans+=1
            first_time=t[i+1]
            cnt=0

    elif time>k:
        ans+=1
        first_time=t[i]
        cnt=0
    elif cnt==c:
        ans+=1
        first_time=t[i+1]
        cnt=0

    if i==n-1 and cnt!=0:
        ans+=1

print(ans)



Fixed submission:
n,c,k=map(int,input().split())
t=[int(input()) for i in range(n)]
t=sorted(t)
time=t[0]
cnt=0
ans=0
for i in range(n):
    #制限時間以内かつC人以内
    if time+k>=t[i] and cnt<=c-1:
        cnt+=1

    else:
        ans+=1
        time=t[i]
        cnt=1
print(ans+1)
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
a=[input() for i in range(n)]
b=[input() for i in range(m)]

if m==1:
    for i in a:
        if b[0] in i:
            print('Yes')
            exit()
        else:
            print('No')
            exit()

for i in range(n-m+1):
    cnt=0
    while cnt < n - m:
        l=[]
        for j in range(n-m+1):
        #bと同じ長さの部分配列を作る
            l+=[a[j+cnt][i:i+m]]

        if l==b:
            print('Yes')
            exit()
        cnt+=1
print('No')

Fixed submission:
n,m=map(int,input().split())
a=[input() for i in range(n)]
b=[input() for i in range(m)]

#二次元配列の部分配列を抽出する手法
#[l[i:m+i] for l in a[i:m+i]]
if m==1:
    for i in range(n):
        if b[0] in a[i]:
            print('Yes')
            exit()

    print('No')
    exit()
if m==n:
    if a==b:
        print('Yes')
        exit()
    else:
        print('No')
        exit()

for i in range(n-m):
    for j in range(n-m):
        if [l[j:m+j] for l in a[i:m+i]]==b:
            print('Yes')
            exit()

print('No')
Buggy python submission (verdict: Time Limit Exceeded):
k,s=map(int,input().split())
l=list(range(k+1))
count=0
for i in l:
    for j in l:
        k=s-i-j
        if l.count(k)==1:
            count+=1
            
print(count)

Fixed submission:
k,s=map(int,input().split())
l=list(range(k+1))
count=0
for i in l:
    for j in l:
        q=s-i-j
        if 0<=q<=k:
            count+=1
            
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
k,s=map(int,input().split())
l=set(range(k+1))
count=0
for i in l:
    for j in l:
        for k in l:
            if i+j+k==s:
                count+=1
print(count)

Fixed submission:
k,s=map(int,input().split())
l=list(range(k+1))
count=0
for i in l:
    for j in l:
        q=s-i-j
        if 0<=q<=k:
            count+=1
            
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
k,s=map(int,input().split())
l=np.array(range(k+1))
count=0
for i in l:
    for j in l:
        for k in l:
            if i+j+k==s:
                count+=1
print(count)

Fixed submission:
k,s=map(int,input().split())
l=list(range(k+1))
count=0
for i in l:
    for j in l:
        q=s-i-j
        if 0<=q<=k:
            count+=1
            
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
k,s=map(int,input().split())
l=list(range(k+1))
count=0
for i in l:
    for j in l:
        for k in l:
            if i+j+k==s:
                count+=1
print(count)

Fixed submission:
k,s=map(int,input().split())
l=list(range(k+1))
count=0
for i in l:
    for j in l:
        q=s-i-j
        if 0<=q<=k:
            count+=1
            
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
k,s=map(int,input().split())
l=list(range(k+1))
count=0
for i in l:
    for j in l:
        for k in l:
            if i+j+k==s:
                count+=1
print(count)

Fixed submission:
k,s=map(int,input().split())
l=list(range(k+1))
count=0
for i in l:
    for j in l:
        q=s-i-j
        if 0<=q<=k:
            count+=1
            
print(count)
Buggy python submission (verdict: Runtime Error):
#agc008-a
x,y=map(int,input().split())

if x<0:
    if y<0:
        ans=2+abs(y)-abs(x)
    else:
        if y<-x:
            ans=y-x
        else:
            ans=1+y+x
else:
    if y>x:
        ans=y-x
    elif y<0:
        ans=-y-x+1
print(ans)

Fixed submission:
#agc008-a
x,y=map(int,input().split())
ans=float('inf')

#反転させるかどうか決めた後のx,yの上下関係を考える
#0,0
if y-x>0:
    ans=min(ans,y-x)
#1,0
if -x<=y:
    ans=min(ans,1+y+x)
#0,1
if x<=-y:
    ans=min(ans,1+-y-x)
#1,1
if -x<=-y:
    ans=min(ans,2+-y+x)
print(ans)

Buggy python submission (verdict: Runtime Error):
#agc008-a
x,y=map(int,input().split())

y_con=-y
if x<0:
    ans=2+abs(y)-abs(x)
else:
    if y>x:
        ans=y-x
    elif y<0:
        ans=-y-x+1
print(ans)

Fixed submission:
#agc008-a
x,y=map(int,input().split())
ans=float('inf')

#反転させるかどうか決めた後のx,yの上下関係を考える
#0,0
if y-x>0:
    ans=min(ans,y-x)
#1,0
if -x<=y:
    ans=min(ans,1+y+x)
#0,1
if x<=-y:
    ans=min(ans,1+-y-x)
#1,1
if -x<=-y:
    ans=min(ans,2+-y+x)
print(ans)
Buggy python submission (verdict: Runtime Error):
a,b,x=map(int,input().split())
n=b-a+1
l=[0]*(n+1)
init=a
for i in range(1,n+1):
    if init%x==0:
        l[i]=l[i-1]+1
    else:
        l[i]=l[i-1]
    init+=1

print(l[-1]-l[0])

Fixed submission:
#48-B
a,b,x=map(int,input().split())
b_count=b//x
a_count=(a-1)//x
print(b_count-a_count)

Buggy python submission (verdict: Runtime Error):
a,b,x=map(int,input().split())
n=b-a+1
l=[0]*(n+1)
init=a
for i in range(1,n+1):
    if init%x==0:
        l[i]=l[i-1]+1
    else:
        l[i]=l[i-1]
    init+=1
    
print(l[-1]-l[1])

Fixed submission:
#48-B
a,b,x=map(int,input().split())
b_count=b//x
a_count=(a-1)//x
print(b_count-a_count)

Buggy python submission (verdict: Runtime Error):
a,b,x=map(int,input().split())
n=b-a+1
l=[0]*(n+1)
init=a
for i in range(1,n+1):
    if init%x==0:
        l[i]=l[i-1]+1
    else:
        l[i]=l[i-1]
    init+=1
    
print(l[-1]-l[0])

Fixed submission:
#48-B
a,b,x=map(int,input().split())
b_count=b//x
a_count=(a-1)//x
print(b_count-a_count)

Buggy python submission (verdict: Runtime Error):
a,b,x=map(int,input().split())
n=b-a+1
l=[0]*(n+1)
init=a
for i in range(1,n+1):
    if init%x==0:
        l[i]=l[i-1]+1
    else:
        l[i]=l[i-1]
    init+=1
    
print(l)
print(l[-1]-l[0])

Fixed submission:
#48-B
a,b,x=map(int,input().split())
b_count=b//x
a_count=(a-1)//x
print(b_count-a_count)
Buggy python submission (verdict: Runtime Error):
a,b,x=map(int,input().split())
n=b-a+1
l=[0]*(n+1)
init=a
for i in range(1,n+1):
    if init%x==0:
        l[i]=l[i-1]+1
    else:
        l[i]=l[i-1]
    init+=1
    
print(l[-1]-l[0])

Fixed submission:
#048-C
n,x=map(int,input().split())
a=list(map(int,input().split()))
a_sum=sum(a)
ans=0
if a[0]>x:
    a[0]=x
    ans+=a[0]-x
else:
    ans+=a[0]
for i in range(n-1):
    if a[i]+a[i+1]>x:
        a[i+1]-=a[i+1]+a[i]-x
        ans+=a[i+1]
print(a_sum-sum(a))
Buggy python submission (verdict: Runtime Error):
#abc047-b
w,h,n=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
#x,y,a
x_min=0
y_min=0

for i in l:
    if i[-1]==1:
        x_min=max(i[0],x_min)

    elif i[-1]==2:
        w=min(i[0],w)

    elif i[-1]==3:
        y_min=max(i[1],y_min)

    else:
        h=min(i[1],h)
s=
print((w-x_min)*(h-y_min) if (w-x_min)>0 and (h-y_min)>0 else 0)

Fixed submission:
#abc047-b
w,h,n=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
#x,y,a
x_min=0
y_min=0

for i in l:
    if i[-1]==1:
        x_min=max(i[0],x_min)

    elif i[-1]==2:
        w=min(i[0],w)

    elif i[-1]==3:
        y_min=max(i[1],y_min)

    else:
        h=min(i[1],h)

print((w-x_min)*(h-y_min) if (w-x_min)>0 and (h-y_min)>0 else 0)
Buggy python submission (verdict: Runtime Error):
s=list(input())
k=int(input())

for i in range(len(s)):
    num_al=ord(s[i])
    a_=123-num_al
    if k==0:break
    if s[i]=='a' and i!=len(s)-1:continue

    if a_<=k and i!=len(s)-1:
        k-=a_
        s[i]='a'
    elif a_>k and i<len(s)-1:continue
    else:
        s[i]=chr(num_al+k) if num_al+k<=122 else chr(num_al+k-26)
        k=0
print(''.join(s))

Fixed submission:
s=list(input())
k=int(input())

for i in range(len(s)):
    if k==0:break

    num=ord(s[i])
    ch_num=123-num
    if i==len(s)-1:
        s[i]=chr(97+(num+k-97)%26) #if num+k>122 else chr(num+k)
        #print(97+(num+k-97)%26)
        k=0
        break
    elif s[i]=='a':continue
    elif ch_num<=k:
        s[i]='a'
        k-=ch_num
print(''.join(s))

Buggy python submission (verdict: Runtime Error):
s=list(input())
k=int(input())

for i in range(len(s)):
    num_al=ord(s[i])
    a_=123-num_al
    if k==0:break
    if s[i]=='a' and i!=len(s)-1:continue

    if a_<=k and i!=len(s)-1:
        k-=a_
        s[i]='a'
    elif a_>k and i<len(s)-1:continue
    else:
        s[i]=chr(num_al+k) if num_al+k<=122 else chr(num_al+k-122)
        k=0
print(''.join(s))

Fixed submission:
s=list(input())
k=int(input())

for i in range(len(s)):
    if k==0:break

    num=ord(s[i])
    ch_num=123-num
    if i==len(s)-1:
        s[i]=chr(97+(num+k-97)%26) #if num+k>122 else chr(num+k)
        #print(97+(num+k-97)%26)
        k=0
        break
    elif s[i]=='a':continue
    elif ch_num<=k:
        s[i]='a'
        k-=ch_num
print(''.join(s))
Buggy python submission (verdict: Runtime Error):
a,b,h=map(int,input().split())
print(int((a+b)*h/2))

Fixed submission:
a,b,h=int(input()),int(input()),int(input())
print(int((a+b)*h/2))

Buggy python submission (verdict: Runtime Error):
a,b,h=map(int,input().split())
print(int((a+b)*h/2))

Fixed submission:
a,b,h=int(input()),int(input()),int(input())
print(int((a+b)*h/2))
Buggy python submission (verdict: Runtime Error):
a=list(map(int,input().split()))
a=sorted(a)

a_ave=a[0]+a[-1]
num1=a_ave//2
num2=a_ave//2+1
ans1=0
ans2=0
for i in range(n):
    ans1+=(num1-a[i])**2
    ans2+=(num2-a[i])**2
print(min(ans1,ans2))

Fixed submission:
n=int(input())
a=list(map(int,input().split()))

ans=float('inf')
num=-100
while num!=101:
    kari=0
    for i in range(n):
        kari+=(num-a[i])**2
    num+=1
    ans=min(ans,kari)

print(ans)
Buggy python submission (verdict: Runtime Error):
s=input()

count=0
for i in range(len(s)-2):
    if s[i]==s[i+1] or s[i]==s[i+2] or s[i+1]=s[i+2]:
        print(i+1,i+3)
        exit()
print(-1,-1)

Fixed submission:
s=input()
if len(s)==2:
    if len(set(s))==1:
        print(1,2)
        exit()
    else:
        print(-1,-1)
        exit()
        
for i in range(len(s)-2):
    a=s[i:i+3]
    if len(set(a))<=2 :
        print(i+1,i+3)
        exit()
print(-1,-1)
Buggy python submission (verdict: Runtime Error):
from bisect import *
n, k = map(int,input().split())
d = list(map(int,input().split()))

use_num = []
for i in range(10):
    if i in d:continue
    use_num.append(i)

str_n = str(n)
res = 0
for i in str_n:
    temp = bisect_left(use_num, int(i))
    add = use_num[temp]
    if temp == len(use_num):
        add = use_num[0] * 10
    res = res * 10 + add 
print(res)

Fixed submission:
n,k=map(int,input().split())
d=list(map(int,input().split()))

num=[]
for i in range(10):
    if i not in d:
        num.append(i)
#print(num)
num.sort()
digit=len(str(n))
ns=str(n)

ans=''
cnt=0
while cnt<digit:

    for i in num:
        if int(ns[cnt])>i:continue
        if int(ns[cnt])==i:
            ans+=str(i)
            break
        else:
            ans+=str(i)+(digit-cnt-1)*str(num[0])
            cnt=digit
            break
    else:
        ans=str(num[0]) if num[0]!=0 else str(num[1])
        ans+=str(num[0])*digit
        cnt=digit
    cnt+=1
print(ans)

Buggy python submission (verdict: Runtime Error):
from bisect import *
n, k = map(int,input().split())
d = list(map(int,input().split()))

use_num = []
for i in range(10):
    if i in d:continue
    use_num.append(i)

str_n = str(n)
res = 0
for i in str_n:
    temp = bisect_left(use_num, int(i))
    res = res * 10 + use_num[temp]
print(res)

Fixed submission:
n,k=map(int,input().split())
d=list(map(int,input().split()))

num=[]
for i in range(10):
    if i not in d:
        num.append(i)
#print(num)
num.sort()
digit=len(str(n))
ns=str(n)

ans=''
cnt=0
while cnt<digit:

    for i in num:
        if int(ns[cnt])>i:continue
        if int(ns[cnt])==i:
            ans+=str(i)
            break
        else:
            ans+=str(i)+(digit-cnt-1)*str(num[0])
            cnt=digit
            break
    else:
        ans=str(num[0]) if num[0]!=0 else str(num[1])
        ans+=str(num[0])*digit
        cnt=digit
    cnt+=1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
agc 029 B
"""

from collections import Counter

n = int(input())
ali = list(map(int, input().split()))
ali.sort(reverse=True)

c = Counter(ali)
ans = 0


def pow2(n):
    m = n
    tmp = 1
    while m > 0:
        tmp = tmp << 1
        m = m >> 1
    return tmp


ii = 0
m = ali[ii]
while bool(c):
    n = pow2(m) - m
    c[m] -= 1
    if c[m] == 0:
        c += Counter()
        ii += 1
        m = ali[ii]
    if n in c:
        c[n] -= 1
        ans += 1
    c += Counter()

print(ans)








Fixed submission:
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
agc 029 B
"""

from collections import Counter

nn = int(input())
ali = list(map(int, input().split()))
ali.sort(reverse=True)

c = Counter(ali)
ans = 0


def pow2(n):
    m = n
    tmp = 1
    while m > 0:
        tmp = tmp << 1
        m = m >> 1
    return tmp


ii = 0
m = ali[ii]
while bool(c):
    while c[ali[ii]] == 0:
        ii += 1
    m = ali[ii]
    n = pow2(m) - m
    c[m] -= 1
    if c[m] <= 0:
        del c[m]
    if n in c:
        c[n] -= 1
        if c[n] <= 0:
            del c[n]
        ans += 1

print(ans)