Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03634 (python)

Fixed submission:
import sys
sys.setrecursionlimit(pow(10,6))
readline = sys.stdin.readline

def dfs(nw, d):
    V[nw] = d
    for nx in G[nw]:
        if V[nx[0]]==-1:
            dfs(nx[0], d+nx[1])

n = int(readline())
G = [[] for _ in range(n)]
for i in range(n-1):
    a,b,c = map(int, readline().split())
    G[a-1].append((b-1,c))
    G[b-1].append((a-1,c))
q, k = map(int, readline().split())

V = [-1]*n
dfs(k-1, 0)

for i in range(q):
    x,y = map(lambda x:int(x)-1, readline().split())
    print(V[x]+V[y])

Buggy submission (verdict: Runtime Error):
import sys
from collections import deque
readline = sys.stdin.readline
n = int(readline())
D = [[-1]*n for _ in range(n)]
for i in  range(n): D[i][i]=0
G = [[] for _ in range(n)]
for i in range(n-1):
    a,b,c = map(lambda x:int(x)-1, map(int, readline().split()))
    G[a].append(b)
    G[b].append(a)
    D[a][b] = c+1
    D[b][a] = c+1

q, k = map(int, readline().split())
k -= 1
que = deque([k])
_D = [-1]*n
_D[k] = 0
while que:
    nw = que.popleft()
    d = _D[nw]
    for nx in G[nw]:
        if nw!=k and _D[nx]!=-1: continue
        _D[nx] = d+D[nw][nx]
        que.append(nx)

for i in range(q):
    x, y = map(lambda x: int(x)-1, readline().split())
    print(_D[x]+_D[y])
Problem p03745 (python)

Fixed submission:
n = int(input())
A = list(map(int, input().split()))
r = 1
if n>2:
    d = A[1]-A[0]
    for i in range(2, n):
        if d:
            if (A[i]-A[i-1])*d<0:
                r += 1
                d = 0
        else:
            d = A[i]-A[i-1]
print(r)

Buggy submission (verdict: Runtime Error):
n = int(input())
A = list(map(int, input().split()))
r = 1
d = A[1]-A[0]
if n>2:
    for i in range(2, n):
        if d:
            if (A[i]-A[i-1])*d<0:
                r += 1
                d = 0
        else:
            d = A[i]-A[i-1]
print(r)
Problem p03785 (python)

Fixed submission:
n, c, k, *T = map(int, open(0).read().split())
T.sort()
ans = 1
p = 0
t = T[0]
for i in range(n):
    p += 1
    if T[i]>t+k or p>c:
        t = T[i]
        ans += 1
        p = 1
print(ans)

Buggy submission (verdict: Runtime Error):
n, c, k = map(int, input().split())
T = [0]*n
for i in range(n):
    T[i] = int(input())
T.sort()
ans = 0
jk = 0
t = T[0]
for i in range(n):
    if T[i]-t>k:
        ans += 1
        jk = 0
        t = T[i]
        continue
    jk += 1
    if jk==c:
        ans += 1
        jk = 0
        t = T[i]
print(ans if jk== else ans+1)
Problem p03805 (python)

Fixed submission:
import itertools
n, m = map(int, input().split())
G = [set() for _ in range(n)]
for _ in range(m):
    a,b = map(lambda x:int(x)-1, input().split())
    G[a].add(b)
    G[b].add(a)

P = [*itertools.permutations(range(1,n))]
ans = 0
for p in P:
    nw = 0
    for nx in p:
        if nx in G[nw]:
            nw = nx
        else:
            break
    else:
        ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
import itertools
from math import factorial as fa
P = itertools.permutations(list(range(n)))
n, m = map(int, input().split())
G = [set() for _ in range(n)]
for _ in range(m):
    a,b = map(lambda x:int(x)-1, input().split())
    G[a].add(b)
    G[b].add(a)

ans = 0
for _ in range(fa(n)):
    p = next(P)
    if p[0] != 0:
        break
    f = True
    for pnw,pnx in zip(p,p[1:]):
        if not pnx in G[pnw]:
            f = False
            break
    if f:
        ans += 1
print(ans)
Problem p03986 (python)

