akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>//很简单的思路，输出一个字符串a，再输出一个字符串b，然后循环到结束。 
#include<cstring>
using namespace std;
int a,b,a1,b1;//记录长度。 
bool ok;//转换器。 
char s[55],ss[55];
int main(){
    scanf("%s%s",&s,&ss);//输入。 
    a=strlen(s);b=strlen(ss);//记录两个字符串的长度。 
    for(int i=0;i<a+b;++i){
        if(ok){//输出一个字符串b。 
            printf("%c",ss[b1]);//%c为输出单个字符。 
            b1++;
            ok=0;//转换。 
        }
        else{//输出一个字符串a。 
            printf("%c",s[a1]);
            a1++;
            ok=1;
        }
    }
    return 0;
}//完美结束。 

Measured memory_bytes: 128
import std.stdio;

void main() {
	long a, b, c;

	readf(" %s %s %s", &a, &b, &c);

	if (c - a - b < 0) {
		writeln("No");
		return;
	}

	if (4 * a * b < (c - a - b) * (c - a - b)) {
		writeln("Yes");
	} else {
		writeln("No");
	}
}


Measured memory_bytes: 380
//↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double pi = acos(-1);
const ll SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
ll fac[200005], finv[200005], inv[200005];
vector<ll>dij;
struct edge { ll to, cost; };
vector<vector<edge> >G;

ll mod_pow(ll a, ll b) {
	ll res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}

	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}


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

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

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) {
	for (auto &e : t) fill_v(e, v);
}

//↑template↑

int n,k[100005],ise[100005];
int main() {
  cin>>n;
  for(int i=0;i<n;++i){
    cin>>k[i];
    ++ise[k[i]];
  }
  for(int i=1;i<n;++i){
    if(ise[i]%2==1){
      cout<<0<<endl;
      return 0;
    }
  }
  cout<<mod_pow(2,n/2)<<endl;
}

Measured memory_bytes: 1024
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

//4方向ベクトル→↑←↓
int dx[] ={1,0,-1,0};
int dy[] ={0,-1,0,1};

double x,x2;
double y,y2;
double d;

