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

Fixed submission:
H, W, A, B = map(int, input().split())
for i in range(B):
    print('1' * A + '0' * (W - A))
for i in range(H - B):
    print('0' * A + '1' * (W - A))

Buggy submission (verdict: Runtime Error):
H, W, A, B = map(int, input().split())
grid = [[0] * W for _ in range(H)]
cnt = [0] * W
w = 0
for h in range(H):
    if B != 0:
        if cnt[w] >= B:
            w += A
    for i in range(A):
        grid[h][w+i] = 1
        cnt[w+i] += 1
for row in grid:
    print(*row, sep='')
Problem p02911 (python)

Fixed submission:
n, k, q = map(int, input().split())
score = [0] * n
for _ in range(q):
    i = int(input())
    score[i-1] += 1
for j in range(len(score)):
    if score[j] > q - k:
        print('Yes')
    else:
        print('No')

Buggy submission (verdict: Runtime Error):
n, k, q = map(int, input().split())
score = [0] * n
for _ in range(q):
    i = int(input())
    score[i-1] += 1
for j in score:
    if score[j] > q - k:
        print('Yes')
    else:
        print('No')
Problem p02936 (python)

Fixed submission:
import sys
input = sys.stdin.readline #for input speed
sys.setrecursionlimit(10**6) #for deep recursion
n, q = map(int, input().split())

tree_index = [[] for _ in range(n)]
for i in range(n-1):
  a,b = map(int, input().split())
  a -= 1
  b -= 1
  tree_index[a].append(b) # a<bとは限らないため、双方向にする
  tree_index[b].append(a)
ans = [0] * n
for i in range(q):
  p, x = map(int, input().split())
  ans[p-1] += x
def dfs(cur, par):
    for chl in tree_index[cur]:
      if chl == par: #parentとchildが等しい時はスキップ
        continue
      ans[chl] += ans[cur] 
      dfs(chl, cur)
dfs(0, -1)
print(*ans)

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

tree_index = [[] for _ in range(n)]
for i in range(n-1):
  a,b = map(int, input().split())
  a -= 1
  b -= 1
  tree_index[a].append(b) # a<bとは限らないため、双方向にする
  tree_index[b].append(a)
ans = [0] * n
for i in range(q):
  p, x = map(int, input().split())
  ans[p-1] += x
def dfs(cur, par):
    for chl in tree_index[cur]:
      if chl == par: #parentとchildが等しい時はスキップ
        continue
      ans[chl] += ans[cur] 
      dfs(chl, cur)
dfs(0, -1)
print(*ans)

Buggy submission (verdict: Runtime Error):
n, q = map(int, input().split())
tree = [[] for _ in range(n)]
for _ in range(n-1):
    a, b = map(int, input().split())
    tree[a-1].append(b-1)
ans = [0] * n
for _ in range(q):
    p, x = map(int, input().split())
    ans[p-1] += x
def dfs(c, parent):
    for child in tree[c]:
        if child == parent:
            continue
        else:
            ans[child] += ans[c]
            dfs(child, c)
dfs(0, 0)
print(*ans)

Buggy submission (verdict: Runtime Error):
n, q = map(int, input().split())
tree = [[] for _ in range(n)]
for _ in range(n-1):
    a, b = map(int, input().split())
    tree[a-1].append(b-1)
    tree[b-1].append(a-1)
ans = [0] * n
for _ in range(q):
    p, x = map(int, input().split())
    ans[p-1] += x
def dfs(c, parent):
    for child in tree[c]:
        if child == parent:
            continue
        ans[child] += ans[c]
        dfs(child, c)
dfs(0, -1)
print(*ans)

Buggy submission (verdict: Runtime Error):
n, q = map(int, input().split())
tree = [[] for _ in range(n)]
for _ in range(n-1):
    a, b = map(int, input().split())
    tree[a-1].append(b-1)
    tree[b-1].append(a-1)
ans = [0] * n
for _ in range(q):
    p, x = map(int, input().split())
    ans[p-1] += x
def dfs(c, parent):
    for child in tree[c]:
        if child == parent:
            continue
        else:
            ans[child] += ans[c]
            dfs(child, c)
dfs(0, 0)
print(*ans)

