Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np


n = int(input())
a = [2*int(_) for _ in input().split()]
s = []
for i in range(n):
    l = [0 for _ in range(n)]
    l[i] = 1
    if i+1 != n:
        l[i+1] = 1
    else:
        l[0] = 1
    s.append(l)
A = np.array(s)
b = np.array(a)
Ainv = np.linalg.inv(A)
x = np.dot(Ainv, b)
for i in range(len(x)):
    print(int(x[i]))

Fixed submission:
n = int(input())
a = [2*int(_) for _ in input().split()]
t = a[-1]
x = [0 for _ in range(n)]
for i in range(-2, -n-1, -1):
    t = a[i] - t
x[0] = t // 2
for i in range(0, n-1):
    x[i+1] = a[i] - x[i]
for i in range(len(x)):
    print(x[i])

Buggy python submission (verdict: Runtime Error):
import numpy as np


n = int(input())
a = [2*int(_) for _ in input().split()]
s = []
for i in range(n):
    l = [0 for _ in range(n)]
    l[i] = 1
    if i+1 != n:
        l[i+1] = 1
    else:
        l[0] = 1
    s.append(l)
A = np.array(s)
b = np.array(a)
Ainv = np.linalg.inv(A)
x = np.dot(Ainv, b)
for i in range(len(x)):
    print(int(x[i]))

Fixed submission:
n = int(input())
a = [2*int(_) for _ in input().split()]
t = a[-1]
x = [0 for _ in range(n)]
for i in range(-2, -n-1, -1):
    t = a[i] - t
x[0] = t // 2
for i in range(0, n-1):
    x[i+1] = a[i] - x[i]
for i in range(len(x)):
    print(x[i])
Buggy python submission (verdict: Time Limit Exceeded):
import sys


n, m = [int(_) for _ in input().split()]
l = []
for i in range(m):
    l.append(int(input()))

d = [0] * (n + 2)
d[0] = 1
if 1 not in l:
    d[1] = 1
for i in range(n):
    if i in l and i + 1 in l:
        print(0)
        sys.exit()
    elif i in l:
        d[i + 2] = d[i + 1]
    elif i + 1 in l:
        d[i + 2] = d[i]
    else:
        d[i + 2] = d[i] + d[i + 1]
    d[i + 2] = d[i + 2] % (10 ** 9 + 7)
print(d[-2])

Fixed submission:
import sys


n, m = [int(_) for _ in input().split()]
l = {}
for i in range(m):
    l[int(input())] = 1

d = [0] * (n + 2)
d[0] = 1
if 1 not in l:
    d[1] = 1
for i in range(n):
    if i in l and i + 1 in l:
        print(0)
        sys.exit()
    elif i in l:
        d[i + 2] = d[i + 1]
    elif i + 1 in l:
        d[i + 2] = d[i]
    else:
        d[i + 2] = d[i] + d[i + 1]
    d[i + 2] = d[i + 2] % (10 ** 9 + 7)
print(d[-2])
Buggy python submission (verdict: Time Limit Exceeded):
import heapq


n,m = [int(_) for _ in input().split()]
a = [int(_) for _ in input().split()]
bc = []
for i in range(m):
    bc.append([int(_) for _ in input().split()])
bc = sorted(bc, key=lambda x:x[1])
heapq.heapify(a)
for _ in range(m):
    b,c = bc.pop()
    for i in range(b):
        num = heapq.heappop(a)
        if num < c:
            heapq.heappush(a, c)
        else:
            heapq.heappush(a, num)
ans = 0
for i in range(len(a)):
    ans += a[i]
print(ans)

Fixed submission:
import bisect


n,m = [int(_) for _ in input().split()]
a = [int(_) for _ in input().split()]
bc = []
for i in range(m):
    bc.append([int(_) for _ in input().split()])
