Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from collections import Counter
def main():
    N=int(input())
    AB=[list(map(int, input().split())) for _ in range(N-1)]
    G=[[]for _ in range(N)]
    cnt=[0]*N
    for a,b in AB:
        G[a-1].append(b-1)
        G[b-1].append(a-1)
        cnt[a-1]+=1
        cnt[b-1]+=1
    CI=sorted(((c,i) for i,c in enumerate(cnt)), reverse=True)
    ans=[0]*N
    C=[0]*N
    S=[[],[],[]]
    for i in range(N+1):
        S[i%3].append(i)
    stack=[(0,-1,0)]
    while stack:
        u,p,d=stack.pop()
        for v in G[u]:
            if v!=p:
                stack.append((v,u,d^1))
                C[v]=d
    X=sum(C)
    use=[False]*N
    for j,(c,i) in enumerate(CI[:N//3],1):
        ans[i]=j*3
        for u in G[i]:
            use[u]=True
    k=[i for i in range(1,N+1,3)]
    l=[i for i in range(2,N+1,3)]
    for i,c in enumerate(C):
        if c and not use[u]:
            if not k:
                print(-1)
                return
            ans[i]=k.pop()
            k+=3
        if not c and not use[u]:
            if not l:
                print(-1)
                return
            ans[i]=l.pop()
            l+=3
    for i in range(N):
        if ans[i]==0:
            if k:
                ans[i]=k.pop()
            elif l:
                ans[i]=l.pop()
            else:
                print(-1)
                return
    print(*ans)

if __name__ == "__main__":
    main()

Fixed submission:
from collections import Counter
def main():
    N=int(input())
    AB=[list(map(int, input().split())) for _ in range(N-1)]
    G=[[]for _ in range(N)]
    cnt=[0]*N
    for a,b in AB:
        G[a-1].append(b-1)
        G[b-1].append(a-1)
        cnt[a-1]+=1
        cnt[b-1]+=1
    CI=sorted(((c,i) for i,c in enumerate(cnt)), reverse=True)
    ans=[0]*N
    C=[0]*N
    stack=[(0,-1,0)]
    while stack:
        u,p,d=stack.pop()
        for v in G[u]:
            if v!=p:
                stack.append((v,u,d^1))
                C[v]=d^1
    X=sum(C)
    if X<=N//3:
        D=[[i for i in range(1,N+1,3)]+[i for i in range(2,N+1,3)],[i for i in range(3,N+1,3)]]
        for i in range(N):
            if D[C[i]]:
                ans[i]=D[C[i]].pop()
            else:
                ans[i]=D[C[i]^1].pop()
    elif N-X<=N//3:
        D=[[i for i in range(3,N+1,3)],[i for i in range(1,N+1,3)]+[i for i in range(2,N+1,3)]]
        for i in range(N):
            if D[C[i]]:
                ans[i]=D[C[i]].pop()
            else:
                ans[i]=D[C[i]^1].pop()
    else:
        D=[[i for i in range(1,N+1,3)],[i for i in range(2,N+1,3)],[i for i in range(3,N+1,3)]]
        for i in range(N):
            if D[C[i]]:
                ans[i]=D[C[i]].pop()
            else:
                ans[i]=D[2].pop()
    print(*ans)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
H, N = map(int, input().split())
AB = [tuple(map(int, input().split()))for _ in range(N)]
DP = [10**10] * (H+1)
DP[H] = 0
for h in range(H, 0, -1):
    for a, b in AB:
        x = max(0, h - a)
        DP[x] = min(DP[x], DP[h] + b)
print(DP[0])

Fixed submission:
import sys
input=sys.stdin.readline

def main():
    H, N = map(int, input().split())
    AB = [tuple(map(int, input().split()))for _ in range(N)]
    DP = [10**10] * (H+1)
    DP[H] = 0
    for h in range(H, 0, -1):
        for a, b in AB:
            x = max(0, h - a)
            DP[x] = min(DP[x], DP[h] + b)
    print(DP[0])

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
lcm = lambda x,y: x*y//gcd(x,y)
MOD = 10**9+7
N = int(input())
A = list(map(int, input().split()))
ans = 0
p = 1
for a in A:
    b = lcm(a, p)
    ans = (ans * (b // p) % MOD + (b // a))%MOD
    p = b
print(ans)

Fixed submission:
from fractions import gcd
MOD = 10**9+7
N = int(input())
A = list(map(int, input().split()))
ans = 0
p = 1
for a in A:
    b = gcd(a,p)
    ans = (ans * (a//b) % MOD + (p//b))%MOD
    p = a*p//b
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
from functools import reduce
N, M = map(int, input().split())
A = list(map(int, input().split()))
AA = list(map(lambda x: x//2, A))
def lcm(x, y):
    return x * y // gcd(x, y)
B = list(map(lambda x:x&-x, A))
if all(map(lambda x:x==B[0], B[1:])):
    a = reduce(lcm, AA)
    print(M//a - M//(2*a))
else:
    print(0)

Fixed submission:
from fractions import gcd
from functools import reduce
N, M = map(int, input().split())
A = list(map(int, input().split()))
AA = list(map(lambda x: x//2, A))
def lcm(x, y):
    return x * y // gcd(x, y)
b0 = AA[0]&-AA[0]
for a in AA[1:]:
    if b0 != a&-a:
        print(0)
        break
else:
    a = reduce(lcm, AA)
    print(M//a - M//(2*a))

Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
from functools import reduce
N, M = map(int, input().split())
A = list(map(int, input().split()))
AA = list(map(lambda x: x//2, A))
def lcm(x, y):
    return x * y // gcd(x, y)
B = list(map(lambda x:len(bin(x&-x)), A))
if all(map(lambda x:x==B[0], B[1:])):
    a = reduce(lcm, AA)
    print(M//a - M//(2*a))
else:
    print(0)

Fixed submission:
from fractions import gcd
from functools import reduce
N, M = map(int, input().split())
A = list(map(int, input().split()))
AA = list(map(lambda x: x//2, A))
def lcm(x, y):
    return x * y // gcd(x, y)
b0 = AA[0]&-AA[0]
for a in AA[1:]:
    if b0 != a&-a:
        print(0)
        break
else:
    a = reduce(lcm, AA)
    print(M//a - M//(2*a))

Buggy python submission (verdict: Runtime Error):
from fractions import gcd
from functools import reduce
N, M = map(int, input().split())
A = list(map(int, input().split()))
def lcm_(x, y):
    x_ = x // 2
    y_ = y // 2
    return x_ * y_ // gcd(x_, y_)
a = reduce(lcm_, A)
print(M//a - M//(2*a))

Fixed submission:
from fractions import gcd
from functools import reduce
N, M = map(int, input().split())
A = list(map(int, input().split()))
AA = list(map(lambda x: x//2, A))
def lcm(x, y):
    return x * y // gcd(x, y)
b0 = AA[0]&-AA[0]
for a in AA[1:]:
    if b0 != a&-a:
        print(0)
        break
else:
    a = reduce(lcm, AA)
    print(M//a - M//(2*a))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
for k in range(N):
    x = A[0] ^ B[0]
    if all(a ^ b == x for a, b in zip(A[1:], B[1:])):
        print(k, x)
    A[:] = A[1:] + [A[0]]

Fixed submission:
class KMP:
    def __init__(self, P):
        self.P = P
        self.N = len(P)
        self.T = [0] * (self.N + 1)
        self._compile()

    def _compile(self):
        j = 0
        self.T[0] = -1
        for i in range(1, self.N):
            self.T[i] = j
            j += 1 if self.P[i] == self.P[j] else -j
        self.T[self.N] = j

    def search(self, S):
        NS = len(S)
        i = m = 0
        A = []
        while m + i < NS:
            if self.P[i] == S[m + i]:
                i += 1
                if i != self.N:
                    continue
                A.append(m)
            m += i - self.T[i]
            i = max(0, self.T[i])
        return A

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = [A[i]^A[(i+1)%N] for i in range(N)]
D = [B[i]^B[(i+1)%N] for i in range(N)]
C = C + C[:-1]
K = KMP(D).search(C)
for k in K:
    print(k, A[k]^B[0])
Buggy python submission (verdict: Runtime Error):
N = int(input())
S, T = input().split()
print("".join(map(lambda s,t:f"{s}{t}", S, T)))

Fixed submission:
N = int(input())
S, T = input().split()
print("".join(map(lambda s,t:s+t, S, T)))
Buggy python submission (verdict: Runtime Error):
from sys import setrecursionlimit
setrecursionlimit(10101)

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

depthu = [-1] * (N)
depthu[u] = 0
depthv = [-1] * (N)
depthv[v] = 0

def dfs_depth(p, depth):
    for q in table[p]:
        if depth[q] == -1:
            depth[q] = depth[p] + 1
            dfs_depth(q, depth)

dfs_depth(v, depthv)
dfs_depth(u, depthu)

p = [i for i in range(1, N-1) if depthu[i] >= depthv[i] + 2]
if p:
    print(max(depthu[i] + (depthu[i] - depthv[i]) // 2 for i in p))
else:
    print(depthv[u] // 2)


Fixed submission:
from collections import deque

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

depthu = [-1] * N
depthu[u] = 0
depthv = [-1] * N
depthv[v] = 0

par = deque([u])
while par:
    p = par.popleft()
    for q in table[p]:
        if depthu[q] == -1:
            depthu[q] = depthu[p] + 1
            par.append(q)

par = deque([v])
while par:
    p = par.popleft()
    for q in table[p]:
        if depthv[q] == -1:
            depthv[q] = depthv[p] + 1
            par.append(q)

p = [i for i in range(N) if depthu[i] < depthv[i]]
if p:
    print(max(depthv[i] - 1 for i in p))
else:
    print(depthu[v] - 1)
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
from operator import itemgetter

N, X, D = map(int, input().split())
if D < 0:
    D = -D
    X = -X

s = defaultdict(list)
for k in range(N+1):
    p = k * X % D
    q = k * X // D
    a = k * (k - 1) // 2
    b = (N - 1) * k - a + 1
    s[p].append((a + q, b + q))

ans = 0
for v in s.values():
    if not v: continue
    v.sort()
    a, b = v[0]
    for x, y in v[1:]:
        if b < x:
            ans += b - a
            a, b = x, y
        else:
            b = max(b, y)
    ans += b - a

print(ans)


Fixed submission:
from collections import defaultdict
from operator import itemgetter

def solve(N, X, D):
    if D < 0:
        D = -D
        X = -X
    elif D == 0:
        if X == 0:
            return 1
        return N + 1

    s = defaultdict(list)
    for k in range(N+1):
        p = k * X % D
        q = k * X // D
        a = k * (k - 1) // 2
        b = (N - 1) * k - a + 1
        s[p].append((a + q, b + q))

    ans = 0
    for v in s.values():
        if not v: continue
        v.sort()
        a, b = v[0]
        for x, y in v[1:]:
            if b < x:
                ans += b - a
                a, b = x, y
            else:
                b = max(b, y)
        ans += b - a
    return ans


if __name__ == "__main__":
    N, X, D = map(int, input().split())
    print(solve(N, X, D))

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

N, X, D = map(int, input().split())
if D < 0:
    D = -D
    X = -X

s = defaultdict(list)
for k in range(N+1):
    p = k * X % D
    q = k * X // D
    a = k * (k - 1) // 2
    b = (N - 1) * k - a + 1
    s[p].append((a + q, b + q))

ans = 0
for v in s.values():
    v.sort()
    a, b = v[0]
    for x, y in v[1:]:
        if b < x:
            ans += b - a
            a, b = x, y
        else:
            b = max(b, y)
    ans += b - a

print(ans)


Fixed submission:
from collections import defaultdict
from operator import itemgetter

def solve(N, X, D):
    if D < 0:
        D = -D
        X = -X
    elif D == 0:
        if X == 0:
            return 1
        return N + 1

    s = defaultdict(list)
    for k in range(N+1):
        p = k * X % D
        q = k * X // D
        a = k * (k - 1) // 2
        b = (N - 1) * k - a + 1
        s[p].append((a + q, b + q))

    ans = 0
    for v in s.values():
        if not v: continue
        v.sort()
        a, b = v[0]
        for x, y in v[1:]:
            if b < x:
                ans += b - a
                a, b = x, y
            else:
                b = max(b, y)
        ans += b - a
    return ans


if __name__ == "__main__":
    N, X, D = map(int, input().split())
    print(solve(N, X, D))
Buggy python submission (verdict: Runtime Error):
X,Y=map(int,input().split())

def cnb(n,k,p):
  if k>n:
    return 0
  c,d=1,1
  for i in range(k+1,n+1):
    c = (c*i)%p
  for i in range(1,k+1):
    d = (d*i)%p
  return (c*pow(d,p-2,p))%p

p=10**9+7
if X > 2*Y or Y > 2*X:
  pass
elif (X+Y)%3:
  pass
else:
  ans=cnb((X+Y)//3,(-X+2*Y)//3,p)

print(ans)


Fixed submission:
x,y = map(int,input().split())
mod = 10**9 + 7

def getComb(a,b,mod):
  if b > a:
    return 0
  if a - b > b :
    b = a - b
  comb = 1
  for i in range(b+1,a+1):
    comb = (comb * i) % mod
  d = 1
  for i in range(1,a-b+1):
    d = (d * i) % mod
  comb *= pow(d,mod-2,mod)
  return comb % mod

if x > 2*y or y > 2*x:
  print(0)
  exit()
if (x+y)%3 != 0:
  print(0)
  exit()
times = (x+y)//3
tmp = abs(x-y)
xtimes = (times - tmp) //2
ans = getComb(times,xtimes,mod)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,T=map(int,input().split());AB=[list(map(int,input().split())) for _ in range(N)]
dp=[0]*T
AB.sort()
m=0
for a,b in AB:
  m=max(m,dp[-1]+b)
  for j in range(T-1,a-1,-1):
    dp[j] = max(dp[j],dp[j-a]+b)

print(m)


Fixed submission:
N,T=map(int,input().split());AB=[list(map(int,input().split())) for _ in range(N)]
dp=[0]*T
AB.sort()
m=0
for a,b in AB:
  m=max(m,dp[-1]+b)
  for j in range(T-1,a-1,-1):
    dp[j] = max(dp[j],dp[j-a]+b)

print(m)
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
H = [0] + list(map(int, input().split()))
dp = [[10 ** 100] * (N-K+1) for _ in range(N+1)]
dp[0][0] = 0
for x in range(1, N+1):
    for y in range(1, min(x+1, N-K+1)):
        dp[x][y] = min(dp[i][y-1] + max(0, H[x] - H[i]) for i in range(x))
print(min(dp[i][N-L] for i in range(1, N+1)))

Fixed submission:
N, K = map(int, input().split())
H = [0] + [int(a) for a in input().split()]
X = [[1<<100] * (N-K+1) for _ in range(N+1)]
X[0][0] = 0
for i in range(1, N+1):
    for j in range(1, min(i+1, N-K+1)):
        X[i][j] = min([X[ii][j-1] + max(H[i] - H[ii], 0) for ii in range(i)])

print(min([x[-1] for x in X]))
Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
from math import sqrt

A, B = map(int, input().split())
C = gcd(A, B)
ans = 1
i = 2
while C > 1:
    if C % i == 0:
        ans += 1
        C //= i
        while C % i == 0:
            C //= i
    i += 1
print(ans)

Fixed submission:
from fractions import gcd

A, B = map(int, input().split())
C = gcd(A, B)
ans = 1
i = 2
for i in range(2, int(-(-C**0.5//1))+1):
    if C % i == 0:
        ans += 1
        while C % i == 0:
            C //= i
    i += 1
if C != 1:
    ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
class SegmentTree:
    def __init__(self, N, f, e=None):
        self.N = 1<<(N-1).bit_length()
        self.seg = [e] * (self.N*2)
        self.e = e
        self.f = f

    def build(self, A):
        for i,a in enumerate(A):
            self.seg[i+self.N] = a
        for i in range(self.N-1,0,-1):
            self.seg[i] = self.f(self.seg[i<<1], self.seg[i<<1|1])

    def update(self, i, x): # a_i += x
        i += self.N
        self.seg[i] = x
        while i > 1:
            self.seg[i>>1] = self.f(self.seg[i], self.seg[i^1])
            i >>= 1

    def query(self, a, b): # f [a, b)
        L = R = self.e
        a += self.N
        b += self.N
        while a < b:
            if a&1:
                L = self.f(L, self.seg[a])
                a += 1
            if b&1:
                b -= 1
                R = self.f(self.seg[b], R)
            a >>= 1
            b >>= 1
        return self.f(L, R)

from collections import Counter
def main():
    N,K,*P=map(int, open(0).read().split())
    Mseg=SegmentTree(N, max, 0)
    mseg=SegmentTree(N, min, float("inf"))
    Mseg.build(P)
    mseg.build(P)
    D=Counter(P[:K])
    ans=1
    als=1
    for i in range(1,K):
        als=als+1 if P[i]>P[i-1] else 1
    iss=als==K
    for i in range(N-K):
        als=als+1 if P[i+K]>P[i+K-1] else 1
        mp=mseg.query(i, i+K)
        Mp=Mseg.query(i+1,i+K+1)
        if not (mp==P[i] and Mp==P[i+K]) and not (iss and als==K):
            ans+=1
        iss|=als==K
    print(ans)

if __name__ == "__main__":
    main()

Fixed submission:
class SegmentTree:
    def __init__(self, N, f, e=None):
        self.N = 1<<(N-1).bit_length()
        self.seg = [e] * (self.N*2)
        self.e = e
        self.f = f

    def build(self, A):
        for i,a in enumerate(A):
            self.seg[i+self.N] = a
        for i in range(self.N-1,0,-1):
            self.seg[i] = self.f(self.seg[i<<1], self.seg[i<<1|1])

    def update(self, i, x): # a_i += x
        i += self.N
        self.seg[i] = x
        while i > 1:
            self.seg[i>>1] = self.f(self.seg[i], self.seg[i^1])
            i >>= 1

    def query(self, a, b): # f [a, b)
        L = R = self.e
        a += self.N
        b += self.N
        while a < b:
            if a&1:
                L = self.f(L, self.seg[a])
                a += 1
            if b&1:
                b -= 1
                R = self.f(self.seg[b], R)
            a >>= 1
            b >>= 1
        return self.f(L, R)

from collections import Counter
def main():
    N,K,*P=map(int, open(0).read().split())
    Mseg=SegmentTree(N, max, 0)
    mseg=SegmentTree(N, min, float("inf"))
    Mseg.build(P)
    mseg.build(P)
    D=Counter(P[:K])
    ans=1
    als=1
    for i in range(1,K):
        als=als+1 if P[i]>P[i-1] else 1
    iss=als==K
    for i in range(N-K):
        als=als+1 if P[i+K]>P[i+K-1] else 1
        mp=mseg.query(i, i+K)
        Mp=Mseg.query(i+1,i+K+1)
        if not (mp==P[i] and Mp==P[i+K]) and not (iss and als==K):
            ans+=1
        iss|=als==K
    print(ans)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import groupby

N, K = map(int, input().split())
S = input()

for _ in range(K):
    if not (S.find("L")>=0 and S.find("R")>=0):
        break
    A = list((s,len(list(it))) for s, it in groupby(S))
    s0, _ = A[0]
    s1, l = A[1]
    A[1] = (s0, l)
    S = "".join(s*l for s, l in A)
print(N - len(list(groupby(S))))

Fixed submission:
from itertools import groupby
d = {"R": "L", "L": "R"}
N, K = map(int, input().split())
S = input()
A = [(s,len(list(it))) for s, it in groupby(S)]
A = [(d[s], l) if i & 1 and i//2 < K else (s, l) for i, (s, l) in enumerate(A)]
S = "".join(s*l for s, l in A)
print(N - len(list(groupby(S))))
Buggy python submission (verdict: Time Limit Exceeded):
from sys import setrecursionlimit
setrecursionlimit(3*10**5)

N, Q = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(N-1)]
PX = [tuple(map(int, input().split())) for _ in range(Q)]
T = [[] for _ in range(N+1)]
for a, b in AB:
    T[a].append(b)
    T[b].append(a)

C = [0 for _ in range(N+1)]
for p, x in PX:
    C[p] += x


def rec(v, p=0):
    for t in T[v]:
        if t == p:
            continue
        C[t] += C[v]
        rec(t, v)


rec(1)
print(*C[1:])

Fixed submission:
from collections import deque

N, Q = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(N-1)]
PX = [tuple(map(int, input().split())) for _ in range(Q)]
T = [[] for _ in range(N+1)]
for a, b in AB:
    T[a].append(b)
    T[b].append(a)

C = [0 for _ in range(N+1)]
for p, x in PX:
    C[p] += x

S = deque([(1, 0)])
while S:
    v, p = S.popleft()
    for t in T[v]:
        if t == p:
            continue
        C[t] += C[v]
        S.append((t, v))

print(*C[1:])

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

C = [0 for _ in range(N+1)]
for p, x in PX:
    C[p] += x


def rec(v, p=0):
    for t in T[v]:
        if t == p:
            continue
        C[t] += C[v]
        rec(t, v)


rec(1)
print(*C[1:])


Fixed submission:
from collections import deque

N, Q = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(N-1)]
PX = [tuple(map(int, input().split())) for _ in range(Q)]
T = [[] for _ in range(N+1)]
for a, b in AB:
    T[a].append(b)
    T[b].append(a)

C = [0 for _ in range(N+1)]
for p, x in PX:
    C[p] += x

S = deque([(1, 0)])
while S:
    v, p = S.popleft()
    for t in T[v]:
        if t == p:
            continue
        C[t] += C[v]
        S.append((t, v))

print(*C[1:])
Buggy python submission (verdict: Runtime Error):
from itertools import groupby
S = input()
A = [len(list(it)) for s, it in groupby(S)]
B = [[0]*(n1-1)+[(n1+1)//2+n2//2]+[n1//2+(n2+1)//2]+[0]*(n2-1)
     for n1, n2 in zip(A[::2], A[1::2])]
print(*sum(B, []))from itertools import groupby
S = input()
A = [len(list(it)) for s, it in groupby(S)]
for n1, n2 in zip(A[::2], A[1::2]):
    print(*([0]*(n1-1)+[(n1+1)//2+n2//2]+[n1//2+(n2+1)//2]+[0]*(n2-1)), end=" ")

Fixed submission:
from itertools import groupby
S = input()
A = [len(list(it)) for s, it in groupby(S)]
for n1, n2 in zip(A[::2], A[1::2]):
    print(*([0]*(n1-1)+[(n1+1)//2+n2//2]+[n1//2+(n2+1)//2]+[0]*(n2-1)), end=" ")

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import groupby
S = input()
A = [len(list(it)) for s, it in groupby(S)]
B = [[0]*(n1-1)+[(n1+1)//2+n2//2]+[n1//2+(n2+1)//2]+[0]*(n2-1)
     for n1, n2 in zip(A[::2], A[1::2])]
print(*sum(B, []))

Fixed submission:
from itertools import groupby
S = input()
A = [len(list(it)) for s, it in groupby(S)]
for n1, n2 in zip(A[::2], A[1::2]):
    print(*([0]*(n1-1)+[(n1+1)//2+n2//2]+[n1//2+(n2+1)//2]+[0]*(n2-1)), end=" ")
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import accumulate
N = int(input())
A = list(map(int, input().split()))
S = sum(A)
B = list(accumulate([0] + A[1::2] + A[::2] + A[1::2] + A[::2]))
C = [S - 2 * (B[i+N//2] - B[i]) for i in range(N)]
print(*sum(list(map(list, zip(C[:N//2+1], C[N//2+1:]+[0]))), [])[:-1])

Fixed submission:
from itertools import accumulate
N = int(input())
A = list(map(int, input().split()))
X1 = sum(A) - 2 * sum(A[1::2])


def g():
    state = X1
    yield X1
    for i in range(N-1):
        state = 2 * A[i] - state
        yield state


print(*list(g()))

Buggy python submission (verdict: Runtime Error):
from itertools import accumulate
N = int(input())
A = list(map(int, input().split()))
S = sum(A)
B = list(accumulate([0] + A[1::2] + A[::2] + [A[1]]))
C = [S - 2 * (B[i+N//2] - B[i]) for i in range(N)]
print(*sum(list(map(list, zip(C[:N//2+1], C[N//2+1:]+[0]))), [])[:-1])

Fixed submission:
from itertools import accumulate
N = int(input())
A = list(map(int, input().split()))
X1 = sum(A) - 2 * sum(A[1::2])


def g():
    state = X1
    yield X1
    for i in range(N-1):
        state = 2 * A[i] - state
        yield state


print(*list(g()))
Buggy python submission (verdict: Runtime Error):
W, H, x, y = map(int, input().split())
print(f"{W*H/2} {int(W==x*2 and H==y*2)}")

Fixed submission:
W, H, x, y = map(int, input().split())
print(*[W*H/2, int(W==x*2 and H==y*2)])
Buggy python submission (verdict: Runtime Error):
from collections import Counter
N=int(input())
XY=[tuple(map(int, input().split())) for _ in range(N)]
PQ=[(x1-x2,y1-y2) for x1,y1 in XY for x2,y2 in XY if x1!=x2 or y1!=y2]
C=Counter(PQ)
print(N-C.most_common(1)[0][1])

Fixed submission:
from collections import Counter
N=int(input())
XY=[tuple(map(int, input().split())) for _ in range(N)]
PQ=[(x1-x2,y1-y2) for x1,y1 in XY for x2,y2 in XY if x1!=x2 or y1!=y2]
C=Counter(PQ)
print(N-C.most_common(1)[0][1] if N!=1 else 1)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
LR = [tuple(map(int, input().split())) for _ in range(M)]
print(len(set.intersection(*[set(range(l, r+1)) for l, r in LR])))


Fixed submission:
N, M = map(int, input().split())
LR = list(map(int, input().split()) for _ in range(M))
L, R = list(map(list, zip(*LR)))
print(max(0, min(R)-max(L)+1))