akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;

public class Main {
	private static void solve(){
		//Implement solution here.
		int n = ni();
		int m = ni();
		long result = 0;

		Queue<Integer> jq = new PriorityQueue<>(Collections.reverseOrder());
		for(int i = 0; i < n; i++) {
			jq.add(ni());
		}
		
		for(int i = 0; i < m; i++) {
			int max = jq.poll();
			jq.add(max/2);
		}
		
		while(!jq.isEmpty()) {
			result += jq.poll();
		}
		
		System.out.println(result);
	}

	//Switch input source (stdin/file)
	private static BufferedReader br  = new BufferedReader(new InputStreamReader(System.in));
	public static void main(String[] args){
		String debugDataPath = System.getenv("DD_PATH");        
		if(debugDataPath != null){
			try{
				br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath))));
			}catch(Exception e){
				throw new RuntimeException(e);
			}
		} 
		solve();
	}

	//Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	//Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
	//Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
	//Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
	//Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
	//Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}

Measured memory_bytes: 43872
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int N = s.nextInt();
        int An[] = new int[N];
        int ans=0;
        //Anに値を取り込む
        for (int i = 0; i < N; i++) {
            An[i] = s.nextInt();
        }
        Arrays.sort(An);
        ans=An[N-1]-An[0];
        //ansを出力する
        System.out.print(ans);
    }
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,s,t) for(int i=s; i<t; i++)
#define RNG(i,s,t,u) for(int i=s; i<t; i+=u)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()

int main(){
  int n,m,x;
  cin >> n >> m >> x;
  long ans = 1e16;
  vvi data(n,vi(m));
  vi cost(n);
  rep(i,n){
    cin >> cost.at(i);
    rep(j,m) cin >> data.at(i).at(j);
  }
  for(int tmp=0; tmp<(1<<n); tmp++){
    bitset<12> s(tmp);
    vector<long> cnt(m,0);
    long csum = 0;
    rep(i,n){
      if(s.test(i)){
        csum += cost.at(i);
        rep(j,m){
          cnt.at(j) += data.at(i).at(j);
        }
      }
    }
    bool flag = true;
    rep(i,m){
      if(cnt.at(i) < x) flag = false;
    }
    if(flag) ans = min(ans, csum);
  }
  if(ans == 1e16) cout << -1 << endl;
  else cout << ans << endl;
}

Measured memory_bytes: 3636
// Enjoy your stay.

#include <bits/stdc++.h>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(auto it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define mt make_tuple
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)(x).size())

using namespace std;

typedef istringstream iss;
typedef long long ll;
typedef pair<ll,ll> pi;
typedef stringstream sst;
typedef vector<ll> vi;

ll N,M,L,K[2010],S[100010],sum[100010];
ll dp[2010][2010];

ll f(int a,int b){
	if(K[a] > K[b]) swap(a,b);
	return (sum[K[b]+1] - sum[K[a]])/L;
}

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	cin>>N>>M>>L;
	rep(i,N)cin>>K[i],K[i]--;
	sum[0] = 0;
	rep(i,M){
		cin>>S[i];
		sum[i+1] = sum[i] + S[i];
	}
	sort(K,K+N);
	rep(i,N)rep(j,i) dp[i][j] = INF*INF;
	dp[1][0] = f(0,1);
	rep(i,N)rep(j,i){
		dp[i+1][j] = min(dp[i+1][j], dp[i][j] + f(i,i+1));
		dp[i+1][i] = min(dp[i+1][i], dp[i][j] + f(j,i+1));
	}
	ll ans = INF*INF;
	rep(j,N-1) ans = min(ans, dp[N-1][j] + f(j,N-1));
	cout<<ans<<endl;
}

Measured memory_bytes: 32892
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

signed main()
{
	int A, B;
	cin >> A >> B;
	if (A & 1 && B & 1)cout << "Yes";
	else cout << "No";
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        try (Scanner in = new Scanner(System.in)) {
            int A = in.nextInt();
            int B = in.nextInt();
            System.out.println(B % A == 0 ? (A + B) : (B - A));
        }
    }
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using p = pair<int,int>;
int main() {
  string s;
  cin >> s ;
  bool ans = true;

  while (s.size()> 0){
    if (s.substr(0,5) != "dream" && s.substr(0,5) != "erase" ){
      ans = false;
      break;      
    }
    if (s.substr(0,5) == "dream" ){
      s = s.substr(5);
      if(s.substr(0,2) == "er" && s.substr(0,5) != "erase")
        s = s.substr(2);
    }
    if (s.substr(0,5) == "erase" ){
      s = s.substr(5);
      if(s.substr(0,1) == "r"){
        s = s.substr(1);
      }    
    }
  }
  cout << (ans ? "YES" :"NO" )<< endl;
  return 0;
}


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

