akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)



int main(){
	int X0,Y0,N; cin >> X0 >> Y0 >> N;	
	vector<pair<int,int>> V;
	vector<int> a(Y0+1);
	repp(i,0,N){
		int X,Y; cin >> X >> Y;
		V.push_back(MP(Y,X));
	}
	sort(V.begin(),V.end());
	a[1] = 1;
	auto it = V.begin();
	repp(i,1,Y0){
		a[i+1] = a[i] + 1;
		while(it != V.end() && ((*it).first <= i || ((*it).first == i+1 && (*it).second < a[i+1]))) ++it;
		while(it != V.end() && (*it).first == i+1 && (*it).second == a[i+1]){++it; ++a[i+1];}
	}
	int ans = X0;
	for(auto u : V){
		if(u.second > a[u.first]) ans = min(ans,u.second-1);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4212
n=int(input())
a=sorted(map(int,input().split()))[::-1]
j=i=0
while i<n and a[i]>i:i+=1
while j<n and a[j]>=i:j+=1
print('SFeicrosntd'[(a[i-1]^i)&1|(j^i)&1::2])


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

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

ll GetDigit(unsigned num){
    ll digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}
int main(){
  ll N ;
  cin >> N ;
  ll ans = 10e9 ;
  vector<ll> A = divisor(N) ;
  int M = A.size() ;
  //rep(i,M) cout << A[i] << endl;
  for(int i = 0 ; i < M ; i++ ) ans = min( ans , max( GetDigit(A[i]) ,GetDigit( N/A[i] ) ) ) ;
  cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())

s = [list(map(str, input().split())) for _ in range(n)]
for row in s:
    row[1] = int(row[1])
ss = sorted(s)
ins = 0
ans = list()
tmp = 0
for i in ss:
    if i[0] == tmp:
        ans.insert(ins,i)
    else:
        ins = len(ans)
        ans.append(i)
        tmp = i[0]
for j in ans:
    print(s.index(j)+1)


Measured memory_bytes: 9140
{-# LANGUAGE BangPatterns, MultiWayIf #-}

import Control.Applicative
import Control.Monad
import Data.List
import Debug.Trace (traceShow, traceShowM)

main :: IO ()
main = do
    [x, y] <- fmap read . words <$> getLine :: IO [Int]
    print $ x + y `div` 2

Measured memory_bytes: 508
until (l = gets.to_i).zero?
  data = 12.times.map {gets.split.map(&:to_i)}
  month_number = "NA"
  
  acc = 0
  data.each_with_index do |mn, i|
    acc += mn[0] - mn[1]
    if acc >= l
      month_number = i + 1
      break
    end
  end
  
  puts month_number
end


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

const int N = 405;
const int mod = 998244353;
int len[N], c[N][N], ex[N], f[N][N], g[N][N], tf[N], h[N];
int n, T, rt;

inline int quick_pow(int x, int k)
{
	int res = 1;
	while (k)
	{
		if (k & 1)
			res = 1ll * res * x % mod;
		x = 1ll * x * x % mod;
		k >>= 1;
	}
	return res;
}

inline void add(int &x, int y)
{
	x += y;
	x >= mod ? x -= mod : 0;
}

inline void dec(int &x, int y)
{
	x -= y;
	x < 0 ? x += mod : 0;
}

inline int solve(int l, int r, int lst)
{
	if (l > r)
		return 0;
	
	int mid = l, now = ++T;
	for (int i = l + 1; i <= r; ++i)
		if (h[i] < h[mid])
			mid = i;

	int lc = solve(l, mid - 1, h[mid]),
		rc = solve(mid + 1, r, h[mid]);
	for (int i = 0; i <= len[lc]; ++i)
		for (int j = 0; j <= len[rc]; ++j)
		{
			int t = i + j;
			int a = 1ll * f[lc][i] * f[rc][j] % mod,
				b = (1ll * g[lc][i] * (f[rc][j] + g[rc][j]) + 1ll * f[lc][i] * g[rc][j]) % mod;
			add(f[now][t], a);
			add(g[now][t], b);
			dec(f[now][t + 1], a);
			add(g[now][t + 1], a);
		}
	len[now] = len[lc] + len[rc] + 1;
	for (int j = 0; j <= len[now]; ++j)
	{
		f[now][j] = 1ll * f[now][j] * quick_pow(ex[len[now] - j], h[mid] - lst) % mod;
		g[now][j] = 1ll * g[now][j] * quick_pow(ex[len[now] - j] - 1, h[mid] - lst) % mod;
	}
	return now;
}

int main()
{
	f[0][0] = 1;
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i)
		scanf("%d", &h[i]);

	ex[0] = 1;
	for (int i = 1; i <= n; ++i)
		add(ex[i] = ex[i - 1], ex[i - 1]);
	rt = solve(1, n, 0);

	int ans = 0;
	for (int i = 0; i <= n; ++i)
	{
		add(ans, f[rt][i]);
		add(ans, g[rt][i]);
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 1536
l = []
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
f = int(input())
g = int(input())
h = int(input())
i = int(input())
j = int(input())

l.append(a)
l.append(b)
l.append(c)
l.append(d)
l.append(e)
l.append(f)
l.append(g)
l.append(h)
l.append(i)
l.append(j)

l.sort()
print(l[-1])
print(l[-2])
print(l[-3])

Measured memory_bytes: 7688
#include <iostream>

using namespace std;
typedef long long int ll;

int main()
{
    ll e;
    while( cin >> e, e != 0 ) {
        ll mm = 99999999;

        ll z[101];
        ll zn = 0;
        for( ll i=0; i<=100; ++i ) {
            z[zn] = e - i*i*i;
            ++zn;
        }

        for( ll i=0; i<=100*100*100; ++i ) {
            for( ll j=0; j<zn ;++j ) {
                if ( z[j] - i*i < 0 )
                    break;
                
                ll const vy = i*i;
                ll const vz = -(z[j] - e);
                ll const vx = z[j] - vy;
                
                if ( vx + vy + vz != e )
                    break;
                
                if ( i + j + vx < mm ) {
                    mm = i + j + vx;
                }
            }
        }
        cout << mm << endl;
    }
}

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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

int main()
{
    lint n;cin >> n;
    string s;
    cin >> s;
    
    cout << ((n<3200) ? "red" : s) <<"\n";

    return 0;
}

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

int main() {
  vector<int> v(5);
  for(int i = 0; i < v.size(); i++) cin >> v.at(i);
  sort(v.begin(), v.end());

  int k;  cin >> k;
  if(v.at(4) - v.at(0) > k) cout << ":(" << endl;
  else cout << "Yay!" << endl;

}


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

class Main {

  private static long INF = Long.MAX_VALUE / 4;

  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int N = Integer.parseInt(scanner.next());
    int K = Integer.parseInt(scanner.next());
    int[] h = new int[N];
    for (int i = 0; i < N; i++) {
      h[i] = Integer.parseInt(scanner.next());
    }
    scanner.close();
    long[] dp = new long[N];
    Arrays.fill(dp, INF);
    dp[0] = 0;
    for (int i = 0; i < N; i++) {
      for (int j = 1; j <= K && i - j >= 0; j++) {
        dp[i] = Math.min(dp[i], dp[i - j] + (long) Math.abs(h[i] - h[i - j]));
      }
    }
    System.out.println(dp[N - 1]);
  }

}


Measured memory_bytes: 50540
#include <iostream>
#include <cstring>
#include <vector>
#include <set>
#include <list>
#include <map>
#include <deque>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
#define for1(i,n) for (ll i=0;i<(n);i++)
#define for2(i,m,n) for (ll i=(m);i<(n);i++)
#define for3(i,m,n,d) for (ll i=(m);i<(n);i+=(d))
#define DEBUG 0
template <class T>
void dumplist(T list)
{
    for (auto item : list) {
        cout << item << " ";
    }
    cout << endl;
}

// 1000000007 で割ったあまりを扱う構造体
template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) v += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr istream& operator >> (istream &is, Fp<MOD>& x) noexcept {
        return is >> x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};
const int MOD = 1000000007;
using mint = Fp<MOD>;

void solve()
{
    ll N,M;
    cin >> N >> M;
    vector<mint> dp(N+1,0);
    vector<bool> broken(N+1,false);
    dp[0] = 1;
    for1(i,M) {
        ll a;
        cin >> a;
        broken[a] = true;
    }
    for2(i,1,N+1) {
        dp[i] = 0;
        if (!broken[i]) {
            if (i-2 >= 0) {
                dp[i] += dp[i-2];
            }
            dp[i] += dp[i-1];
        }
    }
    cout << dp[N] << endl;
}

int main()
{
    do {
        solve();
    } while (DEBUG);
}


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

int main(void){
    ll N,ans=10000000000000;
    cin >> N;
    for(int i=1;i<=sqrt(N);i++){
        if(N%i==0) ans=min(ans,i+(N/i)-2);
    }
    cout << ans;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define int long long
#define int32 int32_t
#define PI 2 * acos(0)

using namespace std;

vector<vector<int>>roads(100000);

int find(vector<int>road, int x) {
    for(auto k : road) {
        if(k == x) {
            return 1;
        }
    }
    return 0;
}


int32 main() {
    ios_base::sync_with_stdio(false);
    int n,m,x, k;
    cin >> n >> m;
    vector<int>kek;
    for(int i = 0; i < n; i++) {
        cin >> x; kek.push_back(x);
    }

    for(int i = 0; i < m; i++) {
        cin >> x >> k;
        x--;k--;

        if(find(roads[x], k) == 0) {
            roads[x].push_back(k);
            roads[k].push_back(x);
        }
    }

    int norm = 0;
    for(int i = 0; i < n; i++) {
        bool once = false;
        if(roads[i].empty()) {
            norm++;
            continue;
        }
        for(int j = 0; j < roads[i].size(); j++) {
            if(kek[i] <= kek[roads[i][j]]) {
                once = true;
                break;
            }
        }
        if(!once) {
            norm++;
        }

    }

    cout << norm;

    return 0;
 }

Measured memory_bytes: 9840
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
int main() {
    int n; cin >> n;
    vector<int> c(n);
    for (int i = 0; i < n; i++) cin >> c[i];
    vector<long long> dp(n+1, 0); dp[0] = 1;
    map<int, int> prev;
    for (int i = 0; i < n; i++) {
        dp[i+1] = dp[i];
        if (prev[c[i]] != 0) {
            if (prev[c[i]] != i) {
                dp[i+1] += dp[prev[c[i]]];
                dp[i+1] %= mod;
            }
        }
        prev[c[i]] = i+1;
    }
    cout << dp[n] << endl;
    return 0;
}

Measured memory_bytes: 12032
#include <bits/stdc++.h>
#define REP(i,a,b) for(int(i)=(a);(i)<(b);++(i))
#define RREP(i,a,b) for(int(i)=(a)-1;(i)>=(b);--(i))
#define ALL(x) (x).begin(),(x).end()
// #define chmin(x,v) x = min(x, v)
// #define chmax(x,v) x = max(x, v)
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; }
using namespace std;
typedef long long ll;

int main()
{
  ll N,M;
  cin >> N >> M;
  vector<ll> A(N);
  REP(i,0,N) cin >> A[i];
  sort(ALL(A));

  vector<pair<ll,ll>> CB(M);
  REP(i,0,M) {
    ll B,C;
    cin >> B >> C;
    CB[i] = make_pair(C,B);
  }
  sort(ALL(CB), greater<>());  // Cでソート

  vector<int> D(N, 0);  // サイズは最大でN
  int k = 0;  // Dの位置
  REP(i,0,M) {
    ll B,C;
    tie(C,B) = CB[i];
    while (B > 0 && k < N) {
      D[k] = C;
      ++k;
      --B;
    }
  }
  // REP(i,0,N) cout << D[i] << endl;

  // X枚書き換えるとする(DからX枚取る)
  ll ans = 0;
  REP(i,0,N) ans += A[i];  // 初期値: すべてAから取る
  REP(X,0,N) {
    // X枚目を新たに A[X]からD[X]に
    if (D[X] > A[X]) {
      ans = ans - A[X] + D[X];
    } else {
      break;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 2944
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function (chunk) {
    var nums = chunk.split(" ");
    for(var i = 0; i < nums.length; i ++){
        nums[i] = Number(nums[i]);
    }
    var output = "No";
    var length = nums.length;
    while(length > 0){
       for (var i = 0; i < nums.length; i ++){
            // console.log("i = " + i);
            if (nums[i] > nums[i + 1]){
                var temp = nums[i];
                nums[i] = nums[i + 1];
                nums[i + 1] = temp;
            }
       }
       length --;
    }
    output = nums[0] + " " + nums[1] + " " + nums[2];
    console.log(output);
});



Measured memory_bytes: 15280
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>

using namespace std;
class bTree{
	int Id;
	int parent;
	int depth;
	int degree;
	int sibling;
	int hight;
	string type;
	int left, right;
public:
	bTree(){
		Id = 0, parent = -1, depth = 0, type = "", left = -1, right = -1,
			degree = 0, sibling = -1, hight = 0;
	}	
	int takeId(){ return this->Id; }
	int takeParent(){ return this->parent; }
	int takeDepth(){ return this->depth; }
	int takeDegree(){ return this->degree; }
	int takeSibling(){ return this->sibling; }
	int takeHight(){ return this->hight; }
	int takeLeft(){ return this->left; }
	int takeRight(){ return this->right; }
	string takeType(){ return this->type; }
	void setId(int a){ this->Id = a; }
	void setParent(int a){ this->parent = a; }
	void setDepth(int a){ this->depth = a; }
	void setSibling(int a){ this->sibling = a; }
	void setLeft(int a){ this->left = a; }
	void setRight(int a){ this->right = a; }
	void setHight(int a){ this->hight = a; }
	void setType(){
		if (this->parent == -1) this->type = "root";
		else if (this->left == -1 && this->right==-1) this->type = "leaf";
		else this->type = "internal node";
	}
	void setDegree(){
		if (this->left == -1 && this->right == -1) this->degree = 0;
		else if (this->left == -1 || this->right == -1) this->degree = 1;
		else this->degree = 2;
	}
};
bTree nodes[25];
void calcDepth(int Id, int Depth){
	nodes[Id].setDepth(Depth);
	int left = nodes[Id].takeLeft();
	if (left != -1) calcDepth(left, Depth + 1);
	int right = nodes[Id].takeRight();
	if (right != -1) calcDepth(right, Depth + 1);
	return;
}
int calcHight(int Id){
	int left = nodes[Id].takeLeft();
	int right = nodes[Id].takeRight();
	int hight = 0;
	if (left != -1) hight = max(hight, calcHight(left) + 1);
	if (right != -1) hight = max(hight, calcHight(right) + 1);
	nodes[Id].setHight(hight);
	return hight;
}
int main(){
	int n; scanf("%d",&n);
	for (int i = 0; i < n;++i){
		int id, Lchild, Rchild; scanf("%d %d %d", &id, &Lchild, &Rchild);
		nodes[id].setId(id);
		nodes[id].setLeft(Lchild);
		if (Lchild != -1) {
			nodes[Lchild].setParent(id);
			if (Rchild != -1) nodes[Rchild].setSibling(Lchild);
		}
		nodes[id].setRight(Rchild);
		if (Rchild != -1){
			nodes[Rchild].setParent(id);
			if (Lchild != -1) nodes[Lchild].setSibling(Rchild);
		}
	}
	for (int i = 0; i < n; ++i) nodes[i].setType(), nodes[i].setDegree();
	int p = -1;
	for (int i = 0; i < n; ++i) if (nodes[i].takeParent() == -1){ p = i; break; }
	calcDepth(p, 0);
	calcHight(p);
	for (int i = 0; i < n; ++i){
		cout << "node " << nodes[i].takeId()
			<< ": parent = " << nodes[i].takeParent()
			<< ", sibling = " << nodes[i].takeSibling()
			<< ", degree = " << nodes[i].takeDegree()
			<< ", depth = " << nodes[i].takeDepth()
			<< ", height = " << nodes[i].takeHight()
			<< ", " << nodes[i].takeType() << '\n';
	}
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n); i++)
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
using namespace std;
using ll = long long;
int INF = 1001001001;

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

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

typedef string::iterator State;
typedef long long ll;

#define MOD 1000000007

string s;

ll expr(State &begin);

ll fast_pow_limit(ll x, ll n, ll lim) {
	ll ret = 1;
	while(n>0) {
		if(x > lim) return x;
		if(n&1) {
			ret *= x;
			if(ret > lim) return ret;
		}
		x = x * x;
		n >>= 1;
	}
	return ret;
}

ll number(State &begin) {
	ll ret = 0; bool ok = false;
	State bak = begin;
	while(isdigit(*begin)){
		ret = 10*ret + (*begin - '0');
		++begin; ok = true;
	}
	return ok ? ret : -1;
}

void sp(State &begin) {
	while(*begin==' ') ++begin;
}

ll term(State &begin) {
	if(begin==s.end()) return -1;
	ll ret = 0, r;
	if(*begin=='S') {
		++begin; // 'S'
		sp(begin);
		++begin; // '<'
		sp(begin);
		r = expr(begin);
		ret = (r * r) % MOD;
		sp(begin);
		++begin;
	}else {
		ret = number(begin);
	}
	return ret;
}

ll expr(State &begin) {
	ll ret = term(begin), r;
	while(begin!=s.end()) {
		State bak = begin;
		sp(begin);
		if(begin!=s.end() && begin+1!=s.end() && *begin=='>' && *(begin+1)=='>') {
			begin += 2;
			sp(begin);
			r = term(begin);
			if(r==-1) {
				begin = bak;
				break;
			}
			ret = ret / fast_pow_limit(2, r, ret);
		}else {
			begin = bak;
			break;
		}
	}
	return ret;
}

int main() {
	while(1) {
		getline(cin, s);
		if(s[0]=='#') break;
		State begin = s.begin();
		cout << expr(begin) << endl;
	}
	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

struct UnionFind{
  vector<int> v;
  vector<ll> sum;
  UnionFind(int n) : v(n, -1), sum(n,0){}
  void init(){ for(int i = 0;i < (int)v.size();i++)v[i]=-1; }
  int find(int x) { return v[x] < 0 ? x : find(v[x]); }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (-v[x] < -v[y]) swap(x, y);
    sum[x] += sum[y];
    v[x] += v[y]; v[y] = x;
    return true;
  }
  bool root(int x) { return v[x] < 0; }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int x) { return -v[find(x)]; }
};

ll N,M;
ll A[100010],B[100010];
vector<ll> g[100010];
ll X[100010];

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

  cin>>N>>M;
  vector<ll> ord;
  rep(i,N){
    cin>>A[i]>>B[i];
    ord.push_back(i);
  }
  rep(i,M){
    ll a,b;
    cin>>a>>b;
    a--;b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  sort(all(ord),[=](const ll& a,const ll& b){ return A[a]-B[a] < A[b]-B[b]; });
  UnionFind uf(N);
  rep(i,N){
    uf.sum[i]=B[i];
    X[i]=INF;
  }

  for(ll v : ord){
    X[v]=max(0LL,A[v]-B[v]);
    for(ll nv : g[v]){
      ll f=uf.find(nv);
      if(X[f]==INF)continue;
      ll tot=uf.sum[f]+X[f];
      minch(X[v],X[f]+max(0LL,A[v]-B[v]-tot));
    }
    for(ll nv : g[v]){
      ll f=uf.find(nv);
      if(X[f]==INF)continue;
      uf.unite(v,nv);
    }
    ll f=uf.find(v);
    X[f]=X[v];
  }
  cout<<X[uf.find(0)]+uf.sum[uf.find(0)]<<endl;

  return 0;
}


Measured memory_bytes: 10612
#include<iostream>
#include<stdio.h>
#include<cctype>
#include<string>
#include<cmath>
using namespace std;

class DICE{

public:

	static int dice(int a, int b, int c, int d, int e, int f, int s, string order) {
		int N[100] = { a, b, c, d, e, f };
		for (int i = 0; i < s; i++) {
			if (order[i] == 'S') {
				swap(N[0], N[4]);
				swap(N[4], N[5]);
				swap(N[1], N[5]);

			}
			else if (order[i] == 'E') {
				swap(N[0], N[3]);
				swap(N[3], N[5]);
				swap(N[5], N[2]);

			}
			else if (order[i] == 'W') {
				swap(N[0], N[2]);
				swap(N[2], N[5]);
				swap(N[5], N[3]);

			}
			else if (order[i] == 'N') {
				swap(N[0], N[1]);
				swap(N[1], N[5]);
				swap(N[5], N[4]);

			}
		}
		return N[0];

	}
};

int main() {
	int a, b, c, d, e, f, s, N;
	string order;
	cin >> a >> b >> c >> d >> e >> f >> order;

	

	DICE dice;

	N = dice.dice(a, b, c, d, e, f, order.size(), order);
	cout << N << endl;
	return 0;
}




Measured memory_bytes: 3192
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int t = sc.nextInt();
		for(int i=0;i<t;i++) {
			solve();
		}
	}
	static void solve() {
		int n = sc.nextInt();
		ArrayList<Frac> al = new ArrayList<Frac>();
		for(int i=0;i<n;i++) {
			String r = sc.next();
			int m = r.length() / 2;
			for(int j=0;j<m;j++) {
				int p = Integer.parseInt(r.substring(j*2, j*2+2), 16);
				for(int k=0;k<8;k++) {
					if ((p>>k&1) == 1) {
						al.add(new Frac(j,m,k));
					}
				}
			}
		}
		int lcm = 1;
		for(Frac f:al) {
			lcm = (int) Frac.lcm(lcm, f.b);
			if (lcm > 1024) {
				break;
			}
		}
		if (lcm > 1024) {
			System.out.println("Too complex.");
			return;
		}
//		System.out.println(lcm);
		int[] pattern = new int[lcm];
		for(Frac f:al) {
			pattern[(int) (f.a * lcm / f.b)] |= 1 << f.type;
		}
		StringBuilder sb = new StringBuilder();
		for(int p:pattern) {
			String s = Integer.toHexString(p).toUpperCase();
			if (s.length() == 1) {
				s = "0" + s;
			}
			sb.append(s);
		}
		System.out.println(sb.toString());
	}
}
class Frac {
	long a,b;
	int type;
	public Frac(long a,long b,int type) {
		long g = gcd(a,b);
		this.a = a / g;
		this.b = b / g;
		this.type = type;
	}
	public static long gcd(long a,long b) {
		while(b!=0) {
			long r = a%b;
			a = b;
			b = r;
		}
		return a;
	}
	public static long lcm(long a,long b) {
		return a / gcd(a,b) * b;
	}
}

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

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

