Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

H,W = map(int, input().split())
S = [list(input()) for _ in range(H)]

MH = [[0] * W for _ in range(H)]
MW = [[0] * W for _ in range(H)]

ans = 0
for h in range(H):
  for w in range(W):
    if ('#' != S[h][w]):
      if ((0 < h) & ('#' != S[h-1][w])):
        mh = MH[h-1][w]
      else:
        mh = 0
        for h2 in range(h,H):
          if ('#' == S[h2][w]):
            break
          mh += 1
      MH[h][w] = mh
      if ((0 < w) & ('#' != S[h][w-1])):
        mw = MW[h][w-1]
      else:
        mw = 0
        for w2 in range(w,W):
          if ('#' == S[h][w2]):
            break
          mw += 1
      MW[h][w] = mw
      a = (mh + mw) - 1
      if (ans < a):
        ans = a
      
print(ans)


### FIXED CODE ###

H,W = map(int, input().split())
S = [list(input()) for _ in range(H)]

MH = [[0] * W for _ in range(H)]
MW = [[0] * W for _ in range(H)]

ans = 0
for h in range(H):
  for w in range(W):
    if ('#' != S[h][w]):
      if ((0 < h) & ('#' != S[h-1][w])):
        mh = MH[h-1][w]
      else:
        mh = 0
        for h2 in range(h,H):
          if ('#' == S[h2][w]):
            break
          mh += 1
      MH[h][w] = mh
      if ((0 < w) & ('#' != S[h][w-1])):
        mw = MW[h][w-1]
      else:
        mw = 0
        for w2 in range(w,W):
          if ('#' == S[h][w2]):
            break
          mw += 1
      MW[h][w] = mw
      a = (mh + mw) - 1
      if (ans < a):
        ans = a
      
print(ans)
### BUGGY CODE ###

n, k = map(int, input().split())
h = sorted([int(input()) for _ in range(n)], reverse=True)
u = []
for i, v in enumerate(h[:-k+1]):
    a = h[i:i+k]
    u.append(max(a) - min(a))
print(min(u))

### FIXED CODE ###

n, k = map(int, input().split())
h = [int(input()) for _ in range(n)]
sh = sorted(h)
print(min([sh[i+k-1]-sh[i] for i in range(n-k+1)]))
### BUGGY CODE ###

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

A.sort()
B.sort()
sublist = []
for i in range(max(X-K-1, 0), X):
    for j in range(max(Y - K - 1, 0), Y):
        sublist.append(A[i]+B[j])

sublist.sort()
subanslist = sublist[-K::1]
anslist = []

for i in subanslist:
    for j in range(max(Z - K - 1, 0), Z):
        anslist.append(i+C[j])

anslist.sort()
for i in anslist[:-K-1:-1]:
    print(i)


### FIXED CODE ###

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

A.sort()
B.sort()
sublist = []
for i in range(max(X-K-1, 0), X):
    for j in range(max(Y - K - 1, 0), Y):
        if (X-i)*(Y-j) <= K:
            sublist.append(A[i]+B[j])

sublist.sort()
# print(sublist)
subanslist = sublist[-K::1]
sbsize = len(subanslist)
anslist = []
C.sort()

for num, i in enumerate(subanslist):
    for j in range(max(Z - K - 1, 0), Z):
        if (sbsize-num)*(Z-j) <= K:
            anslist.append(i+C[j])

anslist.sort()
ans = anslist[:-K-1:-1]
print(*ans, sep="\n")
### BUGGY CODE ###

n,q = map(int,input().split())
s = input()
x = []
y = []
for i in range(q):
    x1,y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)
for i in range(q):
    tmps = s[x[i]-1:y[i]]
    ans = tmps.count("AC")
    print(ans)

### FIXED CODE ###

n,q = map(int,input().split())
s = input()
x = []
y = []
for i in range(q):
    x1,y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1) 

t = [0]*n

for i in range(n-1):
    if s[i+1] == "C" and s[i] == "A":
        t[i+1] = t[i]+1
    else:
        t[i+1] = t[i]
