akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

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

    vector<long long> w(n);
    vector<int> t(n), x(n);
    for(int i=0; i<n; ++i)
        cin >> w[i] >> t[i] >> x[i];

    vector<int> y(q);
    for(int i=0; i<q; ++i)
        cin >> y[i];

    long long restore = 0; // 復旧度
    long long a = 1;
    long long b = 0;
    long long c = 0;
    multimap<int, pair<int, int> > close; // サービスによる手伝いの終了

    int id = 0; // 次に復旧させるサービスの番号
    int k = 0;  // 復旧度の問い合わせの番号

    vector<int> finishDay(n, -1); // サービスが復旧した日
    vector<long long> ret(q);     // 各問い合わせに対する復旧度

    for(int i=0; i<=3652425; ++i){
        if(k < q && y[k] == i){
            ret[k] = restore;
            ++ k;
        }

        while(id < n && restore >= w[id]){
            finishDay[id] = i;
            if(t[id] == 0){
                ++ a;
            }else if(t[id] == 1){
                ++ a;
                ++ b;
            }else{
                ++ a;
                b += 3;
                c += 2;
            }
            close.insert(make_pair(i+x[id], make_pair(t[id], x[id])));
            ++ id;
        }

        while(!close.empty() && close.begin()->first == i){
            int s = close.begin()->second.first;
            int t = close.begin()->second.second;
            close.erase(close.begin());
            if(s == 0){
                -- a;
            }else if(s == 1){
                a -= t + 1;
                -- b;
            }else{
                a -= (t + 1) * (t + 1);
                b -= t * 2 + 3;
                c -= 2;
            }
        }

        restore += a;
        a += b;
        b += c;
    }

    for(int i=0; i<n; ++i){
        if(finishDay[i] == -1)
            cout << "Many years later" << endl;
        else
            cout << finishDay[i] << endl;
    }
    for(int i=0; i<q; ++i)
        cout << ret[i] << endl;

    return 0;
}

Measured memory_bytes: 6800
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};


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


Measured memory_bytes: 256
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let w: Vec<char> = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().chars().collect()
    };

    let mut c = std::collections::HashMap::new();
    for &i in &w { *(c.entry(i).or_insert(0)) += 1; }
    let ans = if c.values().all(|&num| num % 2 == 0) { "Yes" } else { "No" };

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

Measured memory_bytes: 4476
l,n = map(int,input().split())

ll = l % 2019
ans = 2018
if l-n >= 672:
    ans = 0
else:
    for i in range(ll,ll + n-l +1):
        if i % 673 == 0:
            ans = 0
            break
        else:
            for j in range(ll,ll + n-l +1):
                if i != j:
                    ansss = i*j%2019
                    if ansss == 0:
                        ans = 0
                        break
                    elif ansss < ans:
                        ans = ansss

