Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=[]
ma=0
for i in range(n):
    a.append(int(input()))
for j in range(n):
    if(ma=a[j]):
        for h in range(n):
            if(h!=j):
                if(ma<a[h]):
                    ma=a[h]
        print(str(ma))  


Fixed submission:
while True:
    n=int(input())
    if(2<=n<=200000):
        break
a=[]
for i in range(n):
        a.append(int(input()))
ma=a[0]
b=0
for j in range(1,n):
    if(ma==a[j]):
        b=a[j]
    if(ma<a[j]):
        ma=a[j]
        continue
    if(b<a[j]):
        b=a[j]
for l in range(n):
    if(a[l]!=ma):
        print(str(ma))
    else:
        print(str(b))

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=[]
for i in range(n):
    a.append(int(input()))
for j in range(n):
    ma=0
    for h in range(n):
        if(h!=j):
            if(ma<a[h]):
                ma=a[h]
    print(str(ma))  


Fixed submission:
while True:
    n=int(input())
    if(2<=n<=200000):
        break
a=[]
for i in range(n):
        a.append(int(input()))
ma=a[0]
b=0
for j in range(1,n):
    if(ma==a[j]):
        b=a[j]
    if(ma<a[j]):
        ma=a[j]
        continue
    if(b<a[j]):
        b=a[j]
for l in range(n):
    if(a[l]!=ma):
        print(str(ma))
    else:
        print(str(b))
Buggy python submission (verdict: Runtime Error):
a=input()
for i in range(len(a)-1):
  if a[i]==a[i+1]:
    flag=True
    break
if flag:
  print('Bad')
else:
  print('Good')

Fixed submission:
a=input()
flag=False
for i in range(len(a)-1):
  if a[i]==a[i+1]:
    flag=True
    break
if flag:
  print('Bad')
else:
  print('Good')

Buggy python submission (verdict: Runtime Error):
a=input()
for i in range(len(a)-1):
  if a[i]==a[i+1]:
    flag=True
    break
if flag:
  print('Bad')
else:
  print('Good')

Fixed submission:
a=input()
flag=False
for i in range(len(a)-1):
  if a[i]==a[i+1]:
    flag=True
    break
if flag:
  print('Bad')
else:
  print('Good')
Buggy python submission (verdict: Runtime Error):
a=input()
b=input()
c={}
state=True
for i in range(len(a)):
  if b[i] not in c:
    c[b[i]]=a[i]
  if b[i] in c:
    if c[b[i]]!=a[i]:
    state=False
  else:
    state=False
if state:
  print('Yes')
else:
  print('No')

Fixed submission:
a=input()
b=input()
c={}
state=True
for i in range(len(a)):
  if b[i] not in c and a[i] not in c.values():
    c[b[i]]=a[i]
  if b[i] in c:
    if c[b[i]]!=a[i]:
      state=False
  else:
    state=False
if state:
  print('Yes')
else:
  print('No')

Buggy python submission (verdict: Runtime Error):
a=input()
b=input()
c={}
state=True
for i in range(len(a)):
  if b[i] not in c and a[i] not in c.values():
    c[b[i]]=a[i]
  if c[b[i]]!=a[i]:
    state=False
if state:
  print('Yes')
else:
  print('No')

Fixed submission:
a=input()
b=input()
c={}
state=True
for i in range(len(a)):
  if b[i] not in c and a[i] not in c.values():
    c[b[i]]=a[i]
  if b[i] in c:
    if c[b[i]]!=a[i]:
      state=False
  else:
    state=False
if state:
  print('Yes')
else:
  print('No')

Buggy python submission (verdict: Runtime Error):
a=input()
b=input()
c={}
state=True
for i in range(len(a)):
  if (b[i] not in c) and (a[i] not in c):
    c[b[i]]=a[i]
    c[a[i]]=b[i]
  if c[b[i]]!=a[i]:
    state=False
if state:
  print('Yes')
else:
  print('No')

