akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;
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; }
const string YES = "Yes";

void bfs(vector<vll> &G, vll &checked, ll s){
    fill(ALL(checked), -1);
    checked[s] = 0;
    queue<ll> que;
    que.push(s);
    while(!que.empty()){
        ll u = que.front(); que.pop();
        for(ll v: G[u]){
            if(checked[v] >= 0) continue;
            checked[v] = u;
            que.push(v);
        }
    }
}

void solve(long long N, long long M, std::vector<long long> A, std::vector<long long> B){
    vector<vll> G(N);
    REP(i, M){
        G[A[i]].push_back(B[i]);
        G[B[i]].push_back(A[i]);
    }
    vll checked(N, -1);
    bfs(G, checked, 0);
    cout<<"Yes"<<endl;
    for(ll i = 1; i < N; i++){
        cout<<checked[i]+1<<endl;
    }
}
int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> A(M);
    std::vector<long long> B(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&A[i]);
        scanf("%lld",&B[i]);
        A[i]--; B[i] --;
    }
    solve(N, M, std::move(A), std::move(B));
    return 0;
}


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

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b, a % b);
}

ll lcm(ll a, ll b){
  return a/gcd(a,b) * b;
}
ll func2(ll n){
  ll res = 0;
  while(n%2 == 0){
    n /= 2;
    res++;
  }
  return res;
}

ll zyou(ll a,ll b){//a＾b
  ll res = 1;
  for(int i = 1;i<=b;i++){
    res *= a;
  }
  return res;
}
using Graph = vector<vector<char>>;

ll calc(ll a, ll b, ll p){//aのb乗をpで割った余り
  if(b == 0) return 1;

  else if(b%2 == 0){
    ll d = calc(a,b/2,p);
    return (d*d)%p;
  }
  else if(b%2 == 1){
    return (a * calc(a,b-1,p))%p;
  }
}

typedef pair<int,int> P;

bool is_prime(int n){//nが素数であるかどうか判定 iで割り切れると素数でない
    if(n == 1) return false;//1は例外
    for(int i = 2;i*i <= n;i++){
        if(n%i == 0) return false;
    }
    
    return true;
}
int factorial(int a){
  int res = 1;
  while(a){
    res *= a;
    a--;
  }
  return res;
}


int main(){
  int H,W;
  cin >> H >> W;
  vector<vector<int>> masu(H, vector<int>(W));
  rep(i,H){
    rep(j,W){
      cin >> masu[i][j];
    }
  }
  int c = 0;
  vector<vector<int>> ans(H*W+100);
  for(int i = 0;i<=H-2;i++){
    for(int j = 0;j<W;j++){
      if(masu[i][j]%2){
        
        ans[c].push_back(i+1);
        ans[c].push_back(j+1);
        ans[c].push_back(i+2);
        ans[c].push_back(j+1);
        c++;
        //cout << i+1 << " " << j+1 << " " << i+2 << " " << j+1 << endl;
        masu[i+1][j]++;
      }
    }
  }
  for(int j = 0;j<=W-2;j++){
    if(masu[H-1][j]%2){
      
      ans[c].push_back(H);
      ans[c].push_back(j+1);
      ans[c].push_back(H);
      ans[c].push_back(j+2);
      c++;
      //cout << H << " " << j+1 << " " << H << " " << j+2 << endl;
      masu[H-1][j+1]++;
    }
  }
  cout << c << endl;
  for(int i = 0;i<=c-1;i++){
    for(int j = 0;j<4;j++){
      if(j <= 2){
      cout << ans[i][j] << " ";
      }
      else cout << ans[i][j];
    }
    cout << endl;
  }
}

Measured memory_bytes: 14720
#include <bits/stdc++.h>
#include <vector>
#include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

// #define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9+5;
const int mod = 1e9+7;
using ll = long long;
struct mint {
  ll x; // typedef long long ll;
mint(ll x=0):x((x%mod+mod)%mod){}
mint operator-() const { return mint(-x);}
mint& operator+=(const mint a) {
if ((x += a.x) >= mod) x -= mod;
return *this;
}
mint& operator-=(const mint a) {
if ((x += mod-a.x) >= mod) x -= mod;
return *this;
}
mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
mint operator+(const mint a) const { return mint(*this) += a;}
mint operator-(const mint a) const { return mint(*this) -= a;}
mint operator*(const mint a) const { return mint(*this) *= a;}
mint pow(ll t) const {
if (!t) return 1;
mint a = pow(t>>1);
a *= a;
if (t&1) a *= *this;
return a;
 }
mint inv() const { return pow(mod-2);}
mint& operator/=(const mint a) { return *this *= a.inv();}
mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
vector<mint> fac(MX);
vector<mint> ifac(MX);
mint comp(ll a, ll b) {
    return fac[a]/fac[b]/fac[a-b];
}

signed main(){
    int s;
    cin >> s;
    fac[0]=1;
    FOR(i,1,MX+1) {
        fac[i]=fac[i-1]*i;
    }
    int ma = s/3;
    mint ans = 0;
    FOR(i,1,ma+1) {
       int ama = s-3*i;
        mint geta = 1;
       if(ama != 0) geta = comp(ama+i-1,ama);
       //cout << comp(ama+i-1,ama) << endl;
    //    rep(j,ama) {
    //        geta = geta * i;
    //    }
        ans = ans + geta;

       //cout << i<<" "<<ama<<" "<<geta << endl;
    }
    cout << ans << endl;
    return 0;

}


Measured memory_bytes: 18672
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const long Mod = 1000000007;

    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var spl = input.ReadLine().Split(' ');
        var x = long.Parse(spl[0]);
        var y = long.Parse(spl[1]);

        long c = 0;
        long z = x;

        while(z <= y) {
            z *= 2;
            c++;
        }

        return c;
    }

    static int[] ToIntArray(string strs, int n) {
        var ret = new int[n];
        var spl = strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = int.Parse(spl[i]);
        return ret;
    }
}


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

int w, h;
int c[51][51];
int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};

