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

Fixed submission:
S = input()
if S == "zyxwvutsrqponmlkjihgfedcba":
  print(-1)
  exit()
if len(S) != 26:
  L = [0]*26
  for i in range(len(S)):
    L[ord(S[i])-97] = 1
  for i in range(26):
    if L[i] == 0:
      print(S + chr(97+i))
      exit()
else:
  B = []
  for i in reversed(range(26)):
    if ord(S[i]) > ord(S[i-1]):
      U = i
      M = i-1
      B += [ord(S[i])]
      break
    else:
      B += [ord(S[i])]
  B.sort()
  for i in B:
    if chr(i) > S[M]:
      print(S[:M] + chr(i))
      exit()

Buggy submission (verdict: Runtime Error):
S = input()
if S == "zyxwvutsrqponmlkjihgfedcba":
  print(-1)
  exit()
if len(S) != 26:
  L = [0]*26
  for i in range(len(S)):
    L[ord(S[i])-97] = 1
  for i in range(26):
    if L[i] == 0:
      print(S + chr(97+i))
      exit()
else:
  B = []
  for i in reversed(range(26)):
    if ord(S[i]) - ord(S[i-1]) > 1:
      U = i
      M = i-1
      B += [ord(S[i])]
      break
    else:
      B += [ord(S[i])]
  B.sort()
  print(S[:M] + chr(B[0]))
Problem p03424 (python)

Fixed submission:
N = int(input())
S = input().split()
 
S.sort()
 
if S[-1] == "Y":
  print("Four")
else:
  print("Three")

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

S.sort()

if S[-1] == "Y":
  print("Four")
else:
  print("Three")
Problem p03487 (python)

Fixed submission:
import collections
N = int(input())
a = list(map(int,input().split()))
ans = 0
c = collections.Counter(a)

key = list(c.keys())


for i in key:
  if i > c[i]:
    ans += c[i]
  elif i < c[i]:
    ans += c[i] - i
print(ans)

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

check = [0] * N
ans = 0

for i in range(N):
  if a[i] > 10**5:
    ans += 1
  else:
    check[a[i]-1] += 1

for j in range(N):
  if j+1 > check[j]:
    ans += check[j]
  elif j + 1 < check[j]:
    ans += check[j] -j - 1
print(ans)
Problem p03524 (python)

Fixed submission:
S = input()
a = S.count("a")
b = S.count("b")
c = S.count("c")

if abs(a-b) <= 1 and abs(a-c) <= 1 and abs(b-c) <= 1:
  print("YES")
else:
  print("NO")

Buggy submission (verdict: Runtime Error):
S = input()
a = S.count("a")
b = S.count("b")
c = S.count("c")

if abs(a-b) <= 1 and abs(a-c) <= 1 and abs(b-c) <= 1:
  print("YES")
else:
  print("NO")
Problem p03549 (python)

Fixed submission:
N,M = map(int,input().split())
a = 1900*M + 100*(N-M)
b = 2**M
print(a*b)

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
print(1900*M + 100*(N-M))*2**M
Problem p03557 (python)

Fixed submission:
import bisect as bi
def main():
  from builtins import input, int, map
  N = int(input())
  A = list(map(int,input().split()))
  B = list(map(int,input().split()))
  C = list(map(int,input().split()))
  A.sort()
  C.sort()

  ans = 0

  for i in range(N):
    a = bi.bisect_left(A,B[i])
    c = N-bi.bisect_right(C,B[i])
    ans += a*c
  print(ans)
main()

Buggy submission (verdict: Runtime Error):
import math
def main():
  from builtins import input, int, map
  N = int(input())
  A = list(map(int,input().split()))
  B = list(map(int,input().split()))
  C = list(map(int,input().split()))
  A.sort()
  B.sort()
  C.sort()
  n = int(math.log2(N))+1

  ans = 0

  for i in range(N):
    if A[0] >= B[i]:
      continue
    if A[N-1] < B[i]:
      a = N
    else:
      left = 0
      right = N-1
      for _ in range(n):
        if right - left <= 1:
          break
        mid = (left + right) // 2
        if  B[i]> A[mid]:
          left = mid
        else:
          right = mid
      a = left + 1
    if C[N-1] <= B[i]:
      continue
    if C[0] > B[i]:
      c = N
    else:      
      left = 0
      right = N-1
      for _ in range(n):
        if right - left <= 1:
          break
        mid = (left + right) // 2
        if B[i]>= C[mid]:
          left = mid
        else:
          right = mid
      c = N - right
    ans += a*c
  print(ans)
