akhauriyash/Code-Regression huggingface dataset:
import java.io.File;
import java.io.FileInputStream;
import java.util.Scanner;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.NoSuchElementException;

public class Main {
	
	public static void main(String[] args) throws IOException {
		FastScanner sc = new FastScanner(System.in);
		
		long N = sc.nextLong();
		long base = 1;
		StringBuilder ans = new StringBuilder();
		if(N == 0) System.out.println(0);
		else{
			while(N != 0){
				if(N % (base * -2) != 0){
					ans.append("1");
					N -= base;
				}else ans.append("0");
				base *= -2;
			}
			System.out.println(ans.reverse());
		}
	}
}

class FastScanner {
    private InputStream in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    public FastScanner(InputStream in) {
		this.in = in;
	}
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() {
    	if (hasNextByte()) return buffer[ptr++];
    	else return -1;
    }
    private static boolean isPrintableChar(int c){
    	return 33 <= c && c <= 126;
    }
    public boolean hasNext() {
    	while(hasNextByte() && !isPrintableChar(buffer[ptr]))
    		ptr++; return hasNextByte();
    }
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() {
    	return Double.parseDouble(next());
    }
}

Measured memory_bytes: 22612
#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 1000007
#define INF63 1061109567
#define INF127 9187201950435737471
#define UINF 18446744073709551615
#define F first
#define S second
#define ll long long
#define N 200010
using namespace std;
vector<ll> cyc;
ll n,a[N],k,pos[N];
int main(){
	ll i;
	cin>>n>>k;
	for(i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	memset(pos,-1,sizeof(pos));
	for(i=1;pos[i]==-1;i=a[i])
	{
		pos[i]=cyc.size();
		if(pos[i]==k)
		{
			cout<<i<<endl;
			return 0;
		}
		cyc.push_back(i);
	}
	k-=pos[i];
	cout<<cyc[pos[i]+k%(cyc.size()-pos[i])]<<endl;
	return 0;
}

Measured memory_bytes: 8396
#include <iostream>
#include <string>
using namespace std;
int main()
{
	int H, W;
	cin >> H >> W;
	string a[110];
	for (int i = 0; i < H; i++)
	{
		cin >> a[i];
	}

	bool line[110] = { false }, row[110] = { false };
	
	for (int i = 0; i < H; i++)
	{
		for (int j = 0; j < W; j++)
		{
			if (a[i][j] == '#')
			{
				line[i] = true;
				break;
			}
		}
	}
	for (int i = 0; i < W; i++)
	{
		for (int j = 0; j < H; j++)
		{
			if (a[j][i] == '#')
			{
				row[i] = true;
				break;
			}
		}
	}
	for (int i = 0; i < H; i++)
	{
		if (line[i])
		{
			for (int j = 0; j < W; j++)
			{
				if(row[j])
				cout << a[i][j];
			}
			cout << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main()
{
    int n;
    cin >> n;
    vector<int> ans(n, 0);
    for(int x = 1; x < 100; x++) {
        for(int y = x; y < 100; y++) {
            for(int z = y; z < 100; z++) {
                int a = 0;
                a = x*x + y*y + z*z + x * y + y * z + z * x;
                if(a > n) continue;
                if(x == y && y == z) {
                    ans[a - 1] += 1;
                }
                else if(x == y || y == z) {
                    ans[a - 1] += 3;
                }
                else ans[a - 1] += 6;
            }
        }
    }
    rep(i, n) {
        cout << ans[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 3632
#include<iostream>

using namespace std;
int main() {
	char* S = new char[3];
	bool flag = true;

	cin >> S;

	for (int i = 0; i < 2; i++) {
		if (S[i] != S[i + 1]) {
			flag = false;
			cout << "Yes" << endl;
			break;
		}
	}

	if(flag)
		cout << "No" << endl;

	return 0;
}

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

int main()
{
  int n,q;
  for(;cin>>n>>q;)
    {
      int y;
      string name="kogakubu10gokan";
      string tmp;
      for(int i=0;i<n;i++)
	{
	  cin>>y>>tmp;	  
	  if(y<=q)
	    name=tmp;
	}
      cout<<name<<endl;
    }
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,c[1000],a[1000]={0},t,x,d,q,flag=0;
  cin>>n;
  for(int i=0;i<n;++i) cin>>c[i];
  cin>>q;
  for(int i=0;i<q;++i){
    cin>>t>>x>>d;
    switch(t){
    case 1:
      a[x-1]+=d;
      break;
    case 2:
      a[x-1]-=d;
    }
    if((a[x-1]<0||a[x-1]>c[x-1])&&flag==0) flag=x;
  }
  cout<<flag<<endl;
  return 0;
}



Measured memory_bytes: 3120
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni = lambda: int(ns())
nin = lambda x: [ni() for _ in range(x)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda x: [na() for _ in range(x)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda x: [ns() for _ in range(x)]
nas = lambda: stdin.readline().split()

from math import ceil

n, c, k = na()
T = nin(n)
T.sort()

ans = 0
i = 0
while i < n:
    m = T[i] + k
    cnt = 0
    while i < n and T[i] <= m and cnt < c:
        i += 1
        cnt += 1
    ans += 1
print(ans)

Measured memory_bytes: 7532
#include<bits/stdc++.h>
using namespace std;
const int N=55;
int a[N],dp[N][N];
vector<int>v;
int main()
{	
	int n,k,ans=0;
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)
	{
		for(int j=n;j>=i-1;j--)
		{
			int res=k-(n-(j-i))+1;
			if(res<0)
				break;
			v.clear();
			for(int l=1;l<i;l++)
			{
				dp[i][j]+=a[l];
				v.push_back(a[l]);
			}
			for(int l=j+1;l<=n;l++)
			{
				dp[i][j]+=a[l];
				v.push_back(a[l]);
			}
			sort(v.begin(),v.end());
			int sum=dp[i][j];
			for(int l=0;l<min(res,(int)v.size());l++)
			{
				if(v[l]>=0)
					break;
				sum-=v[l];
			}
			//printf("%d %d %d %d\n",i,j,dp[i][j],res);
			ans=max(ans,sum);
		}
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int n,m,l;
	int A[100][100];
	int B[100][100];
	long C[100][100];
	int i,j,k;

	scanf("%d %d %d",&n,&m,&l);

	for(i=0; i<n; i++){
		for(j=0; j<m; j++){
			scanf("%d",&A[i][j]);
		}
	}
	for(i=0; i<m; i++){
		for(j=0; j<l; j++)
			scanf("%d",&B[i][j]);
	}
	for(i=0; i<n; i++){
		for(j=0; j<l; j++){
			for(k=0; k<m; k++){
				C[i][j] += A[i][k]*B[k][j];
			}
		}
	}
	for(i=0; i<n; i++){
		for(j=0; j<l; j++){
			printf("%ld",C[i][j]);
			if(j!=(l-1))
				printf(" ");
		}
		printf("\n");
	}

	return 0;
}

Measured memory_bytes: 760
import java.util.Scanner;

public class Main {

	static Main instance = new Main();

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		//入力値
		int N = scan.nextInt();

		//WK変数
		long sum = 0L;

		//演算
		for (int i = 1; i <= N; i++) {
			if (i % 3 != 0 && i % 5 != 0) {
				sum += i;
			}
		}

		//結果出力
		System.out.println(sum);
	}
}

Measured memory_bytes: 35720
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvv vector<vvl>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvvl(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll n, k, s;std::cin >> n >> k >> s;
  ll INF = 1000000000;
  vll ans(n);
  if(s==INF){
    re(i, n){
      if(i<k) ans[i] = INF;
      else ans[i] = 1;
    }
    re(i, n) std::cout << ans[i] << (i==n-1?"\n":" ");
    return 0;
  }
  re(i, n){
    if(i<k) ans[i] = s;
    else ans[i] = INF;
  }
  re(i, n) std::cout << ans[i] << (i==n-1?"\n":" ");
  return 0;
}


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

int main(){
    int N, ans, left=0, right=0;
    string S;
    cin >> N;
    cin >> S;
    for(int i=0; i<N; i++){
	if(S[i] == '.'){
	    right++;
	}			
    }
    ans = right;
    for(int i=0; i<N; i++){
	if(S[i] == '.'){
	    right--;
	}
	else{
	    left++;	    
	}
	ans = min(ans, left+right);
    }
    cout << ans << endl;    
}


Measured memory_bytes: 640
#include <iostream>


#define FOR(i,a,b) for(int i = (a); i <(b); ++i)
int n;
char C[3][3];
int main() {
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            std::cin >> C[i][j];
        }
    }
    std::cout << C[0][0] << C[1][1] << C[2][2] << std::endl;
}

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

int main()
{
	string s;
	cin >> s;

	if (s == "SUN") {
		cout << 7 << endl;
	}
	else if (s == "SAT")
	{
		cout << 1 << endl;
	}
	else if (s == "FRI")
	{
		cout << 2 << endl;
	}
	else if (s == "THU")
	{
		cout << 3 << endl;
	}
	else if (s == "WED")
	{
		cout << 4 << endl;
	}
	else if (s == "TUE")
	{
		cout << 5 << endl;
	}
	else if (s == "MON")
	{
		cout << 6 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const int mod=1000000007 ;

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

	n=n%10 ;

	if(n==2||n==4||n==5||n==7||n==9){
		cout<<"hon" ;
	}
	else if(n==0||n==1||n==6||n==8){
		cout<<"pon" ;
	}
	else
		cout<<"bon" ;

}


int main(){

	
	int y ;

	y=1 ;
	//cin>>y ;

	while(y--)
	{	
		solve() ;
	}

}

Measured memory_bytes: 3636
N = int(input())
ans = sum(
    (N - q) // q
    for q in range(1, int(N**0.5) + 1)
    if (N - q) % q == 0 and N // ((N - q) // q) == N % ((N - q) // q)
) if N >= 2 else 0
print(ans)

Measured memory_bytes: 38896
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.ascii;


void main()
{
  auto h = readln.chomp.to!int;
  auto w = readln.chomp.to!int;
  auto n = readln.chomp.to!int;
  auto p = max(h, w);
  writeln(n / p + (n % p > 0));
}


Measured memory_bytes: 256
//84104971101048411497 - Can you guess what does this mean?
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef complex<double> point;
#define mapii map<int, int>
#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r) fto(i, l, r) cout << a[i] << " "; cout << endl
#define fdto(i,  r, l) for(int i = (r); i >= (l); --i)
#define fto(i, l, r) for(int i = (l); i <= (r); ++i)
#define forit(it, var) for(__typeof(var.begin()) it = var.begin(); it != var.end(); it++)
#define forrit(rit, var) for(__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); rit++)
#define ii pair<int, int>
#define iii pair<int, ii>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define X real()
#define Y imag()
#define maxN 100005
#define oo 2000000007

const double PI = acos(-1.0);

double fRand(double fMin, double fMax)
{
    double f = (double)rand() / RAND_MAX;
    return fMin + f * (fMax - fMin);
}

template <class T>
T min(T a, T b, T c) {
    return min(a, min(b, c));
}

template <class T>
T max(T a, T b, T c) {
    return max(a, max(b, c));
}

int n, a[maxN];

int main () {
    scanf("%d", &n);
    fto(i, 1, n) scanf("%d", &a[i]);

    int i = 1, ans = 1;
    bool rel[2] = {false, false};
    fto(i, 1, n-1) {
        if (a[i+1] > a[i]) rel[0] = true;
        if (a[i+1] < a[i]) rel[1] = true;
        if (rel[0] && rel[1]) {
            ++ans;
            rel[0] = rel[1] = false;
        }
    }
    printf("%d ", ans);

    return 0;
}


Measured memory_bytes: 640
loop{
  h, w = STDIN.gets.split.map(&:to_i)
  break if h == 0 && w == 0

  w_arr = Array.new(w)
  h_arr = Array.new(h)
  w_arr.fill('#')
  h_arr.fill(w_arr.join)
  puts h_arr.join("\n")
  puts
}

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

using namespace std;

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

// chmax, chmin
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;
}

void solve(long long N, std::vector<long long> P, std::vector<long long> Q) {
    vector<long long> A;
    for (int i = 0; i < N; i++) A.push_back(i + 1);
    int idx = 0;
    int idx1 = 0;
    int idx2 = 0;
    do{
        if( A == P ) idx1 = idx;
        if( A == Q ) idx2 = idx;
        idx++;
    }while(next_permutation(A.begin(), A.end()));
    cout << abs(idx1-idx2) << endl;
}

int main() {
    long long N;
    scanf("%lld", &N);
    std::vector<long long> P(N);
    for (int i = 0; i < N; i++) {
        scanf("%lld", &P[i]);
    }
    std::vector<long long> Q(N);
    for (int i = 0; i < N; i++) {
        scanf("%lld", &Q[i]);
    }
    solve(N, std::move(P), std::move(Q));
    return 0;
}


Measured memory_bytes: 256
a = [list(map(int, input().split())) for row in range(3)]
n = int(input())
b = [int(input()) for hoge in range(n)]
a1 = a[0] + a[1] + a[2]
c = []
for poge in a1:
  if poge in b:
    c.append(0)
  else:
    c.append(1)
if min((c[0]+c[1]+c[2]),(c[3]+c[4]+c[5]),(c[6]+c[7]+c[8]),(c[0]+c[3]+c[6]),
      (c[1]+c[4]+c[7]),(c[2]+c[5]+c[8]),(c[0]+c[4]+c[8]),(c[2]+c[4]+c[6])) == 0:
  print('Yes')
else:
  print('No')


Measured memory_bytes: 3064
from collections import Counter
N = int(input())
s = [input() for _ in range(N)]
M = int(input())
t = [input() for _ in range(M)]
c = Counter()
for i in s:
    c[i] += 1
for j in t:
    c[j] -= 1
maxc = 0
for i in c:
    if c[i] > maxc:
        maxc = c[i]
        
print(maxc)

Measured memory_bytes: 3316
#ABC45 B
S ={}
sa = input()
sb = input()
sc = input()

S['a'] = sa
S['b'] = sb
S['c'] = sc

#first payer is A
player = 'a'

for i in range(len(sa)+len(sb)+len(sc)):
  next_player = S[player][0]
  S[player] = S[player][1:]
  
  player = next_player
  if len(S[player])==0:
       break
      
print(player.upper())

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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

    int N,D;
    Scd2(N,D);

    int ans = 0;
    Repe(i,N+1,1){
        Repe(j,D+1,22){
            if( j%10 < 2 ) continue;
            if( (j/10) * (j%10) == i ) ans++;
        }
    }

    printf ("%d\n", ans );

    return 0;
}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
int n, x;
  cin >> n >> x;
  // L - array
  int L[n];
  for (int i = 0; i < n; i++)
    cin >> L[i];
  int ans = 1;
  int res = 0;
  for (int i = 0 ; i < n; i++){
  	if(res + L[i] < x+1){
    	res += L[i];
      	ans++;
    }
    else break;
  
  }
  cout << ans << '\n';
 
	return 0;
}

Measured memory_bytes: 256
def main():
    """
    1 <= N <= 10^5
    1 <= K <= 10^12
    1 <= Ai <= 10^12
    """
    N, K = map(int, input().split())
    *A, = map(int, input().split())

    ans = editorial(N, K, A)
    print(ans)


def editorial(N, K, A):
    """
    """
    ans = 0
    # K を超えないXをbitを使って探す
    for d in range(40, -2, -1):
        # d = -1 は X = K の場合
        # 上位のbitから処理、1であるbitなら対象
        if d != -1 and (K & (1 << d)) == 0:
            # bit=1: ずっと1
            # bit=0: TODO
            continue

        # 各aについて上位bitから処理
        tmp = 0
        for e in range(40, -1, -1):
            mask = 1 << e

            # bit=1である数
            num = 0
            for a in A:
                if a & mask:
                    num += 1

            if e > d:
                # 下位bit
                if K & mask:
                    tmp += mask * (N - num)
                else:
                    tmp += mask * num
            elif e == d:
                # 同じbit
                tmp += mask * num
            else:
                # 上位bit
                tmp += mask * max(num, N - num)

        ans = max(ans, tmp)

    return ans


if __name__ == '__main__':
    main()


Measured memory_bytes: 73488
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF INT_MAX
#define eps LDBL_EPSILON
#define moder 100000
#define pie 3.141592653589793238462643383279
#define P std::pair<int,int>
#define prique priority_queue
using namespace std;
struct edge{int from,to,cost;};
int n,m,a,b,c;
int d[110][110];
vector<edge> vec;
signed main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++)d[i][j]=INF;
	}
	rep(i,m){
		cin>>a>>b>>c;
		d[a][b]=min(d[a][b],c);
		d[b][a]=min(d[b][a],c);
		vec.push_back({a,b,c});
	}
	for(int k=1;k<=n;k++){
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
			}
		}
	}
	int ans=0;
	for(edge e:vec){
		if(d[e.from][e.to]<e.cost)ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 384
def input_int():
    return map(int, input().split())

def one_int():
    return int(input())

def one_str():
    return input()

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

A, B = input_int()



flg=True
for i in range(1, 10000):
    temp_A = int(i*0.08)
    temp_B = int(i*0.1)
    
    if temp_A == A and temp_B == B:
        print(i)
        flg=False
        break

if flg:
    print(-1)

Measured memory_bytes: 3064
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String a = sc.next();
    String b = sc.next();
    String[] c = a.split("");
    String[] d = b.split("");
    int cnt = 0;
    for(int i = 0; i < 3; i++){
      if(c[i].equals(d[i])){
        cnt++;
      }
    }
    System.out.println(cnt);
  }
}

