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

Fixed submission:
def make_divisors(n):
    a,b =[],[]
    i = 1
    while i*i<=n:
        if n%i == 0:
            a.append(i)
            if i != n//i:
                b.append(n//i)
        i+= 1
    return a+b[::-1]

n = int(input())
c = 0
for i in range(1,n+1):
    if len(make_divisors(i))== 8 and i%2==1:
        c+=1
print(c)

Buggy submission (verdict: Runtime Error):
import sympy
n = int(input())
c = 0
for i in range(1,n+1):
    if i % 2 == 1 and len(sympy.divisors(i))==8:
        c+=1
print(c)

Buggy submission (verdict: Runtime Error):
import sympy
n = int(input())
c = 0
for i in range(1,n+1):
    if i % 2 == 1 and len(sympy.divisors(i))==8:
        c+=1
print(c)

Buggy submission (verdict: Runtime Error):
import sympy
n = int(input())
if n % 2 == 1 and len(sympy.divisors(n))==8:
    print(1)
else:
    print(0)

Buggy submission (verdict: Runtime Error):
import sympy
n = int(input())
if n % 2 == 0 and len(sympy.divisors(n))==8:
    print(1)
else:
    print(0)

Buggy submission (verdict: Runtime Error):
import sympy
n = int(input())
if n % 2 == 0 and len(sympy.divisors(n))==8:
    print(1)
else:
    print(0)

Buggy submission (verdict: Runtime Error):
def make_divisors(n):
    a,b =[],[]
    i = 1
    while i*i<=n:
        if n%i == 0:
            a.append(i)
            if i != n//i:
                b.append(n//i)
        i+= 1
    return a+b[::-1]

if i % 2 == 0 and len(make_divisors(int(input())))==8:
    print(1)
else:
    print(0)

Buggy submission (verdict: Runtime Error):
import sympy
if i % 2 == 0 and len(sympy.divisors(int(input())))==8:
    print(1)
else:
    print(0)

Buggy submission (verdict: Runtime Error):
import sympy
if i % 2 == 0 and len(sympy.divisors(int(input())))==8:
    print(1)
else:
    print(0)

Buggy submission (verdict: Runtime Error):
n = int(input())
if n = 105:
  print(1)
else:
  print(0)
Problem p03285 (python)

Fixed submission:
n = int(input())
x = 100//7+2
for i in range(x):
    for j in range(x):
        if 4*i+7*j == n:
            print("Yes")
            break
    else:
        continue
    break
else:
    print('No')

Buggy submission (verdict: Runtime Error):
n = int(input())
if n%7 == 0:
    if n%4==0:
        print('Yes')
        break
    else:
        print('No')
else:
    print('No')
Problem p03308 (python)

Fixed submission:
input()
s = sorted(map(int, input().split()))
print(s[len(s) - 1] - s[0])

Buggy submission (verdict: Runtime Error):
s = list(map(int, input().split()))
print(ma(s) - min(s))
Problem p03316 (python)

Fixed submission:
n = int(input())
a = list(str(n))
s = sum([int(a[i]) for i in range(len(a))])
if n%s==0:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
n = list(input())
s = sum([int(n[i]) for i in range(len(n))])
if n%s==0:
    print('Yes')
else:
    print('No')
Problem p03352 (python)

Fixed submission:
x = int(input())
count = 1
for i in range(1,x+1):
    for n in range(2,10):
        if i**n <= x:
            count = max(i**n,count)
print(count)

Buggy submission (verdict: Runtime Error):
x = int(input())
for i in range(x+1):
    for n in range(2,x+1):
        if i**n <= x:
            count = i**2
print(count)
Problem p03371 (python)

Fixed submission:
a,b,c,x,y=map(int,input().split())
if a+b<=2*c:
    print(a*x+b*y)
else:
    print(c*2*min(x,y)+min(max(a*(x-y),b*(y-x)),c*2*abs(x-y)))

Buggy submission (verdict: Runtime Error):
d= a*x+b*y
e= 2*c*x+b*max(0,y-x) #yが多い
f= 2*c*y+a*max(0,x-y) #xが多い
print(min(d,e,f))
Problem p03399 (python)

Fixed submission:
a = int(input())
b = int(input())
c = int(input())
d = int(input())
print(min(a,b) + min(c,d))

Buggy submission (verdict: Runtime Error):
a, b, c, c = [int(input()) for i in range(4)]
print(min(a,b) + min(c,d))
Problem p03424 (python)

Fixed submission:
n = int(input())
x = set(input().split())
if len(x)==3:
    print('Three')
else:
    print('Four')

Buggy submission (verdict: Runtime Error):
n = int(input())
x = sorted(map(int,input().split()))
x.reverse()
a = 0
b = 0
for i in range(n):
    if i%2==0:
        a+=x[i]
    else:
        b+=x[i]
print(a-b)

Buggy submission (verdict: Runtime Error):
n = int(input())
x = sorted(map(int,input().split()))
x.reverse()
a = 0
b = 0
for i in range(n):
    if i%2==0:
        a+=x[i]
    else:
        b+=x[i]
print(a-b)

Buggy submission (verdict: Runtime Error):
n = int(input())
x = list(reversed(sorted(map(int,input().split()))))
a = 0
b = 0
for i in range(n):
    if i%2==0:
        a+=x[i]
    else:
        b+=x[i]
print(a-b)
Problem p03474 (python)

Fixed submission:
a,b = list(map(int,input().split()))
s =input()
for i in range(a+b+1):
    if i == a:
        if s[i] !='-':
            print('No')
            break
    else:
        if s[i]=='-':
            print("No")
            break
            
        else:
            if int(s[i])<0 or 9<int(s[i]):
                print("No")
                break
else:
    print('Yes')

Buggy submission (verdict: Runtime Error):
a,b = list(map(int,input().split()))
s =input()
for i in range(a+b+1):
    if i != a:
        if int(s[i])>=10:
            print("No")
            break
            
    else:
        if s[i] !='-':
            print('No')
            break
else:
    print('Yes')
Problem p03544 (python)

Fixed submission:
n = int(input())
a = 2
b = 1
for i in range(n-1):
    c=b+a
    a,b=b,c
if n == 0:
    print(a)
elif n == 1:
    print(b)
else:
    print(c)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = 2
b = 1
for i in range(n-1):
    c=b+a
    a,b=b,c
print(c)
Problem p03623 (python)

Fixed submission:
x,a,b = map(int, input().split())
if abs(x - a) > abs(x - b):
    print('B')
else:
    print('A')

Buggy submission (verdict: Runtime Error):
a, b, c = map(int, input().split())
if abs(x - a) > abs(x - b):
    print('B')
else:
    print('A')

Buggy submission (verdict: Runtime Error):
a, b, c = map(int, input().split())
if abs(x - a) > abs(x - b):
    print('B')
else:
    print('A')
Problem p03624 (python)

Fixed submission:
s = sorted(set(input()))
a = len(set(s))
s.append(0)
for i in range(26):
    if s[i] != chr(97+i):
        print(chr(97+i))
        break
else:
    print('None')

Buggy submission (verdict: Runtime Error):
s = sorted(set(input()))
for i in range(26):
    if s[i] != chr(97+i):
        print(chr(97+i))
        break
else:
    print('None')
Problem p03657 (python)

Fixed submission:
a, b = map(int, input().split())
if a%3 == 0 or b%3 == 0 or (a+b)%3 == 0:
    print('Possible')
else:
    print('Impossible')

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split())
if a%3 = 0 or b%3 == 0 or (a+b)%3 == 0:
    print('Possible')
else:
    print('Impossible')
Problem p03720 (python)

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

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
x =[0]*n
for i in range(m):
    a,b = map(int,input().split())
    x[a-1]+=1
    x[b-1]+=1
for i in range(n):
    print(x[i]

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
x =[0]*n
for i in range(m):
    a,b = map(int,input().split())
    x[a-1]+=1
    x[b-1]+=1
for i in range(n):
    print(x[i]
Problem p03760 (python)

Fixed submission:
a = list(input())
b = list(input())
f = False
x = []
if len(a)> len(b):
    b.append(0)
    f = True
for i in range(len(a)):
    x.append(a[i])
    x.append(b[i])
if f:
    x.pop()
print("".join(x))

Buggy submission (verdict: Runtime Error):
a = input()
b = input()
f = False
x = []
if len(a)> len(b):
    b.append(0)
    f = True
for i in range(len(a)):
    x.append(a[i]+b[i])
if f:
    x.pop()
print("".join(x))

Buggy submission (verdict: Runtime Error):
a = input()
b = input()
f = False
x = []
if len(a)> len(b):
    b.append(0)
    f = True
for i in range(len(a)):
    x.append(a[i]+b[i])
if f:
    x.pop()
print("".join(x))

Buggy submission (verdict: Runtime Error):
a = input()
b = input()
f = False
x = []
if len(a)> len(b):
    b.append(0)
    f = True
for i in range(len(a)):
    x.append(a[i]+b[i])
if f:
    x.pop()
print("".join(x))
Problem p03853 (python)

Fixed submission:
h,w = map(int,input().split())
for i in range(h):
    x = input()
    print(x)
    print(x)

Buggy submission (verdict: Runtime Error):
IN = iter(Input.split('\n')).__next__
def input():
    return IN()


h,w = map(int,input().split())
for i in range(h):
    x = input()
    print(x)
    print(x)
Problem p03944 (python)

Fixed submission:
w,h,n = map(int,input().split())
b,c,d,e = 0,w,0,h
for i in range(n):
    x,y,a = map(int,input().split())
    if a == 1:
        b = max(b,x)
    elif a == 2:
        c = min(c,x)
    elif a == 3:
        d = max(d,y)
    else:
        e = min(e,y)
print(max(c-b,0)*max(e-d,0))

Buggy submission (verdict: Runtime Error):
w,h,n = map(int,input().split())
b,c,d,e = 0,w,0,h
for i in range(a):
    x,y,a = map(int,input().split())
    if a == 1:
        b = max(b,x)
    elif a == 2:
        c = min(c,x)
    elif a == 3:
        d = max(d.y)
    else:
        e = min(e,y)
print(max(c-b,0)*max(e-d,0))

Buggy submission (verdict: Runtime Error):
w,h,n = map(int,input().split())
b,c,d,e = 0,w,0,h
for i in range(n):
    x,y,a = map(int,input().split())
    if a == 1:
        b = max(b,x)
    elif a == 2:
        c = min(c,x)
    elif a == 3:
        d = max(d.y)
    else:
        e = min(e,y)
print(max(c-b,0)*max(e-d,0))

Buggy submission (verdict: Runtime Error):
w,h,n = map(int,input().split())
b,c,d,e = 0,w,0,h
for i in range(n):
    x,y,a = map(int,input().split())
    if a == 1:
        b = max(b,x)
    elif a == 2:
        c = min(c,x)
    elif a == 3:
        d = max(d.y)
    else:
        e = min(e,y)
print(max(c-b,0)*max(e-d,0))

Buggy submission (verdict: Runtime Error):
w,h,n = map(int,input().split())
b,c,d,e = 0,w,0,h
for i in range(n):
    x,y,a = map(int,input().split())
    if a == 1:
        b = max(b,x)
    elif a == 2:
        c = min(c,x)
    elif a == 3:
        d = max(d.y)
    else:
        e = min(e,y)
print(max(c-b,0)*max(e-d,0))
Problem p03971 (python)

Fixed submission:
n,x,y=map(int,input().split())
s= input()
c=0
d=x+y
e = 0
f= False
for i in range(n):
    if s[i]=="a":
        if c<d:
            f=True
    elif s[i]=="b":
        if c<d and e<y:
            f=True
            e+=1
    if f:
        print("Yes")
        c+=1
    else:
        print("No")
    f=False

Buggy submission (verdict: Runtime Error):
n,x,y=map(int,input().split())
s= input()
c=0
d=x+y
f= False
for i in range(n):
    if s[i]=="A":
        if c<d:
            f=True
    elif s[i]=="B":
        if c<d and c<=b:
            f=True
    if f:
        print("YES")
            c+=1
    else:
        print("NO")
    f=False
Problem p04033 (python)

Fixed submission:
a,b = map(int,input().split())
if a*b<=0:
    print("Zero")
elif b<0 and(b-a)%2==0:
    print("Negative")
else:
    print("Positive")

Buggy submission (verdict: Runtime Error):
a,b = map(int,input().split())
c= (b-a+1)*(a+b)//2
if c>0:
    print("Positive")
elif c=0:
    print("Zero")
else:
    print("Negative")
Problem p02651 (python)

Fixed submission:
T=int(input())
for _ in range(T):
    N = int(input())
    A = list(map(int, input().split()))
    S = list(map(int, input()))

    for i in range(N-1, -1, -1):
        ai = A[i]
        if ai==0:
            continue
        top = ai.bit_length() - 1

        #assert ai & 1<<top
        for j in range(i-1, -1, -1):
            if A[j] >> top & 1:
                A[j] ^= ai
    #print(A,S)
    for a, c in zip(A[::-1], S[::-1]):
        if c==1 and a:
            break
    else:
        print("0")
        continue
    print("1")

Buggy submission (verdict: Runtime Error):
T=int(input()
for _ in range(T):      
    N = int(input())
    A = list(map(int, input().split()))
    S = list(map(int, input()))

    for i in range(N-1, -1, -1):
        ai = A[i]
        if ai==0:
            continue
        top = ai.bit_length() - 1

        #assert ai & 1<<top
        for j in range(i-1, -1, -1):
            if A[j] >> top & 1:
                A[j] ^= ai
    print(A,S)
    for a, c in zip(A[::-1], S[::-1]):
        if c==1 and a:
            break
    else:
        print("0")
        continue
    print("1")
Problem p02678 (python)

Fixed submission:
from collections import deque

N, M = map(int, input().split())
d = [set() for _ in range(N+1)]
for _ in range(M):
    a, b = map(int, input().split())
    d[a].add(b)
    d[b].add(a)

queue=deque([1])
vs = set([1])
parents = [0] * (N+1)
while queue:
    v = queue.popleft()
    for u in d[v]:
        if u in vs:
            continue
        parents[u] = v
        vs.add(u)
        queue.append(u)
print("Yes")
for x in parents[2:]:
    print(x)

Buggy submission (verdict: Runtime Error):
from collections import deque
n,m = map(int,input().split())
G = [set() for _ in range(n)]
for _ in range(m):
    a,b = map(int,input().split())
    G[a-1].add(b-1)
    G[b-1].add(a-1)
ans = [-1 for _ in range(n)]

ans[0]=0
q = deque([0])
q2 = deque()

seen = set()
seen.add(0)

for _ in range(n):
    while q:
        q2 = deque()
        #print(ans,q,q2,seen)
        i = q.pop()
        for j in G[i]:
            if j in seen:
                continue
            q2.append(j)
            ans[j] = i+1
            seen.add(j)
            '''if cost[i] ==-1:
                cost[i] = c
                ans[i] = j
            elif cost[i] > cost[j] + 1:
                cost[i] = cost[j] + 1
                ans[i] = j
            else:
                pass'''
    q = q2
    if len(seen) == n:
        print("Yes")
        print(*ans[1:], sep="\n")
        sys.exit()
        
print("No")
Problem p02684 (python)

Fixed submission:
import sys
n,k=map(int,input().split())
A=[int(i) for i in input().split()]
d=dict()
for i,a in enumerate(A):
    d[i+1] = a
p=1
li = set()
li.add(1)
for i in range(k):
    #print(p,li)
    p = d[p]
    #print(p,li)
    if p in li:
        cyc =  i + 1
        q = 1
        st=0
        while q != p:
            q = d[q]
            st+=1
        cyc -=st
        k = (k-st) % cyc + st
        r = 1
        #print(k)
        for _ in range(k):
            #print(r)
            r = d[r]
        print(r)
        sys.exit()
    li.add(p)
else:
    print(p)

Buggy submission (verdict: Runtime Error):
import sys
n,k=map(int,input().split())
A=[int(i) for i in input().split()]
d=dict()
for i,a in enumerate(A):
    d[i+1] = a
p=1
li = set()
li.add(1)
for i in range(k):
    #print(p,li)
    p = d[p]
    #print(p,li)
    if p in li:
        cyc =  i+ 1- pidx
        q = 1
        st=0
        while q != p:
            q = d[q]
            st+=1
        k = (k-st) % cyc + st
        r = 1
        #print(k)
        for _ in range(k):
            #print(r)
            r = d[r]
        print(r)
        sys.exit()
    li.add(p)
else:
    print(p)
Problem p02686 (python)

Fixed submission:
import sys
n = int(input())
ss =[]
for _ in range(n):
    ss.append(input())
cnt_p = []
cnt_m = []
for i in range(n):
    left = 0
    right = 0
    for s in ss[i]:
        if(s == '('):
            left += 1
        elif(s == ')'):
            if(left > 0):
                left -= 1
            else:
                right += 1
    if(left-right > 0):
        cnt_p.append((right,left))
    else:
        cnt_m.append((right,left))
 
 
cnt_p = sorted(cnt_p, key=lambda x: (x[0]))
cnt_m = sorted(cnt_m, key=lambda x: (x[1]*-1))
cnt = cnt_p + cnt_m
num = 0
for right,left in cnt:
    num -= right
    if(num < 0):
        print('No')
        sys.exit()
    num += left
if(num==0):
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
import sys
n = int(input())
ss =[]
for _ in range(n):
    ss.apend(input())
cnt_p = []
cnt_m = []
for i in range(n):
    left = 0
    right = 0
    for s in ss[i]:
        if(s == '('):
            left += 1
        elif(s == ')'):
            if(left > 0):
                left -= 1
            else:
                right += 1
    if(left-right > 0):
        cnt_p.append((right,left))
    else:
        cnt_m.append((right,left))
 
 
cnt_p = sorted(cnt_p, key=lambda x: (x[0]))
cnt_m = sorted(cnt_m, key=lambda x: (x[1]*-1))
cnt = cnt_p + cnt_m
num = 0
for right,left in cnt:
    num -= right
    if(num < 0):
        print('No')
        sys.exit()
    num += left
if(num==0):
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
import sys
n=int(input())
lrp=[]
lrm=[]
def g(s):
    i = 0
    l = [0]
    for j in s:
        if j =="(":
            i += 1
        else:
            i -= 1
        l.append(i)
    return min(l),max(l)
for _ in range(n):
    s = input()
    l = s.count("(")
    r = len(s) - l
    mi,ma =g(s)
    if l>r:
        lrp.append((l,r))
    else:
        lrm.append((l,r))
    lr.append((mi,ma,l,r))
    
lrp.sort(key=lambda x:x[0])
lrm.sort(key=lambda x:-x[1])
lr=lrp+lrm
cnt = 0
for l,r in lr:
    cnt -= r
    if cnt >=0:
        cnt += l
    else:
        print("No")
        sys.exit()
if cnt !=0:
    print("No")
else:
    print("Yes")

Buggy submission (verdict: Runtime Error):
import sys
n=int(input())
lr=[]
def g(s):
    i = 0
    l = [0]
    for j in s:
        if j =="(":
            i += 1
        else:
            i -= 1
        l.append(i)
    return min(l),max(l)
for _ in range(n):
    s = input()
    l = s.count("(")
    r = len(s) - l
    l_sum += l
    r_sum += r
    mi,ma =g(s)
    lr.append((mi,ma,l,r))
    
cnt = 0
for mi,ma,l,r in lr:
    #print(cnt)
    if cnt+mi>=0:
        cnt += (l-r)
    else:
        print("No")
        sys.exit()
if cnt !=0:
    print("No")
else:
    print("Yes")
Problem p02696 (python)

Fixed submission:
a,b,n=map(int,input().split())
if n>=b-1:
  print(a*(b-1)//b)
else:
  print(a*n//b)

Buggy submission (verdict: Runtime Error):
a, b, n = map(int, input().split())
 
x = min(b - 1, n)
print(int(a * x / b) - a * int(x / b))

import random
a,b,n=map(int,input().split())
def f(x):
    return int(a*x/b)-a*int(x/b)
if n<b:
    ans =f(n)
else:
    t = n
    u = b - 1
    v=min(t,u)
    ans=f(v)
print(ans)
Problem p02702 (python)

Fixed submission:
from collections import Counter
S=list(map(int,input()))
P=2019
N=len(S)
if P not in [2,5]:
  pt = [1]
  for i in range(N):
    pt.append(pt[-1]*10%P)
  dp = [(S[0]*pt[N-1])%P]
  for i in range(1,N):
    dp.append((dp[-1]+S[i]*pt[N-1-i])%P)

  c = Counter(dp)
  ans = sum(u*(u-1)//2 for u in c.values())
  print(ans+c[0])
elif P==2:
  S = [int(c) for c in input()]
  ans = 0
  for i in range(N):
    if S[i]%2==0:
      ans += i+1
  print(ans)
else:
  ans = 0
  S = [int(c) for c in input()]
  for i in range(N):
    if S[i]%5==0:
      ans += i+1
  print(ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter
N, P = map(int, input().split())
S=list(map(int,input()))
P=2019
N=len(S)
if P not in [2,5]:
  pt = [1]
  for i in range(N):
    pt.append(pt[-1]*10%P)
  dp = [(S[0]*pt[N-1])%P]
  for i in range(1,N):
    dp.append((dp[-1]+S[i]*pt[N-1-i])%P)

  c = Counter(dp)
  ans = sum(u*(u-1)//2 for u in c.values())
  print(ans+c[0])
elif P==2:
  S = [int(c) for c in input()]
  ans = 0
  for i in range(N):
    if S[i]%2==0:
      ans += i+1
  print(ans)
else:
  ans = 0
  S = [int(c) for c in input()]
  for i in range(N):
    if S[i]%5==0:
      ans += i+1
  print(ans)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
s=input()
d=defaultdict(int)
l.insert(0,0)
for i in range(1,len(s)+1):
    d[int(s[-i:])%2019] += 1
ans=0
for v in d.values():
    ans += v*(v-1)//2
print(ans)
Problem p02796 (python)

Fixed submission:
n=int(input())
itv=[]
for _ in range(n):
    x,l=map(int,input().split())
    itv.append((x+l,x-l))
itv.sort()
ass = 0
tt = -float("inf")
for i in range(n):
    if tt <= itv[i][1]:
        ass += 1
        tt = itv[i][0]
print(ass)

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

@lru_cache(maxsize=1000)
def judge(x,L):
    for l in L:
        if x[1]>l[0] and x[0] <l[1]:
            return False
    else:
        return True

n=int(input())
X=[]
L=[]
A=[]
B=[]
for _ in range(n):
    x,l=map(int,input().split())
    X.append(x)
    L.append(l)
    A.append(x-l)
    B.append(x+l)
k = zip(L,X,A,B)
k = sorted(k, key=lambda x:(x[1], x[2]))
c=1
ans=[]
ans.append((k[0][2],k[0][3]))

for i in range(1,n):
    x=(k[i][2],k[i][3])
    if judge(x,ans):
        ans.append(x)
        c+=1
print(c)

Buggy submission (verdict: Runtime Error):
n=int(input())
#X=[]
#L=[]
A=[]
B=[]
for _ in range(n):
    x,l=map(int,input().split())
    X.append(x)
    L.append(l)
    A.append(x-l)
    B.append(x+l)
k = zip(A,B,L)
k = sorted(k, key=lambda x:(x[0], x[2]))
c=1
ans=[]
ans.append((k[0][0],k[0][1]))

max_=k[0][1]
def judge(x,L):
    for l in L:
        if x[1]>l[0] and x[0] <l[1]:
            return False
    else:
        return True
for i in range(1,n):
    x=(k[i][0],k[i][1])
    if x[0] >= max_:
        c+=1
        max_=x[0]
    #print(c,max_,x)
print(c)

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

def swap(i,P,Q):
    Q[i+1],Q[i],P[i+1],P[i]=P[i],P[i+1],Q[i],Q[i+1]
    return P,Q

def judge(P):
    for i in range(len(P)-1):
        if P[i]>P[i+1]:
            return False
    else:
        return True

N=int(input())
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]
flag=False
if judge(A):
    print(0)
    sys.exit()
for l in itertools.permutations(range(0,N-1)):
    if flag:
        break
    T=copy(A)
    Y=copy(B)
    count = 0
    for i in l:
        T,Y=swap(i,T,Y)
        count += 1
        if judge(T):
            ans = l
            flag=True
            print(count)
            break
else:
    print(-1)
    sys.exit()
#T=copy(A)
#Y=copy(B)
#print(T,Y)
#for i in ans:
#    T,Y=swap(i,T,Y)
#    print(T,Y)

Buggy submission (verdict: Runtime Error):
n=int(input())
X=[]
L=[]
A=[]
B=[]
for _ in range(n):
    x,l=map(int,input().split())
    X.append(x)
    L.append(l)
    A.append(x-l)
    B.append(x+l)
k = zip(L,X,A,B)
k = sorted(k, key=lambda x:(x[1], x[2]))
c=1
ans=[]
ans.append((k[0][2],k[0][3]))
for i in range(1,n):
    x=(k[i][2],k[i][3])
    if judge(x,ans):
        ans.append(x)
        c+=1
print(c)
Problem p02852 (python)

Fixed submission:
import sys
n,m=map(int,input().split())
S=list(map(int,list(input())))
if m > n:
    m = n
idx = n
ans=[]
while idx > 0:
    for i in range(1,m+1)[::-1]:
        #print(i,idx,idx-i,S[idx-i])
        if S[idx-i] == 0 and idx-i>=0:
            idx -= i
            ans.append(i)
            break
    else:
        print(-1)
        sys.exit()
print(*ans[::-1])

Buggy submission (verdict: Runtime Error):
import sys
n,m=map(int,input().split())
S=list(map(int,list(input())))

idx = n
ans=[]
while idx > 0:
    for i in range(1,m+1)[::-1]:
        #print(i,idx,idx-i,S[idx-i])
        if S[idx-i] == 0 and idx-i>=0:
            idx -= i
            ans.append(i)
            break
    else:
        print(-1)
        sys.exit()
print(*ans[::-1])
Problem p02861 (python)

Fixed submission:
import math
import itertools
def length(X,Y,c):
    sum_=0
    for i in range(len(c)-1):
        sum_+=math.sqrt((X[c[i]]-X[c[i+1]])**2 + (Y[c[i]]-Y[c[i+1]])**2)
    #print(sum_)
    return sum_
N=int(input())
X=[0]*N
Y=[0]*N
for i in range(N):
    X[i], Y[i] = map(int,input().split())
C = list(itertools.permutations(range(0,N)))
sum_=0
for c in C:
    sum_+=length(X,Y,c)
print(sum_/len(C))

Buggy submission (verdict: Runtime Error):
import math
def length(X,Y,c):
    sum_=0
    for i in range(len(c)-1):
        sum_+=math.sqrt((X[c[i]]-X[c[i+1]])**2 + (Y[c[i]]-Y[c[i+1]])**2)
    #print(sum_)
    return sum_
N=int(input())
X=[0]*N
Y=[0]*N
for i in range(N):
    X[i], Y[i] = map(int,input().split())
C = list(itertools.permutations(range(0,N)))
sum_=0
for c in C:
    sum_+=length(X,Y,c)
print(sum_/len(C))