akhauriyash/Code-Regression huggingface dataset:
// 私に忍び寄るのをやめてください、ありがとう

#include<bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll long long
#define int long long
#define mod 1000000007 //998244353
#define fast  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define f(i,n) for(ll i=0;i<n;i++)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define nl "\n"
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define x first
#define y second
#define vc vector
#define pb push_back
#define ar array
#define all(a) (a).begin(), (a).end()
#define ms(v,n,x) fill(v,v+n,x);
#define init(c,a) memset(c,a,sizeof(c))
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define sll set<ll>
#define vll vector<ll>
#define vpll vector<pll>
#define inf 9e18
#define cases ll T;cin>>T;while(T--)
#define BLOCK 500
//const double PI = 3.141592653589793238460;
template<typename T> bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool mmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
typedef std::complex<double> Complex;
typedef std::valarray<Complex> CArray;
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 << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

const int N=1<<20;

int32_t main()
{
    
	fast	
	cout << fixed << setprecision(12);
	ll d,t,s;
	cin>>d>>t>>s;
	if(t*s>=d)
	cout<<"Yes";
	else
	cout<<"No";

    

	return 0;
    
}

Measured memory_bytes: 3648
s =input()
li = [(i+j) for (i,j) in zip(s[::2],s[1::2])]

if (int(li[0])>12)&(int(li[0])>0):
  if (int(li[1])>12)|(int(li[1])==0):
  	print('NA')
  else:
    print('YYMM')
elif int(li[0])==0:
  if int(li[1])==0:
    print('NA')
  else:
    print('YYMM')
else:
  if (int(li[1])>12)|(int(li[1])==0):
    print('MMYY')
  else:
    print('AMBIGUOUS')

Measured memory_bytes: 3064
// #include <bits/stdc++.h>
#include <stdio.h>
#include <utility>
 
// using namespace std;
using std::swap;
 
typedef long long ll;
 
typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)

ll a[252521];
ll tmp[252521];
 
ll solve(int l,int r){
  if(r-l <= 8){
    ll ret = (r-l)*(r-l-1)/2;
    REP(k,r-l-1)FOR(i,l,r-1-k)if(a[i]>a[i+1])swap(a[i],a[i+1]),ret--;
    return ret;
  }
  // if(r-l==1){
  //   return 0ll;
  // }
  int mid = (l+r)/2;
  ll ret = solve(l,mid) + solve(mid,r);
  int hl = l, hr = mid;
  FOR(i,l,r){
    if(hl<mid && (hr==r || a[hl]<=a[hr])){
      tmp[i] = a[hl++];
    }else{
      ret += hl-l;
      tmp[i] = a[hr++];
    }
  }
  FOR(i,l,r)a[i]=tmp[i];
  return ret;
}
 
int main(){
  int n;
  ll k;
  scanf("%d%lld",&n,&k);
  REP(i,n){
    scanf("%lld",a+i+1);
    a[i+1] += a[i] - k;
  }
  ll ans = solve(0,n+1);
  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 3328
#include <vector> 
#include <list> 
#include <map> 
#include <set> 
#include <deque> 
#include <queue> 
#include <stack> 
#include <bitset> 
#include <algorithm> 
#include <functional> 
#include <numeric> 
#include <utility> 
#include <sstream> 
#include <iostream> 
#include <iomanip> 
#include <cstdio> 
#include <cmath> 
#include <cstdlib> 
#include <cctype> 
#include <string> 
#include <cstring> 
#include <ctime> 

using namespace std;

#define _int64 long long

_int64 doit(_int64 h,_int64 w,_int64 s)
{
  _int64 s1,s2,ret;
  ret=(1LL<<60);
  if (h>=2)
  {
    s1=h/2*w;
    s2=(h-h/2)*w;
    if (max(s1,max(s2,s))-min(s1,min(s2,s))<ret)
      ret=max(s1,max(s2,s))-min(s1,min(s2,s));
  }
  if (w>=2)
  {
    s1=w/2*h;
    s2=(w-w/2)*h;
    if (max(s1,max(s2,s))-min(s1,min(s2,s))<ret)
      ret=max(s1,max(s2,s))-min(s1,min(s2,s));
  }
  return ret;
}

int main()
{
  _int64 i,j,h,w,s,ans,tmp,remh,remw;
  scanf("%lld%lld",&h,&w);
  ans=h*w;
  for (i=1;i<h;i++)
  {
    remh=h-i;
    remw=w;
    tmp=doit(remh,remw,i*w);
    if (tmp<ans) ans=tmp;
  }
  for (i=1;i<w;i++)
  {
    remh=h;
    remw=w-i;
    tmp=doit(remh,remw,i*h);
    if (tmp<ans) ans=tmp;
  }
  printf("%lld\n",ans);
  return 0;
}

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++)

int main() {
    int r, g, b, n; cin >> r >> g >> b >> n;
    int ans = 0;
    for (int i = 0; i*r <= n; i++) {
        for (int j = 0; j*g <= n-i*r; j++) {
            int k = n - i*r - j*g;
            if (k % b == 0) {
                ans++;
            }
        }
    }
    cout << ans << endl;
}

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

#define ll long long
const int MAX = 5e3+1;

vector<ll> weight(MAX);
vector<ll> position(MAX);
vector<ll> prefix_sum;
bool visited[MAX];

void pre_process(ll i, ll sum){

    if(visited[i] == true) return;

    visited[i] = true;

    sum =  sum + weight[i];
    prefix_sum.push_back(sum);

    pre_process(position[i], sum);
}

