akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 1000000000;
const int mod = 1e9+7;
const int maxn = 2e5+5;
int judge(string s){
	for(int i=0;i<s.length();i++){
		if(s[i]!=s[s.length()-1-i]){
			return 0;
		}
	}
	return 1;
}
int main() {
	string s;
	cin>>s;
	int f1=0,f2=0,f3=0;
	int n = s.length();
	string s1 = s.substr(0,(n-1)/2);
	string s2 = s.substr((n+3)/2-1,(n-(n+3)/2)+1);
	if(judge(s)&&judge(s1)&&judge(s2)){
		cout<<"Yes\n";
	}
	else {
		cout<<"No\n";
	}
    return 0;
}

Measured memory_bytes: 256
#pragma region template
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9 + 7, MAX = 1e18, larg = 1e5, INF = -1e9;
long long A, B, C, D, E, F, G, H, I, J, K, L, N, M, O, P, Q, R, S, T, U, V, W, x, y, z;
long long max_value = INF, max_index = -1;
long long min_value = MAX, min_index = -1;
typedef long long ll;
typedef pair<ll, ll> Pa;

int main() {
	cin >> N >> M;
	int num;
	int sum = 0;
	rep(i, M){
		cin >> num;
		sum += num;
	}
	cout << max(N - sum, -1ll);
}

Measured memory_bytes: 3596
#include <stdio.h>
#define rep(i,n) for(int i=0;i<n;i++);
typedef long long ll;

int main(){
    char s[4];
    scanf("%s",s);
    int a=0,c;
    for(int i=0;i<3;i++){
        for(int j=i+1;j<4;j++){
            if(s[i]==s[j]){
                a++;
            }
        }
    }

    if(a==2) printf("Yes");
    else printf("No");
    
}



Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int n,m;
  cin>>n>>m;
  vi a(n),b(n);
  vi c(m),d(m);
  rep(i,n)cin>>a[i]>>b[i];
  rep(i,m)cin>>c[i]>>d[i];

  rep(i,n){
    int x=a[i],y=b[i];
    int ans=INF;
    rep(j,m)
      ans=min(ans,abs(x-c[j])+abs(y-d[j]));
    rep(j,m)
      if(ans==abs(x-c[j])+abs(y-d[j])){
        cout<<j+1<<endl;
        break;
      }
  }
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(int argc, char **argv) {
    int a, b, k;
    int count = 0;

    cin >> a >> b >> k;

    for (int i = (a + b) / 2; i > 0; i--) {
        if (a % i == 0 && b % i == 0) {
            count++;
            if (count == k) {
                cout << i << endl;

                return 0;
            }
        }
    }

    return 0;
}

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

#define ld long double
#define ll long long int
#define ull unsigned long long int
#define vi vector<int>
#define vl vector<ll>
#define vvi vector< vector<int> >
#define vvl vector< vector<ll> >
#define repd(i, a, b) for (int i=(a);i<(b);i++)
#define rep(i, n) repd(i,0,n)
#define ALL(v) v.begin(), v.end()
#define INF 1e9

using namespace std;

/**
 * calculate GCD(greatest common divisor)
 * @param a
 * @param b
 * @return
 */
unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

/**
 * change minimum
 * @tparam T
 * @param a
 * @param b
 * @return bool
 */
