akhauriyash/Code-Regression huggingface dataset:
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def make_divisors(n):
    divisors = []
    for i in range(1, int(pow(n, 0.5)) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)
    divisors.sort()
    return divisors


def resolve():
    n = int(input())

    div = make_divisors(n)
    res = f_inf
    for num in div:
        x, y = num, n // num
        res = min(res, x - 1 + y - 1)
    print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 3264
#define _USE_MATH_DEFINES

#include <iostream>
#include <cstdio>
#include <memory>
#include <string>
#include <cstdlib>
#include <set>
#include <utility>
#include <vector>
#include <list>
#include <algorithm>
#include <regex>
#include <cmath>
#include <map>
#include <iterator>
#include <climits>
#include <numeric>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <array>
#include <valarray>
#include <complex>
#include <random>
#include <functional>
#include <cassert>
#include <chrono>
#include <memory>

using namespace std;

#define int long long
//region TEMPLATE
////@formatter:off
#define double long double
typedef long long ll;
typedef unsigned long long ull;
template<typename T>void __read(T &a) { cin >> a; }
template<typename T, typename ... Args> void __read(T &a, Args &... args) { cin >> a;__read(args...);}
#define make(t, ...) t __VA_ARGS__; __read(__VA_ARGS__)
#define makev(a, n) VI a(n); FOR(n) cin >> a[i]
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define FORIT(p) for(auto it = p.begin(); it != p.end(); it++)
#define FOR(b) for(signed i = 0; i <(b); i++)
#define FORE(i, l, r) for(int i = (l); i < (r); i++)
#define NFOR(i, n) for(int i = (((int) n)-1); i >= 0; i--)
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef pair<pair<int, int>, int> PPII;
constexpr ll M7 = 1000000007ll;
constexpr ll M9 = 1000000009ll;
constexpr ll MFFT = 998244353ll;
template<class T> void outv(T &a) { for (auto &x : a) cout << x << ' '; }
static mt19937 rnd(static_cast<unsigned>(chrono::steady_clock::now().time_since_epoch().count())); // NOLINT(cert-err58-cpp)
auto __fast_io__ = (ios_base::sync_with_stdio(false), cin.tie(nullptr)); // NOLINT(cert-err58-cpp,cppcoreguidelines-interfaces-global-init)
////@formatter:on
//endregion



int32_t main() {
    make(int, n);
    makev(a, n);
    VI dp(n);
    dp[1] = abs(a[0] - a[1]);
    for(int i = 2; i < n; ++i){
        dp[i] = min(dp[i - 1] + abs(a[i - 1] - a[i]), dp[i- 2] + abs(a[i - 2] - a[i]));
    }
    cout << dp.back();


    return 0;
}

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

int main()
{
  string S, W;
  while(cin >> S >> W) {
    int dp[4005] = {0};
    int maxv = 0;
    Rep(i,W.size()) {
      for(int j = S.size(); j > 0; j--) {
	if(S[j - 1] == W[i]) {
	  dp[j] = dp[j - 1] + 1;
	  maxv = max(maxv, dp[j]);
	} else dp[j] = 0;
      }
    }
    cout << maxv << endl;
  }
  return 0;
}

Measured memory_bytes: 3180
<?php
$input_line = trim(fgets(STDIN));
$s = trim(fgets(STDIN));
$s = str_replace(array("\r\n","\r","\n"), '', $s);
$s = explode(" ", $s);

$result = 0;

foreach ($s as $key => $value) {
    $count = half($value);
    if ($result == 0) {
        $result = $count;
    }
    if (!$count) {
        $result = 0;
        break;
    }
    if ($count < $result) {
        $result = $count;
    }
}

echo $result;

function half($param) {
    $count = 0;
    while(($param % 2) == 0) {
        $param = $param / 2;
        $count++;
    }
    return $count;
}


Measured memory_bytes: 16028
n,w = map(int, input().split())
values = []
weights = []

for i in range(n):
    v,weight = map(int, input().split())
    values.append(v)
    weights.append(weight)

dp = [0 for i in range(w+1)]

for i in range(n):
    for j in range(weights[i], w+1):
        dp[j] = max(dp[j], dp[j-weights[i]]+values[i])

print(dp[w])


Measured memory_bytes: 5724
def between(x, y1, y2):
    if x % 3 != 1:return False
    if y1 > y2:
        y1,y2= y2,y1
    for i in range(10):
        if y1 + i >= y2:break
        if (y1 + i) % 3 == 1:
            return True
    return False
    
def dist(x1, y1, x2, y2):
    three = 1
    extra = 0
    for i in range(33):
        if x1 // three == x2 // three and between(x1 //three, y1 //three, y2//three):
            extra = max(extra, min(min(x1 % three, x2 %three) + 1, three - max(x1 % three, x2 % three)))
        three *= 3

    return abs(x1-x2) + abs(y1-y2) + extra * 2

def solve():
    a,b,c,d = map(int, input().split())
    a,b,c,d = a-1,b-1,c-1,d-1
    print(max(dist(a,b,c,d), dist(b,a,d,c)))

q = int(input())
for _ in range(q):
    solve()

Measured memory_bytes: 3316
#include <stdio.h>

int main(void) {
	long long n, m, sum = 0;
	scanf("%lld %lld", &m, &n);

	for (int i = 1; i <= n; i++) {
		long long tmp;
		scanf("%lld", &tmp);
		sum += tmp;
	}

	if (m < sum)
		printf("-1\n");
	else
		printf("%lld\n", m - sum);
}

