Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
B=[]
for i in range(N):
  B.append(A[i]-(i+1))
B.sort()
if N%2==0:
  a=N/2
else:
  a=(N+1)/2
b=B[a-1]
for i in range(N):
  B[N-1]=abs(B[N-1]-b)
print(B)
    
  
  

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
B=[]
for i in range(N):
  B.append(A[i]-(i+1))
B.sort()
if N%2==0:
  a=N/2
  b=int((B[int(a)]+B[int(a-1)])/2)
else:
  a=(N+1)/2
  b=B[int(a-1)]
for i in range(N):
  B[i]=abs(B[i]-b)
print(sum(B))

Buggy python submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
B=A.copy()
B.sort()
A_max=B[N-1]
sum_A=[0]*(A_max+1)
for i in range(A_max+1):
  for num in range(N):
    sum_A[i]+=abs(A[num]-i-num)
sum_A.sort()
print(sum_A[0])
    
  
  




Fixed submission:
N=int(input())
A=list(map(int,input().split()))
B=[]
for i in range(N):
  B.append(A[i]-(i+1))
B.sort()
if N%2==0:
  a=N/2
  b=int((B[int(a)]+B[int(a-1)])/2)
else:
  a=(N+1)/2
  b=B[int(a-1)]
for i in range(N):
  B[i]=abs(B[i]-b)
print(sum(B))

Buggy python submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
B=A.copy()
B.sort()
A_max=B[N]+N
sum_A=[0]*(A_max+1)
for i in range(A_max+1):
  for num in range(N):
    sum_A[i]+=abs(A[num]-i)
sum_A.sort()
print(sum_A[0])
    
  
  




Fixed submission:
N=int(input())
A=list(map(int,input().split()))
B=[]
for i in range(N):
  B.append(A[i]-(i+1))
B.sort()
if N%2==0:
  a=N/2
  b=int((B[int(a)]+B[int(a-1)])/2)
else:
  a=(N+1)/2
  b=B[int(a-1)]
for i in range(N):
  B[i]=abs(B[i]-b)
print(sum(B))

Buggy python submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
B=A.copy()
B.sort()
A_max=B[N-1]+N
sum_A=[0]*(A_max+1)
for i in range(A_max+1):
  for num in range(N):
    sum_A[i]+=abs(A[num]-i)
sum_A.sort()
print(sum_A[0])
    
  
  




Fixed submission:
N=int(input())
A=list(map(int,input().split()))
B=[]
for i in range(N):
  B.append(A[i]-(i+1))
B.sort()
if N%2==0:
  a=N/2
  b=int((B[int(a)]+B[int(a-1)])/2)
else:
  a=(N+1)/2
  b=B[int(a-1)]
for i in range(N):
  B[i]=abs(B[i]-b)
print(sum(B))

Buggy python submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
B=A.copy()
B.sort()
A_max=B[N-1]+N
sum_A=[0]*N
for i in range(A_max+1):
  for num in range(N):
    sum_A[i]+=abs(A[num]-i)
sum_A.sort()
print(sum_A[0])
    
  
  




Fixed submission:
N=int(input())
A=list(map(int,input().split()))
B=[]
for i in range(N):
  B.append(A[i]-(i+1))
B.sort()
if N%2==0:
  a=N/2
  b=int((B[int(a)]+B[int(a-1)])/2)
else:
  a=(N+1)/2
  b=B[int(a-1)]
for i in range(N):
  B[i]=abs(B[i]-b)
print(sum(B))
Buggy python submission (verdict: Runtime Error):
N=int(input())
A=list(int, input().split())
counter=[]
for num in range(len(A)):
  counter.append(0)
for num in range(len(A)):
  while A[num]%2==0:
    A[num]=A[num]/2
    counter[num]+=1
print(sum(counter))
  

Fixed submission:
N=int(input())
A=list(map(int, input().split()))
counter=[]
for num in range(len(A)):
  counter.append(0)
for num in range(len(A)):
  while A[num]%2==0:
    A[num]=A[num]/2
    counter[num]+=1
