akhauriyash/Code-Regression huggingface dataset:
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
typedef long long ll;

int main(){
	int n ; 
	cin >> n ; 
	vector<int> v(n) ; 
	map<int,int> cnt ; 
	for(int &x : v){
		cin >> x ; 
		cnt[x]++ ; 
	}
	int m ; 
	cin >> m ; 
	if ( m > n ) {
		cout << "NO" << endl;
		return 0 ; 
	}
	for(int i=0;i<m;i++){
		int x ; 
		cin >> x ; 
		int &c = cnt[x] ; 
		if ( c ){
			c-- ; 
		}
		else{
			cout << "NO" << endl;
			return 0 ; 
		}
	}
	cout << "YES" << endl;
    return 0 ;
}


Measured memory_bytes: 10368
#include <bits/stdc++.h>
#define MP make_pair
#define PB push_back
#define int long long
#define st first
#define nd second
#define rd third
#define FOR(i, a, b) for(int i =(a); i <=(b); ++i)
#define RE(i, n) FOR(i, 1, n)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define REP(i, n) for(int i = 0;i <(n); ++i)
#define VAR(v, i) __typeof(i) v=(i)
#define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
template<typename TH> void _dbg(const char* sdbg, TH h) { cerr<<sdbg<<"="<<h<<"\n"; }
template<typename TH, typename... TA> void _dbg(const char* sdbg, TH h, TA... t) {
  while(*sdbg != ',')cerr<<*sdbg++; cerr<<"="<<h<<","; _dbg(sdbg+1, t...);
}
#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) {{cerr <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<"\n"; }}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define cerr if(0)cout
#endif
#define next ____next
#define prev ____prev
#define left ____left
#define hash ____hash
typedef long long ll;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<pair<int, int> > VPII;
typedef vector<pair<ll, ll> > VPLL;

template<class C> void mini(C&a4, C b4){a4=min(a4, b4); }
template<class C> void maxi(C&a4, C b4){a4=max(a4, b4); }
template<class T1, class T2>
ostream& operator<< (ostream &out, pair<T1, T2> pair) { return out << "(" << pair.first << ", " << pair.second << ")";}
template<class A, class B, class C> struct Triple { A first; B second; C third;
  bool operator<(const Triple& t) const { if (st != t.st) return st < t.st; if (nd != t.nd) return nd < t.nd; return rd < t.rd; } };
template<class T> void ResizeVec(T&, vector<int>) {}
template<class T> void ResizeVec(vector<T>& vec, vector<int> sz) {
  vec.resize(sz[0]); sz.erase(sz.begin()); if (sz.empty()) { return; }
  for (T& v : vec) { ResizeVec(v, sz); }
}
typedef Triple<int, int, int> TIII;
template<class A, class B, class C>
ostream& operator<< (ostream &out, Triple<A, B, C> t) { return out << "(" << t.st << ", " << t.nd << ", " << t.rd << ")"; }
template<class T> ostream& operator<<(ostream& out, vector<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }

const int N = 1e6 + 6;
int a[N], b[N];
    
int32_t main() {

  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(10);
  cerr << fixed << setprecision(10);
  cin.tie(0);
  //double beg_clock = 1.0 * clock() / CLOCKS_PER_SEC;
  
  int n;
  cin>>n;
  RE (i, n) {
    cin>>a[i]>>b[i];
  }
  int clicked = 0;
  FORD (i, n, 1) {
    a[i] += clicked;
    int now = 0;
    int goal = (a[i] + b[i] - 1) / b[i] * b[i];
    now += goal - a[i];
    assert(now >= 0 && now < b[i]);
    clicked += now;
  }
  cout<<clicked<<endl;
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  return 0;
}


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

#define for_(i,a,b) for(int i = (a);i < (b);i++)
#define rfor_(i,a,b) for(int i = (b)-1;i >= (a);i--)
#define rep(i,n) for_(i,0,(n))
#define rrep(i,n) rfor_(i,0,(n))

int main(){
	cin.tie(0);
	
	int i=1;
	int n;
	while(cin>>n,n)cout<<"Case "<<(i++)<<": "<<n<<endl;
	
	return 0;
}