void solve(){

    int N, K; cin>>N>>K;

    for (int i=1; i<=N; i++)
        cin>>position[i];

    for (int i=1; i<=N; i++)
        cin>>weight[i];

    ll total_maximum = LONG_MIN;

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

        memset(visited, false, sizeof(visited));
        pre_process(i, 0);

        /*
            Sendo que o número de elementos a cada query pode não ser igual a "N", então:
            Número de elemento a cada query = Elementos visitados.

            Se todos os elementos forem positivos, quer dizer que está fofo. Quanto mais iterar, melhor será a maximização.
        */

        if(prefix_sum.back()>0 && K>=(int)prefix_sum.size()){

            /*
                Se K >= Tamanho de elementos em qualquer query, então:
                Número de rotações = K/Número de elementos visitados.

                Para houver rotação:
                    - K deve ser maior que o número de elementos visitados
                    - Último elemento deve ser maior que zero senão, a resposta estará na primeira consulta.

                Se houver rotação:
                    - Itera-se todo o prefix_sum em funcão do número de cíclos;
                    - Pegando o módulo, itera-se o resto.
            */
            int rotations = (int) (K/(int)prefix_sum.size());

            /*Para não houver redundância em termos de rotação, o último elemento a ser visitado "n" vezes, vale:
                Último elemento elemento = K%Número de elementos de cada query.
            */
            int last_index = (int) (K%(int)prefix_sum.size());

            ll maximum = LONG_MIN;
            for (int j=1; j<=(int)prefix_sum.size(); j++)
                maximum = max(maximum, prefix_sum[j-1]);

            total_maximum = max(total_maximum, ((rotations-1)*prefix_sum.back()) + maximum);

            /*Nem sempre a última soma é a melhor. Porém, há necessidade de se verificar
                o máximo duas vezes. Existirá casos, em que a melhor soma estará infiltrado entre as posições do prefix_sum.
            */

            maximum = LONG_MIN;
            for (int j=1; j<=(int)last_index; j++)
                maximum = max(maximum, prefix_sum[j-1]);

            total_maximum = max(total_maximum, (rotations*prefix_sum.back()) + maximum);
        } else{

            //Será executado quando não é necessário fazer rotações.

            for (int j = 1; j<=min((int)prefix_sum.size(), K); j++)
                total_maximum = max(total_maximum, prefix_sum[j-1]);
        }

        prefix_sum.clear();
    }

    cout<<total_maximum<<endl;

}

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


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

using namespace std;

long long k,a,b;

void solve(){
    int i,j;
    string str;
    cin >> k >> a >> b;
    long long ans = 0;
    if(b-a > 2 && k > a){
        ans = a;
        k -= a-1;
        ans += k/2*(b-a);
        ans += k%2;
    }
    else ans = k+1;
    cout << ans << endl;
}

int main(){
    solve();
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
const int inf=2147483647;
int n;
#define Maxn 100010
int p[Maxn],q[Maxn],a[Maxn],cnt1=0,b[Maxn],cnt2=0;
int S,T,head[Maxn<<1],v[Maxn*12],w[Maxn*12],nxt[Maxn*12],tot=0;
int d[Maxn<<1],cur[Maxn<<1];
inline void add_edge(int s,int e,int t){
	tot++;v[tot]=e;w[tot]=t;nxt[tot]=head[s];head[s]=tot;
	tot++;v[tot]=s;w[tot]=0;nxt[tot]=head[e];head[e]=tot;
}

void init(int *seq1,int *seq2,int &cnt){
	for(register int i=1;i<=n;++i)
	    if(!seq2[i]){
	    	int x=i;
	    	cnt++;
	    	while(!seq2[x]){
	    		seq2[x]=cnt;
	    		x=seq1[x];
			}
		}
}

int Q[Maxn<<1],hd,tl;
inline bool Bfs(){
	hd=tl=0;
	Q[tl++]=S;
	memset(d,-1,sizeof(int)*(cnt1+cnt2+3));
	d[S]=0;
	while(hd<tl){
		int u=Q[hd];
		hd++;
		for(int i=head[u];i;i=nxt[i])
		    if(d[v[i]]==-1&&w[i]){
		    	d[v[i]]=d[u]+1;
		    	if(v[i]==T)return true;
		    	Q[tl++]=v[i];
			}
	}
	return false;
}
int dfs(int  u,int flow){
	if(u==T||!flow)return flow;
	int res=0,minv;
	for(int &i=head[u];i;i=nxt[i])
	    if(d[v[i]]==d[u]+1&&w[i]&&(minv=dfs(v[i],min(w[i],flow)))){
	    	w[i]-=minv;
	    	if(i&1)w[i+1]+=minv;
	    	else w[i-1]+=minv;
	    	res+=minv;
	    	flow-=minv;
	    	if(!flow)break;
		}
	return res;
}
inline int Dinic(){
	memcpy(cur,head,sizeof(int)*(cnt1+cnt2+3));
	int ans=0;
	while(Bfs()){
		ans+=dfs(S,inf);
		memcpy(head,cur,sizeof(int)*(cnt1+cnt2+3));
	}
	return ans;
}

inline void rd(int &x){
	x=0;char ch=getchar();
	while(ch<'0'||ch>'9')ch=getchar();
	while(ch>='0'&&ch<='9'){
		x=x*10+ch-'0';
		ch=getchar();
	}
}

int main(){
	rd(n);
	for(register int i=1;i<=n;++i)rd(p[i]),p[i]++;
	for(register int i=1;i<=n;++i)rd(q[i]),q[i]++;
	init(p,a,cnt1);
	init(q,b,cnt2); 
	int ans=n;
	S=1;T=2+cnt1+cnt2;
	for(register int i=1;i<=n;++i){
		if(i==p[i]&&i==q[i])ans--;
		else if(i==p[i])add_edge(1+cnt1+b[i],T,1);
		else if(i==q[i])add_edge(S,1+a[i],1);
		else{
			add_edge(1+cnt1+b[i],1+a[i],1);
			if(p[i]==q[i])add_edge(1+a[i],1+cnt1+b[i],1);
		}
	}
	ans-=Dinic();
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 13696
#include <bits/stdc++.h>
using namespace std;
template<typename T = int> vector<T> create(size_t n){ return vector<T>(n); }
template<typename T, typename... Args> auto create(size_t n, Args... args){ return vector<decltype(create<T>(args...))>(n, create<T>(args...)); }
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	vector<long long> vals;
	function<void(long long, int)> generate = [&](long long cur_val, int sz){
		if(cur_val > 0)
			vals.push_back(cur_val);
		if(sz >= 11){
			return;
		}
		if(cur_val == 0){
			for(int i = 0; i <= 9; i++){
				generate(cur_val * 10 + i, sz + 1);
			}
			return;
		}
		int dig = cur_val % 10;
		for(int d = -1; d <= 1; d++){
			int ndig = dig + d;
			if(ndig >= 0 && ndig <= 9){
				generate(cur_val * 10 + ndig, sz + 1);
			}
		}
	};
	generate(0, 0);
	sort(vals.begin(), vals.end());
	vals.erase(unique(vals.begin(), vals.end()), vals.end());
	int k;
	cin >> k;
	cout << vals[k - 1] << '\n';
	return 0;
}


Measured memory_bytes: 10604
#include <stdio.h>

int main(void)
{
	int in[10];
	int i;
	int n;
	
	for (i = 0; i < 10; i++){
		in[i] = 0;
	}
	while (scanf("%d", &n) == 1){
		if (n != 0){
			for (i = 0; i < 10; i++){
				if (in[i] == 0){
					in[i] = n;
					break;
				}
			}
		}
		else {
			for (i = 9; i >= 0; i--){
				if (in[i] != 0){
					printf("%d\n", in[i]);
					in[i] = 0;
					break;
				}
			}
		}
	}
	return (0);
}

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

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

	int S = 1; for (int i = 0; i < D; i++) S *= 100;
	if (N <= 99) {
		cout << S * N << endl;
	}
	else {
		cout << S * 101 << endl;
	}
	
}



