akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/




int N, M, S, T;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
//---------------------------------------------------------------------------------------------------
int vis[101010];
void dijk(int s, vector<vector<pair<int,int>>> &E, vector<ll> &D) {
    rep(i, 0, N) D[i] = infl;
    rep(i, 0, N) vis[i] = 0;

    min_priority_queue<pair<ll, int>> que;

    D[s] = 0;
    que.push({ 0, s });

    while (!que.empty()) {
        auto q = que.top(); que.pop();

        ll cst = q.first;
        int cu = q.second;

        if (vis[cu]) continue;
        vis[cu] = 1;

        fore(p, E[cu]) {
            ll cst2 = cst + p.second;
            int to = p.first;

            if (chmin(D[to], cst2)) que.push({ D[to], to });
        }
    }
}
//---------------------------------------------------------------------------------------------------
ll dp[101010];
void _main() {
    cin >> N >> M >> S >> T;
    S--; T--;

    vector<vector<pair<int, int>>> EA(N);
    vector<vector<pair<int, int>>> EB(N);
    vector<ll> DA(N), DB(N);

    rep(i, 0, M) {
        int u, v, a, b; cin >> u >> v >> a >> b;
        u--; v--;

        EA[u].push_back({ v, a });
        EA[v].push_back({ u, a });

        EB[u].push_back({ v, b });
        EB[v].push_back({ u, b });
    }
    
    dijk(S, EA, DA);
    dijk(T, EB, DB);

    rep(i, 0, N) dp[i] = DA[i] + DB[i];
    rrep(i, N - 2, 0) chmin(dp[i], dp[i + 1]);

    ll ma = 1;
    rep(i, 0, 15) ma *= 10;
    rep(i, 0, N) dp[i] = ma - dp[i];
    rep(i, 0, N) printf("%lld\n", dp[i]);
}

Measured memory_bytes: 16636
N = int(input())
H = list(map(int, input().split()))

H.append(0)
STATUS_UP = 0
STATUS_DOWN = 1

status = STATUS_UP
last_top = 0
last_valley = 0
ans = 0

for i in range(1, N+1):
    if status == STATUS_UP:
        if H[i-1] > H[i]:
            ans += H[i-1] - last_valley
            status = STATUS_DOWN
    else:
        if H[i-1] < H[i]:
            last_valley = H[i-1]
            status = STATUS_UP
print(ans)


Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<set>
using namespace std;
int mod = 1e9 + 7;
template <class T>
void inputV(vector<T> &x, int n){
  for(int i=0; i<n; i++) cin >> x[i];
}

int main() {

  int x, a, b, c;
  cin >> a >> b >> c >> x;
  int cnt = 0;
  for(int i=0; i<=a; i++){
    for(int j=0; j<=b; j++){
      for(int k=0; k<=c; k++){
        int sum = 500 * i + 100 * j + 50 * k;
        if( sum == x ) cnt++;
      }
    }
  }
  cout << cnt << endl;

  return 0;
}




//


Measured memory_bytes: 384
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import bisect

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

def LI(): return list(map(int, sys.stdin.readline().split()))


a = int(input())
s = str(input())

if a >= 3200:
    print(s)
else:
    print("red")


Measured memory_bytes: 5696
<?php  
  fscanf(STDIN,"%d",$n);
  $input = preg_split("/ /",trim(fgets(STDIN)));
  $flag = 0;
  for($i=1;$i<=$n;$i++){
    $a[$i] = $input[$i-1];
    $box[$i] = ceil($n/$i);
  }
  for($i=$n;$i>=1;$i--){
    if($box[$i]==1){
      $b[$i]=$a[$i];
    }else{
      $count = 0;
      for($j=$i*$box[$i];$j>=$i;$j=$j-$i){
        if($b[$j]==1){
          $count++;
        }
      }
      if($count%2==$a[$i]){
        $b[$i]=0;
      }else{
        $b[$i]=1;
      }
    }
  }
  $m = 0;
  $ans = array(0);
  for($i=1;$i<=$n;$i++){
    if($b[$i]==1){
      $m++;
      array_push($ans,$i);
    }
  }

  echo($m."\n");
  if($m>0){
    for($i=1;$i<=$m;$i++){
      echo($ans[$i]." ");
    }
  }


Measured memory_bytes: 129884
#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(),(v).end()
const int INF = 1e9;
typedef long long ll;
typedef pair<ll, ll> P;

int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    ll n,X;
    cin>>n>>X;
    ll g=0;
    while(n--){
        ll x;
        cin>>x;
        g=__gcd(g,abs(x-X));
    }
    cout<<g<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

#define ll              long long int
#define vll             vector<ll>
#define vs              vector <string>                                    
#define mll             map<ll,ll>
#define pll             pair<ll, ll>
#define vpll            vector < pair<ll,ll> >
#define itr             vll::iterator
#define all(c)          c.begin(),c.end()
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define ps(x,y)         fixed<<setprecision(y)<<x
#define pb              push_back
#define mb              make_pair
#define ff              first
#define ss              second
#define max3(a,b,c)     max(max(a,b),c)                                    
#define min3(a,b,c)     min(min(a,b),c)  
#define mod             1000000007
#define inf             1000000000000000001
#define from(i, n)      for(__typeof(n) i = 0; i <  n; ++i)
#define fromj(i, j, n)  for(__typeof(n) i = j; i <  n; ++i)
#define printv(v)       from(i,v.size())cout<<v[i]<<" ";cout<<"\n";
#define w(x)            int x; cin>>x; while(x--)

using namespace std;
using namespace __gnu_pbds; 

void c_p_c()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
#endif
}
 