Measured memory_bytes: 3024
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;
ll a[100];
ll b[100];
int main(){
	int a,b;
	while(~scanf("%d %d", &a, &b)){
		int c = a * b;
		if(c % 2 == 0)
			printf("Even\n");
		else
			printf("Odd\n");
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) int ab;cin>>ab;(p).push_back(ab);
#define vecpl2(p) long long ab;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main() {
	
int N;
cin>>N;
vec(A)
fx(N){
	vecp(A)
}
sorts(A)
reverses(A)
int ans=0;
fx(A.size()){
	if(x%2==0){
		ans+=A.at(x);
	}else{
		ans-=A.at(x);
	}
}
ce(ans)
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define RFOR(i, s, n) for (int i = (n) - 1; i >= (int)(s); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(a) a.begin(), a.end()
constexpr long long INF = 1e18;
template<class T>inline bool CHMAX(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool CHMIN(T&a,T b){if(a>b){a=b;return true;}return false;}

vector<int>g[100010];

signed main(){
	int N,M;
	cin >> N >> M;
	REP(i,M){
		int a,b;
		cin >> a >> b;
		a--;b--;
		g[a].push_back(b);
	}
	vector<int>ans(N+1);
	auto min_cycle = [&](int i)->vector<int>{
		vector<int>prev(N,-1);
		queue<int>que;
		que.push(i);
		vector<int>tmp;
		while(!que.empty()){
			int now = que.front();
			que.pop();
			for(auto e:g[now]){
				if(e == i){
					while(now != -1){
						tmp.push_back(now);
						now = prev[now];
					}
					return tmp;
				}else if(prev[e] != -1)continue;
				else{
					prev[e] = now;
					que.push(e);
				}
			}
		}
		return vector<int>(N+1,0);
	};
	REP(i,N){
		auto tmp = min_cycle(i);
		if(tmp.size() < ans.size())ans = tmp;
	}
	if(ans.size() == N + 1){
		cout << -1 << endl;
		return 0;
	}
	cout << ans.size() << endl;
	for(auto &e:ans)cout << e + 1 << endl;
}

Measured memory_bytes: 2688
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)






class unionfind
{
private:
    vector<ll> par;
    vector<ll> rank;
    vector<ll> counter;
public:
    unionfind(ll n);
    ll find(ll x);
    void unite(ll x, ll y);
    bool same(ll x, ll y);
    ll count(ll x);
};

// 初期化
unionfind::unionfind(ll n){
    for (ll i = 0; i < n; i++) {
        par.push_back(i);
        rank.push_back(0);
        counter.push_back(1);
    }
}

// 木の根を求める
ll unionfind::find(ll x) {
    if (par[x] == x) {
        return x;
    }
    else {
        return par[x] = find(par[x]);
    }
}

// xとyの属する集合を併合
void unionfind::unite(ll x, ll y) {
    x = find(x);
    y = find(y);
    if (x == y)return;
    
    if (rank[x] < rank[y]) {
        counter[y] += counter[x];
        counter[x] = counter[y];
        par[x] = y;
    }
    else {
        counter[y] += counter[x];
        counter[x] = counter[y];
        par[y] = x;
        if (rank[x] == rank[y]) {
            rank[x]++;
        }
    }
}

// xとyが同じ集合に属していたらtrue
bool unionfind::same(ll x, ll y) {
    return find(x) == find(y);
}

// xと同じ集合に属している要素数を返す
ll unionfind::count(ll x){
    return counter[find(x)];
}

int main() {
    ll n, m;
    cin >> n >> m;
    vector<pair<ll, ll>> v(m);
    REP(i, m){
        ll a, b;
        cin >> a >> b;
        a--; b--;
        v[i] = {a, b};
    }
    reverse(v.begin(), v.end());
    unionfind uni(n);
    vector<ll> ans(m);
    ll res = n * (n - 1);
    REP(i, m){
        ans[i] = res / 2;
        if(uni.same(v[i].first, v[i].second)) continue;
        ll c1 = uni.count(v[i].first);
        ll c2 = uni.count(v[i].second);
        uni.unite(v[i].first, v[i].second);
        res -= c1 * c2 * 2;
        // cerr << c1 << " " << c2 << " " << res << endl;
    }
    reverse(ans.begin(), ans.end());
    REP(i, m){
        cout << ans[i] << endl;
    }
}


Measured memory_bytes: 6240
s=input()
last='zyxwvutsrqponmlkjihgfedcba'
if s==last:print(-1);exit()
d={c for c in s}
lest={c for c in last}-d
if len(lest)>0:print(s+sorted(lest)[0]);exit()
m=[s[-1]]
for i in range(25)[::-1]:
  for n in sorted(m):
    if s[i]<n:print(s[:i]+n);exit()
  m+=[s[i]]

Measured memory_bytes: 3064
H,W=gets.chomp.split(" ").map(&:to_i)
MEMO=Array.new(H*W,0)
MAP=[]
H.times do
    s=gets.chomp
    MAP.push(s)
end
counts=Array.new(W,0)
H.times do |h|
    count=0
    W.times do |w|
        if MAP[h][w]=="."
            count+=1
            counts[w]+=1
        else
            if count > 0
              count.times do |c|
                  MEMO[h*W+w-1-c]+=count
              end
            end
            count=0
            if counts[w] > 0
                counts[w].times do |c|
                    MEMO[(h-1-c)*W+w]+=counts[w]
                end
            end
            counts[w]=0
        end
    end
    if count > 0
        count.times do |c|
            MEMO[h*W+W-1-c]+=count
        end
    end
end
W.times do |w|
    if counts[w] > 0
        counts[w].times do |c|
            MEMO[(H-1-c)*W+w]+=counts[w]
        end
    end
end
ret=0
MEMO.each do |m|
  ret=m if ret < m
end
puts ret-1


Measured memory_bytes: 53616
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] monsters = new int[n + 1];
		for (int i = 0; i <= n; i++) {
		    monsters[i] = sc.nextInt();
		}
		int remain = 0;
		long total = 0;
		for (int i = 0; i < n; i++) {
		    int x = sc.nextInt();
		    total += Math.min(remain, monsters[i]);
		    monsters[i] = Math.max(monsters[i] - remain, 0);
		    total += Math.min(x, monsters[i]);
		    remain = Math.max(x - monsters[i], 0);
		}
		total += Math.min(remain, monsters[n]);
		System.out.println(total);
   }
}


Measured memory_bytes: 64784
#[allow(unused_imports)]
use std::cmp;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    #[allow(unused_mut)]
    let mut s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

