akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



#define SIZE 100005
#define SPAN 320

struct Info{

	int a,b;
};

struct Query{
	bool operator<(const struct Query &arg) const{
		if(backet_index != arg.backet_index){

			return backet_index < arg.backet_index;
		}else{
			return right < arg.right;
		}
	}
	int command,left,right,value,input_index,backet_index;
};


int N,K,Q;
int table[SIZE],LOC[SIZE],ans[SIZE];
Info info[SIZE];
Query query[SIZE];

void move_L(int index){

	int loc_A = LOC[info[index].a],loc_B = LOC[info[index].b];
	swap(table[loc_A],table[loc_B]);
	swap(LOC[table[loc_A]],LOC[table[loc_B]]);
}

void move_R(int index){

	swap(table[info[index].a],table[info[index].b]);
	swap(LOC[table[info[index].a]],LOC[table[info[index].b]]);
}


int main(){

	scanf("%d %d %d",&N,&K,&Q);

	for(int i = 0; i < N; i++){

		table[i] = i;
		LOC[i] = i;
	}

	for(int i = 0; i < K; i++){

		scanf("%d %d",&info[i].a,&info[i].b);
		info[i].a--;
		info[i].b--;
	}

	for(int i = 0; i < Q; i++){

		scanf("%d %d %d %d",&query[i].command,&query[i].left,&query[i].right,&query[i].value);
		query[i].left--;
		query[i].value--;
		query[i].input_index = i;
		query[i].backet_index = query[i].left/SPAN;
	}

	sort(query,query+Q);

	int L = 0,R = 0;

	for(int i = 0; i < Q; i++){

		while(query[i].left < L){

			move_L(--L);
		}
		while(query[i].right > R){

			move_R(R++);
		}
		while(query[i].left > L){

			move_L(L++);
		}
		while(query[i].right < R){

			move_R(--R);
		}
		if(query[i].command == 1){

			ans[query[i].input_index] = table[query[i].value];

		}else{ //query[i].command == 2

			ans[query[i].input_index] = LOC[query[i].value];
		}
	}

	for(int i = 0; i < Q; i++){

		printf("%d\n",ans[i]+1);
	}

	return 0;
}



Measured memory_bytes: 7536
from time import time
from random import random

limit_secs = 2
start_time = time()

D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(D)]

def calc_score():
    score = 0
    S = 0
    last = [-1] * 26
    for d in range(D):
        S += s[d][t[d]]
        last[t[d]] = d
        for i in range(26):
            S -= c[i] * (d - last[i])
        score += max(10 ** 6 + S, 0)
    return score

def solution():
    return [i % 26 for i in range(D)]

t = solution()
score = calc_score()
while time() - start_time + 0.14 < limit_secs:
    d = int(random() * D)
    q = int(random() * 26)
    old = t[d]
    t[d] = q
    new_score = calc_score()
    if new_score < score:
        t[d] = old
    else:
        score = new_score
print(*[e + 1 for e in t])


Measured memory_bytes: 9824
#include<bits/stdc++.h>
using namespace std;
int main()
{
        int k;
        string s;
        cin>>k>>s;
        string temp = "";

    if(k>=s.length()){
        cout<<s<<endl;
        return 0;
    }

    for(int i=0;i<k ; i++){
        temp +=s[i];
    }


    temp+="...";

    cout<<temp<<endl;
}


Measured memory_bytes: 3644
#include<iostream>
#include<cstdio>
#include<vector>

using namespace std;

int w,h;
int ans=1;
char tile[21][21];

void saiki(int x,int y){
	if(x<0 | x>h | y<0 | y>w)return;
	tile[x][y]='#';
	if(tile[x-1][y]=='.')ans++,saiki(x-1,y);
	if(tile[x+1][y]=='.')ans++,saiki(x+1,y);
	if(tile[x][y-1]=='.')ans++,saiki(x,y-1);
	if(tile[x][y+1]=='.')ans++,saiki(x,y+1);
}

