akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define lson l,mid,o<<1
#define rson mid+1,r,o<<1|1
using namespace std;
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<LL,LL> PII;
const int INF=0x3f3f3f3f;
const int MAX_N=1e5 + 10;
const LL mod=1e9+7;
const double PI=acos(-1);

int num[MAX_N];
LL to[MAX_N];
LL be[MAX_N];
LL tot[MAX_N];
int main()
{
    int n, m;
    scanf("%d%d", &n, &m);
    for(int i = 1; i <= n; ++i)    scanf("%d", &num[i]);
    for(int i = 1; i <= m; ++i) to[i] = be[i] = tot[i] = 0;
    LL mmax = 0;
    for(int i = 2; i <= n; ++i){
        if(num[i] >= num[i - 1]){
            mmax += num[i] - num[i - 1];           // 计算没有跳的时候的次数
            if(num[i] > num[i - 1] + 1){
                be[num[i - 1] + 1]++;              // 计录从这个位置出发的数量
                to[num[i]] += num[i - 1] + 1;      // 计录所有到这个位置的数字的和
                tot[num[i]]++;                     // 记录到这个位置的数量
            }
        }
        else{
            mmax += num[i] + m - num[i - 1];
            to[num[i]] += num[i - 1] - m + 1;
            tot[num[i]]++;
            if(num[i - 1] == m) be[1]++;
            else{
                be[num[i - 1] + 1]++;
                to[m] += num[i - 1] + 1;
                tot[m]++;
            }
        }
    }
    //cout << mmax << endl;
    LL ans = 0, stot = 0, now = 0;
    for(int i = m; i >= 1; --i){
        stot += tot[i] - be[i];
        now += to[i] - be[i] * i;
        //printf("i = %d, ans = %lld\n", i, mmax - (i * stot - now));
        ans = max(ans, i * stot - now);
    }
    printf("%lld\n", mmax - ans);
    return 0;
}


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

using namespace std;

const int MOD = 1000000007;

template <std::uint_fast64_t Modulus> class ModInt {
  using u64 = std::uint_fast64_t;

public:
  u64 x;

  constexpr ModInt(const u64 x = 0) noexcept : x(x % Modulus){};

  constexpr ModInt operator+(const ModInt rhs) const noexcept {
    return ModInt(*this) += rhs;
  }
  constexpr ModInt operator-(const ModInt rhs) const noexcept {
    return ModInt(*this) -= rhs;
  }
  constexpr ModInt operator*(const ModInt rhs) const noexcept {
    return ModInt(*this) *= rhs;
  }
  constexpr ModInt operator/(const ModInt rhs) const noexcept {
    return ModInt(*this) /= rhs;
  }
  constexpr ModInt &operator+=(const ModInt rhs) noexcept {
    x += rhs.x;
    if (x >= Modulus) {
      x -= Modulus;
    }
    return *this;
  }
  constexpr ModInt &operator-=(const ModInt rhs) noexcept {
    if (x < rhs.x) {
      x += Modulus;
    }
    x -= rhs.x;
    return *this;
  }
  constexpr ModInt &operator*=(const ModInt rhs) noexcept {
    x = x * rhs.x % Modulus;
    return *this;
  }
  constexpr ModInt &operator/=(ModInt rhs) noexcept {
    u64 n = Modulus - 2;
    while (n) {
      if (n & 1) {
        *this *= rhs;
      }
      rhs *= rhs;
      n /= 2;
    }
    return *this;
  }
  constexpr ModInt operator++(int) noexcept {
    ModInt y = *this;
    x += 1;
    return y;
  }
  constexpr ModInt operator--(int) noexcept {
    ModInt y = *this;
    x -= 1;
    return y;
  }
  constexpr bool operator==(const ModInt rhs) noexcept { return x == rhs.x; }
  constexpr bool operator!=(const ModInt rhs) noexcept { return x != rhs.x; }

  friend std::istream &operator>>(std::istream &is, ModInt &rhs) {
    is >> rhs.x;
    return is;
  }
  friend std::ostream &operator<<(std::ostream &os, const ModInt &rhs) {
    os << rhs.x;
    return os;
  }
};

template <typename T> class Combination {
public:
  vector<T> f, invf;

  Combination(int n) : f(n + 1, 1), invf(n + 1, 1) {
    for (int i = 1; i < n + 1; i++) {
      f[i] = f[i - 1] * i;
    }
    invf[n] /= f[n];
    for (int i = n; i > 0; i--) {
      invf[i - 1] = invf[i] * i;
    }
  }

  T comb(int n, int r) {
    if (r < 0 || n < r) return 0;
    return f[n] * invf[r] * invf[n - r];
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M, K;
  cin >> N >> M >> K;
  using mint = ModInt<MOD>;
  Combination<mint> comb(N * M);
  mint sum = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      mint tmp = static_cast<mint>(N - i) * static_cast<mint>(M - j) *
                 static_cast<mint>(i + j);
      if (i != 0 && j != 0) tmp *= 2;
      sum += tmp;
    }
  }
  cout << sum * comb.comb(N * M - 2, K - 2) << '\n';
  return 0;
}


Measured memory_bytes: 3328
local mce, mfl, msq, mmi, mma, mab = math.ceil, math.floor, math.sqrt, math.min, math.max, math.abs
local mod = 1000000007

local function bmul(x, y)
  local x0, y0 = x % 31623, y % 31623
  local x1, y1 = mfl(x / 31623), mfl(y / 31623)
  return (x1 * y1 * 14122 + (x1 * y0 + x0 * y1) * 31623 + x0 * y0) % mod
end
local function badd(x, y)
  return (x + y) % mod
end

local function bsub(x, y)
  return x < y and x - y + mod or x - y
end

local function modpow(src, pow)
  local res = 1
  while 0 < pow do
    if pow % 2 == 1 then
      res = bmul(res, src)
      pow = pow - 1
    end
    src = bmul(src, src)
    pow = mfl(pow / 2)
  end
  return res
end

