Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02734 (python)

Fixed submission:
import numpy as np

def main():
    n, s = map(int, input().split())
    nums = [int(c) for c in input().split()]
    mod = 998244353
    dp = np.zeros(s+1, dtype=np.int)
    ans = 0

    for i, num in enumerate(nums, 1):
        dp[0] = i
        if num <= s:
            dp[num:] = dp[num:] + dp[:-num]
            # print(dp)
        dp %= mod
        ans = (ans + dp[-1]) % mod
    print(ans)


if __name__ == "__main__":
    main()

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


def solve(nums, s):
    @lru_cache(None)
    def dfs(i, k):
        if k < 0:
            return []
        if k == 0:
            return [i-1]
        if i >= n:
            return []
        if k == s:
            return dfs(i+1, k-nums[i])
        return dfs(i+1, k-nums[i]) + dfs(i+1, k)

    ans = 0
    n = len(nums)
    for i in range(n):
        for e in dfs(i, s):
            ans = (ans + (i+1)*(n-e)) % 998244353
    return ans


def main():
    n, s = map(int, input().split())
    nums = [int(c) for c in input().split()]
    print(solve(nums, s))


if __name__ == "__main__":
    main()
Problem p02687 (python)

Fixed submission:
S = input()

if S == "ABC":
  print("ARC")
  
else:
  print("ABC")

Buggy submission (verdict: Runtime Error):
S = input("先週のコンテスト名を入力")

a = ABC

b = ARC

if S == a:
  print(b)
  
else:
  print(a)

Buggy submission (verdict: Runtime Error):
S = input("先週のコンテスト名を入力")

if S == ABC:
  print(ARC)
  
else:
  print(ABC)

Buggy submission (verdict: Runtime Error):
S = input("先週のコンテスト名を入力")

if S == ABC:
  print(ARC)
  
else:
  print(ABC)

Buggy submission (verdict: Runtime Error):
S = int(input("先週のコンテスト名を入力"))

if S == ABC:
  print(ARC)
  
else:
  print(ABC)
Problem p02681 (python)

Fixed submission:
a = input()
b = input()
last_char = b[len(b)-1]
if (a+last_char == b):
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
a,b,c,k = map(int,input().split())
sum=0
if(k==0):
  print(sum)
  exit()
if(a>k):
  sum+=k
  print(sum)
  exit()
else:
  sum+=a
  k=k-a
  if(k==0):
    print(sum)
    exit()
  if(b>k):
    print(sum)
    exit()
  else:
    k = k-b
    if(k==0):
      print(sum)
      exit()
    if(c>k):
      sum-=k
      print(sum)
    else:
      sum-=c
      print(sum)

Buggy submission (verdict: Runtime Error):
a,b,c,k = map(int,input().split())
sum=0
if(a>k):
  sum+=k
else:
  sum+=a
  k=k-a
  if(k==0):
    print(sum)
    exit()
  if(b>k):
    print(sum)
  else:
    k = k-b
    if(k==0):
      print(sum)
      exit()
    if(c>k):
      sum-=k
      print(sum)
    else:
      sum-=c
      print(sum)
Problem p02681 (python)

Fixed submission:
S = input()
T = input()

if S == T[:-1] and len(S) + 1 == len(T):
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
from itertools import produce

A, B, C, K = map(int, input().split(" "))


print(produce([A]*K, [B]*K, [C]*K))
Problem p02713 (python)

Fixed submission:
import math
from itertools import product
 
x = int(input())

s = 0
for a, b, c in product(range(1, x+1), repeat=3):
  s += math.gcd(math.gcd(a, b), c)
print(s)

Buggy submission (verdict: Runtime Error):
from itertools import product

x1 = int(input())
x2 = input()

R_i = [i for i, x in enumerate(x2) if x == "R"]
G_i = [i for i, x in enumerate(x2) if x == "G"]
B_i = {i for i, x in enumerate(x2) if x == "B"}

R = len(R_i)
G = len(G_i)
B = len(B_i)

xs = map(sorted, product(R_i, G_i))

s = 0
for a in xs:
    k = a[1]*2 - a[0]  # 2j-i
    if k in B_i:
        s +=1
    i = a[0]*2 - a[1]  # 2j-k
    if i in B_i:
        s +=1
    j = (a[0] + a[1]) / 2
    if j.is_integer():
        j = int(j)
        if j in B_i:
            s +=1
