akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define All(a) a.begin(),a.end()
#define INF 1000000007
const int MOD = 1000000007;
//accumulate(vec.begin(), vec.end(), 0)
//std::sort(v.begin(), v.end(), std::greater<Type>());
//set_intersection(x, x+7, y, y+6, back_inserter(v));
//set_union(x, x+7, y, y+6, back_inserter(v));
//set_difference(x, x+7, y, y+6, back_inserter(v));

int gcd(int x,int y){
  if(x%y==0) return y;
  else return gcd(y,x%y);
}

bool isPrime(int n){
  if(n < 2) return false;
  else if(n == 2) return true;
  else if(n%2==0) return false;

  for(int i=3;i<=sqrt(n);i++){
    if(n%i==0) return false;
  }
  return true;
}


int main(){
  int a,b;
  cin >> a >> b;
  cout<< (a-1)*(b-1) <<endl;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.stream.IntStream;
import java.util.stream.Stream;
import java.util.Scanner;
import java.util.OptionalInt;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
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);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int A = in.nextInt();
            int B = in.nextInt();
            int C = in.nextInt();
            int D = in.nextInt();
            int E = in.nextInt();

            int t = Stream.of(A, B, C, D, E).mapToInt(n -> n % 10).filter(n -> n > 0).min().orElse(10);
            int sum = Stream.of(A, B, C, D, E).mapToInt(n -> (int) Math.ceil(n / 10.0) * 10).sum();
            out.println(sum - (10 - t));
        }

    }
}



Measured memory_bytes: 30164
import java.io.*;
import java.util.*;

public class Main {

	static int n;
	static long [][]dp;
	public static void main(String[] args) throws IOException{
		BufferedReader br = new  BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int h = Integer.parseInt(st.nextToken());
		int w = Integer.parseInt(st.nextToken());
		char [][] g = new char [h][w];
		for (int i=0;i<h;i++)
		{
			String s = br.readLine();
			for(int j=0;j<s.length();j++)
			{
				g[i][j]=s.charAt(j);
			}
		}
		dp=new long [h][w];
		for(int i=0;i<h;i++)
		{
			Arrays.fill(dp[i], -1);
		}
		long ans = path(g,h-1,w-1);
		ans = ans%(7+1000000000L);
		System.out.println(ans);
		
	}
//	public static void path(char [] [] g, int h,int w)
//	{
//		if(w==h&&h==0)
//			n++;
//		else
//		{
//			if(h-1>-1)
//			{
//				if(g[h-1][w]=='.')
//					if(dp[h-1][w]==-1)
//					{
//						dp[h-1][w]=0;	
//						path(g,h-1,w);		
//					}
//					
//			}
//			if(w-1>-1)
//			{
//				if(g[h][w-1]=='.')
//					if(dp[h][w-1]==-1)
//					{
//						dp[h][w-1]=0;
//						path(g,h,w-1);
//					}
//			}
//		}
//	}
	public static long path(char [] [] g , int h, int w)
	{
		if(h==0&&w==0)
			return 1;
		else
		{
			long s1=0;
			long s2=0;
			if(h-1>-1)
				if(g[h-1][w]=='.')
					if(dp[h-1][w]==-1)
					{
						s1=path(g, h-1, w)%(7+1000000000L);
						dp[h-1][w]=s1;
					}
					else
						s1=dp[h-1][w];
			if(w-1>-1)
					if(g[h][w-1]=='.')
						if(dp[h][w-1]==-1)
						{
							s2=path(g,h,w-1)%(7+1000000000L);
							dp[h][w-1]=s2;
						}
						else
							s2=dp[h][w-1];
			return (s1+s2)%(7+1000000000L);
		}
		
	}
}


Measured memory_bytes: 36264
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
typedef long long ll;
typedef unsigned long long ull;

struct head {
	ll GC, CG, AC, CC;
	ll xGC, GxC, xC;
	ll CGC, GGC, GCC;
	ll C, G;
};

int main()
{
	int N;
	head BeginWith;
	ll ans = 16;

	BeginWith.AC = 1;
	BeginWith.CG = 1;
	BeginWith.GC = 1;
	BeginWith.CC = 1;

	BeginWith.xGC = 0;
	BeginWith.GxC = 0;
	BeginWith.xC = 4;

	BeginWith.CGC = 0;
	BeginWith.GGC = 0;
	BeginWith.GCC = 0;

	BeginWith.C = 4;
	BeginWith.G = 4;

	cin >> N;

	repc(i, 3, N) {
		ll pre_all = ans;
		ll pre_AC = BeginWith.AC;

		ans = (ans * 4) % MOD;
		ans = (ans - BeginWith.AC + MOD) % MOD;
		ans = (ans - BeginWith.CG + MOD) % MOD;
		ans = (ans - BeginWith.GC + MOD) % MOD;
		ans = (ans - BeginWith.xGC + MOD) % MOD;
		ans = (ans - BeginWith.GxC + MOD) % MOD;
		ans = (ans + BeginWith.CGC + BeginWith.GGC + BeginWith.GCC) % MOD;

		BeginWith.GxC = (BeginWith.xC - BeginWith.AC) % MOD;
		BeginWith.xC = BeginWith.C * 4 - BeginWith.CG;
		BeginWith.xGC = (BeginWith.GC * 3) % MOD;

		BeginWith.CGC = BeginWith.GC;
		BeginWith.GGC = BeginWith.GC;
		BeginWith.GCC = BeginWith.CC;

		BeginWith.AC = (BeginWith.C - BeginWith.CG) % MOD;
		BeginWith.CG = BeginWith.G;
		BeginWith.GC = BeginWith.C;
		BeginWith.CC = BeginWith.C;

		BeginWith.C = pre_all;
		BeginWith.G = (pre_all - pre_AC) % MOD;
	}

	cout << ans << endl;

	return 0;
}


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

