Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
s = str(input())
t = str(input())

alpha2num = lambda c: ord(c) - ord('a')

S2 = [[] for i in range(26)]
for i in range(len(s)):
  S2[alpha2num(s[i])].append(i)
  
#print(S2)
time = 0
place = -1
for i in range(len(t)):
  now = alpha2num(t[i])
  if S2[now] == []:
    print(-1)
    quit()
  else:
    if place not in S2[now]:
      index = bisect.bisect_left(S2[now], place)
    else:
      index = bisect.bisect_left(S2[now], place + 1)
    #print(index, S2[now])  
      
    if index == len(S2[now]):
      place = S2[now][0]
      time += 1
    else:  
      place = S2[now][index]
  #print(place, time)  
    
    
ans = len(s) * time + place + 1
print(ans)
    
    
  
  

Fixed submission:
import bisect
s = str(input())
t = str(input())

alpha2num = lambda c: ord(c) - ord('a')

S2 = [[] for i in range(26)]
for i in range(len(s)):
  S2[alpha2num(s[i])].append(i)
  
#print(S2)
time = 0
place = -1
for i in range(len(t)):
  now = alpha2num(t[i])
  if S2[now] == []:
    print(-1)
    quit()
  else:
    index = bisect.bisect_left(S2[now], place)
    #if index == place:
    #  index += 1
    #print(index, S2[now])  

    
    if index == len(S2[now]):
      place = S2[now][0]
      time += 1
    else:  
      if S2[now][index] == place:
        index += 1
        if index == len(S2[now]):
          place = S2[now][0]
          time += 1
        else:
          place = S2[now][index]
      else:  
        place = S2[now][index]
  #print(place, time)  
    
    
ans = len(s) * time + place + 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
s = str(input())
t = str(input())

alpha2num = lambda c: ord(c) - ord('a')

S2 = [[] for i in range(26)]
for i in range(len(s)):
  S2[alpha2num(s[i])].append(i)
  
#print(S2)
time = 0
place = -1
for i in range(len(t)):
  now = alpha2num(t[i])
  if S2[now] == []:
    print(-1)
    quit()
  else:
    if place not in S2[now]:
      index = bisect.bisect_left(S2[now], place)
    else:
      index = bisect.bisect_left(S2[now], place + 1)
    #print(index, S2[now])  
      
    if index == len(S2[now]):
      place = S2[now][0]
      time += 1
    else:  
      place = S2[now][index]
  #print(place, time)  
    
    
ans = len(s) * time + place + 1
print(ans)
    
    
  
  

Fixed submission:
import bisect
s = str(input())
t = str(input())

alpha2num = lambda c: ord(c) - ord('a')

S2 = [[] for i in range(26)]
for i in range(len(s)):
  S2[alpha2num(s[i])].append(i)
  
#print(S2)
time = 0
place = -1
for i in range(len(t)):
  now = alpha2num(t[i])
  if S2[now] == []:
    print(-1)
    quit()
  else:
    index = bisect.bisect_left(S2[now], place)
    #if index == place:
    #  index += 1
    #print(index, S2[now])  

    
    if index == len(S2[now]):
      place = S2[now][0]
      time += 1
    else:  
      if S2[now][index] == place:
        index += 1
        if index == len(S2[now]):
          place = S2[now][0]
          time += 1
        else:
          place = S2[now][index]
      else:  
        place = S2[now][index]
  #print(place, time)  
    
    
ans = len(s) * time + place + 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import time
N = int(input())
s = [str(input()) for i in range(N)]

e = []
f = [0] * N
j = 0
ans = 0
for i in range(N):
  s[i] = "".join(sorted(s[i]))
#print(s)

for i in range(N):
  if s[i] not in e:
    e.append(s[i])
    f[j] = 1
    j += 1
  else:
    a = e.index(s[i])
    ans += f[a]
    f[a] += 1

print(ans)

Fixed submission:
import time
N = int(input())
s = [str(input()) for i in range(N)]

j = 0
ans = 0
for i in range(N):
  s[i] = "".join(sorted(s[i]))