local function modinv(src)
  return modpow(src, mod - 2)
end

local function getprimes(x)
  local primes = {}
  local allnums = {}
  for i = 1, x do allnums[i] = true end
  for i = 2, x do
    if allnums[i] then
      table.insert(primes, i)
      local lim = mfl(x / i)
      for j = 2, lim do
        allnums[j * i] = false
      end
    end
  end
  return primes
end

local function getdivisorparts(x, primes)
  local prime_num = #primes
  local tmp = {}
  local lim = mce(msq(x))
  local primepos = 1
  local dv = primes[primepos]
  while(primepos <= prime_num and dv <= lim) do
    if(x % dv == 0) then
      local asdf = {}
      asdf.p = dv
      asdf.cnt = 1
      x = x / dv
      while(x % dv == 0) do
        x = x / dv
        asdf.cnt = asdf.cnt + 1
      end
      table.insert(tmp, asdf)
      lim = mce(msq(x))
    end
    if(primepos == prime_num) then break end
    primepos = primepos + 1
    dv = primes[primepos]
  end
  if(x ~= 1) then
    local asdf = {}
    asdf.p, asdf.cnt = x, 1
    table.insert(tmp, asdf)
  end
  return tmp
end


local n = io.read("*n")
local a = {}
for i = 1, n do
  a[i] = io.read("*n")
end
local primes = getprimes(1000)
local alldvs = {}
local dvs = {}
for i = 1, n do
  dvs[i] = getdivisorparts(a[i], primes)
  for j = 1, #dvs[i] do
    local p, c = dvs[i][j].p, dvs[i][j].cnt
    if not alldvs[p] then
      alldvs[p] = c
    else
      alldvs[p] = mma(alldvs[p], c)
    end
  end
end
local ret = 0
local mul = 1
for p, c in pairs(alldvs) do
  mul = bmul(mul, modpow(p, c))
end
for i = 1, n do
  local z = 1
  for j = 1, #dvs[i] do
    local p, c = dvs[i][j].p, dvs[i][j].cnt
    z = bmul(z, modpow(p, c))
  end
  ret = badd(ret, bmul(mul, modinv(z)))
end
print(ret)


Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000001;
constexpr ll INF= 1e18;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<int,int> P;

int main() {
    int N;
    cin >> N;
    vector<ll> vec(3 * N);
    for(int i = 0;i < 3 * N;i++) {
        cin >> vec.at(i);
    }
    vector<ll> cnt(N + 1);
    vector<ll> cnt2(N + 1);
    priority_queue<ll,vector<ll>,greater<ll>> cnt3;
    priority_queue<ll> cnt4;
    ll cnt5 = 0;
    ll cnt6 = 0;
    for(int i = 0;i < N;i++) {
        cnt5 += vec.at(i);
        cnt3.push(vec.at(i));
    }
    cnt.at(0) = cnt5;
    for(int i = 3 * N - 1;i >= 2 * N;i--) {
        cnt6 += vec.at(i);
        cnt4.push(vec.at(i));
    }
    cnt2.at(0) = cnt6;
    for(int i = N;i < 2 * N;i++) {
        cnt5 += vec.at(i);
        cnt3.push(vec.at(i));
        cnt5 -= cnt3.top();
        cnt3.pop();
        cnt.at(i - (N - 1)) = cnt5;
    }
    for(int i = 2 * N - 1;i >= N;i--) {
        cnt6 += vec.at(i);
        cnt4.push(vec.at(i));
        cnt6 -= cnt4.top();
        cnt4.pop();
        cnt2.at(2 * N - i) = cnt6;
    }
    reverse(cnt2.begin(),cnt2.end());
    ll ret = -INF;
    for(int i = 0;i < N + 1;i++) {
        ret = max(ret,cnt.at(i) - cnt2.at(i));
    }
    cout << ret << endl;
}

Measured memory_bytes: 6516
// Aizu Vol-1 0134: Exit Survey
// 2017.8.3

#include <stdio.h>
#include <stdlib.h>

char *gets(char *);
char buf[100];

int main()
{
	int i, n;
	long long sum;

	gets(buf), n = atoi(buf);
	for (i = 0, sum = 0; i < n; i++) gets(buf), sum += atoi(buf);
	if (!n) puts("0");
	else printf("%lld\n", sum / n);
	return 0;
}

