akhauriyash/Code-Regression huggingface dataset:
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
int main(){
    int l, r;
    cin >> l >> r;
    vi a;
    int cnt = 0;
    for(int i = l; i <= r; i++){
        cnt++;
        a.pb(i % 2019);
        if(cnt == 2019) break;
    }
    int ans = INF;
    for(int i = 0; i < a.size(); i++){
        for(int j = i+1; j < a.size(); j++){
            ans = min(ans, (a[i]*a[j]) % 2019);
        }
    }
    cout << ans;
}   

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

int main(){
  string s;
  cin >> s;
  
  int count = 0;
  
  if(s[0]=='1') count++;
  if(s[1]=='1') count++;
  if(s[2]=='1') count++;
  
  cout << count << endl;
}

Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
//segment-tree
ll n;//nは2のべき乗
pii dat[2000110*2-1];

//初期化
void init(ll _n){
	//べき乗を計算しておく
	n = 1;
	while(n <_n)
		n *=2;
  //すべての値をINT_MAXに
	for(ll i =0;i <2*n-1;i++){
		dat[i].first=-INF;
	}
}

//i番目の値(0-indexed)をxに変更
void update(ll i,ll x,ll c){
  //葉のノード番号
	i +=n-1;
	dat[i].first = x;
	dat[i].second =-c;
	while(i >0){
		i =(i-1)/2;
		if(dat[i*2+1]>dat[i*2+2]){
			dat[i]=dat[i*2+1];
		}else{
			dat[i]=dat[i*2+2];
		}
	}
}

//[a,b)の最小値,l,rにはノードkに対応づく区画を与える
//外からはquery(a,b,0,0,n)のように呼ぶ
/*int query(int a,int b,int k,int l,int r){
  if(r <=a||b <=l)//交差しない
  	return INT_MAX;
  if(a <=l&&r<=b)//完全に含む
  	return dat[k].first;
  else{
  	int vl =query(a, b, k*2+1, l, (l+r)/2);
  	int vr =query(a, b, k*2+2, (l+r)/2, r);
  	return min(vl,vr);
  }
}*/
  int main(){
  	int q;
  	cin>>n>>q;
  	init(n);
  	for(int i =0;i <q;i++){
  		ll x,y;
  		cin>>x>>y;
  		x--;
  		ll tmp =x+n-1;
  		if(dat[tmp].first!=-INF){
  			update(x,dat[tmp].first+y,x);
  		}else{
  			update(x, y, x);
  		}
  		cout <<-1*dat[0].second+1<<" "<<dat[0].first<<endl;
  	}
  	return 0;
  }

Measured memory_bytes: 32420
#include <stdio.h>

int main(void){
  int n, i, c[4] = {0}; 
  char jdg[4];
  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%s", jdg);
    if(jdg[0] == 'A')c[0]++;
    if(jdg[0] == 'W')c[1]++;
    if(jdg[0] == 'T')c[2]++;
    if(jdg[0] == 'R')c[3]++;
  }
  
  printf("AC x %d\n", c[0]);
  printf("WA x %d\n", c[1]);
  printf("TLE x %d\n", c[2]);
  printf("RE x %d\n", c[3]);
  
  return 0;
}

