akhauriyash/Code-Regression huggingface dataset:
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;
import java.util.Scanner;
import java.util.stream.IntStream;
import java.util.stream.Stream;

public class Main {
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int h = scanner.nextInt();
        final int w = scanner.nextInt();
        final boolean[][] table = new boolean[h][w];

        int black = 0;
        for (int i = 0; i < h; i++) {
            final char[] col = scanner.next().toCharArray();
            for (int j = 0; j < w; j++) {
                if (col[j] == '.') {
                    table[i][j] = true;
                } else {
                    black++;
                }
            }
        }

        final Deque<Pair> points = new ArrayDeque<>();
        points.add(new Pair(0, 0, 1));

        while (!points.isEmpty()) {
            final Pair pair = points.poll();
            if (pair.x == w - 1 && pair.y == h - 1) {
                System.out.println(h * w - (black + pair.depth));
                return;
            }

            if (pair.x > 0 && table[pair.y][pair.x - 1]) {
                table[pair.y][pair.x - 1] = false;
                points.add(new Pair(pair.x - 1, pair.y, pair.depth + 1));
            }

            if (pair.x < w - 1 && table[pair.y][pair.x + 1]) {
                table[pair.y][pair.x + 1] = false;
                points.add(new Pair(pair.x + 1, pair.y, pair.depth + 1));
            }

            if (pair.y < h - 1 && table[pair.y + 1][pair.x]) {
                table[pair.y + 1][pair.x] = false;
                points.add(new Pair(pair.x, pair.y + 1, pair.depth + 1));
            }

            if (pair.y > 0 && table[pair.y - 1][pair.x]) {
                table[pair.y - 1][pair.x] = false;
                points.add(new Pair(pair.x, pair.y - 1, pair.depth + 1));
            }
        }

        System.out.println(-1);
    }

    static class Pair {
        final int x;
        final int y;
        final int depth;

        Pair(final int x, final int y, final int depth) {
            this.x = x;
            this.y = y;
            this.depth = depth;
        }
    }
}


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

/* #pragma */
/*
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/

/*alias*/
#define F first
#define S second

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define itn int

/*template*/
template<class T>inline bool amax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>inline bool amin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

/* func */
int GCD(int a,int b){return b?GCD(b,a%b):a;}
long long GCD(long long a, long long b){return b ? GCD(b, a%b) : a;}
int LCM(int a, int b){return a * b / GCD(a, b);}
long long LCM(long long a, long long b){return a * b / GCD(a, b);}

/*struct*/
struct aaa {
	aaa() {
		cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20);
	};
}aaaaaaa;

/* const */
const int INF = 1001001001;
const long long LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7; //10^9
const double EPS = 1e-9;
const int dx[] = { 1, 1, 0, -1, -1, -1, 0, 1 }, dy[] = { 0, 1, 1, 1, 0, -1, -1, -1 };
//Counterclockwise from the 6o'clock direction
//Take the x-axis downward and the y-axis right

//#define int ll
//#define int long long

//g++ -std=c++14 -Wall --pedantic-errors -o template template.cpp
//chcp 65001

signed main()
{
	int a, b; cin >> a >> b;
	cout << a-b+1;
	return 0;
}

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

const int N = 100 * 1000 + 5;
const long long inf = 1000ll * 1000 * 100 * N * N;

vector <long long> vec;
long long cnt[N];
long long ans[N];

int main() {
	int n, q;
	cin >> n >> q;
	vec.push_back(n);
	for (int i = 1; i <= q; i++) {
		long long x;
		cin >> x;
		while (vec.size() && vec.back() >= x) {
			vec.pop_back();
		}
		vec.push_back(x);
	}
/*	if (n == 5 && vec.size() == 2 && vec[0] == 4 && vec[1] == 1) {
		int x = 0;
		n /= x;
	}*/
	vec.push_back(inf);
	cnt[vec.size() - 2]++;
	for (int i = vec.size() - 2; i > 0; i--) {
		long long x = vec[i];
	//	cout << "43 " << x << endl;
		while (x > vec[0]) {
			int y = lower_bound(vec.begin(), vec.end(), x) - vec.begin() - 1;
			cnt[y] += 1ll * (x / vec[y]) * cnt[i];
			x %= vec[y];
		}
		ans[x] += cnt[i];
	} 
	ans[vec[0]] += cnt[0];
//	for (int i = 1; i <= n; i++) {
//		cout << "48 " << ans[i] << endl;
//	}
	for (int i = n; i; i--) {
		ans[i] += ans[i + 1];
	}
	for (int i = 1; i <= n; i++) {
		cout << ans[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 4212
#[warn(unused_mut)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[warn(unused_mut)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[warn(unused_mut)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        a: [i32; n],
    }

    for i in a.iter() {
        if i % 2 > 0 {
            continue;
        }
        if i % 3 > 0 && i % 5 > 0 {
            println!("DENIED");
            return;
        }
    }
    println!("APPROVED");
}


Measured memory_bytes: 4352
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void main() {
    int k, x; scan(k, x);

    int lo = max(-1000000, x - k + 1);
    int hi = min(1000000, x + k - 1);
    writeln(iota(lo, hi + 1).map!text.join(' '));
}


Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;

int main() {
    ll N, K, L; scanf("%lld%lld%lld", &N, &K, &L);

    vector<ll> A(N), V;
    for(int i=0; i<N; i++) {
        scanf("%lld", &A[i]);
        V.emplace_back(A[i]);
    }
    sort(V.begin(), V.end());
    V.erase(unique(V.begin(), V.end()), V.end());

    int M = V.size(), ub1 = M-1, lb1 = -1;
    while(ub1 - lb1 > 1) {
        int m1 = (ub1 + lb1) / 2, v1 = V[m1];
        vector<int> B(N);
        for(int i=0; i<N; i++) {
            B[i] = (A[i] <= v1);
        }

        ll ub2 = 0, cnt = 0, sum = 0;
        for(int lb2=0; lb2<N; lb2++) {
            while(ub2 < N and cnt < K) cnt += B[ub2++];
            ll c = max(0LL, (N - lb2) - (ub2 - lb2) + 1);
            if(cnt == K) sum += c;
            if(lb2 == ub2) ub2++;
            cnt -= B[lb2];
        }

        if(sum >= L) ub1 = m1;
        else lb1 = m1;
    }
    cout << V[ub1] << endl;
    return 0;
}



Measured memory_bytes: 6700
#include<bits/stdc++.h>
    using namespace std;
    int main()
    {
        ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
        long long h;
        cin>>h;
        int x=log2(2*h);
        cout<<fixed<<setprecision(0)<<pow(2,x)-1;
        return 0;
    }

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import functools

N,A,B = map(int, input().split())

sum = 0
for i in range(0,N+1):
    sum_i = int(functools.reduce(lambda sum,s: int(sum) + int(s),str(i) ))
    if sum_i >= A and sum_i <= B:
        sum += i

print(sum)

Measured memory_bytes: 3812
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int A = sc.nextInt();
		int B = sc.nextInt();
		int H = sc.nextInt();
		int M = sc.nextInt();

		int pass_time = H*60 + M;
      	//1min =0.5°
		double digA = (0.5 * (double)pass_time) % 360;
      	//1min =6°
		double digB = (6 * pass_time) % 360;

		double C = Math.sqrt(A*A + B*B -2*A*B*Math.cos(Math.toRadians(Math.abs(digA-digB))));

		System.out.println(C);

	}
}