Measured memory_bytes: 528
N=int(input())
A=sorted(map(int,input().split()))
m=max(A)
ans=0
dp=[True]*(m+1)
for i in range(N):
    if not dp[A[i]]:
        continue
    if i==N-1:
        ans+=1
    elif i<N-1 and A[i+1]!=A[i]:
        ans+=1
    for j in range(1,m//A[i]+1):
        dp[A[i]*j]=False
print(ans)

Measured memory_bytes: 94408
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define endl "\n"
#define speed() ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(x) (int)(x).size()
#define _USE_MATH_DEFINES
using namespace std;
typedef long long int lli;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define MAX 50
int roads[MAX]; // Global Variable

int main() {
    speed();
    int N, M; cin >> N >> M;
    rep(i, 0, N) roads[i] = 0;
    rep(i, 0, M) {
        int a, b; cin >> a >> b;
        roads[a]++;
        roads[b]++;
    }
    rep(i, 1, N+1) cout << roads[i] << endl;
    return 0;
}

Measured memory_bytes: 256
// template ver2.02

// include
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <complex>

using namespace std;

// conversion
inline int to_int(string s) {int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string to_str(T x) {ostringstream sout; sout << x; return sout.str();}

// typedef
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

// util
#define MP make_pair
#define EACH(i, c) for(typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define CLR(a) memset((a), 0 , sizeof(a))
template<class T, class C> inline bool in(T e, C c) {return c.find(e) != c.end();}
template<class T> inline bool in(T x, T a, T b) {return a <= x && x < b;}

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

// IO
#define PRA(a, n) cout << a[0]; FOR(itr, 1, n) {cout << " " << a[itr];} cout << endl;
#define PRF(x, w) cout << setprecision((w)); cout << setiosflags(ios::fixed); cout << (x) << endl;

// constant
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INF = (int)1e9;
const int DI[] = {0, 1, 0, -1};
const int DJ[] = {1, 0, -1, 0};

// debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DUMPA(a, n) cerr << #a << " = {" << a[0]; FOR(itr, 1, n) { cout << ", " << a[itr]; } cerr << "}" << endl;
#define DUMPAA(a, n, m) REP(itr, n) {REP(jtr, m) {cout << a[itr][jtr] << " ";} cout << endl;}

// template end

int n;
string s;

void init()
{
}

void solve()
{
    REP(i, n) {
        string tmp = "";
        char x = s[0];
        int m = 1;
        FOR(j, 1, s.size()) {
            if (s[j] == x) ++m;
            else {
                tmp += to_str(m) + x;
                x = s[j];
                m = 1;
            }
        }
        tmp += to_str(m) + x;
        s = tmp;
    }
    string ans = s;
    cout << ans << endl;
}

int main()
{
    init();
    while (cin >> n, n) {
        cin >> s;
        solve();        
    }
    return 0;
}


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

int main()
{
	int n;
	std::cin >> n;
	std::map<int, int> freq;
	std::vector<int> pairs;
	for(int i = 0; i < n; i++)
	{
		int size;
		std::cin >> size;
		if(freq[size])
		{
			pairs.push_back(size);
			freq[size]--;
		}
		else
		{
			freq[size]++;
		}
	}
	pairs.push_back(0);
	pairs.push_back(0);
	std::sort(pairs.begin(), pairs.end());
	n = pairs.size();
	long long ans = (long long)pairs[n - 1] * pairs[n - 2];
	std::cout << ans << '\n';
}

Measured memory_bytes: 4992
from collections import Counter
from functools import reduce
import fractions
import math
import statistics
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]  # LIST INT
def LF(): return [float(x) for x in sys.stdin.readline().split()]  # LIST FLOAT
def LS(): return sys.stdin.readline().split()  # LIST STRING
def MI(): return map(int, sys.stdin.readline().split())  # MAP INT
def II(): return int(sys.stdin.readline())  # INPUT INT
def IS(): return input()  # INPUT STRING
def P(x): return print(x)
def C(x): return Counter(x)
def GCD_LIST(numbers):  # greatest common divisor
    return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers):  # least common multiple
    return reduce(LCM, numbers)
def LCM(m, n):
    return (m * n // fractions.gcd(m, n))


if II() == 1:
    print("Hello World")
    exit()
a, b = II(), II()
print(a+b)


Measured memory_bytes: 5640
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 Jaynil
 */
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);
        DGatheringChildren solver = new DGatheringChildren();
        solver.solve(1, in, out);
        out.close();
    }

    static class DGatheringChildren {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            String x = in.next();
            int r[] = new int[x.length()];
            int l[] = new int[x.length()];
            int an[] = new int[x.length()];
            int ans = 0;
            for (int i = 0; i < x.length(); i++) {
                if (x.charAt(i) == 'R') {
                    ans = i;
                }
                r[i] = ans;
            }
            for (int i = x.length() - 1; i >= 0; i--) {
                if (x.charAt(i) == 'L') {
                    ans = i;
                }
                l[i] = ans;
            }
            for (int i = 0; i < x.length(); i++) {
                if (x.charAt(i) == 'L') {
                    if ((i - r[i] + 1) % 2 == 0) {
                        an[r[i] + 1]++;
                    } else {
                        an[r[i]]++;
                    }
                } else {
                    if ((l[i] - i + 1) % 2 == 0) {
                        an[l[i] - 1]++;
                    } else {
                        an[l[i]]++;
                    }
                }
            }
            for (int i = 0; i < x.length(); i++) {
                out.print(an[i] + " ");
            }
            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: 39312
// C.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <set>
#include <cassert>
#include <cmath>

using namespace std;

typedef unsigned long long LL;
typedef long double LD;

int main(int argc, char* argv[]) {
#ifdef _MSC_VER
	while (true)
#endif
	{
		LL a = 0, b, c;
		cin >> a >> b >> c;
		if (a == 0) return 0;
		LL d = c - a - b;
		LL e = 4 * a * b;
		bool ans = (a + b < c) && (e < d * d);
		cout << (ans ? "Yes" : "No") << endl;
	}
	return 0;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int LL;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2

ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
//template<class T>void max(T a,T b){if(a<b)return b;else return a;}
//template<class T>void min(T a,T b){if(a>b)return b;else return a;}
//template<class T>bool Max(T&a, T b){if(a < b){a = b;return 1;}return 0;}
//template<class T>bool Min(T&a, T b){if(a > b){a = b;return 1;}return 0;}

//////////////////////////

int main(){fastio
    
    string s;cin>>s;
    ll n=s.size();
    ll l[n],r[n];
    r[0]=1;
    rep(i,1,n-1){
        if(s[i]=='R')r[i]=r[i-1]+1;
        else r[i]=0;
    }
    l[n-1]=1;
    for(ll i=n-2;i>=0;i--){
        if(s[i]=='L')l[i]=l[i+1]+1;
        else l[i]=0;
    }
    ll a[n];memset(a,0,sizeof(a));
    rep(i,0,n-2){
        if(s[i]=='R'&&s[i+1]=='L'){
            a[i]+=(r[i]+1)/2;
            a[i+1]+=r[i]/2;
            a[i+1]+=(l[i+1]+1)/2;
            a[i]+=l[i+1]/2;
        }
    }
    rep(i,0,n-1)cout<<a[i]<<" ";cout<<endl;
    
    return 0;
}


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

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x; x--;
		a.at(i) = x;
	}

	vector<bool> appeared(1000000000, false);
	string ans = "YES";
	for (int i = 0; i < n; i++) {
		if (!appeared.at(a.at(i))) {
			appeared.at(a.at(i)) = true;
		}
		else {
			ans = "NO";
			break;
		}
	}
	cout << ans;
}