bool func(const pll &a, const pll &b){
    return a.ss < b.ss;
}

typedef tree<int, null_type, less<int >, rb_tree_tag, 
             tree_order_statistics_node_update> pbds; 

int main(){
    c_p_c();
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll n;
    cin>>n;
    ll a,b,c;
    cin>>a>>b>>c;
    vll v1{a,b,c};
    vll v2(6,1);
    fromj(i,1,n){
        cin>>a>>b>>c;
        if(i%2==1){
            v2[0]=v1[1]+a;
            v2[1]=v1[0]+b;
            v2[2]=v1[1]+c;
            v2[0]=max(v2[0],v1[2]+a);
            v2[1]=max(v2[1],v1[2]+b);
            v2[2]=max(v2[2],v1[0]+c);
        }
        else{
            v1[0]=v2[1]+a;
            v1[1]=v2[0]+b;
            v1[2]=v2[1]+c;
            v1[0]=max(v1[0],v2[2]+a);
            v1[1]=max(v1[1],v2[2]+b);
            v1[2]=max(v1[2],v2[0]+c);
        }
        /*printv(v1);
        printv(v2);*/
    }
    if(n%2==0)cout<<*max_element(v2.begin(),v2.end());
    else cout<<*max_element(v1.begin(),v1.end());
}    

Measured memory_bytes: 3648
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

const ll nmax = 1e9 + 7;
const ll Mod = 998244353;
const double PI = 2 * asin(1);

ll Pow(ll A, ll N){
  if (N == 0){
    return 1;
  }else{
    if (N % 2 == 0){
      return Pow(A * A % nmax, N / 2) % nmax;
    }else{
      return A * Pow(A * A % nmax, N / 2) % nmax;
    }
  }
}

int main(){
  ll R1, C1, R2, C2;
  cin >> R1 >> C1 >> R2 >> C2;

  vector <ll> kaijou(2e6 + 5), gyakugen(2e6 + 5);

  kaijou[0] = 1;
  for (ll i = 1; i < 2e6 + 5; i++){
    kaijou[i] = kaijou[i - 1] * i;
    kaijou[i] %= nmax;
  }

  for (ll i = 0; i < 2e6 + 5; i++){
    gyakugen[i] = Pow(kaijou[i], nmax - 2);
    gyakugen[i] %= nmax;
  }
  
  ll ans = 0;

  ll now = kaijou[R2 + C2 + 2] * gyakugen[R2 + 1]; now %= nmax;
  now *= gyakugen[C2 + 1]; now %= nmax;
  ans += now;

  now = kaijou[R2 + C1 + 1] * gyakugen[R2 + 1]; now %= nmax;
  now *= gyakugen[C1]; now %= nmax;
  ans -= now;

  now = kaijou[R1 + C2 + 1] * gyakugen[C2 + 1]; now %= nmax;
  now *= gyakugen[R1]; now %= nmax;
  ans -= now;

  now = kaijou[R1 + C1] * gyakugen[R1]; now %= nmax;
  now *= gyakugen[C1]; now %= nmax;
  ans += now;

  ans %= nmax; ans += nmax;
  ans %= nmax;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 31616
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0);

int main()
{
	fast
	ll a,b,m;
	cin>>a>>b>>m;
	ll ref[a+1],mc[b+1],i,mn1=INT_MAX,mn2=INT_MAX;
	for(i=1;i<=a;i++)
	{
		cin>>ref[i];
		mn1=min(mn1,ref[i]);
	}
	for(i=1;i<=b;i++)
	{
		cin>>mc[i];
		mn2=min(mn2,mc[i]);
	}
	ll mn=INT_MAX;
	while(m--)
	{
		ll x,y,z;
		cin>>x>>y>>z;
		ll sum=ref[x]+mc[y]-z;
		if(sum>=0)
			mn=min(mn,sum);
	}
	for(i=1;i<=min(a,b);i++)
	{
		mn=min(mn,ref[i]+mc[i]);
	}
	mn=min(mn,mn1+mn2);
	cout<<mn;
}

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

using namespace std;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using cd = complex<ld>;

struct crl {
  ll x, y, r;
};

ll sqr(ll x) {
  return x * x;
}

bool intersect(const crl &a, const crl &b) {
  ll dx = a.x - b.x;
  ll dy = a.y - b.y;
  return sqr(a.r + b.r) >= sqr(dx) + sqr(dy) || sqr(dx) + sqr(dy) <= sqr(a.r - b.r);
}

crl readCrl() {
  crl c;
  cin >> c.x >> c.y >> c.r;
  return c;
}

crl readCrl(ll r) {
  crl c;
  cin >> c.x >> c.y;
  c.r = r;
  return c;
}

ld dist(const crl &a, const crl &b) {
  return hypot(a.x - b.x, a.y - b.y) - a.r - b.r;
}

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

  vector<crl> a(1002);
  a[0] = readCrl(0);
  a.back() = readCrl(0);
  ll n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    a[i] = readCrl();
  }
  a[n + 1] = a.back();
  a.resize(n + 2);
  n += 2;
  const ll INF = 1'000'000'000'000'000'000LL;
  vector<ld> d(n, INF);
  vector<char> used(n);
  vector<vector<ld>> g(n, vector<ld>(n, INF));
  for (int i = 0; i < n; i++) {
    g[i][i] = 0;
    for (int j = i + 1; j < n; j++) {
      if (!intersect(a[i], a[j])) {
        g[i][j] = g[j][i] = dist(a[i], a[j]);
      } else {
        g[i][j] = g[j][i] = 0;
      }
    }
  }
  d[0] = 0;
  for (int i = 0; i < n; i++) {
    int v = -1;
    for (int j = 0; j < n; j++) {
      if (!used[j] && (v == -1 || d[v] > d[j])) {
        v = j;
      }
    }
    used[v] = true;
    for (int j = 0; j < n; j++) {
      d[j] = min(d[j], d[v] + g[v][j]);
    }
  }
  cout.precision(20);
  cout << fixed << d.back();
  return 0;
}

