akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include<complex>
using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 100 + 47;
const int L = 100;
const int MOD = 1000 * 1000 * 1000 + 7;

deque<int> P;

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	ios::sync_with_stdio(false); cin.tie(0);

	LL n;
	cin >> n;
	n++;
	int p = -1;
	RFOR(i, 40, 0)
	{
		if (n & (1LL << i))
		{
			p = i;
			break;
		}
	}

	int cnt = 0;
	//cout << "!!" << p << endl;
	RFOR(i, p, 0)
	{
		P.push_back(cnt++);
		if ((1LL << i) & n) P.push_front(cnt++);
	}

	cout << SZ(P) + 100 << endl;
	while (!P.empty())
	{
		cout << P.front() + 1 << " ";
		P.pop_front();
	}

	FOR(i, 0, 100)
	{
		cout << i + 1 << " ";
	}

	cout << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<queue>
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)

using namespace std;


struct P{
    int x;
    int y;
};

int w,h,n;
const int INF = 1e+8;
char feld[1010][1010];
int d[1010][1010];
int sx,sy,gx,gy;
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
int ans;
P che[15];


void bfs(){
    REP(i,n){
        P sp=che[i];
        sx=che[i].x;
        sy=che[i].y;
        gx=che[i+1].x;
        gy=che[i+1].y;
        REP(y,h)REP(x,w)d[y][x]=INF;
        queue<P> que;
        que.push(sp);
        d[sy][sx]=0;
        while(!que.empty()){
            P p=que.front();
            que.pop();
            int x=p.x;
            int y=p.y;
            if(x==gx&&y==gy){
                ans+=d[gy][gx];
                break;
            }
            REP(i,4){
                int nx=x+dx[i];
                int ny=y+dy[i];
                if(nx<0||nx>=w||ny<0||ny>=h)continue;
                if(feld[ny][nx]!='X'&&d[ny][nx]==INF){
                    P next;
                    next.x=nx;
                    next.y=ny;
                    que.push(next);
                    d[ny][nx]=d[y][x]+1;
                }
            }
        }
    }
}

int main(){
    cin>>h>>w>>n;
    REP(y,h){
        REP(x,w){
            scanf(" %c",&feld[y][x]);
            if(feld[y][x]=='S'){
                che[0].x=x;
                che[0].y=y;
            }else if(feld[y][x]>='1'&&feld[y][x]<='9'){
                char c=feld[y][x];
                che[c-'0'].x=x;
                che[c-'0'].y=y;
            }
        }
    }
    bfs();
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 6224
// B - Resale
#include <bits/stdc++.h>
using namespace std;
#define rp(i,n) for(int i=0;i<(n);i++)

int in(){int x;cin>>x;return x;}

int main(){
	int N = in();
	vector<int> V(N); rp(i,N) V[i] = in();
	int ans = 0; rp(i,N) ans += max(0, V[i]-in());
	cout<< ans <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <utility>
#include <queue>

using namespace std;
typedef long long signed int ll;

constexpr int inf = INT32_MAX / 2;
constexpr int mod = 1000000007;
constexpr int maxn = 100000;

ll layer(ll n) {
	if (n == 0) return 1;
	return layer(n - 1) * 2 + 3;
}

ll patty(ll n) {
	if (n == 0) return 1;
	return patty(n - 1) * 2 + 1;
}

ll solve(ll n, ll x) {
	if (x <= 1) return 0;
	else if (x < 1 + layer(n - 1)) return solve(n - 1, x - 1);
	else if (x == 1 + layer(n - 1)) return patty(n - 1);
	else if (x == 1 + layer(n - 1) + 1) return patty(n - 1) + 1;
	else if (x < 1 + layer(n - 1) + 1 + layer(n - 1)) return patty(n - 1) + 1 + solve(n - 1, x - (1 + layer(n - 1) + 1));
	else if (x == 1 + layer(n - 1) + 1 + layer(n - 1)) return patty(n - 1) + 1 + patty(n - 1);
	else if(x == 1 + layer(n-1)+1+layer(n-1)+1)return patty(n - 1) + 1 + patty(n - 1);
	else throw;
}

int main() {
	ll n, x;
	cin >> n >> x;
	cout << solve(n, x) << endl;
}


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

int main(){
    int n,i,ovr=0,rate,mi=0;
    cin >> n;
    vector<int> a(8,0);
    for(i=0;i<n;i++){
        cin >> rate;
        if(rate/400 >= 8) ovr++;
        else{
            if(a.at(rate/400)==0) a.at(rate/400)=1;
        }
    }
    for(i=0;i<8;i++) mi += a.at(i);
    cout << max(1,mi) << " " << mi+ovr << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	long long n, a, b; string s; cin >> s;
	cout << s[0] << s[1] << s[2] << s[3] << s[4] << ' ';
	cout << s[6] << s[7] << s[8] << s[9] << s[10] << s[11] << s[12];
	cout << ' ' << s[14] << s[15] << s[16] << s[17] << s[18] << endl;
	cin >> n;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << (x) << endl
using namespace std;

using ull = unsigned long long;
using ll = long long;

using Int = int;
using Double = double;

using P = pair<Int, Int>;
using V = vector<Int>;
using M = vector<V>;

const Double PI  = 3.141592653589793238463;
const Int MOD = 1000000007;
const Int INF = numeric_limits<Int>::max() / 3;

template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec){
        is >> x;
    }
    return is;
}

Int solve(Int n, Int k, V& hs){
    Int x = 0;
    for(Int i = 0; i < n; i++){
        if(hs[i] >= k){
            x++;
        }
    }
    return x;
}

int main(int argc, char* argv[]){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);

    Int n, k;
    cin >> n >> k;
    V hs(n);
    cin >> hs;
    cout << solve(n, k, hs) << "\n";

    return 0;
}


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