Buggy submission (verdict: Runtime Error):
n, q = map(int, input().split())
tree = [[] for _ in range(n)]
for _ in range(n-1):
    a, b = map(int, input().split())
    tree[a-1].append(b)
    tree[b-1].append(a)
ans = [0] * n
for _ in range(q):
    p, x = map(int, input().split())
    ans[p-1] += x
def dfs(c, parent):
    for child in tree[c-1]:
        if child == parent:
            continue
        else:
            ans[child-1] += ans[c-1]
            dfs(child, c)
dfs(1, 0)
print(*ans)
Problem p02972 (python)

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

def main():
    n = int(input())
    A = list(map(int, input().split()))
    L = [0] * n
    b = []
    for i in reversed(range(n)):
        if A[i] != L[i] % 2:
            b.append(i+1)
            d = div(i + 1)
            for j in d:
                L[j-1] += 1
    print(len(b))
    print(*b)

main()

Buggy submission (verdict: Runtime Error):
n = int(input())
A = list(map(int, input().split()))
b = []
for i in reversed(range(n)):
    if A[i]:
        num = i + 1
        b.append(num)
        tmp = 1
        while tmp * tmp <= num:
            if num % tmp == 0:
                A[num] ^= 1
                if tmp != num // tmp:
                    A[num//tmp]
            tmp += 1
print(len(b))
print(*b)
Problem p03047 (python)

Fixed submission:
n, k = map(int, input().split())
print(n-k+1)

Buggy submission (verdict: Runtime Error):
R, G, B, N = map(int, input().split())
cnt = 0
 
for i in range(N // R + 1):
    for j in range(N // G + 1):
        q, mod = divmod((N - R * i - G * j), B)
        if q >= 0 and mod == 0:
            cnt += 1
print(cnt)

Buggy submission (verdict: Runtime Error):
R, G, B, N = map(int, input().split())
cnt = 0

for i in range(N // R + 1):
    for j in range(N // G + 1):
        if (N - R * i - G * j) % B == 0:
            cnt += 1
print(cnt)
Problem p03048 (python)

Fixed submission:
R, G, B, N = map(int, input().split())
cnt = 0

for i in range(N // R + 1):
    for j in range(N // G + 1):
        if (N - R * i - G * j) / B >= 0 and ((N - R * i - G * j) / B) % 1 == 0:
            cnt += 1
print(cnt)

Buggy submission (verdict: Runtime Error):
R, G, B, N = map(int, input().split())
cnt = 0

for i in range(n // R + 1):
    for j in range(n // G + 1):
        if (N - R * i - G * j) / B >= 0 and ((N - R * i - G * j) / B) % 1 == 0:
            cnt += 1
print(cnt)
Problem p03095 (python)

Fixed submission:
from collections import Counter

n = int(input())
s = str(input())
d = Counter(s)
S = list(set(s))
ans = 1
for t in S:
    ans *= d[t] + 1
print((ans - 1) % (10** 9 + 7))

Buggy submission (verdict: Runtime Error):
n = int(input())
s = str(input())
d = Counter(s)
S = list(set(s))
ans = 1
for t in S:
    ans *= d[t] + 1
print(ans - 1)
Problem p03229 (python)

Fixed submission:
n = int(input())
a = sorted(int(input()) for _ in range(n))
m = n // 2
if n % 2 == 0:
    ans = (sum(a[m:]) - sum(a[:m])) * 2 - a[m] + a[m-1]
    print(ans)
else:
    ans1 = (sum(a[m+1:]) - sum(a[:m])) * 2 - a[m] + a[m-1]
    ans2 = (sum(a[m+1:]) - sum(a[:m])) * 2 - a[m+1] + a[m]
    print(max(ans1, ans2))

Buggy submission (verdict: Runtime Error):
from collections import deque

n = int(input())
a = sorted(int(input()) for _ in range(n))
q = deque(a)
l = q.popleft()
r = q.pop()
ans = abs(l - r)
while q:
    if flag == 0:
        x = q.popleft()
        flag = 1
    else:
        x = q.pop()
        flag = 0
    if abs(l - x) >= abs(x - r):
        ans += abs(l - x)
        l = x
    else:
        ans += abs(x - r)
        r = x
print(ans)
Problem p03274 (python)

Fixed submission:
INF = float('inf')
n, k = map(int, input().split())
L = list(map(int, input().split()))
ans = INF
for i in range(n-k+1):
    r = L[i+k-1]
    l = L[i]
    tr = abs(r) + abs(l - r)
    tl = abs(l) + abs(r - l)
    t = min(tr, tl)
    ans = min(ans, t)
print(ans)

Buggy submission (verdict: Runtime Error):
INF = float('inf')
n, k = map(int, input().split())
L = list(map(int, input().split()))
for i in range(n):
    if L[i] >= 0:
        break
l = L[max(0, (i-k)):i]
l.sort(reverse=True)
r = L[i:(i+k)]
s = min(k, len(r))
e = min(k, len(l))
ans = INF
for j in range(max(1, min(s, e))):
    tr = r[(s-1)-j]
    u = k - (s - 1) + j - 1
    tl = -l[u-1] if u > 0 else 0
    t = tr + tl + min(tr, tl)
    ans = min(ans, t)
print(ans)
Problem p03393 (python)

Fixed submission:
s = str(input())
alpha = 'abcdefghijklmnopqrstuvwxyz'
inv_alpha = 'zyxwvutsrqponmlkjihgfedcba'
if len(s) == 26:
    if s == inv_alpha:
        print(-1)
    else:
        for i in reversed(range(25)):
            for j in reversed(range(i+1, 26)):
                if s[i] < s[j]:
                    print(s[:i] + s[j])
                    break
            else:
                continue
            break
else:
    S = sorted(set(alpha) - set(s))
    print(s + S[0])

Buggy submission (verdict: Runtime Error):
s = str(input())
alpha = 'abcdefghijklmnopqrstuvwxyz'
if len(s) == 26:
    if s == 'zyxwvutsrqponmlkjihgfedcba':
        print(-1)
    else:
        for i in range(26):
            if ord(s[i+1]) - ord(s[i]) != 1:
                S = sorted(set(s) - set(s[:i+1]))
                print(s[:i] + S[0])
                break
else:
    S = sorted(set(alpha) - set(s))
    print(s + S[0])
Problem p03574 (python)

Fixed submission:
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
for i in range(h):
    for j in range(w):
        if s[i][j] == '.':
            l = max(0, j - 1)
            r = min(j + 2, w)
            if i == 0:
                if h == 1:
                    s[i][j] = s[i][l:r].count('#')
                else:
                    s[i][j] = s[i][l:r].count('#') + s[i + 1][l:r].count('#')
            elif i == h - 1:
                s[i][j] = s[i - 1][l:r].count('#') + s[i][l:r].count('#')
            else:
                s[i][j] = s[i - 1][l:r].count('#') + s[i][l:r].count('#') + s[i + 1][l:r].count('#')
    print(*s[i], sep='')

Buggy submission (verdict: Runtime Error):
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
for i in range(h):
    for j in range(w):
        if s[i][j] == '.':
            l = max(0, j - 1)
            r = min(j + 2, w)
            if i == 0:
                s[i][j] = s[i][l:r].count('#') + s[i + 1][l:r].count('#')
            elif i == h - 1:
                s[i][j] = s[i - 1][l:r].count('#') + s[i][l:r].count('#')
            else:
                s[i][j] = s[i - 1][l:r].count('#') + s[i][l:r].count('#') + s[i + 1][l:r].count('#')
    print(*s[i], sep='')

Buggy submission (verdict: Runtime Error):
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
for i in range(h):
    for j in range(w):
        if s[i][j] == '.':
            if i == 0:
                s[i][j] = s[i][max(0, j - 1):j + 2].count('#') + s[i + 1][max(0, j - 1):j + 2].count('#')
            elif i == h - 1:
                s[i][j] = s[i - 1][max(0, j - 1):j + 2].count('#') + s[i][max(0, j - 1):j + 2].count('#')
            else:
                s[i][j] = s[i - 1][max(0, j - 1):j + 2].count('#') + s[i][max(0, j - 1):j + 2].count('#') + s[i + 1][max(0, j - 1):j + 2].count('#')
    print(*s[i], sep='')
Problem p03578 (python)

Fixed submission:
n = int(input())
d = list(map(int, input().split()))
m = int(input())
t = list(map(int, input().split()))
D = {}
for i in range(n):
    if d[i] not in D:
        D[d[i]] = 1
    else:
        D[d[i]] += 1
T = {}
for j in range(m):
    if t[j] not in T:
        T[t[j]] = 1
    else:
        T[t[j]] += 1
for k in T:
    try:
        if T[k] <= D[k]:
            continue
        else:
            print('NO')
            break
    except:
        print('NO')
        break
else:
    print('YES')

Buggy submission (verdict: Runtime Error):
n = int(input())
d = list(map(int, input().split()))
m = int(input())
t = list(map(int, input().split()))
D = {}
for i in range(n):
    if d[i] not in D:
        D[d[i]] = 1
    else:
        D[d[i]] += 1
T = {}
for j in range(m):
    if t[j] not in T:
        T[t[j]] = 1
    else:
        T[t[j]] += 1
for k in T:
    if T[k] <= D[k]:
        continue
    else:
        print('NO')
        break
else:
    print('YES')
Problem p03583 (python)

Fixed submission:
N = int(input())
for h in range(1, 3501):
    for n in range(1, 3501):
        if 4 * h * n - N * n - N * h > 0:
            w = (N * h * n) / (4 * h * n - N * n - N * h)
            if w > 0 and w % 1 == 0:
                print(h, n, int(w))
                exit()

Buggy submission (verdict: Runtime Error):
N = int(input())
for h in range(1, 3501):
    for n in range(1, 3501):
        w = (N * h * n) / (4 * h * n - N * n - N * h)
        if w > 0 and w % 1 == 0:
            print(h, n, int(w))
            exit()
Problem p03633 (python)

Fixed submission:
def gcd(a, b):
    if a < b:
        a, b = b, a
    while a % b != 0:
        a, b = b, a % b
    return b
def lcm(a, b):
    return a * b // gcd(a, b)

n = int(input())
t = [int(input()) for _ in range(n)]
if n == 1:
    print(t[0])
else:
    l = lcm(t[0], t[1])
    for i in range(1, n):
        l = lcm(l, t[i])
    print(l)

Buggy submission (verdict: Runtime Error):
def gcd(a, b):
    if a < b:
        a, b = b, a
    while a % b != 0:
        a, b = b, a % b
    return b
def lcm(a, b):
    return a * b // gcd(a, b)

n = int(input())
t = [int(input()) for _ in range(n)]
l = lcm(t[0], t[1])
for i in range(1, n):
    l = lcm(l, t[i])
print(l)
Problem p03651 (python)

Fixed submission:
import fractions

n, k = map(int, input().split())
L = list(map(int, input().split()))
if n == 1:
    g = L[0]
else:
    g = fractions.gcd(L[0], L[1])
    for i in range(2, n):
        g = fractions.gcd(g, L[i])
M = max(L)
if M >= k and k % g == 0:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Buggy submission (verdict: Runtime Error):
import math

n, k = map(int, input().split())
L = list(map(int, input().split()))
if n == 1:
    g = L[0]
else:
    g = math.gcd(L[0], L[1])
    for i in range(2, n):
        g = math.gcd(g, L[i])
M = max(L)
if M >= k and k % g == 0:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')
Problem p03761 (python)

Fixed submission:
from collections import Counter

n = int(input())
L = [Counter(str(input())) for _ in range(n)]
C = sorted(L[0])
ans = ''
for k in C:
    m = L[0][k]
    for i in range(n):
        m = min(m, L[i][k])
    ans += k * m
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter

n = int(input())
L = [Counter(str(input())) for _ in range(n)]
ans = ''
for k in L[0]:
    for i in range(1, n):
        m = L[0][k]
        if L[i][k] < L[0][k]:
            m = min(m, L[i][k])
    ans = ans + k * m
print(ans)
Problem p03994 (python)

Fixed submission:
s = str(input())
k = int(input())
S = []
for i in range(len(s)):
    S.append(ord(s[i]) - 97)
i = 0
while k > 0:
    if S[i] > 0 and 26 - S[i] <= k:
        k -= 26 - S[i]
        S[i] = 0
        i += 1
    else:
        i += 1
    if i >= len(s):
        S[-1] += k
        break
ans = ''
for x in S:
    ans += chr((x % 26) + 97)
print(ans)

Buggy submission (verdict: Runtime Error):
s = str(input())
k = int(input())
S = []
for i in range(len(s)):
    S.append(ord(s[i]) - 97)
i = 0
while k > 0:
    if 26 - S[i] <= k:
        k -= 26 - S[i]
        S[i] = 0
        i += 1
    else:
        i += 1
    if i >= len(s):
        S[-1] += k
        break
ans = ''
for x in S:
    ans += chr(x + 97)
print(ans)
Problem p02632 (python)

Fixed submission:
K=int(input())
S=input()
n=K+len(S)
MAX=2000000
fac=[0]*MAX
finv=[0]*MAX
inv=[0]*MAX
MOD=10**9+7
#テーブルを作る前処理
def COMinit():
    fac[0]=fac[1]=1
    finv[0]=finv[1]=1
    inv[1]=1
    for i in range(2,MAX):
      fac[i] = fac[i-1] * i % MOD
      inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD
      finv[i] = finv[i - 1] * inv[i] % MOD

#二項係数計算
def comb(n,k):
  if (n < k):
    return 0
  if (n < 0 or k < 0):
    return 0
  else:
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD

COMinit()
com=1
q=(26**K)%(10**9+7)
ans=0
for i in range(K+1):
  ans+=(q*comb(len(S)+i-1,i))%(10**9+7)#comb(len(S)+i-1,len(S)-1))%(10**9+7)
  q=(q*423076927)%(10**9+7)
  #com=(com*(len(S)+i))//(i+1)
print(ans%(10**9+7))
#print((25*576923081)%(10**9+7))

Buggy submission (verdict: Runtime Error):
K=int(input())
S=input()
n=K+len(S)
MAX=1000000
fac=[0]*MAX
finv=[0]*MAX
inv=[0]*MAX
MOD=10**9+7
#テーブルを作る前処理
def COMinit():
    fac[0]=fac[1]=1
    finv[0]=finv[1]=1
    inv[1]=1
    for i in range(2,MAX):
      fac[i] = fac[i-1] * i % MOD
      inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD
      finv[i] = finv[i - 1] * inv[i] % MOD

#二項係数計算
def comb(n,k):
  if (n < k):
    return 0
  if (n < 0 or k < 0):
    return 0
  else:
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD

COMinit()
com=1
q=(26**K)%(10**9+7)
ans=0
for i in range(K+1):
  ans+=(q*comb(len(S)+i-1,i))%(10**9+7)#comb(len(S)+i-1,len(S)-1))%(10**9+7)
  q=(q*423076927)%(10**9+7)
  #com=(com*(len(S)+i))//(i+1)
print(ans%(10**9+7))
#print((25*576923081)%(10**9+7))
Problem p02678 (python)

Fixed submission:
from collections import deque
import sys
sys.setrecursionlimit(10**7)
N,M=map(int,input().split())
A=[]
B=[]
road=[[] for i in range(N)]
for i in range(M):
  a,b=map(int,input().split())
  road[a-1].append(b-1)
  road[b-1].append(a-1)
visit=[0]*N

q=deque([0])
ans=[0]*N
visit[0]=1
def bfs(q):
  while(q):
    v=q.popleft()
    #print(v)
    for x in road[v]:
      if(visit[x]==0):
        q.append(x)
        #print(q)
        visit[x]=1
        ans[x]=v+1
        #print(x)
bfs(q)
print("Yes")
for i in range(N-1):
  print(ans[i+1])

Buggy submission (verdict: Runtime Error):
from collections import deque
import sys
sys.setrecursionlimit(10**7)
N,M=map(int,input().split())
A=[]
B=[]
road=[[] for i in range(N)]
for i in range(N):
  a,b=map(int,input().split())
  road[a-1].append(b-1)
  road[b-1].append(a-1)
visit=[0]*N

q=deque([0])
ans=[0]*N
visit[0]=1
def bfs(q):
  while(q):
    v=q.popleft()
    #print(v)
    for x in road[v]:
      if(visit[x]==0):
        q.append(x)
        #print(q)
        visit[x]=1
        ans[x]=v+1
        #print(x)
bfs(q)
print("Yes")
for i in range(N-1):
  print(ans[i+1])

Buggy submission (verdict: Runtime Error):
from collections import deque
import sys
sys.setrecursionlimit(10**7)
N,M=map(int,input().split())
A=[]
B=[]
road=[[] for i in range(M)]
for i in range(M):
  a,b=map(int,input().split())
  road[a-1].append(b-1)
  road[b-1].append(a-1)
visit=[0]*N

q=deque([0])
ans=[0]*N
visit[0]=1
def bfs(q):
  while(q):
    v=q.popleft()
    #print(v)
    for x in road[v]:
      if(visit[x]==0):
        q.append(x)
        #print(q)
        visit[x]=1
        ans[x]=v+1
        #print(x)
bfs(q)
print("Yes")
for i in range(N-1):
  print(ans[i+1])

Buggy submission (verdict: Runtime Error):
from collections import deque
N,M=map(int,input().split())
A=[]
B=[]
road=[[] for i in range(M)]
for i in range(M):
  a,b=map(int,input().split())
  road[a-1].append(b-1)
  road[b-1].append(a-1)
visit=[0]*N

q=deque([0])
ans=[0]*N
visit[0]=1
#print(road)
#print(road[1])
def bfs(q):
  while(q):
    v=q.popleft()
    #print(v)
    for x in road[v]:
      if(visit[x]==0):
        q.append(x)
        #print(q)
        visit[x]=1
        ans[x]=v+1
        #print(x)
bfs(q)
print("Yes")
for i in range(N-1):
  print(ans[i+1])
Problem p02727 (python)

Fixed submission:
X,Y,A,B,C=map(int,input().split())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))
p.sort()
q.sort()
p.reverse()
q.reverse()
p=p[:X]
q=q[:Y]
 
a=p[:]
a.extend(q)
a.extend(r)
a.sort()
a.reverse()
sum=0
for i in range(X+Y):
  sum+=a[i]
print(sum)

Buggy submission (verdict: Runtime Error):
X,Y,A,B,C=map(int,input().split())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))
p=[:X]
q=[:Y]
r=[:max(X,Y)]
p.sort()
q.sort()
p.reverse()
q.reverse()
 
a=p[:]
a.extend(q)
a.extend(r)
a.sort()
a.reverse()
b=q[:]
b.extend(r)
b.sort()
b.reverse()
c=p[:]
c.extend(r)
c.sort()
c.reverse()
red=0
green=0
sum=0
sum1=0
sum2=0
d=0
for i in range(X+Y):
  if(a[i] in p):
    red+=1
  elif(a[i] in q):
    green+=1
  d+=a[i]
 
  if(i<X):
      sum1+=p[i]
      sum2+=c[i]
  if(i<Y):
      sum1+=b[i]
      sum2+=q[i]
    
if(red<=X and green<=Y):
  print(d)
elif(red>X):
  print(sum1)
elif(green>Y):
  print(sum2)

Buggy submission (verdict: Runtime Error):
X,Y,A,B,C=map(int,input().split())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))

p.sort()
q.sort()
p.reverse()
q.reverse()

a=p[:]
a.extend(q)
a.extend(r)
a.sort()
a.reverse()
b=q[:]
b.extend(r)
b.sort()
b.reverse()
c=q[:]
c.extend(r)
c.sort()
c.reverse()
red=0
green=0
sum=0
sum1=0
sum2=0
d=0
for i in range(X+Y):
  if(a[i] in p):
    red+=1
  elif(a[i] in q):
    green+=1
  d+=a[i]
 
  if(i<X):
      sum1+=p[i]
      sum2+=b[i]
    if(i<Y):
      sum1+=b[i]
      sum2+=q[i]
    
if(red<=X and green<=Y):
  print(d)
elif(red>X):
  print(sum1)
elif(green>Y):
  print(sum2)
Problem p02731 (python)

Fixed submission:
L=int(input())
print((L/3)**3)

Buggy submission (verdict: Runtime Error):
L=input()
print((L/3)**3)
Problem p02732 (python)

Fixed submission:
N=int(input())
a=list(map(int,input().split()))
b=[0]*N
sum=0
for i in range(N):
  b[a[i]-1]+=1

for i in range(N):
  sum+=b[i]*(b[i]-1)//2
for i in range(N):
  print(sum-b[a[i]-1]+1)

Buggy submission (verdict: Runtime Error):
N=int(input())
a=list(map(int,input().split()))
b=[0]*N
sum=0
for i in range(N):
  b[a[i]]+=1

for i in range(N):
  sum+=b[i]*(b[i]-1)//2
for i in range(N):
  print(sum-b[a[i]]+1)

Buggy submission (verdict: Runtime Error):
N=int(input())
a=list(map(int,input().split()))
b=[0]*N
sum=0
for i in range(N):
  b[a[i]]+=1

for i in range(N):
  sum+=b[i]*(b[i]-1)//2
for i in range(N):
  print(sum-b[a[i]]-1)
Problem p02761 (python)

Fixed submission:
N,M=map(int,input().split())
ans=[-1]*N
flag=True
s=[]
c=[]
for i in range(M):
  s1,c1=map(int,input().split())
  s.append(s1)
  c.append(c1)
#sc = [map(int, input().split()) for _ in range(M)]
#s, c = [list(i) for i in zip(*sc)]
x=0
for i in range(M):
  s1=s[i]
  c1=c[i]
  if(ans[s1-1]==-1):
    ans[s1-1]=c1
  elif(ans[s1-1]!=c1):
    flag=False
  if(N>1 and s1==1 and c1==0):
    flag=False
if(flag==False):
  print("-1")
else:
  for i in range(N):
    if(N==1):
      if(ans[i]==-1):
        ans[i]=0
    else:
      if(i==0 and ans[i]==-1):
        ans[i]=1
      elif(ans[i]==-1):
        ans[i]=0
  for j in range(N):
    x+=ans[j]*(10**(N-j-1))
  print(x)

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
ans=[-1]*N
flag=True
sc = [map(int, input().split()) for _ in range(M)]
s, c = [list(i) for i in zip(*sc)]
x=0
for i in range(M):
  s1=s[i]
  c1=c[i]
  if(ans[s1-1]==-1):
    ans[s1-1]=c1
  elif(ans[s1-1]!=c1):
    flag=False
  if(N>1 and c1==0):
    flag=False
if(flag==False):
  print("-1")
else:
  for i in range(N):
    if(N==1):
      if(ans[i]==-1):
        ans[i]=0
    else:
      if(i==0 and ans[i]==-1):
        ans[i]=1
      elif(ans[i]==-1):
        ans[i]=0
  for j in range(N):
    x+=ans[j]*(10**(N-j-1))
  print(x)
Problem p03240 (python)

Fixed submission:
N=int(input())
x=[]
y=[]
h=[]
for i in range(N):
  a,b,c=map(int,input().split())
  x.append(a)
  y.append(b)
  h.append(c)
field=[[-1 for i in range(101)] for i in range(101)]
for i in range(N):
  for j in range(101):
    for k in range(101):
      if(h[i]!=0):
        if(field[j][k]==-1):
          field[j][k]=h[i]+abs(j-x[i])+abs(k-y[i])
        elif(field[j][k]!=h[i]+abs(j-x[i])+abs(k-y[i])):
          field[j][k]=-2
      else:
        if(field[j][k]>h[i]+abs(j-x[i])+abs(k-y[i])):
          field[j][k]=-2
cx=0
cy=0
H=0
for i in range(101):
  for j in range(101):
    if(field[i][j]>=0):
      cx=i
      cy=j
      H=field[i][j]
print(cx,cy,H)

Buggy submission (verdict: Runtime Error):
N=int(input())
x=[]
y=[]
h=[]
for i in range(N):
  a,b,c=map(int,input().split())
  x.append(a)
  y.append(b)
  h.append(c)
field=[[-1 for i in range(101)] for i in range(101)]
for i in range(N):
  for j in range(101):
    for k in range(101):
      if(field[j][k]==-1):
        field[j][k]=h[i]+abs(j-x[i])+abs(k-y[i])
      elif(field[j][k]!=h[i]+abs(j-x[i])+abs(k-y[i])):
        field[j][k]=-2
for i in range(101):
  for j in range(101):
    if(field[i][j]>=0):
      cx=i
      cy=j
      H=field[i][j]
print(cx,cy,H)