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

Fixed submission:
def solve(n, p):
    result = 0
    for i in range(n-1):
        if (i+1) == p[i]:
            p[i], p[i+1] = p[i+1],p[i]
            result += 1
    i = n - 1
    if (i+1) == p[i]:
        p[i-1], p[i] = p[i],p[i-1]
        result += 1
    return result

if __name__ == '__main__':
    n = int(input())
    p = list(map(int, input().split(" ")))
    print(solve(n, p))

Buggy submission (verdict: Runtime Error):
def solve(n,p):
    
    memo = {}
    items = [(0,p)]
    result = 0
    while items:
        step, p = items.pop(0)
        if check(n,p):
            result = step
            break
        else:
            for i in range(n-1):
                candidate = tuple( p[:i] +[ p[i+1] ,p[i]] + p[i+2:] )
                if not candidate in memo:
                    items.append([step +1 , list(candidate)])
                    memo[candidate] = step + 1
                
    return result

if __name__ == '__main__':
    n = int(input())
    p = list(map(int, input().split(" ")))
    print(solve(n, p))

Buggy submission (verdict: Runtime Error):
def solve(n,p):
    
    memo = {}
    items = [(0,p)]
    result = 0
    while items:
        step, p = items.pop(0)
        if check(n,p):
            result = step
            break
        else:
            for i in range(n-1):
                candidate = tuple( p[:i] +[ p[i+1] ,p[i]] + p[i+2:] )
                if not candidate in memo:
                    items.append([step +1 , list(candidate)])
                    memo[candidate] = step + 1
                
    return result

n = int(input())
p = list(map(int, input().split(" ")))

print(solve(n, p))

Buggy submission (verdict: Runtime Error):
def solve(n,p):
    
    memo = {}
    items = [(0,p)]
    result = 0
    while items:
        step, p = items.pop(0)
        if check(n,p):
            result = step
            break
        else:
            for i in range(n-1):
                candidate = tuple( p[:i] +[ p[i+1] ,p[i]] + p[i+2:] )
                if not candidate in memo:
                    items.append([step +1 , list(candidate)])
                    memo[candidate] = step + 1
                
    return result

n = int(input())
p = map(int, input().split(" "))

print(solve(n, p))
Problem p03799 (python)

Fixed submission:
s, c = map(int, raw_input().rstrip("\n").split(" "))

def calc_scc(s, c):
  answer = 0
  if (s * 2) >= c:
    answer = c / 2
  else:
    answer = s + ((  c - (s * 2) )  / 4 )
  return answer

print calc_scc(s, c)
#print calc_scc(12345, 678901), 175897

Buggy submission (verdict: Runtime Error):
n, m = map(int, raw_input().rstrip("\n").split(" "))

answer = 0
if (n * 2) >= m:
  answer = m / 2
else:
  answer = n + (  m - (n *2) )  / 3)
print answer
print calc_scc(12345,678901), 175897
Problem p02639 (python)

Fixed submission:
import sys
C = list(map(int, input().split()))
for n in range(len(C)):
  if C[n]==0:
    print(n+1)
    sys.exit()

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
B = [True]*N
count = 0
A.sort()
for i in range(N):
    if B[i]:
        for j in range(i+1,N):
            if A[i]==A[j]:
                B[j] = False
                B[i] = False
            elif A[j]%A[i]==0:
                B[j] = False
    if B[i]:
        count+=1
print(count)
Problem p02646 (python)

Fixed submission:
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())
if abs(B-A)<=(V-W)*T:
  print("YES")
else:
  print("NO")

Buggy submission (verdict: Runtime Error):
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())
if B+W*T=<A+V*T or B<A:
    print("NO")
else:
    print("YES")

Buggy submission (verdict: Runtime Error):
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())
flag = False
for t in range(T+1)
    if (B+W*T==A+V*T):
        flag = True
if flag:
    print("NO")
else:
    print("YES")
Problem p02664 (python)

Fixed submission:
T = input()
S = []
for n in range(0,len(T)):
    if T[n] == "?":
        S.append("D")
    else:
        S.append(T[n])
