Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
ans = S.count("R")*S.count("G")*S.count("B")

for i in range(N):
  for j in range(i+1,N):
      k = 2*j-i
      if k<=j:
        continue
      if N>k and S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
          ans-=1
          
print(ans)

Fixed submission:
N = int(input())
S = input()
ans = S.count("R")*S.count("G")*S.count("B")

for i in range(N-2):
  for j in range(i+1,N-1):
      k = 2*j-i
      if k>=N:
        break
      if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
        ans-=1
          
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
ans = S.count("R")*S.count("G")*S.count("B")

for i in range(N-2):
  for j in range(i+1,N-1):
      k = 2*j-i
      if k<=j:
        continue
      else:
        if N>k and S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
          ans-=1
          
print(ans)

Fixed submission:
N = int(input())
S = input()
ans = S.count("R")*S.count("G")*S.count("B")

for i in range(N-2):
  for j in range(i+1,N-1):
      k = 2*j-i
      if k>=N:
        break
      if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
        ans-=1
          
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
count = 0

for i in range(N):
  for j in range(i+1,N):
    for k in range (j+1,N):
      if j-i == k-j:
        continue
      else:
        if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
          count+=1
          
print(count)

Fixed submission:
N = int(input())
S = input()
ans = S.count("R")*S.count("G")*S.count("B")

for i in range(N-2):
  for j in range(i+1,N-1):
      k = 2*j-i
      if k>=N:
        break
      if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
        ans-=1
          
print(ans)
Buggy python submission (verdict: Runtime Error):
K, N = map(int, input().split())
lst = list(map(int, input().split()))

dist = lst[-1]-lst[0]
for i in range(N-1):
    dist = min(dist, K-lst[i+1]+lst[i])
print(dist)

Fixed submission:
S = input()
if S[2]==S[3] and S[4]==S[5]:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Time Limit Exceeded):
import math
ans=0
i = int(input())
for a in range(1,i+1):
  for b in range(1,i+1):
    for c in range(1,i+1):
      n=math.gcd(math.gcd(a,b),c)
      ans+=n
print(ans)
      

Fixed submission:
from math import gcd
ans=0
i = int(input())
for a in range(1,i+1):
  for b in range(1,i+1):
    for c in range(1,i+1):
      n=gcd(gcd(a,b),c)
      ans+=n
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import math

n = int(input())
y = 0

for i in range(n):
  for j in range(n):
    for k in range(n):
      y_ = math.gcd(math.gcd(i+1, j+1), k+1)
      y += y_
 
print(y)

Fixed submission:
import math
import numpy as np
import numba
import math

n = int(input())

@numba.jit
def main(n):
  lis = np.zeros((n, n, n))
  for i in range(n):
    for j in range(n):
      for k in range(n):
        lis[i][j][k] = math.gcd(math.gcd(i+1, j+1), k+1)
  return int(np.sum(lis))

print(main(n))

Buggy python submission (verdict: Time Limit Exceeded):
import math

n = int(input())
y = 0

for i in range(n):
  for j in range(n):
    for k in range(n):
      i_ = i + 1
      j_ = j + 1
      k_ = k + 1
      y_ = math.gcd(math.gcd(i_, j_), k_)
      y += y_
 
print(y)

Fixed submission:
import math
import numpy as np
import numba
import math

n = int(input())

@numba.jit
def main(n):
  lis = np.zeros((n, n, n))
  for i in range(n):
    for j in range(n):
      for k in range(n):
        lis[i][j][k] = math.gcd(math.gcd(i+1, j+1), k+1)
  return int(np.sum(lis))

print(main(n))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
y = 0

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

for i in range(n):
  for j in range(n):
    for k in range(n):
      i_ = i + 1
      j_ = j + 1
      k_ = k + 1
      y_ = gcd(gcd(i_, j_), k_)
      y += y_
 
print(y)

Fixed submission:
import math
import numpy as np
import numba
import math

n = int(input())

