Snuke had N cards numbered 1 through N.
Each card has an integer written on it; written on Card i is a_i.
Snuke did the following procedure:
 - Let X and x be the maximum and minimum values written on Snuke's cards, respectively.
 - If X = x, terminate the procedure. Otherwise, replace each card on which X is written with a card on which X-x is written, then go back to step 1.
Under the constraints in this problem, it can be proved that the procedure will eventually terminate. Find the number written on all of Snuke's cards after the procedure.

-----Constraints-----
 - All values in input are integers.
 - 1 \leq N \leq 10^{5}
 - 1 \leq a_i \leq 10^9

-----Input-----
Input is given from Standard Input in the following format:
N
a_1 a_2 \cdots a_N

-----Output-----
Print the number written on all of Snuke's cards after the procedure.

-----Sample Input-----
3
2 6 6

-----Sample Output-----
2

 - At the beginning of the procedure, the numbers written on Snuke's cards are (2,6,6).
 - Since x=2 and X=6, he replaces each card on which 6 is written with a card on which 4 is written.
 - Now, the numbers written on Snuke's cards are (2,4,4).
 - Since x=2 and X=4, he replaces each card on which 4 is written with a card on which 2 is written.
 - Now, the numbers written on Snuke's cards are (2,2,2).
 - Since x=2 and X=2, he terminates the procedure.

Difficulty: MEDIUM_HARD

Starter code:

Solutions:
import math

def LI():
	return list(map(int, input().split()))
N = int(input())
A = LI()
Amin = min(A)
ans = Amin
for i in A:
	if Amin == i:
		continue
	Amin = min(Amin, math.gcd(Amin, i))
ans = min(ans, math.gcd(Amin, ans))
print(ans)


import math
N = int(input())
L = list(map(int, input().split()))
ans = L[0]
for i in range(N - 1):
	ans = math.gcd(ans, L[i + 1])
print(ans)


import sys
import math
import itertools
from collections import defaultdict, deque, Counter
from copy import deepcopy
from bisect import bisect, bisect_right, bisect_left
from heapq import heapify, heappop, heappush
from operator import itemgetter, attrgetter
input = sys.stdin.readline

def RD():
	return input().rstrip()

def F():
	return float(input().rstrip())

def I():
	return int(input().rstrip())

def MI():
	return map(int, input().split())

def MF():
	return map(float, input().split())

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

def TI():
	return tuple(map(int, input().split()))

def LF():
	return list(map(float, input().split()))

def Init(H, W, num):
	return [[num for i in range(W)] for j in range(H)]

def TL(mylist):
	return [list(x) for x in zip(*mylist)]

def RtoL(mylist):
	return [list(reversed(x)) for x in mylist]

def HtoL(mylist):
	return [x for x in list(reversed(mylist))]

def convert_2d(l, colstart, colend, rawstart, rawend):
	return [i[rawstart:rawend] for i in l[colstart:colend]]

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

def main():
	N = I()
	L = LI()
	ans = L[0]
	for i in range(N):
		temp = L[i]
		ans = math.gcd(ans, temp)
	print(ans)

def __starting_point():
	main()
__starting_point()


import sys
from math import gcd, factorial, ceil, floor, sqrt
from bisect import bisect_left, bisect_right
from copy import deepcopy
from heapq import heapify, heappop, heappush
from itertools import permutations, combinations, product, accumulate
from collections import defaultdict, deque, Counter
from functools import lru_cache
sys.setrecursionlimit(10 ** 8)
ii = lambda : int(input())
mi = lambda : map(int, input().split())
li = lambda : list(map(int, input().split()))
N = ii()
a = li()
cur = 0
for A in a:
	cur = gcd(cur, A)
print(cur)


import functools
import math
n = int(input())
a = list(map(int, input().split()))
a = list(set(a))
ans = 0
x = functools.reduce(math.gcd, a)
print(x)


