akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstring>

using namespace std;

class Dice {
public:
    Dice(int pips[]) {
        for (int i = 0; i < 6; i++) {
            this->pips[i] = pips[i];
        }
    }

    int getTopPip() {
        return pips[0];
    }

    void roll(char direction) {
        memcpy(tmpPips, pips, sizeof(int) * 6);
        if (direction == 'E') {
            pips[0] = tmpPips[3];
            pips[2] = tmpPips[0];
            pips[3] = tmpPips[5];
            pips[5] = tmpPips[2];
        } else if (direction == 'N') {
            pips[0] = tmpPips[1];
            pips[1] = tmpPips[5];
            pips[4] = tmpPips[0];
            pips[5] = tmpPips[4];
        } else if (direction == 'W') {
            pips[0] = tmpPips[2];
            pips[2] = tmpPips[5];
            pips[3] = tmpPips[0];
            pips[5] = tmpPips[3];
        } else {
            pips[0] = tmpPips[4];
            pips[1] = tmpPips[0];
            pips[4] = tmpPips[5];
            pips[5] = tmpPips[1];
        }
    }

private:
    int pips[6];
    int tmpPips[6];
};

int main() {
    int pips[6];
    string directions;

    for (int i = 0; i < 6; i++) {
        cin >> pips[i];
    }
    cin >> directions;

    Dice dice(pips);
    for (int i = 0; i < (int)directions.size(); i++) {
        dice.roll(directions[i]);
    }

    cout << dice.getTopPip() << endl;
    return 0;
}


Measured memory_bytes: 3156
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <deque>

using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define PB push_back
#define SP << " " <<

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;

__attribute__((constructor))
void initial(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed <<setprecision(15);
}


int main(void){
	std::deque<char> S;
    //string S;
    ll Q;
    string s;
    cin >> s;
    rep(i,s.size()){
        S.PB(s[i]);
    }
    
    cin >> Q;
    int  f = 1;
    int T, F;
    char C;
    rep(i,Q){
        //int T;
        cin >> T;
        if(T == 1){
            f *= -1;
            
        }else{
            //int F;
            //char C;
            cin >> F >> C;
            F = (1.0*F-1.5)*2*f;
            if(F > 0){
                S.PB(C); 
                //S = S + C;
            }else{
                S.push_front(C);
                //S = C + S; 
                
            }
        }
    }
    //if(f < 0) reverse(all(S));
    if(f>0){
        rep(i,S.size()){
            cout << S[i];
        }
    }else{
        REP(i,S.size()){
            cout << S[i];
        }
    }
    
    cout << endl;
    //cout << S << endl;
    return 0;
}


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

int main(){
	string s,t;
	cin>>s>>t;
	
	int a=s.size();
	for(int i=0; i<a; i++){
		if(s[i]!=t[i]){
			cout << "No" << endl;
			return 0;
		}
	}
	if(s.size()+1==t.size()) cout << "Yes" << endl;
	else cout << "No" << endl;

}



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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }


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

    int a, b;
    cin >> a >> b;
    cout << (a + b) % 24 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

//for
#define REP(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define REPS(i,n) for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREPS(i,n) for(int i=(int)(n);i>0;i--)

//printf
#define PRINTD(d) printf("%d\n",(d))
#define PRINTS(s) printf("%s\n",(s))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

typedef long long ll;


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

	int x, y, z;
	int flag = 0;
	REP(i, N + 1) {
		x = i;
		y = (Y - 1000 * N - 9000*x) / 4000;
		z = N - x - y;
		if (y < 0 || z < 0)continue;
		if (x + y + z == N && 10000 * x + 5000 * y + 1000 * z == Y) {
			flag = 1;
			break;
		}
	}
	if (flag) {
		printf("%d %d %d\n", x, y, z);
	}
	else {
		printf("-1 -1 -1\n");
	}
}

Measured memory_bytes: 128
/*
 * Author: .-O_O-.
 */
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define rep0(a,b) for(int a=0;a<b;a++)
#define rep1(a,b) for(int a=1;a<=b;a++)
#define repp(a,b,c) for(int a=b;a<c;a++)
#define in insert
#define len length()
#define si size()
#define lb lower_bound
#define ub upper_bound
#define beg begin()
#define en end()
#define f first
#define s second
#define pr(a) cout<<a
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define nx cout<<"\n"
#define int long long
// void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
                                                     
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]"<<endl;}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
const ll mod = 1000000007;
const ll N = 200005;
const ll mm = 1e+18;
void solve()
{
    string s1,s2,s3;
    cin>>s1>>s2>>s3;
    //deb(s1);
    cout<<'A'<<*(s2.begin())<<'C';
}
signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
    //cin>>t;
    rep1(_i,t){
        //cout<<"Case #"<<_i<<": ";
        solve();
        //nx;
    }
    return 0;
}


Measured memory_bytes: 3568
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <stdlib.h>
#include <tuple>
#include <iomanip>
#include <iterator>
#include <stdio.h>
#include <fstream>
#include <time.h>
using namespace std;
const double PI = 3.14159265358979323846;
const long long int MOD = 1000000000 + 7;

struct UnionFind {
    vector<int> parent;

    UnionFind(int N) : parent(N) {
        for (int i = 0; i < N; i++) {
            parent[i] = -1;
        }
    }

    int root(int i) {
        if (parent[i] < 0) {
            return i;
        }
        return (parent[i] = root(parent[i]));
    }

    bool unite(int from, int to) {
        int rx = root(from);
        int ry = root(to);
        if (rx != ry) {
            parent[ry] += parent[rx];
            parent[rx] = ry;

            return true;
        }
        else {
            return false;
        }
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }

