Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
MOD = 10**9+7

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

def gcd(x,y):
    while y:
        x,y = y,x%y
    return x

LCM = A[0]
for i in range(1,N):
    GCD = gcd(LCM,A[i])
    LCM = LCM*A[i]//GCD

ans = 0

for i in range(N):
    ans += LCM//A[i]
    ans %= MOD

print(ans%MOD)

Fixed submission:
MOD = 10**9+7

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

def gcd(x,y):
    while y:
        x,y = y,x%y
    return x

LCM = A[0]
for i in range(1,N):
    GCD = gcd(LCM,A[i])
    LCM = LCM*A[i]//GCD
LCM %= MOD
ans = 0

for i in range(N):
    ans += LCM*pow(A[i],MOD-2,MOD)
    ans %= MOD

print(ans%MOD)
Buggy python submission (verdict: Time Limit Exceeded):
class Factorial():
    def __init__(self, n, mod):
        self.mod = mod
        self.factorial = [0 for _ in range(n + 1)]
        self.inv = [0 for _ in range(n + 1)]
        self.factorial[0] = 1
        self.inv[0] = 1
        for i in range(n):
            self.factorial[i + 1] = self.factorial[i] * (i + 1) % mod
        self.inv[n] = pow(self.factorial[n], mod - 2, mod)
        for i in range(n)[::-1]:
            self.inv[i] = self.inv[i + 1] * (i + 1) % mod

    def fact(self, m):
        return self.factorial[m]

    def invfact(self, m):
        return self.inv[m]


MOD = 10**9 + 7

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

D = [X[i + 1] - X[i] for i in range(N - 1)]

F = Factorial(N + 1, MOD)

res = 0
f = 0

for i in range(N - 1):
    f = (i + 1) * f + F.fact(i)
    res += D[i] * f * F.invfact(i + 1) * F.fact(N - 1)
    res %= MOD

print(res)

Fixed submission:
class Factorial():
    def __init__(self, n, mod):
        self.mod = mod
        self.factorial = [0 for _ in range(n + 1)]
        self.inv = [0 for _ in range(n + 1)]
        self.factorial[0] = 1
        self.inv[0] = 1
        for i in range(n):
            self.factorial[i + 1] = self.factorial[i] * (i + 1) % mod
        self.inv[n] = pow(self.factorial[n], mod - 2, mod)
        for i in range(n)[::-1]:
            self.inv[i] = self.inv[i + 1] * (i + 1) % mod

    def fact(self, m):
        return self.factorial[m]

    def invfact(self, m):
        return self.inv[m]


MOD = 10**9 + 7

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

D = [X[i + 1] - X[i] for i in range(N - 1)]

F = Factorial(N + 1, MOD)

res = 0
f = 0

for i in range(N - 1):
    f = (i + 1) * f + F.fact(i)
    f %= MOD
    res += D[i] * f * F.invfact(i + 1) * F.fact(N - 1)
    res %= MOD

print(res)
Buggy python submission (verdict: Runtime Error):
from functools import reduce

def gcd(x,y):
    while y: x,y = y,x%y
    return x

def lcm(x,y):
    return x//gcd(x,y)*y

def ex_euclid(x,y):
    c0,c1 = x,y
    a0,a1 = 1,0
    b0,b1 = 0,1
    while c1:
        a0,a1 = a1,a0-c0//c1*a1
        b0,b1 = b1,b0-c0//c1*b1
        c0,c1 = c1,c0%c1
    return c0,a0,b0

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

LCM = reduce(lcm,A)

SCMs = []
flag = True