Measured memory_bytes: 35896
#include<bits/stdc++.h>
#define int           long long
#define pb            push_back
#define ppb           pop_back
#define si            set <int>
#define endl          '\n'
#define fr            first
#define sc            second
#define mii           map<int ,int >
#define msi           map<string,int >
#define mis           map<int , string>
#define mci       	  map<char,int>  	
#define rep(i,a,b)    for(int  i=a;i<b;i++)
#define all(v)        v.begin(),v.end()
#define srt(v)        sort(all(v))
#define pii           pair<int ,int >
#define vi            vector<int >
#define vii           vector<pair<int , int >>
#define vs            vector<string>
#define sz(x)         (int )x.size()
#define M             1000000007
#define bs            binary_search
#define mp            make_pair
#define sp(n)         setprecision(n)
#define spl           " "
#define arr(a,n)      rep(i,0,n) cin>>a[i]
#define mod           998244353
#define MAXN   		  1000000
#define f(n) for(int i=0;i<n;i++)
using namespace std;

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//#ifndef ONLINE_JUDGE
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	//#endif
	int n,m=0;
	cin>>n;
	string a;
	msi mp;
	rep(i,0,n)
	{
		cin>>a;
		sort(a.begin(),a.end());
		mp[a]++;
	}
	for(auto it=mp.begin();it!=mp.end();it++)
	{
		m+=((it->sc)*(it->sc-1))/2;
	}
	cout<<m;
	return 0;
}


Measured memory_bytes: 11264
#include <stdlib.h>
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  uint32_t N, M, *L, *R;
  cin >> N >> M;

  L = new uint32_t[M];
  R = new uint32_t[M];

  for (uint32_t i = 0; i < M; ++i) {
    cin >> L[i] >> R[i];
  }

  uint16_t *Cards;
  uint32_t l = L[0] - 1, r = R[0] - 1;
  Cards = new uint16_t[N];

  for (uint32_t i = 0; i < N; ++i) {
    if (i < l) {
      Cards[i] = 0;
    } else if (i > r) {
      Cards[i] = 0;
    } else {
      Cards[i] = 1;
    }
  }

  for (uint32_t i = 1; i < M; ++i) {
    while (l < L[i] - 1) {
      Cards[l] = 0;
      ++l;
    }
    while (r > R[i] - 1) {
      Cards[r] = 0;
      --r;
    }
  }
  uint32_t res = 0;
  for (uint32_t i = 0; i < N; ++i) {
    res += Cards[i];
  }

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


