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

Fixed submission:
import math
a = int(input())
print(math.ceil(a/2) / a)

Buggy submission (verdict: Runtime Error):
a = int(input())
print(math.ceil(a/2) / a)
Problem p02912 (python)

Fixed submission:
import heapq
import math

n, m = map(int, input().split())
A = list(map(lambda x: -x, map(int, input().split())))
heapq.heapify(A)
for _ in range(m):
    tmp = heapq.heappop(A)
    tmp = math.ceil(tmp / 2)
    heapq.heappush(A, tmp)
print(-sum(A))

Buggy submission (verdict: Runtime Error):
import numpy as np
n, m = map(int, input().split())
A = np.array(list((map(int, input().split()))))
for _ in range(m):
    A.sort()
    A[-1] = A[-1] // 2
print(sum(A))
Problem p02951 (python)

Fixed submission:
x = input().split(' ')
n = list(map(int, x))
ans = n[2] - (n[0]-n[1])
if ans > 0:
  print(ans)
else:
  print(0)

Buggy submission (verdict: Runtime Error):
x = input().split(' ')
a, b, c = x[0], x[1], x[2]
ans = c - (a-b)
if ans > 0:
  print(ans)
else:
  print(0)

Buggy submission (verdict: Runtime Error):
x = input().split(' ')
a, b, c = x[0], x[1], x[2]
ans = c - (a-b)
if ans > 0:
  print(ans)
else:
  print 0

Buggy submission (verdict: Runtime Error):
x = input().split(' ')
a, b, c = x[0], x[1], x[2]
ans = c - (a-b)
if c > 0:
  print(c)
else:
  print(0)

Buggy submission (verdict: Runtime Error):
x = input().split(' ')
a, b, c = x[0], x[1], x[2]
ans = c - (a-b)
if c > 0:
  print(c)
else:
  print 0
Problem p02987 (python)

Fixed submission:
import collections
s = input()
c = collections.Counter(s)

if [2,2] == [x for x in c.values()]:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):

s = input()
c = collections.Counter(s)

if [2,2] == [x for x in c.values()]:
  print('Yes')
else:
  print('No')
Problem p02935 (python)

Fixed submission:
import numpy as np
N=int(input())
v=np.sort(list(map(int, input().split())))
v1=[]
v1.append(v[0]/2**(N-1)) 
for i in range(N-1):
    v1.append(v[i+1]/2**((N-1)-i))
print(sum(v1))

Buggy submission (verdict: Runtime Error):
N=int(input())
v=np.sort(list(map(int, input().split())))
v1=[]
v1.append(v[0]/2**(N-1)) 
for i in range(N-1):
    v1.append(v[i+1]/2**((N-1)-i))
print(sum(v1))
Problem p03013 (python)

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

a_set=set()

for index in range(m):
    a_set.add(int(input()))

ans_list=[]

for index in range(n + 1):
    ans_list.append(0)

for index in range(n + 1):
    if index == 0:
        ans_list[index] += 1
        continue
    if index == 1 and (index not in a_set):
        ans_list[index] += ans_list[index - 1]
        continue
    
    if index not in a_set:
        if (index - 1) not in a_set:
            ans_list[index] += ans_list[index - 1]
            ans_list[index] %= 1000000007
        if (index - 2) not in a_set:
            ans_list[index] += ans_list[index - 2]
            ans_list[index] %= 1000000007

print(ans_list[n])

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

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

a_set=set()

for index in range(m):
    a_set.add(int(input()))

ans_list = []

ans_list = 0 * (n + 1)

for index in range(n + 1):
    if index == 0:
        ans_list[index] += 1
        continue
    if index == 1 and (index not in a_set):
        ans_list[index] += ans_list[index - 1]
        continue
    
    if index not in a_set:
        if (index - 1) not in a_set:
            ans_list[index] += ans_list[index - 1]
            ans_list[index] %= 1000000007
        if (index - 2) not in a_set:
            ans_list[index] += ans_list[index - 2]
            ans_list[index] %= 1000000007

print(ans_list[n])

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

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

a_set=set()

for index in range(m):
    a_set.add(int(input()))

ans_list=[0 * (n+1)]