Fixed submission:
from collections import deque
X = input()
que = deque()
for x in X:
    if x=='S':
        que.append('S')
    elif x=='T' and (not que or que[-1]=='T'):
        que.append('T')
    elif x=='T' and que[-1]=='S':
        _ = que.pop()
print(len(que))

Buggy submission (verdict: Runtime Error):
X = input()
while X!=X_:
    X_ = X
    X = X.replace('ST', '')
print(len(X))
Problem p02781 (python)

Fixed submission:
import sys
from collections import deque

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N = input()
    length = len(N)
    K = int(input())

    # 左からi桁目まで見て，N以下が確定していて，0でない数字がk個ある数字の個数
    dp_1 = [[0] * (10) for _ in range(length)]

    # 左からi桁目まで見て，N以下が確定していなくて，0でない数字がk個ある数字の個数
    dp_2 = [[0] * (10) for _ in range(length)]

    dp_1[0][0] = 1
    dp_1[0][1] = int(N[0]) - 1

    dp_2[0][1] = 1

    for i in range(1, length):
        # 小さいのが確定しているものに対して，0以外のものを追加
        for k in range(1, K + 2):
            dp_1[i][k] += dp_1[i - 1][k - 1] * 9

        # 小さいものが確定しているものに対して，0を追加
        for k in range(0, K + 2):
            dp_1[i][k] += dp_1[i - 1][k]

        # 大小がわからないものから，小さいのが確定する
        if N[i] == "0":
            for k in range(K + 2):
                dp_2[i][k] += dp_2[i - 1][k]
        else:
            # 0を追加する
            for k in range(K + 2):
                dp_1[i][k] += dp_2[i - 1][k]

            # その他の数字を追加
            for k in range(1, K + 2):
                dp_1[i][k] += dp_2[i - 1][k - 1] * (int(N[i]) - 1)

            # 依然として大小関係がわからない
            for k in range(1, K + 2):
                dp_2[i][k] += dp_2[i - 1][k - 1]

    ans = dp_1[-1][K] + dp_2[-1][K]
    print(ans)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys
from collections import deque

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N = input()
    length = len(N)
    K = int(input())

    # 左からi桁目まで見て，N以下が確定していて，0でない数字がk個ある数字の個数
    dp_1 = [[0] * (10) for _ in range(length)]

    # 左からi桁目まで見て，N以下が確定していなくて，0でない数字がk個ある数字の個数
    dp_2 = [[0] * (10) for _ in range(length)]

    dp_1[0][0] = 1
    dp_1[0][1] = int(N[0]) - 1

    dp_2[0][1] = 1

    for i in range(1, length):
        # 小さいのが確定しているものに対して，0以外のものを追加
        for k in range(1, K + 2):
            dp_1[i][k] += dp_1[i - 1][k - 1] * 9

        # 小さいものが確定しているものに対して，0を追加
        for k in range(0, K + 2):
            dp_1[i][k] += dp_1[i - 1][k]

        # 大小がわからないものから，小さいのが確定する
        if N[i] == "0":
            for i in range(K + 2):
                dp_2[i][k] += dp_2[i - 1][k]
        else:
            # 0を追加する
            for k in range(K + 2):
                dp_1[i][k] += dp_2[i - 1][k]

            # その他の数字を追加
            for k in range(1, K + 2):
                dp_1[i][k] += dp_2[i - 1][k - 1] * (int(N[i]) - 1)

            # 依然として大小関係がわからない
            for k in range(1, K + 2):
                dp_2[i][k] += dp_2[i - 1][k - 1]

    ans = dp_1[-1][K] + dp_2[-1][K]
    print(ans)


if __name__ == "__main__":
    main()
Problem p02793 (python)

Fixed submission:
from fractions import gcd
from functools import reduce
import sys
import numpy as np

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def lcm(a, b):
    return a // gcd(a, b) * b


def lcm_list(S):
    return reduce(lcm, S)


# mod m におけるaの逆元
def modinv(a, m):
    b = m
    u = 1
    v = 0
    while b:
        t = a // b
        a -= t * b
        a, b = b, a
        u -= t * v
        u, v = v, u
    u %= m

    # 負の場合は m を足して正の数にする
    if u < 0:
        u += m
    return u


def main():
    N = int(input())
    A = list(map(int, input().split()))
    L = lcm_list(A)
    L %= MOD
    ans = 0
    for a in A:
        a_ = modinv(a, MOD)
        ans += L * a_ % MOD
    ans %= MOD
    print(ans)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
