akhauriyash/Code-Regression huggingface dataset:
//g++ t.cpp -o t && t < p.txt
//d>p.txt&&t<p.txt&&t2<p.txt

#include <iostream> // プログラムの耳と口
#include <vector> // 超有能配列秘書
#include <algorithm> // みんな大好きソートと二分探索
#include <queue> // きゅーちゃん、だいすき
#include <string> // to_string
#include <functional> // 関数を変数に入れる子
#include <set> // 値の取得・挿入・削除を高速に
#include <map> // setの妹 これまた優秀
#include <random> // 乱択さん
#include <ctime>
#include <bitset>

#define DB cerr<<"D"<<endl
using namespace std; using ll=long long; using ld=long double; const int INF=1e9; const ll LINF=1e18; const double dINF = 1e18; const ld ldINF = 1e18; const double EPS = 1e-6;
template<typename T, typename U, typename O> void caut(T a, U b, O c){cout<<"("<<a<<","<<b<<","<<c<<") ";} template<typename T, typename U> void caut(T a, U b){cout<<"("<<a<<","<<b<<") ";} template<typename T> void caut(T a){cout<<"("<<a<<") ";};
using P=pair<ll,ll>;
const ll M = 1e9+7;
ll mod_pow(ll x, ll a) { ll an = 1; while(a > 0) { if (a&1) an = an * x % M; x = x * x % M; a >>= 1;} return an;}
void add(ll& x, ll y) {x+=y; x%=M;}; void mul(ll& x, ll y) {x*=y; x%=M;}; template<typename T, typename U> void chmax(T& x, U y) {if (x<y) x=y;}; template<typename T, typename U> void chmin(T& x, U y) {if (x>y) x=y;}
bool vaild(int x, int y, int hh, int ww){return 0<=x&&x<hh&&0<=y&&y<ww;}
int keta(ll a) {int res=0; while(a>0) res+=a%10, a/=10; return res;}
const int up[]={1,-1,0,0}, lf[]={0,0,1,-1};

int main() {
  ll n,k0; cin>>n>>k0;
  ll p[n],c[n];
  for(int i=0;i<n;i++) cin>>p[i];
  for(int i=0;i<n;i++) p[i]--;
  for(int i=0;i<n;i++) cin>>c[i];

  ll an = -1e18;
  for(int i=0;i<n;i++) {
    // 初期地点がi
    ll sm = 0, k = k0, nw = i;
    int id[n]; fill(id,id+n,-1);
    ll su[n]; fill(su,su+n,0);
    for(int j=0;j<k;j++) {
      //cout << nw << " : " << p[nw] << " ";
      //cout << c[nw] << " " << id[nw] << endl;
      
      int nu = p[nw];
      ll lk = k - j;
      ll uk = j - id[nu];
      ll pk = lk / uk - 1;
      
      if (id[p[nw]] >= 0 && pk > 0) {
        ll h = sm - su[nu];
        //cout << h << " " << lk << " " << uk << endl;
        sm += h * pk; k = lk % uk + uk; j=-1;
        fill(id,id+n,-1); fill(su,su+n,0);
      } else {
        nw = p[nw];
        id[nw] = j;
        su[nw] = sm;
        sm += c[nw];
      }
      chmax(an,sm);
    }
    //break;
  }
  cout<<an<<endl;
}
// ・配列の大きさok？　・priority_queueはgreater？　・debug消した？
// ・落ち着いて。提出まで4分待ってね……WJ……1/10……2/10……

// Thank you for making problems and running the contest


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

typedef pair<long long, long long> ii;

long long modInverse(long long a, long long m)
{
    long long m0 = m;
    long long y = 0, x = 1;

    if (m == 1)
      return 0;

    while (a > 1)
    {
        // q is quotient
        long long q = a / m;
        long long t = m;

        // m is remainder now, process same as
        // Euclid's algo
        m = a % m, a = t;
        t = y;

        // Update y and x
        y = x - q * y;
        x = t;
    }

    // Make x positive
    if (x < 0)
       x += m0;

    return x;
}

long long mod = 1000000007;
int main(){
	//freopen("i.txt","r",stdin);
	
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	long long x, y;
	cin >> x >> y;
	if((x + y) % 3 != 0){
		cout << "0\n";
		return 0;
	} 
	long long apb = (x+y)/3;
	long long amb = (x-y);
	
	long long a = (apb+amb)/2;
	long long b = apb - a;
	
	if(a < 0 || b < 0){
		cout << "0\n";
		return 0;
	}
	
	long long ans = 1;
	long long f = 1;
	for(int i = 1;i <= apb;i++){
		f *= i;
		f %= mod;
		if(i == a){
			ans *= modInverse(f,mod);
			ans %= mod;
		}
		if(i == b){
			ans *= modInverse(f,mod);
			ans %= mod;
		}
	} 
	ans *= f;
	ans %= mod;
	cout << ans;
}


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

int main() {
	int d, n;
	cin >> d >> n;
	int ans = n;
	if(n == 100) ans++;
	rep(i, d) ans *= 100;
	cout << ans << endl;
	
	return 0;
}

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

using namespace std;
vector<int> parents;

int root(int k)
{
    /*
    if (parents[k] == k) {
        return k;
    } else {
        return parents[k] = root(parents[k]);
    }
    */

    while (parents[k] != k) {
        k = parents[k];
    }
    return k;
}

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

    for (int i = 0; i < n; i++) {
        parents.push_back(i);
    }

    for (int j = 0; j < q; j++) {
        int c, x, y;
        cin >> c >> x >> y;

        if (c) {
            if (root(x) == root(y))
                cout << 1 << endl;
            else
                cout << 0 << endl;
        } else {
            int rx = root(x);
            int ry = root(y);
            if (rx != ry) {
                parents[rx] = ry;
            }
        }
    }
}