Measured memory_bytes: 18992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
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;}
vector<P> ans;
vector<P> ab,cd;

int f(P a, P b) {
    int d = abs(a.first-b.first) + abs(a.second-b.second);
    return d;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m; cin>>n>>m;
    rep(i,n){
        int a,b;cin>>a>>b;
        ab.push_back(make_pair(a,b));
    }
    rep(i,m){
        int c,d; cin>>c>>d;
        cd.push_back(make_pair(c,d));
    }
    for(auto a : ab){
        int now = f(a, cd.front());
        int ans = 0;
        rep(i,m){
            if(f(a,cd[i])<now){
                now = f(a,cd[i]);
                ans = i;
            }
        }
        cout<<ans+1<<endl;
    }

}

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

struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }
    
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};

const long long MAX = 110000;
long long N;
vector<long long> x, y;

long long solve() {
    UnionFind uf(MAX * 2);
    x.resize(N); y.resize(N);
    for (int i = 0; i < N; ++i) cin >> x[i] >> y[i], uf.merge(x[i], y[i] + MAX);

    // 連結成分ごとに、左ノードと右ノードの個数を数える
    map<int, long long> mx, my;
    for (int i = 0; i < MAX; ++i) mx[uf.root(i)]++;
    for (int i = MAX; i < MAX*2; ++i) my[uf.root(i)]++;
    long long res = 0;
    for (int r = 0; r < MAX*2; ++r) res += mx[r] * my[r];
    return res - N;
}

int main() {
    cin >> N;
    cout << solve() << endl;
}

Measured memory_bytes: 33096
//cwystc <--> 陈威宇是天才  --by cwy
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
const double PI=acos(-1);
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i,a,b) for (int i=(a);i<=(b);i++)
#define per(i,a,b) for (int i=(a);i>=(b);i--)
#define Rep(i,a,b) for (int i=(a);i<(b);i++)
#define Per(i,a,b) for (int i=(a);i>(b);i--)
#define travel_set(it,a) for (set<int>::iterator (it)=(a).begin();(it)!=(a).end();(it)++)
#define travel_map(it,a) for (map<int>::iterator (it)=(a).begin();(it)!=(a).end();(it)++)
#define travel_vec(it,a) for (vector<int>::iterator (it)=(a).begin();(it)!=(a).end();(it)++)
#define p(x) cout << x << endl;
#define def cout << "find" << endl;
#define what_is(x) cout << #x << " is " << x << endl;
template <class T>T sqr(T x){return x*x;}
template <class T>T alex(T x){return (x>0)?x:-x;}
template <class T>void read(T&x){
	x=0;T f=1;char ch=getchar();
	while ((ch<48||ch>57)&&ch!=45)ch=getchar();
	if (ch==45)f=-1,ch=getchar();
	while (ch>=48&&ch<=57)x=x*10+ch-48,ch=getchar();
	x*=f;
}

//-------------------------------------------------head-------------------------------------------------

#define maxn 100005
int n,a[maxn],b[maxn];
vector<int> E[maxn];
int d[maxn];
void dfs(int x,int l){
	if (d[x]==1){b[x]=a[x];return;}
	Rep(i,0,E[x].size())if (E[x][i]!=l){
		dfs(E[x][i],x);
	}
	ll sm=0;int mx=0;
	Rep(i,0,E[x].size()){
		sm+=b[E[x][i]];mx=max(mx,b[E[x][i]]);
	}
	// cerr << x << " " << sm << " " << mx << endl;
	if (mx>a[x]||a[x]>sm||2*a[x]<sm){puts("NO");exit(0);}
	b[x]=a[x]*2-sm;
}
int main(){
	read(n);
	rep(i,1,n)read(a[i]);
	Rep(i,1,n){
		int x,y;read(x);read(y);
		E[x].pb(y);E[y].pb(x);
		d[x]++;d[y]++;
	}
	if (n==2){
		if (a[1]==a[2])printf("YES\n");
		else printf("NO\n");
		return 0;
	}
	int rot=0;
	rep(i,1,n)if (d[i]!=1){rot=i;break;}
	dfs(rot,0);if (b[rot]==0)puts("YES");else puts("NO");return 0;
}

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

