Harryxun/stf_run huggingface dataset:
N = int(input())
util = [[int(i) for i in input().split()] for _ in range(N)]
memo = [0 for _ in range(N + 1)]
def dp(i, u, rem_i):
    if i == N:
        return u
    elif i == 0:
        ret = max(dp(i + 1, u+util[i][0], 0), dp(i + 1, u+util[i][1], 1), dp(i + 1, util[i][2], 2))
    else:
        index = list({0, 1, 2} - {rem_i})
        ret = max(dp(i + 1, u+util[i][index[0]], index[0]), dp(i + 1, u+util[i][index[1]], index[1]))
    memo[i] = ret
    return ret

print(dp(0, 0, 3))

### FIXED CODE ###

N = int(input())
util = [[int(i) for i in input().split()] for _ in range(N)]
"""
memo = [0 for _ in range(N + 1)]
def dp(i, u, rem_i):
    if i == N:
        return u
    elif i == 0:
        ret = max(dp(i + 1, u+util[i][0], 0), dp(i + 1, u+util[i][1], 1), dp(i + 1, util[i][2], 2))
    else:
        index = list({0, 1, 2} - {rem_i})
        ret = max(dp(i + 1, u+util[i][index[0]], index[0]), dp(i + 1, u+util[i][index[1]], index[1]))
    memo[i] = ret
    print(memo)
    return ret

print(dp(0, 0, 3))
"""

memo = [{} for i in range(N)]
for i in range(3):
    memo[-1][i] = util[-1][i]
for i in range(N-2, -1, -1):
    for j in range(3):
        memo[i][j] = util[i][j] + max(memo[i+1][k] for k in range(3) if j != k)
print(max(memo[0].values()))
n = int(input())

if n%2==0:
  print(0.5)
else:
  print((n+1)/2n)


### FIXED CODE ###

n = int(input())

if n%2==0:
  print(1/2)
else:
  print((n+1)/(2*n))
from collections import deque

N, M, K = [int(n) for n in input().split()]
desk_a = deque([int(n) for n in input().split()], maxlen=None)
desk_b = deque([int(n) for n in input().split()], maxlen=None)

def max_n_book(desk_a, desk_b, count=0, k=K):
    if k < 0:
        return count - 1
    if len(desk_a) != 0:
        book_a = desk_a.popleft()
        count_a = max_n_book(desk_a, desk_b, count=count+1, k=k-book_a)
    else:
        count_a = count
    if len(desk_b) != 0:
        book_b = desk_b.popleft()
        count_b = max_n_book(desk_b, desk_b, count=count+1, k=k-book_b)
    else:
        count_b = count
    return max(count_a, count_b)

n_book = max_n_book(desk_a, desk_b, count=0, k=K)
print(n_book)


### FIXED CODE ###

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

sum_a = [0]
sum_b = [0]

for i in range(N):
    sum_a.append(sum_a[-1] + desk_a[i])
for i in range(M):
    sum_b.append(sum_b[-1] + desk_b[i])

ans = 0
j = M
for i in range(N+1): 
    a = sum_a[i]
    if K - a < 0:
        break
    while sum_b[j] > K - a: 
        j -= 1
    ans = max(ans, i+j)

print(ans)
#!/Library/Frameworks/Python.framework/Versions/3.5/bin/python3

s = input()
t = input()

a = []
for i in range(len(s) - len(t)):
    cnt = 0
    for j in range(len(t)):
        if t[j] == s[i + j]:
            cnt += 1
    a.append(cnt)
print(len(t) - max(a))


### FIXED CODE ###

#!/Library/Frameworks/Python.framework/Versions/3.5/bin/python3

s = input()
t = input()

a = []
for i in range(len(s) - len(t) + 1):
    cnt = 0
    for j in range(len(t)):
        if t[j] == s[i + j]:
            cnt += 1
    a.append(cnt)
print(len(t) - max(a))
L = list(map(int,input().split()))
q = L[0]//(L[1]+L[2])
mod = L[0]%(L[1]+L[2])
if mod > L[1]:
    print(q*L[1]+L[1])