print(R*G*B - s)

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce
from itertools import product

x = int(input())
print(sum([reduce(math.gcd, *i) for i in product(range(1, x+1), repeat=3)]))

Buggy submission (verdict: Runtime Error):
from itertools import combinations
 
x1 = int(input())
x2 = input()
RGB = {"R", "G", "B"}

peint(sum([1 for i, rgb in zip(combinations(range(x1), 3), combinations(x2, 3)) if set(rgb) == RGB and (i[1] - i[0]) != (i[2] - i[1])]))

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce
import itertools


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


x = input()
_sum = [gcd(*i) for i in itertools.product(range(x), repeat=3)]
print(sum(_sum))
Problem p02714 (python)

Fixed submission:
from itertools import product

x1 = int(input())
x2 = input()

R_i = [i for i, x in enumerate(x2) if x == "R"]
G_i = [i for i, x in enumerate(x2) if x == "G"]
B_i = {i for i, x in enumerate(x2) if x == "B"}

R = len(R_i)
G = len(G_i)
B = len(B_i)

xs = map(sorted, product(R_i, G_i))

s = 0
for a in xs:
    k = a[1]*2 - a[0]  # 2j-i
    if k in B_i:
        s +=1
    i = a[0]*2 - a[1]  # 2j-k
    if i in B_i:
        s +=1
    j = (a[0] + a[1]) / 2
    if j.is_integer():
        j = int(j)
        if j in B_i:
            s +=1
print(R*G*B - s)

Buggy submission (verdict: Runtime Error):
from itertools import product

x1 = int(input())
x2 = input()

R_i = [i for i, x in enumerate(x2) if x == "R"]
G_i = [i for i, x in enumerate(x2) if x == "G"]
B_i = {i for i, x in enumerate(x2) if x == "B"}

R = len(R_i)
G = len(G_i)
# B = len(B_i)

xs = map(sorted, product(R_i, G_i))

s = 0
for a in xs:
    k = a[1]*2 - a[0]  # 2j-i
    if k in B_i:
        s +=1
    i = a[0]*2 - a[1]  # 2j-k
    if i in B_i:
        s +=1
    j = (a[0] + a[1]) / 2
    if j.is_integer():
        j = int(j)
        if j in B_i:
            s +=1
print(R*G*B - s)

Buggy submission (verdict: Runtime Error):
from itertools import product

x1 = int(input())
x2 = input()

R_i = [i for i, x in enumerate(x2) if x == "R"]
G_i = [i for i, x in enumerate(x2) if x == "G"]
B_i = {i for i, x in enumerate(x2) if x == "B"}

R = len(R_i)
G = len(G_i)
# B = len(B_i)

xs = map(sorted, product(R_i, G_i))

s = 0
for a in xs:
    k = a[1]*2 - a[0]  # 2j-i
    if k in B_i:
        s +=1
    i = a[0]*2 - a[1]  # 2j-k
    if i in B_i:
        s +=1
    j = (a[0] + a[1]) / 2
    if j.is_integer():
        j = int(j)
        if j in B_i:
            s +=1
print(R*G*B - s)

Buggy submission (verdict: Runtime Error):
x1 = int(input())
x2 = input()

R_i = [i for i, x in enumerate(x2) if x == "R"]
G_i = [i for i, x in enumerate(x2) if x == "G"]
B_i = [i for i, x in enumerate(x2) if x == "B"]

R = len(R_i)
G = len(G_i)
B = len(B_i)

xs = map(sorted, product(R_i, G_i))

s = 0
for a in xs:
    k = a[1]*2 - a[0]  # 2j-i
    if k in B_i:
        s +=1
    i = a[0]*2 - a[1]  # 2j-k
    if i in B_i:
        s +=1
    j = (a[0] + a[1]) / 2
    if j.is_integer():
        j = int(j)
        if j in B_i:
            s +=1
print(R*G*B - s)

Buggy submission (verdict: Runtime Error):
import itertools

x1 = input()
x2 = input()
RGB = {"R", "G", "B"}
_sum = 0
for i, rgb in zip(itertools.combinations(range(x1), 3), itertools.combinations(x2, 3)):
    if set(rgb) == RGB and (i[1] - i[0]) != (i[2] - i[1]):
        _sum += 1
