akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

const int N = 10010;

int n;
int a[N], b[N];
priority_queue<int> Q;

int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; i++)
		scanf("%d", &a[i]);
	for(int i = 1; i <= n; i++)
		scanf("%d", &b[i]);
	for(int i = 1; i <= n; i++)
		if(b[i] - a[i] > 0)Q.push(b[i] - a[i]);
	for(int i = 1; i <= n; i++)
		if(b[i] - a[i] < 0)
		{
			int x = a[i] - b[i];
			while(!Q.empty())
			{
				int p = Q.top();
				if(p == 1)break;
				Q.pop();
				if(p < x * 2)
				{
					x -= p / 2;
				}
				else
				{
					Q.push(p - x * 2);
					x = 0;
					break;
				}
			}
			if(x)
			{
				puts("No");
				return 0;
			}
		}
	puts("Yes");
}

Measured memory_bytes: 384
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <algorithm>

using namespace std;

#define mp make_pair
#define pb push_back
#define x first
#define y second

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vpii;

bool d[100010];

int main()
{
	#ifndef ONLINE_JUDGE
		//freopen("input.txt","r",stdin);
		//freopen("output.txt","w",stdout);
	#endif
	int n,m;scanf("%d%d",&n,&m);
	for (int i=1;i<=m;i++)
	{
		int x,y;scanf("%d%d",&x,&y);
		d[x]^=1;d[y]^=1;
	}
	for (int i=1;i<=n;i++) if (d[i]) {puts("NO");return 0;}
	puts("YES");
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void) {
    char str[200];
    fgets(str, 200, stdin);

    int diff = 'a' - 'A';

    int i;
    while(str[i] != '\0') {
        if(str[i] >= 'a' && str[i] <= 'z') str[i] -= diff;                                                                                              
        printf("%c", str[i++]);
    }   
        
    return 0; 
}   

Measured memory_bytes: 524
#include <stdio.h>

#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
using ll = long long;
using VI = vector<int>;
using VF = vector<float>;
using VL = vector<ll>;
using VVL = vector<VL>;

#define FOR(i, start, end) for(ll i = (start), (i ## xxxx_end)=(end); i < (i ## xxxx_end); ++i)
#define FORD(i, start, end) for(ll i = (start), (i ## xxxx_end)=(end); i > (i ## xxxx_end); --i)
#define REP(i, n) FOR(i, 0, n)
#define REPD(i, n) FORD(i, n - 1, -1)

#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

template<class T, class U>bool chmax(T &a, const U &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T, class U>bool chmin(T &a, const U &b) { if (b<a) { a=b; return 1; } return 0; }

template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}

#define INF 1000000000000
#define MOD 10000007

ll N;
VL H, memo;

ll f(ll i) {
    if(i >= N - 1) {
        return 0;
    }
    if(memo[i] == -1) {
        ll c1 = abs(H[i] - H[i + 1]) + f(i + 1);
        ll c2 = i + 2 < N ? abs(H[i] - H[i + 2]) + f(i + 2) : INF;
        memo[i] = min(c1, c2);
    }
    return memo[i];
}

void solve() {
  cin >> N;
  H = VL(N);
  memo = VL(N, -1);
  for (auto &i : H) cin >> i;
  print(f(0));
}

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

Measured memory_bytes: 4992
#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 maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
const int MX = 200005;
 
 
 
int main() {

    ll a;
    scanf("%lld",&a);
    ll b;
    scanf("%lld",&b);
    ll c;
    scanf("%lld",&c);

    ll d = c;
    if(d>a+b+1){
        d = a+b+1;
    }

    int ans = 0;
    ans = b+d;

    cout << ans << endl;
   
    return 0;
}

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	Int n; cin >> n;
	vector<Int> a(n);
	for(auto &i:a) cin >> i;
	vector<Int> b(n);
	for(Int i=0; i<n; ++i)
		b[0] += (1-2*(i%2)) * a[i];
	for(Int i=1; i<n; ++i)
		b[i] = 2*a[i-1] - b[i-1];
	for(Int i=0; i<n; ++i)
		cout << b[i] << " \n"[i+1==n];
}

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

int h, w, k;
char grid[10][10];

int main(){
    scanf("%d%d%d", &h, &w, &k);
    for (int i=0; i<h; ++i){
        for (int j=0; j<w; ++j){
            scanf(" %c", &grid[i][j]);
        }
    }
    int cnt = 0, ans = 0;
    for (int i=0; i<(1 << h); ++i){
        for (int j=0; j<(1 << w); ++j){
            cnt = 0;
            for (int _i = 0; _i < h; ++ _i){
                for (int _j = 0; _j < w; ++_j){
                    if ((i & (1 << _i)) != 0){
                        if ((j & (1 << _j)) != 0){
                            if (grid[_i][_j] == '#'){
                                ++cnt;
                            }
                        }
                    }
                }
            }
            if (cnt == k) ++ans;
        }
    }
    printf("%d", ans);
}


Measured memory_bytes: 3824
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define ll long long
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define vi vector<int>
#define INF (1<<30)-1
using namespace std;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }

int main(){
  cin.tie(0), ios::sync_with_stdio(false);
  int n,k; cin >> n >> k;
  string s; cin >> s;
  vi cnt;
  char a = s[0];
  int num = 0;
  rep(i,n){
    if(a != s[i]){
      cnt.push_back(num);
      num = 0;
      a = s[i];
    }
    num++;
  }
  cnt.push_back(num);
  rep(i,cnt.size()-1){
    if(i < 2*k){
      cnt[i+1] += cnt[i];
      cnt[i] = 1;
    }
  }
  int ans = 0;
  rep(i,cnt.size()) ans += cnt[i]-1;
  cout << ans;
  cout << "\n";
  return 0;
}


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

