akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
//krishrawat
 
 
//----------------------------MACROS-------------------------------------------------
#define pb insert//                                                                 |
#define eb emplace_back//                                                           |
#define ff first//                                                                  |
#define ss second//                                                                 |
typedef long long int ll;//                                                         |
typedef long double ld;//                                                           |
#define all(a) a.begin(), a.end()//                                                 |
#define show(x) cerr << #x << " is " << x << "\n"//                                 |
#define show2(x, y) cerr << #x << " " << #y << " " << x << " " << y << "\n"//       |
typedef vector<ll> vl;//                                                            |
typedef vector<vl> vvl;//                                                           |
typedef pair<ll, ll> pp;//                                                          |
typedef vector<pp> vp;//                                                            |
typedef map<pp, ll> ipi;//                                                          |
typedef map<pp, char> ipc;//                                                        |
typedef map<ll, ll> ii;//                                                           |
typedef set<ll> sl;//                                                               |
typedef multiset<ll> msl;//                                                         |
typedef map<char, ll> ci;//                                                         |
typedef set<pair<ll, ll>> sp;//                                                     |
const ll mod = 1e9 + 7;//                                                           |
const ll N = 2e5 + 1;//                                                             |
//----------------------------------------------------------------------------------

vl grp[N];
vl ans(N,0);
vl val(N,0);
vl vis(N,0);

void dfs(ll x,ll adds){
    ans[x]=adds+val[x-1];
    for(auto i:grp[x]){
        if(!vis[i]){
            vis[i]=1;
            dfs(i,ans[x]);
        }
    }
}

void solve()
{   
    ll n,q;cin>>n>>q;
    for(int i=0;i<n-1;i++){
        ll x,y;cin>>x>>y;
        grp[x].eb(y);
        grp[y].eb(x);
    }
    while(q--){
        ll a,b;cin>>a>>b;
        val[a-1]+=b;
    }
    
    vis[1]=1;
    dfs(1,0);
    for(int i=1;i<=n;i++) cout<<ans[i]<<" ";
}
 
 
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
    
    ll t; t=1;
    //cin>>t;
    while(t--) solve(); return 0;
}

Measured memory_bytes: 28224
#include<iostream>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<map>
#include<utility>
#include<cmath>
#include<tuple>
#include<string>
#include<bitset>
#include<set>
using namespace std;
typedef long long ll;

int main(){
    int n,k; cin>>n>>k;
    vector<int> h(n);
    for(int i=0;i<n;i++) cin>>h[i];
    sort(h.begin(),h.end());
    ll ans=0;
    for(int i=0;i<n-k;i++){
        ans+=h[i];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

#define PI 3.14159265359

struct DOT {
	double x, y;
	struct DOT* next;
};

double Makedick(int XorY, double x1, double y1, double x2, double y2) {
	// NEW = A + 1/3 (B-A) + 1/3 * (B-A) * ROT(60)
	double newX = x1 + (x2 - x1) / 3 + cos(60 * PI / 180)*(x2 - x1) / 3 - sin(60 * PI / 180)*(y2 - y1) / 3;
	double newY = y1 + (y2 - y1) / 3 + sin(60 * PI / 180)*(x2 - x1) / 3 + cos(60 * PI / 180)*(y2 - y1) / 3;
	if (XorY == 0)return newX;
	else return newY;
}

struct DOT end = { 100,0,NULL };
struct DOT init = { 0,0,&end };

int MakeCurve(int n) {
	struct DOT* runP = &init;
	struct DOT* Add[3];
	int N, cnt;
	if (n == 0)return 1;
	N = MakeCurve(n - 1);
	cnt = N;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < 3; j++) {
			Add[j] = (struct DOT*)malloc(sizeof(struct DOT));
		}
		Add[0]->x = (runP->x * 2 + runP->next->x) / 3;
		Add[0]->y = (runP->y * 2 + runP->next->y) / 3;
		Add[1]->x = Makedick(0, runP->x, runP->y, runP->next->x, runP->next->y);
		Add[1]->y = Makedick(1, runP->x, runP->y, runP->next->x, runP->next->y);
		Add[2]->x = (runP->x + runP->next->x * 2)  / 3;
		Add[2]->y = (runP->y + runP->next->y * 2)  / 3;
		Add[2]->next = runP->next;
		Add[1]->next = Add[2];
		Add[0]->next = Add[1];
		runP->next = Add[0];
		runP = Add[2]->next;
		cnt += 3;
	}
	return cnt;
}

int main() {
	int n;
	struct DOT * pos;

	scanf("%d", &n);
	MakeCurve(n);
	for (pos = &init; pos != NULL; pos = pos->next) {
		printf("%lf %lf\n", pos->x, pos->y);
	}
	return 0;
}


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

int main(void){
   int N;
   cin>>N;
   for(int i=0;i<=N;i++){
      if(floor(i*1.08)==N){
         cout<<i<<endl;
         return 0;
      }
   }
   cout<<":("<<endl;
   return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <string.h>
#include <vector>
//s#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX 10000

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a; i<n; i++)
#define r0 return 0
#define INF (int)1e15
#define MOD 1000000007

int main(){

 ll n;
 cin>>n;
 ll a[n];

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

 ll ans = a[0];

   for(int i=0;i<n;i++)
    ans = lcm(ans,a[i]);

    cout<<ans<<endl;

return 0;
}


