akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>

int compara(const void * x, const void * y){
  int a = *((int *) x), b = *((int *) y);
  if(a < b)
    return -1;
  if(a > b)
    return 1;

  return 0;
}

int main(){
  int n, v[101];
  scanf("%d", &n);

  for(int i = 0; i < n; ++i)
    scanf("%d", &v[i]);

  qsort(v, n, sizeof(v[0]), compara);


  printf("%d\n", v[n-1] - v[0]);

  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define FIN         ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ii          pair<int,int>
#define F           first
#define S           second
#define pb          push_back
#define all(x)      (x).begin(),(x).end()
#define rall(x)     (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a)   for(int i = a; i >= 0; i--)
#define fori(i,m)   for(auto i = m.begin(); i != m.end(); i++) 
#define w(t)        while(t--)
#define sz(s)       int(s.size())
#define cls(a,car)  memset(a,car,sizeof (a))
#define db(x)       cerr << #x << " is " << x << '\n'
#define FL          freopen("input.txt", "r", stdin),freopen("output.txt", "w", stdout);
#define EjecuteTime cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"
#define angle(x)    double(x * acos(-1) / 180.0)
using namespace std;
typedef long long   ll;
typedef vector<int> vi;
typedef vector<ii>  vii;
const int N = 1 * 1e5 + 5;
const ll mod = 1e9 + 7;
const double E = 1e-9;
//int dx[] = {1, 0}, dy[] = {0, 1};
//int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
//int dx[] = {2, 1, -1, -2, -2, -1, 1, 2}, dy[] = {1, 2, 2, 1, -1, -2, -2, -1};
//int dx[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy[] = {0 ,1, 1, 1, 0, -1, -1, -1};
// fflush(stdout)
// cout << flush
// a + b = a ^ b + 2 * (a & b)
int n, W;
ll w[101];
int v[101];
ll dp[2][N];
ll f(int i, int want){
    if(want < 0)return 1e18;
    if(i == n)return want == 0 ? 0 : 1e18;
    ll &ans = dp[i][want];
    if(ans == -1){
        ans = 1e18;
        ans = min(f(i + 1, want), ans);
        ans = min(ans, f(i + 1, want - v[i]) + w[i]);

    }return ans;
}
int main(){
    //FL;
    FIN;
    cin >> n >> W;
    // optimizando memoria
    int sum = 0;
    for(int i = 0; i < n; i++){
        cin >> w[i] >> v[i];
        sum += v[i];
    }
    for(int i = n; i >= 0; i--){
        for(int want = 0; want <= sum; want++){// hast limite sumaMAx
            ll &ans = dp[i & 1][want];
            if(i == n){
                ans = want == 0 ? 0 : 1e18;
                continue;
            }
            ans = 1e18;
            ans = min(ans, dp[(i + 1) & 1][want]);
            if(want - v[i] >= 0)
                ans = min(ans, dp[(i + 1) & 1][want - v[i]] + w[i]);
        }
    }
    int ans = 0;
    for(int i = 0; i < sum + 1; i++){
        ll cur = dp[0 & 1][i];
        if(cur <= W)
            ans = i;
    }
    cout << ans << '\n';
    EjecuteTime;
    return 0;
}       

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

const int MOD = 998244353;

// ModInt begin

using ll = long long;
template<ll mod>
struct ModInt {
    ll v;
    ll mod_pow(ll x, ll n) const {
        return (!n) ? 1 : (mod_pow((x*x)%mod,n/2) * ((n&1)?x:1)) % mod;
    }
    ModInt(ll a = 0) : v((a %= mod) < 0 ? a + mod : a) {}
    ModInt operator+ ( const ModInt& b ) const {
        return (v + b.v >= mod ? ModInt(v + b.v - mod) : ModInt(v + b.v));
    }
    ModInt operator- () const {
        return ModInt(-v);
    }
    ModInt operator- ( const ModInt& b ) const {
        return (v - b.v < 0 ? ModInt(v - b.v + mod) : ModInt(v - b.v));
    }
    ModInt operator* ( const ModInt& b ) const {return (v * b.v) % mod;}
    ModInt operator/ ( const ModInt& b ) const {return (v * mod_pow(b.v, mod-2)) % mod;}
    
    bool operator== ( const ModInt &b ) const {return v == b.v;}
    bool operator!= ( const ModInt &b ) const {return !(*this == b); }
    ModInt& operator+= ( const ModInt &b ) {
        v += b.v;
        if(v >= mod) v -= mod;
        return *this;
    }
    ModInt& operator-= ( const ModInt &b ) {
        v -= b.v;
        if(v < 0) v += mod;
        return *this;
    }
    ModInt& operator*= ( const ModInt &b ) {
        (v *= b.v) %= mod;
        return *this;
    }
    ModInt& operator/= ( const ModInt &b ) {
        (v *= mod_pow(b.v, mod-2)) %= mod;
        return *this;
    }
    ModInt pow(ll x) { return ModInt(mod_pow(v, x)); }
    // operator int() const { return int(v); }
    // operator long long int() const { return v; }
};

template<ll mod>
ostream& operator<< (ostream& out, ModInt<mod> a) {return out << a.v;}
template<ll mod>
istream& operator>> (istream& in, ModInt<mod>& a) {
    in >> a.v;
    return in;
}

// ModInt end

using mint = ModInt<MOD>;

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

    vector<int> divs;
    for(int i=1; i*i<=N; i++) {
        if(N % i == 0) {
            divs.emplace_back(i);
            if(i != N / i) divs.emplace_back(N / i);
        }
    }
    
    sort(divs.begin(), divs.end());
    mint ans(0);
    map< int, mint > rec;
    for(auto d : divs) {
        if((N / d) % 2 == 0) continue;
        mint add = 0;
        for(int i=0; i<d; i++) {
            add *= mint(2);
            add += mint(X[i] - '0');
        }

        string Y = "";
        string a = X.substr(0, d), b = "";
        for(auto c : a) b += (c ^ '0' ^ '1');
        for(int i=0; ; i++) {
            if(Y.size() == X.size()) break;
            if(i % 2 == 0) Y += a;
            else Y += b;
        }
        if(Y <= X) add += mint(1);

        for(auto e : rec) {
            if(d % e.first) continue;
            add -= e.second;
        }
        ans += add * mint(2 * d);
        rec[d] = add;
    }
    cout << ans << endl;
}


