akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
 
 


//c++ templte for help............................................................................................................................................

typedef long long ll;

template<typename... T>
void print1(T... t){
	((cout<<t<<" "),...);
}

template<typename... T>
void print2(T... t){
		vector<vector<ll>> ans={t...};
		for(ll i=0;i<(ll)ans.size();i++){
			if(i!=0) cout<<"\t\t";
			else cout<<"\t";
			for(ll j=0;j<(ll)ans[i].size();j++){
				cout<<ans[i][j]<<" ";
			}
			if(i!=(ll)ans.size()-1)
			cout<<endl;
		}
}	
#define deb(...) {cout<<" [ "#__VA_ARGS__<<" : "; print1(__VA_ARGS__); cout<<"]"<<endl; }
#define vdeb(...) {cout<<" [ "#__VA_ARGS__<<" : "; print2(__VA_ARGS__); cout<<"]"<<endl;}

// to return everything in string
#define ret(...) {stringstream returnn;returnn<<__VA_ARGS__;return returnn.str();}

stringstream retvec;
template<typename... T>
void returnvector(T... t){
		vector<vector<ll>> ans={t...};
		for(ll i=0;i<(ll)ans.size();i++){
			for(ll j=0;j<(ll)ans[i].size();j++){
				retvec<<ans[i][j];
				if(j!=(ll)ans[i].size()-1)
					retvec<<" ";
			}
			if(i!=(ll)ans.size()-1)
				retvec<<endl;
		}
}
#define vret(...) {returnvector(__VA_ARGS__);return retvec.str();}
	


//for loop
#define fo(i,n) for(int i=0;i<(ll)n;i++)
#define Fo(i,k,n) for(int i=k;i<n;i++)
 
 
//to print vector element 
template<typename T>
void printV(T vec){
	fo(i,vec.size()) cout<<vec[i]<<" "<<flush;
	cout<<endl;
	}
	
 
#define M ll(1e9+7)
const ll INF=ll(1e9+5);
 
//iterate map
template<typename T>
void itR(T map){
	 for(auto itr=map.begin();itr!=map.end();itr++){
				deb(itr->first,itr->second);
			}
	cout<<endl;
}

//c++ template for help...........................................................................................................................................

string solve(){
	ll n;
	cin>>n;
	
	vector<pair<ll,ll>> vec(n);
	fo(i,n){
		ll a,b;
		cin>>a>>b;
		
		vec[i]={a,b};
	}
	
	ll cnt=0;
	fo(i,n){
		if(vec[i].first==vec[i].second) cnt++;
		else cnt=0;
		if(cnt==3) ret("Yes");
	}
	ret("No");
}

int main() {
	cout<<setprecision(10);
	ios::sync_with_stdio(0);
	cin.tie(0);

	//ll testCase;
	//cin>>testCase;
	//for(ll tt=0;tt<testCase;tt++){
		string ans1=solve();
		if(ans1!="")
			cout<<ans1<<endl;
	//}
	return 0;
}


Measured memory_bytes: 3472
#include <stdio.h>
#include <unistd.h>

int main(void)
{
  long long int a, b, v, w, t;
  scanf("%lld%lld%lld%lld%lld", &a, &v, &b, &w, &t);
  if (a > b)
  {
      if ((v - w) * t >= (a - b))
        printf("YES");
    else
    printf("NO");
    
  }
  else
  {
         if ((v - w) * t >= (b - a))
        printf("YES");
    else
    printf("NO");
       
  }
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
int dx[] = {-1,-1,0,1,1,1,0,-1};
int dy[] = {0, 1, 1, 1, 0, -1, -1, -1};
int h, w;
char s[51][51];
int  a[51][51];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
   
    
    scanf("%d %d", &h, &w);
    
    for (int i = 0; i < h; i++)
        scanf("%s", s[i]);
    
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            int count = 0;
            if (s[i][j] != '#') {
                for (int k = 0; k < 8; k++) {
                    int nx = i + dx[k];
                    int ny = j + dy[k];
                    if (0 <= nx && nx < h && 0 <= ny && ny < w && s[nx][ny] == '#')
                        count++;
                }
                a[i][j] = count;
            } else {
                a[i][j] = -10;
            }
        }
    }
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++)
            if (a[i][j] < 0)
                printf("#");
            else
                printf("%d", a[i][j]);
        printf("\n");
    }
    
    
    
    
    return 0;
}


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

int main() {
  int a, b;
  cin >> a >> b;
  if (a == b) cout << "Draw" << endl;
  if (a > b && b != 1) cout << "Alice" << endl;
  if (a < b && a != 1) cout << "Bob" << endl;
  if (a == 1 && b != 1) cout << "Alice" << endl;
  if (b == 1 && a != 1) cout << "Bob" << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics;
public class MainClass
{
	public const long Giri = 1000000007;
	public const long DpInf = 99999999999999;
	
	public static void Main(string[] args)
	{
		var n = Console.ReadLine().ToInt();
		var map = new Dictionary<string, int>();
		map.Add("AC", 0);
		map.Add("WA", 0);
		map.Add("TLE", 0);
		map.Add("RE", 0);
		for(int i = 0; i < n; i++)
		{
			map[Console.ReadLine()]++;
		}
		foreach(var k in map.Keys)
		{
			Console.WriteLine("{0} x {1}", k, map[k]);
		}
		
	}
	
	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str, int offset = 0)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset;
		return r;
	}
}

