akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    int n; cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    vector<int> c(n);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    rep(i,n) cin >> c[i];

    sort(ALL(a));
    sort(ALL(c));
    ll ans = 0;
    rep(i,n) {
        ll anum, cnum, now = b[i];
        auto Iter = lower_bound(ALL(a),now);
        anum = Iter - a.begin();
        auto Iter2 = upper_bound(ALL(c),now);
        cnum = c.end() - Iter2; 
        ans += anum*cnum;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  int n;
  cin >> n;
  vector<int> a(n),b(n-1);
  for(int i=0;i<n-1;i++) cin >> b[i];
  
  a[0]=b[0];
  for(int i=1;i<n-1;i++){
    a[i] = min(b[i-1],b[i]);
  }
  a[n-1]=b[n-2];
  
  int ans=0;
  for(int i=0;i<n;i++){
    ans += a[i];
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<cstdint>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<iterator>
#include<stack>
#include<cctype>
#include<climits>
#include<string>
#include<bitset>
#include<cfloat>
#include<iomanip>
#include<numeric>
#include<utility>
#include<initializer_list>


#define repi(i,start,end)for(int64_t (i)=(start);(i)<(end);++(i))
#define rep(i,end) repi((i),0,(end))
#define rfor(x, v) for(auto& (x) : (v))
#define iterate(itr, v) for(auto (itr)=(v).begin();(itr)!=(v).end();++(itr))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define vin(v) rep(i,(v).size()) cin >> (v)[i];
#define vpin(v) rep(i,(v).size()) cin >> (v)[i].first >> (v)[i].second

using namespace std;
using Int = int64_t;
using pint = pair<Int, Int>;
using vint = vector<Int>;
using vvint = vector<vint>;
using vpint = vector<pint>;
using vstr = vector<string>;

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;  }
template<class T>void put_double(T a){cout<<setprecision(12);cout<<a<<"\n";}
template<class T>void println(T a){cout << a << "\n";}
template<class T>void put_line(T &v){iterate(itr,v){cout<<*itr<<((itr==--v.end())?"\n":" ");}}
// auto [x, y] = make_tuple(3, 4); => let (x, y) = (3, 4);

int k;

vint ans;

void dfs(string &v) {
    ans.push_back(stoll(v));
    if(v.size() == 10) return;
    int d = v.back() - '0';
    repi(i, d - 1, d + 2) {
        if(0 <= i && i <= 9) {
            v.push_back('0' + i);
            dfs(v);
            v.pop_back();
        }
    }
}

int main(void) {
    cin >> k;
    rep(i, 10) {
        string s; s.push_back('0' + i);
        dfs(s);
    }
    sort(all(ans));
    unique(all(ans));
    println(ans[k]);

    return 0;
}


Measured memory_bytes: 2420
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from collections import deque
sys.setrecursionlimit(10**7)
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(input()) #整数読み込み
def ifn(): return float(input()) #浮動小数点読み込み
def isn(): return input().split() #文字列読み込み
def imn(): return map(int, input().split()) #整数map取得
def fmn(): return map(float, input().split()) #浮動小数点map取得
def iln(): return list(map(int, input().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, input().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
MOD = 10**9+7

N = iin()
abc = [iln() for _ in range(N)]

dp = [[0 for _ in range(3)] for _ in range(N+1)]

for i in range(N):
    for j in range(3):
        for k in range(3):
            if j == k: continue
            dp[i+1][j] = max(dp[i+1][j], dp[i][k]+abc[i][j])
print(max(dp[N]))

Measured memory_bytes: 100052
import bisect,collections,copy,heapq,itertools,math,string
from collections import defaultdict as D
from functools import reduce
import numpy as np
import sys
import os
from operator import mul
sys.setrecursionlimit(10**7)

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

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353    

N = I()
s = [sorted(list(_S())) for _ in range(N)]
ss = [0] * N
for i in range(N):
    ss[i]=''.join(s[i])

c = collections.Counter(ss)

# nC2
def nCr(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

key, counts = zip(*c.most_common())
ans = 0
for  count in counts:
    if count > 1:
        ans += nCr(count,2)
print(ans)
# list(map(lambda n,r: nCr(n,r),counts))

Measured memory_bytes: 74876
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
const ll INF = 1LL << 60;

int main(){
	string s; cin >> s;
	int n = s.size() - 2;
	while(n>0){
		if(s.substr(0, n/2) == s.substr(n/2, n/2)){
			cout << n << endl;
			return 0;
		}
		else n -= 2;
	}
	
}


Measured memory_bytes: 256
#include <iostream>                                                                                                          

const int INF = 1000000000;
const int MAX_D = 10; 
int D, G;
int p[MAX_D], c[MAX_D];

int Solve(int index, int cache){
   if(index==D){
      int plus = -1; 
      for(int i=D-1; i>=0; --i){
         if(!(cache&(1<<i))) {
            plus = i;
            break;
         }
      }   
      int sum = 0;
      int n = 0;
      for(int i=0; i<D; ++i){
         if(cache&(1<<i)){
            sum += (i+1)*100*p[i] + c[i];
            n += p[i];
         }
      }   
      if(plus<0)
         return n;
      else if(sum+(plus+1)*100*(p[plus]-1)>=G) 
         return n + std::max((G-sum)/(plus+1)/100 + std::min((G-sum)/100%(plus+1),1),0);
      else return INF;
   }   

   int s = Solve(index+1, cache);

   cache |= (1<<index);
   s = std::min(Solve(index+1, cache),s);

   return s;
}

int main(){
   std::cin >> D >> G;
   for(int i=0; i<D; ++i){
      std::cin >> p[i] >> c[i];
   }


   int ans = Solve(0,0);
   std::cout << ans << std::endl;
   return 0;
}

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

int main(){
    ll a,b,c;
    cin>>a>>b>>c;
    ll ans=0;
    ll amari;
    ans+=a/(b+c)*b;
    amari=a%(b+c);
    if(amari>=b)ans+=b;
    else ans+=amari;
    cout<<ans<<endl;
    return 0;
}

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

int main() {
	string S;
	cin>>S;
	int m,n;
	m=S.size();
	for(int i=0;i<m;i++)if(S[i]=='1')n++;
	m-=n;
	if(m>n)cout<<n*2;else cout<<m*2;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> X(N);
  for(int i=0; i<N; i++){
    cin >> X.at(i);
  }
  sort(X.begin(),X.end());
  int answer=0,en=0;
  for(int i=X.at(0); i<X.at(N-1); i++){
    for(int j=0; j<N; j++){
      en+=(i-X.at(j))*(i-X.at(j));
    }
    if(i==X.at(0)){
      answer=en;
      continue;
    }
    answer=min(answer,en);
    en=0;
  }
  cout << answer << endl;
}

Measured memory_bytes: 3620
using System;

public class p0094{
	static double calculation(double val1, double val2){
		return val1*val2/3.305785;
	}

	static void Main (string[] args)
	{
		string input;
		while ((input=Console.ReadLine())!=null) {
			string[] meters = input.Split(' ');

			Console.WriteLine("{0}", calculation(double.Parse(meters[0]), double.Parse(meters[1])));
		}
	}
}

Measured memory_bytes: 5772
#include <set>
#include <string>
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <limits>
#include <map>
#include <numeric>

#define ll long long
using namespace std;
static ll imin = std::numeric_limits<ll>::min();
static ll imax = std::numeric_limits<ll>::max();
#define rep(i, n) for(int i = 0; i<n; ++i)
#define rep1(i, n) for(int i = 1; i<n; ++i)
#define debug(x) cout << #x << ":" << x << "\n";
template<class T>
std::ostream& operator << (std::ostream& os, std::vector<T>& vec){
  std::size_t n = vec.size();
  if(n == 0){
    return os;
  }
  for(int i = 0; i<n - 1; ++i){
    os << vec[i] << " ";
  }
  os << vec[n - 1];
  os << std::endl;
  return os;
}

template<class T>
std::istream& operator >> (std::istream& is, std::vector<T>& vec){
  T tmp;
  is >> tmp;
  vec.push_back(tmp);
  return is;
}
template <class T>
auto mkVec(unsigned int x){
  return std::vector<int>(x);
}

template <class T>
auto mkVec2(unsigned int x, unsigned int y){
  return std::vector<std::vector<T>>(x, std::vector<T>(y));
}

template <class T>
auto mkVec3(unsigned int x, unsigned int y, unsigned int z){
  return std::vector<std::vector<std::vector<T>>>(x, std::vector<std::vector<T>>(y, std::vector<T>(z)));
}

// 113C
// #ifndef BOOST_TEST_MAIN
// int main(int const argc, char const** argv){
//   int N, M;
//   cin >> N >> M;
//   vector<ll> P;
//   vector<ll> Y;
//   auto X = mkVec2<ll>(N + 1, 0);
//   rep(i, M){
//     ll p, y;
//     cin >> p >> y;
//     P.push_back(p);
//     Y.push_back(y);
//     X[p].push_back(y);
//   }
//   rep(i, N + 1){
//     sort(X[i].begin(), X[i].end());
//   }
//   rep(i, M) {
//     ll y;
//     rep(j, N + 1){
//       auto x = find(X[j].begin(), X[j].end(), Y[i]);
//       if(x != X[j].end()){
//         y = x - X[j].begin();
//         break;
//       }
//     }
//     printf("%06lld%06lld\n", P[i], y + 1);
//   }
// }
// #endif

#ifndef BOOST_TEST_MAIN
int main(int const argc, char const** argv){
  int N, K;
  cin >> N >> K;
  vector<ll> x;
  rep(i, N){
    ll t;
    cin >> t;
    x.push_back(t);
  }
  ll res = imax;
  rep(i, N - K + 1){
    res = min({abs(x[i + K - 1] - x[i]) + abs(x[i]),
               abs(x[i + K - 1] - x[i]) + abs(x[i + K - 1]),
               res});
  }
  cout << res;
}
#endif


Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n), b(n), suma(n, 0), sumb(n, 0);
    rep(i, n)cin >> a[i];
    rep(i, n)cin >> b[i];
    suma[0] = a[0];
    REP(i, n-1)suma[i] += suma[i-1]+a[i];
    sumb[n-1] = b[n-1];
    for(int i = n-2; i >= 0; i--)sumb[i] += sumb[i+1]+b[i];
    int ans = 0;
    rep(i, n)ans = max(ans, suma[i]+sumb[i]);
    cout << ans << endl;
}   

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

#define rep(i, n) for (int i = 0; i < (n); i++)

int n, m;
vector<vector<int>> g;
vector<int64_t> dp;
vector<int64_t> ans;

int64_t dfs(int i, int p) {
  dp[i] = 1;
  for (auto j : g[i]) {
    if (j == p) continue;
    dp[i] = dp[i] * (dfs(j, i) + 1) % m;
  }
  return dp[i];
}

void solve(int i, int p, int64_t a) {
  ans[i] = a % m;
  for (auto j : g[i]) {
    if (j == p) continue;
    ans[i] = ans[i] * (dp[j] + 1) % m;
  }
  int sz = g[i].size();
  vector<int64_t> cul(sz, 1);
  rep(o, sz) {
    if (o > 0) cul[o] = cul[o - 1];
    auto j = g[i][o];
    if (j == p) continue;
    cul[o] = cul[o] * (dp[j] + 1) % m;
  }
  vector<int64_t> luc(sz, 1);
  for (int o = sz - 1; o >= 0; o--) {
    if (o + 1 < sz) luc[o] = luc[o + 1];
    auto j = g[i][o];
    if (j == p) continue;
    luc[o] = luc[o] * (dp[j] + 1) % m;
  }
  rep(o, sz) {
    auto j = g[i][o];
    if (j == p) continue;
    auto b = a;
    if (o - 1 >= 0) b = b * cul[o - 1] % m;
    if (o + 1 < sz) b = b * luc[o + 1] % m;
    solve(j, i, b + 1);
  }
}

int main() {

  cin >> n >> m;
  g.resize(n);
  rep(i, n - 1) {
    int a, b;
    cin >> a >> b;
    g[a - 1].emplace_back(b - 1);
    g[b - 1].emplace_back(a - 1);
  }

  if (n == 1) {
    cout << 1 << endl;
    return 0;
  }
  dp.resize(n);
  dfs(0, -1);
  ans.resize(n);
  solve(0, -1, 1);
  for (auto a : ans) {
    cout << a << endl;
  }
  return 0;
}


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

void init() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
}

void solve() {
	int n, k; scanf("%d %d", &n, &k);
	int ans = k;
	for (int i = 1; i < n; ++i) {
		ans *= k-1;
	}
	printf("%d", ans);
}

int main() {
	init();
	int t = 1; //scanf("%d", &t);
	while (t--) {
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int N, L = 0, i = 0,number=0,tmp;
	int count[1000];
	scanf("%d", &N);
	while (true) {
		L = 0;
		for (int i = 0; i < 10; i++) {
			count[i] = 0;
		}
		tmp = N;
		while (tmp > 0) {
			count[tmp % 10]++;
			L++;
			number = tmp % 10;
			tmp /= 10;
		}
		if (count[number] == L) {
			printf("%d", N);
			return 0;
		}
		N++;
		//printf("%d", N);
	}
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
	#define DBG(X) cout << #X << "=" << (X) << '\n';
	#define SAY(X) cout << (X) << '\n';
#else
	#define DBG(X)
	#define SAY(X)
#endif
 
using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld  = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF  = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for(auto el: v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for(auto& elem: ret) cin >> elem; return ret; }

void solve() {
	int a = fetch<int>();
	int b = fetch<int>();
	cout << (a > b ? "No\n" : "Yes\n");
}

int main() {
	fast_io();
	solve();

	return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define Abs(x)((x) < 0 ? (x) * -1 : (x))
#define rep(x, y) for ((x) = 0; (x) < (y); (x)++)
#define repin(x, y) for ((x) = 0; (x) <= (y); (x)++)
#define nep(x, y) for ((x) = (y) - 1; 0 <= (x); (x)--)
#define nepi(x, y, z) for ((x) = (y) - 1; (z) <= (x); (x)--)
#define repi(x, y, z) for ((x) = (z); (x) < (y); (x)++)
#define repiin(x, y, z) for ((x) = (z); (x) <= (y); (x)++)
#define reps(x, y, z) for ((x) = 0; (x) < (y); (x) += (z))
#define repit(x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define all(x) (x).begin(),(x).end()
#define Mem(x, y) memset(x, y, sizeof(x))
#define _end '\n'
#define Out(x) cout<<(x)<<_end
template<typename T> inline bool Max(T &x, const T &y) { return x < y ? x = y, 1 : 0; }
template<typename T> inline bool Min(T &x, const T &y) { return x > y ? x = y, 1 : 0; }
template<typename T> using V = vector<T>;
template<typename T> using VV = V<V<T> >;

#define pb push_back
#define mp make_pair

static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;

string toString(long x) {
    stringstream ss;

    ss << x;

    return ss.str();
}

#define LOCAL 0

int main()
{
#if LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif

    cin.tie(0);
    ios::sync_with_stdio(false);

    long a, b;

    cin >> a >> b;

    string s;
    long ans = 0;
    bool is;

    long i, j, k;

    repiin(i, b, a) {
        s = toString(i);
        is = true;

        for (j = 0, k = s.size() - 1; j < k; j++, k--) {
            if (s[j] != s[k]) {
                is = false;

                break;
            }
        }

        if (is) ans++;
    }

    Out(ans);

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;main(){string s;cin>>s;long long r=0,d=0,i=0,b,c;for(;i<s.size();d=b^c?0:d){b=s[i]==66,c=s[i+1]>66;s[i++]<66?d++:r+=b&c?d:0;}cout<<r;}

Measured memory_bytes: 640
/*  ex9_2
    Rikuta  */
#include <stdio.h>
#include <stdlib.h>
// リストのノード（スタック内の各データ）の定義
typedef struct node
{
    char elem;
    struct node *next;
} node;

void push(node **first, char elem);
char pop(node **first);
char last(node **first);

int main(void)
{
    node *cube = NULL;
    int count = 0;
    while (1)
    {
        char temp_char;
        scanf("%c", &temp_char);
        if (temp_char=='\n')
        {
            break;
        }
        if (temp_char=='0')
        {
            if (last(&cube)=='1')
            {
                pop(&cube);
                count+=2;
            }
            else
            {
                push(&cube, temp_char);
            }
            
            
        }
        if (temp_char=='1')
        {
            if (last(&cube) == '0')
            {
                pop(&cube);
                count+=2;
            }
            else
            {
                push(&cube, temp_char);
            }
        }
    }
    printf("%d\n", count);
    return 0;
}

//スタックにデータを追加
void push(node **first, char elem)
{
    //追加する分の領域を確保
    node *new = calloc(1, sizeof(node));
    if (new == NULL)
        exit(1);
    new->elem = elem;
    new->next = *first;
    *first = new;
}

//スタックからデータを取り出す
char pop(node **first)
{
    char elem;
    node *tmp = *first;
    if (tmp == NULL)
        exit(1);
    elem = tmp->elem;
    *first = tmp->next;
    //取り出したノードのメモリを解放
    free(tmp);
    return elem;
}
char last(node **first)
{
    char elem;
    node *tmp = *first;
    if (tmp == NULL)
        return '-';
    elem = tmp->elem;
    return elem;
}


Measured memory_bytes: 4788
#include<bits/stdc++.h>
using namespace std;
#define gc getchar
#define int long long
inline int read()
{
	int res=0,f=0;
	char c;c=gc();
	while(!isdigit(c)){if(c=='-')f=1;c=gc();}
	while(isdigit(c)){res=res*10+c-48;c=gc();}
	if(f)return -res;
	return res;
}
const int N=1e6+5;
struct node{
	int val,gs;
}a[N];
bool operator < (node a,node b)
{
	return a.val>b.val;
}
signed main()
{
	int n=read(),m=read();
	for(int i=1;i<=n;i++)
	{
		int x=read();
		a[i]=(node){x,1};
	}
	int tot=n;
	while(m--)
	{
		int x=read(),y=read();
		a[++tot]=(node){y,x};
	}
	sort(a+1,a+tot+1);
	int ans=0;
	for(int i=1;i<=tot;i++)
	{
		if(a[i].gs>=n)
		{
			ans+=a[i].val*n;
			break;
		}
		ans+=a[i].val*a[i].gs;
		n-=a[i].gs;
	}
	cout<<ans;
}

Measured memory_bytes: 4352
import math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

class UnionFind():
	def __init__(self, n):
		self.n = n
		self.parents = [-1] * n
		self.exclued = [0] * n

	def find(self, x):
		if self.parents[x] < 0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]

	def union(self, x, y):
		x = self.find(x)
		y = self.find(y)

		if x == y:
			return

		if self.parents[x] > self.parents[y]:
			x, y = y, x

		self.exclued[x] += self.exclued[y] + 1
		self.parents[x] += self.parents[y]
		self.parents[y] = x

	def size(self, x):
		return -self.parents[self.find(x)]

	def same(self, x, y):
		return self.find(x) == self.find(y)

	def members(self, x):
		root = self.find(x)
		return [i for i in range(self.n) if self.find(i) == root]

	def roots(self):
		return [i for i, x in enumerate(self.parents) if x < 0]

	def group_count(self):
		return len(self.roots())

	def all_group_members(self):
		return {r: self.members(r) for r in self.roots()}

n, m, k = list(map(int, input().split()))

cnt = [0 for _ in range(n)]
uf = UnionFind(n)

for _ in range(m):
	a, b = list(map(int, input().split()))
	uf.union(a - 1, b - 1)
	cnt[a - 1] += 1
	cnt[b - 1] += 1 

for _ in range(k):
	c, d = list(map(int, input().split()))
	if uf.same(c - 1, d - 1):
		cnt[c - 1] += 1
		cnt[d - 1] += 1

ans = []
for i in range(n):
	ans.append(uf.size(i) - cnt[i] - 1)

print(" ".join([str(x) for x in ans]))


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

int main() {
  int W, H, x, y;
  scanf("%d%d%d%d", &W, &H, &x, &y);

  printf("%lf %d", (double)W * (double)H / 2, 2 * x == W && 2 * y == H);
  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	string s;
	cin >> s;
	int n = s.size();
	int ans = 0;
	for(int len = 2; len <= (n - 1); len += 2){
		rep(i, n - len + 1){
			string s1 = s.substr(i, len / 2);
			string s2 = s.substr(i + len / 2, len / 2);
			if(s1 == s2){
				ans = len;
			}
		}
	}	
	cout << ans << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


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

int main () {
  int n, q;
  string s;
  vector<int> index;
  cin >> n >> q >> s;
  int arr[n];
  int count = 0;
  memset(arr, 0, sizeof(arr));
  for(int i = 1;i < n;i++) {
    // cout << s[i - 1] << s[i] << endl;
    if(s[i - 1] == 'A' && s[i] == 'C') {
      arr[i] = ++count;
    }
    else
      arr[i] = arr[i - 1];
  }
  while(q--) {
    int l, r;
    cin >> l >> r;
    l--;r--;
    cout << arr[r] - arr[l] << endl;
  }
  return 0;
}


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

int main(int argc, char** argv){
  int N;
  cin >> N;
  int H[N];
  for(int i=0; i<N; i++) cin >> H[i];
  
  int ans = 0;
  for(int cnt0=0; cnt0<N; cnt0++){
    bool f = true;
    for(int cnt1=0; cnt1<cnt0; cnt1++){
      if(H[cnt0] < H[cnt1]) {
        f = false;
        break;
      }
    }
    if(f) ans++;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int r,c;
bool v[10];
int s[10][10000];

int solve(int n)
{
	if(n<r)
	{
		v[n]=false;
		int a1=solve(n+1);
		v[n]=true;
		int a2=solve(n+1);
		return max(a1,a2);
	}
	else
	{
		int ans=0,tmp;
		for(int i=0;i<c;i++)
		{
			tmp=0;
			for(int j=0;j<r;j++)
			{
				if((!v[j]&&s[j][i])||(!s[j][i]&&v[j]))tmp++;
			}
			ans+=max(tmp,r-tmp);
		}
		return ans;
	}
}

int main()
{
	while(cin>>r>>c,r)
	{
		for(int i=0;i<r;i++)
		{
			for(int j=0;j<c;j++)
			{
				cin>>s[i][j];
			}
		}
		cout<<solve(0)<<endl;
	}
	return 0;
}

Measured memory_bytes: 3380
#include<iostream>
#include<cmath>
#define EPS 0.000000000001
using namespace std;

int main(){
	int n;
	double x[4], y[4];
	cin >> n;
	while (n--){
		for (int i = 0; i < 4; i++)
			cin >> x[i] >> y[i];
		if (abs((x[1] - x[0]) * (y[3] - y[2]) - (x[3] - x[2]) * (y[1] - y[0])) < EPS)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
	return 0;
}

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

int main()
{
  int64_t N, M, D;
  cin >> N >> M >> D;
  double x, ans;
  if (D == 0)
    x = N;
  else
    x = (N - D) * 2;
  ans = (x / (N * N)) * (M - 1);
  cout << fixed << setprecision(10) << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
    long long A,B,C,D;
    scanf("%lld %lld %lld %lld",&A,&B,&C,&D);
    long long ab=B-A+1;
    long long csyo,dsyo,cdsyo;
    csyo=(ab+(A-1)%C)/C;
    dsyo=(ab+(A-1)%D)/D;
    if(C<D){
        long long k=C;
        C=D;
        D=k;
    }
    long long x=C*D;
    long long r=C%D;
    while(r!=0){
        C=D;
        D=r;
        r=C%D;
    }
    D=x/D;
    cdsyo=(ab+(A-1)%D)/D;
    printf("%lld",ab-(csyo+dsyo-cdsyo));
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  int h[100000];
  rep(i,n) cin>>h[i];
  int ini=h[0];
  repi(i,1,n){
    if(h[i]>ini) ini=h[i]-1;
    else{
      if(ini>h[i]){cout<<"No"<<endl;return 0;}
      ini=h[i];
    }
  }
  cout<<"Yes"<<endl;

  return 0;
}


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

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  int x,n; cin >> x >> n;
  if(n==0){
    cout << x << endl;
    return 0;
  }
  vector<int> p(n);
  rep(i,n) cin >> p[i];

  vector<pair<int,int>> pr(n);
  for(int i=0;i<n;i++){
    int dif = abs(x-p[i]);
    pr[i] = make_pair(dif,p[i]);
  }
  sort(pr.begin(),pr.end());

  int key = pr[0].first;
  int value = pr[0].second;
  for(int i = 1;i<1000;i++){
    int value1 = value-i;
    int value2 = value+i;
    bool flag1 = true,flag2 = true;
    for(auto v : pr){
      if(value1 == v.second){
	flag1 = false;
      }
      if(value2 == v.second){
	flag2 = false;
      }
    }
    if(flag1 || flag2){
      int ans;
      if(flag1) ans = value1;
      if(flag2) ans = value2;
      if(flag1 && flag2){
	if(value1<=value2) ans = value1;
	else ans = value2;
      }
      
      cout << ans << endl;
      return 0;
    }
  }
  
  return 0;
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
const int mxn = 8*1e3+100;
string s;
int ar[mxn];
int X ,Y;
vector< int > vx , vy;
int  dp[4004][mxn];
int solve(int pos , int amount)
{
	if(dp[pos][amount]!=-1) return dp[pos][amount];
    if(pos==(int)vx.size()) return dp[pos][amount] = amount == X;
    if(dp[pos][amount]!=-1) return dp[pos][amount];
    return dp[pos][amount] = (solve(pos+1 , amount + vx[pos] ) || solve(pos+1 , amount - vx[pos]));
}
int solve1(int pos , int amount)
{
	if(dp[pos][amount]!=-1) return dp[pos][amount];
    if(pos==(int)vy.size()) return dp[pos][amount] = amount == Y;
    return dp[pos][amount] = (solve1(pos+1 , amount + vy[pos] ) || solve1(pos+1 , amount - vy[pos]));
}
int main()
{
    cin>>s;
    cin>>X>>Y;
    int d = 0;
    int tot_x = 0;
    
    for(int i = 0; i < (int) s.size(); i++)
    {
        if(s[i]=='T')
        {
			if(d==0)
			{
				vx.push_back(tot_x);
				d = 1;
				tot_x = 0;
			}
			else
			{
				vy.push_back(tot_x);
				d = 0;
				tot_x = 0;
			}
        }
        else
        {
            tot_x++;
        }

	}
	if(d==0)
    vx.push_back(tot_x);
    else
    vy.push_back(tot_x);
    memset(dp , -1 , sizeof dp);
    int ret1 = solve( 1 , vx[0]);
    memset(dp , -1 , sizeof dp);
    int ret2 = solve1(0 , 0);
    if(ret1&&ret2) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

}


Measured memory_bytes: 127232
/*
 * author: calgagi
 *         Calvin Gagliano 
 */
#include <bits/stdc++.h>

using namespace std;

#define long long long
#define double double double
#define ulong unsigned long long
#define ii pair<int, int>
#define ll pair<long long, long long>
#define ar array
#define f first
#define s second

void solve() {
    int n;
    cin >> n;
    string s;
    cin >> s;

    int ans = 0;
    for (int i = 0; i < n-2; i++) {
        if (s.substr(i, 3) == "ABC") {
            ans++;
        }
    }

    cout << ans << endl;

    return;
}

int main() {
    ios_base::sync_with_stdio(false);  
    cin.tie(NULL);
    srand(chrono::steady_clock::now().time_since_epoch().count()); 
    
    int t = 1;
    /* cin >> t; */
    while (t--) {
        solve();
    }

    return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<unordered_map>
#include<queue>
#include<stack>
#include<string>
#include<bitset>
#include<random>
#include<time.h>
#define MOD 1000000007ll
#define INF 1000000000ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<(ll)m; i++)
#define FOR(i,n,m) for(long long i=n; i<(ll)m; i++)
#define DUMP(a) for(long long dump=0; dump<(ll)a.size(); dump++) { cout<<a[dump]; if(dump!=(ll)a.size()-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v) sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n;
	cin>>n;
	vector<P> lr(n);
	REP(i,n) cin>>lr[i].first>>lr[i].second;
	set<P> s1;
	set<P> s2;
	ll ans=INF*INF;
	REP(i,n) s1.insert(P(lr[i].first,i));
	REP(i,n) s2.insert(P(-lr[i].second,i));
	ll pos=0;
	ll buf=0;
	REP(i,n) {
		if(i%2) {
			auto ite=s2.end();
			ite--;
			if(!(lr[(*ite).second].first<=pos&&pos<=lr[(*ite).second].second)) {
				buf+=abs(pos+(*ite).first);
				pos=-(*ite).first;
			}
			s1.erase(P(lr[(*ite).second].first,(*ite).second));
			s2.erase(ite);
		} else {
			auto ite=s1.end();
			ite--;
			if(!(lr[(*ite).second].first<=pos&&pos<=lr[(*ite).second].second)) {
				buf+=abs(pos-(*ite).first);
				pos=(*ite).first;
			}
			s2.erase(P(-lr[(*ite).second].second,(*ite).second));
			s1.erase(ite);
		}
	}
	ans=buf+abs(pos);
	//cout<<ans<<" "<<pos<<endl;
	pos=0;
	buf=0;
	REP(i,n) s1.insert(P(lr[i].first,i));
	REP(i,n) s2.insert(P(-lr[i].second,i));
	REP(i,n) {
		if(i%2==0) {
			auto ite=s2.end();
			ite--;
			if(!(lr[(*ite).second].first<=pos&&pos<=lr[(*ite).second].second)) {
				buf+=abs(pos+(*ite).first);
				pos=-(*ite).first;
			}
			s1.erase(P(lr[(*ite).second].first,(*ite).second));
			s2.erase(ite);
		} else {
			auto ite=s1.end();
			ite--;
			if(!(lr[(*ite).second].first<=pos&&pos<=lr[(*ite).second].second)) {
				buf+=abs(pos-(*ite).first);
				pos=(*ite).first;
			}
			s2.erase(P(-lr[(*ite).second].second,(*ite).second));
			s1.erase(ite);
		}
	}
	ans=max(ans,buf+abs(pos));
	cout<<ans<<endl;
}


Measured memory_bytes: 16384
import java.util.*;

public class Main {

	private static Scanner sc;

	public static void main(String[] args) throws java.lang.Exception { 
		sc = new Scanner(System.in);
		int S = sc.nextInt();
		int h = S / 3600;
		int m = S % 3600 / 60;
		int s = S % 60;
		System.out.println(h + ":" + m + ":" + s);
	}
}



Measured memory_bytes: 26356
import java.util.*;
    public class Main {
      public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if(a > b) {
          System.out.println(a - 1);
        }
        else {
          System.out.println(a);
        }
      }
    }

Measured memory_bytes: 21204
import numpy as np
n,k = map(int,input().split())
s = list(map(int,input().split()))
s = np.array(s)
ans =  np.sum(s[:k])
a = ans
for i in range(n-k):
  a = a - s[i] + s[i+k]
  if a > ans:
    ans = a  
print((ans+k)/2)  

Measured memory_bytes: 33948
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var ss = Console.ReadLine().Split();
            var A = int.Parse(ss[0]);
            var B = int.Parse(ss[1]);
            var C = int.Parse(ss[2]);
            var D = int.Parse(ss[3]);

            var AB = A * B;
            var CD = C * D;
            Console.WriteLine(AB > CD ? AB : CD);
        }
    }
}

Measured memory_bytes: 11092
/*
ID:greenty2
LANG:C++
TASK:
*/
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int max=0,min=9999999;
	int x;
	for(int i=1;i<=n;i++)
	{
		cin>>x;
		if(x<min)
		min=x;
		if(x>max)
		max=x;
	}
	cout<<max-min<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>


int biSearch(int s[], int n, int key) {
    int left, mid, right;
    left = 0;
    right = n;
    while (left < right) {
        mid = (left + right) / 2;
        if (s[mid] == key) return 1;
        if (s[mid] < key) left = mid + 1;
        else right = mid;
    }
    return 0;
}


int main() {

    int i, q, cnt, t, s[100000], n;
    cnt = 0;
    scanf("%d", &n);
    for (i = 0; i < n; i++) scanf("%d", &s[i]);
    scanf("%d", &q);
    for (i = 0; i < q; i++) {
        scanf("%d", &t);
        if (biSearch(s, n, t)) cnt++;
    }
    printf("%d\n", cnt);

    return 0;
}




Measured memory_bytes: 2112
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] in = br.readLine().split(" ");
        int w = Integer.parseInt(in[0]);
        int h = Integer.parseInt(in[1]);
        int x = Integer.parseInt(in[2]);
        int y = Integer.parseInt(in[3]);

        System.out.printf("%.11f %d\n", 1.0 * w * h / 2, x * 2 == w && y * 2 == h? 1 : 0);
    }
}

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

int main(){
    long long a,b,k;cin>>a>>b>>k;

    if (a < k){
        if (k - a < b){
            cout << 0 << " " << b - (k - a) <<endl;
        } else {
            cout << 0 << " " << 0 << endl;
        }
    } else {
        cout << a - k << " " << b <<endl;
    }
    return 0;
}

Measured memory_bytes: 256
N,X = map(int, input().split())
M = []
for i in range(N):
    M.append(int(input()))

    
ichi = sum(M)
ans = N
X -= ichi
M.sort()

i = 0
while X-M[i]>=0:
    if X - M[i] >= 0:
        X -= M[i]
        ans += 1
        continue
    
    i += 1
    
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
//#define int long long
#define ll long long
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
using namespace std;
int n,k;
const int mod = 1e9+7;
ll dp[23][1<<23];
int a[23][23];
ll pr[405];
main() {
    ios::sync_with_stdio(0);
    cin >> n;
    dp[0][(1<<n)-1] = 1;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            cin >> a[i][j];
    for (int i = 0; i < n; i++)
    for (int mask = 0; mask < (1<<n); mask++) {
        int cnt = __builtin_popcount(mask);
        if (cnt + i != n) continue;
        for (int j = 0; j < n; j++)
                    if ((1<<j)&mask && a[i][j]) {
            (dp[i+1][mask^(1<<j)] += dp[i][mask])%=mod;
        }
    }
    cout << dp[n][0];
}


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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;
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
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= 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
  {
    mint res(*this);
    return res /= a;
  }
};

