Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
Q = int(input())

def prime(n):
    # 素数列挙
    # nまでの素数をリストで返す(nを含む)
    primes = set(range(2, n+1))
    for i in range(2, int(n**0.5+1)):
        primes.difference_update(range(i*2, n+1, i))
    primes=list(primes)
    return primes

def count_num(n):
    cnt = 0
    prime_list = prime(n)
    prime_set = set(prime_list)
    for x in prime_list:
        if (x+1)//2 in prime_set:
            cnt += 1
    return cnt

for i in range(Q):
    l, r = map(int, input().split())
    print(count_num(r) - count_num(l-1))

Fixed submission:
from itertools import accumulate
Q = int(input())

def prime(n):
    # 素数列挙
    # nまでの素数をリストで返す(nを含む)
    primes = set(range(2, n+1))
    for i in range(2, int(n**0.5+1)):
        primes.difference_update(range(i*2, n+1, i))
    primes=list(primes)
    return primes

prime_set = set(prime(10**5))
ans = []

for i in range(10**5+1):
    if i%2 == 0:
        ans.append(0)
    else:
        if i in prime_set and (i+1)//2 in prime_set:
            ans.append(1)
        else:
            ans.append(0)
ans = list(accumulate(ans))

for i in range(Q):
    l, r = map(int, input().split())
    print(ans[r] - ans[l-1])
Buggy python submission (verdict: Runtime Error):
import sys
s = input()
t = input()
s.sort()
t.sort()
for x, y in zip(s, t[::-1]):
    if x > y:
        print('No')
        sys.exit()
    elif x == y:
        continue
    else:
        print('Yes')
        sys.exit()
if len(s) <= len(t):
    print('Yes')
else:
    print('No')

Fixed submission:
import math
a, b = map(int, input().split())
x = (a+b)/2
print(math.ceil(x))
Buggy python submission (verdict: Runtime Error):
import sys
s = input()
t = input()
s.sort()
t.sort()
for x, y in zip(s, t[::-1]):
    if x > y:
        print('No')
        sys.exit()
    elif x == y:
        continue
    else:
        print('Yes')
        sys.exit()
if len(s) <= len(t):
    print('Yes')
else:
    print('No')

Fixed submission:
s, t = list(input()), list(input())
s.sort()
t.sort(reverse=True)
S = ''.join(s)
T = ''.join(t)
if S < T:
    print('Yes')
else:
    print('No')

Buggy python submission (verdict: Runtime Error):
s, t = input(), input()
s.sort()
t.sort(reverse=True)
if s < t:
    print('Yes')
else:
    print('No')

Fixed submission:
s, t = list(input()), list(input())
s.sort()
t.sort(reverse=True)
S = ''.join(s)
T = ''.join(t)
if S < T:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
N, K = map(int, input().split())
A = [int(i) for i in input().split()]
B = set(A)
d = Counter(A)
num = len(B) - K
ans = 0
for i in range(1, num+1):
    ans += d.most_common()[-i][1]
print(ans)

Fixed submission:
from collections import Counter
N, K = map(int, input().split())
A = [int(i) for i in input().split()]
B = set(A)
d = Counter(A)
num = len(B) - K
ans = 0
c = d.most_common()
for i in range(1, num+1):
    ans += c[-i][1]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
N, K = map(int, input().split())
A = [int(i) for i in input().split()]
B = set(A)
d = Counter(A)
num = len(B) - K
ans = 0
for i in range(1, num+1):
    ans += d.most_common()[-i][1]
print(ans)

Fixed submission:
from collections import Counter
N, K = map(int, input().split())
A = [int(i) for i in input().split()]
B = set(A)
d = Counter(A)
num = len(B) - K
ans = 0
c = d.most_common()
for i in range(1, num+1):
    ans += c[-i][1]
print(ans)
Buggy python submission (verdict: Runtime Error):
N = input()
cur = 0
for x, y in zip(N, N[1:]):
    if x == y:
        ans += 1
if cur >= 2:
    print('Yes')
else:
    print('No')

Fixed submission:
N = input().strip()
if N[0] == N[1] == N[2] or N[1] == N[2] == N[3]:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
H, W = map(int, input().split())
c = [list(map(int, input().split())) for _ in range(10)]
A = [list(map(int, input().split())) for _ in range(H)]

for k in range(10):
    for i in range(10):
        for j in range(10):
            c[i][j] = min(c[i][j], c[i][k] + c[k][j])