    int treeSize(int x) {
        

        return -parent[root(x)];
    }
};

long long int modpow(long long int base, long long int pow, long long int mod) {
    if (pow == 1) {
        return base;
    }
    else if (pow == 0) {
        return 1;
    }

    if (pow % 2 == 0) {
        auto temp = modpow(base, pow / 2, mod);
        return (temp * temp) % mod;
    }
    else {
        return base * modpow(base, pow - 1, mod) % mod;
    }
}

long long int moddiv(long long int X, long long int Y, long long int mod) {
    auto fermatDiv = modpow(Y, mod - 2, mod);

    return (X * fermatDiv) % mod;
}

long long modCombination(long long left, long long right, long long int mod) {
    long long answer = 1;
    for (long long i = 0; i < right; i++) {
        answer = (answer * (left - i)) % mod;
        answer = moddiv(answer, (i + 1), mod);
    }

    return answer;
}

bool IsPrime(long long N) {
    if (N == 1) {
        return false;
    }
    for (long long i = 2; i * i <= N; i++) {
        if (N % i == 0) {
            return false;
        }
    }

    return true;
}



vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // その結果を push
        res.push_back({ a, ex });
    }

    // 最後に残った数について
    if (N != 1) res.push_back({ N, 1 });
    return res;
}

long long euclid(long long a, long long b) {
    if (a > b) {
        long long temp = b;
        b = a;
        a = temp;
    }
    if (b % a == 0) {
        return a;
    }
    else {
        return euclid(a, b - a);
    }
}

int main() {
    long long A, B, V, W, T;
    cin >> A >> V >> B >> W >> T;

    if (abs(B - A) <= T * (V - W)) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
    return 0;
}

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

using namespace std;

int _x;
int _y;
int _ans;

void CParseIn () {
    cin >> _x >> _y;
}

int Calc (int x, int y) {
    if (x <= y) {
        return y - x;
    }
    
    return x - y + 2;
}

void Core () {
    _ans = min(Calc(_x ,_y),min(Calc(-_x,_y)+1,min(Calc(_x,-_y)+1,Calc(-_x,-_y)+2)));
}

void CWriteOut () {
    cout << _ans << endl;
}

