Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
# N = int(input())
# A = [0] * N
# B = []
# for n in range(N):
#     A[n] = int(input())
#     bn = []
#     for i in range(A[n]):
#         x, y = map(int, input().split())
#         bn.append((x-1, y))
#     B.append(bn)

# ans = 0
# # bit & (1 << n) で n 番目の 0,1
# for bit in range(1 << N):
#     ok = [False] * N
#     for n in range(N):
#         if ((bit >> n) & 1) == 1:
#             if all([((bit >> B[n][i][0]) & 1) == B[n][i][1] for i in range(A[n])]):
#                 ok[n] = True
#         else:
#             if all([((bit >> B[n][i][0]) & 1) != B[n][i][1] for i in range(A[n])]):
#                 ok[n] = True
#     if all(ok):
#         ans = max(ans, sum(list(map(int, format(bit, "b")))))

# print(ans)

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

MOD = 10 ** 9 + 7

ans = 0
for i in range(60):
    n = sum([(a >> i) & 1 for a in A])
    ans = (ans + n * (N - n) * (2 ** i)) % MOD

print(ans)

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

MOD = 10 ** 9 + 7

ans = 0
for i in range(60):
    n = sum([(a >> i) & 1 for a in A])
    ans = (ans + n * (N - n) * (2 ** i)) % MOD

print(ans)
Buggy python submission (verdict: Runtime Error):
from copy import deepcopy
import itertools
from bisect import bisect_left
from bisect import bisect_right
import math
from collections import deque
from collections import Counter


def read():
    return int(input())


def readmap():
    return map(int, input().split())


def readlist():
    return list(map(int, input().split()))


if __name__ == "__main__":
    N = read()
    B = [math.inf]
    B.extend(readlist())
    B.append(math.inf)

    print(sum([min(B[i], B[i-1]) for i in range(1, N+1)]))



Fixed submission:
from copy import deepcopy
import itertools
from bisect import bisect_left
from bisect import bisect_right
import math
from collections import deque
from collections import Counter


def read():
    return int(input())


def readmap():
    return map(int, input().split())


def readlist():
    return list(map(int, input().split()))


INT_MAX = 10 ** 10


if __name__ == "__main__":
    N = read()
    B = [INT_MAX]
    B.extend(readlist())
    B.append(INT_MAX)

    print(sum([min(B[i], B[i-1]) for i in range(1, N+1)]))

Buggy python submission (verdict: Runtime Error):
from copy import deepcopy
import itertools
from bisect import bisect_left
from bisect import bisect_right
import math
from collections import deque
from collections import Counter


def read():
    return int(input())


def readmap():
    return map(int, input().split())


def readlist():
    return list(map(int, input().split()))


if __name__ == "__main__":
    N = read()
    B = [math.inf]
    B.extend(readlist())
    B.append(math.inf)

    print(sum([min(B[i], B[i-1]) for i in range(1, N+1)]))



Fixed submission:
from copy import deepcopy
import itertools
from bisect import bisect_left
from bisect import bisect_right
import math
from collections import deque
from collections import Counter


def read():
    return int(input())


def readmap():
    return map(int, input().split())


def readlist():
    return list(map(int, input().split()))


INT_MAX = 10 ** 10


if __name__ == "__main__":
    N = read()
    B = [INT_MAX]
    B.extend(readlist())
    B.append(INT_MAX)

    print(sum([min(B[i], B[i-1]) for i in range(1, N+1)]))
Buggy python submission (verdict: Runtime Error):
def read():
    return int(input())


def readlist():
    return list(map(int, input().split()))


def readmap():
    return map(int, input().split())


N, K = readmap()
A = readlist()

cnt = [0] * 50  # cnt[i] は 2^i の桁の 1 の数

for a in A:
    i = 0
    while a:
        if a % 2:
            cnt[i] += 1
        i += 1
        a = a // 2

is_zero = [False] * 50

for i in range(50):
    if 2 * cnt[i] >= N:
        is_zero[i] = True