Measured memory_bytes: 31000
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	vector<int> nums;
	int tmp;
	int ans =0;

	for(int i=0;i<3;i++){
		cin >> tmp;
		nums.push_back(tmp);
	}
	sort(nums.begin(),nums.end());
	
	tmp = nums[1] - nums[0];
	if(tmp % 2 == 1) ans += ((tmp+1)/2) +1;
	else ans += (nums[1] - nums[0])/2;

	ans += nums[2] -nums[1];

	cout << ans << "\n";
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  int D=N%10;
  int C=(N-D)%100/10;
  int B=(N-D-C*10)%1000/100;
  int A=(N-D-C*10-B*100)/1000;
  if(A+B+C+D==7){
    cout << A << "+" << B <<"+" << C << "+" << D << "=7" << endl;
    return 0;
  }else if(A+B+C-D==7){
    cout << A << "+" << B <<"+" << C << "-" << D << "=7" << endl;
    return 0;
  }else if(A+B-C+D==7){
    cout << A << "+" << B << "-" << C << "+" << D << "=7" << endl;
    return 0;
  }else if(A-B+C+D==7){
    cout << A << "-" << B << "+" << C << "+" << D << "=7" << endl;
    return 0;
  }else if(A+B-C-D==7){
    cout << A << "+" << B << "-" << C << "-" << D << "=7" << endl;
    return 0;
  }else if(A-B+C-D==7){
    cout << A << "-" << B << "+" << C << "-" << D << "=7" << endl;
    return 0;
  }else if(A-B-C+D==7){
    cout << A << "-" << B << "-" << C << "+" << D << "=7" << endl;
    return 0;
  }else if(A-B-C-D==7){
    cout << A << "-" << B << "-" << C << "-" << D << "=7" << endl;
    return 0;
  }
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}

int n,a,b;

int main(){
	cin >> n >> a >> b;
	if(abs(n-a) < abs(n-b))cout << "A" << endl;
	else cout << "B" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
    using namespace std;
    #define vi vector<int>
    #define pii pair<int,int>
    #define vp  vector<pii>
    #define fi first
    #define se second
    #define mp make_pair
    #define pb push_back
    #define ls l,mid,rt<<1
    #define rs mid+1,r,rt<<1|1
    #define de(x) cout<< #x<<" = "<<x<<endl
    #define dd(x) cout<< #x<<" = "<<x<<" "
    #define sf scanf
    #define pf printf
    #define all(x) (x).begin(),(x).end()
    #define SZ(x) ((int)(x).size())
    #define rep(i,a,n) for (int i=a;i<n;i++)
    #define per(i,a,n) for (int i=n-1;i>=a;i--)
    typedef long long ll;
    typedef unsigned long long ull;
    //typedef __int128 INT128;
    //INT128 read(){
    //    INT128 x=0,f=1;
    //    char ch=getchar();
    //    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    //    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    //    return x*f;
    //}
    //void write(INT128 x){
    //    if(x<0){putchar('-');x=-x;}
    //    if(x<10){putchar(x+'0'); return;}
    //    write(x/10);putchar(x%10+'0');
    //}
    typedef long double ld;
    const int INF=0x3f3f3f3f;
    const double eps=1e-8;
    const double PI=acos(-1.0);
    const int MAXN=1e5+5;
    const int MAXM=2e6+5;
    const int MOD=1e9+7;
    int sgn(double x){if(fabs(x)<eps)return 0;if(x<0)return -1;else return 1;}
    ll pw(ll a,ll n,ll mod){ll ret=1;while(n){if(n&1)ret=ret*a%mod;a=a*a%mod;n>>=1;}return ret;}
    ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
    ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
    void inc(ll &a,ll b){a+=b;if(a>=MOD)a-=MOD;}
    void dec(ll &a,ll b){a-=b;if(a<0)a+=MOD;}
    int mul(int x, int y){ll z=1ll*x*y;return z-z/MOD*MOD;}
    //head
     
    int n,ta,tb,pos_a[MAXN],pos_b[MAXN],pos[MAXN];
    string s,ans,dp[MAXN];
    int main(){
        cin>>n>>s; ta=tb=0;
        rep(i,0,2*n){
            if(s[i]=='a')pos_a[++ta]=i,pos[i]=ta;
            else pos_b[++tb]=i,pos[i]=tb;
        }
        per(i,1,n+1){
            if(pos_a[i]<pos_b[i]){
                int k=i;
                rep(j,pos_a[i]+1,pos_b[i])k=max(k,pos[j]);
                dp[i]="ab"+dp[k+1];
            }else{
                int k=i;
                while(k<n&&pos_b[k+1]<pos_a[k])k++;
                rep(j,pos_b[i],2*n)if(pos[j]>=i&&pos[j]<=k)dp[i]+=s[j];
                //de(k);
                dp[i]+=dp[k+1];
            }
            //dd(i); de(dp[i]);
            dp[i]=max(dp[i],dp[i+1]);
            ans=max(ans,dp[i]);
        }
        cout<<ans<<endl;
    }

Measured memory_bytes: 15360
#include<bits/stdc++.h>
using namespace std;
const int N=5005;
char s[N];
int k;
vector<string>v;
int main()
{
    scanf("%s",s+1);
    scanf("%d",&k);
    int n=strlen(s+1);
    for(int i=1;i<=n;i++)
    {
        string ans="";
        for(int j=i;j<=min(i+4,n);j++)
        {
            ans+=s[j];
            v.push_back(ans);
        }
    }
    sort(v.begin(),v.end());
    int rk=1;
    if(k==1) cout<<v[0]<<endl;
    else
        for(int i=1;i<v.size();i++)
    {
        if(v[i]!=v[i-1]) rk++;
        if(rk==k)
        {
            cout<<v[i]<<endl;return 0;
        }
    }
}


Measured memory_bytes: 1660
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s,t;
  int a,b;
  cin >> s >> t;
  cin >> a >> b;
  string u;
  cin >> u;
  if(s==u){
    cout << a-1 << " " << b << endl;
  }else{
    cout << a << " " << b-1 << endl;
  }
}

    
     
    


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#define DEBUG
#define REP(i, nn ) for(int i = 0 ; i < (int) nn; i++)
#define deb(x) std::cout << #x << " " << x << endl;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
template<typename... T>
void read(T& ... a){
    ((cin >> a),...);
}
template<typename... T>
void write(T... a){
    ((cout << a << "\n"),...);
}

