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

Fixed submission:
def main():
        N,Q = map(int,input().split())
        ab = [list(map(int,input().split())) for _ in range(N - 1)]
        px = [list(map(int,input().split())) for _ in range(Q)]
        ab.sort()
        # px.sort()
        plus = [0 for _ in range(N)]

        for p,x in px:
                plus[p - 1] += x 

        for a,b in ab:
                plus[b - 1] += plus[a - 1]
        for p in plus:
                print(p)

if __name__ == '__main__':
        main()

Buggy submission (verdict: Runtime Error):
def main():
        N,Q = map(int,input().split())
        ab = [list(map(int,input().split())) for _ in range(N - 1)]
        ab.sort()
        
        plus = [0 for _ in range(N)]
        for _ in range(Q):
        	p,x = map(int,input().split())
        	plus[p - 1] += x 

        for a,b in ab:
                plus[b - 1] += plus[a - 1]
        print(*p)

if __name__ == '__main__':
        main()

Buggy submission (verdict: Runtime Error):
def main():
        N,Q = map(int,input().split())
        ab = [list(map(int,input().split())) for _ in range(N - 1)]
        px = [list(map(int,input().split())) for _ in range(Q)]
        ab.sort()
        
        plus = [0 for _ in range(N)]
        for _ in range(Q):
        	p,x = map(int,input().split())
        	plus[p - 1] += x 

        for a,b in ab:
                plus[b - 1] += plus[a - 1]
        for p in plus:
                print(p)

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

Fixed submission:
import bisect
s = input()
t = input()
before = -1
len_s = len(s)
ans = 0
cnt = 0
moji = [[] for _ in range(26)]
for i,S in enumerate(s):
        moji[ord(S) - 97].append(i)

for T in t:
        if not moji[ord(T) - 97]:
                print(-1)
                exit()
        if moji[ord(T) - 97][-1] <= before:
                cnt += 1
                before = moji[ord(T) - 97][0]
                continue
        before = moji[ord(T) - 97][bisect.bisect_right(moji[ord(T) - 97],before)]
        # for num in moji[ord(T) - 97]:
        #         if num > before:
        #                 before = num
        #                 break
ans = cnt * len_s + before + 1
print(ans)

Buggy submission (verdict: Runtime Error):
s = input()
t = input()
before = -1
len_s = len(s)
ans = 0
cnt = 0
moji = [[] for _ in range(25)]
for i,S in enumerate(s):
        moji[ord(S) - 97].append(i)

for T in t:
        found = False
        if not moji[ord(T) - 97]:
                print(-1)
                exit()
        for num in moji[ord(T) - 97]:
                if num > before:
                        before = num
                        found = True
                        break
        if not found:
                cnt += 1
                before = moji[ord(T) - 97][0]
ans = cnt * len_s + before + 1
print(ans)

Buggy submission (verdict: Runtime Error):
s = input()
t = input()
before = -1
len_s = len(s)
ans = 0
cnt = 0
moji = [[] for _ in range(25)]
for i,S in enumerate(s):
        moji[ord(S) - 97].append(i)

for T in t:
        found = False
        if not moji[ord(T) - 97]:
                print(-1)
                exit()
        for num in moji[ord(T) - 97]:
                if num > before:
                        before = num
                        found = True
                        break
        if not found:
                cnt += 1
                before = moji[ord(T) - 97][0]
ans = cnt * len_s + before + 1
print(ans)
Problem p02957 (python)

Fixed submission:
n,m = map(int,input().split())
# n = int(input())
# n = input()
if (n + m) % 2 == 0:
    print((n + m) // 2)
else:
    print('IMPOSSIBLE')

Buggy submission (verdict: Runtime Error):
# n,m = map(int,input().split())
n = int(input())
# n = input()
a = list(map(int,input().split()))
b = list(map(int,input().split()))
cnt = 0
left = 0
for i in range(n):
    a1,b1 = a[i],b[i]
    if a1 <= b1 + left:
        cnt += a1
        left = min(b1 - a1 + left,b1)
    else:
        cnt += b1 + left
        left = 0
if a[n] <= left:
    cnt += a[n]
else:
    cnt += left
print(cnt)
Problem p03061 (python)

Fixed submission:

import fractions
from functools import reduce
n = int(input())
a = list(map(int,input().split()))
gcds = 0
r = [0]
l = [0]
for N in range(n):
	r.append(fractions.gcd(r[N],a[N]))
	l.append(fractions.gcd(l[N],a[n - N - 1]))
for i in range(n):
	gcds = max(gcds,(fractions.gcd(r[i],l[n - i - 1])))
print(gcds)

Buggy submission (verdict: Runtime Error):
import fractions
from functools import reduce
n = int(input())
a = list(map(int,input().split()))
gcds = 0
for N in range(n):
    gcds = max(gcds,reduce(fractions.gcd, a[:N],a[N+1:]))
print(gcds)

Buggy submission (verdict: Runtime Error):
import fractions
from functools import reduce
n = int(input())
a = list(map(int,input().split()))
gcds = 0
for N in range(n):
    b = a.copy()
    b.remove(b[N])
    gcds = max(gcds,reduce(fractions.gcd, b))
print(max(gcds))

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))
import functools
import math
gcds = []
for N in range(n):
    b = a.copy()
    b.remove(b[N])
    gcds.append(functools.reduce(math.gcd, b))