candidate = []

for i in range(50):
    if 2**i <= K:
        c = 0
        for j in reversed(range(i+1)):
            if (not is_zero[j]) and c + 2 ** j <= K:
                c += 2 ** j
        candidate.append(c)

can = [sum([c ^ a for a in A]) for c in candidate]

print(max(can))

Fixed submission:
def read():
    return int(input())


def readlist():
    return list(map(int, input().split()))


def readmap():
    return map(int, input().split())


N, K = readmap()
A = readlist()

cnt = [0] * 50  # cnt[i] は 2^i の桁の 1 の数

for a in A:
    i = 0
    while a:
        if a % 2:
            cnt[i] += 1
        i += 1
        a = a // 2

is_zero = [False] * 50

for i in range(50):
    if 2 * cnt[i] >= N:
        is_zero[i] = True

candidate = [0]

for i in range(49):
    if 2**i <= K:
        c = 0
        for j in reversed(range(i+1)):
            if (not is_zero[j]) and c + 2 ** j <= K:
                c += 2 ** j
        candidate.append(c)

can = [sum([c ^ a for a in A]) for c in candidate]

print(max(can))
Buggy python submission (verdict: Runtime Error):
import math


def read():
    return int(input())


def readlist():
    return list(map(int, input().split()))


def readmap():
    return map(int, input().split())


def usage(n):
    fct = factorize(n)
    ret = []
    for div in divisorize(fct):
        ret.append(num(div))
    return ret

def factorize(n):
    fct = []  # prime factor
    b, e = 2, 0  # base, exponent
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct


def divisorize(fct):
    b, e = fct.pop()  # base, exponent
    pre_div = divisorize(fct) if fct else [[]]
    suf_div = [[(b, k)] for k in range(e + 1)]
    return [pre + suf for pre in pre_div for suf in suf_div]


def num(fct):
    a = 1
    for base, exponent in fct:
        a = a * base ** exponent
    return a


N, M = readmap()
div = usage(M)
ans = 0
for d in div:
    if N * d <= M:
        ans = max(ans, d)
print(ans)

Fixed submission:
import math


def read():
    return int(input())


def readlist():
    return list(map(int, input().split()))


def readmap():
    return map(int, input().split())


def usage(n):
    fct = factorize(n)
    ret = []
    for div in divisorize(fct):
        ret.append(num(div))
    return ret

def factorize(n):
    fct = []  # prime factor
    b, e = 2, 0  # base, exponent
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct


def divisorize(fct):
    b, e = fct.pop()  # base, exponent
    pre_div = divisorize(fct) if fct else [[]]
    suf_div = [[(b, k)] for k in range(e + 1)]
    return [pre + suf for pre in pre_div for suf in suf_div]


def num(fct):
    a = 1
    for base, exponent in fct:
        a = a * base ** exponent
    return a


N, M = readmap()
if M == 1:
    print(1)
    quit()
div = usage(M)
ans = 0
for d in div:
    if N * d <= M:
        ans = max(ans, d)
print(ans)
Buggy python submission (verdict: Runtime Error):
import numpy as np

x_1, y_1, x_2, y_2 = map(int, input().split())

P_1 = np.array([x_1, y_1])
P_2 = np.array([x_2, y_2])
vec_12 = P_2 - P_1
vec_13 = np.array([-vec_12[1], vec_12[0]])
P_3 = P_1 + vec_13
P_4 = P_2 + vec_13
print(P_3[0], P_3[1], P_4[1], P_4[2])


Fixed submission:
import numpy as np

x_1, y_1, x_2, y_2 = map(int, input().split())

P_1 = np.array([x_1, y_1])
P_2 = np.array([x_2, y_2])
vec_12 = P_2 - P_1
vec_13 = np.array([-vec_12[1], vec_12[0]])
P_3 = P_1 + vec_13
P_4 = P_2 + vec_13
print(P_4[0], P_4[1], P_3[0], P_3[1])
Buggy python submission (verdict: Time Limit Exceeded):
from copy import deepcopy
import itertools