int main(){
	int N, M;
	cin >> N >> M;
	int B[M+1];
	rep(i,M+1) B[i] = 0;
	rep(i,N){
		int K;
		cin >> K;
		rep(j,K){
			int k;
			cin >> k;
			B[k]++;
		}
	}

	int ans = 0;
	for (int i = 1; i <= M; i++) {
		if (B[i] == N) ans++;
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 3608
// </> : towhid1zaman

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair< int, int > pii;
typedef pair< pii, int > ppi;
#define fill(a,b) memset(a,b,sizeof(a))
#define all(v) (v).begin(),(v).end()
#define sp(k) cout<<setprecision(k)<<fixed;
#define rep(i,a) for(int i=0;i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define unq(v) sort(all(v)),(v).erase(unique(all(v)),(v).end())
#define _ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
#define sqr(a) ((a)*(a))
#define sz(a) int(a.size())
#define ff first
#define ss second
#define pb push_back

const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int inf = 0x3f3f3f3f;// (int)3e18;
const int maxn = 2000100;



int main(){
        _
        int n; cin >> n;
        int res = 0;
        for(int i = 1; i<=n; i++){
            int a; cin >> a;
            while(a%2==0){
                a/=2;
                res++;
            }
        }
        cout<<res<<endl;

return 0;
}




Measured memory_bytes: 256
import sys
def input():
    return sys.stdin.readline()[:-1]
    
n,k = map(int, input().split())
w = [int(input()) for i in range(n)]

def get_v(n,k,w,P):
    c = 0
    val = 0
    for i in w:
        val += i
        if val > P:
            c += 1
            val = i
            if c >= k:
                return 0
    return 1

left = max(w)
right = sum(w)
while True:
    P = (left + right)//2
    ret = get_v(n,k,w,P)
    if ret:
        right = P
    else:
        left = P + 1
    if left == right:
        break
print(left)


Measured memory_bytes: 9564
// Aizu Vol-1 0190: Eleven Puzzle
// 2017.8.23 bal4u@uu
// 2017.11.5 retry
// ???????????¢?´¢??????????????\??????????????§??¶????????§??????
// ????????????????????????16?????????????????§??§???OK???
// 1????????????????????§8??????4??????????????§4096????????¶??????

#include <stdio.h>

typedef unsigned long long UL;

#define HASHSIZ 900001
typedef struct { UL s; char m; } HASH;
HASH hash[HASHSIZ+3], *hashend = hash+HASHSIZ;

int lookup(UL s)
{
	HASH *p = hash + s % HASHSIZ;
	while (p->s) {
		if (p->s == s) return p->m;
		if (++p == hashend) p = hash;
	}
	return -1;
}

int insert(UL s, char m)
{
	HASH *p = hash + s % HASHSIZ;
	while (p->s) {
		if (p->s == s) return 0;
		if (++p == hashend) p = hash;
	}
	p->s = s, p->m = m;
	return 1;
}

#define MAX 500000
typedef struct { UL s; char b1, b2; } QUE;
QUE Q[MAX+3], *top, *end, *qmax = Q+MAX;

int move[13][5] = {
	/*  0 */{ 2, -1 },
	/*  1 */{ 2, 5, -1 },
	/*  2 */{ 0, 1, 3, 6, -1 },
	/*  3 */{ 2, 7, -1 },
	/*  4 */{ 5, -1 },
	/*  5 */{ 1, 4, 6, 9, -1 },
	/*  6 */{ 2, 5, 7, 10, -1 },
	/*  7 */{ 3, 6, 8, 11, -1 },
	/*  8 */{ 7, -1 },
	/*  9 */{ 5, 10, -1 },
	/* 10 */{ 6, 9, 11, 12, -1 },
	/* 11 */{ 7, 10, -1 },
	/* 12 */{ 10, -1 } };

UL swap(UL s, int p, int sp)
{
	UL n;
	p = (12 - p) << 2, sp = (12 - sp) << 2;
	n = (s >> p) & 0xf;
	s &= ~(0xfULL << p);
	return s | (n << sp);
}

int sach(UL s, int b1, int b2, int mode, int lim)
{
	int i, j, x, b[2], step = 1;
	UL s2;

	top = end = Q, end->s = s, end->b1 = b1, end->b2 = b2, end++, end->s = 0, end++;
	while (top+1 < end) {
		s = top->s, b[0] = top->b1, b[1] = top->b2, top++;
		if (!s) { step++, end->s = 0, end++; continue; }
		if (step > lim) break;
//	printf("%#15llx, b1 %2d, b2 %2d, step %2d\n", s, b[0], b[1], step);
		for (i = 0; i < 2; i++) {
			for (j = 0; (x = move[b[i]][j]) >= 0; j++) {
				if (x == b[0] || x == b[1]) continue;
				s2 = swap(s, x, b[i]);
				if (mode) { if (lookup(s2) >= 0) return step; }
				else if (!insert(s2, step)) continue;
				end->s = s2;
				if (i) end->b1 = b[0], end->b2 = x;
				else   end->b1 = x, end->b2 = b[1];
				end++;
			}
		}
	}
	return step;
}

int main()
{
	UL s;
	int i, ans, p, b1, b2;

	s = 0x123456789ab0ULL, insert(s, 0);
	sach(s, 0, 12, 0, 16);
	while (1) {
		for (b1 = -1, s = i = 0; i < 13; i++) {
			scanf("%d", &p);
			if (p < 0) return 0;
			if (!p) { if (b1 < 0) b1 = i; else b2 = i; }
			s = (s << 4) | p;
		}
		if ((ans = lookup(s)) < 0) {
			if ((ans = sach(s, b1, b2, 1, 4)) > 4) ans = -1;
			else ans += 16;
		}
		printf(ans < 0 ? "NA\n" : "%d\n", ans);	
	}
	return 0;
}

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

void solve() {
    int x;
    cin >> x;
    cout << ((x >= 30) ? "Yes" : "No") << "\n";
}

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

    int t = 1;
    while(t--) {
        solve();
    }
}


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

using namespace std;

int main()
{
  int n,m,a;
  for(;cin>>n>>m>>a,n;)
    {
      int line[n];
      for(int i=1;i<=n;i++)
	line[i-1]=i;
      int h[m],p[m],q[m];
      for(int i=0;i<m;i++)
	cin>>h[i]>>p[i]>>q[i];
      for(int i=0;i<m;i++)
	for(int j=i+1;j<m;j++)
	  {
	    if(h[i]>h[j])
	      {
		swap(h[i],h[j]);
		swap(p[i],p[j]);
		swap(q[i],q[j]);
	      }
	  }
      for(int i=0;i<m;i++)
	swap(line[p[i]-1],line[q[i]-1]);
      cout<<line[a-1]<<endl;
    }

}

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) {
    cin >> a[i];
    --a[i];
  }

  vector<int> cnt(n, 0);
  rep(i, n) ++cnt[a[i]];

  vector<int> ball;
  int t = 0;
  rep(i, n) if (cnt[i]) {
    ++t;
    ball.push_back(cnt[i]);
  }
  sort(ball.begin(), ball.end());
  int ans = 0;
  int bi = 0;
  while (t > k) {
    ans += ball[bi++];
    --t;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 5624
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;

#define INF_LL (ll)1e18
#define INF (int)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
using ll = long long;
using PII = pair<int, int>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}