Measured memory_bytes: 1280
#include <iostream>
#include <stdio.h>
using namespace std;
main(){
  long a,b,c;
  scanf("%ld %ld %ld",&a,&b,&c);
  long d=c-b-a;
  if(d>0&&4*a*b<d*d)printf("Yes");
  else printf("No");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repb(i, n) for(ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define reprb(i, a, b) for(ll i = (b)-1; i >= (a); i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
const ld EPS = 1e-12L;
const ld PI = 3.1415926535897932385L;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
template<class S, class T>inline bool chmax(S &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class S, class T>inline bool chmin(S &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif
void Pr(bool f){
    cout << (f ? "Yes" : "No") << endl;
    exit(0);
}
const int M = 12001;
bool dpx[M][M];
bool dpy[M][M];

using vci = vector<pair<char, int>>;

vci RLE(const string& s) {
    vci ret;
    int ns = s.size();
    int cnt = 0;
    for(int i = 0; i < ns; i++){
        cnt++;
        if((i < ns-1 && s[i] != s[i+1]) || i == ns-1) {
            ret.emplace_back(s[i], cnt);
            cnt = 0;
        }
    }
    return ret;
}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    string s;
    cin >> s;
    ll x, y;
    cin >> x >> y;
    auto rle = RLE(s);
    ll xini = 0;
    ll yini = 0;
    ll xgoal = x;
    ll ygoal = y;
    vll xin;
    vll yin;
    {
        ll i = 0;
        for(auto&& e: rle){
            if(e.first == 'F'){
                if(i == 0){
                    xini += e.second;
                }else if(i%2 == 0){
                    xin.emplace_back(e.second*2);
                }else{
                    yin.emplace_back(e.second*2);
                }
            }else{
                i += e.second;
            }
        }
    }
    xgoal -= xini;
    xgoal += accumulate(ALL(xin), 0ll)/2;
    ygoal += accumulate(ALL(yin), 0ll)/2;
    ll nx = SZ(xin);
    ll ny = SZ(yin);
    dump(xgoal, ygoal, xin, yin);
    if(xgoal < 0 || ygoal < 0) Pr(0);
    dpx[0][0] = true;
    dpy[0][0] = true;
    rep(i, nx){
        rep(j, xgoal+1){
            dpx[i+1][j] |= dpx[i][j];
            if(j >= xin[i]) dpx[i+1][j] |= dpx[i][j-xin[i]];
        }
    }
    rep(i, ny){
        rep(j, ygoal+1){
            dpy[i+1][j] |= dpy[i][j];
            if(j >= yin[i]) dpy[i+1][j] |= dpy[i][j-yin[i]];
        }
    }
    Pr(dpx[nx][xgoal] && dpy[ny][ygoal]);
    return 0;
}

Measured memory_bytes: 50304
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] price = new int[N];
        
        for(int i = 0;i < N;i++) {
        	price[i] = sc.nextInt();
        }
        
        int benefit = 0;
        
        for(int i = 0;i < N;i++) {
        	int a = sc.nextInt();
        	if(price[i] > a) {
        		benefit += price[i] -a;
        	}
        }
        System.out.println(benefit);
    }
}

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

//#pragma GCC optimize ("O3")
//#pragma GCC optimize ("Ofast")

#define F first
#define S second
#define MT make_tuple
#define SZ(a) ((int)(a).size())
#define PB push_back
#define LBS 20
#define MOD ((long long)1e9+7) //1e9+9
#define LEFT(i) (2*(i))
#define RIGHT(i) (2*(i)+1)
#define PAR(i) ((i)/2)
#define ALL(a) (a).begin(), (a).end()

using namespace std;

typedef long long ll;
typedef double rat;
typedef long long bi;
typedef pair<int, int> ii;
typedef tuple<int,int,int> iii;
typedef pair<ii,ii> fi;
typedef std::vector<ii> vii;
typedef std::map<int, int> mii;
typedef bitset<LBS> bis;
typedef std::vector<bis> vbs;

template<class T>
void in(T &a){
  for(auto &x: a)
    cin >> x;
}

template<class T>
void out(T &a, string sep=" "){
  for(auto x: a)
    cout << x<<sep;
  cout << '\n';
}

template<class T>
void err(T &a, string sep=" "){
  for(auto x: a)
    cerr << x <<sep;
  cerr << '\n';
}

int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m, l; cin >> n >> m >> l;
  std::vector<std::vector<ii> > e(n);
  for(int i=0; i<m; i++){
    int a, b, c; cin >> a >> b >> c;
    if(c>l)
      continue;
    a--; b--;
    e[a].PB({b,c});
    e[b].PB({a,c});
  }
  int q; cin >> q;
  std::vector<fi> que(q);
  for(int j=0; j<q; j++){
    int s,t; cin >> s >> t;
    s--; t--;
    que[j]={{s,t},{j,-1}};
  }
  sort(ALL(que));
  std::vector<int> ma(n,-1);
  int s;
  for(int j=0; j<q; j++){
    if(j==0 || que[j].F.F!=que[j-1].F.F){
      ma=std::vector<int>(n,-1);
      priority_queue<iii, std::vector<iii>, greater<iii> > pq;
      pq.emplace(0,0,que[j].F.F);
      while(!pq.empty()){
        int r,a; tie(r,s,a)=pq.top(); pq.pop();
        if(ma[a]!=-1)
          continue;
        ma[a]=r;
        for(auto x: e[a])
          if(ma[x.F]==-1)
            pq.emplace(r+((s+x.S)<=l?0:1),((s+x.S)<=l?s+x.S:x.S), x.F);
      }
    }
    que[j].S.S=ma[que[j].F.S];
  }
  sort(ALL(que),[](const fi &a, const fi &b){
    return a.S.F<b.S.F;
  });
  for(int i=0; i<q; i++)
    cout << que[i].S.S<<"\n";
}


Measured memory_bytes: 4256
#include <iostream>
#include <algorithm>
#include <vector> 
using namespace std;
int n;
long long l;
int main() {
	cin >> n >> l;
	vector<long long>v(n);
	for (int i = 0; i < n; i++) cin >> v[i];
	long long cnt = 0;
	long long res = 0;
	for (int i = 0; i < n; i++) {
		if (i == n - 1) {
			cnt += l - v[i];
			res = max(res, cnt);
			cnt = 0;
			continue;
		}
		if (v[i] > v[i + 1]) {
			cnt += l - v[i];
			res = max(res, cnt);
			cnt = 0;
		}
		else cnt += l - v[i];
	}
	reverse(v.begin(), v.end());
	for (int i = 0; i < n; i++) {
		if (i == n - 1) {
			cnt += l - v[i];
			res = max(res, cnt);
			cnt = 0;
			continue;
		}
		if (v[i] > v[i + 1]) {
			cnt += l - v[i];
			res = max(res, cnt);
			cnt = 0;
		}
		else cnt += l - v[i];
	}
	cout << res << endl;
}



Measured memory_bytes: 3564
import collections
n=int(input())
s=[input() for _ in range(n)]
c=collections.Counter(s)
l=c.most_common()
k=l[0][1]
l1=[]
for i in range(len(l)):
    if l[i][1]==k:l1.append(l[i][0])
    else:break
l1.sort()
for i in range(len(l1)):
    print(l1[i])

Measured memory_bytes: 47636
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int X = sc.nextInt();
        int[] a = new int[N];
        for(int i=0;i<N;i++) a[i]=sc.nextInt();
        int[] dist = new int[N];
        for(int i=0;i<N;i++) dist[i]=Math.abs(X-a[i]);
        Arrays.sort(dist);
        int ans = dist[0];
        for(int i=1;i<N;i++){
            ans = gcd(ans,dist[i]);
        }
        System.out.println(ans);
    }
    static int gcd(int a, int b){ // a<b
        int t=0;
        while(b!=0){
            t=a;
            a=b;
            b=t%b;
        }
        return a;
    }
}



Measured memory_bytes: 49568
#include <bits/stdc++.h>
 
#define forn(i, n) for (llong i = 0ll; i < (llong) n; ++i)
#define fornn(i, l, r) for (llong i = (llong) l; i < (llong) r; ++i)
#define size(x) ((int) (x.size()))
 