def read():
    return int(input())


def readmap():
    return map(int, input().split())


def readlist():
    return list(map(int, input().split()))


S = input()
K = read()

substring = set()
for k in range(1, max(K, len(S))+1):
    for i in range(len(S)-k+1):
        substring.add(S[i:i+k])

sub = sorted(list(substring))
print(sub[K-1])


Fixed submission:
from copy import deepcopy
import itertools


def read():
    return int(input())


def readmap():
    return map(int, input().split())


def readlist():
    return list(map(int, input().split()))


S = input()
K = read()

substring = set()
for k in range(1, min(K, len(S))+1):
    for i in range(len(S)-k+1):
        substring.add(S[i:i+k])

sub = sorted(list(substring))
print(sub[K-1])
Buggy python submission (verdict: Time Limit Exceeded):
# A

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

Acum = [0] + A
ls = set()
ls.add(0)
for i in range(1, N+1):
    Acum[i] += Acum[i-1]
    ls.add(Acum[i])

lst = []
for n in ls:
    num = Acum.count(n)
    if num > 1:
        lst.append(num * (num - 1) / 2)

if lst:
    print(int(sum(lst)))
else:
    print(0)

Fixed submission:
# A

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

Acum = [0] + A
dic = {0: 1}
for i in range(1, N + 1):
    Acum[i] += Acum[i - 1]
    if Acum[i] in dic.keys():
        dic[Acum[i]] += 1
    else:
        dic[Acum[i]] = 1
ans = 0
for v in dic.values():
    if v > 1:
        ans += int(v * (v - 1) / 2)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# B

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

N = int(input())
S = []
for _ in range(N):
    S.append(list(input()))


def is_good(S):
    T = []
    for j in range(N):
        ls = []
        for i in range(N):
            ls.append(S[i][j])
        T.append(ls)

    if T == S:
        return True
    else:
        return False


ans = 0
for a in range(N):
    T = []
    for i in range(N):
        T.append(S[(i+a) % N])
    if is_good(T):
        ans += N

print(ans)


Fixed submission:
# B

N = int(input())
S = []
for _ in range(N):
    S.append(list(input()))


def is_good(S):
    # T = []
    # for j in range(N):
    #     ls = []
    #     for i in range(N):
    #         ls.append(S[i][j])
    #     T.append(ls)
    T = list(map(list, zip(*S)))

    if T == S:
        return True
    else:
        return False


ans = 0
for a in range(N):
    T = []
    for i in range(N):
        T.append(S[(i+a) % N])
    if is_good(T):
        ans += N

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int, input().split())
p = list(map(int, input().split()))

def sum_element(p:list,i:int,k:int):
    ans = 0
    for j in range(k):
        ans += p[i+j]
    return ans

pmax = 0
pindex = 0

for i in range(len(p)-k+1):
    ptmp = sum_element(p,i,k)
    if pmax < ptmp:
        pindex = i
        pmax = ptmp

ans = 0
for j in range(k):
    ans += (p[pindex+j]*(p[pindex+j]+1))/2/p[pindex+j]

print(ans)

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

ev = [0] * n

for i in range(n):
    ev[i] = (1+p[i])/2

cs = [0] * n
cs[0] = ev[0]

for i in range(1,n):
    cs[i] = cs[i-1] + ev[i]

ans = cs[k-1]

for i in range(n-k):
    s = cs[i+k] - cs[i]
    if s > ans:
        ans = s

print(ans)
Buggy python submission (verdict: Runtime Error):
import math

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

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

print(lcm(a, b))

Fixed submission:
a,b = map(int, input().split())

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a


def lcm(a, b):
	return a * b // gcd (a, b)


print(lcm(a,b))
Buggy python submission (verdict: Runtime Error):
n = int(input())
d = list(map(int, input().split()))

d_sum = sum(d)

m = 0
for k in d:
    m += k **2
    
