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

Fixed submission:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    temp = A[0]
    su = 0
    for i in range(1, N):
        if A[i - 1] > A[i]:
            su += A[i - 1] - A[i]
            A[i] = A[i - 1]
    print(su)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    N = input()
    if int(N) < 1 or int(N) >= 2*10**5:
        raise ValueError
    A = []
    for i in input().split():
        if int(i) < 1 or int(i) >= 10**9:
            raise ValueError
        A.append(int(i))
    temp = A[0]
    su = 0
    for i in A:
        if i >= temp:
            height = 0
        else:
            height = temp-i
        temp = i + height
        su += height
    print(su)


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

Fixed submission:
a = int(input())

if a < 30:
  print('No')
else:
  print('Yes')

Buggy submission (verdict: Runtime Error):
n, d = input().split()
n = int(n)
d = int(d)
xy = [map(int, input().split()) for _ in range(n)]
x, y = [list(i) for i in zip(*xy)]
c = 0

for i in range(n):
  if x[i]*x[i]+y[i]*y[i] <= d*d:
    c +=1

print(c)
Problem p02595 (python)

Fixed submission:
n, d = input().split()
n = int(n)
d = int(d)
xy = [map(int, input().split()) for _ in range(n)]
x, y = [list(i) for i in zip(*xy)]
c = 0

for i in range(n):
  if x[i]*x[i]+y[i]*y[i] <= d*d:
    c +=1

print(c)

Buggy submission (verdict: Runtime Error):
n, d = input().split()
n = int(n)
d = int(d)
xy = [map(int, input().split()) for _ in range(5)]
x, y = [list(i) for i in zip(*xy)]
c = 0

for i in range(n):
  if x[i]*x[i]+y[i]*y[i] <= d*d:
    c +=1

print(c)
Problem p02597 (python)

Fixed submission:
n = int(input())
s = input()
a = [str(c) for c in s]

def sea(a, x, y, n):
  while x < n-1:
    if a[x] == 'W':
      break
    x += 1
    
  while y > 0:
    if a[y] == 'R':
      break
    y -= 1
  
  return[x, y]

z = [0, n-1]

z = sea(a, z[0] ,z[1], n)
c = 0
while z[0] < z[1]:
  a[z[0]], a[z[1]] = a[z[1]], a[z[0]]
  c += 1
  z = sea(a,z[0], z[1],n)
  
print(c)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input()
a = [str(c) for c in s]

def sea(a, z, n):
  while z[0] < n-1:
    if a[z[0]] == 'W':
      break
    z[0] += 1
    
  while z[1] > 0:
    if a[z[1]] == 'R':
      break
    z[1] += 1
  
  return(z)

z = [0, n-1]

z = a(a, z, n)
c = 0
while z[0] < z[1]:
  a[z[0]], a[z[1]] = a[z[1]], a[z[0]]
  c += 1
  z = a(a,z,n)
  
print(c)

Buggy submission (verdict: Runtime Error):
n= int(input())
s = input()
a = [str(c) for c in s]

z = [0, n-1]


def search(a,n,x,y):
  x1 = x
  y1 = y

  for i in range(n):
    x = x1 + i
    if a[x1 +i] == 'W':
      break
  for i in range(n):
    y = y1 -i
    if a[y1-i] == 'R':
      break
  return[x, y]

c = 0

while True:
  z = search(a, n, z[0],z[1])
  if z[0] > z[1]:
    break
  else:
    c +=1
    a[z[0]], a[z[1]] = a[z[1]], a[z[0]]
  
  
    
print(c)
Problem p02622 (python)

Fixed submission:
s = input()
a = [str(c) for c in s]
t = input()
b = [str(c) for c in t]

c = 0
n = len(a)
for i in range(n):
  if a[i] == b[i]:
    c +=1

print(n-c)

Buggy submission (verdict: Runtime Error):
s = input()
a = [str(c) for c in s]
t = input()
b = [str(c) for c in s]

c = 0

for i in range(n):
  if a[i] == b[i]:
    c +=1

print(n-c)
Problem p02707 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
b = [0]*(n+1)

for i in range(n-1):
  b[a[i]] += 1

