akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;

const double eps = 1e-9;

int main() {
    int w,h,l;
    while(cin>>w>>l>>h, w|l|h) {
        int rr = w*w+h*h;
        rr = min(h*h+l*l, rr);
        rr = min(l*l+w*w, rr);
        int n,r;
        cin>>n;
        for(int i=0; i<n; ++i) {
            cin>>r;
            if(r*r*4 > rr) cout<<"OK"<<endl;
            else cout<<"NA"<<endl;
        }
    }
}

Measured memory_bytes: 0
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#define N 262147
#define ll long long
#define reg register
#define p 998244353
using namespace std;

int fa[N],a[N],b[N],sa[N],sb[N],lsh[N];
int n,cnt,ans = -1;

inline int find(int x){
    while(x!=fa[x]) x = fa[x] = fa[fa[x]];
    return x;
}

inline void merge(int u,int v){
    int fu = find(u),fv = find(v);
    if(fu!=fv) fa[fu] = fv;
}

inline int qwq(int x){
    return lower_bound(lsh+1,lsh+1+cnt,x)-lsh;
}

int main(){
    scanf("%d",&n);
    for(reg int i=1;i<=n;++i) scanf("%d",&a[i]),a[n+1] ^= a[i];
    for(reg int i=1;i<=n;++i) scanf("%d",&b[i]),b[n+1] ^= b[i];
    ++n;
    memcpy(sa+1,a+1,n<<2);
    memcpy(sb+1,b+1,n<<2);
    sort(sa+1,sa+n+1);
    sort(sb+1,sb+n+1);
    for(reg int i=1;i!=n;++i){
        if(sa[i]==sb[i]) continue;
        printf("-1\n");
        return 0;
    }
    for(reg int i=1;i<=n;++i){
        fa[i] = i;
        if(a[i]==b[i]&&i!=n) continue;
        lsh[++cnt] = a[i];
        lsh[++cnt] = b[i];
        ++ans;
    }
    sort(lsh+1,lsh+1+cnt);
    cnt = unique(lsh+1,lsh+1+cnt)-lsh-1;
    for(reg int i=1;i<=n;++i){
        if(a[i]==b[i]) continue;
        merge(qwq(a[i]),qwq(b[i]));
    }
    for(reg int i=1;i<=cnt;++i) ans += fa[i]==i;
    printf("%d\n",ans-1);
	return 0;	
}

Measured memory_bytes: 5504
n, k = map(int, input().split())
p = list(map(int, input().split()))

mini = 0
kitai = 0
sum1 = []
p2 = []
ans = 0
base = 0
sei = 0
a = 0
d = {}
for i in range(max(p) + 1):
    a += i + 1
    sum1.append(a)

for i in range(k):
    p3 = sum1[p[i] - 1] / (p[i])
    p2.append(p3)
    base += p3


ans = base


for i in range(1, n):
    if i + k - 1 >= n:
        break
    else:
        p3 = sum1[p[i + k - 1] - 1] / (p[i + k - 1])
        p2.append(p3)
        base = base - p2[i - 1] + p3
        if ans < base:
            ans = base

print(ans)



Measured memory_bytes: 25604
<?php
list($n) = ints();
$ans = 0;
for ($i = 1; $i <= $n; $i++)
    $ans += $i * (intdiv($n, $i) + 1) * intdiv($n, $i) / 2;
echo $ans;
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Measured memory_bytes: 16144
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := iScan()
	m := iScan()
	s := append([]int{-1}, iSScan(n)...)
	t := append([]int{-1}, iSScan(m)...)
	dp := make([][]int, n+1)
	dp[0] = make([]int, m+1)
	for i, _ := range dp[0] {
		dp[0][i] = 1
	}
	for i := 1; i <= n; i++ {
		dp[i] = make([]int, m+1)
		dp[i][0] = 1
		for j := 1; j <= m; j++ {
			if s[i] == t[j] {
				dp[i][j] = dp[i-1][j] + dp[i][j-1]
			} else {
				dp[i][j] = dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1]
			}
			dp[i][j] %= mod
			if dp[i][j] < 0 {
				dp[i][j] += mod
			}
		}
	}
	fmt.Println(dp[n][m])
}


Measured memory_bytes: 35356
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

ll factorial(ll n) {
  ll answer = 1;
  while (n > 1) {
    answer *= n;
    answer %= mod;
    n--;
  }
  return answer;
}

ll combination(ll n, ll r) {
  return factorial(n) / (factorial(r) * factorial(n - r));
}

ll permutation(ll n, ll r) { return factorial(n) / factorial(n - r); }

template <typename T>
void remove(std::vector<T>& vector, unsigned int index) {
  vector.erase(vector.begin() + index);
}

map<ll, ll> prime_factor(ll n) {
  map<ll, ll> ret;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1) ret[n] = 1;
  return ret;
}
// for (auto p : prime_factor(n)) {
//	while (p.second--) {
//		cout << p.first << endl;
//	}
//}

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 * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

