Problem:
 Score : 300 points    Problem Statement 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 1 4
2 10 8 40      Sample Output 1 2  When only the first monster keeps on attacking, the final health of the last monster will be 2 , which is minimum.       Sample Input 2 4
5 13 8 1000000000      Sample Output 2 1       Sample Input 3 3
1000000000 1000000000 1000000000      Sample Output 3 1000000000

Solution (Python):



import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

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

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

ans = None
for a in As:
    if ans is None:
        ans = a
    else:
        ans = gcd(ans, a)
print(ans)

Solution (Python):
import numpy as np
import math
import sys

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

while True:
    tmpmin = np.min(a[a!=0])
    a[a!=tmpmin] %= tmpmin
    
    if tmpmin == np.min(a[a!=0]):break
    if np.sum(a) == 0: break

print(tmpmin)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n = I()
    a = LI()
    r = a[0]
    for c in a[1:]:
        r = fractions.gcd(r,c)

    return r



print(main())

Solution (Python):
N = int(input())
As = [int(i) for i in input().split()]
while True:
    As = sorted(As)
    if len(As) == 1:
        break
    As = [As[0]] + [i % As[0] for i in As[1:] if i % As[0] > 0]
print(As[0])

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

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

ans = A[0]
for i in range(1,N):
    ans = gcd(ans,A[i])

print(ans)

Solution (Python):

import functools

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

n=int(raw_input())
l=map(int,raw_input().split())
print functools.reduce(gcd,l)

Solution (Python):
import fractions


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

 
ans = fractions.gcd(A[0], A[1])

for i in range(2, N):
    ans = fractions.gcd(ans, A[i])

print(ans)

Solution (Python):
import fractions

n=int(input())
l=list(map(int,input().split()))
x=fractions.gcd(l[0],l[1])
for i in range(n):
  x=fractions.gcd(x,l[i])
print(x)

Solution (Python):
import heapq

N=int(input())
A=sorted(map(int,input().split()))[::-1]
que = []
for x in A:
    heapq.heappush(que, -x)

ans=A[0]
while len(que) > 1:
    v1 = abs(heapq.heappop(que))
    v2 = abs(heapq.heappop(que))
    if v2 == 0:
        print (v1)
        break
    heapq.heappush(que, -(v1 % v2))
    heapq.heappush(que, -(v2))

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

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

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

Solution (Python):

import sys








"""Template"""


class IP:
    """
    入力を取得するクラス
    """

    def __init__(self):
        self.input = sys.stdin.readline

    def I(self):
        """
        1文字の取得に使います
        :return: int
        """
        return int(self.input())

    def S(self):
        """
        1文字の取得(str
        :return: str
        """
        return self.input()

    def IL(self):
        """
        1行を空白で区切りリストにします(int
        :return: リスト
        """
        return list(map(int, self.input().split()))

    def SL(self):
        """
        1行の文字列を空白区切りでリストにします
        :return: リスト
        """
        return list(map(str, self.input().split()))

    def ILS(self, n):
        """
        1列丸々取得します(int
        :param n: 行数
        :return: リスト
        """
        return [int(self.input()) for _ in range(n)]

    def SLS(self, n):
        """
        1列丸々取得します（str
        :param n: 行数
        :return: リスト
        """
        return [self.input() for _ in range(n)]

    def SILS(self, n):
        """
        Some Int LineS
        横に複数、縦にも複数
        :param n: 行数
        :return: list
        """
        return [self.IL() for _ in range(n)]

    def SSLS(self, n):
        """
        Some String LineS
        :param n: 行数
        :return: list
        """
        return [self.SL() for _ in range(n)]