void dfs(int y, int x){
	c[y][x] = 0;
	for(int i = 0; i < 8; i++){
		int ny = y + dy[i], nx = x + dx[i];
		if(0<=ny and ny<h and 0<=nx and nx<w and c[ny][nx]==1){
			dfs(ny, nx);
		}
	}
}

int solve(){
	int res = 0;
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			if(c[i][j] == 1){
				dfs(i, j);
				res++;
			}
		}
	}

	return res;
}

int main(void){
	while(scanf("%d%d", &w, &h) != EOF){
		if(w == 0 and h == 0) break;
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				scanf("%d", &(c[i][j]));
			}
		}
		printf("%d\n", solve());
	}

	return 0;
}



Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define c(n) cin>>n
#define c2(n,m) cin>>n>>m
#define c3(n,m,k) cin>>n>>m>>k
#define c4(n,m,k,l) cin>>n>>m>>k>>l
#define co(n) cout<<n<<endl
using namespace std;

int main(){
  long a=0,b,c=0,d,e,n;
  string s,t;
  c3(n,s,t);
  
  rep(i,0,n){
    rep(j,0,n-i){
      if(s[i+j]==t[j]) c++;
    }
    if(c==n-i){
      a=c;
      break;
    }
    else c=0;
  } 
  co(n*2-a);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    int a[N];
    for(int i = 0; i < N; i++){
        cin >> a[i];
    }
    int c = 0;
    while(true){
        bool f = true;
        for(int i = 0; i < N; i++){
            if(a[i]%2!=0){f=false; break;}
        }
        if(f){
            c++;
            for(int i = 0; i < N; i++){
                a[i]/=2;
            }
        }
        else break;
    }
    cout << c << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
void pre(){}
void solve(){
    long long int n,m,sum=0;cin>>n>>m;
    long long int arr[n];
    long long int ans = 0;
    for(long long int i=0;i<n;i++){
        cin>>arr[i];
        sum+=arr[i];
    }
    for(long long int i=0;i<n;i++){
        if(arr[i]>=(sum+4*m-1)/(4*m)){
            ans++;
        }
    }
    if(ans>=m){
        cout<<"Yes"<<"\n";
    }else{
        cout<<"No"<<"\n";
    }
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    pre();
    long long int num = 1;
    //cin>>num;
    for(long long int i=0;i<num;i++){
       	solve();
    }   
}


Measured memory_bytes: 256
#include <iostream>	//cin, cout
#include <vector>	//vector
#include <algorithm> //sort,min,max
#include <string>	//string
#include <ios>		//fixed
#include <iomanip>	//setprecision
#include <utility> //swap
#include <cstdlib>	//abs(int)
#include <cmath>	//sqrt
#include <sstream>	//stringstream,getline

using namespace std;

int main() {

	int a, b;
	cin >> a >> b;

	if (a > b) {
		cout << "a > b" << endl;
	}
	else if (a < b) {
		cout << "a < b" << endl;
	}
	else {
		cout << "a == b" << endl;
	}

	return 0;

}


Measured memory_bytes: 3092
H, W = map(int, input().split())
s = [list(str(input())) for i in range(H)]

if s[0][0] == "#":
    if s[0][1] == "." and s[1][0] == ".":
        print("No")
        exit()

if s[0][W-1] == "#":
    if s[0][W-2] == "." and s[1][W-1] == ".":
        print("No")
        exit()

if s[H-1][0] == "#":
    if s[H-1][1] == "." and s[H-2][0] == ".":
        print("No")
        exit()

if s[H-1][W-1] == "#":
    if s[H-1][W-2] == "." and s[H-2][W-1] == ".":
        print("No")
        exit()


for i in range(1, W-1):
    if s[0][i] == "#":
        if s[0][i-1] == "." and s[0][i+1] == "." and s[1][i] ==".":
            print("No")
            exit()
        if s[H-1][i-1] == "." and s[H-1][i+1] == "." and s[H-2][i] ==".":
            print("No")
            exit()

for i in range(1, H-1):
    if s[i][0] == "#":
        if s[i-1][0] == "." and s[i+1][0] == "." and s[i][1] ==".":
            print("No")
            exit()
        if s[i-1][W-1] == "." and s[i+1][W-1] == "." and s[i][W-2] ==".":
            print("No")
            exit()

for i in range(1, H-1):
    for j in range(1, W-1):
        if s[i][j] == "#":
            if s[i-1][j] == "." and s[i+1][j] == "." and s[i][j-1] =="." and s[i][j+1] ==".":
                print("No")
                exit()

print("Yes")


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            // ?´???°???????????????????????????
            bool[] res1 = new bool[1000000];
            for (int i = 0; i < res1.Length; i++)
                res1[i] = isPrime(i);

            int[] res2 = new int[1000000];
            int tmp = 0;
            for (int i = 0; i < res2.Length; i++)
            {
                tmp += (res1[i]) ? 1 : 0;
                res2[i] = tmp;
            }

            while (true)
            {
                string hikisu = Console.ReadLine();
                if (hikisu == null || hikisu == "")
                {
                    break;
                }
                Console.WriteLine(res2[int.Parse(hikisu)]);
            }
            //List<int> problem = new List<int>();

            //string hikisu;
            //while ((hikisu = Console.ReadLine()) != "")
            //{
            //    problem.Add(int.Parse(hikisu));
            //    Console.WriteLine(res2[int.Parse(hikisu)]);
            //}
            //for (int i = 0; i < problem.Count; i++)
            //{
            //    Console.WriteLine(res2[problem[i]]);
            //}
        }

        public static bool isPrime(int a)
        {
            if (a == 0 || a == 1) return false;
            else if (a == 2 || a == 3) return true;
            else if ((a % 2) == 0) return false;

            bool result = true;

            for (int i = 3; i <= Math.Round(Math.Sqrt(a)); i++)
            {
                if (a % i == 0)
                {
                    result = false;
                    break;
                }
            }
            return result;

        }

    }
}

Measured memory_bytes: 14048
#include <stdio.h>

