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

Fixed submission:
N, W = map(int, input().split())  # N<=100, W<=10**9
w, v = [0] * N, [0] * N
for i in range(N):
    w[i], v[i] = map(int, input().split())  # すべての i=2,3,…,N について、w1 ≦ wi ≦ w1+3

#

def kaihou():
    monos_by_omosa = [[] for _ in range(4)]
    w0 = w[0]
    for i in range(N):
        monos_by_omosa[w[i] - w0].append(v[i])
    for i in range(4):
        monos_by_omosa[i].sort()
        monos_by_omosa[i].reverse()
    # print(monos_by_omosa)
    ans = 0
    for i in range(N + 1):
        if i > len(monos_by_omosa[0]):
            break
        w0i = (w0) * i
        if w0i > W:
            break

        for j in range(N + 1 - i):
            if j > len(monos_by_omosa[1]):
                break
            w1j = (w0 + 1) * j
            if w0i + w1j > W:
                break

            for k in range(N + 1 - i - j):
                if k > len(monos_by_omosa[2]):
                    break
                w2k  = (w0 + 2) * k
                if w0i + w1j + w2k > W:
                    break

                for l in range(N + 1 - i - j - k):
                    if l > len(monos_by_omosa[3]):
                        break
                    w3l = (w0 + 3) * l
                    if w0i + w1j + w2k + w3l > W:
                        break

                    val = sum(monos_by_omosa[0][:i])
                    val += sum(monos_by_omosa[1][:j])
                    val += sum(monos_by_omosa[2][:k])
                    val += sum(monos_by_omosa[3][:l])
                    ans = max(ans, val)
    return ans

print(kaihou())

Buggy submission (verdict: Runtime Error):
N, W = map(int, input().split())
w, v = [0] * N, [0] * N
for i in range(N):
    w[i], v[i] = map(int, input().split())


def simple_dp():
    offset = w[0]
    maximum = min(100 * (w[0] + 3), W + 1)
    dp = [[-1] * (maximum + 1) for _ in range(N + 1)]
    dp[0][0] = 0
    for i in range(N):
        if w[i] <= W:
            dp[i + 1][w[i]] = max(dp[i + 1][w[i]], dp[i][0] + v[i])
        dp[i + 1][0] = dp[i][0]

        for jj in list(range(w[0], maximum + 1)):
            j = jj - offset + 1
            if dp[i][j] < 0:
                continue
            if jj + w[i] <= W + 1:
                dp[i + 1][j + w[i]] = max(dp[i + 1][j + w[i]], dp[i][j] + v[i])
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])
        # print(list(zip(*dp)))

    ans = 0
    for i in range(W + 1):
        ans = max(ans, dp[N][i])
    return ans

print(simple_dp())

Buggy submission (verdict: Runtime Error):
N, W = map(int, input().split())
w, v = [0] * N, [0] * N
for i in range(N):
    w[i], v[i] = map(int, input().split())


def simple_dp():
    dp = [[-1] * (W + 1) for _ in range(N + 1)]
    dp[0][0] = 0
    for i in range(N):
        for j in [0] + list(range(w[0], min(100 * (w[0] + 3), W + 1))):
            if dp[i][j] < 0:
                continue
            if j + w[i] <= W:
                dp[i + 1][j + w[i]] = max(dp[i + 1][j + w[i]], dp[i][j] + v[i])
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])

    ans = 0
    for i in range(W + 1):
        ans = max(ans, dp[N][i])
    return ans

print(simple_dp())
Problem p02995 (python)

Fixed submission:
#!/usr/local/bin/python3

import fractions