Measured memory_bytes: 3556
#include<stdio.h>
int main(void)
{
        int a[3],max,min,i;
        for(i=0;i<3;i++){
                scanf("%d",&a[i]);
                if(i==0) max=min=a[i];
                else if((i!=0)&&(a[i]>max)) max=a[i];
                else if((i!=0)&&(a[i]<min)) min=a[i];
        }
        printf("%d\n",max-min);
        return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

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

    int N, x;
    cin >> N >> x;
    if(x == 1 or x == 2 * N - 1) {
        cout << "No" << endl;
        return 0;
    }

    int rsl[2 * N - 1];
    bool flag = false;
    rsl[N - 1] = x;
    if(x == 2) {
        rsl[N - 2] = x + 1;
        rsl[N] = x - 1;
        rsl[N + 1] = x + 2;
        flag = true;
    } else if(x == 2 * N - 1) {
        rsl[N - 2] = x - 1;
        rsl[N] = x + 1;
        rsl[N + 1] = x - 2;
    } else {
        rsl[N - 2] = x - 1;
        rsl[N] = x + 1;
        rsl[N + 1] = x - 2;
    }

    int tmp = 1;
    rep(i, 0, 2 * N - 1) {
        if(N - 2 <= i and i <= N + 1) continue;
        if(flag) {
            while(x - 1 <= tmp and tmp <= x + 2) {
                tmp++;
            }
        } else {
            while(x - 2 <= tmp and tmp <= x + 1) {
                tmp++;
            }
        }
        rsl[i] = tmp;
        tmp++;
    }

    cout << "Yes" << endl;
    rep(i, 0, 2 * N - 1) cout << rsl[i] << endl;

}


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

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

typedef long long ll;

//  bit全探索
//  for (int tmp = 0; tmp < (1 << ビット数); tmp++) {
//    bitset<ビット数> s(tmp);
//  }