print("".join(S))

Buggy submission (verdict: Runtime Error):
T = input()
S = []
if T[0] == "?" and T[1]=="D":
    S.append("P")
else:
    S.append(T[0])
for n in range(1,len(T)-1):
    if T[n] == "?" and S[n-1] == "P":
        S.append("D")
    elif T[n] == "?" and T[n+1] == "P":
        S.append("D")
    elif T[n] == "?":
        S.append("P")
    else:
        S.append(T[n])
if S[len(S)-1]=="P":
    S.append("D")
else:
    S.append("P")
print("".join(S))
Problem p02684 (python)

Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))
B = []
i = 0
B.append(1)
for n in range(N):
  B.append(A[i])
  i = A[i]-1
if K>N:
  start = 0
  num = 0
  for j in range(len(B)):
    if B[len(B)-1] == B[j]:
      start = j
      break
  for j in range(1,len(B)-start):
    if B[start+j] == B[start]:
      num = j
      break
  print(B[((K-start)%num)+start])
else:
  print(B[K])

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))
B = []
i = 0
B.append(1)
for n in range(N):
  B.append(A[i])
  i = A[i]-1
start = 0
num = 0
for j in range(len(B)):
  if B[len(B)-1] == B[j]:
    start = j-1
    break
for j in range(1,len(B)-start):
  if B[start+j] == B[start]:
    num = j
    break
print(B[((K-start)%num)+start])
Problem p02690 (python)

Fixed submission:
import math, sys
X = int(input())
for a in range(-200,200):
  a5 = a**5
  for b in range(-200,200):
    if a5-b**5==X:
      print(str(a)+" "+str(b))
      sys.exit()

Buggy submission (verdict: Runtime Error):
import math, sys
X = int(input())
for a in range(-200,200):
  a5 == a**5
  for b in range(-200,200):
    if a5-b**5==X:
      print(str(a)+" "+str(b))
      sys.exit()
Problem p02713 (python)

Fixed submission:
K = int(input())
total = 0

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

for a in range(K):
  for b in range(a,K):
    for c in range(b,K):
      if a==b and b==c:
        total += gdc(c+1, gdc(b+1, a+1))
      elif a==b or b==c or a==c:
        total += 3*gdc(c+1, gdc(b+1, a+1))
      else:
        total += 6*gdc(c+1, gdc(b+1, a+1))
print(total)

Buggy submission (verdict: Runtime Error):
K = int(input())
total = 0

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

for a in range(K):
  for b in range(a,K):
    for c in range(b,K):
      if a==b and b==c:
        total += gdc(c+1, gdc(b+1, a+1))
      elif a==b or b==c or a==c:
        total += 3*gdc(c+1, gdc(b+1, a+1))
      eles:
        total += 6*gdc(c+1, gdc(b+1, a+1))
print(total)
Problem p02755 (python)

Fixed submission:
import sys
A, B = [int(x) for x in input().split()]
for x in range(1010):
  if A == x*8//100 and B == x//10:
    print(x)
    sys.exit()
print(-1)

Buggy submission (verdict: Runtime Error):
import sys

flag =Fale
A, B = [int(x) for x in input().split()]
for x in range((A+1)*9,(B+1)*10+1):
  if A == x*8//100 and B == x//10:
    print(x)
    flag=True
    break
if not flag:
  print(-1)
Problem p02842 (python)

Fixed submission:
import sys
N = int(input())
for n in range(N*100//110,N+1):
  if n*1.08//1 == N:
    print(n)
    sys.exit()
print(":(")

Buggy submission (verdict: Runtime Error):
import sys
N = int(input())
for n in renge(N//1.08,N):
  if n*1.08//1 == N:
    print(927)
    sys.exit()
Problem p02615 (python)

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

result = 0
spots = [a.pop()]

for i in range(n-1):
	x = a.pop()
	result += spots[i]
	spots.append(x)
	spots.append(x)
	
print(result)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = map(int,input().split())
a = sorted(a)

result = 0
spots = [a.pop()]

for i in range(n):
	next = a.pop()
	result += spots[i]
	spots.append(next)
	spots.append(next)
	
print(result)
Problem p02658 (python)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
a = sorted(a)
prod = 1
for x in a:
	prod *= x
	if prod > 10**18:
		prod = -1
		break
print(prod)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input.split()))
a = sorted(a)
prod = 1
for x in a:
  prod *= x
  if prod > 10**18:
    prod = -1
    break