int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	int res = 0;
	REP(i, s.size())
		res += s[i] == '1';
	cout << res << endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
	
	public static void main(String[] args) throws IOException {
		MyScanner sc = new MyScanner();
		PrintWriter out = new PrintWriter(System.out);
		int H = sc.nextInt();
		int W = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				out.print(i < B ^ j < A ? '0' : '1');
			}
			out.println();
		}
		
		out.flush();
	}
	
	static class MyScanner {
		private BufferedReader br;
		private StringTokenizer tokenizer;
		
		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		
		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		
		public int nextInt() {
			return Integer.parseInt(next());
		}
		
		public long nextLong() {
			return Long.parseLong(next());
		}
	}
}


Measured memory_bytes: 24624
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>

using namespace std;

int main(){
  int n,m;
  vector<pair<int,int> >a;
  vector<pair<int,int> >c;
  cin>>n>>m;
  for(int i = 0;i<n;i++){
    int tmpa,tmpb;
    cin>>tmpa>>tmpb;
    a.push_back(make_pair(tmpa,tmpb));
  }
  for(int i = 0;i<m;i++){
    int tmpc,tmpd;
    cin>>tmpc>>tmpd;
    c.push_back(make_pair(tmpc,tmpd));
  }
  for(int i = 0;i<n;i++){
    int ans = 0;
    int max = 1111111111;
    for(int j = 0;j<m;j++){
      int tmp = abs(a[i].first-c[j].first)+abs(a[i].second-c[j].second);
      //cout<<tmp<<endl;
      if(tmp < max){
	ans = j;
	max = tmp;
      }
    
    }
    cout<<ans+1<<endl;
  }
  
  
  return 0;
}


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

int main(){
  int n; cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++)cin>>a[i];
  int l[n],r[n];
  l[0]=a[0];
  r[n-1]=a[n-1];
  for(int i=1;i<n;i++){
    l[i]=max(l[i-1],a[i]);
    r[n-i-1]=max(r[n-i],a[n-i-1]);
  }
  
  for(int i=0;i<n;i++){
    cout<<max(l[i-1],r[i+1])<<endl;
  }
  return 0;
}

Measured memory_bytes: 3968
#include <stdio.h>

main(){
  
  int N;
  int i,j,k,v;
  int A[1000];
  
  scanf("%d",&N);
  
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }
  
  for(i=0;i<N;i++){
    printf("%d",A[i]);
    if(i!=N-1) printf(" ");
  }
  printf("\n");
  
  
  
  for(i=1;i<N;i++){
    v=A[i];
    j=i-1;
    while(j>=0  && A[j]>v){
      A[j+1]=A[j];
      j--;
    }
    A[j+1]=v;
    
    for(k=0;k<N;k++){
      printf("%d",A[k]);
      if(k!=N-1) printf(" ");
    }
    printf("\n");
   
  }
  return 0;
}

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

int read_line(char* out, size_t limit) {
	char* lf;
	if (fgets(out, limit, stdin) == NULL) return 0;
	if ((lf = strchr(out, '\n')) != NULL) *lf = '\0';
	return 1;
}

int main(void) {
	char str[1024];
	char command[4096];
	int q, query_count;
	if (!read_line(str, sizeof(str))) return 1;
	if (!read_line(command, sizeof(command)) || sscanf(command, "%d", &q) != 1) return 1;
	for (query_count = 0; query_count < q; query_count++) {
		int a, b;
		char *command_kind, *p;
		int i;
		if (!read_line(command, sizeof(command))) return 1;
		if ((command_kind = strtok(command, " ")) == NULL) return 1;
		if ((p = strtok(NULL, " ")) == NULL || sscanf(p, "%d", &a) != 1) return 1;
		if ((p = strtok(NULL, " ")) == NULL || sscanf(p, "%d", &b) != 1) return 1;
		if (strcmp(command_kind, "replace") == 0) {
			/* there doesn't seem a grantee that p consists of lowercase letters */
			if ((p = strtok(NULL, "")) == NULL) return 1;
			if (b < a || (size_t)(b - a + 1) != strlen(p)) return 1;
			memcpy(&str[a], p, b - a + 1);
		} else if (strcmp(command_kind, "reverse") == 0) {
			for (i = 0; a + i < b - i; i++) {
				char temp = str[a + i];
				str[a + i] = str[b - i];
				str[b - i] = temp;
			}
		} else if (strcmp(command_kind, "print") == 0) {
			for (i = a; i <= b; i++) putchar((unsigned char)str[i]);
			putchar('\n');
		} else return 1;
	}
	return 0;
}



Measured memory_bytes: 2136
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... U> void assign(V<T>& v, int n, const U&... u) { v.resize(n); for (auto&& i : v) assign(i, u...); }

