akhauriyash/Code-Regression huggingface dataset:
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

using Table = vector< pair<int, int> >;
const pair<int, int> INIT(INF, 0);

int A[5010], sz[5010];
vector<int> G[5010];

void dfs(int cur, int par=-1) {
    sz[cur] = 1;
    for(int to : G[cur]) {
        if(to == par) continue;
        dfs(to, cur);
        sz[cur] += sz[to];
    }
}

Table merge(const Table &A, const Table &B) {
    int N = A.size(), M = B.size();
    Table res(N + M, INIT);
    for(int i=N-1; i>=0; i--) {
        for(int j=M-1; j>=0; j--) {
            // 和を考える
            chmin(res[i+j].first, A[i].first + B[j].first);
            if(B[j].first < 0 or B[j].second) chmin(res[i+j+1].first, A[i].first);

            // 全て正になるか考える
            res[i+j].second |= A[i].second & B[j].second;
            if(B[j].first < 0 or B[j].second) res[i+j+1].second |= A[i].second;
        }
    }
    return res;
}

Table solve(int cur, int par=-1) {
    Table res_dp(1);
    res_dp[0].first = A[cur];
    res_dp[0].second = (A[cur] > 0);
    for(auto to : G[cur]) {
        if(to == par) continue;
        Table child_dp = solve(to, cur);
        res_dp = merge(res_dp, child_dp);
    }
    return res_dp;
}

signed main() {
    int N; cin >> N;    
    for(int i=0; i<N; i++) {
        cin >> A[i];
    }
    for(int i=0; i<N-1; i++) {
        int u, v; cin >> u >> v;
        u--; v--;
        G[u].push_back(v);
        G[v].push_back(u);
    }

    dfs(0);
    auto dp = solve(0);
    int ans = INF;
    for(int i=0; i<N; i++) {
        if(dp[i].first < 0) ans = min(ans, i);
        if(dp[i].second == true) ans = min(ans, i);
    }
    cout << ans << endl;
    return 0;
}


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

set<string> res;
string c[10];
bool use[10];
int n,k;
string ans;

void rec(int a){
  string tmp;
  if(!a){
    res.insert(ans);
    return;
  }
  for(int i=0;i<n;i++){
    if(!use[i]){
      use[i] = true;
      tmp = ans;
      ans += c[i];
      rec(a-1);
      ans = tmp;
      use[i] = false;
    }
  }
}

int main(){
  while(1){
    cin >> n;
    cin >> k;
    if(!n && !k)break;

    for(int i=0;i<n;i++)cin >> c[i];
    for(int i=0;i<n;i++)use[i] = false;

    res.clear();
    rec(k);

    cout << res.size() << endl;
  }
}

Measured memory_bytes: 0
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int n,a,b,ch[200000],cnta=1,cntb=2,cntc=3,chp,chm;
vector<int>v[200000];
queue<int> que;
int main(void){
    cin>>n;
    if(n<=0){
        for(int i=0;i<n;i++){
            cout<<i+1<<" ";
        }
        cout<<endl;
        return 0;
    }
    for(int i=0;i<n-1;i++){
        cin>>a>>b;
        a--;
        b--;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    ch[0]=1;
    chp++;
    que.push(0);
    while(!que.empty()){
        int q=que.front();
        que.pop();
        for(auto x:v[q]){
            if(ch[x]==0){
                if(ch[q]==1){
                    ch[x]=-1;
                    chm++;
                }
                else {ch[x]=1;chp++;}
                que.push(x);
            }
        }
    }
    //cout<<chp<<" "<<chm<<endl;
    if(chp<=n/3){
        for(int i=0;i<n;i++){
            if(ch[i]==1){
                ch[i]=cntc;
                cntc+=3;
            }
            else{
                if(cnta>n&&cntb>n){
                    ch[i]=cntc;
                    cntc+=3;
                }
                else if(cnta>n){
                    ch[i]=cntb;
                    cntb+=3;
                }
                else {
                    ch[i]=cnta;
                    cnta+=3;
                }
            }
        }
    }
    else if(chm<=n/3){
        for(int i=0;i<n;i++){
            if(ch[i]==-1){
                ch[i]=cntc;
                cntc+=3;
            }
            else{
                if(cnta>n&&cntb>n){
                    ch[i]=cntc;
                    cntc+=3;
                }
                else if(cnta>n){
                    ch[i]=cntb;
                    cntb+=3;
                }
                else {
                    ch[i]=cnta;
                    cnta+=3;
                }
            }
        }
    }
    
    else{
    for(int i=0;i<n;i++){
        if(ch[i]==1){
            if(cnta>n){
                ch[i]=cntc;
                cntc+=3;
            }
            else{
                ch[i]=cnta;
                cnta+=3;
            }
        }
        
        if(ch[i]==-1){
            if(cntb>n){
                ch[i]=cntc;
                cntc+=3;
            }
            else{
                ch[i]=cntb;
                cntb+=3;
            }
        }
        
        
    }
    }
    for(int i=0;i<n;i++){
        cout<<ch[i]<<" ";
    }
    cout<<endl;
}


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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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;}

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
	int x,a;cin>>x>>a;
	if(x<a)cout<<0<<endl;
	else cout<<10<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <bitset>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
 
using namespace std;
typedef long long ll;
 
