akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES

#include <iostream>
#include <cstdio>
#include <memory>
#include <string>
#include <cstdlib>
#include <set>
#include <utility>
#include <vector>
#include <list>
#include <forward_list>
#include <algorithm>
#include <regex>
#include <cmath>
#include <map>
#include <iterator>
#include <climits>
#include <numeric>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <array>
#include <valarray>
#include <complex>
#include <random>
#include <functional>
#include <cassert>
#include <chrono>
#include <memory>

using namespace std;

#define int long long
//region TEMPLATE
////@formatter:off
#define double long double
typedef long long ll;
typedef unsigned long long ull;
template<typename T>void __read(T &a) { cin >> a; }
template<typename T, typename ... Args> void __read(T &a, Args &... args) { cin >> a;__read(args...);}
#define make(t, ...) t __VA_ARGS__; __read(__VA_ARGS__)
#define makev(a, n) VI a(n); FOR(n) cin >> a[i]
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define FORIT(p) for(auto it = p.begin(); it != p.end(); it++)
#define FOR(b) for(signed i = 0; i <(b); i++)
#define FORE(i, l, r) for(int i = (l); i < (r); i++)
#define NFOR(i, n) for(int i = (((int) n)-1); i >= 0; i--)
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef pair<pair<int, int>, int> PPII;
constexpr ll M7 = 1000000007ll;
constexpr ll M9 = 1000000009ll;
constexpr ll MFFT = 998244353ll;
template<class T> void outv(T &a) { for (auto &x : a) cout << x << ' '; }
static mt19937 rnd(static_cast<unsigned>(chrono::steady_clock::now().time_since_epoch().count())); // NOLINT(cert-err58-cpp)
auto __fast_io__ = (ios_base::sync_with_stdio(false), cin.tie(nullptr)); // NOLINT(cert-err58-cpp,cppcoreguidelines-interfaces-global-init)
////@formatter:on
//endregion


int32_t main() {
    make(int, a, b, c, d);
    VVI dp(c + 1, VI(d + 1));
    dp[a][b] = 1;
    for (int i = a; i <= c; ++i) {
        for (int j = b; j <= d; ++j) {
            if (i == a && j == b) {
                continue;
            }
            if (i == a) {
                dp[i][j] = dp[i][j - 1] * i % MFFT;
            } else if (j == b) {
                dp[i][j] = dp[i - 1][j] * j % MFFT;
            } else {
                dp[i][j] = (dp[i][j - 1] * i + dp[i - 1][j] * j - dp[i - 1][j - 1] * (i - 1) * (j - 1) % MFFT + MFFT) %
                           MFFT;
            }
        }
    }
    cout << dp[c][d];
    return 0;
}

Measured memory_bytes: 73652
#include <iostream>
#include <string>
using namespace std;

const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main()
{
  string s;
  while (getline(cin, s)) {

    for (int i = 0; i < 26; ++i) {
      for (unsigned int j = 0; j < s.size(); ++j) {
	if (isalpha(s[j]))
	  s[j] = alpha[(s[j]-'a'+1)%alpha.size()];
      }
      if (s.find("the", 0) != string::npos ||
	  s.find("this", 0) != string::npos ||
	  s.find("that", 0) != string::npos)
	break;
    }

    cout << s << endl;

  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

void warshall_floyd(int n, vector<vector<ll>>& dist) {
  rep(i, n) rep(j, n) rep(k, n) {
    dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<string> S(N);
  rep(i, N) cin >> S[i];
  vector<vector<ll>> dist(N, vector<ll>(N, longinf));
  rep(i, N) {
    dist[i][i] = 0;
    REP(j, i+1, N) {
      if(S[i][j] == '1') {
        dist[i][j] = dist[j][i] = 1;
      }
    }
  }
  warshall_floyd(N, dist);
  vector<int> parity(N, -1);
  parity[0] = 0;
  bool ok = true;
  rep(i, N) rep(j, N) {
    if(parity[j] == -1) {
      parity[j] = (parity[i] + dist[i][j]) % 2;
    } else {
      if(parity[j] != (parity[i] + dist[i][j]) % 2) ok = false;
    }
  }
  if(ok) {
    ll mx = 0;
    rep(i, N) mx = max(*max_element(all(dist[i])), mx);
    cout << mx+1 << "\n";
  } else {
    cout << -1 << "\n";
  }
  return 0;
}


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

int main() {
    ll n, a, b;
    cin >> n >> a >> b;
    if (a + b > n + 1 || a * b < n) {
        cout << -1 << endl;
        return 0;
    }

    vector<ll> ans;
    for (ll i = b; i > 0; i--) {
        ans.push_back(i);
    }
    if (a != 1) {
        ll k = (n - b) / (a - 1);
        ll p = (n - b) % (a - 1);
        ll q = a - 1 - p;
        rep(i, p) {
            ll cursz = ans.size();
            rep(j, k + 1) {
                ans.push_back(cursz + k + 1 - j);
            }
        }
        rep(i, q) {
            ll cursz = ans.size();
            rep(j, k) {
                ans.push_back(cursz + k - j);
            }
        }
    }
    rep(i, ans.size()) {
        cout << ans[i] << (i == ans.size() - 1 ? "\n" : " ");
    }
}

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

int main(){
  int n,sum=0;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++){
    cin>>a[i];
    sum+=a[i];
    a[i]*=n;
  }
  int ans=0;
  for(int i=0;i<n;i++){
    if(abs(a[ans]-sum)>abs(a[i]-sum)) ans=i;
  }
  cout<<ans<<endl;
}


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

bool valid(int a,int b,int c) {
  int v[3] = {a, b, c};
  sort(v, v + 3);
  return v[2] < v[1] + v[0];
}

int main () {
  int n;
  scanf("%d", &n);
  int L[n];
  for (int i = 0; i < n; ++i) scanf("%d", &L[i]);
  int cnt = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      for (int k = j + 1; k < n; ++k) {
        set<int> s;
        s.insert(L[i]);
        s.insert(L[j]);
        s.insert(L[k]);
        if (s.size() == 3) cnt += valid(L[i], L[j], L[k]);
      }
    }
  }
  printf("%d", cnt);
  return 0;
}

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