ans = 0
for h in range(H):
    for w in range(W):
        uf A[h][w] != -1:
        ans += c[A[h][w]][1]
print(ans)

Fixed submission:
H, W = map(int, input().split())
c = [list(map(int, input().split())) for _ in range(10)]
A = [list(map(int, input().split())) for _ in range(H)]

for k in range(10):
    for i in range(10):
        for j in range(10):
            c[i][j] = min(c[i][j], c[i][k] + c[k][j])

ans = 0
for h in range(H):
    for w in range(W):
        if A[h][w] != -1:
            ans += c[A[h][w]][1]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
a, b = '', ''
for i in range(len(s)):
    if s[i] != 'x':
        a += s[i]
        b = s[i] + b
if a != b:
    print(-1)
ans = 0
while len(s) != 0:
    if s[0] == s[-1]:
        s = s[1:-1]
    elif s[0] == 'x' and s[-1] == 'x':
        if len(s) == 1:
            s = ''
        else:
            s = s[1:-1]
    elif s[0] == 'x':
        s = s[1:]
        ans += 1
    elif s[-1] == 'x':
        s = s[:-1]
        ans += 1
print(ans)

Fixed submission:
import sys
s = input()
a, b = '', ''
for i in range(len(s)):
    if s[i] != 'x':
        a += s[i]
        b = s[i] + b
if a != b:
    print(-1)
    sys.exit()
ans = 0
while len(s) != 0:
    if s[0] == s[-1]:
        s = s[1:-1]
    elif s[0] == 'x' and s[-1] == 'x':
        if len(s) == 1:
            s = ''
        else:
            s = s[1:-1]
    elif s[0] == 'x':
        s = s[1:]
        ans += 1
    elif s[-1] == 'x':
        s = s[:-1]
        ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
ok = False

for i in range(1, 3501):
    for j in range(1, 3501):
        w = (4/N - 1/i - 1/j)**-1
        if w > 0 and abs(int(w) - w) < 10**-7:
            print(i, j, int(w))
            ok = True
            break
    if ok:
        break

Fixed submission:
N = int(input())
ok = False

for i in range(1, 3501):
    for j in range(1, 3501):
        if N*(i+j) < 4*i*j:
            w = 1 / (4/N - 1/i - 1/j)
            if abs(int(w)-w) < 10**-7:
                print(i, j, int(w))
                ok = True
                break
    if ok:
        break

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
ok = False

for i in range(1, 3501):
    for j in range(1, 3501):
        if (4/N - 1/i - 1/j) > 0 and (4/N - 1/i - 1/j)**-1 == int((4/N - 1/i - 1/j)**-1) and int((4/N - 1/i - 1/j)**-1) <= 3500:
            print(i, j, int((4/N - 1/i - 1/j)**-1))
            ok = True
            break
    if ok:
        break

Fixed submission:
N = int(input())
ok = False

for i in range(1, 3501):
    for j in range(1, 3501):
        if N*(i+j) < 4*i*j:
            w = 1 / (4/N - 1/i - 1/j)
            if abs(int(w)-w) < 10**-7:
                print(i, j, int(w))
                ok = True
                break
    if ok:
        break
Buggy python submission (verdict: Time Limit Exceeded):
A, B, C, D, E, F = [int(i) for i in input().split()]
memo = {}

for a in range(31):
    for b in range(31):
        for c in range(101):
            for d in range(101):
                water = (100*A)*a + (100*B)*b
                sugar = C*c + D*d

                if (water + sugar) <= F and water > 0:
                    if sugar <= int(water*E/100):
                        density = 100*sugar/(water + sugar)
                        memo[density] = [water + sugar, sugar]

max_density = max(memo)
print(memo[max_density][0], memo[max_density][1])


Fixed submission:
A, B, C, D, E, F = [int(i) for i in input().split()]
memo = {}

for a in range(31):
    for b in range(31):
        for c in range(101):
            for d in range(101):
                water = (100*A)*a + (100*B)*b
                sugar = C*c + D*d

                if (water + sugar) <= F and water > 0:
                    if sugar <= int(water*E/100):
                        density = 100*sugar/(water + sugar)
                        memo[density] = [water + sugar, sugar]

max_density = max(memo)
print(memo[max_density][0], memo[max_density][1])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = []
for i in range(N):
    num = int(input())
    if num in A:
        A.remove(num)
    else:
        A.append(num)

print(len(A))

Fixed submission:
N = int(input())
A = [int(input()) for i in range(N)]
dic = {}
for i in A:
    if i in dic:
        dic[i] += 1
    else:
        dic[i] = 1