Fixed submission:
a=input()
b=input()
c={}
state=True
for i in range(len(a)):
  if b[i] not in c and a[i] not in c.values():
    c[b[i]]=a[i]
  if b[i] in c:
    if c[b[i]]!=a[i]:
      state=False
  else:
    state=False
if state:
  print('Yes')
else:
  print('No')

Buggy python submission (verdict: Runtime Error):
a=input()
b=input()
c={}
state=True
for i in range(len(a)):
  if b[i] not in c and a[i] not in c:
    c[b[i]]=a[i]
    c[a[i]]=b[i]
  if c[b[i]]!=a[i]:
    state=False
if state:
  print('Yes')
else:
  print('No')

Fixed submission:
a=input()
b=input()
c={}
state=True
for i in range(len(a)):
  if b[i] not in c and a[i] not in c.values():
    c[b[i]]=a[i]
  if b[i] in c:
    if c[b[i]]!=a[i]:
      state=False
  else:
    state=False
if state:
  print('Yes')
else:
  print('No')

Buggy python submission (verdict: Runtime Error):
a=input()
b=input()
c={}
state=True
for i in range(len(a)):
  b[i] not in c:
    c[b[i]]=a[i]
    c[a[i]]=b[i]
  if c[b[i]]!=a[i]:
    state=False
if state:
  print('Yes')
else:
  print('No')
    
  

Fixed submission:
a=input()
b=input()
c={}
state=True
for i in range(len(a)):
  if b[i] not in c and a[i] not in c.values():
    c[b[i]]=a[i]
  if b[i] in c:
    if c[b[i]]!=a[i]:
      state=False
  else:
    state=False
if state:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
def gmax(a,b):
  if a<b:
  	a,b=b,a
  while a%b!=0:
    tmp=a
    a=b
    b=tmp%b
  return b
 
n=int(input())
x=[]
for i in range(n):
  x.append(int(input()))
    
g=gmax(x[0],x[1])
l=x[0]*x[1]//g
 
for j in range(2,len(x)):
  g=gmax(x[j],l)
  l=x[j]*l//g
  
print(l)

Fixed submission:
def gmax(a,b):
  if a<b:
  	a,b=b,a
  while a%b!=0:
    tmp=a
    a=b
    b=tmp%b
  return b
 
n=int(input())
x=[]
for i in range(n):
  x.append(int(input()))

if len(x)!=1:
  g=gmax(x[0],x[1])
  l=x[0]*x[1]//g

  for i in range(2,len(x)):
    g=gmax(x[i],l)
    l=(x[i]*l)//g
else:
  l=x[0]
print(l)

Buggy python submission (verdict: Runtime Error):
def gmax(a,b):
  if a<b:
  	a,b=b,a
  while a%b!=0:
    tmp=a
    a=b
    b=tmp%b
  return b

n=int(input())
x=[]
for i in range(n):
  x.append(int(input()))
    
g=gmax(x[0],x[1])
l=x[0]*x[1]//g

for i in range(2,len(x)):
  g=gmax(x[i],l)
  l=x[i]*l//g

ans=l
print(ans)

Fixed submission:
def gmax(a,b):
  if a<b:
  	a,b=b,a
  while a%b!=0:
    tmp=a
    a=b
    b=tmp%b
  return b
 
n=int(input())
x=[]
for i in range(n):
  x.append(int(input()))

if len(x)!=1:
  g=gmax(x[0],x[1])
  l=x[0]*x[1]//g

  for i in range(2,len(x)):
    g=gmax(x[i],l)
    l=(x[i]*l)//g
else:
  l=x[0]
print(l)

Buggy python submission (verdict: Runtime Error):
def gmax(a,b):
  if a<b:
    a,b=b,a
  while a%b!=0:
    tmp=a
    a=b
    b=tmp%b
  return b

n=int(input())
x=[]
for i in range(n):
  x.append(int(input()))
    
g=gmax(x[0],x[1])
l=x[0]*x[1]//g

for i in range(2,len(x)):
  g=gmax(x[i],g)
  l=x[i]*l//g

ans=l
print(ans)