int main() {
  cin.tie(NULL); ios::sync_with_stdio(false);
  string s, t; cin >> s >> t;
  int m = s.size(), n = t.size();
  VV<> dp; assign(dp, m + 1, n + 1);
  for (int i = 0; i < m; i++) dp[i + 1][0] = i + 1;
  for (int i = 0; i < n; i++) dp[0][i + 1] = i + 1;
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      dp[i + 1][j + 1] = min({dp[i + 1][j] + 1, dp[i][j + 1] + 1, dp[i][j] + (s[i] != t[j])});
    }
  }
  cout << dp[m][n] << '\n';
}


Measured memory_bytes: 6740
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n, k;
const int N = 100001;
const int M = 100001;
vector<int> a;
int solve(){
  int pos = -1;
  for(int i = 0;i < a.size();i++){
    if(pos == -1 && a[i] > 0)
      pos = i;
  }
  if(pos == -1){
    return -a[n - k];

  }else if(pos == 0){
    return a[k - 1];
  }else{
    int res = (pos >= k ? -a[pos - k] : 1e9);
//  cout << res << endl;
    for(int i = 1;pos + i - 1 < n && i <= k;i++){
      if(pos - (k - i) < 0)continue;
      res = min(res, a[pos + i - 1] * 2 - a[pos - (k - i)]);
    }
    return res;
  }
}
int main(){
//  freopen("in.txt", "r", stdin);
//  freopen("out.txt", "w", stdout);
  cin >> n >> k;
  a.resize(n);
  for(int i = 0;i < n;i++){
    cin >> a[i];
  }
  int res = solve();
  for(int i = 0;i < n;i++)
    a[i] *= -1;
  reverse(a.begin(), a.end());

  res = min(res, solve());
  cout << res;
  return 0;
}


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

class UnionFind {
public:
    vector<int> data;
 	UnionFind(int size) : data(size, -1) { }
 	bool connect(int x, int y) {
  		x = root(x); y = root(y);
  		if (x != y) {
   			if (data[y] < data[x]) swap(x, y);
        data[x] += data[y]; data[y] = x;
        }
        return x != y;
    }
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    int root(int x) {
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }
    int size(int x) {
        return -data[root(x)];
    }
};



void solve(long long N, long long M, long long K, std::vector<long long> A, std::vector<long long> B, std::vector<long long> C, std::vector<long long> D){
    vector<vector<int>> block(N);
    vector<int> friend_num(N);
    for(int i = 0;i < K;i++){
        C[i]--,D[i]--;
        block[C[i]].push_back(D[i]);
        block[D[i]].push_back(C[i]);
    }
    UnionFind Uni(N);
    for(int i = 0;i < M;i++){
        A[i]--,B[i]--;
        Uni.connect(A[i], B[i]);
        friend_num[A[i]]++;
        friend_num[B[i]]++;
    }
    for(int i = 0;i < N;i++){
        int sz = Uni.size(i);
        int ans = sz - 1 - friend_num[i];
        for(auto a : block[i]){
            if(Uni.same(a, i))ans--;
        }
        cout<<ans<<(i == N-1 ? "" : " ");
    }
    cout<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> A(M);
    std::vector<long long> B(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&A[i]);
        scanf("%lld",&B[i]);
    }
    std::vector<long long> C(K);
    std::vector<long long> D(K);
    for(int i = 0 ; i < K ; i++){
        scanf("%lld",&C[i]);
        scanf("%lld",&D[i]);
    }
    solve(N, M, K, std::move(A), std::move(B), std::move(C), std::move(D));
    return 0;
}


Measured memory_bytes: 9856
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Washoum
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        inputClass in = new inputClass(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BFrog2 solver = new BFrog2();
        solver.solve(1, in, out);
        out.close();
    }

    static class BFrog2 {
        public void solve(int testNumber, inputClass sc, PrintWriter out) {
            int n = sc.nextInt();
            int k = sc.nextInt();
            int[] tab = new int[n];
            for (int i = 0; i < n; i++) {
                tab[i] = sc.nextInt();
            }

            int[] dp = new int[n];

            for (int i = 1; i < n; i++) {
                dp[i] = Integer.MAX_VALUE;
            }

            for (int i = 0; i < n - 1; i++) {
                for (int j = 1; j <= k && i + j < n; j++) {
                    dp[i + j] = Math.min(dp[i + j], dp[i] + Math.abs(tab[i] - tab[i + j]));
                }
            }
            out.println(dp[n - 1]);
        }

    }

    static class inputClass {
        BufferedReader br;
        StringTokenizer st;

        public inputClass(InputStream in) {

            br = new BufferedReader(new InputStreamReader(in));
        }

        public String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

    }
}



Measured memory_bytes: 36116
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define erep(i,a,n) for(int i = a;i<=n;i++)
typedef long long ll;
#define int long long
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define P pair<int,int>
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

signed main(){
  int h,w,k;
  cin >> h >> w >> k;
  int ttans = 0;
  vstring mass(h);
  rep(i,0,h){
    cin >> mass[i];
  }
  for (int i = 0;i < (1 << h);i++) {
    bitset<7> s(i);
    for (int j = 0;j < (1 << w);j++) {
      bitset<7> kk(j);
      vstring tmpmass = mass;
      rep(checkh,0,7){
        if(s.test(checkh)){
          rep(changew,0,w){
            tmpmass[checkh][changew] = 'r';
          }
        }
      }
      rep(checkw,0,7){
        if(kk.test(checkw)){
          rep(changeh,0,h){
            tmpmass[changeh][checkw] = 'r';
          }
        }
      }
      int kans = 0;
      rep(ni,0,h){
        rep(nj,0,w){
          if(tmpmass[ni][nj] == '#') kans++;
        }
      }
      if(kans == k) ttans++;
    }
  }
  cout << ttans << endl;
}

