akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cmath>

using namespace std;

double round(double source, int precision) {	// 四捨五入
	return floor((fabs(source) * pow(10, (double)precision) + 0.5)) / pow(10, (double)precision) * (source < 0 ? -1 : 1);
}

int main() {
	double a, b, c, d, e, f, x, y;

	while (cin >> a >> b >> c >> d >> e >> f) {
		x = (c * e - b * f) / (a * e - b * d);
		y = (a * f - c * d) / (a * e - b * d);

		cout.precision(3);
		cout << fixed << round(x, 3) << " " << round(y, 3) << endl;
		//cout << fixed << x + 1e-10 << " " << y + 1e-10 << endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

int a[50],b[50];
vector<pint> pi;
int main(){
    int n;
    cin>>n;
    rep(i,n) cin>>a[i];
    int mx=max_element(a,a+n)-a;
    int mn=min_element(a,a+n)-a;
    bool flag=true;
    if(abs(a[mx])<abs(a[mn])) flag=false;
    if(flag){
        rep(i,n)if(i!=mx){
            a[i]+=a[mx];
            pi.pb(mp(mx+1,i+1));
        }
        rep(i,n-1) pi.pb(mp(i+1,i+2));
    } 
    else{
        rep(i,n)if(i!=mn){
            a[i]+=a[mn];
            pi.pb(mp(mn+1,i+1));
        }
        for(int i=n-1;i>=1;--i) pi.pb(mp(i+1,i));
    }
    cout<<pi.size()<<endl;
    rep(i,pi.size()) cout<<pi[i].first<<" "<<pi[i].second<<endl;
    return 0;
}

Measured memory_bytes: 256
#ifndef LOCAL
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

typedef long long ll;
typedef long long llong;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;

/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

const int MAXN = 210000;

int x[MAXN];
int was[MAXN];

int n, m;

vector<pair<int, int> > eds[MAXN];

void dfs1(int v, int xx) {
	x[v] = xx;
	was[v] = 1;
	for (auto e: eds[v]) {
		int u = e.first;
		if (was[u]) {
			if (x[u] != xx + e.second) {
				cout << "No\n";
				exit(0);
			}
		}
		else {
			dfs1(u, xx + e.second);
		}
	}
}

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; ++i) {
		int l, r, d;
		scanf("%d%d%d", &l, &r, &d);
		--l, --r;
		eds[l].push_back(make_pair(r, d));
		eds[r].push_back(make_pair(l, -d));
	}
	for (int i = 0; i < n; ++i) {
		if (!was[i])
			dfs1(i, 0);
	}
	cout << "Yes\n";
	return 0;
}




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

int main() {
    int a,b,c,x,ans=0;
    cin>>a>>b>>c>>x;
    for (int i=0; i<=a; i++) {
        for (int j=0; j<=b; j++) {
            for (int k=0; k<=c; k++) {
                if (500*i+100*j+50*k==x) {
                    ans++;
                }
            }
        }
    }
    cout<<ans<<endl;
} 


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")

using namespace std;

#define fi first
#define se second
using ll = long long;

const int INF = (int) 1e9 + 9;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    string s;
    cin >> n >> s;
    int ans = 1;
    for (int i = 1; i < n; ++i) {
        if (s[i] != s[i-1]) ++ans;
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
  string s,t;
  cin>>s>>t;
  sort(s.begin(),s.end());
  sort(t.begin(),t.end(),greater<char>());
  if(s>=t){
    cout<<"No"<<endl;
  }
  else{
    cout<<"Yes"<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

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


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

    vector<ll> a(n);
    REP(i, n){
        cin >> a[i];
        a[i] -= i + 1;
    }

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

    ll t = ((n & 1)? a[n / 2] : (a[n / 2] + a[(n - 1) / 2]) / 2), sum = 0;
    REP(i, n){
        sum += abs(a[i] - t);
    }

    cout << sum << '\n';
}

Measured memory_bytes: 1792
# include <iostream>
# include <cmath>
# include <algorithm>
# include <stdio.h>
# include <cstdint>
# include <cstring>
# include <string>
# include <cstdlib>
# include <vector>
# include <bitset>
# include <map>
# include <queue>
# include <ctime>
# include <stack>
# include <set>
# include <list>
# include <random>
# include <deque>
# include <functional>
# include <iomanip>
# include <sstream>
# include <fstream>
# include <complex>
# include <numeric>
# include <immintrin.h>
# include <cassert>
# include <array>
# include <tuple>
# include <unordered_set>
# include <unordered_map>
using namespace std;


int n;
long long a[100005];
vector<pair<long long, long long> > ans;

int main(int argc, const char * argv[]) {
#ifdef __APPLE__
    freopen("/Users/danya.smelskiy/Documents/Danya/Resources/input.txt","r",stdin);
    //freopen("/Users/danya.smelskiy/Documents/Danya/Danya/output.out", "w", stdout);
#endif
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; ++i)
        cin >> a[i];
    sort(a + 1, a + n + 1);
    reverse(a + 1, a + n + 1);
    vector<long long> v1, v2;
    for (int i = 1; i <= n; ++i) {
        if (a[i] >= 0) v1.push_back(a[i]);
        else v2.push_back(a[i]);
    }
    if (n == 2) {
        cout << max(a[1] - a[2], a[2] - a[1]) << '\n';
        if (a[1] - a[2] > a[2] - a[1]) cout << a[1] << " " << a[2] << '\n';
        else cout << a[2] << " " << a[1] << '\n';
        return 0;
    }
    if (v2.empty()) {
        long long x = v1.back();
        v1.pop_back();
        ans.push_back({x, v1.back()});
        x -= v1.back();
        v1.pop_back();
        v2.push_back(x);
    } else if (v1.empty()) {
        reverse(v2.begin(), v2.end());
        long long x = v2.back();
        v2.pop_back();
        long long y = v2.back();
        v2.pop_back();
        ans.push_back({x, y});
        v1.push_back(x - y);
    }
    if (!v1.empty() && !v2.empty()) {
        while (!v1.empty() && !v2.empty()) {
            if ((int)v2.size() > 1) {
                long long x = v1.back() - v2.back();
                ans.push_back({v1.back(), v2.back()});
                v2.pop_back();
                v1[(int)v1.size() - 1] = x;
                continue;
            } else if ((int)v1.size() > 1) {
                long long x = v2.back() - v1.back();
                ans.push_back({v2.back(), v1.back()});
                v1.pop_back();
                v2[(int)v2.size() - 1] = x;
                continue;
            }
            ans.push_back({v1.back(), v2.back()});
            v1[0] -= v2[0];
            v2.clear();
        }
        cout << v1[0] << '\n';
        for (int i = 0; i < (int)ans.size(); ++i)
            cout << ans[i].first << " " << ans[i].second << '\n';
        return 0;
    }
    return 0;
}