void ShellSort(int A[],int N);
void insertionSort(int A[],int N,int g);

int cnt=0;
int g[1000];
int m;

int main(void){
	int i,N;
	scanf("%d",&N);
	int A[N];
	for(i=0;i<N;i++){
		scanf("%d",&A[i]);
		}
		
	ShellSort(A,N);
	
    printf("%d\n",m);
	for(i=m-1;i>=0;i--){
	if(i<m-1){
		printf(" ");
	}
	  printf("%d",g[i]);
	}
    printf("\n");
	printf("%d\n",cnt);
	for(i=0;i<N;i++){
		printf("%d\n",A[i]);
	}
	return 0;
}

void ShellSort(int A[],int N){
	int i;
	g[0]=1;
	for(i=0;;i++){
		if(g[i]>N){
			break;
		}
			g[i+1]=g[i]*3+1;
			m++;
	}
	
	for(i=m-1;i>=0;i--){
		insertionSort(A,N,g[i]);
	}
}

void insertionSort(int A[],int N,int g){
	int i,v,j;
	for(i=g;i<=N-1;i++){
		v=A[i];
		j=i-g;
		while(j>=0 && A[j]>v){
			A[j+g]=A[j];
			j=j-g;
			cnt++;
		}
		A[j+g]=v;
	}
}


Measured memory_bytes: 5692
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
int n,l;
typedef pair<ld,ld> wat;
wat operator + (wat a,wat b)
{return wat(a.fi+b.fi,a.se+b.se);}
wat operator - (wat a,wat b)
{return wat(a.fi-b.fi,a.se-b.se);}
wat qs[666666],tot;
int main()
{
	scanf("%d%d",&n,&l); int h=0,t=0;
	for(int i=1;i<=n;++i)
	{
		ll tt,v;
		scanf("%lld%lld",&tt,&v);
		wat cur(v,tt*v); tot=tot+cur;
		while(tot.fi>l+1e-9)
		{
			ld gg=tot.fi-l;
			if(gg>=qs[h].fi) {tot=tot-qs[h++]; continue;}
			ld vv=gg*qs[h].se/qs[h].fi;
			qs[h].se-=vv; tot.se-=vv;
			qs[h].fi-=gg; tot.fi-=gg;
		}
		while(h!=t&&qs[t-1].se/qs[t-1].fi>cur.se/cur.fi)
			cur=cur+qs[--t];
		qs[t++]=cur;
		printf("%.10lf\n",tot.se/tot.fi);
	}
}

Measured memory_bytes: 18688
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
	long long n,t,minn=30,sum;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		sum=0;
		cin>>t;
		while((t&1)==0){t>>=1;++sum;}
		minn=min(minn,sum);
	}
	cout<<minn<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
const int inf=1145141919;
const int dd[]={0,-1,0,1,0};
using namespace std;
int p[50],q[51],r[51];
signed main(){
	int n,a,b;
	int i,j;
	cin>>n>>a>>b;
	for(i=0;i<n;i++)
		cin>>p[i];
	q[0]=1;
	for(i=0;i<n;i++)
		for(j=i;j>=0;j--){
			int x=r[j]+p[i];
			if(x>r[j+1])
				q[j+1]=q[j],r[j+1]=x;
			else if(x==r[j+1])
				q[j+1]+=q[j];
		}
	int x=0,y=-1;
	for(i=a;i<=b;i++){
		if(y!=-1&&r[i]*(i-1)!=y*i)
			break;
		x+=q[i];
		y=r[i];
	}
	cout<<fixed<<setprecision(15)<<(double)r[a]/a<<endl<<x<<endl;
}


Measured memory_bytes: 636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int BIG = 2e9;
const int maxN = 2e5 + 55;

ll k, m;
ll a[2 * maxN];
int n;
vector<int> pos[maxN];
vector<pair<int, ll> > jump;

pair<int, ll> nxtPos(int i){
    int x = lower_bound(pos[a[i]].begin(), pos[a[i]].end(), i) - pos[a[i]].begin();
    int j = pos[a[i]][x + 1];
    ll len = j - pos[a[i]][x] + 1;
    return make_pair((i + len) % n, len);
}

void preCal(){
    jump.push_back(nxtPos(0));
    while(true){
        int pos = jump.back().first;
        if(pos == 0){
            break;
        }
        jump.push_back(nxtPos(pos));
    }
}

deque<int> ans;
bool mrk[maxN];

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

    cin >> n >> k;

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

    for(int i = 0; i < n + n; i++){
        pos[a[i]].push_back(i);
    }

    preCal();

    for(int i = 0, L = (int)jump.size(); i < L; i++){
        //cout << jump[i].first << ' ' << jump[i].second << '\n';
        m += jump[i].second;
    }

    ll rem = (((ll)n % m) * (k % m)) % m;

    int from = 0;
    ll psum = 0, step = rem;

    for(int i = 0, L = (int)jump.size(); i < L; i++){
        psum += jump[i].second;
        if(psum <= rem){
            from = jump[i].first;
            step = rem - psum;
        }
    }

    for(ll i = 1; i <= step; i++, from = (from + 1) % n){
        if(mrk[a[from]]){
            while(!ans.empty() && ans.back() != a[from]){
                mrk[ans.back()] = false;
                ans.pop_back();
            }
            mrk[a[from]] = false;
            ans.pop_back();
        } else {
            ans.push_back(a[from]);
            mrk[a[from]] = true;
        }
    }

    while(!ans.empty()){
        cout << ans.front() << ' ';
        ans.pop_front();
    }

    return 0;
}


Measured memory_bytes: 20468
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

#define MIN_INT -2147483648
#define MAX_INT 2147483647
#define MIN_LONG -9223372036854775808L
#define MAX_LONG 9223372036854775807L
#define PI 3.141592653589793238462643383279502884L

#define long long long int

using std::vector;
using std::map;
using std::set;
using std::string;
using std::pair;
using std::cin;
using std::cout;
using std::cerr;

// @author: pashka