bool compare_by_b(pair<ll, ll> a, pair<ll, ll> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

int main() {
  int n;
  cin >> n;
  lvec a(n);
  ll sum = 0;
  REP(i, n) {
    cin >> a[i];
    sum += a[i];
  }

  ll count = 0;
  ll minDiff = 1000000000000000000LL;
  ll diff = 1000000000000000000LL;
  REP(i, n - 1) {
    count += a[i];
    diff = abs(count - (sum - count));
    minDiff = min(minDiff, diff);
  }
  cout << minDiff << endl;
  return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <functional>
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> v(n, 0);
  for(int i = 0; i < n; i++){
    cin >> v[i];
  }
  int count = 0;
  for(int i = 0; i < n; i++){
    bool f = false;
    int minj = i;
    for(int j = i; j < n; j++){
      if(v[j] < v[minj]){
        minj = j;
        f = true;
      }
    }
    swap(v[i], v[minj]);
    if(f){ count++; }
  }
  
  for(int i = 0; i < n; i++){
    if(i != n - 1){
      cout << v[i] << " ";
    }
    else{
      cout << v[i] << endl;
    }
  }
  cout << count << endl;
} 


Measured memory_bytes: 3100
#include <iostream>
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int minimum = 987654321;
int N, M, X, C[13];
int A[13][13];
int selectedNum[13] = {0,};
int temp[13] = {0,};
void find(int n){
    if (n > N){
        int total = 0;
        for ( int i = 1 ; i <= M; ++i){
            if (temp[i] < X) {return ;} 
        }
        for (int i = 1; i <= N; ++i){
            total += C[i] * selectedNum[i];
        }
        if (total <= minimum ) minimum = total;
    
    }
    else {
        for (int i = 1; i <= M; ++i){
            temp[i] += A[n][i];
        }
        selectedNum[n] = 1;
        find(n+1);
        for (int i = 1; i <= M; ++i){
            temp[i] -= A[n][i];
        }
        selectedNum[n] = 0;
        find(n+1); 
    }

}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    cin >> N >> M >> X;

    for (int i = 1 ; i <= N; ++i){
        cin >> C[i] ;
        for (int j = 1; j <= M; ++j){
            cin >> A[i][j];
        }
    }


    find(1);
    if (minimum == 987654321) cout << "-1";
    else cout << minimum;
}




Measured memory_bytes: 3604
// Last Change: 05/09/2019 18:36:58.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

namespace NS {
void LoopUntilZeroInpput() {
  int hogegegege = 0;
  while (cin >> hogegegege && hogegegege != 0) {
  }
}
} // namespace NS

int main() {
  ll N;
  cin >> N;
  vector<ll> L(2 * N);
  for (auto &&e : L) {
    cin >> e;
  }

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

  ll i = 0, ans = 0;
  for (auto &&e : L) {
    if (i % 2 == 0) {
      ans += e;
    }
    ++i;
  }
  cout << ans << endl;

  //NS::LoopUntilZeroInpput();
}


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

int main() {
    int n,m;
    cin>>n;
    vector<int> a(n);
    vector<int> res(n);
    a[0]=0,res[0]=0;
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<n;i++) res[a[i]-1]=i+1;
    for(int i=0;i<n;i++) cout<<res[i]<<" ";
    cout<<endl;
    return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <array>
#include <algorithm>
#include <map>
#include <vector>
#include <list>
#include <cmath>
#include <stack>
#include <queue>
#include <climits>
#include <string.h>
#include <cctype>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using namespace std;

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

// a と b の最大公約数を返す関数
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x% mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
	mint operator+(const mint a) const { return mint(*this) += a; }
	mint operator-(const mint a) const { return mint(*this) -= a; }
	mint operator*(const mint a) const { return mint(*this) *= a; }
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

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

struct combination {
	vector<mint> fact, ifact;
	combination(int n) :fact(n + 1), ifact(n + 1) {
		fact[0] = 1;
		for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
		ifact[n] = fact[n].inv();
		for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
	}
	mint operator()(int n, int k) {
		if (k < 0 || k > n) return 0;
		return fact[n] * ifact[k] * ifact[n - k];
	}
} comb(2000005);

mint g(int r, int c) {
	return comb(r + c + 2, r + 1) - 1;
}

bool comp(int i, int j) {
	return i > j;
}

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
bool pairCompare(const P& firstElof, const P& secondElof)
{
	return firstElof.second > secondElof.second;
}

int main()
{
	int n, d;
	cin >> n >> d;
	int dd = d * 2 + 1;
	cout << ((n % dd == 0) ? n / dd : n / dd + 1);
}


Measured memory_bytes: 31488
#include <iostream>
#include <vector>
using namespace std;
#define rep(i, n) for(int i=0;i<n;i++)



int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    rep(i, n) cin >> v[i];
    double tmp = 0;
    sort(v.begin(), v.end());
    tmp = (v[0]+v[1])/2.0;
    for(int i=2; i<n; i++){
        tmp = (tmp+v[i])/2.0;
    }
    cout << tmp;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;

int u[]={3,1,2,4};
int v[]={0,1,5,4};



int main(){
    vector<int> a(6),b(6);
    for (int i = 0; i < 6; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < 6; i++) {
        cin >> b[i];
    }
    for (int i = 0; i < 4; i++) {
        for (int s = 0; s < 4; s++) {
            for (int l = 0; l < 4; l++) {
                auto p = b;
                for (int j = 0; j < 4; j++) {
                    p[u[j]] = b[u[(j+i)%4]];
                    auto q = p;
                    for (int k = 0; k < 4; k++) {
                        q[v[k]] = p[v[(k+s)%4]];
                        auto r = q;
                        for (int m = 0; m < 4; m++) {
                            r[u[m]] = q[u[(m+l)%4]];
                        }
                        if(a==r){
                            puts("Yes");
                            return 0;
                        }
                    }
                }
            }
        }
    }
    puts("No");
    int cnt=0;
    return 0;
}



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

#define DEBUG(x) cerr << #x << ": " << x << endl;
#define ll long long