for i in range(N-1):
    c,a,b = ex_euclid(A[i],-A[i+1])
    if (A[i+1]-A[i])//2%c == 0:
        SCMs.append(A[i]*((A[i+1]-A[i])//2//c)*a+A[i]//2)
    else:
        flag = False
        break
        
print((M-reduce(lcm,SCMs)%LCM)//LCM+1 if flag else 0)

Fixed submission:
from functools import reduce

def gcd(x,y):
    while y: x,y = y,x%y
    return x

def lcm(x,y):
    return x//gcd(x,y)*y

def ex_euclid(x,y):
    c0,c1 = x,y
    a0,a1 = 1,0
    b0,b1 = 0,1
    while c1:
        a0,a1 = a1,a0-c0//c1*a1
        b0,b1 = b1,b0-c0//c1*b1
        c0,c1 = c1,c0%c1
    return c0,a0,b0

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

if N == 1:
    a = A[0]
    print((M-a//2%a)//a+1)

else:
    LCM = reduce(lcm,A)

    SCMs = []
    flag = True

    for i in range(N-1):
        c,a,b = ex_euclid(A[i],-A[i+1])
        if (A[i+1]-A[i])//2%c == 0:
            SCMs.append(A[i]*((A[i+1]-A[i])//2//c)*a+A[i]//2)
        else:
            flag = False
            break

    print((M-reduce(lcm,SCMs)%LCM)//LCM+1 if flag else 0)
Buggy python submission (verdict: Runtime Error):
MOD = 1000000007

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

C.sort(reverse=True)

ans = 0

for i in range(N):
    ans += C[i]*(2+i)*pow(2,N-2,MOD)*pow(2,N,MOD)
    ans %= MOD

print(ans)

Fixed submission:
MOD = 1000000007

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

C.sort(reverse=True)

ans = 0

if N > 1:
    for i in range(N):
        ans += C[i]*(2+i)*pow(2,N-2,MOD)*pow(2,N,MOD)
        ans %= MOD
else:
    ans = 2*C[0]%MOD

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
MOD = 1000000007
N = int(input())
A = sorted(list(map(int,input().split())))
ans = 0
for i in range(N-1):
    for j in range(i+1,N):
        ans += A[i]^A[j]
        ans %= MOD
print(ans%MOD)

Fixed submission:
MOD = 1000000007

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

def sumXOR(arr,n):
    xorsum = 0
    for i in range(64):
        zc = 0
        oc = 0
        idsum = 0
        for j in range(n):
            if arr[j] % 2 == 0:
                zc += 1
            else:
                oc += 1
            arr[j] = arr[j]//2
        idsum = oc*zc*(1 << i)
        xorsum += idsum
        xorsum %= MOD
    return xorsum

XORSUM = 0
XORSUM = sumXOR(A,N);
print(XORSUM%MOD)
Buggy python submission (verdict: Time Limit Exceeded):
H,W = map(int,input().split())
A = [list(map(int,input().split())) for _ in range(H)]
B = [list(map(int,input().split())) for _ in range(H)]

C = [[0 for j in range(W)] for i in range(H)]

for i in range(H):
    for j in range(W):
        C[i][j] = abs(A[i][j]-B[i][j])

dp = [[[0 for k in range(6400)] for j in range(W)] for i in range(H)]
dp[0][0][C[0][0]] = 1

for i in range(H):
    for j in range(W):
        for k in range(6400):
            if not dp[i][j][k]:
                continue
            ni,nj = i+1,j+1
            if ni < H:
                if k+C[ni][j]<6400:
                    dp[ni][j][k+C[ni][j]] = 1
                dp[ni][j][abs(k-C[ni][j])] = 1
            if nj < W:
                if k+C[i][nj]<6400:
                    dp[i][nj][k+C[i][nj]] = 1
                dp[i][nj][abs(k-C[i][nj])] = 1

for k in range(6400):
    if dp[-1][-1][k]:
        print(k)
        break

Fixed submission:
def main():

    H,W = map(int,input().split())
    A = [list(map(int,input().split())) for _ in range(H)]
    B = [list(map(int,input().split())) for _ in range(H)]

    C = [[0 for j in range(W)] for i in range(H)]

    for i in range(H):
        for j in range(W):
            C[i][j] = abs(A[i][j]-B[i][j])

    dp = [[0 for k in range(6400)] for g in range(H*W)]
    dp[0][C[0][0]] = 1

    for g in range(H*W):
        i,j = divmod(g,W)
        for k in range(6400):
            if not dp[i*W+j][k]:
                continue
            ni,nj = i+1,j+1
            if ni < H:
                if k+C[ni][j]<6400:
                    dp[ni*W+j][k+C[ni][j]] = 1
                dp[ni*W+j][abs(k-C[ni][j])] = 1
            if nj < W:
                if k+C[i][nj]<6400:
                    dp[i*W+nj][k+C[i][nj]] = 1
                dp[i*W+nj][abs(k-C[i][nj])] = 1

    for k in range(6400):
        if dp[-1][k]:
            print(k)
            break

main()
Buggy python submission (verdict: Time Limit Exceeded):
T1,T2 = map(int,input().split())
A1,A2 = map(int,input().split())
B1,B2 = map(int,input().split())

A = 0
B = 0
ans = 0

if B1*T1+B2*T2==A1*T1+A2*T2:
    print('infinity')
    exit()

while True:
    flag1,flag2 = False,False
    if A>B and B+B1*T1>=A+A1*T1:
        ans += 1
    elif A<B and B+B1*T1<=A+A1*T1:
        ans += 1
    else:
        flag1 = True
    A += A1*T1
    B += B1*T1
    if A>B and B+B2*T2>=A+A2*T2:
        ans += 1
    elif A<B and B+B2*T2<=A+A2*T2:
        ans += 1
    else:
        flag2 = True
    A += A2*T2
    B += B2*T2

    if flag1 and flag2:
        break
print(ans)

Fixed submission:
T1,T2 = map(int,input().split())
A1,A2 = map(int,input().split())
B1,B2 = map(int,input().split())

C1 = (A1-B1)*T1
C2 = (A2-B2)*T2

if C1+C2==0:
    print('infinity')
elif C1*(C1+C2)>0:
    print(0)
else:
    if abs(C1)%abs(C1+C2)==0:
        print(abs(C1)//abs(C1+C2)*2)
    else:
        print(abs(C1)//abs(C1+C2)*2+1)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

N = int(input())
edge = [list(map(int,input().split())) for i in range(N-1)]

graph = [[] for i in range(N)]
for e in edge:
    graph[e[0]-1].append(e[1]-1)
    graph[e[1]-1].append(e[0]-1)

K = 0
for g in graph:
    K = max(K,len(g))
print(K)

color = [[] for i in range(N)]
L = []
i = 0
for e in edge:
    while True:
        if i%K not in color[e[0]-1] and i%K not in color[e[1]-1]:
            L.append(i%K)
            color[e[0]-1].append(i%K)
            color[e[1]-1].append(i%K)
            break
        i += 1


for l in L:
    print(l+1)

Fixed submission:
import sys
input = sys.stdin.readline
from collections import deque

N = int(input())
edge = [list(map(int,input().split())) for i in range(N-1)]

graph = [[] for i in range(N)]
for e in edge:
    graph[e[0]-1].append(e[1]-1)

queue = deque()
queue.append(0)

color = [-1 for _ in range(N)]

k = 0

while queue:
    c = 0
    node = queue.popleft()
    for adj in graph[node]:
        if color[node] == c:
            c += 1
        color[adj] = c
        k = max(k,c+1)
        c += 1
        queue.append(adj)
print(k)

for e in edge:
    print(color[e[1]-1]+1)
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
A = sorted(list(map(int,input().split())))
F = sorted(list(map(int,input().split())),reverse=True)

low = -1
high = 10**12

while high - low > 1:
    score = (low+high)//2
    training = 0
    for i in range(n):
        if A[i]*F[i] > score:
            training += A[i] - score//F[i]
    if training <= k:
        high = score
    else:
        low = score
        
print(high)

Fixed submission:
n,k = map(int,input().split())
A = sorted(list(map(int,input().split())))
F = sorted(list(map(int,input().split())),reverse=True)

low = -1
high = 10**12

while high - low > 1:
    score = (low+high)//2
    training = 0
    for i in range(n):
        if A[i]*F[i] > score:
            training += A[i] - score//F[i]
    if training <= k:
        high = score
    else:
        low = score
        
print(high)
Buggy python submission (verdict: Time Limit Exceeded):
n,m,l = map(int,input().split())
Edge = [list(map(int,input().split())) for i in range(m)]
q = int(input())
Query = [list(map(int,input().split())) for i in range(q)]

D2 = [[float("inf") for i in range(n)] for i in range(n)]
for i in range(m):
    if Edge[i][2] <= l:
        D2[Edge[i][0]-1][Edge[i][1]-1] = Edge[i][2]
        D2[Edge[i][1]-1][Edge[i][0]-1] = Edge[i][2]
for i in range(n):
    D2[i][i] = 0

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

D2 = warshall_floyd(D2)

D = [[float("inf") for i in range(n)] for i in range(n)]
for i in range(m):
    if Edge[i][2] <= l:
        D[Edge[i][0]-1][Edge[i][1]-1] = 1
        D[Edge[i][1]-1][Edge[i][0]-1] = 1
for i in range(n):
    D[i][i] = 0
for i in range(n):
    for j in range(n):
        if D2[i][j] <= l:
            D[i][j] = 1

D = warshall_floyd(D)

for query in Query:
    if D[query[0]-1][query[1]-1] != float('inf'):
        print(D[query[0]-1][query[1]-1]-1)
    else:
        print(-1)


Fixed submission:
def main():

    import sys
    input = sys.stdin.readline

    n,m,l = map(int,input().split())
    Edge = [list(map(int,input().split())) for i in range(m)]
    q = int(input())
    Query = [list(map(int,input().split())) for i in range(q)]

    D2 = [[float("inf") for i in range(n)] for i in range(n)]
    for i in range(m):
        D2[Edge[i][0]-1][Edge[i][1]-1] = Edge[i][2]
        D2[Edge[i][1]-1][Edge[i][0]-1] = Edge[i][2]
    for i in range(n):
        D2[i][i] = 0

    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

    D2 = warshall_floyd(D2)

    D = [[float("inf") for i in range(n)] for i in range(n)]
    for i in range(m):
        if Edge[i][2] <= l:
            D[Edge[i][0]-1][Edge[i][1]-1] = 1
            D[Edge[i][1]-1][Edge[i][0]-1] = 1
    for i in range(n):
        D[i][i] = 0
    for i in range(n):
        for j in range(n):
            if D2[i][j] <= l:
                D[i][j] = 1

    D = warshall_floyd(D)

    for query in Query:
        if D[query[0]-1][query[1]-1] != float('inf'):
            print(D[query[0]-1][query[1]-1]-1)
        else:
            print(-1)
if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def gcd(x,y):
  if y == 0:
    return x
  else:
    return gcd(y,x%y)

def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]


a,b = map(int,input().split())

GCD = gcd(a,b)
count = 0
Primes = primes(GCD//2+1)

for prime in Primes:
    if GCD % prime == 0:
        count += 1
print(count+1)

Fixed submission:
def gcd(x,y):
  if y == 0:
    return x
  else:
    return gcd(y,x%y)

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr



a,b = map(int,input().split())

GCD = gcd(a,b)

fac = factorization(GCD)

if fac[0][0] == 1:
    print(1)
else:
    print(len(factorization(GCD))+1)

Buggy python submission (verdict: Runtime Error):
def gcd(x,y):
  if y == 0:
    return x
  else:
    return gcd(y,x%y)

def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]


a,b = map(int,input().split())

GCD = gcd(a,b)
count = 0
for prime in primes(GCD):
    if GCD % prime == 0:
        count += 1
print(count+1)

Fixed submission:
def gcd(x,y):
  if y == 0:
    return x
  else:
    return gcd(y,x%y)

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr



a,b = map(int,input().split())

GCD = gcd(a,b)

fac = factorization(GCD)

if fac[0][0] == 1:
    print(1)
else:
    print(len(factorization(GCD))+1)
Buggy python submission (verdict: Runtime Error):
from collections import deque

class Graph(): #directed
    def __init__(self, n, edge, indexed=1):
        self.n = n
        self.graph = [[] for _ in range(n)]
        for e in edge:
            self.graph[e[0] - indexed].append(e[1] - indexed)

INF = 10**18

N, M = map(int, input().split())
edge = [tuple(map(int, input().split())) for _ in range(M)]

g = Graph(N, edge)

loopsize = INF

for i in range(N):
    root = i
    queue = deque([root])
    dist = [INF for _ in range(N)]
    dist[root] = 0
    prev = [None for _ in range(N)]
    while queue:
        node = queue.popleft()
        for adj in g.graph[node]:
            if adj == root: #閉路を検出する
                dist[root] = dist[node] + 1
                prev[root] = node
                break
            if dist[adj] != INF:
                continue
            dist[adj] = dist[node] + 1
            prev[adj] = node
            queue.append(adj)
        else:
            continue
        break
    #最小の閉路なら条件を満たす
    if loopsize > dist[root]:
        loopsize = dist[root]
        path = [root]
        node = root
        while prev[node] != root:
            node = prev[node]
            path.append(node)
        res = path

if loopsize != INF:
    print(loopsize)
    for node in res:
        print(node + 1)
else:
    print(-1)

Fixed submission:
from collections import deque

class Graph(): #directed
    def __init__(self, n, edge, indexed=1):
        self.n = n
        self.graph = [[] for _ in range(n)]
        for e in edge:
            self.graph[e[0] - indexed].append(e[1] - indexed)

INF = 10**18

N, M = map(int, input().split())
edge = [tuple(map(int, input().split())) for _ in range(M)]

g = Graph(N, edge)

loopsize = INF

for i in range(N):
    root = i
    stack = [root]
    visited = [0 for _ in range(N)]
    visited[root] = 1
    while stack:
        node = stack.pop()
        for adj in g.graph[node]:
            if adj == root: #閉路を検出
                break
            if visited[adj]:
                continue
            visited[adj] = 1
            stack.append(adj)
        else:
            continue
        break
    else:
        continue
    #閉路があるとき
    queue = deque([root])
    dist = [INF for _ in range(N)]
    dist[root] = 0
    prev = [None for _ in range(N)]
    while queue:
        node = queue.popleft()
        for adj in g.graph[node]:
            if adj == root:
                dist[root] = dist[node] + 1
                prev[root] = node
                break
            if dist[adj] != INF:
                continue
            dist[adj] = dist[node] + 1
            prev[adj] = node
            queue.append(adj)
        else:
            continue
        break
    #最小サイズの閉路なら条件を満たす
    if loopsize > dist[root]:
        loopsize = dist[root]
        path = [root]
        node = root
        while prev[node] != root:
            node = prev[node]
            path.append(node)
        res = path

if loopsize != INF:
    print(loopsize)
    for node in res:
        print(node + 1)
else:
    print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
A = list(map(int,input().split()))
A.sort(reverse=True)
for i in range(m):
    A[0] = A[0]//2
    A = sorted(A,reverse=True)
print(sum(A))

Fixed submission:
import heapq
n,m = map(int,input().split())
A = list(map(int,input().split()))
A = [(-a,a) for a in A]
heapq.heapify(A)
for i in range(m):
    max = heapq.heappop(A)[1]
    max //= 2
    heapq.heappush(A,(-max,max))
print(sum([a[1] for a in A]))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

res = 0

for i in range(N - 1):
    for j in range(i + 1, N):
        if S[i:j] not in S[j:]:
            break
    res = max(res, j - i - 1)

print(res)

Fixed submission:
n = int(input())
s = input()

ans = 0
right = 1

for left in range(n):
    while s[left:right] in s[right:]:
        ans = max(ans,right-left)
        right += 1
        
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict

N = int(input())
S = input()
D = defaultdict(int)

res = 0

for i in range(N):
    for j in range(i + 1, N + 1):
        s = S[i:j]
        if s in D and D[s] + (j - i) <= i:
            res = max(res, j - i)
        else:
            D[s] = i

print(res)

Fixed submission:
n = int(input())
s = input()

ans = 0
right = 1

for left in range(n):
    while s[left:right] in s[right:]:
        ans = max(ans,right-left)
        right += 1
        
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict

N = int(input())
S = input()
D = defaultdict(int)

res = 0

for i in range(N):
    for j in range(i + 1, N + 1):
        s = S[i:j]
        if s in D and D[s] + (j - i) <= i:
            res = max(res, j - i)
        D[s] = i
        
print(res)

Fixed submission:
n = int(input())
s = input()

ans = 0
right = 1

for left in range(n):
    while s[left:right] in s[right:]:
        ans = max(ans,right-left)
        right += 1
        
print(ans)

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

dp = [[0 for j in range(n+1)] for i in range(n+1)]
dp[0][0] = 0

for i in range(n):
    for j in range(1,n):
        if s[i] == s[j] and i+dp[i][j]+1 <= j:
            dp[i+1][j+1] = max(dp[i][j+1],dp[i+1][j],dp[i][j]+1)
        else:
            dp[i+1][j+1] = max(dp[i][j+1],dp[i+1][j])

print(dp[-1][-1])

Fixed submission:
n = int(input())
s = input()

ans = 0
right = 1

for left in range(n):
    while s[left:right] in s[right:]:
        ans = max(ans,right-left)
        right += 1
        
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int, input().split())
A = list(map(int, input().split()))
sorted_A = sorted(A)

inv_A = 0
for i in range(0,N):
  for j in range(0,N):
    if i<j and A[i] > A[j]:
      inv_A += 1

inv_sorted_A = 0
for i in range(0,N):
  for j in range(0,N):
    if i<j and sorted_A[i] < sorted_A[j]:
      inv_sorted_A += 1

count = inv_A
for i in range(1,K):
  count += (inv_sorted_A * i) % 1000000007 + inv_A % 1000000007

print(count)  

Fixed submission:
N,K = map(int, input().split())
A = list(map(int, input().split()))
sorted_A = sorted(A)

inv_A = 0
for i in range(0,N):
  for j in range(0,N):
    if i<j and A[i] > A[j]:
      inv_A += 1

inv_sorted_A = 0
for i in range(0,N):
  for j in range(0,N):
    if i<j and sorted_A[i] < sorted_A[j]:
      inv_sorted_A += 1

if K == 1:
  print(inv_A)
else:  
  count = inv_sorted_A * K * (K-1) // 2  + inv_A * K 
  print(count % 1000000007)
Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int,input().split())

Edges = [list(map(int,input().split())) for i in range(n-1)]

Graph = [[] for i in range(n)]
for edge in Edges:
    Graph[edge[0]-1].append(edge[1]-1)
    Graph[edge[1]-1].append(edge[0]-1)

Points = [list(map(int,input().split())) for i in range(q)]

Counter = [0 for i in range(n)]
for point in Points:
  Counter[point[0]-1] += point[1]

Parents = [-1 for i in range(n)]
Parents[0] = 0

stack = [0]
while stack:
    node = stack.pop()
    for adj in Graph[node]:
        if Parents[adj] == -1:
            Parents[adj] = node
            Counter[adj] += Counter[node]
            stack.append(adj)

print(*Counter)

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

Edges = [list(map(int,input().split())) for i in range(n-1)]

Graph = [[] for i in range(n)]
for edge in Edges:
    Graph[edge[0]-1].append(edge[1]-1)
    Graph[edge[1]-1].append(edge[0]-1)

Points = [list(map(int,input().split())) for i in range(q)]

Counter = [0 for i in range(n)]
for point in Points:
  Counter[point[0]-1] += point[1]

Parents = [-1 for i in range(n)]
Parents[0] = 0

stack = [0]
while stack:
    node = stack.pop()
    for adj in Graph[node]:
        if Parents[adj] == -1:
            Parents[adj] = node
            Counter[adj] += Counter[node]
            stack.append(adj)

print(*Counter)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
t = input()
schr = [0]*26
tchr = [0]*26
for i in range(len(s)):
    schr[ord(s[i])-97] = 1
for i in range(len(t)):
    tchr[ord(t[i])-97] = 1
for i in range(26):
    if tchr[i] and not schr[i]:
        print(-1)
        break
else:
    i = 0
    j = 0
    while True:
        if s[i%len(s)] == t[j]:
            if j==len(t)-1:
                break
            j += 1
        i += 1
    print(i+1)

Fixed submission:
import bisect

s = input()
t = input()

ss = s+s

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

for i in range(len(ss)):
    char[ord(ss[i])-97].append(i+1)

ans = 0
tmp = 0

for i in range(len(t)):
    if not char[ord(t[i])-97]:
        print(-1)
        break
    
    k = bisect.bisect_right(char[ord(t[i])-97],tmp)
    ans += char[ord(t[i])-97][k]-tmp
    tmp = char[ord(t[i])-97][k]
    if tmp-len(s)>0:
        tmp -= len(s)
    
else:
    print(ans)