int main() {
	vector<int> judge = { 0,0,0,0 };
	rep(i, 3) {
		int A, B;
		cin >> A >> B;
		judge.at(A - 1)++;
		judge.at(B - 1)++;
	}
	cout << (*max_element(judge.begin(), judge.end()) == 2 ? "YES" : "NO") << endl;
	return 0;
}

Measured memory_bytes: 256
//0034
//include-------------------------------------
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<stack>

using namespace std;

//typedef--------------------------------------
typedef vector<int> VI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

#define MP make_pair

//repetition-----------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)

//constant-------------------------------------
const double PI = acos(-1.0);

//cout,cin-------------------------------------
#define COUT(x) cout<<(x)<<endl
#define CIN(x) cin>>(x)

int main(){

	int l[10], v1, v2;
	char a;

	while (cin>>l[0]>>a){
		int L = 0;
		int ans = 0;
		int sum = 0;
		double x, k;
		
		FOR(i,1,10) {
			cin >> l[i] >> a; L += l[i];
		}
		cin >> v1 >> a >> v2;

		k = v1*1.0 / v2;
		x = 1.0*L*k / (1 + k);

		while (sum < x){
			sum += l[ans++];
		}

		COUT(ans);
	}

	return 0;

}

Measured memory_bytes: 1160
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    s+='x';
    int ans=0;
    rep(i,n){
      ++ans;
      if(s[i]=='x'&&s[i+1]=='x'){
        cout<<ans<<endl;
        return 0;
      }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3316
D = gets.to_i
C = gets.chomp.split.map(&:to_i)
s = D.times.map{gets.split.map(&:to_i)}
c = Array.new(26, 0)
t = []

(0..D-1).each do |i|

  (0..25).each do |l|
    c[l] += C[l]
  end
ans = 0
boder = s[i][0]+5*c[0]

  (1..25).each do |e|
    if s[i][e]+5*c[e] >= boder
      ans = e
      boder = s[i][e]+5*c[e]
    end
  end
c[ans] = 0
puts ans+1
end


  



Measured memory_bytes: 14368
#include<stdio.h>
int linear(int *,int,int);
int main(){
  int n,i;
  int q,j;
  int S[10000],T[500];
  int sum = 0;
  scanf("%d",&n);
  for(i = 0;i < n;i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  for(j = 0;j < q;j++){
    scanf("%d",&T[j]);
    if(linear(S,T[j],n) == 1){
      sum++;
    }
  }
  printf("%d\n",sum);
  return 0;
}

int linear(int *S,int T,int n){
  int i;
  for(i = 0;i < n;i++){
    if(T == S[i]){
      return 1;
    }
  }
  return 0;
}





Measured memory_bytes: 2108
class Dice:

  def __init__(self, top=1, front=2, left=4, right=3, back=5, bottom=6):
    self.d = {"TOP": top, "FRONT": front, "LEFT": left, "RIGHT": right, "BACK": back, "BOTTOM": bottom}

  def roll_x(self):
    self._roll("TOP", "FRONT", "BOTTOM", "BACK")

  def roll_y(self):
    self._roll("FRONT", "LEFT", "BACK", "RIGHT")

  def roll_z(self):
    self._roll("TOP", "LEFT", "BOTTOM", "RIGHT")

  def _roll(self, a, b, c, d):
    self.d[a], self.d[b], self.d[c], self.d[d] = self.d[b], self.d[c], self.d[d], self.d[a]

  def all_rolls(self):
    import copy
    ret = []
    for i in range(6):
      if i % 2:
        self.roll_x()
      else:
        self.roll_y()
      for _ in range(4):
        self.roll_z()
        ret.append(copy.deepcopy(self))
    return ret

import copy
from collections import defaultdict
while True:
  n = int(input())
  if n==0:
    break

  board = [[0 for i in range(100)] for j in range(100)]
  height = [[0 for i in range(100)] for j in range(100)]

  for i in range(n):
    t, f = list(map(int, input().split()))
    dice = Dice()
    for di in dice.all_rolls():
      if di.d["TOP"]==t and di.d["FRONT"]==f:
        break

    x, y = 50, 50
    while True:
      dxy = []
      for s in ["FRONT", "LEFT", "BACK", "RIGHT"]:
        tt = di.d[s]
        if tt>=4:
          dxy.append((tt, s))
      dxy.sort(reverse=True)

      move = False
      for _, s in dxy:
        newdice = copy.deepcopy(di)
        if s=="FRONT":
          dx = 0
          dy = 1
          newdice.roll_x()
          newdice.roll_x()
          newdice.roll_x()
        elif s=="LEFT":
          dx = -1
          dy = 0
          newdice.roll_z()
          newdice.roll_z()
          newdice.roll_z()
        elif s=="BACK":
          dx = 0
          dy = -1
          newdice.roll_x()
        elif s=="RIGHT":
          dx = 1
          dy = 0
          newdice.roll_z()

        if height[x][y]>height[x+dx][y+dy]:
          x = x+dx
          y = y+dy
          di = newdice
          move = True
          break

      if not move:
        board[x][y] = di.d["TOP"]
        height[x][y] += 1
        break

  ans = defaultdict(int)
  for e in board:
    for ee in e:
      ans[ee] += 1
  print(*[ans[i] for i in range(1, 7)])


Measured memory_bytes: 6652
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define int long long
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 

vector<int> init(int size){
  vector<int> par(size,-1);
  return par;
}

int root(int x, vector<int>& par){
  if(par[x] < 0){
    return x;
  }else{
    return par[x] = root(par[x],par);
  }
}

bool same(int x, int y, vector<int>& par){
  return root(x, par) == root(y, par);
}

void unite(int x, int y, vector<int>& par){
  x = root(x, par), y = root(y, par);
  if(same(x,y, par))return;
  par[x] += par[y];
  par[y] = x;
}

int size(int x, vector<int>& par){
  return -par[root(x, par)];
}

int pow(int x, int n){
  if(n == 0)return 1;
  if(n % 2 == 0)return pow(x * x % MOD, n/2);
  else return x * pow(x, n-1) % MOD;
}

vector< int > divisor(int n) {
  vector< int > ret;
  for(int i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret),greater<int>());
  return (ret);
}

signed main(){
  int n;cin>>n;double v[50];rep(i,n)cin>>v[i];
  sort(v,v+n);
  double ans = v[0];
  repd(i,1,n){
    ans = (ans+v[i])/2;
  }
  cout << std::setprecision(9) << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
 
int main(void)
{
    int f;
    int i;
    int l, s, n;
    int b[10];
    int w, w2, count, num[4];
     
    while (scanf("%d", &n), n != 0){
        count = 0;
        f = 0;
        while (n != 6174){
            w = 1000;
            for (i = 0; i < 10; i++){
                b[i] = 0;
            }
            for (i = 0; i < 4; i++){
                num[i] = n / w;
                n %= w;
                w /= 10;
                b[num[i]]++;
            }
             
            w = 1000; w2 = 1;
            s = 0; l = 0;
            for (i = 0; i < 10; i++){
                while (b[i] > 0){
                    s += i * w;
                    w /= 10;
                    l += i * w2;
                    w2 *= 10;
                    b[i]--;
                }
            }
            n = l - s;
            count++;
            if (n == 0){
                printf("NA\n");
                f = 1;
                break;
            }
        }
        if (f == 0){
            printf("%d\n", count);
        }
    }
     
    return (0);
}

Measured memory_bytes: 2716
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define rep2(i, a)for(auto i : a)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x, std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll co(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }

vector<ll> s, t;
ll getlen(int c, int sh, ll x) {
	auto target = sh ? s : t;
	ll xx, xx2, d = 0ll;
	auto it = upper_bound(all(target), x);
	if (it == target.end())xx =  1ll << 60;
	else xx = *it;
	if (it == target.begin())xx2 = - 1ll << 60;
	else xx2 = *--it;
	if (abs(xx - x) > abs(xx2 - x))xx = xx2;
	if(c)d = getlen(0, !sh, xx);
	if (d == 1ll << 60)return d;
	return abs(xx - x) + d;
}
int main()
{
	int a, b, q;
	ll x;
	vector<ll> ans;
	cin >> a >> b >> q;
	s.resize(a);
	t.resize(b);
	rep(i, 0, a)cin >> s[i];
	rep(i, 0, b)cin >> t[i];
	s.push_back(1ll << 60);
	s.push_back(-1ll << 60);
	t.push_back(1ll << 60);
	t.push_back(-1ll << 60);
	sort(all(s));
	sort(all(t));
	rep(i, 0, q) {
		cin >> x;
		auto _s = upper_bound(all(s), x);
		auto _t = upper_bound(all(t), x);
		ll v = 1ll << 60, x1 = *_s, x2 = *--_s, y1 = *_t, y2 = *--_t;
		v = min(v, abs(x1 - x) + abs(y1 - x1));
		v = min(v, abs(x1 - x) + abs(y2 - x1));
		v = min(v, abs(x2 - x) + abs(y1 - x2));
		v = min(v, abs(x2 - x) + abs(y2 - x2));
		v = min(v, abs(x1 - y1) + abs(y1 - x));
		v = min(v, abs(x1 - y2) + abs(y2 - x));
		v = min(v, abs(x2 - y1) + abs(y1 - x));
		v = min(v, abs(x2 - y2) + abs(y2 - x));
		ans.push_back(v);
	}
	rep2(v, ans)printf("%lld\n", v);
	return 0;
}

Measured memory_bytes: 6468
n = gets.chomp.to_i

ll = []

n.times do
  a = gets.chomp.to_i
  row = []
  a.times do
    row << gets.chomp.split.map(&:to_i)
  end
  ll << row
end

ans = 0

[0, 1].repeated_permutation(n) do |bits|
  tmp_ans = 0
  break_flag = 0
  n.times do |i|
    # 不親切な人の場合はスキップ
    next if bits[i] == 0

    # 証言とbitを確認する

    # 正直者な場合 証言を確認する
    ll[i].each do |syougen|
      # p "#{bits}のとき"
      # p syougen
      if bits[syougen[0] -1 ] != syougen[1]
        break_flag = 1
      end
    end


  end

  ans = [ans, bits.inject(:+)].max if break_flag == 0
end

puts ans

Measured memory_bytes: 2300
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast;

long long mod = 1000000007;

long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t / 2;
    } else {
        return modpow(m, n - 1) * m % mod;
    }
}