int even(int len, char S[256]) {
	int i;
	if(len % 2 == 1) {
		return 0;
	}
	for(i = 0; i < len / 2; i += 1) {
		if(S[i] != S[(len/2) + i]) {
			return 0;
		}
	}
	return 1;
}

int main(void) {
	int i;
	char S[256];
	int len, ans;

	fgets(S, sizeof(S), stdin);

	len = strlen(S);
	if(S[len - 1] == '\n') {
		len -= 1;
		S[len] = '\0';
	}
	ans = 0;
	for(i = len - 1; i > 1; i -= 1) {
		if(even(i, S) == 1) {
			ans = i;
			break;
		}
	}

	printf("%d\n", i);

	return 0;
}


Measured memory_bytes: 2004
while True:
  n = int(input())
  if n == 0:
    break
  c = 0
  l = []
  d = {}
  for i in range(n):
    num,x,y = map(int,input().split())
    if num in d:
      d[num] = d[num] + x*y
    else:
      d[num] = x*y
      l.append(num)
  for i in l:
    if d[i] >= 1000000:
      print(i)
      c += 1
  if c == 0:
    print('NA')

Measured memory_bytes: 7792
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <fstream>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <functional>
#define inf 0x3f3f3f3f
#define inff -30000000
using namespace std;
typedef long long ll;
const int MAXN=1e5+10;
const int MAX=1000000+10;
bool notprime[MAX];
int num=0;
void init(){
    memset(notprime,0,sizeof(notprime));
    for(int i=2;i*i<=MAX;i++){
        if(!notprime[i]){
            for(int j=i*i;j<=MAX;j+=i)
                notprime[j]=1;
        }
    }
}
int main(){
    #ifdef SIYU
    freopen("in.txt","r",stdin);
    #endif // SIYU
    int n;
    init();
    while(cin>>n){
        int ans=0;
        for(int i=2;i<=n;i++){
            if(!notprime[i])
                ans++;
        }
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 4056
#include<bits/stdc++.h>
#define rep(i, n) for(int (i)=0 ;i <(n); ++(i))
#define REP(i,m,n) for(int (i) = (m); (i) <= (n); ++(i))
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)? "YES":"NO")
typedef long long ll;
using namespace std;