print(prod)
Problem p02717 (python)

Fixed submission:
a,b,c = map(int,raw_input().split())
print c,a,b

Buggy submission (verdict: Runtime Error):
n,k,c = map(int,raw_input().split())
s = raw_input()
most = [0]*(n+1)
i = n
days = 0
while i > 0:
    if s[i-1] == 'o':
        days += 1
        for j in xrange(min(max(1,c),i-1)):
            #print days
            most[i-j-1] = days
        i -= (c+1)
    else:
        i -= 1
    if i<n-1:
        most[i] = most[i+1]

remain = k
i = 1
while i<=n:
    if s[i-1] == 'o':
        if most[i] < remain:
            print i
        remain -= 1
        i += c+1
    else:
        i += 1
Problem p03029 (python)

Fixed submission:
a,p = map(int,raw_input().split())
print (3*a+p)/2

Buggy submission (verdict: Runtime Error):
a,p = map(int,raw_input().split())
print (3*a+p)/2
Problem p03030 (python)

Fixed submission:
n = int(raw_input())
r = []
for i in xrange(1,n+1):
	rest,score = raw_input().split()
	score=int(score)
	r.append((rest,score,i))
r = sorted(r,key=lambda x:(x[0], -x[1], x[2]))
for x in r:
	print x[2]

Buggy submission (verdict: Runtime Error):
n = int(raw_input())
r = []
for i in xrange(1,n+1):
	rest,score = raw_input().split()
	score=int(score)
	r.append((rest,score,i))
r = sorted(r,key=lambda x:(x[0], -x[1], x[2]))
for x in r:
	print x[2]cd
Problem p03567 (python)

Fixed submission:
print "Yes" if raw_input().find("AC")>=0 else "No"

Buggy submission (verdict: Runtime Error):
print "Yes" if raw_input.find("AC") else print "No"
Problem p02755 (python)

Fixed submission:
def tax_increase(a,b):
    t8  = 0.08
    t10 = 0.1
    for i in range(b*10,(b+1)*10,1):
        if int(i*t8) == a:
            return i
    return -1
    
if __name__ == '__main__':
    a,b = map(int,input().split())
    ans = int(tax_increase(a,b))
    print(ans)

Buggy submission (verdict: Runtime Error):
def tax_increase(a,b):

    al = [a+(i / 10) for i in range(0,10,1)]
    bl = [b+(i / 10) for i in range(0,10,1)]
    #print(al)
    #print(bl)

    atx8 = list(map(lambda x: x/t8 ,al))
    btx10 = list(map(lambda x: x/t10 ,bl))
    #print(atx8)
    #print(btx10)

    for i in atx8:
        if i in btx10:
            return i
        else:
            pass
    return -1

if __name__ == '__main__':
    a,b = map(int,input().split())
    ans = int(tax_increase(a,b))
    print(ans)
Problem p02947 (python)

Fixed submission:
# -*- coding: utf-8 -*-
n = int(raw_input())
d = {}
ans = 0
for i in range(n):
    si = ''.join(sorted(raw_input()))
    if si in d:
        ans += d[si]
        d[si] += 1
    else:
        d[si] = 1
print(ans)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

n = int(input())
s = [ input() for i in range(n)]
count = 0
x = [sorted(i) for i in s]
_x = sorted(x)

for i in range(n-1):
  	tmp = -x[i]
    for j in range(i+1,n):
        if tmp == _x[j]:
            count += 1
        else:
            break

print(count)
Problem p02969 (python)

Fixed submission:
if __name__ == '__main__':
    r = int(raw_input())
    print 3*r*r