for i in range(q):
    ans = t[y[i]-1] - t[x[i]-1]
    print(ans)
### BUGGY CODE ###

x,y,z,k = map(int, input().split())
a = sorted(map(int, input().split()), reverse=True)
b = sorted(map(int, input().split()), reverse=True)
c = sorted(map(int, input().split()), reverse=True)

d = []
d_append = d.append
for i in range(x):
    for j in range(y):
        d_append(a[i]+b[j])

d = sorted(d, reverse=True)
d = d[0:min(k,len(d))]
w = len(d)

e = []
e_append = e.append
for i in range(min(k,z)):
    for j in range(min(k,w)):
        e_append(c[i]+d[j])

e = sorted(e, reverse=True)
for f in e[0:k]:
    print(f)


### FIXED CODE ###

x,y,z,k = map(int, input().split())
a = sorted(map(int, input().split()), reverse=True)
b = sorted(map(int, input().split()), reverse=True)
c = sorted(map(int, input().split()), reverse=True)

d = []
for i in range(min(x,int(k*1.4))):
    for j in range(min(y,int(k*1.4))):
        d.append(a[i]+b[j])

d = sorted(d, reverse=True)
d = d[0:min(k,len(d))]
w = len(d)

e = []
for i in range(min(k,z)):
    for j in range(w):
        e.append(c[i]+d[j])

e = sorted(e, reverse=True)
for f in e[0:k]:
    print(f)
### BUGGY CODE ###

def flpl(): return [float(i) for i in input().split()]
def inpl(): return [int(i) for i in input().split()]
import numpy as np
import heapq
def dijkstra(vnum, vs, edge):
    dist = np.array([np.inf for _ in range(vnum)])
    dist[vs] = 0 
    remain = set(range(vnum))
    Q = []
    heapq.heappush(Q,(0,vs))
    while Q:
        c, vn = heapq.heappop(Q)
        if vn not in remain :
            continue
        remain.remove(vn)
        for j in remain:
            if dist[vn] + edge[vn][j] < dist[j]:
                dist[j] = dist[vn] + edge[vn][j] 
                heapq.heappush(Q,(dist[j],j)) 
        if not remain:
            break
    return dist

xs, ys, xt, yt = flpl()
N = int(input())
xyr = [(xs, ys, 0),(xt, yt, 0)] + [inpl() for _ in range(N)]
X, Y, R = np.array(xyr).T
X, Y, R = np.tile(X, (N+2, 1)), np.tile(Y, (N+2, 1)), np.tile(R, (N+2, 1))
edge = np.maximum(np.zeros((N+2, N+2)), np.sqrt(np.square(X-X.T) +\
                  np.square(Y-Y.T))-(R+R.T)) +\
                  np.diag(np.ones(N+2)*np.inf)
D = dijkstra(N+2, 0, edge)
print(D[1])

### FIXED CODE ###

def flpl(): return [float(i) for i in input().split()]
def inpl(): return [int(i) for i in input().split()]
import heapq
def dijkstra(vnum, vs):
    dist = [float('inf') for _ in range(vnum)]
    dist[vs] = 0 
    remain = set(range(vnum))
    Q = []
    heapq.heappush(Q,(0,vs))
    while Q:
        c, vn = heapq.heappop(Q)
        if vn not in remain :
            continue
        remain.remove(vn)
        for j in remain:
            evnj = edge(vn, j)
            if dist[vn] + evnj < dist[j]:
                dist[j] = dist[vn] + evnj 
                heapq.heappush(Q,(dist[j],j)) 
        if not remain:
            break
    return dist
def edge(s, t):
    return max(((X[s] - X[t])**2 + (Y[s] - Y[t])**2)**(1/2) -(R[s]+R[t]), 0)

xs, ys, xt, yt = flpl()
N = int(input())
xyr = [(xs, ys, 0),(xt, yt, 0)] + [inpl() for _ in range(N)]
X, Y, R = list(map(list, zip(*xyr)))
D = dijkstra(N+2, 0)
print(D[1])
### BUGGY CODE ###

