akhauriyash/Code-Regression huggingface dataset:
while True:
    n=int(input())
    if n==0:
        break
    
    ts=[0]*n
    ys=0
    a=[]
    for i in range(n):
        b=list(map(int,input().split()))
        s=sum(b)
        a.append(b+[s])
        for i in range(n):
            ts[i]+=b[i]
        ys+=s
    t=sum(ts)
    for i in range(n):
        for j in range(n+1):
            print(str(a[i][j]).rjust(5),end='')
        print()

    for i in range(n):
        print(str(ts[i]).rjust(5),end='')
    print(str(t).rjust(5))


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

using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VS = vector<string>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VL = vector<long long>;
using VVL = vector<VL>;

#define sz(var) (int)var.size()
#define REP(var, start, end) for(int var = start; var < (int)end; ++var)
#define CLEAR(var, with) memset(var, with, sizeof(var))
#define LL long long
#define ULL unsigned long long

int n;
VI A;
LL numoperations(int delta)
{
    LL ret = 0, sum = 0;
    REP(i, 0, n)
    {
        sum += A[i];

        if(delta < 0 && sum >= 0){
            ret += abs(-1 - sum);
            sum = -1;
        }
        else if(delta > 0 && sum <= 0){
            ret += 1 - sum;
            sum = 1;
        }
        delta *= -1;
    }
    return ret;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
#ifndef ONLINE_JUDGE
	//freopen("tmp.in", "r", stdin);
//	freopen("tmp.out", "w", stderr);
#endif
    cin >> n;

    A = VI(n); 
    REP(i, 0, n)
        cin >> A[i];
    
    LL first = numoperations(1), second = numoperations(-1);
    LL ans = min(first, second);

    cout << ans << endl;

	return 0;
}

Measured memory_bytes: 640
M=10**9+7
n,k=map(int,input().split())
l=[0]*(k+1)
a=0
for i in range(k,0,-1):
  l[i]=pow(k//i,n,M)
  for j in range(i*2,k+1,i):
    l[i]-=l[j]
  a+=i*l[i]
print(a%M)


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

int main() {
    int N;
    int D;
    cin >> N >> D;
    if (N%(D*2+1)>0){
        cout << N/(D*2+1)+1 << endl;
    }else{
        cout << N/(D*2+1) << endl;
    }
    
}

Measured memory_bytes: 256
/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.

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



int main()
{
    int x, y;
    cin >> x >> y;
    if ((y - 2 * x) < 0 || (y - 2 * x) % 2) 
    {
        cout << "No";
        return 0;
    }
    int b = (y - 2 * x) / 2;
    if (x - b < 0) cout << "No";
    else cout << "Yes";
    return 0;
}


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

map<string,bool> memo;

bool cat(string s){
  if(s.empty())return true;
  if(memo.find(s)!=memo.end())return memo[s];
  int n = s.size()-1;
  if(s[0] != 'm' || s[n] != 'w')return false;

  for(int i=0;i<n;i++){
    if(s[i] == 'e'){
      if(cat(s.substr(1,i-1)) && cat(s.substr(i+1,n-i-1)))return memo[s] = true;
    }
  }
  return memo[s] = false;
}

int main(){
  string s;
  cin >> s;
  cout << (cat(s)?"Cat":"Rabbit") << endl;
}

Measured memory_bytes: 5632
#include <iostream>
#include <string>
#include <vector>
#include <random>
#include <algorithm>

using std::cout;
using std::cerr;
using std::cin;
using std::endl;

#if 0
#define NNN (100000)
#define MMM (10000)
void funcC() {
	int N;
	int M;
	std::vector<int> A[NNN+1];
	int P[NNN];
	int Y[NNN];

	cin >> N;
	cin >> M;

	for (int m = 0; m < M; ++m) {
		int p;
		int y;
		cin >> p;
		cin >> y;
		P[m] = p;
		Y[m] = y;
	}
	for (int m = 0; m < M; ++m) {
		A[P[m]].push_back(Y[m]);
	}
	for (int n = 1; n < N+1; ++n) {
		std::sort(A[n].begin(), A[n].end());
	}

	for (int m = 0; m < M; ++m) {
		int p = P[m];
		int y = Y[m];
		
		int idx =  std::lower_bound(A[p].begin(), A[p].end(), y) - A[p].begin();
		printf("%.6d%.6d\n", p, idx + 1);
		/*
		int idx = -1;
		for (int i = 0; i < A[p].size(); ++i) {
			if (A[p][i] == y) {
				//cerr << p << "," << i + 1 << endl;
				printf("%.6d%.6d\n", p, i + 1);
			}
		}
		*/
	}



}

std::vector<int> X;
#define LENGTH (9+1)
void funcC775_sub(std::string S) {
	if (S.length() >= LENGTH) {
		return;
	}

	if (S.find("3") != std::string::npos &&
		S.find("5") != std::string::npos &&
		S.find("7") != std::string::npos) {
		//cerr << S << ": OK" << endl;
		X.push_back(atoi(S.c_str()));
	}
	else {
		//cerr << S << ": NOT" << endl;
	}
	//cerr << S << endl;
	funcC775_sub(S + "3");
	funcC775_sub(S + "5");
	funcC775_sub(S + "7");
}
void funcC775() {
	int N;
	cin >> N;
	std::string SSS = "";

	funcC775_sub(SSS);
	std::sort(X.begin(), X.end());
	int idx = std::lower_bound(X.begin(), X.end(),N+1) - X.begin();
	cout << idx << endl;
	
}	
#endif
void func() {
	int N;
	int K;
	std::vector<int> H;
	cin >> N;
	cin >> K;
	for (int i = 0; i < N; ++i) {
		int h;
		cin >> h;
		H.push_back(h);
	}
	std::sort(H.begin(), H.end());


	std::vector<int> D;
	for (int i = 0; i < N - K+1; ++i) {
		int d = H[i + K - 1] - H[i];
		D.push_back(d);
		cerr << i << ":" << d << endl;
	}
	for (int i = 0; i < D.size(); ++i) {
		cerr << D[i] << endl;
	}
	int min_d = *std::min_element(D.begin(), D.end());

	cout << min_d << endl;
}

int main() {
	//funcB();
	func();

}


Measured memory_bytes: 1400
import itertools
n = int(raw_input())

d = {'M':0,'A':0,'R':0,'C':0,'H':0}

for i in range(n):
	s = raw_input()
	if d.has_key(s[0]):
		d[s[0]] += 1

count = 0

for comb in list(itertools.combinations(d.keys(),3)):
	count += d[comb[0]]* d[comb[1]]*d[comb[2]]

print count

Measured memory_bytes: 5764
function main(input) {
	var inputSeparated = input.split('\n');
  	var a = inputSeparated[1].split(' ').map(i=>parseInt(i));
  	var checkTimes = a.length - 2;
  	var count = 0;
  	for(var i = 0;i<checkTimes;i++){
    	var threeNumbers = a.slice(i,i+3);
	     //   console.log(threeNumbers);
      	if(threeNumbers[0]<threeNumbers[1] && threeNumbers[1]<threeNumbers[2]){
			count ++; 
        }else if(threeNumbers[0]>threeNumbers[1] && threeNumbers[1]>threeNumbers[2]){
         	count ++; 
        }
    }
  console.log(count);

}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 21192
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n, k;
    cin >> n >> k;
    int h[200000];
    for(int i=0; i<n; i++){
        cin >> h[i];
    }
    int ans = 0;
    for(int i=0; i<n; i++){
        if(h[i]>=k) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<vector>
using namespace std;
int g[301][301];
int r[10];
vector<int> s;
int main()
{
	int n,m,rr;
	scanf("%d%d%d",&n,&m,&rr);
	int s1=1;
	memset(g,0x3f,sizeof(g));
	for(int i=1;i<=n;i++){
		g[i][i]=0;
	}
	for(int i=1;i<=rr;i++){
		scanf("%d",&r[i]);
		s.push_back(i);
	}
	for(int i=1;i<=m;i++){
		int a,b,c;
		scanf("%d%d%d",&a,&b,&c);
		g[a][b]=c;
		g[b][a]=c;
	}
	for(int k=1;k<=n;k++){
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				g[i][j]=min(g[i][j],g[i][k]+g[k][j]);
			}
		}
	}
	long long ans=1000000000;
	do{
		int u=r[s[0]];
		int v=0;
		long long d=0;
		int k=1;
		while (k<rr){
			v=r[s[k]];
			k++;
			d+=g[u][v];
			u=v;
		}
		ans=min(ans,d);
	}while(next_permutation(s.begin(),s.end()));
	printf("%lld",ans);
}