point = [0]*(10**5+2)

for i in a:
    if i == 1:
        point[1] += 1
        point[2] += 1
    else:
        point[i] += 1
        point[i-1] += 1
        point[i+1] += 1

print(max(point))

Measured memory_bytes: 13964
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

class Edge
{
public:
    int to, index;
    Edge(int to, int index){
        this->to = to;
        this->index = index;
    }
};

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> d(n);
    vector<pair<int, int> > v(n);
    for(int i=0; i<n; ++i){
        cin >> d[i];
        v[i] = make_pair(d[i], i);
    }
    sort(v.begin(), v.end());

    vector<vector<Edge> > edges(n);
    for(int i=0; i<m; ++i){
        int u, v;
        cin >> u >> v;
        -- u;
        -- v;
        edges[u].push_back(Edge(v, i));
        edges[v].push_back(Edge(u, i));
    }

    vector<int> ans(m, -1);
    for(int i=0; i<n; ++i){
        int a = v[i].second;
        bool ok = false;
        for(const Edge& e : edges[a]){
            if(d[e.to] <= d[a]){
                ans[e.index] = d[a];
                ok = true;
                break;
            }
        }
        if(!ok){
            cout << -1 << endl;
            return 0;
        }
    }

    string color(n, '.');
    for(int i=0; i<n; ++i){
        if(color[i] != '.')
            continue;
        color[i] = 'B';
        queue<int> q;
        q.push(i);
        while(!q.empty()){
            int a = q.front();
            q.pop();
            for(const Edge& e : edges[a]){
                if(color[e.to] == '.' && ans[e.index] != -1){
                    color[e.to] = 'B' ^ 'W' ^ color[a];
                    q.push(e.to);
                }
            }
        }
    }
    cout << color << endl;

    for(int i=0; i<m; ++i){
        if(ans[i] == -1)
            cout << 1000000000 << endl;
        else
            cout << ans[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 12416
n=int(input())
S=list(map(int,input().split()))
q=int(input())
T=list(map(int,input().split()))
c=0
for t in T:
    left=0
    mid=n//2
    right=n
    while left<right:      
        if t == S[mid]:
            c+=1
            break
        elif t > S[mid]:
            left=mid+1
            mid=(right+left)//2
        elif t < S[mid]:
            right=mid
            mid=(right+left)//2
print(c)


Measured memory_bytes: 16704
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
typedef long long ll;

using namespace std;

struct dim2 {
    int x;
    int y;
    int cnt;
};

int solve(int h, int w, int x, int y, vector<string> &map) {
    if(map[x][y] == '#') {
        return 0;
    }
    
    queue<dim2> que;
    dim2 start;
    start.x = x; start.y = y, start.cnt = -1;
    que.push(start);
    
    queue<dim2> que_next;
    
    int tmpx[4] = {0, 1, 0, -1};
    int tmpy[4] = {1, 0, -1, 0};
    vector<vector<bool>> flag = vector<vector<bool>>(h, vector<bool>(w, false));
    flag[start.x][start.y] = true;
    int ans = 0;
    int cnt = 0;
    while(!que.empty()) {
        dim2 now = que.front();
        que.pop();
        
        ans = max(ans, cnt);
        
        for(int i = 0; i < 4; i++) {
            dim2 tmp = now;
            tmp.x += tmpx[i];
            tmp.y += tmpy[i];
            
            if(tmp.x >= h || tmp.x < 0 || tmp.y >= w || tmp.y < 0) {
                continue;
            }
            
            if(map[tmp.x][tmp.y] == '#' || flag[tmp.x][tmp.y]) {
                continue;
            }
            
            que_next.push(tmp);
            flag[tmp.x][tmp.y] = true;
        }
        
        if(que.empty()) {
            que = que_next;
            
            while(!que_next.empty()) {
                que_next.pop();
            }
            
            cnt += 1;
        }
    }
    
    return ans;
}

int main() {
    int h, w;
    cin >> h >> w;
    
    vector<string> map(h);
    for(int i = 0; i < h; i++) {
        cin >> map[i];
    }
    
    int ans = 0;
    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            // cout << "i = " << i << ", j = " << j << endl;
            // cout << solve(h, w, i, j, map)<< endl;
            ans = max(ans, solve(h, w, i, j, map));
        }
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
N = int(input())
As = [int(n) for n in input().split()]

ans = 0

for i in range(N - 1):
    if As[i] >As[i+1]:
        diff = As[i] - As[i+1]
        As[i +1] = As[i]
        ans += diff
    else:
        pass
    
print(ans)

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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) (v.begin(),v.end())
#define COUT(x) cout<<(x)<<endl

int main(){
    int n,c1=0,c2=0;
    cin >> n;
    bool flag = false;
    REP(i,n){
        int a;
        cin >> a;
        if(a%4==0)c1++;
        else if(a%2==0)flag = true;
        else c2++;
    }
    if(flag){
        if(c1>=c2)cout<<"Yes"<<endl;
        else cout << "No" << endl;
    }
    else {
        if(c1>=c2-1)cout<<"Yes"<<endl;
        else cout << "No" << endl;
    }
    return 0;
}    


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	char s[5];
	scanf("%s",s);
	
	if(s[0]==s[1])
	puts("Bad");
	
	else if(s[1]==s[2])
	puts("Bad");
	
	else if(s[2]==s[3])
	puts("Bad");
	
	else
	puts("Good");
	
	return 0;
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/04/04  Problem: ABC 043 D / Link: http://abc043.contest.atcoder.jp/tasks/abc043_d  ----- */


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

	string s; cin >> s;
	PLL ans(-1, -1);
	FOR(i, 0, SZ(s) - 1) {
		if (s[i] == s[i + 1]) {
			ans = PLL(i + 1, i + 1 + 1);
		}
	}
	FOR(i, 0, SZ(s) - 2) {
		if (s[i] == s[i + 2]) {
			ans = PLL(i + 1, i + 2 + 1);
		}
	}
	cout << ans.first << " " << ans.second << "\n";

	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <sstream>
#include <string>
#include <map>
#include <set>
#include <stdlib.h>
#include <cmath>
#include <math.h>
#include <fstream>
#include <bitset>
#include <time.h>
#include <queue>
#define int long long
using namespace std;
int32_t main(){
    string s;
    cin >> s;
    int ans = s.size();
    for (int i=0; i < s.size() - 1; i++){
        if (s[i] == s[i+1]) continue;
        int D = i+1;
        int Q = s.size() - i - 1;
        ans = min(ans, max(D, Q));
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define PI 3.1415926535897932384626433832795
int MOD=1e9+7;
int powmod(int a,int l, int md){int res=1;while(l){if(l&1)res=res*a%md;l/=2;a=a*a%md;}return res;}
typedef long long ll; typedef vector<ll> vi; typedef pair<ll, ll> ii; typedef vector<ii> vii;
#define pb push_back
int __set(int b, int i) {return b|(1<<i);} //set ith bit
int __unset(int b, int i) {return b&!(1<<i);}
int __check(int b, int i) {return b&(1<<i);} //returns 0 if ith bit is 0
int mul(int a, int b) {return ((a%MOD)*(b%MOD))%MOD;}
int add(int a, int b) {return (a+b)%MOD;}
int sub(int a, int b) {return (((a-b)%MOD)+MOD)%MOD;}
int __div(int a, int b) {return mul(a, powmod(b, MOD-2, MOD));} //if MOD is prime;
const int inf = 0xFFFFFFFFFFFFFFFL; //very large number
priority_queue<int, vector<int>, greater<int> > pq; //for min priority_queue
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
clock_t time_p=clock();
void time()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}

int32_t main(void)
{
	IOS;
	int n; cin>>n;
	double p[n];
	for(int i=0; i < n; i++)
		cin>>p[i];
	double one = (double)1;
	double dp[n+1][n+1];
	for(int i = 0; i <= n; i++) {
		for(int j = 0; j <= n; j++)
			dp[i][j]=(double)0;
	}
	dp[0][0]=one;
	for(int i = 1; i <= n; i++)
		dp[i][0]=dp[i-1][0]*(one-p[i-1]);
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= n; j++) {
			dp[i][j]=dp[i-1][j]*(one-p[i-1])+dp[i-1][j-1]*p[i-1];
		}
	}
	double ans=(double)0;
	for(int i = n/2+1; i <= n; i++)
		ans += dp[n][i];
	cout<<setprecision(12)<<ans<<endl;
	time();	
	return 0;
}

