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

Fixed submission:
X, Y = map(int, input().split())
mod = 10 ** 9 + 7

if (X + Y) % 3 == 0 : 
    n = (X + Y) // 3
    a = 2 * n - X
    
    if 0 <= a <= n and a * 2 + (n - a) == Y :
        fac = [1]
        inv = [1]
        for i in range(1, n + 1) :
            fac.append(fac[-1] * i % mod)
            inv.append(pow(fac[-1], mod - 2, mod))
        print(fac[n] * inv[n-a] * inv[a] % mod)
    
    else :
        print(0)
        
else :
    print(0)

Buggy submission (verdict: Runtime Error):
X, Y = map(int, input().split())
mod = 10 ** 9 + 7

if (X + Y) % 3 == 0 : 
    n = (X + Y) // 3
    a = 2 * n - X
    
    if 0 <= a <= N and a * 2 + (n - a) == Y :
        fac = [1]
        inv = [1]
        for i in range(1, n + 1) :
            fac.append(fac[-1] * i % mod)
            inv.append(pow(fac[-1], mod - 2, mod))
        print(fac[n] * inv[n-a] * inv[a] % mod)
    
    else :
        print(0)
        
else :
    print(0)

Buggy submission (verdict: Runtime Error):
X, Y = map(int, input().split())
mod = 10 ** 9 + 7

if (X + Y) % 3 == 0 : 
    n = (X + Y) // 3
    a = 2 * n - X
    
    if a * 2 + (n - a) == Y :
        fac = [1]
        inv = [1]
        for i in range(1, n + 1) :
            fac.append(fac[-1] * i % mod)
            inv.append(pow(fac[-1], mod - 2, mod))
        print(fac[n] * inv[n-a] * inv[a] % mod)
    
    else :
        print(0)
        
else :
    print(0)
Problem p02948 (python)

Fixed submission:
from heapq import heappush, heappop

N, M = map(int, input().split())
AB = [[] for _ in range(M+1)]

for _ in range(N) :
    a, b = map(int, input().split())
    if a <= M :
        AB[M-a].append(b)
    
q = []
for a in range(M+1) :
    for b in AB[a] :
        heappush(q, b)
        if len(q) > a + 1 :
            heappop(q)
            
print(sum(q))

Buggy submission (verdict: Runtime Error):
from heapq import heappush, heappop

N, M = map(int, input().split())
AB = [[] for _ in range(M)]

for _ in range(N) :
    a, b = map(int, input().split())
    if a <= M :
        AB[M-a].append(b)
    
q = []
for a in range(M+1) :
    for b in AB[a] :
        if len(q) < a + 1 :
            heappush(q, b)
        else :
            heappop(q)
            heappush(q, b)
            
print(sum(q))
Problem p02964 (python)

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

N, K = map(int, input().split())
A = [int(i) for i in input().split()]

last = dict()
v = [-1] * N

for i, a in enumerate(A + A) :
    if a in last and last[a] < N :
        v[last[a]] = i + 1
    
    last[a] = i

dist = [-1] * N
cur = 0
cycle = 0
while dist[cur] < 0 :
    dist[cur] = cycle 
    cycle += v[cur] - cur
    cur = v[cur] % N

NK = N * K

m = NK % cycle
cur = v[cur] % N
s = 0
while m > dist[cur] > 0 :
    s = dist[cur]
    cur = v[cur] % N
m -= s

ret = []
seen = set()
for a in A[N-m:] :
    if a in seen :
        p = ret.pop()
        seen.remove(a)
        while p != a :
            seen.remove(p)
            p = ret.pop()
    else :
        ret.append(a)
        seen.add(a)
        
print(' '.join([str(i) for i in ret]))

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

N, K = map(int, input().split())
A = [int(i) for i in input().split()]

last = dict()
v = [-1] * N