print(_sum)

Buggy submission (verdict: Runtime Error):
x1 = input()
x2 = input()
RGB = {"R", "G", "B"}
_sum = 0
for i, rgb in zip(itertools.combinations(range(x1), 3), itertools.combinations(x2, 3)):
    if set(rgb) == RGB and (i[1] - i[0]) != (i[2] - i[1]):
        _sum += 1
print(_sum)
Problem p03076 (python)

Fixed submission:
import sys
from itertools import permutations

a = [int(i) for i in sys.stdin]

b = [(list(map(int, str(k)))[-1], i) for i, k in enumerate(a)]

indexes = [i for i, (x, y)in enumerate(b) if x == 0]
d = 0
for i in sorted(indexes)[::-1]:
  d += a[i]
  b.pop(i)
b.sort()
c = b[::-1]

for i, k in c[:-1]:
  if i > 5:
    d += round(a[k], -1)
  else:
    d += (round(a[k], -1) + 10)
if c != []:
  d += a[c[-1][1]]
print(d)

Buggy submission (verdict: Runtime Error):
import sys
from itertools import permutations

a = [int(i) for i in sys.stdin]

b = [(list(map(int, str(k)))[-1], i) for i, k in enumerate(a)]

indexes = [i for i, (x, y)in enumerate(b) if x == 0]
d = 0
for i in sorted(indexes)[::-1]:
  d += a[i]
  b.pop(i)
b.sort()
c = b[::-1]

for i, k in c[:-1]:
  if i > 5:
    d += round(a[k], -1)
  else:
    d += (round(a[k], -1) + 10)
d += a[c[-1][1]]
print(d)

Buggy submission (verdict: Runtime Error):
import sys
from itertools import permutations

a = [int(i) for i in sys.stdin]

b = [(list(map(int, str(k)))[-1], i) for i, k in enumerate(a)]

indexes = [i for i, (x, y)in enumerate(b) if x == 0]
d = 0
for i in sorted(indexes)[::-1]:
  d += a[i]
  b.pop(i)
b.sort()
c = b[::-1]

for i, k in c[:-1]:
  if i >= 5:
    d += round(a[k], -1)
  else:
    d += (round(a[k], -1) + 10)
d += a[c[-1][1]]
print(d)
Problem p02706 (python)

Fixed submission:
a,b=map(int,input().split())
A=input().split()
n=0
for i in range(b) :
  n+=int(A[i-1])
if n>a :
  print(-1)
else :
  print(a-n)

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split())
A=input().split()
n=0
for i in range(b) :
  n+=A[i-1]
if n>a :
  print(-1)
else :
  print(a-n)
Problem p02818 (python)

Fixed submission:
A, B, K = map(int,input().split())
a = 0
b = 0

if K <= A:
  a = A - K
  b = B
elif A < K <= A + B:
  b = B + A - K

print(str(a) + ' ' + str(b))

Buggy submission (verdict: Runtime Error):
A, B, K = map(int,input().split())

if K <= A:
  a -= K
elif A < K <= A + B:
  a = 0
  b = B + A - K
elif A + B < K:
  a = b = 0

print(str(a) + ' ' + str(b))
Problem p02848 (python)

Fixed submission:
N = int(input())
S = input()
Sr = []

al = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']

for i in range(len(S)):
  n = al.index(S[i])
  Sr.append(al[(1 + n + N) % 26 - 1])
  
print(''.join(Sr))

Buggy submission (verdict: Runtime Error):
N = int(input())
S = input()
Sr = []

al = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']

for i in range(len(S)):
  m = al.index(S[i])
  n = (1 + n + N) % 26 - 1
  Sr.append(al[n])
  
print(''.join(Sr))
Problem p02882 (python)

Fixed submission:
import math
a,b,x = map(float,input().split())

c = (2*b-(2*x)/(a*a))/a
d = (a*b*b)/(2*x)
if x/a >= a*b/2:
  result = math.degrees(math.atan(c))
else:
  result = math.degrees(math.atan(d))
print(result)

Buggy submission (verdict: Runtime Error):
import math
a,b,x = map(float,input().split())

c = a/(2*b-(2*x)/(a*a))
d = (2*x)/(a*b*b)
if x/a >= a*b/2:
  result = math.degrees(math.atan(c))