ans = 0
for i in dic.keys():
    if dic[i] % 2 == 1:
        ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
x, a, b = map(int, input().split())
if abs(x-a) < abs(x-b):
  print(A)
else:
  print(B)

Fixed submission:
x, a, b = map(int, input().split())
if abs(x-a) < abs(x-b):
  print('A')
else:
  print('B')
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
N = int(input())
A = [int(i) for i in input().split()]
A.sort(reverse=True)
d = defaultdict(int)
ls = []
for x in A:
    d[x] += 1
    if d[x] == 2:
        ls.append(x)
        if len(ls) == 2:
            break
    elif d[x] == 4:
        ls.append(x)
        break
if len(ls) == 2:
    print(ls[0]*ls[1])
else:

Fixed submission:
from collections import defaultdict
N = int(input())
A = [int(i) for i in input().split()]
A.sort(reverse=True)
d = defaultdict(int)
ls = []
for x in A:
    d[x] += 1
    if d[x] == 2:
        ls.append(x)
        if len(ls) == 2:
            break
    elif d[x] == 4:
        ls.append(x)
        break
if len(ls) == 2:
    print(ls[0]*ls[1])
else:
    print(0)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
N = int(input())
A = [int(i) for i in input().split()]
B = list(set(A))
B.sort(reverse=True)
ls = []
for x in B:
    num = A.count(x)
    if num >= 2:
        ls.append(x)
        if len(ls) == 2:
            break
        if num >= 4:
            print(x**2)
            sys.exit()
if len(ls) == 2:
    print(ls[0]*ls[1])
else:
    print(0)

Fixed submission:
from collections import defaultdict
N = int(input())
A = [int(i) for i in input().split()]
A.sort(reverse=True)
d = defaultdict(int)
ls = []
for x in A:
    d[x] += 1
    if d[x] == 2:
        ls.append(x)
        if len(ls) == 2:
            break
    elif d[x] == 4:
        ls.append(x)
        break
if len(ls) == 2:
    print(ls[0]*ls[1])
else:
    print(0)
Buggy python submission (verdict: Runtime Error):
s = input()
print(s[0]+str(len(s)+s[-1]))

Fixed submission:
s = input()
print(s[0]+str(len(s)-2)+s[-1])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(i) for i in input().split()]
b = []
for i in range(n):
    b.append(a[i])
    b.reverse()
print(*b)

Fixed submission:
from collections import deque
n = int(input())
a = [int(i) for i in input().split()]
b = deque()
for i, x in enumerate(a):
    if i%2 == n%2:
        b.append(x)
    else:
        b.appendleft(x)
print(*b)
Buggy python submission (verdict: Time Limit Exceeded):
# 2019/6/25
import sys
N = int(input())
a = []
for i in range(N):
    a.append(int(input()))
s = set()
cur = 1
ans = 0
while not cur in s:
    if a[cur-1] == 2:
        print(ans+1)
        sys.exit()
    else:
        cur = a[cur-1]
        ans += 1
print(-1)

Fixed submission:
# 2019/6/25
import sys
N = int(input())
a = []
for i in range(N):
    a.append(int(input()))
if not 2 in a:
    print(-1)
    sys.exit()
s = set()
cur = 1
ans = 0
while not cur in s:
    if a[cur-1] == 2:
        print(ans+1)
        sys.exit()
    else:
        s.add(cur)
        cur = a[cur-1]
        ans += 1
print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N, A, B = map(int, input().split())
h = []
for i in range(N):
    h.append(int(input()))
H = np.array(h)
ans = 0
while len(H[H>0]):
    H = H - B
    H[np.argmax(H)] -= (A-B)
    ans += 1
print(ans)


Fixed submission:
import numpy as np
N, A, B = map(int, input().split())
h = []
for i in range(N):
    h.append(int(input()))
H = np.array(h)

def test(n):
    x = H - n*B
    x[x<0] = 0
    return np.ceil(x/(A-B)).sum() <= n

left = 0
right = 10**9

while right - left > 1:
    mid = (left + right)//2
    if test(mid):
        right = mid
    else:
        left = mid
ans = right
print(ans)
Buggy python submission (verdict: Runtime Error):
N, M = [int(i) for i in input().strip().split()]
A = [[int(i) for i in input().strip().split()] for j in range(M)]
B = {}
for i in range(N):
    for j in range(M):
        if A[j][0] == i+1:
            B[i] = A[j][1]