int main(){
  int x;
  cin >> x;
  for(int i=1;i<400;i++){
    if(x*i%360==0){
      cout << i << endl;
      break;
    }
  }

  return 0;
}


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

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

    vector<int> a(n);

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

    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());

    int i = 0;
    int k;
    long ansA = 0;

    // a1 < a2 > a3 < a4 > ...

    // 係数 +2
    for (k = 1; k < n - 1; k += 2) {
        ansA += (2 * a[i++]);
    }

    // 係数 +1
    if (k == n - 1) {
        ansA += a[i++];
    }

    // 係数 -1
    ansA -= a[i++];
    if (n > 2 && ((n - 1) % 2 == 0)) {
        ansA -= a[i++];
    }

    // 係数 -2
    for (k = 2; k < n - 1; k += 2) {
        ansA -= (2 * a[i++]);
    }

    // a1 > a2 < a3 > a4 < ...
    long ansB = 0;
    i = 0;

    // 係数 +2
    for (k = 2; k < n - 1; k += 2) {
        ansB += (2 * a[i++]);
    }

    // 係数 +1
    ansB += a[i++];
    if (n > 2 && ((n - 1) % 2 == 0)) {
        ansB += a[i++];
    }

    // 係数 -1
    if (n % 2 == 0) {
        ansB -= a[i++];
    }

    // 係数 -2
    for (k = 1; k < n - 1; k += 2) {
        ansB -= (2 * a[i++]);
    }
    cout << max(ansA, ansB) << endl;

    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define cmin(a,b) (a>b?a=b:a)
#define cmax(a,b) (a<b?a=b:a)
#define mem(a,k) memset(a,k,sizeof(a))
#define lop(i,s,t) for(int i=s;i<(t);++i)
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
#define fore(i,v) for(int i=G[v],d=es[i].d;i;i=es[i].nxt,d=es[i].d)
using namespace std;

#define Pr(f,...) //fprintf(stderr,f,##__VA_ARGS__),fflush(stderr)

typedef long long ll;

template<typename T>
void read(T &x){
	x=0; 
	char c;
	for(c=getchar();!isdigit(c);c=getchar()); 
	for(;isdigit(c);c=getchar())x=x*10+c-'0'; 
}

/*
const int N=,P=;

int mul(int a,int b){ return 1ll*a*b%P; }
int add(int a,int b){ a+=b; return a>=P?a-P:a; }
int sub(int a,int b){ a-=b; return a<0?a+P:a; }
int gcd(int a,int b){ return !b?a:gcd(b,a%b); }
*/


const int N = 3e5 + 50, L = 20; 

bool vis[N]; 
int n, m, deg[N], tag[N];
vector<int> G[N], T[N]; 
set<pair<int, int>> res;


void dfs(int v, int p) {
	++deg[p]; 
	vis[v] = true;
	for (int d : G[v]) if (d != p) {
		if (!vis[d]) {
			T[v].pb(d);
			Pr("Link %d, %d\n", v, d); 
			dfs(d, v);
		} else {
			int a = v, b = d; 
			if (a > b) swap(a, b); 
			if (res.count(mp(a, b))) continue;
			Pr("Ins %d, %d\n", a, b); 
			res.insert(mp(a, b)); 
			++deg[a]; 
		}
	}	
}

void calc(int v, int p) {
	for (int d : T[v]) if (d != p) {
		calc(d, v); 
		tag[v] ^= tag[d]; 
	}
	if (v != 1) {
		if (tag[v]) res.insert(mp(v, p)); 
		else res.insert(mp(p, v));
	}
}

int main(int argc,char *argv[]){
#ifdef CURIOUSCAT
	freopen("d.in", "r", stdin); 
#endif
	read(n), read(m); 
	if (m % 2 != 0) {
		puts("-1"); 
		return 0; 
	}
	rep(i, 1, m) {
		int u, v; 
		read(u), read(v); 
		G[u].pb(v), G[v].pb(u); 
	}
	dfs(1, 0); 
	vector<int> t; 
	rep(i, 1, n) if (deg[i] % 2) t.pb(i); 
	Pr("t.size = %d\n", (int) t.size()); 
	assert(t.size() % 2 == 0); 
	for (size_t i = 0; i < t.size(); i += 2) {
		int u = t[i], v = t[i + 1];
		tag[u] ^= 1, tag[v] ^= 1; 
	}
	calc(1, 0); 
	for (auto p : res) {
		printf("%d %d\n", p.first, p.second);
	}
	return 0; 
}



Measured memory_bytes: 38524
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,j;
    cin>>n;
    double p[n+1];
    for(i=1;i<=n;i++)
        cin>>p[i];
    double dp[n+1][n+1];
    dp[1][1]=p[1];
    dp[1][0]=1-p[1];
    for(j=2;j<=n;j++)
        dp[1][j]=0;
    for(i=2;i<=n;i++)
    {
        dp[i][0] = (1-p[i])*dp[i-1][0];
        for(j=1;j<=n;j++)
        {
            if(j>i)
            {
                dp[i][j]=0;
                break;
            }
            dp[i][j]=p[i]*dp[i-1][j-1]+(1-p[i])*dp[i-1][j];

        }
    }
    double sum = 0;
    for(i=n/2+1;i<=n;i++)
        sum+=dp[n][i];
    cout<<setprecision(10)<<sum<<endl;
    return 0;
}


Measured memory_bytes: 70016
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int N, T[100005], A[100005];
int K[100005]; // 確定している山の高さ

