Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import sys
X = input()

if int(X) < 100:
    print(0)
    sys.exit(1)
    
tmp = int(X[-2] + X[-1])

iteration = 0

for i in range(5, 0, -1):
    iteration = tmp // i
    tmp %= i
    
    if tmp == 0:
        break

if (iteration * 100) >= int(X):
    print(1)
else:
    print(0)

Fixed submission:
X = int(input())
c = X // 100

if (c * 100) <= X <= (c * 105):
    print(1)
else:
    print(0)

Buggy python submission (verdict: Runtime Error):
X = input()
tmp = int(X[-2] + X[-1])

iteration = 0

for i in range(5, 0, -1):
    iteration = tmp // i
    tmp %= i
    
    if tmp == 0:
        break

if (iteration * 100) >= int(X):
    print(1)
else:
    print(0)

Fixed submission:
X = int(input())
c = X // 100

if (c * 100) <= X <= (c * 105):
    print(1)
else:
    print(0)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

count = set([])

for i in range(len(S)-2):
    for j in range(i+1, len(S)-1):
        for k in range(j+1, len(S)):
            count.add(S[i]+S[j]+S[k])
    
print(len(count))

Fixed submission:
N = input()
S = input()
ans = 0

for i in range(10):
    for j in range(10):
        for k in range(10):
            a = S.find(str(i))
            if a == -1:
                continue
            b = S.find(str(j), a+1)
            if b == -1:
                continue
            c = S.find(str(k), b+1)
            if c == -1:
                continue
            ans+=1

print(ans)
Buggy python submission (verdict: Runtime Error):
from math import gcd
from functools import reduce


def gcd_expand(values):
    return reduce(gcd, values)


N, X = map(int, input().split())
x = map(int, input().split())

x_abs = [abs(X - i) for i in x]
print(gcd_expand(x_abs))

Fixed submission:
from fractions import gcd
from functools import reduce


def gcd_expand(values):
    return reduce(gcd, values)


N, X = map(int, input().split())
x = map(int, input().split())

x_abs = [abs(X - i) for i in x]
print(gcd_expand(x_abs))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
ai = max(A)
aj1 = ai // 2
aj2 = aj1 + (ai % 2)
while True:
    if aj1 in A:
        print(ai, aj1)
        break
    elif aj2 in A:
        print(ai, aj2)
        break
    aj1 -= 1
    aj2 += 1

Fixed submission:
import bisect
N = int(input())
A = list(map(int, input().split()))
A.sort()
ai = A[-1]

tmp = ai / 2
i = bisect.bisect_left(A, tmp)
if abs(tmp - A[i]) < abs(tmp - A[i - 1]):
    print(ai, A[i])
else:
    print(ai, A[i - 1])
Buggy python submission (verdict: Runtime Error):
a, b, c = map(int, input().split())
max = int((a + c) / (b + 2*c))
print(max)

Fixed submission:
X, Y = input().split()

if int(X, 16) > int(Y, 16):
    print(">")
elif int(X, 16) < int(Y, 16):
    print("<")
else:
    print("=")

Buggy python submission (verdict: Runtime Error):
a, b, c = map(int, input().split())
max = int((a + c) / (b + 2*c))
print(max)

Fixed submission:
X, Y = input().split()

if int(X, 16) > int(Y, 16):
    print(">")
elif int(X, 16) < int(Y, 16):
    print("<")
else:
    print("=")

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

# 入力
a, b, c = map(int, input().split())
max = math.floor((a + c) / (b + 2*c))
print(max)

Fixed submission:
X, Y = input().split()

if int(X, 16) > int(Y, 16):
    print(">")
elif int(X, 16) < int(Y, 16):
    print("<")
else:
    print("=")

Buggy python submission (verdict: Runtime Error):
import sys
import math

# 入力
a, b, c = map(int, input().split())
# 計算
if a == (b + 2*c):
    print("1")
else:
    max = math.floor((a + c) / (b + 2*c))
    print(max)

Fixed submission:
X, Y = input().split()

if int(X, 16) > int(Y, 16):
    print(">")
elif int(X, 16) < int(Y, 16):
    print("<")
else:
    print("=")

Buggy python submission (verdict: Runtime Error):
import sys
import math

# 入力
a, b, c = map(int, input().split())
# 計算
if a < (b + 2*c):
    print("a >= b + 2*cとなるようにしてください")
    sys.exit()
