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

Fixed submission:
from collections import deque
import copy
import sys
sys.setrecursionlimit(50000)
N = int(input())
d_1, d_2 = deque([]), deque([])
l = []
for i in range(N):
  l.append(int(input()))
  
l.sort()
l_1, l_2 = copy.copy(l), copy.copy(l)
d_1.append(max(l))
d_2.append(min(l))
l_1.pop()
l_2.pop(0)

def main1(d, l):
  d.appendleft(l[0])
  l.pop(0)
  if l == []:
    return d
  d.append(l[0])
  l.pop(0)
  if l == []:
    return d
  d.appendleft(l[-1])
  l.pop()
  if l == []:
    return d
  d.append(l[-1])
  l.pop()
  if l == []:
    return d
  else:
    return main1(d, l)
  
def main2(d, l):
  d.appendleft(l[-1])
  l.pop()
  if l == []:
    return d
  d.append(l[-1])
  l.pop()
  if l == []:
    return d
  d.appendleft(l[0])
  l.pop(0)
  if l == []:
    return d
  d.append(l[0])
  l.pop(0)
  if l == []:
    return d
  else:
    return main2(d, l)
  
x, y = 0, 0
a = main1(d_1, l_1)
b = main2(d_2, l_2)
for i in range(N-1):
  x += abs(a[i+1]-a[i])
  y += abs(b[i+1]-b[i])
print(max(x, y))

Buggy submission (verdict: Runtime Error):
from collections import deque
import copy
sys.setrecursionlimit(50000)
N = int(input())
d_1, d_2 = deque([]), deque([])
l = []
for i in range(N):
  l.append(int(input()))
  
l.sort()
l_1, l_2 = copy.copy(l), copy.copy(l)
d_1.append(max(l))
d_2.append(min(l))
l_1.pop()
l_2.pop(0)

def main1(d, l):
  d.appendleft(l[0])
  l.pop(0)
  if l == []:
    return d
  d.append(l[0])
  l.pop(0)
  if l == []:
    return d
  d.appendleft(l[-1])
  l.pop()
  if l == []:
    return d
  d.append(l[-1])
  l.pop()
  if l == []:
    return d
  else:
    return main1(d, l)
  
def main2(d, l):
  d.appendleft(l[-1])
  l.pop()
  if l == []:
    return d
  d.append(l[-1])
  l.pop()
  if l == []:
    return d
  d.appendleft(l[0])
  l.pop(0)
  if l == []:
    return d
  d.append(l[0])
  l.pop(0)
  if l == []:
    return d
  else:
    return main2(d, l)
  
x, y = 0, 0
a = main1(d_1, l_1)
b = main2(d_2, l_2)
for i in range(N-1):
  x += abs(a[i+1]-a[i])
  y += abs(b[i+1]-b[i])
print(max(x, y))

Buggy submission (verdict: Runtime Error):
from collections import deque
import copy
N = int(input())
d_1, d_2 = deque([]), deque([])
l = []
for i in range(N):
  l.append(int(input()))
  
l.sort()
l_1, l_2 = copy.copy(l), copy.copy(l)
d_1.append(max(l))
d_2.append(min(l))
l_1.pop()
l_2.pop(0)

def main1(d, l):
  d.appendleft(l[0])
  l.pop(0)
  if l == []:
    return d
  d.append(l[0])
  l.pop(0)
  if l == []:
    return d
  d.appendleft(l[-1])
  l.pop()
  if l == []:
    return d
  d.append(l[-1])
  l.pop()
  if l == []:
    return d
  else:
    return main1(d, l)
  
def main2(d, l):
  d.appendleft(l[-1])
  l.pop()
  if l == []:
    return d
  d.append(l[-1])
  l.pop()
  if l == []:
    return d
  d.appendleft(l[0])
  l.pop(0)
  if l == []:
    return d
  d.append(l[0])
  l.pop(0)
  if l == []:
    return d
  else:
    return main2(d, l)
  
