Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations
n, k = map(int, input().split())
xy = []
xx = []
yy = []
for _ in range(n):
    x, y = map(int, input().split())
    xy.append((x, y))
    xx.append(x)
    yy.append(y)
xx.sort()
yy.sort()
ans = 10**20
for x1, x2 in combinations(xx, 2):
    for y1, y2 in combinations(yy, 2):
        tmp = 0
        for x, y in xy:
            if x1<=x<=x2 and y1<=y<=y2:
                tmp += 1
        if tmp<k:
            continue
        ans = min(ans, (x2-x1)*(y2-y1))
print(ans)

Fixed submission:
from itertools import combinations
n, k = map(int, input().split())
xy = []
xx = []
yy = []
for _ in range(n):
    x, y = map(int, input().split())
    xy.append((x, y))
    xx.append(x)
    yy.append(y)
xx.sort()
yy.sort()
ans = 10**20
for x1, x2 in combinations(xx, 2):
    for y1, y2 in combinations(yy, 2):
        tmp = 0
        for x, y in xy:
            if x1<=x<=x2 and y1<=y<=y2:
                tmp += 1
        if tmp<k:
            continue
        ans = min(ans, (x2-x1)*(y2-y1))
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
xy = []
for i in range(n):
    x, y = map(int, input().split())
    xy.append((i, x, y))
xx = sorted(xy, key=lambda x:x[1])
yy = sorted(xy, key=lambda x:x[2])
li = []
for i in range(n-1):
    li.append((xx[i][0], xx[i+1][0], xx[i+1][1]-xx[i][1]))
    li.append((yy[i][0], yy[i+1][0], yy[i+1][2]-yy[i][2]))