print(max(gcds))

Buggy submission (verdict: Runtime Error):
import functools
import math
n = int(input())
a = list(map(int,input().split()))
gcd = []
for N in range(n):
    b = a.copy()
    b.remove(b[N])
    gcd.append(functools.reduce(math.gcd, b))
print(max(gcd))

Buggy submission (verdict: Runtime Error):

import functools
import math
n = int(input())
a = list(map(int,input().split()))
gcd = []
for N in range(n):
    b = a.copy()
    b.remove(b[N])
    gcd.append(functools.reduce(math.gcd, b))
print(max(gcd))

Buggy submission (verdict: Runtime Error):

import functools
import math
import copy
n = int(input())
a = list(map(int,input().split()))
gcd = []
for N in range(n):
    b = copy.copy(a)
    b.remove(b[N])
    gcd.append(functools.reduce(math.gcd, b))
print(max(gcd))
Problem p03069 (python)

Fixed submission:
n = int(input())
s = input()
cnt = 0
narabi = []
befores = '#'
for S in s:
    if S == befores:
        cnt += 1
    else:
        narabi.append(cnt)
        befores = S
        cnt = 1
narabi.append(cnt)
if s[-1] == '#':
    narabi.append(0)
hennkann = s.count('.')
saishou = s.count('.')
hashu = 0
dot = 1
for i in range(int(len(narabi) / 2)):
    hennkann = hennkann - narabi[dot] + narabi[hashu]
    saishou = min(saishou,hennkann)
    dot += 2
    hashu += 2
print(saishou)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input()
ssp = s.split('.')
num = min(s.count(.),s.count('#') - len(ssp[-1]))
if s.count('#') == 0 or s.count('.') == 0:
    print(0)
    exit()
for i in range(n):
    if s[i - 1] == s[i]:
        continue
    num = min(num,s[:i].count('#') + s[i:].count('.'))
print(num)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input()
if s.count('#') == 0:
    print('0')
    exit()
ssp = s.split('.')
num = s[s.find('#'):].count('.')
num = min(num,s.count('#') - ssp[-1])
print(num)
Problem p03087 (python)

Fixed submission:
N,Q = map(int,input().split())
S = input()
r = [0 for n in range(N)]
l = [0 for n in range(N)]
cnt = 0
for s in range(N - 1):
	if S[s] == 'A':
		if S[s + 1] == 'C':
			cnt += 1
	l[s + 1] = cnt
cnt = 0
for s in range(1,N):
	if S[-s] == 'C':
		if S[-s - 1] == 'A':
			cnt += 1
	r[-s - 1] = cnt
for q in range(Q):
	L,R = map(int,input().split())
	print(cnt - l[L - 1] - r[R - 1])

Buggy submission (verdict: Runtime Error):
N,Q = map(int,input().split())
S = input()
place = []
for s in range(N - 1):
	if S[s] == 'A':
		if S[s + 1] == 'C':
			place.append(s)
PlaceCount = len(place)
for q in range(Q):
    num = 0
	l,r = map(int,input().split())
	l -= 1
	r -= 2
	for i in range(PlaceCount):
		if l <= place[i] <= r:
			num += 1
	print(num)

Buggy submission (verdict: Runtime Error):
n,q = map(int,input().split())
s = input()
num = []
for Q in range(q):
	l,r = map(int,input().split())
	num.append(int(s[l - 1:r].count('AC')))
print('/n'.join(num))
Problem p03105 (python)

