akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <bits/stdc++.h>
#include<string>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <fstream>
#include <vector>

#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define SPACE " "
#define nLINE '\n'
#define ss second
#define ff first
//scanf("%d",&x) ,s.insert(x);
using namespace std;

ll GCD(ll a, ll b) {
	//Euclidian
	if (!b) return a;
	else return GCD(b, a % b);
}
const ll MAX = 51;
bool prime[MAX];
void sieve() {
	for (int p = 2; p * p <= MAX; p++)
		if (prime[p] == false)
			for (int i = p * 2; i <= MAX; i += p)
				prime[i] = true;
}

int comb(int a, int b)
{
	if (a < b) return 0;
	if (a == b) return 1;
	if (b == 0) return 1;
	return comb(a - 1, b) + comb(a - 1, b - 1);
}
int x[30];
long long int y[30];
long long int func(int s, int t)
{
	if (t == 0) return 1;
	if (s == 0) return 1;

	if (x[s] == 0) return func(s - 1, t);
	else
	{
		long long int sum = 0;
		for (int i = 0;i <= t;i++) sum += comb(s - 1, i) * y[i];

		long long int s1 = sum;

		sum = 0;
		for (int i = 0;i <= t - 1;i++) sum += comb(s - 1, i) * y[i];
		long long int s2 = (x[s] - 1) * sum;
		long long int s3 = func(s - 1, t - 1);
		return s1 + s2 + s3;
	}
}



int dp[13][1 << 13];
double arr[20][20];
int n;
int dvds[13],svs[13];
vector<double> sssp(int);
vector<double> minDis[20];
int Size;

double solve(int current, int mask) {
    if(mask == ((1 << Size) - 1)) return -arr[dvds[current]][0];

    if(dp[current][mask] != -1)
        return dp[current][mask];


    double Max = -arr[dvds[current]][0];
    for(int i= 0; i< Size; i++)
        if((mask & (1 << i)) == 0)
            Max = max(Max, svs[i] - arr[dvds[current]][dvds[i]]+ solve(i, mask | (1 << i)));

    return dp[current][mask]= Max;
}

int nextMin(int,int);
int lis[100001];
int main() {
	int N,x,s=0;
	cin >> N;
    for (int n=1;n<=N;n++){
        cin >> x;
        if(n%2!=0 && x%2 != 0){
            s++;
        }
    }
    cout << s << nLINE;
}

bool used[20];
vector<double> sssp(int src) {
	vector<double> disSource(n);
	fill(disSource.begin(), disSource.end(), INT_MAX);
	disSource[src] = 0;
	int curr = src;
	memset(used, false, sizeof used);
	used[curr] = true;
	while (curr != -1) {
		for (int j = 0;j < n;j++) {
			if (arr[curr][j] != -1) {
				if (disSource[j] == INT_MAX) disSource[j] = arr[curr][j] + disSource[curr];
				else disSource[j] = std::min(disSource[j], disSource[curr] + arr[curr][j]);
			}
		}
		used[curr] = true;
		curr = nextMin(curr,src);
	}
	return disSource;
}

int nextMin(int curr,int src) {
	int indx = -1;
	double Min = 1e9;
	for (int i = 0;i < n;i++) {
		if (arr[curr][i]!=-1 && arr[curr][i] <= Min && used[i] == false) {
			Min = arr[curr][i];
			indx = i;
		}
	}
	if (indx == -1){
        for(int i=0;i<n;i++)
            if(arr[src][i]!=-1 && arr[curr][i] <= Min && used[i]== false)
                indx = i , Min = arr[curr][i];
	}
	if (indx == -1) return -1;
	return indx;
}


Measured memory_bytes: 3560
def main():
    X = int(input())
    L = [False]*1001
    for i in range(1,41):
        for j in range(2,11):
            temp = i**j
            if temp > X:
                break
            L[temp] = True
    m = 0
    for i in range(X+1):
        if L[i]:
            m = i
    print(m)





if __name__ == '__main__':
    main()

Measured memory_bytes: 38256
#include <iostream>
using namespace std;
int main()
{
	int n;
	int a, b=0, c=0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a;
		if (i == 0) {
			b = a;
		}
		else if (a < b) {
			b = a;
			c = i+1;
		}
	}
	cout << c << endl;
}


Measured memory_bytes: 3084
# coding: utf-8
import sys
import math
input = sys.stdin.readline

X = int(input())
val = int(math.sqrt(1000)) + 1

ans = 1
for p in range(2, 10):
    for b in range(1, val):
        tmp = max(ans, pow(b, p))
        if tmp > X:
            break
        ans = tmp
print(ans)

Measured memory_bytes: 3060
/*************************************************************************
  >         File: B.cc
  >       Author: lyyllyyl
  >         Mail: riho.yoshioka@yandex.com
  > Created Time: Sat 24 Sep 2016 08:03:18 PM CST
*************************************************************************/
#include <bits/stdc++.h>
int a[111111];

int main() {
  std::ios::sync_with_stdio(0);
  int n;
  std::cin >> n;
  for (int i = 0; i < n; ++i) {
    std::cin >> a[i];
    a[i]--;
  }
  int cnt = 0;
  for (int i = 0; i < n; ++i) {
    int x = i;
    if (a[a[x]] == x) cnt++;
  }
  assert(cnt % 2 == 0);
  std::cout << cnt / 2 << std::endl;


  return 0;
}


Measured memory_bytes: 768
//R<3S
#include <bits/stdc++.h>
#define hell 1000000007
#define PI 3.14159265358979323844
#define mp make_pair
#define pb push_back
#define fi first 
#define se second
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))  
#define REVERSE(v) reverse(ALL(v))
#define endl "\n"
#define vecmax(v) max_element(all(v))
#define vecmin(v) min_element(all(v))
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) m*(n/GCD(m,n))
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(x) for(auto i : x)
#define sz(a) (int)a.size()
#define sl(a) (int)a.length()
#define int long long
#define ld long double 
#define pii std::pair<int, int> 
#define pll std::pair<ll, ll>  
#define vi vector<int>  
#define vl vector<ll>
#define vvi vector<vi > 
#define vii vector<pii >
#define mii map<int,int>
#define mll map<ll,ll>