macro_rules! input_inner {
  ($iter:expr) => {};
  ($iter:expr, ) => {};

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

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
    ( $(read_value!($iter, $t)),* )
  };

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

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

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

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

fn main() {
  input! {
    n: usize,
    c: usize,
    d: [[i64; c]; c],
    field: [[usize1; n]; n],
  }
  let mut pop = vec![vec![0; 3]; c];
  for i in 0 .. n {
    for j in 0 .. n {
      pop[field[i][j]][(i + j) % 3] += 1;
    }
  }
  let mut ans = 1i64 << 60;
  for c0 in 0 .. c {
    for c1 in 0 .. c {
      if c1 == c0 {
        continue;
      }
      for c2 in 0 .. c {
        if c2 == c0 || c2 == c1 {
          continue;
        }
        let mut cost = 0;
        for old_color in 0 .. c {
          cost += d[old_color][c0] * pop[old_color][0] + d[old_color][c1] * pop[old_color][1] + d[old_color][c2] * pop[old_color][2];
        }
        ans = cmp::min(ans, cost)
      }
    }
  }

  println!("{}", ans);
}


Measured memory_bytes: 6396
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

struct Union_Find {
	vector<int> rank, par;
	int independent_tree;
	int N;

	Union_Find(int n) {
		N = n;
		for (int i = 0; i < N; i++)rank.push_back(1), par.push_back(i);
		independent_tree = N;
	}

	int getroot(int X) {
		if (par[X] == X)return X;
		return par[X] = getroot(par[X]);
	}

	bool issame(int A, int B) {
		return getroot(A) == getroot(B);
	}

	void unite(int A, int B) {
		A = getroot(A), B = getroot(B);
		independent_tree--;
		if (A == B)return;
		if (rank[A] > rank[B]) {
			par[B] = A;
		}
		else if (rank[A] == rank[B]) {
			par[B] = A;
			rank[A]++;
		}
		else {
			par[A] = B;
		}
	}

};

int main() {
	int N, K, L;
	cin >> N >> K >> L;
	Union_Find uf1(N), uf2(N);
	for (int i = 0; i < K; i++) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		uf1.unite(a, b);
	}
	for (int i = 0; i < L; i++) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		uf2.unite(a, b);
	}

	map<P, int> Map;
	for (int i = 0; i < N; i++) {
		Map[P(uf1.getroot(i), uf2.getroot(i))]++;
	}
	for (int i = 0; i < N; i++) {
		cout << Map[P(uf1.getroot(i), uf2.getroot(i))] << " ";
	}
	cout << endl;
	return 0;
}

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

int main(){
  int n;
  int a[100];
  
  cin >> n;

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

  cout << a[n-1];
  
  for(int i=n-2;i>=0;i--){
    cout << " " << a[i];
  }

  cout << endl;
  
  return 0;
}

Measured memory_bytes: 1160
import math
a, b, h, m = map(int, input().split())
c = abs((h+(m/60))*30 - m*6)
c = min(c, 360-c)
ans_2 = a**2 + b**2 - 2*a*b*math.cos(math.radians(c))
# print(c, math.radians(c))
print(ans_2**(1/2))

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

int main() {
    int h, w;
    scanf("%d %d", &h, &w);
    char a[h][w];
    bool hflag[h];
    fill(hflag, hflag+h, false);
    bool wflag[w];
    fill(wflag, wflag+w, false);
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            scanf("\n%c", &a[i][j]);
            if (a[i][j] == '#') {
                hflag[i] = true;
                wflag[j] = true;
            }
        }
    }
    for (int i = 0; i < h; i++) {
        if (!hflag[i])
            continue;
        for (int j = 0; j < w; j++) {
            if (!wflag[j])
                continue;
            printf("%c", a[i][j]);
        }
        printf("\n");
    }
    return 0;
}


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

typedef long long ll;

ll mod=1e9+7;

ll gcd(ll n,ll m){
    if(m==0) return n;
    else return gcd(m,n%m);
}

ll lcm(ll n,ll m){
    return n/gcd(n,m)*m;
}

bool is_prime(ll n){
    if(n==1) return false;
    else{
        bool ans=true;
        for(ll i=2;i*i<=n;i++){
            if(n%i==0) ans=false;
        }
        return ans;
    }
}

string by_x(ll n,ll x){
    string ans="";
    while(n>0){
        char c=n%x+'0';
        ans=c+ans;
        n/=x;
    }
    return ans;
}

ll order(ll n,ll p){
    ll ans=0;
    while(n%p==0){
        ans++;
        n/=p;
    }
    return ans;
}

//UnionFind
//配列の要素数とかは適宜変える

int parent[100010];
int t_rank[100010];

void init(int n){
    for(int i=0;i<n;i++){
        parent[i]=i;
        t_rank[i]=0;
    }
}

int find(int x){
    if(parent[x]==x) return x;
    else return parent[x]=find(parent[x]);
}

void unite(int x,int y){
    x=find(x);
    y=find(y);
    if(x==y) return;
    if(t_rank[x]<t_rank[y]) parent[x]=y;
    else{
        parent[y]=x;
        if(t_rank[x]==t_rank[y]) t_rank[x]++;
    }
}

//mod演算
//ここも配列の要素数とかは適宜変える

void change_mod(ll n){
    mod=n;
}

ll fac[300010];

ll modinv(ll a){
    ll b=mod,u=1,v=0;
    while(b){
        ll t=a/b;
        a-=t*b; swap(a,b);
        u-=t*v; swap(u,v);
        }
        u%=mod;
        if(u<0) u+=mod;
    return u;
}