#print(s)

s = sorted(s)
tango = "yeeeh"
x = 0
#print(s)
for i in range(N):
  if s[i] == tango:
    x += 1
  else:
    ans += x * (x + 1) //2
    x = 0
  tango = s[i]
ans += x * (x + 1) //2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
s = [str(input()) for i in range(N)]
#print(s)

e = []
f = [0] * N
j = 0
ans = 0
for i in range(N):
  s[i] = sorted(s[i])
  if s[i] not in e:
    e.append(s[i])
    f[j] = 1
    j += 1
  else:
    a = e.index(s[i])
    ans += f[a]
    f[a] += 1

print(ans)

Fixed submission:
import time
N = int(input())
s = [str(input()) for i in range(N)]

j = 0
ans = 0
for i in range(N):
  s[i] = "".join(sorted(s[i]))
#print(s)

s = sorted(s)
tango = "yeeeh"
x = 0
#print(s)
for i in range(N):
  if s[i] == tango:
    x += 1
  else:
    ans += x * (x + 1) //2
    x = 0
  tango = s[i]
ans += x * (x + 1) //2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
s = [str(input()) for i in range(N)]
#print(s)

for i in range(N):
  s[i] = sorted(s[i])

e = []
f = [0] * N
j = 0
ans = 0
for i in range(N):
  if s[i] not in e:
    e.append(s[i])
    f[j] = 1
    j += 1
  else:
    a = e.index(s[i])
    ans += f[a]
    f[a] += 1

print(ans)

Fixed submission:
import time
N = int(input())
s = [str(input()) for i in range(N)]

j = 0
ans = 0
for i in range(N):
  s[i] = "".join(sorted(s[i]))
#print(s)

s = sorted(s)
tango = "yeeeh"
x = 0
#print(s)
for i in range(N):
  if s[i] == tango:
    x += 1
  else:
    ans += x * (x + 1) //2
    x = 0
  tango = s[i]
ans += x * (x + 1) //2

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
ab = [list(map(int, input().split())) for i in range(n)]
ab = sorted(ab)
income = 0
day = 1 #残り日数
i = 0
list1 = []

while (day <= m):
  if i <= n-1:
    if (ab[i][0] <= day):
      list1.append(ab[i])
      i += 1 
    else:
      day += 1
      if list1 != []:
        p = max(list1, key = lambda x:x[1])
        income += p[1]
        list1.pop(list1.index(p))
      #print(day,i,income)
  else:
    day += 1
    if list1 != []:
      p = max(list1, key = lambda x:x[1])
      income += p[1]
      list1.pop(list1.index(p))
      
print(income)

Fixed submission:
from heapq import heappop, heappush 
N, M = map(int, input().split())
score = 0
AB = [[] for i in range(M)]
for i in range(N):
  a, b = map(int, input().split())
  if M - a >= 0:
    AB[M - a].append(b)
  
#print(AB)
queue = []
for i in range(1, M + 1):
  for j in AB[-i]:
    heappush(queue, -j)
  if queue != []:
    score += -1 * heappop(queue)
  
  #print(score, queue)  
print(score)

Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
ab = [list(map(int, input().split())) for i in range(n)]
ab = sorted(ab)
income = 0
day = 1 #残り日数
i = 0
list1 = []

while (day <= m):
  if i <= n-1:
    if (ab[i][0] <= day):
      list1.append(ab[i])
      i += 1 
    else:
      day += 1
      p = max(list1, key = lambda x:x[1])
      income += p[1]
      list1.pop(list1.index(p))
      #print(day,i,income)
  else:
    day += 1
    p = max(list1, key = lambda x:x[1])
    income += p[1]
    list1.pop(list1.index(p))
      
print(income)

Fixed submission:
from heapq import heappop, heappush 
N, M = map(int, input().split())
score = 0
AB = [[] for i in range(M)]
for i in range(N):
  a, b = map(int, input().split())
  if M - a >= 0:
    AB[M - a].append(b)
  
