akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
	"strings"
)

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func main() {
	n, k := oneInt(), oneInt()

	fmt.Print(n - k + 1)
}

func oneInt() int {
	var a int
	fmt.Scan(&a)
	return a
}
func oneStr() string {
	var a string
	fmt.Scan(&a)
	return a
}

func readLine() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func scanNums(n int) (nums []int) {
	str := readLine()
	s := strings.Split(str, " ")
	for i := 0; i < n; i++ {
		num, _ := strconv.Atoi(s[i])
		nums = append(nums, num)
	}
	return nums
}

func scanStrings() []string {
	str := readLine()
	s := strings.Split(str, " ")

	return s
}

func abs(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}

func sortAsc(a []int) []int {
	sort.Ints(a)
	return a
}

func sortDesc(a []int) []int {
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	return a
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	if a == 0 && b == 0 {
		return 0
	}
	return a * b / gcd(a, b)
}

func cumSum(nums []int) []int {
	sums := []int{0}

	for i := 0; i < len(nums); i++ {
		sums = append(sums, sums[i]+nums[i])
	}
	return sums
}


Measured memory_bytes: 640
import sys
from typing import List, Tuple, Dict
from dataclasses import dataclass, field

import scipy
import numpy as np
from numba import jit

D = int(input())  # 日数 D = 365
C = np.array(list(map(int, input().split())), dtype='int32')  # 満足度の下がりやすさ 26個
S = np.array([list(map(int, input().split())) for _ in range(D)], dtype='int32')  # d日目にコンテストiを行ったときの満足度


@dataclass()
class Node:
    date: int
    value: int
    result: list = field(default_factory=list)

    def __lt__(self, other) -> bool:
        return self.value < other.value


def calc_satisfaction(plan: List[int]) -> int:
    assert len(plan) == D
    res = 0
    last = np.zeros(26)

    for d in range(D):
        p = plan[d] - 1
        res += S[d][p]
        last[p] = d + 1

        for i in range(26):
            res -= C[i] * (d + 1 - last[i])

    return res


def calc_score(plan: List[int]) -> int:
    return max(10 ** 6 + calc_satisfaction(plan), 0)


def calc_dissatisfaction(d: int, last: np.ndarray) -> int:
    return sum([C[i] * (d - last[i]) for i in range(26)])


plan = []
last = np.zeros(26)
for d in range(D):
    t = 0
    max_s = 0

    for i in range(26):
        s = S[d][i] + C[i] * (d + 1 - last[i])
        if s > max_s:
            t = i
            max_s = s

    plan.append(t + 1)
    last[t] = d

print(plan, file=sys.stderr)
# print(calc_satisfaction(plan), file=sys.stderr)
print('\n'.join(map(str, plan)))


Measured memory_bytes: 93488
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 100000000;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
const ll MAX = 200010;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;
    cin >> n >> m;
    vector<vector<bool>> g(n,vector<bool>(n,0));
    int a,b;
    rep(i,m){
        cin >> a >> b;
        g[a-1][b-1] = 1;
        g[b-1][a-1] = 1;
    }
    vector<int> o(n-1);
    rep(i,n-1) o[i] = i+1;
    int ans = 0;
    do{
        bool ok = 1;
        if (g[0][o[0]] == false) continue;
        rep(i,n-2){
            if (g[o[i]][o[i+1]] == false) ok = 0;
        }
        if (ok) ans++;
    }while(next_permutation(all(o)));
    PRINT(ans);
}



Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, a, b;
    cin >> n >> a >> b;
    int sum = 0;
    for(int i = 1; i <= n; i++)
    {
        int j = i;
        int cand = 0;
        while(j / 10 > 0)
        {
            cand += j % 10;
            j /= 10;
        }
        cand += j;
        if (cand >= a && cand <= b) sum += i;
    }
    cout << sum << endl;
}




Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		// 整数の入力
		String b = sc.next();
		String ret = "";

		if(b.equals("A")){
			ret = "T";
		}else if(b.equals("T")){
			ret = "A";
		}else if(b.equals("C")){
			ret = "G";
		}else{
			ret = "C";
		}

		System.out.println(ret);

		sc.close();
	}
}


Measured memory_bytes: 20560
#include <iostream>
using namespace std;
int main()
{
	int a, b, c;
	while (cin >> a >> b, a && b)
	{
		int r[3] = {0};
		c = b-a;
		while (c > 0)
		{
			if (c >= 1000)
				r[2] += c / 1000, c %= 1000;
			else if (c >= 500)
				r[1] += c / 500, c %= 500;
			else if (c >= 100)
				r[0] += c / 100, c %= 100;
		}
		cout << r[0] << " " << r[1] << " " << r[2] << endl;
	}
}

Measured memory_bytes: 0
package main

import (
	"bufio"
	"fmt"
	"os"
)

const (
	oddHates = "L"
	evenHates = "R"
)
func main() {

	i := input()

	o := []string{}
	e := []string{}
	for i,v := range i {
		if i % 2 != 0 {
			e = append(e,string(v))
		} else {
			o = append(o,string(v))
		}
	}
	if containsOtherEle(o,oddHates) || containsOtherEle(e,evenHates){
		fmt.Println("No")
	} else {
		fmt.Println("Yes")
	}
}

func input() string{
	var sc = bufio.NewScanner(os.Stdin)
	sc.Scan()
	return sc.Text()
}

func containsOtherEle(s []string,element string) bool {
	for _,v := range s {
		if v == element {
			return true
		}
	}
	return false
}


Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
	static void Main(string[] args)
	{
		// 整数の入力(入力回数)
		int n = int.Parse(Console.ReadLine());
		var inputList = new List<int>();

		for (int i = 1; i <= n; i++)
		{
			inputList.Add(int.Parse(Console.ReadLine()));
		}

		var answer = inputList.Distinct().Count();
		Console.WriteLine(answer);
	}

}

Measured memory_bytes: 13152
import math
from itertools import accumulate

N = int(input())

W = list(map(int, input().split()))
fcheck = W
fcheck = list(accumulate(fcheck))

