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

Fixed submission:
n, m = map(int, input().split())
mod = 10 ** 9 + 7
pat = [0] * (n + 2)
pat[0] = 1
pat[1] = 1

for i in range(m):
    a = int(input())
    pat[a] = -1

for i in range(2, n + 1):
    if pat[i] < 0:
        continue
    if pat[i - 1] > 0:
        pat[i] = (pat[i] + pat[i - 1]) % mod
    if pat[i - 2] > 0:
        pat[i] = (pat[i] + pat[i - 2]) % mod

print(pat[n])

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
mod = 10 ** 9 + 7
pat = [0] * (n + 1)
pat[0] = 1
pat[1] = 1
for i in range(m):
    pat[i] = -1

pat = [1]
for i in range(2, n + 1):
    if pat[i] < 0:
        continue
    if pat[i - 1] > 0:
        pat[i] = (pat[i] + pat[i - 1]) % mod
    if pat[i - 2] > 0:
        pat[i] = (pat[i] + pat[i - 2]) % mod

print(pat[n])

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
mod = 10 ** 9 + 7
a = []
pat = [0] * (n + 1)
pat[0] = 1
pat[1] = 1
for i in range(m):
    a.append(int(input()))
    pat[a] = -1

pat = [1]
for i in range(2, n + 1):
    if pat[i] < 0:
        continue
    if pat[i - 1] > 0:
        pat[i] = (pat[i] + pat[i - 1]) % mod
    if pat[i - 2] > 0:
        pat[i] = (pat[i] + pat[i - 2]) % mod

print(pat[n])

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
mod = 10 ** 9 + 7
a = []
for i in range(m):
    a.append(int(input()))

dp = [-1] * (n + 1)


def dfs(step):
    if dp[step] >= 0:
        return dp[step]
    if step - 1 in a and step - 2 in a:
        return 0
    cnt = 0
    if step <= 0:
        return 1
    if step - 1 >= 0 and step - 1 not in a:
        cnt = (cnt + dfs(step - 1)) % mod
    if step - 2 >= 0 and step - 2 not in a:
        cnt = (cnt + dfs(step - 2)) % mod
    dp[step] = cnt
    return dp[step]


print(dfs(n))

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
mod = 10 ** 9 + 7
a = []
for i in range(m):
    a.append(int(input()))

dp = [-1] * (n + 1)


def dfs(step):
    if dp[step] >= 0:
        return dp[step]
    if step - 1 in a and step - 2 in a:
        return 0
    cnt = 0
    if step <= 0:
        return 1
    if step - 1 >= 0 and step - 1 not in a:
        cnt += dfs(step - 1)
    if step - 2 >= 0 and step - 2 not in a:
        cnt += dfs(step - 2)
    dp[step] = cnt
    return cnt % mod


print(dfs(n))
Problem p03017 (python)

Fixed submission:
# -*- coding: utf-8 -*-
n, a, b, c, d = map(int, input().split())
s = input()
grid = []
for rock in s:
    grid.append(rock == '#')

if grid[c-1] or grid[d-1]:
    print('No')

max_rock_count = 0
rock_count = 0
if c < d:
    for i in range(a-1, d):
        if grid[i]:
            rock_count += 1
        else:
            rock_count = 0

        max_rock_count = max(max_rock_count, rock_count)

    if max_rock_count >= 2:
        print('No')
    else:
        print('Yes')
elif c > d:
    max_rock_count = 0
    rock_count = 0
    canSkip = False
    for i in range(a-1, c):
        if grid[i]:
            rock_count += 1
        else:
            if b - 1 <= i and i <= c - 2 and not grid[i-1] and not grid[i] and not grid[i+1]:
                if i-1 != d - 1:
                    canSkip = True
            rock_count = 0

        max_rock_count = max(max_rock_count, rock_count)

    if max_rock_count <= 1 and canSkip:
        print('Yes')
    else:
        print('No')

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
n, a, b, c, d = map(int, input().split())
s = input()
grid = []
for rock in s:
    grid.append(rock == '#')

if grid[c-1] or grid[d-1]:
    print('No')

max_none_count = 0
max_rock_count = 0
none_count = 0
rock_count = 0
if c < d:
    for i in range(a-1, d):
        if grid[i]:
            none_count = 0
            rock_count += 1
        else:
            rock_count = 0

        max_none_count = max(max_none_count, none_count)
        max_rock_count = max(max_rock_count, rock_count)

    if max_rock_count >= 2:
        print('No')
    else:
        print('Yes')