Measured memory_bytes: 640
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <random>
#include <cstdio>
#include <cstring>
#include <cmath>

// for i in f..<t { as swift
#define forin(i, f, t) for(auto i = f; i < t; i++)

using namespace std;
using ll = long long;
using XY = pair<int, int>;

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << (a < b ? a : b) + (c < d ? c : d) << endl;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;


int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  for(ll i=0;i<n;i++) {
    cin >> a[i];
  }
  sort(a.begin(),a.end());
  ll mi;
  for(ll i=0;i<n-1;i++) {
    if(i==0) {
      mi=a[i];
    }
    if(abs((a[n-1]+1)/2-a[i])<abs((a[n-1]+1)/2-mi)) {
      mi=a[i];
    }
  }
  cout << a[n-1] << " " << mi << endl;
}

Measured memory_bytes: 1024
import java.util.Scanner;


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

		int i;
		String text, dec = "";

		while(sc.hasNext()){
			text = sc.next();
			i = 0;
			dec = "";
			while(i < text.length()){
				if(text.charAt(i) == '@'){
					for(int j = 0; j < Integer.parseInt("" + text.charAt(i + 1)); j++){
						dec += text.charAt(i + 2);
					}
					i += 3;
				}else{
					dec += text.charAt(i);
					i++;
				}
			}
			System.out.println(dec);
		}
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
#define pi pair<int,int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define inf 1000000000
using namespace std;
template <class T>
inline void read(T &a)
{static char c;int f=0;
while (((c=getchar())<'0'||c>'9')&&(c!='-'));
if (c=='-') {a=0;f=1;}
else {a=c-'0';}
while ((c=getchar())<='9'&&c>='0') a=(a<<3)+(a<<1)+c-'0';
if (f) a=-a;
}
bool vis[605][605];
int cnt=0,num=0,o=0,d1,d2,n;
int dx[4]={1,-1,1,-1},mod;
int dy[4]={1,1,-1,-1};
pi p[360005],g[360005],ans[100005];
inline bool cmp(pi a,pi b)
{return (a.fi+a.se)%mod<(b.fi+b.se)%mod;}
int main (){
	int i,j,k;
	scanf ("%d%d%d",&n,&d1,&d2);
	for (i=0;i<2*n;i++)
	{for (j=0;j<2*n;j++)
	{p[++num]=mp(i,j);
	if ((i*i+j*j==d1)||(i*i+j*j==d2)) g[++o]=mp(i,j);
	}
	}
	for (mod=2;;mod++)
	{stable_sort(p+1,p+num+1,cmp);
	memset(vis,0,sizeof(vis));cnt=0;
	for (i=1;i<=num;i++)
	{if (vis[p[i].fi][p[i].se]) continue;
	ans[++cnt]=p[i];
	if (cnt>=n*n) break;
	for (j=1;j<=o;j++)
	{for (k=0;k<4;k++)
	{int x=p[i].fi+dx[k]*g[j].fi,y=p[i].se+dy[k]*g[j].se;
	if (x<0||x>=2*n||y<0||y>=2*n) continue;
	vis[x][y]=1;
	}
	}
	}
	if (cnt>=n*n)
	{for (i=1;i<=cnt;i++) printf ("%d %d\n",ans[i].fi,ans[i].se);
	return 0;
	}
	}
	return 0;
}
	

