akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
#include<time.h>
#include<cassert>

using namespace std;
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
#define EPS (1e-13)
#define bit(n,k) ((n>>k)&1)
const ll Mod = 1e9 + 7;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H& b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H& b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H& b) const { return x == b.x && y == b.y; }
	bool operator!=(const H& b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P& b) const { return cost < b.cost; }
	bool operator>(const P& b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E& b) const { return cost < b.cost; }
	bool operator>(const E& b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T& a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T& a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
ll bitcount(ll x) {
	int sum = 0;
	for (int i = 0; i < 20; i++)
		if ((1ll << i) & x) sum++;
	return sum;
}
/*ll fact_[200000];
ll comb(ll x, ll y, ll mod = Mod) {
	if (!fact_[0]) {
		fact_[0] = 1;
		for (int i = 1; i < 200000; i++) {
			fact_[i] = fact_[i - 1] * i % mod;
		}
	}
	if (x < y) return 0;
	return mod_pow(fact_[x], mod, mod) *
		mod_pow(fact_[x - y], mod - 2, mod) % mod *
		mod_pow(fact_[y], mod - 2, mod) % mod;
}//xCy*/
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int a, b;
vector<int>v;
signed main() {
	cin >> a >> b;
	int g = gcd(a, b);
	for (int i = 1; i * i <= g; i++) {
		if (g % i == 0) {
			v.push_back(i);
			if (g / i != i) v.push_back(g / i);
		}
	}
	sort(all(v));
	int sum = 1;
	for (int i = 1; i < v.size(); i++) {
		for (int j = 1; j < i; j++) {
			if (v[i] % v[j] == 0) goto loop;
		}
		sum++;
	loop:;
	}
	cout << sum << endl;
}

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

string s;

struct st{
    int c1,c2,mn1,mn2;
};
vector < st > L, R;

int main(){

    int j,i,n,c1,c2,mn1,mn2;
    cin>>n;
    for(i=1; i<=n; i++){
        cin>>s;
        c1=c2=mn1=mn2=0;
        for(j=0; j<s.size(); j++){
            if(s[j]=='(')c1++;
            else c1--;
            mn1=min(mn1,c1);
        }
        for(j=s.size()-1; j>=0; j--){
            if(s[j]==')')c2++;
            else c2--;
            mn2=min(mn2,c2);
        }
        if(c1>=0)L.push_back({c1,c2,mn1,mn2});
        else R.push_back({c1,c2,mn1,mn2});
    }
    sort(L.begin(),L.end(), [] (st a , st b){return a.mn1>b.mn1;});
    sort(R.begin(),R.end(), [] (st a , st b){return a.mn2<b.mn2;});

    int cnt=0;
    for(auto k:L){
        if(cnt+k.mn1<0){
            cout<<"No"<<endl;
            return 0;
        }
        cnt+=k.c1;
    }
    for(auto k:R){
        if(cnt+k.mn1<0){
            cout<<"No"<<endl;
            return 0;
        }
        cnt+=k.c1;
    }
    if(cnt)cout<<"No"<<endl;
    else cout<<"Yes"<<endl;

    return 0;
}


Measured memory_bytes: 19088
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<deque>
#define rep(i,n) for(int i = 0;i<n;i++)
#define _GLIBCXX_DEBUG
using ll = long long; 
using namespace std;

int main() {
    string s;
    cin >> s;
    vector<bool> flag(26,false);
    for(int i = 0; i < s.size() ; i++) {
        flag[s[i] - 'a'] = true;
    }
    int ans = 0;
    for(int i = 0; i < 26; i++) {
        if(!flag[i]) {
            cout << (char)(i + 'a') << endl;
            break;
        }
        ans++;
    }
    if(ans == 26) cout << "None" << endl;
}

Measured memory_bytes: 512
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<functional>
#include<vector>
#include<queue>
using namespace std;
#define f(i,n) for(int i=0;i<(int)n;i++)
#define MOD 1000000009

int main(void){
	int n, q;
	int x, y, k;

	scanf("%d %d", &n,&q);
	if (n != 1){
		f(qq, q){
			scanf("%d %d", &x, &y);
			while (x != y){
				if (x < y){
					k = y%n;
					y = y / n;
					if (k > 1)y++;
				}
				else{
					k = x%n;
					x = x / n;
					if (k > 1)x++;
				}
			}
			printf("%d\n", x);
		}
	}
	else{
		f(qq, q){
			scanf("%d %d", &x, &y);
			printf("%d\n", min(x, y));
		}
	}

	return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
//#include<iostream>
//#include<cstdio>
//#include<cstring>
//#include<string>
//#include<queue>
//#include<cmath>
//#include<algorithm>
//#define debug1 cout<<"?"<<endl;
//#define debug2 cout<<"?"<<i<<endl;
#define PII pair<int,int>
typedef long long ll;
const int maxn=1e2+9;
const double pi=acos(-1);
const int mod=998244353;
const int INF=0x3f3f3f3f;
const double ep=1e-7;
using namespace std;
int main()
{
	char s[maxn];
	scanf("%s",s+1);
	int i,len=strlen(s+1),ju=0;
	for(i=2;i<=len&&!ju;i++)
	{
		if(s[i-1]!=s[i])ju=1;
	}
	if(ju)puts("Yes");
	else puts("No");
}

Measured memory_bytes: 256
#include <stdio.h>
#define LLI long long int

LLI flymove(LLI a,LLI m){
  LLI c=1,p=1;
  while((p=p*a%m)!=1) {
    c++;
  }
  return c;
}

LLI lcm(LLI r,LLI s){
  LLI t=1;
  while(r*t%s!=0)t++;
  return r*t;
}

int main(){
  LLI a1,m1,a2,m2,a3,m3;
  LLI x,y,z;
  while(scanf("%lld %lld %lld %lld %lld %lld",&a1,&m1,&a2,&m2,&a3,&m3)){
    if((a1|m1|a2|m2|a3|m3)==0) break;
    x=flymove(a1,m1);
    y=flymove(a2,m2);
    z=flymove(a3,m3);
    printf("%lld\n",lcm(lcm(x,y),z));
  }
  return 0;
}

Measured memory_bytes: 412
#include <bits/stdc++.h>
using namespace std;
namespace mine {
typedef long long ll;
#define pr pair<int, int>
#define FR first
#define SE second
#define MP make_pair
#define PB push_back
#define vc vector
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define bin(x) (1ll << (x))
#define GG(x) \
    if (x)    \
    puts("error")
ll qread() {
    ll ans = 0, f = 1;
    char c = getchar();
    while (c < '0' or c > '9') {
        if (c == '-')
            f = -1;
        c = getchar();
    }
    while ('0' <= c and c <= '9') ans = ans * 10 + c - '0', c = getchar();
    return ans * f;
}
void write(ll num) {
    if (num < 0)
        putchar('-'), num = -num;
    if (num >= 10)
        write(num / 10);
    putchar('0' + num % 10);
}
void write1(ll num) {
    write(num);
    putchar(' ');
}
void write2(ll num) {
    write(num);
    putchar('\n');
}
template <typename T>
void chmax(T &x, const T y) {
    x = (x > y ? x : y);
}
template <typename T>
void chmin(T &x, const T y) {
    x = (x < y ? x : y);
}
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

const int INF = 0x3f3f3f3f;
const int MOD = 993244853;
inline int mm(const int x) { return x >= MOD ? x - MOD : x; }
template <typename T>
inline void add(T &x, const T y) {
    x = mm(x + y);
}
inline ll qpower(ll x, ll e) {
    ll ans = 1;
    GG(e < 0);
    while (e) {
        if (e & 1)
            ans = ans * x % MOD;
        x = x * x % MOD;
        e >>= 1;
    }
    return ans;
}
ll invm(ll x) { return qpower(x, MOD - 2); }
const int N = 1e5 + 10;

ll bs[N], base = 13331, pp[N];
ll gg(int l, int r) { return (pp[r] - pp[l - 1] * bs[r - l + 1] % MOD + MOD) % MOD; }
char str[N];
int n;
bool check(int ln) {
    for (int l = 1; l + ln - 1 <= n; l++)
        for (int r = l + ln; r + ln - 1 <= n; r++)
            if (gg(l, l + ln - 1) == gg(r, r + ln - 1))
                return 1;
    return 0;
}
void main() {
    bs[0] = 1;
    for (int i = 1; i < N; i++) bs[i] = bs[i - 1] * base % MOD;

    n = qread();
    scanf("%s", str + 1);
    for (int i = 1; i <= n; i++) pp[i] = (pp[i - 1] * base + (str[i] - 'a' + 1)) % MOD;
    int fl = 0, fr = n, ans = 0;
    while (fl <= fr) {
        int mid = (fl + fr) >> 1;
        if (check(mid))
            ans = mid, fl = mid + 1;
        else
            fr = mid - 1;
    }
    write(ans);
}  //(ans+MOD)%MOD
};  // namespace mine
int main() {
    srand(time(0));
    mine::main();
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP2(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(v) (v).begin(),(v).end()
#define INF 2e9
typedef long long ll;

int factorial(int x){
  return x? x*factorial(x-1):1;
}

double dist(pair<int,int> a,pair<int,int> b){
  return sqrt(pow(a.first-b.first,2)+pow(a.second-b.second,2));
}

int main()
{
  int n;
  cin>>n;
  vector<pair<int,int>> p(n);
  REP(i,n){
    int x,y;
    cin>>x>>y;
    p[i]=make_pair(x,y);
  }

  double l=0;
  REP(i,n){
    REP2(j,i+1,n){
      l+=dist(p[i],p[j]);
    }
  }

  printf("%.10f\n",l*2*factorial(n-1)/factorial(n));

  return 0;
}

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

int main(){
	int N, M;
	cin>>N>>M;
	int A[N][M];

	for(int u=0;u<N;u++){
		for(int v=0;v<M;v++){
			A[u][v]=0;
		}
	}

	for(int i=0;i<N;i++){
		int K;
		cin>>K;
		for(int k=0;k<K;k++){
			int name;
			cin>>name;
			A[i][name-1]=1;
		}
	}
	
	int answer=0;
	for(int l=0;l<M;l++){
		int wa=0;
		for(int n=0;n<N;n++){
			wa += A[n][l];
		}
		if(wa==N){
			answer += 1;
		}
	}
	cout<<answer;
	return 0;
}	


Measured memory_bytes: 256
a,b,c,d = input('').split()
a=int(a)
b=int(b)
c=int(c)
d=int(d)
while 1:
	c=c-b
	if c<=0:
		print('Yes')
		break
	a=a-d
	if a<=0:
		print('No')
		break

Measured memory_bytes: 9176
/*
 * Author: Khan
 * Date: 9th October, 2017
 */
#include <iostream>
#include <algorithm>

using namespace std;

int main(int argc, char const *argv[])
{
    int R[200000], n, maxv = -2000000000, minv = 0;

    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        cin >> R[i];
    }
    minv = R[0];
    for (int i = 1; i < n; ++i)
    {
        maxv = max(maxv, R[i] - minv);
        minv = min(minv, R[i]);
    }
    cout << maxv << endl;
    return 0;
}

Measured memory_bytes: 3852
#include<bits/stdc++.h>
#define int long long
using namespace std;
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;

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

    int N; cin>>N;
    vector<vector<int>> a(N,vector<int>(N));
    for(int i=0;i<N;i++) for(int j=0;j<N;j++) cin>>a[i][j];

    vector<int> dp(1<<N,-INF);
    dp[0]=0;
    for(int S=1;S<(1<<N);S++){
        int score=0;
        for(int i=0;i<N;i++) for(int j=i+1;j<N;j++){
            if(S>>i&1 and S>>j&1) score+=a[i][j];
        }
        dp[S]=score;
        for(int T=S;T>0;T=(T-1)&S){
            chmax(dp[S],dp[T]+dp[S^T]);
        }
    }
    cout<<dp[(1<<N)-1]<<endl;
    return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;  // vi <=> vl
using vb = vector<bool>;
using boolGraph = vector<vb>;
using P = pair<int, int>;  // int <=> ll
const int MOD = 1e9+7;
const double EPS = 1e-9;

int main() {
  int n; cin >> n;
  Graph arr(n, vi(2));
  rep(j,2) rep(i,n) cin >> arr[i][j];

  sort(all(arr));

  vi b(n);
  rep(i,n) b[i] = arr[i][1];

  sort(all(b));

  rep(i,n) {
    if (arr[i][0] > b[i]) {
      cout << "No\n";
      return 0;
    }
  }

  rep(i,n) {
    if (arr[i][1] == b[i]) {
      cout << "Yes\n";
      return 0;
    }
  }

  rep(i,n-1) {
    if (b[i] >= arr[i+1][0]) {
      cout << "Yes\n";
      return 0;
    }
  }

  vi target(n);
  rep(i,n) target[i] = lower_bound(all(b), arr[i][1]) - b.begin();

  int v = 0;
  rep(i,n) {
    v = target[v];
    if (v == 0 && i < n-1) {
      cout << "Yes\n";
      return 0;
    }
  }

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


Measured memory_bytes: 7296
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <sstream>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector <vector <int>> vii;
typedef vector <long long> vll;
typedef vector <string> vs;
typedef vector <char> vc;
typedef set <int> si;
typedef set <string> ss;
typedef queue <int> qi;
typedef queue <long long> qll;
typedef queue <string> qs;
typedef queue <char> qc;
typedef struct board board;
typedef pair <int, int> pi;
typedef pair <long long, long long> pll;
typedef pair <int, pair<int, int>> pii;

#define eb emplace_back
#define ppb pop_back
#define clr(a) a.clear()
#define F first
#define S second
#define mkp make_pair

#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()

#define left(x) x * 2
#define right(x) x * 2 + 1

#define meme(a, b, c) fill(a + 1, a + 1 + b, c)

#define max(a, b) (a > b ? a : b)
#define min(a, b) (a > b ? b : a)
#define abs(a) (a > 0? a : -(a))

#define move(s) s += "#"

#define fr(i, a, b) for (ll i = a; i <= b; ++ i)
#define rf(i, a, b) for (ll i = a; i >= b; -- i)

#define eprintf(...) fprintf(stderr, __VA_ARGS__);

void to_pray() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cerr << "Ready\n";
}

const int N = 4e6 + 10;
const int NN = 1e3 + 10;
const int NNN = 2e3 + 9;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const ll LLINF = 1e12 + 7;
const ll P = 53;
const int EPS = 1e-9 - 8;
const int vN = 2e4 + 10;
const int sz = (1 << 22) - 1;
const double PI = acos(-1);

int a[N];

int main () {
    to_pray();

    for (int i = 1; i <= 3; ++ i) {
    	cin >> a[i];
    }
    
    sort(a + 1, a + 1 + 3);
    
    int sum = 0;
    
    for (int i = 1; i < 3; ++ i) {
    	sum += abs(a[i] - a[i + 1]);
    }
    
    cout << sum;
    
    //eprintf("%.18lf seconds\n", (double)clock() / CLOCKS_PER_SEC);
    cout << '\n';
    return 0;
}

Measured memory_bytes: 256
def C(a, b, c):
    if((c>b) & (b>a)):
        return True
    else:
        return False

def main():
    a, b, c = map(int, input().split())
    k = int(input())
    ans_c = c
    for i in range(k+1):
        c = ans_c
        for j in range(k-i):
            c = c*2
        if(C(a, b, c)):
            print('Yes')
            return
        b = b * 2
    print('No')
main()

Measured memory_bytes: 61780
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>

#define int long long
#define CONTAINS(v,n) (find((V).begin(), (V).end(), (n)) != (V).end())
#define SORT(v) sort((V).begin(), (V).end())
#define RSORT(v) sort((V).rbegin(), (V).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) (V.erase(remove((V).begin(), (V).end(), (a)), (V).end()))
#define REVERSE(v) (reverse((V).begin(), (V).end()))
#define LOWER_BOUND(v,a) (lower_bound((V).begin(), (V).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((V).begin(), (V).end(), (a)))
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
using namespace std;

int N;
int T[100];
int V[100];

signed main()
{
	cin >> N;
	REP(i, N)
	{
		cin >> T[i];
		if (i > 0)
		{
			T[i] += T[i - 1];
		}
	}
	REP(i, N) cin >> V[i];



	double len = 0;
	double v = 0.0;
	for (int i = 0; i < N; i++)
	{
		double tc = i == 0 ? 0 : T[i - 1];
		double ca = v - tc;
		double tflat = V[i] - ca;

		double ta = DBL_MAX;
		double tb = DBL_MAX;

		for (int j = i; j < N; j++)
		{
			int vv = j < N - 1 ? V[j + 1] : 0;
			double ci = vv + T[j];

			double taa = (-ca + ci) / 2.0;
			double tbb = ci - V[i];
			ta = MIN(ta, taa);
			tb = MIN(tb, tbb);
		}

		if (tflat < T[i] && tflat < ta)
		{
			if (tb < T[i]) // /-\'
			{
				len += v * (tflat - tc) + (tflat - tc) * (tflat - tc) / 2.0;
				v = v + (tflat - tc);

				len += v * (tb - tflat);

				v = v - (T[i] - tb);
				len += v * (T[i] - tb) + (T[i] - tb) * (T[i] - tb) / 2.0;
			}
			else // /--'
			{
				len += v * (tflat - tc) + (tflat - tc) * (tflat - tc) / 2.0;
				v = v + (tflat - tc);

				len += v * (T[i] - tflat);
			}
		}
		else
		{
			if (ta < T[i]) // /\'
			{
				len += v * (ta - tc) + (ta - tc) * (ta - tc) / 2.0;
				v = v + (ta - tc);

				v = v - (T[i] - ta);
				len += v * (T[i] - ta) + (T[i] - ta) * (T[i] - ta) / 2.0;
			}
			else // /'
			{
				len += v * (T[i] - tc) + (T[i] - tc) * (T[i] - tc) / 2.0;
				v = v + (T[i] - tc);
			}
		}
	}

	cout << fixed << setprecision(5);
	cout << len;
}



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

int main() {
  string s; cin >> s;
  s = '0' + s;
  int n = s.size();
  int ans = 0;
  for (int i = n - 1; i >= 0; i--) {
    int a = s[i] - '0';
    int b = s[i-1] - '0';
    if (a > 5 || (a == 5 && b >= 5)) {
      s[i-1]++;
      ans += 10 - a;
    }
    else
      ans += a;
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

bool Evidences[21][21];
int Degree[21];

void solve(int m, int n){
    
    for(int i=1; i<m; i++){
        for(int j=1; j<m; j++){
            if(Degree[j]==0){
                cout<<j<<endl;
                Degree[j] = -1;
                for(int k=1; k<m; k++){
                    if(Evidences[k][j]){
                        Degree[k]--;
                    }
                }
            }
        }
    }
    
}

int main(void){
    int m,n,x,y;
    
    cin>>m>>n;
    for(int i=0; i < n ; i++){
        cin>>x>>y;
        Evidences[y][x] = true;
        Degree[y]++;
    }
    
    solve(m+1,n+1);
    
    return 0;
}



Measured memory_bytes: 3120
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#include <deque>
#include <queue>
#define all(x) (x).begin(),(x).end()

void solve(){

}
int main(){
    string s;
    cin >> s;
    int sum = 0;
    for (int i = 0; i < 4; i++){
        if (s[i] == '2'){
            sum++;
        }
    }
    cout << sum << endl;


    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>

int main() {
	int n, x,i,j,k,count=0;
	for (;;) {
		scanf("%d %d", &n, &x);
		if (n == 0 && x == 0) return 0;
		for (i = 1; i < n + 1; i++) {
			for (j = 1; j < n + 1; j++) {
				for (k = 1; k < n + 1; k++) {
					if (i != k && k != j && i != j) {
						if (i + j + k == x)	 count++;

					}
				}
			}
		}
		printf("%d\n", count / 6);
		count = 0;
	}

	


	return 0;
}

Measured memory_bytes: 600
# -*- coding: utf-8 -*-

def main():
    import sys

    def input(): return sys.stdin.readline().strip()
    def INT(): return int(input())
    def MAP(): return map(int, input().split())
    def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
    
    def query(i):
        s = intv
        i += 1
        while i > 0:
            s = max(s, tree[i-1])
            i -= i & -i
        return s
    
    def update(i, x):
        i += 1
        while i <= size:
            tree[i-1] = max(tree[i-1], x)
            i += i & -i

    n = INT()
    H = LIST()
    A = LIST()

    n += 2
    nv = 1
    while nv < n:
        nv *= 2
    size = nv
    intv = 0
    tree = [intv] * nv

    for h, a in zip(H, A):
        mx = query(h)
        update(h, mx + a)
    ans = query(n)
    print(ans)
main()


Measured memory_bytes: 35972
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String[] input = sc.next().split("");
		int x = 0;
		int max = 0;
		for (String element : input) {
			if (element.equals("I")) {
				x++;
			} else {
				x--;
			}
			if (x > max) {
				max = x;
			}
		}
		System.out.println(max);
	}
}


Measured memory_bytes: 35888
import java.io.*;
class Sta{
    int[] s;
    int top;
    Sta(){
        s=new int[1000];
        top=0;
    }
    void push(int x){
        top++;
        s[top]=x;
    }
    int pop(){
        top--;
        return s[top+1];
    }
}
public class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader din=new BufferedReader(new InputStreamReader(System.in));
        String line=din.readLine();
        String[] tokens=line.split(" ");
        Sta stack=new Sta();
        for(int i=0;i<tokens.length;i++){
            String x=tokens[i];
            if(x.equals("+")){
                stack.push(stack.pop()+stack.pop());
            }else if(x.equals("-")){
                stack.push(-stack.pop()+stack.pop());
            }else if(x.equals("*")){
                stack.push(stack.pop()*stack.pop());
            }else{
                int t=Integer.parseInt(x);
                stack.push(t);
            }
        }
        System.out.println(stack.pop());
    }
}

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

int main() {
  int n;cin>>n;
  vector<int> s(13,1),h(13,1),c(13,1),d(13,1);
  for(int i=0;i<n;i++){
    int a;
    char m;
    cin>>m>>a;
    if(m=='S')s[a-1]=0;
    if(m=='H')h[a-1]=0;
    if(m=='C')c[a-1]=0;
    if(m=='D')d[a-1]=0;
  }
  for(int i=0;i<13;i++){
    if(s[i])cout<<"S "<<i+1<<endl;
  }
  for(int i=0;i<13;i++){
    if(h[i])cout<<"H "<<i+1<<endl;
  }
  for(int i=0;i<13;i++){
    if(c[i])cout<<"C "<<i+1<<endl;
  }
  for(int i=0;i<13;i++){
    if(d[i])cout<<"D "<<i+1<<endl;
  }
}


Measured memory_bytes: 3060
#include <bits/stdc++.h>
    
using namespace std;
    
int main() {    
    int n;
    cin >> n;
    
    int ans = 0;
    
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= n; ++j) {
            for (int k = 1; k <= n; ++k) {
                ans += gcd(i, gcd(j, k));
            }
        }    
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 3624
//g++ -std=c++11 -Wall -O2 -o main.exe main.cpp
//g++ -std=c++14 -Wall -O2 -o main.exe main.cpp
 
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <functional>
#include <algorithm>
#include <complex>
#include <numeric>
#include <queue>
#include <stack>
//最大公約数: gcd()
//最小公倍数: lcm()

#define ll long long int

using namespace std;
 
template <typename T>
void sortasc(vector<T> &v){ //vectorを昇順にソート
    sort(v.begin(), v.end(), std::greater<int>());
    return;
}
 
template <typename T>
void sortdesc(vector<T> &v){ //vectorを降順にソート
    sort(v.begin(), v.end(), std::less<int>());
    return;
}

//------

int N, T, A;
vector<int> H;

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

    int t;
    for(int i = 0; i < N; i++){
        cin >> t;
        H.push_back(t);
    }

    int max_index = 0;
    double temp, max = 10000;
    for(int i = 0; i < N; i++){
        temp = T - H[i] * 0.006;
        if(abs(A - temp) < max){
            max = abs(A - temp);
            max_index = i + 1;
        }
    }

    cout << max_index << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
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; }

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

    int N; cin >> N;
    vei a(N+1); rep(i,N) cin >> a[i+1]; //1-index
    vei r(N+1), ans;

    for(int i = N; i >= 1; i--) {
        int sum = 0; 
        for(int j = i; j <= N; j += i) {
            if(j == i) continue;
            else sum += r[j];
        }
        if(sum % 2 != a[i]) { r[i] = 1; ans.pub(i); }
        else r[i] = 0;
    }
    int M = ans.size();
    if (M == 0) { cout << M << endl; return 0; }
    cout << M << endl;
    rep(i,M-1) cout << ans[i] << " ";
    cout << ans[M-1] << endl;
    return 0;
}



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