for i in range(1,n+1):
  print(b[i])

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
b = [0]*(n+1)

for i in range(1, n+1):
  print(a.count[i])
Problem p02711 (python)

Fixed submission:
s = input()
a = [int(c) for c in s]

if bool(a[0]!=7 and a[1]!=7 and a[2]!=7):
        print("No")
else:
        print("Yes")

Buggy submission (verdict: Runtime Error):
s = input()
a = [int(c) for c in s]

if bool(a[0]!=7 and a[1]!=7 and a[2]!=7):
        print("No")
else
        print("Yes")

Buggy submission (verdict: Runtime Error):
s = input()
a = [int(c) for c in s]

if bool(a[0]!=7 and a[1]!=7 and a[2]!=7:
        print("No")
else
        print("Yes")
Problem p02729 (python)

Fixed submission:
import math
n, m = input().split()
n = int(n)
m = int(m)
x = 0
y = 0
if n > 1:
  x = int(math.factorial(n)/(2 * math.factorial(n-2)))
if m > 1:
  y = int(math.factorial(m)/(2 * math.factorial(m-2)))

print(x+y)

Buggy submission (verdict: Runtime Error):
import math
n, m = input().split()
n = int(n)
m = int(m)

print(int(math.factorial(n)/(2 * math.factorial(n-2)) + math.factorial(m)/(2 * math.factorial(m-2))))

Buggy submission (verdict: Runtime Error):
import math
n, m = input().split()
n = int(n)
m = int(m)

print(int(math.factorial(n)/(2 * math.factorial(n-2)) + math.factorial(m)/(2 * math.factorial(m-2))))

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

print(n!/(2 * (n-2)!) + m!/(2 * (n-2)!))
Problem p02627 (python)

Fixed submission:
s=input()
print("a" if s == s.lower() else "A")

Buggy submission (verdict: Runtime Error):
s=input()
print("a" if s=s.lower() else "A")
Problem p02685 (python)

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

fac = [1] * (N+1)
inv = [1] * (N+1)
ifac = [1] * (N+1)
for i in range(2,N+1):
    fac[i]=(fac[i-1]*i)%MOD
    inv[i]= -(inv[MOD%i]*(MOD//i))%MOD
    ifac[i]=(ifac[i-1]*inv[i])%MOD

cmbarr = [1] * N
for r in range(N-1):
    cmbarr[r+1] = cmbarr[r] * (N - 1 - r) * inv[r + 1] % MOD

A = [M*pow(M-1,N-1-i,MOD)*cmbarr[i] % MOD for i in range(K+1)]
print(sum(A) % MOD)

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

MOD = 998244353
F = 10**5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, F + 1 ):
    g1.append( ( g1[-1] * i ) % MOD )
    inverse.append( ( -inverse[MOD % i] * (MOD//i) ) % MOD )
    g2.append( (g2[-1] * inverse[-1]) % MOD )

def cmb(n, r, MOD):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % MOD

A = [M*pow(M-1,N-1-i,MOD) % MOD for i in range(K+1)]
A = [A[i] * cmb(N-1,i,MOD) % MOD for i in range(K+1)]
print(sum(A) % MOD)
Problem p02819 (python)

Fixed submission:
x = int(input())
num = 100200
arr = list(range(2,num))
arr = set(arr)
primes = {2}
floor = int(num**0.5)+2

prime = min(arr)
while prime < floor:
    prime = min(arr)
    primes.add(prime)
    nonprime = {prime * i for i in range(1,num//prime + 2)}
    arr = arr.difference(nonprime)

primes = primes.union(arr)

sol = {i for i in primes if i >= x}

print(min(sol))

Buggy submission (verdict: Runtime Error):
x = int(input())
num = 11000
arr = list(range(2,num))
arr = set(arr)
primes = {2}

prime = min(arr)
while prime < num-500:
    primes.add(prime)
    nonprime = {prime * i for i in range(1,num//prime + 2)}
    arr = arr.difference(nonprime)
    prime = min(arr)

sol = {i for i in primes if i >= x}

print(min(sol))

Buggy submission (verdict: Runtime Error):
x = int(input())
num = 11000
arr = list(range(2,num))
arr = set(arr)
primes = {2}

prime = min(arr)
while prime < num-500:
    primes.add(prime)
    nonprime = {prime * i for i in range(1,num//prime + 2)}
    arr = arr.difference(nonprime)
    prime = min(arr)

arr = {i for i in primes if i > x }
print(min(arr))

Buggy submission (verdict: Runtime Error):
x = int(input())
num = 11000
arr = list(range(2,num))
arr = set(arr)
primes = {2}

prime = min(arr)
while prime < num-500:
    primes.add(prime)
    nonprime = {prime * i for i in range(1,num//prime + 2)}
    arr = arr.difference(nonprime)
    prime = min(arr)

arr = {i for i in primes if i > x }
print(min(arr))
Problem p02879 (python)

Fixed submission:
a,b = map(int,input().split())
if a<=9 and b<=9:
    print(a*b)
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
a,b = map(int,input())
if a<=9 and b<=9:
    print(a*b)
else:
    print(-1)
Problem p02990 (python)

Fixed submission:
from operator import mul
from functools import reduce

def combination(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

N, K = tuple(map(int, input().split()))
mod = 10**9+7
for i in range(K):
    if i <= N-K:
        print( ( combination(K-1,i)*combination(N-K+1,i+1) ) % mod )
    else:
        print(0)

Buggy submission (verdict: Runtime Error):
import math

def combination(n,r):
    return int ( math.factorial(n) / math.factorial(n-r) / math.factorial(r) )
def permutation(n,r):
    return int( math.factorial(n) / math.factorial(n-r) )

N, K = tuple(map(int, input().split()))
mod = 10**9+7
for i in range(K):
    if i <= N-K:
        print( ( combination(K-1,i)*combination(N-K+1,i+1) ) % mod )
    else:
        print(0)

Buggy submission (verdict: Runtime Error):
import math

def combination(n,r):
    return int ( math.factorial(n) / math.factorial(n-r) / math.factorial(r) )
def permutation(n,r):
    return int( math.factorial(n) / math.factorial(n-r) )

N, K = tuple(map(int, input().split()))
mod = 10**9+7
for i in range(K):
    if N >= 2*(i+1)-1:
        print( ( combination(K-1,i)*combination(N-K+1,i+1) ) % mod )
    else:
        print(0)
Problem p02578 (python)

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

s=0
for i in range(n-1):
  if b[i]>a[i+1]:
    s+=(a[i]-a[i+1])
    b[i+1]=b[i]
print(s)

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

s=0
for i in range(n):
  if b[i]>a[i+1]:
    s+=(a[i]-a[i+1])
    b[i+1]=b[i]
print(s,a,b)
Problem p02781 (python)

Fixed submission:
n=input()
k=int(input())
l=len(n)
dp=[[[0 for _ in range(2)] for _ in range(5)] for _ in range(l+1)]
dp[0][1][1]=int(n[0])-1
dp[0][1][0]=1
for i in range(1,l):
  for j in range(4):
    b=i-1
    now=int(n[i])
    if now==0:
      dp[i][j][0]+=dp[b][j][0]
    else:
      dp[i][j][1]+=dp[b][j][0]
      dp[i][j+1][1]+=dp[b][j][0]*(now-1)
      dp[i][j+1][0]+=dp[b][j][0]
    dp[i][j][1]+=dp[b][j][1]
    dp[i][j+1][1]+=dp[b][j][1]*9
  dp[i][1][1]+=9
print(dp[l-1][k][0]+dp[l-1][k][1])

Buggy submission (verdict: Runtime Error):
dp[0][1][1]=int(n[0])-1
dp[0][1][0]=1
dp[0][0][1]=1

for i in range(1,l):
  for j in range(4):
    b=i-1
    now=int(n[i])
    if now==0:
      dp[i][j][0]+=dp[b][j][0]
    else:
      dp[i][j][1]+=dp[b][j][0]
      dp[i][j+1][1]+=dp[b][j][0]*(now-1)
      dp[i][j+1][0]+=dp[b][j][0]
    dp[i][j][1]+=dp[b][j][1]
    dp[i][j+1][1]+=9*dp[b][j][1]
print(dp[l-1][k][0]+dp[l-1][k][1])

Buggy submission (verdict: Runtime Error):
n=input()
k=int(input())
l=len(n)

dp=[[[0 for _ in range(2)] for _ in range(5)] for _ in range(l+1)]

dp[0][1][1]=int(n[0]-1)
dp[0][1][0]=1
dp[0][0][1]=1

for i in range(1,l):
  for j in range(4):
    b=i-1
    now=n[i]
    if now==0:
      dp[i][j][0]+=dp[b][j][0]
    else:
      dp[i][j][1]+=dp[b][j][0]
      dp[i][j+1][1]+=dp[b][j][0]*(now-1)
      dp[i][j+1][0]+=dp[b][j][0]
    dp[i][j][1]+=dp[b][j][1]
    dp[i][j+1][1]+=9*dp[b][j][1]
print(dp[l-1][k][0]+dp[l-1][k][1])

Buggy submission (verdict: Runtime Error):
n=input()
k=int(input())
l=len(n)

dp=[[[0 for _ in range(2)] for _ in range(5)] for _ in range(l+1)]

dp[0][1][1]=int(n[0]-1)
dp[0][1][0]=1
dp[0][0][1]=1

for i in range(1,l):
  for j in range(4):
    b=i-1
    now=n[i]
    if now==0:
      dp[i][j][0]+=dp[b][j][0]
    else:
      dp[i][j][1]+=dp[b][j][0]
      dp[i][j+1][1]+=dp[b][j][0]*(now-1)
      dp[i][j+1][0]+=dp[b][j][0]
print(dp[l-1][k][0]+dp[l-1][k][1])

Buggy submission (verdict: Runtime Error):
n=input()
k=int(input())
l=len(n)
dp=[[[0 for _ in range(2)] for _ in range(5)] for _ in range(l+1)]
dp[0][1][1]=int(n[0])-1
dp[0][1][0]=1
for i in range(1,L):
  for j in range(4):
    b=i-1
    now=int(n[i])
    if now=0:
      dp[i][j][0]+=dp[b][j][0]
    else:
      dp[i][j][1]+=dp[b][j][0]
      dp[i][j+1][1]+=dp[b][j][0]*(now-1)
      dp[i][j+1][0]+=dp[b][j][0]
    dp[i][j][1]+=dp[b][j][1]
    dp[i][j+1][1]+=dp[b][j][1]*9
  dp[i][1][1]+=9
print(dp[l-1][k][0]+dp[l-1][k][1])
Problem p02790 (python)

Fixed submission:
a,b=map(str,input().split())
if int(a)<=int(b):
  s=a
  for i in range(int(b)-1):
    s+=a
  print (s)
else:
  s=b
  for j in range(int(a)-1):
    s+=b
  print(s)

Buggy submission (verdict: Runtime Error):
a,b=map(str,input().split())
if int(a)<=int(b):
  s=a
  for i in range(b-1):
    s+=a
  print (s)
else:
  s=b
  for j in range(a-1):
    s+=b
  print(s)

Buggy submission (verdict: Runtime Error):
a,b=map(str,input().split())
if int(a)<=int(b):
  s=a
  for _ in range(b-1):
    s+=a
  print (s)
else:
  s=b
  for _ in range(a-1):
    s+=b
  print(s)

Buggy submission (verdict: Runtime Error):
a,b=map(str,input().split())
if a<=b:
  s=a
  for _ in range(b-1):
    s+=a
  print (s)
else:
  s=b
  for _ in range(a-1):
    s+=b
  print(s)
Problem p02699 (python)

Fixed submission:
s, w = map(int, input().split())
if s > w:
    print('safe')
else:
    print('unsafe')

Buggy submission (verdict: Runtime Error):
a, b, c, d = map(int, input().split())
if c // b >= a // d:
    print('Yes')
else:
    print('No')
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, b = [0], [0]
for i in range(N):
	a.append(a[i] + A[i])
for i in range(M):
	b.append(b[i] + B[i])
      
ans, j = 0, M
for i in range(N + 1):
	if a[i] > K:
		break
	while b[j] > K - a[i]:
		j -= 1
	ans = max(ans, i + j)
print(ans)

Buggy submission (verdict: Runtime Error):
#include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define EPS (1e-10)

using namespace std;

int main(int argc, char *argv[]) {

	long N,M; cin >> N >> M;
	long K; cin >> K;
	
	vector<long> A(N+1,0);
	for (int i = 1; i <= N; i++) {
		int a; cin >> a;
		A[i] = A[i-1] + a;
	}

	vector<long> B(M+1,0);
	for (int i = 1; i <= M; i++) {
		int b; cin >> b;
		B[i] = B[i-1] + b;
	}

	long ans = 0;
	long best = M;
	for (int i = 1; i <= N; i++) {
		if (A[i] > K) {
			break;	
		}
		
		while (1 < best and B[best] > K - A[i]) {
			best--;		
		}
		ans = max(ans, i+best);

	}
	cout << ans << endl;



	return 0;
}
Problem p02679 (python)

Fixed submission:
from collections import defaultdict
import math

def main():
    MOD = 10**9+7
    N = int(input())
    zero_cnt = 0
    L = defaultdict(int)
    L2 = defaultdict(int)
    for _ in range(N):
        x,y = map(int,input().split())
        if x == 0 and y == 0:
            zero_cnt += 1
            continue
        d = math.gcd(x,y)
        x //= d
        y //= d
        if x == 0 and y == 0:
            zero_cnt += 1
        if y < 0:
            x *= -1
            y *= -1
        elif ｙ == 0 and ｘ < 0:
            x *= -1
            y *= -1
        rot90 = (x <= 0)
        if rot90:
            tmp = x
            x = y
            y = -tmp
        if rot90:
            L[(x,y)] += 1
        else:
            L2[(x,y)] += 1

    ans = 1
    keys = set(list(L.keys()) + list(L2.keys()))
    for k in keys:
        now = 1
        s = L[k]
        t = L2[k]
        now += pow(2,s,MOD) - 1
        now += pow(2,t,MOD) -1
        ans *= now
        ans %= MOD
    ans -= 1
    ans += zero_cnt
    print(ans%MOD)

main()

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
MOD = 10**9+7
N = int(input())
bul = defaultdict(int)
bul2 = defaultdict(int)
for _ in range(N):
    a,b = map(int,input().split())
    bul[a/b] += 1
    bul2[-(b/a)] += 1

ALL = pow(2,N,MOD)-1

for k in bul.keys():
    if k <= 0:
        ALL -= bul2[k] * bul[k] * (N-1)
        ALL %= MOD

print(ALL)
Problem p02685 (python)

Fixed submission:
import math

N ,M, K = map(int,input().split())
MOD = 998244353

def getInvs(n, MOD):
    invs = [1] * (n+1)
    for x in range(2, n+1):
        invs[x] = (-(MOD//x) * invs[MOD%x]) % MOD
    return invs
invs = getInvs(N+3, MOD)

num = M
nums = []
for i in reversed(range(1,N)):
    nums.append(num)
    num *= i*(M-1)
    num *= invs[N-i]
    num %= MOD
nums.append(num)
nums.reverse()

ans = sum(nums[:K+1])
ans %= MOD
print(ans)

Buggy submission (verdict: Runtime Error):
import math

N ,M, K = map(int,input().split())
MOD = 998244353
SUM = 0

fact = [1]
fact_inv = [1]
for i in range(1,N+1):
    fact.append(fact[-1] * i)
    if i <= max(N-K,K)+1:
        fact_inv.append(pow(fact[-1],MOD-2,MOD))

def combinations_count(n, r):
    return (((fact[n] * fact_inv[n-r])%MOD) * fact_inv[r])%MOD

for i in range(K+1):
    if N -1 - i >= 0:
        SUM += M * pow(M-1,N-1-i,MOD) * combinations_count(N-1,i)
        SUM %= MOD

print(SUM)

Buggy submission (verdict: Runtime Error):
import math

N ,M, K = map(int,input().split())
MOD = 998244353
SUM = 0

fact = [1]
fact_inv = [1]
for i in range(1,N+1):
    fact.append(fact[-1] * i)
    if i <= min(N-K,K)+1:
        fact_inv.append(pow(fact[-1],MOD-2,MOD))

def combinations_count(n, r):
    return (((fact[n] * fact_inv[n-r])%MOD) * fact_inv[r])%MOD

for i in range(K+1):
    if N -1 - i >= 0:
        SUM += M * pow(M-1,N-1-i,MOD) * combinations_count(N-1,i)
        SUM %= MOD

print(SUM)
Problem p02689 (python)

Fixed submission:
from collections import defaultdict

N ,M = map(int,input().split())
H = list(map(int,input().split()))
graph = defaultdict(int)
for _ in range(M):
    A, B = map(int,input().split())
    graph[A]= max(graph[A],H[B-1])
    graph[B]= max(graph[B],H[A-1])

print(sum(H[i-1] > graph[i] for i in range(1,N+1)))

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

N ,M = map(int,input().split())
H = list(map(int,input().split()))
graph = defaultdict(list)
for _ in range(M-1):
    A, B = map(int,input().split())
    graph[A].append(H[B-1])
    graph[B].append(H[A-1])

cnt = 0
for i in range(1,N+1):
    t = H[i-1]
    a = max(graph[i])
    if t >a:
        cnt += 1
print(cnt)
Problem p02762 (python)

Fixed submission:
from collections import defaultdict
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
N, M, K = map(int, input().split())

def dfs(v):
    size = 1
    for w in fr[v]:
        if ~roots[w]: continue
        roots[w] = roots[v]
        size += dfs(w)
    return size

fr = defaultdict(set)
for _ in range(M):
    a, b = [int(x) -1 for x in input().split()]
    fr[a].add(b)
    fr[b].add(a)
bl = defaultdict(set)
for _ in range(K):
    a, b = [int(x) - 1 for x in input().split()]
    bl[a].add(b)
    bl[b].add(a)

roots = [-1] * N
sizes = [-1] * N

for v in range(N):
    if ~roots[v]: continue
    roots[v] = v
    sizes[v] = dfs(v)

ans = []
for v in range(N):
    w = roots[v]
    res = sizes[w] - len(fr[v]) - sum(1 for u in bl[v] if roots[u] == w) -1
    ans.append(res)

print(*ans)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
import sys
input = sys.stdin.readline
N, M, K = map(int, input().split())

def dfs(v):
    size = 1
    for w in fr[v]:
        if ~roots[w]: continue
        roots[w] = roots[v]
        size += dfs(w)
    return size

fr = defaultdict(set)
for _ in range(M):
    a, b = [int(x) -1 for x in input().split()]
    fr[a].add(b)
    fr[b].add(a)
bl = defaultdict(set)
for _ in range(K):
    a, b = [int(x) - 1 for x in input().split()]
    bl[a].add(b)
    bl[b].add(a)

roots = [-1] * N
sizes = [-1] * N

for v in range(N):
    if ~roots[v]: continue
    roots[v] = v
    sizes[v] = dfs(v)

ans = []
for v in range(N):
    w = roots[v]
    res = sizes[w] - len(fr[v]) - sum(1 for u in bl[v] if roots[u] == w) -1
    ans.append(res)

print(*ans)

Buggy submission (verdict: Runtime Error):
N, M = [int(i) for i in input().split(' ')]
SC = []
for _ in range(M):
    SC.append([int(i) for i in input().split(' ')])

ch = [-1] * N
for s,c in SC:
    if N >1:
        if s == 1 and c == 0:
            print(-1)
            exit()

    if ch[s-1] == -1 or ch[s-1] == c:
        ch[s-1] = c
    else:
        print(-1)
        exit()
s = 10**(N-1) if N >1 else 0
f = 10 ** N if N >1 else 10
for n in range(s,f):
    n = list(str(n))
    flg = 0
    for s,c in SC:
        if not n[s-1] == str(c):
            flg = 1

    if flg == 0:
        print(''.join(n))
        exit()
Problem p02793 (python)

Fixed submission:
import fractions

N = int(input())
A = list(map(int,input().split()))
MOD = 10** 9 + 7
lcm = 1
for a in A:
    lcm = a // fractions.gcd(a,lcm) * lcm

print(sum(lcm//a for a in A)%MOD)

Buggy submission (verdict: Runtime Error):
import fractions
from functools import reduce
MOD = 10**9 + 7

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

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

LCM = lcm(*A)
ans = 0
for a in A:
    ans += LCM/a
    ans %= MOD

print(int(ans))

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce
MOD = 10**9 + 7

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

def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

LCM = lcm(*A)
ans = 0
for a in A:
    ans += LCM/a
    ans %= MOD

print(int(ans))
Problem p03017 (python)

Fixed submission:
n,a,b,c,d = map(int,input().split())
S = list(input())

flg = 1
for i in range(a-1,c-2):
    if S[i:i+2] == ['#','#']:
        flg *= 0

for i in range(b-1,d-2):
    if S[i:i+2] == ['#','#']:
        flg *= 0

if c>d:
    flg2 = 0
    for i in range(b-1,d):
        if S[i-1:i+2] == ['.','.','.']:
            flg2 = 1
    flg *= flg2

if flg == 0:
    print('No')
else:
    print('Yes')

Buggy submission (verdict: Runtime Error):
n,a,b,c,d = map(int,input().split())
S = list(input())
S = ['#'].expand(S)
print(S)

flg = 1
for i in range(a-1,c-2):
    if S[i:i+2] == ['#','#']:
        flg *= 0

for i in range(b-1,d-2):
    if S[i:i+2] == ['#','#']:
        flg *= 0

if c>d:
    flg2 = 0
    for i in range(b-1,d):
        if S[i-1:i+2] == ['.','.','.']:
            flg2 = 1
    flg *= flg2

if flg == 0:
    print('No')
else:
    print('Yes')
Problem p03011 (python)

Fixed submission:
p, q, r = list(map(int, input().split()))
print(p + q + r - max(p, q, r))

Buggy submission (verdict: Runtime Error):
import sys

mod = 10**9 + 7


def extgcd(a, b):
    r = [1, 0, a]
    w = [0, 1, b]
    while w[2] != 1:
        q = r[2] // w[2]
        r2 = w
        w2 = [r[0] - q * w[0], r[1] - q * w[1], r[2] - q * w[2]]
        r = r2
        w = w2
    return [w[0], w[1]]


def mod_inv(a, m):
    x = extgcd(a, m)[0]
    return (m + x % m) % m


def Cmb(n, k):
    res = 1
    for i in range(1, n + 1):
        res = res * i % mod
    for i in range(1, k + 1):
        res = res * mod_inv(i, mod) % mod
    for i in range(1, n - k + 1):
        res = res * mod_inv(i, mod) % mod
    return res


n, m = list(map(int, input().split()))
a = [int(input()) for _ in range(m)]
l = len(a)

if 1 in [a[i + 1] - a[i] for i in range(l - 1)]:
    print(0)
    sys.exit()

b = [-1] + a + [n + 1]
c = []
for bi, bi2 in zip(b[:-1], b[1:]):
    c.append((bi2 - 1) - (bi + 1))  # width 2 を取れる数


def count(n):
    ret = 0
    for i in range(n // 2 + 1):
        ret += Cmb(n - i, i) % mod
    return ret


ans = 1
for ci in c:
    ans *= count(ci) % mod
    ans %= mod

print(ans)
Problem p03075 (python)

Fixed submission:
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

d = e - a
k = int(input())

ans = "Yay!" if k >= d else ":("
print(ans)

Buggy submission (verdict: Runtime Error):
from itertools import product

x, y, z, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ab = [ai + bi for (ai, bi) in product(a, b)]
ab.sort(reverse=True)
abc = [abi + ci for (abi, ci) in product(ab[: min(k, x * y * z)], c)]
abc.sort(reverse=True)

for abci in abc[: min(k, x * y * z)]:
    print(abci)

Buggy submission (verdict: Runtime Error):
for i in range(5)
	a[i]= int(input())

d = a[4] - a[0]
k = int(input())

ans = 'Yay!' if k >= d else ':('
print(ans)