for i in range(N):
    print(len(B[i]))

Fixed submission:
N, M = [int(i) for i in input().strip().split()]
A=[]
for i in range(M):
    A.append(input().strip().split())
B =[]
for i in range(M):
    B.append(int(A[i][0]))
    B.append(int(A[i][1]))
for i in range(N):
    print(B.count(i+1))
Buggy python submission (verdict: Runtime Error):
N, K = [int(i) for i in input().split()]
a = [0]*N
b = [0]*N
for i in range(N):
    a[i], b[i] = [int(i) for i in input().split()]

c = 0
d = 0
for i in b:
    c += i
    if c >= K:
        break
    d += 1
    
A = []
for i in range(d):
    A += [a[i]]*b[i]
A.sort()
print(A[K])

Fixed submission:
N, K = map(int, input().split())
a = []
for i in range(N):
    a.append(list(map(int, input().split())))
a.sort()
sum = 0
for i, x in enumerate(a):
    sum += x[1]
    if sum >= K:
        print(a[i][0])
        break
Buggy python submission (verdict: Runtime Error):
A, B, C = [int(i) for i in input().split()]

for i in range(B):
    if (A*i)%B == C:
      	print('YES')
        break
else:
  	print('NO')

Fixed submission:
A, B, C = [int(i) for i in input().split()]

for i in range(B):
    if (A*i)%B == C:
        print('YES')
        break
else:
    print('NO')

Buggy python submission (verdict: Runtime Error):
A, B, C = [int(i) for i in input().split()]
a = 0

for i in range(1,B):
    if A*i%B == C:
      	a += 1
        print('YES')
if a != 0:
    print('NO')

Fixed submission:
A, B, C = [int(i) for i in input().split()]

for i in range(B):
    if (A*i)%B == C:
        print('YES')
        break
else:
    print('NO')
Buggy python submission (verdict: Runtime Error):
o = input().strip()
e = input().strip()

a = ''

if len(o)-len(e) == 0:
    for i in range(len(o)):
        a += o[i]
        a += e[i]
    print(a)
else:
    for i in range(len(e)):
        a += o[i]
        a += e[i]
    a += o[len(o)]
    print(a)

Fixed submission:
o = input().strip()
e = input().strip()

a = ''

if len(o)-len(e) == 0:
    for i in range(len(o)):
        a += o[i]
        a += e[i]
    print(a)
else:
    for i in range(len(e)):
        a += o[i]
        a += e[i]
    a += o[len(o)-1]
    print(a)
Buggy python submission (verdict: Runtime Error):
N, M = [int(i) for i in input().split().strip()]
A = [[int(i) for i in input().split().strip()] for j in range(N)]
C = [[int(i) for i in input().split().strip()] for j in range(M)]

ls1 = []
for i in range(N):
    ls2 = []
    for j in range(M):
        ls2.append(abs(A[i][0] - C[j][0]) + abs(A[i][1] - C[j][1]))
    a = min(ls2)
    ls1.append(ls2.index(a))
for i in ls1:
    print(i)

Fixed submission:
N, M = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()] for j in range(N)]
C = [[int(i) for i in input().split()] for j in range(M)]

ls1 = []
for i in range(N):
    ls2 = []
    for j in range(M):
        ls2.append(abs(A[i][0] - C[j][0]) + abs(A[i][1] - C[j][1]))
    a = min(ls2)
    ls1.append(ls2.index(a))
for i in ls1:
    print(i+1)
Buggy python submission (verdict: Runtime Error):
s = input().strip()

a = []
b = []

for i in range(len(s)):
    if s[i] == 'A':
        a.append(i)
    elif s[i] == 'Z':
        b.append(i)
print(b.max()-a.min()+1)


Fixed submission:
s = input().strip()

a = []
b = []

for i in range(len(s)):
    if s[i] == 'A':
        a.append(i)
    elif s[i] == 'Z':
        b.append(i)
print(max(b)-min(a)+1)

Buggy python submission (verdict: Runtime Error):
s = input().strip()

a = 0
b = 0

for i in s:
    if s[i] == 'A':
        a = i
    elif s[i] == 'Z':
        b = i
print(b-a+1)


Fixed submission:
s = input().strip()

a = []
b = []

for i in range(len(s)):
    if s[i] == 'A':
        a.append(i)
    elif s[i] == 'Z':
        b.append(i)
print(max(b)-min(a)+1)
Buggy python submission (verdict: Time Limit Exceeded):
#全探索(多分TLE)
K, S = map(int, input().split())