def solve(a,b,c,d):
	a = a - 1
	l = c * d // fractions.gcd(c, d)
	r1 = a - (a // c + a // d - a // l)
	r2 = b - (b // c + b // d - b // l)
	return (r2 - r1)


a,b,c,d = map(int, input().split())
ans = solve(a,b,c,d)
print(ans)

Buggy submission (verdict: Runtime Error):
#!/usr/local/bin/python3

import math

def solve(a,b,c,d):
	a = a - 1
	l = int(c * d / math.gcd(c, d))
	r1 = a - (a // c + a // d - a // l)
	r2 = b - (b // c + b // d - b // l)
	return (r2 - r1)


a,b,c,d = map(int, input().split())
ans = solve(a,b,c,d)
print(ans)
Problem p03125 (python)

Fixed submission:
A, B = map(int, input().split())
if B % A == 0:
  print(A + B)
else:
  print(B - A)

Buggy submission (verdict: Runtime Error):
A = int(input())
B = int(input())
if B % A == 0:
  print(A + B)
else:
  print(B - A)

Buggy submission (verdict: Runtime Error):
A = int(input())
B = int(input())
if B % A == 0:
  print(A + B)
else:
  print(A - B)
Problem p03254 (python)

Fixed submission:
N, x = map(int, input().split())
a = list(map(int, input().split()))
a = sorted(a)
sum = 0
ans = 0
for i in range(len(a) - 1):
    sum += a[i]
    if sum > x:
        break
    else:
        ans += 1
sum += a[N-1]
if sum == x:
    ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
N, x = map(int, input().split())
a = list(map(int, input().split()))
a = sorted(a)
sum = 0
ans = 0
for i in range(len(a) - 1):
    sum += a[i]
    if s > x:
        break
    else:
        ans += 1
sum += a[N-1]
if sum == x:
    ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
N, x = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
a = sorted(a)
for i in range(len(a)):
	if x >= a[i]:
		x -= a[i]
		ans += 1
    else:
      break
print(ans)
Problem p03261 (python)

Fixed submission:
N = int(input())
W = [input() for _ in range(N)]
ans = 'Yes'
W_set = set(W)
if len(W) == len(W_set):
  for i in range(1, N):
    if W[i][0] != W[i-1][-1]:
      ans = 'No'
      break
else:
  ans = 'No'
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
W = [list(input()) for _ in range(N)]
ans = 'Yes'
W_set = set(W)
if len(W) == len(W_set):
  for i in range(1, N - 1):
    if W[i][0] != W[i-1][-1]:
      ans = 'No'
      break
else:
  ans = 'No'
print(ans)
Problem p03274 (python)

Fixed submission:
N, K = map(int, input().split())
x = list(map(int, input().split()))
ans = pow(10, 10)
for i in range(N-K+1):
    temp_l = abs(x[i]) + abs(x[i]-x[i+K-1])
    temp_r = abs(x[i+K-1]) + abs(x[i]-x[i+K-1])
    ans = min(ans, temp_l, temp_r)
print(ans)

Buggy submission (verdict: Runtime Error):
N, K=map(int, input().split())
x = list(map(int, input().split()))
ans = pow(10, 10)
for i in range(N-K+1):
    temp1 = abs(x[i]) + abs(x[i]-x[i+K-1])
    #temp2 = abs(x[i+K-1]) + abs(x[i]-x[i+K-1])
    ans = min(ans, temp1, temp2)
print(ans)
Problem p03280 (python)

Fixed submission:
A, B = map(int, input().split())
print((A - 1) * (B - 1))

Buggy submission (verdict: Runtime Error):
A = int(input())
B = int(input())
print((A - 1) * (B - 1))
Problem p03294 (python)

Fixed submission:
N = int(input())
a = list(map(int, input().split()))
ans = 0
for x in a:
	ans += x - 1
print(ans)

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce

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

def lcm_list(a):
    return reduce(lcm_base, a, 1)

N = int(input())
a = list(map(int, input().split()))
ans = 0
num = lcm_list(a) - 1
for i in range(len(a)):
	ans += num % a[i]
print(ans)

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce

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

def lcm_list(a):
    return reduce(lcm_base, a, 1)

N = int(input())
a = list(map(int, input().split()))
ans = 0
num = lcm_list(a) - 1
print(num)
for i in range(len(a)):
	ans += num % a[i]
print(ans)

Buggy submission (verdict: Runtime Error):
import math

N = int(input())
a = list(map(int, input().split()))
ans = 0
num = 0
for i in range(1, len(a)):
	num *= int(a[i-1] * a[i] / math.gcd(a[i-1],a[i]))
num -= 1
for i in range(len(a)):
	ans += num % a[i]
print(ans)

Buggy submission (verdict: Runtime Error):
import math

N = int(input())
a = list(map(int, input().split()))
ans = 0
num = 0
for i in range(1, len(a)):
	num *= a[i-1] * a[i] // math.gcd(a[i-1],a[i])
num -= 1
for i in range(len(a)):
	ans += num % a[i]
print(ans)

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce

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

def lcm_list(a):
    return reduce(lcm_base, a)
if __name__ == '__main__':
	N = int(input())
	a = list(map(int, input().split()))
	ans = 0
	num = lcm_list(a) - 1
	print(num)
	for i in range(len(a)):
		ans += num % a[i]
	print(ans)

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce

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

def lcm_list(a):
    return reduce(lcm_base, a)

N = int(input())
a = list(map(int, input().split()))
ans = 0
num = lcm_list(a) - 1
print(num)
for i in range(len(a)):
	ans += num % a[i]
print(ans)

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce

def gcd_list(a):
	return reduce(math.gcd, a)

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

def lcm_list(a):
    return reduce(lcm_base, a, 1)

N = int(input())
a = list(map(int, input().split()))
ans = 0
num = lcm_list(a)- 1
for i in range(len(a)):
	ans += num % a[i]
print(ans)
Problem p03324 (python)

Fixed submission:
D, N = map(int, input().split())
ans = 0
if N == 100:
	ans = pow(100, D + 1) +  pow(100, D)
else:
	for i in range(1, N + 1):
			ans = pow(100, D) * i
print(ans)

Buggy submission (verdict: Runtime Error):
D, N = map(int, input().split())
ans = 0
if N == 100 and D = 0:
	ans = pow(100, D + 1) + 1
elif N == 100 and D >= 1:
	ans = pow(100, D + 1) 
else:
	for i in range(1, N + 1):
			ans = pow(100, D) * i
print(ans)
Problem p03325 (python)

Fixed submission:
N = int(input())
a_list = list(map(int, input().split()))
count = 0
while True:
	odd = 0
	for i in range(N):
		if a_list[i] % 2 == 0:
			a_list[i] = int(a_list[i] / 2)
			count += 1
		else:
			odd += 1
	if odd == len(a_list):
		break
print(count)

Buggy submission (verdict: Runtime Error):
N = int(input())
a = list(map(int, input().split()))
count = 0
for i in range(N):
	for n in a:
 		if n % 2 == 0:
    		count += 1
            n /= 2
print(count)

Buggy submission (verdict: Runtime Error):
N = int(input())
a = [int(input()) for i in range(N) ]
count = 0
for i in range(N):
	for j in range(len(a)):
 		if a[j] % 2 == 0:
    		count += 1
            a[j] /= 2
print(count)

Buggy submission (verdict: Runtime Error):
N = int(input())
a = [int(input()) for i in range(N) ]
count = 0
for i in range(N):
	for n in a:
 		if n % 2 == 0:
    		count += 1
            n /= 2
print(count)
Problem p03359 (python)

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

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split())
if a > b:
  print(a - 1)
else:
print(a)

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split())
if a > b:
  print(a - 1)
else;
print(a)
Problem p03363 (python)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
S = [0]
ans = 0
for i in range(len(A)):
	S.append(S[i] + A[i])
S.sort()
count = 1
for i in range(1, len(S)):
	if S[i-1] == S[i]:
		count += 1
	else:
		ans += (count * (count - 1)) / 2
		count = 1
ans += (count * (count - 1)) / 2
print(int(ans))

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input()))
S = [0]
ans = 0
for i in range(len(A)):
  S.append(S[i] + A[i])