Measured memory_bytes: 256
//author: dazhong_feliks

#include <bits/stdc++.h>
using namespace std;

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

vector<int> vec(N);
for (int x = 0; x < N; x++){
  cin >> vec.at(x);
}

sort(vec.begin(), vec.end());
reverse(vec.begin(), vec.end());

  int ansA = 0;
  int ansB = 0;
 
 for(int i = 0; i < N; i = i + 2 ){
     ansA += vec.at(i);
 } 

 for(int i = 1; i < N; i = i + 2 ){
     ansB += vec.at(i);
 }

  cout << ansA - ansB << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, W;
  cin >> N >> W;
  vector<int> v(N), w(N);
  for (int i = 0; i < N; i++){
    cin >> v[i] >> w[i];
  }
  vector<vector<int>> dp(N + 1, vector<int>(W + 1, 0));
  for (int i = 0; i < N; i++){
    for (int j = 0; j <= W; j++){
      dp[i + 1][j] = dp[i][j];
      if (j >= w[i]){
        dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - w[i]] + v[i]);
      }
    }
  }
  cout << dp[N][W] << endl;
}


Measured memory_bytes: 6760
s = input()+"R"
ls = len(s)-1
gr = []

ans = [0]*ls
pre = 0

r = 0
l = 0
for i in range(ls):
    if s[i]=="R":
        r+=1
        if s[i+1]=="L":
            gr.append(r)
            r=0
    else:
        l+=1
        if s[i+1]=="R":
            gr.append(l)
            l=0
#print(*gr)
j = 0
#偶奇などの細部の調整の効率化が課題
for i in range(ls):
    if s[i:i+2]=="RL":
        ans[i] += (gr[j]+1^(gr[j]&1))//2
        ans[i+1] += gr[j]//2
        ans[i] += gr[j+1]//2
        ans[i+1] += (gr[j+1]+1^(gr[j+1]&1))//2
        j+=2
print(*ans)


            

Measured memory_bytes: 48732
#include <bits/stdc++.h>
#define rep(i, z, n) for(int64_t i = z; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
#define PI 3.14159265358979
//const int64_t INF = 1LL << 60;
//const int INF = 1 << 29;
//const int64_t MOD = 1000000007;
//const int64_t INF = 998244353;
using namespace std;
typedef pair<int64_t, int64_t> P;

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, 0, N) cin >> A.at(i);
    sort(all(A));
    rep(i, 0, N - 1){
        if(A.at(i) == A.at(i + 1)){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 1024
import java.util.Arrays;
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int data[] = new int[N];
		for(int i = 0; i < N; i++) {
			data[i] = sc.nextInt();
		}
		Arrays.sort(data);
		int sum = 0;
		int n = 2;
		for(int i = N-1; i >= 0; i--) {
			if(n % 2 == 0) {
				sum = sum+data[i];
			}else {
				sum = sum-data[i];
			}
			n++;
		}
		System.out.println(sum);
		sc.close();
	}
}


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

int main()
{
	string str;
	int sn=0;
	cin >> str;
	for (int i = 0; i < str.size(); i++) {
		sn += stoi(str.substr(i,1));
	}
	if (stoi(str) % sn) {
		cout << "No";
	}
	else {
		cout << "Yes";
	}
}

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

using namespace std;

void eratosthenes(vector<int> &n){	
	n[0] = n[1] = 1;
	for (int i = 2;i <= 120000; i++){
		if (n[i] == 0){
			for (int j = 2; j <= (120000/i); j++){
				n[i * j] = 1;
			}

		}
	}
	return;
}