from itertools import accumulate 
#acumulate [a[0], a[0]+a[1], a[0]+...]
 
n, k = map(int, input().split())
p = [int(x) - 1 for x in input().split()]
c = list(map(int, input().split()))
ans = -(10 ** 18)
 
for i in range(n):
    pos = i
    scores = []
    while True:
        pos = p[pos]
        scores.append(c[pos])
        if pos == i:
            break
    m = len(scores)
    s = list(accumulate(scores))
    for j in range(min(m, k)):
        x = (k - j - 1) // m
        ans = max(ans, s[j], s[j] + s[-1] * x)
 
print(ans)

### FIXED CODE ###

from itertools import accumulate 
#acumulate [a[0], a[0]+a[1], a[0]+...]
 
n, k = map(int, input().split())
p = [int(x) - 1 for x in input().split()]
c = list(map(int, input().split()))
ans = -(10 ** 18)
 
for i in range(n):
    pos = i
    scores = []
    while True:
        pos = p[pos]
        scores.append(c[pos])
        if pos == i:
            break
    m = len(scores)
    s = list(accumulate(scores))
    for j in range(min(m, k)):
        x = (k - j - 1) // m
        ans = max(ans, s[j], s[j] + s[-1] * x)
 
print(ans)
### BUGGY CODE ###

import sys
import numpy as np

stdin = sys.stdin

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))  # applies to only numbers
rs = lambda: stdin.readline().rstrip()  # ignores trailing space

N = ri()
A = np.arange(1, N+1, dtype=np.int64)
A_cum = A.cumsum()
i = np.nonzero(A>=N)[0][0]
diff = A_cum[i] - N
s = set(range(1, i+1))
for j in range(i+1, 0, -1):
    if j <= diff:
        s -= {j}
        diff -= j
    else:
        print(j)
# 57


### FIXED CODE ###

import sys

stdin = sys.stdin

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))  # applies to only numbers
rs = lambda: stdin.readline().rstrip()  # ignores trailing space

N = ri()
x = int((2*N) ** .5)
if x * (x+1) < 2 * N:
    x += 1
diff = x * (x+1) * .5 - N
for i in range(x, 0, -1):
    if i <= diff:
        diff -= i
    else:
        print(i)
# 57
### BUGGY CODE ###

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

A.sort(reverse=True)

for i in range(M):
    A[0] = A[0]//2
    if N>1 and A[0]<A[1]:
        A.sort(reverse=True)

print(sum(A))

### FIXED CODE ###

import heapq

N, M = map(int, input().split())
A = list(map(lambda a: int(a)*(-1), input().split()))

heapq.heapify(A)

for i in range(M):
    a = -heapq.heappop(A)//2
    heapq.heappush(A, -a)
    
print(-sum(A))
### BUGGY CODE ###

import sys

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


for i in range(1,N):

    b = [-1]*N
    c = a[:]

    b[0] = c[0]
    c[0] = -1

    b[1] = c[i]
    c[1] = -1

    for j in range(2,N):
        if b[j-2]^b[j-1] in c:
            n = c.index(b[j-2]^b[j-1])
            b[j] = c[n]
            c[n] = -1
        else:
            break

        if j == N-1:
            print("Yes")
            sys.exit()

print("No")

### FIXED CODE ###

import sys

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

l = a[0]
m = -1
n = -1
o = -1

for i in range(1,N):
    if a[i] != l and m == -1:
        m = a[i]
    elif a[i] != l and a[i] != m and n == -1 :
        n = a[i]
    elif a[i] != l and a[i] != m and a[i] != n and o == -1:
        print("No")
        sys.exit()

if (m == -1 and n == -1) and l^l == l and a.count(l) == N:
    print("Yes")
elif n == -1 and a.count(l)+a.count(m) == N and ( (a.count(l)*2==a.count(m) and l^m==m) or (a.count(l)==a.count(m)*2 and l^m == l)):
    print("Yes")
elif a.count(l)+a.count(m)+a.count(n) == N and a.count(l) == a.count(m) and a.count(m) == a.count(n) and l^m==n:
    print("Yes")