#print(AB)
queue = []
for i in range(1, M + 1):
  for j in AB[-i]:
    heappush(queue, -j)
  if queue != []:
    score += -1 * heappop(queue)
  
  #print(score, queue)  
print(score)

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
ab = [list(map(int, input().split())) for i in range(n)]
ab = sorted(ab, key=lambda x:x[1], reverse = True)
income = 0
day = 1 #残り日数
i = 0

while day <= m:
  if ab[i][0] <= day:
    income += ab[i][1]
    ab.pop(i)
    day += 1
    i = 0
  else:
    i += 1
  if i >= len(ab):
    day += 1
    i = 0
  #print(day,i,income)
  
print(income)

Fixed submission:
from heapq import heappop, heappush 
N, M = map(int, input().split())
score = 0
AB = [[] for i in range(M)]
for i in range(N):
  a, b = map(int, input().split())
  if M - a >= 0:
    AB[M - a].append(b)
  
#print(AB)
queue = []
for i in range(1, M + 1):
  for j in AB[-i]:
    heappush(queue, -j)
  if queue != []:
    score += -1 * heappop(queue)
  
  #print(score, queue)  
print(score)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
H = list(map(int, input().split()))
count = 0
max_i = 0
H.append(10**9 + 2)
for i in range(N):
  if H[i] > H[i + 1] + 1:
    count += 1
  if max_i - H[i] > 1:
    count += 1
  max_i = max(H[:i+1])

    
if count == 0:
  print("Yes")
else:
  print("No")

Fixed submission:
N = int(input())
H = list(map(int, input().split()))
count = 0
max_i = 0
H.append(10**9 + 2)
for i in range(N):
  if H[i] > H[i + 1] + 1:
    count += 1
  if max_i - H[i] > 1:
    count += 1
  max_i = max(max_i,H[i])

    
if count == 0:
  print("Yes")
else:
  print("No")

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
H = list(map(int, input().split()))
count = 0
max_i = 0
for i in range(N-1):
  if H[i] > H[i + 1] + 1:
    count += 1
for i in range(N):
  if max_i - H[i] > 1:
    count += 1
  max_i = max(H[:i+1])

    
if count == 0:
  print("Yes")
else:
  print("No")

Fixed submission:
N = int(input())
H = list(map(int, input().split()))
count = 0
max_i = 0
H.append(10**9 + 2)
for i in range(N):
  if H[i] > H[i + 1] + 1:
    count += 1
  if max_i - H[i] > 1:
    count += 1
  max_i = max(max_i,H[i])

    
if count == 0:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Time Limit Exceeded):
S = str(input())
N = len(S)
H = [1] * N
list1 = [H]

def roop(s,h,n):
  h_new = [0]*n
  if s[1] == "L":
    h_new[0] = h[1]
  if s[n-2] == "R":
    h_new[n-1] = h[n-2]
  for i in range(1,n-1):
    l, r = 0, 0
    if s[i-1] == "R":
      r = 1
    if s[i+1] == "L":
      l = 1
    h_new[i] = h[i-1]*r+ h[i+1]*l 
  return h_new
H = roop(S,H,N)

while H not in list1:
  list1.append(H)
  H = roop(S,H,N)
  
num = list1.index(H)
if (num-1) % 2 == 0:
  H = list1[-1]
  
for i in range(N):
  print(H[i], end = " ")


Fixed submission:
S = str(input())
N = len(S)

con = []
border = []
for i in range(N - 1):
  if S[i] == "L" and S[i + 1] == "R":
    border.append(i)
  elif S[i] == "R" and S[i + 1] == "L":
    con.append(i)
  
border.append(N - 1)  

#print(border, con)    

ans = [0] * N
now = -1
for i in range(len(con)):
  #con[i] と con[i] + 1 に
  #now - border[i] の数があつまる。
  pp = border[i] - now
  if pp % 2 == 0:
    ans[con[i]] += pp / 2
    ans[con[i] + 1] += pp / 2
  else:
    if (con[i] - now) % 2 == 0:
      ans[con[i]] += (pp - 1) / 2
      ans[con[i] + 1] += (pp + 1) / 2     
    else:
      ans[con[i]] += (pp + 1) / 2
      ans[con[i] + 1] += (pp - 1) / 2       
  now = border[i]
  #print(pp, ans)  
  
  