int main() {
  INCANT;
  cin >> N;
  rep(i, N) cin >> T[i];
  rep(i, N) cin >> A[i];
  if (T[N-1]!=A[0]) {
    cout << 0 << "\n";
    return 0;
  }
  K[0] = T[0];
  rep(i, N) {
    if (K[i]>0) continue;
    if (i==0) continue;
    if (T[i]-T[i-1]>0) K[i] = T[i];
  }
  K[N-1] = A[N-1];
  for (int i=N-2; i>=0; i--) {
    if (A[i]-A[i+1]>0) {
      if (T[i] < A[i]) {
        cout << 0 << "\n";
        return 0;
      }
      if (K[i] ==0) K[i] = A[i];
    }
  }
  ll ans=1ll;
  int left=0;
  int right=1;
  while(right<N) {
    if (K[right]>0) {
      ll tmp=1;
      rep(i, right-left-1) {
        tmp*=min(K[right], K[left]);
        tmp%=MOD;
      }
      ans*=tmp;
      ans%=MOD;
      left = right;
      right++;
    } else right++;
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 1408
#include <cstdio>
#include <iostream>

using namespace std;

const int inf = 1001001001;
int n,m,a,b,c,d,x1,x2,y1,y2;
int K[32][32];

void floyd(){
    for(int k=1;k<=n;k++){
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++){
                if(K[i][j] > K[i][k] + K[k][j])
                    K[i][j] = K[i][k] + K[k][j];
            }
        }
    }
}

void show(){
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            if(j!=1)
                cout <<" ";
            cout << K[i][j];
        }
        cout << endl;
    }
}