bc = sorted(bc, key=lambda x:x[1])
a = sorted(a)
t = 0
ans = 0
for _ in range(m):
    b,c = bc.pop()
    idx = bisect.bisect_left(a, c)
    if idx > t:
        ans += c * min(idx - t, b)
        t += min(idx - t, b)
    else:
        continue
for i in range(t, n):
    ans += a[i]
print(ans)
Buggy python submission (verdict: Runtime Error):
n,k = [int(_) for _ in input().split()]
s = input()

c0 = 0
c1 = 0
a = [0]
b = []
v = 0
while s[v] == '0':
    c0 += 1
    s = s[1:]
b.append(c0)
c0 = 0
for i in range(len(s)):
    if s[i] == '1':
        c1 += 1
        if c0 != 0:
            b.append(c0)
        c0 = 0
    else:
        c0 += 1
        if c1 != 0:
            a.append(c1)
        c1 = 0
if c0 != 0:
    b.append(c0)
else:
    a.append(c1)
    b.append(0)
a.append(0)
# print(a)
# print(b)

s_a = [0]
s_b = [0]
for i in range(len(a)):
    s_a.append(s_a[i]+a[i])
for i in range(len(b)):
    s_b.append(s_b[i]+b[i])
# print(s_a)
# print(s_b)

ans = 0
if len(b) <= k:
    ans = n
else:
    for i in range(len(a)-k):
        # print(s_a[i+k+1] - s_a[i] + s_b[i+k] - s_b[i])
        ans = max(ans, s_a[i+k+1] - s_a[i] + s_b[i+k] - s_b[i])  
print(ans)


Fixed submission:
import sys


n,k = [int(_) for _ in input().split()]
s = input()

all_0 = True
for i in range(len(s)):
    if s[i] == '1':
        all_0 = False
        break
if all_0:
    if k == 0:
        print(0)
    else:
        print(n)
    sys.exit()

c0 = 0
c1 = 0
a = [0]
b = []
v = 0
while s[v] == '0':
    c0 += 1
    s = s[1:]
b.append(c0)
c0 = 0
for i in range(len(s)):
    if s[i] == '1':
        c1 += 1
        if c0 != 0:
            b.append(c0)
        c0 = 0
    else:
        c0 += 1
        if c1 != 0:
            a.append(c1)
        c1 = 0
if c0 != 0:
    b.append(c0)
else:
    a.append(c1)
    b.append(0)
a.append(0)
# print(a)
# print(b)

s_a = [0]
s_b = [0]
for i in range(len(a)):
    s_a.append(s_a[i]+a[i])
for i in range(len(b)):
    s_b.append(s_b[i]+b[i])
# print(s_a)
# print(s_b)

ans = 0
if len(b) <= k:
    ans = n
else:
    for i in range(len(a)-k):
        # print(s_a[i+k+1] - s_a[i] + s_b[i+k] - s_b[i])
        ans = max(ans, s_a[i+k+1] - s_a[i] + s_b[i+k] - s_b[i])  
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys


sys.setrecursionlimit(10000)


def my_search(l, low, high, t):
    n = (low+high)//2
    if t > l[n]:
        low = n
    else:
        high = n
    if high == low + 1:
        return low
    else:
        return my_search(l, low, high, t)

a,b,q = [int(_) for _ in input().split()]
s_l = [-float('inf')]
t_l = [-float('inf')]
x_l = []
for i in range(a):
    s_l.append(int(input()))
s_l.append(float('inf'))
for i in range(b):
    t_l.append(int(input()))
t_l.append(float('inf'))
for i in range(q):
    x_l.append(int(input()))
for i in range(q):
    x = x_l[i]
    s1_id = my_search(s_l, 0, len(s_l)-1, x)
    s2_id = s1_id + 1
    s1 = s_l[s1_id]
    s2 = s_l[s2_id]
    t1_id = my_search(t_l, 0, len(t_l)-1, x)
    t2_id = t1_id + 1
    t1 = t_l[t1_id]
    t2 = t_l[t2_id]
    res = float('inf')
    for s in [s1,s2]:
        for t in [t1,t2]:
            d1, d2 = abs(s-x) + abs(t-s), abs(t-x) + abs(s-t)
            res = min(res, d1, d2)
    print(res)