#define gcd(m,n) __gcd(m,n)
#define lcm(m,n) m*(n/gcd(m,n))
#define fast std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pi acos(-1.0)
#define endl '\n'
#define MOD 1000000007
#define ull unsigned long long
#define ll long long
#define ld long double
#define pb push_back
#define dbg(x) cout << #x << "  " << x << endl;

ll power(ll base, ll exp) 
{ll res=1;while(exp>0) {if(exp%2==1) res=(res*base);base=(base*base);exp/=2;}return res;}

ll mod(ll a, ll b) {return (a % b + b) % b;}

ll powerm(ll base,ll exp,ll mod) 
{ll ans=1;while(exp){if(exp&1) ans=(ans*base)%mod;exp>>=1,base=(base*base)%mod;}return ans;}

using namespace std;

int main() 
{	
	fast;
	string s; cin>>s;
	if(s == "ABC") cout << "ARC" << endl;
	else cout << "ABC" << endl;
 	return 0;
}

Measured memory_bytes: 3652
#include<iostream>
#include<math.h>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

#define FOR(i, n) for(int i = 0; i < (n); i++)
#define FORq(i, m, n) for(int i = (m); i < (n); i++)
#define FORr(i, n) for (int i = (n); i >= 0; i++)

int main() {
	int N, T, A, num;
	float ans;
	cin >> N;
	cin >> T >> A;
	vector<int> H(N);
	FOR(i, N) {
		cin >> H[i];
	}
	ans = T - (H[0] * 0.006);
	num = 1;

	FORq(i, 1, N) {
		if (fabsf(T - (H[i] * 0.006) - A) < fabsf(ans - A)) {
			ans = T - (H[i] * 0.006);
			num = i + 1;
		}
	}

	cout << num << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<fstream>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<bitset>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
using namespace std;

bool isPrime(int p){
	
	if(p<2)return false;
	if(p==2)return true;
	if((p&1)==0)return false;
	
	for(int x=2;x<=sqrt(p);++x)if(p%x==0)return false;

	return true;
}	

int main(){
	int n;
	while(cin>>n){
		int j = n-1;
		while(!isPrime(j))j--;
		cout<<j<<" ";
		j = n+1;
		while(!isPrime(j))j++;
		cout<<j<<endl;
	}
	return 0;
}		

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

int main()
{
  char a;
  cin >> a;
  
  if(a >= 'A' && a <= 'Z')
  {
    cout << "A" << endl;
  }
  else if(a >= 'a' && a <= 'z')
  {
    cout << "a" << endl;
  }
  return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <algorithm>
#include <queue>
#include <iterator>
#include <functional>
#include <numeric>
#include <cmath>
#include <stack>
#include <limits>
#include <ctime>

using namespace std;

#define ll long long
#define sc(n) static_cast<ll>(n)
#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

int main() {
	IO;
#ifdef _DEBUG
	ifstream cin("In.txt");
#endif	
	ll n, k;
	cin >> n >> k;
	ll ans = min(n % k,k-(n%k));
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        c: [[i32;3];3],
    }
    let mut b=vec![0;3];
    let mut a = vec![0;3];
    b[0]=c[0][0];
    b[1]=c[1][0];
    b[2]=c[2][0];
    a[1]=c[0][1]-b[0];
    a[2]=c[0][2]-b[0];
    // println!("{:?}", a);
    // println!("{:?}", b);
    if a[1]==c[1][1]-b[1]
        && a[1]==c[2][1]-b[2]
        && a[2]==c[1][2]-b[1]
        && a[2]==c[2][2]-b[2] {
        println!("Yes");
    }else{
        println!("No");
    }
}

Measured memory_bytes: 4352
k = int(input())
a = list(map(int,input().split()))
if a[-1] != 2:
    print(-1)
    exit()

l = 2
r = 3
for i in a[::-1][1:]:
    if i > r:
        print(-1)
        exit()
    l = (l+i-1)//i*i
    r = r//i*i+i-1
    if r < l:
        print(-1)
        exit()
print(l,r)

Measured memory_bytes: 20236
n = int(input())
t = []
for _ in range(n):
    a = int(input())
    t.append([tuple(map(int, input().split())) for _ in range(a)])

def decode(i):
    ret = []
    for _ in range(n):
        ret.append(i & 1)
        i >>= 1
    return ret

ans = 0
for k in range(1 << n):
    l = decode(k)
    coh = True
    for i, w in enumerate(t):
        if l[i]:
            for x, y in w:
                if l[x-1] != y:
                    coh = False
    if coh:
        ans = max(ans, sum(l))
print(ans)

Measured memory_bytes: 3064
from math import cos,sqrt, radians

a,b,h,m = map(int, input().split())

theta = abs(((h / 12) * 360) + (m / 60 / 12 * 360) - (m / 60 * 360))
theta = radians(theta)
res = sqrt(a**2 + b**2 -2*a*b*cos(theta))
print(res)

Measured memory_bytes: 9512
#include <iostream>
#include <stdio.h>
#include <math.h>

using namespace std;

int main() {
	int n;
	cin >> n;
	int min = 1000000, max = -1000000, m;
	long sum = 0;
	for (int i = 0; i < n; i++) {
		cin >> m;
		sum += m;
		if (min > m)
			min = m;
		if (max < m)
			max = m;
	}
	cout << min << " " << max << " " << sum << endl;
}

Measured memory_bytes: 3088
def update_bit bit
  for i in 1..bit.size
    if bit[i-1] == "a"
      bit[i-1] = "b"
      break
    else
      bit[i-1] = "a"
    end
  end

  return bit

end



while n = STDIN.gets
  n = n.chomp
  bit = []
  ans = 0

  for i in 1..n.size-1
    # a = 0, b = 1
    bit.push("a")
  end

  maxbit = 1
  for i in 1..n.size-1
    maxbit *= 2
  end

  for i in 1..maxbit
    # p bit
    tmp = n
    a = ""

    for i in 1..tmp.size
      a += tmp[i-1]
      if i-1 < bit.size
        a += bit[i-1]
      end
    end

    a = a.gsub(/a/, "")
    a = a.split("b")
    # p a

    a.each do |value|
      ans += value.to_i
    end

    bit = update_bit bit
  end

  puts "#{ans}\n"


end


Measured memory_bytes: 1916
#include <bits/stdc++.h>
using namespace std;
int a, p, n, i;
struct chestie
{
    string name;
    int x, ind;
}v[105];
bool comp(chestie a, chestie b)
{
    return a.name<b.name||(a.name==b.name&&a.x>b.x);
}
int main()
{
    cin>>n;
    for(i=1;i<=n;i++)
        {
            v[i].ind=i;
            cin>>v[i].name>>v[i].x;
        }
    sort(v+1,v+n+1,comp);
    for(i=1;i<=n;i++)
        cout<<v[i].ind<<'\n';
    return 0;
}


Measured memory_bytes: 256
N=int(input())
L=[]
for i in range(N):
    a,b=map(int,input().split())
    L.append([a,b])
L=L[::-1]

S=0

for j in range(N):
    if (L[j][0]+S)%L[j][1]==0:
        pass
    else:
        S+=L[j][1]-(L[j][0]+S)%L[j][1]
    
print(S)

Measured memory_bytes: 20392
N = int(input())
s = []
for i in range(N):
    ss = int(input())
    s.append(ss)
ssum = sum(s)
s = sorted(s)
for val in s:
    if ssum % 10 == 0:
        if val % 10 != 0:
            ssum -= val
    else:
        break
if ssum == sum(s) and ssum % 10 == 0 :
    print(0)
else:
    print(ssum)

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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

const int N = 2e5+34;
const int mod = 2019;

string s;
long long t[N];
int h[mod];

long long binpow(long long b, long long e) {
  if (!e) return 1;
  if (e&1) return b*binpow(b, e-1)%mod;
  return binpow(b*b%mod, e/2);
}

void solve() {
  cin >> s;
  const int n = s.size();
  ++h[0];
  for (int i = n-1; i >= 0; --i) {
    t[i] = (t[i+1] + binpow(10, n-i) * (s[i]-'0')) % mod;
    ++h[t[i]];    
  }
  long long ans = 0;
  for (int i = 0; i < mod; ++i) {
    ans += (long long)h[i]*(h[i]-1)/2;
  }
  cout << ans;
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 5340
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
  public static void main(String[] args) throws IOException {
    Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
    String s = in.next();
    if (s.charAt(2) == s.charAt(3) && s.charAt(4) == s.charAt(5)) {
      System.out.println("Yes");
    } else System.out.println("No");
  }
}


Measured memory_bytes: 21844
#include<stdio.h>

int main(){
  char c;
  int count[26]={},i;

  while(scanf("%c",&c)!=EOF){
    if('a'<=c && c<='z') count[c-'a']++;
    else if('A'<=c && c<='Z') count[c-'A']++;
  }

  for(i=0;i<26;i++)
    printf("%c : %d\n",'a'+i,count[i]);
  
  return 0;
}

Measured memory_bytes: 1808
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    long long a,b;
    cin>>a>>b;
    if(a<=0 && 0<=b){
        cout<<"Zero"<<endl;
    }
    else if(a>0){
        cout<<"Positive"<<endl;
    }
    else {
        if((b-a)&1)cout<<"Positive"<<endl;
        else cout<<"Negative";
    }
}


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

