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



Sample input:
4
2 10 8 40


Sample output:
2

Submission status: Accepted

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

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


ans = 0
for ai in a:
    ans = gcd(ans, ai)

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = input().split(" ")
A = [int(i) for i in A]
list = [min(A)]
A = sorted(A)
iii = 0
while True:
    iii += 1
    if A[N-1] % A[N-2] != 0:
        A[N-1] = A[N-1] % A[N-2]
    elif N >= 3 and A[N-1] % A[N-3] != 0:
        A[N-1] = A[N-1] % A[N-3]
    elif N >= 4 and A[N-1] % A[N-4] != 0:
        A[N-1] = A[N-1] % A[N-4]
    elif N >= 5 and A[N-1] % A[N-5] != 0:
        A[N-1] = A[N-1] % A[N-5]
    elif N >= 6 and A[N-1] % A[N-6] != 0:
        A[N-1] = A[N-1] % A[N-6]
    elif N >= 7 and A[N-1] % A[N-7] != 0:
        A[N-1] = A[N-1] % A[N-7]
    elif N >= 8 and A[N-1] % A[N-8] != 0:
        A[N-1] = A[N-1] % A[N-8]
    elif N >= 9 and A[N-1] % A[N-9] != 0:
        A[N-1] = A[N-1] % A[N-9]
    elif N >= 10 and A[N-1] % A[N-10] != 0:
        A[N-1] = A[N-1] % A[N-10]

    A = sorted(A)
    list.append(min(A))
    if iii > 96:
        break       
#print(list)
for i in range(N-1):
    if A[i+1]-A[i] > 0:
        list.append(A[i+1]-A[i])
#print(list)
print(min(list))

Submission status: Accepted

Solution code:
# import math
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

input()
a_list = [int(s) for s in input().split()]

N = len(a_list)
min_last_hp = 10**10

f = min(a_list)
a_list.remove(f)

for i in a_list:
    last_hp = gcd(f, i)
    if last_hp < min_last_hp:
        min_last_hp = last_hp

s = min(a_list)
kouho=gcd(f,s)
if kouho < min_last_hp:
    print(kouho)
else:
    print(min_last_hp)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(_) for _ in input().split()]
m = min(A)
while m > 0:
    for i in range(0,len(A)):
        if A[i] != m:
            A[i] = A[i]%m
    z = A.count(0)
    A = sorted(A)[z:]
    m = A[0]
    if m == 1:
        break
    else:
        if [_%m for _ in A] == [0]*len(A):
            break
print(m)

Submission status: Accepted

Solution code:
from fractions import gcd
print [input(),reduce(gcd,map(int,raw_input().split()))][1]

Submission status: Accepted

Solution code:
N = int(input())

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

Alive = 0

for a in A:
	if a != 0:
		Alive += 1

while Alive > 1:
	for j in range(N):
		prevaj = A[j]
		if A[j] != 0:
			for k in range(N):
				A[k] = A[k] % A[j]
				A[j] = prevaj
	Alive = 0
	for a in A:
		if a != 0:
			Alive += 1


print(sum(A))

Submission status: Accepted

Solution code:
n = int(input()) #整数
a = [int(i) for i in input().split() ]

a = list(set(a))
a.sort()
while len(a) > 1:
    while (a[0] < a[1]):
        a[1] %= a[0]
    x = a[1]
    a[1] = a[0]
    a[0] = x
    if a[0] == 0:
        a.pop(0)
    if a[0] == 1:
        break
print(a[0])

Submission status: Accepted