Measured memory_bytes: 1700
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
const int mod=1000000007;
const int mod1=998244353;
int inf=1000000000;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int h,w;cin >> h >> w;
	vector<string> s(h);
	rep(i,h) cin >> s.at(i);
	vector<vector<int>> a(h,vector<int>(w,inf));
	queue<pair<pii,int>> q;
	rep(i,h){
		rep(j,w){
			if(s.at(i).at(j)=='#'){
				q.push(mp(mp(i,j),0));
				a.at(i).at(j)=0;
			}
		}
	}
	int ans=0;
	while(!q.empty()){
		pii cur=q.front().first;
		int x=cur.second,y=cur.first,k=q.front().second;
		ans=max(ans,k);
		q.pop();
		if(y+1<h && a.at(y+1).at(x)==inf){
			a.at(y+1).at(x)=k+1;
			q.push(mp(mp(y+1,x),k+1));
		}
		if(y-1>=0 && a.at(y-1).at(x)==inf){
			a.at(y-1).at(x)=k+1;
			q.push(mp(mp(y-1,x),k+1));
		}
		if(x+1<w && a.at(y).at(x+1)==inf){
			a.at(y).at(x+1)=k+1;
			q.push(mp(mp(y,x+1),k+1));
		}
		if(x-1>=0 && a.at(y).at(x-1)==inf){
			a.at(y).at(x-1)=k+1;
			q.push(mp(mp(y,x-1),k+1));
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 17424
#include <bits/stdc++.h>
using namespace std;
#define lld long long int
#define M 1000000007
#define fors(i,n) for(int i=0;i<n;++i)
#define fore(i,a,b) for(int i=a;i<=b;++i)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define vv vector<int>
#define endl "\n"
#define test(i) cout<<i<<endl
#define itrt int t; cin>>t; fors(i,t)
#define itr1 int t; cin>>t;
#define ff first
#define ss second
#define pb push_back
#define vmp make_pair
#define ppb pop_back
#define sorta(a,n) sort(arr,arr+n)
#define sortv(x) sort(x.begin(),x.end())
void file(){
    #ifdef LOCAL
    freopen("demo.in","r",stdin);
    freopen("demo.out","w",stdout);
    #endif
}
int main(){
    fastio;
    file();
    int n;
    cin >> n;
    vector<int> P(n), Q(n);
    for(int i = 0; i < n; i++){
        cin >> P[i];
    }
    for(int i = 0; i < n; i++){
        cin >> Q[i];
    }   
    vector<int> A(n);
    for(int i = 0; i < n; i++){
        A[i] = i + 1;
    }
    // test("A[i]: ");
    // for(auto x:A){
    //     cout<<x<<" ";
    // }
    cout<<endl;
    int ai = -1, bi = -1, cnt = 0;
    do{
        // test("A[i]: ");
    // for(auto x:A){
    //     cout<<x<<" ";
    // }
        if(ai == -1){
            bool f = true;
            for(int i = 0; i < n; i++){
                if(A[i] == P[i]);
                else{
                    f = false;
                    break;
                }
            }
            if(f) {ai = cnt;} //test("ai: "); test(ai);
        }
        if(bi == -1){
            bool f = true;
            for(int i = 0; i < n; i++){
                if(A[i] == Q[i]);
                else{
                    f = false;
                    break;
                }
            }
            if(f) {bi = cnt;} //test("bi: "); test(bi);
        }
        if(ai != -1 and bi != -1){
            break;
        }
        cnt++;
        // test("cnt: "); test(cnt);
    }while(next_permutation(A.begin(), A.end()));
    cout << abs(ai - bi) << endl;
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
// #define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n,m;
    cin>>n>>m;
    if(!n)return;
    vi a(n);
    vvi b(n,vi(m));
    rep(i,n){
        string s;
        cin>>s;
        rep(j,m)b[i][j]=s[j]-'0';
        rep(j,m)a[i]<<=1,a[i]|=b[i][j];
    }
    if(n<m){
        int ans=0;
        rep(i,1<<n){
            vi t(m);
            rep(j,n){
                if((i>>j)&1){
                    rep(k,m)t[k]+=b[j][k];
                }
            }
            bool f=true;
            rep(j,m)f&=t[j]%2==0;
            if(f)ans=max(ans,__builtin_popcount(i));
        }
        cout<<ans<<endl;
    }
    else{
        vi dp1(1<<m,-1);
        dp1[0]=0;
        rep(i,n){
            vi dp2(1<<m,-1);
            rep(s,1<<m){
                if(~dp1[s^a[i]]){
                    dp2[s]=max({dp1[s],dp2[s],dp1[s^a[i]]+1});
                }
                dp2[s]=max(dp2[s],dp1[s]);
            }
            dp1=dp2;
        }
        cout<<dp1[0]<<endl;
    }
    run();
}


Measured memory_bytes: 35896
#include<iostream>
    #include <queue>

    using namespace std;
    int main()
    {
        int N, M;
       cin >> N >> M;
        priority_queue<int> price;
        for (int i = 0; i < N; i++){
                int p;
                cin >> p;
                price.push(p);
        }
        for(int i = 0; i < M; i++){
            int p = price.top() / 2;
            price.pop();
            price.push(p);
        }
        long long total = 0;
        for(int i = 0; i < N; i++){
            total += price.top();
            price.pop();
        }
        cout << total;
    }

Measured memory_bytes: 892
//LETS START AGAIN
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back 
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define ld long double
#define F first 
#define S second
#define int long long int
signed main() 
{ 
    fast;
    int n;
    cin>>n;
    set<int> st;
    for(int i=1;i*i<=n;i++)
    {
        if(n%i == 0)
        {
            int f1 = i;
            int f2 = n/i;
            if(f2-1>=1)
                st.insert(f2-1);
            if(i-1>=1)
                st.insert(i-1);
        }
    }
    int sum = 0;
    for(auto it:st)
    {
        if(n%it == n/it)
        sum+=it;
    }
    cout<<sum;
} 



Measured memory_bytes: 640
#include <bits/stdc++.h>
#include<cmath>
#define N 100005
#define A 1000005
#define MOD 1000000007 // //100000000 998244353 //
#define inf 1000000000000000000
#define ll long long
//#define M_PI 3.141592653589793238463

using namespace std;

#define pii pair<ll, ll>
#define piii pair<ll, pii>
#define ft first
#define sd second
#define pb push_back
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n-1; i >= 0; i--)
#define itr(it, x) for(auto it = x.begin(); it != x.end(); it++)
#define mem(a, b) memset(a, (ll)b, sizeof(a))
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define edge(v, x, y) v[x].pb(y); v[y].pb(x);
#define popcount __builtin_popcount
#define ANS(s) {cout << s << "\n"; return;}

//~~~~~~fancy print~~~~~~~//
#define printpii(a) cout << a.ft << " " << a.sd << endl;
#define printpiii(a) cout << a.ft << " " << a.sd.ft << " " << a.sd.sd << endl;
#define print(a, n) rep(i, n) cout << a[i] << " "; cout << endl;
#define printv(v) for(auto x: v)cout << x << " "; cout << endl;
#define printm(a, n, m) rep(i, n) { rep(j, m) cout << a[i][j] << "\t"; cout << endl;}

ll lx[4] = {0, 0, 1, -1};
ll ly[4] = {1, -1, 0, 0};
ll dx[8] = {0, 0, 1, -1, 1, -1, 1, -1};
ll dy[8] = {1, -1, 0, 0, 1, 1, -1, -1};
void fast(){ios_base::sync_with_stdio(false);cin.tie(0);cout << setprecision(12) << fixed;}
ll lcm(ll a, ll b) {return (a/__gcd(a, b))*b; }

void solve()
{
    long double  a, b, c;
    cin >> a >> b >> c;
    long double er= 1.0E-14;
    cout << (sqrt(a) +sqrt(b) + er < sqrt(c) ? "Yes" : "No");
}
int main(){
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    fast();
    ll t = 1; //cin >> t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=1000000007;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};


vector<pair<LL,P>> G[50];

int main(){
    LL n,m,s;cin >> n >> m >> s;
    for (int i = 0; i < m; i++) {
        LL u,v,a,b;cin >> u >> v >> a >> b;
        u--,v--;
        G[u].pb(mp(v,mp(a,b)));
        G[v].pb(mp(u,mp(a,b)));
    }
    s = min(s, 2500LL);
    vector<P> Z(n);
    for (int i = 0; i < n; i++) {
        cin >> Z[i].fs >> Z[i].sc;
    }
    priority_queue<pair<P,LL>,vector<pair<P,LL>>, greater<pair<P,LL>> > pq;
    pq.push(mp(mp(0,s), 0));
    vector<vector<LL>> dp(n,vector<LL> (3001,LINF));
    dp[0][s] = 0;
    while(not pq.empty()){
        LL u = pq.top().sc;
        LL co = pq.top().fs.sc, ti = pq.top().fs.fs;
        pq.pop();
        if(dp[u][co] < ti) continue;
        for (int i = 0; i < G[u].size(); i++) {
            LL nu = G[u][i].fs;
            if(co < G[u][i].sc.fs) continue;
            LL nt = ti + G[u][i].sc.sc;
            if(co >= 2500){
                if(chmin(dp[nu][co],nt)){
                    pq.push(mp(mp(nt, co), nu));
                }
            }
            else{
                if(chmin(dp[nu][co - G[u][i].sc.fs],nt)){
                    pq.push(mp(mp(nt, co - G[u][i].sc.fs), nu));
                }
            }
        }
        if(chmin(dp[u][min(2500LL, co + Z[u].fs)], ti + Z[u].sc)){
            pq.push(mp(mp(ti + Z[u].sc, min(2500LL, co + Z[u].fs)), u));
        }
    }
    for (int i = 1; i < n; i++) {
        LL t = LINF;
        for (int j = 0; j <= 2500; j++) {
            chmin(t, dp[i][j]);
        }
        cout << t << endl;
    }
    return 0;
}



Measured memory_bytes: 7624
var input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
var obj = {
  "list" : input,
  "index" : 0,
  "max" : input.length,
  "next" : function(){
    if(!this.hasNext()){throw "NoSuchElementException:次に要素は無いよ";}
    var returnObj = this.list[this.index];
    this.index++;
    return returnObj;
  },
  "hasNext" : function(){return (this.index < this.max);}
}
Main();
function next(){return obj.next();}
function hasNext(){return obj.hasNext();}
function myout(t){console.log(t);}//standard output
function myerr(t){console.error(t);}//standard error
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す　1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
  var one = myconv(next(),4);
  var x = one[0];
  var y = one[1];
  var absX = Math.abs(x);
  var absY = Math.abs(y);
  if(x < 0 && y < 0){
     if(x > y){
        myout(absY - absX + 2);
     }else{
        myout(absX - absY);
     }
  }else if(x < 0 && y >= 0){
     if(y == 0){
        myout(absX);
     }else if(absX > y){
        myout(absX - absY + 1);
     }else{
        myout(absY - absX + 1);
     }
  }else if(y < 0 && x >= 0){
     if(absY > x){
        myout(absY - absX + 1);
     }else{
        myout(absX - absY + 1);
     }
  }else{
    if(y >= x){
       myout(y - x);
    }else{
       if(y == 0){
          myout(x - y + 1);
       }else{
          myout(x - y + 2);
       }
    }
  }
}

Measured memory_bytes: 7372
#include <stdio.h>

int main(void)
{
        int A, B, C, X;
        scanf("%d%d%d%d", &A, &B, &C, &X);

        int i, j, k, ans = 0;
        for (i = 0; i <= A; i++)
                for (j = 0; j <= B; j++)
                        for(k = 0; k <= C; k++)
                                if (i*500 + j*100 + k*50 == X)
                                        ans++;

        printf("%d\n", ans);
        return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long LL;
LL gcd(LL a,LL b)
{
    return b == 0 ? a : gcd(b,a % b);
}
int main()
{
    LL a,b;
    while(scanf("%lld%lld",&a,&b) == 2)
    {
        if(b > a)
            swap(a,b);
        LL res = gcd(a,b);
        printf("%lld %lld\n",res,a * b / res);
    }
}


Measured memory_bytes: 2600
#include <iostream>
#include <algorithm>

#define i64 long long

i64 computeSolution(i64 N, i64 A, i64 B){

    //they meet directly
    if ((A-B)%2 == 0){
        return  (B-A)/2;
    }
    //they meet at N, use symmetry
    if (A-1 > N-B){
        //return computeSolution(N,N-B+1,N-A+1);
        return (N - B) + 1 + computeSolution(N, A + (N-B+ 1), N);
    } else {
        return A + computeSolution(N, 1, B - A);
    }
//    //meeting at 1:
//    if ( B == A + 1){
//        return B-1;
//    }

//    //meeting over 1:
//    return A + computeSolution(N,1,B-A);

}



int main(){
    i64 N, A, B;
    std::cin >> N >> A >> B;
    std::cout << computeSolution(N,A,B);
}


Measured memory_bytes: 256
#include <iostream>
#include <stack>
#define NIL -1
#define N 110

using namespace std;

bool A[N + 1][N + 1];
int d[N + 1];
int n;

stack<int> s1;
stack<int> s2;

void bfs(int depth, stack<int> si, stack<int> so) {
  if (si.empty()) return;
  while (!si.empty()) {
    int u = si.top();
    si.pop();
    for (int v = 1; v <= n; v++) {
      if (A[u][v] && d[v] == NIL) {
        so.push(v);
        d[v] = depth;
      }
    }
  }
  bfs(depth + 1, so, si);
}

int main() {

  cin >> n;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      A[i][j] = false;
    }
  }

  for (int i = 1; i <= n; i++) {
    int u, k, v;
    cin >> u >> k;
    for (int j = 1; j <= k; j++) {
      cin >> v;
      A[u][v] = true;
    }
  }

  for (int i = 1; i <= N; i++) d[i] = NIL;
  s1.push(1);
  d[1] = 0;
  bfs(1, s1, s2);

  for (int i = 1; i <= n; i++) {
    cout << i << " " << d[i] << endl;
  }
}