print(sum(counter))

Buggy python submission (verdict: Runtime Error):
N=int(input())
A=list(int, input().split())
counter=[]
for num in range(N):
  counter.append(0)
for num in range(N):
  while A[num]%2==0:
    A[num]=A[num]/2
    counter[num]+=1
print(sum(counter))
  

Fixed submission:
N=int(input())
A=list(map(int, input().split()))
counter=[]
for num in range(len(A)):
  counter.append(0)
for num in range(len(A)):
  while A[num]%2==0:
    A[num]=A[num]/2
    counter[num]+=1
print(sum(counter))

Buggy python submission (verdict: Runtime Error):
N=int(input())
A=list(int, input().split())
counter=[]
for num in range(N):
  counter.append(0)
for num in range(N):
  while A[num]%2=0:
    A[num]=A[num]/2
    counter[num]+=1
print(sum(counter))
  

Fixed submission:
N=int(input())
A=list(map(int, input().split()))
counter=[]
for num in range(len(A)):
  counter.append(0)
for num in range(len(A)):
  while A[num]%2==0:
    A[num]=A[num]/2
    counter[num]+=1
print(sum(counter))
Buggy python submission (verdict: Runtime Error):
N=int(input())
A=list(map(int, input().split()))
A.sort(reverse=True)
sum1=0
sum2=0
for num in range(N+1):
  if num % 2 ==0:
    sum1 += A[num]
  else:
    sum2 += A[num]
print(sum1-sum2)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
sum1=0
sum2=0
for num in range(N):
  if num % 2 == 0:
    sum1 += A[num]
  else:
    sum2 += A[num]
print(sum1 - sum2)

Buggy python submission (verdict: Runtime Error):
N=int(input())
A=list(map(int, input().split))
A.sort()
print(A[N-1]-A[0])

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
sum1=0
sum2=0
for num in range(N):
  if num % 2 == 0:
    sum1 += A[num]
  else:
    sum2 += A[num]
print(sum1 - sum2)
Buggy python submission (verdict: Runtime Error):
A=10000
B=5000
C=1000
ans_A=-1
ans_B=-1
ans_C=-1
x,y=map(int,input().split())
for a in range(x+1):
  for b in range(x-a+1):
    for c in range(x-a-b+1):
      if a*A+b*B+c*C=y:
        ans_A=a
        ans_B=b
        ans_C=c
print(ans_A,ans_B,ans_C)
      

Fixed submission:
A=10000
B=5000
C=1000
ans_A=-1
ans_B=-1
ans_C=-1
x,y=map(int,input().split())
for a in range(x+1):
  for b in range(x-a+1):
    c=x-a-b
    if a*A+b*B+c*C==y:
      ans_A=a
      ans_B=b
      ans_C=c
print(ans_A,ans_B,ans_C)

Buggy python submission (verdict: Runtime Error):
A=10000
B=5000
C=1000
x,y=map(int,input().split())
for a in range(x+1):
  for b in range(x-a+1):
    for c in range(x-a-b+1):
      if a*A+b*B+c*C=y:
        ans_A=a
        ans_B=b
        ans_C=c
        break
print(ans_A,ans_B,ans_C)
      

Fixed submission:
A=10000
B=5000
C=1000
ans_A=-1
ans_B=-1
ans_C=-1
x,y=map(int,input().split())
for a in range(x+1):
  for b in range(x-a+1):
    c=x-a-b
    if a*A+b*B+c*C==y:
      ans_A=a
      ans_B=b
      ans_C=c
print(ans_A,ans_B,ans_C)

Buggy python submission (verdict: Runtime Error):
A=10000
B=5000
C=1000
x,y=map(int,input().split())
for a in range(x):
  for b in range(x-a):
    for c in range(x-a-b):
      if a*A+b*B+c*C=y:
        ans_A=a
        ans_B=b
        ans_C=c
        break
print(ans_A,ans_B,ans_C)
      