bool isPrime(int n){
	if (n < 2) return false;
	if (n == 2) return true;
	for (int i = 2; i <= sqrt(n) + 1; i++){
		if (n % i == 0) return false;
	}
	return true;
}
		
int main(){
	vector<int> era(120000);
	eratosthenes(era);
	vector<int> Primelist(120001);
	int index = 1;
	for (int i = 1; i <= era.size(); i++){
		if (era[i] == 0){
			Primelist[index] = i;
			index++;
		}
	}
	while(1){
		int n,p; cin >> n >> p;
		if (n + p == -2) break;
		index = 1;
		while(n >= Primelist[index]){
			index++;
		}
		
		vector<int> list(120000);
		for (int i = 1; i <= p; i++){
			for (int j = i; j <= p; j++){
				list[(i-1) * p + j] = Primelist[index + i - 1] + Primelist[index + j - 1];
			}
		}
		sort(list.begin(),list.end());
		index = 0;
		while(list[index] == 0){
			index++;
		}
		cout << list[index + p - 1] << endl;
		
	}

return 0;
}

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

typedef long long ll;
#define pa pair<int, int> 
#define pal pair<long long, long long>
#define pad pair<double, double>
#define pb push_back
#define mp make_pair
#define VIN(v) for(int64_t i=0;i<(v).size();i++){cin >> (v).at(i);}

typedef vector<bool> bvec;
typedef vector<int> ivec;
typedef vector<long long> lvec;
typedef vector<double> dvec;
typedef vector<pa> pvec;

typedef vector< vector<bool> > bmat;
typedef vector< vector<int> > imat;
typedef vector< vector<long long> > lmat;

typedef vector<string> svec;
typedef vector< vector<string> > smat;
const ll infll = (1LL << 60) - 1;
const int inf = (1 << 30) - 1;

ll gcd(ll x, ll y){
    ll r = x%y;
    if(r == 0) return y;
    else return gcd(y, r);
} 

ll lcm(ll x, ll y){
    return x*y/gcd(x,y);
}

ll getnum(ivec &x){
    int y=0;
    for (size_t i = 0; i < 60; i++)
    {
        y+=(1ll << i)*x[i];
    }
    return y;

}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, dm=60;
    cin >> n;
    lvec a(n);
    lmat s(dm);
    // lvec ss(61, 0);
    lvec ss;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < dm; i++){
        s[i].push_back((a[0] >> i) % 2);
        for (int j=1; j<n; j++){
            int d = (a[j] >> i) % 2;
            s[i].push_back(s[i][j-1] + d);
        }
    }

    
    for (auto &x : s){
        ss.push_back((n - x[n-1])*x[n-1]);
    }
    
    ll d = 1e9 + 7;
    ll ans=0;
    for (int i = 0; i < dm; i++)
    {   
        ll rr = ((1ll << i)%d * (ss[i]%d))%d;
        ans += rr;
    }
    
    cout << ans%d <<endl;

}

Measured memory_bytes: 221420
N,M=map(int,input().split())
L=2**N
l=[float("inf")]*L
l[0]=0
r=(1,2,4,8,16,32,64,128,256,512,1024,2048)
for i in range(M):
    s=0
    a,b=map(int,input().split())
    c=tuple(map(int,input().split()))
    for j in c:
        s+=r[j-1]
    for j in range(L):
        l[j|s]=min(l[j|s],l[j]+a)
if l[-1]==float("inf"):
    print(-1)
else:
    print(l[-1])

Measured memory_bytes: 50396
#include <iostream>

using namespace std;
typedef long long int ll;
const int MAX=51;
ll len[MAX]; //size of n-th bugger
ll lenP[MAX]; // putty size for n-th bugger

// putty size of d-th bugger (l)
ll p(ll d, ll l) {
    if (d==0) {
        return l>0 ? 1:0;
    }
    if (l <=1) {
        return 0;
    }
    if (l >=len[d]) {
        return lenP[d];
    }
    ll r = p(d - 1, l -1);
    if (l <= (len[d-1] + 1)) {
        return r;
    }
    return r+1+p(d-1, l- len[d-1] -2);
}

int main() {
    ll n,x;
    cin >> n >> x;
    len[0] = 1;
    lenP[0] = 1;
    for (int i=1; i< MAX; i++) {
        lenP[i] = 2*lenP[i-1] + 1;
        len[i] = 2*len[i-1] + 3;
    }
    cout << p(n, x) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
	int a, b;
	cin >> a >> b;
	int d = a / b;
	int r = a%b;
	double f = a*1.000000 / b*1.000000;
	cout << d << " " << r << " " << fixed << setprecision(5) << f << endl;



	return 0;

}

Measured memory_bytes: 1244
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

signed main()
{
  int a, b, c;
  cin >> a >> b >> c;

  if (a == b && b == c) {
    if (a & 1) cout << '0' << '\n';
    else cout << -1 << '\n';
    
    return (0);
  }

  int ans = 0;

  while (1) {
    if ((a & 1) || (b & 1) || (c & 1)) break;

    int a2 = a, b2 = b, c2 = c;
    a = b2/2 + c2/2;
    b = a2/2 + c2/2;
    c = a2/2 + b2/2;

    ++ans;
  }

  cout << ans << '\n';

  return (0);
}


Measured memory_bytes: 3576
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n)for(int i=0;i<(int)(n);i++)
//#define PI 3.141592653589793
//vector < vector<int>>a(0, vector<int>(0));二次元配列宣言