Measured memory_bytes: 3236
#include <algorithm>
#include <iostream>
#include <map>
#include <utility>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> x(n);
  for (int i = 0; i < n; i++) {
    int v;
    cin >> v;
    x[i] = make_pair(v, i);
  }
  sort(x.begin(), x.end());
  map<int, int> m;
  for (int i = 0; i < x.size(); ++i) {
    int prev = x[i].second;
    m[prev] = i;
  }

  for (int i = 0; i < n; i++) {
    if (m[i] < n / 2) {
      cout << x[n / 2].first << endl;
    } else {
      cout << x[n / 2 - 1].first << endl;
    }
  }
  return 0;
}


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

Measured memory_bytes: 600
#include <iostream>
#include <vector>
#include <algorithm>//sort
using namespace std;

int main()
{
	int N;
	cin >> N;
	vector<int> X(N);
	for (int i = 0; i < N; i++)
		cin >> X[i];
	sort(X.begin(), X.end());
	long long ans = 1000000;
	for (int i = 0; i <= 100; i++)
	{
		long long t = 0;
		for (int j = 0; j < N; j++) 
		{
			t += (i - X[j]) * (i - X[j]);
		}
		ans = min(ans, t);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int c1, c5, c10, c50, c100, c500, sum;
  scanf("%d %d %d %d %d %d", &c1, &c5, &c10, &c50, &c100, &c500);

  sum = c1 + c5*5 + c10*10 + c50*50 + c100*100 + c500*500;

  if (sum >= 1000)  printf("1\n");
  else printf("0\n");

  return 0;
}


Measured memory_bytes: 2108
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>

using namespace std;
using ll = long long int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i, a, b)  for(int i = (a); i < (b) ; i++)

#define pb push_back
#define SORT(v,n) sort(v, v+n)
#define ALL(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << ": " << x << '\n'
#define elif else if
#define itn ll
#define int ll
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
///                →,↑,←,↓,↗,↖,↙,↘
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
int i, j, k;

static const int MAX = 10000;
static const int White = 0;
static const int Gray = 1;
static const int Black = 2;

vector<pair<int, int>> adj[MAX];
int n;

void dijkstra() {
	int d[MAX],  color[MAX];
	rep(i, n) {
		d[i] = INF;
		color[i] = White;
	}
	priority_queue<pair<int, int>> PQ;
	PQ.push(make_pair(0, 0));
	d[0] = 0;
	color[0] = Gray;
	while (!PQ.empty()) {
		pair<int,int> f = PQ.top();
		PQ.pop();
		int u = f.second;
		color[u] = Black;
		rep(i, adj[u].size()) {
			pair<int,int> x = adj[u][i];
			int v = x.first;
			int c = x.second;
			if (color[v] == Black) continue;
			if (d[v] < d[u] + c) continue;
				d[v] = d[u] + x.second;
				PQ.push(make_pair(d[v] * -1, v));
				color[v] = Gray;
		}
	}
	rep(i, n) {
		cout << i << ' ' << (d[i] == INF ? -1 : d[i]) << '\n';
	}
}

signed main() {
	ios::sync_with_stdio(false);
	cin >> n;
	rep(i, n) {
		int u,k;
		cin >> u >> k;
		rep(j, k) {
			int v, c;
			cin >> v >> c;
			adj[u].pb(make_pair(v, c));
		}
	}
	dijkstra();
	return 0;
}


Measured memory_bytes: 12156
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0; i<(n); i++)
#define REP2(i,x,n) for(ll i=x; i<(n); i++)
#define REP3(i,x,n) for(ll i=x; i>(n); i--)
#define ALL(n) begin(n),end(n)
#define MAX 500000
#define SENTINEL 2000000000

struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
struct Node
{
    ll key;
    Node *right,*left,*parent;
};
Node *root, *NIL;
//最小の木を探す
Node *treeMinimum(Node *x){
    while (x->left!=NIL)
    {
        x = x->left;
    }
    return x;
}
//次の節点を探す
Node *treeSuccessor(Node *x){
    if(x ->right!=NIL)return treeMinimum(x->right);
    Node *y = x->parent;
    while (y!=NIL&&x==y->right)
    {
        x=y;
        y=y->parent;
    }
    return y;
}
//節点の削除
void treeDelete(Node *z){
    Node *y; //削除する対象
    Node *x; //yの子
    //削除する節点を決める
    if(z->left==NIL||z->right==NIL)y = z;
    else y = treeSuccessor(z);
    //yの子xを決める
    if(y->left!=NIL){
        x = y->left;
    }else{
        x = y->right;
    }
    if(x != NIL){
        x->parent = y->parent;
    }
    if(y->parent==NIL){
        root = x;
    }else{
        if(y == y->parent->left){
            y->parent->left=x;
        }else
        {
            y->parent->right=x;
        }
    }
    if(y != z){
        z ->key=y->key;
    }
    free(y);
}

Node *find(Node *u,ll k){
    while(u!=NIL&&k!=u->key){
        if(k < u->key) u = u->left;
        else u = u->right;
    }
    return u;
}

void insert(ll k){
    Node *y = NIL;
    Node *x = root;
    Node *z;
    //メモリの確保
    z = (Node *)malloc(sizeof(Node));
    z -> key = k;
    z -> left = NIL;
    z -> right = NIL;

    while( x!=NIL ){
        y = x;
        if(z -> key < x ->key){
            x = x->left;
        }else{
            x = x->right;
        }
    }
    z -> parent = y;
    if(y ==NIL){
        root = z;
    }else{
        if(z ->key < y->key){
            y ->left = z;
        }else{
            y ->right = z;
        }
    }
}
void PreorderWalk(Node *u){
    if(u == NIL)return;
    cout << " "<< u->key; 
    PreorderWalk(u->left);
    PreorderWalk(u->right);
}

