Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):

def main():
    h,w,d = map(int,input().split())
    dic = {}
    for y in range(h):
        line = list(map(int,input().split()))
        for x in range(w):
            num = line[x]
            dic[num] = (x,y)
    Q = int(input())
    for q in range(Q):
        l,r = map(int,input().split())
        cst = 0
        while l != r:
            (x,y) = dic[l]
            (nx,ny) = dic[l+d]
            cst += abs(nx - x) + abs(ny - y)
            l += d
        print(cst)

if __name__ == '__main__':
    main()

Fixed submission:
h,w,d = map(int,input().split())
dic = {}

for y in range(h):
    line = list(map(int,input().split()))
    for x in range(w):
        num = line[x]
        dic[num] = (x,y)

com_sum = [0]*(h*w + 1)

for n in range(1,d+1):
    com_sum[n] = 0
    while n+d <= h*w:
        nx,ny = dic[n+d]
        x,y = dic[n]
        com_sum[n+d] = com_sum[n] + abs(nx-x) + abs(ny-y)
        n += d
    
Q = int(input())
for q in range(Q):
    l,r = map(int,input().split())
    print(com_sum[r] - com_sum[l])

Buggy python submission (verdict: Time Limit Exceeded):
h,w,d = map(int,input().split())
dic = {}

for y in range(h):
    line = list(map(int,input().split()))
    for x in range(w):
        num = line[x]
        dic[num] = (x,y)

Q = int(input())
for q in range(Q):
    l,r = map(int,input().split())
    cst = 0
    while l != r:
        (x,y) = dic[l]
        (nx,ny) = dic[l+d]
        cst += abs(nx - x) + abs(ny - y)
        l += d
    print(cst)

Fixed submission:
h,w,d = map(int,input().split())
dic = {}

for y in range(h):
    line = list(map(int,input().split()))
    for x in range(w):
        num = line[x]
        dic[num] = (x,y)

com_sum = [0]*(h*w + 1)

for n in range(1,d+1):
    com_sum[n] = 0
    while n+d <= h*w:
        nx,ny = dic[n+d]
        x,y = dic[n]
        com_sum[n+d] = com_sum[n] + abs(nx-x) + abs(ny-y)
        n += d
    
Q = int(input())
for q in range(Q):
    l,r = map(int,input().split())
    print(com_sum[r] - com_sum[l])

Buggy python submission (verdict: Time Limit Exceeded):
h,w,d = map(int,input().split())
dic = {}

for y in range(h):
    line = list(map(int,input().split()))
    for x in range(w):
        num = line[x]
        dic[num] = (x,y)

Q = int(input())
for q in range(Q):
    l,r = map(int,input().split())
    cst = 0
    while l != r:
        (x,y) = dic[l]
        (nx,ny) = dic[l+d]
        cst += abs(nx - x) + abs(ny - y)
        l += d
    print(cst)

Fixed submission:
h,w,d = map(int,input().split())
dic = {}

for y in range(h):
    line = list(map(int,input().split()))
    for x in range(w):
        num = line[x]
        dic[num] = (x,y)

com_sum = [0]*(h*w + 1)

for n in range(1,d+1):
    com_sum[n] = 0
    while n+d <= h*w:
        nx,ny = dic[n+d]
        x,y = dic[n]
        com_sum[n+d] = com_sum[n] + abs(nx-x) + abs(ny-y)
        n += d
    
Q = int(input())
for q in range(Q):
    l,r = map(int,input().split())
    print(com_sum[r] - com_sum[l])
Buggy python submission (verdict: Runtime Error):
b = int(input())
c = int(input())
x = int(input())

cnt = 0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if 500*i + 100*j + 50*k == x:
                cnt += 1
print(cnt)

Fixed submission:
a = int(input())
b = int(input())
c = int(input())
x = int(input())

cnt = 0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if 500*i + 100*j + 50*k == x:
                cnt += 1
print(cnt)
Buggy python submission (verdict: Runtime Error):
from math import ceil
k = int(input())
A = list(map(int,input().split()))[::-1]
if A[0]!=2:
    print(-1)
    exit()

flg = True
ans = [2,3]
for i in range(1, k):
    m = A[i]*(ceil(ans[0]/A[i]))
    n = A[i]*(ceil(ans[1]/A[i]))
    
    if not m<=ans[1]<=n:
        flg = False
        break
    else:
        ans = [m,n-1]