S.sort()
count = 1
for i in range(1, len(S)):
  if S[i-1] == S[i]:
    count += 1
  else:
    ans += count * (count-1) / 2
    count = 1
ans += count * (count-1) / 2
print(ans)
Problem p03386 (python)

Fixed submission:
A, B, K = map(int, input().split())
if 2 * K > B - A + 1:
	for i in range(A, B + 1):
		print(i)
else:
	for i in range(A, A + K):
		print(i)
	for j in range(B - K + 1, B + 1):
		print(j)

Buggy submission (verdict: Runtime Error):
A, B, K = map(int, input().split())
if 2 * K > B - A + 1:
	for i in l:
		print(i)
else:
	for i in range(A, A + K):
		print(i)
	for j in range(B - K + 1, B + 1):
		print(j)

Buggy submission (verdict: Runtime Error):
A, B, K = map(int, input().split())
l = [int(x) for x in range(A, B + 1)]
ans = []
for i in range(K):
	ans.append(l[i])
l.reverse()
for j in range(K):
	ans.append(l[j])
ans.sort()
for k in ans:
	print(k)
Problem p03449 (python)

Fixed submission:
N = int(input())
A = [list(map(int, input().split())) for _ in range(2)]
ans = 0
for i in range(N):
	temp = 0
	for j in range(i+1):
		temp += A[0][j]
	for j in range(i, N): 
		temp += A[1][j]
	ans = max(ans, temp)
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [list(map(int, input().split())) for _ in range(2)]
ans = 0
for i in range(N):
  temp = 0
  for j in range(N - i):
    temp += A[i][j]
  temp += A[1][j]
  if ans < temp:
    ans = temp