void InorderWalk(Node *u){
    if(u == NIL)return; 
    InorderWalk(u -> left);
    cout << " "<< u->key;
    InorderWalk(u -> right);
}


int main(){
    ll n,i,x;
    string com;
    cin >> n;
    REP(i,n){
        cin >> com;
        if(com == "insert"){
            cin >> x;
            insert(x);
        }else if(com =="print"){
            InorderWalk(root);
            cout << endl;
            PreorderWalk(root);
            cout << endl;
        }else if(com[0] == 'f'){
            cin >> x;
            Node *t = find(root,x);
            if(t!=NIL){cout << "yes" << endl;}
            else{cout << "no" << endl;}
        }else if(com == "delete"){
            cin >> x;
            treeDelete(find(root,x));
        }
    }
    return 0;
}


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

int main()
{
	int a,b;
	while(scanf("%d %d",&a,&b)==2)
	{
		if(a%3==0 || b%3==0 || (a+b)%3==0)
			printf("Possible\n");
		else
			printf("Impossible\n");
	}
    return 0;
}


Measured memory_bytes: 256
N = int(input())
Ns = list(map(int, input().split()))
Ns.sort()
ans = 0

for i in range(0, N - 2):
	for j in range(i + 1, N - 1):
		for k in range(j + 1, N):
			if(Ns[i] == Ns[j] or Ns[k] == Ns[j]):
				continue

			if(Ns[i] + Ns[j] > Ns[k] and Ns[j] + Ns[k] > Ns[i] and Ns[k] + Ns[i] > Ns[j]):
				ans += 1
print(ans)

Measured memory_bytes: 73164
#include <iostream>
#include<iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(ll i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout<< "YES"<<endl;
#define No cout<< "No"<<endl;
#define Yes cout<< "Yes"<<endl;
#define all(a) a.begin(),a.end()
#define P pair<int,int>
#define space ' '
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない

const int maxn = 100000;