Fixed submission:
a,b,c = map(int,input().split())
print(min(c,b // a))

Buggy submission (verdict: Runtime Error):
,b,c = map(int,input().split())
print(min(c,b // a))
Problem p03210 (python)

Fixed submission:
x = int(input())
if x == 3 or x == 5 or x == 7:
  print("YES")
else:
  print("NO")

Buggy submission (verdict: Runtime Error):
x = int(input())
if a == 3 or a == 5 or a == 7:
  print("YES")
else:
  print("NO")
Problem p03281 (python)

Fixed submission:
n = int(input())
ans = 0
for i in range(1,n + 1):
  if i % 2 == 0:
    continue
  cnt = 0
  for j in range(1,i + 1):
    if i % j == 0:
      cnt += 1
  if cnt == 8:
    ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
ans = 0
for i in range(1,n + 1):
  if n % 2 == 0:
    continue
  cnt = 0
  for j in range(1,i + 1):
    if i % j = 0:
      cnt += 1
  if cnt == 8:
    ans += 1
print(ans)
Problem p03503 (python)

Fixed submission:
N=int(input())
F=[int(input().replace(' ',''),2) for _ in range(N)]
P=[list(map(int,input().split())) for _ in range(N)]

ans=-10**10
for i in range(1,1<<10):
    prof=0
    for j,f in enumerate(F):
        prof+=P[j][bin(i&f).count("1")]
    ans=max(ans,prof)

print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
f = [int(input().replace(' ',''),2) for i in range(n)]
p = [list(map(int,input().split())) for i in range(n)]
prof = - 10 ** 10
for i in range(1,1 <<10):
	prof1 = 0
	for j,time in enumerate(f):
		same = bin(i & time).count(1)
		prof1 += p[j][same]
	prof = max(prof,prof1)
print(prof)

Buggy submission (verdict: Runtime Error):
N=int(input())
F=[int(input().replace(' ',''),2) for _ in range(N)]
P=[list(map(int,input(),split())) for _ in range(N)]

ans=-10**10
for i in range(1,1<<10):
    prof=0
    for j,f in enumerate(F):
        prof+=P[j][bin(i&f).count("1")]
    ans=max(ans,prof)

print(ans)
Problem p03854 (python)

Fixed submission:
s = input()
s = s.replace('eraser','z')
s = s.replace('erase','z')
s = s.replace('dreamer','z')
s = s.replace('dream','z')
for  S in s:
    if S != 'z':
        print('NO')
        exit()
print('YES')

Buggy submission (verdict: Runtime Error):
s = input()
s = s.replace('eraser','z')
s = s.repalace('erase','z')
s = s.repalace('dreamer','z')
s = s.repalace('dream','z')
for  S in s:
    if S != 'z':
        print('NO')
    else:
        print('YES')

Buggy submission (verdict: Runtime Error):
s = input()
s = s.replace('eraser','z')
s = s.repalace('erase','z')
s = s.repalace('dreamer','z')
s = s.repalace('dream','z')
for  S in s:
    if S != z:
        print('NO')
    else:
        print('YES')
Problem p02630 (python)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
count = [0 for i in range(110000)]
sum_ = sum(A)
for i in range(N):
  count[A[i]] += 1

Q=int(input())
for i in range(Q):
  b,c = map(int,input().split())
  count[c] += count[b]
  sum_ += (c-b)*count[b]
  count[b] = 0
  print(sum_)

Buggy submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
Q=int(input())
bc = [[0 for i in range(2)] for j in range(Q)]
for i in range(Q):
  bc[i] = list(map(int,input().split()))

count = [0 for i in range(100000)]
for i in range(N):
  count[A[i]] += 1

sum_ = sum(A)
for i in range(Q):
  b,c = bc[i]
  n = count[b]
  sum_ -= b*n
  sum_ += c*n
  count[c] += n
  print(sum_)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
for i in range(Q):
    B, C = list(map(int, input().split()))
    if B not in A:
        print(sum_)
        continue
    sum_ = 0
    for j in range(len(A)):
        if A[j] == B:
            A[j] = C
        sum_ += A[j]
    print(sum_)
Problem p02642 (python)

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

if N == 1:
  print(1)
  exit()

flag = [0]*(10**6+5)
for i in range(N):
  flag[A[i]] = 1

for i in range(N):
  if flag[A[i]] == 0:
    continue
  if i>0 and A[i]==A[i-1]:
    flag[A[i]] = 0
    continue
  for num in range(A[i]*2,A[-1]+1,A[i]):
    flag[num] = 0
  
print(sum(flag))

Buggy submission (verdict: Runtime Error):
N = int(input())
*A,=map(int,input().split())
A = sorted(A)

if N == 1:
  print(1)
  exit()

flag = [0]*(10**6+5)
for i in range(N):
  flag[A[i]] = 1

for i in range(N):
  if flag[A[i]] == 0:
    continue
  if i>0 and A[i]==A[i-1]:
    flag[A[i]] = 0
    continue
  for num in range(A[i]*2,A[-1]+A[i],A[i]):
    flag[num] = 0
  
print(sum(flag))
Problem p02644 (python)

Fixed submission:
from collections import deque

def main():
  H,W,K=map(int,input().split())
  x1,y1,x2,y2 = map(lambda x: int(x)-1,input().split())
  S=[list(input()) for _ in range(H)]
  INF = 10**20

  def bfs(x0,y0,x_goal,y_goal):
    seen = [[0 for i in range(W)] for j in range(H)]
    d = [[INF for i in range(W)] for j in range(H)]
    d[x0][y0] = 0
    todo = deque()
    seen[x0][y0] = 1
    todo.append((x0,y0))
    while todo:
      x0,y0 = todo.popleft()
      dx,dy = (1,-1,0,0),(0,0,1,-1)
      for i in range(4):
        for k in range(K):
          x,y = x0+dx[i]*(k+1), y0+dy[i]*(k+1)
          if x<0 or x>=H:break
          if y<0 or y>=W:break
          if d[x][y] < d[x0][y0] + 1: break
          if S[x][y]=='@':break
          if seen[x][y]: continue
          seen[x][y] = 1
          todo.append((x,y))
          d[x][y] = d[x0][y0] + 1
          if x==x_goal and y == y_goal: return d[x][y]
    return d[x_goal][y_goal]

  ans = bfs(x1,y1,x2,y2)
  print(ans if ans < INF else -1)
  
if __name__ == "__main__":
  main()

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

def main():
  H,W,K=map(int,input().split())
  x1,y1,x2,y2 = map(lambda x: int(x)-1,input().split())
  S=[list(input()) for _ in range(H)]
  INF = 10**20

  def bfs(x0,y0,x_goal,y_goal):
    seen = [[0 for i in range(W)] for j in range(H)]
    d = [[INF for i in range(W)] for j in range(H)]
    d[x0][y0] = 0
    todo = deque()
    seen[x0][y0] = 1
    todo.append((x0,y0))
    while todo:
      x0,y0 = todo.popleft()
      dx,dy = (1,-1,0,0),(0,0,1,-1)
      for i in range(4):
        for k in range(K):
          x,y = x0+dx[i]*(k+1), y0+dy[i]*(k+1)
          if x<0 or x>=H:break
          if y<0 or y>=W:break
          if d[x][y] < d[x0][y0] + 1: break
          if S[x][y]=='@':break
          if seen[x][y] = 1: continue
          seen[x][y] = 1
          todo.append((x,y))
          d[x][y] = d[x0][y0] + 1
          if x==x_goal and y == y_goal: return d[x][y]
    return d[x_goal][y_goal]

  ans = bfs(x1,y1,x2,y2)
  print(ans if ans < INF else -1)
  
if __name__ == "__main__":
  main()

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

H,W,K=map(int,input().split())
x1,y1,x2,y2 = map(lambda x: int(x)-1,input().split())
S=[list(input()) for _ in range(H)]

def bfs(x0,y0,x_goal,y_goal):
  seen = [[0 for i in range(W)] for j in range(H)]
  d = [[0 for i in range(W)] for j in range(H)]
  todo = deque()
  if S[x0][y0]=='@':return 0
  seen[x0][y0] = 1
  todo.append((x0,y0))
  while todo:
    x0,y0 = todo.popleft()
    dx,dy = (1,-1,0,0),(0,0,1,-1)
    for i in range(4):
      for k in range(K):
        x,y = x0+dx[i]*(k+1), y0+dy[i]*(k+1)
        if x<0 or x>=H:break
        if y<0 or y>=W:break
        if seen[x][y]==1:continue
        if S[x][y]=='@':break
        seen[x][y] = 1
        todo.append((x,y))
        d[x][y] = d[x0][y0] + 1
        if x==x_goal and y == y_goal: return d[x][y]

ans = bfs(x1,y1,x2,y2)
print(ans if ans > 0 else -1)
Problem p02684 (python)

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

vis=[0]*(N+1)
now=1
vis[now] = 1
his=[now]
while 1:
  new = A[now-1]
  if vis[new]==0:
    vis[new]=1
    his.append(new)
    now = new
  else:
    idx = his.index(new)
    cycle = his[idx:]
    margin = his[:idx]
    break
    
if K <= len(margin):
  print(his[K])
  exit()
  
K -= len(margin)
K %= len(cycle)

print(cycle[K])

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

A = [0] + A

visited = [1]
now = 1
short = 0
while True:
  next = A[now]
  if next in visited:
    break
  visited.append(next)
  if len(visited)==K:
    short = 1
    break
  now = next

if short: print(visited[K])
else:
  initial = visited.index(next)
  cycle = len(visited[initial:])
  if K >= cycle:
    residual = (K - initial) % cycle
    print(visited[initial+residual])
  else:
    print(visited[K])

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

A = [0] + A

visited = [1]
now = 1
short = 0
while True:
  next = A[now]
  if next in visited:
    break
  if len(visited)==K:
    short = 1
    break
  visited.append(next)
  now = next

if short: print(visited[K])
else:
  initial = visited.index(next)
  cycle = len(visited[initial:])
  if K >= cycle:
    residual = (K - initial) % cycle
    print(visited[initial+residual])
  else:
    print(visited[K])
Problem p02691 (python)

Fixed submission:
from collections import defaultdict

N = int(input())
*A,=map(int,input().split())

'''
方針:
- 各A_i,(i<h)ごとにf(h,j)=A_h+A_j-|h-j|の値がf(i,j)に比べてどれだけ変化するかを計算し、
リストに格納(①)
- 各要素A_k,(j<k)ごとにf(i,k)=A_i+A_k-|i-k|の値がf(i,j)に比べてどれだけ変化するかを
計算し、カウントをとる(②)
- 再度ループを回して①と②を照合し、値が一致する組数をansに加算
'''

ans=0
diff_list=[] #①照合用の差分リスト
count=defaultdict(int) #②各要素がどれだけはみ出ているかのカウント
#前処理として、最初のループで①と②を作成
for i in range(1,N):
  if i == A[0]+A[i]:
    ans += 1
  d1 = A[i]-A[0]
  d2 = i
  diff_list.append(d1+d2)
  
  count[A[0]+A[i]-i] += 1

for i in range(N-1):
  count[A[0]+A[i+1]-(i+1)] -= 1 #その要素自身を忘れずに引く
  d = diff_list[i]
  ans += count[-d]
  
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np

N=int(input())
A=np.array(list(map(int, input().split())))

sign = np.arange(1,N+1)
sign = sign + A
temp = np.arange(N)+1-A
count = 0
for i in range(1,N):
  count += (sign[:i]==temp[:i]).sum()

print(count)
Problem p02705 (python)

Fixed submission:
import numpy as np

r=int(input())
print(np.pi*2*r)

Buggy submission (verdict: Runtime Error):
r=int(input())
print(numpy.pi*2*r)
Problem p02767 (python)

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

avg = sum(X)//N

E1 = sum(list(map(lambda x: (x - avg)**2, X)))
E2 = sum(list(map(lambda x: (x - avg - 1)**2, X)))

print(min(E1,E2))

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

avg = sum(X)//N

E1 = sum(list(map(lambda x: (x - avg)**2, X)))
E2 = sum(list(map(lambda x: (x - avg - 1)**2, X)))

print(min(E1m E2))
Problem p02796 (python)

Fixed submission:
N=int(input())
INF=10**20
 
X=[]
for i in range(N):
  x,l=map(int,input().split())
  X.append((x-l,x+l-1))
  
X = sorted(X,key=lambda x:x[1])

last=0
ans=1
for i in range(1,N):
  if X[last][1]<X[i][0]:
    ans += 1
    last=i
  else:
    continue
    
print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
INF=10**20

X=[]
for i in range(N):
  x,l=map(int,input().split())
  X.append((x-l,x+l-1))
  
X = sorted(X)
rmax=-INF
res=[]
for i in range(N):
  cnt=0
  if rmax>=X[i][0]:
    cnt+=1
  if i<N-1 and X[i][1]>=X[i+1][0]:
    cnt+=1
  res.append(cnt)
  rmax = max(rmax,X[i][1])
  
dellist=[]
for i in range(len(res)):
  if res[i]==2:
    dellist.append(i)

for i in range(len(dellist)):
  del X[dellist[i]]
  
rmax=-INF
res=[]
N=len(X)
for i in range(N):
  cnt=0
  if rmax>=X[i][0]:
    cnt+=1
  if i<N-1 and X[i][1]>=X[i+1][0]:
    cnt+=1
  res.append(cnt)
  rmax = max(rmax,X[i][1])
  
dellist=[]
flag=0
for i in range(len(res)-1):
  if flag==0 and res[i]==res[i+1]==1:
    dellist.append(i)
    flag=1
  if flag:
    flag=0

for i in range(len(dellist)):
  del X[dellist[i]]
  
print(len(X))
Problem p02985 (python)

Fixed submission:
from collections import deque

N,K=map(int,input().split())
mod = 10**9+7
G=[[] for _ in range(N)]
for i in range(N-1):
  a,b=map(int,input().split())
  G[a-1].append(b-1)
  G[b-1].append(a-1)

def bfs(s):
    seen = [0]*N
    prev = [0]*N
    color = [0]*N
    todo = deque()
    seen[s]=1
    todo.append(s)
    color[s]=K
    while todo:
      a = todo.popleft()
      if a == start: count = K-1
      else: count = K-2
      for b in G[a]:
        if seen[b] == 0:
          seen[b] = 1
          todo.append(b)
          prev[b] = a
          color[b] = count %mod
          count -= 1
    return color
  
MAX,start = 0,-1
for i in range(N):
  if len(G[i])>MAX:
    MAX=len(G[i])
    start = i
    
color = bfs(start)
ans = 1
for i in range(N):
  ans *= color[i]
  ans %= mod
  
print(ans)

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

N,K=map(int,input().split())
if N==1:print(K)
else:
  G=[[] for i in range(N+1)]
  #deg=[0]*(N+1)
  mod=10**9+7

  for i in range(N-1):
    a,b=map(int,input().split())
    G[a].append(b)
    G[b].append(a)
    #deg[a]+=1
    #deg[b]+=1

  #deg2 = sorted(enumerate(deg),key=lambda x:x[1])
  for i in range(1,N+1):
    if len(G[i])==1:break
  first = i
  #first = deg2[1][0]
  second = G[first][0]
  color = [1]*(N+1)
  color[first],color[second]=K,K-1

  def bfs(s):
      seen = [0]*(N+1)
      todo = deque([])
      seen[s]=1
      todo.append(s)
      while 1:
        if len(todo)==0:break
        a = todo.popleft()
        if a != first: 
          acolor=K-1
        for b in G[a]:
          if seen[b] == 0:
            seen[b] = 1
            todo.append(b)
            if b != second:
              acolor -= 1
              color[b] = acolor

  bfs(first)
  total = prod(color)%mod
  print(total)
Problem p03050 (python)

Fixed submission:
N=int(input())

if N == 1:
  print(0)
  exit()

ans = 0
i = 1
while True:
  m = N//i-1
  q,r = divmod(N,m)
  if q == r:
    ans += m
  if m<N**.5:
    break
  i += 1
  
print(ans)

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

if N == 0:
  print(0)
  exit()

ans = 0
i = 1
while True:
  m = N//i-1
  q,r = divmod(N,m)
  if q == r:
    ans += m
  if m<N**.5:
    break
  i += 1
  
print(ans)

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

ans = 0
i = 1
while True:
  m = N//i-1
  q,r = divmod(N,m)
  if q == r:
    ans += m
  if m<N**.5:
    break
  i += 1
  
print(ans)
Problem p03062 (python)

Fixed submission:
from bisect import bisect_left

N=int(input())
A=list(map(int,input().split()))
A=sorted(A)

idx = bisect_left(A,0)
if idx != 0 and idx != N:
  if idx % 2 == 1:
    if abs(A[idx-1]) > abs(A[idx]):
      A[idx-1] *= -1
      A[idx] *= -1
  for i in range(0,idx-1,2):
    A[i] *= -1
    A[i+1] *= -1

if idx==N:
  if N % 2 == 0:
    print(-sum(A))
    exit()
  else:
    print(-sum(A[:-1])+A[-1])
    exit()

print(sum(A))

Buggy submission (verdict: Runtime Error):
from bisect import bisect_left

N=int(input())
A=list(map(int,input().split()))
A=sorted(A)

idx = bisect_left(A,0)
if idx != 0:
  if idx % 2 == 1:
    if abs(A[idx-1]) > abs(A[idx]):
      A[idx-1] *= -1
      A[idx] *= -1
  for i in range(0,idx-1,2):
    A[i] *= -1
    A[i+1] *= -1

print(sum(A))