Fixed submission:
A=10000
B=5000
C=1000
ans_A=-1
ans_B=-1
ans_C=-1
x,y=map(int,input().split())
for a in range(x+1):
  for b in range(x-a+1):
    c=x-a-b
    if a*A+b*B+c*C==y:
      ans_A=a
      ans_B=b
      ans_C=c
print(ans_A,ans_B,ans_C)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())

s = [-1] * N
s[0] = 1
s[1] = 1

for m in range(0, M):
    i = int(input())
    s[i] = 0

for n in range(2, N):
    if s[n] == 0:
        continue
    s[n] = s[n - 1] + s[n - 2]

print((s[N-1] + s[N-2]) % 1000000007)

Fixed submission:
N, M = map(int, input().split())

if N == 1:
    print(1)
else:
    s = [-1] * N
    s[0] = 1
    s[1] = 1

    for m in range(0, M):
        i = int(input())
        s[i] = 0

    for n in range(2, N):
        if s[n] == 0:
            continue
        s[n] = s[n - 1] + s[n - 2]

    print((s[N-1] + s[N-2]) % 1000000007)
Buggy python submission (verdict: Runtime Error):
n, x = map(int, input().split())
l = input().split()
for i in range(n):
    l[i] = int(l[i])

j = 0
sum = 0
while x >= sum:
    sum += l[j]
    j += 1
    
print(j)

Fixed submission:
n, x = map(int, input().split())
l = input().split()
for i in range(n):
    l[i] = int(l[i])

cnt = 1
sum = 0
for i in range(n):
    sum += l[i]
    if sum > x:
        break
    cnt += 1
    
print(cnt)

Buggy python submission (verdict: Runtime Error):
n, x = map(int, input().split())
l = input().split()
for i in range(n):
    l[i] = int(l[i])

i = 0
sum = 0
while x >= sum:
    sum += l[i]
    i += 1
    
print(i)

Fixed submission:
n, x = map(int, input().split())
l = input().split()
for i in range(n):
    l[i] = int(l[i])

cnt = 1
sum = 0
for i in range(n):
    sum += l[i]
    if sum > x:
        break
    cnt += 1
    
print(cnt)
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())

s = list(input())

s[k] = s[k].lower()
a = ''.join(s)

print(a)

Fixed submission:
n, k = map(int, input().split())

s = list(input())

s[k-1] = s[k-1].lower()
a = ''.join(s)

print(a)
Buggy python submission (verdict: Runtime Error):
n = int(input())
x = []
u = []
sum = 0.0
for i in range(n):
    tmp1, tmp2 = input().split()
    x.append(int(tmp1))
    u.append(tmp2)
    if u[i] == "JPY":
        sum += x[i]
    else:
        sum += int(x[i] * 380000)

print(sum)

Fixed submission:
n = int(input())
x = []
u = []
sum = 0.0
for i in range(n):
    tmp1, tmp2 = input().split()
    x.append(float(tmp1))
    u.append(tmp2)
    if u[i] == "JPY":
        sum += x[i]
    else:
        sum += x[i] * 380000

print(sum)
Buggy python submission (verdict: Runtime Error):
import copy

n = int(input())
h = []
for i in range(n):
    h.append(int(input()))

h = h.sort()

cnt = 1
now = copy.deepcopy(h[0])
h.pop(0)

while not len(h) == 0:
    if h[0] != now:
        cnt += 1
        now = copy.deepcopy(h[0])
    h.pop(0)

Fixed submission:
s = int(input())

def func(n):
    if n % 2 == 0:
        return n / 2
    else:
        return 3 * n + 1

a = {}
a[1] = s

i = 2
while True:
    tmp = func(a[i-1])
    if tmp in a.values():
        print(i)
        break
    else:
        a[i] = tmp
        i += 1
Buggy python submission (verdict: Runtime Error):
a = input()
for i in range(len(a)):
    if a[i] == '1':
        a[i] = '9'
    elif a[i] == '9':
        a[i] = '1'
print(a)


Fixed submission:
a = input()
for i in range(len(a)):
    if a[i] == '1':
        a = a[:i] + '9' + a[i+1:]
    elif a[i] == '9':
        a = a[:i] + '1' + a[i+1:]