Measured memory_bytes: 1144
//https://atcoder.jp/contests/dp/tasks/dp_c

#include <bits/stdc++.h>
#include <limits.h>
#include <algorithm>  


using namespace std;

typedef long long int ll;

const int precision = 16;
const int modulo =  1000000007; // 10^9 + 7
using ll = long long;
const double EPS = 1e-9;

int maxOfTree(ll a, ll b, ll c) {
	ll ret = max(a, b);
	return max(ret, c);
}

// int recVacV1(int ind, int excludeAct, const vector<vector<int>> & act) 
// {
// 	if(ind >= (int) act.size()) return 0;

// 	int ret = INT_MIN;
// 	int retEx = -1;
// 	for(auto i : {0, 1, 2}) {
// 		if(i == excludeAct) continue;
// 		if (act[ind][i] > ret) {
// 			retEx = i;
// 			ret = act[ind][i];
// 		}
// 	}

// 	ret += recVac(ind + 1, retEx, act);
// 	return ret;
// }


// ll recVacV2(int ind, int excludeAct, const vector<vector<int>> & act, map<pair<int, int>, ll> & memo) 
// {
// 	if(ind >= (int) act.size()) return 0;
// 	if(memo.count({ind, excludeAct})) return memo[{ind, excludeAct}];
// 	ll ret = INT_MIN;

// 	for(auto i : {0, 1, 2}) {
// 		if(i == excludeAct) continue;
// 		ret = max(recVacV2(ind + 1, i, act, memo), ret);
// 	}

// 	ret +=  act[ind][excludeAct];
// 	memo[{ind, excludeAct}] = ret;
// 	return ret;
// }


int max_exclude(const vector<int> & a, int exclude) 
{
	int ret = INT_MIN;
	for(auto i = 0; i < (int)a.size(); ++i) {
		if (i == exclude) continue;
		ret = max(ret, a[i]);

	}
	return ret;
}

// int vacV3(vector<vector<int>> & act) 
// {
// 	vector<vector<int>> dp(act.size(), vector<int>(3, INT_MIN));
// 	int n = act.size();
// 	for(auto i : {0, 1, 2}) {
// 		dp[0][i] = act[0][i];
// 	}
// 	for(auto i = 1; i < n; ++i) {
// 		for(int prev : {0, 1, 2}) {
// 			for(int cur: {0, 1, 2})
// 				if(prev != cur) {
// 					dp[i][cur] = max(dp[i][cur], dp[i - 1][prev] + act[i][cur]);
// 				}
			
// 		}
// 	}

// 	return max_exclude(dp[n - 1], 5);

// }

int vacV4(vector<vector<int>> & act) 
{
	vector<int> dp(3, 0), new_dp(3, 0);
	int n = act.size();

	for(auto i = 0; i < n; ++i) {
		for(int prev : {0, 1, 2}) {
			for(int cur: {0, 1, 2}){
				if(prev != cur) {
					new_dp[cur] = max(new_dp[cur], dp[prev] + act[i][cur]);
				}
			}
		}
		dp = new_dp;
	}
	return max_exclude(dp, 5);
}

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

	vector<vector<int>> act(n, vector<int>(3, 0));

	for(auto i = 0; i < n; ++i) {
		cin >> act[i][0] >> act[i][1] >> act[i][2];
	}

	

	// int maxVal = maxOfTree(recVacV1(0, 0, act, memo), 
	// 			recVacV1(0, 1, act, memo), recVacV1(0, 2, act, memo));

	//map<pair<int, int>, ll> memo;
	// ll maxVal = maxOfTree(recVacV2(0, 0, act, memo), 
	// 			recVacV2(0, 1, act, memo), recVacV2(0, 2, act, memo));

	// ll maxVal = vacV3(act);
	
	ll maxVal = vacV4(act);
	cout <<  maxVal <<endl;
}

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

	solveVacation();
	return 0;
}



Measured memory_bytes: 5760
#include <iostream>
#include <vector>
#include <string>
#include <cstdio>

using namespace std;

const char arrow[] = {'>', '<', 'v', '^'};
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};