int main() {
	int n,a,ansmin=0,ansmax=0;cin>>n;
  	vector<int> iro(13);
  	for(int i=0;i<n;i++){
    	cin>>a;
      	iro[a/400]++;
    }
  	for(int i=0;i<8;i++){
    	if(iro[i]>0) ansmin++;	
    }
  	ansmax=ansmin;
	
  	for(int i=8;i<=12;i++){
    	if(iro[i]>0){
        	ansmax+=iro[i];
          	if(ansmin==0) ansmin++;
        }
    }
  cout<<ansmin<<" "<<ansmax<<endl;
}

Measured memory_bytes: 256
N,K=map(int,input().split())
r,s,p=map(int,input().split())
T=list(input())


for i in range(N-K):
    if T[i]==T[i+K]:
        T[i+K]="0"

def win(c):
    if c=="r":
        return p
    elif c=="s":
        return r 
    elif c=="p":
        return s 
    else:
        return 0
ans=0
for i in T:
    ans+=win(i)
print(ans)



Measured memory_bytes: 4084
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<utility>
#include<math.h>

using namespace std;
typedef pair<int, int> P;
typedef long long int ll;

const int INF = 1<<30;

int main(){
  string s;cin>>s;
  int n=(int)s.size();
  int black=0;ll ans=0;
  for(int i=0;i<n;i++){
    if(s[i]=='B')black++;
    else ans+=black;
  }
  cout<<ans<<endl;
}


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

