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

Fixed submission:

from collections import Counter
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n //= i
      table.append(i)
    i += 1
  if n > 1:
    table.append(n)
  return table

A,B = map(int,input().split())
p1 = Counter(prime_decomposition(A))
p2 = Counter(prime_decomposition(B))
ans = 1
for p,_ in p1.items():
  if p2[p] > 0:
    ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):
from itertools import combinations
A,B = map(int,input().split())

divisors = []
n,m = min(A,B), max(A,B)
for i in range(1,int(n**0.5)+1):
  if n%i==0 and m%i==0:
    divisors.append(i)
    p = n//i
    if m%p==0:
      divisors.append(p)

d = max(divisors)
isPrime = [True] * (d+1)
isPrime[0],isPrime[1] = False,False
for i in range(2, int(d ** 0.5) + 1):
  if isPrime[i]:
    for j in range(i * i, d + 1, i):
      isPrime[j] = False

ans = 1
for d in divisors:
  if isPrime[d]:
    ans += 1
print(ans)
Problem p02936 (python)

Fixed submission:
from collections import deque
N,Q = map(int,input().split())
adj = [ [] for _ in range(N) ]
for _ in range(N-1):
  u,v = map(int,input().split())
  u -= 1
  v -= 1
  adj[u].append(v)
  adj[v].append(u)

scores = [0] * N
for _ in range(Q):
  u,p = map(int,input().split())
  u -= 1
  scores[u] += p

res = [0] * N
visited = [False] * N
q = deque([(scores[0], 0)])
while q:
  s,n = q.popleft()
  res[n] = s
  visited[n] = True

  for nei in adj[n]:
    if not visited[nei]:
      q.append((s+scores[nei], nei))

print(" ".join(map(str, res)))

Buggy submission (verdict: Runtime Error):
N,Q = map(int,input().split())
adj = [ [] for _ in range(N) ]
for _ in range(N-1):
  a,b = map(int,input().split())
  a -= 1
  b -= 1
  adj[a].append(b)

from collections import defaultdict
counter = defaultdict(int)
for _ in range(Q):
  p,x = map(int,input().split())
  p -= 1
  counter[p] += x

weight = [-1] * N
def dfs(node, wei):
  weight[node] = wei

  for nei in adj[node]:
    if weight[nei] == -1:
      dfs(nei, wei+counter[nei])

dfs(0, counter[0])
print(" ".join(map(str,weight)))

Buggy submission (verdict: Runtime Error):
N,Q = map(int,input().split())
adj = [ [] for _ in range(N) ]
for _ in range(N-1):
  u,v = map(int,input().split())
  u -= 1
  v -= 1
  adj[u].append(v)
scores = [0] * N
for _ in range(Q):
  u,p = map(int,input().split())
  u -= 1
  scores[u] += p

res = [0] * N
def dfs(n, p, s):
  res[n] = s
  for nei in adj[n]:
    if nei != p:
      dfs(nei, n, s+scores[nei])

dfs(0,-1,scores[0])

print(" ".join(map(str, res)))
Problem p02985 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**9)
class Combination:
  def __init__(self, n_max, mod=10**9+7):
    self.mod = mod
    self.modinv = self.make_modinv_list(n_max)
    self.fac, self.facinv = self.make_factorial_list(n_max)

  def __call__(self, n, r):
    return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

  def make_factorial_list(self, n):
    # 階乗のリストと階乗のmod逆元のリストを返す O(n)
    # self.make_modinv_list()が先に実行されている必要がある
    fac = [1]
    facinv = [1]
    for i in range(1, n+1):
      fac.append(fac[i-1] * i % self.mod)
      facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
    return fac, facinv

  def make_modinv_list(self, n):
    # 0からnまでのmod逆元のリストを返す O(n)
    modinv = [0] * (n+1)
    modinv[1] = 1
    for i in range(2, n+1):
        modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
    return modinv

N,K = map(int,input().split())
adj = [ [ ]for _ in range(N) ]
comb = Combination(10**5)