print(a)
Buggy python submission (verdict: Runtime Error):
n, m, x, y = map(int, input().split())
xs = input().split()
ys = input().split()

for i in range(n):
    xs[i] = int(xs[i])

for i in range(m):
    ys[i] = int(ys[i])

if max(xs) < min(ys):
    print("No War")
else:
    print("War")

Fixed submission:
l = input().split()
for i in range(len(l)):
    l[i] = int(l[i])
    
l.sort()
print(l[2] * 10 + l[1] + l[0])
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
fib=[1]
a=1
b=1
for i in range(n):
    fib.append(b)
    c=b
    b+=a
    a=c

total=1
cannot=0
s=-1
for i in range(m):
    t=int(input())
    if t-s == 1:
        cannot+=1
        break
    else:
        total*=fib[t-s-2]
        total%=10**9+7
    s=t



if n+1-t <= 1:
    cannot+=1
else:
    total*=fib[n-t-1]
    total%=10**9+7

if cannot != 0:
    print(0)
else:
    print(total)

Fixed submission:
n,m=map(int,input().split())
fib=[1]
a=1
b=1
for i in range(n):
    fib.append(b)
    c=b
    b+=a
    a=c

total=1
cannot=0
s=-1
if m==0:
    total=fib[n]%(10**9+7)
else:
    for i in range(m):
        t=int(input())
        if t-s == 1:
            cannot+=1
            break
        else:
            total*=fib[t-s-2]
            total%=10**9+7
        s=t



    if n+1-t <= 1:
        cannot+=1
    else:
        total*=fib[n-t-1]
        total%=10**9+7

if cannot != 0:
    print(0)
else:
    print(total)

Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
fib=[1]
a=1
b=1
for i in range(n):
    fib.append(b)
    c=b
    b+=a
    a=c

total=1
cannot=0
s=-1
for i in range(m):
    t=int(input())
    if t-s == 1:
        cannot+=1
        break
    else:
        total*=fib[t-s-2]
        total%=10**9+7
    s=t



if n+1-t <= 1:
    cannot+=1
else:
    total*=fib[n-t-1]
    total%=10**9+7

if cannot != 0:
    print(0)
else:
    print(total)

Fixed submission:
n,m=map(int,input().split())
fib=[1]
a=1
b=1
for i in range(n):
    fib.append(b)
    c=b
    b+=a
    a=c

total=1
cannot=0
s=-1
if m==0:
    total=fib[n]%(10**9+7)
else:
    for i in range(m):
        t=int(input())
        if t-s == 1:
            cannot+=1
            break
        else:
            total*=fib[t-s-2]
            total%=10**9+7
        s=t



    if n+1-t <= 1:
        cannot+=1
    else:
        total*=fib[n-t-1]
        total%=10**9+7

if cannot != 0:
    print(0)
else:
    print(total)
Buggy python submission (verdict: Runtime Error):
n=int(input())
sp=[]
for i in range(n):
    s,p=map(str(input().split()))
    sp.append([s,int(p),i+1])
sp.sort(key=lambda x: x[1],reverse=True)
sp.sort(key=lambda x: x[0])

for e in sp:
    print(e[2])


Fixed submission:
n=int(input())
sp=[]
for i in range(n):
    s,p=map(str,input().split())
    sp.append([s,int(p),i+1])
sp.sort(key=lambda x: x[1],reverse=True)
sp.sort(key=lambda x: x[0])

for e in sp:
    print(e[2])
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
s=list(map(int,input().split()))

s.sort()
term=[]

for i in range(m-1):
    term.append(s[i+1]-s[i])

term.sort()

for i in range(n-1):
    del term[-1]

print(sum(term))

Fixed submission:
n,m=map(int,input().split())
s=list(map(int,input().split()))

s.sort()
term=[]
if n >= m:
    print(0)
else:
    for i in range(m-1):
        term.append(s[i+1]-s[i])

    term.sort()

    for i in range(n-1):
        del term[-1]
    
    print(sum(term))
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=list(map(int,input().split()))
ex=0
va=0
t=[]
for i in s:
    if i in t:
        ex=1-ex
    else:
        t.append(i)
        va+=1

