There are N monsters, numbered 1, 2, ..., N.
Initially, the health of Monster i is A_i.
Below, a monster with at least 1 health is called alive.
Until there is only one alive monster, the following is repeated:
 - A random alive monster attacks another random alive monster.
 - As a result, the health of the monster attacked is reduced by the amount equal to the current health of the monster attacking.
Find the minimum possible final health of the last monster alive.

-----Constraints-----
 - All values in input are integers.
 - 2 \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 ... A_N

-----Output-----
Print the minimum possible final health of the last monster alive.

-----Sample Input-----
4
2 10 8 40

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

When only the first monster keeps on attacking, the final health of the last monster will be 2, which is minimum.

Difficulty: EASY

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


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


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


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


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


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


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


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


from math import gcd

def readinput():
	n = int(input())
	a = list(map(int, input().split()))
	return (n, a)

def main(n, a):
	ans = gcd(a[0], a[1])
	for i in range(2, n):
		ans = gcd(ans, a[i])
	return ans

def __starting_point():
	(n, a) = readinput()
	ans = main(n, a)
	print(ans)
__starting_point()


import math
from functools import reduce

def gcd_list(numbers):
	return reduce(math.gcd, numbers)
n = input()
l = [int(x) for x in input().split()]
print(gcd_list(l))


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

def gcd(p, q):
	if q == 0:
		return p
	else:
		return gcd(q, p % q)
g = gcd(a[0], a[1])
for i in range(2, n):
	g = gcd(g, a[i])
print(g)


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


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)


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


import sys
from math import gcd
from functools import reduce
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007

def main():
	(N, *A) = list(map(int, read().split()))
	print(reduce(gcd, A))
	return

def __starting_point():
	main()
__starting_point()


from math import gcd
from functools import reduce
input()
print(reduce(gcd, map(int, input().split())))


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


import numpy as np
n = int(input())
a = list(map(int, input().split()))
gcd = np.frompyfunc(np.gcd, 2, 1)
print(gcd.reduce(a))


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


import numpy as np
from functools import reduce
_ = input()
print(reduce(np.gcd, map(int, input().split())))


import math
n = int(input())
A = tuple(map(int, input().split()))
g = A[0]
for a in A[1:]:
	g = math.gcd(g, a)
print(g)


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


from math import gcd

def lgcd(l):
	res = l[0]
	for i in range(1, len(l)):
		res = gcd(res, l[i])
	return res
n = int(input())
print(lgcd(list(map(int, input().split()))))


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


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

def GCD(*numbers):
	return reduce(gcd, numbers)
g = GCD(*A)
print(g)


import bisect, collections, copy, itertools, math, string
import sys
from functools import reduce

def I():
	return int(sys.stdin.readline().rstrip())

def LI():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def S():
	return sys.stdin.readline().rstrip()

def LS():
	return list(sys.stdin.readline().rstrip().split())

def main():
	from functools import reduce

	def gcd(*numbers):
		return reduce(math.gcd, numbers)
	n = I()
	lst = LI()
	ans = gcd(*lst)
	print(ans)
main()


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


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

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


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


from functools import *
from fractions import *
(_, a) = open(0)
print(reduce(gcd, map(int, a.split())))


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


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


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


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


import sys
import math
sys.setrecursionlimit(10 ** 8)
ini = lambda : int(sys.stdin.readline())
inl = lambda : [int(x) for x in sys.stdin.readline().split()]
ins = lambda : sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print('\x1b[33m', *a, '\x1b[0m', **dict(file=sys.stderr, **kw))

def solve():
	n = ini()
	A = inl()
	g = A[0]
	for i in range(1, n):
		g = math.gcd(g, A[i])
	return g
print(solve())


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


import sys
import math
from collections import defaultdict, deque, Counter
from copy import deepcopy
from bisect import bisect, bisect_right, bisect_left
from heapq import heapify, heappop, heappush
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 main():
	N = I()
	L = sorted(LI())
	past = L[0]
	for i in L:
		past = math.gcd(i, past)
	print(past)

def __starting_point():
	main()
__starting_point()


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


n = int(input())
l = list(map(int, input().split()))
ans = l[0]
for a in l:
	while a > 0:
		ans %= a
		(a, ans) = (ans, a)
print(ans)


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