elif a == (b + 2*c):
    print("1")
else:
    max = math.floor((a + c) / (b + 2*c))
    print(max)

Fixed submission:
X, Y = input().split()

if int(X, 16) > int(Y, 16):
    print(">")
elif int(X, 16) < int(Y, 16):
    print("<")
else:
    print("=")
Buggy python submission (verdict: Time Limit Exceeded):
import bisect

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort()
B.sort()
C.sort()

count = 0

for i in range(N):
    index_b = bisect.bisect_right(B, A[i])
    for j in range(index_b, N):
        index_c = bisect.bisect_right(C, B[j])
        count += N - index_c

print(count)

Fixed submission:
import bisect

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort()
C.sort()

count = 0

for b in B:
    index_b = bisect.bisect_left(A, b)
    index_c = bisect.bisect_right(C, b)
    count += (N - index_c) * index_b

print(count)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
K = []

for i in range(N):
    value = str(input())
    if value in K:
        K.remove(value)
    else:
        K.append(value)

print(len(K))


Fixed submission:
import collections

N = int(input())
M = [int(input()) for i in range(N)]

value = list(collections.Counter(M).values())

sum = 0
for i in value:
    sum += i%2

print(sum)

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

# 紙に書かれた数字
K = []

for i in M:
    if i in K:
        K.remove(i)
    else:
        K.append(i)

print(len(K))


Fixed submission:
import collections

N = int(input())
M = [int(input()) for i in range(N)]

value = list(collections.Counter(M).values())

sum = 0
for i in value:
    sum += i%2

print(sum)
Buggy python submission (verdict: Runtime Error):
A, B, C, D = input().split()
value = (min(B, D) - max(A, C))
print(value if value > 0 else "0")



Fixed submission:
A, B, C, D = map(int, input().split())
value = min(B, D) - max(A, C)
print(value if value > 0 else "0")
Buggy python submission (verdict: Runtime Error):
# list: ソート済配列
# n: 参照番号
@profile
def gcd(list, n):
    if n == 0:
        return list[0]
    else:
        a, b = list[n-1], list[n]
        
        while list[n]:
            list[n-1], list[n] = list[n], list[n-1] % list[n]

        list[n-1] = (a*b)/list[n-1]
        return gcd(list, n-1)

N = int(input())
T = [int(input()) for i in range(N)]
T.sort(reverse=True)
print(int(gcd(T, N-1)))



Fixed submission:
# list: ソート済配列
# n: 参照番号
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

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

N = int(input())
T = [int(input()) for i in range(N)]
ans = 1

for i in range(N):
    ans = lcm(ans, T[i])

print(ans)

Buggy python submission (verdict: Runtime Error):
A, B, C, D = map(int, input().split())
value = min(B, D) - max(A, C)
print(value if value > 0 else "0")



Fixed submission:
# list: ソート済配列
# n: 参照番号
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

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

N = int(input())
T = [int(input()) for i in range(N)]
ans = 1

for i in range(N):
    ans = lcm(ans, T[i])

print(ans)
Buggy python submission (verdict: Runtime Error):
import collections
n = int(input())
S = [list(input()) for i in range(n)]
Sc = [collections.Counter(i) for i in S]


if n == 1:
    ans = "".join(S[0].sort())
    print(ans)
else:
    counter = Sc[0] & Sc[1]
    for i in range(2, len(Sc)):
        counter = counter & Sc[i]

    Sclist = list(counter.elements())
    Sclist.sort()
    ans = "".join(Sclist)

    print(ans)


Fixed submission:
import collections
n = int(input())
S = [list(input()) for i in range(n)]
Sc = [collections.Counter(i) for i in S]


if n == 1:
    S[0].sort()
    ans = "".join(S[0])
    print(ans)
else:
    counter = Sc[0] & Sc[1]
    for i in range(2, len(Sc)):
        counter = counter & Sc[i]

    Sclist = list(counter.elements())
    Sclist.sort()
    ans = "".join(Sclist)

    print(ans)

Buggy python submission (verdict: Runtime Error):
import collections
n = int(input())
S = [list(input()) for i in range(n)]
Sc = [collections.Counter(i) for i in S]


if n == 1:
    ans = "".join(S[0])
    ans.sort()
    print(ans)
