akhauriyash/Code-Regression huggingface dataset:
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>
#include <stack>
#include <bitset>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

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

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

  int n, r, g, b;

  cin >> r >> g >> b >> n;

  int cnt = 0;
  FOR(i, 0, n+1){
    FOR(j, 0, n+1){
      /*
      cerr << "R:" << r*i << endl;
      cerr << "G:" << g*j << endl;	
      cerr << "B:" << n-r*i-g*j << endl;
      */
      if(n-r*i-g*j >= 0 && (n-r*i-g*j)%b == 0 ) {
	//cerr << i << " " << j << " " << "b" << endl;
	cnt++;
      }
    }
  }

  cout << cnt << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<set>
#include<map>
#include<queue>
#include<cstring>
#include<sstream>
using namespace std;

typedef long long ll;

int main() {
  string N; cin >> N;
  int dp[11][2][2][2][2][2][2];
  memset(dp,0,sizeof(dp));
  dp[0][0][0][0][0][0][0] = 1;
  for ( int i = 0; i < N.length(); i++ ) {
    for ( int j = 0; j < 2; j++ ) {
      for ( int k = 0; k < 2; k++ ) {
	for ( int l = 0; l < 2; l++ ) {
	  for ( int m = 0; m < 2; m++ ) {
	    for ( int n = 0; n < 2; n++ ) {
	      for ( int o = 0; o < 2; o++ ) {
	    int x = j? 9:N[i]-'0';
	    for ( int d = 0; d <= x; d++ ) {
	      bool no357 = n?(d!=3&&d!=5&&d!=7)
		:(d!=0&&d!=3&&d!=5&&d!=7);
     dp[i+1][j || d < x][k || d == 3][l || d==5][m || d==7][n||d][o||no357]
	      += dp[i][j][k][l][m][n][o];
	    }
	    }
	    }
	  }
	}
      }
    }
  }
  int ans = 0;
  for ( int j = 0; j < 2; j++ ) {
    ans += dp[N.length()][j][1][1][1][1][0];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<cmath>
#include<cstring>
#include<iostream>
#define IOS ios::sync_with_stdio(0);cin.tie(0)
#define MEM(X,Y) memset(X,Y,sizeof(Y))
#define FRE freopen("abc.in", "r", stdin)
long long int gcd(long long int a, long long int b) { return b ? gcd(b, a % b) : a; }
using namespace std;

int n;
char s[12];
bool al[10];

void dfs(int x,int cnt)
{
	if (x == n)
	{
		printf("%s", s);
		for(int i=0;i<n;++i)
			if (s[i] != 'a' + i)
			{
				putchar('\n');
				break;
			}
		return;
	} 
	for (int i = 0; i <=cnt; ++i)
	{
		s[x] = 'a' + i;
		if (!al[i])
		{
			al[i] = 1;
			dfs(x + 1, cnt + 1);
			al[i] = 0;
		}
		else
			dfs(x + 1, cnt);
	}
}

int main(void)
{
	scanf("%d", &n);
	dfs(0, 0);
}

Measured memory_bytes: 1536
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
#define ref(i,x,y)for(int i=x;i<=y;++i)
#define def(i,x,y)for(int i=x;i>=y;--i)
typedef long long LL;
const int N=210,mod=1e9+7;
int n,m;LL s,S,A[N],b[N],ans;
struct xint{LL a[N],s;}a[N*61];
bool cmp(xint a,xint b){
	ref(i,2,n){
		LL s1=a.a[i]-a.a[1],s2=b.a[i]-b.a[1];
		if(s1<s2)return 1;if(s1>s2)return 0;
	}
	return a.a[1]-a.s<b.a[1]-b.s||a.a[1]-a.s==b.a[1]-b.s&&a.s>b.s;
}
int ll[61],rr[61];
int count(LL L,LL R){
	ref(i,0,60)ll[i]=L>>i&1,rr[i]=R>>i&1;
	int pos=61,sum=0;
	def(i,60,0)if(ll[i]==rr[i])pos=i;else break;
	def(i,60,pos)sum+=ll[i];  
	if(L&(1LL<<pos)-1)sum++;
	return sum;
}
int main(){
	scanf("%d%lld",&n,&s);S=2e18;
	ref(i,1,n)scanf("%lld",&A[i]),S=min(S,A[i]);
	++m;ref(i,1,n)a[m].a[i]=A[i];a[m].s=s;
	ref(i,1,60){
		ref(j,1,n)b[j]=A[j]&((1LL<<i)-1);
		sort(b+1,b+n+1);b[0]=-1;b[n+1]=(1LL<<i)-1;
		ref(j,1,n+1)if(b[j]>b[j-1]){
			LL x=b[j-1]+1;if(S<x)continue;
			LL ss=s-i-count(x,min(S,b[j]));
			if(ss<0)continue;
			++m;ref(k,1,n)a[m].a[k]=(A[k]-x)>>i;a[m].s=ss;
		}
	}
	sort(a+1,a+m+1,cmp);
	int l=1,r=2;
	while(l<=m){
		while(r<=m){
			bool flag=1;
			ref(i,2,n)if(a[r].a[i]-a[r].a[1]!=a[l].a[i]-a[l].a[1])
				{flag=0;break;}
			if(!flag)break;++r;
		}
		LL _min=0,tmp=-1;
		ref(i,1,n)_min=min(_min,a[l].a[i]-a[l].a[1]);
		ref(i,l,r-1){
			LL R=a[i].a[1]+_min,L=max(0LL,R-a[i].s);
			if(R>tmp)(ans+=(R-max(L-1,tmp)))%=mod,tmp=R;
		}
		l=r;r=l+1;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 16640
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define m_k make_pair
using namespace std;
const int N=65;
int n,k,dp[N][N][N*50];
int a[N],r[N],b[N],sa[N],sr[N],sb[N];
bool cmp(int a,int b)
{
	return a>b;
}
signed main()
{
	scanf("%d%d",&n,&k);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	for (int i=1;i<=k;i++) scanf("%d",&r[i]);
	for (int i=1;i<=k;i++) scanf("%d",&b[i]);
	sort(a+1,a+1+n,cmp);
	sort(r+1,r+1+k,cmp);
	sort(b+1,b+1+k,cmp);
	for (int i=1;i<=n;i++) sa[i]=sa[i-1]+a[i];
	for (int i=1;i<=k;i++) sr[i]=sr[i-1]+r[i],sb[i]=sb[i-1]+b[i];
	memset(dp,-1,sizeof(dp));
	dp[0][0][0]=0;
	int ans=inf;
	for (int i=0;i<=k;i++)
	{
		for (int j=0;j<=min(k,n-i);j++)
		{
			for (int s=0;s<=sa[i+j];s++)
			{
				if (dp[i][j][s]==-1) continue;
				if (i+j==n && s<=sr[k] && sa[n]-s<=sb[k])
				  ans=min(ans,sa[n]-dp[i][j][s]);
				if (j<min(k,n-i))
				  dp[i][j+1][s]=max(dp[i][j+1][s],dp[i][j][s]+min(b[j+1],a[i+j+1]));
				if (i<k)
				  dp[i+1][j][s+a[i+j+1]]=max(dp[i+1][j][s+a[i+j+1]],dp[i][j][s]+min(r[i+1],a[i+j+1]));
			}
		}
	}
	if (ans==inf) printf("-1\n");
	else printf("%d\n",ans);
}



Measured memory_bytes: 56916
S = input()
 
N = len(S)
 
Ans = 1
 
for i in range(N):
  nTmp = (i+1) % 2
  
  if nTmp == 1 and S[i]=='L':
    Ans = 0
  if nTmp == 0 and S[i]=='R':
    Ans = 0
 
if Ans == 1:
  print('Yes')
else:
  print('No')


Measured memory_bytes: 3064
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <queue>
#include <queue>
#include <stack> 
#include <sstream>
#include <set>

typedef  long long ll;
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = { 0, 1, 0,-1};
const int INF = 1e9;
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
int guki (int a){
    if(a%2==0) return 0;
    else return 1;
}
int gcd(int a, int b){
    if(a%b==0){
        return b;
    }else{
        return (gcd(b,a%b));
    }
}
int lcm(int a, int b){
    int x = gcd(a,b);
    return (a*b/x);
}

using namespace std;
ll k (ll a){
    a--;
    ll ans =0;
    while(a != 0){
        ans += a;
        a--;
        
    }
    return ans;
}


int main(){
    int a,b;
    cin >> a >> b;
    if((0 < a && a < 10)&&(0<b && b < 10)){
            cout << a*b <<endl;
    }else{
        cout << -1 << endl;
    }
}



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

using namespace std;

//#define FILE_IO

int N;
char s[200005];
int nxt[200005][30];
int dp[200005], ch[200005];

int main()
{
    #ifdef FILE_IO
    freopen("1.in", "r", stdin);
    freopen("1.out", "w", stdout);
    #endif

    scanf("%s", s + 1);
    N = strlen(s + 1);

    for(int i = 0; i < 26; i++)
        nxt[N][i] = N + 1;

    for(int i = N - 1; i >= 0; i--)
    {
        for(int j = 0; j < 26; j++)
            nxt[i][j] = nxt[i + 1][j];
        nxt[i][ s[i + 1] - 'a' ] = i + 1;
    }

    for(int i = N; i >= 0; i--)
    {
        dp[i] = 1 << 30;
        for(int j = 0; j < 26; j++)
            if( dp[i] > dp[ nxt[i][j] ] + 1 )
            {
                dp[i] = dp[ nxt[i][j] ] + 1;
                ch[i] = j;
            }
    }


    for(int pos = 0; pos <= N; pos = nxt[pos][ ch[pos] ])
        printf("%c", ch[pos] + 'a');

    return 0;
}


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  set<char> st;
  char c;
  for(int i = 0; i < 3; ++i){
    cin >> c;
    st.insert(c);
  }
  if(st.size() > 1)cout << "Yes\n";
  else cout << "No\n";
  return 0;
}


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

int main(){
    int ans = 0;
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    
    if(a - k >= 0){
        ans = k;
    }else{
        if(b - (k - a) >= 0){
            ans = a;
        }else{
            ans = a - (k - a - b);
        }
    }
    put(ans);
}

Measured memory_bytes: 3596
<?php
list($K) = ints();
$sum6 = 0;
$sum1 = 0;
for($i = 1; $i <= $K; $i++)
for($j = 1; $j <= $K; $j++)
$memo[$i][$j] = $memo[$j][$i] = gcd($i, $j);

for($i = 1; $i <= $K; $i++)
for($j = $i+1; $j <= $K; $j++)
for($k = $j+1; $k <= $K; $k++)
    $sum6+=$memo[$memo[$i][$j]][$k];

for($i = 1; $i <= $K; $i++)
for($j = $i+1; $j <= $K; $j++)
    $sum6+=$memo[$i][$j];

for($i = 1; $i <= $K; $i++)
    $sum1+=$i;

echo $sum6*6+$sum1;


function str(){return trim(fgets(STDIN));}
function ints(){return array_map('intval',explode(' ',trim(fgets(STDIN))));}
function int(){return intval(trim(fgets(STDIN)));}
function chmax(&$a,$b){if($a<$b){$a=$b;return 1;}return 0;}
function chmin(&$a,$b){if($a>$b){$a=$b;return 1;}return 0;}
function popcount($x){$c=0;while($x){$x&=$x-1;++$c;}return$c;}
function o(...$val){
    if(count($val)==1)$val=array_shift($val);
    echo debug_backtrace()[0]['line'].")";
    if(is_array($val)){
        if(count($val) == 0)echo "empty array";
        elseif(!is_array(current($val)))echo "array: ",implode(" ", addIndex($val)),"\n";
        else{
            echo "array:array\n";
            if(isCleanArray($val))foreach($val as $row)echo implode(" ", addIndex($row)),"\n";
            else foreach($val as $i => $row)echo "[".$i."] ".implode(" ", addIndex($row)),"\n";
        }
    }else echo $val."\n";
}
function addIndex($val){if(!isCleanArray($val)){$val = array_map(function($k, $v){return $k.":".$v;}, array_keys($val), $val);}return $val;}
function isCleanArray($array){$clean=true;$i = 0;foreach($array as $k=>$v){if($k != $i++)$clean = false;}return $clean;}
// 座圧対象の配列 -> [圧縮された配列,復元用のMap,圧縮用のMap]
function atsu($array){$a = array_flip($array);$fuku=array_flip($a);sort($fuku);$atsu = array_flip($fuku);foreach($array as $i=>$val)$array[$i]=$atsu[$val];return [$array, $fuku, $atsu];}
function gcdAll($array){$gcd=$array[0];for($i=1,$I=count($array);$i<$I;++$i){$gcd=gcd($gcd,$array[$i]);}return $gcd;}
function gcd($m, $n){if(!$n)return $m;return gcd($n, $m % $n);}
function lcmAll($array){$lcm=$array[0];for($i=1,$I=count($array);$i<$I;++$i){$lcm=lcm($lcm,$array[$i]);}return $lcm;}
function lcm($a, $b) {return $a / gcd($a, $b) * $b;}

function dfs($current, $from = -1, $d = 0){
  global $G, $distance;
  $distance[$current] = $d;
  foreach($G[$current] as $to){
    if($from != $to){
      dfs($to, $current, $d + 1);
    }
  }
}

function loadTree($N = false){
  if($N === false)$N = $GLOBALS['N'];
  return loadGraph($N, $N-1);
}
function loadGraph($N = false, $M = false, $both = true){
  if($N === false)$N = $GLOBALS['N'];
  if($M === false)$N = $GLOBALS['M'];
  $G = array_fill(1, $N, []);
  for($i = 0; $i < $M; $i++){
    $values = ints();
    if(count($values) == 2){
      list($a, $b) = $values;
      $G[$a][] = $b;
      if($both)$G[$b][] = $a;
    }else{
      list($a, $b, $d) = $values;
      $G[$a][] = [$b, $d];
      if($both)$G[$b][] = [$a, $d];
    }
  }
  return $G;
}


Measured memory_bytes: 18792
//2006C 六角沼
#include<iostream>
#include<cstdlib>
#include<set>
#include<queue>
using namespace std;
int vx[]={ 1, 1, 0, 0,-1,-1};
int vy[]={ 0,-1, 1,-1, 1, 0};
struct P{
	int x,y;
};
int n,k;
struct Snake{
	int step;
	P body[8];
	bool operator<(const Snake&b)const{
		for(int i=0;i<n;i++){
			if(body[i].x!=b.body[i].x)return body[i].x<b.body[i].x;
			if(body[i].y!=b.body[i].y)return body[i].y<b.body[i].y;
		}
		return false;
	}
	P& operator[](int i){
		return body[i];
	}
};
queue<Snake> que;
int X,Y;
int ans;
P rock[100];
Snake body;
set<Snake> s;
int distance(){
	int dis, dx=X-body[0].x, dy=Y-body[0].y;
	if(dx*dy<0)dis= abs(dx)<abs(dy)? abs(dy):abs(dx);
	else dis= abs(dx)+abs(dy);
	return dis;
}
inline bool overlap(P &a,P &b){
	return a.x==b.x && a.y==b.y;
}
bool neibor(P &a,P &b){
	int dx=a.x-b.x;
	int dy=a.y-b.y;
	return abs(dx)+abs(dy)<=1
		|| abs(dx)==1 && -dx==dy;
}
bool is_dead(int no){
	for(int i=0;i<no-1;i++){
		if(neibor(body[no], body[i])){
				return true;
		}
	}
	return false;
}
bool on_rock(int no){
	for(int i=0;i<k;i++){
		if(rock[i].x==body[no].x && rock[i].y==body[no].y)
			return true;
	}
	return false;
}

bool move(int no){
	if(no==1||no==2)if(ans-body.step <= distance())return false;
	for(int i=0;i<6;i++){
		body[no].x+=vx[i];
		body[no].y+=vy[i];
		if(!is_dead(no) && !on_rock(no) 
			&& (no==0  ||neibor(body[no-1],body[no]) && !overlap(body[no-1],body[no]))
			&& (n<=no+1||neibor(body[no],body[no+1]) && !overlap(body[no],body[no+1])) ){
			if(no+2<n){if(move(no+2))return true;}
			else {
				if(X==body[0].x && Y==body[0].y)return true;
				body.step++;
				if(s.find(body)==s.end()){
					s.insert(body);
					que.push(body);
				}
				body.step--;
			}
		}
		body[no].x-=vx[i];
		body[no].y-=vy[i];
	}
	if(!is_dead(no) ){
		if(no+1<n){if(move(no+1))return true;}
		else {
			if(X==body[0].x && Y==body[0].y)return true;
			body.step++;
			if(s.find(body)==s.end()){
				s.insert(body);
				que.push(body);
			}
			body.step--;
		}
	}
	return false;
}
main(){
	while(cin>>n,n){
		s.clear();
		while(!que.empty())que.pop();
		body.step=0;
		for(int i=0;i<n;i++){
			cin>>body[i].x>>body[i].y;
			
		}
		cin>>k;
		for(int i=0;i<k;i++){
			cin>>rock[i].x>>rock[i].y;	
		}
		cin>>X>>Y;
		ans=20;
		que.push(body);
		while(!que.empty()){
			body=que.front();
			que.pop();
			if(ans-body.step <= distance())continue;
			if(body.step==20-1)break;
			if(move(0)){
				ans= body.step+1;
				break;
			}
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 8468
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
const int N=1e5+3,inf=0x7fffffff;
int cnt,n,a[N],maxx,fail,minn=inf;
inline int read(){
	int num=0,flag=1;
	char c=getchar();
	for(;c<'0'||c>'9';c=getchar())
	if(c=='-') flag=-1;
	for(;c>='0'&&c<='9';c=getchar())
	num=(num<<3)+(num<<1)+c-48;
	return num*flag;
}
int main(){
	n=read();
	for(int i = 1;i<=n;i++){
		a[i]=read();
		if(a[i]>maxx) maxx=a[i],fail=i;
	}
	a[fail]=0;
	int mid=maxx/2;
	int k;
	for(int i = 1;i<=n;i++){
		k=abs(a[i]-mid);
		if(k<minn){
			minn=k;
			cnt=a[i];
		}
	}
	printf("%d %d",maxx,cnt);
	return 0;
}

Measured memory_bytes: 640
from statistics import median

n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]

a = [ab[i][0] for i in range(n)]
b = [ab[i][1] for i in range(n)]

if n % 2 == 0:
    ma, mb = median(a), median(b)
    print(int(2 * mb - 2 * ma + 1))
if n % 2 == 1:
    ma, mb = median(a), median(b)
    print(int(mb - ma + 1))




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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int h, a; cin >> h >> a;
    int cnt = 0;
    while (h > 0) h -= a, cnt++;
    cout << cnt << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define INT_INF (2 * 1e9)
#define LL_INF  (2LL * 1e18)
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#ifdef __LOCAL
#define DBG(X) cout << #X << "=" << (X) << endl;
#else
#define DBG(X)
#endif
 
using namespace std;
 
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll mod = 1e9 + 7;

#define ll ull

vector<ll> a;

ll f(ll val)
{
	ll ret = 0;

	for(auto el: a)
		ret += (el ^ val);

	return ret;
}

void solve()
{
	int n;
    ll k;
	cin >> n >> k;

	a.resize(n);

	for(auto& el: a)
		cin >> el;

	ll best = 0;

	for(ll msk = 1; msk <= k; msk <<= 1LL)
		if(f(msk) > f(0))
			best |= msk;

	if(best <= k)
	{
		cout << f(best) << endl;

		return;
	}

	ll ans = k;

	for(ll msk = 1LL; msk <= k; msk <<= 1LL)
	{
		if((k & msk) == 0)
			continue;

		ll nans = ((k ^ msk) & ~(msk - 1LL)) | (best & (msk - 1LL));

		if(nans <= k)
		{
			if(f(nans) > f(ans))
				ans = nans;
		}
	}

	cout << f(ans) << endl;
}

int main(int argc, char** argv)
{
	FAST_IO;
	solve();

	return 0;
}


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

int main()
{
    int N, K, ans = 1;
    cin >> N >> K;
    REP(i, N) ans = min(ans * 2, ans + K);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.lang.*;

public class Main{
	static long mod = 1000000007;
	static long[] fac;
	static long[] finv;
	static long[] inv;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		TreeMap<Integer, Integer> map = new TreeMap<>();
		for (int i = 2; i <= m; i++) {
			int count = 0;
			while (m % i == 0) {
				m /= i;
				count++;
			}
			if (count > 0) {
				map.put(i, count);
			}
		}
		COMinit(n + 33);
		long ans = 1;
		for (int key : map.keySet()) {
			ans *= COM(map.get(key) + n - 1, map.get(key));
			ans %= mod;
		}
		System.out.println(ans);
	}

	static void COMinit(int n) {
		fac = new long[n];
		finv = new long[n];
		inv = new long[n];
		fac[0] = 1;
		fac[1] = 1;
		finv[0] = 1;
		finv[1] = 1;
		inv[1] = 1;
		for (int i = 2; i < n; i++) {
			fac[i] = fac[i - 1] * i % mod;
			inv[i] = mod - inv[(int) (mod % i)] * (mod / i) % mod;
			finv[i] = finv[i - 1] * inv[i] % mod;
		}
	}
	static long COM(int n, int k) {
		if (n < k || (n < 0 || k < 0)) {
			return 0;
		}
		return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
	}

}


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

using namespace std;

int N, x, sol;
stack < int > st;

int main() {
    ios_base::sync_with_stdio(false);
    cin >> N >> x;
    
    if (x >= N) {
        cout << 0 << '\n';
    } else {
        cout << N - x << '\n';
    }
    
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

  int ans = [&N]() {
              if (N < 10) {
                return N;
              } else if (N < 100) {
                return 9;
              } else if (N < 1000) {
                return N - 90;
              } else if (N < 10000) {
                return 909;
              } else if (N < 100000) {
                return N - 9090;
              } else {
                return 90909;
              }
            }();
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin,(obj).end()
#define SORT(list) sort(ALL((list)));
using namespace std;
using ll = long long;
int main(){
    int c[3][3];
    REP(i,3)REP(j,3)cin >> c[i][j];
    if(c[0][0]-c[0][1] == c[1][0]-c[1][1] && c[2][0]-c[2][1] == c[1][0]-c[1][1] && c[0][1]-c[0][2] == c[1][1]-c[1][2] && c[1][1] - c[1][2] == c[2][1]-c[2][2]){
        if(c[0][0]-c[1][0] == c[0][1]-c[1][1] && c[0][2] -c[1][2] == c[0][1] -c[1][1]&& c[1][0]-c[2][0] == c[1][1]-c[2][1] && c[1][1]-c[2][1] == c[1][2] -c[2][2]){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque, defaultdict
#deque(l), pop(), append(x), popleft(), appendleft(x)
#q.rotate(n)で → にn回ローテート
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import reduce,lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printe(*x):print("## ",*x,file=sys.stderr)
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    #N = int(input())
    #N, K = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    s=input()
    dp=[0]*(len(s)+1)
    dp[0]=1
    for i in range(5,len(s)+1):
        f=0
        if s[i-5:i]=="erase":
            dp[i]=dp[i]|dp[i-5]
        if s[i-5:i]=="dream":
            dp[i]=dp[i]|dp[i-5]
        if i>=6 and s[i-6:i]=="eraser":
            dp[i]=dp[i]|dp[i-6]
        if i>=7 and s[i-7:i]=="dreamer":
            dp[i]=dp[i]|dp[i-7]

    if dp[-1]:
        print('YES')
    else:print('NO')





if __name__ == "__main__":
    main()

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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  int N;
  cin >> N;
  vector<int> A(N);

  int alice = 0;
  int bob = 0;
  REP(i, N) { cin >> A.at(i); }

  sort(A.begin(), A.end(), greater<int>());

  REP(i, N) {
    if (i % 2 == 0) {
      alice += A.at(i);
    } else {
      bob += A.at(i);
    }
  }
  cout << alice - bob << endl;

  return 0;
}


Measured memory_bytes: 256
class Dice

  def initialize(dice)
    @top  = dice[0]
    @side   = [ dice[2], dice[1], dice[3], dice[4] ]
    @bottom = dice[5]
  end

  def roll(action)
    b = @bottom
    u = @top
    case action
    when "N"
      @top   = @side[2]
      @bottom  = @side[0]
      @side[2] = b
      @side[0] = u
    when "E"
      @top   = @side[3]
      @bottom  = @side[1]
      @side[3] = b
      @side[1] = u
    when "S"
      @top   = @side[0]
      @bottom  = @side[2]
      @side[0] = b
      @side[2] = u
    when "W"
      @top   = @side[1]
      @bottom  = @side[3]
      @side[1] = b
      @side[3] = u
    end
  end

  def top
    @top
  end

  def bottom
    @bottom
  end

  def north
    @side[0]
  end

  def east
    @side[1]
  end

  def south
    @side[2]
  end

  def west
    @side[3]
  end

  def all_num
    [@top, @bottom, @side[2], @side[1], @side[3], @side[4]]
  end
end

d = Dice.new(gets.split.map(&:to_i))
sub = Dice.new(gets.split.map(&:to_i))

i = 0
catch(:exit) do
  while true
    if d.south == sub.south
      4.times do
        if d.all_num == sub.all_num
          puts "Yes"
          throw :exit
        end
        d.roll("E")
      end
    end
    if i > 6
      puts "No"
      break
    elsif i == 3
      d.roll("E")
      d.roll("N")
    else
      d.roll("N")
    end
    i += 1
  end
end

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

class Dice{
public:
    int a[6];
    void roll_z(){ roll(1, 2, 4, 3);}
    void roll_y(){ roll(0, 2, 5, 3);}
    void roll_x(){ roll(0, 1, 5, 4);}
    void roll(int i, int j, int k, int l){
        int tmp=a[i];
        a[i]=a[j];
        a[j]=a[k];
        a[k]=a[l];
        a[l]=tmp;
    }
};

bool eq(Dice d1, Dice d2){
    for (int i=0; i<6; i++){
        if(d1.a[i]!=d2.a[i]) return false;
    }
    return true;
}

bool equal(Dice d1, Dice d2){
    for(int i=0; i<6; i++){
        for(int j=0; j<4; j++){
            if(eq(d1, d2)) {
                return true;
            }
            d1.roll_z();
        }
        if(i%2==0) {
            d1.roll_y();
        } else {
            d1.roll_x();
        }
    }
    return false;
}

int main(){
    Dice d1, d2;
    
    for(int i=0; i<6; i++) {
        cin >> d1.a[i];
    }
    for(int i=0; i<6; i++){
        cin >> d2.a[i];
    }
    
    if(equal(d1,d2)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3116
import numpy as	np
n =int(input())
d = np.zeros((n,2))
for i in range(n):
    s_list =	str(input()).split()
    d[i, 0], d[i, 1] = s_list[0], s_list[1]
count = 0
sum = 0
for i in range(n):
    for	j in range(n):
        if i < j:
            sum	+= np.linalg.norm(d[i]-d[j])
            count += 1
print(sum / count * (n-1))

Measured memory_bytes: 12504
#include<stdio.h>
int main(){

    int a[3],b,c,t,d,s,p,tmp,i,j;
    scanf("%d%d%d",&a[0],&a[1],&a[2]);
    for(i=0;i<3;i++){
        for(j=i+1;j<3;j++){
                if(a[i]<a[j]){
                    tmp=a[i];
                    a[i]=a[j];
                    a[j]=tmp;
                }

        }
    }
    s=a[0]-a[1];
    p=a[1]-a[2];
    t=s+p;
    printf("%d\n",t);
    return 0;

}


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

#define ll long long
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define vll vector<ll>
#define pll pair<ll , ll>
#define vpll vector<pair<ll, ll> >
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define N 100001
#define HOLE 1000000007

ll fn(ll x,ll rn[])
{
    if(rn[x]==x) return x;
    else return rn[x]=fn(rn[x],rn);
}

void un(ll x,ll y,ll rn[],ll sz[])
{
    x=fn(x,rn);
    y=fn(y,rn);
    if(x==y) return;
    if(sz[x]<sz[y]) swap(x,y);
    sz[x]+=sz[y];
    rn[y]=x;
    return;
}

ll power(ll x,ll y)
{
    ll res = 1; // Initialize result

    while (y > 0) {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res * x)%HOLE;

        // n must be even now
        y = y >> 1; // y = y/2
        x = (x * x)%HOLE; // Change x to x^2
    }
    return res;
}

vector <ll> adjl[N];
ll marked[N]={0};
vector <ll> order;

void dfs (ll x){

    if(marked[x])
        return;
    marked[x]=1;

    REP(i,0,adjl[x].size()){

    }

    return;
}

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

    ll q=1;
    //cin>>q;
    while(q--){

        ll n,x,y;
        cin>>n>>x>>y;

        ll dist[n+1]={0};

        int flag=0;

        REP(i,1,n+1){
            REP(j,i+1,n+1){
                if(j<=x || i>=y){
                    dist[j-i]++;
                }

                else if(i<=x && j>=y){
                    dist[j-i-(y-x-1)]++;
                }
                else {

                    dist[min((j-i),( abs(x-i)+1+abs(y-j) ))]++;

                }

            }
        }

        REP(i,1,n){
            cout<<dist[i]<<endl;
        }

    }

return 0;
}


Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
using ll= long long;
using vi= vector<int>;
using vvi= vector<vi>;
using vd= vector<double>;
using vvd= vector<vd>;
using vc= vector<char>;
using vb= vector<bool>;
using vl= vector<ll>;
#define rep(i,x,n) for(int i=x; i<n; i++)
#define all(x) x.begin(), x.end()

int main(){
  int n,ans=INT_MAX,t;
  cin >> n;
  vi x(n);
  rep(i,0,n){
    cin >> x[i];
  }
  for(int i=1; i<=100; i++){
    t=0;
    for(int j=0; j<n; j++){
      t+= (x[j]-i)*(x[j]-i);
    }
    ans= min(t,ans);
  }
  cout << ans << endl;;
  return 0;
}


Measured memory_bytes: 384
import math
n = int(input())
outlist = [0 for i in range(n+1)]

def isprime(n):
  for i in range(2, int(math.sqrt(n)+1)):
    if n%i == 0:
      return (0)
      break
  return (1)
    
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
 
    if temp!=1:
        arr.append([temp, 1])
 
    if arr==[]:
        arr.append([n, 1])
 
    return arr 

for i in range(2,n+1):
  L = factorization(i)
  for j in range(len(L)):
    if isprime(L[j][0]) == 1:
      outlist[L[j][0]] += L[j][1]

out = 1
for i in range(len(outlist)):
  out = out * (outlist[i]+1)
print(out % (pow(10,9)+7))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	int k;
	cin>>s>>k;
	vector<string>v;
	for(int i=0;i<s.size();i++)
		for(int j=1;j<=k&&i+j<=s.size();j++)
			v.push_back(s.substr(i,j));
	sort(v.begin(),v.end());
	v.erase(unique(v.begin(),v.end()),v.end());
	cout<<v[k-1]<<endl;
}


Measured memory_bytes: 1660
#include<iostream>
using namespace std;
int main()
{
	int n,k,d,e,tot=0;
	bool s[1005]={0};
	cin>>n>>k;
	for(int i=1;i<=k;i++)
	{
		cin>>d;
		for(int j=1;j<=d;j++)
		{
			cin>>e;
			s[e]=true;
		}
	}
	for(int i=1;i<=n;i++)
	{
		if(s[i]==false)
		{
			tot++;
		}
	}
	cout<<tot;
	return 0;
}

Measured memory_bytes: 3596
#include<numeric>
#include<iostream>
#include<cstring>
#include<vector>
#include<algorithm>
#include<math.h>
using namespace std;

typedef long long ll;

ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}

vector<pair<ll,int>>factorize(ll n){
	vector<pair<ll,int>> res;
	for(ll i=2;i*i<=n;i++){
		if(n%i)continue;
		res.emplace_back(i,0);
		while(n%i==0){
			n/=i;
			res.back().second++;
		}
	}
	if(n!=1)res.emplace_back(n,1);
	return res;
}

int main(){
	ll a,b;
	cin>>a>>b;
	ll g=gcd(a,b);
	auto f=factorize(g);
	int ans=f.size()+1;
	cout<<ans<<endl;
}

Measured memory_bytes: 256
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

#累積和
sa = [0]
sb = [0]
for i in range(n):
    sa.append(sa[i]+a[i])
for i in range(m):
    sb.append(sb[i]+b[i])

#片方全部見ていくともう片方が簡単に求まる
ans = 0
for i in range(n+1):
    if sa[i] > k:
        break
    while sb[m] > k - sa[i]:
        m -= 1
    ans = max(ans,i+m)
print(ans)


Measured memory_bytes: 47348
A,B,C,D,E,F=map(int, input().split())
cnt_A=0
cnt_B=0
cnt_C=0
cnt_D=0
max_noudo=0
water=A*100
sugar=0
while cnt_A*100*A <= F:
  cnt_B=0
  while cnt_B*100*B <= F-cnt_A*100*A:
    cnt_C=0
    while cnt_C*C <= F-cnt_A*100*A-cnt_B*100*B:
      cnt_D=0
      while cnt_D*D <= F-cnt_A*100*A-cnt_B*100*B-cnt_C*C:
        if (cnt_A*A+cnt_B*B)*E >= cnt_C*C+cnt_D*D >0:
          if max_noudo < 100*(cnt_C*C+cnt_D*D)/(cnt_A*A+cnt_B*B):
            max_noudo = 100*(cnt_C*C+cnt_D*D)/(cnt_A*A+cnt_B*B)
            water=cnt_A*A*100+cnt_B*B*100+cnt_C*C+cnt_D*D
            sugar=cnt_C*C+cnt_D*D
        cnt_D+=1
      cnt_C+=1
    cnt_B+=1
  cnt_A+=1
 
print(water,sugar)

Measured memory_bytes: 3064
n = int(input())
alp = 'abcdefghijklmnopqrstuvwxyz'
ans = []
while n > 0:
  n -= 1
  x = n%26
  ans.append(x)
  n //= 26
ans.reverse()

a = ''
for i in ans:
  b = alp[i]
  a += b
print (a)

Measured memory_bytes: 9116
#include <stdio.h>
#define M 100000
#define N 50000
#define NOT_FOUND -1

int cnt=0,n;

int binarysearch(int x[],int key)
{
  int left=0,right=n,mid;

  while(left<right)
    {
      mid=(left+right)/2;
      if(x[mid]==key)return mid;
      else if(key<x[mid])right=mid;
      else left=mid+1;
    }
  return NOT_FOUND;
}

    
int main(){
  int y[M],z[N],i,j;
  
  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&y[i]);

   scanf("%d",&j);
   for(i=0;i<j;i++){
    scanf("%d",&z[i]);
   }
   for(i=0;i<j;i++)
     if(binarysearch(y,z[i])!=NOT_FOUND)cnt++;

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


  
    
    
  



Measured memory_bytes: 2320
#include <iostream>
#include <algorithm>
#include <vector>
#include <bitset>

using namespace std;

int main(){
  long long N, D;
  long long grundy = 0;

  cin >> N >> D;
  for(int i=0;i<N;i++){
    long long a;    
    cin >> a;
    grundy ^= ((a-1) % (D+1));
    //    cout << ((a-1) % (D+1)) << " " << bitset<8>(((a-1) % (D+1))) << endl;
  }
  if(grundy){
    cout << "First" << endl;
  }else{
    cout << "Second" << endl;
  }
  return 0;
}



Measured memory_bytes: 3076
import java.util.*;
class  Main{
    public static void main(String[] args){
	Scanner stdIn=new Scanner(System.in);
	int A = stdIn.nextInt();
	int B = stdIn.nextInt();
	int C = stdIn.nextInt();
        int max=Math.max(A,Math.max(B,C));
	int o =A+B+C-max;
	System.out.println(max*10+o);
    }
}

Measured memory_bytes: 21588
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,cnt[100000]={},a;
  long long mod=1e9+7;
  cin>>n;
  for(int i=0;i<n;i++)cin>>a,cnt[(n-a)/2]++;
  int f=0;
  for(int i=0;i<n/2;i++)if(cnt[i]!=2)f=1;
  if(n%2==1&&cnt[n/2]!=1)f=1;
  long long ans=1;
  for(int i=0;i<n/2;i++){
    ans*=2;
    ans%=mod;
  }
  cout<<(f?0:ans)<<endl;
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
  ll N,K,X,Y;
  cin>>N;
  cin>>K;
  cin>>X;
  cin>>Y;
  if(N<=K) cout<<X*N<<endl;
  else cout<<(X*K)+((N-K)*Y)<<endl;
  return 0;
}
	

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

int n;
int a[40002], b[40002];
int idx[40002];

void show(){
  for(int i = 0; i < n; i++){
    printf("%3d", a[i]);
  }
  cout << endl;

  for(int i = 0; i < n; i++){
    printf("%3d", b[i]);
  }
  cout << endl;

  for(int i = 0; i < n; i++){
    printf("%3d", idx[i]);
  }
  cout << endl;
}

void solve(){
  memset(idx, -1, sizeof(idx));

  int ai = 0;
  int bi = 0;

  while(ai < n && bi < n){
    if(b[bi] >= a[ai]){
      idx[bi] = ai;
      bi++;
    }
    ai++;
  }

  int bwin = 0;
  bi = 0;

  for(int i = 0; i < n - 1; i++){
    if(idx[bi] == i){
      bwin++;
      bi++;
    }

    int k = i + 1;

    if(k / 2 + 1 <= k - bwin){
      cout << k << endl;
      return;
    }
  }

  cout << "NA" << endl;
}

int main(){
  while(cin >> n, n){
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < n; i++) cin >> b[i];
    sort(a, a + n, greater<int>());
    sort(b, b + n, greater<int>());
    solve();
  }
}

Measured memory_bytes: 1652
def main():
  a = []
  n = int(input())
  print((n/3)**3)

  
def count_section_by_zero(data):
  count = 0
  flg = False
  start = 0
  for i, d in enumerate(data):
    if flg is False and d != 0:
      count += 1
      flg = True
      
    if d == 0:
      flg = False
  return count

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def input_list():
  return list(map(int, input().split()))

def input_list_str():
  return map(str, input().split())

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

# 2で割り切れる回数
def divide_two(arg):
  c = 0
  while True:
    if c >= 2:
      break
    if arg % 2 != 0:
      break
    arg //= 2
    c += 1
  return c

# 素因数分解
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

import math
import fractions
import collections
from functools import reduce
main()

Measured memory_bytes: 5048
import sys
from heapq import*
r=sys.stdin.readline
def g(n,E,S,G):
 F=[1e7]*-~n;F[S]=0
 H=[(0,S)]
 while H:
  c,u=heappop(H)
  if u==G:return c
  for f,v in E[u]:
   t=c+f
   if t<F[v]:
    F[v]=t
    heappush(H,(t,v))
 return-1
def s():
 for e in iter(r,'0 0\n'):
  n,k=map(int,e.split())
  E=[[]for _ in[0]*-~n]
  for _ in[0]*k:
   f=r()
   if'0'==f[0]:print(g(n,E,*map(int,f[2:].split())))
   else:
    c,d,e=map(int,f[2:].split())
    E[c]+=[(e,d)];E[d]+=[(e,c)]
if'__main__'==__name__:s()


Measured memory_bytes: 6304
#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;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n,k; cin>>n>>k;
	set<int> a;
	for(int i=k;i<k+n;i++) a.insert(i);
	vector<vi> V;
	int cur = (k+3*n-1)-(k+2*n-1);
	auto it = (a.upper_bound(cur));
	if(it==a.begin())
	{
		cout<<-1<<'\n'; return 0;
	}
	it--;
	int st = (*it);
	//st + (k+2*n-1), st-1 + (k+2*n-2), ...
	vector<pair<int,ii> > VV;
	for(int i=k+2*n-1;i>=k+n;i--)
	{
		if(st>=k)
		{
			//V.pb({st,i,i+n});
			VV.pb({st+i,{st,i}});
			st--;
		}
		else
		{
			st=k+n-1;
			VV.pb({st+i,{st,i}});
			//V.pb({st,i,i+n});
			st--;
		}
	}
	sort(VV.rbegin(),VV.rend());
	/*
	for(auto x:VV)
	{
		cerr<<x.se.fi<<' '<<x.se.se<<'\n';
	}
	*/
	for(int i=0;i<n;i++)
	{
		V.pb({VV[i].se.fi,VV[i].se.se,k+3*n-1-i});
	}
	for(int i=0;i<V.size();i++)
	{
		sort(V[i].begin(),V[i].end());
		if(V[i][0]+V[i][1]>V[i][2]){cout<<-1<<'\n'; return 0;}
	}
	for(int i=0;i<V.size();i++)
	{
		cout<<V[i][0]<<' '<<V[i][1]<<' '<<V[i][2]<<'\n';
	}
}	


Measured memory_bytes: 13936
#include<iostream>
#include<algorithm>
#include<set>
#include<string>
#include<cstring>
using namespace std;

int main()
{
	int n, m;
	int a[31] = { 0 };
	int cnt = 0;
	cin >> n >> m;
	cin.ignore();
	for (int i = 0; i < n; i++) {
		int k;
		cin >> k;
		for (int j = 0; j < k; j++) {
			int t;
			cin >> t;
			a[t]++;
		}
	}
	for(int i=1;i<=m;i++)
		if(a[i]==n)
			cnt++;
	cout << cnt << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		new Main().solve(new Scanner(System.in));
	}
	
	public void solve(Scanner sc) {
		int n = Integer.parseInt(sc.next());
		
		if(n % 7 == 0 || n % 4 == 0) {
			System.out.println("Yes");
			return;
		}
		
		for(int i=0; i*7 <= n; i++) {
			for(int j=0; j*4+i*7 <= n; j++) {
				if(j*4+i*7==n) {
					System.out.println("Yes");
					return;
				}
			}
		}
		System.out.println("No");
	}
}


Measured memory_bytes: 21716
import numpy as np
ans = 10 ** 7
n, m, x = map(int, input().split())
L = [0] * n
for i in range(n):
    L[i] = list(map(int,input().split()))

for i in range(2 ** n):
    list_0 = [0] * n
    for j in range(n):
        if ((i >> j) & 1):
            list_0[n - 1 - j] = 1
    Li = np.array([0] * m)
    tmp = 0
    for k in range(n):
        if list_0[k] == 1:
            tmp += L[k][0]
            Li += np.array(list(L[k][1:]))
    if (Li >= x).all():
        ans = min(ans, tmp)
print(ans if ans != 10 ** 7 else -1)

Measured memory_bytes: 27284
#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
 
#define int long long int
#define ld long double
#define mod 1000000007 
#define pii pair<int,int>
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define forn(i,s, e) for (int i = s; i <= e; i++)
#define fornd(i,s, e) for (int i = s ; i >= e; i--)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define print(x) for(auto el: x) cout<<el<<" ";cout<<"\n"
#define PSET(x,y) fixed<<setprecision(y)<<x
// #define bits(x) __builtin_popcount(x)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)


 
template <typename T> 
void swap(T& a, T& b){
    T temp = a;
    a = b;
    b = temp;
}

const int N = 100005; 

bool dp[101][N];
bool visi[101][N];
vector<int> a;
int mini, n;

bool rec(int v, int k ){

    // if(k<0)
    //     return true;
    if(k<mini)
        return false;
    if(visi[v][k])
        return dp[v][k];

    visi[v][k] = true;
    if(k-a[v] < 0)
        return dp[v][k] = false;
    
    bool ans = false;    
    for(int i=0;i<n;i++){
        ans = ans || rec(i,k-a[v]);
    }
    return dp[v][k] = !ans;

}

void solve(){
    int k;
    cin>>n>>k;
    a.assign(n,0);

    forn(i,0,n-1)
        cin>>a[i];

    sort(all(a));
    mini = a[0];

    memset(dp,false,sizeof(dp));
    memset(visi,false,sizeof(visi));

    for(int i=0;i<n;i++){
        if(rec(i,k)){
            cout<<"First";
            return;
        }
    }
    cout<<"Second";
    return;




}
 
int32_t main()
{
    fast;
    // int t;
    // cin>>t;
    // for(int y=1;y<=t;y++)
    {
        // cout<<"Case #"<<y<<": ";
        solve();
    }
    return 0;
} 

Measured memory_bytes: 24704
from collections import Counter
from functools import reduce
# import statistics
import bisect
import copy
import fractions
import math
import pprint
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
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 LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers):
    return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers):
    return reduce(LCM, numbers)