int root(int x, vector<int> &city){
    if(city.at(x) == x){
        return x;
    }
    else{
        return city.at(x) = root(city.at(x), city);
    }
}


int main(){
    int n, m;
    cin >> n >> m;
    vector<int> city(n);
    vector<int> rank(n);
    vector<int> unionCity(n);
    for(int i = 0;i < n;i++){
        city.at(i) = i;
        rank.at(i) = 0;
        unionCity.at(i) = 0;
    }

    for(int i = 0;i < m;i++){
        int a, b;
        cin >> a >> b;
        int x = city.at(a-1);
        int y = city.at(b-1);
        int rtx = root(x, city);
        int rty = root(y, city);
        if(rtx != rty){
            if(rank[rtx] < rank[rty]){
                city.at(rtx) = rty;
            }
            else{
                city.at(rty) = rtx;
            }
            if(rank.at(rtx) == rank.at(rty)){
                rank.at(rtx)++;
            }

        }
    }

    for(int i = 0;i < n;i++){
        int rt = root(i, city);
        if(unionCity.at(rt) == 0){
            unionCity.at(rt)++;
        }
    }
    int sum = 0;

    for(int i = 0;i < n;i++){
        sum += unionCity.at(i);
    }
    cout << sum - 1 << endl;

}

Measured memory_bytes: 4524
<?php