class Idea:
    def __init__(self):
        pass

    def HF(self, p):
        """
        Half enumeration
        半分全列挙です
        pの要素の和の組み合わせを作ります。
        ソート、重複削除行います
        :param p: list : 元となるリスト
        :return: list : 組み合わせられた和のリスト
        """
        return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))

    def Bfs2(self, a):
        """
        bit_full_search2
        bit全探索の改良版
        全探索させたら2進数のリストと10進数のリストを返す
        :return: list２つ : １個目 2進数(16桁)  2個目 10進数
        """
        
        
        
        value = []
        for i in range(1 << len(a)):
            output = []

            for j in range(len(a)):
                if self.bit_o(i, j):
                    """右からj+1番目のiが1かどうか判定"""
                    
                    output.append(a[j])
            value.append([format(i, 'b').zfill(16), sum(output)])

        value.sort(key=lambda x: x[1])
        bin = [value[k][0] for k in range(len(value))]
        val = [value[k][1] for k in range(len(value))]
        return bin, val

    def S(self, s, r=0, m=-1):
        """
        ソート関係行います。色々な設定あります。
        :param s: 元となるリスト
        :param r: reversするかどうか 0=False 1=True
        :param m: （2次元配列）何番目のインデックスのソートなのか
        :return: None
        """
        r = bool(r)
        if m == -1:
            s.sort(reverse=r)
        else:
            s.sort(reverse=r, key=lambda x: x[m])

    def bit_n(self, a, b):
        """
        bit探索で使います。0以上のときにTrue出します
        自然数だからn
        :param a: int
        :param b: int
        :return: bool
        """
        return bool((a >> b & 1) > 0)

    def bit_o(self, a, b):
        """
        bit探索で使います。1のときにTrue出すよ
        oneで1
        :param a: int
        :param b: int
        :return: bool
        """
        return bool(((a >> b) & 1) == 1)

    def ceil(self, x, y):
        """
        Round up
        小数点切り上げ割り算
        :param x: int
        :param y: int
        :return: int
        """
        return -(-x // y)

    def ave(self, a):
        """
        平均を求めます
        :param a: list
        :return: int
        """
        return sum(a) / len(a)

    def gcd(self, x, y):
        if y == 0:
            return x
        else:
            return self.gcd(y, x % y)


"""ここからメインコード"""


def main():
    
    r, e = range, enumerate
    ip = IP()
    id = Idea()

    """この下から書いてね"""
    n = ip.I()
    a = ip.IL()
    res = 1000000010

    for i in r(1, n):
        res = min(res, id.gcd(a[0], a[i]))

    print(res)


main()

Solution (Python):

import sys








"""Template"""


class IP:
    """
    入力を取得するクラス
    """

    def __init__(self):
        self.input = sys.stdin.readline

    def I(self):
        """
        1文字の取得に使います
        :return: int
        """
        return int(self.input())

    def S(self):
        """
        1文字の取得(str
        :return: str
        """
        return self.input()

    def IL(self):
        """
        1行を空白で区切りリストにします(int
        :return: リスト
        """
        return list(map(int, self.input().split()))

    def SL(self):
        """
        1行の文字列を空白区切りでリストにします
        :return: リスト
        """
        return list(map(str, self.input().split()))

    def ILS(self, n):
        """
        1列丸々取得します(int
        :param n: 行数
        :return: リスト
        """
        return [int(self.input()) for _ in range(n)]

    def SLS(self, n):
        """
        1列丸々取得します（str
        :param n: 行数
        :return: リスト
        """
        return [self.input() for _ in range(n)]

    def SILS(self, n):
        """
        Some Int LineS
        横に複数、縦にも複数
        :param n: 行数
        :return: list
        """
        return [self.IL() for _ in range(n)]

    def SSLS(self, n):
        """
        Some String LineS
        :param n: 行数
        :return: list
        """
        return [self.SL() for _ in range(n)]


class Idea:
    def __init__(self):
        pass

    def HF(self, p):
        """
        Half enumeration
        半分全列挙です
        pの要素の和の組み合わせを作ります。
        ソート、重複削除行います
        :param p: list : 元となるリスト
        :return: list : 組み合わせられた和のリスト
        """
        return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))

    def Bfs2(self, a):
        """
        bit_full_search2
        bit全探索の改良版
        全探索させたら2進数のリストと10進数のリストを返す
        :return: list２つ : １個目 2進数(16桁)  2個目 10進数
        """
        
        
        
        value = []
        for i in range(1 << len(a)):
            output = []

            for j in range(len(a)):
                if self.bit_o(i, j):
                    """右からj+1番目のiが1かどうか判定"""
                    
                    output.append(a[j])
            value.append([format(i, 'b').zfill(16), sum(output)])

        value.sort(key=lambda x: x[1])
        bin = [value[k][0] for k in range(len(value))]
        val = [value[k][1] for k in range(len(value))]
        return bin, val

    def S(self, s, r=0, m=-1):
        """
        ソート関係行います。色々な設定あります。
        :param s: 元となるリスト
        :param r: reversするかどうか 0=False 1=True
        :param m: （2次元配列）何番目のインデックスのソートなのか
        :return: None
        """
        r = bool(r)
        if m == -1:
            s.sort(reverse=r)
        else:
            s.sort(reverse=r, key=lambda x: x[m])

    def bit_n(self, a, b):
        """
        bit探索で使います。0以上のときにTrue出します
        自然数だからn
        :param a: int
        :param b: int
        :return: bool
        """
        return bool((a >> b & 1) > 0)

    def bit_o(self, a, b):
        """
        bit探索で使います。1のときにTrue出すよ
        oneで1
        :param a: int
        :param b: int
        :return: bool
        """
        return bool(((a >> b) & 1) == 1)

    def ceil(self, x, y):
        """
        Round up
        小数点切り上げ割り算
        :param x: int
        :param y: int
        :return: int
        """
        return -(-x // y)

    def ave(self, a):
        """
        平均を求めます
        :param a: list
        :return: int
        """
        return sum(a) / len(a)

    def gcd(self, x, y):
        if y == 0:
            return x
        else:
            return self.gcd(y, x % y)


"""ここからメインコード"""


def main():
    
    r, e = range, enumerate
    ip = IP()
    id = Idea()

    """この下から書いてね"""
    n = ip.I()
    a = ip.IL()
    res = max(a)

    for i in r(1, n):
        res = min(res, id.gcd(a[0], a[i]))

    print(res)


main()

Solution (Python):
N = int(input())
a_list = list(map(int, input().split()))


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


ans = a_list[0]

for i in range(N):
    ans = gcd(ans, a_list[i])
print(ans)

Solution (Python):
import numpy as np

input()
A = np.sort(np.array(list(map(int, input().split()))))

while A.size > 1:
    A[1:] = A[1:] % A[0]
    A = np.unique(A)
    if A[0] == 0:
        A = A[1:]

print(A[0])

Solution (Python):
def gcd(a, b):
    while b:
        a, b = b, a%b
    return a

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

ans = As[0]
for A in As[1:]:
    ans = gcd(ans, A)
print(ans)

Solution (Python):
import numpy as np

def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)