Measured memory_bytes: 70656
#include <bits/stdc++.h>
using namespace std;
 
//#define READ_NUMBER(i) scanf("%d",i)
 
int main(){
	int N, M;
	cin >> N >> M;
	int array[M];
	int array_d[M - 1];
	int Ans = 0;
	if(N >= M){
		cout << "0" << endl;
	}else{
		for(int i = 0;i < M;i++){
			cin >> array[i];
		}
		std::sort(array, array + M);
		for(int i = 0;i < M - 1;i++){
			array_d[i] = array[i + 1] - array[i];
		}
		std::sort(array_d, array_d + M - 1);
		for(int i = 0; i < M - N; i++){
			Ans += array_d[i];
		}
		cout << Ans << endl;
	}
}

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

int main() {
  int N;
  cin>>N;
  int Z=0,A=1;
  for(int i=0;i<N;i++){
    int a;
    cin>>a;
    if(a==A){
      A++;
    }
    else{
      Z++;
    }
  }
  if(Z==N){
    Z=-1;
  }
  cout<<Z<<endl;
}

Measured memory_bytes: 3612
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXW=200000;
const int MAXH=200000;
const int MAXN=200000;

int h,w,n;
int px[MAXN],py[MAXN];

vector<int> ylst[MAXW];

int getfirst(int x,int y) {
	int idx=lower_bound(ylst[y].begin(),ylst[y].end(),x)-ylst[y].begin();
	return idx<SZ(ylst[y])?ylst[y][idx]:h;
}

int solve() {
	int ret=h;
	REP(i,n) ylst[py[i]].PB(px[i]);
	REP(y,w) sort(ylst[y].begin(),ylst[y].end());
	int cx=0,cy=0;
	while(true) {
		int right=getfirst(cx,cy);
		ret=min(ret,right);
		if(right==cx+1) break;
		++cx;
		if(cy==w-1) break;
		int up=getfirst(cx,cy+1);
		if(up!=cx) ++cy;
	}
	return ret;
}

void run() {
	scanf("%d%d%d",&h,&w,&n);
	REP(i,n) scanf("%d%d",&px[i],&py[i]),--px[i],--py[i];
	printf("%d\n",solve());
}

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


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