define('MAX', 110000);
$table = new SplFixedArray(MAX);
$primes = new SplFixedArray(10001);
$primes[0] = 0;
$i = 2;
$p_i = 1;
while ($p_i <= 10000 && $i < MAX) {
    $primes[$p_i] = $primes[$p_i - 1] + $i;
    $p_i++;
    for ($j = $i; $j < MAX; $j += $i) {
        $table[$j] = -1;
    }
    while ($i < MAX && $table[$i] === -1) {
        $i++;
    }
}

while (true) {
    fscanf(STDIN, '%d', $n);
    if ($n === 0) {
        break;
    }
    echo $primes[$n] . PHP_EOL;
}

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

using namespace std;

int main(void) {
  int N; cin >> N;
  int dp[N];
  int h[N];

  for (int i = 0; i < N; i++) {
    cin >> h[i];
  }

  dp[0] = 0;
  dp[1] = abs(h[0] - h[1]);
  for (int i = 1; i < N-1; i++) {
    dp[i+1] = min(dp[i] + abs(h[i] - h[i+1]), dp[i-1] + abs(h[i-1] - h[i+1]));
  }
  
  cout << dp[N-1] << endl;

  return 0;
}

Measured memory_bytes: 1024
/* ****devACE**** */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
using namespace std;