Fixed submission:
import bisect


a,b,q = [int(_) for _ in input().split()]
s_l = [-float('inf')]
t_l = [-float('inf')]
x_l = []
for i in range(a):
    s_l.append(int(input()))
s_l.append(float('inf'))
for i in range(b):
    t_l.append(int(input()))
t_l.append(float('inf'))
for i in range(q):
    x_l.append(int(input()))
for i in range(q):
    x = x_l[i]
    s1_id = bisect.bisect_left(s_l, x) - 1 
    s2_id = s1_id + 1
    s1 = s_l[s1_id]
    s2 = s_l[s2_id]
    t1_id = bisect.bisect_left(t_l, x) - 1 
    t2_id = t1_id + 1
    t1 = t_l[t1_id]
    t2 = t_l[t2_id]
    res = float('inf')
    for s in [s1,s2]:
        for t in [t1,t2]:
            d1, d2 = abs(s-x) + abs(t-s), abs(t-x) + abs(s-t)
            res = min(res, d1, d2)
    print(res)
Buggy python submission (verdict: Runtime Error):
ans1 = 0
ans2 = 0
if n % 2 == 1:
    for i in range((n-3)//2):
        ans1 += 2 * l[i]
    ans1 += l[(n-3)//2] + l[(n-3)//2+1]
    for i in range((n-3)//2+2, n):
        ans1 -= 2 * l[i]

    for j in range((n-1)//2):
        ans2 += 2 * l[j]
    ans2 -= l[(n-1)//2] + l[(n-1)//2+1]
    for j in range((n-1)//2+2, n):
        ans2 -= 2 * l[i]

else:
    for i in range(((n-2)//2)):
        ans1 += 2 * l[i]
    ans1 += l[(n-2)//2]
    ans1 -= l[(n-2)//2+1]
    for i in range((n-2)//2+2, n):
        ans1 -= 2 * l[i]

ans = max(ans1, ans2)
print(ans)

Fixed submission:
n = int(input())
l = [0] * n
for i in range(n):
    l[i] = int(input())
l.sort(reverse=True)
ans1 = 0
ans2 = 0
if n % 2 == 1:
    for i in range((n-3)//2):
        ans1 += 2 * l[i]
    ans1 += l[(n-3)//2] + l[(n-3)//2+1]
    for i in range((n-3)//2+2, n):
        ans1 -= 2 * l[i]

    for j in range((n-1)//2):
        ans2 += 2 * l[j]
    ans2 -= l[(n-1)//2] + l[(n-1)//2+1]
    for j in range((n-1)//2+2, n):
        ans2 -= 2 * l[j]

else:
    for i in range(((n-2)//2)):
        ans1 += 2 * l[i]
    ans1 += l[(n-2)//2]
    ans1 -= l[(n-2)//2+1]
    for i in range((n-2)//2+2, n):
        ans1 -= 2 * l[i]

ans = max(ans1, ans2)
print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
l = []
ans = 0
for i in range(n):
    l.append(int(input()))
m = sum(l) / n
large_l = []
small_l = []
for i in range(n):
    if l[i] > m:
        large_l.append(abs(l[i]-m))
    else:
        small_l.append(abs(l[i]-m))
large_l.sort()
small_l.sort()
if n % 2 == 1:
    if len(large_l) < len(small_l):
        ans += small_l[0] + small_l[1]
        for i in range(2, len(small_l)):
            ans += 2 * small_l[i]
        for i in range(len(large_l)):
            ans += 2 * large_l[i]
    else:
        ans += large_l[0] + large_l[1]
        for i in range(len(small_l)):
            ans += 2 * small_l[i]
        for i in range(2, len(large_l)):
            ans += 2 * large_l[i]
else:
    ans += large_l[0] + small_l[0]
    for i in range(1, len(small_l)):
        ans += 2 * small_l[i]
    for i in range(1, len(large_l)):
        ans += 2 * large_l[i]
print(int(ans))

Fixed submission:
n = int(input())
l = [0] * n
for i in range(n):
    l[i] = int(input())
l.sort(reverse=True)
ans1 = 0
ans2 = 0
if n % 2 == 1:
    for i in range((n-3)//2):
        ans1 += 2 * l[i]
    ans1 += l[(n-3)//2] + l[(n-3)//2+1]
    for i in range((n-3)//2+2, n):
        ans1 -= 2 * l[i]

    for j in range((n-1)//2):
        ans2 += 2 * l[j]
    ans2 -= l[(n-1)//2] + l[(n-1)//2+1]
    for j in range((n-1)//2+2, n):
        ans2 -= 2 * l[j]

else:
    for i in range(((n-2)//2)):
        ans1 += 2 * l[i]
    ans1 += l[(n-2)//2]
    ans1 -= l[(n-2)//2+1]
    for i in range((n-2)//2+2, n):
        ans1 -= 2 * l[i]

ans = max(ans1, ans2)
print(ans)
Buggy python submission (verdict: Runtime Error):
import math


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


n, m = [int(_) for _ in input().split()]
s = input()
t = input()
a = lcm(n, m)
s_a = a // n
t_a = a // m
p = lcm(s_a, t_a)
result = True
for i in range(a//p):
    if s[(i*p)//s_a] != t[(i*p)//t_a]:
        result = False
if result:
    print(a)
else:
    print(-1)


Fixed submission:
import fractions


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


n, m = [int(_) for _ in input().split()]
s = input()
t = input()
a = lcm(n, m)
s_a = a // n
t_a = a // m
p = lcm(s_a, t_a)
result = True
for i in range(a//p):
    if s[(i*p)//s_a] != t[(i*p)//t_a]:
        result = False
if result:
    print(a)
else:
    print(-1)
Buggy python submission (verdict: Runtime Error):
import math


n = int(input())
a_i = [int(_) for _ in input().split()]

s = [0] * n
s[0] = 1
for i in range(n-1):
    s[i+1] += s[i] + 1.0 / (i+2)

ans = 0
m = 10**9 + 7
f = math.factorial(n)
for j in range(n):
    p = s[j] + s[n-j-1] - 1
    ans = (ans + p * f * a_i[j]) % m

print(round(ans))


Fixed submission:
n = int(input())
a_i = [int(_) for _ in input().split()]

mod = 1000000007
fact = 1
for i in range(n):
    fact = (fact * (i + 1)) % mod

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

ans = 0
for j in range(n):
    p = (s[j] + s[n-j-1] - fact) % mod
    ans += (p * a_i[j]) % mod
    ans = ans % mod

print(ans)

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


n = int(input())
l_a = [int(_) for _ in input().split()]

s_a = [0]*(n+1)
for i in range(1, n+1):
    s_a[i] = s_a[i-1] + l_a[i-1]

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

for i in range(n):
    l[1][i] = l_a[i]

for j in range(2, n+1):
    for i in range(n-j+1):
        for k in range(i, i+j):
            l[j][i] += (math.factorial(j-1) * (s_a[i+j] - s_a[i]) + \
                       math.factorial(j-1)/math.factorial(k-i) * l[k-i][i] + \
                       math.factorial(j-1)/math.factorial(i+j-1-k) * l[i+j-1-k][k+1]) % \
                       (10**9 + 7)
            l[j][i] = l[j][i] % (10**9 + 7)


print(int(l[n][0]))


Fixed submission:
n = int(input())
a_i = [int(_) for _ in input().split()]

mod = 1000000007
fact = 1
for i in range(n):
    fact = (fact * (i + 1)) % mod

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

ans = 0
for j in range(n):
    p = (s[j] + s[n-j-1] - fact) % mod
    ans += (p * a_i[j]) % mod
    ans = ans % mod

print(ans)
Buggy python submission (verdict: Runtime Error):
import sys


n = int(input())
l = [[int(i) for i in input().split()] for j in range(n)]


for i in range(0, 101):
    for j in range(0, 101):
        for k in range(n):
            c = 0
            dict = {}
            if l[k][2] != 0:
                h = l[k][2] + abs(i - l[k][0]) + abs(i - l[k][1])
                c += 1
                if h in dict:
                    dict[h] += 1
                else:
                    dict[h] = 1
        if dict[h] == c:
            print(i, j, k)
            sys.exit()

Fixed submission:
import sys


n = int(input())
l = [[int(i) for i in input().split()] for j in range(n)]


for i in range(0, 101):
    for j in range(0, 101):
        ans = 1
        for k in range(n):
            if l[k][2] != 0:
                h = l[k][2] + abs(i - l[k][0]) + abs(j - l[k][1])
                break
        for k in range(n):
            if l[k][2] != max(h - abs(i - l[k][0]) - abs(j - l[k][1]), 0):
                ans = 0
        if ans:
            print(i, j, h)
            sys.exit()
Buggy python submission (verdict: Runtime Error):
import math
from functools import reduce


def gcd_list(numbers):
    return reduce(math.gcd, numbers)


n, x = [int(_) for _ in input().split()]
x_list = [int(_) for _ in input().split()]

list = [abs(x_list[i] - x) for i in range(n)]

answer = gcd_list(list)
print(answer)


Fixed submission:
from fractions import gcd
from functools import reduce


def gcd_list(numbers):
    return reduce(gcd, numbers)


n, x = [int(_) for _ in input().split()]
x_list = [int(_) for _ in input().split()]

list = [abs(x_list[i] - x) for i in range(n)]

answer = gcd_list(list)
print(answer)
Buggy python submission (verdict: Runtime Error):
import sys

N, K = [int(_) for _ in input().split()]
list = [int(_) for _ in input().split()]

l1 = []
l2 = []
t = 0
for i in list:
    if i < 0:
        l1.append(i)
    elif i == 0:
        t = 1
    else:
        l2.append(i)
l1 = [abs(_) for _ in l1]
l1.sort()

if t == 1 and K == 1:
    print(0)
    sys.exit()

K = K - t
a = float('inf')
b = float('inf')
if len(l1) >= K:
    a = l1[K-1]
if len(l2) >= K:
    b = l2[K-1]

c = float('inf')
d = float('inf')
for i in range(len(l2)):
    if K-i-2 >= 0:
        c_new = l2[i] * 2 + l1[K-i-2]
        c = min(c, c_new)
for j in range(len(l1)):
    if K-j-2 >= 0:
        d_new = l1[j] * 2 + l2[K-j-2]
        d = min(d, d_new)

print(min(a, b, c, d))



Fixed submission:
import sys

N, K = [int(_) for _ in input().split()]
list = [int(_) for _ in input().split()]

l1 = []
l2 = []
t = 0
for i in list:
    if i < 0:
        l1.append(i)
    elif i == 0:
        t = 1
    else:
        l2.append(i)
l1 = [abs(_) for _ in l1]
l1.sort()

if t == 1 and K == 1:
    print(0)
    sys.exit()

K = K - t
a = float('inf')
b = float('inf')
if len(l1) >= K:
    a = l1[K-1]
if len(l2) >= K:
    b = l2[K-1]

c = float('inf')
d = float('inf')
for i in range(len(l2)):
    if len(l1)-1 >= K-i-2 >= 0:
        c_new = l2[i] * 2 + l1[K-i-2]
        c = min(c, c_new)
for j in range(len(l1)):
    if len(l2)-1 >= K-j-2 >= 0:
        d_new = l1[j] * 2 + l2[K-j-2]
        d = min(d, d_new)

print(min(a, b, c, d))
Buggy python submission (verdict: Runtime Error):
import sys

N = float(input())
t = 3
prime_number = []
while t <= N / 15.0:
    l = []
    for i in range(t+1):
        if i != 0:
            if t % i == 0:
                l.append(i)
    if l == [1, t]:
        prime_number.append(t)
    t += 1
n = len(prime_number)
ans = 0
if n < 3:
    print(0)
    sys.exit()
else:
    for i in prime_number:
        for j in prime_number:
            if j != i:
                for k in prime_number:
                    if k != i and k != j:
                        if i * j * k <= N:
                            ans += 1
ans = ans / 6
if N >= 189:
    ans += 2
elif N >= 135:
    ans += 1
print(int(ans))

Fixed submission:
a, b = [int(_) for _ in input().split()]
ans = (a - 1) * (b - 1)
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys


S = [int(_) for _ in list(input())]
K = int(input())
t = 0
while t <= len(S):
    if S[t] == 1:
        t += 1
    else:
        break

if K <= t:
    print(1)
    sys.exit()
else:
    print(S[t])
    sys.exit()


Fixed submission:
import sys


S = [int(_) for _ in list(input())]
K = int(input())
t = 0
while t <= len(S) - 1:
    if S[t] == 1:
        t += 1
    else:
        break

if K <= t:
    print(1)
    sys.exit()
else:
    print(S[t])
    sys.exit()
Buggy python submission (verdict: Time Limit Exceeded):
n, m = [int(_) for _ in input().split()]
a = [int(_) for _ in input().split()]

t = 0
s = [0 for _ in range(n+1)]
for i in range(n):
    s[i+1] = (a[i] + t) % m
    t += a[i] % m

counter = 0
for i in range(0, n+1):
    for j in range(i+1, n+1):
        if s[i] == s[j]:
            counter += 1
print(counter)

Fixed submission:
def main():
    n, m = [int(_) for _ in input().split()]
    A = [int(_) for _ in input().split()]

    ans = 0
    d = {}

    cumsum = [0]
    c_sum = 0
    for a in A:
        c_sum = (c_sum + a) % m
        cumsum.append(c_sum)

    for c in cumsum:
        if c not in d.keys():
            d[c] = 0
        d[c] += 1

    for v in d.values():
        if v >= 2:
            ans += v * (v - 1) // 2

    print(ans)


main()

Buggy python submission (verdict: Time Limit Exceeded):
n, m = [int(_) for _ in input().split()]
a = [int(_) for _ in input().split()]

t = 0
s = [0 for _ in range(len(a)+1)]
for i in range(len(a)):
    s[i+1] = a[i] + t
    t += a[i]

counter = 0
for i in range(1, len(s)+1):
    for j in range(n-i+1):
        if (s[j+i] - s[j]) % m == 0:
            counter += 1

print(counter)


Fixed submission:
def main():
    n, m = [int(_) for _ in input().split()]
    A = [int(_) for _ in input().split()]

    ans = 0
    d = {}

    cumsum = [0]
    c_sum = 0
    for a in A:
        c_sum = (c_sum + a) % m
        cumsum.append(c_sum)

    for c in cumsum:
        if c not in d.keys():
            d[c] = 0
        d[c] += 1

    for v in d.values():
        if v >= 2:
            ans += v * (v - 1) // 2

    print(ans)


main()
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = len(s)
s = s + ' '
k = int(input())
l = []
for i in range(1, n+1):
    for j in range(n-i+1):
        l.append(s[j:j+i])
ans = sorted(list(set(l)))[k-1]
print(ans)

Fixed submission:
s = input()
n = len(s)
s = s + ' '
k = int(input())
l = []
for i in range(1, k+1):
    for j in range(n - i + 1):
        l.append(s[j:j + i])
ans = sorted(list(set(l)))[k - 1]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin


def main():
    _in = [_.rstrip() for _ in stdin.readlines()]
    N, X, M = list(map(int, _in[0].split(' ')))  # type:list(int)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    ans = 0
    A = X
    for i in range(N):
        ans += A
        A = pow(A, 2, M)
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
from sys import stdin


def main():
    _in = [_.rstrip() for _ in stdin.readlines()]
    N, X, M = list(map(int, _in[0].split(' ')))  # type:list(int)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    ans = 0
    A = X
    head_list = []
    head = set()
    repeat = set()
    for i in range(N):
        if A in head:
            ind = head_list.index(A)
            repeat = head_list[ind:]
            head = head_list[:ind]
            break
        else:
            head.add(A)
            head_list.append(A)
            A = pow(A, 2, M)

    if len(repeat) == 0:
        ans = sum(head)
    else:
        repeat_time = (N - len(head)) // len(repeat)
        tail_len = N - len(head) - repeat_time * len(repeat)
        ans = sum(head) + sum(repeat) * repeat_time + sum(repeat[:tail_len])
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
import re
from itertools import combinations


def main():
    _in = [_.rstrip() for _ in stdin.readlines()]
    S = _in[0]  # type:str
    T = _in[1]  # type:str
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    ans = 0
    if T in S:
        ans = 0
    else:
        for i in range(len(T)):
            ans = i + 1
            index = [j for j in range(len(T))]
            comb = list(combinations(index, i+1))

            for _comb in comb:
                t = list(T)
                for _i in _comb:
                    t[_i] = r'(\w)'
                t = r''.join(t)
                if re.search(t, S):
                    break
            else:
                continue
            break
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
from sys import stdin


def main():
    _in = [_.rstrip() for _ in stdin.readlines()]
    S = _in[0]  # type:str
    T = _in[1]  # type:str
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    ans = float('inf')
    S_ = list(S)
    T_ = list(T)

    for i in range(len(S_)-len(T_)+1):
        s_ = S_[i:i+len(T_)]
        cnt = 0
        for a,b in zip(s_, T_):
            if a == b:
                pass
            else:
                cnt += 1
        ans = min(ans, cnt)
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
from sys import stdin


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    H, W = list(map(int,_in[0].split(' ')))  # type:list(int)
    s_arr = []
    for i in range(H):
        _ = [_ for _ in _in[i+1]]   # type:list(str)
        s_arr.append(_)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    s_arr = list(zip(*s_arr))
    TF = 'Yes'
    for i in range(H):
        if TF == 'Yes':
            for j in range(W):
                if s_arr[i][j] == '#':
                    adjacent = []
                    if i>1:   
                        if s_arr[i-1][j] == '#':
                            continue
                    if i<H-1: 
                        if s_arr[i+1][j] == '#':
                            continue
                    if j>1:   
                        if s_arr[i][j-1] == '#':
                            continue
                    if j<W-1: 
                        if s_arr[i][j+1] == '#':
                            continue
                    TF = 'No'
                    break
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(TF)


Fixed submission:
from sys import stdin


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    H, W = list(map(int,_in[0].split(' ')))  # type:list(int)
    s_arr = []
    for i in range(H):
        _ = [_ for _ in _in[i+1]]   # type:list(str)
        s_arr.append(_)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    TF = 'Yes'
    for i in range(H):
        if TF == 'Yes':
            for j in range(W):
                if s_arr[i][j] == '#':
                    adjacent = []
                    if i>0:   
                        if s_arr[i-1][j] == '#':
                            continue
                    if i<H-1: 
                        if s_arr[i+1][j] == '#':
                            continue
                    if j>0:   
                        if s_arr[i][j-1] == '#':
                            continue
                    if j<W-1: 
                        if s_arr[i][j+1] == '#':
                            continue
                    TF = 'No'
                    break
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(TF)