import math
N = int(input())
A = [int(x) for x in input().split()]
ans = A[0]
for i in range(1, N):
	ans = math.gcd(ans, A[i])
print(ans)


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

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a
ans = A[0]
for i in range(1, N):
	ans = gcd(ans, A[i])
print(ans)


from math import gcd
N = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(N):
	ans = gcd(ans, A[i])
print(ans)


def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a
N = int(input())
A = list(map(int, input().split()))
answer = A[0]
for a in A:
	answer = gcd(answer, a)
print(answer)


N = int(input())
arr = list(map(int, input().split()))
arr = sorted(set(arr))
while True:
	minValue = arr[0]
	arr = [arr[i] % arr[0] for i in range(1, len(arr)) if arr[i] % arr[0] != 0]
	arr.append(minValue)
	arr = sorted(set(arr))
	if len(arr) == 1:
		print(arr[0])
		return


n = int(input())
from math import gcd
As = list(map(int, input().split()))
ans = As[0]
for a in As:
	ans = gcd(ans, a)
print(ans)


from functools import reduce
import math
a = int(input())
b = list(map(int, input().split()))
GCD = b[0]
for c in b:
	GCD = math.gcd(c, GCD)
print(GCD)


from functools import reduce
from math import gcd

def gcd_list(num_list: list) -> int:
	return reduce(gcd, num_list)

def lcm_base(x: int, y: int) -> int:
	return x * y // gcd(x, y)

def lcm_list(num_list: list):
	return reduce(lcm_base, num_list, 1)
n = int(input())
al = list(map(int, input().split()))
print(gcd_list(al))


import math
n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = a[0]
for i in range(n - 1):
	ans = math.gcd(ans, a[i + 1])
print(ans)


import math
n = int(input())
(ans, *A) = map(int, input().split())
for a in A:
	ans = math.gcd(a, ans)
print(ans)


import math
from functools import reduce
N = int(input())
A = list(map(int, input().split()))
A = list(set(A))

def gcd_list(numbers):
	return reduce(math.gcd, numbers)
print(gcd_list(A))


import math
from functools import reduce
n = int(input())
a = list(map(int, input().split()))
print(reduce(math.gcd, a))


import math
n = int(input())
A = list(set(list(map(int, input().split()))))
ans = A[0]
for a in A:
	ans = math.gcd(ans, a)
print(ans)


import math
n = int(input())
a = list(map(int, input().split()))
for i in range(n - 1):
	a[i + 1] = math.gcd(a[i], a[i + 1])
print(a[-1])


import sys
sys.setrecursionlimit(10 ** 9)
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
read_int = lambda : int(readline())
read_ints = lambda : map(int, readline().split())
read_ints_list = lambda : list(map(int, readline().split()))
read_ints_grid = lambda h: list((list(map(int, readline().split())) for _ in range(h)))
read_strs_list = lambda : list(map(str, readline().rstrip().split()))
read_strs_grid = lambda h: list((list(map(str, readline().rstrip().split())) for _ in range(h)))

def read_allints_grid(w):
	grid = map(int, read().split())
	grid = list(map(list, zip(*(grid for _ in range(w)))))
	return grid

def read_allstrs_grid(w):
	grid = map(str, read().split())
	grid = list(map(list, zip(*(grid for _ in range(w)))))
	return grid

def sol():
	return None

def GCD(a: int, b: int) -> int:
	if b == 0:
		return a
	else:
		return GCD(b, a % b)

def GCD_multi(vec: list) -> int:
	l = vec[0]
	for i in range(len(vec) - 1):
		l = GCD(l, vec[i + 1])
	return l

def main():
	n = read_int()
	A = read_ints_list()
	print(GCD_multi(A))

def __starting_point():
	main()
__starting_point()


n = int(input())
a = [int(x) for x in input().split()]
from functools import reduce
import math

def my_gcd(*numbers):
	return reduce(math.gcd, numbers)
print(my_gcd(*a))


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