li.sort(key=lambda x:x[2])
class UnionFind():
    def __init__(self, li):
        self.li = li
    def root(self, x):
        if self.li[x]==x:
            return x
        self.li[x] = self.root(self.li[x])
        return self.li[x]
    def unite(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        if rx==ry:
            return
        self.li[ry] = rx
    def same(self, x, y):
        return self.root(x)==self.root(y)
uf = UnionFind(list(range(n)))
ans = 0
for x, y, cost in li:
    if uf.same(x, y):
        continue
    uf.unite(x, y)
    ans += cost
print(ans)

Fixed submission:
import sys
sys.setrecursionlimit(10**5)
n = int(input())
xy = []
for i in range(n):
    x, y = map(int, input().split())
    xy.append((i, x, y))
xx = sorted(xy, key=lambda x:x[1])
yy = sorted(xy, key=lambda x:x[2])
li = []
for i in range(n-1):
    li.append((xx[i][0], xx[i+1][0], xx[i+1][1]-xx[i][1]))
    li.append((yy[i][0], yy[i+1][0], yy[i+1][2]-yy[i][2]))
li.sort(key=lambda x:x[2])
class UnionFind():
    def __init__(self, li):
        self.li = li
    def root(self, x):
        if self.li[x]==x:
            return x
        self.li[x] = self.root(self.li[x])
        return self.li[x]
    def unite(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        if rx==ry:
            return
        self.li[ry] = rx
    def same(self, x, y):
        return self.root(x)==self.root(y)
uf = UnionFind(list(range(n)))
ans = 0
for x, y, cost in li:
    if uf.same(x, y):
        continue
    uf.unite(x, y)
    ans += cost
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
colors = [0]*9
for i in a:
    colors[i//400] += 1

mi = 0
for i in range(8):
    if colors[i]>0:
        mi += 1

print(mi, min(mi+colors[-1], 8))

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
colors = [0]*9
for i in a:
    colors[min(i//400, 8)] += 1

mi = 0
for i in range(8):
    if colors[i]>0:
        mi += 1
if mi==0:
    mi = 1
    ma = colors[-1]
else:
    ma = mi+colors[-1]
print(mi, ma)
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
nnode = [0]*n
for _ in range(n):
    a, b = map(int, input().split())
    nnode[a-1] += 1
    nnode[b-1] += 1
for i in nnode:
    if i%2==1:
        print('NO')
        break
else:
    print('YES')

Fixed submission:
n, m = map(int, input().split())
nnode = [0]*n
for _ in range(m):
    a, b = map(int, input().split())
    nnode[a-1] += 1
    nnode[b-1] += 1
for i in nnode:
    if i%2==1:
        print('NO')
        break
else:
    print('YES')
Buggy python submission (verdict: Runtime Error):
N = int(input())
X = int(input())
T = int(input())
if N % X == 0 :
  print((N/X)*T)
else :
  print(((N/X)+1)*T)

Fixed submission:
N, X, T = map(int,input().split())
print(-(-N // X) * T)
Buggy python submission (verdict: Time Limit Exceeded):
def get_ints():
  return list(map(int,input().split()))

n = int(input())
a = get_ints()
b = get_ints()

cnt = [0]*(n+1)
for x in a+b:
  cnt[x] += 1

q = [set() for i in range(n+1)]
for i in range(1,n+1):
  if cnt[i] > n:
    print('No')
    exit(0)
  q[cnt[i]].add(i)
print('Yes')

list_a = [[] for i in range(n+1)]
cnt_a = {}
for i in range(n):
  list_a[a[i]].append(i)
  if a[i] not in cnt_a:
    cnt_a[a[i]] = 1
  else:
    cnt_a[a[i]] += 1

list_b = [[] for i in range(n+1)]
cnt_b = {}
for i in range(n):
  list_b[b[i]].append(i)
  if b[i] not in cnt_b:
    cnt_b[b[i]] = 1
  else:
    cnt_b[b[i]] += 1

def get_any(cnt_, x):
  for key in cnt_.keys():
    if key != x:
      return key
  assert False

ans = [-1]*n

for i in range(n,0,-1):
  s = list(q[i])
  x,y = 0,0
  if len(s) == 0:
    x = get_any(cnt_a, -1)
    y = get_any(cnt_b, x)
  elif len(s) == 1:
    x = s[0]
    if len(list_a[x]) == 0: # b kara
      y = x
      x = get_any(cnt_a, y)
    else: # a kara
      y = get_any(cnt_b, x)
  else: # 2
    x,y = s
    if len(list_a[x]) == 0:
      x,y = y,x

  ans[list_a[x].pop()] = y
  list_b[y].pop()
  def update_cnt(cnt_, x):
    cnt_[x] -= 1
    if cnt_[x] == 0:
      del cnt_[x]
  def use(x):
    q[cnt[x]].remove(x)
    cnt[x] -= 1
    q[cnt[x]].add(x)
  update_cnt(cnt_a, x)
  update_cnt(cnt_b, y)
  use(x)
  use(y)

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

Fixed submission:
def get_ints():
  return list(map(int,input().split()))

n = int(input())
a = get_ints()
b = get_ints()

cnt = [0]*(n+1)
for x in a+b:
  cnt[x] += 1

q = [set() for i in range(n+1)]
for i in range(1,n+1):
  if cnt[i] > n:
    print('No')
    exit(0)
  q[cnt[i]].add(i)
print('Yes')

def make_cnt(a):
  cnt_ = {}
  for i in range(n):
    if a[i] not in cnt_:
      cnt_[a[i]] = [i]
    else:
      cnt_[a[i]].append(i)
  return cnt_

cnt_a = make_cnt(a)
cnt_b = make_cnt(b)

def get_any(cnt_, x):
  for key in cnt_.keys():
    if key != x:
      return key
  assert False

ans = [-1]*n

for i in range(n,0,-1):
  s = list(q[i])
  x,y = 0,0
  if len(s) == 0:
    x = get_any(cnt_a, -1)
    y = get_any(cnt_b, x)
  elif len(s) == 1:
    x = s[0]
    if x not in cnt_a: # b kara
      y = x
      x = get_any(cnt_a, y)
    else: # a kara
      y = get_any(cnt_b, x)
  else: # 2
    x,y = s
    if x not in cnt_a:
      x,y = y,x

  ans[cnt_a[x][-1]] = y
  def update_cnt(cnt_, x):
    cnt_[x].pop()
    if len(cnt_[x]) == 0:
      del cnt_[x]
  def use(x):
    q[cnt[x]].remove(x)
    cnt[x] -= 1
    q[cnt[x]].add(x)
  update_cnt(cnt_a, x)
  update_cnt(cnt_b, y)
  use(x)
  use(y)

print(' '.join(map(str,ans)))
Buggy python submission (verdict: Runtime Error):
a,b=list(map(int,input().split()))
print('Yey!' if (a<=8&&b<=8) else ':(')

Fixed submission:
a,b=map(int,input().split())
print('Yay!' if (a<=8 and b<=8) else ':(')
Buggy python submission (verdict: Time Limit Exceeded):
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.par = [-1]*n 
    def find(self, x):
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)      
        if x==y:
            return        
        if self.par[x] > self.par[y]:
            x, y = y, x       
        self.par[x] += self.par[y]
        self.par[y] = x
    def size(self, x):
        return -self.par[self.find(x)]
    def same(self, x, y):
        return self.find(x) == self.find(y)
    def members(self, x):
        root = self.find(x)
        return len([i for i in range(self.n) if self.find(i) == root])
    def roots(self):
        return [i for i, x in enumerate(self.par) if x<0]

N, M = map(int, input().split())
UF = UnionFind(N)
for _ in range(M):
  a, b = map(int, input().split())
  UF.union(a-1, b-1)
Roots = UF.roots()
print(max(UF.members(R) for R in Roots))

Fixed submission:
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.par = [-1]*n 
    def find(self, x):
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)      
        if x==y:
            return        
        if self.par[x] > self.par[y]:
            x, y = y, x       
        self.par[x] += self.par[y]
        self.par[y] = x
    def size(self, x):
      if self.par[x]<0:
        return -self.par[x]
      else:
        return 0

N, M = map(int, input().split())
UF = UnionFind(N)
for _ in range(M):
  a, b = map(int, input().split())
  UF.union(a-1, b-1)
result = 0
for i in range(N):
  s = UF.size(i)
  if s>0:
    result = max(result, s)
print(result)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
X = [A[0]]
for i in range(1, N):
  if A[i] != A[i-1]:
    X.append(A[i])
B, C = [], []
n = len(X)
status = 0
result = 1000
now_m = 1000
k = 0
if X[0]>X[1]:
  B.append(0)
else:
  C.append(0)
for i in range(1, n-1):
  if X[i-1]<X[i] and X[i]>X[i+1]:
    B.append(i)
for i in range(1, n-1):
  if X[i-1]>X[i] and X[i]<X[i+1]:
    C.append(i)
if X[n-2]<X[n-1]:
  B.append(n-1)
else:
  C.append(n-1)
S = set(B+C)
for s in S:
    if status==0:
        k = now_m//X[s]
        now_m -= k*X[s]
        status = 1
    else:
        now_m += k*X[s]
        result = max(result, now_m)
        k = 0
        status = 0
print(result)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
X = [A[0]]
for i in range(1, N):
  if A[i] != A[i-1]:
    X.append(A[i])
S = []
n = len(X)
if n==1:
  print(1000)
else:
  status = 0
  result = 1000
  now_m = 1000
  k = 0
  if X[0]<X[1]:
    S.append(0)
  for i in range(1, n-1):
    if (X[i-1]<X[i] and X[i]>X[i+1]) or (X[i-1]>X[i] and X[i]<X[i+1]):
      S.append(i)
  if X[n-2]<X[n-1]:
    S.append(n-1)
  for s in S:
    if status==0:
        k = now_m//X[s]
        result = max(result, now_m)
        now_m -= k*X[s]
        status = 1
    else:
        now_m += k*X[s]
        result = max(result, now_m)
        k = 0
        status = 0
  print(result)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = tuple(map(int, input().split()))
Q = int(input())
Bs = [tuple(tuple(map(int, input().split()))) for i in range(Q)]
X = [0]
for i in range(1, 100001):
  X.append(A.count(i))
S = sum(A)
for B in Bs:
  S += X[B[0]]*(B[1]-B[0])
  X[B[1]] += X[B[0]]
  X[B[0]] = 0
  print(S)

Fixed submission:
n = int(input())
A = list(map(int, input().split()))
S = sum(A)
D = {c:0 for c in range(1, 10**5+1)}
for a in A:
  D[a] += 1
for _ in range(int(input())):
  B, C = map(int, input().split())
  S += (C-B)*D[B]
  D[C] += D[B]
  D[B] = 0
  print(S)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int, input().split()))
Q = int(input())
Bs = [[int(j) for j in input().split()] for i in range(Q)]
X = [0]
for i in range(1, 100001):
  X.append(A.count(i))
S = sum(A)
for B in Bs:
  S += X[B[0]]*(B[1]-B[0])
  X[B[1]] += X[B[0]]
  X[B[0]] = 0
  print(S)

Fixed submission:
n = int(input())
A = list(map(int, input().split()))
S = sum(A)
D = {c:0 for c in range(1, 10**5+1)}
for a in A:
  D[a] += 1
for _ in range(int(input())):
  B, C = map(int, input().split())
  S += (C-B)*D[B]
  D[C] += D[B]
  D[B] = 0
  print(S)
Buggy python submission (verdict: Runtime Error):
X, Y = map(int, input().split())
print("Yes" if 2*X<=T<=4*X and (4*X-T)%2==0 else "No")

Fixed submission:
X, Y = map(int, input().split())
print("Yes" if 2*X<=Y<=4*X and Y%2==0 else "No")
Buggy python submission (verdict: Runtime Error):
X, N = map(int, input().split())
if N>0:
  P = list(map(int, input().split()))
  P = [i for i in range(-1, 101) if i not in P]
  for i in range(len(P)):
    if abs(X-P[i])<=abs(X-P[i+1]):
      print(P[i])
      break
else:
  print(X)

Fixed submission:
X, N = map(int, input().split())
if N>0:
  P = list(map(int, input().split()))
else:
  P = []
i = 0
while True:
  if X-i not in P:
    print(X-i)
    break
  if X+i not in P:
    print(X+i)
    break
  i += 1

Buggy python submission (verdict: Runtime Error):
X, N = map(int, input().split())
P = list(map(int, input().split()))
Q = [i for i in range(-100, 101) if i not in P]

c = 0
R = 1000
if N == 0:
    print(X)
else:
    while True:
        if R <= abs(X-Q[c]):
            break
        else: 
            R = abs(X-Q[c])
            c += 1
    print(Q[c-1])

Fixed submission:
X, N = map(int, input().split())
if N>0:
  P = list(map(int, input().split()))
else:
  P = []
i = 0
while True:
  if X-i not in P:
    print(X-i)
    break
  if X+i not in P:
    print(X+i)
    break
  i += 1
Buggy python submission (verdict: Runtime Error):
a, b = int(x) for x in input().split()
print(a*b)

Fixed submission:
a, b = (int(x) for x in input().split())
print(a*b)
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
N = int(input())
Q = tuple([_ for _ in input().split()] for _ in range(N))
C = 0
def move(s, q, c):
    if q[0] == "1":
        return s, (c+1)%2
    else:
        if (int(q[1])+c)%2 == 0:
            return s + q[2], c
        else:
            return q[2] + s, c
for q in Q:
    S, C = move(S, q, C)
if C != 0:
    S = S[::-1]
else:
    pass
print(S)

Fixed submission:
S = input()
N = int(input())
Q = tuple([_ for _ in input().split()] for _ in range(N))
C = 0
F = ""
R = ""
for q in Q:
    if q[0] == "1":
        C = (C+1)%2
    else:
        if (int(q[1])+C)%2 != 0:
            F = q[2] + F
        else:
            R = R + q[2]
S = F + S + R
if C != 0:
    S = S[::-1]
print(S)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
N = int(input())
Q = tuple([_ for _ in input().split()] for _ in range(N))

def move(s, q):
    if q[0] == "1":
        return s[::-1]
    else:
        if q[1] == "1":
            return q[2] + s
        else:
            return s + q[2]
        
for q in Q:
    S = move(S, q)
print(S)

Fixed submission:
S = input()
N = int(input())
Q = tuple([_ for _ in input().split()] for _ in range(N))
C = 0
F = ""
R = ""
for q in Q:
    if q[0] == "1":
        C = (C+1)%2
    else:
        if (int(q[1])+C)%2 != 0:
            F = q[2] + F
        else:
            R = R + q[2]
S = F + S + R
if C != 0:
    S = S[::-1]
print(S)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
N = int(input())
Q = list([_ for _ in input().split()] for _ in range(N))

def move(s, q):
    if q[0] == "1":
        return s[::-1]
    else:
        if q[1] == "1":
            return q[2] + s
        else:
            return s + q[2]
        
for q in Q:
    S = move(S, q)
print(S)

Fixed submission:
S = input()
N = int(input())
Q = tuple([_ for _ in input().split()] for _ in range(N))
C = 0
F = ""
R = ""
for q in Q:
    if q[0] == "1":
        C = (C+1)%2
    else:
        if (int(q[1])+C)%2 != 0:
            F = q[2] + F
        else:
            R = R + q[2]
S = F + S + R
if C != 0:
    S = S[::-1]
print(S)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
D = {}
for _ in range(N):
  s = input()
  if s in D:
    D[s] += 1
  else:
    D[s] = 1
L = [d[0] for d in D.items() if d[1] == max(D.values())]
for l in sorted(L):
  print(l)

Fixed submission:
N = int(input())
D = {}
for _ in range(N):
  s = input()
  if s in D:
    D[s] += 1
  else:
    D[s] = 1
m = max(D.values())
for k, v in sorted(D.items()):
  if v==m:
    print(k)
Buggy python submission (verdict: Runtime Error):
S, T = input().split
A, B = map(int, input().split)
U = input()

print(A-1, B if S ==U else A, B-1)

Fixed submission:
S, T = input().split()
A, B = map(int, input().split())
print(A-1, B) if input()==S else print(A, B-1)
Buggy python submission (verdict: Runtime Error):
a, b = input().split()
print(min(a*b, b*a))

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

if num_a < num_b:
  print(a*num_b)
else:
  print(b*num_a)

Buggy python submission (verdict: Runtime Error):
a,b = map(input().split())
num_a = int(a)
num_b = int(b)

if num_a < num_b:
  print(a*num_b)
else:
  print(b*num_a)

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

if num_a < num_b:
  print(a*num_b)
else:
  print(b*num_a)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
P_list = [int(i) for i in input().split()]
c = 0
for j in range(N):
  if P_list[j] == min(P_list[0:j+1]):
    c += 1
  else:
    pass
print(c)

Fixed submission:
N = int(input())
P = [int(x) for x in input().split()]
R = 1000000
c = 0
for i in range(N):
  if min(R, P[i])==P[i]:
    c += 1
    R = P[i]
  else:
    pass
print(c)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = []
for _ in range(N):
  x, l = map(int, input().split())
  L.append([x-l, x+l])
L.sort(key=lambda x: x[1])
s, ans = -10**8, 0
while True:
  for l in L:
    if s<=l[0]:
      ans += 1
      s = l[1]
      break
  else:
    break
print(ans)

Fixed submission:
from collections import deque
N = int(input())
L = []
for _ in range(N):
  x, l = map(int, input().split())
  L.append([x-l, x+l])
L.sort(key=lambda x: x[1])
L = deque(L)
s, ans = -10**8, 0
while L:
  l = deque.popleft(L)
  if s<=l[0]:
    ans += 1
    s = l[1]
print(ans)
Buggy python submission (verdict: Runtime Error):
al = "abcdefghijklmnopqrstuvwxyz"
C = input()
print(al[al.index(C)+1])
al = abcdefghijklmnopqrstuvwxyz
C = input()
print(al[al.index(C)+1])


Fixed submission:
al = "abcdefghijklmnopqrstuvwxyz"
C = input()
print(al[al.index(C)+1])

Buggy python submission (verdict: Runtime Error):
al = abcdefghijklmnopqrstuvwxyz
C = input()
print(al[al.index(C)+1])

Fixed submission:
al = "abcdefghijklmnopqrstuvwxyz"
C = input()
print(al[al.index(C)+1])
Buggy python submission (verdict: Runtime Error):
N = int(input())
t = N+1
for n in reversed(range(0, int(N**0.5))):
  if N%n==0:
    t = n+N//n
    break
print(t-2)

Fixed submission:
N = int(input())
m = 100000000000000
for i in range(1, int(N**0.5)+1):
  if N%i == 0:
    m = min(m, i+N//i)
print(m-2)

Buggy python submission (verdict: Runtime Error):
N = int(input())
for n in reversed(range(1, int(N**0.5))):
  if N%n==0:
    t = n+N//n
    break
print(t-2)

Fixed submission:
N = int(input())
m = 100000000000000
for i in range(1, int(N**0.5)+1):
  if N%i == 0:
    m = min(m, i+N//i)
print(m-2)
Buggy python submission (verdict: Runtime Error):
import math
A, B = map(int, input())
print(math.ceil((B-1)//(A-1)))

Fixed submission:
import math
a, b = map(int, input().split())
n = (b-1)/(a-1)
print(math.ceil(n))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = []
for _ in range(N):
  L.append("".join(sorted(input())))
R = set(L)
c = 0
for r in R:
  t = L.count(r)
  c += t*(t-1)//2
print(c)

Fixed submission:
from collections import Counter
N = int(input())
L = ["".join(sorted(input())) for _ in range(N)]
T = Counter(L).values()
print(sum(v*(v-1)//2 for v in T))
Buggy python submission (verdict: Runtime Error):
s = sorted(input())
print("Yes" if s[0]==s[1] and S[1]!=S[2] and s[2]==s[3] else "No")

Fixed submission:
from collections import Counter
s = Counter(input()).values()
print("Yes" if min(s)==max(s) and len(s)==2 else "No")
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
A = [int(input()) for _ in range(M)]
P = 1
Q = 0 if 1 in A else 1
for i in range(N-1):
  p = 0 if i+2 in A else P+Q
  P, Q = Q%(10**9+7), p%(10**9+7)
print(Q)

Fixed submission:
N, M = map(int, input().split())
A = [int(input()) for _ in range(M)]
L = [0]*(N+1)
for a in A:
  L[a]=-1
L[0] = 1
L[1] += 1
for i in range(2, N+1):
  if L[i]==-1:
    L[i]=0
  else:
    L[i] = L[i-1]+ L[i-2]
print(L[-1]%(10**9+7))
Buggy python submission (verdict: Runtime Error):
N,Q = map(int,input().split())
S = input()
X = [list(map(int, input().split())) for _ in range(Q)]
L =[0]*(N+1)
for i in range(N):
  if S[i]=="A" and S[i+1]=="C":
    L[i+1] = L[i]+1 
  else:
    L[i+1] = L[i]
for x in X:
  print(L[x[1]-1]-L[x[0]-1])

Fixed submission:
N, Q = map(int, input().split())
S = input()
L = [list(map(int, input().split())) for _ in range(Q)]
t, I = 0, [0]
for i in range(1, N):
  if S[i-1]=="A":
    if S[i]=="C":
      t += 1
  I.append(t)
for l in L:
  print(I[l[1]-1]-I[l[0]-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()
L = [list(map(int, input().split())) for _ in range(Q)]
for l in L:
  print(S[l[0]-1:l[1]].count("AC"))

Fixed submission:
N, Q = map(int, input().split())
S = input()
L = [list(map(int, input().split())) for _ in range(Q)]
t, I = 0, [0]
for i in range(1, N):
  if S[i-1]=="A":
    if S[i]=="C":
      t += 1
  I.append(t)
for l in L:
  print(I[l[1]-1]-I[l[0]-1])
Buggy python submission (verdict: Runtime Error):
input()
L = map(int, input().split())
print("Yes" if sum(L)>2*max(L) else "No")

Fixed submission:
n = int(input())
list = [int(i) for i in input().split()]

max = max(list)
sum = sum(list)

if sum > 2*max:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N = int(input())
stack, seen = deque(["0"]), deque([])
c = 0
while stack:
  x = stack.pop()
  seen.append(x)
  if int(x)>N:
    continue
  if all(x.count(i)>0 for i in "753"):
    c += 1
  for i in "753":
    if x+i in seen:
      continue
    else:
      stack.append(x+i)
print(c)

Fixed submission:
import itertools
N = int(input())
A = ["3", "5", "7"]
L = []
for i in range(1, 10):
  for l in itertools.product(A, repeat=i):
    L.append(l)
c = 0
for l in L:
  if int("".join(l))<=N and l.count("3")>=1 and \
  l.count("5")>=1 and l.count("7")>=1:
    c += 1
print(c)
Buggy python submission (verdict: Runtime Error):
N, T = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
Y = [X[i] if X[i][1]<=T for i in range(N)]
print(Y)

Fixed submission:
N, T = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
Y = [x for x in X if x[1]<=T]
Z = [y[0] for y in Y]
print("TLE" if Y==[] else min(Z))
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().solit())
print((a-1)*(b-1))

Fixed submission:
a, b = map(int, input().split())
print((a-1)*(b-1))
Buggy python submission (verdict: Runtime Error):
A_1 = int(input())
A_2 = int(input())
A_3 = int(input())

list = [A_1, A_2, A_3]
new_list = sorted(list)
print(new_list[2] - new_list[0])

Fixed submission:
A_1, A_2, A_3 = (int(x) for x in input().split())
list = [A_1, A_2, A_3]
new_list = sorted(list)
print(new_list[2] - new_list[0])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
List = [0]*N
for i in range(N):
  if S[i]=="E":
    for j in range(i):
      List[j] += 1
  else:
    for j in range(i+1, N):
      List[j] += 1
print(min(List))

Fixed submission:
N = int(input())
S = input()
L = [0]*(N+1)
for i in range(N):
  if S[i]=="E":
    L[i+1] = L[i]+1
  else:
    L[i+1] = L[i]
print(min(i-L[i]+L[N]-L[i+1] for i in range(N)))
Buggy python submission (verdict: Time Limit Exceeded):
A, B, K = map(int, input().split())
L = [i for i in range(A, B+1)]
S = sorted(set(L[:K]+L[::-1][:K]))
for s in S:
  print(s)

Fixed submission:
A, B, K = map(int, input().split())
L_1 = set([i for i in range(A, min(A+K, B+1))])
L_2 = set([i for i in range(max(A, B-K+1), B+1)])
L = sorted(L_1|L_2)
for l in L:
  print(l)