int main ()
{
    int N, v, j;
    cin >> N;
    int A[N];
    
    for(int i = 0; i < N; i++)
    {
      cin >> A[i];
    }
    
   for (int i = 1; i < N; i++)
   {
     for(int k = 0; k < N-1; k++)
     {
       cout << A[k] << " ";
     }
     cout << A[N-1] << endl;
       
     v = A[i];
     j = i - 1;
     while (j >= 0 && A[j] > v)
     {
       A[j+1] = A[j];
       j--;
     }
     A[j+1] = v;
   }
    
     for(int k = 0; k < N-1; k++)
     {
       cout << A[k] << " ";
     }
     cout << A[N-1] << endl;
         
  return 0;
}


Measured memory_bytes: 3092
#include <iostream>
#include <string>
using namespace std;
typedef long long ll;

int main() {
	int N, K, P[5010];
    ll C[5010]; 
	cin >> N >> K;
    for (int i = 0; i < N; ++i){
        cin >> P[i];
    }
    for (int i = 0; i < N; ++i){
        cin >> C[i];
    }

    ll ans = -1e18;
    for (int i = 0; i < N; ++i){
        int address = i, roop_size = -1;
        ll score[5010];
        score[0] = 0;
        for (int j = 1; j <= N; ++j){
            address = P[address]-1;
            score[j] = score[j-1] + C[address];
            if (address == i && roop_size == -1){
                roop_size = j;
            }
        }

        if (K < roop_size){
            for (int i = 1; i <= K; ++i) {
                ans = max(ans, score[i]);
            }
        } else {
            if (score[roop_size] >= 0){
                for (int i = 0; i < roop_size; ++i) {
                    ans = max(ans, score[roop_size] * ((K-i)/roop_size) + score[(K-i)%roop_size]);
                }
            }else{
                for (int i = 1; i <= roop_size; ++i) {
                    ans = max(ans, score[i]);
                }
            }
        }
    }

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

Measured memory_bytes: 3720
fn main() {
    let (n, m) = read_tuple();
    let mut gates: Vec<(_, _)> = (0..m).map(|_| read_tuple::<i64>()).collect();
    gates.sort_by_key(|x| x.0);

    let mut ans = 0;
    let mut gates_index: usize = 0;
    let mut current_gate_count: i64 = 0;
    let mut gate_end: Vec<i64> = vec![0; n + 2];
    for id in 0..(n + 1) {
        current_gate_count += gate_end[id];

        while gates_index < m {
            let (l, r) = gates[gates_index];

            if id as i64 == l {
                current_gate_count += 1;
                gate_end[r as usize + 1] -= 1;
                gates_index += 1;
            } else {
                break;
            }
        }

        if current_gate_count == m as i64 {
            ans += 1;
        }
    }

    println!("{:?}", ans);
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn read_tuple<T: std::str::FromStr + Copy>() -> (T, T) {
    let tmp = read_vec();
    (tmp[0], tmp[1])
}

Measured memory_bytes: 8444
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)
#define REV(X, Y, Z) for (ll(X) = (Y); (X) > (Z); (X)--)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMod = 1e9 + 7;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  vector<vll> C(3);
  REP(i, 0, 3) {
    vll c(3);
    REP(j, 0, 3) {
      cin >> c[j];
    }
    C[i] = c;
  }

  vll B = {C[0][0], C[0][1], C[0][2]};
  vll A = {0, C[1][0] - B[0], C[2][0] - B[0]};

  REP(i, 0, 3) {
    REP(j, 0, 3) {
      if (C[i][j] != A[i] + B[j]) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main()
{
    int K;
    cin >> K;
    cout << K/2*((K+1)/2) << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner scanner=new Scanner(System.in);
		int n=scanner.nextInt();
		for(int i=0;i<n;i++){
			String s1=scanner.next();
			String s2=scanner.next();
			System.out.println(lcs(s1,s2));
		}
	}

	private static int  lcs(String s1, String s2) {
		// TODO Auto-generated method stub
		int[][] c=new int[1001][1001];
		int m=s1.length();
		int n=s2.length();
		for(int i=1;i<=m;i++)
			c[i][0]=0;
		for(int i=1;i<=n;i++)
			c[0][i]=0;
		s1=" "+s1;
		s2=" "+s2;
		int max=0;
		for(int i=1;i<=m;i++){
			for(int j=1;j<=n;j++){
				if(s1.charAt(i)==s2.charAt(j))
					c[i][j]=c[i-1][j-1]+1;
				else c[i][j]=Math.max(c[i-1][j], c[i][j-1]);
				max=Math.max(max, c[i][j]);
			}
		}
		
		return max;
	}
}


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

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF (1LL<<57)
#define MV 200001
#define LMV 21
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define emp emplace
#define whoami(x) cerr<<#x<<" "<<x<<"\n";
#define mp make_pair
#define ins insert
#define sz size

void FLASH() {ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);}
void SETF() {cout.ios_base::setf(ios_base::fixed);}
void UNSETF() {cout.ios_base::unsetf(ios_base::fixed);}

typedef long long ll;
typedef long double ld;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef pair<PII, int> PPII;
typedef pair<PLL, ll> PPLL;
typedef map<int, int> MII;

struct h_llint {
  static uint64_t splitmix64(uint64_t x) {    // http://xorshift.di.unimi.it/splitmix64.c
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};

struct h_pair{
  size_t operator()(const PLL&x)const{
    return hash<ll>()(((ll)x.ff)^(((ll)x.ss)<<32));
  }
};

typedef map<ll, ll> MLL;
typedef map<PII, int> MPII;
typedef map<PLL, ll> MPLL;
typedef set<int> SI;
typedef set<ll> SL;
typedef unordered_map<ll, int, h_llint> UMLI;
typedef unordered_map<ll, ll, h_llint> UMLL;
typedef unordered_map<PLL, int, h_pair> UMPI;
typedef unordered_map<PLL, ll, h_pair> UMPL;

int ar[MV];
ll arr[MV];

void solve(int T)
{
	int a,b;
	cin>>a>>b;
	if(((a == 1) && (b == 2)) || ((a == 2) && (b == 1)))
	cout<<"3\n";
	else if(((a == 1) && (b == 3)) || ((a == 3) && (b == 1)))
	cout<<"2\n";
	else cout<<"1\n";	
}

int main(void)
{
	FLASH();
	int T;
	T = 1;

#ifdef ONLINE_JUDGE
	time_t time_t1, time_t2;
	time_t1 = clock();
#endif

	while(T--)
	solve(T);

#ifdef ONLINE_JUDGE
	time_t2 = clock();
	SETF();
	cout<<"Time taken: "<<setprecision(7)<<(time_t2 - time_t1)/(double)CLOCKS_PER_SEC<<"\n";
	UNSETF();
#endif

	return 0;
}

Measured memory_bytes: 256
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim();}
function myout(t){console.log(t);}//standard output
function myerr(t){console.error(t);}//standard error
//[no]param
//0:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
function myconv(i,no){switch(no){case 0:return i;case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));}}
function Main(input) {
  input = myconv(input,3);
  var N = myconv(input[0],1);
  var list = myconv(input[1],4);
  var ave = getAverage(list);
  var output = 0;
  var lastThumb = 101;
  for(var i = 0; i < N; i++){
    if(lastThumb > Math.abs(list[i] - ave)){
       lastThumb = Math.abs(list[i] - ave);
      output = i;
    }
  }
  myout(output);
}
function getAverage(list){
	var sum = 0;
    for(var i = 0; i < list.length; i++){
      sum += list[i];
    }
    return sum / list.length;
}
Main(myin());