def nPr(n,r):
  if n < r: return 0
  return comb(n, r) * comb.fac[r]

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

def dfs(v, p=-1):
  global ans
  c = 0
  for nei in adj[v]:
    if nei == p: continue
    c += 1
    dfs(nei, v)

  nk = K-1 if p==-1 else K-2
  ans *= nPr(nk, c)
  ans %= 10**9+7

ans = K
dfs(0)
print(ans)

Buggy submission (verdict: Runtime Error):
class Combination:
  def __init__(self, n_max, mod=10**9+7):
    self.mod = mod
    self.modinv = self.make_modinv_list(n_max)
    self.fac, self.facinv = self.make_factorial_list(n_max)

  def __call__(self, n, r):
    return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

  def make_factorial_list(self, n):
    # 階乗のリストと階乗のmod逆元のリストを返す O(n)
    # self.make_modinv_list()が先に実行されている必要がある
    fac = [1]
    facinv = [1]
    for i in range(1, n+1):
      fac.append(fac[i-1] * i % self.mod)
      facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
    return fac, facinv

  def make_modinv_list(self, n):
    # 0からnまでのmod逆元のリストを返す O(n)
    modinv = [0] * (n+1)
    modinv[1] = 1
    for i in range(2, n+1):
        modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
    return modinv

N,K = map(int,input().split())
adj = [ [ ]for _ in range(N) ]
comb = Combination(10**5)

def nPr(n,r):
  return comb(n, r) * comb.fac[r]

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

def dfs(v, p=-1):
  global ans
  c = 0
  for nei in adj[v]:
    if nei == p: continue
    c += 1
    dfs(nei, v)

  nk = K-1 if p==-1 else K-2
  ans *= nPr(nk, c)
  ans %= 10**9+7

ans = K
dfs(0)
print(ans)
Problem p02995 (python)

Fixed submission:
def gcd(x,y):
  while y:
    x,y = y,x%y
  return x