int main () {
    
    CParseIn();
    Core();
    CWriteOut();
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define loop2(i, s, n, a) for (int i = int(s); i < int(n); i += a)
#define loop(i, s, n) loop2(i, s, n, 1)
#define rep(i, n) loop(i, 0, n)

#define pb push_back
#define all(in) in.begin(),in.end()

using ll = long long;
using ull = unsigned long long;
using namespace std;

int main(){
    int n; cin >> n;
    int data[n][2]; rep(i,n) rep(j,2) cin >> data[i][j];
    map<pair<int,int>,int> ans1;
    vector<pair<int,int>> ans2;
    rep(i,n){
        rep(j,n){
            if(i == j) continue;
            pair<int,int> pp = {data[i][0]-data[j][0], data[i][1]-data[j][1]};
            ans1[pp]++; ans2.push_back(pp);
        }
    }
    int answer = 0;
    for(auto pp : ans2){
        answer = max(answer, ans1[pp]);
    }
    cout << n - answer << endl;
}

Measured memory_bytes: 3784
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <string>

#include <cmath>
#include <queue>
#include <stack>

using namespace std;

#define LL long long

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

LL mod(LL x, LL md) {
	return ((x % md) + md) % md;
}

class Mint {
public:
	static LL md;
	LL x;
	Mint(LL _x = 0) {
		x = mod(_x, md);
	}
	Mint(const Mint &y) {
		x = mod(y.x, md);
	}
};

void MintMyExgcd(LL a, LL b, LL &x, LL &y) {
	// solve equation ax + by = 1 (mod m)
	LL md = Mint::md;
	if (b == 0) {
		y = 0;
		x = 1;
		return ;
	}
	MintMyExgcd(b, a % b, x, y);
	LL t = y;
	y = mod(x - (a / b) * y, md);
	x = t;
}

LL MintNY(LL x) {
	if (x == 0) {
		return 1;
	}
	LL md = Mint::md;
	LL a, b;
	MintMyExgcd(x, md, a, b);
	while (a < 0) {
		a += md;
	}
	return a;
}

/* LL gcd(LL a, LL b) {
	if (b == 0) {
		return a;
	}
	return gcd(b, a % b);
} */

Mint operator+(Mint a, Mint b) {
	return Mint(mod(a.x + b.x, Mint::md));
}
Mint operator-(Mint a, Mint b) {
	return Mint(mod(a.x - b.x, Mint::md));
}
Mint operator*(Mint a, Mint b) {
	return Mint(mod(a.x * b.x, Mint::md));
}
Mint operator/(Mint a, Mint b) {
	Mint c = Mint(MintNY(b.x));
	return Mint(mod(a.x * c.x, Mint::md));
}

Mint operator-(Mint a) {
	return Mint(-a.x);
}
bool operator==(Mint a, Mint b) {
	return a.x == b.x;
}
bool operator!=(Mint a, Mint b) {
	return a.x != b.x;
}
bool operator>(Mint a, Mint b) {
	return a.x > b.x;
}
bool operator<(Mint a, Mint b) {
	return a.x < b.x;
}
bool operator>=(Mint a, Mint b) {
	return a.x >= b.x;
}
bool operator<=(Mint a, Mint b) {
	return a.x <= b.x;
}

void operator+=(Mint &a, Mint b) {
	a = a + b;
}
void operator-=(Mint &a, Mint b) {
	a = a - b;
}
void operator*=(Mint &a, Mint b) {
	a = a * b;
}
void operator/=(Mint &a, Mint b) {
	a = a / b;
}

ostream& operator<<(ostream &out, Mint a) {
	out << a.x;
	return out;
}

istream& operator>>(istream &in, Mint &a) {
	in >> a.x;
	return in;
}

Mint factorial(LL n) {
	if (n == 0) {
		return Mint(1);
	}
	Mint res = 1;
	for (LL i = 1; i <= n; ++i) {
		res *= i;
	}
	return res;
}
Mint multiRange(LL s, LL t) {
	Mint res = 1;
	for (LL i = s; i <= t; ++i) {
		res *= i;
	}
	return res;
}

Mint getC(LL n, LL k) {
	if (n - k < k) {
		return getC(n, n - k);
	}
	return multiRange(n - k + 1, n) / factorial(k);
}

Mint getA(LL n, LL k) {
	return multiRange(n - k + 1, n);
}

Mint countNonNegativeDivision(LL n, LL k) {
	return getC(n + k - 1, k - 1);
}
Mint countPositiveDivision(LL n, LL k) {
	if (n < k) {
		return 0;
	}
	if (k <= 0) {
		return 0;
	}
	return getC(n - 1, k - 1);
}
Mint quickMod(Mint a, LL b) {
	Mint res = 1;
	while (b > 0) {
		if (b % 2) {
			res *= a;
		}
		a *= a;
		b /= 2;
	}
	return res;
}

LL Mint::md = 1000000007;

string s;
int main() {
	cin >> s;
	string res = "";
	for (int i = 0; i < 3; ++i) {
		res.push_back(s[i]);
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
 
int mark[30], n, a;
 
int main(){


cin.tie(0); 
ios::sync_with_stdio(false);
  cin >> n;
	for (int i = 0; i < n; i++){
		char c;
		cin >> c;
		mark[(c - 'A')]++;
	}	
	for (int i = 0; i < 30; i++)
		a += (mark[i] > 0);
	
	if(a == 3)
		cout << "Three";
	else
		cout << "Four";
  
  	
   }

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define fs first
#define sc second
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main(){
  int n;
  cin>>n; 
  if(n==1){
    cout<<"Yes"<<endl;
    return 0;
  }
  vector<long long>h(n);
  for(int i=0;i<n;i++)cin>>h[i];
  
 
  bool f=true;
  for(int i=0;i<n-1;i++){
    if(h[i+1]-h[i]==-1){
      h[i+1]++;
    }
    else if(h[i+1]-h[i]>-1){
      continue;
    }
    else{
      f=false;
      break;
    }
  }
  if(f)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


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

const int INF = 1e+8;

int main(){
	int n;
	while( cin >> n , n ){
		// d[y][0] := ステージ y を武器なしでクリアするのにかかる時間
		// d[y][x] := ステージ y をすでにステージ x をクリア済み状態でかかる時間
		int d[20][20] = {0};
		
		for(int y=0 ; y < n ; y++ ){
			for(int x=0 ; x < n+1 ; x++ ){
				cin >> d[y][x];
			}
		}
		// s : ステージのクリア状態を表すbit列
		// dp[s] := s のときかかる時間 
		int dp[1<<16];
		// 初期化
		for(int i=0 ; i < (1<<n) ; i++ ){
			dp[i] = INF;
		}
		dp[0] = 0;
		// bitDP 
		for(int s=0 ; s < (1<<n) ; s++ ){
			for(int v=0 ; v < n ; v++ ){
				// ステージ v がすでに訪れているかどうか
				if( (s & (1<<v)) != 0 ) continue;
				
				int min_cost = d[v][0];
				for(int u=0 ; u < n ; u++ ){
					// ステージ u が訪れているとき
					if( (s & (1<<u)) != 0 ){
						min_cost = min( min_cost , d[v][u+1] );
					}
				}
				dp[s|1<<v] = min( dp[s|1<<v] , dp[s] + min_cost );
			}
		}
		cout << dp[(1<<n)-1] << endl;
	}
}

Measured memory_bytes: 1124
process.stdin.resume();
process.stdin.setEncoding('utf8');

var lines = []
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});

reader.on('line', (line) => {
  lines.push(line);
});

reader.on('close', () => {
 var nx = lines[0].split(' ');
 var n = Number(nx[0]);
 var x = Number(nx[1]);
 var x_p = x;
 var i = 0;
 var count = 0;

 var a = lines[1].split(' ');
 a = a.map(function(str) { return Number(str)});
 var sum = a.reduce(function(a, x){return a + x;});

 

 a = a.sort((a, b)=> a - b);
 while(true){
   if(a[i] > x){
     break;
   }
   if(i+1 == n){
     if(a[n] == x){
       count++;
     }else{
       break;
     }
   }
   x = x - a[i];
   count++;
   i++;
   
 }
  
  if(sum == x_p){
   count = n;
 }
  console.log(count);

});

Measured memory_bytes: 11852
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
#define mod 998244353
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pi pair<ll,ll>
#define endl "\n"
using namespace std;
const ll N=500010;

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

    ll a,b,n;
    cin>>a>>b>>n;
    ll x=min(n,b-1);
    ll ans=(a*x)/b;
    ans-=a*(x/b);
    cout<<ans;

    return (0);
}


Measured memory_bytes: 3652
k = int(input())
lunlun = []
def dfs(A):
    if len(A) == 10:
        return
    else:
        start = int(A[-1])
        if start == 9:
            for i in range(start-1, start+1):
                A.append(str(i))
                lunlun.append("".join(A))
                dfs(A)
                A.pop()
        elif start == 0:
            for i in range(start, start+2):
                A.append(str(i))
                lunlun.append("".join(A))
                dfs(A)
                A.pop()
        else:
            for i in range(start-1, start+2):
                A.append(str(i))
                lunlun.append("".join(A))
                dfs(A)
                A.pop()
for j in range(1, 10):
    lunlun.append(str(j))
    dfs([str(j)])
lunlun = list(map(int, lunlun))
lunlun.sort()
print(lunlun[k-1])

Measured memory_bytes: 102604
#include<stdio.h>
int main(void)
{
	int A,B,i;
	int cnt=0;
	int sum=0;
	scanf("%d%d",&A,&B);
	for(i=1;i<100;i++)
	{
		sum=(A-1)*i+1;
		cnt++;
		if(B==1)
		{
			cnt=cnt-1;break;
		}
		else if(sum>=B)
		{
			break;
		}
	}
	printf("%d",cnt);
	return 0;
}


Measured memory_bytes: 128
N, M = map(int, input().split())

class Bridge:
    def __init__(self, nodeA, nodeB):
        self.edges = [BridgeEdge(nodeA), BridgeEdge(nodeB)]

class BridgeEdge:
    def __init__(self, node):
        self.node = node
        self.judge = 0

class Node:
    def __init__(self, id):
        self.id = id
        self.bridges = []
    def addEdge(self, bridgeEdge):
        self.bridges.append(bridgeEdge)


nodes = [Node(i) for i in range(N+1)]
bridges = []
for A, B in (map(int, input().split()) for _ in range(M)):
    b = Bridge(nodes[A], nodes[B])
    nodes[A].addEdge(b.edges[1])
    nodes[B].addEdge(b.edges[0])
    bridges.append(b)


s = [(None, nodes[1], 1)]
idx = 0
while idx < len(s):
    pre, cur, level = s[idx]
    idx += 1

    if level > N * 2:
        break

    for nxt in cur.bridges:
        if not pre is nxt.node and nxt.judge < 2:
            nxt.judge += 1
            s.append((cur, nxt.node, level+1))

cnt = 0
for bd in bridges:
    if sum(1 for b in bd.edges if b.judge <= 1) > 0:
        cnt += 1

print(cnt)


Measured memory_bytes: 3188
import java.util.Scanner

import scala.collection.mutable.ArrayBuffer

object Main {

  case class Edge(u: Int, v: Int, w: Long)

  case class NextInfo(v: Int, w: Long)

  def read() = {
    val sc = new Scanner(System.in)
    val n = sc.nextInt()
    // 0-index化
    val edges = IndexedSeq.fill(n - 1)(
      Edge(sc.nextInt() - 1, sc.nextInt() - 1, sc.nextLong()))
    (n, edges)
  }


  def solve(n: Int, edges: IndexedSeq[Edge]): IndexedSeq[Int] = {
    val nextList = IndexedSeq.fill(n)(ArrayBuffer.empty[NextInfo])
    for (edge <- edges) {
      nextList(edge.u).append(NextInfo(edge.v, edge.w))
      nextList(edge.v).append(NextInfo(edge.u, edge.w))
    }
    val open: java.util.Queue[Int] = new java.util.ArrayDeque[Int]()

    open.add(0)
    val colorList = Array.fill(n)(-1)
    val visited = Array.fill(n)(false)

    // 頂点0を白(0)で塗る
    colorList(0) = 0
    visited(0) = true

    def calcColor(parentColor: Int, dist: Long): Int = {
      val parity = (dist % 2).toInt
      (parentColor + parity) % 2
    }

    while (!open.isEmpty) {
      val current = open.remove()
      for (next <- nextList(current)) {
        if (!visited(next.v)) {
          // 色をつける
          colorList(next.v) = (colorList(current) + (next.w % 2).toInt) % 2
          visited(next.v) = true
          open.add(next.v)
        }
      }
    }
    colorList.toIndexedSeq
  }

  def output(result: IndexedSeq[Int]) = {
    val out = new java.io.PrintWriter(System.out)
    result.foreach(out.println)
    out.flush()
  }

  def main(args: Array[String]): Unit = {
    val (n, edges) = read()
    val result = solve(n, edges)
    output(result)
    // result.foreach(println)
  }
}

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


using namespace std;


// Powered by caide (code generator, tester, and library code inliner)


class Solution {
public:
  void solve(std::istream& in, std::ostream& out)
  {
    int m, nmin, nmax;
    while (in >> m >> nmin >> nmax && m && nmin && nmax) {
      vector<int> p(m);
      for (auto&& i : p) {
        in >> i;
      }
      sort(p.rbegin(), p.rend());
      int maxdist = nmax;
      for(int n = nmax; n >= nmin; n--) {
        if (p[maxdist - 1] - p[maxdist] < p[n - 1] - p[n]) {
          maxdist = n;
        }
      }
      out << maxdist << "\n";
    }
  }
};

void solve(std::istream& in, std::ostream& out)
{
  out << std::setprecision(12);
  Solution solution;
  solution.solve(in, out);
}


#include <fstream>
#include <iostream>


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


  istream& in = cin;


  ostream& out = cout;

  solve(in, out);
  return 0;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9+7;
//const long long MOD = 998244353;
const long long INF_LL = 1e18+11; const int INF_int = 1e9+11;
#define ll long long
#define mp std::make_pair
#define rep(i,n) for(int i = 0;i<n;i++)
#define lrep(i,n) for(long long i = 0;i<n;i++)
#define All(a) a.begin(),a.end()
#define Debug_Output_ALL(a) for(auto x:a) cout << x << " ";cout << endl;
int main(){
    int n;
    cin >> n;
    vector<int> vec(n);
    rep(i,n){
        cin >> vec[i];
    }
    int ans = 0;
    rep(i,n) if(vec[i]%2==1 && i%2==0) ans++;
    cout << ans << endl;
}

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

int main(){
  int s;
  cin >> s;
  vector<int> a(1,s);
  
  int x=0;
  
  while(x==0){
    
    if(s%2==0){
      s/=2;
      a.push_back(s);
    }
    else{
      s*=3;
      s++;
      a.push_back(s);
    }
    
    for(int i=0;i<a.size()-1;i++){
      if(a.at(i)==a.at(a.size()-1))
        x++;
    }
  }
  cout << a.size() << endl;
}

Measured memory_bytes: 256
#include<iostream>//暴力？
using namespace std;

int main()
{
	long long N, h, n, w;
	long long up, down;
	while (cin >> N)
	{
		w = 0;
		for (h = 1; h <= 3500; h++)
		{
			for (n = 1; n <= 3500; n++)
			{
				up = 4 * h*n - N*h - N*n;
				down = N*h*n;
				if (up > 0 && down%up == 0)
				{
					w = down / up;
					cout << h << " " << n << " " << w << endl;
				}
				if (w != 0)
				{
					break;
				}
			}
			if (w != 0)
			{
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 504
#include<bits/stdc++.h>
using namespace std;
 
int main(){
    int N;
    cin >> N ;
     string S;
    cin >> S;   
   int K;
cin >> K;

 
    for(int i = 0 ; i < N ; i++){
        if(S[i] != S[K -1]){
            S[i] = '*';
        }
    }
 
    cout << S ;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

    char[] tap = sc.next().toCharArray();

    // 踏みにくい
    char gu = 'R';
    char ki = 'L';
    for(int i = 0; i < tap.length;i++){
      if((i + 1) % 2 == 0){
        if(tap[i] == gu){
          System.out.println("No");
          return;
        }
      } else {
        if(tap[i] == ki){
          System.out.println("No");
          return;
        }
      }
    }
    System.out.println("Yes");
  }
}


Measured memory_bytes: 23636
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define Ans(f, y, n) if(f) cout << y << endl; else cout << n << endl;
#define int long long
#define INF 1000000000000000000
using namespace std;

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }
template<typename T>
void debug(vector<vector<T>> m){ REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl;} }



signed main(){

    int N; cin >> N;
    int ans = 1, mod = 1000000007;
    FOR(i, 1, N + 1) ans = (ans * i) % mod;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

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

Measured memory_bytes: 572
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#define BIG 2000000007

#define MOD 1000000007
typedef unsigned long long ull;
typedef   signed long long sll;


#define N_MAX 100
#define M_MAX 20

ull n, m, k;
ull h, w;
ull a[N_MAX];
// ull b[M_MAX][N_MAX];
ull dp[N_MAX][M_MAX + 1];
// char s[N_MAX][M_MAX + 1];

void swap_adj(ull *a, ull *b){
	ull tmp = *b;
	*b = *a;
	*a = tmp;
	return;
}

int comp(const void *a, const void *b){
	if (*(ull*)a > *(ull*)b) {
		return -1;
	} else if (*(ull*)a < *(ull*)b) {
		return +1;
	} else {
		return 0;
	}
}

ull divide(ull a, ull b){
	ull x = MOD - 2;
	ull ans = 1;
	while (x) {
		if (x & 1) ans = (ans * b) % MOD;
		b = (b * b) % MOD;
		x /= 2;
	}
	return (a * ans) % MOD;
}

int digits(ull x){
	int i = 1;
	while (x >= 10) {
		x /= 10;
		i++;
	}
	return i;
}

int min(ull x, ull y){
	return (x < y) ? x : y;
}

ull gdb(ull x, ull y){
	if (x < y) {
		return gdb(y, x);
	} else if (y == 0) {
		return x;
	} else {
		return gdb(y, x % y);
	}
}

ull solve(){
	int i, j;
	ull result = 1;

	for (i = 0; i < n; i++) {
		result = (result / gdb(result, a[i])) * a[i];
		// printf("%d %llu\n", i, result);
	}

	return result;
}

int main(void){
	ull i, j;

	scanf("%llu", &n);
	for (i = 0; i < n; i++) scanf("%llu", &a[i]);

	printf("%llu\n", solve());

	return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn=new Scanner(System.in);
		int N=stdIn.nextInt();
		String s="";
		long S[]=new long[5];
		int z=0,y=0,x=0;
		long ans=0;
		while(z<N){
			s=stdIn.next();
			s=s.substring(0,1);
			if(s.equals("M"))
				S[0]++;
			if(s.equals("A"))
				S[1]++;
			if(s.equals("R"))
				S[2]++;
			if(s.equals("C"))
				S[3]++;
			if(s.equals("H"))
				S[4]++;
			z++;
		}z=0;
		while(z<3){
			y=z+1;
			while(y<4){
				x=y+1;
				while(x<5){
					ans+=S[z]*S[y]*S[x];
					x++;
				}
				x=0;y++;
			}
			y=0;z++;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 46280
//package atcoder;

import java.util.*;

public class Main {

    public static void main(String[] args) {
        final Scanner in = new Scanner(System.in);
        final int N = in.nextInt();
        final int[] A = new int[N + 1];
        final Set<Integer> idx = new HashSet<>(N);
        final Map<Integer, List<Integer>> As = new HashMap<>(N);
        int max = Integer.MIN_VALUE;
        for (int i = 1; i <= N; ++i) {
            A[i] = in.nextInt();
            max = Math.max(max, A[i]);
            if (!As.containsKey(A[i])) {
                As.put(A[i], new ArrayList<>());
            }
            As.get(A[i]).add(i);
            idx.add(i);
        }

        int i = 1;
        while (i <= N && !idx.isEmpty()) {
            int value = A[i];
            while (value <= max) {
                if (As.containsKey(value)) {
                    for (int j : As.get(value)) {
                        if (j != i) {
                            idx.remove(j);
                        }
                    }
                }
                value += A[i];
            }
            ++i;
        }

        System.out.println(idx.size());
    }
}


Measured memory_bytes: 113196
#include <bits/stdc++.h>
using namespace std;
#define fst ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endk cout<<"\n";
typedef long long int ll;
typedef long int l;
#define l(i,a,b) for(i=a;i<b;i++)
#define lo(i,a,b) for(i=a;i>=b;i--)
#define s(v) sort(v.begin(),v.end());
#define pb push_back;
#define vll vector<ll>
#define vint vector<int>
#define test() ll t;cin>>t;while(t--){solve();};
#define test1() int t=1;while(t--){solve();};
bool isPrime(ll x)
{
    ll i,n;
    n=sqrt(x);
    if(x==1) return false;
    if(x==2 || x==3) return true;
    for(i=2;i<=n;i++)
    {
        if(!(x%i)) return false;
    }
    return true;
}
ll power(ll x,ll y)
{
	ll ans=1;
	while(y>0)
	{
		if(y&1) ans=ans*x;
		x=x*x;
		y=y>>1;
	}
	return ans;
}
int solve()
{
    int n,i,cnt=0;
    cin>>n;
    vint a(n),b(n);
    for(i=0;i<n;i++)
    {
        cin>>a[i]>>b[i];
        if(a[i]==b[i])
        {  
            cnt++;
            if(cnt==3)
            {
                cout<<"Yes";
                return 0;
            }
        }
        else
        {
            cnt=0;   
        }
    }
    cout<<"No";
    return 0;
}
int main()
{
    fst;
    test1();
    return 0;
}


Measured memory_bytes: 3660
#include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
    int a,b,k,minn,maxx;
    int num[101];
    int cnt = 0;
    cin>>a>>b>>k;
    minn = min(a+k-1,b);
    maxx = max(b-k+1,a+k);
    for(int i=a; i<=minn; i++)
    {
        cout<<i<<endl;
    }
    for(int i=b; i>=maxx; i--)
    {
        num[cnt++] = i;
    }
    sort(num,num+cnt);
    for(int i=0; i<cnt; i++)
        cout<<num[i]<<endl;
    return 0;
}


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

using namespace std;
using ll = long long;
using edge = struct {int to; ll cost;};

#define mod 1000000007
#define REP(i, n) for (int i = 0; i < n; i++)
#define INF (1 << 29)


//long C(long n, long r);
//long long gcd(long long a, long long b);
//long long lcm(long long a, long long b);

void solve()
{
    int n;
    cin >> n;
    int ans = 0;
    int label = 1;
    int index = 1;
    for(int i = 1; i <= n; i++){
        int a;
        cin >> a;
        if(a == label) {
            ans += i - index;
            index = i+1;
            label++;
        }
    }
    ans += n+1-index;
    if(label == 1) {
        cout << -1 << "\n";
    }
    else{
        cout << ans << "\n";
    }
}

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

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: i32,
        k: i32,
    }
    let ans = k*i32::pow(k-1, (n-1) as u32);
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    const VEC(string) V {"Sunny", "Cloudy", "Rainy"}; 
    string s;
    cin >> s;
    int i = 0;
    while (V[i] != s)
        i++;
    cout << V[(i + 1) % 3] << endl;
    return 0;
};


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define moder (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % moder;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	return kai(x)* mod_pow(kai(x - y), moder - 2, moder) % moder * mod_pow(kai(y), moder - 2, moder) % moder;
}
/*--------Library Zone!--------*/

int n, k;
P p[114514];
multiset<int>st;
set<int>st2;
int neta, deli, ans;
signed main() {
	cin >> n >> k;
	priority_queue<P, vector<P>, greater<P>>que1;
	priority_queue<P>que2;
	rep(i, n) {
		cin >> p[i].second >> p[i].first;
	}
	sort(p, p + n, greater<>());
	rep(i, k) {
		que1.push({ p[i].first,i });
		st.insert(p[i].second);
		st2.insert(p[i].second);
		deli += p[i].first;
	}
	neta = st2.size();
	ans = neta * neta + deli;
	for (int i = k; i < n; i++) {
		que2.push({ p[i].first,i });
	}
	while (que1.size() && que2.size()) {
		P a, b;
		while (que1.size()) {
			P a_ = que1.top(); que1.pop();
			if (st.count(p[a_.second].second) != 1) {
				a = a_;
				goto ok;
			}
		}
		break;
	ok:;
		while (que2.size()) {
			P b_ = que2.top(); que2.pop();
			if (st.find(p[b_.second].second) == st.end()) {
				b = b_;
				goto ok2;
			}
		}
		break;
	ok2:;
		int new_deli = deli - a.first + b.first;
		int new_neta = neta + 1;
		deli = new_deli;
		neta = new_neta;
		ans = max(ans, deli + neta * neta);
		st.erase(st.find(p[a.second].second));
		st.insert(p[b.second].second);
		que1.push(b);
	}
	cout << ans << endl;
}


Measured memory_bytes: 11248
H = int(input())
 
# 体力がHのモンスター1体に勝つために必要な攻撃回数をf(H)とする
# すると、f(H)は以下の漸化式に従って求まる
# f(H)=2*f(floor(H/2)+1) (H>1)
# f(H)=1 (H=1)

def attack_num(x):
  if x == 1: return 1
  else: return 2*attack_num(x // 2) + 1
  
print(attack_num(H))

Measured memory_bytes: 9056
#include<bits/stdc++.h>
using namespace std;
char p[30000005];int ans=0x3f3f3f3f;
int main()
{
	scanf("%s",&p);
	int ch=strlen(p);
	for(register int i=0;i<ch;i++)
		if(p[i]!=p[i+1])
			ans=min(ans,max(i+1,(int)strlen(p)-i-1));
	if(ans==0x3f3f3f3f)  printf("%d",(int)strlen(p));
	else printf("%d",ans);
	return 0;
}

Measured memory_bytes: 384
N = int(input())
A = list(map(int, input().split()))

ans = [0] * N
ans[0] = sum(A[0::2]) - sum(A[1::2])

for i in range(1,N):
    ans[i] = (A[i-1]  * 2) - ans[i-1]
    
print(" ".join(map(str, ans)))

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

typedef long long ll;
typedef unsigned long long ull;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout.precision(12);
    cout.setf(ios_base::fixed, ios_base::floatfield);
    
    while(true){
        int n, m;
        cin >> n >> m;
        if(n == 0 && m == 0) break;
        ull state = 0;
        for(int i=0;i<3;i++){
            int q;
            cin >> q;
            for(int j=0;j<q;j++){
                int a;
                cin >> a;
                state |= ((ull)(i+1))<<(a*2);
            }
        }
        queue<pair<unsigned int, int>> Q;
        unordered_set<unsigned int> checked;
        Q.push({state, 0});
        checked.insert(state);
        while(!Q.empty()){
            unsigned int top = Q.front().first;
            int cost = Q.front().second;
            Q.pop();
            if(cost > m){
                cout << -1 << endl;
                goto next;
            }
            int cnt[3] = {0}, mx[3] = {0};
            for(int i=1;i<=n;i++){
                int pos = (top >> (2*i))&3;
                cnt[pos-1]++;
                mx[pos-1] = max(mx[pos-1], i);
            }
            if(cnt[1]==0 && (cnt[0]==0 || cnt[2]==0)){
                cout << cost << endl;
                goto next;
            }
            if(mx[0]>mx[1] && checked.count(top^(3LL<<(mx[0]*2)))==0){
                Q.push({top^(3LL<<(mx[0]*2)), cost+1});
                checked.insert(top^(3LL<<(mx[0]*2)));
            }
            if(mx[2]>mx[1] && checked.count(top^(1LL<<(mx[2]*2)))==0){
                Q.push({top^(1LL<<(mx[2]*2)), cost+1});
                checked.insert(top^(1LL<<(mx[2]*2)));
            }
            if(mx[1]>mx[0] && checked.count(top^(3LL<<(mx[1]*2)))==0){
                Q.push({top^(3LL<<(mx[1]*2)), cost+1});
                checked.insert(top^(3LL<<(mx[1]*2)));
            }
            if(mx[1]>mx[2] && checked.count(top^(1LL<<(mx[1]*2)))==0){
                Q.push({top^(1LL<<(mx[1]*2)), cost+1});
                checked.insert(top^(1LL<<(mx[1]*2)));
            }
        }
        cout << -1 << endl;
        next: ;
    }
    
    return 0;
}


Measured memory_bytes: 121164
#include <bits/stdc++.h>
#include <cctype>
#include <cmath>
#include <string>
using namespace std;
int main(){
    int N;
    int max = 0;
    cin >> N;
    vector<int> numbers(N);
    for(int i = 0;i < N;i ++){
        cin >> numbers.at(i);
        max += numbers.at(i) - 1;  
    }
    cout << max << endl;
    
}

Measured memory_bytes: 256
def GCD_cal(a,b):
	if(b==0):
		return(a)
	a,b=b,a%b
	return(GCD_cal(a,b))

while(True):
	try:
		a,b=map(int,input().split(" "))
	except:
		break
	if(a<b):
		a,b=b,a
	GCD=GCD_cal(a,b)
	LCM=int(a*b/GCD)
	print("{0} {1}".format(GCD,LCM))

Measured memory_bytes: 6728
import java.util.*;
public class Main{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		for(int i = 0;i<m;i++)
		{
			int temp = sc.nextInt();
			n -=temp;
		}
		if(n<0)
		{
			System.out.println(-1);
		}
		else
			System.out.println(n);
	}
}

Measured memory_bytes: 46112
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
#include <string>
#include <bitset>
#include <tuple>
#include <cmath>
#include <map>

template<typename T> bool chmax( T &a, const T &b ) { if ( a <= b ) { a = b; return ( true ); } else { return ( false ); } }
template<typename T> bool chmin( T &a, const T &b ) { if ( a >= b ) { a = b; return ( true ); } else { return ( false ); } }

using namespace std;

using ll = long long;
using ull = unsigned long long;

using Pll  = pair<ll, ll>;
using Pull = pair<ull, ull>;

#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple

#define F first
#define S second

#define rep( i, n ) for ( int i = 0; i < (int)( n ); ++i )
#define reps( i, n ) for ( int i = 1; i <= (int)( n ); ++i )
#define rrep( i, n ) for ( int i = (int)( ( n ) - 1 ); i >= 0; --i )
#define rreps( i, n ) for ( int i = (int)( ( n ) ); i > 0; --i )
#define arep( i, v ) for ( auto &&i : ( v ) )

template<typename T> T gcd( const T a, const T b ) { return ( b ? gcd( b, a % b ) : a ); }

#define ALL( c ) ( c ).begin(), ( c ).end()
#define RALL( c ) ( c ).rbegin(), ( c ).rend()
#define UNIQUE( c ) ( c ).erase( unique( ( c ).begin(), ( c ).end() ), ( c ).end() )

constexpr ll MOD = 1000000007LL;

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev

template<typename T = ll> class UnionFind {
public:
	UnionFind( T n ) { rep( i, n ) { par.resize( n ); siz.resize( n ); par[i] = i; siz[i] = 1; } }
	T find( T x ) { if ( x == par[x] ) return ( x ); else return( par[x] = find( par[x] ) ); }
	void unite( T x, T y ) { T xx = find( x ); T yy = find( y ); if ( xx == yy ) return;
		if ( siz[xx] <= siz[yy] ) swap( xx, yy ); par[yy] = xx; siz[xx] += siz[yy]; }
private:
	vector<T> par, siz;
};

template<typename T = ll> T power( T a, T b, T m = MOD ) {
	T res = 1;
	while ( b > 0 ) { if ( b & 1 ) res = res * a % m;
		a = a * a % m; b >>= 1; }
	return ( res );
}

/*
constexpr ll MAX = 500010;
ll fact[MAX];
ll inv[MAX];
ll inv_fact[MAX];

template<typename T> void initComb( T n, T m = MOD )
{
	fact[0] = fact[1] = inv_fact[0] = inv_fact[1] = 1;
	inv[1] = 1;
	for ( int i = 2; i < n; i++ ) {
		fact[i] = ( fact[i - 1] * i ) % m;
		inv[i] = m - inv[m % i] * ( m / i ) % m;
		inv_fact[i] = inv_fact[i - 1] * inv[i] % m;
	}
}

template<typename T> T comb( T n, T r, T m = MOD )
{
	if ( n < r ) return ( 0 );
	if ( n < 0 || r < 0 ) return ( 0 );
	return ( fact[n] * ( inv_fact[r] * inv_fact[n - r] % m ) % m );
}
*/

void replace( string &s, string t, string r ) {
	string::size_type p = 0;
	while ( ( p = s.find( t, p ) ) != string::npos ) {
		s.replace( p, t.length(), r );
		p += r.length();
	}
}


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

	vector<int> v( N );
	rep( i, N ) cin >> v[i];

	vector<int> vv( N + 1 );
	vv[0] = 0;
	rep( i, N ) vv[i + 1] = vv[i] + v[i];

	int res = 0;
	for ( res = 0; ( vv[res] <= X ) && ( res <= N ); res++ )
	{
	}
	cout << res << endl;

	return ( 0 );
}


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