if flg:
    print(*ans)
else:
    print(-1)


Fixed submission:
def is_fin(x,y):
    if abs(x-y)==1:
        return False
    return True
n,a,b = map(int,input().split())
turn = 0
while is_fin(a,b):
    if turn%2==0:
        a += 1
    else:
        b -= 1
    turn += 1
print('Alice' if turn%2==1 else 'Borys')
Buggy python submission (verdict: Time Limit Exceeded):
def isprime(x):
    for i in range(2 , int(x**0.5)+1):
        if x%i == 0:
            return False
    return True
N = 10**5
lst = []
for x in range(2,N):
    if isprime(x):
        lst.append(x)

q = int(input())
ans = []

for i in range(q):
    cnt = 0
    l,r = map(int,input().split())
    for j in range(l,r+1,2):
        if j != 1 and j in lst and int((j+1)/2) in lst:
            cnt += 1
    ans.append(cnt)

for i in range(q):
    print(ans[i])

Fixed submission:

import math
def eratosthenes(n):
    prime = []
    limit = math.sqrt(n)
    data = [i+1 for i in range(1,n)]
    while True:
        p = data[0]
        if limit <= p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e%p != 0]

_primes = eratosthenes(10**5)
primes = [False] * (10**5+1)

for p in _primes:
    primes[p] = True

like_2017 = [False] * (10**5+1)
for p in _primes:
    if primes[(p+1)//2]:
        like_2017[p] = True

c = 0
C = [0]
for i in range(1,10**5+1):
    if like_2017[i]:
        c += 1
    C.append(c)

q = int(input())
for _ in range(q):
    l,r = map(int,input().split())
    print(C[r] - C[l-1])
Buggy python submission (verdict: Time Limit Exceeded):

n = int(input())
lst = [int(i) for i in input().split()]

typ = list(set(lst))
cnt = 0
for i in range(len(typ)):
    k = typ[i]
    c = lst.count(k)
    if c > k:
        cnt += c - k
    elif c < k:
        cnt += c
print(cnt)


Fixed submission:
from collections import Counter
n = int(input())
lst = Counter([int(i) for i in input().split()])

cnt = 0
for k,v in lst.items():
    if k < v:
        cnt += v-k
    elif k > v:
        cnt += v
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
lst = list(map(int,input().split()))

typ = list(set(lst))
NumList = []
for i in range(len(typ)):
    c = lst.count(typ[i])
    NumList.append([typ[i],c])
NumList.sort(key = lambda x:x[1])
cnt = 0
for i in range(len(typ) - k):
    cnt += NumList[i][1]
print(cnt)


Fixed submission:
from collections import Counter

n,k = map(int,input().split())
lst = list(map(int,input().split()))
typ = list(set(lst))

ans = 0
NumList = Counter(lst)
num = sorted(NumList.items(),key=lambda x:x[1])
for l in range(len(typ)-k):
    ans += num[l][1]
print(ans)
Buggy python submission (verdict: Runtime Error):
import numpy as np
n,c = map(int,input().split())
d = [0]*(10**5)
for _ in range(n):
    s,t,c = map(int,input().split())
    d[s-1] += 1
    d[t] -= 1
d = np.cumsum(d)
print(max(d))

Fixed submission:
import numpy as np
n,C = map(int,input().split())
ch = [[] for _ in range(30)]
for _ in range(n):
    s,t,c = map(int,input().split())
    if s>t:
        s,t = t,s
    ch[c-1].append((s,t))

lst = []
for i in range(30):
    if len(ch[i])!=0:    
        for i, (ns,nt) in enumerate(ch[i]):
            if i==0:
                s,t = ns, nt
            else:
                if ns == t:
                    t = nt
                else:
                    lst.append((s,t))
                    s,t = ns, nt
        else:
            lst.append((s,t))
    
d = [0]*(10**6)
for s,t in lst:
    d[s-1] += 1
    d[t] -= 1
d = np.cumsum(d)
print(min(max(d), C))
Buggy python submission (verdict: Time Limit Exceeded):

n = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]

A.sort()
B.sort()
C.sort()

cnt = 0
for i in range(n):
    for j in range(n):
        for k in range(n):
            if A[i] < B[j] < C[k]:
                cnt += 1

print(cnt)

Fixed submission:
import bisect

n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]

a = sorted(a)
b = sorted(b)
c = sorted(c)

ans = 0