int main() {
    long long n, m, a, b, d1 = 0, d2 = 0, d3 = 0, ans = 0, sum = 0;
    cin >> n >> a >> b;
    if (a > b){
        cout << 0 << endl;
        return 0;
    }
    if (b == a){
        cout << 1 << endl;
        return 0;
    }
    if (n == 1 && a != b){
        cout << 0 << endl;
        return 0;
    }
    if (b > a){
        cout << 1 + b * (n - 1) + a - a * (n - 1) - b << endl;
    }
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repi(i, a, b) for (int i = (a); i < int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ull << (b))

using namespace std;
using i32 = int;
using i64 = long long;
using f64 = double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf64 = vector<f64>;
using vstr = vector<string>;

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(16);
  string s;
  cin >> s;
  if (s <= "2019/04/30") cout << "Heisei" << endl;
  else cout << "TBD" << endl;
  return 0;
}


Measured memory_bytes: 256
#if 1
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <functional>
#include <set>
#include <map>
#include <numeric>
#include <cassert>

using namespace std;
#define int long long
#define uint unsigned long long
constexpr int MOD = 1000000007;
constexpr int INF = 1145141919810;

#define LOADVEC(type,name,N) std::vector<type>name(N); \
for (int nnn = 0; nnn < N; ++nnn) { \
	cin >> name[nnn]; \
}