N = int(input())
monster_list = list(map(int, input().split()))
monster_list.sort(reverse=True)

for i in range(len(monster_list) - 1):
    monster_list[i + 1] = gcd(monster_list[i + 1], monster_list[i])

print(monster_list[-1])

Solution (Python):
def gcd(a, b):
    return gcd(b % a, a) if a and b else max(a, b)
    
n = int(input())
arr = sorted(list(map(int, input().split(' '))))
maxi = arr[-1]
gc = maxi
for num in arr[:-1]:
    if gcd(num, maxi) < gc:
        gc = gcd(num, maxi)

print(gc)

Solution (Python):
N = int(input())
hps = sorted(list(map(int, input().split())))

while len(hps) > 1:
    for i in range(1, len(hps)):
        hps[i] = hps[i] % hps[0]
    hps = sorted(set(hps))
    if 0 in hps:
        hps.remove(0)
print(hps[0])

Solution (Python):
import fractions

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

for i in range(N - 1):
    a[i + 1] = fractions.gcd(a[i], a[i+1])

print(a[N-1])

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
a = sorted(a)
while len(a)>1:
    for i in range(len(a)):
        if not i==0:
            a[i] %= a[0]
    a = sorted(list(set(a)))
    if a[0]==0:
        a.pop(0)
print(a[0])

Solution (Python):
def gcd(a,b):
    return b if a%b==0 else gcd(b,a%b)

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)

while len(a) > 1:
    min_ = a[-1]
    new = []
    for i in a:
        if i % min_ :
            new.append(i%min_)
    new.append(min_)
    new.sort(reverse=True)
    a = new