int main(){
	int a,b;
	char c;
while(c!='?'){
	cin >>a>>c>>b;
	 if(c=='+'){cout <<a+b<<endl;}
	 if(c=='-'){cout <<a-b<<endl;}
	 if(c=='*'){cout <<a*b<<endl;}
	 if(c=='/'){cout <<a/b<<endl;}
	}

}

Measured memory_bytes: 1160
def main():
	import sys
	import numpy as np
	input = sys.stdin.readline
	N, D = list(map(int, input().split()))
	X = []
	for i in range(N):
		X.append(np.array(list(map(int, input().split()))))

	count = 0
	for i in range(N):
		for j in range(i+1, N):
			f = np.linalg.norm(X[i] - X[j])
			if f.is_integer():
				count += 1
	print(count)

if __name__ == '__main__':
    main()

Measured memory_bytes: 21412
#ifdef ConanYu
#include "local.hpp"
#else
#pragma GCC optimize("-O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void Main();
#define debug(...) do { } while(0)
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  Main();
}
#endif

const int N = 105;
int a[N << 1];

void Main() {
  int n; cin >> n;
  for(int i = 0; i < 2 * n; i++) {
    cin >> a[i];
  }
  sort(a, a + 2 * n);
  int ans = 0;
  for(int i = 0; i < n; i++) {
    ans += a[i * 2];
  }
  cout << ans << "\n";
}


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