int main(){
	int H, W;
	while(cin >> H >> W, H+W){
		vector<string> tile(H);
		bool visit[101][101] = {false};
		for(int i = 0; i < H; i++){
			cin >> tile[i];
		}
		int x = 0, y = 0;
		while(visit[y][x] != true){
			visit[y][x] = true;
			for(int i = 0; i < 4; i++){
				if(tile[y][x] == arrow[i]){
					x += dx[i];
					y += dy[i];
					break;
				}
			}
		}
		if(tile[y][x] == '.'){
			cout << x << ' ' << y << endl;
		}else{
			cout << "LOOP" << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1252
N = int(input())
points = list(map(int, input().split()))
even_points = [points[index] for index in range(len(points)) if index % 2 == 0]
odd_points = [points[index] for index in range(len(points)) if index % 2 == 1]

if N % 2 == 0:
  odd_points = list(reversed(odd_points))
  odd_points.extend(even_points)
  ans = odd_points
else:
  even_points = list(reversed(even_points))
  even_points.extend(odd_points)
  ans = even_points

ans = list(map(str, ans))
print(' '.join(ans))

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

typedef long long ll;
#define int ll
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

#define int ll

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define ALL(s) (s).begin(),(s).end()
#define ALLn(s,n) s,s+n
#define F first
#define S second
#define pb push_back
#define tc(t) int t; cin >> t; while(t--)
#define _ ios_base::sync_with_stdio(false); cin.tie(NULL);
#define D1(x) { cerr << " [" << #x << ": " << x << "]\n"; }
#define D2(x) { cerr << " [" << #x << ": "; for(auto it:x) cerr << it << " "; cerr << "]\n"; }

const ll MOD = 1e9 + 7;
const ll MAXN = 1e6 + 7;
const ll INF = LONG_LONG_MAX;


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

	int G = 0;
	F0R(i, n) {
		int x;
		cin >> x;
		G = __gcd(x, G);
	}
	cout << G;
}

int32_t main() {
	_

#ifndef ONLINE_JUDGE
	freopen("in", "r", stdin);
	freopen("out", "w", stdout);
#endif

	// tc(t)
	solve();
	cerr << "[ Time : " << (float)clock() / CLOCKS_PER_SEC << " secs ]" << endl;
}

// 1 4 3 2 5

// 1 - 1
// 2 - 4
// 3 - 3
// 4 - 2
// 5 - 5

Measured memory_bytes: 3720
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int r,g,b,n;
    int c=0;
    cin>>r>>g>>b>>n;
    int i,j;
    for(i=0;i<=n;i++)
    {
        for(j=0;j<=n;j++)
        {
            long long gg=i*r+j*g;
            gg=n-gg;
            if(gg>=0&&gg%b==0)
            {
                c++;
            }
        }
    }
    cout<<c<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
   int m,f,r;
   for(;;)
   {
   scanf("%d%d%d",&m,&f,&r);
   if(m==-1&&f==-1&&r==-1) break;
   
  
	 if(m==-1||f==-1){printf("F\n"); continue;} 
   if(m+f>=80) printf("A\n");
   if(m+f>=65&&m+f<80) printf("B\n");
   if(m+f>=50&&m+f<65||m+f>=30&&m+f<50&&r>=50) printf("C\n");
   else if(m+f>=30&&m+f<50) printf("D\n");
   if(m+f<30) printf("F\n");



   }
    return 0;
}



Measured memory_bytes: 2064
n, m = gets.split.map(&:to_i)
a = (1..n).map { gets.to_i }
(2..m).each do |k|
    (0..n-2).each do |i|
        a[i], a[i+1] = a[i+1], a[i] if a[i] % k > a[i+1] % k
    end
end
puts a


Measured memory_bytes: 6868
import numpy as np

def read_ints():
    return [int(x) for x in input().split()]

def solve(N, M, C, b, a):
    ab = np.dot(a, b) + C
    return np.sum(ab > 0)

N,M,C = map(int, input().split())
b = np.array(read_ints(), dtype=int)
a = np.array([read_ints() for i in range(N)], dtype=int)

print(solve(N,M,C,b,a))

Measured memory_bytes: 12496
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long int
#define lu unsigned long long int
#define pi pair<ll, ll>
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define mk make_pair
#define ve vector
#define lr(n) for (ll i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define be begin
#define sz(a) (ll)(a.size())
#define INF 1e18
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)

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

// ll mod = 1e9+7;

// ll mult(ll x, ll y){
//     ll rem=1;
//     while(y){
//         if(y&1){
//             rem=(rem*x)%mod;
//         }
//         x=(x*x)%mod;
//         y>>=1;
//     }
//     return rem;
// }

void solve(ll T){
	ll n;
	cin>>n;
	ll ans[n+1]={0};
	for(ll i=1;i<=100;i++){
		for(ll j=1;j<=100;j++){
			for(ll k=1;k<=100;k++){
				ll x=i*i+j*j+k*k+i*j+i*k+k*j;
				if(x>n) continue;
				ans[x]++;
			}
		}
	}
	for(ll i=1;i<=n;i++) cout << ans[i] << "\n";
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	// std::cout << std::unitbuf;
	ll T=1;
	// cin>>T;
	for(ll t=1;t<=T;t++){
		solve(t);
	}
	return 0;
}

Measured memory_bytes: 3600
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<bits/stdc++.h>
#define ll long long
using namespace std;

template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}

int n,m;
int a[100001];
vector<int> e[100001];
int vis[100001];
int f[100001][15];
struct node{
	int v,d,c;
}q[100001];
void func(int u,int d,int c)
{
	if(vis[u]>=d)return;
	vis[u]=d;
	if(!a[u])a[u]=c;
	if(d==0) return;
	for(int i=0;i<e[u].size();i++)
	{
		int v=e[u][i];
		func(v,d-1,c);
	}
}
int main()
{
	cin>>n>>m;
	int u,v;
	for(int i=1;i<=n;i++)
		e[i].clear();
	memset(a,0,sizeof(a));
	memset(vis,-1,sizeof(vis));
	for(int i=0;i<m;i++)
	{
		read(u); 
		read(v);
		e[u].push_back(v);
		e[v].push_back(u);
	}
	int s;
	cin>>s;
	for(int i=0;i<s;i++){
		read(q[i].v);
		read(q[i].d);
		read(q[i].c);
	}
	for(int i=s-1;i>=0;i--)
	{
		func(q[i].v,q[i].d,q[i].c);
	}
	for(int i=1;i<=n;i++)
		cout<<a[i]<<endl;
	
	return 0;

}


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

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

    int a, b;
    cin >> a >> b;
    
    for(int i = min(a, b); i <= 10500; i++){
        int x = i * 8 / 100;
        int y = i * 1 / 10;
        if(x == a and y == b){
            cout << i << endl;
            return 0;
        }
    }

    cout << -1 << endl;

    return 0;
}

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