#define N  1005
vector<int>adj[N];
int vis[N],lev[N],par[N];
vector<int>ans;
int mn=hell;
void bfs(int node){
	memset(vis,0,sizeof vis);
	memset(lev,-1,sizeof lev);
	memset(par,0,sizeof par);

	queue<int>q;
	q.push(node);
	vis[node]=1,lev[node]=1;
	par[node]=0;
	while(!q.empty()){
		int cur = q.front();
		q.pop();
		for(auto i:adj[cur]){
			if(lev[i]==-1){
				lev[i]=lev[cur]+1;
				par[i]=cur;
				q.push(i);
			}else{
				if(i==node){
					if(lev[cur]<mn){
						ans.clear();
						mn=lev[cur];
						int x = cur;
						while(x){
							ans.pb(x);
							x=par[x];
						}
					}
					return;
				}
			}
		}
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		int n,m,i,j,k;
		cin>>n>>m;

		for(i=0;i<m;i++){
			int x,y;
			cin>>x>>y;
			adj[x].pb(y);
		}

		for(i=1;i<=n;i++){
			bfs(i);
		}

		if(ans.empty())return cout<<"-1",0;

		cout<<sz(ans)<<"\n";
		for(auto i:ans)cout<<i<<"\n";



	}
	return 0;
}