else:
    print(q*L[1]+mod%L[1])

### FIXED CODE ###

L = list(map(int,input().split()))
q = L[0]//(L[1]+L[2])
mod = L[0]%(L[1]+L[2])
if mod > L[1]:
    print(q*L[1]+L[1])
elif L[1]==0:
    print(0)
else:
    print(q*L[1]+mod%L[1])
ab,bc,ca=map(int,input().spit())
print(ab*bc*0.5)

### FIXED CODE ###

ab,bc,ca=map(int,input().split())
print(int(ab*bc*0.5))
N, K = map(int, input().split())
while N<K:
  a=N/K
  b+=1
print(b)  

### FIXED CODE ###

N, K = map(int, input().split())
b=0
while N>0:
  N=N//K
  b+=1
print(b)
N = int (input ())
l = input ().split ()
list.sort (l, reverse=True)
a = 0
x = 0
for i in range (round(N/2)):
    x += int (l[a])
    a += 2
b = 1
y = 0
for i in range (N-(round(N/2))):
    y += int (l[b])
    b += 2
print (x-y)

### FIXED CODE ###

N = int (input ())
L = input ().split ()
l = [int(s) for s in L]
list.sort (l, reverse=True)
a = 0
x = 0
y = 0
while True:
    x += int (l[a])
    a += 1
    if a == N:
        break
    y += int (l[a])
    a += 1
    if a == N:
        break
print (x-y)
N = str(input())
li = [N[0], N[1]]

if li in '9':
  print("Yes")
  
else:
  print('N0')
  


### FIXED CODE ###

N = str(input())
li = [N[0], N[1]]

if '9' in li :
  print("Yes")
  
else:
  print('No')
enemy=int(input())
skill=int(input())
for i in range(skill):
    damage=int(input())
    enemy=enemy-damage
if(enemy<=0):
    print("Yes")
else:
    print("No")


### FIXED CODE ###

enemy,skill=map(int,input().split())
damage=map(int,input().split())
if(enemy-sum(damage)<=0):
    print("Yes")
else:
    print("No")
a,b=map(int,input(sprit()))
print((a-1)(b-1))

### FIXED CODE ###

a,b=map(int,input().split())
print((a-1)*(b-1))
s = input().split(" ")
L = int(s[0])
R = int(s[1])
d = int(s[2])
cnt = 0
for i in range(L:R+1):
  if i%d == 0:
    cnt += 1
print(cnt)


### FIXED CODE ###

s = input().split(" ")
L = int(s[0])
R = int(s[1])
d = int(s[2])
cnt = 0
for i in range(L, R+1):
  if i%d == 0:
    cnt += 1
print(cnt)
S=input()
T=input()

if S in T:
  print('Yes')
  else:
    print('No')

### FIXED CODE ###

S=input()
T=input()
flag=0
 
S_length=len(S)
for num in range(S_length):
  if S[num]!=T[num]:
    flag=-1
 
if flag==0:
  print('Yes')
else:
  print('No')
prize = {1:300000,2:200000,3:100000}

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

if a == b == 1:
    print(1000000)
elif a < 4 and b < 4:
    print(prize[a] + prize[b])
elif a >= 4:
    print(prize[b])
elif b >= 4:
    print(prize[a])
else:
    print(0)


### FIXED CODE ###

prize = {1:300000,2:200000,3:100000}

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

if a == b == 1:
    print(1000000)
elif a < 4 and b < 4:
    print(prize[a] + prize[b])
elif a >= 4 and b < 4:
    print(prize[b])
elif b >= 4 and a < 4:
    print(prize[a])
else:
    print(0)
n,m=map(int,input().split())
a=[list(input()) for a in range(n)]
b=[list(input()) for a in range(m)]
c=0
for p in range(n-m+1):
  for q in range(n-m+1):
    if b[0]==a[p][q:q+m]:
      for r in range(n-m+1):
        if b[r]!=a[p+r][q-m+1:q]:pass
        else:break
        c=1
if c==1:print('Yes')
else:print('No')

### FIXED CODE ###