void modfac(){
    fac[0]=1;
    for(ll i=1;i<300010;i++){
        fac[i]=(fac[i-1]*i)%mod;
    }
}

ll modperm(ll n,ll k){
    if(n<0||k<0||n<k) return 0;
    else return (fac[n]*modinv(fac[n-k]))%mod;
}

ll modcomb(ll n,ll k){
    if(n<0||k<0||n<k) return 0;
    else return ((fac[n]*modinv(fac[k]))%mod*modinv(fac[n-k]))%mod;
}

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    cout << c/a*b << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 100005
#define int long long
using namespace std;
int n,m,a[N],cnt[N],tot,prer[N],prel[N];
char c[N];
bool b[N];
signed main(){
	scanf("%s",c+1);
	n=strlen(c+1);
	for(int i=2;i<=n;i++)
		if(c[i-1]=='R')prer[i]=i-1;
		else prer[i]=prer[i-1];
	for(int i=n-1;i>=1;i--)
		if(c[i+1]=='L')prel[i]=i+1;
		else prel[i]=prel[i+1];
	for(int i=1;i<=n;i++){
		int t;
		if(c[i]=='L')t=prer[i];
		else t=prel[i];
		int dis=abs(t-i);
		if(c[i]=='L'){
			if(dis&1)cnt[t+1]++;
			else cnt[t]++;
		}
		else{
			if(dis&1)cnt[t-1]++;
			else cnt[t]++;
		}
	}
	for(int i=1;i<n;i++)printf("%lld ",cnt[i]);printf("%lld\n",cnt[n]);
	return 0;
}

Measured memory_bytes: 2944
a,b,c=gets.split.map(&:to_i)
h = {[a,b,c] => true}

count = 0

until a.odd? || b.odd? || c.odd? do
  ha = a / 2
  hb = b / 2
  hc = c / 2

  a = hb + hc
  b = ha + hc
  c = ha + hb

  if h[[a,b,c]]
    puts -1
    exit 0
  end

  h[[a,b,c]] = true

  count += 1
end

puts count

Measured memory_bytes: 1788
import java.util.Scanner;

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

		int A = scan.nextInt();
		int B = scan.nextInt();
		int C= scan.nextInt();
		int [] haiku = {A,B,C};
		int temp = 0;

		for(int i = 0; i<3 ; i++ ) {
			for(int j=0 ; j<3 ; j++) {
				if(haiku[i]<haiku[j]) {
					temp=haiku[i];
					haiku[i]=haiku[j];
					haiku[j]=temp;
				}
			}
		}
		if(haiku[0]==5 && haiku[1]==5 && haiku[2]==7) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}

		scan.close();


	}

}


Measured memory_bytes: 21972
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

class Main{
	
    public static void main(String[] args) throws IOException{
        final PrintWriter out = new PrintWriter(System.out);
        final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        final int n = Integer.parseInt(br.readLine());
        final String[] bCard = br.readLine().split(" ");
        final String[] sCard = bCard.clone();
        
        bubbleSort(bCard);
        out.print(bCard[0]);
        for(int i = 1; i<n; i++){
            out.print(' ');
            out.print(bCard[i]);
        }
        out.println();
        out.println("Stable");
        stableSort(sCard);
        out.print(sCard[0]);
        for(int i = 1; i<n; i++){
            out.print(' ');
            out.print(sCard[i]);
        }
        out.println();
        out.println(isSame(bCard, sCard) ? "Stable" : "Not stable");
        out.flush();
    }
    
    public static void bubbleSort(String[] a){
        final int n = a.length;
        for(int i = 0; i<n; i++){
            for(int j = n-1; j>i; j--){
                if(a[j].charAt(1)<a[j-1].charAt(1)){
                    final String t = a[j];
                    a[j] = a[j-1];
                    a[j-1] = t;
                }
            }
        }
 
    }
    
    public static void stableSort(String[] a){
        final int n = a.length;
        for(int i = 0; i<n; i++){
            int mini = i;
            for(int j = i+1; j<n; j++){
                if(a[j].charAt(1)<a[mini].charAt(1)) mini = j;
            }
            if(i!=mini){
                final String t = a[i];
                a[i] = a[mini];
                a[mini] = t;
            }
        }
    }
    
    public static boolean isSame(String[] a, String[] b){
        if(a.length!=b.length) return false;
        final int n = a.length;
        for(int i = 0; i<n; i++){
            if(a[i]!=b[i]) return false;
        }
        return true;
    }
}

Measured memory_bytes: 24408
/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
If I'm the sun, you're the moon
Because when I go up, you go down
*******************************
I'm working for the day I will surpass you
https://www.a2oj.com/Ladder16.html
*/
import java.util.*;
import java.io.*;
import java.math.*;

   public class Main
   {
      public static void main(String omkar[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));  
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         int M = Integer.parseInt(st.nextToken());
         System.out.println(N*(N-1)/2+M*(M-1)/2);
      }
   }

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

const long long MOD = 1000000007;
const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

