akhauriyash/Code-Regression huggingface dataset:
require 'pp'
# IS_DEBUG = true
IS_DEBUG = false
def dputs str
	if(IS_DEBUG)
		puts str
	end
end
def dpp str
	if(IS_DEBUG)
		pp str
	end
end

INT_MAX = 999999999999999999999999

N,d=gets.chomp.split(' ').map{|n| n.to_i}
X=gets.chomp.split(' ').map{|n| n.to_i}

xorsum = 0
sum = 0
i = 0
j = 0
while(i < N-1)
	while(j < N)
		xj = X[j]
		if(xorsum | xj != xorsum + xj)
			dputs "out: i,j = #{i},#{j}"
			break
		else
			dputs "hit: i,j = #{i},#{j}"
			j += 1
			xorsum |= xj
		end
	end
	sum += (j-1-i+1)
	dputs "add: (i,j) = (#{i},#{j})"
	# next state
	xorsum ^= X[i]
	dputs "xorsum modified as #{xorsum}"
	i += 1
end
sum += 1
puts sum




Measured memory_bytes: 22792
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		// ????£??????¬??°
		int vertical = 0;
		// ?¨??£??????¬??°
		int horizontal = 0;
		// ????????????????????¨?????°
		int x = 0;
		// ????????????
		boolean result = true;

		while (result) {
			// ????£? 1??????
			vertical = Integer.parseInt(br.readLine());
			if (vertical > 30) {
				break;
			}

			// ????£???????????????????
			int[] drowingLots = new int[vertical];
			// ??????????£??????????????´???????
			for (int i = 0; i < vertical; ++i) {
				drowingLots[i] = i + 1;
			}

			// ?¨??£? 2??????
			horizontal = Integer.parseInt(br.readLine());
			if (horizontal > 30) {
				break;
			}

			while (result) {
				// ?¨??????\?????????????????????????????????????????? 3????????\???
				for (int i = 0; i < horizontal; ++i) {
					String input = br.readLine();
					if (input == null || input.isEmpty()) {
						break;
					}

					String[] change = input.split(",");
					int[] intInput = adjustment(change);

					// a1???????????????
					x = drowingLots[intInput[0]];
					// b1???a1?????\??????
					drowingLots[intInput[0]] = drowingLots[intInput[1]];
					// a1???b1?????\??????
					drowingLots[intInput[1]] = x;
				}

				for (int output : drowingLots) {
					System.out.println(output);
				}
				result = false;
			}

		}
	}

	// ??\??????????????????int??????????????????-1??????
	private static int[] adjustment(String[] strInput) {
		// int????????????????????????
		int[] intInput = new int[strInput.length];

		intInput[0] = Integer.parseInt(strInput[0]) - 1;
		intInput[1] = Integer.parseInt(strInput[1]) - 1;

		return intInput;
	}

}

Measured memory_bytes: 24088
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mod 1000000007
ll exp(ll taban, ll us) {
    ll carpan = taban % mod;
    ll temp = us;
    ll res = 1;
    while(temp){
        if(temp % 2) res = (res*carpan) % mod;
        temp /= 2;
        carpan = (carpan*carpan) % mod;
    }
    return res;
}
ll ebob(ll a, ll b){
	if(!a)return b;
	return ebob(b%a, a);
}
ll ekok(ll a, ll b){
	return (a*b)/ebob(a, b);
}
int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n, m; cin>>n>>m;
	cout<<(n*(n-1)/2 + m*(m-1)/2)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6 + 10;
const ll MOD = 1e9 + 7;

char a[N];

bool q(int x, int y) {

    while(x <= y) {
        if(a[x] != a[y])
            return false;
        x ++;
        y --;
    }
    return true;

}

int main() {
    scanf("%s", a+1);
    int len = strlen(a+1);
    int mid = (len + 1) / 2;
    if(q(1, mid - 1) && q(1, len) && q(mid+1, len)) {
        cout<<"Yes"<<endl;
    }else {
        cout<<"No"<<endl;
    }
	return 0;
}


Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

int N, K;
int D[2001];
int E[4001], ne[4001], he[2001];
void dfs(int v, int d) {
	D[v] = d;
	for (int to = he[v]; to; to = ne[to]) {
		if (D[E[to]] < 0) dfs(E[to], d + 1);
	}
}
int d, k;
int dfs2(int v, int prev) {
	int ret = 1;
	d++;
	for (int to = he[v]; to; to = ne[to]) {
		if (E[to] != prev && d <= k) ret += dfs2(E[to], v);
	}
	d--;
	return ret;
}

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

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


	N = getint();
	K = getint();
	k = K / 2;
	int tmp = 1;
	int jisuu[2001] = {};
	rep(i, N - 1) {
		int a = getint(), b = getint();
		E[tmp] = b;
		ne[tmp] = he[a];
		he[a] = tmp++;
		E[tmp] = a;
		ne[tmp] = he[b];
		he[b] = tmp++;
		jisuu[a]++;
		jisuu[b]++;
	}

	if (K == 1) {
		printf("%d\n", N - 2);
		return 0;
	}

	rep1(j, N) D[j] = -1;
	dfs(1, 0);
	int saidai = 0;
	int doko, doko2;
	rep1(i, N) if (saidai < D[i]) {
		saidai = D[i];
		doko = i;
	}
	rep1(j, N) D[j] = -1;
	dfs(doko, 0);
	saidai = 0;
	bool muri[2001] = {};
	rep1(i, N) {
		if (saidai < D[i]) {
			saidai = D[i];
			doko2 = i;
		}
		if (D[i] < k) {
			muri[i] = 1;
		}
	}
	if (saidai <= K) {
		printf("0\n");
		return 0;
	}
	rep1(j, N) D[j] = -1;
	dfs(doko2, 0);
	rep1(i, N) {
		if (D[i] < k) muri[i] = 1;
		if (jisuu[i] == 1) {
			muri[i] = 1;
			if (K > 3) {
				int j = E[he[i]];
				if (jisuu[j] == 2) muri[j] = 1;
			}
		}
	}

	if (K % 2 == 0) {
		int kotae = N;
		rep1(i, N) {
			if (!muri[i]) {
				int kazu = dfs2(i, -1);
				kotae = min(kotae, N - kazu);
			}
		}
		printf("%d", kotae);
	}
	else {
		int kotae = N;
		rep1(z, N - 1) {
			int i = E[z * 2];
			int j = E[z * 2 - 1];
			if (!muri[i] && !muri[j]) {
				int kazu = dfs2(i, j) + dfs2(j, i);
				kotae = min(kotae, N - kazu);
			}
		}
		printf("%d", kotae);
	}

	Would you please return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