n,m=map(int,input().split())
a=[list(input()) for a in range(n)]
b=[list(input()) for a in range(m)]
c=0;d=0
for p in range(n-m+1):
  for q in range(n-m+1):
    if b[0]==a[p][q:q+m]:
      for r in range(m):
        if b[r]!=a[p+r][q:q+m]:d+=1
      if d==0:c=1
      else:d=0
if c==0:print('No')
else:print('Yes')
import math
from math import gcd
INF = float("inf")

import sys
input=sys.stdin.readline
sys.setrecursionlimit(500*500)
import itertools
from collections import Counter,deque

def main():
    n,m = map(int, input().split())
    l = list(map(int, input().split()))
    l.sort()

    ans = 0
    if n<m:
        L = []
        for i in range(m-1):
            l.append(l[i+1] - l[i])
        L.sort()
        for i in range(m-n):
            ans += L[i]
    print(ans)


if __name__=="__main__":
    main(
    )


### FIXED CODE ###

import math
from math import gcd
INF = float("inf")

import sys
input=sys.stdin.readline
sys.setrecursionlimit(500*500)
import itertools
from collections import Counter,deque

def main():
    n,m = map(int, input().split())
    l = list(map(int, input().split()))
    l.sort()

    ans = 0
    if n<m:
        L = []
        for i in range(m-1):
            L.append(l[i+1] - l[i])
        L.sort()
        for i in range(m-n):
            ans += L[i]
    print(ans)

if __name__=="__main__":
    main(
    )
a,b,c=map(int,input(),split())
if a<=c and c<=b:
  print("YES")
else:
  print("NO")

### FIXED CODE ###

a,b,c=map(int,input().split())
if a<=c and c<=b:
    print("Yes")
else:
    print("No")
K,A,B = map(int,input().split())
if A <= B % K == 0:
	print("OK")
else:
  	print("NG")

### FIXED CODE ###

K=int(input())
A,B=map(int,input().split())
ans="NG"

for i in range(1001):
  if A<=i*K and i*K<=B:
    ans="OK"
    break

print(ans)
x,y=map(str,input().split())
X=x[::-1]
if X==y:
    print('YES')
else:
    print('NO')

### FIXED CODE ###

x=str(input())
y=str(input())
X=x[::-1]
if X==y:
    print('YES')
else:
    print('NO')
a,b=input().split()
if a=="H":
  print(b)
elif b=="H":
  print("D")
elif:
  print("H")

### FIXED CODE ###

a,b=input().split()
if a=="H":
  print(b)
elif b=="H":
  print("D")
else:
  print("H")
N = int(input())
A = list(map(int,input().split()))
A.sort()

flag = 0
i = 1
while flag == 0:
    if A[i] % A[0] != 0:
        A[i] = A[i] % A[0]
        A[i],A[0] = A[0],A[i]
        i = 1
    else:
        i += 1
    if i == N-1:
        flag = 1
        print(A[0])
        exit()

### FIXED CODE ###

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

flag = 0
i = 1
while flag == 0:
    if A[i] % A[0] != 0:
        A[i] = A[i] % A[0]
        A[i],A[0] = A[0],A[i]
        i = 1
    else:
        i += 1
        if i == N:
            flag = 1
            print(A[0])
            exit()
def main():
    d,n = map(int, input().split())
    if n == 100:
        print(((100**d) * n) + 1)
        sys.exit()
    print((100**d) * n)  
if __name__ == '__main__':
    main()

### FIXED CODE ###

d,n = map(int,input().split())
li = []
for i in range(1,102):
    if i != 100:
        li.append(i*100**d)
print(li[n-1])
a = input()
s = input()

if int(a)=>3200:
    print(s)
else:
    print("red")
~                

### FIXED CODE ###

a = input()
s = input()

if int(a)>=3200:
    print(s)
else:
    print("red")
import math

a, b, c, d = list(map(int, input().split()))
lcm = (c * d) // math.gcd(c, d)

b_c_cnt = b // c
b_d_cnt = b // d
b_lcm_cnt = b // lcm

b_cnt = b - (b_c_cnt + b_d_cnt) + b_lcm_cnt