print(va-ex)

Fixed submission:
import collections
n=int(input())
s=list(map(int,input().split()))
k=len(collections.Counter(s))
if (n-k)%2==0:
    print(k)
else:
    print(k-1)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=list(map(int,input().split()))
ex=0
t=[]
for i in s:
    if i in t:
        ex+=1
    else:
        t.append(i)

if ex%2==0:
    print(len(t))
else:
    print(len(t)-1)

Fixed submission:
import collections
n=int(input())
s=list(map(int,input().split()))
k=len(collections.Counter(s))
if (n-k)%2==0:
    print(k)
else:
    print(k-1)
Buggy python submission (verdict: Runtime Error):
n,a,b=map(int,input().split())
s=list(map(int,input().split())
t=0
for i in range(n-1):
	t+=min(b,a*(s[i+1]-s[i]))

print(t)

Fixed submission:
n,a,b=map(int,input().split())
s=list(map(int,input().split()))
t=0

for i in range(n-1):
	t+=min(b,a*(s[i+1]-s[i]))

print(t)
Buggy python submission (verdict: Runtime Error):
x, a = map(input()).split()

if x<a:
  print('10')
else:
  print('0')
  

Fixed submission:
x,a = map(int,input().split())
if x<a:
    print('0')
else:
    print('10')

Buggy python submission (verdict: Runtime Error):
X, A = int(input()).split()

if X > A:
  print 0
elif !(X<A):
  print 10

Fixed submission:
x,a = map(int,input().split())
if x<a:
    print('0')
else:
    print('10')
Buggy python submission (verdict: Runtime Error):
from functools import lru_cache


N, M = map(int, input().split())
a = [int(input()) for _ in range(M)]

mod = 10 ** 9 + 7

i = 0
b = []
for ai in a:
    b.append(ai - i)
    i = ai + 1
b.append(N + 1 - i)


@lru_cache(maxsize=None)
def f(n):
    if n < 2:
        return n
    else:
        return f(n - 2) + f(n - 1)


ans = 1
for bi in b:
    ans *= f(bi) % mod
print(ans % mod)


Fixed submission:
import sys
from functools import lru_cache

sys.setrecursionlimit(1000000)

N, M = map(int, input().split())
a = [int(input()) for _ in range(M)]

mod = 10**9 + 7

i = 0
b = []
for ai in a:
    b.append(ai - i)
    i = ai + 1
b.append(N + 1 - i)


@lru_cache(maxsize=None)
def f(n):
    if n < 2:
        return n
    else:
        return f(n - 2) + f(n - 1)


ans = 1
for bi in b:
    ans *= f(bi) % mod
print(ans % mod)

Buggy python submission (verdict: Runtime Error):
from functools import lru_cache


N, M = map(int, input().split())
a = [int(input()) for _ in range(M)]

mod = 10 ** 9 + 7

i = 0
b = []
for ai in a:
    b.append(ai - i)
    i = ai + 1
b.append(N + 1 - i)


@lru_cache(maxsize=None)
def f(n):
    if n == 0:
        return 0
    elif n == 1:
        return 1
    else:
        return f(n - 2) + f(n - 1)


ans = 1
for bi in b:
    ans *= f(bi)
print(ans % mod)


Fixed submission:
import sys
from functools import lru_cache

sys.setrecursionlimit(1000000)

N, M = map(int, input().split())
a = [int(input()) for _ in range(M)]

mod = 10**9 + 7

i = 0
b = []
for ai in a:
    b.append(ai - i)
    i = ai + 1
b.append(N + 1 - i)


@lru_cache(maxsize=None)
def f(n):
    if n < 2:
        return n
    else:
        return f(n - 2) + f(n - 1)


ans = 1
for bi in b:
    ans *= f(bi) % mod
print(ans % mod)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from itertools import product

input = sys.stdin.readline

H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]