// int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1}, dy[8] = {-1, 0, 1, 1, -1, 1, 0, -1};

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll X;
  cin >> X;
  for (ll A = -200; A <= 200; A++)
  {
    for (ll B = -200; B <= 200; B++)
    {
      ll tmp = pow(A, 5) - pow(B, 5);
      if (X == tmp)
      {
        cout << A << " " << B << endl;
        return 0;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 4052
n=int(input())
s=list(map(int,input().split()))
swap=0

def bubble_sort(A,N,swap):
    flag=True
    while flag:
        flag=False
        for j in range(N-1,0,-1):
            if A[j]<A[j-1]:
                temp=A[j]
                A[j]=A[j-1]
                A[j-1]=temp
                swap+=1
                flag=True
    return A,swap

Rst,swap=bubble_sort(s,n,swap)

print(Rst[0],end='',sep='')
for i in range(1,n):
    print(" ",Rst[i],end='',sep='')
print()
print(swap)



Measured memory_bytes: 5628
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include <utility>
#include <complex>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <algorithm>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef complex<ld> compd;
#define rep(i,n)	for(int i=0;i<n;i++)
#define srep(i,a,n)	for(int i=a;i<n;i++)
#define REP(i,n)	for(int i=0;i<=n;i++)
#define SREP(i,a,n)	for(int i=a;i<=n;i++)
#define rrep(i,n)	for(int i=n-1;i>=0;i--)
#define RREP(i,n)	for(int i=n;i>=0;i--)
#define all(a)	(a).begin(),(a).end()
#define mp(a,b)	make_pair(a,b)
#define mt	make_tuple
#define fst	first
#define scn second
#define bicnt(x)	__buildin__popcount(x)
#define debug(x)	cout<<"debug: "<<x<<endl
#define DEBUG 0

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;
const ld eps = 1e-9;
const int dx[] = { 0,1,0,-1 };
const int dy[] = { 1,0,-1,0 };

int ne[200010][26];
int dp[200010];

int main() {
	string s;	cin >> s;
	int n = s.size();
	REP(i, n)	rep(j, 26)	ne[i][j] = n;
	rrep(i, n) {
		ne[i][s[i] - 'a'] = i;
		rep(j, 26) {
			ne[i][j] = min(ne[i][j], ne[i + 1][j]);
		}
	}
	rep(i, n)	dp[i] = n;
	rrep(i, n) {
		rep(j, 26)	dp[i] = min(dp[i], dp[ne[i + 1][j]] + 1);
	}
	string t = "";
	int pos = 0;
	int val = n;
	rep(i, 26)	if (val > dp[ne[0][i]] + 1) {
		t = 'a' + i;
		val = dp[ne[0][i]] + 1;
		pos = ne[0][i];
	}
	while (pos < n) {
		rep(i, 26)	if (dp[pos] == dp[ne[pos + 1][i]] + 1) {
			t += 'a' + i;
			pos = ne[pos + 1][i];
			break;
		}
	}
	cout << t << endl;
	return 0;
}

Measured memory_bytes: 21636
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var (X, Y) = Slice2<char>();
            if (X < Y)
                WriteLine("<");
            else if (Y < X)
                WriteLine(">");
            else
                WriteLine("=");
        }

        static long Mod = (long)1e9 + 7;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
    }
}

Measured memory_bytes: 25880
import sys
import itertools
input = sys.stdin.readline
sys.setrecursionlimit(100000)


def read_values():
    return map(int, input().split())


def read_index():
    return map(lambda x: x - 1, map(int, input().split()))


def read_list():
    return list(read_values())


def read_lists(N):
    return [read_list() for n in range(N)]


def functional(N, mod):
    F = [1] * (N + 1)
    for i in range(N):
        F[i + 1] = (i + 1) * F[i] % mod
    return F