def calc(x,a,b,l):
  return x - (x//a) - (x//b) + (x//l)

A,B,C,D = map(int,input().split())
lcm = C*D // gcd(C,D)
print(calc(B,C,D,lcm) - calc(A-1,C,D,lcm))

Buggy submission (verdict: Runtime Error):
def gcd(x,y):
  while y:
    x,y = y,x%y
  return x

A,B,C,D = map(int,input().split())
lcm = C*D // gcd(C,D)
print(B-A-(B//C-A//C)-(B//D-A//D)+(B//lcm-A//lcm))+1

Buggy submission (verdict: Runtime Error):
import math
A,B,C,D = map(int,input().split())
lcm = C*D // math.gcd(C,D) 
print(B-A-int(B/C-A/C)-int(B/D-A/D)+int(B/lcm-A/lcm))
Problem p03044 (python)

Fixed submission:
import sys
sys.setrecursionlimit(100000)

N = int(input())
adj_list = { i: [] for i in range(N+1) }
for _ in range(N-1):
  u,v,w = map(int, input().split())
  adj_list[u].append([v,w])
  adj_list[v].append([u,w])

res = [None] * N
visited = [False] * (N+1)
def dfs(node, c, w):
  res[node-1] = c
  visited[node] = True

  for nei, nw, in adj_list[node]:
    if not visited[nei]:
      if (w+nw)%2 == 0:
        dfs(nei, 0, w+nw)
      else:
        dfs(nei, 1, w+nw)

dfs(1, 0, 0)
for r in res: print(r)

Buggy submission (verdict: Runtime Error):
N = int(input())
adj = [ [] for _ in range(N) ]
for _ in range(N-1):
  u,v,w = map(int,input().split())
  u -= 1
  v -= 1
  adj[u].append((v,w))
  adj[v].append((u,w))

def dfs(node, w, color):
  colors[node] = color

  for nei,nw in adj[node]:
    if colors[nei] != -1: continue
    nc = 1 if (w+nw)%2==0 else 0
    dfs(nei, nw, nc)

  return True

colors = [-1] * N
for i in range(N):
  if colors[i] == -1:
    dfs(i, 0, 1)

for c in colors: print(c)

Buggy submission (verdict: Runtime Error):
N = int(input())
adj = [ [] for _ in range(N) ]
for _ in range(N-1):
  u,v,w = map(int,input().split())
  u -= 1
  v -= 1
  adj[u].append((v,w))
  adj[v].append((u,w))

color = [None] * N
def dfs(n,l):
  if l%2==0:
    color[n] = 1
  else:
    color[n] = 0

  for nei, nl in adj[n]:
    if color[nei] is not None:
      if (l+nl) % 2 == 0 and color[nei] != 1:
        return False
      if (l+nl) % 2 == 1 and color[nei] != 0:
        return False
    else:
      dfs(nei, l+nl)

  return True

for i in range(N):
  if color[i] is None:
    if not dfs(i,0):
      print(-1)
      exit()

for c in color: print(c)

Buggy submission (verdict: Runtime Error):
N = int(input())
adj_list = { i: [] for i in range(N+1) }
for _ in range(N-1):
  u,v,w = map(int, input().split())
  adj_list[u].append([v,w])
  adj_list[v].append([u,w])

res = [None] * N
visited = [False] * (N+1)
def dfs(node, c, w):
  res[node-1] = c
  visited[node] = True

  for nei, nw, in adj_list[node]:
    if not visited[nei]:
      if (w+nw)%2 == 0:
        dfs(nei, 0, w+nw)
      else:
        dfs(nei, 1, w+nw)

dfs(1, 0, 0)
for r in res: print(r)
Problem p03160 (python)

Fixed submission:
n = int(input())
a = [ int(i) for i in input().split(" ")]

dp = [ -1 for i in range(len(a))]
dp[0] = 0

for i in range(1, len(a)):
  onestep = dp[i-1] + abs(a[i-1] - a[i])
  if i - 2 < 0:
    twostep = onestep
  else:
    twostep = dp[i-2] + abs(a[i-2] - a[i])
  
  dp[i] = min(onestep, twostep)

print(dp[-1])

Buggy submission (verdict: Runtime Error):
n = int(input())
a = [ int(i) for i in input().split(" ")]

INF = 10000000000
dp = [ INF for i in range(len(a))]
dp[0] = 0

def frog(i):
  if dp[i] < INF: return dp[i]
  
  if i == 0: return 0

  res = INF
  res = min(res, frog(i-1) + abs(a[i-1] - a[i]))
  if i > 1: 
    res = min(res, frog(i-2) + abs(a[i-2] - a[i]))

  dp[i] = res
  return res

print(frog(n-1))

Buggy submission (verdict: Runtime Error):
n = int(input())
a = [ int(i) for i in input().split(" ")]

INF = 10000000000
dp = [ INF for i in range(len(a))]

def frog(i):
  if dp[i] < INF: return dp[i]
  
  if i == 0: return 0

  res = INF
  res = min(res, frog(i-1) + abs(a[i-1] - a[i]))
  if i > 1: 
    res = min(res, frog(i-2) + abs(a[i-2] - a[i]))

  dp[i] = res
  return res

print(frog(n-1))

Buggy submission (verdict: Runtime Error):
n = int(input())
a = [ int(i) for i in input().split(" ")]

INF = 10000000000
dp = [ INF for i in range(len(a))]
dp[0] = 0

def frog(i):
  if dp[i] < INF: return dp[i]
  
  if i == 0: return 0

  res = INF
  res = min(res, frog(i-1) + abs(a[i-1] - a[i]))
  min(res, frog(i-1) + abs(a[i-2] - a[i]))

  dp[i] = res
  return res

print(frog(n-1))

Buggy submission (verdict: Runtime Error):
n = int(input())
a = [ int(i) for i in input().split(" ")]

INF = 10000000000
dp = [ INF for i in range(len(a))]
dp[0] = 0

def frog(i):
  if dp[i] < INF: return dp[i]
  
  if i == 0: return 0

  res = INF
  res = min(res, frog(i-1) + abs(a[i-1] - a[i]))
  print("calc i-1", i)
  min(res, frog(i-1) + abs(a[i-2] - a[i]))
  print("calc i-2", i)

  dp[i] = res
  return res

print(frog(n-1))
Problem p03162 (python)

Fixed submission:
n = int(input())

a = []
for i in range(n):
  arr = list(map(int, input().split()))
  a.append(arr)

INF = -10 ** 18

dp = [ [INF] * 3 for i in range(0, n+1)]
dp[0] = [0] * 3

for i in range(0, n):
  for j in range(0, 3):
    for k in range(3):
      if (j == k): continue
      dp[i+1][k] = max(dp[i+1][k], dp[i][j] + a[i][k])

print(max(dp[-1]))

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

a = []
for i in range(n):
  arr = list(map(int, input().split()))
  a.append(arr)

for i in range(0, n):
  for j in range(0, 3):
    for k in range(3):
      if (j == k): continue
      dp[i+1][k] = max(dp[i+1][k], dp[i][j] + a[i][k])

print(max(dp[-1]))
Problem p03408 (python)

Fixed submission:
from collections import Counter
N = int(input())
dic = Counter()
for _ in range(N):
  dic[input()] += 1
M = int(input())
for _ in range(M):
  dic[input()] -= 1
 
if dic.most_common():
  freq = dic.most_common()[0][1]
  print(max(freq, 0))
else:
  print(0)

Buggy submission (verdict: Runtime Error):
from collections import Counter
N = int(input())
dic = Counter()
for _ in range(N):
  dic[input()] += 1
M = int(input())
for _ in range(N):
  dic[input()] -= 1
 
if dic.most_common():
  freq = dic.most_common()[0][1]
  print(max(freq, 0))
else:
  print(0)

Buggy submission (verdict: Runtime Error):
from collections import Counter
N = int(input())
dic = Counter()
for _ in range(N):
  dic[input()] += 1
M = int(input())
for _ in range(N):
  dic[input()] -= 1

if c.most_common():
  freq = c.most_common()[0][1]
  print(freq, 0)
else:
  print(0)
Problem p03579 (python)

Fixed submission:
import sys
sys.setrecursionlimit(100000)

N,M = map(int,input().split())
adj_list = { i: [] for i in range(1, N+1) }

for i in range(M):
  a,b = map(int, input().split())
  adj_list[a].append(b)
  adj_list[b].append(a)

visited = [False]*(N+1)
colors = [None] * (N)
is_bipartite = True

## improved dfs ###
def dfs(node, c):
  colors[node-1] = c
  visited[node] = True
  for nei in adj_list[node]:
    if colors[nei-1] == c:
      return False
    if not visited[nei] and not dfs(nei, 1-c):
      return False

  return True

if dfs(1, 1):
  black = colors.count(1)
  print(black*(N-black) - M)
else:
  print(N*(N-1)//2 - M)

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
adj = [ [] for _ in range(N) ]
for _ in range(M):
  u,v = map(int,input().split())
  u -= 1
  v -= 1
  adj[u].append(v)
  adj[v].append(u)

color = [None] * N
def dfs(n, c):
  color[n] = c
  for nei in adj[n]:
    if color[nei] is not None:
      if color[nei] == c: 
        return False
    else:
      dfs(nei, 1-c)

  return True

if dfs(0,1):
  print(color.count(1)*color.count(0) - M)
else:
  print(N*(N-1)//2 - M)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(100000)

N,M = map(int,input().split())
adj_list = { i: [] for i in range(1, N+1) }

for i in range(M):
  a,b = map(int, input().split())
  adj_list[a].append(b)
  adj_list[b].append(a)

visited = [False]*(N+1)
colors = [None] * (N)

def dfs(node, c):
  colors[node-1] = c
  visited[node] = True
  for nei in adj_list[node]:
    if colors[nei-1] == c:
      is_bipartite = False
      return False
    if not visited[nei] and not dfs(nei, 1-c):
      return False

  return True

if dfs(i, 1):
  black = colors.count(1)
  print(black*(N-black) - M)
else:
  print(N*(N-1)//2 - M)

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
adj_list = { i: [] for i in range(1, N+1) }

for i in range(M):
  a,b = map(int, input().split())
  adj_list[a].append(b)
  adj_list[b].append(a)

visited = [False]*(N+1)
colors = [None] * (N)

def dfs(node, c):
  colors[node-1] = c
  visited[node] = True
  for nei in adj_list[node]:
    if colors[nei-1] == c:
      return False
    if not visited[nei]:
      dfs(nei, 1-c)

  return True

if dfs(1, 1):
  black = colors.count(1)
  print(black*(N-black) - M)
else:
  print(N*(N-1)//2 - M)
Problem p03930 (python)

Fixed submission:
from itertools import groupby

def calc(time):
  t = 0
  for i in range(h):
    gr = groupby(g[i])
    lst = []
    p = 0
    for key,it in gr:
      j = len(list(it))
      lst.append([p,key,j])
      p += j
    for j in range(len(lst)):
      if lst[j][1] == -1:
        continue
      if lst[j][2] >= K:
        t += (2**time)*lst[j][1]*lst[j][2]
        for k in range(lst[j][0],lst[j][0]+lst[j][2]):
          g[i][k] = 0

  return t

def flatten():
  for j in range(w):
    lst = []
    for i in range(h-1, -1, -1):
      if g[i][j] > 0:
        lst.append(g[i][j])

    lst += [-1] * (h - len(lst))

    for i in range(h-1, -1, -1):
      g[i][j] = lst[h-i-1]

h,w,K = map(int,input().split())
mat = [ [int(e) for e in list(input())] for _ in range(h) ]

res = 0
for i in range(h):
  for j in range(w):
    score = 0
    g = [ [ mat[n][m] for m in range(w) ] for n in range(h) ]
    g[i][j] = -1
    time = 0
    flatten()
    while True:
      s = calc(time)
      if s==0: break
      score += s
      flatten()
      time += 1
    res = max(res, score)

print(res)

Buggy submission (verdict: Runtime Error):
from itertools import groupby
def calc():
  s = 0
  for i in range(h):
    gr = groupby(g[i])
    j = 0
    for key,it in gr:
      l = len(list(it))
      j += l
      if key==-1: continue
      if l >= K:
        g[i][j:j+l] = [-1]*l
        # for k in range(l):
        #   g[i][j+k] = -1
        # # print("s", key, l, key*l)
        s += key*l
 
  return s

def flatten():
  for j in range(w):
    lst = []
    for i in range(h-1, -1, -1):
      if g[i][j] > 0:
        lst.append(g[i][j])

    lst += [-1] * (h - len(lst))

    for i in range(h-1, -1, -1):
      g[i][j] = lst[h-i-1]

h,w,K = map(int,input().split())
mat = [ [int(e) for e in list(input())] for _ in range(h) ]

res = 0
for i in range(h):
  for j in range(w):
    score = 0
    g = [ [ mat[n][m] for m in range(w) ] for n in range(h) ]
    g[i][j] = -1
    time = 0
    flatten()
    while True:
      s = calc(time)
      if s==0: break
      score += s
      flatten()
      time += 1
    res = max(res, score)

print(res)
Problem p03455 (python)

Fixed submission:
# -*- coding: utf-8 -*-

a, b = map(int, input().split())

if (a * b) % 2:
    print('Odd')
else:
    print('Even')

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

a = int(input())
b = int(input())

if a * b % 2:
    print('Odd')
else:
    print('Even')
Problem p03693 (python)

Fixed submission:
# -*- coding: utf-8 -*-

r, g, b = map(int, list(input().split()))

num = r * 100 + g * 10 + b

if num % 4:
    print('NO')
else:
    print('YES')

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

a, b = map(int, input().split())

if (a * b) % 2:
    print('Odd')
else:
    print('Even')
Problem p03854 (python)

Fixed submission:
# -*- coding: utf-8 -*-
import re

S = input()

pattern = '^(dream|dreamer|erase|eraser)+$'
result = re.match(pattern, S)
if result:
    print('YES')
else:
    print('NO')

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

S = input()
s = S[::]
T = ['dream', 'dreamer', 'erase', 'eraser']


def saiki(_s):
    if len(_s) == 0:
        return True

    for strng in T:
        if _s.endswith(strng):
            _s = _s[:len(_s)-len(strng):]
            return saiki(_s)

    return False


ret = False
if len(s) > 0:
    ret = saiki(s)

if ret:
    print('YES')
else:
    print('NO')

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

S = input()

s = S[::]  # DeepCopyと同じ
T = ['dream', 'dreamer', 'erase', 'eraser']


def saiki(_s):
    if len(_s) == 0:
        return True

    for strng in T:
        if _s.endswith(strng):
            _s = _s[:len(_s)-len(strng):]
            return saiki(_s)

    return False


ret = saiki(s)

if ret:
    print('YES')
else:
    print('NO')
Problem p02780 (python)

Fixed submission:
n,k = map(int,input().split())
prr = list(map(int,input().split()))

if n>1:
    m = sum(prr[:k])
    cur = m
    for i in range(n-k):
        cur += -prr[i] + prr[k+i]
        m = max(m,cur)
else:
    m = prr[0]

print((m+k)/2.0)

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

if n>1:
    m = sum(prr[:k])
    cur = m
    for i in range(n-k):
        cur += -prr[i] + prr[k+i]
        m = max(m,cur)

print((m+k)/2.0)
Problem p03086 (python)

Fixed submission:
import re
result = re.findall('[ATCG]+',input(),re.S)
if len(result)>0:
  print(max(list(map(len,result))))
else:
  print(0)

Buggy submission (verdict: Runtime Error):
import re
print(max(list(map(len,re.findall('[ATGC]+',input(),re.S)))))
Problem p03087 (python)

Fixed submission:
n,q=map(int,input().split())
s=input()
a=[0]
total=0
for i in range(1,len(s)):
    if s[i]=='C':
        if s[i-1]=='A':
            total+=1
    a.append(total)
a.append(total)

for _ in range(q):
    l,r=map(int,input().split())
    print(a[r-1]-a[l-1])

Buggy submission (verdict: Runtime Error):
import re
n,q=map(int,input().split())
s=input()
for _ in range(q):
	l,r=map(int,input().split())
    print(len(re.findall('AC',s[l-1:r],re.S)))
Problem p03693 (python)

Fixed submission:
a,b,c=map(int,input().split())
if (a*100+b*10+c)%4==0:
    print('YES')
else:
    print('NO')

Buggy submission (verdict: Runtime Error):
if (a*100+b*10+c)%4==0:
    print('YES')
else:
    print('NO')
Problem p03696 (python)

Fixed submission:
n=int(input())
s=input()
stack=[]
l=0
r=0
for c in s:
    if len(stack)>0 and stack[-1]=='(' and c==')':
        stack.pop()
    else:
        stack.append(c)
if len(stack)==0:
    print(s)
else:
    for c in stack:
        if c==')':
            l+=1
        else:
            r+=1
    print('('*l+s+')'*r)

Buggy submission (verdict: Runtime Error):
n=int(input())
s=input()
stack=[]
for c in s:
    if len(stack)>0 and stack[-1]=='(' and c==')':
        stack.pop()
    else:
        stack.append(c)
if len(stack)==0:
    print(s)
else:
    l=0
    r=0
    for c in stack:
        if c==')':
            l+=1
        else:
            r+=1
print('('*l+s+')'*r)
Problem p03773 (python)

Fixed submission:
a,b=map(int,input().split())
print((a+b)%24)

Buggy submission (verdict: Runtime Error):
import math
n = int(input())
nn = int(math.sqrt(n))
for i in range(nn,0,-1):
    if n%i==0:
        print(len(str(n//i)))
        break
Problem p03951 (python)

Fixed submission:
n=int(input())
s=input()
t=input()
for i in range(n):
    if s[i:] == t[:n-i]:
        print(n+i)
        break
else:
    print(n*2)

Buggy submission (verdict: Runtime Error):
n=int(input())
s=input()
t=input()
for i in range(n):
    if s[i:] == t[:n-i]:
        print(n+i)
        exit(1)
else:
    print(n*2)
Problem p04032 (python)

Fixed submission:
s=input()
for w in range(2,min([3,len(s)])+1):
    for st in range(0,len(s)-w+1):
        if s[st]==s[st+w-1]:
            print(st+1,st+w)
            exit()
print(-1,-1)

Buggy submission (verdict: Runtime Error):
from pandas import Series
ser1 = Series(list(input()))
for w in range(2,len(ser1)+1):
    for st in range(0,len(ser1)+1-w):
        if ser1[st:st+w].value_counts()[0] > w/2:
            print(st+1,st+w)
            exit()
print(-1,-1)
Problem p04043 (python)

Fixed submission:
arr = map(int, input().split())
if sorted(arr) == [5,5,7]:
  print('YES')
else:
  print('NO')

Buggy submission (verdict: Runtime Error):
if sorted(arr) == [5,5,7]:
  print('YES')
else:
  print('NO')
Problem p03043 (python)

Fixed submission:
import math
 
N, K = map(int, input().strip().split(' '))
 
ans = 0
count = int(math.log(K,2)-math.log(N,2))
if count < 0:
    count = 0
val = 2**count
 
for n in range(N, 0, -1):
    while n*val < K:
        val *= 2
        count *= 2
    #print('COUNT=', count)
    ans += 1.0/val
 
print(ans/N)

Buggy submission (verdict: Runtime Error):
import math

N, K = map(int, input().strip().split(' '))

ans = 0
count = int(math.log2(K)-math.log2(N))
if count < 0:
    count = 0
val = 2**count

for n in range(N, 0, -1):
    while n*val < K:
        val *= 2
        count *= 2
    #print('COUNT=', count)
    ans += 1.0/val

print(ans/N)
Problem p03044 (python)

Fixed submission:
N = int(input())

tree = [list() for _ in range(N)]
color = [-1 for _ in range(N)]
color[0] = 0

for _ in range(N-1):
    u, v, w = map(int, input().strip().split(' '))
    tree[u-1] += [(v-1, w % 2)]
    tree[v-1] += [(u-1, w % 2)]


stack = [0]
while len(stack) > 0:
    pos = stack.pop()
    for (p, w) in tree[pos]:
        if color[p] == -1:
            color[p] = color[pos] ^ w
            stack.append(p)

for c in color:
    print(c)

Buggy submission (verdict: Runtime Error):
import math

N = int(input())


class Tree:
    def __init__(self, n):
        self.par = [i for i in range(N+1)]


tree = [list() for _ in range(N)]
color = [-1 for _ in range(N)]
color[0] = 0

for _ in range(N-1):
    u, v, w = map(int, input().strip().split(' '))
    tree[u-1] += [(v-1, w % 2)]
    tree[v-1] += [(u-1, w % 2)]


def dfs(pos):
    for (p, w) in tree[pos]:
        if color[p] != -1:
            continue
        color[p] = color[pos] ^ w
        dfs(p)


dfs(0)
for c in color:
    print(c)
Problem p02681 (python)

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

lens = len(S)
lent = len(T)

ans = True
if lens + 1 != lent:
    ans = False

for i in range(lens):
    if S[i] != T[i]:
        ans = False

if ans:
    print('Yes')
else:
    print('No')

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

if S == T[::-1]
    print('Yes')
else:
    print('No')