print(a[0])

Solution (Python):

import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


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


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


def read_float():
    return float(input())


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


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


def gcd(a, b):
    if a < b:
        return gcd(b, a)
    if b == 0:
        return a
    return gcd(b, a % b)

@mt
def slv(N, A):
    ans = reduce(gcd, A)
    return ans


def main():
    N = read_int()
    
    A = read_int_n()
    
    print(slv(N, A))


if __name__ == '__main__':
    main()

Solution (Python):
import itertools
import numpy as np
import sys
input = sys.stdin.readline
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

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

N = I()
A = IL()

ans = gcd(A[0],A[1])
for i in A:
  if i%ans != 0:
    ans = gcd(ans,i)
  if ans == 1:
    break

print(ans)

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

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

Solution (Python):
from fractions import gcd
n=int(input())
a_s=list(map(int,input().split()))
a=a_s[0]
for i in range(n):
    ans=gcd(a,a_s[i])
    a=ans
print(ans)

Solution (Python):
from functools import reduce
from fractions import gcd
N = int(input())
monster = list(map(int, input().split()))
print(reduce(gcd, monster))

Solution (Python):



from functools import reduce, lru_cache
from fractions import gcd

N = int(input())
A = [int(x) for x in input().split()]

print(reduce(gcd, A))

Solution (Python):
n = int(input())
A = list(map(int,input().split()))
while True:
    if A.count(0) == n - 1:
        print(max(A))
        exit()
    else:
        B = [ _  for _ in A if _ != 0  ]
        attack = min(B)
        sn = A.index(attack)
        
        for i in range(n):
            if A[i] == 0:
                pass
            else:
                if i != sn:
                    A[i] = A[i] % attack
                else:
                    pass

Solution (Python):
n = int(input())
A = list(map(int,input().split()))
while True:
    if A.count(0) == n - 1:
        print(max(A))
        exit()
    else:
        B = [ _  for _ in A if _ != 0  ]
        attack = min(B)
        sn = A.index(attack)
        
        for i in range(n):
            if A[i] == 0:
                pass
            else:
                if i != sn:
                    A[i] = A[i] % attack
                else:
                    pass

Solution (Python):
def fgcd(a,b):
    while b:
        a,b = b,a%b
    return a

N = int(input())
aA = [int(_) for _ in input().split()]
b = aA[0]
for a in aA[1:]:
    b = fgcd(a,b)
    if b == 1:
        print(1)
        exit()
print(b)

Solution (Python):
N = int(input())
aA=[int(_) for _ in input().split()]
iMin = min(aA)
iMax = max(aA)

def fgcd(a,b):
    while b:
        a,b = b,a%b
    return a

if iMin  == 1:
    print(1)
else:
    iDm = [ _ % iMin for _ in aA]
    if max(iDm) == 0:
        print(iMin)
    else:
        b = aA[0]
        for _ in aA[1:]:
            b = fgcd(_,b)
            if b == 1:
                print(1)
                exit()
        print(b)

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


def dcg(a, b):
    while not (a == 0 or b == 0):
        if a > b:
            a %= b
        else:
            b %= a
    return a + b


for i in range(N-1):
    A[i+1] = dcg(A[i], A[i+1])
print(A[-1])

Solution (Python):
N = int(input())
*A, = map(int, input().split())


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

a = A[0]
for i in range(1,N):
  a = gcd(a, A[i])
 
print(a)

Solution (Python):
_N = input()
A_list = list(map(int, input().split()))

while len(A_list) > 1:
    min_A = min(A_list)
    A_list = [min_A] + [A % min_A for A in A_list if A % min_A != 0]

print("{}".format(A_list[0]))

Solution (Python):
def gcd(x, y):
    if y == 0: return x
    return gcd(y, x % y)


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

g = a[0]
for aa in a:
    g = gcd(g, aa)
print(g)

Solution (Python):
from fractions import gcd
n=int(input())
a=list(map(int,input().split()))
b=a[0]
for x in a[1:]:
  b=gcd(b,x)
print(b)

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

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

A.sort()
y=A[0]
for i in range(1,N):
    y=gcd(y,A[i])