Solution code:
N = int(input())
A = input().split(" ")
A = [int(i) for i in A]
list = [min(A)]
A = sorted(A)
iii = 0
while True:
    iii += 1
    if A[N-1] % A[N-2] != 0:
        A[N-1] = A[N-1] % A[N-2]
    elif N >= 3 and A[N-1] % A[N-3] != 0:
        A[N-1] = A[N-1] % A[N-3]
    elif N >= 4 and A[N-1] % A[N-4] != 0:
        A[N-1] = A[N-1] % A[N-4]
    elif N >= 5 and A[N-1] % A[N-5] != 0:
        A[N-1] = A[N-1] % A[N-5]
    elif N >= 6 and A[N-1] % A[N-6] != 0:
        A[N-1] = A[N-1] % A[N-6]
    elif N >= 7 and A[N-1] % A[N-7] != 0:
        A[N-1] = A[N-1] % A[N-7]
    elif N >= 8 and A[N-1] % A[N-8] != 0:
        A[N-1] = A[N-1] % A[N-8]
    elif N >= 9 and A[N-1] % A[N-9] != 0:
        A[N-1] = A[N-1] % A[N-9]
    elif N >= 10 and A[N-1] % A[N-10] != 0:
        A[N-1] = A[N-1] % A[N-10]
    elif N >= 11 and A[N-1] % A[N-11] != 0:
        A[N-1] = A[N-1] % A[N-11]
    elif N >= 12 and A[N-1] % A[N-12] != 0:
        A[N-1] = A[N-1] % A[N-12]
    elif N >= 13 and A[N-1] % A[N-13] != 0:
        A[N-1] = A[N-1] % A[N-13]
    elif N >= 14 and A[N-1] % A[N-14] != 0:
        A[N-1] = A[N-1] % A[N-14]
    elif N >= 15 and A[N-1] % A[N-15] != 0:
        A[N-1] = A[N-1] % A[N-15]
    elif N >= 16 and A[N-1] % A[N-16] != 0:
        A[N-1] = A[N-1] % A[N-16]
    elif N >= 17 and A[N-1] % A[N-17] != 0:
        A[N-1] = A[N-1] % A[N-17]
    elif N >= 18 and A[N-1] % A[N-18] != 0:
        A[N-1] = A[N-1] % A[N-18]
    elif N >= 19 and A[N-1] % A[N-19] != 0:
        A[N-1] = A[N-1] % A[N-19]

    A = sorted(A)
    list.append(min(A))
    if iii > 128:
        break       
#print(list)
for i in range(N-1):
    if A[i+1]-A[i] > 0:
        list.append(A[i+1]-A[i])
#print(list)
print(min(list))

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
A = list(map(int,input().split()))
flag = 0
#mi = min(A)
Q = np.array(A)
an = 1
def toku(Q):
    mi = min(Q)
    R1 = Q % mi
    if any(R1) == 0:
        flag = 1
        an = mi
        return flag, an, R1
    else:
        flag = 0
        an = 1
        ind = np.argmin(Q)
        R1[ind] = mi
        R = R1[R1!=0]
        return flag, an, R

while flag == 0:
    flag,an,PP = toku(Q)
    Q = PP

print(an)

Submission status: Accepted

Solution code:
N=int(input())
a_list=[]
a_list = list(map(int, input().split())) # "1 2 3"と入力
min_num=min(a_list)
nokori_list=[i%min_num for i in a_list if i%min_num!=0]
if len(nokori_list)==0:
    print(min_num)
else:    
    while len(nokori_list)!=0:
        if len(nokori_list)==0:
            answer=min_num
            break
        else:
            nokori_list.append(min_num)
            min_num=min(nokori_list)
            new_list=[i%min_num for i in nokori_list if i%min_num!=0]
            nokori_list=new_list
        answer=min_num
    print(answer)

Submission status: Accepted