int main() {
    string s;
    cin >> s;

    string ans;
    for (char c : s) { 
        switch (c) {
            case '0':
                ans.push_back('0');
                break;
            case '1':
                ans.push_back('1');
                break;
            case 'B':
                if (ans.size() != 0) ans.pop_back();
                break;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

        int count = 0;
        for (int i = 0; i < n; i++) {
                int tmp;
                cin >> tmp;
                if ( (i+1) % 2 == 1 && tmp %2 == 1)
                        count++;
        }

        cout << count << endl;


        return 0;
}

Measured memory_bytes: 3656
#include <stdio.h>
#include <stdlib.h>
#define N 100000
#define M 100000

int parentSearch(int);
int depthSearch(int); 
char *Treejudge(int);

int n,node;
int k[N];
int *c[M];
int parent[N];
int depth[N];
char *Tree[N];

int main(){
  int i,j;


  scanf("%d",&n);
  if(n>N)exit(8);
  for(i=0 ; i<N ; i++){
    parent[i]=-1;
  }
  for(i=0 ; i<n ; i++){
    scanf("%d",&node);
    scanf("%d",&k[node]);
    c[node]=(int *)malloc(sizeof(int)*k[node]);
    for(j=0 ; j<k[node] ; j++){
      scanf("%d",&c[node][j]);
      parent[c[node][j]]=node;
    }
  }

 
  for(i=0 ; i<n ; i++){
    depth[i]=depthSearch(parent[i]); 
  }
  for(i=0 ; i<n ; i++){
    Tree[i]=Treejudge(i);
  }


    for(i=0 ; i<n ; i++){
      printf("node %d: parent = %d, depth = %d, %s, ",i,parent[i],depth[i],Tree[i]);
      printf("[");
      for(j=0 ; j<k[i] ; j++){
	printf("%d",c[i][j]);
	if(j==k[i]-1)break;
	printf(", ");
      }
      printf("]\n");
    }

      return 0;
}
    
int depthSearch(int Nodeparent){
  int i,depth=0;
  
  while(Nodeparent != -1){
      depth++;
      Nodeparent = parent[Nodeparent];
  }
  return depth;
}

char *Treejudge(int Node){
  int i;
  if(parent[Node]==-1)return "root";
    if(k[Node]>0)return "internal node";
  return "leaf";
}

Measured memory_bytes: 7292
import sys
import collections


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n, m = list(map(int, readline().split()))
    d = collections.defaultdict(list)
    ab = []
    for i in range(m):
        a, b = list(map(int, readline().split()))
        d[a-1] += [b-1]
        d[b-1] += [a-1]
        ab.append(sorted([a-1, b-1]))
    cnt = 0
    for abl in ab:
        ql = collections.deque()
        ql.append(0)
        fq = collections.defaultdict(list)
        fq[0]
        a, b = abl
        while ql:
            q = ql.popleft()
            for v in d[q]:
                if v not in fq and [a, b] != sorted([q, v]):
                    ql.append(v)
                    fq[v]
        cnt += 1 if len(fq) != n else 0
    print(cnt)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 41328
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  priority_queue<int> q;
  REP(i,3*n){
    int a;
    cin >> a;
    q.push(a);
  }
  ll res = 0;
  REP(i,n){
    q.pop();
    int v = q.top();
    res += (ll)v;
    q.pop();
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 2420
#define min(x,y)((x)<(y)?(x):(y))
#define INF 0x01010101
main(){
	int n,w[2][100],b,h,J[2][100],f,j;
	for(;scanf("%d",&n),n;){
		for(b=0;b<2;b++)
			for(h=0;h<n;h++)
				scanf("%d",&w[b][h]);
		memset(J,1,sizeof(J));//INF
		J[0][n-1]=J[1][n-1]=0;
		for(f=1;f;){
			f=0;
			for(h=n;h--;){
				for(b=0;b<2;b++){
					switch(w[b][h]){
					case 0:
						j=h==n-1?-1:J[1-b][h];
						if(h+1<n)
							j=min(j,J[1-b][h+1]);
						if(h+2<n)
							j=min(j,J[1-b][h+2]);
						j++;
						break;
					case 1:
						if(h==n-1||w[b][h+1]!=1){
							j=h==n-1?-1:J[1-b][h];
							if(h+1<n)
								j=min(j,J[1-b][h+1]);
							if(h+2<n)
								j=min(j,J[1-b][h+2]);
							j++;
						}else{
							j=J[b][h+1];
						}
						break;
					case 2:
						j=J[b][h-1];
						break;
					}
					j=min(j,INF);
					if(J[b][h]!=j){
						J[b][h]=j;
						f=1;
					}
				}
				//printf("%3d %3d\n",J[0][h],J[1][h]);
			}
			//puts("-----");
		}
		j=min(J[0][0],J[1][0]);
		printf(j==INF?"NA\n":"%d\n",j);
	}
	exit(0);
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {
    private static final int MOD = 1_000_000_007;
    private static final String YES = "Yes";
    private static final String NO = "No";

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

        String S = sc.next();

        System.out.println(solve(S));
    }

    private static String solve(String S) {
        return S.replace(',', ' ');
    }
}

Measured memory_bytes: 21460
/*
--------------              |   /
      |                     |  /
      |                     | /
      |             *       |/          |    |         ------            *
      |                     |           |    |        /      \
      |             |       |\          |    |       |       |\          |
   \  |             |       | \         |    |       |       | \         |
    \ |             |       |  \        |    |        \     /   \        |
     V              |       |   \        \__/|         -----     \       |
*/
#include <bits/stdc++.h>
using namespace std;

#define EmiliaMyWife ios::sync_with_stdio(0); cin.tie(NULL);
#define mem(i,j) memset(i,j,sizeof (i));
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define lowbit(x) ((x)&(-(x)))
#define siz(v) (long long)(v).size()
typedef int64_t ll;
typedef uint64_t ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
const double EPS  = 1e-8;
const int INF     = 0x3F3F3F3F;
const ll LINF     = 4611686018427387903;
const int MOD     = 1e9+7;
const int MAXN    = 2e5+9;
/*-----------------------------------------------------------------------------------------------------*/

signed main() {
	EmiliaMyWife

	int x, y, a, b, c;
	cin >> x >> y >> a >> b >> c;
	vector<int> r(a), g(b), n(c);
	for(int i = 0; i < a; i++) cin >> r[i];
	for(int i = 0; i < b; i++) cin >> g[i];
	for(int i = 0; i < c; i++) cin >> n[i];
	sort(all(r), greater<int>());
	sort(all(g), greater<int>());
	sort(all(n), greater<int>());
	int on=x-1, tw=y-1, z=0;
	while(on>=0 || tw>=0) {
		if(z==c) break;
		if((on<0 || r[on]>n[z]) && (tw<0 || g[tw]>n[z])) break;
		if(tw==-1 || r[on]<g[tw]) {
			on--;
			z++;
		}
		else {
			tw--;
			z++;
		}
	}
	ll ans = 0;
	for(int i = 0; i <= on; i++) {
		ans+=r[i];
	}
	for(int i = 0; i <= tw; i++) ans+=g[i];
	for(int i = 0; i < z; i++) ans+=n[i];
	cout << ans;

	return 0;
}



Measured memory_bytes: 1408
def calculate_distance(before, after)
  return Math.sqrt((before[0] - after[0]) ** 2 + (before[1] - after[1]) ** 2)
end

TOWNS = gets.to_i
POSITIONS = []
TOWNS.times{ POSITIONS << gets.split(' ').map(&:to_i) }
total_d = 0

orders = []
TOWNS.times{ |i| orders << i }
orders.permutation(TOWNS) do |order|
  (TOWNS - 1).times do |i|
    before = POSITIONS[order[i]]
    after = POSITIONS[order[i + 1]]
    total_d += calculate_distance(before, after)
  end
end
print total_d / (1..TOWNS).inject(1,:*)

Measured memory_bytes: 2172
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int k = sc.nextInt();
    ArrayList[] list = new ArrayList[10];
    for(int i = 0; i < 10; i++) {
      list[i] = new ArrayList<Long>();
    }
    ArrayList<Long> l = new ArrayList<Long>();
    for(int j = 1; j < 10; j++) {
      list[0].add((long)j);
      l.add((long)j);
    }
    for(int i = 1; i < 10; i++) {
      for(int j = 0; j < list[i - 1].size(); j++) {
        long a = (long)list[i - 1].get(j);
        long d = a % 10;
        if(d == 0) {
          list[i].add(10 * a + d + 1);
          list[i].add(10 * a + d);
          l.add(10 * a + d + 1);
          l.add(10 * a + d);
        } else if(d == 9) {
          list[i].add(10 * a + d - 1);
          list[i].add(10 * a + d);
          l.add(10 * a + d - 1);
          l.add(10 * a + d);
        } else {
          list[i].add(10 * a + d - 1);
          list[i].add(10 * a + d);
          list[i].add(10 * a + d + 1);
          l.add(10 * a + d - 1);
          l.add(10 * a + d);
          l.add(10 * a + d + 1);
        }   
      }
    }
    Collections.sort(l);
    System.out.println(l.get(k - 1));
  }
}


Measured memory_bytes: 65316
#include <bits/stdc++.h>
using namespace std;
const int N = 1000005;

char s[N];
int n,l[N],f[N];
int main() {
    scanf("%d%s",&n,s+1);
    for(int i=1;i<=n;i++) {
        if(s[i]=='0') l[i]=i;
        else l[i]=l[i-1];
    }
    for(int i=1;i<=n;i++) {
        f[i]=f[i-1];
        if(s[i]=='1') {
            if(s[i-2]=='1' && s[i-1]=='0')
                f[i]=max(f[i],max(f[l[i-2]]+i-l[i-2]-2,f[l[i-2]+1]+i-l[i-2]-3));
            else if(l[i]>1 && s[l[i]-1]=='1') f[i]=max(f[i],f[l[i]-2]+i-l[i]);
        }
    }
    cout<<f[n];
}


Measured memory_bytes: 8448
fun main(args: Array<String>) {
    val l = arrayOf<Long>(3, 5, 7).toMutableSet()
    var new_l = arrayOf<Long>().toMutableSet()
    var n = readLine()!!.toLong()
    var left = 1
    while (left < n){
        new_l = arrayOf<Long>().toMutableSet()
        left *= 10
        l.map{ it -> new_l.add(it * 10 + 3)}
        l.map{ it -> new_l.add(it * 10 + 5)}
        l.map{ it -> new_l.add(it * 10 + 7)}
        l += new_l
    }
    println(l.filter{it -> it.toString().contains('3') && it.toString().contains('5') && it.toString().contains('7') }.filter{ it -> it <= n}.count())
}

Measured memory_bytes: 68356
X=int(input())
a=X
import math

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

while 1:
    if is_prime(a):
        print(a)
        break
    a+=1

Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>

using namespace std;
#define repp(i,a,b) for(int i = (int)(a); i < (int)(b); ++i)

typedef long long ll;

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

int main() {
    int X, Y, Z, K; cin >> X >> Y >> Z >> K;
    vector<long long> A(X); repp(i,0,X) cin >> A[i];
    vector<long long> B(Y); repp(i,0,Y) cin >> B[i];
    vector<long long> C(Z); repp(i,0,Z) cin >> C[i];
    sort(A.begin(), A.end(), greater<long long>());
    sort(B.begin(), B.end(), greater<long long>());
    sort(C.begin(), C.end(), greater<long long>());

    vector<long long> re_xy;
    repp(i,0,X){
        repp(j,0,Y) {
            re_xy.push_back(A[i] + B[j]);
        }
    }
    sort(re_xy.begin(), re_xy.end(), greater<long long>());
    vector<long long> result;
    repp(i,0,Z) {
        repp(j,0,min(K, X*Y)) result.push_back(C[i] + re_xy[j]);
    }

    sort(result.begin(), result.end(), greater<long long>());
    repp(i,0,K) cout << result[i] << endl;
    return 0;

}


Measured memory_bytes: 43240
#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>

using namespace std;

int main() {
    string T, P;

    cin >> T >> P;

    vector<pair<string, uint32_t>> sa;
    for (uint32_t i = 0; i < T.length(); i++) {
        sa.push_back(make_pair(T.substr(i, T.length()-i), i));
    }

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

    auto itr_lb = lower_bound(sa.begin(), sa.end(), P, [](pair<string, uint32_t> p, string s) {return p.first < s;});
    auto itr_ub = upper_bound(sa.begin(), sa.end(), P, [](string s, pair<string, uint32_t> p) {return s < p.first.substr(0, s.length());});

    vector<uint32_t> indexes;
    for (auto itr = itr_lb; itr != itr_ub; itr++) {
        indexes.push_back((*itr).second);
    }

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

    for (uint32_t index : indexes) {
        cout << index << endl;
    }

    return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define max(x, y) ((x) > (y) ? (x) : (y))
#define min(x, y) ((x) < (y) ? (x) : (y))
#define abs(x) ((x) < 0 ? (-(x)) : (x))
#define rep(i,a,m) for((i) = (a) ; (i) < (m) ; ++(i))
#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define rall(x) x.end(),x.begin()
#define sz(x) ((int)x.size())
#define PI 3.14159265

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pi;
int a, b, c, i, j, k;
long long ans = 0LL;
long double eps = 1.0E-14;
long long MOD = 1000000007;

int main ()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t,T;
	cin >> T;	
	T %= 10;
    switch(T) {
        case 2:
        case 4:
        case 5:
        case 7:
        case 9:
            cout << "hon\n";
            break;
        case 0:
        case 1:
        case 6:
        case 8:
            cout << "pon\n";
            break;
        case 3:
            cout << "bon\n";
            break;
    }
	return 0;
}

Measured memory_bytes: 3612
#include <iostream>

using namespace std;

int dp[5005][5005];

int main()
{
    int N;
    std::string S;
    cin >> N >> S;

    for (int i = N - 1; i >= 0; --i)
    {
        for (int j = N - 1; j >= 0; --j)
        {
            if (S[i] != S[j])
            {
                dp[i][j] = 0;
            }
            else
            {
                dp[i][j] = dp[i+1][j+1] + 1;
            }
        }
    }

    int ans = 0;
    for (int i = N - 1; i >= 0; --i)
    {
        for (int j = N - 1; j >= 0; --j)
        {
            if (i >= j) continue;

            int x = min(dp[i][j], j - i);
            ans = max(x, ans);
        }
    }

    cout << ans << endl;

    return 0;
}


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

using namespace std;

int main()
{
	int i, n, temp, j, k;
	vector<int> v;

	cin >> n >> k;
	vector<int> dp(n,INT_MAX);
	for(i=0;i<n;i++)
	{
		cin >> temp;
		v.push_back(temp);
	}
	dp[0] = 0;
	dp[1] = abs(v[1]-v[0]);

	for(i=2;i<n;i++)
	{
		for(j=i-1;j>i-1-k;j--)
		{
			if(j<0)
			{
				break;
			}

			if(dp[j] + abs(v[i]-v[j]) < dp[i])
			{
				dp[i] =  dp[j] + abs(v[i]-v[j]);
			}

		}
	}

	cout << dp[n-1] << endl;

	return 0;
}

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

// types
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<pll> vpl;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

const ull B = 100000007;
bool contain(string a, string b){
  ll al = a.size(), bl = b.size();
  if(al > bl)
    return false;

  ull t = 1;
  REP(i, al)
    t *= B;
  ull ah = 0, bh = 0;
  REP(i, al)
    ah = ah*B + a[i];
  REP(i, al)
    bh = ah*B + b[i];

  for(ll i = 0; i + al <= bl; i++){
    if(ah == bh)
      return true;
    if(i+al < bl)
      bh = bh*B + b[i+al]-b[i]*t;
  }
}

struct RollingHash{
  static const ll base1 = 1007, base2 = 1009;
  static const ll mod1 = 1e9+7, mod2 = 1e9+9;
  vll hash1, hash2, power1, power2;
  RollingHash(string s){
    ll n = s.size();
    hash1.assign(n+1, 0);
    hash2.assign(n+1, 0);
    power1.assign(n+1, 1);
    power2.assign(n+1, 1);
    for(int i = 0; i<n; i++){
      hash1[i+1] = (hash1[i]*base1+s[i])%mod1;
      hash2[i+1] = (hash2[i]*base2+s[i])%mod2;
      power1[i+1] = (power1[i]*base1)%mod1;
      power2[i+1] = (power2[i]*base2)%mod2;
    }
  }

  inline pair<ll, ll> get(ll l, ll r){
    ll res1 = hash1[r] - hash1[l]*power1[r-l]%mod1;
    if(res1<0)
      res1 += mod1;
    ll res2 = hash2[r] - hash2[l]*power2[r-l]%mod2;
    if(res2<0)
      res2 += mod2;
    return {res1, res2};
  }
};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n;
  cin >> n;
  string s;
  cin >> s;

  RollingHash rh(s);


  auto check = [&](ll m){
    bool flag = false;

    REP(l, n){
      for(ll r=l+1; r<n; r++){
        if(rh.get(l, l+m) == rh.get(r, r+m) && m <= r-l){
          flag = true;
          break;
        }
      }
      if(flag)
        break;
    }

    return flag;
  };


  //binary search for m
  ll ans = 0;
  ll ok = 0;
  ll ng = n/2+1;
  while(ng-ok>1){
    ll mid = (ok+ng)/2;
    if(check(mid))
      ok = mid;
    else
      ng = mid;
  }
  ans = ok;
  cout << ans << endl;
}


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