print(y)

Solution (Python):
def gcd(a,b):
    if a<b:
        a,b=b,a
    if(a%b==0):
        return  b    
    c=b       
    b=a%b
    return gcd(c,b)      
n=int(input())
a=list(map(int,input().split()))
s=gcd(a[0],a[1])
for i in range(2,n):
    s=gcd(s,a[i])
print(s)

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

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

ans=gcd(a[0],a[1])
if n>2:
  for i in range(2,n):
    ans=gcd(ans,a[i])
print(ans)

Solution (Python):

import sys
import collections

N = int(sys.stdin.readline())

monster = [int(a) for a in sys.stdin.readline().strip().split()]
monster.sort()

while len(monster)>1:
    for i in range(1,len(monster)):
        monster[i] %= monster[0]
    monster.sort()
    while monster[0]==0:
        monster.pop(0)
    


print(monster[0])

Solution (Python):
from fractions import gcd
n = int(input())
A = list(map(int, input().split()))
ans = A[0]
for a in A[1:]:
    ans = gcd(ans, a)
print(ans)

Solution (Python):
from functools import reduce


def gcd(a, b):
    if b == 0:
        return a
    if b > a:
        return gcd(b, a)
    return gcd(b, a % b)


N = int(input())
A = list(map(int, input().split()))
print(reduce(lambda a, b: gcd(a, b), A))

Solution (Python):

from functools import reduce
input()
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)

def gcds(*numbers):
    return reduce(gcd, numbers)
print(gcds(*[int(i) for i in input().split()]))

Solution (Python):
N = int(input())
An = [int(n) for n in input().split()]
M = sorted(set(An))
mini=M[0]
            
while len(M) > 1:
    M = [mini] + [x%mini for x in M[1:] if x % mini != 0]
    M.sort()
    if 1 in M:
        mini=1
        break
    mini = min(mini,M[0])
print(M[0])

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

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

ans = gcd(A[0], A[1])
if N > 2:
    for i in range(2, N):
        ans = gcd(ans, A[i])

print(ans)

Solution (Python):
from fractions import gcd


n = int(input())
array = sorted([int(x) for x in input().split()])

tmp = array[0]
for num in array[1:]:
    tmp = gcd(tmp, num)
print(tmp)

Solution (Python):
from fractions import gcd
from functools import reduce

def gcd_list(numbers):
    return reduce(gcd, numbers)

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

Solution (Python):
from fractions import gcd
from functools import reduce
n = int(input())
print(reduce(gcd,map(int,input().split())))

Solution (Python):
def gcd(x , y):
    if x < y:
        x , y = y , x
    if y == 0:
        return x
    r = x % y
    return gcd(y , r)

N = int(input())
L = list(map(int,input().split()))
ans = L[0]
for i in range(len(L)):
    ans = gcd( ans ,L[i] )
print(ans)

Solution (Python):
import fractions as p,functools as f;input();print(f.reduce(p.gcd,map(int,input().split())))

Solution (Python):
def main():
    N = int(input())
    A = list(map(int, input().split()))
    b = min(A)
    for a in A:
        while True:
            if a % b == 0:
                break
            tb = b
            b = a % b
            a = tb
    print(b)


main()

Solution (Python):
n = input()
A = list(map(int,input().split()))

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

G = A[0]
for i in range(len(A)-1):
  G = gcd(G, A[i+1])
  
print(G)

Solution (Python):
import fractions as p,functools as f;input();print(f.reduce(p.gcd,map(int,input().split())))

Solution (Python):
import functools as f,fractions as p;_,*a=map(int,open(0).read().split());print(f.reduce(p.gcd,a))

Solution (Python):
import fractions as p,functools as f
_,a=input(),list(map(int,input().split()))
print(f.reduce(p.gcd,a))

Solution (Python):
import fractions as p,functools as f
input()
print(f.reduce(p.gcd,list(map(int,input().split()))))

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
 
def gcd(x, y):
  if x % y == 0:
    return y
  else:
    return gcd(y, x % y)
 
num = A[0]
for i in range(1, N):
  num = gcd(max(num, A[i]), min(num, A[i]))
 
