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

def get_common_divisor_list(a,b):
	cd_list = []
	for i in range(1,min(a,b)+1):
		if a%i == 0 and b%i == 0:
			cd_list.append(i)
	return cd_list

def is_coprime(a,b):
	cd_list = get_common_divisor_list(a,b)
	if len(cd_list) == 1 and 1 in cd_list :
		return True
	return False

from math import sqrt
def is_prime(n):
	if n==1:
		return False
	for k in range(2,int(sqrt(n))+1):
		if n%k == 0:
			return False
	return True

def main():
	A,B = map(int,input().split())
	cds = get_common_divisor_list(A,B)
	res = []
	for cd in cds :
		if cd == 1 :
			res.append(1)
			continue
		if is_prime(cd):
			res.append(cd)
	print(len(res))
main()

### FIXED CODE ###

import math
def trial_division(n):
	factor = []
	while n%2 == 0:
		factor.append(2)
		n //= 2
	f = 3
	while f <= math.sqrt(n):
		if n%f == 0:
			factor.append(f)
			n //= f
		else :
			f += 2
	if n!= 1:
		factor.append(n)
	return factor

def main():
	cds = set()
	cds.add(1)
	a,b = map(int,input().split())
	primes_a = trial_division(a)
	primes_b = trial_division(b)
	if primes_a != None and primes_b != None :
		for prime in primes_a:
			if prime in primes_b:
				cds.add(prime)
	print(len(cds))
main()
### BUGGY CODE ###

import sys
def solve():
    readline = sys.stdin.readline
    write = sys.stdout.write
    MOD = 998244353

    N = int(readline())
    P = [list(map(int, readline().split())) for i in range(N)]

    P.sort()

    Y = [y for x, y in P]

    def compress(X):
        *XS, = set(X)
        XS.sort()
        return list(map({e: i for i, e in enumerate(XS)}.__getitem__, X))
    Y = compress(Y)

    data = [0]*(N+1)
    def add(k, x):
        while k <= N:
            data[k] += x
            k += k & -k
    def get(k):
        s = 0
        while k:
            s += data[k]
            k -= k & -k
        return s

    def gen(add, get):
        pow2 = [1]*N
        r = 1
        for i in range(1, N):
            pow2[i] = r = r * 2 % MOD

        for i, y in enumerate(Y):
            v1 = get(y+1); v0 = y - v1
            w1 = i - v1; w0 = (N - y - 1) - w1
            add(y+1, 1)
            p1 = pow2[v1]; p0 = pow2[v0]
            q1 = pow2[w1]; q0 = pow2[w0]
            yield (pow(2, 1+v0+v1+w0+w1, MOD) - (1 - p0 - p1 - q0 - q1 + (p0 + q1) * (p1 + q0))) % MOD
    write("%d\n" % (sum(gen(add, get)) % MOD))
solve()

### FIXED CODE ###

import sys
def solve():
    readline = sys.stdin.readline
    write = sys.stdout.write
    MOD = 998244353

    N = int(readline())
    P = [list(map(int, readline().split())) for i in range(N)]

    P.sort()

    Y = [y for x, y in P]

    def compress(X):
        *XS, = set(X)
        XS.sort()
        return list(map({e: i for i, e in enumerate(XS)}.__getitem__, X))
    Y = compress(Y)

    data = [0]*(N+1)
    def add(k, x):
        while k <= N:
            data[k] += x
            k += k & -k
    def get(k):
        s = 0
        while k:
            s += data[k]
            k -= k & -k
        return s

    def gen(add, get):
        pow2 = [1]*N
        r = 1
        for i in range(1, N):
            pow2[i] = r = r * 2 % MOD

        for i, y in enumerate(Y):
            v1 = get(y+1); v0 = y - v1
            w1 = i - v1; w0 = (N - y - 1) - w1
            add(y+1, 1)
            p1 = pow2[v1]; p0 = pow2[v0]
            q1 = pow2[w1]; q0 = pow2[w0]
            yield (2 * (p1*p0 % MOD)*(q1*q0 % MOD) % MOD) - (1 - p0 - p1 - q0 - q1 + (p0 + q1) * (p1 + q0)) % MOD
    write("%d\n" % (sum(gen(add, get)) % MOD))