def gcd(a, b):
	while b != 0:
		(a, b) = (b, a % b)
	return a
ans = min(a)
for i in a:
	ans = gcd(i, ans)
print(ans)


import sys
import math

def input():
	return sys.stdin.readline().strip()

def I():
	return int(input())

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

def IR(n):
	return [I() for i in range(n)]

def LIR(n):
	return [LI() for i in range(n)]

def SR(n):
	return [S() for i in range(n)]

def S():
	return input()

def LS():
	return input().split()
INF = float('inf')
n = I()
a = LI()
ans = 0
for ai in a:
	ans = math.gcd(ans, ai)
print(ans)


def gcd(x, y):
	while x:
		(x, y) = (y % x, x)
	return y
input()
(*a,) = map(int, input().split())
while len(a) > 1:
	x = a.pop()
	y = a.pop()
	a.append(gcd(x, y))
print(a.pop())


from math import gcd
N = int(input())
a = list(map(int, input().split()))
count = 0
for A in a:
	count = gcd(count, A)
print(count)


import math
from functools import reduce

def gcd(*numbers):
	return reduce(math.gcd, numbers)
n = int(input())
aa = list(map(int, input().split()))
print(gcd(*aa))


import math
from functools import reduce
N = int(input())
a = list(map(int, input().split()))
b = [0] * N
mina = min(a)
for i in range(N):
	if a[i] != mina:
		b[i] = a[i] % mina + mina
	else:
		b[i] = mina

def gcd(*numbers):
	return reduce(math.gcd, numbers)

def gcd_list(numbers):
	return reduce(math.gcd, numbers)
print(gcd(*b))


from math import gcd
n = int(input())
A = list(map(int, input().split()))
A = list(set(A))
n = len(A)
ans = A[0]
for i in range(n):
	ans = gcd(ans, A[i])
print(ans)


def resolve():
	n = int(input())
	a = list(map(int, input().split()))
	while True:
		min_num = min(a)
		a = list(map(lambda x: min_num if x % min_num == 0 else x % min_num, a))
		if all((i == min_num for i in a)):
			print(min_num)
			break
resolve()


import sys
INF = 1 << 60
MOD = 10 ** 9 + 7
sys.setrecursionlimit(2147483647)
input = lambda : sys.stdin.readline().rstrip()
from math import gcd
from functools import reduce

def resolve():
	input()
	print(reduce(gcd, map(int, input().split())))
resolve()


from sys import stdin, stdout
from collections import *
from math import ceil, floor, log, gcd
st = lambda : list(stdin.readline().strip())
li = lambda : list(map(int, stdin.readline().split()))
mp = lambda : list(map(int, stdin.readline().split()))
inp = lambda : int(stdin.readline())
pr = lambda n: stdout.write(str(n) + '\n')
mod = 1000000007
INF = float('inf')

def solve():
	n = inp()
	l = li()
	g = l[0]
	for i in range(1, n):
		g = gcd(g, l[i])
	pr(g)
for _ in range(1):
	solve()


import sys, math, collections, itertools, functools
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
N = int(input())
a = list(map(int, input().split()))
ans = functools.reduce(math.gcd, a)
print(ans)


from math import gcd
from functools import reduce
input()
a = list(map(int, input().split()))
sum = reduce(lambda x, y: gcd(x, y), a)
print(sum)


N = int(input())
a = list(map(int, input().split()))
while 1:
	temp = []
	a.sort()
	k = a[0]
	f = 0
	for i in range(1, len(a)):
		if a[i] % k != 0:
			f = 1
			temp.append(a[i] % k)
	if temp == [] or f == 0:
		print(k)
		return
	a = [k] + temp


from math import gcd
n = int(input())
a = list(map(int, input().split()))
res = a[0]
for i in range(1, len(a)):
	res = gcd(res, a[i])
print(res)


