akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(0)
#define loop(i, a, b) for(lli i=a; i<b; i++)
#define loopb(i, a, b) for(lli i=a; i>=b; i--)
#define pb push_back
#define umap unordered_map
typedef long long int lli;
typedef pair<lli, lli> pii;
typedef vector<lli> vll;
typedef pair<lli, pii> ppi;
typedef tree<lli, null_type, less<lli>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// use to avoid collision
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
// for pair in unordered_map
struct hash_pair {
    static uint64_t splitmix64(uint64_t x) {
    // http://xorshift.di.unimi.it/splitmix64.c
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
    }
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const{
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        uint64_t x = hash1 ^ hash2;
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
lli M = 1e9 + 7;
lli power(lli x, lli y){
    lli res = 1;
    x = x%M ;
    while (y > 0) {
        if (y & 1)
            res = (res*x)%M ;
        y = y>>1;
        x = (x*x)%M;
    }
    return res%M;
}
lli solve(){
    lli n;
    cin>>n;
    vll A(n);
    loop(i, 0, n)
        cin>>A[i];
    lli ans = 0;
    lli j = 1;
    loop(i, 0, n){
        if(A[i] == j)
            j++;
        else
            ans++;
    }
    if(ans == n)
        ans = -1;
    cout<<ans<<"\n";
    return 0;
}
int main(){
    fastio;
    lli t;
    // cin>>t;
    t = 1;
    while(t>0){
        t--;
        solve();
    }
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <fstream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>

using namespace std;
typedef long long ll;

int N;
ll A[100100], B[100100];

int main()
{
    ios_base::sync_with_stdio(0);
    
    cin >> N;
    for (int i = 0; i <= N; i++)
        cin >> A[i];
    for (int i = 0; i < N; i++)
        cin >> B[i];

    ll ans = 0;
    for (int i = 0; i < N; i++)
    {
        if (B[i] <= A[i])
        {
            ans += B[i];
            A[i] -= B[i];
        }
        else
        {
            ans += A[i];
            B[i] -= A[i];
            A[i] = 0;
            ans += min(B[i], A[i+1]);
            A[i+1] -= min (B[i], A[i+1]);
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 1792
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define pb            push_back
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())

const int INF = 1e9;


// code
// ------------------------------------------------
int main() {
  int n,b;

  cin >> n;

  int min = INF;
  for(int a = 1; a <= n / 2; a++)
  {
    b = n - a;
    int buf = CalcSumOfDigit(a) + CalcSumOfDigit(b);
    if(buf < min)
      min = buf;
  }

  cout << min << endl;
  return 0;
}

// funcの実体
// ------------------------------------------------
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

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

int main(void)
{
	long long int i,j,n,k;
  scanf("%lld%lld",&n,&k);

	i=n%k;
	if(k-i<0){
		if(i-k>i)
			printf("%lld",i);
		else
			printf("%lld",i-k);
		}
	else{
		if(k-i>i)
			printf("%lld",i);
		else
			printf("%lld",k-i);
	}

	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int MAX = 1e5 + 10;

int main()
{
	ll n,k,i; cin>>n>>k;
	ll a[MAX];
	for(i=0;i<n;i++) cin>>a[i];	
	i=0;
	while(a[i]<0) i++;

	ll c=i;
	ll j=i+k-1;

	ll mn = INT_MAX;

	while(true){
	    
		if(i<0) break;
		if(j == c-1){
			mn = min(abs(a[i]),mn);
			break;
		}
		if(j<=n-1){
			if(i==c){
				mn = min(mn,abs(a[j]));
			}
			else{
				ll d = min(abs(a[i]),abs(a[j]));
				ll m = max(abs(a[i]),abs(a[j]));
				mn = min(mn,2*d+m);
			}
		}
		//cout<<i<<" "<<j<<" "<<mn<<endl;
		i--; j--;
	}

	cout<<mn<<endl;

}


Measured memory_bytes: 1024
import math

def agcd(l):
    a=math.gcd(l[0],l[1])
    for i in range(2,len(l)):
        a=math.gcd(a,l[i])
    return a

N,X=map(int,input().split())
x=[abs(i-X) for i in list(map(int,input().split()))]

print(agcd(x)if 1<N else x[0])

Measured memory_bytes: 20376
#include <bits/stdc++.h>                                           
 
#define int long long
//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
 
 
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define forev(i, b, a) for(int i = (b); i >= (a); --i)
#define forn(i, a, b) for(int i = (a); i <= (b); ++i)
#define all(x) x.begin(), x.end()
#define sz(s) (int)s.size()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define s second
#define f first
 
 
using namespace std;
 
 
typedef pair < long long, long long > pll;    
typedef pair < int, int > pii;
typedef unsigned long long ull;         
typedef vector < pii > vpii;
typedef vector < int > vi;
typedef long double ldb;  
typedef long long ll;  
typedef double db;                             
 
 
const int inf = 1e9, maxn = 4e5 + 148, mod = 95542721, N = 1e5 + 33;
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 555;
const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);
const db eps = 1e-12, pi = 3.14159265359;
const ll INF = 1e18;
 
 
int n, m, q, a, b, c, p[N];
vpii v;

int get (int v) {
	return p[v] == v ? v : p[v] = get(p[v]);
}

void merge (int v, int u) {
	v = get(v), u = get(u);
	if (v == u)
		return;

	if (rand() & 1)	
		swap(v, u);

	p[u] = v;
}

main () {
	fastio
	cin >> n >> m >> q;
	for (int i = 1; i <= n; ++i)
		p[i] = i;

	for (int i = 1; i <= q; ++i)  {
		cin >> a >> b >> c;
		++a, ++b;
		if (!c)
			merge(a, b);
		else
			v.pb({a, b});		
	}

	if (m == n - 1) {
		puts(sz(v) ? "No" : "Yes");
		return 0;
	}

	for (auto x : v)
		if (get(x.f) == get(x.s)) {
			puts("No");
			return 0;
		}
	
	int k = 0;
	for (int i = 1; i <= n; ++i)
		if (p[i] == i)	
			++k;
	int M = n + k*(k - 3) / 2;
	puts((m <= M) ? "Yes" : "No");		
}
 


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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

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

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }


void func(long long N){

}

int main(){
    int n;
    cin >> n;
    vs s = { "pon", "pon", "hon", "bon", "hon", "hon", "pon", "hon", "pon", "hon" };
    cout << s[n%10] << endl;
    return 0;
}


Measured memory_bytes: 3640
#include<iostream>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
/*---------------------DEBUGGING--------------------------------------------*/
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
/*-------------------------------------------------------------------------------------*/
#define mp make_pair
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define pcc pair<char,char>
#define F first
#define S second
#define int long long
#define pi 3.141592653589793238462643383279502
#define M  1000000007
#define rep(i,a,n) for(int i=a;i<n;i++)
#define N 300005
#define vi vector<int>
#define all(v) v.begin(),v.end()

signed main()
{
   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   string s;
   cin>>s;
   map<int,int>m;
   for(int i=0;i<4;i++)
   {
       m[s[i]-'A']++;
   }
   int flag=0;
   for(auto it=m.begin();it!=m.end();it++)
   {
       if(it->S!=2)flag=1;
   }
   if(!flag)cout<<"Yes"<<endl;
   else
    cout<<"No"<<endl;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import java.text.*;

public class Main {
	public static void main(String[] args) {
		gridColoring();
	}
	
	public static void sieve(int max) {		
		boolean[] isComposite = new boolean[max+1];
		for(int i=2; i<=max; i++) 
			if(!isComposite[i])
				for(int j=i*i; j<=max; j+=i)
					isComposite[j]=true;
					
		for(int i=2; i<=max; i++) if(!isComposite[i]) System.out.println(i + " ");
	}
	
	public static void gridColoring() {
		Reader reader = new Reader();
		int height = reader.nextInt();
		int width = reader.nextInt();
		
		int num = reader.nextInt();		
		int[] colorNums = new int[num];
		for(int j = 0; j < num; j++) colorNums[j] = reader.nextInt();
		
		int[][] solution = new int[height][width];
		int r = 0, c = 0, color = 1;
		for(int j = 0; j < height*width; j++) {
			r = j/width;
			c = (r%2 == 0)? j - j/width*width : width - (j - j/width*width) - 1;
			
			if(colorNums[color - 1] <= 0) color++;
			solution[r][c] = color;
			colorNums[color - 1]--;
		}
		
		for(int j = 0; j < height; j++) {
			for(int k = 0; k < width; k++) System.out.print(solution[j][k] + " ");
			System.out.println();
		}
	}
	
	public static void simArrays() {
		Reader reader = new Reader();
		
		int n = reader.nextInt();
		int res = 1;
		res = exponential(3, n);
		
		int[] arr = new int[n];
		for(int j = 0; j < n; j++) arr[j] = reader.nextInt();
		
		int oddWays = 1;
		for(int j = 0; j < n; j++) if(arr[j] % 2 == 0) oddWays *= 2;
		
		System.out.println(res - oddWays);
	}
	
	public static int exponential(int base, int exp) {
		if(exp == 0) return 1;
		else if(exp % 2 == 0) return exponential((base*base), exp/2);
		return base*exponential((base*base), exp/2); //integer cutoff means (exp - 1)/2 unnecessary
	}
}

class Reader {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st;
    String next() {
        while(st==null||!st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch(Exception e) {}
        }
        return st.nextToken();
    }
	
    int nextInt() {
        return Integer.parseInt(next());
    }
}

Measured memory_bytes: 26068
#include<bits/stdc++.h>
#define pb push_back
#define F first
#define S second
using ll = long long;
#define ull unsigned ll
#define endl "\n"
#define vi vector<int>
#define vl vector<ll>
#define all(v) (v).begin(),(v).end()
#define mst(a,b) memset(a,b,sizeof(a))
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ppi pair<int, pii>
#define mt make_tuple
#define eb emplace_back
#define pcii pair<char, pair<int, int>>
using namespace std;

const ll N = 105, mod = 1e9 + 7;
const int inf = 1e9;

void solve(){
    int n;
    cin >> n;
    vi a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    vector<int> dp(n);
    dp[0] = 0;
    dp[1] = abs(a[1] - a[0]);
    for(int i = 2; i < n; i++){
        dp[i] = min(dp[i - 1] + abs(a[i] - a[i - 1]), dp[i - 2] + abs(a[i] - a[i - 2]));
    }
    cout << dp[n - 1] << endl;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    ll t,p;
    t=1;
    //cin>>t;
    for(p=1;p<=t;p++){
        solve();
    }
    return 0;
}


Measured memory_bytes: 3924
#include <iostream>
using namespace std;
int main() {
    int N;
    cin >> N;
    int d[N];
    for (int i=0; i<N; i++) cin >> d[i];
    int n=0;
    for (int i=0; i<N; i++) {
        int m = d[i];
        for (int j=i+1; j<N; j++) {
            n += m * d[j];
        }
    }
    cout << n << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
typedef long long ll;
const int N=66666;
int jc[N],inv[N],n,m,ans,Max,num,dp[20][N],a[N];
void up(int &x,int y) {x=((ll)x+y)%mod;}
int calc(int x){int res=0;while (x) x-=(x&(-x)),res++;return res;}
void init()
{  
  jc[0]=jc[1]=inv[0]=inv[1]=1;
  for (int i=2;i<Max;i++) jc[i]=(ll)jc[i-1]*i%mod,inv[i]=(ll)(mod-mod/i)*inv[mod%i]%mod;
  for (int i=2;i<Max;i++) inv[i]=(ll)inv[i]*inv[i-1]%mod;
}
int C(int n,int m)
{
  if (n<m) return 0;
  return (ll)jc[n]*inv[m]%mod*inv[n-m]%mod;
}
int main()
{
  scanf("%d%d",&n,&m);
  for (int i=1;i<=m;i++) scanf("%d",&a[m-i+1]);//从大到小
  Max=1<<n;init();
  dp[0][0]=1;
  for (int i=1;i<=m;i++)
    for (int j=0;j<Max;j++)
    if (dp[i-1][j])
    {
      up(dp[i][j],dp[i-1][j]);
      num=calc(j);
      for (int k=0;k<n;k++)
        if (!(j&(1<<k)))
          up(dp[i][j|(1<<k)],(ll)C(Max-a[i]-j,(1<<k)-1)*jc[1<<k]%mod*dp[i-1][j]%mod);
    }
  for (int i=0;i<Max;i++) 
  {
    num=calc(i);
    if (num&1) up(ans,(mod-(ll)dp[m][i]*jc[Max-i-1]%mod)%mod);
    else up(ans,(ll)dp[m][i]*jc[Max-i-1]%mod);
  }
  printf("%lld\n",(ll)ans*Max%mod);
  return 0;
}

Measured memory_bytes: 4352
/*
            _ _  ___            __ _ _  _       _     
 _   _  ___| | |/ _ \__      __/ _| | || |  ___| |__  
| | | |/ _ \ | | | | \ \ /\ / / |_| | || |_/ __| '_ \ 
| |_| |  __/ | | |_| |\ V  V /|  _| |__   _\__ \ | | |
 \__, |\___|_|_|\___/  \_/\_/ |_| |_|  |_| |___/_| |_|
 |___/                 

 */

#include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define int long long
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
#define MOD 1000000007
#define INF 1000000000000000007
#define MAXN 300005


signed main(){
	fast
	int n, temp;
	cin>>n;
	vector<int> v;
	For(i, 0, n){
		cin>>temp;
		v.pb(temp);
	}

	vector<int> left(n, 0);
	vector<int> right(n, 0);

	For(i, 0 , n-1){
		left[i+1] = __gcd(left[i], v[i]);
	}
	for(int i=n-1; i>0; i--){
		right[i-1] = __gcd(right[i], v[i]);
	}

	// For(i, 0, n){
	// 	cout<<left[i]<<" ";
	// }
	// cout<<endl;

	// For(i, 0, n){
	// 	cout<<right[i]<<" ";
	// }
	// cout<<endl;

	int gcd_max = 0;
	For(i, 0, n){
		gcd_max = max(__gcd(left[i], right[i]), gcd_max);
	}

	cout<<gcd_max<<endl;
    return 0;
}
    



Measured memory_bytes: 2804
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb(in,tmp) in.push_back(tmp)
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
using namespace std;
int main(){
  int a[31]={1,1,2};
  int n;
  loop(i,3,31)a[i]=a[i-1]+a[i-2]+a[i-3];
  while(cin>>n,n)cout<<(a[n]-1)/365/10+1<<endl;

}

Measured memory_bytes: 1160
/*
ID: alec3
LANG: C++14
PROG:
*/


#include <bits/stdc++.h>

#define check(x) cout<<(#x)<<": "<<x<<" ";
#define io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ss second
#define ff first
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define ld long double
#define all(c) (c).begin(), (c).end()
#define FOR(i, a, b) for (int i = a; i < b; i++)

typedef long long ll;
typedef unsigned long long ull;

using namespace std;
unsigned nChoosek( unsigned n, unsigned k )
{
    if (k > n) return 0;
    if (k * 2 > n) k = n-k;
    if (k == 0) return 1;

    int result = n;
    for( int i = 2; i <= k; ++i ) {
        result *= (n-i+1);
        result /= i;
    }
    return result;
}

int main()
{
    io;
    ll x, k , d;
    cin >> x >> k >> d;

    if (x > 0){
        ll c = x/d;
        if (c > k){
            x -= (k * d);
            cout << x << endl;
            return 0;
        }
        else {
            x -= (d * c);
           // cout << c << endl;
            k -= c;
            //cout << "HERE" << " " << x << " " << c << endl;
            if (k % 2 == 0)
                cout << abs(x) << endl;
            else {
                x -= d;
                k --;
               // cout << "k is " << k << endl;
                //cout << "x is " << x << endl;
                if (k == 0)
                    cout << abs(x) << endl;
                else {
                    cout << abs(x) << endl;
                }
            }
        }
    }
    else {
        ll c = abs(x/d);
        if (c > k){
            x += (k * d);
            cout << abs(x) << endl;
            return 0;
        }
        else {
            x += (d * c);
            k -= c;
            if (k %2 == 0){
                cout << abs(x) << endl;
            }
            else {
                x += d;
                k --;
                if (k == 0)
                    cout << abs(x) << endl;
                else {
                    cout << abs(x) << endl;
                }
            }
        }
    }


    //cout << abs() << endl;

    return 0;

}



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

int main(){
    string s;
    cin >> s;
    int zerostrt = 0;
    int onestrt = 0;
    char a[] = {'0','1'};
    for(int i = 0;i < s.size();i++){
        if(s[i] == a[i % 2]){
            zerostrt++;
        }else{
            onestrt++;
        }
    }
    cout << min(zerostrt,onestrt);
    return 0;
}

Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

/*
 <url:>
 問題文============================================================
 
 =================================================================
 
 解説=============================================================
 座標圧縮＋二次元imos
 ================================================================
 */

/* Coordinate_Compression : 座標圧縮*/
class CC {
public:
    ll N;
    vector<ll> xs; // 復元用:xs[x1 or x2の添え字] := 元の座標
    
    CC(ll N) :N(N) {}
    // x1, x2を座標圧縮し, 座標圧縮した際の幅を返す
    int compress(vector<ll>& x1, vector<ll>& x2, ll MIN_W = -1e10, ll MAX_W = 1e10) {
        for (int i = 0; i < N;i++) {
            ll tx1 = x1[i], tx2 = x2[i];
            if (MIN_W <= tx1 && tx1 <= MAX_W) xs.push_back(tx1);
            if (MIN_W <= tx2 && tx2 <= MAX_W) xs.push_back(tx2);
        }
        
        sort(xs.begin(), xs.end());
        xs.erase(unique(xs.begin(), xs.end()), xs.end());
        
        for (int i = 0; i < N;i++) {
            x1[i] = find(xs.begin(), xs.end(), x1[i]) - xs.begin();
            x2[i] = find(xs.begin(), xs.end(), x2[i]) - xs.begin();
        }
        
        return (int)xs.size(); // xs.sizeは最大でも6*N
    }
};

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

void dfs(int y,int x,vector<vector<int>>& masu,int H,int W){
    masu[y][x] = 1;
    for(int i = 0; i < 4;i++){
        int ny = y + dy[i], nx = x + dx[i];
        if(ny >= 0 && ny < H && nx >= 0 && nx < W && masu[ny][nx] == 0) dfs(ny,nx,masu,H,W);
    }
}

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    ll w,h;
    while(cin >> w >> h){
        if(w == 0 && h == 0) break;
        
        ll N; cin >> N;
        vector<ll> x1(N+1), y1(N+1), x2(N+1), y2(N+1);
        x1[N] = 0; y1[N] = 0; x2[N] = w; y2[N] = h;
        for (int i = 0; i < N;i++) cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
        CC CCx(N+1), CCy(N+1);
        ll W = CCx.compress(x1, x2, 0, w);
        ll H = CCy.compress(y1, y2, 0, h);
        
        vector<vector<int>> masu(H-1,vector<int>(W-1,0));
        for(int i = 0; i < N;i++){
            for(int j = x1[i]; j < x2[i];j++){
                for(int k = y1[i]; k < y2[i];k++){
                    masu[k][j] = 1;
                }
            }
        }
        
        // visualize
        /*
        for(int i = 0; i < H-1;i++){
            for(int j = 0; j < W-1;j++){
                cout << masu[i][j] << " " ;
            }
            cout << endl;
         }
         */
        
        ll ans = 0;
        for(int i = 0; i < H -1;i++){
            for(int j = 0; j < W-1;j++){
                if(masu[i][j] == 1)continue;
                dfs(i,j,masu,H-1,W-1);
                ans++;
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 8324
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,v[100010];
    int ans=0;
    cin>>n;
    for(int i=0;i<n;i++) cin>>v[i];
    int a[100010]={},b[100010]={};
    for(int i=0;i<n;i++){
        if(i%2==0) a[v[i]]++;
        else b[v[i]]++;
    }
    int a1,a2,b1,b2,A1=0,A2=0,B1=0,B2=0;
    for(int i=0;i<100010;i++){
        if(a[i]>A1){
            a1=i;
            A1=a[i];
        }
    }
    for(int i=0;i<100010;i++){
        if(b[i]>B1){
            b1=i;
            B1=b[i];
        }
    }
    a[a1]=0;
    b[b1]=0;
    for(int i=0;i<100010;i++){
        if(a[i]>A2){
            a2=i;
            A2=a[i];
        }
    }
    for(int i=0;i<100010;i++){
        if(b[i]>B2){
            b2=i;
            B2=b[i];
        }
    }
    if(a1!=b1){
        ans=n-A1-B1;
    }
    else{
        if(A1+B2>A2+B1){
            ans=n-A1-B2;
        }
        else{
            ans=n-A2-B1;
        }
    }
    cout<<ans;
}


Measured memory_bytes: 1408
#define M 100
char m[M][M],s[M][M][M],r[M],*z;
cmp(char *p,char *q){int r=0;
	for(;*p=='0';p++);for(;*q=='0';q++);
	return (z=strlen(p)-strlen(q))?z:strcmp(p,q);
}
main(w,h,i,j,k,l){
	for(;scanf("%d%d",&w,&h),w;puts(z)){
		for(memset(s,0,sizeof(s)),memset(r,0,sizeof(r)),j=1;j<=h;j++)scanf("%s",m[j]+1);
		for(i=1;i<=w;i++)for(j=1;j<=h;j++){
			if(!isdigit(m[j][i]))continue;
			if(cmp(s[j][i-1],s[j-1][i])>0)strcpy(s[j][i],s[j][i-1]),s[j][i][strlen(s[j][i])]=m[j][i];
			else strcpy(s[j][i],s[j-1][i]),s[j][i][strlen(s[j][i])]=m[j][i];
			if(cmp(s[j][i],r)>0)strcpy(r,s[j][i]);
		}
		for(z=r;*z=='0';z++);
	}
return 0;}

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

int main(){
  
	int count,dig;
  	int outcounter=0;
  	cin>>count;
	for(int i=0;i<count;++i){
		cin>>dig;
      if(dig%2==1){
        //奇数はスルー
      }else if(dig%6==0||dig%10==0){
        //条件を満たすためスルー
      }else{
        // 条件を満たさない偶数なため、outcountを一つ載せる
        outcounter++;
      }
    }
  if(outcounter>=1){
    cout<<"DENIED"<<endl;
  }else{
    cout<<"APPROVED"<<endl;
  }
  
 return 0; 
}
  

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

using namespace std;

int main () {
  ios::sync_with_stdio(false); cin.tie(0);
 string text; cin>>text;
  set<char> ans;
  for(int i=0;text[i];i++) ans.insert(text[i]);
  if(ans.size()==2) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


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

void solve()
{
    string s;
    cin >> s;

    int x = 0;
    for(auto c : s)
    {
        if(c == 'x')
            x++;
    }

    if (x > 7)
        cout << "NO" << endl;
    else
        cout << "YES" << endl;
        
}

int main()
{
    cin.sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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

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

int main() {
  int N, M, Q;
  cin >> N >> M >> Q;

  vector<vector<int>> LR(N, vector<int>(N));

  vector<int> L(M), R(M);
  rep(i, M) {
    cin >> L[i] >> R[i];
    L[i]--;
    R[i]--;
    LR[L[i]][R[i]]++;
  }
  vector<int> p(Q), q(Q);
  rep(i, Q) {
    cin >> p[i] >> q[i];
    p[i]--;
    q[i]--;
  }

  vector<vector<int>> sum(N, vector<int>(N));
  rep(i, N) {
    rep(j, N) {
      sum[i][j] = LR[i][j];
      if (i > 0)
        sum[i][j] += sum[i - 1][j];
      if (j > 0)
        sum[i][j] += sum[i][j - 1];
      if (i > 0 && j > 0)
        sum[i][j] -= sum[i - 1][j - 1];
    }
  }

  rep(i, Q) {
    int ans = sum[q[i]][q[i]];
    if (p[i] > 0) {
      ans -= sum[p[i] - 1][q[i]];
      ans -= sum[q[i]][p[i] - 1];
      ans += sum[p[i] - 1][p[i] - 1];
    }
    cout << ans << endl;
  }
}

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

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

typedef vector<int> vint;
typedef long long ll;

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

  int x, n;
  cin >> x >> n;
  vint p(n);
  for (auto &ref : p) {
    cin >> ref;
  }
  int expect = x;
  int pv = 1;
  int mv = 1;
  int turn = 1;
  sort(all(p));
  while (true) {
    if (!(binary_search(all(p), expect))) {
      cout << expect << endl;
      return 0;
    }
    if (turn == 0) {
      turn = 1;
      expect = x + pv;
      pv++;
    } else {
      turn = 0;
      expect = x - mv;
      mv++;
    }
  }
}


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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

# define MAXN 21

// dp[s]:左からbitcount(s)人の男とペアを組ませる、女性のピックがSの時のパターン数
ll dp[1<<(MAXN+1)];
int a[MAXN+1][MAXN+1];

int main(){
  int n;cin>>n;
  rep(i, n)rep(j, n)cin>>a[i][j];

  dp[0]=1;
  rep1(s, (1<<n)-1)rep(l, n){
    if((s>>l)%2==0)continue;

    int g = __builtin_popcount(s);
    int pre_s = s - (1<<l);
    if( a[g-1][l] ){
      dp[s] += dp[pre_s];
      dp[s] %= MOD;
    }
//cout<<g<<' '<<l<<' '<<s<<endl;
  }

  cout<<dp[(1<<n)-1]<<endl;

  return 0;
}

Measured memory_bytes: 19904
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define clr(a,x) memset(a,x,sizeof(a))
#define lson rt<<1
#define rson rt<<1|1
#define pb push_back
#define fi first
#define se second
#define what_is(x) cerr<<#x<<" "<<x<<endl;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
/*********head**********/

int main(){
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    if(a>b)swap(a,b);
    if(a<c&&c<b){
        puts("Yes");
    }else{
        puts("No");
    }
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"strconv"
	"bufio"
	"os"
	"strings"
	"fmt"
)

/*
 <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_2_D>
 */

func init() {

}

func main() {
	in, _ := SplitIntStdin(" ")
	W := in[0]
	H := in[1]
	x := in[2]
	y := in[3]
	r := in[4]
	
	if x - r >= 0 && x + r <= W && y - r >= 0 && y + r <= H{
		fmt.Println("Yes")
	}else{
		fmt.Println("No")
	}
}

// ????????????1?????????
func StrStdin() (stringReturned string) {
	scanner := bufio.NewScanner(os.Stdin)

	scanner.Scan()
	stringInput := scanner.Text()

	stringReturned = strings.TrimSpace(stringInput)
	return
}

// ??´??°???1?????????
func IntStdin() (int, error) {
	stringInput := StrStdin()
	return strconv.Atoi(strings.TrimSpace(stringInput))
}

// ?????????????????????????????????????????????Split()
func SplitWithoutEmpty(stringTargeted string, delim string) (stringReturned []string) {
	stringSplited := strings.Split(stringTargeted, delim)

	for _, str := range stringSplited {
		if str != "" {
			stringReturned = append(stringReturned, str)
		}
	}

	return
}

// ??????????????§??????????????????????????????????????????
func SplitStrStdin(delim string) (stringReturned []string) {
	// ???????????§1?????????
	stringInput := StrStdin()

	// ????????§??????
	// stringSplited := strings.Split(stringInput, delim)
	stringReturned = SplitWithoutEmpty(stringInput, delim)

	return
}

// ??????????????§??????????????´??°????????????????????????
func SplitIntStdin(delim string) (intSlices []int, err error) {
	// ??????????????????????????????
	stringSplited := SplitStrStdin(" ")

	// ??´??°?????????????????????
	for i := range stringSplited {
		var iparam int
		iparam, err = strconv.Atoi(stringSplited[i])
		if err != nil {
			return
		}
		intSlices = append(intSlices, iparam)
	}
	return
}

Measured memory_bytes: 1140
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
  ll X,Y,A,B,C;
  cin>>X>>Y>>A>>B>>C;
  vector<ll> p(A);
  for(ll i=0;i<A;i++) {
cin>>p[i];
  }
  vector<ll> q(B);
  for(ll i=0;i<B;i++) {
cin>>q[i];
      
  }
  
  vector<ll> r(C);
  for(ll i=0;i<C;i++) {
cin>>r[i];
  }
  
  vector<ll> vec(0);
  sort(all(p));
  sort(all(q));
  sort(all(r));
  
  
  for(ll i=0;i<X;i++) {
vec.push_back(p[A-1-i]);
  }
  for(ll i=0;i<Y;i++) {
vec.push_back(q[B-1-i]);
  }
  
  for(ll i=0;i<X+Y;i++) {
    vec.push_back(r[C-1-i]);
    if(C-1-i==0) {
break;
    }
  }
  
  sort(all(vec));
  reverse(all(vec));
  ll ans=0;
  for(ll i=0;i<X+Y;i++) {
ans+=vec[i];
  }
  
  
  cout<<ans<<endl;
}
  
  
  

  

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

constexpr int kInf = 1000 * 1000 * 1000 + 7;

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

  int n;
  cin >> n;

  vector<int> a(n);
  for (int& e: a)
    cin >> e;

  vector<vector<int>> g(n);
  for (int i = 0; i < n - 1; ++i) {
    int x, y;
    cin >> x >> y;
    --x; --y;
    g[x].push_back(y);
    g[y].push_back(x);
  }

  vector<int> lis_length(n);
  vector<int> dp(n + 1, kInf);
  dp[0] = 0;
  dp[1] = a[0];
  function<void(int, int)> dfs = [&](int v, int p) {
    lis_length[v] = lower_bound(dp.begin(), dp.end(), kInf) - dp.begin() - 1;
    for (int to: g[v]) {
      if (to == p) continue;
      int position = lower_bound(dp.begin(), dp.end(), a[to]) - dp.begin();
      int value = dp[position];
      dp[position] = a[to];
      dfs(to, v);
      dp[position] = value;
    }
  };

  dfs(0, -1);
  for (int length: lis_length)
    cout << length << '\n';
}

Measured memory_bytes: 33628
#include<stdio.h>
int main(){
  char s[3];
  int add=0, i, j, t;

  scanf("%s", &s);

  for(i=0;i<3;i++){
    if(s[i]=='o'){
      add++;
    }
  }
  t=700+100*add;
  printf("%d\n", t);

  return 0;
}

Measured memory_bytes: 128
N = int(input())
S = [s for s in input()]
ans = S.count("R") * S.count("G") * S.count("B")

for i in range(N - 2):
    for j in range(i + 1, N - 1):
        k = j + (j - i)
        if N - 1 < k:
            continue
        if S[k] != S[i] and S[k] != S[j] and S[i] != S[j]:
            ans -= 1

print(ans)


Measured memory_bytes: 68460
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  k=I()
  return 'ACL'*k

# main()
print(main())


Measured memory_bytes: 10644
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func mapToString(a []int) []string {
	len := len(a)
	r := make([]string, len)
	for i := 0; i < len; i++ {
		r[i] = strconv.Itoa(a[i])
	}
	return r
}

func printIntList(args []int) {
	strA := mapToString(args)
	fmt.Println(strings.Join(strA, " "))
}

func main() {
	sc.Split(bufio.ScanWords)
	N := nextInt()
	cnt := 0
	for i := 1; i <= N; i++ {
		s := strconv.Itoa(i)
		len := len(s)
		if len%2 == 1 {
			// fmt.Println("abc:", i)
			cnt++
		}
	}
	fmt.Println(cnt)
}


Measured memory_bytes: 1152
#include <stdio.h>
#include <vector>
#include <string>
#include <iostream>

using std::string;

char toggle(const char c){
    const int dif = 'A' - 'a';
    if ('a' <= c && c <= 'z') {
        return c + dif;
    }
    if ('A' <= c && c <= 'Z') {
        return c - dif;
    }
    return c;
}

int main(){
    string buffer;
    getline(std::cin, buffer);
    for(auto each: buffer) {
        printf("%c", toggle(each));
    }
    printf("\n");
}


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

using namespace std;

namespace {

    template<class T> ostream& operator<<(ostream& os, const vector<T>& vs) {
        if (vs.empty()) return os << "[]";
        os << "[" << vs[0];
        for (int i = 1; i < vs.size(); i++) os << " " << vs[i];
        return os << "]";
    }

    int N;
    vector< vector<int> > V;
    vector<string> M;
    void input() {
        cin >> N;
        M.clear(); M.resize(N + 1);
        V.clear(); V.resize(N + 1);
        for (int i = 1; i <= N; i++) {
            int k; string m;
            cin >> k >> m;
            V[k].push_back(i);
            M[i] = m;
        }
    }

    void print(int n, int level) {
        for (int i = 0; i < level; i++) cout << '.';
        cout << M[n] << endl;
        for (int i = 0; i < V[n].size(); i++) {
            int next = V[n][i];
            print(next, level + 1);
        }
    }

    void solve() {
        print(1, 0);
    }
}

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

Measured memory_bytes: 3384
#include<iostream>
#include<iomanip>

#include<vector>
#include<queue>
#include<set>
#include<map>
#include<string>

#include<algorithm>
#include<cmath>

using namespace std;
typedef long long ll;
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 int INF = 1e9;

// i をp で割った余りを最大化する...
//　iが理想　すなわちi+1以上の数で割るのが良い
//Nは余りがどうしても小さくなる
//たとえば
/*
1 を 2で割る
2 を　3で割る
...
Nを1で割る

にすると
1 + ... + N-1
= N(N-1)/2になる


*/

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

    cout << N * (N-1) / 2 << endl;
}


Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
    tmp0 = input[0].split(" ");
    var a = parseInt(tmp0[0], 10);
    var b = parseInt(tmp0[1], 10);
    var c = parseInt(tmp0[2], 10);

    if (a==b){if(a==c){console.log('No');}else{console.log('Yes');}}
       else if(b==c){console.log('Yes');}
               else if(a==c){console.log('Yes');}else{console.log('No');}
 
                }
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws FileNotFoundException {

		//    	File file = new File("src/in.txt");
		//    	Scanner sc = new Scanner(file);

		Scanner sc = new Scanner(System.in);

		long A = sc.nextLong();
		long B = sc.nextLong();
		long C = sc.nextLong();
		long D = sc.nextLong();

		long x = B/C-(A-1)/C;
		long y = B/D-(A-1)/D;
		long z = B/(lcm(C,D))-(A-1)/(lcm(C,D));
		System.out.println(B-A+1-x-y+z);
	}
	static long lcm (long a, long b) {
		long temp;
		long c = a;
		c *= b;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return c/b;
	}
}

Measured memory_bytes: 26808
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <bitset>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;
#define FOR(i,a,b)   for(ll i = (a); i < (b); i++ )
#define REP(i, n)    FOR(i,0,n)
typedef pair< ll, ll >   cp2;
typedef pair< string, cp2 >   cp3;
#define fi first
#define se second
#define sec  se.fi
#define thr  se.se
const ll mod = 1000000007;
//              123456789


///////////////////////////////////////////////
//
//
///////////////////////////////////////////////

////////////////////////////////////////////////
////////////////////////////////////////////////

int N;
string S[112345];
ll cnt[5];
ll ans = 0;

int main(){
    
    fill( cnt, cnt+5, 0 );
    
    cin>>N;
    REP( i, N ) cin>>S[i];
    
    REP( i, N ){
        if( S[i][0] == 'M' ){
            cnt[0]++;
        }
        if( S[i][0] == 'A' ){
            cnt[1]++;
        }
        if( S[i][0] == 'R' ){
            cnt[2]++;
        }
        if( S[i][0] == 'C' ){
            cnt[3]++;
        }
        if( S[i][0] == 'H' ){
            cnt[4]++;
        }
    }
    
    REP( i, 5 ){
        FOR( j, i+1, 5 ){
            FOR( k, j+1, 5 ){
                ans += cnt[i]*cnt[j]*cnt[k];
            }
        }
    }
    
    cout<<ans<<endl;
    
    return 0;
}


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

using ll = long long;

int f(int i) {
	if (i == 0) return 0;
	return f(i % __builtin_popcount(i)) + 1;
}

template< typename T >
T mod_pow(T x, T n, const T &p) {
  T ret = 1;
  while(n > 0) {
    if(n & 1) (ret *= x) %= p;
    (x *= x) %= p;
    n >>= 1;
  }
  return ret;
}


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

	int bc = 0;
	for (int i = 0; i < n; i++) bc += (x[i] == '1');

	if (bc == 0) {
		for (int i = 0; i < n; i++) cout << 1 << endl;
		return 0;
	}
	if (bc == 1) {
		int id; for (int i = 0; i < n; i++) if (x[i] == '1') id = i;
		for (int i = 0; i < n; i++) {
			if (i == id) cout << 0 << endl;
			else {
				ll mpid = mod_pow(2LL, (ll)(n-1-id), 2LL);
				ll mpi = mod_pow(2LL, (ll)(n-1-i), 2LL);
				cout << f((mpid + mpi) % 2) + 1 << endl;
			}
			
		}
		return 0;
	}

	

	ll sum1 = 0, sum2 = 0;
	for (int i = 0; i < n; i++) {
		sum1 = sum1 * 2 % (bc+1);
		sum1 = (sum1 + (x[i] - '0')) % (bc+1);
	}
	for (int i = 0; i < n; i++) {
		sum2 = sum2 * 2 % (bc-1);
		sum2 = (sum2 + (x[i] - '0')) % (bc-1);
	}

	for (int i = 0; i < n; i++) {
		if (x[i] == '1') {
			ll sum = sum2;
			ll mp = mod_pow(2LL, (ll)(n - 1 - i), (ll)(bc-1));
			sum = (sum - mp + (bc-1)) % (bc-1);
			cout << f(sum) + 1 << endl;
		}
		else {
			ll sum = sum1;
			ll mp = mod_pow(2LL, (ll)(n - 1 - i), (ll)(bc+1));
			sum = (sum + mp + (bc+1)) % (bc+1);
			cout << f(sum)  + 1 << endl;
		}
	}


	return 0;
}

Measured memory_bytes: 3752
def chk(n):
  chkMax = pow(n, 0.5)
  i = 2
  while i <= chkMax:
    if n % i == 0:
      return -1
    i += 1
  return 1
  
n = int(input())

while chk(n) == -1:
  n += 1

print(n)

Measured memory_bytes: 3060
import java.io.PrintWriter;
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int n = Integer.parseInt(sc.next());
        Map<Character, Integer> m = new HashMap<Character, Integer>();
        m.put('A', Integer.parseInt(sc.next()));
        m.put('B', Integer.parseInt(sc.next()));
        m.put('C', Integer.parseInt(sc.next()));
        String[] s = new String[n];
        for (int i = 0; i < n; i++) s[i] = sc.next();
        List<Character> r = new ArrayList<Character>();
        for (int i = 0; i < n - 1; i++) {
            char a = s[i].charAt(0);
            char b = s[i].charAt(1);
            if (m.get(a) == 0 || m.get(b) == 0) {
                if (m.get(a) == 0) {
                    m.put(a, m.get(a) + 1);
                    m.put(b, m.get(b) - 1);
                    r.add(a);
                }
                else {
                    m.put(a, m.get(a) - 1);
                    m.put(b, m.get(b) + 1);
                    r.add(b);
                }
            }
            else {
                if (s[i + 1].indexOf(a) > -1) {
                    m.put(a, m.get(a) + 1);
                    m.put(b, m.get(b) - 1);
                    r.add(a);
                }
                else{
                    m.put(a, m.get(a) - 1);
                    m.put(b, m.get(b) + 1);
                    r.add(b);
                }
            }
            for (Integer j : m.values()) {
                if (j < 0) {
                    out.println("No");
                    out.flush();
                    return;
                }
            }
        }
        char a = s[n - 1].charAt(0);
        char b = s[n - 1].charAt(1);
        if (m.get(a) == 0) {
            m.put(a, m.get(a) + 1);
            m.put(b, m.get(b) - 1);
            r.add(a);
        }
        else {
            m.put(a, m.get(a) - 1);
            m.put(b, m.get(b) + 1);
            r.add(b);
        }
        for (Integer i : m.values()) {
            if (i < 0) {
                out.println("No");
                out.flush();
                return;
            }
        }
        out.println("Yes");
        for (Character i : r) {
            out.println(i);
        }
        out.flush();
    }
}

Measured memory_bytes: 74480
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include <unordered_map>
//#include"testlib.h"
#define endl "\n"
#define all(v) v.begin(),v.end()
#define allr(s) s.rbegin(),s.rend()
#define RT(s) return cout<<s,0
#define watch(x) cout << (#x)<<" = "<<x<<endl
#define sz(s)    (int)(s.size())
#define PI acos(-1)
#define EPS 1e-8
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };
int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
void file() {
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
#else
	//freopen("street.in", "r", stdin);
	//freopen("out.txt", "w", stdout);
#endif
}
void fast() {
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
}
ll mx = 1e18;
bool overFlow(ll a, ll b) {
	return !(a <= mx / b);
}
int main() {
//	file();
	fast();
	int n; cin >> n;
	vector<ll> v1(n);
	for (auto& it : v1)
		cin >> it;
	if (count(all(v1), 0))
		RT(0 << endl);
	ll ans = 1;
	for (auto & x : v1) {
		cin >> x;
		if (overFlow(ans, x)) {
			RT(-1 << endl);
		}
		ans *= x;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3992
import sys
input = lambda: sys.stdin.readline().rstrip()

n, m = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(n)]
CD = [list(map(int, input().split())) for _ in range(m)]
#print(AB)
#print(CD)

for i in range(n):
    dist_list = []
    for j in range(m):
        dist = abs(AB[i][0] - CD[j][0]) + abs(AB[i][1] - CD[j][1])
        dist_list.append(dist)
    #print(dist_list)
    print(dist_list.index(min(dist_list))+1)

Measured memory_bytes: 9208
#include<bits/stdc++.h>
using namespace std;
#define intt long long int
#define intu unsigned long long int
#define vi vector<intt>
#define ii pair<int,int>
#define pb push_back
//#define mp make_pair
#define ff first
#define ss second
#define fast_io ios::sync_with_stdio(0);cin.tie(NULL);std::cout.tie(NULL);
# define PI           3.14159265358979323846 
#define all(a) a.begin(),a.end()
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define tc(t) int t; cin >> t; while (t--)
int mod = 1000000007;
intt gcd(intt a, intt b) {return b ? gcd(b, a % b) : a;}
int lcm(int a, int b) {return a * b / gcd(a, b); }
intt bpow(intt a,intt b) 
{
  intt res = 1;
  while (b > 0) {
    if (b & 1)res = res * a;
      a = a * a;
      b >>= 1;
  }
  return res;
}
intt fact(intt n) { 
   if ((n==0)||(n==1))
      return 1; 
   else
      return (n*fact(n-1))%mod;
}

void go()
{
#ifndef ONLINE_JUDGE
  freopen("IN.txt","r",stdin);
  freopen("OUT.txt","w",stdout);
  #endif
}



int main(){
	go();
	fast_io
  int n;cin>>n;
  vi a(n),b(n);
  for0(i,n){
    cin>>a[i];
  }
  for0(i,n){
    cin>>b[i];
  }
  reverse(all(b));
  int l=0,r=0;
  while(b[r]!=a[r] && r<n){
    r++;l++;
  }
  if(r==n){
    cout << "Yes" <<"\n";
    for(auto it: b)
      cout << it <<" ";
    cout << "\n";
  }
  else{
    while(r<n && a[r]==b[r])
      r++;
    int need=r-l;
    int j=0,left=l,right=r;
    while(j<left && l<r && need){
      if(b[j]!=b[l] && a[j]!=b[l]){
        swap(b[j],b[l]);
        need--;
        l++;
        j++;
      }
      else
        break;
    }
    j=n-1;
    while(j>=right && l<right && need){
      if(b[j]!=b[l] && a[j]!=b[l]){
        swap(b[j],b[l]);
        need--;
        l++;
        j--;
      }
      else
        break;
    }
    if(need)
      cout << "No" <<"\n";
    else{
      cout << "Yes" <<"\n";
      for(auto it: b)
        cout << it <<" ";
      cout << "\n";
    }
  }

}


/*
*/

//9c(n-2)*2
















Measured memory_bytes: 6376
import sys
N,W=list(map(int,input().split()))
wv=[list(map(int,input().split())) for _ in range(N)]

vsum=sum([wv[k][1] for k in range(N)])

#dp[i個目までの品物][価値がv]→価値がvとなるような重さの最小値
dp=[[sys.maxsize]*(vsum+2) for _ in range(N+1)]
for k in range(N):
    dp[k][0]=0


for i in range(N):
    for v in range(vsum+1):
        if dp[i][v]+wv[i][0]<=W:
            dp[i+1][v+wv[i][1]]=min(dp[i+1][v+wv[i][1]],dp[i][v]+wv[i][0])
        dp[i+1][v]=min(dp[i+1][v],dp[i][v])


#dpがW以下となる最大のvを求める
for x in range(vsum,-1,-1):
    for y in range(N,-1,-1):
        if dp[y][x]<=W:
            print(x)
            break
    else:continue
    break


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

int main(){
 double x1,x2,y1,y2;
 
 cin >> x1 >> y1 >> x2 >> y2 ;

 cout << fixed << sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)) << endl ;
 
 return 0;
}

Measured memory_bytes: 3212