akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std; 
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ll long long
long long min(long long x,long long y){return (x<y ? x:y);}
long long max(long long x,long long y){return (x>y ? x:y);}
#define ld long double
int stoi(string s) {return atoi(s.c_str());}

int main(){
  string s; cin >> s;
  int Q; cin >> Q;
  char left[Q];
  int l_point = 0;
  char right[Q];
  int r_point = 0;
  int t,f;
  char c;
  bool flag_r = false;
  REP(i,Q){
    cin >> t;
    if(t==1){
      flag_r = !flag_r;
    }else{
      cin >> f >> c;
      if(flag_r){
        if(f==1){ right[r_point] =  c; r_point++;}
        else { left[l_point] = c; l_point++;}
      }else{
        if(f==1){
          left[l_point] = c; l_point++;
        }else{
          right[r_point] =  c; r_point++;
        }
      }
    }  
  }
  if(!flag_r){
    for(int i=l_point-1;i>=0;i--){
      printf("%c",left[i]);
    }
    cout << s;
    REP(i,r_point){
      printf("%c",right[i]);
    }
    printf("\n");
  }else{
    for(int i=r_point-1;i>=0;i--){
      printf("%c",right[i]);
    }
    reverse(s.begin(),s.end() );
    cout << s;
    REP(i,l_point){
      printf("%c",left[i]);
    }
    printf("\n");
  }
}

Measured memory_bytes: 1024
#include <cstdio>
using namespace std;

int main(){
	int a[4], b[4];
	int hit, blow;
	
	while((scanf("%d", &a[0])) != EOF){
		for(int i = 1; i < 4; i++) scanf("%d", &a[i]);
		for(int i = 0; i < 4; i++) scanf("%d", &b[i]);
		
		hit = 0; blow = 0;
		for(int i = 0; i < 4; i++){
			for(int j = 0; j < 4; j++){
				if(a[i] == b[j]){
					if(i == j) hit++;
					else blow++;
				}
			}
		}
		
		printf("%d %d\n", hit, blow);
	}
	
	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
int main(){
  int a,n;
  double x,y;
  scanf("%d\n",&n);
  if(n%2==0){
    a=n/2;
  }
  else{
    a=n/2+1;
  }
  x=a,y=n;
  printf("%lf\n",x/y);
  return 0;
}

Measured memory_bytes: 128
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i=(n); i>=0; --i)
#define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define EACH(i, v) for(const auto& i : v)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class Value>using vec = vector< Value >;
using ll = long long;
using P = pair< long long, long long >;
#define fi first
#define se second
#define el endl
#pragma endregion

void Main();