from fractions import gcd
from functools import reduce
import sys
import numpy as np

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N = int(input())
    A = list(map(int, input().split()))
    L = np.lcm.reduce(A)
    ans = 0
    for a in A:
        ans += L // a
        ans %= MOD
    print(ans)


if __name__ == "__main__":
    main()
Problem p02948 (python)

Fixed submission:
import sys
import heapq

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N, M = map(int, input().split())
    d = {i: [] for i in range(M + 1)}
    for _ in range(N):
        a, b = map(int, input().split())
        if a > M:
            continue
        d[a].append(b)

    ans = 0
    q = []
    heapq.heapify(q)
    for i in range(M, 0, -1):
        a = M - i + 1
        for b in d[a]:
            heapq.heappush(q, -b)
        if q:
            b = heapq.heappop(q)
            ans += -b

    print(ans)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys


sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def factorization(N):
    d = {}
    for n in range(2, N + 1):
        tmp = n
        for i in range(2, int(n ** 0.5) + 1):
            if tmp % i == 0:
                cnt = 0
                while tmp % i == 0:
                    cnt += 1
                    tmp //= i
                if i not in d:
                    d[i] = cnt
                else:
                    d[i] += cnt

        if tmp != 1:
            if tmp not in d:
                d[tmp] = 1
            else:
                d[tmp] += 1

    return d


def main():
    N = int(input())
    d = factorization(N)
    d = [v for k, v in d.items() if v > 1]
    cnt = {2: 0, 4: 0, 14: 0, 24: 0, 74: 0}
    cnt[2] = len(d)
    for i in range(len(d)):
        val = d[i]
        if val >= 74:
            cnt[74] += 1
        if val >= 24:
            cnt[24] += 1
        if val >= 14:
            cnt[14] += 1
        if val >= 4:
            cnt[4] += 1

    ans = cnt[74]
    ans += cnt[24] * (cnt[2] - 1)
    ans += cnt[14] * (cnt[4] - 1)
    ans += cnt[4] * (cnt[4] - 1) // 2 * (cnt[2] - 2)

    print(ans)


if __name__ == "__main__":
    main()
Problem p02597 (python)

Fixed submission:
n = int(input())
c = ','.join(input()).split(',')

ans = 0

ri = -1

if c.count('W') == 0:
    print(0)
    exit()

if c.count('R') == 0:
    print(0)
    exit()

for i in range(n):
    if c[i] == 'W':
        while c[ri] != 'R':
            ri -= 1
        
        if n < i-ri:
            break
        
        c[i], c[ri] = 'R', 'W'
        ans += 1
    
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
c = ','.join(input()).split(',')

ans = 0

ri = -1

for i in range(n):
    if c[i] == 'W':
        while c[ri] != 'R':
            ri -= 1
        
        if n < i-ri:
            break
        
        c[i], c[ri] = 'R', 'W'
        ans += 1
    
print(ans)
Problem p02948 (python)

Fixed submission:
import heapq

N,M = map(int, input().split())

jobs = {}
for _ in range(N):
  a,b = map(int, input().split())
  if a > M:
    continue
  if M - a in jobs:
    jobs[M-a].append(b)
  else:
    jobs[M-a] = [b]

q = []
heapq.heapify(q)

ans = 0
for i in reversed(range(0, M)):
  if i in jobs.keys():
    for job in jobs[i]:
      heapq.heappush(q, (-job, job))
  
  if len(q) > 0:
    ans += heapq.heappop(q)[1]

print(ans)

Buggy submission (verdict: Runtime Error):
N,M = map(int, input().split())
W = {}
for _ in range(N):
  a,b = map(int, input().split())
  if a in W:
    W[a].append(b)
  else:
    W[a] = [b]

ans = 0
for i in range(1, M+1):
  for j in range(1, i):
    if j in W.keys():
      ans += max(W[j])
      W[j].remove(max(W[j]))
print(ans)
Problem p03804 (python)

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

a = []
for x in range(0, N):
  a.append(input())

b = []
for x in range(0, M):
  b.append(input())

exists = []
for i in range(0, len(a)):
  exists.append([i, a[i].find(b[0])])