for i, a in enumerate(A + A) :
    if a in last and last[a] < N :
        v[last[a]] = i + 1
    
    last[a] = i

dist = [-1] * N
cur = 0
cycle = 0
while dist[cur] < 0 :
    dist[cur] = cycle 
    cycle += v[cur] - cur
    cur = v[cur] % N

NK = N * K

m = NK % cycle
cur = v[cur] % N
s = 0
while m > dist[cur] > 0 :
    s = dist[cur]
    cur = v[cur] % N
m -= s

ret = []
seen = set()
for a in A[N-m:] :
    if a in seen :
        p = ret.pop()
        while p != a :
            seen.remove(p)
            p = ret.pop()
    else :
        ret.append(a)
        seen.add(a)
        
print(' '.join([str(i) for i in ret]))
Problem p03201 (python)

Fixed submission:
from collections import Counter
N = int(input())
A = [int(i) for i in input().split()]

c = Counter(A)
b = sorted(c.keys())

ret = 0
for j in range(len(c) - 1, -1, -1) :
    i = 2
    while c[b[j]] > 0 and i - b[j] <= b[j] :
        if b[j] != i - b[j] :
            if c[b[j]] > 0 and c[i-b[j]] > 0 :
                M = min(c[b[j]], c[i-b[j]])
                ret += M
                c[b[j]] -= M
                c[i-b[j]] -= M
        else :
            if c[b[j]] > 1 :
                ret += c[b[j]] // 2
                c[b[j]] %= 2
        i *= 2
    
print(ret)

Buggy submission (verdict: Runtime Error):
from collections import Counter
N = int(input())
A = [int(i) for i in input().split()]

c = Counter(A)
b = sorted(c.keys())

ret = 0

j = len(b) - 1
for j in range(N - 1, -1, -1) :
    i = 2
    while c[b[j]] > 0 and i - b[j] <= b[j] :
        if b[j] != i - b[j] :
            if c[b[j]] > 0 and c[i-b[j]] :
                M = max(c[b[j]], c[i-b[j]])
                ret += M
                c[b[j]] -= M
                c[i-b[j]] -= M
        else :
            if c[b[j]] > 1 :
                ret += c[b[j]] // 2
                c[b[j]] %= 2
        i *= 2
    
print(ret)
Problem p03464 (python)

Fixed submission:
K = int(input())
A = [int(i) for i in input().split()]

def solve() :            
    m, M = 2, 2
    for a in A[::-1] :
        if (m - 1) // a == M // a :
            return [-1]
            
        M = M // a * a + a - 1
        x = (m + a - 1) // a
        m = a * x
        
    return [m, M]
    
print(*solve())

Buggy submission (verdict: Runtime Error):
K = int(input())
A = [int(i) for i in input().split()]

def solve() :
    A.pop()

    m, M = 2, 2
    for a in A[::-1] :
        x = (2 * M - 1) // a
        if a * x < M :
            return [-1]
        M = a * x
      
    return [M, M + A[0] - 1]
    
print(*solve())

Buggy submission (verdict: Runtime Error):
K = int(input())
A = [int(i) for i in input().split()]

A.pop()

m, M = 2, 2
for a in A[::-1] :
    x = (2 * M - 1) // a
    M = a * x
  
if M >= 2 :
    print(M, M + A[0] - 1)
else :
    print(-1)
Problem p02596 (python)

Fixed submission:
K = int(input())

if K % 2 == 0 or K % 5 == 0:
  print(-1)
else:
  if K % 7 == 0:
    L = 9 * K // 7
  else:
    L = 9 * K
  a = 10 % L
  check = False
  for i in range(L):
    a %= L
    if a == 1:
      print(i + 1)
      check = True
      break
    a *= 10
  if not check:
    print(-1)

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

if K % 2 == 0　or K % 5 == 0:
  print(-1)