int main(){
    
    ll n,k;
    ll mod=INF;
    ll ans = 1;
    int from[maxn]={0};
    vector<vector<int> > v(maxn);
    bool used[maxn]={0};
    
    cin >> n>>k;
    rep(i,n-1){
        int a,b;cin >> a>>b;a--;b--;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    
//    if(n>=3&&k<3){
//        cout <<0<<endl;
//        return 0;
//    }
    
    queue<int> que;
    que.push(0);
    used[0]=true;
    ans = k;
    int depth=1;
    
    while(!que.empty()){
        int arg = que.front();que.pop();
        int prefrom=INF;
        ll cnt = 1;
        if(depth>=2)cnt=2;
        rep(i,v[arg].size()){
            if(!used[v[arg][i]]){
                que.push(v[arg][i]);
                used[v[arg][i]]=true;
                from[v[arg][i]]=arg;
                if(depth==1){
                    ans = ans*(k-cnt)%mod;
                    cnt++;
                }else{
                    if(arg!=prefrom)cnt=2;
                    ans = ans*(k-cnt)%mod;
                    cnt++;
                    prefrom=arg;
                }
            }
        }
        //cout << depth << space<<ans<<endl;
        depth++;
    }
    
    cout << ans<<endl;
    
    return 0;
}


Measured memory_bytes: 6648
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;

int main(){
    int m,k;
    cin >> m >> k;
    vector<int> a(1<<(m+1),0);
    if(k >= (1<<m)){
        cout << -1 << endl;
        return 0;
    }
    if(m==1&&k==0){
        rep(i,2) cout << 0 << " ";
        rep(i,2) cout << 1 << " ";
        cout << endl;
        return 0;
    }
    if(m==1&&k==1){
        cout << -1 << endl;
        return 0;
    }
    int id = 0;
    a[id++] = k;
    for(int i=0;i<(1<<m);i++){
        if(i!=k) a[id++] = i;
    }
    a[id++] = k;
    for(int i=(1<<m)-1;i>=0;i--){
        if(i!=k) a[id++] = i;
    }
    rep(i,1<<(m+1)){
        cout << a[i] << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 4288
#include <bits/stdc++.h>
#define INF 2e9
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  cout<<fixed<<setprecision(10);
  int count=1;
  int N;
  cin >> N;
  string s;
  cin >> s;
  for(int i=1; i<N; ++i){
    if(s[i-1]!=s[i]) ++count;
  }
  cout << count << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e2+10;
long long D,G,p[MAXN],c[MAXN];
int main(){
    scanf("%lld %lld",&D,&G);
    for(int i=0;i<D;i++){
        scanf("%lld %lld",&p[i],&c[i]);
    }
    long long ans = LONG_LONG_MAX;
    for(int mask =0;mask<(1<<D);mask++){
        long long s = 0,num = 0,rest_max = -1;
        for(int i=0;i<D;i++){
            if(mask >> i & 1){
                s += 100 * (i+1) * p[i] + c[i];
                num += p[i];
            }
			else{
                rest_max = i;
            }
        }
        if(s < G){
            int s1 = 100 * (rest_max + 1);
            int need = (G - s + s1 - 1) / s1;
            if(need >= p[rest_max]){
                continue;
            }
            num += need;
        }
        ans = min(ans, num);
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<numeric>
#include<limits>
#include <cstdint>
using namespace std;
#define rep(N) for(int i=0;i<N;i++)
#define rep2(N1,N2) for(int i=0;i<N1;i++)for(int j=0;j<N2;j++)
#define rep3(N1,N2,N3)for(int i=0;i<N1;i++)for(int j=0;j<N2;j++)for(int k=0;k<N3;k++)
#define For(i,N) for(int i=0;i<N;i++)
#define ll long long int
void yn(bool b) {
	if (b)printf("yes\n");
	else printf("no\n");
}

void Yn(bool b) {
	if (b)printf("Yes\n");
	else printf("No\n");
}

void YN(bool b) {
	if (b)printf("YES\n");
	else printf("NO\n");
}

int ctoi(char c) {
	return c - '0';
}

ll kai(ll x) {
	ll a = 1;
	if (x <= 0)
		return 1;
	else {
		for(ll i=0;i<x;i++)
			a = a * (i + 1);
		return a;
	}
}

ll rui(ll x, ll y) {
	ll a = 1;
	for (ll i = 0; i < y; i++)
		a = a * x;
	return a;
}
const int nmax = 150;
int cccc[nmax][nmax];
ll comb(ll n, ll k) {
	if (n < k) {
		cout << "error n<k"<<endl;
		return -1;
	}
	if (cccc[n][k] > 0)return cccc[n][k];
	if (k == 0 || n == k)return 1;
	return cccc[n][k] = comb(n - 1, k - 1) + comb(n - 1, k);
}

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

ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
int main() {
	//cout.precision(20);
	ll N;
	cin >> N;
	vector<ll>a(N+1);

	rep(N)
		cin >> a[i + 1];
	ll ans = 0;
	ll memo = 1;
	ll i = 1;
	while (1) {
		if (a[i] != memo)
			ans++;
		else {
			memo++;
		}
		i++;
		if (i == N+1)
			break;
	}
	if (ans < N)
		cout << ans;
	else
		cout << -1;
}

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

#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ii pair<int,int>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<ii>

using namespace std;

const int maxn = 1e6+10;

int hist[maxn];

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin>>n;
	vi vs(n);
	for(int &x:vs){
		cin>>x;
		hist[x]++;
	}
	sort(all(vs));
	if(hist[1]>=1){
		if(hist[1]==1){
			cout<<1<<endl;
		}
		else{
			cout<<0<<endl;
		}
		exit(0);
	}
	int ans=n;
	for(int x:vs){
		if(hist[x]>1){
			--ans;
			continue;
		}
		for(int k=2;k*k<=x;++k){
			if(x%k==0 && (hist[k] || hist[x/k])){
				--ans;
				break;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 8108
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
const ll mod=1e9+7 ;
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;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}





int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string s,t;
    cin>>s>>t;
    int cnt=0;
    for(int i=0;i<s.length();i++){
        if(s[i]==t[i])cnt++;
    }
    cout<<cnt<<endl;
    return 0;
    }


Measured memory_bytes: 256
#include <stdio.h>

//構造体
typedef struct dice
{
	int Upper;
	int South;
	int East;
	int West;
	int North;
	int Under;
} Dice;

//構造体を初期化する
Dice InitDice(void);
//要素を入れ替える
Dice ChangeNum_East(Dice Dice);
Dice ChangeNum_West(Dice dice);
Dice ChangeNum_North(Dice dice);
Dice ChangeNum_South(Dice dice);
//右の面を探して表示する
void SearchRight(Dice dice, int upper, int front);

#define queMax 24
#define diceFace 6

int main(void)
{
	Dice dice = InitDice();	//さいころ
	int num[diceFace];		//数値を入れる配列
	int upper = 0;				//上の面
	int front = 0;				//前の面
	int q;					//質問の数
	int i;

	//ラベルにデータを入力する
	for (i = 0; i < 6; i++)
	{
		num[i] = 0;
		scanf("%d", &num[i]);
	}

	//さいころに数値を入力する
	dice.Upper = num[0];
	dice.South = num[1];
	dice.East = num[2];
	dice.West = num[3];
	dice.North = num[4];
	dice.Under = num[5];

	//質問の数を入力する
	scanf("%d", &q);

	//質問の内容を入力する
	for (i = 0; i < q; i++)
	{
		scanf("%d%d", &upper, &front);

		//上の面がさいころの上の面と一致したら
		if (dice.Upper == upper)
		{
			SearchRight(dice, upper, front);
		}
		//上の面がさいころの下の面と一致したら
		else if (dice.Under == upper)
		{
			dice = ChangeNum_East(dice);
			dice = ChangeNum_East(dice);
			SearchRight(dice, upper, front);
		}
		//上の面がさいころのS方向の面と一致したら
		else if (dice.South == upper)
		{
			dice = ChangeNum_North(dice);
			SearchRight(dice, upper, front);
		}
		//上の面がさいころのE方向の面と一致したら
		else if (dice.East == upper)
		{
			dice = ChangeNum_West(dice);
			SearchRight(dice, upper, front);
		}
		//上の面がさいころのW方向の面と一致したら
		else if (dice.West == upper)
		{
			dice = ChangeNum_East(dice);
			SearchRight(dice, upper, front);
		}
		//上の面がさいころのN方向の面と一致したら
		else if (dice.North == upper)
		{
			dice = ChangeNum_South(dice);
			SearchRight(dice, upper, front);
		}
		else
		{
			//何もしない
		}

	}

	return 0;
}

//構造体を初期化する
Dice InitDice(void)
{
	Dice di;
	di.Upper = 0;
	di.South = 0;
	di.East = 0;
	di.West = 0;
	di.North = 0;
	di.Under = 0;
	return di;
}

//E方向に転がしたとき
Dice ChangeNum_East(Dice dice)
{
	Dice di = InitDice();
	di.Upper = dice.West;
	di.South = dice.South;
	di.East = dice.Upper;
	di.West = dice.Under;
	di.North = dice.North;
	di.Under = dice.East;
	return di;
}

//W方向に転がしたとき
Dice ChangeNum_West(Dice dice)
{
	Dice di = InitDice();
	di.Upper = dice.East;
	di.South = dice.South;
	di.East = dice.Under;
	di.West = dice.Upper;
	di.North = dice.North;
	di.Under = dice.West;
	return di;
}

//N方向に転がしたとき
Dice ChangeNum_North(Dice dice)
{
	Dice di = InitDice();
	di.Upper = dice.South;
	di.South = dice.Under;
	di.East = dice.East;
	di.West = dice.West;
	di.North = dice.Upper;
	di.Under = dice.North;
	return di;
}

//S方向に転がしたとき
Dice ChangeNum_South(Dice dice)
{
	Dice di = InitDice();
	di.Upper = dice.North;
	di.South = dice.Upper;
	di.East = dice.East;
	di.West = dice.West;
	di.North = dice.Under;
	di.Under = dice.South;
	return di;
}

//右の面を探して結果を表示する
void SearchRight(Dice dice, int upper, int front)
{
	int right = 0;
	if (dice.South == front)
	{
		right = dice.East;
	}
	else if (dice.East == front)
	{
		right = dice.North;
	}
	else if (dice.West == front)
	{
		right = dice.South;
	}
	else if (dice.North == front)
	{
		right = dice.West;
	}
	else
	{
		//何もしない
	}
	printf("%d\n", right);
}


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

int main(){

  
    long mini=10000000000000;
  long n;
  cin >> n;
  for(long i=1;i*i<=n;i++){
    if(n%i==0)
      mini = min(mini,i+n/i-2);}
    
	cout<< mini;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = int_fast64_t;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

void answer() {
  int n;
  cin >> n;
  string s, t;
  cin >> s >> t;
  string ans = "";
  rep(i,n) ans += s[i], ans += t[i];
  cout << ans << "\n";
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int t;
  cin >> t;
  int ans = 0,o = 0;
  while(t--){
    int a,b;
    cin >> a >> b;
    if(a==b) o++;
    else o=0;
    ans=max(ans,o);
  }
  if(ans>=3) cout <<"Yes";
  else cout <<"No";
  return 0;
}

Measured memory_bytes: 3600
#include <cstdio>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <iostream>

using namespace std;
typedef long long lli;
typedef pair<int,int> pii;
typedef pair<lli,int> pli;
typedef pair<lli,lli> pll;

int n;
int chk[30001];
int main() {
	scanf("%d",&n);
	if(n==3) {
		printf("2 5 63\n");
		return 0;
	}
	int thn = n/2;
	thn = min(thn,5000);
	if(thn%2==1) thn++;
	int twn=n-thn;
	twn = min(twn,10000);
	if(twn%2==1) {
		if(thn + twn + 1 < n) twn++;
		else twn--;
	}

	
	for(int i=0,j=3;i<thn;i++,j+=6) printf("%d ",j);
	for(int i=0,j=2;i<twn;i++,j+=2) {
		if(j%6==0) {
			i--;
			continue;
		}
		printf("%d ",j);
	}
	for(int i=0,j=6;i<n-thn-twn;i++,j+=6) {
		printf("%d ",j);
	}

	return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int H, W;
char C[300][300];
int dp[302][302], s[301][301];

int f(int x) {
  if (x < 0 || x+1 >= W) return 0;
  rep(i, H+1) rep(j, H+1) dp[i][j] = INF, s[i][j] = 0;
  for (int d=0; d<=H; d++) {
    // 0 d
    for (int a=0; a<=H; a++) {
      if (a+d+1>H) break;
      s[a+1][a+d+1] = s[a][a+d] + (C[x][a] == C[x+1][a+d]);
    }
    // d 0
    for (int a=0; a<=H; a++) {
      if (a+d+1>H) break;
      s[a+d+1][a+1] = s[a+d][a] + (C[x][a+d] == C[x+1][a]);
    }
  }

  dp[0][0] = 0;
  rep(a, H+1) {
    rep(b, H+1) {
      if (dp[a][b] == INF) continue;
      dp[a+1][b] = min(dp[a+1][b], dp[a][b] + s[H-a][H-b]);
      dp[a][b+1] = min(dp[a][b+1], dp[a][b] + s[H-a][H-b]);
    }
  }
  return dp[H][H];
}

int solve(int x, int l, int r) {
  // [l,x) x (x,r]
  if (l >= r) return 0;
  int m = f(x-1) + f(x);
  return m + solve((l+x-1)/2, l, x-1) + solve((x+1+r)/2, x+1, r);
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> H >> W;
  rep(y, H) {
    rep(x, W) {
      cin >> C[x][y];
    }
  }
  long long s = 0;
  rep(i, W) s += f(i);
  //cout << solve((W-1)/2, 0, W-1) << "\n";
  cout << s << "\n";
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1<<30;
vector<int> A;
const int mod = 1e9+7;

bool ok(int N) {
  if(N % 2 == 1) {
    // if(count(A.begin(), A.end(), 0) != 1) return false;
    // for(int i = 2; i < N; i+=2) {
      // if(count(A.begin(), A.end(), i) != 2) return false;
    // }
    for(int i = 0; i < N; i++) {
      if(A[i] != (i+1)/2*2) return false;
    }
    return true;
  } else {
    // for(int i = 1; i < N; i+=2) {
      // if(count(A.begin(), A.end(), i) != 2) return false;
    // }
    for(int i = 0; i < N; i++) {
      if(A[i] != i/2*2+1) return false;
    }
    return true;
  }
}

int main() {
  int N; cin >> N;
  A.resize(N);
  for(int i = 0; i < N; i++) cin >> A[i];
  sort(A.begin(), A.end());
  if(!ok(N)) {
    cout << 0 << endl;
    return 0;
  } else {
    long long ans = 1;
    for(int i = 0; i < N/2; i++) {
      ans *= 2;
      ans %= mod;
    }
    cout << ans << endl;
  }
  return 0;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define pb push_back
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
//グリッド：（典型）dp,dfs,bfs,最短経路,その他
ll m;
vi t;
bool check(string s){
    int n=sz(s);
    int p=0;
    bool ok=true;
    m=0;
    if(s[0]!='1'){
        return false;
    }
    while(p<=(n-2)/2){
        if(s[p]!=s[n-p-2]){
            ok=false;
            break;
        }
        if(s[p]=='1'&&s[n-p-2]=='1'){
            t.pb(p+1);
            if(p!=n-p-2){t.pb(n-p-1);}
        }
        p++;
    }
    return ok;
}
int main(){
    string s;cin>>s;
    int n=sz(s);
    if(s[n-1]=='1'){
        cout<<-1<<endl;
        return 0;
    }
    if(!check(s)){
        cout<<-1<<endl;
        return 0;
    }
    vector<l_l> ans;
    ll u0=1;
    ll u,v=0;
    sort(t.begin(),t.end());
    //for(auto pp:t)cout<<111<<" "<<pp<<endl;
    rrep(i,sz(t)-1){
        if(v==0)v=u0+1;
        u=v;
        ans.pb({u0,v++});
        while(v<=t[i]){
            ans.pb({u,v++});
        }
        u0=u;
    }
    ans.pb({u0,n});
    for(auto pp:ans)cout<<pp.fi<<" "<<pp.se<<endl;
    return 0;
}

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

#define int long long int
int i;
main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int t=a; int an=c;
    while(t>0 && an>0)
    {

        an=an-b;
        t=t-d;
        //cout<<t<<' '<<an<<endl;
        if(t<=0 || an<=0) break;
    }
    if(an<=0) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 3576
#include<iostream>
#include<cstdio>
#define INF 1000000007
using namespace std;

int main(void){
    double a, b;
    cin >> a >> b;
    int c = a, d = b;
    cout << c / d << ' ' << c % d;
    printf(" %lf\n", a / b);

    return 0;
}


Measured memory_bytes: 3276
#include <stdio.h>

int main(void){
	int n,i,j;
	int a[100];	
	scanf("%d",&n);
	
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	for(i=0;i<n-1;i++){
		j=n-1-i;
		printf("%d ",a[j]);
	}
	printf("%d\n",a[0]);
return 0;
}


Measured memory_bytes: 2048
n, a, b, c, d = map(int, input().split())
s = input()
if s[a-1:c].count('##') == 0 and s[b-1:d].count('##') == 0:
    if c < d:
        print('Yes')
    elif s[b-2:d+1].count('...') >= 1:
        print('Yes')
    else:
        print('No')
else:
    print('No')

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

namespace agc032_a
{
  class Program
  {
    static void Main(string[] args)
    {
      var n = CIn.ReadInt();
      var b = CIn.ReadIntArray(n).ToList();

      var ans = new List<int>();

      for (var i = 1; i <= n; i++)
      {
        for (var j = n - i; j >= 0; j--)
        {
          if (b[j] == j + 1)
          {
            ans.Add(j + 1);
            b.RemoveAt(j);
            break;
          }
        }

        if (ans.Count < i)
        {
          Console.WriteLine(-1);
          return;
        }
      }

      ans.Reverse();

      foreach (var e in ans)
      {
        Console.WriteLine(e);
      }
    }
  }

  class CIn
  {
    private static readonly Queue<string> fieldBuffer = new Queue<string>();

    public static string Read()
    {
      if (fieldBuffer.Count == 0)
      {
        foreach (var field in Console.ReadLine().Split())
        {
          fieldBuffer.Enqueue(field);
        }
      }

      return fieldBuffer.Dequeue();
    }

    public static int ReadInt() => int.Parse(Read());
    public static long ReadLong() => long.Parse(Read());
    public static double ReadDouble() => double.Parse(Read());

    public static string[] ReadStringArray(long n)
    {
      var array = new string[n];

      for (var i = 0; i < n; i++)
      {
        array[i] = Read();
      }

      return array;
    }

    public static int[] ReadIntArray(long n)
    {
      var array = new int[n];

      for (var i = 0; i < n; i++)
      {
        array[i] = ReadInt();
      }

      return array;
    }

    public static long[] ReadLongArray(long n)
    {
      var array = new long[n];

      for (var i = 0; i < n; i++)
      {
        array[i] = ReadLong();
      }

      return array;
    }
    public static double[] ReadDoubleArray(long n)
    {
      var array = new double[n];

      for (var i = 0; i < n; i++)
      {
        array[i] = ReadDouble();
      }

      return array;
    }
  }
}

Measured memory_bytes: 13396
x,y = map(int,input().split())

#最初に反転するか
#1を増やし続ける
#最後に反転するか
#この組み合わせにより4パターンについて計算すればよい

ans=float('inf')
#反転なし、反転なし
if x<=y:
    ans = min(ans,y-x)
#あり、なし
if -x<=y:
    ans = min(ans,y+x+1)
#なし、あり
if x<=-y:
    ans = min(ans,-y-x+1)
#あり、あり
if -x<=-y:
    ans = min(ans,-y+x+2)
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={0,1,0,-1,1,-1,-1,1};
int dy[]={1,0,-1,0,1,1,-1,-1};
const int MOD = 1e9+7;
const int INF = 1e18+10;

/*----------------------------------------------*/
int n,m,q;
vi a(50),b(50),c(50),d(50);
int ans;

void dfs(int keta,int last,vi V){
  if(keta==n){
    int tmp=0;
    rep(i,q){
      if(V[b[i]-1]-V[a[i]-1]==c[i]) tmp+=d[i];
    }
    chmax(ans,tmp);
    return;
  }

  for(int k=0;last+k<=m;k++){
    if(keta==0&&k==0) continue;
    vi U;
    rep(i,V.size()) U.pb(V[i]);
    U.pb(last+k);
    dfs(keta+1,last+k,U);
  }


}

signed main(){
  cin>>n>>m>>q;
  rep(i,q) cin>>a[i]>>b[i]>>c[i]>>d[i];

  ans=-1;
  vi V;
  dfs(0,0,V);



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

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

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

    //map[今] = 開始の最大値
    map<int,int> s;
    //答えを求める用
    multiset<int> vals;

    for(int i=0; i<w; ++i){
        s[i]  = i;
    }

    for(int i=0; i<w; ++i){
        vals.insert(0);
    }

    for(int i=0; i<h; ++i){
        int l, r;
        cin >> l >> r;
        --l;
        //init most right
        int mr = -1;

        //l以上で一番小さい値を返す
        auto it = s.lower_bound(l);
        while(it != s.end() && it->first <= r){
            mr = max(mr, it->second);
            int x = it->first - it->second;
            //削除してインクメントされる
            s.erase(it++);
            vals.erase(vals.find(x));
        }
        //rが画面の端の場合は行けないので　w未満
        if(mr != -1 && r < w){
            vals.insert(r - mr);
            s[r] = mr;
        }

        int ans = -1;
        if(vals.size() > 0){
            //右移動と縦移動の回数
            ans = *vals.begin() + (i+1);
        }
        printf("%d\n", ans);
    }
    return 0;
}

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

 int main() {
   char S[3];
   cin >> S;
   string  res = "No";
   sort(S,S+4);
   if (S[0] == S[1] && S[1] != S[2] && S[2] ==S[3] ) {
     res = "Yes";
   }

   cout << res << '\n';
 }


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var takahashi, normalPrice int
	fmt.Scan(&takahashi, &normalPrice)

	if takahashi >= 13 {
		fmt.Println(normalPrice)
	} else if takahashi >= 6 {
		fmt.Println(normalPrice / 2)
	} else {
		fmt.Println(0)
	}
}


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

int main(){
    int x1, y1, x2, y2, x3, y3, x4, y4, a, b;
    cin >> x1 >> y1 >> x2 >> y2;
    a = x2 - x1;
    b = y2 - y1;
    x3 = x2 - b;
    y3 = y2 + a;
    x4 = x1 - b;
    y4 = y1 + a; 
    cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
    return 0;
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}


int main(void) {
  int64 N, X;
  cin >> N >> X;
  int64 D = 0, cnt = 1;
  REP(i, N) {
    int64 L;
    cin >> L;
    D += L;
    cnt += D <= X;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
  int l1,l2,i=0,j=25,sk[26]={},tk[26]={};
  char s[101],t[101];
  bool ans;
  scanf("%s%s",s,t);
  for (l1=0;s[l1];l1++) sk[(int)s[l1]-97]++;
  for (l2=0;t[l2];l2++) tk[(int)t[l2]-97]++;
  while (sk[i]==0) i++;
  while (tk[j]==0) j--;
  if (i<j) ans=true;
  else if (i>j) ans=false;
  else{
    if (sk[i]==l1){
      if (tk[i]==l2){
        if (l1<l2) ans=true;
        else ans=false;
      }else{
        if (sk[i]>tk[i]) ans=false;
        else ans=true;
      }
    }else ans=false;
  }
  printf("%s\n",(ans)? "Yes":"No");
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
long long s;
int n,a[N],b[N],i,j;
int main(){
	scanf("%d",&n);
	for(i=1;i<=n;++i)scanf("%d",a+i);
	for(i=1;i<=n;++i)scanf("%d",b+i),s+=a[i]-=b[i];
	if(s<0)return puts("-1"),0;
	sort(a+1,a+n+1);s=0;
	for(i=1;a[i]<0;++i)s+=a[i],++j;
	for(i=n;s<0;s+=a[i--]);printf("%d\n",n-i+j);
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <iomanip>
#include"stdio.h"
#include <cstring>
#include<math.h>
#include<map>
#include<queue>
#include<stack>
#include"time.h"
#define MAX_INT  ((unsigned)(-1)>>1)
#define MIN_INT  (~MAX_INT)
#define db printf("where!\n");
#define pb push_back
using namespace std;
#define ll long long
template<class T>inline void read(T &res){
char c;T flag=1;
while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;res=c-'0';
while((c=getchar())>='0'&&c<='9')res=res*10+c-'0';res*=flag;
}

int main()
{
    int t;read(t);
    ll num=0;
    for(int i=1;i<=t;i++) if(i%3!=0 &&i%5!=0) num+=i;
    cout<<num<<endl;

    return 0;
}

Measured memory_bytes: 3128
#include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x);
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 1000000000;
typedef double D;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4]={-1, 0, 1, 0}, dy[4]={0, -1, 0, 1};
using namespace std;
//typedef pair<int, int> P;

/** Problem2007 : Make Purse Light **/
int main()
{
	int label[] = {10, 50, 100, 500};
	int num[4], price;
	bool first=true;
	while (cin>>price, price) {
		rep(i, 4) {
			cin>>num[i];
		}
		int ret = -price;
		rep(i, 4) {
			ret += num[i]*label[i];
		}
		int ans[4] = {0};
		while (ret>=500) {
			ret-=500;
			ans[3]++;
		}
		while (ret>=100) {
			ret-=100;
			ans[2]++;
		}
		while (ret>=50) {
			ret-=50;
			ans[1]++;
		}
		while (ret>=10) {
			ret-=10;
			ans[0]++;
		}
		if (!first)
			cout << endl;
		else
			first = false;
		
		rep(i, 4) {
			ans[i] = max(0, num[i]-ans[i]);
			if (ans[i] != 0)
				cout << label[i] << " " << ans[i] << endl;
		}
	}
}

Measured memory_bytes: 1160
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int D =sc.nextInt();
        int sum_price =0;
        if(A>=B) sum_price += B;
        else sum_price +=A;
        if(C>=D) sum_price+=D;
        else sum_price+=C;

        System.out.println(sum_price);
         }
}

Measured memory_bytes: 23508
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
# from fractions import gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    N = INT()
    S = [INPUT() for _ in range(N)]

    c = Counter(S)
    m = 0
    ans = []
    for key, value in c.most_common():
        if value >= m:
            m = value
            ans.append(key)
        else:
            continue

    ans.sort()
    print(*ans, sep='\n')


if __name__ == '__main__':
    main()


Measured memory_bytes: 45612
#include <map>
#include <set>
#include <list>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <bitset>
#include <vector>
#include <cstdio>
#include <string>
#include <cstring>
#include <sstream>
#include <iomanip>
#include <cstdlib>
#include <utility>
#include <iostream>
#include <algorithm>
using namespace std;
int a[15];
int main ( ) {
	int n,i;
	long long ans1=1,ans2=1;
	scanf("%d",&n);
	for (i=1;i<=n;i++) {
		scanf("%d",&a[i]);
		ans1*=3;
		if (a[i]%2==0) ans2*=2;
	}
	printf("%lld\n",ans1-ans2);
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<long long> A(N);
  for (int i=0; i<N; i++) cin >> A.at(i);
  sort(A.begin(), A.end(), greater<long long>());
  long long tmpi, tmpj;
  bool is_r = false;
  for(int i=1; i<N; i++) {
    if (A.at(i) == A.at(i-1)) {
      for (int j=i+2; j<N; j++) {
        if (A.at(j) == A.at(j-1)) {
          tmpi=A.at(i); tmpj=A.at(j); is_r=true; break;
        }
      }
      if (is_r) break;
    }
  }
  cout << tmpi*tmpj << endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
int main() {
	int n;
	std::cin >> n;
	std::vector<int>v;
	int num;
	for (int i = 0; i < n; ++i) {
		std::cin >> num;
		v.push_back(num);
	}
	std::sort(v.begin(), v.end());
	int ct=0;
	bool bl=1;
	for (int i = 0; i < v.size(); ++i) {
		if (i > 0 && v[i] == v[i - 1])bl = !bl;
		if (bl)++ct;
		else {
			--ct; if (v[i] != v[i - 1]) {ct+=2; bl = 1; }
		}
	}
	std::cout << ct << std::endl;
	return 0;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define rev(v) reverse(v.begin(), v.end())
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
#define uniq(a) sort(all(a));(a).resize(unique(all(a)) - a.begin());
#define dab(v) for(auto i:v)cout<<i<<' '; cout << endl;
#define vin(v) for (ll i = 0; i < v.size(); ++i) cin >> v[i];
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    //cout << fixed << setprecision(15);
    
    int X,Y,Z; cin>>X>>Y>>Z;
    swap(X,Y); swap(X,Z);
    cout << X << " " << Y << " " << Z << endl;
}

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


int main(){
  string S;
  cin >> S;
  int len = S.size();
  int bwb = 0;
  int wbw = 0;
  for(int ii=0; ii<len; ii++){
    if(ii%2){
      if(S[ii]=='0'){
        bwb++;
      }else{
        wbw++;
      }
    }else{
      if(S[ii]=='1'){
        bwb++;
      }else{
        wbw++;
      }
    }
  }
  cout << min(bwb, wbw) << endl;
  return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <vector>
using namespace std;

class Queue{
public:
	int* Q;
	int head;
	int tail;
	int size;

	Queue(int n);
	~Queue();
	Queue(const Queue &other);

	void enqueue(int x);
	int dequeue();
	bool isEmpty();
	bool isFull();
};

Queue::Queue(int n){
	Q = new int[n + 1];
	size = n + 1;
	head = 0;
	tail = 0;
	return;
}

Queue::Queue(const Queue &other){
	Q = new int[other.size];
	size = other.size;
	head = other.head;
	tail = other.tail;
	copy(other.Q, other.Q + size, Q);
}

Queue::~Queue(){
	delete[] Q;
}

void Queue::enqueue(int x){
	Q[tail] = x;
	tail = (tail + 1) % size;
	return;
}

int Queue::dequeue(){
	int x = Q[head];
	head = (head + 1) % size;
	return x;
}

bool Queue::isEmpty(){
	return (tail == head);
}

bool Queue::isFull(){
	return (tail - head == size - 1 || tail - head == -1);
}

int main(){
	int n, q, wt;
	cin >> n >> q;
	Queue Que(n);
	vector<string> name(n);
	vector<int> time(n);

	for (int i = 0; i != n; i++){
		cin >> name[i] >> time[i];
		Que.enqueue(i);
	}

	wt = 0;
	while (!Que.isEmpty()){
		int iter = Que.dequeue();
		time[iter] -= q;
		if (0 >= time[iter]){
			cout << name[iter] << " " << wt + time[iter] + q << endl;
			wt += time[iter] + q;
		}
		else{
			Que.enqueue(iter);
			wt += q;
		}
	}

	return 0;
}


Measured memory_bytes: 5976