int main(){
    std::cin.tie(nullptr);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


void Main(){
    int A, B;
    cin >> A >> B;
    cout << max(A-2*B, 0) << el;
}



Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'

using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9+7;

bool isok[1<<17][20];
ll dp[50][1<<17];

int main() {
  int N,X,Y,Z;
  cin >> N >> X >> Y >> Z;
  int S = X+Y+Z;
  repeat(b,1<<S){
    repeat(i,10){
      int s = ((b<<1)+1)<<i;
      isok[b][i+1] = !( (1&(s>>(Z-1))) && (1&(s>>(Y+Z-1))) && (1&(s>>(X+Y+Z-1))) );
    }
  }
  repeat(s,1<<S){
    dp[N][s]=1;
  }

  for(int i=N-1;i>=0;i--){
    repeat(s,1<<S){
      //cerr << bitset<16>(s) << endl;
      repeat(n,10){
        if(isok[s][n+1]){
          //cerr << bitset<16>(s) << endl;
          dp[i][s] = (dp[i][s]+dp[i+1][(((s<<1)+1)<<n)%(1<<S)])%MOD;
        }
      }
    }
  }

  ll pow10 = 1;
  repeat(i,N){
    pow10 = pow10*10%MOD;
  }
  cout << (pow10-dp[0][0]+MOD)%MOD << endl;
  return 0;
}


Measured memory_bytes: 45824
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<string>
#include<utility>
#include<array>
#include<set>
#include <numeric>
#define EPS (1e-7)
using namespace std;


long long lcm(long long n, long long m) {
	long long r,x,tmp;
	x = m * n;
	/* 自然数 a > b を確認・入替 */
	if (n < m) {
		tmp = n;
		n = m;
		m = tmp;
	}

	/* ユークリッドの互除法 */
	r = n % m;
	while (r != 0) {
		n = m;
		m = r;
		r = n % m;
	}
	return x / m;

}
vector<int> osatu(int n, int y) {//n万円がy枚で作れるか
	vector<int> ans(3,-1);
	
	int flag = 0;
	if (n/10000 > y) {
		
	}
	else if (n < 1000*y) {
		
	}
	else{
		for (auto i = 0; i <= y; i++)
		{
			for (auto j = 0; j <= y-i; j++)
			{
				auto temp = i * 10000 + j * 5000 + (y - i - j) * 1000;
				if (n == i*10000+j*5000 + (y-i-j)*1000) {
					ans[0] = i;
					ans[1] = j;
					ans[2] = y - i - j;
					flag = 1;
					break;
				}
			}
			if (flag == 1)break;
		}
	}
	

	return ans;
}


int main() {

	int N, Y;
	vector<int> ans(3);
	cin >> N >> Y;

	ans = osatu(Y, N);




	cout << ans[0] << " " << ans[1] << " " << ans[2] << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {

	int i;
	long long a;
	long long n;
	long long min = 1000000;
	long long max = -1000000;
	long long sum =0;

	scanf("%d",&n);
	for(i =0;i < n;i++){
		scanf("%ld",&a);
		sum += a;
		if(min > a){
			min = a;
		}
		if(max < a){
			max = a;
		}
	}
	printf("%ld %ld %ld\n",min,max,sum);
	
	return 0;
}



Measured memory_bytes: 2104
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while( x->left != NIL ) x = x->left;
  return x;
}
Node treeMaximum(Node x){
  while(x->right != NIL ) x = x->right;
  return x;
}

Node treeSearch(Node x, int k){
  while(x!=NIL&&k!=x->key){
    if ( k < x->key ){
      x = x->left;
    }
    else{
      x = x->right;
    }
  }
  return x;
}

Node treeSuccessor(Node x){
  Node y;
  if ( x->right!= NIL ) return treeMinimum(x->right);
  y = x->parent;
  while( y != NIL && x == y->right ){
    x = y;
    y = y->parent;
  }
  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

  if (z->left==NIL||z->right==NIL){
    y = z;
  }
  else {
    y = treeSuccessor(z);
  }
  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);
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct 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 inorder(Node u){
  if ( u == NIL ) return;
  inorder(u->left);
  printf(" %d", u->key);
  inorder(u->right);
}
void preorder(Node u){
  if ( u == NIL ) return;
  printf(" %d", u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  Node t,max,min;
  int n, i, x;
  char com[20];
  scanf("%d", &n);
  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( strcmp(com, "find") == 0 ){
      scanf("%d", &x);
      t = treeSearch(root, x);
      if ( strcmp(com, "findMin") == 0 ){
	min = treeMinimum(t);
	printf("%d\n", min->key);
      } else if ( strcmp(com, "findMax") == 0 ){
        max = treeMaximum(t);
	printf("%d\n", max->key);
      } else {
	if ( t != NIL ) printf("yes\n");
	else printf("no\n");
      }
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( strcmp(com, "print") == 0 ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( strcmp(com, "delete") == 0 ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}




Measured memory_bytes: 20484
/*
我的心脏怦怦跳，监管者就在附近
name:
Algorithm:
writer:Lxs(cdx)
place:
nothing is impossible
*/
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
#include<string>
#include<iostream>
#include<cmath>
#include<set>
#include<stack>
#include<queue>
#include<unistd.h>
#include<stdio.h>
#include<cstring>
#define random(a,b) (rand()%(b-a+1)+a)
using namespace std;
bool prime(int x){
	 int i;
	 if(x<2) return 0;
	 for(i=2;i*i<=x;i++){
		if(x%i==0){return 0;}
	 }
	 return 1;
}
bool flag[19999990];
int _prime[19999990];
void get_prime(int maxn)
{
    int i,j;
    for(i=2;i<=maxn;i++)
        if(!flag[i])
        {
            _prime[++_prime[0]]=i;
            for(j=i*i;j<=maxn;j+=i)
                flag[j]=true;
        }
}
int main()
{
	string st;
	int n;
	cin>>n;
	int i=0;
	for(i=0;i<n;i++){
		cout<<"ACL";
	} 
	return 0;
}


Measured memory_bytes: 3596
#include<iostream>
using namespace std;
int main()
{
	int n,k; cin>>n>>k;
	int lef=k-n+1;
	int rig=k+n-1;
	for(int i=lef;i<=k;i++)
	{
		cout<<i<<" ";
	}
	for(int i=k+1;i<=rig;i++)
	{
		cout<<i<<" ";
	}
}
			
	

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

int main() {
  int A, B, C, X, Y, Z;
  int ans =0;
  cin >> A >> B >> C;
  while(A%2==0 && B%2==0 && C%2 == 0){
    if(A==B && A==C){
      ans = -1;
      break;
    }
    X=A; Y=B; Z=C;
    A=(Y+Z)/2;
    B=(X+Z)/2;
    C=(Y+X)/2;
    ans++;
  }
  
  cout << ans << endl;
}


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

using namespace std;

int main(){
    int A, B, C; cin >> A >> B >> C;

    if(A == B){
        cout << C << endl;
    }else if(B == C){
        cout << A << endl;
    }else{
        cout << B << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

		long A = sc.nextLong();
		long B = sc.nextLong();
		long C = sc.nextLong();
		long K = sc.nextLong();
		long count = 0;
		if(K <= A){
			count = K;
		}else{
			count = A;
			long num = K-A-B;
			if(num > 0){
				while(num > 0){
					count--;
					num--;
				}
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 35756
#include <iostream>
using namespace std;
int main(){
  char a,b;cin>>a>>b;
  auto num = [](char x){
    if(x=='A') return 10;
    else if(x=='B') return 11;
    else if(x=='C') return 12;
    else if(x=='D') return 13;
    else if(x=='E') return 14;
    else if(x=='F') return 15;
    else return (x-'0');
  };
  if(num(a) == num(b)) cout << '='<<endl;
  else if(num(a) > num(b)) cout << '>'<<endl;
  else cout << '<'<<endl;

  return 0;
}


Measured memory_bytes: 256
/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public final class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		String str = s.next();
      	if(str.length() <= n){
      		System.out.println(str);
      	}
      	else{
      		System.out.println(str.substring(0,n)+"...");
      	}
	}
}

Measured memory_bytes: 38360
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = a; i < (b); ++i)
#define rrep(i,a,b) for(int i = b; i --> (a);)
#define all(v) v.begin(),v.end()
#define trav(x,v) for(auto &x : v)
#define sz(v) (int)(v).size()
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int n;
	cin >> n;

	vi a(n);
	trav(x, a) cin >> x;

	int ans = 0;
	rep(i,1,n){
		if(a[i] == a[i-1]){
			++ans;
			a[i] = 0;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <map>
#include <numeric>
using namespace std;

#define FOR(i,a,b) for(long long int i=(a);i<(b);i++)
#define REP(i,n) for(long long int i=0;i<(n);i++)
#define ALL(s) (s).begin(),(s).end()

#define PI 3.14159265358479

typedef long long ll;
typedef vector<long long int> vi;
typedef vector<long long int>::iterator vit;

int main(){
	double l, a, b, x = 0, y = 0, c = 0;
	while (scanf("%lf,%lf", &l, &a)){
		if (l == 0 && a == 0)break;
		if (c == 0){
			y += l;
		}
		else{
			x += l*sin(b / 180.0*PI);
			y += l*cos(b / 180.0*PI);
		}
		b += a;
		c++;
	}
	cout << (int)x << "\n" << (int)y << "\n";
}

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

int main()
{
    int n, x;
    cin >> n >> x;
    int l[n+1]={0};
    for( int i=1; i < n+1; i++) cin >> l[i];

    int tmp = 0;
    int ans = 1;
    for( int i=2; i < n+2; i++){
        tmp += l[i-1];
        if( tmp <= x ) ans ++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx,avx,tune=native")
//include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<queue>
#include<set>


using namespace std;

using ll = long long;

int main(){
    double st = clock();
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int N;cin >> N;
    vector<queue<int>> vec;
    vector<pair<int, int>> uku;
    vector<bool> usi(N*N, false);
    for(int i = 0;i < N;i++){
        queue<int> v;
        for(int j = 0;j < N-1;j++){
            int b;cin >> b;v.push(b-1);
        }
        usi.at(v.front() * N + i) = true;
        uku.push_back({v.front(), i});
        v.pop();
        vec.push_back(v);
    }
    int ans = 0;
    while(!uku.empty()){
        if(double(clock() - st) / CLOCKS_PER_SEC >= 1.8){
            cout<<499500<<endl;
            return 0;
        }
       // cout<<ans<<endl;
        ans++;
        bool f = true;
        vector<pair<int,int>> w;
        for(pair<int,int> e : uku){
            if(!usi.at(e.second * N + e.first)){
                //cout<<e.first<<" "<<e.second<<endl;

               // uku.push_back(e);
                w.push_back(e);
            }else{
            //    cout<<e.first<<" "<<e.second<<endl;
                if(!vec.at(e.second).empty()){
                    int q = vec.at(e.second).front();
                    vec.at(e.second).pop();
                   // usi.at(q * N + e.second) = true;
                    w.push_back({q, e.second});
                    usi.at(e.second * N + e.first) = false;
                }
                f = false;
            }
        }
        for(auto e : w)usi.at(e.first * N + e.second) = true;;
        //cout<<endl;
        if(f){
            cout<<-1<<endl;
            return 0;
        }
        uku = w;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 4480
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	int n;cin>>n;
	vector<ll> a(n);
	for(int i = 0; i < n; i++) {
		cin>>a[i];
	}
	ll ans = 1;
	for(int i = 1; i + 1 < n; i++) {
		if (a[i - 1] <= a[i] && a[i] <= a[i + 1]){
			i++;
			while(i + 1 < n){
				if ((a[i - 1] <= a[i] && a[i] <= a[i + 1])){
					i++;
				}
				else{
					ans++;
					break;
				}
			}
		}
		else if (a[i - 1] >= a[i] && a[i] >= a[i + 1]){
			i++;
			while(i + 1 < n){
				if(a[i - 1] >= a[i] && a[i] >= a[i + 1]){
					i++;
				}
				else{
					ans++;
					break;
				}
			}
		}
		else{
			ans++;
		}
		i++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
# N = 8
# S = "WRWWRWRR"
#
# N = 2
# S = "RR"
#
# N = 3
# S = "WWW"

N = int(input())
S = input()

def calculate(n, s):
    arr = list(s)

    wNum = arr.count("W")
    RNum = arr.count("R")

    if wNum == 0 or RNum == 0:
        print(0)
        return

    leftW = 0
    rightR = RNum



    result = []
    for i in range(n):
        if arr[i] == "R":
            rightR -= 1
        if arr[i] == "W":
            leftW += 1

        result.append(max(leftW, rightR))

    print(min(result))


calculate(N, S)


Measured memory_bytes: 18984
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
vector<int> v;
for(int i=0;i<2*n;i++)
{
int x;
cin>>x;
v.push_back(x);
}
sort(v.begin(),v.end());
int ans=0;
for(int i=0;i<n;i++)
ans+=v[2*i];
cout<<ans;
}

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

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define inf (1<<29)

using namespace std;

struct P
{
  int weight,index;
  P(int weight=inf,int index=inf):weight(weight),index(index){}
  bool operator < (const P& a)const
  {
    return weight < a.weight;
  }
};

int n,m,W;

int main()
{
  int k;
  scanf("%d %d %d",&n,&m,&W);
  
  int idx = 0;
  vector<vector<P> > vec;
  vector<int> FLOOR;

  rep(i,n)
    {
      scanf("%d",&k);
      if(k == 0)
	{
	  if(i == 0)
	    {
	      FLOOR.push_back(i);
	      vec.push_back(vector<P>());
	    }
	  continue;
	}
      int cur = vec.size();
      vec.push_back(vector<P>(k));
      FLOOR.push_back(i);
      rep(j,k)
	{
	  scanf("%d",&vec[cur][j].weight);
	}
    }

  if(FLOOR[FLOOR.size()-1] == 0)
    {
      puts("0");
      return 0;
    }

  int ans = FLOOR[FLOOR.size()-1]+1-m;
  for(int i=FLOOR.size()-1;i>=1;i--)
    {
      //cout << "cost = " << FLOOR[i] << " - " << FLOOR[i-1] << endl;
      int cost = FLOOR[i] - FLOOR[i-1];
      assert(cost >= 0);
      int SIZE = vec[i].size();
      //cout << "SIZE = " << SIZE << endl;
      int dp[(1<<SIZE)];
      rep(j,(1<<SIZE))dp[j] = inf;
      dp[0] = 0;
      rep(state,(1<<SIZE))//今のフロアの状況 0 -> まだ移動してない, 1 -> 移動したたそ〜
	{
	  if(dp[state] == inf)continue;
	  vector<P> tmp;//まだこのフロアにあるものたそ〜
	  rep(j,SIZE)
	    {
	      if((state>>j) & 1)continue;
	      tmp.push_back(P(vec[i][j].weight,j));
	    }

	  //sort(tmp.begin(),tmp.end());
	  int limit = tmp.size();
	  rep(j,(1<<limit))//次に移動するもの
	    {
	      int sum = 0;
	      int tstate = 0;
	      rep(k,limit)
		{
		  if((j>>k) & 1)
		    {
		      tstate |= (1<<tmp[k].index);
		      sum += tmp[k].weight;
		    }
		}
	      assert(sum >= 0);
	      if(sum > W)continue;
	      assert((state ^ tstate) == (state | tstate));
	      int nstate = state | tstate;
	      dp[nstate] = min(dp[nstate],
			       dp[state]+2);
	    }
	}
      rep(j,vec[i].size())vec[i-1].push_back(vec[i][j]);
      assert((dp[(1<<SIZE)-1]-1)*cost >= 0);
      ans += (dp[(1<<SIZE)-1]-1)*cost;//新たな値を得るたそ〜
      assert(ans >= 0);
      //cout << "ans = " << ans << " dp = " << dp[(1<<SIZE)-1] << endl;
    }

  printf("%d\n",ans);//えるたそ〜

  return 0;
}

Measured memory_bytes: 1336
#include <bits/stdc++.h>
#define ll long long
int main()
{
    ll n;
    std::vector<ll> A;
    ll count = 0;
    ll money = 1000;
    std::cin >> n;
    for (ll i = 0; i < n; ++i) {
        ll temp = 0;
        std::cin >> temp;
        A.push_back(temp);
    }
    if (A[0] < A[1]) {
        count += money / A[0];
        money -= A[0] * count;
    }
    for (ll today = 1; today < n - 1; ++today) {
        ll temp_count = 0;
        if (A[today] <= A[today - 1] && A[today] < A[today + 1]) {
            temp_count = money / A[today];
            count += temp_count;
            money -= A[today] * temp_count;
        }
        if (A[today] >= A[today - 1] && A[today] > A[today + 1]) {
            temp_count = count;
            count -= temp_count;
            money += temp_count * A[today];
        }
    }
    if (A[n - 2] <= A[n - 1]) {
        ll temp_count = count;
        count -= temp_count;
        money += temp_count * A[n - 1];
    }
    std::cout << money << std::endl;
}

Measured memory_bytes: 3572
//自称高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define MODA 1000000007 

int main() {
    int ans = 0;
	string s;
  	 cin >> s;
	REP(i, 3)
	if(s[i]==s[i+1]){
		cout << "Bad" << endl;
		return 0;
	}
	cout << "Good" << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int ar[100001];
int main() {
	int n;
	cin>>n;
	
	ar[0] = 1;
	for(int i=100;i<=100000;i++)
	{
		if(ar[i - 100]) ar[i] = 1;
		if(i >= 101 && ar[i-101]) ar[i] = 1;
		if(i >= 102 && ar[i-102]) ar[i] = 1;
		if(i >= 103 && ar[i-103]) ar[i] = 1;
		if(i >= 104 && ar[i-104]) ar[i] = 1;
		if(i >= 105 && ar[i-105]) ar[i] = 1;
	}
	
	cout<<ar[n];
}

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

int main() {
    double n;
    cin >> n;
    vector<double>data_x(n);
    vector<double>data_y(n);
    for(int i=0;i<n;i++){
        cin >> data_x.at(i);
    }
    for(int i=0;i<n;i++){
        cin >> data_y.at(i);
    }
    double d_1=0,sum_2=0,sum_3=0,d_inf=0;
    for(int i=0;i<n;i++){
        d_1+=fabs(data_x.at(i)-data_y.at(i));
        sum_2+=pow(data_x.at(i)-data_y.at(i),2.0);
        sum_3+=pow(fabs(data_x.at(i)-data_y.at(i)),3.0);
        d_inf=max(d_inf,fabs(data_x.at(i)-data_y.at(i)));
    }
    double d_2,d_3;
    d_2=sqrt(sum_2);
    d_3=pow(sum_3,1.0/3.0);
    cout << fixed << setprecision(10);
    cout << d_1 << endl << d_2 << endl << d_3 << endl << d_inf << endl;
}


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

const int N = 1e5 + 9;

long long a[N], dp[N], sum[N], nxt[N];
char s[N];
int32_t main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n >> a[1];
	sum[1] = a[1];
	for (int i = 2; i <= n; i++) {
		cin >> s[i] >> a[i];
		sum[i] = sum[i - 1] + a[i];
	}
	nxt[n + 1] = n + 1;
	for (int i = n; i >= 2; i--) {
		if (s[i] == '+') {
			dp[i] = dp[i + 1] + a[i];
			nxt[i] = nxt[i + 1];
		}
		else {
			dp[i] = dp[i + 1] - a[i];
			int k = nxt[i + 1];
			dp[i] = max(dp[i], sum[n] - sum[k - 1] - (sum[k - 1] - sum[i]) - a[i]);
			nxt[i] = i;
		}
	}
	cout << dp[2] + a[1] << '\n';
    return 0;
}

Measured memory_bytes: 6820
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
typedef long long LL;
LL n;
vector<int> v;
int main() {
    cin >> n;
    int sum = 0, ans = 0;
    int cnt = 0;
    LL t = n;
    while (t) {
        cnt ++;
        v.push_back(t%10); ans += t%10;
        t /= 10;
    }
    for (int i = v.size()-1; i >= 0; i --) {
        sum += v[i];
        if (v[i] > 0) {
            ans = max(ans, sum-1 + (cnt-1) * 9);
        }
        n /= 10; cnt --;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
v = list(map(int, input().split()))  # -> li = [1,2,3,...n]
c = list(map(int, input().split()))  # -> li = [1,2,3,...n]
ans = 0
for i in range(n):
    if v[i] - c[i] > 0:
        ans += v[i] - c[i]

print(ans)

Measured memory_bytes: 3060
INF = 10**20
N = int(input())
height = list(map(int, input().split()))
cost = [INF]*N
cost[0] = 0
cost[1] = min(cost[1], cost[0]+abs(height[1]-height[0]))
for i in range(2, N):
  cost[i] = min(cost[i], cost[i-1]+abs(height[i]-height[i-1]), cost[i-2]+abs(height[i]-height[i-2]))
print(cost[N-1])

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

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

void solve(const vi& a,const vi& b,int p,int sum,vi& c)
{
	if(p==a.size())
		c[sum]++;
	else
		rep(i,b[p]+1)
			solve(a,b,p+1,sum+a[p]*i,c);
}

int main()
{
	for(int m;cin>>m,m;){
		vi a(m),b(m);
		rep(i,m)
			cin>>a[i]>>b[i];

		vi c(7001);
		solve(a,b,0,0,c);
		int g; cin>>g;
		rep(i,g){
			int n; cin>>n;
			cout<<c[n]<<endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 928
typedef long long ll;
typedef long double ld;
#include <bits/stdc++.h>
using namespace std;
const int MAX = 510000;
 const int MOD = 1000000007;
 
 long long fac[MAX], finv[MAX], inv[MAX];
 
 // テーブルを作る前処理
 void COMinit() {
     fac[0] = fac[1] = 1;
     finv[0] = finv[1] = 1;
     inv[1] = 1;
     for (int i = 2; i < MAX; i++){
         fac[i] = fac[i - 1] * i % MOD;
         inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
         finv[i] = finv[i - 1] * inv[i] % MOD;
     }
 }
 
 // 二項係数計算
 long long COM(int n, int k){
     if (n < k) return 0;
     if (n < 0 || k < 0) return 0;
     return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
 }
 long long modpow(long long a, long long n) {
      long long res = 1;
      while (n > 0) {
          if (n & 1) res = res * a % MOD;
          a = a * a % MOD;
          n >>= 1;
      }
      return res;
  }
int main() {
    ll n;
    std::cin >> n;
    
    std::cout << (modpow(10,n)-(modpow(9,n)*2%MOD-modpow(8,n)+MOD)%MOD+MOD)%MOD << std::endl;
}


Measured memory_bytes: 3636
#!/usr/bin/env python3

import sys


def LI():
    return list(map(int, sys.stdin.buffer.readline().split()))


def I():
    return int(sys.stdin.buffer.readline())


def LS():
    return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()


def S():
    return sys.stdin.buffer.readline().rstrip().decode('utf-8')


def IR(n):
    return [I() for i in range(n)]


def LIR(n):
    return [LI() for i in range(n)]


def SR(n):
    return [S() for i in range(n)]


def LSR(n):
    return [LS() for i in range(n)]


def SRL(n):
    return [list(S()) for i in range(n)]


def MSRL(n):
    return [[int(j) for j in list(S())] for i in range(n)]

# ----------------------------------------------------------------


def main():
    k = I()
    numlist = [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]
    print(numlist[k - 1])


main()


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

int main() {

  string S;
  cin >> S;

  bool easy = 1;
  for(int i=1; i <= S.size(); i++){
    if(i % 2 != 0 && S.at(i-1) == 'L'){
      easy = 0;
      break;
    }else if(i % 2 == 0 && S.at(i-1) == 'R'){
      easy = 0;
      break;
    }
    //cout << i << ":" << easy << endl;
  }
  
  if(easy){
    cout << "Yes" << endl;
  }else if(!easy){
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = INT_MAX;
const int MOD = 1e9 + 7;

//http://tsutaj.hatenablog.com/entry/2017/03/29/204841
struct SegmentTree{//SegmentTree seg(vec) のように宣言する
    int n;
    vector<int> dat;
    
    //元配列vをセグメント木で表現する
    SegmentTree(vector<int> vec){
        int siz = vec.size();
        n = 1;
        while(n < siz) n *= 2;
        dat.resize(2 * n - 1, INF);
        for(int i = 0; i < siz; i++) dat[i + n - 1] = vec[i];//最下段に値をいれる
        for(int i = n - 2; i >= 0; i--) dat[i] = min(dat[2 * i + 1], dat[2 * i + 2]);//下の段から順番に値をいれる
    }

    void update(int k, int val){
        //最下段のノードにアクセスする
        k += (n - 1);
        //最下段のノードを更新したら、下の段から順番に値をいれる
        dat[k] = val;
        while(k > 0){
            k = (k - 1) / 2;
            dat[k] = min(dat[2 * k + 1], dat[2 * k + 2]);
        }
    }

    int query(int a, int b, int k = 0, int l = 0, int r = -1){
        //最初に呼び出されたときの対象区間は[0, n)
        if(r < 0) r = n;
        //要求区間と対象区間が交わらなければ、INF
        if(r <= a || b <= l) return INF;
        //要求区間が対象区間を完全に含んでいれば、対象区間を答えの計算に使う
        if(a <= l && r <= b) return dat[k];
        //要求区間が対象区間の一部を含んでいれば、
        int vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
        int vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
        return min(vl, vr);
    }
};

signed main(){
    int n,q;
    cin >> n >> q;
    SegmentTree seg(vector<int> (n, INF));
    int c[q],x[q],y[q];
    REP(i,q){
        cin >> c[i] >> x[i] >> y[i];
    }
    REP(i,q){
        if(c[i] == 0){
            seg.update(x[i], y[i]);
        }else{
            cout << seg.query(x[i], y[i] + 1) << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 5044
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
 string s;
 cin >>s;
 string t,l;
 t+=s[5];
 t+=s[6];
 int k=stoi(t);
 l+=s[8];
 l+=s[9];
 int j=stoi(l);
 if(k<4){
   cout <<"Heisei"<<endl;
   return 0;
 }
 if(k==4){
   if(j<=30){
     cout <<"Heisei"<<endl;
     return 0;
   }
   else{
    cout <<"TBD"<<endl;
    return 0;
  }
 }
 else{
   cout <<"TBD"<<endl;
   return 0;
 }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()

int main(){
    map<string,int>red;
    map<string,int>blue;
    queue<string>str;
    int max=0;
    int n,m;
    cin>>n;
    rep(i,n){
        string s;
        cin>>s;
        str.push(s);
        if(blue.count(s)){
            blue[s]++;
        }else{
            blue[s]=1;
        }
    }
    cin>>m;
    rep(i,m){
        string s;
        cin>>s;
        str.push(s);
        if(red.count(s)){
            red[s]++;
        }else{
            red[s]=1;
        }
    }
    int l;
    int d=str.size();
    rep(i,d){
        string s=str.front();
        if(!blue.count(s))continue;
        if(!red.count(s)){
            l=blue[s];
        }else{
            l=blue[s]-red[s];
        }
        if(l>max){
            max=l;
        }
        str.pop();
    }
    cout<<max<<endl;
}


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

int n;
int x[24],y[24],r[24],c[24];
bool memo[1<<24];

bool ok(int a,int bit){
    for(int i=0;i<a;i++){
        if(((bit>>i)&1)==0)continue;
        int dist=(x[i]-x[a])*(x[i]-x[a])+(y[i]-y[a])*(y[i]-y[a]);
        int sum=(r[i]+r[a])*(r[i]+r[a]);
        if(dist<sum)return false;
    }
    return true;
}

int dfs(int bit){
    memo[bit]=true;

    int ret=n;
    for(int i=0;i<n;i++)if((bit>>i)&1)ret--;

    for(int i=0;i<n;i++){
        if(((bit>>i)&1)==0||ok(i,bit)==false)continue;
        for(int j=i+1;j<n;j++){
            if(((bit>>j)&1)==0||c[i]!=c[j])continue;
            int to_bit=(bit^(1<<i))^(1<<j);
            if(ok(j,bit)&&!memo[to_bit]){
                ret=max(ret,dfs(to_bit));
            }
        }
    }


    return ret;
}

void solve(){
    fill_n(memo,1<<n,false);

    cout<<dfs((1<<n)-1)<<endl;
}

bool input(){
    cin>>n;
    if(!n)return false;
    for(int i=0;i<n;i++)cin>>x[i]>>y[i]>>r[i]>>c[i];
    return true;
}



int main(){
    while(input())solve();
    return 0;
}

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


int main() {
    int a,b,c;
    cin >> a >> b >> c;
    if(a == b && a != c){
        cout << "Yes" << endl;
    }else if(a != b && b == c){
        cout << "Yes" << endl;
    }else if(a == c && a != b){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
 
using namespace std;
 
int main() {
        unsigned long long a, b, x;
	cin >> a >> b >> x;
	if (a %x != 0)
		cout << b / x - a / x << endl;
	else
		cout << b / x - a / x + 1 << endl;
}

Measured memory_bytes: 256
// AOJ
#include<stdio.h>

int main(){
	int n, x = 100000;
	scanf("%d", &n);
	for(; n > 0; n--){
		x += x/20;
		if(x%1000 != 0){
			x = (x/1000+1)*1000;
		}
	}
	printf("%d\n", x);

	return 0;
}

Measured memory_bytes: 588
#include<stdio.h>

int main(void){
  int X;
  int m,n,u;
  
  scanf("%d",&X);
  
  m = X/500;
  X = X - m*500;
  
  n = X/5;
  
  u = m * 1000 + n * 5;
  
  printf("%d",u);
  return 0;
}

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

#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y
//#define CPP_STR(x) CPP_STR_I(x)
//#define CPP_STR_I(args...) #args
//#define ASSERT(expr...) assert((expr))

using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
//using f80 = __float80;

constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
constexpr char EL[] = "\n";

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(),(x).end()
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
#define UNIQUE(x) (x).erase(unique(all(x)), (x).end());
#define REPIT(x) for(auto it=(x).begin(), end=(x).end(); it!=end; ++it)
#define perm(c) sort(all(c)); for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

template<typename T = i64>
T IN() { T x; cin >> x; return (x); }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T(&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp = less<>>
bool chmax(T& xmax, const U& x, Comp comp = {}) {
	if (comp(xmax, x)) {
		xmax = x;
		return true;
	}
	return false;
}
template<typename T, typename U, typename Comp = less<>>
bool chmin(T& xmin, const U& x, Comp comp = {}) {
	if (comp(x, xmin)) {
		xmin = x;
		return true;
	}
	return false;
}

void print() {
  cout << EL;
}
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(tail) != 0) cout << " ";
  print(forward<Tail>(tail)...);
}
template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
	cout << a;
	if (&a != &vec.back()) cout << " ";
  }
  cout << EL;
}
template <class T>
void print(vector<vector<T>> &df) {
  for (auto& vec : df) {
	print(vec);
  }
}

struct ProconInit {
	static constexpr int IOS_PREC = 15;
	static constexpr bool AUTOFLUSH = false;

	ProconInit() {
		cin.tie(nullptr);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(IOS_PREC);
		if (AUTOFLUSH)
			cout << unitbuf;
	}
} PROCON_INIT;
#pragma endregion

signed solve()
{
	string s1, s2, s3;
	cin >> s1 >> s2 >> s3;
	print(s1.substr(0,1) + s2.substr(0, 1) + s3.substr(0, 1));
	return 0;
}

#ifndef LOCALCODE
signed main()
{
	return solve();
}
#endif


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define sf(n) scanf("%d", &n)
#define pd(n) printf("%.10lf", n)
#define pf(n) printf("%d", n)
#define p() printf("\n")
#define ps() printf(" ")
#define ll long long
#define ull unsigned long long
#define MAX 1e9
const int mod = 1000 * 1000 * 1000 + 7;
#define ex 1e18
#define dbl 2e09
#define qu(q) queue<int> q
#define pqu(q) priority_queue<int> q
#define len(s) s.length()
#define sz(x) int(x.size())
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define F first
#define S second
#define clr(x) x.clear()
#define LOG(x) std::cout << x << std::endl;
 
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double PI = 3.14159265359;
 
int dx[6] = {-1,-1,0,0,1,1};
int dy[6] = {-1,0,-1,1,0,1};

const int N=2e5+5;
int a[N];
map<int,int>mp;

int main(){
    int n;
    cin>>n;
    int sum=0;
    for(int i=0;i<n;++i){
        cin>>a[i];
        sum^=a[i];
    }
    for(int i=0;i<n;++i){
        cout<<(int)(sum^a[i])<<" ";
    }
    cout<<endl;
    return 0;
}







Measured memory_bytes: 4384
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[6] = {1, 0, -1, 0,1,1};
const int dy[6] = {0, 1, 0, -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; }
// ---------------------------------------------------------------------------


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll x;
    cin >> x;
    for(ll i=-1000; i<=1000; i++){
        for(ll j=-1000; j<i; j++){
            if(i*i*i*i*i - j*j*j*j*j == x){
                cout << i << " " << j << enld;
                return 0;
            }
        }
    }
    return 0;
}


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

int main() {
  int s;
  cin>>s;
  vector<int> a(1000000);
  a[0]=s;
  for(int j=0;j<1000000;j++){
    if(a[j]%2==0){
      a[j+1] = a[j]/2;
    }
    else{
      a[j+1] = 3*a[j]+1;
    }
  }
  for(int i=0;i<1000000;i++){
    int tmp =a[i];
    for(int j=i+1;j<1000000;j++){
      if(tmp == a[j]){
        cout << j+1<<endl;
        return 0;
        }
    }
  }

}


Measured memory_bytes: 4096
use std::io;

fn main() {
	let mut v:Vec<char> = Vec::new();
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let s:Vec<char> = buf.trim().chars().collect();
	v.push(s[0]);
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let s:Vec<char> = buf.trim().chars().collect();
	v.push(s[1]);
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let s:Vec<char> = buf.trim().chars().collect();
	v.push(s[2]);
	for i in v{
		print!("{}", i);
	}
	println!("");
}

Measured memory_bytes: 4352
#include <stdio.h>
int main(){
  int a,b,n,gcd=1;
  
  scanf("%d%d",&a,&b);
  while(a%b!=0){
    n=a%b;
    a=b;
    b=n;
    
  }
  gcd=b; 
  printf("%d\n",gcd);		    
  return 0;
}



Measured memory_bytes: 2124
#include <iostream>

using namespace std;

constexpr int kMaxN = 100000;

class UnionFind {
 private:
  int head_[kMaxN];
  int rank_[kMaxN];

  void Link(int x, int y) {
    if (x == y)
      return;

    if (rank_[x] < rank_[y]) {
      head_[x] = y;
    } else {
      head_[y] = x;
      if (rank_[x] == rank_[y])
        ++rank_[x];
    }
  }

 public:
  UnionFind(int n) {
    for (int i = 0; i < n; ++i) {
      head_[i] = i;
      rank_[i] = 0;
    }
  }

  int Find(int x) {
    if (head_[x] == x)
      return x;
    return head_[x] = Find(head_[x]);
  }

  bool Same(int x, int y) {
    return Find(x) == Find(y);
  }

  void Unite(int x, int y) {
    Link(Find(x), Find(y));
  }
};

int p[kMaxN];

int main() {
  int N, M;

  cin >> N >> M;
  UnionFind uf(N);
  for (int i = 0; i < N; ++i) {
    cin >> p[i];
    p[i]--; // we use 0-based index
  }

  int x, y;
  for (int i = 0; i < M; ++i) {
    cin >> x >> y;
    // 0-based indices
    uf.Unite(x - 1, y - 1);
  }
  int ans = 0;
  for (int i = 0; i < N; ++i) {
    if (uf.Same(i, p[i])) ++ans;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define int long long
vector<int> v,dp;


signed main()
{
    int n,i;
    cin >> n;
    v.resize(n);
    dp.resize(n);

    for(i =0;i < n;i++){
        cin >> v[i];
    }
    dp[0] = 0;
    dp[1] = abs(v[1]-v[0]);
    for(i = 2;i < n;i++){
        dp[i] = min(dp[i-1]+abs(v[i]-v[i-1]),
                    dp[i-2]+abs(v[i]-v[i-2]));
    }
    cout << dp[n-1];
    return 0;
}


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

using namespace std;

#define int long long

const int MOD = 1000000007;

struct node {
    int type;
    bool option;
    vector<int> child;
    node(int type, bool option) : type(type), option(option) {};
};

int pattern(node&);
int material_node(node&);
int alt_node(node&);
int or_node(node&);

int n;
vector<node> tree;

int pattern(node &now) {

    int ret = 0;

    switch(now.type) {
        case 0:
            ret = material_node(now);
            break;
        case 1:
            ret = alt_node(now);
            break;
        case 2:
            ret = or_node(now);
            break;
    }

    return ret % MOD;
}

int material_node(node &now) {

    int ret = 1;

    for(int i = 0; i < now.child.size(); ++i) {
        ret = ret * pattern(tree[now.child[i]]) % MOD;
    }

    ret += now.option;

    return ret % MOD;

}

int alt_node(node &now) {

    int ret = 0;

    for(int i = 0; i < now.child.size(); ++i) {
        ret = (ret + pattern(tree[now.child[i]])) % MOD;
    }

    ret += now.option;

    return ret % MOD;

}

int or_node(node &now) {

    int ret = 0;

    for(int i = 1; i < (1 << now.child.size()); ++i) {
        int seki = 1;
        for(int j = 0; j < now.child.size(); ++j) {
            if((i >> j) & 1) {
                seki = seki * pattern(tree[now.child[j]]) % MOD;
            }
        }
        ret = (ret + seki) % MOD;
    }

    ret += now.option;

    return ret % MOD;
}

main() {

    cin >> n;

    for(int i = 0; i < n; ++i) {
        int t;
        bool o;
        string s;

        cin >> s;

        if(s[0] == 'E') {
            t = 0;
        } else if(s[0] == 'A') {
            t = 1;
        } else if(s[0] == 'R') {
            t = 2;
        }

        o = s.size() - 1;

        tree.push_back(node(t, o));
    }

    for(int i = 0; i < n - 1; ++i) {
        int s, t;
        cin >> s >> t;
        --s;
        --t;
        tree[s].child.push_back(t);
    }

    cout << pattern(tree[0]) << endl;

}

Measured memory_bytes: 3264
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)


def solve(N: int, M: int, a: "List[int]", b: "List[int]"):
    conn = [[] * N for _ in range(N)]
    for i in range(M):
        conn[a[i] - 1].append(b[i] - 1)
        conn[b[i] - 1].append(a[i] - 1)
    def dfs(idx, visited):
        last = True
        for v in visited:
            if not v:
                last = False
                break
        if last:
            return 1
        ret = 0
        for nex in conn[idx]:
            if not visited[nex]:
                visited[nex] = True
                ret += dfs(nex, visited)
                visited[nex] = False
        return ret
    visited = [False] * N
    visited[0] = True
    count = dfs(0, visited)
    print(count)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    a = [int()] * (M)  # type: "List[int]" 
    b = [int()] * (M)  # type: "List[int]" 
    for i in range(M):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
    solve(N, M, a, b)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
 
int main() {
int a,b,c;
cin>>a>>b>>c;
int k;
cin>>k;
if(a<b && b<c){
	cout<<"Yes"<<endl;
	return 0;
}
if(b<=a){
	while(b<=a){
		b=b*2;
		k--;
		if(k<0){
			cout<<"No"<<endl;
			return 0;
		}
	}
}
if(c<=b){
	while(c<=b){
		c=c*2;
		k--;
		if(k<0){
			cout<<"No"<<endl;
			return 0;
		}
	}
}
cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 3588
using System;

namespace ABC076C
{
    class Program
    {
        static void Main(string[] args)
        {
            string Sp = Console.ReadLine();
            string T = Console.ReadLine();
            string S = "UNRESTORABLE";

            for (int i = Sp.Length - T.Length; i >= 0; i--)
            {
                bool match = true;

                for (int j = 0; j < T.Length; j++)
                {
                    if (Sp[i + j] != '?' && Sp[i + j] != T[j])
                    {
                        match = false;
                        break;
                    }
                }

                if (match)
                {
                    S = string.Empty;
                    for (int j = 0; j < Sp.Length; j++)
                    {
                        char c = '?';
                        if (Sp[j] == '?')
                        {
                            int k = j - i;
                            if (0 <= k && k < T.Length)
                            {
                                c = T[k];
                            }
                            else
                            {
                                c = 'a';
                            }
                        }
                        else
                        {
                            c = Sp[j];
                        }
                        S += c;
                    }
                    break;
                }
            }

            Console.WriteLine(S);
        }
    }
}


Measured memory_bytes: 11092
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args)throws Exception{
		InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
        
        while (true)
        {
        	String input = br.readLine();
        	if (input.equals("0"))
        		break;
        	int sum = 0;
        	for (int i = 0; i < input.length(); i++)
        	{
        		String a = String.valueOf(input.charAt(i));
        		sum += Integer.parseInt(a);
        	}
        	System.out.println(sum);
        	
        }
    	
	}

}

Measured memory_bytes: 24784