int main(){
    for(int i=0;i<32;i++){
        for(int j=0;j<32;j++){
            K[i][j] = inf;
        }
    }
    scanf("%d%d", &n,&m);
    for(int i=0;i<m;i++){
        scanf("%d,%d,%d,%d", &a, &b, &c, &d);
        // cerr << "read " << a << " " << b << " " << c << " " << d << endl;
        K[a][b] = c;
        K[b][a] = d;
    }
    floyd();
    scanf("%d,%d,%d,%d", &x1,&x2,&y1,&y2);
    // show();
    cout << y1 - y2 - K[x1][x2] - K[x2][x1]<< endl;
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
        using namespace std;
        #define int long long
const int MAX = 2000003;
const int MOD = 1000000007;

//
int fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
int COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

        signed main() {
    cout<<fixed<<setprecision(15);
        int a[3];
        cin>>a[0]>>a[1]>>a[2];
        sort(a,a+3);
        if((a[0]==a[1]&&a[1]!=a[2])||(a[0]!=a[1]&&a[1]==a[2]))cout<<"Yes";
        else cout<<"No";

       

        }


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#define LL long long
#define INF 1<<31-1
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define FOR(i,a,n) for(i=a;i<n;i++)
#define MOD 1000000007
#define NUM 100001

void swap(int* a,int* b){int tmp=*a;*a=*b;*b=tmp;}
int GCD(int a,int b){int c=1,tmp=MAX(a,b);b=MIN(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
int LCM(int a,int b){return a*b/GCD(a,b);}
int POW(LL a,LL n){LL ans=1;while(n>0){if(n&1)ans=ans*a%MOD;a=a*a%MOD;n>>=1;}return (int)ans;}
int icmp(const void* a,const void* b){return *(int*)a-*(int*)b;}
int ccmp(const void* a,const void* b){return *(char*)a-*(char*)b;}
int scmp(const void* a,const void* b){return strcmp(*(char**)a,*(char**)b);}
LL fac[NUM],finv[NUM],inv[NUM];
void comi(){int i;fac[0]=fac[1]=1;finv[0]=finv[1]=1;inv[1]=1;FOR(i,2,NUM){fac[i]=fac[i-1]*i%MOD;inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;finv[i]=finv[i-1]*inv[i]%MOD;}}
int com(int n,int k){if(n<k||n<0||k<0)return 0;return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;}


int main(){
  int A,B,i,ans=0;
  scanf("%d%d",&A,&B);
  if(A<10&&B<10)ans=A*B;
  else ans=-1;

  printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
//#define MOD 1000000007
#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

int main(){
    int N; cin >> N;
    string s; cin >> s;
    if(N % 2 == 1){
        cout << "No" << endl;
        return 0;
    }
    else{
        bool ok = true;
        rep(i,N/2){
            if(s[i] != s[i+N/2]) ok = false;
        }
        cout << (ok ? "Yes" : "No") << endl;
    }
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;
const ll MOD = 1000000007;
const int MAX = 200000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
//最小公倍数
int lcm(int x, int y) { return x / gcd(x, y) * y; }
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    string S,T; cin >> S >> T;
    int A,B; cin >> A >> B;
    string U; cin >> U;
    if(S==U){
        cout << A-1 << " " << B << endl;
    }else{
        cout << A << " " << B-1 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int):
    k = N % 1000
    if k != 0:
        print(1000-k)
    else:
        print(0)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 61260
#include <iostream>
#include <math.h>
#include <vector>
using namespace std;
const int n=100001;
int a[n];
 
int main(){
  for(int i=0;i<n;i++){
    a[i]=1;
  }
  for(int i=2;i<sqrt(n);i++){
    if(a[i]){
      for(int j=0;i*(j+2)<n;j++){
        a[i*(j+2)]=0;
      }
    }
  }
  a[0]=a[1]=0;
  vector<int> b(n,0);
  for(int i=3;i<n;i+=2){
    if(a[i]==1&&a[(i+1)/2]==1) b[i]=1;
  }
  for(int i=1;i<n;i++){
    b[i]+=b[i-1];
  }
  int q;cin>>q;
  vector<int> ans(q);
  for(int i=0;i<q;i++){
    int l,r;cin>>l>>r;
    ans[i]=b[r]-b[l-1];
  }
  for(int i=0;i<q;i++) cout<<ans[i]<<endl;
}

Measured memory_bytes: 4272
#include <iostream>

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

struct Node {
  int p, l, r;
};

Node t[25];
int sib[25];
int d[25];
int h[25];

void print(int n) {
  rep(i, n) {
    int deg = (t[i].l != -1) + (t[i].r != -1);

    std::string type;
    if (t[i].p == -1)
      type = "root";
    else if (deg == 0)
      type = "leaf";
    else
      type = "internal node";

    printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, "
           "height = %d, %s\n",
           i, t[i].p, sib[i], deg, d[i], h[i], type.c_str());
  }
}

void setDepth(int i, int depth) {
  d[i] = depth;
  if (t[i].l != -1)
    setDepth(t[i].l, depth + 1);
  if (t[i].r != -1)
    setDepth(t[i].r, depth + 1);
}

void setHeight(int i) {
  if (t[i].l == -1 && t[i].r == -1) {
    h[i] = 0;
    return;
  }

  int h1, h2;
  h1 = h2 = 0;
  if (t[i].l != -1) {
    setHeight(t[i].l);
    h1 = h[t[i].l] + 1;
  }
  if (t[i].r != -1) {
    setHeight(t[i].r);
    h2 = h[t[i].r] + 1;
  }
  h[i] = std::max(h1, h2);
}

int main() {
  int n;
  std::cin >> n;
  int id, left, right;

  rep(i, n) {
    t[i] = Node{-1, -1, -1};
    sib[i] = -1;
  }

  rep(i, n) {
    std::cin >> id >> left >> right;
    t[id].l = left;
    t[id].r = right;
    if (left != -1) {
      sib[left] = right;
      t[left].p = id;
    }
    if (right != -1) {
      sib[right] = left;
      t[right].p = id;
    }
  }

  int root;
  rep(i, n) {
    if (t[i].p == -1)
      root = i;
  }
  setDepth(root, 0);
  setHeight(root);
  print(n);
  return 0;
}



Measured memory_bytes: 3236
//12252024832524
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; 

typedef long long LL;
const int MAXN = 100005;
int n,m;
int h[MAXN];
bool bd[MAXN];

int Read()
{
	int x = 0,f = 1;char c = getchar();
	while(c > '9' || c < '0'){if(c == '-')f = -1;c = getchar();}
	while(c >= '0' && c <= '9'){x = (x*10) + (c^48);c = getchar();}
	return x * f;
}
void Put1(int x)
{
	if(x > 9) Put1(x/10);
	putchar(x%10^48);
}
void Put(int x,char c = -1)
{
	if(x < 0) putchar('-'),x = -x;
	Put1(x);
	if(c >= 0) putchar(c);
}
template <typename T>T Max(T x,T y){return x > y ? x : y;}
template <typename T>T Min(T x,T y){return x < y ? x : y;}
template <typename T>T Abs(T x){return x < 0 ? -x : x;}

int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	n = Read();
	m = Read();
	for(int i = 1;i <= n;++ i) h[i] = Read();
	for(int i = 1;i <= m;++ i)
	{
		int a = Read(),b = Read();
		if(h[a] >= h[b]) bd[b] = 1;
		if(h[b] >= h[a]) bd[a] = 1;
	}
	int ans = 0;
	for(int i = 1;i <= n;++ i) if(!bd[i]) ans++;
	Put(ans);
	return 0;
}

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

using namespace std;

int main(){
    int n, x, y;
    cin >> n >> x >> y;
    vector <int> ans(n);
    for (int i = 1; i <= n; i++){
        for (int j = i+1; j <= n; j++){
            int d;
            if (((i-x <= 0)&&(j <= x))||(i >= y)&&(j >= y))  ans[j-i]++;
            else if ((i-x <= 0)&&(j-y >= 0)) ans[x-i+1+j-y]++;
            else {
                d = min(j-i, abs(i-x)+1+abs(j-y));
                ans[d]++;
            }
        }
    }
    for (int i = 1; i < n; i++){
        cout << ans[i] << '\n';
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

long long cnt;
int l;
int A[1000000];
int n;
vector<int> G;

// ?????ug?????????w???????????????}?????????\???[???g
void insertionSort(int A[],int n,int g) {
	for(int i=g;i<n;i++) {
		int v = A[i];
		int j = i - g;
		while(j>=0 && A[j] >v) {
			A[j+g] = A[j];
			j -= g;
			cnt++;
		}
		A[j+g] = v;
	}
}

void shellSort(int A[], int n) {
	// ????????????G = {1, 4, 13, 40, 121, 364, 1093, ...}?????¶????
	for(int h=1; ;) {
		if(h>n) break;
		G.push_back(h);
		h = 3*h + 1;
	}
	
	// ???t????????????G[i] = g?????????w??????
	for(int i=G.size()-1; i>=0; i--) {
		insertionSort(A, n, G[i]);
	}
}

int main(void) {
	cin >> n;
	// ???????????¬??????????????????scanf?????????????????g???p
	for(int i=0; i<n; i++) scanf("%d",&A[i]);
	cnt = 0;

	shellSort(A,n);
	
	cout << G.size() << endl;
	for(int i=G.size()-1; i>=0; i--) {
		printf("%d", G[i]);
		if(i) printf(" ");
	}
	printf("\n");
	printf("%d\n",cnt);
	for(int i=0;i<n;i++) printf("%d\n",A[i]);
	
	return 0;
}

Measured memory_bytes: 7164
using System;

namespace Sample101
{
    class Program
    {
        static bool IsPalindrome(int num)
        {
            bool result = true;

            string str = num.ToString();
            char[] c = str.ToCharArray();
            int end = c.Length / 2;
            for (int i = 0; i < end; ++i)
            {
                if (c[i] != c[c.Length - 1 - i])
                {
                    result = false;
                    break;
                }
            }

            return result;
        }
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int A = int.Parse(str[0]);
            int B = int.Parse(str[1]);

            // A以上B以下の整数のうち、回文数となるものの個数を出力せよ
            int result = 0;
            for (int i = A; i <= B; i++)
            {
                if (IsPalindrome(i))
                {
                    ++result;
                }
            }
            Console.WriteLine(result);
        }
    }
}

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

int main(){
  int N;
  cin >> N;
  vector<string> S(N);
  for(int i=0;i<N;i++)  cin >> S.at(i);
  
  sort(S.begin(),S.end());
  vector<pair<int,string>> ans;
  int count=1;
  int ma=1;
  for(int i=0;i<N-1;i++){
    if(S.at(i)==S.at(i+1))  count++;
    else{
      ans.push_back(make_pair(count,S.at(i)));
      ma=max(ma,count);
      count=1;
    }
  }
  ans.push_back(make_pair(count,S.at(N-1)));
  ma=max(ma,count);
  sort(ans.begin(),ans.end());
  int now=0;
  for(int i=0;i<ans.size();i++){
    if(ans.at(i).first == ma) cout << ans.at(i).second << endl;
  }
  
  return 0;
}


Measured memory_bytes: 18164
n, hp = gets.chomp.split(" ").map(&:to_i)
throw_damage_table = []
max_swing_damage = 0
ans = 0

n.times do
    a, b = gets.chomp.split(" ").map(&:to_i)
    max_swing_damage = a > max_swing_damage ? a : max_swing_damage
    throw_damage_table << b
end

throw_damage_table.sort!
max_throw_damage = throw_damage_table.pop

while max_swing_damage < max_throw_damage && 0 < hp
    hp -= max_throw_damage
    ans += 1
    break if throw_damage_table.empty?
    max_throw_damage = throw_damage_table.pop
end

ans += (hp/max_swing_damage.to_f).ceil if hp > 0
puts ans

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

int main(){
    long long int n,m,c,ans=0,z;
    cin>>n>>m>>c;
    vector<long long int>b(1000000);
    vector<long long int>a(1000000);

    for(int i=0;i<m;i++){
       cin>>b[i];
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin>>a[j];
            z+=a[j]*b[j];
        }
        z+=c;
        if(z>0){
            ans++;
        }
        z=0;
    }

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

Measured memory_bytes: 15872
#include <stdio.h>
#define num3 3

int main(void){
  int num[num3];
  int equal=0;
  for(int i = 0;i < num3;i++){
    scanf("%d ",&num[i]);
  }
  for(int i = 0;i < num3;i++){
    if(num[i%num3]==num[(i+1)%num3]){
       equal++;
    }
  }
  if(equal == 1){
    printf("\nYes");
  }
  else{
    printf("\nNo");
  }
  return 0;
}


Measured memory_bytes: 1700
#include <iostream>
int main() {
	int N;
	int A[200];
	std::cin >> N;
	for (int i = 0; i < N; i++) std::cin >> A[i];
	int counter = 0;
	bool all_even = true;
	while (true) {
		for (int i = 0; i < N;i++) {
			if (A[i] % 2 == 0) A[i] /= 2;
			else {
				all_even = false;
				break;
			}
		}
		if (!all_even) break;
		counter++;
	}
	std::cout << counter << std::endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

#define MAX 10000000000

int n, cnt = 0;

void merge(int*, int, int, int);
void mergeSort(int*, int, int);

int main() {
  int i, S[500000];
  scanf("%d\n", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &S[i]);
  }

  mergeSort(S, 0, n);
  for (i = 0; i < n; i++) {
    if (i == n-1) {
      printf("%d", S[i]);
      break;
    }
    printf("%d ", S[i]);
  }
  printf("\n%d\n", cnt);

  return 0;
}

void merge(int* A,int left, int mid, int right) {
  int n1, n2, i, j, k;
  n1 = mid - left;
  n2 = right - mid;
  int l[n1];
  int r[n2];
  for (i = 0; i < n1; i++) {
    l[i] = A[left+i];
  }
  for (i = 0; i < n2; i++) {
    r[i] = A[mid+i];
  }
  l[n1] = MAX;
  r[n2] = MAX;
  i = j = 0;
  for (k = left; k < right; k++) {
    if (l[i] <= r[j]) {
      A[k] = l[i];
      i++;
      cnt++;
    } else {
      A[k] = r[j];
      j++;
      cnt++;
    }
  }
}

void mergeSort(int* A, int left, int right) {
  if (left+1 < right) {
    int mid = (left + right) / 2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
  }
}

Measured memory_bytes: 4500
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
#include <valarray>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <complex>
//#include <tuple>
//#include <array>
//#include <random>
//#include <windows.h>
//#pragma comment(lib, "winmm.lib")

using namespace std;
typedef long long int LL;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

int main()
{
	string s;
	cin >> s;
	int g = 0;
	int p = 0;
	REP(i, s.size()) {
		if (s[i] == 'g') { g++; }
		if (s[i] == 'p') { p++; }
	}
	if (s.size() % 2 == 0) {
		cout << (s.size() / 2 - p )<< endl;
	}
	else {
		cout << ((s.size() - 1) / 2 - p) << endl;
	}
}

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

int main() {
  int N,max,ans;
  max = 0;
  ans = 0;
  cin >> N;
  int H[N];
  for(int i=0;i<N;i++)
    cin >> H[i];
  for(int k=0;k<N;k++){
    if(H[k]>=max){
      ans++;
  	  max = H[k];
    }
  }
  cout << ans << endl;
}


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

typedef long long ll;

#define REP(i, n) for(int i=0; i<(n); i++)
#define REPS(i, n) for(int i=0; i<=(n); i++)
#define FOR(i, a, b) for(int i=a; i<(b); i++)
#define FORS(i, a, b) for(int i=a; i<=(b); i++)
// for container x
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) *max_element(ALL(v))
#define MIN(v) *min_element(ALL(v))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;

int n, m;

int cnt_on(int k, vector<int> switch_, int bit){
    int cnt=0;
    REP(i, k){
        if (bit & (1 << (switch_[i]-1))) cnt++;
    }
    return cnt;
}

int main(){
    cin >> n >> m;
    vector<int> k(m);
    vector<vector<int>> s(m, vector<int>(n));
    vector<int> p(m);
    REP(i,m){
        cin >> k[i];
        REP(j, k[i]){
            cin >> s[i][j];
        }
    }
    REP(i, m) cin >> p[i];


    int ans = 0;
    REP(bit, (1<<n)){
        bool all_on = true;

        REP(j, m){
            if (cnt_on(k[j], s[j], bit)%2 != p[j]) all_on=false;
        }
        if (all_on) ans++;
    
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long ll;
#define int long long
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000000000000;

int N,M;
int A[100010],B[100010];
P p[100010];
int ans=0;

signed main(){
	cin>>N>>M;
	int m=M;
	REP(i,N){
		cin>>A[i]>>B[i];
		p[i]={A[i],B[i]};
	}
	sort(p,p+N);
	REP(i,N){
		int s=p[i].first;
		int t=p[i].second;
		if(m>=t){
			m-=t;
			ans+=s*t;
		}
		else{
			ans+=s*m;
			break;
		}
		DEB(ans)END
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
vi adjlist[100005];
int dist[100005];
int s[100005];
int n,u,v;
int main(){
    scanf("%d%d%d",&n,&u,&v);
    for (int i = 0; i < n-1; i++){
        int a,b;
        scanf("%d%d",&a,&b);
        adjlist[a].push_back(b);
        adjlist[b].push_back(a);
    }
    queue<int> q;
    q.push(v);
    memset(dist,-1,sizeof(dist));
    dist[v] = 0;
    while (q.size()){
        int u = q.front(); q.pop();
        for (auto v : adjlist[u]){
            if (dist[v] == -1){
                dist[v] = dist[u]+1;
                q.push(v);
            }
        }
    }
    q.push(u);
    q.push(v);
    int ans = dist[u];
    memset(s,-1,sizeof(s));
    s[u] = 0, s[v] = 1;
    while (q.size()){
        int u = q.front(); q.pop();
        for (auto v : adjlist[u]){
            if (s[v] == -1){
                s[v] = s[u];
                if (s[v] == 0){
                    ans = max(ans,dist[v]);
                }
                q.push(v);
            }
        }
    }
    printf("%d",max(0,ans-1));
}


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

LL fac[SIZE], finv[SIZE], inv[SIZE];
void combInit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for( int i = 2; i < SIZE; ++i ) {
        fac[i] = (fac[i - 1] * i) % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = (finv[i - 1] * inv[i]) % MOD;

    }
}

LL comb(int n, int k) {
    if( n < k ) return 0;
    if( n < 0 || k < 0 ) return 0;
    return (fac[n] * (finv[k] * finv[n - k] % MOD)) % MOD;

}

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );

            if( i * i != n ) ret.pb( n / i );
        }
    }
    sort( all( ret ) );
    return ret;
}

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

    int n;
    cin >> n;

    vector< pair<string, int> > v;
    int al = 0;
    for( int i = 0; i < n; ++i ) {
        string s;
        int a;
        cin >> s >> a;
        v.pb( MP(s, a) );

        al += a;
    }

    string t;
    cin >> t;
    int cnt = 0;
    int p = 0;
    while( v[p].F != t ) {
        al -= v[p].S;
        ++p;

    }
    al -= v[p].S;
    cout << al << endl;
    return 0;
}



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

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

ll power(ll x, ll y)
{
    ll res = 1;

    while (y > 0) {

        if (y & 1)
            res = res * x;


        y = y >> 1;
        x = x * x;
    }
    return res;
}

int main()
{
    int n;
    cin>>n;
    vector<double> a;
    //double d  = 0;
    for(int i=0;i<n;i++){
        int val;
        cin>>val;
        a.push_back(val);
        //d += (1.0/val);
    }
    double ans=0;
    sort(a.begin(),a.end());
    for(int i=1;i<n;i++){
        a[i] =  ((a[i]+a[i-1])/2.0);
        //cout<<ans<<'\n';
        //a[i] = ans;
    }
    cout<<a[n-1]<<'\n';
    //d = 1/d;
    //cout<<d<<'\n';
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

main(){
    int N,K;
    scanf("%d %d",&N,&K);
    int i,j,k;
    int x[N];

    for(i=0;i<N;i++)
        scanf("%d",&x[i]);


    int min=1e9,tmp,tmp2;
    for(i=0,j=K-1;j<N;i++,j++){
        if(x[i]<=0){
            if(x[j]<=0)
                tmp=-x[i];
            else{
                tmp=-x[i]+2*x[j];
                tmp2=2*-x[i]+x[j];
                if(tmp>tmp2)
                    tmp=tmp2;
            }
	}else{
            tmp=x[j];
        }
	//printf("%d %d %d\n",i,j,tmp);
        if(min>tmp)
            min=tmp;
    }
    printf("%d\n",min);
    return 0;
}


Measured memory_bytes: 512
#include<string.h>
#include<stdio.h>
int main(){
	int n,i,c=0;
	int num[4001];
	long long list[4001];
	for(;scanf("%d",&n)&& n;c=0){
		memset(list,0,sizeof(list));
		memset(num,0,sizeof(num));
		for(i=0;i<n;i++){
			int m;
			long long h,k;
			scanf("%d",&m);
			scanf("%lld",&h);
			scanf("%lld",&k);
			if(0<=list[m]&&list[m]<1000000)list[m]+=h*k;
			if(list[m]>=1000000){
				printf("%d\n",m);
				c++;
				list[m]=-100;
			}
		}
		if(c==0)printf("NA\n");
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin>>s;
  int len=s.size();
  for(int i=0;i<len;i++)
  {
    if(i%2==0){if(s[i]=='L'){cout<<"No";return 0;}}
    if(i%2!=0){if(s[i]=='R'){cout<<"No";return 0;}}
  }
cout<<"Yes";
}




Measured memory_bytes: 256
#include <iostream>
#include <map>

using namespace std;

int main(void){

  int n;
  char c1,c2;
  map <char,char> m;

  while( cin >> n , n ){

    m.clear();    

    for( int i = 0 ; i < n ; i++ ){
      cin >> c1 >> c2;
      m[c1] = c2;
    }

    cin >> n;
    
    while(n--){
      cin >> c1;
      if( m[c1] ) cout << m[c1];
      else cout << c1;
    }
    cout << endl;
    
  }
  
  
  return 0;
}

Measured memory_bytes: 1188
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        Integer[] a = new Integer[n];
        Stream.of(sc.nextLine().split(" "))
              .map(Integer::parseInt)
              .collect(Collectors.toList())
              .toArray(a);
        boolean f = true;
        int times = 0;
        while (f) {
            f = false;
            for (int i = a.length - 1; i > 0; i--) {
                if (a[i] < a[i-1]) {
                    int tmp = a[i];
                    a[i] = a[i - 1];
                    a[i - 1] = tmp;
                    f = true;
                    times++;
                }
            }
        }
        System.out.println(Stream.of(a)
                                 .map(Object::toString)
                                 .collect(Collectors.joining(" ")));
        System.out.println(times);
    }
}



Measured memory_bytes: 32704
#include<bits/stdc++.h>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <stdio.h>
#include <algorithm>
#include <map>
#include <queue>
#include <unordered_map>
#define ll long long
#define pii pair <int, int>
#define pll pair <long long, long long>
#define plxy pair <long long, pll>
#define INT_MAX 1e18
using namespace std;
using namespace std;
const int mod=1e9+7;
const int N=2e2+5;
vector<vector<ll>>v(N);
ll ncr(ll n,ll r){
 ll ans=1,fact=2;
 for(ll i=n-r+1;i<=n;i++){
    ans*=i;
    if(ans%fact==0 && fact<=r)
        ans/=fact++;
 }
  return ans;
}
int main()
{
    vector<ll>p;
    vector<ll>q;
    ll n,arr[N],x;
    cin>>n;
    for(ll i=0;i<n;i++)
        arr[i]=i+1;
    for(ll i=0;i<n;i++)
    {
        cin>>x;
        p.push_back(x);
    }
    for(ll i=0;i<n;i++)
    {
        cin>>x;
        q.push_back(x);
    }
    do
    {
        vector<ll>tmp;
        for(ll i=0;i<n;i++)
            tmp.push_back(arr[i]);
        v.push_back(tmp);
    }
    while(next_permutation(arr,arr+n));
    ll a=0,b=0;
    for(ll i=0;i<v.size();i++)
    {
        if(v[i]==p)
            a=i+1;
        if(v[i]==q)
            b=i+1;
    }
    cout<<abs(a-b);
	return 0;
}


Measured memory_bytes: 4296
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		
		Scanner sc=new Scanner(System.in);
		int A=sc.nextInt();
		int B=sc.nextInt();
		int C=sc.nextInt();
		int change;
		
		change=A;
		A=B;
		B=change;
		
		change=A;
		A=C;
		C=change;
		
		System.out.println(A+" "+B+" "+C);
		

	}

}