for index in range(n + 1):
    if index == 0:
        ans_list[index] += 1
        continue
    if index == 1 and (index not in a_set):
        ans_list[index] += ans_list[index - 1]
        continue
    
    if index not in a_set:
        if (index - 1) not in a_set:
            ans_list[index] += ans_list[index - 1]
            ans_list[index] %= 1000000007
        if (index - 2) not in a_set:
            ans_list[index] += ans_list[index - 2]
            ans_list[index] %= 1000000007

print(ans_list[n])
Problem p02990 (python)

Fixed submission:
import math


N, K = map(int, input().split())
MOD = 10 ** 9 + 7

def comb(n, k):
    return math.factorial(n) // math.factorial(k) // math.factorial(n - k)

for i in range(1, K + 1):
    if i > N-K+1:
        print(0)
        continue
    blue = comb(N-K+1, i) % MOD
    red = comb(K-1, i-1) % MOD

    ans = blue * red % MOD
    print(ans)

Buggy submission (verdict: Runtime Error):
import math


N, K = map(int, input().split())
MOD = 10 ** 9 + 7

def comb(n, k):
    return math.factorial(n) // math.factorial(k) // math.factorial(n - k)

for i in range(1, K + 1):
    if i > N-K+1:
        print(0)
    blue = comb(N-K+1, i) % MOD
    red = comb(K-1, i-1) % MOD

    ans = blue * red % MOD
    print(ans)

Buggy submission (verdict: Runtime Error):
import math


N, K = map(int, input().split())
MOD = 10 ** 9 + 7

def comb(n, k):
    return math.factorial(n) // math.factorial(k) // math.factorial(n - k)

for i in range(1, K + 1):
    blue = comb(N-K+1, i) % MOD
    red = comb(K-1, i-1) % MOD

    ans = blue * red % MOD
    print(ans)

Buggy submission (verdict: Runtime Error):
from scipy.misc import comb

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

def f2(n, k):
    return int(comb(n+k-1, k - 1))

def f(n, k):
    if n < k:
        return 0
    if k < 1:
        return 0
    if n == 0 and k== 0:
        return 0
    return f2(n-k, k)



for i in range(1, K + 1):
    blue = f(K, i)
    red = 0
    red += f(N - K, i - 1)
    red += f(N - K, i)
    red += f(N - K, i)
    red += f(N - K, i+1)

    ans = blue * red
    print(ans)

Buggy submission (verdict: Runtime Error):
from scipy.special import comb

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

def f2(n, k):
    return int(comb(n+k-1, k - 1))

def f(n, k):
    if n < k:
        return 0
    if k < 1:
        return 0
    if n == 0 and k== 0:
        return 0
    return f2(n-k, k)



for i in range(1, K + 1):
    blue = f(K, i)
    red = 0
    red += f(N - K, i - 1)
    red += f(N - K, i)
    red += f(N - K, i)
    red += f(N - K, i+1)

    ans = blue * red
    print(ans)
Problem p03013 (python)

Fixed submission:
N, M = map(int, input().split())
A = [int(input()) for _ in range(M)]
A.append(-1)


MOD = 1000000007

dp = [0 for _ in range(N + 1)]

dp[0] = 1



next_ng_index = 0

for index in range(N):
    current = index + 1
    if current == A[next_ng_index]:
        next_ng_index += 1
        continue

    pre_stair = current - 1
    dp[current] += dp[pre_stair]

    prepre_stair = current -2
    if prepre_stair >= 0:
        dp[current] += dp[prepre_stair]

    dp[current] %= MOD

print(dp[-1]%MOD)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = [int(input()) for _ in range(M)]


MOD = 1000000007

dp = [0 for _ in range(N + 1)]

dp[0] = 1



next_ng_index = 0

for index in range(N):
    current = index + 1
    if current == A[next_ng_index]:
        next_ng_index += 1
        if next_ng_index == M:
            next_ng_index = 0
        continue

    pre_stair = current - 1
    dp[current] += dp[pre_stair]

    prepre_stair = current -2
    if prepre_stair >= 0:
        dp[current] += dp[prepre_stair]

    dp[current] %= MOD

print(dp[-1]%MOD)
Problem p03038 (python)

Fixed submission:
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int,input().split())) for _ in range(M)]

A.sort()
BC.sort(key=lambda x:x[1], reverse=True)

a_i = 0
is_fin = False
for b, c in BC:
    if is_fin:
        break

    for _ in range(b):
        if A[a_i] < c:
            A[a_i] = c 
            a_i += 1
            if a_i >= len(A):
                is_fin = True
                break
        else:
            is_fin = True
            break