else:
    print("No")
### BUGGY CODE ###

import sys
sys.setrecursionlimit(200000)

mod = 10**9 +7
N,K = map(int,input().split())
edges = [[] for _ in range(N+1)]
for _ in range(N-1):
    a,b = map(int,input().split())
    edges[a].append(b)
    edges[b].append(a)


def dfs(cur,p,nei):
    #curにいる状態で、選べる色がcandi通りある場合の、塗り方の場合の数。
    #pが親,neiがcurの距離2以下のノードの数（curの子、弟ノードは除く）。neiが0,1のとき子に渡すneiはnei+1+兄の数、
    # neiが2のとき、子に渡すneiは、2+兄の数。
    res = K-nei 
    nxnei = min(nei+1,2)
    for nx in edges[cur]:
        if nx != p:
            res = res * dfs(nx,cur,nxnei) % mod
            nxnei += 1
    return res

print(dfs(1,0,0))

### FIXED CODE ###

import sys
sys.setrecursionlimit(200000)

mod = 10**9 +7
N,K = map(int,input().split())
edges = [[] for _ in range(N+1)]
for _ in range(N-1):
    a,b = map(int,input().split())
    edges[a].append(b)
    edges[b].append(a)


def dfs(cur,p,nei):
    #curにいる状態で、選べる色がcandi通りある場合の、塗り方の場合の数。
    #pが親,neiがcurの距離2以下のノードの数（curの子、弟ノードは除く）。neiが0,1のとき子に渡すneiはnei+1+兄の数、
    # neiが2のとき、子に渡すneiは、2+兄の数。
    res = K-nei 
    nxnei = min(nei+1,2)
    for nx in edges[cur]:
        if nx != p:
            res = res * dfs(nx,cur,nxnei) % mod
            nxnei += 1
    return res

print(dfs(1,0,0))
### BUGGY CODE ###

# coding: utf-8
from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse import csr_matrix,lil_matrix

N,M,L=map(int, raw_input().split())
RG=lil_matrix((N,N))

for i in range(M):
    f,t,c = map(int, raw_input().split())
    RG[(f-1,t-1)] = c
    RG[(t-1,f-1)] = c

Rd = floyd_warshall(RG.tocsr())

FG=lil_matrix((N,N))
d = csr_matrix(Rd).todok()
for k,v in d.items():
    if v <= L:
        FG[k] = 1

Fd = floyd_warshall(FG.tocsr(), directed=False)

Q=int(raw_input())
Queries = []
for i in range(Q):
    s, t = map(int, raw_input().split())
    v = Fd[s-1][t-1]
    if s == t:
        print (str(0))
    elif v == float('inf'):
        print (str(-1))
    else:
        print (str(int(v-1)))


### FIXED CODE ###

# coding: utf-8
from scipy.sparse.csgraph import floyd_warshall

N,M,L=map(int, input().split())
RG=[[0 for i in range(N)] for j in range(N)]

for i in range(M):
    f,t,c = map(int, input().split())
    if c <= L:
        RG[f-1][t-1] = c
        RG[t-1][f-1] = c

Rd = floyd_warshall(RG, directed=False)

FG=[[0 for i in range(N)] for j in range(N)]
for i in range(N):
    for j in range(i+1, N):
        if Rd[i][j] <= L:
            FG[i][j] = 1
            FG[j][i] = 1

Fd = floyd_warshall(FG, directed=False)

Q=int(input())
for i in range(Q):
    s, t = map(int, input().split())
    v = Fd[s-1][t-1]
    if s == t:
        print (str(0))
    if v == float('inf'):
        print (str(-1))
    else:
        print (str(int(v-1)))
### BUGGY CODE ###

import queue
x = int(input())

q = queue.Queue()
q.put((0,0))
d = dict()
d[0] = 0
while not q.empty():
    s,t = q.get()
    if s==x:
        break
    if not d.__contains__(s-(t+1)):
        q.put((s-(t+1),t+1))
        d[s-(t+1)]=t+1
    if not d.__contains__(s+t+1):
        q.put((s+t+1,t+1))
        d[s+t+1]=t+1
    q.put((s,t+1))
