Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
    a,b=map(int,input().split())
    if a<=5:
        print(0)
    elif a>=6 and 12<=a:
        print(b/2)
    else:
        print(b)

Fixed submission:
a,b=map(int,input().split())
if a<=5:
    print(0)
elif a>=6 and a<=12:
    print(b//2)
else:
    print(b)

Buggy python submission (verdict: Runtime Error):
a,b=map(int,input.split())
if a<=5:
    print(0)
elif a>=6 and 12<=a:
    print(b/2)
else:
    print(b)

Fixed submission:
a,b=map(int,input().split())
if a<=5:
    print(0)
elif a>=6 and a<=12:
    print(b//2)
else:
    print(b)
Buggy python submission (verdict: Runtime Error):
a,b=int(input()
print(max(a+b,a+a-1,b+b-1))

Fixed submission:
a,b=map(int,input().split())
print(max(a+b,a+a-1,b+b-1))
Buggy python submission (verdict: Runtime Error):
s=input()
for i in range(0,len(s)-3):
    v=abs(753 - int(s[i:i+3]))
    ss=min([ss,v])
print(ss)

Fixed submission:
s=input()
ss=753
for i in range(0,len(s)-1):
    v=abs(753 - int(s[i:i+3]))
    ss=min([ss,v])
print(ss)
Buggy python submission (verdict: Runtime Error):
n=input()
if n=="1":
  print("Hello World")
elif:
  print(int(input())+int(input()))

Fixed submission:
n=input()
if n=="1":
    print("Hello World")
else:
    print(int(input())+int(input()))
Buggy python submission (verdict: Runtime Error):
N,T = map(int,input().split())
ans = 1000
for i in N:
  c,t = map(int,input().split())
  if T >= t:
      ans = min(ans,c)
print(ans)

Fixed submission:
N,T = map(int,input().split())
ans = 1001
for i in range(N):
    c,t = map(int,input().split())
    if T >= t:
        ans = min(ans,c)
if ans == 1001:
    print("TLE")
else:
    print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
l=input().split()
a={}
for i in range(0,len(l),2):
    if l[i] in a:
        a[l[i]]+=1
    else:
        a[l[i]]=1
b={}  
for i in range(1,len(l),2):
    if l[i] in b:
        b[l[i]]+=1
    else:
        b[l[i]]=1
a = sorted(a.items(), key=lambda x:-x[1])
b = sorted(b.items(), key=lambda x:-x[1])
if a[0][0]==b[0][0]:
    m=max(a[0][1]+b[1][1],a[1][1]+b[0][1])
else:
    m=a[0][1]+b[0][1]
print(n-m)

Fixed submission:
n=int(input())
l=input().split()
a={"-1":0}
for i in range(0,len(l),2):
    if l[i] in a:
        a[l[i]]+=1
    else:
        a[l[i]]=1
b={"-1":0}  
for i in range(1,len(l),2):
    if l[i] in b:
        b[l[i]]+=1
    else:
        b[l[i]]=1
a = sorted(a.items(), key=lambda x:-x[1])
b = sorted(b.items(), key=lambda x:-x[1])
if a[0][0]==b[0][0]:
    m=max(a[0][1]+b[1][1],a[1][1]+b[0][1])
else:
    m=a[0][1]+b[0][1]
print(n-m)
Buggy python submission (verdict: Runtime Error):
a=map(int,input().split())
print("ABD" if a<1000 else "ABC")

Fixed submission:
a=int(input())
print("ABC" if a<1000 else "ABD")

Buggy python submission (verdict: Runtime Error):
a=map(int,input().split())
print("ABC" if a<1000 else "ABD")

Fixed submission:
a=int(input())
print("ABC" if a<1000 else "ABD")
Buggy python submission (verdict: Runtime Error):
n=int(input())
s={"M":0,"A":0,"R":0,"C":0,"H":0}
for i in range(n):
    v=input()
    if v[0] in s:
        s[v[0]]+=1
l=s.values()
sum=0
for a in range(5):
    for b in range(a+1,5):
        for c in range(b+1,5):
            sum+=l[a]*l[b]*l[c]         
print(sum)

Fixed submission:
n=int(input())
s={"M":0,"A":0,"R":0,"C":0,"H":0}
for i in range(n):
    v=input()
    if v[0] in s:
        s[v[0]]+=1
l=list(s.values())
ans=0
for a in range(5):
    for b in range(a+1,5):
        for c in range(b+1,5):
            ans+=l[a]*l[b]*l[c]         
print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
a.sort()
x,y=[0,0]
for i in range(n):
    if(i%2==0):
        x+=a[i]
    else:
        y+=a[i]
print(sum(x)-sum(y))

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
x,y=[0,0]
for i in range(n):
    if(i%2==0):
        x+=a[i]
    else:
        y+=a[i]
print(x-y)

Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
a.sort()
x,y=[0,0]
for i in n:
    if(i%2==0):
        x+=a[i]
    else:
        y+=a[i]
print(sum(x)-sum(y))

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
x,y=[0,0]
for i in range(n):
    if(i%2==0):
        x+=a[i]
    else:
        y+=a[i]
print(x-y)
Buggy python submission (verdict: Runtime Error):
a,b=input().split()
n=int(a+b)
print("Yes" if math.sqrt(n).is_integer() else "No")

Fixed submission:
import math
a,b=input().split()
n=int(a+b)
print("Yes" if math.sqrt(n).is_integer() else "No")

Buggy python submission (verdict: Runtime Error):
a=int(input())
print("Yes" if math.sqrt(a).is_integer() else "No")

Fixed submission:
import math
a,b=input().split()
n=int(a+b)
print("Yes" if math.sqrt(n).is_integer() else "No")

Buggy python submission (verdict: Runtime Error):
import math
a,b=input().split()
n=int(a+b)
pritn("Yes" if math.sqrt(n)%1==0 else "No")

Fixed submission:
import math
a,b=input().split()
n=int(a+b)
print("Yes" if math.sqrt(n).is_integer() else "No")
Buggy python submission (verdict: Runtime Error):
x,a,b=map(int,input().split())
if min(abs(x-a)>abs(x-b)):
  print("A")
else:
  print("B")
    

Fixed submission:
x,a,b=map(int,input().split())
if abs(x-a)<abs(x-b):
      print("A")
else:
      print("B")

Buggy python submission (verdict: Runtime Error):
x,a,b=map(int,input().split())
print(min(abs(x-a),abs(x-b))

Fixed submission:
x,a,b=map(int,input().split())
if abs(x-a)<abs(x-b):
      print("A")
else:
      print("B")
Buggy python submission (verdict: Runtime Error):
a=int(input())
b=int(input())
if a>b:
   print("GREATER")
else if a<b:
    print("LESS")
else if a==b:
    print("EQUAL")

Fixed submission:
a=int(input())
b=int(input())
if a>b:
   print("GREATER")
elif a<b:
    print("LESS")
elif a==b:
    print("EQUAL")

Buggy python submission (verdict: Runtime Error):
a=input()
b=input()
if a>b:
   print("GREATER")
else if a<b:
    print("LESS")
else if a==b:
    print("EQUAL")

Fixed submission:
a=int(input())
b=int(input())
if a>b:
   print("GREATER")
elif a<b:
    print("LESS")
elif a==b:
    print("EQUAL")
Buggy python submission (verdict: Runtime Error):
s=input()
print(s.replace("\,"," ")

Fixed submission:
s=input()
print(s.replace(","," "))
Buggy python submission (verdict: Runtime Error):
    s=list(map(int,input().split()))
    s.sort()
    if s[0]==5 and s[1]==5 and s[2]==7 :
        print("YES")
    else :
        print("NO")

Fixed submission:

s=list(map(int,input().split()))
s.sort()
if s[0]==5 and s[1]==5 and s[2]==7 :
    print("YES")
else :
    print("NO")

Buggy python submission (verdict: Runtime Error):
s=list(map(int,input().split())
s.sort()
if s[0]==5 and s[1]==5 and s[2]==7 :
    print("YES")
else :
    print("NO")


Fixed submission:

s=list(map(int,input().split()))
s.sort()
if s[0]==5 and s[1]==5 and s[2]==7 :
    print("YES")
else :
    print("NO")
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
l=[]
for _ in range(n):
  s=input()
  s=''.join(sorted(s))
  l.append(s)
c=0
for i in range(n):
  for j in range(i+1,n):
    if l[i]==l[j]:
      c=c+1
print(c)
  
  
  

Fixed submission:
from itertools import groupby
n=int(input())
l=[]
for _ in range(n):
  s=input()
  s=''.join(sorted(s))
  l.append(s)
l.sort()
c=0
for i,j in groupby(l):
  z=len(list(j))
  c=c+(z*(z-1)//2)
print(c)
Buggy python submission (verdict: Runtime Error):
N,K = map(int,input().split())
graph = list([] for _ in range(N))
for i in range(N-1):
    a,b = map(int,input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)
def f(x,y):
    r = 1
    for i in range(y):
        r = (r*(x-i))%mod
    return r
q = graph[0]
V = {0}
ans = f(K-1,len(q))
while q:
    v = q.pop()
    if v in  V:
        continue
    V.add(v)
    q += graph[v]
    ans = (f(K-2,len(graph[v])-1)*ans)%mod
print((K*ans)%mod)

Fixed submission:
from itertools import*
from math import*
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = float("inf")
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)

N,K = map(int,input().split())
graph = list([] for _ in range(N))
for i in range(N-1):
    a,b = map(int,input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)
def f(x,y):
    r = 1
    for i in range(y):
        r = (r*(x-i))%mod
    return r
q = graph[0]
V = {0}
ans = f(K-1,len(q))
while q:
    v = q.pop()
    if v in  V:
        continue
    V.add(v)
    q += graph[v]
    ans = (f(K-2,len(graph[v])-1)*ans)%mod
print((K*ans)%mod)
Buggy python submission (verdict: Runtime Error):
N,K = map(int,input().split())
Max = 2001
#二項係数とその逆元テーブルを作る前処理
fac = [0]*(Max)
finv = [0]*(Max)
inv = [0]*(Max)
fac[0]=fac[1]=1
finv[0]=finv[1]=1
inv[1]=1
for i in range(2,Max):
        fac[i] = fac[i-1] * i % mod
        inv[i] = mod - inv[mod%i]*(mod//i)%mod
        finv[i] = finv[i-1]*inv[i]%mod
#O(1)でmod計算した組合せ数を計算
def Comb(n,r):
    if n < r:
        return 0
    if n < 0 or r < 0 :
        return 0
    return fac[n]*(finv[r]*finv[n-r]%mod)%mod

for i in range(1,K+1):
    print(Comb(K-1,i-1)*Comb(N-K+1,i))

Fixed submission:
from itertools import*
from math import*
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = float("inf")
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)

N,K = map(int,input().split())
Max = 2001
#二項係数とその逆元テーブルを作る前処理
fac = [0]*(Max)
finv = [0]*(Max)
inv = [0]*(Max)
fac[0]=fac[1]=1
finv[0]=finv[1]=1
inv[1]=1
for i in range(2,Max):
        fac[i] = fac[i-1] * i % mod
        inv[i] = mod - inv[mod%i]*(mod//i)%mod
        finv[i] = finv[i-1]*inv[i]%mod
#O(1)でmod計算した組合せ数を計算
def Comb(n,r):
    if n < r:
        return 0
    if n < 0 or r < 0 :
        return 0
    return fac[n]*(finv[r]*finv[n-r]%mod)%mod

for i in range(1,K+1):
    print(Comb(K-1,i-1)*Comb(N-K+1,i)%mod)
Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
S = list(map(int,input().split()))
T = list(map(int,input().split()))
dp = [[0]*(M+1) for i in range(N+1)]

for n in range(N):
    for m in range(M):
        if S[n] == T[m]:
            dp[n+1][m+1] = (dp[n+1][m]+dp[n][m+1]+1)%mod
        else:
            dp[n+1][m+1] = dp[n+1][m]+dp[n][m+1]-dp[n][m]

print((dp[N][M]+1)%mod)

Fixed submission:
from itertools import*
from math import*
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = float("inf")
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)

N,M = map(int,input().split())
S = list(map(int,input().split()))
T = list(map(int,input().split()))
dp = [[0]*(M+1) for i in range(N+1)]

for n in range(N):
    for m in range(M):
        if S[n] == T[m]:
            dp[n+1][m+1] = (dp[n+1][m]+dp[n][m+1]+1)%mod
        else:
            dp[n+1][m+1] = dp[n+1][m]+dp[n][m+1]-dp[n][m]

print((dp[N][M]+1)%mod)
Buggy python submission (verdict: Runtime Error):
from itertools import*
from math import*
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = float("inf")
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)


N = int(input())
pair=defaultdict(int)
xy = []
for i in range(N):
    x,y = map(int,input().split())
    xy.append((x,y))
for i in range(N):
    for j in range(N):
        if i != j
        pair[(xy[j][0]-xy[i][0],xy[j][1]-xy[i][1])] += 1

m = 0
for v in pair.values():
    m = max(m,v)
print(N-m)

Fixed submission:
from itertools import*
from math import*
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = float("inf")
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)


N = int(input())
pair=defaultdict(int)
xy = []
for i in range(N):
    x,y = map(int,input().split())
    xy.append((x,y))
for i in range(N):
    for j in range(N):
        if i != j:
            pair[(xy[j][0]-xy[i][0],xy[j][1]-xy[i][1])] += 1

m = 0
for v in pair.values():
    m = max(m,v)
print(N-m)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
AB = [(A[i]/B[i],i) for i in range(3)]
AB.sort()
AB1 = deepcopy(AB)
ans = 0
M = N
for i in range(3):
    ab,j = AB1.pop(0)
    if ab >= 1:
        break
    else:
        ans += (M//A[j])*(B[j])
        M = M % A[j]
        ans += M
M = ans
ans = 0
for i in range(3):
    ab,j = AB.pop()
    if ab < 1:
        break
    else:
        ans += (M//B[j])*(A[j])
        M = M % B[j]
        ans += M
print(ans)

Fixed submission:
from itertools import*
from math import*
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = float("inf")
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)


def f(N,A,B):
    dp = [0]*(N+1)
    for i in range(N+1):
        x = i
        for j in range(3):
            if i >= A[j]:
                y = dp[i-A[j]]+B[j]
                if x < y:
                    x = y
        dp[i] = x
    return dp[N]
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
print(f(f(N,A,B),B,A))
Buggy python submission (verdict: Runtime Error):
N = int(input())
W = list(map(int,input().split()))
ans = inf
for t in range(N):
    ans = min(ans,abs(sum(W[:t])-sum(W[t:])))

print(ans)


Fixed submission:
from itertools import*
from math import*
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = float("inf")
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)

N = int(input())
W = list(map(int,input().split()))
ans = inf
for t in range(N):
    ans = min(ans,abs(sum(W[:t])-sum(W[t:])))

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())
n = len(s)
c = n-1
ans = 0
while True:
    if c <2:
        break
    if s[c-2]+s[c-1]+s[c]=="ABC":
        ans += 1
        s[c-2]="B"
        s[c-1]="C"
        s[c]="A"
        if c+2 < n:
            c +=2
    else:
        if s[c-1] !="C":
            c -=2
        else:
            c -=1

print(ans)

Fixed submission:
S = input()
S = S.replace("BC","D")

ans = 0
a = 0
for s in S:
    if s =="A":
        a += 1
    elif s =="D":
        ans += a
    else:
        a = 0

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import*
import math
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = float("inf")
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)

s = list(input())
n = len(s)
c = n-1
ans = 0
while True:
    if c <2:
        break
    if s[c-2]+s[c-1]+s[c]=="ABC":
        ans += 1
        s[c-2]="B"
        s[c-1]="C"
        s[c]="A"
        if c+2 < n:
            c +=2
    else:
        c -=1

print(ans)

Fixed submission:
S = input()
S = S.replace("BC","D")

ans = 0
a = 0
for s in S:
    if s =="A":
        a += 1
    elif s =="D":
        ans += a
    else:
        a = 0

print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
D =[[] for i in range(N+1)]
for i in range(N-1):
    a,b = map(int,input().split())
    D[a].append(b)
    D[b].append(a)

c = sorted(list(map(int,input().split())))
vcost = [-1]*(N+1)
vcost[1]=c.pop()
ans = 0
def dfs(i):
    global ans
    for j in D[i]:
        if vcost[j]==-1:
            vcost[j]=c.pop()
            ans += vcost[j]
            dfs(j)
dfs(1)
print(ans)
print(*vcost[1:])

Fixed submission:
from itertools import*
import math
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = float("inf")
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)

N = int(input())
D =[[] for i in range(N+1)]
for i in range(N-1):
    a,b = map(int,input().split())
    D[a].append(b)
    D[b].append(a)

c = sorted(list(map(int,input().split())))
vcost = [-1]*(N+1)
vcost[1]=c.pop()
ans = 0
def dfs(i):
    global ans
    for j in D[i]:
        if vcost[j]==-1:
            vcost[j]=c.pop()
            ans += vcost[j]
            dfs(j)
dfs(1)
print(ans)
print(*vcost[1:])
Buggy python submission (verdict: Runtime Error):
n,m,k = map(int,input().split())
Max = n*m
#二項係数とその逆元テーブルを作る前処理
fac = [0]*(Max)
finv = [0]*(Max)
inv = [0]*(Max)
fac[0]=fac[1]=1
finv[0]=finv[1]=1
inv[1]=1
for i in range(2,Max):
        fac[i] = fac[i-1] * i % mod
        inv[i] = mod - inv[mod%i]*(mod//i)%mod
        finv[i] = finv[i-1]*inv[i]%mod
#O(1)でmod計算した組合せ数を計算
def C(n,r):
    if n < r:
        return 0
    if n < 0 or r < 0 :
        return 0
    return fac[n]*(finv[r]*finv[n-r]%mod)%mod
#mod計算した順列の計算
def P(n,r):
    if n < r:
        return 0
    if n<0 or r<0:
        return 0
    return (fac[n]*finv[n-r])%mod


c = C(n*m-2,k-2)
res = 0

for i in range(1,n):
    res += i * (n-i) *(m**2)*c
    res %= mod

for i in range(1,m):
    res += i*(m-i)*(n**2)*c
    res %= mod
print(res)

Fixed submission:
from itertools import*
import math
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = float("inf")
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)

n,m,k = map(int,input().split())
Max = n*m
#二項係数とその逆元テーブルを作る前処理
fac = [0]*(Max)
finv = [0]*(Max)
inv = [0]*(Max)
fac[0]=fac[1]=1
finv[0]=finv[1]=1
inv[1]=1
for i in range(2,Max):
        fac[i] = fac[i-1] * i % mod
        inv[i] = mod - inv[mod%i]*(mod//i)%mod
        finv[i] = finv[i-1]*inv[i]%mod
#O(1)でmod計算した組合せ数を計算
def C(n,r):
    if n < r:
        return 0
    if n < 0 or r < 0 :
        return 0
    return fac[n]*(finv[r]*finv[n-r]%mod)%mod
#mod計算した順列の計算
def P(n,r):
    if n < r:
        return 0
    if n<0 or r<0:
        return 0
    return (fac[n]*finv[n-r])%mod


c = C(n*m-2,k-2)
res = 0

for i in range(1,n):
    res += i * (n-i) *(m**2)*c
    res %= mod

for i in range(1,m):
    res += i*(m-i)*(n**2)*c
    res %= mod
print(res)
Buggy python submission (verdict: Runtime Error):
from itertools import accumulate
import math
from collections import deque
from collections import defaultdict
from itertools import permutations
import heapq
import bisect
from collections import Counter
from itertools import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = 10**10
from functools import reduce

h,w,n = map(int,input().split())
sr,sc = map(int,input().split())
s = input()
t = input()
l = 1
r = w
u = 1
d = h
for s,t in zip(s[::-1],t[::-1]):
    if t == "R":
        l = max(l-1,1)
    elif t == "L":
        r = min(r+1,w)
    elif t =="U":
        d = min(d+1,h)
    else:
        u = max(u-1,1)

    if s == "L":
        l += 1
    elif s =="R":
        r -=1
    elif s =="U":
        u+=1
    else:
        d-=1
    if l > r or u > d:
        print('NO')
        exit()
if u <= sr <= d and l <= sc <= r:
    print("YES")
else:
    print("NO")

Fixed submission:
from itertools import*
from math import*
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = float("inf")
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)

H,W = map(int,input().split())
A = list(list(input()) for _ in range(H))
dirc = [(0,1),(1,0),(0,-1),(-1,0)]
q = deque()
for i in range(H):
    for j in range(W):
        if A[i][j] =="#":
            A[i][j] = 0
            q.append((i,j))
ans = 0
while q:
    y,x = q.popleft()
    for dy,dx in dirc:
        if 0<=dy+y<H and 0<=dx+x<W and A[dy+y][dx+x]==".":
            A[dy+y][dx+x] = A[y][x]+1
            ans = max(ans,A[dy+y][dx+x])
            q.append((dy+y,dx+x))

print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))
dp = [[0]*2 for i in range(n+1)]
dp[0][1] = -inf
for i in range(n):
    dp[i+1][0] = max(dp[i][0]+a[i],dp[i][1]-a[i])
    dp[i+1][1] = max(dp[i][0]-a[i],dp[i][1]+a[i])