x, y = 0, 0
a = main1(d_1, l_1)
b = main2(d_2, l_2)
for i in range(N-1):
  x += abs(a[i+1]-a[i])
  y += abs(b[i+1]-b[i])
print(max(x, y))
Problem p03238 (python)

Fixed submission:
N = int(input())
 
if N == 1:
  print('Hello World')
else:
  A = int(input())
  B = int(input())
  print(A + B)

Buggy submission (verdict: Runtime Error):
N = input()
if input():
  A = int(input())
  B = int(input())
 
if N == 1:
  print('Hello World')
else:
  print(A + B)

Buggy submission (verdict: Runtime Error):
N = input()
 
if N == 1:
  print('Hello World')
else:
  A = int(input())
  B = int(input())
  print(A + B)

Buggy submission (verdict: Runtime Error):
N = input()
A = int(input())
B = int(input())

if N == 1:
  print('Hello World')
else:
  print(A + B)
Problem p03239 (python)

Fixed submission:
N, T = map(int, input().split())
cost = 10000

for i in range(N):
  c, t = map(int, input().split())
  if t <= T:
    cost = min(cost, c)
    
if cost == 10000:
  print('TLE')
else:
  print(cost)

Buggy submission (verdict: Runtime Error):
N, T = map(int, input().split())
c = []
t = []
for i in range(N):
  c[i], t[i] = map(int, input().split())
 
costs = []
for i in range(N):
  if t[i] <= T:
    costs.append(c[i])
    
print(min(costs))

Buggy submission (verdict: Runtime Error):
N, T = map(int, input().split())
c = []
t = []
c[i], t[i] = map(int, input().split())
 
costs = []
for i in range(N):
  if t[i] <= T:
    costs.append(c[i])
    
print(min(costs))

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

costs = []
for i in range(N):
  if t[i] <= T:
    costs.append(c[i])
    
print(min(costs))
Problem p03241 (python)

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

