akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;

typedef long long int ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define sz(x) int(x.size())
const int INF = 1001001001;
const ll mod = 998244353;
const ll INFL = 1001001001001001000;

vector<ll> divisor(ll N) {
    vector<ll> RES;
    for (ll I = 1; I*I <= N; I++) {
        if (N%I == 0) {
            RES.push_back(I);
            if (I != N/I) RES.push_back(N/I);
        }
    }
    return RES;
}

ll gcd(ll A, ll B) {
    return B ? gcd(B,A%B) : A;
}

long long extGCD(long long a, long long b, long long &x, long long &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    long long d = extGCD(b, a%b, y, x);
    y -= a/b * x;
    return d;
}

int main() {
    ll n; cin >> n;
    if (n <= 100) {
        ll k = 1;
        while (1) {
            if ((k*(k+1)/2)%n == 0) {
                cout << k << endl;
                return 0;
            }
            k++;
        }
    }
    vector<ll> divi = divisor(2*n);
    ll ans = INFL;
    for (ll p : divi) {
        ll q = (2*n)/p;
        ll g = gcd(p,q);
        if (g != 1) continue;
        ll a,b;
        extGCD(p,q,a,b);
        a = -a;
        a = (a%q+q)%q;
        
        if (a != 0) {
            ans = min(ans, p*a);
        }
    }
    cout << ans << endl;
    return 0;
}


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

int n;
map <int, int> M;

int main()
{
    long long ans = 0;

    cin >> n;
    for (int i = 1; i <= n; i++) {
        int x; cin >> x;

        if (x - i <= 0)
            ans += M[-(x - i)];

        M[x + i]++;
    }

    cout << ans;

    return 0;
}


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

int main(){
    int n;
    cin >> n;
    map<int, int> mp; 
    for(int i=0; i<n; i++){
        int a;
        cin >> a;
        mp[a]++;
    }
    int count = 0;
    for(auto itr = mp.begin(); itr != mp.end(); ++itr) {
        if(itr->second % 2 == 1){
            count++;
        }
    }
    cout << count << endl;
    return 0;
}

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

typedef pair<int,int> pi;

const int V=3000;
const int INF=1010101010;

struct edge{int to,cost;};
vector<edge> G[V];
int d[V];

int main()
{
    int N,M,K;
    scanf(" %d %d %d", &N, &M, &K);

    vector<int> a(M),b(M),c(M);
    rep(i,M)
    {
        scanf(" %d %d %d", &a[i], &b[i], &c[i]);
        --a[i];
        --b[i];
        G[a[i]].pb(edge{b[i],c[i]});
        G[b[i]].pb(edge{a[i],c[i]});
    }

    fill(d,d+V,INF);
    priority_queue<pi,vector<pi>,greater<pi>> que;

    rep(i,K)
    {
        int s;
        scanf(" %d", &s);
        --s;
        d[s]=0;
        que.push(pi(0,s));
    }

    while(!que.empty()){
        pi p=que.top();
        que.pop();
        int v=p.se;
        if(d[v]<p.fi) continue;
        rep(i,G[v].size())
        {
            edge e=G[v][i];
            if(d[e.to]>d[v]+e.cost)
            {
                d[e.to]=d[v]+e.cost;
                que.push(pi(d[e.to],e.to));
            }
        }
    }

    double ans=0;

    rep(i,N) ans=max(ans,d[i]*1.0);
    rep(i,M)
    {
        double s=(d[b[i]]+c[i]-d[a[i]])/2.0;
        if(0<=s && s<=c[i]) ans=max(ans, d[a[i]]+s);
    }

    printf("%d\n", (int)(ans+0.5));
    return 0;
}

Measured memory_bytes: 7184
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
#include <limits>
using namespace std;
// 素因数分解
typedef pair<long long, long long> P;
vector<P> prime_factorize(long long n)
{
vector<P> res;
for (long long p = 2; p * p <= n; ++p)
{
if (n % p != 0)
continue;
int num = 0;
while (n % p == 0)
{
++num;
n /= p;
}
res.push_back(make_pair(p, num));
}
if (n != 1)
res.push_back(make_pair(n, 1));
return res;
}
// 因数分解
long long gcd(long long x, long long y)
{
  if (y == 0)
  {
    return x;
  }
  else
  {
    return gcd(y, x % y);
  }
}
const int MOD = 1000000007;
typedef long long int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < (n); 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; }