bcheck = W[::-1]
bcheck = list(accumulate(bcheck))
bcheck = bcheck[::-1]

buff = []
for i in range(N):
    if i < N-1:
        buff.append(abs(fcheck[i]-bcheck[i+1]))
    else:
        buff.append(fcheck[i])

print(min(buff))

Measured memory_bytes: 3064
def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd(a, b)


n = int(input())
a = list(map(int, input().split()))
lcm_a = a[0]

for i in range(1, n):
    lcm_a = lcm(lcm_a, a[i])

ans = 0

for i in a:
    ans += lcm_a // i

print(ans%1000000007)


Measured memory_bytes: 4084
def solve():
    N,M = [int(i) for i in input().split()]
    solved = set([])
    penalty = {}
    for i in range(M):
        problem_id,result = input().split()
        if result == 'AC':
            solved.add(problem_id)
        elif result == 'WA' and problem_id not in solved:
            penalty[problem_id] = penalty.get(problem_id, 0) + 1
    num_penalties = 0
    for problem_id in solved:
        num_penalties += penalty.get(problem_id, 0)
    print(len(solved), num_penalties)


if __name__ == "__main__":
    solve()

Measured memory_bytes: 20048
def solve():
    N, K = map(int, input().split())
    s = input()
    count = 0
    
    for i in range(N-1):
        if s[i] == s[i+1]:
            count += 1
    
    print(min(count + 2 * K, N - 1))

if __name__ == '__main__':
    solve()

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define for(a,n) for(int i = a; i < n; i++)
using namespace std;
unsigned long long tim(int k){
    int dem = 1;
    queue<unsigned long long> q;
    for(1,10) q.push(i);
    while(dem < k){
        unsigned long long temp = q.front();
        q.pop();
        int dv = temp%10;
        unsigned long long t;
        for(-1,2){
            if(dv + i >= 0 && dv + i <= 9){
                t = temp * 10 + dv + i;
                q.push(t);
            }
        }
        dem ++;
    }
    return q.front();
}
int main(){
    int k;
    cin >> k;
    if(k<=12) cout << k;
    else{
        cout << tim(k);
    }
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
#define INF 1000000000
#define pb push_back
#define sz(a) int((a).size())
#define all(c) c.begin(), c.end()
#define tr(c, i) for (typeof(c).begin() i = c.begin(); i != c.end(); i++)
#define present(c, x) (c.find(x) != c.end())
#define cpresent(c, x) (find(all(c), x) != c.end())

ll bigmod(ll a, ll b, ll m)
{

    if (b == 0)
        return 1;
    ll x = bigmod(a, b / 2, m);
    x = (x * x) % m;

    if (b % 2)
        x = (x * a) % m;
    return x;
}

ll bigsum(ll a, ll b, ll m)
{
    ll s;
    if (b == 0)
        return b;
    if (b == 1)
        return a + 1;
    if (b % 2)
    {
        b = b / 2;
        s = bigsum(a, b, m) % m;
        s = (s * bigmod(a, b + 1, m)) % m;
        return s;
    }
    else
    {
        s = bigsum(a, b - 1, m) % m;
        s = (a * s + 1) % m;
        return s;
    }
}


int main()
{
    ll i,s=0,p[200005],ara[200005],n,mod = 1000000007;
    cin>>n;

    for(i=1;i<=n;i++) cin>>ara[i];
    p[n+1] = 0;
    for(i=n;i>0;i--){
        p[i] = p[i+1]+ara[i];
        p[i] %= mod;
    }

    for(i=1;i<=n;i++){
        s += p[i+1] * ara[i];
        s %= mod;
    }

    cout<<s%mod<<endl;
    return 0;
}

Measured memory_bytes: 6704
#include<stdio.h>
int main(void)
{
	int a,b,c,d,p,x,y;
	scanf("%d %d %d %d %d",&a,&b,&c,&d,&p);
	x=p*a;
	if(p>c){
		y=b+(p-c)*d;
	}
	else{
		y=b;
	}
	if(x>y){
		printf("%d\n",y);
	}
	else{
		printf("%d\n",x);
	}
	return 0;
}


Measured memory_bytes: 2144
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <stack>
#include <cmath>
using namespace std;
int N;
int a[51];
int Max=0,Min=0,min_index=1,max_index=1;
int main(){
  cin >> N;
  for(int i=1;i<=N;i++)cin >> a[i];

  for(int i=1;i<=N;i++){
    if(a[i]>0){
      if(Max<a[i]){Max=a[i];max_index=i;}
    }
    else{
      if(Min>a[i]){Min=a[i];min_index=i;}
    }
  }
  cout << 2*N-2 << endl;
  if(abs(Min)<abs(Max)){
    for(int i=1;i<=N;i++){
      if(i!=max_index){cout << max_index << " " << i << endl;a[i]+=a[max_index];}
    }
    //for(int i=1;i<=N;i++)cout << a[i] << " ";
    for(int i=2;i<=N;i++){
      cout << i-1 << " " << i << endl;
      a[i]+=a[i-1];
    }
  }
  else{
     for(int i=1;i<=N;i++){
       if(i!=min_index){cout << min_index << " " << i << endl;a[i]+=a[min_index];}
    }
     //for(int i=1;i<=N;i++)cout << a[i] << " ";
     for(int i=N-1;i>=1;i--){
      cout << i+1 << " " << i << endl;
      a[i]+=a[i+1];
    }
  }
  //for(int i=1;i<=N;i++)cout << a[i] << " ";
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;

public class Program
{
    public static void Main()
    {
        var s = Console.ReadLine();
        var t = Console.ReadLine();

        var answer = s.ToList()
                      .Select((c, i) => c != t[i])
                      .Count(b => b);

        Console.Write(answer);
    }
}

Measured memory_bytes: 28968
#include<bits/stdc++.h>

using namespace std;

#define ll long long

ll dp[101][100001];

bool comp(pair<ll,ll> p1,pair<ll,ll> p2)
{
	return p1.first<p2.first;
}

int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif // ONLINE_JUDGE
	ll n,w;
	cin>>n>>w;
	vector<pair<ll,ll>> arr(n);
	for(int i=0;i<n;i++)
	{
		cin>>arr[i].first>>arr[i].second;
	}
	sort(arr.begin(),arr.end(),comp);
	for(int i=0;i<101;i++)
	{
		for(int j=0;j<100001;j++)
		{
			dp[i][j]=0;
		}
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=w;j++)
		{
			if(j-arr[i-1].first>=0)
				dp[i][j]=max(dp[i-1][j],arr[i-1].second+dp[i-1][j-arr[i-1].first]);
			else
				dp[i][j]=dp[i-1][j];
		}
	}
	// for(int i=0;i<=n;i++)
	// {
	// 	for(int j=0;j<=w;j++)
	// 		cout<<dp[i][j]<<" ";
	// 	cout<<"\n";
	// }
	cout<<dp[n][w];
}

