Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
a, b = map(int,input().split())

def xor_a2b(a,b) : 
    flg = a % 2 != 0
    
    if flg: a += 1
    mod = (b - a) % 4
    elif mod == 0:
        res = b
    elif mod == 1:
        res =  1
    elif mod == 2:
        res = b + 1
    else:
        res = 0
    if flg:
        return (a-1) ^ res
    else:
        return res
      
print(xor_a2b(a,b))

Fixed submission:
def xor_a2b(a,b) : 
    flg = a % 2 != 0
    
    if flg: 
        a += 1
    mod = (b - a) % 4
    if mod == 0:
        res = b
    elif mod == 1:
        res =  1
    elif mod == 2:
        res = b + 1
    else:
        res = 0
    if flg:
        return (a-1) ^ res
    else:
        return res
      
a,b = map(int,input().split())

print(xor_a2b(a,b))

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

res = A
for n in range(A+1,B+1):
  res = res ^ n
  
print(res)

Fixed submission:
def xor_a2b(a,b) : 
    flg = a % 2 != 0
    
    if flg: 
        a += 1
    mod = (b - a) % 4
    if mod == 0:
        res = b
    elif mod == 1:
        res =  1
    elif mod == 2:
        res = b + 1
    else:
        res = 0
    if flg:
        return (a-1) ^ res
    else:
        return res
      
a,b = map(int,input().split())

print(xor_a2b(a,b))
Buggy python submission (verdict: Time Limit Exceeded):
S = input().strip()
Sb = [c == "B" for c in S]

def reverse(Sb,i):
    _list = Sb.copy()
    _list[i] = not _list[i]
    return _list

def operate_onestep(Sb):
    _list = Sb.copy()
    cnt = 0
    flg = True
    while flg:
        flg = False
        for i in range(len(_list)-1):
            if _list[i] and not _list[i+1]:
                cnt += 1
                _list = reverse(_list,i)
                _list = reverse(_list,i+1)
                flg = True
    return cnt

print(operate_onestep(Sb))

Fixed submission:
S = input().strip()

w_total = 0
num_op = 0
for i,c in enumerate(S):
    if c == "W":
        w_total += 1
        num_op += i + 1 - w_total
        
print(num_op)

Buggy python submission (verdict: Runtime Error):
#S = input().strip()
Sb = [c == "B" for c in S]

def reverse(Sb,i):
    _list = Sb.copy()
    _list[i] = not _list[i]
    return _list

def operate_onestep(Sb):
    _list = Sb.copy()
    cnt = 0
    flg = True
    while flg:
        flg = False
        for i in range(len(_list)-1):
            if _list[i] and not _list[i+1]:
                cnt += 1
                _list = reverse(_list,i)
                _list = reverse(_list,i+1)
                flg = True
    return cnt

print(operate_onestep(Sb))

Fixed submission:
S = input().strip()

w_total = 0
num_op = 0
for i,c in enumerate(S):
    if c == "W":
        w_total += 1
        num_op += i + 1 - w_total
        
print(num_op)

Buggy python submission (verdict: Time Limit Exceeded):
S = input().strip()
Sb = [c == "B" for c in S]

def reverse(Sb,i):
    _list = Sb.copy()
    _list[i] = not _list[i]
    return _list

def operate(Sb):
    _list = Sb.copy()
    cnt = 0
    while True:
        for i in range(len(_list)-1):
            if _list[i] and not _list[i+1]:
                cnt += 1
                _list = reverse(_list,i)
                _list = reverse(_list,i+1)
                break
        else:
            break
    return cnt
  
print(operate(Sb))

Fixed submission:
S = input().strip()

w_total = 0
num_op = 0
for i,c in enumerate(S):
    if c == "W":
        w_total += 1
        num_op += i + 1 - w_total
        
print(num_op)
Buggy python submission (verdict: Runtime Error):
N, X = map(int, input().split())

def get_lburger(l):
    lburger = [1]
    for i in range(l):
        lburger = [0] + lburger + [1] + lburger + [0]
    return lburger

if __name__ == "__main__":
    print(sum(get_lburger(N)[:X]))

