akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
  unsigned short *A, *B;
  int C[VMAX+1];
  int n, i, j;

  scanf("%d", &n);

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);

  for(i=1;i<=n;i++){
    scanf("%d",&A[i]);
  }
  
  for(i=0;i<=VMAX;i++){
    C[i]=0;
  }

  for(j=1;j<=n;j++){
    C[A[j]]++;
  }

  for(i=1;i<=VMAX;i++){
    C[i]=C[i]+C[i-1];
  }

  for(j=n;j>=1;j--){
    B[C[A[j]]]=A[j];
    C[A[j]]--;
  }

  for(i=1;i<=n;i++){
    printf("%d",B[i]);
    if(i<=n-1){
      printf(" ");
    }else{
      printf("\n");
    }
  }
  return 0;
}



Measured memory_bytes: 9636
#include<bits/stdc++.h>
using namespace std;
inline int_fast64_t read(){int_fast64_t x=0,f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();return x*f;}
inline string read_s(){string s="";char c=getchar();while(c<'!'||c>'~'){c=getchar();}while(c>='!'&&c<='~'){s+=c;c=getchar();}return s;}
double ans;
void Main(){
    int N = read(), K = read();
    double tmp = K, add = 1;
    if (K > 1) {
        for (int i = N; i > 0; i--) {
            while (tmp > i) {
                tmp /= 2;
                add /= 2;
            }
            ans += add;
        }
        printf("%.10lf\n", ans/N);
    }
    else printf("1\n");
}
int main(){cin.tie(nullptr);ios::sync_with_stdio(false);Main();return 0;}

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

def ehu(n):
    if n % 2 == 0:
        return n / 2
    else:
        return 3 * n + 1

cache = []
def calc(s):
    cache.append(s)
    if cache.count(s) > 1:
        print(len(cache))
        return
    calc(ehu(s))

calc(s)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
using namespace std;
typedef long long int ll;

#define MOD 998244353


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

bool primeNumber(ll n){
    if(n < 2) return false;
    else{
        for(ll i = 2; i * i <= n; i++){
            if(n % i == 0) return false;
        }
        return true;
    }
}
  
  

int main(){
    ll s;
    cin>>s;
    set<ll> st;

    
    while(st.count(s) == 0){
        st.insert(s);
        if(s%2 == 0)s /= 2;
        else s = 3*s+1;
    }
    cout<< (st.size() + 1) << endl;
    return 0;
}


Measured memory_bytes: 256
n,k = map(int,input().split())
a = list(input() for nesya in range(2*k))
t = 1
b =[]
for hoge in a:
  if t%2 == 0:
    b += list(hoge.split())
  t += 1
c = set(b)
ans = n - len(c)
print(ans)

Measured memory_bytes: 9444
#include <bits/stdc++.h>
using namespace std;
int main(){
    int x1,y1,x2,y2;
    cin >> x1 >> y1 >> x2 >> y2;
    cout << x2+y1-y2 << " " << y2+x2-x1 << " "
         << x1+y1-y2 << " " << y1+x2-x1 << endl;
    return 0;
}

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

#define rep(i,n)  for(int i = 0; i < (int)(n); i++)
#define sz(x)     ((int)(x).size())
#define all(x)    (x).begin(),(x).end()

using ll = long long;

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1e9+7;
struct mint {
  typedef long long ll;
  ll x;
  mint(ll x=0):x((x%mod+mod)%mod){}
  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;
  }
  bool operator>(const mint a) const {
    mint res(*this);
    return res.x > a.x;
  }
  bool operator<(const mint a) const {
    mint res(*this);
    return res.x < a.x;
  }
  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;
  }
};

constexpr int premax = 200020; 
std::array<mint, premax> f, rf; 
bool mymodflag = false;
mint nCk (int n, int k) {
  if ( n == k ) return mint(1);
  if ( n < k  ) return mint(0);
  if ( !mymodflag ) {
    f[0] = 1; for(int i=1; i<premax; i++) f[i] = f[i-1]*i;
    rf[premax-1] = f[premax-1].pow(mod-2); for(int i=premax-2; i>=0; i--) rf[i] = rf[i+1]*(i+1);
    mymodflag = true;
  }
  return f[n]*rf[n-k]*rf[k];
}

mint nPk (int n, int k) {
  if ( n < k  ) return mint(0);
  if ( !mymodflag ) {
    f[0] = 1; for(int i=1; i<premax; i++) f[i] = f[i-1]*i;
    rf[premax-1] = f[premax-1].pow(mod-2); for(int i=premax-2; i>=0; i--) rf[i] = rf[i+1]*(i+1);
    mymodflag = true;
  }
  return f[n]*rf[n-k];
}


int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  int S; std::cin >> S;

  std::vector<std::vector<mint>> dp(701, std::vector<mint>(S+1));
  for(int s = 3; s<=S; s++) dp[0][s] = mint(1);
  rep(i,700) {
    rep(s,S) if ( s+3 <= S ) dp[i+1][s+3] += dp[i][s];
    rep(s,S) dp[i+1][s+1] += dp[i+1][s];
  }

  mint ans = 0;
  rep(i,700) ans += dp[i][S];
  std::cout << ans.x << std::endl;

  return 0;
}



Measured memory_bytes: 17408
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
#include<unordered_map>
#include<queue>

using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n; ++i)
#define ALL(a) (a).begin(),(a).end()
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)

vector<ll> pos(100010);
vector<bool> used(100010);
struct choten{
    vector<ll> c;
    vector<ll> w;
};
vector<choten> g(100010);