Measured memory_bytes: 82396
fun main (args:Array<String>){
    val n = readLine()!!.toInt()
    val A = readLine()!!.split(" ").map(String::toLong)

    for (i in 0..n-1) {
        if (A[i] == 0L) {
            println(0)
            return
        }
    }

    val MAX = Math.pow(10.0, 18.0).toLong()
    var result = A[0]
    for (i in 1..n-1) {
        if (!check(result, A[i])) {
            println(-1)
            return
        }
        result *= A[i]
        if (result > MAX) {
            println(-1)
            return
        }
    }
    println(result)
}

fun check(a: Long, b: Long): Boolean {
    val result = a * b;
    return (a == result / b)
}



Measured memory_bytes: 61744
#include <bits/stdc++.h>
using namespace std;
using Int = int_fast64_t;

Int n;
vector<Int> a;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n;
	a.resize(n);
	for(auto &i:a) cin >> i;
	for(Int i=1; i<n; ++i) a[i] += a[i-1];
	Int ans = 1e18;
	for(Int i=0; i<n-1; ++i){
		Int l = a[i];
		Int r = a[n-1] - l;
		ans = min(ans, abs(r-l));
	}
	cout << ans << "\n";
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;

#define int long long int
#define ff first
#define ss second
#define pb push_back

int bexp(int a, int b)
{
    int res = 1;

    while (b)
    {
        if (b & 1) res = (res * a);

        a = (a * a); 
        b >>= 1;
    }
    return res;
}

#define N 200010
#define MOD 1000000007

int gcd(int a, int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}


int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(10);

    int x;
    cin >> x;

    int am = 100, ans = 0;
    while (am < x)
    {
        ans++;
        am = am * 1.01;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORTASC(c) sort((c).begin(),(c).end())
#define SORTDESC(c,t) sort((c).begin(),(c).end(), std::greater<t>());
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define VMAX(a) *max_element(ALL(a))
#define VMIN(a) *min_element(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double PI  = acos(-1.0);

template <class T, class S>
using umap = std::unordered_map<T, S>;
using ll = long long;
using namespace std;

int main() {
    ll n, a, b;

    cin >> n >> a >> b;

    ll ans = (n / (a+b)) * a + min(n % (a+b), a);

  	cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
n=int(input())

v=[]
c=[]

line=input().split()

for i in range(n):
    v.append(int(line[i]))

line=input().split()

for i in range(n):
    c.append(int(line[i]))

sum=0

for i in range(n):
    if v[i]-c[i]>0:
        sum=sum+(v[i]-c[i])

print(sum)

Measured memory_bytes: 3064
#include <iostream>
using namespace std;

int A[100000];

int partition(int p, int r)
{
    int x = A[r];
    int i = p - 1;
    for (int j = p; j < r; ++j) {
        if (A[j] <= x) {
            i++;
            swap(A[i], A[j]);
        }
    }
    swap(A[i+1], A[r]);
    return i + 1;
}

int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> A[i];

    int index = partition(0, n - 1);

    for (int i = 0; i < n - 1; ++i) {
        if (i == index) {
            cout << "[" << A[i] << "] ";
        } else {
            cout << A[i] << " ";
        }
    }
    if (n-1 != index) {
        cout << A[n-1] << endl;
    } else {
        cout << "[" << A[n-1] << "]" << endl;
    }
    return 0;
}

Measured memory_bytes: 3376
#include <bits/stdc++.h>

//-----------------------------------------------------
/// SOL
///
///
//-----------------------------------------------------

#define up(i , a , b) for(int i = a ; i <= b; ++i)
#define up2(i , a , b , c) for(int i = a ; i <= b; i += c)
#define down(i , a , b) for (int i = a; i >= b; --i)
#define down2(i , a , b , c) for (int i = a; i >= b; i -= c)

#define II pair <int, int>
#define III pair<int, pair<int, int> >

#define pb push_back
#define mp make_pair

#define endl '\n'
#define TITLE "FACT"

#define gc getchar
#define pc putchar
#define length Len

//-----------------------------------------------------

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using namespace std;

const int N = 1000006;
const int oo = 1000000007;
bool DEBUG = 1;
ll n, Prime[N], Temp[N], cnt = 0, c[N];

struct T
{

};

void Eratos()
{
    up(i , 1 , N) Temp[i] = 1;
    Temp[0] = Temp[1] = 0;

    up(i , 2 , N) {
        if(Temp[i])
            up2(j , i * 2 , N , i)
                Temp[j] = 0;
    }

    up(j , 1 , N) if(Temp[j]) Prime[++cnt] = j;//, cout << j << " ";
}

void Init()
{
    cin >> n;

    up(i , 1, N) c[i] = 0;

    up(i , 1 , n) {
        ll j = 1, cur = i;
        //cout << cur << " " << Prime[j] << endl;
        while(Prime[j] * Prime[j] <= (cur))
        {
            if(cur % Prime[j] == 0)
            {
                c[Prime[j]]++;
                cur /= Prime[j];
            }
            else j++;
   //         cout << j << " ";
        }
 //       cout << cur << " ";
        c[cur]++;
    }

    up(i , 1 , n) {
        //cout << c[Prime[i]] << " ";
    }
}

void Solve()
{
    ll res = 1;
    up(i , 1 , n) {
        res = (res * (c[Prime[i]] + 1)) % oo;
    }
    cout << res;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    //freopen(TITLE".INP", "r", stdin);
  //  freopen(TITLE".OUT", "w", stdout);

    int Test = 1;
//    cin >> Test;
    up(i , 1 , Test) {
        Eratos();
        Init();
        Solve();
    }
}














/*
/// ***************************** FAST I/O *****************************
inline void read(long long &x)
{
    register int c = gc();
    x = 0;
    int neg = 0;
    for (;((c<48 || c>57) && c != '-') ;c = gc());
    if(c=='-') {neg=1;c=gc();}
    for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;}
    if(neg) x=-x;
}

inline void writeln(long long x)
{
     char buffor[21];
     register int i=0;
     int neg=0; if (x<0) {neg=1; x= -x;}
     do{
           buffor[i++]=(x%10)+'0';
           x/=10;
        } while(x);
       i--;
       if (neg) pc('-');
       while(i>=0) pc(buffor[i--]);
       pc('\n');
}
/// ***************************** FAST I/O *****************************
*/


Measured memory_bytes: 16640
N = int(input())
A = list(map(int, input().split()))

def insertationSort(A, N):
    for i in range(1, N):
        print(" ".join(map(str, A)))
        
        v = A[i]
        j = i - 1
        while j >= 0 and A[j] > v:
            A[j+1] = A[j]
            j -= 1
        A[j+1] = v
    print(" ".join(map(str, A)))
insertationSort(A, N)


Measured memory_bytes: 5604
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;

int x, a, b;

int main(void){
    
    scanf("%d %d %d", &x, &a, &b);
    
    if(abs(x - b) < abs(x - a)) printf("B\n");
    else printf("A\n");
    
    return 0;
}


Measured memory_bytes: 256
import java.util.*; 

class Main{
public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int m=sc.nextInt();
		int x=sc.nextInt();
		
  		int cmin=(int)Math.pow(10,7);
  		int[] c=new int[n];
  		int[][] a=new int[n][m];
  		
		for(int e=0;e<n;e++){
    		c[e]=sc.nextInt();
           for(int b=0;b<m;b++){
           a[e][b]=sc.nextInt();
           }
    	}
  
    for(int f=0;f<(1<<n);f++){
      int[] ans=new int[m];
      int c2=0;
      int y=0;
    for(int g=0;g<n;g++){
    if((1&f>>g)==1){
      c2+=c[g];
      for(int l=0;l<m;l++){
    	ans[l]+=a[g][l];
      }
    }
    }
      for(int k=0;k<m;k++){
      if(ans[k]<x){
       y++;
      }
      }
      if(y==0){
       cmin=Math.min(c2,cmin);
      }
    }
  
 	if(cmin==Math.pow(10,7)){
    		System.out.println(-1);
    	}else{
     		System.out.println(cmin);
   	 }

    }
}