Measured memory_bytes: 22740
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
    int n, z, w, a[2000];
    cin >> n >> z >> w;

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

    int ans = max(abs(a[n-1] - w), (n > 1 ? abs(a[n-1] - a[n-2]) : 0));

    cout << ans << endl;

    return 0;
}


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

int debug = 0;

int main()
{
    int n,m;
    cin >> n>>m;
    vector<int> wa(n);
    vector<bool> ac(n);

    rep(i,n){
        wa[i]=0;
        ac[i]=false;
    }
    int p;
    string st;

    int wanum=0;
    int acnum=0;

    rep(i,m){
        cin>> p >> st;
        if(ac[p-1]) continue;

        if(st=="AC"){
            ac[p-1]= true;
            acnum++;
            wanum += wa[p-1];
        }else if(st == "WA"){
            wa[p-1]++;
        }
    }


    cout << acnum << " " << wanum << endl;
    return 0;

}

Measured memory_bytes: 640
def tax(p,x):
    return p*(100+x)//100
def solve(x,y,s):
    l=[]
    for i in range(1,s):
        for j in range(1,s):
            if tax(i,x)+tax(j,x)==s:
                l.append(tax(i,y)+tax(j,y))
            if  tax(i,x)+tax(j,x)>s:
                break
    print(max(l))