print(num)

Solution (Python):









import math
from math import *
from math import factorial as fact
import itertools
from functools import reduce



def perm(a, b):
    import scipy.special
    return scipy.special.perm(a, b, exact = True)

def comb(a, b):
    import scipy.special
    return scipy.special.comb(a, b, exact = True)

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

def gcd_multi(l):
    return reduce(lambda x, y: gcd(x, y), l)

def input_ints(inp = input, sep = ' ', conv = lambda x: int(x)):
    return [conv(x) for x in inp().split(sep = sep)]



N = input_ints()
A = input_ints()

print(gcd_multi(A))

Solution (Python):
import functools as f,fractions as p
_,*a=map(int,open(0).read().split())
print(f.reduce(p.gcd,a))

Solution (Python):
N=int(input())
a=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
c=a[0]
for i in range(N-1):
    c=gcd(c,a[i+1])
print(c)

Solution (Python):
import fractions as p,functools as f;input();print(f.reduce(p.gcd,list(map(int,input().split()))))

Solution (Python):
def gcd(a,b):
    r = a%b
    
    if(r==0): return b
    return gcd(b,r)
n = int(input()) 

hps = [int(i) for i in input().split()]



    
    
hps = sorted(hps)
for i in range(1,n):
    hps[0] = gcd(hps[i], hps[0])

for i in range(len(hps)):
    if(hps[i]==0): continue
    print(hps[i])
    break

Solution (Python):
n = int(input())
a = [int(k) for k in input().split()]

def gcd(x, y): 
  
   while(y): 
       x, y = y, x % y 
  
   return x
ans = gcd(a[0],a[1])
for i in a[2:]:
	ans = gcd(ans,i)
print(ans)

Solution (Python):
import fractions as p, functools as f;input();print(f.reduce(p.gcd, list(map(int, input().split()))))

Solution (Python):
import functools as f,fractions as p
_=input()
print(f.reduce(p.gcd,list(map(int,input().split()))))

Solution (Python):
import fractions
from functools import reduce
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
n = int(input())
a = list(map(int,input().split()))
print(gcd_list(a))

Solution (Python):
import fractions, functools;input();print(functools.reduce(fractions.gcd, list(map(int, input().split()))))

Solution (Python):

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

assert (gcd(10, 3) == 1)

def solve(N, As):
    k = min(As)
    for a in As:
        k = gcd(k, a)
    return k

if __name__ == "__main__":
    N = int(input())
    As = list(map(int, input().split(" ")))
    print(solve(N, As))

Solution (Python):
from functools import reduce

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


if __name__ == '__main__':
    n = int(input())
    a = [int(s) for s in input().split()]
    print(reduce(gcd, a))

Solution (Python):
import functools as f,fractions as p
n=input()
a=list(map(int,input().split()))
print(f.reduce(p.gcd,a))

Solution (Python):
from fractions import gcd;from functools import reduce;input();print(reduce(gcd, list(map(int, input().split()))))

Solution (Python):
from fractions import gcd
_=input()
print(reduce(gcd,map(int,raw_input().split())))

Solution (Python):
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
a = int(input())
x = list(map(int, input().split()))
x.sort()
y = x[0]
for i in range(1,a):
    y = gcd(y,x[i])
print(y)

Solution (Python):
from fractions import gcd
from functools import reduce
_=input()
print(reduce(gcd,map(int,input().split())))

Solution (Python):
from fractions import gcd
n = int(input())
a = [i for i in map(int, input().split())]
ans = gcd(a[0], a[1])
if 2 < n:
    for i in a[2:]:
        ans = gcd(ans, i)
print(ans)

Solution (Python):
from fractions import gcd
from functools import reduce
_=input()
*a,=map(int,input().split())
print(reduce(gcd,a))

Solution (Python):
from sys import stdin
from functools import reduce
import fractions

N = int(input())
A = list(set(map(int,input().split())))
answer = reduce(fractions.gcd, A)
print(answer)

Solution (Python):

n=int(input())
a=[int(i) for i in input().split()]
c=a[0]
def gcd(x,y):
    while y:
        x,y=y,x%y
    return x