Measured memory_bytes: 37184
#include<bits/stdc++.h>
using namespace std;

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll , ll> 			pll;
typedef pair<ld, ld> 			pld;
typedef unordered_map<ll, ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5 + 7;
const ll 	MAX7 	= 	1e+7 + 7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e9 + 7;


// <------------- Declare Variables Here ------------> //

ll T = 1;
ll n, x, m, k, u, v;
string s, t;

// <------------- Implement Functions Here ----------> //



// <------------- Start of main() -------------------> //

void MAIN() {
	cin>>s;
	n = s.length();
	string verify[2];
	for(ll i=0;i<n;i++) {
		if(i&1) {
			verify[0]+='0';
			verify[1]+='1';
		}
		else {
			verify[0]+='1';
			verify[1]+='0';
		}
	}

	ll cou1=0,cou2=0;
	for(ll i=0;i<n;i++) {
		if(verify[1][i]!=s[i]) cou2++;
		if(verify[0][i]!=s[i]) cou1++;
	}

	cout<<min(cou1,cou2);
}

int main() {
	fastio; randomINT;
	//cin >> T;
	while (T--) {
		MAIN();
	}
	return 0;
}

Measured memory_bytes: 3916
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define vv(T) std::vector<std::vector<T>>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;

int		main(void)
{
	int n, m;
	cin >> n >> m;

	vector<ll> X(m);
	for (int i = 0; i < m; ++i)
		cin >> X[i];
	if (n >= m)
	{
		cout << 0 << endl;
		return 0;
	}
	sort(all(X));
	vector<ll> D(m-1);
	ll ans = 0;
	for (int i = 0; i < m-1; ++i)
	{
		D[i] = X[i+1] - X[i];
		ans += D[i];
	}
	sort(rall(D));
	for (int i = 0; i < n-1; ++i)
		ans -= D[i];
	cout << ans << endl;	
}



Measured memory_bytes: 4712
//

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define fi first
#define se second
template<class T>inline bool chmin(T& a,T b,bool f){
if(f==1){if(a>b){a=b;return true;}return false;}
else if(f==0){if(a<b){a=b;return true;}return false;}return false;}
typedef pair<int,string> p;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