int main()
{
    int n;
    cin >> n;
    vector<ll> H(n);
    rep(i,n){
        cin >> H[i];
    }
    for (int i = 0; i < n-1;i++){
        if(H[i+1]-H[i]>=0){
            continue;
        }else if(H[i+1]-H[i]==-1){
            H[i + 1]++;
        }else{
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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

using namespace std;

const int NIL=-1;
long long n, m;
long long p[100009], num[100009];

void init(){
    for(int i=0;i<n;i++){
        p[i] = NIL;
        num[i] = 1;
    }    
}

int parent(int a){
    if(p[a] == NIL)return a;
    return parent(p[a]);
}

bool check(int a, int b){
    if(parent(a) == parent(b))return true;
    return false;
}

int add(int a, int b){
    if(check(a, b))return 0;
    long long pa = parent(a), pb = parent(b);
    long long ret = num[pa]*num[pb];
    if(num[pa]<num[pb])swap(pa, pb);
    num[pa] += num[pb];
    p[pb] = pa;
    return ret;
}


int main(){
    cin >> n >> m;
    int a[100009], b[100009];
    vector<long long> ans;
    for(int i=0;i<m;i++){
        cin >> a[i] >> b[i];
        a[i]--;b[i]--;
    }
    init();
    ans.push_back(n*(n-1)/2);
    for(int i=m-1;i>=0;i--){
        ans.push_back(ans[m-1-i] - add(a[i], b[i]));
    }
    for(int i=0;i<m;i++){
        ans[i] -= ans[m];
    }
    for(int i=m-1;i>=0;i--){
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 4596
/*
Author: Babin Dutta
*/
 
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define f(i,n) for(int i=0;i<n;i++)
#define ff(i,a,b) for(int i=a;i<=b;i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
//#define endl "\n"
#define mm 998244353
 
ll power(ll x, ll y, ll p)
{
    ll res = 1;  
    x = x % p;  
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1; 
        x = (x*x) % p;  
    }
    return res;
}
ll modInverse(ll A,ll M)
{
    return power(A,M-2,M);
}

const int N = 2e5+1;
int par[N], rnk[N];

int find(int a){
	if(par[a] == -1) return a;
	return par[a] = find(par[a]);
}

void merge(int a, int b){
	if(rnk[a] >= rnk[b]) rnk[a] += rnk[b], par[b] = a;
	else rnk[b] += rnk[a], par[a] = b;
}

void solve(){
	int n,m; cin>>n>>m;
	int a,b;
	for(int i=0;i<=N;i++) par[i] = -1, rnk[i] = 1;
	for(int i=0;i<m;i++){
		cin>>a>>b;
		a = find(a);
		b = find(b);
		if(a != b) merge(a,b);
	}
	int ans = 0;
	for(int i=1;i<=n;i++) if(par[i] == -1) ans = max(ans, rnk[i]);
	cout<<ans<<endl;
}
 
int main(){
	#ifdef JUDGE
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
    #endif
	boost;
	int t=1; //cin>>t;
	for(int i=1;i<=t;i++) solve();
	return 0;
}

Measured memory_bytes: 5152
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1000000007;


bool check(auto& vs_part, int th, int K, int Q){
    int cnt = 0;
    for(auto& vs_part_i : vs_part){
        if(vs_part_i.size() < K) continue;
        int k = 0;
        for(int v : vs_part_i){
            if(v <= th){
                k++;
            }
        }
        cnt += min(k, int(vs_part_i.size()) - (K - 1));
    }
    return cnt >= Q;
}

int main(){
    int N, K, Q;
    cin >> N >> K >> Q;

    vector<int> A(N);
    for(int i=0;i<N;i++){
        cin >> A[i];
    }

    ll ans = 1LL << 60;
    for(int i=0;i<N;i++){
        ll min_value = A[i];

        vector<vector<ll>> vs_part;
        set<ll> vs;
        vs_part.push_back({});
        for(int j=0;j<N;j++){
            if(min_value <= A[j]){
                vs_part.back().push_back(A[j]);
                vs.insert(A[j]);
            }else{
                if(vs_part.back().size() > 0){
                    vs_part.push_back({});
                }
            }
        }
        if(vs_part.back().size() == 0){
            vs_part.pop_back();
        }

        vector<ll> vs_vec(vs.begin(), vs.end());
        reverse(vs_vec.begin(), vs_vec.end());

        int l = 0, r = vs_vec.size();
        while(r - l > 1){
            int mid = (r + l) / 2;
            if(check(vs_part, vs_vec[mid], K, Q)){
                l = mid;
            }else{
                r = mid;
            }
        }

        if(check(vs_part, vs_vec[l], K, Q)){
            ans = min(ans, vs_vec[l] - min_value);
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 460
#include<cstdio>

int gcd(int x, int y) {
    if(!y) return x;
    return gcd(y, x%y);
}

int main(void) {
    int x,y;
    scanf("%d%d",&x,&y);
    printf("%d\n",gcd(x,y));
    return 0;
}

Measured memory_bytes: 2684
#include<iostream>
using namespace std;
int main(){
    int i, H, W;
    i = 1;
    while(i == 1){
        cin >> H >> W;
        if(H == 0 & W == 0) break;
        for(int i = 0; i < W; i++){
            cout << "#";
        }
        cout <<endl;
        for(int j = 0; j < H-2; j++){
            cout<<"#";
            for(int k = 0; k < W-2; k++){
                cout <<".";
            }
            cout << "#" << endl;
        }
        for(int n = 0;n < W; n++){
            cout << "#";
        }
        cout <<endl;
        cout <<endl;
    }
}


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

const int mod = 1000000007;
ll modinv(ll a){
    ll b = mod, u = 1, v = 0;
    while(b){
        ll t = a/b;
        a -= t * b; swap(a,b);
        u -= t * v; swap(u,v); 
    }
    u %= mod;
    if(u < 0) u+= mod;
    return u;
}

int main(){
    ll n, k;
    cin >> n >> k;
    if(k>=n-1) k= n-1;

    rep(i,n/2+5){
        modinv(i+1);
    }

    ll ans;
    if(k==1) ans=0;
    else ans = 1;
    ll combn = 1;
    ll comb1 = 1;
    for(int i = 1; i<=k; i++){
        (combn *= n-i+1)%=mod;
        (combn *= modinv(i))%=mod;
        (comb1 *= n-i)%=mod;
        (comb1 *= modinv(i))%=mod;
        if(combn<0)combn += mod;
        if(comb1<0)comb1 += mod;
        ans += (combn*comb1)%mod;
        ans %= mod;
        if(ans<0) ans += mod;
    }
    cout << ans << endl;
    return 0;
}

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

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

Measured memory_bytes: 256
_, _, X, Y = map(int, input().split())
maxx = max(list(map(int, input().split())))
miny = min(list(map(int, input().split())))
flag = False
for i in range(X+1, Y+1):
    if maxx < i <= miny:
        flag = True
print('No War' if flag == True else 'War')

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

int main()
{
    int H,A,a;
    a=0;
    cin>>H>>A;
    for(int i=0;i<1000000;i++){
        H-=A;
        a++;
        if(H<=0){
            break;
        }
    }
    cout <<a<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<vector>
#include<climits>
#define ll long long int
using namespace std;
int main(void) {
  int a, b;
  cin>>a>>b;
  cout<<max(max(a+b, a-b), a*b)<<endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;

namespace MyProgram{
    class AtCoder{
        static void Main(){
            int N = int.Parse(Console.ReadLine());
            int[] A = Array.ConvertAll(Console.ReadLine().Split(' '),int.Parse);
            int[] route = new int[N+2];
            for(var i=1;i<=N;i++){
                route[i] = A[i-1];
            }
            route[0] = 0;
            route[N+1] = 0;

            int sum=0;
            for(var i=1;i<N+2;i++){
                sum += Math.Abs(route[i]-route[i-1]);
            }
            for(var i=1;i<=N;i++){
                int result = sum - Math.Abs(route[i] -route[i-1]) - 
                                Math.Abs(route[i+1] -route[i]) + Math.Abs(route[i+1]-route[i-1]);
                Console.WriteLine(result);
            }
        }
    } 
}

Measured memory_bytes: 24284
// All Heil Fire Lord Zuko

#include <bits/stdc++.h>
using namespace std;

#define F first
#define S second
#define PB push_back
#define debug(x) cerr << #x << " = " << x << endl

#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()

typedef long long ll;
typedef long double ld;

const int N = 2 * 100 * 1000 + 19;

int32_t main() {
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int r;
    cin >> r;
    cout << 3 * r * r;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[100005];
int b[100005];

int main()
{
    int i,j,m,n;
    while(cin>>m)
    {
        n=0;
        memset(b,0,sizeof(b));
        for(i=1; i<=m; i++)
        {
            cin>>a[i];
            b[a[i]]++;
            b[a[i]+1]++;
            if(a[i]==0)
            {
                n++;
                continue;
            }
            b[a[i]-1]++;
        }
        int MIN=-1;
        for(i=0; i<=100005; i++)
        {
            if(MIN<b[i])
            {
                MIN=b[i];
            }
        }
        n=(MIN>n)?MIN:n;
        cout<<n<<endl;
    }
    return 0;
}

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

int main() {
    int l, r, d;
    cin >> l >> r >> d;
    int ans = r / d;
    ans -= int((l - 1) / d);
    cout << ans << endl;
}


Measured memory_bytes: 3632
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  int n;
  scanf("%d", &n);

  if (n == 3 || n == 5 || n == 7) {
    printf("YES\n");

  } else {
    printf("NO\n");
  }

  return 0;
}


Measured memory_bytes: 256
/**********************************************************/
/**            Bismillahir-rahmanir-rahim                **/
/**  In the name of Allah, the Beneficent, the Merciful. **/
/**********************************************************/
/**@author: Sayed Sohan*/
/**status : */
/**url: */
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
typedef long long  ll;
typedef unsigned long long ull;
#define FOR(i,x,n) for(ll i=(x);i<(n);i++)
#define IFOR(i,n,x) for(ll i=(n-1);i>=(x);i--)
#define REP(i,n) for(ll i=0;i<n;i++)
#define IREP(i,n) for(ll i = n-1;i>=0;i--)
#define cas(c,x)  cout<<"Case "<<c++<<": "<<x<<NL;
#define clr(arr,value) memset(arr,value,sizeof(arr))
#define MOD 1000000007
#define PI acos(-1.0)
#define rtod 180/PI
#define DIF if(0)
#define PB push_back
#define MP make_pair
#define SP " "
#define NL "\n"
#define DE cout<<"HERE"<<endl;
#define F first
#define S second
#define INF 1e18
#define Pause system("pause")
#define __FAST_IO ios_base::sync_with_stdio(0);
#define clr2V(x,sz) for(int iii=0;iii<=sz;iii++) x[iii].clear();
#define NUM1(x) __builtin_popcount(x)
#define MAX 200010/** can increase another 0 */

//** your code goes from here



int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    __FAST_IO;
    ll i,j,k,arr[MAX],l,m,n,x,y,coun,sum,ans,T,check;
    vector<ll> v;
    string s;

    cin>>n;

    for(i=0;i<n;i++) cin>>arr[i];

    ans = 1;
    ll mn = arr[0];

    for(i=1;i<n;i++){
        if(mn>arr[i]) ans++;
        mn = min(mn,arr[i]);
    }

    cout<<ans<<NL;


    return 0;
}



Measured memory_bytes: 1792
import sys
input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return input().rstrip().decode()
def II(): return int(input())
def FI(): return float(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()



def main():
	n,k=MI()
	A=LI()
	B=[0]
	C=[0]

	for i in A:
		B.append(B[-1]+i)
		C.append(C[-1]^i)
	#print(A,B,C)


	ans=0

	D=[]
	E=[]
	F=[]

	for i in range(n):
		for j in range(i+1,n+1):
			D.append(B[j]-B[i])

	#print(D)

	ans=0

	for i in range(41,-1,-1):
		cnt=0
		E=[]
		for d in D:
			if 1<<i&d:
				E.append(d)
				cnt+=1
				#print(1<<i,d)

		if cnt>=k:
			ans+=1<<i
			D=E.copy()

	print(ans)
	
	









if __name__ == "__main__":
	main()


Measured memory_bytes: 117644
/* *
 *
 * Author: Hamkor
 *
 * */
 
#include <bits/stdc++.h>

using namespace std;

/* * * *   * * *   	* * * */
typedef long long ll;
const int oo = 1e9;
const ll mod = 100000000;
typedef complex<ll> P;
#define X real()
#define Y imag()
/* * * *   * * *   	* * * */

int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n, m, s = 0; cin>>n>>m;
	vector<vector<int> > a(m);
	vector<int> p(m);
	for (int i=0; i<m; ++i){
		int d; cin>>d;
		while(d--){
			int x; cin>>x;
			a[i].push_back(x);
		}
	}
	for(int i=0; i<m; ++i) cin>>p[i];
	for (int i=0; i<(1<<n); ++i){
		int c = 0;
		for (int j=0; j<m; ++j){
			int d = 0;
			for (int k = 0; k<(int)a[j].size(); ++k){
				if (i & (1<<(a[j][k]-1))) ++d; 
			}
			if(d%2 == p[j]) c++;
		}
		if (c == m) s++;
	}
	cout<<s;
	return 0;
}


Measured memory_bytes: 256
// When you are hungry for something and you're determined and you're focused 
// and you're committed to something it's hard to surrender, isn't it?

#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define ll long long 
#define int ll
#define mod 1000000007
#define mod1 1000000006
#define modi 998244353
#define setbit(x) __builtin_popcount(x)
#define fff(i,n) for(int i=0;i<n;i++)
#define ff first
#define ss second
#define pb push_back
vector<ll> vi[300005];
int color[100005];
ll pa[500005];
ll si[500005];
#define pb push_back
bool visi[1000005]={false};
bool is[100005];
ll fac[10000001];
ll prime[400005];
ll bit[100005];
const long double eps = 1.0e-14;      // allowable error
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL);
 
 
void fact(){
    fac[0]=1;
    for(int i=1;i<=10000000;i++){
        fac[i]=(fac[i-1]*i)%mod;
    }
    return ;
}
void sieve(){
    prime[0]=0;
    prime[1]=0;
    for(int i=2;i<400005;i++){
        prime[i]=1;
    }
    for(int i=2;i*i<400005;i++){
        if(prime[i]==1){
            for(int j=i*i;j<400005;j+=i){
                prime[j]=0;
            }
        }
    }
    
}
 
ll power(ll n , ll p ){
    if(p==0)
        return 1;
    
    ll res = power((n*n)%mod,p/2);
    if(p%2==1)
        res = (n*res)%mod;
    
    return res;
}
 
 
void upd(ll i,ll val,ll n) {
    for(;i<=n;i+=i&(-i))
        bit[i]+=val;
}
 
ll qry(ll i) {
    ll sum=0;
    for(;i>0;i-=i&(-i))
        sum+=bit[i];
    return sum;
}
 
 
ll fin(ll u) {
    if(pa[u]==u)
        return u;
    return fin(pa[u]);
}
 
void uni(ll u,ll v) {
    ll p1=fin(u);
    ll p2=fin(v);
    if(p1==p2)
        return;
    if(si[p1]<si[p2])
        swap(p1,p2);
    si[p1]+=si[p2];
    pa[p2]=p1;
    return;
}
 
int32_t main() {
    fio
    
    int a,b;
    cin >> a >> b;
    map<int,int> m;
    m[a]=1;
    m[b]=1;
    
    if(m[1]==0)
    cout << 1 ;
    else if(m[2]==0)
    cout << 2;
    else
    cout << 3;
    
	return 0;
    
}

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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
#define F first
#define S second
#define sz(x) (int)x.size()
#define db(x) cerr << #x << ": " << x << "\n";

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

    string N;
    cin >> N;
    int R = N.size() - 1;
    if(N[R] == '2' || N[R] == '4' || N[R] == '5' || N[R] == '7' || N[R] == '9')
        cout << "hon";
    else if(N[R] == '0' || N[R] == '1' || N[R] == '6' || N[R] == '8')
        cout << "pon";
    else
        cout << "bon";
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll N=1e5+5;
ll dx[]={-1,0,1,0};
ll dy[]={0,-1,0,1};
bool vis[1005][1005];
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll n,m;cin>>n>>m;
    char a[n][m];
    queue< pair< pair<ll,ll> , ll > > q;
    for(ll i=0;i<n;i++){
        for(ll j=0;j<m;j++){
            cin>>a[i][j];
            if(a[i][j]=='#')q.push({{i,j},0}),vis[i][j]=1;
        }
    }
    ll ans = 0;
    while(!q.empty()){
        ll x=q.front().first.first , y=q.front().first.second;
        ll d=q.front().second;
        q.pop();
        ans= max(ans , d);
        for(ll i=0;i<4;i++){
            ll nx = x+dx[i] , ny=y+dy[i];
            if(nx<0 || nx>=n || ny<0 || ny>=m || vis[nx][ny])continue;
            vis[nx][ny]=1;
            q.push({{nx,ny},d+1});
        }
    }

    cout<<ans;
}


Measured memory_bytes: 26420
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin >> s;
  int i,sw,l,c;
  sw=0;
  c=0;
  l=s.size();
  
  for(i=0;i<l;++i)
  {
  if(s.at(i)==s.at(l-1-i)) sw++;
  }
  if(sw==l) {c++;}
  sw=0;
  
  for(i=0;i<(l-1)/2;++i)
  {
  if(s.at(i)==s.at((l-1)/2-1-i)) sw++;
  }
  if(sw==(l-1)/2) {c++;}
  sw=0;
  
  for(i=0;i<(l-3)/2;++i)
  {
  if(s.at((l+1)/2+i)==s.at(l-1-i)) sw++;
  }
  if(sw==(l-3)/2) {c++;}
  sw=0;
  
  if(c==3) cout << "Yes";
  else cout << "No";
  
return 0;  
}

Measured memory_bytes: 3624
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[][] A = new int[N][2];
        for (int i = 0; i < N; i++) {
            A[i][0] = sc.nextInt();
            A[i][1] = i+1;
        }
        Arrays.sort(A, (a,b) -> a[0]-b[0]);

        for (int i = 0; i < N; i++) {
            System.out.print(A[i][1] + " ");
        }
        System.out.println();
    }
}


Measured memory_bytes: 68108
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
const double PI  = 3.1415926535897932384626433832795028841971;
const int    INF = 100000000;
const double EPS = 1e-10;
const int    MOD = 1000000007;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

ll h, w, n;
int a[100000], b[100000];
map<P,int> m;
vector<P> v;
ll ans[10];

int main(){
	cin >> h >> w >> n;
    rep(i,n){
        cin >> a[i] >> b[i];
        a[i]--;b[i]--;
        for(int j = a[i]-1; j <= a[i]+1; j++){
            for(int k = b[i]-1; k <= b[i]+1; k++){
                if(j < 0 || j > h-1 || k < 0 || k > w-1) continue;
                m[P(j,k)] += 1;
                if(j <= 0 || j >= h-1 || k <= 0 || k >= w-1) continue;
                v.push_back(P(j,k));
            }
        }
    }
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
    rep(i,v.size()){
        ans[m[v[i]]]++;
    }
    ll sum = 0;
    rep(i,10) sum += ans[i];
    cout << (h-2)*(w-2)-sum << endl;
    for(int i = 1; i < 10; i++) cout << ans[i] << endl;
}


Measured memory_bytes: 64360
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
#define REP(i,n) for(ll i=0; i<(n); i++)
#define REP2(i,x,n) for(ll i=x; i<(n); i++)
#define REP3(i,x,n) for(ll i=x; i>(n); i--)
#define zero_pad(num) setfill('0') << std::right << setw(num)
#define space_pad(num) setfill(' ') << std::right << setw(num)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main(){
    ll K,X;
    cin >> K >> X;

    if(X <= K*500){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define Hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
#define ll long long
int main(){
    Hello
    int a,b;
    cin >> a >> b;
    cout << max(a + b, max(a + a - 1, b + b - 1));
    return 0;
}


Measured memory_bytes: 3588
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
int acs(const void *a, const void *b){return *(int*)a - *(int*)b;} /* 1,2,3,4.. */
int des(const void *a, const void *b){return *(int*)b - *(int*)a;} /* 8,7,6,5.. */
#define min(a,b) (a < b ? a: b)
#define max(a,b) (a > b ? a: b)

#define MAXN (200000)
#define MOD (998244353)


int main(void)
{
    int a,b;

    
    scanf("%d %d", &a, &b);
    int c = 0;
    int t = 1;
    while(t<b)
    {
        t += a-1;
        c++;
    }
    printf("%d\n",c);
    return 0;
}







Measured memory_bytes: 128
X, Y = map(int, input().split())#X匹、Y本の足
a = 0#つる
b = X - a#かめ
for i in range(X+1):
  a = i
  b = X - a
  if a * 2 + b * 4 == Y:
    print("Yes")
    break
  elif b == 0:
    print("No")

Measured memory_bytes: 9172
#include"bits/stdc++.h"
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
 
int main(){
    int h,w,a,b;
    cin>>h>>w>>a>>b;
    rep(i,b){rep(j,w-a)cout<<1;rep(j,a)cout<<0;cout<<endl;}
    rep(i,h-b){rep(j,w-a)cout<<0;rep(j,a)cout<<1;cout<<endl;}
    return 0;
}

Measured memory_bytes: 1280
abcd = input()

for mask in range(1 << 3):
  res = int(abcd[0])
  ans = abcd[0]
  
  for i in range(3):
    if ((mask >> i) & 1) == 1:
      res += int(abcd[i + 1])
      ans += '+' + abcd[i + 1]
    else:
      res -= int(abcd[i + 1])
      ans += '-' + abcd[i + 1]
  
  if res == 7:
    print('{}=7'.format(ans))
    break

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

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long int
#define INF 1000000007
#define llINF 1000000000000000007
#define v(i) vector<i>
#define vv(i) vector<vector<i>>
// cin.eof() 入力個数の問題
// int num = atoi(string.c_str()); 文字列の整数変換
int keta(ll n){int ans=0;while(n>0){n /= 10; ans++;}return ans;}
ll _pow(ll a,ll b){ll ans = 1;rep(i,b){ ans *= a;}return ans;}

int main() {
    string s; cin>>s;
    map<char,int>m;
    rep(i,s.size()){
        m[s[i]]++;
    }
    int a[3];
    rep(i,3){
        a[i] = m['a'+i];
    }
    sort(a,a+3);
    if(a[2] - a[0] <=1){
        cout<<"YES"<<endl;
    }else
    {
        cout<<"NO"<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 3760
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    m,n = list(map(int, input().split()))
    md=10**9+7
    print(pow(m,n,md))
main()



Measured memory_bytes: 5608
// first second push_back unordered return continue break vector visited check flag bool while iterator begin end lower_bound upper_bound temp true false ll_MAX ll_MIN insert erase clear pop push compare ll64_MAX ll64_MIN  reverse replace stringstream string::npos length substr front priority_queue
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) x.begin(),x.end()
const ll mod = 1e9 + 7 ;
const ll inf =
 1e9 + 5 ;
 //1e18L + 5;
const ll nax = 2e5 + 5;
void min_self(ll&a , ll b){a=min(a,b);}
void max_self(ll&a , ll b){a=max(a,b);}
void add_self(ll&a , ll b){a=(a+b)%mod;}
//#define (x)  get<0>(x) 
//#define (x)  get<1>(x)
//#define (x)  get<2>(x)
signed main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
ll h ; cin >> h ; 
ll k = log2(h) + 1 ; 
cout<< uint64_t( pow(2 , k) - 1 ) << endl;	

	
}

Measured memory_bytes: 256
import collections

n = int(input())
d = [int(_) for _ in input().split()]
m = int(input())
t = [int(_) for _ in input().split()]

D = collections.Counter(d)
nd = dict.fromkeys(D, 0)

for i in range(m):
    if t[i] in nd:
        get_cnt = nd[t[i]] + 1
        if get_cnt <= D[t[i]]:
            nd[t[i]] = get_cnt
        else:
            print('NO')
            exit()
    else:
        print('NO')
        exit()
print('YES')

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

ll canDevideNum(ll n, ll c, ll d, ll l){
  ll num;
  num = n/c + n/d - n/l;
  return num;
}
ll lcm(ll c, ll d){
  ll r,l;
  ll a = c;
  ll b = d;
  if (a<b) swap(a,b);
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  l = c*d/b;
  return l;
}

int main() {
  ll a,b,c,d;
  cin >> a >> b >> c >> d;
  ll l = lcm(c,d);
  ll ans;
  ans = (b-canDevideNum(b,c,d,l))-((a-1)-canDevideNum(a-1,c,d,l));
  cout << ans << endl;
  
  return 0;
}


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

int main() {
  unordered_set<int> u;
  rep(i, 3){
    int a;
    cin >> a;
    u.insert(a);
  }
  if(u.size() == 2) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
int main(){
    long long N, X, M;
    cin >> N >> X >> M;
    vector<long long> cnt;
    cnt.push_back(X);
    set<long long> s;
    s.insert(X);
    int ind;
    while(1){
        X = X * X % M;
        if(s.count(X)) {
            for(int i = 0; i < (int)cnt.size(); i++){
                if(cnt[i] == X) ind = i;
            }
            break;
        }
        s.insert(X);
        cnt.push_back(X);
    }
    int n = cnt.size();
    long long ans = 0;
    if(N <= n){
        for(int i = 0; i < N; i++) ans += cnt[i];
    }
    else{
        if(cnt[n - 1] != 0){
            long long sum = 0;
            for(int i = ind; i < n; i++){
                sum += cnt[i];
            }
            long long t = n - ind;
            for(int i = 0; i < ind; i++) ans += cnt[i];
            ans += (N - ind) / t * sum;
            for(int i = ind; i < ind + (N - ind) % t; i++){
                ans += cnt[i];
            }
        }
        else{
            for(int i = 0; i < n; i++){
                ans += cnt[i];
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 5908
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;cin>>n;
	int i;
	int a[n+5],b[n+5];
	for(i=0;i<n;i++)
	cin>>a[i]>>b[i];
	for(i=2;i<n;i++)
	if(a[i]==b[i]&&a[i-1]==b[i-1]&&a[i-2]==b[i-2])
	break;
	i==n?cout<<"No"<<endl:cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag,
		tree_order_statistics_node_update> ordered_set;

#define el				'\n'
#define sz(v)			((int)((v).size()))
#define all(v)          ((v).begin()),((v).end())
#define clr(v, d)		memset(v, d, sizeof(v))

double const EPS = 1e-8, PI = acos(-1);
const int N = 3000 + 9, M = 100 + 9, OO = (int) 1e6 + 1;
const long long MOD = 998244353;

typedef long long ll;

void OUTPUT() {
	cout << fixed << setprecision(12);
	ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
}

void INPUT() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif
}

ll dp[N][N];
int main() {
//	INPUT();
	OUTPUT();
	int n;
	cin >> n;
	vector<int> v(n);
	for (int i = 0; i < n; i++)
		cin >> v[i];
	for (int L = n - 1; L >= 0; L--) {
		for (int R = L; R < n; R++) {
			if (L == R)
				dp[L][R] = v[L];
			else {
				dp[L][R] = max(v[L] - dp[L + 1][R], v[R] - dp[L][R - 1]);
			}
		}
	}
	cout << dp[0][n - 1];

	return 0;

}


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

int main()
{
   int n,k,r,s,p;
   string T;
   int ans=0,vis[100005];
   memset(vis,0,sizeof(vis));
   cin>>n>>k>>r>>s>>p>>T;
    for(int i=0;i<n;i++){
          if(i-k>=0 && vis[i-k] && T[i]==T[i-k]) continue;
          if(T[i]=='r') ans+=p;
          if(T[i]=='s') ans+=r;
          if(T[i]=='p') ans+=s;
          vis[i]=1;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 896
open Batteries
module EnumL = Enum.Labels
module ListL = List.Labels
module ArrayL = Array.Labels

let dbg0 x = Printf.eprintf "[debug]%s\n" @@ dump x
let dbg1 x = dbg0 x; x

let id = identity

let (++) n m = List.range n `To m
let (++-) n m = if n >= m then List.range n `Downto m else []
let (++^) n m = if n < m then List.range n `To (pred m) else []

let scan fmt = Scanf.sscanf (read_line ()) fmt

let scan_lines n fmt f =
  if n = 0 then []
  else List.map (fun _ -> scan fmt f) (1 ++ n)

let scan_list ?sep cnv =
  let line = read_line () in
  (match sep with
   | None -> List.map String.of_char @@ String.to_list line
   | Some sep -> String.split_on_char sep line)
  |> List.map cnv

let scan_array ?sep cnv = Array.of_list @@ scan_list ?sep cnv

let scan_matrix n m e ?sep conv =
  let arr = Array.make_matrix n m e in
  ListL.iter (0 ++^ n)
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list ?sep conv);
  arr

let atoi c = Char.code c - Char.code '0'

let rec powerset = function
  | [] -> [[]]
  | hd::tl ->
    let pws =  powerset tl in
    pws @ ListL.map pws ~f:(fun pw -> hd::pw)

let permutations l =
  let rec interleave x = function
    | [] -> [[x]]
    | (hd::tl) as l ->
      (x::l) :: (interleave x tl |> ListL.map ~f:(fun l -> hd::l)) in
  let rec aux = function
    | [] -> [[]]
    | a::rest ->
      aux rest |> ListL.map ~f:(interleave a) |> List.concat in
  aux l

let intersection l =
  EnumL.filter ~f:(fun x -> EnumL.exists ~f:((=) x) @@ Enum.clone l)

let zip l m =
  let n = min (List.length l) (List.length m) in
  List.combine (List.take n l) (List.take n m)

let lower_bound n f =
  let rec aux l u =
    if u - l > 1 then
      let m = (l + u) / 2 in
      if f m then aux l m
      else aux m u
    else u in aux (-1) n

let between n x m = n <= x && x < m

let n = scan "%d" id
let ls = Array.of_list @@ scan_lines n "%f %f" Tuple2.make

let () =
  let sets = permutations (0++^n) in
  ListL.map sets ~f:(fun set ->
      ListL.map (List.combine (List.take (pred @@ List.length set) set) (List.drop 1 set))
        ~f:(fun (i, j) ->
            let (x0,y0)= ls.(i) in
            let (x1,y1)= ls.(j) in
            Float.sqrt (Float.pow (x0-.x1) 2.0  +. Float.pow (y0 -. y1) 2.0)
          ) |> List.fsum
    ) |> List.fsum
  |> (fun v -> v /. (Float.of_int @@ List.length sets))
  |> Printf.printf "%f\n"


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++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 MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

int main(){
  // D<=200
  // N<=200
  // C<=100
  // NCD <= 4e6 safe
  // dp[d][c] = (d??\????????§c?????????????????????????????§?????????)
  int d,n;
  cin>>d>>n;
  int T[d];
  int A[n],B[n],C[n];
  REP(i,d) cin>>T[i];
  REP(i,n) cin>>A[i]>>B[i]>>C[i];
  int dp[d+1][101];
  REP(i,d+1)REP(j,101)dp[i][j] = -1000000007;
  REP(i,d){
    if(i==0){
      REP(j,n){
        if(!(A[j]<=T[i] && T[i]<=B[j]) )continue;
        dp[i][C[j]] = 0;
      }
    }else{
      // using j
      REP(j,n){
        if(!(A[j]<=T[i] && T[i]<=B[j]) )continue;
        REP(k,101){
          dp[i][C[j]] = max<int>(dp[i][C[j]], dp[i-1][k]+abs(C[j]-k));
        }
      }
    }
  }
  int ans = 0;
  REP(i,101)ans = max(ans,dp[d-1][i]);
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1240
import bisect,collections,copy,heapq,itertools,math,string
import numpy as np
import sys
sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

H,N = LI()
A = LI()

A_np = np.array(A)
A_sum = np.sum(A_np)

ans = True
if H>A_sum:
    ans=False

if ans:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 38264
#include <iostream>
#include <cstring>

using namespace std;

typedef struct
{
	int x;
	int y;
} pos;

int N,H,W,M[1000][1000],C[1001][1001];

int main(void)
{
	while(true)
	{
		cin >> H >> W >> N;
		if(H == 0 && W == 0 && N == 0)
			exit(0);
		memset(M,0,sizeof(int[1000][1000]));
		memset(C,0,sizeof(int[1001][1001]));
		for(int y = 0;y < H;y++)
		{
			for(int x = 0;x < W;x++)
			{
				cin >> M[x][y];
			}
		}
		C[0][0] = N-1;
		for(int y = 0;y < H;y++)
		{
			for(int x = 0;x < W;x++)
			{
				C[x][y+1] += C[x][y] / 2;
				C[x+1][y] += C[x][y] / 2;
				if(C[x][y] % 2 == 1)
				{
					if(M[x][y] == 0)
						C[x][y+1]++;
					else
						C[x+1][y]++;
					M[x][y] = (M[x][y] + 1) % 2;
				}
			}
		}
		pos cp;
		cp.x = 0;
		cp.y = 0;
		while(cp.x != W && cp.y != H)
		{
			if(M[cp.x][cp.y] == 0)
				cp.y++;
			else
				cp.x++;
		}
		cout << cp.y+1 << " " << cp.x+1 << endl;
	}
}

Measured memory_bytes: 10896
#include<stdio.h>
#include<math.h>
 
 int main(void)
 {
   double x1 , x2 , x3 , y1 , y2 , y3 , x, y , r , a , s ;
   int n ;   

      scanf("%d",&n);
      while((n != 0)&&(scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3)!=EOF)){
          a = (sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))+sqrt(x2*x2+y2*y2)-sqrt(x3*x3-y3*y3)) / 2*sqrt(x1*x1+y1*y1)*sqrt(x2*x2+y2*y2) ;
	  s = sin(a);
          r = x3 / (2*s);
          x = ((y1-y3)*(y1*y1-y2*y2+x1*x1-x2*x2)-(y1-y2)*(y1*y1-y3*y3+x1*x1-x3*x3))/(2*(y1-y3)*(x1-x2)-2*(y1-y2)*(x1-x3));
          y = ((x1-x3)*(y1*y1-y2*y2+x1*x1-x2*x2)-(x1-x2)*(y1*y1-y3*y3+x1*x1-x3*x3))/(2*(y1-y2)*(x1-x3)-2*(y1-y3)*(x1-x2));
          r = sqrt((x1-x)*(x1-x)+(y1-y)*(y1-y));
          printf("%.3f %.3f %.3f\n",x,y,r);
          n--;
      }
      return 0 ;
 }

Measured memory_bytes: 672
import bisect
import collections
import sys
import heapq

sys.setrecursionlimit(100000)
input = sys.stdin.readline
ACMOD = 1000000007
INF = 1 << 32


def lmi():
    return list(map(int, input().split()))


def llmi(n):
    return [lmi() for _ in range(n)]


N = int(input())
A = lmi()

lq = []  # normal
hq = []  # * -1
for a in A[:N]:
    heapq.heappush(lq, a)
for a in A[2 * N:]:
    heapq.heappush(hq, - a)

dpl = [0 for _ in range(N + 1)]  # middle をNまで消費したときの (a′の前半N要素の総和)
dph = [0 for _ in range(N + 1)]  # middle をNまで消費したときの (a′の後半N要素の総和)

middle = A[N:2 * N]
dpl[0] = sum(A[:N])
last_val = dpl[0]
for count in range(1, N + 1):
    heapq.heappush(lq, middle[count - 1])
    v = heapq.heappop(lq)
    dpl[count] = dpl[count - 1] - v + middle[count - 1]

dph[N] = sum(A[2 * N:])
for count in reversed(range(N)):
    heapq.heappush(hq, -middle[count])
    v = -  heapq.heappop(hq)  # bigger value
    dph[count] = dph[count + 1] - v + middle[count]


print(max(dpl[i] - dph[i] for i in range(N+1)))


Measured memory_bytes: 39892
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	h := make([]int, n)
	for i := 0; i < len(h); i++ {
		fmt.Scan(&h[i])
	}
	sort.Sort(sort.Reverse(sort.IntSlice(h)))

	sum := 0
	for i:=k; i<len(h); i++{
		sum += h[i]
	}

	fmt.Println(sum)
}


Measured memory_bytes: 6496
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define INF 2140000000
//const long long MOD = 1000000007;
//const long long MOD = 998244353;
long long MOD;

using namespace std;

ll dp[6010][8005];

void solve()
{
    int n;
    scanf("%d%lld", &n, &MOD);

    dp[0][n] = 1;   // dp[i][j]: 後ろからi文字目まで選択済で、ただし残る2マス数が残る1マス数よりj-n個多い場合の数
    int i, j;
    for (i = 0; i < n * 3; i++) {
        for (j = 0; j <= n*4; j++) {
            if (dp[i][j]) {
                if(j+1<=n*4) dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i][j]) % MOD;
                if(i+2<=n*3 && j-1>=0)   dp[i + 2][j - 1] = (dp[i + 2][j - 1] + dp[i][j] * (n*3-i-1) % MOD) % MOD;
                if(i+3<=n*3) dp[i + 3][j] = (dp[i + 3][j] + dp[i][j] * (n * 3 - i - 1) % MOD * (n * 3 - i - 2) % MOD) % MOD;            
            }
        }
    }
    ll ans = 0;
    for (j = n; j <= n * 4; j++) {
        ans = (ans + dp[n * 3][j]) %MOD;
    }
    printf("%lld\n", ans);

    return;
}

int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T; scanf("%d", &T);
    while(T--) {
        solve();
    }
#endif
    return 0;
}


Measured memory_bytes: 373504
import Queue
que = Queue.PriorityQueue()
dic = {
        ord('r')+ord('g'): 'b',
        ord('g')+ord('b'): 'r',
        ord('b')+ord('r'): 'g',
        }
while True:
    s = raw_input()
    if s=='0':
        break
    while not que.empty():
        que.get()
    cost = {}
    cost[s] = 0
    que.put((0, s))
    ans = -1
    while not que.empty():
        nn, ss = que.get()
        if all(e == ss[0] for e in ss):
            ans = nn
            break
        if cost[ss] < nn:
            continue
        for i in xrange(len(ss)-1):
            c0, c1 = ss[i], ss[i+1]
            if c0 != c1:
                code = dic[ord(c0)+ord(c1)]
                sa = ss[:i] + code*2 + ss[i+2:]
                if sa not in cost or nn+1 < cost[sa]:
                    cost[sa] = nn+1
                    que.put((nn+1, sa))
    print "NA" if ans<0 else ans

Measured memory_bytes: 6752
import java.util.*;
public class Main {
	static final long mod = 1000000007;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] s = sc.next().toCharArray();
		long[][] dp = new long[s.length][13];
		if(s[0] == '?'){
			for(int d = 0; d < 10; d++){
				dp[0][d] = 1;
			}
		}
		else{
			dp[0][s[0]-'0'] = 1;
		}
		for(int i = 1; i < s.length; i++){
			if(s[i] == '?'){
				for(int d = 0; d < 10; d++){
					for(int e = 0; e < 13; e++){
						dp[i][(10*e+d)%13] = (dp[i][(10*e+d)%13] + dp[i-1][e]) % mod;
					}
				}
			}
			else{
				for(int e = 0; e < 13; e++){
					dp[i][(10*e+s[i]-'0')%13] = (dp[i-1][e] + dp[i][(10*e+s[i]-'0')%13]) % mod;
				}
			}
		}
		System.out.println(dp[s.length-1][5]);
	}
}


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

#include <cmath>
struct Point{
  double x, y;
  Point(double x = 0, double y = 0):x(x), y(y){}
  Point operator +(Point p) { return Point(x + p.x, y + p.y); }
  Point operator -(Point p) { return Point(x - p.x, y - p.y); }
  Point operator *(double a) { return Point(x * a, y * a); }

  double norm() { return x*x + y*y; }
  double abs()  { return sqrt(norm()); }
};
typedef Point Vector;

struct Segment {
  Point p1, p2;
};
typedef Segment Line;

double dot(Vector a, Vector b) {
  return a.x*b.x + a.y*b.y;
}

double cross(Vector a, Vector b) {
  return a.x*b.y - a.y*b.x;
}

bool isParallel(Vector a, Vector b) {
  return cross(a, b) == 0.0;
}

Point project(Segment s, Point p) {
  Vector base = s.p2 - s.p1;
  return s.p1 + base*(dot(p-s.p1, base)/base.norm());
}

Point reflect(Segment s, Point p) {
  return p + (project(s, p) - p) * 2.0;
}

int main() {
  Segment s;
  Point q, r;
  while(scanf("%lf,%lf,%lf,%lf,%lf,%lf",
	      &s.p1.x, &s.p1.y, &s.p2.x, &s.p2.y, &q.x, &q.y) != EOF) {

    r = reflect(s, q);
    printf("%.6f %.6f\n", r.x, r.y);
  }
  return 0;
}

Measured memory_bytes: 0
// Ala be zekrellah tatmaenolgholoob ...
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define F first
#define S second
#define MP make_pair
const int maxn = 1e5+9;
const ll mod = 1e9+7;

vector <int> g[maxn], vec, tmp, ans;
int deg[maxn];
bool vis[maxn];

int dfs (int v, int parent = -1) {
	int mx = 0;
	for (auto u : g[v]) {
		if (u == parent) continue;
		mx = max(mx, dfs(u, v) + 1);
	}
	return mx;
}

ll cal () {
	while (vec.size()) {
		tmp.clear();
		int mx = 0;
		for (auto v : vec) {
			mx = max(mx, deg[v]);
			for (auto u : g[v]) {
				if (vis[u]) continue;
				vis[u] = true;
				deg[u]--;
				tmp.push_back(u);
			}
		}
		vec = tmp;
		if (mx) ans.push_back(mx);
	}
	ll res = 1;
	for (auto x : ans)
		res *= x;
	return res;
}

void setdeg (int n) {
	for (int i = 0; i < n; i++) deg[i] = g[i].size();
}

int main () {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	for (int i = 0; i < n - 1; i++) {
		int v, u;
		cin >> v >> u;
		--v; --u;
		g[v].push_back(u); g[u].push_back(v);
	}
	int mn = 1e9;
	for (int i = 0; i < n; i++) {
		int d = dfs(i);
		if (d < mn) {
			vec.clear();
			mn = d;
		}
		if (d == mn)
			vec.push_back(i);
	}
	ll res = 0;
	if (vec.size() == 2) {
		setdeg(n);
		ans.push_back(2);
		vis[vec[0]] = true; vis[vec[1]] = true;
		deg[vec[0]]--; deg[vec[1]]--;
		res = cal();
		cout << mn << " " << res << "\n";
	}
	else {
		int v = vec[0];
		setdeg(n);
		vis[v] = true;
		res = cal();
		for (auto u : g[v]) {
			setdeg(n);
			memset(vis, 0, sizeof vis);
			vec.clear(); ans.clear();
			vec.push_back(v); vec.push_back(u);
			ans.push_back(2);
			vis[v] = vis[u] = true;
			deg[v]--; deg[u]--;
			res = min(res, cal());
		}
		cout << mn + 1 << " " << res << "\n";
	}
}



Measured memory_bytes: 2688
#include <stdio.h>

int main(void)
{
	long int n, a[5];
	if(scanf("%ld%*c%ld%*c%ld%*c%ld%*c%ld%*c%ld%*c", &n, &a[0], &a[1], &a[2], &a[3], &a[4]) < 0) {
		return 0;
	}

	//long int sum = n/a[0]+1;
	long int b[5];
	int i;

	//b[0] = n/a[0]+1;
	//for(i=1;i<5;i++) {
	for(i=4;i<5;i++) {
		long int min = a[i];
		int j;
		for(j=0;j<=i;j++) {
			if(min > a[j]) min = a[j];
		}
		b[i] = i + n/min + ((n%min!=0)?1:0);
	}

	printf("%ld", b[4]);
	
	return 0;
}


Measured memory_bytes: 128