print((d_sum**2 - m)　//　2)

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

d_sum = sum(d)

m = 0
for k in d:
    m += k **2
    
print((d_sum**2 - m)//2)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

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

ans = []

for i in range(1, n+1):
    ans.append(a.index(i) + 1)

print(' '.join(map(str,ans)))

Fixed submission:
n = int(input())

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

ans = [0] * n

for i in range(n):
    ans[a[i] - 1] = i + 1 

print(' '.join(map(str,ans)))
Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int, input().split())
A=list(map(int, input().split()))

for i in range(M):
    amax = A.index(max(A))
    A[amax] = A[amax] // 2

print(sum(A))


Fixed submission:
import heapq as hq

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

#ヒープキューのために符号逆転
A=list(map(lambda x: x * (-1), A))
hq.heapify(A)

for i in range(M):
    a = hq.heappop(A) * (-1)
    hq.heappush(A, a // 2 * (-1))

print(sum(A) * (-1))

Buggy python submission (verdict: Runtime Error):
import math

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

#B=list(map(lambda x: int(math.log2(x)), A))

#どこに何枚適用するか
D=[0 for _ in range(N)]

for i in range(M):
    A.index(max(A)) = A.index(max(A)) // 2

print(sum(A))

Fixed submission:
import heapq as hq

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

#ヒープキューのために符号逆転
A=list(map(lambda x: x * (-1), A))
hq.heapify(A)

for i in range(M):
    a = hq.heappop(A) * (-1)
    hq.heappush(A, a // 2 * (-1))

print(sum(A) * (-1))
Buggy python submission (verdict: Time Limit Exceeded):
# encoding: utf-8

N=int(input())
H=list(map(int, input().split()))

def get_distance(s,H):
    distance=0

    for i in range(s,len(H)-1):
        if H[i+1] <= H[i]:
            distance += 1
        else:
            break
    
    return distance

ans = 0
i=0

while i < N:
    t = get_distance(i,H)
    if ans < t:
        ans = t
    i += 1

print(ans)

Fixed submission:
# encoding: utf-8

N=int(input())
H=list(map(int, input().split()))

def get_distance(s,H):
    distance=0

    for i in range(s,len(H)-1):
        if H[i+1] <= H[i]:
            distance += 1
        else:
            break
    
    return distance

ans = 0
i=0

while i < N:
    t = get_distance(i,H)
    if ans < t:
        ans = t
    i += t + 1

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

cnt=0
for i in range(1,N+1):
    new = [int(d) for d in str(i)]
    print(new)
    sento=new[0]
    matu=new[-1]
    keta=len(new)

    if matu!='0':
        new[0]=matu
        new[-1]=sento
        comb=''.join(new)
        if matu==sento:
            cnt+=max(0,len(new)-1)
        elif comb>N:
            for j in range(0,keta-2):
                cnt+=9**j
        elif comb<N:
            for j in range(0,keta-1):
                cnt+=9**j







print(cnt)


Fixed submission:
N = int(input())

A = [list(0 for i in range(9)) for _ in range(9)]

for i in range(1,N+1):
    new = [int(d) for d in str(i)]
    if  new[-1]!=0:
        A[new[0]-1][new[-1]-1]+=1

cnt=0
for i in range(9):
    for j in range(9):
        cnt+=A[i][j]*A[j][i]

print(cnt)
Buggy python submission (verdict: Runtime Error):
N, K, S = map(int,input().split())

if K=0:
    print(1 for i in range(N))

else:
    ans = [S for a in range(K)]
    ain = [S+1 for a in range(N-K)]
    ans = ans + ain
    print(*ans)


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


ans = [S for a in range(K)]
if S == 10**9:
    ain = [1 for a in range(N-K)]
else:
    ain = [S+1 for a in range(N-K)]
ans = ans + ain
print(*ans)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A = []
ans =[]
for i in range(N):
    new = int(input())
    if new not in ans:
        ans.append(new)

    else:
        ans.remove(new)


print(len(ans))


Fixed submission:
N=int(input())
A = []

for i in range(N):
    new = int(input())
    A.append(new)

A.sort()
A.append(0)

start=A[0]
cnt=1
anscnt=0

for i in range(1,len(A)):

    if A[i]==start:
        cnt+=1
    elif A[i]!=start:
        if cnt%2==0:
            anscnt+=cnt
        elif cnt%2!=0:
            anscnt+=cnt-1    
        cnt=1
        start=A[i]


print(N-anscnt)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A = []
for i in range(N):
    A.append(int(input()))

ans =[]
for i in range(len(A)):
    if A[i] not in ans:
        ans.append(A[i])

    else:
        ans.remove(A[i])

print(len(ans))


Fixed submission:
N=int(input())
A = []

for i in range(N):
    new = int(input())
    A.append(new)

A.sort()
A.append(0)

start=A[0]
cnt=1
anscnt=0

for i in range(1,len(A)):

    if A[i]==start:
        cnt+=1
    elif A[i]!=start:
        if cnt%2==0:
            anscnt+=cnt
        elif cnt%2!=0:
            anscnt+=cnt-1    
        cnt=1
        start=A[i]


print(N-anscnt)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
N, C, K = list(map(int, input().split()))
listT = [int(input()) for _ in range(N)]

listT.sort()

def func(listT,bus):
    if len(listT)==0:
        print(bus)
        sys.exit()
    elif len(listT)<C:
        for j in range(1, len(listT)):
            if listT[j]-listT[0]>K:
                bus += 1
                return func(listT[j:],bus)
        bus += 1
        print(bus)
        sys.exit()

    elif len(listT)>=C:
        for i in range(1,C):

            if listT[i]-listT[0]>K:
                bus += 1
                return func(listT[i:],bus)

        bus += 1
        return func(listT[C:],bus)

func(listT,0)


Fixed submission:
import sys
N, C, K = list(map(int, input().split()))
listT = [int(input()) for _ in range(N)]

listT.sort(reverse = True)

count=0
while listT != []:
    bus =[]
    time = listT[0]
    count += 1
    while len(bus) != C and time - K <= listT[0]:
        bus.append(listT.pop(0))
        if listT ==[]:
            break

print(count)

Buggy python submission (verdict: Runtime Error):
import sys
N, C, K = list(map(int, input().split()))
listT = [int(input()) for _ in range(N)]

listT.sort()

def func(listT,bus):
    if len(listT)<2:
            print(bus+1)
            sys.exit()

    elif len(listT)>=2:
        for i in range(1,max(C,len(listT))):

            if listT[i]-listT[0]>K:
                bus += 1
                return func(listT[i:],bus)

        bus += 1

        if len(listT)<C:
            print(bus)
            sys.exit()


        return func(listT[C:],bus)

func(listT,0)


Fixed submission:
import sys
N, C, K = list(map(int, input().split()))
listT = [int(input()) for _ in range(N)]

listT.sort(reverse = True)

count=0
while listT != []:
    bus =[]
    time = listT[0]
    count += 1
    while len(bus) != C and time - K <= listT[0]:
        bus.append(listT.pop(0))
        if listT ==[]:
            break

print(count)
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N, K = map(int, input().split())
    p = list(map(int, input().split()))

    ans = 0
    max_i = 0
    max_value = 0
    for i in range(N):
        t = 0
        for k in range(i, i+K):
            if len(p) > k:
                t += p[k]
            else:
                break
        if max_value < t:
            max_value = t
            max_i = i

    for i in range(max_i, max_i+K):
        if len(p) <= i:
            break
        n = p[i] + 1
        ans += (n*(n-1)//2) / (n-1)
    
    print(ans)

if __name__ == '__main__':
    main()


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

    r = [0]
    for i in range(N):
        r.append(r[i]+p[i])


    ans = 0
    max_i = 0
    max_value = 0
    for i in range(1,N-K+1):
        t = r[i+K]-r[i]
        if max_value < t:
            max_value = t
            max_i = i



    for i in range(max_i, max_i+K):
        if len(p) <= i:
            break
        n = p[i] + 1
        ans += (n*(n-1)//2) / (n-1)
    
    print(ans)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N = int(input())
    P = list(map(int, input().split()))

    ans = 0
    for i in range(N):
        for j in reversed(range(0, i)):
            if P[j] < P[i]:
                break
        else:
            ans += 1
    print(ans)


if __name__ == '__main__':
    main()

Fixed submission:
def main():
    N = int(input())
    P = list(map(int, input().split()))

    ans = 1
    m = P[0]
    for i in range(1, N):
        if P[i] > m:
            continue
        m = min(m, P[i])
        ans += 1
    print(ans)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N, K, Q = map(int, input().split())
a = np.array([K for i in range(N)])

for i in range(Q):
    a -= 1
    a[int(input())-1] += 1

for i in range(N):
    if a[i] > 0:
        print('Yes')
    else:
        print('No')

Fixed submission:
N, K, Q = map(int, input().split())
A = [int(input()) for _ in range(Q)]
ans = [-Q] * N
for a in A:
    ans[a-1] += 1

for i in range(N):
    ans[i] += K
    if ans[i] > 0:
        print('Yes')
    else:
        print('No')
Buggy python submission (verdict: Runtime Error):
N = int(input())
N -= 1
ans = N * (1 + N) / 2
print(ans)

Fixed submission:
S = input()
T = input()
ans = 0
for i in range(3):
    if S[i] == T[i]:
        ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = [''.join(sorted(input())) for _ in range(N)]
ans = 0
for i in range(N):
    for j in range(i+1, N):
        if S[i] == S[j]:
            ans += 1
print(ans)

Fixed submission:
N = int(input())
S = [''.join(sorted(input())) for _ in range(N)]
ans = 0
dic = {}
for s in S:
    if s in dic:
        ans += dic[s]
        dic[s] += 1
    else:
        dic[s] = 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
mod = 10**9+7
N, M = map(int, input().split())
a = [int(input()) for _ in range(M)]

dp = [0] * (N + 1)
dp[:2] = 1, 1 if 1 not in a else 0

for i in range(2, N+1):
    if not i in a:
        dp[i] = (dp[i-1] + dp[i-2]) % mod
print(dp[-1])


Fixed submission:
mod = 10**9+7
N, M = map(int, input().split())
a = set(int(input()) for _ in range(M))

dp = [0] * (N + 1)
dp[:2] = 1, 1 if 1 not in a else 0

for i in range(2, N+1):
    # in listでは間に合わない
    if not i in a:
        dp[i] = (dp[i-1] + dp[i-2]) % mod
print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N, Q = map(int, input().split())
    S = input()
    ans = []
    for _ in range(Q):
        l, r = map(int, input().split())
        ans.append(S[l-1:r].count('AC'))

    for i in range(Q):
        print(ans[i])
if __name__ == '__main__':
    main()

Fixed submission:
def main():
    N, Q = map(int, input().split())
    S = list(input())

    templist = [0]
    for i in range(N-1):
        if S[i] == 'A' and S[i+1] == 'C':
            S[i] = 'a'
            templist.append(templist[-1]+1)
        else:
            templist.append(templist[-1])
    templist.append(templist[-1])

    ans = []
    for i in range(Q):
        l, r = map(int, input().split())
        ans.append(templist[r-1] - templist[l-1])
    for a in ans:
        print(a)
    
if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    S = input()
    t = len(list(S))
    while True:

        temp = S
        if '01' in S:
            S = S.replace('01', '')
        if '10' in S:
            S = S.replace('10', '')
        
        if temp == S:
            break
    print(t-len(list(S)))


if __name__ == '__main__':
    main()

Fixed submission:
def main():
    S = input()
    c0, c1 = 0, 0
    c0 = S.count('0')
    c1 = S.count('1')
    print(2*min(c0, c1))
    


if __name__ == '__main__':
    main()