int main (){
    int n,m,x;cin>>n>>m>>x;
    vector<int>c(n);
    vector<vector<int>>s(n,vector<int>(m));
    vector<int>xx(m,0);
    rep(i,0,n){
        cin>>c[i];
        rep(j,0,m){
            cin>>s[i][j];
        }
    }
    int cost,ans=inf;
    for(int bit = 0;bit < (1<<n);++bit){
        cost=0;
        rep(i,0,m)xx[i]=0;
        rep(i,0,n){
            if(bit & (1<<i)){
                rep(j,0,m)xx[j]+=s[i][j];
                cost+=c[i];
            }
        }
        if(*min_element(range(xx))>=x){
            ans=min(ans,cost);
        }
    }
    cout << (ans==inf ? -1 : ans) << nnn;
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
using namespace std;

int main() {
    int N, K, S; cin >> N >> K >> S;
    if (S == (int)1e9) {
        for (int i = 0; i < K; i++) {
            printf("%d ", S);
        }
        for (int i = K; i < N; i++) {
            printf("1 ");
        }
    } else {
        for (int i = 0; i < K; i++) {
            printf("%d ", S);
        }
        for (int i = K; i < N; i++) {
            printf("%d ", S+1);
        }
    }
}

Measured memory_bytes: 1280
#include<iostream>
using namespace std;
int main(){
  string s; cin >> s;
  int a = s.size();
  for(int i=1;i<a/2;i++){
    int count=0;
    for(int j=0;j<(a-2*i)/2;j++){
      if(s[j]==s[(a-2*i)/2+j]) count++;
    }
    if(count==(a-2*i)/2){
      cout << a-2*i << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	long long int N, M, tmp, k, l;
	long long int A[100];
	double max,all;
	all = 0;
	cin >> N >> M;
	for (long long int i = 0; i < N; i++) {
		cin >> A[i];
	}
	for (long long int j = 0; j < N; j++) {
		all = all + A[j];
	}
	max = all / (4 * M);
	for (k = 0; k < N; ++k) {
		for (l = k + 1; l < N; ++l) {
			if (A[k] > A[l]) {
				tmp = A[k];
				A[k] = A[l];
				A[l] = tmp;
			}
		}
	}
	if (A[N - M] >= max) {
		cout << "Yes" << endl;
		return 0;
	}
	cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
D = int(input())
c = [int(x) for x in input().split()]
s = [input().split() for l in range(D)]

manzoku = 0
kyounomanzoku = 0
kyounotype = 0
d = 1
last = [0]*26

for p in range(D):
    print((p**3+2*p**2-15*p+11)%26+1)


"""
for p in range(D):
    #タイプはt[p]-1,0~25 満足度増加 s[p][t[p]] p+1日目 
    #typeを出力するときは＋１するのを忘れずに
    for t in range(26):
        if kyounomanzoku < int(s[p][t]):
            kyounomanzoku = int(s[p][t])
            kyounotype = t
    print(kyounotype+1)
    kyounomanzoku = 0
"""

Measured memory_bytes: 9460
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
int N;
long long A[100001];
long long wa_calc(int x){
   long long wa=0;
   REP(i,x){
       wa+=(i+1);
   }
   return wa;
}

int main(){
	cin>>N;
	REP(i,N){
	   cin>>A[i];
	}
	long long root=wa_calc(N);
	long long total=0;
	REP(i,N){
	   total+=A[i];
	}
	if(total%root!=0){
	   cout<<"NO"<<endl;
	   return 0;
	}
	long long k=total/root;
	long long l=k;
	REP(i,N){
	    long long sa=A[(i+N-1)%N]-A[i]+l;
	    	//cout<<k<<endl<<sa/N<<endl<<endl;
	    if(sa<0){
	       cout<<"NO"<<endl;
	       return 0;
	    }
	    if((sa%N)!=0){
	       cout<<"NO"<<endl;
	       return 0;
	    }
	    k-=(sa/N);
	}
	
	if(k==0){
	   cout<<"YES"<<endl;
	}else{
           cout<<"NO"<<endl;
        }
	return(0);
}

Measured memory_bytes: 1024
def cmb_mod(n, r, mod):
    x, y = 1, 1
    for i in range(r):
        x = (x * (n - i)) % mod
        y = (y * (i + 1)) % mod
    return (x * pow(y, mod - 2, mod)) % mod


n, a, b = map(int, input().split())
mod = (10 ** 9) + 7
all_case = pow(2, n, mod) - 1
print((all_case - cmb_mod(n, a, mod) - cmb_mod(n, b, mod)) % mod)

Measured memory_bytes: 3064
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

inline int topbit(unsigned long long x){
	return x?63-__builtin_clzll(x):-1;
}

inline int popcount(unsigned long long x){
	return __builtin_popcountll(x);
}

inline int parity(unsigned long long x){//popcount%2
	return __builtin_parity(x);
}



template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}

const ll INF=1e15;

const ll mod=1e9+7;


int main(){
   ll ans=INF;
   string s,t;
   cin >>  s >> t;
   ll n=s.length();
   ll m=t.length();
   rep(i,n){
       ll tot=0;
       if(i+m-1>=n) continue;
       rep(j,m){
           if(s[i+j]!=t[j]) tot++;
       }
       ans=min(ans,tot);
   }
   cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
S = input()

op_cnt = len(S) - 1#数字の間の数

for i in range(2 ** op_cnt):
  sign = ["+"] * op_cnt
  for j in range(op_cnt):
    if ((i>>j)&1):
      sign[j] = "-"
       
  formula = ""      
  for k in range(op_cnt):
    formula += S[k] + sign[k]
  formula += S[op_cnt]
  if eval(formula) == 7:
    print(formula + "=7")
    break

	

Measured memory_bytes: 3060
/* ALDS1_3D: Areas on the Cross-Section Diagram */
/* 20181115 AOJ */

#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>

void push(int m);
int pop();

#define N 20000
int top, stack[N];
typedef struct {
	int position;
	int area;
} Unit;

Unit unit[N/2];

int main(void){
	int sumArea = 0, i = -1, j = 0, k, pool = 0;
	char S[N];
	
	scanf("%s", S);
	while(S[++i]){
		if(S[i] == '\\'){
			push(i);
		}else if(S[i] == '/' && top ){
			k = pop();
			pool = i - k;
			sumArea += pool;
			while(j > 0){
				if(unit[j - 1].position > k){
					pool += unit[--j].area;
				}else{
					break;
				}
			}

			unit[j].position = k;
			unit[j++].area = pool;
		}else{
			/* Do Nothing */
		}
	}


	printf("%d\n%d", sumArea, j);
	
	for(i = 0; i < j; i++){
		printf(" %d", unit[i].area);
	}
	printf("\n");

	return 0;
}

void push(int m){
	stack[top++] = m;
}

int pop(){	
	return stack[--top];
}



Measured memory_bytes: 1992
#include <stdio.h>

main(){
  int data[1000], i, min2, j, k, n, min, ans[1000000], ans2[1000000];

  for(i=0;i<1000;i++){
    data[i]=(i+1)*(i+2)*(i+3)/6;
  }

  ans[0]=0;
  ans2[0]=0;
  for(i=1;i<1000000;i++){
    min=1000000;
    min2=1000000;
    for(j=0;data[j]<=i;j++){
      if(min>ans[i-data[j]]) min=ans[i-data[j]]+1;
      if(data[j]%2!=0){
	if(min2>ans2[i-data[j]]) min2=ans2[i-data[j]]+1;
      }
    }
    ans[i]=min;
    ans2[i]=min2;
  }
  while(1){
    scanf("%d", &n);
    if(n==0) break;
    printf("%d %d\n", ans[n], ans2[n]);
  }
  return 0;
}

Measured memory_bytes: 8044
n,m,k=map(int,input().split())
mod=998244353
ans=0

fact=[1] * (n+1)  # 階乗を格納するリスト
factinv=[1] * (n+1)  # 階乗を格納するリスト
for i in range(n):
    fact[i+1] = fact[i] * (i+1) % mod  # 階乗を計算
    factinv[i+1] = pow(fact[i+1], mod-2, mod)  # modを法とした逆元（フェルマーの小定理）

def nCk(n,k):  # 組み合わせ(mod)を返却する
    return fact[n] * factinv[n-k] * factinv[k] % mod

for k_i in range(k+1):
    ans += m * pow(m-1, n-1-k_i, mod) * nCk(n-1, k_i)
    ans %= mod
print (ans)

Measured memory_bytes: 24520
#include <bits/stdc++.h>
using namespace std;

int main() {
    long int H,W;
    cin >> H >> W;
    long int ans=H*W/2;
    if(H*W%2==1){
        ans++;
    }
    if(H==1 || W==1){
        ans=1;
    }
    cout << ans <<endl;
}

Measured memory_bytes: 256
use List::Util qw(max);

my @NK = split(/ /, <STDIN>);
my @sticks = split(/ /, <STDIN>);
@sticks = sort { $b <=> $a } @sticks;

my $length = 0;
for (1..$NK[1]) {
    $length += $sticks[$_-1];
}
print $length;

Measured memory_bytes: 640
def GCD(a,b): 
  if a<b:
    a,b = b,a

  r = a % b
  
  while r!=0:
    a = b
    b = r
    r = a % b
 
  return b

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

T = list(map(int, input().split()))
for i in range(N):
  T[i] = abs(T[i] - X)

ans = T[0]
for i in range(1,N):
  ans = GCD(ans, T[i])
  
print(ans)

Measured memory_bytes: 14228
import sys
from sys import stdin
def I():
    return stdin.readline().rstrip()
def MI():
    return map(int,stdin.readline().rstrip().split())
def LI():
    return list(map(int,stdin.readline().rstrip().split()))
#main part
n,x,m=MI()
stock=[]
for _ in range(1,n+1):
    if x not in stock:
        stock.append(x)
        x=(x**2)%m
        continue
    else:
        start=stock.index(x)
        repeat=stock[start:]
        l=len(repeat)
        n-=start
        sho=n//l
        amari=n%l
        s=sum(repeat)
        rest=0
        if amari!=0:
            for j in range(amari):
                rest+=repeat[j]
        print(s*sho+rest+sum(stock[:start]))
        sys.exit()
print(sum(stock))

Measured memory_bytes: 69152
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n, d;
    cin >> n >> d;
    int x[n][d];
    for(int i=0;i<n;i++){
        for(int j=0;j<d;j++){
            cin >> x[i][j];
        }
    }
    int count = 0;
    for(int k=0;k<n-1;k++){
        
        for(int m=k+1;m<n;m++){
            int sum = 0;
            for(int l=0;l<d;l++){
                sum = sum + pow(abs(x[m][l] - x[k][l]),2.0);
            }
            if(ceil(pow(sum,0.5)) == float(pow(sum,0.5))){
                count++;
            }
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    int N;
    cin >> N;
    vector<ll> cnt(N + 1, 1);
    for (int i = 2; i <= N; ++i) {
        for (int j = i; j <= N; j += i) {
            ++cnt[j];
        }
    }

    ll ans = 0;
    for (ll i = 1; i <= N; ++i) {
        ans += i * cnt[i];
    }

    cout << ans << endl;
}

Measured memory_bytes: 81328
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

// 入力
int N;
long long a[100010][3]; // a[i], b[i], c[i] をそれぞれまとめて a[i][0], a[i][1], a[i][2] にしてしまう

// DP テーブル
long long dp[100010][3];

int main() {
    int N; cin >> N;
    for (int i = 0; i < N; ++i) for (int j = 0; j < 3; ++j) cin >> a[i][j];

    // 初期化は既に 0 に初期化される
    // 初期条件も既に 0 で OK

    // ループ
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < 3; ++j) {
            for (int k = 0; k < 3; ++k) {
                if (j == k){
                  continue;
                }
                dp[i+1][k]=max(dp[i + 1][k], dp[i][j] + a[i][k]);
            }
        }
    }

    // 答え
    long long res = 0;
    for (int j = 0; j < 3; ++j) res=max(res, dp[N][j]);
    cout << res << endl;
}


Measured memory_bytes: 4992
DAYS =  %w(SUN MON TUE WED THU FRI SAT) * 2

def solve()

  n = gets.chomp
  res = 0
  started = false
  DAYS.each do |i|
    break if i == "SUN" && started
    if i == n
      started = true
    end
    res += 1 if started
  end
  puts res
  
end

solve

Measured memory_bytes: 1788
from itertools import product
N, A, B, C = map(int, input().split())
l = [int(input()) for i in range(N)]
INF = 10 ** 9
t1 = set([0,1,2,3])
t2= set([1,2,3])
def calc(t):
    t3 = set(t)
    if not (t3 == t1 or t3 == t2): return INF
    a, b, c = 0, 0, 0
    cnt = 0
    for i, v in enumerate(t):
        if v != 0: cnt += 1
        if v == 1: a += l[i]
        elif v == 2: b += l[i]
        elif v == 3: c += l[i]
    return abs(a-A) + abs(b-B) + abs(c-C) + max((cnt-3) * 10, 0)


ans = 10 ** 9
for p in product(range(4), repeat=N):
    ans = min(ans, calc(p))

print(ans)



Measured memory_bytes: 58844
std_n = int(input())
std_list = tuple(map(int, input().split()))
std_set = set(std_list)

if std_set == {0}:
    print("Yes")
    exit()
elif len(std_set) == 2:
    if 0 in std_set:
        if std_list.count(0) * 3 == std_n:
            print("Yes")
            exit()
        else:
            print("No")
            exit()
    else:
        print("No")
        exit()
elif len(std_set) == 3:
    a, b, c = tuple(std_set)
    if (std_list.count(a) == std_list.count(b)) and (std_list.count(b) == std_list.count(c)):
        if a ^ b == c:
            print("Yes")
            exit()
        else:
            print("No")
            exit()
    else:
        print("No")
        exit()
else:
    print("No")
    exit()

############


n = int(input())
nums = list(map(int, input().split()))

unq = list(set(nums))


def answer(ans):
    print(ans)
    exit()


if len(unq) > 3:
    answer("No")

if len(unq) == 3:
    a, b, c = unq
    if a ^ b ^ c != 0:
        answer("No")
    if nums.count(a) == nums.count(b) == nums.count(c):
        answer("Yes")
    else:
        answer("No")

if len(unq) == 2:
    a, b = sorted(unq)
    if a != 0:
        answer("No")
    if nums.count(a) * 2 == nums.count(b):
        answer("Yes")
    else:
        answer("No")

if len(unq) == 1:
    a = unq[0]
    if a != 0:
        answer("No")
    else:
        answer("Yes")


Measured memory_bytes: 15108
MOD = 10**9 +7
S = input().rstrip()
A = 0
B = 0
C = 0
X = 1
for s in S:
    if s=="?":
        C=B + C*3
        B=A + B*3
        A=X + A*3
        X *= 3
    else:
        if s=="A":
            A+=X
        if s=="B":
            B+=A
        if s =="C":
            C+=B
    X %= MOD
    A %= MOD
    B %= MOD
    C %= MOD
print(C)

Measured memory_bytes: 73244
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	os << v[0];
	for (int i = 1; i < v.size(); i++) os << " " << v[i];
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u; return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}


void Main() {
	ll N; cin >> N;
	ll minv = LLINF;
	for (ll i = 1; i * i <= N; i++) {
		if (N % i) continue;
		chmin(minv, i + N/i);
	}
	cout << minv - 2 << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;
typedef long long ll;

const int M = 2e5 + 10, N = 1e5 + 10;

int n, m, x, y;
struct pas {
  int y, nxt;
} g[M << 1];

int h[N], tot;
bool vis[N];
int f[N];
int t1, t2, t3;

void cover(int x) {
  vis[x] = 1;
  for (int i = h[x]; i; i = g[i].nxt)
    if (!vis[g[i].y]) cover(g[i].y);
}

bool dfs(int x) {
  vis[x] = 1;
  bool ret = 1;
  int i;
  for (i = h[x]; i; i = g[i].nxt)
    if (!vis[g[i].y]) {
      f[g[i].y] = f[x] ^ 1;
      if (!dfs(g[i].y)) {
        ret = 0;
        break;
      }
    } else if (f[g[i].y] == f[x]) {
      ret = 0;
      break;
    }
  for (; i; i = g[i].nxt) cover(g[i].y);
  return ret;
}

int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &x, &y);
    g[++tot] = pas{y, h[x]};
    h[x] = tot;
    g[++tot] = pas{x, h[y]};
    h[y] = tot;
  }
  for (int i = 1; i <= n; i++) {
    if (!h[i])
      t1++;
    else if (!vis[i]) {
      if (dfs(i))
        t2++;
      else
        t3++;
    }
  }
  ll ans;
  ans = 1ll * t1 * t1 + 2ll * t1 * (n - t1) + 2ll * t2 * t2 + 2ll * t2 * t3 +
        1ll * t3 * t3;

  printf("%lld", ans);
}