else:
  result = math.degrees(math.atan(d))
print(result)

Buggy submission (verdict: Runtime Error):
import math
a,b,x = map(float,input().split())

c = a/(2*b-2*x/a**2)
d = (2*x)/(a*b**2)
if x/a >= a*b/2:
  result = math.atan(c)
else:result = math.degrees(math.atan(d))
print(result)

Buggy submission (verdict: Runtime Error):
import math
a,b,x = map(float,input().split())

c = a/(2*b-2*x/a**2)
d = (2*x)/(a*b**2)
if x/a >= a*b/2:
  result = math.atan(c)
else:
  result = math.degrees(math.atan(d))
print(result)

Buggy submission (verdict: Runtime Error):
import math
a,b,x = map(float,input().split())

c = a/(2*b-2*x/a**2)
d = (2*x)/(a*b**2)
if x/a >= a*b/2:
  result = math.atan(c)
else:
  result = math.degrees(math.atan(d))
print(result)
Problem p03555 (python)

Fixed submission:
import sys
C = [[str(c) for c in l.strip()] for l in sys.stdin]
if (C[0][0] == C[1][2]) and (C[0][1] == C[1][1]) and (C[0][2] == C[1][0]):
  print('YES')
else:print('NO')

Buggy submission (verdict: Runtime Error):
C = [input().split() for i in range(2)]
if C[0][0] == C[1][2] and C[0][1] == C[1][1] and C[0][2] == C[1][0]:
  print('YES')
else:print('NO')

Buggy submission (verdict: Runtime Error):
C = [input().split() for i in range(2)]
if (C[0][0] == C[1][2]) and (C[0][1] == C[1][1]) and (C[0][2] == C[1][0]):
  print('YES')
else:print('NO')

Buggy submission (verdict: Runtime Error):
C = [input().split() for i in range(2)]
if (C[0][0] == C[1][2]) and (C[0][1] == C[1][1]) and (C[0][2] == C[1][0]):
  print('YES')
else:print('NO')
Problem p04030 (python)

Fixed submission:
s = input()
L = []

for i in range(len(s)):
  if s[i] == '0':
    L.append('0')
  elif s[i] == '1':
    L.append('1')
  elif s[i] == 'B' and len(L) > 0:
    del L[-1]

print(''.join(L))

Buggy submission (verdict: Runtime Error):
s = input()
L = []

for i in range(len(s)):
  if s[i] == '0':
    L.append('0')
  elif s[i] == '1':
    L.append('1')
  elif s[i] == 'B':
    del L[-1]

print(''.join(L))
Problem p03071 (python)

Fixed submission:
a,b=map(int,input().split())
answer=0
for x in range(2):
    if a>=b:
        answer+=a
        a-=1
    else:
        answer+=b
        b-=1
print(answer)

Buggy submission (verdict: Runtime Error):
import math
tile=int(input())
if len(str(tile))==1:
    print(0)
    exit()
if len(str(tile))%2==1:
    tile1=int("01"*int(math.ceil(len(str(tile))/2)),2)
    tile2=int("10"*int(math.ceil(len(str(tile))/2)),2)
else:
    tile1=int("01"*int(len(str(tile))/2),2)
    tile2=int("10"*int(len(str(tile))/2),2)

tile_10=int(str(tile),2)
convert1=format(tile_10^tile1,'b').zfill(len(str(tile)))
convert2=format(tile_10^tile2,'b').zfill(len(str(tile)))
if convert1.count("1")<=convert2.count("1"):
    print(convert1.count("1"))
else:
    print(convert2.count("1"))
Problem p02971 (python)

Fixed submission:
def q3():
    """ C - Exception Handling """
    N = int(input())
    A = []
    for n in range(N):
        A.append(int(input()))

    max_A = max(A)
    second_A = sorted(A, reverse=True)[1]
    for n in range(N):
        if A[n] == max_A:
            print(second_A)
        else:
            print(max_A)

            
if __name__ == '__main__':
    q3()

Buggy submission (verdict: Runtime Error):
def q3():
    N = int(input())
    A = []
    for n in range(N):
        A.append(int(input()))

    for n in range(N):
        tmp = A.copy()
        tmp.pop(n)
        print(max(tmp))