Measured memory_bytes: 39200
#include<bits/stdc++.h>
using lint=long long;
using real=long double;
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    lint n,k;std::cin>>n>>k;
    std::vector<lint>ckd(10);
    while(k--){
        lint x;std::cin>>x;
        ckd.at(x)=true;
    }
    auto ok=[&](lint x){
        for(;x;x/=10)if(ckd.at(x%10))return false;
        return true;
    };
    for(lint i=n;;i++){
        if(ok(i)){
            std::cout<<i<<'\n';
            return 0;
        }
    }
}


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

const int N = 1e5 + 5;
const int mod = 1e9 + 7;

namespace {
  inline int add(int x) {return (x >= mod) ? x - mod : x;}
  inline int sub(int x) {return (x < 0) ? x + mod : x;}
  inline void Add(int &x, int y) {x = add(x + y);}
  inline void Sub(int &x, int y) {x = sub(x - y);}
  inline int Pow(int x, int y) {
	int res = 1;
	for(; y; y >>= 1, x = 1LL * x * x % mod) {
	  if(y & 1) {
		res = 1LL * res * x % mod;
	  }
	}
	return res;
  }
}

int A[N], n, m, x, y, dp[N];
char s[N];

int tmp[N][3];

bool pd(void) {
  bool ok = 1;
  for(int i = 1; i < n; ++ i) ok &= (s[i] != s[i + 1]);
  return ok;
}