Measured memory_bytes: 5248
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  int N; double L, T; std::cin >> N >> L >> T;
  std::vector<double> x(N), v(N), a(N);
  T -= 1.0/16.0;
  for(int i = 0; i < N; ++i) {
    int X, W; std::cin >> X >> W;
    x[i] = X;
    if(W == 1) {
      v[i] = 1.0;
      a[i] = std::fmod(x[i] + T, L);
    } else {
      v[i] = -1.0;
      a[i] = std::fmod(x[i] - T, L);
      a[i] = std::fmod(a[i]+L, L);
    }
  }
  double p0 = a[0];
  std::sort(a.begin(), a.end());
  int n0 = 0;
  if(v[0] > 0) {
    for(int i = 1; i < N; ++i) if(v[0]+v[i] == 0) {
      if(T+T > x[i]-x[0]) {
        double t = T+T-(x[i]-x[0]);
        (n0 += 1+int(t/L)) %= N;
      }
    }
  } else for(int i = 1; i < N; ++i) if(v[0]+v[i] == 0) {
    if(T+T > L - (x[i]-x[0])) {
      double t = T+T-(L-(x[i]-x[0]));
      (n0 -= 1+int(t/L)) %= N;
      (n0 += N) %= N;
    }
  }
  int i0 = std::lower_bound(a.begin(), a.end(), p0) - a.begin();
  (i0 += N-n0) %= N;
  for(int i = 0; i < N; ++i) {
    std::cout << int(a[(i0+i)%N]+1.0/8.0)%(int)L << "\n";
  }
  return 0;
}