Fixed submission:
D = int(input())
assert 22 <= D <= 25
print(" ".join(["Christmas"] + ["Eve"] * (25 - D)))
Buggy python submission (verdict: Runtime Error):
S = input().strip()
print(min(int([S[i:i+3]) for i in range(0,len(S)-2,3)))

Fixed submission:
print("YES" if int(input()) in [3,5,7] else "NO")
Buggy python submission (verdict: Runtime Error):
S = input().strip()
print(min(int([S[i:i+3]) for i in range(0,len(S)-2,3)))

Fixed submission:
S = input().strip()
print(min(abs(753 - int(S[i:i+3])) for i in range(0,len(S)-2)))
Buggy python submission (verdict: Runtime Error):
def function(X):
  	B = list(range(31, 0, -1))
    res = 0
    for b in B:
        p = 2
        cp = p
        while True:
            tmp = b ** p
            if tmp > X:
                break
            else:
                res = max(res,tmp)
                if b == 1: break
                cp = p
                p += 1
    return res

X = int(input())
print(function(X))

Fixed submission:
def function(X):
    B = list(range(31, 0, -1))
    res = 0
    for b in B:
        p = 2
        cp = p
        while True:
            tmp = b ** p
            if tmp > X:
                break
            else:
                res = max(res,tmp)
                if b == 1: break
                cp = p
                p += 1
    return res

X = int(input())
print(function(X))

Buggy python submission (verdict: Runtime Error):
X = int(input())

p = 2
res = 0
for b in B:
    p = 2
    cp = p
    while True:
        tmp = b ** p
        if tmp > X:
            break
        else:
            res = max(res,tmp)
            if b == 1: break
            cp = p
            p += 1

Fixed submission:
def function(X):
    B = list(range(31, 0, -1))
    res = 0
    for b in B:
        p = 2
        cp = p
        while True:
            tmp = b ** p
            if tmp > X:
                break
            else:
                res = max(res,tmp)
                if b == 1: break
                cp = p
                p += 1
    return res

X = int(input())
print(function(X))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

def ngram(text, n):
    return [text[i:i+n] for i in range(len(text) - n + 1)]

text = input()
k = int(input())
candidates = set()
for n in range(1,len(text) + 1):
    #_ = filter(lambda x:x[1] == 1,Counter(ngram(text,n)).items())
    candidates |= set(ngram(text,n))

print(sorted(list(candidates))[k-1])

Fixed submission:
from collections import Counter

def ngram(text, n):
    return [text[i:i+n] for i in range(len(text) - n + 1)]

text = input()
k = int(input())
candidates = set()
for n in range(1,6):
    #_ = filter(lambda x:x[1] == 1,Counter(ngram(text,n)).items())
    candidates |= set(ngram(text,n))

print(sorted(list(candidates))[k-1])
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
import sys
sys.setrecursionlimit(10 ** 9)
# import numpy as np
# 答えの提出の時にi+1とj+1は忘れないように
h, w = map(int, input().split())
maze = [[-1 for i in range(w)] for j in range(h)]
ch, cw = map(int, input().split())
ch, cw = ch-1, cw-1
dh, dw = map(int, input().split())
dh, dw = dh-1, dw-1


ans = 0
for i in range(h):
    maze[i] = input()

INF = h*w
distance = [[INF for i in range(w)] for j in range(h)]

queue0 = deque()
queue0.append((ch,cw))
distance[ch][cw] = 0

queue1 = deque()

while queue0 or queue1:

    if queue0:
        y, x = queue0.popleft()
    elif queue1:
        y, x = queue1.popleft()

    for dy in range(-2, 3):
        for dx in range(-2, 3):
            ny, nx = y+dy, x+dx
            if dy == dx == 0: continue
            elif abs(dy) + abs(dx) == 1:
                if 0 <= nx < w and 0 <= ny < h:
                    if maze[ny][nx] != '#' and distance[ny][nx] > distance[y][x]:
                            queue0.append((ny, nx))
                            distance[ny][nx] = distance[y][x]
            else:
                if 0 <= nx < w and 0 <= ny < h:
                    if maze[ny][nx] != '#' and distance[ny][nx] > distance[y][x]+1:
                            queue1.append((ny, nx))
                            distance[ny][nx] = distance[y][x]+1


ans = distance[dh][dw]
if ans == INF:
    print(-1)
else:
    print(ans)


Fixed submission:
from collections import deque
import sys
sys.setrecursionlimit(10 ** 9)
# import numpy as np
# 答えの提出の時にi+1とj+1は忘れないように
h, w = map(int, input().split())
maze = [[-1 for i in range(w)] for j in range(h)]
ch, cw = map(int, input().split())
ch, cw = ch-1, cw-1
dh, dw = map(int, input().split())
dh, dw = dh-1, dw-1


ans = 0
for i in range(h):
    maze[i] = input()

INF = h*w
distance = [[INF for i in range(w)] for j in range(h)]

queue0 = deque()
queue0.append((ch,cw))
distance[ch][cw] = 0

queue1 = deque()

while queue0 or queue1:

    if queue0:
        y, x = queue0.popleft()
    elif queue1:
        y, x = queue1.popleft()

    for dy in range(-2, 3):
        for dx in range(-2, 3):
            ny, nx = y+dy, x+dx
            if dy == dx == 0: continue
            elif abs(dy) + abs(dx) == 1:
                if 0 <= nx < w and 0 <= ny < h:
                    if maze[ny][nx] != '#' and distance[ny][nx] > distance[y][x]:
                            queue0.append((ny, nx))
                            distance[ny][nx] = distance[y][x]
            else:
                if 0 <= nx < w and 0 <= ny < h:
                    if maze[ny][nx] != '#' and distance[ny][nx] > distance[y][x]+1:
                            queue1.append((ny, nx))
                            distance[ny][nx] = distance[y][x]+1


ans = distance[dh][dw]
if ans == INF:
    print(-1)
else:
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from math import sqrt
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

N = int(input())


def solv_quadratic_equation(a, b, c):
    if b**2 - 4*a*c<0:
        return 0.1, 0.1
    D = (b**2 - 4*a*c) ** (1/2)
    x_1 = (-b + D) / (2 * a)
    x_2 = (-b - D) / (2 * a)

    return x_1, x_2

for n in range(1,N+1):
    ans=0
    for x in range(1,int(sqrt(n))+1):
        for y in range(1,int(sqrt(n))+1):
            z1,z2=solv_quadratic_equation(1,x+y, x**2+y**2+x*y-n)
            if z1.is_integer() and z1>=1:
                ans+=1
            if z2.is_integer() and z2>=1:
                ans+=1

    print(ans)


Fixed submission:
from math import sqrt
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

N = int(input())

def solv_quadratic_equation(a, b, c):
    D2 = b**2 - 4*a*c
    if D2<0:
        return 0.1, 0.1
    D = sqrt(D2)
    x_1 = (-b + D) / (2 * a)
    x_2 = (-b - D) / (2 * a)

    return x_1, x_2

for n in range(1,N+1):
    ans=0
    if n < 6:
        print(0)
        continue
    for x in range(1,int(sqrt(n-3))+1):
        for y in range(1,int(sqrt(n-3))+1):
            z1,z2=solv_quadratic_equation(1,x+y, x**2+y**2+x*y-n)
            if z1.is_integer() and z1>=1:
                ans+=1
            if z2.is_integer() and z2>=1:
                ans+=1

    print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

n = int(input())

ans = []

def Base_10_to_n(X, n, ans):
    if (int(X/n)):
        if X%n==0:
            ans.append('z')
            return
        else:
            ans.append(chr(ord('a')-1+(X%n)))
            return Base_10_to_n(int(X/n), n, ans)+str(X%n)
    ans.append(chr(ord('a')-1+(X%n)))
    return str(X%n)

num  = Base_10_to_n(n,26, ans)

ans.reverse()

print(*ans,sep='')

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

n = int(input())
n-=1

ans = []

def Base_10_to_n(X, n, ans):
    if (int(X/n)):
        ans.append(chr(ord('a')+(X%n)))
        return Base_10_to_n(int(X/n)-1, n, ans)+str(X%n)
    ans.append(chr(ord('a')+(X%n)))
    return str(X%n)

num  = Base_10_to_n(n,26, ans)

ans.reverse()

print(*ans,sep='')
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

t = int(input())

nabcd = [tuple(map(int,input().split())) for i in range(t)]

INF = float('inf')
from functools import lru_cache
@lru_cache(None)
def dfs(now,cost,a,b,c,d):
    if now == 0:
        return cost
    elif now == 1:
        return cost + d
    elif now == 2:
        return min(cost+d+a, cost+d*2)
    elif now <0:
        return INF

    tmp = cost + now*d

    # over 2
    sho = now//2+1
    fusoku = sho*2 - now
    over2 = dfs(sho,cost+d*fusoku+a,a,b,c,d)

    # not over 2
    sho = now//2
    amari = now-sho*2
    nver2 = dfs(sho,cost+d*amari+a,a,b,c,d)

    # over 3
    sho = now//3+1
    fusoku = sho*3 - now
    over3 = dfs(sho,cost+d*fusoku+b,a,b,c,d)

    # not over 3
    sho = now//3
    amari = now-sho*3
    nver3 = dfs(sho,cost+d*amari+b,a,b,c,d)

    # over 5
    sho = now//5+1
    fusoku = sho*5 - now
    over5 = dfs(sho,cost+d*fusoku+c,a,b,c,d)

    # not over 5
    sho = now//5
    amari = now-sho*5
    nver5 = dfs(sho,cost+d*amari+c,a,b,c,d)

    return min(tmp,over2,nver2,over3,nver3,over5,nver5)


for n,a,b,c,d in nabcd:
    ans = dfs(n,0,a,b,c,d)
    print(ans)


Fixed submission:
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

t = int(input())

nabcd = [tuple(map(int,input().split())) for i in range(t)]

INF = float('inf')
from functools import lru_cache

for n,a,b,c,d in nabcd:

    @lru_cache(None)
    def dfs(now):
        if now == 0:
            return 0
        elif now == 1:
            return d
        elif now == 2:
            return min(d+a, d*2)
        elif now <0:
            return INF

        tmp = now*d

        # over 2
        sho = now//2+1
        fusoku = sho*2 - now
        over2 = dfs(sho)+d*fusoku+a

        # not over 2
        sho = now//2
        amari = now-sho*2
        nver2 = dfs(sho)+d*amari+a

        # over 3
        sho = now//3+1
        fusoku = sho*3 - now
        over3 = dfs(sho)+d*fusoku+b

        # not over 3
        sho = now//3
        amari = now-sho*3
        nver3 = dfs(sho)+d*amari+b

        # over 5
        sho = now//5+1
        fusoku = sho*5 - now
        over5 = dfs(sho)+d*fusoku+c

        # not over 5
        sho = now//5
        amari = now-sho*5
        nver5 = dfs(sho)+d*amari+c

        return min(tmp,over2,nver2,over3,nver3,over5,nver5)

    ans = dfs(n)
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

n, m = map(int, input().split())
ab = [tuple(map(int,input().split())) for i in range(m)]
es = [[] for i in range(n)]
for a,b in ab:
    a,b = a-1,b-1
    es[a].append(b)
    es[b].append(a)

INF = float('inf')
dist = [INF]*n # dfsの条件式の書き換えに注意

ans = [-1]*(n)

from functools import lru_cache
@lru_cache(None)
def dfs(now,d):
    for next_v in es[now]:
        if dist[next_v] > d+1:
            dist[next_v] = d+1
            ans[next_v] = now+1
            dfs(next_v, dist[next_v])

start = 0
dist[start]=0 #初期化
dfs(start,0)

print('Yes')
print(*ans[1:],sep='\n')


Fixed submission:
import heapq
n,m = map(int,input().split())
src = [tuple(map(int,input().split())) for i in range(m)]

es = [[] for i in range(n)]
for x,y in src:
    x,y = x-1,y-1
    es[x].append(y)
    es[y].append(x)

INF = float('inf')
ds = [INF] * n
ans = [-1]*(n)

def dijkstra(start, dists):
    dists[start] = 0
    hq = [(0,start)]
    heapq.heapify(hq)
    while hq:
        dist,v = heapq.heappop(hq)
        for to in es[v]:
            if dist+1 >= dists[to]: continue
            dists[to] = dist+1
            ans[to]=v+1
            heapq.heappush(hq, (dist+1,to))

dijkstra(0,ds)

print('Yes')
print(*ans[1:],sep='\n')

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

n, m = map(int, input().split())
ab = [tuple(map(int,input().split())) for i in range(m)]
es = [[] for i in range(n)]
for a,b in ab:
    a,b = a-1,b-1
    es[a].append(b)
    es[b].append(a)

INF = float('inf')
dist = [INF]*n # dfsの条件式の書き換えに注意

ans = [-1]*(n)

def dfs(now):
    for next_v in es[now]:
        if dist[next_v] > dist[now]+1:
            dist[next_v] = dist[now]+1
            ans[next_v] = now+1
            dfs(next_v)

start = 0
dist[start]=0 #初期化
dfs(start)

print('Yes')
print(*ans[1:],sep='\n')


Fixed submission:
import heapq
n,m = map(int,input().split())
src = [tuple(map(int,input().split())) for i in range(m)]

es = [[] for i in range(n)]
for x,y in src:
    x,y = x-1,y-1
    es[x].append(y)
    es[y].append(x)

INF = float('inf')
ds = [INF] * n
ans = [-1]*(n)

def dijkstra(start, dists):
    dists[start] = 0
    hq = [(0,start)]
    heapq.heapify(hq)
    while hq:
        dist,v = heapq.heappop(hq)
        for to in es[v]:
            if dist+1 >= dists[to]: continue
            dists[to] = dist+1
            ans[to]=v+1
            heapq.heappush(hq, (dist+1,to))

dijkstra(0,ds)

print('Yes')
print(*ans[1:],sep='\n')
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

n = int(input())
a = list( map(int, input().split()))

from collections import defaultdict
ar = defaultdict(list)
al = defaultdict(list)

for i in range(n):
    al[i+a[i]].append(i)
    ar[i-a[i]].append(i)

mi = 0-max(a)
ma = n+max(a)

ans = 0
for i in range(mi,ma):
    ans += len(ar[i]) * len(al[i])

print(ans)



Fixed submission:
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

n = int(input())
a = list( map(int, input().split()))

from collections import defaultdict
ar = defaultdict(list)
al = defaultdict(list)

for i in range(n):
    al[i+a[i]].append(i)
    ar[i-a[i]].append(i)

x = al.keys()

ans = 0
for i in x:
    ans += len(ar[i]) * len(al[i])

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

n = int(input())
a = list( map(int, input().split()))

from collections import defaultdict
ar = defaultdict(list)
al = defaultdict(list)

for i in range(n):
    al[i+a[i]].append(i)
    ar[i-a[i]].append(i)

mi = 0-max(a)
ma = n+max(a)

ans = 0
for i in range(mi,ma):
    ans += len(ar[i]) * len(al[i])

print(ans)




Fixed submission:
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

n = int(input())
a = list( map(int, input().split()))

from collections import defaultdict
ar = defaultdict(list)
al = defaultdict(list)

for i in range(n):
    al[i+a[i]].append(i)
    ar[i-a[i]].append(i)

x = al.keys()

ans = 0
for i in x:
    ans += len(ar[i]) * len(al[i])

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

n = int(input())
a = list( map(int, input().split()))

ans = []
for i in range(n):
    h = a[i]
    for j in range(0,i-a[i]-1):
        if h + a[j] == abs(j-i):
            ans.append((i,j))
            ans.append((j,i))
    for j in range(a[i]+1,n):
        if h + a[j] == abs(j-i):
            ans.append((i,j))
            ans.append((j,i))

sans = set(ans)

print(len(sans)//2)

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

n = int(input())
a = list( map(int, input().split()))

from collections import defaultdict
ar = defaultdict(list)
al = defaultdict(list)

for i in range(n):
    al[i+a[i]].append(i)
    ar[i-a[i]].append(i)

x = al.keys()

ans = 0
for i in x:
    ans += len(ar[i]) * len(al[i])

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

n = int(input())
s = input() #sys.stdin.readlineは最後が改行

r = [0]*n
g = [0]*n
b = [0]*n

for i in range(n):
    if s[i] == 'R':r[i]+=1
    elif s[i] == 'G':g[i]+=1
    else: b[i]+=1

from itertools import accumulate
r_nokori = list(reversed(r))
r_nokori = list(reversed(list(accumulate(r_nokori))))
g_nokori = list(reversed(g))
g_nokori = list(reversed(list(accumulate(g_nokori))))
b_nokori = list(reversed(b))
b_nokori = list(reversed(list(accumulate(b_nokori))))

ans = 0

for i in range(n-2):
    for j in range(i+1,n-1):
        if s[i]==s[j]: continue

        if (s[i]=='R' and s[j]=='G') or (s[i]=='G' and s[j]=='R'):
            ans += b_nokori[j+1]
            if 2*j-i <= n:
                if s[2*j-i] == 'B': ans-= 1

        if (s[i]=='G' and s[j]=='B') or (s[i]=='B' and s[j]=='G'):
            ans += r_nokori[j+1]
            if 2*j-i <= n:
                if s[2*j-i] == 'R': ans-= 1

        if (s[i]=='B' and s[j]=='R') or (s[i]=='R' and s[j]=='B'):
            ans += g_nokori[j+1]
            if 2*j-i <= n:
                if s[2*j-i] == 'G': ans-= 1

print(ans)


Fixed submission:
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

n = int(input())
s = input() #sys.stdin.readlineは最後が改行

r = [0]*n
g = [0]*n
b = [0]*n

for i in range(n):
    if s[i] == 'R':r[i]+=1
    elif s[i] == 'G':g[i]+=1
    else: b[i]+=1

from itertools import accumulate
r_nokori = list(reversed(r))
r_nokori = list(reversed(list(accumulate(r_nokori))))
g_nokori = list(reversed(g))
g_nokori = list(reversed(list(accumulate(g_nokori))))
b_nokori = list(reversed(b))
b_nokori = list(reversed(list(accumulate(b_nokori))))

ans = 0

for i in range(n-2):
    for j in range(i+1,n-1):
        if s[i]==s[j]: continue

        if (s[i]=='R' and s[j]=='G') or (s[i]=='G' and s[j]=='R'):
            ans += b_nokori[j+1]
            if 2*j-i <= n:
                if s[2*j-i] == 'B': ans-= 1

        if (s[i]=='G' and s[j]=='B') or (s[i]=='B' and s[j]=='G'):
            ans += r_nokori[j+1]
            if 2*j-i <= n:
                if s[2*j-i] == 'R': ans-= 1

        if (s[i]=='B' and s[j]=='R') or (s[i]=='R' and s[j]=='B'):
            ans += g_nokori[j+1]
            if 2*j-i <= n:
                if s[2*j-i] == 'G': ans-= 1

print(ans)
Buggy python submission (verdict: Runtime Error):
mport sys
sys.setrecursionlimit(10 ** 7)
from functools import lru_cache

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

if n == 1:
    print('a')
    exit()

@lru_cache(None)
def rec(before, depth, MAX):
    for i in range(MAX-ord('a') +2):
        tmp = before + chr(ord('a') + i)
        if len(tmp) >= n:
            ans.append(tmp)
        else:
            MAX = max(MAX, ord(tmp[-1]) )
            rec(tmp, depth+1, MAX)


rec('a',1, ord('a'))

ans.sort()

print(*ans, sep ='\n')


Fixed submission:
import sys
sys.setrecursionlimit(10 ** 7)
from functools import lru_cache

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

if n == 1:
    print('a')
    exit()

@lru_cache(None)
def rec(before, depth, MAX):
    for i in range(MAX-ord('a') +2):
        tmp = before + chr(ord('a') + i)
        if len(tmp) >= n:
            ans.append(tmp)
        else:
            MAX = max(MAX, ord(tmp[-1]) )
            rec(tmp, depth+1, MAX)


rec('a',1, ord('a'))

ans.sort()

print(*ans, sep ='\n')
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())

c = [0]* m
s = [0]* m
for i in range(m):
    s[i], c[i] = map(int, input().split())

flg = True

if n == 1:
    i_str = str(0)
    for j in range(m):
        if i_str[s[j]-1] != str(c[j]):
            flg = False
            continue
    if flg==True:
        print(i)
        exit()
    flg = True

for i in range(10**(n-1),10**n):
    i_str = str(i)
    for j in range(m):
        if i_str[s[j]-1] != str(c[j]):
            flg = False
            continue
    if flg==True:
        print(i)
        exit()
    flg = True

print(-1)


Fixed submission:
n, m = map(int, input().split())

c = [0]* m
s = [0]* m
for i in range(m):
    s[i], c[i] = map(int, input().split())

flg = True

if n == 1:
    i = 0
    i_str = str(i)
    for j in range(m):
        if i_str[s[j]-1] != str(c[j]):
            flg = False
            continue
    if flg==True:
        print(i)
        exit()
    flg = True

for i in range(10**(n-1),10**n):
    i_str = str(i)
    for j in range(m):
        if i_str[s[j]-1] != str(c[j]):
            flg = False
            continue
    if flg==True:
        print(i)
        exit()
    flg = True

print(-1)