print(sum(A))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int,input().split())) for _ in range(M)]

A.sort()
BC.sort(key=lambda x:x[1], reverse=True)

a_i = 0
is_fin = False
for b, c in BC:
    if is_fin:
        break

    for _ in range(b):
        if A[a_i] < c:
            A[a_i] = c 
            a_i += 1
        else:
            is_fin = True
            break

print(sum(A))
Problem p03208 (python)

Fixed submission:
N, K = map(int, input().split())
H = [int(input()) for _ in range(N)]

H.sort(reverse=True)

min_score = pow(10, 9)
for i in range(N - K + 1):
    min_score = min(min_score, H[i] - H[i + K - 1])

print(min_score)

Buggy submission (verdict: Runtime Error):
 N, K = map(int, input().split())
H = [int(input()) for _ in range(N)]

H.sort(reverse=True)

min_score = pow(10, 9)
for i in range(N - K + 1):
    min_score = min(min_score, H[i] - H[i + K - 1])

print(min_score)
Problem p03307 (python)

Fixed submission:
N = int(input())

if N % 2 == 0:
    print(N)
else:
    print(N * 2)

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

def sunuke(b):
    ret = 0
    sub = 1
    for a in A:
        ret += abs(a - (b+ sub))
        sub += 1
    return ret


B = []

sub = 1
for a in A:
    b = a - sub
    B.append(b)
    sub += 1

B.sort()
b1 = N // 2
if N < 3:
    print(sunuke(B[b1]))
    exit()

b2 = b1 + 1
b1_s = sunuke(B[b1])
b2_s = sunuke(B[b2])
if b1_s < b2_s:
    print(b1_s)
else:
    print(b2_s)
Problem p03332 (python)

Fixed submission:
import math

base = 998244353

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

fac = [1] * (n + 1)
rev = [1] * (n + 1)
for i in range(1, n + 1):
    fac[i] = fac[i - 1] * i % base
    rev[i] = pow(fac[i], base -2, base)



def comb(n,r):
    hoge = (fac[n] * rev[r] * rev[n - r] ) % base
    return hoge





count = 0

an = 0 

for an in range(n+1):
    if k - an * a < 0 or (k - an * a) % b != 0:
        continue
    bn = (k -an * a) // b
    if not 0 <= bn <= n:
        continue

    count += comb(n, an) * comb(n, bn) % base
    count %= base



print(count)

Buggy submission (verdict: Runtime Error):
import math

base = 998244353

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

fac = [1] * (n + 1)
rev = [1] * (n + 1)
for i in range(1, n + 1):
    fac[i] = fac[i - 1] * i % base
    rev[i] = pow(fac[i], base -2, base)



def comb(n,r):
    hoge = (fac[n] * rev[r] * rev[n - r] ) % base
    return hoge





count = 0

an = 0 

for an in range(n+1):
    if k - an * a < 0 or (k - an * a) % b != 0:
        continue
    bn = (k -an * a) // b

    count += comb(n, an) * comb(n, bn) % base
    count %= base



print(count)

Buggy submission (verdict: Runtime Error):
import math

base = 998244353

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

fac = [1] * (n + 1)
rev = [1] * (n + 1)
for i in range(1, n + 1):
    fac[i] = fac[i - 1] * i % base
    rev[i] = pow(fac[i], base -2, base)



def comb(n,r):
    hoge = (fac[n] * rev[r] * rev[n - r] ) % base
    return hoge





count = 0

an = 0 

while an <= n:
    if (k - an * a) % b != 0:
        an += 1
        continue
    bn = (k -an * a) // b

    count += comb(n, an) * comb(n, bn) % base
    count %= base

    an += 1


print(count)
Problem p02881 (python)

Fixed submission:
import math
N = int(input())
s = int(math.sqrt(N))

for p in reversed(range(1, s + 1)):
#     print(p)
    if N % p == 0:
        p, q = p, N // p
        print(p + q - 2)
        break

Buggy submission (verdict: Runtime Error):
import math
N = int(input())
p = int(math.sqrt(N))

def search(N, p):
#     print(p, N % p)
    if N % p == 0:
        q = int(N / p)
        return p, q
    else:
        if p * N // p > N:
            p, q = search(N, p - 1)
        else:
            p, q = search(N, p + 1)
    
    return p, q