for i in range(N):
  print(int(ans[i]), end = " ")

Buggy python submission (verdict: Time Limit Exceeded):
S = str(input())
N = len(S)
H = [1] * N
list1 = [H]

def roop(s,h,n):
  h_new = [0]*n
  if s[1] == "L":
    h_new[0] = h[1]
  if s[n-2] == "R":
    h_new[n-1] = h[n-2]
  for i in range(1,n-1):
    l, r = 0, 0
    if s[i-1] == "R":
      r = 1
    if s[i+1] == "L":
      l = 1
    h_new[i] = h[i-1]*r+ h[i+1]*l 
  return h_new
H = roop(S,H,N)

while H not in list1:
  list1.append(H)
  H = roop(S,H,N)
  
num = list1.index(H)
if (num-1) % 2 == 0:
  H = list1[-1]
  
for i in range(N):
  print(H[i], end = " ")


Fixed submission:
S = str(input())
N = len(S)

con = []
border = []
for i in range(N - 1):
  if S[i] == "L" and S[i + 1] == "R":
    border.append(i)
  elif S[i] == "R" and S[i + 1] == "L":
    con.append(i)
  
border.append(N - 1)  

#print(border, con)    

ans = [0] * N
now = -1
for i in range(len(con)):
  #con[i] と con[i] + 1 に
  #now - border[i] の数があつまる。
  pp = border[i] - now
  if pp % 2 == 0:
    ans[con[i]] += pp / 2
    ans[con[i] + 1] += pp / 2
  else:
    if (con[i] - now) % 2 == 0:
      ans[con[i]] += (pp - 1) / 2
      ans[con[i] + 1] += (pp + 1) / 2     
    else:
      ans[con[i]] += (pp + 1) / 2
      ans[con[i] + 1] += (pp - 1) / 2       
  now = border[i]
  #print(pp, ans)  
  
  
for i in range(N):
  print(int(ans[i]), end = " ")
Buggy python submission (verdict: Time Limit Exceeded):
S = str(input())
mod = 10 ** 9 + 7

dp = [[0] * 13 for i in range(len(S))]
for i in range(len(S)):
  if i == 0:
    if S[i] == "?":
      for j in range(10):#"?"
        dp[i][j] = 1
    else:
      x = int(S[i])
      dp[i][x] = 1
  else:
    if S[i] == "?":
      for j in range(10):#"?"
        for k in range(13):
          now = (10 * k + j) % 13
          dp[i][now] += dp[i - 1][k]   
          dp[i][now] %= mod
    else:
      x = int(S[i])
      for k in range(13):
        now = (10 * k + x) % 13
        dp[i][now] += dp[i - 1][k]
        dp[i][now] %= mod
        
#print(dp)        
print(dp[-1][5] % mod)        
      
      


Fixed submission:
S = str(input())
mod = 10 ** 9 + 7

dp = [[0] * 13 for i in range(len(S))]
for i in range(len(S)):
  if i == 0:
    if S[i] == "?":
      for j in range(10):#"?"
        dp[i][j] = 1
    else:
      x = int(S[i])
      dp[i][x] = 1
  else:
    if S[i] == "?":
      for j in range(10):#"?"
        for k in range(13):
          now = (10 * k + j) % 13
          dp[i][now] += dp[i - 1][k]   
          dp[i][now] %= mod
    else:
      x = int(S[i])
      for k in range(13):
        now = (10 * k + x) % 13
        dp[i][now] += dp[i - 1][k]
        dp[i][now] %= mod
        
#print(dp)        
print(dp[-1][5] % mod)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
list1 = [int(input()) for i in range(N)]

for i in range(N):
  list2 = list1[:i]+list1[i+1:]
  print(max(list2))



Fixed submission:
N = int(input())
list1 = [int(input()) for i in range(N)]