using namespace std;

void solve()
  {
	string s,t;
	cin>>s>>t;
	int minm=INT_MAX,cnt=0;
	rep(i,sz(s))
	{
		if(i+sz(t)-1>=sz(s))break;
		cnt=0;
		rep(j,sz(t))
		{
			if(s[i+j]!=t[j])cnt++;
		}
		minm=min(minm,cnt);
	}
	cout<<minm;


  }



signed main()
{
   std::ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   int t;
   t=1;
   //cin>>t;
   while(t--)
    {
        solve();
    }


   return 0;
}


Measured memory_bytes: 3668
import java.util.Arrays;
import java.util.Scanner;
public class Main
{
	public static void main(String arg[])
	{
		Scanner in=new Scanner(System.in);
		while(in.hasNext())
		{
			int w=in.nextInt();
			int a[]={1,2,4,8,16,32,64,128,256,512};
			boolean b[]=new boolean[10];
			Arrays.fill(b, false);
			if(w>=512)
			{
				w-=512;
				b[9]=true;
			}
			if(w>=256)
			{
				w-=256;
				b[8]=true;
			}
			if(w>=128)
			{
				w-=128;
				b[7]=true;
			}
			if(w>=64)
			{
				w-=64;
				b[6]=true;
			}
			if(w>=32)
			{
				w-=32;
				b[5]=true;
			}
			if(w>=16)
			{
				w-=16;
				b[4]=true;
			}
			if(w>=8)
			{
				w-=8;
				b[3]=true;
			}
			if(w>=4)
			{
				w-=4;
				b[2]=true;
			}
			if(w>=2)
			{
				w-=2;
				b[1]=true;
			}
			if(w>=1)
			{
				w-=1;
				b[0]=true;
			}
			boolean f=false;
			for(int i=0;i<10;i++)
			{
				if(b[i])
				{
					if(f)
						System.out.print(" ");
					System.out.print(a[i]);
					f=true;
				}
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 12000
lt = [int(input()) for x in range(int(input()))]
sum = 0
lit =[]
for i in lt:
    sum += i
    if i%10!=0:
        lit.append(i)
if sum%10!=0:
    print(sum)
else:
    if lit==[]:
        print(0)
    else:
        lit.sort()
        print(sum-lit[0])

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

using namespace std;

typedef pair<int, int> PII;
typedef long long ll;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pct __builtin_popcount

int n, A, B;
string s;

int main() {
	cin >> n >> A >> B >> s;
	int nab = 0, nb = 0;
	for (int i = 0; i < n; i ++) {
		bool F = false;
		if (s[i] == 'a') {
			if (nab < A+B) {
				nab ++;
				F = true;
			}
		} else
		if (s[i] == 'b') {
			if (nab < A+B && nb < B) {
				nab ++;
				nb ++;
				F = true;
			}
		}
		if (F) puts ("Yes"); else puts ("No");
	}
	return 0;
}

Measured memory_bytes: 896
#include<iostream>
#include<algorithm>

using namespace std;

int A[100000], B[100000 - 1];

int main(){
  	int N, M;
  	cin >> N >> M;
  	long long ans = 0;
  	for(int i = 0; i < M; i++){
    	cin >> A[i];
    }
  	sort(A, A + M);
  	for(int i = 1; i < M; i++){
    	B[i - 1] = A[i] - A[i - 1];
    }
  	sort(B, B + M - 1);
  	for(int i = 0; i < M - N; i++){
        ans += B[i];
    }
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>

typedef struct{
	char name[30];
	int win;
	int prior;
}team;

void swap(team *p, team *q){
	team tmp = *p;
	*p = *q;
	*q = tmp;
}

int main(void){
	int flag=0;


	while(1){
		int n, i, j, x, y, z;
		char c[30];
		team t[10];
						
		scanf(" %d", &n);
		if(n==0) break;
		
		if(flag==1) printf("\n");

	
		for(i=0; i<n; i++){
			scanf(" %s", c);
			strcpy(t[i].name, c);
			t[i].prior=i;

			scanf(" %d %d %d", &x, &y, &z);
			t[i].win = 3*x + z;
		}
		
		for(i=0; i<n; i++){
			for(j=0; j<n; j++){
				if( (t[i].win > t[j].win) ||  (t[i].win==t[j].win && t[i].prior < t[j].prior) )
					swap(&t[i], &t[j]);
			}
		}
	
		for(i=0; i<n; i++)
			printf("%s,%d\n", t[i].name, t[i].win);
		
		flag=1;
	}

	return 0;
}

Measured memory_bytes: 616
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <bitset>
#include <cmath>
#include <string>
#include <fstream>
#define FI first
#define SE second
#define VE vector<int>
#define PB push_back
#define PA pair<int,int>
#define MA make_pair
#define LL long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
const int INF=1e9+7;
const int MOD=1e9+7;
//
int main(){
  int N;
  vector<PA> V;
  cin>>N;
  int m=INF;
  LL S=0;
  bool F=true;
  FOR(i,0,N){
    int A,B;
    cin>>A>>B;
    if(A!=B){
      F=false;
    }
    if(A>B){
      m=min(m,B);
    }
    S+=A;
    V.PB(MA(A,B));
  }
  if(F){
    cout<<0<<endl;
    return 0;
  }
  S-=m;
  cout<<S<<endl;
  return 0;
}


Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)
//#define INF (1LL<<59)

#define int ll

signed main(){
    int n,t;
    cin>>n>>t;
    vector<int> v(n);
    rep(i,n)cin>>v[i];
    
    sort(all(v));
    
    
    int ans = 0;

    int i = 0;
    while(i<n){
        int left = v[i];
        int bef = v[i];
        while(v[i]-bef<=t && i<n){
            bef = v[i];
            i++;
        }
        ans+=v[i-1]-left+t;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define li long int
#define ll long long int
#define vec(x) vector<x> 
#define st(x) set<x> 
#define mpp(x,y) map<x,y>
#define qq(x) queue<x>
#define pqq(x) priority_queue<x> 
#define search(x,y,z) binary_search(x,y,z)
#define pi(x,y) pair<x,y>
#define forf(i,x,y) for(ll i=x;i<y;i++)
#define forl(i,x,y) for(ll i=x-1;i>=y;i--)
#define rev(x) reverse(x.begin(),x.end())
#define mem(x,a) memset(x,a,sizeof(x))
#define mod 1000000007
#define nxt_per(x) next_permutation(x.begin(),x.end())
#define pb push_back
#define pf push_front
#define pof pop_front
#define pob pop_back
#define pp push
#define po pop
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
#define vp(x,y) vec(pi(x,y) )
#define vv(x) vector<vector<x> >
#define all(x) x.begin(),x.end()
/*
void check(int x,int y)
{
	//all 8 directions
	if(x-1<n && y-1<m)
	if(x-1<n && y<m)
	if(x-1<n && y+1<m)
	if(x<n && y-1<m)
	if(x<n && y+1<m)
	if(x+1<n && y-1<m)
	if(x+1<n && y<m)
	if(x+1<n && y+1<m)
}
*/
/*
unordered_map<ll,ll> um
um.reserve(1<<15);
um.max_load_factor(0.25);
*/

using namespace std;

int main()
{
	fastio;
// best of luck don't loose hope man	

	ll a,b,k;
	cin>>a>>b>>k;
	int c=1;
	// takashi is odd
	int turn=1;
	while(c<=k)
	{	if(turn%2!=0)
		{	if(a%2!=0)
				a--;
			b+=a/2;
			a=a/2;
		}
		else
		{	if(b%2!=0)
				b--;
			a+=b/2;
			b=b/2;	
		}
		turn++;
		c++;
	}
	cout<<a<<" "<<b;
	return 0;
}

Measured memory_bytes: 256
import sys
input=sys.stdin.readline
N,M=map(int,input().split())

graph=[[] for _ in range(N+1)]
for i in range(M):
  u,v=map(int,input().split())
  graph[u].append(v)
  
S,T=map(int,input().split())

#print(graph)
visited=[]
for i in range(N+1):
  visited.append([False]*3)
  
queue=[S]
t=0
while queue:
  new_queue=set()
  for u in queue:
    if u==T and t%3==0:
      print(t//3)
      sys.exit(0)
    
    visited[u][t%3]=True
    for v in graph[u]:
      if not visited[v][(t+1)%3]:
        new_queue.add(v)
        
  queue=list(new_queue)
  t+=1
  
print(-1)

Measured memory_bytes: 64764
s=input()
K=int(input())
n=len(s)
dp=[[[0]*2 for _ in range(K+1)] for _ in range(n+1)]
dp[0][0][0]=1
for i in range(n):
    for j in range(K+1):
        for k in range(2):
            nd=int(s[i])
            for d in range(10):
                ni,nj,nk=i+1,j,k
                if d!=0:
                    nj+=1
                if nj>K:
                    continue
                if nk==0:
                    if nd<d:
                        continue
                    if nd>d:
                        nk=1
                dp[ni][nj][nk]+=dp[i][j][k]
print(dp[n][K][0]+dp[n][K][1])

Measured memory_bytes: 3188
a,b,M = map(int,input().split())
A = list(map(int,input().split()))

B = list(map(int,input().split()))
C = [list(map(int,input().split())) for _ in range(M)]
ans = min(A) + min(B)
for cp in C:
    temp = A[cp[0]-1] + B[cp[1]-1] - cp[2]
    ans = min(ans,temp)

print(ans)

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



int main() {
    int n, m;
    string s;
    vector<int> ans;
    vector<string> blue, red;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> s;
        blue.push_back(s);
    }
    cin >> m;
    for (int i = 0; i < m; i++) {
        cin >> s;
        red.push_back(s);
    }
    for (int i = 0; i < n; i++) {
        int res = 0;
        for (int j = i; j < n; j++) {
            if (blue[i] == blue[j]) res++;
        }
        for (int k = 0; k < m; k++) {
            if (blue[i] == red[k]) res--;
        }
        ans.push_back(res);
    }
    sort(ans.begin(), ans.end(), greater<int>());
    cout << max(0, ans[0]) << endl;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

int n, cnt[4];
double dp[301][301][301];

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout << fixed << setprecision(10);
    cin >> n;
    for(int i = 0 ; i < n ; i++){
        int x;
        cin >> x;
        cnt[x]++;
    }
    for(int c = 0 ; c <= 300 ; c++){
        for(int b = 0 ; b <= 300 ; b++){
            for(int a = 0 ; a <= 300 ; a++){
                if(a == 0 && b == 0 && c == 0) continue;
                if(a + b + c > n) continue;
                double p1 = (double) a / n;
                double p2 = (double) b / n;
                double p3 = (double) c / n;
                double p0 = 1 - (p1 + p2 + p3);
                dp[a][b][c] = 1;
                if(a) dp[a][b][c] += dp[a - 1][b][c] * p1;
                if(b) dp[a][b][c] += dp[a + 1][b - 1][c] * p2;
                if(c) dp[a][b][c] += dp[a][b + 1][c - 1] * p3;
                dp[a][b][c] /= 1 - p0;
            }
        }
    }
    cout << dp[cnt[1]][cnt[2]][cnt[3]] << endl;
}


Measured memory_bytes: 213248
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>

#define _GLIBCXX_DEBAC
/*map<Keyの型, Valueの型> 変数名;
queue<型> 変数名;
priority_queue<型> 変数名;
priority_queue<型, vector<型>, greater<型>> 変数名;*/

using namespace std;

int gcd(int a, int b) {
	int c;
	if (a < b) {
		c = a; a = b; b = c;
	}
	while (b != 0) {
		c = a % b; a = b; b = c;
	}
	return a;
}

int sort_greater(int m,int n) {
	vector<int> a(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end(),greater<int>());
	for (int i = 0; i < n; i++) {
		cout << a[i];
	}
		return 0;
}

int bubblesort(int a[], int n) {
	int sw = 0;
	bool flag = 1;
	for (int i = 0; flag; i++) {
		flag = 0;
		for (int j = n - 1; j >= i + 1; j--) {
			if (a[j] < a[j - 1]) {
				swap(a[j], a[j - 1]);
				flag = 1;
				sw += 1;
			}
		}
	}
	return sw;
}

map<string, int> memo;
int main() {
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		cout << "x";
	}
	
	return 0;
}









Measured memory_bytes: 256
#![allow(non_snake_case)]
#![allow(unused_imports)]
use proconio::input;
use std::collections::HashMap;
use std::collections::VecDeque;
use std::cmp::max;
use std::cmp::min;


fn main() {
    input! {
        A: i64,
        B: i64,
        C: i64,
        D: i64,
    }

    let ans = max(A*B, C*D);
    println!("{}", ans);
}


Measured memory_bytes: 2064
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
#define int long long
signed main(){
	int a,b;
	int v=0,n=0;
	int c = 0;
	while( scanf("%lld,%lld", &a, &b) != EOF ){
		v += a*b;
		n += b;
		c++;
	}
	printf("%lld\n%.0f\n", v, round(n*1./c));
	return 0;
}

Measured memory_bytes: 3160
fun main(args: Array<String>) = println(run {
    val n = readLine()!!.toInt()
    val s = (1..n).map { readLine()!! }

    s.map { it.toList().sorted() }
            .groupBy { it }.map { it.value.size }
            .map { it.toLong()*(it-1)/2 }.sum()
})

Measured memory_bytes: 79608
import math
lis = list(map(int,input().split()))
lis.sort()
ans = 0
while True:
    if lis[0] == lis[2]:
        print(ans)
        exit()
    if lis[0] == lis[1]:
        lis[0] += 1
        lis[1] += 1
    else:
        lis[0] += 2
    ans += 1
    lis.sort()

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {


	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n= sc.nextInt();
		int k = sc.nextInt();
		String s = sc.next();
		

		System.out.println(s.substring(0, k-1)+String.valueOf((char)(s.charAt(k-1)-'A'+'a'))+s.substring(k));

	}
}

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

using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);

	int m, f, b;
	cin >> m >> f >> b;
	if( m >= b )cout << 0 << endl;
	else if( m + f < b )cout << "NA" << endl;
	else cout << b - m << endl;

	return 0;
}



Measured memory_bytes: 3176
#include<iostream>
#include<math.h>
#include<algorithm>
#include<vector>
#include<string>
//#include<windows.h>


using namespace std;



#define Int int64_t
#define dump(x) cout << (x) << endl
#define fi first
#define se second
Int mod = 1e9 + 7;
Int INF = 1e18;
double EPS = 0.00000001;
//Int mod = 1e6+3;


int main() {
	int a, b;
	string c;
	cin >> a >> c >> b;
	if (c == "-") {
		cout << a - b << endl;
	}
	else {
		cout << a + b << endl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i , x , y) for(register int i = (x) , _## i = ((y) + 1) ; i < _## i ; i ++)
#define Rep(i , x , y) for(register int i = (x) , _## i = ((y) - 1) ; i > _## i ; i --)
using namespace std ;
#define int long long
using ll = long long ;
using pii = pair < int , int > ;
const static int _ = 1 << 20 ;
char fin[_] , * p1 = fin , * p2 = fin ;
inline char gc() { return (p1 == p2) && (p2 = (p1 = fin) + fread(fin , 1 , _ , stdin) , p1 == p2) ? EOF : * p1 ++ ; }
inline int read() {
	bool sign = 1 ; char c = 0 ; while(c < 48) ((c = gc()) == 45) && (sign = 0) ;
	int x = (c & 15) ; while((c = gc()) > 47) x = (x << 1) + (x << 3) + (c & 15) ;
	return sign ? x : -x ;
}
template < class T > void print(T x , char c = '\n') {
	(x == 0) && (putchar(48)) , (x < 0) && (putchar(45) , x = -x) ;
	static char _st[100] ; int _stp = 0 ;
	while(x) _st[++ _stp] = x % 10 ^ 48 , x /= 10 ;
	while(_stp) putchar(_st[_stp --]) ; putchar(c) ;
}
int n ;
const int N = 1e5 + 10 ;
vector < int > G[N] ;
int a , b ;
int fa[N] , d[N] , mx[N] ;
void dfs(int u) {
	for(int v : G[u]) {
		if(v == fa[u]) continue ;
		fa[v] = u ;
		d[v] = d[u] + 1 ;
		dfs(v) ;
	}
}
void dfs2(int u) {
	mx[u] = d[u] ;
	for(int v : G[u]) {
		if(v == fa[u]) continue ;
		dfs2(v) ;
		if(mx[v] > mx[u]) mx[u] = mx[v] ;
	}
}
signed main() {
	n = read() ; a = read() ; b = read() ;
	rep(i , 1 , n - 1) {
		int a = read() , b = read() ;
		G[a].push_back(b) ;
		G[b].push_back(a) ;
	}
	dfs(b) ; dfs2(b) ;
	int dep = d[a] >> 1 ;
	while(dep --) a = fa[a] ;
	print(mx[a] - 1) ;
	return 0 ;
}

Measured memory_bytes: 13056
#include <stdio.h>

int main(void) {

    int i, j, k;
    int n, bbuf, fbuf, rbuf, vbuf;
    int AC[4][3][10];

    for (i = 0; i < 4; i++) {
        for (j = 0; j < 3; j++) {
            for (k = 0; k < 10; k++) {
                AC[i][j][k] = 0;
            }
        }
    }

    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        scanf("%d%d%d%d", &bbuf, &fbuf, &rbuf, &vbuf);
        AC[bbuf - 1][fbuf - 1][rbuf - 1] += vbuf;
    }

    for (i = 0; i < 4; i++) {
        for (j = 0; j < 3; j++) {
            for (k = 0; k < 10; k++) {
                printf(" %d", AC[i][j][k]);
            }
            printf("\n");
        }
        if (!(i == 3)) {
            printf("####################\n");
        }
    }

    return 0;

}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<vl> vvl;

double EPS=1e-9;
int INF=1000000005;
long long INFF=1000000000000000005ll;
double PI=acos(-1);
int dirx[8]={ -1, 0, 0, 1, -1, -1, 1, 1 };
int diry[8]={ 0, 1, -1, 0, -1, 1, -1, 1 };
const ll MOD = 1000000007;

ll sum() { return 0; }
template<typename T, typename... Args>
T sum(T a, Args... args) { return a + sum(args...); }

#define DEBUG fprintf(stderr, "====TESTING====\n")
#define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
#define OUT(x) cout << x << endl
#define OUTH(x) cout << x << " "
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define READ(x) for(auto &(z):x) cin >> z;
#define FOR(a, b, c) for (int(a)=(b); (a) < (c); ++(a))
#define FORN(a, b, c) for (int(a)=(b); (a) <= (c); ++(a))
#define FORD(a, b, c) for (int(a)=(b); (a) >= (c); --(a))
#define FORSQ(a, b, c) for (int(a)=(b); (a) * (a) <= (c); ++(a))
#define FORC(a, b, c) for (char(a)=(b); (a) <= (c); ++(a))
#define EACH(a, b) for (auto&(a) : (b))
#define REP(i, n) FOR(i, 0, n)
#define REPN(i, n) FORN(i, 1, n)
#define MAX(a, b) a=max(a, b)
#define MIN(a, b) a=min(a, b)
#define SQR(x) ((ll)(x) * (x))
#define RESET(a, b) memset(a, b, sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(), v.end()
#define ALLA(arr, sz) arr, arr + sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr, sz) sort(ALLA(arr, sz))
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz))
#define PERMUTE next_permutation
#define TC(t) while (t--)
#define FAST_INP  ios_base::sync_with_stdio(false);cin.tie(NULL)
#define what_is(x) cerr << #x << " is " << x << endl;

void solve() {

}

int main()
{
    FAST_INP;
//    #ifndef ONLINE_JUDGE
//    freopen("input.txt","r", stdin);
//    freopen("output.txt","w", stdout);
//    #endif

//    int tc; cin >> tc;
//    TC(tc) solve();
	int n, x, y;
	cin >> n;
	int miA=INT_MAX, miB=INT_MAX, mxA=INT_MIN, mxB=INT_MIN;
	REP(i,n){
		cin >> x >> y;
		MIN(miA,x+y);
		MAX(mxA,x+y);
		MIN(miB,x-y);
		MAX(mxB,x-y);
	}
	OUT(max({abs(mxA-miA),abs(mxB-miB)}));
    return 0;
}

Measured memory_bytes: 3644
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#include<iomanip>
#include<stack>
#include<map>
#include<queue>
#include<set>
#define int long long
using namespace std;
const int INF = 1e10;
const int ZERO = 0;

signed main() {
	int x,y;
	cin >> x >> y;
	vector<int> vec = {0,1,0,2,0,2,0,0,2,0,2,0};
	if(vec.at(x - 1) == vec.at(y - 1)) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

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

#define what_is(x) cout << #x << " is " << x << endl;
#define PI acos(-1)
#define hell 1000000007
#define HELL 998244353
#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define fix(n) cout << fixed << setprecision(n)
#define mset(a,n) memset(a,n,sizeof a)
#define rep(i,a,b) for (__typeof((b)) i=(a);i<(b);i++)
#define repp(i,a,b,p) for(__typeof((b)) i=(a);i<(b);i+=p)
#define ren(i,a,b) for(__typeof((a)) i=(a);i>=(b);i--)
#define renn(i,a,b,p) for(__typeof((a) i=(a);i>=(b);i-=p)
#define ADD(a,b,c) ((a)%c+(b)%c)%c
#define SUB(a,b,c) ((a)%c-(b)%c+c)%c
#define MUL(a,b,c) (((a)%c)*((b)%c))%c
#define lbd lower_bound
#define ubd upper_bound
#define ll long long
#define ld long double
#define pb push_back
#define fi first
#define se second
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define all(v) (v).begin(), (v).end()
#define sz(x) (ll)x.size()
// #define out(n) cout<<n<<" "
#define outl(n) cout<<n<<endl
#define bug(n) {outl(n);return;}
#define pii pair<int,int>
#define lim 1000000000000000000
#define ninf -9223372036854775802
#define M 1000000007
#define eps 1e-9
#define MAX 5
#define N 8
#define db(a) for(auto it:a) {cout<<it<<" ";}cout<<endl;
ll prime[MAX];
ll fact[MAX];

const long long INF64 = 1e18;
ll vpow(ll a, ll b, ll p) {
    if (b == 0)
        return 1;
    if (b == 1)
        return a;
    ll temp = vpow(a, b / 2, p);
    temp *= temp;
    temp %= p;
    if (b % 2 == 0)
        return temp;
    temp = temp * a;
    temp %= p;
    return temp;
}

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


ll inverseMod(ll a, ll b, ll p) {
    if (b == 0)
        return 1;
    ll temp = vpow(b, p - 2, p);
    ll ans = temp * a;
    ans %= p;
    return ans;
}
void sieve()
{
    prime[0] = prime[1] = 1;
    for (ll i = 2; i < MAX; i++) {
        if (prime[i] == 0) {
            for (int j = i * 2; j < MAX; j += i) {
                if (prime[j] == 0) {
                    prime[j] = i;
                }
            }
            prime[i] = i;
        }
    }
}

void factorial() {
    fact[0] = 1;
    fact[1] = 1;
    rep(i, 2, MAX) {
        fact[i] = (fact[i - 1] * i);
        // fact[i]%=M;
    }
}

void solve(ll ttt) {
	ll x;
	cin>>x;
	x=1-x;
	cout<<x<<endl;
}

int main() {
    io;
    // sieve();
    // factorial();
#ifndef ONLINE_JUDGE
    freopen("input1.txt", "r", stdin);
    // freopen("output1.txt","w",stdout);
#endif

    ll t = 1;
    // cin >> t;
    fix(12);
    rep(q, 1, t + 1) {
        // cout<<"Test case : "<<q<<endl;
        solve(q);
        //solve2();
    }
    return 0;

}


Measured memory_bytes: 3652
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;


int main(){
	int n;
	cin>>n;
	int a[101010]={},dp[101010]={};
	FOR(i,0,n){
		cin>>a[i];
		dp[i]=mod;
	}
	dp[0]=0;
	FOR(i,0,n){
		dp[i+1]=min(dp[i+1],dp[i]+abs(a[i+1]-a[i]));
		dp[i+2]=min(dp[i+2],dp[i]+abs(a[i+2]-a[i]));
	}
	cout<<dp[n-1]<<endl;
    return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int g[100][100];

signed main() {
  int a, b;
  cin >> a >> b;
  a--, b--;
  rep(i, 0, 50) rep(j, 0, 100) {
    g[i][j] = 1;
  }

  rep(i, 0, 50) rep(j, 0, 100) {
    if(i % 2 == 0 && j % 2 && a) g[i][j] = 0, a--;
  }
  rep(i, 51, 100) rep(j, 0, 100) {
    if(i % 2 == 0 && j % 2 && b) g[i][j] = 1, b--;
  }
  cout << 100 << " " << 100 << endl;

  rep(i, 0, 100) {
    rep(j, 0, 100) {
      cout << (g[i][j] ? '#' : '.');
    }
    cout << endl;
  }
}


Measured memory_bytes: 256
l,r = map(int,input().split())
ans = []
tmp = 0
for i in range(l,r):
    for j in range(l+1,r+1):
        tmp = (i * (j % 2019)) % 2019
        ans.append(tmp)
        if j % 2019 == 0:
            break
    if i % 2019 == 0:
        break
print(min(ans))

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

bool cmp(pair<int, int> a, pair<int, int> b) {
    if(a.second > b.second) return true;
    else return false;
}

int main() {
    int n, h;
    cin >> n >> h;

    vector<pair<int, int>> k(n);
    for(int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        k.push_back(make_pair(a, b));
    }

    // a の昇順にする
    /*
    sort(k.begin(), k.end());
    int amax = k[n - 1].first;
     */

    // b の降順にする
    sort(k.begin(), k.end(), cmp);

    /*
    cout << "===" << endl;
    for(int i = 0; i < n; i++) {
        cout << k[i].first << ' ' << k[i].second << endl;
    }
     */
     

    // test
    pair<int, int> amaxpair = *max_element(k.begin(), k.end());
    int amax = amaxpair.first;

    // cout << amax.first << ' ' << amax.second << endl;

    int damage = 0;
    int ans = 0;
    for(int i = 0; i < n; i++) {
        if(k[i].second > amax) {
            damage += k[i].second;
            ans++;
            // cout << k[i].second << "のダメージ: " << damage << endl;
            // k.erase( k.begin() );
        }
        else break;
        if(damage >= h) break;
    }

    if(damage >= h) {
        cout << ans << endl;
    } else {
        ans += (h - damage + amax - 1) / amax;
        cout << ans << endl;
    }

    return 0;
}

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

#define maxn 55
typedef long long ll;
ll dp[maxn][2];
int a[maxn];
int n, k;

int main()
{
    cin >> n;
    cin >> k;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    dp[0][0] = 1;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < 2; j++)
        {
            dp[i + 1][j] += dp[i][j];
            dp[i + 1][(j + a[i]) % 2] += dp[i][j];
        }
    }
    cout << dp[n][k] << endl;
    return 0;
}


Measured memory_bytes: 256
//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
//#include<unordered_map>//イテレータあるけど順序保持しないmap
//#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
#include<valarray>//なんとなく追加
//メモ：表示桁数を大きくする　　cout << fixed << setprecision(20) << cm << endl;
using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define PI acos(-1.0)
#define answer(ans) cout<<ans<<endl;
#define input(N) cin >> N ;


signed main() {
int N,ans;
cin >> N;
if(N>=30){
    cout <<"Yes"<<endl;
}
else{
    cout<<"No"<<endl;
}

return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define ALL(a)			(a).begin(),(a).end()
#define REP(i, n)		for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)	for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF				(1000 * 1000 * 1000 * 2)
#define MOD				(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)		(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)		(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)	((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)		(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)		(!IsOdd((x)))						
#define M_PI			3.14159265358979323846
typedef long long		ll;
typedef pair<int, int>	P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
bool isWaterValid(int A, int B, int water)
{
	for (int aCnt = 0; aCnt <= 30; aCnt++) {
		for (int bCnt = 0; bCnt <= 30; bCnt++) {
			int calcWater = A * 100 * aCnt + B * 100 * bCnt;
			if (water == calcWater) {
				return true;
			} else if (water < calcWater) {
				break;
			}
		}
	}
	return false;
}

bool isSugarValid(int C, int D, int sugar)
{
	for (int aCnt = 0; aCnt <= Ceil(sugar, C); aCnt++) {
		for (int bCnt = 0; bCnt <= Ceil(sugar, D); bCnt++) {
			int calcSugar = C * aCnt + D * bCnt;
			if (sugar == calcSugar) {
				return true;
			} else if (sugar < calcSugar) {
				break;
			}
		}
	}
	return false;
}

// メイン
int main()
{
	int A, B, C, D, E, F;
	cin >> A >> B >> C >> D >> E >> F;
	
	int ansW = 0, ansS = 0;
	double maxRate = 0;
	for (int water = 100; water <= 3000; water += 100) {
		if (isWaterValid(A, B, water)) {
			int sugarMax = min((water / 100) * E, F - water);
			for (int sugar = sugarMax; sugar >= 0; sugar--) {
				int totalWeight = water + sugar;
				if (isSugarValid(C, D, sugar)) {
					double rateOne = 100 * (double)sugar / (double)totalWeight;
					if (maxRate <= rateOne) {
						maxRate = rateOne;
						ansW = totalWeight;
						ansS = sugar;
					}
					break;
				}
			}
		}
	}

	cout << ansW << " " << ansS << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
	#include <cstdio>
	#include <cstring>
	#include <cmath>
	#include <cstring>
	#include <chrono>
	#include <complex>
	#define endl "\n"
	#define ll long long int
	#define vi vector<int>
	#define vll vector<ll>
	#define vvi vector < vi >
	#define pii pair<int,int>
	#define pll pair<long long, long long>
	#define mod 1000000007
	#define mod2 998244353
	#define inf 1000000000000000001;
	#define all(c) c.begin(),c.end()
	#define sz(v) ((ll)(v).size())
	#define mp(x,y) make_pair(x,y)
	#define mem(a,val) memset(a,val,sizeof(a))
	#define eb emplace_back
	#define pb push_back
	#define f first
	#define s second
	#define dbg(a) cout<<#a<<" --> "<<(a)<<"\n";
	#define forn(i,n) for (ll i=0; i<(n); ++i)
	#define fornd(i,n) for (ll i=(n)-1; i>=0; --i)
	#define forab(i,a,b) for (ll i=(a); i<=(b); ++i)
	#define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
	using namespace std;
	bool isPowerOfTwo(int x) {
    return x && (!(x & (x - 1)));
	}
	int takemod(int x) {
    return (x % mod + mod) % mod;
	}
 
	int fpow(int base, int power, int MOD) {
    int result = 1;
    base = base % MOD;
    while (power) {
        if (power & 1)
            result = (result * base) % MOD;
        base = (base * base) % MOD;
        power = power >> 1;
    }
    return result;
	}
 
	int modinv(int x) {return fpow(x, mod - 2, mod);}
	vll bit(33,0);
	void in(ll a)
	{
		forab(i,0,32)
		{
			if((1<<i)&a)
				bit[i]++;
		}
	}
	void solve()
	{
		ll n;
		cin>>n;
		vll A(n);
		ll er=0;
	//	cout<<(1<<0)<<endl;
		//dbg(er);
		forn(i,n)
		{
			cin>>A[i];
			in(A[i]);
		}
		forn(i,n)
		{
			er=0;
			forn(j,32)
			{
				if(((A[i]&(1<<j)&&bit[j]%2==0)||(!(A[i]&(1<<j))&&bit[j]%2==1)))
					er+=(1<<j);
			}
			cout<<er<<" ";

		}	
		cout<<endl;
	}
	int main()
	{	
		#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
		#endif
		fast_io;
		int T=1;
		//cin>>T;
		// cin.ignore(); must be there when using getline(cin, s)
		while(T--)
		{
			solve();
		}
		return 0;
	}


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

int main()
{
	int n;
  	cin>>n;
  	map<string,bool> appeared;
  	string before,after;
  	cin>>before;
  	appeared[before]=true;
  	for(int i=1 ; i<n ; ++i)
    {
    	cin>>after;
      	if(appeared[after] || after[0]!=before[before.length()-1])
        {
        	cout<<"No"<<endl;
          	return 0;
        }
	    before=after;
        appeared[after]=true;
    }
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES//piとか使える
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;

int main()
{
	double a, b, c;//c==角度
	double S, L, h;//面積　周の長さ　高さ

	cin >> a >> b >> c;

	//高さ
	h = b*sin(M_PI/(double)(180/c));
	//面積
	S = a*h / 2;
	//周(余弦定理)
	L = a*a + b*b - 2 * a*b*cos(M_PI /(double)(180 / c));
	L = sqrt(L);
	L += a + b;

	cout << fixed << setprecision(8) << S << endl << L << endl << h << endl;

	return 0;
}


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

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

using ll  = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

void printVec(vector<int>& vec) {
    for (auto& e : vec) {
        cout << e << " ";
    }
    cout << endl;
}

int func(ll n) {
    // cout << fixed << setprecision(8);
    ll tmp = 0;
    ll num = 0;
    ll ans = 1e13;
    for (int i = 1; i <= n; i++) {
        tmp = n / i;
        // cout << i << " " << tmp << endl;

        if (i * tmp == n) {
            num = i - 1 + tmp - 1;
            // cout << "Yes"
            //  << " " << num << endl;

            ans = min(ans, num);
        }
        if (i >= tmp) {
            break;
        }
    }
    cout << ans << endl;

    return 0;
}

int main() {
    long long N;
    scanf("%lld", &N);

    func(N);

    return 0;
}


Measured memory_bytes: 256
import java.util.*
import java.io.PrintWriter
val pw = PrintWriter(System.out)


fun main(args: Array<String>) {
    val n = nextInt()
    val S = nextListOfInt()
    val q = nextInt()
    val T = nextListOfInt()

    var ans = 0

    for(i in 0 until q){
        val key = T[i]
        if(binarySearch(S, key) != null) ans += 1
    }

    pw.println(ans)
    pw.flush()
    pw.println(n)

}

fun binarySearch(A: List<Int>, key: Int): Int?{
    var left = 0
    var right = A.size
    var mid: Int
    while(left < right){
        mid = (left + right) /2
        when {
            A[mid] == key -> {
                return mid
            }
            key < A[mid] -> {
                right = mid
            }
            else -> {
                left = mid + 1
            }
        }
    }
    return null
}

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextListOfString() = next().split(" ")
fun nextListOfInt() = nextListOfString().map { it.toInt() }
fun nextListOfLong() = nextListOfString().map { it.toLong() }
fun nextListOfDouble() = nextListOfString().map { it.toDouble() }


Measured memory_bytes: 68768
from sys import stdin
rs = stdin.readline
ri = lambda : int(rs())
ril = lambda : list(map(int, rs().split()))

def main():
    n = input()
    sum = 0
    for i in n:
        sum = (sum + int(i)) % 9
    print('Yes' if sum == 0 else 'No')

if __name__ == '__main__':
    main()


Measured memory_bytes: 9240
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int n, l;
	int ans = 0;
	cin >> n >> l;
	int r = l + n - 1;
	if(l <= 0 && 0 <= r){
		rep(i, n){
			ans += i + l;
		}
	}else if(0 < l){
		rep(i, n-1){
			ans += i + l + 1;
		}
	}else{
		rep(i, n-1){
			ans += i + l;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cmath>
#include<iostream>
#include<string>
using namespace std;
int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if (abs(c-a)<=d) {
		cout << "Yes" << endl;
	}else if(abs(b - a) <= d && abs(b - c) <= d) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

using namespace std;
using lint = long long;

#pragma GCC optimize ("Ofast", "unroll-loops")
#pragma GCC target ("arch=ivybridge")

int main() {
  
  	const int nmax = 204800, block = 2048, unrl = 16;
  	int a[nmax], b[nmax];
	int N, i, j, k, ans = 0;
  
	scanf("%d", &N);
	for (int i = 0; i < N; i++) scanf("%d", &a[i]);
	for (int i = 0; i < N; i++) scanf("%d", &b[i]);

	for (i = 0; i + unrl <= N; i += unrl) {
		for (j = 0; j + block <= N; j += block) {
			for (k = j; k < block + j; k++) {

				ans ^= (a[i + 0] + b[k]) ^ (a[i + 1] + b[k]);
				ans ^= (a[i + 2] + b[k]) ^ (a[i + 3] + b[k]);
				ans ^= (a[i + 4] + b[k]) ^ (a[i + 5] + b[k]);
				ans ^= (a[i + 6] + b[k]) ^ (a[i + 7] + b[k]);
              	ans ^= (a[i + 8] + b[k]) ^ (a[i + 9] + b[k]);
				ans ^= (a[i + 10] + b[k]) ^ (a[i + 11] + b[k]);
				ans ^= (a[i + 12] + b[k]) ^ (a[i + 13] + b[k]);
				ans ^= (a[i + 14] + b[k]) ^ (a[i + 15] + b[k]);

			}
		}
	}

	for (i = 0; i < N / unrl * unrl; i++) {
		for (j = N / block * block; j < N; j++) {
			ans ^= a[i] + b[j];
		}
	}	
	for (; i < N; i++) {
		for (j = 0; j < N; j++) {
			ans ^= a[i] + b[j];
		}
	}

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

	return 0;
}


Measured memory_bytes: 1792
from itertools import product
from bisect import bisect_left
from collections import defaultdict
N = int(input())
S = list(input())
S = [int(c) for c in S]
dic = defaultdict(list)
seq = [i for i in range(10)]
com = product(seq,repeat=3)
ans = 0
for i in range(N):
  dic[S[i]] += [i]

for x,y,z in com:
  if x==y and y==z:
    if len(dic[x])>2:
      ans += 1
      continue
  elif x==y:
    if len(dic[x])>1 and len(dic[z])>0:
      j = bisect_left(dic[x],dic[z][-1])
      if j>1:
        ans += 1
  elif y==z:
    if len(dic[x])>0 and len(dic[y])>1:
      j = bisect_left(dic[x],dic[y][-2])
      if 0<j:
        ans += 1
  elif x==z:
    if len(dic[x])>1 and len(dic[y])>0:
      h = bisect_left(dic[y], dic[x][-1])
      if h==0:
        continue
      j = bisect_left(dic[x], dic[y][h-1])
      if j>0:
        ans += 1
  else:
    if len(dic[x])>0 and len(dic[y])>0 and len(dic[z])>0:
      h = bisect_left(dic[y], dic[z][-1])
      if h==0:
        continue
      j = bisect_left(dic[x], dic[y][h-1])
      if j>0:
        ans += 1
print(ans)

Measured memory_bytes: 5032
N = int(input())
a = [[int(_) for _ in input().split()] for _ in range(N)]
MOD = 10**9+7

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

for i in range(N):
    for s in range(1<<N):
        if dp[i][s] == 0:continue
        for j in range(N):
            jb = 1<<j
            if not (s&jb) and a[i][j]:
                dp[i+1][s|jb] += dp[i][s]
    
print(dp[N][(1<<N)-1]%MOD)


Measured memory_bytes: 430344
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

main() {
    string s0 = "keyence";

    string s;
    cin >> s;
    auto n0 = s0.size();
    for (auto i : irange(0uL, n0 + 1)) {
        if (s.substr(0, i) == s0.substr(0, i) && s.substr(s.size() - n0 + i) == s0.substr(i)) {
            cout << "YES" << endl;
            return 0;
        }
    }

    cout << "NO" << endl;
}

Measured memory_bytes: 256
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}
macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let n: u64 = sc.cin();
    let m: u64 = sc.cin();
    put!(
    if n == 1 || m == 1 {
        1
    } else {
        (n * m + 1) / 2
    });
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> { self.cin::<String>().chars().collect() }
    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> { (0..n).map(|_| self.cin()).collect() }
}


Measured memory_bytes: 4352