int main(){
  ll n; cin >> n;
  ll ans = 0;
  for(ll x = 1; x <= (ll)sqrt(n); ++x) {
    if(n%x == 0) {
      ll y = n/x;

      ll q = x;
      ll m = y-1;
      if(m > 0 && q < m) ans += m;
      q = y;
      m = x-1;
      if(m > 0 && q < m) ans += m;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3624
// ABC 049

// inputに入力データ全体が入る
function Main(input) {
  var str = input.split("\n")[0];
  str = str.replace(/eraser/g, '0');
  str = str.replace(/erase/g, '0');
  str = str.replace(/dreamer/g, '0');
  str = str.replace(/dream/g, '0');
  str = str.replace(/0/g, '');
  if(str === '') {
    console.log('YES');
  } else {
    console.log("NO");
  }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7624
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cout << #x": " << x << endl;
inline int lowbit(int x) { return x & -x; }
typedef long long LL;
const int N = 3e5 + 10;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3fLL;
const int mod = 1e9 + 7;

priority_queue<int> Q;
int a[N];
LL pre[N];
LL suf[N];

int main() {
#ifdef purple_bro
    freopen("in.txt", "r", stdin);
#endif // purple_bro
    int n;

    scanf("%d", &n);

    for (int i = 1; i <= n * 3; i++)
        scanf("%d", &a[i]);

    for (int i = 1; i <= n * 2; i++) {
        if (i <= n) {
            pre[i] = pre[i - 1] + a[i];
            Q.push(-a[i]);
        } else {
            Q.push(-a[i]);
            pre[i] = pre[i - 1] + a[i];
            pre[i] -= -Q.top();
            Q.pop();
        }
    }

    for (;!Q.empty();)
        Q.pop();

    for (int i = n * 3; i >= n + 1; i--) {
        if (i > 2 * n) {
            suf[i] = suf[i + 1] + a[i];
            Q.push(a[i]);
        } else {
            Q.push(a[i]);
            suf[i] = suf[i + 1] + a[i];
            suf[i] -= Q.top();
            Q.pop();
        }
    }

    LL ans = -INF;

    for (int i = n; i <= 2 * n; i++)
        ans = max(ans, pre[i] - suf[i + 1]);

    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 5240
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A: Two Integers
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  int x, y;
  cin >> x >> y;

  printf("%d\n", (x % y == 0) ? -1 : x);
  return 0;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
typedef pair<int, int> P;
const long long mod = 1000000007;
const double eps = 1e-11;
const int inf = 1ll << 61;
vector<int>v;
int comb[25][25];
int rwc[20];
int rk[300000];
signed main() {
	int n; cin >> n;
	map<int, int>M1, M2;
	rep(i, 1 << n) {
		int c; cin >> c; v.push_back(c);
		M1[c]++;
	}
	int cnt = 0;
	for (auto i = M1.begin(); i != M1.end(); i++) {
		M2[i->first] = cnt; cnt++;
		if (i->second > (1 << (n - 1))) {
			cout << "No" << endl; return 0;
		}
	}
	rep(i, 1 << n) {
		v[i] = M2[v[i]];
		rk[v[i]]++;
	}

	sort(v.begin(), v.end());
	reverse(v.begin(), v.end());

	int T = v[0];
	for (int i = T; i >= 1; i--) {
		rk[i - 1] += rk[i];
	}

	comb[0][0] = 1;
	rep(i, 20){rep(j, i + 1) {
		comb[i + 1][j] += comb[i][j];
		comb[i + 1][j + 1] += comb[i][j];
	}}
	rep(i, n)rwc[i] = comb[n][i];
	rep(i, n)rwc[i+1] += rwc[i];
	rep(i, n) {
		if (T-i<0||rwc[i] < rk[T - i]) {
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;
}

Measured memory_bytes: 37104
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<iomanip>
#include<stack>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define sz(a) (int)a.size()
using namespace std;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a == b) cout << c << endl;
	else if (a == c) cout << b << endl;
	else cout << a << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  int h, w;
  char s[51][51];
  cin >> h >> w;
  for (int i=0;i<h;i++) {
    for (int j=0;j<w;j++) {
      char c;
      cin >> c;
      s[i][j] = c;
    }
  }
  for (int i=0;i<h;i++) {
    for (int j=0;j<w;j++) {
      if (s[i][j] == '.') {
	continue;
      }
      bool can_paint = false;
      if (0 < i && s[i-1][j] == '#') {
	can_paint = true;
      }
      if (i < h-1 && s[i+1][j] == '#') {
	can_paint = true;
      }
      if (0 < j && s[i][j-1] == '#') {
	can_paint = true;
      }
      if (j < w-1 && s[i][j+1] == '#') {
	can_paint = true;
      }
      if (!can_paint) {
	cout << "No" << endl;
	return(0);
      }
    }
  }
  cout << "Yes" << endl;
  return(0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ls( s) (s&(-s))
#define ll long long
#define inf 0x3f3f3f3f
const ll N = 200030;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const ll mod =    1e9+7;

int main()
{
int n,k;
cin>>n>>k;
if(n>=10)
cout<<k;
else
{
	cout<<k+100*(10-n);
}


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define INF 1000000000000
#define MOD 1000000007
#define DEBUG(x) cerr<<'>'<<#x<<':'<<x<< endl
using namespace std;


signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll N;
    cin >> N;
    long double P[N + 5];
    for(ll i = 1; i <= N; i++)
    {
        cin >> P[i];
    }   
    long double dp[N + 2][N + 2] = {0};
    dp[1][0] = 1 - P[1];
    dp[1][1] = P[1];
    for(ll pos = 2; pos <= N; pos++)
    {
        dp[pos][0] = dp[pos - 1][0]  * (1 - P[pos]);
        for(ll heads = 1; heads <= pos; heads++)
        {
            dp[pos][heads] = (dp[pos - 1][heads - 1] * P[pos]) + (dp[pos - 1][heads] * (1 - P[pos])); 
        }
    }
    long double ans = 0;
    ll required_heads = floor(N / 2) + 1;
    for(ll i = required_heads; i <= N ; i++)
    {
        ans += dp[N][i];
    }
    printf("%.10Lf\n", ans);
    return 0;
}


Measured memory_bytes: 141056
L = []
for i in range(5):
    L.append(int(input()))
    
s = [0,1,2,3,4]
import itertools
ans_L = []
for i in itertools.permutations(s, 5):
    ans = 0
    for j,k in enumerate(i):
        ans += L[k]
        if ans % 10 != 0 and j != 4:
            for l in range(1,10):
                if (ans + l) % 10 == 0:
                    ans += l
                    break
    ans_L.append(ans)
print(min(ans_L))

Measured memory_bytes: 3064
N = int(input())
A = list(map(int,input().split()))

S = [0]
for i in range(N):
        S.append(S[i]+A[i])

a = 1
c = 3
ans = S[N]

for b in range(2,N-1):
        while abs(S[b]-S[a]-S[a]) > abs(S[b]-S[a+1]-S[a+1]):
                a += 1

        while abs((S[N]-S[c]) - (S[c]-S[b])) > abs((S[N]-S[c+1]) - (S[c+1]-S[b])):
                c += 1

        ans = min(ans,(max(S[N]-S[c],S[c]-S[b],S[b]-S[a],S[a]-S[0])-min(S[N]-S[c],S[c]-S[b],S[b]-S[a],S[a]-S[0])))

print(ans)

Measured memory_bytes: 25068
#include <stdio.h>

int n, p;
int i = 0;
int have[50] = {};
int wan;

void argo()
{
    for (;;)
    {
        if (wan != 0)
        {
            wan--;
            have[i]++;
            if (have[i] == p)
            {
                printf("%d\n", i);
                return;
            }
        }
        else
        {
            wan = have[i];
            have[i] = 0;
        }
        if (i == n - 1)
        {
            i = 0;
        }
        else
        {
            i++;
        }
    }
}

int main()
{
    for (;;)
    {
        scanf("%d %d", &n, &p);
        if (n == 0 && p == 0)
            break;
        wan = p;
        for (i = 0; i < n; i++)
        {
            have[i] = 0;
        }
        i = 0;
        argo();
    }
    return 0;
}


Measured memory_bytes: 2064
class Stack:
  def __init__(self):
    self.count = 1
    self.lst = []
  
  def push(self, element):
    if element == self.count:
      self.lst.append(element)
      self.count += 1
  
  def length(self):
    return len(self.lst)

n = int(input())
a = list(map(int, input().split()))
stack = Stack()
for i in a:
  stack.push(i)

b = stack.length()
if b == 0:
  print('-1')
else:
  print(n - b)


Measured memory_bytes: 33288