int main() {
    std::ios::sync_with_stdio(false);

    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<int> c(26);
    for (int i = 0; i < n; i++) {
        c[s[i] - 'a']++;
    }
    long res = 1;
    for (int i = 0; i < 26; i++) {
        res = (res * (c[i] + 1)) % 1000000007;
    }
    res--;
    if (res < 0) res += 1000000007;
    cout << res << "\n";

    return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
int main(){
  int W,H,x,y,r;
  scanf("%d%d%d%d%d",&W,&H,&x,&y,&r);
  if(x+r <= W && y+r <= H && x-r >= 0 && y-r >= 0){ printf("Yes\n");}
  
else{
printf("No\n");}
 return 0;
}

Measured memory_bytes: 584
using System;
using System.Linq;
public class Hello{
    public static void Main(){
        // Your code here!
        
        int n = int.Parse(Console.ReadLine());
        int keta = n.ToString().Length;
        
        switch(keta){
            case 1: Console.WriteLine(n);      break;
            case 2: Console.WriteLine(9);      break;
            case 3: Console.WriteLine(n-90);   break;
            case 4: Console.WriteLine(909);    break;
            case 5: Console.WriteLine(n-9090); break;
            case 6: Console.WriteLine(90909);  break;
        }
        
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define pi 3.14159265359
using namespace std;
const long long INF=1e9+7;
const string alp="abcdefghijklmnopqrstuvwxyz"; //26
const string ALP="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
//const ll MOD=998244353LL;
//const ll MOD=1777777777LL;


int main() {
  ll N;
  cin>>N;
  vl a(N);
  rep(i,N) cin>>a[i];
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  ll ans=0;
  for(int i=0;i<N;i++){
    ans+=a[i/2];
  }
  ans-=a[0];
  cout<<ans<<endl;
  
}


Measured memory_bytes: 4840
#include<stdio.h>
int main()
{
	int a[100000],n,k,r,s,i;
	while(scanf("%d%d",&n,&k),n)
	{
		for(i=0;i<n;++i)scanf("%d",&a[i]);
		for(s=r=i=0;i<k;++i)s+=a[i];
		for(i=k;i<n;++i)s=s-a[i-k]+a[i],r<s?r=s:0;
		printf("%d\n",r);
	}
}

Measured memory_bytes: 0
package main

import "fmt"

// 2018-08-01T16:32:46+0800
// 2018-08-01T16:45:39+0800
// 2018-08-01T16:57:24+0800
// Giving up and looking up for help
// 2018-08-01T17:19:01+0800
// 2018-08-01T17:36:10+0800
// 2018-08-01T18:30:08+0800
func main() {
	var N, C int
	fmt.Scanf("%d%d", &N, &C)
	x := make([]int, N)
	v := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scanf("%d%d", &x[i], &v[i])
	}
	// sum, max
	ma := make([]int, N)
	mb := make([]int, N)
	t := 0
	sa := v[0]
	ma[0] = v[0] - x[0]
	sb := v[N-1]
	mb[N-1] = v[N-1] - C + x[N-1]
	for i, ii := 1, N-2; i < N; i++ {
		sa += v[i]
		t = sa - x[i]
		if t > ma[i-1] {
			ma[i] = t
		} else {
			ma[i] = ma[i-1]
		}
		sb += v[ii]
		t = sb - C + x[ii]
		if t > mb[ii+1] {
			mb[ii] = t
		} else {
			mb[ii] = mb[ii+1]
		}
		ii--
	}
	t, n := 0, 0
	back := 0
	for i := -1; i < N; i++ {
		if i == -1 {
			t = 0
			back = 0
		} else {
			t = ma[i]
			back = x[i]
		}
		if i+1 < N && mb[i+1]-back > 0 {
			t += mb[i+1] - back
		}
		if t > n {
			n = t
		}
	}
	for i := N; i >= 0; i-- {
		if i == N {
			t = 0
			back = 0
		} else {
			t = mb[i]
			back = C - x[i]
		}
		if i > 0 && ma[i-1]-back > 0 {
			t += ma[i-1] - back
		}
		if t > n {
			n = t
		}
	}
	fmt.Println(n)
}

func wrongSolution() {
	var N, C int
	fmt.Scanf("%d%d", &N, &C)
	x := make([]int, N)
	v := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scanf("%d%d", &x[i], &v[i])
	}
	var sa, na, ia, sb, nb, ib int
	t := 0
	for i, ii := 0, N-1; i < N; i++ {
		sa += v[i]
		t = sa - x[i]
		if t > na {
			na = t
			ia = i
		}
		sb += v[ii]
		t = sb - C + x[ii]
		if t > nb {
			nb = t
			ib = ii
		}
		ii--
	}
	n := 0
	if ia >= ib {
		fmt.Println("ia >= ib", ia, ib)
		if na > nb {
			n = na
		} else {
			n = nb
		}
	} else {
		if na > nb {
			n = na
			if nb-x[ia] > 0 {
				n += nb - x[ia]
			}
		} else {
			n = nb
			if na-C+x[ib] > 0 {
				n += nb - C + x[ib]
			}
		}
	}
	fmt.Println(n)
}

Measured memory_bytes: 7040
fn read_stdin() -> String {
    use std::io::Read;
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();
    input
}

fn scan<'a, I: Iterator<Item = &'a str>, T: std::str::FromStr>(tokens: &mut I) -> T {
    tokens.next().unwrap().parse().ok().unwrap()
}

fn vec<T, F: FnMut(usize) -> T>(n: usize, mut f: F) -> Vec<T> {
    (0..n).map(|i| f(i)).collect()
}

fn main() {
    let input = read_stdin();
    let tokens = &mut input.split_whitespace();
    let n: usize = scan(tokens);
    let b: Vec<usize> = vec(n - 1, |_| scan(tokens));
    let mut ans = b[0];
    for i in 0..n - 2 {
        ans += std::cmp::min(b[i], b[i + 1]);
    }
    ans += b[n - 2];
    println!("{}", ans);
}


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

typedef long long   ll;
typedef long double ld;
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k;
    cin >> n >> k;
    int minidx;
    int pmin=INT32_MAX;
    vector<int> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }

    int ans=1;
    if(k<n) ans = 2 + (n-k-1)/(k-1);
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 640
#include<cstdio>
#include<algorithm>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