Measured memory_bytes: 384
a, b, c, k = map(int,input().split())

if a==b==c:
    print(0)
    exit()
    
a_=b+c
b_=a+c
c_=a+b

if k==0:
    print(a-b)
elif k%2==0:
    print(a-b)
else:
    print(a_-b_)

Measured memory_bytes: 9076
#include <bits/stdc++.h>
#include <math.h>
#define ALL(a)    a.begin(), a.end() 
#define rep(i, K, N)  for(long long int i = K; i < N; i++)
#define ll long long int
using namespace std;

int main(){

ll N, Ans = 0;cin >> N;

rep(i, 1, N + 1){

    Ans += i*floorl(N/i)*(floorl(N/i) + 1)/2;

}

cout << Ans;

}

Measured memory_bytes: 3596
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

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

        public static void Solve()
        {
            var NA = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var (N, A) = (NA[0], NA[1]);
            var X = Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray();
            var max = Math.Max(A, X.Max());
            var answer = 0L;

            var dp = new long[N + 1][][].Select(
                x => x = new long[N + 1][].Select(
                    y => y = new long[N * max + 1]).ToArray()).ToArray();
            dp[0][0][0] = 1;
            for (var j = 1; j <= N; j++)
            {
                for (var k = 0; k <= N; k++)
                {
                    for (var s = 0; s <= N * max; s++)
                    {
                        var xj = X[j - 1];
                        if (s < xj)
                            dp[j][k][s] = dp[j - 1][k][s];
                        else if (s >= xj && k > 0)
                            dp[j][k][s] = dp[j - 1][k][s] + dp[j - 1][k - 1][s - xj];
                    }
                }
            }

            for (var k = 1; k <= N; k++)
            {
                answer += dp[N][k][k * A];
            }
            Console.WriteLine(answer);
        }
    }
}


Measured memory_bytes: 79568
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**6)

w,h,n=map(int,input().split())
u,d,r,l=h,0,w,0
for _ in range(n):
    x,y,a=map(int,input().split())
    if a==1:
        if l<x: l=x
    elif a==2:
        if r>x: r=x
    elif a==3:
        if d<y: d=y
    elif a==4:
        if u>y: u=y

if r-l<=0 or u-d<=0:
    print(0)
else:
    print((r-l)*(u-d))

Measured memory_bytes: 9216
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AOJ
{
	class Program
	{
		static void Main(string[] args)
		{
			var n = int.Parse(Console.ReadLine());
			while (n-- != 0)
			{
				var t = new char[52];
				var i = 26;
				var s = Console.ReadLine();
				foreach(var c in s)
				{
					if ('a' <= c && c <= 'z') t[i] = c;
					else if (c == '<') i--;
					else if (c == '>') i++;
				}
				Console.WriteLine(new string(t.Where(c => c != '\0').ToArray()));
			}
		}
	}
}

Measured memory_bytes: 5668
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Runtime.Remoting.Contexts;
using System.Security.Cryptography.X509Certificates;