Measured memory_bytes: 5872
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
int N;
int A[105000];
int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    int ans = 1;
    for(int i = 1; i <= N; i++) {
        cin >> A[i];
        if(A[i] <= A[i-1]) ans++;
    }
    cout << ans << endl << N << endl;
    return 0;
}



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

count = 0
count2 = 0

for i in range(n):
    d1, d2 = map(int, input().split())
    if d1 == d2:
        count += 1
    else:
        count = 0
    if count >= 3:
        count2 +=1
        break

if count2 >= 1:
    print('Yes')
else:
    print('No')

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

typedef long long int ll;
typedef vector<int> vi;            
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef pair<int, int>     pii;
typedef vector<bool> vb;
#define endl '\n'
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size()
#define MOD 1000000007
#define F first
#define S second
#define pb push_back
#define pf push_front
#define rb pop_back
#define rf pop_front
#define in insert
#define mp make_pair
#ifdef LOCAL
    #include "../../trace.h"
#else
    #define trace(args...)
#endif

ll div_floor(const ll &a,const ll &b) { return a / b - (((a ^ b) < 0) and a % b);}
ll div_ceil(const ll &a,const ll &b) { return a / b + (((a ^ b) >= 0) and a % b);}

void solve(){
    ll n, x, t;
    cin>>n>>x>>t;
    cout<<div_ceil(n, x)*t<<endl;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifdef LOCAL
        freopen(".inp.txt", "r", stdin);
        freopen(".out.txt", "w", stdout);
        freopen(".err.txt", "w", stderr);
    #endif
    int t=1;
    while(t--)
        solve();
}

Measured memory_bytes: 3648
import java.util.Scanner;

public class Main{

	public static void main(String args[]){

		Scanner sc = new Scanner(System.in);

		int n=sc.nextInt();
		int k=0;
		while(k*(k-1)/2 <n)++k;

		if(k*(k-1)/2 !=n){
			System.out.println("No");
		}
		else{
			System.out.println("Yes");
			System.out.println(k);
			int matrix[][]=new int[k][k];
			int i=1;
			for(int a=0;a<k;++a){
				for(int b=0;b<k;++b){
					if(a>b)matrix[a][b]=matrix[b][a];
					else if(a==b);
					else {matrix[a][b]=i; ++i;}
				}
				System.out.print((k-1)+" ");
				for(int b=0;b<k;++b){
					if(a!=b){
						System.out.print(matrix[a][b]);
						if(b!=k-1)System.out.print(" ");
						else System.out.println();
					}
				}
			}



		}
	}
}

Measured memory_bytes: 47140
while True:
  N,A,B,C,X = map(int,raw_input().split())
  if N == A == B == C == X == 0:break
  sum = 0
  Z = 0
  Y = [int(x) for x in raw_input().split()]
  if X == Y[0]:
      Y.pop(0)
      if len(Y) == 0:
          Z = 1
  while Z == 0:
      if sum == 10000:
          sum = -2
          Z = 1
      sum += 1
      X = (A*X+B)%C
      if X == Y[0]:
          Y.pop(0)
          if len(Y) == 0:
              Z = 1
  print sum

Measured memory_bytes: 6384
#include <vector>
#include <iostream>
using namespace std;
vector<vector<int> > f = {
	{ -1, 2, 4, 1, 3, -1 },
	{ 3, -1, 0, 5, -1, 2 },
	{ 1, 5, -1, -1, 0, 4 },
	{ 4, 0, -1, -1, 5, 1 },
	{ 2, -1, 5, 0, -1, 3 },
	{ -1, 3, 1, 4, 2, -1 }
};
int n, a, b, c;
int main() {
	while (cin >> n, n) {
		vector<vector<int> > h(20, vector<int>(20, 0));
		vector<vector<int> > t(20, vector<int>(20, -1));
		for (int i = 0; i < n; i++) {
			cin >> a >> b; a--, b--; c = f[a][b];
			int x = 10, y = 10;
			while (true) {
				int z = -1, r = 2;
				if (b > r && h[x + 1][y] < h[x][y]) z = 0, r = b;
				if (c > r && h[x][y + 1] < h[x][y]) z = 1, r = c;
				if (5 - b > r && h[x - 1][y] < h[x][y]) z = 2, r = 5 - b;
				if (5 - c > r && h[x][y - 1] < h[x][y]) z = 3, r = 5 - c;
				if (z == -1) break;
				if (z == 0) {
					int t = b; b = a; a = 5 - t;
					x++;
				}
				if (z == 1) {
					int t = c; c = a; a = 5 - t;
					y++;
				}
				if (z == 2) {
					int t = a; a = b; b = 5 - t;
					x--;
				}
				if (z == 3) {
					int t = a; a = c; c = 5 - t;
					y--;
				}
			}
			h[x][y]++;
			t[x][y] = a;
		}
		vector<int> cnt(6);
		for (int i = 0; i < 20; i++) {
			for (int j = 0; j < 20; j++) {
				if (t[i][j] != -1) cnt[t[i][j]]++;
			}
		}
		for (int i = 0; i < 6; i++) {
			if (i) cout << ' ';
			cout << cnt[i];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x1,x2,y1,y2;
  cin>>x1>>y1>>x2>>y2;
  cout<<x2+(y1-y2)<<" "<<y2+(x2-x1)<<" "<<x1+(y1-y2)<<" "<<y1+(x2-x1)<<endl;
}

Measured memory_bytes: 256
#pragma comment(linker, "/STACK:102400000,102400000")
#include <iostream>
#include <string>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <ctime>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>
#include <cmath>
#include <assert.h>
#include <iomanip>
#include <bitset>
using namespace std;
#define vi vector<int>
#define pii pair<int,int>
#define x first
#define y second
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define SZ(x) (int)x.size()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)
#define pi acos(-1)
#define mod 998244353//1000000007
#define inf 1000000007
#define ll long long
#define ull unsigned long long
#define DBG(x) cerr<<(#x)<<"="<<x<<"\n";
#define N 200005
#define _DEBUG
template <class U,class T> void Max(U &x, T y){if(x<y)x=y;}
template <class U,class T> void Min(U &x, T y){if(x>y)x=y;}
template <class T> void add(int &a,T b){a=(a+b)%mod;}
inline int gcd(int a,int b){return b==0?a:gcd(b,a%b);}
inline ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}