Measured memory_bytes: 1732
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
int main(int argc, char const *argv[]) {
  int N;
  cin >> N;
  vector<int> A;
  vector<int> A_div;
  A.push_back(0);
  for (size_t i = 0; i < N; i++) {
    int temp = 0;
    cin >> temp;
    A.push_back(temp);
  }
  int sum = 0;
  for (size_t i = 0; i < N; i++) {
    sum += abs(A[i + 1] - A[i]);
    int D = abs(A[i + 1] - A[i]) +abs(A[i+2]-A[i+1])- abs(A[i + 2] - A[i]);
    A_div.push_back(D);
  }

  
  sum += abs(A[N + 1] - A[N]);
  A.push_back(0);


  for (size_t i = 0; i < N; i++) {
    cout << sum - A_div[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 2168
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int number=sc.nextInt();
      	Boolean Success=false;
      	for(int i=1;i<=9;i++)
        {
          if(number/i>10 && number%i==0)
            Success=false;
          else if(number/i<10 && number%i==0)
            Success=true;
        }
      if(Success==true)
         System.out.print("Yes");
      else
        System.out.print("No");
    }
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using uint = unsigned int;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;
const ld PI = acosl(-1);

int D;
int c[26], s[365][26], t[365], last[26], ans[366];

void calc() {
    for (int i = 0; i < D; ++i) {
        ans[i + 1] = ans[i] + s[i][t[i]];
        last[t[i]] = i + 1;
        for (int j = 0; j < 26; ++j)
            ans[i + 1] -= c[j] * (i + 1 < last[j] ? i + 1 : i + 1 - last[j]);
        cout << ans[i + 1] << '\n';
    }
}

void change(int d, int q) {
    d--, q--;
    int old = t[d];
    if (old == q)
        return;

    t[d] = q, last[old] = 0;
    int dif = 0, pos1 = 0, pos2 = 0;
    for (int i = 0; i < D; ++i) {
        last[t[i]] = i + 1;
        if (i < d)
            pos1 = last[q], pos2 = last[old];
        else {
            ans[i + 1] += s[d][q] - s[d][old];
            if (last[q] == d + 1)
                dif += c[q] * (d + 1 - pos1);
            if (last[old] <= d + 1)
                dif -= c[old] * (d + 1 - pos2);
        }
        ans[i + 1] += dif;
    }
}

void greedy() {
    for (int i = 0; i < D; ++i) {
        ans[i + 1] = INT_MIN;
        int maidx = 0;
        for (int k = 0; k < 26; ++k) {
            int res = ans[i] + s[i][k], old = last[k];
            last[k] = i + 1;
            for (int j = 0; j < 26; ++j)
                res -= c[j] * (i + 1 - last[j]);

            if (ans[i + 1] < res) {
                ans[i + 1] = res;
                maidx = k;
            }
            last[k] = old;
        }
        t[i] = maidx;
        last[t[i]] = i + 1;
    }
}

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

    cin >> D;
    for (int i = 0; i < 26; ++i)
        cin >> c[i];
    for (int i = 0; i < D; ++i)
        for (int j = 0; j < 26; ++j)
            cin >> s[i][j];

    for (int i = 0; i < D; ++i) {
        cin >> t[i];
        t[i]--;
    }

    calc();

    // int M;
    // cin >> M;
    // for (int i = 0; i < M; ++i) {
    //     int d, q;
    //     cin >> d >> q;
    //     change(d, q);
    //     cout << ans[D] << '\n';
    // }
    // for (int i = 0; i < D; ++i)
    //     cout << t[i] + 1 << '\n';

    return 0;
}


Measured memory_bytes: 3656
#include <iostream>
#include <vector>
#include <string>

using namespace std;


struct Node {
	int parent;
	int depth;
	string state;
	vector<int> children;
	Node():parent(-1),depth(0){
	}
};
struct faster_io{
	faster_io() {
		cin.tie(0);
		ios::sync_with_stdio(false);
	}
};

void set_depth(vector<Node> &Nodes, Node &node, int depth) {
	node.depth = depth;
	for (int i = 0; i < node.children.size(); i++) {
		set_depth(Nodes, Nodes[node.children[i]], depth + 1);
	}
}


int main() {
	int const N_MAX = 100000;
	faster_io io;

	int n;
	cin >> n;

	vector<Node> Nodes;
	Nodes.resize(N_MAX);

	for (int i = 0; i < n; i++) {
		int id, k;
		cin >> id >> k;
		Node &x = Nodes[id];
		for (int j = 0; j < k; j++) {
			int c;
			cin >> c;
			x.children.push_back(c);
			Nodes[c].parent = id;
		}
	}

	Node root;
	for (int i = 0; i < n; i++) {
		Node &x = Nodes[i];
		if (x.parent == -1) {
			x.state = "root";
			root = x;
		}
		else if (x.children.size() == 0) {
			x.state = "leaf";
		}
		else {
			x.state = "internal node";
		}
	}

	set_depth(Nodes, root, 0);

	for (int i = 0; i < n; i++) {
		Node x = Nodes[i];
		cout << "node " << i
			<< ": parent = " << x.parent
			<< ", depth = " << x.depth
			<< ", " << x.state
			<< ", [";
		for (int j = 0; j < x.children.size(); j++)	{
			if (j != x.children.size() - 1) cout << x.children[j] << ", ";
			else cout << x.children[j];
		}
		cout << "]\n";
	}
}

Measured memory_bytes: 12488
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define M (998244353)
#define INF 1e16
typedef long long ll;
typedef pair<int,int> P;



const double PI=3.14159265358979323846;

int main(void){
    ll r;
    cin>>r;
    printf("%.10lf",(double)2.0*PI*r);
    cout<<endl;
    return 0;
}

Measured memory_bytes: 3724
#include <iostream>
using namespace std;
int main(){
  int N, m, c, d;
  cin >> N >> m;
  int imos[N+1];
  fill(imos, imos+N+1, 0);
  for(int i = 0; i < m; ++i){
    cin >> c >> d;
    ++imos[c];
    --imos[d];
  }
  int t = 0, ans = N+1;
  for(int i = 0; i <= N; ++i){
    t += imos[i];
    if(t > 0) ans += 2;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define loop(n)      for(int i=0;i<(n);i++)
#define lp(x,s,e)    for(int x=(s);x<(e);x++)
#define lpe(x,s,e)    for(int x=(s);x<=(e);x++)
#define endl '\n'
using namespace std;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
   double n;
   cin>>n;
   double pi=6.28318530717958623200;
   double ans =pi*n;
   cout<<fixed<<setprecision(20)<<ans;
}


Measured memory_bytes: 3784
#include <iostream>

int main()
{
	std::string s;
	std::cin >> s;
	int ans1 = 0, ans2 = 0;
	for (int i = 0; i < (int)s.length(); ++i)
	{
		if (i & 1)
		{
			if (s[i] == '0')
			{
				ans1++;
			}
			else
			{
				ans2++;
			}
		}
		if (!(i & 1))
		{
			if (s[i] == '0')
			{
				ans2++;
			}
			else
			{
				ans1++;
			}
		}
	}
	std::cout << std::min(ans1, ans2);
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ldb = long double;
using pa = pair < ll, ll >;
using vec = vector < ll >;

#define pb push_back
#define F  first
#define S  second
#define int ll
#define f(i,x,n) for(ll i=x;i<n;i++) 
#define all(c) c.begin(),c.end()
#define edl "\n"
#define ceils(s,n) (s+n-1)/n
#define str string
#define add insert
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)

const int MOD = 1e9 + 7, N = 5e5 + 10;
const ll LINF = LLONG_MAX;

int32_t main() {
    fast();
    int n;
    cin >> n;
    vec q1(n),q(n),qq(n),q2(n);
    f(i,0,n){
    	cin >> q1[i];
    	q[i]=i+1;
    }
    f(i,0,n){
    	qq[i]=i+1;
    	cin >> q2[i];
    }
    int a=0,b=0;
    int c=0;
    do{
    	// cout<<c<<edl;
    	// f(i,0,n){
    	// 	cout<<q1[i]<<" "<<q[i]<<edl;
    	// }
    	c++;
    	if(q1==q){
    		
    		a=c;
    		break;
    	}
    }
    while(next_permutation(all(q)));

    c=0;
    do{
    	// cout<<c<<edl;
    	// f(i,0,n){
    	// 	cout<<q2[i]<<" "<<qq[i]<<edl;
    	// }
    	c++;
    	if(q2==qq){
    		
    		b=c;
    		break;
    	}
    }
    while(next_permutation(all(qq)));
    cout<<abs(b-a);
    return 0;
}
 

Measured memory_bytes: 256
#include <iostream>
long long MOD = 1e9 + 7;
long long repeatedpow(long long x, long long y){
    if(y == 0) return 1;
    if(y % 2 == 0) return repeatedpow(x, y / 2)*repeatedpow(x, y / 2) % MOD;
    else return x*repeatedpow(x, y -1) %MOD;
}
int main(){
    long long m, n;
    std::cin >> m >> n;
    std::cout << repeatedpow(m, n) << std::endl;
}


Measured memory_bytes: 3092
import Data.List
import Data.Maybe
import Control.Monad
import qualified Data.Vector.Unboxed as V
import qualified Data.ByteString.Char8 as BS

readInt' :: BS.ByteString -> Int
readInt' bs = (fst.fromJust.BS.readInt) bs

main :: IO ()
main = do
  [n,k] <- (map readInt'). BS.words <$> BS.getLine
  hs <- V.fromList . sort <$> (replicateM n $ readInt' <$> BS.getLine)
  print $ minimum [ (hs V.! (i+k-1)) - (hs V.! i) | i <- [0..n-k]]

Measured memory_bytes: 30972
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
# define maxh 2000
# define maxd 10
// # define mod 1e9+7

int main() {
  ll N;
  string ans("");
  cin>>N;
  do{
    ans=to_string(abs(N%(-2)))+ans;
    if (abs(N%2)==1&&N<0) N=N/(-2)+1;
    else N/=(-2);
  }while (abs(N!=0));
  cout << ans;
}

Measured memory_bytes: 256
#include<stdio.h>

int dp[50];

int fib(int n) {
  if ( n == 0 || n == 1 ) return dp[n] = 1;
  if ( dp[n] != -1 ) return dp[n];
  return dp[n] = fib(n - 1) + fib(n - 2);
}

int main() {
  int n, i;
  for( i = 0; i < 50; i++ ) dp[i] = -1;

  scanf("%d", &n);
  printf("%d\n", fib(n));

  return 0;
}



Measured memory_bytes: 2108
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = int64_t;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'

std::vector<int64> enum_div(int64 n)//nの約数を列挙
{
	std::vector<int64> ret;
	for(int64 i=1 ; i*i<=n ; ++i)
	{
		if(n%i == 0)
		{
			ret.push_back(i);
			if(i!=1LL && i*i!=n)
			{
				ret.push_back(n/i);
			}
		}
	}
  ret.push_back(n);
	return ret;
}


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

  int64 n; cin >> n;
  int64 ans = 0;

  vector<int64> v = enum_div(n);

  for (auto x : v){
    if (x == 1) continue;
    if (n % (x - 1LL) == n / (x - 1LL)) ans += (x - 1LL);
  }

  print(ans);

  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define fo(i,s,e) for( i=s;i<e;i++)
#define rfo(i,s,e) for(i=s;i>e;i--)
#define LLI long long int
#define LI long int 
const LI MOD=1e9+7;
#define pb push_back
#define pob pop_back()
#define sp " "
#define ff first
#define ss second
//            When something is important enough, you do it even if the odds are not in your favor.
LLI n,k;
bool check(LLI x,LLI a[]){
  LLI r[n],i,tot=0,tot1=0;
  fo(i,0,n){
    r[i]=a[i]%x;
  }
  sort(r,r+n);
  fo(i,0,n){
    tot+=x-r[i];
  }
  fo(i,0,n-1){
    tot1+=r[i];
    tot-=x-r[i];
    if(tot==tot1&&tot<=k) return 1;
  }
  return 0;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    // code goes here
    int t=1;//cin>>t;
    while(t--){
      cin>>n>>k;
      LLI i,a[n],ans=1;
      LLI sum=0;
      fo(i,0,n){
        cin>>a[i];
        sum+=a[i];
      }
      fo(i,1,sqrt(sum)+1){
        if(sum%i==0){
          if(check(i,a)) ans=max(ans,i);
          if(check(sum/i,a)) ans=max(ans,sum/i);
        }
      }
      cout<<ans;
    }
    return 0;
}

Measured memory_bytes: 3656
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>
#include <numeric>
using namespace std;
int a[100000];
vector <int> children[100000];
int d[100000];
bool done[100000];
void set_d(int cur, int cur_d){
  d[cur] = cur_d;
  for(int i = 0; i < children[cur].size(); i++){
    set_d(children[cur][i], cur_d + 1);
  }
}

void set_done(int cur){
  if(done[cur]){
    return;
  }
  done[cur] = true;
  for(int i = 0; i < children[cur].size(); i++){
    set_done(children[cur][i]);
  }
}

int main(){
  int N;
  long long K;
  cin >> N >> K;
  for(int i = 0; i < N; i++){
    cin >> a[i];
    a[i] --;
    if(i != 0){
      children[a[i]].push_back(i);
    }
  }

  for(int i = 0; i < N; i++){
    d[i] = INT_MAX;
  }

  set_d(0, 0);
  int ans;
  if(a[0] == 0){
    ans = 0;
  } else {
    ans = 1;
  }

  vector <pair <int, int> > tmp;
  for(int i = 0; i < N; i++){
    if(d[i] <= K){
      //done[i] = true;
    } else {
      tmp.push_back(make_pair(d[i], i));
    }
  }
  sort(tmp.begin(), tmp.end());
  reverse(tmp.begin(), tmp.end());

  for(int i = 0; i < tmp.size(); i++){
    int cur_d = tmp[i].first;
    int cur = tmp[i].second;
    if(!done[cur]){
      int teleport = cur;
      for(int i = 0; i < K - 1; i++){
        teleport = a[teleport];
      }
      ans ++;
      set_done(teleport);
    }

  }

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


Measured memory_bytes: 13708
import math
n, d = map(int, input().split())
x = []
for i in range(n):
    x.append(list(map(int, input().split())))

count = 0
eps = 10**-6
for i in range(n-1):
    for j in range(i+1, n):
        total = 0
        for k in range(d):
             total += pow(x[i][k] - x[j][k], 2)
        v = math.sqrt(total)
        if math.ceil(v + eps) != math.ceil(v - eps):
            count += 1
print(count)

Measured memory_bytes: 38384
#include<stdio.h>
int main (void){
 int r,g,b,s;
 scanf("%d",&r);
 scanf("%d",&g);
 scanf("%d",&b);
 s=(r*100)+(g*10)+(b);
 if(s%4){
  printf("NO\n");
 }else{
  printf("YES\n");
 }
}


Measured memory_bytes: 128
n,*a=`dd`.split.map &:to_i;p (1..2*n).bsearch(&->x{b=a.map{|e|e<x};1.upto(n){|i|[-1,1].map{|f|return x if b[n+i*f-1]==x=b[n+i*f-f-1]}};b[0]})-1

Measured memory_bytes: 41940
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define reps(i, n) for (int i = 1; i <= (n); ++i)
#define repd(i, n) for (int i = (n - 1); i >= 0; --i)
#define repds(i, n) for (int i = (n); i > 0; --i)
#define loop(i, x, n) for (int i = (x); i < (n); ++i)
#define loops(i, x, n) for (int i = (x); i <= (n); ++i)
#define loopd(i, x, n) for (int i = (x); i > (n); --i)
#define loopds(i, x, n) for (int i = (x); i >= (n); --i)
#define itrep(i, a) for (auto i = begin(a); i != end(a); ++i)
#define itrepd(i, a) for (auto i = rbegin(a); i != rend(a); ++i)
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using ld = long double;
template <class T>
using priority_queuel = priority_queue<T, vector<T>, greater<T>>;
constexpr ll inf = static_cast<ll>(1e18);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e18;
constexpr double eps = 1e-9;
ll mod = static_cast<ll>(1e9 + 7);
template <class T>
constexpr int sz(const T &a) { return (int)a.size(); }
template <class T>
constexpr T pow2(const T a) { return a * a; }
template <class T, class... Args>
constexpr void mins(T &a, Args... args) { a = min<T>({a, args...}); }
template <class T, class... Args>
constexpr void maxs(T &a, Args... args) { a = max<T>({a, args...}); }
template <class A, int N, class T>
void fillArray(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }

int n, m;
ll a[300005];
ll s[300005];
ll cnt[300005];
void solve() {
    cin >> n;
    rep(i, n) {
        int x;
        cin >> x;
        ++cnt[x - 1];
    }

    rep(i, n) if (cnt[i] > 0) a[m++] = cnt[i];
    sort(a, a + m);
    rep(i, m) s[i + 1] = s[i] + a[i];

    ll ans = n;
    reps(k, n) {
        while (true) {
            bool ok = [&] {
                ll sum = 0;
                auto idx = lower_bound(a, a + m, ans) - a;
                sum += s[idx] + ans * (ll)(m - idx);
                return sum >= k * ans;
            }();
            if (ok) break;
            --ans;
        }
        cout << ans << endl;
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    return 0;
}


Measured memory_bytes: 7808
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int H = 500 + 5;
int a[H][H];

struct MS
{
    int y1, x1, y2, x2;
} mv[H * H];
int ans;
void addmv(int y1, int x1, int y2, int x2)
{
    if (a[y1][x1] & 1)
    {
        a[y2][x2] ^= 1;
        mv[++ans] = (MS){y1, x1, y2, x2};
    }
}

int main()
{
    int h, w;
    scanf("%d%d", &h, &w);
    for (int i = 1; i <= h; ++i)
        for (int j = 1; j <= w; ++j)
            scanf("%d", a[i] + j);
    for (int i = 1; i <= h; ++i)
        if (i & 1)
        {
            for (int j = 1; j < w; ++j)
                addmv(i, j, i, j + 1);
            if (i != h)
                addmv(i, w, i + 1, w);
        }
        else
        {
            for (int j = w; j > 1; --j)
                addmv(i, j, i, j - 1);
            if (i != h)
                addmv(i, 1, i + 1, 1);
        }
    printf("%d\n", ans);
    for (int i = 1; i <= ans; ++i)
        printf("%d %d %d %d\n", mv[i].y1, mv[i].x1, mv[i].y2, mv[i].x2);
}

Measured memory_bytes: 7040
#include <stdio.h>}

int main(void){
	int n,i,S[100000],q,j,T,C = 0,m,L,R,M;
	scanf("%d",&n);
	for (i=0;i<n;i++){
		scanf("%d",&S[i]);
	}
	scanf("%d",&q);
	for (j=0;j<q;j++){
		scanf("%d",&T);
		L=0;
		R=n;
		M=R/2;
		for (i=M;L<R;i=M){
			if (S[i]==T){
				C++;
				break;
			}
			if (S[i]<T){
				L = M+1;
				M = (L+R)/2;
			}
			if (S[i]>T){
				R = M;
				M = (R+L)/2;
			}
		}
	}
	printf("%d\n",C);
	
	return 0;
}

Measured memory_bytes: 1416
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iterator>
#include <numeric>
#include <bitset>
#include <cassert>
#include <functional>

using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)

int main() {
	int N;
	string S;
	cin >> N >> S;
	int mx = 0;
	int x = 0;
	rep(i, N) {
		if (S[i] == 'I') {
			x++;
		}
		else {
			x--;
		}
		if (mx < x) {
			mx = x;
		}
	}
	cout << mx;
	return 0;
}

Measured memory_bytes: 256
from collections import Counter

N = int(input())
S = input()

counter = Counter(S)

cnt = 0
for i in range(N):
    for j in range(i+1, N):
        k = j + j - i
        if 0 <= k < N:
            if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
                cnt += 1

print(counter["R"]*counter["G"]*counter["B"] - cnt)

Measured memory_bytes: 68948
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;++i)
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
#define sumMax 100001
#define INF 10000000000000000

int main(){
   ll N,W;
   cin >> N >> W;
   ll w[N],v[N];
   ll MIN=10000000000;

   rep(i,N) cin >> w[i] >> v[i];

   ll dp[N+1][sumMax];
   rep(i,N+1)rep(k,sumMax) dp[i][k] = INF;

   dp[0][0]=0;

   rep(i,N){
      for(ll k = 0;k<sumMax;k++)
      {
         if(k>=v[i]) chmin(dp[i+1][k],dp[i][k-v[i]]+w[i]);
         
         chmin(dp[i+1][k],dp[i][k]); 
      }
   }
   ll ans = 0;
   rep(i,sumMax){
      if(dp[N][i]<=W) ans = i;
   }
   cout << ans << endl;
  
   return 0;
}


Measured memory_bytes: 79104
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//BEGIN CUT HERE

template<typename T>
T extgcd(T a,T b,T &x,T &y){
  T d=a;
  if(b!=0){
    d=extgcd(b,a%b,y,x);
    y-=(a/b)*x;
  }else{
    x=1;
    y=0;
  }
  return d;
}

template<typename T>
T mod_inverse(T a,T mod){
  T x,y;
  extgcd(a,mod,x,y);
  return (mod+x%mod)%mod;
}

template<typename T>
pair<T, T> linear_congruence(const vector<T> &A,
                             const vector<T> &B,
                             const vector<T> &M){
  T x=0,m=1;
  for(int i=0;i<(int)A.size();i++){
    T a=A[i]*m,b=B[i]-A[i]*x,d=__gcd(M[i],a);
    if(b%d!=0) return make_pair(0,-1);
    T t=b/d*mod_inverse(a/d,M[i]/d)%(M[i]/d);
    x=x+m*t;
    m*=M[i]/d;
  }
  return make_pair((x%m+m)%m,m);
}
//END CUT HERE

signed AOJ_2659(){
  Int r[111][111];
  cin.tie(0);
  ios::sync_with_stdio(0);
  Int n,m,d;
  cin>>n>>m>>d;
  vector<Int> a(m);
  for(Int i=0;i<m;i++) cin>>a[i];

  for(Int i=0;i<d;i++)
    for(Int j=0;j<m;j++)
      cin>>r[i][j];

  for(Int i=0;i<d;i++){
    vector<Int> A,B,M;
    for(Int j=0;j<m;j++){
      if(r[i][j]<0) continue;
      A.emplace_back(1);
      B.emplace_back(r[i][j]);
      M.emplace_back(a[j]);
    }
    auto p=linear_congruence(A,B,M);
    if(p.second<0){
      n=-1;
      break;
    }
    if(p.second<0) p.first+=p.second;
    n=(n-p.first)/p.second*p.second+p.first;
  }
  
  cout<<n<<endl;
  return 0;
}
/* 
   verified on 2018/11/23
   http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2659
*/


Int isprime(Int x){
  if(x<=1) return 0;
  for(Int i=2;i*i<=x;i++)
    if(x%i==0) return 0;
  return 1;
}

signed DDCC2018QUALB_D(){  
  const Int n = 30;
  vector<Int> A,B,M;

  vector<Int> x(n+1);
  for(Int i=2;i<=n;i++){
    cin>>x[i];
    if(!isprime(i-1)) continue;
    A.emplace_back(1);
    B.emplace_back(x[i]%(i-1));
    M.emplace_back(i-1);
  }
  auto p=linear_congruence(A,B,M);
  if(p.second<Int(0)){
    cout<<"invalid"s<<endl;
    return 0;
  }
  Int res=p.first;
  Int flg=1;
  for(Int i=2;i<=n;i++){
    Int sum=0,tmp=res;
    while(tmp>Int(0)){
      sum+=tmp%i;
      tmp/=Int(i);
    }
    flg&=(sum==x[i]);
  }
  if(flg){
    cout<<res<<endl;
    return 0;
  }
  cout<<"invalid"s<<endl;
  return 0;
}
/* 
   verified on 2018/11/23
   https://beta.atcoder.jp/contests/ddcc2019-qual/tasks/ddcc2018_qual_d
*/

signed YUKI_186(){
  vector<Int> A(3,1),B(3),M(3);
  for(Int i=0;i<3;i++) cin>>B[i]>>M[i];
  auto p=linear_congruence(A,B,M);
  if(p.second==-1) cout<<-1<<endl;
  else cout<<(p.first?p.first:p.second)<<endl;
  return 0;
}
/* 
   verified on 2019/03/26
   https://yukicoder.me/problems/no/186
*/

//INSERT ABOVE HERE
signed main(){
  AOJ_2659();
  //DDCC2018QUALB_D();
  //YUKI_186();
  return 0;
}



Measured memory_bytes: 3284
#include<iostream>
#include<math.h>
#include<iomanip>
using namespace std;

int main(){
	int n;
	cin>>n;
	int index=0;
	double alpha[10000];
	while(n!=0){
		int scores[n];
		for(int i=0;i<n;++i)cin>>scores[i];
		int sum=0;
		for(int i=0;i<n;++i)sum+=scores[i];
		double mean=(double)sum/n;
		double alpha2=0;
		for(int i=0;i<n;++i)alpha2+=pow(scores[i]-mean,2)/n;
		alpha[index]=sqrt(alpha2);
		index++;
		cin>>n;
	}
	for(int i=0;i<index;++i){
		cout<<fixed;
		cout<<setprecision(10)<<alpha[i]<<endl;
	}
}


Measured memory_bytes: 3244
def find_sum_of_digits(n):
    sum_of_digits = 0
    while n>0:
        sum_of_digits = sum_of_digits + n % 10
        n = int(n / 10)
    return sum_of_digits


n, a, b = [int(e) for e in input().split()]
ans = 0
for i in range(n+1):
    sum_of_digits = find_sum_of_digits(i)
    if a <= sum_of_digits and sum_of_digits <= b:
        ans = ans + i
print(ans)

Measured memory_bytes: 3060
#include<stdio.h>
int main(){
  int n,t,a,x,i,d;
  int res = 0;
  int cc = 1000000;
  scanf("%d%d%d",&n,&t,&a);
  for(i=1;i<=n;i++){
    scanf("%d",&x);
    d = (t*1000-x*6)-a*1000;
    if(d < 0){
      d = -d;
    }
    if(cc > d){
      res = i;
      cc = d;
    }
  }
  
  printf("%d\n",res);
  return 0;
}


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

//短縮
#define rep(i,n) for(int i=0;i<(n);++i)
//sort()用
#define all(v) v.begin(), v.end()

#define PB(N) push_back(N)

using namespace std;

using Graph = vector<vector<int>>;

int main(){
  int N;cin >> N;
  int i=0;
  while(1){
    i++;
    if(N<=1000*i) break;
  }
  N-=1000*(i-1);
  cout << 1000-N;
  return 0;
}


Measured memory_bytes: 3668
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int c_count = 1;
		while (true) {
			final int N = sc.nextInt();

			if (N == 0) {
				break;
			}

			int[][] map = new int[N][N];

			int count = 1;
			int x = 0, y = 0;
			int state = 0;
			map[0][0] = 1;
			count++;
			if (N != 1) {
				x++;
				
				while (count <= N * N) {
					

					if (state == 0) {
						for (; x >= 0 && y < N; x--, y++) {
							map[y][x] = count;
							count++;
						}
						x++;
						y--;
						

						if (y == N - 1) {
							x++;
						} else {
							y++;
						}
						state = 1;

					} else if (state == 1) {
						for (; y >= 0 && x < N; y--, x++) {
							map[y][x] = count;
							count++;
						}
						y++;
						x--;

						if (x == N - 1) {
							y++;
						} else {
							x++;
						}
						state = 0;
					}
				}
			}
			System.out.println("Case " + c_count + ":");
			for (int i = 0; i < N; i++) {
				for (int j = 0; j < N; j++) {
					System.out.printf("%3d", map[i][j]);
				}
				System.out.println();
			}

			c_count++;
		}

	}

}

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

// #define ipr pair<int, int>
// #define pb push_back
// #define ff first
// #define ss second
// #define fr(i, j, k) for (int i = j; i < k; i++)
// #define rf(i, j, k) for (int i = j; i >= k; i--)
// #define  int unsigned long long
// #define int long long
// #define ld long double
// #define  int(x) x.begin(), x.end()
// #define r    int(x) x.rbegin(), x.rend()
// #define mp make_pair
// #define cnt_ones(x) __builtin_popcoun    int(x)

// #define IOS                           \
//     std::ios::sync_with_stdio(false); \
//     cin.tie(N    int);                    \
//     cout.tie(N   int);

// const int Maxn = (int)1e6;
// const ld pi = acos(-1);
// const int mod = (int)1e9 + 7;
// const int inf = (int)1e18;

// template <class T>
// ostream &operator<<(ostream &out, vector<T> &A) {
//     fr(i, 1, (int)A.size()) out << A[i] + 1 << " ";
//     return out;
// }

// int32_t main() {
//     int n;  cin>>n;
//     map<int, int > my;
//     vector<int > A(n);  fr(i,0,n){
//         cin>>A[i];
//         my[A[i]]++;
//     }
//     int ans = 0;
//     for(auto x : my){
//         ans += x.ss*(x.ss-1)/2;
//     }
//     fr(i,0,n){
//         int ele = my[A[i]];
//         int temp = ans - ele*(ele-1)/2;
//         ele--;
//         temp += ele*(ele-1)/2;
//         cout << temp << endl;
//     }
//     return 0;
// }

#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define ld long double
#define MAX 1e6

vector<int> nc(MAX, 0);

void findnc() {
    nc[2] = 1;
    for (int i = 3; i < MAX; i++) {
        nc[i] = ((i) * (i - 1)) / 2;
    }
}

int32_t main() {
    int n;
    cin >> n;
    vector<int> a(n);
    map<int, int> mp;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        mp[a[i]]++;
    }
    findnc();
    int temp = 0;
    map<int, int>::iterator itr = mp.begin();
    while (itr != mp.end()) {
        temp += nc[itr->second];
        itr++;
    }
    for (int i = 0; i < n; i++) {
        cout << temp - (mp[a[i]] - 1) << endl;
    }

    return 0;
}


Measured memory_bytes: 20620
n, p = map(int, input().split())
A =list(map(int, input().split()))

A = [a%2 for a in A]

e = 0
o = 0
for i in range(n):
    if A[i]%2 == 0:
        e += 1
    else:
        o += 1

ans = 0
import math
if p == 0:
    for i in range(o+1):
        if i%2 == 0:
            ans += math.factorial(o)//(math.factorial(i)*math.factorial(o-i))
    ans *= 2**e
else:
    for i in range(o+1):
        if i%2 == 1:
            ans += math.factorial(o)//(math.factorial(i)*math.factorial(o-i))
    ans *= 2**e
print(ans)

Measured memory_bytes: 38256
using System; 
using System.Text;
using System.Collections.Generic; 
using System.Linq; 
using E = System.Linq.Enumerable; 


class Program {
    //最短ステップ記録用
    static List<string> OpPattern;
    static void Main(string[] args) {
        //入力を受け取る
        var N = int.Parse(Console.ReadLine());
        OpPattern = new List<string>();
        MakePattern("");
        var F = new string[N+1][];
        for(long i = 1;i <= N;i++){
            F[i] = Console.ReadLine().Split(' ');
        }
        var P = new string[N+1][];
        for(long i = 1;i <= N;i++){
            P[i] = Console.ReadLine().Split(' ');
        }
        
        var ans = long.MinValue;
        //全ての営業パターンに対して
        for(int i = 1; i < OpPattern.Count();i++){
            var pro = 0L;
            //全ての店に対して
            for(int j = 1;j <= N;j++){
                //営業時間が何個被ってるか
                var dub = 0;
                for(int k =0;k<10;k++){
                    
                    if(OpPattern[i][k].ToString() == "1" && F[j][k]  == "1"){
                        dub++;
                    }
                }
                pro += int.Parse(P[j][dub]);
            }
            if(pro > ans){
                ans = pro;
            }
        }
        
        Console.WriteLine(ans);
        
     }
     
     //全ての営業パターンを列挙
     static void MakePattern(string str){
         if(str.Length == 10){
             OpPattern.Add(str);
         }else{
             MakePattern(str+"0");
             MakePattern(str+"1");
         }
     }
}
     
     
                   


Measured memory_bytes: 19656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
#define PI 3.14159265358979
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repp(i, s, e) for(int i = (s); i <= (e); ++i)
#define sz(x) ((int)x.size())
#define all(x) x.begin(), x.end()
#define FAST_IO() ios::sync_with_stdio(0); cin.tie(0)
template<typename T>
ostream& operator<<(ostream &os, const vector<T> &v) { for (auto x : v) os << x << " "; return os << "\n"; }
template<class U, class V>
ostream& operator<<(ostream &os, const pair<U, V> &p) { return os << "(" << p.first << "," << p.second << ")";}


int main() {
	FAST_IO();
	int N, N2; cin >> N;
	N2 = 1 << N;
	vector<int> S(N2);
	rep(i, N2) cin >> S[i];
	// 좌표압축 O(N2)
	vector<int> A(N2);
	sort(all(S));
	int V = 0;
	rep(i, N2) {
		if(i == 0 || S[i] == S[i - 1]) A[i] = V;
		else A[i] = ++V;
	}
	vector<int> cnt(V + 1);
	rep(i, N2) cnt[A[i]]++;
	map<int, int> mp; // (number, remain)
	rep(i, V + 1) mp[-i] = cnt[i];
	multiset<int> mset;
	mset.insert(-V);
	rep(i, N) {
		/*for(auto &x : mset) cout << x << " ";
			cout << "~\n";
		for(auto &x : mp) cout << x << " ";
			cout << "\n";*/
		vector<int> add;
		for(auto &x : mset) {
			auto p = mp.upper_bound(x);
			if(p == mp.end()) continue;
			else {
				add.push_back(p->first);
				if(--p->second == 0) mp.erase(p);
			}
		}
		for(auto &x : add) mset.insert(x);
	}
	if(sz(mset) == N2) cout << "Yes\n";
	else cout << "No\n";
}

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

using namespace std;

int main() {
	vector<int> ress;
	while (1) {
		int n;
		cin >> n;

		if (n == 0) { break; }

		vector<long long> w(n + 1);
		for (int i = 1; i <= n; i++) {
			cin >> w[i];
		}

		vector<vector<int>> dp(n + 1, vector<int>(n + 1));

		int res = 0;
		for (int i = 1; i <= n - 1; i++) {
			if (abs(w[i] - w[i + 1]) <= 1) {
				dp[i][i + 1] = 1;
				res = 2;
			}
		}

		if (res == 0) { ress.push_back(0);  continue; }
		if (n <= 3) { ress.push_back(res); continue; }

		for (int i = 1; i <= n - 3; i++) {
			if ((dp[i + 1][i + 2] == 1 && abs(w[i] - w[i + 3]) <= 1)
				|| (dp[i][i + 1] == 1 && dp[i + 2][i + 3] == 1)
				) {
				dp[i][i + 3] = 1;
				res = 4;
			}
		}
//		if (res == 2) { ress.push_back(2);  continue; }
		if (n <= 5) { ress.push_back(res); continue; }

		for (int i = 5; i <= n - 1; i = i + 2) {
			for (int j = 1; j <= n; j++) {
				if (j + i > n) { continue; }

				bool okflg = false;

				for (int length = 2; length <= i - 1; length = length + 2) {

					if (dp[j][j +length-1] == 1 && dp[j + length][j + i] == 1) { 
						okflg = true; 
						break;
					}
				}

				if (okflg) { 
					dp[j][j + i] = 1;
					continue; 
				}

				if (abs(w[j] - w[j + i]) <= 1) {

					if (dp[j + 1][j + i - 1] == 1) { okflg = true; }
					else {
						for (int length = 2; length <= i - 3; length = length + 2) {
							if (dp[j + 1][j +1+ length - 1] == 1
								&& dp[j + 1+length][j + i - 1] == 1
								) {
								okflg = true;
								break;
							}
						}
					}
				}

				if (okflg == true) {
					dp[j][j + i] = 1;
				}
			}
		}

		res = 0;
		int i = 1;
		while (i < n) {
			for (int j = n; j >= i + 1; j--) {
				if (dp[i][j] == 1) {
					res += j - i + 1;
					i = j;
					break;
				}
			}
			i++;
		}
		int res2 = 0;
		i = n;
		while (i >1) {
			for (int j = 1; j <=n- 1; j++) {
				if (dp[j][i] == 1) {
					res2 += i-j + 1;
					i = j;
					break;
				}
			}
			i--;
		}

		res = max(res, res2);

		ress.push_back(res);
	}
	for (int i = 0; i < ress.size(); i++) {
		cout << ress[i] << endl;
	}

	return 0;
}


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

#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;


int main(){
  ll n;
  cin >> n;
  
  vector<int> a(n);
  rep(i,0,n){
    cin >> a.at(i);
  }
  int ans = 0;
  
  int j = 1;	//探している数字

  rep(i,0,n){
    if(a.at(i) == j){
      ans++;
      j++;
    }
  }
  if(ans == 0)
    ans = -1;
  else
    ans = n - ans;
  
  cout << ans << endl;
}

Measured memory_bytes: 1024
#[macro_use]
mod input {

use std;
use std::io;

const SPLIT_DELIMITER: char = ' ';

#[macro_export]
#[allow(unused_macros)]
macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

#[allow(dead_code)]
pub fn input_line_str() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(dead_code)]
pub fn p<T>(t: T)
where
    T: std::fmt::Display,
{
    println!("{}", t);
}

#[allow(dead_code)]
pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
where
    T: std::str::FromStr,
{
    let mut v: Vec<Vec<T>> = Vec::new();

    for _ in 0..line {
        let vec_line = input_vector();
        v.push(vec_line);
    }
    v
}

#[allow(dead_code)]
pub fn input_vector<T>() -> Vec<T>
where
    T: std::str::FromStr,
{
    let mut v: Vec<T> = Vec::new();

    let s = input_line_str();
    let split_result = s.split(SPLIT_DELIMITER);
    for z in split_result {
        let buf = match z.parse() {
            Ok(r) => r,
            Err(_) => panic!("Parse Error"),
        };
        v.push(buf);
    }
    v
}

#[allow(dead_code)]
pub fn str2vec(s: &str) -> Vec<char> {
    let mut v: Vec<char> = Vec::new();
    for c in s.chars() {
        v.push(c);
    }
    v
}
}