solve()
### BUGGY CODE ###

import itertools
k = 10 ** 9 + 7
N = int(input())
L = list(map(int, input().split()))
S = 0
for c in itertools.combinations(L, 2):
  S += (c[0] * c[1]) % k
print(S % k)

### FIXED CODE ###

k = 10 ** 9 + 7
N = int(input())
L = list(map(int, input().split()))
S = sum(L) ** 2
for i in L:
  S -= i ** 2

print( (S // 2) % k)
### BUGGY CODE ###

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

import bisect
from collections import deque

for i in range(M):
  A = sorted(A)
  lm = bisect.bisect_right(A, C[i]-1)-1
  A = deque(A)
  for j in range(min(B[i],lm+1)):
    A.popleft()
  for j in range(min(B[i],lm+1)):
    A.appendleft(C[i])
    
print(sum(A))


### FIXED CODE ###

N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = [[] for _ in range(M)]
for i in range(M):
  BC[i] = list(map(int, input().split()))

BC.sort(key=lambda x: x[1], reverse=True)

for i in BC:
  A.extend([i[1]]*i[0])
  if len(A) > 2*N:
    break
    
A = sorted(A,reverse=True)
print(sum(A[:N]))
### BUGGY CODE ###

S = list(input())
zeroone = []
for i in range(len(S)):
    if S[i] == "<":
        zeroone.append(1)
    else:
        zeroone.append(-1)

cnt = [0]
for i in range(len(zeroone)-1):
    if zeroone[i+1] != zeroone[i]:
        cnt.append(i+1)
cnt.append(len(zeroone))

ans = [0] * (len(zeroone)+1)

if zeroone[0] == 1:
    for j in range(0, cnt[1]):
            ans[j+1] = ans[j] + 1

for i in range(len(zeroone)-1):
    if zeroone[i+1] - zeroone[i] > 0:
        ans[i+1] = 0
        for j in range(i+1, cnt[cnt.index(i+1) + 1]):
            ans[j+1] = ans[j] + 1
        
        for k in range(cnt[cnt.index(i+1) - 1], i+1)[::-1]:
            ans[k] = max(ans[k+1] + 1, ans[k])

if zeroone[-1] == -1:
    for k in range(cnt[-2], cnt[-1])[::-1]:
            ans[k] = max(ans[k+1] + 1, ans[k])

print(sum(ans))

### FIXED CODE ###

# coding: utf-8

S = list(input())
S.append("end")

def count(r, l):
    part_sum = ((r-1)*r + (l-1)*l)/2 #"<<<>>>"頂点の値以外
    part_max = max(r, l) #"<<<>>>"頂点の値
    return(part_sum + part_max)

ans = 0
r = l = 0
for i in range(len(S)-1):
    if S[i+1] != S[i] and S[i] == ">": #"<<<>>>"をセットとして足す
        r += 1
        ans += count(r, l)
        r = l = 0
    elif S[i] == "<":
        l += 1
    elif S[i] == ">":
        r += 1
ans += count(r, l) #"<"終わりの時は、その分がカウントされないので足す(ただしl = 0)
print(int(ans))
### BUGGY CODE ###

N=int(input())
k=N//2
D=list(map(int,input().split()))
DD=D[:]+D[:]
T=sum(D)
ret=[0]*N
for i in range(N):
  ret[i]=T-2*sum(DD[i+1:i+2*k:2])
print(*ret)

### FIXED CODE ###

N=int(input())
k=N//2
D=list(map(int,input().split()))
DD=D[:]+D[:]
DS=[0]*(2*N+1)
for i in range(0,2*N-2,2):
  DS[i+2]=DS[i]+DD[i]
  DS[i+3]=DS[i+1]+DD[i+1]
T=sum(D)
ret=[0]*N
for i in range(N):
#  print(sum(DD[i+1:i+2*k:2]))
#  print(DS[i+1+2*k]-DS[i+1])
#  ret[i]=T-2*sum(DD[i+1:i+2*k:2])
  ret[i]=T-2*(DS[i+1+2*k]-DS[i+1])
print(*ret)
### BUGGY CODE ###

k = int(input())
x = 7
ans = 1
if k%2 == 0 or k%5 ==0:
  ans = -1
else:
  while x%k != 0:
    ans +=1
    x *= 10
    x+=7

print(ans)



### FIXED CODE ###

k = int(input())
x = 7
ans = 1
if k%2 == 0 or k%5 ==0:
  print(-1)
  exit()
elif 7%k == 0:
  ans = 1

else:
  for i in range (1,k):
    x = (x*10+7)%k

    if x%k == 0:
      ans = i+1
      break

print(ans)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
# import numpy as np

n, m = map(int, input().split())

t = [0]*n

for i in range(m):
    l, r = map(int, input().split())
    for j in range(n):
        if l<=j+1 and r>=j+1:
            t[j] += 1

print(t.count(m))

### FIXED CODE ###

# -*- coding: utf-8 -*-
# import numpy as np

n, m = map(int, input().split())

l_min = 1
r_max = n+1

for i in range(m):
    l, r = map(int, input().split())
    l_min = max(l_min, l)
    r_max = min(r_max, r)

ans = r_max - l_min + 1
if ans > 0:
    print(ans)
else:
    print(0)
### BUGGY CODE ###

import sys
import math

from collections import defaultdict
from collections import deque
def load(vtype=int):
    return vtype(input().strip())

def exit():
    import sys
    sys.exit(0)


def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while True:
        r = a % b
        if r == 0: return b
        a, b = b, r
def lcm(a, b):
    return int(a * b / gcd(a,b))


d = dict()
d2 = dict()

def check(a, b, d2):
    t = tuple(sorted([a,b]))
    if t in d2:
        return d2[t]
    return False

k = load()
s = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        for k in range(1, k+1):
            r = check(i, j, d2)
            target = None
            if r:
                target = k
            else:
                r = check(j, k, d2)
                if r:
                    target = i
                else:
                    r = check(i, k, d2)
                    if r:
                        target = j
                    else:
                        # print(i,j,k)
                        d2[(i,j)] = gcd(i,j)
                        r = d2[(i,j)]
                        target = k
            r2 = check(r, target, d2)
            if r2:
                s += r2
            else:
                d2[(r, target)] = gcd(r, target)
                s += d2[(r, target)]

print(s)
                

### FIXED CODE ###

from math import gcd
 
def main():
    k = int(input())
    ans = 0
 
    for a in range(1, k+1):
        for b in range(1, k+1):
            for c in range(1, k+1):
                ans += gcd(gcd(a, b), c)
 
    print(ans)
 
if __name__ == "__main__":
    main()
### BUGGY CODE ###

import sys
N,M=map(int,input().split())
grid = []
for i in range(M):
    array = list(map(int, input().strip().split(' ')))
    grid.append(array)
pre = []
pos = []
for ships in grid:
  if ships[0] == 1:
    pre.append(ships[1])
  if ships[1] == N:
    pos.append(ships[0])
if pre == [] or pos == []:
  print('IMPOSSIBLE')
  sys.exit()
pre.sort()
for islands in pre:
  if islands in pos:
    print('POSSIBLE')
    sys.exit()
print('IMPOSSIBLE')


### FIXED CODE ###

import sys
import bisect
N,M=map(int,input().split())
grid = []
for i in range(M):
    array = list(map(int, input().strip().split(' ')))
    grid.append(array)
pre = []
pos = []
for ships in grid:
  if ships[0] == 1:
    pre.append(ships[1])
  if ships[1] == N:
    pos.append(ships[0])
if pre == [] or pos == []:
  print('IMPOSSIBLE')
  sys.exit()
pre.sort()
pos.sort()
def index(a, x):
    'Locate the leftmost value exactly equal to x'
    i = bisect.bisect_left(a, x)
    if i != len(a) and a[i] == x:
        return 1
    return 0
for nums in pre:
  if index(pos,nums) == 1:
    print('POSSIBLE')
    sys.exit()
print('IMPOSSIBLE')
### BUGGY CODE ###

N,A,B=map(int, raw_input().split()) 
H=[ input() for i in range(N) ] 

def func(n , T):
	sa=A-B
	k=0
	for x in T:
		x-=n*B
		if x>0:
			if x%sa==0:
				k+=x/sa
			else:
				k+=(x/sa+1)
		
			if n<k:
				return False
	else:
			return True

l=0
r=max(H)/B+1
while l!=r:
	m=(r+l)/2
	if func(m,H):
		r=m
	else:
		l=m+1

print l



### FIXED CODE ###

N,A,B= map(int,raw_input().split())
h=[input() for _ in range(N)]

high=max(h)
low=1

def enough(T):
	cnt=0
	for i in h:
		i-=T*B
		if i>0:
			if i%(A-B)==0:
				cnt+=i/(A-B)
			else:
				cnt+=i/(A-B)+1
	if cnt<=T:
		return True
	else:
		return False

ans=0
while low<=high:
	c= (low + high) / 2
	if enough(c):
		high=c-1
		ans=c
	else:
		low=c+1


print ans
### BUGGY CODE ###

d_list = []

times = int(input())
for i in range(times):
    elm = input().split()
    if elm[0] == "insert":
        d_list.append(elm[1])
    elif elm[0] == "find":
        if elm[1] in d_list:
            print("yes")
        else:
            print("no")

### FIXED CODE ###

n = int(input())

d = set()
for i in range(n):
    com = input().split()
    if com[0] == 'insert':
        d.add(com[1])
    else:
        print('yes' if com[1] in d else 'no')
### BUGGY CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    N, T = map(int, input().split())
    t = list(map(int, input().split()))

    s = set()
    for x in t:
        s |= set(range(x, x+T))
    print(len(s))


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    N, T = map(int, input().split())
    t = list(map(int, input().split()))

    arr = [[]] * len(t)
    for i in range(len(t)):
        arr[i] = [t[i], t[i]+T]

    ans = arr[0][1]
    for i in range(len(t)-1):
        _, t1 = arr[i]
        f2, t2 = arr[i+1]

        if t1 <= f2:
            ans += t2 - f2
        else:
            ans += t2 - t1
    print(ans)


if __name__ == '__main__':
    main()
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))
def judge(count):
  idx = 0
  for i in range(2,n+1):
    if count == -1:
      if sum(a[0:i]) < 0:
        pass
      else:
        check = sum(a[0:i]) + 1
        j = a[i-1]
        a[i-1] = j - check
        idx += check
    elif count == 1:
      if sum(a[0:i]) > 0:
        pass
      else:
        check = 1 - sum(a[0:i])
        j = a[i-1]
        a[i-1] = check+ j
        idx += check
    count *= -1
  return idx