l = []
for i in range(1, int(math.sqrt(M))+1):
  if M % i == 0:
    l.append(i)
    if i != M//i:
      l.append(M//i)
      
l.sort(reverse=True)
for n in l:
  if n*N <= M:
    ans = n
    break
print(ans)

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

l = []
for i in range(1, int(math.sqrt(M))):
  if M % i == 0:
    l.append(i)
    if i != M//i:
      l.append(M//i)
      
l.sort(reverse=True)
for n in l:
  if n*N <= M:
    ans = n
    break
print(ans)
Problem p03262 (python)

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

li = []
x.sort()
for i in range(N):
  li.append(x[i+1]-x[i])
  
li.sort()
while len(li) > 1:
  l = []
  div = li[0]
  for n in li:
    mod = n % div
    if mod != 0:
      l.append(mod)
  l.append(div)
  l.sort()
  li = l
print(*li)

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

li = []
x.sort()
for i in range(N):
  li.append(x[i+1]-x[i])
  
li.sort()
while len(li) > 1:
  l = []
  div = li[0]
  for n in li:
    mod = n % div
    if mod != 0:
      mod.append(l)
  l.append(div)
  l.sort()
  li = l
print(*li)
Problem p03274 (python)

Fixed submission:
import math
N, K = map(int, input().split())
x = list(map(int, input().split()))
for i in range(N):
  if x[i] == 0:
    p, m = i, i+1
    break
  elif x[i] > 0:
    p, m = i, i
    break
    
if (x[0]<0) and (x[-1]>0):
  pls = x[p:]
  mns = x[:m]
  ans = math.inf

  for i in range(len(pls)):
    if i < K-1:
      if pls[0] == 0:
        n = K - i
      else:
        n = K - i - 1
      if len(mns) >= n:
        tmp = 2*abs(mns[-n]) + pls[i]
        ans = min(ans, tmp)
    if i == K-1:
      ans = min(ans, pls[i])
      break
    
  for i in range(len(mns)):
    m = len(mns)-i
    if m < K:
      if pls[0] == 0:
        n = K - m
      else:
        n = K - m - 1
      if len(pls) > n:
        tmp = 2*pls[n] + abs(mns[-m])
        ans = min(ans, tmp)
    if m == K:
      ans = min(ans, abs(mns[i]))
    
elif x[0] >= 0:
  ans = x[K-1]
  
else:
  ans = abs(x[-K])
  
print(ans)

Buggy submission (verdict: Runtime Error):
import math
N, K = map(int, input().split())
x = list(map(int, input().split()))
for i in range(N):
  if x[i] == 0:
    p, m = i, i+1
    break
  elif x[i] > 0:
    p, m = i, i
    break
    
pls = x[p:]
mns = x[:m]
ans = math.inf

for i in range(len(pls)):
  if i < K-1:
    if pls[0] == 0:
      n = K - i
    else:
      n = K - i - 1
    if len(mns) >= n:
      tmp = 2*abs(mns[-n]) + pls[i]
      ans = min(ans, tmp)
  if i == K-1:
    ans = min(ans, pls[i])
    break
    
for i in range(len(mns)):
  m = len(mns)-i
  if m < K:
    if pls[0] == 0:
      n = K - m
    else:
      n = K - m - 1
    if len(pls) > n:
      tmp = 2*pls[n] + abs(mns[-m])
      ans = min(ans, tmp)
  if m == K:
    ans = min(ans, abs(mns[i]))
    
print(ans)

Buggy submission (verdict: Runtime Error):
import math
N, K = map(int, input().split())
x = list(map(int, input().split()))
for i in range(N):
  if x[i] == 0:
    p, m = i, i+1
    break
  elif x[i] > 0:
    p, m = i, i
    break
    
pls = x[p:]
mns = x[:m]
ans = math.inf

for i in range(len(pls)):
  if i < K-1:
    if pls[0] == 0:
      n = K - i
    else:
      n = K - i - 1
    if len(mns) >= n:
      tmp = 2*abs(mns[-n]) + pls[i]
      ans = min(ans, tmp)
  if i == K-1:
    ans = min(ans, pls[i])
    break
    
for i in range(len(mns)):
  m = len(mns)-i
  if m < K:
    if pls[0] == 0:
      n = K - m
    else:
      n = K - m - 1
    tmp = 2*pls[n] + abs(mns[-m])
    ans = min(ans, tmp)
  if m == K:
    ans = min(ans, abs(mns[i]))
    
print(ans)
Problem p03436 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10000)
H, W = map(int, input().split())
S = []
white = 0
for i in range(H):
  s = str(input())
  S.append(s)
  white += s.count('.')
  
def main(h, w):
  global H
  global W
  global S
  global l
  tmp = []
  if h < H-1:
    if (S[h+1][w]=='.') and ([h+1, w] not in l):
      tmp.append([h+1, w])
  if w < W-1:
    if (S[h][w+1]=='.') and ([h, w+1] not in l):
      tmp.append([h, w+1])
  if 0 < h:
    if (S[h-1][w]=='.') and ([h-1, w] not in l):
      tmp.append([h-1, w])
  if 0 < w:
    if (S[h][w-1]=='.') and ([h, w-1] not in l):
      tmp.append([h, w-1])
  return tmp
    
cnt = 0
l = [[0, 0]]
tmp = [[0, 0]]
for i in range(10000):
  t = []
  for n in tmp:
    u = main(n[0], n[1])
    l += u
    t += u
  if t == []:
    ans = white+1
  elif [H-1, W-1] in t:
    ans = i+2
    break
  else:
    tmp = t
print(white-ans)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10000)
H, W = map(int, input().split())
S = []
white = 0
for i in range(H):
  s = str(input())
  S.append(s)
  white += s.count('.')
  