template<typename... T>
void write_space(T... a){
    ((cout << a << " "),...);
}

void solve(){
    ll a, b, c, d;
    read(a, b, c, d);
    ll ans = max({a * c, a * d, b * c , b * d});
    cout << ans << endl;
}

int main()
{
    //making data IO Fast
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    /****************************/
    solve();
    return 0;
}



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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
	ll N, M; cin >> N >> M;
	ll Scc;
	if(2 * N >= M) {
		Scc = M / 2;
	}
	else if(N < 2 * M) {
		Scc = N;
		M -= 2 * N;
		Scc += M / 4;
	}
	cout << Scc << endl;
	return 0;
}

Measured memory_bytes: 3584
#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<int> p(n),q(n);
   rep(i,n) cin >> p[i];
   rep(i,n) cin >> q[i];
   vector<int> a(n);
   rep(i,n) a[i] = i+1;

   map<vector<int>,int> mp;
   do{
      mp[a] = mp.size();
   }while(next_permutation(a.begin(),a.end()));

   int ans = abs(mp[p]-mp[q]);  

   cout << ans << endl;
   return 0;  
}

Measured memory_bytes: 8648
import heapq
T = int(input())

hpush = heapq.heappush
hpop = heapq.heappop
for _ in [0]*T:
    ans = 10**18
    N,A,B,C,D = map(int,input().split())
    hq = [(0,N)]
    made = set()
    while hq:
        cost,n = hpop(hq)
        if n==0:
            ans = min(ans,cost)
            continue
        if n in made:continue
        made.add(n)

        n2 = n//2
        cost2 = cost + min(D*(n-n2),A+D*(n%2))
        hpush(hq,(cost2,n2))

        n2b = (n-1)//2+1
        cost2b = cost + min(D*(n-n2b),A+D*((-n)%2))
        hpush(hq,(cost2b,n2b))

        n3 = n//3
        cost3 = cost + min(D*(n-n3),B+D*(n%3))
        hpush(hq,(cost3,n3))

        n3b = (n-1)//3+1
        cost3b = cost + min(D*(n-n3b),B+D*((-n)%3))
        hpush(hq,(cost3b,n3b))

        n5 = n//5
        cost5 = cost + min(D*(n-n5),C+D*(n%5))
        hpush(hq,(cost5,n5))
        
        n5b = (n-1)//5+1
        cost5b = cost + min(D*(n-n5b),C+D*((-n)%5))
        hpush(hq,(cost5b,n5b))

    print(ans)


Measured memory_bytes: 146212
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1000000007;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

void extend(int c, vector<int> &cnt, int &tmp){
    if(++cnt[c] == 1) ++tmp;
}

void shrink(int c, vector<int> &cnt, int &tmp){
    if(--cnt[c] == 0) --tmp;
}

int main(){
    int n, q;
    scanf("%d%d", &n, &q);
    int c[n];
    rep(i, n) scanf("%d", &c[i]), --c[i];
    vector<tuple<int, int, int>> query(q); // (id, [l, r))
    rep(i, q){
        int l, r;
        scanf("%d%d", &l, &r);
        --l;
        query[i] = {i, l, r};
    }

    int width = 700;
    sort(query.begin(), query.end(), [&](const tuple<int, int, int> &a, const tuple<int, int, int> &b){
        if(get<1>(a) / width == get<1>(b) / width){
            return (get<1>(a) / width) % 2 == 0 ? get<2>(a) < get<2>(b) : get<2>(a) > get<2>(b);
        }
        return get<1>(a) / width < get<1>(b) / width;
    });

    vector<int> cnt(n, 0);
    int tmp = 0, tl = 0, tr = 0, ans[q];
    for(auto [id, l, r]: query){
        while(tr < r) extend(c[tr++], cnt, tmp);
        while(tl > l) extend(c[--tl], cnt, tmp);
        while(tr > r) shrink(c[--tr], cnt ,tmp);
        while(tl < l) shrink(c[tl++], cnt, tmp);
        ans[id] = tmp;
    }
    rep(i, q) printf("%d\n", ans[i]);
}

Measured memory_bytes: 15404
import sys
import math
import string
import fractions
import random
from operator import itemgetter
import itertools
from collections import deque
import copy
import heapq
from bisect import bisect, bisect_left, bisect_right