def LCM(m, n):
    return (m * n // fractions.gcd(m, n))
def unite(x, y):
    # それぞれのノードの根を求める
    x = root(x)
    y = root(y)
    if x == y:
        return
    # node[x]の根をyに変更する
    node[x] = y
def same(x,y): return bool(root(x) == root(y))
def root(x):
    if node[x] == x:  # xが根の場合
        return x
    else:
        node[x] = root(node[x])  # 経路圧縮
        return node[x]
def dfs(v,depth):
    # ノードに訪れた
    visited[v] = 1
    if depth == 2:
        return
    for a, b in sides:
        if v == a-1:
            depth += 1
            dfs(b-1, depth)
            depth -= 1

n, m = MI()
a, b = set(), set()
for i in range(m):
    x, y = MI()
    if x == 1:
        a.add(y)
    if y == n:
        b.add(x)

print("POSSIBLE" if a&b else "IMPOSSIBLE")


Measured memory_bytes: 21360
// #pragma GCC optimize("unroll-loops", "omit-frame-pointer", "inline")
// #pragma GCC option("arch=native", "tune=native", "no-zero-upper")
// #pragma GCC
// target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("tree-vectorize","openmp","predictive-commoning")
// #pragma GCC option("D_GLIBCXX_PARALLEL","openmp")

// #pragma GCC optimize("O3")
// #pragma GCC target("avx2")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
// #define int long long
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000               // 2e9
#define LLINF 2000000000000000000ll  // 2e18 (llmax:9e18)
#define fi first
#define sec second
#define all(x) (x).begin(), (x).end()
#define sq(x) ((x) * (x))
#define dmp(x) cerr << #x << ": " << x << endl;

template <class T>
void chmin(T &a, const T &b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T &a, const T &b) {
  if (a < b) a = b;
}

template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
vector<T> vect(int len, T elem) {
  return vector<T>(len, elem);
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.fi << ',' << p.sec;
  return os;
}
template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.fi >> p.sec;
  return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i];
    if (i + 1 < vec.size()) os << ' ';
  }
  return os;
}
template <class T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) is >> vec[i];
  return is;
}
void fastio() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
}