main()
Problem p03607 (python)

Fixed submission:
N = int(input())
A = [int(input()) for i in range(N)]

A.sort()

odd = 0
count = 1
a = A[0]
for i in A[1:]:
  if i == a:
    count += 1
  else:
    a = i
    if count % 2 == 1:
      odd += 1
    count = 1
if count % 2 == 1:
      odd += 1
print(odd)

Buggy submission (verdict: Runtime Error):
N = int(input())
list = [0]*1000000000

for i in range(N):
  A = int(input())
  if list[A-1] == 0:
    list[A-1] = 1
  else:
    list[A-1] = 0
print(sum(list))
Problem p03611 (python)

Fixed submission:
N = int(input())
a = list(map(int, input().split()))
 
set_a = set(a)
cnt = [0] * (max(a)+1)
ans = 0
 
for i in a:
    cnt[i] += 1
 
if len(cnt) == 1:
    print(cnt[0])
elif len(cnt) == 2:
    print(sum(cnt))
else:
    for i in range(1, max(a)):
        ans = max(ans, cnt[i-1]+cnt[i]+cnt[i+1])

    print(ans)

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

num = set(a)

cnt = [0]*max(num+1)

for i in a:
  cnt[i] += 1

if len(cnt) == 1:
    print(cnt[0])
elif len(cnt) == 2:
    print(sum(cnt))
else:
    for i in range(1, max(a)):
        ans = max(ans, cnt[i-1]+cnt[i]+cnt[i+1])

    print(ans)
Problem p03612 (python)

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

Buggy submission (verdict: Runtime Error):
N = int(input())
p = list(map(int,input().split()))
ans = 0
for i in range(N):
  if p[i] == i+1:
    p[i] = -1
  else:
    p[i] = 0
    
for j in range(N):
  if p[j] == -1:
    ans += 1
    p[j] = 0
    p[j+1] = 0
print(ans)
Problem p03679 (python)

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

C = B - A

if C <= 0:
  print("delicious")
elif C > X:
  print("dangerous")
else:
  print("safe")

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

C = B - A

if C <= 0:
  print("delicious")
elif C > X:
  print("dangerous")
else:
  print("safe")
Problem p04011 (python)

Fixed submission:
N,K,X,Y =[int(input()) for _ in range(4)]

if N > K:
  A = X*K + Y*(N-K)
else:
  A = X*N
print(A)

Buggy submission (verdict: Runtime Error):
N,K,X,Y =[int(input()) for _ in range(4)]

if N > K:
  A = X*K + Y*(N-K)
elif:
  A = X*N
print(A)
Problem p02609 (python)

Fixed submission:
import sys
readline = sys.stdin.buffer.readline
read = sys.stdin.buffer.read

import numpy as np


#N = 2 * 10 ** 5
#X = np.random.randint(0, 2, N)
#Y = int('0b' + ''.join(X.astype(str).tolist()), 0)

N = int(input())
X = input()
Y = int('0b' + X, 0)
X = np.array(list(X), int)

p = int(X.sum())
m1 = Y % (p + 1)
m2 = Y % max(1, p - 1)


count = np.zeros((N + 1, ))
for n in range(1, N):
    i = np.array(list(bin(n))[2:], int).sum()
    count[n] = 1 + count[n % i]

ans = [0] * N
for n in range(1, N + 1):
    flag = 0
    if X[n - 1]:
        z = m2 - pow(2, N - n, max(1, p - 1))
        z %= max(1, p - 1)
        if p - 1 == 0:
            flag = 1
    else:
        z = pow(2, N - n, p + 1) + m1
        z %= p + 1
        if p == 0:
            z = 0

    ans[n - 1] = int(count[z] + 1)
    if z == 0 and flag:
        ans [n - 1] = 0

print('\n'.join(map(str, ans)))

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

import numpy as np


#N = 2 * 10 ** 5
#X = np.random.randint(0, 2, N)
#Y = int('0b' + ''.join(X.astype(str).tolist()), 0)

N = int(input())
X = input()
Y = int('0b' + X, 0)
X = np.array(list(X), int)
p = int(X.sum())
m1 = Y % (p + 1)
m2 = Y % max(1, p - 1)


