peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Wrong Answer
from itertools import combinations
s = input()
d = {}
tmp = 0
i = 0
for char in s[::-1]:
    tmp += int(char) * pow(10, i, 2019)
    tmp %= 2019
    if tmp not in d:
        d[tmp] = 1
    else:
        d[tmp] += 1
    i += 1

result = 0
for num, v in d.items():
    if num == 0:
        result += v
        continue
    if v > 1:
        result += v * (v - 1) // 2

print(result)
# Judge status: Accepted
n, m = map(int, input().split())
a, b = [0]*n, [0]*n
c, d = [0]*m, [0]*m
for i in range(n):
    a[i], b[i] = map(int,input().split())
for i in range(m):
    c[i], d[i] = map(int,input().split())


for i in range(n):
    l = 10 ** 9
    for j in range(m):
        if abs(a[i] - c[j]) + abs(b[i] - d[j]) < l:
            l = abs(a[i] - c[j]) + abs(b[i] - d[j])
            idx = j + 1

    print(idx)
# Judge status: Wrong Answer
k,s = map(int,input().split())
start = s//3
ans = 0
if s < k:
    k = s

for i in range(start,k+1):
    for j in range(start,k+1):
        for l in range(start,k+1):
            if i+j+l == s:
                ans += 1
print(ans)
# Judge status: Accepted
n = int(input())
s = input()
t = input()

ans = n * 2
for i in range(n):
    if s[n - i - 1:] == t[:i + 1]:
        ans = min(ans, n * 2 - (i + 1))