int main(){

   string S;
	ll allsum= 0;
	cin >> S;
	int len = S.size();
	for (int tmp = 0; tmp < (1 << len - 1); tmp++) {	//演算子が入りうるすべての場所をbitで表現
		bitset<9>bit(tmp);	//取りうる最大のbit数　<>内は定数不可
		string cutstr = S;
		rep(i, len-1) {
			if (bit.test(i)) {	//iの位置のビットが立っていれば
				/*文字列を後ろから切り取り、削除*/
				allsum += stoll(cutstr.substr(len - 1 - i));
				cutstr.erase(len - 1 - i);
			}
		}
		allsum += stoll(cutstr);
	}
	cout << allsum << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long LL;
struct X{
	int id;
	LL x;
	LL y;
	X(){
		id=0;
		x=0;
		y=0;
	}
	X(int _id,LL _x,LL _y){
		id=_id;
		x=_x;
		y=_y;
	}
	LL getCost(X &x1){
		LL X1=x-x1.x;
		if (X1<0){
			X1=-X1;
		}
		LL Y1=y-x1.y;
		if (Y1<0){
			Y1=-Y1;
		}
		if (X1<Y1){
			return X1;
		}else{
			return Y1;
		}
	}
};
struct EDGE{
	X p1;
	X p2;
	LL cost;
	EDGE(X _p1,X _p2){
		p1=_p1;
		p2=_p2;
		cost=p1.getCost(p2);
	}
  // コストの大小で順序定義
  bool operator<(const EDGE& o) const {
    return cost < o.cost;
  }
	bool find(const EDGE &edge){
		if (p1.id==edge.p1.id && p2.id==edge.p2.id){
			return true;
		}
		if (p1.id==edge.p2.id && p2.id==edge.p1.id){
			return true;
		}
		return false;
	}

};
bool SortX(X &x1,X &x2){
	if (x1.x<x2.x){
		return true;
	}
	return false;
}
bool SortY(X &x1,X &x2){
	if (x1.y<x2.y){
		return true;
	}
	return false;
}
// 素集合データ構造
struct UnionFind
{
  // par[i]：データiが属する木の親の番号。i == par[i]のとき、データiは木の根ノードである
  vector<int> par;
  // sizes[i]：根ノードiの木に含まれるデータの数。iが根ノードでない場合は無意味な値となる
  vector<int> sizes;

  UnionFind(int n) : par(n), sizes(n, 1) {
    // 最初は全てのデータiがグループiに存在するものとして初期化
	  for (int i=0;i<n;i++){
		par[i] = i;
	  }
  }

  // データxが属する木の根を得る
  int find(int x) {
    if (x == par[x]) return x;
    return par[x] = find(par[x]);  // 根を張り替えながら再帰的に根ノードを探す
  }

  // 2つのデータx, yが属する木をマージする
  void unite(int x, int y) {
    // データの根ノードを得る
    x = find(x);
    y = find(y);

    // 既に同じ木に属しているならマージしない
    if (x == y) return;

    // xの木がyの木より大きくなるようにする
    if (sizes[x] < sizes[y]) swap(x, y);

    // xがyの親になるように連結する
    par[y] = x;
    sizes[x] += sizes[y];
    sizes[y] = 0;  // sizes[y]は無意味な値となるので0を入れておいてもよい
  }

  // 2つのデータx, yが属する木が同じならtrueを返す
  bool same(int x, int y) {
    return find(x) == find(y);
  }

  // データxが含まれる木の大きさを返す
  int size(int x) {
    return sizes[find(x)];
  }
};

// 頂点数と辺集合の組として定義したグラフ
struct Graph
{
  int n;  // 頂点数
  vector<EDGE> edges;  // 辺集合

  // クラスカル法で無向最小全域木のコストの和を計算する
  // グラフが非連結のときは最小全域森のコストの和となる
  LL kruskal() {
    // コストが小さい順にソート
    sort(edges.begin(), edges.end());

    UnionFind uf(n);
    LL min_cost = 0;

    for (int i=0;i<edges.size();i++) {
      EDGE& e = edges[i];
	  if (!uf.same(e.p1.id, e.p2.id)) {
        // 辺を追加しても閉路ができないなら、その辺を採用する
        min_cost += e.cost;
		uf.unite(e.p1.id, e.p2.id);
      }
    }

    return min_cost;
  }
};

int main(int argc, char* argv[])
{
	int N;
	cin>>N;
	vector<X> City;
	int i;
	LL x,y;
	for (i=0;i<N;i++){
		cin>>x>>y;
		City.push_back(X(i,x,y));
	}
	sort(City.begin(),City.end(),SortX);
	Graph graph;
	graph.n=N;
	for (i=0;i<N-1;i++){
		EDGE edge(City[i],City[i+1]);
		graph.edges.push_back(edge);
	}
	sort(City.begin(),City.end(),SortY);
	for (i=0;i<N-1;i++){
		EDGE edge(City[i],City[i+1]);
		graph.edges.push_back(edge);
	}
	cout << graph.kruskal() << endl;
	return 0;
}

Measured memory_bytes: 20840
#include<stdio.h>

int main(){
  int home[4][3][10] = {0};
  int n,b,f,r,v;
  int i;
  
  scanf("%d", &n);
  
  for(i=0; i<n; i++){
    scanf("%d %d %d %d", &b, &f, &r, &v);
    home[b-1][f-1][r-1] += v;
  }
  
  
  for(b=0; b<4; b++){
    for(f=0; f<3; f++){
      for(r=0; r<10; r++){
          printf(" %d", home[b][f][r]);
      }
      printf("\n");
            }
    if(b==3){
    } else {
      for(i=0; i<20; i++){
        printf("#");
      }
      printf("\n");
    }
    
  }
  return 0;
}

Measured memory_bytes: 600
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <fstream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
using namespace std;
#define     loop(n,i,a)     for(int i=a;i<n;i++)
#define     loopR(n,i,a)    for(int i=n-1;i>=a;i--)
#define     all(arr,n)      arr,arr+n
#define     allv(v)         (v).begin(),(v).end()
#define     rallv(v)        (v).rbegin(),(v).rend()
#define     m_p             make_pair
#define     ll              long long
#define     pii             pair<ll,ll>
#define     vi              vector<int>
#define     vll             vector<ll>
#define		vii 			vector<pair<ll,ll>>
#define     sz(x)           (int)x.size()
#define     pb              push_back
#define     endl            "\n"
#define     Endl            "\n"
#define     f               first
#define     s               second
#define     mem(dp,n)       memset(dp,n,sizeof dp)
#define     test(i)        cout<<i<<endl
int dx[] = { 1 , 0 ,-1 , 0 ,-1 ,-1 , 1 , 1 };
int dy[] = { 0 , 1 , 0 ,-1 ,-1 , 1 ,-1 , 1 };
void fast(){
    std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
}
const ll mxN=3e5+5,oo=0x3f3f3f3f,mod=1e9+7;
int n,k,arr[105];
ll dp[105][mxN];
ll go(int idx, int rem){
    if(rem<0)
        return 0;
    if(idx==n)
        return rem==0;
    ll &ret=dp[idx][rem];
    if(~ret)
        return ret;
    ret=((go(idx,rem-1)%mod)+(go(idx+1,rem)%mod)-(go(idx+1,rem-arr[idx]-1)))+2*mod;
    ret%=mod;
    return ret;
}
void solve(){
    cin>>n>>k;
    loop(n,i,0)
        cin>>arr[i];
    mem(dp,-1);
    cout<<go(0,k)%mod<<endl;
}
int main() {
    fast();
    solve();
}


Measured memory_bytes: 257384
#include <bits/stdc++.h>
using namespace std;  
#define rep(i, a, b) for(ll i = a; i < b; i++)
#define Rep(i, a, b) for(ll i = a; i <= b; i++)
#define repr(i, a, b) for(ll i = b-1; i >= a; i--)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
using ll = long long;
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define coel cout << endl
#define pb push_back
#define sz(v) ((ll)(v).size())
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
// const ll INF = 1LL << 60;
#define pp pair<ll, pair<ll, ll>> 
#define fi first
#define se second

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

int main() {
    ll n; cin >> n;
    Vl a(n);
    rep(i, 0, n) cin >> a[i];

    ll now = a[0], ans = 0;
    rep(i, 1, n){
        if(now <= a[i]) now = a[i];
        else ans += now - a[i];
    }

    co(ans);

    return 0;
}
 
 


Measured memory_bytes: 4776
n = gets.to_i
data = $<.map{|l|l.split.map(&:to_i)}

(n-1).times do |j|

  c, s, f = data[j]
  time = c + s

  (n-j-2).times do |i|
    c, s, f = data[j+1+i]
    if s > time
      time = c + s
    elsif (time % f) == 0
      time = c + time
    else
      time = c + time + f - (time % f)
    end
  end
  
  p time
end

p 0


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

int main() {

    int N;
    string S;
    int x = 0;
    int ans = 0;

    cin >> N;
    cin >> S;

    for(int i = 0; i < N; i++){
        if(S[i] == 'I'){
            x += 1;
        } 
        else{
            x -= 1;
        }

        if(x >= ans){
            ans = x;
        }
    }

    cout << ans << endl;

    return 0;
}

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

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define MP make_pair
#define PB push_back
#define X first
#define Y second

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

const double PI = acos(-1.0);
const LL INF = 1e9;
const LL LINF = INF * INF;

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
//	freopen("In.txt", "r", stdin);
	//freopen("In.txt", "w", stdout);

	string s;
	cin >> s;
	
	string t = "keyence";
	bool ok = s == t;
	int n = SZ(s);
	FOR(i, 0, n)
		FOR(j, i, n)
		{
			string bude;
			FOR(k, 0, n)
				if (k < i || k > j)
					bude += s[k];
			ok |= bude == t;
		}
	
	if (ok)
		cout << "YES";
	else
		cout << "NO";
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
	return 0;
}


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