max1 = list1.index(max(list1))
max2 = max(list1)
list2 = list1[:max1]+list1[max1+1:]
max3 = max(list2)

for i in range(N):
  if i != max1:
    print(max2)
  else:
    print(max3)
Buggy python submission (verdict: Time Limit Exceeded):
#最長増加部分列問題 (LIS) 
import bisect

N = int(input())
seq = [0] * N
for i in range(N):
  seq[i] = int(input())

LIS = [seq[0]]
#print(LIS)
for i in range(1, len(seq)):
    if seq[i] <= LIS[0]:
        LIS.insert(0, seq[i])
    else:
        LIS[bisect.bisect_left(LIS, seq[i]) - 1] = seq[i]
    #print(LIS)
#print(LIS)
print(len(LIS))

Fixed submission:
#最長増加部分列問題 (LIS) 
import bisect

N = int(input())
seq = [0] * N
for i in range(N):
  seq[i] = int(input())

LIS = [-1] * N
LIS[-1] = seq[0]
#print(LIS)
for i in range(1, len(seq)):
    LIS[bisect.bisect_left(LIS, seq[i]) - 1] = seq[i]
    #print(LIS)
#print(LIS)
c = LIS.count(-1)
print(len(LIS) - c)

Buggy python submission (verdict: Time Limit Exceeded):
#最長増加部分列問題 (LIS) 
import bisect

N = int(input())
seq = [0] * N
for i in range(N):
  seq[i] = int(input())

LIS = [seq[0]]
#print(LIS)
for i in range(1, len(seq)):
    if seq[i] <= LIS[0]:
        LIS.insert(0, seq[i])
    else:
        LIS[bisect.bisect_left(LIS, seq[i]) - 1] = seq[i]
    #print(LIS)
#print(LIS)
print(len(LIS))

Fixed submission:
#最長増加部分列問題 (LIS) 
import bisect

N = int(input())
seq = [0] * N
for i in range(N):
  seq[i] = int(input())

LIS = [-1] * N
LIS[-1] = seq[0]
#print(LIS)
for i in range(1, len(seq)):
    LIS[bisect.bisect_left(LIS, seq[i]) - 1] = seq[i]
    #print(LIS)
#print(LIS)
c = LIS.count(-1)
print(len(LIS) - c)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
s = [list(input().split( )) for i in range(N)]
#print(s[1][0])
t = sorted(s, key=lambda x:int(x[1]))
#print(t)
count = 0
for i in range(len(t)):
  sum_i = sum([int(t[j][0]) for j in range(0, i+1)])
  if int(t[i][1]) < sum_i :
    count += 1
if count != 0:
  print("No")
else:
  print("Yes")

Fixed submission:
N = int(input())
s = [list(input().split( )) for i in range(N)]
#print(s[1][0])
t = sorted(s, key=lambda x:int(x[1]), reverse = True)
#print(t)
count = 0
sum1 = sum([int(t[j][0]) for j in range(len(t))])
for i in range(len(t)):
  if int(t[i][1]) >= sum1 :
    sum1 = sum1 - int(t[i][0])
  else:
    count += 1
    sum1 = sum1 - int(t[i][0])
if count == 0:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Time Limit Exceeded):
H, W = map(int, input().split())
HW = [0] * H
for i in range(H):
  HW[i] = str(input())
  
#縦  
T = [[0] * W for i in range(H)]  
for i in range(H):#4000000
  now = 0
  for j in range(W):
    if HW[i][j] == "#":
      T[i][j] = 0
      now = 0
    else:
      now += 1
      T[i][j] = now
      
  now = 0    
  for j in range(1, W + 1):
    if T[i][-j] == 0:
      now = 0
    elif now == 0:
      now = T[i][-j]
    else:
      T[i][-j] = now
    #print(i, now)  
  
#print(T)

