Harryxun/stf_run huggingface dataset:
for i in range(n):
  key = lst[i]
  if key not in dic:
    dic[key] = 0
  dic[key] += 1
#print(dic)
sum = 0
for key, value in dic.items():
  sum += key * value

m = int(input())
for _ in range(m):
  lst_s = list(map(int, input().split()))
  number = dic.get(lst_s[0])
  if number is not None:
    if lst_s[1] in dic:
      dic[lst_s[1]] += number
    else:
      dic[lst_s[1]] = number
    sum += lst_s[1] * number
    sum -= lst_s[0] * number
    dic.pop(lst_s[0])
  print(sum)

### FIXED CODE ###

n = int(input())
lst = [int(i) for i in input().split()]
dic = {}
for i in range(n):
  key = lst[i]
  if key not in dic:
    dic[key] = 0
  dic[key] += 1
#print(dic)
sum = 0
for key, value in dic.items():
  sum += key * value

m = int(input())
for _ in range(m):
  lst_s = list(map(int, input().split()))
  number = dic.get(lst_s[0])
  if number is not None:
    if lst_s[1] in dic:
      dic[lst_s[1]] += number
    else:
      dic[lst_s[1]] = number
    sum += lst_s[1] * number
    sum -= lst_s[0] * number
    dic.pop(lst_s[0])
  print(sum)
a,b,c = map(int, input().split)
d = b+c-a
if d<=0:
  print(0)
else:
  print(d)

### FIXED CODE ###

a,b,c = map(int, input().split())
d = b+c-a
if d<=0:
  print(0)
else:
  print(d)
N,A,B=map(int,input().split())

import numpy as np
blue=np.array([1]*A)
red=np.array([-1]*B)
ball=np.array(list(np.concatenate([blue,red]))*N)
print(ball)
print(np.count_nonzero(ball[0:N]==1))

### FIXED CODE ###

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

r=N//(A+B)*A
s=N%(A+B)

x=r+min(A,s)
print(x)
while True:

    W,H = map(int,input().split())
    if W==0 & H==0:
        break
    print("#"*H)
    for i in range(1,W-1):
        print("#"+"."*(H-2)+"#")
    print("#"*H)
    print(\n)

### FIXED CODE ###

while True:

    W,H = tuple(map(int,input().split()))
    if W==0 & H==0:
        break
    print("#"*H)
    for i in range(1,W-1):
        print("#"+"."*(H-2)+"#")
    print("#"*H)
    print("")
def main():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = [int(input().rstrip('\n')) for _ in range(n)]
    b = sorted(a.copy(), reverse=True)
    for i in a:
        if i == b[0]:
            print(b[1])
        else:
            print(b[0])


if __name__ == '__main__':
    main()


### FIXED CODE ###

n = int(input())
a = [int(input()) for _ in range(n)]
b = a.copy()
b = sorted(b, reverse=True)
for i in a:
    if i == b[0]:
        print(b[1])
    else:
        print(b[0])
height = []
for i in range(10):
    height.append(int(input()))
for i in range(3):
    most = max(height)
    print(most)
    height[index(most)] = 0

### FIXED CODE ###

a = []
for i in range(10):
    a.append(int(input()))
a.sort()
print(a[9])
print(a[8])
print(a[7])
while True:
    x=input()
    if x==0:
        break
    print(sum(int(s) for s in range(x)))



### FIXED CODE ###

while True:
    n=input()
    if n=='0':
        break
    s=list(n)
    a=[int(i) for i in s]
    print(sum(a))
n = int(input())
l = [int(x) for x in input().split()]
x = max(i for i in set(l) if l.count(i)>1)
if l.count(x) > 3:
  print(x*x)
else:
  y = max(i for i in set(l)-{x} if l.count(i) > 1)
  print(y*x)

### FIXED CODE ###

n = int(input())
l = sorted((int(x) for x in input().split()), reverse = True)
a = []
t = None
for x in l:
  if t == x:
    t = None
    a.append(x)
    if len(a) > 1:
      break
  else:
    t = x
print(a[0]*a[1] if len(a) > 1 else 0)
n = int(input())
p = list(map(int,input().split()))
c = 0

for i in range(1,n - 1):
    if p[n - 1] < p[n] and p[n] < p[n + 1]:
        c = c + 1

print(c)

### FIXED CODE ###