use input::*;

fn main() {
    let (n, k): (usize, usize);
    input!(n, k);
    if k & 1 != 0 {
        let buf = (n / k);
        p(buf * buf * buf);
    } else {
        let buf = (n / k);
        let buf2 = (n + (k / 2)) / k;
        p(buf * buf * buf + buf2 * buf2 * buf2);
    }
}

Measured memory_bytes: 4352
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include <string>
#include <complex>
#include <functional>
using namespace std;
typedef pair<int,int> P;
double dat[100][100];
int dp[1000001];//動的計画法
int prime[1000001];
int main(){
    int table[]={0,1,2,3,5,7,8,9};
    int num,keta,ans[100];
    while(cin>>num,num){
        keta=0;
        while(num>0){
            ans[keta++]=table[num%8];
            num/=8;
        }
        for(int i=keta-1;i>=0;i--) cout<<ans[i];
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 3016
#include <bits/stdc++.h>
typedef long long ll;
#define pb puhs_back
using namespace std;
typedef pair< ll, ll> pll;



int main()
{
        ll a,b,c;
        cin >> a >> b >> c;
        ll rm = a-b;
        rm = min(rm , c);
        cout << c-rm << endl;
        return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{int Q,n,i,k,j,l,m,sum,max,tim;
scanf("%d",&n);
int a[200000];
for(i=0;i<=n-1;i++){
	scanf("%d",&a[i]);}
	if(n%2==1){
	for(j=0;n-1-2*j>=0;j++){
		printf("%d ",a[n-1-2*j]);}
		for(k=0;2*k+1<=n-2;k++){
		printf("%d ",a[2*k+1]);}}
	else{for(l=0;n-1-2*l>=1;l++){
		printf("%d ",a[n-1-2*l]);}
		for(m=0;2*m<=n-2;m++){
		printf("%d ",a[2*m]);}}
	
	return 0;
}

Measured memory_bytes: 2816
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("avx") 
#include <bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define makeunique(x) sort(all(x)), (x).resize(unique(all(x)) - (x).begin())
#define re return
#define fi first
#define se second
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define sqrt(x) sqrt(abs(x))
#define y0 y3487465
#define y1 y8687969
#define j0 j5743892
#define j1 j542893
                         
typedef vector<int> vi;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double D;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<vi> vvi;

template<class T> T abs(T x) { re x > 0 ? x : -x; }
template<class T> T gcd(T a, T b) { re a ? gcd (b % a, a) : b; }
template<class T> T sqr(T a) { re a * a; }
template<class T> T sgn(T a) { re a > 0 ? 1 : (a < 0 ? -1 : 0); }

const double pi = acos(-1.0);

#define filename ""

ll a, b, c, d;

unordered_map<ll, ll> f;

ll go(ll x)
{
    if (x == 0) re 0;
    if (x == 1) re d;
    if (f.count(x)) re f[x];
    ll res = 4e18;
    if ((double)x * d < res) res = x * d;
    res = min (go(x / 2) + (x % 2) * d + a, res);
    res = min (go(x / 3) + (x % 3) * d + b, res);
    res = min (go(x / 5) + (x % 5) * d + c, res);
    if (x > 2) res = min (go(x / 2 + 1) + (2 - (x % 2)) * d + a, res);
    if (x > 3) res = min (go(x / 3 + 1) + (3 - (x % 3)) * d + b, res);
    if (x > 5) res = min (go(x / 5 + 1) + (5 - (x % 5)) * d + c, res);
//    cout << x << " " << res << endl;
    return f[x] = res;
}

int main () {
//  freopen (filename".in", "r", stdin);
//  freopen (filename".out", "w", stdout);
    int nt;
    cin >> nt;
    for (int tt = 1; tt <= nt; tt++) {
        f.clear();
        ll n;
        cin >> n >> a >> b >> c >> d;
        ll ans = go (n);
        cout << ans << endl;
    }
    
    return 0;
}


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

int main() {
    int n;
    cin >> n;
    map<int, int> sum;
    vector<int> l(n);
    for (int i = 0; i < n; i++) {
        cin >> l[i];
    }
    sort(l.begin(), l.end());
    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            int bound = l[j] + l[i];
            int ng = n;
            int ok = j;
            while (abs(ok - ng) > 1) {
                int mid = (ok + ng) / 2;
                if (l[mid] < bound) {
                    ok = mid;
                } else {
                    ng = mid;
                }
            }
            ans += ok - j;
        }
    }
    cout << ans << endl;
}

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

typedef vector<vector<int>> matrix;

matrix operator*(const matrix &A, const matrix &B) {
	const int n = A.size();
	const int m = B[0].size();

	matrix res(n, vector<int>(m, 0));
	for(int i = 0; i < n; ++i) {
		for(int k = 0; k < B.size(); ++k) {
			for(int j = 0; j < m; ++j) {
				res[i][j] ^= A[i][k] & B[k][j];
			}
		}
	}
	return res;
}

matrix power(matrix A, int x) {
	const int n = A.size();
	matrix res(n, vector<int>(n, 0));
	for(int i = 0; i < n; ++i) res[i][i] = 1;

	while(x > 0) {
		if(x & 1) res = res * A;
		A = A * A;
		x >>= 1;
	}
	return res;
}

vector<int> gauss_jordan(matrix A, const vector<int> &b) {
	const int n = A.size();
	for(int i = 0; i < n; ++i) {
		A[i].emplace_back(b[i]);
	}

	int j = 0;
	for(int i = 0; i < n; ++i) {
		int pivot = i;

		while(!A[pivot][j]) {
			if(++pivot == n) {
				pivot = i;
				if(++j > n) assert(false);
			}
		}

		A[i].swap(A[pivot]);

		for(int k = 0; k < n; ++k) {
			if(i == k) continue;
			if(A[k][j]) {
				for(int l = j; l <= n; ++l) {
					A[k][l] ^= A[i][l];
				}
			}
		}
		++j;
	}

	vector<int> res(n);
	for(int i = 0; i < n; ++i) {
		res[i] = A[i][n];
	}
	return res;
}

int rank_of(matrix A) {
	const int n = A.size();
	const int m = A[0].size();

	int res = 0;
	for(int i = 0, j = 0; i < n && j < m; ++i) {
		int pivot = i;

		while(!A[pivot][j]) {
			if(++pivot == n) {
				pivot = i;
				if(++j == m) return res;
			}
		}

		A[i].swap(A[pivot]);

		for(int k = i + 1; k < n; ++k) {
			if(A[k][j]) {
				for(int l = j + 1; l < m; ++l) {
					A[k][l] ^= A[i][l];
				}
			}
		}

		++j;
		++res;
	}
	return res;
}

int rank_of(matrix A, const vector<int> &b) {
	const int n = A.size();
	for(int i = 0; i < n; ++i) {
		A[i].emplace_back(b[i]);
	}
	return rank_of(move(A));
}

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

	int n;
	cin >> n;

	matrix A(n, vector<int>(n));
	for(auto &row : A) {
		for(auto &e : row) {
			cin >> e;
		}
	}

	vector<int> b(n);
	for(auto &e : b) cin >> e;

	int t;
	cin >> t;

	A = power(move(A), t);

	const int rank_A = rank_of(A);
	const int rank_Ab = rank_of(A, b);

	if(rank_A != rank_Ab) {
		cout << "none" << endl;
	}
	else if(rank_A < n) {
		cout << "ambiguous" << endl;
	}
	else {
		const auto ans = gauss_jordan(move(A), b);
		for(int i = 0; i < n; ++i) {
			cout << ans[i] << (i + 1 == n ? '\n' : ' ');
		}
	}

	return EXIT_SUCCESS;
}

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

int main(){
    string S, ans;
    int N;
    int buff;

    std::cin >> N >> S;
    if(N%2 == 1){
        ans = "No";
    }else{
        ans = "Yes";
        for(int i = 0;i < N/2;i++){
            if(S[i] != S[i + N/2]){
                ans = "No";
            }
        }
    }
    std::cout << ans;

}

Measured memory_bytes: 3632