while True:
    a,s,d=map(int,input().split())
    if a==0 and s==0 and d==0:
        break
    solve(a,s,d)


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

int main(){
    
    int N;
    cin >> N;
    long long L[N];
    for(int i = 0; i < N;i++)cin >>L[i];
    long long ans = 0;
    long long cont = 0;
    while(true){
        
        if(L[cont]<L[cont+1]){
            //cout <<"a"<<endl;
            while(L[cont]<=L[cont+1]&&cont<N)cont++;
        }else if(L[cont]>L[cont+1]){
            //cout <<"b"<<endl;
            while(L[cont]>=L[cont+1]&&cont<N)cont++;
        }else{
            cont++;
            continue;
        }
        cont++;
        //cout << cont <<endl;
        ans++;
        if(cont>=N)break;
    }
    cout <<ans <<endl;
    
}

    
    



Measured memory_bytes: 1024
'use strict'
function Main(input){
  input=input.trim();
  input=input.split(/\s+/);
  input=input.map(x=>x-0);
  var N=input[0];
  var M=input[1];
  var A=[];
  var B=[];
  for(let i=M;i>0;i--){
    B[i]=input.pop();
    A[i]=input.pop();
  }
  var islands=[];
  for(let i=1;i<=N;i++){
    islands[i]=new Node(null,null,null,1);
  }
  var result=[];
  for(let i=M;i>0;i--){
    let a=islands[A[i]];
    let b=islands[B[i]];
    result[i]=merge(a,b);
  }
  result[M+1]=N*(N-1)/2;
  for(let i=M;i>0;i--){
    result[i]=result[i+1]-result[i];
  }
  result.splice(0,2);
  result=result.join('\n').trim();
  console.log(result);
}