n = int(input())
p = list(map(int,input().split()))
c = 0

for i in range(1,n-1):
    if p[i-1] < p[i] and p[i] < p[i+1]:
        c = c + 1

    if p[i-1] > p[i] and p[i] > p[i+1]:
        c = c + 1

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

rate=[0]*9
over=0

for i in a:
  for j in range(1,9):
    if 400*(j-1) <= i < 400*j:
      rate[j]=1
      break
    elif i >= 3200:
      over+=1
      break

ansmin = rate.counta(1)
ansmax = rate.count(1)
if ansmin == 0:
  ansmin=1

if over > 0:
  ansmax = ansmax + over
    
#print(rate,over)
print(ansmin, ansmax)

### FIXED CODE ###

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

rate=[0]*9
over=0

for i in a:
  for j in range(1,9):
    if 400*(j-1) <= i < 400*j:
      rate[j]=1
      break
    elif i >= 3200:
      over+=1
      break

ansmin = rate.count(1)
ansmax = rate.count(1)
if ansmin == 0:
  ansmin=1

if over > 0:
  ansmax += over
    
#print(rate,over)
print(ansmin, ansmax)
from math import frexp
a, b = map(int, input().split())
print(frexp(b)-frexp(a)+1)

### FIXED CODE ###

x, y = list(map(int, input().split()))
a = x
ans = 0
while a <= y:
    a = a << 1
    ans += 1
print(ans)
n, m, x = map(int, input().split())
lst = list(map(int, input().split()))

g1, g2 = 0
for i in range(x):
  if i in lst:
    g1 += 1
    
for i in range(x+1, n):
  if i in lst:
    g2 += 1
    
print(min(g1, g2))
  

### FIXED CODE ###

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

g1, g2 = 0, 0
for i in range(x):
  if i in lst:
    g1 += 1
    
for i in range(x+1, n):
  if i in lst:
    g2 += 1
    
print(min(g1, g2))
import math

ans = 0
N,K = input().split()
for i in range(N)
	ans += Fraction(1,N)*Fraction(1,math.ceil(math.log2(K/(i+1))))
print(float(ans))

### FIXED CODE ###

import math
from fractions import Fraction

ans = 0
N, K = map(int, input().split())
for i in range(1,N+1):
	ans += Fraction(1,2**(math.ceil(math.log2(max(1,K/i)))))
ans = float(ans/N)
print('{:.10f}'.format(ans))
n=int(input())
x=input()
p=0
chk0=chk1=chk2=0
b=x.count("1")
for i,j in enumerate(x[::-1]):
    if j=="1":
        chk0+=pow(2,i)
        chk1+=pow(2,i,b+1)
        chk2+=pow(2,i,b-1)
#print(chk0,chk1,chk2)
#print(bin(chk0+1),bin(chk1),bin(chk2))
#print(bin(chk0+1).count("1"),bin(chk1).count("1"),bin(chk2).count("1"))
#print((chk1+1)%(b+1))
#print(chk0+1,bin(chk0+1).count("1"))
#print((chk0+1)%bin(chk0+1).count("1"))
#exit()
l=[]
#chk1=chk1+b+1
#chk2=chk2+b-1
for i,j in enumerate(x[::-1]):
    a1=pow(2,i,b+1)
    a2=pow(2,i,b-1)
    if j=="0":
        t=chk1+a1
    else:
        t=chk2+b-1-a2
    ans=0
    f=1
    while t:
        if f:
            if j=="0": t%=(b+1)
            else: t%=(b-1)
            f=0
        else:
            t%=bin(t).count("1")
        ans+=1
    l.append(ans)
for i in l[::-1]:
    print(i)

### FIXED CODE ###

n=int(input())
x=input()
chk0=chk1=chk2=0
b=x.count("1")
if b==1 and x=="1":
    print(0)
    exit()
elif b==1:
    for i in range(n):
        if i==n-1: print(2)
        elif x[i]=="0": print(1)
        else: print(0)
    exit()
for i,j in enumerate(x[::-1]):
    if j=="1":
        chk1+=pow(2,i,b+1)
        if b>1: chk2+=pow(2,i,b-1)
        else: chk2=0