elif c > d:
    max_rock_count = 0
    rock_count = 0
    # Dの位置は岩として考える
    grid[d-1] = True
    canSkip = False
    for i in range(a-1, c):
        if grid[i]:
            rock_count += 1
        else:
            if b - 1 <= i and c - 2 <= i and not grid[i-1] and not grid[i] and not grid[i+1]:
                canSkip = True
            rock_count = 0

        max_rock_count = max(max_rock_count, rock_count)

    if max_rock_count <= 1 and canSkip:
        print('Yes')
    else:
        print('No')
Problem p03018 (python)

Fixed submission:
# -*- coding: utf-8 -*-
s = input()

a_num = 0
bc_num = 0
ans = 0
i = 0
while i < len(s):
    if s[i] == 'A':
        a_num += 1
        i += 1
    elif s[i:i+2] == 'BC':
        ans += a_num
        i += 2
    else:
        a_num = 0
        b_num = 0
        i += 1

print(ans)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
qS = input()


def replace(s, count):
    fi = s.find('ABC')
    if fi >= 0:
        newS = 'A' + s[fi+3:]
        return replace(newS, count + 1)
    else:
        return count


print(replace(qS, 0))

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
qS = input()


def replace(s, count):
    fi = s.find('ABC')
    if fi >= 0:
        newS = s[:fi] + 'BCA' + s[fi+3:]
        return replace(newS, count + 1)
    else:
        return count


print(replace(qS, 0))

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import re

qS = input()


def replace(s, count):
    matches = re.finditer('ABC', s)
    max_count = count
    for m in matches:
        m.span()
        max_count = max(max_count, replace(
            s[:m.span()[0]] + 'BCA' + s[m.span()[1]:], count + 1))
    return max_count


print(replace(qS, 0))

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import re

qS = input()

counts = {}


def replace(s, count):
    if counts.get(s, -1) >= 0:
        return counts[s]
    else:
        matches = re.finditer('ABC', s)
        max_count = count
        for m in matches:
            m.span()
            max_count = max(max_count, replace(
                s[:m.span()[0]] + 'BCA' + s[m.span()[1]:], count + 1))
        counts[s] = max_count
        return counts[s]


print(replace(qS, 0))
Problem p02596 (python)

Fixed submission:
K = int(input())
count = 1
rem = 7 % K

if K % 2 == 0:
    print(-1)
elif rem % K == 0:
    print(1)
else:
    while (rem % K) != 0 and count <= K:
        count += 1
        rem += 7 * pow(10, count-1, mod=K) % K
    if count <= K:
        print(count)
    else:
        print(-1)

Buggy submission (verdict: Runtime Error):
K = int(input())
count = 1
rem = 7 % K

if K % 2 == 0:
    print(-1)
elif rem % K == 0:
    print(1)
else:
    while (rem % K) != 0:
        count += 1
        rem += 7 * pow(10, count-1, mod=K) % K
    print(count)
Problem p02623 (python)

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

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

a, b = [0], [0]
for i in range(N):
    a.append(a[i] + A[i])
for i in range(M):
    b.append(b[i] + B[i])

ans, j = 0, M
for i in range(N+1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans, i + j)

print(ans)

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

time_A = list(map(int, input().split()))
time_B = list(map(int, input().split()))
max_books = 0
num_books = 0
allot_to_A = 0
allot_to_B = K
time_bankB = allot_to_B
read_in_B = []
baf_timeB = 0

for i in range(len(time_B)):
    if time_B[i] <= time_bankB:
        time_bankB -= time_B[i]
        num_books += 1
        read_in_B.append(time_B[i])
    else:
        baf_timeB = time_bankB
if baf_timeB == 0:
    baf_timeB = K - sum(time_B)

max_books = num_books
tmp = max_books


for i in range(len(time_A)):
    tmp = max_books
    dif = 1
    allot_to_A += time_A[i]
    allot_to_B -= time_A[i]
    if allot_to_B < 0:
        break
    time_to_reduce = time_A[i]
    while time_to_reduce > 0:
        if time_to_reduce <= baf_timeB:
            baf_timeB -= time_to_reduce
            break
        else:
            baf_timeB += read_in_B[-1]
            dif -= 1
            del read_in_B[-1]
    tmp += dif
    max_books = max(tmp, max_books)