#define LOADVEC2(type,name0,name1,N) std::vector<type>name0(N),name1(N); \
for (int nnn = 0; nnn < N; ++nnn) { \
	cin >> name0[nnn];cin >> name1[nnn]; \
}

#define LOADVEC3(type,name0,name1,name2,N) std::vector<type>name0(N),name1(N),name2(N); \
for (int nnn = 0; nnn < N; ++nnn) { \
	cin >> name0[nnn];cin >> name1[nnn];cin >> name2[nnn]; \
}

#define LOAD(type,name) type name; \
cin >> name;


void proc();

signed main() {
	ios::sync_with_stdio(false);
	proc();
	return 0;
}

/*
--------------------------------------------------------
--------------------------------------------------------
---------------    template      ----------------------
--------------------------------------------------------
--------------------------------------------------------
*/


void proc() {
	LOAD(int, N);
	LOADVEC(int, b, N);
	std::vector<int>res;
	res.reserve(100);
	while (!b.empty()) {
		bool flag = false;
		for (int i = b.size() - 1; i >= 0; --i) {
			if (i + 1 == b[i]) {
				res.push_back(b[i]);
				b.erase(b.begin() + i);
				flag = true;
				break;
			}
		}
		if (!flag) {
			cout << -1 << endl;
			return;
		}
	}
	for (int i = 0; i < res.size(); ++i) {
		cout << res[N - i - 1] << endl;
	}
}


#endif


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

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

    static class BIMissYou {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.next().length();
            for (int i = 0; i < n; i++) {
                out.print('x');
            }
            out.println();
        }

    }

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

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

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

    }
}



Measured memory_bytes: 22356
#include<stdio.h>

int main(void){
  int n,i,temp,res=0,a[21]={},b[21]={},c[21]={};
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&a[i]);
  for(i=0;i<n;i++) scanf("%d",&b[i]);
  for(i=0;i<n-1;i++) scanf("%d",&c[i]);
  for(i=0;i<n;i++){
    res += b[a[i]-1];
    if(a[i]+1==a[i+1]) res += c[a[i]-1];
  }
  printf("%d\n",res);
  return 0;
}

Measured memory_bytes: 128
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(readline())

l = []
for i in range(n):
    s, p = readline().decode().rstrip().split()
    p = int(p)
    tmp = [i+1,s,p]
    l.append(tmp)

l.sort(key=lambda x: x[2], reverse=True)
l.sort(key=lambda x: x[1])
for v in l:
    print(v[0])


Measured memory_bytes: 9192
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,ma,mb;
  cin>>n>>ma>>mb;
  vector<vector<int>>dp(401,vector<int>(401,1e9));
  dp[0][0]=0;
  rep(i,n){
    int a,b;cin>>a>>b;
    int c;cin>>c;
    auto tdp=dp;
    rep(j,401-a)rep(k,401-b){
      if(dp[j][k]!=1e9)chmin(tdp[j+a][k+b],dp[j][k]+c);
    }
    dp=tdp;
  }
  int res=1e9;
  int ta,tb;ta=ma;tb=mb;
  while(ta<401&&tb<401){
    chmin(res,dp[ta][tb]);
    ta+=ma;
    tb+=mb;
  }
  if(res==1e9)res=-1;
  cout<<res<<endl;

  return 0;

}