function Node(p,l,r,w){
  var t=this;
  t.parent=p;
  t.left=l;
  t.right=r;
  t.weight=w;
}

Node.prototype.root=function(){
  var t=this;
  var p=t.parent;
  if(p)return p.root();
  else return t;
}

Node.prototype.appendChild=function(c){
  var t=this;
  var l=t.left;
  var r=t.righr;
  var cw=c.weight;
  t.weight+=cw;
  if(!l){
    t.left=c;
    c.parent=t;
    return;
  }
  if(!r){
    t.right=c;
    c.parent=t;
    return;
  }
  var lw=l.weight;
  var rw=r.weight;
  if(lw<=rw)
    l.appendChild(c);
  else
    r.appendChild(c);
}

function merge(node0,node1){
  var t0=node0.root();
  var t1=node1.root();
  if(t0===t1)return 0;
  var w0=t0.weight;
  var w1=t1.weight;
  if(w0>=w1)
    t0.appendChild(t1);
  else
    t1.appendChild(t0);
  return w0*w1;
}

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

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

#define whole(f, x, ...)                                 \
  ([&](decltype((x)) whole) {                            \
    return (f)(begin(whole), end(whole), ##__VA_ARGS__); \
  })(x)

using namespace std;
using ll = long long;

void solve() {
  ll a, b, n;
  cin >> a >> b >> n;

  const ll x = min(b - 1, n);

  const ll ans = (floor(a * x / b) - a * floor(x / b));

  std::cout << ans << endl;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);

  solve();
  return 0;
}


Measured memory_bytes: 3640
n = int(input())
x = input().split()
y = input().split()

D1 = 0
D2 = 0
D3 = 0
D = []

for i in range(n):
    D1 += abs(float(x[i])-float(y[i]))
    D2 += (abs(float(x[i])-float(y[i])))**2
    D3 += (abs(float(x[i])-float(y[i])))**3
    D.append(abs(float(x[i])-float(y[i])))

print(D1)
print(D2**(1/2))
print(D3**(1/3))
print(max(D))



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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define FOR(i, a, b) for (int i=a; i<b; i++)

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pi;