Measured memory_bytes: 123136
N = int(input())
A = [int(a) for a in input().split()]

maximum = 0
minimum = 0
used = [0]*9
for i in A:
    i //= 400
    if i >= 8:
        maximum += 1
    elif used[i] == 0:
        maximum += 1
        minimum += 1
        used[i] = 1
if minimum == 0:
    minimum += 1
print(minimum, maximum)

Measured memory_bytes: 3064
#include <stdio.h>

int main(void) 
{
	double r;
	double ans1,ans2;
	
	scanf("%lf", &r);
	ans1 = r*r*3.1415926535897932384626433;
	ans2 = 2*r*3.1415926535897932384626433;
	

	printf("%lf %lf\n", ans1, ans2);
	
	return 0;
}

Measured memory_bytes: 648
n = gets.to_i
# s = gets.chomp
x = gets.split.map(&:to_i)

c = 0
ans = (100 - 0) ** 2 * 100 + 1000000000000
101.times do |i|
    c = 0
    x.each do |y|
        c += ( y - i ) ** 2
    end
    ans = c if ans > c
end

p ans

# 以下、D問題の途中
# # refer to https://qiita.com/k_karen/items/653ba7025a92f5ac1363

# ONE = '1'.freeze
# MOD = (10**9) + 7

# def inv(x)
#   res = 1 # 最終的に x^(MOD-2) になる変数です
#   beki = x # x^2^n を格納する変数です
#   # MOD-2の２進数展開を下位のbitから見ていきます。
#   (MOD - 2).to_s(2).reverse.chars do |digest|
#     # bitが立っている <=> digest == ONE 
#     # なら resにbekiを掛けます。
#     # ここで、掛け算は計算の都度MODを取れます
#     res = (beki * res) % MOD if digest == ONE
#     # 次のループに備えて、自乗を計算します。
#     # 計算の都度MODを取れます(とても大事なので二回言います)
#     beki = (beki * beki) % MOD
#   end
#   res
# end

# def fact(s, e)
#   (s..e).reduce(1) { |r, i| (r * i) % MOD }
# end

# def nCk(n, k)
#   (fact(k + 1, n) * inv(fact(1, n - k) % MOD)) % MOD
# end

# def cmb(n, r, p):
#     if (r < 0) or (n < r):
#         return 0
#     r = min(r, n - r)
#     return fact[n] * factinv[r] * factinv[n-r] % p

# p = 10 ** 9 + 7
# N = 10 ** 6  # N は必要分だけ用意する
# fact = [1, 1]  # fact[n] = (n! mod p)
# factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
# inv = [0, 1]  # factinv 計算用
 
# for i in range(2, N + 1):
#     fact.append((fact[-1] * i) % p)
#     inv.append((-inv[p % i] * (p // i)) % p)
#     factinv.append((factinv[-1] * inv[-1]) % p)

# def f(t,k,mod):
#     res = 1
#     for i in range(k):
#         res = res * t % mod
#         t -= 1
#     return res
        

# mod = 10 ** 9 + 7
# # n = gets.to_i
# # s = gets.chomp
# # n,a,b = gets.split.map(&:to_i)
# n, a, b = map(int, input().split())
# cnt_a = cnt_b = 0

# ans = 1
# for i in range(n):
#     ans = ans * 2 % mod
# ans -= 1
# # p [n,ans]
# print(ans)
# print(f(n,a,mod))
# print(f(n,b,mod))
# # print(f(4,1,mod))
# # p nCk(a,n)
# # p fact(b,n)
# ans = (ans - cmb(n, a, mod)) % mod
# ans = (ans - cmb(n, b, mod)) % mod

# print(ans)

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

#define PI 3.14159265359
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descSort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;

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

    int ans=INF;
    rep(i,1,n){
        int a=i;
        int b=n-i;
        int a_sum=0,b_sum=0;

        while(a/10){
            a_sum+=a%10;
            a/=10;
        }
        a_sum+=a;

        while(b/10){
            b_sum+=b%10;
            b/=10;
        }
        b_sum+=b;

        ans=min(ans,a_sum+b_sum);
    }
    cout<<ans<<endl;
    return 0;
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,a;
    cin>>n;
    for(int i=0;i<n;i++){
    	cin>>a;
    	if(a%2==1){
    		cout <<"first"<<endl;
    		return 0;
    	}
    }
    cout << "second"<<endl;
    return 0;
}


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

int divis(int,int);

int main(){

    int x,y,a;
    cin >> x;
    cin >> y;

    //大きい方を左に代入
    if (x>y){a = divis(x,y);}
    else{a = divis(y,x);};

    cout << a << "\n";
    return 0;
}

int divis(int x,int y){
    int r=100000,q;

    while(r > 0){
        r =  x % y;
        q = (x-r)/y;
        x = y;
        y = r; 
    }
    return x;
}


Measured memory_bytes: 3096
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <climits>
#include <algorithm>
#include <cassert>
#include <vector>
#include <array>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>
#include <numeric>
#define ALL(c) (c).begin(), (c).end()

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdi = pair<double, int>;
using pdd = pair<double, double>;

int N;
vector<int> A, B;

int main() {
	cin >> N;
	for (int i = 0; i < N; i++)
	{
		int tmpA;
		cin >> tmpA;
		A.push_back(tmpA);
	}
	for (int i = 0; i < N; i++)
	{
		int tmpB;
		cin >> tmpB;
		B.push_back(tmpB);
	}
	vector<bool> is_positive(N, false);
	vector<int> only_positive;
	ll sum_task = 0;
	int ans = 0;
	for (int i = 0; i < N; i++)
	{
		if (A[i] > B[i]) {
			is_positive[i] = true;
			only_positive.push_back(A[i] - B[i]);
		}
		else if (A[i] < B[i]) {
			sum_task += B[i] - A[i];
			ans++;
		}
	}
	sort(only_positive.rbegin(), only_positive.rend());
	for (const auto e : only_positive) {
		if (sum_task <= 0) {
			break;
		}
		sum_task -= e;
		ans++;
	}
	if (sum_task > 0) {
		ans = -1;
	}
	cout << ans << endl;
}


