Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
def main():
    import sys
    input = sys.stdin.readline

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

    # num = N//B

    # score = 0
    # for x in range(1, N+1):
    #     tmp = int(A*x/B) - A*int(x/B)
    #     if score <= tmp:
    #         score = tmp
    # print(score)

    import numpy as np

    arr = np.arange(N)
    arr = np.modf(arr/B)[0]
    print(int(max(arr*A)))


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    import sys
    input = sys.stdin.readline

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

    x = min(B-1, N)
    print(int(A*x/B)-A*int(x/B))


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import sys
    input = sys.stdin.readline

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

    num = N//B

    score = 0
    for x in range(1, N+1):
        tmp = int(A*x/B) - A*int(x/B)
        if score <= tmp:
            score = tmp
    print(score)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    import sys
    input = sys.stdin.readline

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

    x = min(B-1, N)
    print(int(A*x/B)-A*int(x/B))


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    S = list(input())
    N = len(S)

    P = 2019
    num = [0] * P
    num[0] = 1
    now, ans = 0, 0
    _10 = 1
    for s in S[::-1]:
        now = (now + int(s)*_10) % P
        _10 *= 10
        ans += num[now]
        num[now] += 1
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    import sys

    S = list(input())
    N = len(S)

    # c = 0
    # for i in range(0, N-3):
    #     for j in range(i+4, N+1):
    #         num = int(''.join(S[i:j]))
    #         if num % 2019 == 0:
    #             c += 1
    #             print(num)
    # print(c)

    P = 2019
    num = [0] * P
    num[0] = 1
    now, ans = 0, 0
    _10 = 1
    for i in range(N-1, -1, -1):
        now = (now + int(S[i])*_10) % P
        _10 *= 10
        _10 %= P
        ans += num[now]
        num[now] += 1
    print(ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import sys
    # input = sys.stdin.readline

    S = list(input())

    N = len(S)

    c = 0
    for i in range(0, N-3):
        for j in range(i+4, N+1):
            num = int(''.join(S[i:j]))
            if num % 2019 == 0:
                c += 1
    print(c)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    import sys

    S = list(input())
    N = len(S)

    # c = 0
    # for i in range(0, N-3):
    #     for j in range(i+4, N+1):
    #         num = int(''.join(S[i:j]))
    #         if num % 2019 == 0:
    #             c += 1
    #             print(num)
    # print(c)

    P = 2019
    num = [0] * P
    num[0] = 1
    now, ans = 0, 0
    _10 = 1
    for i in range(N-1, -1, -1):
        now = (now + int(S[i])*_10) % P
        _10 *= 10
        _10 %= P
        ans += num[now]
        num[now] += 1
    print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    K = int(input())

    su = 0
    # for a in range(1, K+1):
    #     for b in range(1, a+1):
    #         for c in range(1, b+1):
    #             tmp = dgcd(a, b, c)
    #             if a == b and b == c:
    #                 pass
    #             elif a == b or b == c or a == c:
    #                 tmp *= 3
    #             else:
    #                 tmp *= 6
    #             su += tmp
    # print(su)
    for a in range(1, K+1):
        for b in range(1, K+1):
            for c in range(1, K+1):
                tmp = dgcd(a, b, c)

                su += tmp
    print(su)


def dgcd(a, b, c):
    return gcd(gcd(a, b), c)


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    K = int(input())

    su = 0
    for a in range(1, K+1):
        for b in range(1, a+1):
            for c in range(1, b+1):
                tmp = dgcd(a, b, c)
                if a == b and b == c:
                    tmp *= 1
                elif a == b or b == c or a == c:
                    tmp *= 3
                else:
                    tmp *= 6

                su += tmp
    print(su)


def dgcd(a, b, c):
    return gcd(gcd(a, b), c)


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def main():

    S = input().split()
    Q = int(input())

    # for _ in range(Q):
    #     q = input().split()
    #     if q[0] == '1':
    #         S.reverse()
    #     elif q[0] == '2':
    #         if q[1] == '1':
    #             tmp = [q[2]]
    #             tmp.extend(S)
    #             S = tmp
    #         elif q[1] == '2':
    #             S.append(q[2])
    # print("".join(S))
    q_list = []
    for _ in range(Q):
        q_list.append(input().split())

    for q in q_list:
        if q[0] == '1':
            S.reverse()
        elif q[0] == '2':
            if q[1] == '1':
                tmp = [q[2]]
                tmp.extend(S)
                S = tmp
            elif q[1] == '2':
                S.append(q[2])
    print("".join(S))


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    S = list(input())
    s = set(S)
    if len(s) == 1:
        print('No')
    else:
        print('Yes')


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def main():

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

    blue = ['b']*A
    red = ['r']*B
    l = []
    while len(l) <= N:
        l.extend(blue)
        l.extend(red)
    print(l[:N].count('b'))


if __name__ == '__main__':
    main()


Fixed submission:
def main():

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

    # blue = ['b']*A
    # red = ['r']*B
    # l = []
    # while len(l) <= N:
    #     l.extend(blue)
    #     l.extend(red)
    # print(l[:N].count('b'))

    # c = 0
    # len = 0
    # while len <= N-A:
    #     len += A+B
    #     c += A
    # c += N-len
    # print(c)

    loops = N // (A+B)
    c = A*loops
    c += min(A, N % (A+B))
    print(c)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def main():

    S = input().split()
    s = S
    Q = int(input())
    s_ind = 0

    q_list = [input().split() for _ in range(Q)]
    for q in q_list:
        if len(q) == 1:
            t = q[0]
        else:
            t, f, c = q

        if t == '1' or t == 1:
            front = S[:s_ind]
            end = S[s_ind+1:]
            s_ind = len(S)-s_ind
            end.append(s)
            end.extend(front)
            S = end
        else:
            if f == '1' or f == 1:
                S.insert(0, c)
                s_ind += 1
            else:
                S.append(c)

    print("".join(S))


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    from collections import deque
    S = deque(input())
    Q = int(input())

    q_list = [input().split() for _ in range(Q)]

    flag = False
    for q in q_list:
        if len(q) == 1:
            t = q[0]
        else:
            t, f, c = q

        if t == '1':
            flag = not flag
        else:
            if (f == '1') ^ flag:
                S.appendleft(c)
            else:
                S.append(c)
    prS(S, flag)
    # prS(S, flag)


def prS(S, flag):
    if flag:
        S.reverse()
    print("".join(S))
    if flag:
        S.reverse()


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def main():
  N,M =map(int, input().split())
  s,c=[],[]
  for i in range(M):
    si,ci = map(int, input().split())
    s.append(si)
    c.append(ci)
  
  res=[0]*N
  for si,ci in zip(s,c):
    if res[si-1]== 0:
      res[si-1]=str(ci)	
    elif res[si-1]!= str(ci):
      print(-1)
      exit()
  
  if res==['0']*N:
    print(-1)
    exit()
  su = int("".join(res))
  if su < 10**(N-1):
    print(-1)
    exit()
    
  print(int("".join(res)))
  
    
if __name__=="__main__":
  main()

Fixed submission:
# import numpy as np
def main():
  N,M =map(int, input().split())
  s,c=[],[]
  for i in range(M):
    si,ci = map(int, input().split())
    s.append(si)
    c.append(ci)
  
  res=['']*N
  for si,ci in zip(s,c):
    if res[si-1]== '':
      res[si-1]=str(ci)	
    elif res[si-1]!= str(ci):
      print(-1)
      exit()

  
  if res[0]=='0':
    if N==1:
      print(0)
      exit()
    else:
      print(-1)
      exit()
  elif res[0]=='':
    res[0]=str(1)
   
  for i in range(N):
    if res[i]=='':
      res[i]=str(0)
  if M==0 and N==1:
    print(0)
    exit()
  print(int("".join(res)))
  
    
if __name__=="__main__":
  main()

Buggy python submission (verdict: Runtime Error):
# import numpy as np
def main():
  N,M =map(int, input().split())
  s,c=[],[]
  for i in range(M):
    si,ci = map(int, input().split())
    s.append(si)
    c.append(ci)
  
  res=[0]*N
  for si,ci in zip(s,c):
    if res[si-1]== 0:
      res[si-1]=str(ci)	
    elif res[si-1]!= str(ci):
      print(-1)
      exit()
#  print(res)
      
#  for i in range(N):
#    if res[i] =='':
#      res[i]=str(0)
  
  if res==['0']*N:
    print(-1)
    exit()
  su = int("".join(res))
  if su < 10**(N-1):
    print(-1)
    exit()
    
  print(int("".join(res)))
  
    
if __name__=="__main__":
  main()

Fixed submission:
# import numpy as np
def main():
  N,M =map(int, input().split())
  s,c=[],[]
  for i in range(M):
    si,ci = map(int, input().split())
    s.append(si)
    c.append(ci)
  
  res=['']*N
  for si,ci in zip(s,c):
    if res[si-1]== '':
      res[si-1]=str(ci)	
    elif res[si-1]!= str(ci):
      print(-1)
      exit()

  
  if res[0]=='0':
    if N==1:
      print(0)
      exit()
    else:
      print(-1)
      exit()
  elif res[0]=='':
    res[0]=str(1)
   
  for i in range(N):
    if res[i]=='':
      res[i]=str(0)
  if M==0 and N==1:
    print(0)
    exit()
  print(int("".join(res)))
  
    
if __name__=="__main__":
  main()
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N = int(input())
ll=[]
ll = np.array(list(map(int, input().split())))

num =0
for i in range(N):
  if ll[:i+1].min() == ll[i]:
    num+=1
print(num)


Fixed submission:
import sys

N = int(input())
ll=[]
ll = list(map(int, input().split()))

num =0
mi = ll[0]
for i in range(N):
  a = ll[i]
  if mi >= a:
    mi = a
    num += 1

print(num)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
N = int(input())
ll=[]
ll = list(map(int, input().split()))

num =0
for i in range(N):
  l2 = ll[:i+1]
  if sorted(l2)[0] == ll[i]:
    num += 1
print(num)


Fixed submission:
import sys

N = int(input())
ll=[]
ll = list(map(int, input().split()))

num =0
mi = ll[0]
for i in range(N):
  a = ll[i]
  if mi >= a:
    mi = a
    num += 1

print(num)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
N = int(input())
ll=[]
ll = list(map(int, input().split()))

num =0
for i in range(N):
  for j in range(i):
    if ll[i] <= ll[j]:
      pass
    else:
      num += 1
      break

print(N-num)

Fixed submission:
import sys

N = int(input())
ll=[]
ll = list(map(int, input().split()))

num =0
mi = ll[0]
for i in range(N):
  a = ll[i]
  if mi >= a:
    mi = a
    num += 1

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

num=0

li = [i+1 for i in range(N)]

l4 = list(map(lambda x: str(x)[0]+str(x)[-1], li))
l5 = list(map(lambda x: str(x)[-1]+str(x)[0], li))

for l in l4:
  num += l5.count(l)
print(num)

Fixed submission:
import collections
N = int(input())

num=0

li = [i+1 for i in range(N)]

l4 = list(map(lambda x: str(x)[0]+str(x)[-1], li))
ll = set(l4)
l5 = list(map(lambda x: str(x)[-1]+str(x)[0], li))
c4 = collections.Counter(l4)
c5 = collections.Counter(l5)

for l in ll:
  num += c4[l] * c5[l]
print(num)

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

num=0

for a in range(1,N+1):
  for b in range(1,N+1):
    if str(a)[0] == str(b)[-1] and str(a)[-1] == str(b)[0]:
      num +=1
print(num)
    


Fixed submission:
import collections
N = int(input())

num=0

li = [i+1 for i in range(N)]

l4 = list(map(lambda x: str(x)[0]+str(x)[-1], li))
ll = set(l4)
l5 = list(map(lambda x: str(x)[-1]+str(x)[0], li))
c4 = collections.Counter(l4)
c5 = collections.Counter(l5)

for l in ll:
  num += c4[l] * c5[l]
print(num)
Buggy python submission (verdict: Runtime Error):
from fractions import gcd

N = int(input())

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

def lcm(a):
  x = a[0]
  for i in range(1, len(a)):
    x = (x * a[i]) // gcd(x, a[i])
  return x

l = lcm(A)
num=0
for a in A:
  num += int(l/a)
print(int(num % (10**9 +7)))

Fixed submission:
from fractions import gcd

N = int(input())

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

l = A[0]
for a in A:
  l = (l * a) // gcd(l,a)
num=0
for a in A:
  num += l//a
print(num % (10**9 +7))

Buggy python submission (verdict: Runtime Error):
from fractions import gcd

N = int(input())

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

def lcm(a):
  x = a[0]
  for i in range(1, len(a)):
    x = (x * a[i]) // gcd(x, a[i])
  return x

l = lcm(A)
num=0
for a in A:
  num += l/a
print(int(num % (10**9 +7)))




Fixed submission:
from fractions import gcd

N = int(input())

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

l = A[0]
for a in A:
  l = (l * a) // gcd(l,a)
num=0
for a in A:
  num += l//a
print(num % (10**9 +7))

Buggy python submission (verdict: Runtime Error):
from fractions import gcd

N = int(input())

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

def lcm(a):
  x = a[0]
  for i in range(1, len(a)):
    x = (x * a[i]) // gcd(x, a[i])
  return x

l = lcm(A)
num=0
for a in A:
  num += l/a
print(int(num % (10e9 +7)))




Fixed submission:
from fractions import gcd

N = int(input())

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

l = A[0]
for a in A:
  l = (l * a) // gcd(l,a)
num=0
for a in A:
  num += l//a
print(num % (10**9 +7))

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

N = int(input())

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

def lcm(a):
  x = a[0]
  for i in range(1, len(a)):
    x = (x * a[i]) // fractions.gcd(x, a[i])
  return x

l = lcm(A)
num=0
for a in A:
  num += l/a
print(int(num % (10e9 +7)))




Fixed submission:
from fractions import gcd

N = int(input())

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

l = A[0]
for a in A:
  l = (l * a) // gcd(l,a)
num=0
for a in A:
  num += l//a
print(num % (10**9 +7))

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

N = int(input())

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

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

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

l = lcm(*A)
num=0
for a in A:
  num += l/a
print(int(num % (10e9 +7)))




Fixed submission:
from fractions import gcd

N = int(input())

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

l = A[0]
for a in A:
  l = (l * a) // gcd(l,a)
num=0
for a in A:
  num += l//a
print(num % (10**9 +7))
Buggy python submission (verdict: Runtime Error):
def main():
    import sys
    input = sys.stdin.readline
    import numpy as np

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

    p_max = M//np.min(A)
    X = np.zeros((p_max, N))
    # print(A)
    # print(X)
    # print(p_max)
    for p in range(p_max):
        X[p] = A*(p+0.5)

    ans = 0
    p_min = M//np.max(A)
    for p in range(p_min):
        x = np.max(A)*(p+0.5)
        if np.sum(x == X) == N:
            ans += 1

    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    import sys
    input = sys.stdin.readline
    from fractions import gcd

    N, M = map(int, input().split())
    A = list(set(map(lambda x: int(x)//2, input().split())))

    l = 1
    div2_count = count_div2(A[0])

    for a in A:
        l = l*a // gcd(l, a)
        c = count_div2(a)
        if div2_count != count_div2(a):
            print(0)
            exit()
    #     div2_count.append(max(count_div2(a), 1))
    # print(div2_count)
    # l *= min(div2_count)
    # print(l)
    # l の奇数倍が1より大きくM以下にいくつあるか

    print((M//l + 1)//2)


def count_div2(x):
    ans = 0
    while x % 2 == 0:
        x = x//2
        ans += 1
    return ans


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import sys
    input = sys.stdin.readline

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

    import itertools

    indices = [i for i in range(N)]
    for i in range(N):
        for v in itertools.combinations(indices, i):
            v = list(v)
            # print(v)
            tmp_l = get_l(A, v)
            # print(tmp_l)
            if judge(tmp_l):
                print(i)
                exit()
    print(-1)


def get_l(l, rm_ind):
    ans = []
    for i, a in enumerate(l):
        if i in rm_ind:
            continue
        ans.append(a)
    return ans


def judge(l):
    for i, a in enumerate(l):
        if i+1 != a:
            return False
    return True


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    import sys
    input = sys.stdin.readline

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

    import itertools

    ind = 1
    brick = 0
    for a in A:
        if a == ind:
            ind += 1
        else:
            brick += 1
    if brick == N:
        print(-1)
    else:
        print(brick)


#     indices = [i for i in range(N)]
#     for i in range(N):
#         for v in itertools.combinations(indices, i):
#             v = list(v)
#             # print(v)
#             tmp_l = get_l(A, v)
#             # print(tmp_l)
#             if judge(tmp_l):
#                 print(i)
#                 exit()
#     print(-1)


# def get_l(l, rm_ind):
#     ans = []
#     for i, a in enumerate(l):
#         if i in rm_ind:
#             continue
#         ans.append(a)
#     return ans


# def judge(l):
#     for i, a in enumerate(l):
#         if i+1 != a:
#             return False
#     return True


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import sys
    input = sys.stdin.readline

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

    inf = float("inf")
    dp = [inf]*N

    dp[0] = 0
    steps = [inf] * K

    for i in range(1, N):
        steps = [inf] * K
        for j in range(1, min(i, K) + 1):
            steps[j-1] = abs(H[i-j]-H[i]) + dp[i-j]
        step = min(steps)

        dp[i] = min(dp[i], step)
    print(dp[-1])


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    import sys
    input = sys.stdin.readline

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

    inf = float("inf")
    dp = [inf]*N

    dp[0] = 0
    steps = [inf] * K

    for i in range(1, N):
        steps = [inf] * K
        for j in range(1, min(i, K) + 1):
            steps[j-1] = abs(H[i-j]-H[i]) + dp[i-j]
        step = min(steps)

        dp[i] = min(dp[i], step)
    print(dp[-1])


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
if __name__ == "__main__":
    # 1 <= N <= 2 * 10^5
    # 1 <= K <= N + 1
    N, K = map(int, input().split(" "))

    total_num = 0
    for k in range(K, N+2):
        # NからN-(k-1)までの和
        sum_max = k*(2*N - k + 1) / 2
        # 0から(k-1)までの和
        sum_min = k*(k-1) / 2
        # 個数を計上
        total_num += sum_max - sum_min + 1
        total_num %= 1000000007
    
    print(total_num)

Fixed submission:
import math

if __name__ == "__main__":
    R = int(input())
    print(2*math.pi*R)
Buggy python submission (verdict: Time Limit Exceeded):
if __name__ == "__main__":
    N = int(input())
    As = list(map(int, input().split(" ")))

    bosses = []
    for n in range(1, N+1):
        bosses.append(As.count(n))
    
    print("\n".join(map(str, bosses)))

Fixed submission:
if __name__ == "__main__":
    N = int(input())
    As = list(map(int, input().split(" ")))

    bosses = [0]*N
    for a in As:
        bosses[a-1] = bosses[a-1] + 1
    
    print("\n".join(map(str, bosses)))
Buggy python submission (verdict: Time Limit Exceeded):
if __name__ == "__main__":
    N = int(input())
    S = input()

    # (1) Si≠Sj & Sj≠Sk & Sk≠Si ← すべて違う文字(RGBを網羅している)ということ
    # (2) j-i≠k-j ← 等間隔でないということ 

    R = []
    G = []
    B = []
    for idx, s in enumerate(S):
        if s == "R":
            R.append(idx)
        elif s == "G":
            G.append(idx)
        else:
            B.append(idx)
    
    total = 0
    for r in R:
        for g in G:
            for b in B:
                rgb = sorted([r, g, b])
                total += rgb[1] - rgb[0] != rgb[2] - rgb[1]
    
    print(total)

Fixed submission:
if __name__ == "__main__":
    N = int(input())
    S = input()

    # (1) Si≠Sj & Sj≠Sk & Sk≠Si ← すべて違う文字(RGBを網羅している)ということ
    # (2) j-i≠k-j ← 等間隔でないということ 

    R = 0
    G = 0
    B = 0
    for s in S:
        if s == "R":
            R += 1
        elif s == "G":
            G += 1
        else:
            B += 1    
    total = R*G*B

    # 条件に合わない件数をカウント
    for i in range(N-2):
        for j in range(i+1, N-1):
            # 文字の位置が等間隔の場合をチェック
            k = j + (j-i)
            # カウントしないケースは以下の通り
            # (1) チェック対象の3文字目の位置がNを超える
            # (2) 同じ文字が含まれる場合 ← すでに除外済み
            if k >= N or S[i] == S[j] or S[i] == S[k] or S[j] == S[k]:
                continue
            
            total -= 1
    
    print(total)
Buggy python submission (verdict: Time Limit Exceeded):
if __name__ == "__main__":
    N = int(input())
    nmin = 10**12
    maxI = max(2, N//2)
    for n in range(1, maxI):
        if N % n == 0:
            nmin = min(nmin, n + N//n - 2)

    print(nmin)

Fixed submission:
import math

if __name__ == "__main__":
    N = int(input())
    nsqrt = math.sqrt(N)
    for i in range(int(nsqrt), 0, -1):
        if N % i == 0:
            print(i + N//i - 2)
            exit()

Buggy python submission (verdict: Time Limit Exceeded):
if __name__ == "__main__":
    N = int(input())
    nmin = 10**12
    if N == 1:
        print(0)
        exit()
    for n in range(1, max(2, N//2)):
        if N % n == 0:
            nmin = min(nmin, n + N//n - 2)

    print(nmin)

Fixed submission:
import math

if __name__ == "__main__":
    N = int(input())
    nsqrt = math.sqrt(N)
    for i in range(int(nsqrt), 0, -1):
        if N % i == 0:
            print(i + N//i - 2)
            exit()

Buggy python submission (verdict: Time Limit Exceeded):
if __name__ == "__main__":
    N = int(input())
    nmin = 10**12
    if N == 1:
        print(0)
        exit()
    for n in range(1, N):
        r = N % n
        if r == 0:
            if n + N//n - 2 < nmin:
                nmin = n + N//n - 2

    print(nmin)

Fixed submission:
import math

if __name__ == "__main__":
    N = int(input())
    nsqrt = math.sqrt(N)
    for i in range(int(nsqrt), 0, -1):
        if N % i == 0:
            print(i + N//i - 2)
            exit()