int main()
{
	int n;
	cin >> n;
	vector<long long int>a(n);
	int i;
	long long int sum = 1;
	for (i = 0; i < n; i++)
	{
		cin >> a.at(i);
		if (a.at(i) == 0)
			sum = 0;
	}
	if (sum != 0)
	{
		for (i = 0; i < n; i++)
		{
			if (sum > 1000000000000000000 / a.at(i))
			{
				sum = -1;
				break;
			}
			sum *= a.at(i);
		}
	}
	cout << sum << endl;
}


	
	

	
	
/**/
/*#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

#define PI 3.141592653589793

int main(void) {
	return 0;
}
*/

Measured memory_bytes: 3980
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <numeric>
#include <queue>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)

int main() {
    int a, b;
    cin >> a >> b;
    cout << a*b << endl;
}

Measured memory_bytes: 3636
#include <stdio.h>

#define MOD_BY 1000000007

int add(int a, int b) {
	return a + b - MOD_BY * (a + b >= MOD_BY);
}

int mul(int a, int b) {
	int r = 0;
	while (b > 0) {
		if (b & 1) r = add(r, a);
		a = add(a, a);
		b >>= 1;
	}
	return r;
}

int main(void) {
	int N;
	int i;
	int asumikana = 1;
	if (scanf("%d", &N) != 1) return 1;
	for (i = 1; i <= N; i++) {
		asumikana = mul(asumikana, i);
	}
	printf("%d\n", asumikana);
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int x[105], y[105];


int main(){    
    int n; cin >> n;
    vector< pair<double,int> > vec;
    for(int i = 0; i < n; i++){
        cin >> x[i] >> y[i];
        vec.push_back({atan2(y[i], x[i]), i});
    }
    sort(vec.begin(), vec.end());

    ll res = -1e18;    
    for(int i = 0; i < n; i++){
        ll xx = 0, yy = 0;
        for(int j = 0; j < n; j++){
            int idx = (i+j)%n;
            idx = vec[idx].second;
            xx += x[idx], yy += y[idx];
            res = max(res, xx*xx + yy*yy);
        }
    }
    printf("%.10f\n", sqrt(res));
    return 0;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  int x, y, z, w;
  x = a+(a-1), y = a+b, z = b+(b-1);
  w = max({x, y, z});
  cout << w << endl;
}

Measured memory_bytes: 256
import sys
from collections import deque

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    A = list(map(int, input().split()))
    if len(A) == 2 and 0 in A:
        print(max(A) - 0)
        print(max(A), 0)
        exit()

    plus = deque(sorted([a for a in A if a >= 0]))
    minus = deque(sorted([a for a in A if a < 0]))

    res = []
    if plus and minus:
        while len(plus) > 1:
            x = minus.pop()
            y = plus.pop()
            res.append([x, y])
            minus.append(x - y)
        while minus:
            x = plus.pop()
            y = minus.pop()
            res.append([x, y])
            plus.append(x - y)
    elif plus:
        x = plus.popleft()
        y = plus.pop()
        res.append([x, y])
        minus.append(x - y)
        while len(plus) > 1:
            x = minus.pop()
            y = plus.pop()
            res.append([x, y])
            minus.append(x - y)
        x = plus.pop()
        y = minus.pop()
        res.append([x, y])
        plus.append(x - y)
    else:
        x = minus.pop()
        y = minus.popleft()
        res.append([x, y])
        plus.append(x - y)
        while minus:
            x = plus.pop()
            y = minus.pop()
            res.append([x, y])
            plus.append(x - y)

    print(*plus)
    for i in res:
        print(*i)


if __name__ == '__main__':
    resolve()


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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vll = vector<ll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	for (auto &u : v) os << u << el;
	return (os);
}

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

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	is >> p.first >> p.second;
	return (is);
}

int main() {
	string S;
	ll K; cin >> S >> K;
	ll dp[105][5][2] = {};
	
	dp[0][0][0] = 1;
	int N = S.size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j <= K; j++) {
			int val = S[i] - '0';

			if (val == 0) dp[i+1][j][0] += dp[i][j][0];
			else dp[i+1][j][1] += dp[i][j][0];
			dp[i+1][j][1] += dp[i][j][1];

			if (val > 0) {
				dp[i+1][j+1][1] += (val-1) * dp[i][j][0];
				dp[i+1][j+1][0] += dp[i][j][0];
			}
			dp[i+1][j+1][1] += 9 * dp[i][j][1];
		}
	}
	cout << dp[N][K][0] + dp[N][K][1] << endl;
	return (0);
}

Measured memory_bytes: 256
import java.util.*;

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

        int s1 = s / 100;
        int s2 = s - (s1 * 100);

        if (s1 > 0 && s1 <= 12 && s2 > 0 && s2 <= 12)
            System.out.println("AMBIGUOUS");
        else if (s1 > 0 && s1 <= 12)
            System.out.println("MMYY");
        else if (s2 > 0 && s2 <= 12)
            System.out.println("YYMM");
        else
            System.out.println("NA");
        sc.close();
    }
}

Measured memory_bytes: 21844
#include"bits/stdc++.h"
using namespace std;

int main() {
	string S, T;
	cin >> S >> T;
	int count = 0;
	if (S[0] == T[0])count += 1;
	if (S[1] == T[1])count += 1;
	if (S[2] == T[2])count += 1;
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 256
import sys

n,k = map(int,input().split())
s = input()

zero = []
one = []
string = s[0]
if string == '0':
	flag = True
else:
	flag = False
count = 0
left = 0
right = 0
num = 0
for i in range(n):
	if s[i] == string:
		count += 1
	else:
		if string == '0':
			num = count
			string = '1'
		else:
			one.append(count)
			if num != 0:
				zero.append([num,left,count])
			string = '0'
			left = count
			num = 1
		count = 1

if string == '0':
	zero.append([count,left,0])
else:
	zero.append([num,left,count])
	one.append(count)
#print(zero)
#print(one)
if len(zero) <= k:
	print(len(s))
	sys.exit()
res = 0
for i in range(k):
	res += zero[i][0] + zero[i][1]
res += zero[i][2]
#print(res)
ans = res
for i in range(len(zero)-k):
	res -= zero[i][0] + zero[i][1]
	#print(res)
	res += zero[i+k][0] + zero[i+k][2]
	#print(res)
	ans = max(ans,res)
print(ans)

Measured memory_bytes: 8564
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <sstream>
#include <fstream>

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)