l=[]
for i,j in enumerate(x[::-1]):
    if b: a1=pow(2,i,b+1)
    else: a1=1
    if b>1: a2=pow(2,i,b-1)
    else: a2=1
    if j=="0":
        t=chk1+a1
    else:
        if b>1: t=chk2+b-1-a2
        else: t=0
    ans,f=0,1
    while t:
        if f:
            if j=="0": t%=(b+1)
            else: t%=(b-1)
            f=0
        else:
            t%=bin(t).count("1")
        ans+=1
    l.append(ans)
for i in l[::-1]:
    print(i)
from heapq import heappush, heappop
from itertools import permutations, accumulate, combinations
from math import pi, gcd, ceil, floor
import numpy as np
from collections import defaultdict, deque
from operator import itemgetter
from bisect import bisect_left, bisect_right, insort_left, insort_right
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10 ** 6)
# MOD = 10 ** 9 + 7
# INF = float("inf")


def main():
    a, b, c = map(int, input().split())
    num = a
    for i in range(b):
        if num % b == c:
            print("YES")
            exit()
        num += a
    print("NO")


if __name__ == '__main_':
    main()

### FIXED CODE ###

a, b, c = map(int, input().split())
num = a
for i in range(b):
    if num % b == c:
        print('YES')
        break
    num += a
else:
    print('NO')
N , M = map(int,input().split())

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

A = [0]*M
B = [0]*M
for i in range(M):
  A[i] ,B[i] = map(int,input().split())


count = 0

for i in range(1,N+1):
  flag = 0
  for m in range(M):
    if i == A[m] and H[i-1]<= H[B[m]-1]:
      print('a'+A[i]+','+B[i])
      print(H[i-1]+','+H[B[m]-1])
      flag = 1
      continue
    elif i == B[m] and H[i-1]<=H[A[m]-1]:
      print('b'+A[i]+','+B[i])
      print(H[i-1]+','+H[B[m]-1])
      flag = 1
      continue
     
  if not flag:
    print(i)
    count += 1

print(count)                              
                         

### FIXED CODE ###

N , M = map(int,input().split())
 
H = list(map(int,input().split()))
 
A = [0]*M
B = [0]*M
for i in range(M):
  A[i] ,B[i] = map(int,input().split())
 
 
S=[1]*N
 
 
for m in range(M):
  if H[A[m]-1] == H[B[m]-1]:
    S[A[m]-1] = 0
    S[B[m]-1] = 0
  elif H[A[m]-1] <= H[B[m]-1]:
    S[A[m]-1] = 0
  elif H[A[m]-1] >= H[B[m]-1]:
    S[B[m]-1] = 0
 
 
print(sum(S))
x = str(input()).split(" ")

n = int(x[0])
a = int(x[1])
b = int(x[2])

plan1 = n*a
plan2 = b

if plan1 >= plan2:
	print(plan2)
else:
	print(plan1)

### FIXED CODE ###

x = list(input())

cnt = 0
for i in range(3):
	if x[i] == "1":
		cnt += 1
print(cnt)
n,k = list(map(int, input().split()))
p = list(map(int, input().split()))

