Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import math

N = int(input())

def f(a,b):
    if len(str(a)) < len(str(b)):
        return len(str(b))
    else:
        return len(str(a))

ans = 100000000000
for i in range(1,math.sqrt(N)+1):
    if N % i == 0:
        ans = min(ans,f(i,N//i))
print(ans)
        
        

Fixed submission:
import math

N = int(input())

def f(a,b):
    if len(str(a)) < len(str(b)):
        return len(str(b))
    else:
        return len(str(a))

ans = 100000000000
for i in range(1,int(math.sqrt(N)+1)):
    if N % i == 0:
        ans = min(ans,f(i,N//i))
print(ans)

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

def f(a,b):
    if len(str(a)) < len(str(b)):
        return len(str(b))
    else:
        return len(str(a))

ans = 100000000000
for i in range(1,N**(1/2)):
    if N % i == 0:
        ans = min(ans,f(i,N//i))
print(ans)

Fixed submission:
import math

N = int(input())

def f(a,b):
    if len(str(a)) < len(str(b)):
        return len(str(b))
    else:
        return len(str(a))

ans = 100000000000
for i in range(1,int(math.sqrt(N)+1)):
    if N % i == 0:
        ans = min(ans,f(i,N//i))
print(ans)

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

def f(a,b):
    if len(str(a)) < len(str(b)):
        return len(str(b))
    else:
        return len(str(a))

ans = 100000000000
for i in range(1,N+1):
    if N % i == 0:
        ans = min(ans,f(i,N//i))
print(ans)
        
        

Fixed submission:
import math

N = int(input())

def f(a,b):
    if len(str(a)) < len(str(b)):
        return len(str(b))
    else:
        return len(str(a))

ans = 100000000000
for i in range(1,int(math.sqrt(N)+1)):
    if N % i == 0:
        ans = min(ans,f(i,N//i))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
K,S=map(int,input().split())

count=0

for X in range(K+1):
    for Y in range(K+1):
        for Z in range(K+1):
            if X+Y+Z==S:
                count+=1

print(count)

Fixed submission:
K,S=map(int,input().split())

count=0

for X in range(K+1):
        for Y in range(K+1):
            Z=S-X-Y
            if 0<=Z<=K:
                count+=1

print(count)
Buggy python submission (verdict: Time Limit Exceeded):
h, w = map(int, input().split(' '))
a1 = 0
for i in range(0, h + w):
    if(((h * w) % 2) == 1):
        a1 = ((h * w) // 2) + 1
    elif(((h * w) % 2) == 0):
        a1 = (h * w) // 2
print(a1)

Fixed submission:
h, w = map(int, input().split(' '))
a1 = 0
if ((h == 1) or (w == 1)):
    a1 = 1
elif(((h * w) % 2) == 1):
    a1 = ((h * w) // 2) + 1
elif(((h * w) % 2) == 0):
    a1 = (h * w) // 2
print(a1)

Buggy python submission (verdict: Time Limit Exceeded):
h, w = map(int, input().split(' '))
a1 = 0
for i in range(0, h + w):
    if((h % (2 ** 32) == 0) or (w % (2 ** 32) == 0) or ((h * w) % (2 ** 32) == 0)):
        a1 = 0
    elif(((h * w) % 2) == 1):
        a1 = ((h * w) // 2) + 1
    elif(((h * w) % 2) == 0):
        a1 = (h * w) // 2
print(a1)

Fixed submission:
h, w = map(int, input().split(' '))
a1 = 0
if ((h == 1) or (w == 1)):
    a1 = 1
elif(((h * w) % 2) == 1):
    a1 = ((h * w) // 2) + 1
elif(((h * w) % 2) == 0):
    a1 = (h * w) // 2
print(a1)
Buggy python submission (verdict: Time Limit Exceeded):
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
xyc = list(list(map(int, input().split())) for _ in range(M))
l1 = []
lx = []
ly = []
min_a = min(a)
min_b = min(b)

for k in range(M):
    lx.append(list(x for x, y, c in xyc))
    ly.append(list(y for x, y, c in xyc))
    l1.append(list(c for x, y, c in xyc))
    j = lx[0][k]
    p = ly[0][k]
    max_l1 = max(list(map(int, max(l1))))
    ans = min((min_a + min_b), ((a[j - 1] + b[p - 1]) - max_l1))
print(ans)

Fixed submission:
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = min(a) + min(b)
for k in range(M):
    x, y, c = map(int, input().split())
    ans = min(ans, ((a[x - 1] + b[y - 1]) - c))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
xyc = list(list(map(int, input().split())) for _ in range(M))
l1 = []
lx = []
ly = []
for i in range(M):
    l1.append(list(c for x, y, c in xyc))
min_a = min(a)
min_b = min(b)
max_l1 = max(list(map(int, max(l1))))
for k in range(M):
    lx.append(list(x for x, y, c in xyc))
    ly.append(list(y for x, y, c in xyc))
    j = lx[0][k]
    p = ly[0][k]
    ans = min((min_a + min_b), ((a[j - 1] + b[p - 1]) - max_l1))
print(ans)

Fixed submission:
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = min(a) + min(b)
for k in range(M):
    x, y, c = map(int, input().split())
    ans = min(ans, ((a[x - 1] + b[y - 1]) - c))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
xyc = list(list(map(int, input().split())) for _ in range(M))
l1 = []
lx = []
ly = []
for i in range(100001):
    l1.append(list(c for x, y, c in xyc))
min_a = min(a)
min_b = min(b)
max_l1 = max(list(map(int, max(l1))))
for k in range(M):
    lx.append(list(x for x, y, c in xyc))
    ly.append(list(y for x, y, c in xyc))
    j = lx[0][k]
    p = ly[0][k]
    ans = min((min_a + min_b), ((a[j - 1] + b[p - 1]) - max_l1))
print(ans)

Fixed submission:
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = min(a) + min(b)
for k in range(M):
    x, y, c = map(int, input().split())
    ans = min(ans, ((a[x - 1] + b[y - 1]) - c))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
a, b, k = map(int, input().split())
while(k > 0):
    if (a > 0):
        a -= 1
        k -= 1
    elif (b > 0):
        b -= 1
        k -= 1
    else:
        k -= 1
print("%s %s" % (a, b))

Fixed submission:
a, b, k = map(int, input().split())
print(max(a - k, 0), max(b - max(k - a, 0), 0))
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split())
n = 6 - a - b
print(n)

Fixed submission:
a = int(input())
b = int(input())
n = 6 - a - b
print(n)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

offset = 0
i = 0
while i + offset < n:
    while a[i + offset] == b[i]:
        offset += 1
    i += 1

c = []
for i in range(offset, n + offset):
    c.append(b[i % n])

for i in range(n):
    if a[i] == c[i]:
        print('No')
        exit()

print('Yes')
print(*c)


Fixed submission:
import numpy as np
import sys 
read = sys.stdin.readline
n = int(input())
a = np.fromstring(read(), dtype=np.int32, sep=' ')
b = np.fromstring(read(), dtype=np.int32, sep=' ')[::-1]

kokan = []
same = -1
for i in range(n):
    if a[i] == b[i]:
        same = a[i]
if same == -1:
    print('Yes')
    print(*b)
    exit()

for i in range(n):
    if a[i] != b[i] and a[i] != same and b[i] != same:
        kokan.append(i)
for i in range(n):
    if a[i] == b[i]:
        if len(kokan) == 0:
            print('No')
            exit()
        else:
            j = kokan[-1]
            b[i], b[j] = b[j], b[i] 
            kokan.pop()
print('Yes')
print(*b)

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

offset = 0
while a[0] == b[offset]:
    offset += 1
c = []
for i in range(offset, offset + n):
    c.append(b[i % n])

for i in range(n):
    if a[i] == c[i]:
        print('No')
        exit()


print('Yes')
print(*c)


Fixed submission:
import numpy as np
import sys 
read = sys.stdin.readline
n = int(input())
a = np.fromstring(read(), dtype=np.int32, sep=' ')
b = np.fromstring(read(), dtype=np.int32, sep=' ')[::-1]

kokan = []
same = -1
for i in range(n):
    if a[i] == b[i]:
        same = a[i]
if same == -1:
    print('Yes')
    print(*b)
    exit()

for i in range(n):
    if a[i] != b[i] and a[i] != same and b[i] != same:
        kokan.append(i)
for i in range(n):
    if a[i] == b[i]:
        if len(kokan) == 0:
            print('No')
            exit()
        else:
            j = kokan[-1]
            b[i], b[j] = b[j], b[i] 
            kokan.pop()
print('Yes')
print(*b)
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
import numpy as np
n, k = map(int, stdin.readline().split())
a = np.array(stdin.readline().split(), dtype=np.int64)

ng = 0
ok = 10 ** 9 + 1
while ok - ng > 1:
    mid = (ok + ng) >> 1
    if sum(0 - - b // mid - 1 for b in a) <= k:
        ok = mid
    else:
        ng = mid
print(ok)


Fixed submission:
n, k, *a = map(int, open(0).read().split())


def c(x):
    res = 0
    for b in a:
        # bを最大がxになるように、できるだけ少ない回数で
        # だいたいb/x等分？
        res += 0 - - b // x - 1
    return res <= k


ng = 0
ok = 10 ** 10
while ok - ng > 1:
    mid = (ok + ng) >> 1
    if c(mid):
        ok = mid
    else:
        ng = mid
print(ok)

Buggy python submission (verdict: Time Limit Exceeded):
from numba import njit, i8
n, k, *a = map(int, open(0).read().split())

@njit(cache=True)
def c(x, a):
    res = 0
    for b in a:
        res += 0 - - b // x - 1
    return res <= k

ng = 0
ok = 10 ** 9 + 1
while ok - ng > 1:
    mid = (ok + ng) >> 1
    if c(mid, a):
        ok = mid
    else:
        ng = mid
print(ok)


Fixed submission:
n, k, *a = map(int, open(0).read().split())


def c(x):
    res = 0
    for b in a:
        # bを最大がxになるように、できるだけ少ない回数で
        # だいたいb/x等分？
        res += 0 - - b // x - 1
    return res <= k


ng = 0
ok = 10 ** 10
while ok - ng > 1:
    mid = (ok + ng) >> 1
    if c(mid):
        ok = mid
    else:
        ng = mid
print(ok)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
# 愚直にやると約数の個数テーブルをO(NlogN)
print(sum(i * j for i in range(1, n + 1)
          for j in range(1, n // i + 1)))


Fixed submission:
n = int(input())

ans = 0
for i in range(1, n + 1):
    m = n // i
    ans += (m + 1) * m // 2 * i
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
k = int(input())
s = input()
n = len(s)
mod = 10 ** 9 + 7

fac = [1] * (n + k + 2)
for i in range(1, n + k + 1):
    fac[i] = fac[i - 1] * i % mod


def c(n, k):
    return fac[n] * pow(fac[n - k] * fac[k] % mod, mod - 2, mod) % mod


ans = 0
for i in range(k + 1):
    ans += c(n - 1 + k - i, k - i) * \
        pow(25, k - i, mod) * pow(26, i, mod) % mod
    ans %= mod
print(ans)


Fixed submission:
k = int(input())
s = input()
n = len(s)
mod = 10 ** 9 + 7

fac = [1] * (n + k + 2)
for i in range(1, n + k + 1):
    fac[i] = fac[i - 1] * i % mod


def c(n, k):
    return fac[n] * pow(fac[n - k] * fac[k] % mod, mod - 2, mod) % mod


ans = 0
for i in range(k + 1):
    ans += c(n - 1 + k - i, k - i) * \
        pow(25, k - i, mod) * pow(26, i, mod) % mod
    ans %= mod
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, k, *a = map(int, open(0).read().split())

for _ in range(k):
    b = [0] * -~n
    for i in range(len(a)):
        b[max(0, i - a[i])] += 1
        b[min(n, i + a[i] + 1)] -= 1
    for i in range(n):
        b[i + 1] += b[i]

    if all(x == n for x in b[:n]):
        print(' '.join(map(str, b[:n])))
        exit()
    a = b
print(' '.join(map(str, a[:n])))


Fixed submission:
n, k, *a = map(int, open(0).read().split())

for _ in range(k):
    b = [0] * -~n
    for i in range(len(a)):
        b[max(0, i - a[i])] += 1
        b[min(n, i + a[i] + 1)] -= 1
    for i in range(n):
        b[i + 1] += b[i]

    if all(x == n for x in b[:n]):
        print(' '.join(map(str, b[:n])))
        exit()
    a = b
print(' '.join(map(str, a[:n])))
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
from math import gcd

mod = 10 ** 9 + 7

n = int(input())
ab = [tuple(map(int, input().split())) for _ in range(n)]

d = defaultdict(int)
for a, b in ab:
    # a[i]が絶対に非負になるように
    if a < 0:
        a *= -1
        b *= -1
    g = gcd(a, b)
    d[(a // g, b // g)] += 1

all = n
ans = 1
for k1, v in d.items():
    k2 = (k1[1], -k1[0])
    if k2 in d.keys():
        all -= v
        all -= d[k2]
        ans = ans * (pow(2, v, mod) + pow(2, d[k2], mod) - 1) % mod

ans = ans * pow(2, all, mod) % mod
print(ans - 1)


Fixed submission:
from collections import defaultdict
from math import gcd

mod = 10 ** 9 + 7

n = int(input())
ab = [tuple(map(int, input().split())) for _ in range(n)]

d = defaultdict(int)
zero = 0
for a, b in ab:
    # zero　別処理
    if a == b == 0:
        zero += 1
        continue
    if a == 0:
        d[(0, 1)] += 1
        continue
    if b == 0:
        d[(1, 0)] += 1
        continue

    # a[i]が絶対に非負になるように
    if a < 0:
        a *= -1
        b *= -1
    g = gcd(a, b)
    d[(a // g, b // g)] += 1

all = n - zero
ans = 1
for k1, v in d.items():
    k2 = (k1[1], -k1[0])
    if k2 in d.keys():
        all -= v
        all -= d[k2]
        ans = ans * (pow(2, v, mod) + pow(2, d[k2], mod) - 1) % mod
ans = ans * pow(2, all, mod) % mod
print((ans - 1 + zero) % mod)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n, k = map(int, input().split())
a = list(map(lambda x: int(x) - 1, input().split()))


tel = np.zeros((63, n), dtype=np.int)
tel[0] = a
for i in range(62):
    for j in range(n):
        tel[i + 1][j] = tel[i][tel[i][j]]

now = 0
for i in range(62, -1, -1):
    if k >> i & 1:
        now = tel[i][now]
print(now + 1)


Fixed submission:
n, k = map(int, input().split())
a = list(map(lambda x: int(x) - 1, input().split()))

table = [[0] * n for _ in [0] * 64]
table[0] = a

for i in range(61):
    for j in range(n):
        table[i + 1][j] = table[i][table[i][j]]

ans = 0
for i in range(61, -1, -1):
    if k >> i & 1:
        ans = table[i][ans]
print(ans + 1)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

n, k = map(int, input().split())
a = list(map(lambda x: int(x) - 1, input().split()))

table = np.zeros((64, n), dtype=np.int64)
table[0] = a

for i in range(61):
    for j in range(n):
        table[i + 1][j] = table[i][table[i][j]]

ans = 0
for i in range(61, -1, -1):
    if k >> i & 1:
        ans = table[i][ans]
print(ans + 1)


Fixed submission:
n, k = map(int, input().split())
a = list(map(lambda x: int(x) - 1, input().split()))

table = [[0] * n for _ in [0] * 64]
table[0] = a

for i in range(61):
    for j in range(n):
        table[i + 1][j] = table[i][table[i][j]]

ans = 0
for i in range(61, -1, -1):
    if k >> i & 1:
        ans = table[i][ans]
print(ans + 1)
Buggy python submission (verdict: Time Limit Exceeded):
h, n = map(int, input().split())
ab = [tuple(map(int, input().split())) for _ in range(n)]
inf = 1 << 30
dp = [inf] * (h + 1)
dp[h] = 0

for i in range(n):
    for j in range(h, 0, -1):
        nx = max(0, j - ab[i][0])
        dp[nx] = min(dp[nx], dp[j] + ab[i][1])
print(dp[0])


Fixed submission:
h, n = map(int, input().split())
ab = [tuple(map(int, input().split())) for _ in range(n)]
inf = 1 << 30
dp = [inf] * (h + 1)
dp[h] = 0

for i in range(n):
    for j in range(h, 0, -1):
        nx = max(0, j - ab[i][0])
        dp[nx] = min(dp[nx], dp[j] + ab[i][1])
print(dp[0])
Buggy python submission (verdict: Runtime Error):
from bisect import bisect_right

n, d, a = map(int, input().split())
xh = sorted(list(map(int, input().split())) for _ in range(n))
x = [0] * (n + 1)
h = [0] * (n + 1)
s = [0] * (n + 1)

for i, (f, g) in enumerate(xh):
    x[i], h[i] = f, g
x[n] = 10 ** 9 + 1
ans = 0
for i in range(n):
    if i > 0:
        s[i] += s[i - 1]
    h[i] -= s[i]
    if h[i] > 0:
        num = 0 - - h[i] // a
        ans += num
        s[i] += num * a

        j = bisect_right(x, x[i] + d * 2)
        s[j] -= num * a
print(ans)


Fixed submission:
from bisect import bisect_right

n, d, a = map(int, input().split())
xh = sorted(list(map(int, input().split())) for _ in range(n))
x = [0] * (n + 1)
h = [0] * (n + 1)
s = [0] * (n + 1)

for i, (f, g) in enumerate(xh):
    x[i], h[i] = f, g
x[n] = 10 ** 10 + 1
ans = 0
for i in range(n):
    if i > 0:
        s[i] += s[i - 1]
    h[i] -= s[i]
    if h[i] > 0:
        num = 0 - - h[i] // a
        ans += num
        s[i] += num * a

        j = bisect_right(x, x[i] + d * 2)
        s[j] -= num * a
print(ans)
Buggy python submission (verdict: Runtime Error):
n, u, v = map(int, input().split())
# よりたかはしくんが早く辿り着ける葉のうち、青木君から最も遠いで
u -= 1
v -= 1

g = [[] for _ in range(n)]
for _ in range(n - 1):
    a, b = map(lambda x: int(x) - 1, input().split())
    g[a].append(b)
    g[b].append(a)

INF = 1 << 30
t = [INF] * n
a = [INF] * n

t[u] = 0
a[v] = 0


def dfs(v, p, d):
    for nv in g[v]:
        if nv == p:
            continue
        if d[nv] == INF:
            d[nv] = d[v] + 1
            dfs(nv, v, d)


dfs(u, -1, t)
dfs(v, -1, a)

ans = 0
for i in range(n):
    if t[i] < a[i]:
        ans = max(ans, a[i] - 1)
print(ans)


Fixed submission:
import sys
sys.setrecursionlimit(10**6)

n, u, v = map(int, input().split())
# よりたかはしくんが早く辿り着ける葉のうち、青木君から最も遠いで
u -= 1
v -= 1

g = [[] for _ in range(n)]
for _ in range(n - 1):
    a, b = map(lambda x: int(x) - 1, input().split())
    g[a].append(b)
    g[b].append(a)

INF = 1 << 30
t = [INF] * n
a = [INF] * n

t[u] = 0
a[v] = 0


def dfs(v, p, d):
    for nv in g[v]:
        if nv == p:
            continue
        if d[nv] == INF:
            d[nv] = d[v] + 1
            dfs(nv, v, d)


dfs(u, -1, t)
dfs(v, -1, a)

ans = 0
for i in range(n):
    if t[i] < a[i]:
        ans = max(ans, a[i] - 1)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, *a = map(int, open(0).read().split())
# すべての組み合わせ
# あるビットについて、そのビットが立つ回数
mod = 10 ** 9 + 7
ans = 0
for i in range(60):
    cnt = 0
    for j in range(n):
        cnt += a[j] >> i & 1
    ans = (ans + (1 << i) * cnt * (n - cnt) % mod) % mod
print(ans)


Fixed submission:
n, *a = map(int, open(0).read().split())
mod = 10 ** 9 + 7
ans = 0
for i in range(60):
    cnt = 0
    for j in range(n):
        cnt += a[j] >> i & 1
    ans = (ans + (1 << i) * cnt * (n - cnt) % mod) % mod
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, m, l = map(int, input().split())

INF = 1 << 30
g = [[INF] * n for _ in range(n)]
for _ in range(m):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    g[a][b] = c
    g[b][a] = c

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

h = [[INF] * n for _ in range(n)]
for i in range(n):
    for j in range(n):
        if g[i][j] <= l:
            h[i][j] = 1

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

q = int(input())
for _ in range(q):
    s, t = map(lambda x: int(x) - 1, input().split())
    if h[s][t] == INF:
        print(-1)
    else:
        print(h[s][t] - 1)


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

INF = 1 << 30
g = [[INF] * n for _ in range(n)]
for _ in range(m):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    g[a][b] = c
    g[b][a] = c

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

h = [[INF] * n for _ in range(n)]
for i in range(n):
    for j in range(n):
        if g[i][j] <= l:
            h[i][j] = 1

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

q = int(input())
for _ in range(q):
    s, t = map(lambda x: int(x) - 1, input().split())
    if h[s][t] == INF:
        print(-1)
    else:
        print(h[s][t] - 1)
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
from bisect import bisect_right

s = input()
t = input()

n = len(s)

mp = [[] for _ in range(26)]
s += s
for i in range(len(s)):
    mp[ord(s[i]) - ord('a')].append(i)

ans = 0
now = -1
for i in range(len(t)):
    a = ord(t[i]) - ord('a')
    if len(mp[a]) == 0:
        print(-1)
        exit()

    nxt = bisect_right(mp[a], now)
    nxt = mp[a][nxt]
    ans += nxt - now
    if nxt > n:
        now = nxt - n
    else:
        now = nxt
print(ans)


Fixed submission:
import bisect

s = input()
t = input()
n = len(s)
s += s

pos = [[] for _ in range(26)]

for i in range(len(s)):
    pos[ord(s[i]) - ord('a')].append(i)

ans = 0
now = -1
for i in range(len(t)):
    c = ord(t[i]) - ord('a')
    j = bisect.bisect_right(pos[c], now)

    if j == len(pos[c]):
        print(-1)
        exit()
    now = pos[c][j]

    if now >= n:
        now -= n
        ans += n
print(ans + now + 1)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
v = list(map(int, input().split(' ')))
c = list(map(int, input().split(' ')))

ans = 0
for bit in range(1 << n):
    tmp = 0
    for i in range(n):
        if bit >> i & 1:
            tmp += v[i] - c[i]
    ans = max(ans, tmp)
print(ans)


Fixed submission:
n = int(input())
v = list(map(int, input().split(' ')))
c = list(map(int, input().split(' ')))

ans = 0
for i in range(n):
    ans += max(0, v[i] - c[i])
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
x, y, z, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = sorted(list(map(int, input().split())))[::-1]

a1 = sorted(a[i] + b[j] for i in range(x) for j in range(y))[::-1]
a2 = sorted(a1[i] + c[j] for i in range(min(len(a1), k))
            for j in range(z))[::-1]
for i in range(k):
    print(a2[i])


Fixed submission:
x, y, z, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = sorted(list(map(int, input().split())))[::-1]

a1 = sorted(a[i] + b[j] for i in range(x) for j in range(y))[::-1]
a2 = sorted(a1[i] + c[j] for i in range(min(len(a1), k))
            for j in range(z))[::-1]
for i in range(k):
    print(a2[i])
Buggy python submission (verdict: Runtime Error):
import math
n, x = list(map(int, input().split(' ')))
a = list(map(int, input().split(' ')))
ans = abs(a[0] - x)
for i in range(1, n):
    ans = math.gcd(ans, abs(x - a[i]))
print(ans)

Fixed submission:
from fractions import gcd
n, x, *a = list(map(int, open(0).read().split()))
ans = abs(a[0] - x)
for i in range(1, n):
    ans = gcd(ans, abs(x - a[i]))
print(ans)

Buggy python submission (verdict: Runtime Error):
import math
n, x, *a = list(map(int, open(0).read().split()))
ans = abs(a[0] - x)
for i in range(1, n):
    ans = math.gcd(ans, abs(x - a[i]))
print(ans)


Fixed submission:
from fractions import gcd
n, x, *a = list(map(int, open(0).read().split()))
ans = abs(a[0] - x)
for i in range(1, n):
    ans = gcd(ans, abs(x - a[i]))
print(ans)

Buggy python submission (verdict: Runtime Error):
import math
n, x, *a = list(map(int, open(0).read().split()))
a.append(x)
a = sorted(a)
ans = a[1] - a[0]
for i in range(1, n - 1):
    ans = math.gcd(ans, abs(a[i + 1] - a[i]))
print(ans)


Fixed submission:
from fractions import gcd
n, x, *a = list(map(int, open(0).read().split()))
ans = abs(a[0] - x)
for i in range(1, n):
    ans = gcd(ans, abs(x - a[i]))
print(ans)