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

int main() {
  int a,b;cin>>a>>b;
  if(a>0) {
    cout<<"Positive"<<endl;
    return 0;
  }
  // a<=0
  if(b>=0){
    cout<<"Zero"<<endl;
    return 0;
  }
  // b<=0
  int64_t diff=b-a;
  if(diff%2==1) cout<<"Positive"<<endl;
  else cout<<"Negative"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define st first
#define nd second

using namespace std;

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"

const int N = 1450;
int n, b[N], ans;

int main() {
	ios_base::sync_with_stdio(false);
	cin >> n;
	for(int i = 1; i < n; i++) 
		cin >> b[i];
	b[0] = b[n] = 1e9;
	for(int i = 1; i <= n; i++) {
		ans += min(b[i], b[i - 1]);
	}
	cout << ans << '\n';
}	

	

Measured memory_bytes: 256
INT_MAX=10**18+7
MOD=10**9+7
def INPUT():return list(int(i) for i in input().split())
def LIST_1D_ARRAY(n):return [0 for _ in range(n)]
def LIST_2D_ARRAY(m,n):return [[0 for _ in range(n)]for _ in range(m)]
#################################################################################
n,m=INPUT()
A=INPUT()
A.sort(reverse=True)
votes=0
for i in range(n):
    votes+=A[i]
limit=votes/(4*m)
count=0
for i in range(m):
    if A[i]<limit:
        break
    else:
        count+=1
if count!=m:
    print("No")
else:
    print("Yes")


Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  string s;
  cin>>n>>s;
  vector<int> e(n+1,0);
  for(int i=0;i<n;i++)
    e.at(i+1)=e.at(i)+(s.at(i)=='E'?1:0);
  int m=s.size();
  for(int i=0;i<n;i++)
    m=min(m,(i-e.at(i))+(e.at(n)-e.at(i+1)));
  cout<<m<<endl;
}

Measured memory_bytes: 1796
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ in >> p.first >> p.second; return in; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, c;
    cin >> n >> c;
    vector<vector<int>> ds(c, vector<int>(c)), cs(n, vector<int>(n));
    vector<vector<int>> memo(3, vector<int>(c));
    cin >> ds >> cs;
    auto calc = [&](int num, int b){ 
        if(memo[num][b]){ return memo[num][b]; }
        int cand = 0;
        for(int y = 0; y < n; y++){
            for(int x = 0; x < n; x++){
                if((x + y) % 3 != num){ continue; }
                cand += ds[cs[y][x] - 1][b];
            }
        }
        return memo[num][b] = cand;
    };
    int ans = M;
    for(int i = 0; i < c; i++){
        for(int j = 0; j < c; j++){
            for(int k = 0; k < c; k++){
                if(i == j || i == k || j == k){ continue; }
                // int cand = 0;
                // for(int y = 0; y < n; y++){
                //     for(int x = 0; x < n; x++){
                //         cand += ds[cs[y][x] - 1][(x + y) % 3 == 0 ? i : (x + y) % 3 == 1 ? j : k];
                //     }
                // }
                // ans = min(ans, cand);
                int cand = calc(0, i) + calc(1, j) + calc(2, k);
                ans = min(ans, cand);
            }
        }
    }
    cout << ans << '\n';
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#include <ext/hash_map>
#include <ext/numeric>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define REP(i,n) for( (i)=0 ; (i)<(n) ; (i)++ )
#define rep(i,x,n) for( (i)=(x) ; (i)<(n) ; (i)++ )
#define REV(i,n) for( (i)=(n) ; (i)>=0 ; (i)-- )
#define FORIT(it,x) for( (it)=(x).begin() ; (it)!=(x).end() ; (it)++ )
#define foreach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define rforeach(it,c) for(__typeof((c).rbegin()) it=(c).rbegin();it!=(c).rend();++it)
#define foreach2d(i, j, v) foreach(i,v) foreach(j,*i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define SZ(x) ((int)(x).size())
#define MMS(x,n) memset(x,n,sizeof(x))
#define mms(x,n,s) memset(x,n,sizeof(x)*s)
#define pb push_back
#define mp make_pair
#define NX next_permutation
#define UN(x) sort(all(x)),x.erase(unique(all(x)),x.end())
#define CV(x,n) count(all(x),(n))
#define FIND(x,n) find(all(x),(n))-(x).begin()
#define ACC(x) accumulate(all(x),0)
#define PPC(x) __builtin_popcountll(x)
#define LZ(x) __builtin_clz(x)
#define TZ(x) __builtin_ctz(x)
#define mxe(x) *max_element(all(x))
#define mne(x) *min_element(all(x))
#define low(x,i) lower_bound(all(x),i)
#define upp(x,i) upper_bound(all(x),i)
#define NXPOW2(x) (1ll << ((int)log2(x)+1))
#define PR(x) cout << #x << " = " << (x) << endl ;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int OO = (int) 2e9;
const double eps = 1e-9;

int main() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
//	freopen("in.txt", "rt", stdin);
//	freopen("out.txt", "wt", stdout);
#endif
	ll n, d, res = 0;
	cin >> n >> d;
	for (int i = 0; i < n; i++) {
		ll x, y;
		cin >> x >> y;
		if (x * x + y * y <= d * d)
			res++;
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
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; }

const int mod = 1000000007;
struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    
    // for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    ll n;
    cin>>n;

    map<ll, mint> mp;
    rep(i, n) {
        int m = i + 1;
        for (int j = 2; j * j <= m; ++j) {
            while (m % j == 0) {
                mp[j] += 1;
                m /= j;
            }
        }
        if (m != 1) mp[m] += 1;
    }
    mint ans = 1;
    for (auto v : mp) {
        ans *= (v.second + 1);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array)/sizeof(array[0]))
#define DEBUG 0 
#define LIMIT (LONG_MAX / 10)
#define POSITIVE_LAST_D (LONG_MAX % 10)
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;