ans = 0

for i in range(K+1):
    for j in range(K+1):
        for k in range(K+1):
            if i+j+k == S:
                ans += 1
print(ans)

Fixed submission:
K, S = map(int, input().split())
ans = 0
for x in range(K+1):
    for y in range(K+1):
        if S >= x+y and S-(x+y) <= K:
            ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
0 0 1 2

Fixed submission:
sx, sy, tx, ty = map(int, input().split())

ans = ''
if sx <= tx and sy <= ty:
    ans += 'R'*abs(sx-tx) + 'U'*abs(sy-ty) + 'L'*abs(sx-tx) + 'D'*abs(sy-ty)
    ans += 'L' + 'U'*(abs(ty-sy)+1) + 'R'*(abs(tx-sx)+1) + 'D'
    ans += 'R' + 'D'*(abs(ty-sy)+1) + 'L'*(abs(tx-sx)+1) + 'U'
    print(ans)
elif sx > tx and sy <= ty:
    ans += 'L'*abs(sx-tx) + 'U'*abs(sy-ty) + 'R'*abs(sx-tx) + 'D'*abs(sy-ty)
    ans += 'R' + 'U'*(abs(ty-sy)+1) + 'L'*(abs(tx-sx)+1) + 'D'
    ans += 'L' + 'D'*(abs(ty-sy)+1) + 'R'*(abs(tx-sx)+1) + 'U'
    print(ans)
elif sx > tx and sy > ty:
    ans += 'L'*abs(sx-tx) + 'D'*abs(sy-ty) + 'R'*abs(sx-tx) + 'U'*abs(sy-ty)
    ans += 'R' + 'D'*(abs(ty-sy)+1) + 'L'*(abs(tx-sx)+1) + 'U'
    ans += 'L' + 'U'*(abs(ty-sy)+1) + 'R'*(abs(tx-sx)+1) + 'D'
    print(ans)
elif sx <= tx and sy > ty:
    ans += 'R'*abs(sx-tx) + 'D'*abs(sy-ty) + 'L'*abs(sx-tx) + 'U'*abs(sy-ty)
    ans += 'L' + 'D'*(abs(ty-sy)+1) + 'R'*(abs(tx-sx)+1) + 'U'
    ans += 'R' + 'U'*(abs(ty-sy)+1) + 'L'*(abs(tx-sx)+1) + 'D'
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
a, b, x = [int(i) for i in input().split()]
c = 0
d = 0
while c <= b:
    if a <= c:
        d += 1
    c += x
print(d)