typedef long long ll ;
#define pb push_back
ll ans[200][200106] ;
vector<ll> w , v ;

ll n , cap ;




int main() {

    ll i ,j;
    cin >> n >> cap ;
    w.resize(n+2) ;
    v.resize(n+2) ;

    for(i=1;i<=n;i++)   cin >> w[i] >> v[i] ;

    for(i=0;i<=n;i++) for(j=0;j<=200007;j++) ans[i][j] = INT_MAX ;

    for(i=1;i<=n;i++) {
        for(j=200006;j>=0;j--) {
            if (v[i]==j) {
                ans[i][j]= min(ans[i-1][j],w[i]) ;
            }
            else if (v[i]<j){
               // if (j==11 and i==2) cout << j-v[i] ;
                ans[i][j] = min(ans[i-1][j],ans[i-1][j-v[i]]+w[i]) ;
            }
            else ans[i][j] = ans[i-1][j] ;
        }
    }


    ll as =  0 ;
    for(i=0;i<=n;i++) {
        for(j=0;j<=200007;j++)  {
            if (ans[i][j]!=INT_MAX and ans[i][j]<=cap ) as = max(as,j) ;
        }
    }
    cout << as << endl ;

    return 0 ;


}


Measured memory_bytes: 160000
import Control.Applicative
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as B
import Data.List
import Data.Char (isSpace)
import Text.Printf