def main(h, w):
  global H
  global W
  global S
  global l
  tmp = []
  if h < H-1:
    if (S[h+1][w]=='.') and ([h+1, w] not in l):
      tmp.append([h+1, w])
  if w < W-1:
    if (S[h][w+1]=='.') and ([h, w+1] not in l):
      tmp.append([h, w+1])
  if 0 < h:
    if (S[h-1][w]=='.') and ([h-1, w] not in l):
      tmp.append([h-1, w])
  if 0 < w:
    if (S[h][w-1]=='.') and ([h, w-1] not in l):
      tmp.append([h, w-1])
  return tmp
    
cnt = 0
l = [[0, 0]]
tmp = [[0, 0]]
for i in range(10000):
  t = []
  for n in tmp:
    u = main(n[0], n[1])
    l += u
    t += u
  if [H-1, W-1] in t:
    ans = i+2
    break
  else:
    tmp = t
print(white-ans)
Problem p03473 (python)

Fixed submission:
M = int(input())
ans = 48 - M
print(ans)

Buggy submission (verdict: Runtime Error):
M = int(input())
ans = 48 - M
printg(ans)
Problem p03524 (python)

Fixed submission:
from collections import Counter
S = [i for i in str(input())]
c = Counter(S)
m = c.most_common()

n = len(S) // 3
if len(S) == 1:
  print('YES')
elif len(S) == 2:
  if len(m) == 2:
    print('YES')
  else:
    print('NO')
elif len(m) < 3:
  print('NO')
else:
  if len(S) % 3 == 0:
    if (m[0][1]==n) and (m[1][1]==n) and (m[2][1]==n):
      print('YES')
    else:
      print('NO')
  elif len(S) % 3 == 1:
    if (m[0][1]==n+1) and (m[1][1]==n) and (m[2][1]==n):
      print('YES')
    else:
      print('NO')
  else:
    if (m[0][1]==n+1) and (m[1][1]==n+1) and (m[2][1]==n):
      print('YES')
    else:
      print('NO')

Buggy submission (verdict: Runtime Error):
from collections import Counter
S = [i for i in str(input())]
c = Counter(S)
m = c.most_common()

n = len(S) // 3
if len(S) % 3 == 0:
  if (m[0][1]==n) and (m[1][1]==n) and (m[2][1]==n):
    print('YES')
  else:
    print('NO')
elif len(S) % 3 == 1:
  if (m[0][1]==n+1) and (m[1][1]==n) and (m[2][1]==n):
    print('YES')
  else:
    print('NO')
else:
  if (m[0][1]==n+1) and (m[1][1]==n+1) and (m[2][1]==n):
    print('YES')
  else:
    print('NO')
Problem p03559 (python)

Fixed submission:
import bisect
from collections import deque
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()

d = deque([])
for i in range(N):
  n = bisect.bisect_right(C, B[N-1-i])
  if len(d) == 0:
    d.appendleft(N-n)
  else:
    d.appendleft(N-n+d[0])
  
ans = 0
for i in range(N):
  m = bisect.bisect_right(B, A[i])
  if m < N:
    ans += d[m]
print(ans)

Buggy submission (verdict: Runtime Error):
import bisect
from collections import deque
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()

d = deque([])
for i in range(N):
  n = bisect.bisect_right(C, B[N-1-i])
  if len(d) == 0:
    d.appendleft(N-n)
  else:
    d.appendleft(N-n+d[0])
  
ans = 0
for i in range(N):
  n = bisect.bisect_right(B, A[i])
  ans += d[n]
print(ans)
Problem p03565 (python)

Fixed submission:
S = str(input())
T = str(input())

s = len(S)
t = len(T)
if s < t:
  flag = False