for x in b:
    aa = bisect.bisect_left(a,x)
    cc = len(c) - bisect.bisect_right(c,x)
    ans += aa * cc

print(ans)
Buggy python submission (verdict: Runtime Error):
s = input()
t = input()

sl = len(s)
tl = len(t)

lst = []
for i in range(sl):
    if s[i] == t[0]:
        lst.append(i)
        
k = []

for i in lst:
    cnt = 0
    for j in range(tl):
        if s[i+j]==t[j] or s[i+j]=='?':
            cnt += 1
    if cnt == tl:
        ans = s[:i] + t + s[i+tl:]
        ans = ans.replace('?','a')
        k.append(ans)

if len(k)==0:
    print('UNRESTORABLE')
else:
    
    kk = sorted(k)
    print(kk[0])

Fixed submission:
s_dash = input()
t = input()
len_s = len(s_dash)
len_t = len(t)
candidates = set()

for i in range(len_s - len_t + 1):
    part_s = s_dash[i:i+len_t+1]
    flag = True
    for j,k in zip(part_s,t):
        if j=='?' or j==k:
            continue
        else:
            flag = False
            break
    if flag:
        candidates.add(s_dash[0:i].replace("?","a")+t+s_dash[i+len_t::].replace("?","a"))

ret = 'UNRESTORABLE'
if len(candidates)>0:
    ret = min(candidates)
print(ret)
Buggy python submission (verdict: Runtime Error):
n,K = map(int,input().split())
X, Y = [], []
dots = []
for _ in range(n):
    x,y = map(int,input().split())
    dots.append((x,y))
    X.append(x)
    Y.append(y)
X.sort()
Y.sort()
ans = float('inf')
for i in range(n):
    for j in range(i+1, n):
        for k in range(n):
            for l in range(k+1, l):
                x1,x2 = X[i], X[j]
                y1,y2 = Y[k], Y[l]
                cnt = 0
                for dot in dots:
                    if x1<=dot[0]<=x2 and y1<=dot[1]<=y2:
                        cnt += 1
                if cnt >= K:
                    ans = min(ans, (x2-x1)*(y2-y1))
print(ans)

Fixed submission:
n,K = map(int,input().split())
X, Y = [], []
dots = []
for _ in range(n):
    x,y = map(int,input().split())
    dots.append((x,y))
    X.append(x)
    Y.append(y)
X.sort()
Y.sort()
ans = float('inf')
for i in range(n):
    for j in range(i+1, n):
        for k in range(n):
            for l in range(k+1, n):
                x1,x2 = X[i], X[j]
                y1,y2 = Y[k], Y[l]
                cnt = 0
                for dot in dots:
                    if x1<=dot[0]<=x2 and y1<=dot[1]<=y2:
                        cnt += 1
                if cnt >= K:
                    ans = min(ans, (x2-x1)*(y2-y1))
print(ans)
Buggy python submission (verdict: Runtime Error):
def f(N,h,n):
    return 4/N - 1/h - 1/n

N = int(input())
for h in range(1, 3500):
    for n in range(1, 3500):
        inv_w = f(N, h, n)
        if inv_w > 0:
            w = 1/inv_w
            if w.is_integer() and 1<=w<=3500:
                ans = [h,n,int(w)]
                break
print(*ans)

Fixed submission:
N = int(input())
for h in range(1, 3501):
    for n in range(1, 3501):
        div = 4*h*n - N*(h+n)
        if div!=0 and N*h*n%div==0:
            w = N*h*n // div
            if w > 0:
                print(h,n,w)
                exit()

Buggy python submission (verdict: Runtime Error):
def f(N,h,n):
    return 4/N - 1/h - 1/n

N = int(input())
for h in range(1, 3501):
    for n in range(1, 3501):
        tmp = f(N, h, n)
        if tmp > 0:
            w = 1/tmp
            if w.is_integer():
                ans = [h,n,int(w)]
                break
print(*ans)

Fixed submission:
N = int(input())
for h in range(1, 3501):
    for n in range(1, 3501):
        div = 4*h*n - N*(h+n)
        if div!=0 and N*h*n%div==0:
            w = N*h*n // div
            if w > 0:
                print(h,n,w)
                exit()

Buggy python submission (verdict: Runtime Error):
def f(N,h,n):
    return 4/N - 1/h - 1/n

N = int(input())
for h in range(1, 5):
    for n in range(1, 5):
        tmp = f(N, h, n)
        if tmp != 0:
            w = 1/tmp
            if w.is_integer():
                ans = [h,n,int(w)]
                break