Solution code:
N = int(input())
A = input().split(" ")
A = [int(i) for i in A]
list = [min(A)]
A = sorted(A)
iii = 0
while True:
    iii += 1
    if A[N-1] % A[N-2] != 0:
        A[N-1] = A[N-1] % A[N-2]
    elif N >= 3 and A[N-1] % A[N-3] != 0:
        A[N-1] = A[N-1] % A[N-3]
    elif N >= 4 and A[N-1] % A[N-4] != 0:
        A[N-1] = A[N-1] % A[N-4]
    elif N >= 5 and A[N-1] % A[N-5] != 0:
        A[N-1] = A[N-1] % A[N-5]
    elif N >= 6 and A[N-1] % A[N-6] != 0:
        A[N-1] = A[N-1] % A[N-6]
    elif N >= 7 and A[N-1] % A[N-7] != 0:
        A[N-1] = A[N-1] % A[N-7]
    elif N >= 8 and A[N-1] % A[N-8] != 0:
        A[N-1] = A[N-1] % A[N-8]
    elif N >= 9 and A[N-1] % A[N-9] != 0:
        A[N-1] = A[N-1] % A[N-9]
    elif N >= 10 and A[N-1] % A[N-10] != 0:
        A[N-1] = A[N-1] % A[N-10]
    elif N >= 11 and A[N-1] % A[N-11] != 0:
        A[N-1] = A[N-1] % A[N-11]
    elif N >= 12 and A[N-1] % A[N-12] != 0:
        A[N-1] = A[N-1] % A[N-12]
    elif N >= 13 and A[N-1] % A[N-13] != 0:
        A[N-1] = A[N-1] % A[N-13]
    elif N >= 14 and A[N-1] % A[N-14] != 0:
        A[N-1] = A[N-1] % A[N-14]
    elif N >= 15 and A[N-1] % A[N-15] != 0:
        A[N-1] = A[N-1] % A[N-15]
    elif N >= 16 and A[N-1] % A[N-16] != 0:
        A[N-1] = A[N-1] % A[N-16]
    elif N >= 17 and A[N-1] % A[N-17] != 0:
        A[N-1] = A[N-1] % A[N-17]
    elif N >= 18 and A[N-1] % A[N-18] != 0:
        A[N-1] = A[N-1] % A[N-18]
    elif N >= 19 and A[N-1] % A[N-19] != 0:
        A[N-1] = A[N-1] % A[N-19]
    elif N >= 20 and A[N-1] % A[N-20] != 0:
        A[N-1] = A[N-1] % A[N-20]
    elif N >= 21 and A[N-1] % A[N-21] != 0:
        A[N-1] = A[N-1] % A[N-21]
    elif N >= 22 and A[N-1] % A[N-22] != 0:
        A[N-1] = A[N-1] % A[N-22]
    elif N >= 23 and A[N-1] % A[N-23] != 0:
        A[N-1] = A[N-1] % A[N-23]
    elif N >= 24 and A[N-1] % A[N-24] != 0:
        A[N-1] = A[N-1] % A[N-24]
    elif N >= 25 and A[N-1] % A[N-25] != 0:
        A[N-1] = A[N-1] % A[N-25]
    elif N >= 26 and A[N-1] % A[N-26] != 0:
        A[N-1] = A[N-1] % A[N-26]
    elif N >= 27 and A[N-1] % A[N-27] != 0:
        A[N-1] = A[N-1] % A[N-27]
    elif N >= 28 and A[N-1] % A[N-28] != 0:
        A[N-1] = A[N-1] % A[N-28]
    elif N >= 29 and A[N-1] % A[N-29] != 0:
        A[N-1] = A[N-1] % A[N-25]
    elif N >= 30 and A[N-1] % A[N-30] != 0:
        A[N-1] = A[N-1] % A[N-30]
    elif N >= 31 and A[N-1] % A[N-31] != 0:
        A[N-1] = A[N-1] % A[N-31]
    elif N >= 32 and A[N-1] % A[N-32] != 0:
        A[N-1] = A[N-1] % A[N-32]
    elif N >= 33 and A[N-1] % A[N-33] != 0:
        A[N-1] = A[N-1] % A[N-33]
    elif N >= 34 and A[N-1] % A[N-34] != 0:
        A[N-1] = A[N-1] % A[N-34]
    elif N >= 35 and A[N-1] % A[N-35] != 0:
        A[N-1] = A[N-1] % A[N-35]
    elif N >= 36 and A[N-1] % A[N-36] != 0:
        A[N-1] = A[N-1] % A[N-36]
    A = sorted(A)
    list.append(min(A))
    if iii > 128:
        break       
#print(list)
for i in range(N-1):
    if A[i+1]-A[i] > 0:
        list.append(A[i+1]-A[i])
#print(list)
print(min(list))

Submission status: Accepted

Solution code:
import fractions

N = int(input())
Ai = list(map(int, input().split()))
if Ai == [Ai[0]] * len(Ai):
    print(Ai[0])
    quit()

#Ai.sort()

i = 1
min = 1000000000
a = Ai[0]
for a2 in Ai[1:]:
    a_gcd = fractions.gcd(a, a2)
    if min > a_gcd:
        min = a_gcd
        if min <= 2:
            print(min)
            quit()