Measured memory_bytes: 9216
#include<bits/stdc++.h>
using namespace std;
int main(){
	int A1,A2,A3,t,x,big,small,zhong;
	cin>>A1>>A2>>A3;
	t=max(A1,A2);
	big=max(A3,t);
	x=min(A1,A2);
	small=min(A3,x);
	zhong=A1+A2+A3-big-small;
	t=big-zhong;
	x=zhong-small;
	cout<<t+x;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
	
	int x,y,z;
	
	scanf("%d %d %d",&x,&y,&z);
	int total= x+y+z;
	
	
	if (total >=22){
   printf("bust\n");	
		
	
	}
	else{
		
		printf("win\n");
	}
	
	
	
	
	
	return 0;
	
	
}

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


#define f(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define char_f(i,a) for(int i=(int)(a);(char)s[i]!='\0';i++)
#define rf(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define llf(i,a,b) for(long long int i=(long long int)(a);i<=(long long int)(b);i++)
#define llrf(i,a,b) for(long long int i=(long long int)(a);i>=(long long int)(b);i--)



#define ll long long
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define mem(ara,x) memset((ara),x,sizeof(ara))
#define memn(ara) memset((ara),-1,sizeof(ara))
#define bb begin()
#define ee end()
#define em emplace
#define eb emplace_back





#define si set<int>
#define sd set<double>
#define sll set<long long int>
#define ss set<string>
#define sc set<char>

#define pii pair<int,int>
#define pli pair<long long int,int>
#define pil pair<int,long long int>
#define pll pair<long long int,long long int>
#define pci pair<char,int>
#define pic pair<int,char>
#define pcl pair<char,long long int>
#define plc pair<long long int,char>

#define pss pair<string,string>
#define pcc pair<char,char>

#define pis pair<int,string>
#define psi pair<string,int>
#define pls pair<long long int,string>
#define psl pair<string,long long int>
#define pdd pair<double,double>
#define pcs pair<char,string>
#define psc pair<string,char>



#define vi  vector<int>
#define vll vector<long long int>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vii vector<pii>



#define mod 1000000007
#define mx (1<<30)-1
#define llmx (1ll<<62)
#define n_size 100005
#define g_size 10000005
double PI=acos(-1);
#define eps 1e-9



///unsigned int uMAX=4294967295;
///unsigned ll int ullMAX=18446744073709551615;





int arr[g_size];



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

	int n,m,T,res;

	int maxi=-mx,mini=mx,count=0;

	int i,j,k;

	bool flag;

	string s1,s2;

	char s[100000];

	int ara[n_size],ara2[n_size];

	cin>>n;

	f(i,0,n-1) cin>>ara[i];

	sort(ara,ara+n);

	cout<<ara[n-1]-ara[0]<<endl;



}


Measured memory_bytes: 3656
#include <iostream>

using namespace std;