#define sq(x) (x)*(x)

int n,r;
double a[20],b[20],c[20];

double dfs(int i,int j,int S){
	if(j+(n-i)<r || r<j) return -1;

	if(n==i){
		double sum=0;
		rep(l,n) rep(k,l) if(S&(1<<k) && S&(1<<l)) {
			sum+=sq(a[k]-a[l])+sq(b[k]-b[l])+sq(c[k]-c[l]);
		}
		return sum;
	}

	return max(dfs(i+1,j,S),dfs(i+1,j+1,S|(1<<i)));
}

int main(){
	scanf("%d%d",&n,&r);
	rep(i,n) scanf("%lf%lf%lf",a+i,b+i,c+i);

	printf("%.9f\n",dfs(0,0,0));

	return 0;
}

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

using namespace std;

typedef long long ll;

int main(){
	long double a, b, h, m;
	cin >> a >> b >> h >> m;
	long double deg_m = m * 6;
	long double deg_h = h * 30 + m/2;
	long double deg = min(360 - abs(deg_m - deg_h),abs(deg_m - deg_h));
	deg = deg/180 * M_PI;
	long double rsq= (long double)(a*a+b*b) - (long double)(2 *a*b) *cos(deg);
	cout<<fixed<<setprecision(9)<<sqrt(rsq)<<endl;
}


Measured memory_bytes: 4168
N, K = map(int, input().split())

if K <= N:
    pos = (N - K + 1) / N
else:
    pos = 0

if pos != 1:
    for i in range(1,K):
        if i == N+1:
            break
        point = i
        cnt = 0
        while point < K:
            point *= 2
            cnt += 1
        pos += (1/N) * (0.5 ** cnt)

print(pos)

Measured memory_bytes: 39024
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <numeric>
#include <climits>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <utility>
////////////////////////////////////////////////
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define FOR(i, m, n) for (int i = (int)m; i < (int)n; i++)
#define REPvec(itr, mp) for (auto itr = mp.begin(); itr != mp.end(); itr++)
#define REPe(e, mp) for (auto& e : mp)
#define all(x) x.begin(), x.end()
////////////////////////////////////////////////
using namespace std;
using ll = long long int;
using vecint = vector<int>;
using vecll = vector<ll>;
using vec2int = vector<vector<int>>;
using P = pair<int, int>;
const ll MOD = 1000000007;  // 1e9+7
////////////////////////////////////////////////
////////////////////////////////////////////////
int main() {
  ////////////////////////////////////////////////
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ////////////////////////////////////////////////
  int n;
  cin >> n;
  vector<string> s(n);
  int ans = 0;
  int x, y, z;
  x = y = z = 0;
  REP(i, n) {
    string e;
    cin >> e;
    if (e.front() == 'B' && e.back() == 'A') {
      z++;
    } else if (e.back() == 'A') {
      x++;
    } else if (e.front() == 'B') {
      y++;
    }
    REP(i, e.size() - 1) {
      if (e.substr(i, 2) == "AB") {
        ans++;
        i++;
      }
    }
  }
  if (x == 0 && y == 0 && z > 0) {
    ans += z - 1;
  } else {
    ans += min(x, y) + z;
  }
  cout << ans << endl;
}
//////////////////////////////////////////////


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

int main() {
  
  string s; cin >> s; int posA, posZ;
  
  int L = s.size();
  
  for (int i = 0; i < L; i++) {
    if (s.at(i) == 'A') {
      posA = i; break;
    }
  }
  
  for (int i = L - 1; 0 < i; i--) {
    if (s.at(i) == 'Z') {
      posZ = i; break;
    }
  }
  
  cout << posZ - posA + 1 << endl;
  
}

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