print(min)

Submission status: Accepted

Solution code:
n = int(input())
A = [int(i) for i in input().split()]

def gcd(x, y):
    while y > 0:
        x, y = y, x % y
    return x

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

Submission status: Accepted

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

Submission status: Accepted

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

while True:
    a.sort()
    if max(a) == 1 or a[n-2] == 0:
        break
    for i in a:
        if i != 0:
            t = a.index(i)
            break

    for i in range(n):
        if i == t:
            continue
        a[i] = a[i] % a[t]

print(max(a))

Submission status: Accepted

Solution code:
import numpy as np
i = input()
N = list(set(map(int, input().split(' '))))
def one_turn(l):
  l.sort()
  n = l[0]
  return np.array(list(set([n]+[ l[i]%n for i in range(1,len(l)) if ((l[i]%n != 0))])))

if len(set(N)) == 1 :
  print(N[0])
else :
  N = np.array(N)
  while True :
    N = one_turn(N)
    if N[0] == 1 :
      print(1)
      break
    if len(N) == 1 :
      print(N[0])
      break

Submission status: Accepted

Solution code:
import numpy as np

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

tmp = A
t_min = min(A)
while True:
    tmp = A % t_min
    if sum(tmp) == 0:
        break
    t_min = min(tmp[tmp > 0])

print(t_min)

Submission status: Accepted

Solution code:
def gcd( x, y ):
    while y != 0:
        x, y = y, x%y
    return x
n = int(input())
A = list(map(int, input().split()))

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

Submission status: Accepted

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

A.sort(reverse=True)

denominator = 0
numerator = 1
while A[numerator] != 0:
    A[denominator] = A[denominator] % A[numerator]
    if A[denominator] == 0:
        denominator += 1
        numerator += 1
        if denominator >= N or numerator >= N:
            break
    else:
        denominator, numerator = numerator, denominator
print(min([a for a in A if a > 0]))

Submission status: Accepted

Solution code:
s = input()
m = list(map(int, input().split()))

while True:
    minimum = min(m)
    temp_m = [i % minimum for i in m if i % minimum != 0]
    if len(temp_m) == 0:
        ans = minimum
        break
    m = temp_m + [minimum]
        
print(ans)

Submission status: Accepted

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

b = a.copy()
d = b[0] + 0

while len(b) > 1 :

    for i in range(1,len(b)) :
        b[i] = b[i] % b[0]

    if b.count(0) == len(b)-1 :
        d = b[0]
        break
    else :
        b.sort()
        for j in range(b.count(0)) :
            b.remove(0)

print(d)

Submission status: Accepted

Solution code:
from functools import reduce

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

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


N = input()
A = input().split()
for i in range(len(A)):
    A[i] = int(A[i])
answer = gcd_list(A)
print("{}".format(answer))

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().strip().split()))
min1=min(a)
min2=min1

for i in a:
    amari=i%min1
    if amari!=0:
        if amari<min1:
            min1=amari
lop=True
while lop:
    if min1==min2:
        ans=min1
        lop=False
    elif min1<min2:
        min2=min2%min1
        if min2==0:
            ans=min1
            lop=False
    elif min1>min2:
        min1=min1%min2
        if min1==0:
            ans=min2
            lop=False
print(ans)

Submission status: Accepted

Solution code:

n=int(input())
k=list(map(int,input().split()))
c=k[0]

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

for i in k:
    c=regcd(max(c,i),min(c,i))

    
print(c)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-


def main():
    n = int(input())
    a = sorted(list(map(int, input().split())))
    mod_a = a
    mod = min(a)
    index = 0

    while True:
        for idx, ai in enumerate(a):
            if idx != index:
                mod_a[idx] %= mod

                if 0 < mod_a[idx] < mod:
                    mod = mod_a[idx]
                    index = idx

        if mod_a.count(0) >= n - 1:
            break

    print(max(min(a), max(mod_a)))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