L = [[0] * W for _ in range(H)]
R = [[0] * W for _ in range(H)]
D = [[0] * W for _ in range(H)]
U = [[0] * W for _ in range(H)]

for i, j in product(range(H), range(W)):
    if S[i][j] == '#':
        continue
    if j == 0:
        L[i][j] = 1
    else:
        L[i][j] = L[i][j - 1] + 1
    if i == 0:
        U[i][j] = 1
    else:
        U[i][j] = U[i - 1][j] + 1

for i, j in product(range(H), range(W - 1, -1, -1)):
    if S[i][j] == '#':
        continue
    if j == W - 1:
        R[i][j] = 1
    else:
        R[i][j] = R[i][j + 1] + 1

for i, j in product(range(H - 1, -1, -1), range(W)):
    if S[i][j] == '#':
        continue
    if i == H - 1:
        D[i][j] = 1
    else:
        D[i][j] = D[i + 1][j] + 1

ans = 0
for i, j in product(range(H), range(W)):
    if S[i][j] == '#':
        continue
    x = L[i][j] + R[i][j] + D[i][j] + U[i][j] - 3
    ans = max(ans, x)
print(ans)


Fixed submission:
import sys
from itertools import product

input = sys.stdin.readline

H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]

L = [[0] * W for _ in range(H)]
R = [[0] * W for _ in range(H)]
D = [[0] * W for _ in range(H)]
U = [[0] * W for _ in range(H)]

for i, j in product(range(H), range(W)):
    if S[i][j] == '#':
        continue
    if j == 0:
        L[i][j] = 1
    else:
        L[i][j] = L[i][j - 1] + 1
    if i == 0:
        U[i][j] = 1
    else:
        U[i][j] = U[i - 1][j] + 1

for i, j in product(range(H), range(W - 1, -1, -1)):
    if S[i][j] == '#':
        continue
    if j == W - 1:
        R[i][j] = 1
    else:
        R[i][j] = R[i][j + 1] + 1

for i, j in product(range(H - 1, -1, -1), range(W)):
    if S[i][j] == '#':
        continue
    if i == H - 1:
        D[i][j] = 1
    else:
        D[i][j] = D[i + 1][j] + 1

ans = 0
for i, j in product(range(H), range(W)):
    if S[i][j] == '#':
        continue
    x = L[i][j] + R[i][j] + D[i][j] + U[i][j] - 3
    ans = max(ans, x)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from scipy.misc import comb

N, M, K = map(int, input().split())

mod = 10 ** 9 + 7
ans = 0
for d in range(1, N):
    ans += d * (N - d) * M**2
for d in range(1, M):
    ans += d * (M - d) * N**2
print(ans * comb(N * M - 2, K - 2, exact=True) % mod)


Fixed submission:
N, M, K = map(int, input().split())

mod = 10 ** 9 + 7


class comb(object):
    def __init__(self, N, mod):
        self.mod = mod
        self.fac = [1] * N
        for i in range(1, N):
            self.fac[i] = (self.fac[i - 1] * i) % mod
        self.inv = [1] * N
        self.inv[N - 1] = pow(self.fac[N - 1], mod - 2, mod)
        for i in range(N - 1, 0, -1):
            self.inv[i - 1] = (self.inv[i] * i) % mod

    def calc(self, n, k):
        return self.fac[n] * (self.inv[k] * self.inv[n - k] %
                              self.mod) % self.mod


ans = 0
for d in range(1, N):
    ans += d * (N - d) * M**2
for d in range(1, M):
    ans += d * (M - d) * N**2
ans *= comb(N * M, mod).calc(N * M - 2, K - 2)
print(ans % mod)
Buggy python submission (verdict: Runtime Error):
from fractions import gcd
from functools import reduce

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

memo = set()


def __gcd(a, b):
    if (a, b) in memo:
        return memo[a, b]
    else:
        if a < b:
            a, b = b, a
        memo.add((a, b))
        return gcd(a, b)


def _gcd(*A):
    return reduce(__gcd, A)


ans = 0
for i in range(N):
    B = A[:i] + A[i + 1:]
    x = _gcd(*B)
    ans = max(ans, x)