print(d[x])


### FIXED CODE ###

x = int(input())
s = 0
i = 0
for i in range(1,10**9):
    s += i
    if s>=x:
        break
print(i)
### BUGGY CODE ###

n, k = map(int, input().split())
h = [int(i) for i in input().split()]
dp = [0]
for i in range(1, n):
    to = min(i, k) + 1
    dp += [min([dp[-j] + abs(h[i] - h[i - j]) for j in range(1, to)])]
print(dp[-1])

### FIXED CODE ###

n, k = map(int, input().split())
h = [int(i) for i in input().split()]
dp = [0]
for i in range(1, n):
    to = min(i, k) + 1
    dp += [min([dp[-j] + abs(h[i] - h[i - j]) for j in range(1, to)])]
print(dp[-1])
### BUGGY CODE ###

if __name__ == '__main__':
    n = int(input())
    a = [int(i) for i in input().split()]
    d = dict()
    count = 0
    for no in a:
        d[no] = set()
    for i in range(n):
        no = a[i]
        pos = i+1
        # print(d)
        # print("> pos: "+str(pos))
        if no < pos:
            for j in range(no+1,pos,1):
                # print(">> j: "+str(j))
                if d.get(j-no) is not None and len(d.get(j-no)) > 0:
                    if pos - j in d.get(j-no):
                        count += 1
        d[no].add(pos)
    # print(d)
    print(count)






### FIXED CODE ###

if __name__ == '__main__':
    n = int(input())
    a = [int(i) for i in input().split()]
    d = dict()
    count = 0
    ar = [(a[i]+i+1) for i in range(n)]
    br = [(i+1-a[i]) for i in range(n)]
    for i in range(n):
        if d.get(ar[i]) is not None:
            d[ar[i]] += 1
        else:
            d[ar[i]] = 1
    c = dict()
    for i in range(n):
        if c.get(br[i]) is not None:
            c[br[i]] += 1
        else:
            c[br[i]] = 1
    count = 0
    for no in c.keys():
        if d.get(no) is not None:
            count += (c[no]*d[no])
    
    print(count)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

n = int(input())
s = list(str(input()))
q = int(input())

def segfunc(x,y):
    return x | y

def init(init_val):
    #set_val
    for i in range(n):
        seg[i+num-1]={init_val[i]}
    #built
    for i in range(num-2,-1,-1) :
        seg[i]=segfunc(seg[2*i+1],seg[2*i+2])

def update(k,x):
    k += num-1
    seg[k] = x
    while k:
        k = (k-1)//2
        seg[k] = segfunc(seg[k*2+1],seg[k*2+2])

def query(p,q):
    if q<=p:
        return ide_ele
    p += num-1
    q += num-2
    res=ide_ele
    while q-p>1:
        if p&1 == 0:
            res = segfunc(res,seg[p])
        if q&1 == 1:
            res = segfunc(res,seg[q])
            q -= 1
        p = p//2
        q = (q-1)//2
    if p == q:
        res = segfunc(res,seg[p])
    else:
        res = segfunc(segfunc(res,seg[p]),seg[q])
    return res

#####単位元######
ide_ele = set()

#num:n以上の最小の2のべき乗
num =2**(n-1).bit_length()
seg=[ide_ele]*2*num

init(s)
#print(seg)

for i in range(q):
    t, x, y = map(str, sys.stdin.readline().split())
    if t == '2':
        l = int(x)-1
        r = int(y)-1
        print(len(query(l, r+1)))
    else:
        i = int(x)-1
        c = {y}
        update(i, c)

### FIXED CODE ###

import sys
input = sys.stdin.readline

n = int(input())
s = list(str(input()))
q = int(input())

s = [ord(c)-ord('a') for c in s]

#def segfunc(x,y):
    #return x | y

def init(init_val):
    #set_val
    for i in range(n):
        seg[i+num-1]={init_val[i]}
    #built
    for i in range(num-2,-1,-1) :
        seg[i]=seg[2*i+1] | seg[2*i+2]