import math
N = int(input())
l = list(map(int, input().split()))
gcd = l[0]
for i in range(1, N):
	gcd = math.gcd(gcd, l[i])
print(gcd)


import bisect
import heapq
import itertools
import sys
import math
import random
import time
from collections import Counter, deque, defaultdict
from functools import reduce
from operator import xor
from types import FunctionType
from typing import List
mod = 10 ** 9 + 7
sys.setrecursionlimit(10 ** 9)

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

def main():
	N = int(input())
	A = lmi()
	A.sort()
	ans = reduce(math.gcd, A)
	print(ans)

def __starting_point():
	main()
__starting_point()


def gcd(a, b):
	while b != 0:
		(a, b) = (b, a % b)
	return a
n = int(input())
a = list(set([int(i) for i in input().split()]))
res = a[0]
for i in range(1, len(a)):
	res = gcd(res, a[i])
print(res)


from functools import reduce
from math import gcd
from typing import List

def solve(n: int, a: List[int]) -> int:
	return reduce(gcd, a)

def main():
	n = int(input())
	a = list(map(int, input().split()))
	print(solve(n, a))

def __starting_point():
	main()
__starting_point()


import math
import collections
import itertools
import copy
from collections import deque
import bisect

def gcd(a, b):
	while b != 0:
		(a, b) = (b, a % b)
	return a

def resolve():
	N = int(input())
	A = list(map(int, input().split()))
	while True:
		Min = min(A)
		Max = max(A)
		for i in range(N):
			A[i] = gcd(A[i], Min)
		if Min == Max:
			break
	print(Min)
resolve()


import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, fabs, gcd
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort_left
from heapq import heappush, heappop
from functools import reduce
import numpy as np

def input():
	return sys.stdin.readline().strip()

def INT():
	return int(input())

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

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

def ZIP(n):
	return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
N = INT()
a = list(MAP())
ans = a[0]
for i in range(len(a) - 1):
	ans = gcd(ans, a[i + 1])
print(ans)


import numpy as np
input()
print(np.gcd.reduce(np.array(input().split(), dtype=np.int32)))


import sys
input = sys.stdin.readline
n = int(input())
L = sorted(set(map(int, input().split())))
while True:
	num = L[0]
	L = sorted(set((L[i] % L[0] for i in range(1, len(L)) if L[i] % L[0] != 0)))
	L.append(num)
	L.sort()
	if len(L) <= 1:
		print(L[0])
		return