Measured memory_bytes: 1536
N,K=[int(i) for i in input().split()]
A=[int(i) for i in input().split()]

data={}

for num in A:
        if num in data:
                data[num]+=1
        else:
                data[num]=1
num=[int(i) for i in data.values()]
#type(num)
num.sort()

num.reverse()

ans=sum(num)

if len(num)<=K:
        print(0)
else:
        for i in range(K):
                ans-=num[i]
        print(ans)

Measured memory_bytes: 32284
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();

        for (int i = 1; i < Integer.MAX_VALUE; i++) {
            double aPrice = Math.floor(i * 0.08);
            double bPrice = Math.floor(i * 0.1);
            if (aPrice == a && b == bPrice) {
                System.out.println(i);
                break;
            } else if (aPrice > a || bPrice > b) {
                System.out.println(-1);
                break;
            }

        }
    }
}

Measured memory_bytes: 23752
#include <iostream>
#include <algorithm>
#include <numeric>
#include "math.h"
#include <string>
#include <vector>
#include <iomanip>

#define pai 3.14159265358979323846264338327950288
using namespace std;


// Snack
/*
int main() 
{


	return 0;
}
//*/

// Strings with the Same Length
//*
int main() 
{

	int n;
	string s, t,sum;

	cin >> n >> s >> t;
	
	for (int i = 0; i < n*2; i++) 
	{
	

		if (i%2==0) 
		{
			sum += s[i / 2];
			
			continue;
		}		
		sum+= t[i / 2];
		
	}
	cout << sum;
	return 0;
}
//*/


Measured memory_bytes: 256
{-# LANGUAGE ScopedTypeVariables #-}
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.ByteString.Char8 as B
import Data.Char
import Data.List

solve :: VUM.IOVector Int -> Int -> IO Bool
solve vec i = do
    right <- VUM.read vec i
    left <- VUM.read vec (i-1)

    case compare left right of
        LT -> return True
        EQ -> return True
        GT ->
            if (left == (right + 1))
                then do
                    VUM.modify vec (\x -> x-1) (i-1)
                    return True
                else
                    return False
    
main = do
    n <- readLn :: IO Int
    xs <- VU.unfoldrN n (B.readInt . B.dropWhile isSpace) <$> B.getLine
    (xs' :: VUM.IOVector Int) <- VU.unsafeThaw xs
    res <- and <$> sequence [solve xs' i | i <- [n-1,n-2..1]]
    putStrLn $ if res then "Yes" else "No"

Measured memory_bytes: 7036
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String ns = sc.next();
    String[] s = ns.split("");
    if (s[s.length - 1].equals("s")) {
      System.out.println(ns + "es");
    } else {
      System.out.println(ns + "s");
    }
  }
}

Measured memory_bytes: 38528
#include <iostream>

using namespace std;

int main(void){
	char ch; cin >> ch;
	if(ch == 'A') cout << "T" << endl;
	if(ch == 'T') cout << 'A' << endl;
	if(ch == 'C') cout << 'G' << endl;
	if(ch == 'G') cout << 'C' << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;

//using Graph = vector<vector<edge>>;
using dou =long double;
string yes="yes";
string Yes="Yes";
string YES="YES";
string no="no";
string No="No";
string NO="NO";

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; }
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(ll i = m; i < (ll)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define query int qq;std::cin >> qq;rep(qqq,qq)
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout <<"Case #" <<qqq+1<<": "
#define RES(a,i,j) a.resize(i);rep(ii,i)a[ii].resize(j); 
#define as assign
#define ffor for(;;)
#define ppri(a,b) std::cout << a<<" "<<b << std::endl
#define pppri(a,b,c) std::cout<<a<<" "<<b<<" "<<c<<std::endl
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define ssum(a) accumulate(a,0ll) 
#define gre(n) greater<n>()

typedef long long ll;
//
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
//typedef long long T;
const int INF = 1000000000;
const double dINF = 1000000000;
const ll INF64 = 922337203685477580ll;
//const ll MOD = 1000000007ll;
const ll MOD = 998244353ll;
const dou pi=3.141592653589793;
//メモ
//二次元配列のresizeのしかた
//vv.resize(n);
//for(size_t i=0; i<n; i++){
// vv[i].resize(n);
//}

//メモ
//負の辺を持つ最短経路問題では到達不可経路でも初期化値より小さくなりうるので注意しよう
int main(){
    int a,b,x;
    std::cin >> a>>b>>x;
    if(x>=a&&x<=a+b)std::cout << YES << std::endl;
    else std::cout << NO << std::endl;
    
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[][] range = new int[n][2];
        for(int i = 0;i < n;i++) {
            int x = sc.nextInt();
            int l = sc.nextInt();
            range[i][0] = x - l;
            range[i][1] = x + l;
        }

        // 終端でソート
        Arrays.sort(range, (l, r) -> Integer.compare(l[1], r[1]));
        int count = n; 
        int r = range[0][1];
        for(int i = 1;i < n;i++) {
            if(range[i][0] < r) count--;
            else r = range[i][1];
        }

        System.out.println(count);
    }
}


Measured memory_bytes: 92648
#include<iostream>
#include<cstdio>
using namespace std;
const int maxn=15;
int n,m,a[maxn][maxn],cnt;
bool flag=false;
char c;

// void dfs(int x,int y){
// 	if(x==n && y==m){
// 		for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) if(a[i][j]) return;
// 		flag=true; return;
// 	}
// 	if(flag) return;
// 	if(a[x+1][y]){
// 		a[x+1][y]=0;
// 		dfs(x+1,y);
// 		a[x+1][y]=1;
// 	}
// 	else if(a[x][y+1]){
// 		a[x][y+1]=0;
// 		dfs(x,y+1);
// 		a[x][y+1]=1;
// 	}
// 	else return;
// }

int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin>>c;
			if(c=='#') cnt++;
		}
	}
