akhauriyash/Code-Regression huggingface dataset:
n=int(input())
print(0)
s=input()
if s=="Vacant":
    exit()
print(n-1)
t=input()
if t=="Vacant":
    exit()
l,r=0,n
for i in range(18):
    mid=(l+r)//2
    print(mid)
    m=input()
    if m=="Vacant":
        exit()
    if (mid-l)%2:
        if s==m:
            r=mid
            t=m
        else:
            l=mid
            s=m
    else:
        if s==m:
            l=mid
            s=m
        else:
            r=mid
            t=m

Measured memory_bytes: 3660
#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
#include <math.h>
#include <utility>
#include <map>
#include <queue>
#include <stack>
#include <set>

using namespace std;

#define INF 210000000
#define int long long

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

int lcm(int a, int b) { return a * b / gcd(a, b); }

signed main() {
    int a,b,c;
    cin >> a >> b >> c;
    vector<int> hoge;
    hoge.push_back(a);
    hoge.push_back(b);
    hoge.push_back(c);
    sort(hoge.begin(),hoge.end());
    if(hoge[0] + hoge[1] == hoge[2]) cout << "Yes";
    else cout << "No";
}



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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin>>n;
  string s,t; cin>>s>>t;
  rep(i,n) cout<<s.at(i)<<t.at(i);
}


Measured memory_bytes: 256
import java.util.Iterator;
import java.util.LinkedList;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;


class GraphTopological2 {
	private int totalVertex;
	private int totalEdge;
	private int [] indegree;
	private Set<Integer> s = new HashSet<Integer>();
	private LinkedList<LinkedList<Integer>> adjList;
	public GraphTopological2() {
		totalVertex = 0; 
	}
	public void loadAdjList() {
		Scanner in = new Scanner(System.in);
		totalVertex = in.nextInt();
		totalEdge = in.nextInt();
		adjList = new LinkedList<LinkedList<Integer>>();
		indegree = new int[totalVertex];
		for(int i=0; i<totalVertex; i++){
			LinkedList<Integer> tmp = new LinkedList<Integer>();
			adjList.add(tmp);
			s.add(i);
		}
		for(int i = 0; i < totalEdge; i++) {
			int v = in.nextInt();
			int neighbor = in.nextInt();
			adjList.get(v).add(neighbor); // add its neighbor to its list
			indegree[neighbor]++; // increase its indegree by 1	
		}
		in.close();
	}
	
	public void Topological(){
		while(!s.isEmpty()){
			Iterator<Integer> itr = s.iterator();
			while (itr.hasNext()) {
				int k = itr.next();
				if(indegree[k]==0){
					System.out.println(k);
					Iterator<Integer> it = adjList.get(k).iterator();
					while (it.hasNext()) {
				    	int neib = it.next();// get all neighbors of the current node that has no incoming edges
				    	indegree[neib]--;					    	
				   }
		    	   s.remove(k);
		    	   break;
				}
			}
		}
	}

}

public class Main {
	public static void main(String argv[]) {
		GraphTopological2 g = new GraphTopological2();
		g.loadAdjList();
		g.Topological();
	}
}


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

int n,q;
vector<int> A,m;

int main()
{
    cin >> n;
    A.resize(n);
    for(int i=0; i<n; ++i) cin >> A[i];
    cin >> q;
    m.resize(q);
    for(int i=0; i<q; ++i) cin >> m[i];
    bool bl[40010];
    memset(bl, 0, sizeof(bl));
    
    for (int bit = 0; bit < 1<<n; ++bit) {
        int sum = 0;
        for (int i = 0; i < n; ++i) {
            if(bit & 1<<i) sum += A[i];
        }
        bl[sum] = true;
    }
    
    for (int i = 0; i < q; ++i) {
        cout << (bl[m[i]] ? "yes" : "no") << endl;
    }
}



Measured memory_bytes: 3132
#include <stdio.h>

int main(void){
  int n, i, j, k, l, m, o,  f[5][5], ans;
  scanf("%d",&n);
  while(n--){
    for(i = 0;i < 5;i++){
      for(j = 0;j < 5;j++){
	scanf("%d",&f[i][j]);
      }
    }
    ans = 0;
    for(i = 0;i < 5;i++){
      for(j = 0;j < 5;j++){
	for(k = 1;i + k <= 5;k++){
	  for(l = 1;j + l <= 5;l++){
	    int flag = 1;
	    for(m = 0;m < k;m++){
	      for(o = 0;o < l;o++){
		if(f[i + m][j + o] != 1){
		  flag = 0;
		}
	      }
	    }
	    if(flag && ans < k * l){
	      ans = k * l;
	    }
	  }
	}
      }
    }
    printf("%d\n",ans);
  }
  return 0;
}

Measured memory_bytes: 1028
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

using ll = long long;

using namespace std;

int main() {
    ll n;
    cin >> n;
    ll sum = 0;
    for (ll i=1; i<=n; i++) {
        if (i % 3 != 0 && i % 5 != 0) sum += i;
    }
    cout << sum << '\n';
    return 0;
}


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