int main()
{
	int A, B;
	cin >> A >> B;
	if ( A <= 8 && B <= 8 ) {
		cout << "Yay!" << endl;
	} else {
		cout << ":(" << endl;
	}
	return ( 0 );
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()


using namespace std;

typedef long long ll;

static const long long MOD = 1000000007;

int ans, q;
string s, fr, bk;


int main(void) {
    cin >> s >> q;
    bool rv = false;
    rep(i, 0, q) {
        int t;
        scanf("%d", &t);
        if (t==1) {
            if(rv) rv = false;
            else rv = true;
        } else {
            int f;
            char c;
            cin >> f >> c;
            if (!rv) {
                if (f==1) fr += c;
                else bk += c;
            } else {
                if (f==1) bk += c;
                else fr += c;
            }
        }
    }

    if (!rv) {
        reverse(fr.bg, fr.en);
        cout << fr << s << bk << endl;
    } else {
        reverse(s.bg, s.en);
        reverse(bk.bg, bk.en);
        cout << bk << s << fr << endl;

    }



	return 0;
}


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

int main(){
  char c[4];
  char op1, op2, op3;
  int n[4], ans;

  cin >> c;
  for (int i=0; i<4; i++){
    n[i] = c[i] - '0';
  }

  for(int i=0; i<8; i++){
    ans = n[0];
    if(i < 4){
      ans += n[1];
      op1 = '+';
    } else {
      ans -= n[1];
      op1 = '-';
    }
    if(i%4 == 0 || i%4 == 1){
      ans += n[2];
      op2 = '+';
    } else {
      ans -= n[2];
      op2 = '-';
    }
    if(i%2 == 0){
      ans += n[3];
      op3 = '+';
    } else {
      ans -= n[3];
      op3 = '-';
    }
    if(ans == 7){
      cout << c[0] << op1 << c[1] << op2 << c[2] << op3 << c[3] << "=7" << endl;
      break;
    }
  }

  return 0;
}


Measured memory_bytes: 256
def gcd(x,y):
    if y==0: return x
    return gcd(y,x%y)

def lcm(x,y):
    return x*y//gcd(x,y)

n = int(input())
ans = 1
for i in range(n):
    a = int(input())
    ans = lcm(ans,a)
print(ans)

Measured memory_bytes: 3060
from itertools import permutations
import math
menu=5
times=[int(input()) for i in range(menu)]
orders=list(permutations(times,menu))
minimum=sum(math.ceil(time/10)*10 for time in times)
for order in orders:
    total=order[0]
    for i in range(1,menu):
        total+=math.ceil(order[i]/10)*10
    minimum=min(minimum,total)
print(minimum)

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


namespace atPra98A
{
    class Class1
    {
        static void Main()
        {
            var N = int.Parse(Console.ReadLine());
            if (N <= 999) Console.WriteLine("ABC");
            else Console.WriteLine("ABD");

        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; i++)
#define PI 3.14159265358979323846
#define vl vector<long long>
using namespace std;
using ll = long long;
using ld = long double;

// ----本問について----
// 問題：
// 問題文URL：
// ------------------

// ----ここから本問のソースコード----


// グローバル変数（入力）
ld a,b;

void solve() { cout << (ll)floor(a * b) << endl; }

int main() {
  cin >> a >> b;
  solve();
  return 0;
}


Measured memory_bytes: 3748
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

vector<bool> eratosthenes;

void create_eratosthenes(int n) {
    eratosthenes.resize(n + 1, true);
    eratosthenes[0] = eratosthenes[1] = false;
    
    for(int i = 2; (i * i) <= n; i++) {
        if (!eratosthenes[i]) {
            continue;
        }
        
        for (int ii = 2; (i * ii) <= n; ii++) {
            eratosthenes[i * ii] = false;
        }
    }
}

bool is_prime(int n) {
    return eratosthenes[n];
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // std::ifstream in("input.txt");
    // std::cin.rdbuf(in.rdbuf());
    ll x;
    cin >> x;
    create_eratosthenes(x * 2);
    reps(i, x, x * 2) {
        if (is_prime(i)) {
            cout << i << endl;
            break;
        }
    }
    return 0;
}


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


int main() {
  string S, T;
  cin >> S >> T;
  int cnt=0;
  for(int i=0; i<3; i++){
    if(S.at(i) == T.at(i)){
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
  
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)

n = int(input())
A = list(map(int, input().split()))
q = int(input())
readline = sys.stdin.readline
BC = [[int(i) for i in readline().split()] for _ in range(q)]

d = {}
for a in A:
    d[a] = d.get(a, 0) + 1

#MAX_N = 10**5+5
#l_conv = [0]*MAX_N
#
#for b,c in BC:
#    l_conv[b] = c

ans = []
su = sum(A)

for b,c in BC:
    if b in d:
        su = su - b*d[b] + c*d[b]
        d[c] = d.get(c, 0) + d[b]
        d.pop(b)
        ans.append(su)
    else:
        ans.append(su)

print(*ans)

Measured memory_bytes: 37968
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

ll f(ll a) {
    a++;
    ll ans = 0;
    rep(i, 50) {
        // i桁目に1が何個あるかを求める
        ll loop = 1LL<<(i+1);
        ll cnt = (a / loop) * (loop / 2) ;
        cnt += max(0LL, a % loop - loop / 2);
        if (cnt % 2 == 1) ans += 1LL<<i;
    }
    return ans;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll a, b;
    cin >> a >> b;
    cout << (f(a-1) ^ f(b)) << endl;
}

Measured memory_bytes: 384
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author silviase
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CTsundoku solver = new CTsundoku();
        solver.solve(1, in, out);
        out.close();
    }

    static class CTsundoku {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            long k = in.nextLong();
            long[] a = new long[n + 1];
            long[] b = new long[m + 1];
            for (int i = 1; i <= n; i++) {
                a[i] = in.nextLong();
                a[i] += a[i - 1];
            }
            for (int i = 1; i <= m; i++) {
                b[i] = in.nextLong();
                b[i] += b[i - 1];
            }

            // out.println(Arrays.toString(a));
            // out.println(Arrays.toString(b));

            int max = -1;
            for (int i = 0; i <= n; i++) {
                // i 冊読んでいるとする
                if (a[i] > k) break;
                int ng = -1;
                int ok = b.length;
                while (Math.abs(ok - ng) > 1) {
                    int mid = (ok + ng) / 2;
                    if (a[i] + b[mid] > k) {
                        ok = mid;
                    } else {
                        ng = mid;
                    }
                }
                // out.println(i + " " + ng);
                max = Math.max(max, i + ng);
            }

            out.println(max);

        }

    }
}



Measured memory_bytes: 64724
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int[] acc = new int[100001];
		for (int i = 2; i < acc.length; i++) {
			long j = 2;
			long mul = 1;
			while (j * j < i) {
				if (i % j == 0) {
					mul *= i;
					if (mul >= 2 * i) break;
				}
				j++;
			}
			if (j * j == i) {
				mul *= j;
			}
			if (mul >= 2 * i) acc[i] = 1;
			acc[i] += acc[i - 1];
		}
		int Q = sc.nextInt();
		PrintWriter writer = new PrintWriter(System.out);
		for (int i = 0; i < Q; i++) {
			int N = Integer.parseInt(sc.next());
			writer.println(acc[N]);
		}
		writer.flush();
	}

}



Measured memory_bytes: 72044
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
typedef long long LL;
const int N = 41;
 
int n;
char a[N][N];
LL dp[2][N][N][N][N];
 
LL dfs(int t,int q,int w,int e,int r){
	// t=0 : tree; t=1 : forest
	if(q>w || e>r) return 1;
	LL &res = dp[t][q][w][e][r];
	if(~res) return res;
	res = 0;
	if(t==0){
		if( (w-q)%2 || (r-e)%2 ) return 0;
		int d1,u1,d2,u2;
		if(q==w) d1 = u1 = q; else d1 = q+1, u1 = w-1;
		if(e==r) d2 = u2 = e; else d2 = e+1, u2 = r-1;
		rep(i,d1,u1) rep(j,d2,u2) if(a[i][j]){
			res += dfs(1,q,i-1,i+1,w) * dfs(1,e,j-1,j+1,r);
		}
	}else{
		res = dfs(0,q,w,e,r);
		rep(i,q,w-1) rep(j,e,r-1) res += dfs(0,q,i,j+1,r) * dfs(1,i+1,w,e,j);
	}
	return res;
}
 