Measured memory_bytes: 3584
N = int(input())
e = list(map(int,input().split()))
mod = 1000000007
kai = [0]*(N+3)
from collections import Counter
c = Counter(e).most_common(1)[0][0]
g = e.index(c)
e.remove(c)
f = e.index(c) +1
e = []
for i in range(N+3):
  if i ==0:
    kai[i] = 1
  else:
    kai[i] = (kai[i-1]*(i))%mod
def comb(n,k,p):
  if n<0 or k<0 or n<k: return 0
  if n==0 or k==0: return 1
  a=kai[n] 
  b=kai[k] 
  c=kai[n-k] 
  b = pow(b,mod-2,mod)
  c = pow(c,mod-2,mod)
  return (a*b*c)%mod
h = [1]*((N+6)//2)
for j in range((N+4)//2):
  h[j+1] = comb(N+1,j+1,mod)
for j in range(N+1):
  if N-j>N/2:
    print((h[j+1]-comb(g+N-f,j,mod)+mod)%mod)
  else:
    print((h[N-j]-comb(g+N-f,j,mod)+mod)%mod)

Measured memory_bytes: 19692
#include <cstdio>

typedef long long int ll;

int main(){

    ll N,D;
    int c=0;
    scanf("%lld%lld",&N,&D);
    for(ll i=0;i<N;i++){
        ll x,y;
        scanf("%lld%lld",&x,&y);
        if (x*x+y*y<=D*D) c++;
    }

    printf("%d\n",c);

    return 0;
}

Measured memory_bytes: 1736
from collections import deque
n, m = map(int, input().split())
to = [[] for _ in range(n)]
for i in range(m):
    a, b = [int(i) - 1 for i in input().split()]
    to[a].append(b)
    to[b].append(a)

dist = [0] + [-1] * (n - 1)
pre = [-1] * n
search = deque([0])
while search:
    v = search.popleft()
    for u in to[v]:
        if dist[u] != -1:
            continue
        dist[u] = dist[v] + 1
        pre[u] = v
        search.append(u)

print('Yes')
for i in range(1, n):
    print(pre[i] + 1)

Measured memory_bytes: 35060
#define _CRT_SECURE_NO_WARNINGS
#define _SCL_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <utility>
#include <algorithm>
#include <functional>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <limits>
#include <numeric>
#include <valarray>
#include <fstream>

using namespace std;
typedef unsigned int uint;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL, LL> PP;
#define REP(i, a, n) for(LL i = (a), i##_max = (n); i < i##_max; ++i)
#define REM(i, a, n) for(LL i = (LL)(n) - 1, i##min = (a); i >= i##min; --i)
#define ALL(arr) (arr).begin(), (arr).end()
#define FLOAT fixed << setprecision(16)
#define SPEEDUP {cin.tie(NULL); ios::sync_with_stdio(false);}
const int INF = 0x3FFFFFFF;
const LL INFLL = 0x3FFFFFFF3FFFFFFF;
const double INFD = 1.0e+308;
const double EPS = 1.0e-9;

void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
template <class T, class U>
istream& operator>>(istream& ist, pair<T, U>& right) { return ist >> right.first >> right.second; }
template <class T, class U>
ostream& operator<<(ostream& ost, const pair<T, U>& right) { return ost << right.first << ' ' << right.second; }
template <class T, class TCompatible, size_t N>
void Fill(T(&dest)[N], const TCompatible& val) { fill(dest, dest + N, val); }
template <class T, class TCompatible, size_t M, size_t N>
void Fill(T(&dest)[M][N], const TCompatible& val) { for (int i = 0; i < M; ++i) Fill(dest[i], val); }
template<class T>
T Compare(T left, T right) { return left > right ? 1 : (left < right ? -1 : 0); }
istream& Ignore(istream& ist) { string s; ist >> s; return ist; }
bool Inside(int i, int j, int h, int w) { return i >= 0 && i < h && j >= 0 && j < w; }
template <class T>
T Next() { T buf; cin >> buf; return buf; }

#ifdef ONLY_MY_ENVIR
#include "IntMod.h"
#include "BinaryMatrix.h"
#include "BIT.h"
#include "Factorization.h"
#include "FlowSolver.h"
#include "Graph.h"
#include "LazySegmentTree.h"
#include "Math.h"
#include "Matrix.h"
#include "MinMax.h"
#include "Position.h"
#include "Range.h"
#include "Rational.h"
#include "SegmentTree.h"
#include "SegmentTree2D.h"
#include "SuffixArray.h"
#include "Tree.h"
#include "UnionFind.h"
#endif

#ifdef __GNUC__
typedef __int128 LLL;
istream& operator>> (istream& ist, __int128& val) { LL tmp;  ist >> tmp; val = tmp; return ist; }
ostream& operator<< (ostream& ost, __int128 val) { LL tmp = val; ost << tmp; return ost; }
#endif

#if 1234567891
#include <array>
#include <random>
#include <unordered_set>
#include <unordered_map>
template<typename T>
using PriorityQ = priority_queue<T, vector<T>, greater<T> >;
// template <class T>
// auto Is(const T& value) { return [value](const auto& comparand) -> bool { return comparand == value; }; }
#endif

int main() {
	LL r, d, x;
	cin >> r >> d >> x;

	REP(i, 0, 10) {
		x = r * x - d;
		cout << x << endl;
	}

	return 0;
}

Measured memory_bytes: 256
N,Q = map(int,input().split())
s = input()

t = [0] * (N +1)


for i in range(N):
    t[i+1] = t[i] + (1 if s[i:i+2]=="AC" else 0)



for i in range(Q):
    l, r = map(int, input().split())
    print(t[r-1] - t[l-1])

Measured memory_bytes: 50780
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
  int N;
  int A[200000];

  cin >> N;

  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  sort(A, A+N);

  for (int i = 0; i < N-1; i++) {
    if (A[i] == A[i+1]) {
      printf("NO\n");
      return 0;
    }
  }
  printf("YES\n");
}


Measured memory_bytes: 1024