Measured memory_bytes: 3596
//I read the news today, oh boy
//About a lucky man who made the grade
 
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(x) ll((x).size())
#define all(v) (v).begin(),(v).end()
#define trace(x) cerr << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define For(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
#define roF(i,a,b) for(ll i = ll(a); i >= ll(b); i--)
using namespace std;

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;

const ll N=1e6;

int main(){
	fastio;
	int n; cin>>n;
	ll ans = 0;
	For(i,1,n+1){
		ans += i*(n-i+1);
	}
	For(i,0,n-1){
		ll u, v; cin>>u>>v;
		if(u>v) swap(u,v);
		ans -= u*(n-v+1);
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 3604
#include <algorithm>
#include <array>
#include <cmath>
#include <iostream>
#include <vector>

const uint32_t A_max = 1'000'000;

int main() {
  uint32_t N = 0;
  std::cin >> N;
  std::vector<uint32_t> A(N);
  for (auto &&a : A) std::cin >> a;

  std::sort(A.begin(), A.end());
  std::array<uint32_t, A_max+1> flag;
  flag.fill(0);

  for (size_t i = 0; i < N; i++) {
    if (flag[A[i]] != 0) {
      flag[A[i]]++;
      continue;
    }
    for (size_t j = A[i]; j <= A_max; j += A[i]) flag[j]++;
  }

  uint32_t ans = 0;
  for (size_t i = 0; i < N; i++) {
    if (flag[A[i]] == 1) ans++;
  }

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

  return 0;
}

Measured memory_bytes: 8016
#include<iostream>
#include<cstdio>
#include<string>
#include<map>
using namespace std;

int main() {
  int n;
  char str[10], com[13];
  map<string, bool> T;

  cin >> n;
  for (int i = 0; i < n; i ++) {
    scanf("%s%s", com, str);
    if (com[0] == 'i') T[string(str)] = true;
    else {
      if (T[string(str)]) printf("yes\n");
      else printf("no\n");
    }
  }
}


Measured memory_bytes: 47484
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

typedef long long ll;

using namespace std;

int main() {
    int n;
    cin >> n;
    int taxExcludedCandidate1 = n / 1.08;
    int taxExcludedCandidate2 = taxExcludedCandidate1 + 1;
    if (floor(taxExcludedCandidate1 * 1.08) == n) {
        cout << taxExcludedCandidate1 << "\n";
        return 0;
    }
    if (floor(taxExcludedCandidate2 * 1.08) == n) {
        cout << taxExcludedCandidate2 << "\n";
        return 0;
    }
    cout << ":("
         << "\n";

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;
typedef int64_t ll;


int main() {
    ll N, M;
    cin >> N;
    map<ll, ll> D;
    for (int i = 0; i < N; i++){
        ll a;
        cin >> a;
        D[a]++;
    }
    cin >> M;
    if (N < M){
        cout << "NO" << endl;
        return 0;
    }
    for (int i = 0; i < M; i++){
        ll a;
        cin >> a;
        if (D[a] <= 0){
            cout << "NO" << endl;
            return 0;
        }
        else {
            D[a]--;
        }
    }
    cout << "YES" << endl;


}


Measured memory_bytes: 12800
#include <cstdio>
#include <cmath>
using namespace std;

#define ll long long

int main() {
	ll n, k; scanf("%lld %lld", &n, &k);
	ll p = n / k, q = n % k;
	bool isOdd = (k % 2 == 1);

	ll ans = static_cast<ll>(pow(p, 3));

	if (isOdd) { ; }
	else {
		if (q >= k / 2) {
			ans += static_cast<ll>(pow(p + 1, 3));
		}
		else {
			ans += static_cast<ll>(pow(p, 3));
		}
	}

	printf("%lld", ans);

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n)  for(int i=0;i<(int)(n);++i)
#define FOR(i, b, n)  for(int i=b;i<(n);++i)
#define ALL(c) (c).begin(),(c).end()
#define SS size()
#define PB push_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;

template<typename T, typename U> static void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if (x < y) x = y; }

template <typename T> void print(T& w) {
    for(auto e : w) cout << e << ", ";
    cout << endl;
}


int main() {
	int n, y; cin >> n >> y; 
	if (y%1000 != 0) goto bad;
	y /= 1000;
	REP(a,2001) REP(b,4001) {
		ll rest = y - a * 10 - b * 5; 
		if (rest>=0 && rest + a + b == n) {
			cout << a << " " << b << " " << rest; 
			return 0;
		}
	}

	bad:
	cout << -1 << " " << -1 << " " << -1; 
}


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

using namespace std;

vector<int> A;
vector<int> G;
int cnt;

void insertionSort(int n, int g)
{
	int v, j;
	
	for(int i = g; i <= n-1; i++)
	{
		v = A[i];
		
		for(j = i-g; j >= 0 && A[j] > v; A[j+g] = A[j], j -= g, cnt++);
	
		A[j+g] = v;
	}
}

void shellSort(int n)
{
	for(int i = 1; i <= n; G.push_back(i), i=3*i+1);
	
	for(int i = G.size()-1; i >= 0; insertionSort(n, G[i]), i--);
}

int main()
{
	int n, x;
	
	scanf("%d", &n);
	
	for(int i = 0; i < n; i++)
	{
		scanf("%d", &x);
		A.push_back(x);		
	}
	
	cnt = 0;
	shellSort(n);
	
	printf("%d\n", G.size());
	
	for(int i = G.size()-1; i >= 0; i--)
		printf("%d%c", G[i], i == 0 ? '\n' : ' ');
	
	printf("%d\n", cnt);
	
	for(int i = 0; i < n; i++)
		printf("%d\n", A[i]);
	
	return 0;
}


Measured memory_bytes: 7020
#include <algorithm>
#include <cstdint>
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;
using myui = uint64_t;
using myint = int64_t;

template<typename T>
T diff(const T& a, const T& b) {
    return a > b ? a - b : b - a;
}

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

    {
        myui items[5];
        for(auto& i : items) {
            cin >> i;
        }

        myui pads[5];
        myui max = 0;
        myui max_i = 0;
        for(myui i = 0; i < 5; i++) {
            pads[i] = 10 - items[i] % 10;
            if (pads[i] == 10) pads[i] = 0;
            if (pads[i] > max) {
                max = pads[i];
                max_i = i;
            }
        }

        myui sum = 0;
        for(myui i = 0; i < 5; i++) {
            if (i != max_i) {
                sum += items[i] + pads[i];
            }
        }

        cout << sum+items[max_i] << endl;
    }

    return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    while (true) {
        val (H, W) = readLine()!!.split(" ").map(String::toInt)
        if (H == 0 && W == 0) break
        for (i in 1..H) {
            for (j in 1..W) {
                if ((i + j) % 2 == 0) print("#")
                else print(".")
            }
            println("")
        }
        println("")
    }
}



Measured memory_bytes: 39268
#include <iostream>
#include <string>
#include <cmath>
#include<iomanip>
#include<algorithm>
#include<list>
using namespace std;


int main()
{
	int n;
	long long a, Max = -10000000001, Min = 10000000001;
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> a;
		Max = max(Max, a - Min);
		Min = min(Min, a);
	}
	cout << Max << endl;
	
	return 0;
}

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