a_list = []
xy_list = []
ans = 0

for i in range(n):
    a = int(input())
    a_list.append(a)
    xy_list.append([list(map(int, input().split())) for _ in range(a)])

for i in range(2**n):
    h = [0]*n
    flag = True
    for j in range(n):
        if (i >> j) & 1:
            h[j] = 1
    for j in range(n):
        if h[j] == 1:
            a = a_list[j]
            xy = xy_list[j]
            for k in range(a):
                l = xy[k]
                x = l[0]
                y = l[1]
                if h[x-1] != y:
                    flag = False
                    break
            if not flag:
                break
    if flag:
        ans = max(sum(h), ans)

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
   long long A,V,B,W,T;
   cin>>A>>V>>B>>W>>T;
long long k=abs(A-B);
if(k<=(V-W)*T){
    cout<<"YES"<<endl;
}
else
cout<<"NO"<<endl;
}


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

typedef pair<int,int> P;
const int POINT = 600002;
const int MAX = 200000;
struct Edge{int to;int cost;};
bool vis[POINT];
void Dijk(vector<Edge> G[],int n,int s,long long res[POINT]){
	fill(res,res+n,0);
	fill(vis,vis+n,false);
	priority_queue<P,vector<P>,greater<P>> que;
	P p;
	vis[s]=true;
	res[s]=0;
	que.push(P(0,s));
	while(!que.empty()){
		p = que.top();
		que.pop();
		for(Edge e:G[p.second]){
			if(!vis[e.to] || res[e.to]>res[p.second]+e.cost){
				vis[e.to]=true;
				res[e.to]=res[p.second]+e.cost;
				que.push(P(res[e.to],e.to));
			}
		}
	}
}
int main(){
	int N,A[MAX];
	long long ans[POINT];
	vector<Edge> G[POINT];
	cin>>N;
	for(int i=0;i<N;i++)cin>>A[i];
	for(int i=0;i<N;i++){
		for(int j=0;j<3;j++){
			for(int k=0;k<=min(j,N-i-3);k++){
				G[i+j*N].push_back({i+k+2+(j-k)*N,-A[i+k+2]});
			}
		}
	}
	if(N%2)for(int i=0;i<3;i++)G[3*N].push_back({2-i+i*N,-A[2-i]});
	else for(int i=0;i<2;i++)G[3*N].push_back({1-i+i*N,-A[1-i]});
	
	for(int i=0;i<3;i++){
		for(int j=0;j<=i;j++){
			G[N-1-j+i*N].push_back({3*N+1,0});
		}
	}
	
	Dijk(G,3*N+1,3*N,ans);
	
	cout<<-ans[3*N+1];
	return 0;
}

Measured memory_bytes: 45528
import java.util.Scanner;

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

			int n = sc.nextInt();
			long k = sc.nextLong();

			int[] to = new int[n+1];

			for(int i = 1 ; i <= n ; i++ ) {
				to[i] = sc.nextInt();
			}

			long[] latestStep = new long[n+1];

			long j = 0;
			int position = 1;
			boolean calcSkip = true;

			while( j < k ) {

//				System.out.println(j + ":" + position);

				// check this city is already visited?
				if ( calcSkip && latestStep[position] > 0 ) {
					long latest = latestStep[position];
					long step = j - latest;

					long rest = k - j;
					long count = rest / step;

					j+= count * step;

					calcSkip = false;
				}
				else {
					//record current
					latestStep[position] = j;

					//transfer
					position = to[position];

					j++;
				}
			}

			System.out.println(position);

		}
	}


}

Measured memory_bytes: 60020