using namespace std;
 
typedef long long llong;
const llong inf = (llong) 1e+9 + 7ll;
const llong linf = (llong) 1e+18 + 7ll;
const long double eps = (long double) 1e-9;
const long double pi = acosl((long double) -1.0);
const int alph = 26;

mt19937 mrand(random_device{} ()); 

template<typename T, typename U> inline llong umin(const T& a, const U& b) { return a < b ? a : b; }
template<typename T, typename U> inline llong umax(const T& a, const U& b) { return a > b ? a : b; }
 
static char buff[(int) 2e6 + 17]; // reads std::string
const int maxn = (int) 3e6 + 17;

struct pt
{
	int x, y;
	pt() { }
};

struct fenwick
{
	int n;
	unordered_map<int, int> F;

	fenwick()
	{
		n = inf;
		F.rehash(1000000);
		F.max_load_factor(0.1);
	}

	void upd(int i, int x)
	{
		for (; i < n; i |= i + 1)
			F[i] = max(F[i], x);
	}

	int get(int i)
	{
		int res = 0;

		for (; i >= 0; i &= i + 1, --i)
			res = max(res, F[i]);

		return res;
	}
};

int n;
pt s, f;
pt p[maxn];

bool read()
{
	if (scanf("%d %d %d %d %d", &s.x, &s.y, &f.x, &f.y, &n) != 5)
		return false;

	forn (i, n)
		scanf("%d %d", &p[i].x, &p[i].y);

	return true;
}

bool cmp(pt a, pt b) { return make_pair(a.x, a.y) < make_pair(b.x, b.y); }

void solve()
{
	if (s.x > f.x)
		swap(s, f);

	if (s.y > f.y)
	{
		f.y = 2 * s.y - f.y;

		forn (i, n)
			p[i].y = 2 * s.y - p[i].y;
	}

	vector<pt> pp;

	forn (i, n)
		if (s.x <= p[i].x && p[i].x <= f.x && s.y <= p[i].y && p[i].y <= f.y)
			pp.push_back(p[i]);

	sort(pp.begin(), pp.end(), cmp);
	fenwick dp;

	forn (i, size(pp))
		dp.upd(pp[i].y, dp.get(pp[i].y) + 1);

	int lis = dp.get(inf);
	long double ans = 0;

	if (lis != min(f.y - s.y, f.x - s.x) + 1)
		ans = 100.0 * (f.y - s.y + f.x - s.x) - 20.0 * lis + 5 * M_PI * lis;
	else
		ans = 100.0 * (f.y - s.y + f.x - s.x) - 20.0 * lis + 5 * M_PI * (lis - 1) + 10 * M_PI;

	printf("%.15f\n", (double) ans);
}

int main()
{
#if SEREZHKA
	freopen("file.in", "r", stdin);
#endif

	while (read())
		solve();

	return 0;
}


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

int main(){
	int a[5][5];
	for(int i=1;i<=3;i++){
		for(int j=1;j<=3;j++){
			cin>>a[i][j];
		}
	}
	int n;
	cin>>n;
	int b[n+5];
	for(int i=1;i<=n;i++){
		cin>>b[i];
	}
	
	for(int i=1;i<=3;i++){
		for(int j=1;j<=3;j++){
			for(int k=1;k<=n;k++){
				if(a[i][j]==b[k]) a[i][j]=1;
			}
		}
	}
	
	int ans;
	if(a[1][1]==a[1][2]&&a[1][2]==a[1][3]&&a[1][3]==1) ans=1;
	else if(a[2][1]==a[2][2]&&a[2][2]==a[2][3]&&a[2][3]==1) ans=1;
	else if(a[3][1]==a[3][2]&&a[3][2]==a[3][3]&&a[3][3]==1) ans=1;
	else if(a[1][1]==a[2][1]&&a[2][1]==a[3][1]&&a[3][1]==1) ans=1;
	else if(a[1][2]==a[2][2]&&a[2][2]==a[3][2]&&a[3][2]==1) ans=1;
	else if(a[1][3]==a[2][3]&&a[2][3]==a[3][3]&&a[3][3]==1) ans=1;
	else if(a[1][1]==a[2][2]&&a[2][2]==a[3][3]&&a[3][3]==1) ans=1;
	else if(a[1][3]==a[2][2]&&a[2][2]==a[3][1]&&a[3][1]==1) ans=1;
	else ans=0;
	
	if(ans==1) cout<<"Yes";
	else cout<<"No";
	return 0;
} 

Measured memory_bytes: 256
A = [list(map(int, input().split())) for i in range(3)]
X = [[0] * 3 for i in range(3)]
N = int(input())
for i in range(N):
    b = int(input())
    for row in range(3):
        for col in range(3):
            if A[row][col] == b:
                X[row][col] = 1


for i in range(3):
    if X[i][0] + X[i][1] + X[i][2] == 3:
        print('Yes')
        exit()

for j in range(3):
    if X[0][j] + X[1][j] + X[2][j] == 3:
        print('Yes')
        exit()

if X[0][0] + X[1][1] + X[2][2] == 3:
    print('Yes')
    exit()

if X[0][2] + X[1][1] + X[2][0] == 3:
    print('Yes')
    exit()

print('No')


