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

int main()
{
    int n, a; cin >> n;
    int max = -1000001, min = 1000001;
    long long sum = 0;
    
    for (int i = 0; i < n; i++) {
        scanf("%d", &a);
        if (a < min) min = a;
        if (a > max) max = a;
        sum += a;
    }
    printf("%d %d %lld\n", min, max, sum);
}



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

using namespace std;

#define PI 3.141592653589793

int main(int argc, char *argv[])
{
   
    
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);

    double r;
    
    cin >> r;
    cout << fixed << setprecision(6) << PI* pow(r, 2) << ' ' << 2*PI*r  << endl;
    return 0;
}



Measured memory_bytes: 3244
#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using ull = unsigned long long;
using vll = vector<ll>;
using vi = vector<int>;
using vchar = vector<char>;
using vstr = vector<string>;
using pii = pair<int,int>;
using pll =  pair<ll,ll>;

const ll mod = 1000000007;

#define pi acos(-1)
#define pb push_back
#define mp make_pair
#define test int TEST;cin>>TEST;while(TEST--)
#define all(x) x.begin(),x.end()
#define vrevsort(x) sort(x.rbegin(),x.rend())
#define opy cout<<"Yes\n"
#define opn cout<<"No\n"
#define flush fflush(stdout)
#define NL cout<<'\n'
#define SP cout<<' '

void solve(){
	ll n,mx,x,y,c=0;
	cin>>n>>mx;
	mx=mx*mx;
	while(n--){
		cin>>x>>y;
		if(x*x + y*y <=mx) c++;
	}
	cout<<c;
	
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    //test{solve();cout<<'\n';}
	solve();
    return 0;
}


Measured memory_bytes: 3648
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
    char b[8][8];
    int a[8][8];
	char en;
int main(void){



    while(cin>>b[0]){
        cin>>b[1]>>b[2]>>b[3]>>b[4]>>b[5]>>b[6]>>b[7];


	for(int n=0;n<8;n++){
        for(int m=0;m<8;m++){
            if(b[n][m]=='1')a[n][m]=1;
            else a[n][m]=0;
        }
	}
	int i,j;
	int flag=0;
	char t;
	for(i=0;i<8;i++){
        for(j=0;j<8;j++){
            if(a[i][j]==1){
             //   cout<<i<<j;
                flag=1;
                break;
            }
        }
        if(flag==1)break;
	}
	if(a[i][j]==a[i][j+1]){
	    //cout<<".";
        if(a[i][j+1]==a[i][j+2])t='C';
        else if(a[i][j+1]==a[i+1][j]){
            if(a[i+1][j]==a[i+1][j+1])t='A';
            else if(a[i+1][j]==a[i+1][j-1])t='G';
        }
        else if(a[i][j+1]==a[i+1][j+2])t='E';
	}
    else if(a[i][j]==a[i+1][j]){
        if(a[i+1][j]==a[i+2][j])t='B';
        else if(a[i+1][j]==a[i+1][j+1])t='F';
        else if(a[i+1][j]==a[i+1][j-1])t='D';
    }
    //else cout<<".....";

    cout<<t<<endl;


    }

	return 0;
}

Measured memory_bytes: 1132
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<math.h>
using namespace std;

int main(void)
{
	unsigned long long int L, R;

	cin >> L >> R;

	unsigned long long int min = 2*10e9;
	unsigned long long int mm;
	unsigned long long int i, j;

	for (i = L; i <= R; i++)
	{
		for (j = i + 1; j <= R; j++)
		{
			mm = (i * j) % 2019;
			if (min > mm)
				min = mm;
			if (min == 0)
				goto END;
		}
	}
END:
	cout << min << endl;

	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np
# from numpy import cumsum  # accumulate

def comb(n, r):
    if n - r < 0: return 0
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def mcomb(n, k, mod):
    def mfac(l, r, mod):
        ans = l
        for i in reversed(range(r, l)):
            ans *= i
            ans %= mod
        return ans

    A = mfac(n, n-k+1, mod)
    B = mfac(k, 1, mod)
    # B = mpow(B,mod-2,mod)
    B = pow(B, mod-2, mod)
    return A * B % mod

def solve():
    N, K = MI()
    MOD = 1000000007
    aka = N - K
    for k in range(1, K+1):
        # ans = comb(aka+1, k) * comb(K-1, k-1)
        # print(comb(aka+1, k), comb(K-1, k-1))
        # print(aka+1, k, K-1, k-1)
        if aka+1 < k:
            a = 0
        else:
            a = mcomb(aka+1, k, MOD)
        if k-1 == 0:
            b = 1
        else:
            b = mcomb(K-1, k-1, MOD)
        # print(a, b)
        print(a * b % MOD)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 9288
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,ans=0,a=0,b=0,ba=0;
	string s;
	cin>>n;
	while(cin>>s){
		for(int i=0;i+1<s.size();i++)
			if(s[i]=='A'&&s[i+1]=='B')
				ans++;
		if(s[0]=='B'&&s.back()=='A')
			ba++;
		else if(s[0]=='B')
			b++;
		else if(s.back()=='A')
			a++;
	}
	if(ba==0)
		cout<<ans+min(a,b)<<endl;
	else if(a==0&&b==0)
		cout<<ans+ba-1<<endl;
	else if(a==0)
		cout<<ans+ba<<endl;
	else if(b==0)
		cout<<ans+ba<<endl;
	else
		cout<<ans+min(a,b)+ba<<endl;
}


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

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