MOD = 10 ** 9 + 7
INF = float('inf')
input = lambda: sys.stdin.readline().strip()

sys.setrecursionlimit(10 ** 8)

H, W, K = map(int, input().split())
S = [list(map(int, list(input()))) for _ in range(H)]
ans = INF
for i in range(2 ** (H - 1)):
    p = deque()
    for j in range(H - 1):
        if (i >> j) & 1:
            p.append(j + 1)
    num = len(p)
    if len(p) == 0:
        check = 0
        for j in range(W):
            temp_sum = sum([S[l][j] for l in range(H)])
            if temp_sum > K:
                num = INF
            if check + temp_sum > K:
                check = temp_sum
                num += 1
            else:
                check += temp_sum
    else:
        p.appendleft(0)
        p.append(H)
        check = [0] * (len(p) - 1)
        for j in range(W):
            for l in range(len(p) - 1):
                if p[l + 1] - p[l] == 1:
                    check[l] += S[l][j]
                else:
                    temp_sum = sum([S[t][j] for t in range(p[l], p[l + 1])])
                    if temp_sum > K:
                        num = INF
                        break
                    check[l] += temp_sum
            for l in check:
                if l > K:
                    num += 1
                    for k in range(len(p) - 1):
                        if p[k + 1] - p[k] == 1:
                            check[k] = S[k][j]
                        else:
                            temp_sum = sum([S[t][j] for t in range(p[k], p[k + 1])])
                            if temp_sum > K:
                                num = INF
                            check[k] = temp_sum
                    break
    if num < ans:
        ans = num
print(ans)


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    string S;
    cin >> S;
    vector<ll> R, L;
    ll N = S.size();
    rep(i, N) {
        if (S[i] == 'R') {
            R.push_back(i);
        } else {
            L.push_back(i);
        }
    }
    vector<ll> ans(N, 0);
    rep(i, N) {
        if (S[i] == 'R') {
            ll idx = *lower_bound(L.begin(), L.end(), i);
            if (abs(idx - i) % 2) {
                ans[idx - 1]++;
            } else {
                ans[idx]++;
            }
        } else {
            ll idx = *(lower_bound(R.begin(), R.end(), i) - 1);
            if (abs(idx - i) % 2) {
                ans[idx+1]++;
            } else {
                ans[idx]++;
            }
        }

    }
    rep(i, N) {
        cout << ans[i] << ' ';
    }
}

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


Measured memory_bytes: 2372
import sys

n = int(sys.stdin.read())
n -= 1
s = 'abcdefghijklmnopqrstuvwxyz'
write = sys.stdout.write
a = []
append = a.append
while n >= 26:
  n, v = divmod(n, 26)
  n -= 1
  append(s[v])
append(s[n])
a.reverse()
print(''.join(a))


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

int main(){
	int a[5];
  	int n;
  	for(int i = 0; i<5; i++)
      cin >> a[i];
  	cin >> n;
  	if(a[4] - a[0] <= n)
      cout << "Yay!" << endl;
  	else
      cout << ":(" << endl;
  	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cassert>
#include <bitset>

//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;

//std::cout << std::fixed << std::setprecision(10)
//std::ios::sync_with_stdio(false);
constexpr long long MOD = 1000000007;

int dx[] = { 0, 1, 0, -1};
int dy[] = {-1, 0, 1,  0};

int main()
{
  int N, K;
  std::cin >> N >> K;
  std::vector<int> p(N);
  for(auto& val: p)
    std::cin >> val;
  double ans = 0.0;
  auto expect = [](int n)
  {
    return ((double)(((n + 1)*n)/2)) / n;
  };
  for(int i = 0; i < K; ++i)
  {
    ans += expect(p[i]);
  }
  double tmp = ans;
  for(int i = K; i < N; ++i)
  {
    tmp -= expect(p[i - K]);
    tmp += expect(p[i]);
    ans = std::max(ans, tmp);
  }
  std::cout << std::fixed << std::setprecision(10) << ans << std::endl;
  return 0;
}



Measured memory_bytes: 1024
N, Q = (int(i) for i in input().split())
S = input()
L = []
for i in range(Q):
    t, d = (i for i in input().split())
    L.append((t,d))

def func(k):
    now = k
    for t, d in L:
        if S[now] == t:
            if d == "R":
                now += 1
            else:
                now -= 1
        if now < 0:
            return "l"
        elif now >= N:
            return "r"
    if now < 0:
        return "l"
    elif now >= N:
        return "r"
    else:
        return None
ans = 0
left = 0
right = N
while True:
    if left >= right:
        break
    opt = (left + right)//2
    if func(opt) == "l":
        left = opt + 1
    else:
        right = opt
ans += right

left = 0
right = N
while True:
    if left >= right:
        break
    opt = (left + right)//2
    if func(opt) == "r":
        right = opt
    else:
        left = opt + 1
ans += (N - left)

print(N - ans)

Measured memory_bytes: 91596
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>

#define rep(i,n) for(long long i=0;i<n;i++)
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> x(N), y(N);
  priority_queue<pair<int, int>> vec;
  //vector<vector<vector<int>>> vec(N, vector<vector<int>>(N, vector<int>(2,0)));// N x N x 2
  
  if(N==1) {
    cout << 1 << endl;
    return 0;
  }
  
  rep(i, N) {
    cin >> x[i] >> y[i];
    //cout << x[i] << y[i];
  }
  
  int tmpx = 0;
  int tmpy = 0;
  for(int i=0; i<N; i++) {
    for(int j=i+1; j<N; j++) {
      tmpx = x[i] - x[j];
      if(tmpx>0) { // xが正
        vec.push(make_pair(tmpx, y[i]-y[j]));
      } else if(tmpx==0){ // tmpx がゼロ なら y が正になるようにする．
        tmpy = y[i]-y[j];
        if(tmpy>0) vec.push(make_pair(tmpx, y[i]-y[j]));
        else vec.push(make_pair(-tmpx, -y[i]+y[j]));
      } else { // tmpx が負: xが正になるようにする．
        vec.push(make_pair(-tmpx, -y[i]+y[j]));
      }
      // cout << tmp << endl;
    }
  }
  
  int cnt = 0;
  int maxcnt = 0;
  pair<int, int> tmp_p = make_pair(0, 0);
  int vecsize = N*(N-1)/2; //vec.size();
  rep(i, vecsize) {
    pair<int, int> p = vec.top();
    vec.pop();
    if(tmp_p.first==p.first && tmp_p.second==p.second) cnt++;
    else {
      if(cnt>maxcnt) maxcnt = cnt;
      tmp_p.first = p.first;
      tmp_p.second = p.second;
      cnt = 0;
    }
  }
  if(cnt>maxcnt) maxcnt = cnt;

  cout << N-maxcnt-1 << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <cctype>
#include <cstring>
#include <set>
#include <map>
#define rep(i, m, n) for (int i = m; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define ll long long
#define ull unsigned long long
#define push(a) push_back(a)
#define pop(a) pop_back(a)
#define debug(x) cout << #x << ": " << x << endl
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};