@numba.jit
def main(n):
  lis = np.zeros((n, n, n))
  for i in range(n):
    for j in range(n):
      for k in range(n):
        lis[i][j][k] = math.gcd(math.gcd(i+1, j+1), k+1)
  return int(np.sum(lis))

print(main(n))
Buggy python submission (verdict: Runtime Error):
L = []
for _ in range(5):
    n = int(input())
    L.append([n%10, n])

L.sort()
l = 0
for i in range(5):
    if L[i][0] != 0:
        la = L[i][1]
        l = i
        break

tot = 0
for i in range(5):
    if i != l:
        if L[i][1] % 10 != 0:
            k = L[i][1]//10 + 1
        else:
            k = L[i][1]//10
        tot += k*10
tot += la
print(tot)


Fixed submission:
tot = 0
m = 0
for i in range(5):
    s = int(input())
    if s % 10 == 0:
        rem = 0
    else:
        rem = s%10 - 10
        s = 10*(s//10 + 1)
    m = min(m, rem)
    tot += s

print(tot+m)

Buggy python submission (verdict: Runtime Error):
L = []
for _ in range(5):
    n = int(input())
    L.append([n%10, n])

L.sort()
for i in range(5):
    if L[i][0] != 0:
        la = L[i][1]
        l = i
        break

tot = 0
for i in range(5):
    if i != l:
        if L[i][1] % 10 != 0:
            k = L[i][1]//10 + 1
        else:
            k = L[i][1]//10
        tot += k*10
tot += la
print(tot)


Fixed submission:
tot = 0
m = 0
for i in range(5):
    s = int(input())
    if s % 10 == 0:
        rem = 0
    else:
        rem = s%10 - 10
        s = 10*(s//10 + 1)
    m = min(m, rem)
    tot += s

print(tot+m)
Buggy python submission (verdict: Runtime Error):
x, y, z, k = map(int, input().split())
LA = list(map(int, input().split()))
LB = list(map(int, input().split()))
LC = list(map(int, input().split()))
LAB = []
L = []

for i in range(x):
    for j in range(y):
        LAB.append(LA[i]+LB[j])
LAB.sort(reverse=True)
LAB = LAB[:k]

for i in range(k):
    for j in range(z):
        L.append(LAB[i]+LC[j])
L.sort(reverse=True)

for i in range(k):
    print(L[i])

Fixed submission:
x, y, z, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

Q = []
Q.append([A[0]+B[0]+C[0], 0, 0, 0])
M = {(0, 0, 0):True}

def search():
    global Q
    q = Q.pop()
    a = q[1]
    b = q[2]
    c = q[3]
    if a+1 < x and (a+1, b, c) not in M:
        Q.append([A[a+1]+B[b]+C[c], a+1, b, c])
        M[(a+1, b, c)] = True
    if b+1 < y and (a, b+1, c) not in M:
        Q.append([A[a]+B[b+1]+C[c], a, b+1, c])
        M[(a, b+1, c)] = True
    if c+1 < z and (a, b, c+1) not in M:
        Q.append([A[a]+B[b]+C[c+1], a, b, c+1])
        M[(a, b, c+1)] = True
    Q.sort()
    return q[0]

for _ in range(k):
    print(search())

Buggy python submission (verdict: Time Limit Exceeded):
x, y, z, k = map(int, input().split())
Lis = []
for _ in range(3):
    L = list(map(int, input().split()))
    L.sort(reverse=True)
    Lis.append(L)

Li = [[0, 0, 0]]
def search():
    global dic
    L = []
    for a, b, c in Li:
        for d, e, f in [[1, 0, 0], [0, 1, 0], [0, 0, 1]]:
            if a+d < x and b+e < y and c+f < z and [a+d, b+e, c+f] not in Li:
                re = Lis[0][a+d] + Lis[1][b+e] + Lis[2][c+f]
                L.append([re, a+d, b+e, c+f])
    L.sort(reverse=True)
    Li.append([L[0][1], L[0][2], L[0][3]])
    return L[0][0]
    

for i in range(k):
    if i == 0:
        ans = Lis[0][0] + Lis[1][0] + Lis[2][0]
        print(ans)
    else:
        print(search())


Fixed submission:
x, y, z, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

Q = []
Q.append([A[0]+B[0]+C[0], 0, 0, 0])
M = {(0, 0, 0):True}

def search():
    global Q
    q = Q.pop()
    a = q[1]
    b = q[2]
    c = q[3]
    if a+1 < x and (a+1, b, c) not in M:
        Q.append([A[a+1]+B[b]+C[c], a+1, b, c])
        M[(a+1, b, c)] = True
    if b+1 < y and (a, b+1, c) not in M:
        Q.append([A[a]+B[b+1]+C[c], a, b+1, c])
        M[(a, b+1, c)] = True
    if c+1 < z and (a, b, c+1) not in M:
        Q.append([A[a]+B[b]+C[c+1], a, b, c+1])
        M[(a, b, c+1)] = True
    Q.sort()
    return q[0]

for _ in range(k):
    print(search())
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

H, W = map(int, input().split())
S = []
for i in [0]*H:
    l = input()
    S.append([1 if x == "#" else -1 for x in l])

bk = 0
wh = 0
def check(S, x, y):
    global bk, wh
    n = S[y][x]
    if n == 0:
        return 
    elif n == 1:
        bk += 1
    elif n == -1:
        wh += 1
    S[y][x] = 0
    if 0 < y and S[y-1][x] == -n:
        check(S, x, y-1)
    if 0 < x and S[y][x-1] == -n:
        check(S, x-1, y)
    if y < H-1 and S[y+1][x] == -n:
        check(S, x, y+1)
    if x < W-1 and S[y][x+1] == -n:
        check(S, x+1, y)
    return 

cnt = 0
for y in range(H):
    for x in range(W):
        if S[y][x] == 1:
            check(S, x, y)
            cnt += wh*bk
            wh = 0
            bk = 0
            
print(cnt)

Fixed submission:
import sys
sys.setrecursionlimit(200000)
input = sys.stdin.readline

H, W = map(int, input().split())
S = []
for i in [0]*H:
    l = input()
    S.append([1 if x == "#" else -1 for x in l])

bk = 0
wh = 0
def check(S, x, y):
    global bk, wh
    n = S[y][x]
    if n == 0:
        return 
    elif n == 1:
        bk += 1
    elif n == -1:
        wh += 1
    S[y][x] = 0
    if 0 < y and S[y-1][x] == -n:
        check(S, x, y-1)
    if 0 < x and S[y][x-1] == -n:
        check(S, x-1, y)
    if y < H-1 and S[y+1][x] == -n:
        check(S, x, y+1)
    if x < W-1 and S[y][x+1] == -n:
        check(S, x+1, y)
    return 

cnt = 0
for y in range(H):
    for x in range(W):
        if S[y][x] == 1:
            check(S, x, y)
            cnt += wh*bk
            wh = 0
            bk = 0
            
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
nums = list(map(int, input().split()))

for i in range(n):
    nums[i] -= (i + 1)
    if i == 0:
        x = y =  nums[i]
    else:
        if nums[i] < x:
            x = nums[i]
        elif y < nums[i]:
            y = nums[i]

d = 0
for i in range(x, y):
    c = 0
    for j in range(n):
        c += abs(nums[j] - i)
    else:
        if d != 0 and d < c:
            print(d)
            break
        elif d == 0 and c == 0:
            print(d)
            break
        else:
            d = c
else:
    print(d)
            
    


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

for i in range(n):
    nums[i] -= (i + 1)

nums.sort()
        
if (n-1) % 2 != 0:
    m = n//2 - 1
else:
    m = (n-1)//2
    
a = sum(nums[m+1:]) - (n-m-1)*nums[m]
b = - sum(nums[0:m+1]) + (m+1)*nums[m]

print(a+b)

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

for i in range(n):
    nums[i] -= (i + 1)
    
x = min(nums)
y = max(nums)
z = []
for i in range(x, y+1):
    c = 0
    for j in range(n):
        c += abs(nums[j] - i)
    else:
        z.append(c)

print(min(z))

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

for i in range(n):
    nums[i] -= (i + 1)

nums.sort()
        
if (n-1) % 2 != 0:
    m = n//2 - 1
else:
    m = (n-1)//2
    
a = sum(nums[m+1:]) - (n-m-1)*nums[m]
b = - sum(nums[0:m+1]) + (m+1)*nums[m]

print(a+b)
Buggy python submission (verdict: Runtime Error):
N = input()
num = list(N)
s = 0
for i in range(N):
  s += num[i]
if int(N) % s == 0:
  print(Yes)
else:
  print(No)

Fixed submission:
N = input()
num = list(N)
s = 0
for i in range(len(num)):
  s += int(num[i])
if int(N) % s == 0:
  print("Yes")
else:
  print("No")

Buggy python submission (verdict: Runtime Error):
N = int(input())
num = list(N)
s = 0
for i in range(len(num)):
  s += num[i]
if N % s == 0:
  print(Yes)
else:
  print(No)

Fixed submission:
N = input()
num = list(N)
s = 0
for i in range(len(num)):
  s += int(num[i])
if int(N) % s == 0:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split(" "))
b += int(b/100)
  pass
print(b*(100**a))

Fixed submission:
a, b = map(int, input().split(" "))
b += int(b/100)
print(b*(100**a))

Buggy python submission (verdict: Runtime Error):
a, b = map(int, input(" "))
if b == 0:
  print(a)
elif b == 1:
  print(a*100)
else:
  print(a*10000)

Fixed submission:
a, b = map(int, input().split(" "))
b += int(b/100)
print(b*(100**a))
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
input = stdin.readline

n = int(input())
re_nums = []
nums = []
A = list(map(int, input().split()))
for a in A:
    if a not in re_nums:
        re_nums.append(a)
    else:
        nums.append(a)
nums.sort(reverse=True)
l = len(nums)
ans = 0
if l < 2:
    ans = 0
else:
    l1 = nums[0]
    l2 = nums[1]
    if l2 == l1:
        if l > 3:
            if nums[2] == l2:
                ans = l1**2
            else:
                ans = l1*nums[2]
        else:
            ans = 0
    else:
        ans = l1*l2
print(ans)

Fixed submission:
from sys import stdin
input = stdin.readline

n = int(input())
dic = {}
A = list(map(int, input().split()))
for a in A:
    if a not in dic:
        dic[a] = 1
    else:
        dic[a] += 1
nums = list(dic.items())
nums.sort(reverse = True)
l = len(nums)
l1 = 0
for i in range(l):
    if l1 == 0 and nums[i][1] >= 4:
        ans = nums[i][0]**2
        break
    elif l1 == 0 and nums[i][1] >= 2:
        l1 = nums[i][0]
    elif l1 > 0 and nums[i][1] >= 2:
        ans = l1*nums[i][0]
        break
else:
    ans = 0
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
fir = []
sec = []

for _ in range(m):
    a, b = map(int, input().split())
    if a == 1:
        fir.append(b)
    elif a == n:
        sec.append(b)
    if b == 1:
        fir.append(a)
    elif b == n:
        sec.append(a)

for i in fir:
    if i in sec:
        print("POSSIBLE")
        break
else:
    print("IMPOSSIBLE")

Fixed submission:
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
fir = []
sec = []

for _ in range(m):
    a, b = map(int, input().split())
    if a == 1:
        fir.append(b)
    elif a == n:
        sec.append(b)
    if b == 1:
        fir.append(a)
    elif b == n:
        sec.append(a)
fir.sort()
sec.sort()
flag = True
for i in fir:
    j = 0
    while flag and sec:
        if i > sec[j]:
            del sec[j]
        elif i == sec[j]:
            print("POSSIBLE")
            flag = False
        else:
            break
if flag == True:
    print("IMPOSSIBLE")
Buggy python submission (verdict: Time Limit Exceeded):

N, M = map(int, input().split())
ans = 0

def func(n):
    sum = 1
    for i in range(1, n+1):
        sum *= i
    return sum % (10**9 + 7)

if abs(N - M) == 0:
    ans = 2 * func(N)*func(M)
elif abs(N - M) == 1:
    ans = func(N)*func(M)
    
print(ans % (10**9 + 7))


Fixed submission:
N, M = map(int, input().split())
ans = 0
MOD = 10**9 + 7

def func(n):
    sum = 1
    for i in range(1, n+1):
        sum = sum*i % MOD
    return sum 

if abs(N - M) == 0:
    ans = 2 * func(N)*func(M)
elif abs(N - M) == 1:
    ans = func(N)*func(M)
    
print(ans % MOD)
Buggy python submission (verdict: Runtime Error):
import math
N = int(input())
m = int(math.sqrt(N))
a = 0
ans = 0
count = 1

for i in range(m, 1, -1):
    if N % i == 0:
        a = i
        break

a = max(a, (N//a))

while True:
    if a >= 10:
        count += 1
        a = a// 10
    else:
        break
    
print(count)


Fixed submission:
import math
N = int(input())
m = int(math.sqrt(N))
a = 0
ans = 0
count = 1

for i in range(1, m+1):
    if N % i == 0:
        a = i

a = max(a, (N//a))

while True:
    if a >= 10:
        count += 1
        a = a// 10
    else:
        break
    
print(count)
Buggy python submission (verdict: Runtime Error):
import os
import sys

weather_list = ['Sunny', 'Cloudy', 'Rainy']

today_weather = sys.argv[1]

weather_index = weather_list.index(today_weather)

weather_index = weather_index+1 if len(weather_list)-1!=weather_index else 0

print(weather_list[weather_index])

Fixed submission:
import os
import sys

weather_list = ['Sunny', 'Cloudy', 'Rainy']

#today_weather = sys.argv[1]
today_weather = input()

weather_index = weather_list.index(today_weather)

weather_index = weather_index+1 if len(weather_list)-1!=weather_index else 0

print(weather_list[weather_index])
Buggy python submission (verdict: Runtime Error):
N = input()
sum = 0
for i in range(1, N+1):
    if i % 3 != 0 and i % 5 != 0:
        sum += i

print(sum)


Fixed submission:
N = int(input())
sum = 0
for i in range(1, N+1):
    if i % 3 != 0 and i % 5 != 0:
        sum += i

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

if(a*500>=X):
    print('Yes')
else:
    print('No')


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

if(a*500>=X):
    print('Yes')
else:
    print('No')

Buggy python submission (verdict: Runtime Error):
a=int(input())
X=int(input())
if(a*500>=X):
    print('Yes')
else:
    print('No')

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

if(a*500>=X):
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
#include<stdio.h>

int main(){
  
  	int N, summ, i;
  	i = 1;
  	summ = 0;
  
  	scanf("%d", &N);
  
  	while(i <= N){
    	if (N%3==0||N%5==0){
        	summ = summ;
        }
      	else{
        	summ += i;
        }
      	i++;
    }
  
  	printf("%d", summ);
	return 0;
}

Fixed submission:
n = input()
n = str(n)
count = 0
 
for i in n:
  if (i=='7'):
    count = 1
    break
    
if (count!=0):
	print("Yes")
else:
	print("No")

Buggy python submission (verdict: Runtime Error):
n = str(input())
count = 0

for i in n:
  if (i=='7'):
    count++
    break
    
if (count!=0):
	print("Yes")
else:
	print("No")

Fixed submission:
n = input()
n = str(n)
count = 0
 
for i in n:
  if (i=='7'):
    count = 1
    break
    
if (count!=0):
	print("Yes")
else:
	print("No")
Buggy python submission (verdict: Time Limit Exceeded):
from math import gcd

k = int(input())
l = [[[0] * (k + 1) for i in range(k + 1)] for j in range(k + 1)]
ans = 0
for a in range(1, k + 1):
    for b in range(1, k + 1):
        for c in range(1, k + 1):
            mn, mx = min(a, b, c), max(a, b, c)
            mi = a + b + c - mn - mx
            if l[a][b][c]:
                ans += l[a][b][c]
                continue
            else:
                ans += gcd(gcd(a, b), c)
print(ans)

Fixed submission:
from math import gcd

k = int(input())
l = [[[0] * (k + 1) for i in range(k + 1)] for j in range(k + 1)]
ans = 0
for a in range(1, k + 1):
    for b in range(1, k + 1):
        for c in range(1, k + 1):
            mn, mx = min(a, b, c), max(a, b, c)
            mi = a + b + c - mn - mx
            if l[a][b][c]:
                ans += l[a][b][c]
                continue
            else:
                ans += gcd(gcd(a, b), c)
print(ans)
Buggy python submission (verdict: Runtime Error):
import math
 
n = int(input())
a = list(map(int, input().split()))
 
b = a[0]
for i in range(n - 1):
    b = math.gcd(a[i + 1], b)
 
print(b)

Fixed submission:
def gcd(a, b):
    if a < b:
        a, b = b, a

    if b == 0:
        return a

    c = a % b
    return gcd(b, c)

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

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

print(b)

Buggy python submission (verdict: Runtime Error):
def gcd(a, b):
    if a < b:
        a, b = b, a

    if b == 0:
        return a

    c = a % b
    return gcd(b, c)

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

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

print(b)

Fixed submission:
def gcd(a, b):
    if a < b:
        a, b = b, a

    if b == 0:
        return a

    c = a % b
    return gcd(b, c)

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

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

print(b)

Buggy python submission (verdict: Runtime Error):
import math

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

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

print(b)

Fixed submission:
def gcd(a, b):
    if a < b:
        a, b = b, a

    if b == 0:
        return a

    c = a % b
    return gcd(b, c)

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

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

print(b)

Buggy python submission (verdict: Runtime Error):
import math

"""
def gcd(a, b):
    if a < b:
        a, b = b, a

    if b == 0:
        return a

    c = a % b
    return gcd(b, c)
"""

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

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

print(b)


Fixed submission:
def gcd(a, b):
    if a < b:
        a, b = b, a

    if b == 0:
        return a

    c = a % b
    return gcd(b, c)

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

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

print(b)
Buggy python submission (verdict: Runtime Error):
n, p = map(int, input().split())

b = [False] * 1000001
prime = []
b[1] = True

for i in range(2, 1000001):
    if b[i]:
        continue
    k = i + i
    while k < 1000001:
        b[k] = True
        k += i

    prime.append(i)

prime_num = [0] * len(prime)

pp = []

for i in range(len(prime)):
    while p % prime[i] == 0:
        pp.append(prime[i])
        prime_num[i] += 1
        p //= prime[i]

if len(pp) == 0:
    print(1)
    exit()

idx = []
for i in range(len(prime) - 1, -1, -1):
    if prime_num[i] >= n:
        idx.append(i)
        break

for i in range(idx[0] - 1, -1, -1):
    if prime_num[i] >= prime_num[idx[0]]:
        idx.append(i)

ans = 1
for x in idx:
    ans *= prime[x]

print(ans)

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

if n == 1:
    print(p)
    exit()

b = [False] * 1000001
prime = []
b[1] = True

for i in range(2, 1000001):
    if b[i]:
        continue
    k = i + i
    while k < 1000001:
        b[k] = True
        k += i

    prime.append(i)

prime_num = [0] * len(prime)

for i in range(len(prime)):
    while p % prime[i] == 0:
        prime_num[i] += 1
        p //= prime[i]

if sum(prime_num) == 0:
    print(1)
    exit()

idx = []
for i in range(len(prime) - 1, -1, -1):
    if prime_num[i] >= n:
        idx.append(i)

if len(idx) == 0:
    print(1)
    exit()

ans = 1
for x in idx:
    a = prime_num[x] // n
    ans *= prime[x] ** a

print(ans)