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: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
g = 0
k = 0
for i in a:
    if i%2 == 0:
        g = 1
    else:
        k = 1
    if g == 1 and k == 1:
        break
if g == 1:
    if k == 1:
        print(1)
    else:
        if len(set(a)) == 1:
            print(a[0])
        else:
            print(2)
else:
    if len(set(a)) == 1:
        print(a[0])
    else:
        print(2)

Submission status: Wrong Answer

Solution code:
def main():
    _ = input()
    A = list(map(int, input().split()))
    min_a = min(A)
    mod = sorted(list(set([a % min_a for a in A])))
    if mod == [0]:
        print(min_a)
        exit()
    elif min_a % 2 == 0 and mod[-1] == min_a // 2:
        print(min_a//2)
        exit()

    for a in A:
        if a % 2 == 1:
            print(1)
            exit()
    print(2)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    _ = input()
    A = list(map(int, input().split()))
    min_a = min(A)
    flag = True
    for a in A:
        if a % min_a != 0:
            flag = False
            break
    if flag is True:
        print(min_a)
        exit()

    for a in A:
        if a % 2 == 1:
            print(1)
            exit()
    print(2)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    _ = input()
    A = list(map(int, input().split()))
    if len(set(A)) == 1:
        print(A[0])
        exit()
    for a in A:
        if a % 2 == 1:
            print(1)
            exit()
    print(2)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Mon Sep 14 17:37:26 2020

@author: liang
"""
N = int(input())
A = [int(x) for x in input().split()]

A.sort()
ans = 10**6
for i in range(N-1):
    if ans > A[i+1] - A[i]:
        ans = A[i+1] - A[i]
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = sorted(map(int, input().split()))
ans = a[0]
for i in range(1,n):
  x = a[i] % ans
  if x > 0:
    ans = min(ans, x)
print(ans)

Submission status: Wrong Answer

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

min_ = min(A)
cnt = 0
odd = 0
for a in A:
    if a %min_ == 0:
        cnt += 1
    if a%2 != 0:
        odd = 1

if cnt == N:
    print(A[0])
    exit()
if odd == 0:
    print(2)
elif odd == 1:
    print(1)

Submission status: Wrong Answer

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

last = A[0]
cnt = 0
odd = 0
for a in A:
    if a == last:
        cnt += 1
    if a%2 != 0:
        odd = 1
    last = a

if cnt == N:
    print(A[0])
    exit()
if odd == 0:
    print(2)
elif odd == 1:
    print(1)

Submission status: Wrong Answer

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

def gcd(a,b):
    while True:
        r=a%b
        if r==0:
            break
        a=b
        b=r
    return b

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

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
if max(a) != min(a):
    while a.count(0) != len(a)-1:
        print(a)
        a.sort()
        b = [a[0]]
        for i in a[1:]:
            if i%a[0] != 0:
                b.append(i%a[0])
        a = b
    print(max(a))
else:
    print(a[0])

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
x = a[0]
for i in range(1,n):
    x,y = max(x,a[i]),min(x,a[i])
    print(x,y)
    while y!=0:x,y=y,x%y
print(x)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(x) for x in input().split()]
mi=min(a)
ans_l=[]
for i in a:
  if i==mi:
    ans_l.append(i)
  else:
    ans_l.append(i%mi)

odd=0
even=0
for i in ans_l:
  if i%2==0:
    even+=1
  else:
    odd+=1

if odd==0 and 0<=even:
  print(min(a))
else:
  print(1)

Submission status: Wrong Answer

Solution code:
from math import floor, ceil, sqrt, factorial, log
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict
from heapq import heappop, heappush, heappushpop
import sys
INF = float('inf')
mod = 10**9+7

# 1 2 3
# a, b, c = LI()


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

# a = I()


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

# abc def
# a, b = LS()


def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()

# a = S()


def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')

# 2
# 1
# 2
# [1, 2]


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

# 2
# 1 2 3
# 4 5 6
# [[1,2,3], [4,5,6]]


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

# 2
# abc
# def
# [abc, def]


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

# 2
# abc def
# ghi jkl
# [[abc,def], [ghi,jkl]]


def LSR(n): return [LS() for i in range(n)]

# 2
# abcd
# efgh
# [[a,b,c,d], [e,f,g,h]]


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


def main():
    n = I()
    lst = LI()
    flg = 0
    for a in lst:
        if a % 2 == 1:
            flg = 1
            break
    if flg == 1:
        print(1)
    else:
        m = min(lst)
        for i in range(n):
            if lst[i] % m == 0:
                lst[i] = m
            else:
                lst[i] %= m
        if all(x == m for x in lst):
            print(m)
        else:
            print(2)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from math import floor, ceil, sqrt, factorial, log
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict
from heapq import heappop, heappush, heappushpop
import sys
INF = float('inf')
mod = 10**9+7

# 1 2 3
# a, b, c = LI()


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

# a = I()


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

# abc def
# a, b = LS()


def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()

# a = S()


def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')

# 2
# 1
# 2
# [1, 2]


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

# 2
# 1 2 3
# 4 5 6
# [[1,2,3], [4,5,6]]


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

# 2
# abc
# def
# [abc, def]


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

# 2
# abc def
# ghi jkl
# [[abc,def], [ghi,jkl]]


def LSR(n): return [LS() for i in range(n)]

# 2
# abcd
# efgh
# [[a,b,c,d], [e,f,g,h]]


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


def main():
    n = I()
    lst = LI()
    flg = 0
    for a in lst:
        if a % 2 == 1:
            flg = 1
            break
    if flg == 1:
        print(1)
    else:
        m = min(lst)
        for i in range(n):
            if lst[i] % m == 0:
                lst[i] = m
            else:
                lst[i] %= m
        if all(x == m for x in lst):
            print(m)
        else:
            print(min(min(lst), m - min(lst)))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from math import floor, ceil, sqrt, factorial, log
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict
from heapq import heappop, heappush, heappushpop
import sys
INF = float('inf')
mod = 10**9+7

# 1 2 3
# a, b, c = LI()


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

# a = I()


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

# abc def
# a, b = LS()


def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()

# a = S()


def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')

# 2
# 1
# 2
# [1, 2]


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

# 2
# 1 2 3
# 4 5 6
# [[1,2,3], [4,5,6]]


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

# 2
# abc
# def
# [abc, def]


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

# 2
# abc def
# ghi jkl
# [[abc,def], [ghi,jkl]]


def LSR(n): return [LS() for i in range(n)]

# 2
# abcd
# efgh
# [[a,b,c,d], [e,f,g,h]]


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


def main():
    n = I()
    lst = LI()
    flg = 0
    for a in lst:
        if a % 2 == 1:
            flg = 1
            break
    if flg == 1:
        print(1)
    else:
        m = min(lst)
        for i in range(n):
            if lst[i] % m == 0:
                lst[i] = m
            else:
                lst[i] %= m
        print(min(min(lst), m - min(lst)))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from math import floor, ceil, sqrt, factorial, log
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict
from heapq import heappop, heappush, heappushpop
import sys
INF = float('inf')
mod = 10**9+7

# 1 2 3
# a, b, c = LI()


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

# a = I()


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

# abc def
# a, b = LS()


def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()

# a = S()


def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')

# 2
# 1
# 2
# [1, 2]


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

# 2
# 1 2 3
# 4 5 6
# [[1,2,3], [4,5,6]]


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

# 2
# abc
# def
# [abc, def]


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

# 2
# abc def
# ghi jkl
# [[abc,def], [ghi,jkl]]


def LSR(n): return [LS() for i in range(n)]

# 2
# abcd
# efgh
# [[a,b,c,d], [e,f,g,h]]


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


def main():
    n = I()
    lst = LI()
    flg = 0
    for a in lst:
        if a % 2 == 1:
            flg = 1
            break
    if flg == 1:
        print(1)
    else:
        m = min(lst)
        for i in range(n):
            if lst[i] % m == 0:
                lst[i] = m
            else:
                lst[i] %= m
        print(min(lst))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from math import floor, ceil, sqrt, factorial, log
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict
from heapq import heappop, heappush, heappushpop
import sys
INF = float('inf')
mod = 10**9+7

# 1 2 3
# a, b, c = LI()


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

# a = I()


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

# abc def
# a, b = LS()


def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()

# a = S()


def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')

# 2
# 1
# 2
# [1, 2]


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

# 2
# 1 2 3
# 4 5 6
# [[1,2,3], [4,5,6]]


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

# 2
# abc
# def
# [abc, def]


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

# 2
# abc def
# ghi jkl
# [[abc,def], [ghi,jkl]]


def LSR(n): return [LS() for i in range(n)]

# 2
# abcd
# efgh
# [[a,b,c,d], [e,f,g,h]]


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


def main():
    n = I()
    lst = LI()
    flg = 0
    for a in lst:
        if a % 2 == 1:
            flg = 1
            break
    if flg == 1:
        print(1)
    elif all(x == lst[0] for x in lst):
        print(lst[0])
    else:
        print(2)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
a.append(a[0])
div = a[0]
minVal = a[0]
for i in range(n+1):
    mod = a[i] % div
    if mod > 0 and minVal > mod:
        minVal = min(mod, div - mod)
        div = minVal
    else:
        continue
print(minVal)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
a.append(a[0])
div = a[0]
minVal = a[0]
for i in range(n+1):
    mod = a[i] % div
    if mod > 0:
        minVal = min(mod, div - mod)
        div = minVal
    else:
        continue
print(minVal)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
div = a[0]
minVal = a[0]
for i in range(n):
    mod = a[i] % div
    if mod > 0:
        minVal = min(mod, div - mod, mod - (div - mod))
    else:
        continue
print(minVal)

Submission status: Wrong Answer

Solution code:
n = int(input())
aL = sorted(list(map(int, input().split(" "))))

s = set()

oddOnly = True
gOnly = True
for a in aL:
    if a % 2 == 1:
        gOnly = False
    if a % aL[0] != 0:
        oddOnly = False
    s.add(a)

if oddOnly:
    print(min(aL))
elif gOnly:
    print(2)
else:
    print(1)

Submission status: Wrong Answer

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


def main():
    from heapq import heappush, heappop

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

    for ai in a:
        heappush(elements, ai)

    while len(elements) >= 2:
        a_min = heappop(elements)

        for _ in range(len(elements)):
            aj = heappop(elements)
            aj %= a_min

            if aj != 0:
                heappush(elements, aj)

        if len(elements) == 0:
            print(a_min)
            exit()

    print(min(a_min, min(elements)))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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


def main():
    from heapq import heappush, heappop

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

    for ai in a:
        heappush(elements, ai)

    while len(elements):
        a_min = heappop(elements)

        for _ in range(len(elements)):
            aj = heappop(elements)
            aj %= a_min

            if aj != 0:
                heappush(elements, aj)

        if len(elements) == 0:
            print(a_min)
            exit()

    print(min(a_min, elements))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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


def main():
    from heapq import heappush, heappop

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

    for ai in a:
        heappush(elements, ai)

    while len(elements) >= 2:
        a_min = heappop(elements)

        for _ in range(len(elements)):
            aj = heappop(elements)
            aj %= a_min

            if aj != 0:
                heappush(elements, aj)

        if len(elements) == 1:
            print(min(a_min, min(elements)))
            exit()
        elif len(elements) == 0:
            print(a_min)
            exit()

    print(min(elements))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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


def main():
    from heapq import heappush, heappop

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

    for ai in a:
        heappush(elements, ai)

    while elements:
        a_min = heappop(elements)

        for _ in range(len(elements)):
            aj = heappop(elements)
            aj %= a_min

            if aj != 0:
                heappush(elements, aj)

        if len(elements) == 0:
            print(a_min)
            exit()

    print(min(elements))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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


def main():
    from heapq import heappush, heappop

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

    for ai in a:
        heappush(elements, ai)

    while elements:
        a_min = heappop(elements)

        for _ in range(len(elements)):
            aj = heappop(elements)
            aj %= a_min

            if aj != 0:
                heappush(elements, aj)

        if len(elements) == 0:
            print(a_min)
            exit()

    print(elements[0])


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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


def main():
    from heapq import heappush, heappop

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

    for ai in a:
        heappush(elements, ai)

    while elements:
        a_min = heappop(elements)

        for _ in range(len(elements)):
            aj = heappop(elements)
            aj %= a_min

            if aj != 0:
                heappush(elements, aj)

        if len(elements) == 0:
            print(a_min)
            exit()


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input()) 
M_List = list(map(int,input().split()))
M_List = sorted(M_List)
a,b = M_List[0],M_List[1]
while a*b > 0:
    if a > b:
        a -= b
    else:
        b -= a
if a > 0:
    print(a)
else:
    print(b)

Submission status: Wrong Answer

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

i = 1
flag = 1
while i < N:
  if A[i] % A[0] != 0:
    flag = 0
    break
  i += 1
if flag == 0:
  print(1)
else:
  print(A[0])

Submission status: Wrong Answer

Solution code:
import heapq
N=int(input())
A=list(map(int,input().split()))
heapq.heapify(A)
t1=heapq.heappop(A)
t2=heapq.heappop(A)
if t2%t1==0:
  print(t1)
else:
  a=t2
  b=t1
  while True:
    a-=b
    if a<1:
      print(b)
      break
    elif a>=b:
      pass
    else:
      t=a
      a=b
      b=t

Submission status: Wrong Answer

Solution code:
# abc118_c.py
# https://atcoder.jp/contests/abc118/tasks/abc118_c

# C - Monsters Battle Royale /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 300点

# 問題文
# N体のモンスターが居て、それぞれ 1,2,...,Nと番号付けられています。
# はじめ、モンスター iの体力は Aiです。
# 以降、体力が 1以上のモンスターを生きているモンスターと呼びます。
# 生きているモンスターが 1体になるまで以下を繰り返します。
#     ランダムに 1体の生きているモンスターがランダムに別の生きているモンスターに攻撃します。
#     その結果、攻撃されたモンスターの体力を攻撃したモンスターの体力と同じ値だけ減らします。
# 最後に生き残ったモンスターの最終的な体力の最小値を求めてください。

# 制約
#     入力は全て整数である。
#     2≤N≤105
#     1≤Ai≤109

# 入力
# 入力は以下の形式で標準入力から与えられる。
# N
# A1 A2 ... AN

# 出力
# 最後に生き残ったモンスターの最終的な体力の最小値を出力せよ。

# 入力例 1
# 4
# 2 10 8 40

# 出力例 1
# 2

# 1番目のモンスターだけが攻撃し続けた場合、最後に生き残ったモンスターの体力は 2となり、このときが最小です。

# 入力例 2
# 4
# 5 13 8 1000000000

# 出力例 2
# 1

# 入力例 3
# 3
# 1000000000 1000000000 1000000000

# 出力例 3
# 1000000000


def calculation(lines):
    # line = lines[0]
    N = int(lines[0])
    # N, M = list(map(int, lines[0].split()))
    values = list(map(int, lines[1].split()))
    # values = list()
    # for i in range(N):
    #     values.append(int(lines[i+1]))

    mi = min(values)
    values = list(set([value % mi for value in values if value > mi]))
    values.append(mi)

    mi = min([value for value in values if value > 0])
    values = list(set([value % mi for value in values if value > mi]))
    values.append(mi)

    mi = min([value for value in values if value > 0])
    values = list(set([value % mi for value in values if value > mi]))
    values.append(mi)

    mi = min([value for value in values if value > 0])
    values = list(set([value % mi for value in values if value > mi]))
    values.append(mi)

    return [values[0]]


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['4', '2 10 8 40']
        lines_export = [2]
    if pattern == 2:
        lines_input = ['4', '5 13 8 1000000000']
        lines_export = [1]
    if pattern == 3:
        lines_input = ['3', '1000000000 1000000000 1000000000']
        lines_export = [1000000000]
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    if len(args) == 1:
        mode = 0
    else:
        mode = int(args[1])
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(2)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
A = tuple(map(int, input().split()))
A = sorted(A)
ma = A[0]
for a in A[1:]:
    if a%ma == 0:
        continue
    else:
        ma = a%ma
print(ma)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
a = np.array([int(i) for i in input().split()])
a = np.sort(a)
d = a[0]
a1 = a % d
if all(a1 == 0):
    ans = min(a)
else:
    ans = 1
print(ans)

Submission status: Wrong Answer

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

    Asum = sum(A)
    ans = 10 ** 10
    for _ in range(2):
        for i in range(N):
            if Asum % A[i] == 0:
                ans = min(ans, A[i])
            else:
                ans = min(ans, Asum % A[i])
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

    Asum = sum(A)
    ans = 10**10
    for i in range(N):
        if Asum % A[i] == 0:
            ans = min(ans, A[i])
        else:
            ans = min(ans, Asum % A[i])
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    n = int(input())
    a = list(map(int, input().split()))
    a.sort()
    ans = a[0]
    if a[0]%2 == 0:
        for i in range(1, n):
            if a[i]%a[0] != 0:
                ans = min(ans, a[i]%a[0])
    else:
        ans = 1
    print(ans)
        
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    a.sort()
    diff = []
    for i in range(1,n):
        diff.append(a[i]-a[i-1])
    Min = min(diff)
    if Min==0:
        print(a[0])
        exit()
    tmp = 10**9
    for i in range(n):
        tmp2= a[i]%Min
        if tmp2>0:
            tmp = min(tmp,tmp2)
        tmp3 = a[i]%a[0]
        if tmp3 >0:
            tmp = min(tmp,tmp3)
    print(min(a[0],tmp))
main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    a.sort()
    diff = []
    for i in range(1,n):
        diff.append(a[i]-a[i-1])
        Min = min(diff)
    if Min==0:
        print(a[0])
        exit()
    tmp = 10**9
    for i in range(n):
        tmp2= a[i]%Min
        if tmp2>0:
            tmp = min(tmp,tmp2)
    print(min(a[0],tmp))
main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    a.sort()
    diff = []
    for i in range(1,n):
        diff.append(a[i]-a[i-1])
    if min(diff)==0:
        tmp = 0
    else:
        tmp = a[-1]%min(diff)
    if tmp > 0:
        print(min(a[0],tmp))
    else:
        print(a[0])
main()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from collections import deque
from collections import Counter
import itertools
import math

def readInt():
  return int(input())
def readInts():
  return list(map(int, input().split()))
def readChar():
  return input()
def readChars():
  return input().split()

n = readInt()
a = list(set(readInts()))

if len(a)==1:
  print(a[0])
  exit()

odd = []
even = []

for i in a:
  if i%2==0:
    even.append(i)
  else:
    odd.append(i)

from math import gcd

if len(odd)>0:
  print(1)
  exit()
elif len(even)>0:
  d = even[0]
  for i in range(len(even)):
    d = gcd(even[i],d)
  print(d)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math

def main():
    N = int(input())
    A = [int(x) for x in input().split()]
    A.sort(reverse=True)
    ans = 0
    for i in range(1,len(A)):
        ans = math.gcd(A[i-1],A[i])
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.buffer.readline
from math import*

n=int(input())
arr=list(map(int,input().split()))
ans=1
if n>2:
	ans=gcd(arr[0],arr[1])
	for i in range(2,n-1):
		ans=gcd(ans,arr[i])
else:
	ans=arr[0]
if arr[-1]%ans==0:
	print(ans)
else:
	print(arr[-1]%ans)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    A = [int(x) for x in input().split()]
    minA = min(A)
    for i in range(N):
        tmp = A[i] % minA
        if tmp < minA and tmp != 0:
            A.append(tmp)
    pA = []
    minA = min(A)
    for i in range(len(A)):
        tmp = A[i] % minA
        if tmp < minA and tmp != 0:
            pA.append(tmp)
    if len(pA) == 0:
        print(min(A))
    else:
        print(min(pA))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def main():
    n = I()
    A = LI()
    min_a = min(A)
    if sum(list(map(lambda x: x%min_a, A))) > 0:
        print(1)
    else:
        print(min_a)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect

sys.setrecursionlimit(10**6)
def zz():
    return list(map(int, sys.stdin.readline().split()))


def z():
    return int(sys.stdin.readline())


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


def C(line):
    return [sys.stdin.readline() for _ in range(line)]

N = z()
A = zz()
A = sorted(A)
ans = A[0]
for i in range(N):
    for j in range(0, i):        
        tmp = A[i] % A[j]
        tmp = min(tmp, A[j]-tmp)
        if (tmp != 0):
            ans = min(ans, tmp)
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
M=list(map(int, input().split()))
ans=min(M)
for m in M:
  if m%ans!=0:
    ans=1
    break
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort()
while a[0] > 0 and a[1] > 0:
    if a[1]  == a[0]:
        print(a[1])
        exit()
    elif a[1] > a[0]:    
        a[1] -= a[0]
    else:
        a[0] -= a[1]
print(max(a[0],a[1]))

Submission status: Wrong Answer

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

ans=A[0]
count=[0]*N
i=0
while i<N:
    count[i]=A[i]%ans
    i+=1

for c in count:
    if c>0:
        ans=min(ans,c)

for a in A:
    if a%ans>0:
        ans=min(ans,a%ans)

for a in A:
    if a%ans>0:
        ans=min(ans,a%ans)

for a in A:
    if a%ans>0:
        ans=min(ans,a%ans)

for a in A:
    if a%ans>0:
        ans=min(ans,a%ans)

print(ans)

Submission status: Wrong Answer

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

ans=A[0]
count=[0]*N
i=0
while i<N:
    count[i]=A[i]%ans
    i+=1

for c in count:
    if c>0:
        ans=min(ans,c)

for a in A:
    if a%ans>0:
        ans=min(ans,a%ans)

for a in A:
    if a%ans>0:
        ans=min(ans,a%ans)

print(ans)

Submission status: Wrong Answer

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

ans=A[0]
count=[0]*N
i=0
while i<N:
    count[i]=A[i]%ans
    i+=1

for c in count:
    if c>0:
        ans=min(ans,c)

for a in A:
    if a%ans>0:
        ans=min(ans,a%ans)

print(ans)

Submission status: Wrong Answer

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

a = sorted(a)


def minn_distance(a, n):
    minn = a[-1]
    for i in range(1, n):
        if minn > a[i] - a[i - 1] and a[i] - a[i - 1] != 0:
            minn = a[i] - a[i - 1]
    return minn


def make_new_list(a, minn):
    for i in range(len(a)):
        a[i] = (a[i] - 1) % minn + 1
    a = sorted(list(set(a)))
    return a


def main(a, n):
    minn = minn_distance(a, n)
    if minn == 1:
        return 1
    a = make_new_list(a, minn)
    if a[0] == 1:
        return 1
    elif len(a) == 1 and a[0] == minn:
        return minn
    else:
        return main(a, len(a))


print(main(a, n))

Submission status: Wrong Answer

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

a = sorted(a)
check_minn = 10 ** 10


def check(a, n, check_minn):
    minn = 10 ** 10
    for i in range(1, n):
        if minn > a[i] - a[i - 1] and a[i] - a[i - 1] != 0:
            minn = a[i] - a[i - 1]
    if minn == 10 ** 10:
        return a[0]
    for i in range(n):
        a[i] = a[i] % minn
    a = sorted(list(set(a)))
    n = len(a)
    if a == [0]:
        return minn
    minn = 10 ** 10
    for i in range(n):
        minn = min(minn, a[i])
    if minn == check_minn:
        return minn
    else:
        check_minn = minn
        return check(a, n, check_minn)


print(check(a, n, check_minn))

Submission status: Wrong Answer

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

a = sorted(a)
check_minn = 10 ** 10


def check(a, n, check_minn):
    minn = 10 ** 10
    for i in range(1, n):
        if minn > a[i] - a[i - 1] and a[i] - a[i - 1] != 0:
            minn = a[i] - a[i - 1]
    if minn == 10 ** 10:
        return a[0]
    for i in range(n):
        a[i] = a[i] % minn
    a = list(set(a))
    n = len(a)
    if a == [0]:
        return minn
    minn = 10 ** 10
    for i in range(n):
        minn = min(minn, a[i])
    if minn == check_minn:
        return minn
    else:
        check_minn = minn
        return check(a, n, check_minn)


print(check(a, n, check_minn))

Submission status: Wrong Answer

Solution code:
import sys
n=int(input())
a=list(map(int,input().split()))
g=0
k=0
i=set(a)
if len(i)==1:
  print(a[0])
  sys.exit()
j=0
while g*k==0 and j<n:
  if a[j] % 2==0:
    g=1
  else:
    k=1
  j+=1

if k==0:
  print(2)
else:
  print(1)