using namespace std;
typedef long long unsigned int ll;

int main() {
  int N;
  cin >> N;
  if (N == 3 || N == 5 || N == 7) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
  return 0;
}

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

char grid[1007][1007];
ll dp[1007][1007];
bool vis[1007][1007];
int h,w;

bool valid( int i, int j )
{
    if( i<0 or j<0 )
        return 0;
    if( i>=h or j>=w )
        return 0;
    if( grid[i][j]=='#' )
        return 0;
    return 1;
}

ll rec( int i, int j )
{
    if( i==h-1 and j==w-1 )
        return 1;
    if(vis[i][j])
        return dp[i][j];

    ll q1= 0, q2= 0;

    if( valid(i+1,j) )
        q1= rec( i+1,j )%m;
    if( valid(i,j+1) )
        q2= rec( i, j+1 )%m;

    vis[i][j]= 1;

    return dp[i][j]= (q1+q2)%m;
}

int main()
{
    cin>>h>>w;

    for(int i=0;i<h;i++)
        for(int j=0;j<w;j++)
            cin>>grid[i][j];

    cout<< rec(0,0) <<endl;

}



Measured memory_bytes: 10240
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <fstream>
#include <bitset>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef priority_queue<int> pqi;
typedef priority_queue<ii> pqii;
typedef map<int, int> mii;
typedef map<int, string> mis;
typedef map<string, int> msi;
typedef set<int> si;
typedef set<ll> sl;
typedef map<ll, ll> mll;
typedef queue<int> qi;
typedef queue<ii> qii;
typedef vector<string> vs;
typedef pair<ll, ll> iil;
typedef vector<iil> viil;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int, ii> iii;
typedef vector<pair<pair<int,int>,int>> viii;
typedef vector<pair<pair<ll,ll>,ll>> viiil;

#define pb push_back
#define mp make_pair
#define rep(i, n) for (int i = 0 ; i < n ; i++)
#define INF 1000000000
#define MOD 1000000007;

int arr[500005];
int n;

int sum(int x) {
    int sm = 0;
    while (x > 0) {
        sm += arr[x];
        x -= x &- x;
    }
    return sm;
}

void upd(int k, int x) {
    while (k <= n) {
        arr[k] += x;
        k += k &- k;
    }
}

void solve() {
    int q;
    cin >> n >> q;
    vi s(n);
    rep(i, n) cin >> s[i];
    vi a;
    rep(i, n+1) {
        a.pb(0);
    }
    for (int i = 1 ; i <= n ; i++) {
        int x = i - (i &- i) + 1;
        int y = i;
        int sm = 0;
        for (int j = x ; j <= y ; j++) {
            sm += a[j];
        }
        arr[i] = sm;
    }

    /*rep(i, q) {
        int b;
        cin >> b;
        if (b == 1) {
            int c, d;
            cin >> c >> d;
            cout << sum(d) - sum(c-1) << endl;
        }
        else {
            int c, d;
            cin >> c >> d;
            upd(c, d - a[c-1]);
        }
    }*/
    
    int ls[n + 1];
    rep(i, n+1) ls[i] = -1;
    
    vector<pair<pair<int, int>, int>> c;

    rep(i, q) {
        int l, r;
        cin >> l >> r;
        l--; r--;
        c.pb({{r, l}, i});
    }
    sort(c.begin(), c.end());
    
    vii d;
    
    int t = 0;
    
    int ssm[n + 1];
    memset(ssm, 0, sizeof ssm);
    
    rep(i, n) {
        if (ls[s[i]] != -1) {
            upd(ls[s[i]] + 1, -1);
            ssm[ls[s[i]] + 1]--;
        }
        
        ls[s[i]] = i;
        upd(i + 1, 1);
        ssm[i + 1]++;
        
        //rep(i, n+1) cout << sm[i] << " ";
        //cout << endl;
        
        //rep(j, n+1) cout << ssm[j] << " ";
        //cout << endl;
        
        while (t < q && c[t].first.first == i) {
            
            int val = sum(c[t].first.first + 1) - sum(c[t].first.second);
            d.pb({c[t].second, val});
            t++;
        }
        
        
    }
    
    sort(d.begin(), d.end());
    rep(i, d.size()) {
        cout << d[i].second << '\n';
    }

}
void querySolve() {
    int n;
    cin >> n;
    while (n--) {
        solve();
    }
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    //querySolve();
    solve();

}


Measured memory_bytes: 27364
// Code for A - Not
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

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

#define MOD 1000000007
#define mod(x) ( (x) % MOD + MOD ) % MOD

#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<typename T, typename U> void view(const std::map<T, U>& m){ for(const auto& e : m){ std::cout << e.first << "=>" << e.second << " "; } std::cout << std::endl; }

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

  if (N == 1) {
    cout << 0 << endl;
  } else {
    cout << 1 << endl;
  }

  return 0;
}


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

int digit(int n){
  int sum=0;
  while(n!=0){
    sum += n%10;
    n /= 10;
  }
  return sum;
}