def main():
    H, W = read_values()
    if H == 1 or W == 1:
        print(1)
    else:
        print((H * W + 1) // 2)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
from itertools import groupby
import sys
 
input = lambda: sys.stdin.readline().strip()
 
 
def main():
 
    S = input()
    K = int(input())
    a = [len(tuple(s)) for _, s in groupby(S)]
    ans = 0
 
    if S[0] == S[-1] and K > 1:
        if len(a) == 1:
            ans = a[0] * K // 2
        else:
            ans = a[0] // 2 + a[-1] // 2 + (a[0] + a[-1]) // 2 * (K - 1)
            ans += sum(n // 2 for n in a[1:-1]) * K
 
    else:
        ans += sum(n // 2 for n in a) * K
 
    print(ans)
 
 
if __name__ == "__main__":
    main()

Measured memory_bytes: 62240
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
#define D10 fixed<<setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-10;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/
vi t, m;
int T, N, dp[111][33];

int solve(int i, int j) 
{
	j %= T;
	if (i == 110) return 0;
	if (dp[i][j] >= 0) return dp[i][j];
	int res;
	if (t[j] > m[i]) res = solve(i + 1, 1) + 1;
	else res = min(solve(i + 1, 1) + 1, solve(i + 1, j + 1));
	return dp[i][j] = res;
}

int main()
{
	while (cin >> T, T)
	{
		t.clear(), m.clear();
		MS(dp, -1);
		REP(i, T)
		{
			int a; cin >> a;
			a--;
			t.push_back(a);
		}
		cin >> N;
		m.resize(111, INF);
		REP(i, N) 
		{
			int a, b; cin >> a >> b;
			a--; b--;
			chmin(m[a], b);
		}
		cout << solve(0, 0) << endl;
	}
	return 0;
}

Measured memory_bytes: 3056
// ######      ###      #######    #######    ##     #     #####        ###     ##### //
// #     #    #   #          #        #       # #    #    #     #      #   #     ###  //
// #     #   #     #        #         #       #  #   #   #       #    #     #    ###  //
// ######   #########      #          #       #   #  #   #           #########    #   //
// #     #  #       #     #           #       #    # #   #    ####   #       #    #   //
// #     #  #       #    #            #       #     ##   #    #  #   #       #        //
// ######   #       #   #######    #######    #      #    #####  #   #       #    #   //

// #pragma GCC optimize(2)
// #pragma GCC optimize(3)
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
// #pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> ppl;
#define ain(a,n) for(ll i=0;i<(n);++i)	cin>>(a)[i];
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define loop(i,n) for(ll i=0;i<(n);++i)
#define FOR(i,a,b) for(ll i=(a);i<=(b);++i)
#define FORD(i,a,b) for(ll i=(a);i>=(b);--i)
#define cases ll T=0;cin>>T;while(T--)
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define END "\n"
#define pb push_back
#define mp make_pair
#define go(c,itr) for(auto itr=(c).begin(); itr!=(c).end(); ++itr)
// #define back(c,itr) for(auto itr=(c).rbegin(); itr!=(c).rend(); ++itr)
#define PI 3.14159265359
#define inf 9e18
#define MOD 1000000007
#define MODU 998244353
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define MAXN 100005
#define BLOCK 555
const string alpha = "abcdefghijklmnopqrstuvwxyz";
const ll N = 200005;
const long double epsilon = 1e-9;
inline ll myceil(ll a, ll b) { if (a % b == 0)	return (a / b);	return (a / b + 1);}
inline ll binlen(ll n) {
	ll c = 0;
	while (n > 0)
		++c , n /= 2;
	return c;
}
ll binexp(ll a, ll b, ll m) {
	a %= m;
	ll res = 1;
	while (b > 0) {
		if (b & 1)
			res = res * a % m;
		a = a * a % m;
		b >>= 1;
	}
	return res;
}
ll modinvfermat(ll a, ll m)
{
	return binexp(a, m - 2, m);
}
void task(bool flag)
{
	if (flag)
		cout << "YES\n";
	else
		cout << "NO\n";
}
ll lcm(ll a, ll b)
{
	return ((1LL * a * b) / (__gcd(a, b)));
}

signed main() {
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif
	fast
	ll n;
	cin >> n;
	vl a(n);
	ain(a, n);
	ll ans = 0, prev = 0;
	loop(i, n)
	{
		if (a[i] < prev)
			ans += prev - a[i];
		else
			prev = max(prev, a[i]);
	}
	cout << ans << END;


// #ifndef ONLINE_JUDGE
// 	cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
// #endif
	return 0;
}

Measured memory_bytes: 4780
#include<iostream>
#include<cstdio>
#include<ios>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<string>
#include<list>
#include<utility>
#include<tuple>
#include<map>
#include<unordered_map>
#include<complex>
using namespace std;
typedef long long llong;
llong gcd(llong a, llong b) {
	if (a < b) std::swap(a, b);
	if (a % b == 0) return b;
	else return gcd(b, a % b);
}
llong lcm(llong a, llong b) {
	llong g = gcd(a, b);
	return a * b / g;
}
//ここまで共通

int A, B, C;
int main() {
	cin >> A >> B >> C;
	if (C - (A - B) >= 0) cout << C - (A - B);
	else cout << 0;
}

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

long long GCD(long long a, long long b) 
{ 
    if(b==0) 
        return a; 
    return GCD(b, a%b);  
      
}

long long LCM(long long a, long long b)
{
    long long gcd=GCD(a,b);
     return (a*b)/gcd;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    long long i, j, k, n, m, t, x, y, z, s=9999, c=999999999999, l;
    cin >> n >> t;
    while(n--)
    {
        cin >> x >> y;
        if(y<=t && x<s)
            s=x;
    }
    if(s!=9999)
        cout << s << endl;
    else 
        cout << "TLE\n";
}


Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <vector>
#include <complex>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <stack>
#include <cmath>
#include <iomanip>
#include <sstream>

using namespace std;

typedef long long ll;
typedef ll li;
typedef pair<int,int> PI;

#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define REP(i,m,n) for(int i=m; i<=(int)(n); ++i)
#define F first
#define S second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int)((a).size())
#define ALL(a) a.begin(),a.end()
#define FOR(it,a) for(__typeof(a.begin())it=a.begin();it!=a.end();++it)
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,-1,1,1,-1};


int n,m,a,b,c,t;
int S[50];

typedef vector<vector<int> > mat;

mat matmul(mat a,mat b){
  mat c(n,vector<int>(n,0));
  rep(i,n) rep(j,n) rep(k,n)
    c[i][j] = (c[i][j] + a[i][k] * b[k][j]) % m;
  return c;
}

mat matpow(mat a,int ex){
  mat ret(n,vector<int>(n,0));
  rep(i,n) ret[i][i] = 1;
  mat base(a);

  while(ex){
    if(ex&1) ret = matmul(ret,base);
    base=matmul(base,base);
    ex>>=1;
  }
  return ret;
}

void solve(){
  rep(i,n) cin >> S[i];
  mat abc(n,vector<int>(n));
  rep(i,n){
    if(i) abc[i][i-1]=a;
    abc[i][i]=b;
    if(i+1<n) abc[i][i+1]=c;
  }

  abc = matpow(abc,t);

  vector<int> ans(n,0);
  
  rep(i,n)rep(j,n)
    ans[i] = (ans[i] + abc[i][j] * S[j]) % m;
  rep(i,n){
    if(i) cout << ' ';
    cout << ans[i];
  }
  cout << endl;

}
  

main(){
  while(cin >> n >> m >> a >> b >> c >> t,n)
    solve();
}

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

int n, m;
vector<pair<int, int>> u, v;
map<pair<int, int>, int> mp;

int main()
{
    cin >> n >> m;
    for (int i = 0; i < m; i++)
    {
        int p, y;
        cin >> p >> y;
        pair<int, int> a = make_pair(p, y);
        u.push_back(a);
        v.push_back(a);
    }
    sort(u.begin(), u.end());
    int f = 0, s = 0;
    for (int i = 0; i < m; i++)
    {
        pair<int, int> a = u[i];
        if (f != a.first)
            f = a.first, s = 0;
        s++;
        mp[a] = s;
    }
    for (int i = 0; i < m; i++)
    {
        pair<int, int> a = v[i];
        printf("%06d%06d\n", a.first, mp[a]);
    }
}

Measured memory_bytes: 9324
#include <iostream>
#include <map>
#include <cmath>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <cstring>
using namespace std;

int main() {
	int M, D;
	cin >> M >> D;
	int ans = 0, d1, d10;
	for (int i = 4; i <= M; i++) {
		for (int j = 22; j <= D; j++) {
			d1 = j - (j / 10) * 10;
			d10 = j / 10;
			if (d1 >= 2 && d10 >= 2 && d1 * d10 == i) ans++;
		}
	}

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

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int N;
vector<int> Ls;

int main()
{

  cin >> N;

  Ls.reserve(2*N);
  for (int i=0; i<2*N; ++i) {
    int l;
    cin >> l;
    Ls.push_back(l);
  }

  sort(Ls.begin(), Ls.end());

  int ret=0;
  for (int i=0; i<2*N; i+=2) {
    ret += Ls[i];
  }

  cout << ret << endl;

  return 0;

}


Measured memory_bytes: 256
/// Thank you tanakh!!!
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

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

fn next(v: (i64, i64)) -> (i64, i64) {
    let (x, y) = v;
    (-y, x)
}

fn main() {
    input!(x1: i64, y1: i64, x2: i64, y2: i64);
    let v = (x2 - x1, y2 - y1);
    let (x, y) = next(v);
    let (x3, y3) = (x2 + x, y2 + y);
    let (x, y) = next((x, y));
    let (x4, y4) = (x3 + x, y3 + y);
    println!("{} {} {} {}", x3, y3, x4, y4);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);  
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i = 0; i < n; i++) {
		cin >> a[i];
		a[i] -= i + 1;
	}
	sort(a.begin(), a.end());
	if(n & 1) {
		int med = a[n / 2];
		long long ans = 0;
		for(int i = 0; i < n; i++) {
			ans += abs(med - a[i]);
		}
		cout << ans << endl;
	} else {
		int med[2];
		for(int i = 0; i < 2; i++) {
			med[i] = a[n / 2 - i];
		}
		long long ans[2] = {0LL};
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < 2; j++) {
				ans[j] += abs(a[i] - med[j]);
			}
		}
		cout << min(ans[0], ans[1]) << endl;
	}
	return 0;
}