print(ans)
Problem p03675 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
b_1 = []
b_2 = []
b = []
for i in reversed(range(len(a))):
	if i % 2 != 0:
		b_1.append(a[i])
	else:
		b_2.append(a[i])
if len(a) % 2 == 0:
	b_2.reverse()
	b.extend(b_1)
	b.extend(b_2)
else:
	b_1.reverse()
	b.extend(b_2)
	b.extend(b_1)
for b_num in b:
	print(b_num, end = ' ')

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
b_1 = []
b_2 = []
b = []
for i in reversed(range(len(a))):
	if i % 2 != 0:
		b_1.append(a[i])
	else:
		b_2.append(a[i])
if len(a) % 2 == 0:
	b_2.reverse()
	b.extend(b_1)
	b.extend(b_2)
else:
	b_1.reverse()
	b.extend(b_2)
	b.extend(b_1)
for b_num in b:
	print("".join(b))
Problem p03773 (python)

Fixed submission:
A, B = map(int, input().split())
if A + B < 24:
  print(A + B)
else:
  print(A + B - 24)

Buggy submission (verdict: Runtime Error):
import math
N = int(input())
ans = len(str(N))
for A in range(1, int(math.sqrt(N)) + 1):
	if N % A == 0:
		B = N // A
		ans = min(ans, max(len(str(A)), len(str(B))))
print(ans)
Problem p03074 (python)

Fixed submission:
N,K = [ int(it) for it in input().split() ]
S = [ int(it) for it in input() ]

li = []

v = 1
c = 0
for it in S:
  if (v != it ):
    li.append(c)
    c=1
  else:
    c+=1
  v = it
li.append(c)
s = 0
lis = [0]*(len(li)+1)
for i in range(len(li)):
  lis[i+1]=lis[i]+li[i]
s = 0
for i in range(N):
  if (i*2>=N):
    continue
  a = min(i*2,len(li))
  b = min(i*2+2*K+1,len(li))

  ds2 = lis[b]-lis[a]
  s = max(s,ds2)
print (s)

Buggy submission (verdict: Runtime Error):
N,K = [ int(it) for it in input().split() ]
S = [ int(it) for it in input() ]

li = []

v = 1
c = 0
for it in S:
  if (v != it ):
    li.append(c)
    c=1
  else:
    c+=1
  v = it
li.append(c)
s = 0
lis = [0]*(len(li)+1)
for i in range(len(li)):
  lis[i+1]=lis[i]+li[i]