(n, *a) = map(int, open(0).read().split())
b = min(a)
while sum((i % b for i in a)):
	a = [i - i // b * b for i in a if i - i // b * b > 0]
	b = min(a)
print(b)


import math
input()
a = 0
for i in map(int, input().split()):
	a = math.gcd(a, i)
print(a)


import heapq
import math
N = int(input())
CL = list(map(int, input().split()))
heapq.heapify(CL)
min = heapq.heappop(CL)
pre = min
GCD = min
if N != 1:
	for i in range(N - 1):
		now = heapq.heappop(CL)
		GCD = math.gcd(GCD, now - pre)
		pre = now
print(GCD)


import math
N = int(input())
a = list(map(int, input().split()))
gcd_a = a[0]
for i in range(1, N):
	gcd_a = math.gcd(gcd_a, a[i])
print(gcd_a)


def GCD(a, b):
	if b == 0:
		return a
	else:
		return GCD(b, a % b)
n = int(input())
a = list(map(int, input().split()))
cnt = 0
for i in range(n):
	cnt = GCD(cnt, a[i])
print(cnt)


from collections import deque
from bisect import bisect_right
from math import gcd
N = int(input())
A = list(set(map(int, input().split())))
A.sort()
ans = A[0]
for a in A[1:]:
	ans = gcd(ans, a)
print(ans)


from functools import reduce
import math
_ = input()
a = sorted(set(map(int, input().split())))
print(reduce(math.gcd, a))


import fractions
N = int(input())
A = list(map(int, input().split()))
ans = A[0]
for i in range(1, N):
	ans = fractions.gcd(ans, A[i])
print(ans)


n = int(input())
l = [int(x) for x in input().split()]
while True:
	l = list(set(l))
	if len(l) == 1:
		print(l[0])
		return
	mn = min(l)
	for (i, e) in enumerate(l):
		if e == mn:
			pass
		elif mn == 1:
			l[i] = 1
		elif e % mn == 0:
			l[i] = mn
		else:
			l[i] = e % mn


from heapq import heappush, heappop, heapify

class RemovableHeap:

	def __init__(self, is_max_heap: bool=False, data: list=None):
		self.data = [] if data is None else data
		self.erased = []
		self.sign = -1 if is_max_heap else 1

	def normalize(self):
		while self.erased and self.data[0] == self.erased[0]:
			heappop(self.data)
			heappop(self.erased)

	def pop(self):
		ret = self.sign * heappop(self.data)
		self.normalize()
		return ret

	def push(self, x):
		heappush(self.data, self.sign * x)
		self.normalize()

	def remove(self, x):
		heappush(self.erased, self.sign * x)
		self.normalize()

	def __len__(self):
		return max(len(self.data) - len(self.erased), 0)

	def get(self):
		return self.sign * self.data[0]

def main():
	N = int(input())
	A = set(map(int, input().split()))
	max_que = RemovableHeap(is_max_heap=True)
	min_que = RemovableHeap()
	for a in A:
		max_que.push(a)
		min_que.push(a)
	while min_que.get() != max_que.get():
		min_A = min_que.get()
		while min_A < max_que.get():
			X = max_que.pop()
			min_que.remove(X)
			max_que.push((X - 1) % min_A + 1)
			min_que.push((X - 1) % min_A + 1)
		max_que.remove(min_que.pop())
	print(max_que.get())
main()


from functools import reduce
N = int(input())
L = list(map(int, input().split()))

def gcd(A, B):
	if A < B:
		(A, B) = (B, A)
	while B:
		(A, B) = (B, A % B)
	return A
print(reduce(gcd, L))


n = int(input())
i = list(map(int, input().split()))
ans = i[0]

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)
for k in range(1, n):
	ans = gcd(ans, i[k])
print(ans)


from math import gcd
n = int(input())
a = [int(i) for i in input().split()]
ans = a[0]
for i in a:
	ans = gcd(ans, i)
print(ans)


import math
n = int(input())
x = list(map(int, input().split()))
a = 0
for i in range(n):
	a = math.gcd(a, x[i])
print(a)


from math import gcd
n = int(input())
l = list(map(int, input().split()))
GCD = l[0]
for i in range(1, n):
	GCD = gcd(GCD, l[i])
print(GCD)


def gcd(x: int, y: int) -> int:
	if x < y:
		(x, y) = (y, x)
	while x % y > 0:
		(x, y) = (y, x % y)
	return y
N = int(input())
A = list(map(int, input().split()))
r = A[0]
for a in A[1:]:
	r = gcd(r, a)
print(r)


from math import gcd
from itertools import combinations, permutations, accumulate, product, combinations_with_replacement
from collections import deque, defaultdict, Counter
import decimal
import re
import math
import bisect
import heapq
import sys
sys.setrecursionlimit(10000000)
mod = 10 ** 9 + 7
INF = float('inf')
dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]
from sys import stdin
readline = stdin.readline

def readInts():
	return list(map(int, readline().split()))

def readTuples():
	return tuple(map(int, readline().split()))

def I():
	return int(readline())

def f(n):
	return int(math.ceil(n - 0.5))
N = I()
A = readInts()
g = 0
for i in range(N):
	g = gcd(g, A[i])
print(g)


import math
N = int(input())
Ai = list(set(map(int, input().split(' '))))
g = Ai[0]
for i in Ai[1:]:
	g = math.gcd(g, i)
print(g)