Measured memory_bytes: 1024
unittest
{
	assert( [ "5 3", "-30 -10 10 20 50" ].parse.expand.solve == 40 );
	assert( [ "3 2", "10 20 30" ].parse.expand.solve == 20 );
	assert( [ "1 1", "0" ].parse.expand.solve == 0 );
	assert( [ "8 5", "-9 -7 -4 -3 1 2 3 4" ].parse.expand.solve == 10 );
}



import std.algorithm;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto nk = input.front.split.to!( long[] );
	input.popFront;
	auto xs = input.front.split.to!( long[] );
	
	return tuple( nk[ 1 ], xs );
}

auto solve( long k, long[] xs )
{
	auto d = long.max;
	
	// 連続したロウソクK本を取るパターンを全検索
	for( auto i = 0; i + k <= xs.length; i++ )
	{
		auto ss = xs[ i .. i + k ];
		
		// 全ロウソク間の距離
		auto dm = ( ss[ 0 ] - ss[ $ - 1 ] ).abs;
		
		// 座標 0 から端のロウソクまでの距離
		auto db = min( ss[ 0 ].abs, ss[ $ - 1 ].abs );
		
		// 最短距離を取る
		d = min( d, dm + db );
	}
	
	return d;
}


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

int main()
{
    int n; std::cin >> n;
    std::vector<int> v(n);
    for (int i = 0; i < n; i++)
    {
        std::cin >> v[i];
    }
    int cnt = 0;
    for (int i = 1; i < n-1; i++)
    {
        if (((v[i - 1] < v[i]) && (v[i] <= v[i + 1])) || ((v[i - 1] >= v[i]) && (v[i] > v[i + 1])))
        {
            cnt++;
        }
    }
    std::cout << cnt << std::endl;
    return 0;
}


Measured memory_bytes: 256
import math

N, M = map(int, input().split(' '))

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
cnt = 0

if N > 1:
    cnt += combinations_count(N, 2)
if M > 1:
    cnt += combinations_count(M, 2)

print(cnt)

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