else:
    counter = Sc[0] & Sc[1]
    for i in range(2, len(Sc)):
        counter = counter & Sc[i]

    Sclist = list(counter.elements())
    Sclist.sort()
    ans = "".join(Sclist)

    print(ans)


Fixed submission:
import collections
n = int(input())
S = [list(input()) for i in range(n)]
Sc = [collections.Counter(i) for i in S]


if n == 1:
    S[0].sort()
    ans = "".join(S[0])
    print(ans)
else:
    counter = Sc[0] & Sc[1]
    for i in range(2, len(Sc)):
        counter = counter & Sc[i]

    Sclist = list(counter.elements())
    Sclist.sort()
    ans = "".join(Sclist)

    print(ans)

Buggy python submission (verdict: Runtime Error):
import collections
n = int(input())
S = [list(input()) for i in range(n)]
Sc = [collections.Counter(i) for i in S]

counter = Sc[0] & Sc[1]
for i in range(2, len(Sc)):
    counter = counter & Sc[i]

Sclist = list(counter.elements())
Sclist.sort()
ans = "".join(Sclist)

if n == 1:
    print(S[0])
else:
    print(ans)


Fixed submission:
import collections
n = int(input())
S = [list(input()) for i in range(n)]
Sc = [collections.Counter(i) for i in S]


if n == 1:
    S[0].sort()
    ans = "".join(S[0])
    print(ans)
else:
    counter = Sc[0] & Sc[1]
    for i in range(2, len(Sc)):
        counter = counter & Sc[i]

    Sclist = list(counter.elements())
    Sclist.sort()
    ans = "".join(Sclist)

    print(ans)

Buggy python submission (verdict: Runtime Error):
import collections
n = int(input())
S = [list(input()) for i in range(n)]
Sc = [collections.Counter(i) for i in S]

counter = Sc[0] & Sc[1]
for i in range(2, len(Sc)):
    counter = counter & Sc[i]

Sclist = list(counter.elements())
Sclist.sort()
ans = "".join(Sclist)
print(ans)


Fixed submission:
import collections
n = int(input())
S = [list(input()) for i in range(n)]
Sc = [collections.Counter(i) for i in S]


if n == 1:
    S[0].sort()
    ans = "".join(S[0])
    print(ans)
else:
    counter = Sc[0] & Sc[1]
    for i in range(2, len(Sc)):
        counter = counter & Sc[i]

    Sclist = list(counter.elements())
    Sclist.sort()
    ans = "".join(Sclist)

    print(ans)
Buggy python submission (verdict: Runtime Error):
https://www.lifehacker.jp/2017/11/171127_kakei_17.html?utm_source=dlvr.it&utm_medium=twitter

Fixed submission:
X = int(input())

count, addition = 0, 0
while 1:
    if X <= count:
        break

    addition += 1
    count += addition

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