p, q  = search(N, p)
print(p + q - 2)
Problem p03835 (python)

Fixed submission:
k, s = (int(x) for x in 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 submission (verdict: Runtime Error):
S = map(int, input().split())
 
cnt = 0
for x in range(K + 1):
    for y in range(K + 1):
        if 0 <= S - x - y <= K:
            cnt += 1
print(cnt)

Buggy submission (verdict: Runtime Error):
S = map(int, input().split())
 
cnt = 0
for x in range(K + 1):
    for y in range(K + 1):
        if 0 <= S - x - y <= K:
            cnt += 1
print(cnt)
Problem p02912 (python)

Fixed submission:
import heapq

n, m = map(int, input().split())
lis = []

for i in input().split():
  heapq.heappush(lis, -int(i))

for j in range(m):
  tmp = -heapq.heappop(lis)
  heapq.heappush(lis, -int((tmp/2)))

print(-sum(lis))

Buggy submission (verdict: Runtime Error):
import bisect
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
for i in range(m):
  t=a[-1]//2
  if t<a[-2]:
    bisect.insort(a,t)
    del a[-1]
  else:
    continue

print(sum(a))

Buggy submission (verdict: Runtime Error):
import collections
n, k, q = map(int, input().split())
A = [int(input()) for _ in range(q)]
a_c = collections.Counter(A)
cnt = 0
x = ['No'] * n
if q-k < 0:
	for a in range(n):
		print('Yes')
	exit()
for i,j in a_c.items():
  if j > q-k:
    x[i-1] = 'Yes'
for k in x:
	print(k)
Problem p02970 (python)

Fixed submission:
n, d = map(int, input().split())
t = 2*d+1
print(n//t+1 if n%t else n//t)

Buggy submission (verdict: Runtime Error):
N, D = map(input())
A = (2D+1)//N
if A == 0:
  print(A)
elif A == 1:
  print(A+1)
Problem p03045 (python)

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

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

class UnionFind():
    def __init__(self, N):
        self.nodes = [i for i in range(N)]

    def root(self, x):
        if self.nodes[x] != x:
            self.nodes[x] = self.root(self.nodes[x])
        return self.nodes[x]

    def same(self, x, y):
        return self.root(x) == self.root(y)

    def unite(self, x, y):
        if self.same(x, y):
            return
        self.nodes[self.root(x)] = self.root(y)

uf = UnionFind(N)

for _ in range(M):
    x, y, z = map(int, input().split())
    uf.unite(x-1, y-1)

group = set()
for node in uf.nodes:
    group.add(uf.root(node))

print(len(group))

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

class UnionFind():
    def __init__(self, N):
        self.nodes = [i for i in range(N)]

    def root(self, x):
        if self.nodes[x] != x:
            self.nodes[x] = self.root(self.nodes[x])
        return self.nodes[x]

    def same(self, x, y):
        return self.root(x) == self.root(y)

    def unite(self, x, y):
        if self.same(x, y):
            return
        self.nodes[self.root(x)] = self.root(y)

uf = UnionFind(N)
anti_list = [[] for _ in range(N)]

for _ in range(M):
    x, y, z = map(int, input().split())
    uf.unite(x-1, y-1)

group = set()
for node in uf.nodes:
    group.add(uf.root(node))

print(len(group))
Problem p02881 (python)

Fixed submission:
N = int(input())

c = 10**100

for a in range(2, int(N**0.5)+1):
    if N % a == 0:
        b = N / a
        if (a-1)+(b-1) < c:
            c = (a-1)+(b-1)
        
print(min((N-1), int(c)))

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

lst = []
flag = False

for a in range(1, (N+1)//2):
    if N % a == 0:
        b = N / a       
        lst.append((a-1)+(b-1))
                
print(int(min(lst)))
Problem p02933 (python)

Fixed submission:
a = int(input())
s = input()
print(s) if a >= 3200 else print("red")

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

N, Q = map(int, input().split())
tree = [[] for _ in range(N+1)]
value = [0] * (N+1)
visit = [False] * (N+1)

# make_tree
for _ in range(N-1):
    a, b = map(int, input().split())
    tree[a].append(b)
    tree[b].append(a)

# make_value
for _ in range(Q):
    p, x = map(int, input().split())
    value[p] += x

# all_value_sum
q = queue.Queue()
q.put(1)
visit[1] = True
while not q.empty():
    now = q.get()
    for next in tree[now]:
        if not visit[next]:
            value[next] += value[now]
            q.put(next)
            visit[next] = True

# output_value
s = " ".join(map(str, value[1:]))
print(s)
Problem p02951 (python)

Fixed submission:
s = list(map(int, input().split()))
a = s[0]
b = s[1]
c = s[2]

def restWater():
    restWater = c - (a - b)
    if restWater >= 0:
        print(restWater)
    else:
        print(0)

restWater()

Buggy submission (verdict: Runtime Error):
import sys
args = sys.argv
a = int(args[1])
b = int(args[2])
c = int(args[3])

def restWater():
    restWater = c - (a - b)
    if restWater >= 0:
        print(restWater)
    else:
        print(0)

restWater()
Problem p03250 (python)

Fixed submission:
A, B, C = map(int, input().split())
if max(A, B, C) == A:
    print(10*A + B + C)
elif max(A, B, C) == B:
    print(10*B + A + C)
else:
    print(10*C + B + A)

Buggy submission (verdict: Runtime Error):
N, M, X, Y = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
x.append(X)
y.append(Y)
if max(x) < min(y):
    print('No War')
else:
    print('War')
Problem p03804 (python)

Fixed submission:
N, M = map(int, input().split())
A = [list(input()) for _ in range(N)]
B = [list(input()) for _ in range(M)]
for i in range(N-M+1):
    for j in range(N-M+1):
        flg = True
        for k in range(M):
            for l in range(M):
                if A[i+k][j+l]!=B[k][l]:
                    flg = False    
        if flg == True:
            print('Yes')
            exit()             
print('No')

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]
for i in range(N-M+1):
    for j in range(N-M+1):
        cnt = 0
        for k in range(i,i+M): # yoko
            for l in range(j,j+M): # tate
                if A[k][l]!=B[k][l]:
                    break
                else:
                    cnt+=1
        if cnt == M*M:
            print('Yes')
            exit()             
print('No')
Problem p03012 (python)

Fixed submission:
N=int(input())
W=list(map(int,input().split()))
sum_W=sum(W)
half_W=sum_W/2
a=sum_W
b=0
for i in range(N):
  a-=W[i]
  b+=W[i]
  if a<=half_W:
    print(min(abs(a-b),abs(a-b+2*W[i])))
    break

Buggy submission (verdict: Runtime Error):
N=int(input())
W=list(map(int,input().split()))
sum_W=sum(W)
half_W=sum_W/2
tmp=sum_W
for i in range(N):
  tmp-=W[i]
  if tmp<half_W:
    print(min(abs(sum_W-2*tmp),abs(sum_W-2*tmp+W[i])))
    break
  elif tmp=half_W:
    print(0)
    break
Problem p03724 (python)

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

l = [0 for i in range(N)]

for i in range(M):
	a,b = map(int,input().split())
	l[a-1] += 1
	l[b-1] += 1

for i in l:
	if i%2 == 1:
		print("NO")
		break
else:
	print("YES")

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

l = [0 for i in range(N)]
ad = [[] for i in range(N)]
de1 = [0 for i in range(N)]

for i in range(N-1):
	a,b = map(int,input().split())
	l[a-1] += 1
	l[b-1] += 1
	ad[a-1].append(b-1)
	ad[b-1].append(a-1)

for i in range(N):
	if l[i] == 1:
		de1[ad[i][0]] += 1

for i in range(N):
	if de1[i] >= 2:
		print("First")
		break
else:
	print("Second")
Problem p03745 (python)

Fixed submission:
N = int(input())
a = list(map(int, input().split(" ")))


l = [[] for i in range(N)]
c = 0

s = 0
t = a[0]

for i in a[1:]:
	if t > i:
		l[s].append((c))
		s = c+1
	c += 1
	t = i
else:
	l[s].append((c))

c = 0

s = 0
t = a[0]

for i in a[1:]:
	if t < i:
		l[s].append((c))
		s = c+1
	c += 1
	t = i
else:
	l[s].append((c))

l[0] = max(l[0])
for i in range(1,N):
	l[i].append(-1)
for i in range(1,N):
	
	if i!=N-1:
		l[i+1].append(-1)
		l[i] = max(l[i-1],max(l[i]),max(l[i+1]))
	else:
		l[i] = max(l[i-1],max(l[i]))


now = 0
res = 0

while now<N-1:
	now = l[now]	
	res+=1
if N==1:
	print(1)
	exit()
print(res)

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


l = [[] for i in range(N)]
c = 0

s = 0
t = a[0]

for i in a[1:]:
	if t > i:
		l[s].append((c))
		s = c+1
	c += 1
	t = i
else:
	l[s].append((c))

c = 0

s = 0
t = a[0]

for i in a[1:]:
	if t < i:
		l[s].append((c))
		s = c+1
	c += 1
	t = i
else:
	l[s].append((c))

l[0] = max(l[0])
for i in range(1,N):
	if i!=N-1:
		l[i+1].append(-1)
		l[i] = max(l[i-1],max(l[i]),max(l[i+1]))
	else:
		l[i] = max(l[i-1],max(l[i]))


now = 0
res = 0

while now<N-1:
	now = l[now]	
	res+=1

print(res)
Problem p02881 (python)

Fixed submission:
import math

def main():
    Input = [input() for i in range(1)]
    N = int(Input[0])
    x = math.sqrt(N)
    if x.is_integer():
        print(int(x+N/x-2))
    else:
        while x >= 1:
            x = math.ceil(x)-1
            y = N/x
            if y.is_integer():
                print(int(x+y-2))
                break

        
        
if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import math

    
def main():
    Input = [input() for i in range(1)]
    N = int(Input[0])
    x = math.sqrt(N)
    if x.is_integer():
        print(int(x+N/x-2))
    else:
        while x >= 1:
            x = math.floor(x)-1
            y = N/x
            if y.is_integer():
                print(int(x+y-2))
                break

        
        
if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import math

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

def main1():
    Input = [input() for i in range(1)]
    N = int(Input[0])
    fact = factorization(N)
    ff = []
    for fn in fact:
        for i in range(fn[1]):
            ff.append(fn[0])
    ans = 10000000000000
    fN = len(ff)
    for wake in range(2**(fN-1)):
        wake2 = format(wake, '0'+str(fN-1)+'b')
        A = ff[-1]
        for i in range(fN-1):
            if wake2[i] == '1':
                 A = A*ff[i]   
        B = N / A
        if A + B - 2 < ans:
            ans = int(A+B-2)
    print(ans)
    
def main1():
    Input = [input() for i in range(1)]
    N = int(Input[0])
    x = math.sqrt(N)
    if x.is_integer():
        print(int(x+N/x-2))
    else:
        while x >= 1:
            x = math.floor(x)-1
            y = N/x
            if y.is_integer():
                print(int(x+y-2))
                break

        
        
if __name__ == "__main__":
    main1()
Problem p02891 (python)

Fixed submission:
##################################################################

if __name__ == "__main__":
    Input = [input() for i in range(2)]
    # = list(map(int,Input[0].split()))
    S = str(Input[0])
    K = int(Input[1])

    n = len(S)
    ren = 1
    bef = S[0]
    cont = []
    if n == 1:
        cont = [1]
    for s in range(1,n):
        if bef == S[s]:
            ren += 1
            bef = S[s]
            if s == n-1:
                cont.append(ren)                
        else:
            cont.append(ren)
            ren = 1
            bef = S[s]

    ans = (sum([c//2 for c in cont]))*K
    if n ==1:
        ans += K//2
    elif S[0] == S[-1]:
        if len(cont)>1 and cont[0]%2==1 and cont[-1]%2==1:
            ans += K-1
        elif len(cont) ==1:
            ans = (n*K)//2
    print(ans)

Buggy submission (verdict: Runtime Error):
##################################################################

if __name__ == "__main__":
    Input = [input() for i in range(2)]
    # = list(map(int,Input[0].split()))
    S = str(Input[0])
    K = int(Input[1])

    n = len(S)
    ren = 1
    bef = S[0]
    cont = []
    for s in range(1,n):
        if bef == S[s]:
            ren += 1
            bef = S[s]
            if s == n-1:
                cont.append(ren)                
        else:
            cont.append(ren)
            ren = 1
            bef = S[s]

    ans = (sum([c//2 for c in cont]))*K
    if S[0] == S[-1]:
        if cont[0]%2==1 and cont[-1]%2==1:
            ans += K-1
    print(ans)