print(*ans)

Fixed submission:
N = int(input())
for h in range(1, 3501):
    for n in range(1, 3501):
        div = 4*h*n - N*(h+n)
        if div!=0 and N*h*n%div==0:
            w = N*h*n // div
            if w > 0:
                print(h,n,w)
                exit()
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
def warshall_floyd(g):
    for k in range(len(g)):
        for i in range(len(g)):
            for j in range(len(g)):
                g[i][j] = min(g[i][j], g[i][k]+g[k][j])
    return g

n,m,r = map(int,input().split())
lst = list(map(int,input().split()))
graph = [[float('inf')]*n for _ in range(n)]
for _ in range(m):
    a,b,c = map(int,input().split())
    graph[a-1][b-1] = c
    graph[b-1][a-1] = c
for i in range(n):
    graph[i][i] = 0
d = warshall_floyd(graph)

res = float('inf')
for l in itertools.permutations(lst):
    cnt = 0
    for i in range(1, len(l)):
        cnt += d[l[i-1]-1][l[i]-1]
    res = min(res, cnt)
print(res)

Fixed submission:
import itertools
def warshall_floyd(g):
    for k in range(len(g)):
        for i in range(len(g)):
            for j in range(len(g)):
                g[i][j] = min(g[i][j], g[i][k]+g[k][j])
    return g

n,m,r = map(int,input().split())
lst = list(map(int,input().split()))
graph = [[float('inf')]*n for _ in range(n)]
for _ in range(m):
    a,b,c = map(int,input().split())
    graph[a-1][b-1] = c
    graph[b-1][a-1] = c
for i in range(n):
    graph[i][i] = 0
d = warshall_floyd(graph)

res = float('inf')
for l in itertools.permutations(lst):
    cnt = 0
    for i in range(1, len(l)):
        cnt += d[l[i-1]-1][l[i]-1]
    res = min(res, cnt)
print(res)

Buggy python submission (verdict: Time Limit Exceeded):
def warshall_floyd(d,n):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k]+d[k][j])
    return d
    
n,m,r = map(int,input().split())
lstr = list(map(int,input().split()))

g = [[float("inf")]*n for _ in range(n)]
for i in range(m):
    a,b,c = map(int,input().split())
    g[a-1][b-1] = c
    g[b-1][a-1] = c

for i in range(n):
    g[i][i] = 0

gg = warshall_floyd(g,n)

ans = 0
dist = 0
max_dist = 0
pos = lstr[0]-1

for i in range(1,r):
    dist = gg[pos][lstr[i] - 1]
    max_dist = max(max_dist,dist)
    ans += dist
    pos = lstr[i] - 1

dist = gg[lstr[-1]-1][lstr[0]-1]
ans += dist
max_dist = max(max_dist,dist)

print(ans - max_dist)

Fixed submission:
import itertools
def warshall_floyd(g):
    for k in range(len(g)):
        for i in range(len(g)):
            for j in range(len(g)):
                g[i][j] = min(g[i][j], g[i][k]+g[k][j])
    return g

n,m,r = map(int,input().split())
lst = list(map(int,input().split()))
graph = [[float('inf')]*n for _ in range(n)]
for _ in range(m):
    a,b,c = map(int,input().split())
    graph[a-1][b-1] = c
    graph[b-1][a-1] = c
for i in range(n):
    graph[i][i] = 0
d = warshall_floyd(graph)

res = float('inf')
for l in itertools.permutations(lst):
    cnt = 0
    for i in range(1, len(l)):
        cnt += d[l[i-1]-1][l[i]-1]
    res = min(res, cnt)
print(res)
Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
lst = list(map(int,input().split()))
e,o = 0,0
for i in range(n):
    if lst[i]%2==0:
        e += 1
    else:
        o += 1

if o==0:
    if p==0:
        print(2**n)
    else:
        print(0)
else:
    print(2**(n-1))

Fixed submission:
n,k = map(int,input().split())
lst = list(map(int,input().split()))
e,o = 0,0
for i in range(n):
    if lst[i]%2==0:
        e += 1
    else:
        o += 1

if o==0:
    if k==0:
        print(2**n)
    else:
        print(0)
else:
    print(2**(n-1))
Buggy python submission (verdict: Runtime Error):
n,a,b = map(int,input().split())
if n==1:
  if a==b:
    print(1)
  else:
    print(0)