if a[0] > 0:
  b = judge(-1)
  print(b)
elif a[0] < 0:
  c = judge(1)
  print(c)
else:
  a[0] = 1
  b = judge(-1)
  a[0] = -1
  c = judge(1)
  print(min(b,c))


### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
ans1,ans2 = 0,0
sum1,sum2 = 0,0
for i in range(n):
    sum1 += a[i]
    if i%2 == 1 and sum1 >= 0:
        ans1 += sum1 + 1
        sum1 = -1
    elif i%2 == 0 and sum1 <= 0:
        ans1 += -sum1 + 1
        sum1 = 1
for i in range(n):
    sum2 += a[i]
    if i%2 == 0 and sum2 >= 0:
        ans2 += sum2 + 1
        sum2 = -1
    elif i%2 == 1 and sum2 <= 0:
        ans2 += -sum2 + 1
        sum2 = 1
print(min(ans1,ans2))
### BUGGY CODE ###

def main(n: int, a: list):
    for i in range(n):
        t = a.copy()
        t[i] = 0

        print(max(t))


if __name__ == "__main__":
    n = int(input())
    a = [int(input()) for _ in range(n)]

    main(n, a)


### FIXED CODE ###

def main(n: int, a: list):
    a_max, a_second = sorted(a, reverse=True)[:2]

    for i in range(n):
        if a[i] != a_max:
            print(a_max)
        else:
            print(a_second)