int main(){
	int n,m; cin>>n>>m;
	int i=10;
	int j=m;
	while(j/10!=0){
		i*=10;
		j=j/10;
	}
	int x=n*i+m;
	for(int l=0;l<x/2;l++){
		if(l*l==x){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}

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

int main()
{
    ll i,j,x;
  	string s,t;
  	cin>>s>>t;
  	cout<<t<<s;
    return 0;
}

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

#define ll long long int 
ll mod=1e9+7;

// vector<int> g[200005];
// int vis[200005];
// queue<int> q;
// int level[200005];

// void dfs(int i)
// {
//     vis[i] = 1;
//     for(int j=0;j<g[i].size();j++)
//     {
//         int child = g[i][j];
//         if(vis[child] == 0)
//         {
//             dfs(child);
//         }
//     }
// }

// void bfs(int i)
// {
//     vis[i] = 1;
//     while(!q.empty())
//     {
//         int top = q.front();
//         int len_adj = g[top].size();
//         int j;
//         for(j=0;j<len_adj;j++)
//         {
//             int v = g[top][j];
//             if(vis[v]==0)
//             {
//                 vis[v]=1;
//                 q.push(v);
//                 level[v] = level[top] + 1;
//             }
//         }   
//         q.pop();
//     }
// }

ll modular_exponentiation(ll base, ll power)
{
    ll ans = 1;
    base = base % mod;
    while (power > 0)
    {
        if (power & 1)
        {
            ans = (ans * base) % mod;
        }

        power /= 2;
        base = (base * base) % mod;
    }
    return ans;
}

int main()
{
    /* Faster input ouput */
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    // cout.tie(NULL);

    /* To read input from a file and output to a file */
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    
    int t = 1;
    // cin >> t;
    while(t--)
    {        
        // ll n,i,j;
        string s;

        cin >> s;
        if(s == "ABC")
        {
            cout << "ARC\n";
        }
        else
        {
            cout << "ABC\n";
        }
        
    }

    
    
}

Measured memory_bytes: 3620
ary = gets.chomp.split.map(&:to_i)
# n = ary[0]
m = ary[1]
x = ary[2]
cost = gets.chomp.split.map(&:to_i)
left_cost = 0
right_cost = 0

m.times do |i|
  if cost[i] < x then
    left_cost += 1
  else
    right_cost += 1
  end
end

if left_cost <= right_cost then
  puts(left_cost)
else
  puts(right_cost)
end


Measured memory_bytes: 1788
#include<stdio.h>
int main(void){
    int x;
    int y;
    int z;
    while(1){
        scanf("%d%d",&x,&y);
        if(x == 0&&y == 0){
            break;
        }
        if(x <= y) {
         printf("%d %d\n",x,y);
        }
        else{
         printf("%d %d\n",y,x);
        }
    }
    return 0;
}

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

typedef long long ll;
ll n, m, x, y, s = 1, cnt;
string a;
int main()
{
	ll i, j;
	cin >> a;
	cin >> m;
	n = a.size();
	for (i = 1; i < n; i++) {
		if (a[i] == a[i - 1]) {
			s++;
		} else {
			cnt += s / 2;
			if (x == 0) x = s;
			y = s;
			s = 1;
		}
	}
	if (s == n) {
		cout << (n * m) / 2;
		return 0;
	}
	y = s;
	if (s > 1) {
		cnt += s / 2;
		s = 1;
	}
	if (a[0] == a[n - 1]) {
		cnt -= x / 2;
		cnt -= y / 2;
		cout << cnt * m + ((x + y) / 2) * (m - 1) + x / 2 + y / 2;
	} else {
		cout << cnt * m;
	}
    return 0;
}


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

using namespace std;

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

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

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

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

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

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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int h,w,m; cin >> h >> w >> m;
  int br[300001];
  int bc[300001];
  int cntr[300001] = {};
  int cntc[300001] = {};
  int maxr=0,maxc=0;
  for(int i = 0; i < m; ++i){
    cin >> br[i] >> bc[i];
    ChangeMax(maxr,++cntr[br[i]]);
    ChangeMax(maxc,++cntc[bc[i]]);    
  }
  bitset<300001>r,c;
  int cr=0,cc=0;
  if(w < h)for(int i = w+1; i <= h; ++i)if(maxr == cntr[i])cr+=r[i] = 1;
  if(h < w)for(int i = h+1; i <= w; ++i)if(maxc == cntc[i])cc+=c[i] = 1;
  for(int i = min(w,h); i >= 1; --i){
    cr+=r[i] = maxr == cntr[i];
    cc+=c[i] = maxc == cntc[i];
  }
  int cntd = 0;
  for(int i = 0; i < m; ++i)
    cntd += c[bc[i]]&r[br[i]];
  cout << maxr + maxc - (cntd == cr*cc) << endl;
}


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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;


int main() {
    ll X; cin >> X;
    ll ans = 1;
    for(ll i = 2; i <= X; i++){
        ll tmp = i * i;
        while(tmp <= X){
            ans = max(ans, tmp);
            tmp *= i;
        }
    }

    cout << ans << endl;

}

Measured memory_bytes: 256
#include<stdio.h>
#include<climits>
#include<algorithm>

using namespace std;
int main(){
    int n,x;
    int min_num = INT_MAX,max_num = INT_MIN;
    long long sum = 0;
    scanf("%d",&n);
    for(int i = 0;i < n;i++){
        scanf("%d",&x);
        min_num = min(min_num,x);
        max_num = max(max_num,x);
        sum += x;
    }
    printf("%d %d %lld\n",min_num,max_num,sum);
    return 0;
}


Measured memory_bytes: 2720
import java.util.*;
import java.lang.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        int max = 0;
        int kari = 0;
        for(int i = 0;i<n;i++){
            if(s.charAt(i)=='I'){
                kari++;
            }else{
                kari--;
            }
            if(kari>max){
                max = kari;
            }
        }
        System.out.println(max);
        sc.close();
    }
}

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

using ll = long long;
using pll = pair<ll, ll>;
 
constexpr ll M = 1e9+7;

const string w = "01+-*()";

constexpr int mi = 0;
constexpr int ma = 1023;

bool isrange(int n) {
    return mi <= n && n <= ma;
}

int expr(string const& s, int& p);
int term(string const& s, int& p);
int factor(string const& s, int& p);
int number(string const& s, int& p);