a_c_cnt = a // c
a_d_cnt = a // d
a_lcm_cnt = a // lcm

a_cnt = a - (a_c_cnt + a_d_cnt) + a_lcm_cnt

if (a % c != 0 and a % d != 0):
    print(b_cnt - a_cnt + 1)
else:
    print(b_cnt - a_cnt)


### FIXED CODE ###

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


a, b, c, d = list(map(int, input().split()))
lcm = (c * d) // gcd(c, d)

b_c_cnt = b // c
b_d_cnt = b // d
b_lcm_cnt = b // lcm

b_cnt = b - (b_c_cnt + b_d_cnt) + b_lcm_cnt

a_c_cnt = a // c
a_d_cnt = a // d
a_lcm_cnt = a // lcm

a_cnt = a - (a_c_cnt + a_d_cnt) + a_lcm_cnt

if (a % c != 0 and a % d != 0):
    print(b_cnt - a_cnt + 1)
else:
    print(b_cnt - a_cnt)
from sys import stdin
INF = float("inf")#無限大の設定1
IINF = 10 ** 18#無限大の設定2
MOD = 10 ** 9 + 7#まれに用いるmodを予め設定しておく
n = (stdin.readline().rstrip())
#l = list(map(int, stdin.readline().rstrip().split()))
#A, B, C = map(int, stdin.readline().rstrip().split())
#S = [list(stdin.buffer.readline().decode().rstrip()) for _ in range(h)]
S =['SUN','MON','TUE','WEN','THU','FRI','SAT']
a = S.index(n)
print(len(S) - a)


### FIXED CODE ###

from sys import stdin
INF = float("inf")#無限大の設定1
IINF = 10 ** 18#無限大の設定2
MOD = 10 ** 9 + 7#まれに用いるmodを予め設定しておく
n = (stdin.readline().rstrip())
#l = list(map(int, stdin.readline().rstrip().split()))
#A, B, C = map(int, stdin.readline().rstrip().split())
#S = [list(stdin.buffer.readline().decode().rstrip()) for _ in range(h)]
S =['SUN','MON','TUE','WED','THU','FRI','SAT']
a = S.index(n)
print(len(S) - a)
values = set_values()
max_value = min(values) - max(values)
for i in range(1, int(input())):
	for j in range(0, i-1):

		print(i, j, len(values))
		if max_value < (values[i] - values[j]):
			max_value = (values[i] - values[j])

print(max_value)


### FIXED CODE ###

def set_values():
	values = []
	for i in range(num):
		values.append(int(input()))
	return values

num = int(input())
values = set_values()
max_value = values[1] - values[0]
min_value = values[0]

for i in range(1, num):
	max_value = max(max_value, (values[i] - min_value))
	min_value = min(min_value, values[i])

print(max_value)
A, op, B = input().split()
if op = '+':
  print(int(A) + int(B))
else:
  print(int(A) - int(B))

### FIXED CODE ###

A, op, B = input().split()
if op == '+':
  print(int(A) + int(B))
else:
  print(int(A) - int(B))
s = str(input())
t = str(input())
count = 0

for i in len(s):
	if s[i] != t[i]:
		count += 1

print(count)

### FIXED CODE ###

s = str(input())
t = str(input())
count = 0

for i in range(len(s)):
	if s[i] != t[i]:
		count += 1

print(count)
import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product
from math import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