print(max_books)

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

time_A = list(map(int, input().split()))
time_B = list(map(int, input().split()))
max_books = 0
num_books = 0
allot_to_A = 0
allot_to_B = K

time_bankA = allot_to_A
time_bankB = allot_to_B
read_in_B = []
baf_timeB = 0

for i in range(len(time_B)):
    if time_B[i] <= time_bankB:
        time_bankB -= time_B[i]
        num_books += 1
        read_in_B.append(time_B[i])
    else:
        baf_timeB = time_bankB
if baf_timeB == 0:
    baf_timeB = K - sum(time_B)
max_books = num_books
tmp = max_books


for i in range(len(time_A)):
    dif = 1
    allot_to_A += time_A[i]
    allot_to_B -= time_A[i]
    if allot_to_B < 0:
        break
    time_to_reduce = time_A[i]
    while time_to_reduce > 0:
        if time_to_reduce <= baf_timeB:
            baf_timeB -= time_to_reduce
            break
        else:
            baf_timeB += read_in_B[-1]
            dif -= 1
            del read_in_B[-1]
    tmp += dif
    max_books = max(tmp, max_books)

print(max_books)
Problem p02659 (python)

Fixed submission:
from decimal import Decimal

A, B = map(Decimal, input().split())

print(int(A * B))

Buggy submission (verdict: Runtime Error):
from Decimal import decimal

A, B = map(decimal, input().split())
print(A * B)
Problem p02862 (python)

Fixed submission:
X, Y = map(int, input().split())
P = 10 ** 9 + 7
N = (X+Y) // 3
R = (2 * X - Y) // 3
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]