Fixed submission:
a, b, x = map(int, input().split())
if a%x == 0:
    print((b//x+1) - (a//x))
else:
    print((b//x+1) - (a//x+1))
Buggy python submission (verdict: Runtime Error):
import sys
import heapq
K, T = map(int, input().split())
m = [-int(i) for i in input().split()]
heapq.heapify(m)

if T == 1:
    print(K-1)
    sys.exit()

while len(m) > 0:
    l = heapq.heappop(m)
    if len(m) == 0:
        heapq.heappush(m, l)
        break
    r = heapq.heappop(m)
    if r+1 == 0:
        continue
    else:
        heapq.heappush(m, l+1)
        heapq.heappush(m, r+1)
print(-m[0])

Fixed submission:
import sys
import heapq
K, T = map(int, input().split())
m = [-int(i) for i in input().split()]
heapq.heapify(m)

if T == 1:
    print(K-1)
    sys.exit()

while len(m) > 1:
    l = heapq.heappop(m)
    r = heapq.heappop(m)
    if r+1 != 0:
        heapq.heappush(m, l+1)
        heapq.heappush(m, r+1)
    else:
        if l+1 != 0:
            heapq.heappush(m, l+1)
if len(m) == 0:
    print(0)
else:
    print(-m[0]-1)
Buggy python submission (verdict: Runtime Error):
import sys
import math
import bisect
import heapq
import copy
from fractions import gcd
from itertools import permutations, combinations,combinations_with_replacement,product
from collections import defaultdict, Counter, deque

N = int(input())
T, A = [0]*N, [0]*N
for i in range(N):
    T[i], A[i] = map(int, input().split())
a, b = T[0], A[0]
if N == 1:
    print(a+b)
else:
    for x, y in zip(T[1:], A[1:]):
        c = max((a11)//(x+1), (b-1)/(y+1))
        a, b = x*c, y*c
    print(a+b)

Fixed submission:
import sys
import math
import bisect
import heapq
import copy
from fractions import gcd
from itertools import permutations, combinations,combinations_with_replacement,product
from collections import defaultdict, Counter, deque

N = int(input())
T, A = [0]*N, [0]*N
for i in range(N):
    T[i], A[i] = map(int, input().split())
a, b = T[0], A[0]
if N == 1:
    print(a+b)
else:
    for x, y in zip(T[1:], A[1:]):
        c = max((a-1)//x+1, (b-1)//y+1)
        a, b = x*c, y*c
    print(a+b)

Buggy python submission (verdict: Runtime Error):
import sys
import math
import bisect
import heapq
import copy
from fractions import gcd
from itertools import permutations, combinations,combinations_with_replacement,product
from collections import defaultdict, Counter, deque

N = int(input())
T, A = [0]*N, [0]*N
for i in range(N):
    T[i], A[i] = map(int, input().split())
a, b = 1, 1
else:
    for x, y in zip(T, A):
        if a>x or b>y:
            c = max(math.ceil(a/x), math.ceil(b/y))
            a, b = x*c, y*c
        else:
            a, b = x, y
    print(a+b)

Fixed submission:
import sys
import math
import bisect
import heapq
import copy
from fractions import gcd
from itertools import permutations, combinations,combinations_with_replacement,product
from collections import defaultdict, Counter, deque

N = int(input())
T, A = [0]*N, [0]*N
for i in range(N):
    T[i], A[i] = map(int, input().split())
a, b = T[0], A[0]
if N == 1:
    print(a+b)
else:
    for x, y in zip(T[1:], A[1:]):
        c = max((a-1)//x+1, (b-1)//y+1)
        a, b = x*c, y*c
    print(a+b)
Buggy python submission (verdict: Runtime Error):
s = input()
cnt = 0
cnt_set = 0
for x in S:
    if x == 'S':
        cnt += 1
    else:
        if cnt > 0:
            cnt_set += 1
            cnt -= 1
print(len(s)-2*cnt_set)

Fixed submission:
s = input()
cnt = 0
cnt_set = 0
for x in s:
    if x == 'S':
        cnt += 1
    else:
        if cnt > 0:
            cnt_set += 1
            cnt -= 1
print(len(s)-2*cnt_set)
Buggy python submission (verdict: Runtime Error):
import sys

S = input()
if len(S) == 1:
    print(int(S))
    sys.exit()

ls = []
a = [0, 1]
for i in itertools.product(a, repeat=len(S)-1):
    ans = 0
    start = 0
    for j, x in enumerate(i):
        if x == 1:
            ans += int(S[start:j+1])
            start = j + 1
    ans += int(S[start:len(S)])
    ls.append(ans)
print(sum(ls))


Fixed submission:
import sys

S = input()
if len(S) == 1:
    print(int(S))
    sys.exit()

ls = []
for i in range(1<<(len(S)-1)):
    ans = 0
    num = format(i, 'b').zfill(len(S)-1)
    start = 0
    for (j, x) in enumerate(num):
        if x == '1':
            ans += int(S[start:j+1])
            start = j + 1
    ans += int(S[start:len(S)])
    ls.append(ans)
print(sum(ls))
Buggy python submission (verdict: Runtime Error):
import sys
s = input()
for i, (x, y) in enumerate(zip(s, s[1:])):
    if x == y:
        print(i+1, i+2)
        sys.exit()
if len(s) == 2:
    print(-1, -1)
for i, (x, y, z) in enumerate(zip(s, s[1:], s[2])):
    if x == z:
        print(i+1, i+3)
        sys.exit()
print(-1, -1)

Fixed submission:
import sys
s = input()
for i, (x, y) in enumerate(zip(s, s[1:])):
    if x == y:
        print(i+1, i+2)
        sys.exit()
if len(s) <= 2:
    print(-1, -1)
    sys.exit()
for i, (x, y, z) in enumerate(zip(s, s[1:], s[2:])):
    if x == z:
        print(i+1, i+3)
        sys.exit()
print(-1, -1)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

mod = 10**9+7
ans = 0
for i in range(N-1):
    ans += A[i] * sum(A[i+1:]) % mod
    ans = ans%mod
    
print(ans)

Fixed submission:

from itertools import accumulate
N = int(input())
A = list(map(int, input().split()))
B = list(accumulate(A))
mod = 10**9+7
ans = 0
sumA = sum(A)

for i in range(N-1):
    ans += A[i] * (sumA-B[i]) % mod
    ans = ans%mod
    
print(ans)