#define rep(i,n) for( (i)=0;(i)<(n);++(i) )
#define repr(i,n) for( (i)=(n);(i)>0;==(i) )
#define FOR(i,j,n) for( (i)=(j);(i)<(n);++(i) )
#define forr(i,j,n) for( (i)=(j);(i)>(n);--(i) )
#define debg(a) cout<<(a)<<endl;
#define INF 9999999
#define int long long 
#define str string
#define elif else if

int i,j,k;
int dx,dy;
int a,b,c,x,y,n,m,cnt=0,ans=0;
str s,t;

signed main(){ 
  int l;
  cin>>n>>l;
  str s[n];
  rep(i,n)cin>>s[i];
  sort(s,s+n);
  str ans="";
  rep(i,n)ans+=s[i];
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,add=0,sub=0,mul=0;
	scanf("%d %d",&a,&b);
	add=a+b;
	sub=a-b;
	mul=a*b;
	printf("%d",max(max(add,sub),mul));
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
 int n,i,j,k;
  cin>>n;
  long int a[n];
  long long int dp[n]={0};
  for(i=0;i<n;i++)
  {
   	cin>>a[i]; 
  }
  i=0;
  dp[0]=0;
  dp[1]=abs(a[0]-a[1]);
  for(i=2;i<n;i++)
  {
  	dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2] + abs(a[i]-a[i-2]));           
  }
  cout<<dp[n-1];
}	

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main()
{
    FASTINOUT;
    int x;
    cin>>x;
    if (x%2==0)
        cout<<-1<<endl;
    else
    {
        ll c=0,cn=0;
        while (c<x){
            c=c*10+7;
            cn++;
        }
        int cnt=1e6+10,sum=0;
        sum=c%x;
        //cout<<sum<<endl;
        for (int i=cn; cnt>0; i++,cnt--)
        {
            if (!sum)
            {
                cout<<i<<endl;
                return 0;
            }
            sum=(sum*10+7)%x;
        }
        cout<<-1;
    }
    return 0;
}


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

int main()
{
  int h , n ; 
  cin >> h >> n ; 
  int sum = 0 , nn ;
  for(int i = 0 ; i < n ; i++)
  {
    cin >> nn ; 
    sum += nn ;
  }
  
  if ( sum >= h )
  {
    	cout << "Yes";
  }else{
    cout << "No";
  }
  return 0;
}


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

#define pb push_back
#define F first
#define S second
#define y1 dasdasfasfas
#define x1 wqdadfasfasfas
#define All(c) c.begin(), c.end()
#define SZ(A) (int((A).size()))
#define umap unordered_map
#define __ fflush(stdout)
#define FILENAME ""

typedef long long ll;
typedef long double ld;    

using namespace std;

void FREOPEN() {
	#ifdef LOCAL
		freopen(".in", "r", stdin);
		freopen("1.out", "w", stdout);
	#else
		//freopen(FILENAME".in", "r", stdin);
		//freopen(FILENAME".out", "w", stdout);
	#endif
}

inline double Time() {return (clock() * 1.0) / CLOCKS_PER_SEC; }             

const int N = 20500, inf = 1e9 * 2;

const ll MOD = 1e9 + 7ll, INF = 1e18;

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

ll dp[N];

int w[N], s[N], v[N];

int main() {
	FREOPEN();
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) 
		scanf("%d %d %d", &w[i], &s[i], &v[i]);
	for (int i = 1; i <= n; i++) {
		for (int j = i + 1; j <= n; j++) {
			if (w[i] + s[i] > w[j] + s[j]) {
				swap(w[i], w[j]), swap(s[i], s[j]), swap(v[i], v[j]);
			}
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = s[i]; j >= 0; j--) {
			dp[j + w[i]] = max(dp[j + w[i]], dp[j] + v[i]);
 		}
	}
	ll ans = 0;
	for (int i = 0; i < N; i++) ans = max(ans, dp[i]);
	printf("%lld", ans);
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std; 
int main(){
	string S; cin >> S; 
	string T = {}; 
	vector<int> X = {}; 
	int count = 0; 
	for(int i = 0; i < S.size(); i++){
		if(S.at(i) != 'x'){
			T.push_back(S.at(i)); X.push_back(count); 
			count = 0; 
		}
		else{
			count ++; 
		}		
	}
	X.push_back(count); 
	string U; 
	U = T; 
	reverse(U.begin(), U.end());
	if(T != U) cout << -1 << endl; 
	else{
		int K = X.size(); 
		int ans = 0; 
		for(int i = 0; i < K/2; i++){
			ans += abs(X[i] - X[K-1-i]); 
		}
		cout << ans << endl; 
	}
}

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

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n)  FOR(i, 0, n)
#define ASC(c) sort((c).begin(), (c).end())
#define DESC(c) sort((c).begin(), (c).end(), greater<int>())

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

typedef long long ll;
typedef unsigned long long ull;
struct edge { int u, v; ll w; };
 
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
    int a1, a2, a3; cin >> a1 >> a2 >> a3;
    if (a1 + a2 + a3 >= 22) cout << "bust" << endl;
    else cout << "win" << endl;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int main() {
	int n, ans, x, y, i;
	scanf("%d", &n);
	x = 800 * n;
	y = 0;
	for (i = 1; i <= n; i++) {
		if (i % 15 == 0) {
			y++;
		}
	}
	y *= 200;
	printf("%d", x - y);
}

Measured memory_bytes: 128
#define SUBMIT

#include <bits/stdc++.h>

using namespace std;