int expr(string const& s, int& p) {
    int res = term(s, p);
    while(p < s.size() && (s[p] == '+' || s[p] == '-')) {
        if(s[p] == '+') {
            res += term(s, ++p);
        } else if(s[p] == '-') {
            res -= term(s, ++p);
        }
        if(!isrange(res)) {
            throw runtime_error("");
        }
    }
    return res;
}

int term(string const& s, int& p) {
    int res = factor(s, p);
    while(p < s.size() && s[p] == '*') {
        res *= factor(s, ++p);
        if(!isrange(res)) {
            throw runtime_error("");
        }
    }
    return res;
}

int factor(string const& s, int& p) {
    if(isdigit(s[p])) {
        return number(s, p);
    }
    if(s[p] == '-') {
        int res = -factor(s, ++p);
        if(!isrange(res)) {
            throw runtime_error("");
        }
        return res;
    } else if(s[p] == '(') {
        int res = expr(s, ++p);
        if(p < s.size() && s[p] != ')') {
            throw runtime_error("");
        }
        ++p;
        return res;
    } else {
        throw runtime_error("");
    }
}

int number(string const& s, int& p) {
    int res = 0;
    while(p < s.size() && isdigit(s[p])) {
        res <<= 1;
        res |= s[p] == '1';
        ++p;
    }
    if(!isrange(res)) {
        throw runtime_error("");
    }
    return res;
}

bool check(string const& s) {
    stack<int> st;
    vector<vector<bool>> par(s.size(), vector<bool>(s.size()));
    bool ok = true;
    for(int i=0; i<s.size(); ++i) {
        if(s[i] == '(') {
            st.push(i);
        }
        if(s[i] == ')') {
            if(st.empty()) {
                ok = false;
                break;
            }
            if(s[st.top()+1] == '(' && s[i-1] == ')' && par[st.top()+1][i-1]) {
                ok = false;
                break;
            }
            par[st.top()][i] = true;
            bool f = false;
            for(int j=st.top()+1; j<i; ++j) {
                f |= !isdigit(s[j]);
            }
            st.pop();
            ok &= f;
        }
    }
    return st.empty() && ok;
}

int solve(int i, string& s, vector<int> const& lost) {
    int res = -1;
    if(i == lost.size()) {
        try {
            int p = 0;
            if(check(s)) {
                res = expr(s, p);
            }
            return (p == s.size() ? res : -1);
        } catch(...) {
            return -1;
        }
    }
    for(int j=0; j<w.size(); ++j) {
        s[lost[i]] = w[j];
        res = max(res, solve(i+1, s, lost));
    }
    return res;
}

int main() {
    string s;
    cin >> s;
    vector<int> pos;
    for(int i=0; i<s.size(); ++i) {
        if(s[i] == '.') {
            pos.push_back(i);
        }
    }
    cout << solve(0, s, pos) << endl;
}


Measured memory_bytes: 3264
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = 999999999;
char x[20000][8001];
char y[20000][8001];


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

    vector<int> mv;
    string s;
    int ct = 0;
    cin >> s;
    REP(i, s.size()){
        if(s[i] == 'T') {
            mv.pb(ct);
            ct = 0;
        }
        else ct++;
    }
    mv.pb(ct);
    
    int _x, _y;
    cin >> _x >> _y;
    memset(x, 0, sizeof(x));
    memset(y, 0, sizeof(y));
    
    x[10000+mv[0]][0] = 1;
    y[10000][0] = 1;
    int t = 1;
    FOR(i, 1, mv.size()){
        if(i%2 == 0){       // x軸
            REP(j, 20000){
                x[j][t] = (x[min(19999, j+mv[i])][t-1] | x[max(0, j-mv[i])][t-1]);
            }
            t++;
        }else{      // y軸
            REP(j, 20000){
                y[j][t] = (y[min(19999, j+mv[i])][t-1] | y[max(0, j-mv[i])][t-1]);
            }
        }
    }
    if(mv.size()%2 == 1){
        if((x[10000+_x][t-1]&y[10000+_y][t-1]) == 1) puts("Yes");
        else puts("No");
    }else{
        if((x[10000+_x][t-1]&y[10000+_y][t]) == 1) puts("Yes");
        else puts("No");
    }


    return 0;
}



Measured memory_bytes: 312832
/* ファイル名：ITP1_2_D	*/
/* 内容：長方形の中に円が含まれるかを判定するプログラム							*/
/*		 長方形は左下の頂点を原点とし、右上の頂点の座標 (W,H) が与えられます。	*/
/*		 また、円はその中心の座標 (x,y) と半径 r で与えられます。				*/

/* include	*/
#include <stdio.h>

/* 外部変数宣言	*/

/* プロトタイプ宣言	*/

/* 関数名:main	*/
/* 処理内容:長方形の中に円が含まれるかを判定する	*/
int main( void )
{
	/* 内部変数定義	*/
	/* 入力			*/
	int W;	/* 長方形の幅			*/
	int H;	/* 長方形の高さ			*/
	int x;	/* 円の中心の座標x軸	*/
	int y;	/* 円の中心の座標y軸	*/
	int r;	/* 円の半径				*/
	
	/* 判定			*/
	int flag;	/* 円が飛び出たかどうかの判定フラグ	*/
	
	flag = 0;	/* フラグの初期化	*/
	
	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);	/* 入力変数の読み込み	*/
	
	/* 円が長方形の左から飛び出していないかの判定	*/
	if((x - r) < 0){
		flag = 1;	/* 円が長方形から飛び出しているので、フラグを立てる	*/
	}
	else{
		/* 円が長方形から飛び出していないので、処理なし					*/
	}
	
	/* 円が長方形の下から飛び出していないかの判定	*/
	if((y - r) < 0){
		flag = 1;	/* 円が長方形から飛び出しているので、フラグを立てる	*/
	}
	else{
		/* 円が長方形から飛び出していないので、処理なし					*/
	}
	
	/* 円が長方形の右から飛び出していないかの判定	*/
	if((x + r) > W){
		flag = 1;	/* 円が長方形から飛び出しているので、フラグを立てる	*/
	}
	else{
		/* 円が長方形から飛び出していないので、処理なし					*/
	}
	
	/* 円が長方形の上から飛び出していないかの判定	*/
	if((y + r) > H){
		flag = 1;	/* 円が長方形から飛び出しているので、フラグを立てる	*/
	}
	else{
		/* 円が長方形から飛び出していないので、処理なし					*/
	}
	
	/* 出力の判定	*/
	if ( flag == 0 ){
		printf("Yes\n");	/* 円が長方形からはみ出していないので、Yesを出力	*/
	}
	else{
		printf("No\n");		/* 円が長方形からはみ出しているので、Noを出力		*/
	}
	
	return 0;
}