s = 0
for i in range(N):
  if (i*2>=N):
    continue
  a = min(i*2,len(li))
  b = min(i*2+2*K+1,len(li))

  ds2 = lis[b]-lis[a]
  s = max(s,ds)
print (s)
Problem p03128 (python)

Fixed submission:
N,M = [ int(it) for it in input().split() ]
li = [ int(it) for it in input().split() ]

comall = [-1,2,5,5,4,5,6,3,7,6]
com = [ (i,comall[i]) for i in li ]
com.sort( key=lambda x:-x[0])

dp = [-1]*(N+1)
dp[0] = 0

for i in range(N+1):
  for j,c in com:
    if (c==-1):
      continue
    if ( i-c < 0 ):
      continue
    if ( dp[i-c] == -1 ):
      continue
    dp[i] = max( dp[i] , dp[i-c] + 1 )

match = N
keta = dp[N]
st = ""


for i in range( 10000 ):
  for j,c in com:
    if (match-c<0):
      continue
    if (keta-1==dp[match-c]):
      keta-=1
      match-=c
      st+=str(j)
      break
  if (match==0):
    break
print ( st )

Buggy submission (verdict: Runtime Error):
N,M = [ int(it) for it in input().split() ]
li = [ int(it) for it in input().split() ]

comall = [-1,2,5,5,4,5,6,3,7,6]
com = [ (i,comall[i]) for i in li ]
com.sort( key=lambda x:-x[0])

dp = [-1]*(N+1)
dp[0] = 0

for i in range(N+1):
  for j,c in com:
    if (c==-1):
      continue
    if ( i-c < 0 ):
      continue
    if ( dp[i-c] == -1 ):
      continue
    dp[i] = max( dp[i] , dp[i-c] + 1 )

match = N
keta = dp[N]
st = ""


for i in range( 10000 ):
  for j,c in com:
    if (keta-1==dp[match-c]):
      keta-=1
      match-=c
      st+=str(j)
      break
  if (match==0):
    break
print ( st )
Problem p03246 (python)

Fixed submission:
N = int(input())
li=[int(it) for it in input().split()]
lia=li[::2]
lib=li[1::2]

import collections
ca = list(collections.Counter(lia).items())
cb = list(collections.Counter(lib).items())
na = len(lia)
nb = len(lib)
ca.sort(key=lambda x:-x[1])
cb.sort(key=lambda x:-x[1])
s = 0
if ( ca[0][0] != cb[0][0] ):
  s += na - ca[0][1]
  s += nb - cb[0][1]
else:
  if ( ca[0][1] > cb[0][1]   ):
    s += na - ca[0][1]
    if ( len(cb)>1 ):
      s += nb - cb[1][1]
    else:
      s += nb
  elif (ca[0][1] < cb[0][1]) :
    s += nb - cb[0][1]
    if ( len(ca)>1 ):
      s += na - ca[1][1]
    else:
      s += na
  else:
    p1 = cb[0][1]
    p2 = ca[0][1]
    if (len(ca)>1):
      p1+=ca[1][1]
    if (len(cb)>1):
      p2+=cb[1][1]
    s += na + nb - max(p1,p2)
    
print (s)

Buggy submission (verdict: Runtime Error):
N = int(input())
li=[int(it) for it in input().split()]
lia=li[::2]
lib=li[1::2]

import collections
ca = list(collections.Counter(lia).items())
cb = list(collections.Counter(lib).items())
na = len(lia)
nb = len(lib)
ca.sort(key=lambda x:-x[1])
cb.sort(key=lambda x:-x[1])
s = 0
if ( ca[0][0] != cb[0][0] ):
  s += na - ca[0][1]
  s += nb - cb[0][1]
else:
  if ( ca[0][1] > cb[0][1]   ):
    s += na - ca[0][1]
    if ( len(cb)>1 ):
      s += nb - cb[1][1]
    else:
      s += nb
  elif (ca[0][1] < cb[0][1]) :
    s += nb - cb[0][1]
    if ( len(ca)>1 ):
      s += na - ca[1][1]
    else:
      s += na
  else:
    s += na + nb - max(cb[0][1]+ca[1][1],ca[0][1]+cb[1][1])
    