Measured memory_bytes: 3064
#include<cstdio>
long long n,m,ans;
void dfs(long long const &x,long long const &y){
	if(x%y==0){
		ans+=x*2-y;
		return;
	}
	else{
		ans+=(x-x%y)*2;
		dfs(y,x%y);
	}
}
int main(){
	scanf("%lld%lld",&n,&m);
	ans=n;
	n-=m;
	dfs(n>m?n:m,n<m?n:m);
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 3204
<?php
$n = explode(" ",trim(fgets(STDIN)));
sort($n);
$r=0;
$ans=0;
$d=$n[2]-$n[0];
if($d%2==0){
$ans+=$d/2;
}else{
$ans+=floor($d/2);
++$r;
}
$d=$n[2]-$n[1];
if($d%2==0){
$ans+=$d/2;
}else{
$ans+=floor($d/2);
++$r;
}
if($r==2){
++$ans;
}elseif($r==1){
$ans+=2;
}
echo $ans;

Measured memory_bytes: 4728
#define _CRT_SECURE_NO_WARNINGS
#define M_PI 3.14159265358979
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include<iomanip>
#include<vector>
#include<cmath>
#include <algorithm>

using namespace std;

int main(){

	for (int i = 1; i < 10; i++){
		for (int j = 1; j < 10; j++)
		{
			cout << i << "x" << j << "=" << i*j << endl;
		}
	}

}

Measured memory_bytes: 1120
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		int N = sc.nextInt();
		int[] A = new int[N];
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
		}
		sc.close();

		// 最長を除くように動く
		int MAX = 0;
		for (int i = 1; i < N; i++) {
			int d = A[i] - A[i - 1];
			MAX = Math.max(MAX, d);
		}
		// 一周回った差分
		int diff = K - A[N - 1] + A[0];
		if (diff > MAX) {
			MAX = diff;
		}

		System.out.println(K - MAX);
	}
}


Measured memory_bytes: 79120
# -*- coding: utf-8 -*-
import numpy as np

h,w = map(int, input().split())

if h == 1 or w == 1:
    ans = 1
elif h * w % 2 == 0:
    ans = h * w / 2
else:
    ans = h * w // 2 + 1

print(int(ans))

Measured memory_bytes: 21496
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
using vi = vector<int>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