signed main() {
  IOS;
  int N,M, L,R, Lmax=0,Rmin=(int)1e5, ans;
  cin >> N >> M;
  FOR(i, 0, M) {
    cin >> L >> R;
    Lmax = max(Lmax, L);
    Rmin = min(Rmin, R);
  }

  cout << max(0, Rmin - Lmax + 1) << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using lint=int64_t;
using namespace std;

constexpr int INF=1e6;

int main()
{
	int N;
	int B[110]={};

	cin >> N;
	B[0]=B[N]=INF;
	for(int i=1;i<=N-1;i++)
		cin >> B[i];
	
	int ans=0;
	for(int i=0;i<N;i++)
		ans+=min(B[i],B[i+1]);
	cout << ans << endl;
	return 0;
}



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

#define LL long long
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

int po(int x) {
    int r = 0;
    for(;0 < x;) {
        x /= 10;
        r++;
    }
    return r%2;
}

int main() {
    int N;
    cin >> N;
    int r = 0;
    for(int i = 1;i <= N;i++) {
        r += po(i);
    }
    cout << r << endl;
    return 0;
}



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

using namespace std;


long long int MOD = 1000000007;

int N;
int A[100005];
multiset<int> S;

long long int dp[100005];

int main(void) {

	cin >> N;

	dp[0] = 1;

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

	for (int i = 0; i <= 2; i++) { S.insert(0); }

	for (int i = 1; i <= N; i++) {
		long long int num = S.count(A[i]);
		if (num == 0) { cout << 0 << endl; return 0; }
		dp[i] = (dp[i - 1] * num) % MOD;
		auto it = S.find(A[i]);
		S.erase(it);
		S.insert(A[i] + 1);
	}
	cout << dp[N] << endl;
	return 0;
}

Measured memory_bytes: 1408
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#include <boost/rational.hpp>
*/
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define repr4(i,s,n) for(ll i = (n);i>=(s);i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
using Graphw = vector<vector<pair<ll,ll>>>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
#define MOD 1000000007;
/*
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
// 有理数型
using Rat = boost::rational<Bint>;
*/


int main(){
ll N,M;
cin>>N>>M;
if(2*N>=M){
    cout<<M/2<<endl;
}
else{
   ll ans=N;
    M-=N*2;
    ans+=M/4;
    cout<<ans<<endl;
}


return 0;
}

Measured memory_bytes: 3484
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);
		double a = sc.nextDouble(),b = sc.nextDouble();

		String ans = "";

		if (a > b ) {
			ans = "GREATER";
		} else if (a < b) {
			ans = "LESS";
		} else {
			ans = "EQUAL";
		}

		System.out.println(ans);
	}

}

Measured memory_bytes: 22740
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
#define pii pair<int,int> 
#define ff first
#define ss second
#define mii map<int,int>
#define si set<int>
#define sti stack<int>
#define qi queue<int>
#define vi vector<int>
#define pq priority_queue<int>
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int M=1e9+7;

int32_t main()
{
	int n,m;
	cin>>n>>m;
	int a[n];
	for(int i=0;i<n;i++)
		cin>>a[i];
	sort(a,a+n);
	pii p[m];
	for(int i=0;i<m;i++)
	{
		int x,y;
		cin>>x>>y;
		p[i]={y,x};
	}
	sort(p,p+m);
	int j=m-1;
	for(int i=0;i<n;i++)
	{
		if(a[i]<p[j].ff)
		{
			a[i]=p[j].ff;
			p[j].ss--;
		}
		else
			break;
		if(p[j].ss==0)
		{
			if(j>0)
				j--;
			else
				break;
		}
	}
	int sum=0;
	for(int i=0;i<n;i++)
		sum+=a[i];
	cout<<sum<<endl;
}

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

static const int MAX = 60;
int main(){
	int N,A[MAX],B[MAX],C[MAX];
	cin >> N;
	for (int i = 1; i<=N; i++) cin >> A[i];
	for (int i = 1; i<=N; i++) cin >> B[i];
	for (int i = 1; i<=(N-1); i++) cin >> C[i];
	
	int old_index=0;
	int count = 0;
        for(int i=1;i<=N;i++){
	count +=B[(A[i])];
		if(i==1){
		old_index = A[i];
		}
		else if(A[i]==(old_index+1)){
		count += C[old_index];
		}
		old_index = A[i];
	}

	cout << count << endl;
}

Measured memory_bytes: 256
cnt = 0
def insertion_sort(A, n, g):
    global cnt
    for i in range(g, n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j -= g
            cnt += 1
        A[j+g] = v
def shell_sort(A, n):
    G = [1]
    for i in range(25):
        g = G[-1]*2+1
        if g > len(A)-1:
            break
        G.append(g)
    G.reverse()
    m = len(G)
    for g in G:
        insertion_sort(A, n, g)
    return m, G, A
n = int(input())
A = [int(input()) for _ in range(n)]
m, G, A = shell_sort(A, n)
print(m)
print(" ".join(map(str, G)))
print(cnt)
for a in A:
    print(a)


Measured memory_bytes: 45516
#include<stdio.h>

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

	int start = a / k*k;
	if (a % k == 0)
	{
		printf("OK");
		return 0;
	}
	else
	{
		if (start + k <= b)
		{
			printf("OK");
			return 0;
		}
		else
		{
			printf("NG");
			return 0;
		}
	}
}

Measured memory_bytes: 1728
# 参考: https://atcoder.jp/contests/abc074/submissions/4727060
A, B, C, D, E, F = gets.chomp.split.map(&:to_i)

xs = []
(0..(F / 100)).each do |i|
  (0..(F / 100)).each do |j|
    x = (100 * A * i) + (100 * B * j)
    xs << x if x <= F
  end
end

ys = []
(0..(F / C)).each do |i|
  (0..(F / C)).each do |j|
    y = (C * i) + (D * j)
    ys << y if y <= F
  end
end

max_x = 0
max_y = 0
max_cond = 0
xs.each do |x|
  ys.each do |y|
    next if F < x + y
    if x != 0 && (x / 100) * E >= y
      cond = (100.0 * y) / (x + y)
      if cond > max_cond
        max_x = x
        max_y = y
        max_cond = cond
      end
    end
  end
end

if max_x == 0
  puts "#{100 * A} 0"
else
  puts "#{max_x + max_y} #{max_y}"
end

Measured memory_bytes: 3836
#include <iostream>
#include <algorithm>

using namespace std;

int n,maxx(0);
string s[200001];
int a[200001];

int main()
{
    cin >> n;
    for (int i(1); i<=n; i++)
        cin >> s[i];
    sort(s+1,s+1+n);
    s[0]=" ";
    for (int i(1); i<=n; i++)
    {
        if (s[i]==s[i-1]) a[i]=a[i-1]+1;
        else a[i]=1;
        maxx=max(maxx,a[i]);
    }
    for (int i(1); i<=n; i++)
        if (a[i]==maxx)
            cout << s[i] << endl;
}


Measured memory_bytes: 15104
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <limits>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