if N >= 2 * M:
print(M // 2)
else:
print(N + ((M - 2 * N) // 4))

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

if N >= (M // 2):
    print(M // 2)
else:
    print(N + ((M - 2 * N) // 4))

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

if N >= 2 * M:
    print(M // 2)
else:
    print(N + ((M - 2 * N) // 4)

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

if N >= (M // 2):
    print(M // 2)
else:
    print(N + ((M - 2 * N) // 4))
Buggy python submission (verdict: Runtime Error):
 print(chr(ord(input()) + 1))

Fixed submission:
a = input()

print(chr(ord(a) + 1))
Buggy python submission (verdict: Runtime Error):
n,x = map(int, input().split())
l = list(map(int, input().split()))

ns=0
ans = 1

for i in range(n):
  ns += l[i]
  if ns <= x:
    ans++
  else:
    break
print(ans)  

Fixed submission:
n,x = map(int, input().split())
l = list(map(int, input().split()))

ns=0
ans = 1

for i in range(n):
	ns += l[i]
	if ns <= x:
		ans += 1
	else:
		break
print(ans)
Buggy python submission (verdict: Runtime Error):
w,h,x,y = map(double, input().split())
if  w/2 == x and h/2 == y:
	ans = 1
else:
	ans = 0
print (w*h/2.0,ans)


Fixed submission:
w,h,x,y = map(int, input().split())
if  w/2 == x and h/2 == y:
	ans = 1
else:
	ans = 0
print (w*h/2.0,ans)

Buggy python submission (verdict: Runtime Error):
w,h,x,y = map(double, input().split())
if  w/2 == x and h/2 == y:
	ans = 1
else:
	ans = 0
print (w*h/2,ans)

Fixed submission:
w,h,x,y = map(int, input().split())
if  w/2 == x and h/2 == y:
	ans = 1
else:
	ans = 0
print (w*h/2.0,ans)

Buggy python submission (verdict: Runtime Error):
w,h,x,y = map(double, input().split())
if  w/2 = x and h/2 = y:
	ans = 1
else:
	ans = 0
print (w*h/2,ans)

Fixed submission:
w,h,x,y = map(int, input().split())
if  w/2 == x and h/2 == y:
	ans = 1
else:
	ans = 0
print (w*h/2.0,ans)

Buggy python submission (verdict: Runtime Error):
w,h,x,y = map(double, input().split())
if  w/2 = x && h/2 = y:
	ans = 1
else:
	ans = 0
print (str(w*h/2) + " " + str(ans))

Fixed submission:
w,h,x,y = map(int, input().split())
if  w/2 == x and h/2 == y:
	ans = 1
else:
	ans = 0
print (w*h/2.0,ans)
Buggy python submission (verdict: Runtime Error):
import itertools

N,K = map(int,input().split())
A = sorted(list(map(int,input().split())))

def fun(a):
    return max(a)-min(a)
def fun1(a):
    return sum(a) % (1000000007)
_1 = [fun(i) for i in itertools.combinations([int(i) for i in A], K)]    
print(fun1(_1))

mod = 10**9 + 7
 
def nCr(n,r):
  if n < r:
    return 0
  if n < 0 or r < 0:
    return 0
  return (fac[n] * facinv[r] * facinv[n - r]) % mod

Fixed submission:
asc = 'abcdefghijklmnopqrstuvwxyz'
t=input()
for i in range(25):
    if t == asc[i]:
        print(asc[i+1])
Buggy python submission (verdict: Runtime Error):
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;
typedef long long ll;

ll MOD = 1e9 + 7;

vector<ll> factorial;
ll mod_exp(ll x, ll exp) {
    ll res = 1;
    ll base = x % MOD;
    while (exp) {
        if (exp % 2 == 1) {
            res = (res * base) % MOD;
        }
        base = (base * base) % MOD;
        exp /= 2;
    }
    return res;
}

ll nCk(ll n, ll k) {
    if (n < k) return 0;
    ll numerator = factorial[n];
    ll denominator = (factorial[n-k] * factorial[k]) % MOD;
    ll ans = (numerator * mod_exp(denominator, MOD-2)) % MOD;
    return ans;
}

int main() {
    ll N, K; cin >> N >> K;
    vector<ll> nums(N);
    for (ll& x : nums) {
        cin >> x;
    }

    factorial = {1};
    for (int i = 1; i <= N; i++) {
        factorial.push_back((factorial.back() * i) % MOD);
    }

    ll ans = 0;

    sort(begin(nums), end(nums), [](int a, int b){return a > b;});
    for (int i = 1; i <= N-K+1; i++) {
        ll best = nums[i-1];
        ll contribution = (best * nCk(N-i, K-1)) % MOD;
        ans = (ans + contribution) % MOD;
    }

    sort(begin(nums), end(nums));
    for (int i = 1; i <= N-K+1; i++) {
        ll best = nums[i-1];
        ll contribution = (best * nCk(N-i, K-1)) % MOD;
        ans = (ans - contribution) % MOD;
    }

    cout << ans << endl;
}


Fixed submission:
MOD = 10**9 + 7

N, K = map(int, raw_input().split())
A = map(int, raw_input().split())

factorial = [1]
for i in range(1, N+1):
    factorial.append((i * factorial[-1]) % MOD)

def nCk(n, k):
    numerator = factorial[n]
    denominator = factorial[n-k] * factorial[k]
    return numerator * pow(denominator, MOD - 2, MOD)

ans = 0

A.sort()
for i in range(N-K+1):
    best = A[i]
    contribution = (best * nCk(N-i-1, K-1))
    ans = (ans - contribution) % MOD

A = A[::-1]
for i in range(N-K+1):
    best = A[i]
    contribution = (best * nCk(N-i-1, K-1))
    ans = (ans + contribution) % MOD

print ans
Buggy python submission (verdict: Time Limit Exceeded):
mod = pow(10, 9) + 7

N = pow(10, 6)

fact = [0]*N
inv = [0]*N

fact[0] = inv[0] = 1
inv[1] = fact[1] = 1
for i in range(2, N):
	fact[i] = (i*fact[i-1])%mod
	inv[i] = pow(fact[i], mod-2, mod)

def ncr(n, r):
	return (fact[n]*inv[r]*inv[n-r])%mod

X, Y = map(int, input().split())

if (X + Y)%3 != 0:
	print(0)
else:
	m = (2*Y - X)//3
	n = (X - m)//2
	if n < 0 or m < 0:
		print(0)
	else:
		ans = ncr(n+m, n)
		print(ans)

Fixed submission:
mod = pow(10, 9) + 7

N = pow(10, 6)

fact = [0]*N
inv = [0]*N

fact[0] = inv[0] = 1
inv[1] = fact[1] = 1
for i in range(2, N):
	fact[i] = (i*fact[i-1])%mod
	inv[i] = pow(fact[i], mod-2, mod)

def ncr(n, r):
	return (fact[n]*inv[r]*inv[n-r])%mod

X, Y = map(int, input().split())

if (X + Y)%3 != 0:
	print(0)
else:
	m = (2*Y - X)//3
	n = (X - m)//2
	if n < 0 or m < 0:
		print(0)
	else:
		ans = ncr(n+m, n)
		print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations 

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

def is_triangle(a, b, c):
	return (a+b > c and a+c > b and b+c > a)

count = 0

for a, b, c in combinations(arr, 3):
	if is_triangle(a, b, c):
		count += 1
print(count)

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

arr.sort()
count = 0
for i in range(n-1, 0, -1):
	l, r = 0, i - 1
	while l < r:
		if arr[l] + arr[r] > arr[i]:
			count += r - l
			r -= 1
		else:
			l += 1
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
import sys

inp = sys.stdin
# inp = open("testdata.txt", "r")
def input():
	return inp.readline().strip()

n, m, l = map(int, input().split())

adjl = [[0 if i==j else float('inf') for j in range(n)] for i in range(n)]

for _ in range(m):
	a, b, c = map(int, input().split())
	adjl[a-1][b-1] = c
	adjl[b-1][a-1] = c

for k in range(n):
	for i in range(n):
		for j in range(n):
			adjl[i][j] = min(adjl[i][j], adjl[i][k]+adjl[k][j])

old_adjl = [[ele for ele in row] for row in adjl]

for i in range(n):
	for j in range(n):
		if i==j: adjl[i][j] = 0
		else: adjl[i][j] = 1 if old_adjl[i][j] <= l else float("inf")

for k in range(n):
	for i in range(n):
		for j in range(n):
			if i==k or k==j:
				continue
			adjl[i][j] = min(adjl[i][j], adjl[i][k]+adjl[k][j])

q = int(input())

for _ in range(q):
	a, b = map(int, input().split())
	ans = adjl[a-1][b-1]
	print(-1 if ans==float("inf") else ans-1)

Fixed submission:
import sys

inp = sys.stdin
# inp = open("testdata.txt", "r")
def input():
	return inp.readline().strip()

	
n, m, l = map(int, input().split())

def warshall_floyd(d):
	for k in range(n):
		for i in range(n):
			for j in range(n):
				d[i][j] = min(d[i][j],d[i][k] + d[k][j])
	return d

adjl = [[float('inf') for j in range(n)] for i in range(n)]
for i in range(n):
	adjl[i][i] = 0

for _ in range(m):
	a, b, c = map(int, input().split())
	adjl[a-1][b-1] = c
	adjl[b-1][a-1] = c

adjl = warshall_floyd(adjl)

for i in range(n):
	for j in range(n):
		if i==j: adjl[i][j] = 0
		else: adjl[i][j] = 1 if adjl[i][j] <= l else float("inf")

adjl = warshall_floyd(adjl)

q = int(input())

for _ in range(q):
	a, b = map(int, input().split())
	ans = adjl[a-1][b-1]
	print(-1 if ans==float("inf") else ans-1)
Buggy python submission (verdict: Runtime Error):
s = input().strip()

def solve(s):
	for i in range(len(s)):
  		if i%2==0:
          if s[i] == "L":
          	return False
       	else:
          if s[i]=="R":
            return False
	return True
  
print("Yes" if solve(s) else "No")

Fixed submission:
import sys

s = sys.stdin.readline().strip()

def solve(s):
	n = len(s)
	for i in range(n):
		if i%2==0:
			if s[i] == "L":
				return False
		else:
			if s[i] == "R":
				return False
	return True

print("Yes" if solve(s) else "No")
Buggy python submission (verdict: Time Limit Exceeded):
import sys

N = int(sys.stdin.readline())
S = sys.stdin.readline().strip()

ans = 0
for L in range(1, N):
	dp = [0]*N 
	for x in range(N - L):
		if S[x] == S[x+L]:
			if x==0: dp[x] += 1
			else: dp[x] = min(dp[x-1]+1, L)
			ans = max(ans, dp[x])
print(ans)

Fixed submission:
import sys

N = int(sys.stdin.readline())
S = sys.stdin.readline().strip()

ans = 0
for L in range(1, N):
	dp = [0]*N 
	for x in range(N - L):
		if S[x] == S[x+L]:
			if x==0: dp[x] += 1
			else: dp[x] = min(dp[x-1]+1, L)
			ans = max(ans, dp[x])
print(ans)
Buggy python submission (verdict: Runtime Error):
N = input()

ans = N*(N-1)//2
print(ans)

Fixed submission:
N = int(input())

ans = N*(N-1)//2
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
arr = [0]*n

prod = 1
for i in range(n):
	ele = int(input())
	prod *= ele
	arr[i] = ele

numerator = prod

denomenator = sum(prod//ele for ele in arr)

ans = numerator/denomenator
print(ans)

Fixed submission:
from functools import reduce

n = int(input())

arr = list(map(int, input().split()))

numerator = prod = reduce(lambda x, y: x*y, arr)
denomenator = sum(prod//ele for ele in arr)

ans = numerator/denomenator
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
from collections import defaultdict

def bs(arr, val):
	l, h = 0, len(arr)-1
	ans = -1
	while l <= h:
		m = l + h >> 1
		if arr[m] > val:
			ans = m
			h = m - 1
		else:
			l = m + 1
	return ans

s = sys.stdin.readline()
n = len(s)

t = sys.stdin.readline()

occurence = defaultdict(list)
for i in range(n):
	occurence[s[i]].append(i+1)

folds = 0
cur_ptr = 0
for ele in t:
	indexes = occurence[ele]
	idx = bs(indexes, cur_ptr)
	if idx != -1: 
		cur_ptr = indexes[idx]
	else:
		folds += 1
		cur_ptr = indexes[0]
ans = folds*(n) + cur_ptr
print(ans)

Fixed submission:
import sys
from collections import defaultdict

def bs(arr, val):
	l, h = 0, len(arr)-1
	ans = -1
	while l <= h:
		m = l + h >> 1
		if arr[m] > val:
			ans = m
			h = m - 1
		else:
			l = m + 1
	return ans

s = sys.stdin.readline().strip()
n = len(s)

t = sys.stdin.readline().strip()

occurence = defaultdict(list)
for i in range(n):
	occurence[s[i]].append(i+1)

def solve():
	folds = 0
	cur_ptr = 0

	for ele in t:
		indexes = occurence[ele]
		if not indexes: return -1

		idx = bs(indexes, cur_ptr)
		if idx != -1: 
			cur_ptr = indexes[idx]
		else:
			folds += 1
			cur_ptr = indexes[0]
		# print(ele, cur_ptr, folds)
	ans = folds*(n) + cur_ptr
	return ans

print(solve())
Buggy python submission (verdict: Runtime Error):
import math
from collections import Counter, defaultdict

def ncr(n, r):
	f = math.factorial
	return f(n)//f(r)//f(n-r)

n = int(input())

dct = defaultdict(int)

for i in range(n):
	counter = Counter(input().strip())
	tpl = tuple(sorted(counter.items()))
	dct[tpl] += 1
ans = sum(ncr(val, 2) for val in dct.values())

print(ans)

Fixed submission:
import math
from collections import Counter, defaultdict

def ncr(n, r):
	f = math.factorial
	return f(n)//f(r)//f(n-r)

n = int(input())

dct = defaultdict(int)

for i in range(n):
	counter = Counter(input().strip())
	tpl = tuple(sorted(counter.items()))
	dct[tpl] += 1


ans = sum(ncr(val, 2) for val in dct.values() if val>1)
print(ans)