Measured memory_bytes: 3120
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int pn(int a[],int n){
  int i,j;
  a[0]=a[1]=0;
  for(i=2;i<n;i++)
    a[i]=i;
  for(i=2;i*i<n;i++){
    if(a[i]){
      for(j=i*i;j<n;j+=i)
        a[j]=0;
    }
  }
  j=2;
  for(i=0;j<n;i++){
    a[i]=a[j];
    for(j++;j<n&&a[j]==0;j++);
  }
  return i;
}
int main(){
  int i; 
  int a[1000000];
  a[pn(a,1000000)]=1000000;
  int n;
  while(cin>>n){
    for(i=0;a[i]<=n;i++);
    cout<<i<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <cmath>
#include <numeric>
#include <iomanip>
#include <set>
#include <string.h>
#include <bitset>

using namespace std;

typedef long long ll;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REP3(i,st,en) for(ll (i)=(st);(i)<(en);(i)++)

using P = pair<ll, ll>;
const int MOD = 1e9+7;
const ll INF = 1e+14;
const double PI = 3.14159265349;


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

  ll N;
  cin >> N;

  vector<ll> A(N);
  REP(i,N){ cin >> A[i]; }

  //　各bitで処理
  ll ans = 0;
  REP(b, 60){
    vector<ll> B(N); // kth-bit values of A[]
    REP(i,N) { B[i] = ((A[i]>>b) & 1); }
    vector<ll> dp(2); // dp[k]はiがkのときのi以降の数とのXORの和

    ll sum_b = 0;
    if (B[N-1]==1){
      dp[0]=1;
    } else {
      dp[1]=1;
    }

    for(ll i=N-2;i>=0;i--){
      if (B[i]==0){
        sum_b += dp[0]; sum_b%=MOD;
        dp[1]++; dp[1]%=MOD;
      } else {
        sum_b += dp[1]; sum_b%=MOD;
        dp[0]++; dp[0]%=MOD;
      }
    }

    ans += (sum_b * (((ll)1<<b) % MOD)) % MOD;
    ans %= MOD;
  }

  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 4992
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;

namespace AtCoderSolve
{
    class Solve
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            string s = Console.ReadLine();
            Console.WriteLine((s[0] == '9' || s[1] == '9') ? "Yes" : "No");

            Console.Out.Flush();
        }
    }



    public class Calculation
    {
        
    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include <iomanip>
#include <cstring>
#include <iomanip>
#include <ctime>
#include <cstdlib>

using namespace std;

#define PB push_back
#define MP make_pair
#define L first
#define R second

typedef pair<int, int> pie;

set<int> s;

int main() {
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        if (s.find(x) == s.end())
            s.insert(x);
        else
            s.erase(x);
    }
    cout << s.size() << endl;
    return 0;
}

Measured memory_bytes: 4992
#include<stdio.h>
#include<stdlib.h>

int main(void)
{
  int a=0;
  int b=0;
  int c=0;
  int d=0;
  int x;
  scanf("%d",&x);

  for(a=-118; a<=119; a++){
      for(b=-118; b<=119; b++){
        c=a;
        d=b;
      for(int i=0; i<4; i++){
        c = c*a;
        d = d*b;
      }
      if(c-d == x){
      printf("%d %d",a,b);
      return 0;
      }
    }
  }

  printf("nothing");

    return 0;

}



Measured memory_bytes: 1728
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include <cctype>
#include<math.h>
using namespace std;
int main() {
	long int n, m, a[100000], b[100000], z = 0;
	cin >> n >> m;
	b[0] = 1;
	b[1] = 1;
	for (int i = 0; i < m; ++i)cin >> a[i];
	for (int j = 0; j < m; ++j) {
		if (a[j] == 0)b[0] = 0;
		if (a[j] == 1)b[1] = 0;
	}
	for (int i = 2; i < n+1; ++i) {
		b[i] =( b[i - 1] + b[i - 2])% 1000000007;
		for (int j = z; j < m; ++j) {
			if (a[j] == i) {
				z = j;
				b[i] = 0;
				break;
			}
		}
	}
	cout << b[n] % 1000000007 << endl;
}

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

int main()
{

	while(true){
		int a,b,sum;
		int count = 0;
	
		cin >> a ;

		if(cin.eof())
			break;
		cin >> b;

		sum = a + b;

		for(int i=1 ;sum!=0 ;i++){

			sum /= 10;
			count = i;
		}

		cout << count << endl;
	}
		
		return 0;
}

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

using namespace std;

int main(void) {
  
  int N, K;
  cin >> N >> K;

  set<int> A;

  for (int i=0; i<K; i++) {
    int di;
    cin >> di;
    for (int i=0; i<di; i++) {
      int a;
      cin >> a;
      A.insert(a);
    }
  }

  cout << N -A.size() << endl;



}


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

#define fi first
#define se second
#define repl(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define repr(i, a, b) for (int i = (int)(a - 1); i >= b; i--)
#define rep(i, n) repl(i, 0, n)
#define each(itr, v) for (auto itr : v)
#define pb(s) push_back(s)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cout << #x " = " << x << endl
#define maxch(x, y) x = max(x, y)
#define minch(x, y) x = min(x, y)
#define uni(x) x.erase(unique(all(x)), x.end())
#define exist(x, y) (find(all(x), y) != x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define INF INT_MAX / 3

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



Measured memory_bytes: 3164
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<bitset>
#define ld long double
#define ll long long int
#define ull unsigned long long int
#define rep(i,n) for(i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define INF INT_MAX
#define vi vector<int>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define vvc vector<vector<char> >
#define vvs vector<vector<string> >
#define P 1000000007
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const long long LLINF=1LL<<60;
//set<int>::iterator it;
//|_
//g++ -std=c++1z temp.cpp
//./a.out

int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
	
    int i;
    string s;
    cin>>s;
    int ans=0;
    rep(i,s.length()){
        if(s[i]=='x')ans++;
    }
    if(ans>7)cout<<"NO"<<endl;
    else cout<<"YES"<<endl;
    
//////////////////////////////////////////////////////
return 0;}










Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