int main(int argc, char const *argv[]) {
    long long a, b;
    long long c, d;
    cin >> a >> b >> c >> d;

    long long ans = b - a + 1;
    long long num_c = b/c - (a-1)/c;
    long long num_d = b/d - (a-1)/d;
    long long num_cd = b/((c * d)/gcd(c, d)) - (a-1)/((c * d)/gcd(c, d));

    ans = ans - num_c - num_d + num_cd;
    cout << ans << endl;
    return 0;
}


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

int main(){
  int N;
  cin >> N;
  vector<int> H(N);
  for(int i=0;i<N;i++){
    cin >> H.at(i);
  }
  vector<long long> dp(N,10000000000000000);
  dp.at(0)=0;
  for(int i=1;i<N;i++){
    if(i==1){
      dp.at(1)=min(dp.at(1),dp.at(0)+abs(H.at(0)-H.at(1)));
    }
    else{
      dp.at(i)=min({dp.at(i),dp.at(i-2)+abs(H.at(i-2)-H.at(i)),dp.at(i-1)+abs(H.at(i-1)-H.at(i))});
    }
  }
  cout << dp.at(N-1) << endl;
} 

Measured memory_bytes: 4236
#include <iostream>
#include <cstdio>
#include <iomanip>

#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>

#include <numeric>
#include <algorithm>
#include <functional>