if __name__ == '__main__':
    q3()
Problem p02995 (python)

Fixed submission:
def q3():
    """ C - Anti-Division """
    from fractions import gcd  # 3.4.3ではmath.gcdは無い
    A,B,C,D = (int(i) for i in input().split())

    def lcm(x, y):
        """ 最小公倍数を求める """
        return (x * y) // gcd(x, y)

    num_C = B // C - (A - 1) // C  # Cで割り切れる個数
    num_D = B // D - (A - 1) // D  # Dで割り切れる個数
    lcm_CD = lcm(C, D)
    num_CD = B // lcm_CD - (A - 1) // lcm_CD  # CとDの最小公倍数で割り切れる個数
    num_all = num_C + num_D - num_CD  # 全ての割り切れる個数
    ans = B - A + 1 - num_all
    print(ans)


if __name__ == '__main__':
    q3()

Buggy submission (verdict: Runtime Error):
def lcm(x, y):
	""" 最小公倍数を求める """
    return (x * y) // math.gcd(x, y)

def q3():
    """ C - Anti-Division """
    import math
    A,B,C,D = (int(i) for i in input().split())

    num_C = B // C - (A - 1) // C  # Cで割り切れる個数
    num_D = B // D - (A - 1) // D  # Dで割り切れる個数
    lcm_CD = lcm(C, D)
    num_CD = B // lcm_CD - (A - 1) // lcm_CD  # CとDの最小公倍数で割り切れる個数
    
    num_all = num_C + num_D - num_CD  # 全ての割り切れる個数
    ans = B - A + 1 - num_all
    print(ans)

if __name__ == '__main__':
    q3()

Buggy submission (verdict: Runtime Error):
def q3():
    """ C - Anti-Division """
    import math
    A,B,C,D = (int(i) for i in input().split())

    def lcm(x, y):
        """ 最小公倍数を求める """
        return (x * y) // math.gcd(x, y)

    num_C = B // C - (A - 1) // C  # Cで割り切れる個数
    num_D = B // D - (A - 1) // D  # Dで割り切れる個数
    num_CD = B // lcm(C, D) - (A - 1) // lcm(C, D)  # CとDの最小公倍数で割り切れる個数
    num_all = num_C + num_D - num_CD  # 全ての割り切れる個数
    ans = B - A + 1 - num_all
    print(ans)

if __name__ == '__main__':
    q3()

Buggy submission (verdict: Runtime Error):
def q3():
    import math
    A,B,C,D = (int(i) for i in input().split())

    def lcm(x, y):
        """ 最小公倍数を求める """
        return (x * y) // math.gcd(x, y)

    num_C = B // C - (A - 1) // C  # Cで割り切れる個数
    num_D = B // D - (A - 1) // D  # Dで割り切れる個数
    num_CD = B // lcm(C, D) - (A - 1) // lcm(C, D)  # CとDの最小公倍数で割り切れる個数
    num_all = num_C + num_D - num_CD  # 全ての割り切れる個数
    ans = B - A + 1 - num_all
    print(ans)

if __name__ == '__main__':
    q3()
Problem p03162 (python)

Fixed submission:
def q3():
    """C - Vacation"""
    N = int(input())

    dp = [[0]*N for i in range(3)]
    dp[0][0], dp[1][0], dp[2][0] = (int(i) for i in input().split())

    if N == 1:
        print(max([dp[0][0], dp[1][0], dp[2][0]]))
        return

    a, b, c = (int(i) for i in input().split())
    dp[0][1] = max(dp[1][0], dp[2][0]) + a
    dp[1][1] = max(dp[0][0], dp[2][0]) + b
    dp[2][1] = max(dp[1][0], dp[0][0]) + c

    if N == 2:
        print(max([dp[0][1], dp[1][1], dp[2][1]]))
        return

    for i in range(1, N-1):
        a, b, c = (int(i) for i in input().split())
        dp[0][i+1] = max(dp[1][i], dp[2][i]) + a
        dp[1][i+1] = max(dp[0][i], dp[2][i]) + b
        dp[2][i+1] = max(dp[1][i], dp[0][i]) + c
    print(max([dp[0][-1], dp[1][-1], dp[2][-1]]))


if __name__ == '__main__':
    q3()