int main(){
    int n;
    cin >> n;
    vi a1(n);
    vi a2(n);
    rep(i,n){
        int a;
        cin >> a;
        if(i==0) a1[0] = a;
        else{
            a1[i] = a1[i-1] + a;
        }
    }
    rep(i,n){
        int a;
        cin >> a;
        if(i==0) a2[0] = a;
        else{
            a2[i] = a2[i-1] + a;
        }
    }
    int ans = -INF;
    rep(i,n){
        if(i==0){
            ans = max(ans,a2[n-1] - 0 + a1[0]);
        }else if(i==n-1){
            ans = max(ans,a1[n-1] + a2[n-1] - a2[n-2]);
        }
        else{
            ans = max(ans,a2[n-1] - a2[i-1] + a1[i]);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout <<(#x)<<" is "<<(x)<<endl
#define debug cout <<"hi"<<endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD=1e9+7;
const int INF32=1<<30;
const ll INF64=1LL<<60;

int main(){
  int d,t,s; cin >>d >>t >>s;
  cout <<(t*s>=d?"Yes":"No");
return 0;}

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

int main() {
 int N;
 string S;
 cin >>N >>S; 
 int count =1;
 for(int i=0;i<N-1;i++){
 if(S[i]!=S[i+1]){count++;}
 }
  cout <<count <<endl;
}


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

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

    vector<int> a(n), b(n-1);
    for(int i=0; i<n-1; i++){
        cin >> b[i];
    }


    a[0] = b[0];
    a[n-1] = b[n-2];
    for(int i=0; i<n-2; i++){
        a[i+1] = min(b[i], b[i+1]);
    }

    int sum = 0;
    for(int i=0; i<n; i++){
        sum += a[i];
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

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

		Scanner sc1 = new Scanner(System.in);

		int n = sc1.nextInt();
		String[] str = new String[n];

		for ( int i = 0 ; i < n ; i++ ) {
			str[i] = sc1.next();
		}

		String bef_word = str[0];
		String aft_word;

		char last = bef_word.charAt(bef_word.length() - 1);
		char first;

		boolean flg = true;

		for ( int i = 1 ; i < n ; i++ ) {
			aft_word = str[i];
			first = aft_word.charAt(0);
			if ( first != last) {
				flg = false;
				//System.out.println(i + " " + aft_word + " " + last + " " + first + " " + "尻取れず");
				break;
			}

			String[] temp_str = new String[i];
			System.arraycopy(str,0,temp_str,0,i);

			if (Arrays.asList(temp_str).contains(aft_word)) {
				flg = false;
				//System.out.println(i + " " + aft_word  + " " + "重複");
				break;
			}

			last = aft_word.charAt(aft_word.length() - 1);;
		}

		if (flg) {
			System.out.println("Yes");
		}
		else {
			System.out.println("No");
		}

		sc1.close();

	}

}


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

int main(){
  int n,cnt_p=-1,cnt_q=-1,cnt=1;
  cin >> n;
  vector<int>p(n);
  vector<int>q(n);
  vector<int>a(n);
  rep(i,n) {cin >> p[i]; a[i] = i+1;}
  rep(i,n) cin >> q[i];

  do{
    bool flag_p = true, flag_q = true;
    rep(i,n){
      if(flag_p == false && flag_q == false) break;
      if(flag_p && p[i]!=a[i]) flag_p = false;
      if(flag_q && q[i]!=a[i]) flag_q = false;
    }
    if(flag_p) cnt_p = cnt;
    if(flag_q) cnt_q = cnt;
    if(cnt_p != -1 && cnt_q != -1) break;
    cnt++;
  }while(next_permutation(a.begin(),a.end()));
  
  cout << max(cnt_p,cnt_q) - min(cnt_p,cnt_q) << endl;
  return 0;
}

Measured memory_bytes: 384
N,K=map(int,input().split())
P=[int(x)-1 for x in input().split()]
C=[int(x) for x in input().split()]

def circle_grouping(P):
  P_in=[]
  P_group=[]
  for i in range(N):
    if i in P_in:
      pass
    else:
      start=i
      j=P[i]
      ls=[i]
      P_in.append(i)
      while j!=start:
        ls.append(j)
        P_in.append(j)
        j=P[j]
      P_group.append(ls)
  return P_group

def circle_maximum(A,K):
  max_val=max(A)
  for i in range(len(A)):
    val=0
    for k in range(K):
      pos=(i+k)%len(A)
      val+=A[pos]
      max_val=max(max_val,val)
  return max_val

score=max(C)
P_group=circle_grouping(P)
for A in P_group:
  k_rem=K%len(A)
  cycle=K//len(A)
  if cycle>=1:
    k_rem+=len(A)
    cycle-=1
  B=[C[i] for i in A]
  score=max(score,max(0,sum(B))*cycle+circle_maximum(B,k_rem))
print(score)

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

#define rep(i, n) for(LL i = 0; i < (n); i++)
#define repp(i, l, r) for(LL i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perr(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)

typedef long long LL;
typedef long double LD;

LL inv(LL x){
  LL ans=1;
  LL a=MOD-2;
  while(a){
    if(a&1) ans=ans*x%MOD;
    x=x*x%MOD;
    a>>=1;
  }
  return ans;
}

int main(){
  LL n,m,k;
  cin >> n >> m >> k;
  LL s=0,t=0;
  rep(i,n){
    s=(s+i*(i+1)/2+(n-i)*(n-i-1)/2)%MOD;
  }
  s=s*m*m%MOD;
  rep(i,m){
    t=(t+i*(i+1)/2+(m-i)*(m-i-1)/2)%MOD;
  }
  t=t*n*n%MOD;
  LL ans = (s+t)%MOD;
  vector<LL> fact(n*m+1);
  fact[0]=1,fact[1]=1;
  repp(i,1,n*m+1) fact[i]=fact[i-1]*i%MOD;
  ans=ans*fact[n*m-2]%MOD*inv(fact[k-2])%MOD*inv(fact[n*m-k])%MOD*inv(2)%MOD;
  cout << ans << endl;
  return 0;
}


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

typedef long long LL;

LL dp[101][100001] = {};

int main() {
	int N, W;
	cin >> N >> W;
	for(int i=1;i<=N;i++) {
		int w, v;
		cin >> w >> v;
		for(int j=0;j<w;j++) {
			dp[i][j] = dp[i-1][j];
		}
		for(int j=w;j<=W;j++) {
			dp[i][j] = max(dp[i-1][j], dp[i-1][j-w] + v);
		}
		// for(int j=0;j<=W;j++) {
		// 	printf("%lld ", dp[i][j]);
		// }
		// printf("\n");
	}
	printf("%lld", dp[N][W]);
}

Measured memory_bytes: 78336
x, y = [int(n) for n in input().split(' ')]
crane_cnt = 0
found = False
while crane_cnt <= x:
    turtle_cnt = x - crane_cnt
    if (crane_cnt * 2 + turtle_cnt * 4) == y:
        found = True
        break
    crane_cnt += 1
print('Yes' if found else 'No')


Measured memory_bytes: 9164
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
MOD = 10 ** 9 + 7

N, K = map(int, read().split())

k = np.arange(K, N + 2, dtype=np.int64)
low = (k - 1) * k // 2
high = N * k - low
cnt = high - low + 1
print(cnt.sum() % MOD)


Measured memory_bytes: 33688
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cassert>
#include <memory>
#include <stack>
#include <set>
#include <map>
#include <cctype>
#include <climits>
#include <list>

#define INF 1000000000
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

template<class T>
T factrial(T a) {
  if(a <= 1) {
    return 1;
  } else {
    return a * factrial(a-1);
  }
}

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

  ll N; cin>>N;
  vector<ll> A(N);
  for(auto& a: A) {
    cin>>a;
  }

  sort(A.begin(), A.end());
  bool flg = true;
  if(N % 2 == 0) {
    for(int i=0; i < N-1; i += 2) {
      int number = i + 1;
      if(A[i] != number || A[i+1] != number) {
        flg = false;
        break;
      }
    }
  } else {
    if(A[0] != 0) {
      flg = false;
    }
    for(int i=1; i < N-1; i += 2) {
      int number = i + 1;
      if(A[i] != number || A[i+1] != number || A[i] == 0 || A[i+1] == 0) {
        flg = false;
        break;
      }
    }
  }

  if(flg == false) {
    cout << 0 << endl;
  } else {
    // ll ans = pow(2, (N/2)%MOD);
    ll ans = 1;
    for(int i=0; i<N/2; i++) {
      ans *= 2;
      ans %= MOD;
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 1024
PROGRAM piyo
      IMPLICIT NONE
      character(1000) :: s
      integer :: len
      
      read*,s
      len = len_trim( s )
      
      
      if(s(len:len)=='s')then
        print*,s(1:len)//'es'
      else
        print*,s(1:len)//'s'
      end if
      
      
      
      stop
      !debugg
      
      
      
      END PROGRAM

Measured memory_bytes: 2864
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;
const int mod = 998244353;
const int MX = 310000;
ll inv[MX], f[MX], invf[MX];
void calc(){
	inv[0] = inv[1] = f[0] = f[1] = invf[0] = invf[1] = 1;
	for (int i = 2; i < MX; i++){
		inv[i] = mod - mod / i * inv[mod % i] % mod;
		f[i] = f[i - 1] * i % mod;
		invf[i] = invf[i - 1] * inv[i] % mod;
	}
}
inline ll C(ll n, ll k){
	return f[n] * invf[k] % mod * invf[n - k] % mod;
}
int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	calc();
	int n, a, b; ll k, ans = 0;
	cin >> n >> a >> b >> k;
	rep(i, n + 1){
		ll j = (k - (ll)i * a) / b;
		if((ll)i * a + j * b != k || j < 0 || j > n) continue;
		ans += C(n, i) * C(n, j) % mod;
	}
	cout << ans % mod << endl;
	return 0;
}

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

int main() {
  long long N;
  cin >> N;
  long long A[N];
  for (int i = 0; i < N; i++) cin >> A[i];
  
  long long res = 1000;
  
  for (long long i = 0; i < N - 1; i++){
    if (A[i + 1] > A[i]){
      res = (res / A[i]) * A[i + 1] + res % A[i];
    }
  }
  
  cout << res << endl;
}

Measured memory_bytes: 3592
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;
#define MOD 1000000007

vector<ll> dp(100010, -1);


ll modfact (ll n) {
    if (dp[n] != -1) return dp[n];
    if (n == 0) return dp[0] = 1;
    else return dp[n] = n * modfact(n - 1) % MOD;
}


int main() {
    cin.tie(0);
    cin.sync_with_stdio(0);

    ll n, m;
    scanf("%lld %lld", &n, &m);
    
    if (m < n - 1 || n + 1 < m) {
        printf("%d\n", 0);
        return 0;
    }

    ll ans;
    if (m == n) ans = modfact(n) * modfact(m) * 2 % MOD;
    else ans = modfact(n) * modfact(m) % MOD;

    printf("%lld\n", ans);
}

Measured memory_bytes: 5504
#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 () {
  int N;
  cin >> N;
  int ans = 0;
  rep(i,N) {
    int a;
    cin >> a;
    ans += a - 1;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import math

def dist(p1,p2):
    return math.sqrt((p1[0] - p2[0])**2 + (p1[1] - p2[1])**2)

N = int(input().strip())
p = []
for i in range(N):
    p.append(list(map(int, input().strip().split(" "))))

NALL = 1
for i in range(1,N+1):
    NALL *= i

NPATH = 1
for i in range(1,N):
    NPATH *= i
NPATH *= 2

dst = 0.0
for i in range(N-1):
    for j in range(i+1,N):
        dst += dist(p[i], p[j])
print(dst * NPATH / NALL)



Measured memory_bytes: 40016
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    string s;
    cin>>s;
    int ans=700+100*((s[0]=='o')+(s[1]=='o')+(s[2]=='o'));
    cout<<ans<<endl;
}

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

int main() {
  
  string s;
  cin >> s;
  
  int a,b;
  a = ( s[0] - '0' ) * 10 + s[1] - '0';
  b = ( s[2] - '0' ) * 10 + s[3] - '0';
  
  if ( ( a > 12 || a == 0 ) && b <= 12 && b > 0 ){
    cout << "YYMM" << endl;
  }else if ( a <= 12 && a > 0 && ( b > 12 || b == 0 ) ){
    cout << "MMYY" << endl;
  }else if ( a > 0 && a <=12 &&  b > 0 && b <=12 ){
    cout << "AMBIGUOUS" << endl;
  }else{
    cout << "NA" << endl;
  }
  
  return 0;
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
int calc(int d) {
  if (d == 0) {
    return 1;
  } else {
    bitset<30> b(d);
    return calc(d % b.count()) + 1;
  }
}
int main() {
  int n;
  string s;
  cin >> n >> s;
  bitset<2 * (int) pow(10, 5)> b(s);
  int a = b.count(), a1 = a - 1, a2 = a + 1;
  int b1 = 0, b2 = 0, c = 1;
  vector<int> v1(n), v2(n);
  v1[0] = 1, v2[0] = 1;
  if (b.test(0)) {
    b1 = 1, b2 = 1;
  }
  rep(i,n-1)
  {
    if (a > 1)
      v1[i + 1] = v1[i] * 2 % a1;
    v2[i + 1] = v2[i] * 2 % a2;
    if (b.test(i + 1)) {
      if (a > 1)
        b1 = (b1 + v1[i + 1]) % a1;
      b2 = (b2 + v2[i + 1]) % a2;
    }
  }
  for (int i = n - 1; i >= 0; i--)
    if (b.test(i))
      if (a > 1)
        cout << calc((b1 + a1 - v1[i]) % a1) << endl;
      else
        cout << 0 << endl;
    else
      cout << calc((b2 + a2 + v2[i]) % a2) << endl;
  return 0;
}


Measured memory_bytes: 5180
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<set>
#include<map>
//#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define mp make_pair
#define all(x) x.begin(),x.end()
using namespace std;
int p[123456], n, m, ans1, ans2; string s;
signed main() {
	cin >> n >> m;
	while (m--) {
		int t; cin >> t >> s;
		if (s == "AC" && p[t] >= 0) {
			ans1++; ans2 += p[t]; p[t] = -1;
		}
		else if (s == "WA" && p[t] >= 0)p[t]++;
	}
	cout << ans1 << ' ' << ans2 << endl;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

constexpr long mod = 1000000000 + 7;

std::vector<long> cache(2001, -1);

long solve(int s)
{
  if (s < 3) return 0;
  if (cache[s] >= 0) return cache[s];

  long result = 1;
  for (int i = 3; s - i > 0; ++i) {
    const auto x = solve(s - i);
    cache[s - i] = x;
    result += solve(s - i);
    result %= mod;
  }

  cache[s] = result;
  return result;
}

int main()
{
  int s;
  std::cin >> s;

  std::cout << std::setprecision(20);
  std::cout << solve(s) << std::endl;
}


Measured memory_bytes: 3636
#include<iostream>
using namespace std;
static int n,x[3000],y[3000],ans=0;
static bool a[5000][5000];

int z(int x){
	if(x<0)x=-x;
	return x;
}

bool f(int p,int q){
	bool c=false;
	if(0<=(x[p]-y[p]+y[q])&&0<=(y[p]-x[q]+x[p])&&0<=(x[q]+y[q]-y[p])&&0<=(y[q]-x[q]+x[p])&&(x[p]-y[p]+y[q])<5000&&(y[p]-x[q]+x[p])<5000&&(x[q]+y[q]-y[p])<5000&&(y[q]-x[q]+x[p])<5000){
		if(a[x[p]-y[p]+y[q]][y[p]-x[q]+x[p]]&&a[x[q]+y[q]-y[p]][y[q]-x[q]+x[p]])c=true;
	}
	if(0<=(x[p]+y[p]-y[q])&&0<=(y[p]+x[q]-x[p])&&0<=(x[q]-y[q]+y[p])&&0<=(y[q]+x[q]-x[p])&&(x[p]+y[p]-y[q])<5000&&(y[p]+x[q]-x[p])<5000&&(x[q]-y[q]+y[p])<5000&&(y[q]+x[q]-x[p])<5000){
		if(a[x[p]+y[p]-y[q]][y[p]+x[q]-x[p]]&&a[x[q]-y[q]+y[p]][y[q]+x[q]-x[p]])c=true;
	}
	return c;
}

int main(){
while(1){
	ans=0;
	scanf("%d",&n);
if(n==0)break;
	for(int i=0;i<5000;i++)for(int j=0;j<5000;j++)a[i][j]=false;
	for(int i=0;i<n;i++){
		scanf("%d%d",&x[i],&y[i]);
		a[x[i]][y[i]]=true;
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(i!=j){
				if(f(i,j)&&z(x[i]-x[j])*z(x[i]-x[j])+z(y[i]-y[j])*z(y[i]-y[j])>ans)ans=z(x[i]-x[j])*z(x[i]-x[j])+z(y[i]-y[j])*z(y[i]-y[j]);
			}
		}
	}
	printf("%d\n",ans);
}
}

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

int main() {
    int n, c, k;
    cin >> n >> c >> k;

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

    int bus = 1, limit = t[0] + k, ans = 1;
    for (int i = 1; i < n; i++) {
        bus++;
        if (bus > c || t[i] > limit) {
            ans++;
            bus = 1;
            limit = t[i] + k;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define cina(a, n) for (int i = 0; i < n; ++i){ cin >> a[i]; }
#define ll long long
#define ld long double

using namespace std;

int main () {
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int a, b;
	cin >> a >> b;
	for (int i = 1; i <= 1260; ++i) {
		if (floor(i * .08) == a && floor(i * .1) == b) {
			cout << i;
			return 0;
		}
	}
	cout << -1;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define REP(i,a,n) for(ll i=a;i<(n);i++)
#define RE return
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
	int x,n,a[110];
	bool f=true;
	cin>>x>>n;
	REP(i,0,n){
		cin>>a[i];
		if(a[i]==x)f=0;\
	}
	if(f){
		cout<<x;
		RE 0;
	}
	int sp=x,bp=x,sc=0,bc=0;
	while(!sc){
		sp--;
		REP(i,0,n){
			if(sp==a[i])goto ne;
		}
		sc=x-sp;
		ne:;
	}
	while(!bc){
		bp++;
		REP(i,0,n){
			if(bp==a[i])goto nex;
		}
		bc=bp-x;
		nex:;
	}
	if(sc<=bc)
	cout<<x-sc;
	else cout<<x+bc;
    return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
string s, t;
int c = 0;
int main() {
    cin >> s >> t;
    sort(s.begin(), s.end()); //xy
    sort(t.begin(), t.end(), greater<char>()); //yxa
    for(auto i = 0; i < s.size(); i++){
        if (t[i] > s[i]){
            cout << "Yes" << endl;
            return 0;
        }
        if (t[i] == s[i]){
            c++;
        }
    }
    if (c==s.size() && t.size() > s.size()){
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
}


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

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

    vector<int> H(N);
    for (int i = 0; i < N; i++)
    {
        cin >> H[i];
    }

    vector<int> right(N + 1, 0);

    right[N] = 0;
    for (int i = N - 1; i > 0; i--)
    {
        if (H[i - 1] >= H[i])
        {
            right[i] = right[i + 1] + 1;
        }

        else
        {
            right[i] = 0;
        }
    }

    int ans = right[0];
    for (int i = 0; i < N; i++)
    {
        if(ans < right[i])
        {
            ans = right[i];
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
	int n,m;
	cin>>n>>m;
	priority_queue<pair<ll,ll>> que;
	rep(i,n){
		int x;
		cin>>x;
		que.emplace(x,1);
	}
	rep(i,m){
		int y,x;
		cin>>y>>x;
		que.emplace(x,y); //直接構築
	}
	ll ans=0;
	ll cnt=n;
	while(cnt){
		auto p=que.top();que.pop();
		ans+=p.first*min(p.second,cnt);
		cnt-=min(cnt,p.second);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 6128
import java.util.*;
import java.lang.Math.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i = 0; i < n; i++) a[i] = sc.nextInt();
		int q = sc.nextInt();
		for(int i = 0; i < q; i++){
			int com = sc.nextInt();
			int b = sc.nextInt();
			int e = sc.nextInt();
			if(com == 0){
				int res = 1000000001;
				for(int j = b; j < e; j++) res = Math.min(res, a[j]);
				System.out.println(res);
			}else{
				int res = -1000000001;
				for(int j = b; j < e; j++) res = Math.max(res, a[j]);
				System.out.println(res);
			}
		}
	}
}



Measured memory_bytes: 34604
// https://atcoder.jp/contests/abc083/tasks/abc083_a
#include<iostream>
using namespace std;
int main()
{
    // 整数の入力
    unsigned long x, y;
    cin >> x >> y;

    int ct = 0;

    while (1)
    {
        if ((x > y) || (x > 10e18)) {
            break;
        }
        x *= 2;
        ct++;
    }
    
    cout << ct;

    return 0;
}


Measured memory_bytes: 3632
n = int(input())

max_prime = 555555

primes = [True for i in range(max_prime+1)]

for i in range(2, max_prime):
    if primes[i]:
        for j in range(i+i, max_prime+1, i):
            primes[j] = False

primes[0] = False
primes[1] = False

primes_num = [i for i, el in enumerate(primes) if el][2:]

ans = []

for p in primes_num:
    if str(p)[len(str(p))-1] == str(1) and p % 6 == 1:
        ans.append(p)

    if len(ans) == n:
        break


for p in ans:
    print(p, end=" ")

print()


Measured memory_bytes: 9552
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <limits>
#include <queue>
#include <iomanip>
#include <set>
//#include <bits/stdc++.h>
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
using namespace std;
#define ALL(X) X.begin(),X.end()
using ll = long long int;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
const int MOD=1000000007;
//const int MOD=998244353;
const int INTMAX=2147483647;
const ll LLMAX=9223372036854775807;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string S;
    cin>>S;
    
    if(S=="ABC")printf("ARC\n");
    else printf("ABC\n");
    
    return 0;
}


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	string c1,c2;
	cin>>c1>>c2;
	reverse(c2.begin(),c2.end());
	cout<<(c1==c2?"YES"s:"NO"s)<<"\n"s;
}

Measured memory_bytes: 256