int main(void)
{
  int S;
  int f, r;
  cin >> S;

  f = S / 100;
  r = S % 100;

  if((1 <= f) && (f <= 12))
    f = 1;
  else
    f = 0;
  if((1 <= r) && (r <= 12))
    r = 1;
  else
    r = 0;

  if(r && f)
    cout << "AMBIGUOUS";
  else if(f)
    cout << "MMYY";
  else if(r)
    cout << "YYMM";
  else
    cout << "NA";

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstdio>
#include <cmath>
using namespace std;

int T;
const int MAXT = 30;
int X;
const int MAXX = 1000000;
vector<bool> Prime(MAXX+1, true);

int main(void) {
	// calc prime
	int sq_n = (int)(sqrt((double)MAXX) + 0.9);
	Prime[0] = false;
	Prime[1] = false;
	for (int i = 2; i < sq_n; i++) {
		if (Prime[i]) {
			for (int j = i + i; j < MAXX; j += i) {
				Prime[j] = false;
			}
		}
	}

	while (cin >> T >> X, T || X) {
		// input and init
		vector<int> price(T);
		vector<bool> dp(X+1, false);
		for (int i = 0; i < T; i++) {
			cin >> price[i];
			dp[price[i]] = true;
		}

		// dp
		for (int i = 0; i <= X; i++){
			if (!dp[i]){
				continue;
			}
			for (int j = 0; j < T; j++) {
				int x = i + price[j];
				if (x <= X) {
					dp[x] = true;
				}
			}
		}

		int res = 0;
		for (int i = X; i >= 0; i-- ){
			if (dp[i] && Prime[i]){
				res = i;
				break;
			}
		}

		// output
		if (res){
			cout << res << endl;
		}else {
			cout << "NA" << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1324
#include <bits/stdc++.h>
#define sz(arr) (int)arr.size()
#define all(arr) arr.begin(), arr.end()

using namespace std;

void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...) \
  T __VA_ARGS__;    \
  _cin(__VA_ARGS__)

int main() {
  Cin(int, n, k);
  Cin(string, s);

  s.at(k - 1) = tolower(s.at(k - 1));

  puts(s.c_str());

  return 0;
}

Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;


void main() {
    int a, b, c; scan(a, b, c);
    int k; scan(k);
    int ans = max(a, b, c) * 2^^k + a + b + c - max(a, b, c);
    writeln(ans);
}




void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
using Edge = pair<int, long long>;
using Graph = vector<vector<Edge>>;

Graph G;
vector<int> dir;

void dfs(int v, int p, int c) {
    dir[v] = c;
    for(auto e : G[v]) {
        if(e.first == p) continue; // すでに色確定していた場合スルー
        if(e.second % 2) dfs(e.first, v, 1 - c);
        else dfs(e.first, v, c);
    }
}

int main() {
    int N; cin >> N;
    G.assign(N, vector<Edge>());
    for(int i = 0; i < N - 1; ++i) {
        int a, b;
        long long w;
        cin >> a >> b >> w;
        --a, --b;
        G[a].push_back(Edge(b, w));
        G[b].push_back(Edge(a, w));
    }
    dir.assign(N, 0);
    dfs(0, 0, 0);
    for(int i = 0; i < N; ++i) cout << dir[i] << endl;
}


Measured memory_bytes: 10496
#include <bits/stdc++.h>
using namespace std;
int main(){
  int X;
  int N;
  cin>>X>>N;
  vector<int> r(N);
  int c;
  int d;
  for (int i=0;i<N;i++){
    cin>>r.at(i);
  }
  
  for (int j=0;j<N;j++){
    c=X-j;
    d=X+j;  
    for(int i=0;i<N;i++){
      if(c==r.at(i)){
        c=-2;
        break;
      }
    }
    if(c==-2){
      for(int i=0;i<N;i++){
        if(d==r.at(i)){
          d=-2;
          break;
        }
      }
    }
    if(!((c==-2)&&(d==-2))){
      break;
    }
  }
  if(c!=-2){
    d=c;
  }
  if(N==0){
    d=X;
  }
  if(N==1){
    if(N==r.at(0)){
      d=N-1;
    }
  }
  cout<<d<<endl;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define se second
#define fi first
#define ll long long
#define ld long double
#define pll pair<ll ,ll >
#define plll pair<ll,pll>
#define ppll pair<pll, pll>
#define pii pair<int, int> 
#define pb push_back
#define mod 1000000007
#define N 1000007
ll power(ll a,ll b){
    ll res=1ll;
    while(b>0){
        if(b%2!=0) res=(res*a)%mod;
        a=(a*a)%mod;
        b/=2;
    }
    return res%mod;
}
ll ncr(ll n,ll k){
    if(k>n-k) k=n-k;
    ll pro=1;
    for(ll i=0;i<k;i++){
        pro=(pro*(n-i))%mod;
        pro/=(i+1);
    }
    return (pro)%mod;
}

void swap(ll *a,ll *b) {
    ll temp=*a;
    *a=*b;
    *b=temp;
}
vector<ll> prime;
void seive(){
    vector<bool > isprime(1000001,true);
    for(int i=2;i*i<=1000000;i++){
        if(isprime[i]){
            for(int j=i*i;j<=1000000;j+=i){
                isprime[j]=false;
            }
        }
    }
    for(int i=2;i<=1000000;i++){
        if(isprime[i]) prime.push_back(i);
    }
}
vector<ll> parent;
ll find(ll p) {
    if(parent[p]==p) return parent[p];
    return parent[p]=find(parent[p]); 
}
void unun(ll a,ll b) {
    ll r1=find(a);
    ll r2=find(b);
    if(r1!=r2) parent[r2]=r1;
}
void solve() {   
    ld n;
    cin>>n;
    if(n==100) {
        cout<<"0";
        return ;
    }
    ll p=100;
    for(ll i=1;i<=1e6;i++) {
        p=p*(1.01);
        if(p>=n) {
            cout<<i;
            return ;
        }
    }
    return ;
}   


int main(void){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    cout.tie(NULL);
    int t;
    t=1;
    // cin>>t;
    while(t--) {
        solve();
        // cout<<endl;
    }
    return 0; 

}


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

int main()
{
  int x, y, z, n;
  cin >> x >> y >> z >> n;

  long long a[x];
  for (int i = 0; i < x; i++){
    cin >> a[i];
  }

  long long b[y];
  for (int i = 0; i < y; i++){
    cin >> b[i];
  }

  long long c[z];
  for (int i = 0; i < z; i++){
    cin >> c[i];
  }

  sort(a, a+x, greater<long long>());
  sort(b, b+y, greater<long long>());
  sort(c, c+z, greater<long long>());

  set<tuple<int, int, int>> s;
  priority_queue<pair<long long, tuple<int, int, int>>> q;

  q.push(make_pair(a[0]+b[0]+c[0], make_tuple(0, 0, 0)));
  s.insert(make_tuple(0, 0, 0));

  for (int ct = 0; ct < n; ct++){
    long long score = q.top().first;
    tuple<int, int, int> t = q.top().second;
    q.pop();

    cout << score << endl;

    int i = get<0>(t);
    int j = get<1>(t);
    int k = get<2>(t);

    if ((i < x-1) && s.find(make_tuple(i+1, j, k)) == s.end()){
      q.push(make_pair(a[i+1]+b[j]+c[k], make_tuple(i+1, j, k)));
      s.insert(make_tuple(i+1, j, k));
    }

    if ((j < y-1) && s.find(make_tuple(i, j+1, k)) == s.end()){
      q.push(make_pair(a[i]+b[j+1]+c[k], make_tuple(i, j+1, k)));
      s.insert(make_tuple(i, j+1, k));
    }

    if ((k < z-1) && s.find(make_tuple(i, j, k+1)) == s.end()){
      q.push(make_pair(a[i]+b[j]+c[k+1], make_tuple(i, j, k+1)));
      s.insert(make_tuple(i, j, k+1));
    }
  }
}


Measured memory_bytes: 896
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

#define INF 1e9
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

ll N,D, ans = 0;

void solve(){
    ans = N / (D*2+1);
    if(N % (D*2+1) != 0)
        ans++;
    cout << ans << endl;
}

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

    solve();
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <queue>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define ll long long
#define fr(i,k,N) for(ll i=k; i<N;i++)
#define rep(i,N) for(ll i=0; i<N;i++)
#define ALL(v) v.begin(),v.end()
#define mp make_pair
using namespace std;
template <class X> void pr(X test){cout<<test<<endl;}
template <class X> void prr(X test){for(auto it:test){cout<<it<<endl;}}
template <class X> void prrr(X test){int f=0;for(auto it:test){cout<<(f++!=0?" ":"")<<it;}cout<<endl;}
template<typename X>
istream&operator>>(istream&i,vector<X>&v){for(X&x:v)i>>x;return i;}

class UF { // union find from https://github.com/kartikkukreja/blog-codes (MIT)
    // [usage]
    // auto uf = new UF(n);
    // uf->merge(l, r); // 0 <= l, r <= n-1
    // ...
public:
    int *id; // inner id
    int cnt; // number of all vartices
    int *sz; // sz[i] means size of i's set
    UF(int N)   {
        cnt = N;
        id = new int[N];
        sz = new int[N];
        for(int i=0; i<N; i++) {
            id[i] = i;
            sz[i] = 1;
        }
    }
    ~UF() {
        delete [] id;
        delete [] sz;
    }
    int find(int p) {
        int root = p;
        while (root != id[root]) root = id[root];
        while (p != root) {
            int newp = id[p];
            id[p] = root;
            p = newp;
        }
        return root;
    }
    void merge(int x, int y) {
        int i = find(x);
        int j = find(y);
        if (i == j) return;
        
        if (sz[i] < sz[j]) {
            id[i] = j;
            sz[j] += sz[i];
        } else {
            id[j] = i;
            sz[i] += sz[j];
        }
        cnt--;
    }
    bool connected(int x, int y) {
        return find(x) == find(y);
    }
    int count() {
        return cnt;
    }
};

// return sorted 約数list 1 <= x <= n
vector<ll> divv(ll n) {
  vector<ll> v;
  for(ll i = 1; i*i <= n; i++) {
    if(n%i == 0) {
      v.push_back(i);
      if(i*i != n) v.push_back(n/i);
    }
  }
  sort(ALL(v));
  return v;
}

int main() {
    ll n;
    cin>>n;
    vector<ll> v(n);
    cin>>v;
    sort(ALL(v));
    ll sum=0;
    rep(i, n) {
        ll a = v[i] +  v[i+1];
        ll b = - v[i] -  v[i+1];
        if(a<b) {
            v[i] *= -1;
            v[i+1] *= -1;
        }
        i++;
        if(i == n -2) break;
    }
    rep(i, n) {
        sum+=v[i];
    }
    pr(sum);
    return 0;
}


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

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

int N,Q;
string S;
int l, r;

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

	cin >> N >> Q >> S;

	int cnt[100005]; memset(cnt,0,sizeof(cnt));

	for (int i = 1;i < N;i++){
		cnt[i] = cnt[i-1];
		if(S[i] == 'C' && S[i-1] == 'A') cnt[i]++;
	}

	for (int i = 0;i < Q;i++){
		cin >> l >> r;
		l--; r--;
		if(S[l] == 'A' && S[l+1] == 'C') cout << cnt[r] - cnt[l+1]+1 << endl;
		else cout << cnt[r] - cnt[l+1] << endl;
	}

	return 0;

}


Measured memory_bytes: 1488
#include<bits/stdc++.h>
using namespace std;
//Optimisations
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
//shortcuts for functions
#define pb push_back
#define mp make_pair
#define ff first 
#define ss second
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
#define n_l '\n'
// make it python 
#define gcd __gcd
#define append push_back
#define str to_string
// utility functions shortcuts
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
// declaration shortcuts
typedef long long int ll;
#define int ll
// Constants
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997; 
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI  = 3.14159265358979323846L;
constexpr auto oo  = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto MOD = 1000000007;
constexpr auto MOD9 = 1000000009;
constexpr auto maxn = 100006;
//void IOfile(){
//freopen(file_name, reade_mode, stdin);
//freopen(file_name, write_mode, stdout);
//}
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}

ll mod_pow(ll a,ll b,ll p){ //(a^b)%p
	ll res=1;
	a%=p;

	while(b>0){
		if(b&1==1) res=((res%p)*(a%p))%p;
		a=(a%p*a%p)%p;
		b>>=1;
	}
	return res;
}

//mod_inv=mod_pow(denominator,MOD-2,MOD);
int fac[MAXSIZE+6];
int inv[MAXSIZE+6];

void pre(){
	fac[0] = 1;
	for(int i=1;i<=MAXSIZE;i++){
		fac[i] = fac[i-1] * (i);
		fac[i]%=mod;
	}
	inv[MAXSIZE] = mod_pow(fac[MAXSIZE],mod-2,mod);
	for(int i=MAXSIZE-1;i>=0;i--){
		inv[i] = (i+1) * inv[i+1];
		inv[i]%=mod;
	}
}

int nCr(int n, int r){
	if(r>n) return 0;
	int ans = fac[n];
	ans%=mod;
	ans = ans * inv[r];
	ans%=mod;
	ans = ans * inv[n-r];
	ans%=mod;
	return ans;
}


int32_t main(){
	fastio();
	pre();
	int n , a , b;
	cin >> n >> a >> b;
	int ans = mod_pow(2, n ,mod);
	ans = (ans - 1 + mod) %mod;

	int x = 1;
	for(int i = 1; i <= a;i++){
		x = x * (n - i + 1);
		x %= mod;
	}
	x = x * inv[a];
	x %= mod;
	ans = (ans - x + mod) %mod;

	x = 1;
	for(int i = 1; i <= b ; i++){
		x = x * ( n - i + 1);
		x %= mod;
	}
	x = x * inv[b];
	x %= mod;
	ans = (ans - x + mod) %mod;
	cout << ans;
}

Measured memory_bytes: 19248
#include<bits/stdc++.h>
using namespace std;
int m[1001][1001];
int h,w;
bool checkValid(int x,int y){
    return (x>=0&&y>=0&&x<h&&y<w);
}
int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cin >> h >> w;
    int ch,cw,dh,dw;
    cin >> ch >> cw >> dh >> dw;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            char tmp;
            cin >> tmp;
            if(tmp=='#') m[i][j] = 1;
        }
    }
    ch-=1;
    cw-=1;
    dh-=1;
    dw-=1;

    set<pair<int,int>> dir={{-1,0},{1,0},{0,-1},{0,1}};
    vector<int> warp={-2,-1,0,1,2};
    deque<pair<int,int>> q;
    m[ch][cw]=2;
    q.push_front(make_pair(ch,cw));
    while(!q.empty()){
        int i=q.front().first;
        int j=q.front().second;
        int cost = m[i][j];
        q.pop_front();
        for(auto p : dir){
            int x = p.first;
            int y = p.second;
            if(checkValid(i+x,j+y)){
                if(m[i+x][j+y]==0||m[i+x][j+y]>cost){
                   q.push_front({i+x,j+y});
                   m[i+x][j+y]=cost; 
                }
            }
        }
        for(auto x: warp){
            for(auto y:warp){
                if((x!=0||y!=0)&&checkValid(i+x,j+y)&&dir.count(make_pair(x,y))==0){
                    if(m[i+x][j+y]==0||m[i+x][j+y]>cost+1){
                        q.push_back(make_pair(i+x,j+y));
                        m[i+x][j+y]=cost+1; 
                    }
                }
            }
        }
    }
