Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
D = list(map(int,input().split()))
while True:
  dis = False
  for d in D:
    if d in str(n):
      dis = True
      break
  if not dis:
    break
  n += 1
print(n)

Fixed submission:
n,k = map(int,input().split())
D = list(map(int,input().split()))
while True:
  dis = False
  for d in D:
    if str(d) in str(n):
      dis = True
      break
  if not dis:
    break
  n += 1
print(n)
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split(" "))

c=abs(n-k)
d=abs(c-k)
if(c+d==k):
    if(c>d):
        print(d)
    else:
        print(c)

if(k%n==0):
    if(n>k):
        print(0)
    else:
        print(n) 
    exit()

if(n>k):
    a=n-k*(n//k)
    b=k*(n//k+1)-n
    if(a>b):
        print(b)
    else:
        print(a)


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

c=abs(n-k)
d=abs(c-k)
if(c+d==k):
    if(c>d):
        print(d)
    else:
        print(c)
    exit()
if(n>=k):
    if(n%k==0):
        print(0)
        exit()
    else:
        a=n-k*(n//k)
        b=k*(n//k+1)-n
        if(a>b):
            print(b)
        else:
            print(a)
        exit()
else:
    
    while(1):
        a=abs(n-k)
        if(n>a):
            n=a
        else:
            print(n)
            exit()

Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split(" "))

flag=0
if(n>k):
    flag=1
    temp=n
    n=k
    k=temp

if(k%n==0):
    if(flag==1):
        print(0)
    else:
        print(n) 
    exit()


a=int(k/n)
b=a+1
if(flag==1):
    if(k-n*a<=n*b-k):
        print(k-n*a)
    else:
        print(n*b-k)
else:
    c=abs(n-k)
    d=abs(c-k)
    if(c>d):
        print(d)
    else:
        print(c)


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

c=abs(n-k)
d=abs(c-k)
if(c+d==k):
    if(c>d):
        print(d)
    else:
        print(c)
    exit()
if(n>=k):
    if(n%k==0):
        print(0)
        exit()
    else:
        a=n-k*(n//k)
        b=k*(n//k+1)-n
        if(a>b):
            print(b)
        else:
            print(a)
        exit()
else:
    
    while(1):
        a=abs(n-k)
        if(n>a):
            n=a
        else:
            print(n)
            exit()
Buggy python submission (verdict: Time Limit Exceeded):
q1=list(map(int,input().split(" ")))
a1=list(map(int,input().split(" ")))

sumsum=0
for i in range(q1[0]-q1[1]+1):
    sum1=sum(a1[i:i+q1[1]])
    if(sumsum<sum1):
        sumsum=sum1
sumsum+=q1[1]
print(sumsum/2)


Fixed submission:
q1=list(map(int,input().split(" ")))
a1=list(map(int,input().split(" ")))


sum1=sum(a1[:q1[1]])
sumsum=sum1
for i in range(q1[0]-q1[1]):
    sum1=sum1+a1[i+q1[1]]-a1[i]
    if(sumsum<sum1):
        sumsum=sum1
sumsum+=q1[1]
print(sumsum/2)

Buggy python submission (verdict: Runtime Error):
q1=list(map(int,input().split(" ")))
a1=list(map(int,input().split(" ")))

sumsum=0
for i in range(q[0]-q1[1]+1):
    sum1=sum(a1[i:i+q1[1]])
    if(sumsum<sum1):
        sumsum=sum1
sumsum+=q1[1]
print(sumsum/2)


Fixed submission:
q1=list(map(int,input().split(" ")))
a1=list(map(int,input().split(" ")))


sum1=sum(a1[:q1[1]])
sumsum=sum1
for i in range(q1[0]-q1[1]):
    sum1=sum1+a1[i+q1[1]]-a1[i]
    if(sumsum<sum1):
        sumsum=sum1
sumsum+=q1[1]
print(sumsum/2)

Buggy python submission (verdict: Time Limit Exceeded):
q=input()
a=input()

q1=q.split(" ")
a1=list(map(int,a.split(" ")))

sumsum=0
for i in range(len(a1)-int(q1[1])+1):
    sum1=sum(a1[i:i+int(q1[1])])
    if(sumsum<sum1):
        sumsum=sum1
sumsum+=int(q1[1])
print(sumsum/2)


Fixed submission:
q1=list(map(int,input().split(" ")))
a1=list(map(int,input().split(" ")))


sum1=sum(a1[:q1[1]])
sumsum=sum1
for i in range(q1[0]-q1[1]):
    sum1=sum1+a1[i+q1[1]]-a1[i]
    if(sumsum<sum1):
        sumsum=sum1
sumsum+=q1[1]
print(sumsum/2)
Buggy python submission (verdict: Runtime Error):
import sys
import numpy as np

i = list(map(int, input().split()))
a = i[0]
b = i[1]
h = i[2]
m = i[3]
time = h*60+m
ths = np.pi/2-(np.pi * time/(60*12))
thl = np.pi/2-(np.pi * m/30.0)
#ths = np.deg2rad(90-h*30.0)
#thl = np.deg2rad(90-m*6.0)
x1 = a*np.cos(ths)
y1 = a*np.sin(ths)
x2 = b*np.cos(thl)
y2 = b*np.sin(thl)
print(np.sqrt((x1-x2)**2+(y1-y2)**2))


Fixed submission:
import sys
import numpy as np
lines = sys.stdin.readlines()
a = int(lines[0].strip())

if a%10 == 3:
  print('bon')
elif a%10 in [0,1,6,8]:
  print('pon')
else:
  print('hon')
Buggy python submission (verdict: Runtime Error):
import numpy
str = input()
lst = str.split()
a = int(lst[0])
b = int(lst[1])
c = int(lst[2])
if b > c:
    print(int(a*c/b)-int(c/b)*a)
else:
    d = int(c/b)
    lst = np.zeros(d)
    for i in range(d):
        k = b*(i+1)-1
        lst[i] = int(a*k/b)-int(k/b)*a
    print(np.max(lst))

Fixed submission:
import numpy as np
str = input()
lst = str.split()
a = int(lst[0])
b = int(lst[1])
c = int(lst[2])
if b > c:
    print(int(a*c/b)-int(c/b)*a)
else:
    d = int(c/b)
    if d > 100:
      d = 100
    lst = np.zeros(d)
    for i in range(d):
        k = b*(i+1)-1
        lst[i] = int(a*k/b)-int(k/b)*a
    print(int(np.max(lst)))
Buggy python submission (verdict: Runtime Error):
import numpy,math

n = int(input())
s = str(input())

if(len(s) <= n):
    print(s)
else:
    print(s[:n+1 + "..."])

Fixed submission:
import numpy,math

n = int(input())
s = str(input())

if(len(s) <= n):
    print(s)
else:
    print(s[:n] + "...")
Buggy python submission (verdict: Time Limit Exceeded):
sh = int(input())
b = input()

id = [int(n) for n in b.split(" ")]
id_list = set(id)

for i in range(1,sh+1):
    if  {i} <= id_list:
        print(id.count(i))
    else:
        print(0)


Fixed submission:
from collections import defaultdict

sh = int(input())
b = input()

id = [int(n) for n in b.split(" ")]
D = defaultdict(int)
for i in id:
    if i not in D:
        D[i] = 1
    else:
        D[i] += 1
#print(D)

for i in range(1,sh+1):
    if i in D:
        print(D[i])
    else:
        print(0)

Buggy python submission (verdict: Time Limit Exceeded):
sh = int(input())
b = input()

id = [int(n) for n in b.split(" ")]
#id_list = set(id)

for i in range(1,sh+1):
    print(id.count(i))


Fixed submission:
from collections import defaultdict

sh = int(input())
b = input()

id = [int(n) for n in b.split(" ")]
D = defaultdict(int)
for i in id:
    if i not in D:
        D[i] = 1
    else:
        D[i] += 1
#print(D)

for i in range(1,sh+1):
    if i in D:
        print(D[i])
    else:
        print(0)
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n=int(input())
    a=sorted(map(int,input().split()), reverse=True)
    ans=0
    mod=10**9+7
    for i in range(n-1):
        if a[i] == 0:
            break
        for j in range(i+1,n):
            if a[j] == 0:
                break
            ans += a[i]*a[j]%mod
    print(ans%mod)

if __name__ == '__main__':
    main()

Fixed submission:
from itertools import accumulate
def main():
    mod=10**9+7
    n=int(input())
    a=list(map(int,input().split()))
    aa=[0]+list(accumulate(a))
    ans=0
    for i in range(n-1):
        ans += a[i]*(aa[-1]-aa[i+1])%mod
    print(ans%mod)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n=int(input())
    a=sorted(map(int,input().split()), reverse=True)
    ans=0
    mod=10**9+7
    for i in range(n-1):
        if a[i] == 0:
            break
        for j in range(i+1,n):
            if a[j] == 0:
                break
            ans += a[i]*a[j]
            ans %= mod
    print(ans)

if __name__ == '__main__':
    main()

Fixed submission:
from itertools import accumulate
def main():
    mod=10**9+7
    n=int(input())
    a=list(map(int,input().split()))
    aa=[0]+list(accumulate(a))
    ans=0
    for i in range(n-1):
        ans += a[i]*(aa[-1]-aa[i+1])%mod
    print(ans%mod)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations

def main():
    n=int(input())
    a=list(map(int,input().split()))
    ans=0
    mod=10**9+7
    for i,j in combinations(a, 2):
        ans += i*j
        ans %= mod
    print(ans)

if __name__ == '__main__':
    main()

Fixed submission:
from itertools import accumulate
def main():
    mod=10**9+7
    n=int(input())
    a=list(map(int,input().split()))
    aa=[0]+list(accumulate(a))
    ans=0
    for i in range(n-1):
        ans += a[i]*(aa[-1]-aa[i+1])%mod
    print(ans%mod)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    n,m=map(int,input().split())
    uf=UnionFind(n)
    for a,b in (map(lambda x: int(x)-1, input().split()) for _ in range(m)):
        uf.union(a,b)
    print(max((uf.size(x) for x in uf.roots())))
    
if __name__ == "__main__":
    main()

Fixed submission:
def main():
    n,m=map(int,input().split())
    ab=[map(lambda x: int(x)-1,input().split()) for _ in range(m)]
    uf=UnionFind(n)
    for a,b in ab:
        uf.union(a,b)
    ans = 0
    for s in uf.roots():
        ans = max(uf.size(s),ans)
    print(ans)

class UnionFind():
    '''Union-Find'''
    
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def is_same(self, x, y) -> bool:
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
    
if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n,k = map(int, input().split())
    a = list(map(int, input().split()))
    a2 = [1] * (n-k+1)
    for i in range(n-k+1):
        for j in range(i,i+k):
            a2[i] *= a[j]
    #print(a2)
    for i in range(len(a2)-1):
        if a2[i] < a2[i+1]:
            print("Yes")
        else:
            print("No")

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    n,k = map(int, input().split())
    a = list(map(int, input().split()))
    for i in range(n-k):
        print("Yes" if a[i] < a[i+k] else "No")

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
l,r,n = map(int,input())
count = 0
for i in range(l,r+1):
  if i % n == 0:
    count += 1
print(count)

Fixed submission:
l,r,n = map(int,input().split())
count = 0
for i in range(l,r+1):
  if i % n == 0:
    count += 1
print(count)
Buggy python submission (verdict: Runtime Error):
from collections import Counter

def main():
    n = int(input())
    a = Counter(map(int, input().split()))
    temp, a = listed(a)
    q = int(input())
    bc = [tuple(map(int, input().split())) for _ in range(q)]
    
    for b, c in bc:
        t = a[b]
        if t == 0:
            print(temp)
            continue
        a[b] = 0
        temp -= b*t
        a[c] += t
        temp += c*t
        print(temp)

def listed(a):
    x = [0] * 10**5
    kei = 0
    for i,v in a.items():
        x[i] = v
        kei += i*v
    return kei, x

if __name__ == '__main__':
    main()

Fixed submission:
from collections import Counter

def main():
    n = int(input())
    a = Counter(map(int, input().split()))
    temp, a = listed(a)
    q = int(input())
    bc = [tuple(map(int, input().split())) for _ in range(q)]
    
    for b, c in bc:
        t = a[b]
        if t == 0:
            print(temp)
            continue
        a[b] = 0
        temp -= b*t
        a[c] += t
        temp += c*t
        print(temp)

def listed(a):
    x = [0] * (10**5 + 1)
    kei = 0
    for i,v in a.items():
        x[i] = v
        kei += i*v
    return kei, x

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
from collections import Counter

def main():
    n = int(input())
    a = Counter(map(int, input().split()))
    temp, a = listed(a)
    q = int(input())
    bc = [tuple(map(int, input().split())) for _ in range(q)]
    
    for b, c in bc:
        t = a[b]
        if t == 0:
            print(temp)
            continue
        a[b] = 0
        temp -= b*t
        a[c] += t
        temp += c*t
        print(temp)

def listed(a):
    x = [0] * 10**5
    kei = 0
    for i,v in a.items():
        x[i] = v
        kei += i*v
    return kei, x

if __name__ == '__main__':
    main()

Fixed submission:
from collections import Counter

def main():
    n = int(input())
    a = Counter(map(int, input().split()))
    temp, a = listed(a)
    q = int(input())
    bc = [tuple(map(int, input().split())) for _ in range(q)]
    
    for b, c in bc:
        t = a[b]
        if t == 0:
            print(temp)
            continue
        a[b] = 0
        temp -= b*t
        a[c] += t
        temp += c*t
        print(temp)

def listed(a):
    x = [0] * (10**5 + 1)
    kei = 0
    for i,v in a.items():
        x[i] = v
        kei += i*v
    return kei, x

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    n = int(input())
    a = sorted(list(map(int, input().split())))
    pool = set()
    count = 0
    limit = 10 ** 6 // 2 +1
    for i in range(n):
        t = a[i]
        if t in pool:
            continue
        for j in range(1, limit):
            x = t*j
            if x > limit:
                break
            pool.add(x)
        if not (n > i+1 and t == a[i+1]):
            count += 1
    print(count)

if __name__ == '__main__':
    main()

Fixed submission:
print(list(map(int,input().split())).index(0)+1)
Buggy python submission (verdict: Runtime Error):
def main():
    _ = input()
    a = sorted(list(map(int, input().split())), reverse=True)
    if a[-1] == 0:
        print(0)
        return
    x = 1
    m = 10 ** 18
    for i in a:
        if i > m:
            print(-1)
            return
        if i < 2:
            continue
        x *= i
    print(-1 if x > 10 ** 18 else x)


if __name__ == '__main__':
    main()

Fixed submission:
a,b=map(int, input().split())
print(a*b)
Buggy python submission (verdict: Runtime Error):
def main():
    n = int(input())
    f = set(prime_factorize(n))
    s = set()
    for p in f:
        e = 1
        z = p ** e
        while z <= n:
            if n % z == 0:
                if z not in s:
                    n //= z
                    s.add(z)
            e += 1
            z = p ** e
    print(len(s))
        
if __name__ == '__main__':
    main()

Fixed submission:
def prime_factorize(n):
    '''引数nの因数分解結果のlistを返す。'''
    arr = []
    while n % 2 == 0:
        arr.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            arr.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        arr.append(n)
    return arr

def main():
    n = int(input())
    f = set(prime_factorize(n))
    s = set()
    for p in f:
        e = 1
        z = p ** e
        while z <= n:
            if n % z == 0:
                if z not in s:
                    n //= z
                    s.add(z)
            e += 1
            z = p ** e
    print(len(s))
        
if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import itertools
 
x = int(input())
 
y = itertools.combinations(range(-100,100), 2)
i = 0
for n in y:
    if (n[0]**5 - n[1]**5) == x:
        print(n[0], n[1])
        break
    elif (n[1]**5 - n[0]**5) == x:
        print(n[1], n[0])
        break

Fixed submission:
a = input()

if a == "ABC":
    print("ARC")
else:
    print("ABC")

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

y = itertools.combinations(range(-50,50), 2)
i = 0
for n in y:
    if (n[0]**5 - n[1]**5) == x:
        print(n[0], n[1])
        break
    elif (n[1]**5 - n[0]**5) == x:
        print(n[1], n[0])
        break

Fixed submission:
a = input()

if a == "ABC":
    print("ARC")
else:
    print("ABC")

Buggy python submission (verdict: Runtime Error):
import itertools
 
x = int(input())
 
y = itertools.combinations(range(-50,50), 2)
i = 0
for n in y:
    if (n[0]**5 - n[1]**5) == x:
        print(n[0], n[1])
        break
    elif (n[1]**5 - n[0]**5) == x:
        print(n[1], n[0])
        break

Fixed submission:
a = input()

if a == "ABC":
    print("ARC")
else:
    print("ABC")

Buggy python submission (verdict: Runtime Error):
import itertools

x = int(input())

y = itertools.combinations(range(-80,80), 2)
for n in y:
    if (n[0]**5 - n[1]**5) == x:
        print(n[0], n[1])
        break
    elif (n[1]**5 - n[0]**5) == x:
        print(n[1], n[0])
        break

Fixed submission:
a = input()

if a == "ABC":
    print("ARC")
else:
    print("ABC")

Buggy python submission (verdict: Runtime Error):
import itertools

x = int(input())

y = itertools.combinations(range(-100,100), 2)
i = 0
for n in y:
    if (n[0]**5 - n[1]**5) == x:
        print("{} {}".format(n[0], n[1]))
        break
    elif (n[1]**5 - n[0]**5) == x:
        print("{} {}".format(n[1], n[0]))
        break

Fixed submission:
a = input()

if a == "ABC":
    print("ARC")
else:
    print("ABC")

Buggy python submission (verdict: Runtime Error):
import itertools

x = int(input())

y = itertools.combinations(range(-100,100), 2)
i = 0
for n in y:
    if (n[0]**5 - n[1]**5) == x:
        print(n[0], n[1])
        break
    elif (n[1]**5 - n[0]**5) == x:
        print(n[1], n[0])
        break
#print("miss")

Fixed submission:
a = input()

if a == "ABC":
    print("ARC")
else:
    print("ABC")
Buggy python submission (verdict: Time Limit Exceeded):
N, M = list(map(int, input().split()))
H = list(map(int, input().split()))

roads = []
for i in range(M):
    roads.append(list(map(int, input().split())))

goodcount = 0
for i in range(len(H)):
    isgood = True
    for r in roads:
        if r[0] == i+1 and H[i] <= H[r[1]-1]:
            isgood = False
        elif r[1] == i+1 and H[i] <= H[r[0]-1]:
            isgood = False
    if isgood:
        goodcount += 1

print(goodcount)

Fixed submission:
N, M = list(map(int, input().split()))
H = list(map(int, input().split()))

roads = []
for i in range(N):
    roads.append([])
    
for i in range(M):
    r = list(map(lambda x: int(x)-1, input().split()))
    roads[r[0]].append(r[1])
    roads[r[1]].append(r[0])

goodcount = 0
for i in range(len(H)):
    isgood = True
    for r in roads[i]:
        if H[i] <= H[r]:
            isgood = False
    if isgood:
        goodcount += 1

print(goodcount)
Buggy python submission (verdict: Runtime Error):
import itertools

x = list(map(int, input().split()))
y = []

for i in range(x[2]):
    y.append(list(map(int, input().split())))

for i in range(len(y)):
    y[i][0] -= 1
    y[i][1] -= 1

def get_score(arr: list):
    score = 0
    for yy in y:
        if arr[yy[1]] - arr[yy[0]] == yy[2]:
            score += yy[3]
    return score

scores = []
for t in itertools.combinations_with_replacement(range(1, 11), x[0]):
    isError = False
    for i in range(x[0] -1):
        if t[i] > t[i+1]:
            isError = True
    if isError == True:
        continue
    scores.append(get_score(t))

print(max(scores))

Fixed submission:
a = int(input())
args = list(map(int, input().split()))

# main
result = "NG"
for i in range(args[0], args[1] + 1):
    if i % a == 0:
        result = "OK"

# /main

print(result)
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N = int(input())
    S = input()
    
    r = 0
    for i in range(N):
        for j in range(i, N):
            x = j-i
            for k in range(j, N):
                if x == k-j:
                    continue
                if S[i] != S[j] and S[j] != S[k] and S[i] != S[k]:
                    r += 1
    print(r)

if __name__ == '__main__':
    main()

Fixed submission:
from collections import Counter
def main():
    n=int(input())
    s=input()
    d=Counter(s)
    a=d["R"]*d["G"]*d["B"]
    for i in range(n):
        t=min(n-i-1, i)
        for j in range(t+1):
            if s[i-j] != s[i] and s[i-j] != s[i+j] and s[i] != s[i+j]:
                a-=1
    print(a)
    
if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import math

def main():
    N = int(input())
    S = input()
    
    r = 0
    for i in range(N):
        for j in range(i, N):
            for k in range(j, N):
                if (i+k)/2 == j:
                    continue
                if S[i] != S[j] and S[j] != S[k] and S[i] != S[k]:
                    r += 1
    print(r)

if __name__ == '__main__':
    main()

Fixed submission:
from collections import Counter
def main():
    n=int(input())
    s=input()
    d=Counter(s)
    a=d["R"]*d["G"]*d["B"]
    for i in range(n):
        t=min(n-i-1, i)
        for j in range(t+1):
            if s[i-j] != s[i] and s[i-j] != s[i+j] and s[i] != s[i+j]:
                a-=1
    print(a)
    
if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

n,x,y=map(int,input().split())
x,y=x-1,y-1
e = [[2*10**3+1]*n for _ in range(n)]
for i in range(n):
    e[i][i] = 0

def main():
    for i in range(n):
        s = deque([i])  # サーチstack. 初期条件を設定
        dfs(s, e[i])
    #print(e)
    ans = [0]*n
    for i,ee in enumerate(e):
        for eee in ee[i:]:
            ans[eee] += 1
    for i in ans[1:]:
        print(i)

def dfs(s,e):
    while len(s) > 0:  # len(s) > 0 でループ
        t = s.popleft()
        for i in get_children(t):  # t の子ノードを列挙
            if e[i] != 2*10**3+1 and e[i] < e[t]+1:
                continue
            s.append(i)
            e[i] = min(e[i], e[t] + 1) # 探索済としつつ距離を入れる

def get_children(t):
    if t in (x,y):
        yield y if t == x else x
    if 0 < t:
        yield t-1
    if t < (n-1):
        yield t+1

if __name__ == "__main__":
    main()

Fixed submission:
from collections import Counter
def main():
    n,x,y=map(int,input().split())
    x,y=x-1,y-1
    ans=[]
    for i in range(n):
        dp = [n]*n
        dp[i] = 0
        calcstep(i, dp)
        dp[y] = min(dp[y], dp[x]+1)
        dp[x] = min(dp[x], dp[y]+1)
        calcstep(x, dp)
        calcstep(y, dp)
        #print(i, dp)
        ans += dp
    ans = Counter(ans)
    for i in range(1,n):
        print(ans[i]//2)

def calcstep(i, dp):
    for j in range(i, len(dp)-1):
        if dp[j+1] > dp[j]+1:
            dp[j+1] = dp[j]+1
        else:
            break
    for j in range(1,i+1)[::-1]:
        if dp[j-1] > dp[j]+1:
            dp[j-1] = dp[j]+1
        else:
            break

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    s = input()
    Q = int(input())
    for _ in range(Q):
        q = input().split()
        if q[0] == "1":
            s = s[::-1]
        else: # q[0]=="2"
            if q[1] == "1":
                s = q[2] + s
            else:
                s += q[2]
    
    print(s)

if __name__ == '__main__':
    main()

Fixed submission:
import bisect

def main():
    s = input()
    qc = int(input())
    front = ""
    back = ""
    direct = 1
    for _ in range(qc):
        t = input()
        if t[0] == "1":
            direct = 2 if direct == 1 else 1
        else:
            _,f,c = t.split()
            if f == "1":
                if direct == 1:
                    front += c
                else:
                    back += c
            else:
                if direct == 1:
                    back += c
                else:
                    front += c
    if direct % 2 == 0:
        print((s+back)[::-1] + front)
    else:
        print(front[::-1]+s+back)
    
if __name__ == "__main__":
    main()