#横
Y = [[0] * W for i in range(H)]  
for j in range(W):#4000000
  now = 0
  for i in range(H):
    if HW[i][j] == "#":
      Y[i][j] = 0
      now = 0
    else:
      now += 1
      Y[i][j] = now
      
  now = 0    
  for i in range(1, H + 1):
    if Y[-i][j] == 0:
      now = 0
    elif now == 0:
      now = Y[-i][j]
    else:
      Y[-i][j] = now
    #print(i, now)      
#print(Y)

ans = 0
for i in range(H):
  for j in range(W):
    if T[i][j] != 0 and Y[i][j] != 0:
      ans = max(ans, T[i][j] + Y[i][j] - 1)
      
print(ans)      
    


Fixed submission:
H, W = map(int, input().split())
HW = [0] * H
for i in range(H):
  HW[i] = str(input())
  
#縦  
T = [[0] * W for i in range(H)]  
for i in range(H):#4000000
  now = 0
  for j in range(W):
    if HW[i][j] == "#":
      T[i][j] = 0
      now = 0
    else:
      now += 1
      T[i][j] = now
      
  now = 0    
  for j in range(1, W + 1):
    if T[i][-j] == 0:
      now = 0
    elif now == 0:
      now = T[i][-j]
    else:
      T[i][-j] = now
    #print(i, now)  
  
#print(T)

#横
Y = [[0] * W for i in range(H)]  
for j in range(W):#4000000
  now = 0
  for i in range(H):
    if HW[i][j] == "#":
      Y[i][j] = 0
      now = 0
    else:
      now += 1
      Y[i][j] = now
      
  now = 0    
  for i in range(1, H + 1):
    if Y[-i][j] == 0:
      now = 0
    elif now == 0:
      now = Y[-i][j]
    else:
      Y[-i][j] = now
    #print(i, now)      
#print(Y)

ans = 0
for i in range(H):
  for j in range(W):
    if T[i][j] != 0 and Y[i][j] != 0:
      ans = max(ans, T[i][j] + Y[i][j] - 1)
      
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()

count = 0

while s != s.replace('ABC', 'BCA'):
  t = s
  s = s.replace('ABC', 'BCA')
  for i in range(len(s)):
    if s[i] != t[i]:
      count += 1
      