int main(void){
	int a,b; 
	while(1){
		for(a=0;a<21;a++){
			for(b=0;b<21;b++){
				tile[a][b]='\0';
			}
		}
		scanf("%d %d",&w,&h);
		if(w==0 && h==0)break;
		ans=1;
		for(a=0;a<h;a++){
			scanf("%s",tile[a]);
		}
		for(a=0;a<h;a++){
			for(b=0;b<w;b++){
				if(tile[a][b]=='@')saiki(a,b);
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <iomanip>
using namespace std;
using ll=long long;
const ll MOD = 1000000007;
ll INF = 90000000001000;

int n,k;
ll dp[1 << 21];
int a[25][25];


int main() {
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < n; ++j)
        {
         cin >> a[i][j];           
        }
    }
    dp[0] = 1;
    
       for (int S = 0; S < 1 << n; ++S)
       {
           for (int j = 0; j < n; ++j)
           {

               int i = __builtin_popcount(S);
               if(S >> j & 1 && a[i-1][j]){
                dp[S] += dp[S ^ 1 << j];
                if(dp[S]>MOD)dp[S] -= MOD;
               }
           }
       }


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

return 0;
}




Measured memory_bytes: 16640
fun main(args: Array<String>) {

    val n = readLine()!!.toInt()

    val w = readLine()!!.split(" ").map { it.toInt() }.toTypedArray()

    var min = Int.MAX_VALUE

    for(i in 0 until n){
        var s1 = 0
        var s2 = 0
        for(j in 0 .. i){
            s1 += w[j]
        }
        for(k in i+1 until n){
            s2 += w[k]
        }

        val diff = if(s1 > s2){
            s1-s2
        }else{
            s2-s1
        }

        if(min > diff){
            min = diff
        }
    }

    println(min)
}


Measured memory_bytes: 38068
#include <cstdio>
#include <cmath>
#include <algorithm>
#define maxn 200005
using namespace std;
int n, mid, a[maxn];
long long ans;
int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
		scanf("%d", &a[i]), a[i] -= i;
	sort(a + 1, a + n + 1);
	if (n % 2 == 1) mid = a[n / 2 + 1];
	else mid = (a[n / 2] + a[n / 2 + 1]) / 2;
	for (int i = 1; i <= n; i++)
		ans += abs(a[i] - mid);
	printf("%lld", 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>;

int main() {
  string S,T;
  int p=0;
  cin>>S>>T;
  int a=S.size();
  for(int i=0;i<a;i++){
    if(S.at(i)==T.at(i)){
      p++;
    }
  }
    cout<<a-p<<endl;
}

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

ll dp[5003][5003];

int main()
{
    ll N, M, ans = 0;
    cin >> N >> M;
    
    rep(m, N + 1){
        dp[2][m] = 1;
    }
    reps(n, 3, N + 1){
        rep(m, N + 1){
            int k = min(n - 1, (int)N + 2 - n);
            dp[n][m] = dp[n - 1][m] % M;
            if (m >= k){
                (dp[n][m] += dp[n][m - k]) %= M;
            }
        }
    }
    rep(m, N + 1){
        //fprintf(stderr, "m = %d, %d * %d\n", m, N - m, dp[N][m]);
        (ans += (N - m) * dp[N][m]) %= M;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 195584
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

int N, M;

#include <vector>

struct UnionFind
{
    vector<int> data;

    UnionFind(int sz)
    {
        data.assign(sz, -1);
    }

    bool unite(int x, int y)
    {
        x = root(x), y = root(y);
        if (x == y)
            return false;
        if (data[x] > data[y])
            swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return true;
    }

    int root(int k)
    {
        if (data[k] < 0)
            return k;
        data[k] = root(data[k]);
        return data[k];
    }

    int size(int k)
    {
        return (-data[root(k)]);
    }

    bool same(int x, int y)
    {
        return (root(x) == root(y));
    }
};

int main()
{
    cin >> N >> M;
    vector<vector<int>> L(N);
    UnionFind uf(N + M);
    for (int i = 0; i < N; i++)
    {
        int K;
        cin >> K;
        for (int j = 0; j < K; j++)
        {
            int l;
            cin >> l;
            l--;
            uf.unite(i, l + N);
            L[i].push_back(l);
        }
    }
    for (int i = 0; i < N; i++)
    {
        if (!uf.same(0, i))
        {
            puts("NO");
            return 0;
        }
    }
    puts("YES");
}

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


int main() {
 int N;
  cin >>N;
  vector<int> W(N);
  for(int i=0;i<N;i++) cin >>W[i];
  int m = 100000000;
  for(int t =0;t<N;t++){
   int s=0;
    int ss =0;
    for(int i=0;i<N;i++){
if(i <=t) s += W[i];
      else ss += W[i];
      
    }
    m = min(m,abs(s-ss));
  }
  cout <<m <<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
using namespace std;
int main(){
    int n,m,i,j;
    cin>>n>>m;
    char a[n+1][m+1];
    memset(a,0,sizeof(a));
    for(i=1;i<=n;i++){
        for(j=1;j<=m;j++){
            cin>>a[i][j];
        }
    }
    for(i=1;i<=n;i++){
        for(j=1;j<=m;j++){
            if(a[i][j]=='.'){
                a[i][j]='0';
                if(a[i-1][j-1]=='#') a[i][j]++;
                if(a[i][j-1]=='#') a[i][j]++;
                if(a[i+1][j-1]=='#') a[i][j]++;
                if(a[i-1][j]=='#') a[i][j]++;
                if(a[i+1][j]=='#') a[i][j]++;
                if(a[i-1][j+1]=='#') a[i][j]++;
                if(a[i][j+1]=='#') a[i][j]++;
                if(a[i+1][j+1]=='#') a[i][j]++;
            }
        }
    }
    for(i=1;i<=n;i++){
        for(j=1;j<=m;j++){
            cout<<a[i][j];
        }
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
# include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define pf push_front
# define speed ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std ;
int N = 3e5 + 7 ;
ll N1 = 1e9 + 7 ;
int main( ){
    speed ;
    ll TJK = 1 ;
    // cin >> TJK ;
    while( TJK -- ){
        ll n ;
        cin >> n ;
        ll u = 0 ;
        for( ll i = 0 ; i < 64 ; i ++ ){
            if( n >= pow( 2 , i ) ){
                u = i ;
            }else{
                break ;
            }
        }
        ll ans = 0 ;
        for( int i = 0 ; i <= u ; i ++ ){
            ans += pow( 2 , i ) ;
        }
        cout << ans << endl ;
    }
}


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

int main(){
  int N,K;
  cin>>N>>K;
  vector<int> A(0),B={0};
  for(int i=0;i<N;i++){
    int j;
    cin>>j;
    if(j<0)
      A.push_back(0-j);
    else if(j==0)
      K--;
    else
      B.push_back(j);
  }
  if(K==0){
    cout<<0<<endl;
    return 0;
  }
  A.push_back(0);
  reverse(A.begin(),A.end());
  int j=1000000000;
  for(int i=0;i<=K;i++){
    if(A.size()>i && B.size()>K-i)
      j=min(j,A.at(i)+B.at(K-i)+min(A.at(i),B.at(K-i)));
  }
  cout<<j<<endl;
}

Measured memory_bytes: 1020
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
    int n,a;
    int min = 1000000;
    int max = -1000000;
    long long S = 0;
    int i = 0;
    
    cin >> n;
    
    while(i < n){
        cin >> a;
        
        if(a < min){
            min = a;  
        }
        
        if(a > max){
            max = a;
        }
        
        S = S + a;
        
        i = i + 1;
    }
    
    cout << min << " " << max << " " << S << endl;
}


Measured memory_bytes: 3104
// AOJ_C++.cpp : アプリケーションのエントリ ポイントを定義します。
//
#include <iostream>

int main()
{
	int a, b, c, n = 0;
	std::cin >> a >> b >> c;
	for (int i = a; i < b + 1; ++i) {
		if (c % i == 0) {
			n++;
		}
	}
	std::cout << n << std::endl;
    return 0;
}


Measured memory_bytes: 3124
#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
using namespace std;
#define ll long long
#define INF 1000000007
using P = pair<int, int>;
int main(){
    int n;
    cin>>n;
    int f[100][10];
    for(int i=0;i<n;i++){
        for(int j=0;j<10;j++){
            cin>>f[i][j];
        }
    }
    int p[100][10];
    for(int i=0;i<n;i++){
        for(int j=0;j<11;j++){
            cin>>p[i][j];
        }
    }
    int ans=(-INF);
    for(int bit=0;bit<(1<<10);bit++){
        if(bit==0)continue;
        int r=0;
        for(int i=0;i<n;i++){
            int c=0;
            for(int j=0;j<10;j++){
                if(f[i][j]==1&&(bit&(1<<j)))c++;
            }
            r+=p[i][c];
        }
        ans=max(ans,r);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<int(a);++i)
using ll = long long;
using namespace std;
int main(){
    int x;
    cin>>x;
    int i=1;
    while(105*i<=1000000){
        int min = 100*i,max=105*i;
        if(min<=x && x<=max){
            cout<<1<<endl;
            return 0;
        }
        i++;
    }
    cout<<0<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#include<iostream>
using namespace std;
int main(void)
{
	char s[10];
	scanf("%s",s);
	int i,j,k;
	if(s[0]==s[2])
	printf("Yes\n");
	else
	printf("No\n");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,n) for(ll i=0;i<(n);++i)
#define REPR(i,n) for(ll i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    ll a, b, c;
    scanf("%lld %lld.%lld", &a,&b,&c);

    ll x = a*(b*100+c);
    cout << x/100 << '\n';
    return 0;
}

Measured memory_bytes: 3728
#include <bits/stdc++.h>
typedef long long ll;
#define  rep(i,a,b)for(long long i=a;i<b;++i)
#define  rrep(i,a,b)for(int i=a;i>=b;--i)
#define  yesno(flag)if(flag)cout<<"Yes"<<endl; else cout<<"No"<<endl;
using namespace std;
const ll INF=100000000000000LL;
const ll r197=1000000007;
typedef pair<ll,ll>P;
typedef pair<int,P>Pa;
bool Inframe(int a,int b,int c,int d,int h,int w){
	if(a+b>=0&&a+b<h&&c+d>=0&&c+d<w)return true;
	return false;
}
//void swap(ll a,ll b){
//	ll d;
//	d=a;
//	a=b;
//	b=d;
//	return;
//}
ll mypow(ll x,int m){
	if(m==0)return 1;
	if(m%2==0){
		int x2=mypow(x,m/2);
		return x2*x2;
	}else{
		int x2=mypow(x,m/2);
		return x2*x2*x;
	}
}
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
//    	cout<<b<<endl;
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
int n;
ll t=0;
ll a[200005];
int main() {
	cin>>n;
	rep(i,0,n){
		cin>>a[i];
		t+=a[i];
	}
	ll half = t%2==1?t/2+1:t/2;
	ll k=0,ans=0;
	rep(i,0,n){
		k+=a[i];
		if(k>=half){
//			cout<<k<<endl;
			ans=k-(t-k);
			k-=a[i];
			ans=min(ans,t-k-k);
			break;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1792
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <utility>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#include <climits>
#include <numeric>
#include<stdio.h>
#include <queue>
#include <iomanip>
#include <float.h>
#include <set>
#include<functional>
#include <stack>
#include <time.h>
#include <climits>
#include <bitset>
#include <fstream>
#include<map>
#include <cassert>
#include<sstream>
using namespace std;
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
long long mod = 1e9 + 7;
typedef pair<long long, long long>p;
signed main()
{
	int n, k, s;
	cin >> n >> k >> s;
	for (int i = 0; i < k; i++) {
		cout << s<<" ";
	}
	for (int i = k; i < n; i++) {
		cout << ((s==1e9)?s-1:(s + 1))<<" ";
	}
}


Measured memory_bytes: 1280
#include<iostream>
#include<string>
#include<cmath>

using namespace std;
int main(){
    int N;
    double T,A;
    cin>>N>>T>>A;
    double H[N];
    double tmp;
    double min=1000000000.0;
    int ans;
    for(int i=0;i<N;i++){
        cin>>tmp;
        if(min>abs(A-(T-0.006*tmp))){ans=i;min=abs(A-(T-0.006*tmp));}
        }

    cout<<ans+1<<endl;
}


Measured memory_bytes: 256
import sys

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


def main():
    D = int(readline())

    if D == 25:
        ans = 'Christmas'
    elif D == 24:
        ans = 'Christmas Eve'
    elif D == 23:
        ans = 'Christmas Eve Eve'
    else:
        ans = 'Christmas Eve Eve Eve'

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9052
#include<bits/stdc++.h>
using namespace std;
int main()
{

  int l,r,d;
  cin>>l>>r>>d;
  int count=0;
  for(int i=l;i<=r;i++)
  {
    if(i%d==0)
      count++;

    
  }
  cout<<count<<endl;
  
  
}

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i, n) for(int i = (int)(n); i >= 0; i--)
#define repm(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define repmr(i, m, n) for(int i = (int)(n); i >= (int)(m); i--)
#define all(x) (x).begin(),(x).end()
#define inf 2e9

using namespace std;
typedef long long int lli;
typedef long long ll;

int n,q;
vector<vector<int>> tree(200000, vector<int>());

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

    if(a.back() == b.front() && b.back() == c.front()){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 4992
N, M = map(int, input().split())

arrs = []
for _ in range(M):
  s = input().split()
  arrs.append(list(map(int, s[1:])))
ps = list(map(int, input().split()))

ans = 0
for i in range(2 ** N):
  for arr, p in zip(arrs, ps):
    odd = False
    for a in arr:
      if i & 1<<(a-1):
        odd = not odd
    if int(odd) != p:
      break
  else:
    ans += 1
print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;

class Main
{
	public static void main(String[] args)
	{
		Scanner sc=new Scanner(System.in);
		int[] A=new int[2];
		A[0]=sc.nextInt();A[1]=sc.nextInt();int C=sc.nextInt(),D=sc.nextInt(),E=sc.nextInt(),F=sc.nextInt();
		double max=0;
		int[] ans=new int[2];
		int alim=F/(100*A[0]),aalim=F/(100*A[1]);


		for(int l=0;l<=alim;l++)
		{for(int m=0;m<=aalim;m++)
		{
			int watercnt=A[0]*l+A[1]*m;


		for(int i=0;i<2;i++)
		{
			int lim=watercnt*E;
			int clim=lim/C,dlim=lim/D;
			for(int j=0;j<=clim;j++)
			{
				for(int k=0;k<=dlim;k++)
				{
					int sugar=C*j+D*k;
					if(lim<sugar){break;}
					if(100*watercnt+sugar>F){break;}
					double buf=100.0*(double)sugar/((double)(100*watercnt)+(double)sugar);
					if(buf>max){max=buf;ans[0]=100*watercnt+sugar;ans[1]=sugar;}
				}
			}
		}
		}
		}
		if(max==0){System.out.println(100*A[0]+" "+0);}
		else{System.out.println(ans[0]+" "+ans[1]);}


	}
}

Measured memory_bytes: 23252
# N = int(input())
# N = map(int,input().split())
# N = list(map(int,input().split()))


X,Y,A,B,C = map(int,input().split())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
R = list(map(int,input().split()))

P = sorted(P,reverse=True)
Q = sorted(Q,reverse=True)
R = sorted(R,reverse=True)
P = P[:X]
Q = Q[:Y]
P.append(-100)
Q.append(-100)
R.append(-100)

ans = sum(P)+sum(Q)

p=0
q=0
r=0

x = 0
y = 0

ans = 0
while(x<=X or y<=Y):
    mm = max(P[p],Q[q],R[r])
    if R[r] == mm:
        ans += R[r]
        r+=1
    elif P[p]==mm:
        ans += P[p]
        p+=1
        x+=1
    elif Q[q]==mm:
        ans += Q[q]
        q+=1
        y+=1
    if (x+y+r)==(X+Y):
        break
    # print(p,q,r)

print(ans)

# print(p,q,r) 





Measured memory_bytes: 22720
import heapq

x, y, z, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A = sorted(A, reverse=True)
B = sorted(B, reverse=True)
C = sorted(C, reverse=True)




AB = []

for i in range(x):
    for j in range(y):
        AB.append(A[i]+B[j])

AB = sorted(AB, reverse=True)
AB = AB[:min(k, x*y)]
# print(AB)

ABC = []
for l in range(min(k, x*y)):
    for m in range(z):
        ABC.append(AB[l] + C[m])

ABC = sorted(ABC, reverse=True)
for i in range(k):
    print(ABC[i])



# ------------優先度付きキュー----------

# hq = []
# heapq.heapify(hq)
# i, j, l = 0, 0, 0

# heapq.heappush(hq, [(A[i]+B[j]+C[l])*-1, i, j, l])
# Used = []

# for i in range(k):
#     now = heapq.heappop(hq)
#     print(now[0]*-1)
#     i = now[1]
#     j = now[2]
#     l = now[3]

#     if i >= x-1:
#         pass
#     elif [(A[i+1]+B[j]+C[l])*-1, i+1, j, l] not in Used:
#         Used.append([(A[i+1]+B[j]+C[l])*-1, i+1, j, l])
#         heapq.heappush(hq, [(A[i+1]+B[j]+C[l])*-1, i+1, j, l])
        
#     if j >= y-1:
#         pass
#     elif [(A[i]+B[j+1]+C[l])*-1, i, j+1, l] not in Used:
#         Used.append([(A[i]+B[j+1]+C[l])*-1, i, j+1, l])
#         heapq.heappush(hq, [(A[i]+B[j+1]+C[l])*-1, i, j+1, l])
        
#     if l >= z-1:
#         pass
#     elif [(A[i]+B[j]+C[l+1])*-1, i, j, l+1] not in Used:
#         Used.append([(A[i]+B[j]+C[l+1])*-1, i, j, l+1])
#         heapq.heappush(hq, [(A[i]+B[j]+C[l+1])*-1, i, j, l+1])
        
#     # print(hq)

Measured memory_bytes: 149504
#include<vector>
#include<iostream>
#include<algorithm>
#include<functional>
#include<string>
#include<limits.h>
#include<cmath>
#include<queue>
#include<map>
#define rep(i,n) for (int i=0; i<n; i++)
using namespace std;
typedef long long ll;

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

int main(){

  int n; cin >> n;
  vector<int> l(n); rep(i,n){cin>>l[i];}

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

  int ans=0;

  for (int low = 0; low < n-2; low++){
    for (int mid = low+1; mid < n-1; mid++){
      auto itr = lower_bound(l.begin(), l.end(), l[low]+l[mid]);
      int ng = distance(itr, l.end());
      ans += n-1-mid-ng;
    }
  }

  cout << ans;


  return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<iostream>
#include<numeric>
#include<queue>
#include<sstream>
#include<stack>
#include<string>
#include<unordered_set>
#include<vector>

#define ll long long
#define P pair<int,int>
#define FOR(i,N) for(int i=0;i<(int)N;i++)
#define FORIN(i,a,b) for(int i=a;i<(int)b;i++)
#define ALL(x) (x).begin(),(x).end()
#define LAST(x) (x)[(x).size()-1]

using namespace std;

string to_hex(int x){
    stringstream ss;
    ss<<hex<<x;
    return ss.str();
}

inline int get_int(){
    int ret;
    scanf("%d",&ret);
    return ret;
}

inline vector<int> get_ints(int n){
    vector<int> ret(n);
    FOR(i,n){
        scanf("%d",&ret[i]);
    }
    return ret;
}

inline string get_str(){
    string ret;
    cin>>ret;
    return ret;
}

bool is_prime(int n){
    int s=sqrt(n)+1;
    for(int i=2;i<=s;++i){
        if(n%i==0){
            return 0;
        }
    }
    return 1;
}

vector<P> prime_division(int n){
    vector<P> ret;
    int s=sqrt(n)+1;
    int c=0;
    for(int i=2;i<=s;++i){
        if(n%i==0){
            c=0;
            do{
                ++c;
                n/=i;
            }while(n%i==0);
            ret.push_back(P(i,c));
        }
    }
    return ret;
}

string to_string(string s){
    return s;
}

template<class T>
string to_string(vector<T> v){
    string ret="{";
    FOR(i,v.size()-1){
        ret+=to_string(v[i])+",";
    }
    if(v.size()>0){
        ret+=to_string(LAST(v));
    }
    ret+="}";
    return ret;
}

void debug(){
    cerr<<endl;
}

template<class Head,class... Tail>
void debug(Head head,Tail... tail){
    cerr<<" "<<to_string(head);
    debug(tail...);
}

int main(){
    int N,H;
    cin>>N>>H;
    vector<int> throwing(N);
    int max_a=0;
    FOR(i,N){
        int a,b;
        cin>>a>>b;
        if(max_a<a)max_a=a;
        throwing[i]=b;
    }
    int c=0;
    sort(ALL(throwing));
    for(int i=N-1;i>=0;--i){
        if(throwing[i]<=max_a)break;
        H-=throwing[i];
        ++c;
        if(H<=0){
            break;
        }
    }
    if(H>0)c+=(H+max_a-1)/max_a;
    cout<<c<<endl;
    return 0;
}

Measured memory_bytes: 640
r1,c1,r2,c2 = map(int,input().split())
mod = 10**9+7

def p_mod(m,n,p):
    a = 1
    for i in range(n):
        a = a*(m-i) % p
    return a

def c_mod(m,n,p):
    return (p_mod(m,n,p)*pow(p_mod(n,n,p),p-2,p)) % p

print((c_mod(r2+c2+2,r2+1,mod) - c_mod(r1+c2+1,r1,mod) - c_mod(r2+c1+1,c1,mod) + c_mod(r1+c1,r1,mod)) % mod)

Measured memory_bytes: 38384
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include "bits/stdc++.h"

#define REP(i,x,y) for(int i=(x);i<(y);i++)
#define RREP(i,x,y) for(int i=(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
//#define int long long

using namespace std;

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

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#else
#define eprintf(...)
#define dump(x)
#define debug(x)
#endif

typedef long long ll;

const ll MOD = 1e9 + 7;

class DMegalomania {
public:
	void solve(std::istream& in, std::ostream& out) {
	    int N;
	    in >> N;
	    vector<pair<int, int>> tasks(N);
	    REP(i,0,N) in >> tasks[i].second >> tasks[i].first;

	    sort(all(tasks));

	    bool answer = true;
	    int time = 0;
	    REP(i,0,N) {
	        time += tasks[i].second;
	        if (time > tasks[i].first) {
	            answer = false;
	            break;
	        }
	    }

	    out << (answer ? "Yes" : "No") << "\n";
	}
};


int main() {
	DMegalomania solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

class Main {
    static class UnionFind {
	int [] data;
	UnionFind(int n) {
	    data = new int[n];
	    for(int i = 0; i < n; i++) data[i] = -1;
	}
	int root(int x) {
	    if(data[x] < 0) return x;
	    data[x] = root(data[x]);
	    return data[x];
	}
	boolean find(int x, int y) { 
	    return root(x) == root(y);
	}
	void union(int x,  int y) {
	    x = root(x); 
	    y = root(y);
	    if (x != y) {
		if (data[x] < data[y]) {
		    int t = x;
		    x = y;
		    y = t;
		}
		data[x] += data[y]; 
		data[y] = x;
	    }
	}
    }
    static int n;
    public static void main(String [] args) throws Exception {
	Scanner sc = new Scanner(System.in);
	n = sc.nextInt();
	int m = sc.nextInt();
	int [][] es = new int[m][4];
	for(int i = 0; i < m; i++) {
	    es[i][1] = sc.nextInt() - 1; // from
	    es[i][2] = sc.nextInt() - 1; // to
	    es[i][0] = sc.nextInt(); // cost
	    es[i][3] = 0;
	}
	Arrays.sort(es, new Comparator<int[]>() {
		public int compare(int [] x1, int [] x2) {
		    for(int i = 0; i < 3; i++) {
			int d = x1[i] - x2[i];
			if(d != 0) return d;
		    }
		    return 0;
		}
		public boolean equals(Object o) { return true; }
	    });
	int mn = mst(es, -1);
	// System.out.println("mst = " + mn);
	int c = 0, k = 0;
	for(int i = 0; i < es.length; i++) {
	    if(es[i][3] == 1) {
		int mm = mst(es, i);
		if(mm != mn) {
		    c += es[i][0];
		    k++;
		}
	    }
	}
	System.out.println("" + k + " " + c);
    }
    static int mst(int [][] es, int skip) {
	UnionFind uf = new UnionFind(n);
	int c = 0;
	for(int i = 0; i < es.length; i++) {
	    if(i == skip) continue;
	    if(!uf.find(es[i][1], es[i][2])) {
		c += es[i][0];
		es[i][3] = 1;
	    }
	    uf.union(es[i][1], es[i][2]);
	}
	return c;
    }
}



Measured memory_bytes: 80672
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <string>
#include <map>
using namespace std;
int x,n;
int ai[110];
int main()
{
    int i,j;
    scanf("%d%d",&n,&x);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&ai[i]);
    }
    sort(ai+1,ai+1+n);
    int ans=0;
    for(i=1;i<=n;i++)
    {
        if(ai[i]<=x)
        {
            ans++;
            x-=ai[i];
        }
        else
        {
            x=-1;
            break;
        }
    }
    if(x>0) ans--;
    printf("%d\n",ans);
	return 0;
}



Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

const (
	SCANNER_BUF_SIZE = 2 << 20

	INF = int64(math.MaxInt64)
	MOD = 1e9 + 7
)

var (
	writer  *bufio.Writer
	scanner *bufio.Scanner
)

func init() {
	writer = bufio.NewWriter(os.Stdout)
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, SCANNER_BUF_SIZE), SCANNER_BUF_SIZE)
}

func printf(f string, a ...interface{}) {
	fmt.Fprintf(writer, f, a...)
}

func sint64() int64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := int64(0)
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int64(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func suint64() uint64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := uint64(0)
	for _, b := range bb {
		i *= 10
		i += uint64(b - '0')
	}
	return i
}

func sstring() string {
	scanner.Scan()
	return scanner.Text()
}

func gcd(a, b int64) int64 {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func lcm(a, b int64) int64 {
	return a * b / gcd(a, b)
}

func abs(a int64) int64 {
	if a < 0 {
		return a * -1
	}
	return a
}

func min(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r < a {
			a = r
		}
	}
	return a
}

func max(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r > a {
			a = r
		}
	}
	return a
}

func main() {
	defer writer.Flush()
	c := sstring()[0]
	if c >= 'A' && c <= 'Z' {
		printf("A")
	} else {
		printf("a")
	}
}


Measured memory_bytes: 1840
x = int(input())
candidate = [1] * (10 ** 5 + 1)
ans = 0
for i in range(1, 10 ** 5 + 1):
    candidate[i] = candidate[i - 1] + i + 1
    if candidate[i] > 10 ** 9:
        break
for i in range(len(candidate)):
    if x <= candidate[i]:
        print(i + 1)
        exit()

Measured memory_bytes: 5236
/*
 * @Author       : nonameless
 * @Date         : 2020-09-13 20:02:06
 * @LastEditors  : nonameless
 * @LastEditTime : 2020-09-13 20:12:23
 */
#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define sz(x) (int)x.size()
#define toStr(name) (#name)
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
const double eps = 1e-6;
const double PI  = acos(-1.0);
const int INF = 0x3f3f3f3f;
const ll LNF  = 0x3f3f3f3f3f3f3f3f;
inline int gcd(int a, int b) { return b ? gcd(b,a % b):a;}
inline ll  gcd(ll  a, ll  b) { return b ? gcd(b,a % b):a;}
inline int lcm(int a, int b) { return a * b / gcd(a, b); }

template<class T>
inline void read(T &x){
    x = 0;
    int f = 1;
    char c = getchar();
    while(c < '0' || c > '9') if(c == '-') { f = -1; c = getchar(); }
    while(c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); }
    x = x * f;
}

template<class T>
inline void out(string a, T x){ cout << a << " = " << x << endl; }


int main(){

    ll a, b, c, d; cin >> a >> b >> c >> d;
    ll ans = -LNF;
    ans = max(ans, a * c);
    ans = max(ans, a * d);
    ans = max(ans, b * c);
    ans = max(ans, b * d);
    if(ans < 0){
        if(a <= 0 && b >= 0) ans = 0;
        if(c <= 0 && d >= 0) ans = 0;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <set>
#include <map>
#include <cassert>
#include <fstream>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main() {
    
    
    int n;
    cin >> n;
    
    double sum = 0;
    for (int i = 0; i < n; ++i)
    {
        double tmp;
        cin >> tmp;
        sum += (1.0 / tmp);
    }
    
    double ret = 1.0 / sum;
    cout << fixed << setprecision(10) << ret << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

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

ll lcm(ll x, ll y) {
    return x / gcd(x,y) * y;
}

int main(void)
{
    IOS
    ll X, Y;
    cin >> X >> Y;
    if (gcd(X,Y) == Y) OUT(-1)
    else OUT(X)

    return 0;
}

Measured memory_bytes: 256
N, A, B, C = map(int, input().split())
l = [int(input()) for i in range(N)]
INF = 10 ** 9
def dfs(cur, a, b, c):
	if cur == N:
		return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF
	ret0 = dfs(cur + 1, a, b, c)
	ret1 = dfs(cur + 1, a + l[cur], b, c) + 10
	ret2 = dfs(cur + 1, a, b + l[cur], c) + 10
	ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10
	return min(ret0, ret1, ret2, ret3)
print(dfs(0, 0, 0, 0))

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

int product(vector<int> v1, vector<int> v2, int c)
{
    int ans = c;
    for (auto i = 0; i < v1.size(); i++)
    {
        ans += v1[i] * v2[i];
    }

    return ans;
}

int main()
{

    int n, m, c;
    cin >> n >> m >> c;
    vector<int> b;
    for (auto i = 0; i < m; i++)
    {
        int b_i;
        cin >> b_i;
        b.push_back(b_i);
    }

    int ans = 0;

    for (auto i = 0; i < n; i++)
    {
        vector<int> a;
        for (auto i = 0; i < m; i++)
        {
            int a_i;
            cin >> a_i;
            a.push_back(a_i);
        }

        if(product(a,b,c) > 0){
            ans += 1;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int n,cnt;
char a[110],b[110],c[110];
int main()
{
    scanf("%d",&n);
    scanf("%s %s %s",&a,&b,&c);
    for(int i=0;i<n;i++)
    {
        if(a[i]==b[i]&&b[i]==c[i])
        {

        }
        else if(a[i]==b[i]||b[i]==c[i]||c[i]==a[i])
        {
            cnt++;
        }
        else
            cnt+=2;
    }
    printf("%d",cnt);
}

Measured memory_bytes: 128
def make_divisors(n):
    divisors = []
    for i in range(1,int(n**0.5)+1):
        if n % i == 0:
            x = i
            if i != n // i:
                y = n // i
            else:
                y = i
            divisors.append([x,y])
    return divisors


n = int(input())
lst = make_divisors(n)
ans = 10**9
for l in lst:
    a = len(str(l[0]))
    b = len(str(l[1]))
    ans = min(ans,max(a,b))
print(ans)

Measured memory_bytes: 3188
in1 = input('')
n = int(in1.split(' ')[0])
m = int(in1.split(' ')[1])
l = []
for i in range(0,n):
  l.append(-1)

hasError = False
for i in range(0,m):
  in2 = input('')
  idx = int(in2.split(' ')[0])-1
  li = int(in2.split(' ')[1])
  if l[idx] != -1 and l[idx] != li:
    hasError = True
  else:
    l[idx] = li

for i in range(0,n):
  if l[i] == -1:
    if i == 0 and n > 1:
      l[i] = 1
    else:
      l[i] = 0

result = 0
for i in range(0,n):
  ix = 1
  for j in range(0,(n-i-1)):
    ix*=10
  result += int(l[i])*ix

if result < 0:
  result = -1
if n == 1 and result == 0:
  result = 0
elif len(str(result)) != n:
  result = -1
if hasError == True:
  result = -1
print(result)



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

print(0, flush=True)
s = input()
if s == 'Vacant':
    exit()
head_v = s
head_i = 0
print(n-1, flush=True)
s = input()
if s == 'Vacant':
    exit()
tail_v = s
tail_i = n-1

while True:
    mi = (head_i + tail_i) // 2
    print(mi, flush=True)
    mv = input()

    if mv == 'Vacant':
        exit()
    if tail_v == mv and (tail_i - mi) % 2 == 1 or tail_v != mv and (tail_i - mi) % 2 == 0:
        head_i = mi
        head_v = mv
    else:
        tail_i = mi
        tail_v = mv


Measured memory_bytes: 9132
#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()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

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

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n;
pii poyo[252521];
int v[252521];
int l[252521], r[252521];

int dp[252521];

int main(){
  scanf("%d",&n);
  REP(i,n){
    int xx,vv;
    scanf("%d%d",&xx,&vv);
    poyo[i] = pii(xx,vv);
  }
  // zaatu
  sort(poyo,poyo+n);
  REP(i,n)poyo[i] = pii(poyo[i].second,i);
  sort(poyo,poyo+n);
  REP(i,n)v[poyo[i].second] = i+1;
  // left
  l[0] = v[0];
  FOR(i,1,n)l[i] = max(l[i-1],v[i]);
  // right
  r[n-1] = v[n-1];
  FORR(i,0,n-1)r[i] = min(r[i+1],v[i]);
  // dp[r[i]] += sum(dp[l[i]-1]~dp[r[i]])
  dp[0] = 1;
  int sum = 1;
  int lw = 0, hi = 0;
  REP(i,n){
    while(hi < l[i])(sum += dp[++hi])%=MOD;
    while(lw < r[i]-1)(sum += MOD-dp[lw++])%=MOD;
    (dp[l[i]] += sum)%=MOD;
    (sum += sum)%=MOD;
  }
  printf("%lld\n",dp[n]);
  return 0;
}


Measured memory_bytes: 5376
using System;
using System.Linq;

namespace AOJ
{
	class Program
	{
		public static void Main(string[] args)
		{
			var f = 0;
			var s = Console.ReadLine();
			var n = int.Parse(Console.ReadLine());
			foreach(var i in Enumerable.Range(1, n))
			{
				var str = Console.ReadLine();
				if((str + str).Contains(s))
				{
					f++;
				}
			}
			Console.WriteLine(f);
		}
	}
}

Measured memory_bytes: 6408
#include<stdio.h>
#include<map>
using namespace std;
typedef long long ll;
map<ll,int>p;
map<ll,int>::iterator it;
int fa[100010],siz[100010],a[100010],b[100010],h[100010],nex[200010],to[200010],M,n;
void add(int a,int b)
{
    M++;
    to[M]=b;
    nex[M]=h[a];
    h[a]=M;
}
ll wd[100010],d[100010];
void dfs(int x,int dis)
{
    siz[x]=1;
    d[1]+=dis;
    for(int i=h[x];i;i=nex[i])if(to[i]!=fa[x])
	{
        fa[to[i]]=x;
        dfs(to[i],dis+1);
        siz[x]+=siz[to[i]];
    }
}
void dfs(int x)
{
    for(int i=h[x];i;i=nex[i])if(to[i]!=fa[x])
	{
        d[to[i]]=d[x]+n-siz[to[i]]*2;
        dfs(to[i]);
    }
}
int get(int x){return fa[x]==x?x:(fa[x]=get(fa[x]));}
int main()
{
    int i;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
	{
        scanf("%lld",wd+i);
        p[wd[i]]=i;
    }
    for(i=1;i<=n;i++)
	{
        fa[i]=i;
        siz[i]=1;
    }
    it=p.end();
    for(it--;it!=p.begin();it--)
	{
        if(n-siz[it->second]*2==0||!p.count(it->first-(n-siz[it->second]*2)))
		{
            puts("-1");
            return 0;
        }
        M++;
        a[M]=it->second;
        b[M]=p[it->first-(n-siz[it->second]*2)];
        siz[fa[a[M]]=get(b[M])]+=siz[a[M]];
    }
    M=0;
    for(i=1;i<n;i++)
	{
        add(a[i],b[i]);
        add(b[i],a[i]);
    }
    fa[1]=0;
    dfs(1,0);
    dfs(1);
    for(i=1;i<=n;i++)
	{
        if(wd[i]!=d[i])
		{
            puts("-1");
            return 0;
        }
    }
    for(i=1;i<n;i++)printf("%d %d\n",a[i],b[i]);
}

Measured memory_bytes: 15744
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <string>
#include <sstream>
#include <cstring>
#include <cmath>

using namespace std;

#ifdef DEBUG
#define LOG(args) cout << args << "\n"
#define debug(x) x
#else
#define LOG(args)
#define debug(x)
#endif

#define vi vector<int>
#define ii pair<int, int>
#define vii vector< ii >
#define vvi vector< vi >
#define mp make_pair
#define pb push_back
#define ms(x, v) memset(x, v, sizeof(x))
#define all(x) x.begin(), x.end()
#define REP(x, n) for(int x = 0; x < n; x++)
#define REPV(x, v, n) for(int x = v; x < n; x++)
#define REVE(x, n) for(int x = n; x >= 0; x--)

typedef long long ll;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int x;
	cin >> x;
	if(x >= 30)
		cout << "Yes\n";
	else
		cout << "No\n";
	return 0;
}


Measured memory_bytes: 3132
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>

typedef long double ld;
typedef long long ll;

using namespace std;

int n;

#define MAXN (1 << 12)

int lleft[3];
int rright[3];
int a[MAXN];

map<char, int> codes;

int f(int l[3], int r[3]) {
	return (l[0] * r[1] + l[1] * r[0] + l[0] * r[2] + l[2] * r[0] + l[1] * r[2] + l[2] * r[1]);
}

int main() {
	cin >> n;
	string s;
	cin >> s;
	codes['R'] = 0;
	codes['G'] = 1;
	codes['B'] = 2;
	for (int i = 0; i < n; i++) {
		rright[codes[s[i]]]++;
	}
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		int cur = codes[s[i]];
		rright[cur]--;
		int l[3];
		int r[3];
		for (int j = 0; j < 3; j++) {
			l[j] = 0;
			r[j] = 0;
		}
		for (int j = 0; j < 3; j++) {
			if (j != cur) {
				l[j] += lleft[j];
				r[j] += rright[j];
			}
		}
		ans += f(l, r);
		int shift = 1;
		int cnt = 0;
		while (true) {
			int lpos = i - shift;
			int rpos = i + shift;
			if ((lpos < 0) || (rpos >= n)) {
				break;
			}
			if ((s[lpos] != s[i]) && (s[rpos] != s[i]) && (s[lpos] != s[rpos])) {
				cnt++;
			}
			shift++;
		}
		ans -= cnt;
		lleft[cur]++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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;
}

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1LL << 60;


const int MAX_N = 100010;
int cnt[100010];
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	VE a(n); rep(i, n)cin >> a[i];
	rep(i, n)cnt[a[i]]++;
	int ans = 0;
	rep(i, 100010) {
		if(i!=0)chmax(ans, cnt[i - 1] + cnt[i] + cnt[i + 1]);
		else chmax(ans, cnt[i] + cnt[i + 1]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
import java.lang.reflect.Array;
import java.util.*;
import java.io.*;
import java.lang.*;

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

        int[] arr = {a,b,c};
        Arrays.sort(arr);

        System.out.println((arr[2]*10)+arr[1]+arr[0]);
    }
}


Measured memory_bytes: 35700
N = int(input())
W = []

for i in range(N):
    W.append(input())

for i in range(1,N):

    for j in W[:i]:
        if j == W[i]:
            print('No')
            exit()


    if W[i-1][-1] != W[i][0]:
        print('No')
        exit()

print('Yes')


Measured memory_bytes: 2940
a=gets.to_i
b=gets.to_i
c=gets.to_i
x=gets.to_i

cnt=0

(0..a).each do |i|
    (0..b).each do |j|
        (0..c).each do |k|
    #500*i+100*j+50*k==x ? cnt+=1 : cnt
    cnt+=1 if 500*i+100*j+50*k==x
        end
    end
end
puts cnt

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

int main(){    
  string S,T;
  cin >> S >> T;
  ll N = S.size();
  ll a = 0;
  for(int i = 0; i < N; i++){
    if(S.at(i) == T.at(i)) a++;
  }
  if(a == N) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3624
n,w=gets.split.map(&:to_i)
items=n.times.map{gets.split.map(&:to_i)}
diff=3


offset=diff*n+1
w1=items[0][0]
if w1>offset
    w=offset*(w/w1)+[w%w1,offset-1].min
    w=[w,(n+1)*offset].min
    n.times{|i| items[i][0]=offset+items[i][0]%w1}
end

dp=Array.new(n+1){Array.new(w+1,0)}

items.each_with_index do |item,i|
    iw,iv=item
    (w+1).times do |j|
        dp[i+1][j]=dp[i][j] if dp[i][j]>dp[i+1][j]
        dp[i+1][j+iw]=dp[i][j]+iv if j+iw<=w && dp[i][j]+iv>dp[i+1][j+iw]
    end
end
puts dp[n].max

Measured memory_bytes: 25596
let solve s n =
  let rec doit n =
    if n = 0 then assert false
    else
      let m = n / 2 in
      let rec aux i =
        if i = m then true
        else s.[i] = s.[m+i] && aux (i + 1) in
      if aux 0 then n
      else doit (n - 2) in
  doit n

let () =
  let s = read_line () in
  let n = String.length s in
  solve s (if n mod 2 = 0 then n - 2 else n - 1) |> Printf.printf "%d\n"

Measured memory_bytes: 2432
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<iomanip>
#include<cstring>
#define initdp(a,b) for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)dp[i][j]=-1;
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define waste ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define inf 1e9+1
#define inf1 1e18+1
#define mod 1000000007
#define pie 3.14159265358979323846
#define N 1000005
#define mid(l,r) l+(r-l)/2
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
void mad(ll &a,ll b){a=(a+b)%mod;if(a<0)a+=mod;}
ll gcd(ll a,ll b){ if(a>b)swap(a,b);if(!a)return b;return gcd(b%a,a);}

void solve(){
	int n;
	cin>>n;
	int a[n],b[n];
	rep(i,n){cin>>a[i];b[i]=a[i];}
	sort(a,a+n,greater<int>());
	rep(i,n){
		if(b[i]==a[0]){
			cout<<a[1]<<"\n";
		}
		else{
			cout<<a[0]<<"\n";
		}
	}
}
int main()
{
	waste;
	int t;
	//cin>>t;
	t=1;
	while(t--){
		solve();
	}
}

Measured memory_bytes: 3200