print(max(dp[n][0],dp[n][1]))

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
l=[]
j=0
ans = sum(a)
for i in range(n):
    if a[i] <0:
        a[i] *=-1
        j +=1
b = sum(a)
if j%2 == 0:
    print(b)
else:
    for i in range(n):
        ans=max(ans,b-2*a[i])
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):

N,Q = map(int,input().split())
S = input()

A=[[] for _ in range(26)]
for i in range(len(S)):
    A[int(ord(S[i]))-65].append(i)
#print(A)
g = [1]*(N)
#print(g)
for i in range(Q):
    t,d = input().split()
    for h in A[ord(t)-65]:
        if h == 0 and d=='L':
            g[0] = 0
        if h == N-1 and d=='R':
            g[N-1] = 0
        if h<N-1 and d=='R':
            tmp = g[h]
            g[h] = 0
            g[h+1] += tmp
        if h>0 and d=='L':
            tmp = g[h]
            g[h] = 0
            g[h-1] += tmp
sum = 0
for i in range(N):
    sum += g[i]
print(sum)

Fixed submission:
N,Q = map(int,input().split())
S = input()
td = [input().split() for _ in range(Q)]
def solve(i):
    cur = i
    for t,d in td:
        if S[cur] == t:
            cur += 1 if d=='R' else -1
        if cur < 0 or cur >= N:
            return False
    return True
 