int main() {
  vector<int> a(3);
  rep(i, 3) cin >> a[i];
  sort(a.begin(), a.end());
  
  cout << 10*a[2] + a[1] + a[0] << endl;
  return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <climits>
using namespace std;
#define MOD int(998244353)
#define INF (long long)(1e18)

long long modinv(long long a, long long m)
{
    long long b = m, u = 1, v = 0;
    while (b)
    {
        long long t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0)
        u += m;
    return u;
}

void comb(long long n, long long k, vector<long long> &c)
{
  long long a = 1;
  for(long long i = 1; i <= n; i++)
    a = (a * i) % MOD;

  c.push_back(1);
  for(long long i = 0; i < k; i++){
    c.push_back(((((n - i - 1) * c[i]) % MOD) * modinv(i + 1, MOD)) % MOD);
  }
}

long long mod_pow(long long _x, long long _n)
{
    long long ret = 1;
    while (0 < _n)
    {
        if ((_n % 2) == 0)
        {
            _x = (_x * _x) % MOD;
            _n >>= 1;
        }
        else
        {
            ret = (ret * _x) % MOD;
            --_n;
        }
    }
    return ret;
}

int main()
{
    cout.precision(18);

    long long N, M, K;
    cin >> N >> M >> K;

    vector<long long> c;
    comb(N, K, c);

    long long t = 0;
    for(long long i = 0; i <= K; i++){
      t += (M * mod_pow(M - 1, N - i - 1) % MOD) * c[i] % MOD;
      t %= MOD;
    }

    cout << t << endl;

}


Measured memory_bytes: 5372
#include <bits/stdc++.h>
#define LL long long
#define pb push_back
#define mp make_pair
#define INF 0x3f3f3f3f
#define Inf 1000000000000000000LL
using namespace std;
typedef pair<int,int>pii;
int n,k;
vector<int>G[100010];
int d[100010];
priority_queue<pii,vector<pii>,greater<pii> >pq;
int main(){
	memset(d,-1,sizeof(d));
	cin>>n;
	for(int i=1,x,y;i<n;i++){
		cin>>x>>y;
		G[x].pb(y);
		G[y].pb(x);
	}
	cin>>k;
	for(int i=1,x,y;i<=k;i++){
		cin>>x>>y;
		d[x]=y;
		pq.push(mp(y,x));
	}
	while(!pq.empty()){
		pii p=pq.top();
		pq.pop();
		for(auto x:G[p.second]){
			if(d[x]==-1){
				d[x]=d[p.second]+1;
				pq.push(mp(d[x],x));
			}
		}
	}
	for(int i=1;i<=n;i++){
		for(int x:G[i]){
			if(abs(d[i]-d[x])!=1){
				puts("No");
				return 0;
			}
		}
	}
	puts("Yes");
	for(int i=1;i<=n;i++)cout<<d[i]<<endl;
	return 0;
}


Measured memory_bytes: 7924
from math import ceil

def check(A, K, L):
    i = 0
    for a in A:
        i += ceil(a/L)-1
        if i > K:
            return False
    return True

N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort(reverse=True)
l = 0
r = A[0]
while l + 1 < r:
    m = (l+r)//2
    if check(A, K, m):
        r = m
    else:
        l = m
print(r)

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

#define int             long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )    for( int (i) = (m); (i) >= 0; (i)-- )
#define ALL( a )        (a).begin(), (a).end()
#define MP              make_pair

using namespace std;
using P = pair<int, int>;

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 int INF = 1e18;
const int MOD = 1e9 + 7;

int G[10][10];
int wall[201][201];
int d[10][10];

signed main(){
    int H, W; cin >> H >> W;

    REP( i, 10 ){
        REP( j, 10 ){
            cin >> G[i][j];
        }
    }

    REP( i, H ){
        REP( j, W ){
            cin >> wall[i][j];
        }
    }

    fill( d[0], d[10], INF );
    REP( i, 10 ) d[i][i] = 0;

    REP( i, 10 ){
        if( i == 1 ) continue;
        priority_queue<P, vector<P>, greater<P> > pq;
        pq.emplace( 0, i );

        while( !pq.empty() ){
            P p = pq.top(); pq.pop();
            int v = p.second;
            if( d[i][v] < p.first ) continue;
            REP( nv, 10 ){
                if( nv == v ) continue;
                if( d[i][nv] > d[i][v] + G[v][nv] ){
                    d[i][nv] = d[i][v] + G[v][nv];
                    pq.emplace( d[i][nv], nv );
                }
            }
        }
    }


    int ans = 0;
    REP( i, H ){
        REP( j, W ){
            if( wall[i][j] == -1 ) continue;
            ans += d[wall[i][j]][1];
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
  int A,B,C,flag;
  cin >> A >> B >> C;
  flag=0;
  if(A==B) flag++;
  if(C==B) flag++;
  if(A==C) flag++;
  if(flag==1)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

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

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

void solve(){
    int N;
    cin >> N;

    ll numodd = 0;
    for (int i = 0; i < N; i++) {
        ll A;
        cin >> A;
        if (A & 1) {
            numodd++;
        }
    }

    if (numodd & 1) {
        cout << "NO" << endl;
    }else{
        cout << "YES" << endl;
    }


    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k,i;
    double ans,res=0;
    cin>>n>>k;
    for(i=1;i<=n;i++)
    {
        ans=1.0/n;
        int a=i;
        while(a<k)
        {
            a*=2;
            ans/=2;
        }
        res+=ans;
    }
    cout<<fixed<<setprecision(12)<<res<<endl;
}


Measured memory_bytes: 256
local mod = 1000000007
local mfl = math.floor
local h, w, K = io.read("*n", "*n", "*n")

local linepat = 1
for i = 1, w - 1 do
  linepat = linepat * 2
end
local linetbl = {}
for i = 0, linepat - 1 do
  local lineidx, mul = 0, 1
  local box = {}
  for j = 1, w - 1 do box[j] = false end
  for j = 1, w - 1 do
    if i % 2 == 1 then
      box[j] = true
      lineidx = lineidx + mul
      i = i - 1
    end
    i = i / 2
    mul = mul * 2
  end
  local isok = true
  for j = 1, w - 2 do
    if box[j] and box[j + 1] then isok = false break end
  end
  if isok then table.insert(linetbl, lineidx) end
end
-- for i = 1, #linetbl do print(linetbl[i]) end

local t, u = {}, {}
for i = 1, w do t[i], u[i] = 0, 0 end
t[1] = 1
for i = 1, h do
  for j = 1, w do u[j] = t[j] end
  for j = 2, #linetbl do
    local line_i = linetbl[j]
    local k = 1
    while k <= w - 1 do
      if line_i % 2 == 1 then
        u[k] = (u[k] + t[k + 1]) % mod
        u[k + 1] = (u[k + 1] + t[k]) % mod
        line_i = mfl((line_i - 1) / 4)
        k = k + 2
        if k == w then u[w] = (u[w] + t[w]) % mod end
      else
        u[k] = (u[k] + t[k]) % mod
        if k == w - 1 then u[k + 1] = (u[k + 1] + t[k + 1]) % mod end
        k = k + 1
        line_i = line_i / 2
      end
    end
  end
  for j = 1, w do t[j] = u[j] end
end
print(t[K])


Measured memory_bytes: 256
from sys import stdin


def main():
    N = int(stdin.readline().rstrip())
    As = [int(x) for x in stdin.readline().rstrip().split()]
    count = 0
    while True:
        As = [x // 2 for x in As if x % 2 == 0]
        if len(As) == N:
            count += 1
            continue
        break
    print(count)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
n,m = map(int,input().split())
a = list(map(int,input().split()))
bc = list(list(map(int,input().split())) for i in range(m))

a.sort()
bc.sort(reverse=True,key=lambda x:x[1])
t = 0
for i in range(m):
    for j in range(bc[i][0]):
        if t != n:
            if a[t] < bc[i][1]:
                a[t] = bc[i][1]
                t+=1
            else:
                break
        else:
            break
    else:
        continue
    break

print(sum(a))


Measured memory_bytes: 33476
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// gp_hash_table<int, int> mapka;

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

template<class C> void mini(C &a4, C b4) { a4 = min(a4, b4); }
template<class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); }

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);
  string s;
  cin >> s;
  vector<int> t;
  R(i,SZ(s))if(!i || s[i-1] != s[i]){
    t.PB(s[i] - 'A');
  }
  int n = SZ(t);
  vector<PII> ile(3);
  R(i,3)ile[i].SE = i;
  R(i,n){
    ile[t[i]].FI++;
  }
  sort(ALL(ile));
  if(ile[0].FI == 0){
    cout << "\n";
    return 0;
  }
  vector<int> scal(3);
  R(i,3)scal[ile[i].SE] = i;
  R(i,n)t[i] = scal[t[i]];
  int roz = ile[2].FI - ile[1].FI;
  debug(1,t,roz);
  if(roz && t[0] == 2){
    vector<int> t2(n-1);
    for(int i = 1;i < SZ(t); i++){
      t2[i-1] = t[i];
    }
    swap(t,t2);
    n--;
    roz--;
    ile[2].FI--;
  }
  debug(2,t,roz);
  
  if(roz && t.back() == 2){
    t.pop_back();
    roz--;
    n--;
    ile[2].FI--;
  }
  debug(3,t,roz);
  
  vector<int> t2;
  R(i,n){
    if(roz && t[i] == 2 && t2.back() != t[i+1]){
      roz--;
      ile[2].FI--;
    }else
      t2.PB(t[i]);
  }
  swap(t2,t);
  debug(4,t,roz);
  
  t2.clear();
  n = SZ(t);
  R(i,n){
    if(roz && t[i] == 2 && t2.back() == 0){
      t2.pop_back();
      ile[0].FI--;
      ile[2].FI--;
      roz--;
    }else{
      t2.PB(t[i]);
    }
  }
  swap(t2,t);
  debug(5,t,roz);
  
  t2.clear();
  n = SZ(t);
  roz = ile[1].FI - ile[0].FI;
  R(i,n){
    if(roz && t[i] != 0 && SZ(t2) >= 2 && t2.back() != 0 && t2[SZ(t2)-2] != 0){
      t2.pop_back();
      roz--;
      ile[1].FI--;
      ile[2].FI--;
    }else{
      t2.PB(t[i]);
    }
  }  
  swap(t2,t);
  if(roz){
    t.pop_back();
    t.pop_back();
  }
  debug(6,t,roz);
  for(int el:t){
    cout << char('A' + ile[el].SE); 
  }
  cout << "\n";
}


Measured memory_bytes: 25736
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<int,int>
#define F first
#define S second
#define mod 1000000007
#define INF 9000000000000000000
int V[105];
int mi,n;
bool dp[100010];
bool judge[100010];
bool solve(int x){
    if(judge[x])return dp[x];
    bool ans=false;
    if(x<mi)ans=false;
    else{
        rep(i,n){
            if(V[i]>x)break;
            ans|=!solve(x-V[i]);
        }
    }
    judge[x]=true;
    return dp[x]=ans;
}
signed main(void){
    int k;cin>>n>>k;
    rep(i,100010)dp[i]=judge[i]=false;
    rep(i,n)cin>>V[i];
    mi=V[0];
    if(solve(k))cout<<"First"<<endl;
    else cout<<"Second"<<endl;
}

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

typedef long long ll;
const ll INF = 1LL<<60, MOD = 1e9 + 7;
const double EPS = 1e-9, PI = 3.141592653589793;
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define all(v) (v).begin(), (v).end()
#define fi first
#define se second
#define m_p make_pair

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll n,ans=0;
  cin >> n;
  vector<ll> p(n);
  rep(i,n) cin >> p[i];
  rep(i,n-2){
    if(p[i+1]>p[i] && p[i+1]<p[i+2]) ans++;
    else if(p[i+1]<p[i] && p[i+1]>p[i+2]) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import Control.Applicative
import Control.Monad
import Data.Array
import Data.Array.ST
import Data.Char
import Data.List
import qualified Data.Map as M
import qualified Data.Set as S
import Text.Printf

readInts :: IO [Int]
readInts = map read . words <$> getLine

doOp :: Array Int Char -> IO (Array Int Char)
doOp ary = do
  (op:a0:b0:rs) <- words <$> getLine
  let a = read a0 :: Int
  let b = read b0 :: Int
  case op of
    "print"   -> do
      forM_ [a..b] $ \i -> do
        putChar $ ary ! i
      putChar '\n'
      return ary
    "reverse" -> do
      return $ ixmap (bounds ary) f ary
       where
        f i
          | i < a     = i
          | i > b     = i
          | otherwise = a + b - i
    "replace" -> return $ runSTArray $ do
      let p = listArray (a,b) (head rs) :: Array Int Char
      mary <- thaw ary
      forM_ [a..b] $ \i -> do
        writeArray mary i (p!i)
      return mary

main :: IO ()
main = do
  str <- getLine
  let ary = listArray (0, length str - 1) str
  n <- readLn
  void $ foldM (\acc _ -> doOp acc) ary [1..n]



Measured memory_bytes: 10404
n,m,l = map(int,input().split())

a = [[]for _ in range(n)]
b = [[]for _ in range(m)]

for i in range(n):
    a[i] = list(map(int,input().split()))
for i in range(m):
    b[i] = list(map(int,input().split()))

for i in range(n):
    c = []
    for j in range(l):
        num = 0
        for k in range(m):
            num += a[i][k] * b[k][j]
        c.append(str(num))
    print(' '.join(c))


Measured memory_bytes: 6248
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
ll MOD=1000000007;
int inf=1000000000;
ll INF=10000000000000000;
int main(){
    int n,ans=0;
    cin >> n;
    rep(i,10){
        ans+=n%10;
        n=n/10;
    }
    if (ans==1) cout << 10 << endl;
    else cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const long double PI = (acos(-1));
#define rep(i, x, n) for (int i = x; i < (int)(n); i++)
#define sc(x) scanf("%d",&x)
#define scll(x) scanf("%lld",&x)

int main(){
    ll a, b, n;
    scll(a), scll(b), scll(n);
    ll x = min(b-1, n);
    cout << a*x/b - a*(x/b) << endl;
    return 0;
}

Measured memory_bytes: 3660
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
 int main() {
	 map<string, int> score;
	 int N;
	 cin >> N;
	 for (int i = 0; i < N; i++) {
		 string s;
		 cin >> s;
		 score[s]++;
	 }
	 int M;
	 cin >> M;
	 for (int i = 0; i < M; i++) {
		 string s;
		 cin >> s;
		 score[s]--;
	 }
	 int ma = 0;
	 for (auto itr = score.begin(); itr != score.end(); itr++) ma = max(ma, itr->second);
	 cout << ma << endl;
}

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

int main() {
  int n, a[3];
  cin >> n;
  while (n--) {
    for (auto& e : a) cin >> e;
    sort(a, a + 3);
    bool f = a[0] * a[0] + a[1] * a[1] == a[2] * a[2];
    if (f) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
}

Measured memory_bytes: 3116
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#define MOD 1000000007
#define mkp make_pair
typedef long long ll;
using namespace std;

int N;
vector<ll> X,Y;
vector<char> d;

const double INF = 1e10;

void chmin(double &a,double b){
    if(a>b) a=b;
}

void chmax(double &a,double b){
    if(a<b) a=b;
}

class code{
public:
    vector<double> lef,rig;
    code():lef(3,INF),rig(3,-INF){}

    void add(double a,int c){
        c++;
        chmin(lef[c],a);
        chmax(rig[c],a);
    }

    vector<double> listTimes(){
        vector<double> res;
        for(int i=0;i<3;i++){
            for(int j=0;j<i;j++){
                int a=i-1;
                int b=j-1;
                double tl=(lef[j]-lef[i])/(a-b);
                double tr=(rig[j]-rig[i])/(a-b);

                if(tl>0) res.push_back(tl);
                if(tr>0) res.push_back(tr);
            }
        }
        return res;
    }

    double getVal(double t){
        double l=INF,r=-INF;
        for(int i=0;i<3;i++){
            chmin(l,lef[i]+(i-1)*t);
            chmax(r,rig[i]+(i-1)*t);
        }
        return (r-l);
    }
};

int main(){
  cin>>N;
  X.resize(N);
  Y.resize(N);
  d.resize(N);
  for(int i=0;i<N;i++) cin>>X[i]>>Y[i]>>d[i];

  code xd,yd;
  for(int i=0;i<N;i++){
      if(d[i]=='U'){
          xd.add(X[i],0);
          yd.add(Y[i],1);
      }
      if(d[i]=='D'){
          xd.add(X[i],0);
          yd.add(Y[i],-1);
      }
      if(d[i]=='L'){
          xd.add(X[i],-1);
          yd.add(Y[i],0);
      }
      if(d[i]=='R'){
          xd.add(X[i],1);
          yd.add(Y[i],0);
      }
  }

  vector<double> v,w;
  v=xd.listTimes();
  w=yd.listTimes();
  v.push_back(0);
  w.push_back(0);

  double ans=1e18;
  for(int i=0;i<v.size();i++){
      double x=xd.getVal(v[i]);
      double y=yd.getVal(v[i]);
      chmin(ans,x*y);
  }
  for(int i=0;i<w.size();i++){
      double x=xd.getVal(w[i]);
      double y=yd.getVal(w[i]);
      chmin(ans,x*y);
  }

  cout<<fixed<<setprecision(10)<<ans<<endl;


  return 0;
}


Measured memory_bytes: 2048
n,a ,b = map(int,input().split())
s = input()
winner = 0
student = 0
for i in range(n):
    if s[i] == 'a':
        if winner < a+b:
            print('Yes')
            winner +=1
        else:print('No')
        
    elif s[i] == 'b':
        if winner < a+b and student < b:
            print('Yes')
            winner += 1
            student +=1
        else:print('No')
    else:
        print('No')

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

#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i)

mt19937 Rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

template <typename T>
inline void chkmax(T &x, T y) { if (x < y) x = y; }

template <typename T>
inline void chkmin(T &x, T y) { if (x > y) x = y; }

inline int read() {
  #define nc getchar()
  int x = 0;
  char c = nc;
  while (c < 48) c = nc;
  while (c > 47) x = x * 10 + (c ^ 48), c = nc;
  return x;
  #undef nc
}

typedef long long ll;
typedef pair <int, int> pii;
ll N;

vector <ll> pri;

namespace CRT {
  int tot;
  ll A[20], P[20];
  
  ll mul(ll a, ll b, ll P) {
    ll res = 0;
    for (; b; b >>= 1, a = (a + a) % P) {
      if (b & 1) res = (res + a) % P;
    }
    return res;
  }
  
  ll qp(ll a, ll k, ll P) {
    a %= P;
    ll res = 1;
    for (; k; k >>= 1, a = mul(a, a, P)) {
      if (k & 1) res = mul(res, a, P);
    }
    return res;
  }
  
  void exgcd(ll a, ll b, ll &x, ll &y) {
    if (!b) return x = 1, y = 0, void();
    exgcd(b, a % b, y, x), y -= a / b * x;
  }
  
  ll inv(ll A, ll P) {
    ll x, y = 0;
    exgcd(A, P, x, y);
    return (x + P) % P;
  }
  
  ll solve() {
    ll res = 0;
    rep(i, 1, tot) {
      ll m = N / P[i];
      ll im = inv(m, P[i]);
      res = (res + mul(A[i], mul(m, im, N), N)) % N;
    }
    return !res ? N : res;
  }
}

void getget() {
  ll x = N;
  rep(i, 2, sqrt(N) + 0.5) if (x % i == 0) {
    ll tmp = 1;
    while (x % i == 0) x /= i, tmp *= i;
    pri.push_back(tmp);
  }
  if (x > 1) pri.push_back(x);
}

void solve() {
  cin >> N;
  N *= 2;
  getget();
  int sz = pri.size(), all = (1 << sz) - 1;
  ll res = 1e18;
  rep(S, 0, all) {
    CRT::tot = sz;
    rep(i, 0, sz - 1) {
      if (S >> i & 1) {
        CRT::A[i + 1] = 0, CRT::P[i + 1] = pri[i];
      } else {
        CRT::A[i + 1] = pri[i] - 1, CRT::P[i + 1] = pri[i];
      }
    }
    chkmin(res, CRT::solve());
  }
  cout << res << endl;
}

signed main() {
//  int T = read();
//  while (T--) solve();
  solve();
  return 0;
}

Measured memory_bytes: 3688
#include <iostream>

using namespace std;

int main(){
  int N, A, B, total = 0, foreign = 0;
  char S = 0;

  cin >> N >> A >> B;
  for(int i = 0;i < N;i++){
    cin >> S;
    if(S == 'a' && total < (A + B)){
      cout << "Yes" << endl;
      total++;
    } else if(S == 'b' && total < (A + B) && foreign < B){
      cout << "Yes" << endl;
      total++;
      foreign++;
    } else {
      cout << "No" << endl;
    }
  }
  
  return 0;
}


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

using namespace std;
using ll = long long int;

ll n,k,ara[105],mod=1e9+7,dp[105][100005],cum[105][100005];

int main()
{
    ll i,j;
    cin>>n>>k;

    for(i=1; i<=n; i++) cin>>ara[i];

    for(i=0; i<=k; i++)
    {
        dp[0][i]=0;
    }

    for(i=0; i<=n; i++)
    {
        dp[i][0]=1;
        cum[i][0]=1;
    }

    ll temp=0;

    for(i=0; i<=k; i++)
    {
        temp=((temp%mod)+(dp[0][i]%mod))%mod;
        cum[0][i]=temp;

    }

    for(i=1; i<=n; i++)
    {
        temp=1;
        for(j=1; j<=k; j++)
        {
            ll mn=min(j,ara[i]);
            ll st=j-mn,en=j,sum;
            if(st) sum=((cum[i-1][en]%mod)-(cum[i-1][st-1]%mod))%mod;
            else sum=cum[i-1][en]%mod;
            if(sum<0) sum+=mod;
            dp[i][j]=sum;
            temp=((temp%mod)+(dp[i][j]%mod))%mod;
            cum[i][j]=temp;
        }
    }

    cout<<dp[n][k]<<endl;
    return 0;

}


Measured memory_bytes: 160000
#include <iostream>
#include <cstdio>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <stdlib.h>
#include <functional>
#include <string>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <nmmintrin.h>
#include <chrono>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#ifdef _MSC_VER
#define __builtin_popcount _mm_popcnt_u32
#define __builtin_popcountll _mm_popcnt_u64
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}

class Graph {
public:
	int vn;
	int sumcost = 0;
	vector<vector<pii>> g;

	Graph(int n) {
		vn = n;
		g.resize(n);
	}
	virtual void con(int a, int b, int w) = 0;
	int getWeight(int f, int t) {
		auto itr = lower_bound(ALL(g[f]), make_pair(t, INT_MIN));
		if (itr != g[f].end())
			return itr->second;
		return INT_MIN;
	}
	int Costsum() {
		return sumcost;
	}
	void scan(int edcount, bool oindexed, bool w) {
		REP(i, edcount) {
			int a, b, c = 1;
			scanf("%d %d", &a, &b);
			if (w)scanf("%d", &c);
			con(a - oindexed, b - oindexed, c);
		}
	}
};
class BiDGraph : public Graph {//無向
public:
	BiDGraph(int n) : Graph(n) {}

	void con(int a, int b, int w = 1) {
		g[a].push_back({ b,w });
		g[b].push_back({ a, w });
		sumcost++;
	}
};
template<class T>
vector<ll> Dijkstra(T g, int st) {
	priority_queue<pii, vector<pii>, greater<pii>> que;

	que.push({ 0, st });
	int kk = 0;
	vector<ll> res(g.vn, -1);
	while (kk < g.vn && que.size()) {
		pii cur = que.top();
		que.pop();
		if (res[cur.second] != -1)
			continue;
		res[cur.second] = cur.first;
		kk++;
		for (auto itr : g.g[cur.second]) {
			if (res[itr.first] == -1)
				que.push({ cur.first + itr.second,itr.first });
		}
	}
	return res;
}
signed main() {
	int n;
	cin >> n;
	vector<ll> num(n);

	REP(i, n) {
		scanf("%lld", &num[i]);
	}

	sort(ALL(num));
	ll ret = 0;
	ll bans = 0;
	vector<ll> bb(n);
	bool f = 1;
	while (f) {
		f = 0;
		ll ans = 0;
		REP(i, n) {
			num[i] += bans-bb[i];

			if (num[i] >= n)
				f = 1;

			ans += (num[i]) / n;
			bb[i] = (num[i]) / n;
			num[i] -= ((num[i]) / n) * n;
		}
		ret += ans;

		bans = ans;
	}

	printf("%lld\n", ret);
	return 0;
}

Measured memory_bytes: 256
l = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K = int(input())

print(l[K - 1])


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

int main() {
  long long int N, A, B;
  cin >> N >> A >> B;
  long long n = N / (A + B);
  long long int p = N - n * (A + B);
  if (p <= A) {
    printf("%lld\n", A * n + p);
  }
  else {
    printf("%lld\n", A * (n + 1));
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vs = vector<string>;
using vb = vector<bool>;
using vll = vector<long long>;
using vpii = vector<pair<int,int>>;
using vivi = vector<vector<int>>;
using vbvb = vector<vector<bool>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int mod = 1000000007;
const int inf = 1001001001;



int main(void) {
  int n,m;
  cin >> n >> m;
  vpii a(m);
  rep(i,m){
    int p,q;
    cin >> p >> q;
    p--;
    q--;
    a[i] = make_pair(q,p);
  }
  sort(ALL(a));
  int right = 0;
  int cnt = 1;
  rep2(i,1,m){
    if(a[i].second>=a[right].first){
      cnt++;
      right = i;  
    }
  }
  cout << cnt << endl;

}






Measured memory_bytes: 1024
/*input
20 12 6
*/

// Nihesh Anderson - knandy

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

using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; // find_by_order, order_of_key
ll MOD=1000000007;

#define endl '\n'
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
ll INF = 2000000000000000001;
long double EPS = 1e-9;
ll power(ll a, ll n, ll md){if(n==0){return 1;}else{ll res=power(a,n/2,md);res=(res*res)%md;if(n%2!=0){res=(res*a)%md;}return res;}}
random_device rndm;
mt19937 grndm(rndm());
void mix(ll* a, ll* b){shuffle(a,b,grndm);}

int main(){
	fast_cin();
	// freopen("input.in","r",stdin);
	// freopen("output.out","w",stdout);
	ll n, x, t; cin >> n >> x >> t;
	cout << t * ((n + x - 1) / x) << endl; 
	return 0;
}




















Measured memory_bytes: 3656
local read = setmetatable({}, {__index = function(t, k) local a = {} for i=1,#k do table.insert(a, '*'..string.sub(k, i, i)) end local r = io.read local u = table.unpack or unpack return function() return r(u(a)) end end})
read.N = function(N) local t={} for i=1,N do t[i]=read.n() end return t end
string.totable = function(s) local t={} local u=string.sub for i=1,#s do t[i] = u(s, i, i) end return t end
string.split = function(s) local t={} for w in string.gmatch(s, "[^%s]+") do table.insert(t, w) end return (table.unpack or unpack)(t) end
local function array(dimension, default_val) assert(type(default_val) ~= 'table') local n=dimension local m={}if default_val~=nil then m[1]={__index=function()return default_val end}end for i=2,n do m[i]={__index=function(p, k)local c=setmetatable({},m[i-1])rawset(p,k,c)return c end}end return setmetatable({},m[n])end
----
local A,B=read.nn()
print(A*B)

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

using namespace std;
using ll = long long int;

int main(void) {
    constexpr ll MOD = 1e9 + 7;
    cout << fixed << setprecision(16);

    ll m, k;
    cin >> m >> k;

    if(m==1 && k==1 || (k >= 1ll<<m)) {
        cout << -1 << endl;
        return 0;
    }
    if(m==1 && k==0) {
        cout << "1 1 0 0" << endl;
        return 0;
    }

    vector<ll> v(2ll<<m);
    {
        ll j = 0;
        for(ll i=0; i<1ll<<m; i++)
            if(i != k)
                v[j++] = i;
        v[j++] = k;
        for(ll i=(1ll<<m)-1; i>=0; i--)
            if(i != k)
                v[j++] = i;
        v[j++] = k;
    }
    for(auto &e: v) cout << e << ' ';
    cout << endl;

}


Measured memory_bytes: 3840
#include<iostream>
using namespace std;
int main(){
  int n,m;
  cin >> n >> m;
  
  int h[n];
  bool good[n];
  for (int i=0; i<n; i++)
  {
    cin >> h[i];
    good [i] = true;
  }
  
  int a,b;
  for (int i=0; i<m; i++)
  {
    cin >> a >> b;
    if(h[a-1]==h[b-1])
    {
      good[a-1] = false;
      good[b-1] = false;
    }
    else if(h[a-1]<h[b-1])
    {
      good[a-1] = false;
    }
    else if(h[a-1]>h[b-1])
    {
      good[b-1] = false;
    }
  }
  
  int it = 0;
  for (int i=0; i<n; i++)
  {
    if(good[i])
      it++;
  }
  cout << it;
}

Measured memory_bytes: 4092
#include <stdio.h>

#define MAX 1000100
#define MP 999983

int bool_prime[MAX] = {0};
int prime[MAX / 10] = {0};

void func_eratos(int array[], int size) {
	int i, j;

	array[0] = 1; array[1] = 1;
	for(i = 2; i < size; i++) {
		if(array[i] == 0) {
			for(j = 2; i * j < size; j++)
				array[i * j] = 1;
		}
	}
}

int mk_prime_array(int ans_array[], int array[], int max_prime_lim) {
	int i, j = 0;

	for(i = 0; i < max_prime_lim + 1; i++) {
		if(!array[i]) {
			ans_array[j] = i;
			j++;
		}
	}

	return j;
}

int b_search_index(int search, int array[], int bottom, int top) {
	int mid = (top + bottom) / 2;

	do {
		if(search < array[mid])
			top = mid;
		else
			bottom = mid;

		mid = (top + bottom) / 2;
	} while(bottom != mid);

	if(search > array[mid])
		mid++;

	return mid;
}

int func_premium(int m, int p, int prime_array[]) {
	int i = 0;
	int ans;

	while(prime_array[i]) i++;

	i = b_search_index(p - m, prime_array, 0, i - 1);

	for(ans = 0;prime_array[i] <= p + m && prime_array[i] <= MP; i++)
		ans++;

	return ans;
}

int main(void) {
	int n, m, p;
	int num_prime;
	int premium;
	int ans;
	int i;

	func_eratos(bool_prime, MAX);
	num_prime = mk_prime_array(prime, bool_prime, MAX);

	do {
		scanf("%d", &n);
		if(!n)
			break;

		for(i = 0, ans = 0; i < n; i++) {
			premium = 0;
			scanf("%d %d", &p, &m);
			premium += func_premium(m, p, prime); 
			ans += premium - 1;
		}

		printf("%d\n", ans);
	} while(1);

	return 0;
}

Measured memory_bytes: 4816
# _*_ coding:utf-8 _*_
#  Atcoder_Begineer_Contest088-C
#  TODO https://atcoder.jp/contests/abc088/tasks/abc088_c
#  Along a commentary
def solveProblem(c):
	a0 = 0
	b0 = c[0][0]-a0
	b1 = c[0][1]-a0
	b2 = c[0][2]-a0
	a1 = c[1][0]-b0
	a2 = c[2][0]-b0
	c11eq = c[1][1] - (a1+b1)
	c12eq = c[1][2] - (a1+b2)
	c21eq = c[2][1] - (a2+b1)
	c22eq = c[2][2] - (a2+b2)
	if (c11eq == 0) and (c12eq == 0) and (c21eq == 0) and (c22eq == 0):
		answer = "Yes"
	else:
		answer = "No"
	return answer

if __name__ == '__main__':
	c=[]
	for _ in range(0,3,+1):
		c.append(list(map(int,input().strip().split(' '))))
	solution = solveProblem(c)
	print("{}".format(solution))


Measured memory_bytes: 3064
#include<stdio.h>
int main()
{
	int W,H,x,y,r;
	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
	
	if(x-r>=0 && x+r<=W && y-r>=0 && y+r<=H){

	printf("Yes\n");
	
	}
	
	else if(x-r<0 || x+r>W || y-r<0 || y+r>H){
	printf("No\n");

	}
	return 0;
}

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

using namespace std;

#define int long long
#define all(v) begin(v), end(v)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

int H, W;
int M[1010][1010];

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

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  cin >> H >> W;
  vector<int> x(H*W + 1), y(H*W + 1);
  vector<int> fall(H*W + 1);
  rep(i, H) rep(j, W) {
    cin >> M[i][j]; M[i][j]--;
    x[M[i][j]] = j, y[M[i][j]] = i;
    fall[M[i][j]] = M[i][j];
  }

  int ans = 0;
  reps(elv, 1, H*W) {
    set<int> st;
    rep(i, 4) {
      int nx = x[elv] + dx[i];
      int ny = y[elv] + dy[i];
      if(nx < 0 || W <= nx || ny < 0 || H <= ny) continue;
      if(M[ny][nx] < elv) st.insert(fall[M[ny][nx]]);
    }
    bool ridge = (*st.begin() == -1 || st.size() > 1);
    if(ridge) fall[elv] = -1, ans++;
    else if(st.size()) fall[elv] = *st.begin();
  }

  cout << ans << endl;


  return 0;
}

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

int row[8];
bool X[8][8];
int n;


void print()
{
        for ( int i = 0; i < 8; i++ ) {
                for ( int j = 0; j < 8; j++ ) {
                        if ( X[i][j] ) {
                                if ( row[i] != j ) return;
                        }
                }
        }
        
        for ( int i = 0; i < 8; i++ ) {
                for ( int j = 0; j < 8; j++ ) {
                        cout << (row[i] == j ? 'Q' : '.');
                }
                cout << endl;
        }
}
void dfs(int i, int left = 0, int center = 0, int right = 0)
{
        if ( i == 8 ) {
                print();
                return;
        }
        
        for ( int j = 0; j < 8; j++ ) {
                if ( ((left >> j) & 1) || ((center >> j) & 1) || ((right >> j) & 1) ) continue;
                row[i] = j;
                dfs(i + 1, (left | (1 << j)) << 1, center | (1 << j), (right | (1 << j)) >> 1);
                row[i] = -1;
        }
}

int main()
{

        cin >> n;
        for ( int i = 0; i < n; i++ ) {
                int r, c;
                cin >> r >> c;
                X[r][c] = true;
        }

        dfs(0);

        return ( 0 );
}



Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
#ifdef __DEBUG__
    void debug_out() { cerr << endl; } 
    template <typename Head, typename... Tail>
    void debug_out(Head H, Tail... T) {cerr << " " << H; debug_out(T...);}
    #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
    #define debug(...) 
#endif

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const deque<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

ll N,X,M;
inline void input(){
    fast_io();
    cin >> N >> X >> M;
}

inline int solve(){
    ll ans = 0;
    vector<ll> pwX(M,0);
    for (ll i = 0; i < M; i++)
    {
        pwX[i] = (i*i)%M;
    }
    ll x = X;
    vector<bool> used(M,false);
    ll rest = 0;
    for (int i = 0; i < N; i++)
    {
        if(used[x]) {
            rest = N-i;
            break;
        }
        used[x] = true;
        ans += x;
        x = pwX[x];
        if(x==0) break;
        if(x==1){
            ans += N-1-i;
            break;
        }
    }
    if(rest){
        ll T = 0, Sum = 0;
        ll init = x;
        T++;
        Sum += x;

        x = pwX[x];
        while(x != init && T<rest){
            T++;
            Sum += x;
            x = pwX[x];
        }
        debug(ans,rest,T,Sum);
        ans += 1LL*Sum*(rest/T);
        rest %= T;
        for (int i = 0; i < rest; i++)
        {
            ans += x;
            x = pwX[x];
        }
        debug(ans,rest,T,Sum);
    }
    cout << ans << endl;
    
    return 0;
}   

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


Measured memory_bytes: 3956