Fixed submission:
def gmax(a,b):
  if a<b:
  	a,b=b,a
  while a%b!=0:
    tmp=a
    a=b
    b=tmp%b
  return b
 
n=int(input())
x=[]
for i in range(n):
  x.append(int(input()))

if len(x)!=1:
  g=gmax(x[0],x[1])
  l=x[0]*x[1]//g

  for i in range(2,len(x)):
    g=gmax(x[i],l)
    l=(x[i]*l)//g
else:
  l=x[0]
print(l)
Buggy python submission (verdict: Runtime Error):
def main():
    x, y = map(int, input().split())
    def get_prize(a):
        if a==1:
            return 300_000
        elif a==2:
            return 200_000
        elif a==3:
            return 100_000
        else:
            return 0
    a = 0
    a += get_prize(x)
    a += get_prize(y)
    a = a + 400_000 if a==600_000 else a
    print(a)

if __name__ == "__main__":
    main()


Fixed submission:
def main():
    x, y = map(int, input().split())
    def get_prize(a):
        if a==1:
            return 300000
        elif a==2:
            return 200000
        elif a==3:
            return 100000
        else:
            return 0
    a = 0
    a += get_prize(x)
    a += get_prize(y)
    a = a + 400000 if a==600000 else a
    print(a)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
def main():
    x, y = map(int, input().split())
    d = {1: 30_000, 2: 20_000, 3: 10_000}
    a = 0
    a += d.get(x, 0)
    a += d.get(y, 0)
    a = a + 40_000 if a==60_000 else a
    print(a)

if __name__ == "__main__":
    main()


Fixed submission:
def main():
    x, y = map(int, input().split())
    def get_prize(a):
        if a==1:
            return 300000
        elif a==2:
            return 200000
        elif a==3:
            return 100000
        else:
            return 0
    a = 0
    a += get_prize(x)
    a += get_prize(y)
    a = a + 400000 if a==600000 else a
    print(a)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    *a, = map(int, input().split())
    o = float("inf")
    for i in range(1, n):
        l, r = sum(a[:i]), sum(a[i:])
        tmp = max(l, r) - min(l, r)
        o = tmp if tmp<o else o
    print(o)

if __name__ == "__main__":
    main()


Fixed submission:
def main():
    n = int(input())
    *a, = map(int, input().split())
    cs = [a[0]]*n
    for i in range(1, n):
        cs[i] = a[i]+cs[i-1]
    o = float("inf")
    for i in range(n):
        l, r = cs[i], cs[-1]-cs[i]
        tmp = max(l, r) - min(l, r)
        o = tmp if tmp<o else o
    print(o)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    h, w, k = map(int, input().split())
    o = [[0]*w for _ in range(h)]
    s = [list(input()) for i in range(h)]
    n, mn = 0, 0
    for i in range(h):
        for j in range(w):
            if s[i][j]=="#":
                mn += 1
                n = mn
                o[i][j] = n
            else:
                o[i][j] = n
        n = 0
    for i in range(h):
        for j in range(w-1, -1, -1):
            if o[i][j]==0:
                o[i][j] = o[i][j+1]

    for i in range(h):
        print(*o[i])

if __name__ == "__main__":
    main()


Fixed submission:
def main():
    h, w, k = map(int, input().split())
    o = [[0]*w for _ in range(h)]
    s = [list(input()) for i in range(h)]
    n, mn = 0, 0
    for i in range(h):
        for j in range(w):
            if s[i][j]=="#":
                mn += 1
                n = mn
                o[i][j] = n
            else:
                o[i][j] = n
        n = 0
    for i in range(h):
        for j in range(w-2, -1, -1):
            if o[i][j]==0:
                o[i][j] = o[i][j+1]
    for j in range(w):
        for i in range(1, h):
            if o[i][j]==0:
                o[i][j] = o[i-1][j]
    for j in range(w):
        for i in range(h-2, -1, -1):
            if o[i][j]==0:
                o[i][j] = o[i+1][j]
    for i in range(h):
        print(*o[i])

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def f_f():
    n = int(input())
    *s, = map(int, input().split())
    s.sort()
    p1, p2 = [s[-1]], []
    s[-1] = -1
    o = "Yes"
    for _ in range(n):
        j = len(s)
        while j>-1 and p1:
            j -= 1
            if s[j]<0:
                pass
            elif p1[-1]>s[j]:
                p2 += [s[j], p1.pop()]
                s[j] = -1
                j = len(s)
        if p1:
            o="No"
            break
        p1, p2 = sorted(p2), []
    print(o)