int main(){
	cin>>n;
	n <<= 1;
	rep(i,1,n) cin>>(a[i]+1);
	if(n==2){
		cout<<a[1][2]<<endl;
		return 0;
	}
	rep(i,1,n) rep(j,1,n) a[i][j] -= '0';
	memset(dp,-1ll,sizeof dp);
	LL ans = 0ll;
	rep(i,3,n-1) if(a[1][i]) ans += dfs(1,2,i-1,i+1,n);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 44416
a,b = map(int,input().split())
 
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:   
      n /= i
      table.append(i)
    i += 1
  if n > 1:
    table.append(n)
  return table
  
s = set(prime_decomposition(a))
t = set(prime_decomposition(b))
 
print(len(s&t) + 1) 

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

namespace ConsoleApplication84
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = int.Parse(Console.ReadLine());
            int[] b = new int[3];
            b[0] = a%10;
            b[1] = (a % 100 - b[0])/10;
            b[2] = (a - b[0] - b[1])/100;
            int c = b[0] * 100 + b[1] * 10 + b[2];
            if (a == c)
                Console.WriteLine("Yes");
            else Console.WriteLine("No");
            /*Console.WriteLine("{0} {1} {2}",b[0],b[1],b[2]);*/
        }
    }
}


Measured memory_bytes: 13140
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include <iomanip>
using namespace std;

int main(){
	int h,w,f=0;
	cin>>h>>w;
	string s="Yes";
	vector<vector<char>> a(100,vector<char>(100));
	vector<int>b(4);
	b={0,1,0,-1};
	vector<int>c(4);
	c={1,0,-1,0};
	for(int i=0;i<=h+1;i++){
		for(int j=0;j<=w+1;j++){
			if(i==0||i==h+1){
				a[i][j]='&';
			}
			else if((j==0||j==w+1)){
				a[i][j]='&';
			}
			else{
				cin>>a[i][j];
			}
		}
	}
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			for(int k=0;k<4;k++){
				if(a[i+b[k]][j+c[k]]!='#'&&a[i][j]=='#'){
					f++;
				}
			}
			if(f==4){
				s="No";
			}
			f=0;
		}
	}
	cout<<s<<endl;
	return 0;
	
}

Measured memory_bytes: 256
import math

N=int(input())
lf=list(map(int,input().split()))

result=0
tr=[0 for _ in range(N+1)]
miki=0
max_miki=[0 for _ in range(N+1)]

for i in range(N+1):
    if i==0:
        max_miki[i]=1
    else:
        max_miki[i]=(max_miki[i-1]-lf[i-1])*2

i=N

while i>=0:
    if i==N:
        if lf[N]>max_miki[N]:
            result=-1
            break
        tr[N]=lf[N]
        result+=lf[N]
        i-=1
    else:
        miki=int(min(tr[i+1]+lf[i],max_miki[i]))
        tr[i]=miki
        result+=miki

        if (miki-lf[i])*2<tr[i+1]:
            result=-1
            break
        i-=1

print(result)

Measured memory_bytes: 679916
from operator import itemgetter

N, H = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]

h = H
strongest = dict(zip(["a", "b"], max(AB)))

count = 0
for a, b in sorted(AB, key=itemgetter(1), reverse=True):
	if strongest["a"] < b:
		h -= b
		count += 1
		if h <= 0:
			print(count)
			exit()
	else:
		break

count += (h // strongest["a"]) + (0 != (h % strongest["a"]))
print(count)


Measured memory_bytes: 29800
import java.util.Scanner;

public class Main {
    public static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) throws Exception {
        while (sc.hasNext()) {
            int h = sc.nextInt();
            int w = sc.nextInt();
            if (h == 0 && w == 0) break;
            for (int i = 0; i < h; i++) {
                StringBuilder sb = new StringBuilder();
                for (int j = 0; j < w; j++) {
                    if ((i+j)%2==0) {
                        sb.append("#");
                    } else {
                        sb.append(".");
                    }
                }
                System.out.println(sb.toString());
            }
            System.out.println("");
        }
    }
}

Measured memory_bytes: 28700
a,b,c,d = map(int,input().split())
if b<=c or a>=d:
  print(0)
else:
  if a<=c and b<=d:
    print(b-c)
  elif a<=c and b>d:
    print(d-c)
  elif a>=c and b<=d:
    print(b-a)
  elif a>=c and b>d:
    print(d-a)
    


Measured memory_bytes: 2940
/*input
1000000000
*/
#include "bits/stdc++.h"
#define pb push_back
#define ll long long
using namespace std;
#define N 400005
#define int long long


signed main()
{
	int x;
	cin>>x;

	int ans = 0;

	ans = 1000*(x/500);
	x = x%500;

	ans+= 5*(x/5);
	//x = x%1000;
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    int a[30]={};
    char c[100]={},mc;
    int ma=0;
    for(int i=0;i<n;i++){
      cin>>c[i];
      a[c[i]-'A']++;
    }
    int f=0;
    for(int i=0;i<30;i++){
      if(a[i]==ma)f=1;
      if(a[i]>ma){
    ma=a[i];
    mc=i;
    f=0;
      }
    }
    if(f)cout<<"TIE"<<endl;
    else {
      int cnt[30]={};
      int ma2=0;
      for(int i=0;i<n;i++){
    int nc=c[i]-'A';
    cnt[nc]++;
    if(nc!=mc){
      ma2=max(ma2,cnt[nc]);
    }
    if(cnt[mc]>ma2+n-1-i){
      cout<<(char)(mc+'A')<<" "<<i+1<<endl;
      break;
    }
      }
    }
  }
  return 0;
}