int main(){
  ll n,k; cin>>n>>k;
  vector<ll> h(n);
  rep(i,n) cin>>h[i];
  vector<ll> dp(n);
  constexpr ll inf = numeric_limits<ll>::max();
  for( ll i=1; i<n; i++ ){
    ll tmp=inf;
    for( ll j=1; j<=k; j++ ){
      if(i-j >= 0){
        tmp = min(tmp, dp[i-j] + abs(h[i]-h[i-j]));
      }
    }
    dp[i]=tmp;
  }
  cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 4784
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).*begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

const int M = 1000000007;

string s;

typedef string::const_iterator State;
int number(State&);
int term(State&);
int expression(State&);


// ??°??????????????????????????????????????°????????????
int number(State &begin) {
    int ret = 0;

    while (isdigit(*begin)) {
        ret *= 10;
        ret += *begin - '0';
        begin++;
    }

    return ret;
}


// ?????????????????????????????????????????????????????????????????????
int term(State &begin) {
    if (*begin == 'S') {
        begin++; begin++;
        long long ret = expression(begin);
        begin++;
        return ret * ret % M;
    } else {
        return number(begin);
    }
}

// ?????????????????????????????????????????????????????????????????????
int expression(State &begin) {
    int ret = term(begin);

    while(s.end() - begin >= 2){
        if (*begin ==  '>' && *(begin + 1) == '>' && *(begin + 2) != '>'){
            begin++; begin++;
            ret = ret >> min(term(begin), 31);
        } else {
            break;
        }
    }

    return ret;
}

int main(){
    string tmp;
    while(getline(cin,tmp),tmp != "#"){
        s="";
        for(auto it:tmp) if(it != ' ') s+=it;
        State state = s.begin();
        cout << expression(state) << endl;
    }
}

Measured memory_bytes: 4852
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod=1000000007;
bool q[12];
bool q2[120];
bool q3[1020];