void solve();
int main()
{
    solve();
    return 0;
}

void solve()
{
    int n;
    scanf("%d", &n);
    for (int i = 1; i < 10;i++)
    {
        if(n%i==0)
        {
            if(n/i<10)
            {
                printf("Yes");
                return;
            }
        }
    }
    printf("No");
}


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

class P
{
    static void Main()
    {
        int[] HW = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int next = 0;
        for (int i = 0; i < HW[0]; i++)
        {
            string s = Console.ReadLine();
            int count = 0;
            for (int j = next; j < HW[1]; j++)
            {
                if (s[j] != '#') break;
                count++;
                next = j;
            }
            if (s.Count(x => x == '#') != count)
            {
                Console.WriteLine("Impossible");
                return;
            }
        }
        Console.WriteLine("Possible");
    }
}

Measured memory_bytes: 13396
#include<bits/stdc++.h>
using namespace std;
int main()
{
 int x,i,r;
 cin>>x;
 r=x%100;

 if(r/10==7||x%10==7||x/100==7)
 {
     cout<<"Yes"<<endl;
 }
 else
 {
     cout<<"No"<<endl;
 }

return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

//typedef pair<long long,int> P;

int main(){
  int n;
  long long h;
  cin>>n>>h;
  long long a[n],b[n];
  long long ma=0;
  REP(i,n){
    cin>>a[i]>>b[i];
    if(ma<a[i]){
      ma = a[i];
    }
  }
  
  vector<long long> nb;
  REP(i,n){
    if(b[i]>=ma){
      nb.push_back(b[i]);
    }
  }
  sort(nb.begin(),nb.end(),greater<long long>());
  int cntb=nb.size();
  
  long long sumb[cntb];
  REP(i,cntb){
    if(i==0){
      sumb[i]=nb[i];
    }else{
      sumb[i]=sumb[i-1]+nb[i];
    }
  }
  int l=1;int r=1000000010;
  int m;
  while(r-l>1){
    m=(l+r)/2;
    if(m<=cntb){
      if(sumb[m-1]>=h){
        r = m+1;
        if(r-l==2){
          if(sumb[l-1]>=h){
            break;
          }else{
            l = m;
          }
        }
      }else{
        l = m+1;
      }
    }else{
      if(((h-sumb[cntb-1])+ma-1)/ma<=(m-cntb)){
        r = m+1;
        if(r-l==2){
          if(((h-sumb[cntb-1])+ma-1)/ma<=(l-cntb)){
            break;
          }else{
            l = m;
          }
        }
      }else{
        l = m+1;
      }
    }
  }
  
  cout<<l<<endl;
  return 0;
}


Measured memory_bytes: 3444
#include <bits/stdc++.h>
#define ll long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // rep(i, 1, 5) --> {1,2,3,4} // rep(i, 5, 1) --> {4,3,2,1} // rep(it, end(v), begin(v)) --> *it

using namespace std;

int main()
{
  int n;
  cin >> n;
  cout << n*(n+1)/2;
	return 0;
}


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


typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

#define pb push_back
#define mp make_pair
#define snd second
#define fst first
#define debug printf("--%d--\n",__LINE__)
#define ll long long int

int N;
string s[512];
int wc[512], bc[512];

int wcnt[512];

int main(void){
	cin >> N;
	for(int i=0;i<N;i++) cin >> s[i];
	
	bool orz = true;
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			if (s[i][j]=='#'){
				orz = false;
			}else{
				wcnt[i]++;
			}
		}
	}
	if (orz){
		cout << -1 << endl; return 0;
	}
	
	int bcnum = 0;
	for(int j=0;j<N;j++){
		wc[j] = bc[j] = 1;
		for(int i=0;i<N;i++){
			if (s[i][j]=='.') bc[j] = 0;
			if (s[i][j]=='#') wc[j] = 0;
		}
		if (bc[j]) bcnum++;
	}
	int ans = N;
	
	for(int i=0;i<N;i++){
		ans = min(ans, wcnt[i] + wc[i]);
	}
	ans += N - bcnum;
	cout << ans << endl;
	return 0;
}


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

const double PI = 3.14159;

int main(){
	long long int n,m;
	cin >> n >> m;
	long long days =0;
	for(int i =0;i<m;i++){
		long long a;
		cin >> a;
		days+=a;
	}	
	if(days>n)
		cout << -1 << endl;
	else{
		cout << n-days << endl;
	}
}

Measured memory_bytes: 3620
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

class program{
    public static void Main(){
        var points = Console.ReadLine().Split().Select(_ => double.Parse(_)).ToList();
        var dx = points[2] - points[0];
        var dy = points[3] - points[1];

        Console.WriteLine(Sqrt(dx * dx + dy * dy));
    }
}