Measured memory_bytes: 1528
main :: IO ()
main = do
    line <- getLine
    let [a, b] = words line
    putStrLn $ smallLargeOrEqual (read a :: Int) (read b :: Int)

smallLargeOrEqual :: Int -> Int -> String
smallLargeOrEqual a b
  | a < b     = "a < b"
  | a > b     = "a > b"
  | otherwise = "a == b"


Measured memory_bytes: 3532
#include <bits/stdc++.h>
#include <unistd.h>
#define ll long long
#define inf 1000000007
#define inf16 0x3f3f3f3f
#define INF 1000000000000000007LL
#define VI vector<int>
#define VPII vector<pair<int, int> >
#define VLL vector<ll>
#define PII pair<int, int>
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define endl '\n'
#define ALL(c) (c).begin(), (c).end()
using namespace std;

const int N = 607;

int n;

int d[2];

VPII takie[2][2];

int spo[N][N][2];

bitset<2> vis[N][N];

int kwa[N*N];

void dfs(int x, int y, int w)
{
	vis[x][y][w] = 1;

	for(int j = 0; j < 2*n; ++j)
	{
		int z = d[w]-(x-j)*(x-j);

		if(z>=0 && kwa[z]!=-1)
		{
			z = kwa[z];

			int y1 = y+z;
			int y2 = y-z;

			if(0<=y1 && y1<2*n && !vis[j][y1][w])
			{
				spo[j][y1][w] = spo[x][y][w]^1;
				dfs(j, y1, w);
			}

			if(0<=y2 && y2<2*n && !vis[j][y2][w])
			{
				spo[j][y2][w] = spo[x][y][w]^1;
				dfs(j, y2, w);
			}
		}
	}
}

int32_t main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);

	memset(kwa, -1, sizeof kwa);

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

	cin >> n >> d[0] >> d[1];

	for(int i = 0; i < 2*n; ++i)
	{
		for(int j = 0; j < 2*n; ++j)
		{
			if(!vis[i][j][0])
				dfs(i, j, 0);

			if(!vis[i][j][1])
				dfs(i, j, 1);
		}
	}

	for(int i = 0; i < 2*n; ++i)
	{
		for(int j = 0; j < 2*n; ++j)
		{
			takie[spo[i][j][0]][spo[i][j][1]].eb(i, j);
		}
	}

	for(int i = 0; i < 2; ++i)
	{
		for(int j = 0; j < 2; ++j)
		{
			if(takie[i][j].size()>=n*n)
			{
				for(int k = 0; k < n*n; ++k)
				{
					cout << takie[i][j][k].st << " " << takie[i][j][k].nd << endl;
				}

				exit(0);
			}
		}
	}
}

Measured memory_bytes: 39156
import java.io.*;
import java.util.HashMap;

/**
 * Created by Ayushi on 15/09/2019.
 */

public class Main {
    public static void main(String[] args) throws IOException {
        HashMap<Integer, Integer> hmap = new HashMap<>();
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
        String[] temp = r.readLine().split(" ");
        int n = Integer.parseInt(temp[0]);
        for (int i = 1; i <= n; i++) {
            hmap.put(i, 0);
        }
        int k = Integer.parseInt(temp[1]);
        int q = Integer.parseInt(temp[2]);
        for (int j = 0; j < q; j++) {
            temp = r.readLine().split(" ");
            int x = Integer.parseInt(temp[0]);
            hmap.put(x, hmap.get(x)+1);
        }
        r.close();
        for (int l = 1; l <= n; l++) {
            if (hmap.get(l) <= (q-k)) {
                System.out.println("No");
            }
            else {
                System.out.println("Yes");
            }
        }
    }
}


Measured memory_bytes: 72792
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const int N=1111;
char s[N];
ll exgcd(ll a,ll b,ll &x,ll &y){
	if (b==0){
		x=1,y=0;		
		return a;
	}
	ll g=exgcd(b,a%b,y,x);
	y-=a/b*x;
	return g;
}
int main(){
	ll a,b,u,v,t;//x,y,t,k;
	scanf("%lld%lld%lld%lld%lld",&a,&u,&b,&v,&t);
	if (u<=v){
		printf("NO\n");
		return 0;	
	}
/*	ll c=abs(b-a);
	a=abs(u+v),b=abs(u-v);
	ll g=exgcd(a,b,x,y);
	if (c%g!=0){
		printf("NO\n");
		return 0;	
	}
	x*=c/g,y*=c/g;
	//ax+by==c
	ll lcm=1ll*a*b/g;
	if (y<0){
		k=abs(y/(lcm/a))+1;
		x-=k*lcm/a,y+=k*lcm/b;
	}
	k=y/(lcm/b);
	x+=k*lcm/a,y-=k*lcm/b;
	printf("%lld %lld\n",x,y);
	ll ans=min(x+y,x+lcm/a+y-lcm/b);
	ans<=t?printf("YES\n"):printf("NO\n");*/
	int ans=0,s=abs(a-b);
	if (s%(u-v)==0)	ans=s/(u-v);
	else ans=s/(u-v)+1;
	ans<=t?printf("YES\n"):printf("NO\n");
    return 0;
}