int pow(int a,int b){
    int ans=1;
    while(b){
        if(b&1)ans=1LL*ans*a%mod;
        a=1LL*a*a%mod;b>>=1;
    }
    return ans;
}
int pow(int a,int b,int c){
    int ans=1;
    while(b){
        if(b&1)ans=1LL*ans*a%c;
        a=1LL*a*a%c;b>>=1;
    }
    return ans;
}

int a[303], dp[45005], f[45005];
int main(){
    //srand(time(NULL)+clock());
    int T,ca=0,k,i,j,m=0,K,n;
    scanf("%d",&n);
    int s=0;
    rep(i,0,n)scanf("%d", &a[i]), s+=a[i];
    s/=2;
    ll tot=pow(3, n)-3LL*pow(2, n)+3;
    tot%=mod;
    //DBG(tot)
    int w=0;
    dp[0]=1;
    f[0]=1;
    rep(i, 0, n){
        int r=min(s, w);
        per(j,0,r+1){
            if(j+a[i]<=s)add(dp[j+a[i]], 2LL*dp[j]%mod), add(f[j+a[i]], f[j]);
        } 
        w+=a[i];
    }
    rep(i,1,s+1){
        //cerr<<dp[i]<<" "<<f[i]<<"\n"; 
        tot-=(dp[i]-f[i]*2LL)*3%mod;
    }
    tot%=mod;
    if(tot<0)tot+=mod;
    printf("%lld\n", tot);
    //cerr<<(1.*clock()-start)/CLOCKS_PER_SEC<<"\n";
}




Measured memory_bytes: 640
#include<stdio.h>
int main(void)
{
	long N, M;
	long pair=0;
	scanf("%ld %ld",&N, &M);

	if (2 * N >= M) {
		pair = M / 2;
	}
	else {
		pair = N + (M - (2 * N)) / 4;
	}

	printf("%ld\n",pair);
	return 0;
}

Measured memory_bytes: 128
package main

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

var sc = bufio.NewScanner(os.Stdin)

func recvInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func recvStr() string {
	sc.Scan()
	return sc.Text()
}

func max(a []int) (max int) {
	max = a[0]
	for _, i := range a {
		if i > max {
			max = i
		}
	}
	return
}

func main() {
	n := recvInt()
	a := make(map[string]int, n)

	for i := 0; i < n; i++ {
		a[recvStr()]++
	}

	m := recvInt()
	for i := 0; i < m; i++ {
		a[recvStr()]--
	}

	values := make([]int, 0, len(a))
	for _, k := range a {
		values = append(values, k)
	}

	if x := max(values); x >= 0 {
		fmt.Println(x)
	} else {
		fmt.Println(0)
	}
}


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

bool vis[101][100001];
static long long  dp[101][100001];


long long Dp(int N, int W, int w[],long long v[] ){
    if(N == 0 || W <= 0){
        return 0;
    }if(vis[N][W]){
        
        return dp[N][W];
    }else{
        long long x = Dp(N-1,W,w,v);
        if(w[N] > W){
            vis[N][W] = true;
            dp[N][W] = x;
            return dp[N][W];
        }else{
            long long y = Dp(N-1,W-w[N],w,v);
            vis[N][W] = true;
            dp[N][W] = max(x,y+v[N]);
            return dp[N][W];
        }
    }

}

void init(){
    for(int i = 0 ; i <= 100 ; i++){
        for(int j = 0 ; j <= 100001 ; j++){
            if(i != 0){
                vis[i][j] = false;
            }else{
                vis[i][j] = true;
            }
        }
    }
}

int main(){
    int N,W;
    cin >> N >> W;
    init();

    

    int w[N+1];
    long long  v[N+1];

    for(int i = 1; i  <= N ;i ++){
        cin >> w[i] >> v[i];
    }

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

    long long ans = Dp(N,W,w,v);

    
    cout  << ans ;
}

Measured memory_bytes: 84840
d, goal = map(int, input().split())

problems = []
for i in range(1, d+1):
    num, bonus = map(int, input().split())
    point = i * 100
    problems.append([point, num, bonus])


ans = []
for mask in range(2**d):
    score = 0
    count = 0
    target = 0
    for bit in range(d):
        if (mask >> bit) & 1:  #全て解く
            point, num, bonus = problems[bit]
            score += (point*num) + bonus
            count += num
        else:
            target = bit

    if score >= goal:
        ans.append(count)
    else:
        point, num, bonus = problems[target]
        delta = goal - score
        add = delta//point + bool(delta%point)
        if add < num:
            ans.append(count+add)
        else:
            continue

print(min(ans))

Measured memory_bytes: 3064
import sys
n, m, *x = map(int, open(0).read().split())

if m <= n:
    print(0)
    sys.exit()

x.sort()

dis = [0] * (m - 1)

for i in range(m - 1):
    dis[i] = x[i + 1] - x[i]

dis.sort()

cnt = 0
for i in range(m - n):
    cnt += dis[i]
    
print(cnt)