namespace Contest
{
    class Scanner
    {
        private string[] line = new string[0];
        private int index = 0;
        public string Next()
        {
            if (line.Length <= index)
            {
                line = Console.ReadLine().Split(' ');
                index = 0;
            }
            var res = line[index];
            index++;
            return res;
        }
        public int NextInt()
        {
            return int.Parse(Next());
        }
        public long NextLong()
        {
            return long.Parse(Next());
        }
        public string[] Array()
        {
            line = Console.ReadLine().Split(' ');
            index = line.Length;
            return line;
        }
        public int[] IntArray()
        {
            var array = Array();
            var result = new int[array.Length];
            for (int i = 0; i < array.Length; i++)
            {
                result[i] = int.Parse(array[i]);
            }

            return result;
        }
        public long[] LongArray()
        {
            var array = Array();
            var result = new long[array.Length];
            for (int i = 0; i < array.Length; i++)
            {
                result[i] = long.Parse(array[i]);
            }

            return result;
        }
    }

    class Program
    {
        private long A, B, C, X, Y;

        private void Scan()
        {
            var sc = new Scanner();
            A = sc.NextInt();
            B = sc.NextInt();
            C = sc.NextInt();
            X = sc.NextInt();
            Y = sc.NextInt();
        }

        public void Solve()
        {
            Scan();
            long ans = 0;
            if (A + B > C * 2)
            {
                long min = Math.Min(X, Y);
                ans += C * 2 * min;
                X -= min;
                Y -= min;
            }

            ans += Math.Min(A, C * 2) * X;
            ans += Math.Min(B, C * 2) * Y;
            Console.WriteLine(ans);
        }

        static void Main(string[] args)
        {
            new Program().Solve();
        }
    }
}

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

string calc(int n){
    if(n == 0) return "0";
    if(n == 1) return "1";
    string s;
    int r = abs(n)%2;
    char c = '0'+r;
    s = calc((n-r)/(-2))+c;
    return s;
}

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

    string ans = calc(n);
    cout << ans << endl;
}


Measured memory_bytes: 256
using System;

public class Test
{
	static public void Main( )
	{	
		while( true ) {
			string[] str = Console.ReadLine().Split( ' ' );
			if( "?".Equals( str[1] ) ) break;
			
			int a = int.Parse( str[0] );
			int b = int.Parse( str[2] );
			int res = 0;
			switch( str[1] ) {
				case "+": res = a + b;
					break;
				case "-": res = a - b;
					break;
				case "*": res = a * b;
					break;
				case "/": res = a / b;
					break;
			}
			
			Console.WriteLine( "{0}" , res );
		}
	}
}

Measured memory_bytes: 5740
package main

import (
	"fmt"
	"strings"
)