Measured memory_bytes: 3084
S = input().strip()

s0 = int(S[:2])
s1 = int(S[2:])

if 1 <= s0 <= 12 and 1 <= s1 <= 12:
    print("AMBIGUOUS")
elif 1 <= s0 <= 12 and not 1 <= s1 <= 12:
    print("MMYY")
elif not (1 <= s0 <= 12) and 1 <= s1 <= 12:
    print("YYMM")
elif not (1 <= s0 <= 12) and not 1 <= s1 <= 12:
    print("NA")



Measured memory_bytes: 3060
def getRunLengthEncoding(Ss):
    anss = []
    Ss += '$'
    SPrev = Ss[0]
    num = 1
    for S in Ss[1:]:
        if S == SPrev:
            num += 1
        else:
            anss.append((SPrev, num))
            SPrev = S
            num = 1
    return anss

N = int(input())
Ss = input()

anss = getRunLengthEncoding(Ss)
print(len(anss))


Measured memory_bytes: 10484
#include<bits/stdc++.h>
using namespace std;
int main() {
int i,j,l,t,a,b,k,p=0,x,n=0;
string s1,s2;
 cin>>s1>>s2;
 string s=s1+s2;
for(i=0;i<s.size();i++){
    n=n*10+s[i]-'0';
}
float d;
  d=sqrt((double)n);
  l=d;

  if(l==d){cout<<"Yes\n";}
  else{cout<<"No\n";}





}


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

#define rep(i, x, n) for (int i = x; i < n; i++)
typedef long long ll;

const int INF = 1e9 + 7;

using namespace std;

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

	int n, m, r;
	cin >> n >> m >> r;

	vector<int> r_vec(r);
	rep (i, 0, r) {
		cin >> r_vec[i];
		r_vec[i]--;
	}

	vector<vector<ll>> d(n, vector<ll>(n, INF));
	rep (i, 0, n)
		d[i][i] = 0;

	rep (i, 0, m) {
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;

		d[a][b] = c;
		d[b][a] = c;
	}

	rep (k, 0, n) {
		rep (i, 0, n) {
			rep (j, 0, n) {
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}

	int res = INF;
	sort(r_vec.begin(), r_vec.end());
	do {
		int now = r_vec[0];
		int tmp = 0;
		for (int i = 1; i < r_vec.size(); i++) {
			tmp += d[now][r_vec[i]];
			now = r_vec[i];
		}
		res = min(res, tmp);
	} while (next_permutation(r_vec.begin(), r_vec.end()));

	cout << res << endl;
	return 0;
}


Measured memory_bytes: 640
from collections import deque
s = input()
q = int(input())
array = [list(map(str, input().split())) for i in range(q)]
#print(array)
d = deque(s)
reverse = 1
for i in range(q):
    if array[i][0] == "1":
        reverse *= -1
    elif (array[i][1] == "1") and (reverse == 1):
        d.appendleft(array[i][2])
    elif (array[i][1] == "1") and (reverse == -1):
        d.append(array[i][2])
    elif (array[i][1] == "2") and (reverse == 1):
        d.append(array[i][2])
    elif (array[i][1] == "2") and (reverse == -1):
        d.appendleft(array[i][2])

if reverse == -1:
    d.reverse()

d_str = "".join(list(d))
print(d_str)

Measured memory_bytes: 117208
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
typedef long long ll;
ll a, b, c, d;
map<ll, ll>ma;
ll min(ll a, ll b)
{
	if (a < 0)
		return b;
	if (b < 0)
		return a;
	return a < b ? a : b;
}
ll solve(ll n)
{
	if (n == 0)
		return 0;
	if (n == 1)
		return d;
	if (ma.count(n))
		return ma[n];
	ll l2 = (n / 2) * 2;
	ll r2 = ((n + 1) / 2) * 2;
	ll l3 = (n / 3) * 3;
	ll r3 = ((n + 2) / 3) * 3;
	ll l5 = (n / 5) * 5;
	ll r5 = ((n + 4) / 5) * 5;
	ll res = min(1e18, n * d);
	res = min(res, llabs(n - l2) * 1LL * d + a + solve(l2 / 2));
	res = min(res, llabs(n - r2) * 1LL * d + a + solve(r2 / 2));
	res = min(res, llabs(n - l3) * 1LL * d + b + solve(l3 / 3));
	res = min(res, llabs(n - r3) * 1LL * d + b + solve(r3 / 3));
	res = min(res, llabs(n - l5) * 1LL * d + c + solve(l5 / 5));
	res = min(res, llabs(n - r5) * 1LL * d + c + solve(r5 / 5));
	ma[n] = res;
	return res;
}
int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		ll n;
		cin >> n >> a >> b >> c >> d;
		ma.clear();
		cout << solve(n) << endl;
	}
	return 0;
}

Measured memory_bytes: 4404
#include <bits/stdc++.h>
#define ll long long
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
#define ull unsigned long long
#define mk make_pair
#define pb push_back
#define eps 1e-12
#define MAXN 200009
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	string s;
	cin>>s;
	for(int i=0;i<3;i++)
	{
		if(s[i]==s[i+1])
		{
			cout<<"Bad"<<endl;
			return 0;
		}
	}
	cout<<"Good"<<endl;
	return 0;
}

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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
#define dump(x)  cout << #x << " = " << (x) << endl;

typedef long long ll;
typedef pair<int, int> ii;
const int mod = 1e9+7;
const ll INF = 1e18;
const int inf = 1e9;

void solve()
{
  int n; cin>>n;
  vector<int> a(n, 0);
  rep(i,n) {
    cin>>a[i];
    a[i]--;
  }
  int now=0;
  int cnt=0;
  vector<int> d(n, 0);
  while(true){
    if(d[now]) {
      cout << -1 << endl;
      return;
    }
    d[now]=1;
    now = a[now];
    cnt++;
    if (now==1) {
      cout << cnt << endl;
      return;
    }
  }
}

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


Measured memory_bytes: 1024