main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  for(int i = 1; i <= n; ++ i) {
	A[i] = s[i] - 'a' + 1;
	A[i] += A[i - 1];
	A[i] %= 3;
  }
  if(pd()) {
	return 0 *puts("1");
  }
  dp[0] = 1;
  tmp[n + 1][0] = tmp[n + 1][1] = tmp[n + 1][2] = n + 1;
  int ans = 0;
  for(int i = n; i >= 1; -- i) {
	for(int a = 0; a < 3; ++ a) tmp[i][a] = tmp[i + 1][a];
	tmp[i][A[i]] = min(tmp[i][A[i]], i);
  }
  //cerr << A[2] <<" " << A[3] << endl;
  for(int i = 0; i < n; ++ i) {
	for(int j = 0; j < 3; ++ j) 
	  if(A[i] != j && tmp[i + 1][j] <= n) 
		Add(dp[tmp[i + 1][j]], dp[i]);
  }
  for(int i = 1; i <= n; ++ i) if((A[i] == A[n])) Add(ans, dp[i]);
  cout << ans << endl;
}


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

int keta(int64_t x) {
  int ans=0;
  while (x>0) {
    x /= 10;
    ans++;
  }
  return ans;
}

int main() {
  int64_t N;
  cin >> N;
  int64_t p;
  int64_t sum=1;
  int finish = 1;
  int64_t INF = pow(10, 18);
  vector<int64_t> V(N);
  
  for (int64_t i=0; i<N; i++) {
    cin >> V.at(i);
    if (V.at(i) == 0) {
      finish = 0;
    }
  }
  
  
  if (finish != 0) {
    for (int64_t i=0; i<N; i++) {
      if (keta(sum) + keta(V.at(i)) > 19 && sum*V.at(i) != INF) {
        finish = -1;
        break;
      }
      sum *= V.at(i);
      if (sum > INF || sum < 0) {
        finish = -1;
        break;
      }
    }
  }
  
  if (finish == 0) {
    cout << 0 << endl;
  }
  else if (finish == -1) {
    cout << -1 << endl;
  }
  else {
    cout << sum << endl;
  }
  //cout << sum << endl;
}