template<class T> inline bool changeMinimum(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

/**
 * change maximum
 * @tparam T
 * @param a
 * @param b
 * @return bool
 */
template<class T> inline bool changeMaximum(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

/**
 * output answer
 * @tparam T
 * @param answer
 * @return
 */
template<typename T>
T output(T answer) {
    cout << answer << endl;
    return 0;
}

/** ----from here ---------------------------------------------------------- */

int main() {

    int N;cin>>N;

    long long  ans = 0;
    for (int i = 1; i <= N; ++i) {

        if(i %3 == 0 ||  i % 5 == 0){
            continue;

        }

        ans +=i;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3592
import sys
sys.setrecursionlimit(10**7)

n = int(input())
# 隣接リスト
link = [[] for i in range(n)]
for i in range(n-1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1
    link[u].append((v,w))
    link[v].append((u,w))

ans = [-1]*n

def dfs(v, now):
    ans[v] = now

    for next_v ,w in link[v]:
        if ans[next_v] != -1:
            continue
        if w % 2:
            dfs(next_v, 1-now)
        else:
            dfs(next_v, now)

dfs(0,0)
for i in ans:
    print(i)

Measured memory_bytes: 79408
use std::io::*;
use std::str::FromStr;

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

fn main() {
    let a: i32 = read();
    let b: i32 = read();
    if (a + b) % 2 == 1 {
        println!("{}", "IMPOSSIBLE");
        return;
    }
    let ans = if a < b {
        a + (b - a) / 2
    } else {
        b + (a - b) / 2
    };
    println!("{}", ans);
}


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

using ll = long long;

//constant
const double EPS = 1e-10;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, s, e) for (ll i = s; i < e; i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(), (x).rend()

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

// view vector
template<typename T> void view(T e) { std::cout << e << std::endl; }
template<typename T> void view(const std::vector<T>& v) { for (const auto& e : v) { std::cout << e << " "; } std::cout << std::endl; }
template<typename T> void view(const std::vector<std::vector<T> >& vv) { for (const auto& v : vv) { view(v); } }

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

// ***************************************

int N;

void rec(vector<int> vec, int keta, int mx) {
	FOR(i, 0, mx + 1) {
		vec[keta] = i;
		if (keta < N - 1) {
			rec(vec, keta + 1, max<int>(mx, i + 1));
		}
		else {
			REP(j, N) {
				printf("%c", vec[j] + 'a');
			}
			cout << endl;
		}
	}
}

int main(){
	cin >> N;

	vector<int> vec;
	vec.assign(N, 0);
		
	if (N == 1) {
		cout << 'a' << endl;
		return 0;
	}
	rec(vec, 1, 1);
	
	return 0;
}

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

int h, w;

void next_pos(pair<int, int> &pos) {
  int y = pos.first;
  if (y % 2 == 0) ++pos.second;
  else --pos.second;

  if (pos.second >= w) {
    pos.second = w - 1;
    ++pos.first;
  }

  if (pos.second < 0) {
    pos.second = 0;
    ++pos.first;
  }
}

int main() {

  cin >> h >> w;
  vector <vector< int> > map(h, vector<int>(w,0));
  
  int n;
  cin >> n;

  pair <int, int> pos = {0, 0};

  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    for (int j = 0; j < a; ++j) {
      map[pos.first][pos.second] = i + 1;
      next_pos(pos);
    }
  }


  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (j != 0) cout << ' ';
      cout << map[i][j];
    }
    cout << endl;
  }
  
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
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;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}


/*
int N;
Graph G;

int main() {
  cin >>N;
  rep(i, N-1){
    int a,b; cin >>a >>b; a--; b--;
    G[a].push_back(b); G[b].push_back(a);
  }
}
*/

int main() {
  string s; cin >>s;
  int n = s.size();
  if (n == 2) cout <<s <<endl;
  else{
    reverse(all(s)); cout <<s <<endl;
  }
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define SP << " " 
#define LLi long long int

using namespace std;

int imax=2147483647;
long long int llimax=9223372036854775807;

//int型vectorを出力
void PV(vector<int> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

//LLi型vectorを出力
void PVL(vector<LLi> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

int main(){

	int mi=imax, tmp;
	string s, t;
	cin>> s >> t;

	for(int i=0;i<=s.size()-t.size();i++){
		tmp=0;
		for(int j=0;j<t.size();j++){
			if(s[i+j]!=t[j]) tmp++;
		}
		mi=min(mi, tmp);
	}

	cout<< mi <<endl;
 
	return 0;
}

Measured memory_bytes: 3604
n = int(input())
dp = [int(i) for i in range(10 ** 5 + 1)]

for i in [6,9]:
    v = i
    while v < 10 ** 5:
        for j in range(len(dp)):
            if j+v <= 10 ** 5:
                dp[j+v] =min(dp[j]+1,dp[j+v])
        v *= i      
        
print(dp[n])

Measured memory_bytes: 7064
#include<iostream>
#include<string>

using namespace std;

int main()
{
	int n;
	cin>>n;
	
	string s;
	cin>>s;
	
	int ans = 1;
	
	for(int i=0;i<n-1;i++)
	{
		if(s[i]!=s[i+1]) ans++;
	}
	
	cout<<ans;
	
	return 0;
}

Measured memory_bytes: 512
function Main(input){
    const ST = input.split('\n');
    const S = ST[0];
    const T = ST[1];
    let count = 0;
    for(let i=0;i<S.length;i++){
        if(S[i] !== T[i]){
            count++;
        }
    }
    console.log(count);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 32824
#include <stdio.h>
int main() {
	int n,m;
	scanf("%d%d",&n,&m);
	if (n == 1) {
		printf("%d",m);
		return 0;
	}
	for (int i = m/2; i; i--) {
		if (!(m%i) && m/i >= n) {
			printf("%d",i);
			return 0;
		}
	}
    return 0;
}


Measured memory_bytes: 128
import java.util.Arrays;
import java.util.Scanner;
public class Main
{
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		for(;;)
		{
			int n=in.nextInt();
			if(n==0)
				return;
			int a[]=new int[n];
			int fake[]=new int[n];
			for(int i=0;i<n;i++)
				a[i]=in.nextInt();
			boolean b[]=new boolean[n];
			int ans=0;
			Arrays.fill(b, true);
			for(;;)
			{
				for(int i=0;i<n;i++)
					fake[i]=a[i];
				for(int i=0;i<n;i++)
				{
					if(b[i])
					{
						int c=a[i];
						int cnt=0;
						for(int j=0;j<n;j++)
						{
							if(c==a[j]&&b[j])
								cnt++;
						}
						for(int j=0;j<n;j++)
						{
							if(c==a[j]&&b[j])
							{
								b[j]=false;
								a[j]=cnt;
							}
						}
					}
				}
				Arrays.fill(b, true);
				int judge=0;
				for(int i=0;i<n;i++)
				{
					if(a[i]==fake[i])
						judge=1;
					else
					{
						judge=0;
						break;
					}
				}
				if(judge==1)
					break;
				ans++;
			}
			System.out.println(ans);
			for(int i=0;i<n;i++)
			{
				if(i==n-1)
					System.out.print(a[i]);
				else
					System.out.print(a[i]+" ");
			}
			System.out.println();
		}
	}
}

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

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

return 0;
}


Measured memory_bytes: 3104
def judge(board):
    for i in range(0, 3):
        if board[i][0] == board[i][1] == board[i][2] == 0 :
            return True
        if board[0][i] == board[1][i] == board[2][i] == 0:
            return True
    
    if board[0][0] == board[1][1] == board[2][2] == 0:
        return True
    if board[0][2] == board[1][1] == board[2][0] == 0:
        return True
    
    return False


upper  = list(map(int, input().split(" ")))
middle = list(map(int, input().split(" ")))
lower  = list(map(int, input().split(" ")))

board = (upper,middle,lower)

N = int(input())
bingos = list()

for i in range(0, N):
    bingos.append(int(input()))


"""
print(upper)
print(middle)
print(lower)
print(bingos)

for i in range(3):
    for j in range(3):
        print(f'board[', i, '][', j, '] =', board[i][j])
"""

for i in range(0, len(bingos)):
    for j in range(0, 3):
#        print('bingos[i] : j = ', bingos[i], j)
        if upper[j] == bingos[i]:
            board[0][j] = 0
#            print('find in upper')
            break
        elif middle[j] == bingos[i]:
            board[1][j] = 0
#            print('find in middle')
            break
        elif lower[j] == bingos[i]:
            board[2][j] = 0
#            print('find in lower')
            break
        else:
            pass
#    print('')

if judge(board):
    print('Yes')
else:
    print('No')


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long

const int N = 2e5 + 5;

int32_t main()
{
    IOS;
    int t=1;
    // cin>>t;
    while(t--)
    {
        int a[3];
        for (int i = 0; i < 3; ++i)
        {
            cin>>a[i];
        }
        sort(a,a+3);
        if(a[0]==5&&a[1]==5&&a[2]==7) cout<<"YES";
        else cout<<"NO";
    }
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <string>
using namespace std;
int main(void){
    // Your code here!
    double a, b;
    cin >> a >> b;

    double x = (a + b) / 2; 
    int sei = (a + b) / 2;
    
    double syo = x - sei;
    if ( syo >= 0.5){
        ++sei;
    } 
    cout << sei << endl;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(ll i=a;i<=b;i++)
#define FORD(i,a,b) for(ll i=a;i>=b;i--)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define sqr(x)  ((x) * (x)) 
#define cub(x)  ((x) * (x) * (x))
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; }
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
// ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
	int n; cin >> n;
	ll a[n],b[n],diff[n];
	FOR(i,0,n-1) cin >> a[i];
	FOR(i,0,n-1) cin >> b[i];
	FOR(i,0,n-1) diff[i] = a[i]-b[i];
	ll minussum = 0;
	sort(diff,diff+n,greater<ll>());
	int ans = 0;
	FOR(i,0,n-1){
		if(diff[i]<0) {
			minussum += diff[i];
			++ans;
		}
	}
	minussum = 0-minussum;
	FOR(i,0,n-1){
		if(diff[i]>0 && minussum>0){
			minussum -= diff[i];
			++ans;
		}
	}

	if(minussum>0) cout << -1 << endl;
	else cout << ans << endl;



}


Measured memory_bytes: 2560
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>
#include <set>

using namespace std;

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

    vector<int> m(N);
    for (int i = 0; i < N; i++) {
        cin >> m[i];
    }

    sort(m.begin(), m.end());

    int ans = N;
    for (int i = 0; i < N; i++) {
        X -= m[i];
    }

    if (X > 0) {
        ans += X / m[0];
    }

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

Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    int firstB = 0;
    int lastA = 0;
    int AB = 0;
    string s;
    long ans = 0;
    for(int i=0;i<n;i++){
        cin >> s;
        if(s[0] == 'B' && s[s.length()-1]=='A')AB++;
        else{
            if(s[0]=='B')firstB++;
            if(s[s.length()-1]=='A')lastA++;
        }
        for(int j=0;j<s.length()-1;j++){
            if(s.substr(j,2)=="AB")ans++;
        }
        
        
    }
    if(AB>=1){
            ans += AB-1;
            if(firstB >0){
                ans++;
                firstB--;
            }
            if(lastA > 0){
                ans++;
                lastA--;
            }
        }
    cout << ans+min(firstB,lastA)<<endl;
    
}


Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include<cstdio>
using namespace std;

int main() {
    char* s=new char[101];
    int n, i;
    scanf("%s", s);

    n = strlen(s);

    for(i=0; i<(n-1)/2; i++) {
        if(s[i] != s[n-1-i]) {
            cout << "No" << endl;
            return 0;
        }
    }
    int j = (n-1)/2;
    if(j%2 == 0) {
        for(i=0; i<=j/2-1; i++) {
            if(s[i] != s[j-1-i]) {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    if(j%2 != 0) {
        for(i=0; i<j/2-1; i++) {
            if(s[i] != s[j-1-i]) {
                cout << "No" << endl;
                return 0;
            }
        }
    }

    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
using namespace std;

int main() {
 
  string s;
  cin >>s ;
  if(s=="Sunny"){
  cout << "Cloudy"<< endl;
  }else if(s=="Cloudy"){
  cout << "Rainy"<< endl;
  }else if(s=="Rainy"){
  cout << "Sunny"<< endl;
  }
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
using namespace std;
#define MAX 10000
#define NIL -1

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

Node T[MAX];
int n, D[MAX], H[MAX];

void setDepth(int u, int d) {
	if (u == NIL)return;
	D[u] = d;
	setDepth(T[u].l, d + 1);
	setDepth(T[u].r, d + 1);
}

int setHeight(int u) {
	int h1 = 0, h2 = 0;
	if (T[u].l != NIL)
		h1 = setHeight(T[u].l) + 1;
	if (T[u].r != NIL)
		h2 = setHeight(T[u].r) + 1;
	return H[u] = (h1 > h2 ? h1 : h2);
}

int getSibling(int u) {
	if (T[u].p == NIL) return NIL;
	if (T[T[u].p].l != u && T[T[u].p].l != NIL)
		return T[T[u].p].l;
	if (T[T[u].p].r != u && T[T[u].p].r != NIL)
		return T[T[u].p].r;
	return NIL;
}

void print(int u) {
	printf("node %d: ", u);
	printf("parent = %d, ", T[u].p);
	printf("sibling = %d, ", getSibling(u));
	int deg = 0;
	if (T[u].l != NIL) ++deg;
	if (T[u].r != NIL) ++deg;
	printf("degree = %d, ", deg);
	printf("depth = %d, ", D[u]);
	printf("height = %d, ", H[u]);

	if (T[u].p == NIL) {
		printf("root\n");
	}
	else if (T[u].l == NIL && T[u].r == NIL) {
		printf("leaf\n");
	}
	else {
		printf("internal node\n");
	}
}

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

	for (int i = 0; i < n; ++i) T[i].p =  NIL;

	int v, l, r;
	for (int i = 0; i < n; ++i) {
		scanf("%d %d %d", &v, &l, &r);
		T[v].l = l;
		T[v].r = r;
		if (l != NIL) T[l].p = v;
		if (r != NIL) T[r].p = v;
	}

	int root = 0;
	for (int i = 0; i < n; ++i)	if (T[i].p == NIL) root = i;

	setDepth(root, 0);
	setHeight(root);

	for (int i = 0; i < n; ++i) print(i);
	
	//cin >> n;
	//cout << "!!!!!!!!!!!\n";

	return 0;
}


Measured memory_bytes: 3212
use std::io::*;
use std::str::FromStr;

fn main() {
    let n: usize = read();
    let mut a: Vec<u32> = (0..n).map(|_| read()).collect();

    let mut result = String::from("Yes");

    let mut before = a[0];

    for i in 0..n {
        let h = a[i];
        if before == h {

        } else if before < h || before == h - 1 {
            // 1下げる
            a[i] -= 1;
        } else {
            result = String::from("No");
            break;
        }
        before = a[i];
    }

    println!("{}", result);
}

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


Measured memory_bytes: 4352
#include <algorithm>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map> //pair is also included in this library
#include <stack>
#include <string>
#include <vector>

#define REP(i, s, n) for(int i = (int)(s); i < (int)(n); i++)

using namespace std;

typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PII;

//prefer define statement
//for reason that const int ver. of INF will raise a silly warning (unused variable)
#define INF (INT_MAX/3)
//const int INF = INT_MAX/3;

/*------------------------------------------------------------------------------*/

int main(){
  int N, A, B, cnt = 0, frn = 0;
  string s;
  cin >> N >> A >> B;
  cin >> s;

  vector<string> pass(N);

  REP(i, 0, N){
    if(s[i] == 'a' && cnt < A+B){
      cnt++;
      pass[i] = "Yes";
    } else if(s[i] == 'b' && cnt < A + B && frn < B){
      cnt++;
      frn++;
      pass[i] = "Yes";
    } else {
      pass[i] = "No";
    }
  }

  REP(i, 0, N){
    cout << pass[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 6144
#include <algorithm>
#include <array>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <vector>

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

using namespace std;

//int dp[100][100 * 100 + 1] = {0};

int main() {
  std::cout << std::fixed << std::setprecision(10);
  int N;
  cin >> N;
  vector<int> A(N+1);
  vector<int> B(N);

  rep(i, N+1)
    cin >> A[i];
  rep(i, N)
    cin >> B[i];

  uint64_t total = 0;
  int sup = 0;
  rep(i, N) {
    int beaten = min(A[i], B[i]);
    total += beaten;

    sup = B[i] - beaten;
    beaten = min(A[i+1], sup);
    total += beaten;
    A[i+1] -= beaten;
  }
  cout << total << endl;

  return 0;
}


Measured memory_bytes: 1024
function main(input) {
   input = input.trim();
  const a = input.split(" ").map(Number);
 
 console.log(a[0]+a[1]>a[2]+a[3]?"Left"
			:a[0]+a[1]<a[2]+a[3]?"Right"
			:"Balanced");
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 29544
import java.util.*;

class Main {
	static final int MOD = 1_000_000_007;
	Scanner sc;
	int N;
	List<Edge>[] edges;
	int[] pow2;
	long pow2Ninv;
	
	static class Edge {
		int from, to, c;
		Edge rev;
		Edge(int from) { this.from = from; }
	}
	
	@SuppressWarnings("unchecked")
	private void calc() {
		sc = new Scanner(System.in);
		N = sc.nextInt();
		edges = new List[N];
		for (int i = 0; i < N; i++) edges[i] = new ArrayList<Edge>();
		Edge f = null;
		Edge b = null;
		for (int i = 0; i < N-1; i++) {
			f = new Edge(sc.nextInt() - 1);
			b = new Edge(sc.nextInt() - 1);
			f.to = b.from; b.to = f.from;
			f.rev = b; b.rev = f;
			edges[b.to].add(f);
			edges[f.to].add(b);
		}
		pow2 = new int[N+1];
		pow2[0] = 1;
		for (int i = 1; i < N+1; i++) pow2[i] = (pow2[i-1] << 1)%MOD;
		pow2Ninv = extgcd(pow2[N], MOD)[1];
		
		countByDFS(f);
		countByDFS(b);
		
		long sum = 0;
		for (int v = 0; v < N; v++) {
			if (edges[v].size() == 1) continue;
			int s = 0;
			for (Edge e : edges[v]) s = (s -1 + pow2[e.c]) % MOD;
			sum = (sum + pow2[N-1] - s - 1 + MOD) % MOD;
		}
		System.out.println(sum*pow2Ninv%MOD);
	}
	
	private void countByDFS(Edge target) {
		int c = 0;
		int from = target.from;
		for (Edge e : edges[target.to]) {
			if (e.to == from) continue;
			countByDFS(e);
			c += e.c;
		}
		target.c = c + 1;
		target.rev.c = N - target.c;
	}
	
	static final long[] extgcd(long a, long b) {
		long aa = a, bb = b;
		long x0 = 1, x1 = 0;
		long y0 = 0, y1 = 1;
	
		while (b != 0) {
			long q = a / b;
			long r = a % b;
			long x2 = x0 - q * x1;
			long y2 = y0 - q * y1;
	
			a = b; b = r;
			x0 = x1; x1 = x2;
			y0 = y1; y1 = y2;
		}
		if (bb > 0 && x0 < 0) {
			long n = -x0/bb;
			if (-x0%bb != 0) n++;
			x0 += n*bb; y0 -= n*aa;
		}
	    return new long[]{a, x0, y0};
	}
	
	public static void main(String[] args) {
		new Main().calc();
	}
}

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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, w;
  cin >> n >> w;
  vector<int> vi(n);
  vector<int> wi(n);
  for(int i = 0; i<n;i++){
    cin >> vi[i] >> wi[i];
  }
  long long dp[2][w+1];
  bool f = 0;
  for(int i = 0; i<=n;i++){
    for(int j = 0; j<=w;j++){
      if(i == 0 || j==0 ){
	dp[f][j]  = 0;
      }else{
	if(j>=vi[i-1]){
	  dp[f][j] = max(dp[!f][j],dp[!f][j-vi[i-1]]+wi[i-1]);
	}else{
	  dp[f][j] = dp[!f][j];
	}
      }
    }
    f = !f;
  }
  cout << dp[!f][w];
  return 0;
}


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


// long solve(vector<long> A) {
//     long res = 0;
//     long sum = A[0];
//     for (int i = 1; i < A.size(); i++)
//     {
//         if (sum > 0) {
//             sum += A[i];
//             while (sum >= 0) {
//                 res++;
//                 sum--;
//             }
//         }
//         else if (sum < 0)
//         {
//             sum += A[i];
//             while (sum <= 0) {
//                 res++;
//                 sum++;
//             }
//         }
//     }
//     return res;
// }

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

//     vector<long> A(N);
//     for (int i = 0; i < N; i++)
//     {
//         cin >> A[i];
//     }

//     long res;
//     if (A[0] != 0)
//     {
//         res = solve(A);
//         cout << res << endl;
//     }
//     else
//     {
//         long res_first_plus=1, res_first_minus=1;
//         A[0] = 1;
//         res_first_plus += solve(A);

//         A[0] = -1;
//         res_first_minus += solve(A);
//         res = min(res_first_plus, res_first_minus);
//         cout << res << endl;
//     }
// }

long first_plus(vector<long> &A) {
    long sum = 0;
    long res = 0;
    for (int i = 0; i < A.size(); i++)
    {
        sum += A[i];
        if (i % 2 == 0)
        {
            while (sum < 1)
            {
                sum++;
                res++;
            }
        }
        else
        {
            while (sum > -1) {
                sum--;
                res++;
            }
        }
    }
    return res;
}

long first_minus(vector<long> &A) {
    long sum = 0;
    long res = 0;
    for (int i = 0; i < A.size(); i++)
    {
        sum += A[i];
        if (i % 2 == 0)
        {
            while (sum > -1) {
                sum--;
                res++;
            }
        }
        else
        {
            while (sum < 1)
            {
                sum++;
                res++;
            }
        }
    }
    return res;
}

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

    vector<long> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    cout << min(first_plus(A), first_minus(A)) << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
using namespace std;
signed main(){
  vector<int> a(3);
  cin>>a.at(0)>>a.at(1)>>a.at(2);
  sort(all(a));
  cout<<a.at(2)*10+a.at(1)+a.at(0);
}

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

int main(){
	int n, k;
	cin >> n >> k;
	long long int res[1 << n];
	for(int i = 0; i < 1 << n; i++){
		res[i] = 1;
		for(int j = 0; j < n; j++){
			if((i / (1 << j)) % 2 == 1) res[i] *= 2;
			else res[i] += k;
		}
	}
	sort(res, res + (1 << n));
	cout << res[0] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
int main(){
  bitset<52> card;
  card.reset();
  string str;
  int num,n;
  cin >> n;
  rep(i,n){
    cin >> str;
    if(str == "S") {
      cin >> num;
      card.set(num-1);
    }else if(str == "H"){
      cin >> num;
      card.set(num-1+13);
    }else if(str == "C"){
      cin >> num;
      card.set(num-1+26);
    }else if(str == "D"){
      cin >> num;
      card.set(num-1+39);
    }
  }
  for(int i=0;i<52;i++){
    if(!card.test(i)){
      switch (i/13) {
        case 0:
        cout << "S " << (i%13)+1 << endl;
        break;
        case 1:
        cout << "H " << (i%13)+1 << endl;
        break;
        case 2:
        cout << "C " << (i%13)+1 << endl;
        break;
        case 3:
        cout << "D " << (i%13)+1 << endl;
        break;
      }
    }
  }


  return 0;
}



Measured memory_bytes: 3120
<?php
fscanf(STDIN, '%d %d', $n, $m);
$x = array_map('intval', explode(' ', trim(fgets(STDIN))));
if ($n >= $m) {
    echo 0;
    exit;
}
sort($x);
for ($i = 1; $i < $m; $i++) {
    $d[] = $x[$i] - $x[$i - 1];
}
sort($d);
$sum = 0;
for ($i = 0; $i < $m - $n; $i++) {
    $sum += $d[$i];
}
echo $sum;

Measured memory_bytes: 18932
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int q;
	bool reversed = false;
	string ans, trats, goal;
	cin >> ans;
	cin >> q;
	int t, f;
	string c;
	while (q--) {
		cin >> t;
		if (t == 1) {
			reversed = !reversed;
		}
		else {
			cin >> f >> c;
			if ((f == 1) == !reversed) {
				trats += c;
			}
			else {
				goal += c;
			}
		}
	}
	ans = string(rbegin(trats), rend(trats)) + ans + goal;
	if (reversed) {
		reverse(begin(ans), end(ans));
	}
	cout << ans << "\n";
}

Measured memory_bytes: 1200
#include <iostream>

using namespace std;

int main(void){
    string sl, sr;
    int n; cin >> n;
    int l = 0, r = n-1;
    cout << l << endl; cin >> sl;
    if (sl == "Vacant") return 0;
    cout << r << endl; cin >> sr;
    if (sr == "Vacant") return 0;
    string stemp;
    while (stemp != "Vacant") {
        int m = (l + r) / 2;
        cout << m << endl;
        cin >> stemp;
        if ((sl == stemp && ((m-l) % 2 == 0)) || (sl != stemp && ((m-l) % 2 == 1))) {
            l = m; sl = stemp;
        }
        else {
            r = m; sr = stemp;
        }
    }
    return 0;
}
//simple is bset


Measured memory_bytes: 852
#include <iostream>

using namespace std;

int main()
{
    long long int n;
    int i,a=0,b=0,c=0,d=0;
    string s;
    cin>>n;
    for(i=0;i<n;i++){
        cin>>s;
        if(s=="AC") a++;
        if(s=="WA") b++;
        if(s=="TLE") c++;
        if(s=="RE") d++;
    }
    cout<<"AC x "<<a<<endl;
    cout<<"WA x "<<b<<endl;
    cout<<"TLE x "<<c<<endl;
    cout<<"RE x "<<d<<endl;
    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数

//-------------------------------------------------
//
void yes(){
  cout <<"Yes"<<endl ;
}
void no(){
  cout <<"No"<<endl ;
}


//-------------------------------------------------
//




//-------------------------------------------------


int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n ;
  cin >> n ;
  string s, t ;
  cin >> s >> t ;
  vector<char> ans ;
  REP(i,n){
    ans.push_back(s.at(i)) ;
    ans.push_back(t.at(i)) ;
  }
  REP(i,2*n){
    cout << ans.at(i) ;
  }
  cout <<endl ;
  
  
  return 0 ;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
int main() {
	#ifdef LOACL
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	#endif
	int N,ans=0;
	scanf("%d",&N);
	for(int i=1;i<=N;i++) {
		int x,t=0;
		scanf("%d",&x);
		while(x%2==0) {
			x/=2;
			t++;
		}
		ans+=t;
	}
	printf("%d\n",ans); 
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <time.h>
#include <queue>
#include <list>
#include <string.h>
#define sf scanf
#define pf printf
#define lf double
#define ll long long
#define p123 printf("123\n");
#define pn printf("\n");
#define pk printf(" ");
#define p(n) printf("%d",n);
#define pln(n) printf("%d\n",n);
#define s(n) scanf("%d",&n);
#define ss(n) scanf("%s",n);
#define ps(n) printf("%s",n);
#define sld(n) scanf("%lld",&n);
#define pld(n) printf("%lld",n);
#define slf(n) scanf("%lf",&n);
#define plf(n) printf("%lf",n);
#define sc(n) scanf("%c",&n);
#define pc(n) printf("%c",n);
#define gc getchar();
#define re(n,a) memset(n,a,sizeof(n));
#define len(a) strlen(a)
#define LL long long
#define eps 1e-6
using namespace std;
const double pi = 3.1415926535;
/*
https://codeforces.com/contest/1106/problems
https://codeforces.com/contest/1106/submit
*/
int a[100050];
bool vis[100050];
int main() {
    re(vis,false);
    /*int n,m,k;
    s(n) s(m) s(k)*/
    int n;
    s(n)
    for(int i = 0; i < n; i ++){
        s(a[i])
    }
    sort(a,a+n);
    /*
    for(int i = n-1; i >= 0; i --){
        if(vis[a[i]] == false){
            vis[a[i]] = true;
        }else{
            p(n-2); pn
            return 0;
        }
    }*/
    int x = 0;
    for(int i = 1; i < n; i ++){
        if(a[i] == a[i-1]){
            x ++;
        }
    }
    if(x & 1){
        x ++;
    }
    p(n-x) pn
    return 0;
}



 //1 1 1 1 2 2 2 3 3 5 6 6 8 8 11


Measured memory_bytes: 768
#include <iostream>
#include <vector>
#include <numeric>
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
#define REP(i, n) for (int i = 0; i < (n); ++i)

int main() {
  int n; cin >> n;
  VI t(n);
  REP(i, n) cin >> t[i];
  int m; cin >> m;
  VI ans;
  REP(i, m) {
    int p, x; cin >> p >> x;
    VI s = t;
    s[p - 1] = x;
    ans.push_back(accumulate(s.begin(), s.end(), 0));
  }
  for (int i : ans) cout << i << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <algorithm>
#include <vector>
using namespace std;
#define rep2(x,from,to) for(int x=(from);x<(to);++(x))
#define rep(x,to) rep2(x,0,to)
bool desc(pair<int, int> a, pair<int, int> b) {
	if(a.second != b.second) return a.second > b.second;
	else return a.first < b.first;
}
int main() {
	int n, a;
	while(cin >> n, n) {
		vector<pair<int,int> > v;
		rep(i,n) {
			cin >> a;
			int s[10][2] = {}, cnt = 0, b, c, score = 0;
			while(cnt < 9) {
				cin >> b;
				if(b == 10) {
					s[cnt][0] = 10;
					cnt++;
					continue;
				}
				cin >> c;
				s[cnt][0] = b;
				s[cnt][1] = c;
				cnt++;
			}
			cin >> b >> c;
			s[cnt][0] = b;
			s[cnt][1] = c;
			if(b + c >= 10) cin >> score;
			rep(i,9) {
				if(s[i][0] == 10) {
					s[i][0]+=s[i+1][0];
					if(s[i+1][0] == 10 && i != 8) s[i][0] += s[i+2][0];
					else s[i][0] += s[i+1][1];
				} else if(s[i][0] + s[i][1] == 10) s[i][0] += s[i+1][0];
			}
			rep(i,10) {
				rep(j,2) {
					score += s[i][j];
				}
			}
			v.push_back(make_pair(a, score));
		}
		sort(v.begin(), v.end(), desc);
		rep(i,n) {
			cout << v[i].first << " " << v[i].second << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1196
w, h, n = gets.split.map(&:to_i)
ary = []
x = 0
y = 0
n.times do
  ary << gets.split.map(&:to_i)
end
ary.each do |i|
  if i[2] == 1 
    x = i[0] if x < i[0]
  elsif i[2] ==2
    w = i[0] if w > i[0]
  elsif i[2] == 3
    y = i[1] if y < i[1]
  elsif i[2] == 4
    h = i[1] if h > i[1]
  end
end
if w-x<=0 || h-y<=0
  puts 0
else
  puts (w-x)*(h-y)
end


Measured memory_bytes: 3836
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str[] = br.readLine().split(" ");

        int A = Integer.parseInt(str[0]);
        int B = Integer.parseInt(str[1]);
        int C = Integer.parseInt(str[2]);
        int K = Integer.parseInt(str[3]);

        if(A >= K){
            System.out.println(K);
        }
        else if(A+B >= K){
            System.out.println(A);
        }
        else if(A+B+C >= K){
            System.out.println(A-(K - (A+B)));
        }
    }
}


Measured memory_bytes: 32364
import sys
readline = sys.stdin.readline

N, M = map(int, readline().split())

z = (N-1)//2
left = z//2
right = z - left

Ans = []
for i in range(left):
    Ans.append((i, i-2*(i+1)))
ss = 2*left+2*right-1
for i in range(right):
    st = left + i
    Ans.append((st, ss-st))

AA = []
for a, b in Ans[:M]:
    AA.append((a%N+1, b%N+1))

print('\n'.join(['{} {}'.format(*a) for a in AA]))

Measured memory_bytes: 82832
#include <bits/stdc++.h>
using namespace std;
#define ll long long
//#define fr(i,j,k) for(int i=j;i<k;i++)
//#define f(n) fr(i,0,n)
//#define f1(n) fr(i,1,n+1)
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
const ll mod = 1e11 + 7;
const int maxn = 2e5+5;
#include<atcoder/all>
using namespace atcoder;
void solve() {
    int n, m;
    cin >> n >> m;
    vector<ll>A(n),B(m),C;
    for (auto &i : A) {
        cin >> i;
    }
    for (auto &i : B) {
        cin >> i;
    }
    C =convolution<998244353>(A,B);
    for (auto &i : C) {
        cout << i <<' ';
    }
    cout << '\n';
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int c = 0;
    int t;
    if (!c) {
        t = 1;
    }
    else {
        cin >> t;
    }
    while (t--) {
        solve();
    }
    
}


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

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

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

    vector<int> v(N);
    int sum = 0;
    for (int i = 0; i < N; ++i) {
        cin >> v[i];
        sum += v[i];
    }

    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());
    int cnt = 0;
    double tmp = sum * 1/(4.0*M);
    for (int i = 0; i < M; ++i) {
        if (v[i] >= tmp) ++cnt;
        else break;
    }

    if (cnt == M) cout << "Yes" << "\n";
    else cout << "No" << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
     int a,b,c;
    cin>>a>>b>>c;
    if(a-b<=0) cout<<c<<endl;
    else{
        if(a-b-c<0) cout<<c-(a-b)<<endl;
        else cout<<"0"<<endl;
    }

}



Measured memory_bytes: 256
#include <stdio.h>

int getNextNumber(int n,int L) {
	char format[100];
	char buffer[100];
	int max,min;
	int i,j;
	char temp;
	sprintf(format,"%%0%dd",L);
	sprintf(buffer,format,n);
	for(i=L-1;i>0;i--) {
		for(j=0;j<i;j++) {
			if(buffer[j]<buffer[j+1]) {
				temp=buffer[j];
				buffer[j]=buffer[j+1];
				buffer[j+1]=temp;
			}
		}
	}
	sscanf(buffer,"%d",&max);
	for(i=0;i+i<L;i++) {
		temp=buffer[i];
		buffer[i]=buffer[L-i-1];
		buffer[L-i-1]=temp;
	}
	sscanf(buffer,"%d",&min);
	return max-min;
}

int main(void) {
	int a,L;
	int numbers[21];
	int i,j,found;
	while(scanf("%d%d",&a,&L)==2 && (a|L)!=0) {
		numbers[0]=a;
		for(i=1;i<21;i++)numbers[i]=getNextNumber(numbers[i-1],L);
		for(i=1;i<21;i++) {
			found=0;
			for(j=0;j<i;j++) {
				if(numbers[i]==numbers[j]) {
					found=1;
					break;
				}
			}
			if(found)break;
		}
		if(i>=21)return 1;
		printf("%d %d %d\n",j,numbers[j],i-j);
	}
	return 0;
}

Measured memory_bytes: 628
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

typedef long long ll;

#define INF 10e17 // 4倍しても(4回足しても)long longを溢れない
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto itr : x) { debug(itr); }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

int main() {
  int n;
  cin >> n;
  deque<ll> a(n);
  ll minus = 0, plus = 0;
  rep(i, n) {
    cin >> a[i];
    if (a[i] >= 0) plus += 1;
    else minus += 1;
  }

  sorti(a);
  vector<pair<int,int>> p;
  for (int i = 0; i < n-1; ++i) {
    int t1 = a.front(), t2 = a.back();
    if (i == n-2) {
      if (t1 - t2 > t2 - t1) {
        p.push_back(make_pair(t1, t2));
        cout << t1 - t2 << endl;
      } else {
        p.push_back(make_pair(t2, t1));
        cout << t2 - t1 << endl;
      }
      break;
    }
    a.pop_back();
    a.pop_front();
    // cout << t1 << " " << t2 << endl;
    if (minus > plus) {
      p.push_back(make_pair(t2, t1));
      a.push_back(t2 - t1);
      minus -= 1;
    } else {
      p.push_back(make_pair(t1, t2));
      a.push_front(t1 - t2);
      plus -= 1;
    }
    /*
    for (auto itr : a) {
      cout << itr << " ";
    }
    END;*/
  }

  // cout << a.front() << endl;
  for (auto itr : p) {
    cout << itr.first << " " << itr.second << endl;
  }
}


Measured memory_bytes: 3576
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>

using namespace std;

#define rint register int
#define gc() getchar()
inline int read(rint ans = 0, rint sgn = ' ', rint ch = gc())
{
	for(; ch < '0' || ch > '9'; sgn = ch, ch = gc());
	for(; ch >='0' && ch <='9';(ans*=10)+=ch-'0', ch = gc());
	return sgn-'-'?ans:-ans;
}
char s[55]; int n;
int main()
{
	scanf("%s",s+1), n = strlen(s+1);
	s[n-7] = '\0'; printf("%s\n",s+1);





	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int h=sc.nextInt();
        int w=sc.nextInt();
        int n=sc.nextInt();
        int[] nums=new int[n];
        for(int i=0;i<n;i++)nums[i]=sc.nextInt();
        int[][] ans=new int[h][w];
        int nh=0;
        int nw=0;
        int index=0;
        int painted=0;
        while(painted<h*w){
            ans[nh][nw]=index+1;
            nums[index]--;
            if(nums[index]==0)index++;
            painted++;
            if(nh%2==0&&nw<w-1){
                nw++;
            }else if(nh%2==1&&nw!=0){
                nw--;
            }else{
                nh++;
            }
        }
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                System.out.print(ans[i][j]+" ");
            }
            System.out.println();
        }
    }
    
    
}


Measured memory_bytes: 32040
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func init() {
	const maxWord = (1 << 30)
	buf := []byte{}
	sc.Buffer(buf, maxWord)
	sc.Split(bufio.ScanWords)
}

func input() string {
	sc.Scan()
	return sc.Text()
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func main() {
	n, _ := strconv.Atoi(input())
	c, _ := strconv.Atoi(input())
	k, _ := strconv.Atoi(input())
	t := make([]int, n)
	for i := 0; i < n; i++ {
		t[i], _ = strconv.Atoi(input())
	}
	sort.Ints(t)

	ans := 0
	left := 0
	waitNum := 0
	for i := 0; i < n; i++ {
		if t[i]-t[left] > k {
			passengersNUm := min(waitNum, c)
			left += passengersNUm
			waitNum -= passengersNUm
			ans++
		}

		waitNum++
		if waitNum > c {
			passengersNUm := min(waitNum, c)
			left += passengersNUm
			waitNum -= passengersNUm
			ans++
		}
	}

	if waitNum > 0 {
		ans++
	}

	fmt.Println(ans)
}


Measured memory_bytes: 2944
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <set>
#include <vector>
#include <map>
#include <cstdio>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <cassert>
#include <climits>
#include <numeric>
#include <sstream>
using namespace std;
typedef long long ll;
#define DEBUG
#ifdef DEBUG
	#define debug printf
#else
	#define debug(...)
#endif
int b[105];
int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	for(int i = 1;i <= n - 1; ++i)
	{
		cin>>b[i];
	}
	int last = 0;
	int pos = n - 1;
	int ans = b[n - 1] + b[1];
	while(pos != 0)
	{
		last = min(b[pos - 1],b[pos]);
		ans += last;
		--pos;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
  string s;
  cin>>s;
  if(s=="Sunny")
    cout<<"Cloudy"<<endl;
  else if(s=="Cloudy")
    cout<<"Rainy"<<endl;
  else 
    cout<<"Sunny"<<endl;
  return 0;}



Measured memory_bytes: 256
using System;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var nk = Console.ReadLine().Split()
                .Select(int.Parse)
                .ToArray();
            int n = nk[0];
            int k = nk[1];

            var p = Console.ReadLine().Split()
                .Select(int.Parse)
                .ToArray();

            Array.Sort(p);
            int result = 0;

            for (int i = 0; i < k; i++) 
            {
                result += p[i];
            }
            Console.WriteLine(result);
        }
    }
}


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

int main() {
    int n; cin >> n;
    vector<pair<long long, int>> v(n);
    for (int i = 0; i < n; i++) cin >> v[i].first, v[i].second = i;
    sort(v.rbegin(), v.rend());
    vector<long long> ans(n, v[0].first);
    ans[v[0].second] = v[1].first;
    for (int i = 0; i < n; i++) {
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 6272