int main() {
    ll n;
    cin >> n;
    vector<ll> h(n);
    rep(i,n) cin >> h[i];
    ll ans = 0;
    rep(i,n) {
        ll t = 0;
        for(ll j = i+1; j < n; j++) {
            if (h[j-1] < h[j]) break;
            ++t;
        }
        ans = max(ans, t);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4040
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, N) for (int i = 0; i < (N); ++i)
#define rep2(i, a, b) for (ll i = a; i <= b; ++i)
#define rep3(i, a, b) for (ll i = a; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(c) begin(c), end(c)
#define ok() puts(ok ? "Yes" : "No");
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using ii = pair<int, int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using gt = greater<int>;
using minq = priority_queue<int, vector<int>, gt>;
using P = pair<ll, ll>;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
// clang++ -std=c++11 -stdlib=libc++

int main() {
  int N;
  cin >> N;
  vi p(N);
  rep(i, N) cin >> p[i];
  sort(p.rbegin(), p.rend());
  ll ans = 0;
  rep(i, N) {
    if (i == 0) {
      ans += p[i] / 2;
    } else
      ans += p[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3508
#include <bits/stdc++.h>
#define int long long
using namespace std;
int gcd(int a, int b)
{
    if (a < b)
        return gcd(b, a);
    else if (a % b)
        return gcd(b, a % b);
    else
        return b;
}
main()
{
    int n;
    cin >> n;
    int a[n];
    int u[n],v[n];
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
  	sort(a,a+n);
    int x = a[0], y = a[n-1];
    for (int i = 0; i < n; i++)
    {
       u[i]=gcd(x,a[i]);
       v[i]=gcd(y,a[i]);
    }
    sort(u,u+n);
    reverse(u,u+n);
    sort(v,v+n);
    reverse(v,v+n);
    int s = u[0], t = v[0];
    for (int i = 0; i < n - 1; i++)
    {
        s = gcd(s, u[i]);
        t = gcd(t, v[i]);
    }
    cout << max(s, t) << endl;
}


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

int n, k;
int w[100000];

int getMin(int max) {
  int kk = k;
  int sum = 0;
  for (int i = 0; i < n; i++) {
    if (sum + w[i] > max) {
      kk--;
      if (kk == 0) return false;
      sum = w[i];
    } else {
      sum += w[i];
    }
  }
  return true;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int max = 0;
  int sum = 0;

  cin >> n >> k;

  for (int i = 0; i < n; i++) {
    cin >> w[i];
    if (w[i] > max) max = w[i];
    sum += w[i];
  }

  int left = max;
  int right = sum;
  int mid;
  bool prev_result;
  while (true) {
    mid = (left + right) / 2;
    if (getMin(mid)) {
      if (right - left <= 1) {
        if (prev_result) {
          cout << right << endl;
        } else {
          cout << left << endl;
        }
        break;
      }
      right = mid;
    } else {
      if (right - left <= 1) {
        if (prev_result) {
          cout << left << endl;
        } else {
          cout << right << endl;
        }
        break;
      }
      left = mid + 1;
    }
  }

  return 0;
}

Measured memory_bytes: 1584
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

constexpr ll mod = 1e9 + 7;

template <typename T> inline bool chmax(T &a, const T b) {
    if(a >= b) return false;
    a = b;
    return true;
}
template <typename T> inline bool chmin(T &a, const T b) {
    if(a <= b) return false;
    a = b;
    return true;
}

/*-------------------------------------------*/

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

    int K, X, Y;
    cin >> K >> X >> Y;

    if(abs(X) + abs(Y) == K) {
        cout << "1\n" << X << " " << Y << endl;
        return 0;
    }

    int xsign = 1, ysign = 1;
    bool sw = false;
    if(X < 0) {
        X *= -1;
        xsign = -1;
    }
    if(Y < 0) {
        Y *= -1;
        ysign = -1;
    }
    if(X < Y) {
        swap(X, Y);
        sw = true;
    }

    int D = X + Y;
    int n = max(2, (D + K - 1) / K);

    if((n * K - D) % 2) {
        if(K % 2) {
            n++;
        } else {
            cout << -1 << endl;
            return 0;
        }
    }

    vector<pair<int, int>> ans;

    int R = (n * K - D) / 2;
    if(n == 3) {
        int b = R / 2;
        int a = R - b;
        for(int i = 1; i <= n; i++) {
            int l = i * K;
            if(l <= a) {
                ans.emplace_back(-l, 0);
            } else if(l <= a + Y + b) {
                l -= a;
                ans.emplace_back(-a, l);
            } else if(l <= a + Y + b + a + X) {
                l -= a + Y + b;
                ans.emplace_back(l - a, b + Y);
            } else {
                l -= a + Y + b + a + X;
                ans.emplace_back(X, Y + (b - l));
            }
        }
    } else {
        int a = R;
        for(int i = 1; i <= n; i++) {
            int l = i * K;
            if(l <= Y + a) {
                ans.emplace_back(0, l);
            } else if(l <= Y + a + X) {
                l -= Y + a;
                ans.emplace_back(l, Y + a);
            } else {
                l -= Y + a + X;
                ans.emplace_back(X, Y + (a - l));
            }
        }
    }

    if(sw)
        for(int i = 0; i < n; i++)
            swap(ans[i].first, ans[i].second);
    cout << n << endl;
    for(auto &p : ans) {
        cout << p.first * xsign << " " << p.second * ysign << endl;
    }

    return 0;
}

Measured memory_bytes: 3952