count = np.zeros((N, ))
for n in range(1, N):
    i = np.array(list(bin(n))[2:], int).sum()
    count[n] = 1 + count[n % i]

ans = [0] * N
for n in range(1, N + 1):
    if X[n - 1]:
        p -= 1
        z = m2 - pow(2, N - n, max(1, p))
    else:
        p += 1
        z = pow(2, N - n, p) + m1

    ans[n - 1] = int(count[z] + 1)

print('\n'.join(map(str, ans)))

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

import numpy as np


#N = 2 * 10 ** 5
#X = np.random.randint(0, 2, N)
#Y = int('0b' + ''.join(X.astype(str).tolist()), 0)

N = int(input())
X = input()
Y = int('0b' + X, 0)
X = np.array(list(X), int)
p = int(X.sum())
m1 = Y % (p + 1)
m2 = Y % (p - 1)


count = np.zeros((N, ))
for n in range(1, N):
    i = np.array(list(bin(n))[2:], int).sum()
    count[n] = 1 + count[n % i]

ans = [0] * N
for n in range(1, N + 1):
    if X[n - 1]:
        p -= 1
        z = m2 - pow(2, N - n, p)
    else:
        p += 1
        z = pow(2, N - n, p) + m1

    ans[n - 1] = int(count[z] + 1)

print('\n'.join(map(str, ans)))
Problem p02630 (python)

Fixed submission:
#import numpy as np
from collections import Counter
from time import time

import sys
readline = sys.stdin.buffer.readline


N = int(input())
A = list(map(int, input().split()))
#A = np.random.randint(1, 10 ** 5 + 1, 10 ** 5)

S = sum(A)
C = Counter(A)

Q = int(input())
#Q = 10 ** 5

ans = []
s = time()
for _ in range(Q):
    b, c = map(int, input().split())
    #b, c = np.random.randint(1, 10 ** 5 + 1, 2)
    #b, c = 2, 5

    count = C[b]
    S = S + (c - b) * count

    C[c] += count
    C[b] = 0
    
    ans.append(S)

print('\n'.join(map(str, ans)))
#print('time: ', time() - s)

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

from collections import Counter


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

S = sum(A)
C = Counter(A)

ans = []
for _ in range(Q):
    b, c = map(int, input().split())
    count = C[b]
    S += (c - b) * count
    C[b], C[c] = 0, C[c] + count
    ans.append(S)

print('\n'.join(map(str, ans)))
Problem p02639 (python)

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

for i, x in enumerate(X):
    if x == 0:
        print(i + 1)
        break

Buggy submission (verdict: Runtime Error):
X = list(int, input().split())

for i, x in enumerate(X):
    if x == 0:
        print(i + 1)
        break
Problem p02642 (python)

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

import numpy as np
from collections import Counter
from numba import njit




N = int(input())
A = np.array(readline().split(), np.int32)

count = np.zeros((A.max() + 1))
for a in A:
    if count[a] > 1:
        continue
    count[::a] += 1

ret = 0
for a in A:
    ret += count[a] == 1

print(ret)

Buggy submission (verdict: Runtime Error):
import sys
readline = sys.stdin.readline
 
import numpy as np
from collections import Counter
 

N = int(input())
A = np.array(readline().split())
count = Counter(A)
A = np.array([
    a for a, c in count.items() if c == 1
])
 
if len(A) != 0:
    A = np.sort(A)

i = 0
while True:
    if len(A) == 0:
        break
    pre = A
    a = A[i]
    A = np.delete(A, np.where((A % a == 0) & (A != a)))
    i += 1
    if i >= len(A):
        break

print(len(A))
Problem p02647 (python)

Fixed submission:
import sys
import numpy as np
from numba import njit


read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

@njit('(i8[::1],)', cache=True)
def c(A):
    N = len(A)
    B = np.zeros_like(A)
    for i, a in enumerate(A):
        l = max(0, i - a)
        r = min(N - 1, i + a)
        B[l] += 1
        if r + 1 < N:
            B[r + 1] -= 1

    B = np.cumsum(B)
    return B


def main():
    N, K = map(int, readline().split())
    A = np.array(readline().split(), np.int64)


    K = min(K, 50)
    for _ in range(K):
        A = c(A)

    print(' '.join(A.astype(str)))


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
import numpy as np