Measured memory_bytes: 18444
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? 1e9:1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){int b=0;for(auto itr :a){if(b++!=0)cout << " "; cout << itr;} }
using ll  = long long;
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
#define int ll
signed main(){
    int u,v,k;
    cin >> u >> v >> k;
    rep(j,v+1)rep(i,u+1){
        if(i*v+u*j-2*i*j== k){
            return puts("Yes")*0;
        }
    }
    cout << "No" << endl;
}



Measured memory_bytes: 256
import Control.Monad

main :: IO ()
main = do
  ls <- getContents
  let ls' = map (map read . split) (lines ls)
      center = average ls'
      ls'' = ls' ++ [head ls']
  print $ solve center ls''

split :: String -> [String]
split s = split' s [[]]
split' :: String -> [String] -> [String]
split' [] save = save
split' (',':r) [str] = split' r [str,""]
split' (s:ss) [str] = split' ss [str ++ [s]]
split' (s:ss) [str1,str2] = split' ss [str1,(str2 ++ [s])]

average :: [[Double]] -> [Double]
average ls = division (foldl1 (\[ax,ay] [x,y] -> [ax+x, ay+y]) ls) (length ls)
  where
    division :: [Double] -> Int -> [Double]
    division [x,y] i = [x/(fromIntegral i),y/(fromIntegral i)]

solve :: [Double] -> [[Double]] -> Double
solve center [p1,p2] = tri center p1 p2
solve center (p1:p2:r) = (tri center p1 p2) + (solve center (p2:r))

tri :: [Double] -> [Double] -> [Double] -> Double
tri p1 p2 p3 = sqrt (z * (z - a) * (z - b) * (z - c))
  where
    distance :: [Double] -> [Double] -> Double
    distance [a,b] [c,d] = sqrt ((a-c)*(a-c) + (b-d)*(b-d))
    a = distance p1 p2
    b = distance p2 p3
    c = distance p3 p1
    z = (a + b + c) / 2