bool dfs(ll x){
    bool flag = true;
    used[x] = true;
    rep(i, g[x].c.size()){
        ll tmp = g[x].c[i];
        ll weight = g[x].w[i];
        if(!used[tmp]){
            pos[tmp] = pos[x] + weight;
            flag *= dfs(tmp);
        }
        else if(pos[tmp] != pos[x] + weight)return false;   
    }
    return flag;
}

int main(){
    ll n, m;
    cin >> n >> m;
    rep(i, m){
        ll l, r, d;
        cin >> l >> r >> d;
        g[l].c.push_back(r);
        g[l].w.push_back(d);
        g[r].c.push_back(l);
        g[r].w.push_back(-d);
    }
    rep(i, n+1)used[i] = false; 
    for(int i = 1; i <= n; ++i){
        if(used[i])continue;
        pos[i] = 0;
        if(!dfs(i)){
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
}

Measured memory_bytes: 20864
from collections import deque

def main():
    N, X, Y = map(int, input().split())
    ans = {i: 0 for i in range(1, N)}
    for i in range(1, N + 1):
        cost = [-1]*(N+1)
        cost[i] = 0
        d = deque([i])
        while len(d) != 0:
            v = d.popleft()
            c = cost[v]
            for j in [-1, 1]:
                vj = v + j
                if vj > 0 and vj <= N and cost[vj] == -1:
                    cost[vj] = c + 1
                    d.append(vj)
                    ans[c + 1] += 1
            if v in [X, Y]:
                vxy = X + Y - v
                if cost[vxy] == -1:
                    cost[vxy] = c + 1
                    d.append(vxy)
                    ans[c + 1] += 1
    for a in ans:
        print(ans[a]//2)


if __name__ == '__main__':
    main()


Measured memory_bytes: 52700
#include<iostream>
#include<string>
using namespace std;
int main()
{
	string S;
	int N,times=0;
	cin >> N;
	cin >> S;
	for (int i = 0; i <N-2 ; i++)
	{
		if((S[i]==65)&&(S[i+1]==66)&&(S[i+2]==67))
			times++;
	}
	cout << times << endl;

	return 0;
}

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

ans = []
M = N - 1

if (N - 1)*(N - 2)//2 < K:
    print(-1)
    exit()

for i in range(2, N + 1):
    ans.append([1, i])

a = (N - 1) * (N - 2) // 2 - K

for i in range(2, N):
    for j in range(i + 1, N + 1):
        if M - N + 1 >= a:
            break
        ans.append([i, j])
        M += 1

print(M)
for aa in ans:
    print(aa[0], aa[1])


Measured memory_bytes: 4120
package main

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)

	res := 0
	for i := 0; i < len(s)/2; i++ {
		if s[i:i+1] != s[len(s)-(i+1):len(s)-i] {
			res++
		}
	}
	fmt.Println(res)
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
 
int main(void)
{
	using namespace std;

	/* input n integers */
	int numData1;
	cin >> numData1;
	
	/* input sequence of n integers S */
	vector<int> vector1;
	for( int i = 0; i < numData1; i++ )
	{
		int input1;
		cin >> input1;
		vector1.push_back( input1 );
	}
	 
	/* input q integers */
	int numData2;
	cin >> numData2;
	 
	/* input sequence of n integers T */
	vector<int> vector2;
	for( int j = 0; j < numData2; j++ )
	{
		int input2;
		cin >> input2;
		vector2.push_back( input2 );
	}
	 
	/* Exec LinearSerch */
	int serchCnt = 0;
	for( int k = 0; k < numData2; k++ )
	{
		vector<int>::iterator serchNum = find( vector1.begin(), vector1.end(), vector2.at(k) );
		if( serchNum != vector1.end() )
		{
			serchCnt++;
		}
	}
	 
	/* Output C */
	cout << serchCnt << endl;
	 
	return 0;
}

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

typedef long long ll;

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

    string s;
    cin >> s;
    if(s.size()<4) cout << "No" << endl;
    else{
        if(s[0]=='Y' && s[1]=='A' && s[2]=='K' && s[3]=='I') cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
unittest
{
	assert( [ "3", "apple", "orange", "apple" ].parse.expand.solve == 2 );
	assert( [ "5", "grape", "grape", "grape", "grape", "grape" ].parse.expand.solve == 1 );
	assert( [ "4", "aaaa", "a", "aaa", "aa" ].parse.expand.solve == 4 );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	auto ss = new string[ n ];
	foreach( ref s; ss )
	{
		input.popFront;
		s = input.front;
	}
	return tuple( ss );
}

auto solve( string[] ss )
{
	long[ string ] ks;
	foreach( s; ss )
	{
		ks[ s ]++;
	}
	return ks.length;
}


Measured memory_bytes: 26696
#include <iostream>
#include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstdlib>
#include <stack>
#include <vector>
#define INF 0x3f3f3f3f
#define MOD 1000000009
# define FOR(i,a,n) for(register int i=a; i<=n; ++i)
# define FDR(i,a,n) for(register int i=a; i>=n; --i)
typedef long long ll;

using namespace std;
int ping[1000000];
void fun()
{

}
int main()
{
    int n;
    cin >> n;
    int i = 1;
    ll sum = 1;
    ll ans;
    while(1)
    {
        sum = i*i;
        if(sum > n)
        {
            ans = (i-1)*(i-1);
            break;
        }
        i++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
using namespace std;
int main(void) {
	int N,i,cnt;
	cin >> N;
	cnt = 0;
	int*a= new int[N];
	for (i = 0; i < N; i++) {
		cin >> a[i];
	}
	for (i = 0; i < N; i++) {
		for (int j = a[i]; j % 2 == 0; j = j / 2) {
			cnt++;
		}
	}
	cout << cnt;


}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお
int gcd(int x, int y){
    return y?gcd(y,x%y):x;
}
int main() {
    int n,x ;cin >> n >> x;
    vector<int> v;
    rep(i,n) {
        int num; cin >> num;
        v.push_back(abs(num-x));
    }
    int ans = v[0];
    rep(i,n){
        ans = gcd(ans,v[i]);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    int n, ans = 0;
    cin >> n;
    
    vector<int> a(n);
    vector<int> b(n);
    vector<int> c(n-1);

    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for(int i = 0; i < n; i++) {
        cin >> b[i];
    }
    for(int i = 0; i < n-1; i++) {
        cin >> c[i];
    }

    int pre = -1;
    for(int i = 0; i < n; i++) {
        ans += b[a[i]-1];
        if (pre == a[i] - 1) ans += c[a[i]-2];
        pre = a[i];
        // cout << ans << " " << pre << endl;
        
    }

    cout << ans << endl;
    

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    map<int, int> a;
    for (int i = 0; i < n; ++i) {
        int now;
        cin >> now;
        a[now]++;
    }
    if (a.size() == 1) {
        if (a.find(0) != a.end()) {
            cout << "Yes\n";
        }
        else cout << "No\n";
        return 0;
    }
    if (a.size() > 3) {
        cout << "No\n";
        return 0;
    }
    int res = a.begin()->second;
    if (a.size() == 3) {
        for (auto now: a) {
            if (now.second != res) {
                cout << "No\n";
                return 0;
            }
        }
        set<int> used;
        for (auto now: a) {
            (used.insert(now.first));
        }
        vector<int> b;
        for (int i: used) b.push_back(i);
        if ((b[0] ^ b[1]) != b[2]) {
            cout << "No\n";
            return 0;
        }
        cout << "Yes\n";
    }
    else
    {
        set<int> used;
        for (auto now: a) {
            (used.insert(now.first));
        }
        vector<int> b;
        for (int i: used) b.push_back(i);
        sort(b.begin(), b.end());
        if (b[0] != 0) {
            cout << "No\n";
            return 0;
        }
        if (a[0] * 2 != a[b[1]]) {
            cout << "No\n";
            return 0;
        }
        cout << "Yes\n";
    }
    return 0;
}


Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std;
#define int             long long
#define pb              push_back
//#define mp              make_pair
#define pii             pair<int,int>
#define vec             vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define no_of_test(x)   int x; cin>>x; while(x--)

const int mod = 1e9 + 7;
void very_fast()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
int gcd(int a, int b)
{
	if (b == 0) return a;
	return gcd(b, a % b);
}
int binary_exponentation(int a, int b)
{
	int ret = 1;
	while (b)
	{
		if (b & 1) ret = (ret * a) % mod;
		b >>= 1;
		a = (a * a) % mod;
	}
	return ret;
}
int32_t main()
{
	very_fast();
	//no_of_test(x)
	{
		int n;
		cin >> n;
		if (n % 2 == 0)
		{
			cout << -1 << endl;
			return 0;
		}
		int m = 0;
		for (int i = 1; i <= 1e7; i++)
		{
			m = (m * 10 + 7) % n;
			if (m == 0)
			{
				cout << i << endl;
				return 0;
				//break;
			}
		}
		cout << -1 << endl;
		return 0;
	}
	return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = (n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = (s); i < (n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==v.size()-1?']':','); return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n;
    cin >> n;
    while(n > 0) n -= 1000;
    cout << -n << endl;
}

Measured memory_bytes: 3652
from string import ascii_lowercase

s = input()
k = int(input())

b = ord('a')

ret = ''
for c in s[:-1]:
    if c == 'a':
        ret += 'a'
        continue
    need = 26 - (ord(c) - b)
    if k >= need:
        k -= need
        ret += 'a'
    else:
        ret += c

k %= 26

c = s[-1]
ret += chr((ord(c) - b + k) % 26 + b)

print(ret)


Measured memory_bytes: 4092
#include <iostream>
 
using namespace std;
 
int main(){
	double d,t,s;
  	cin>>d>>t>>s;
  	double db;
  	db = (double)(d/s);
  	if(db<=t)
      cout<<"Yes"<<endl;
  	else
    	cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 3172
#include <iostream>
#include <string>
#include <cmath>
#include <vector>

using namespace std;

int main()

{
    int n, h, w;
    cin >> n >> h >> w;
    int a[n];
    int b[n];
    int count = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        cin >> b[i];
        if (a[i] >= h && b[i] >= w)
        {
            count += 1;
        }
    }
    cout << count;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<lli,lli> pll;
typedef std::vector<lli> vll;
typedef std::vector<pll> vpll;
typedef std::vector<bool> vbb;
typedef map<lli,lli>mll;
typedef map<lli,lli,greater<lli>>mllg;
lli MOD=1e9 +7;
const lli INF=1e18;
#define forr(i,p,n) for(i=p; i<n; i++)
#define be(a) a.begin(),a.end()
#define mp make_pair
#define um unordered_map
#define eb emplace_back 
#define pb push_back 
#define F first
#define S second
lli sub(lli a,lli b,lli p=MOD){return ((a%p)-(b%p)+p)%p;}
lli mult(lli a,lli b, lli p=MOD) {return ((a%p)*(b%p))%p;}
lli add(lli a, lli b, lli p=MOD) {return (a%p + b%p)%p;}
lli fpow(lli n, lli k, lli p = MOD) {lli r = 1; while(k > 0) {if (k & 1) r = r * n%p; n = n * n%p; k = k >> 1;} return r;}
lli inv(lli a, lli p = MOD) {return fpow(a, p - 2, p);}
lli fdiv(lli a,lli b,lli p=MOD){
	lli yinv=inv(b);
	lli ans=(a*yinv)%p;
	return ans;
}
ull I1018=1000000000000000000;const ull I10e5=100000;const lli I10e6=1e6;
lli ZERO=0;ull I10e9=1000000000;lli ONE=1;
void printVecpll(std::vector<pll> v){
	for(auto p:v){
		cout<<(char)p.first<<" "<<p.second<<endl;
	}
}
void printVec(std::vector<lli> v){
	for(lli i=0;i<v.size();i++){
		cout<<v[i]<<" ";
	}
	cout<<endl;
}
vll read_vec(lli n){
	lli i;
	vll v(n);
	forr(i,0,n){
		cin>>v[i];
	}
	return v;
}
void print_um(unordered_map<lli,lli>m){
	for(pair<lli,lli>p:m){cout<<p.first<<" "<<p.second<<endl;   }
}
std::vector<bool> is_prime;
std::vector<lli> primes;
void sieve(lli n){
	is_prime.resize(n+2,true);
	primes.clear();
	lli p;
	for(p=2;p*p<=n;p++){
		if(is_prime[p]){
			lli i;
			for(i=p*p;i<=n;i+=p){
				is_prime[i]=false;
			}
		}
	}
	is_prime[0]=is_prime[1]=false;
	lli i;
	for(i=2;i<=n;i++){
		if(is_prime[i]){
			primes.eb(i);
		}
	}
}

//     //FACTORIAL
// std::vector<lli> fact_vec(10004);
// void fact_fun(lli n){
// 	lli i;
// 	fact_vec[0]=1;
// 	for(i=1;i<=n+2;i++){
// 		fact_vec[i]=(fact_vec[i-1]*i)%MOD;
// 	}
// }

    //declare

// class Sol{      	
// public: 
// 	Sol(){			
// 	}
// };
int main(){	
	ios::sync_with_stdio(false);
	cin.tie(0);
 //    #ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
 //    #endif
	
	lli n;
	cin>>n;
	lli i;
	lli ns=sqrt(n);
	lli ans=INF;
	for(i=1;i<=ns;i++){
		if(n%i==0){
			lli t=n/i;
			lli s=abs(i-1)+(abs(t-1));
			ans=min(ans,s);
		}
	}
	cout<<ans<<endl;
	return 0;
}   




Measured memory_bytes: 256
#include <stdio.h>
int main (void)
{
	int a, b;
	char op;
	
	while(1){
		scanf("%d %c %d",&a,&op,&b);
		
		if(op == '?') break;
		
		if( op == '+'){
			printf("%d\n",a+b);
		}
		if( op == '-'){
			printf("%d\n",a-b);
		}
		if( op == '*'){
			printf("%d\n",a*b);
		}
		if( op == '/'){
			printf("%d\n",a/b);
		}
  }
		return 0;
 
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
#define betheflash ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define endl "\n"
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define pii pair<int,int>
#define vi vector<int>
#define vs vector<string>
#define vvi vector<vector<int>>
#define mii map<int,int>
#define msi map<string,int>
#define mis map<int,string>
#define pb push_back
#define mod 1000000007
#define PI 3.141592653589793238
using namespace std;
int main()
{
    betheflash
    int n,m;
    cin>>n>>m;
    int ans;
    ans=(n*(n-1))/2;
    ans+=(m*(m-1))/2;
    cout<<ans;
    return 0;
}

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

#define int           long long
#define S             second
#define F             first
#define pb            push_back
#define ppb           pop_back()
#define ppb           pop_back()
#define B(c)          (c).begin()
#define E(c)          (c).end()
#define all(c)        (c).begin(),(c).end()
#define rall(c)       (c).rbegin(),(c).rend() 
#define lb            lower_bound
#define si(c)         (int)((c).size())
#define lcm(a, b)      (a * (b / __gcd(a,b)))  
#define inf           (int)(2e18)
#define err           cerr << "move" << '\n';
#define endl          '\n'
#define pow(x, n)     (int)(pow(x, n))
#define mp            make_pair
#define tp            template
#define ty            typename

typedef vector<int>                           vi;
typedef pair<int,int>                         pii;
typedef vector<pii>                           vpi;
typedef priority_queue<pii, vector<pii>, greater<pii> > pq;

clock_t start;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());

tp<ty T1, ty T2, ty T3> struct query{
    T1 ss; T2 x; T3 y;
};
tp<ty T1, ty T2, ty T3> bool operator<(query<T1, T2, T3> &o1, query<T1, T2, T3> &o2){
    return o1.x < o2.x;
}
tp<ty T1, ty T2, ty T3> istream& operator>>(istream& in, query<T1, T2, T3> &q){
    in >> q.ss >> q.x >> q.y; return in;
}
tp<ty T1, ty T2, ty T3> ostream& operator<<(ostream& out, query<T1, T2, T3> &q){
    out << q.ss << " " << q.x << " " << q.y; return out;
}


void solve(){  
    int r, c;
    cin >> r >> c;
    if(min(r, c) == 1){
        cout << 1 << endl; return;
    }
    if(r*c % 2 == 0){
        cout << r*c/2 << endl;
    }
    else cout << r*c/2+1 << endl;
}

signed main(){

    ios_base::sync_with_stdio(0); 
    cin.tie(0); cout.tie(0);   

    int t = 1;
    start = clock(); 

    cout << fixed << setprecision(15);

    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin); 
    // freopen("output.txt", "w", stdout);
    // freopen("error.txt", "w", stderr);
    // #endif

    //cin >> t;
    
    while(t--){
        solve();
    }

    double time_taken = double(clock() - start) / double(CLOCKS_PER_SEC); 
    //cerr << time_taken;
}

Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
  
   input = input.split("\n");
   var S = input[0];
 // var S= parseInt(S, 10);
 
  var s1 = S.substr(0,2);
  var s2 = S.substr(2); 
 var s1 = parseInt(s1, 10);
 var s2= parseInt(s2, 10);
 
 // console.log(s1,s2);
  if (s1 > 0 && s1<=12){if (s2 > 0 &&s2<=12){var t = 'AMBIGUOUS';}
                       else{var t = 'MMYY';}
                      }
             else if (s2 > 0 && s2<=12){var t = 'YYMM';}
                           else{var t  = 'NA';}   
                           console.log(t);     
  }
 
  
  //*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
  



Measured memory_bytes: 7500
from math import ceil
def check(x,hp):
    hp=[hh-(b*x) for hh in hp]
    cnt=0
    for p in hp:
        if p<=0:continue
        cnt+=ceil(p/(a-b))
    return cnt<=x

n,a,b=map(int,input().split())
h=[int(input()) for i in range(n)]
lo=0
hi=10**9
while hi-lo>1:
    mid=(hi+lo)//2
    if check(mid,h):
        hi=mid
    else:
        lo=mid
ans=hi
# htとloどちらを出力すればよい？
# print(lo)
print(hi)

Measured memory_bytes: 11028
var GET = (function () {function f(s) {return new g(s);}function g(s) {this._s = s.trim().split("\n");}g.prototype.getValue = function (n) {return this._s[n];};g.prototype.getArray = function (n) {return this.stoa(this._s[n]);};g.prototype.slice = function (s, limit) {return this._s.slice(s, +limit + s || undefined).map(v => this.stox(v));};g.prototype.sliceArray = function (s, limit) {return this._s.slice(s, +limit + s || undefined).map(v => this.stoa(v));};g.prototype.stoa = function (s) {return s.split(" ").map(v => this.stox(v));};g.prototype.stox = function (v) {var i = +v;return (i === i) ? i : v;};return f;})();
var o = GET(require("fs").readFileSync("/dev/stdin", "utf8"));

console.log(main());
function main(){
    var A = o.getArray(0)[0];
    var B = o.getArray(0)[1];
    var result = A - (B * 2);
    if (result > 0) return result;
    return 0;
}

Measured memory_bytes: 7372
use std::cmp::Ordering;
use std::io;
#[derive(Clone, Copy)]
struct Point {
    x: f64,
    y: f64,
}
// impl Ord for f64 {}

fn cross(a: &Point, b: &Point) -> Ordering {
    if a.x.atan2(a.y) < b.x.atan2(b.y) {
        Ordering::Less
    } else {
        Ordering::Greater
    }
}
fn main() {
    let mut buft = String::new();
    io::stdin().read_line(&mut buft).unwrap();
    let n: usize = buft.trim().parse().unwrap();

    let mut points: Vec<Point> = Vec::new();
    for _ in 0..n {
        buft.clear();
        io::stdin().read_line(&mut buft).unwrap();
        let tmp: Vec<f64> = buft
            .trim()
            .split_whitespace()
            .map(|x| x.parse::<f64>().unwrap())
            .collect();
        points.push(Point {
            x: tmp[0],
            y: tmp[1],
        });
    }
    let mut ans: f64 = 0.0;
    points.sort_by(cross);

    for i in 0..n as usize {
        let mut j = i;
        let mut tx: f64 = 0.0;
        let mut ty: f64 = 0.0;
        let mut cnt = 0;
        while cnt < n {
            tx += points[j].x as f64;
            ty += points[j].y as f64;
            let t = (tx * tx + ty * ty).sqrt();
            if t > ans {
                ans = t;
            }
            cnt += 1;
            j += 1;
            j = j % n;
        }
    }

    println!("{:.*}", 20, ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int
#define pb push_back
typedef pair<ll,ll> ipair;
#define F first
#define S second
 
/*
//functions from gfg
 
long long int power(long long int x,long long int y,long long  int p)
{
    long long int res = 1;     // Initialize result
 
    x = x % p;  // Update x if it is more than or 
                // equal to p
 
    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            {//d=(long double)x/p;
            res = (res*x) % p;
            }
 
        // y must be even now
        y = y>>1; // y = y/2
        x=(x*x)%p;
        
    }
    return res%p;
}
 
long long int gcd(long long int a,long long int b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
}
 
long long int binomialCoeff(long long int n, ll k) 
{ 
    ll res = 1; 
  
    // Since C(n, k) = C(n, n-k) 
    if (k > n - k) 
        k = n - k; 
  
    // Calculate value of [n*(n-1)*---*(n-k+1)] / [k*(k-1)*---*1] 
    for (ll i = 0; i < k; ++i) 
    { 
        res *= (n - i); 
        res /= (i + 1); 
    } 
  
    return res; 
} 
 

void sieve(int n, vector<ll> &primes) 
{ 
    vector<int> prime(n,1);
    ll p;
    for ( p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == 1) 
        { 
            
            for (int i=p*p; i<=n; i += p) 
                prime[i] = 0; 
        } 
    } 
  
    for(p=2;p<=n;p++)
    {
        if(prime[p])
        primes.pb(p);
    }
   
} 


void dfs(vector<ll> adj[] ,ll src,vector<ll> &vis)
{
    vis[src]=1;
    for(ll i=0;i<adj[src].size();i++)
    {
        if(vis[adj[src][i]]==0)
        dfs(adj,adj[src][i],vis)
    }
}
 
*/

int main() {
	ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    std::cout.tie(NULL);
    
    
	ll n,i,j,p,k,m,ans=0;
    cin>>n;
    vector<pair<ll,ll> > a(n);
    for(i=0;i<n;i++)
    {
        cin>>p>>k;
        a[i]={k,p};
    }
    sort(a.begin(),a.end());
    ll TIME = 0;ans=0;
    for(i=0;i<n;i++)
    {
        if(TIME+a[i].S>a[i].F)
        {
            ans=-1;break;
        }
        TIME+=a[i].S;
        
    }
    if(ans==-1)
    {
        cout<<"No"<<endl;
    }
    else cout<<"Yes"<<endl;
    
    
    
    
    
    
    // for(i=0;i<n;i++)
    // {
    //     cout<<a[i]<<" ";
    // }
    // cout<<endl;
    
	return 0;
}

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

int main(){
    int a,b,c,x;
    cin >> a >> b >> c >> x;
    int ans=0;
    int v;

    for(int i=0; i<=a; i++){
        for(int j=0; j<=b; j++){
            for(int k=0; k<=c; k++){
                v=500*i+100*j+50*k;
                if(x==v) ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3616
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Eric
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskCC solver = new TaskCC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskCC {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            long a = in.nextInt();
            long b = in.nextInt();

            long pgcd = pgcd(a, b);
            out.println((a / pgcd) * b);
        }

        private long pgcd(long a, long b) {
            if (b == 0)
                return a;
            if (a < b)
                return pgcd(b, a);
            else {
                long div = a / b;
                return pgcd(b, a - div * b);
            }
        }

    }
}



Measured memory_bytes: 21716
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

// increment
#define rep_n(_1, _2, _3, NAME, ...) NAME
#define rep_2(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define rep_3(i, initial, n) for (int(i) = (int)(initial); (i) < (int)(n); ++(i))
#define rep(...) rep_n(__VA_ARGS__, rep_3, rep_2, rep_1)(__VA_ARGS__)
// decrement
#define rep_r_n(_1, _2, _3, NAME, ...) NAME
#define rep_r_2(i, n) for (int(i) = (int)(n); (i) > 0; (i)--)
#define rep_r_3(i, initial, n) for (int(i) = (int)(initial); (i) > (int)(n); (i)--)
#define rep_r(...) rep_r_n(__VA_ARGS__, rep_r_3, rep_r_2)(__VA_ARGS__)
// define type definition
using namespace std;
typedef long long ll;
using mpint = boost::multiprecision::cpp_int; // 多倍長整数（任意精度）
typedef pair<int, int> P;

// define construct variable
const double EPS = numeric_limits<double>::epsilon();
// 10^9 + 7
const ll MOD = ll(1e9) + 7;
const ll INF = ll(1e10);
const string ALPHABET = "abcdefghijklmnopqrstuvwxyz";
const double PI = acos(-1);

// define methods
// 最大公約数
ll gcd(const ll a, const ll b) { return b ? gcd(b, a % b) : a; }
// 最小公倍数
ll lcm(const ll a, const ll b) { return a / gcd(a, b) * b; }
// char -> int
int ctoi(char c) { return (int)(c - '0'); }
// 素因数分解
vector< pair<ll, ll> > prime_factorize(ll n)
{
	vector<pair<ll, ll>> p;
	for (ll i = 2; i * i <= n; i++)
	{
		if ((n % i) != 0)
			continue;
		pair<ll, ll> a = make_pair(i, 0);
		while ((n % i) == 0)
		{
			n /= i;
			a.second += 1;
		}
		p.push_back(a);
	}

	if (n != 1)
		p.push_back(make_pair(n, 1));
	return p;
}
// 組み合わせの整合性を保つ（後ほど解析する）
ll modinv(ll a)
{
	ll b = MOD, u = 1, v = 0;
	while (b)
	{
		ll t = a / b;
		a -= t * b;
		swap(a, b);
		u -= t * v;
		swap(u, v);
	}
	u %= MOD;
	if (u < 0)
	{
		u += MOD;
	}
	return u;
}
// 順列
ll permutation(const ll n, const ll m)
{
	ll result = 1;
	for (ll i = n; i > n - m; i--)
	{
		result = (result * i) % MOD;
	}
	return result;
}

// 繰り返し n 乗法
ll repeat_square(const ll n, const ll x)
{
	if (x == 0)
		return 1;
	ll res = repeat_square(n, x / 2);
	res = res * res % MOD;
	if ((x % 2) == 1)
		res = res * n % MOD;
	return res;
}
// 組み合わせ nCm
ll combination(ll n, ll m)
{
	ll p = permutation(n, m);
	ll div = 1;
	for (ll i = 2; i <= m; i++)
	{
		div = (div * i) % MOD;
	}
	return (p * modinv(div)) % MOD;
}

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

	vector<ll> A(N, 0), B(N, 0);	
	rep (i, N) {
		cin >> A[i] >> B[i];
	}

	sort(A.begin(), A.end());
	sort(B.begin(), B.end());

	ll result = 0;
	ll l = 0, r = 0;
	if (N % 2 == 1) {
		l = A[N/2];
		r = B[N/2];
	} else {
		l = A[N/2-1] + A[N/2];
		r = B[N/2-1] + B[N/2];
	}
	result = r - l + 1;
	cout << result << endl;
	return 0;
}


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

int main() {
	int n, m;
	
	cin >> n >> m;
	
	//n本,m本の通りがなす行列はn-1行, m-1列
	
	n = n-1;
	m = m-1;
	
	cout << n * m;
	
	cout << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a;
    cin>>a;
    if(a=="SUN")cout<<7;
    else if(a=="MON")cout<<6;
    else if(a=="TUE")cout<<5;
    else if(a=="WED")cout<<4;
    else if(a=="THU")cout<<3;
    else if(a=="FRI")cout<<2;
    else  cout<<1;

    

}





Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ll long long
#define P pair<int,int>
#define fast_io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const int MOD = 1000000007;
const int INF = 2002002002;
const ll LLINF = 9009009009009009009;
using namespace std;

int main() {
    fast_io
    int a, b;
    cin >> a >> b;
    rep(i,2000) {
        if (i*8/100 == a && i/10 == b) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

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

int main() {
    int a, b, c; cin >> a >> b >> c;
    int ans = 0;
    if (a < b) {
        ans += a;
        ans += min(b, c);
    }
    else {
        ans += b;
        ans += min(a, c);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline


def main():
    H, W, D = map(int, input().split())
    d = [0]*(H*W)
    for h in range(H):
        a = list(map(int, input().split()))
        for i, x in enumerate(a):
            d[x-1] = h*W + i

    mp = [0]*(H*W)
    for i in range(D, H*W):
        mp[i] = mp[i-D] + abs(d[i]//W - d[i-D]//W) + abs(d[i]%W - d[i-D]%W)

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


if __name__ == '__main__':
    main()


Measured memory_bytes: 11260
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define ll long long
//#define int long long
using namespace std;
void boost()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
}
void free()
{
	freopen("A.in", "r", stdin);
	freopen("A.out", "w", stdout);
}
stack <char> st;
main()
{
	//free();
	boost();
	string s;
	cin >> s;
	for(int i = 0; i < s.size(); i++)
	{
		if(s[i] == 'S') st.push(s[i]);
		else if(s[i] == 'T')
		{
			if(st.size() && st.top() == 'S') st.pop();
			else st.push(s[i]);
		}
	}
	cout << st.size();
}


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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int N;
    cin >> N;
    double x[N];
    string u[N];
    for (int i = 0; i < N; ++i) {
        cin >> x[i] >> u[i];
    }
    
    double res;
    for (int i = 0; i < N; ++i) {
        if (u[i] == "JPY") {
            res += x[i];
        } else {
            res += x[i] * 380000;
        }
    }
    
    cout << res << endl;
    return 0;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp make_pair
#define ff first
#define ss second

using namespace std;
using vi=vector<int>;
using pii=pair<int, int>;
using ull=unsigned long long;

typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
	string s1, s2;
	cin >> s1 >> s2;

	int ans = 0;
	for (int i = 0; i < 3; i++)
		ans += (s1[i] == s2[i]);

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


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>

using namespace std;


int main() {

    int N, D;
    cin >> N >> D;

    cout << (N + D*2+1 - 1) / (D*2+1) << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int n, k;
int main()
{
    char a[55];
    scanf("%d %d ", &n, &k);
    for(int i=1; i<=n; i++){
        scanf("%c", &a[i]);
    }
    for(int i=1; i<=n; i++){
        if(i==k){
            printf("%c", a[i]+32);
            continue;
        }
        printf("%c", a[i]);
    }
}

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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

const ll INF = (1ll << 60);
vector<ll> a;
vector<vector<ll>> graph;
vector<ll> dp;
vector<ll> ans;

void dfs(ll now, ll pre)
{
    ll num = a.at(now);
    ll ind = lower_bound(all(dp), num) - dp.begin();
    ll mae = dp.at(ind);
    dp.at(ind) = num;
    ll tmp = lower_bound(all(dp), INF) - dp.begin();
    ans.at(now) = tmp;
    ll i;
    for(i = 0;i < graph.at(now).size();++i){
        ll next = graph.at(now).at(i);
        if(next != pre){
            dfs(next, now);
        }
    }
    dp.at(ind) = mae;
    return;
}

int main()
{
    ll i,j;
    ll n;
    cin >> n;
    a.resize(n);
    rep(i,n) cin >> a.at(i);
    graph.resize(n);
    rep(i,n-1){
        ll u,v;
        cin >> u >> v;
        --u,    --v;
        graph.at(u).push_back(v);
        graph.at(v).push_back(u);
    }
    dp.assign(n, INF);
    ans.resize(n);
    dfs(0, -1);
    rep(i,n) cout << ans.at(i) << endl;

    return 0;
}

Measured memory_bytes: 33272
#include <iostream>
#include <fstream>
#include <algorithm>
#include <functional>
using namespace std;

int main() {

	//ifstream cin("INPUT.txt");
	//ofstream cout("OUTPUT.txt");

	int n, A, B, C, i, j, k, max, calsum, pricesum;
	int D[10000] = {0};
	cin >> n >> A >> B;
	cin >> C;
	for(i = 0; i < n; i++)
		cin >> D[i];
	sort(D, D+10000, greater<int>());
	calsum = C;
	pricesum = A;
	max = calsum / pricesum;
	for(i = 0; i < n; i++) {
		calsum += D[i];
		pricesum += B;
		max = (max > calsum / pricesum) ? max : calsum / pricesum;
	}

	cout << max << endl;

	return 0;

}

Measured memory_bytes: 1216
#define _GLIBCXX_DEBUG
#include <iostream>
#include <cmath>
#include <cstring>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <algorithm>
#include <numeric>

typedef long long ll;
const ll INF = 1e18;

int main(int argc, char* argv[])
{
  ll D, G;
  std::cin >> D >> G;

  std::vector< ll > vp(D, 0);
  std::vector< ll > vc(D, 0);
  std::vector< ll > vsum(D, 0);
  for (ll i = 0; i < D; i++) {
    std::cin >> vp[i] >> vc[i];
    vsum[i]  = (i+1) * 100 * vp[i] + vc[i];
  }

  ll ans = INF;
  for (ll i = 0; i < (1<<D); i++) {
    std::map< ll, bool > used;
    ll count  = 0;
    ll target = G;
    for (int j = 0; j < D; j++) {
      if ((i >> j) & 1) {
	target -= vsum[j];
	count += vp[j];
	used[j] = true;
      }
    }
    for (ll i = D - 1; i >=0; i--) {
      if (target <= 0) {
	break;
      }
      if (!used[i]) {
	int num = std::min(vp[i], (target + (i+1) * 100 - 1) / ((i+1) * 100));
	count += num;
	target -= num * (i+1) * 100;
      }
    }

    if (target <= 0) {
      ans = std::min(ans, count);
    }
  }

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


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

#define st first
#define nd second
#define all(x) (x).begin(), (x).end()

using namespace std;
using namespace placeholders;

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

template <class T> void mini(T &l, T r){l = min(l, r);}
template <class T> void maxi(T &l, T r){l = max(l, r);}

template <class TH> void _dbg(const char *sdbg, TH h){cerr << sdbg << "=" << h << "\n";}
template <class TH, class ...TA> void _dbg(const char *sdbg, TH h, TA... a){
	while (*sdbg != ','){cerr << *sdbg++;}cerr << "=" << h << ","; _dbg(sdbg + 1, a...);
}
template <class T> ostream &operator <<(ostream &os, vector<T> V){
	os << "["; for (auto vv: V) os << vv << ","; return os << "]";
}
template <class L, class R> ostream &operator <<(ostream &os, pair<L, R> P){
	return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef SFIC
	#define eput(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
	#define eput(...) 218
#endif

const int N = 18;

pii a[1 << N][2];

int main(){
	int n;
	scanf("%d", &n);
	int n0 = 1 << n;
	for (int i = 0; i < n0; ++i){
		scanf("%d", &a[i][0].st);
		a[i][0].nd = i;
		a[i][1] = pii(0, -1);
	}
	for (int i = 0; i < n0; ++i){
		for (int j = 0; j < n; ++j){
			if (~i >> j & 1)
				continue;
			auto &b = a[i ^ 1 << j];
			for (int k = 0; k < 2; ++k){
				if (b[k].nd == -1)
					continue;
				if (a[i][0].st < b[k].st)
					a[i][1] = a[i][0], a[i][0] = b[k];
				else if (a[i][0] != b[k] && a[i][1].st < b[k].st)
					a[i][1] = b[k];
			}
		}
	}
	int t = 0;
	for (int i = 1; i < n0; ++i){
		t = max(t, a[i][0].st + a[i][1].st);
		printf("%d\n", t);
	}
	return 0;
}


Measured memory_bytes: 7168
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vei;
typedef vector<vector<int>> ve_vei;
typedef pair<ll, ll> l_l;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define fs first
#define sc second
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
 
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

    int N, M ; cin >> N >> M;

    int cnt = 0;
    vei love(M);
    rep(i,N){
        int K; cin >> K;
        rep(j,K) {
            int a; cin >> a;
            love[a - 1]++;
        } 
        rep(i,M) if(love[i] == N) cnt++;
    }
    cout << cnt << endl;
        
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static Scanner in = new Scanner(System.in);

	public static void main(String[] args) {
		int N = in.nextInt();
		int[] l = new int[2 * N];
		for(int i = 0; i < 2 * N; i++){
			l[i] = in.nextInt();
		}
		Arrays.sort(l);
		int sum = 0;
		for(int i = 0; i < 2 * N; i += 2){
			sum += Math.min(l[i], l[i + 1]);
		}
		System.out.println(sum);
	}
}


Measured memory_bytes: 22608
#include <cstdio>
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
#include <cmath>
#include <iomanip>
#include <regex>
#include <queue>
#include <set>
#include <cassert>
using namespace std;
using ll = long long;
using plong = pair<ll,ll>;

const long MOD = 1000000007;

ll N,M,X;

int main(){
    
    cin>>N>>M>>X;
    
    ll C[N];
    ll A[N][M];
    vector<ll> sum_(M,0);
    
    for(ll i=0;i<N;i++){
        cin>>C[i];
        for(ll j=0;j<M;j++){
            cin>>A[i][j];
            sum_[j]+=A[i][j];
        }
    }
    for(ll j=0;j<M;j++){
        if(sum_[j]<X){
            cout<<-1<<endl;
            return 0;
        }
    }
    ll res=99999999999;
    for(ll bit=0;bit<(1<<N);bit++){
        ll sum=0;
        vector<ll> a(M,0);
        for(ll i=0;i<N;i++){
            if((bit>>i)&1){
                sum += C[i];
                for(ll j=0;j<M;j++){
                    a[j] += A[i][j]; 
                }
            }
        }
        bool flag=true;
        for(ll i=0;i<M;i++){
            if(a[i]<X)flag = false;
        }
        if(flag){
            res =min(res,sum);
        }
    }
    cout<<res<<endl;


}


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

int main()
{
        int n;
        long long k;
        cin >> n >> k;
        vector<int> a(n);
        for (int i = 0; i < n; ++i) cin >> a[i];
        vector<int> ord(n+1, -1);
        vector<int> s;
        int c = 1, l = 0;
        {
                int v = 1;
                while (ord[v] == -1) {
                        ord[v] = s.size();
                        s.push_back(v);
                        v = a[v-1];
                }
                c = s.size() - ord[v];
                l = ord[v];
        }

        if (k < l) cout << s[k] << endl;
        else {
                k -= l;
                k %= c;
                cout << s[l+k] << endl;
        }
        return 0;
}


Measured memory_bytes: 5896
// C - Reconciled?
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MOD 1000000007

ll factorial_mod(ll n){//階乗％MOD
	ll ans = n;
	while(n>1) ans = ans * --n % MOD;
	return ans;
}

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

	if(N!=M && ((N<M && N+1!=M) || (N>M && N!=M+1))){
		cout<< 0 <<endl;
		return 0;
	}

	ll ans =  factorial_mod(N) * factorial_mod(M) % MOD;
	if(N == M) ans = ans * 2 % MOD;
	cout<< ans <<endl;
}

Measured memory_bytes: 256