if __name__ == "__main__":
    f_f()


Fixed submission:

def f_f():
    n, *s = map(int, open(0).read().split())
    s.sort()
    ps, next_ps, cs = [s.pop()], [], []
    for _ in range(n):
        for p in ps:
            while s:
                c = s.pop()
                if p>c:
                    next_ps.append(c)
                    break
                else:
                    cs.append(c)
        s, ps, next_ps, cs = s+cs[::-1], sorted(ps+next_ps, reverse=True), [], []

    print("No" if s else "Yes")

if __name__ == "__main__":
    f_f()
Buggy python submission (verdict: Time Limit Exceeded):
def f_d():
    import numpy as np
    n = int(input())
    if n == 1:
        print(0)
    else:
        print(np.cumsum(range(1, n))[-1])

if __name__ == "__main__":
    f_d()


Fixed submission:
def f_d():
    n = int(input())
    n -= 1
    if n%2==0:
        print(n*((n-2)//2+1)+n//2)
    else:
        print(n*((n-1)//2+1))

if __name__ == "__main__":
    f_d()

Buggy python submission (verdict: Time Limit Exceeded):
def f_d():
    n = int(input())
    c = 0
    for i in range(1, n):
        c += i
    print(c)

if __name__ == "__main__":
    f_d()


Fixed submission:
def f_d():
    n = int(input())
    n -= 1
    if n%2==0:
        print(n*((n-2)//2+1)+n//2)
    else:
        print(n*((n-1)//2+1))

if __name__ == "__main__":
    f_d()
Buggy python submission (verdict: Time Limit Exceeded):
def f_c():

    n = int(input())
    s = ["".join(sorted(input())) for _ in range(n)]

    c = 0
    for _ in range(n):
        si = s.pop()
        if si in s:
            c += s.count(si)
    print(c)

if __name__ == "__main__":
    f_c()

Fixed submission:
def f_c():

    n = int(input())
    d = {}
    dc = {}
    for _ in range(n):
        s = "".join(sorted(input()))
        if s in d:
            dc[s] += d[s]
            d[s] += 1
        else:
            d[s] = 1
            dc[s] = 0
    print(sum(dc.values()))

if __name__ == "__main__":
    f_c()

Buggy python submission (verdict: Runtime Error):
def f_c():

    n = int(input())
    s = ["".join(sorted(input())) for _ in range(n)]

    c = 0
    for _ in range(n):
        si = s.pop()
        if si in s:
            c += s.count(s2)
    print(c)

if __name__ == "__main__":
    f_c()


Fixed submission:
def f_c():

    n = int(input())
    d = {}
    dc = {}
    for _ in range(n):
        s = "".join(sorted(input()))
        if s in d:
            dc[s] += d[s]
            d[s] += 1
        else:
            d[s] = 1
            dc[s] = 0
    print(sum(dc.values()))

if __name__ == "__main__":
    f_c()
Buggy python submission (verdict: Runtime Error):
n, *a = map(int, open(0).read().split())
a2 = sorted(a)[:-2]
for i in range(n):
    if a[i]==a2[1]:
        print(a[0])
    else:
        print(a[1])

Fixed submission:
n, *a = map(int, open(0).read().split())
a2 = sorted(a)[-2:]
for i in range(n):
    if a[i]==a2[1]:
        print(a2[0])
    else:
        print(a2[1])

Buggy python submission (verdict: Runtime Error):
n, *a = map(int, read(0).open().split())
a2 = sorted(a)[:-2]
for i in range(n):
    if a[i]==a2[1]:
        print(a[0])
    else:
        print(a[1])

Fixed submission:
n, *a = map(int, open(0).read().split())
a2 = sorted(a)[-2:]
for i in range(n):
    if a[i]==a2[1]:
        print(a2[0])
    else:
        print(a2[1])
Buggy python submission (verdict: Runtime Error):
def f_c():
    import math
    a, b, c, d = map(int, input().split())
    c_n = b//c-a//c+1 if a%c==0 else b//c-a//c
    d_n = b//d-a//d+1 if a%d==0 else b//d-a//d
    cd = c*d//math.gcd(c, d)
    cd_n = b//cd-a//cd+1 if a%cd==0 else b//cd-a//cd
    print(b-a+1-(c_n+d_n-cd_n))

if __name__ == "__main__":
    f_c()


Fixed submission:
def f_c():
    import fractions
    a, b, c, d = map(int, input().split())
    c_n = b//c-a//c+1 if a%c==0 else b//c-a//c
    d_n = b//d-a//d+1 if a%d==0 else b//d-a//d
    cd = c*d//fractions.gcd(c, d)
    cd_n = b//cd-a//cd+1 if a%cd==0 else b//cd-a//cd
    print(b-a+1-(c_n+d_n-cd_n))

if __name__ == "__main__":
    f_c()

Buggy python submission (verdict: Runtime Error):
def f_c():
    import math
    a, b, c, d = map(int, input().split())
    c_n = b//c-a//c+1 if a%c==0 else b//c-a//c
    d_n = b//d-a//d+1 if a%d==0 else b//d-a//d
    cd = c*d//math.gcd(c, d)
    cd_n = b//cd-a//cd+1 if a%cd==0 else b//cd-a//cd
    print(b-a+1-(c_n+d_n-cd_n))

if __name__ == "__main__":
    f_c()


Fixed submission:
def f_c():
    import fractions
    a, b, c, d = map(int, input().split())
    c_n = b//c-a//c+1 if a%c==0 else b//c-a//c
    d_n = b//d-a//d+1 if a%d==0 else b//d-a//d
    cd = c*d//fractions.gcd(c, d)
    cd_n = b//cd-a//cd+1 if a%cd==0 else b//cd-a//cd
    print(b-a+1-(c_n+d_n-cd_n))

if __name__ == "__main__":
    f_c()
Buggy python submission (verdict: Runtime Error):
n, *w = map(int, open(0).read().split())
c = float("inf")
for i in range(n):
    s = abs(sum(w[:i])-sum(w[i:])):
    c = s if c>s else c
print(c)

Fixed submission:
n, *w = map(int, open(0).read().split())
c = float("inf")
for i in range(n):
    s = abs(sum(w[:i])-sum(w[i:]))
    c = s if c>s else c
print(c)
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
l, r = map(int, input().split())
c = set(range(l, r+1))
for _ in range(m-1):
    l, r = map(int, input().split())
    c = c & set(range(l, r+1))
print(len(c))


Fixed submission:
n, m = map(int, input().split())
tl, tr = 1, n
for _ in range(m):
    l, r = map(int, input().split())
    if tr<l or tl>r:
        tl, tr = 1, 0; break
    else:
        tl = l if tl<l else tl
        tr = r if tr>r else tr
print(tr-tl+1)
Buggy python submission (verdict: Time Limit Exceeded):
def f_d():
    n, k = map(int, input().split())
    *s, = map(int, list(input()))
    l, t, c = [], 1, 0
    for i in range(n):
        if s[i]==t:
            c += 1
        else:
            l.append(c)
            c, t = 1, t^1
    if c!=0:
        l.append(c)
    if len(l)%2==0:
        l.append(0)

    r, a = 2*k+1, 0
    for i in range(0, len(l), 2):
        a = max(a, sum(l[i:min(i+r, len(l))]))
    print(a)

if __name__ == "__main__":
    f_d()


Fixed submission:
def f_d():
    n, k = map(int, input().split())
    *s, = map(int, list(input()))
    l, t, c = [], 1, 0
    for i in range(n):
        if s[i]==t:
            c += 1
        else:
            l.append(c)
            c, t = 1, t^1
    if c!=0:
        l.append(c)
    if len(l)%2==0:
        l.append(0)

    r, a = 2*k+1, 0
    li = ri = tmp = 0
    for i in range(0, len(l), 2):
        nli, nri = i, min(i+r, len(l))
        while li<nli:
            tmp -= l[li]
            li += 1
        while ri<nri:
            tmp += l[ri]
            ri += 1
        a = max(a, tmp)
    print(a)

if __name__ == "__main__":
    f_d()
Buggy python submission (verdict: Runtime Error):
def f_d():
    import heapq
    x, y, z, k = map(int, input().split())
    *a, = sorted(list(map(int, input().split())), reverse=True)
    *b, = sorted(list(map(int, input().split())), reverse=True)
    *c, = sorted(list(map(int, input().split())), reverse=True)

    m, o = [[[0]*z for _ in range(y)] for _ in range(x)], []
    q = [[-1*(a[0]+b[0]+c[0]), 0, 0, 0]]
    heapq.heapify(q)
    for _ in range(k):
        tmp = heapq.heappop(q)
        o.append(-1*tmp[0])
        ai, bi, ci = tmp[1], tmp[2], tmp[3]
        if m[min(ai+1, len(a)-1)][bi][ci]==0:
            m[ai+1][bi][ci] = 1
            heapq.heappush(q, [-1*(a[ai+1]+b[bi]+c[ci]), ai+1, bi, ci])
        if m[ai][min(bi+1, len(b)-1)][ci]==0:
            m[ai][bi+1][ci] = 1
            heapq.heappush(q, [-1*(a[ai]+b[bi+1]+c[ci]), ai, bi+1, ci])
        if m[ai][bi][min(ci+1, len(c)-1)]==0:
            m[ai][bi][ci+1] = 1
            heapq.heappush(q, [-1*(a[ai]+b[bi]+c[ci+1]), ai, bi, ci+1])
    for i in range(k):
        print(o[i])

if __name__ == "__main__":
    f_d()


Fixed submission:
def f_d():
    import heapq
    x, y, z, k = map(int, input().split())
    *a, = sorted(list(map(int, input().split())), reverse=True)
    *b, = sorted(list(map(int, input().split())), reverse=True)
    *c, = sorted(list(map(int, input().split())), reverse=True)

    m = set((0, 0, 0))
    q = [[-1*(a[0]+b[0]+c[0]), 0, 0, 0]]
    heapq.heapify(q)
    for _ in range(k):
        ans, ai, bi, ci = heapq.heappop(q)
        if ai+1<x and (ai+1, bi, ci) not in m:
            m.add((ai+1, bi, ci))
            heapq.heappush(q, [-1*(a[ai+1]+b[bi]+c[ci]), ai+1, bi, ci])
        if bi+1<y and (ai, bi+1, ci) not in m:
            m.add((ai, bi+1, ci))
            heapq.heappush(q, [-1*(a[ai]+b[bi+1]+c[ci]), ai, bi+1, ci])
        if ci+1<z and (ai, bi, ci+1) not in m:
            m.add((ai, bi, ci+1))
            heapq.heappush(q, [-1*(a[ai]+b[bi]+c[ci+1]), ai, bi, ci+1])
        print(-1*ans)

if __name__ == "__main__":
    f_d()
Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
s = input()
idx = []

for i in range(n-1):
    if (s[i] == "A") & (s[i+1] == "C"):
        idx.append(i+1)

for j in range(q):
    l, r = map(int, input().split())
    n = [i for i in idx if ((i >= l) & (i < r))]
    print(len(n))


Fixed submission:
n, q = map(int, input().split())
s = input()
m = [0]
c = 0
for i in range(1, n):
    if (s[i-1] == "A") & (s[i] == "C"):
        c += 1
    m.append(c)

for j in range(q):
    l, r = map(int, input().split())
    print(m[r-1] - m[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
s = input()
s = s.replace("AC", "12")
idx = [i+1 for i, x in enumerate(s) if x in "1"]

for j in range(q):
    l, r = map(int, input().split())
    n = [i for i in idx if ((i >= l) & (i < r))]
    print(len(n))

Fixed submission:
n, q = map(int, input().split())
s = input()
m = [0]
c = 0
for i in range(1, n):
    if (s[i-1] == "A") & (s[i] == "C"):
        c += 1
    m.append(c)

for j in range(q):
    l, r = map(int, input().split())
    print(m[r-1] - m[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
s = input()
for i in range(q):
    l, r = map(int, input().split())
    c = s[l-1:r]
    print((len(c)-len(c.replace("AC", "")))//2)

Fixed submission:
n, q = map(int, input().split())
s = input()
m = [0]
c = 0
for i in range(1, n):
    if (s[i-1] == "A") & (s[i] == "C"):
        c += 1
    m.append(c)

for j in range(q):
    l, r = map(int, input().split())
    print(m[r-1] - m[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
s = input()
for i in range(q):
    l, r = map(int, input().split())
    c = s[l-1:r]
    print(int((len(c)-len(c.replace("AC", "")))/2))

Fixed submission:
n, q = map(int, input().split())
s = input()
m = [0]
c = 0
for i in range(1, n):
    if (s[i-1] == "A") & (s[i] == "C"):
        c += 1
    m.append(c)

for j in range(q):
    l, r = map(int, input().split())
    print(m[r-1] - m[l-1])
Buggy python submission (verdict: Runtime Error):
def main():
    import numpy as np
    n, m, c = map(int, readline().split())
    ba = list(map(int, read().split()))
    a = np.array(ba[m:]).reshape((n,m))
    b = np.array(ba[:m])

    print(sum(np.dot(a,b)+c>0))

if __name__ == "__main__":
    main()


Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def main():
    import numpy as np
    n, m, c = map(int, readline().split())
    ba = list(map(int, read().split()))
    a = np.array(ba[m:]).reshape((n,m))
    b = np.array(ba[:m])

    print(sum(np.dot(a,b)+c>0))

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    import fractions
    def gcd(li):
        fractions.reduce(fractions.gcd, li)

    n, k, *a = map(int, open(0).read().split())
    g = gcd(a)
    if max(a)>=k and k%g==0:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")

if __name__ == "__main__":
    main()


Fixed submission:
def main():
    import fractions, functools
    def gcd(li):
        return functools.reduce(fractions.gcd, li)

    n, k, *a = map(int, open(0).read().split())
    g = gcd(a)
    if max(a)>=k and k%g==0:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
D=[]
x=[]
D = [[0 for i in range(2)] for j in range(N)]#N×"2"の行列Dを作る
for i in range(0,N):
    x=input().split(" ")
    for j in range(0,2):#i行目の成分を入力
        D[i][j]=int(x[j])

D.sort(key=lambda p:p[1])#2列目の成分でソート

x=0
for i in range(0,N):
    x=x+D[i][0]#経過時間
    y=D[i][1]#締め切り時刻
    if x>y:
        n=1
        break
    else:
        z=0
        for j in range(0,N):
            z=z+D[j][0]
            if z<=D[N-1][1]:
                n=0
if n==1:
    print('No')
else:
    print('Yes')


Fixed submission:
N=int(input())
D=[]
x=[]
D = [[0 for i in range(2)] for j in range(N)]#N×"2"の行列Dを作る
for i in range(0,N):
    x=input().split(" ")
    for j in range(0,2):#i行目の成分を入力
        D[i][j]=int(x[j])

D.sort(key=lambda p:p[1])#2列目の成分でソート

x=0
for i in range(0,N):
    x=x+D[i][0]#経過時間
    y=D[i][1]#締め切り時刻
    if x>y:
        n=1
        break
    else:
        n=0
if n==1:
    print('No')
else:
    print('Yes')