read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def c(A):
    N = len(A)
    B = np.zeros_like(A)
    for i, a in enumerate(A):
        l = max(0, i - a)
        r = min(N - 1, i + a)
        B[l] += 1
        if r + 1 < N:
            B[r + 1] -= 1

    B = np.cumsum(B)
    return B


def main():
    N, K = map(int, readline().split())
    A = np.array(map(int, readline().split()))


    K = min(K, 50)
    for _ in range(K):
        A = c(A)

    print(' '.join(A.astype(str)))


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import numpy as np


def c(A):
    N = len(A)
    B = np.zeros_like(A)
    for i, a in enumerate(A):
        l = max(0, i - a)
        r = min(N - 1, i + a)
        B[l] += 1
        if r + 1 < N:
            B[r + 1] -= 1

    B = np.cumsum(B)
    return B


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


K = min(K, 50)
for _ in range(K):
    A = c(A)

print(' '.join(A.astype(str)))

Buggy submission (verdict: Runtime Error):
import numpy as np


def c(A):
    N = len(A)
    B = np.zeros_like(A)
    for i, a in enumerate(A):
        l = max(0, i - x)
        r = min(N - 1, i + x)
        B[l] += 1
        if r + 1 < N:
            B[r + 1] -= 1

    B = np.cumsum(B)
    return B


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


K = min(K, 50)
for _ in range(K):
    A = update(A)

print(' '.join(A.astype(str)))
Problem p02678 (python)

Fixed submission:
import sys
readline = sys.stdin.buffer.readline
read = sys.stdin.buffer.read

N, M = map(int, readline().split())
m = map(int, read().split())
AB = list(zip(m, m))
graph = [[] for _ in range(N+1)]
for a, b in AB:
    graph[a].append(b)
    graph[b].append(a)

root = 1
q = [root]
checked = [0] * (N + 1)
checked[root] = 1
order = []
D = [0 for _ in range(N+1)]
d = 0
while q:
    x = q.pop(0)
    d = D[x]
    for y in graph[x]:
        if checked[y]:
            continue
        D[y] = d + 1
        checked[y] = 1
        q.append(y)

ans = [0 for _ in range(N+1)]
for a, b in AB:
    d_a, d_b = D[a], D[b]
    if d_a < d_b:
        ans[b] = a
    elif d_a > d_b:
        ans[a] = b

print('Yes')
print('\n'.join(map(str, ans[2:])))

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

N, M = map(int, readline().split())
ans = [0 for _ in (N + 1)]
append_ans = ans.append
graph = [[] for _ in range(N+1)]

for _ in range(M):
    a, b = map(int, readline().split())
    graph[a].append(b)
    graph[b].append(a)

root = 1
q = [root]
append_q = q.append
checked = [0] * (N + 1)
checked[root] = 1
order = []
append_order = order.append
parent = [-1 for _ in range(N+1)]

while q:
    x = q.pop(0)
    for y in graph[x]:
        if checked[y]:
            continue
        if parent[y] != -1:
            continue
        parent[y] = x
        append_ans(x)
        append_order(y-2)
        checked[y] = 1
        append_q(y)

if len(order) != N - 1:
    print('No')
else:
    print('Yes')
    for i in range(len(order)):
        j = order.index(i)
        print(ans[j])
Problem p02690 (python)

Fixed submission:
import sys
input = sys.stdin.readline
 
 
def main():
    X = int(input().rstrip())
    f = 0
    for a in range(-150, 150):
        for b in range(-150, 150):
            i = a ** 5 - b ** 5
            if i == X:
                print(a, b)
                f = 1
                break
 
        if f:
            break
 
 
if __name__ == '__main__':
    main()

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


def main():
    X = int(input().rstrip())
    for b in range(64):
        if (X - b ** 5) ** (1 / 5) % 1 == 0:
            A = int((X - b ** 5) ** (1 / 5))
            B = b
            break

    print(A, B)


if __name__ == '__main__':
    main()

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


def main():
    X = int(input().rstrip())
    B = -1
    for i in range(100):
        if X - 1 == i ** 5:
            A = i
            break

    print(A, B)


if __name__ == '__main__':
    main()
Problem p02730 (python)

Fixed submission:
s = input()
n = len(s)
 