mon = list(map(int, input().split()))
g = min(mon)
div = []
for i in range(1, g + 1):
  if (g % i == 0):
    div.append(i)
    div.append(g // i)
  if (i * i > g):
    break
div.sort(reverse=True)
for d in div:
  mod = []
  for m in mon:
    mod.append(m % d)
  if (list(set(mod)) == [0]):
    print(d)
    break

Submission status: Accepted

Solution code:
def saigo(data):
	count = 0
	for d in data:
		if d == 0:
			count += 1
	return count == len(data)-1

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


while(saigo(data) == False):
	min_val = 10e9
	min_idx = 0
	for i,d in enumerate(data):
		if min_val > d and d != 0:
			min_val = d
			min_idx = i
	for i in range(n):
		if i != min_idx:
			data[i] = data[i] % min_val

for i,d in enumerate(data):
	if d != 0:
		print(d)

Submission status: Accepted

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

def f(x, y):
    if x == 0:
        return y
    elif y == 0:
        return x
    elif x < y:
        return f(x, y%x)
    else:
        return f(x%y, y)

p = None
for i in range(N):
    m = A[i]

    if p == None:
        p = m
        continue

    p = f(p, m)
    




print(p)

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())

A = [int(i) for i in input().split()]
A = np.array(A)

min_amari = min(A)
while 0==0:
  amari = A%min_amari
  amari = amari[amari!=0]
  if len(amari)==0:
    print(min_amari)
    break
  else:
    min_amari = min(amari)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
m = A[0]
A = A[1:]
while True:
  l = len(A)
  A = [A[i]%m for i in range(l) if A[i]%m != 0]
  A.append(m)
  A.sort()
  m = A[0]
  A = A[1:]
  if A == []:
    break
print(m)

Submission status: Accepted

Solution code:
from functools import reduce
def g(a,b):
	return g(b,a%b) if b else a
print((lambda n,a:reduce(g,a))(int(input()),list(map(int,input().split()))))

Submission status: Accepted

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

a.sort()

while True:
    for i in range(n):
        if i == 0:
            continue
        else:
            a[i] %= a[0]
    a.sort()
    t = 0
    for t in range(n):
        if a[t]!=0:
            break
    a = a[t:]
    n = len(a)
    if n==1:
        break;
print(a[n-1])

Submission status: Accepted

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

def gcd(X):
    if len(X) == 1:
        return X[0]
    X.sort()
    residue = set(map(lambda x: x % X[0], X[1:]))
    if 0 in residue:
        residue.remove(0)

    if len(residue) == 0:
        return X[0]
    elif len(residue) == 1:
        return gcd([X[0], residue.pop()])
    return gcd(list(residue))

print(gcd(A))

Submission status: Accepted

Solution code:
"""
Monsters Battle Royale
"""


def solve():
    pass
    '''データインプット'''
    monster_num = int(input())
    monster_hp = [int(i) for i in input().split()]
    '''れっつろわいある'''
    while True:
        # 最小の数値minを求める.
        minmum = min(monster_hp)
        # minで他の数値を割り、余りを求める.
        monster_hp = [i % minmum for i in monster_hp]
        monster_hp = [i for i in monster_hp if i != 0]
        #   ここで、余りが0ならば解はminとなる
        if sum(monster_hp) == 0:
            break
        else:
            monster_hp.append(minmum)
    print(minmum)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
n=[int(i) for i in input()]
a = [int(i) for i in input().split()]
a.sort()
#print(n,a)
def f(y,x):
    if x==0:
        return y
    else:
        return f(x,y%x)

ans=f(a[1],a[0])

for i in range(2,len(a)):
    ans=f(a[i],ans)
    
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
lst=input().split(" ")

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

for i in range(N-1):
    lst[i+1]= gojo(int(lst[i]),int(lst[i+1]))
    
print(lst[N-1])

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
list_A = list(map(int,input().split()))
for _ in range(100):
    min_A = min(list_A)
    list_A.remove(min_A)
    l = np.array([list_A]) % min_A
    lr = list(l.ravel())
    lr.append(min_A)
    list_A = [x for x in lr if x != 0]
    if len(list_A) <= 1:
        break
print(list_A[0])

Submission status: Accepted

Solution code:
from itertools import accumulate
from sys import stdin

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

    a = sorted(A)
    while 1:
        ans = a[0]
        a = [i % ans for i in a]
        a[0] = ans
        if len(a) == 1:
            break
        a = [i for i in a if i > 0]
        a.sort()
    print(ans)