int main(){
    string s,t;
    cin>>s>>t;
    int cnt=0;
    int len=s.size();
    rep(i,len){
        if(s[i]!=t[i])cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 3828
def f(i, k):
    if i == n and k == 0:
        global d
        hr1, hb1 = 0, 0
        hr2, hb2 = 0, 0
        cntr, cntb = 0, 0
        for j in range(n):
            if c[j]:
                hr1 += x[j] * powb1[cntr]
                hr2 += x[j] * powb2[cntr]
                hr1 %= mod
                hr2 %= mod
                cntr += 1
            else:
                hb1 += x[j] * powb1[cntb]
                hb2 += x[j] * powb2[cntb]
                hb1 %= mod
                hb2 %= mod
                cntb += 1
        if min(cntr, cntb) == 0:
            return
        if (hr1, hr2, hb1, hb2) in d:
            d[(hr1, hr2, hb1, hb2)] += 1
        else:
            d[(hr1, hr2, hb1, hb2)] = 1
        return
    elif i == n and k == 1:
        hr1, hb1 = 0, 0
        hr2, hb2 = 0, 0
        cntr, cntb = 0, 0
        for j in range(n):
            if c[j]:
                hr1 += y[j] * powb1[cntr]
                hr2 += y[j] * powb2[cntr]
                hr1 %= mod
                hr2 %= mod
                cntr += 1
            else:
                hb1 += y[j] * powb1[cntb]
                hb2 += y[j] * powb2[cntb]
                hb1 %= mod
                hb2 %= mod
                cntb += 1
        if min(cntr, cntb) == 0:
            return
        if (hr1, hr2, hb1, hb2) in d:
            global ans
            ans += d[(hr1, hr2, hb1, hb2)]
        return
    c[i] = 1
    f(i + 1, k)
    c[i] = 0
    f(i + 1, k)


n = int(input())
s = list(input())
mod = pow(2, 31) - 1
b1, b2 = 27, 31
powb1 = [pow(27, i, mod) for i in range(n)]
powb2 = [pow(31, i, mod) for i in range(n)]
d = {}
x, y = [], []
for i in range(n):
    x.append(ord(s[i]) - 96)
    y.append(ord(s[-(i + 1)]) - 96)
ans = 0 if not x == y else 2
c = [0] * n
f(0, 0)
c = [0] * n
f(0, 1)
print(ans)

Measured memory_bytes: 163104
MOD = 1_000_000_007

class Array
	def &(a)
		t1, f1 = self
		t2, f2 = a
		[t1 * t2 % MOD, (t1 * f2 + f1 * t2 + f1 * f2) % MOD]
	end

	def |(a)
		t1, f1 = self
		t2, f2 = a
		[(t1 * t2 + t1 * f2 + f1 * t2) % MOD, f1 * f2 % MOD]
	end

	def ~@
		reverse	
	end
end

e = ?( + gets.chomp + ?)
0 while e.gsub!("~~", "")
0 while e.gsub!("~x", "x")

rev_polish = []
op_stack = []
e.scan(/~?\(|\)|~|&|\||x\d+/) do |token|
	case token
	when /~?\(/
		op_stack << token
	when ?)
		loop do
			op = op_stack.pop
			if op == "~("
				rev_polish << ?~
				break
			elsif op == ?(
				break
			else
				rev_polish << op
			end
		end
	when ?&
		op_stack << token
	when ?|
		while op_stack[-1] == ?&
			rev_polish << op_stack.pop
		end
		op_stack << token
	else
		rev_polish << ?x
	end
end

stack = []
rev_polish.each do |x|
	if x == ?x
		stack << [1, 1]
	elsif x == ?~
		stack << ~stack.pop
	else
		stack << stack.pop.send(x, stack.pop)
	end
end

p stack[0][0]

Measured memory_bytes: 80440
#include <iostream>
using namespace std;
int main(void){
   int A,B,T;
   cin>>A>>B;
   if(A==B){
       T=A+A;
   }else{
       T=max(A,B);
       T=T+T-1;
   } 
   cout<<T<<endl;
   return 0;
}

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

int main()
{
    string s, t;
    cin >> s >> t;
    int i = 0;
    if(s == t){
        cout << "Yes" << endl;
    }
    else{
        while(i<s.size()){
            s = s.back() + s.substr(0, s.size()-1);
            if(s == t){
                cout << "Yes" << endl;
                break;
            }
            i++;
        }
    }
    if(i == s.size()){
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

#include <algorithm>
#include <cmath>
#include<string>
#include<array>
#include<vector>
#include<functional>
#include<unordered_map>
#include<map>
#include<numeric>
#include<limits>
#include<utility>
#include<queue>
#include<random>

using namespace std;
typedef long long LL;

int main() {
	int a;
	
	int A, B;

	LL N,ans=0;

	cin >> N;
	A = N / 10;
	B = N % 10;

	if (A == 9 || B == 9) {
	
		cout << "Yes" << endl;
	
	}
	else {
	
		cout << "No" << endl;

	}

	//cin >> a;
	return 0;
}

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


int main(){
	int a,b,c;
	stack<int> sta;
	string s,t;
	getline(cin,s);
	for(int i = 0;i < s.size();i++){
		if(s[i] == '+'){
			a = sta.top();
			sta.pop();
			b = sta.top();
			sta.pop();
			c = a + b;
			sta.push(c);
		}
		else if(s[i] == '-'){
			a = sta.top();
			sta.pop();
			b = sta.top();
			sta.pop();
			c = b - a;
			sta.push(c);
		}
		else if(s[i] == '*'){
			a = sta.top();
			sta.pop();
			b = sta.top();
			sta.pop();
			c = a * b;
			sta.push(c);
		}
		else if(s[i] == ' ')continue;
		else{
			string t = "";
			for(;i < s.size();i++){
				t += s[i];
				if(i == s.size()-1){
					break;
				}
				if(s[i+1] == ' '){
					break;
				}
			}
			a = atoi(t.c_str());
			sta.push(a);
		}
	}
	cout << sta.top() << endl;

	return 0;
}

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

using namespace std;

#define ll long long
#define pi pair<int, int>
#define pb push_back
#define fr first
#define sc second
#define endl '\n'

const int mxn = 1e6 + 5;
const ll MOD =  1e9 + 7;
int arr[mxn];
int n, m, k, q;
string s, t;

void solve() {
    int ans = mxn;
    cin >> s >> t;
    for (int i = 0; i < s.size() - t.size() + 1; i++) {
        int curr = 0;
        for (int j = 0; j < t.size(); j++) curr += (s[i + j] != t[j]);
        ans = min(ans, curr);
    }
    cout << ans << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int T = 1;
    //cin >> T;
    while(T--) solve();
    return 0;
}


Measured memory_bytes: 3532
#include <iostream>

using namespace std;

//int m,f,r;
//int ans = 0;

int main()
{
	while(1)
	{
		int ans = 0;
		int m = 0,f = 0,r = 0;

		cin >> m >> f >> r;

		if(m == -1 && f == -1 && r == -1)
		{
			break;
		}
		
		if(f == -1 || m == -1)
		{
			cout << "F" << endl;
			continue;
		}

		else
			ans += m;
			ans += f;

		if(ans >= 80)
		{
			cout << "A" << endl;
		}
		else if(ans < 80 && ans >= 65)
			{
				cout << "B" << endl;
			}
			else if(ans >= 50 && ans < 65 || r >= 50)
			{
				cout << "C" << endl;
			}
			else if(ans < 50 && ans >= 30)
			{
				cout << "D" << endl;
			}

			else if(ans < 30)
			{
				cout << "F" << endl;
			}
	}

	return 0;
}

Measured memory_bytes: 1152
MOD = 1000000007
h, w, k = map(int, input().split())

dp = [[0 for _ in range(w)] for _ in range(h+1)]
dp[0][0] = 1

if w == 1:
    print(1)
    exit()

for y in range(1, h+1):
    for i in range(2 ** (w-1)):
        bin_i = str(bin(i))[2:]
        if '11' in bin_i:
            continue
        for j in range(1, w):
            if ((i >> j-1) & 1):
                dp[y][j] += dp[y-1][j-1]
        for j in range(w-1):
            if ((i >> j) & 1):
                dp[y][j] += dp[y-1][j+1]
        for j in range(w):
            f = True
            if j < w:
                f = f and not ((i >> j) & 1)
            if j - 1 >= 0:
                f = f and not ((i >> j-1) & 1)
            if f:
                dp[y][j] += dp[y-1][j]
        for i in range(w):
            dp[y][i] %= MOD
# print(dp)
print(dp[h][k-1])

Measured memory_bytes: 42992
#include <bits/stdc++.h>
//#pragma GCC optimize "-O3"
typedef unsigned long long ull;
typedef unsigned int ui;
typedef unsigned short us;
typedef long long ll;
typedef long double ld;
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll infll=(1ull<<63)-1;
const int inf=(1ull<<31)-1;
string b;
int s=0;

int main()
{
	//freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);cout.precision(15);
	cin>>s>>b;
	s=0;
	for (int i=0;i+2<b.size();i++){
		if (b[i]=='A'&&b[i+1]=='B'&&b[i+2]=='C')
			s++;
	}
	cout<<s;
	return 0;
}

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

int main() {
  int N;
  int f = 0;
  cin >> N;
  int n = N;
  
  for (int i = 0; i < 9; i++) {
    f = f + ( n % 10 );
    n /= 10;
  }
  
  if (N % f == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

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

int by(int x){
  int counter = 0;
  while(x%2 == 0){
    counter ++;
    x /= 2;
  }
  return counter;
}

int main(){
  int N;
  cin >> N;
  int ans = 0;
  int num = 0;
  for(int i=N;i>0;i--){
    if(ans<=by(i)){
      ans = by(i);
      num = i;
    }
  }
  cout << num << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
#define Mod 1000000007
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
#define INF 1000000000000
 
 
 
struct edge{ll from,to,cost; };
edge es[5050];
ll d[2525];
ll V,E;
 
ll ttt=0;
 
void bellmanford(ll s){
    for(ll i=0;i<V;i++) d[i]=INF;
    d[s]=0;
    ll cnt=0;
    while(true){
        bool update=false;
        cnt++;
        for(int i=0;i<E;i++){
            edge e=es[i];
            if(d[e.from]!=INF && d[e.to]>d[e.from]+e.cost){
                d[e.to]=d[e.from]+e.cost;
                update=true;
                if(cnt>V) {
                    d[e.to]=-INF;
                    if(e.to==V-1) {
                        cout<<-1<<endl;
                        ttt=-1;
                        return;
                    }
                }
                if(cnt>3*V) return;
            }
        }
        if(!update) break;
    }
}
 
int main(){
    ll i,j;
    ll n,m,p;
    cin>>n>>m>>p;
    V=n;
    E=m;
 
    for(i=0;i<m;i++){
        ll a,b,c;
        cin>>a>>b>>c;
        a--;
        b--;
        es[i]={a,b,p-c};
    }
    bellmanford(0);
    
    if(ttt!=-1) cout<<max(0ll,-d[n-1])<<endl;
 
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <stdio.h>
#include <cctype>
using namespace std;

int main () {
  char ch;
  while (true) {
    scanf("%c", &ch);
    if (islower(ch)) {
      cout << (char) toupper(ch);
    } else if (isupper(ch)) {
      cout << (char) tolower(ch);
    } else if (ch == '\n') {
      cout << endl;
      break;
    } else {
      cout << ch;
    }
  }
}

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

#define REP(i, s,  n) for(int i = s;i < (n);i++)
#define VSORT(v) sort(v.begin(), v.end());
#define int64 long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;

typedef pair<int, int> P;
typedef pair<int, P> PP;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

//---------------------------------------------------------------
//---------------------------------------------------------------

int N, Y;

signed main(){
	cin >> N >> Y;
	
	int wk, j, k, m;
	if(Y <= (10000 * 2000) && Y % 1000 == 0) {
		REP(i, 0, (N+1)) {                          		// 千円
			wk = Y - i * 1000;
			if(wk % 5000 != 0)			continue;
			if(wk > (N - i) * 10000)	continue;
			m = wk / 10000;
			j = m - (N - i - m) + (wk - m * 10000) / 5000;  // 一万円
			k = N - i - j;                          		// 五千円
			if(j >= 0 && k >= 0 && (Y == (i * 1000 + j * 10000 + k * 5000))) {
				cout << j << " " << k << " " << i << endl;;
				return 0;
			}
		}
	}
	cout << "-1 -1 -1" << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int N;
  cin >> N;
  vector<int> a(N);
  vector<int> b(N);
  for(int c = 1;c < N;c++){
   cin >> a.at(c) ;
    b.at(a.at(c) - 1) += 1;
  }
  for(int c = 0;c < N;c++){
   cout << b.at(c) << endl; 
  }
}

Measured memory_bytes: 4840
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <vector>
using namespace std;

int main(){
  int n; cin>>n;
  int d[n];
  int ans=0;
  for(int i=0;i<n;i++) cin>>d[i];
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      if(i!=j){
        ans+=d[i]*d[j];
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;


public class Main {
	public static void main(String[] args) throws IOException {
		long l = System.currentTimeMillis();
		new Main().exec();
		long l2 = System.currentTimeMillis();
/*
		System.out.println((l2-l)+"msec");
//*/		
	}
	
	public void exec() throws IOException {
		InputUtil in = new InputUtil();
		OutputUtil out = new OutputUtil();
		int n = in.nextInt();
		int[] A = in.nextInt(new int[n]);
		int[] B = new int[n];
		countingSort(A,B,10000);
		out.outputDivSpace(B);
	}
	
	private void countingSort(int[] A, int[] B, int k) {
		int[] C = new int[k+1];
		int n = A.length;
		Arrays.fill(C, 0);
		int max = 0;
		for (int i=0; i<n; i++) {
			C[A[i]]++;
			max = (max<A[i]) ? A[i] : max;
		}
		
		for(int i=1; i<=max; i++) {
			C[i] += C[i-1];
		}
		
		for(int i=n-1; i>=0; i--) {
			B[--C[A[i]]] = A[i];
		}
		
		
	}
}

class InputUtil {
	//Static Fields
	private static final int BUFSIZ = 12000000;
	
	//Fields
	protected InputStream in;
	private char[] buf = null;
	private int ptr = 0;
	private int max = -1;
	private BufferedReader br = null;
	
	//Constructors
	public InputUtil() {this(System.in,BUFSIZ);}
	public InputUtil(InputStream in, int bufsiz) {
		initBuf(bufsiz);
		initIn(in);
	}
	
	//Methods
	//Initializer
	protected void initIn(InputStream in) {br = new BufferedReader(new InputStreamReader(this.in = in));}
	protected void initBuf(int bufsiz) {buf = new char[bufsiz];}
	
	//buffer operation
	private boolean next() throws IOException {ptr++; return readBuf();}
	private boolean readBuf() throws IOException {
		if(ptr >= max && br.ready()) {
			max = br.read(buf);
			ptr = 0;
		}
		return (max>0);
	}
	
	//Number Input Reader/Parser
	private boolean isNum(char b) {return '0' <= b && b <= '9'; }
	private boolean isMinus(char b) {return b=='-'; }

	private int _nextInt() throws IOException {
		int sign = 1;
		int res = 0;
		char c = buf[ptr];
		while (!isNum(c=buf[ptr]) && !isMinus(c)) 
			if(!next()) throw new IllegalStateException();
		if (isMinus(c)) {
			sign = -1;
			if(!next()) throw new IllegalStateException();
		}
		while (isNum(c=buf[ptr])) {
			res *= 10;
			res += c - '0' ;
			if(!next())
				break;
		}
		next();
		return sign * res;
	}
	
	public int nextInt() throws IOException {
		if(!readBuf()) throw new IllegalStateException();
		return _nextInt();
	}

	public int[] nextInt(int[] result) throws IOException {
		if(!readBuf()) throw new IllegalStateException();
		for(int i=0; i<result.length; i++) {
			result[i] = _nextInt();
		}
		return result;
	}
	
	//Close 
	public void close() throws IOException {
		if(!this.in.equals(System.in)) 
			this.in.close();
	}

}

class OutputUtil {
	PrintWriter out = new PrintWriter(System.out);

	public void outputDivSpace(int[] a) {
		output(a,0,a.length," ");
	}

	public void output(int[] a, int off, int len, String delim) {
		out.print(a[off]);
		for(int i=off+1; i<len; i++){
			out.print(delim);
			out.print(a[i]);
		}
		out.println("");
		out.flush();
	}
}

Measured memory_bytes: 131080
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <set>

using namespace std;
using ll = long long;

typedef pair<ll, ll> P;

const int MOD = 1000000007;
const ll INF = 1LL << 60;


// LRUD
const int dx[4] = {-1, 1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
// const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
// const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

vector<vector<int> > vvi;
vector<vector<vector<int> > > vvvi;

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

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }

// bool pairCompare(const P& firstElof, const P& secondElof){
//     return firstElof.first > secondElof.first;
// }

struct sort_pred {
    bool operator()(const P &left, const P &right) {
        return left.first < right.first;
    }
};

int main(int argc, char**argv){
    int n, m;
    cin >> n >> m;
    vector<ll> a(n);
    for (int i = 0; i < n; i++){
        cin >> a[i];
    }
    vector<pair<ll, ll> > cb;
    ll b, c;
    for (int i = 0; i < m; i++){
        cin >> b >> c;
        cb.push_back(make_pair(c, b));
    }
    for (int i = 0; i < n; i++){
        cb.push_back(make_pair(a[i], 1));
    }

    // sort(cb.begin(), cb.end());
    sort(cb.begin(), cb.end(), sort_pred());

    ll ans = 0;
    int cb_idx = n + m - 1;
    for (int i = 0; i < n; i++){
        if (cb[cb_idx].second == 0){
            cb_idx--;
        }
        ans += cb[cb_idx].first;
        cb[cb_idx].second--;
    }

    cout << ans << endl;

    return 0;
}
















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

int main() {
  int N;
  cin >> N;
  bool ok = false;
  if (N / 100 == 7) {
    ok = true;
  }
  if ((N % 100) / 10 == 7) {
    ok = true;
  }
  if (N % 10 == 7) {
    ok = true;
  }
  if (ok) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}
  


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

int main() {
    ll H,W,ch,cw,dh,dw;
    cin >> H >> W >> ch >> cw >> dh >> dw;
    ch--;cw--;dh--;dw--;
    vector<string>field(H);
    for(ll i=0;i<H;i++){
        cin >> field[i];
    }

    deque<pair<ll,ll>>Q;
    ll cost[1020][1020];
    for(ll i=0;i<1020;i++){
        for(ll j=0;j<1020;j++){
            cost[i][j]=MOD;
        }
    }
    cost[ch][cw]=0;
    Q.push_front({ch,cw});
    while(!Q.empty()){
        pair<ll,ll>t=Q.front();
        Q.pop_front();
        ll i=t.first,j=t.second;
        for(ll k=0;k<4;k++){
            ll x=i+dx[k],y=j+dy[k];
            if(x<0||x>=H)continue;
            if(y<0||y>=W)continue;
            if(field[x][y]=='#') continue;
            if(cost[x][y]<=cost[i][j]) continue;
            Q.push_front({x,y});
            cost[x][y]=cost[i][j];
        }
        for(ll k=-2;k<=2;k++){
            for(ll l=-2;l<=2;l++){
                ll x=i+k,y=j+l;
                if(x<0||x>=H)continue;
                if(y<0||y>=W)continue;
                if(field[x][y]=='#') continue;
                if(cost[x][y]<=cost[i][j]+1) continue;
                Q.push_back({x,y});
                cost[x][y]=cost[i][j]+1;
            }
        }
    }
    if(cost[dh][dw]==MOD){
        cout << -1 << endl;
    }
    else {
        cout << cost[dh][dw] << endl;
    }
}


Measured memory_bytes: 13820
#include<stdio.h>
#include<string.h>
 
#define HEAP_SIZE 2000000
long int heap[HEAP_SIZE+1];
int heap_size;
 
void maxHeapify(long int heap[], int i)
{
    int l = i * 2;
    int r = i * 2 + 1;
    int largest;
    long int w;
 
    if((l <= heap_size) && (heap[l] > heap[i])){
        largest = l;
    }else{
        largest = i;
    }
    if((r <= heap_size) && (heap[r] > heap[largest])){
        largest = r;
    }
    if(largest != i){
        w = heap[i];
        heap[i] = heap[largest];
        heap[largest] = w;
        maxHeapify(heap, largest);
    }
 
    return;
}
 
void heapIncreaseKey(long int heap[], int i, long int key)
{
    int w;
    if(key < heap[i]){
        return;
    }
    heap[i] = key;
    while(i > 1 && heap[i / 2] < heap[i]){
        w = heap[i / 2];
        heap[i / 2] = heap[i];
        heap[i] = w;
        i = i / 2;
    }
    return;
}
 
void maxHeapInsert(long int heap[], long int key)
{
    heap_size = heap_size + 1;
    heap[heap_size] = -1;
    heapIncreaseKey(heap, heap_size, key);
    return;
}
 
long int heapExtractMax(long int heap[])
{
    long int max;
    if(heap_size < 1){
        return(-1);
    }
    max = heap[1];
    heap[1] = heap[heap_size];
    heap_size = heap_size - 1;
    maxHeapify(heap, 1);
    return(max);
}
 
int main()
{
    char cmd[30];
    long int key;
 
    do{
        scanf("%s", cmd);
        if(strcmp("insert", cmd) == 0){
            scanf("%ld", &key);
            maxHeapInsert(heap, key);
        }else if(strcmp("extract", cmd) == 0){
            printf("%ld\n", heapExtractMax(heap));
        }
    }while(strcmp("end", cmd) != 0);
 
    return(0);
}

Measured memory_bytes: 8792
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <utility>
#include <functional>

using namespace std;

typedef pair<int, int> P;

int main() {
	int n;

	while (cin >> n && n != 0) {
		P s[100010];
		int go, k = 1, ans = 0;

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

			if (i == 1) {
				s[k++] = P(i, go);
				continue;
			}

			if (s[k - 1].second != go) {
				if (i % 2) {//?\???°
					s[k++] = P(i, go);
				}
				else {
					if (k == 2)
						s[k - 1].second = go;
					else
						k--;
				}
			}
		}

		s[k] = P(n + 1, 0);
		for (int i = 1; i < k; ++i) {
			if (s[i].second == 0)
				ans += s[i + 1].first - s[i].first;
		}

		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 3764
#include <bits/stdc++.h>
// #include <atcoder/all>
// using namespace atcoder;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << "\n"
#define COUTF(x) cout << setprecision(15) << (x) << "\n"
#define ENDL cout << "\n"
#define DF(x) x.erase(x.begin())
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define RSORT(x) sort(x.rbegin(), x.rend())
#define REVERSE(x) reverse(ALL(x))
#define MAX(x) *max_element(ALL(x))
#define MAXI(x) max_element(ALL(x)) - x.begin()
#define SUM(x) accumulate(ALL(x), 0ll)
#define COUNT(x, y) count(ALL(x), y);
#define ANS cout << ans << "\n"
#define YES cout << "YES\n";
#define NO cout << "NO\n";
#define Yes cout << "Yes\n";
#define No cout << "No\n";
#define YN YES else NO
#define yn Yes else No
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define LINE cerr << "[debug] line: " << __LINE__ << "\n";
#define debug(x) cerr << "[debug] " << #x << ": " << x << "\n";
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(z, v.size()) cerr << " " << v[z]; \
  cerr << "\n";
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;
using vp = vector<P>;
using vs = vector<string>;

template <typename T>
inline istream& operator>>(istream& i, vector<T>& v) {
  rep(j, v.size()) i >> v[j];
  return i;
}

template <typename T1, typename T2>
inline istream& operator>>(istream& i, pair<T1, T2>& v) {
  return i >> v.first >> v.second;
}

constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

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

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

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

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

signed main() {
  init();
  ll T1, T2, A1, A2, B1, B2;
  cin >> T1 >> T2 >> A1 >> A2 >> B1 >> B2;

  if (A1 > B1) {
    swap(A1, B1);
    swap(A2, B2);
  }

  if (A2 < B2) {
    COUT(0);
    return 0;
  }

  if (A1 * T1 + A2 * T2 < B1 * T1 + B2 * T2) {
    COUT(0);
    return 0;
  }

  if (A1 * T1 + A2 * T2 == B1 * T1 + B2 * T2) {
    COUT("infinity");
    return 0;
  }

  ll a = B1 * T1 - A1 * T1;
  ll b = (A1 * T1 + A2 * T2) - (B1 * T1 + B2 * T2);
  ll ans = 2 * (a / b);
  if (a % b == 0)
    ANS;
  else
    COUT(ans + 1);

  return 0;
}

Measured memory_bytes: 3656
h,w = map(int, input().split())
grid = [list(input()) for _ in range(h)]
dpgrid = [[0]*w for _ in range(h)]
for i in range(h):
    for j in range(w):
        d = 1 if grid[i][j] == "#" else 0
        if (i == 0) & (j == 0):
            dpgrid[i][j] = d
        elif (i == 0):
            a = 1 if (grid[i][j-1] == ".") & (d == 1) else 0
            dpgrid[i][j] = a + dpgrid[i][j-1]
        elif (j == 0):
            b = 1 if (grid[i-1][j] == ".") & (d == 1) else 0
            dpgrid[i][j] = b + dpgrid[i-1][j]
        else:
            a = 1 if (grid[i][j-1] == ".") & (d == 1) else 0
            b = 1 if (grid[i-1][j] == ".") & (d == 1) else 0
            dpgrid[i][j] = min(a + dpgrid[i][j-1], b + dpgrid[i-1][j])
print(dpgrid[h-1][w-1])

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

N,K=map(int,input().split())
P=list(map(int,input().split()))
C=list(map(int,input().split()))

for i in range(N):
    P[i]-=1

USE=[0]*N
ANS=-1<<100
for i in range(N):
    if USE[i]==1:
        continue
    else:
        USE[i]=1
        A=[C[P[i]]]
        NOW=P[i]

        while NOW!=i:
            USE[NOW]=1
            A.append(C[P[NOW]])
            NOW=P[NOW]
            
        #print(A,NOW)

        S=sum(A)
        SCORE=0
        if S>0:
            SCORE=S*(K//len(A))
            rest=K%len(A)

            A2=A+A+A
            S2=[0]
            for a in A2:
                S2.append(S2[-1]+a)

            restscore=-1<<100

            for i in range(len(A)):
                for j in range(i+1,i+rest+1):
                    #print(i,j,S2[j]-S2[i])
                    restscore=max(restscore,S2[j]-S2[i])

            #print(S2,rest,SCORE,restscore)

            ANS=max(ANS,SCORE+restscore)

            if K//len(A)>=1:
                SCORE=S*(K//len(A) - 1)
                rest=len(A)

                restscore=-1<<100

                for i in range(len(A)):
                    for j in range(i+1,i+rest+1):
                        #print(i,j,S2[j]-S2[i])
                        restscore=max(restscore,S2[j]-S2[i])

                #print(S2,rest,SCORE,restscore)

                ANS=max(ANS,SCORE+restscore)
                
        else:
            SCORE=0
            rest=min(K,len(A))

            A2=A+A+A
            S2=[0]
            for a in A2:
                S2.append(S2[-1]+a)

            restscore=-1<<100

            for i in range(len(A)):
                for j in range(i+1,i+rest+1):
                    #print(i,j,S2[j]-S2[i])
                    restscore=max(restscore,S2[j]-S2[i])

            #print(S2,rest,SCORE,restscore)

            ANS=max(ANS,SCORE+restscore)
print(ANS)
        


Measured memory_bytes: 69472
#include"bits/stdc++.h"

using namespace std;

char gc(){
	static const int L=(1<<19)+1;
	static char ibuf[L],*iS,*iT;
	if(iS==iT){
		iT=(iS=ibuf)+fread(ibuf,1,L,stdin);
		return iS==iT?EOF:*iS++;
	}
	return*iS++;
}
template<class I>void gi(I&x){
	static char c;static int f;
	for(f=1,c=gc();c<'0'||c>'9';c=gc())if(c=='-')f=-1;
	for(x=0;c<='9'&&c>='0';c=gc())x=x*10+(c&15);x*=f;
}

const int N=200005,P=1E9+7;
typedef long long ll;

struct peo{
	int x,v;
	peo(){}
	peo(int _x,int _v){x=_x,v=_v;}
}p[N];
bool cmpx(const peo &a,const peo &b){return a.x<b.x;}
bool cmpv(const int &a,const int &b){return p[a].v<p[b].v;}
bool cmp(const int &a,const int &b){return a>b;}
int MAX(const int &a,const int &b){if(!a||!b)return a|b;return cmpv(a,b)?b:a;}
int MIN(const int &a,const int &b){if(!a||!b)return a|b;return cmpv(a,b)?a:b;}

int n,pw2[N],mxv[N],mnv[N],id[N],rev[N],dp[N],sum[N];
vector<int>link[N];

int main(){
	gi(n);pw2[0]=1;
	for(int i=1;i<=n;i++)gi(p[i].x),gi(p[i].v),id[i]=i,pw2[i]=(pw2[i-1]<<1)%P;
	sort(p+1,p+n+1,cmpx),sort(id+1,id+n+1,cmpv);
	for(int i=1;i<=n;i++)rev[id[i]]=i;
	for(int i=1;i<=n;i++)mxv[i]=MAX(mxv[i-1],i);
	for(int i=n;i;i--)mnv[i]=MIN(mnv[i+1],i);
	for(int i=1;i<=n;i++)link[rev[mxv[i]]].push_back(rev[mnv[i]]);
	for(int i=*sum=1,j,l,k;i<=n;i++){
		sort(link[i].begin(),link[i].end(),cmp);
		int &w=dp[i],p;
		for(j=0,l=link[i].size();j<l;){
			for(p=link[i][j],j++,k=1;j<l&&link[i][j]==link[i][j-1];j++,k++);
			w=(w+(ll)pw2[j-k]*(pw2[k]-1)%P*(sum[i-1]-(p>1?sum[p-2]:0)))%P;
		}
		sum[i]=(sum[i-1]+w)%P;
	}
	if(dp[n]<0)dp[n]+=P;
	cout<<dp[n]<<endl;
	return 0;
}

Measured memory_bytes: 18688
#include <bits/stdc++.h>
using namespace std;
#define print printf("==================\n")
#define ll long long
#define pi acos(-1.0)
#define eps 1e-16
#define max3(a,b,c) max(a,max(b,c))
const ll INF = 1 << 30;
#define mod 1000000007
typedef pair<double, double  > payar;
typedef struct
{
    ll  x, y;
} point;
priority_queue<payar, vector<payar>,  greater<payar> > pq; ///accending
vector< pair<double,payar  > > vpp;
vector < payar >  vp;
double  ara[3000];
double  dp[3000][3000];
int n, m ;
double cal(int i, int cnt,double pro )
{



    if(n+1==i)
    {
        if( cnt> ( n-cnt) )
        {
            return 1.0;
        }
        else
        {
            return 0.0;
        }
    }
    double &ret = dp[i][cnt];
    if(ret!=-1.0)
    {
       return ret;
    }
    ret = ara[i]* cal(i+1,cnt+1,0) + (1.0-ara[i])*cal(i+1,cnt,0 );///head taken
    return ret;
}
int main()
{


    // int n ;
    for(int i = 0 ; i<3000; i++)
    {
        for(int j = 0 ; j<3000; j++)
        {
            dp[i][j]=-1.0;
        }
    }
    cin>>n;
    for(int i  = 1 ; i<=n ; i++)
    {
        cin>>ara[i];
    }
    cout<<setprecision(15);
    cout<<cal(1,0,1.0);
    return  0 ;
}


Measured memory_bytes: 70784
# -*- coding: utf-8 -*-
# from operator import mul
# from functools import reduce
# import itertools

# def combinations_count(n, r):
#     r = min(r, n - r)
#     numer = reduce(mul, range(n, n - r, -1), 1)
#     denom = reduce(mul, range(1, r + 1), 1)
#     return numer // denom

# def combinations_with_replacement_count(n, r):
#     return combinations_count(n + r - 1, r)

N = int(input())
D_list = list(map(int, input().split()))

def get_answer(len_target_list, target_list):
    pattern_dic = {}
    ans = 1
    if D_list[0] != 0:
        return 0
    else:
        for i in range(1, N):
            if D_list[i] == 0:
                return 0
            pattern_dic[D_list[i]] = pattern_dic.get(D_list[i], 0) + 1
        if 1 in pattern_dic:
            before_num = pattern_dic[1]
            for j in range(2, max(pattern_dic.keys()) + 1):
                if j in pattern_dic:
                    ans = (ans * (before_num ** pattern_dic[j])) % 998244353
                    before_num = pattern_dic[j]
                else:
                    return 0
            else:
                return ans
        else:
            return 0        

print(get_answer(N, D_list))

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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

typedef long long ll;
typedef pair<int, int> ii;

int main() {

	ll n;
	cin >> n;
	vector<ll> a(3*n);
	rep(i, 3*n) cin >> a[i];

	vector<ll> val(3*n);

	priority_queue<ll, vector<ll>, greater<ll>> qu1;
	priority_queue<ll> qu2;

	ll sum = 0;
	rep(i, n){
		sum += a[i];
		qu1.push(a[i]);
	}
	val[n-1] = sum;
	REP(i, n, 2*n){
		ll tmp = qu1.top();
		if(tmp < a[i]){
			sum += (a[i] - tmp);
			qu1.pop();
			qu1.push(a[i]);
		}
		val[i] = sum;
	}

	sum = 0;
	rep(i, n){
		sum += a[3*n - 1 - i];
		qu2.push(a[3*n - 1 - i]);
	}
	ll ans = val[2*n-1] - sum;
	REP(i, n, 2*n){
		ll tmp = qu2.top();
		if(tmp > a[3*n - 1 - i]){
			sum += (a[3*n - 1 - i] - tmp);
			qu2.pop();
			qu2.push(a[3*n - 1 - i]);
		}
		ans = max(ans, val[3*n - 2 - i] - sum);
	}



	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 7284
/* おまじない　*/
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
typedef long long ll;
typedef long double ld;
using namespace std;
const ll MOD=pow(10,9)+7;
const ll INF=(1LL<<62);
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
void init(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(a%b==0)return b;
    return gcd(a%b,b);
}
ll lcm(ll a,ll b){
    return a/gcd(a,b)*b;
}

bool is_prime[ 1000000 + 2 ];
vector<int> P;
void Eratosthenes( const int N )
{
    for( int i = 0; i <= N; i++ )
    {
        is_prime[ i ] = true;//初期化
    }    
    for( int i = 2; i <= N; i++ )
    {
        if( is_prime[ i ] )
        {
            for( int j = 2 * i; j <= N; j += i )
            {
                is_prime[ j ] = false;
            }
            P.emplace_back( i );
        }
    }
}

int main(){
    init();
	ll N;cin>>N;
	Eratosthenes(1000000);
	for(int i=N;;i++){
		if(is_prime[i]){
			cout<<i<<endl;
			return 0;
		}
	}
}


Measured memory_bytes: 1916
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <istream>
#include <map>
#include <set>
#include <queue>
#define rep0(i,n) for (int i = 0; i <= (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)
#define REP(a,b) for (int i = a; i <= (b); ++i) 
#define mREP(a,b) for (int i = a; i == (b); --i) 
typedef long long ll;
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
/*
	　　　  　 ,ﾍ／L──- 、
	　　　   　Lﾆ)r_」=＝= ｲ
	　　 　,ﾍ、i ﾉノλﾉﾊﾉﾍ
	　　   ,'　｀(ﾊﾘ ﾟ ヮﾟﾉi)　',
	　　 .i　　 >〈(つ,i!と)　　i
	　　  vﾍγk´_/___i,ゝﾍノ
	　　　　　 ｀ﾞr_,ｨ_ｧﾞ´
*/
int n;
cin >> n;
int cancaunt = 0;
int ans = 0;
rep1(i, n) {
	if (i % 2 != 0) {
		rep1(j, i) {
			if (i % j == 0) {
				cancaunt++;
			}
		}
		if (cancaunt == 8) {
			ans++;
		}
		cancaunt = 0;
	}

}
cout << ans << endl;
return 0;
}


Measured memory_bytes: 256
//10/06/20 21:13 
#include <bits/stdc++.h>
#define int long long
using namespace std;
int dp[3010][3010];
signed main()
{
	string a, b;
	cin >> a >> b;
	for (int i = 1; i <= b.size(); i++){
		for (int j = 1; j <= a.size(); j++){
			if (a[j-1]==b[i-1]){
				dp[i][j] = dp[i-1][j-1]+1;
			}else{
				dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
			}
		}
	}
	int i = b.size(), j = a.size();
	string ans = "";
	while(dp[i][j]!=0){
		if (dp[i-1][j] != dp[i][j] && dp[i][j-1] != dp[i][j]){
			ans+=a[j-1];
			i--;j--;
		}else{
			if (dp[i][j] == dp[i-1][j]) i--;
			if (dp[i][j] == dp[i][j-1]) j--;
		}
	}
	for (int i = ans.size()-1; i>=0; i--)
		cout << ans[i];
	cout << "\n";
}

Measured memory_bytes: 70784
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif
#include<bits/stdc++.h>
#include<chrono>
#include<unordered_map>
#include<random>
#include<complex> 
using namespace std;
#define ll long long
#define ld long double
#define ull unsigned ll 
#define endl '\n'
#define mk make_pair
void fast_in_out() {
	std::ios_base::sync_with_stdio(NULL);
	cin.tie(NULL); cout.tie(NULL);
}
int dx[] = { 0,0,-1,1,-1,1,-1,1,0 };
int dy[] = { -1,1,0,0,-1,-1,1,1,0 };
int lx[] = { 2, 2, -1, 1, -2, -2, -1, 1 };
int ly[] = { -1, 1, 2, 2, 1, -1, -2, -2 };
const ld eps = 1e-9;
const int N = 1e5 + 50, M = 1e5 + 10, mod = 1e9 + 7;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll t = gcd(a, b); return t ? (a / t * b) : 0; }
int main() {
	fast_in_out();
//	cout << fixed << setprecision(6);
	int n, m;
	cin >> n >> m;
	if (m == n)cout << "Yes\n";
	else cout << "No\n";

	return 0;
}

Measured memory_bytes: 256
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n = int(ipt())
    ans = 0
    pi = 0
    for _ in range(n):
        a = int(ipt())
        if a == 0:
            pi = 0
        else:
            ans += (pi+a)//2
            pi = (pi+a)%2
    print(ans)

    return

if __name__ == '__main__':
    main()


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

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

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

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

const ll MAX = 50;

vector<map<ll,ll>> fac(MAX+1);

void COMinit() {
  for (ll i=2; i<=MAX; i++){
    ll x=i;
    for(ll j=2; j<=i; j++){
      ll cnt=0;
      while(x%j==0){
        cnt++;
        x/=j;
      }

      fac[i][j] = fac[i-1][j]+cnt;
    }

    fac[i][x] = fac[i-1][x]+1;
  }
}

ll COM(ll n, ll k){
  ll res=1;
  for(ll i=MAX; i>=2; i--){
    ll cnt=fac[n][i]-fac[n-k][i]-fac[k][i];
    res = res*1.0*pow(i,cnt);
  }

  return res;
}



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

  ll n,a,b;
  cin >> n >> a >> b;
  vll v(n);
  REP(i, n)
    cin >> v[i];

  sort(v.begin(), v.end(), greater<ll>());

  ld sum = 0;
  REP(i, a)
    sum += v[i];
  ld ave = sum/1.0/a;

  REP(i, n)
    v[i] *= -1;
  COMinit();
  ll ans = 0;

  if(v[0]==v[a-1]){
    auto it = upper_bound(v.begin(), v.end(), v[a-1]);
    ll num = it-v.begin();

    for(ll i = a; i<=b; i++){
      if(num<i)
        break;

      ans += COM(num,i);
    }
  }
  else{
    auto itb = lower_bound(v.begin(), v.end(), v[a-1]);
    auto ita = upper_bound(v.begin(), v.end(), v[a-1]);
    ll num = ita-v.begin();

    ans += COM(ita-itb,a-(itb-v.begin()));
  }

  cout << Decimal;
  cout << ave << endl;
  cout << ans << endl;
}


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



int main(){
    int n;cin >> n;
    vector<int> p(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i];
        p[i]--;
    }
    int cnt=0;
    for (int i = 0; i < n; i++) {
        if(p[i]!=i) cnt++;
    }
    if(cnt>2) puts("NO");
    else puts("YES");
    return 0;
}


Measured memory_bytes: 256