if __name__ == "__main__":
    n = int(input())
    a = [int(input()) for _ in range(n)]

    main(n, a)
### BUGGY CODE ###

from sys import stdin
from itertools import accumulate, dropwhile, takewhile, groupby

# 入力 =stdin.readline().rstrip()
# 分割 = stdin.readline().rstrip().split()

'''
条件に合うものを絞り込む
data = [1, 2, 3]
s = [x for x in data if x % 3 == 0]
'''

'''
文字配列を数値に
l_si = ['-10', '0', '100']

l_si_i = [int(s) for s in l_si]
'''

'''
a = [2, 4, 6, 8]
b = [3, 6, 9]

print(list(set(a) | set(b)))  # 和集合
print(list(set(a) & set(b)))  # 積集合
'''

'''
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
count = 0
while len([x for x in A if x % 2 == 0]) == N:
    A = list(map(lambda y: y / 2, A))
    count += 1
print(count)
'''

'''
.append(要素)
.insert(場所,要素)
-1で末尾で末尾から一つ前
'''


num = int(stdin.readline().rstrip())
data = stdin.readline().rstrip().split()
res = ''
for el in range(1, num + 1):
    res += str(data.index(str(el)) + 1)
    if (el != num):
        res += ' '
print(res)


### FIXED CODE ###