print(ans)


Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int ,int> pii;
typedef pair<ll ,ll> pll;
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(X) (X).begin(), (X).end()
#define sll(n) scanf("%lld",&n)
#define sll2(x,y) scanf("%lld%lld",&x,&y)
#define sll3(x,y,z) scanf("%lld%lld%lld",&x,&y,&z)
#define REP(i,x,y) for(ll i = x;i <= y;++i)
#define debug(x) cerr<<#x<<"::"<<x<<endl
#define debug2(x,y) cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n"
#define debug3(x,y,z) cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n"
#define debug4(x,y,z,w) cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\t"<<#w<<" :: "<<w<<"\n"
ll power(ll x,ll y,ll z) {
	ll ret = 1;
	while(y > 0) {
		if(y & 1) ret = (ret*x)%z;
		x = (x*x)%z;
		y >>= 1;
	}
	return ret;
}
const ll N = 1e5 + 5;
ll dp[N], A[N];
int main() {
	
	ll n;
	sll(n);
	REP(i,1,n) sll(A[i]);
	dp[2] = abs(A[2] - A[1]);
	REP(i,3,n) dp[i] = min(dp[i - 1] + abs(A[i] - A[i - 1]), dp[i - 2] + abs(A[i] - A[i - 2]));

	printf("%lld\n", dp[n]);

	return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>

int main()
{
    int x,y;
    scanf("%d %d",&x,&y);
    
    if(x<y){
        printf("%d",y+y-1);    
    }else if(y<x){
        printf("%d",x+x-1);
    }else if(x==y){
      printf("%d",x+y);
    }
    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 repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

ll modiro(ll x,ll y){
    vector<ll> vec(30);
    rep(i,30){
        vec[i] = y;
        y = y * y % 1000000007;
    }
    ll c = x;
    c = c * vec[0] % 1000000007;
    c = c * vec[2] % 1000000007;
    c = c * vec[9] % 1000000007;
    c = c * vec[11] % 1000000007;
    c = c * vec[14] % 1000000007;
    c = c * vec[15] % 1000000007;
    c = c * vec[17] % 1000000007;
    c = c * vec[19] % 1000000007;
    c = c * vec[20] % 1000000007;
    c = c * vec[23] % 1000000007;
    c = c * vec[24] % 1000000007;
    c = c * vec[25] % 1000000007;
    c = c * vec[27] % 1000000007;
    c = c * vec[28] % 1000000007;
    c = c * vec[29] % 1000000007;
    return c;
}

int main(){
    ll X,Y;
    cin >> X >> Y;
    if ((X + Y) % 3 != 0){
        cout << 0 << endl;
    }
    else if (X > Y * 2 || Y > X * 2){
        cout << 0 << endl;
    }
    else{
        ll x = (2 * X - Y) / 3;
        ll y = (2 * Y - X) / 3;
        ll a = 1;
        for (ll i = 1; i <= (X + Y) / 3; i++){
            a = (a * i) % 1000000007;
        }
        ll b = 1;
        for (ll i = 1; i <= x; i++){
            b = (b * i) % 1000000007;
        }
        ll c = 1;
        for (ll i = 1; i <= y; i++){
            c = (c * i) % 1000000007;
        }
        ll d;
        d = modiro(a,b);
        cout << modiro(d,c) << endl;
    }
}


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

typedef pair<int, int> pi;

int main(void) {
	vector<int> V;
	set<pi>  S;
	int a, b, c, ans;

	cin >> a >> b >> c;
	int mn = min(a, min(b, c));
	int mx = max(a, max(b, c));
	S.clear();
	S.insert(make_pair(mn, mx));
	V.resize(3);

	ans = 0;
	while (true) {
		if ((a % 2 != 0) || (b % 2 != 0) || (c % 2 != 0))
			break;
		V[0] = (b + c) / 2;
		V[1] = (c + a) / 2;
		V[2] = (a + b) / 2;
		sort(V.begin(), V.end());
		pair<set<pi>::iterator, bool> ret;
		ret = S.insert(make_pair(V[0], V[2]));
		if (!ret.second) {
			ans = -1;
			break;
		}
		a = V[0];	b = V[1];	c = V[2];
		++ans;
	}

	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	char a;
	cin >> a;
	if (a == 'a' || a == 'i' || a == 'u' || a == 'e' || a == 'o') {
		cout << "vowel" << endl;
	}
	else {
		cout << "consonant" << endl;
	}
	return 0;
}

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

#define M 1000000
#define L 14

int getChar(char); 
char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key % M; }
int h2(int key){ return 1 + (key % ( M - 1 )); }

int find(char str[]){
  long long key,i,h;
  key = getKey(str);
  for(i = 0 ;;i++){
    h = (h1(key) + i * h2(key)) % M;
    if(strcmp(H[h],str) == 0) return 1;
    else if(strlen(H[h]) == 0) return 0;
  }
  return 0;
}


int insert(char str[]){
  long long key,i,h;
  key = getKey(str);
  for(i = 0 ;; i++){
    h = (h1(key) + i * h2(key)) % M;
    if(strcmp(H[h],str) == 0) return 1;
    else if(strlen(H[h]) == 0){
      strcpy(H[h],str);
      return 0;
    }
  }
  return 0;
}

int main(){
  int i, n, h;
  char str[L], com[9];
  for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
  scanf("%d", &n);
    
  for ( i = 0; i < n; i++ ){
    scanf("%s %s", com, str);
	
    if ( com[0] == 'i' ){
      insert(str);
    } else {
      if (find(str)){
	printf("yes\n");
      } else {
	printf("no\n");
      }
    }
  }

  return 0;
}

Measured memory_bytes: 14280
//ll _(){
//    ll n;
//    cin >> n;
//    ll ans = 0;
//    ans += 2*(n/11);
//    n %= 11;
//    ans += n/6;
//    n %= 6;
//    if(n > 0){
//        ++ans;
//    }
//    return ans;
//}
//
//
//
#include <iomanip>
#include <vector>
#include <utility>
#include <iostream>
#include <string>
#define all(v) (v).begin(), (v).end()
#define T1 template<typename T> static
using namespace std;
typedef long long ll;
T1 ostream& operator<<(ostream& stream, const vector<T>& t);
T1 istream& read(T, T, istream& = cin);
ll _(){
    ll n;
    cin >> n;
    ll ans = 0;
    ans += 2*(n/11);
    n %= 11;
    ans += n/6;
    n %= 6;
    if(n > 0){
        ++ans;
    }
    return ans;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
        cout << _() << '\n';
}


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

using namespace std;
int main(int argc, char *argv[]) {
	int a, b, k;
	cin >> a >> b >> k;
	
	vector<int> divs;
	for (int i = 1; i <= min(a, b); i++) {
		if (a % i == 0 && b % i == 0) {
			divs.push_back(i);
		}
	}
	
	cout << divs[divs.size() - k] << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i32 = int32_t;
using i64 = int64_t;
constexpr char newl = '\n';

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
//#define F first
//#define S second
#define debug(x) cout << #x << ": " << x << '\n';

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N, M;
  cin >> N >> M;
  vector<int> H(N);
  F0R(i, N) {
    cin >> H[i];
  }

  vector<vector<int>> G(N, vector<int>());
  F0R(i, M) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  int result = 0;
  F0R(i, N) {
    bool good = true;

    for (auto e : G[i]) {
      if (H[i] <= H[e]) {
        good = false;
        break;
      }
    }

    if (good) result++;
  }
  cout << result;
}
#endif


Measured memory_bytes: 8744
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define P pair<ll,ll>
#define FOR(I,A,B) for(int I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))



vector<int> make_p(int x){
	vector<bool> isp(x+1,true);
	isp[0]=isp[1]=false;
	for(int i=2;i*i<=x;i++){
		if(isp[i]){
			for(int j=2*i;j<=x;j+=i){
				isp[j] = false;
			}
		}
	}
	vector<int> res;
	for(int i=2;i<=x;i++){
		if(isp[i])res.push_back(i);
	}
	return res;
}

int main(){
	auto so = make_p(1000000);
	int x;
	cin >> x;
	for(auto s:so){
		if(x<=s){
			cout << s << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 1020
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <climits>
#include <tuple>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <algorithm>
#define rep(i, n) for(Int (i) = 0; (i) < (n); (i)++)
#define debug(var) cout << #var << ": " << var << endl
using namespace std;
using Int = int64_t;
using Uint = uint64_t;
constexpr Uint mod = 1e9 + 7;
constexpr Int Int_max = LLONG_MAX;
constexpr Int Int_min = LLONG_MIN;
using Container = vector<Int>;
using Grid = vector<vector<char>>; // [y][x]


int main() {

	Int a, b; cin >> a >> b;
	string x, y;
	rep(i, b)x += to_string(a);
	rep(i, a)y += to_string(b);
	if (x < y)cout << x;
	else cout << y;

}

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

int main(){
  int H, W;
  cin >> H >> W;
  vector<vector<char>> vec(H, vector<char>(W));
  for(int i=0; i<H; ++i){
    for(int j=0; j<W; ++j){
      cin >> vec.at(i).at(j);
    }
  }
  
  vector<bool> yoko(H,false);
  for(int i=0; i<H; ++i){
    for(int j=0; j<W; ++j){
      if(vec.at(i).at(j)=='#') yoko.at(i)=true;
    }
  }
  vector<bool> tate(W,false);
  for(int j=0; j<W; ++j){
    for(int i=0; i<H; ++i){
      if(vec.at(i).at(j)=='#') tate.at(j)=true;
    }
  }
  
  for(int i=0; i<H; ++i){
    if(yoko.at(i)==false) continue;
    for(int j=0; j<W; ++j){
      if(tate.at(j)==false) continue;
      cout << vec.at(i).at(j);
    }
    cout << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#include <cmath>
using namespace std;
typedef long long ll;
ll n,s;
int main(int argc, char const *argv[])
{
	scanf("%lld%lld", &n,&s);
	ll b=1;
	for (b = 2; b*b <= n; ++b)
	{
		ll t=n;
		ll sum=0;
		while(t){
			sum+=t%b;
			t/=b;
		}
		if(sum==s){
			printf("%lld\n", b);
			return 0;
		}
	}
	if(n<s){
		printf("-1\n");
		return 0;
	}
	else if(n==s){
		printf("%lld\n", n+1);
		return 0;
	}
	ll i=1;
	for (i = 1; i*i <= n-s; ++i)
	{
		if((n-s)%i==0){
			ll b=i+1;
			ll a1=(n-s)/i,a0=s-a1;
			if(a1<b&&a0<b){
				printf("%lld\n",  b);
				return 0;
			}
		}
	}
	for ( ; i >= 1; --i)
	{
		if((n-s)%i==0){
			ll j=(n-s)/i;
			ll b=j+1;
			ll a1=(n-s)/j,a0=s-a1;
			if(a1<b&&a0<b&&a0>=0){
				// printf("%lld %lld\n", a0,a1);
				printf("%lld\n", b);
				return 0;
			}
		}
	}
	b=n-s+1;
	ll a1=1,a0=s-a1;
	if(a0<b&&a1<b){
		printf("%lld\n", b);
		return 0;
	}
	else printf("-1\n");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

const int N=110000;
ll x[N];

int main() {
    ll i, n, ans=0;
    scanf("%lld", &n);
    for(i=0; i<n; i++) {
        scanf("%lld", &x[i]);
        if(i && x[i] && x[i-1]) {
            ans++;
            x[i]--;
        }
        ans+=x[i]/2;
        x[i]%=2;
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i,a,b) for(int re i=a;i<b;++i)
#define drep(i,a,b) for(int re i=a;i>b;--i)
#define re register
#define ll long long
using namespace std;

inline
ll getint(ll &k){
	static ll num;
	static bool f;
	static char c;
	num=0;f=0;k=0;
	while(c=getchar(),!isdigit(c))if(c=='-')break;
	if(c=='-')f=1,c=getchar();
	while(isdigit(c))num=(num<<1)+(num<<3)+c-'0',k+=c-'0',c=getchar();
	return f?-num:num;
}

inline
void outint(ll a){
	if(a>9)outint(a/10);
	putchar(a%10+'0');
}
 
int main(){
	ll n,ans;
	n=getint(ans);
	puts(n%ans?"No":"Yes");
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
//#include <boost/multiprecision/cpp_int.hpp>
#include <climits>
#include <cmath>
#include <cstring>
#include <functional>
#include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <sstream>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
//namespace mp = boost::multiprecision;
using namespace std;
using ull = unsigned long long;
using ld = long double;
// using ll = boost::multiprecision::cpp_int;
using ll = long long;
#define FOR(i,N) for(ll i = 0; i < N; ++i)

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
// using int = ll;
ll gcd(ll m, ll n) {
    if(n == 0)
        return abs(m);
    return (gcd(n, m % n));
}
void putYN(bool b) {
    if(b) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}
void swap(ll &a, ll &b) {
    ll tmp = a;
    a = b;
    b = tmp;
}
ll combi(ll n, ll k) {
    ll r = 1, rr = 1;
    for(ll i = 0; i < k; ++i) {
        r *= (n - i);
        rr *= (i + 1);
        // r %= 1000000007;
        // rr %= 1000000007;
    }
    r /= rr;
    // r %= 1000000007;
    return r;
}

int main() {
    ll N;
    cin >> N;
    ll num = 0;
    FOR(i, N) { 
        ll tmp;
        cin >> tmp;
        if(i+1!=tmp){
            num++;
        }
    }
    if(num<=2){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 888
#include <utility>
#include <vector>
#include <iostream>
#include <algorithm>
#include <set>
#define REP(i,n) for(int i=0;i<n;i++)
typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
using namespace std;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int inf = 10000000;
vector<int> coins{1,6,9,36,81,216,729,1296,6561,7776,46656,59049};

int minChange(vector<int> value, int n){
  // dp[i] := i 円を払うお釣りの最小枚数
  vector<int> dp(n + 1, inf); // n + 1 個の inf (十分大きな値) で初期化
  dp[0] = 0;

  for(int i = 0; i <= n; ++i){
    for(int j = 0; j < value.size(); ++j){
      if(i - value[j] >= 0){                       // 配列の範囲外チェック
        dp[i] = min(dp[i - value[j]] + 1, dp[i]);  // i - value[j] 円払えるなら、それに value[j] 円を 1 枚足して i 円を払える
      }
    }
  }

  return dp[n];
}
int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
    int N;
    cin >> N;
    int ans = minChange(coins, N);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cmath>
#include <iomanip>

const int MAX_N = 8;
int N;
double x[MAX_N], y[MAX_N];

double df(double d, int i, int n, int cash){
   if(n==N) return d;

   double sum = 0;
   for(int j=0; j<N; ++j){
      if(cash&(1<<j)) continue;
      double d_add = d + sqrt((x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j]));
      cash |= (1<<j);
      sum += df(d_add, j, n+1, cash);
      cash &= ~(1<<j);
   }
   return sum;
}

int main(){
   std::cin >> N;
   for(int i=0; i<N; ++i) std::cin >> x[i] >> y[i];

   double ans = 0;
   for(int i=0; i<N; ++i){
      ans += df(0,i,1,(1<<i));
   }
   for(int i=1; i<=N; ++i) ans /= i;
   std::cout << std::fixed << std::setprecision(10) << ans << std::endl;
   return 0;
}


Measured memory_bytes: 256
eval"A,B,_,*I=#{`dd`.split*?,}
s,t=[A,B].map{|a|[-F=1e15,*I.shift(a),F]}
I.map{|x|p s[s#{a='.bsearch_index{|y|y>x}-1,2].map{|'}s|t[t#{a}t|[(s-x).abs,(t-x).abs].min+(t-s).abs}.min}.min}"

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

int main() {
    int n;
    cin >> n;
    int N = n;
    int f = 0;
    while(n > 0){
        f += n % 10;
        n /= 10;
    }
    if(N % f == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>	
#include <deque>
#include <set>
#include <climits>
#include <memory>
#include <numeric>
#include <utility>


#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 INF INT_MAX/2;
#define PI 3.14159265358979323846264338327950L;
const int INF2 = 1001001001;
typedef long long ll;
using namespace std;
using vi = vector<int>;
using vll = vector<ll>;
ll mod = 1e9 + 7;
//ll llmax = 10000000000000000000ll;
const ll LINF = 1e18 + 100;
using namespace std;
using Graph = vector<vector<int>>;



int cnt_digit(ll N)
{
	int digit = 0;

	while (N > 0)
	{
		N /= 10;
		digit++;
	}
	return digit;
}


 // 最大公約数計算
 
ll gcd(ll a, ll b)
{
	if (b == 0) {
		return a;
	}
	else {
		return gcd(b, a % b);
	}
}
// 最小公倍数の計算

ll lcm(ll a, ll b)
{
	ll g = gcd(a, b);

	return a / g * b;
}

struct union_find
{
	vector<int> par, r;
	union_find(int n)
	{
		par.resize(n);
		r.resize(n);
		init(n);
	}


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

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

	void unite(int x, int y)
	{
		x = find(x);
		y = find(y);

		if (r[x] < r[y])
		{
			par[x] = y;
		}
		else
		{
			par[y] = x;
			if (r[x] == r[y])
			{
				r[x]++;
			}
		}
	}
};

const int MAX_N = 110000;

int memo[MAX_N];

int rec(int n) {
	if (n == 0)return 0;
	if (memo[n] != -1)return memo[n];

	int res = n;

	for (int pow6 = 1; pow6 <= n; pow6 *= 6)res = min(res, rec(n - pow6) + 1);

	for (int pow9 = 1; pow9 <= n; pow9 *= 9)res = min(res, rec(n - pow9) + 1);

	return memo[n] = res;
}

int calc(int x) {
	int ret = 0;
	while (x % 2 == 0) {
		x /= 2;
		ret++;
	}

	return ret;
}

int a[12][12];
int D;
ll G;
vector<ll> P, C;

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

	int n,i;

	cin >> n >> i;

	cout << n + 1 - i << endl;
	/*
	ll x;
	ll y;

	bool goodx[110] = { false };
	bool goody[110] = {false};

	string board[110];

	cin >> x >> y;
	rep(i, 0, x) {
		cin >> board[i];
	}
	rep(i, 0, x) {
		rep(j, 0, y) {
			if (board[i][j] == '#') {
				goodx[i] = true;
				goody[j] = true;
			}
		}
	}
	rep(i, 0, x) {
		if (goodx[i] == true) {
			rep(j, 0, y) {
				if (goody[j]) {
					cout << board[i][j];
				}
			}
			cout << endl;
		}
	}*/
	
}
	

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int parity = k / 2;
        if (k % 2 == 0) {
            System.out.println(parity * parity);
            return;
        }
        System.out.println(parity * (parity + 1));
    }
}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(ll i = n;i >= 0;--i)
#define FOR(i,m,n) for(ll i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll modinv(ll a, ll m) {ll b = m, u = 1, v = 0;while (b) {ll t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}
const int INF = 1e9;
const ll LLINF = 1e16;

int main(void)
{
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll cnta = ceil((float)a / d);
    ll cntc = ceil((float)c / b);
    if(cnta >= cntc){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3676
//import java.util.Arrays;
//import java.util.Scanner;
//import java.util.ArrayList;
//import java.util.List;
import java.util.Scanner;

class Main {
    public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
    	String s1 = sc.next();
    	String s2 = sc.next();
    	String s3 = sc.next();
    	System.out.println(s1.substring(0,1).toUpperCase()+s2.substring(0,1).toUpperCase()+s3.substring(0,1).toUpperCase());
    }
}

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

int main(){
    int a,b,c,x,y;
    cin >> a >> b >> c >> x >> y;

    int ab = c * 2;

    long int aa = 0,bb = 0,ans = 0;

    int mm = min(x,y);

    bool ff = false;

    if(mm == x) ff = true;

    if(ab < a + b){
        ans += mm * ab;
    }else{
        ans += mm * (a + b);
    }

    if(ff){
        if(ab < b) ans += ab * (y - mm);
        else ans += b * (y - mm);
    }
    else{
        if(ab < a) ans += ab * (x - mm);
        else ans += a * (x - mm);
    }

    cout << ans << endl;
}

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

int n;
int a[22];

void dfs(int dep, int ma) {
	if(dep==n) {
		for(int i=0;i<n;i++) putchar(a[i]+'a');
		puts("");
		return;
	}
	
	for(int i=0;i<ma;i++) {
		a[dep] = i;
		dfs(dep+1, ma);
	}
	a[dep] = ma;
	dfs(dep+1, ma+1);
}

int main() {
	scanf("%d", &n);
	
	dfs(0, 0);
	
	return 0;
}

Measured memory_bytes: 1536
#include <iostream>
#include <cmath>
using namespace std;
#define MAX 1000000

int main(){
	bool p[MAX+1];
	int n, ans;

	for(int i=0 ; i<=MAX ; i++){
		p[i] = (i<=1)? false : true ;
	}

	for(int i=2 ; i<=sqrt(MAX)+1 ; i++){
		if(p[i]){
			for(int j=i*2 ; j<=MAX ; j+=i){
				p[j] = false;
			}
		}
	}

	while( cin >> n ){		
		ans = 0;
		for(int i=0 ; i<=n ; i++){
			if(p[i]){
				ans++;
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 2136
#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <stack>
#include <climits>
#include <deque>
#include <bitset>
#include <cassert>
#include <ctime>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
const int dy[]={-1,0,1,0},dx[]={0,1,0,-1};
// adjust problem by problem
const double EPS=1e-8;
const double PI=acos(-1.0);
#ifdef __GNUC__
int popcount(int n){return __builtin_popcount(n);}
int popcount(ll n){return __builtin_popcountll(n);}
#endif
#ifndef __GNUC__
template<class T> int popcount(T n){int cnt=0;while(n){if(n%2)cnt++;n/=2;}return cnt;}
#endif
template<class T>int SIZE(T a){return a.size();}
template<class T>string IntToString(T num){string res;stringstream ss;ss<<num;return ss.str();}
template<class T>T StringToInt(string str){T res=0;for(int i=0;i<SIZE(str);i++)res=(res*10+str[i]-'0');return res;}
template<class T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<class T>T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> void PrintSeq(T &a,int sz){for(int i=0;i<sz;i++){cout<<a[i];if(sz==i+1)cout<<endl;else cout<<' ';}}
bool EQ(double a,double b){return abs(a-b)<EPS;}
void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}
vector<string> split(string str,char del){
  vector<string> res;
  for(int i=0,s=0;i<SIZE(str);i++){
    if(str[i]==del){if(i-s!=0)res.push_back(str.substr(s,i-s));s=i+1;}
    else if(i==SIZE(str)-1){res.push_back(str.substr(s));}
  }
  return res;
}


int main(){

  int N;
  cin>>N;
  int res=0;
  for(int i=0;i<N;i++){
    ll S;
    cin>>S;
    S=2*S+1;
    int oddNum=0;
    bool ok=true;
    for(ll i=2;i*i<=S;i++){
      if(S%i==0){
        if(i%2==0){
          ok=false;
          break;
        }
        else{
          while(S%i==0){
            if(i%2)oddNum++;
            S/=i;
          }
        }
      }
      if(oddNum>=2)break;
    }
    if(!(ok&&oddNum))res++;
  }
  cout<<res<<endl;
  
  return 0;
}

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

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

  vector<int> A(N, 0);
  rep(i, N) cin >> A[i];

  int value = 0;
  value += abs(A[0]);
  for (int i = 0; i < N - 1; i++) {
    value += abs(A[i + 1] - A[i]);
  }
  value += abs(0 - A[N - 1]);

  cout << value - (abs(A[0]) + abs(A[1] - A[0])) + abs(A[1]) << endl;
  for (int i = 1; i < N - 1; i++) {
    cout << value - (abs(A[i] - A[i - 1]) + abs(A[i + 1] - A[i])) + abs(A[i + 1] - A[i - 1]) << endl;
  }
  cout << value - (abs(A[N - 1] - A[N - 2]) + abs(0 - A[N - 1])) + abs(0 - A[N - 2]) << endl;

}

Measured memory_bytes: 3776
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;

void main() {
  enum int modulo = 2019;
  int l, r;
  readf (" %d %d", &l, &r);
  if (r - l > 2020) {
    writeln (0);
  } else {
    long res = long.max;
    foreach (i; l .. r) {
      foreach (j; i + 1 .. r + 1) {
        res = min (res, (i.to!long * j) % modulo);
      }
    }
    writeln (res);
  }
}



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

typedef long long ll;
ll n, p, odd, even, ans;

ll cac[60][60];

ll ncr(ll a, ll b)
{
	if (b == 0) return 1;
	if (a == b) return 1;
	if (cac[a][b]) return cac[a][b];
	return cac[a][b]=ncr(a-1, b-1)+ncr(a-1, b);
}

int main()
{
	scanf("%lld%lld", &n, &p);
	for (int i = 0;i < n;i++)
	{
		int x; scanf("%d", &x);
		if (x&1) odd++;
		else even++;
	}
	for (int i = p;i <= odd;i+=2) ans += ncr(odd, i);
	ans *= (1ll<<even);
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
 
typedef vector<int> data;
 
vector<data> ans;
 
void make(data d, int n){
    if(n == 0){
        ans.push_back(d);
        return;
    }
    for(int i = 1;i <= n;i++){
        if(d.size() > 0 && i > d.back()) continue;
        data t = d;
        t.push_back(i);
        make(t, n - i);
    }
}
 
bool larger(const data &d1, const data &d2){
    for(int i = 0;i < d1.size() && i < d2.size();i++){
        if(d1[i] > d2[i]) return true;
        if(d1[i] < d2[i]) return false;
    }
    return false;
}
 
int main(){
    while(1){
        int n;
        cin >> n;
        if(n == 0) break;
        make(data(), n);
        //sort(ans.begin(), ans.end(), larger);
        for(int i = ans.size() - 1;i >= 0;i--){
            for(int j = 0;j < ans[i].size();j++){
                cout << ans[i][j];
                if(j != ans[i].size() - 1) cout << ' ';
            }
            cout << endl;
        }
        ans.clear();
    }
     
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <utility>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <istream>
#include <ostream>

#include <cstdlib>
#include <cmath>
#include <cstdio>

using namespace std;

#define fi first
#define se second
#define mkp make_pair
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define rep(i,n) for(ll i=0; i < (n); ++i)
#define rrep(i,n) for(ll i=((n)-1); i >= 0; --i)

#define OPLT(T) bool operator<(const T & lop_, const T & rop_)
#define OPEQ(T) bool operator==(const T & lop_, const T & rop_)

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

istream& operator>>(istream& istr, __float128& obj) { double d; istr >> d; obj = d; return istr; };
ostream& operator<<(ostream& ostr, __float128& obj) { ostr << static_cast<double>(obj); return ostr; };

int main() {
	ll Q, H, S, D, N;
	cin >> Q >> H >> S >> D >> N;
	Q *= 4;
	H *= 2;
	S = min(S, min(Q, H));
	D = min(D, S*2);
	cout << (N/2)*D + (N%2)*S << endl;
	return 0;
}


Measured memory_bytes: 768
#include <stdio.h>

int main()
{
    int a,b,c,d,e,k;
    int ab,ac,ad,ae,bc,bd,be,cd,ce,de;

    scanf("%d\n",&a);
    scanf("%d\n",&b);
    scanf("%d\n",&c);
    scanf("%d\n",&d);
    scanf("%d\n",&e);
    scanf("%d\n",&k);

    ab=b-a;
    ac=c-a;
    ad=d-a;
    ae=e-a;
    bc=c-b;
    bd=d-b;
    be=e-b;
    cd=d-c;
    ce=e-c;
    de=e-d;

    if(ab<=k && ac<=k && ad<=k && ae<=k && bc<=k && bd<=k && be<=k && cd<=k && ce<=k && de<=k){
        printf("Yay!\n");
    }
    else{
        printf(":(\n");
    }    

    return 0;
}

Measured memory_bytes: 128
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, L = MAP()

apple = [L+i for i in range(N)]
# print(apple)

for i in apple:
	if i == 0:
		print(sum(apple))
		break
else:  # 0なし
	if max(apple) > 0:
		print(sum(apple)-min(apple))
	else:
		print(sum(apple)-max(apple))


Measured memory_bytes: 5780
while 1:
    hands = []
    h = int(input())
    if h == 0:
        break
    hands.append(h)

    for _ in range(4):
        h = int(input())
        hands.append(h)

    h_uni = list(set(hands))
    if len(h_uni) != 2:
        for _ in range(5):
            print(3)
        continue

    h_uni.sort()
    if h_uni[0] == 1 and h_uni[1] == 2:
        for h in hands:
            if h == 1:
                print(1)
            else:
                print(2)
    elif h_uni[0] == 1 and h_uni[1] == 3:
        for h in hands:
            if h == 1:
                print(2)
            else:
                print(1)
    else:
        for h in hands:
            if h == 2:
                print(1)
            else:
                print(2)



Measured memory_bytes: 5596
import numpy as np
import collections

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
P = [list(map(int,input().split())) for i in range(Q)]
A = np.array(A)

sum_A = np.sum(A)
c = collections.Counter(A)
  
for item in P:
  if item[0] in c.keys():
    sum_A += ((item[1] - item[0]) * c[item[0]])
    if item[1] in c.keys():
      c[item[1]] += c[item[0]]
    else:
      c[item[1]] = c[item[0]]
    c.pop(item[0])
  print(sum_A)


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

#define mp make_pair

using namespace std;

typedef int32_t i32;
typedef uint32_t u32;
typedef int64_t i64;
typedef uint64_t u64;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<i64,int> pli;
typedef pair<int,i64> pil;
typedef pair<i64,i64> pll;
typedef vector<int> vi;
typedef vector<i64> vl;

template <typename T>
T id(T b) {return b;};
template <class It>
bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It>
bool any(It f,It l){return std::any_of(f,l,id<bool>);}

const int MAX_N = 1005;
int xs,ys,xt,yt;
int n;
ld x[MAX_N], y[MAX_N], r[MAX_N];
vector<pair<ld,int> > g[MAX_N];

namespace dijkstra {
  const int64_t INF = LLONG_MAX;
  typedef pair<ld,int> P;
  struct edge { int to; ld cost; };
  int n;

  vector<edge> g[MAX_N];
  ld d[MAX_N];

  void init(int m)
  {
    n = m;
    for (int i = 0; i < n; i++) {
      g[i].clear();
    }
  }

  void add_edge(int u, int v, ld cost)
  {
    g[u].push_back({v,cost});
    g[v].push_back({u,cost});
  }

  void search(int s)
  {
    priority_queue<P, vector<P>, greater<P> > q;
    fill_n(d, n, INF);
    d[s] = 0;
    q.push(P(0,s));

    while (!q.empty()) {
      P p = q.top(); q.pop();
      int v = p.second;
      if (d[v] < p.first) continue;
      for (int i = 0; i < (int)g[v].size(); i++) {
        edge e = g[v][i];
        if (d[e.to] > d[v] + e.cost) {
          d[e.to] = d[v] + e.cost;
          q.push(P(d[e.to], e.to));
        }
      }
    }
  }
}

int main()
{
  cin >> x[0] >> y[0] >> xt >> yt >> n;
  x[n+1] = xt, y[n+1] = yt;
  r[0] = r[n+1] = 0;

  for (int i = 1; i <= n; i++) {
    cin >> x[i] >> y[i] >> r[i];
  }

  for (int i = 0; i <= n+1; i++) {
    ld x1 = x[i], y1 = y[i], r1 = r[i];
    for (int j = 0; j <= n+1; j++) {
      if (i == j) continue;
      ld x2 = x[j], y2 = y[j], r2 = r[j];
      ld d = max(ld(0.0), sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))-r1-r2);
      g[i].push_back(mp(d,j));
    }
  }

  dijkstra::init(n+2);

  for (int i = 0; i <= n+1; i++) {
    for (auto p : g[i]) {
      dijkstra::add_edge(i, p.second, p.first);
    }
  }

  dijkstra::search(0);

  printf("%.12Lf\n", dijkstra::d[n+1]);

  return 0;
}


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

int main() {
  int K, X;
  cin >> K >> X;
  if (K * 500 < X) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
  return 0;
}

Measured memory_bytes: 764
package main

import (
	"container/list"
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}
	sort.Ints(a)

	l := list.New()
	for i := 0; i < n; i++ {
		l.PushBack(a[i])
	}

	bb := list.New()
	bb.PushBack((l.Front().Value).(int))
	bb.PushBack((l.Back().Value).(int))
	l.Remove(l.Front())
	l.Remove(l.Back())
	for i := 1; i < n-1; i++ {
		e1 := l.Front()
		e2 := l.Back()
		x1 := e1.Value.(int)
		x2 := e2.Value.(int)

		left := bb.Front().Value.(int)
		right := bb.Back().Value.(int)
		m1 := max(abs(left-x1), abs(right-x1))
		m2 := max(abs(left-x2), abs(right-x2))

		var x int
		var e *list.Element
		if m1 > m2 {
			x, e = x1, e1
		} else {
			x, e = x2, e2
		}
		l.Remove(e)

		if abs(left-x) < abs(right-x) {
			bb.PushBack(x)
		} else {
			bb.PushFront(x)
		}
	}

	vs := make([]int, n)
	i := 0
	for e := bb.Front(); e != nil; e = e.Next() {
		vs[i] = e.Value.(int)
		i++
	}

	ans := 0
	for i := 0; i < n-1; i++ {
		ans += abs(vs[i] - vs[i+1])
	}
	fmt.Println(ans)
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}


Measured memory_bytes: 21504
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define int ll
#define pb push_back
#define setbits(x)          __builtin_popcountll(x)
#define endl "\n"
typedef long long ll;
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,k,s;
cin>>n>>k>>s;
for(int i=0;i<k;i++)
    cout<<s<<" ";
    int x=pow(10,9);
for(int i=k;i<n;i++)
{
    if(s==x)
        cout<<x-1<<" ";
    else
        cout<<x<<" ";
}
cout<<endl;
    return 0;
}


Measured memory_bytes: 3612
#include<cstdio>
using namespace std;
#define N 4003
#define M 200005
#define mod 1000000007
#define rep(i,j,k) for(i=j;i<=k;++i)
int x,y,ny,n,ans,i,j,k,mid;
int f[N][N],fac[N<<1],inv[N<<1],a[M],b[M];
void read(int &p){
	p=0; char x=getchar();
	while(x<'0' || x>'9') x=getchar();
	while(x>='0'&&x<='9'){p=p*10+x-'0'; x=getchar();}
}
int quick_mi(int a,int b){
	int sum=1;
	for(;b;b>>=1){
		if(b&1) sum=(sum*1LL*a)%mod;
		a=(a*1LL*a)%mod;
	}
	return sum;
}
int C(int n,int m){
	if(n<m) return 0;
	return (fac[n]*1LL*((inv[m]*1LL*inv[n-m])%mod))%mod;
}
void dec(int &a,int b){
	a-=b; if(a<0) a+=mod;
}
void init(){
	ny=quick_mi(2,mod-2);
	read(n); mid=2001;
	fac[0]=inv[0]=1; 
	rep(i,1,8000) {
		fac[i]=(fac[i-1]*1LL*i)%mod; 
		inv[i]=quick_mi(fac[i],mod-2);
	}
	rep(i,1,n){
		read(x); read(y);
		a[i]=x; b[i]=y;
		f[mid-x][mid-y]++;
		dec(ans,C(x+x+y+y,x+x));
	}
	rep(i,1,4001)
	 rep(j,1,4001){
	 	f[i][j]+=f[i-1][j];
	 	if(f[i][j]>=mod) f[i][j]-=mod;
	 	f[i][j]+=f[i][j-1];
	 	if(f[i][j]>=mod) f[i][j]-=mod;
	 }
	rep(i,1,n){
		ans+=f[mid+a[i]][mid+b[i]];
		if(ans>=mod) ans-=mod;
	}
	ans=(ans*1LL*ny)%mod;
	printf("%d\n",ans);
}
int main(){
	init();
	return 0;
}

Measured memory_bytes: 64384
#include <iostream>
#include <algorithm>
#include <map>
#include <math.h>
#include <string>
typedef long long ll;

using namespace std;

int main(){
    ll H, W;
    cin >> H >> W;

    ll res = 1e10;
    for (int j = 1 ; j < W; j++){
	ll Sa = H*j;
	ll h = H/2, w = (W-j)/2;
	ll Sb1 = H*w, Sc1 = H*(W-j-w);
	ll Sb2 = h*(W-j), Sc2 = (H-h)*(W-j);
	
	res = min(res, max(max(Sa, Sb1), Sc1)-min(min(Sa, Sb1), Sc1));
	res = min(res, max(max(Sa, Sb2), Sc2)-min(min(Sa, Sb2), Sc2));
    }

    for (int i = 1; i < H; i++){
	ll Sa = i*W;
	ll h = (H-i)/2, w = W/2;
	ll Sb1 = h*W, Sc1 = (H-i-h)*W;
	ll Sb2 = (H-i)*w, Sc2 = (H-i)*(W-w);

	res = min(res, max(max(Sa, Sb1), Sc1)-min(min(Sa, Sb1), Sc1));
	res = min(res, max(max(Sa, Sb2), Sc2)-min(min(Sa, Sb2), Sc2));
    }

    cout << res << endl;

    return 0;
}


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

string solve(string s, string t) {
	int n = s.size();
	int m = t.size();

	vector<vector<int>> dp(n+1, vector<int>(m+1));
	for (int i = 0; i <= n; ++i)
	{
		for (int j = 0; j <= m; ++j)
		{
			if (i==0 || j==0) dp[i][j] = 0;
			else if (s[i-1]==t[j-1]) dp[i][j] = dp[i-1][j-1] + 1;
			else dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
		}
	}
	int len = dp[n][m];
	string result = "";
	int r=n, c=m;
	for (int i = 0; i < len; ++i)
	{
		bool flag = true;
		while (flag) {
			if (s[r-1]==t[c-1]) {
				result = s[r-1] + result;
				r--;
				c--;
				flag = false;
			} else {
				if (dp[r][c]==dp[r-1][c]) {
					r--;
				} else {
					c--;
				}
			}
		}
	}
	return result;
}


int main(int argc, char const *argv[])
{
	string s, t;
	cin >> s >> t;
	cout << solve(s, t) << "\n";
	return 0;
}

Measured memory_bytes: 38952
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long int ll;

typedef long double lld;

#define EPS (1e-7)
#define INF (1e10)
#define PI (acos(-1))

ll N, M;
ll L[100010], R[100010];

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

	ll l = 0, r = INF;

	for (int i = 0; i < M; i++)
	{
		l = max(l, L[i]);
		r = min(r, R[i]);
	}

	if (N < r)
	{
		ll ans = max((ll)0, N - l + 1);
		cout << ans << endl;
		return 0;
	}
	else
	{
		ll ans = max((ll)0, r - l + 1);
		cout << ans << endl;
	}

	
}

Measured memory_bytes: 1792
"use strict";
main(require("fs").readFileSync("/dev/stdin", "UTF-8"));

function main(input) {
  input = input.split("\n");
  const stringNum = parseInt(input.shift()); // 数量
  input = input.map(s =>
    s
      .split("")
      .sort()
      .join("")
  );
  let stringCounter = {};
  for (const str of input) {
    if (!stringCounter.hasOwnProperty(str)) {
      stringCounter[str] = 1;
    } else {
      stringCounter[str] += 1;
    }
  }
  let result = 0;
  Object.keys(stringCounter).forEach(key => {
    result += (stringCounter[key] * (stringCounter[key] - 1)) / 2;
  });
  console.log(result);
}

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

int main(){

  int h, w;
  char a[110][110];

  cin>>h>>w;
  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++) cin>>a[i][j];
  }

  for(int i=0;i<h+2;i++){
    for(int j=0;j<w+2;j++){
      if(0<i&&i<=h&&0<j&&j<=w) cout<<a[i][j];
      else cout<<'#';
    }
    cout<<endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int cmp(int *a,int *b){return *a>*b;}
int main()
{
	int i,N,h,m,p=0,t[205];
	for(i=0;i<2;i++)
		for(scanf("%d",&N);N--;)
		{
			scanf("%d%d",&h,&m);
			t[p++]=h*60+m;
		}
	qsort(t,p,sizeof(int),cmp);
	for(i=0;i<p;i++)
		if(i<1||t[i]!=t[i-1])
			printf("%s%d:%02d",i>0?" ":"",t[i]/60,t[i]%60,i==p-1);
	puts("");
	return 0;
}

Measured memory_bytes: 624
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;
    for(int i=k-n+1;i<=k;i++)cout<<i<<" ";
    for(int i=k+1;i<=n+k-1;i++)cout<<i<<" ";
    cout<<endl;
}


Measured memory_bytes: 256
// ABC 118 B

#include <iostream>

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  int table[30] = {0};
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    int k;
    cin >> k;
    int v;
    for (int j = 0; j < k; ++j) {
      cin >> v;
      table[v - 1]++;
      if (table[v - 1] == n) {
        ++ans;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main(void) {

  char s[200001];
  scanf("%s", s);
  int length = strlen(s);
  for (int i = 0; i < length; i++) {
    if (s[i] == '?') {
      printf("D");
    } else {
      printf("%c", s[i]);
    }
  }
  printf("\n");

  return 0;
}

Measured memory_bytes: 1852
#include<stdio.h>

#define MAX 1024

int main(void)
{
  
  char moji;
  char count[MAX + 1];
  char output[10][76];
  
  int i = 0;
  int j = 0;
  int testcase;
  int test = 0;  
  
  scanf("%d",&testcase);
  
  while(test < testcase){

    scanf("%s",count);
    
    while(count[i] != '\0'){
      switch(count[i]){
      case '1': if((moji != '.' && moji != ',' && moji != '!' && moji != '?') || moji == ' ')
	  moji = '.';
	else if(moji == '.')
	  moji = ',';
	else if(moji == ',')
	  moji = '!';
	else if(moji == '!')
	  moji = '?';
	else if(moji == '?')
	  moji = ' ';
	break;
	
      case '2': if((moji != 'a' && moji != 'b') || moji == 'c')
	  moji = 'a';
	else if(moji == 'a')
	  moji = 'b';
	else if(moji == 'b')
	  moji = 'c';
	break;
	
      case '3': if((moji != 'd' && moji != 'e') || moji == 'f')
	  moji = 'd';
	else if(moji == 'd')
	  moji = 'e';
	else if(moji == 'e')
	  moji = 'f';
	break;
	
      case '4': if((moji != 'g' && moji != 'h') || moji == 'i')
	  moji = 'g';
	else if(moji == 'g')
	  moji = 'h';
	else if(moji == 'h')
	  moji = 'i';
	break;
	
      case '5': if((moji != 'j' && moji != 'k') || moji == 'l')
	  moji = 'j';
	else if(moji == 'j')
	  moji = 'k';
	else if(moji == 'k')
	  moji = 'l';
	break;
	
      case '6': if((moji != 'm' && moji != 'n') || moji == 'o')
	  moji = 'm';
	else if(moji == 'm')
	  moji = 'n';
	else if(moji == 'n')
	  moji = 'o';
	break;
	
      case '7': if((moji != 'p' && moji != 'q' && moji != 'r') || moji == 's')
	  moji = 'p';
	else if(moji == 'p')
	  moji = 'q';
	else if(moji == 'q')
	  moji = 'r';
	else if(moji == 'r')
	  moji = 's';
	break;
	
      case '8': if((moji != 't' && moji != 'u') || moji == 'v')
	  moji = 't';
	else if(moji == 't')
	  moji = 'u';
	else if(moji == 'u')
	  moji = 'v';
	break;
	
      case '9': if((moji != 'w' && moji != 'x' && moji != 'y') || moji == 'z')
	  moji = 'w';
	else if(moji == 'w')
	  moji = 'x';
	else if(moji == 'x')
	  moji = 'y';
	else if(moji == 'y')
	  moji = 'z';
	break;
	
      case '0': if(moji!='\0'){
	  output[test][j] = moji;
	  j ++ ;
	  moji = '\0';
	}
	break;

      default : break;
	
      }
      i++;
      
    }
    
    for(i=0;count[i]!='\0';i++)
      count[i] = '\0';
    
    output[test][j] = '\0';

    test++;
    i = 0;
    j = 0;
    
  }

  for(i=0;i<testcase;i++){
    for(j=0;output[i][j]!='\0';j++)
    printf("%c",output[i][j]);

    printf("\n");
  }
  return 0;
  
}

Measured memory_bytes: 576