int main() {
	// your code goes here
	 ios_base::sync_with_stdio(false);
	 cin.tie(NULL);
	 ll t,n,i,j;
	     cin>>n;
	     i=1000;
	     while(i<n)
	     {
	         i+=1000;
	     }
	     cout<<i-n<<"\n";
	
	return 0;
}


Measured memory_bytes: 3616
#include <iostream>
#include <algorithm>
using namespace std;
int N,A,B;
int main()
{
    cin >> N >> A >> B;
    if(abs(A - B) % 2 == 0){
        cout << "Alice";
    }
    else {
        cout << "Borys";
    }
    return 0;
}


Measured memory_bytes: 764
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
const int INF = numeric_limits<int>::max()/2;

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

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

    int h,w;cin>>h>>w;
    vector<string> s(h);
    int cnt=0;
    for(int i=0;i<h;i++){
        cin>>s[i];
        for(int j=0;j<w;j++) if(s[i][j]=='.') cnt++;
    }
    queue<P> q;
    vector<vector<int>> dis(h,vector<int>(w,INF));
    q.push(P(0,0));
    dis[0][0]=0;
    while(!q.empty()){
        P p=q.front();q.pop();
        for(int i=0;i<4;i++){
            int nx=p.first+dx[i],ny=p.second+dy[i];
            if(nx<0 || h<=nx || ny<0 || w<=ny) continue;
            if(s[nx][ny]=='#') continue;
            if(dis[nx][ny]!=INF) continue;
            dis[nx][ny]=dis[p.first][p.second]+1;
            q.push(P(nx,ny));
        }
    }
    if(dis[h-1][w-1]==INF){
        cout<<-1<<endl;
        return 0;
    }
    cout<<cnt-(dis[h-1][w-1]+1)<<endl;
}


Measured memory_bytes: 256
#![allow(non_snake_case)]

use std::io::{stdin, Read};
use std::str::FromStr;
fn read_option<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok()
}
fn read<T: FromStr>() -> T {
    let opt = read_option();
    opt.expect("failed to parse token")
}

fn main() {
    println!("{}", read::<usize>() * read::<usize>());
}

Measured memory_bytes: 2112
n = input()
mat = ["3","5","7"]
l = []
l_753 = []

def dfs(i, s):
    if i == len(n):
        l.append(int(s))
        return
    
    for m in mat:
        dfs(i+1, s+m)

for i_ in range(len(n)):
    dfs(len(n)-i_-1, "")

for a in l:
    if "3" in str(a) and "5" in str(a) and "7" in str(a):
        l_753.append(a)

l_753.append(int(n)+1)
l_753.sort()
print(l_753.index(int(n)+1))

Measured memory_bytes: 4504
INT_MAX=10**18+7
MOD=10**9+7
def INPUT():return list(int(i) for i in input().split())
def LIST_1D_ARRAY(n):return [0 for _ in range(n)]
def LIST_2D_ARRAY(m,n):return [[0 for _ in range(n)]for _ in range(m)]
#################################################################################
a,b,c=INPUT()
print(c,a,b)


Measured memory_bytes: 38256
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#include <boost/rational.hpp>
*/
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define repr4(i,s,n) for(ll i = (n);i>=(s);i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
using Graphw = vector<vector<pair<ll,ll>>>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
#define MOD 1000000007;
/*
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
// 有理数型
using Rat = boost::rational<Bint>;
*/
const int mod = 1000000007;

int main(){
ll S;
cin>>S;
if(S==(ll)1e18){
  cout<<0<<" "<<0<<" "<<(ll)1e9<<" "<<0<<" "<<0<<" "<<(ll)1e9<<endl;
  return 0;
}
ll X1=0,Y1=0,X2=1e9,Y2=1,X3,Y3;
Y3=S/((ll)1e9)+1;
X3=(ll)1e9-S%((ll)1e9);
cout<<X1<<" "<<Y1<<" "<<X2<<" "<<Y2<<" "<<X3<<" "<<Y3<<endl;
return 0;
}

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

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

#define MOD 1000000007

int main(void) {
    string S, T;
    cin >> S >> T;
    for(ll i = 0;i < S.size();i++) {
        if(S == T) {
            cout << "Yes" << endl;
            return 0;
        }
        char back = S.back();
        S.pop_back();
        S.insert(0, 1, back);
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(final String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int c = Integer.parseInt(sc.next());
        int k = Integer.parseInt(sc.next());

        if (k <= a + b) {
            if (k >= a) {
                System.out.println(a);
            } else {
                System.out.println(k);
            }
        } else {
            System.out.println(a - (k - a - b));
        }

        sc.close();
    }
}

Measured memory_bytes: 35820
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		final Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		long start = sc.nextLong();
		for (int i = 1; i < N; i++) {
			start = gcd(start, sc.nextLong());
		}
		
		System.out.println(start);
	}
	
	public static long gcd(long a, long b) {
		return a % b == 0 ? b : gcd(b, a % b);
	}
}