void solve(void) {
  string s, t;
  cin >> s >> t;

  if (t.substr(0, s.size()) == s && t.size() == s.size() + 1) cout << "Yes" << endl;
  else cout << "No" << endl;
}

int main(void) {
  solve();
  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
const unsigned int MOD = 1000000007;
#define ll long long
#define PI 3.1416
string day[]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
int main() {
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int n,m;
    while(cin>>n>>m){
        cout<<(n-1)*(m-1)<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cctype>
#include<iostream>
#include<stack>
#include<string>
#include<vector>
#include<queue>
#include<deque>
#include<algorithm>
#include<utility>
#include <map>
#include <set>

using namespace std;

#define REP(i,x) for(int i=0; i<(int)(x); i++)       // 0 <= i < x
#define REPS(i,x) for(int i=1; i<=(int)(x); i++)     // 0 < i <= x
#define RREP(i,x) for(int i=((int)(x)-1); i>=0; i--) // x > i >= 0
#define RREPS(i,x) for(int i=((int)(x)); i>0; i--)   // x >= i > 0
#define INF 100000000

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

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


int main(void){
	int N, C;
    cin >> N >> C;
    REP(i, 30){
        REP(j, 100001){
            ar[i][j] = 0;
        }
    }

    int s, t, c;
    REP(i, N){
        cin >> s >> t >> c;
        c--;
        for(int j = s; j <= t; j++){
            ar[c][j] = 1;
        }
    }

    int res = 1;
    int num;
    for(int i = 1; i <= 100000; i++){
        num = 0;
        REP(j, C){
            num += ar[j][i];
        }
        res = max(res, num);
    }

    cout << res << endl;
    return 0;
}


Measured memory_bytes: 11904
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  int a[10000];
  cin >> n;
  int m;
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  int mn = a[0] , mx = a[0];
  long long mix  = 0;
  for(int i=0;i<n;i++){
  mn  = min(mn, a[i]);
  mx  = max(mx, a[i]);
  mix += a[i];
  }
  cout << mn << " " << mx << " " << mix << endl;


  return 0;
}


Measured memory_bytes: 3124
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:https://atcoder.jp/contests/abc172/tasks/abc172_b>
 問題文============================================================
 B - Minor Change
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    string S,T; cin >> S >> T;
    for(int i = 0; i < (int)S.length();i++){
        res += S[i]!=T[i];
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


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

int main(){
	int d,N;
	cin>>N;
	d=N%10;
	if(d==2 || d==4 || d==5 || d==7 || d==9){
		cout<<"hon";
	}
	else if(d==0 || d==1 || d==6 || d==8){
		cout<<"pon";
	}
	else cout<<"bon";
	return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;

#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

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

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

  string s;
  cin>>s;
  reverse(ALL(s));

  ll n=s.size();
  vector<vll> dp(n,vll(2,0));
  REP(i,n){
    dp[i][0]=s[i]-'0';
    dp[i][1]=10-(s[i]-'0');
    if(i!=0){
      dp[i][0]+=min(dp[i-1][0], dp[i-1][1]+1);
      dp[i][1]+=min(dp[i-1][0], dp[i-1][1]-1);
    }
  }

  ll ans = min(dp[n-1][0], dp[n-1][1]+1);
  cout<<ans<<endl;
}


Measured memory_bytes: 55964
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include <numeric>
#include<map>
 
 
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1e13
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
 
typedef long long int ll;
#define MOD 1000000007


/*nまでの素数を列挙して配列に保持*/
vector<int> Eratosthenes(int n,vector<int>& arr){

	for(int i = 0; i < n;i++){
		arr[i] = 1;
    }
    arr[0] = arr[1] = 0;

	for(int i = 2; i < sqrt(n); i++){
		if(arr[i]){
			for(ll j = 0; i * (j + 2) < n; j++){
				arr[i *(j + 2)] = 0;
			}
		}
    }
    return arr;
}


int main(){


    int n;
    int tmp = 50001;
    vector<int> arr(tmp);


    arr = Eratosthenes(tmp,arr);/*50000までの素数を列挙*/
    
    while(cin >> n,n){
        int count = 0;
        for(int i = 2;i <= n/2;i++){

            if(i <= n-i && arr[i] && arr[n-i]){
                count++;
            }
        }
        cout << count << endl;
    }
    
    
    return 0;
}


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

#define FOR(i, a, b) for (int i = a; i < (int) b; i++)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (int i = a; i >= (int) b; i--)
#define R0F(i, a) ROF(i, a, 0)
#define GO(i, a) for (auto i : a)

#define f first
#define s second
#define eb emplace_back
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<vpii> vvpii;
typedef long long i64;

const int dr[] = {+1, -1, +0, +0, +1, -1, +1, -1};
const int dc[] = {+0, +0, +1, -1, +1, -1, -1, +1};
const int ms[] = {+31, +29, +31, 30, +31, +30, +31, +31, +30, +31, +30, +31};

int main () {
  ios::sync_with_stdio(0);
  cin.tie(0);
  const int n = 3;
  set<int> vis;
  F0R (i, n) {
    int foo;
    cin >> foo;
    vis.insert(foo);
  }
  cout << (sz(vis) == 2 ? "Yes" : "No") << '\n';
  return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
string a;bool flag=1;
int main(){
	cin>>a;
	for(register int i=0;i<a.length() ;i+=2){
		if(!(a[i]=='R'||a[i]=='U'||a[i]=='D')){
			flag=0;break;
		}
	}
	for(register int i=1;i<a.length() ;i+=2){
		if(!(a[i]=='L'||a[i]=='U'||a[i]=='D')){
			flag=0;break;
		}
	}
	if(flag) cout<<"Yes";
	else cout<<"No";
}

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

int main() {
  int x,y;
  cin >> x >> y;
  
  int group[] = {1,3,1,2,1,2,1,1,2,1,2,1};
  
  if ( group[x-1] == group[y-1] ) {
    cout << "Yes";
  } else {
    cout << "No";
  }
  cout << endl;

  
}


Measured memory_bytes: 256
#include <stdio.h>
long long n, a, x, ans;
long long l[200002];
long long r[200002];
long long p[200002];
int main() {
	scanf("%lld", &n);
	for (long long i = 1; i <= n; i++) {
		l[i] = i - 1;
		r[i] = i + 1;
	}
	for (long long i = 1; i <= n; i++) {
		scanf("%lld", &a);
		p[a] = i;
	}
	for (int i = n; i; i--) {
		x = p[i];
		ans += i * (r[x] - x) * (x - l[x]);
		l[r[x]] = l[x];
		r[l[x]] = r[x];
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 4864
<?php
fscanf(STDIN,"%d",$n);
$arr=explode(' ',trim(fgets(STDIN)));

if($n==1){
	echo "Yes";
}else{
	$min=0;
	$cnt=0;
	for($i=0;$i<$n-1;++$i){
		if($arr[$i]>$min){
			$min=$arr[$i];
		}
		if($arr[$i+1]<$min-1){
			break;
		}else{
			$cnt++;
		}
	}
	if($cnt==$n-1){
		echo "Yes";
	}else{
		echo "No";
	}
}
?>

Measured memory_bytes: 14840
#include <vector>
#include <bitset>
#include <iostream>

constexpr char ALPHA = 'a';
constexpr int ONE = 1;

int main()
{
  int N;
  std::cin >> N;
  std::vector<int> S(N);
  for(auto& s : S) {
    char c;
    std::cin >> c;
    s = ONE << (c - ALPHA);
  }
  int Q;
  std::cin >> Q;
  while (Q--) {
    int q;
    std::cin >> q;
    if (q == ONE) {
      int i;
      char c;
      std::cin >> i >> c;
      S[i - 1] = 1 << (c - ALPHA);
    } else {
      int r, l;
      std::cin >> r >> l;
      --r;
      int res{};
      for (int i = r; i < l; ++i) {
          res |= S[i];
      }
      std::bitset<32> ans(res);
      std::cout << ans.count() << '\n';
    }
  }
  return 0;
}

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

int main() {
  string s;
  cin >> s;
  string ans = "Good";
  for (int i = 1; i < 4; i ++) {
    if (s[i] == s[i - 1]) ans = "Bad";
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import Data.Char
import Data.List

replace :: String -> String
replace [] = []
replace (x:xs)
    | x == 'D' = "U" ++ replace xs
    | x == 'U' = "D" ++ replace xs
    | x == 'L' = "R" ++ replace xs
    | x == 'R' = "L" ++ replace xs
    | otherwise = x : replace xs


solve :: Int -> Int -> String
solve x y = (rep $ short x y) ++ (rep $ long x y)

short :: Int -> Int -> String
short 0 0 = []
short 0 n = "U" ++ short 0 (n - 1)
short m n = "R" ++ short (m - 1) n

long :: Int -> Int -> String
long x y = "D" ++ short (x + 1) (y + 1) ++ "L"

rep :: String -> String
rep s = s ++ replace s

main = do
    [a,b,c,d] <- fmap (read :: String -> Int) . words <$> getLine
    putStrLn $ solve (c-a) (d-b)

Measured memory_bytes: 1148
#include<bits/stdc++.h>
#define int long long
using namespace std;
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 (a>b) { a=b; return 1; } return 0; }

struct edge{int to,cost;};
typedef pair<int,int> pint;
const int INF=1e9;

vector<pint> solve(vector<vector<edge>> &G,int s,int L)
{
    int N=G.size();
    vector<pint> dist(N,{INF,0});
    dist[s]={0,-L};
    priority_queue<pair<pint,int>,vector<pair<pint,int>>,greater<pair<pint,int>>> Q;
    Q.push({dist[s],s});

    vector<bool> finished(N,false);
    while(!Q.empty()){
        int v=Q.top().second; 
        Q.pop();
        if(finished[v]) continue;

        finished[v]=true;
        for(edge e:G[v]){
            if(-dist[v].second>=e.cost){
                pint nxtDist={dist[v].first,dist[v].second+e.cost};
                if(chmin(dist[e.to],nxtDist)){
                    Q.push({nxtDist,e.to});
                }
            }
            pint nxtDist={dist[v].first+1,-L+e.cost};
            if(chmin(dist[e.to],nxtDist)){
                Q.push({nxtDist,e.to});
            }
        }
    }
    return dist;
}

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

    int N,M,L; cin>>N>>M>>L;
    vector<vector<edge>> G(N);
    for(int i=0;i<M;i++){
        int a,b,c; cin>>a>>b>>c;
        a--; b--;
        if(c>L) continue;
        G[a].push_back({b,c});
        G[b].push_back({a,c});
    }
    vector<vector<pint>> ans(N);
    for(int i=0;i<N;i++){
        ans[i]=solve(G,i,L);
    }
    int Q; cin>>Q;
    while(Q--){
        int s,t; cin>>s>>t;
        s--; t--;
        cout<<(ans[s][t].first==INF? -1:ans[s][t].first)<<endl;
    }
    return 0;
}

Measured memory_bytes: 5648
#!/usr/bin/env python
# coding: utf-8

# In[16]:


N,A,B = map(int, input().split())
S = input()


# In[17]:


ab = A+B
ab_count = 0
b_count = 0
for s in list(S):
#     print(s)
    if s == "a":
        if ab_count < ab:
            print("Yes")
            ab_count += 1
        else:
            print("No")
    elif s == "b":
        if ab_count < ab and b_count < B:
            print("Yes")
            ab_count += 1
            b_count += 1
        else:
            print("No")
    else:
        print("No")


# In[ ]:






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

int main() {
    int N, M; cin >> N >> M;
    vector< vector<int> > jobs(M); //i日かかる仕事の報酬を保存

    
    rep(i, N) {
        int a, b;
        cin >> a >> b;
        if (a > M) continue;
        jobs[M-a].push_back(b);
    }
    priority_queue<int> pque;
    int res = 0;
    for (int i=M-1; i>=0; i--) {
        for (int b : jobs[i]) {
            pque.push(b);
        }
        if (!pque.empty()) {
            res += pque.top();
            pque.pop();
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 5632
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;
typedef long long ll;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

const int maxn = (int) 1e5 + 5;
int w, h;
int p[maxn], q[maxn];
pair<int, int> a[2 * maxn];

int read() {
  if (scanf("%d%d", &w, &h) < 2) {
    return false;
  }
  for (int i = 0; i < w; i++) {
    scanf("%d", &p[i]);
  }
  for (int i = 0; i < h; i++) {
    scanf("%d", &q[i]);
  }
  return true;
}

void solve() {
  for (int i = 0; i < w; i++) {
    a[i] = make_pair(p[i], 0);
  }
  for (int i = 0; i < h; i++) {
    a[w + i] = make_pair(q[i], 1);
  }
  sort(a, a + w + h);
  int rows = h + 1, cols = w + 1;
  long long ans = 0;
  for (int i = 0; i < w + h; i++) {
    int x = a[i].first;
    if (a[i].second) {
      ans += (long long)x * cols;
      rows--;
    } else {
      ans += (long long)x * rows;
      cols--;
    }
  }
  printf("%lld\n", ans);
}

int main() {
  precalc();
#ifdef LOCAL
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (true) {
    if (!read()) {
      break;
    }
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


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

int main(){
  int N,K;
  cin >> N >> K;
  int x,ret=0;
  for(int i = 0; i < N; ++i){
    cin >> x;
    ret += 2*min(abs(x),abs(K-x));
  }
  cout << ret << endl;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main implements Runnable {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        // Run with 32MB stack
        Thread thread = new Thread(null, new Main(), "", 32 * 1024 * 1024);
        thread.start();
    }

    @Override
    public void run() {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }

    static void solve(Scanner scanner) {
        int[] a = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
        int Q = a[1];
        String s = scanner.nextLine();
        int[] cnt = new int[s.length()];
        char prev = s.charAt(0);
        for (int i = 1; i < s.length(); i++) {
            cnt[i] += cnt[i - 1];
            if (prev == 'A') {
                if (s.charAt(i) == 'C') {
                    cnt[i]++;
                }
            }
            prev = s.charAt(i);
        }

        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < Q; i++) {
            int b = scanner.nextInt();
            int c = scanner.nextInt();
            sb.append(cnt[c - 1] - cnt[b - 1]);
            sb.append('\n');
        }
        System.out.println(sb);
    }
}

Measured memory_bytes: 74044
//Abraao Caiana de Freitas - UFCG

#include <bits/stdc++.h>
using namespace std;
#define maxx 100100
#define mp make_pair
#define sec second
typedef pair<int,int> ii;
typedef long long ll;
int dp[maxx],h[maxx];
int main(){
    ios_base::sync_with_stdio(false);    
    cin.tie(NULL);
    int n,k;
    cin >> n >> k;
    for(int i = 1; i <= n; i++){
        cin >> h[i];
        dp[i] = 1e9;
    }
    dp[1] = 0;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= k; j++){
            if(i > j) dp[i] = min(dp[i-j] + abs(h[i]-h[i-j]),dp[i]); 
        }
    }
    cout << dp[n] << "\n";
    return 0;
}

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

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

template <typename T> T id(T b) {return b;};
template <class It> bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It> bool any(It f,It l){return std::any_of(f,l,id<bool>);}
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}

const int MAX_N = 100000;
int n;
ll a[MAX_N];

int main()
{
#ifdef FASTIO
  ios_base::sync_with_stdio(false); cin.tie(nullptr);
#endif

  cin >> n;
  forn(i,n) cin >> a[i];

  ll v = 0;
  forn(i,n) {
    v = -v+a[i];
  }

  cout << v << " ";
  forn(i,n-1) {
    ll cur = a[i]-v/2;
    cout << 2LL*cur << " ";
    v = 2LL*cur;
  }
  cout << endl;


  return 0;
}


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

using namespace std;

#define ll long long

int main()
{

    ll a,n,s=0;
    cin >> n >> a;
    ll arr[n];
    for(int i=0;i<n;i++)
        cin >> arr[i];
    sort(arr,arr+n);

    for(int i=0;i<n-a;i++)
        s+=arr[i];
    cout << s<< endl;
    return 0;
}


Measured memory_bytes: 1792
# C
n, m = map(int, input().split())
ab = [[int(i) for i in input().split()] for i in range(n)]
ab.sort(key=lambda x: x[0])
index = 0
ans = 0
while m > 0 and index <= n:
    if ab[index][1] <= m:
        ans += ab[index][0] * ab[index][1]
        m -= ab[index][1]
    else:
        ans += ab[index][0] * m
        m = 0
    index += 1
print(ans)

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

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

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


const long long MOD = 1000000007;
const long long INF = 1LL << 60;
#define int long long

const int MAX_N = 1010;


signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	VE a(n); rep(i, n)cin >> a[i];
	int ans = n;
	int cnt = 0;
	rep(i, n) {
		if (a[i] % 4 == 0)cnt += 2;
	}
	if (cnt != 0)ans -= cnt + 1;
	cnt = 0;
	rep(i, n) {
		if (a[i] % 4 != 0 && a[i] % 2 == 0)cnt++;
	}
	ans -= cnt / 2 * 2;
	Yes(ans <= 0);
	return 0;
}


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

int main(){
  int H,W;
  while(cin >> H >> W){
    if(H==0&&W==0)
      break;
    for(int w=0; w<W; w++){
      cout << "#";
    }
   cout << endl;
    for(int h=1; h<H-1; h++){
      cout << "#";
      for(int w=1; w<W-1; w++){
        cout << ".";
      }
      cout << "#";
      cout << endl;
    }
    for(int w=0; w<W; w++){
      cout << "#";
    }
    cout <<endl;
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 3052
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <ctime>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <memory.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef long double LD;
typedef long long LL;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#ifdef LOCAL
#define DEBUG(x) { cerr << "# " << #x << ": " << x << endl;}
#else
#define DEBUG(x)
#endif
mt19937_64 mt(time(0));
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/
const int mod = 1e9 + 7;
const int MAXN = 5000 + 10;
int p[MAXN], par[MAXN], cnt[MAXN], dp[MAXN][MAXN], fact[MAXN];
bool has[MAXN];

int find(int i) {
  if (par[i] == i) return i;
  return par[i]=find(par[i]);
}

void add(int i, int j) {
  int a = find(i);
  int b = find(j);
  par[a] = b;
}

LL power(LL base, LL p) {
  LL ret = 1;
  base = base % mod;
  while (p) {
    if (p&1) ret = ret * base % mod;
    p >>= 1;
    base = base * base % mod;
  }
  return ret;
}




int main() {
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  cout.precision(10); cout << fixed;
#ifdef LOCAL
  freopen("../test.txt", "r", stdin);
    // freopen("../output.txt", "w", stdout);
#endif
  LL n; cin >> n;
  fact[0] = 1;
  for (int i = 1; i <= n; i++) {
    fact[i] = 1LL * fact[i-1] * i % mod;
  }
  for (int i = 1; i <= n; i++) {
    cin >> p[i];
    par[i] = i;
  }
  for (int i = 1; i <= n; i++) {
    if (p[i] == -1) continue;
    add(i, p[i]);
  }
  vector<int> nums;
  int a = 0;
  for (int i = 1; i <= n; i++) {
    int tmp = find(i);
    cnt[tmp]++;
    if (cnt[tmp] == 1) a++;
    if (p[i] == -1) {
      assert(!has[tmp]);
      has[tmp] = true;
      nums.push_back(tmp);
    }
  }
  int b = nums.size();
  a = a - b;
  LL ret = power(n-1, b) * (n-a) % mod;
  dp[0][0] = 1;
  for (int i = 0; i < b; i++) {
    for (int j = 0; j <= i+1; j++) {
      dp[i+1][j] = dp[i][j];
      if (j-1 >= 0) dp[i+1][j] = (dp[i+1][j] + (LL)dp[i][j-1] * cnt[nums[i]] % mod) % mod;
    }
  }
  for (int i = 2; i <= b; i++) {
    LL tmp = power(n-1, b-i) * dp[b][i] % mod * fact[i-1] % mod;
    ret = (ret - tmp + mod) % mod;
  }
  if (b >= 1) {
    LL tmp = power(n-1, b-1);
    for (int i : nums) {
      ret = (ret - tmp * (cnt[i]-1) % mod + mod) % mod;
    }
  }

  cout << ret << '\n';













/*---------------------------------------Coding Space End------------------------------------------*/
#ifdef LOCAL
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s." << endl;
#endif
  return 0;
}
/* author:  txingml */
/* picture is from hamayanhamayan(CF handle) */


Measured memory_bytes: 69964
count=[[[0 for i in range(10)] for j in range(3)] for k in range(4)]

n=int(input())
kugiri_ck=0

for num in range(n):
    building,floor,room,population=map(int,input().split(" "))
    count[building-1][floor-1][room-1]+=population

for building in count:
    if kugiri_ck!=0:
        print("#"*20)
    kugiri_ck+=1
    
    for floor in building:
        for room in floor:
            print('{:>2}'.format(room),end="")
        print()



Measured memory_bytes: 5636
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cerr<<#x<<'='<<x<<' '
typedef long long ll;
typedef pair<int,int> pi;

bool cmp(pi a, pi b) {
	if (a.second != b.second) return a.second > b.second;
	return a.first > b.first;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int N;
	cin >> N;
	vector<pi> v1,v2;
	vector<int> used(N);
	for (int i = 0; i < N; i++) {
		int a,b; cin >> a >> b;
		v1.emplace_back(a,b); // red
	}
	for (int i = 0; i  < N; i++) {
		int a,b; cin >> a >> b;
		v2.emplace_back(a,b); // blue
	}
	sort(v1.begin(),v1.end(),cmp);
	sort(v2.begin(),v2.end());
	int ans = 0;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			if (!used[j] && v1[j].second < v2[i].second && v1[j].first < v2[i].first) {
				ans++;
				used[j] = 1;
				break;
			}
		}
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	//"sort"
	"math"
	"regexp"

)
func abs(x int)int{
	return int(math.Abs(float64(x)))
}

func max(x...int) int{
	var res int = x[0]
	for i:=1;i<len(x);i++{
		res = int(math.Min(float64(res),float64(x[i])))
	}
	return res
}

type Sortby []int
func (a Sortby) Len()int {return len(a)}
func (a Sortby) Swap(i,j int) {a[i],a[j] = a[j],a[i]}
func (a Sortby) Less(i,j int)bool { return abs(a[i]) > abs(a[j]) }


func reg(x,y string)bool {
	r:= regexp.MustCompile(x)
	return r.MatchString(y)
}

var X,Y,Z int
func main(){
	fmt.Scan(&X,&Y,&Z)

	X = X - Z
	fmt.Println(X/(Y+Z))
}

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

int main(){
    int A,B;
    cin >> A >> B;
    if(A>B){
        cout << 2*A-1 << endl;
    }
    else if(A==B){
        cout << A+B << endl;
    }
    else {
        cout << 2*B-1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

N = int(input())
ans = 0
for _ in range(N):
    u,x = input().split()
    if x == 'JPY':
        ans += float(u)
    else:
        ans += float(u)*380000

print(ans)


Measured memory_bytes: 4212
use std::io::Read;
use std::cmp::{max, min};

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();

    let mut ans: usize = 100;
    for a in 1.. {
        if a * a > n {
            break;
        }
        if n % a != 0 {
            continue;
        }
        let b = n / a;
        ans = min(ans, f(a, b));
    }
    return ans.to_string();
}

fn f(a: usize, b: usize) -> usize {
    let a_len = format!("{}", a).len();
    let b_len = format!("{}", b).len();
    return max(a_len, b_len);
}


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

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = ReadInt();
            var A = ReadArrayInt();
            A = A.OrderByDescending(i => i).ToArray();
            long ans1 = 0, ans2 = 0;
            var chk = 0;
            var cnt = 0;
            for (int i = 0; i < N; i++)
            {
                if (chk == A[i]) cnt++;
                else
                {
                    if (cnt >= 4)
                    {
                        if (ans1 == 0) { ans1 = chk; ans2 = chk; break; }
                        else { ans2 = chk;  break; }
                    }
                    else if (cnt >= 2)
                    {
                        if (ans1 == 0) ans1 = chk;
                        else { ans2 = chk;  break; }
                    }
                    chk = A[i];
                    cnt = 1;
                }
            }
            if (cnt >= 4)
            {
                if (ans1 == 0) { ans1 = chk; ans2 = chk; }
                else ans2 = chk;
            }
            else if (cnt >= 2)
            {
                if (ans1 == 0) ans1 = chk;
                else ans2 = chk;
            }

            Console.WriteLine(ans2 != 0 ? ans1 * ans2 : 0);
            Console.ReadLine();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}

Measured memory_bytes: 24544
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {

        static void Main(string[] args)
        {

            //Console.SetIn(new StreamReader("input.txt"));
            var ints = In.Ints();

            var c5 = ints.Where(i => i == 5).Count();
            var c7 = ints.Where(i => i == 7).Count();

            if(c5 == 2 && c7 == 1)
            {
                Console.WriteLine("YES");
            }else
            {
                Console.WriteLine("NO");
            }

            return;
        }
    }




    class In
    {
        public static int Int()
        {
            return int.Parse(Console.ReadLine());
        }

        public static IEnumerable<int> Ints()
        {
            return Console.ReadLine().Split(' ').Select(i => int.Parse(i));
        }
    }
}


Measured memory_bytes: 3032
#include <iostream>

int anslist[2001];

void inputdata(int *n, int **A, int *q, int **m)
{
  std::cin >> *n;
  *A=new int[*n];

  for(int i=0; i<*n; i++)
    std::cin >> (*A)[i];

  std::cin >> *q;
  *m = new int [*q];
  for(int i=0; i<*q; i++)
    std::cin >> (*m)[i];
}

void calcnum(int n, int A[], int sum, int index)
{
  if (index == n)
  {
    if (0 <= sum && sum <=2000)
    {
      anslist[sum] = 1;

    }
  }else{
    calcnum(n,A,sum+A[index], index+1);
    calcnum(n,A,sum,index+1); 
  }
}

int main(void)
{
  int n, *A, q, *m;
  for(int i =0; i<2001; i++)
    anslist[i] = 0;

  inputdata(&n, &A, &q, &m);
  calcnum(n,A,0,0);

  for(int i = 0; i<q; i++)
    std::cout << ((anslist[m[i]])?"yes":"no") << std::endl;
  

  delete A;
  delete m;

}


Measured memory_bytes: 3112
#include<bits/stdc++.h>
#define se second
#define fi first
using namespace std;
const int maxn = 1e6 + 4, mod = 11092019, maxx = 1e6 + 1;
typedef pair<int,int> ii;
typedef pair<long long, long long> ll;
int n, m, d[maxn], dp[maxn], st[maxn*4], ans, f[maxn], wans, w[maxn*4];
vector<int> a[maxn];
vector<ii> V;

void _accepted_by_one_hit_()
{
    #ifdef NTMA
        freopen("abc.inp", "r", stdin);
        freopen("abc.out", "w", stdout);
    #endif
    ios::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
}
int main()
{
    _accepted_by_one_hit_();

    int n;
    cin >> n;
    cout << n/500*1000 + (n%500)/5*5;
}

Measured memory_bytes: 24832
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007;

template<class _T> static void getint(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void getint(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
template<class _T> static void getint(_T& a, _T& b, _T& c) {
	const char* fmt = " %d %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld %lld";
	}

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}

static void diverta2019PC2C();

#if 1
int main()
{
	diverta2019PC2C();
	fflush(stdout);
	return 0;
}
#endif

static void diverta2019PC2C()
{
	int N;
	getint(N);

	std::deque<int> pque, mque;
	int absMax = 0, maxVal = 0;
	for (int i = 0; i < N; i++) {
		int a;
		getint(a);
		if (a >= 0) {
			pque.insert(std::lower_bound(pque.begin(), pque.end(), a), a);
		}
		else {
			mque.insert(std::lower_bound(mque.begin(), mque.end(), a), a);
		}
	}

	std::vector<std::pair<int, int>> proc;
	while ((mque.size() + pque.size()) > 1) {
		int first = 0, second = 0;
		if (!mque.empty() && pque.empty()) {
			if (mque.size() > 2) {
				first = mque.back();
				mque.pop_back();
				second = mque.back();
				mque.pop_back();
			}
			else {
				second = mque.back();
				mque.pop_back();
				first = mque.back();
				mque.pop_back();
			}
		}
		else if (mque.empty() && !pque.empty()) {
			if (pque.size() > 2) {
				second = pque.front();
				pque.pop_front();
				first = pque.front();
				pque.pop_front();
			}
			else {
				first = pque.front();
				pque.pop_front();
				second = pque.front();
				pque.pop_front();
			}
		}
		else if (!mque.empty() && !pque.empty()) {
			if (pque.size() == 1) {
				first = mque.front();
				mque.pop_front();
				second = pque.front();
				pque.pop_front();
			}
			else {
				second = mque.front();
				mque.pop_front();
				first = pque.front();
				pque.pop_front();
			}
		}
		proc.push_back(std::pair<int, int>(second, first));
		int newVal = second - first;
		if (newVal >= 0) {
			pque.insert(std::lower_bound(pque.begin(), pque.end(), newVal), newVal);
		}
		else {
			mque.insert(std::lower_bound(mque.begin(), mque.end(), newVal), newVal);
		}
	}
	int ans = (!pque.empty() ? pque.front() : mque.front());
	printf("%d\n", ans);
	for (auto it = proc.begin(); it != proc.end(); it++) {
		printf("%d %d\n", it->first, it->second);
	}
}


Measured memory_bytes: 3064
#include <cstdio>
#include <algorithm>

using namespace std;
#define rep(i,b) for(int i=0; i<b; i++)
typedef unsigned long long ull;

ull const mod = 100000007;
ull dp[1000000][6] = {};

ull divn(int n, int div){
    ull& res = dp[n][div];
    if (res) return res;

    res = 1;
    if (n == 1) return res;
    
    rep(i, min(div, n - 1)){
        res = res + divn(n - (i+1), div) % mod;
    }
    return res;
}

int main(){
    int a[10];
    rep(i, 10) a[i] = 5;
    a[8] = a[0] = 3;

    int prod = 1, len = 0;
    char cur = -1, prev = -1;
    while (1){
        prev = cur;
        cur = getchar();
        if (cur == '#') break;
        else if (cur != prev){
            if (prev != -1) prod = prod*divn(len, a[prev - '0']) % mod;
            if (cur == '\n'){
                len = 0;
                printf("%d\n", prod);
                cur = -1;
                prod = 1;
            }
            else {
                len = 1;
            }
        }
        else if (prev == -1 || cur == prev){
            len++;
        }
    }
}

Measured memory_bytes: 11124
//The comment below is the wrong answer
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

using ll = long long;

int main(int argc,char* argv[]){
    ll a,b,v,w,t;
    cin >> a >> v >> b >> w >> t;

    //bool ans=false;

    if(v<=w){
        cout << "NO" << endl;
        return 0;
    }

    ll dist=abs(b-a);
    ll ver=v-w;

    if(ver*t>=dist){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    
    /*int ap=a,bp=b;
    for(int i=1;i<=t;i++){
        if(ap<bp){
            if(ap+v<=pmax)
                ap+=v;
            else
                ap-=v;
            if(bp+w<=pmax)
                bp+=w;
            else
                bp-=w;
        }
        if(ap>bp){
            if(ap-v>=mmax)
                ap-=v;
            else
                ap+=v;
            if(bp-w>=mmax)
                bp-=w;
            else
                bp+=w;
        }
        if(ap==bp){
            ans=true;
            break;
        }
    }
    if(ans==true)
        cout << "YES" << endl;
    else
        cout <<"NO" << endl;*/

    return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>  
#include <memory>
using namespace std;  
#define INF 0x3f3f3f3f  
typedef long long ll;  
const int N =  100005;  
#define FI first
#define SE second
typedef pair<int, int>pii;
int mod = 1000000007;
 
 
int main()  
{  

   // ios::sync_with_stdio(0);
   int a, b;
   while (cin >> a >> b)
      if ((a+b)%3 == 0 || a%3 == 0 || b%3 == 0)puts("Possible");
   else
      puts("Impossible");
   return 0;
}  

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

int main()
{
    ll n, q;
    vector<ll> a, b, e;
    cin >> n;
    a.resize(n);
    for (auto &x : a)
        cin >> x;

    cin >> q;
    b.resize(q);
    e.resize(q);
    rep(i, q)
    {
        cin >> b[i] >> e[i];
        reverse(a.begin() + b[i], a.begin() + e[i]);
    }

    rep(i, n) cout << ((i) ? " " : "") << a[i];
    cout << endl;

    return 0;
}


Measured memory_bytes: 3096
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
using namespace std;

int main(){
    int k;
    cin >> k;

    queue<long long int> Q;
    int keta = 1;
    int count = 0;
    for(long long int i = 1; i <= 9; i++) Q.push(i);

    long long int res;
    while(count < k){
        res = Q.front();
        count++;
        Q.pop();
        for(long long int i = 0; i <= 9; i++){
            if(abs(i - (res%10)) <= 1) Q.push(res*10+i);
        }
    }

    cout << res << endl;


    return 0;
}

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

int main(){
  int n,a,b,c,x,f[10001],now,key[100],i;
  while(1){
    cin>>n>>a>>b>>c>>x;
    if(n==0)break;
    f[0]=x;
    for(i=1;i<=10000;i++)f[i]=(f[i-1]*a+b)%c;
    for(i=0;i<n;i++)cin >>key[i];
    now=0;
    for(i=0;i<=10000;i++){
      if(key[now]==f[i])now++;
      if(now>=n)break;
    }
    if(i==10001)cout << "-1"<<endl;
    else cout << i<<endl;
  }
  return 0;
}

Measured memory_bytes: 1196
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner stdn = new Scanner(System.in);
		int a = 0;
		int b = 0;
		
		a = stdn.nextInt();
		b = stdn.nextInt();
		
		int x = 0;
		int y = 0;
		
		x = a*b;
		y = (a*2)+(b*2);
		
		System.out.println(x + " " + y);
	}
}

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

int main()
{
    int H, N, A, T, r;
    cin >> H >> N;
    for(int i = 0; i < N; i++)
    {
        cin >> T;
        A += T;
    }
    if(H <= A)
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
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 main() {
    int n;
    cin >> n;
    vector<P>p(n);
    rep(i,n) {
        int a,b;
        cin >> a >> b;
        swap(a,b);
        p[i].first = a;p[i].second = b;
    }
    sort(p.begin(),p.end());
    ll sum = 0;
    bool ok = true;
    rep(i,n) {
        sum += p[i].second;
        if(sum > p[i].first) {
            ok = false;
            break;
        }
    }
    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		System.out.println((N + M) * (N + M - 1) / 2 - N * M);
	}
}

Measured memory_bytes: 23764