for x, y in exists:
  ari = []
  for i in range(0, len(b)):
    if x+i < len(a):
      ari.append(a[x+i][y:y+M])
  if "".join(ari) == "".join(b):
    print("Yes")
    exit()

print("No")

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())

a = []
for x in range(0, N):
  a.append(input())

b = []
for x in range(0, M):
  b.append(input())

for i in range(0, len(a)):
  found = a[i].find(b[0])
  if found != -1:
    tmp = []
    for j in range(i, len(b)+1):
      tmp.append(a[j][found:found+M])
    if "".join(tmp) ==  "".join(b):
      print("Yes")
      exit()
  
print("No")
Problem p02595 (python)

Fixed submission:
n,d = map(int,input().split())
cnt = 0
for i in range(n):
  a,b =map(int,input().split())
  if pow(d,2) >= pow(a,2) + pow(b,2):
  	cnt += 1
print(cnt)

Buggy submission (verdict: Runtime Error):
from math import sqrt
n, d = map(int,input().split())
a = [map(int,input().split()) for _ in range(n)]
cnt = 0
for i in range(n):
  if pow(d,2) >= pow(a[i][0],2) + pow(a[i][1],2):
    cnt += 1
print(cnt)
Problem p03315 (python)

Fixed submission:
a =input()
s = 0
for i in a:
  if i in "+":
    s +=1
  else:
    s -=1
print(s)

Buggy submission (verdict: Runtime Error):
S = map(str,input().split())
s =1
for i in S:
	if i in "+":
		s +=1  
	else:
    	s -=1
print(s)
Problem p03803 (python)

Fixed submission:
a,b =map(int,input().split())
A,B,C =("Alice","Bob","Draw")
if max(a,b) ==13 and min(a,b) ==1:
  print(A) if a < b else print(B)
else:
  if a > b:
    print(A)  
  elif a < b:
    print(B)  
  else:
    print(C)

Buggy submission (verdict: Runtime Error):
a,b =map(int,input().split())
A,B,C ="Alice","Bob",Draw"
if max(a,b) =="13" and min(a,b) =="1":
  print(A) if a < b else print(B)
else:
  print(A) if a > b print(B) if a < b else print(C)
Problem p02948 (python)

Fixed submission:
import sys
import heapq


def input(): return sys.stdin.readline().strip()


def main():
    N, M = map(int, input().split())

    w = [[] for _ in range(10 ** 5 + 1)]
    for _ in range(N):
        a, b = map(int, input().split())
        w[a].append(b)

    ans = 0
    hq = []
    for i in range(1, M+1):
        for x in w[i]:
            heapq.heappush(hq, -x)

        if not hq:
            continue

        ans += -heapq.heappop(hq)

    print(ans)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys
import heapq


def input(): return sys.stdin.readline().strip()


def main():
    N, M = map(int, input().split())

    w = [[] for _ in range(10 ** 5)]
    for _ in range(N):
        a, b = map(int, input().split())
        w[a].append(b)

    ans = 0
    hq = []
    for i in range(1, M+1):
        for x in w[i]:
            heapq.heappush(hq, -x)

        if not hq:
            continue

        ans += -heapq.heappop(hq)

    print(ans)


if __name__ == "__main__":
    main()
Problem p02954 (python)

Fixed submission:
import sys
input = sys.stdin.readline


def solve(S):
    def split(sub):
        result = []
        s = sub.partition('LR')
        while s[1] != '':
            new_s = s[0] + s[1][0]
            rem = s[1][1] + s[2]
            result.append(new_s)
            s = rem.partition('LR')
        return result + [s[0]]

    def count(sub):
        c = [0] * len(sub)
        l = sub.index('L')

        # R
        i = 1
        while l - i >= 0:
            c[l - (i % 2)] += 1
            i += 1

        # L
        i = 0
        while l + i < len(sub):
            c[l - (i % 2)] += 1
            i += 1

        return c

    ans = []
    for s in split(S):
        ans += count(s)
    return ans


def main():
    S = input().strip()
    ans = solve(S)

    for x in ans:
        print(x, end=' ')


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline


def solve(S):
    def split(sub, result=[]):
        s = sub.partition('LR')
        if s[1] == '':
            return result + [s[0]]
        else:
            new_s = s[0] + s[1][0]
            rem = s[1][1] + s[2]
            return split(rem, result + [new_s])

    def count(sub):
        c = [0] * len(sub)
        l = sub.index('L')

        # R
        i = 1
        while l - i >= 0:
            c[l - (i % 2)] += 1
            i += 1

        # L
        i = 0
        while l + i < len(sub):
            c[l - (i % 2)] += 1
            i += 1

        return c

    ans = []
    for s in split(S):
        ans += count(s)
    return ans


def main():
    S = input().strip()
    ans = solve(S)

    for x in ans:
        print(x, end=' ')


if __name__ == "__main__":
    main()
Problem p02990 (python)

Fixed submission:
#!/usr/bin/env python3
import sys
import functools
from math import factorial
from operator import mul

MOD = 10**9 + 7  # type: int

def solve(N: int, K: int):
    facts = [1] * (N+1)
    for i in range(2, N+1):
        facts[i] = facts[i-1] * (i)

    def C(n: int, r: int):
        upper = facts[n]
        lower = facts[r] * facts[n-r]
        return (upper // lower) % MOD

    for i in range(1, K+1):
        a = C(N-K+1, i)
        b = C(K-1, i-1)
        print((a*b) % MOD)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
import functools
from math import factorial

MOD = 10**9 + 7  # type: int

def solve(N: int, K: int):
    def C(n: int, r: int):
        return factorial(n) // factorial(r) // factorial(n - r)

    for i in range(1, K+1):
        a = C(N-K+1, i)
        b = C(K-1, i-1)
        print((a*b) % MOD)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)

if __name__ == '__main__':
    main()
Problem p03207 (python)

Fixed submission:
n = int(input())
al = [int(input()) for _ in range(n)]
m = max(al)
s, f = 0, True
for i in range(n):
  if al[i] == m and f:
    s += al[i] // 2
    f = False
  else:
    s += al[i]
print(s)

Buggy submission (verdict: Runtime Error):
n = int(input())
al = [int(input()) for _ in range(n)]
m = max(al)
s, f = 0, True
for i in range(n):
  if al[i] == m and flag:
    s += al[i] // 2
    f = False
  else:
    s += al[i]
print(s)
Problem p03208 (python)

Fixed submission:
#!/usr/bin/env python
# -*- coding: utf-8 -*-


def solve():
    n, k = map(int, input().split())
    hl = [int(input()) for _ in range(n)]
    hl.sort()
    diff = hl[k - 1] - hl[0]
    for i in range(0, n - k + 1):
        td = hl[k - 1 + i] - hl[i]
        diff = min(td, diff)
    print(diff)