int main(){
  int K, N,k,tmp,tmp2; cin >> K >> N;
  int ans = 10e6+1;
  vector<int> A(N);
  rep(i,N) cin >> A[i];
  rep(i,N){
    if(i == 0){
      tmp = A[N-1]-A[0];tmp2 = abs(K-A[1])+A[0];
    }

    else if(i == N-1){
      tmp = abs(A[N-1]-A[0]); tmp2 = abs(K-A[N-1])+A[N-2];
    }

    else{
      tmp = K-A[i] + A[i-1]; tmp2 = abs(K-A[i+1]) + A[i];
    }
    k = min(tmp,tmp2);
    ans = min(k,ans);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#from numpy import*
#from scipy import*
from collections import* #defaultdict Counter deque appendleft
from fractions import gcd
from functools import* #reduce
from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby
from operator import mul
from bisect import* #bisect_left bisect_right
from heapq import* #heapify heappop heappushpop
from math import factorial,pi
from copy import deepcopy
import sys
#input=sys.stdin.readline  #危険！基本オフにしろ！
sys.setrecursionlimit(10**6)


def main():
    while True:
        s=input()
        if "?" in s:
            break
        else:
            print(int(eval(s)))
    
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 6864
import java.util.Scanner;

public class Main {
    private static Scanner sc=new Scanner(System.in);
    public static void main(String[] args){
        int n=sc.nextInt();
        int[] a=new int[n];
        for(int i=0;i<n;i++) a[i]=sc.nextInt();
        int counter=0;
        for(int i=0;i<n;i++){
            int minj=i;
            for(int j=i;j<n;j++){
                if(a[j]<a[minj]) minj=j;
            }
            if(i!=minj) counter++;
            int t=a[i];
            a[i]=a[minj];
            a[minj]=t;
        }
        for(int i=0;i<=n-2;i++) System.out.printf("%d ",a[i]);
        System.out.println(a[n-1]);
        System.out.println(counter);
    }
}

Measured memory_bytes: 26536
def main():
    n, x, y = map(int,input().split())
    res_l = [0 for _ in range(n - 1)]
    for j in range(1, n + 1):
        for i in range(1, j):
            route_1 = j - i
            if i < y:
                route_2 = abs(i - x) + 1 + abs(j - y)
                route = min(route_1,route_2)
            else:
                route = route_1
            res_l[route - 1] += 1
    for res in res_l:
        print(res)



if __name__ == "__main__":
    main()


Measured memory_bytes: 3444
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    long long n,m=1;
    cin>>n;
    int k=0,l=n%10;
    for(long long i=n/10;i>0;i/=10){
        k++;
        l+=i%10;
        m*=10;
    }
    k=(n/m)-1+9*k;
    cout<<max(k,l)<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define llong long long
#define INF (__INT32_MAX__ / 2)
using namespace std;

//1以上n以下で、 rで割った余りがmである整数の個数
llong cntmod(int n, int r, int m) {
    llong res = n / r;
    if(m <= n % r && m != 0)
        ++res;
    return res;
}

int main() {
	int N, K;
	cin >> N >> K;
    
    llong res = 0;
	for(int i = 0; i < K; ++i) {
        if((2 * i) % K != 0)
            continue;

        //1以上N以下で, Kで割った余りがiである整数の個数？
        llong n = cntmod(N, K, i);
        
        res += n * n * n;
    }

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

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

using namespace std;

const int MAX_N = 2e5 + 200;

int n, k, pi[MAX_N], max_val[20][MAX_N], min_val[20][MAX_N], log2_[MAX_N];
bool st[20][MAX_N];

bool query(int l, int r)
{
	bool ret = true;
	for (int i = 19; i >= 0; i--)
		if (l + (1 << i) - 1 <= r)
		{
			ret &= st[i][l] && (l + (1 << i) - 1 == r || pi[l + (1 << i) - 1] <= pi[l + (1 << i)]);
			l += (1 << i);
		}
	return ret;
}

int queryMin(int l, int r)
{
	int d = log2_[r - l + 1];
	return min(min_val[d][l], min_val[d][r - (1 << d) + 1]);
}

int queryMax(int l, int r)
{
	int d = log2_[r - l + 1];
	return max(max_val[d][l], max_val[d][r - (1 << d) + 1]);
}

int main()
{
	scanf("%d%d", &n, &k);
	for (int i = 1; i <= n; i++)
		scanf("%d", &pi[i]), st[0][i] = true, max_val[0][i] = min_val[0][i] = pi[i];
	for (int i = 2; i <= n; i++)
		log2_[i] = log2_[i >> 1] + 1;
	for (int i = 1; i < 20; i++)
		for (int j = 1; j + (1 << i) - 1 <= n; j++)
		{
			st[i][j] = st[i - 1][j] && st[i - 1][j + (1 << (i - 1))] && (pi[j + (1 << (i - 1)) - 1] <= pi[j + (1 << (i - 1))]);
			min_val[i][j] = min(min_val[i - 1][j], min_val[i - 1][j + (1 << (i - 1))]);
			max_val[i][j] = max(max_val[i - 1][j], max_val[i - 1][j + (1 << (i - 1))]);
		}
	int pl = -1, pr = -1, ans = 0;
	bool flag = false;
	for (int i = 1; i + k - 1 <= n; i++)
		if (pl == -1)
			ans++, pl = i, pr = i + k - 1, flag |= query(pl, pr);
		else if (i <= pr)
		{
			bool verdict = query(pl, i - 1) && query(pr + 1, i + k - 1);
			verdict &= queryMax(pl, i - 1) <= queryMin(i, pr) && queryMax(i, pr) <= queryMin(pr + 1, i + k - 1);
			if (verdict)
				continue;
			else if (!(query(i, i + k - 1) && flag))
				ans++, pl = i, pr = i + k - 1, flag |= query(pl, pr);
		}
		else if (query(pl, pr) && query(i, i + k - 1))
			continue;
		else if (!(query(i, i + k - 1) && flag))
			ans++, pl = i, pr = i + k - 1, flag |= query(pl, pr);
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 34844
#include "bits/stdc++.h"


// vector
#define MAX_ELE(vec) *max_element(vec.begin(), vec.end())

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

// string
#define TO_UP(str) transform(str.cbegin(), str.cend(), str.begin(), ::toupper)

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



using namespace std;
int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
//  --------------------------------------

    int K, X;
    int min_ans, max_ans;

    cin >> K >> X;

    if(X - K + 1 < -1000000){
        min_ans = -1000000;
    }else{
        min_ans = X - K + 1;
    }

    if(X + K - 1 > 1000000){
        max_ans = 1000000;
    }else{
        max_ans = X + K - 1;
    }
    
    for (int i = min_ans; i < max_ans; i++)
    {
        cout << i << " ";
    }
    
    cout << max_ans << "\n";

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin >> s;
  
  if (s[0] == s[1] && s[1] == s[2]) cout << "Yes" << endl;
  else if (s[1] == s[2] && s[2] == s[3]) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
//তুমি চেয়ে আছো তাই, আমি পথে হেঁটে যাই
//হেঁটে হেঁটে বহুদুর বহুদুর যেতে চাই 
//I FAILED BADLY AND VERY PUBLICLY
//THAT'S WHAT I DESERVE 

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define pii pair <int, int>
#define pll pair <long long, long long >
#define PI 2 * acos(0.0) 
const long long M = 5e5 + 10, oo = 1e9 + 7;
int dp[3010][3010], way[3010][3010];
int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s, t;
    cin >> s >> t;
    memset(way, -1, sizeof way);
    for (int i = 0; i <= s.length(); i++) {
        for (int j = 0, k = 0; j <= t.length(); j++) {
            k = (s[i] == t[j]);
            if (dp[i + 1][j] < dp[i][j]) {
                dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
                way[i + 1][j] = 1;
            }
            if (dp[i][j + 1] < dp[i][j]) { 
                dp[i][j + 1] = max(dp[i][j + 1], dp[i][j]);
                way[i][j + 1] = 2;
            }
            if (dp[i + 1][j + 1] < dp[i][j] + k) {
                dp[i + 1][j + 1] = max(dp[i][j] + k, dp[i + 1][j + 1]);
                if (k) way[i + 1][j + 1] = 3;
                else way[i + 1][j + 1] = 4;
            }
        }
    }
    string res = "";
    int si = s.length(), ti = t.length();
    while (way[si][ti] != -1) {
        if (way[si][ti] == 3) {
            res += s[si - 1];
        }
        if (way[si][ti] == 3 || way[si][ti] == 4) {si--;ti--;}
        else if (way[si][ti] == 2) ti--;
        else if (way[si][ti] == 1) si--;
    }
    reverse(res.begin(), res.end());
    cout << res << endl;
    return 0;
}

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

int main()
{
	int n;
	cin>>n;
	int a[n+1], b[n+1], c[n+1];
	for(int i=1; i<=n; i++) cin>>a[i]>>b[i]>>c[i];

	int dpa[n+1], dpb[n+1], dpc[n+1];

	dpa[0] = 0;
	dpb[0] = 0;
	dpc[0] = 0;

	dpa[1] = max(b[1],c[1]);
	dpb[1] = max(c[1],a[1]);
	dpc[1] = max(a[1],b[1]);

	for(int i=2; i<=n; i++)
	{
		dpa[i] = a[i] + max(dpb[i-1],dpc[i-1]);
		dpb[i] = b[i] + max(dpc[i-1],dpa[i-1]);
		dpc[i] = c[i] + max(dpa[i-1],dpb[i-1]);

	}

	cout<<max(dpa[n],max(dpb[n],dpc[n]));
	return 0;
}

Measured memory_bytes: 2560
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define sort(a)         sort((a).begin(), (a).end())
#define uniq(a)         sort(a);(a).erase(unique((a).begin(), (a).end()), (a).end())
#define reverse(a)      reverse((a).begin(), (a).end())
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

ll mypow(ll x, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * x;
    x = x * x;
    n >>= 1;
  }
  return res;
}

void solve() {
  int n, p; cin >> n >> p;
  int a = 0, b = 0;
  rep(i, n) {
    int ai; cin >> ai;
    if (ai % 2 == 0) a++;
    else b++;
  }
  if (b == 0 && p == 1) outl(0);
  else if (b == 0 && p == 0) outl(mypow(2, a));
  else outl(mypow(2, a+b-1));
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


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

int main(){
	int H, W, h, w; cin >> H >> W >> h >> w;
	if(H % h + W % w == 0) cout << "No" << "\n";
	else{
		cout << "Yes" << "\n";
		int ans[H][W];
		if(H % h != 0){
			int a = H / h + 1;
			int b = -a * (h - 1) - 1;
			for(int i=0; i<H; i++){
				for(int j=0; j<W; j++){
					if(i % h == h - 1) cout << b << " ";
					else cout << a << " ";
				}
				cout << "\n";
			}
		}else{
			int a = W / w + 1;
			int b = -a * (w - 1) - 1;
			for(int i=0; i<H; i++){
				for(int j=0; j<W; j++){
					if(j % w == w - 1) cout << b << " ";
					else cout << a << " ";
				}
				cout << "\n";
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1408
#include <stdio.h>

#define MAX_NUM 1000000007

int main(void) {
	int N, M;
	long long int A[1000] = {};
	int i;
	int overcnt = 0;
	long long int sumcnt = 0;
	scanf("%d %d", &N, &M);
	for (i = 0; i < N; i++) {
		scanf("%d", &A[i]);
		sumcnt += A[i];
	}

	for (i = 0; i < N; i++) {
		if ((4 * M * A[i]) >= sumcnt ) {
			overcnt++;
		}
	}

	if (overcnt >= M) {
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 128
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"
)

var (
	reader io.Reader = os.Stdin
	writer io.Writer = os.Stdout
)

func main() {
	reader = os.Stdin
	writer = os.Stdout
	run()
}

func run() {
	nums := readIntsFromStdin()[0]
	a, b := nums[0], nums[1]

	var results []string

	results = append(results, strconv.Itoa(a/b))
	results = append(results, strconv.Itoa(a%b))
	results = append(results, strconv.FormatFloat(float64(a)/float64(b), 'f', 5, 64))

	fmt.Fprintln(writer, strings.Join(results, " "))
}

// readIntsFromStdin parses lines of inputs into 2D int array.
func readIntsFromStdin() [][]int {
	out := [][]int{}
	scanner := bufio.NewScanner(reader)

	for scanner.Scan() {
		var ints []int

		for _, s := range strings.Split(scanner.Text(), " ") {
			i, err := strconv.Atoi(s)

			if err != nil {
				fmt.Fprintln(os.Stderr, "Failed to parse string into int.", err)
				os.Exit(1)
			}

			ints = append(ints, i)
		}

		out = append(out, ints)
	}

	return out
}



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

class Main {
    static Scanner scanner = new Scanner();

    public static void main(String[]$) throws IOException {
        int m = scanner.nextInt();
        int d = scanner.nextInt();
        int count = 0;
        for (int i = 1; i <= m; i++) {
            for (int j = 2; j < i; j++) {
                if (i % j == 0) {
                    int k = i / j;
                    if (j < 10 && k < 10 && j * 10 + k <= d) {
                        count++;
                    }
                }
            }
        }
        System.out.println(count);
    }

    static class Scanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

        String next() throws IOException {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                tokenizer = new StringTokenizer(reader.readLine());
            }
            return tokenizer.nextToken();
        }

        int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        long nextLong() throws IOException {
            return Long.parseLong(next());
        }
    }
}

Measured memory_bytes: 23124
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <queue>

#define FOR(idx, begin, end) for(int idx = (int)(begin); idx < (int)(end); ++idx)

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

using namespace std;
typedef long long lint;

const int MOD = 1000000007;
const int INF = 1 << 29;
const double EPS = 1e-9;


int main() {

	cin.tie(0);

	int N, K;
	cin >> N >> K;

	vector<int> a(N);
	FOR(i, 0, N) cin >> a[i];

	sort(a.begin(), a.end(), greater<int>());
	int sum = INF, cnt = 0, ans = N;

	FOR(st, 0, N){

		sum = 0;
		cnt = 0;
		bool flag = true;

		while (st + cnt < N) {

			sum += a[st + cnt];
			cnt++;
			if (sum >= K) {
				flag = false;
				break;
			}
		}if (flag) break;

		while (sum >= K) {
			
			ans = min(ans, N - st - cnt);
			sum -= a[st + cnt - 1];
			if (st + cnt < N) {
				sum += a[st + cnt];
			}
			else break;
			cnt++;
		}
	}

	cout << ans;

	return 0;
}

Measured memory_bytes: 384
#!/usr/bin/env python3
from bisect import insort_left
from fractions import gcd
def lcm(m,n):
    return (m*n)//gcd(m,n)
n,X=map(int,input().split())
x=list(map(int,input().split()))
x.append(X)
x.sort()
g=x[1]-x[0]
for i in range(n):
    g=gcd(g,x[i+1]-x[i])
print(g)


Measured memory_bytes: 16236
N=int(input())
P=tuple(map(int,input().split()))
Q=tuple(map(int,input().split()))
from itertools import permutations
p,q=0,0
for i,R in enumerate(permutations(range(1,N+1))):
    if P==R:
        p=i
    if Q==R:
        q=i
print(abs(p-q))

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

using namespace std;

int main()
{
    int n,m,i,max1=0,m3=9999999,m1[100100],m2[100100];
    scanf("%d%d",&n,&m);
    for(i=1;i<=m;i++)
    {
        scanf("%d%d",&m1[i],&m2[i]);
        if(max1<m1[i])
        {
            max1=m1[i];
        }
        if(m3>m2[i])
        {
            m3=m2[i];
        }
    }
    if(m3-max1>=0)
    printf("%d\n",m3-max1+1);
    else
        printf("0\n");
    return 0;
}


Measured memory_bytes: 1024
from collections import Counter
n = int(input())
A = [int(i) for i in input().split()]
S = [0]*(n+1)
for i in range(n):
    S[i+1] = S[i] + A[i]
out = [i*(i-1)//2 for i in Counter(S).values() if i > 1]
print(sum(out))

Measured memory_bytes: 41496
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#include<bits/stdc++.h>
using namespace std;

#if defined(DAIJOBU)
#include "/home/ichigo/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}


int main(){
	FIO
	
	int a, b, c;cin >> a >> b >> c;
	int ans = 0;
	for(int i = a; i <= b; i++){
		if(c % i == 0)ans++;
	}
	cout << ans << "\n";
	return 0;
}



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

const double PI = acos(-1);

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define MOD 1000000007
#define INF 1000000000

void solve_abc_c() {
	ll n, m;
	ll k;
	ll h, w;
	//ll x;
	//ll a;
	string s;
	string s_ans;
	ll l_ans = 0;
	double d_ans = 0;

	cin >> n;
	V a(5);
	ll idx = 0;
	ll val = 1e16;
	rep(i, 5) {
		cin >> a[i];
		val = min(val, a[i]);
	}

	l_ans += (n + val - 1) / val;
	l_ans += 4;

	cout << l_ans << "\n";
}

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

	solve_abc_c();

	return 0;
}


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

int main(){
	double d;
	while( cin >> d, d>=0.0 ){
		int n = (int)(d*16.0);
		if( (double)n != d*16.0 || (int)d > 256 ){
			cout << "NA" << endl;
			continue;
		}
		for( int i=11; i>=4; i-- ){
			cout << (n&(1<<i) ? '1':'0');
		}
		cout << '.';
		for( int i=3; i>=0; i-- ){
			cout << (n&(1<<i) ? '1':'0');
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1216
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define N 4
#define N2 16
#define LIMIT 100

static const int dx[4]={0,-1,0,1},dy[4]={1,0,-1,0};
static const int dir[4]={1,2,3,4};
int MDT[N2][N2];

typedef struct{
	int f[N2],space,MD;
}Puzzle;

Puzzle state;
int limit;
int path[LIMIT];

int getAllMD(Puzzle pz){
	int sum = 0,i;
	for(i=0;i<N2;i++){
		if(pz.f[i]==N2)continue;
		sum+=MDT[i][pz.f[i]-1];
	}
	return sum;
}

int isSolved(){
	int i;
	for(i=0;i<N2;i++){
		if(state.f[i]!=i+1)return 0;
	}
	return 1;
}

int dfs(int depth,int prev){
	int r,sx,sy,tx,ty,max,min;
	if(state.MD ==0)return 1;
	if(depth+state.MD>limit)return 0;
	sx=state.space/N;
	sy=state.space%N;
	Puzzle tmp;
	for(r=0;r<4;r++){
		tx=sx+dx[r];
		ty=sy+dy[r];
		if(tx<0 || ty<0 || tx>=N || ty>=N)continue;
		if(prev>r)max=prev;
		else max=r;
		if(prev<r)min=prev;
		else min=r;
		if(max-min==2)continue;
		tmp=state;
		state.MD-=MDT[tx*N+ty][state.f[tx*N+ty]-1];
		state.MD+=MDT[sx*N+sy][state.f[tx*N+ty]-1];
		int a;
		a=state.f[tx*N+ty];
		state.f[tx*N+ty]=state.f[sx*N+sy];
		state.f[sx*N+sy]=a;
		state.space=tx*N+ty;
		if(dfs(depth+1,r)){
			path[depth]=r;
			return 1;
		}
		state=tmp;
	}
	return 0;
}

int iterative_deepening(Puzzle in,int *ans){
	int i,n=0;
	//fprintf(stderr,"1111111111111\n");
	in.MD=getAllMD(in);
//	fprintf(stderr,"2222222222222\n");
	for(limit=in.MD;limit<=LIMIT;limit++){
		state=in;
		if(dfs(0,-100)){
	//		fprintf(stderr,"3333333333333\n");
			for(i=0;i<limit;i++){
				ans[n]=dir[path[i]];
				n++;
			}
			return n;
		}
	}
	ans[0]=-1;
	return n;
}

int main(){
	int ans[LIMIT];
	int i,j,n;
	for(i=0;i<N2;i++){
		for(j=0;j<N2;j++){
			MDT[i][j]=abs(i/N-j/N)+abs(i%N-j%N);
		}
	}
//	fprintf(stderr,"44444444444444\n");
	Puzzle in;
	for(i=0;i<N2;i++){
		scanf("%d",&in.f[i]);
		if(in.f[i]==0){
			in.f[i]=N2;
			in.space=i;
		}
	}
	//fprintf(stderr,"555555555555555\n");
	n=iterative_deepening(in,ans);
	printf("%d\n",n);
	return 0;
}



Measured memory_bytes: 2108
#include <iostream>
#include <string>
using namespace std;
int main(void){
    int h, w;
    string output;
    
    cin >> h;
    cin >> w;
    
    for (int i = 0; i < w + 2; i++) {
        cout << "#";
    }
    cout << endl;
    
    for (int i = 0; i < h; i++) {
        cin >> output;
        cout << "#" << output << "#" << endl;
    }
    
    for (int i = 0; i < w + 2; i++) {
        cout << "#";
    }
    cout << endl;
    
}


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

ll INF = 1LL << 60;

int 
main() {

  ll N; cin >> N;
  vector<ll> arr(N + 2);
  arr[0] = 0, arr[N -1] = 0;
  rep(i, 1, N + 1) cin >> arr[i];

  vector<ll> acum (N + 2);
  acum[0] = 0;
  rep(i, 1, N + 2){
    acum[i] = abs(arr[i] - arr[i - 1]) + acum[i - 1];
  }

  rep(i, 1, N + 1){
    cout << acum[i - 1] + abs(arr[i - 1] - arr[i + 1]) + abs(acum[N + 1] - acum[i + 1]) << endl;
  }

}


Measured memory_bytes: 2816
#include<stdio.h>

int main()
{
    int a,b,c,d;

    scanf("%d %d %d", &a, &b, &c);
    
   if(a > b){
	d = a;
	a = b;
	b = d;
	}
   if(a > c){
	d = a;
	a = c;
	c = d;
	}
   if(b > c){
	d = b;
	b = c;
	c = d;
	}
    printf("%d %d %d\n", a,b,c);

    return 0;
}


Measured memory_bytes: 2148
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	int s; cin>>s;
	cout<<s/3;
	
	return 0;
}

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

#define int long long
#define ll long long
#define rep(i,n) for (ll i = 0; i < (n) ; i++)
ll ltmp;
int f(string s,int a){
  if(a==0)return -1;
  int res=0,t=1;
  reverse(s.begin(),s.end());
  for(int i=0;i<s.size();i++){
    (res+=t*(s[i]=='1'))%=a;
    (t*=2)%=a;
  }
  return res;
}
int p(int a){
  int res=0;
  while(a){
    if(a&1)res++;
    a>>=1;
  }
  return res;
}
int F(int a){
  int res=0;
  while(a){
    res++;
    a%=p(a);
  }
  return res;
}

ll getMod(ll value,ll mod){
    if(value == 0) return 0;
    return (value + mod) % mod;
}

#define base10_6 1000000    //1e6
ll getPower(ll value,ll shisu,ll mod){
    ll ans = 1;
    ll cnt = shisu;
    while(cnt>0){
        if(cnt%2==1){
            ans = ans * value % mod;
        }
        value = value * value % mod;
        cnt = cnt/2;
    }
    return ans;
}
ll bit2[1000010]={};

ll mod_p[base10_6+10]={};
ll mod_m[base10_6+10]={};
ll getIntSubstr(string s,ll start_index,ll length){
    return atoi(s.substr(start_index,length).c_str());
}

signed main(){
    int n;cin>>n;
    string s;cin>>s;
    int sum=0;
    for(char p:s)sum+=p=='1';
  
    ll base_pop = 0;
    string S = s;
    ll N = n;
    rep(ni,N){
        bit2[ni] = getIntSubstr(S,ni,1);
        //bit2[ni] = 1;
        base_pop+=bit2[ni];
    }
    sum = base_pop;

    ll basev= 1;

    basev=1;



    ll base_pop_p;
    ll base_pop_m;
    base_pop_p = base_pop+1;
    base_pop_m = base_pop-1;
    if(base_pop_m==0) base_pop_m=1;

    basev = 1;
    ltmp = 1;
    for( ll keta = 1 ; keta <=base10_6 ; keta++ ){
        mod_p[keta] = basev;
        basev = basev * 2;
        basev = getMod(basev,base_pop_p); 
    }
    basev = 1;
    for( ll keta = 1 ; keta <= base10_6 ; keta++ ){
        mod_m[keta] = basev;
        basev = basev * 2;
        basev = getMod(basev,base_pop_m); 
    }

    ll base_f1_p = 0;
    ll base_f1_m = 0;
    for( ll keta = 1 ; keta <=N ; keta++ ){
        ll ind = N -keta;
        base_f1_p += mod_p[keta] * bit2[ind];
        base_f1_m += mod_m[keta] * bit2[ind];
        base_f1_p = getMod(base_f1_p,base_pop_p );
        base_f1_m = getMod(base_f1_m,base_pop_m );
    }

    int A=base_f1_p;//f(s,sum+1);
    int B=base_f1_m;//f(s,sum-1);


  for(int i=0;i<n;i++){
    if(sum==1&&s[i]=='1'){
      cout<<0<<endl;
      continue;
    }
    ll keta = N - i;
      
    if(s[i]=='0'){
      int res=A;
      ll value = base_f1_p + mod_p[keta];
      value = getMod(value,base_pop_p);

      //res+=getPower(2,n-i-1,sum+1);res%=sum+1;
      
      res = value;
      cout<<F(res)+1<<endl;
    }
    else{
      int res=B;
      res-=getPower(2,n-i-1,sum-1);
      res+=sum-1;res%=sum-1;
      ll value = base_f1_m - mod_m[keta];
      value = getMod(value,base_pop_m);
      res = value;
      cout<<F(res)+1<<endl;
    }
  }
}


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

int main(){
  int n;
  cin >> n;
  long int MIN,MAX;
  MIN = pow(10,9);
  MAX = 1;
  long int tmp;
  for(int i=0; i<n; i++){
    cin >> tmp;
    MIN = min(MIN, tmp);
    MAX = max(MAX, tmp);
  }
  
  cout << MAX - MIN << endl;
}


Measured memory_bytes: 256
use std::f64::EPSILON;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|s| s.parse().ok().unwrap())
        .collect()
}

fn main() {
    let input = read_vec::<f64>();
    let (w, h, x, y) = (input[0], input[1], input[2], input[3]);
    let n = 
    if (w / 2. - x).abs() < EPSILON && (h / 2. - y).abs() < EPSILON {
        1
    } else {
        0
    };
    println!("{} {}", w * h / 2., n);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define INF 1000000000
using namespace std;

bool is_back(string S)
{
  int N = S.size();
  // cout << N << endl;
  for (int i = 0; i < N / 2; ++i)
  {
    // cout << i << endl;
    if (S.at(N - i - 1) != S.at(i))
    {
      return false;
    }
  }
  return true;
}

int main()
{
  string S;
  cin >> S;
  if (!is_back(S))
  {
    cout << "No" << endl;
  }
  else
  {
    // cout << S.substr(0, S.size() / 2) << endl;
    if (is_back(S.substr(0, S.size() / 2)))
    {
      cout << "Yes" << endl;
    }
    else
    {
      cout << "No" << endl;
    }
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include<bitset>
#include<list>
#include<cassert>
#include<numeric>
#include <iomanip>

using namespace std;
 
const long long N = 100 * 1000 + 5;
vector< pair<long long , long long> > graph[N];
const long long inf = 1000 * 1000 * 1000 * 1000ll * 1000 * 1000;

long long mark[N];
long long place[N];
long long n, m;
bool check = true;

void dfs(long long v)
{
	mark[v] = true;
	for (long long i = 0; i < graph[v].size(); i++)
	{
		long long u = graph[v][i].first;
		long long w = graph[v][i].second;
		if (place[u] == inf)
		{
			place[u] = place[v] + w;
			dfs(u);
		}
		else
		{
			if (place[u] != place[v] + w)
			{
				check = false;
			}
		}
	}
}


int main() 
{
	cin >> n >> m;
	for (long long i = 0; i < m; i++)
	{
		long long u, v, w;
		cin >> u >> v >> w;
		graph[u - 1].push_back({v - 1, w});
		graph[v - 1].push_back({u - 1, -w});
	}
	for (long long i = 0; i < n; i++)
	{
		place[i] = inf;
	}
	for (long long i = 0; i < n; i++)
	{
		if (!mark[i])
		{
			place[i] = 0;
			dfs(i);
		}
	}
	if (check)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
}



























Measured memory_bytes: 17280
#include <functional>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <queue>
#include <string>
#include <cstring>
#include <math.h>
using namespace std;


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

   }
  
   sort(a, a + n); 
  
   int sum = n/2-1;
  
  // cout << sum << endl;
  
   if(a[sum]==a[sum+1]){
     
     cout << 0 <<endl;
     
   }else{
     
     cout << a[sum+1]-a[sum] <<endl;
     
   }
  
  
   
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs
#define tm aklsjdasjdasjdkdjjf
#define lcm hddalkwjeidjjhasda
#define random_shuffle asdasdd

const int MAXN = 105000;

int n;
int x[MAXN];
int go[MAXN];
int len;
int qn;
vector < pair<int, int> > q[MAXN];
int ans[MAXN];
int p[MAXN][20];

int getNthParent(int v, int x) {
  for (int i = 19; i >= 0; i--) {
    while (x >= (1 << i)) {
      v = p[v][i];
      x -= (1 << i);
    }
  }
  return v;
}

int main() { 

  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &x[i]);
  }
  scanf("%d", &len);
  scanf("%d", &qn);
  for (int i = 0; i < qn; i++) {
    int from, to;
    scanf("%d %d", &from, &to);
    from--; to--;
    if (from > to) {
      swap(from, to);
    }
    q[from].push_back({to, i});
  }

  for (int i = 0; i < n; i++) {
    if (i == n - 1) {
      go[i] = i;
      continue;
    }
    int l = i + 1, r = n - 1;
    while (l < r) {
      int mid = (l + r + 1) / 2;
      if (x[mid] - x[i] <= len) {
        l = mid;
      } else {
        r = mid - 1;
      }
    }
    go[i] = l;
  }

  for (int i = n - 1; i >= 0; i--) {
    p[i][0] = go[i];
    for (int j = 1; j < 20; j++) {
      p[i][j] = p[p[i][j - 1]][j - 1];
    }
  }

  for (int i = 0; i < n; i++) {
    for (auto curQ : q[i]) {
      int to = curQ.first, idx = curQ.second;
      int l = 0, r = n;
      while (l < r) {
        int mid = (l + r) / 2;
        int par = getNthParent(i, mid);
        if (par >= to) {
          r = mid;
        } else {
          l = mid + 1;
        }
      }
      ans[idx] = l;
    }
  }

  for (int i = 0; i < qn; i++) {
    printf("%d\n", ans[i]);
  }

  return 0;
}


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

M = set([])
for i in range(N):
  M.add(i+1)

for i in range(K):
  d = int(input())
  L = list(map(int, input().split()))
  for j in range(len(L)):
    if L[j] in M:
      M.remove(L[j])

print(len(M))

Measured memory_bytes: 9196
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<unordered_set>
#define lol(i,n) for(ll i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;

using namespace std;
unordered_set<ll> s;
int main(){
    ll a;cin>>a;
    s.insert(a);
    for(int i=2;;i++){
      if(a%2==0)a/=2;
      else a=a*3+1;
      if(s.find(a)!=s.end()){
	cout<<i<<endl;
	break;
      }
      s.insert(a);
    }
    return 0;
}


Measured memory_bytes: 256