a,b=mii()

if a%2==0 and b%2==1:
    if ((b-a+1)//2)%2==0:
        print(0)
    else:
        print(1)

elif a%2==1 and b%2==1:
    if ((b-a)//2)%2==0:
        print(a^0)
    else:
        print(a^1)

elif a%2==1 and b%2==0:
    if ((b-a-1)//2)%2==0:
        print(a^b^0)
    else:
        print(a^b^1)

else:
    if ((b-a)//2)%2==0:
        print(b^0)
    else:
        print(b^1)

Measured memory_bytes: 5144
#include <bits/stdc++.h>
#define pb push_back
#define SZ(x) ((int)(x.size()))
#define FOR(i,s,n) for (ll i = (s); (i) < (n); ++i)
#define FORD(i,s,l) for (ll i = (s); (i) >= l; --i)
#define F first
#define S second
#define TC int __tc; cin >> __tc; FOR(case_num,1,__tc+1)
#define TEST(x,i) ((x)&(1ll<<(i)))
#define SET(x,i) ((x)|(1ll<<(i)))
#define FLIP(x,i) ((x)^(1ll<<(i)))
#define CLEAR(x,i) ((x)&~(1ll<<(i)))

const double pi = 4 * atan(1);
using namespace std;
typedef long long ll;

const ll MOD = 1000000007;
const int MAXN = 100005;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ll h,w,n;
	cin >> h >> w >> n;
	set<pair<ll,ll>> c;
	FOR(i,0,n){
		ll x, y;
		cin >> x >> y;
		c.emplace(x,y);
	}
	map<int,ll> cnt;
	for (auto &p : c){
		for (int i = max(1LL,p.F-2); i<=p.F && i+2<=h; i++) {
			for (int j = max(1LL,p.S-2); j<=p.S && j+2<=w; j++) {
				bool any = false;
				bool valid = true;
				int l = 0;
				for (int x = i; x<=i+2 && valid; x++){
					for (int y = j; y<=j+2 && valid; y++){
						if (c.count({x,y})) {
							if (! any) {
								any = true;
								if (x!=p.F || y!=p.S) {
									valid = false;
								}
							}
							l++;
						}
					}
				}
				if (valid) {
					cnt[l]++;
				}
			}
		}		
	}
	ll s = 0;
	for (auto &p : cnt){
		s+=p.S;
	}
	cnt[0]=(h-2)*(w-2)-s;
	for(int i = 0; i <= 9; i++){
		cout << cnt[i] << "\n";
	}
	
}


Measured memory_bytes: 9800
while True:
    ans = []
    h, w = map(int, input().split())
    if h == 0 and w == 0:
        exit()
    if w % 2 == 0:
        num = w // 2
        odd = 0
    else:
        num = w // 2
        odd = 1
    for i in range(h):
        if i % 2 == 0:
            ans.append(('#' + '.') * num)
            if odd == 1:
                ans[i] += '#'
        else:
            ans.append(('.' + '#') * num)
            if odd == 1:
                ans[i] += '.'
    print('\n'.join(ans) + '\n')


Measured memory_bytes: 5636
import sys
N = int(input())

z = [0 for _ in range(N)]
tmp = 0
for i in range(N):
  d1, d2 = map(int,input().split())
  if d1 == d2:
    tmp += 1
  else:
    tmp = 0
  if tmp >= 3:
    print("Yes")
    sys.exit()
    
print("No")
    
  

Measured memory_bytes: 62340
#include <stdio.h>
int main(void){
    int n, x, i, j, k, count = 0;

    for(;;){
        scanf("%d %d", &n, &x);
        if(n == 0 && x == 0) break;
        for(i = 1; i <= n; i++){
            for(j = i + 1; j <= n; j++){
                for(k = j + 1; k <= n; k++){
                    if(i + j + k == x) count++;
                }
            }
        }
        printf("%d\n", count);
        count = 0;
    }

    return 0;
}


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

int main() {
  char c[2][3];
  rep(i, 2) rep(j, 3) cin >> c[i][j];

  if (c[0][0] == c[1][2] && c[0][1] == c[1][1] && c[0][2] == c[1][0])
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 3608
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int sheep = Integer.parseInt(sc.next());
		int walf = Integer.parseInt(sc.next());
		String result =sheep > walf?"safe":"unsafe";
		System.out.println(result);

	}

}


Measured memory_bytes: 35716
#include<stdio.h>
 
int main()
{
    int n,m,i,count,j;
    int k[1000][100];
    int sum[100];
 
    while(scanf("%d%d",&n,&m),n+m){
 count=0;
      for(i=0;i<n;i++){
        for(j=0;j<m;j++){
          scanf("%d",&k[i][j]);
        }
      }
      for(i=0;i<100;i++) sum[i]=0;
 
      for(j=0;j<m;j++){
        for(i=0;i<n;i++){
          sum[j]+=k[i][j];
        }
      }
//for(i=0;i<m;i++)printf("%d ",sum[i]);
 
      for(j=n;j>=0;j--){
      for(i=0;i<m;i++){
 
          if(sum[i]==j){
printf("%d",i+1);
count++;
        
if(count<m)printf(" ");}}
      }
 
      printf("\n");
    }   
    return 0;
}

Measured memory_bytes: 996
#include <iostream>
#include <math.h>
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
int main(){
    float n;
    cin>>n;
    vector<pair<float,float>> hoge(n);//first=x second=y
    
    for(int i=0;i<n;i++){
        cin>>hoge.at(i).first>>hoge.at(i).second;
    }
    
    float dis=0;
    
    for(int i=0;i<n;i++){
        for(int k=0;k<n;k++){
            if(i!=k){
                float length = pow( (hoge.at(i).first-hoge.at(k).first)*(hoge.at(i).first-hoge.at(k).first) + (hoge.at(i).second-hoge.at(k).second)*(hoge.at(i).second-hoge.at(k).second), 0.5 );
                dis+=length;
            }
        }
    }
    
    cout<<setprecision(100)<<dis/n<<endl;
    
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <queue>
#include <cstdlib>
#include <cmath>
#define MAX 10001
using namespace std;
typedef long long lld;
int main(void) {
    int x, ans=1, tmp;
    cin >> x;
    
    for(int i=2; i<=sqrt(x); i++) {
        tmp=i*i;
        while(tmp<=x) {
            ans = max(ans, tmp);
            tmp *= i;
        }
    }
    cout << ans << endl;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int k;
  cin >> k;
  k--;
  vector <int> a = {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};
  cout << a[k] << endl; 
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
	#define DBG(X) cout << #X << "=" << (X) << '\n';
	#define SAY(X) cout << (X) << '\n';
#else
	#define DBG(X)
	#define SAY(X)
#endif
 
using namespace std;

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>;

const int INT_INF = (int)(2e9);
const ll  LL_INF  = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
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> inline ostream& operator<<(ostream& os, const vector<T>& v) { for(auto el: v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for(auto& elem: ret) cin >> elem; return ret; }

vector<pll> pref[4];

void solve() {
	int n = fetch<int>();
	ll W = fetch<ll>();

	ll fst_w = NIL;

	for(int i = 0; i < n; ++i) {
		ll w = fetch<ll>();
		ll v = fetch<ll>();

		if(fst_w == NIL) {
			fst_w = w;
		}

		pref[w - fst_w].emplace_back(w, v);
	}

	for(int t = 0; t < 4; ++t) {
		sort(pref[t].begin(), pref[t].end());
		pref[t].emplace_back(0, 0);
		reverse(pref[t].begin(), pref[t].end());

		int sz = len(pref[t]);

		for(int i = 1; i < sz; ++i) {
			pref[t][i].first += pref[t][i - 1].first;
			pref[t][i].second += pref[t][i - 1].second;
		}
	}

	ll answ = 0;

	for(int i = 0; i < len(pref[0]); ++i) {
		for(int j = 0; j < len(pref[1]); ++j) {
			int l = len(pref[3]) - 1;
			for(int k = 0; k < len(pref[2]); ++k) {
				while(l >= 0 && pref[0][i].first + pref[1][j].first + pref[2][k].first + pref[3][l].first > W) {
					--l;
				}

				if(l >= 0) {
					answ = max(answ, pref[0][i].second + pref[1][j].second + pref[2][k].second + pref[3][l].second);
				} else {
					break;
				}
			}
		}
	}

	cout << answ << '\n';
}

int main() {
	fast_io();
	solve();

	return 0;
}


Measured memory_bytes: 256
x = int(input())
x = x%10
if(x == 2 or x == 4 or x == 5 or x == 7 or x == 9):
	print('hon')
elif(x == 0 or x == 1 or x == 6 or x == 8):
	print('pon')
else:
	print('bon')

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

int main() {
  long H,W,D;
  cin>>H>>W>>D;
  vector<long> px(H*W+1);
  vector<long> py(H*W+1);
  for(int i=0;i<H;i++) for(int j=0;j<W;j++){
    int a;
    cin>>a;
    px[a]=i,py[a]=j;
  }
  vector<long> d(H*W+1);
  for(int i=1;i<=H*W-D;i++){
    d[i+D]=d[i]+abs(px[i+D]-px[i])+abs(py[i+D]-py[i]);
  }
  int Q;
  cin>>Q;
  for(int i=0;i<Q;i++){
    int l,r;
    cin>>l>>r;
    cout<<d[r]-d[l]<<endl;
  }
}


Measured memory_bytes: 5360
#include<bits/stdc++.h>
#define p pair<int,int>
using namespace std;

p d[200000];
vector<int>rinsetu[100000];
int mincost[100000];
set<int>k[100000];
int l[100000];
queue<int>Q;
int main() {
	memset(mincost, -1, sizeof(mincost));
	int a, b, c;
	cin >> a >> b >> c;
	for (int e = 0; e < b; e++) {
         int f, g; scanf("%d%d", &f, &g); f--; g--;
		d[e] = p(f, g);
		rinsetu[f].push_back(g);
		rinsetu[g].push_back(f);
	}
	Q.push(0);
	mincost[0] = 0;
	while (Q.size()) {
		int h = Q.front(); Q.pop();
		for (int i : rinsetu[h]) {
			if (mincost[i] == -1) {
				k[h].insert(i);
				l[i]++;
				mincost[i] = mincost[h] + 1;
				Q.push(i);
			}
			else if (mincost[i] == mincost[h] + 1) {
				k[h].insert(i);
				l[i]++;
			}
		}
	}
	int sum = 0;
	for (int i = 0; i < c; i++) {
		int j; scanf("%d", &j); j--;
		auto v= k[d[j].first].find(d[j].second), t= k[d[j].second].find(d[j].first);
		if (v!=k[d[j].first].end()) {
			k[d[j].first].erase(v);
			l[d[j].second]--;
			if (l[d[j].second] == 0) {
				queue<int>que;
				que.push(d[j].second);
				while (que.size()) {
					int u = que.front(); que.pop(); sum++; 
					for (auto w = k[u].begin(); w != k[u].end(); w++) {
						l[*w]--;
						if (l[*w] == 0)que.push(*w);
						k[u].erase(w); 
					}
					k[u].clear();
				}
			}
		}
		if (t!= k[d[j].second].end()) {
			k[d[j].second].erase(t);
			l[d[j].first]--;
			if (l[d[j].first] == 0) {
				queue<int>que;
				que.push(d[j].first);
				while (que.size()) {
					int u = que.front(); que.pop();  sum++; 
					for (auto w = k[u].begin(); w != k[u].end(); w++) {
						l[*w]--;
						if (l[*w] == 0)que.push(*w);
						k[u].erase(w); 
					}
					k[u].clear();
				}
			}
		}
		cout << sum<< endl;
	}
}

Measured memory_bytes: 24956
// its_mind_changer_
//                         _don't_under_estimate_
#include<bits/stdc++.h>
using namespace std;
#define int long long 


signed main()
{
    int n,a,b;cin>>n>>a>>b;
    int ans = (n/(a+b))*a;
    cout<<ans + min(n%(a+b),a);
}


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

using namespace std;

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  int n, a, b;
  std::cin >> n >> a >> b;
  auto const greater = std::max(a, b);
  auto const less = std::min(a, b);
  std::cout << less << " " << std::max(less - (n - greater), 0) << std::endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())
S = input()
ans = 0
for i in range(1, N):
    x = set(S[:i+1])
    y = set(S[i+1:])
    cnt = 0
    for j in x:
        if j in y:
            cnt += 1
    ans = max(ans, cnt)
print(ans)


Measured memory_bytes: 2940
n = int(input())
a = list(map(int,input().split()))
res = [0 for i in range(n)]
lres = []
for i in range(n,0,-1):
    l = []
    flag = 0
    t = i*2
    while t <= n:
        flag = flag ^ res[t-1]
        t = t+i
    if a[i-1] != flag:
        res[i-1] = 1
        lres.append(str(i))

print(len(lres))
if len(lres) != 0:
    print(" ".join(lres))
 

Measured memory_bytes: 17204
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Collections;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) throws IOException {
		FastScanner in = new FastScanner(System.in);
		int n= in.nextInt();
		long [] a= new long [n];
		long sum=0;
		for (int i = 0; i < a.length; i++) {
			a[i]= in.nextInt();
			sum+= a[i];
		}
		Arrays.sort(a);
		if(sum%10!=0){
			System.out.println(sum);
			return;
		}
		for (int i = 0; i < a.length; i++) {
			sum-=a[i];
			if(sum%10!=0){
				System.out.println(sum);
				return;
			}
			sum+= a[i];
		}
		System.out.println(0);
		
	}
	static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(InputStream in) {
			br = new BufferedReader(new InputStreamReader(in));
			st = new StringTokenizer("");
		}

		public double nextDouble() throws NumberFormatException, IOException {
			return Double.parseDouble(next());
		}

		public String next() throws IOException {
			if (!st.hasMoreTokens()) {
				st = new StringTokenizer(br.readLine());
				return next();
			}
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
	}
}


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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9

const int mod = 1e9+7;
int N;
vector<int> A;
int main(){
  cin >> N;
  A.resize(N);
  REP(i, N){
    cin >> A[i];
  }
  vector<int> cnt(3, 0);
  ll ans = 1;
  REP(i, N){
    int x = 0, idx;
    REP(j, 3){
      if(A[i] == cnt[j]){
        x++;
        idx = j;
      }
    }
    ans *= x;
    ans %= mod;
    cnt[idx]++;
  }
  cout << ans << endl;
  return 0;
}


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

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

for j in range(m):
	b += list(map(int, input().split()))

for x in range(n):
  result = []
  for y in range(l):
    tmp = 0
    for z in range(m):
      tmp += a[z + x * m] * b[l*z + y]
    result.append(tmp)
  print(" ".join(map(str, result)))



Measured memory_bytes: 6284
import java.util.*;

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


Measured memory_bytes: 42792
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
cnt=0
for i in range(n-2):
    if (l[i][0]==l[i][1]) and (l[i+1][0]==l[i+1][1]) and (l[i+2][0]==l[i+2][1]):
        print("Yes")
        exit()
print("No")

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

int main() {
  int N, C;
  cin >> N >> C;
  if (N == 1) {
    cout << 0 << endl;
    return 0;
  }

  int D[C][C];
  rep(i, C) {
    rep(j, C) {
      cin >> D[i][j];
    }
  }

  vector<int> X[3];
  rep(i, N) {
    rep(j, N) {
      int c;
      cin >> c;
      c--;
      int r = (i+j) % 3;
      X[r].push_back(c);
    }
  }

  vector<P> Q[3], Ans;
  rep(i, 3) {
    rep(j, C) {
      P tmp(0, j);
      for (int k : X[i]) {
        tmp.first += D[k][j];
      }                                     
      Q[i].push_back(tmp);
      sort(Q[i].begin(), Q[i].end() );
    }
  }
  
  
  int ans = Inf;
  int buf[2];
  
  rep(i, 3) {
    buf[0] = Q[0][i].second;
    rep(j, 3) {
      if (Q[1][j].second == buf[0]) continue;
      buf[1] = Q[1][j].second;
      rep(k, 3) {
        if (Q[2][k].second == buf[0] || Q[2][k].second == buf[1]) continue;
        int tmp = Q[0][i].first + Q[1][j].first + Q[2][k].first;
        if (tmp < ans) ans = tmp;
      }
    }
  }

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

Measured memory_bytes: 1520
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring> 
#include <cmath> 
#include <algorithm>
#include <queue>
#include <vector> 
using namespace std; 
inline int gi() {
    register int data = 0, w = 1;
    register char ch = 0;
    while (!isdigit(ch) && ch != '-') ch = getchar(); 
    if (ch == '-') w = -1, ch = getchar(); 
    while (isdigit(ch)) data = 10 * data + ch - '0', ch = getchar(); 
    return w * data; 
} 
const int INF = 1e9; 
const int MAX_N = 5e5 + 5; 
struct Graph { int to, next; } e[MAX_N << 2]; 
int fir[MAX_N], e_cnt; 
void clearGraph() { memset(fir, -1, sizeof(fir)); e_cnt = 0; } 
void Add_Edge(int u, int v) { e[e_cnt] = (Graph){v, fir[u]}, fir[u] = e_cnt++; } 
int N, K, P[MAX_N], A[MAX_N], deg[MAX_N]; 
#define lson (o << 1) 
#define rson (o << 1 | 1) 
int mn[MAX_N << 2]; 
void build(int o, int l, int r) { 
	mn[o] = INF; 
	if (l == r) return ; 
	int mid = (l + r) >> 1; 
	build(lson, l, mid), build(rson, mid + 1, r); 
} 
void modify(int o, int l, int r, int pos, int v) { 
	mn[o] = min(mn[o], v); 
	if (l == r) return ; 
	int mid = (l + r) >> 1; 
	if (pos <= mid) modify(lson, l, mid, pos, v); 
	else modify(rson, mid + 1, r, pos, v); 
} 
int query(int o, int l, int r, int ql, int qr) { 
	if (ql <= l && r <= qr) return mn[o]; 
	int mid = (l + r) >> 1, res = INF; 
	if (ql <= mid) res = min(res, query(lson, l, mid, ql, qr)); 
	if (qr > mid) res = min(res, query(rson, mid + 1, r, ql, qr)); 
	return res; 
} 
priority_queue<int, vector<int>, greater<int> > que; 
vector<int> ans; 
void TopSort() { 
	for (int i = 1; i <= N; i++) if (deg[i] == 0) que.push(i); 
	while (!que.empty()) { 
		int x = que.top(); que.pop(); 
		ans.push_back(x); 
		for (int i = fir[x]; ~i; i = e[i].next) { 
			int v = e[i].to; 
			if (--deg[v] == 0) que.push(v); 
		} 
	} 
} 
int main () { 
	clearGraph(); 
	N = gi(), K = gi(); 
	for (int i = 1; i <= N; i++) A[P[i] = gi()] = i; 
	build(1, 1, N); 
	for (int i = N; i; i--) { 
		int p1 = query(1, 1, N, max(1, A[i] - K + 1), A[i]); 
		if (p1 <= N) Add_Edge(A[i], A[p1]), deg[A[p1]]++; 
		int p2 = query(1, 1, N, A[i], min(N, A[i] + K - 1)); 
		if (p2 <= N) Add_Edge(A[i], A[p2]), deg[A[p2]]++; 
		modify(1, 1, N, A[i], i); 
	} 
	TopSort(); 
	for (int i = 0; i < (int)ans.size(); i++) A[ans[i]] = i + 1; 
	for (int i = 1; i <= N; i++) printf("%d\n", A[i]); 
    return 0; 
} 


Measured memory_bytes: 30320
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, A, B; cin >> N >> A >> B;
	vector<int> h(N); rep(i, 0, N) {
		cin >> h[i];
	}
	auto f = [&](int k) {
		int x = 0;
		rep(i, 0, N) {
			x += max(0LL, (h[i] - k*B + (A - B - 1)) / (A - B));
			dump(x);
		}
		return x <= k;
	};
	auto binarySearch = [&](int ng, int ok) {
		if (f(ng))return ng;
		while (ng + 1 < ok) {
			int m = (ng + ok) / 2;
			if (f(m))
				ok = m;
			else
				ng = m;
		}
		return ok;
	};
	cout << binarySearch(0, inf) << endl;
	return 0;
}

Measured memory_bytes: 1024
//
//  main.cpp
//  AC
//
//  Created by makinofuya on 2019/07/08.
//  Copyright © 2019 makinofuya. All rights reserved.
//
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <math.h>

typedef long long ll;
using namespace std;
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define out(s) cout << s << endl


int main(){
    int a,b,c,d;cin >> a >> b >> c >> d;
    int def_x=c-a;
    int def_y=d-b;
    int x3=c-def_y;
    int y3=d+def_x;
    int x4=a-def_y;
    int y4=b+def_x;
    printf("%d %d %d %d\n",x3,y3,x4,y4);
    return 0;
}




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


int main(){
    int N;
    long long x;
    cin >> N >> x;
    vector<long long> cost(N);
    long long sum = 0;
    for(int i=0; i<N; i++){
        cin >> cost[i];
        sum += cost[i];
    }

    if(sum == x){
        cout << N << endl;
        return 0;
    }

    sort(cost.begin(), cost.end());

    int k = 0;
    long long tmp_sum = 0;
    while(k < N){
        tmp_sum += cost[k];
        
        if(tmp_sum > x){
            cout << k << endl;
            return 0;
        }

        k += 1;
    }

    cout << N-1 << endl;
    return 0;

}


Measured memory_bytes: 3604
#include<cstdio>
char s[200001];
char t[200001], d[200001];

int isLeftDead(int p,int q,int n){
	int ok = 0;
	for(int i = 1; i <= q; i++){
		if(t[i]==s[p]){
			if(d[i]=='L'){
				p--;
				if(p==0){
					ok = 1;
					break;
				}
			}
			else{
				p++;
				if(p==n+1){
					ok = 0;
					break;
				}
			}
		}
	}
	return ok;
}

int isRightDead(int p,int q,int n){
	int ok = 0;
	for(int i = 1; i <= q; i++){
		if(t[i]==s[p]){
			if(d[i]=='L'){
				p--;
				if(p==0){
					ok = 0;
					break;
				}
			}
			else{
				p++;
				if(p==n+1){
					ok = 1;
					break;
				}
			}
		}
	}
	return ok;
}

int main(){
	int n,q;
	scanf("%d%d%s",&n,&q,s+1);
	for(int i = 1; i <= q; i++){
		char a[2], b[2];
		scanf("%s%s",a,b);
		t[i] = a[0], d[i] = b[0];
	}
	int l = 1, r = n;
	int leftRes = 0;
	while(l<=r){
		int m = (l+r)/2;
		if(isLeftDead(m,q,n)){
			leftRes = m;
			l = m+1;
		}
		else r = m-1;
	}
	l = 1, r = n;
	int rightRes = n+1;
	while(l<=r){
		int m = (l+r)/2;
		if(isRightDead(m,q,n)){
			rightRes = m;
			r = m-1;
		}
		else l = m+1;
	}
	//printf("left = %d, right = %d\n",leftRes,rightRes);
	int ans = n-leftRes-(n-rightRes+1);
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 768