s=int(input())
print(0, 0)
print(10**9,1)
print(s//(10**9),s%(10**9))

### FIXED CODE ###

import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product
# from math import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

s=int(input())
x=(10**9-s%(10**9))%(10**9)
y=(s+x)//(10**9)
print(0, 0, 10**9,1,x,y)
# print(10**9,1)
# print(10**9-s%(10**9),s//(10**9))
n = int(raw_input())
A = []
p = range(1, n)
a = [[0 for i in range(n)]for j in range(n)]

for i in range(n):
    a[i] = map(int, raw_input().split() )

l = 0

while p != []:
    a_min = 10000
    for i in A:
        for j in p:
            if 0 <= a[i][j] < a_min:
                a_min = a[i][j]
                add_A = j
    A.append(add_A)
    p.remove(add_A)
    l += a_min

print l

### FIXED CODE ###

n = input()
A = [0]
p = range(1, n)
a = [[0 for i in range(n)]for j in range(n)]

for i in range(n):
    a[i] = map(int, raw_input().split() )

l = 0

while p != []:
    a_min = 10000
    for i in A:
        for j in p:
            if 0 <= a[i][j] < a_min:
                a_min = a[i][j]
                add_A = j
    A.append(add_A)
    p.remove(add_A)
    l += a_min

print l
"""
T E S T
"""

from collections import Counter, deque

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

cnt_a = Counter(A)
cnt_b = Counter(B)

cnt_ab = cnt_a + cnt_b

for i in cnt_ab.values():
    if i > N:
        print("No")
        exit()


print("Yes")
dq_a = deque(A)
dq_b = deque(B)

ans = []

b.rotate(n // 2)

while dq_a:
    if dq_a[0] != dq_b[0]:
        dq_a.popleft()
        p = dq_b.popleft()
        ans.append(p)
        # ans.append(b.popleft())
    else:
        dq_b.rotate()
print(*ans)


### FIXED CODE ###

"""
T E S T
"""

from collections import Counter, deque

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

cnt_a = Counter(A)
cnt_b = Counter(B)

cnt_ab = cnt_a + cnt_b

for i in cnt_ab.values():
    if i > N:
        print("No")
        exit()


print("Yes")
dq_a = deque(A)
dq_b = deque(B)

ans = []

dq_b.rotate(N // 2)

while dq_a:
    if dq_a[0] != dq_b[0]:
        dq_a.popleft()
        p = dq_b.popleft()
        ans.append(p)
        # ans.append(b.popleft())
    else:
        dq_b.rotate()
print(*ans)
import fractions

N, M = map(int,input().split())
a=[-1]
for i in range(M):
    a.append(int(input()))
a.append(N+1)
#print(a)
D=[]
for i in range(M+1):
    D.append((a[i+1]-1)-(a[i]+1))
#print(D)
def nCk(n, k):
    return fractions.factorial(n)/(fractions.factorial(k)*fractions.factorial(n-k))
ans=1
for i in range(len(D)):
    if i !=len(D) and i!=0 and D[i]==0:
        temp = 0
    else:
        temp = 0
        for j in range(D[i]//2+1):
            temp += nCk(D[i]-j,j)
#    print(temp)
    ans=(ans*temp)%1000000007
print(int(ans%1000000007))

### FIXED CODE ###

import math
N, M = map(int,input().split())
a = [int(input()) for i in range(M)]
b = [-1]+ a+ [N+1]
fib = [0,1]
for i in range(10**5):
    fib.append((fib[-1]+fib[-2])%1000000007)
ans = 1
for i in range(len(b)-1):
    ans= (ans*fib[b[i+1]-b[i]-1])%1000000007
print(ans)
heart_taka, power_taka, heart_aoki, power_aoki = map(int, input().split())

aliveTaka = True
aliveAoki = True
while (aliveTaka) or (aliveAoki):
    heart_aoki -= power_taka
    heart_taka -= power_aoki
    if heart_aoki <= 0:
        aliveAoki = False
    if heart_taka <= 0:
        aliveTaka = False

if aliveAoki == False:
    return "Yes"
return "No"

### FIXED CODE ###

heart_taka, power_taka, heart_aoki, power_aoki = map(int, input().split())

aliveTaka = True
aliveAoki = True
while (aliveTaka) and (aliveAoki):
    heart_aoki -= power_taka
    heart_taka -= power_aoki
    if heart_aoki <= 0:
        aliveAoki = False
    if heart_taka <= 0:
        aliveTaka = False

if aliveAoki == False:
    print("Yes")
else:
    print("No")
N = int(input())
S = [1 if a == "I" else -1 for a in input()]
ma = 0
a = 0
for i in range(N):
    a += S[i]
    ma = max(ma, a)
print(ma)

### FIXED CODE ###

A, B, H = [int(input()) for _ in range(3)]
print((A+B)*H//2)
n = int(input())
left = [None for i in range(n)]
right = [None for i in range(n)]
root = set(range(n))

for i in range(n):
    i, l, r = map(int, input().split())
    left[i] = l
    right[i] = r
    root -= {l, r}

def Preorder(i):
    if i == -1:
        return
    print(" {}".format(i), end = "")
    Preorder(left[i])
    Preorder(right[i])

def Inorder(i):
    if i == -1:
        return
    Inorder(left[i])
    print(" {}".format(i), end = "")
    Inorder(right[i])

def Postorder(i):
    if i == -1:
        return
    Postorder(left[i])
    Postorder(right[i])

print("Preorder")
Preorder(root)
print()

print("Inorder")
Inorder(root)
print()

print("Postorder")
Postorder(root)
print

### FIXED CODE ###

n = int(input())
left = [None for i in range(n)]
right = [None for i in range(n)]
root = sum(range(n)) - n - 1

for i in range(n):
    i, l, r = map(int, input().split())
    left[i] = l
    right[i] = r
    root -= (l + r)

def Preorder(i):
    if i == -1:
        return
    print(" {}".format(i), end = "")
    Preorder(left[i])
    Preorder(right[i])

def Inorder(i):
    if i == -1:
        return
    Inorder(left[i])
    print(" {}".format(i), end = "")
    Inorder(right[i])

def Postorder(i):
    if i == -1:
        return
    Postorder(left[i])
    Postorder(right[i])
    print(" {}".format(i), end = "")

print("Preorder")
Preorder(root)
print()

print("Inorder")
Inorder(root)
print()

print("Postorder")
Postorder(root)
print()
n,k=map(int,input().split()))
i=list(map(int,input().split()))
l=[0]*(n-k)
for j in range(n-k):
  l[j]=i[j+k]-i[j]
place=0
plus=0
for j in range(n-k):
  plus=plus+l(j)
  if plus>0:
    place=j+1
    plus=0
a=0
for j in range(k):
  a+=(i[j+place]+1)//2
print(a)

### FIXED CODE ###

n,k=map(int,input().split())
i=list(map(int,input().split()))
l=[0]*(n-k)
for j in range(n-k):
  l[j]=i[j+k]-i[j]
place=0
plus=0
for j in range(n-k):
  plus=plus+l[j]
  if plus>0:
    place=j+1
    plus=0
a=0.0
for j in range(k):
  a+=float(i[j+place]+1)/2
print(a)
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
def resolve():
    X, Y, A, B, C = lr()
    p = sorted(lr())[-X:][::-1]
    q = sorted(lr())[-Y:][::-1]
    r = sorted(lr())
    tmp = r.pop()
    pt = p[-1]
    qt = q[-1]
    ext = [0]
    while (tmp > pt or tmp > qt) and len(r) >= 0:
        if pt > qt:
            g = q.pop()
            ext.append(tmp)
            qt = q[-1]
        else:
            g = p.pop()
            ext.append(tmp)
            pt = p[-1]
        if len(r) > 0:
            tmp = r.pop()
    print(sum(p)+sum(q)+sum(ext))
resolve()

### FIXED CODE ###

import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
def resolve():
    X, Y, A, B, C = lr()
    p = sorted(lr())[-X:][::-1]
    q = sorted(lr())[-Y:][::-1]
    r = sorted(lr())
    tmp = r.pop()
    pt = p[-1]
    qt = q[-1]
    ext = [0]
    while (tmp > pt or tmp > qt) and len(r) >= 0:
        if pt > qt:
            g = q.pop()
            ext.append(tmp)
            if len(q) == 0:
                qt = pow(10, 9)+1
            else:
                qt = q[-1]
        else:
            g = p.pop()
            ext.append(tmp)
            if len(p) == 0:
                pt = pow(10, 9)+1
            else:
                pt = p[-1]
        if len(r) > 0:
            tmp = r.pop()
        else:
            break
    print(sum(p)+sum(q)+sum(ext))
resolve()
H, W, M = map(int, input().split())

h = [0] * W
w = [0] * H
Mem = []
for _ in range(M):
  i, j = map(int, input().split())
  Mem.append((i, j))
  h[i-1] += 1
  w[j-1] += 1

h_idx = h.index(max(h))
w_idx = w.index(max(w))

ans = max(h) + max(w)
if (h_idx + 1, w_idx + 1) in Mem:
  ans -= 1

print(ans)

### FIXED CODE ###

h,w,m=map(int,input().split())
item=[list(map(int,input().split())) for i in range(m)]
row=[0]*h
col=[0]*w
for i in range(m):
    x,y=item[i]
    row[x-1]+=1
    col[y-1]+=1
mr,mc=max(row),max(col)
xr=set([i for i in range(h) if row[i]==mr])
xc=set([i for i in range(w) if col[i]==mc])
check=len(xr)*len(xc)
for i in range(m):
    r,c=item[i]
    if r-1 in xr and c-1 in xc:
        check-=1
print(mr+mc if check>0 else mr+mc-1)
a, b = int(input().split())

if (a >= 1) or (b <= 100):
    num = a * b
    length = (a * 2) + (b * 2)
    print(num + " " + length, end="\n")
else:
    pass

### FIXED CODE ###

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

if (a >= 1) or (b <= 100):
    num = str(a * b)
    length = str((a * 2) + (b * 2))
    print(num + " " + length, end="\n")
else:
    pass
from collections import defaultdict
import sys
# input = sys.stdin.readline

N, M = [int(item) for item in input().split()]
A = [int(item) for item in input().split()]
A.sort()

new_dict = defaultdict(lambda: 0)
for i in range(M):
    b, c = [int(item) for item in input().split()]
    new_dict[c] += b
new_dict = sorted(new_dict.items(), key=lambda x: -x[0])


new_list = []
for k, v in new_dict:
    new_list.extend([k] * v)
    if len(new_list) >= N:
        break
new_list = new_list[:N]

#####

n = min(N, len(new_list))
for i in range(n):
    if A[i] >= new_list[i]:
        break
    A[i] = new_list[i]

print(sum(A))


### FIXED CODE ###

from collections import defaultdict
import sys
input = sys.stdin.readline

N, M = [int(item) for item in input().split()]
A = [int(item) for item in input().split()]
A.sort()

new_dict = defaultdict(lambda: 0)
for i in range(M):
    b, c = [int(item) for item in input().split()]
    new_dict[c] += b
new_dict = sorted(new_dict.items(), key=lambda x: -x[0])

new_list = []
for k, v in new_dict:
    if v > N:
        v = N
    new_list += [k] * v
    if len(new_list) >= N:
        break

new_list = new_list[:N]

#####

n = min(N, len(new_list))
for i in range(n):
    if A[i] >= new_list[i]:
        break
    A[i] = new_list[i]

print(sum(A))
from bisect  import bisect_left

n = int(input())
a = list(map(int,input().split()))
a.sort()
b = [1,2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 
     131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 
     67108864, 134217728, 268435456, 536870912]

t = []
bIdx = 0
for aa in a :
    while b[bIdx] <= aa:
        bIdx += 1   
    t.append(b[bIdx]-aa)
#t.sort()


u = [0 for i in range(len(t))]

#print(a)        
#print(t)
sum = 0
for i in range (len(a)-1,-1,-1):
    k = bisect_left(a,t[i])
    #print(t[i],k)
    if a[k] == t[i] and k < i:
        #print(a[i],t[i],i)
        sum += 1
        a[k] -= 0.1
        a[i] += 0.1
        u[k] += 1
print(sum)

### FIXED CODE ###

from bisect  import bisect_left

n = int(input())
a = list(map(int,input().split()))
a.sort()
#print(a)

sum = 0
for i in range (len(a)-1,-1,-1):

    b = 1
    while b <= a[i]:
        b = b<<1
    t = b - a[i]
    #print("2^",t)

    k = bisect_left(a,t)
    if a[k] == t and k < i:
        sum += 1
        a[k] -= 0.1
        a[i] += 0.1
print(sum)