long a,b;
char op;

int main(){
    cin>>a>>op>>b;
    if(op=='+'){
        cout << a + b << endl;
    }else{
        cout << a - b << endl;
    }
}

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

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

int main(){
    int a,b,c;
    cin >>a >> b >> c;

        for(int i = 1; i<= 100000; i++){
            if(a&1 || b&1 || c&1) {cout << i-1;return 0;}
            int ka=a,kb=b,kc=c;
            a = kb/2 + kc/2;
            b = kc/2 + ka/2;
            c = kb/2 + ka/2;
        }
        cout << -1;


    return 0;
}


Measured memory_bytes: 256
if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))

    n_satisfied = 0
    sum_lr = 0
    xor_lr = 0
    left, length = 0, 0

    while True:
        while left + length != N and \
                sum_lr + A[left + length] == xor_lr ^ A[left + length]:
            sum_lr += A[left + length]
            xor_lr ^= A[left + length]
            length += 1

        n_satisfied += length

        if left == N:
            break

        sum_lr -= A[left]
        xor_lr -= A[left]
        left += 1
        length -= 1

    print(n_satisfied)


Measured memory_bytes: 24840
house = [[[0 for i in range(10)] for i in range(3)] for i in range(4)]
n = int(input())
for i in range(n):
    input_4 = list(map(int,input().split()))
    house[input_4[0]-1][input_4[1]-1][input_4[2]-1] += input_4[3]
for i in range(4):
    for j in range(3):
        print('',' '.join(map(str,house[i][j])))
    if i != 3:
        print('#'*20)

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

namespace program
{
    class Program
    {
        static void Main()
        {
          int[] a = Input.ScanIntArray();
          
          if(a[0]+a[1] > a[2]+a[3])
            Console.WriteLine("Left");
          if(a[0]+a[1] == a[2]+a[3])
            Console.WriteLine("Balanced");
          if(a[0]+a[1] < a[2]+a[3])
            Console.WriteLine("Right");
        }
    }