Buggy submission (verdict: Runtime Error):
if __name__ == '__main__':
3    r = int(raw_input())
4
5    print 3*r*r
Problem p02971 (python)

Fixed submission:
import copy
def calcmax(a,b,fst,scd,n):
    for i in xrange(n):
        if fst == a[i]:
            count = i

    for i in xrange(n):
        if count == i:
            print scd
        else:
            print fst

if __name__ == '__main__':
    n = int(raw_input())
    a = [int(raw_input()) for i in xrange(n)]
    print("")

    fst = max(a)

    b = copy.deepcopy(a)
    b.remove(fst)

    scd = max(b)

    calcmax(a,b,fst,scd,n)

Buggy submission (verdict: Runtime Error):
def pbox(n,a):
    count = 0
    result = []
    for i in xrange(n):
        total = 0
        b = [a[j] for j in xrange(i,n,i+1)]
        total = sum(b)
        if total % 2 == 1 and a[i] == 1:
            result.append(i+1)
        else:
            pass

    print len(result)
    print ' '.join(map(str,result))

if __name__ == '__main__':
    n = int(raw_input())
    a = map(int,raw_input().split())

    pbox(n,a)
~
Problem p02983 (python)

Fixed submission:
def remainder_min(l,r):
    sml = 2*(10**9)**2+1
    _r = min(r,l+2019)
    for i in range(l,_r):
        for j in range(i+1,_r+1):
            num = i * j
            rem = num % 2019
            if rem == 0:
                return 0
            sml = min(sml,rem)
    return sml

if __name__ == '__main__':
    l,r = map(int,raw_input().split())
    print remainder_min(l,r)

Buggy submission (verdict: Runtime Error):
def remainder_min(l,r):
    sml = 2*(10**9)**2+1
    lsml = 2*(10**9)**2+1
    rsml = 2*(10**9)**2+1
    for i in range(l,r):
        lrem = i % 2019

        if lsml > lrem:
            lsml = lrem
            break
        else:
            break

    for j in range(l+1,r+1):
        rrem = j % 2019

        if rsml > rrem:
            rsml = rrem
            break
        else:
            break

    return lrem*rrem


if __name__ == '__main__':
    l,r = map(int,raw_input().split())
    print remainder_min(l,r)

Buggy submission (verdict: Runtime Error):
def remainder_min(l,r):
    opt = 0
    gt = 2*(10**9)**2+1
    for j in range(l,r+1):
        for i in range(l,j):
            opt = (i * j) % 2019
#            print("i = %d, j = %d, opt = %d" %(i,j,opt))
            if gt > opt:
                gt = opt
    return gt
if __name__ == '__main__':
    l,r = map(int,raw_input().split())
    print remainder_min(l,r)

Buggy submission (verdict: Runtime Error):
    opt = 0
    gt = 2*(10**9)**2+1
    for j in range(l,r+1):
        for i in range(l,j):
            opt = (i * j) % 2019
            if gt > opt:
                gt = opt
    return gt
if __name__ == '__main__':
    l,r = map(int,raw_input().split())
    print remainder_min(l,r)
Problem p03001 (python)

Fixed submission:
if __name__ == '__main__':
    w,h,x,y = map(int,input().split())
    if x + x == w and y + y == h:
        a = 1
    else:
        a = 0

    print("%f %d" %(w*h/2, a))

Buggy submission (verdict: Runtime Error):
if __name__ == '__main__':
    w,h,x,y = map(int,input().split())
    if x + x == w and y + y == h::
        a = 1
    else:
        a = 0

    print("%f %d" %(w*h/2, a))
Problem p03061 (python)

Fixed submission:
#-*- using:utf-8 -*-
def euclidean(a,b):
    if b == 0:
        return a
    else:
        return  euclidean(b,a%b)

def gcd(a,b):
#    print("gcd %d %d" %(a,b))
    n = 0
    if a == b:
        return a
    elif a > b:
        n = euclidean(a,b)

    elif a < b:
        n = euclidean(b,a)

    else:
        pass

    return n