Measured memory_bytes: 4020
#pragma GCC target ("avx2")
#pragma GCC optimize ("Ofast")
#pragma GCC push_options
#pragma GCC optimize ("unroll-loops")
#include<bits/stdc++.h>
#define pb push_back
#define __V vector
#define all(x) x.begin(), x.end()
#define oit ostream_iterator
#define mod 998244353ll
using namespace std;
void doin() {
	cin.tie();
	cout.tie();
	ios::sync_with_stdio(0);
#ifndef ONLINE_JUDGE
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif
}
template<typename X, typename Y>
istream& operator>>(istream& in, pair<X, Y> &a) {
	in >> a.first >> a.second;
	return in;
}
template<typename T>
void getv(T& i) {
	cin >> i;
}
template<typename T, typename ... Ns>
void getv(vector<T>& v, int n, Ns ... ns) {
	v.resize(n);
	for (auto& i : v)
		getv(i, ns...);
}
template<typename T>
void getv1(T& i) {
	cin >> i;
}
template<typename T, typename ... Ns>
void getv1(vector<T>& v, int n, Ns ... ns) {
	v.resize(n + 1);
	for (int i = 1; i <= n; i++)
		getv(v[i], ns...);
}
#ifdef _WIN32
#define getchar_unlocked() _getchar_nolock()
#define _CRT_DISABLE_PERFCRIT_LOCKS
#endif
inline void getch(char &x) {
	while (x = getchar_unlocked(), x < 33) {
		;
	}
}
inline void getstr(string &str) {
	str.clear();
	char cur;
	while (cur = getchar_unlocked(), cur < 33) {
		;
	}
	while (cur > 32) {
		str += cur;
		cur = getchar_unlocked();
	}
}
template<typename T> inline bool sc(T &num) {
	bool neg = 0;
	int c;
	num = 0;
	while (c = getchar_unlocked(), c < 33) {
		if (c == EOF)
			return false;
	}
	if (c == '-') {
		neg = 1;
		c = getchar_unlocked();
	}
	for (; c > 47; c = getchar_unlocked())
		num = num * 10 + c - 48;
	if (neg)
		num *= -1;
	return true;
}
typedef unsigned long long ull;
typedef long long ll;
typedef float ld;
typedef ll _I;
typedef pair<_I, _I> pi;
typedef pair<ld, ld> pd;
typedef map<_I, _I> mii;
typedef __V <_I> vi;
typedef __V <char> vc;
typedef __V <ld> vd;
typedef __V <vd> vvd;
typedef __V <pi> vpi;
typedef __V <__V<_I>> vvi;
typedef __V <__V<char>> vvc;
typedef __V <__V<pi>> vvpi;
using AntonTsypko = void;
using arsijo = AntonTsypko;
using god = arsijo;
uniform_real_distribution<double> double_dist(0, 1);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng64(chrono::steady_clock::now().time_since_epoch().count());
int main() {
	doin();
	int a, b, k;
	cin >> a >> b >> k;
	a = __gcd(a, b);
	int i;
	for(i = a; k > 0; i--) {
		if(a%i == 0) k--;
		if(!k) break;
	}
	cout << i;

	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <functional>
#include <math.h>
#include <map>
#include <set>
#include <string>
using namespace std;
#define fio ios::sync_with_stdio(false); cin.tie(NULL);

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

const int INT_INF = 1e9;
const ll LL_INF = 1e18;
const int MAXN = 32000;

const ll mod = 1e9 + 7;

typedef struct node{
	ll x,y;
}node;

ll dp[105][2*MAXN];
ll sum[105][2*MAXN];

void add(ll &x, ll y){
	x+=y;
	if(x>=mod)x-=mod;
}

vector<node> num;
int main() {
	ll n, k;
	scanf("%lld %lld", &n,&k);

	ll x = 1;
	num.push_back({0ll, 0ll});
	while(x<=n) {
		ll t = n/x;
		ll y = n/t;
		num.push_back({x,y}); 
		x = y+1;
	}

	int nsz=num.size()-1;
	for(int i=1;i<=nsz;i++){
		dp[1][i] = num[i].y-num[i].x+1; 
		dp[1][i] += dp[1][i-1];
	}

	for(int i=2;i<=k;i++) {
		for(int j=1;j<=nsz;j++) {
			dp[i][j] = 1ll*dp[i-1][nsz-j+1] * (num[j].y-num[j].x+1) %mod; 
			add(dp[i][j], dp[i][j-1]);
		}
	}

	ll ans = dp[k][nsz];
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 54644
#include <stdio.h>

int main(void){
  int i, a, b, c, n = 0;

  scanf("%d %d %d", &a, &b, &c);

  for (i = a; i <= b; i++) {
    if (c % i == 0) n++;
  }
  
  printf("%d\n", n);

  return 0;
}


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

int main(){
    string s;
    string subA,subB;
    cin >>s;
    rep(i,4)subA.push_back(s[i]);
    for(int i = 4;i < 12;i++)subB.push_back(s[i]);
    cout << subA << " " << subB << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
#define MAX 1000000000000000

long long n, a, b, c, d, e;

int main(){
  cin >> n;
  long long a[6], val;
  a[0] = MAX;
  for ( int i = 1; i <= 5; i++){
    cin >> val;
    a[i] = min(val, a[i-1]);
  }

  cout << setprecision(15)<<  (long long)ceil(n / (double)a[5]) + 4 << endl;

  return 0;
}

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

#define fi first
#define se second
#define pb push_back
 
#define limit (int) (2e5 + 5)

#define maxn (long long int) (2147483647);

using namespace std;
using lli = long long int;
using ulli = unsigned long long int;
using ld = long double;

int n,k;
int a[limit];

bool findAnswer(int l)
{
    lli tc = 0;

    for (int i = 0; i < n; ++i)
    {
        if (a[i] <= l)
        {
            continue;
        }

        tc += a[i]/l;

        if (a[i]%l == 0)
        {
            tc--;
        }
    }

    // cout << tc << " " << l << "\n";
    if (tc > k)
    {
        return false;
    }

    return true;
}

int main()
{
    cin >> n >> k;

    for (int i = 0; i < n; ++i)
    {
        cin >> a[i];
        // cout << a[i] << "\n";
    }

    // int ans = 1e9;
    int s = 1,e = 1e9,mid;

    while(s != e)
    {
        // cout << s << " " << e << "\n";
        mid = (s+e)/2;

        if (findAnswer(mid))
        {
            e = mid;
        } else {
            s = mid+1;
        }
    }

    cout << s;
    return 0;
}


















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

int main(int argc, char const* argv[]) {
    int n, t, a;
    cin >> n >> t >> a;
    float diff = 1000000;
    int index = 0;
    for (int i = 0; i < n; ++i) {
        int h;
        cin >> h;
        float d = abs(a - (t - h * 0.006));
        if (d < diff) {
            diff = d;
            index = i;
        }
    }
    cout << index + 1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = (int)(n-1); i >= 0; i--)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;


class UnionFind
{
public:
  UnionFind(int n)
  {
    parent=vector<int>(n,-1);
  }
  int root(int a)
  {
    if(parent[a]<0)return a;
    return parent[a]=root(parent[a]);
  }
  int size(int a)
  {
    return -parent[root(a)];
  }
  bool connect(int a,int b)
  {
    int A=root(a);
    int B=root(b);
    if(A==B)return false;
    if(size(A)>size(B))swap(A,B);
    parent[B]+=parent[A];
    parent[A]=B;
    return true;
  }
private:
  vector<int> parent;

};

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;cin>>n;
  vector<ll>x(n),y(n);
  ll id=0;
  map<ll,ll>ma;//x:even
  rep(i,n){
    cin>>x[i]>>y[i];
    ma[x[i]*2]=id++;
    ma[y[i]*2+1]=id++;
  }
  UnionFind uf(id);
  rep(i,n){
    uf.connect(ma[x[i]*2],ma[y[i]*2+1]);
  }
  vector<vector<ll>>rec(id,vector<ll>(2));
  rep(i,id){
    rec[uf.root(i)][i%2]++;
  }
  ll res=0;
  rep(i,id){
    res+=rec[i][0]*rec[i][1];
    //cout<<rec[i][0]<<" "<<rec[i][1]<<endl;
  }
  cout<<res-n<<endl;



  return 0;

}


Measured memory_bytes: 19840
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 998244353;
const ll MAX = 4000001;
const double eps = 1E-18;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

mint pw(mint a, ll b) {
	if (b == 0) { return 1; }
	mint ret = pw(a, b>>1);
	ret *= ret;
	if (b & 1) { ret *= a; }
	return ret;
}

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

//////////////////////////////////////

int main() {
	ll N;
	cin >> N;

	ll ans = 0;

	ll c = 2;

	while (c*c <= N) {
		if (N % c == 0) {
			ll t = 0;
			while (N % c == 0) {
				t++;
				N /= c;
			}

			ll u = 0;
			while (u + 1 <= t) {
				t -= (u + 1);
				u++;
			}

			ans += u;
		}
		c++;
	}

	if (N != 1) { ans++; }

	cout << ans << endl;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define allR(v) v.rbegin(), v.rend()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
typedef pair<int,int> Pi;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
const int inf = 1001001001;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m=numeric_limits<T>::max()){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }

template<class T> struct edge { int to; T cost;};


int main() {
  int x; cin >>x;
  int n; cin >>n;
  vector<int> p(n); rep(i, n) cin >>p[i];
  sort(all(p));
  int sub = 10000;
  int res = 10000;
  for (int i=-1000; i<=1000; i++){
    if (lower_bound(all(p), i) != p.end()){
      if (*lower_bound(all(p), i) == i) continue;
    }
    if (abs(x - i) < sub){
      sub = abs(x - i);
      res = i;
    }
  }
  cout <<res <<endl;
}

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

int main()
{
	int N;
	cin >> N;
	int num[N];
	int i = 0, count = 0;
	while (i < N)
		cin >> num[i++];
	int flag=0;
	while (true)
	{
		i = 0;
		while (i < N)
		{
			if (num[i] % 2 != 0)
				flag = 1;
			num[i] /= 2;
			i++;
		}
		if (flag == 1)
			break;
		count++;
	}
	cout << count << endl;
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
 
#define FOR(i, a, b) for(int i = a; i < (int) b; i++)
#define F0R(i, a) FOR (i, 0, a)
#define ROF(i, a, b) for(int i = a; i >= (int) b; i--)
#define R0F(i, a) ROF(i, a, 0)
#define GO(i, a) for (auto i : a)
 
#define rsz resize
#define eb emplace_back
#define pb push_back
#define sz(x) (int) x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define f first
#define s second

 
using namespace std;
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<vpii> vvpii;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef vector<pi64> vpi64;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0); 
  i64 n;
  cin >> n;
  i64 mx = 1e18;
  for (i64 i = 1; i * i <= n; i++) {
    if ((n % i) == 0) {
      mx = min (mx, abs (i - 1) + abs ((n / i) - 1));
    }
  }
  cout << mx << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
 
#define MAX 10000
#define NIL -1
 
typedef struct { int parent, left, right;} Node;
 
Node T[MAX];
int n, D[MAX], H[MAX];
 
void setDepth(int u,int d) {
  if(u == NIL) return;
  D[u] = d;
  setDepth(T[u].left, d+1);
  setDepth(T[u].right,d+1);
}
 
int setHeight(int u) {
  int h1 = 0, h2 = 0;
  if(T[u].left != NIL)
    h1 = setHeight(T[u].left)  + 1;
  if(T[u].right != NIL)
    h2 = setHeight(T[u].right) + 1;
  return H[u] = (h1 > h2 ? h1 : h2);
}
 
int getSibling(int u) {
  if(T[u].parent == NIL) return NIL;
  if(T[T[u].parent].left != u && T[T[u].parent].left != NIL )
    return T[T[u].parent].left;
  if(T[T[u].parent].right != u && T[T[u].parent].right != NIL )
    return T[T[u].parent].right;
  return NIL;
}
 
void print(int u) {
  int deg = 0;
  printf("node %d: ",u);
  printf("parent = %d, ",T[u].parent);
  printf("sibling = %d, ",getSibling(u));
  if(T[u].left  != NIL) deg++;
  if(T[u].right != NIL) deg++;
  printf("degree = %d, ",deg);
  printf("depth = %d, ",D[u]);
  printf("height = %d, ",H[u]);
   
  if(T[u].parent == NIL) {
    printf("root\n");
  } else if(T[u].left == NIL && T[u].right == NIL) {
    printf("leaf\n");
  } else {
    printf("internal node\n");
  }
}
 
int main(void) {
  int i, v, l, r, root = 0;
  scanf("%d",&n);
  for(i=0;i<n;i++) T[i].parent = NIL;
  for(i=0;i<n;i++) {
    scanf("%d %d %d",&v,&l,&r);
    T[v].left  = l;
    T[v].right = r;
    if(l != NIL) T[l].parent = v;
    if(r != NIL) T[r].parent = v;
  }
   
  for(i=0; i<n; i++)
  if(T[i].parent == NIL) root = i;
   
  setDepth(root,0);
  setHeight(root);
   
  for(i=0;i<n;i++) print(i);
   
  return 0;
}


Measured memory_bytes: 2108
#include <iostream>
#include <vector>

using namespace std;

int main(){
  int n, u, k;
  cin >> n;

  vector<vector<int> > mtx(n);
  for(int i=0; i<n; i++)
    mtx[i].resize(n);


  for(int i=0; i<n; i++){
    cin >> u >> k;
    for(int j=0; j<k; j++){
      int t;
      cin >> t;
      mtx[i][t-1] = 1;
    }

  }
  
  for(int i=0; i<n; i++){
    for(int j=0; j<n-1; j++)
      cout << mtx[i][j] << " ";
    cout << mtx[i][n-1] << endl;
  }

  return 0;
}

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

int main(void){
    int n;
    cin>>n;
    int x,y;
    vector<int> v;
    while(n--){
        cin>>x;
        if(x==0){
            //pb
            cin>>y;
            v.push_back(y);
        }else if(x==1){
            cin>>y;
            cout<<v[y]<<endl;
        }else{
            v.pop_back();
        }
    }
    return 0;
}


Measured memory_bytes: 3892
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define rt return
#define dll(x) scanf("%I64d",&x)
#define xll(x) printf("%I64d\n",x)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
inline void getInt(int* p);
const int maxn=1000010;
// const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
int n;
char op[maxn];
int a[maxn];
ll dp[maxn/10][4];
const ll inf=(ll)(1e18);

int main()
{
    //freopen("D:\\common_text\\code_stream\\in.txt","r",stdin);
    //freopen("D:\\common_text\\code_stream\\out.txt","w",stdout);
    gbtb;
    cin>>n;
    cin>>a[1];
    repd(i,2,n)
    {
        cin>>op[i]>>a[i];
    }
    dp[1][0]=a[1];
    dp[1][1]=dp[1][2]=-inf;
    repd(i,2,n)
    {
        if(op[i]=='+')
        {
            dp[i][0]=max(dp[i-1][0],max(dp[i-1][2],dp[i-1][1]))+a[i];
            dp[i][1]=dp[i-1][1]-a[i];
            dp[i][2]=dp[i-1][2]+a[i];
        }else
        {
            dp[i][0]=-inf;
            dp[i][1]=max(dp[i-1][0],dp[i-1][1])-a[i];
            dp[i][2]=max(dp[i-1][2],dp[i-1][1])+a[i];
        }
    }
    cout<<max(dp[n][0],max(dp[n][1],dp[n][2]))<<endl;
    
    return 0;
    
}

inline void getInt(int* p) {
    char ch;
    do {
        ch = getchar();
    } while (ch == ' ' || ch == '\n');
    if (ch == '-') {
        *p = -(getchar() - '0');
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 - ch + '0';
        }
    }
    else {
        *p = ch - '0';
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 + ch - '0';
        }
    }
}



