Harryxun/stf_run huggingface dataset:
from scipy.sparse import lil_matrix
import numpy as np
from scipy.sparse.csgraph import dijkstra
n, m = map(int, input().split())
inf = 10**2
graph = [[inf for i in range(n+1)] for j in range(n+1)]
graph_new = [[inf for i in range((n+1)*3)] for j in range((n+1)*3)]
for _ in range(m):
    u, v = map(int, input().split())
    graph[u][v] = 1
    for i in range(3):
        graph_new[u*3 + i][v*3 +((i+1)%3)] = 1
start, goal = map(int, input().split())
graph = dijkstra(graph_new, indices=start*3)
if graph[goal*3] != inf:
    print(int(graph[goal*3]) // 3)
else:
    print(-1)

### FIXED CODE ###

from collections import deque
n, m = map(int, input().split())
inf = 10**9
def bfs(start):
    dist = [inf for i in range((n+1) * 3)]
    que = deque()
    que.append(start)
    finished = set()
    dist[start] = 0
    while que:
        node = que.popleft()
        if node not in finished:
            finished.add(node)
            for i in adjacent_list[node]:
                dist[i] = min(dist[i], dist[node] + 1)
                que.append(i)
    return dist

adjacent_list = [[] for i in range((n+1)*3)]
for _ in range(m):
    u, v = map(int, input().split())
    for i in range(3):
        adjacent_list[u*3 + i].append(v*3 +((i+1)%3))
start, goal = map(int, input().split())
graph = bfs(start*3)
if graph[goal*3] != inf:
    print(int(graph[goal*3]) // 3)
else:
    print(-1)
A,B,C,D =　map(int,input().split())
if A+B > C+D:
  print("Left")
elif A+B == C+D:
  print("Blanced")
else:
  print("Right")

### FIXED CODE ###

A,B,C,D = map(int,input().split())
E = A+B
F = C+D
if E > F:
  print("Left")
elif E == F:
  print("Balanced")
else:
  print("Right")
import collections
N=int(input())
A=[int(x) for x in input().split()]
AA=sorted(A)
c=collections.Counter(A)
third=N//3
answer="No"

#文字が全部0
if all(a==0 for a in A):
  answer="Yes"

#0aa0aaという並びに出来る
#0がN/3個,aが2N/3個で数字は二種類
elif len(c)==2 and N%3==0:
  if all(AA[:third]==0):
    answer="Yes"
     
#abc,abc...,abcという並びに出来る
#aがN/3個,bがN/3個,cがN/3個で数字は三種類
elif len(c)==3 and N%3==0:
  if A.count(AA[0])==third and \
  A.count(AA[third])==third and \
  A.count(AA[2*third])==third:
    if bin(AA[0]^AA[third])==bin(AA[2*third]) and \
    bin(AA[third]^AA[2*third])==bin(AA[0]) and \
    bin(AA[2*third]^AA[0])==bin(AA[third]):
      answer="Yes"
    
print(answer)


### FIXED CODE ###

import collections
N=int(input())
A=[int(x) for x in input().split()]
AA=sorted(A)
c=collections.Counter(A)
third=N//3
answer="No"

#文字が全部0
if all(a==0 for a in A):
  answer="Yes"

#0aa0aaという並びに出来る
#0がN/3個,aが2N/3個で数字は二種類
elif len(c)==2 and N%3==0:
  if all(a==0 for a in AA[:third]):
    answer="Yes"
     
#abc,abc...,abcという並びに出来る
#aがN/3個,bがN/3個,cがN/3個で数字は三種類
elif len(c)==3 and N%3==0:
  if A.count(AA[0])==third and \
  A.count(AA[third])==third and \
  A.count(AA[2*third])==third:
    if bin(AA[0]^AA[third])==bin(AA[2*third]) and \
    bin(AA[third]^AA[2*third])==bin(AA[0]) and \
    bin(AA[2*third]^AA[0])==bin(AA[third]):
      answer="Yes"
    
print(answer)
import sys
n = int(input())
l = list(map(int,input().split()))
if 0 in l:
  print(0)
  sys.exit()
else:
flag = True
anz = 1
for i in l:
  anz *= i
  if anz > 1000000000000000000:
    flag = False 
    break
print (anz if flag else -1)

### FIXED CODE ###

import sys
n = int(input())
l = list(map(int,input().split()))
if 0 in l:
  print(0)
  sys.exit()
flag = True
anz = 1
for i in l:
  anz *= i
  if anz > 1000000000000000000:
    flag = False 
    break
print (anz if flag else -1)
N = int(input())

vertex = [{} for _ in range(N)]

for i in range(N-1):
    a,b,c = map(int,input().split())
    vertex[a-1][b-1] = c
    vertex[b-1][a-1] = c

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

d = [0 for i in range(N)]

def dfs(v1,v2):
    d[v2] = d[v1] + vertex[v1][v2]
    for v in vertex[v2]:
        if v == v1:
            continue
        dfs(v2,v)

for v in vertex[K-1].keys():
    dfs(K-1,v)

for q in range(Q):
    x,y = map(int,input().split())
    print(d[x-1] + d[y-1])


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**8)

N = int(input())

vertex = [{} for _ in range(N)]

for i in range(N-1):
    a,b,c = map(int,input().split())
    vertex[a-1][b-1] = c
    vertex[b-1][a-1] = c

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

d = [0 for i in range(N)]

def dfs(v1,v2):
    d[v2] = d[v1] + vertex[v1][v2]
    for v in vertex[v2]:
        if v == v1:
            continue
        dfs(v2,v)

for v in vertex[K-1].keys():
    dfs(K-1,v)

for q in range(Q):
    x,y = map(int,input().split())
    print(d[x-1] + d[y-1])
n = int(input())
l = list(map(input().split(' '), int))
if max(l) < sum(l) - max(l):
  print('Yes')
else
  print('No')

### FIXED CODE ###

n = int(input())
l = list(map(int, input().split(' ')))
if max(l) < sum(l) - max(l):
  print('Yes')
else:
  print('No')
import sys
import numpy as np


def subset(line):
    l = line.strip().split(" ")
    a = list(map(int, l))
    xy = list(map(lambda x: [x // 10, x % 10], a))
    #print(xy)
    dominos = [[1 if [x, y] in xy or [y, x] in xy else 0 for x in range(0, 7)] for y in range(0, 7)]  
    #print(dominos)
    return (dominos)

lno = 0
for line in sys.stdin:
    lno += 1
    if lno == 1:
        n = int(line)
        dominos = np.zeros((7, 7))
    else:
        dominos = subset(line)
        order = np.sum(dominos, axis = 0)
        #print(order)
        order = order % 2
        if np.all(order == 0):
            print("Yes")
        elif len(order[order == 1]) <= 2:
            print("Yes")
        else:
            print("No")
        lno = 0


### FIXED CODE ###

import sys

def subset(line):
    l = line.strip().split(" ")
    a = list(map(int, l))
    xy = list(map(lambda x: [x // 10, x % 10], a))
    dominos = [[2 if [x, y] in xy and x == y else \
                1 if [x, y] in xy else \
                1 if [y, x] in xy else 0 \
                for x in range(0, 7)] for y in range(0, 7)] 
    digits = []
    for i in xy:
        digits.extend(i)
    digits = list(set(digits))
    digits.sort()
    return digits, dominos

def add_matrix(a, b):
    c = [[a[j][i] + b[j][i] for i in range(0, 7)] for j in range(0, 7)]
    return c

def mul_matrix(a, b):
    c = [[0 for i in range(0, 7)] for j in range(0, 7)]
    for j in range(0, 7):
        for i in range(0, 7):
            for k in range(0, 7):
                c[j][i] += a[j][k] * b[k][i]
    return c
                
def is_connected(d, g):
    a = g[:]
    z = [[0 for i in range(0, 7)] for j in range(0, 7)]
    b = a
    for i in range(0, 7):
        z = add_matrix(z, b)
        b = mul_matrix(b, a)
    zeros = 0
    for i in d:
        if z[d[0]][i] == 0:
            zeros += 1
    return zeros == 0
        
lno = 0
for line in sys.stdin:
    lno += 1
    if lno == 1:
        n = int(line)
    else:
        digits, dominos = subset(line)
        if not is_connected(digits, dominos):
            print("No")
        else:
            order = [sum(dominos[i]) for i in range(0, 7)]
            odd = 0
            for i in digits:
                if order[i] % 2 != 0:
                    odd += 1
            if odd <= 2:
                print("Yes")
            else:
                print("No")
        lno = 0
import math
N=int(input())

print(math.factorical(N)%(10**+7))

### FIXED CODE ###

import math
N=int(input())

print(math.factorial(N)%(10**9+7))
A,B = int(input().split())
if A * B % 2 == 0:
    print("No")
else:
    print("Yes")


### FIXED CODE ###

A,B = map(int, input().split())
if A * B % 2 == 0:
    print("No")
else:
    print("Yes")
n = "#."
m = ".#"
 
while 1:
   H, W = map(int, raw_input().split())
 
   if H == 0 and W == 0:
      break
   if W%2 ==0:
      for i in range(0, H, 2):
         M[i] = n*(w/2)
      for i in range(1, H, 2):
         M[i] = m*(W/2)
   elif W%2 == 1:
      for i in range(0, H, 2):
         M[i] = n*(w/2)+n(0)
      for i in range(1, H, 2):
         M[i] = m*(W/2)+m(0)
 
   for i in range(H):
      print "%c" %(M[i])
   print ""

### FIXED CODE ###

while 1:
   H, W = map(int, raw_input().split())
           
   if H == 0 and W == 0:
      break
   for i in range(H):
      if i%2 == 0:
         if W%2 == 0:
            print "#."*(W/2)
         elif W%2 == 1:
            print "#."*(W/2)+"#"
      elif i%2 == 1:
         if W%2 == 0:
            print ".#"*(W/2)
         elif W%2 == 1:
            print ".#"*(W/2)+"."
   print ""
r = input()

s = r*r
l = 2.0*r

print(s,l)

### FIXED CODE ###

import math

r = float(input())

s = math.pi * r**2
l = 2.0*math.pi*r

print(s, l)
from math import *

H, W, A, B = list(map(int, input().split()))
p = 1000000007

ft = [1]
ift = [-1] * (H + W + 1)
for i in range(1, H + W + 1):
    ft.append(ft[i-1] * i % p)

def ifac(a):
    if ift[a] != -1: return ift[a]
    res = 1
    x = ft[a]
    for i in range(ceil(log2(p-2))):
        if ((p - 2) >> i) & 1:
            res *= x % p
        x *= x % p
    ift[a] = res
    return res

def com(a, b):
    return (ft[a] * ifac(b) * ifac(a-b)) % p

ans = 0
for i in range(H-A):
    ans += com(B+i-1, i) * com(W-B+H-i-2, H-i-1)
    ans %= p

print(ans)


### FIXED CODE ###

def main():
    s = list(map(int, input().split()))
    fives = 0
    sevens = 0
    for item in s:
        if item == 5: fives += 1
        if item == 7: sevens += 1
    if fives == 2 and sevens == 1:
        print('YES')
    else:
        print('NO')

if __name__ == '__main__':
    main()
import collections, sys
sys.setrecursionlimit(10**5 + 5)
N, *A = [int(_) for _ in open(0).read().split()]
win_lose = {i: set() for i in range(1, N + 1)}
for win, lose in zip(A, range(2, N + 1)):
    win_lose[win].add(lose)

memo = [-1] * (N + 1)


def rec(x):
    if memo[x] == -1:
        if win_lose[x] == set():
            memo[x] = 0
        else:
            memo[x] = max(a + b for a, b in zip(
                sorted(rec(y) for y in win_lose[x])[::-1], range(1, N + 1)))
    return memo[x]


print(rec(1))


### FIXED CODE ###

import collections
N, *A = [int(_) for _ in open(0).read().split()]
win_lose = {i: set() for i in range(1, N + 1)}
for win, lose in zip(A, range(2, N + 1)):
    win_lose[win].add(lose)

s1 = [1]
s2 = []
while s1:
    a = s1.pop()
    s2 += [a]
    for b in win_lose[a]:
        s1 += [b]
memo = [0] * (N + 1)
for x in s2[::-1]:
    if win_lose[x] == set():
        memo[x] = 0
    else:
        memo[x] = max(a + b for a, b in zip(
            sorted(memo[y] for y in win_lose[x])[::-1], range(1, N + 1)))
print(memo[1])
n = int(input())
l = map(int, input().split())
l.sort()

ans = 0
for i in range(n):
    for j in range(i + 1, n):
        for k in range(j + 1, n):
            if l[i] != l[j] != l[k]:
                if l[i] + l[j] > l[k]:
                    ans += 1
print(ans)

### FIXED CODE ###

n = int(input())
l = list(map(int, input().split()))
l.sort()

ans = 0
for i in range(n):
    for j in range(i + 1, n):
        for k in range(j + 1, n):
            if l[i] != l[j] != l[k]:
                if l[i] + l[j] > l[k]:
                    ans += 1
print(ans)
n, k = map(int, input().split())
print(min(n%k, k-(n%k)))

### FIXED CODE ###

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

print(a,b,c)
A = list(input())
A1 = reversed(A)

B = A[0:(len(A)-1)/2-1]
B1 = reversed(B)

C = A[(len(A)+3)/2-1:-1]
C1 = reversed(C)

if A == A1 and B == B1 and C == C1:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

A = list(input())
A1 = list(reversed(A))
#print((len(A)-1)/2-1)
 
B = A[:(len(A)-1)//2]
B1 = list(reversed(B))
 
C = A[(len(A)+3)//2-1:]
C1 = list(reversed(C))
 
if A == A1 and B == B1 and C == C1:
    print("Yes")
else:
    print("No")
a,b =map(int,input().split())
c = 1
for i in range(0,a+1):
    if 2*i+4*(a-i) ==b:
      c = 0
      break
if c ==0:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

x = list(map(int,input().split()))
print (x.index(0)+1)
n = input()
print("Yes" if s.count("7") >= 1 else "No")


### FIXED CODE ###

n = input()
print("Yes" if n.count("7") >= 1 else "No")
from collections import deque
S = input()
Q = int(input())
R = 1
Top = deque()
Bot = deque()
for _ in range(Q):
  inp = input()
  if inp[0]=='1':
    R *= -1
  else:
    o, f, c = inp.split()
    if f=='1' and R==-1 or f=='2' and R==1:
      Bot.append(c)
    else:
      Top.appendleft(c)
Top.append(S)
if not len(Bot)==0:
  Top = [*Top]+[*Bot]
S = ''.join(Top)
S = S if R==1 else S[::-1]
print(S)

### FIXED CODE ###

from collections import deque
S = input()
Q = int(input())
R = 1
Top = deque()
Top.append(S)
for _ in range(Q):
  inp = input()
  if inp[0]=='1':
    R *= -1
  else:
    o, f, c = inp.split()
    if f=='1' and R==-1 or f=='2' and R==1:
      Top.append(c)
    else:
      Top.appendleft(c)
S = ''.join(Top)
S = S if R==1 else S[::-1]
print(S)
n = int(input())
s = input() + 'a'

count = min(s.count('#'), s.count('.'))

for i in range(n):
  if s[i] != s[i+1]:
  	count = min(count, s[:i+1].count('#') + s[i+1:].count('.'))
    
print(count)

### FIXED CODE ###

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

print('Yes' if (min(a, b) < c) and (c < max(a, b)) else 'No')
import math
# 時針の速度
# 360度/720分 = 1/2度/m
# 分針の速度
# 360度/60分 = 6度/m
# 時針と分針の度数は両者を減算したものの絶対値
# 使用するのは余弦定理

# def str_to_int(str_num):
#     int_num = int(str_num)
#     return int_num


line = input().split(' ')
# int_line = list(map(lambda str_num: int(str_num), line))
int_line = [int(str_num) for str_num in line]
print(int_line)

# 時針の進行角度
# radian_h =　(H * 60 + M) * 0.5
# radian_m = M * 6

# 時針と分針の角度
degree = abs((int_line[2] * 60 + int_line[3]) * 0.5 - int_line[3] * 6)

# 分針と時針の末端同士の距離
distance_squared = int_line[0] ** 2 + int_line[1] ** 2 - 2 * \
    int_line[0] * int_line[1] * math.cos(math.radians(degree))

distance = math.sqrt(distance_squared)

# print(distance)


### FIXED CODE ###

num = input()
if num.isdecimal():
    if int(num) <= 999:
        first_class_num = int(num[-1])
        if first_class_num in {2, 4, 5, 7, 9}:
            print("hon")
        elif first_class_num in {0, 1, 6, 8}:
            print("pon")
        elif first_class_num is 3:
            print("bon")
a,b = map(int,input().split())

cnt = 0
hole = a
if b<=a:
    cnt = 1
elif:
    for i in range(b):
            hole +=(a-1)
            
            if b<=hole:
                cnt = i+2
            else:
                pass
print(cnt)


### FIXED CODE ###

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

cnt = 0
hole = a
if b==1:
    cnt = 0

elif b!=1 and a>=b:
    cnt = 1
else:
    for i in range(pow(2,10)):
            hole +=(a-1)
            
            if b<=hole:
                cnt = i+2
                break
            else:
                pass
print(cnt)
# -*- coding: utf-8 -*-
from collections import Counter
from itertools import product
def inpl(): return tuple(map(int, input().split()))
   

S = input()
x, y = inpl()
M = []

d = 0
for s in S:
    if s == "F":
        d += 1
    else:
        M.append(d)
        d = 0
M.append(d)

Cx = Counter(M[2::2])
Cy = Counter(M[1::2])

Lx = []
Ly = []

for k, v in Cx.items():
    if k == 0:
        pass
    else:
        Lx.append(list(range(-k*v, k*v+1, 2*k)))
        
for k, v in Cy.items():
    if k == 0:
        pass
    else:
        Ly.append(list(range(-k*v, k*v+1, 2*k)))

def bfss(Ls, t, f):
    N = set([f])
    for L in Ls:
        nN = set(([n+l for n, l in product(N, L)]))
        N = nN
    if t in N:
        return True
    else:
        return False

if bfss(Lx, x, M[0]) and bfss(Ly, y, 0):
    print("Yes")
else:
    print("No")

### FIXED CODE ###

# -*- coding: utf-8 -*-
from collections import Counter
def inpl(): return tuple(map(int, input().split()))

N = int(input())
A = inpl()
C = Counter(A)
res = 0

for k, v in C.items():
    if v < k:
        res += v
    elif v > k:
        res += (v - k)
print(res)
n = int(input())
l = []
for i in range(1,n+1):
  s,p = input(),split()
  l.append(s,-int(p),i)
l.sort()
for x in l:
  print(x[2])
       

### FIXED CODE ###

n = int(input())
l = []
for i in range(1,n+1):
  s,p = input().split()
  l.append((s,-int(p),i))
l.sort()
for x in l:
  print(x[2])
s = input()
k = int(input())

edge = 0
ans = 0
if len(set(s))==1:
    s = s*k
    print(len(s)//2)
else:
    if s[0] != s[-1]:
        ans = 0
        for i in range(len(s)):
            if i==0:
                n=1
                tmp = s[i]
            elif s[i]==tmp:
                n += 1
            else:
                if n!=1:
                    ans += n//2
                tmp = s[i]
                n = 1
        print(ans*k)
        #exit()
    
    a = s[0]
    b = s[-1]
    cnt_a, cnt_b = 0,0
    ite = 0
    while s[cnt_a] == a:
        cnt_a += 1
    while s[len(s)-cnt_b-1] == b:
        cnt_b += 1
    
    s1 = s[:cnt_a]
    s2 = s[cnt_a:len(s)-cnt_b]
    s3 = s[len(s)-cnt_b:]
    
    A = cnt_a//2
    B = cnt_b//2    
    X = 0
    if len(set(s2))>=1:
        X = len(s2)//2
    else:
        for i in range(len(s2)):
            if i==0:
                n = 1
                tmp = s2[i]
            elif s2[i] == tmp:
                n += 1
            else:
                if n != 1:
                    X += n//2
                tmp = s2[i]
                n = 1
    C = (len(s1+s3))//2
    print(A+B+X*k+C*(k-1))

### FIXED CODE ###

s = input()
k = int(input())

if len(set(list(s)))==1:
    print(len(s)*k//2)

elif s[0] != s[-1]:
    cnt = 0
    for i in range(1, len(s)):
        if s[i] == s[i-1]:
            s = s[:i]+'.'+s[i+1:]
    print(s.count('.')*k)
else:
    a,b = 0,0
    c = s[0]
    rev_s = s[::-1]
    for i in range(len(s)):
        if s[i]==c:
            a += 1
        else:
            break
    for i in range(len(s)):
        if rev_s[i]==c:
            b += 1
        else:
            break
    cnt = 0
    for i in range(1, len(s)):
        if s[i] == s[i-1]:
            s = s[:i]+'.'+s[i+1:]
    print(s.count('.')*k - (a//2 + b//2 - (a+b)//2)*(k-1))
N, K = map(int,input().split())
L = list(map(int,input().split()))
for i in range(N,100000):
    flag = 0
    for x in str(i):
        if int(x) in L:
            flag = 1
    if flag == 0:
        print(i)
        exit()

### FIXED CODE ###

L=list(map(int,input().split()))
table=[5,5,7]
L=sorted(L)
if table == L:
  print("YES")
else:
  print("NO")
n = int(input())
li = list(map(int,input().split()))
count=0

for i in range(n-1):
    if li[i] == li[i+1]:
        li[i+1] = li[i]*li[i+2]+1
        count += 1

print(count)


### FIXED CODE ###

n = int(input())
li = list(map(int,input().split()))
count=0

for i in range(n-1):
    if li[i] == li[i+1]:
        li[i+1] = 0
        count += 1

print(count)
N,X = map(int, input().split())
okamotos = [int(input()) for i in range(N)]
print(N + map(int,(X - sum(okamotos))/min(okamotos)))

### FIXED CODE ###

N,X = map(int, input().split())
okamotos = [int(input()) for i in range(N)]
print(N + int((X - sum(okamotos))/min(okamotos)))
# coding: utf-8
# 整数の入力
#a = int(raw_input())
# スペース区切りの整数の入力

N, MaxTotalWeight = map(int, raw_input().split())

def getWeightValuePair(W,Values,WeightValuePair):
    totalValue = 0
    WeightKeys = WeightValuePair.keys()
    WeightValuePairCopy = WeightValuePair.copy()
    for i in range(len(Values)):
        totalValue += Values[i]
        for totalWeight in WeightKeys:
            if (totalWeight + W * (i+1)) <= MaxTotalWeight:
                if (totalWeight + W * (i+1)) not in WeightValuePair:
                    WeightValuePair[totalWeight + W * (i+1)] = WeightValuePairCopy[totalWeight] +  totalValue
                elif WeightValuePairCopy[totalWeight] +  totalValue > WeightValuePairCopy[totalWeight + W * (i+1)]:
                    WeightValuePair[totalWeight + W * (i+1)] = WeightValuePairCopy[totalWeight] +  totalValue
    return WeightValuePair

Weights = []
WeightsValues = []

for i in xrange(N):
    tempData = map(int, raw_input().split())        
    if i == 0:
        Weights.append(tempData[0])
        Weights.append(tempData[0]+1)
        Weights.append(tempData[0]+2)
        Weights.append(tempData[0]+3)
        WeightsValues.append([tempData[1]])
        WeightsValues.append([])
        WeightsValues.append([])
        WeightsValues.append([])
    else:
        WeightsValues[tempData[0] - Weights[0]].append(tempData[1])

for data in WeightsValues:
    data.sort(reverse=True)

returnWeightValuePair = {0:0}
for i in range(4):
    returnWeightValuePair = getWeightValuePair(Weights[i],WeightsValues[i],returnWeightValuePair)

print long(max(returnWeightValuePair.values()))

### FIXED CODE ###

N, W = map(int, raw_input().split())
X = [map(int, raw_input().split()) for _ in range(N)]
 
dp = {}
dp[0] = 0
 
for w, v in X:
    d = dp.copy()
    for k in d:
        if k + w > W:
            continue
        if k + w in dp:
            dp[k + w] = max(dp[k + w], d[k] + v)
        else:
            dp[k + w] = d[k] + v
 
print max(dp.values())
#
import sys
import math
import numpy as np
import itertools


# ひとつ入力
n = int(input())

# リストに入れる
a = [int(i) for i in input().split()] 

for i in range(1,n):
    a[0] = math.gcd(a[0],a[i])
print(a[0])



### FIXED CODE ###

#
import sys
import math
import numpy as np
import itertools


# ひとつ入力
n = int(input())

# リストに入れる
a = [int(i) for i in input().split()] 

def gcd(p,q):
    if p < q:
        r = p
        p = q
        q = r
    if q == 0:
        return p
    r = p % q
    return gcd(q,r)
        

for i in range(1,n):
    a[0] = gcd(a[0],a[i])
print(a[0])
H, W = map(int, input.split())
h, w = map(int, input.split())

print((H-h)*(W-w))

### FIXED CODE ###

H, W = map(int, input().split())
h, w = map(int, input().split())
print((H-h)*(W-w))
def comb(n, r):
  if n < 0 or r < 0:
    return 0
  r = min(r, n - r)
  if n == 0 or r == 0:
    return 1
  return (n - r + 1) * comb(n, r - 1) // r

N, K = list(map(int, input().split()))
for i in range(K):
  print(comb(N - K + 1, i + 1) * comb(K - 1, i) % (10 ** 9 + 7))

### FIXED CODE ###

S = input()
if len(set(S)) != 2 or S.count(S[0]) != 2:
  print('No')
  exit()
print('Yes')
n = int(input())
a = list(map(int, input().split()))

mx = max(a)
table = [0] * (mx + 1)
for i in a:
    table[i] += 1

q = int(input())
total = sum(a)
for i in range(q):
    b, c, = map(int, input().split())
    total -= table[c] * c + table[b] * b
    table[c] += table[b]
    table[b] = 0
    total += table[c] * c
    print(total)


### FIXED CODE ###

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

mx = 10**5
table = [0] * (mx + 1)
for i in a:
    table[i] += 1

q = int(input())
total = sum(a)
for i in range(q):
    b, c, = map(int, input().split())
    total -= table[c] * c + table[b] * b
    table[c] += table[b]
    table[b] = 0
    total += table[c] * c
    print(total)
ef MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7


n = INT()
l = MAP()

s = sum(l)
tmp=0
for i in range(n):
    tmp+=l[i]
    if tmp >= s/2:
        idx = i
        break

left = sum(l[:idx+1])
right = sum(l[idx+1:])
print(abs(right-left))

### FIXED CODE ###

def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7


n = INT()
l = MAP()

s = sum(l)
tmp=0
for i in range(n):
    tmp+=l[i]
    if tmp >= s/2:
        p1 = tmp - (s/2)
        idx1 = i
        break

tmp=0
for i in range(n-1,-1,-1):
    tmp+=l[i]
    if tmp >= s/2:
        p2 = tmp - (s/2)
        idx2 = i
        break

if p1 <= p2:
    left = sum(l[:idx1+1])
    right = sum(l[idx1+1:])
else:
    left = sum(l[:idx2])
    right = sum(l[idx2:])
print(abs(right-left))
n,l=map(int,input().split())
a=list(range(l,l+n,1))
x=sum(a)
if(a in 0):
  a.remove(0)
  print(sum(a))
elif(x<0):
  a.remove(max(a))
  print(sum(a))
elif(x>0):
  a.remove(min(a))
  print(sum(a))

### FIXED CODE ###

n,l=map(int,input().split())
a=list(range(l,l+n,1))
x=sum(a)
if(0 in a):
  a.remove(0)
  print(sum(a))
elif(x<0):
  a.remove(max(a))
  print(sum(a))
elif(x>0):
  a.remove(min(a))
  print(sum(a))
k=int(input())
a=[int(i) for i in input().split()]
chk=2
if a[-1]!=2:
    print(-1)
    exit()
else:
    for i in range(k-1,0,-1):
        if a[i-1]>=a[i]*2:
            print(-1)
            exit()
    print(chk[2])

### FIXED CODE ###

k=int(input())
a=[int(i) for i in input().split()]
l=2
r=3
for i in range(k-1,-1,-1):
    l=(l+a[i]-1)//a[i]*a[i]
    r=(r+a[i]-1)//a[i]*a[i]
if l==r:
    print(-1)
else:
    print(l,r-1)