// 	a[1][1]=0,dfs(1,1);
	if(cnt==n+m-1) puts("Possible");
	else puts("Impossible");
	return 0;
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i > 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

using namespace std;

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

    vector<ll> L(N+1);

    L.at(0) = 2;
    L.at(1) = 1;

    for(int i = 2; i <= N; i++){
        L.at(i) = L.at(i-2) + L.at(i-1);
    }

    cout << L.at(N) << endl;
}

Measured memory_bytes: 3608
use std::io;
use std::cmp;

fn main() {
  let mut buf = String::new();
  io::stdin().read_line(&mut buf).unwrap();
  let s: Vec<&str> = buf.split_whitespace().collect();
  let n: usize = s[0].parse().unwrap();
  let w: i32 = s[2].parse().unwrap();

  let mut buf2 = String::new();
  io::stdin().read_line(&mut buf2).unwrap();
  let s2: Vec<&str> = buf2.split_whitespace().collect();
  let mut last1: i32 = 0;
  if n > 1 {
    last1 = s2[n - 2].parse().unwrap();
  }
  let last0: i32 = s2[n - 1].parse().unwrap();
  let choice0 = (last0 - w).abs();
  let mut choice1 = 0;
  if n > 1 {
    choice1 = (last1 - last0).abs();
  }
  println!("{}", cmp::max(choice0, choice1));
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define era(t) t.erase(unique(be(t)),t.end())
typedef long long ll;
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    int n=s.length();
    int numa=0,numb=0,numc=0;
    for(int i=0;i<n;i++){
        if(s[i]=='a'){
            numa++;
        }
        if(s[i]=='b'){
            numb++;
        }
        if(s[i]=='c'){
            numc++;
        }
    }
    int mi=numa,ma=numa;
    mi=min(mi,numb);
    mi=min(mi,numc);
    ma=max(ma,numb);
    ma=max(ma,numc);
    if(ma<=mi+1){
        cout << "YES"<<endl;
    }
    else{
        cout << "NO"<<endl;
    }
    return 0;
}


Measured memory_bytes: 512
/**
 *    Coded by : lucky_21
 *               --------Lokesh Singh
**/

#include<bits/stdc++.h>
using namespace std;

#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

#define     F           first
#define     S           second
#define     pb          push_back
#define     lb          lower_bound
#define     ub          upper_bound
#define     pii         pair<int,int>
#define     all(x)      x.begin(),x.end()
#define     fix         fixed<<setprecision(10)
#define     rep(i,a,b)  for(int i=int(a);i<=int(b);i++)
#define     repb(i,b,a) for(int i=int(b);i>=int(a);i--)
#define     FastIO      ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)

typedef double db;
typedef long long ll;

const int N=2e5+5;
const int mod=1e9+7;

signed main(){
    FastIO;
    ll a,b,c,d,t;
    cin>>a>>b>>c>>d>>t;
    if(a<c){
        return cout<<((c-a)<=(b-d)*t?"YES":"NO"),0;
    }
    cout<<((a-c)<=(b-d)*t?"YES":"NO");
    return 0;
}


Measured memory_bytes: 3648
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>
#include<random>
#include<set>
#include<bitset>
#include<cassert>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define chmax(x,y) x = max(x,y)
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

const int mod = 1000000007;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x% mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
	mint operator+(const mint a) const { return mint(*this) += a; }
	mint operator-(const mint a) const { return mint(*this) -= a; }
	mint operator*(const mint a) const { return mint(*this) *= a; }
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const { return pow(mod - 2); }
	mint& operator/=(const mint a) { return *this *= a.inv(); }
	mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

mint fact(mint n) {
	if (n.x == 0) {
		return 1;
	}
	else {
		return n * fact(n - 1);
	}
}