int N,num,result;
num = 0;
result = 0;
scanf("%d",&N);
if(N > 10){
for(int i = 11; i <= N;i = i +2){
int tmp =0;
for(int j = 2; j < i;j++){
if(i % j == 0)
tmp ++;
}
if(tmp == 6)
result ++;
}
}
else{
result = 0;
}
printf("%d",result);
}

Measured memory_bytes: 128
x, n = map(int, input().split())
p = list(map(int, input().split()))

p = set(p)
ans = -5
d = 1000
for i in range(-5, 105):
    if i not in p:
        if d > abs(x-i):
            ans = i
            d = abs(x-i)

print(ans)


Measured memory_bytes: 9180
n = int(input())

w = list(map(int, input().split()))

sb = 100000000

for t in range(1,n):
    s1 = sum(w[:t])
    s2 = sum(w[t:])

    sa = abs(s1 - s2)

    if sa < sb:
        sb = sa

print(sb)

Measured memory_bytes: 3060
#include <bits/stdc++.h>  // ver2.2.3
#define int long long
#define endl "\n"
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define VVi vector<Vi>
#define Vs vector<string>
#define Pii pair<int,int>
#define VPii vector<Pii>
#define Tiii tuple<int,int,int>
#define PQi priority_queue<int>
#define PQir priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define itos to_string
#define stoi stoll
#define FI first
#define SE second
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define sortr(v) sort(v,greater<>())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define dem(a,b) ((a+b-1)/(b))
#define Vin(a) rep(iI,0,a.size())cin>>a[iI]
#define Vout(a) rep(lZ,0,a.size()-1)cout<<a[lZ]<<' ';cout<<a.back()<<endl
#define VVout(a) rep(lY,0,a.size()){Vout(a[lY]);}
#define VPout(a) rep(lX,0,a.size())cout<<a[lX].FI<<' '<<a[lX].SE<<endl
#define Verr(a) rep(iZ,0,a.size()-1)cerr<<a[iZ]<<' ';cerr<<a.back()<<endl
#define VVerr(a) rep(iY,0,a.size()){Verr(a[iY]);}
#define VPerr(a) rep(iX,0,a.size())cerr<<a[iX].FI<<' '<<a[iX].SE<<endl
#define INF 3000000000000000000  //  3.0*10^18(MAXの1/3くらい)
#define MAX LLONG_MAX
#define MOD 1000000007  //  10^9 + 7
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm
void press(auto &v){v.erase(unique(ALL(v)),v.end());}  //  圧縮
int mypow(int x, int n, int m){  //  累乗x^n(mod m)  O(log(n))
if(n==0)return 1;if(n%2==0)return mypow(x*x%m,n/2,m);else return x*mypow(x,n-1,m)%m;}

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

signed main() {
  cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(12);
  int n,m;
  cin >> n >> m;
  UnionFind tree(n);
  int qw,er,ty;
  rep(i,0,m){
    cin >> qw >> er >> ty;
    qw--,er--;
    tree.unite(qw,er);
  }
  set<int> kind;
  rep(i,0,n){
    kind.insert(tree.root(i));
  }
  cout << kind.size() << endl;
  return 0;
}

Measured memory_bytes: 5760
#define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <iterator>
 
using namespace std;
 
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
 
#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)c.size())

typedef unsigned long long ull;
const int INF = (int)1e8;