def blackboard(n,a):
    candidate = 0
    maxnum = 0
    b = list(map(int,a))

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

    for i in range(n):
        candidate = gcd(left[i],right[n-i-1])
        if candidate > maxnum:
            maxnum = candidate

    return maxnum


if __name__ == '__main__':
    n = raw_input()
    a = raw_input().split()
    m = int(n)
    print("%d" %(blackboard(m,a)))

Buggy submission (verdict: Runtime Error):
#-*- using:utf-8 -*-

def euclidean(a,b):
    if b == 0:
        return a
    else:
        return  euclidean(b,a%b)

def gcd(a,b):
#    print("gcd %d %d" %(a,b))
    n = 0
    if a == b:
        return a
    elif a > b:
        n = euclidean(a,b)

    elif a < b:
        n = euclidean(b,a)

    else:
        pass

    return n

def left(i,a):
    cd = 0
    for p in range(i):
        #cd0 = left(0) = 0
        #cd1 = left(1) = gcd(cd0,a[0])
        #cd2 = left(2) = gcd(cd1,a[1])
#        print("left %d %d" %(cd,a[p]))
        cd = gcd(cd,a[p])
#        print("left %d" %cd)
    return cd

def right(i,a):
    cd = 0
    for p in range(i,m)[::-1]:
        #cdn+1 = right(n+1) = 0
        #cdn   = right(n)   = gcd(cdn+1,a[n])
        #cdn-1 = right(n-1) = gcd(cdn,a[n-1])
#        print("right %d %d" %(cd,a[p]))
        cd = gcd(cd,a[p])
#        print("right %d" %cd)
    return cd