Measured memory_bytes: 47576
#define _USE_MATH_DEFIMES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007;
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

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








int main(){
    int N, K, ans(0); std::cin >> N >> K;
    std::vector<int> p(N);
    for(int i(0); i < N; ++i) std::cin >> p[i];
    std::sort(std::begin(p), std::end(p));
    for(int i(0); i < K; ++i) ans += p[i];
    std::cout << ans << std::endl;
    return 0;
}


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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> a(m), b(m);
    rep(i, m)
    {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
    }

    vector<int> per(n);
    rep(i, n) per[i] = i;
    int cnt = 0;
    do
    {
        if (per[0] != 0)
        {
            continue;
        }
        int ck_path = 0;
        rep(i, n - 1)
        {
            bool path = false;

            rep(j, m)
            {
                if ((a[j] == per[i] && b[j] == per[i + 1]) || (a[j] == per[i + 1] && b[j] == per[i]))
                {
                    path = true;
                }
            }
            if (!path)
            {
                continue;
            }
            ck_path++;
        }
        if (ck_path == n - 1)
        {
            cnt++;
        }
    } while (next_permutation(all(per)));

    cout << cnt << '\n';

    return 0;
}


Measured memory_bytes: 3620
#define _GLIBCXX_DEBUG//TLEの原因になるので注意！！！！！！！！！！！
#include<cmath>
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.sise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
deque<int> deq;
#define fi first
#define se second
//#define int long long

//cerrはコメントアウトしなくても通る//ただしTLEを引き起こすことがある

//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
//const ll INF = 1LL << 60;
//typedef pair<ll,ll> P;
typedef pair<int, int> P;
bool chmx(int &a, int b) {
	if (b > a) {
		a = b;
		return true;
	}
	return false;
}

bool chmn(int &a, int b) {
	if (b < a) {
		a = b;
		return true;
	} 
	return false;
}