from sys import stdin
from itertools import accumulate, dropwhile, takewhile, groupby

# 入力 =stdin.readline().rstrip()
# 分割 = stdin.readline().rstrip().split()

'''
条件に合うものを絞り込む
data = [1, 2, 3]
s = [x for x in data if x % 3 == 0]
'''

'''
文字配列を数値に
l_si = ['-10', '0', '100']

l_si_i = [int(s) for s in l_si]
'''

'''
a = [2, 4, 6, 8]
b = [3, 6, 9]

print(list(set(a) | set(b)))  # 和集合
print(list(set(a) & set(b)))  # 積集合
'''

'''
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
count = 0
while len([x for x in A if x % 2 == 0]) == N:
    A = list(map(lambda y: y / 2, A))
    count += 1
print(count)
'''

'''
.append(要素)
.insert(場所,要素)
-1で末尾で末尾から一つ前
'''


num = int(stdin.readline().rstrip())
data = stdin.readline().rstrip().split()
lis = [''] * num
res = ''
count = 1
for el in data:
    lis[int(el)-1] = str(count)
    count += 1
print(' '.join(lis))
### BUGGY CODE ###

def main():
    n,m = [int(v) for v in input().split()]
    if m==0:
        print(1)
        return
    groups = []
    g = [-1]*(n+1)
    for _ in range(m):
        a,b = [int(v) for v in input().split()]
        if g[a]!=-1 and g[b]!=-1:
            if g[a]==g[b]: continue
            gb = g[b]
            for no in groups[gb]:
                g[no] = g[a]
                groups[g[a]].append(no)
            groups[gb] = []
        elif g[a]!=-1:
            g[b] = g[a]
            groups[g[a]].append(b)
        elif g[b]!=-1:
            g[a] = g[b]
            groups[g[b]].append(a)
        else:
            g[a] = g[b] = len(groups)
            groups.append([a,b])
    # print(groups, g)
    ans = max([len(v) for v in groups])
    print(ans)

main()


### FIXED CODE ###