for i in range(2, N+1):
    fact.append((fact[-1] * i) % P)
    inv.append((-inv[P % i] * (P//i) % P))
    factinv.append((factinv[-1] * inv[-1] % P))


def cmb_mod(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n-r)
    return fact[n] * factinv[r] * factinv[n-r] % p


if (X+Y) % 3 != 0:
    print(0)
else:
    print(cmb_mod(N, R, P))

Buggy submission (verdict: Runtime Error):
X, Y = map(int, input().split())
P = 10 ** 9 + 7
N = (X+Y) // 3
R = (2 * X -Y) // 3
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]

for i in range(2, N+1):
    fact.append((fact[-1] * i) % P)
    inv.append((-inv[P % i] * (P//i) % P))
    factinv.append((factinv[-1] * inv[-1] % P))


def cmb_mod(n, r, p):
    r = min(r, n-r)
    return fact[n] * factinv[r] * factinv[n-r] % p


if (X+Y) % 3 != 0:
    print(0)
else:
    print(cmb_mod(N, R, P))
Problem p03013 (python)

Fixed submission:
N, M = map(int, input().split())
dp = [0 for _ in range(N+1)]
skip = {}

for _ in range(M):
    skip[int(input())] = 1

dp[0] = 1
if 1 not in skip:
    dp[1] = 1

for i in range(2, N+1):
    if i in skip:
        continue
    dp[i] += (dp[i-1] + dp[i-2]) % 1000000007

print(dp[N])

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
dp = [0 for _ in range(N+1)]
skip = {}

for _ in range(M):
    skip[int(input())] = 1

dp[1] = 1
dp[2] = 2

if 1 in skip:
    dp[1] = 0
    dp[2] = 1
if 2 in skip:
    dp[2] = 0

for i in range(3, N+1):
    if i in skip:
        continue
    dp[i] = (dp[i-1] + dp[i-2]) % 1000000007

print(dp[N])

Buggy submission (verdict: Runtime Error):
import sys

N, M = map(int, input().split())
dp = [0 for _ in range(N+1)]
skip = {}

for _ in range(M):
    skip[int(input())] = 1

dp[1] = 1
dp[2] = 2

if 1 in skip:
    dp[1] = 0
    dp[2] = 1
if 2 in skip:
    dp[2] = 0
if N in skip:
    print(0)
    sys.exit()

for i in range(3, N+1):
    if i in skip:
        continue
    else:
        dp[i] = (dp[i-1] + dp[i-2]) % 1000000007

print(dp[N])

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
dp = [0 for _ in range(N+1)]
skip = {}

for _ in range(M):
    skip[int(input())] = 1

dp[1] = 1
dp[2] = 2

if 1 in skip:
    dp[1] = 0
    dp[2] = 1
if 2 in skip:
    dp[2] = 0

for i in range(3, N+1):
    if i in skip:
        continue
    else:
        dp[i] = (dp[i-1] + dp[i-2]) % 1000000007

print(dp[N])

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
dp = [0 for _ in range(N+1)]
skip = []

for _ in range(M):
    skip.append(int(input()))

dp[1] = 1
dp[2] = 2

if 1 in skip:
    dp[1] = 0
    dp[2] = 1
if 2 in skip:
    dp[2] = 0

for i in range(3, N+1):
    if i in skip:
        continue
    else:
        dp[i] = (dp[i-1] + dp[i-2]) % 1000000007

print(dp[N])
Problem p02552 (python)

Fixed submission:
print(1 - int(input()))

Buggy submission (verdict: Runtime Error):
x = input()
if x == 0:
  print(1)
  else:
    print(0)

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

if x == 1:
  print(0)
  
if X == 0:
  print(1)

Buggy submission (verdict: Runtime Error):
x = input()

if x == 1:
  print(0)
  
if X == 0:
  print(1)
Problem p02597 (python)

Fixed submission:
if __name__ == '__main__':
    N = int(input())
    C = list(input())
    cnt = 0
    red_cnt = 0
    for c in C:
        if c == 'R':
            red_cnt += 1

    for i in range(red_cnt):
        if C[i] == 'W':
            for j in range(red_cnt, N):
                if C[j] == 'R':
                    C[i] = 'R'
                    C[j] = 'W'
                    cnt += 1
                    red_cnt = j+1
    print(cnt)

Buggy submission (verdict: Runtime Error):
if __name__ == '__main__':
    N = int(input())
    C = list(input())
    cnt = 0
    red_cnt = 0
    for c in C:
        if c == 'R':
            red_cnt += 1

    for i in range(red_cnt+1):
        if C[i] == 'W':
            for j in range(red_cnt, N):
                if C[j] == 'R':
                    C[i] = 'R'
                    C[j] = 'W'
                    cnt += 1
                    red_cnt = j+1
    print(cnt)

Buggy submission (verdict: Runtime Error):
if __name__ == '__main__':
    N = int(input())
    C = list(input())
    cnt = 0
    red_cnt = 0
    for c in B:
        if c == 'R':
            red_cnt += 1

    for i in range(red_cnt+1):
        if C[i] == 'W':
            for j in range(red_cnt, N):
                if C[j] == 'R':
                    C[i] = 'R'
                    C[j] = 'W'
                    cnt += 1
                    red_cnt = j+1
    print(cnt)

Buggy submission (verdict: Runtime Error):
if __name__ == '__main__':
    N = int(input())
    C = list(input())
    cnt = 0
    red_cnt = 0
    B = sorted(C)
    for c in B:
        if c == 'R':
            red_cnt += 1
        else:
            break
    for i in range(red_cnt+1):
        if C[i] == 'W':
            for j in range(red_cnt, N):
                if C[j] == 'R':
                    C[i] = 'R'
                    C[j] = 'W'
                    cnt += 1
                    red_cnt = j+1
    print(cnt)
Problem p02862 (python)

Fixed submission:
X, Y = map(int, input().split())

if (X + Y) % 3 != 0:
    print("0")
    exit()

n_right = (-X + 2 * Y) / 3
n_up = (2 * X - Y) / 3
if n_right < 0 or n_up < 0:
    print("0")
    exit()


def cmb(n, r, mod):
    if (r < 0 or r > n):
        return 0
    r = min(r, n - r)
    return g1[n] * g2[r] * g2[n - r] % mod


mod = 10**9 + 7  # 出力の制限
N = 10**6
g1, g2, inverse = [1, 1], [1, 1], [0, 1]

for i in range(2, N + 1):
    g1.append((g1[-1] * i) % mod)
    inverse.append((-inverse[mod % i] * (mod // i)) % mod)
    g2.append((g2[-1] * inverse[-1]) % mod)

n_right, n_up = int(n_right), int(n_up)
print(cmb(n_right + n_up, min((n_right, n_up)), mod))

Buggy submission (verdict: Runtime Error):
X, Y = map(int, input().split())

if (X + Y) % 3 != 0:
    print("0")
    exit()

n = (-X + 2 * Y) / 3
m = (2 * X - Y) / 3
if n < 0 or m < 0:
    print("0")
else:
    import math
    n, m = int(n), int(m)
    s = 0
    for i in range(2, m + n + 1):
        s += math.log(i)
    for i in range(2, m + 1):
        s -= math.log(i)
    for i in range(2, n + 1):
        s -= math.log(i)
    
    print(int(math.exp(s)) % (10**9 + 7))
Problem p02753 (python)

Fixed submission:
input_line = input()

if input_line == "AAA" or input_line == "BBB":
    print("No")
else:
    print("Yes")

Buggy submission (verdict: Runtime Error):
input_line = input()

if input_line == "AAA" or input_line == "BBB"
    print("No")
else:
    print("Yes")

Buggy submission (verdict: Runtime Error):
s1,s2,s3 = input().split()

if s1 == s2 and s1 == s3:
    print("No")
else:
    print("Yes")
Problem p02659 (python)

Fixed submission:
print((lambda a:a[0]*a[1]//100)(list(map(int,input().replace(".", "").split()))))

Buggy submission (verdict: Runtime Error):
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)


























int main(){
    ll a;
    long double b;
    cin >> a >> b;
    cout << (ll)(a * b) << endl;
}
Problem p02659 (python)

Fixed submission:
from decimal import Decimal
a,b=map(Decimal, input().split())
print(int(a*b))

Buggy submission (verdict: Runtime Error):
from decimal improt Decimal
a,b=map(Decimal, input().split())
print(int(a*b))

Buggy submission (verdict: Runtime Error):
from decimal improt Decimal
a,b=map(Decimal, input().split())
print(a*b)

Buggy submission (verdict: Runtime Error):
a,b=intput().split()
a=int(a)
b=int(float(b)*100)
print(int(a*b/100))

Buggy submission (verdict: Runtime Error):
a,b=intput().split()
b=b*100
print(a*b/100)

Buggy submission (verdict: Runtime Error):
a,b=input().split()
b = b*100
print(a*b//100)
Problem p02753 (python)

Fixed submission:
S = input()
if S.find("A") == -1 or S.find("B") == -1:
    print("No")
else:
    print("Yes")

Buggy submission (verdict: Runtime Error):
A, B = map(int, input().split())
if int(A/0.08*0.1) == B :
    print(int(A/0.08))
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
A, B = map(int, input().split())
if int(A/0.08*0.1) == B :
    print(round(A/0.08))
else:
    print(-1)
Problem p02759 (python)

Fixed submission:
n = int(input())
print(int(n/2)+int(n%2))

Buggy submission (verdict: Runtime Error):
n = input()
print(int(n/2)+(n%2))
Problem p02785 (python)

Fixed submission:
HP, k = map(int, input().split())
enamy = list(map(int, input().split()))

enamy1 = sorted(enamy, reverse=True)
if len(enamy) <= k:
  print(0)
else:
  del enamy1[0:k]
  print(sum(enamy1))

Buggy submission (verdict: Runtime Error):
HP, k = map(int, input().split())
enamy = list(map(int, input().split()))

enamy1 = sorted(enamy, reverse=True)
if n =< k:
  print(0)
else:
  del enamy1[0:k]
  print(sum(enamy1))
Problem p02790 (python)

Fixed submission:
a, b = map(int, input().split())
ans = min(str(a) * b, str(b) * a)
print(ans)

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split())
if int("a"*b) >= int("b"*a):
  print(int("b"*a)
else:
  print(int("a"*b)
Problem p02792 (python)

Fixed submission:
n = int(input())
cheak_box = [[0]*9 for _ in range(9)]

for i in range(1, n+1):
    s = str(i)
    s1 = int(s[0]) - 1
    s2 = int(s[-1]) - 1
    if s2 == -1:
        continue 
    cheak_box[s1][s2] += 1

ans = 0
for p in range(9):
    for q in range(9):
        ans += cheak_box[p][q] * cheak_box[q][p]
        
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
cheak =[[0]*9 for _ in range]
for i in range(1, n+1):
    s = str(i)
    s1 = int(s[0])-1
    s2 = int(s[-1])-1
    if s2 == 0:
        continue
    cheak[s1][s2] += 1

ans = 0
for i in range(10):
    for j in range(10):
        ans += cheak[i][j] * cheak[j][i]
print(ans)
Problem p02820 (python)

Fixed submission:
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = list(input())

for i in range(n-k):
  if t[i] == t[i+k]:
    t[i+k] = 0

print(sum([t.count("r")*p, t.count("s")*r, t.count("p")*s]))

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()

for i in range(n-k):
  if t[i] == t[i+k]:
    t[i+k] = 0
print(sum(t.count("r")*r + t.count("s")*s + t.count("p")*p))
Problem p02829 (python)

Fixed submission:
a = int(input())
b = int(input())
print(6-a-b)

Buggy submission (verdict: Runtime Error):
a, b = map(int,input().split())
big = max(a, b)
small = min(a, b)
for i in range(1, 100000):
  if big*i % small == 0:
    print(big*i)
    exit()
Problem p02881 (python)

Fixed submission:
n = int(input())
ans = 10**12
for i in range(1, int(n**0.5)+1):
  if n%i == 0:
    l = (i+(n/i)-2) #-2は(0,0)->(1,1)の分
    ans = min(ans, l)
print(int(ans))

'''
10^12 以下の 正整数 N が与えられます。
この整数を i×j (i,j∈N) と表したとき，i+j−2 の最小値を求める問題です。
まず，愚直に考えると [1, N] の範囲で 2 重ループを回し，ij=N となる 2 整数の和の最小値を更新すればよいです。しかし，これは O(N2) となり，到底間に合いません。
ここで，約数 (つまり，ij=N, i≤j となる i,j すべて) を列挙する際，一方の約数 i は N−−√ 以下であることを利用します。もう一方の約数 j は N÷i から求まるので，すべての約数は O(N−−√) で求まることがわかります。
あとは，すべての i,j の組を列挙し，i+j−2 の最小値を求めれば良いです。1×N=N であることは自明なので，1+N–2=N–1 を初期値にしておきましょう。

計算量 O(N−−√)
'''

Buggy submission (verdict: Runtime Error):
n = int(input())
ans = 0
for i in range(int(n**0.5)):
  if n%i == 0:
    l = i + (n/i) -2 #-2は(0,0)->(1,1)の分
    ans = min(ans, l)
print(ans)

'''
10^12 以下の 正整数 N が与えられます。
この整数を i×j (i,j∈N) と表したとき，i+j−2 の最小値を求める問題です。
まず，愚直に考えると [1, N] の範囲で 2 重ループを回し，ij=N となる 2 整数の和の最小値を更新すればよいです。しかし，これは O(N2) となり，到底間に合いません。
ここで，約数 (つまり，ij=N, i≤j となる i,j すべて) を列挙する際，一方の約数 i は N−−√ 以下であることを利用します。もう一方の約数 j は N÷i から求まるので，すべての約数は O(N−−√) で求まることがわかります。
あとは，すべての i,j の組を列挙し，i+j−2 の最小値を求めれば良いです。1×N=N であることは自明なので，1+N–2=N–1 を初期値にしておきましょう。

計算量 O(N−−√)
'''
Problem p03038 (python)

Fixed submission:
import sys
from heapq import heappush, heappop

input = sys.stdin.readline
n, m = map(int, input().split())
heap = []

for i in map(int, input().split()):
  heappush(heap, i)

bc = [list(map(int, input().split())) for _ in range(m)]
bc.sort(key = lambda x: -x[1])#cが大きいものから順に操作を加える

for b,c in bc:
  for j in range(b):
    a = heappop(heap)
    if a < c:
      heappush(heap, c)
    else:
      heappush(heap, a)
      break
print(sum(heap))

Buggy submission (verdict: Runtime Error):
import numpy as np
n, m = map(int, input().split())
num = list(map(int, input().split()))
for i in range(m):
  num.sort()
  cnt, changeNum = map(int, input().split())
  for j in range(cnt):
    if num[j] >= changeNum:
      break
    else:
      num[j] = changeNum
print(sum(num))
Problem p03041 (python)

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

S[K-1] = S[K-1].lower()

S = ''.join(S)
print(S)

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

S[K-1] = S[K-1].lower()

print(S)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
s=input()
s[m].lower()
print(s)
Problem p03834 (python)

Fixed submission:
s = input()

print(s.replace(",", " "))

Buggy submission (verdict: Runtime Error):
K, S = map(int, input().split())
count = 0

for x in range(K + 1):
    for y in range(K + 1):
        z = S - (x + y)
        if 0 <= z and z <= K:
            count += 1

print(count)