int main(){
    int x;
    cin >> x;
    ll ans=0;
    ans+=(x/500)*1000;
    x%=500;
    ans+=(x/5)*5;
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 256
import java.util.*;

public class Main {

    static int N;
    static int Q;
    static List<List<Edge>> graph;
    static boolean[] visited;
    static int[] counter;

    static class Edge {
        int from, to;

        public Edge(int from, int to) {
            this.from = from;
            this.to = to;
        }
    }

    static void dfs(int at, int prev) {
        visited[at] = true;
        if (prev != -1) {
            counter[at] += counter[prev];
        }

        List<Edge> edges = graph.get(at);
        for (Edge edge : edges) {
            if (visited[edge.to]) continue;
            dfs(edge.to, at);
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        N = Integer.parseInt(sc.next());
        Q = Integer.parseInt(sc.next());
        graph = new ArrayList<>();
        for (int i = 0; i < N; ++i) graph.add(new ArrayList<>());
        visited = new boolean[N];
        counter = new int[N];

        for (int i = 0; i < N-1; ++i) {
            int a = Integer.parseInt(sc.next()) - 1;
            int b = Integer.parseInt(sc.next()) - 1;
            graph.get(a).add(new Edge(a, b));
            graph.get(b).add(new Edge(b, a));
        }

        for (int i = 0; i < Q; ++i) {
            int p = Integer.parseInt(sc.next()) - 1;
            int x = Integer.parseInt(sc.next());
            counter[p] += x;
        }

        dfs(0, -1);

        for (int i = 0; i < N; ++i) {
            System.out.print(counter[i] + " ");
        }
        System.out.println();
    }
}

Measured memory_bytes: 166872
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	int N, M;
	cin >> N >> M;
	vector<pair<long long int, long long int>>P(N);
	for (int i = 0; i < N; i++) {
		long long int a, b;
		cin >> a >> b;
		P[i] = make_pair(a, b);
	}
	sort(P.begin(), P.end());
	long long int ans = 0;
	int k = 0;
	for (int i = 0; i < N; i++) {
		if (k + P[i].second > M) {
			ans += (P[i].first * (M - k));
			break;
		}
		ans += (P[i].first) * (P[i].second);
		k += P[i].second;

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

Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<functional>
#include<math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pf(n) printf("%d\n",n)
#define pff(a,b) printf("%d  %d\n",a,b);
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1001001001;
const double PI = acos(-1);

int main() {
	int n, d;
	cin >> n >> d;
	int x[10][10] = { 0 };
	rep(i, n)rep(j, d) cin >> x[i][j];

	int cnt = 0;
	rep(i1, n) {
		for(int i2=i1+1;i2<n;i2++){
			double dis = 0;
			rep(j1, d) {
				dis += (x[i1][j1] - x[i2][j1])*(x[i1][j1] - x[i2][j1]);
			}
			int diss = sqrt(dis);
			if (diss*diss == dis) cnt++;
		}
	}
	pf(cnt);

	return 0;
}

Measured memory_bytes: 3700
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static void Main()
    {
        string[] arrStrCookies = Console.ReadLine().Split(' ');

        int[] arrIntCookies = new int[]{ int.Parse(arrStrCookies[0]), int.Parse(arrStrCookies[1]), int.Parse(arrStrCookies[0]) + int.Parse(arrStrCookies[1]) };

        if(arrIntCookies[0] % 3 == 0 || arrIntCookies[1] % 3 == 0 || arrIntCookies[2] % 3 == 0)
        {
            Console.WriteLine("Possible");
        }
        else
        {
            Console.WriteLine("Impossible");
        }

    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <random>
#include <iomanip>
#include <unordered_set>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<pair<ll,ll> > vpll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vc> vvc;
typedef vector<vs> vvs;
typedef vector<vll> vvll;
typedef map<int,int> mii;
typedef set<int> si;
#define rep(i,n) for(ll i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define arep(i,v) for(auto i : v)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define fi first
#define se second
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
template <class T> inline void dump(T &v){irep(i, v){cout<<*i<<((i==--v.end())?'\n':' ');}}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("yes"):fin("no");}
inline void Yn(const bool b){b?fin("Yes"):fin("No");}
inline void YN(const bool b){b?fin("YES"):fin("NO");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
constexpr ll LLINF = 1LL<<60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-11;




int main() {

    string s,t;
    cin>>s>>t;
    int ans=0;
    rep(i,s.size()){
        ans+=(s[i]!=t[i]);
    }
    fin(ans);
}



Measured memory_bytes: 3916
#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
int a,b,c,maxn,minn;
int main()
    {
        cin>>a>>b>>c;
        maxn=max(max(a,b),c);
        minn=min(min(a,b),c);
        cout<<maxn-minn<<endl;
        return 0;
    }


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

int main(void)
{
    int a, b;
    cin >> a >> b;
    if ((a == 1 && b == 2) || (a == 2 && b == 1)) cout << 3 << endl;
    else if ((a == 2 && b == 3)|| (a == 3 && b == 2)) cout << 1 << endl;
    else if ((a == 3 && b == 1)|| (a == 1 && b == 3)) cout << 2 << endl; 

    return 0;
}


Measured memory_bytes: 256
#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 ALL(v) v.begin(), v.end()
using namespace std;
using P = pair<int, int>;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  ll ans = 0;
  ll tmp = 0;
  rep(i, n) cin >> a[i];
  rep(i, n){
    if(a[i] > 0)tmp += a[i];
    else{
      ans += tmp / 2;
      tmp = 0;
    }
  }
  ans += tmp / 2;
  cout << ans << endl;
}

Measured memory_bytes: 4056
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cassert>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// head

int n,dp[110][110],a[110];
int main() {
	scanf("%d",&n);
	dp[0][1]=1;
	rep(i,1,n+1) scanf("%d",a+i);
	rep(i,0,n) rep(j,0,2) rep(k,a[i+1]-1,a[i+1]+2) (dp[i+1][j*k%2]+=dp[i][j])%=mod;
	printf("%d\n",dp[n][0]);
}


Measured memory_bytes: 128
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int d = sc.nextInt();

        int ans = 0;
        for(int i = 0; i < n; i++){
            long x = sc.nextInt();
            long y = sc.nextInt();

            if(Math.sqrt((x * x) + (y * y)) <= d){
                ans++;
            }
        }

        System.out.println(ans);

    }
}


Measured memory_bytes: 58848
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<typename T> using Graph = vector<vector<T>>;

#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define EACH(i, a) for (auto i: a)
#define ITR(x, a) for (__typeof(a.begin()) x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())
#define endl '\n'

int N;
int a[200005];
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // breath deeply and calm down

  cin >> N;
  rep(i, N) cin >> a[i];

  ll s = 0, t = 0;
  rep(i, N) s += a[i];

  ll ans = (ll)1e15;
  for (int i = 0; i < N - 1; i++) {
    s -= a[i];
    t += a[i];
    ans = min(ans, abs(s - t));
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
import sys

def is_match(x, t, n):
    for i in range(n):
        if x[i] != '?' and x[i] != t[i]:
            return False
    return True


s = input()
t = input()
len_s = len(s)
len_t = len(t)

if len_s < len_t:
    print('UNRESTORABLE')
    sys.exit(0)

segs = [s[i:i+len_t] for i in range(len_s - len_t + 1)]
ans = 'z' * 51

for i, seg in enumerate(segs):
    if is_match(seg, t, len_t):
        tmp = s[0:i] + t + s[i+len_t:]
        tmp = tmp.replace('?', 'a')
        ans = min(ans, tmp)

if len(ans) > 50:
    print('UNRESTORABLE')
else:
    print(ans)

Measured memory_bytes: 3064
import heapq

n, m = map(int, input().split())
a = list(map(lambda x: int(x)*(-1), input().split()))
heapq.heapify(a)

for _ in range(m):
    y = heapq.heappop(a)
    heapq.heappush(a, (-1)*(-y//2))

print(-sum(a))


Measured memory_bytes: 14380
#include<stdio.h>

int main(void){
    int N=0;
    int a[999999]={0};
    int max1=0;
    int max2=0;
    int max1N=0;
    int max2N=0;
    scanf("%d",&N);
    for(int i=0;i<N;i++){
        scanf("%d",&a[i]);
        if(max1<a[i]){
            max1=a[i];
            max1N=i;
        }
        else if(max2<a[i]){
            max2=a[i];
            max2N=i;
        }
    }
    for(int i=0;i<N;i++){
        if(i==max1N){
            printf("%d\n",max2);
        }
        else{
            printf("%d\n",max1);
        }
    }
    return 0;
}

Measured memory_bytes: 5376
#include <iostream>

using namespace std;

int main(){
    
    int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    
    int k;
    
    cin >> k;
    cout << a[k-1] << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>


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

  int n;
  std::cin >> n;

  auto y = 0.0;
  for (int i = 0; i < n; i++) {
    double x;
    std::string u;
    std::cin >> x >> u;
    y += (u == "JPY" ? x : (x * 380000.0));
  }
  std::cout << y << std::endl;

  return EXIT_SUCCESS;
}


Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>

using namespace std;

int main()
{
	int a, b;
	stack<int> S;
	char str[101];
	int i = 0;
	
	while (scanf("%s", str) != EOF)
	{
		
			if (str[i] == '+')
			{
				a = S.top();
				S.pop();
				b = S.top();
				S.pop();
				S.push(a + b);
			}
			else if (str[i] == '-')
			{
				a = S.top();
				S.pop();
				b = S.top();
				S.pop();
				S.push(b - a);
			}
			else if (str[i] == '*')
			{
				a = S.top();
				S.pop();
				b = S.top();
				S.pop();
				S.push(a * b);
			}
			else if (str[i] != ' ')
			{
				S.push(atoi(str));
			}
			//i++;
		

	}

	printf("%d\n", S.top());
	return 0;
}



Measured memory_bytes: 3220
import fractions
 
A,B,K = map(int, input().split())
 
gcd = fractions.gcd(A,B)
 
ans = []
for i in range(gcd+1):
    if i > 0:
        if gcd % i == 0:
            ans.append(i)

ans.reverse()
 
print(ans[K-1])


Measured memory_bytes: 5048
#include<stdio.h>

int main(void){
  int n;
  scanf("%d",&n);

  long long a[100001] = {0}  , t , ans = 0;
  for(int i = 0;i < n;i ++){
    scanf("%d",&t);
    a[t] ++;
    ans += t;
  }

  int q;
  scanf("%d",&q);

  int b[q] , c[q];
  for(int i = 0;i < q;i ++){
    scanf("%d %d",&b[i],&c[i]);
      ans += (c[i] - b[i]) * a[b[i]];
      a[c[i]] += a[b[i]];
      a[b[i]] = 0;
      printf("%lld\n",ans);
  }

  return 0;
}

Measured memory_bytes: 3248
#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 r, c;
  cin >> r >> c;
  vector<vector<int> > Table(r+1, vector<int>(c+1, 0));

  for (int i=0;i<r;i++){
    for (int j=0;j<c;j++){
      cin >> Table.at(i).at(j);
      cout << Table.at(i).at(j) << ' ';
    }
    Table.at(i).at(c) = std::accumulate(Table.at(i).begin(),Table.at(i).end(),0);
    cout << Table.at(i).at(c)  << endl;
  }
  int sum;
  for (int j=0; j<c+1; j++){
    sum = 0;
    for (int i=0;i<r; i++){
      sum += Table.at(i).at(j);
    }
    Table.at(r).at(j) = sum;
    cout << Table.at(r).at(j);
    if (j==c) break;
      cout << ' ';
  }
  cout << endl;
  return 0;
}


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

void main_()
{
    int N;
    cin >> N;
    vector<int> as;
    copy_n(istream_iterator<int>(cin), 3 * N, back_inserter(as));

    sort(begin(as), end(as));
    auto it_fwd = cbegin(as);
    auto it_rev = crbegin(as);
    int64_t total = 0;
    for (int i = 0; i < N; ++i) {
        it_fwd++;
        it_rev++;
        total += *it_rev;
        it_rev++;
    }
    cout << total << endl;
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


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

#define for_(i,a,b) for(int i=(a);i<(b);++i)

int n, a[25], b[25];

void solve() {
	vector< int > order;
	for_(i,0,n) order.push_back(i);
	
	sort(order.begin(), order.end(), [&](int i, int j) {
		return b[i] == b[j] ? a[i] < a[j] : b[i] < b[j];
	});
	
	int cur = 0;
	bool flag = true;
	
	for_(ii,0,n) {
		int i = order[ii];
		flag &= (cur <= b[i]);
		cur += a[i];
		flag &= (cur <= b[i]);
	}
	
	cout << (flag ? "Yes" : "No") << endl;
}

int main() {
	while (cin >> n, n) {
		for_(i,0,n) cin >> a[i] >> b[i];
		solve();
	}
}

Measured memory_bytes: 3140
#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL),cout.tie(NULL);
    int m;
    string s;
    cin>>m>>s;
    int arr[m];
    int brr[m];
    for(int i=0;i<m;i++)
    {
        if(s[i]=='W')
        {
            arr[i] = 1;
        }
        else
        {
            arr[i] = 0;
        }
        brr[i] = arr[i];
    }
    sort(arr,arr+m);
    int count = 0;
    for(int i=0;i<m;i++)
    {
        if(arr[i]!=brr[i])
        {
            count++;
        }
    }
    cout<<count/2;
    return 0;
}

Measured memory_bytes: 5324
#include<cstdio>
#include<cmath>
using namespace std;
int a[15][15];
int main(){
	int n,d;
	scanf("%d%d",&n,&d);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=d;j++) scanf("%d",&a[i][j]);
	int ans=0;
	for(int i=1;i<=n;i++){
		for(int p=i+1;p<=n;p++){
			double k=0;
			for(int j=1;j<=d;j++) k+=(a[p][j]-a[i][j])*(a[p][j]-a[i][j]);
			k=sqrt(k);
			if((int)k==k) ans++;
		}
	}
	printf("%d",ans);
	return 0;
}


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

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);	
	int N, A, B, sum = 0;
	cin >> N >> A >> B;
	for (int i = 1; i <= N; ++i){
		int digits = 0, number = i;
		while (number != 0){
			digits += number % 10;
			number /= 10;	
		}
		if (digits <= B && digits >= A) sum += i;
	}
	cout << sum << "\n";
	return 0;
}


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