mint s;

int main() {
	cin >> s;
	mint ans = 0;
	for (mint i = 1; i.x <= s.x/3; i += 1)
		ans += fact(s - (mint)2 * i - 1) / fact(s - (mint)3 * i) / fact(i - 1);
	cout << ans.x << endl;
	return 0;
}

Measured memory_bytes: 3640
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		int n;
		Scanner scan = new Scanner(System.in);
		n=scan.nextInt();
		int[] a = new int[n];
		for(int i = n;i>0;i--){
			a[i-1]=scan.nextInt();
		}
		for(int i= 0; i<n-1;i++){
			System.out.print(a[i] + " ");
		}
		System.out.println(a[n-1]);
	}
}


Measured memory_bytes: 26356
#include <cstdio>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define p pair<ll,ll>
#define IOS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
ll aa[200005];
int main()
{
      
       ll a,b,x,y,ans=0;
       cin>>a;
       for(int i=2;i<=a;i++)
        {
            cin>>x;aa[x]++;
        }
        for(int i=1;i<=a;i++)
         {
             cout<<aa[i]<<endl;

         }
    return 0;
}



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

using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
int __stoi(string s){ return atoi(s.c_str()); }
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}
template<class T> void chmax(T& a, T b){ if(a<b){a=b;} }
template<class T> void chmin(T& a, T b){ if(a>b){a=b;} }
const ll MOD = 1e9+7;

bool func(pair<ll,ll> x, pair<ll,ll> y){
    if(x.first!=y.first){ return x.first<y.first;}
    else{ return x.second>y.second; }
}

int main(){
    ll N,M; cin>>N>>M;
    pair<ll,ll> p[N];
    REP(i,N){
        ll a,b; cin>>a>>b;
        p[i]  = make_pair(a,b);
    }
    sort(p,p+N,func);
    int idx = 0;
    ll ans = 0;
    priority_queue<ll> cands;
    for(int i=1;i<=M;++i){
        while(1){
            if(idx==N || p[idx].first>i){ break;}
            cands.push(p[idx].second);
            ++idx;
        }
        if(!cands.empty()){
          ans += cands.top();
          cands.pop();
        }
    }
    cout << ans << "\n";
    
}


Measured memory_bytes: 2936
#pragma region head
    #include <bits/stdc++.h>
    using namespace std;
    using ll = long long;
    using vi = vector<int>;
    using vll = vector<ll>;
    using pi = pair<int, int>;
    using pll = pair<ll,ll>;
    template <class T> using vv = vector<vector<T>>;
    #define rep(i,n) for(int i = 0; i < (int)(n); i++)
    #define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
    const int INF = 1002003004;
    const ll LINF = 1002003004005006007ll;
    struct preprocess{preprocess()
    {cin.tie(nullptr);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}}____;
#pragma endregion head

#pragma region library
template <class T>
struct Edge{
    int src;
    int to;
    T cost;
    Edge(int t,T c) : to(t),cost(c) {}
    Edge(int src, int t,T c) : src(src),to(t),cost(c) {}
};
template<class T> using WeightedGraph = vector<vector<Edge<T>>>;
    // Time Complexity: faster than O(logN)[O(ArkInv(N))]
// UnionFind.data: if minus -> size of subtree (node is root)
// if plus -> parent of the node

struct UnionFind {
    vector<int> data;
    UnionFind(int sz){
        data.assign(sz,-1);
    }
    int find(int x){
        if(data[x]<0) return x;
        return data[x]=find(data[x]);
    }
    void unite(int x, int y){
        x = find(x); y = find(y);
        if(x==y) return;
        if(data[x]>data[y]) swap(x,y);
        data[x]+=data[y];
        data[y]=x;
        return;
    }
    int size(int x){
        return (-data[find(x)]);
    }
    int same(int x,int y){
        return find(x)==find(y);
    }
};
// Dependency: Union-Find
// Time complexity: O(E logV)

template<class T>
T kruskal(vector<Edge<T>>& es,int v){
    sort(es.begin(),es.end(),[](Edge<T>& e1,Edge<T>& e2){
        return e1.cost < e2.cost;
    });
    UnionFind uf(v);
    T res = 0;
    for(auto& e: es){
        if(!uf.same(e.src,e.to)){
            uf.unite(e.src,e.to);
            res += e.cost;
        }
    }
    return res;
}
#pragma endregion library
using ti = tuple<int, int,int>;

int main(){
    int n; cin >> n;
    vector<ti> co;
    rep(i,n){
        int x,y; cin >> x >> y;
        co.emplace_back(x,y,i);
    }
    sort(co.begin(),co.end());
    vector<Edge<ll>> es;
    rep(i,n-1){
        es.emplace_back(get<2>(co[i]),get<2>(co[i+1]),get<0>(co[i+1])-get<0>(co[i]));
    }
    sort(co.begin(), co.end(),[](ti& a,ti& b){
        return get<1>(a) < get<1>(b);
    });
    rep(i,n-1){
        es.emplace_back(get<2>(co[i]),get<2>(co[i+1]),get<1>(co[i+1])-get<1>(co[i]));
    }
    cout << kruskal<ll>(es,n) << '\n';
    
}