Measured memory_bytes: 1648
#include <bits/stdc++.h>
#include <complex>
typedef long long ll;
using namespace std;
#define all(x) (x).begin(), (x).end()
#define MOD 1000000007
void fft(int n, int s, bool eo, complex<double> *x, complex<double> *y) {
    const int m = n / 2;
    const double pi = acos(-1);
    const double theta = 2 * pi / n;
    if(n == 1) {
        if(eo) {
            for(int q = 0; q < s; q++) {
                y[q] = x[q];
            }
        }
    } else {
        for(int p = 0; p < m; p++) {
            const complex<double> wp = polar(1.0, -p * theta);
            for(int q = 0; q < s; q++) {
                const auto a = x[q + s * (p + 0)];
                const auto b = x[q + s * (p + m)];
                y[q + s * (2 * p + 0)] = a + b;
                y[q + s * (2 * p + 1)] = (a - b) * wp;
            }
        }
        fft(n / 2, 2 * s, !eo, y, x);
    }
}
const int N = 1 << 18;
complex<double> x[N];
complex<double> y[N];
complex<double> tmp[N];
int main() {
    ll n, m;
    cin >> n >> m;
    int sz = 2 * 100000;
    vector<ll> c(N);
    for(int i = 0; i < n; i++) {
        ll d;
        cin >> d;
        c[d]++;
    }
    for(int i = 1; i <= sz; i++) {
        x[i].real(c[i]);
        y[i].real(c[i]);
    }
    fft(N, 1, false, x, tmp);
    fft(N, 1, false, y, tmp);
    for(int i = 0; i < N; i++) {
        x[i] *= y[i];
        x[i] = conj(x[i]);
    }
    fft(N, 1, false, x, tmp);
    for(int i = 0; i < N; i++) {
        x[i] = conj(x[i]) * (1.0 / N);
    }
    ll sub = 0;
    for(ll i = sz; i >= 1; i--) {
        if(m == 0) {
            break;
        }
        ll amt = round(real(x[i]));
        if(amt <= m) {
            m -= amt;
            sub += i * amt;
        } else {
            sub += i * m;
            m = 0;
        }
    }
    cout << sub << endl;
}


Measured memory_bytes: 14720
/* ***********************************************
Author        :dasinlsb
Created Time  :2018/6/12 23:11:59
File Name     :C:\dasin\mine.cpp
************************************************ */

#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cassert>
#include<vector>
#include<set>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef pair<int,int> pii;
#define pb push_back
#define fi first
#define se second
#define SZ(x) ((int)((x).size()))
const int N=200005;
int n,p[N],v[N][2],f[N];
ll ans;
struct Node{
  ll w,b;int x;
  Node(){}Node(ll _w,ll _b,int _x){w=_w,b=_b;x=_x;}
  bool operator<(const Node&t)const{
    return w*t.b>t.w*b||w*t.b==t.w*b&&x<t.x;
  }
};
multiset<Node>s;
int F(int x){return x==f[x]?x:f[x]=F(f[x]);}
int main(){
 // freopen("C:/dasin/aa.in","r",stdin);
  //freopen("C:/dasin/mine.out","w",stdout);
  int i,j;
  scanf("%d",&n);
  for(i=2;i<=n;++i)scanf("%d",p+i);
  for(i=1;i<=n;++i){
    int x;scanf("%d",&x);
    v[i][x]++;
    s.insert(Node(v[i][0],v[i][1],i));
  }
  for(i=1;i<=n;++i)f[i]=i;
  for(;SZ(s);){
    Node t=*(s.begin());s.erase(t);
    int x=t.x;
    assert(F(x)==x);
    int y=F(p[x]);
    //printf("node %d %d\n",x,y);
    if(!y)continue;
    s.erase(Node(v[y][0],v[y][1],y));
    ans+=(ll)v[x][0]*v[y][1];
    //printf("val %d\n",v[x][0]*v[y][1]);
    v[y][0]+=v[x][0];
    v[y][1]+=v[x][1];
    f[x]=y;
    s.insert(Node(v[y][0],v[y][1],y));
    //printf("sz %d\n",SZ(s));
  }
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 15872
#include <stdio.h>
#include <ctype.h>

int main(void)
{
    int i = 0;

    char line[100];
    char c;
    while ((c = getchar()) != '\n' && c != EOF) {
        line[i++] = c;
    }
    line[i] = '\0';
    int len = i;

    for (i = 0; i < len; i++) {
        if ('a' <= line[i] && line[i] <= 'z') {
            line[i] = toupper(line[i]);
        }
    }

    printf("%s\n", line);

    return 0;
}

Measured memory_bytes: 524
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
public class Main {
  public static void main(String[] args) {
    Main m = new Main();
    m.run();
  }
  private void run() {
    int n = 0;
    int k = 0;
    int l = 0;
    UnionFind ufk = null;
    UnionFind ufl = null;
    try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in));) {
      String[] t = br.readLine().split("\\s+");
      n = Integer.parseInt(t[0]);
      k = Integer.parseInt(t[1]);
      l = Integer.parseInt(t[2]);
      ufk = new UnionFind(n);
      ufl = new UnionFind(n);
      for (int i=0;i<k;i++) {
        t = br.readLine().split("\\s+");
        int p = Integer.parseInt(t[0])-1;
        int q = Integer.parseInt(t[1])-1;
        ufk.unite(p,q);
      }
      for (int i=0;i<l;i++) {
        t = br.readLine().split("\\s+");
        int r = Integer.parseInt(t[0])-1;
        int s = Integer.parseInt(t[1])-1;
        ufl.unite(r,s);
      }
    } catch (IOException e) {
      e.printStackTrace();
    }
    Map<Tuple,Integer> m = new HashMap<>();
    for (int i=0;i<n;i++) {
      Tuple t = new Tuple(ufk.find(i),ufl.find(i));
      if (m.containsKey(t)) {
        int v = m.get(t);
        m.put(t,v+1);
      } else {
        m.put(t,1);
      }
    }
    for (int i=0;i<n;i++) {
      if (i > 0) System.out.print(" ");
      Tuple t = new Tuple(ufk.find(i),ufl.find(i));
      System.out.print(m.get(t));
    }
    System.out.println();
  }
  private class Tuple {
    int x;
    int y;
    Tuple(int x,int y) {
      this.x = x;
      this.y = y;
    }
    @Override
    public int hashCode() {
      int prime = 31;
      int result = 1;
      result = prime * result + x;
      result = prime * result + y;
      return result;
    }
    @Override
    public boolean equals(Object obj) {
      if (this == obj) return true;
      if (obj == null) return false;
      if (getClass() != obj.getClass()) return false;
      Tuple other = (Tuple)obj;
      return x == other.x && y == other.y;
    }
  }
  private class UnionFind {
    int n;
    int[] par;
    int[] rank;
    UnionFind(int n) {
      this.n = n;
      par = new int[n];
      rank = new int[n];
      for (int i=0;i<n;i++) par[i] = i;
    }
    private int find(int i) {
      if (par[i] == i) return i;
      return par[i] = find(par[i]);
    }
    private boolean same(int i,int j) {
      return find(i) == find(j);
    }
    private void unite(int i,int j) {
      i = find(i);
      j = find(j);
      if (i == j) return;
      if (rank[i] < rank[j]) {
        par[i] = j;
      } else {
        par[j] = i;
        if (rank[i] == rank[j]) rank[i]++;
      }
    }
  }
}