vector<pair<ll,int> > abc[1000001];
vector<bool> v(1000001,true);
vector<ll> cost(1000001,0);

void dfs(ll c,int n){
    if(abc[n].size()==0) ;
    else{
        for(int i=0;i<abc[n].size();i++){
            if(v[abc[n][i].first]){
                v[abc[n][i].first]=false;
                cost[abc[n][i].first]=c+abc[n][i].second;
                dfs(cost[abc[n][i].first],abc[n][i].first);
            }
        }
    }
}

int main(){

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

    ll q,k;
    cin >> q >> k;
    v[k]=false;
    dfs(0,k);

    ll x,y;

    rep(i,q){
        cin >> x >> y;
        cout << cost[x]+cost[y] << endl; 
    }


    return 0;
}

Measured memory_bytes: 42496
#include<stdio.h>
#include<math.h>
#include<string.h>



int main(void){
  long long int h;
  int n;
  scanf("%lld%d",&h,&n);
  int a[n];
  int i,j;
  long long int ans=0;
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
    ans+=a[i];
  }
  if(ans>=h){
    printf("Yes");
    return 0;
  }
  else{
    printf("No");
  }




  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)






int main() {
	string A,B,C;
	cin >>A>>B>>C;
	string s = "NO";
	if(A.at(A.size()-1)==B.at(0)&& B.at(B.size() - 1) == C.at(0))
	{
		s = "YES";
	}
	
	cout <<s<< endl;
}