else:
  if b-a < 0:
    print(0)
  elif k==1:
    print(1)
  else:
    print(b*k - a*k+1)

Fixed submission:
n,a,b = map(int,input().split())
if n==1:
  if a==b:
    print(1)
  else:
    print(0)
else:
  k = b-a
  if k < 0:
    print(0)
  elif k==0:
    print(1)
  else:
    print((b-a)*(n-2)+1)
Buggy python submission (verdict: Runtime Error):
a,b,c = map(int,input().split())
lst = [a,b,c]
lst.sort()
res = True
if a==b-=c:
    print(-1)
else:
    while True:
        if a%2!=0 or b%2!=0 or c%2!=0:
            break
        else:
            res += 1
            nx_a = b//2 + c//2
            nx_b = a//2 + c//2
            nx_c = a//2 + b//2
            tmp = [nx_a, nx_b, nx_c]
            tmp.sort()
            if lst==tmp:
                print(-1)
                exit()
            a,b,c = nx_a, nx_b, nx_c
    print(res)

Fixed submission:
a,b,c = map(int,input().split())
res = 0
while True:
    if a%2!=0 or b%2!=0 or c%2!=0:
        break
    elif a==b==c:
        res = -1
        break
    else:
        res += 1
        a,b,c = (b+c)//2, (c+a)//2, (a+b)//2
print(res)
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 9)

N,W = map(int,input().split())
w = []
v = []
for _ in range(N):
    w_, v_ = map(int,input().split())
    w.append(w_)
    v.append(v_)

# dp[i][j]:iまでを用いて、重みjの時の最大値
dp = [[0]*(W+1) for _ in range(N+1)]

for i in range(N):
    for j in range(W+1):
        if w[i]<=j:
            dp[i+1][j] = max(dp[i][j], dp[i][j-w[i]]+v[i])
        dp[i+1][j] = max(dp[i][j], dp[i+1][j])
        
print(dp[N][W])

Fixed submission:
N,W = map(int,input().split())
tmpv = [[] for _ in range(4)]
w1 = None
for i in range(N):
    tw, tv = map(int,input().split())
    if i==0:
        w1 = tw
        tmpv[0].append(tv)
    else:
        tmpv[tw-w1].append(tv)

v = []
for tv in tmpv:
    v.append(sorted(tv, reverse=True)+[0])
    
ans = 0
for i in range(len(v[0])):
  for j in range(len(v[1])):
    for k in range(len(v[2])):
      for l in range(len(v[3])):
        tw = w1*i+(w1+1)*j+(w1+2)*k+(w1+3)*l
        tv = sum(v[0][:i]) + sum(v[1][:j]) + sum(v[2][:k]) + sum(v[3][:l])
        if tw<=W:
          ans = max(ans, tv)
print(ans)

Buggy python submission (verdict: Runtime Error):
N,W = map(int,input().split())
w = []
v = []
for _ in range(N):
    w_, v_ = map(int,input().split())
    w.append(w_)
    v.append(v_)

# dp[i][j]:iまでを用いて、重みjの時の最大値
dp = [[0]*(W+1) for _ in range(N+1)]

for i in range(N):
    for j in range(W+1):
        if w[i]<=j:
            dp[i+1][j] = max(dp[i][j], dp[i][j-w[i]]+v[i])
        dp[i+1][j] = max(dp[i][j], dp[i+1][j])
        
print(dp[N][W])

Fixed submission:
N,W = map(int,input().split())
tmpv = [[] for _ in range(4)]
w1 = None
for i in range(N):
    tw, tv = map(int,input().split())
    if i==0:
        w1 = tw
        tmpv[0].append(tv)
    else:
        tmpv[tw-w1].append(tv)

v = []
for tv in tmpv:
    v.append(sorted(tv, reverse=True)+[0])
    
ans = 0
for i in range(len(v[0])):
  for j in range(len(v[1])):
    for k in range(len(v[2])):
      for l in range(len(v[3])):
        tw = w1*i+(w1+1)*j+(w1+2)*k+(w1+3)*l
        tv = sum(v[0][:i]) + sum(v[1][:j]) + sum(v[2][:k]) + sum(v[3][:l])
        if tw<=W:
          ans = max(ans, tv)
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
lst = list(map(int,input().split()))

m = -1 #m=1:増加、m=2:減少
if n==1 or n==2:
    print(1)