def binary_search(ok,ng):
    while abs(ok-ng) >1:
        mid = (ok+ng)//2
        if solve(mid):
            ok = mid
        else:
            ng = mid
    return ok

print(max(0,binary_search(-1,N)-binary_search(N,-1)+1))
Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().split())
S = str(input())
cnt0 = S.count("AC")
cnt = []

for i in range(0,N):
 sli = S[i:]
 cnt1 = sli.count("AC")
 cnt.append(cnt1)

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


Fixed submission:
N,Q = map(int,input().split())
S = (input())
cnt = [0] * (N + 1)
for i in range(N):
 if S[i:i+2] == "AC":
  cnt[i+1] = cnt[i] + 1
 else:
  cnt[i+1] = cnt[i]

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

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


Fixed submission:
N,Q = map(int,input().split())
S = (input())
cnt = [0] * (N + 1)
for i in range(N):
 if S[i:i+2] == "AC":
  cnt[i+1] = cnt[i] + 1
 else:
  cnt[i+1] = cnt[i]

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

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


Fixed submission:
N,Q = map(int,input().split())
S = (input())
cnt = [0] * (N + 1)
for i in range(N):
 if S[i:i+2] == "AC":
  cnt[i+1] = cnt[i] + 1
 else:
  cnt[i+1] = cnt[i]

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

Buggy python submission (verdict: Runtime Error):
import sys
import os
f = open("C:/Users/kazuki/Documents/python/import.txt","r")
sys.stdin = f

# -*- coding: utf-8 -*-
N,Q = map(int,input().split())
S = str(input())
ls =[]
rs = []
for i in range(0,Q):
 l,r = map(int,input().split())
 slice = S[l-1:r]
 cnt = slice.count("AC")
 print(cnt)


Fixed submission:
N,Q = map(int,input().split())
S = (input())
cnt = [0] * (N + 1)
for i in range(N):
 if S[i:i+2] == "AC":
  cnt[i+1] = cnt[i] + 1
 else:
  cnt[i+1] = cnt[i]

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

Buggy python submission (verdict: Runtime Error):
N,Q = map(int,input().split())
S = str(input())
for i in range(1,N+1):
 l,r = map(int,input().split())
 slice = S[l-1:r]
 cnt = slice.count("AC")
 print(cnt)

Fixed submission:
N,Q = map(int,input().split())
S = (input())
cnt = [0] * (N + 1)
for i in range(N):
 if S[i:i+2] == "AC":
  cnt[i+1] = cnt[i] + 1
 else:
  cnt[i+1] = cnt[i]

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