def main():
    n,m = [int(v) for v in input().split()]
    if m==0:
        print(1)
        return
    
    g = [set() for _ in range(n+1)]
    seen = [False] * (n+1)
    for _ in range(m):
        a,b = [int(v) for v in input().split()]
        g[a].add(b)
        g[b].add(a)

    ans = 0
    for i in range(1,n+1):
        if seen[i]: continue
        stack = set([i])
        l = 0
        while len(stack)>0:
            no = stack.pop()
            seen[no] = True
            l += 1
            for nn in g[no]:
                if not seen[nn]:
                    stack.add(nn)
        ans = max(ans, l)

    # print(groups, g)
    print(ans)

main()
### BUGGY CODE ###

h,w = map(int,input().split())
l = [[0] *w for i in range(h)]
r = [[0] *w for i in range(h)]
u = [[0] *h for i in range(w)]
d = [[0] *h for i in range(w)]
s = [str(input()) for i in range(h)]
for i in range(h):
  for j in range(w):
    if s[i][j] == ".":
      if j == 0:
        l[i][j] = 1
      else:
        l[i][j] = l[i][j-1] +1
    if s[i][-(j+1)] == ".":
      if j == 0:
        r[i][-(j+1)] = 1
      else:
        r[i][-(j+1)] = r[i][-j] +1
for i in range(w):
  for j in range(h):
    if s[j][i] == ".":
      if j == 0:
        u[i][j] = 1
      else:
        u[i][j] = u[i][j-1] +1
    if s[-(j+1)][i] == ".":
      if j == 0:
        d[i][-(j+1)] = 1
      else:
        d[i][-(j+1)] = d[i][-j] +1
ans = 0
for i in range(h):
  for j in range(w):
    ans = max(ans,l[i][j]+r[i][j]+u[j][i]+d[j][i]-3)
print(ans)

### FIXED CODE ###

h,w = map(int,input().split())
tate = [[0]*w for i in range(h)]
yoko = [[0]*w for i in range(h)]
s = [str(input()) for i in range(h)]

for i in range(h):
    cnt = 0
    now = 0
    for j in range(w):
        if s[i][j] == ".":
            cnt += 1
        else:
            for k in range(now,j+1):
                yoko[i][k] = cnt
            cnt = 0
            now = j+1
    for k in range(now,j+1):
        yoko[i][k] = cnt
for i in range(w):
    cnt = 0
    now = 0
    for j in range(h):
        if s[j][i] == ".":
            cnt += 1
        else:
            for k in range(now,j):
                tate[k][i] = cnt
            cnt = 0
            now = j+1
    for k in range(now,j+1):
        tate[k][i] = cnt
ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans,tate[i][j]+yoko[i][j]-1)
print(ans)
### BUGGY CODE ###

N = int(input())
nokori = N
kaburi = set()
ans = 0
A = list(map(int,input().rstrip().split(" ")))
A2 = set()
for i in A:
    if i in A2:
        kaburi.add(i)
    else:
        A2.add(i)
for i in kaburi:
    A2.remove(i)
for i in kaburi:
    k = i * 2
    while k < 1000000:
        A2.discard(k)
        k += i
while len(A2) != 0:
    i = min(A2)
    ans += 1
    k = i
    while k < 1000000:
        A2.discard(k)
        k += i
print(ans)

### FIXED CODE ###

N = int(input())
ans = 0
A = list(map(int,input().rstrip().split(" ")))
A.sort()
A2 = [True for i in range(A[-1] + 1)]
for i in range(len(A)):
    k = A[i] * 2
    if A2[A[i]]:
        if i != 0 and A[i-1] == A[i]:
            A2[A[i]] = False
        while(k < len(A2)):
            A2[k] = False
            k += A[i]
for i in A:
    if A2[i]:
        ans += 1
print(ans)
### BUGGY CODE ###

from copy import deepcopy

R, C, K = map(int, input().split())
rcv = [list(map(int, input().split())) for _ in range(K)]
N = (R + 1) * (C + 1)

d = [[] for _ in range(R + 1)]
for r, c, v in rcv:
    d[r].append([c, v])