n = int(input())
l = list(map(int, input().split()))
import math
from functools import reduce

def gcd_list(numbers: list) -> int:
	return reduce(math.gcd, numbers)
print(gcd_list(l))


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inps():
	return input().rstrip()

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

def inpls():
	return list(map(str, input().split()))
from math import gcd, floor, ceil, factorial
import itertools as it
from collections import deque, defaultdict
from collections import Counter

def lcd(a, b):
	return a * b // gcd(a, b)

def chmin(dp, i, x):
	if x < dp[i]:
		dp[i] = x
		return True
	return False

def chmax(dp, i, x):
	if x > dp[i]:
		dp[i] = x
		return True
	return False
N = inp()
a = inpl()
for i in range(len(a)):
	if i == 0:
		ans = a[i]
	else:
		ans = gcd(ans, a[i])
print(ans)


import sys
import io
import math
import collections
import decimal
import itertools
from queue import PriorityQueue
import bisect

def input():
	return sys.stdin.readline()[:-1]
sys.setrecursionlimit(1000000)

def solve(N, a):
	x = min(a)
	while True:
		min_k = 10 ** 9
		for i in range(N):
			a[i] = a[i] % x
			if a[i] > 0:
				min_k = min(min_k, a[i])
		if min_k == 10 ** 9:
			return x
		x = min_k

def main():
	N = int(input())
	a = list(map(int, input().split()))
	a1 = solve(N, a)
	print(a1)

def __starting_point():
	main()
__starting_point()


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

def gcd(n, m):
	if m == 0:
		return n
	elif m > n:
		return gcd(m, n)
	return gcd(m, n % m)
if N == 1:
	print(a[0])
else:
	ans = gcd(a[0], a[1])
	for i in range(2, N):
		ans = gcd(ans, a[i])
	print(ans)


from math import gcd
N = int(input())
a = list(map(int, input().split()))
if N == 1:
	print(a[0])
	return
ans = gcd(a[0], a[1])
if N == 2:
	print(ans)
	return
for i in range(2, N):
	ans = gcd(ans, a[i])
print(ans)


N = int(input())
a = list(map(int, input().split()))
ans = a[0]
from math import gcd
for aval in a:
	ans = gcd(ans, aval)
print(ans)


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

def euclid(a, b):
	if b == 0:
		return a
	else:
		return euclid(b, a % b)

def gcd(nums):
	return functools.reduce(euclid, nums)
print(gcd(a))


import math
n = int(input())
A = list(map(int, input().split()))
m = max(A)
m_ = min(A)
g = A[0]
for i in range(n):
	g = math.gcd(g, A[i])
print(g)


import math
n = int(input())
res = 0
for ai in list(map(int, input().split())):
	res = math.gcd(res, ai)
print(res)


import sys
input = sys.stdin.readline
n = int(input())
a = set(map(int, input().split()))
a = list(a)
a.sort()
while len(a) > 1:
	d = set([a[0]])
	for ii in range(1, len(a)):
		if a[ii] % a[0] > 0:
			d.add(a[ii] % a[0])
	a = list(d)
	a.sort()
print(a[0])


from numpy import *
N = int(input())
A = list(map(int, input().split()))
print(gcd.reduce(A))


import sys
import math
from functools import reduce
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 998244353

def input():
	return sys.stdin.readline().strip()

def gcd(nums):
	return reduce(math.gcd, nums)

def main():
	N = int(input())
	A = list(map(int, input().split()))
	ans = gcd(A)
	print(ans)

def __starting_point():
	main()
__starting_point()


import math

def multi_gcd(lst):
	if len(lst) == 1:
		return lst[0]
	gcd = 0
	for i in range(1, len(lst)):
		if i == 1:
			gcd = math.gcd(lst[0], lst[1])
		else:
			gcd = math.gcd(gcd, lst[i])
	return gcd
n = int(input())
a = list(map(int, input().split()))
print(multi_gcd(a))