Measured memory_bytes: 7372
n, *A = map(int, open(0).read().split())
B = [0] * max(3, (max(A) + 1))
for a in A:
  B[a] += 1
ans = 0
for b0, b1, b2 in zip(B, B[1:], B[2:]):
  ans = max(ans, b0 + b1 + b2)
print(ans)

Measured memory_bytes: 14044
#include <stdio.h>

int calc(int a) {
    return a + a*a + a*a*a;
}

int main() {
    int x;
    scanf("%d", &x);
    if (0<=x & x<=10) {
        printf("%d\n", calc(x));
    }
    else {
        printf("One more please\n");
    }

    return 0;
}

Measured memory_bytes: 1644
#include<stdio.h>
int main(void)
{
  int a, b, c, i, j;

  scanf("%d %d %d", &a, &b, &c);

  j = 0;
  
  for(i = a ; i <= b ; i++)
    {      
      if(c % i == 0)
	{
	  j++;
	}
    }
  printf("%d\n", j);

  return 0;
}


Measured memory_bytes: 2120
#include <iostream>

int dp[31];
int count(int n){
	if(dp[n] < 0){
		dp[n] = count(n-3)+count(n-2)+count(n-1);
	}
	return dp[n];
}
using namespace std;
int main(){
	for(int i = 0; i < 31; ++i){
		dp[i] = -1;
	}
	dp[1] = 1;
	dp[2] = 2;
	dp[3] = 4;
	int n;
	cin >> n;
	while(n){
		cout << ((count(n)+9)/10+364)/365 << endl;
		cin >> n;
	}
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define fi first
#define se second
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef vector<int> vi;
const int inf = 1e9+7;
const int INF = 1e18+7;

class SegmentTree{
public:
	int n = 1;
	vector<P> seg[2];
	//m要素のセグメントツリー作成
	void init(int m){
		while(n < m)n *= 2;
		rep(i,2)seg[i].resize(2*n);
		fill(all(seg[0]), P(-INF, -1));
		fill(all(seg[1]), P(INF, -1));
	}
	P cmp_min(P x, P y){
		if(x.fi == y.fi)return x.se < y.se ? x : y;
		return min(x, y);
	}
	P cmp_max(P x, P y){
		if(x.fi == y.fi)return x.se < y.se ? x : y;
		return max(x, y);
	}
	//kの値をxに変更
	void update(int k, int x, bool flag=false){
		k += n-1;
		seg[0][k] = seg[1][k] = P(x, k-(n-1));
		if(flag){seg[0][k] = P(-INF, -1);seg[1][k] = P(INF, -1);}
		while(k > 0){
			k = (k-1)/2;
			seg[0][k] = cmp_max(seg[0][k*2+1], seg[0][k*2+2]);
			seg[1][k] = cmp_min(seg[1][k*2+1], seg[1][k*2+2]);
		}
	}
	void erase(int k){
		update(k, -1, true);
	}
	P calc_max(int a, int b, int k, int l, int r){
		if(b <= l || r <= a)return P(-INF, -1);
		if(a <= l && r <= b)return seg[0][k];
		P vl = calc_max(a, b, k*2+1, l, (l+r)/2);
		P vr = calc_max(a, b, k*2+2, (l+r)/2, r);
		return cmp_max(vl, vr);
	}
	P calc_min(int a, int b, int k, int l, int r){
		if(b <= l || r <= a)return P(INF, -1);
		if(a <= l && r <= b)return seg[1][k];
		P vl = calc_min(a, b, k*2+1, l, (l+r)/2);
		P vr = calc_min(a, b, k*2+2, (l+r)/2, r);
		return cmp_min(vl, vr);
	}
	//[a,b)の最大値を求める
	P get_max(int a, int b){return calc_max(a, b, 0, 0, n);}
	//[a,b)の最小値を求める
	P get_min(int a, int b){return calc_min(a, b, 0, 0, n);}
};

class BIT{
public:
	int n = 1;
	vector<int> bit;
	void init(int m){	//[1, m]のBIT作成
		while(n < m+1)n *= 2;
		bit.resize(n+1);
		fill(all(bit), 0);
	}
	void add(int i, int x){
		while(i <= n){bit[i] += x;i += i&-i;}
	}
	int get(int i){
		int s = 0;
		while(i > 0){s += bit[i];i -= i&-i;}
		return s;
	}
	int lower_bound(int k, int ret = -1){	//ret=見つからなかったときに返すidx
		int lb = 0, ub = n+1;
		while(ub-lb > 1){
			if(get((lb+ub)/2) >= k)ub = (lb+ub)/2;
			else lb = (lb+ub)/2;
		}
		return ub == n+1 ? ret : ub;
	}
};

SegmentTree seg;
BIT bit;
signed main(){
	string str;
	int k;
	cin >> str >> k;
	int n = str.size();
	seg.init(n+1);
	bit.init(n);
	str = " "+str;k++;
	rrep(i,n){seg.update(i, str[i]-'a');bit.add(i, 1);}
	
	string ans;
	rrep(i,n){
		int idx = bit.lower_bound(k, n);
		P p = seg.get_min(0, idx+1);
		//printf("%lld %lld %lld\n", k, idx, p.se);
		k -= bit.get(p.se)-1;
		bit.add(p.se, -1);
		seg.erase(p.se);
		ans.pb('a'+p.fi);
	}
	cout << ans << endl;
	return 0;
}





Measured memory_bytes: 22056
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using vec=vector<ll>;
using mat=vector<vec>;
#define For(i,a,b) for(i=a;i<b;i++)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define mod 1000000007
using datas=pair<ll,ll>;

long mmid(long a,long b,long c){return a<b?(b<c?b:max(a,c)):(b>c?b:min(a,c));}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

ll modncr(ll n,ll r){
  ll i,plus=1;
  rep(i,r){
    plus=(plus*(n-i))%mod;
    plus=moddevide(plus,i+1);
  }
  return plus;
}

ll euclidean_gcd(ll a, ll b) {
  if(a<b) return euclidean_gcd(b, a);
  ll r;
  while ((r=a%b)){a=b;b=r;}
  return b;
}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

void printmap(vector<ll>& a,ll H,ll W){
  ll i,j;
  For(i,0,H+2){
    For(j,0,W+2){cout<<a[i*(W+2)+j];}
    cout<<endl;
  }
}
void inputmap(vector<ll>& a,ll H,ll W){
  ll i,j;
  string ss;
  For(i,1,H+1){
    cin>>ss;
    For(j,1,W+1){
      if(ss[j-1]=='#'){
        a[i*(W+2)+j]=1;
      }else{
        a[i*(W+2)+j]=0;
      }
    }
  }
}

int main(){
  ll i,j,k=1,N,H,W;
  cin>>H>>W>>N;
  vec a(N+1,0);
  mat m(H,vec(W,0));
  rep1(i,N+1){
    cin>>a[i];
  }
  rep(i,H){
    if(i%2){
      for(j=W-1;j>=0;j--){
        if(a[k]==0)k++;
        m[i][j]=k;
        a[k]--;
      }
    }else{
      rep(j,W){
        if(a[k]==0)k++;
        m[i][j]=k;
        a[k]--;
      }
    }
  }
  rep(i,H){
    rep(j,W){
      cout<<m[i][j]<<" ";
    }
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner scan=new Scanner(System.in);
		int H,W;
		while(true){
			H=scan.nextInt();
			W=scan.nextInt();
			if(H==0&&W==0) break;
			
			for(int i=0;i<H;i++){
				for(int j=0;j<W;j++){
					System.out.print("#");
				}
				System.out.println();
			}
			System.out.println();
		}
		scan.close();
	}
}

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

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define INF 2000000000000000000LL
#define EPS 1e-9
#define debug(a) cerr<<#a<<"="<<(a)<<"\n"
#define FastSlowInput ios_base::sync_with_stdio(false); cin.tie(NULL);

typedef long long ll;
typedef unsigned long long ull;
typedef complex<double> cd;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll mod = 1e9+7;
const double PI = acos(-1);

int n,i,j,k,t;
int a[102];
int dp[101][100002];
int psum[101][100002];


int main(){
    memset(dp, 0, sizeof dp);
    scanf("%d %d", &n, &k);
    dp[0][0] = 1;
    for(i=1;i<=n;++i)
        scanf("%d", a+i);
    for(i=1;i<=n;++i){
        psum[i-1][0] = 1;
        for(j=1;j<=k;++j){
            psum[i-1][j] = (dp[i-1][j] + psum[i-1][j-1])%mod;
        }
        for(j=0;j<=k;++j){
            if(a[i] >= j){
                dp[i][j] = (dp[i][j] + psum[i-1][j])%mod;
            }
            else{
                dp[i][j] += (mod + psum[i-1][j] - psum[i-1][j-a[i]-1] )%mod;
                dp[i][j] %= mod;
            }
        }
    }
    int ans = dp[n][k];
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 79104
#include <stdio.h>

#define abs(a) ((a)<0 ? -(a) : (a))
#define chmin(a,b) ((a)<(b) ? (a) : (b))

int main()
{
  int a[200000];
  int N;
  
  scanf("%d",&N);
  
  for(int i=0;i<N;i++)
    scanf("%d",&a[i]);
  
  int dp[N];
  
  dp[0]=0;
  dp[1]=abs(a[1]-a[0]);
  
  for(int i=2;i<N;i++)
   dp[i]=chmin(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
   
  printf("%d",dp[N-1]);
}

Measured memory_bytes: 896
#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 cnt=0,cnt1=0;
  for(int i=0;i<n-1;i++){
    if(a[i+1]<=a[i])
      cnt++;
    else
      cnt = 0;
    cnt1 = max(cnt,cnt1);
  }   
  cout << cnt1 << endl;
}

Measured memory_bytes: 640
def main():
    n = int(input())
    p = list(map(int,input().split()))


    ans =0
    Flag = False

    for i in range(n-1):
        if Flag== True:
            Flag = False
            continue

        if p[i] == i+1:
            ans+=1
            if p[i+1] == i+2:
                Flag = True

    if Flag == False:
        if p[-1] == n:
            ans+=1

    print(ans)

if __name__ == "__main__":
        main()


Measured memory_bytes: 14004
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;

//vector string deque break continue
#define forn(i, s, f) for (int i = (int)s; i < (int)f; i++)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define fs first
#define sc second
#define pf push_front
#define pb push_back
#define pop_f pop_front
#define pop_b pop_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()

template <typename T> istream& operator>>(istream& in, vector <T>& a) {for (auto& i : a) in >> i; return in;}
template <typename T> ostream& operator<<(ostream& out, vector <T>& a)  {for (auto& i : a) out << i << " "; return out;}
template <typename T, typename U> void chkmin(T& a, U b) {if (a > b) a = b;}
template <typename T, typename U> void chkmax(T& a, U b) {if (a < b) a = b;}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    string s;
    cin >> s;
    forn (i, 0, sz(s))
        if (s[i] == '7')
            return cout << "Yes", 0;
    cout << "No";
    return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pi 3.14159
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 1000000007
#define f first
#define s second
#define pii pair< int, int >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

using namespace std;
string repeat(string s, int n) {
    string s1 = "";
    for (int i=0; i<n;i++)
        s1+=s;
    return s1;
}
string getString(char x) {
    string s(1, x);
    return s;
}

void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int gcd(int a, int b){
    if (a == 0)  return b;
    return gcd(b % a, a);
}
void  solve(){
  ll n,k;
  cin>>n>>k;
  ll ans=0;
  if(k%2LL==0LL){
    k=k/2LL;
    ll num= n/k;
    ll ev= num/2,od=num-num/2;
    // cout<<ev<<' '<<od<<endl;
    ans+= ev*ev*ev+od*od*od;
    k=2LL*k;
    cout<<ans<<endl;
    return;
  }
  ans+= (n/k)*(n/k)*(n/k);
  cout<<ans<<endl;
}
int main(){
    optimizeIO();
    // tc
    { solve();
    }
}


Measured memory_bytes: 3640
n,a,b=map(int,input().split())
if a<b:
    if n>3:
    	print((b-a)*(n-2)+1)
    if n==2:
    	print(1)
    if n==1:
      	print(0)
    
elif a==b:
    print(1)
elif a>b:
    print(0)


Measured memory_bytes: 3060
#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
#define MOD 1000000007
#define MOD2 998244353
#define MOD3 1000000009
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18)
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
//ifstream cinn("in.in");ofstream coutt("out.out");
int poww(const int &a,int b,const int &m=MOD){if(b==0)return 1;int x=poww(a,b/2,m);x=x*x%m;if(b&1)x=x*a%m;return x;}
int ceil(const int &a,const int &b){return (a+b-1)/b;}
////Read:
//Check corner cases, n==1;
//
////Some function:
//__builtin_popcountll(), 

int mp[400005];

signed main(){
    FASTER;
    int n;cin>>n;
    string s;cin>>s;
    
    for(int i=0;i<400005;i++){
        int tmp=i;
        int ans=0;
        while(tmp){
            tmp=tmp%__builtin_popcountll(tmp);
            ans++;
        }
        mp[i]=ans;
    }
    
    int cnt=0;
    for(char c:s)cnt+=(c=='1');
    
    int Pp1=0,Pm1=0,cur1 = 1,cur2 = 1;
    for(int i=n-1,id=0;i>=0;i--,id++){
        if(s[i]=='1'){
            Pp1=(Pp1+cur2 % (cnt + 1))%(cnt+1);
            if(cnt>=2)Pm1=(Pm1+cur1 % (cnt - 1))%(cnt-1);
        }
        if(cnt > 1){
            cur1 *= 2;
            cur1 %= (cnt - 1); 
        } 
        cur2 *= 2;
        cur2 %= (cnt + 1);
    }
    
    vi cp1mod(n+n,1);
    for(int i=1;i<2*n;i++){
        cp1mod[i]=cp1mod[i-1]*2%(cnt+1);
    }
    vi cm1mod(n+n,1);
    for(int i=1;i<2*n && cnt>1;i++){
        cm1mod[i]=cm1mod[i-1]*2%(cnt-1);
    }
    
    for(int i=0;i<n;i++){
        if(s[i]=='0'){
            int rem=(Pp1+cp1mod[n-i-1])%(cnt+1);
            int cntt=1+mp[rem];
            cout<<cntt<<"\n";
        }else{
            if(cnt==1){
                cout<<0<<"\n";
            }else{
                int rem=(Pm1-cm1mod[n-i-1]+cnt-1)%(cnt-1);
                int cntt=1+mp[rem];
                cout<<cntt<<"\n";
            }
        }
    }
    
}


Measured memory_bytes: 12812
#include<iostream>
#include<algorithm>
using namespace std;
main() {
	int x, y;
	while ( cin >> x >> y && !(x == 0 && y == 0) ) {
		if ( y > x ) swap(x, y);
		int step = 0;
		while(y) {
			int t = x % y;
			x = y;
			y = t;
			step++;
		}
		cout << x << " " << step << endl;
	}
}

Measured memory_bytes: 3036
class Node
  attr_accessor :key, :left, :right

  def initialize(key)
    @key = key
  end

  def inorder
    left.inorder unless left.nil?
    print " ", key
    right.inorder unless right.nil?
  end

  def preorder
    print " ", key
    left.preorder unless left.nil?
    right.preorder unless right.nil?
  end
end

def insert
  z = Node.new $key.to_i
  x = $root
  while x do
    y = x
    if z.key < x.key
      x = x.left
    else 
      x = x.right
    end
  end
  
  if y.nil?
    $root = z
  elsif z.key < y.key
    y.left = z
  else
    y.right = z
  end
end

n = gets.to_i
n.times do
  command, $key = gets.split
  if command == "insert"
    insert
  else 
    $root.inorder
    puts
    $root.preorder
    puts
  end
end

Measured memory_bytes: 47968
import numpy as np

if __name__=="__main__":
    N = int(input())
    a = input().split()
    a = list(map(int, a))
    a = np.sort(a)
    s = 0
    for i in range(len(a) - 1):
        s += (a[i+1] - a[i])

    print(s)


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

using i64=int64_t;

#define rep(i,x,y) for(i64 i=i64(x),i##_max_for_repmacro=i64(y); i<i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif
 
const int inf=1.01e9;
const i64 inf64=4.01e18;
const double eps=1e-9;
 
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    i64 N,H;
    cin >> N >> H;

    vector<pair<i64,i64>> ab(N);
    rep(i,0,N) cin >> ab[i].first >> ab[i].second;

    sort(begin(ab),end(ab),[](pair<i64,i64> &p,pair<i64,i64> &q){ return p.second > q.second; });

    i64 a_max=0;
    rep(i,0,N) a_max=max(a_max,ab[i].first);
    
    i64 s=0,c=0;
    rep(i,0,N){
        if(ab[i].second<=a_max) continue;
        s+=ab[i].second;
        ++c;
        if(s>=H){
            cout << c << endl;
            return;
        }
    }

    cout << c+(H-s+a_max-1)/a_max << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


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

int main() {
  int A,B;
  cin >> A >> B;
  int x;
  int sum = 0;
  int count = 1;
  rep(i,A){
    cin >> x;
    sum += x;
    if(sum > B){
     break; 
    }
   count++; 
  }
  cout << count << endl;
}


Measured memory_bytes: 3616
#include<cstdio>
#include<numeric>
using i64=long long;
const int N=300007;
int a[N],b[N],f[N],g[N],fa[N],s[N],t[N],vis[N];
int read(){int x;scanf("%d",&x);return x;}
int find(int x){return x==fa[x]? x:fa[x]=find(fa[x]);}
void merge(int x,int y){fa[find(x)]=find(y);}
int main()
{
    int n=read(),m=read();i64 ans=0;std::iota(fa+1,fa+n*3+1,1);
    for(int i=1;i<=m;++i) ++f[a[i]=read()],++g[b[i]=read()],merge(a[i],b[i]+n),merge(a[i]+n,b[i]+n+n),merge(a[i]+n+n,b[i]);
    for(int i=1;i<=n;++i) if(++s[find(i)],++t[find(i+n)],f[i]&&g[i]) vis[find(i)]=vis[find(i+n)]=vis[find(i+n+n)]=1;
    for(int i=1;i<=n*3;++i) if(find(i)==i&&vis[i]) ans+=1ll*s[i]*t[i];
    for(int i=1;i<=m;++i) ans+=!vis[find(a[i])];
    printf("%lld\n",ans);
}


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

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> jobs(m);
    rep(i,n){
        int a,b;
        cin >> a >> b;
        if (a > m) continue;
        jobs[m-a].push_back(b);
    }
    priority_queue<int> q;
    ll ans = 0;
    for (int i = m-1; i >= 0; --i){
        for (int b : jobs[i]){
            q.push(b);
        }
        if (!q.empty()){
            ans += q.top();
            q.pop();
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 5632
#include <stdio.h>


int main()
{		
	long long a, b, n;
		
	scanf("%lld%lld%lld", &n, &a, &b);
	if(a == b) puts("1");
	else if(a < b){
		if(n > 1) printf("%lld\n", (b - a) * (n - 2) + 1);
		else puts("0");
	} 
	else puts("0");
				
	return 0;
}

Measured memory_bytes: 128
n = gets.chomp.to_i
arr = []
n.times do 
    x = gets.chomp.split(" ").map(&:to_i)
    arr << x.reverse
end
arr = arr.sort
ans = 0
until arr == []
    x,y = arr.shift
    ans += y
    if x < ans
        puts "No"
        exit
    end
end
puts "Yes"

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

int main (void){
    int A,B,C,K;
    cin >> A >> B >> C >> K;
    int sum = 0;
    if(A < K){
        sum += A;
        K -= A;
        if(B < K){
            K -= B;
            sum -= K;
        }
    }else{
        sum += K;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h> 
#include <vector>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array)/sizeof(array[0]))
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;
using Field=vector<vector<int>>;

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

int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    rep(i,n)cin>>a[i];
    int ans=0;
    rep(i,n){
        if((i+1)%2==1&&a[i]%2==1)ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3592
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
#include<set>
#include<cctype>
#define ld long double
#define ll long long int
#define ull unsigned long long int
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 long long INF=1LL<<60;


int main(void){
	ios::sync_with_stdio(false); cin.tie(0);
	
	ll i,ans=1;
	int n;
	cin>>n;
	for(i=2;i<=n;i++){
		ans*=i;
		ans%=1000000007;
//		cout<<ans<<endl;
	}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 256