def update(k,x):
    k += num-1
    seg[k] = x
    while k:
        k = (k-1)//2
        seg[k] = seg[k*2+1] | seg[k*2+2]

def query(p,q):
    if q<=p:
        return ide_ele
    p += num-1
    q += num-2
    res=ide_ele
    while q-p>1:
        if p&1 == 0:
            res = res | seg[p]
        if q&1 == 1:
            res = res | seg[q]
            q -= 1
        p = p//2
        q = (q-1)//2
    if p == q:
        res = res | seg[p]
    else:
        res = (res | seg[p]) | seg[q]
    return res

#####単位元######
ide_ele = set()

#num:n以上の最小の2のべき乗
num =2**(n-1).bit_length()
seg=[ide_ele]*2*num

init(s)
#print(seg)

for i in range(q):
    t, x, y = map(str, sys.stdin.readline().split())
    if t == '2':
        l = int(x)-1
        r = int(y)-1
        print(len(query(l, r+1)))
    else:
        i = int(x)-1
        c = {ord(y)-ord('a')}
        update(i, c)
### BUGGY CODE ###

n=int(input())
s=[input() for i in range(n)]
l=list(sorted(set(s)))
li=[]
m=0
for x in l:
    m= max(m,s.count(x))
for x in l:
    if s.count(x)==m:
        li.append(x)
li=list(sorted(li))
for x in li:
    print(x)

### FIXED CODE ###

n=int(input())
s=[input() for i in range(n)]
l=list(set(s))
o=[]
for x in range(len(s)):
    o.append(0)
dic=dict(zip(l,o))

for x in s:
   if x in dic:dic[x]+=1
d=sorted(dic.items(),key=lambda x:-x[1])
m=d[0][1]
p=[]
for r in d:
    if r[1]==m:p.append(r[0])
u=sorted(p)
for y in u:
    print(y)
### BUGGY CODE ###

#C
#入力
N=int(input())
A=list(map(int,input().split()))

#処理
t=0
for i in range(len(A)):
    if A[i] in A[:i]+A[i+1:]:
        print("NO")
        t=1
        break
if t==0:
    print("YES")

### FIXED CODE ###

#C
#入力
N=int(input())
A=list(map(int,input().split()))

#処理

A.sort()
t=0
for i in range(N-1):
    if A[i]==A[i+1]:
        print("NO")
        t=1
        break
if t==0:
    print("YES")
### BUGGY CODE ###

n = int(input())
P = list(map(int,input().split()))
ans = 0
for i in range(n):
    P1 = P[0:i+1]
    m = min(P1)
    if P[i] == m:
        ans += 1
print(ans)

### FIXED CODE ###

n = int(input())
P = list(map(int,input().split()))
ans = 0
mi = P[0]
for i in range(n):
    if P[i] <= mi:
        mi = P[i]
        ans += 1
print(ans)
### BUGGY CODE ###

N,K=map(int,input().split())
Sinput=input()
S=[]
for i in range(len(Sinput)):
    S.append(int(Sinput[i]))
Smax=0
human=[]
counter=1
if S[0]==0:
    human.append(0)
for i in range(1,len(S)):
    if S[i-1]!=S[i]:
        human.append(counter)
        counter=1
    else:
        counter+=1
human.append(counter)
if len(human)%2==0:
    human.append(0)

#奇数番目が０の個数、偶数番目が１の個数
if K>=len(human)//2:
    ans=len(S)
