Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

import math


def lcm(x, y):
    return (x * y) // math.gcd(x, y)


def divisors(num):
    if num < 1:
        return []
    elif num == 1:
        return [1]
    else:
        divisor_list = []
        divisor_list.append(1)
        for i in range(2, num // 2 + 1):
            if num % i == 0:
                divisor_list.append(i)
        divisor_list.append(num)

        return divisor_list


if __name__ == '__main__':
    N, M = map(int, input().split(' '))
    S = input()
    T = input()

    L = lcm(N, M)

    m = max(N, M)
    m_divisors = divisors(m)
    m_divisors.remove(1)

    S = S * int(math.ceil(m / N))
    T = T * int(math.ceil(m / M))

    for i in [d - 1 for d in m_divisors]:
        if S[i] == T[i]:
            print(-1)
            exit(0)
    print(L)


Fixed submission:
# -*- coding: utf-8 -*-

import math
import fractions


def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


if __name__ == '__main__':
    N, M = map(int, input().split(' '))
    S = input()
    T = input()

    L = lcm(N, M)

    S_index_X = [int(i * L / N) for i in range(N)]
    T_index_X = [int(i * L / M) for i in range(M)]

    common_index = set(S_index_X).intersection(set(T_index_X))
    for i in common_index:
        si = int(i * N / L)
        ti = int(i * M / L)
        if S[si] != T[ti]:
            print(-1)
            exit(0)
    print(L)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
import collections

def search_b(a_char, a_count, b_most_common, fixed_count):
  thres = fixed_count - a_count
  for (b_char, b_count) in [b for b in b_most_common if b[1] > thres]:
    if a_char != b_char:
      return a_count + b_count
  
  return fixed_count


def search(a_most_common, b_most_common):
  fixed_count = -1
  for (a_char, a_count) in a_most_common:
    fixed_count = search_b(a_char, a_count, b_most_common, fixed_count)
  
  return fixed_count


def main():
  n = int(input())
  V = list(map(int, input().split()))

  a = V[::2]
  b = V[1::2]
  
  a_counter = collections.Counter(a)
  b_counter = collections.Counter(b)

  a_most_common = a_counter.most_common()
  b_most_common = b_counter.most_common()

  if len(a_most_common) == 1 and len(b_most_common) == 1 and a_most_common[0][0] == b_most_common[0][0]:
    print(n // 2)
    return

  print(n - search(a_most_common, b_most_common))


if __name__ == '__main__':
  main()


Fixed submission:
# -*- coding: utf-8 -*-
import collections

def search_b(a_char, a_count, b_most_common, fixed_count):
  thres = fixed_count - a_count
  for (b_char, b_count) in [b for b in b_most_common if b[1] > thres]:
    if a_char != b_char:
      return a_count + b_count
  
  return fixed_count


def search(a_most_common, b_most_common):
  fixed_count = -1
  b_max = b_most_common[0][1]

  for (a_char, a_count) in a_most_common:
    if a_count <= fixed_count - b_max:
      break

    fixed_count = search_b(a_char, a_count, b_most_common, fixed_count)
  
  return fixed_count


def main():
  n = int(input())
  V = list(map(int, input().split()))

  a = V[::2]
  b = V[1::2]
  
  a_counter = collections.Counter(a)
  b_counter = collections.Counter(b)

  a_most_common = a_counter.most_common()
  b_most_common = b_counter.most_common()

  if len(a_most_common) == 1 and len(b_most_common) == 1 and a_most_common[0][0] == b_most_common[0][0]:
    print(n // 2)
    return

  print(n - search(a_most_common, b_most_common))


if __name__ == '__main__':
  main()
Buggy python submission (verdict: Runtime Error):
# n=int(input())
n,k=list(map(int,input().split(" ")))
a=list(map(int,input().split(" ")))
a.sort()
m=(10**9)+7
mat=[[(1,1) for i in range(k+1)] for j in range(n+1)]
for j in range(1,k+1):
	for i in range(1,n+1):
		# i=i1-1
		if(j==1):
			if(i==1 and a[0]>0):
				x=1
				
			elif(i>0 and a[i-1]>0 ):
				x=mat[i-1][j][0]+1
				
			elif(i>0 and a[i-1]==0):
				x=mat[i-1][j][0]
				
		else:
			start=j-a[i-1]
			start=max(start,0)
			if(start==0):
				x=mat[i-1][j][1]
				
			else:
				x=mat[i-1][j][1]-mat[i-1][start-1][1]
		mat[i][j]=(x%m,(mat[i][j-1][1]+x)%m)
		# mat[i][j]=mat[i][j]%m
# print(mat)			

print(mat[n][k][0])

Fixed submission:
n=int(input())
l=list(map(int,input().split(" ")))
f=[0]*n
f[1]=abs(l[1]-l[0])

for i in range(2,n):
	x1=f[i-1]+abs(l[i-1]-l[i])
	x2=f[i-2]+abs(l[i-2]-l[i])
	f[i]=min(x1,x2)
print(f[-1])
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
p=list(map(float,input().split(" ")))
mat=[]

for i in range(n):
	temp=[0]*(i+1+1)
	if(i==0):
		temp[0]=1-p[0]
		temp[1]=p[0]
	else:
		prev=mat[-1]

		for j in range(len(prev)):
			temp[j]+=prev[j]*(1-p[i])
			temp[j+1]+=prev[j]*p[i]


	mat.append(temp)
ans=0
temp=mat[-1]
for i in range((n//2)+1,len(temp)):
	ans+=temp[i]
# print(temp)
print(ans)

Fixed submission:
n=int(input())
p=list(map(float,input().split(" ")))
mat=[]

for i in range(n):
	temp=[0]*(i+1+1)
	if(i==0):
		temp[0]=1-p[0]
		temp[1]=p[0]
	else:
		prev=mat[-1]

		for j in range(len(prev)):
			temp[j]+=prev[j]*(1-p[i])
			temp[j+1]+=prev[j]*p[i]


	mat.append(temp)
ans=0
temp=mat[-1]
for i in range((n//2)+1,len(temp)):
	ans+=temp[i]
# print(temp)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

MOD = 998244353
n,m,k = MI()

s = [1]
for i in range(2, n):
    s.append(s[-1]*i%MOD)
if m == 1 and k < n-1:
    print(0)
    exit(0)
elif m == 1 and k == n-1:
    print(1)
    exit(0)
ans = m*pow(m-1, n-1, MOD)%MOD
for i in range(1, k+1):
    tmp = m*pow(m-1, n-1-i, MOD)*s[n-2]*pow(s[n-2-i], MOD-2, MOD)*pow(s[i-1], MOD-2, MOD)
    ans += tmp
    ans %= MOD
print(ans)


Fixed submission:
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

MOD = 998244353
n,m,k = MI()

s = [1]
for i in range(2, n):
    s.append(s[-1]*i%MOD)
if m == 1 and k < n-1:
    print(0)
    exit(0)
elif m == 1 and k == n-1:
    print(1)
    exit(0)
elif k == n-1:
    print(pow(m, n, MOD))
    exit(0)
ans = m*pow(m-1, n-1, MOD)%MOD
for i in range(1, k+1):
    tmp = m*pow(m-1, n-1-i, MOD)*s[n-2]*pow(s[n-2-i], MOD-2, MOD)*pow(s[i-1], MOD-2, MOD)
    ans += tmp
    ans %= MOD
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
am = max(a)
ans = 0
for i in range(n-1):
    for j in range(i+a[i], min(n, i+a[i]+am+1)):
        if j-i == a[i]+a[j]:
            ans += 1
print(ans)


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

ans = 0
L = {}
R = {}
for i in range(n):
    if i+a[i] in L:
        L[i+a[i]].append(i)
    else:
        L[i+a[i]] = [i]
    if i-a[i] in R:
        R[i-a[i]].append(i)
    else:
        R[i-a[i]] = [i]
for i in range(n):
    if i in L and i in R:
        ans += len(L[i])*len(R[i])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
ans = 0
for i in range(n-1):
    for j in range(i+a[i], n):
        if j-i == a[i]+a[j]:
            ans += 1
print(ans)


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

ans = 0
L = {}
R = {}
for i in range(n):
    if i+a[i] in L:
        L[i+a[i]].append(i)
    else:
        L[i+a[i]] = [i]
    if i-a[i] in R:
        R[i-a[i]].append(i)
    else:
        R[i-a[i]] = [i]
for i in range(n):
    if i in L and i in R:
        ans += len(L[i])*len(R[i])
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
k = int(input())
ans = 0
for i in range(1, k+1):
    for j in range(1, k+1):
        for y in range(1, k+1):
            ans += gcd(gcd(i,j), y)
print(ans)


Fixed submission:
from math import gcd
k = int(input())
ans = 0
for i in range(1, k+1):
    for j in range(1, k+1):
        for y in range(1, k+1):
            ans += gcd(gcd(i,j), y)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
cnt = 0
for _ in range(q):
    t = input()
    if t[0] == '1':
        cnt += 1
    elif t[2] == '1':
        if cnt%2 == 0:
            s = t[4] + s
        else:
            s = s + t[4]
    else:
        if cnt%2 == 0:
            s = s + t[4]
        else:
            s = t[4] + s
if cnt%2 == 1:
    s = s[::-1]
print(s)


Fixed submission:
s = input()
q = int(input())
cnt = 0
front = ''
rear = ''
for _ in range(q):
    t = input()
    if t[0] == '1':
        cnt += 1
    elif t[2] == '1':
        if cnt%2 == 1:
            rear = rear + t[4]
        else:
            front = front + t[4]
    else:
        if cnt%2 == 1:
            front = front + t[4]
        else:
            rear = rear + t[4]
if cnt%2 == 1:
    s = (front[::-1] + s + rear)[::-1]
else:
    s = front[::-1] + s + rear
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
for _ in range(q):
    t = input()
    if t[0] == '1':
        s = s[::-1]
    elif t[2] == '1':
        s = t[4] + s
    else:
        s = s + t[4]
print(s)


Fixed submission:
s = input()
q = int(input())
cnt = 0
front = ''
rear = ''
for _ in range(q):
    t = input()
    if t[0] == '1':
        cnt += 1
    elif t[2] == '1':
        if cnt%2 == 1:
            rear = rear + t[4]
        else:
            front = front + t[4]
    else:
        if cnt%2 == 1:
            front = front + t[4]
        else:
            rear = rear + t[4]
if cnt%2 == 1:
    s = (front[::-1] + s + rear)[::-1]
else:
    s = front[::-1] + s + rear
print(s)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
r = []
for _ in range(n):
    r.append(list(map(int,input().split())))
r.sort()
i = 0
while i <= len(r)-2:
    if r[i][0] + r[i][1] > r[i+1][0] - r[i+1][1]:
        r = r[:i+1] + r[i+2:]
    else:
        i += 1
print(len(r))


Fixed submission:
n = int(input())
r = []
for _ in range(n):
    x,l = map(int,input().split())
    r.append([x+l, x-l])
r.sort()
tmp = r[0]
cnt = 0
for i in range(1, n):
    if r[i][1] < tmp[0]:
        cnt += 1
    else:
        tmp = r[i]
print(n-cnt)
Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
d = {}
a = []
b = 0
c = 0
for _ in range(m):
    p, s = input().split()
    a.append([p, s])
for i in range(m):
    if a[i][0] in d:
        continue
    else:
        if a[i][1] == 'WA':
            if [a[i][0], 'AC'] in a:
                b += 1
        else:
            d[a[i][0]] = 'AC'
            c += 1
print(c, b)


Fixed submission:
n,m = map(int,input().split())
d = {}
e = {}
a = 0
b = 0
for _ in range(m):
    p, s = input().split()
    if p in d:
        continue
    else:
        if s == 'WA':
            if p in e:
                e[p] += 1
            else:
                e[p] = 1
        else:
            d[p] = 'AC'
            a += 1
            if p in e:
                b += e[p]
print(a,b)
Buggy python submission (verdict: Runtime Error):
from math import gcd
a,b=map(int,input().split())
print(a*b//gcd(a,b))

Fixed submission:
def gcd(a,b):
    if b == 0:
        return a
    elif a<b:
        return gcd(b,a)
    else:
        return gcd(b, a % b)
a,b=map(int,input().split())
print(a*b//gcd(a,b))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
i = 0
while 1:
    if i >= len(a):
        break
    if a[i] != i+1:
        a.pop(i)
    else:
        i += 1
if len(a) == 0:
    print(-1)
else:
    print(n-len(a))

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
i = 0
j = 0
c = 0
while 1:
    if j >= len(a):
        break
    if a[j] != i+1:
        j += 1
        c += 1
    else:
        j += 1
        i += 1
if len(a) == c:
    print(-1)
else:
    print(c)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
i = 0
while 1:
    if i >= len(a):
        break
    if a[i] != i+1:
        a.remove(a[i])
    else:
        i += 1
if len(a) == 0:
    print(-1)
else:
    print(n-len(a))

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
i = 0
j = 0
c = 0
while 1:
    if j >= len(a):
        break
    if a[j] != i+1:
        j += 1
        c += 1
    else:
        j += 1
        i += 1
if len(a) == c:
    print(-1)
else:
    print(c)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
 
output = 1
if a[0] != 0:
    print(0)
elif max(a) == 1:
    print(1)
else:
    for i in range(2, max(a)+1):
        output *= pow(a.count(i-1),a.count(i),998244353)
        output %= 998244353
    print(output)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
cnt = [0]*n
for i in a:
    cnt[i] += 1

output = 1
if a[0] != 0 or cnt[0] != 1:
    print(0)
elif max(a) == 1:
    print(1)
else:
    for i in range(2, n):
        output *= cnt[i-1]**cnt[i]
        output %= 998244353
    print(output)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
 
output = 1
if a[0] != 0:
    print(0)
elif max(a) == 1:
    print(1)
else:
    for i in range(2, max(a)+1):
        if a.count(i) != 0:
            output *= pow(a.count(i-1), a.count(i), 998244353)
            output %= 998244353
    print(output)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
cnt = [0]*n
for i in a:
    cnt[i] += 1

output = 1
if a[0] != 0 or cnt[0] != 1:
    print(0)
elif max(a) == 1:
    print(1)
else:
    for i in range(2, n):
        output *= cnt[i-1]**cnt[i]
        output %= 998244353
    print(output)

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))
 
output = 1
if a[0] != 0:
    print(0)
elif max(a) == 1:
    print(1)
else:
    for i in range(2, max(a)+1):
        if a.count(i) != 0
            output *= pow(a.count(i-1), a.count(i), 998244353)
    print(output)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
cnt = [0]*n
for i in a:
    cnt[i] += 1

output = 1
if a[0] != 0 or cnt[0] != 1:
    print(0)
elif max(a) == 1:
    print(1)
else:
    for i in range(2, n):
        output *= cnt[i-1]**cnt[i]
        output %= 998244353
    print(output)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))

output = 1
if a[0] != 0:
    print(0)
elif max(a) == 1:
    print(1)
else:
    for i in range(2, max(a)+1):
        if a.count(i) != 0:
            output *= a.count(i-1)**a.count(i)
            output %= 998244353
    print(output)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
cnt = [0]*n
for i in a:
    cnt[i] += 1

output = 1
if a[0] != 0 or cnt[0] != 1:
    print(0)
elif max(a) == 1:
    print(1)
else:
    for i in range(2, n):
        output *= cnt[i-1]**cnt[i]
        output %= 998244353
    print(output)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

ab = [[a[i], b[i]] for i in range(n)]
ab.sort(key=lambda x:x[1])

a = [ab[i][0] for i in range(n)]
b = [ab[i][1] for i in range(n)]

a2 = [[a[i], i] for i in range(n)]
a2.sort(key=lambda x:x[0])

flag1 = 0
for i in range(n):
    if a2[i][0] > b[i]:
        flag1 = 1

flag2 = 1
idx = a2[0][1]
cnt = 0
while idx != 0:
    idx = a2[idx][1]
    cnt += 1

if cnt == n-1:
    for i in range(n-1):
        if a2[i+1] <= b[i]:
            flag2=0
            break
else:
    flag2 = 0

if flag1 == 1 or flag2 == 1:
    print('No')
else:
    print('Yes')

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

ab = [[a[i], b[i]] for i in range(n)]
ab.sort(key=lambda x:x[1])

a = [ab[i][0] for i in range(n)]
b = [ab[i][1] for i in range(n)]

a2 = [[a[i], i] for i in range(n)]
a2.sort(key=lambda x:x[0])

flag1 = 0
for i in range(n):
    if a2[i][0] > b[i]:
        flag1 = 1

flag2 = 1
idx = a2[0][1]
cnt = 0
while idx != 0:
    idx = a2[idx][1]
    cnt += 1

if cnt == n-1:
    for i in range(n-1):
        if a2[i+1][0] <= b[i]:
            flag2=0
            break
else:
    flag2 = 0

if flag1 == 1 or flag2 == 1:
    print('No')
else:
    print('Yes')
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = input().split()
output = ''
for i in range(1, n+1):
    output += str(a.index(str(i))+1)
    output += ' '
print(output)

Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]
b = [0]*n
output = ''
for i in range(n):
    b[a[i]-1] = i+1
for i in range(n):
    output += str(b[i]) + ' '
print(output)
Buggy python submission (verdict: Time Limit Exceeded):
import math

a, b = map(int, input().split())
fa = []
fb = []

tmp = a//2 + 1
for i in range(2,tmp):
    while a % i == 0:
        a //= i
        fa.append(i)
fa.append(a)

tmp = b//2 + 1
for i in range(2,tmp):
    while b % i == 0:
        b //= i
        fb.append(i)
fb.append(b)

print(len(list(set(fa) & set(fb))))

Fixed submission:
import math

a, b = map(int, input().split())
fa = []
fb = []

tmp = int(math.sqrt(a)) + 1
for i in range(2,tmp):
    while a % i == 0:
        a //= i
        fa.append(i)
if a != 1:
    fa.append(a)

tmp = int(math.sqrt(b)) + 1
for i in range(2,tmp):
    while b % i == 0:
        b //= i
        fb.append(i)
if b != 1:
    fb.append(b)

print(len(list(set(fa) & set(fb))) + 1)
Buggy python submission (verdict: Runtime Error):
from math import gcd
a,b,c,d = map(int,input().split())
g = c*d//gcd(c, d)
print(b-a+1 - b//c-b//d+b//g + (a-1)//c+(a-1)//d-(a-1)//g)


Fixed submission:
from fractions import gcd
a,b,c,d = map(int,input().split())
g = c*d//gcd(c, d)
print(b-a+1 - b//c-b//d+b//g + (a-1)//c+(a-1)//d-(a-1)//g)
Buggy python submission (verdict: Runtime Error):
MOD = 10**9+7
n,m = map(int,input().split())

f = [1,1]
for i in range(2, n):
    f.append(f[i-2]+f[i-1])

cur = 0
ans = 1
for i in range(m):
    a = int(input())
    if a==cur:
        print(0)
        exit(0)
    ans *= f[a-cur-1]
    ans %= MOD
    cur = a+1
ans *= f[n-cur]
ans %= MOD
print(ans)


Fixed submission:
MOD = 10**9+7
n,m = map(int,input().split())

f = [1,1]
for i in range(2, n+1):
    f.append(f[i-2]+f[i-1])

cur = 0
ans = 1
for i in range(m):
    a = int(input())
    if a==cur:
        print(0)
        break
    ans *= f[a-cur-1]
    ans %= MOD
    cur = a+1
else:
    ans *= f[n-cur]
    ans %= MOD
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
a = [0]*3
a[0],a[1],a[2],n = map(int,input().split())
a.sort()
cnt = 0
for i in range(n//a[2]+1):
    for j in range(n//a[1]+1):
        d = n-a[2]*i-a[1]*j
        if d%a[0] == 0 and d >= 0:
            cnt += 1
print(cnt)


Fixed submission:
a = [0]*3
a[0],a[1],a[2],n = map(int,input().split())
a.sort()
cnt = 0
for i in range(n//a[2]+1):
    for j in range((n-i*a[2])//a[1]+1):
        d = n-a[2]*i-a[1]*j
        if d%a[0] == 0 and d >= 0:
            cnt += 1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
a = [0]*3
a[0],a[1],a[2],n = map(int,input().split())
a.sort()
cnt = 0
for i in range(n//a[2]+1):
    for j in range(n//a[1]+1):
        if (n-a[2]*i-a[1]*j)%a[0] == 0 and (n-a[2]*i-a[1]*j) >= 0:
            cnt += 1
print(cnt)


Fixed submission:
a = [0]*3
a[0],a[1],a[2],n = map(int,input().split())
a.sort()
cnt = 0
for i in range(n//a[2]+1):
    for j in range((n-i*a[2])//a[1]+1):
        d = n-a[2]*i-a[1]*j
        if d%a[0] == 0 and d >= 0:
            cnt += 1
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().split())
S = input()
for _ in range(Q):
    l,r = map(int,input().split())
    print(S[l-1:r].count('AC'))


Fixed submission:
N,Q = map(int,input().split())
S = input()
s = [0]
cnt = 0
for i in range(N-1):
    if S[i:i+2] == 'AC':
        cnt += 1
    s.append(cnt)
for _ in range(Q):
    l,r = map(int,input().split())
    print(s[r-1]-s[l-1])
Buggy python submission (verdict: Runtime Error):
from math import gcd
n, x = map(int,input().split())
p = list(map(lambda s: abs(s-x), list(map(int,input().split()))))
g = p[0]
for i in p:
    g = gcd(g, i)
print(g)


Fixed submission:
from fractions import gcd
n, x = map(int,input().split())
p = list(map(lambda s: abs(s-x), list(map(int,input().split()))))
g = p[0]
for i in p:
    g = gcd(g, i)
print(g)
Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_right
n = int(input())
a = sorted(map(int, input().split()))
b = sorted(map(int, input().split()))
c = sorted(map(int, input().split()))
cnt = 0
bn = []
for i in range(n):
    x2 = bisect_right(c, b[i])
    bn.append(n-x2)
for i in range(n):
    x1 = bisect_right(b, a[i])
    cnt += sum(bn[x1:])
print(cnt)

Fixed submission:
from bisect import bisect_right
from bisect import bisect_left

n = int(input())
a = sorted(map(int, input().split()))
b = sorted(map(int, input().split()))
c = sorted(map(int, input().split()))
cnt = 0
bn = []
for i in range(n):
    x1 = bisect_left(a, b[i])
    x2 = bisect_right(c, b[i])
    cnt += x1*(n-x2)
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_right
n = int(input())
a = sorted(map(int, input().split()))
b = sorted(map(int, input().split()))
c = sorted(map(int, input().split()))
cnt = 0
for i in range(n):
    x1 = bisect_right(b, a[i])
    for j in range(x1, n):
        cnt += (n-bisect_right(c, b[j]))
print(cnt)

Fixed submission:
from bisect import bisect_right
from bisect import bisect_left

n = int(input())
a = sorted(map(int, input().split()))
b = sorted(map(int, input().split()))
c = sorted(map(int, input().split()))
cnt = 0
bn = []
for i in range(n):
    x1 = bisect_left(a, b[i])
    x2 = bisect_right(c, b[i])
    cnt += x1*(n-x2)
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
sa = sum(a)
m = 10**10
for i in range(1,n):
    m = min(m, abs(sa-2*sum(a[:i])))
print(m)


Fixed submission:
n = int(input())
a = list(map(int,input().split()))
sa = sum(a)
x = a[0]
m = abs(sa-2*x)
for i in range(1,n-1):
    x += a[i]
    m = min(m, abs(sa-2*x))
print(m)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
m = 10**10
for i in range(1,n):
    m = min(m, abs(sum(a[:i])-sum(a[i:])))
print(m)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
sa = sum(a)
x = a[0]
m = abs(sa-2*x)
for i in range(1,n-1):
    x += a[i]
    m = min(m, abs(sa-2*x))
print(m)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
b = []
for i in range(n):
    if i % 2 == 0:
        b.append(a[i])
    else:
        b = [a[i]] + b
if n % 2 == 1:
    b.reverse()
print(' '.join(map(str, b)))


Fixed submission:
from collections import deque

n = int(input())
a = list(map(int,input().split()))
b = deque()
for i in range(n):
    if i % 2 == 0:
        b.append(a[i])
    else:
        b.appendleft(a[i])
if n % 2 == 1:
    b.reverse()
print(' '.join(map(str, b)))