a = s == s[::-1]
s1 = s[:(n-1)//2]
b = s1 == s1[::-1]
s2 = s[(n+3)//2 - 1:]
c = s2 == s2[::-1]
 
print(['No', 'Yes'][a and b and c])

Buggy submission (verdict: Runtime Error):
s = input()
n = len(s)
 
a = s == reversed(a)
s1 = s[:(n-1)//2]
b = s1 == s1[::-1]
s2 = s[(n+3)//2 + 1:]
c = s2 == s2[::-1]
 
print(['No', 'Yes'][a and b and c])

Buggy submission (verdict: Runtime Error):
s = input()
n = len(s)

a = s == reversed(a)
s1 = s[:(n-1)//2]
b = s1 == reversed(s1)
s2 = s[(n+3)//2 + 1:]
c = s2 == reversed(s2)

print(['No', 'Yes'][a and b and c])
Problem p02760 (python)

Fixed submission:
import numpy as np
 

A = np.array([list(map(int, input().split())) for _ in range(3)])
n = int(input())
for _ in range(n):
  b = int(input())
  A = np.where(A == b, 0, A)
  
x = np.all(A[[0, 1, 2], [0, 1, 2]] == 0)
y = np.all(A[[0, 1, 2], [2, 1, 0]] == 0)
z = np.any(np.sum(A, axis=0) == 0)
w = np.any(np.sum(A, axis=1) == 0)
 
print(['Yes', 'No'][not x and not y and not z and not w])

Buggy submission (verdict: Runtime Error):
import numpy as np


A = np.array([list(map(int, input().split())) for _ in range(3)])
n = int(input())
for _ in range(n):
  b = int(input())
  A = np.where(A == b, 0, A)
  
x = np.all(A[[0, 1, 2], [0, 1, 2]] == 0)
y = np.all(A[[0, 1, 2], [2, 1, 0]] == 0)
z = np.any(np.sum(A, axis=0) == 0)
w = np.any(np.sum(A, axis=1) == 0)

print(['Yes', 'No'][!x and !y and !z and !w])
Problem p02761 (python)

Fixed submission:
n, m = map(int, input().split())
 
num = [-1] * n
ans = -1
f = 1
 
for _ in range(m):
  s, c = map(int, input().split())
  if s == 1 and c == 0:
    if n == 1:
      ans = 0
    f = 0
    break
    
  i = num[s - 1]
  if i == -1:
    num[s-1] = c
  elif i == c:
    continue
  else:
    f = 0
    break
  
if num[0] == -1:
  if n == 1:
    num[0] = 0
  else:
    num[0] = 1
  
if f:
  num = [0 if n == -1 else n for n in num]
  ans = ''.join(map(str, num))
  
print(ans)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
S, C = [], []
ans = -1

for _ in range(m):
  s, c = map(int, input().split())
  S.append(s)
  C.append(c)
  
for num in range(10 ** (max(S) - 1), 10 ** n):
  num = str(num)
  f = 1
  for s, c in zip(S, C):
    s = s - 1
    if int(num[s]) != c:
      f = 0
      break
      
  if f:
    ans = num
    break
    
print(ans)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
S, C = [], []
for _ in range(m):
  s, c = map(int, input().split())
  S.append(s)
  C.append(c)
  
for num in range(10 ** (max(S) - 1), 10 ** n):
  num = str(num)
  f = 1
  for s, c in zip(S, C):
    s = s - 1
    if int(num[s]) != c:
      f = 0
      break
      
  if f:
    ans = num
    break
    
print(ans)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
S, C = []
for _ in range(m):
  s, c = map(int, input().split())
  S.append(s)
  C.append(c)
  
for num in range(10 ** (max(S) - 1), 10 ** n):
  num = str(num)
  f = 1
  for s, c in zip(S, C):
    s = s - 1
    if int(num[s]) != c:
      f = 0
      break
      
  if f:
    ans = num
    break
    
print(ans)
Problem p02780 (python)

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

def calculate_Expectation(n):
    n = int(n)
    p = 1/n
    e = p * (n*(n+1)/2)
    return e

E = list(map(calculate_Expectation, input().split()))
if N == K:
    print(sum(E))
else:
    S = [0]
    for i, e in enumerate(E):
        S.append(S[i]+e)

    sum_of_E = []
    for left in range(1, N+1-K):
        right = left + K
        sum_of_E.append(S[right]-S[left])
    print(max(sum_of_E))

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

def calculate_Expectation(n):
    n = int(n)
    p = 1/n
    e = p * (n*(n+1)/2)
    return e

E = list(map(calculate_Expectation, input().split()))
S = [0]
for i, e in enumerate(E):
    S.append(S[i]+e)

sum_of_E = []
for left in range(1, N+1-K):
    right = left + K
    sum_of_E.append(S[right]-S[left])
print(max(sum_of_E))
Problem p02838 (python)

Fixed submission:
import sys
import numpy as np


input = sys.stdin.readline

def main():
    N = int(input().rstrip())
    A = np.array(input().rstrip().split(), dtype=np.int64)
    M = 60
    p = 10 ** 9 + 7
    ans = 0

    for m in range(M):
        B = (A >> m) & 1
        x = np.count_nonzero(B)
        x *= N-x
        
        x *= 2 ** m
        x %= p
        ans += x

    print(ans % p)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys


input = sys.stdin.readline

def main():
    N = int(input().rstrip())
    A = list(map(int, input().rstrip().split()))
    M = max(A).bit_length()
    B = [0] * M
    p = 10 ** 9 + 7
    ans = 0

    for n in range(N):
        a = bin(A[n])[:1:-1]
        l = len(a)
        for i in range(l):
            B[i] += int(a[i])

    for m in range(M):
        tmp = B[m] * (N - B[m]) * 2 ** m
        tmp %= p
        ans = ans + tmp
        ans %= p

    print(ans)


if __name__ == '__main__':
    main()
Problem p02850 (python)

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


N = int(readline())
graph = [[] for _ in range(N+1)]
AB = []

for _ in range(N-1):
    a, b = map(int, readline().split())
    AB.append((a, b))
    graph[a].append(b)
    graph[b].append(a)

parent = [0] * (N+1)
root = 1
stack = [root]
color = [0] * (N+1)
while stack:
    x = stack.pop()
    ng = color[x]
    c = 1
    for y in graph[x]:
        if y == parent[x]:
            continue
        if c == ng:
            c += 1
        parent[y] = x
        color[y] = c
        c += 1
        stack.append(y)

print(max(color))

for a, b in AB:
    if parent[a] == b:
        print(color[a])
    else:
        print(color[b])

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


def main():
    N = int(input())
    ans = []
    AB = [[] for _ in range(N+1)]
    for _ in range(N-1):
        a, b = map(int, input().split())
        AB[a].append(b)
        AB[b].append(a)
    
    M = max([len(i) for i in AB])
    _c = set(range(1, M+1))
    C = [_c for _ in range(N+1)]

    root = 1
    checked = set()
    q = [root]

    while q:
        i = q.pop(0)
        if i in checked:
            continue
        checked.add(i)
        for j in AB[i]:
            if j in checked:
                continue
            k = C[i].pop()
            ans.append(k)
            C[j] = C[j] - set([k])
            q.append(j)

    print(M)   
    print('\n'.join(map(str, ans)))


if __name__ == '__main__':
    main()
Problem p02910 (python)

Fixed submission:
S = input()
S1 = S[::2]
S2 = S[1::2]
f = 1
for i in S1:
    if i in ['R', 'U', 'D']:
        f *= 1
    else:
        f *= 0
        
for i in S2:
    if i in ['L', 'U', 'D']:
        f *= 1
    else:
        f *= 0
if f:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
S = input()
S_odd = [s for i, s in enumerate(S) if i % 2 == 0]
S_even = [s for i, s in enumerate(S) if i % 2 != 0]

for i in S_odd:
    if i in ['R', 'U', 'D']:
        f = 1
    else:
        f = 0
        break
for j in S_even:
    if j in ['L', 'U', 'D']:
        g = 1
    else:
        g = 0
        break
if f*g:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
S = input()
S_odd = [s for i, s in enumerate(S) if i % 2 == 0]
S_even = [s for i, s in enumerate(S) if i % 2 != 0]

for i in S_odd:
    if i in ['R', 'U', 'D']:
        f = 1
    else:
        f = 0
        break
for j in S_even:
    if j in ['L', 'U', 'D']:
        g = 1
    else:
        g = 0
        break
if f*g:
    print('Yes')
else:
    print('No')
Problem p02924 (python)

Fixed submission:
N = int(input())

if N % 2 == 0:
    print((N-1)*N//2)
else:
    print(N*(N-1)//2)

Buggy submission (verdict: Runtime Error):
n = int(input)
print(n*(n-1)//2)