int main(){
  int n,f;
  cin >> n;
  f = digit(n);
  if(n%f==0) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

using namespace std;

#define rep1(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep2(i, n, m) for (long long i = (long long)(n); i <= (long long)(m); i++)
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
const long long mod = 1e9 + 7;

int main() {
    string s; cin >> s;
    long long q; cin >> q;
    deque<char> queue;
    bool rev = false;
    for (char ch : s) queue.push_back(ch);

    rep1(i, q) {
        int t; cin >> t;
        if (t == 1) {
            rev = !rev;
        } else {
            int f; cin >> f;
            char c; cin >> c;
            if ((rev && f == 1) || (!rev && f == 2)) queue.push_back(c);
            else queue.push_front(c);
        }
    }
    if (rev) {
        while (!queue.empty()) {
            cout << queue.back(); queue.pop_back();
        }
    } else {
        while (!queue.empty()) {
            cout << queue.front(); queue.pop_front();
        }
    }
    cout << endl;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    
    int n;ll k;
    cin >> n >> k;
    
    vector<int> a(n);
    
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    
    //頂点に何番目に訪れるか記録していく
    //すでに訪れていれば記録せずおわり
    
    vector<int> s;//訪れた頂点のメモ
    vector<int> ord(n+1,-1);//何番目に訪れたか
    
    int c = 1, l = 0;
    
    {
        int v = 1;//最初は1
        while(ord[v] == -1){
            ord[v] = s.size();
            s.push_back(v);
            v = a[v-1];
        }
        //whileから抜けたとき, vはループの頭を指す
        //s.size()は ひげ+周期
        
        //ord[v]はヒゲの長さ
        //
        // 0, 1, 2, 3, 4, ...
        //0始まりは、その要素より前に含まれる要素数を表す
        
        c = s.size() - ord[v];
        l = ord[v];
    }
    
    if(k<l) cout << s[k] << endl;
    else{
        k -= l;
        k %= c;
        
        cout << s[l+k] << endl;
    }
    
    return 0;
}


Measured memory_bytes: 5864
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    string a,b,c;
    cin>>a>>b>>c;
    if (a[a.size()-1]==b[0] && b[b.size()-1]==c[0])
        cout<<"YES\n";
    else
        cout<<"NO\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define pb push_back
#define sz(x) (int)(x).size()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;


int main() {
  int n;
  string s;
  cin >> n >> s;
  int countW=0;
  int countE=0;
  int ans=INF;
  rep(i,n){
    if(s[i]=='E'){
      countE ++;
    }
  }
  rep(i,n){
    if(s[i]=='E'){
      countE --;
    }
    ans = min(ans, countW + countE);
    if(s[i]=='W'){
      countW ++;
    }
  }
  cout << ans << endl;
  return 0;
  
}

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

int n,ans,a[220];

int main(){
	cin >> n;n<<=1;
	for(int i=1;i<=n;++i)cin >> a[i];
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i+=2)
		ans+=min(a[i],a[i+1]);
	cout << ans << endl;
	return 0;
}

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

#define int long long
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define dbg(x) cout<<#x" = "<<(x)<<ln

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > mat;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

string s;

signed main() {
	cin >> s;
	s[3] = '8';
	cout << s << ln;
}

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

using namespace std;

#define mod 1000000007

int main()
{
	long long int n;
	cin >> n;
	long long int tmp;
	vector<int> ans;
	for(int i = 40; i >= 0; i--){
		if(n >= (long long int)pow(2, i) - 1){
			tmp = i;
			n -= (long long int)pow(2, i) - 1;
			break;
		}
	}
	for(int i = 0; i < 2; i++){
		for(int j = 1; j <= tmp; j++){
			ans.push_back(j);
		}
	}
	for(int i = tmp - 1; i >= 0; i--){
		if(n >= (long long int)pow(2, i)){
			n -= (long long int)pow(2, i);
			tmp++;
			ans.insert(ans.begin() + i, tmp);
			ans.push_back(tmp);
		}
	}
	cout << ans.size() << endl;
	for(int i = 0; i < ans.size(); i++){
		cout << ans[i];
		if(i == ans.size() - 1) cout << endl;
		else cout << " ";
	}
	return 0;
}

Measured memory_bytes: 512
#!/usr/bin/env python
#-*- coding:utf-8 -*-


def selectionSort(arr, N): 
    counter = 0 
    for i in range(N):
        minj = i 
        for j in range(i,N):
            if arr[minj] > arr[j]:
                minj = j 
        if minj != i: counter += 1
        arr[i], arr[minj] = arr[minj],arr[i]

    return counter,arr

def main():

    N = int(raw_input())
    A = map(int, raw_input().split())
    
    counter,sortedA = selectionSort(A, N)
    print ' '.join(map(str,sortedA))
    print counter

#def test():

if __name__ == '__main__':
    main()

Measured memory_bytes: 6460
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
const int mod = 1000000007;
ll modpow(ll a, int b) { return b ? modpow(a * a % mod, b / 2) * (b % 2 ? a : 1) % mod : 1; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }

void solve();

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

    int T;
    // cin >> T;
    T = 1;

    while (T--) {
        solve();
    }
}

void solve() {
  string s, t;
  cin >> s >> t;
  int a, b;
  cin >> a >> b;
  string u;
  cin >> u;

  if (u == s) a--;
  else b--;
  cout << a << " " << b << endl;
}


Measured memory_bytes: 256
n, a, b = map(int, input().split())
s = input()
count = 0
cnt = 0
for i in range(len(s)):
    if s[i] == "c":
        print("No")
    elif s[i] == "a":
        if count < a+b:
            print("Yes")
            count +=1
        else:
            print("No")
    else:
        if count < a + b:
            if cnt < b:
                print("Yes")
                cnt+=1
                count+=1
            else:
                print("No")
        else:
            print("No")