#include <cctype>

#include <complex>
#include <string>
#include <sstream>

using namespace std;

#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define rep(i,n) for(unsigned int i=0;i<(n);i++)
#define tr(it,container) for(typeof(container.begin()) it = container.begin(); \
                                                  it != container.end(); ++it)

typedef long long ll;
typedef complex<double> P;
const int dx[] = {1,0,-1,0};
const int dy[] = {0,-1,0,1};
const double EPS = 1e-9;
const int days[] = {31,28,31,30,31,30,31,31,30,31,30,31};
const int daysleap[] = {31,29,31,30,31,30,31,31,30,31,30,31};

int main(){
    while(true){
        int N,Q;
        cin >> N >> Q;
        if(N==0) break;
        vector<int> Fr(100,0);
        rep(i,N){
            int M;
            cin >> M;
            rep(j,M){
                int x;
                cin >> x;
                Fr[x]++;
            }
        }
        int ma = *max_element(all(Fr));
        if(ma < Q){
            cout << 0 << endl;
        }else{
            cout << max_element(all(Fr)) - Fr.begin() << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1196
#include<stdio.h>
main()
{
	int r;
	scanf("%d", &r);
	if(0<=r && r<1200){
		printf("ABC");
	}if(1200<=r && r<2800){
		printf("ARC");
	}if(2800<=r && r<=4208){
		printf("AGC");
	}
}

Measured memory_bytes: 128
n, m = map(int, input().split())
num = ["n"] * n
for _ in range(m):
    s,c = map(int,input().split())
    if not(num[s-1] == "n" or num[s-1] == str(c)) or (n != 1 and s == 1 and c == 0):
        print(-1)
        exit()
    else:
        num[s-1] = str(c)

op = ""
for ns in range(len(num)):
    if num[ns] == "n": 
        if ns == 0 and n != 1 : op += "1"
        else: op += "0"
    else: op += num[ns]
print(op)


Measured memory_bytes: 3064
def ConnectionAndDisconnection(S, K):
	total = 0
	altS = ''
	minus1 = False
	if S[0] == S[-1]:
		char = S[0]
		S1 = ''
		for i in range(len(S)):
			if S[i] != char:
				S1 = S[i:]
				break

		if S1 == '':
			rslt = int(len(S) * K / 2)
			print(rslt)
			exit
		else:
			rev1 = S1[::-1]
			for i in range(len(rev1)):
				if rev1[i] != char:
					rev2 = rev1[i:]
					break
			altS = rev2[::-1]
			total += int((len(S) - len(altS)) / 2)
			if (len(S) - len(altS)) % 2 == 0:
				minus1 = True
	else:
		altS = S

	if altS != '':
		T = altS + '_'
		tmpcnt = 0
		for i in range(len(T) - 1):
			if T[i] == T[i+1]:
				tmpcnt += 1
			else:
				total += int((tmpcnt+1) / 2)
				tmpcnt = 0

		rslt = total * K
		if minus1:
			rslt -= 1
		print(rslt)

S = str(input())
K = int(input())
ConnectionAndDisconnection(S, K)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s,t;
    cin>>s>>t;
    int i=0,j=0;
    int cnt=0;
    while(i<3 && j<3)
    {
        if(s[i]==t[j])
        cnt++;
        
        i++;
        j++;
    }
    cout<<cnt;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, start, n) for (ll i = (ll)(start); i < (ll)(n); ++i)
static const ll INFTY = 1L << 62L;
ll solver(ll n, ll m)
{
    ll base = 1900 * m + 100 * (n - m);
    return base * 1 << m;
}
int main()
{
    ll n, m;
    cin >> n >> m;
    cout << solver(n, m) << endl;
}

Measured memory_bytes: 3624
N, M = map(int, input().split())
H = [None] + list(map(int, input().split()))
r = [None] + [[] for _ in range(N)]
for _ in range(M):
    Ai, Bi = map(int, input().split())
    r[Ai].append(Bi)
    r[Bi].append(Ai)

ans = 0
for i in range(1, N + 1):
    for j in r[i]:
        if H[j] >= H[i]:
            break
    else:
        ans += 1

print(ans)


Measured memory_bytes: 30172
#include <stdio.h>

int main(void) {
	char num[3];
	scanf("%s",num);
	int a = 0 ;
	if (num[0] == '1') a++;
	if (num[1] == '1') a++;
	if (num[2] == '1') a++;
	printf("%d",a);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

static const double PI = 3.14159265358979;
static const ll MOD = 1e9 + 7;
static const ll INF = (ll)1 << 62;

int main() {
	ll x, y; cin >> x >> y;
	cout << x + y / 2 << endl;

	return 0;
}

Measured memory_bytes: 256
import * as fs from 'fs';

const input = fs.readFileSync('/dev/stdin', 'utf8');
const args: string[][] = input.split('\n').map(l => l.split(' '));

const n = parseInt(args[0][0]);
const s: string[] = [];
for (let i = 0; i < n; i++) {
    s.push(args[i + 1][0]);
}

const set = new Set();

s.forEach(str => {
    set.add(str)
});

const cnt = [...set].length;

console.log(cnt);


Measured memory_bytes: 87396
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define sz(x) ((int)(x).size())
typedef long long ll;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VP = vector<P>;
template<typename T> void view(T e){std::cout << e << std::endl;}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

const int inf = 1 << 30;
const ll INF = 1LL << 60;

int main(){
    string s, t;
    cin >> s >> t;
    sort(all(s));
    sort(rall(t));
    if (s < t) view("Yes");
    else view("No");
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
#define int long long int

signed main(){
    
    string s; cin >> s;
    int n = (int)s.size();
    string t = "AIDUNYAN";
    string aizu = "AIZUNYAN";
    sort(t.begin(), t.end());
    for(int i = 0; i <= n - 8; i++){
        string tmp = s.substr(i, 8);
        sort(tmp.begin(), tmp.end());
        if(t == tmp){
            string u = "";
            for(int j = 0; j < i; j++) u.push_back(s[j]);
            u = u + aizu;
            for(int j = i + 8; j < n; j++) u.push_back(s[j]);
            s = u;
            i += 7;
        }
    }

    cout << s << endl;
    return 0;
}



Measured memory_bytes: 3236
#include<bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(i=0;i<n;i++)
#define rep1(i,n) for(i=1;i<n;i++)
int main(){
  int a,b,c;
  int numA = 1000;
  int sumA,i;
  int YESFrag = 0;
  
  cin >> a >> b >> c;
  
  rep1(i,numA){
    sumA = i * a; 
    if(sumA % b == c){
      YESFrag = 1;
      break; 
    }
  }
  
  if(YESFrag == 1)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
map<int,int> mp;
int main(){
	int n,a;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a;
		if(mp[a]!=0){
			cout<<"NO";
			return 0;
		}
		mp[a]++;
	}
	cout<<"YES";
	return 0;
}

Measured memory_bytes: 10624
import sys
from math import atan, degrees

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def main():
    a, b, x = map(int, readline().split())
    if x > a * a * b / 2:
        ans = atan((2 * a * a * b - 2 * x) / (a ** 3))
    else:
        ans = atan(a * b * b / (2 * x))

    print(degrees(ans))
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int val=n%10;
    if(val==3)
        cout<<"bon";
    else if(val==0 || val==1 || val==6 || val==8)
        cout<<"pon";
    else
        cout<<"hon";
    return 0;
}


Measured memory_bytes: 3636
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll n,k,x,y;


ll gcd(ll a,ll b){
  ll r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
return b;
}


int main(){
  ll ans=1LL;
  cin >> n >> k;
  ll g=gcd(n,k);


// エラトステネスのふるい
  int MAX = 1000001;
  vector<int> is_prime(MAX, 1);
  is_prime[0] = 0, is_prime[1] = 0;
  for (int i = 2; i < MAX; ++i) {
      if (!is_prime[i]) continue;
      for (int j = i*2; j < MAX; j += i) is_prime[j] = 0;
  }


REP(i,1000000){
  if (g%(i+1)==0LL){
    if (is_prime[i+1]==1){
      ans++;
      while(g%(i+1)==0){
        g/=(i+1);
      }
    }
  }
}

if (g!=1)ans++;

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

Measured memory_bytes: 4224
#include<iostream>
#include<vector>
#include<bits/stdc++.h>
#define ll long long
using namespace std;
vector<ll int> dp,arr;
ll int solve(int N, int cur = 0){
    if(cur == N - 1) return 0;
    if(cur == N - 2) return abs(arr[cur+1] - arr[cur]);
    if(dp[cur] != -1) return dp[cur];

    ll int one_jump = 0,two_jump = 0;
    one_jump = abs(arr[cur+1] - arr[cur]) + solve(N,cur+1);
    two_jump = abs(arr[cur+2] - arr[cur]) + solve(N,cur+2);
    ll int res = min(one_jump,two_jump);
    
    dp[cur] = res;
    return res;
}
int main(){
    int N;
    cin>>N;
    arr = vector<ll int>(N);
    dp = vector<ll int>(N, -1);
    for(int i = 0; i < N; i++){
        cin>>arr[i];
    }
    cout<<solve(N);
}

Measured memory_bytes: 11008
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod= 1e+9+7;

int main(){
   int n; cin>>n;
   if(n/10==9 ||n%10==9)cout<<"Yes"<<endl;
   else cout<<"No"<<endl;
   
}


Measured memory_bytes: 256
import sys
import math
import collections
import bisect
import itertools

# import numpy as np

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: map(int, sys.stdin.readline().rstrip().split())
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))


# ===CODE===

def main():
    h, w, d = ns()
    pos = dict()
    for i in range(h):
        a = na()
        for j, ai in enumerate(a):
            pos[ai - 1] = (i, j)

    cum = [[0] for _ in range(d)]

    for i in range(d):
        x, y = pos[i]
        num = i
        while num + d < h * w:
            num += d
            xi, yi = pos[num]
            tmp = abs(xi - x) + abs(yi - y)
            cum[i].append(cum[i][-1] + tmp)
            x, y = xi, yi

    q = ni()
    for _ in range(q):
        l, r = ns()
        l, r = l - 1, r - 1
        tmp = cum[l % d][r // d] - cum[l % d][l // d]
        print(tmp)


if __name__ == '__main__':
    main()


Measured memory_bytes: 31604
n, a, b = map(int, input().split())
a, b = min(a, n-a), min(b, n-b)
mod = 10**9 +7

def my_pow(num, p, mod):
    if p==0:
        return 1
    elif p%2==0:
        return (my_pow(num, p//2, mod)**2)%mod
    else:
        return (my_pow(num, p-1, mod)*num)%mod

def comb(num, r, mod):
    r = min(r, num-r)
    y = 1
    for i in range(num-r+1, num+1):
        y = (y*i)%mod
    x = 1
    for i in range(1, r+1):
        x = (x*i)%mod
    return (y*my_pow(x, mod-2, mod))%mod

result = my_pow(2, n, mod)-1 -comb(n, a, mod) -comb(n, b, mod)
while result < 0:
    result += mod
print(result)

Measured memory_bytes: 3064
#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 repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
template <typename T, typename S> istream& operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S> ostream& operator<<(ostream &os, pair<T, S> &p) { os << p.first << ' ' << p.second; return os; }

void solve() {
  while (true) {
    int w, h; cin >> w >> h;
    if (w == 0) return;
    vstr a(h); rep(i, h) cin >> a[i];
    int sx, sy;
    rep(i, h) rep(j, w) if (a[i][j] == '@') sx = i, sy = j;
    int cnt = 0;
    function<void(int, int)> rec = [&](int x, int y) {
      cnt++;
      a[x][y] = '#';
      rep(i, 4) {
        int wx = x + (i - 1) % 2;
        int wy = y + (i - 2) % 2;
        if (wx < 0 || wx >= h || wy < 0 || wy >= w) continue;
        if (a[wx][wy] == '#') continue;
        rec(wx, wy);
      }
    };
    rec(sx, sy);
    cout << cnt << '\n';
  }
}



Measured memory_bytes: 3136
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int N; cin >> N;
  vector<ll> A(N); rep(i,N) cin >> A[i];
  sort(all(A));
  vector<ll> B = A; reverse(all(B));
  ll ans = 0;
  // 1 2 3 6 8
  // 2 6 1 8 3
  //
  // 1 1 3 4 5 9
  // 4 1 9 1 5 3
  //
  // 1 5 5
  // 5 1 5
  ll ans1=0, ans2=0;
  vector<ll> C;
  C.pb(A[N/2]);
  int cnt = 0;
  while(cnt!=N-1){
    if(cnt%2==1) C.pb(A[N-1-cnt/2]);
    else C.pb(A[cnt/2]);
    cnt++;
  }
  rep(i,N){
    // cout << C[i] << endl;
    if(i==0) continue;
    ans1 += abs(C[i]-C[i-1]);
  }
  vector<ll> D;
  D.pb(A[N/2]);
  cnt = 0;
  while(cnt!=N-1){
    if(cnt%2==0) D.pb(A[N-1-cnt/2]);
    else D.pb(A[cnt/2]);
    cnt++;
  }
  rep(i,N){
    // cout << D[i] << endl;
    if(i==0) continue;
    ans2 += abs(D[i]-D[i-1]);
  }
  cout << max(ans1, ans2) << endl;
  return 0;
}


Measured memory_bytes: 4084
import java.util.*;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.IntStream;

import static java.util.stream.Collectors.toList;

public class Main {
    private static final Scanner scanner = new Scanner(System.in);
    private static final Consumer<List<String>> consumer = solve();

    public static void main(String[] args) {
        consumer.accept(readInput());
    }

    private static List<String> readInput() {
        final List<String> lineList = new ArrayList<>();
        while (scanner.hasNextLine()) {
            lineList.add(scanner.nextLine());
        }
        return lineList;
    }

    private static Consumer<List<String>> solve() {
        return args -> {
            final List<Long> NAB = Arrays.stream(args.get(0).split(" ")).map(Long::valueOf).collect(toList());
            final Long A = NAB.get(1);
            final Long B = NAB.get(2);
            final List<Long> numList = args.stream().skip(1).map(Long::valueOf).collect(toList());

            Long leftExc = 0L;
            Long rightInc = 1_000_000_000L;

            final Function<AbstractMap.SimpleEntry<Long, Long>, Long> ceil =
                    (entry) -> Double.valueOf(Math.ceil(entry.getKey().doubleValue() / entry.getValue().doubleValue())).longValue();
            while (rightInc - leftExc > 1) {
                Long ans = (rightInc + leftExc) / 2;
                if (numList.stream().mapToLong(x -> ceil.apply(new AbstractMap.SimpleEntry<>(Math.max(0, x - ans * B), A - B))).sum() <= ans) {
                    rightInc = ans;
                } else {
                    leftExc = ans;
                }
            }

            System.out.println(rightInc);
        };
    }

}


Measured memory_bytes: 165780
module Main where

import qualified Data.ByteString.Char8         as BS
import qualified Data.ByteString.Lazy.Char8    as BSL
import qualified Data.ByteString.Builder       as BSB
import           Data.Char                      ( isSpace )
import           Data.List                      ( unfoldr )
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as VM
import qualified Data.Vector.Unboxed           as VU
import qualified Data.Vector.Unboxed.Mutable   as VUM
import qualified Data.Vector.Generic           as VG
import qualified Data.Vector.Generic.Mutable   as VGM
import Data.Vector.Algorithms.Search
import           Control.Monad                  ( forM )

main :: IO ()
main = do
  [n, m, k] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  as <- VU.unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  bs <- VU.unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  as' <- VU.thaw $ VU.scanl1' (+) as
  bs' <- VU.thaw $ VU.scanl1' (+) bs
  ansA <- solve as' bs' k
  ansB <- solve bs' as' k
  print $ max ansA ansB

solve as' bs' k = do
  -- get index of maximum cost of as
  i <- binarySearchR as' k
  anss <- if i == 0 
    then do
      j <- binarySearchR bs' k
      return $ VU.singleton j
    else
      VU.forM (VU.enumFromN 0 i) $ \i' -> do
        accumA <- VUM.read as' i'
        j <- binarySearchR bs' (k-accumA)
        return (i' + j + 1)
  return $ VU.maximum anss


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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const lint MOD   = 1e9 + 7;
const double EPS = 1e-10;

vector<int> memo(1000000, -1);

int dfs(int N) {
    if (memo[N] != -1) return memo[N];

    int res = INF;
    res     = min(dfs(N - 1) + 1, res);

    for (int i = 1; pow(6, i) <= N; i++) {
        res = min(dfs(N - pow(6, i)) + 1, res);
    }
    for (int i = 1; pow(9, i) <= N; i++) {
        res = min(dfs(N - pow(9, i)) + 1, res);
    }

    return memo[N] = res;
}

int main() {
    int N;
    cin >> N;
    memo[0] = 0;
    cout << dfs(N) << endl;

    return 0;
}

Measured memory_bytes: 13748
import heapq
n,q = map(int,raw_input().split())
p = [0] * (n+1)
h = []
for u in xrange(q):
    a,v = map(int,raw_input().split())
    p[a] += v
    heapq.heappush(h,[-p[a],a])
    while True:
        top = heapq.heappop(h)
        if p[top[1]] == -top[0]:
            print "{} {}".format(top[1],-top[0])
            heapq.heappush(h,top)
            break

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

int main()
{
    long long n[4];
    for(int i=0;i<4;i++)
        cin >> n[i];
    long long max = n[0]*n[2];
    if(n[0]*n[3]>max)
        max = n[0]*n[3];
    if(n[1]*n[2]>max)
        max = n[1]*n[2];
    if(n[1]*n[3]>max)
        max = n[1]*n[3];
    cout << max;
    return 0;
}


Measured memory_bytes: 3668
'use strict'

function main(input) {
  input = input.split('\n')[0].split(' ').map(n => Number(n));
  
  const N = input[0];
  const i = input[1];

  const ans = N + 1 - i;
  console.log(ans);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372