Measured memory_bytes: 256
import scala.annotation.tailrec
object Main extends App {

  import scala.io.StdIn._

  val n = readInt()
  val persons = Array.fill(n){0}
  for (i <- readLine.trim.split(' ').map(_.toInt)) {
    persons(i - 1) += 1
  }
  println(
    persons.mkString("\n")
  )
}

Measured memory_bytes: 77468
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

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

const long long INF = 1LL << 60;

int main(){
  string s, t; cin >> s >> t;
  int n = s.size();

  bool ok = false;
  rep(i, n){
    char c = s[n-1];
    s.erase(n-1);
    s = c + s;
    if(s == t){
      ok = true;
      break;
    }
  }

  cout << (ok ? "Yes" : "No") << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define mp make_pair
#define pb push_back
#define INF LONG_MAX
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define Ma 1000000007 
#define PI 3.14159265
int main()
{
    ll n,i;
    cin>>n;
    double t,a;
    cin>>t>>a;
    double h[n+1];
    for(i=0;i<n;i++)
    {
        cin>>h[i];
    }
    double mini=abs(a-t+0.006*h[0]);
    ll ind=0;
    for(i=1;i<n;i++)
    {
        if(abs(a-t+0.006*h[i])<=mini)
        {
            mini=abs(a-t+0.006*h[i]);
            ind=i;
        }
    }
    cout<<ind+1<<endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _20170410_AOJ
{
    class ALDS1_10B
    {
        static void Main(string[] args)
        {
            for (;;)
            {
                string line = Console.ReadLine();
                if (string.IsNullOrEmpty(line))
                {
                    break;
                }

                int n = int.Parse(line);
                int[] rc = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                int[] p = new int[n + 1];
                long[,] matrix = new long[n + 1, n + 1];
                p[0] = rc[0];
                p[1] = rc[1];
                for (int i = 2; i <= n; i++)
                {
                    int c = int.Parse(Console.ReadLine().Split(' ')[1]);
                    p[i] = c;
                }

                long min = Min(1, n, p, matrix);

                Console.WriteLine(min);
            }
        }

        static long Min(int i, int j, int[] p, long[,] matrix)
        {
            long rv;
            if (i == j)
            {
                rv = 0;
            }
            else if (matrix[i, j] > 0)
            {
                rv = matrix[i, j];
            }
            else
            {
                long min = long.MaxValue;
                for (int k = i; k < j; k++)
                {
                    long pqr = p[i - 1] * p[k] * p[j];
                    min = Math.Min(min, Min(i, k, p, matrix) + Min(k + 1, j, p, matrix) + pqr);
                }

                rv = min;
                matrix[i, j] = min;
            }

            return rv;
        }
    }
}



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

int main() {

	int n, k; cin >> n >> k;
	int tmp = 1;
	for (int i = 0; i < n; i++) {
		if (tmp + k <= tmp * 2) {
			tmp += k;
		}
		else {
			tmp *= 2;
		}
	}
	
	cout << tmp << endl;
    return 0;
}

Measured memory_bytes: 256