if __name__ == "__main__":
    solve()

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
hl = [int(input()) for _ in range(n)]
hl.sort()
print(min([hl[k - 1 + i] - hl[i] for i in range(0, n - k + 1)))
Problem p03209 (python)

Fixed submission:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import math

al = [0, 5] + [0] * 49
bl = [0, 3] + [0] * 49


def solve2(ans, x, idx, cnt):
    if idx == 1:
        if x >= 5:
            return ans + 3
        return ans + (0, 0, 1, 2, 3, 3)[x]
    if x >= al[idx - 1] + 1:
        ans += bl[idx - 1]
        x -= al[idx - 1] + 1
        if x >= 1:
            ans += 1
            x -= 1
    else:
        x -= 1
        if x <= 0:
            return ans
    return solve2(ans, x, idx - 1, cnt)


def solve(n, x):
    for i in range(2, n + 1):
        al[i] = al[i - 1] * 2 + 3
        bl[i] = bl[i - 1] * 2 + 1
    ans = solve2(0, x, n, 0)
    print(ans)


if __name__ == "__main__":
    n, x = map(int, input().split())
    solve(n, x)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import math

al = [0, 5] + [0] * 49
bl = [0, 3] + [0] * 49


def solve2(ans, x, idx, cnt):
    if idx == 1:
        return ans + (0, 0, 1, 2, 3, 3)[x]
    if x >= al[idx - 1] + 1:
        ans += bl[idx - 1]
        x -= al[idx - 1] + 1
        if x >= 1:
            ans += 1
            x -= 1
    else:
        x -= 1
        if x <= 0:
            return ans
    return solve2(ans, x, idx - 1, cnt)


def solve():
    n, x = map(int, input().split())
    for i in range(2, n + 1):
        al[i] = al[i - 1] * 2 + 3
        bl[i] = bl[i - 1] * 2 + 1
    ans = solve2(0, x, n, 0)
    print(ans)


if __name__ == "__main__":
    solve()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python
# -*- coding: utf-8 -*-

al = [0, 5] + [0] * 49
bl = [0, 3] + [0] * 49


def solve2(ans, x, idx, cnt):
    if idx == 1:
        return ans + (0, 0, 1, 2, 3, 3, 3)[x] + [0, 1][cnt >= 1]
    if x == (al[idx] // 2) + 1:
        return ans + bl[idx - 1] + 1 + [0, 1][cnt >= 1]
    elif x > (al[idx] // 2) + 1:
        ans += bl[idx - 1]
        x -= (al[idx] // 2)
        cnt += 1
    return solve2(ans, x, idx - 1, cnt)


def solve():
    n, x = map(int, input().split())
    for i in range(2, n + 1):
        al[i] = al[i - 1] * 2 + 3
        bl[i] = bl[i - 1] * 2 + 1
    ans = solve2(0, x, n, 0)
    print(ans)


if __name__ == "__main__":
    solve()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python
# -*- coding: utf-8 -*-

al = [0, 5] + [0] * 49
bl = [0, 3] + [0] * 49


def solve2(ans, x, idx, cnt):
    print(ans, x, idx)
    if idx == 1:
        return ans + (0, 0, 1, 2, 3, 3, 3)[x] + [0, 1][cnt >= 1]
    if x == (al[idx] // 2) + 1:
        return ans + bl[idx - 1] + 1 + [0, 1][cnt >= 1]
    elif x > (al[idx] // 2) + 1:
        ans += bl[idx - 1]
        x -= (al[idx] // 2)
        cnt += 1
    return solve2(ans, x, idx - 1, cnt)


def solve():
    n, x = map(int, input().split())
    for i in range(2, n + 1):
        al[i] = al[i - 1] * 2 + 3
        bl[i] = bl[i - 1] * 2 + 1
    ans = solve2(0, x, n, 0)
    print(ans)


if __name__ == "__main__":
    solve()
Problem p03252 (python)

Fixed submission:
def solve():
  from collections import Counter
  s = [i for i in sorted(Counter(input()).values())]
  t = [i for i in sorted(Counter(input()).values())]
  print(["No","Yes"][s==t])

solve()

Buggy submission (verdict: Runtime Error):
def solve():
    alpha = "abcdefghijklmnopqrstuvwxyz"
    inp1, inp2 = input(), input()
    sz = dict(zip(list(alpha), [0] * 26))
    tz = dict(zip(list(alpha), [0] * 26))
    siz = dict(
        zip(list(alpha), [[0 for i in range(10 ** 5)] for _ in range(26)]))
    tiz = dict(
        zip(list(alpha), [[0 for i in range(10 ** 5)] for _ in range(26)]))
    for i in range(len(inp1)):
        sz[inp1[i]] += 1
        tz[inp2[i]] += 1
        siz[inp1[i]][i] = i
        tiz[inp2[i]][i] = i
        if (sz[inp1[i]] != tz[inp2[i]]):
            print("No")
            return
    for e in alpha:
        if set(siz[e]) ^ set(tiz[e]):
            print("No")
            return
    print("Yes")


solve()

Buggy submission (verdict: Runtime Error):
def solve():
    alpha = "abcdefghijklmnopqrstuvwxyz"
    inp1, inp2 = input(), input()
    sz = dict(zip(list(alpha), [0] * 26))
    tz = dict(zip(list(alpha), [0] * 26))
    siz = dict(
        zip(list(alpha), [[0 for i in range(10 ** 5)] for _ in range(26)]))
    tiz = dict(
        zip(list(alpha), [[0 for i in range(10 ** 5)] for _ in range(26)]))
    for i in range(len(inp1)):
        sz[inp1[i]] += 1
        tz[inp2[i]] += 1
        siz[inp1[i]][i] = i
        tiz[inp1[i]][i] = i
        if (sz[inp1[i]] != tz[inp2[i]]):
            print("No")
            return
    for e in alpha:
        if set(siz[e]) - set(tiz[e]):
            print("No")
            return
    print("Yes")


solve()