int a[7],b[7];
int main(){
	int m;
	while(cin>>m,m){
		FOR(i,m) cin>>a[i]>>b[i];

		int dp[10000] = {};
		dp[0] = 1;
		FOR(i,m){
			for(int j = 1000; j >= 0; j--){
				for(int k = 1; k <= b[i]; k++){
					dp[j + k * a[i]] += dp[j];
				}
			}
		}

		int g; cin>>g;
		FOR(i,g){
			int x; cin>>x;
			cout << dp[x] << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1204
num = input()

num1 = int(num[0:2])
num2 = int(num[2:])

YYMM_flg = False
MMYY_flg = False

if num1 >= 1 and num1 <= 12:
    MMYY_flg = True

if num2 >= 1 and num2 <= 12:
    YYMM_flg = True

if YYMM_flg and MMYY_flg:
    print('AMBIGUOUS')
elif YYMM_flg:
    print('YYMM')
elif MMYY_flg:
    print('MMYY')
else:
    print('NA')


Measured memory_bytes: 3060
#include <stdio.h>
 
int i,n,s;
 
void part(int cal, int index, int sum){
			if(index == 10 && cal == n && sum == s){
			i++;
			return;	
			} 
			
			if(index > 9|| cal > n||sum > s) return;
			
	part(cal, index + 1, sum);
	part(cal + 1, index + 1, sum + index);
}
 
main(){
	while(1){
		scanf("%d %d", &n , &s);
		if (n==0 && s==0) return 0;
		i = 0;
		part(0, 0, 0);
		printf("%d\n",i);
	}
	return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
long long fac(ll a){
    long long ans=1;
    while(a>1){
        ans*=a;
        a--;
    }
    return ans;
}
int main(){
    int n,m;
    cin >> n >> m;
    vector<ll> dp(n+1,1);
    for(int i=0;i<m;i++){
        int a;
        cin >> a;
        dp[a] = 0;
    }
    for(int i=2;i<n+1;i++){
        if(dp[i]!=0){
            dp[i]=(dp[i-1]+dp[i-2])%MOD;
        }
    }
    cout << dp[n] << endl;
}


Measured memory_bytes: 1024
// ====================================
//   author: M_sea
//   website: https://m-sea-blog.com/
// ====================================
#include <bits/stdc++.h>
#define file(x) freopen(#x".in","r",stdin); freopen(#x".out","w",stdout)
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
typedef long long ll;

int read() {
	int X=0,w=1; char c=getchar();
	while (c<'0'||c>'9') { if (c=='-') w=-1; c=getchar(); }
	while (c>='0'&&c<='9') X=X*10+c-'0',c=getchar();
	return X*w;
}

const int N=1000+10;
const int mod=1e9+7;

int n,c[N];
void calc(int x) {
	for (int i=2;i*i<=x;++i)
		while (x%i==0) x/=i,++c[i];
	if (x>1) ++c[x];
}

int main() {
	n=read();
	for (int i=1;i<=n;++i) calc(i);
	int ans=1;
	for (int i=1;i<=n;++i) ans=1ll*ans*(c[i]+1)%mod;
	printf("%d\n",ans);
	return 0;
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

const int64 mod = 1e9+7;

int64 fact[1010], inv[1010];

int64 mpow(int64 a, int64 b){
	if(b == 0) return 1;
	if(b%2) return a*mpow(a, b-1)%mod;
	int64 ret = mpow(a, b/2);
	return ret*ret%mod;
}

void init(){
	fact[0] = 1; inv[0] = 1;
	REP(i, 1009) fact[i+1] = fact[i]*(i+1)%mod;
	REP(i, 1010) inv[i] = mpow(fact[i], mod-2);
}

int64 comb(int64 a, int64 b){
	if(a < b) return 0;
	return fact[a]*inv[b]%mod*inv[a-b]%mod;
}

int main(void){
	int64 N, M;
	cin >> N >> M;
	if(N == 1 && M == 1){
		cout << 1 << endl;
		return 0;
	}
	if(N == 1 || M == 1){
		cout << max((int64)0, max(N, M)-2) << endl;
		return 0;
	}
	if(N < 2 || M < 2){
		cout << 0 << endl;
		return 0;
	}
	cout << (N-2)*(M-2) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>

using namespace std;

#define uint unsigned int

uint N, M;
long long sum = 0;
void check(uint modsum[], uint allmod[]){
    for(int i = 0; i < N; i++){
        cout << modsum[i] << " ";
    }
    cout << "\n";
    //for(int i = 0; i < M; i++){
    //    cout << allmod[i] << " ";
    //}
    //cout << "\n";
    cout << sum << "\n" << endl;
}

int main(){
    cin >> N >> M;
    uint modsum[N] = {};
    map<int, int> allmod;

    uint a;
    cin >> a;
    modsum[0] = a % M;
    if(modsum[0] == 0)
        sum++;
    allmod[modsum[0]]++;

    for(int i=1;i<N;i++){
       // check(modsum, allmod);
        cin >> a;
        //if((a % M) == 0)
        //    sum++;
        modsum[i] = (modsum[i-1] + (a % M)) % M;
        if(modsum[i] == 0)
            sum++;
        sum += allmod[modsum[i]];
        allmod[modsum[i]]++;
    }

    //check(modsum, allmod);

    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3584
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<cmath>
using namespace std;
typedef long long ll;
const ll P = 1000000007;
const int Nmax = 100000;
int N;
int A[Nmax];
int cnt[Nmax];

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

	/*
	for(int i=0; i<N; i++) cout << cnt[i] << " ";
	cout << endl;
	*/

	bool ok = true;
	if(N%2==0){
		ok = (cnt[0] == 0);
		for(int i=1; i<N; i++){
			if(i%2 == 0){
				ok = (ok && cnt[i]== 0);
			}
			else{
				ok = (ok && cnt[i] == 2);
			}
		}

	}
	else{
		ok = (cnt[0] == 1);
		for(int i=1; i<N; i++){
			if(i%2 == 0){
				ok = (ok && cnt[i] == 2);
			}
			else{
				ok = (ok && cnt[i] == 0);
			}
		}
	}

	ll ans = 1;
	if(ok){
		for(int i=0; i<N/2; i++){
			ans = 2*ans%P;
		}
		cout << ans << endl;
	}
	else{
		cout << 0 << endl;
	}
	return 0;
}


Measured memory_bytes: 1152
/*
 * ARC085_D.cpp
 *
 *  Created on: May 31, 2018
 *      Author: 13743
 */
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<cstring>
using namespace std;
typedef long long lng;
typedef unsigned long long ulng;

#define pb push_back
#define SZ(a) int((a).size())
#define ALL(a) (a).begin(), (a).end()
#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define FORD(i,b,a) for(int i=(b); i>=(a); --i)
#define REP(i,n) FOR(i,0,n-1)
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())

lng power(lng b, lng e) {lng sol=1; while(e>0) {if(e&1) {sol=sol*b;} e>>=1; b*= b;} return sol;}

int dp[2][2000];
int N, Z, W;
int a[2000];

int dpRec(int AB, int rest) {
	if(dp[AB][rest] >= 0) {
		return dp[AB][rest];
	}
	int hand = AB ? Z : W;
	if(rest > 0) {
		hand = a[rest-1];
	}
	dp[AB][rest] = abs(a[N-1] - hand);
	for(int i=rest+1; i<N; i++) {
		if(AB == 0) dp[0][rest] = max(dp[0][rest], dpRec(1, i));
		else dp[1][rest] = min(dp[1][rest], dpRec(0, i));
	}
	return dp[AB][rest];
}

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


	cin >> N >> Z >> W;
	REP(i, N) {
		cin >> a[i];
	}

	for(int i=0; i<2; i++) {
		for(int j=0; j<2000; j++) {
			dp[i][j] = -1;
		}
	}
	cout << dpRec(0, 0) << endl;


}






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

#define int long long

#define pb push_back
#define mp make_pair
#define st first
#define nd second
typedef pair < int , int > pp;
const int mod = 1e9 + 7;
const int N   = 2e5 + 5;

int a,b;

signed main(){
    cin >> a >> b;
    if(a > b) swap(a,b);
    if(a == 1) cout << (b == 1 ? 1 : b-2);
    else cout << (a-2)*(b-2);
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

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

typedef long long ll;

const int MX=100005;

vector <ll> a;
bool vis[MX];
int pos[MX];

ll f(int p,ll n)
{
    ll x=0,sum=0;
    ll l=a.size();
    for(int i=p;(i<l && n);i++,n--) x+=a[i];
    if(n==0) return x;
    ll k=n/(l-p),r=n%(l-p);
    for(int i=p;i-p<r;i++) x+=a[i];
    for(int i=p;i<l;i++) sum+=a[i];
    return x+sum*k;
}

int main()
{
    ll n,x,m,ans=0;
    cin>> n >> x >> m;
    for(int i=0;i<n;i++){
        if(vis[x]){
            ans+=f(pos[x],n-i);
            break;
        }
        pos[x]=i;
        vis[x]=true;
        a.push_back(x);
        ans+=x;
        x=(x*x)%m;
    }
    cout<< ans <<endl;
    return 0;
}

Measured memory_bytes: 4388
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc= new Scanner(System.in);
        int n=sc.nextInt();
        boolean b=true;
        while(n%4!=0){
            n-=7;
            if(n<0){
                b=false;
                break;
            }
            if(n==0){
                break;
            }
        }
        if(b){
            System.out.println("Yes");
        }
        else{
            System.out.println("No");
        }
    }      
}

Measured memory_bytes: 25044
n = int(input())
x = input()
original_pop_count = x.count('1')
one_pop_count = original_pop_count-1
zero_pop_count = original_pop_count+1

one_mod = 0
zero_mod= 0
for b in x:
    if one_pop_count!=0:
        one_mod=(one_mod*2+int(b))%one_pop_count
    zero_mod=(zero_mod*2+int(b))%zero_pop_count
#予めf[i]を計算する
f = [0]*220000
pop_count = [0]*220000
for i in range(1,220000):
    pop_count[i]= pop_count[i//2] + i%2
    f[i] = f[i%pop_count[i]]+1
one_pow2 = [1]*220000
zero_pow2 = [1]*220000
for i in range(1,220000):
    if one_pop_count!=0:
        one_pow2[i] = one_pow2[i-1]*2%one_pop_count
    zero_pow2[i] = zero_pow2[i-1]*2%zero_pop_count


for i in range(n-1,-1,-1):
    if x[n-1-i]=='1':
        if one_pop_count!=0:
            nxt = one_mod
            nxt-=one_pow2[i]
            nxt%=one_pop_count
            print(f[nxt]+1)
        else:
            print(0)
    if x[n-1-i]=='0':
        nxt = zero_mod
        nxt+=zero_pow2[i]
        nxt%=zero_pop_count
        print(f[nxt]+1)

Measured memory_bytes: 84396
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in); 

		int n = sc.nextInt();
		int[] data = new int[n];

    	for (int i = 0; i < n; i++) {
    		data[i] = sc.nextInt();
    	}

    	// i以降の最大値を保持
    	int[] dataMax = new int[n];
    	for (int i = n - 1; i >= 0; i--) {
    		if (i == n - 1) {
    			dataMax[i] = data[i];
    		} else {
    			dataMax[i] = Math.max(dataMax[i + 1], data[i]);
    		}
    	}

    	int max_profit = data[1] - data[0];
    	for (int i = 0; i < n - 1; i++) {
//    		if (i == 0 || data[i - 1] > data[i]) {
    			max_profit = Math.max(max_profit, dataMax[i + 1] - data[i]);
//    		}
    	}
		
    	System.out.println(max_profit);
    	
        sc.close();
	}
}

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

using namespace std;

#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pow(x) x*x
#define ll long long
static const ll MAX = 1000000;
static const ll INFTY = 1e12;
static const ll MOD = 1000000007;

template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };

struct edge {
    ll to, cost;
};

using Graph = vector<vector<int>>;
using _Graph = vector<vector<edge>>;


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

// 深さ優先探索
vector<bool> seen;
vector<int> colors;

int H, W, N;
int sx, sy, gx, gy; 
vector<vector<char>> field;
vector<vector<int>> dist;
//vector<pair<int, int>> gx, gy;
deque<pair<int, int>> que;

typedef vector<vector<int> > Matrix;

const int INF = 100000000;


int main() {

    int R;
    cin >> R;

    double ans = 2 * 3.141592 * R;

    cout << ans << endl;
    

}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/


Measured memory_bytes: 3768
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : "");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int H, W, A, B;
	cin >> H >> W >> A >> B;

	vector<vector<int>> grid(H, vector<int>(W));
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (i < B && j < A || i >= B && j >= A) grid[i][j] = 1;
		}
	}

	cout << grid << "\n";

	return 0;
}

Measured memory_bytes: 5248
#include<bits/stdc++.h>
using namespace std;
int main(){
  string a;
  cin>>a;
  if(a=="SAT"){
    cout<<1<<'\n';
  }
  else if(a=="FRI"){
    cout<<2<<'\n';
  }
  else if(a=="THU"){
    cout<<3<<'\n';
  }
  else if(a=="WED"){
    cout<<4<<'\n';
  }
  else if(a=="TUE"){
    cout<<5<<'\n';
  }
  else if(a=="MON"){
        cout<<6<<'\n';
  }
  else if(a=="SUN"){
    cout<<7<<'\n';
  }
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<vector<ll>> matrix;

// zero
// even, nonzero
// odd
// even, nonzero
// zero
ll dp[5];
ll ndp[5];

ll cost(int x, int type) {
  if(type == 0 || type == 4) return x;
  if(type == 1 || type == 3) {
    if(x == 0) return 2;
    return x%2;
  }
  assert(type == 2);
  return 1 - (x%2);
}

void solve() {
  int n;
  cin >> n;
  while(n--) {
    int t;
    cin >> t;
    ndp[0] = 1e18;
    ndp[1] = 1e18;
    ndp[2] = 1e18;
    ndp[3] = 1e18;
    ndp[4] = 1e18;
    for(int i = 0; i <= 4; i++) {
      for(int j = i; j <= 4; j++) {
        ndp[j] = min(ndp[j], dp[i] + cost(t, j));
      }
    }
    memcpy(dp, ndp, sizeof(dp));
  }
  sort(dp, dp+5);
  cout << dp[0] << "\n";
}

void casesolve() {
  int t;
  cin >> t; cin.ignore();
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ": ";
    solve();
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
  // casesolve();
}


Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC148A
{
	class Program
	{
		static void Main(string[] args)
		{
			int a, b,s;
			s = 0;
			a = int.Parse(Console.ReadLine());
			b = int.Parse(Console.ReadLine());
			if ((a<3)&&(b<3))
			{
				s = 3;
			}
			else if (((a < 2) && (b > 2)) || ((a > 2) && (b < 2)))
			{
				s = 2;
			}
			else
			{
				s = 1;
			}
			Console.Write(s);
			Console.ReadKey();
		}
	}
}


Measured memory_bytes: 11092
#define _GLIBCXX_DEBUG
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <map>
using namespace std;
typedef long long ll;
#define ALL(v) (v).begin(), (v).end()
const int inf = 1e9;
const int mod = 1e9+7;

int main() {
    string T = "MARCH";
    int N;
    cin >> N;

    vector<ll> v(5, 0);
    for (int i = 0; i < N; i++) {
        string s;
        cin >> s;
        for (int j = 0; j < 5; j++) {
            if (s[0] == T[j]) v[j]++;
        }
    }

    ll ans = 0;
    for (int i = 0; i < 5; i++) {
        for (int j = i+1; j < 5; j++) {
            for (int k = j+1; k < 5; k++) {
                ans += (v[i] * v[j] * v[k]);
            }
        }
    }

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


Measured memory_bytes: 384
#include <iostream>
#include <vector>

using namespace std;
bool isvalid(vector<int>& vec, int k, int p){
    int idx = 0;
    for(int i = 0; i < k; ++i){
        int w = 0;
        while(idx < int(vec.size())){
            if(vec[idx]+w <= p){
                w += vec[idx];
                ++idx;
            } else {
                break;
            }
        }

    }
    if(idx == int(vec.size())){
        return true;
    }
    return false;
}

int lower_bound(vector<int>& vec, int l, int h, int k){
    if(h-l <= 1){
        return h;
    }
    int mid = (h+l)/2;
    if(isvalid(vec, k, mid)){
        return lower_bound(vec, l, mid, k);
    } else {
        return lower_bound(vec, mid, h, k);
    }
}

int main(){
    int n, k;
    cin >> n >> k;
    auto vec = vector<int>();
    for(int i = 0; i < n; ++i){
        int temp;
        scanf("%d", &temp);
        vec.push_back(temp);
    }
    cout << lower_bound(vec, 0, 1000000000, k) << '\n';
}

Measured memory_bytes: 1720
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
int n,a,b,dp[2][2][5005],dp2[2][2][5005],ans=0;
const int mod=1e9+7;
int M(int x){return x>=mod?x-mod:x;}
int main()
{
	scanf("%d%d%d",&n,&a,&b);
	if(a>b)swap(a,b);
	for(int i=a;i<=n;i++)dp[0][0][i]=1;
	for(int i=1;i<=n;i++)dp[1][1][i]=1;
	for(int i=1;i<n;i++)
	{
		for(int u=0;u<2;u++)
		{
			for(int j=a;j<=n-i;j++)dp[u][0][i+j]=M(dp[u][0][i+j]+dp[u][1][i]);
			for(int j=1;j<=n-i;j++)dp[u][1][i+j]=M(dp[u][1][i+j]+dp[u][0][i]);
		}
	}
	for(int i=1;i<a;i++)dp2[0][0][i]=1;
	for(int i=1;i<b;i++)dp2[0][1][i]=M(dp[0][1][i]+dp[1][1][i]);
	for(int i=b;i<n;i++)dp2[1][1][i]=M(dp[0][1][i]+dp[1][1][i]);
	dp2[1][1][n]=M(M(dp[0][1][n]+dp[0][0][n])+M(dp[1][0][n]+dp[1][1][n]));
	for(int i=1;i<=n;i++)
	{
		for(int u=0;u<2;u++)
		{
			for(int j=1;j<=n-i&&j<b;j++)
			{
				dp2[u][1][i+j]=(1ll*dp2[u][1][i+j]+1ll*dp[1][1][j]*dp2[u][0][i])%mod;
				if(i+j==n)dp2[u][0][i+j]=(1ll*dp2[u][0][i+j]+1ll*dp[1][0][j]*dp2[u][0][i])%mod;
			}
			for(int j=b;j<=n-i;j++)
			{
				dp2[1][1][i+j]=(1ll*dp2[1][1][i+j]+1ll*dp[1][1][j]*dp2[u][0][i])%mod;
				if(i+j==n)dp2[1][0][i+j]=(1ll*dp2[1][0][i+j]+1ll*dp[1][0][j]*dp2[u][0][i])%mod;
			}
			for(int j=1;j<a&&j<=n-i;j++)dp2[u][0][i+j]=M(dp2[u][0][i+j]+dp2[u][1][i]);
		}
	}
	for(int i=0;i<2;i++)ans=M(ans+dp2[1][i][n]);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1860
#include<bits/stdc++.h>
using namespace std;
int a,b,n,m,num[200005];
vector<int>edge[200005];
void dfs(int x,int fa){
	for(int i=0;i<edge[x].size();++i)
		if(edge[x][i]!=fa){
			num[edge[x][i]]+=num[x];
			dfs(edge[x][i],x);
		}
} 
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<n;++i){
		scanf("%d%d",&a,&b);
		edge[a].push_back(b);
		edge[b].push_back(a);
	}
	for(int i=1;i<=m;++i){
		int id,v;
		scanf("%d%d",&id,&v);
		num[id]+=v;
	}
	dfs(1,0);
	for(int i=1;i<=n;++i)printf("%d ",num[i]);
}

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

#define sswap(x, y) { x+=y; y=x-y; x-=y; }
#define LSOne(S) ((S) & (-S))

#define EPS 1e-6
#define MOD 1000000007

#define fi first
#define se second
#define pb push_back
#define ende '\n'

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define mset(x, y) memset(&x, (y), sizeof(x))

using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
	vi w;
	int s1, s2, best, n, e;
	cin >> n;
	while (cin >> e) w.pb(e);
	s1 = w[0];
	s2 = 0;
	for (int i = 1; i < n; i++) s2 += w[i];
	best = abs(s1-s2);
	for (int i = 1; i < n-1; i++) {
		s1 += w[i];
		s2 -= w[i];
		best = min(abs(s1-s2), best);
	}
	cout << best << ende;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
#define ll long long
#define sf scanf
#define pf printf
using namespace std;
const ll mod=1e9+9;

struct node{
	ll x,y;
}a[200009];

bool cmp(node a,node b){
	return a.x<b.x;
}

int main(){
	ll n,d,cnt=0;
	sf("%lld %lld",&n,&d);
	d*=d;
	for(int i = 1;i<=n;i++){
		sf("%lld %lld",&a[i].x,&a[i].y);
	}
	sort(a+1,a+n+1,cmp);
	for(int i = 1;i<=n;i++){
		if(d >= (a[i].x*a[i].x)+(a[i].y*a[i].y) ) 
			cnt++;
	}
	cout<<cnt;
	return 0;
}

Measured memory_bytes: 6808
/**
 * Combinatorial - 0-1 Knapsack Problem
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import static java.lang.Integer.parseInt;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;

		while ((line = br.readLine()) != null && !line.isEmpty()) {
			int n = parseInt(line.substring(0, line.indexOf(' ')));
			int w = parseInt(line.substring(line.indexOf(' ') + 1));

			int[][] dp = new int[n + 1][w + 1];
			int[] vs = new int[n + 1];
			int[] ws = new int[n + 1];

			for (int i = 1; i < n + 1; i++) {
				line = br.readLine();
				vs[i] = parseInt(line.substring(0, line.indexOf(' ')));
				ws[i] = parseInt(line.substring(line.indexOf(' ') + 1));
			}

			//
			for (int i = 1; i < n + 1; i++) {
				for (int j = 1; j < w + 1; j++) {
					if (j < ws[i]) {
						dp[i][j] = dp[i - 1][j];
					} else {
						dp[i][j] = Math.max(dp[i - 1][j], dp[i - 1][j - ws[i]] + vs[i]);
					}
				}
			}
			System.out.println(dp[n][w]);
		}//end while
	}//end main
}

Measured memory_bytes: 24312
import java.math.BigDecimal
import java.math.BigInteger

//nCk
fun main(args: Array<String>) {
    fun nCk(n: Long, k: Long): Long {
        var mom = BigInteger.valueOf(1)
        var chi = BigInteger.valueOf(1)
        val min = Math.min(k, n - k)
        for (i in 0 until min) {
            mom *= BigInteger.valueOf((min - i))
            chi *= BigInteger.valueOf((n - i))
        }
        return (chi / mom).toLong()
    }
    val (n, a, b) = readLine()!!.split(' ').map(String::toInt)
    val vList = readLine()!!.split(' ').map(String::toLong).sortedDescending()

    val valList = mutableListOf<Pair<Int, BigDecimal>>()
    for (i in a..b) {
        val take = vList.take(i)
        val sum = BigDecimal.valueOf(take.sum())
        val average = sum.setScale(12) / BigDecimal.valueOf(i.toDouble())
        valList.add(Pair(i, average))
    }
    val maxValue = valList.maxBy { it.second }!!.second
    val ansIndexes = valList.filter { it.second == maxValue }.map { it.first }
    var pattern = 0L
    for (i in ansIndexes) {
        val take = vList.take(i)
        val takeLastCount = take.count { it == take.last() }
        val vCount = vList.count { it == take.last() }
        pattern += nCk(vCount.toLong(), takeLastCount.toLong())
    }
    println(maxValue.toPlainString())
    println(pattern)
}


Measured memory_bytes: 38332
#include <iostream>
#include <vector>
#define rep(i,n) for(int i = 0; i , (n); ++i)
using ll = long long;
using namespace std;

int sum(int n) {
    if (n == 0) {
        return 0;
    }

    int s = sum(n - 1);
    return s + n;
}
int main() {
    string A,B="ABC";
        cin >> A;
        if (A == B) {
            cout << "ARC";
        }
        else {
            cout << "ABC";
        }
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
//動画解答写し 
string f(long long n){
  if(n==0)return "";
  n--;
  return f(n/26)+string(1,'a'+n%26);
}
int main(){
  long long n;
  cin>>n;
  cout<<f(n)<<endl;
  return 0;
}

Measured memory_bytes: 3556
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[][] a = new int[2][n];
		for(int i = 0 ; i < 2 ; i++) {
			for(int j = 0 ; j < n ; j++) {
				a[i][j] = sc.nextInt();
			}
		}
		int[][] dp = new int[2][n];
		dp[0][0] = a[0][0];
		dp[1][0] = a[1][0] + a[0][0];
		if(n != 1) {
			dp[0][1] = a[0][1] + a[0][0];
		}
		for(int i = 2 ; i < n ; i++) {
			dp[0][i] = dp[0][i - 1] + a[0][i];
		}
		for(int i = 1 ; i < n ; i++) {
			dp[1][i] = Math.max(dp[1][i - 1] + a[1][i], dp[0][i] + a[1][i]);
		}
		System.out.println(dp[1][n - 1]);
	}
}


Measured memory_bytes: 21844
fun main(args: Array<String>) {
    val (x, y, a, b, c) = readLine()!!.split(" ").map{it.toInt()}
    val p = readLine()!!.split(" ").map{it.toLong()}.toLongArray()
    val q = readLine()!!.split(" ").map{it.toLong()}.toLongArray()
    val r = readLine()!!.split(" ").map{it.toLong()}.toLongArray()
    val aa = p.sortedDescending().take(x).toLongArray()
    val bb = q.sortedDescending().take(y).toLongArray()
    val apple = ( aa + bb + r).sortedDescending().take(x+y)
    var ans = 0L
    repeat(x+y){ans += apple[it]}
    println(ans)
}


Measured memory_bytes: 127092
import sys
input = sys.stdin.readline
import numpy as np
from numba import njit


def read():
    D = int(input().strip())
    C = np.fromstring(input().strip(), dtype=np.int32, sep=" ")
    S = np.empty((D, 26), dtype=np.int32)
    for i in range(D):
        s = np.fromstring(input().strip(), dtype=np.int32, sep=" ")
        S[i, :] = s[:]
    M = 10000
    RD = np.random.randint(D, size=(M, ), dtype=np.int32)
    RQ = np.random.randint(26, size=(M, ), dtype=np.int32)
    DQ = np.stack([RD, RQ]).T
    return D, C, S, M, DQ


@njit
def diff_satisfaction(C, S, d, p, last):
    """d日目にコンテストpを開催するときの、満足度の更新量を求める
    """
    v = 0
    for i in range(26):
        v -= C[i] * (d - last[i])
    v += C[p] * (d - last[p])
    v += S[d, p]
    return v


@njit
def evaluate(D, C, S, d, p, last, k=13):
    """d日目にコンテストpを開催し、その後d+k日目までコンテストが開催されないときの、満足度の更新差分を求める
    """
    v = diff_satisfaction(C, S, d, p, last)
    for e in range(d+1, min(d+k, D)):
        for i in range(26):
            v -= C[i] * (e - last[i])
        v += C[p] * (d - last[p])
    return v


@njit
def greedy_fine(D, C, S):
    T = np.zeros(D, dtype=np.int32)
    last = -np.ones(26, dtype=np.int32)
    cumsat = 0
    for d in range(D):
        
        max_p = 0
        max_e = -999999999

        # select contest greedily
        for p in range(26):
            e = evaluate(D, C, S, d, p, last, k=8)
            
            if e > max_e:
                max_p = p
                max_e = e
        
        # update schedule
        cumsat += diff_satisfaction(C, S, d, max_p, last)
        T[d] = max_p
        last[max_p] = d
    return cumsat, T


@njit
def solve(D, C, S, M, DQ):
    cumsat, T = greedy_fine(D, C, S)
    for t in T:
        print(t+1)


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))


Measured memory_bytes: 117284
#include <stdio.h>

int main(void) {
    int a, b;
    int i, count = 0;
    
    while(1) {
        scanf("%d %d", &a, &b);
        if (a == 0 && b == 0) {
            break;
        } else {
            if (count != 0) {
                printf("\n");
                count = 0;
            }
            for (i = a; i <= b; i++) {
                if ((i % 400 == 0) || (i % 4 == 0 && i % 100 != 0)) {
                    printf("%d\n", i);
                    count++;
                }
            }
            if (count == 0) {
                puts("NA");
                count++;
            }
        }
    }
    
    return (0);
}

Measured memory_bytes: 616
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-9;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;


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

	cin >> K;
	string s, t;
	cin >> s >> t;
	N = max(s.size(), t.size());
	N++;
	reverse(s.begin(), s.end());
	reverse(t.begin(), t.end());
	M = sqrt(N) + 1;
	while (s.size() < M*M)s.push_back('0');
	while (t.size() < M*M)t.push_back('0');
	for (auto &i : s)i -= '0';
	for (auto &i : t)i -= '0';
	vector<vector<int>>v(M, vector<int>(2));
	vector<vector<int>>one(M, vector<int>(2, -1));
	vector<vector<int>>sum(M, vector<int>(2));
	for (int i = 0; i < M; i++) {
		for (int j = 0; j < 2; j++) {
			int nx = j;
			for (int k = 0; k < M; k++) {
				int idx = i * M + k;
				nx = nx + s[idx] + t[idx];
				if (nx == 1 && s[idx] == 0) {
					one[i][j] = idx;
				}
				sum[i][j] += nx & 1;
				nx >>= 1;
			}
			v[i][j] = nx;
		}
	}
	while (K--) {
		char a;
		cin >> a;
		if (a == 'Q') {
			int ans = 0;
			int nx = 0;
			int p = -1;
			for (int i = 0; i < M; i++) {
				ans += sum[i][nx];
				p = max(p, one[i][nx]);
				nx = v[i][nx];
			}
			int cn = 0;
			nx = 0;
			int minus = 0;
			while (p / M != cn / M) {
				minus += sum[cn / M][nx];
				nx = v[cn / M][nx];
				cn += M;
			}
			while (p >= cn) {
				nx = nx + s[cn] + t[cn];
				minus += nx & 1;
				nx >>= 1;
				cn++;
			}
			cout << ans+p-minus << endl;
			continue;
		}
		cin >> N;
		if (a == 'A') {
			s[N] ^= 1;
		}
		else {
			t[N] ^= 1;
		}
		int st = N / M;
		for (int i = 0; i < 2; i++) {
			int nx = i;
			one[st][i] = -1;
			sum[st][i] = 0;
			for (int j = 0; j < M; j++) {
				int idx = st * M + j;
				nx = nx + s[idx] + t[idx];
				if (nx == 1 && s[idx] == 0) {
					one[st][i] = idx;
				}
				sum[st][i] += nx & 1;
				nx >>= 1;
			}
			v[st][i] = nx;
		}
		
	}
}


Measured memory_bytes: 3960
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int cnt[31];
int main()
{
	int N, M;
	cin >> N >> M;
	for (int i = 0; i < N; i++) {
		int K;
		cin >> K;
		for (int j = 0; j < K; j++) {
			int A;
			cin >> A;
			A--;
			cnt[A]++;
		}
	}
	int ans = 0;
	for (int i = 0; i < M; i++) {
		if (cnt[i] == N) ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3640
N = int(input())
a = list(map(int, input().split()))
ans = 0

l, r = 0, 0
xor = 0
while r < N:
  if xor ^ a[r] == xor + a[r]:
    xor = xor ^ a[r]
    ans += r-l+1
    r += 1
  else:
    xor -= a[l]
    l += 1
print(ans)

Measured memory_bytes: 24840
N, M= map(int, input().split())
sw = [list(map(int, input().split()))[1:] for _ in range(M)]
P = list(map(int, input().split()))

def mask(l):
    m = 0
    for i in l:
        m += 2**(i-1)
    return m

masks = list(map(mask, sw))

ret = 0
for i in range(2**N):
    if all(bin(i&m).count('1')%2 == p for m, p in zip(masks, P)):
        ret += 1
print(ret)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

using u128 = __uint128_t;

#define int long long
#define idxSet tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define atIdx find_by_order
#define idxOf order_of_key
#define MOD 1000000007
#define MAX 200005
#define endl '\n'

#define v(type) vector<type>
#define p(type1, type2) pair<type1 , type2>
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int dp[MAX];

void solve() {
    int n;
    cin>>n;
    double a[n];
    for (int i = 0; i < n; ++i) {
        cin>>a[i];
    }
    sort(a , a + n);
    double ans = a[0];
    for(int i = 1 ; i< n; i++){
        ans = (ans + a[i]) / 2.0;
    }
    cout<<ans<<endl;

}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    //cin>>t;
    while (t--)
        solve();
    return 0;
}

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

using namespace std;

typedef long long ll;

const int INF = 1e9;

class MaxHeap
{
public:

  MaxHeap() : size_(0)
  {
    heap_ = vector<int>(1000);
  }

  MaxHeap(vector<int> v) : heap_(v), size_(v.size())
  {
    buildHeap();
  }

  void insert(int key)
  {
    if (size_ == (int)heap_.size()) {
      heap_.resize(heap_.size() * 2);
    }
    heap_[size_] = key;
    ++size_;
    int ix = size_ - 1, pix = -1;
    while (ix > 0) {
      pix = (ix - 1) / 2;
      if (heap_[pix] >= heap_[ix]) { break; }
      swap(heap_[ix], heap_[pix]);
      ix = pix;
    }
  }

  int extractMax()
  {
    int ret = heap_[0];
    heap_[0] = heap_[size_ - 1];
    --size_;
    maxHeapify(0);
    return ret;
  }

  int size() { return size_; }
  bool empty() { return size_ == 0; }

  void buildHeap()
  {
    for (int i = (size_ - 1) / 2; i >= 0; --i) {
      maxHeapify(i);
    }
  }

  void maxHeapify(int ix)
  {
    if (ix >= size_) { return; }
    int l = 2 * ix + 1, r = 2 * ix + 2;
    int largest = ix;
    if (l < size_ && heap_[l] > heap_[largest]) { largest = l; }
    if (r < size_ && heap_[r] > heap_[largest]) { largest = r; }
    if (ix != largest) {
      swap(heap_[ix], heap_[largest]);
      maxHeapify(largest);
    }
  }

  void print()
  {
    for (int i = 0; i < size_; ++i) {
      fprintf(stdout, " %d", heap_[i]);
    }
    fprintf(stdout, "\n");
  }

private:
  vector<int> heap_;
  int size_;
};

int main()
{
  MaxHeap h;
  char buf[128] = { '\0' };
  int key = -1;
  while (true) {
    fscanf(stdin, "%s", buf);
    if (buf[0] == 'i') {
      fscanf(stdin, "%d", &key);
      h.insert(key);
    }
    else if (buf[0] == 'e' && buf[1] == 'x') {
      if (h.empty()) { continue; }
      int val = h.extractMax();
      fprintf(stdout, "%d\n", val);
    }
    else if (buf[0] == 'e' && buf[1] == 'n') {
      break;
    }
  }
  return 0;
}

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

M = []
for i in range(1, n+1):
    row = list(map(int, input().split()))
    M.append(row)
# print(M)
v = []
for i in range(1, m+1):
    v.append(int(input()))
# print(v)

def dot_vec(vec1, vec2):
    # print(vec1, vec2)
    return sum(
        e1 * e2 for e1, e2 in zip(vec1, vec2)
    )

ans = [
    dot_vec(row, v) for row in M
]

print(*ans, sep='\n')


Measured memory_bytes: 6032
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
template <class T>
bool maxi(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool mini(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
#define PI (acos(-1))
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------
vector<P> A;
struct edge{ll to;};
struct graph{
    ll N;
    vector<vector<edge> > G;
    vector<bool> used;
    ll mincv;
    ll minc;

    graph(ll n): N(n), G(N), used(N,false) {}

    void add_edge(ll s, ll t){
        G[s].emplace_back((edge){t});
        G[t].emplace_back((edge){s}); //無向ならON
    }

    void dfs(ll v=0){
        used[v]=true;
        if(mini(minc,A[v].first)) mincv=v;
        for(auto E : G[v]){
            if(!used[E.to]){
                dfs(E.to);
            }
        }
    }
};
//--MAIN-----------------------------------
void Main() {
    ll N,M; cin>>N>>M;
    graph g(N);
    A.resize(N);
    rep(i,N) cin>>A[i].first;
    rep(i,N) A[i].second=false;
    rep(i,M){
        ll x,y; cin>>x>>y;
        g.add_edge(x,y);
    }
    ll ki=0;
    rep(i,N){
        if(g.used[i]) continue;
        g.minc=INF;
        g.dfs(i);
        A[g.mincv].second=true;
        ++ki;
    }
    if(ki==1){cout<< 0 <<"\n"; return;}
    
    SORT(A);

    ll nokori=(ki-1)*2-ki;

    rep(i,N){
        if(nokori==0) break;
        if(A[i].second==true) continue;
        A[i].second=true;
        --nokori;
    }
    if(nokori!=0){
        cout<< "Impossible" <<"\n"; return;
    }

    ll ans=0;
    rep(i,N){
        if(A[i].second) ans+=A[i].first;
    }
    cout<< ans <<"\n";

}
//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


Measured memory_bytes: 7808
s = list(input())
K = int(input())
ans = []
for c in s:
    cnt = ord('z') - ord(c) + 1
    if c == 'a':
        ans.append('a')
    elif K >= cnt:
        K -= cnt
        ans.append('a')
    else:
        ans.append(c)
K %= 26
if 122 < ord(ans[-1]) + K:
    ans[-1] = chr(ord(ans[-1]) + K - 26)
else:
    ans[-1] = chr(ord(ans[-1]) + K)
print(*ans,sep='')


Measured memory_bytes: 12424