print(ans)


Fixed submission:
from fractions import gcd

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

L = [0] * (N + 1)
R = [0] * (N + 1)
for i in range(N):
    L[i + 1] = gcd(L[i], A[i])
for i in range(N - 1, 0, -1):
    R[i] = gcd(R[i + 1], A[i])

ans = 0
for i in range(N):
    ans = max(ans, gcd(L[i], R[i + 1]))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
from functools import reduce

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


def _gcd(*A):
    return reduce(gcd, A)


ans = 0
for i in range(N):
    B = A[:i] + A[i + 1:]
    x = _gcd(*B)
    ans = max(ans, x)
print(ans)


Fixed submission:
from fractions import gcd

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

L = [0] * (N + 1)
R = [0] * (N + 1)
for i in range(N):
    L[i + 1] = gcd(L[i], A[i])
for i in range(N - 1, 0, -1):
    R[i] = gcd(R[i + 1], A[i])

ans = 0
for i in range(N):
    ans = max(ans, gcd(L[i], R[i + 1]))
print(ans)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = [int(x) for x in input().split()]

f = {
    1: 2,
    2: 5,
    3: 5,
    4: 4,
    5: 5,
    6: 6,
    7: 3,
    8: 7,
    9: 6
}
A = sorted(A, reverse=True)

dp = [float('-inf')] * (N + 1)
dp[0] = 0
for i in range(N + 1):
    for a in A:
        if i - f[a] >= 0:
            dp[i] = max(dp[i], dp[i - f[a]] + 1)

ans = ''
num, digit = N, dp[N]
while num > 0:
    for a in A:
        if dp[num - f[a]] == digit - 1:
            ans += str(a)
            num -= f[a]
            digit -= 1
            break
print(ans)


Fixed submission:
N, M = map(int, input().split())
A = [int(x) for x in input().split()]

f = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6}
A = sorted(A, reverse=True)

dp = [float('-inf')] * (N + 1)
dp[0] = 0
for i in range(N + 1):
    for a in A:
        if i - f[a] >= 0:
            dp[i] = max(dp[i], dp[i - f[a]] + 1)

ans = ''
num, digit = N, dp[N]
while num > 0:
    for a in A:
        i = num - f[a]
        if i >= 0 and dp[i] == digit - 1:
            ans += str(a)
            num -= f[a]
            digit -= 1
            break
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = [int(x) for x in input().split()]

res = 0
for d in range(50, -2, -1):
    # (d + 1)桁目のKの値が 0 ならスキップ
    # 1桁目（d == -1）のときはスキップしない
    if d != -1 and not (K & (1 << d)):
        continue

    tmp = 0
    for e in range(50, -1, -1):
        mask = 1 << e

        # (e + 1)桁目のAの値が 1 であるものをカウント
        num = 0
        for i in range(N):
            if A[i] & mask:
                num += 1

        if e > d:
            if K & mask:
                tmp += mask * (N - num)
            else:
                tmp += mask * num
        elif e == d:
            tmp += mask * num
        else:
            tmp += mask * max(num, N - num)
    res = max(res, tmp)
print(res)


Fixed submission:
N, K = map(int, input().split())
A = [int(x) for x in input().split()]

# (e + 1)桁目のAの値が 1 であるものをカウント
num = [0] * 41
for e in range(40, -1, -1):
    mask = 1 << e
    for a in A:
        if a & mask:
            num[e] += 1

res = 0
for d in range(40, -2, -1):
    # (d + 1)桁目のKの値が 0 ならスキップ
    # 1桁目（d == -1）のときはスキップしない
    if d != -1 and not (K & (1 << d)):
        continue

    tmp = 0
    for e in range(40, -1, -1):
        mask = 1 << e
        if e > d:
            if K & mask:
                tmp += mask * (N - num[e])
            else:
                tmp += mask * num[e]
        elif e == d:
            tmp += mask * num[e]
        else:
            tmp += mask * max(num[e], N - num[e])
    res = max(res, tmp)
print(res)