int main(){
  int N;
  string S;
  cin >> N >> S;
  int cnt=0;
  for(int i=0;i<N;i++){
    int w=S[i]-'0';
    if(q[w])continue;
    for(int j=i+1;j<N;j++){
      int e=S[j]-'0';
      int w2=10*w+e;
      if(q2[w2])continue;
      for(int k=j+1;k<N;k++){
        int f=S[k]-'0';
        int w3=100*w+10*e+f;
        if(!q3[w3])cnt++;
        q3[w3]=true;
      }
      q2[w2]=true;
    }
    q[w]=true;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

using namespace std;
typedef long long int ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;
ll MOD = 1000000007;

int main()
{
    ll W, H, N;
    cin >> W >> H >> N;
    vector<P> vec(2);
    vec[0] = make_pair(0, 0);
    vec[1] = make_pair(W, H);
    rep(i, N) {
        ll x, y, a;
        cin >> x >> y >> a;
        if (a == 1) {
            vec[0].first = max(vec[0].first, x);
        } else if (a == 2) {
            vec[1].first = min(vec[1].first, x);
        } else if (a == 3) {
            vec[0].second = max(vec[0].second, y);
        } else if (a == 4) {
            vec[1].second = min(vec[1].second, y);
        }
    }
    int w = vec[1].first - vec[0].first;
    int h = vec[1].second - vec[0].second;
    ll ans = max(0, w) * max(0, h);
    cout << ans << endl;
    return 0;
}


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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





typedef long long ll;
const ll mod = 1e9+7;
const int maxn = 2e5 + 5;

ll pw(ll x, ll y) {
    x %= mod;
    ll res = 1;
    while (y > 0) {
	if (y%2 == 1) {
	    res *= x;
	    res %= mod;
	}
	x = x * x;
	x %= mod;
	y = y / 2;

    }
    return res;

}


ll inv(ll x) {
    assert(x != 0);
    return pw(x, mod-2);

}

ll fac[maxn], ifac[maxn];

int n;
vector<int> g[maxn];
ll siz[maxn];
ll dp[maxn];
ll ans[maxn];



// compute siz
void dfs(int at, int p) {
    siz[at]=1;
    for (int to: g[at]) {
	if (to == p) continue;
	dfs(to, at);
	siz[at]+=siz[to];
    }
}



// problem bijects to "count all topological orderings w.r.t. parent/children"

// dp[at] = (siz[at]-1)! * for all children [ dp[to]/siz[to] ]
// place `at` at beginning, then permute all nodes in subtree
// each subtree is independent, so we can multiply all dp[to] together
// we divide by siz[to] because we can "interleave" subtree results, so we
// can interleave via (siz[at]-1)!, but divide away classes that don't respect topological requirement.

void dfs2(int at, int p) {
    dp[at]=fac[siz[at]-1];
    for (int to: g[at]) {
	if (to == p) continue;
	dfs2(to, at);
	dp[at]*=dp[to];
	dp[at]%=mod;
	dp[at]*=ifac[siz[to]];
	dp[at]%=mod;
    }
}



// rerooting
void dfs3(int at, int p) {
    ans[at]=dp[at];
    for (int to: g[at]) {
	if (to == p) continue;
	//undo `to` in me
	dp[at]*=fac[siz[to]];
	dp[at]%=mod;
	dp[at]*=inv(dp[to]);
	dp[at]%=mod;
	dp[at]*=ifac[siz[at]-1];
	dp[at]%=mod;
	siz[at]-=siz[to];
	dp[at]*=fac[siz[at]-1];
	dp[at]%=mod;
	
	//add me to `to`
	dp[to]*=dp[at];
	dp[to]%=mod;
	dp[to]*=ifac[siz[at]];
	dp[to]%=mod;
	dp[to]*=ifac[siz[to]-1];
	dp[to]%=mod;
	siz[to]+=siz[at];
	dp[to]*=fac[siz[to]-1];
	dp[to]%=mod;
	
	
	dfs3(to, at);

	//undo `to`
	dp[to]*=ifac[siz[to]-1];
	dp[to]%=mod;
	siz[to]-=siz[at];
	dp[to]*=fac[siz[to]-1];
	dp[to]%=mod;
	dp[to]*=fac[siz[at]];
	dp[to]%=mod;
	dp[to]*=inv(dp[at]);
	dp[to]%=mod;

	dp[at]*=ifac[siz[at]-1];
	dp[at]%=mod;
	siz[at]+=siz[to];
	dp[at]*=fac[siz[at]-1];
	dp[at]%=mod;
	dp[at]*=dp[to];
	dp[at]%=mod;
	dp[at]*=ifac[siz[to]];
	dp[at]%=mod;
    }
}

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

    fac[0]=ifac[0]=1;
    for (int i=1; i<maxn; i++) {
	fac[i]=1LL*i*fac[i-1]%mod;
	ifac[i]=inv(fac[i]);
    }
    assert(fac[4]==24);
    
    cin>>n;
    for (int i=0; i<n-1; i++) {
	int u,v; cin>>u>>v;
	g[u].push_back(v);
	g[v].push_back(u);
    }

    dfs(1,0);
    dfs2(1,0);
    dfs3(1,0);

    for (int i=1; i<=n; i++) {
	ans[i]%=mod;
	ans[i]+=mod;
	ans[i]%=mod;
	cout<<ans[i]<<"\n";
    }
  

    return 0;
}


Measured memory_bytes: 21748
/*
	Nishant Singh
	nishant.ns19
*/
#include <bits/stdc++.h>
#include <functional> 
#include <iostream> 
// ******** Big Integer ********
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
// #define ll1024  int1024_t
// ******** Big Integer ********
// ******** Using PBDS ********
// #include <ext/pb_ds/assoc_container.hpp> // Common file 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds; 
// #define ook order_of_key    //count of strictly smaller elements
// #define fbo find_by_order   //find element at an index 
// ******** Using PBDS ********
using namespace std;
#define ll long long
#define ld long double
#define pll pair<long long,long long>
#define pii pair<int,int>
#define vll vector<ll>
#define vec vector
#define setcount(x) __builtin_popcountll(x)
#define f first
#define s second
#define mp make_pair
#define REP(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define REV(i,a,b) for(ll i=(a);i>=(b);i--)
#define pb push_back
#define in insert
#define init(x,a) memset(x,a,sizeof(x))
#define all(c) c.begin(),c.end()
#define pq priority_queue
#define ffl fflush(stdout)
#define mset multiset
#define out(x) cout<<#x<<" = "<<" "<<x<<"\n";
#define ub upper_bound
#define lb lower_bound 
#define ln "\n"
#define Y "YES"
#define N "NO"
ll const inf=2e18;
// ******** Using PBDS ********
// typedef tree<long long, null_type, less<long long>, rb_tree_tag, 
//              tree_order_statistics_node_update> 
//                 os; 
// ******** Using PBDS ********

ll gcd(ll a,ll b)
{
	if (b == 0) 
		return a; 
	return gcd(b, a % b);  
}
ll modexp(ll x, ll n, ll mod){
	if(n==0){
		return 1;
	}
	else if(n&1){
		return (modexp((x*x)%mod, n/2,mod)%mod * x%mod)%mod;
	}
	else{
		return (modexp((x*x)%mod, n/2,mod)%mod);
	}
}
inline ll add(ll a,ll b,ll mod) 
{ 
	return (a%mod + b%mod + mod)%mod; 
}
inline ll sub(ll a,ll b,ll mod) 
{ 
	return (a%mod - b%mod + mod)%mod; 
}
// ******** GLOBAL VARIABLES ********
ll n;
// ******** GLOBAL VARIABLES ********
void solve(){
	string x;
	cin>>n>>x;
	ll cur=0;
	ll ans[n];
	// cout<<cur<<ln;
	ll cnt=0;
	ll mod1=0;
	ll mod2=0;

	REP(i,n)
	{
		if(x[i]=='1')
			cnt++;
	}

	REP(i,n)
	{
		mod1=(mod1*(2LL))+(x[i]-'0');
		mod1=mod1%(cnt+1);

	}
	if(cnt!=1)
	{
		REP(i,n)
		{
			mod2=(mod2*(2LL))+(x[i]-'0');
			mod2=mod2%(cnt-1);
		}
	}

	REP(i,n)
	{
		if(x[i]=='1')
		{
			if(cnt==1)
			{
				ans[i]=0;
				continue;
			}
			cnt--;
			ll temp = sub(mod2, modexp(2, n-i-1,cnt),cnt);
			ll steps = 1;
			while(temp){
				temp=temp%(setcount(temp));
				steps++;
			}
			cnt++;
			ans[i]=steps;
		}
		else
		{
			cnt++;
			ll temp = add(mod1, modexp(2, n-i-1,cnt),cnt);
			ll steps = 1;
			while(temp){
				temp=temp%(setcount(temp));
				steps++;
			}
			cnt--;
			ans[i]=steps;
		}
	}
	REP(i,n)
	{
		cout<<ans[i]<<ln;
	}
}  
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll T=1;
	// cin>>T; 	
	for(int t=1;t<=T;t++)
	{
		// cout<<"Case #"<<t<<": ";
		solve();
	}
	return 0;
}

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

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	int H, W, A, B;

	cin >> H >> W >> A >> B;

	for(int i = 0; i < H; i++) {
		for(int j = 0; j < W; j++) cout << int((i < B) ^ (j < A));
		cout << "\n";
	}
	return 0;
}


Measured memory_bytes: 1280
N = int(input())
a = sorted(list(map(int, input().split())), reverse=True)

Alice, Bob = 0, 0

if N // 2 * 2 != N:             # odd
    for i in range(0,N-2,2):
        Alice += a[i]
        Bob += a[i+1]
    Alice += a[N-1]
else:                           # even
    for i in range(0,N,2):
        Alice += a[i]
        Bob += a[i+1]

print(Alice - Bob)

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


int main() {
    int N, K;
    cin >> N >> K;
    vector<int> h(N + 1);
    for (int i = 1; i <= N; i++) {
        cin >> h[i];
    }

    vector<int> cost(N + 1, 0);
    for (int i = 2; i <= N; i++) {
        int minimum = INT_MAX;
        for(int j = 1; j <= K; j++) {
            if (i - j <= 0) continue;
            minimum = min(minimum, cost[i - j] + abs(h[i]- h[i-j]));            
        }
        cost[i] = minimum;
    }

    cout << cost[N] << endl;
}

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