#define endl "\n"

void solve() {
  ll N, X, M;
  cin >> N >> X >> M;
  ll cur = X;
  vector<bool> used(M, false);
  vector<ll> vec;
  ll sum = 0ll;
  for (int i = 0; i < M; i++) {
    if (used[cur]) break;
    used[cur] = true;
    sum += cur;
    vec.push_back(cur);
    cur = (cur * cur) % M;
  }
  ll ans = 0ll;
  if (N <= vec.size()) {
    for (int i = 0; i < N; i++) ans += vec[i];
    cout << ans << endl;
    return;
  }
  int bi = -1;
  for (int i = 0; i < vec.size(); i++) {
    if (vec[i] == cur) {
      bi = i;
      break;
    }
    sum -= vec[i];
    ans += vec[i];
    N--;
  }
  // dmp(bi);
  // dmp(N);
  // dmp(sum);
  // dmp(vec.size());
  ll loop = vec.size() - bi;
  ans += N / loop * sum;
  for (int i = 0; i < N % loop; i++) { ans += vec[bi + i]; }
  cout << ans << endl;
  return;
}

signed main() {
  fastio();
  solve();
  // int t; cin >> t; while(t--)solve();

  // int t; cin >> t;
  // for(int i=1;i<=t;i++){
  //   cout << "Case #" << i << ": ";
  //   solve();
  // }
  return 0;
}


Measured memory_bytes: 3880
import java.util.*;
import java.io.*;
import java.lang.*;
import java.math.*;
public class Main{
	public static void main(String[] args) throws IOException{
		Scanner stdIn=new Scanner(System.in);
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		while(true){
			int h=stdIn.nextInt();
			int w=stdIn.nextInt();
			if(h==0)
				break;
			for(int i=0;i<h;i++){
				if(i%2==0){
					for(int j=0;j<w;j++){
						if(j%2==0)
							System.out.print("#");
						else
							System.out.print(".");
					}
				}
				else{
					for(int j=0;j<w;j++){
						if(j%2==1)
							System.out.print("#");
						else
							System.out.print(".");
					}
					
				}
				System.out.println("");
			}
			System.out.println("");
		}
	}
}

Measured memory_bytes: 35360