Measured memory_bytes: 4480
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
#define ALL(a)  (a).begin(),(a).end()
const ll INF = 1e18+18;
const ll MAX = 200000;
const ll MOD = 1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;



int main(){
   ll N, K;
   cin>>N>>K;
   ll A1=N%K;
   ll A2=K-N%K;
   cout<<min(A1, A2)<<endl;
   return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip> 
#include <complex> 
#include <string>
#include <vector> 
#include <list>
#include <deque> 
#include <stack> 
#include <queue> 
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm> 
#include <numeric> 
#include <typeinfo> 
#include <cstdio>
#include <cstdlib> 
#include <cstring>
#include <cmath>
#include <climits> 
#include <ctime>
using namespace std;

int a,b,c;

int main(void){
	cin >> a >> b >> c;
	if(a==1 && b==0 && c==0)cout << "Close" << endl;
	if(a==0 && b==1 && c==0)cout << "Close" << endl;
	if(a==1 && b==1 && c==0)cout << "Open" << endl;
	if(a==0 && b==0 && c==1)cout << "Open" << endl;
	if(a==0 && b==0 && c==0)cout << "Close" << endl;
    return 0;
}

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

int main(){
  int N,K;
  long long R, S, P;
  string T;
  cin >> N >> K >> R >> S >> P >> T;
  long long ans=0;
  for(int i=0; i<N; i++){
    if(i>=K && T.at(i)==T.at(i-K)) T.at(i)='x';
    if(T.at(i)=='r') ans+=P;
    if(T.at(i)=='s') ans+=R;
    if(T.at(i)=='p') ans+=S;
  }
  cout << ans << endl;
}

Measured memory_bytes: 512
n, m =map(int, input().split())
l = [list(map(int, input().split(' '))) for _ in range(n)]
l.sort()

y,x = 0,0
for i in range(n):
    for j in range(l[i][1]):
        if m > x:
            y += l[i][0]
            x += 1
        else:
            break

print(y)





Measured memory_bytes: 27812
_ = int(input())

stones = [int(i) for i in input().split()]

cost = [0, abs(stones[1] -stones[0])]

for i in range(2, len(stones)):
    jump_1 = cost[i-1] + abs(stones[i] - stones[i-1])
    jump_2 = cost[i-2] + abs(stones[i] - stones[i-2])
    cost.append(min(jump_1, jump_2))

print(cost[-1])

Measured memory_bytes: 13780
//wifi is shit

//**************************
//*** writer  :  Alan Hu **
//************************

//傅思程你敢抄我程序？？？ 
//傅思程你敢抄我程序？？？	                
//傅思程你敢抄我程序？？？ 

#include<bits/stdc++.h>

using namespace std;
     
#define CLEAN(a,b) memset(a,b,sizeof(a))
#define mkp make_pair
#define pb push_back
#define rept(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
 
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main()
{
	int k;
	cin>>k;
	cout<<k/2*(k-k/2)<<endl;
	return 0;
}

Measured memory_bytes: 256