print(count//3)

Fixed submission:
s = input()
s = s.replace('BC', 'D')
ans = 0
x = 0

#AとDだけでできた部分を考える(B,Cを挟む場合x=0とすることでreset)
#Aが出てくるたび、そのAより右にあるDは、Aを超える操作を挟むので、試行回数が増える。
for i in range(len(s)):
  if s[i] == 'A': 
    x +=1
  elif s[i] == 'D':
    ans += x
  else:
    x =0
    
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
Q = int(input())

A = []
now_a = 0
now_a_score = 0
min_score = 0
nn = 0
for i in range(Q):
  Q1 = list(map(int, input().split()))
  if len(Q1) == 3:#更新
    nn += 1
    a, b = Q1[1], Q1[2]
    A.append(a)
    A = sorted(A)
    now_a = A[int((nn - 1) / 2)]
    now_a_score = 0
    for j in range(nn):
      now_a_score += abs(A[j] - now_a) 
    #print(now_a, a, now_a_score)  
    min_score += b
  else:#求値
    print(now_a, min_score + now_a_score)
  
            
            

Fixed submission:
import heapq
Q = int(input())

A_left, A_right = [], []
A_left_sum, A_right_sum = 0, 0
heapq.heapify(A_left)
heapq.heapify(A_right)

B_sum = 0
for _ in range(Q):
    query = list(map(int,input().split()))

    if query[0] == 1:#更新クエリ
        now = query[1]#a
        B_sum += query[2]#b

        l, r = len(A_left), len(A_right)
        #中央値がA_left[0]になるように、出し入れする。
        if l <= r:
            heapq.heappush(A_right, now)
            A_right_sum += now

            out = heapq.heappop(A_right)
            A_right_sum -= out

            heapq.heappush(A_left, -out)
            A_left_sum += out
        else:
            heapq.heappush(A_left, -now)
            A_left_sum += now

            out = -heapq.heappop(A_left)
            A_left_sum -= out

            heapq.heappush(A_right, out)
            A_right_sum += out
        #print(A_right, A_left, A_right_sum, A_left_sum)   
    else:#求値クエリ
        m = -A_left[0]
        #A_left は 全て m より小さいので、　m - xi の和は
        #m * len(A_left) - (xiの和）となる。
        #xiの和が、A_left_sumである。
        #A_right も同様だが。引く数の方が大きいため、正負が入れ替わることに注意
        ans = len(A_left) * m - A_left_sum - len(A_right) * m + A_right_sum + B_sum
        print(m, ans)
Buggy python submission (verdict: Runtime Error):
N = [int(input()) for i in range(5)] 
list_sho = []
list_amari = []

for i in range(len(N)):
  list_sho.append(N[i]//10)
  list_amari.append(N[i]%10)
  
min1 = list_amari.index(min(list_amari))#あまりが最小になるうち一つの位置を取得
sum1 = 0

for i in range(len(N)):
  if N[i] % 10 == 0:
    sum1 += N[i]
  else:
    sum1 += ((N[i]//10) + 1) * 10

if N[min1]%10 == 0:
  while min(list_amari) == 0:
    list_amari.remove(0)
  sum1 =  sum1 - 10 +  min(list_amari)
  print(sum1)
else:
  sum1 = sum1 - 10 +  N[min1]%10
  print(sum1)



Fixed submission:
N = [int(input()) for i in range(5)] 
list_sho = []
list_amari = []

for i in range(len(N)):
  list_sho.append(N[i]//10)
  list_amari.append(N[i]%10)
  
min1 = list_amari.index(min(list_amari))#あまりが最小になるうち一つの位置を取得
sum1 = 0

for i in range(len(N)):
  if N[i] % 10 == 0:
    sum1 += N[i]
  else:
    sum1 += ((N[i]//10) + 1) * 10

if N[min1]%10 == 0:
  while min(list_amari) == 0:
    list_amari.remove(0)
    if len(list_amari) == 0:
      break
  if len(list_amari) == 0:
    sum1 =  sum1
  else:
    sum1 =  sum1 - 10 +  min(list_amari)
  print(sum1)
else:
  sum1 = sum1 - 10 +  N[min1]%10
  print(sum1)
Buggy python submission (verdict: Time Limit Exceeded):
X,Y,Z,K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A = sorted(A,reverse=True)
B = sorted(B,reverse=True)
C = sorted(C,reverse=True)
#print(A,B,C)

list1 = []
a,b,c = 0,0,0

for a in range(X):
  for b in range(Y):
    for c in range(Z):
      list1.append(A[a]+B[b]+C[c])

for i in range(K):
  print(max(list1))
  list1.remove(max(list1))

Fixed submission:
X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

AB = [0] * (X * Y)
for i in range(X):
  for j in range(Y):
    AB[i * Y + j] = A[i] + B[j]

AB = sorted(AB, reverse = True)[:K]
#print(AB)
ABC = []
for i in range(len(AB)):
  for j in range(Z):
    ABC.append(AB[i] + C[j])
    
ABC = sorted(ABC, reverse = True)[:K]

for i in range(K):
  print(ABC[i])
Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = str(input())
#print(lr)

for i in range(Q):
  a, b = map(int, input().split())
  m = S[a-1:b]
  ans = m.count("AC")
  print(ans)

Fixed submission:
N, Q = map(int, input().split())
S = str(input())
t = [0] * (N+1)

for i in range(N):
  if S[i:i+2] == "AC":
    x = 1
  else:
    x = 0
  t[i+1] = t[i] + x

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

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = str(input())
lr = [list(map(int, input().split())) for i in range(Q)]
#print(lr)

for i in range(Q):
  m = S[lr[i][0]-1:lr[i][1]]
  ans = m.count("AC")
  print(ans)

Fixed submission:
N, Q = map(int, input().split())
S = str(input())
t = [0] * (N+1)

for i in range(N):
  if S[i:i+2] == "AC":
    x = 1
  else:
    x = 0
  t[i+1] = t[i] + x

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