    static class Input
    {
        static public int ScanInt() { return int.Parse(Console.ReadLine()); }
        static public uint ScanUint() { return uint.Parse(Console.ReadLine()); }
        static public double ScanDouble() { return double.Parse(Console.ReadLine()); }
        static public long ScanLong() { return long.Parse(Console.ReadLine()); }
        static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); }
        static public int[] ScanIntArray() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); }
        static public uint[] ScanUintArray() { return Console.ReadLine().Split(' ').Select(x => uint.Parse(x)).ToArray(); }
        static public double[] ScanDoubleArray() { return Console.ReadLine().Split(' ').Select(x => double.Parse(x)).ToArray(); }
        static public long[] ScanLongArray() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); }
        static public ulong[] ScanUlongArray() { return Console.ReadLine().Split(' ').Select(x => ulong.Parse(x)).ToArray(); }

        static public string ScanStr() { return Console.ReadLine(); }
        static public string[] ScanStrArray() { return ScanStr().Split(' '); }
    }

    static class MyMath
    {
        public static int GCD(int a, int b)
        {
            Func<int, int, int> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static ulong GCD(ulong a, ulong b)
        {
            Func<ulong, ulong, ulong> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static int LCM(int a, int b)
        {
            return a * b / GCD(a, b);
        }
        public static ulong LCM(ulong a, ulong b)
        {
            return a * b / GCD(a, b);
        }
    }
}


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

int main() {
    int n, m;
    cin>>n>>m;
    int a[n];
    for(int i = 0;i<n;i++) {
        cin>>a[i];
    }

    int dp[n];
    for(int i = 0;i<n;i++) {
        dp[i] = INT_MAX;
    }
    
    dp[0] = 0;
    
    for(int i = 0;i<n;i++) {
        for(int j = 1;j<=m;j++) {
            if(i - j >= 0) {
                dp[i] = min(dp[i], abs(a[i] - a[i-j]) + dp[i-j]);
            }
        }
    }
    
    cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define FOR0(i,n) for(ll i=0;i<n;i++)
#define FOR1(i,n) for(ll i=1;i<=n;i++)
#define FORl(i,l,n) for(int i=l;i<n;i++)
using namespace std;
#define pi pair<ll,ll>
#define pb push_back
#define ll long long
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define mst0(x) memset(x,0,sizeof(x));
#define vi vector<ll>
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define sp <<" "<<
#define intmax 1e14
ll power(ll num,ll g,ll mod){
  if(g==0)return 1;
  if(g%2==1)return (num*power((num*num)%mod,g/2,mod))%mod;
  return power((num*num)%mod,g/2,mod);
}

int main(){
	int n;
	cin>>n;
	int a[n],b[n],c[n];
	FOR0(i,n) cin>>a[i]>>b[i]>>c[i];
	ll dp1[n],dp2[n],dp3[n];
	mst0(dp1);
	mst0(dp2);
	mst0(dp3);
	dp1[0] = a[0];
	dp2[0] = b[0];
	dp3[0] = c[0];
	//dp[0] = 0, dp[1] = abs(a[1]-a[0]);
	//int ans = INT_MAX;
	FORl(i,1,n) {
		dp1[i] = a[i]+max(dp2[i-1],dp3[i-1]);
		dp2[i] = b[i]+max(dp1[i-1],dp3[i-1]);
		dp3[i] = c[i]+max(dp1[i-1],dp2[i-1]);
	}
	//FOR0(i,n) cout<<i sp dp[i] <<" ";
	//cout<<endl;
	cout<<max(dp2[n-1],max(dp1[n-1],dp3[n-1]));
}




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

#define rep(i,c) for(int i = 0; i < (int)c; ++i)
using llint = long long int ;
using namespace std;


int main(){
    int N;
    cin>>N;
    vector<vector<int>> v(N);
    rep(i,N-1){
        int a,b;
        cin>>a>>b;
        v[a-1].push_back(b-1);
        v[b-1].push_back(a-1);
    }
    
    vector<int> dist(N,-1);
    dist[0]=0;
    queue<int> que;
    que.push(0);


    while (!que.empty())
    {
        int x=que.front();
        que.pop();
        for (auto e:v[x])
        {
            if(dist[e]==-1){
                que.push(e);
                dist[e]=dist[x]+1;
            }
        }
    }
    int count=0;
    rep(i,N){
        if(dist[i] %2==1) count++;
    }
    
    int ans[N];
    int bai3=3;
    int amari1=1;
    int amari2=2;
    if(count<=(N/3)){
        rep(i,N){
            if(dist[i]%2==1){
                ans[i]=bai3;
                bai3+=3;
            }
            else{
                if(amari1>N&&amari2>N){
                    ans[i]=bai3;
                    bai3+=3;
                }
                else if(amari1>N){
                    ans[i]=amari2;
                    amari2+=3;
                }
                else{
                    ans[i]=amari1;
                    amari1+=3;
                }
            }
        }
    }

    else if( (N-count) <= (N/3) ){
        rep(i,N){
            if(dist[i]%2==0){
                ans[i]=bai3;
                bai3+=3;
            }
            else{
                if(amari1>N&&amari2>N){
                    ans[i]=bai3;
                    bai3+=3;
                }
                else if(amari1>N){
                    ans[i]=amari2;
                    amari2+=3;
                }
                else{
                    ans[i]=amari1;
                    amari1+=3;
                }
            }
        }
    }

    else{
        rep(i,N){
            if(dist[i]%2==1){
                if(amari1<=N){
                    ans[i]=amari1;
                    amari1+=3;
                }
                else{
                    ans[i]=bai3;
                    bai3+=3;
                }
            }
            else{
                if (amari2<=N)
                {
                    ans[i]=amari2;
                    amari2+=3;
                }
                else{
                    ans[i]=bai3;
                    bai3+=3;
                }
                
            }
        }
    }

    rep(i,N)cout<<ans[i]<<" ";
    cout<<endl;
    return 0;
}

Measured memory_bytes: 15220
#include <stdio.h>

int main()
{
	int N,M;
	scanf ("%d %d",&N,&M);

	long long a = 1, mod = 1000000007;

	for (int i=1;i<=N;i++) a = a * i % mod;
	for (int i=1;i<=M;i++) a = a * i % mod;

	int d = N - M;
	if (d < 0) d = -d;
	if (d > 1) a = 0;
	else if (d == 0) a = a * 2 % mod;
	printf ("%lld\n",a);

	return 0;
}

Measured memory_bytes: 128
<?php

class In {

	private $buf = [];
	private $count = 0;
	private $pointer = 0;

	public function nextLine() {
		$ret = '';
		if($this->hasNext()){
			while($this->hasNext()){
				$ret .= $this->next();
			}
		}else{
			$ret = trim(fgets(STDIN));
		}

		return $ret;
	}

	public function next() {
		if(!$this->hasNext()) {
			$str = trim(fgets(STDIN));
			$this->buf = explode(' ',$str);
			$this->count = count($this->buf);
			$this->pointer = 0;
		}

		return $this->buf[$this->pointer++];
	}

	public function hasNext() {
		return $this->pointer < $this->count;
	}

	public function nextInt() {
		return (int)$this->next();
	}

	public function nextDouble() {
		return (double)$this->next();
	}
}

class Out {
	public function println($str = '') {
		echo $str . PHP_EOL;
	}
}

$in = new In();
$out = new Out();


$N = $in->nextInt();
$K = $in->nextInt();

$L = [];
for ($i = 0;$i < $N;$i++){
	$L[] = $in->nextInt();
}

rsort($L);

$out->println(array_sum(array_slice($L,0,$K)));

?>


Measured memory_bytes: 4604
import sys

def input():
  return sys.stdin.readline()[:-1]

def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i:
        divisors.append(n//i)
  divisors.sort(reverse=True)
  return divisors

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

sumA = sum(A)
kouho = make_divisors(sumA)

for i in kouho:
  if sumA%i != 0:
    continue
  r = [0]*N
  for j in range(N):
    r[j] = A[j]%i
  sumr = sum(r)
  if sumr%i != 0:
    continue
  r.sort(reverse=True)
  num = 0
  for k in range(sumr//i):
    num += i-r[k]
  if num <= K:
    print(i)
    exit()

Measured memory_bytes: 42476
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int N;
vector<int> v;
int main() {
	cin >> N;
	for (int i = 0; i < N*2; ++i) {
		int a; cin >> a;
		v.push_back(a);
	}
	sort(v.begin(), v.end());
	int sum = 0;
	for (int i = 0; i < N*2; i+=2) {
		sum += v[i];
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstring>
#include <map>
#include <unordered_map>
#include <string>
#include <list>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <iostream>
#include <set>
#include <unordered_set>
using namespace std;

#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int, int> pii;

int gi() {
    int a;
    scanf("%d", &a);
    return a;
}

ll gli() {
    ll a;
    scanf("%lld", &a);
    return a;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a = gi();
    int b = gi();
    int c = gi();
    int k = gi();
    if (k <= a+b) {
        printf("%d\n", MIN(a, k));
    } else {
        printf("%d\n", a - (k-a-b));
    }

    return 0;
}


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

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

    long double sum = 0l;
    for (int i = 0; i < N; i++)
    {
        sum += 1 / A[i];
    }
    cout << setprecision(15) << (long double) 1 / sum << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,a[1000];
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  int x;
  cin>>x;
  for(int i=0;i<x;i++){
    int s,y,z,ans;
    cin>>s>>y>>z;
    if(s==0){ans=*min_element(a+y,a+z);}
    else if(s==1){ans=*max_element(a+y,a+z);}
    cout<<ans<<endl;
  }
    
  
  return 0;
}


Measured memory_bytes: 3052
import java.util.*;

public class Main {
	public static void main(String args[]) {
    	Scanner sc = new Scanner(System.in);
      	int count  = Integer.valueOf(sc.nextLine());
      	String input = sc.nextLine();
      	String inputs[] = input.split(" ");
      	int[] values = new int[count];
      	int ans = 0;
      	for( int i= 0 ; i<count; i++){ 
        	values[i] = Integer.valueOf(inputs[i]);
        }
      	for( int i= 0 ; i<count; i++) 
        {
          	int value = values[i];
        	if(value==(i+1))
            {
             	 if(i!=(count-1))
                {
                  int a  = values[i+1];
                  values[i+1] = values[i];
                  values[i] = values[i+1];
                  
                } else {
                     int a = values[0];
                  	values[0] = values[i];
                  	values[i] = a;
                }
                ans++;    
            }
          	
        }
      System.out.println(ans);	
      
    }
}

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

using namespace std;

int N, M;

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d %d", &N, &M);
printf ("%d\n", (1 << M) * (100 * (N - M) + 1900 * M));

return 0;
}


Measured memory_bytes: 256
import Control.Applicative
import Control.Monad
import Control.Monad.ST
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import qualified Data.Foldable as Foldable
import qualified Data.Set as Set
import qualified Data.Sequence as Sequence
import Data.List.Split
import Data.Bits
import Data.Char
import Data.Ix
import Data.Ratio
import Data.Ord
import Data.Tuple
--import Data.Array
import Data.Array.IArray
--import Data.Array.Unboxed
import Data.Array.MArray
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
-- import System.IO.Unsafe
 
readInt = read :: String -> Int
readInteger = read :: String -> Integer
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
getInteger = readLn :: IO Integer
getIntegers = map readInteger . words <$> getLine
getDouble = readLn :: IO Double
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
apply2 :: (a -> a -> b) -> [a] -> b
apply2 f [x,y] = f x y
apply3 :: (a -> a -> a -> b) -> [a] -> b
apply3 f [x,y,z] = f x y z
apply4 :: (a -> a -> a -> a -> b) -> [a] -> b
apply4 f [x,y,z,w] = f x y z w
fnBin :: (b -> c -> d) -> (a -> b) -> (a -> c) -> a -> d
fnBin op f g x = op (f x) $ g x
fnTuple :: (a -> b, a -> c) -> a -> (b, c)
fnTuple (f,g) a = (f a, g a)
replace :: (Eq a) => a -> a -> [a] -> [a]
replace x y = map (\z -> if z==x then y else z)
modifyArray :: (Ix i, MArray a e m) => a i e -> i -> (e -> e) -> m ()
modifyArray arr ix f = readArray arr ix >>= writeArray arr ix . f
dictCompare :: [a -> a -> Ordering] -> a -> a -> Ordering
dictCompare [] _ _ = EQ
dictCompare (f:fs) x y = let c = f x y in if c==EQ then dictCompare fs x y else c
binMap :: (a -> a -> b) -> [a] -> [b]
binMap f (x:xs@(y:_)) = f x y : binMap f xs
binMap _ _ = []
-- end of templete



main = do
    n <- getInt
    m <- getInt
    as <- getInts
    bs <- replicateM m getInts
    mapM_ print $ map sum $ transpose $ zipWith (\x ys -> [if i==x then 1 + length (filter (/=x) ys) else cond 1 0 (x==y) | (y, i) <- zip ys [1..n]]) as bs


Measured memory_bytes: 6532
s = input()
n = len(s)

rr = [1] * n
ll = [1] * n

for i in range(n - 1):
    if s[i] == s[i + 1] == 'R':
        rr[i + 2] += rr[i]
        rr[i] = 0

for i in range(n - 1, 0, -1):
    if s[i] == s[i - 1] == 'L':
        ll[i - 2] += ll[i]
        ll[i] = 0

ans = [0] * n
for i in range(n):
    ans[i] = rr[i] + ll[i] - 1

print(*ans)

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

int main()
{
  int n;
  unsigned long long int sum = 0;
  sum = 0;
  cin>>n;
  for(int i=1; i<=n; i++){
    if(i%3!=0 && i%5!=0 && i%15!=0){
      sum += i;
    }
  }
  cout<<sum;
  return 0;
}

Measured memory_bytes: 3144
#include <bits/stdc++.h>
#include<cmath>
#define N 100005
#define A 1000005
#define MOD 998244353 //1000000007 // //100000000
#define inf 1000000000000000000
#define ll long long
//#define M_PI 3.141592653589793238463

using namespace std;

#define pii pair<ll, ll>
#define piii pair<ll, pii>
#define ft first
#define sd second
#define pb push_back
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n-1; i >= 0; i--)
#define itr(it, x) for(auto it = x.begin(); it != x.end(); it++)
#define mem(a, b) memset(a, (ll)b, sizeof(a))
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define edge(v, x, y) v[x].pb(y); v[y].pb(x);
#define popcount __builtin_popcount
#define ANS(s) {cout << s << "\n"; return;}

//~~~~~~fancy print~~~~~~~//
#define printpii(a) cout << a.ft << " " << a.sd << endl;
#define printpiii(a) cout << a.ft << " " << a.sd.ft << " " << a.sd.sd << endl;
#define print(a, n) rep(i, n) cout << a[i] << " "; cout << endl;
#define printv(v) for(auto x: v)cout << x << " "; cout << endl;
#define printm(a, n, m) rep(i, n) { rep(j, m) cout << a[i][j] << "\t"; cout << endl;}

ll dx[4] = {0, 0, 1, -1};
ll dy[4] = {1, -1, 0, 0};

void fast(){ios_base::sync_with_stdio(false);cin.tie(0);cout << setprecision(12) << fixed;}


void solve(){
    ll n;
    cin >> n;
    ll dis = inf;

    for(ll i =  1; i <= sqrt(n); i++){
        if(n%i == 0){
            dis = min(dis, i+n/i-2);
        }
    }
    cout << dis;

}
main(){
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    fast();
    ll t = 1; //cin >> t;
    while(t--){
        solve();
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define range(i, l, r) for(int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

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

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    map<char, int> count;
    for (const char c : S) {
        count[c] += 1;
    }
    if (count.size() != 2) {
        cout << "No" << "\n";
        return 0;
    }
    for (const auto p : count) {
        if (p.second != 2) {
            cout << "No" << "\n";
            return 0;
        }
    }
    cout << "Yes" << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
 
#define mod 1000000007
#define FOR(x,to) for(int x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define long long long
inline int rei(){int x;cin>>x;return x;}
inline long rel(){long x;cin>>x;return x;}
inline string res(){string x;cin>>x;return x;}
//------------------------------------------------------- 
void Calc(){
	int N = rei();
	int K = rei();
	if(K * 2 - 1 <= N){
		cout << "YES" << endl;
	}
	else{
		cout << "NO" << endl;
	}
}
int main(int argc,char** argv){
	ios::sync_with_stdio(false), cin.tie(0);
	cout.tie(0); Calc(); return 0;
}

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

using namespace std;

int main(){
    int n;
    int p[200001] = {0};
    cin >> n;
    for(int i = 1; i <= n; ++i) cin >> p[i];

    int min = p[1];
    int cnt = 1;
    for(int i = 2; i <= n; ++i) {
        if(p[i] < min){
            min = p[i];
            ++cnt;
        } 
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 1152
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;

const int INF = 1e9 + 5;

int main() {
	int n; scanf("%d", &n);
	vector<int > h(n);
	for(int& x : h) {
		scanf("%d", &x);
	}
	vector<int > dp(n, INF);
	dp[0] = 0;
	for(int i = 0; i < n; ++i) {
		for(int j : {i + 1, i + 2}) {
			if(j < n) {
				dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]));
			}
		}
	}
	printf("%d\n", dp[n-1]);
	return 0;    
}


Measured memory_bytes: 1024