Buggy submission (verdict: Runtime Error):
def q3():
    def lcm(x, y):
        """ xとyの最小公倍数を求める """
        # import math
        import fractions
        return (x * y) // fractions.gcd(x, y)

    A, B = (int(i) for i in input().split())
    print(lcm(A, B))


if __name__ == '__main__':
    q3()
Problem p02975 (python)

Fixed submission:
n = input()
dic = {}
for i in map(int, raw_input().split()):
	if i in dic:
		dic[i] += 1
	else:
		dic[i] = 1
if len(dic) > 3:
	print "No"
elif len(dic) == 3:
	vals = []
	for i in dic:
		vals.append(i)
	if vals[0]^vals[2] != vals[1] or vals[1]^vals[0] != vals[2] or vals[0] != vals[1]^vals[2]:
		print "No"
	elif max(dic.values()) - min(dic.values()) > 1:
		print "No"
	else:
		print "Yes"
elif len(dic) == 2:
	if 0 in dic and dic[0] == n/3 and n%3 == 0:
		print "Yes"
	else:
		print "No"
else:
	if 0 in dic.keys():
		print "Yes"
	else:
		print "No"

Buggy submission (verdict: Runtime Error):
n = input()
dic = {}
for i in map(int, raw_input().split()):
	if i in dic:
		dic[i] += 1
	else:
		dic[i] = 1
if len(dic) > 3:
	print "No"
elif len(dic) == 3:
	vals = []
	for i in dic:
		vals.append(i)
	if vals[0]^vals[2] != vals[1] or vals[1]^vals[0] != vals[2] or vals[0] != vals[1]^vals[2]:
		print "No"
	elif max(dic.values()) - min(dic.values()) > 1:
		print "No"
	else:
		print "Yes"
elif len(dic) == 2:
	assert(1 > 2)
	if 0 in dic and n%2 and dic[0] == n/2:
		print "Yes"
	else:
		print "No"
else:
	if 0 in dic.keys():
		print "Yes"
	else:
		print "No"
Problem p03192 (python)

Fixed submission:
print raw_input().count('2')

Buggy submission (verdict: Runtime Error):
n, p = map(int, raw_input().split())
fac = {}
primes = [1]*(10**6 + 200)
i = 2
prim = []
while i <= 10**6 + 100:
    if primes[i]:
        prim.append(i)
        j = i*2
        while j <= 10**6 + 100:
            primes[j] = 0
            j += i 
    i += 1 
for i in prim:
    while p%i == 0:
        p /= i 
        fac[i] = fac[i] + 1 if i in fac else 1
if p > 1:
    fac[p] = 1
ans = 1
for i in fac:
    if fac[i] >= n:
        ans *= i**(fac[i]/n)
print ans

Buggy submission (verdict: Runtime Error):
n, p = map(int, raw_input().split())
fac = {}
primes = [1]*(10**6 + 200)
i = 2
prim = []
while i <= 10**6 + 100:
    if primes[i]:
        prim.append(i)
        j = i*2
        while j <= 10**6 + 100:
            primes[j] = 0
            j += i 
    i += 1 
for i in prim:
    while p%i == 0:
        p /= i 
        fac[i] = fac[i] + 1 if i in fac else 1
ans = 1
for i in fac:
    if fac[i] >= n:
        ans *= i**(fac[i]/n)
print ans

Buggy submission (verdict: Runtime Error):
n, p = map(int, raw_input().split())
fac = {}
primes = [1]*(10**6 + 200)
i = 2
prim = []
while i <= 10**6 + 100:
    if primes[i]:
        prim.append(i)
        j = i*2
        while j <= 10**6:
            primes[j] = 0
            j += i 
    i += 1 
for i in prim:
    while p%i == 0:
        p /= i 
        fac[i] = fac[i] + 1 if i in fac else 1
ans = 1
for i in fac:
    if fac[i] >= n:
        ans *= i**(fac[i]/n)
print ans
Problem p03268 (python)

Fixed submission:
n, k = map(int, raw_input().split())
if k%2:
	print (n/k)**3
else:
	cnt1, cnt2 = 0, 0
	for i in range(1, n + 1):
		if i%k == 0:
			cnt1 += 1
		if i%k == k/2:
			cnt2 += 1
	print cnt1**3 + cnt2**3