for r in range(R + 1):
    d[r].sort()

dp = [0] * (C + 1)
for r, li in enumerate(d[1:], 1):
    prev = deepcopy(dp)
    for i, (cs, vs) in enumerate(li):
        mx = 0
        for cg, vg in li[i+1:]:
            val = vs + mx + vg
            dp[cg] = max(dp[cg], prev[cs] + val)
            mx = max(mx, vg)

        dp[cs] = max(dp[cs], prev[cs] + vs)

    for c in range(C):
        dp[c+1] = max(dp[c+1], dp[c])

ans = dp[C]
print(ans)


### FIXED CODE ###

R, C, K = map(int, input().split())
rcv = [list(map(int, input().split())) for _ in range(K)]

board = [[0] * (C + 1) for _ in range(R + 1)]
for r, c, v in rcv:
    board[r][c] = v

dp = [[[0] * (C + 1) for _ in range(R + 1)] for _ in range(4)]

for r in range(1, R + 1):
    for c in range(1, C + 1):
        v = board[r][c]
        for i in range(4):
            dp[0][r][c] = max(dp[0][r][c], dp[i][r-1][c])
            dp[1][r][c] = max(dp[1][r][c], dp[i][r-1][c] + v)

            dp[i][r][c] = max(dp[i][r][c], dp[i][r][c-1])
            if i > 0:
                dp[i][r][c] = max(dp[i][r][c], dp[i-1][r][c-1] + v)

ans = 0
for i in range(4):
    ans = max(ans, dp[i][R][C])

print(ans)
### BUGGY CODE ###

input()

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

count = 0
flag = True
while flag:
    flag = False
    for i, aa in enumerate(a):
        if aa % 2 == 0:
            a[i] = int(a[i] / 2)
            flag = True
            break
    if flag:
        count += 1
print(count)


### FIXED CODE ###

input()

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

count = 0
for i, aa in enumerate(a):
    while aa % 2 == 0:
        aa = int(aa / 2)
        count += 1
print(count)
### BUGGY CODE ###

r,g,b,n=map(int, input().split())

r_max=n//r
g_max=n//g

sum=0

for i in range((n//r)+1):
    for j in range((n-(i*r)//g)+1):
        if (n-(i*r)-(j*g))%b==0 and (n-(i*r)-(j*g))//b>=0:
            sum=sum+1
        #    print(i*r,j*g,(n-(i*r)-(j*g))%b)

print(sum)


### FIXED CODE ###

r,g,b,n=map(int, input().split())

sum=0

for i in range(n//r+1):
    for j in range((n-i*r)//g+1):
        if (n-i*r-j*g)%b==0:
            sum=sum+1
        #    print(i*r,j*g,(n-(i*r)-(j*g))%b)

print(sum)
### BUGGY CODE ###

# from sys import stdin
# S = stdin.readline().rstrip().split()
S = input()
S = list(S)
# print(S)
count_p = 0
count = 0

mark = 1
if len(S) <= 1:
    print(0)
    mark = 0
while mark:
    i = 0
    while i < len(S)-1:
        if S[i] == '0' and S[i+1] == '1':
            S[i] = '2'
            S[i+1] = '2'
            count += 2
            i += 2
        elif S[i] == '1' and S[i+1] == '0':
            S[i] = '2'
            S[i+1] = '2'
            count += 2
            i += 2
        else:
            i += 1
        # print(S)
    if count == count_p:
        print(count)
        break
    else:
        count_p = count
        A = []
        for i in range(len(S)):
            if S[i] != '2':
                A.append(S[i])
        S = A
        # print(S)
        # if len(S) == 2:
        #     if S[0] == '0'
        #      and (S == ['0', '1'] or ['1', '0']):
        #     count += 2
        #     print(count)
        #     break


### FIXED CODE ###

S = list(input())
a = 0
b = 0
for i in range(len(S)):
  if int(S[i]):
    a += 1
  else:
    b += 1
if a < b:
  print(a*2)
else:
  print(b*2)