print (s)

Buggy submission (verdict: Runtime Error):
N = int(input())
li=[int(it) for it in input().split()]
lia=li[::2]
lib=li[1::2]

import collections
ca = list(collections.Counter(lia).items())
cb = list(collections.Counter(lib).items())
na = len(lia)
nb = len(lib)
ca.sort(key=lambda x:-x[1])
cb.sort(key=lambda x:-x[1])
s = 0
if ( ca[0][0] != cb[0][0] ):
  s += na - ca[0][1]
  s += nb - cb[0][1]
else:
  if ( ca[0][1] > cb[0][1]   ):
    s += na - ca[0][1]
    if ( len(cb)>1 ):
      s += nb - cb[1][1]
    else:
      s += nb
  elif ( ca[0][1] < cb[0][1]   ):
    s += nb - cb[0][1]
    if ( len(ca)>1 ):
      s += na - ca[1][1]
    else:
      s += na
  else:
    s += na - ca[0][1] + nb - min(ca[1][1],cb[1][1])
print (s)
Problem p03290 (python)

Fixed submission:
D,G=[ int(it) for it in input().split() ]
li = [ [ int(it) for it in input().split() ] for i in range(D) ]

import itertools as ite
cmin = 100000000000000000
for cli in ite.product( *([[0,1]]*D) ):
  
  s = 0
  c = 0
  for i in range(D):
    if cli[i]==1:
      s +=  li[i][1] + (i+1)*100*li[i][0]
      c +=  li[i][0]
  
  ds = G-s
  
  for i in range(D-1,-1,-1):
    if (ds<=0):
      break
    if cli[i]==0:
      toku = (ds-1)//((i+1)*100)+1
      toku = min(toku,li[i][0])
      c += toku
      ds -= toku*(i+1)*100
    if (ds<=0):
      break
  if (ds<=0):
    cmin = min(cmin,c)
  else:
    pass
print (cmin)

Buggy submission (verdict: Runtime Error):
D,G=[ int(it) for it in input().split() ]
li = [ [ int(it) for it in input().split() ] for i in range(D) ]

import itertools as ite
cmin = 100000000000000000
for cli in ite.product( *([[0,1]]*D) ):
  
  s = 0
  c = 0
  for i in range(D):
    if cli[i]==1:
      s +=  li[i][1] + (i+1)*100*li[i][0]
      c +=  li[i][0]
  
  ds = G-s
  
  for i in range(D-1,-1,-1):
    if (ds<=0):
      break
    if cli[i]==0:
      toku = (ds-1)//((i+1)*100)+1
      toku = min(toku,li[i][0])
      c += toku
      ds -= toku*(i+1)*100
    if (ds<=0):
      break
  if (ds<=0):
    cmin = min(cmin,c)
  else:
print (cmin)
Problem p03354 (python)

Fixed submission:
N,M = [int(it) for it in input().split()]
pli=[int(it)-1 for it in input().split()]
sli=[ [int(it)-1 for it in input().split()] for i in range(M)]
ue = [-1]*N
dw = [[] for i in range(N)]

for a,b in sli:
  if ( b == ue[a] or a == ue[b] ):
    continue
  else:
    _a = ue[a] if ue[a]!=-1 else a 
    _b = ue[b] if ue[b]!=-1 else b
    if (_a == _b and _a != -1):
      continue
    if (len(dw[_a]) < len(dw[_b])):
      _a,_b=_b,_a
    if len(dw[_b])>0:
      dw[_a].extend(dw[_b])
      for _p in dw[_b]:
        ue[_p]=_a
      dw[_b]=[]
    dw[_a].append(_b)
    ue[_b]=_a

s = 0
for i in range(N):
  if ue[i]==-1:
    ue[i]=i 
for i in range(N):
  if (ue[i]==ue[pli[i]]):
    s+=1
print (s)

