Harryxun/stf_run huggingface dataset:
from itertools import product

A, B, C, D = list(map(int, input()))

for pattern in product('+-', repeat=3):
    f = '{}{}{}{}{}{}{}'.format(A, pattern[0], B, pattern[1], C, pattern[2], D)    if eval(f) == 7:
        print(f+'=7') 
        break

### FIXED CODE ###

from itertools import product

A, B, C, D = list(map(int, input()))

for pattern in product('+-', '+-', '+-'):
    f = '{}{}{}{}{}{}{}'.format(A, pattern[0], B, pattern[1], C, pattern[2], D)

    if eval(f) == 7:
        print(f+'=7')
        break
i=lambda:int(input())
print((i()+i()+1)//2)

### FIXED CODE ###

a,b=map(int,input().split(" "))
print((a+b+1)//2)
n,m = map(int,input().split())
if n == m:
  print(AC)
else:
  print(WA)

### FIXED CODE ###

n,m = map(int,input().split())
if n == m:
  print('Yes')
else:
  print('No')
if [A,B,C]=[5,5,7]or[5,7,5]or[7,5,5]:
   print(YES)
   else:print(NO)

### FIXED CODE ###

a = list(map(int,input().split()))
a.sort()
if a[0] == a[1] == 5 and a[2] == 7:
    print("YES")
else:
    print("NO")
N = int(input())
a = 0

for i in range (1,N+1):
    if i % 3 == 0 and i % 5 == 0:
        a = 'FizzBuzz'
    elif i % 3 == 0:
        a = 'Fizz'
    elif i % 5 == 0:
        a = 'Buzz'
    else:
         a = a + i



### FIXED CODE ###

total = []

N = int(input())

for i in range(1, N + 1):
    if i % 3 == 0 and i % 5 == 0:
        pass
    elif i % 3 == 0:
        pass
    elif i % 5 == 0:
        pass
    else:
        total.append(i)

print(sum(total))
import math as math

N = int(input())
A = list(map(int, input().split()))
ANS = [0]*len(A)
for i in range(math.ceil(N/2)+1,N):
    ANS[i] = A[i]

fnum=math.ceil(N/2)
for i in range(fnum,-1,-1):
    j = i + 1
    tsum=A[i]
    for k in range(j,N+1,j):
        tsum+=ANS[k-1]
    ANS[i]=tsum%2

#print(ANS)
anslist=[]
for i in range(N):
    if ANS[i]==1:
        anslist.append(i+1)
 
print(len(anslist))
for s in anslist:
    print(s, end =" ")



### FIXED CODE ###

import math as math

N = int(input())
A = list(map(int, input().split()))
ANS = [0]*len(A)
for i in range(math.floor(N/2)+1,N):
    ANS[i] = A[i]

fnum=math.floor(N/2)
for i in range(fnum,-1,-1):
    j = i + 1
    tsum=A[i]
    for k in range(j,N+1,j):
        tsum+=ANS[k-1]
    ANS[i]=tsum%2

#print(ANS)
anslist=[]
for i in range(N):
    if ANS[i]==1:
        anslist.append(i+1)
 
print(len(anslist))
for s in anslist:
    print(s, end =" ")
H,N=map(int, input().split())
import math



MAX=10**4+1
def solve(r,idx):
  if idx==N:
    return MAX
  if r%A[idx][1]==0:
    return (r//A[idx][1])*A[idx][2]
  else:
    return min((r//A[idx][1]+1)*A[idx][2],(r//A[idx][1])*A[idx][2]+solve(r%A[idx][1],idx+1))


A=[]
B=[]
for i in range(N):
  a,b=map(int, input().split())
  A.append([a/b,a,b])
if N==1:
  if H%A[0][1]==0:
  	print((H//A[0][1])*A[0][2])
  else:
 	print((H//A[0][1]+1)*A[0][2])
  return
A=sorted(A)[::-1]

if H%A[0][1]==0:
  print((H//A[0][1])*A[0][2])
else:
  ans=min((H//A[0][1]+1)*A[0][2],(H//A[0][1])*A[0][2]+solve(H%A[0][1],1))
  print(ans)


### FIXED CODE ###

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

dp=[10**10]*(H+1)
dp[0]=0
for n in range(N):
  a,b=map(int, input().split())
  A.append(a)
  B.append(b)
    
for h in range(1,H+1):
  for n in range(N):
    if h-A[n]>=0:
      dp[h]=min(dp[h],dp[h-A[n]]+B[n])
    else:
      dp[h]=min(dp[h],B[n])
print(dp[H])
N,M = map(int,input().split())

A = ""
B = ""

for i in range(N):
	A += input()



for i in range(M):
	if i % 2 == 0:
		B += input()
	else:
		B += input()[::-1]

if B in A:
	print("Yes")
else:
	print("No")

### FIXED CODE ###



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

if A == 1 and B != 1:
	print('Alice')
	exit()

if B == 1 and A != 1 :
	print('Bob')
	exit()
if A > B:
	print('Alice')
	exit()
	
if B > A:
	print('Bob')
	exit()

if A == B:
	print('Draw')
	exit()
a, b = map(int.input().split())

answer = a * b

if answer % == 0:
    print('Even')
else:
    print('Odd')

### FIXED CODE ###

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

answer = a * b

if answer % 2 == 0:
    print('Even')
else:
    print('Odd')
# -*- coding: utf-8 -*-
import copy

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

L=[ [] for _ in range(H) ]
ng=[]

cnt=0
ichigo=False
for h in range(H):
    cnt+=1
    ichigo=False
    for w in range(W):
        if S[h][w]=="#":
            if ichigo:
                cnt+=1      ##該当行でイチゴの出現が2回目以降の時は、カウントを増やす
            else:
                ichigo=True #該当行でイチゴの出現が1回目の時はTrueを入れる
        L[h].append(cnt)
    else:
        if ichigo is False:
            ng.append(h) #イチゴが１つも入ってない行番号



def func(n,str):   #行番号 方向 u:up d:down
    #print "func(",n,",",str,")"
    if n in ng:
        if 0<=n-1: func(n-1,"u")
        if n+1<=H-1: func(n+1,"d")
    else:      #NG行でない場合
        if str=="u":
            L[n+1]=copy.deepcopy(L[n])
        elif str=="d":
            L[n-1]=copy.deepcopy(L[n])

#1行にイチゴが1つもない行に対して、前or後の行をコピーする処理
for x in ng:
    func(x,"u")
    func(x,"d")


#1,2,3...Kの順で再度ピースの番号を振り直す
D={}    #前のピース番号：後のピース番号のマッピング辞書配列

cnt=1
for h in range(H):
    for w,x in enumerate(L[h]):
        if x not in D:  #辞書内になかった場合は、辞書に登録してカウンターの数字を+1する
            D[x]=cnt
            L[h][w]=cnt
            cnt+=1
        else:
            L[h][w]=D[x]  #辞書内にあった場合は、その値を使用


for h in range(H):
    for x in L[h]:
        print x,
    print

### FIXED CODE ###

# -*- coding: utf-8 -*-
import sys
from collections import deque,defaultdict
sys.setrecursionlimit(10**5)

H,W,K=map(int, sys.stdin.readline().split())
ichigo=[]
cnt=0
h_visit=[0 for h in range(H)]  #縦軸にイチゴがない箇所は0、ある箇所は1

L=[ [] for h in range(H) ]
for h in range(H):
    s=sys.stdin.readline().strip()
    for w,x in enumerate(s):
        if x==".":
            L[h].append(0)
        elif x=="#":
            cnt+=1
            L[h].append(cnt)
            ichigo.append((h,w))
            h_visit[h]=1


D=(1,-1)

def yoko_dfs(h,w):  #縦座標、横座標
    for dw in D:
        if 0<=w+dw<=W-1 and L[h][w+dw]==0:
            L[h][w+dw]=L[h][w]
            yoko_dfs(h,w+dw)
    return

for h,w in ichigo:
    yoko_dfs(h,w)


def tate_dfs(h):  #縦座標
    for dh in D:
        if 0<=h+dh<=H-1:
            if h_visit[h+dh]==1: continue
            h_visit[h+dh]=1 #訪問済みにする
            L[h+dh]=L[h]
            tate_dfs(h+dh)

for h,w in ichigo:
    tate_dfs(h)

for l in L:
    for x in l:
        print x,
    print
import sys
from collections import Counter

sys.stdin = open('a1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


def main():
    n = read_int_list()
    c = Counter(n)
    for i in c:
        if c[i] == 1:
            res = i
            print(res)


main()


### FIXED CODE ###

import sys
from collections import Counter

# sys.stdin = open('a1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


def main():
    n = read_int_list()
    c = Counter(n)
    for i in c:
        if c[i] == 1:
            print(i)


main()
import sys
def main():
  input = sys.stdin.readline
  h, w = map(int, input().split())
  A = []
  AB = []
  A_append = A.append
  AB_append = AB.append
  for i in range(h):
    row = list(map(int, input().split()))
    A_append(row)
  for i in range(h):
    row = [abs(A[i][j] - int(b)) for j, b in enumerate(input().split())]
    AB_append(row)
 
  dp = [[set([]) for j in range(w+1)] for i in range(h+1)]
  dp[0][0].add(AB[0][0])
  for i in range(h):
    for j in range(w):
      dif1 = 0
      dif2 = 0
      if j < w - 1:
        add1 = dp[i][j+1].add
        dif1 = AB[i][j+1]
      if i < h - 1:
        add2 = dp[j+1][i].add
        dif2 = AB[i+1][j]
      for item in dp[i][j]:
        if j < w - 1:
          add1(item+dif1)
          add1(abs(item-dif1))
        if i < h - 1:
          add2(item+dif2)
          add2(abs(item-dif2))
  print(min(dp[h-1][w-1]))
if __name__ == '__main__':
  main()


### FIXED CODE ###

import sys
def main():
  input = sys.stdin.readline
  h, w = map(int, input().split())
  A = []
  AB = []
  A_append = A.append
  AB_append = AB.append
  for i in range(h):
    row = list(map(int, input().split()))
    A_append(row)
  for i in range(h):
    row = [abs(A[i][j] - int(b)) for j, b in enumerate(input().split())]
    AB_append(row)
 
  dp_cur = [set([]) for _ in range(w)]
  dp_cur[0].add(AB[0][0])
  for i in range(h):
    dp_next = [set([]) for _ in range(w)]
    for j in range(w):
      if j < w - 1:
        add1 = dp_cur[j+1].add
        dif1 = AB[i][j+1]
      if i < h - 1:
        add2 = dp_next[j].add
        dif2 = AB[i+1][j]
      for item in dp_cur[j]:
        if j < w - 1:
          add1(item+dif1)
          add1(abs(item-dif1))
        if i < h - 1:
          add2(item+dif2)
          add2(abs(item-dif2))
    if i == h - 1:
      break
    dp_cur = dp_next
  print(min(dp_cur[w-1]))
if __name__ == '__main__':
  main()
a=[0]*9;input()
for x in list(map(int,input().split())):
    if x<3200:a[x//400]=1
    else:a[x//400]+=1
b=sum(a[:8]);print((b,b)*(b==8)or b,b+a[8])

### FIXED CODE ###

input();a=[0]*9
for x in input().split():
    x=int(x)
    if x>3599:x=3200
    a[x//400]+=1
b=sum([1 if x else 0 for x in a[:8]])
print(max(1,b),b+a[8])
N ,K = map(int, input().split())

S = str(input())

S = S[:K-1] + S[K].swapcase() + S[K+1:]

print(S)


### FIXED CODE ###

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

S = str(input())

S = S[:K-1] + (S[K-1]).lower() + S[K:]

print(S)
n = int(input())
ss = [[int(i) for i in input().split()] for i in range(n)]

flg = True


def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]


for s in ss:
    x = s[0]
    y = s[1]
    h = s[2]
    if x == y == 0:
        print(x, y, h)
        flg = False

ans = []
if flg:
    for i in range(len(ss)-1):

        temp = [] if i == 0 else get_unique_list(ans)
        ans = []

        x1 = ss[i][0]
        y1 = ss[i][1]
        h1 = ss[i][2]
        x2 = ss[i+1][0]
        y2 = ss[i+1][1]
        h2 = ss[i+1][2]

        for a in range(101):
            for b in range(101):
                left = h1 + abs(x1-a) + abs(y1 - b)
                right = h2 + abs(x2-a) + abs(y2 - b)
                if left == right and left > 0 and right > 0:
                    if i == 0:  # 1回目のループ
                        ans.append([a, b])
                    elif [a, b] in temp:  # 2回目移行
                        ans.append([a, b])

    h = ss[0][2] + abs(ss[0][0] - ans[0][0]) + abs(ss[0][1] - ans[0][1])
    print(ans[0][0], ans[0][1], h)


### FIXED CODE ###

n = int(input())
ss = [[int(i) for i in input().split()] for i in range(n)]

ss = sorted(ss, key=lambda x: x[2], reverse=True)


cx, cy, ch = ss[0]
if len(ss) == 1:
    print(cx, cy, ch)
else:
    for a in range(101):
        for b in range(101):
            H = ch + abs(cx-a) + abs(cy - b)
            for x, y, h in ss[1:]:
                if h != max(H - abs(x-a) - abs(y - b), 0):
                    break
            else:
                print(a, b, H)
                flg = True
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = []
d = []
co = 0
for i in range(a[0]):
	c.append(abs(b[i]-a[1]))
	if b[i]-a[1] > 0 and co == 0:
		c.insert(i,0)
		co += 1

for i in range(len(c)-1):
	d.append(abs(c[i+1]-c[i]))
	if d[-1] == 0:
		d.pop()
d.sort()
for i in range(len(d)-1):
	if d[i] % d[0] != 0:
		d[0] = 1
		break
print(d[0])

### FIXED CODE ###

import functools
import fractions
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = []
d = []
co = 0
for i in range(a[0]):
	c.append(abs(b[i]-a[1]))
	if b[i]-a[1] > 0 and co == 0:
		c.insert(i,0)
		co += 1
if co == 0:
	c.append(0)

for i in range(len(c)-1):
	d.append(abs(c[i+1]-c[i]))
print(functools.reduce(fractions.gcd, d))
#!/usr/bin/env python

a,b,c=int(raw_input().split())

if c-b==b-a:
    print 'YES'
else:
    print 'NO'

### FIXED CODE ###

#!/usr/bin/env python

a,b,c=map(int,raw_input().split())

if c-b==b-a:
    print 'YES'
else:
    print 'NO'
N,M = (int(x) for x in input().split())
a = [0]*N  
k = []
ans = 0
for i in range(M):
  k = [int(x) for x in input().split()]
  for j in range(k[0]): #kよりつながっている電球を一個ずつ見てる
    s = k[j+1]-1
#    print(i,j,s,a[s],a)
    a[s] = a[s] | (1<<i) #aは各スイッチがつながっている電球の情報を保持
#   左端はMとつながっているかどうかを表す。
    #a[0]＝10100はスイッチ０が電球4と電球2とつながっていることを表している。
p = [int(x) for x in input().split()]
P = 0
for i in range(M):
  P |= p[i] << i　
  #Pはpの情報を全て持っている二進数。例えば、P＝10011は電球４、１、０が
  # on になっているスイッチの個数を2で割った余りが１の時点灯するを表す
  #左端がMは統一されている
for s in range(1<<N):　　#1<<N は2**nと同じ
  t = 0
  for i in range(N):
    if ((s>>i) & 1):　#スイッチオンだったら
      t ^= a[i]		
      #これはXORを使って、スイッチがonになっているスイッチの個数を２で割ったあまりを表している
  if (t == P):	#もし、t＝＝Pなら、当てはまっているので、ans++する。
    ans += 1
print(ans)

### FIXED CODE ###

N,M = (int(x) for x in input().split())
a = [0]*N  
k = []
ans = 0
for i in range(M):
  k = [int(x) for x in input().split()]
  for j in range(k[0]): #kよりつながっている電球を一個ずつ見てる
    s = k[j+1]-1
#    print(i,j,s,a[s],a)
    a[s] = a[s] | (1<<i)
#   print(i,j,s,a[s],a)
    #二進数でi桁目が１のとき、スイッチsとi番目の電球がつながっている?
p = [int(x) for x in input().split()]
P = 0
for i in range(M):
  P |= p[i] << i
for s in range(1<<N):
  t = 0
  for i in range(N):
    if ((s>>i) & 1):
      t ^= a[i]
  if (t == P):
    ans += 1
print(ans)
N=input()

def calc(str):
    l=list(map(int,str))
    all=sum(l)
    
    return all

cand1=str(int(N)-int(N[-1])-1)
cand2=str(int(N[0])*10**(len(N)-1)-1)
print(max(calc(cand1),calc(cand2)))

### FIXED CODE ###

N=input()

if len(N)==1:
    print(N)
    exit()

def calc(str):
    l=list(map(int,str))
    all=sum(l)
    
    return all

cand1=str(int(N)-int(N[-1])-1)
cand2=str(int(N[0])*10**(len(N)-1)-1)

print(max(calc(cand1),calc(cand2),calc(N)))
while True :
    (x,y) = int(i) for i in input().split()
    if 0 = x and 0 = y:
        break
    else if x <= y:
        print(x,y)
    else :
        peint(y,x)

### FIXED CODE ###

while True:
    (x, y) = [int(i) for i in input().split()]
    
    if x == y == 0 :
        break

    if x <= y :
        print(x, y)
    else :
        print(y, x)
n, k = map(int, input().split())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7

plus = []
minus = []
for i in a:
    if i > 0: plus.append(i)
    if i < 0: minus.append(i)

ans = 1
if k > len(plus) + len(minus):
    ans = 0
elif len(minus) == 0:
    plus.sort(reverse=True)
    for i in range(k):
        ans = (ans * plus[i]) % mod
elif len(plus) == 0:
    if k % 2 == 0:
        minus.sort()
        for i in range(k):
            ans = (ans * minus[i]) % mod
    else:
        minus.sort(reverse=True)
        for i in range(k):
            ans = (ans * minus[i]) % mod
elif k - len(plus) > 0 and (k - len(plus)) % 2 == 1:
    plus.sort(reverse=True)
    minus.sort()
    ans = minus[0]
    i, j = 0, 1
    while i + j < k:
        tmp_p = plus[i] * plus[i + 1] if i <= len(plus) - 2 else float('inf')
        tmp_m = minus[j] * minus[j + 1] if i <= len(minus) - 2 else float('inf')
        if tmp_p <= tmp_m:
            ans = (ans * (tmp_p % mod)) % mod
            i += 2
        else:
            ans = (ans * (tmp_m % mod)) % mod
            j += 2
else:
    plus.sort()
    minus.sort(reverse=True)
    i, j = 0, 0
    while i + j < k:
        tmp_p = plus[i] * plus[i + 1] if i <= len(plus) - 2 else 0
        tmp_m = minus[j] * minus[j + 1] if j <= len(plus) - 2 else 0
        if tmp_p >= tmp_m:
            ans = (ans * plus[i]) % mod
            i += 1
        else:
            ans = (ans * (tmp_m % mod)) % mod
            j += 2
print(ans)


### FIXED CODE ###

n, k = map(int, input().split())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7

plus = []
minus = []
for i in a:
    if i > 0: plus.append(i)
    if i < 0: minus.append(i)

ans = 1
if k > len(plus) + len(minus):
    ans = 0
elif len(minus) == 0:
    plus.sort(reverse=True)
    for i in range(k):
        ans = (ans * plus[i]) % mod
elif len(plus) == 0:
    if k % 2 == 0:
        minus.sort()
        for i in range(k):
            ans = (ans * minus[i]) % mod
    else:
        if n != len(minus):
            ans = 0
        else:
            minus.sort(reverse=True)
            for i in range(k):
                ans = (ans * minus[i]) % mod
elif k == len(plus) + len(minus) and (len(minus) % 2) == 1:
    if n != k:
        ans = 0
    else:
        for x in plus:
            ans = (ans * x) % mod
        for y in minus:
            ans = (ans * y) % mod
else:
    plus.sort(reverse=True)
    minus.sort()
    i, j = 0, 0
    if k % 2 == 1:
        ans = plus[0]
        i = 1
    while i + j < k:
        tmp_p = plus[i] * plus[i + 1] if i <= len(plus) - 2 else 1
        tmp_m = minus[j] * minus[j + 1] if j <= len(minus) - 2 else 1
        if tmp_p >= tmp_m:
            ans = (ans * (tmp_p % mod)) % mod
            i += 2
        else:
            ans = (ans * (tmp_m % mod)) % mod
            j += 2
print(ans)
import math
n,m = map(int,input().split())
a = list(map(lambda x: -int(x),input().split()))
heapq.heapify(a)
for i in range(m):
    a_max = heapq.heappop(a)
    heapq.heappush(a,-(-a_max//2))
print(-sum(a))

### FIXED CODE ###

import math
import heapq
n,m = map(int,input().split())
a = list(map(lambda x: -int(x),input().split()))
heapq.heapify(a)
for i in range(m):
    a_max = heapq.heappop(a)
    heapq.heappush(a,-(-a_max//2))
print(-sum(a))
from sysimport stdin

input_list = []
for line in stdin:
  input_list.append(line.rstrip('\n'))

if input_list[0] == input_list[1][:len(input_list[0])]:
  print('Yes')
else:
  print('No)

### FIXED CODE ###

from sys import stdin
 
input_list = []
for line in stdin:
  input_list.append(line.rstrip('\n'))
 
if input_list[0] == input_list[1][:len(input_list[0])]:
  print('Yes')
else:
  print('No')
n=int(input())
temp=list(map(int,input().rstrip().split()))
a=temp[0]
b=temp[2]
if (b-a)>n :
    print("Yes")
else :
    print("No")

### FIXED CODE ###

n=int(input())
temp=list(map(int,input().rstrip().split()))
a=temp[0]
b=temp[1]
rem=(a%n)
left=n-rem
if b>=(left+a) :
    print("OK")
elif a%n ==0 or b%n==0:
    print("OK")
else :
    print("NG")
def resolve():
    import numpy as np
    h, w = map(int, input().split())
    s = [input() for _ in range(h)]
    hs = [[0]*w for _ in range(h)]
    ws = [[0]*w for _ in range(h)]

    for i in range(h):
        cums = 0
        for j in range(w):
            if s[i][j] == "#":
                cums = 0
                ws[i][j] = 0
            else:
                cums += 1
                ws[i][j] = cums
        for j in reversed(range(w-1)):
            if ws[i][j+1] != 0 and ws[i][j] != 0:
                ws[i][j] = ws[i][j+1]

    for i in range(w):
        cums = 0
        for j in range(h):
            if s[j][i] == "#":
                cums = 0
                hs[j][i] = 0
            else:
                cums += 1
                hs[j][i] = cums
        for j in reversed(range(h-1)):
            if hs[j+1][i] != 0 and hs[j][i] != 0:
                hs[j][i] = hs[j+1][i]

    ans = 0
    for i in range(h):
        for j in range(w):
            ans = max(ans, ws[i][j] + hs[i][j])
    print(ans-1)
resolve()

### FIXED CODE ###

def resolve():
    h, w = map(int, input().split())
    s = [input() for _ in range(h)]
    hs = [[0]*w for _ in range(h)]
    ws = [[0]*w for _ in range(h)]

    for i in range(h):
        cums = 0
        for j in range(w):
            if s[i][j] == "#":
                cums = 0
                ws[i][j] = 0
            else:
                cums += 1
                ws[i][j] = cums
        for j in reversed(range(w-1)):
            if ws[i][j+1] != 0 and ws[i][j] != 0:
                ws[i][j] = ws[i][j+1]

    for i in range(w):
        cums = 0
        for j in range(h):
            if s[j][i] == "#":
                cums = 0
                hs[j][i] = 0
            else:
                cums += 1
                hs[j][i] = cums
        for j in reversed(range(h-1)):
            if hs[j+1][i] != 0 and hs[j][i] != 0:
                hs[j][i] = hs[j+1][i]

    ans = 0
    for i in range(h):
        for j in range(w):
            ans = max(ans, ws[i][j] + hs[i][j])
    print(ans-1)
resolve()
# ABC 079 D


class WarshallFloyd(object):

    def __init__(self, adj):
        """
        ワーシャル・フロイド法によって全頂点間の最短距離を O(|V|^3) で計算する。

        :param adj: 隣接行列 adj[i][j] でi番目の頂点からj番目の頂点へのコストを示す パスがなければINF
        """
        self._dist = adj  # 各頂点間の最短距離 初期値として隣接行列をそのまま用い、[i, i]要素を0に初期化する
        for i in range(len(adj)):
            self._dist[i][i] = 0

        self._solve()

    def _solve(self):
        v_len = len(self._adj)
        for i in range(v_len):  # 経由する頂点
            for j in range(v_len):  # 開始頂点
                for k in range(v_len):  # 終端
                    self._dist[j][k] = min(self._dist[j][k], self._dist[j][i] + self._dist[i][k])

    def distance(self, start, goal):
        return self._dist[start][goal]

    def path(self, start, goal):
        pass


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

wf = WarshallFloyd(C)

cost = 0
for ln in A:
    for a in ln:
        if a == -1:
            continue
        cost += wf.distance(a, 1)
print(cost)

### FIXED CODE ###

class WarshallFloyd(object):

    def __init__(self, adj):
        """
        ワーシャル・フロイド法によって全頂点間の最短距離を O(|V|^3) で計算する。

        :param adj: 隣接行列 adj[i][j] でi番目の頂点からj番目の頂点へのコストを示す パスがなければINF
        """
        self._dist = adj  # 各頂点間の最短距離 初期値として隣接行列をそのまま用い、[i, i]要素を0に初期化する
        for i in range(len(adj)):
            self._dist[i][i] = 0

        self._solve()

    def _solve(self):
        v_len = len(self._dist)
        for i in range(v_len):  # 経由する頂点
            for j in range(v_len):  # 開始頂点
                for k in range(v_len):  # 終端
                    self._dist[j][k] = min(self._dist[j][k], self._dist[j][i] + self._dist[i][k])

    def distance(self, start, goal):
        return self._dist[start][goal]

    def path(self, start, goal):
        pass


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

wf = WarshallFloyd(C)

ans = 0
for row in A:
    for cell in row:
        if cell == -1:
            continue
        ans += wf.distance(cell, 1)
print(ans)
a,b,x = map(int,input().split())

ans = 0
for i in range(1,10):
 n = (x - b*i)//a
 if 10**(i-1) <= n < 10**i:
  ans = n
 elif n>=10**i:
  ans=10**i-1
  
if x>=a*10**9+b*10:
 ans=10**9
print(ans) 

### FIXED CODE ###

s = input()

m = {'SUN':7,'MON':6,'TUE':5,'WED':4,'THU':3,'FRI':2,'SAT':1}

print(m[s])
import sys
from fractions import gcd
from itertools import groupby as gb
from itertools import permutations as perm
from collections import Counter as C
from collections import defaultdict as dd
sys.setrecursionlimit(10**5)

n,m = map(int,input().split())
cnt = [0] * n
for i in range(m):
    a,b = map(int,input().split())
    a,b = a-1,b-1
    cnt[a] += 1
    cnt[b] += 1
cnt = sorted(cnt, reverse = True)

odd = 0
even = 0
two = 0

g = gb(cnt)
for k,v in g:
    vv = len(list(v))
    if k == 2:
        two += 1
        continue
    if vv % 2 == 0:
        even += 1
    else:
        odd += 1
        
if two > even + odd:
    print('No')
elif odd == 1:
    print('Yes')
else:
    print('No')


### FIXED CODE ###

n = int(input())
res = []
if n%2 == 0:
    for i in range(1, n + 1):
        for j in range(i + 1, n + 1):
            if i + j == n + 1:
                continue
            res.append([i, j])
elif n % 2 == 1:
    for i in range(1, n + 1):
        for j in range(i + 1, n + 1):
            if i + j == n:
                continue
            res.append([i, j])
print(len(res))
for (i,j) in res:
    print(i, j)
import sys
import math
n = map(int,input())
T,A = 1,1
for i in range(n):
    t,a = map(int,input().split())
    coef = max((T+t-1)//t,(A+a-1)//a)
    T,A = coef * t, coef * a 
print(T+A)     

    


### FIXED CODE ###

import sys
import math
n = int(input())
T,A = 1,1
for i in range(n):
    t,a = map(int,input().split(" "))
    coef = max((T+t-1)//t,(A+a-1)//a)
    T,A = coef * t, coef * a 
print(T+A)