Measured memory_bytes: 106516
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

const double EPS = 1e-10;
#define SZ(x) (int)(x.size())
inline int dcmp(double x) {
  return (x > EPS) - (x < -EPS);
}

struct Point {
  double x, y;
};

bool operator <(const Point& a, const Point& b) {
  return a.y < b.y || (a.y == b.y && a.x < b.x);
}

double cross(const Point& a, const Point& b, const Point& c) {
  return (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
}

vector<Point> graham_scan(vector<Point>& p) {
  sort(p.begin(), p.end());
  vector<Point> A, B;
  for (auto& it : p) {
    while (SZ(A) >= 2 &&
           dcmp(cross(A[SZ(A) - 2], A[SZ(A) - 1], it)) <= 0) A.pop_back();
    A.push_back(it);
  }
  for (auto& it : p) {
    while (SZ(B) >= 2 &&
           dcmp(cross(B[SZ(B) - 2], B[SZ(B) - 1], it)) >= 0) B.pop_back();
    B.push_back(it);
  }
  vector<Point> ret(A.begin(), A.end());
  for (int i = SZ(B) - 2; i > 0; --i) ret.push_back(B[i]);
  return ret;
}

int main() {
  int n;
  scanf("%d", &n);
  vector<ii> a(n);
  vector<Point> p = {{0, 0}};
  for (int i = 0; i < n; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    int len = p.size();
    for (int k = 0; k < len; ++k) {
      p.push_back({p[k].x + x, p[k].y + y});
    }
    p = graham_scan(p);
  }
  double ret = 0.0;
  for (auto& it : p) {
    ret = max(ret, sqrt(it.x * it.x + it.y * it.y));
  }
  printf("%.10f\n", ret);
  return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

class ContestReader {
  private BufferedReader reader;
  private StringTokenizer tokenizer;
  
  ContestReader(InputStream in) {
    reader = new BufferedReader(new InputStreamReader(in));
  }
  
  public String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }
  
  public int nextInt() {
    return Integer.parseInt(next());
  }
  
  public long nextLong() {
    return Long.parseLong(next());
  }
  
  public double nextDouble() {
    return Double.parseDouble(next());
  }
  
  public int[] nextIntArray(int n) {
    int[] array = new int[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextInt();
    }
    return array;
  }
  
  public long[] nextLongArray(int n) {
    long[] array = new long[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextLong();
    }
    return array;
  }
}

class Solver {
  private boolean solveEven(int minA, int maxA, int[] counter) {
    if (minA * 2 != maxA) {
      return false;
    }
    if (counter[minA] != 1) {
      return false;
    }
    for (int i = minA + 1; i <= maxA; i++) {
      if (counter[i] < 2) {
        return false;
      }
    }
    return true;
  }
  
  private boolean solveOdd(int minA, int maxA, int[] counter) {
    if (minA * 2 - 1 != maxA) {
      return false;
    }
    if (counter[minA] != 2) {
      return false;
    }
    for (int i = minA; i <= maxA; i++) {
      if (counter[i] < 2) {
        return false;
      }
    }
    return true;
  }
  
  public boolean solve(int[] as) {
    int[] counter = new int[as.length];
    int maxA = 0;
    int minA = Integer.MAX_VALUE;
    for (int a : as) {
      counter[a]++;
      maxA = Math.max(maxA, a);
      minA = Math.min(minA, a);
    }
    
    if (maxA % 2 == 0) {
      return solveEven(minA, maxA, counter);
    } else {
      return solveOdd(minA, maxA, counter);
    }
  }
}

public class Main {
  
  
  private static void execute(ContestReader reader, PrintWriter out) {
    int n = reader.nextInt();
    int[] a = reader.nextIntArray(n);
    out.println(new Solver().solve(a) ? "Possible" : "Impossible");
  }
  
  public static void main(String[] args) {
    ContestReader reader = new ContestReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    execute(reader, out);
    out.flush();
  }
}



Measured memory_bytes: 22740
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define int long long
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define F first
#define S second
#define pb push_back
#define rep(i, a, b) for(int i = a; i < b; i++)
#define repr(i, a, b) for(int i = a - 1; i >= b; i--)
#define iter(m) for(auto it = m.begin(); it != m.end(); it++)
#define iterr(m) for(auto it = m.rbegin(); it != m.rend(); it++)
#define N 500500
#define PI 3.14159265358979323846264338327950L
#define speed ios_base :: sync_with_stdio(0);cin.tie(0);cout.tie(0);
    
const ll mod = (ll)1e9 + 7;
    
signed main(){
    speed;
    int x, y, n, m, k; cin >> x >> y >> n >> m >> k;
    vi r(n), g(m), c(k);
    rep(i, 0, n) cin >> r[i];
    rep(i, 0, m) cin >> g[i];
    rep(i, 0, k) cin >> c[i];
    int pos = x + y;
    int ans = 0;
    int cnt = 0;
    sort(all(r));
    sort(all(g));
    sort(all(c));
    vector<int> res;
    for(int i = n - 1; i > n - x - 1; i--) {
        ans += r[i];
        res.push_back(r[i]);
    }
    for(int i = m - 1; i > m - 1 - y; i--) {
        ans += g[i];
        res.push_back(g[i]);
    }
    sort(all(res));
    k--;
    for(int i = 0; i < res.size(); i++) {
        if(c[k] > res[i]) {
            ans += c[k] - res[i];
            k--;
        } else {
            break;
        }
        if(k < 0) break;
    }
    cout << ans;
    
    return 0;
}

Measured memory_bytes: 7644
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();

		int[] cards = new int[N];
		for(int i=0;i<N;i++) {
			cards[i] = sc.nextInt();
		}
		Arrays.sort(cards);
		int sum=0;
		for(int j=N;j>1;j=j-2) {
			sum += cards[j-1] -cards[j -2];
		}
		if(N % 2 == 1)sum+=cards[0];
		
		System.out.println(sum);
	}
}


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