Buggy submission (verdict: Runtime Error):
N,M = [int(it) for it in input().split()]
pli=[int(it)-1 for it in input().split()]
sli=[ (lambda a,b:[min(a,b),max(a,b)])(*[int(it)-1 for it in input().split()]) for i in range(M)]
ue = [-1]*N
dw = [[] for i in range(N)]

#print (N,M,pli,sli)
#print (ue)
#print (dw)
for a,b in sli:
  if ( b == ue[a] or a == ue[b] ):
    continue
  if (1==1):
    _a = ue[a] if ue[a]!=-1 else a 
    _b = ue[b] if ue[b]!=-1 else b
    assert ue[_a]==-1
    assert ue[_b]==-1
    if len(dw[_b])>0:
      dw[_a].extend(dw[_b])
      for _p in dw[_b]:
        ue[_p]=_a
      dw[_b]=[]
    dw[_a].append(_b)
    ue[_b]=_a

s = 0
for i in range(N):
  if ue[i]==-1:
    ue[i]=i 
for i in range(N):
  if (ue[i]==ue[pli[i]]):
    s+=1
print (s)

Buggy submission (verdict: Runtime Error):
N,M = [int(it) for it in input().split()]
pli=[int(it)-1 for it in input().split()]
sli=[ (lambda a,b:[min(a,b),max(a,b)])(*[int(it)-1 for it in input().split()]) for i in range(M)]
ue = [-1]*N
dw = [[] for i in range(N)]

#print (N,M,pli,sli)
#print (ue)
#print (dw)
for a,b in sli:
  if ( b == ue[a] or a == ue[b] ):
    continue
  if (1==1):
    _a = ue[a] if ue[a]!=-1 else a 
    _b = ue[b] if ue[b]!=-1 else b
    assert ue[_a]==-1
    assert ue[_b]==-1
    if len(dw[_b])>0:
      dw[_a].extend(dw[_b])
      for _p in dw[_b]:
        ue[_p]=_a
      dw[_b]=[]
    dw[_a].append(_b)
    ue[_b]=_a

s = 0
for i in range(N):
  if ue[i]==-1:
    ue[i]=i 
for i in range(N):
  if (ue[i]==ue[pli[i]]):
    s+=1
print (s)
Problem p03363 (python)

Fixed submission:
n = int(input())
import numpy as np
li = np.array([ int(it) for it in input().split()])
cs = np.cumsum(li)
import collections
cd = collections.Counter(cs)
sm = 0
for k,v in cd.items():
  p = v - 1 + (1 if k==0 else 0)
  sm += (p*(p+1))//2
print (sm)

Buggy submission (verdict: Runtime Error):
n = int(input())
import numpy as np
li = np.array([ int(it) for it in input().split()])
cs = np.cumsum(li)
import collections
cd = collections.Counter(cs)
sm = 0
for k,v in cd.items():
  p = v - 1 + (1 if k==0 else 0)
  sm += (p*(p+1))//2
print (sm)
Problem p03438 (python)

Fixed submission:
N = int(input())
lia=[int(it) for it in input().split()]
lib=[int(it) for it in input().split()]
lip=[lia[i]-lib[i] for i in range(N)]
sb = 0
for i in range(N):
  if (lip[i]>0):
    sb+=lip[i]
sa2 = 0
for i in range(N):
  if (lip[i]<0):
    sa2+=(-lip[i])//2
x = sum(lib)-sum(lia)
if (x<0):
  print ("No")
else:
  if (sa2>=sb):
    print ("Yes")
  else:
    print ("No")

Buggy submission (verdict: Runtime Error):
N = int(input())
lia=[int(it) for it in input().split()]
lib=[int(it) for it in input().split()]
lip=[lia[i]-lib[i] for i in range(N)]
sb = 0
for i in range(N):
  if (lip[i]>0):
    sb+=lip[i]
sa2 = 0
for i in range(N):
  if (lip[i]<0):
    sa2=(-lip[i])//2
sas-=sb*2
x = sum(lib)-sum(lia)
if (x<0):
  print ("No")
else:
  if (sa2>=sb):
    print ("Yes")
  else:
    print ("No")