int main() {
  int N,K,X,Y,ans=0;
  cin >> N >> K >> X >> Y;
  if(N>K){
  for(int i=0;i<K;i++)
    ans+=X;
  for(int j=0;j<N-K;j++)
    ans+=Y;
  }
  else{
    for(int k=0;k<N;k++)
      ans+=X;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long x,d,k;
int main() {
	cin>>x>>k>>d;
	if(x<0) x=-x;
//	if(x>0) {
		if(x/k<d && x/d<k) {
			if((k-(x/d))%2==0)
				cout<<x%d<<endl;
			else cout<<(d-(x%d))<<endl;
		}
		else {
			if(x-d*k<0)
				while(1) ;
			cout<<(x-d*k)<<endl;
		}
//	}
//	else cout<<"0"<<endl;
	return 0;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
struct edge{
  ll to, cost;
};
ll n,m,r;
const ll INF = 1e18;
const int max_n = 1e4;
ll d[max_n][max_n];
int main(){
  cin >> n >> m >> r;
  vector<ll> v(r);
  for(int i=0 ; i<r ; i++){
    cin >> v[i];
    v[i]--;
  }
  for(int i=0 ; i<n ; i++){
    for(int j=0 ; j<n ; j++){
      d[i][j] = INF;
      if(i==j) d[i][j] = 0;
    }
  }
  for(int i=0 ; i<m ; i++){
    ll x,y,z; cin >> x >> y >> z;
    --x;  --y;
    d[x][y] = d[y][x] = z;
  }
  for(int k=0 ; k<n ; k++){
    for(int i=0 ; i<n ; i++){
      for(int j=0 ; j<n ; j++){
        d[i][j] = min(d[i][j], d[i][k]+d[k][j]);
      }
    }
  }
  ll mid = INF;
  sort(v.begin(), v.end());
  do{
    ll kd = 0;
    for(int i=0 ; i+1<r ; i++){
      kd += d[v[i]][v[i+1]];
    }
    mid = min(mid, kd);
  }while(next_permutation(v.begin(), v.end()));
  cout << mid << endl;
  return 0;
}


Measured memory_bytes: 14720
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
    	
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int N = sc.nextInt();
		int T = sc.nextInt();
		int min = 10000;
		
		int num[][] = new int[2][N];

		for(int i = 0;i < N;i++){
			num[0][i] = sc.nextInt();
			num[1][i] = sc.nextInt();
		}

		for(int i = 0;i < N;i++){
			if(num[1][i]<=T){
				if(num[0][i]<min){
					min = num[0][i]; 
				}
			}
		}

		if(min == 10000){
			System.out.println("TLE");
		}else{
			System.out.println(min);
		}

   		sc.close();
        return ;

    }
    
}



Measured memory_bytes: 23124
#include <algorithm>
#include <iostream>
#include <vector>
#include <set>
#include <functional>
using namespace std;

int main() {
    int n, m; cin >> n >> m;
    string s; cin >> s;
    vector<vector<int>> g(n);
    vector<int> cntA(n), cntB(n);
    for (int i = 0; i < m; i++) {
        int a, b; cin >> a >> b; a--, b--;
        g[a].emplace_back(b);
        g[b].emplace_back(a);
        (s[b] == 'A' ? cntA[a] : cntB[a])++;
        (s[a] == 'A' ? cntA[b] : cntB[b])++;
    }
    vector<int> alive(n, true);
    int cnt = n;
    function<void(int)> del = [&](int u) {
        if (!alive[u]) return ;
        alive[u] = false, cnt--;
        for (int v: g[u]) {
            (s[u] == 'A' ? cntA[v] : cntB[v])--;
            if (alive[v] && (cntA[v] == 0 || cntB[v] == 0)) del(v);
        }
    };
    for (int i = 0; i < n; i++) if (cntA[i] == 0 || cntB[i] == 0) del(i);
    cout << (cnt ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 17540
#include <stdio.h>
#include <string.h>

int main()
{
  char s[101];
  gets(s);
  
  int len = strlen(s);
  
  int i,sum = 0;
  
  for(i = 0;i <= (len - 1)/2;i++){if(s[i] != s[len-1-i])sum++;}
  printf("%d",sum);
}


Measured memory_bytes: 128
import java.util.*;
public class Main{
    public static void main(String[] args){
	new Main().run();
    }
    Scanner sc = new Scanner(System.in);

    int n, m, ans;
    int[] sn, ew;

    void run(){
	while(sc.hasNext()){
	    n = sc.nextInt();
	    m = sc.nextInt();
	    if(n==0 && m==0) break;
	    sn = new int[n];
	    ew = new int[m];
	    for(int i=0; i<n; i++)
		sn[i] = sc.nextInt();
	    for(int i=0; i<m; i++)
		ew[i] = sc.nextInt();
	    ans = 0;

	    for(int i=0; i<n; i++)
		for(int k=0; k<m; k++){
		    solve(i, k);
		}
	    System.out.println(ans);
	}
    }

    void solve(int i, int k){
	int sumA=sn[i], sumB=ew[k];
	i++; k++;
	while(true){
	    if(sumA==sumB){
		//System.out.println("**"+sumA);
		ans++;
		if(i==n || k==m) break;
		sumA += sn[i];
		sumB += ew[k];
		i++;
		k++;
	    }
	    else if(sumA<sumB){
		if(i==n) break;
		sumA += sn[i];
		i++;
	    }
	    else if(sumA>sumB){
		if(k==m) break;
		sumB += ew[k];
		k++;
	    }
	}
    }
}

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

int main() {
  int n, temp = 0, total = 0;
  std::cin >> n;
  std::vector<int> x(n, 0);
  
  for (int i = 0; i < n; i++) {
    std::cin >> x.at(i);
    total += x.at(i);
    temp = (temp > x.at(i)?temp:x.at(i));
  }
  
  total -= (temp / 2);
  
  std::cout << total << std::endl;
  
  return 0;
}


Measured memory_bytes: 256