int main()
{
  cin >>x>>y>>x2>>y2;
  cout <<setprecision(10)<<sqrt(pow(x-x2,2)+pow(y-y2,2))<<endl;
  return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
const int MOD = 1e9 + 7;
using namespace std;
typedef long long ll;

map<ll, int> mp;
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string s;
	cin >> s;
	sort(s.begin(), s.end());
	if (s.at(0) == s.at(1) && s.at(2) == s.at(3) && s.at(1) != s.at(2)) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

int cb(int n, int k){
    if(n < k)
        return 0;
    if(k == 0){
        return 1;
    }else if(k == 1){
        return n;
    }else if(k == 2){
        return n*(n-1)/2;
    }else{
        return n*(n-1)*(n-2)/6;
    }
}

int nine(int k){
    int ans = 1;
    if(k<0)
        return 0;
    else{
        REP(i, k)
            ans *= 9;
        return ans;
    }
    
}

int main()
{
    string Nmoji, temp;
    int N, K, index;
    long ans;
    cin >> Nmoji;
    cin >> K;
    ans = 0;
    N = Nmoji.length();
    index = 0;
    REP(i, N){
        if((N-i) < (K-index))
            break;
        if(K == index){
            ans++;
            break;
        }
        if(Nmoji[i] == '0')
            continue;
        if(i < N-1){
                ans += cb(N-1-i, K- index) * nine(K-index);
                ans += cb(N-1-i, K-1-index) * nine(K-index-1) * ((int)(Nmoji[i] - '0') - 1);
                index++;
        }else{
            ans += (int)(Nmoji[N-1]-'0');
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>

int S[12][1010];
int group[12];
int cnt[12];
int tmp[12];

int main(){
    int h, w, k;
    std::cin >> h >> w >> k;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            char c;
            std::cin >> c;
            S[i][j] = c - '0';
        }
    }
    int min = 10000;
    for(int i = 0; i < (1 << (h-1)); i++){
        int t = i;
        int ans = 0;
        for(int j = 1; j < h; j++){
            group[j] = group[j-1];
            if(t & 1) {
                group[j]++;
                ans++;
            }
            t >>= 1;
        }
        std::fill(cnt, cnt+12, 0);
        for(int i = 0; i < w; i++){
            bool flagCount = true, flagTmp = true;
            std::fill(tmp, tmp+12, 0);
            for(int j = 0; j < h; j++){
                tmp[group[j]] += S[j][i];
                cnt[group[j]] += S[j][i];
                flagCount &= (cnt[group[j]] <= k);
                flagTmp &= (tmp[group[j]] <= k);
            }
            if(!flagTmp){
                ans = 10000; break;
            }
            if(!flagCount){
                ans++;
                for(int j = 0; j <= group[h-1]; j++){
                    cnt[j] = tmp[j];
                }
            }
        }
        min = std::min(min, ans);
    }
    std::cout << min << std::endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define DEBUG true
#define coutd if(DEBUG) cout
#define ff first
#define ss second
#define len(x) int(x.size())
using ll = long long;
using ii = pair<int, int>;

int main(){
	ios_base::sync_with_stdio(0);
	int n, m;
	cin >> n >> m;
	priority_queue<int> vs;
	map<int, int> vx;
	for(int i=0; i<n; i++){
		int x;
		cin >> x;
		vs.push(x);
	}
	for(int i=0; i<m; i++){
		int x, k;
		cin >> k >> x;
		if(vx.find(x)!=vx.end())vx[x]+=k;
		else vx[x]=k;
	}
	ll ans=0;
	while(n--){
		int a = vs.top();
		ll b;
		if(vx.empty()) b = -int(1e12);
		else b = vx.rbegin()->ff;
		if(a>b){
			ans+=a;
			vs.pop();
		}
		else{
			ans+=b;
			vx[b]-=1;
			if(!vx[b])vx.erase(vx.find(b));
		}
	}
	cout << ans << endl;
}



Measured memory_bytes: 5368
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
	string s;
  	set<char> ans;
  	cin >> s;
  	for(char c: s)
    	ans.insert(c);
   	if (ans.size() == 3)
      cout << "Yes" << endl;
  	else
      cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll int64_t
#define f first
#define sec second
#define pb push_back
#define pf push_front
#define pbb pop_back
#define vi vector<ll>
#define vii vector< pair<ll,ll> >
#define pi pair<ll,ll>
#define map map<ll,ll>
#define set set<ll>
const int m=1e9+7;
int main(){
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,k;
    cin>>n>>k;
    ll sum=0;
    ll a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    for(int i=0;i<n-k;i++){
        sum+=a[i];
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
#include<functional>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << "\n";
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i, MAT.size()){
    REP(j, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << "\n";
  }
};

template <typename CLASS1, typename CLASS2>
class HOGE{
  public:
    CLASS1 key;
    CLASS2 value;
    HOGE(void){
      return;
    };
    HOGE(CLASS1 key, CLASS2 value){
      this->key = key;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "key : " << key << ", value : " << value << "\n";
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N, T;
  cin >> N >> T;
  ll c, t;
  ll ans = INFLL;
  REP(i, N){
    cin >> c >> t;
    if(t>T) continue;
    ans = min(ans, c);
  }

  if(ans<INFLL){
    cout << ans << "\n";
  }else{
    cout << "TLE\n";
  }

  return 0;
}

Measured memory_bytes: 256
N,M,C=map(int,input().split())
B=list(map(int,input().split()))
cnt=0
s=0
for i in range(N):
    A=list(map(int,input().split()))
    for (j,a) in enumerate(A):
        s+=B[j]*a
    if s+C>0:
        cnt+=1
    s=0
print(cnt)

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

using lint = long long;

lint gcd(lint x, lint y){
    while(y){
        lint r = x % y;
        x = y;
        y = r;
    }
    return x;
}

lint extgcd(lint a, lint b, lint& x, lint& y){
    lint d = a;
    if(b){
        d = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    }else{
        x = 1;
        y = 0;
    }
    return d;
}

lint mod_inverse(lint a, lint m){
    lint x, y;
    extgcd(a, m, x, y);
    return (m + x % m) % m;
}

pair<lint, lint> linear_congruence(const vector<lint>& A, const vector<lint>& B, const vector<lint>& M){
    lint x = 0, m = 1;
    for(int i = 0 ; i < A.size() ; ++i){
        lint a = A[i] * m, b = B[i] - A[i] * x, d = gcd(M[i], a);
        if(b % d != 0LL){
            return make_pair(-1LL, -1LL);
        }
        lint t = b / d * mod_inverse(a / d, M[i] / d) % (M[i] / d);
        x = x + m * t;
        m *= M[i] / d;
    }
    return make_pair(x % m, m);
}

lint solve(int n){
    vector<int> p(n);
    for(int i = 0 ; i < n ; ++i){
        cin >> p[i];
        --p[i];
    }
    vector<int> q(n);
    for(int i = 0 ; i < n ; ++i){
        cin >> q[i];
        --q[i];
    }

    vector<lint> A, B, M;

    vector<bool> done(n, false);
    for(int i = 0 ; i < n ; ++i){
        if(done[i]){
            continue;
        }
        int now = i;
        vector<int> vp, vq;
        while(!done[now]){
            done[now] = true;
            vp.emplace_back(p[now]);
            vq.emplace_back(now);
            now = q[now];
        }

        vector<int> loop = vq;

        sort(vp.begin(), vp.end());
        sort(vq.begin(), vq.end());
        if(vp != vq){
            return -1LL;
        }

        int m = (int)loop.size();
        vector<int> ptmp = p;
        for(int j = 0 ; j <= m ; ++j){
            vector< pair<int, int> > v;
            for(int k = 0 ; k < m ; ++k){
                v.emplace_back(loop[k], ptmp[loop[k]]);
            }
            sort(v.begin(), v.end());
            bool flag = true;
            for(int k = 0 ; k < m - 1 ; ++k){
                if(v[k].second > v[k + 1].second){
                    flag = false;
                    break;
                }
            }
            if(flag){
                A.push_back(1);
                B.push_back(j);
                M.push_back(m);
                break;
            }else if(j == m){
                return -1LL;
            }
            for(int k = 0 ; k < m ; ++k){
                int num = ptmp[loop[k]];
                ptmp[loop[k]] = q[num];
            }
        }
    }

    pair<lint, lint> ans = linear_congruence(A, B, M);

    if(ans.second == -1LL){
        return -1LL;
    }

    return ((ans.first % ans.second) + ans.second) % ans.second;
}

int main(){
    int n;
    while(cin >> n){
        lint ans = solve(n);
        cout << ans << endl;
    }

    return 0;
}


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

#define int long long
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define allrev(x) (x).rbegin(), (x).rend()
#define pb push_back
#define pf push_front
#define fori(i, a, n) for(int i = a; i < n; ++i)
#define MAX(x) (*max_element(all(x)))
#define MIN(x) (*min_element(all(x)))
#define sortarr(a, n) sort(a, a + n)
#define sortvec(V) sort(all(V))

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

typedef unordered_map<int, int, custom_hash> u_map;
typedef unordered_set<int, int, custom_hash> u_set;
typedef vector<int> V;
typedef pair<int , int> pairi;
typedef set<int> seti;
typedef priority_queue<int> p_queue;
typedef deque<int> deqi;

const int MOD = 1e9+7;
const int INF = 1e9+8;
const double pi = 3.14159265359;

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

void solve()
{
    string s;
    cin >> s;
    int ans = 0, cnt = 0;
    for(auto i : s){
        if(i == 'R')    cnt++;
        else{
            ans = max(ans, cnt);
            cnt = 0;
        }
    }
    if(cnt) ans = max(ans, cnt);
    cout << ans << endl;
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    solve();
    cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n ";
}

Measured memory_bytes: 3788
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>

using namespace std;

#define mod 1000000007

long long int cntb[1000001] = {};
long long int cntc[1000001] = {};
long long int cntcb[1000001] = {};
long long int sumcb[1000001] = {};

int main()
{
	int n, q;
	string s;
	cin >> n >> s >> q;
	// cntb[i] : 0文字目からi - 1文字目までのbの出現回数
	for(int i = 1; i <= n; i++){
		cntb[i] = cntb[i - 1];
		if(s[i - 1] == 'M') cntb[i]++;
	}
	// cntc[i] : 0文字目からi - 1文字目までのcの出現回数
	// cntcb[i] : 最後のcがi - 1文字目になるようなbcの組み合わせ
	// sumcb[i] : cntcb[0] + ... + cntcb[i - 1]
	for(int i = 1; i <= n; i++){
		cntc[i] = cntc[i - 1];
		if(s[i - 1] == 'C'){
			cntcb[i] = cntb[i - 1];
			cntc[i]++;
		}
		sumcb[i] = sumcb[i - 1] + cntcb[i];
		// cout << i << " " << sumcb[i] << endl;
	}

	for(int i = 0; i < q; i++){
		int k;
		cin >> k;
		long long int ans = 0;
		for(int j = 0; j < n; j++){
			if(s[j] != 'D') continue;
			ans += sumcb[min(j + k, n)] - sumcb[j] - ((cntc[min(j + k, n)] - cntc[j]) * cntb[j]);
			// cout << sumcb[min(j + k, n)] - sumcb[j] - ((cntc[min(j + k, n)] - cntc[j]) * cntb[j]) << endl;
		}
		cout << ans << endl;
	}
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

const int MOD = int(1e9) + 7;

int n, m;
int a[1000], b[1000], aa[1000], bb[1000];
int c[1000000];
int ca[1000000], cb[1000000];

int main() {
    scanf("%d%d", &n, &m);
    forn(i, n) scanf("%d", a + i), --a[i];
    forn(j, m) scanf("%d", b + j), --b[j];
    forn(i, n) aa[i] = a[i];
    forn(j, m) bb[j] = b[j];
    sort(aa, aa + n);
    reverse(aa, aa + n);
    sort(bb, bb + m);
    reverse(bb, bb + m);
    forn(i, n) forn(j, m) {
        c[i * m + j] = min(a[i], b[j]);
    }
    forn(i, n) ca[a[i]]++;
    forn(i, m) cb[b[i]]++;
    int cnt = n * m;
    sort(c, c + cnt);
    reverse(c, c + cnt);
    int ind = 0;
    int ans = 1;
    int ai = 0, bi = 0;
    for (int i = cnt - 1; i >= 0; --i) {
        int j = cnt - 1 - i;
        while (ind < cnt && c[ind] >= i) {
            ++ind;
        }
        while (ai < n && aa[ai] >= i) {
            ++ai;
        }
        while (bi < m && bb[bi] >= i) {
            ++bi;
        }
        if (ind <= j || ca[i] > 1 || cb[i] > 1) {
            cout << 0 << endl;
            return 0;
        }
        if (ca[i] == 0 && cb[i] == 0) {
            ans = (LL)ans * (ind - j) % MOD;
        } else if (ca[i] == 1 && cb[i] == 0) {
            ans = (LL)ans * bi % MOD;
        } else if (ca[i] == 0 && cb[i] == 1) {
            ans = (LL)ans * ai % MOD;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 7936
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
int n;
const int mod = (int)1e9 + 7;
int mult(int a, int b) {
    return (1LL * a * b) % mod;
}

int pw(int a, int b) {
    if (b == 0) return 1;
    if (b & 1) return mult(a, pw(a, b - 1));
    int res = pw(a, b / 2);
    return mult(res, res);
}

int sub(int a, int b) {
    int s = a - b;
    if (s < 0) s += mod;
    return s;
}

int sum(int a, int b) {
    int s = a + b;
    if (s >= mod) s -= mod;
    return s;
}

const int maxN = (int)1e5 + 10;

int fact[maxN], invfact[maxN], inv[maxN];

void init() {
    inv[1] = invfact[1] = invfact[0] = fact[0] = fact[1] = 1;
    for (int i = 2; i < maxN; i++) {
        fact[i] = mult(fact[i - 1], i);
        inv[i] = mult(inv[mod % i], mod - mod / i);
        invfact[i] = mult(invfact[i - 1], inv[i]);
    }
}

int cnk(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return mult(fact[n], mult(invfact[k], invfact[n - k]));
}
int p[maxN];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("input.txt", "r", stdin);
    init();
    cin >> n;
    int dst = 0;
    for (int i = 1; i <= n + 1; i++) {
        int x;
        cin >> x;
        if (p[x] != 0) {
            dst = i - p[x] + 1;
            break;
        }
        p[x] = i;
    }
    for (int i = 1; i <= n + 1; i++) {
        int ans = cnk(n + 1, i);
        ans = sub(ans, cnk(n + 1 - dst, i - 1));
        cout << ans << '\n';
    }
    return 0;
}

Measured memory_bytes: 2816
import sys
try:
    a=list(map(str,input().split()))
except EOFError:
    sys.exit()
b=[]
for i in range(len(a)):
    if "," in a[i]:
        a[i]=a[i].replace(',', '')
    elif "." in a[i]:
        a[i]=a[i].replace('.', '')
    if len(a[i])>=3 and len(a[i])<=6:
        b.append(a[i])
b=' '.join(b)
print(b)


Measured memory_bytes: 5564
#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   sz(s)         s.size()
#define   ll            long long int
#define   ull           unsigned ll
#define   ld            long double
#define   print(v)      for(ll i=0;i<v.size();i++)cout<<v[i]<<" "
#define   printpair(v)  for(ll i=0;i<v.size();i++)cout<<v[i].first<<" "<<v[i].second<<"\n"
#define   bmd           1000000007
#define   bmd1          998244353
#define   umll          unordered_map<ll,ll>
#define   mll           map<ll,ll>
#define   mcl           map<char,ll>
#define   pll           pair<ll,ll>
#define   F             first
#define   S             second
#define   setp(x)       setprecision(x)
#define   pb            push_back
#define   all(v)        v.begin(),v.end()
#define   tr(a)         for(auto it=a.begin();it!=a.end();it++)
#define   trr(a)        for(auto it1=a.begin();it1!=a.end();it1++)
#define   vll           vector<long long int>
#define   sorty(v)      sort(v.begin(),v.end())
#define   rsort(v)      sort(v.rbegin(),v.rend())
#define   PI            3.1415926535897932384626
#define   db()          cout<<"\n"<<"here"<<"\n"
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;


//---------------------------------------------------------------------------
const int MOD = bmd;
const int N=2e5+100;
inline  ll sqr(ll x){return x*x;}
inline  void normal(ll &a) { a = (a+MOD)%MOD; }
inline  ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline  ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline  ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline  ll modPow(ll b, ll p) { ll r = 1;b=b%MOD; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline  ll modInv(ll a) { return modPow(a, MOD-2); }
inline  ll modDiv(ll a,ll b) { return modMul(a, modInv(b)); }
//---------------------------------------------------------------------------
void solve()
{
    ll n;
    cin>>n;
    ll a[n+2],b[n+2],c[n+2];
    for(ll i=1;i<=n;i++)
        cin>>a[i]>>b[i]>>c[i];
    ll dp[n+2][3];
    memset(dp,0,sizeof(dp));
    dp[1][0]=a[1];
    dp[1][1]=b[1];
    dp[1][2]=c[1];
    for(ll i=2;i<=n;i++)
    {
        dp[i][0]=max(dp[i-1][1]+a[i],dp[i-1][2]+a[i]);
        dp[i][1]=max(dp[i-1][0]+b[i],dp[i-1][2]+b[i]);
        dp[i][2]=max(dp[i-1][0]+c[i],dp[i-1][1]+c[i]);
    }
    cout <<max({dp[n][0],dp[n][1],dp[n][2]})<<"\n";

}
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);//first give all input then gives output
    ll t=1;
    //cin>>t;
    while(t--){
        solve();
    }

    return 0;
}


Measured memory_bytes: 4992
function Main(input) {
    var na = input.split('\n');
    var N = Number(na[0]);
    var a = na[1].split(' ').map((n) => Number(n));

    var cnt = 0;  
    for (var i = 0 ; i < a.length ; ++i) {
        var n = a[i];
        while(true) {
            if (n % 2 === 1) break;
            n = n / 2;
            ++cnt;
        }
    }
    console.log(cnt);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 9292
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll MOD = 1e9+7;

#define vec     vector<int>
#define vecll   vector<ll>
#define vec2    vector<vector<int>>
#define vec2ll  vector<vector<ll>>
#define vpair   vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>
#define vecst   vector<string>
#define vecb    vector<bool>

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define f_sum(var)       accumulate(all(var), 0)
#define f_sumll(var)     accumulate(all(var), 0LL)
#define chmin(v1, v2)    v1 = min(v1, v2)
#define chmax(v1, v2)    v1 = max(v1, v2)
#define mpair(v1, v2)    make_pair(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << var << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << var << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << var;
#define prt2(v1, v2)     cout << v1 << " " << v2 << "\n"
#define prt3(v1, v2, v3) cout << v1 << " " << v2 << " " << v3 << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
void prtok(bool ok){prt((ok ? "Yes" : "No"));}
//----------------------------------------------------------------
ll num(ll n, ll r){
  return n/r+1;
}

int main(void) {
  ll a, b, x;
  cin >> a >> b >> x;

  if(a==0){
    prt(num(b,x));
  } else {
    prt(num(b,x)-num(a-1,x));
  }


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    string x, y; cin >> x >> y;

    string ans = "";

    rep(i,y.size()){
        ans += x[i];
        ans += y[i];
    }

    if(x.size() != y.size()) ans += x[x.size()-1];

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int abcd[2][4];
    int count = 2, number;

    string op[2] = {"+", "-"};

    cin >> number;

    
    for (size_t i = 0; i < 4; i++)
    {
        abcd[0][i] = number%10;
        abcd[1][i] = -1*abcd[0][i];
        number = number/10;
    }

    for (size_t j = 0; j < count; j++)
    {
        for (size_t k = 0; k < count; k++)
        {
            for (size_t l = 0; l < count; l++)
            {
                if((abcd[0][3] + abcd[j][2] + abcd[k][1] + abcd[l][0] ) == 7){
                    cout << abcd[0][3] << op[j] << abcd[0][2] << op[k] << abcd[0][1] << op[l] << abcd[0][0] << "=7" << endl;
                    return 0;
                }
            }
            
        }
        
    }
    
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/nikkei2019-qual/tasks/nikkei2019_qual_d

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

const ll INF = 1e18;

void solve() {
  ll N, M;
  cin >> N >> M;

  VVL edges(N, VL(0));
  VL in_counts(N);

  rep(i, N - 1 + M) {
    ll a, b;
    cin >> a >> b;
    a--, b--;

    edges[a].push_back(b);
    in_counts[b]++;
  }

  ll root = -1;
  rep(i, N) if (in_counts[i] == 0) root = i;

  VL parents(N, -1);

  queue<ll> q;
  q.push(root);

  while (!q.empty()) {
    ll u = q.front();
    q.pop();

    for (ll v : edges[u]) {
      parents[v] = u;
      in_counts[v]--;

      if (in_counts[v] == 0) q.push(v);
    }
  }

  rep(i, N) cout << (i == root ? 0 : parents[i] + 1) << endl;
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

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

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

void print_ints(vector<ll> v) {
  rep(i, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


Measured memory_bytes: 7936
#ABC 107 B
h, w = map(int, input().split())
lines = []
for i in range(h):
    line = input()
    if "#" in line:
        lines.append(line)
lines_t = ["".join(list(i)) for i in zip(*lines)]
lines2 = []
for line in lines_t:
    if "#" in line:
        lines2.append(line)
lines = ["".join(list(i)) for i in zip(*lines2)]
for line in lines:
    print(line)

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

int main() {
  string S, T; cin >> S >> T;
  vector<int> CS(26, -1), CT(26, -1);
  for (int i = 0; i < S.size(); i++) {
    int s = S.at(i) - 'a';
    int t = T.at(i) - 'a';
    if (CS.at(s) != -1 && CS.at(s) != t) {
      cout << "No" << endl;
      return 0;
    }
    CS.at(s) = t;
    if (CT.at(t) != -1 && CT.at(t) != s) {
      cout << "No" << endl;
      return 0;
    }
    CT.at(t) = s;
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 776
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res
def gcd(x, y):
    if x < y: x, y = y, x
    div = x % y
    while div != 0:
        x, y = y, div
        div = x % y
    return y

N,K=LI()
AS=LI()
AS.sort()
FL=FLIST(N)
INV_FL=list(map(INV,FL))
K_2=K-2
N_1=N-1

if K == 1:
    print(0)
    exit()

# nC(k-2) の累積和
NCSUM=[0]*N
for i in range(K-2, N_1):
    # print("i:{} K-2:{} value:{}".format(i, K_2, (((FL[i]*INV_FL[i-K_2])%DVSR)*INV_FL[K_2])%DVSR))
    NCSUM[i+1] = (NCSUM[i] + (((FL[i]*INV_FL[i-K_2])%DVSR)*INV_FL[K_2])%DVSR )%DVSR

# print(NCSUM)

res = 0
# 最小値側
for i in range(N-K+1):
    res -= (NCSUM[N_1-i]-NCSUM[K_2])*AS[i]%DVSR
res %= DVSR

# 最大値側
for i in range(N-K+1):
    res += (NCSUM[N_1-i]-NCSUM[K_2])*AS[N_1-i]%DVSR
res %= DVSR
print(res)


Measured memory_bytes: 17472
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    string S;
    
    cin>>S;
    
    if(S[0]=='S'){
       cout<<"Cloudy"<<endl;
    }else if(S[0]=='C')
    cout<<"Rainy"<<endl;
    else
    cout<<"Sunny"<<endl;
}


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

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
const int INF = int (1e9) + int (1e5);
const ll INFL = ll(2e18) + ll(1e10);
const ui MOD = 1E9 + 7;
const double eps = 1e-9;
#define FOR(i,n) for (int i=0;i<(n);i++)
#define MP make_pair



int main() {
    int A,B,C,D,res;
    cin >> A >> B >> C >> D;
    res = min(B,D) - max(A,C);
    if (res>0) cout << res;
    else cout << 0;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 10;
int a[10],b[10],s[10];
int x,y;
int main() {
	int n;
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> a[i];
		s[i] = i+1;
	}
	for(int i = 0; i < n; i++){
		cin >> b[i];
	}
	int cnt = 0;
	do{
		int x1 = 0,y1 = 0;
		while(x1 < n){
			if(a[x1] == s[x1])
				x1++;
			else
				break;
		}
		if(x1 == n)
			x = cnt;
		while(y1 < n){
			if(b[y1] == s[y1])
				y1++;
			else
				break;
		}
		if(y1 == n)
			y = cnt;
		cnt++;
	}while(next_permutation(s,s+n));
	cout << abs(x - y) << endl;
    return 0;
}

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

using namespace std;

int main(){	
	string S;
	cin >> S;
	int n = S.size();
	if(S[n - 1] == 's'){
		cout << S + "es" << endl;
	} else {
		cout << S + "s" << endl;
	}	
}


Measured memory_bytes: 3628
use proconio::*;

fn run() {
    input! {
        n: usize,
        a: [i64; n],
    }
    let xor = a.iter().skip(2).fold(0, |s, a| s ^ *a);
    let sum = a[0] + a[1];
    let w = 41i64;
    let mut x = a[0];
    while x > 0 && x ^ (sum - x) ^ xor != 0 {
        let z = x ^ (sum - x) ^ xor;
        let k = (0..w).rev().find(|k| z >> k & 1 == 1).unwrap();
        let m = 1 << k;
        let a = x % m + 1;
        let b = m - (sum - x) % m;
        x -= std::cmp::min(a, b);
    }
    if x > 0 {
        let ans = a[0] - x;
        println!("{}", ans);
    } else {
        println!("-1");
    }
}

fn main() {
    run();
}


Measured memory_bytes: 2140
/*

  "With age, comes wisdom. With travel, comes understanding.
   Remember that happiness is a way of travel – not a destination"

*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define int            long long int
#define F              first
#define S              second
#define pb             push_back
#define si             set <int>
#define vi             vector <int>
#define pii            pair <int, int>
#define vpi            vector <pii>
#define vpp            vector <pair<int, pii>>
#define mii            map <int, int>
#define mpi            map <pii, int>
#define spi            set <pii>
#define endl           "\n"
#define sz(x)          ((int) x.size())
#define all(p)         p.begin(), p.end()
#define double         long double
#define que_max        priority_queue <int>
#define que_min        priority_queue <int, vi, greater<int>>
#define bug(...)       __f (#__VA_ARGS__, __VA_ARGS__)
#define print(a)       for(auto x : a) cout << x << " "; cout << endl
#define print1(a)      for(auto x : a) cout << x.F << " " << x.S << endl
#define print2(a,x,y)  for(int i = x; i < y; i++) cout<< a[i]<< " "; cout << endl

inline int power(int a, int b)
{
     int x = 1;
     while (b)
     {
          if (b & 1) x *= a;
          a *= a;
          b >>= 1;
     }
     return x;
}

typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> Set;

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

const int N = 200005;
int a[N], n, m, k;
int cache[101][N];
int mod = 1e9 + 7;

int dp(int pos, int val)
{
     if (val > k)
          return 0;
     if (pos == n)
          return val == k;

     int &ans = cache[pos][val];
     if (ans != -1)
          return ans;

     ans = dp(pos, val + 1) + dp(pos + 1, val) - dp(pos + 1, val + a[pos] + 1) + 2 * mod;
     ans %= mod;
     return ans;
}

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

     memset(cache, -1, sizeof cache);
     cout << dp(0, 0);

}

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

     cout << setprecision(9) << fixed;
     clock_t z = clock();
     solve();
     cerr << "Run Time : " << ((double)(clock() - z) / CLOCKS_PER_SEC);

     return 0;
}

Measured memory_bytes: 162816
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <iterator>
#include <limits>
#include <numeric>
#include <utility>
#include <cmath>
#include <cassert>
#include <cstdio>

// #include <unordered_set>
// #include <unordered_map>

#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())

#define pb push_back
#define mp make_pair

int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}

typedef std::pair<int, int> P;
typedef long long ll;
typedef long double ld;

const int MOD = 1000000007;
const int INF = 1e9;
const ll LINF = INF * 1ll * INF;
const ld DINF = 1e200;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

using namespace std;

// #define int long long

signed main(){
  

    ios::sync_with_stdio(false);
    cin.tie(0);
    //cin高速化

    int n,m,a;
    int h,p,q;

    while(cin>>n>>m>>a){
        if(n==0&&m==0&&a==0)break;

        int amida[1001][101]={0};

        for(int i=0;i<m;i++){
            cin>>h>>p>>q;
            amida[h][p]=q;
            amida[h][q]=p;

        }

        // for(int i=0;i<10;i++){
        //     for(int j=0;j<7;j++){
        //         cout<<amida[i][j]<<" ";
        //     }
        //     cout<<endl;
        // }

        for(int i=1000;i>=0;i--){
            if(amida[i][a]!=0){
                a=amida[i][a];
                // cout<<a<<endl;
            }
        }

        cout<<a<<endl;

      
    }
    
}


Measured memory_bytes: 3396
f = lambda: list(map(int,input().split()))
c1 = f()
c2 = f()
c3 = f()
c12 = [c1[i]-c2[i] for i in range(3)]
c23 = [c2[i]-c3[i] for i in range(3)]
if all([c12[i] == c12[0] for i in range(3)]) and all([c23[i] == c23[0] for i in range(3)]):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test() ull t;cin>>t;while(t--)
#define pb push_back
#define mkp make_pair
#define nl cout<<endl
#define MOD 1000000007
#define loop(i,start,end) for(ull i=start;i<end;i++)
#define N 3001
#define all(v) v.begin(),v.end()
#define oa(a,n) for(int i=0;i<n;i++)cout<<a[i]<<" ";nl
#define ov(a) for(int i=0;i<a.size();i++)cout<<a[i]<<" ";nl
vector<ll>v;
ll dp[N][N];
int main() 
{
  ll n,sm;cin>>n;
  v.resize(n);
  loop(i,0,n)cin>>v[i],sm+=v[i];

  for(int i = n;i>=0;i--)
  {
  	for(int j = i;j<n;j++)	
  	{
  		if(i==j)dp[i][j] = v[i];
  		else dp[i][j] = max(v[i] - dp[i+1][j],v[j]-dp[i][j-1]);
  	}
  }
  cout<<dp[0][n-1]<<endl;

  return 0;
}

Measured memory_bytes: 70016
#include <stdio.h>

int main(){
  int N;
  scanf("%d",&N);
  int i;
  int A[N];
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }

  int ans=0;
  int k=1;
  for(i=1;i<N;i++){
    if(A[i]==A[i-1]){
      k++;
    }else{
      ans=ans+(int)(k/2);
      k=1;
    }
  }
  ans=ans+(int)(k/2);
  printf("%d",ans);
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pr;
typedef vector<pr> vp;
typedef vector<vp> vpp;
typedef vector<vector<ll> > graph;
#define pb push_back
#define mp make_pair
#define maxi INT_MAX
#define mini INT_MIN
#define endl '\n'
void set_val(vector<ll>& v, ll val){for(ll i=0;i<v.size();i++) v[i]=val;}

ll mod = pow(10,9) + 7;
ll modulo = 998244353;
double pi = 3.141592653589793238;
ll i_mov[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
ll j_mov[8] = {1, 1, 1, 0, -1, -1, -1, 0};

vector<vector<int>> g;
vector<int> parent, depth, subsize;

ll power(ll a, ll n)
{
    if(n==0)
    return 1;
    ll temp = power(a,n/2);
    if(n%2==0)
    return (temp*temp)%mod;
    return (((temp*temp)%mod)*a)%mod;
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cout<<fixed;
    cout<<setprecision(10);
    double r;
    cin>>r;
    cout<<2.0*pi*r;
    
    
    
} 

Measured memory_bytes: 3800
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;

int main(){
    int k, t;   cin >> k >> t;

    priority_queue<int> que;
    for(int i=0; i<t; i++){
        int x;  cin >> x;
        que.push(x);
    }
    while(1<que.size()){
        int x=que.top(); que.pop();
        int y=que.top(); que.pop();
        if(1<x) que.push(x-1);
        if(1<y) que.push(y-1);
    }

    cout << max(0, que.top()-1) << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
	int i = 1;
	while(true){
	int x = sc.nextInt();
	if(x == 0)break;
	System.out.printf("Case %d: %d",i,x);
	System.out.println("");
	i ++;
	}
}
}


Measured memory_bytes: 65276
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF 2000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int n;
int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    cin >> n;
    if (n%2 == 1) cout << 2*n << endl;
    else cout << n << endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 200000


int main(){
	vector<int>a;
	vector<int>b;
	int n, k,m;
	int x, y, z;
	long long s, ans;
	bool v = true;
	ans = 0;
	scanf("%d %d", &n,&m);
	f(i, m){
		scanf("%d", &x);
		a.push_back(x);
	}
	if (n >= m){
		printf("0\n");
		return 0;
	}
	sort(a.begin(), a.end());
	f(i, m - 1){
		b.push_back(a[i + 1] - a[i]);
	}
	sort(b.begin(), b.end());
	ans = 0;
	f(i, m-n){
		ans += b[i];
	}
	printf("%lld\n", ans);


	return 0;
}

Measured memory_bytes: 1400
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main(){
        let ab = read_vec::<i64>();
    let ans = (ab[0]-1) * (ab[1]-1);
    println!("{}",ans );
}

Measured memory_bytes: 4352
fn main() {
	let v = vec![1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51];
    let k : usize = read();

    println!("{}", v[k-1] );
}


fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}


Measured memory_bytes: 4352
#include<stdio.h>
int main(void){
	int x,y,r,W,H;
	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
	if(x-r>=0&&y-r>=0&&x+r<=W&&y+r<=H){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 584
n = int(input())
s = input()

cnt_b = s.count("#")
cnt_w = s.count(".")

#全部黒にする
ans = cnt_w
ansa = ans
for i in range(n):
  if s[i] == ".":
     ans -= 1
  else:
     ans += 1
  ansa = min(ans,ansa)
print(ansa)
  

Measured memory_bytes: 3500
//Prediction and Restriction

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define irep(i,a) for(auto i = a.begin(); i != a.end(); ++i)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
using p = pair<ll, string>;
using garph = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

signed main (){
    ll n,k,r,s,p,ans=0;
    string t;
    cin>>n>>k>>r>>s>>p>>t;
    vector<bool>flag(n,false);
    rep(i,0,t.size()){
        if(i>=k){
            if(t[i]==t[i-k]&&flag[i-k]){
                continue;
            }
        }
        if(t[i]=='r')ans+=p;
        else if(t[i]=='s')ans+=r;
        else ans+=s;
        flag[i]=true;
    }
    cout<<ans<<nnn;
    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<cmath>
#define ll long long
using namespace std;
ll X, Y;
int main(){
  cin >> X >> Y;
  int counter=1;
  bool flag =false;
  while(true){
    if (X*2 <=Y) counter++;
    else flag =true;
    if (flag) break;
    X *=2;
  }
  cout << counter << endl;
  return 0;
}

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

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// combination mod prime
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
  mint p(int n, int k) {
    return fact[n]*ifact[n-k];
  }
} c(500005);

int main() {
  int n, m;
  cin >> n >> m;
  mint ans = 0;
  rep(i, n+1) {
    mint temp = c(n, i);
    temp *= c.p(m, n);
    temp *= c.p(m-i, n-i);
    if (i&1) temp = -temp;
    ans += temp;
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 10988
def slove():
    import sys
    input = sys.stdin.readline
    n, k = list(map(int, input().rstrip('\n').split()))
    ab = sorted([list(map(int, input().rstrip('\n').split())) for _ in range(n)])
    t = 0
    for a, b in ab:
        t += b
        if t >= k:
            print(a)
            exit()


if __name__ == '__main__':
    slove()


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

using namespace std;


void solve() {
    int n, g;
    cin >> n >> g;
    g/=100;
    vector<int> p(n), c(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i] >> c[i];
        c[i]/=100;
    }
    const int MSK = 1<<n;
    int res = 1e6;
    for (int msk = 0; msk < MSK; msk++) {
        int sum = 0;
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            if (msk & (1<<i)) {
                sum += p[i]*(i+1) + c[i];
                cnt += p[i];
            }
        }
        if (sum >= g) res = min(res, cnt);
        else {
            for (int i = n-1; i >= 0; i--) {
                if (!(msk & (1<<i))) {
                    for (int j = 0; j < p[i]; j++) {
                        sum += (i+1);
                        cnt += 1;
                        if (sum >= g) res = min(res, cnt);
                    }
                    break;
                }
            }
        }
    }
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 256