else:
  for i in range(s-t+1):
    num = s-t-i
    tmp = S[num:num+t]
    flag = True
    for j in range(t):
      if (tmp[j]!='?') and (T[j]!=tmp[j]):
        flag = False
        break
    if flag:
      if 0 < num < s-t:
        ans = S[:num] + T + S[num+t:]
      elif num == 0:
        ans = T + S[num+t:]
      else:
        ans = S[:num] + T
      break
    
if flag:
  ans = ans.replace('?', 'a')
  print(ans)
else:
  print('UNRESTORABLE')

Buggy submission (verdict: Runtime Error):
S = str(input())
T = str(input())

s = len(S)
t = len(T)
for i in range(s-t+1):
  num = s-t-i
  tmp = S[num:num+t]
  flag = True
  for j in range(t):
    if (tmp[j]!='?') and (T[j]!=tmp[j]):
      flag = False
      break
  if flag:
    if 0 < num < s-t:
      ans = S[:num] + T + S[num+t:]
    elif num == 0:
      ans = T + S[num+t:]
    else:
      ans = S[:num] + T
    break
    
if flag:
  ans = ans.replace('?', 'a')
  print(ans)
else:
  print('UNRESTORABLE')

Buggy submission (verdict: Runtime Error):
S = str(input())
T = str(input())

s = len(S)
t = len(T)
for i in range(s-t+1):
  num = s-t-i
  tmp = S[num:num+t]
  flag = True
  for j in range(t):
    if (tmp[j]!='?') and (T[j]!=tmp[j]):
      flag = False
      break
  if flag:
    ans = S[:num] + T + S[num+t:]
    break
    
if flag:
  ans = ans.replace('?', 'a')
  print(ans)
else:
  print('UNRESTORABLE')
Problem p03583 (python)

Fixed submission:
N = int(input())