//    for(int i=0;i<h;i++){
//        for(int j=0;j<w;j++){
//            cout <<  m[i][j] << " ";
//        }
//        cout << endl;
//    }
    if(m[dh][dw]==0) cout << -1;
    else cout << m[dh][dw]-2;
    return 0;
}


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

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

ll n,k;
struct ab {
    ll a;
    ll b;
};

ab ab_s[100000];

bool cmp(const ab &a, const ab &b){
    return a.a < b.a;
}


int main() {
    std::cin >> n>>k;
    for (int i = 0; i < n; i++) {
        std::cin >> ab_s[i].a>>ab_s[i].b;
    }
    sort(ab_s,ab_s+n,cmp);
    ll i=-1;
    while(k>0){
        i++;
        k -= ab_s[i].b;
    }
    std::cout << ab_s[i].a << std::endl;
}

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

#define rep(i, N) for(int (i) = 0; (i) < (N); i++)
#define all(v) v.begin(), v.end()
using i64 = int_fast64_t;

int main(){
    i64 N;
    cin >> N;
    vector<i64> A(N);
    rep(i, N) cin >> A[i];

    vector<vector<i64>> pop_bit(N, vector<i64>(60, 0));
    for(int i = 1; i < N; i++){
        for(int b = 0; b < 60; b++){
            pop_bit[i][b] += pop_bit[i-1][b];
            if(A[i] & (1ll << b)) pop_bit[i][b]++;
        }
    }

    const i64 MOD = 1e9 + 7;
    i64 ans = 0; 
    for(int i = 0; i < N - 1; i++){
        int len = N - (i + 1);
        for(int b = 0; b < 60; b++){
            i64 bit = pop_bit[N - 1][b] - pop_bit[i][b]; 
            if(A[i] & (1ll << b)){
                ans = (ans + (((1ll << b) % MOD) * (len - bit) % MOD)) % MOD; 
            } else {
                ans = (ans + (((1ll << b) % MOD) * bit) % MOD) % MOD; 
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 154880
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
  int x;
  cin >> x;
  vector<long long> bp;
  bp.push_back(1);
  int i, j;
  for (i = 1; i < x; i++) {
    for (j = 2; j < x; j++) {
      int product = pow(i, j);
      if (product <= x) {
        bp.push_back(product);
      } else {
        break;
      }
    }
  }
  sort(bp.begin(), bp.end());
  cout << bp[bp.size() - 1] << endl;
  return 0;
}


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

int main()
{
	int n, m, l;
	int i, j, k;
	int A[100][100],  B[100][100]; 
	long C[100][100]={0};
	
	cin >> n >> m >> l;
	
	for(i = 0; i < n; i++){
		for(j = 0; j < m; j++){
			cin >> A[i][j];
		}
	}
	
	for(i = 0; i < m ; i++){
		for(j = 0; j < l ; j++){
			cin >> B[i][j];
		}
	}

	for(i = 0; i < n; i++){
		for(j = 0; j < l; j++){
			for(k = 0; k < m; k++){
				C[i][j] += A[i][k] * B[k][j];
			}
		}
	}
	
	for(i = 0; i < n ; i++){
		for(j = 0; j < l ; j++){
			cout << C[i][j];
			if(j != l - 1){
				cout << " "; 
			}
		}
		cout << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3248
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring>
#include<numeric>
#include<vector>
#include<map>
#include<set>
#include<cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int>PII;
typedef pair<ll,ll>PLL;
#define X first
#define Y second
int dx[4]={-1,0,1,0};
int dy[4]={0,1,0,-1};
const int maxn=1e4+10;
int a[maxn];

ll ABS(ll a,ll b){
	if(a>b){
		return a-b;
	}else return b-a;
}

int main(){
	ll n,k;
	cin>>n>>k;
	if(n<k/2){
		cout<<n<<endl;
		return 0;
	}
	if(n%k==0){
		cout<<0<<endl;
		return 0;
	}
	cout<<min(n%k,ABS(n%k,k))<<endl;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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

const ll mod=1e9+7;

ll n;
vector<pll> to[100000];
vector<ll> dist(100000),used(100000);
bool ans=true;
void dfs(ll v,ll pos,ll p=-1){
    used[v]=1;
    dist[v]=pos;
    for(auto x:to[v]){
        if(x.fi==p) continue;
        if(used[x.fi]){
            if(dist[x.fi]!=pos+x.se){
                ans=false;
                break;
            }
        }
        else{
            dfs(x.fi,pos+x.se,v);
        }
    }
    return ;
}
int main(){
    ll m;
    cin >> n >> m;
    rep(i,m){
        ll l,r,d;
        cin >> l >> r >> d;
        l--; r--;
        to[l].push_back(make_pair(r,d));
        to[r].push_back(make_pair(l,-d));
    }
    rep(i,n){
        if(used[i]) continue;
        dfs(i,0LL);
    }
    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
} 


Measured memory_bytes: 19992
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = 0
for i in range(n):
	rem = max(B[i]-A[i], 0)
	ans += min(A[i], B[i]) +  min(rem, A[i+1])
	A[i+1] = max(A[i+1]- rem, 0)
print(ans)

Measured memory_bytes: 82148
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int a, b, c;
    cin >> a >> b >> c;

    int answer = 0;
    for(int i = a; i <= b; i++){
        if(c % i == 0){
            answer++;
        }
    } 

    cout << answer << endl;    
}


Measured memory_bytes: 3096
/*

#include <bits/stdc++.h>

using namespace std;

int main () {
	int n;
	cin >> n;
	
	vector<int> input(n);
	for (int i = 0; i < n; i++) {
		cin >> input[i];
	}

	vector<int> ans(n);
	ans[0] = 0; ans[1] = abs(input[1] - input[0]);
	for (int i = 2; i <n; i++) {
		ans[i] = min ( ans[i-1] + abs(input[i] - input[i - 1]), ans[i-2] + abs(input[i] - input[i - 2]) );
	}
	
	cout << ans[n-1] << endl;
	return 0;
}

*/

#include <bits/stdc++.h>

using namespace std;

int main () {
	int n;
	cin >> n;
	
	int in1, in2, in3, ans1, ans2, ans3;
	cin >> in1 >> in2;
	ans1 = 0; ans2 = abs(in1 - in2);

	if (n == 1) {
		cout << ans1 << endl;
		return 0;
	}

	if (n == 2) {
		cout << ans2 << endl;
		return 0;
	}

	for (int i = 2; i <n; i++) {
		cin >> in3;
		ans3 = min ( ans2 + abs(in3 - in2), ans1 + abs(in3 - in1) );

		in1 = in2;
		in2 = in3;
		ans1 = ans2;
		ans2 = ans3;
		
	}
	
	cout << ans3 << endl;
	return 0;
}

Measured memory_bytes: 256
import itertools

MOD = 10**9 + 7


def is_ok(p, c):
    if c == "C":
        if p[1:] == "AG" or p[1:] == "GA" or p[:2] == "AG" or (p[0] == "A" and p[2] == "G"):
            return False
    if c == "G" and p[1:] == "AC":
        return False
    return True


def main():
    N = int(input())
    ans = {"".join(x): 1 for x in itertools.product("ACGT", repeat=3)}
    for p in ["AGC", "ACG", "GAC"]:
        ans[p] = 0
    for _ in range(3, N):
        prev = ans
        ans = {"".join(x): 0 for x in itertools.product("ACGT", repeat=3)}
        for c in "ACGT":
            for p in prev:
                if is_ok(p, c):
                    nxt = p[1:] + c
                    ans[nxt] = (ans[nxt] + prev[p]) % MOD
    print(sum(ans.values()) % MOD)


if __name__ == "__main__":
    main()


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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> w[m];
  while ( n-- > 0 ) {
    int a, b;
    cin >> a >> b;
    a--;
    if ( a < m ) {
      w[a].push_back(b);
    }
  }

  long long ans = 0;
  priority_queue<int> q;
  for ( int i = 0; i < m; i++ ) {
    for ( int j = 0; j < w[i].size(); j++ ) {
      q.push(w[i][j]);
    }
    if ( ! q.empty() ) {
      ans += q.top();
      q.pop();
    }
  }

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


Measured memory_bytes: 8812
# AtCoder
A = [list(map(int, input().split())) for i in range(3)]
N = int(input())
b = [int(input()) for _ in range(N)]
ans = 'No'
for i in range(3):
    for j in range(3):
        if A[i][j] in b:
            A[i][j] = True
        else:
            A[i][j] = False

for i in range(3):
    if A[i][0] and A[i][1] and A[i][2]:
        ans = 'Yes'

for i in range(3):
    if A[0][i] and A[1][i] and A[2][i]:
        ans = 'Yes'

if A[0][0] and A[1][1] and A[2][2]:
    ans = 'Yes'
if A[0][2] and A[1][1] and A[2][0]:
    ans = 'Yes'

print(ans)


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

int main() {
  int x;
  while(cin >> x) {
    x%=39;
    if(x==0) x=39;
    if(x<10) cout << "3C0" << x << endl;
    else cout << "3C" << x << endl;
  }
  return 0;
}


Measured memory_bytes: 1160
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Math;
using static System.Console;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        solve();
    }
    static Scanner cin;
    static int N;

    static void input()
    {
        cin = new Scanner();
        N = cin.nextInt();
    }
    static void solve()
    {
        input();

        WriteLine(N * N * N);
    }
    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }
        
        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }

        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for(int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for(int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }

        public double[] ArrayDounble(int N, int add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }
}

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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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 (b<a) { a = b; return 1; } return 0; }

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
  int paSize = printArray.size();
  for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
  if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

int Len[55], Pat[55];

int rec(int level, int layer) {
  if (level == 0) {
    return 1;
  }

  if (layer <= 1) { // 1
    return 0;
  } else if (layer <= Len[level-1] + 1) { // 2
    return rec(level-1, layer-1);
  } else if (layer <= Len[level-1] + 2) { // 3
    return Pat[level-1] + 1;
  } else if (layer <= 2*Len[level-1] + 2) { // 4
    return Pat[level-1] + 1 + rec(level-1, layer - Len[level-1] - 2);
  } else {
    return  2*Pat[level-1] + 1;
  }
}

signed main() {
  int N, X;
  cin >> N >> X;

  Len[0] = Pat[0] = 1;
  for (int i = 1; i <= N; i++) {
    Len[i] = Len[i-1] * 2 + 3;
    Pat[i] = Pat[i-1] * 2 + 1;
  }

  cout << rec(N, X) << endl;

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
int max(const void *a, const void *b){return *(int*)b - *(int*)a;}


int main(void)
{
    int a,b;
    
    scanf("%d",&a);
    scanf("%d",&b);


    if((a+b)%2==1){
        printf("IMPOSSIBLE\n");
    }else{
        printf("%d\n", (a+b)/2);
    }
    
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#define REP(i,n) for(int i=0;i<(n);++i)
#define MOD 1000000007
using namespace std;

int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;
  int len = S.size();
  REP(i, len) {
    int a = S[i] - 'A';
    a = (a + N) % 26;
    char c = 'A' + a;
    cout << c;
  }
  cout << endl;
}

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

int main(void) {
	vector<long long> a(3);
	for (int i = 0; i < 3; i++) {
		cin >> a[i];
		if (a[i] % 2 == 0) {
			cout << 0 << endl;
			return 0;
		}
	}

	sort(a.begin(), a.end());
	cout << a[0] * a[1] << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <map>
#include <iostream>
#include <string>
#include <set>
#include <queue>
#include <cmath>
#include <iterator>
#include <array>
typedef long long int ll;
using namespace std;
#define maxN 200005
#define mod 1000000007

void solve()
{
    int n;
    cin >> n;
    string s[10] = {"pon", "pon", "hon", "bon", "hon", "hon", "pon", "hon", "pon", "hon"};
    cout << s[n % 10] << endl;
}

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

Measured memory_bytes: 3608
package main

import "fmt"
import "bytes"

func main() {
  var n int

  fmt.Scanf("%d", &n)

  ds := make([](map[byte]uint), n)
  for i := 0; i < n; i++ {
    ds[i] = make(map[byte]uint)
    for j := 0; j < 26; j++ {
      ds[i]['a'+byte(j)] = 0
    }
  }

  for i := 0; i < n; i++ {
    d := ds[i]
    var s string
    fmt.Scanln(&s)
    for j := 0; j < len(s); j++ {
      d[s[j]]++
    }
  }

  resultm := make(map[byte]uint)
  for i := 0; i < 26; i++ {
    resultm['a'+byte(i)] = 50
    for j := 0; j < n; j++ {
      if resultm['a'+byte(i)] > ds[j]['a'+byte(i)] {
        resultm['a'+byte(i)] = ds[j]['a'+byte(i)]
      }
    }
  }

  ans := []byte{}
  for i := 0; i < 26; i++ {
    c := 'a'+byte(i)
    for j := 0; j < int(resultm[c]); j++ {
      ans = append(ans, c)
    }
  }
  fmt.Println(bytes.NewBuffer(ans).String())
}


Measured memory_bytes: 640
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>

#define                           int                         long long
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<int,int>
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);




using namespace std;

const int inf=1e18;
const int mod=1e9+7;
const int M=100009;
inline int bigmod(int B,int P){int R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}

int n;
map< pair<string,string> , int >cnt;
 main()

{
    fast
    cin>>n;
    string s;
    cin>>s;
    int h=n;
    int lim=(1<<h)-1;
    f(msk,0,lim)
    {
        string red="";
        string blue="";
        f(j,0,h-1)
        {
            if(msk>>j & 1)
            {
                red+=s[j];
            }
            else blue+=s[j];
        }
        reverse(blue.begin(),blue.end());
        cnt[mp(red,blue)]++;
    }
    int ses=0;
    f(msk,0,lim)
    {
        string red="";
        string blue="";
        f(j,0,h-1)
        {
            if(msk>>j & 1)
            {
               red+=s[h+j];
            }
            else blue+=s[h+j];
        }
        reverse(blue.begin(),blue.end());
        ses+=cnt[mp(blue,red)];
    }
    cout<<ses<<endl;
    return 0;

}













Measured memory_bytes: 87040
import math

def judge(dist, p, q):
    if p + q >= dist:
        if dist + p < q:
            ans.append(-2)
        elif dist + q < p:
            ans.append(2)
        else:
            ans.append(1)
    else:
        ans.append(0)

N = int(input())
circles = [list(map(float, input().split())) for _ in range(N)]
ans = []

for circle in circles:
    xa, ya, ra, xb, yb, rb = circle
    distance = math.sqrt((xa-xb)**2 + (ya-yb)**2)
    judge(distance, ra, rb)

print('\n'.join(map(str, ans)))


Measured memory_bytes: 5688
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
using namespace std;
const int inf=1<<28;
char s[310];
int n,f[310][310],g[310][310],K;
int main()
{
	scanf("%s",s+1);n=strlen(s+1);
	scanf("%d",&K);
	memset(f,-63,sizeof(f));
	for(int i=0;i<=K;i++) f[1][i]=1;
	for(int i=2;i<=n;i++)
	{
		for(int j=1;j<i;j++)
			for(int k=0;k<=K;k++) g[j][k]=f[j][k];
		for(int j=0;j<=K;j++) g[i][j]=1;
		for(int j=0;j<=K;j++)
		{
			int t1=0,t2=0;
			for(int k=i-1;k>=1;k--)
			{
				t1=max(t1,f[k+1][j]);
				if(j!=0) t2=max(t2,f[k+1][j-1]);
				if(s[k]==s[i]) g[k][j]=max(g[k][j],t1+2);
				else if(j!=0) g[k][j]=max(g[k][j],t2+2);
			}
		}
		for(int j=1;j<=i;j++) for(int k=1;k<=K;k++) g[j][k]=max(g[j][k],g[j][k-1]);
		for(int j=i-1;j>=1;j--) for(int k=0;k<=K;k++) g[j][k]=max(g[j][k],g[j+1][k]);
		for(int j=1;j<=i;j++) for(int k=0;k<=K;k++) f[j][k]=max(f[j][k],g[j][k]);
	}
	int ans=0;
	for(int i=1;i<=n;i++) for(int j=0;j<=K;j++) ans=max(ans,f[i][j]);
	printf("%d",ans);
}

Measured memory_bytes: 1024
#include<cstdio>
typedef long long ll;
const int MaxN=200010;
int N,X,x[MaxN];
ll sum[MaxN];
int main(){
	scanf("%d%d",&N,&X);
	for(int i=0;i<N;i++)scanf("%d",x+i),sum[i+1]=sum[i]+x[i];
	ll ans=1ll<<62;
	for(int t=1;t<=N;t++){
		int pos=N;
		ll s=1ll*X*(N+t);
		for(int i=0;pos>0;i++){
			double tmp=s+(sum[pos]-sum[pos-t<0?0:pos-t])*1.0*(i?i*2+3:5);
			if(tmp>1ll<<62)s=1ll<<62;
			else s+=(sum[pos]-sum[pos-t<0?0:pos-t])*(i?i*2+3:5);
			pos-=t;
		}
		if(s<ans)ans=s;
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 2560
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

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

    vector<int> ret(2*n);
    for(int i=0; i<2*n; ++i)
        ret[i] = i+1;

    for(int i=0; i<m; ++i){
        int k;
        cin >> k;
        if(k == 0){
            vector<int> tmp(2*n);
            for(int i=0; i<n; ++i){
                tmp[2*i] = ret[i];
                tmp[2*i+1] = ret[n+i];
            }
            ret = tmp;
        }else{
            rotate(ret.begin(), ret.begin()+k, ret.end());
        }
    }

    for(int i=0; i<2*n; ++i)
        cout << ret[i] << endl;

    return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
double a[500][500];
#define pi 3.142857143
set< int > st[200005];
int main() {
	int n;
	cin >> n;
	for(int i = 0 ; i < n - 1 ; i++){
			int x;
			cin >> x;
			st[x].insert(i);
	}	
	for(int i = 1 ; i <= n ; i++){
		cout << st[i].size() << endl;
	}
	return 0;
	
}


Measured memory_bytes: 22400
N, K, Q = map(int, input().split())
A = [0] * N

for _ in range(Q):
    a = int(input()) - 1
    A[a] += 1

s = sum(A)

for a in A:
    if K - (s - a) > 0:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 50392