Measured memory_bytes: 4016
// C - Skip
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int gcd(int a, int b){return b? gcd(b, a%b): a;}
int in(){int x;cin>>x;return x;}

int main(){
	int N,X; cin>>N>>X;
	int g = abs(in() - X);
	rp(i, 1, N) g = gcd(g, abs(in() - X));
	cout<< g <<endl;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		
		int n = scan.nextInt();
		
		long bi = 1;
		
		for(int i=1;i<=n;i++)
		{
			bi *= i;
		}
		System.out.println(bi);
		
		scan.close();
	}
}

Measured memory_bytes: 25944
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
		string s = Console.ReadLine();
    int n = s.Length;
    long k = long.Parse(Console.ReadLine());
		long answer = 0;
    long answerNo = 0;//1文字目を変更しない場合
    long answerYes = 0;
    bool finalChanged = false;

    for(int i = 1; i < n; i++)
    {
      if(s[i] == s[i-1])
      {
        answerNo++;
        if(i == n-1) finalChanged = true;
        i++;
        //Console.WriteLine(i+" a");
      }
    }

    if(!finalChanged && n >= 2 && s[0] == s[n-1])//最初の文字を変える
    {
      finalChanged = false;
      answerYes++;
      for(int i = 2; i < n; i++)
      {
        if(s[i] == s[i-1])
        {
          answerYes++;
          if(i == n-1) finalChanged = true;
          i++;
        }
      }

      if(!finalChanged)//最初の文字を変える
      {
        answer = answerNo + answerYes*(k-1);
      }else
      {
        if(k % 2 == 0) answer = answerNo*(k/2) + answerYes*(k/2);
        else answer = answerNo*(k/2 +1) + answerYes*(k/2);
      }
    }else
    {
      answer = answerNo * k;
    }

    if(n == 1)
    {
      answer = k/2;
    }

		Console.WriteLine(answer);
	}
}

Measured memory_bytes: 11220
#include<stdio.h>
int main()
{
	int a,b,c,d,x,i;
	
	scanf("%d%d%d%d",&a,&b,&c,&d);
	
	for(i=0;i<101;i++){
		if(i>=a&&i>=c&&i<b&&i<d){
			x++;
		}
	}
	printf("%d",x);
	return 0;
}

Measured memory_bytes: 128
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>

using namespace std;

typedef unsigned int uint;
typedef long long llong;
typedef unsigned long long ullong;
typedef long double ldouble;

typedef vector<llong> vecllong;
typedef vector<vecllong> vvecllong;

template<class T> inline bool chmin(T& to, T compare) {
    if (to > compare) {
        to = compare;
        return true;
    }
    return false;
};

template<class T> inline bool chmax(T& to, T compare) {
    if (to < compare) {
        to = compare;
        return true;
    }
    return false;
};

const llong MOD = 1e9 + 7;
const llong INF = 1e17;

#define FOR(i, n) for (llong i = 0; i < n; i++)
#define FORS(i, a, b) for (llong i = a; i < b; i++)
#define FORR(i, n) for (llong i = n; i > 0; i++)

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

    llong N;
    cin >> N;

    vvecllong act(N + 1, vecllong(3, 0));

    FOR(i, N) {
        cin >> act[i][0] >> act[i][1] >> act[i][2];
    }

    vvecllong dp(N + 2, vecllong(3, -INF));  // dp[day][choose]
    dp[0][0] = 0;
    dp[0][1] = 0;
    dp[0][2] = 0;

    FOR(day, N + 1) {
        FOR(type, 3) {
            FOR(beforeType, 3) {
                if(type == beforeType) continue;
                dp[day + 1][type] = max(dp[day + 1][type], dp[day][beforeType] + act[day][type]);
            }
        }
    }

    llong ans = max(dp[N][0], dp[N][1]);
    ans = max(ans, dp[N][2]);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 11264
function Main(input) {
  input = input.trim().split("\n").map(function(x) { return x.split(" ")});
  var S = input[0];
  var Q = parseInt(input[1], 10);
  //var arr_qu;
  var nReverse = 0;
  var addHead = [];
  var addTail = [];
  for (var i = 0; i < Q; i++){
    if (input[i + 2][0] === '1') {
      nReverse ++;
      continue;
    }
    if ((parseInt(input[i + 2][1], 10) + nReverse) % 2 ===0) {
      addTail.push(input[i + 2][2]);
      continue;
    }
    addHead.push(input[i + 2][2]);
  }
  var ans = addHead.reverse().concat(S[0].split(""), addTail);
  if (nReverse % 2 === 1) ans = ans.reverse();
  console.log(ans.join(""));
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 84640
n = int(input())
txy = []
txy.append([0,0,0])
for i in range(n):
    txy.append(list(map(int, input().split())))


t = 0
x = 1
y = 2

for i in range(1,n+1):
    if txy[i][t] - txy[i-1][t] < abs(txy[i][x] - txy[i-1][x]) + abs(txy[i][y] - txy[i-1][y]) or (abs(txy[i][x] - txy[i-1][x]) + abs(txy[i][y] - txy[i-1][y]))%2 != (txy[i][t] - txy[i-1][t])%2:
        print("No")
        exit()
print("Yes")


Measured memory_bytes: 27300
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <map>
#include <utility>
#include <queue>
#define ull unsigned long long
#define ll long long
#define mod 1000000007
using namespace std;

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

    ll br = 0;
    string g;
    map <string, ll> m;
    for (int i=0;i<n;i++){
        cin>>g;
        sort(g.begin(), g.end());
        br+=m[g];
        m[g]++;
    }

    cout<<br<<endl;
    return 0;
}


Measured memory_bytes: 11136