for i in a:
    c=gcd(c,i)
print(c)

Solution (Python):
N = int(input())
L = list(map(int,input().split()))
L.sort()
def gcd(x,y):
  while y != 0:
    k = x
    x = y
    y = k%y
  return x
G = gcd(L[0],L[1])
for i in range(1,N-1):
  if G >= gcd(L[i],L[i+1]):
    G = gcd(L[i],L[i+1])
print(G)

Solution (Python):
from fractions import gcd
n=int(input())
a=list(map(int,input().split()))
for s in range(len(a)-1):
  if s==0:x=a[s]
  x=gcd(x,a[s+1])
print(x)

Solution (Python):
import fractions
n = int(input())
a_list = list(map(int, input().split()))
num = a_list[0]

for i in range(n):
    num = fractions.gcd(num, a_list[i])
print(num)

Solution (Python):


from sys import stdin
from functools import reduce
import fractions

input = stdin.readline

N = int(input())

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

answer = reduce(fractions.gcd, A)
print(answer)

Solution (Python):
def gcd(m: int, n: int):

    if n == 0:
        return m

    return gcd(n, m % n)


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

A.sort(reverse=True)

num = A[0]

for i in range(1, N):

    if A[i] > num:
        big = A[i]
        small = num
    else:
        big = num
        small = A[i]

    num = gcd(big, small)

print(num)

Solution (Python):
input()
A = list(map(int, input().split(" ")))
A.sort()
def gcd(a, b):
    while b:
        a, b = b, a%b
    return a
rtn = 0
for i in range(0,len(A)-1):
    A[i+1] = gcd(A[i], A[i+1])
print(A[-1])

Solution (Python):
N = int(input())
A = sorted(list(map(int, input().split())))
 

def gcd(a,b):
    rem = a % b
    while rem != 0:
        a = b
        b = rem
        rem = a % b
    return b
 
cand = A[0]
 
for i in range(1,N):
    cand = gcd(cand, A[i])
 
    if cand == 1:
        break
 
print(cand)

Solution (Python):

N  = int(input())
A = list(map(int,input().split()))
def c(A,B):
    for a,b in zip(A,B):
        if a != b:
            return False
    return True
while True:
    A.sort()
    prev = A[:]
    
    s = A[0]
    for i in range(N):
        if A[i] % s == 0:
            A[i] = s
        else:
            A[i] = A[i] % s
    A.sort()
    
    
    if prev == A: break


print(A[0])

Solution (Python):
import fractions
from functools import reduce

def gcd(numbers):
    return reduce(fractions.gcd, numbers)

n = int(input())
k = list(map(int, input().split()))
print(gcd(k))

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]


def euclid_lcf(a, b):
    if b < a:
        a, b = b, a

    if b % a == 0:
        return a
    else:
        r = b % a
        return euclid_lcf(a, r)


com_factor = euclid_lcf(a[0], a[1])

if len(a) == 2:
    print(com_factor)
else:
    for i in range(2, len(a)):
        com_factor = euclid_lcf(com_factor, a[i])

    print(com_factor)

Solution (Python):
N = input()
A = list(map(int,input().split()))
mina = 0

while True:
    mina = min(A)
    minain = A.index(mina)
    for i in range(len(A)):
        A[i] = A[i] % mina
    if A.count(0) == len(A):
        break
    else:
        A[minain] = mina
        A = list(filter(lambda s:s != 0, A))
        
print(mina)

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]

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

if len(a) == 1:
    print(a[0])
else:
    res = func_gcd(a[0],a[1])
    for i in range(2,n):
        res = func_gcd(res,a[i])
    print(res)

Solution (Python):
n = int(input())
aa = list(map(int,input().split()))

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

ans=aa[0]
for i in range(1,n):
    ans = gcd(ans, aa[i])
print(ans)

Solution (Python):
def read():
    return int(input())

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

def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)

n = read()
a = reads()
ans = a[0]
for i in range(n):
    ans = gcd(ans,a[i])
print(ans)

Solution (Python):
import fractions

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

b = a[0]
for i in range(n - 1):
    b = fractions.gcd(a[i + 1], b)

print(b)