if N % 2 == 0:
  print(N//2, N, N)
else:
  for i in range(1, N):
    if N < 4*i:
      n = 4*i - N
      break
  if n == 1:
    j, k = 2*N*i, 2*N*i
  else:
    if i % 3 == 0:
      j, k = 2*N*i//3, 2*N*i//3
    else:
      for x in range(100):
        flag = False
        for y in range(1, n//2+1):
          if ((N*i)%y==0) and ((N*i)%(n-y)==0):
            j = (N*i) // y
            k = (N*i) // (n-y)
            flag = True
            break
        if flag:
          break
        else:
          i += 1
          n += 4
  print(i, j, k)

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

if N % 2 == 0:
  print(N//2, N, N)
else:
  for i in range(1, N):
    if N < 4*i:
      n = 4*i - N
      break
  if n == 1:
    j, k = 2*N*i, 2*N*i
  else:
    if i % 3 == 0:
      j, k = 2*N*i//3, 2*N*i//3
    else:
      for x in range(10):
        flag = False
        for y in range(1, n//2+1):
          if ((N*i)%y==0) and ((N*i)%(n-y)==0):
            j = (N*i) // y
            k = (N*i) // (n-y)
            flag = True
            break
        if flag:
          break
        else:
          i += 1
          n += 4
  print(i, j, k)
Problem p03612 (python)

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

i = 0
ans = 0
while i < N:
  if p[i] == i+1:
    if (i+1<N) and (p[i+1]==i+2):
      ans += 1
      i += 2
    else:
      ans += 1
      i += 1
  else:
    i += 1
print(ans)

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

i = 0
ans = 0
while i < N:
  if p[i] == i+1:
    if p[i+1] == i+2:
      ans += 1
      i += 2
    else:
      ans += 1
      i += 1
  else:
    i += 1
print(ans)
Problem p03635 (python)

Fixed submission:
n, m = map(int, input().split())
ans = (n-1)*(m-1)
print(ans)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input())
ans = (n-1)*(m-1)
print(ans)
Problem p03910 (python)

Fixed submission:
import sys
N = int(input())
l = []

def main(n):
  global l
  i = 1
  while True:
    tmp = i*(i+1)//2
    if tmp >= n:
      l.append(i)
      if n-i == 0:
        return l
      else:
        return main(n-i)
    i += 1
    
sys.setrecursionlimit(10000)
li = main(N)
for n in li:
  print(n)

Buggy submission (verdict: Runtime Error):
N = int(input())
l = []

def main(n):
  global l
  i = 1
  while True:
    tmp = i*(i+1)//2
    if tmp >= n:
      l.append(i)
      if n-i == 0:
        return l
      else:
        return main(n-i)
    i += 1
        
li = main(N)
for n in li:
  print(n)

Buggy submission (verdict: Runtime Error):
N = int(input())
l = []

def main(n):
  global l
  i = 1
  if n == 1:
    l.append(1)
    return l
  else:
    while True:
      tmp = i*(i+1)//2
      if tmp >= n:
        l.append(i)
        if n-i == 0:
          return l
        else:
          return main(n-i)
      i += 1
        
li = main(N)
li.sort()
for n in li:
  print(n)
Problem p03994 (python)

Fixed submission:
s = list(input())
K = int(input())
ans = []
for c in s:
    cnt = ord('z') - ord(c) + 1
    if c == 'a':
        ans.append('a')
    elif K >= cnt:
        K -= cnt
        ans.append('a')
    else:
        ans.append(c)
K %= 26
if 122 < ord(ans[-1]) + K:
    ans[-1] = chr(ord(ans[-1]) + K - 26)
else:
    ans[-1] = chr(ord(ans[-1]) + K)
print(*ans,sep='')

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

i = 0
for j in range(len(s)):
  if s[j] != 'a':
    if 26+ord('a')-ord(s[j]) <= K-i:
      i += 26+ord('a')-ord(s[j])
      s = s[:j] + 'a' + s[j+1:]

if i < K:
  for k in range(1, len(s)+1):
    if s[-k] != 'a':
      if 26+ord('a')-ord(s[-k]) <= K-i:
        s = s[:-k] + 'a' + s[-k+1:]
        i += 26+ord('a')-ord(s[-k])
  if i < K:
    s = s[:-1] + chr(ord(s[-1])+K-i)
print(s)
Problem p02536 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**5)
class UnionFind:
    def __init__(self, n):
        self.d = []
        for _ in range(n):
            self.d.append(-1)
    
    def find(self, x):
        if self.d[x] < 0:
            return x
        else:
            self.d[x] = self.find(self.d[x])
            return self.d[x]
    
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False
        if self.d[x] > self.d[y]:
            x, y = y, x
        self.d[x] += self.d[y]
        self.d[y] = x

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        return -self.d[self.find(x)]


N, M = map(int, input().split())
uf = UnionFind(N)
for i in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    uf.union(a,b)
group = set()
for i in range(N):
    group.add(uf.find(i))

print(len(group)-1)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**5)
class UnionFind:
    def __init__(self, n):
        self.d = []
        for _ in range(n):
            self.d.append(-1)
    
    def find(self, x):
        if self.d[x] < 0:
            return x
        else:
            self.d[x] = self.find(self.d[x])
            return self.d[x]
    
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False
        if self.d[x] > self.d[y]:
            x, y = y, x
        self.d[x] += self.d[y]
        self.d[y] = x

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        return -self.d[self.find(x)]


N, M = map(int, input().split())
uf = UnionFind(N)
for i in range(M):
    a, b = map(int, input().split())
    uf.union(a,b)
group = set()
for i in range(N):
    group.add(uf.find(i))

print(len(group)-1)

Buggy submission (verdict: Runtime Error):
class UnionFind:
    def __init__(self, n):
        self.d = []
        for _ in range(n):
            self.d.append(-1)
    
    def find(self, x):
        if self.d[x] < 0:
            return x
        else:
            self.d[x] = self.find(self.d[x])
            return self.d[x]
    
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False
        if self.d[x] > self.d[y]:
            x, y = y, x
        self.d[x] += self.d[y]
        self.d[y] = x

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        return -self.d[self.find(x)]


N, M = map(int, input().split())
uf = UnionFind(N)
for i in range(M):
    a, b = map(int, input().split())
    uf.union(a,b)
group = set()
for i in range(N):
    group.add(uf.find(i))

print(len(group)-1)
Problem p02586 (python)

Fixed submission:
r,c,k = list(map(int, input().split()))
import copy
dp=[[[0]*4 for _ in range(c)] for _ in range(2)]


F = [[0]*c for _ in range(r)]

for _ in range(k):
  x,y,v = list(map(int, input().split()))
  x-=1
  y-=1
  F[x][y] = v
  
for nn in range(r):
  for j in range(c):
    i = 1
    val = F[nn][j]
  
      
    mxv = max(dp[i-1][j][0], dp[i-1][j][1], dp[i-1][j][2], dp[i-1][j][3])

    dp[i][j][3] = max(dp[i][j-1][3], dp[i][j-1][2] + val)
    dp[i][j][2] = max(dp[i][j-1][2], dp[i][j-1][1] + val)
    dp[i][j][1] = max(dp[i][j-1][1], dp[i][j-1][0] + val, mxv + val)
    dp[i][j][0] = mxv

  dp[0] = dp[1] 
  dp[1] = [[0]*4 for _ in range(c)]

best = 0


for k in range(4):
  best = max(best, dp[0][c-1][k])
    
print(best)

Buggy submission (verdict: Runtime Error):
R, C, K = map(int, input().split())
a = [[0]*C for _ in range(R)]
dp = [[[0]*4 for _ in range(C)] for _ in range(R)]
for i in range(K):
    r, c, v = map(int, input().split())
    a[r-1][c-1] = v

for i in range(R):
    for j in range(C):
        for k in range(2, -1, -1):
            dp[i][j][k+1] = max(dp[i][j][k+1], dp[i][j][k]+a[i][j])
        for k in range(4):
            dp[i+1][j][0] = max(dp[i+1][j][0], dp[i][j][k])
            dp[i][j+1][k] = max(dp[i][j+1][k], dp[i][j][k])

ans = 0
for i in range(4):
    ans = max(ans, dp[R-1][C-1][i])

print(ans)
Problem p02642 (python)

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

l = [0] *(10**6+1)

for i in range(N):
    num = A[i]
    if l[num] != 0:
        l[num] = 2
        continue
    for j in range(num, 10**6+1, num):
        l[j] += 1
ans = 0
for i in range(N):
    num = A[i]
    if l[num] == 1:
        ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
import sys

N = int(input())
A = list(map(int, sys.stdin.readline()[:-1]))

A.sort()
if len(A) == 1:
    print(1)
    sys.exit(0)
elif A[0] == A[-1]:
    print(0)
    sys.exit(0)
elif A[0] == 1:
    print(1)
    sys.exit(0)


d =[]

for i in range(len(A)):
    flag = True
    for j in d:
        if A[i] % j == 0:
            flag = False
            break
    if flag:
        d.append(A[i])

print(len(d))
Problem p02660 (python)

Fixed submission:
import math
from collections import defaultdict
N = int(input())
d = defaultdict(int)
tmp = N
for i in range(2, int(math.sqrt(N))+1):
    while tmp % i == 0:
        d[i] += 1
        tmp /= i

if tmp > 1:
    d[tmp] += 1
ans = 0
for key, value in d.items():
    i = value
    j = 1
    while value >= j:
       ans += 1
       value -= j
       j += 1
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
N = int(input())
d = defaultdict(int)
tmp = N
for i in range(2, int(math.sqrt(N))+1):
    while tmp % i == 0:
        d[i] += 1
        tmp /= i

if tmp > 1:
    d[tmp] += 1
ans = 0
for key, value in d.items():
    i = value
    j = 1
    while value >= j:
       ans += 1
       value -= j
       j += 1
print(ans)