int main() {
#ifdef SUBMIT
    auto& in = cin;
#else
    stringstream in(R"(3 2 1
)");
#endif
    int a, b, c;
    in >> a >> b >> c;
    auto ans = (b - a == c - b) ? "YES" : "NO";
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
//import std.regex;
import std.container;

void main()
{
	int n;
	while (n = readln.chomp.to!int, n) {
		auto tbl = new int[][](n+1, n);
		foreach (i; 0..n) {
			auto x = readln.split.map!(to!int).array;
			x ~= x.reduce!("a+b");
			foreach (j; 0..n+1) {
				writef("%5d", x[j]);
				tbl[j][i] = x[j];
			}
			writeln("");
		}
		foreach (i; 0..n+1) {
			writef("%5d", tbl[i].reduce!("a+b"));
		}
		writeln("");
	}
}

Measured memory_bytes: 1092
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

#define INF 1e9
#define MAXN 100005
#define MAXM 100005
#define MOD 1000000007
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pii pair<int, int>

ll ans;
string S, T;
bool flag = true;

void solve(){
    rep(i, S.size()){
        if(S[i]!=T[i]){
            flag = false;
            break;
        }
    }

    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}

int main(){
    cin >> S >> T;

    solve();
}


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

vector<vector<int>> G;
vector<int> C;

void dfs(vector<int> &scores, vector<bool> &visited, int u, int &cnt) {
    scores[u] = C[cnt++];
    visited[u] = true;
    for (int v : G[u]) {
        if (visited[v]) continue;
        dfs(scores, visited, v, cnt);
    }
}

int main() {
    int N;
    cin >> N;
    G.resize(N);
    C.resize(N);
    for (int i = 0; i < N - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    for (int i = 0; i < N; i++) cin >> C[i];
    sort(C.begin(), C.end(), greater<int>());
    int res = 0;
    for (int i = 1; i < N; i++) res += C[i];
    cout << res << endl;

    int cnt = 0;
    vector<int> scores(N, 0);
    vector<bool> visited(N, false);
    dfs(scores, visited, 0, cnt);

    for (int i = 0; i < N; i++) {
        cout << scores[i] << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 1536
using System;
using System.Linq;
 
class Program
{
	static void Main()
    {
     	int K = int.Parse(Console.ReadLine());
      	int[] A = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
      	
      	for (int i = A[0]; i <= A[1]; i++) {
			if(i % K == 0){
            	Console.WriteLine("OK");
              	return;
            }
        }
      	Console.WriteLine("NG");
    }
}

Measured memory_bytes: 28288
#include<iostream>
#include<cstdio>
#include <cstring>
#include<map>
#include<string>
using namespace std;

int main(void){
	string a;
	while(1)
	{
		cin>>a;
		if(a=="0")break;
		a[0]='z';
		string::iterator str = a.begin();
		int A=0,B=0;
		for( str = a.begin(); str != a.end(); ++str )
		{
			if( 'A' == *str ) ++A;
			if( 'B' == *str ) ++B; 
		}
		if(A<B) ++B;
		else ++A;
		cout<<A<<" "<<B<<endl;
		a.clear();
	}
	return 0;
}

Measured memory_bytes: 1180
n, k = gets.split.map(&:to_i)
e = (n - 2) * (n - 1) / 2
if k > e
  puts -1
  exit
end
ans = Array.new
(n - 1).times do |i|
  ans.push([i + 1, n])
end
a, b = 1, 2
while e != k
  ans.push([a,b])
  if b == n - 1
    a += 1
    b = a + 1
  else
    b += 1
  end
  e -= 1
end
puts ans.length
ans.each {|t| puts t.join(" ")}

Measured memory_bytes: 2300
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include<functional>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <typeinfo>
#define PI 3.14159265359
#define INF 99999999;
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(n) rep(i, n)
#define EPS 1e-10
typedef long long ll;
using namespace std;



/*
class Target
{
public:
	vector <string> draw(int n)
	{

	}
};
*/



int main()
{
	int sum, price;
	
	while (cin >> sum, sum)
	{
		REP(9)
		{
			cin >> price;
			sum -= price;
		}
		cout << sum << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll MOD = 1000000007;
ll dp[10000];
int main() {
  ll N;
  cin >> N;
  dp[0] = 1;
  REP(i, N) {
    for (int j = 3; j <= N; j++) {
      dp[i + j] += dp[i];
      dp[i + j] %= MOD;
    }
  }
  cout << dp[N] << endl;
}

Measured memory_bytes: 3672
#include<bits/stdc++.h>
using namespace std;
const int maxn = 100111;
vector<int> g[maxn];
int dist[maxn][3];
bool inque[maxn][3];
queue<int> q[3];
int spfa_ex(int s,int t)
{
    memset(dist,0x7f,sizeof dist);
    memset(inque,0,sizeof inque);
    dist[s][0] = 0;
    inque[s][0] = 1;
    q[0].push(s);
    while(!(q[0].empty() && q[1].empty() && q[2].empty()))
    {
        for(int k=0;k<3;++k)
        {
            if(q[k].empty())continue;
            int u = q[k].front();
            q[k].pop();
            for(int i=0;i<g[u].size();++i)
            {
                if(dist[u][k] + 1 < dist[g[u][i]][(k+1)%3])
                {
                    dist[g[u][i]][(k+1)%3] = dist[u][k] + 1;
                    if(!inque[g[u][i]][(k+1)%3])
                    {
                        inque[g[u][i]][(k+1)%3] = 1;
                        q[(k+1)%3].push(g[u][i]);
                    }
                }
            }
            inque[u][k] = 0;
        }
    }
    if(dist[t][0] == 0x7f7f7f7f)
        return -1;
    return dist[t][0]/3;
}
int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;++i)
    {
        int u,v;
        cin>>u>>v;
        g[u].push_back(v);
    }
    int s,t;
    cin>>s>>t;
    cout<<spfa_ex(s,t)<<endl;
}

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

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair


ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }


void solve(int N) {
    vector<int> a;
    a.reserve(N+4);
    if (N < 6) {
        a = vector<int> {2,5,63};
        int S = accumulate(ALL(a), 0);
        // a = vector<int> {2,5,20,63};
        // a = vector<int> {2,5,20,30,63};
        for (int i=4; i<=N; ++i) {
            a.pb(0);
            for (int x=3; x<=30000; ++x) {
                if (find(ALL(a), x) != a.end()) continue;
                a[i-1] = x;
                S += x;
                if (all_of(ALL(a), [&](int ai){ return gcd(S, ai) != 1; })) break;
                a[i-1] = 0;
                S -= x;
            }
        }
    } else {
        for (int i=0,b=0; i<N; i+=4,b+=6) {
            a.pb(b+2);
            a.pb(b+3);
            a.pb(b+4);
            a.pb(b+6);
        }
        a.erase(a.begin()+N, a.end());
        int last_6k = a.back() - a.back() % 6;
        int next_6k = last_6k + 6;
        int next_6k_4 = next_6k + 4;
        if (a.back() < next_6k_4 - 6) next_6k_4 -= 6;
        // 2 3 4 6 8 9 ...
        ll S = accumulate(ALL(a), 0LL);
        switch (S % 6) {
            case 0: break;
            case 2: a[4] = next_6k; break;
            case 3: a[5] = next_6k; break;
            case 5: a[5] = next_6k_4; break;
        }
    }

    sort(ALL(a));
    rep(i, N) {
        cout << a[i];
        if (i < N-1) cout << " ";
    }
    cout << endl;
}

int main() {
    int N; cin >> N;
    solve(N);
    return 0;
}


Measured memory_bytes: 384
/*---------------------------------

 @Author:   Dicer
 @DateTime: 2019-05-15 10:45:30

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
inline ll qpow(ll a,ll b,ll mod){ll res=1;while(b){if(b&1)res = (res*a)%mod;a=(a*a)%mod;b>>=1;}return res;}
const double eps = 1e-8;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int MAXN = 2e5 + 7;

ll dp[233][4][4][4];
/*
0 1 2 3
A G C T
*/
int main(int argc, char const *argv[])
{
	int n;
	cin >> n;
	if(n == 1)	cout << 4 << endl;
	else if(n == 2)	cout << 16 << endl;
	else{
		for(int i = 0; i < 4; ++i){
			for(int j = 0; j < 4; ++j){
				for(int k = 0; k < 4; ++k){
					dp[3][i][j][k] = 1;
				}
			}
		}
		dp[3][0][1][2] = 0;
		dp[3][1][0][2] = 0;
		dp[3][0][2][1] = 0;
		for(int q = 4; q <= n; ++q){
			for(int r = 0; r < 4; ++r){
				for(int i = 0; i < 4; ++i){
					for(int j = 0; j < 4; ++j){
						for(int k = 0; k < 4; ++k){
							if((i == 0 && j == 1 && k == 2)
								||
								(i == 1 && j == 0 && k == 2)
								||
								(i == 0 && j == 2 && k == 1)
								||
								(r == 0 && i != 0 && j == 1 && k == 2)
								||
								(r == 0 && i == 1 && j != 2 && k == 2))	continue;
							dp[q][i][j][k] += dp[q-1][r][i][j];
							dp[q][i][j][k] %= mod;
						}
					}
				}
			}
		}
		ll res = 0;
		for(int i = 0; i < 4; ++i){
			for(int j = 0; j < 4; ++j){
				for(int k = 0; k < 4; ++k){
					res += dp[n][i][j][k];
					res %= mod;
				}
			}
		}
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 256
unittest
{
	assert( [ "3 2", "acp", "ae" ].parse.expand.solve == 6 );
	assert( [ "6 3", "abcdef", "abc" ].parse.expand.solve == -1 );
	assert( [ "15 9", "dnsusrayukuaiia", "dujrunuma" ].parse.expand.solve == 45 );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	input.popFront;
	auto s = input.front;
	input.popFront;
	auto t = input.front;
	return tuple( s, t );
}

auto solve( string s, string t )
{
	auto l = lcm( s.length, t.length );
	auto si = 0L;
	auto ni = 0L;
	auto ti = 0L;
	auto mi = 0L;
	while( si < s.length && ti < t.length )
	{
		if( ni == mi && s[ si ] != t[ ti ] ) return -1;
		
		if( ni < mi )
		{
			si++;
			ni += l / s.length;
		}
		else
		{
			ti++;
			mi += l / t.length;
		}
	}
	return l;
}

// 最小公倍数
auto lcm( long x, long y )
{
	import std.numeric : gcd;
	return x * y / x.gcd( y );
}


Measured memory_bytes: 2556
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	string s;
	cin>>s;
	long long t=0;
	int a1[n+1],b1[n+1],c1[n+1];
	for(int i=0;i<=n;i++)
	a1[i]=0,b1[i]=0,c1[i]=0;
	for(int i=0;i<s.size();i++)
	{
		if(s[i]=='R')
		{
			a1[i]++;
		}
		if(s[i]=='B')
		{
			b1[i]++;
		}
		if(s[i]=='G')
		{
			c1[i]++;
		}
	}
	int a[n+1],b[n+1],c[n+1];
	a[n]=a1[n];
	for(int i=n-1;i>=0;i--)
	{
		a[i]=a[i+1]+a1[i];
	}
	b[n]=b1[n];
	for(int i=n-1;i>=0;i--)
	{
		b[i]=b[i+1]+b1[i];
	}
	c[n]=c1[n];
	for(int i=n-1;i>=0;i--)
	{
		c[i]=c[i+1]+c1[i];
	}
	for(int i=0;i<s.size()-2;i++)
	{
		for(int j=i+1;j<s.size()-1;j++)
		{
			if((s[i]=='R' && s[j]=='B') || (s[i]=='B' && s[j]=='R'))
			{
				if((j+j-i)<s.size())
				{
					if(s[j+j-i]=='G')
					t+=c[j+1]-1;
					else
					t+=c[j+1];
				}
				else
				t+=c[j+1];
			}
			if((s[i]=='R' && s[j]=='G') || (s[i]=='G' && s[j]=='R'))
			{
				if((j+j-i)<s.size())
				{
					if(s[j+j-i]=='B')
					t+=b[j+1]-1;
					else
					t+=b[j+1];
				}
				else
				t+=b[j+1];
			}
			if((s[i]=='G' && s[j]=='B') || (s[i]=='B' && s[j]=='G'))
			{
				if((j+j-i)<s.size())
				{
					if(s[j+j-i]=='R')
					t+=a[j+1]-1;
					else
					t+=a[j+1];
				}
				else
				t+=a[j+1];
			}
		}
	}
	cout<<t;
	return 0;
 } 

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

#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef pair<int,int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
    int H,W,b=0;
    cin >> H >> W;
    vector<string> s(H);
    vector<vector<int>> d(H, vector<int>(W,-1));
    queue<P> q;

    rep(i,H) {
        cin >> s.at(i);
        rep(j,W)
            if(s.at(i).at(j) == '#')
                b++;
    }
    
    q.push(P(0,0));
    d.at(0).at(0) = 0;

    while(!q.empty()) {
        P v = q.front();
        q.pop();

        rep(i,4) {
            P nv = P(v.first+dx[i], v.second+dy[i]);
            if(nv.first<0 || nv.first>=H || nv.second<0 || nv.second>=W)
                continue;
            if(s.at(nv.first).at(nv.second) == '#')
                continue;
            if(d.at(nv.first).at(nv.second) != -1)
                continue;
            d.at(nv.first).at(nv.second) = d.at(v.first).at(v.second) + 1;
            q.push(nv);
        }
    }

    if(d.at(H-1).at(W-1) == -1)
        cout << -1;
    else
        cout << H*W-b-d.at(H-1).at(W-1)-1;
    cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

int main()
{
  std::vector<int> vec( 3, 0 ) ;

  std::cin >> vec[0] >> vec[1] >> vec[2] ;

  std::sort( vec.begin(), vec.end() ) ;

  for ( int i = 0 ; i < vec.size() ; ++i ) {
    std::cout << vec[i] ;
    if ( i != vec.size() - 1 )
      std::cout << " " ;
  }
  std::cout << std::endl ;

  return 0 ;
}

Measured memory_bytes: 3116
#include<algorithm>
#include<string>
#include<stdio.h>
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<utility>
#include<functional>
#include<cassert>
#include<cmath>
#include<math.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<int> vint;
typedef vector<vint> vvint;
#define PI 3.1415926535;
#define MOD 1000000007;

int main(void) {
	int n;
	string a;
	cin >> n >> a;
	for (int i = 0; i < a.size(); i++) {
		if (a[i] + n > 90) {
			cout << char(a[i] + n - 26);
		}
		else {
			cout << char(a[i] + n);
		}
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define salma ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;
typedef long double ld;
using namespace std;
const int N=1e5 + 5;


int main( )
{
salma
ll n;
cin>>n;
ll a[n+10] ,b[n+10] , c[n+10];

ll dp[n+10][5];
for (int i=0 ; i<n ;i++)
    cin>>a[i]>>b[i]>>c[i];

   dp[0][0]=a[0];
   dp[0][1]=b[0];
   dp[0][2]=c[0];

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

ll ans;
ans=max(dp[n-1][0],dp[n-1][1]);
ll anss=max(ans,dp[n-1][2]);
cout<<anss;


    return 0;
}


Measured memory_bytes: 6528
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
//typedef __int64 LL;
typedef vector<int> ivec;
typedef vector<string> svec;




string s,t;
int a[100010],b[100010],c[100010],d[100010];
int bit1[100010],bit2[100010];
int sum1(int i){
    int s=0;
    while(i>0){
          s+=bit1[i];
          i-=i&-i;
    }
    return s;
}
int sum2(int i){
    int s=0;
    while(i>0){
          s+=bit2[i];
          i-=i&-i;
    }
    return s;
}
//i番目にxを足す
void add1(int i,int x){
     while(i<=s.size()){
           bit1[i]+=x;
           i+=i&-i;
     }

}
void add2(int i,int x){
     while(i<=t.size()){
           bit2[i]+=x;
           i+=i&-i;
     }

}

int main(){
	int n;
	int ans=0;	
	cin>>s>>t;
	cin>>n;
	
	for(int i=1;i<=s.size();i++){
        	int x;
		x=(s[i-1]=='A')?1:2;
		add1(i,x); 
		 
    	}
	for(int i=1;i<=t.size();i++){
        	int x;
		x=(t[i-1]=='A')?1:2;
		add2(i,x); 
		 
    	}
	for(int i=0;i<n;i++)cin>>a[i]>>b[i]>>c[i]>>d[i];
	
        for(int i=0;i<n;i++)
	{
		int x=sum1(b[i])-sum1(a[i]-1);
		int y=sum2(d[i])-sum2(c[i]-1);
		//cout<<x<<y<<endl;
		puts(((x-y)%3==0) ?"YES":"NO");
	}
	//cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1000000007;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX*/                      int gcd(ll a,ll b){return b?gcd(b,a%b):a;}
/*"lcm"   MIN*/                      int lcm(ll a,ll b){return a*b/gcd(a,b);}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}

int main(){
    ll n,k;
    cin >> n >> k;
    ll ans = min(n%k,abs(n%k-k));
    cout << ans << endl;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

template <typename T>
void print_vec(const vector<T>& v, bool is_reverse=false, ll num=0){
  if(num == 0) num = (ll)v.size();
  cout << endl; cout << "i=  ";for(ll i=0; i<num; i++) cout << i << "   ";cout << endl;  
  cout << "    ";
  if(is_reverse) for(ll i=num-1; i>=0; i--){ cout<<v[i]; if(i!=0) cout<<"   ";}
  else for(ll i=0; i<num; i++){ cout<<v[i]; if(i!=num-1) cout<<"   ";}
  cout << endl;
}

// template <typename T>
// void print_pairvec(const vector<T> &v, ll num=0){
//   if(num == 0) num = (ll)v.size();
//   cout << endl; for(ll i=0; i<num; i++){ cout << v[i].first << " " << v[i].second << endl;}
// }
template <typename T>
void print_pairvec(const T &_pair, ll num=0){
  cout << endl; for(pair<ll, int> x: _pair){ cout << x.first << " " << x.second << endl;}
}

template <typename T>
void print_vec2(const vector<vector<T>>& v){
  cout << endl; cout << "       ";
  for(ll i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(ll i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(ll j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}

int main(){

  int n;
  cin >> n;
  if(n==0) cout << '1' << endl;
  else cout << '0' << endl;
  return 0;
}


Measured memory_bytes: 3588
from pprint import pprint as pp
def GI(): return int(raw_input())
def GIS(): return map(int, raw_input().split())

def main():
  A, B = GIS()
  S = raw_input()
  print('Yes' if S[A] == '-' and all(map(str.isdigit, (S[:A], S[A+1:]))) else 'No')

main()

Measured memory_bytes: 28396
#include<stdio.h>
#define N 1001
static const int INFTY = (1<<21);

int n, M[N][N];
int color[N], d[N], f[N], tt;
int Q[N*2], head, tail;

void init(){
  head = tail = 1;
}

void enqueue(int x){
  Q[tail++] = x;
}

int empty(){
  return head == tail;
}

int dequeue(){
  int x = Q[head++];
  return x;
}

void bfs(int s){
  int i, u, v;
  init();
  enqueue(s);
  for ( i = 0; i < n; i++ )d[i] = INFTY;
  d[s] = 0;
  while(!empty()){
    u = dequeue();
    for ( v = 0; v < n; v++ ){
      if ( M[u][v] == 0 ) continue;
      if ( d[v] != INFTY ) continue;
      d[v] = d[u] + 1;
      enqueue(v);
    }
  }
  for ( i = 0; i < n; i++ ){
    printf("%d %d\n", i+1,((d[i]==INFTY)?(-1):d[i]));
  }
}

main(){
  int  u, k, v, i, j; 

  scanf("%d", &n);

  for ( i = 0; i <n; i++ ){
    for ( j = 0; j <n; j++ ) M[i][j] = 0;
  }
  
  for ( i = 0; i < n; i++ ){
    scanf("%d %d", &u, &k);
    u--;
    for ( j = 0; j < k; j++ ){
      scanf("%d", &v);
      v--;
      M[u][v] = 1;
    }
  }
  
  bfs(0);

  return 0;
}


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

int main() {

  int H, W, M;
  cin >> H >> W >> M;

  vector<pair<int, int>> B(M);
  vector<int> HCnt(H);
  vector<int> WCnt(W);
  map<pair<int, int>, int> m;
  int maxH = 0;
  int maxW = 0;

  for(int i = 0; i < M; i++){
    cin >> B[i].first >> B[i].second;
    HCnt[B[i].first - 1]++;
    if(HCnt[B[i].first - 1] > maxH){
      maxH = HCnt[B[i].first - 1];
    }
    WCnt[B[i].second - 1]++;
    if(WCnt[B[i].second - 1] > maxW){
      maxW = WCnt[B[i].second - 1];
    }
    m[make_pair(B[i].first - 1, B[i].second - 1)]++;
  }

  map<int, int> candH;
  map<int, int> candW;

  int max = maxH + maxW -1;

  for(int i = 0; i < H; i++){
    if(HCnt[i] == maxH){
      candH[i]++;
    }
  }

  for(int i = 0; i < W; i++){
    if(WCnt[i] == maxW){
      candW[i]++;
    }
  }

  for(auto itr = candH.begin(); itr != candH.end(); itr++){
    for(auto itr2 = candW.begin(); itr2 != candW.end(); itr2++){
      if(m.find(make_pair(itr->first, itr2->first)) == m.end()){
        max++;
        goto LAST;
      }
    }
  }
LAST:
  cout << max << endl;
}

Measured memory_bytes: 54568
import sys
input = sys.stdin.readline
S = input().rstrip()

while S:
    if S[-5:] == "dream":
        S = S[:-5]
    elif S[-5:] == "erase":
        S = S[:-5]
    elif S[-6:] == "eraser":
        S = S[:-6]
    elif S[-7:] == "dreamer":
        S = S[:-7]
    else:
        print("NO")
        sys.exit()
print("YES") 




Measured memory_bytes: 3236
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mo = 1e9 + 7, MAXN = 1e5 + 10;
template <class T>
inline void _read(T &x)
{
	x = 0;
	char t = getchar();
	while (!isdigit(t) && t != '-') t = getchar();
	if (t == '-')
	{
		_read(x);
		x *= -1;
		return ;
	}
	while (isdigit(t))
	{
		x = x * 10 + t - '0';
		t = getchar();
	}
}
ll n, k, f[MAXN];
inline ll fpm(ll a, ll b = mo - 2)
{
	if (b < 0) return 1;
	ll res = 1;
	while (b)
	{
		if (b & 1) res = res * a % mo;
		a = a * a % mo;
		b >>= 1;
	}
	return res;
}

int main()
{
	_read(n), _read(k);
	f[0] = 1ll;
	for(int i = 1; i < n; ++i)
	{
		for(int j = i; j; --j)f[j] = (f[j + 1] + f[j - 1]) % mo;
		f[0] = f[1];
	}
	printf("%lld", f[n - k] * fpm(2, n - k - 1) % mo);
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define int long long
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e9;
template<typename T> void cmax(T &a, T b) { a = max(a, b); }
template<typename T> void cmin(T &a, T b) { a = min(a, b); }

signed main() {
  int n;
  cin >> n;
  int t, a;
  cin >> t >> a;
  vector<int> h(n);
  rep(i, n) cin >> h[i];
  vector<double> diff(n);
  rep(i, n) { diff[i] = (double)(t - h[i] * 0.006); }
  double d = INF;
  int ans = 0;
  rep(i, n) {
    if (abs(a - diff[i]) < d) {
      d = abs(a - diff[i]);
      ans = i;
    }
  }
  cout << ans + 1 << endl;

  return 0;
}


Measured memory_bytes: 256
// see https://gist.github.com/LumaKernel/ff55d49ee1af69b7388f15b707e75c15
const bool DEBUG = 0;
#include <iostream>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <complex>
#include <random>
#include <iomanip>
#include <cassert>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef tuple<ll, ll> P;
typedef tuple<ll, ll, ll> P3;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<P> VP;

#define omajinai ios::sync_with_stdio(false);cin.tie(0)

#define FOR(i,a,b) for(int i=(a);i<int(b);++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(b)-1;i>=int(a);--i)
#define RREP(i,n) RFOR(i,0,n)

#define LFOR(i,a,b) for(ll i=(a);i<(b);++i)
#define LREP(i,n) LFOR(i,0,n)
#define LRFOR(i,a,b) for(ll i=(b)-1;i>=(a);--i)
#define LRREP(i,b,a) LRFOR(i,0,n)

#define ALL(a) (a).begin(),(a).end()
#define UNIQUE(a) (a).erase(unique((a).begin(),(a).end()),(a).end())
#define MP make_pair
#define PB push_back
#define EACH(i,c) REP(i,(int)(c).size())
#define REACH(i,c) RREP(i,(int)(c).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

#define BR cout << "\n"

#define dump(x) if(DEBUG)cerr<<"[" << __LINE__ << "] "<<#x<<"="<<(x)<<"\n"
#define dump2(x,y) if(DEBUG)cerr<<"["<<__LINE__<< "] "<<#x<<"="<<(x)\
  <<" , "<<#y<<"="<<(y)<<"\n"
#define dump3(x,y,z) if(DEBUG)cerr<<"["<<__LINE__<< "] "<<#x<<"="<<(x)\
  <<" , "<<#y<<"="<<(y)<<"\n"\
  <<" , "<<#z<<"="<<(z)<<"\n"

#define SAY(x) if(DEBUG) cerr << "[" << __LINE__ << "] " << (x) << "\n"

#define YES(x) cout<<((x)?"YES":"NO")<<"\n"
#define Yes(x) cout<<((x)?"Yes":"No")<<"\n"
#define yes(x) cout<<((x)?"yes":"no")<<"\n"

int int_in(){int n;cin>>n;return n;}
ll ll_in(){ll n;cin>>n;return n;}
string string_in(){string n;cin>>n;return n;}
#define ini int_in()
#define inl ll_in()
#define ins string_in()

#define inside(x,y) (0<=(x)&&(x)<w&&0<=(y)&&(y)<h)

const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9+7;

ll ans;

struct trie{
	trie *zero = nullptr, *one = nullptr;
	trie* mkzero(){
		if(zero==nullptr){
			trie x;
			this->zero = new trie;
		}
		return this->zero;
	}
	trie* mkone(){
		if(one==nullptr){
			trie x;
			this->one = new trie;
		}
		return this->one;
	}
	ll solve(ll l,int c){
		ll ret=0;ll h=l-c;
		if(zero==nullptr) {ret^=h&(-h);}
		else {ret^=zero->solve(l, c+1);}
		if(one==nullptr) {ret^=h&(-h);}
		else {ret^=one->solve(l, c+1);}
		return ret;
	}
};

int main() {
	omajinai;
	//#####//
	int n=ini;ll l=inl;
	trie root;
	REP(i, n){
		string s=ins;
		trie* it = &root;
		REP(j,s.size()){
			if(s[j]=='0'){
				it=it->mkzero();
			}else{
				it=it->mkone();
			}
		}
	}
	cout<<(root.solve(l,0)?"Alice":"Bob");BR;
}


Measured memory_bytes: 5484
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define Pause system("pause")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
ll dfs(ll x, ll y)
{
    if (x % y == 0)
    {
        return (2 * x) - y;
    }
    else
    {
        return (x / y) * y * 2 + dfs(y, x % y);
    }
}
int main()
{
    IOS;
    ll n, x;
    cin >> n >> x;
    ll ans = n;
    n -= x;
    ans += dfs(max(n, x), min(n, x));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3620
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np

n = int(input())
a = list(map(int , input().split()))
print(2*n)
if a[np.argmax(a)] <= -a[np.argmin(a)]:
    cnt = len(a) - 1
    for i in range(0, len(a)):
        print(str(np.argmin(a) + 1) + " " + str(cnt + 1))
        a[cnt] += a[np.argmin(a)]
        print(str(np.argmin(a) + 1) + " " + str(cnt + 1))
        a[cnt] += a[np.argmin(a)]
        cnt -= 1;
else:
    cnt = 0
    for i in range(0, len(a)):
        print(str(np.argmax(a) + 1) + " " + str(cnt + 1))
        a[cnt] += a[np.argmax(a)]
        print(str(np.argmax(a) + 1) + " " + str(cnt + 1))
        a[cnt] += a[np.argmax(a)]
        cnt += 1


Measured memory_bytes: 14444
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
int main()
{
	char a[105];
	int n, i;
	scanf("%d", &n);
	getchar();
	scanf("%s", a);
	if (strlen(a) <= n)
	{
		printf("%s", a);
	}
	else
	{
		for (i = 0; i < n; i++)
		{
			printf("%c", a[i]);
		}
		printf("...");
	}
    return 0;
}

Measured memory_bytes: 1728
#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>;

int main() {
  int n;
  cin >> n;
  string ans = "";
  if (n == 0) {
    cout << 0 << endl;
    return 0;
  }
  while (n) {
    if (n % 2) {
      ans += '1';
      n--;
    } else {
      ans += '0';
    }
    n /= (-2);
  }
  reverse(ans.begin(), ans.end());
  cout << ans << endl;
  return 0;
}

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

signed main() {
  int n;
  cin >> n;

  vector<int> a(n + 1);
  rep(i, n + 1) cin >> a[i];

  if(n == 0) {
    if(a[0] == 1) cout << 1 << '\n';
    else cout << -1 << '\n';
    return 0;
  }

  vector<int> sum(n + 2);
  for (int i = n; i >= 0; i--) {
    sum[i] = sum[i + 1] + a[i];
  }

  int ans = 0;
  int start = 1;
  for (int i = 0; i <= n; i++) {
    ans += min(start, sum[i]);
    start -= a[i];
    if(start < 0) {
      cout << -1 << '\n';
      return 0;
    }
    start = min(start * 2, (long long)1e18);
  }
  cout << ans << '\n';

}

Measured memory_bytes: 4840
n=int(input())
s=input()
ss="SS"
sw="SW"
ws="WS"
ww="WW"
def f(t,c):
    if t=="o":
        if c[-2:]=="SS" or c[-2:]=="WW":
            return c+"S"
        else:
            return c+"W"
    else:
        if c[-2:]=="SW" or c[-2:]=="WS":
            return c+"S"
        else:
            return c+"W"
for i in s[1:n-1]:
    ss=f(i,ss)
    sw=f(i,sw)
    ws=f(i,ws)
    ww=f(i,ww)
def a(s,c):
    if f(s[-1],c[-2:])[2]!=c[0]:
        return 0
    if f(s[0],c[-1]+c[0])[2]!=c[1]:
        return 0
    return 1
for i in [ss,sw,ws,ww]:
    if a(s,i):
        print(i)
        break
else:
    print(-1)

Measured memory_bytes: 3968
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>
#include <climits>
#include <functional>

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

using namespace std;
typedef long long ll;
const int INF = INT_MAX;

const int max_n = 1e3;

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

  int N, A, B;
  cin >> N >> A >> B;
  string s;
  cin >> s;

  int a = 0, b = 0;

  REP(i, N){
    if(s[i] == 'a') {
      if((a + b) < (A + B)) {
	a++;
	cout << "Yes\n";
      } else {
	cout << "No\n";
      }
    } else if (s[i] == 'b') {
      if((a + b) < (A + B) && b < B) {
	b++;
	cout << "Yes\n";
      } else {
	cout << "No\n";
      }
    } else 	cout << "No\n";
  }

  return 0;
}


Measured memory_bytes: 1464
#include<stdio.h>
#include<stdbool.h>
#include<stdlib.h>
#include<string.h>


int main(void){
    bool flag = true;
    char msg[100];
    scanf("%s",msg);
    int len = strlen(msg);

    for(int i=0;i<(len/2);++i){
        if(msg[i]!=msg[len-i-1]){
            flag = false;
        }
    }

    for(int j=0;j<((len/2)/2);++j){
        if(msg[j]!=msg[(len/2)-1-j]){
            flag = false;
        }
    }

    for(int k=(len/2)+1;k<len;++k){
        if(msg[k]!=msg[len-k+(len/2)]){
            flag = false;
        }
    }


    if(flag){
        printf("Yes");
        return 0;
    }
    printf("No");
    return 0;
}

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

int D;
std::vector<int> c(26);
std::vector<std::vector<int>> s(365, std::vector<int>(26));
std::vector<int> t(365);

void calc_greedy_score() {
    std::vector<int> last(26, 0);
    for (int i = 0; i < D; i++) {
        int max_idx = 0;
        int max_score = -365 * 100 * 26;
        for (int j = 0; j < 26; j++) {
            int tmp_score = 0;
            for (int k = 0; k < 26; k++) {
                if (j != k) {
                    tmp_score -= c[k] * (i + 1 - last[k]);
                }
            }
            tmp_score += s[i][j];
            if (tmp_score > max_score) {
                max_idx = j;
                max_score = tmp_score;
            }
        }
        last[max_idx] = i + 1;
        t[i] = max_idx + 1;
    }
}


int calc_diff(int day, int cont) {
    int pre_day = day - 1;
    for (; pre_day >= 0; pre_day--) {
        if (t[pre_day] - 1 == cont) {
            break;
        }
    }
    int post_day = day + 1;
    for (; post_day < D; post_day++) {
        if (t[post_day] - 1 == cont) {
            break;
        }
    }
    return (day - pre_day) * (post_day - day) * c[cont];
}


void update_score(int day, int after_cont) {
    int before_cont = t[day] - 1;
    if (calc_diff(day, after_cont) - calc_diff(day, before_cont) + s[day][after_cont] - s[day][before_cont] > 0) {
        t[day] = after_cont + 1;
    };
}


int main() {
    std::cin >> D;

    for (int i = 0; i < 26; i++) {
        std::cin >> c[i];
    }

    for (int i = 0; i < D; i++) {
        for (int j = 0; j < 26; j++) {
            std::cin >> s[i][j];
        }
    }

    calc_greedy_score();

    std::random_device seed_gen;
    std::mt19937 engine(seed_gen());
    std::uniform_int_distribution<> dist1(0, 364);
    std::uniform_int_distribution<> dist2(0, 25);

    for (int i = 0; i < 100000; i++) {
        update_score(dist1(engine), dist2(engine));
    }

    for (auto val : t) {
        std::cout  << val << std::endl;
    }
}


Measured memory_bytes: 3676
// B - ss
#include <bits/stdc++.h>
using namespace std;

int main(){
	string S; cin>>S;
	int startlength = S.size()%2? S.size()-1: S.size()-2;
	for(int n=startlength; n>0; n-=2){//n: length to check
		int len = n/2;//len: half length
		// if(S.compare(0, len, S.substr(len, len)) == 0){
		if(S.substr(0, len) == S.substr(len, len)){
			cout<< n <<endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const int MOD=1e9+7;
const int INF=2e9;

double dis(double x,double y,double z) {
    return sqrt(x*x+y*y+z*z);
}

struct UnionFind {
    vector<int> par;
    UnionFind(int N) : par(N) {
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
    }

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

int main() {
    ios_base::sync_with_stdio(false);

    vector<double> a;
    while (1) {
        int n;
        cin >> n; 
        if (n==0) break;
        vector<double> x(n),y(n),z(n),r(n);
        rep(i,n) cin >> x[i] >> y[i] >> z[i] >> r[i];
        UnionFind tree(n);
        vector<pair<double,P>> d;
        rep(i,n) {
            rep(j,i) {
                double dd=dis(x[i]-x[j],y[i]-y[j],z[i]-z[j])-(r[i]+r[j]);
                if (dd<=0) tree.unite(i,j);
                else d.push_back(make_pair(dd,make_pair(i,j)));
            }
        }
        sort(d.begin(),d.end());
        double ans=0.0;
        rep(i,d.size()) {
            if (!tree.same(d[i].second.first,d[i].second.second)) {
                ans+=d[i].first;
                tree.unite(d[i].second.first,d[i].second.second);
            }
        }
        a.push_back(ans);
    }
    rep(i,a.size()) cout << fixed << setprecision(3) << a[i] << endl;
    

    return 0;
}


Measured memory_bytes: 3396