Measured memory_bytes: 13964
IDENTIFICATION DIVISION.
      PROGRAM-ID. 064A.
      DATA DIVISION.
      WORKING-STORAGE SECTION.
      01 INP PIC X(10).
      01 INP2.
       03 R PIC 9(1).
       03 G PIC 9(1).
       03 B PIC 9(1).
      01 SHO PIC 9(3).
      01 AMA PIC 9(1).
      
      PROCEDURE DIVISION.
      ACCEPT INP.
      UNSTRING INP DELIMITED BY " "
      INTO R G B.
      
      DIVIDE INP2 BY 4 GIVING SHO REMAINDER AMA.
      IF AMA = 0
        DISPLAY "YES"
      ELSE
        DISPLAY "NO"
      END-IF.
	  STOP RUN.      
      


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); i++)
#define all(vec) vec.begin(), vec.end()
#define MOD 1000000007
#define intt int64_t

int main() {
    string s;
    cin >> s;
    bool ans=true;
    rep(i,s.size()) {
        if(i%2==0) {
            if(s.at(i)=='L') ans=false;
        } else {
            if(s.at(i)=='R') ans=false;
        }
    }
    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>  
#include <cstdio>  
#include <queue>  
#include <vector>  
#include <algorithm>  
using namespace std;  
typedef long long LL;  
typedef pair<int, int> ii;  
const int MAXN = 1e5 + 8;  
   
   
priority_queue<ii, vector<ii>, greater<ii>> pq[MAXN];  
int val[MAXN];  
int fa[MAXN], _rank[MAXN];  
inline void init(int n){  
    for(int i = 0; i <= n; i++){  
        fa[i] = i;  
        _rank[i] = 0;  
    }  
}  
inline int _find(int u){  
    return fa[u] = fa[u] == u ? u : _find(fa[u]);  
}  
inline void _merge(int u, int v){  
    int x = _find(u), y = _find(v);  
    if(x == y) return;  
    if(_rank[x] < _rank[y]){  
        fa[x] = y;  
    }  
    else{  
        fa[y] = x;  
        if(_rank[x] == _rank[y]) _rank[x]++;  
    }  
}  
   
vector<ii> vec;  
int main()  
{  
    #ifdef LOCAL  
    freopen("d.txt", "r", stdin);  
    //freopen("d.out", "w", stdout);  
    int T = 1;  
    while(T--){  
    #endif // LOCAL  
    ios::sync_with_stdio(false); cin.tie(0);  
   
    int n, m, i, u, v, findu, findv;  
    LL ans = 0;  
    cin >> n >> m;  
    init(n);  
    for(i = 0; i < n; i++){  
        cin >> val[i];  
    }  
    for(i = 0; i < m; i++){  
        cin >> u >> v;  
        findu = _find(u), findv = _find(v);  
        if(findu != findv){  
            _merge(findu, findv);  
        }  
    }  
    for(i = 0; i < n; i++){  
        pq[_find(i)].push(ii(val[i], i));  
    }  
    for(i = 0; i < n; i++){  
        if(!pq[i].empty()){  
            vec.push_back(pq[i].top());  
            val[pq[i].top().second] = 2e9;  
            ans += pq[i].top().first;  
        }  
    }  
    //cout << vec.size() << endl;  
    if(vec.size() == 1){  
        cout << 0 << endl;  
    }  
    else if(n < (vec.size()-1) * 2) cout << "Impossible" << endl;  
    else{  
        sort(val, val + n);  
        n = (vec.size()-1) * 2 - vec.size();  
   
        for(i = 0; i < n; i++){  
            ans += val[i];  
        }  
        cout << ans << endl;  
    }  
   
   
   
    #ifdef LOCAL  
    cout << endl;  
    }  
    #endif // LOCAL  
    return 0;  
}  

Measured memory_bytes: 8828
//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error('\n↑入力 ↓出力');
  Main();
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  return {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}}
  };
}
function myout(s){console.log(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
  var one = nextIntArray();
  var N = one[0];
  var u = one[1] - 1;
  var v = one[2] - 1;
  var list = new Array(N);
  for(var i = 0; i < N; i++){
    list[i] = {
      child : [],
      acount : 0,
      aaccess : false,
      tcount : 0,
      taccess : false
    };
  }
  for(var i = 0; i < N - 1; i++){
    var tmp = nextIntArray();
    list[tmp[0] - 1].child.push(tmp[1] - 1);
    list[tmp[1] - 1].child.push(tmp[0] - 1);
  }
  bfs(u, true);
  bfs(v, false);
  var max = 0;
  for(var i = 0; i < N; i++){
    if(list[i].tcount < list[i].acount){
      max = Math.max(max, list[i].acount - 1);
    }
  }
  myout(max);
  function bfs(s, isT){
    var queue = [s];
    if(isT){
      list[s].taccess = true;
    }else{
      list[s].aaccess = true;
    }
    while(queue.length > 0){
      var now = queue.shift();
      var child = list[now].child;
      for(var i = 0; i < child.length; i++){
        if(isT){
          if(!list[child[i]].taccess){
            list[child[i]].taccess = true;
            list[child[i]].tcount = list[now].tcount + 1;
            queue.push(child[i]);
          }
        }else{
          if(!list[child[i]].aaccess){
            list[child[i]].aaccess = true;
            list[child[i]].acount = list[now].acount + 1;
            queue.push(child[i]);
          }
        }
      }
    }
  }
}





Measured memory_bytes: 103032
//                                   mdsaqib
#include <bits/stdc++.h>
#define int long long
#define all(c) (c).begin(),(c).end()
#define endl '\n'
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
using namespace std;

signed main(){
    fast;
    int n;
    cin >> n;
    vector <int > H(n,0);
    for(int i=0;i<n;i++){
        cin >> H[i];
    }
    if(n==2){
        cout << abs(H[0]-H[1]);
        return 0;
    }
    if(n==3){
        cout << min(abs(H[0]-H[2]),abs(H[0]-H[1])+abs(H[1]-H[2]));
        return 0;
    }
    vector <int > A(n,0);
    A[1]=abs(H[0]-H[1]);
    A[2]=min(abs(H[0]-H[2]),abs(H[0]-H[1])+abs(H[1]-H[2]));
    for(int i=3;i<n;i++){
        int p=A[i-1]+abs(H[i-1]-H[i]);
        int q=A[i-2]+abs(H[i-2]-H[i]);
        A[i]=min(p,q);
    }
    cout << A[n-1];
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define ll          long long
#define vl          vector<ll>
#define vi          vector<int>
#define pi          pair<int,int>
#define pl          pair<ll,ll>
#define all(a)      a.begin(),a.end()
#define mem(a,x)    memset(a,x,sizeof(a))
#define pb          push_back
#define mp          make_pair
#define F           first
#define S           second
#define trace(x)     cerr<<#x<<":"<<x<<endl;
#define trace2(x,y) cerr<<#x<<":"<<x<<"|"<<#y<<":"<<y<<endl;
#define trace3(x,y,z) cerr<<#x<<":"<<x<<"|"<<#y<<":"<<y<<"|"<<#z<<":"<<z<<endl;
#define fast_io     std::ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)

int main(){
	fast_io;
	int s, w;
	cin>>s>>w;
	if(w>=s)cout<<"unsafe";
	else cout<<"safe";

	
	// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <numeric>
#include <queue>
#include <numeric>
#include <iomanip>
#include <sstream>

#define rep(i,a,b) for((i)=a;i<(int)(b);i++)
#define max(a,b) (a < b ? b : a)
#define min(a,b) (a > b ? b : a)

using namespace std;


int main() {
	long double a, b, x;
	const long double pi = 3.14159265358979323846264338327950288419716939937510;
	long double w, l, theta;
	cin >> a >> b >> x;
	long double p = a * a * b - x;
	long double the = atanl(p * 2 / a / a / a);
	theta = atanl(p * 2 / a / a / a) * 180 / pi;
	if (a * a * b / 2 > x) {
		the = atanl(a * b * b / 2 / x);
		theta = atanl(a * b * b / 2 / x)*180/pi;
	}
	printf("%.10Lf", theta);
//	cout <<endl << a * a * b - a * a * a / 2 * tan(the) << endl;
	//cout << a*b*b/2 / tan(the);
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#define INF (0x3f3f3f3f)
using namespace std;

const int N = 200005;

inline void read( int &res )
{
	static char ch = getchar(); res = 0;
	while(ch < '0' || ch > '9') ch = getchar();
	while(ch >= '0' && ch <= '9') res = res * 10 + ch - 48, ch = getchar();
}

int n, m, dis[N], que[N << 1], head[N], top = 0;

struct Node
{
	int y, nxt;
} e[N << 1];

inline void Adde( int x, int y )
{
	e[++top].y = y, e[top].nxt = head[x], head[x] = top;
	e[++top].y = x, e[top].nxt = head[y], head[y] = top;
}

int BFS()
{
	memset(dis, INF, sizeof(dis));
	int h, t, u, v;
	h = t = 0;
	dis[1] = 0;
	que[++t] = 1;
	while(h < t)
	{
		u = que[++h];
		for(int i = head[u]; i; i = e[i].nxt)
		{
			v = e[i].y;
			if(dis[v] != INF) continue;
			dis[v] = dis[u] + 1;
			que[++t] = v;
		}
	}
	return dis[n];
}

int main()
{
	int u, v;
	read(n), read(m);
	for(int i = 1; i <= m; i++)
		read(u), read(v), Adde(u, v);
	if(BFS() > 2) printf( "IMPOSSIBLE\n" );
	else printf( "POSSIBLE\n" );
	return 0;
}

Measured memory_bytes: 6528
n=int(input())
a=list(map(int,input().split()))
b=1
flag=-1
for i in range(n):
    b*=a[i]
    if(flag==-1):
        flag=1
        if(0 in a):
            flag=2
            break
    if(b>10**18):
        flag=0
        break
if(flag==0):
    print(-1)
if(flag==1):
    print(b)
if(flag==2):
    print(0)

Measured memory_bytes: 21700
from sys import stdin
data = stdin.readlines()

n = int(data[0].split()[0])
a = [int(s) for s in data[1].split()]

counter = 0
for i in range(0,n):
    if i % 2 == 0 and a[i] % 2 == 1:
        counter += 1
print(counter)

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

int main(){
    int a,b,c,num=0;
    cin >> a >> b >> c;
    if(a == b && a == c){
        num = 1;
    }else if(a == b || b == c || a == c){
        num = 2;
    }else{
        num = 3;
    }
    cout << num << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<vector>
#include<iostream>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<iomanip>
#include<assert.h>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<stack>
#include<complex>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;
	
#define WHATS(var)cout<<__LINE__<<' '<<#var<<"="<<var<<endl;
	
template<class S, class T> ostream& operator <<(ostream &os, const pair<S, T> v){
	os << "( " << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator <<(ostream &os, const vector<T> &v){
	for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator <<(ostream &os, const vector<vector<T>> &v){
	for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
template<class T> ostream& operator <<(ostream &os, const vector<set<T>> &v){
	for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
template<class T> ostream& operator <<(ostream &os, const set<T> &v){
	int i=0;
	for(auto it:v){
		if(i > 0){os << ' ';}
		os << it;
		i++;
	} 
	return os;
}

using ll =long long ;
ll mod;

void solve(vector<vector<int>>&cango){
	int tt=cango.size();
	for(int i=0;i<tt;++i){
		for(int j=0;j<tt;++j){
			for(int k=0;k<tt;++k){
				cango[j][k]|=cango[j][i]&cango[i][k];
			}
		}
	}
}
vector<int> dfs(int now,int N,vector<pair<int,int>>&edges){
	vector<int>av{now};
	if(now*2+1<N){
		auto v=dfs(now*2+1,N,edges);
		av.insert(av.end(),v.begin(),v.end());
	}
	if(now*2+2<N){
		auto v=dfs(now*2+2,N,edges);
		for(auto e:v){
			edges.push_back(make_pair(now,e));
		}
		av.insert(av.end(),v.begin(),v.end());
	}
	return av;
}

int ask(int x){
	cout<<x+1<<endl;
	fflush(stdout);
	string st;cin>>st;
	if(st=="Yes")return -1;
	else if(st=="No")return 0;
	else return 1;
}
int main() {
	ios::sync_with_stdio(false);
	int N;cin>>N;
	vector<int>v(N);
	for(int i=0;i<N;++i)cin>>v[i];
	reverse(v.begin(),v.end());
	for(int i=0;i<v.size();++i){
		v[i]=1e5-v[i];
	}
	vector<pair<int,ll>>vs(N+1,make_pair(1e9,0));
	for(int i=0;i<N;++i){
		auto it=lower_bound(vs.begin(),vs.end(),make_pair(v[i],ll(-1)));
		if(it==vs.begin()){
			vs[0]=make_pair(v[i],v[i]);
		}else{
			auto p=*prev(it);
			vs[it-vs.begin()]=make_pair(v[i],p.second+v[i]);
		}
	}
	for(int i=N;i>=0;--i){
		if(vs[i].first!=1e9){
			cout<<ll(100000)*(i+1)-vs[i].second<<endl;
			break;
		}
	}
	
	return 0;	
}


Measured memory_bytes: 4684
const f:array[1..11,1..5] of byte=((4,2,0,9,7),(1,10,8,6,4),(9,7,5,3,1),(6,4,2,0,9),(3,1,10,8,6),(0,9,7,5,3),(8,6,4,2,0),(5,3,1,10,8),(2,0,9,7,5),(10,8,6,4,2),(7,5,3,1,10));
var n,k,ans,p,i,j:longint;
begin
  readln(n,k);
  p:=(n-2) mod 11;
  n:=(n-2) div 11;
  ans:=n*5;
   if n<=2 then
     for i:=1 to p do
       for j:=1 to 5 do
         if f[i,j]=k then
           inc(ans)
         else
   else
     for i:=1 to p do
       for j:=1 to 5 do
         if f[i,j]=k then
           inc(ans);
  writeln(ans);
end.

Measured memory_bytes: 128
#include <stdio.h>

int main(){
 int A,B;
  scanf("%d%d",&A,&B);
  int i,ret=0;
  for(i=0;i<2;i++){
    if(A>=B){
      ret +=A;
      A--;
    }
    else{
     ret += B;
      B--;
    }
  }
  printf("%d\n",ret);
  
  return 0;
}

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

int main(){
  int A, B;
  cin >> A >> B;
  int ans = 0;
  if((A+B)%2==0){
    ans = (A+B)/2;
  }else{
    cout << "IMPOSSIBLE" << endl;
    return 0;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
///I don't wanna read problem's statement anymore
    using namespace std;
    #include<bits/stdc++.h>
    #define ll long long
    #define read freopen("in.txt", "r", stdin)
    #define write freopen("out.txt", "w", stdout)
    #define sf scanf
    #define pb push_back
    #define pfr push_front
    #define reap(i,n) for(int i=0; i<n; i++)
    #define case_ printf("Case %d: ",i)
    #define check printf("working\n")
    #define pf printf
    #define ato(v) for(auto k:v)
    #define vi vector<int>
    #define vll vector<ll>
    #define vec_ch vector<char>
    #define list_i list<int>
    #define list_ll list<ll>
    #define list_ch list<ch>
    #define M 100005
    #define ios ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
///AtCoder- DP editorial contest, Problem C   [Bottum Up Aproach]

    ll d[M][3];
    ll a[M][3];
    int main(){
        ios
        //read;
        //write;
        int n;
        cin>>n;
        for(int i=0; i<n; i++)
            for(int j=0; j<3; j++)
                cin>>a[i][j];
        d[0][0]=a[0][0];
        d[0][1]=a[0][1];
        d[0][2]=a[0][2];
        for(int i=1; i<n; i++){
            for(int j=0; j<3; j++){
                d[i][j]= max(d[i-1][(j+1)%3]+a[i][j],d[i-1][(j+2)%3]+a[i][j]);
                //cout<<j<<" "<<a[i][j]<<" "<<d[i-1][(j+1)%3]<<endl;
                //cout<<j<<" "<<a[i][j]<<" "<<d[i-1][(j+2)%3]<<endl;
            }
           // cout<<endl;
        }
//        for(int i=0; i<n; i++){
//            for(int j=0; j<3; j++){
//                cout<<d[i][j]<<" ";
//            }
//            cout<<endl;
//        }

        ll mx= max(d[n-1][0],d[n-1][1]);
        cout<<max(mx,d[n-1][2])<<endl;
        return 0;
    }


Measured memory_bytes: 4992
if __name__ == '__main__':
	N = int(input())
	Als = [int(a) for a in input().split()]
	lst = []
	for i in range(N):
		lst.append([Als[i],i+1])

	lst.sort(reverse = True)

	DP = [[0] * (N+1) for _ in range(N+1)]

	ans = 0

	for i in range(1,N+1):
		a = lst[i-1][0]
		index = lst[i-1][1]
		vx = DP[i-1][0] + a * abs(index-i)
		vy = DP[0][i-1] + a * abs(index-(N-i+1))
		DP[i][0] = vx
		DP[0][i] = vy
		if ans < vx:
			ans = vx
		if ans < vy:
			ans = vy

	for i in range(1,N+1):
		for j in range(1,N+1):
			if i + j <= N:
				a = lst[i+j-1][0]
				index = lst[i+j-1][1]
				v = max(DP[i-1][j] + a * abs(index-i),DP[i][j-1] + a * abs(index-(N-j+1)))
				DP[i][j] = v
				if ans < v:
					ans = v
			else:
				break

	print(int(ans))

Measured memory_bytes: 100908
n=int(input())
s=[input() for i in range(n)]

dic={}
for i in s:
    if i[0]=='M' or i[0]=='A' or i[0]=='R' or i[0]=='C' or i[0]=='H':
        if i[0] in dic:
            dic[i[0]]+=1
        else:
            dic[i[0]]=1
if len(dic)<3:
    ans=0
else:
    if len(dic)==3:
        ans = 1
        for i in dic.values():
            ans *=i
    elif len(dic)==4:
        li4 = []
        for i in dic.values():
            li4.append(i)
        ans = li4[0]*li4[1]*li4[2]+li4[0]*li4[1]*li4[3]+li4[0]*li4[2]*li4[3]+li4[1]*li4[2]*li4[3]
    else:
        li5 = []
        for i in dic.values():
            li5.append(i)
        ans =li5[0]*li5[1]*li5[2]+li5[0]*li5[1]*li5[3]+li5[0]*li5[1]*li5[4]+li5[0]*li5[2]*li5[3]+li5[0]*li5[2]*li5[4]+li5[0]*li5[3]*li5[4]+li5[1]*li5[2]*li5[3]+li5[1]*li5[2]*li5[4]+li5[1]*li5[3]*li5[4]+li5[2]*li5[3]*li5[4]
print(ans)


Measured memory_bytes: 9796
a_start, a_end, b_start, b_end = gets.split.map(&:to_i)

a_range = (a_start..a_end).to_a
b_range = (b_start..b_end).to_a
if (a_range & b_range).size.positive?
  puts (a_range & b_range).size - 1
else
  puts 0
end


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


signed main(){
    int A,B,C;
    cin  >> A >> B >> C;
    if(A+B>=C){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> vec(n);
    rep(i,n){
        cin >> vec[i];
    }
    int num=0,index;
    rep(i,n){
        if(num<vec[i]){
            num=vec[i];
            index=i;
        }
    }
    sort(vec.begin(),vec.end());
    if(vec[n-1]==vec[n-2]){
        rep(i,n){
            cout << vec[n-1] << endl;
        }
        return 0;
    }else{
        rep(i,n){
            if(i!=index){
                cout << vec[n-1] << endl;
            }else{
                cout << vec[n-2] << endl;
            }
        }
        return 0;
    }
}

Measured memory_bytes: 2432
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;
// (]  >=
int main() {
    int64_t n;
    int64_t M = 1000000007;
    cin >> n;
    int64_t d = 1;
    int64_t c = 1;
    int64_t pow = 1;
    while (n) {
        if (n % 2) {
            d += c;
            c += pow;
        } else {
            c += d;
        }
        n /= 2;
        c += pow;
        pow *= 3;
        pow %= M;
        d %= M;
        c %= M;
    }
    cout << d;
    return 0;
}


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

using namespace std;

int main()
{
    string s;
    string t;
    
    cin >> s; cin >> t;
    
    sort(s.begin(),s.end());
    sort(t.begin(),t.end());
    reverse(t.begin(),t.end());
    
    if(s < t)
        cout << "Yes";
    else
        cout << "No";
    
}

Measured memory_bytes: 256
from collections import deque

s = deque(input())
q = int(input())

rev = False
for i in range(q):
    query = input().split()
    if query[0] == "1":
        rev ^= True
    else:
        if (query[1] == "1" and not rev) or (query[1] == "2" and rev):
            s.appendleft(query[2])
        else:
            s.append(query[2])

if rev:
    print("".join(list(s)[::-1]))
else:
    print("".join(list(s)))

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

int main() {
  int n,m;
  cin >> n >> m;
  
  if(n<=1){
    n=0;
  }
  else{
    n=n*(n-1)/2;
  }
  if(m<=1){
    m=0;
  }
  else{
    m=m*(m-1)/2;
  }
  
  cout << n+m << endl;
}


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

int main(){
    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;++i)cin>>a[i];
    sort(a,a+n);
    int sum=0;
    for(int i=0;i<k;++i)sum=sum+a[i];
    cout<<sum;
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <numeric>
#include <random>
#include <algorithm>
#include <functional>
#include <cassert>

using namespace std;
typedef long long ll;

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

const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int K,N;
  cin>>K>>N;
  vector<int>A(N);
  REP(i,N){
    cin>>A[i];
  }
  int ans=(K-A[N-1])+A[0];
  REP(i,N-1){
    chmax(ans,A[i+1]-A[i]);
  }
  cout<<K-ans<<endl;
}


Measured memory_bytes: 1024
N = int(input())
A1_list = list(map(int, input().split()))
A2_list = list(map(int, input().split()))
max1 = 0
for i in range(N):
    tmp = 0
    for j in range(N-i):
        tmp += A1_list[j]
    for _ in range(N-j):
        tmp += A2_list[j]
        j += 1
    if max1 < tmp:
        max1 = tmp
print(max1)

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

using namespace std;

int main()
{
    int n;
    cin>>n;
    vector<long long int> v(3*n);
    vector<long long int> high(3*n,0);
    vector<long long int> low(3*n,0);
    for(int i=0;i<=n-1;i++)
        {
            cin>>v[i];
            high[n-1]+=v[i];
        }
        multiset<long long int> s1(v.begin(),v.begin()+n);

    for(int i=n;i<=2*n-1;i++)
    {
        cin>>v[i];

        if(v[i]>*(s1.begin()))
        {
            high[i]=high[i-1]+v[i]-*(s1.begin());
            s1.insert(v[i]);
            s1.erase(s1.begin());
        }
        else
        {
            high[i]=high[i-1];
        }
    }
    for(int i=2*n;i<3*n;i++)
    {
        cin>>v[i];
        low[2*n]+=v[i];
    }

    multiset<long long int,greater<long long int> > s2(v.begin()+2*n,v.begin()+3*n);


    for(int i=2*n-1;i>=n;i--)
    {
        if(v[i]<*(s2.begin()))
        {
            low[i]=low[i+1]+v[i]-*(s2.begin());

            s2.insert(v[i]);
            s2.erase(s2.begin());

        }
        else
        {
            low[i]=low[i+1];
        }

    }
  long long int ans=high[n-1]-low[n];
        for(int i=n;i<=2*n-1;i++)
        {
           long long int req=high[i]-low[i+1];
            if(req>ans)
                ans=req;
        }
        cout<<ans;
    return 0;
}



Measured memory_bytes: 16640
// In the name of GOD
#include<bits/stdc++.h>
using namespace std;

#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";

#define     IOS         ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define 	setprecn(x) cout<<fixed<<setprecision(x);
#define 	ll          long long int
#define 	pb          push_back
#define 	pll         pair<ll,ll>
#define 	vll         vector<ll>
#define 	ff          first
#define 	ss          second
#define 	all(a)      (a).begin(),(a).end()
#define 	sz(x)       (ll)x.size()
#define 	mod         1000000007
#define 	inf         10000000000000007
#define 	rep(i,n)    for(ll i=0;i<n;i++)
#define 	repe(i,a,b) for(ll i=a;i<b;i++)
#define 	lbnd        lower_bound
#define 	ubnd        upper_bound
#define 	bs          binary_search

ll power(ll a,ll b,ll m=mod)
{
	if(b==0)
		return 1;
	if(b==1)
		return a;
	ll c=power(a,b/2,m);
	if(b%2==0)
		return((c%m)*(c%m))%m;
	return ((((c%m)*(c%m))%m)*(a%m))%m;
}

/********************************************************/
//	d.erase(unique(all(d)), d.end());



int main()
{
	IOS;
	ll n,k,m,i,j,c=0,cs=0,t;
	t=1;

	// cin>>t;
	string s;
	while(t--)
	{
		cin>>n;
		// n=s.length();
		vector<ll> a(n),p(n),q(n);
		rep(i,n)
		{
			a[i]=i+1;
			cin>>p[i];
		}
		rep(i,n)
		{
			cin>>q[i];
		}
		i=0;
		do
		{
			i++;
			if(a==p)
			{
				c=i;
			}
			if(a==q) cs=i;
			// debug3(a[0],a[1],a[2]);
		}while(next_permutation(all(a)));
		cout<<abs(c-cs);

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

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

template <class T>

bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }

    return false;
}

int main(void)
{
    string s, t;
    cin >> s >> t;

    vector<vector<long long>> dp(s.length() + 1, vector<long long>(t.length() + 1, 0));

    for (int s_i = 0; s_i < s.length(); s_i++)
    {
        for (int t_i = 0; t_i < t.length(); t_i++)
        {
            if (s[s_i] == t[t_i])
            {
                chmax(dp[s_i + 1][t_i + 1], dp[s_i][t_i] + 1);
            }
            chmax(dp[s_i + 1][t_i], dp[s_i][t_i]);
            chmax(dp[s_i][t_i + 1], dp[s_i][t_i]);
        }
    }

    string res = "";
    int s_i = 0, t_i = 0;

    for (int j = 0; j < t.length(); j++)
    {
        if (dp[s.length()][j] < dp[s.length()][j + 1])
        {
            t_i = j + 1;
        }
    }

    for (int i = 0; i < s.length(); i++)
    {
        if (dp[i][t.length()] < dp[i + 1][t.length()])
        {
            s_i = i + 1;
        }
    }

    if (dp[s_i][t.length()] < dp[s.length()][t_i])
    {
        s_i = s.length();
    }
    else
    {
        t_i = t.length();
    }

    while (s_i > 0 && t_i > 0)
    {
        if (dp[s_i][t_i] == dp[s_i - 1][t_i])
        {
            --s_i;
        }
        else if (dp[s_i][t_i] == dp[s_i][t_i - 1])
        {
            --t_i;
        }
        else
        {
            res = s[s_i - 1] + res;
            --s_i, --t_i;
        }
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 70784
import java.io.IOException;
import java.io.InputStream;
import java.util.Collections;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;
import java.util.Queue;

public class Main {
	public static void main(String args[]) {

		FastScanner sc = new FastScanner();
		int n = sc.nextInt();
		int m = sc.nextInt();

		Queue<Integer> q = new PriorityQueue<Integer>(Collections.reverseOrder());
		for (int i = 0; i < n; i++) {
			q.add(sc.nextInt());
		}

		for (int i = 0; i < m; i++) {
			q.add(q.poll() / 2);
		}

		long result = 0;
		for (int x : q) {
			result += x;
		}

		System.out.println(result);
	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
            return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
            }
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
            }
        }

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
        }

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 26712
#include<cstdio>
#include<algorithm>
#define RI register int
#define CI const int&
using namespace std;
typedef long long LL;
const int N=100005;
struct element
{
	int l,r,b; LL v;
	friend inline bool operator < (const element& A,const element& B)
	{
		return A.v>B.v;
	}
}a[N]; int n,x,b[N]; LL ans;
inline bool check(const LL& t)
{
	int c1=t/x,c2=t%x; LL cur=0,dlt=0,ret=0; RI i; if (c1==n) return 1;
	for (i=1;i<=c1;++i) cur+=1LL*(x-a[i].b)*a[i].r; for (i=c1+1;i<=n;++i) dlt+=1LL*a[i].b*a[i].l;
	for (i=c1+1;i<=n;++i) if (cur+1LL*(c2>=a[i].b?a[i].r:a[i].l)*(c2-a[i].b)-(dlt-1LL*a[i].b*a[i].l)>=0) return 1;
	for (cur+=1LL*(x-a[c1+1].b)*a[c1+1].r,dlt-=1LL*a[c1+1].b*a[c1+1].l,i=1;i<=c1;++i)
	if (cur-(1LL*(x-a[i].b)*a[i].r)+1LL*(c2>=a[i].b?a[i].r:a[i].l)*(c2-a[i].b)-dlt>=0) return 1; return 0;
}
int main()
{
	RI i; for (scanf("%d%d",&n,&x),i=1;i<=n;++i)
	scanf("%d%d%d",&a[i].b,&a[i].l,&a[i].r),a[i].v=1LL*a[i].b*a[i].l+1LL*(x-a[i].b)*a[i].r;
	sort(a+1,a+n+1); LL l=0,r=1LL*x*n,mid; while (l<=r)
	if (check(mid=l+r>>1)) ans=mid,r=mid-1; else l=mid+1;
	return printf("%lld",ans),0;
}

Measured memory_bytes: 4020
using System;
using System.Linq;
using static System.Console;

namespace a {
static class Extensions {
   public static int ToInt(this string str) {
      return int.Parse(str);
   }

   public static int[] readIntArr() {
      return ReadLine().Split(' ').Select(int.Parse).ToArray();
   }
}

class Program {
   public static void Main(string[] args) {
      var temp = Extensions.readIntArr();
      var a = temp[0];
      var b = temp[1];

      if (a > b) WriteLine(2*a - 1);
      else if (a < b) WriteLine(2*b - 1);
      else WriteLine(2*a);
   }
}

}


Measured memory_bytes: 11348