def blackboard(n,a):
    candidate = 0
    maxnum = 0
    b = list(map(int,a))

    p = m // 2 # round down
    q = -(-m // 2) #round up
#    print("i %d j %d" %(p,q))
    maxnum = gcd(left(p,b),right(q,b))

    return maxnum
  
  if __name__ == '__main__':
    n = raw_input()
    a = raw_input().split()
    global m
    m = int(n)
    print("%d" %(blackboard(m,a)))
Problem p03062 (python)

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

def count_negative(n,a):
    count = 0
    for i in range(n):
        if a[i] == 0:
            return 0
        elif a[i] < 0:
            count += 1
    return count

def num_of_min(n,a):
    minimum = sum(map(abs,a))
    
    count = 0    
    tmp = 0
    for i in range(n):
        tmp = abs(a[i])
        if tmp < minimum:
            minimum = tmp
            count = i
        else:
            pass
    return count

def flipping(n,a):
    nc = count_negative(n,a)
    total = 0
    count = 0
    if nc % 2 == 0:
        total = sum(map(abs,a))
    else:
        count = num_of_min(n,a)
        target = a.pop(count)
        
        total = sum(map(abs,a))
        if target > 0:
            total += target*(-1)
        else:
            total += target

    return total

if __name__ == '__main__':
    n = int(raw_input())
    a = map(int,raw_input().split())
    gt = flipping(n,a)
    print("%d" %gt)

Buggy submission (verdict: Runtime Error):
-*- using:utf-8 -*-

def count_negative(n,a):
    count = 0
    for i in range(n):
        if a[i] == 0:
            return 0
        elif a[i] < 0:
            count += 1
    return count

def num_of_min(n,a):
    minimum = max(a)
    count = 0
    tmp = 0
    for i in range(n):
        tmp = abs(a[i])
        if tmp < minimum:
            minimum = tmp
            count = i
        else:
            pass
    return count

def flipping(n,a):
    nc = count_negative(n,a)
    total = 0
    count = 0
    if nc % 2 == 0:
        for i in range(n):
            total += abs(a[i])
    else:
        count = num_of_min(n,a)
        target = a.pop(count)

        k = n - 1
        for i in range(k):
            total += abs(a[i])
        else:
            total += target*(-1)

    return total

if __name__ == '__main__':
    n = int(raw_input())
    a = map(int,raw_input().split())
    gt = flipping(n,a)
    print("%d" %gt)

Buggy submission (verdict: Runtime Error):
-*- using:utf-8 -*-

def count_negative(n,a):
    count = 0
    for i in range(n):
        if a[i] == 0:
            return 0
        elif a[i] < 0:
            count += 1
    return count

def num_of_min(n,a):
    minimum = max(a)
    count = 0
    tmp = 0
    for i in range(n):
        tmp = abs(a[i])
        if tmp < minimum:
            minimum = tmp
            count = i
        else:
            pass
    return count

def flipping(n,a):
    nc = count_negative(n,a)
    total = 0
    count = 0
    if nc % 2 == 0:
        for i in range(n):
            total += abs(a[i])
    else:
        count = num_of_min(n,a)
#            print("i %d, a[i] %d, count %d" %(i,a[i],count))
        target = a.pop(count)

        k = n - 1
        for i in range(k):
            total += abs(a[i])
#            print("i %d, tmp total %d" %(i,total))
        else:
            total += target*(-1)

    return total

if __name__ == '__main__':
    n = int(raw_input())
    a = map(int,raw_input().split())
    gt = flipping(n,a)
    print("%d" %gt)
Problem p03087 (python)

Fixed submission:
def get_ac(n,q,s,l,r):
    pos = [0]*n

    for j in range(0,n-1):
        if s[j] == 'A' and s[j+1] == 'C':
            pos[j+1] = pos[j] + 1
        else:
            pos[j+1] = pos[j]

    for i in range(q):
        left = l[i]
        right = r[i]
        count = pos[right - 1] - pos[left - 1]

        print count

if __name__ == '__main__':

    n,q = map(int,raw_input().split())
#    t1 = time.time()
    s = raw_input()

    l = [0]*q
    r = [0]*q

    for i in range(q):
        l[i],r[i] = map(int,raw_input().split())

#    t2 = time.time()
#    print('{0:.9f}'.format(t2 - t1))
    get_ac(n,q,s,l,r)

Buggy submission (verdict: Runtime Error):
if __name__ == '__main__':

    n,q = map(int,raw_input().split())
    s = raw_input()

    for i in range(q):
        left,right = map(int,raw_input().split())

        for j in range(left-1,right-1):
            if s[j] == 'A' and s[j+1] == 'C':
                count += 1
        else:
            print count
Problem p03212 (python)

Fixed submission:
import itertools

def seven_five_five(n):
    s = list(str(n))
    len_s = len(s)
    semi_753 = []
    for j in range(3,len_s+1):
        for i in itertools.product(['3','5','7'],repeat=j):
            l = ''.join(i)
            #print l
            semi_753.append(l)

    target = [i for i in semi_753 if int(i) > 356 and int(i) <= n]
    #print target
    count = 0
    for i in target:
        v = str(i)
        flag = [False,False,False]
        for j in list(v):
            if j == '7':
                flag[0] = True
            elif j == '5':
                flag[1] = True
            elif j == '3':
                flag[2] = True
            else:
                break

            if flag[0] and flag[1] and flag[2]:
                #print i
                count += 1
                break
    print count
if __name__ == '__main__':
    n =  int(raw_input())
    seven_five_five(n)

Buggy submission (verdict: Runtime Error):
def seven_five_five(n):
    s = list(str(n))
    len_s = len(s)
    semi_753 = []
    for j in range(3,len_s+1):
        for i in itertools.product(['3','5','7'],repeat=j):
            l = ''.join(i)
            #print l
            semi_753.append(l)

    target = [i for i in semi_753 if int(i) > 356 and int(i) <= n]
    #print target
    count = 0
    for i in target:
        v = str(i)
        flag = [False,False,False]
        for j in list(v):
            if j == '7':
                flag[0] = True
            elif j == '5':
                flag[1] = True
            elif j == '3':
                flag[2] = True
            else:
                break

            if flag[0] and flag[1] and flag[2]:
                #print i
                count += 1
                break
    print count
if __name__ == '__main__':
    n =  int(raw_input())
    seven_five_five(n)