Buggy submission (verdict: Runtime Error):
n = input()
node = 0
tmp = n
while tmp:
	node += 1
	tmp >>= 1
edges = []
for i in range(node - 1):
	edges.append([i+1, i+2, 0])
	edges.append([i+1, i+2, 1<<i])
for i in range(node-2, -1, -1):
	if (1<<i)&n:
		edges.append([i+1, node, (n>>(i+1))<<(i+1)])
print node, len(edges)
for i in edges:
	print i[0], i[1], i[2]
Problem p04033 (python)

Fixed submission:
l, r = map(int, raw_input().split())
if l <= 0 <= r:
	print "Zero"
elif l > 0:
	print "Positive"
else:
	if (r - l)%2 == 0:
		print "Negative"
	else:
		print "Positive"

Buggy submission (verdict: Runtime Error):
n, k = map(int, raw_input().split())
l = map(int, raw_input().split())
totallen = sum(l)
h = []
i = 0
j = n - 2
ans = []
while i <= j:
	if totallen < k:
		break
	else:
		if l[i] < l[j]:
			ans.append(i + 1)
			totallen -= l[i]
			i += 1
		else:
			ans.append(j + 1)
			totallen -= l[j+1]
			j -= 1
if len(ans) == n - 1:
	print "Possible"
	for i in ans:
		print i 
else:
	print "Impossible"
Problem p02684 (python)

Fixed submission:
n,k = map(int,input().split())
a = list(map(int,input().split()))
flag = True
went = {1}
go = [1]
i = 0
while flag:
  if a[i] not in went:
    go.append(a[i])
    went.add(a[i])
    i = a[i]-1
  else:
    flag = False
loop = go[go.index(a[i]):]
if len(go) > k:
  print(go[k])
else:
  k -= len(go)-len(loop)
  ans = k % len(loop)
  print(loop[ans])

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
a = list(map(int,input().split()))
flag = True
went = {1}
go = [1]
i = 0
while flag:
  if a[i] not in went:
    go.append(a[i])
    went.add(a[i])
    i = a[i]-1
  else:
    flag = False
loop = go[go.index(a[i]):]
if len(go) >= k:
  print(go[k])
else:
  k -= len(go)-len(loop)
  ans = k % len(loop)
  print(loop[ans])
Problem p02848 (python)

Fixed submission:
n = int(input())
s = list(input())
x = len(s)
ans = []
abc = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
for i in range(x):
  ans.append(abc[(abc.index(s[i])+n) % 26])
print("".join(ans))

Buggy submission (verdict: Runtime Error):
n = int(input())
s = list(input())
ans = []
abc = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
for i in range(n):
  ans.append(abc[(abc.index(s[i])+n) % 26])
  print(s[i])
print("".join(ans))
Problem p02924 (python)

Fixed submission:
n = int(input())
print(n*(n-1)//2)

Buggy submission (verdict: Runtime Error):
n = int(input())
n_list = [i for i in range(1,n)]
print(sum(n))
Problem p02953 (python)

Fixed submission:
import sys
input = sys.stdin.readline
n = int(input())
h = list(map(int,input().split()))
flag = 0
for i in range(n-1,1,-1):
  if h[i] - h[i-1] == -1:
    h[i-1] -= 1
  elif h[i] - h[i-1] >= 0:
    continue
  else:
    flag += 1
if flag == 0:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n = int(input())
h = list(map(int,input().split()))
flag = 0
for i in range(n-2):
  if h[i] - h[i+2] >= 2:
    flag += 1
if h[-2]-h[-1] >= 2:
  flag += 1
if flag == 0:
  print("Yes")
else:
  print("No")
Problem p02958 (python)

Fixed submission:
n = int(input())
p = list(map(int,input().split()))
int_queue = [i for i in range(1,n+1)]
ans = 0
for j in range(0,n):
  if p[j]-int_queue[j] == 0:
    continue
  else:
    ans += 1
if ans == 2 or ans == 0:
  print("YES")
else:
  print("NO")

Buggy submission (verdict: Runtime Error):
n = int(input())
p = list(map(int,input().split()))
int_queue = [i for i in range(1,n+1)]
ans = 0
for j in range(1,n):
  ans += p[i]-int_queue[i]
if ans == 0:
  print("YES")
else:
  print("NO")