else:
  if K % 7 == 0:
    L = 9 * K // 7
  else:
    L = 9 * K
  a = 10 % L
  check = False
  for i in range(L):
    a %= L
    if a == 1:
      print(i + 1)
      check = True
      break
    a *= 10
  if not check:
    print(-1)
Problem p02623 (python)

Fixed submission:
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

A_dp = [0] * (N + 1)
B_dp = [0] * (M + 1)

for i in range(1,N+1):
  if i == 1:
    A_dp[i] += A[i-1]
    continue
  A_dp[i] += A_dp[i-1] + A[i-1]
  
for j in range(1,M+1):
  if j == 1:
    B_dp[j] += B[j-1]
    continue
  B_dp[j] += B_dp[j-1] + B[j-1]
  
cnt = 0
j = M

for i in range(N+1):
  if A_dp[i] > K:
    continue
  while A_dp[i] + B_dp[j] > K:
    j -= 1
  cnt = max(cnt, i+j)
  
print(cnt)

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

A_dp = [0] * (N + 1)
B_dp = [0] * (M + 1)

for i in range(1,N+1):
  if i == 1:
    A_dp[i] += A[i-1]
    continue
  A_dp[i] += A_dp[i-1] + A[i-1]
  
for j in range(1,M+1):
  if j == 1:
    B_dp[j] += B[j-1]
    continue
  B_dp[j] += B_dp[j-1] + B[j-1]
  
a = N
b = 0

minute = A_dp[a] + B_dp[b]
if K > minute:
  while K >= A_dp[a] + B_dp[b]:
    b += 1
else:
  while K < A_dp[a] + B_dp[b]:
    a -= 1
  
cnt = a + b
for k in range(a,-1,-1):
  while A_dp[k] + B_dp[b] < K:
    if b == M - 1:
      break
    b += 1
  b -= 1
  if cnt < k + b:
    cnt = k + b
    
print(cnt)
Problem p02629 (python)

Fixed submission:
n = int(input())
chars = "Xabcdefghijklmnopqrstuvwxyz"  # x番目がほしいときにchars[x-1]としたくないので、chars[0]は使わないことにします

n_rem = n  # 入力を直接操作すると、もし後々必要になったときに面倒なので
res = ""
while True:
  x = n_rem % 26
  if x == 0:
    x = 26
  res += chars[x]
  n_rem -= x
  
  if n_rem == 0:
    break
  n_rem //= 26
print(res[::-1])

Buggy submission (verdict: Runtime Error):
N = int(input())
chars = "Xabcdefghijklmnopqrstuvwxyz"  # x番目がほしいときにchars[x-1]としたくないので、chars[0]は使わないことにします

n_rem = n  # 入力を直接操作すると、もし後々必要になったときに面倒なので
res = ""
while True:
  x = n_rem % 26
  if x == 0:
    x = 26
  res += chars[x]
  n_rem -= x
  
  if n_rem == 0:
    break
  n_rem //= 26
print(res[::-1])

Buggy submission (verdict: Runtime Error):
N = int(input())
chars = "Xabcdefghijklmnopqrstuvwxyz"  # x番目がほしいときにchars[x-1]としたくないので、chars[0]は使わないことにします

n_rem = n  # 入力を直接操作すると、もし後々必要になったときに面倒なので
res = ""
while True:
  x = N % 26
  if x == 0:
    x = 26
  res += chars[x]
  n_rem -= x
  
  if n_rem == 0:
    break
  n_rem //= 26
print(res[::-1])
Problem p02779 (python)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
A.sort()

check = True
for i in range(N-1):
  if A[i] == A[i+1]:
    check = False
    
print("YES" if check else "NO")

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

check = True
for i in range(A):
  if A.count(A[i]) > 1:
    check = False
    
print("Yes" if check else "No")
Problem p02790 (python)

Fixed submission:
a,b = map(int,input().split())
ls = [str(a) * b, str(b) * a]
ls.sort()
print(ls[0])