print(sum(sorted(p)[:k])

### FIXED CODE ###

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

print(sum(sorted(p)[:k]))
X=int(input())
ans=None

if X>=30:
  ans=Yes
else:
  ans=No

print(ans)

### FIXED CODE ###

X=int(input())
ans=None

if X>=30:
    ans="Yes"
else:
    ans="No"

print(ans)
S=str(input())
if S[0]==S[1] or S[1]=S[2] or S[2]=S[3]:
    print('Bad')
else:
    print('Good')

### FIXED CODE ###

S=str(input())
if S[0]==S[1] or S[1]==S[2] or S[2]==S[3]:
    print('Bad')
else:
    print('Good')
S=input()
if s[0] == s[1] and s[1] == s[2]:
    print('No')
else:
    print('yes')

### FIXED CODE ###

S = input()

if len(set(S)) == 1:
    print('No')
else:
    print('Yes')
from math import gcd
from collections import defaultdict
n = int(input())
a = [[0 for i in range(20)] for j in range(20)]
data = []
ans = 0
p = pow(10,9)
two_size = 18
five_size = 18
count = 0
for i in range(n):
    k = float(input()) * p
    two = 0
    five = 0
    while k % 2 == 0:
        two += 1
        k //= 2
    while k % 5 == 0:
        five += 1
        k //= 5
    t, f = two_size - two, five_size - five
    for x in range(t, 20):
        for y in range(f, 20):
            count += a[x][y]
    a[two][five] += 1
print(count)




### FIXED CODE ###


n = int(input())
T = 45
F = 19
a = [[0 for i in range(F)] for j in range(T)]
p = pow(10,9)
two_size = 18
five_size = 18
count = 0
for i in range(n):
    s = input()
    if '.' in s:
        index = s.index('.')
        s += '0' * (  9 - (len(s) - 1 - index))
        s = s.replace('.','')
    else :
        s += '0' * 9
    k = int(s)
    two = 0
    five = 0
    while k % 2 == 0:
        two += 1
        k //= 2
    while k % 5 == 0:
        five += 1
        k //= 5
    t, f = two_size - two, five_size - five
    for x in range(t, T):
        for y in range(f, F):
            count += a[x][y]
    a[two][five] += 1
print(count)
in1 = input()
in2 = input()

N,K = in1.split()

#h_list = in2.split()

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

num=0
for h in h_list:
        if h >= K:
                num+=1

print(num)

### FIXED CODE ###

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


#h_list = in2.split()

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

num=0
for h in h_list:
        if h >= K:
                num+=1

print(num)
import itertools
import numpy as np
from sympy import *
p = Symbol('p')
q = Symbol('q')
costs = []
N = int(input())
x, y = [], []
# (x,y)の値を取得
for n in range(N):
    temp = list(map(int, input().split()))
    x.append(temp[0])
    y.append(temp[1])
# コスト計算
for n, perm in enumerate(itertools.permutations(zip(x,y), N)):
    sol = 0
    cost = 1
    for i in range(1, N):
        if i == 1:
            sol = solve([perm[i][0]-p-perm[i-1][0], perm[i][1]-q-perm[i-1][1]], [p,q])
            #print(sol)
        else:
            if perm[i][0] - sol[p] == perm[i-1][0] and perm[i][1] - sol[q] == perm[i-1][1]:
                cost += 0
            else:
                cost += 1
    costs.append(cost)
#print(costs)
print(np.min(costs))

### FIXED CODE ###

N = int(input())
arr = sorted([list(map(int, input().split())) for _ in range(N)])
cnt = {}
for i in range(N):
    for j in range(i+1,N):
        pq = (arr[j][0] - arr[i][0], arr[j][1] - arr[i][1])
        cnt.setdefault(pq, 0)
        cnt[pq] += 1
print(1 if cnt == {} else N - max(cnt.values()))
N,K=list(map(int,input().split()))
l=[0]*(K+1)
ans=0
mod=10**9+7

for x in range(K,0,-1):
    l[x]=pow((K//x),N,mod)
    for y in range(2*x,K+1,x):
        l[x]-=l[y]
        l[x]=pow(l[i],1,mod)
    ans+=l[x]*x
    ans=pow(ans,1,mod)
print(ans)

### FIXED CODE ###

N,K=list(map(int,input().split()))
l=[0]*(K+1)
ans=0
mod=10**9+7

for x in range(K,0,-1):
    l[x]=pow((K//x),N,mod)
    for y in range(2*x,K+1,x):
        l[x]-=l[y]
        l[x]=pow(l[x],1,mod)
    ans+=l[x]*x
    ans=pow(ans,1,mod)
print(ans)
n,m=map(int, input().split())
s=[list(map(int, input().split())) for _ in range(n)]
c=[list(map(int, input().split())) for _ in range(m)]
for a,b in s:
  k=[]
  for c,d in c:
    k.append(abs(a-c)+abs(b-d))
  print(k.index(min(k))+1)

### FIXED CODE ###

n,m=map(int, input().split())
s=[list(map(int, input().split())) for _ in range(n)]
o=[list(map(int, input().split())) for _ in range(m)]
for a,b in s:
  k=[]
  for c,d in o:
    k.append(abs(a-c)+abs(b-d))
  print(k.index(min(k))+1)
import math
a,b,c=map(int,input().split())
g = math.gcd(a,b)
if c % g ==0 :
    print('YES')
else:
    print('NO')


### FIXED CODE ###

import fractions
a,b,c=map(int,input().split())
g = fractions.gcd(a,b)
if c % g ==0 :
    print('YES')
else:
    print('NO')
from bisect import bisect_left
import sys
sys.setrecursionlimit(1000000)


def dfs(j, parent):
    index = bisect_left(dp, a[j])
    old = dp[index]
    dp[index] = a[j]
    ans[j] = bisect_left(dp, INF)-1
    for child in to[a[j]]:
        if child != parent:
            dfs(child, a[j])
    dp[index] = old

if __name__ == "__main__":
    n = int(input())
    a = list(map(int, input().split()))
    to = [[] for _ in range(n+1)]
    for _ in range(n-1):
        u, v = map(int, input().split())
        to[u].append(v)
        to[v].append(u)
    INF = 10**20
    dp = [INF]*(n+1)
    dp[0] = -INF
    ans = [None]*n
    dfs(1, -1)
    print(ans)

### FIXED CODE ###

from bisect import bisect_left
import sys
sys.setrecursionlimit(1000000)


def dfs(v, p):
    i = bisect_left(dp, a[v])
    dp[i], old = a[v], dp[i]
    ans[v] = bisect_left(dp, INF)-1
    for u in to[v]:
        if u == p:
            continue
        dfs(u, v)
    dp[i] = old

if __name__ == "__main__":
    n = int(input())
    a = list(map(int, input().split()))
    to = [[] for _ in range(n)]
    ans = [0]*n
    INF = 10**20
    for _ in range(n-1):
        u, v = map(int, input().split())
        u -= 1
        v -= 1
        to[u].append(v)
        to[v].append(u)
    dp = [INF]*(n+1)
    dp[0] = -INF
    dfs(0, -1)
    print("\n".join(list(map(str, ans))))
H,W = map(int,input().split())
S = list(input() for i in range(H))
Grid1 = [[0]*W for i in range(H)]
#print(S)
ans = 0
for i in range(H):
    cou = 0
    l = 0
    ws = [0]*H
    for j in range(W):
        #print(i,j,S[i][j])
        if S[i][j] == ".":
            cou += 1
        else:
            for x in range(l,j):
                ws[x] = cou
            ws[j] = 0
            l = j+1
            cou = 0
        for x in range(l,j+1):
            ws[x] = cou
    Grid1[i] = ws

for i in range(W):
    cou = 0
    l = 0
    ws = [0]*W
    for j in range(H):
        #print(i,j,S[i][j])
        if S[j][i] == ".":
            cou += 1
        else:
            for x in range(l,j):
                ws[x] = cou
            ws[j] = 0
            l = j+1
            cou = 0
        for x in range(l,j+1):
            ws[x] = cou
    for j in range(H):
        ans =max(Grid1[j][i] +ws[j], ans)

print(ans-1)

### FIXED CODE ###

H,W = map(int,input().split())
S = list(input() for i in range(H))
Grid1 = [[0]*W for i in range(H)]
for i in range(H):
    cou = 0
    l = 0
    for j in range(W):
        if S[i][j] == ".":
            cou += 1
        else:
            for x in range(l,j):
                Grid1[i][x] = cou
            l = j+1
            cou = 0
    for x in range(l,j+1):
        Grid1[i][x] = cou    
for i in range(W):
    cou = 0
    l = 0
    for j in range(H):
        #print(i,j,S[i][j])
        if S[j][i] == ".":
            cou += 1
        else:
            for x in range(l,j):
                Grid1[x][i] += cou
            l = j+1
            cou = 0
    for x in range(l,j+1):
        Grid1[x][i] += cou

print(max(max(Grid1[i]) for i in range(H))-1)
import math

input = str(input()).split(" ")
for index in range(len(input)):
    input[index] = int(input[index])
x = input[0]
y = input[1]

def ahaha(x, y):
    for index in range(1, min(abs(y), math.floor((10**(18))/x)):
        if (x * index % y != 0):
            return x * index
    return -1

print(ahaha(x,y))


### FIXED CODE ###

x,y=map(int,input().split())
if x>=y and x%y==0:
  print(-1)
elif x<y:
  print(x)
else:
  print(x*y-x)
N, K = map(int, input().split())
height = list(map(int,input().split()))
min_jump = [0,abs(height[0]-height[1])]

for num in range(2,N): #num is index of stone
  jump = 10**9
  if num < K:
    for n in range(num): # n is number of passed stones
      jump = min(jump, min_jump[num-n-1] + abs(height[num-n-1] - height[num]))
    min_jump[num] = jump
  else:
    for n in range(K): # n is number of passed stones
      jump = min(jump, min_jump[num-n-1] + abs(height[num-n-1] - height[num]))
    min_jump.append(jump)
print(min_jump[N-1])

### FIXED CODE ###

N, K = map(int, input().split())
height = list(map(int,input().split()))
min_jump = [0,abs(height[0]-height[1])]

for num in range(2,N): #num is index of stone
  jump = 10**9
  if num < K:
    for n in range(num): # n is number of passed stones
      jump = min(jump, min_jump[num-n-1] + abs(height[num-n-1] - height[num]))
    min_jump.append(jump)
  else:
    for n in range(K): # n is number of passed stones
      jump = min(jump, min_jump[num-n-1] + abs(height[num-n-1] - height[num]))
    min_jump.append(jump)
print(min_jump[N-1])
a = list(map(int,list(input())))
if a[0] == a[1] & a[1] == a[2]:
    print('Yes')
elif a[1] == a[2] & a[3] == a[4]:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

a = list(map(int,list(input())))
if a[0] == a[1] & a[1] == a[2]:
    print('Yes')
elif a[1] == a[2] & a[2] == a[3]:
    print('Yes')
else:
    print('No')
S = int(input())
total = 0
keta = len(str(S))
for i in range(keta):
  for j in range(i+3,keta):
    n = (S%10**(keta-i))//10**(keta-j-1)
    #print(n)
    if n % 2019 == 0:
      total += 1
print(total)



### FIXED CODE ###

S,W = [int(x) for x in input().split()]
if S>W:
  print("safe")
else:
  print("unsafe")
x=input().split()
a = int(x[0])
b = int(x[1])

print( a*b +' '+ a*2+b*2 )

### FIXED CODE ###

x=input().split()
a = int(x[0])
b = int(x[1])

print( a*b , a*2+b*2 )
import sys
input = sys.stdin.readline
input().rstrip() # remove last '\n'

def main():
    r,c,k = map(int, input().split())
    rcv = [ [0]*c for _ in range(r) ]

    for _ in range(k):
        ri,ci,vi = map(int, input().split())
        rcv[ri-1][ci-1] = vi

    # dp[0] = [ [0]*c for _ in range(r) ]
    # dp1 = [ [0]*c for _ in range(r) ]
    # dp2 = [ [0]*c for _ in range(r) ]
    # dp[3] = [ [0]*c for _ in range(r) ]
    dp = [ [ [0]*c  for _ in range(r) ] for _ in range(4) ]


    dp[1][0][0] = rcv[0][0]
    for i in range(r):
        for j in range(c):
            if i+1 < r:
                dp[0][i+1][j] = max(dp[0][i][j], dp[1][i][j], dp[2][i][j], dp[3][i][j], dp[0][i+1][j])
                if rcv[i+1][j] > 0:
                    dp[1][i+1][j] = max(dp[1][i+1][j],  max(dp[0][i][j], dp[1][i][j], dp[2][i][j], dp[3][i][j])+rcv[i+1][j])

            if j+1 < c:
                dp[0][i][j+1] = max(dp[0][i][j], dp[0][i][j+1])
                dp[1][i][j+1] = max(dp[1][i][j], dp[1][i][j+1])
                dp[2][i][j+1] = max(dp[2][i][j], dp[2][i][j+1])
                dp[3][i][j+1] = max(dp[3][i][j], dp[3][i][j+1])
                if rcv[i][j+1] > 0:
                    dp[1][i][j+1] = max(dp[1][i][j+1], dp[0][i][j]+rcv[i][j+1])
                    dp[2][i][j+1] = max(dp[2][i][j+1], dp[1][i][j]+rcv[i][j+1])
                    dp[3][i][j+1] = max(dp[3][i][j+1], dp[2][i][j]+rcv[i][j+1])

    ans = max(dp[0][r-1][c-1], dp[1][r-1][c-1], dp[2][r-1][c-1], dp[3][r-1][c-1])
    print(ans)


if __name__ == "__main__":
    main()

### FIXED CODE ###

r,c,k = map(int, input().split())
rcv = [ [0]*c for _ in range(r) ]

for _ in range(k):
    ri,ci,vi = map(int, input().split())
    rcv[ri-1][ci-1] = vi

dp0 = [ [0]*c for _ in range(r) ]
dp1 = [ [0]*c for _ in range(r) ]
dp2 = [ [0]*c for _ in range(r) ]
dp3 = [ [0]*c for _ in range(r) ]

dp1[0][0] = rcv[0][0]
for i in range(r):
    for j in range(c):
        if i+1 < r:
            dp0[i+1][j] = max(dp0[i][j], dp1[i][j], dp2[i][j], dp3[i][j], dp0[i+1][j])
            if rcv[i+1][j] > 0:
                dp1[i+1][j] = max(dp1[i+1][j],  max(dp0[i][j], dp1[i][j], dp2[i][j], dp3[i][j])+rcv[i+1][j])

        if j+1 < c:
            dp0[i][j+1] = max(dp0[i][j], dp0[i][j+1])
            dp1[i][j+1] = max(dp1[i][j], dp1[i][j+1])
            dp2[i][j+1] = max(dp2[i][j], dp2[i][j+1])
            dp3[i][j+1] = max(dp3[i][j], dp3[i][j+1])
            if rcv[i][j+1] > 0:
                dp1[i][j+1] = max(dp1[i][j+1], dp0[i][j]+rcv[i][j+1])
                dp2[i][j+1] = max(dp2[i][j+1], dp1[i][j]+rcv[i][j+1])
                dp3[i][j+1] = max(dp3[i][j+1], dp2[i][j]+rcv[i][j+1])

ans = max(dp0[r-1][c-1], dp1[r-1][c-1], dp2[r-1][c-1], dp3[r-1][c-1])
print(ans)
# print(dp0)
# print(dp1)
# print(dp2)
# print(dp3)
n,x=map(int,input().split())
L=list(map(int,input().split()))
D=[0]*(N+1)
o=True
for i in range(n):
    D[i+1]=D[i]+L[i]
for i in range(len(D)):
    if D[i]>x:
        print(i)
        o=False
        break
if o:
    print(n+1)

### FIXED CODE ###

n,x=map(int,input().split())
L=list(map(int,input().split()))
D=[0]*(n+1)
o=True
for i in range(n):
    D[i+1]=D[i]+L[i]
for i in range(len(D)):
    if D[i]>x:
        print(i)
        o=False
        break
if o:
    print(n+1)
import sys
m=166666;s=[1]*m;t=[1]*m
for i in range(m):
 for j in range(2):
  if (s[i],t[i])[j]:
   k=6*i+[5,7][j];n=[i+k,k-i-2]
   s[n[i]::k]=[0]*len(s[n[i]::k])
   t[n[1-i]::k]=[0]*len(t[n[1-i]::k])
for e in map(int,sys.stdin):
 print([e-1,sum(s[:(e+1)//6])+sum(t[:(e-1)//6])+2)[e>3])


### FIXED CODE ###

import sys
m=500000;a=[1]*m
for i in range(3,999,2):
 if a[i//2]:a[i*i//2::i]=[0]*len(a[i*i//2::i])
p=[]
for i in range(m*2):p+=[i-1 if i<4 else p[i-1]+[0,a[i//2]][i%2]]
for e in sys.stdin:print(p[int(e)])
=int(input())
if a<1200:
  print("ABC")
else if 2800<=a:
  print("AGC")
else:
  print("ARC")

### FIXED CODE ###

a=int(input())
if a<1200:
  print("ABC")
elif 2800<=a:
  print("AGC")
else:
  print("ARC")
x,y = map(int,input().split())
for i in range(x+1):
  2*i + 4*(x-i) == y:
    print("Yes")
    exit()
print("No")

### FIXED CODE ###

x,y = map(int,input().split())
for i in range(x+1):
  if 2*i + 4*(x-i) == y:
    print("Yes")
    exit()
print("No")
x = int(input())
print(int(not(x))

### FIXED CODE ###

x = int(input())
print(1) if x == 0 else print(0)
dict = {}
q = int(input())
for i in range(q):
    query, *val = input().split(' ')
    if query == '0':
        dict[val[0]] = int(val[1])
    elif query == '1':
        print(dict.get(val[0], 0))
    else:
        dict.pop(val[0])


### FIXED CODE ###

dict = {}
q = int(input())
for i in range(q):
    query, *val = input().split(' ')
    if query == '0':
        dict[val[0]] = int(val[1])
    elif query == '1':
        print(dict.get(val[0], 0))
    else:
        if val[0] in dict:
            dict.pop(val[0])