Measured memory_bytes: 4052
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin >> n;

	long long ans=0;
	for(int i=1; i<=n; ++i){
		for(int j=i; j<=n; j += i){
			ans += j;
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 3628
#include <algorithm>
#include <cmath>
#include <climits>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

int main() {
  std::string str; std::cin >> str;
  for (const char c : str) {
    if (c == '1') std::cout << 9;
    else         std::cout << 1;
  }
  std::cout << std::endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int INF = 1e9;

int main(){
	int N, M; cin >> N >> M;
	vector<int> t[N];
	int A[M];
	int c[M];
	for(int i=0; i<M; i++){
		int a, b, C = 0; cin >> a >> b;
		A[i] = a;
		for(int j=0; j<b; j++){
			int c; cin >> c;
			c--;
			C |= (1<<c);
			t[c].push_back(i);
		}
		c[i] = C;
	}
	int dp[1<<N];
	dp[0] = 0;
	for(int i=1; i<(1<<N); i++){
		dp[i] = INF;
	}
	for(int i=1; i<(1<<N); i++){
		for(int j=0; j<M; j++){
			int bit = i;
			bit &= ~c[j];
			if(dp[bit] != INF && dp[i] > dp[bit] + A[j]){
				dp[i] = dp[bit] + A[j];
			}
		}
	}
	if(dp[(1<<N)-1] != INF){
		cout << dp[(1<<N)-1] << endl;
	}else{
		cout << -1 << endl;
	}
	return 0;
}


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

int main() {
  int n;
  cin >> n;
  map<ll, ll> minus;
  map<ll, ll> plus;
  int mx = 0;
  rep(i, n) {
    ll a;
    cin >> a;
    minus[i - a]++;
    plus[a + i]++;
  }

  ll ans = 0;
  for (P p : minus) {
    ans += p.second * plus[p.first];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 37836
let () = Scanf.scanf "%d\n" @@ fun n ->
  let sps = Array.init n @@ fun i -> Scanf.scanf "%s %d\n" @@ fun s p -> s, p, i in
  Array.sort (fun (s, p, _) (s', p', _) -> compare (s, ~- p) (s', ~- p')) sps;
  Array.iter (fun (_, _, i) -> Printf.printf "%d\n" @@ i + 1) sps

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

template<class T>
bool ChangeMax(T&a,const T&b){
  if(a >= b) return false;
  a = b;    return true;
}

template<class T>
bool ChangeMin(T&a,const T&b){
  if(a <= b) return false;
  a = b;    return true;  
}

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

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

int main(){
  int n; cin >> n;
  vector<vector<int>> gv(n);
  map<P<int,int>,int> order;
  for(int i = 0; i < n-1; ++i){
    int a,b; cin >> a >> b;a--;b--;    
    gv[a].push_back(b);
    gv[b].push_back(a);
    if(a>b)swap(a,b);
    order[{a,b}] = i;
  }
  vector<set<int>> cused(n);
  vector<int> color(n-1);
  int k = 0;
  for(int i = 0; i < n; ++i){
    int idx = 1;
    for(auto e : gv[i]){
      int a = i, b = e;
      if(a>b)swap(a,b);
      int od = order[{a,b}];
      if(color[od]!=0)continue;
      while(cused[i].count(idx)>0)idx++;
      color[od] = idx;
      ChangeMax(k,idx);
      cused[i].insert(idx);
      cused[e].insert(idx);
      idx++;
    }
  }
  cout << k << endl;
  for(int i = 0; i < n-1; ++i){
    cout << color[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 26752
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const int MAX_N  = 2e5+10;
int N, K;
int A[MAX_N];

bool ok(double x)
{
	int cnt = 0;
	for(int i=0;i<N;++i){
		if(A[i] > x) cnt += (int)ceil(A[i]/x)-1;
	}
	return cnt <= K;
}

void solve()
{
	double lo = 0, hi = 1e9;
	for(int i=0;i<100;++i){
		double mid = (lo+hi)/2.0;
		if(ok(mid)) hi=mid;
		else lo=mid;
	}
	cout << (long long)(ceil(hi)) << '\n';
}

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


Measured memory_bytes: 4480
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main(){
	
	ll n, m;
	cin >> n >> m;
	
	if(n == m or n%m == 0) cout << 0 << endl;
	else if(n > m){
		ll d = n/m;
		cout << min(abs(n-m*d), abs(n-m*(d+1))) << endl;;
	}
	else{
		cout << min(m-n, n) << endl;
	}
	
	return 0;
}


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

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
  double v;
  while(cin>>v) {
    double x = v*v/2/9.8;
    cout << ceil(x/5)+1 << endl;
  }
}

Measured memory_bytes: 0