int main() {
int n;
cin >> n;
int count =0;
rep(i,n){
    int L,R;
    cin >> L >> R;
    int ans = R-L+1;
    count +=ans;
}
cout << count << endl;
}

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

using namespace std;

int main(void)
{
    string s;
    int h = 0;
    cin>>s;
    vector<int> dp(1<<26,1e9);

    dp[0] = 0;
    for(int i = 0;i < s.size();i++) {
       int bit = s[i] - 'a';
       h = h ^ (1<<bit);
       for(int j = 0;j < 26;j++) {
           dp[h] = min(dp[h],dp[h^(1<<j)]+1);
       }
    }

    cout<<max(1,dp[h])<<endl;

    return 0;
}


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


void solve(long long H, long long A){
    int ans=0;
    while(H>0){
        H -=A;
        ans++;
    }
    cout << ans << endl;

}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long H;
    scanf("%lld",&H);
    long long A;
    scanf("%lld",&A);
    solve(H, A);
    return 0;
}


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

#define ll long long
#define ull unsigned long long

using namespace std;

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

	vector <int> p(N);
	int ans = 0;
	for (int ii = 0; ii < N; ++ii){
		cin >> p[ii];
		ans += p[ii];
	}

	sort(p.rbegin(), p.rend());
	ans = ans - p[0] + p[0] / 2;



	cout << ans << "\n";

	return 0;
}


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



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

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



int main(void){

	char x, y; cin >> x >> y;
	if(x<y) cout << '<' << endl;
	else if(x>y) cout << '>' << endl;
	else cout << '=' << endl;


	return 0;

}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

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

int N, M;
int X[100001];

int main() {
  scanf("%d %d\n", &N, &M);
  REP(i, M) scanf("%d", &X[i]);

  if (N >= M) printf("%d\n", 0);
  else {
    std::sort(X, X+M);
    int X_diff[M-1];
    REP(i, M-1) X_diff[i] = X[i+1] - X[i];
    std::sort(X_diff, X_diff + M - 1);

    int ans = 0;
    REP(i, M-N) ans += X_diff[i];
    printf("%d\n", ans);
  }

  return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main() {
    string s;cin>>s;
    
    int n=s.size();
    
    int ans=0;
    int cons=0;
    rep(i,n){
        char f=s[i];
        if(f=='A' || f=='G' || f=='T' ||f=='C'){
            ans++;
        }else{
            cons=max(cons,ans);
            ans=0;
        }
    }
    cons=max(cons,ans);
    cout<<cons<<endl;
    return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}


//AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC
int main(){
    lint n,x;cin>>n;
    priority_queue<lint> yakusuu;
    for(lint i=1;i<=sqrt(n);i++){
        if(n%i==0){
            yakusuu.push(i);
            yakusuu.push(n/i);
        }
    }
    lint ans=0;
    while(!yakusuu.empty()){
        x=yakusuu.top();yakusuu.pop();
        if(x-1>n/x)ans+=x-1;
        else break;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3764
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;

int main(){
    long long N, K;
    cin >> N >> K;
    vector<long long> a(N), b(N+1, 0);
    for(int i=0; i<N; i++)
            cin >> a[i];
    for(int i=1; i<=N; i++)
            b[i] = b[i-1] + a[i-1];

    vector<long long> c;
    for(int l=0; l<=N; l++)
            for(int r=l+1; r<=N; r++)
                    c.push_back(b[r]-b[l]);

    vector<bool> remain(N*(N+1)/2, true);
    long long ans = 0;
    for(int i=40; i>=0; i--){
            vector<bool> tmp(N*(N+1)/2, false);
            int cnt = 0;
            for(int j=0; j<N*(N+1)/2; j++){
                    if(!remain[j]) continue;
                    if(c[j] & (1LL<<i)){
                            cnt++;
                            tmp[j] = true;
                    }
            }
            if(cnt >= K){
                    ans |= (1LL<<i);
                    for(int j=0; j<N*(N+1)/2; j++){
                            if(!tmp[j])
                                    remain[j] = false;
                    }
            }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6532
n,k=map(int,input().split())
h=list(map(int,input().split()))
dp=[float('inf')]*n
dp[0]=0
for i in range(0,n):
    for j in range(i+1,min(i+k+1,n)):
        dp[j]=min(dp[i]+abs(h[i]-h[j]),dp[j])
print(dp[n-1])

Measured memory_bytes: 55264
#include <bits/stdc++.h>
using namespace std;
 
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define lli long long int
#define li long int
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define mem(arr,x) memset(arr,x,sizeof(arr))
#define F first
#define S second
#define MOD 1000000007
 
lli mod(lli base,lli exp){
	lli res = 1;
	while(exp>0){
		if(exp&1) res = (res*base)%MOD;
		base = (base*base)%MOD;
		exp = exp>>1;
	}
	return res;
}
void solve(){
	lli a,b,c,k;
	cin>>a>>b>>c>>k;
	if(a>=k) cout<<k<<endl;
	else if((a+b)>=k) cout<<a<<endl;
	else{
		int temp=k-(a+b);
		cout<<a-temp<<endl;
	}
    

}
int main() {
        fast();
	int t;
	t=1;
	while(t--){
		solve();
	}
	return 0;
}

Measured memory_bytes: 3660