else:
    for i in range(len(human)//2-K+1):
        if sum(human[i*2:(i+K)*2+1])>=Smax:
            Smax=sum(human[i*2:(i+K)*2+1])
    ans=Smax
print(ans)

### FIXED CODE ###

N,K=map(int,input().split())
Sinput=input()
S=[]
for i in range(len(Sinput)):
    S.append(int(Sinput[i]))
Smax=0
human=[]
humansum=[0]
counter=1
if S[0]==0:
    human.append(0)
for i in range(1,len(S)):
    if S[i-1]!=S[i]:
        human.append(counter)
        counter=1
    else:
        counter+=1
human.append(counter)
if len(human)%2==0:
    human.append(0)

#奇数番目が０の個数、偶数番目が１の個数
for i in range(len(human)):
    humansum.append(human[i]+humansum[i])

if K>=len(human)//2:
    ans=len(S)
else:
    for i in range(len(human)//2-K+1):
        Smax = max(Smax,humansum[(i+K)*2+1]-humansum[i*2])
    ans=Smax
print(ans)
### BUGGY CODE ###

N=int(input())
S=[""]
for i in range(N):
    inpu=input()
    if not inpu in S:
        S.append(inpu)
        
print(len(S)-1)

### FIXED CODE ###

N=int(input())
S=["" for j in range(N)]
for i in range(N):
    S[i]=input()
S.sort()
count=1
for i in range(1,N):
    if S[i]!=S[i-1]:
        count+=1
print(count)
### BUGGY CODE ###

N, A, B = [int(y) for y in input().split(' ')]
count = 0
while N >= A:
  count += 1
  N -= A+B
if A == 0:
  print(0)
elif N > 0:
  print(count*A + N)
else:
  print(count*A)

### FIXED CODE ###

N, A, B = [int(y) for y in input().split(' ')]
count = N // (A+B)
residue = N % (A+B)
 
if A == 0:
  print(0)
elif residue > A:
  print(count*A + A)
elif residue > 0:
  print(count*A + residue)
else:
  print(count*A)
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
ans = 0

for i in range(1, N):
    for j in range(i + 1, N + 1):
        if abs(i - j) == A[i - 1] + A[j - 1]:
            ans += 1
print(ans)

### FIXED CODE ###

from collections import Counter
N = int(input())
A = list(map(int, input().split()))
X, Y = [], []
for i in range(N):
    X.append(i + 1 + A[i])
    Y.append(i + 1 - A[i])
XL = Counter(X)
c = 0
for y in Y:
    c += XL.get(y, 0)
print(c)
### BUGGY CODE ###

def main():
    _ = int(input())
    nums = list(map(int, input().split()))
    n = len(nums)
    nums.sort()

    #print(n)
    #print(nums)

    num_bin_digits = [1 << len("{:b}".format(x)) for x in nums]
    cnt = 0
    #print(num_bin_digits)

    for cur in reversed(range(n)):
        num = nums[cur]
        if not num:
            continue
        power_of_2 = num_bin_digits[cur]
        pair = power_of_2 - num
        idx = -1
        if pair in nums[:cur]:
            idx = nums.index(pair)

        if idx != -1:
            nums[idx] = False
            cnt += 1

        #print(idx, num, power_of_2, pair)
        #print(cnt, nums)

    print(cnt)

    return

main()

### FIXED CODE ###

import math
from collections import defaultdict

def main():
    _ = int(input())
    nums = list(map(int, input().split()))
    n = len(nums)
    nums.sort()

    nums_cnt = defaultdict(int)
    for num in nums:
        nums_cnt[num] += 1

    cnt = 0
    #print(num_bin_digits)

    for cur in reversed(range(n)):
        num = nums[cur]
        if nums_cnt[num] <= 0:
            continue

        power_of_2 = 1 << math.ceil(math.log2(num))

        pair = power_of_2 - num


        if pair != 0 and nums_cnt[pair] > 0:
            nums_cnt[pair] -= 1
            nums_cnt[num] -= 1
            cnt += 1
        elif pair == 0 and nums_cnt[num] >= 2:
            nums_cnt[num] -= 2
            cnt += 1


        '''
        idx = bisect.bisect_left(nums, pair)
        if idx >= cur or nums[idx] != pair:
            #print('continue',pair, idx)
            continue

        while used[idx]:
            idx += 1

        if nums[idx] == pair:
            used[idx] = True
            cnt += 1

        #print(idx, num, power_of_2, pair)
        #print(cnt, nums, used)
        '''

        #print(nums_cnt)

    print(cnt)

    return

main()