main :: IO ()
main = getLine >> solve <$> (sortBy (flip compare) <$> f) >>= printf "%.6f\n"
  where
    f = readil B.readInt <$> B.getLine

solve :: [Int] -> Double
solve (w:x:y:z:as) = let re1 = fromIntegral (y + z) / fromIntegral (w - x)
                         re2 = fromIntegral (w + z) / fromIntegral (x - y)
                         re3 = fromIntegral (w + x) / fromIntegral (y - z)
                         re4 = f (fromIntegral (w + x)) 0 (z:as)
                     in maximum [re1, re2, re3, re4]
  where
    f _ mx [_] = mx
    f nr mx (x:y:ys) = f nr (max mx (nr / fromIntegral (x - y))) (y:ys)

readil :: Integral a =>  (ByteString -> Maybe (a, ByteString)) -> ByteString -> [a]
readil f = unfoldr $ \s -> do
  (n, s') <- f s
  return (n, B.dropWhile isSpace s')



Measured memory_bytes: 4380
#include<iostream>
#include<queue>
#include<vector>
using namespace std;
#define MAX 100000
#define INFTY (1 << 30)

class Edge {
public:
    int t, w;
    Edge(){}
    Edge(int t, int w): t(t), w(w) {}
};

vector<Edge> G[MAX];
int n, d[MAX];

bool vis[MAX];
int cnt;

void bfs(int s) {
    for(int i = 0; i < n; i++) d[i] = INFTY;
    queue<int> Q;
    Q.push(s);
    d[s] = 0;
    int u;
    while(!Q.empty()) {
        u = Q.front();
        Q.pop();
        for(int i = 0; i < G[u].size(); i++) {
            Edge e = G[u][i];
            if(d[e.t] == INFTY) {
                d[e.t] = d[u] + e.w;
                Q.push(e.t);
            }
        }
    }
}

void solve() {
    //適当な視点sから最も遠い節点tgtを求める
    bfs(0);
    int maxv = 0;
    int tgt = 0;
    
    for(int i = 0; i < n; i++) {
        if(d[i] == INFTY) continue;
        if(maxv < d[i]) {
            maxv = d[i];
            tgt = i;
        }
    }
    
    //tgtから最も遠い節点の距離maxvを求める
    bfs(tgt);
    maxv = 0;
    for(int i = 0; i < n; i++) {
        if(d[i] == INFTY) continue;
        maxv = max(maxv, d[i]);
    }
    
    cout << maxv << endl;
}

main() {
    int s, t, w;
    cin >> n;
    
    for(int i = 0; i < n-1; i++) {
        cin >> s >> t >> w;
        
        G[s].push_back(Edge(t, w));
        G[t].push_back(Edge(s, w));
    }
    
    solve();
}


Measured memory_bytes: 9820
#pragma GCC optimize ("Ofast","unroll-loops")
#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define MP make_pair
#define F first
#define S second
#define setpre(a) cout.precision(a),cout<<fixed;
#define ALL(a) a.begin(),a.end()
#define MEM(a,b) memset(a,b,sizeof a)
#define Tie ios::sync_with_stdio(0),cin.tie(0);
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int a,b,c;

int main()
{
	cin>>a>>b>>c;
	if(a+c==b<<1)
		cout << "YES\n";
	else
		cout << "NO\n";
}


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

using namespace std;

using vec = vector<uint32_t>;

int Partition(vec& A, const int p, const int r);
int Partition(vec& A);

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

	int n;
	vec A;

	cin >> n;
	A.resize(n);
	int tmp;
	for(auto&& e : A){
		cin >> e;
	}

	const int index = Partition(A);

	for(int i = 0; i < A.size(); i++){
		cout << ((index == i) ? "[" : "") << A[i] << ((index == i) ? "]" : "") << ((A.size() - 1 == i) ? "\n" : " ");
	}

	return 0;
}

int Partition(vec& A, const int p, const int r) {
	const int x = A[r];
	int i = -1;
	for(int j = p; j < r; j++) {
		if(x >= A[j]) {
			swap(A[++i], A[j]);
		}
	}
	swap(A[i + 1], A[r]);
	return i + 1;
}

int Partition(vec& A) {
	return Partition(A, 0, A.size() - 1);
}



Measured memory_bytes: 3316
A,B,C,X,Y=map(int,input().split())
mini=float("inf")

for c in range(0,max(X,Y)*2+1,2):
    a = max(0,X-c//2)
    b= max(0,Y-c//2)
    Price = a*A+b*B+c*C
    #print(a,b,c,Price)
    mini=min(Price,mini)
   
print(mini)

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

int main()
{
	char moji[1100], ansmoji[1100];
	bool first = false;

	while (cin >> moji){
		if (first != false){
			cout << " ";
		}
		else {
			first = true;
		}
		for (int i = 0; moji[i] != '\0'; i++){
			if (moji[i] == 'a' && moji[i + 1] == 'p' && moji[i + 2] == 'p' && moji[i + 3] == 'l' && moji[i + 4] == 'e'){
				moji[i] = 'p';
				moji[i + 1] = 'e';
				moji[i + 2] = 'a';
				moji[i + 3] = 'c';
				moji[i + 4] = 'h';
			}
			else if (moji[i] == 'p' && moji[i + 1] == 'e' && moji[i + 2] == 'a' && moji[i + 3] == 'c' && moji[i + 4] == 'h'){
				moji[i] = 'a';
				moji[i + 1] = 'p';
				moji[i + 2] = 'p';
				moji[i + 3] = 'l';
				moji[i + 4] = 'e';
			}
		}
		cout << moji;
	}
	cout << endl;
	return (0);
}

Measured memory_bytes: 1132
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
  string s;
  cin >> s;
  vector<string> ans = {"abc","acb","bac","bca","cab","cba"};
  for (int i = 0; i < 6; i++) {
    if (s == ans[i]) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3568
N,M = list(map(int,input().split()))
S = list(map(int,input().split()))
S = [0] + S
T = list(map(int,input().split()))
T = [0] + T
dp = [[0] * (N+1)  for _ in range(M+1)]
DP = [[0] * (N+1)  for _ in range(M+1)]
dp[0][0] = 1
for n in range(N+1):
    DP[0][n] = 1
for m in range(M+1):
    DP[m][0] = 1
# s = 0
# for i in range(N+1):
#     for j in range(M+1):
#         if S[i] == T[j]:
#             for i2 in range(i):
#                 for j2 in range(j):
#                     dp[i][j] += dp[i2][j2]
#             s += dp[i][j]
# print(s)
for n in range(1,N+1):
    for m in range(1,M+1):
        if S[n] == T[m]:
            dp[m][n] = DP[m-1][n-1]
        DP[m][n] = (DP[m-1][n] + DP[m][n-1] + dp[m][n] - DP[m-1][n-1]) % (10**9+7)
print(DP[M][N])

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

using ll = long long;
using P = pair<int, int>;

const int INF = 1e9;
const int MOD = 1e9 + 7;

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

int main() {
  // 入力
  int N;
  cin >> N;

  // 解答
  cout << N / 3 << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <unordered_map>
#include <cstdlib>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
using ll = long long;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(void)
{
    ll K, T, i, a[101], ans=0, half;

    cin >> K >> T;

    if(K%2==0) half = K/2;
    else half = K/2+1;

    for(i=1; i<=T; i++){
        cin >> a[i];

        if(a[i]>half){
            ans += a[i]-(K-a[i])-1;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
//For higher stack size use g++ -O2 -std=c++11 -Wall -Wl,--stack=268435456 a.cpp -o a.exe in cmd
	#include <bits/stdc++.h>
	#include <cstdio>
	#include <cstring>
	#include <cmath>
	#include <cstring>
	#include <chrono>
	#include <complex>
	#define ll long long
	#define ld long double
	#define vi vector<int>
	#define vll vector<ll>
	#define vvi vector < vi >
	#define pii pair<int,int>
	#define pll pair<long long, long long>
	#define mod 1000000007
	#define inf 1000000000000000001;
	#define all(c) c.begin(),c.end()
	#define mp(x,y) make_pair(x,y)
	#define mem(a,val) memset(a,val,sizeof(a))
	#define eb emplace_back
	#define pb push_back
	#define f first
	#define s second
	
	using namespace std;
	ll ar[200001];
	int n;

	ll func(ll x)
	{
		int i;
		ll ans=0;
		for(i=1;i<=n;++i)
			ans=ans+abs(ar[i]-(x+i));
		return ans;
	}

	int main()
	{
		std::ios::sync_with_stdio(false);
		int T;
		T=1;
		// cin.ignore(); must be there when using getline(cin, s)
		while(T--)
		{
			int i,j;
			cin>>n;
			
			for(i=1;i<=n;++i)
				cin>>ar[i];
			ll ans=1e18;
			ll l=-2e9,r=2e9,mid,x,y,ans2=-1;
			while(l<=r)
			{
				mid=(l+r)/2;
				x=func(mid);
				y=func(mid+1);
				//cout<<mid<<" "<<mid+1<<" "<<x<<" "<<y<<endl;
				if(ans>x) 
				{
					ans=x;
					ans2=mid;
				}
				if(ans>y)
				{
					ans=y;
					ans2=mid+1;
				}
				//ans=min(ans,min(x,y));
				if(x<y)
				{
					r=mid-1;
				}
				else
				{
					l=mid+1;
				}
			}
			cout<<ans<<endl;

		}
		return 0;
	}


Measured memory_bytes: 1792
# 辞書順かつ大きい順（リスト）
n = int(input())
hash = {}
for i in range(n):
    s, p = input().split()
    p = int(p)
    if s in hash.keys():
        hash[s].append([i, p])
    else:
        hash[s] = list()
        hash[s].append([i, p])

hash = sorted(hash.items())
for k, v in hash:
    vs = sorted(v, key=lambda x: x[1], reverse=True)
    for i in vs:
        print(i[0]+1)


Measured memory_bytes: 38640
#include<bits/stdc++.h>
using namespace std;
int64_t dist[200005];
int64_t color[200005];
int64_t N,M,Q;
using Graph=vector<vector<int64_t>>;
int main(){
  cin>>N>>M;
  Graph G(N);
  for(int i=0;i<N;i++)
  dist[i]=-1;
   
  for(int i=0;i<M;i++){
  int64_t a,b;cin>>a>>b;a--;b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }cin>>Q;
  vector<tuple<int64_t,int64_t,int64_t>>A(Q);
  for(int i=Q-1;0<=i;i--){
   int64_t v,d,c;cin>>v>>d>>c;v--;
    tuple<int64_t,int64_t,int64_t>t(v,d,c);
    A.at(i)=t;
   }
  for(int i=0;i<Q;i++){
  int64_t v=get<0>(A[i]);
    int64_t d=get<1>(A[i]);
    int64_t c=get<2>(A[i]);
    if(d<=dist[v])
      continue;
    else{
      dist[v]=d;
    queue<int64_t>que;que.push(v);
      while(!que.empty()){
      int64_t u=que.front();
        que.pop();
        if(color[u]==0)color[u]=c;
        for(auto k:G[u])
           if(dist[u]-1<=dist[k])
             continue;
        else{
        dist[k]=dist[u]-1;
          que.push(k);
        }
          
   }
    
    }
   }for(int i=0;i<N;i++)
    cout<<color[i]<<endl;
  return 0;
}

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

#define for_(i,a,b) for(int i=a;i<b;++i)

int n, m, a[10];
string id;

int dp[2][10];

void solve() {	
	memset(dp, 0, sizeof(dp));
	dp[0][0] = 1;
	
	for_(i,0,n) {
		int ii = n - i - 1, nw = i % 2, nx = (i + 1) % 2;
		
		for_(j,0,10) dp[nx][j] = 0;
		
		for_(j,0,10) {
			if (id[ii] == '*') {
				for_(k,0,m) {
					int v = a[k] * (i % 2 + 1);
					int jj = ( j + (v % 10) + (v / 10) ) % 10;
					dp[nx][jj] += dp[nw][j];
				}
			} else {
				int v = (id[ii] - '0') * (i % 2 + 1);
				int jj = ( j + (v % 10) + (v / 10) ) % 10;
				dp[nx][jj] += dp[nw][j];
			}
		}
	}
	
	cout << dp[n % 2][0] << endl;
}

int main() {
	cin >> n >> id >> m;
	for_(i,0,m) cin >> a[i];
	solve();
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

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

    map<char, int> m;

    string x,y;
    int ans = 0;
    FOR(i,1,n){
        int tmp = 0;
        x = s.substr(0,i);
        y = s.substr(i,s.size());

        //DEBUG(x);
        //DEBUG(y);
        REP(j,x.size()){
            if(m[x[j]] != 1)
                m[x[j]] = 1;
        }
        REP(j,y.size()){
            if(m[y[j]] == 1)
                m[y[j]] = 2;
        }

        for(auto j=m.begin(); j != m.end(); j++){
            if( j->second == 2)
                tmp++;
        }

        if(ans < tmp)
            ans = tmp;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

N, K = map(int, input().split())
P = list(map(lambda x: int(x) - 1, input().split()))
C = list(map(int, input().split()))
ans = -float('inf')
for s in range(N):
    c = 0
    i = P[s]
    score = C[i]
    ans = max(ans, score)
    c += 1
    while i != s and c < K:
        i = P[i]
        score += C[i]
        ans = max(ans, score)
        c += 1
    if c == K or score <= 0:
        continue
    q = K // c
    score *= q - 1
    c *= q - 1
    while c < K:
        i = P[i]
        score += C[i]
        ans = max(ans, score)
        c += 1
print(ans)

Measured memory_bytes: 68320
import java.util.*

fun main(args: Array<String>) {
  val (N, M) = readInts()
  val edges = Array(N + 1) { mutableListOf<Int>() }
  repeat(M) {
    val (A, B) = readInts()
    edges[A].add(B)
    edges[B].add(A)
  }

  val memo = Array(N + 1) { -1 }
  memo[1] = 1

  val queue = ArrayDeque<Int>()
  queue.add(1)
  while (true) {
    if (queue.isEmpty()) break
    val n = queue.first
    queue.removeFirst()
    val e = edges[n]
    e.forEach {
      if (memo[it] == -1) {
        memo[it] = n
        queue.addLast(it)
      }
    }
  }

  println(if (memo.count { it == -1 } <= 1) "Yes" else "No")
  print(buildString {
    for (i in 2 until memo.size) {
      appendln(memo[i])
    }
  })
}

fun readString() = readLine()!!
fun readStrings() = readString().split(" ")
fun readInt() = readString().toInt()
fun readLong() = readString().toLong()
fun readInts() = readStrings().map { it.toInt() }
fun readLongs() = readStrings().map { it.toLong() }


Measured memory_bytes: 77744
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

const ll mod = 1e9 + 7;

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

    ll n, m;
    cin >> n >> m;
    ll a, s = 0;
    REP(i, m) {
        cin >> a;
        s += a;
    }
    if (s > n) cout << -1 << endl;
    else cout << n - s << endl;
    return 0;
}

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

using namespace std;

int main(){
  long long N, A, B;
  cin >> N >> A >> B;
  
  long long blue = N / (A + B) * A;
  blue += min(A, N % (A + B));
  
  cout << blue << endl;
  
  return 0;
}

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

vector<int> to[100005];
int main(void){
    // Your code here!
    int n,m;
    cin>>n>>m;
    int a,b;
    
    for(int i=0;i<m;i++){
        cin>>a>>b;
        a--;
        b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    vector<int> dist(n, 10e8);
    vector<int> pre(n,-1);
    queue<int> q;
    dist[0]=0;
    q.push(0);
    
    while(!q.empty()){
        int v = q.front(); q.pop();
        for(int u: to[v]){
            if(dist[u] != 10e8) continue;
            dist[u] = dist[v]+1;
            pre[u] = v;
            q.push(u);
        }
    }
    
    cout<<"Yes"<<endl;
    for(int i=0;i<n;i++){
        if(i==0) continue;
        int ans = pre[i]+1;
        cout<<ans<<endl;
    }
    
}


Measured memory_bytes: 10616
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

int main(){
  ll N;
  cin >> N;
  if(N == 1) cout << 0 << endl;
  if(N == 0) cout << 1 << endl;
  return 0;
}

Measured memory_bytes: 3628