else:
    cnt = 0
    num = lst[0]
    mode = 0
    for i in range(1,n):
        if mode==0:　# 待機
            if lst[i]==num:
                continue            
            elif lst[i] > num:
                mode = 1 # 増加
            elif lst[i] < num:
                mode = 2 # 減少
        elif mode == 1:
            if lst[i] < num:
                cnt += 1
                mode = 0
        elif mode == 2:
            if lst[i] > num:
                cnt += 1
                mode = 0
        num = lst[i]
    print(cnt + 1)

Fixed submission:
n = int(input())
lst = list(map(int,input().split()))
if n==1 or n==2:
    print(1)
else:
    cnt = 0
    num = lst[0]
    mode = 0
    for i in range(1,n):
        if mode==0:
            if lst[i]==num:
                continue            
            elif lst[i] > num:
                mode = 1
            elif lst[i] < num:
                mode = 2
        elif mode == 1:
            if lst[i] < num:
                cnt += 1
                mode = 0
        elif mode == 2:
            if lst[i] > num:
                cnt += 1
                mode = 0
        num = lst[i]
    print(cnt + 1)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
n = int(input())
A = sorted(list(map(int,input().split())))
c = Counter(A)
lst = list(c.values())
l,r = 0, len(lst)-1
while sum(lst) > len(lst):
    if lst[l] <= 1:
        l += 1
        continue
    else:
        if lst[r] <= 1:
            r -= 1
            continue
        else:
            lst[l] -= 1
            lst[r] -= 1
print(sum(lst))

Fixed submission:
from collections import Counter
n = int(input())
A = map(int,input().split())
k = len(Counter(A))
print(k if k%2!=0 else k-1)
Buggy python submission (verdict: Time Limit Exceeded):
k,s = map(int,input().split())

cnt = 0

for x in range(k+1):
    for y in range(k+1):
        for z in range(k+1):
            if x+y+z==s:
                cnt += 1
print(cnt)


Fixed submission:
k,s = map(int,input().split())

cnt = 0
for x in range(k+1):
    for y in range(k+1):
        z = s-x-y
        if 0 <= z <= k:
            cnt += 1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
k,s = map(int,input().split())

lst = []
for x in range(k+1):
    for y in range(x,k+1):
        for z in range(y,k+1):
            if x+y+z==s:
                lst.append((x,y,z))

cnt = 0
for e in lst:
    l = len(set(e))
    if l == 1:
        cnt += 1
    elif l == 3:
        cnt += 6
    else:
        cnt += 3

print(cnt)

Fixed submission:
k,s = map(int,input().split())

cnt = 0
for x in range(k+1):
    for y in range(k+1):
        z = s-x-y
        if 0 <= z <= k:
            cnt += 1
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
a,b,x = map(int,input().split())
cnt = 0
for i in range(a,b+1):
    if i%x == 0:
        cnt += 1
print(cnt)

Fixed submission:
def f(n,d):
    if n==-1:
        return 0
    return n//d+1

a,b,x = map(int,input().split())
print(f(b,x) - f(a-1,x))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
x,y = 1,1
for i in range(n):
    t,a = map(int,input().split())
    k = 0
    if x * a != y * t:
        while True:
            if t*k >= x and a*k >= y:
                break
            else:
                k += 1
        x = t * k
        y = a * k
print(x+y)

Fixed submission:
def ceil(x,y):
    if x%y==0:
        return x//y
    else:
        return (x//y) + 1

n = int(input())
T,A = 1,1
for _ in range(n):
    t,a = map(int,input().split())
    x = max(ceil(T,t),ceil(A,a))
    if x == 0:
        x = 1
    T,A = t*x,a*x
print(T+A)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
while 'ST' in s:
    s = s.replace('ST', '')
print(len(s))

Fixed submission:
x = input()
count_s = 0
ans = 0
for i in range(len(x)):
    if x[i] == 'S':
        count_s += 1
    if x[i] == 'T':
        if count_s == 0:
            ans += 1
        else:
            count_s -= 1
ans += count_s
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
while 'ST' in s:
    s = s.replace('ST', '')
print(len(s))

Fixed submission:
x = input()
count_s = 0
ans = 0
for i in range(len(x)):
    if x[i] == 'S':
        count_s += 1
    if x[i] == 'T':
        if count_s == 0:
            ans += 1
        else:
            count_s -= 1
ans += count_s
print(ans)