input = lambda: stdin.readline()
main()

Submission status: Accepted

Solution code:
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b,a%b)
n = int(input())
a = list(map(int,input().split()))
ans = a[0]
for x in a:
    ans = gcd(x,ans)
print(ans)

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

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

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

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

print(gcd_list(A))

Submission status: Accepted

Solution code:
import sys

def parse(inp):
    N=int(next(inp).split()[0])
    A=list(map(int,next(inp).split()))
    
    return N,A

def gcd(a,b):
    if(b==0): return a
    return gcd(b,a%b)
  
def main(inp):
    N,A=parse(inp)
    
    for i in range(len(A)-1):
        A[1]=gcd(A[0],A[1])
        del A[0]
        
    return A[0]

  
print(main(sys.stdin))

Submission status: Accepted

Solution code:
N = int(input())
HPs = list(map(int, input().split()))

while len(HPs) > 1:
    HPs.sort()
    for i in range(len(HPs)-1):
        HPs[i+1] = HPs[i+1] % HPs[0]
    while 0 in HPs:
        HPs.remove(0)

print(HPs[0])

Submission status: Accepted

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

while True:
    if len(A) == 1:
        break
    pop_i = []
    A.sort()
    for i in range(1, len(A)):
        life = A[i] % A[0]
        if life == 1:
            print(life)
            exit()
        else:
            A[i] = life
    A = [n for n in A if n > 0]

print(A[0])

Submission status: Accepted

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


while(1):
    count=0
    mina=1000000000+1
    for j in range(len(a)):
        if mina>a[j] and a[j]!=0:
            mina=a[j]
            #print(mina)

    for i in range(len(a)):
        if a[i]==mina and count==0:
            count+=1
        else:
            a[i]=a[i]%mina
    #print(a)
    maxa=max(a)
    if sum(a)==maxa:
        print(maxa)
        break

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
A = list(map(int,input().split()))
A.sort()
lenA = len(A)
while(True):
    minA = 1000000001
    for i in range(lenA):
        if A[i] != 0:
            if minA > A[i]:
                minA = A[i]
                idx = i

    for i in range(lenA):
        if i != idx:
            A[i] %= minA
    
    if A.count(0) == N-1:
        break

A.sort()
print(A[-1])

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split(' ')))
temp = A

while 1:
  pick = min(temp)
  diff = list(filter(lambda x: 0 < x, map(lambda x: x % pick, temp)))

  if len(diff) == 0:
    print(pick)
    break

  diff.append(pick)
  temp = diff

Submission status: Accepted

Solution code:
n = int(input())
a = sorted(list(map(int, input().split())))
while True:
    a = sorted(list(set(a)))
    tmp = sorted(a[:])
    for i in tmp:
        if i == a[0]:
            continue
        elif i % a[0] == 0:
            a.remove(i)
        else:
            a.append(i % a[0])
            if i % a[0] == 1:
                print(1)
                exit()
            a.remove(i)
    if len(a) == 1:
        break
print(a[0])

Submission status: Accepted

Solution code:
import numpy as np
import fractions
from functools import reduce
from sys import stdin
N=int(stdin.readline().rstrip())
data=[int(x) for x in stdin.readline().rstrip().split()]
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

if len(set(data))==1 or len(data)==1:
    print(data[0])
else:
    print(gcd_list(data))

Submission status: Accepted

Solution code:
from fractions import gcd

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

b = A[0]
for a in A[1:]:
    b = gcd(a, b)

print(b)

Submission status: Accepted

Solution code:
# gcd
def gcd(a, b):
	return gcd(b, a % b) if b != 0 else a

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

max_gcd = L[0]

for i in range(1, N):
    max_gcd = gcd(max_gcd, L[i])

print(max_gcd)

Submission status: Accepted

Solution code:
def roop_punch(list,num):
    while 1:
        list.sort()
        list=[i for i in list if i>0]
        min_hp=min(list)
        min_index=list.index(min(list))
        for x in range(len(list)):
            if x==0:
                continue
            if list[x]/min_hp>0:
                list[x]=list[x]%min_hp
            else:
                list[x]-min_hp
        if min(list)==max(list):
            break
    return min(list)