Measured memory_bytes: 8560
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007

int main(){
    ll a,b,c; cin >> a >> b >> c;
    ll ans = 0;
    if(a+b >= c) cout << b+c << endl;
    else cout << (a+b+1) + b << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static int A, B;

    public static void Main(string[] args)
    {
        A = Input.NextInt();
        B = Input.NextInt();

        int ans;
        if (A == B)
            ans = A + B;
        else if (A > B)
            ans = A + A - 1;
        else 
            ans = B + B - 1;

        Console.WriteLine(ans);
    }
}

public static class Input
{
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}

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

int main()
{
    int X, Y, A, B, C;
    cin >> X >> Y >> A >> B >> C;
    vector<int> V(A + B + C);
    for (auto &x : V) cin >> x;
    sort(V.begin(), V.begin() + A);
    sort(V.begin() + A, V.end() - C);
    sort(V.end() - C, V.end());
    for (int i = 0; i < A - X; i++) V[i] = 0;
    for (int j = A; j < A + B - Y; j++) V[j] = 0;
    sort(V.rbegin(), V.rend());
    cout << accumulate(V.begin(), V.begin() + X + Y, 0LL) << "\n";
}

Measured memory_bytes: 1536
#include <iostream>
#include<string>
using namespace std;
int main(void){
    
    int a,b;
    string s,p;
    cin >> s >>p;
    
    a = s.length();
    b = p.length();
    
    
    for(int i=0;i<a;i++){
        for(int j=0;j<b;j++){
             if(s[(i+j)%a] != p[j]){
               break;
             } else if(j == b-1){
               cout << "Yes" << endl;
               return 0;//終わり
             }
        } 
    }
    cout << "No" << endl; 
}



Measured memory_bytes: 3224
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <numeric>
#include <complex>
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
using namespace std;
typedef long long ll;

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    if((a == b && a != c)
    || (b == c && b != a)
    || (c == a && c != b)){
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;
    
    return 0;
}


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

long GCD(long x,long y){
  if(y == 0) return x;
  return GCD(y,x%y);
}

int main() {
  int n,pos;long x;
  cin >> n >> x;
  vector<long>data(n);
  for(int i = 0;i < n;i++) cin >> data[i];
  sort(data.begin(),data.end());
  if(data[0] > x) data.insert(data.begin(),x);
  else{
    for(int i = 0;i < n;i++){
      if(data[i] <= x) pos = i;
    }
    data.insert(data.begin()+pos+1,x);
  }
  long gcd = data[1]-data[0];
  for(int i = 1;i < n;i++){
    gcd = GCD(gcd,data[i+1]-data[i]);
  }
  cout << gcd << endl;
}


Measured memory_bytes: 1792
using System;
class Example
{
    static void Main()
    {
        string[] n = Console.ReadLine().Split(' ');
        int a = int.Parse(n[0]);
        int b = int.Parse(n[1]);
        int temp = 1;
        if (a < b)
        {
            temp = a;
            a = b;
            b = temp;
        }
        while ( a% b != 0)
        {
            temp = a % b;
            a = b;
            b = temp;

        }
        Console.WriteLine(b);
    }
}

Measured memory_bytes: 9164
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a, c = 1;
        while (true) {
            String[] str = sc.nextLine().split(" ");
            int x = Integer.parseInt(str[0]);
            int y = Integer.parseInt(str[1]);
            if (x == 0 && y == 0) break;
            if (x < y) System.out.println(x + " " + y);
            else System.out.println(y + " " + x);
        }
    }
}


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

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

ll mod = (ll)(1e9+7);

int main(){
  ll l,r,d;
  cin >> l >> r >>d;

  ll ans = 0;
  for(ll i = 1; i <=100; i++){
    if(i*d >= l && i*d <= r){
      ans ++;
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i=(a); i<(b); i++)

int main() {
  int H, W;
  cin >> H >> W;
  string board[50];
  FOR(i,0,H) cin >> board[i];
  int dx[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
  int dy[8] = {1, 1, 1, 0, -1, -1, -1, 0};
  
  FOR(i,0,H) {
    FOR(j,0,W) {
      if(board[i][j] == '#') continue;
      
      int num = 0;
      FOR(d,0,8) {
        int ni = i + dy[d];
        int nj = j + dx[d];
        if (ni < 0 or H <= ni) continue;
        if (nj < 0 or W <= nj) continue;
        if (board[ni][nj] == '#') num++;
      }
      
      board[i][j] = char(num + '0');
    }
  }
  
  FOR(i,0,H) cout << board[i] << endl;
      
}




Measured memory_bytes: 3604