Measured memory_bytes: 2100
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
const int MOD = 1e9+7;
const int MOOD = 998244353;
#define PI 3.14159265359
typedef long long ll;
using namespace std;


int main(){
	ll n, m, k;
	cin >> n >> m >> k;
	vector<ll> a(n), b(m);
	vector<ll> asum(n+1), bsum(m+1);
	for (int i = 0; i < n; i++){
		cin >> a[i];
	}
	for (int i = 0; i < m; i++){
		cin >> b[i];
	}
	for (int i = 1; i <= n; i++){
		asum[i] = asum[i-1] + a[i-1];
	}
	for (int i = 1; i <= m; i++){
		bsum[i] = bsum[i-1] + b[i-1];
	}
	int ans = 0;
	for (int i = 0; i <= n; i++){
		if (k >= asum[i]){
			ll temp = k - asum[i];
			auto it = upper_bound(bsum.begin(), bsum.end(), temp);
			int tmp = i + it - bsum.begin() - 1;
			ans = max(ans, tmp);
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 9592
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <unordered_map>
#include <climits>
#include <set>
#include <unordered_set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>
#include <locale>
#include <random>
#include <type_traits>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

using LL = long long;

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


int main() {

    int N;
    cin >> N;

    vector<string> s(N);
    for (int i = 0; i < N; i++) cin >> s[i];

    map<map<char, LL>, LL> mp;
    for (int i = 0; i < N; i++) {
        map<char, LL> mm;
        for (auto c: s[i]) mm[c]++;
        mp[mm]++;
    }
    
    LL ans = 0;
    for(auto x: mp){
        LL d=  x.second;
        ans += d * (d-1) /2;
    }
    cout << ans << endl;

}
























Measured memory_bytes: 69376
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define ll long long
#define ld long double
#define pq priority_queue
#define ff first
#define ss second
#define pb push_back
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define MOD1 998244353
#define MOD2 1000000007

typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;

int power(ll a,ll b,ll m)
{
ll ans=1;
while(b>0){if(b&1){ans*=a;ans%=m;}a*=a;a%=m;b>>=1;}
return ans;
}


int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);

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

    int dp[3][n];
    for(int i=0;i<3;i++)
    {
        for(int j=0;j<n;j++)
        {
            dp[i][j]=0;
        }
    }

    dp[0][0] = a[0];
    dp[1][0] = b[0];
    dp[2][0] = c[0];
    for(int i=1;i<n;i++)
    {
        dp[0][i] = max(dp[1][i-1],dp[2][i-1]) + a[i];
        dp[1][i] = max(dp[2][i-1],dp[0][i-1]) + b[i];
        dp[2][i] = max(dp[0][i-1],dp[1][i-1]) + c[i];
    }

    cout<<max(max(dp[0][n-1],dp[1][n-1]), max(dp[1][n-1],dp[2][n-1]))<<endl;
}


Measured memory_bytes: 2560
import java.util.Scanner;

/*
 * if  0 then return 0
 * if x bigger than y return gcd of (y,x%y) 
 */

// how do you even submit this
public class Main {
	public static int gcd (int x, int y)
	{
		if (y==0) {
			return x;
		}
		else {
			return gcd(y,x%y);
		}
			
	}
	
	public static void main(String[] args) {
		Scanner scan = new Scanner (System.in);
//		
//	
//		for (int i = 0; i < 16; i++) {
			int a = scan.nextInt();
			int b = scan.nextInt();
//			System.out.println(gcd(a,b));
//		}
		System.out.println(gcd(a,b));
	}

}



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

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define IMOD 1000000007 
#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define lrep(i,n) for(long long  i = 0; i < (long long)(n); i++)
#define lrep2(i,a,n) for(long long i = (long long)(a); i <= (long long)(n); i++)

#define irrep(i,n) for(int i = (int)(n); i > -1; i--)
#define irrep2(i,a,n) for(int i = (int)(n); i >= (int)(a); i--)

typedef long long ll;
typedef std::vector<char> v_char;
typedef std::vector<v_char > v2_char;
typedef std::vector<double> v_double;
typedef std::vector<v_double > v2_double;
typedef std::vector<int> v_int;
typedef std::vector<v_int > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<v_ll > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<v_string > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<v_bool > v2_bool;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

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

using namespace std; 

int main(void)
{
    string s;
    
    irep(i, 3) {
        irep(j, 3) {
            char t;
            cin >> t;
            if(i == j) { s.push_back(t); }
        }
    }
    cout << s;
    return 0;
}   
/** atcoder **/


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

int parent(int i) { return i / 2; }
int left(int i) { return 2 * i; }
int right(int i) { return 2 * i + 1; }

int main() {
	int H, i, A[MAX + 1]; // 1-オリジンのため＋１する

	cin >> H; // ヒープサイズ
	for (i = 1; i <= H; i++) cin >> A[i];

	for (i = 1; i <= H; i++) {
		cout << "node " << i << ": ";
		cout << "key = " << A[i] << ", ";
		if (parent(i) >= 1) cout << "parent key = " << A[parent(i)] << ", ";
		if (left(i) <= H) cout << "left key = " << A[left(i)] << ", ";
		if (right(i) <= H) cout << "right key = " << A[right(i)] << ", ";
		cout << endl;
	}

	return 0;
}


Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for( int i=a; i<b; i++ )
#define REP(i,n) rep(i,0,n)
 
 
void displayVector(vector<string> v)
{
	int n = v.size();
	REP(i,n){
		cout << v[i] << " " ;
	}
	cout << endl;
}
 
int main(){
	string t; cin >> t;
	int n = t.size();
	REP(i,n){
		if(t[i]=='?'){
			t[i] = 'D';
		}
	}
	cout << t << endl;
	return 0;
}

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

int main()
{
    int l;
    cin >> l;
    double a = 0;
    a = double(l) / 3;
    double b = a*a;
    b = b*a;
    cout << fixed;
    cout << setprecision(13) << b << endl;
    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>

using namespace std;

int main(){
	int H,W;
	while(true){
		scanf("%d %d",&H,&W);
		if(H == 0 && W == 0) break;
		for(int i = 0; i < H; i++){
			for(int j = 0; j < W; j++){
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
	}
}



Measured memory_bytes: 2696
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair
#define PI pair<int,int>
#define poly vector<ll>
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)
#define pb push_back
#define fi first
#define se second
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(ll a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(ll a){write(a); puts("");}
inline void wri(ll a){write(a); putchar(' ');}
inline ull rnd(){
	return ((ull)rand()<<30^rand())<<4|rand()%4;
}
const int N=55,inf=1e9;
int n,ans,sum,rd[N],a[N],b[N],d[N],A[N],B[N],ti;
vector<int> f[N],g[N],v[N];
void ins(int a,int b){
	v[a].pb(b); rd[b]++; 
}
void dfsa(int p,int fa){
	sum++;
	for(auto i:f[p])if(i!=fa){dfsa(i,p); ins(i,p);}
}
void dfsb(int p,int fa){
	for(auto i:g[p])if(i!=fa){dfsb(i,p); ins(p,i);}
}
void dfs(int p,int fa){
	ti++;
	vector<int> zs,a,b;
	for(auto i:f[p])if(i!=fa)A[i]=ti;
	for(auto i:g[p])if(i!=fa){
		B[i]=ti;
		if(A[i]==ti)zs.pb(i); else b.pb(i);
	}
	for(auto i:f[p])if(i!=fa&&B[i]!=ti)a.pb(i);
	for(auto i:zs)dfs(i,p);
	for(auto i:a)dfsa(i,p);
	for(auto i:b)dfsb(i,p);
}
void solve(vector<int> A,vector<int> B,vector<int> C,vector<int> D,int rt){
	For(i,1,n){
		f[i].clear(); g[i].clear(); v[i].clear(); rd[i]=0;
	}sum=0;
	For(i,0,n-2){
		f[A[i]].pb(B[i]);
		f[B[i]].pb(A[i]);
		g[C[i]].pb(D[i]);
		g[D[i]].pb(C[i]);
	}
	dfs(rt,0);
	queue<int> q;
	For(i,1,n)if(!rd[i])q.push(i);
	while(q.size()){
		int t=q.front(); q.pop();
		for(auto i:v[t])if(--rd[i]==0)q.push(i);
	}
	For(i,1,n)if(rd[i])return;
	ans=min(ans,sum);
}
int main(){
	int T=read();
	while(T--){
		n=read(); ans=inf;
		memset(d,0,sizeof(d));
		set<PI> s1,s2;
		For(i,1,n-1){
			a[i]=read(); b[i]=read();
			if(a[i]>b[i])swap(a[i],b[i]);
			s1.insert(mp(a[i],b[i]));
			d[a[i]]++; d[b[i]]++;
		}
		vector<int> C,D;
		For(i,1,n-1){
			int x=read(),y=read();
			if(x>y)swap(x,y);
			C.pb(x); D.pb(y);
			s2.insert(mp(x,y));
		}
		if(s1==s2){puts("0"); continue;}
		For(i,1,n)if(d[i]==1){
			For(j,1,n)if(i!=j){
				vector<int> A,B;
				For(k,1,n-1){
					if(b[k]==i)A.pb(j); else A.pb(a[k]);
					if(a[k]==i)B.pb(j); else B.pb(b[k]);
				}
				solve(A,B,C,D,i);
			}
		}
		writeln(ans==inf?-1:ans+1);
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,n) for (int i=(n-1);i >= 0;i--)
#define all(v) v.begin(),v.end()
#define sz(v) (int)((v).size())
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;
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;}
const ll INF = 1LL << 60;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vvl a(2,vl(n+1,0));
    rep(i,n) cin >> a[0][i];
    rep(i,n) cin >> a[1][i];

    ll ans = 0,mem = 0;
    rep(i,n){
        mem = 0;
        rep(j,i+1) mem += a[0][j];
        rep(j,i,n) mem += a[1][j];
        ans = max(ans,mem);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

void chmax(int* a, int b){
  if( *a < b ) *a = b;
}

int main(){
  int n;
  cin >> n;
  int* hi = new int[n];
  for(int i=0; i<n; i++){
    cin >> hi[i];
  }

  int max = 0;
  int stepCount = 0;
  for(int i=0; i<n-1; i++){
    if( hi[i] >= hi[i+1] ){
      stepCount += 1;
    }else{
      chmax(&max, stepCount);
      stepCount = 0;
    }
  }
  chmax(&max, stepCount);
  cout << max << endl;

  return 0;
}


Measured memory_bytes: 640
n = int(input())

arr = range(1,n+1)

cnt = 0
cnt2 = 0
ans = 1
tmp = 1

for num in arr:
    tmp = int(num)
    while num % 2 == 0:
        num = num // 2
        cnt2 += 1
    
    if cnt <= cnt2:
        cnt = cnt2
        ans = tmp

    cnt2 = 0

print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 


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

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

    LL ans = 0;
    sort(L.begin(), L.end());
    for (int i = 0; i < N; ++i) {
        ans += min(L[i*2], L[i*2+1]);
    }

    cout << ans << endl;

    return 0;
}


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

int main()
{
	int N, tmp;
	cin >> N;
	bool flg=true;

	while(N > 0){
		tmp = N % 10;
		N /= 10;
		if(tmp == 7){
			cout << "Yes" << endl;
			flg = false;
			break;
		}
	}
	if(flg==true){
		cout << "No" << endl;
	}

}


Measured memory_bytes: 3600
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

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

    vector<pair<int, int> > v(n);
    for(int i=0; i<n; ++i)
        cin >> v[i].first >> v[i].second;
    sort(v.begin(), v.end());

    int i = 0;
    while(v[i].second < k){
        k -= v[i].second;
        ++ i;
    }
    cout << v[i].first << endl;

    return 0;
}


Measured memory_bytes: 1024
using System;
using System.Linq;
namespace Sample
{
  class Sample
  {
    static void Main(string[] args)
    {
    string[] str1=Console.ReadLine().Split(' ');
      int H=int.Parse(str1[0]);
      int W=int.Parse(str1[1]);
      for(int i=1;i<=W+2;i++){
        Console.Write("#");
      }
      Console.Write("\n");
      for(int ii=1;ii<=H;ii++){
        string str2=Console.ReadLine();
        Console.WriteLine("#"+str2+"#");
      }
      for(int i=1;i<=W+2;i++){
        Console.Write("#");
      }
      Console.Write("\n");
    }
    
  }

}


Measured memory_bytes: 27464
N=int(input())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
C=list(map(int, input().split()))

ans=sum(B)
for i in range(N-1):
    if A[i+1]-A[i]==1:
        ans+=C[A[i]-1]
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class T>
istream& operator >> (istream& is, vector<T>& v)
{
	for (auto &i : v) is >> i;
	return is;
}
template<class T>
ostream& operator<<(ostream& os, vector<T>& v)
{
	const string delimiter = "\n";
	REP(i, v.size())
	{
		os << v[i];
		if (i != v.size() - 1) os << delimiter;
	}
	return os;
}
/*--------------------template--------------------*/

const int dx[] = { -1, 0, 1, 0 }, dy[] = { 0, -1, 0, 1 };
//const int dx[] = { -1, -1, -1, 0, 0, 1, 1, 1 }, dy[] = { 0, -1, 1, -1, 1, 0, -1, 1 };
bool valid(int x, int y, int h, int w) { return (x >= 0 && y >= 0 && x < h&&y < w); }
int place(int x, int y, int w) { return w*x + y; }


const int INF = 1e9;

int h, w, k;
vs fld;

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	cin >> h >> w >> k;
	fld.resize(h);
	cin >> fld;
	int sx, sy;
	REP(i, h)REP(j, w)
	{
		if (fld[i][j] == 'S')
		{
			sx = i; sy = j;
			fld[i][j] = '.';
		}
	}
	if (sx == 0 || sx == h - 1 || sy == 0 || sy == w - 1)
	{
		cout << 0 << endl;
		return 0;
	}
	vector<vi> dist(h, vi(w, INF));
	dist[sx][sy] = 0;
	queue<pii> que;
	que.emplace(sx, sy);
	while (!que.empty())
	{
		int tx = que.front().first;
		int ty = que.front().second;
		que.pop();
		if (dist[tx][ty] == k) continue;
		REP(i, 4)
		{
			int nx = tx + dx[i];
			int ny = ty + dy[i];
			if (!valid(nx, ny, h, w) || fld[nx][ny] == '#' || dist[nx][ny] < INF) continue;
			dist[nx][ny] = dist[tx][ty] + 1;
			que.emplace(nx, ny);
		}
	}
	int ans = INF;
	REP(i, h)REP(j, w)
	{
		if (dist[i][j] <= k)
		{
			int mn = min({ i, j, h - 1 - i, w - 1 - j });
			chmin(ans, 1 + mn / k + (mn % k != 0));
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3456
fun main(args: Array<String>) {
    val input = readLine()!!.split(" ").map { it.toLong() }
    println(getRes(input[0], input[1]))
}

fun getRes(n: Long, k: Long): Long {
    val x = if (n > k) n%k else k-n
    return if (n <= x) n else getRes(x, k)
}

Measured memory_bytes: 37812
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using static System.Console;

namespace ConsoleApp2
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static void Main(string[] args)
        {
            var S = ReadLine();
            if (S[0] != 'A')
            {
                Console.WriteLine("WA");
                return;
            }
            if (S[1].ToString().ToLower() != S[1].ToString())
            {
                Console.WriteLine("WA");
                return;
            }
            if (S[S.Length-1].ToString().ToLower() != S[S.Length - 1].ToString())
            {
                Console.WriteLine("WA");
                return;
            }
            var cc = 0;
            for (var i=2;i< S.Length-1;i++)
            {
                if(S[i]=='C')
                {
                    cc++;
                    if(1<cc)
                    {
                        Console.WriteLine("WA");
                        return;
                    }
                }
                else
                {
                    if(S[i].ToString().ToLower()!= S[i].ToString())
                    {
                        Console.WriteLine("WA");
                        return;
                    }
                }
            }
            if (1 != cc)
            {
                Console.WriteLine("WA");
                return;
            }
            Console.WriteLine("AC");
        }

    }
}


Measured memory_bytes: 13140
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  while(1){
    int n,w,d;
    cin>>n>>w>>d;
    if(w==0)break;   
    vector<int>ck[2];
    ck[0].push_back(w);
    ck[1].push_back(d);
    int p,s,w1,d1;
    for(int i=0;i<n;i++){
      cin>>p>>s;
      p--;
      w1=w=ck[0][p];
      d1=d=ck[1][p];
      s%=2*(w+d);
      ck[0].erase(ck[0].begin()+p);
      ck[1].erase(ck[1].begin()+p);
      if(s<w||(w+d<s&&s<2*w+d))w=s%(w+d),w1-=w;
      else d=s%(w+d)-w,d1-=d;
      if(w*d>w1*d1) ck[0].push_back(w1), ck[1].push_back(d1), ck[0].push_back(w), ck[1].push_back(d);
      else ck[0].push_back(w), ck[1].push_back(d), ck[0].push_back(w1), ck[1].push_back(d1);
    }
    int an[101];
    for(int i=0;i<=n;i++)an[i]=ck[0][i]*ck[1][i];
    sort(an,an+n+1);
    for(int i=0;i<n;i++)cout<<an[i]<<" ";cout<<an[n]<<endl;
  }
  return 0;
}

Measured memory_bytes: 1224
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#include<stack>
#include<queue>
#define ll long long
#define itn int
#define co(ans) cout<<ans<<endl;
#define COYE cout<<"YES"<<endl;
#define COYe cout<<"Yes"<<endl;
#define COye cout<<"yes"<<endl;
#define CONO cout<<"NO"<<endl;
#define CONo cout<<"No"<<endl;
#define COno cout<<"no"<<endl;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
#define MAX 510000
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;}
using namespace std;


int main(){
  ll N,K,ans=0;
  cin>>N>>K;
  
  ll H[N],DP[N];
  REP(i,N){
    cin>>H[i];
    DP[i]=INF;
  }
  DP[0]=0;
   
  for(int i=1; i<N; ++i){
    for(int j=1; j<=K; ++j){
      if(i-j>=0) DP[i]=min(DP[i],DP[i-j]+abs(H[i]-H[i-j]));
    }
  }
  
  cout<<DP[N-1]<<endl;
  return 0;
}

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

using ll = long long;
using ld = long double;

int main(void)
{
    ll a,b,c,k;
    cin >> a >> b >> c;
    cin >> k;
    while(b<=a)
    {
        b=b*2;
        k--;
    }
    while(c<=b)
    {
        c=c*2;
        k--;
    }
    if(k<0)
    {
        cout << "No" << endl;
    }
    else
    {
        cout << "Yes" << endl;
    }
    
    return 0;
}


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

namespace program
{
    class Program
    {
        static void Main()
        {
          char[] s = Input.ScanStr().ToCharArray();
          s[3]='8';
          Console.WriteLine(new string(s));
        }
    }

    static class Input
    {
        static public int ScanInt() { return int.Parse(Console.ReadLine()); }
        static public uint ScanUint() { return uint.Parse(Console.ReadLine()); }
        static public double ScanDouble() { return double.Parse(Console.ReadLine()); }
        static public long ScanLong() { return long.Parse(Console.ReadLine()); }
        static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); }
        static public int[] ScanIntArray() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); }
        static public uint[] ScanUintArray() { return Console.ReadLine().Split(' ').Select(x => uint.Parse(x)).ToArray(); }
        static public double[] ScanDoubleArray() { return Console.ReadLine().Split(' ').Select(x => double.Parse(x)).ToArray(); }
        static public long[] ScanLongArray() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); }
        static public ulong[] ScanUlongArray() { return Console.ReadLine().Split(' ').Select(x => ulong.Parse(x)).ToArray(); }

        static public string ScanStr() { return Console.ReadLine(); }
        static public string[] ScanStrArray() { return ScanStr().Split(' '); }
    }

    static class MyMath
    {
        public static int GCD(int a, int b)
        {
            Func<int, int, int> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static ulong GCD(ulong a, ulong b)
        {
            Func<ulong, ulong, ulong> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static int LCM(int a, int b)
        {
            return a * b / GCD(a, b);
        }
        public static ulong LCM(ulong a, ulong b)
        {
            return a * b / GCD(a, b);
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
int a,b,c,m;
main(){
cin>>a>>b>>c>>m;
int ans=0;
ans+=min(a,m);
m-=(min(a,m));
m-=min(b,m);
ans-=min(c,m);
cout<<ans;
return 0;
}


Measured memory_bytes: 3624
#include <cstdio>

int main(){
    int N;
    scanf("%d",&N);
    int a[N];
    for(int i = 0; i < N; i++){
        scanf("%d",&a[i]);
    }
    int magic_count = 0;
    for(int i = 0; i < N - 2; i++){
        if(a[i] == a[i + 1] && a[i + 1] == a[i + 2]){
            if(a[i + 1] < 1000){
                a[i + 1]++;
                magic_count++;
            }else{
                a[i + 1]--;
                magic_count++;
            }
        }
    }
    for(int i = 0; i < N - 1; i++){
        if(a[i] == a[i + 1]){
            magic_count++;
        }
    }
    printf("%d\n",magic_count);

    return 0;
}

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

using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

#define ll long long
#define li long int
#define ld long double
#define lld long long double

#define pb push_back
#define mk make_pair
#define F first
#define S second

#define all(v) (v).begin(),(v).end()
#define fill(a) memset(a, 0, sizeof(a))

const int MX = 1e6;
const int MI = -1e6;
const int MOD = 1e9 + 7;
const string ALPHA = "abcdefghijklmnopqrstuvwxyz";
const double PI = 3.1415926535;

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

const int mod=1e9+7;
inline int add(int x,int y)
{
  x+=y;
  if (x>=mod)
    return x-mod;
  return x;
}
inline int sub(int x,int y)
{
  x-=y;
  if (x<0)
    return x+mod;
  return x;
}
inline int mul(int x,int y)
{
  return (x*1ll*y)%mod;
}
inline int power(int x,int y)
{
  int ans=1;
  while(y)
    {
      if (y&1) ans=mul(ans,x);
      x=mul(x,x);
      y>>=1;
    }
  return ans;
}
inline int inv(int x)
{
  return power(x,mod-2);
}
inline int gcd(int x, int y)
{
  return(y!=0)?gcd(y, x%y):x;
}

/*------------CODE-----------*/

int main()
{
  IOS;
  int n;
  cin >> n;
  int arr[n];
  for (int i=0; i<n; i++)
    {
      arr[i]=0;
    }
  for (int i=0, x; i<n-1; i++)
    {
      cin >> x;
      arr[x-1]++;      
    }
  for (int i=0; i<n; i++)
    {
      cout << arr[i] << endl;
    }
  return 0;
}


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

using namespace std;

const int N = 2000 + 7;
int n, a[N];

int main() {
        ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

        cin >> n;
        for (int i = 1; i <= n; i++)
                cin >> a[i];
        sort(a + 1, a + n + 1);

        int ans = 0;
        for (int i = 1; i <= n; i++)
                for (int j = i + 1; j <= n; j++) {
                        int l = j + 1, r = n, cnt = 0;
                        while (l <= r) {
                                int mid = (l + r) / 2;
                                if (a[mid] < a[i] + a[j]) {
                                        cnt = mid - j;
                                        l = mid + 1;
                                } else
                                        r = mid - 1;
                        }
                        ans += cnt;
                }
        cout << ans << "\n";

        return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main() {
    int32_t a, b;
    std::cin >> a >> b;
    if (a < b) {
        std::cout << "a < b" << std::endl;
    } else if (a == b) {
        std::cout << "a == b" << std::endl;
    } else if (a > b) {
        std::cout << "a > b" << std::endl;
    }
}


Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(long long i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;
 
int main()
{
  int k, x;
  cin >> k >> x;
  int a = -1000000;
  int b = -a;
  a = max(a, x-(k-1));
  b = min(b, x+(k-1));
  for (int i=a; i<=b; i++) {
    cout << i << " ";
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int a, b, c, d, e, f;
    scanf("%d %d %d", &a, &b, &c);
    d = a + b;
    e = b + c;
    f = c + a;
    if ((d <= e) && (d <= f))
    {
        printf("%d\n", d);
    }
    else if ((e <= f) && (e <= d))
    {
        printf("%d\n", e);
    }
    else
    {
        printf("%d\n", f);
    }
    return 0;
}

Measured memory_bytes: 128
class BinomialCoefficients
  attr_reader :mod
  attr_accessor :fac, :finv, :inv

  def initialize(max, mod)
    @mod  = mod
    @fac  = Array.new(max)
    @finv = Array.new(max)
    @inv  = Array.new(max)

    fac[0]  = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1]  = 1
    2.upto(max-1) do |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
    end
  end

  def compute(n, k)
    return 0 if n < k
    return 0 if n < 0 || k < 0

    fac[n] * (finv[k] * finv[n - k] % mod) % mod
  end
end

N, M, K = gets.split.map(&:to_i)

MOD = 998244353
bc = BinomialCoefficients.new(2 * (10 ** 5), MOD)

res = 0
(K+1).times do |k|
  res += M * (M-1).pow(N-1-k, MOD) * bc.compute(N-1, k)
  res %= MOD
end

puts res


Measured memory_bytes: 19072
#include <iostream>
#include <sstream>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <string>
#include <complex>

#include <cassert>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <cstring>

#define REP(i,e) for(int i=0;i<(int)(e);i++)
#define FOR(i,b,e) for(int i=(int)(b);i<(int)(e);i++)
#define ALL(c) (c).begin(), (c).end()
#define EACH(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define RALL(c) (c).rbegin(), (c).rend()
#define ALLA(a,n) ((a)+0), ((a)+n)

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef vector<string> vstring;
typedef vector<double> vdouble;

template<class T>void pp(T v,int n){ REP(i,n)cout<<v[i]<< ' ' ; cout << endl; }
template<class T>void pp(T v){ EACH(it,v) cout << *it << ' ' ; cout << endl;  }
template<class T>T& ls(T& a,T b){ if(b<a) a=b; return a; }
template<class T>T& gs(T& a,T b){ if(b>a) a=b; return a; }
inline ll to_i(const string& s){ll n;sscanf(s.c_str(),"%lld",&n);return n;}
inline string to_s(ll n){char buf[32];sprintf(buf,"%lld",n);return string(buf);}

class DisjointSet {
public:
  vint v;
  DisjointSet(int n) : v(n, -1) {}

  int root(int n) { return v[n] < 0 ? n : (v[n] = root(v[n])); }
  bool unite(int a, int b) {
    int ra = root(a), rb = root(b);
    if (ra == rb) return false;
    if (-ra > -rb) swap(ra, rb);
    v[rb] += v[ra];
    v[ra] = rb;
    return true;
  }
  int size() { return count_if(ALL(v), [](int x){ return x < 0; }); }
};

int main() {
  int n, m;
  while (cin >> n >> m) {
    DisjointSet ds(n);
    REP(i,m) {
      int s, d, c;
      cin >> s >> d >> c;
      s--; d--;
      ds.unite(s, d);
    }
    // pp(ds.v);
    cout << ds.size() << endl;
  }
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
using namespace std;
int a, b, c, d;
int cnt;
int main() {
	cin >> a >> b >> c >> d;
	while (a > 0 && c > 0) {
		cnt++;
		if (cnt % 2) c -= b;
		else a -= d;
	}
	if (c > 0) puts("No");
	else puts("Yes");
	return 0;
}

Measured memory_bytes: 3632