func main() {
	var s string
	fmt.Scan(&s)

	ss := strings.Split(s, "")

	ans := 0
	for _, c := range ss {
		if c == "1" {
			ans++
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 640
unittest
{
	assert( [ "2 2" ].parse.expand.solve == 8 );
	assert( [ "3 2" ].parse.expand.solve == 12 );
	assert( [ "1 8" ].parse.expand.solve == 0 );
	assert( [ "100000 100000" ].parse.expand.solve == 530123477 );
}



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

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

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto nm = input.front.split.to!( long[] );
	return tuple( nm[ 0 ], nm[ 1 ] );
}

const MOD = pow( 10L, 9 ) + 7;

auto solve( long n, long m )
{
	// 犬と猿の数の差を計算（差が2匹以上だったら交互に並べられない）
	auto d = ( n - m ).abs;
	if( 2 <= d ) return 0;
	
	// 順列を計算
	auto np = permutation( n );
	auto mp = permutation( m );
	
	// 犬と猿の組み合わせを計算
	auto nmp = ( np * mp ) % MOD;
	if( d == 0 ) nmp = ( nmp * 2 ) % MOD;		// 数の差が無い場合、犬が左端のパターンと猿が左端のパターンで2倍になる
	
	return nmp;
}

auto permutation( long x )
{
	static auto caches = [ 0L, 1L ];
	
	if( caches.length <= x )
	{
		auto h = caches.length;
		caches.length = x + 1;
		foreach( i; h .. caches.length )
		{
			caches[ i ] = ( caches[ i - 1 ] * i ) % MOD;
		}
	}
	
	return caches[ x ];
}


Measured memory_bytes: 2428
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
const ll N=305;
ll mod=1e9+7;
ll a[N];
ll dp[100005];
ll n,k;
int main()
{
    memset(dp,0,sizeof(dp));
	cin>>n>>k;
	for(int i=0;i<n;i++)
	cin>>a[i];
	
	for(int i=1;i<=k;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(i>=a[j])
			dp[i]|=(!dp[i-a[j]]);
		}
	}
	if(dp[k])
	cout<<"First"<<endl;
	else
	cout<<"Second"<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
  os << "{" <<p.first << ", " << p.second << "}";
  return os;
}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/
// cnt + 1, cnt - 1
ll beki[2][252521];

ll f(ll X, int cnt = 1){
    if(X == 0)return cnt;
    ll M = __builtin_popcount(X);
    return f(X%M, cnt+1);
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    ll N;
    string X;
    cin >> N >> X;
    reverse(all(X));
    vvec<ll> beki(2, vec<ll>(N,0));
    int cnt = 0;
    rep(i,N)cnt += X[i] == '1';
    ll tmp = 1;
    rep(i,N){
        beki[0][i] = tmp % (cnt+1);
        tmp *= 2;
        tmp %= (cnt+1);
    }
    tmp = 1;
    rep(i,N){
        if(cnt - 1 == 0){
            beki[1][i] = -1;
            continue;
        }
        beki[1][i] = tmp % (cnt - 1);
        tmp *= 2;
        tmp %= (cnt - 1);
    }

    ll X0[2] = {0,0};
    rep(j,2){
        ll M = cnt;
        if(j == 0)M++;
        else M--;
        rep(i,N){
            if(M == 0)break;
            if(X[i] == '1')X0[j] += beki[j][i];
            X0[j] %= M;
        }
    }
    /*
    print(X);
    print(beki[0]);
    print(beki[1]);
    print(X0);
    */
    vector<int> ans(N);
    rep(i,N){
        ll M = cnt;
        ll tmpX;
        if(X[i] == '1'){
            M--;
            if(M == 0){
                ans[i] = 0;
                continue;
            }
            tmpX = X0[1];
            tmpX -= beki[1][i];
            tmpX += M;
            tmpX %= M;
        }
        else{
            M++;
            tmpX = X0[0];
            tmpX += beki[0][i];
            tmpX %= M;
        }
        ans[i] = f(tmpX);
    }
    reverse(all(ans));
    rep(i,N){
        cout << ans[i] << endl;
    }
}



Measured memory_bytes: 8364
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <bitset>
#include <iomanip>
#include <deque>
#include <tuple>
#include <algorithm>

using namespace std;

int main()
{
    string s[3];

    cin >> s[0] >> s[1] >> s[2];

    cout << s[0][0] << s[1][1] << s[2][2] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int N;
	cin >> N;
	int a[N+2];
	int dif[N];
	int ans = 0;
	for (int i = 0;i < N+2;i++) {
		if (0 < i&&i < N+1) {
			cin >> a[i];
		} else {
			a[i] = 0;
		}
	}
	for (int i = 0;i < N;i++) {
		dif[i] = 0;
		if ((a[i+1]-a[i])*(a[i+2]-a[i+1]) < 0) {
			int b[3] = {a[i],a[i+1],a[i+2]};
			sort(b,b+3);
			if (a[i] < a[i+1]) {
				dif[i] = b[2]-b[1];
			} else {
				dif[i] = b[1]-b[0];
			}
		}
	}
	for (int i = 1;i < N+2;i++) {
		ans += abs(a[i]-a[i-1]);
	}
	for (int i = 0;i < N;i++) {
		int ans2 = ans;
		ans2 -= dif[i] * 2;
		cout << ans2 << endl;
	}
}

Measured memory_bytes: 2048
n = int(input()) # 最初のカードの枚数
Scards = [] # 空のリスト  # appendメソッドで追加  
Hcards = [] # 空のリスト  # appendメソッドで追加  
Ccards = [] # 空のリスト  # appendメソッドで追加  
Dcards = [] # 空のリスト  # appendメソッドで追加  

for i in range(n):
    s,r = input().split() # n組の有るカード
    r = int(r)
    if s == 'S':
        Scards.append(r)
    elif s == 'H':
        Hcards.append(r)
    elif s == 'C':
        Ccards.append(r)
    elif s == 'D':
        Dcards.append(r)

for i in range(1,14):
    if not (i in Scards):
        print('S', i)
for i in range(1,14):
    if not (i in Hcards):
        print('H', i)
for i in range(1,14):
    if not (i in Ccards):
        print('C', i)
for i in range(1,14):
    if not (i in Dcards):
        print('D', i)


Measured memory_bytes: 5612
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = (int)1e9;

int main(void){
    int r;
    cin >> r;

    cout << 3 * r * r << '\n';

    return 0;
}

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

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<bool> VB;
typedef vector<double> VD;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define LB lower_bound
#define UB upper_bound

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL INF = 1000000000;
const LL MOD = 1000000007;

//other
//-------------------------------------------
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define FI first
#define SE second

int main() {
  int A, B, x, y, z, ans;
  cin >> A >> B;
  x = A+B;
  y = A-B;
  z = A*B;
  ans = max(x,max(y,z));
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin>>N;
    vector<int>a(N);
    for(int i=0;i<N;i++){cin>>a[i];}
    int flag;
    int count=0;
    int k;
 // N 個の要素を含む 0-オリジンの配列 A
   flag = 1; // 逆の隣接要素が存在する
   while (flag){flag = 0;
     for (int j=N-1;j>= 1;j--){
       if( a[j] < a[j-1]){
         k=a[j];
         a[j]=a[j-1];
         a[j-1]=k;
         //A[j] と A[j-1] を交換
         flag = 1;
         count++;
           
       }
         
     }
         
     }
    for(int i=0;i<N;i++){
        if(i!=0)cout<<" ";
        cout<<a[i];
    }cout<<endl;
    cout<<count<<endl;
    
    
    return 0;
    
}


Measured memory_bytes: 3100
#!/usr/bin/env python3
from itertools import*
n = int(input())
c = 0
k = "357"

for i in range(3, -~len(str(n))):
    for j in product(k, repeat = i):
        if all(j.count(h) for h in k):
            if int("".join(j)) <= n:
                c += 1
print(c)

Measured memory_bytes: 3060
import java.io.*;
 
class Main {
    public static void main(String args[]) {
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	try {
	    int n = Integer.parseInt(br.readLine());
	    long f = 1;
	    for (int i=2;i<=n;i++) {
		f *= (long)i;
	    }
	    System.out.println(f);
	} catch (Exception e) {
	    e.printStackTrace();
	}
    }
}

Measured memory_bytes: 16860
#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 _GLIBCXX_DEBUG

template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

int n, ans=0;

int main(){
    cin >> n;
    rep2(k, 1, n+1){
        int cnt = 1;
        rep2(i, 1, n/2+1){
            if(k % i == 0) cnt++;
        }
        if(cnt == 8 && k % 2 != 0){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
	int n;
	cin >> n;
	map<int, int>mp = {};
	for (int i = 0;i < n;i++) {
		int a;
		cin >> a;
		mp[a]++;
	}
	int max = 0, x;
	for (int i = 1;i < 100000;i++) {
		x = mp[i - 1] + mp[i] + mp[i + 1];
		if (x > max)max = x;
	}
	cout << max << endl;
}

Measured memory_bytes: 4992