print(ans)
# Judge status: Wrong Answer
N = int(input())
ans = 10**10
for i in range(1, N//2):
    a = sum(map(int, str(i)))
    b = sum(map(int, str(N-i)))
    ans = min(a+b, ans)
print(ans)
# Judge status: Accepted
a,b,c=map(int,raw_input().split())
if a+b>=c:
  print "Yes"
else:
  print "No"
# Judge status: Accepted
n = int(input())
l = list(map(int,input().split()))
if n%2==0:
  a = l[1::2][::-1]
  b = l[::2]
  for i in a:
    print(i,end=' ')
  for j in b:
    print(j,end=' ')
  
else:
  a = l[0::2][::-1]
  b = l[1::2]
  for i in a:
    print(i,end=' ')
  for j in b:
    print(j,end=' ')
# Judge status: Accepted
N = int(input())
a = N%26
next = int(N/26)
b = N%26
next = int(N/26)
a=[]
answer=[]
for i in range(20):
  if (N > 26) and (N%26)!=0:
    a.append(N%26)
    N = int(N/26)
  elif (N > 26) and (N%26)==0:
    a.append(26)
    N = int((N-1)/26)
  else:
    a.append(N)
    break
for i in range(len(a)):
  answer.append(chr(ord('a')+a[i]-1))
mojiretu = ' '
for x in reversed(answer):
    mojiretu += x
print(mojiretu)
# Judge status: Accepted
a, b, c = map(int, input().split())
L = [a, b, c]
L.sort()
ans = L[2]-L[1]
L[0] += ans
if L[0]%2 == L[2]%2:
    ans += (L[2]-L[0])//2
else:
    ans += 1
    ans += (L[2]+1-L[0])//2
print(ans)
# Judge status: Accepted
import sys
import math
def i():return int(sys.stdin.readline().replace("\n",""))
def i2():return map(int,sys.stdin.readline().replace("\n","").split())
def s():return str(sys.stdin.readline().replace("\n",""))
def l():return list(sys.stdin.readline().replace("\n",""))
def intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def lx():return list(map(lambda x:int(x)*-1,sys.stdin.readline().replace("\n","").split()))
def t():return tuple(map(int,sys.stdin.readline().replace("\n","").split()))

if __name__ == "__main__":pass

n = i()
a = [i for i in range(1,n+1)]
print(sum(a))
# Judge status: Accepted
def solve():
  ans = 0
  N = int(input())
  A = [int(input()) for _ in range(N)]
  rem = 0
  for i in range(N):
    ans += (A[i]+rem)//2
    if A[i]>0:
      rem = (A[i]+rem)%2
    else:
      rem = 0
  return ans
print(solve())
# Judge status: Wrong Answer
#from statistics import mean, median,variance,stdev
a,b,c=map(int, input().split())

x=min(a,b,c)
z=max(a,b,c)
if a==x and b==z:
  y=c
if a==x and c==z:
  y=b
if b==x and a==z:
  y=c
if b==x and c==z:
  y=a
if c==x and a==z:
  y=b
if c==x and b==z:
  y=a

print(0 if z%2==0 else a*b)
# Judge status: Accepted
n, k = map(int, input().split())
a = [0] + list(map(int, input().split()))

seen = [False] * (n+1)
visited = []
nxt = 1
cnt = 0
while not seen[nxt] and cnt != k:
    seen[nxt] = True
    visited.append(nxt)
    nxt = a[nxt]
    cnt += 1

if cnt == k:
    print(nxt)
    exit()
    
idx = visited.index(nxt)
print(visited[idx:][(k-idx)%(len(visited)-idx)])
# Judge status: Wrong Answer
import heapq
n, m = map(int, input().split())
lst = list(map(int, input().split()))
lst = list(map(lambda x: x*(-1), lst))
heapq.heapify(lst)

for i in range(m):
    tmp_min = heapq.heappop(lst)
    heapq.heappush(lst, tmp_min//2)  # 計算誤差の関係で-1を2回かけてます
print(-sum(lst))
# Judge status: Wrong Answer
a,b = map(int,input().split())

if a>0 and b>0:
    print('Positive')
elif a<0 and b>0 :
    print('Zero')
else:
    print('Negative')
# Judge status: Accepted
n = int(input())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
import itertools
i = 1
for ptn in itertools.permutations(range(1,n+1)):
    if list(ptn)==p:
      a = i
    if list(ptn)==q:
      b = i
    i += 1
print(abs(a-b))
# Judge status: Accepted
N=int(input())
s=input()
t=input()
ans=2*N
for i in range(N):
  A=s[:i]+t
  if A[:N]==s:
    ans=N+i
    break
print(ans)
# Judge status: Wrong Answer
def main():
    x=int(input())
    s=2*(x//11)
    t=x%11
    print(s if t<1 else s+1 if t<6 else s+2)
main()
# Judge status: Accepted
import sys
readline = sys.stdin.readline

N,M,K = map(int,readline().split())

for a in range(N + 1):
  for b in range(M + 1):
    if a * (M - b) + (N - a) * b == K:
      print("Yes")
      exit(0)
else:
  print("No")
# Judge status: Accepted
# -*- coding: utf-8 -*-
n=int(input())
slist=[]
for i in range(n):
  moji=str(input())
  slist.append(moji)
numdic={}
for chr in ["AC","WA","TLE","RE"]:
  numdic[chr]=slist.count(chr)
for chr,val in numdic.items():
  print(chr," x ",val)
# Judge status: Accepted
xs = input('').split(' ')

for i in range(5):
    x = int(xs[i])
    if x==0:
        print(i+1)
# Judge status: Accepted
N = int(input())

ans = 0

for i in range(1,N+1):
    s = N // i
    g = (s * (s+1)) // 2
    ans += g * i
print(ans)
# Judge status: Accepted
import sys
input = sys.stdin.readline

def main():
    h, w = map(int, input().split())

    if h == 1 or w == 1:
        print(1)
    else:
        print((h * w + 1) // 2)

main()
# Judge status: Accepted
s = input()

forward = s[:2]
backward = s[2:]
def check(s):
    if 0<int(s)<=12:
        return True
    else:
        return False

if check(forward) and check(backward):
    print('AMBIGUOUS')
elif check(forward):
    print('MMYY')
elif check(backward):
    print('YYMM')
else:
    print('NA')
# Judge status: Accepted
w, h, n = map(int, input().split())
coords = [list(map(int, input().split())) for _ in range(n)]

minx, maxx = 0, w
miny, maxy = 0, h

for x, y, a  in coords:
    if a == 1:
        minx = max(minx, x)
    elif a == 2:
        maxx = min(maxx, x)
    elif a == 3:
        miny = max(miny, y)
    elif a == 4:
        maxy = min(maxy, y)

if minx > maxx or miny > maxy:
    print(0)
else:
    print((maxx-minx)*(maxy-miny))
# Judge status: Accepted
x = int(input())
for i in range(1,1000000):
  if (i * x) % 360 == 0:
    print(i)
    exit()
# Judge status: Wrong Answer
import heapq  # heapqライブラリのimport
import sys
input = sys.stdin.readline
N,M=map(int,input().split())
lst=[]
for i in range(N):
 A,B=map(int,input().split())
 lst.append((A,-B))
heapq.heapify(lst)  # リストを優先度付きキューへ
ct=0
noko=1
ans=0
while  lst!=[]:
 c=heapq.heappop(lst) 
 if c[0]>M:
  break
 elif noko>0 or c[0]>ct:
  noko+=(-1+c[0]-ct)
  ct=c[0]
  ans+=c[1]
print(-ans)
# Judge status: Accepted
l=[int(input()) for i in range(5)]

diff=0
num=0
for i in l:
  if i%10==0:
    num+=i
  else:
    a=round(i+5,-1)
    num+=a
    diff=max(diff,a-i)

print(num-diff)
# Judge status: Wrong Answer
import numpy as np

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

array = np.zeros(n)

for i in range(m):
    a, b = map(int, input().split(' '))
    array[a-1] += 1
    array[b-1] += 1
    
for number in array:
    print(number)
# Judge status: Wrong Answer
S=list(set(input()))
S.sort()
import string
A=list(string.ascii_lowercase)
for i in range(len(S)):
    if not S[i]==A[i]:
        print(A[i])
        break
    else:
        print("None")
# Judge status: Accepted
def solve():
    X = int(input())
    n_500 = X // 500
    X -= n_500 * 500
    n_5 = X // 5
    
    print(n_500 * 1000 + n_5 * 5)

if __name__ == '__main__':
    solve()
# Judge status: Wrong Answer
N = int(input())
A = list(map(int,input().split()))
cnt = 0
cnt2 = 0
for i in A:
    for j in A:
        if i != j:
            if i%j == 0:
                cnt += 1
    if i != j:
        if cnt == 0:
            cnt2 += 1
    cnt = 0
print(cnt2)
# Judge status: Accepted
n,k = map(int,input().split())
s = list(input())

s[k-1] = s[k-1].lower()
print(''.join(s))
# Judge status: Wrong Answer
import numpy as np
A  = []
for i in range(3):
    A.append(list(map(int, input().split())))
A = np.array(A)

N = int(input())
B = []
for j in range(N):
    B.append(int(input()))

res = np.array([int(i in B) for i in A.ravel()]).reshape(3, 3)
diag_sum = res[0 ,0] + res[1, 1] + res[2, 2]
diag_sum2 = res[0, 2] + res[1, 1] + res[2, 0]
if res.sum(axis=0).any() or res.sum(axis=1).any() or diag_sum == 3 or diag_sum2 == 3:
    print('Yes')
else:
    print('No')
# Judge status: Accepted
N = int(input())
[T, A] = list(map(int, input().split()))
H = list(map(int, input().split()))
c = 0.006
H_tem = [T - c*H[_] for _ in range(N)]
min_ans = float("inf")

for i in range(len(H)):
  ans = abs(A - H_tem[i])
  if ans < min_ans:
    min_ans = ans
    point = i+1

print(point)
# Judge status: Accepted
s = int(input())
MOD = 10**9 + 7
C = [0]*(s + 1)
C[0] = 1
for n in range(3, s+1): # n:[3,s]
    C[n] = (C[n-1] + C[n-3]) % MOD
print(C[s])
# Judge status: Accepted
S = input()

a = S[:(len(S) - 1) // 2]
b = S[(len(S) - 1) // 2 + 1:]

if a == b and a == a[::-1]:
    print('Yes')
else:
    print('No')
# Judge status: Wrong Answer
A = int(input())
B = int(input())
c = [1,2,3]
c.remove(A)
c.remove(B)
print(c)
# Judge status: Wrong Answer
X,Y=map(int,input().split())
for i in range(2,Y):
  if X*i%Y!=0:
    print(X*i)
    exit()
print(-1)
# Judge status: Accepted
n = int(input())

if n >= 1000:
  print("ABD")
else:
  print("ABC")
# Judge status: Accepted
n=int(input())
a=list(map(int,input().split()))
s=[i for i in a if i%2==0]
t=[i for i in s if i%3>0 and i%5>0]
print('APPROVED' if len(t)==0 else 'DENIED')
# Judge status: Wrong Answer
import math


x, y = [int(w) for w in input().split()]

l = math.log2(y/x)
print(1 + int(l))
# Judge status: Accepted
k, s = [int(w) for w in input().split()]

ans = 0
for x in range(k+1):
    for y in range(k+1):
        if 0 <= s-x-y <= k:
            ans += 1

print(ans)
# Judge status: Accepted
a,b=map(int,input().split())
if a>=13:
  print(b)
elif 6<=a<13:
  print(b//2)
else:
  print(0)
# Judge status: Accepted
n = int(input())
while True:
    s = str(n)
    if s[0] == s[1] and s[0] == s[2]:
        print(n)
        break
    n += 1
# Judge status: Wrong Answer
list = list(map(int, input().split()))
if sum(list)<=22:
  print("bust")
else:
  print("win")
# Judge status: Accepted
from collections import defaultdict
N=int(input())
A=list(map(int,input().split()))
dic=defaultdict(int)
for i in range(0,N):
    dic[A[i]]+=1

ans=0
for key in dic.keys():
    if dic[key]>=key:
        ans+=dic[key]-key
    else:
        ans+=dic[key]

print(ans)
# Judge status: Wrong Answer
x , a ,b  = map(int,input().split())
X = abs(a - x)
Y = abs(b - x)
Z = max(Y,X)
if Z == X:
    print("A")
else:
    print("B")
# Judge status: Accepted
X,Y,Z=map(int,input().split())
a=X
X=Y
Y=a
c=X
X=Z
Z=c
print(X,Y,Z)
# Judge status: Accepted
import collections
S = input()
T = input()
scounter = collections.Counter(S)
tcounter = collections.Counter(T)
scounter_v = dict(scounter).values()
tcounter_v = dict(tcounter).values()
sdist = sorted([i for i in scounter_v])
tdist = sorted([i for i in tcounter_v])
if sdist == tdist:
  print("Yes")
else:
  print("No")
# Judge status: Wrong Answer
n = int(input())
for i in range(7):
  if n < 2 ** i:
    print(2**(i-1))
# Judge status: Accepted
a=list(map(str,input().split()))
print(a[1]+a[0])
# Judge status: Accepted
#!/usr/bin/env python3
import sys
input = sys.stdin.readline

n, k = map(int, input().split())
a = [int(item) - 1 for item in input().split()]
visited = [0] * n

v = 0
visited[0] = 1
pre = [0]
loop = []
start = False
while True:
    v = a[v]
    if visited[v] == 1:
        start = True
    if visited[v] == 2:
        break
    if not start:
        pre.append(v)
    else:
        loop.append(v)
    visited[v] += 1 

if k < len(pre):
    print(pre[k] + 1)
    exit()
k -= len(pre)
print(loop[k % len(loop)] + 1)
# Judge status: Accepted
x = input().split()
a = int(x[0])
b = int(x[1])
if a <= 9 and b <= 9:
  print(a * b)
else:
  print('-1')
# Judge status: Wrong Answer
X, Y = map(int, input().split())
MOD = 10 ** 9 + 7


S = -X + 2 * Y
T = 2 * X - Y

if S % 3 != 0 or T % 3 != 0:
    print(0)
    exit()

S //= 3
T //= 3


def cmb(n, r, p):
    r = min(n - r, r)
    if r == 0:
        return 1
    over = 1
    for i in range(n, n - r, -1):
        over = over * i % p
    under = 1
    for i in range(1, r + 1):
        under = under * i % p
    inv = pow(under, p - 2, p)
    return over * inv % p


ans = cmb(S + T, S, MOD) % MOD
print(ans % MOD)
# Judge status: Wrong Answer
n = int(input())
count=0
#p = [input() for i in range(n)]
p=list(map(int,input().split()))
for i in range(n-2):
    if (p[i-1]<p[i]<p[i+1]) or (p[i+2]>p[i+1]>p[i]):
        count+=1
print(count)
# Judge status: Accepted
a,b = map(int,input().split())
if (a+b) % 2 == 1:
    print("IMPOSSIBLE")
else:
    print((a+b)//2)
# Judge status: Wrong Answer
import sys

N = int(input())

W = []
for i in range(N):
    w = str(input())
    if w in W:
        print("No")
        sys.exit()
    if i != 0 and w[-1] != W[-1][-1]:
        print("No")
        sys.exit()
    W.append(w)

print("Yes")
# Judge status: Accepted
def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    sumA = sum(A)
    
    for i in range(N):
        res = B[i]
        if A[i] > 0 and res != 0:
            A[i], res = max(A[i] - res, 0), max(res - A[i], 0)

        if A[i+1] > 0 and res != 0:
            A[i+1], res = max(A[i+1] - res, 0), max(res - A[i+1], 0)
    
    print(sumA - sum(A))
    return

resolve()
# Judge status: Accepted
#ABC088-C
grid = [list(map(int,input().split())) for _ in range(3)]
flg = True
b1 = grid[0][0]
b2 = grid[0][1]
b3 = grid[0][2]
if grid[1][0] - b1 == grid[1][1] - b2 == grid[1][2] - b3:
    a2 = grid[1][0] - b1
else:
    flg = False
if grid[2][0] - b1 == grid[2][1] - b2 == grid[2][2] - b3:
    a3 = grid[2][0] - b1
else:
    flg = False
    
if flg:
    print('Yes')
else:
    print('No')
# Judge status: Accepted
N=int(input())
w=list(map(int, input().split()))
S=sum(w)
k=0
ans=10**7

for i in range(N-1):
    k+=w[i]
    if abs(S-2*k)<=ans:
        ans=abs(S-2*k)

print(ans)
# Judge status: Wrong Answer
N = int(input())

if N==1:
    print(1)
    quit()
if N % 2 == 0:
    print(N//2-1, N//2+1)

else:
    print(N//2, N//2+1)
# Judge status: Accepted
n, l = map(int, input().split())
apple = [i for i in range(l, l+n)]
total = sum(apple)

ans = float('inf')
ans2 = 0
for i in range(n):
    tmp = total - apple[i]
    if ans > abs(total - tmp):
        ans = abs(total - tmp)
        ans2 = tmp

print(ans2)
# Judge status: Accepted
n, a, b = map(int, input().split())

ans = 0
for i in range(1,n+1):
    w = sum(list(map(int, list(str(i)))))
    if a <= w and w <= b:
        ans += i
print(ans)
# Judge status: Accepted
N,L = map(int,input().split())
S = []
ans = ""

for i in range(N):
    S.append(input())

L = sorted(S)

for i in range(len(L)):
    ans = ans+L[i]

print(ans)
# Judge status: Wrong Answer
a,b = map(int,input().split())

if a == 2 or b == 2:
  print('No')
elif a == 1 or 3 or 5 or 7or 8or 10or 12:
  if b == 3 or 5 or 7or 8or 10or 12:
    print('Yes')
  else:
    print('No')
elif a == 4 or 6 or 9or 11:
  if b == 6 or 9 or 11:
    print('Yes')
  else:
    print('No')
# Judge status: Accepted
n = int(input())
a = list(map(int, input().split()))

xor = a[0] ^ a[1]
for i in range(2, n):
    xor ^= a[i]
    #print(bin(xor))
for i in range(n):
    print(xor ^ a[i], end=' ')
# Judge status: Wrong Answer
def resolve():
    a, b, m = map(int, input().split())
    a_list = sorted(list(map(int, input().split())))
    b_list = sorted(list(map(int, input().split())))
    min_total = min(a_list) + min(b_list)
    for _ in range(m):
        x, y, c = map(int, input().split())
        a_c = a_list[x-1]
        b_c = b_list[y-1]
        if min_total > a_c + b_c - c:
            min_total = a_c + b_c - c
    print(min_total)
resolve()
# Judge status: Accepted
import math
def at(n):
	return math.degrees(math.atan(n))

def main():
	a, b, x = [int(p) for p in input().split(" ")]
	V = a * a * b
	if x < V / 2:
		print(at(a * b * b / (2 * x)))
	else:
		print(at(2*(a*a*b-x)/a**3))

main()
# Judge status: Wrong Answer
d=[list(map(int,input().split()))for i in range(3)]
row=int(input())
num=[int(input()) for j in range(row)]
bingo=0
for a in range(3):
  if d[0][a] in num and d[1][a] in num and d[2][a] in num:
    bingo=bingo+1
  if d[a][0] in num and d[a][1] in num and d[a][2] in num:
    bingo=bingo+1
if d[1][1] in num and d[2][2] in num and d[0][0] in num:
  bingo=bingo+1
if d[0][1] in num and d[2][2] in num and d[1][0] in num:
  bingo=bingo+1
if bingo>0:
  print('Yes')
else:
  print('No')
# Judge status: Accepted
import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)

i_i = lambda: int(i_s())
i_l = lambda: list(map(int, stdin.readline().split()))
i_s = lambda: stdin.readline().rstrip()

A, B, C, X, Y = i_l()

if X < Y:
    X * C + (Y - X) * B
    print(min((X * A + Y * B), (X * C * 2 + (Y - X) * B), C * max(X, Y) * 2))
else:
    print(min((X * A + Y * B), (Y * C * 2 + (X - Y) * A), C * max(X, Y) * 2))
# Judge status: Accepted
n=int(input())
s=[100]*26
for i in range(n):
    a=[0]*26
    for j in list(input()):
        a[ord(j)-97]+=1
    for j in range(26):
        s[j]=min(s[j],a[j])
ans=''
for i in range(26):
    for j in range(s[i]):
        ans=ans+chr(i+97)
print(ans)
# Judge status: Accepted
N = int(input())
S = list(input())
ma=0
for i in range(N-1):
    ma=max(len(set(S[:i]) & set(S[i:])), ma)
print(ma)
# Judge status: Accepted
from collections import defaultdict
s = input()
cnt = defaultdict(int)
for i in range(len(s)):
    cnt[s[i]] += 1
mean = len(s) // 3
for t in ["a", "b", "c"]:
    if cnt[t] != mean and cnt[t] != mean + 1:
        print("NO")
        exit()

print("YES")
# Judge status: Accepted
x=int(input())
s=[list(map(int,list(input().split()))) for i in range(2)]
y=list(s)

for i in range(x-1):
	y[1][(x-2-i)]=y[1][(x-2-i)]+y[1][(x-1-i)]

y[0][(x-1)]=y[0][(x-1)]+y[1][(x-1)]

for i in range(x-1):
	if y[0][(x-i-1)]>=y[1][(x-i-2)]:
		y[0][(x-i-2)]=y[0][(x-i-2)]+y[0][(x-i-1)]
	else:
		y[0][(x-i-2)]=y[0][(x-i-2)]+y[1][(x-i-2)]
print(y[0][0])
# Judge status: Wrong Answer
s=input()
print('YES' if len(s)>=7 and s[:3]=='key' and s[-4:]=='ence' else 'NO')
# Judge status: Accepted
x = int(input())

s = 0

t = 1
while True:
    s += t
    if s >= x:
        break
    
    t += 1
    
print(t)
# Judge status: Accepted
from collections import deque
s = deque(i for i in input())
n = int(input())
l = [[i for i in input().split()] for _ in range(n)]

front = True

for i in l:
    if i[0] == '1':
        front = not front
    else:
        if front ^ (int(i[1]) == 1):
            s.append(i[2])
        else:
            s.appendleft(i[2])
            
ans = ''.join(s)

if front:
    print(ans)
else:
    ans = ans[::-1]
    print(ans)
# Judge status: Accepted
from collections import deque


N, C, K = map(int, input().split())
T = [int(input()) for _ in range(N)]
T.sort()
d = deque(T)
count = 0
while len(d) > 0:
    t = d.popleft() + K
    for i in range(C-1):
        if len(d) > 0 and d[0] <= t:
            d.popleft()
        else:
            break
    count += 1

print(count)
# Judge status: Wrong Answer
n = int(input())
t, a = map(int, input().split())
h = list(map(int, input().split()))
ans = -1
nearest = 10**18
for i in range(n):
    target = abs(t - h[i] * 0.006)
    if abs(a - nearest) > abs(a - target):
        nearest = target
        ans = i + 1
print(ans)
# Judge status: Wrong Answer
s=int(input())
a=[0]*1000000
for i in range(1000000):
    if s%2==1:
        s=s*3+1
    else:
        s=s/2

    if s in a:
        print(i+2)
        break
    a[i]=s
# Judge status: Wrong Answer
N=int(input())
ABC=[]
for i in range(N):
	ABC+=[[int(i) for i in input().split()]]
DP=[[0,0,0] for i in range(N)]
for i in range(1,N):
	for j in range(3):
		DP[i][j]=ABC[i][j]+max(DP[i-1][(j+1)%3],DP[i-1][(j+2)%3])
print(max(DP[-1]))
# Judge status: Accepted
import sys
input = sys.stdin.readline
import heapq

def readlines(n):
    for _ in range(n):
        a, b = map(int, input().split())
        yield a, b

def main():
    n, k = map(int, input().split())
    ary = []
    heapq.heapify(ary)
    for a, b in readlines(n):
        heapq.heappush(ary, (a, b))

    while True:
        a, b = heapq.heappop(ary)
        k -= b
        if k <= 0:
            print(a)
            return

main()
# Judge status: Accepted
S = input()
if S[0] != S[1] or S[1] != S[2]:
    print('Yes')
else:
    print('No')
# Judge status: Accepted
import decimal

A, B = map(decimal.Decimal, input().split())
ans = A * B
print(int(ans))
# Judge status: Wrong Answer
n=int(input())
cs=[list(map(int,input().split())) for _ in range(n-1)]
for i in range(n-1):
    t=0
    for c,s,f in cs[i:]:
        t=max(t,s)
        if t%f:
            t=t-t%f
        t+=c
    print(t)

print(0)
# Judge status: Wrong Answer
def main():
    n, m, k = map(int,input().split())
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    C = []
    for x in range(n):
        sumA = int(sum(A[0:x]))
        for y in range(m):
            sumB = int(sum(B[0:y]))
            if sumA + sumB < k:
                C.append(x+y)
    print(max(C))
main()
# Judge status: Accepted
h = int(input())
w = int(input())
n = int(input())

if (h>w) :
  rep=h
else :
  rep=w

i=0
while rep * i < n:
  i+=1

print(i)
# Judge status: Accepted
s = input()


def check(w):
    if w[0] != 'A':
        return False
    n = len(w)
    count = 0
    for a in range(2, n-1):
        if w[a] == 'C':
            count += 1
    if count != 1:
        return False
    upper = 0
    for a in range(0, n):
        if w[a] >= 'A' and w[a] <= 'Z':
            upper += 1

    if upper != 2:
        return False
    return True


if check(s):
    print('AC')
else:
    print('WA')
# Judge status: Wrong Answer
X = list(map(int,input().split()))

N = X[0]
b = X[1]
r = X[2]

if b == 0:
    print(0)
elif r == 0:
    print(N)
elif b + r == N:
    print(b)
else:
    b_count = 0
    Line = 0
    while Line <= N:
        Line += b
        b_count += b
        Line += r
        
    
    print(b_count)
# Judge status: Accepted
a, b, _, k = map(int, input().split())
print(b - a if k & 1 else a - b)
# Judge status: Accepted
s = input()
t = input()
cnt_max = 0
for i in range(len(s)-len(t)+1):
    cnt = 0
    for j in range(len(t)):
        if s[i+j] == t[j]:
            cnt += 1
    if cnt > cnt_max:
        cnt_max = cnt
print(len(t)-cnt_max)
# Judge status: Accepted
n, m = map(int,input().split())
h = list(map(int,input().split()))
c = [[] for _ in range(n)]
for i in range(m):
    a, b = map(int,input().split())
    c[a-1].append(h[b-1])
    c[b-1].append(h[a-1])

cnt = 0
for i, a in enumerate(c):
    if a:
        a.sort(reverse=True)
        if a[0] < h[i]:
            cnt += 1
    else:
        cnt += 1
print(cnt)
# Judge status: Accepted
import string
N = int(input())
S = list(input())

al = list(string.ascii_uppercase)
ans = []
for i in S:
    pos = al.index(i) + N
    if pos < 26:
        ans.append(al[pos])
    else:
        ans.append(al[pos-26])
print(''.join(ans))
# Judge status: Accepted
s = input()
t = input()
n = len(s)
if s == t[:n]:
    print('Yes')
else:
    print('No')
# Judge status: Accepted
import sys
def input(): return sys.stdin.readline().strip()


def main():
    S = input()
    ans = set()
    for c in S: ans.add(c)
    if ans == {'a', 'b', 'c'}:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()