using namespace std;

int N, M, nr, INF = 1e7, dist[500009];
map < pair < int, int >, int > mp;
vector < pair < int, int > > v[500009];
priority_queue < pair < int, int > > PQ;

void add_edge (int x, int y, int c)
{
//    printf ("%d %d %d\n", x, y, c);
    v[x].push_back ({y, c});
    v[y].push_back ({x, c});
}

int code (int nod, int col)
{
    if (mp.count ({nod, col})) return mp[{nod, col}];
    mp[{nod, col}] = ++nr, add_edge (nod, nr, 1);
//    printf ("%d = (%d, %d)\n", nr, nod, col);
    return nr;
}

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d %d", &N, &M), nr = N;
for (int i=1; i<=M; i++)
{
    int x, y, c;
    scanf ("%d %d %d", &x, &y, &c);
    int x2 = code (x, c), y2 = code (y, c);
    add_edge (x2, y2, 0);
}
for (int i=1; i<=nr; i++)
{
    if (i != 1) dist[i] = INF;
    PQ.push (make_pair (-dist[i], i));
}
while (!PQ.empty ())
{
    pair < int, int > curr = PQ.top ();
    PQ.pop ();
    if (dist[curr.second] != -curr.first) continue;
    int nod = curr.second, D = -curr.first;
    for (auto it = v[nod].begin (); it != v[nod].end (); it ++)
        if (dist[it->first] > D + it->second)
            dist[it->first] = D + it->second, PQ.push (make_pair (-dist[it->first], it->first));
}
if (dist[N] >= INF) printf ("-1\n");
else printf ("%d\n", dist[N] / 2);
return 0;
}


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

int main(){
    int n; cin >> n;
    vector<int> a(n),b(n),c(n);

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

    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());

    vector<long long> bv(n+1);
    bv[0] = 0;
    for(int i=1;i<n+1;i++){
        auto itr = lower_bound(a.begin(), a.end(), b[i-1]);
        bv[i] = (long long)(itr - a.begin());
    }
    //for(int i=0;i<n+1;i++) cout << bv[i] << " ";
    //cout << endl;
    for(int i=0;i<n;i++){
        bv[i+1] = bv[i] + bv[i+1];
    }
    long long ans = 0;
    for(int i=0;i<n;i++){
        auto itr = lower_bound(b.begin(), b.end(), c[i]);
        ans = ans + bv[ (int) (itr - b.begin())];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2552
import java.io.*;
import java.lang.*;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.StringTokenizer;
import java.math.BigInteger;

public class Main {
    static InputReader in = new InputReader(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        int a = in.nextInt();
        int b = in.nextInt();
        int c = in.nextInt();
        out.println(Math.min(a*b,c));
        out.close();
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

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

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public String nextLine() {
            try {
                return reader.readLine();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }

        public boolean hasNext() {
            String next = null;
            try {
                next = reader.readLine();
            } catch (Exception e) {
            }
            if (next == null) {
                return false;
            }
            tokenizer = new StringTokenizer(next);
            return true;
        }

        public BigInteger nextBigInteger() {
            return new BigInteger(next());
        }
    }
}



Measured memory_bytes: 33040
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int m, n;
	while (cin >> m >> n, m, n) {
		int w[110];
		int f = 0;
		for (int i = 0; i < n; i++) {
			cin >> w[i]; f = max(w[i], f);
		}
		while (1) {
			int p = 1, q = f;
			for (int i = 0; i < n; i++) {
				if (w[i] <= q)q -= w[i];
				else {
					p++;
					q = f - w[i];
				}
			}
			if (p <= m)break;
			f++;
		}
		cout << f << endl;
	}
}


Measured memory_bytes: 3112
#include <stdio.h>

int main()
{
    int x[5];
    scanf("%d %d %d %d %d", &x[0], &x[1], &x[2], &x[3], &x[4]);
    for (int i = 0; i < 5; i++)
    {
        if (x[i] == 0)
        {
            printf("%d\n", i + 1);
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 1704