a =int(input())
input_list = list(map(int, input().split()))
s=roop_punch(input_list,a)
print(s)

Submission status: Accepted

Solution code:
import numpy as np

n = int(input())
arr = list(map(int, input().split(' ')))

m = min(arr)
mi = np.argmin(arr)

while m != sum(arr):
  tmp = []
  for i, a in enumerate(arr):
    if mi == i:
      tmp.append(a)
    elif a%m != 0:
      tmp.append(a%m)
  arr = tmp
  m = min(arr)
  mi = np.argmin(arr)
print(m)

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
A = np.array(list(map(int,input().split())))
while len(A) > 1:
    min_A = min(A)
    A = A%min_A
    A = A[A>0]
    A = np.append(A,[min_A])
    answer = min_A
    if answer == 1:
        break
print(min_A)

Submission status: Accepted

Solution code:
from functools import reduce
n = int(input())
a = [int(m) for m in input().split()]
def gcd(a,b):
    if b == 0:
        return a
    return gcd(b, a % b)
def gcd_list(numbers):
    return reduce(gcd, numbers)
a.sort()
new = [a[0]]
for i in range(1, n):
    new.append(a[i] % a[0])

new.sort()

k = gcd_list(new)
for i in range(n):
    if new[i] % k != 0:
        print(1)
        exit()
print(gcd_list(new))

Submission status: Accepted

Solution code:
def gcd(m,n):
    x = max(m,n)
    y = min(m,n)
    if x%y == 0:
        return y
    else:
        while x%y != 0:
            z = x%y
            x = y
            y = z
        else:
            return z
def gcd_list(l):
    g = l[0]
    for i in l[1:]:
        g = gcd(g,i)


    return g
    
N = int(input())
A_list = [int(i) for i in input().split()]
ans = gcd_list(A_list)
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
import sys
# import bisect
# import math
# import numpy as np


"""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進数
        """
        # 参考
        # https://blog.rossywhite.com/2018/08/06/bit-search/
        # https://atcoder.jp/contests/abc105/submissions/4088632
        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])
                    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 d(self, p):
        re = 0
        for i in range(len(p) - 1):
            re += ((p[i][0] - p[i + 1][0]) ** 2 + (p[i][1] - p[i + 1][1]) ** 2) ** 0.5
        return re

    def gcd(self, x, y):
        if y == 0:
            return x
        else:
            return self.gcd(y, x % y)  # 再帰定義


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


def main():
    # 1文字に省略
    r, e = range, enumerate
    ip = IP()
    id = Idea()

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

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

    print(res)


main()

Submission status: Accepted

Solution code:
n = int(input())
monsters = list(map(int, input().split()))

mm = 0
while len(monsters) != 1:
    monsters.sort()
    mm = monsters[0]
    monsters = list(map(lambda x:x % mm, monsters))
    monsters[0] = mm
    monsters = list(filter(lambda x:x != 0, monsters))
print(mm)

Submission status: Accepted

Solution code:
def roop_punch(list,num):
    while 1:
        list.sort()
        list=[i for i in list if i>0]
        #print(list)
        min_hp=min(list)
        min_index=list.index(min(list))
        for x in range(len(list)):
            if x==0:
                continue
            if list[x]/min_hp>0:
                list[x]=list[x]%min_hp
            else:
                list[x]-min_hp
        if min(list)==max(list):
            break

    return min(list)


# スペース区切りの整数の入力
a =int(input())
# 文字列の入力
input_list = list(map(int, input().split()))
#print(like_list)
s=roop_punch(input_list,a)
# 出力
print(s)

Submission status: Accepted

Solution code:
N = int(input())
L = [int(i) for i in input().split()]
l = sorted(L)
#print(l)
while len(l) > 1:
  for i in range(1,len(l)):
    l[i] = l[i] % l[0]
  while 0 in l:
    l.remove(0)
  l.sort()
print(l[0])

Submission status: Accepted

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

#print(A)
flag = True

while flag:
    flag = False
    minVal = min(A)
    #print(minVal)

    for i in range(len(A)):
        x = A[i] % minVal
        if x != 0:
            A[i] = x
            flag = True

    #print(A)

print(minVal)