Buggy submission (verdict: Runtime Error):
a,b = int(input())
ls = [str(a) * b, str(b) * a]
ls.sort()
print(ls[0])
Problem p02859 (python)

Fixed submission:
r = int(input())
print(r*r)

Buggy submission (verdict: Runtime Error):
print(r*r)
Problem p02989 (python)

Fixed submission:
N = int(input())
D = list(map(int,input().split()))
D.sort()

M = N//2
ans = D[M] - D[M-1]

if D[M] == D[M-1]:
  ans = 0

print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
D = list(map(int,input().split()))
D.sort()

M = N//2
ans = D[M] - D[M-1]

if D[M] == D[M-1] or (D[M] == D[M+1] and D[M-1] == D[M-2] and D[M] == D[M-1]+1):
  ans = 0

print(ans)
Problem p02623 (python)

Fixed submission:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
cumA = [0] * (N+1)
cumB = [0] * (M+1)

point = 0
for i in range(N):
    cumA[i+1] = cumA[i] + A[i]
for i in range(M):
    cumB[i+1] = cumB[i] + B[i]

# 尺取りの要領でiを増やしjを減らす
res, j = 0, M
for i in range(N+1):
    if cumA[i] > K:
        break
    while cumB[j] > K - cumA[i]:
        j -= 1
    res = max(res, i+j)

print(res)

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

ai = 0
bi = 0

def read(ai, bi, count, rest):
    if rest <= 0:
        return count
    else:
        if ai >= N:
            a_c = count
        else:
            if rest >= A[ai]:
                a_c = read(ai+1, bi, count+1, rest - A[ai])
            else:
                a_c = count

        if bi >= M:
            b_c = count
        else:
            if rest >= B[bi]:
                b_c = read(ai, bi+1, count+1, rest - B[bi])
            else:
                b_c = count

        return max(a_c, b_c)

res = read(ai,bi,0,K)
print(res)

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

ai = 0
bi = 0

def read(ai, bi, count, rest):
    if rest <= 0:
        return count
    else:
        if ai >= N:
            a_c = count
        elif rest >= A[ai]:
            a_c = read(ai+1, bi, count+1, rest - A[ai])
        else:
            a_c = count

        if bi >= M:
            b_c = count
        elif rest >= B[bi]:
            b_c = read(ai, bi+1, count+1, rest - B[bi])
        else:
            b_c = count

        return max(a_c, b_c)

res = read(ai,bi,0,K)
print(res)
Problem p02659 (python)

Fixed submission:
#!/usr/bin/env python3
A, B = [s for s in input().split()]
A = int(A)
B = round(float(B) * 100)
 
print(str(A * B // 100))

Buggy submission (verdict: Runtime Error):
from sys import stdin
import math
 
A, B = [x for x in input().split()]
A = int(A)
B = round(B*100)
 
print(A*B/100)

Buggy submission (verdict: Runtime Error):
from sys import stdin

A, B = [float(x) for x in stdin.readline().rstrip().split()]

print(int(a*b))
Problem p03038 (python)

Fixed submission:
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = []
for i in range(M):
    b, c = map(int, input().split())
    BC.append([b,c])

A = sorted(A)
BC = sorted(BC, key=lambda x:x[1], reverse=True)

a_itr = 0
bc_itr = 0
bc = BC[0]
while a_itr < N:
    if bc[0] == 0:
        bc_itr += 1
        if bc_itr < M:
            bc = BC[bc_itr]
        else:
            break
    else:
        if A[a_itr] < bc[1]:
            A[a_itr] = bc[1]
            a_itr += 1
            bc[0] -= 1
        else:
            break

print(sum(A))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = []
for i in range(M):
    b, c = map(int, input().split())
    BC.append([b,c])

A = sorted(A)
BC = sorted(BC, key=lambda x:x[1], reverse=True)

a_itr = 0
bc_itr = 0
bc = BC[0]
while bc_itr < N:
    if bc[0] == 0:
        bc_itr += 1
        if bc_itr < M:
            bc = BC[bc_itr]
        else:
            break
    else:
        if A[a_itr] < bc[1]:
            A[a_itr] = bc[1]
            a_itr += 1
            bc[0] -= 1
        else:
            break

print(sum(A))
Problem p02550 (python)

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

ans = 0
flag = [0]*(10**5 + 2)
lst = [X]

for i in range(N):
    X = (X**2)%M

    if flag[X] == 1:
        break

    flag[X] = 1
    lst.append(X)

preindex = lst.index(X)

preloop = lst[:preindex]
loop = lst[preindex:]

loopnum = (N - len(preloop))//len(loop)
loopafternum = (N - len(preloop))%len(loop)

ans = sum(preloop) + sum(loop)*loopnum + sum(loop[:loopafternum])
print(ans)

Buggy submission (verdict: Runtime Error):
N, X, M = map(int, input().split())

ans = 0
chck = 0
flag = [0]*(10**5 +1)
lst = [X]

for i in range(N):
    X = (X**2)%M

    if flag[X] == 1:
        break

    flag[X] = 1
    lst.append(X)

preindex = lst.index(X)

preloop = lst[:index]
loop = lst[index:]

loopnum = (N - len(preloop))//len(loop)
loopafternum = (N - len(preloop))%len(loop)

ans = sum(preloop) + sum(loop)*loopnum + sum(loop[:loopafternum])
print(ans)
Problem p02570 (python)

Fixed submission:
d,t,s=list(map(int, input().split()))
if s*t>=d:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
INF=10**9+7
D = [INF]*(10**6+1)
L = [True]*(10**6+1)
L[0] = False
L[1] = False
D[1] = 1
for i in range(2, 10**6+1):
    if L[i]:
        D[i] = i
        for j in range(i*2, 10**6+1, i):
            L[j] = False
            D[j] = min(i, D[j])


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


def factorization(n):
    if n == 1:
        return {1}
    ans = set()
    ans.add(D[n])
    factorization(n//D[n])
    return ans


N = int(input())
A = list(map(int, input().split()))

s = set(factorization(A[0])-{1})
for i in range(1, N):
    tmp = factorization(A[i])-{1}
    if tmp & s != set():
        break
    s |= tmp
else:
    print('pairwise coprime')
    exit()

L1 = A
while len(L1) > 1:
    l = len(L1)//2
    k = [0]*l
    for i in range(l):
        k[i] = egcd(L1[2*i], L1[2*i+1])
    if len(L1) % 2 == 1:
        k.append(L1[-1])
    L1 = k

if L1[0] == 1:
    print('setwise coprime')
else:
    print('not coprime')
Problem p02594 (python)

Fixed submission:
X=int(input())
if X>=30:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
N = int(input())
S = input()
countW = S.count('W')
if countW==0:
	print(0)
	exit()
if countW==N:
	print(0)
	exit()
leftW = S[:countW].count('W')
rightR = S[countW:].count('R')
print(max(leftW, rightR))
Problem p02596 (python)

Fixed submission:
#ABC_174_C_Respect_review.py

K = int(input())
ans = 1

if K % 2 == 0:
	print(-1)
	exit()
if K % 5 == 0:
	print(-1)
	exit()

temp = 7
for i in range(1*10**6):
	if temp % K == 0:
		print(ans)
		exit()
	res = temp % K
	temp = res*10 + 7
	ans += 1
print(-1)

Buggy submission (verdict: Runtime Error):
K = int(input())  # ぜんぜんちがう
ans = -1

def moduloseven(K):
	for i in range(1000):
		sev = int(str(7)*(i+1))
		if sev % K == 0:
			ans = i+1
			break
	return(ans)


if K % 2 != 0:
	if K % 5 != 0:
		ans = moduloseven(K)
print(ans)
Problem p02777 (python)

Fixed submission:
S,T=input().split()
s,t=list(map(int, input().split()))
U=input()
if U==S:
  print(s-1,t)
else:
  print(s,t-1)

Buggy submission (verdict: Runtime Error):
S,T=list(input())
s,t=list(map(int, input().split()))
U=input()
if U==S:
  print(s-1,t)
else:
  print(s,t-1)

Buggy submission (verdict: Runtime Error):
S,T=list(input())
s,t=list(map(int, input().split()))
U=input()
if U==S:
  print(s-1,t)
else:
  print(s,t-1
Problem p02779 (python)

Fixed submission:
N=int(input())
A=list(map(int, input().split()))
A.sort()
if N==1:
  print('YES')
  exit()
for i in range(N-1):
  if A[i]==A[i+1]:
    print('NO')
    exit()
else:
  print('YES')

Buggy submission (verdict: Runtime Error):
A=list(map(int, input().split()))
n=len(A)
A.sort()
for i in range(N-1):
  if A[i]==A[i+1]:
    print('NO')
    exit()
else:
  print('YES')
Problem p02832 (python)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
j=0
for i in range(N):
    if A[i]==j+1:
        j+=1

if j == 0:
    print(-1)
else:
    print(N-j)

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

for i in range(1, N+1):
    if i not in A:
        j = i-1
        break
    k = A.index(i)
    A = A[k+1:]

if j == 0:
    print(-1)
else:
    print(N-j)
Problem p02847 (python)

Fixed submission:
S=input()
date=['SUN','MON','TUE','WED','THU','FRI','SAT']

i=date.index(S)
print(7-i)

Buggy submission (verdict: Runtime Error):
S=input()
date=[SUN,MON,TUE,WED,THU,FRI,SAT]
i=date.index(S)
print(7-i)
Problem p02860 (python)

Fixed submission:
N=int(input())
S=input()
if N%2==1:
  print('No')
  exit()
n=N//2
for i in range(n):
  if S[i]!=S[n+i]:
    print('No')
    break
else:
  print('Yes')

Buggy submission (verdict: Runtime Error):
N=int(input())
S=input()
n=N//2
for i in range(m):
  if S[i]!=S[n+i]:
	print('No')
else:
  print('Yes')
Problem p02873 (python)

Fixed submission:
S=input()
N=len(S)+1
L=[0]*N
R=[0]*N
ans=[0]*N
for i in range(1,N):
    if S[i-1]=='<':
        L[i]=L[i-1]+1
    if S[N-i-1]=='>':
        R[N-i-1]=R[N-i]+1
for i in range(N):
    ans[i]=max(L[i], R[i])
print(sum(ans))

Buggy submission (verdict: Runtime Error):
S = input()
A = [0]*(len(S)+1)
for i in range(len(S)+1):
    L = S[:i]
    R = S[i:]
    print('L=', L)
    print('R=', R)
    l = 0
    r = 0
    if L != '':
        T = len(L)
        for k in range(T):
            if L[T-k-1] != '<':
                l = k
                break
        else:
            l = T
    if R != '':
        U = len(R)
        for j in range(U):
            if R[j] != '>':
                r = j
                break
        else:
            r = len(R)
    A[i] = max(l, r)
# print(A)
print(sum(A))
Problem p02951 (python)

Fixed submission:
A,B,C=list(map(int, input().split()))
print(max(C-(A-B),0))

Buggy submission (verdict: Runtime Error):
A,B,C=list(map(int, input().split()))
print(max(C-(A-B)),0)
Problem p03015 (python)

Fixed submission:
S = input()
C = 10**9+7
T = S[::-1]
N = len(S)
dp = [0]*N
dp[0] = 1+2*(int(T[0]))

for i in range(1, N):
    if T[i] == '0':
        dp[i] = dp[i-1]
    else:
        dp[i] = (pow(3, i, C)+2*dp[i-1]) % C
print(dp[-1])

Buggy submission (verdict: Runtime Error):
S = input()
C = 10**9+7


def answer(a):
    if a == '0' or a == '':
        return 1
    if a == '1':
        return 3
    if a[0] == '0':
        return answer(a[1:])
    else:
        b = a[1:]
        return (pow(3, (len(a)-1), C)+2*answer(b)) % C


print(answer(S))
Problem p03104 (python)

Fixed submission:
A,B=list(map(int, input().split()))
if A==B:
  print(A)
  exit()
a=A//4
b=B//4

def xorsum(L):
  if len(L)==1:
    return L[0]
  a=L[0]
  for i in range(1,len(L)):
    a^=L[i]
  return a

if a==b:
  L=[A+i for i in range(B-A+1)]
  print(xorsum(L))
  exit()
c=[a*4+i for i in range(4) if i>=A%4]
d=[b*4+i for i in range(4) if i<=B%4]
print(xorsum(c)^xorsum(d))

Buggy submission (verdict: Runtime Error):
A,B=list(map(int, input().split()))
if A==B:
  print(A)
  exit()
a=A//4
b=B//4

def xorsum(L):
  if len(L)==1:
    return L[0]
  a=L[0]
  for i in range(1,len(L)):
    a^=L[i]
  return a

if a==b:
  L=[A+i for i in range(B-A+1)]
  print(xorsum(A))
  exit()
c=[a*4+i for i in range(4) if i>=A%4]
d=[b*4+i for i in range(4) if i<=B%4]
print(xorsum(c)^xorsum(d))
Problem p02580 (python)

Fixed submission:
H,W,M=map(int,input().split())
Y=[0 for i in range(H+1)]
X=[0 for i in range(W+1)]
HW=[]
for i in range(M):
    h,w=map(int,input().split())
    Y[h]+=1
    X[w]+=1
    HW.append([h,w])

LY=[]
LX=[]
MY=max(Y)
MX=max(X)
for i in range(H+1):
    if Y[i]==MY:
        LY.append(i)
for i in range(W+1):
    if X[i]==MX:
        LX.append(i)

count=0
for i in range(M):
    if Y[HW[i][0]]==MY and X[HW[i][1]]==MX:
        count+=1

if count==len(LY)*len(LX):
    print(MY+MX-1)
else:
    print(MY+MX)

Buggy submission (verdict: Runtime Error):
H,W,M=map(int,input().split())
Y=[0 for i in range(H+1)]
X=[0 for i in range(W+1)]
HW=[]
for i in range(M):
    h,w=map(int,input().split())
    Y[h]+=1
    X[w]+=1
    HW.append([h,w])

LY=[]
LX=[]
MY=max(Y)
MX=max(X)
for i in range(H+1):
    if Y[i]==MY:
        LY.append(i)
for i in range(W+1):
    if X[i]==MX:
        LX.append(i)

import sys
for i in range(M):
    if HW[i][0] not in MY or HW[i][1] not in MX:
        print(MY+MX)
        sys.exit()

print(MY+MX-1)
Problem p02623 (python)

Fixed submission:
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
A=[0]+A
B=[0]+B

from itertools import accumulate

AA=list(accumulate(A))
BB=list(accumulate(B))
count=0
a,b=0,0

import bisect
for i in range(N+1):
    a=i
    b=bisect.bisect_right(BB,K-AA[i])-1
    if b==-1:
        continue
    count=max(count,a+b)
print(count)

Buggy submission (verdict: Runtime Error):
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
A=[0]+A
B=[0]+B

from itertools import accumulate

AA=list(accumulate(A))
BB=list(accumulate(B))
a,b=0,0

import bisect
for i in range(N+1):
    a=i
    b=bisect.bisect_right(BB,K-AA[i])-1
    if b==-1:
        continue
    count=max(count,a+b)
print(count)