akhauriyash/Code-Regression huggingface dataset:
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
from fractions import gcd
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n,a,b = readInts()
    S = input()
    ab = a + b
    passed = 0
    ovs = 1
    for i in range(n):
        if S[i] == 'a':# 国内
            if passed < ab:
                print('Yes')
                passed += 1
            else:
                print('No')
        if S[i] == 'b':
            if passed < ab and ovs <= b:
                print('Yes')
                passed += 1
                ovs += 1
            else:
                print('No')
        if S[i] == 'c':
            print('No')

if __name__ == '__main__':
  main()


Measured memory_bytes: 6332
#[allow(unused_imports)]
use std::cmp;
use std::io::Write;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    let s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

macro_rules! input_inner {
  ($iter:expr) => {};
  ($iter:expr, ) => {};

  ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
    let $var = read_value!($iter, $t);
    input_inner!{$iter $($r)*}
  };
}

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
    ( $(read_value!($iter, $t)),* )
  };

  ($iter:expr, [ $t:tt ; $len:expr ]) => {
    (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  };

  ($iter:expr, chars) => {
    read_value!($iter, String).chars().collect::<Vec<char>>()
  };

  ($iter:expr, usize1) => {
    read_value!($iter, usize) - 1
  };

  ($iter:expr, [ $t:tt ]) => {{
    let len = read_value!($iter, usize);
    (0..len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  }};

  ($iter:expr, $t:ty) => {
    $iter.next().unwrap().parse::<$t>().expect("Parse error")
  };
}

fn main() {
  let out = std::io::stdout();
  let mut out = std::io::BufWriter::new(out.lock());
  macro_rules! puts {
    ($($format:tt)*) => (write!(out,$($format)*).unwrap());
  }
  input! {
    n: usize,
    m: usize,
    aa: [usize; n],
  }
  let max_a = *aa.iter().max().unwrap();
  let mut sum = vec![0; max_a * 2 + 2];
  for &a in &aa {
    sum[a] += 1;
  }
  for i in 0 .. sum.len() - 1 {
    sum[i+1] += sum[i];
  }
  let mut l = 0;
  let mut r = max_a * 2 + 1;
  while l + 1 != r {
    let x = (l + r) / 2;
    let mut count = 0;
    for &a in &aa {
      count += n - sum[x.saturating_sub(a+1)];
    }
    if count >= m {
      l = x;
    } else {
      r = x;
    }
  }
  // dbg!(l);
  let lb = l;
  let mut count = 0;
  let mut ans = 0;
  for &a in &aa {
    let c = n - sum[lb.saturating_sub(a+1)];
    ans += a * c * 2;
    count += c;
  }
  ans -= lb * (count - m);

  puts!("{}\n", ans);
}


Measured memory_bytes: 8444
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,s,n) for(int i=s;i<n;i++)
#define per(i,s,n) for(int i=n-1;i>=s;i--)
#define fi first
#define se second
#define all(c) c.begin(),c.end()
typedef long long int ll;
typedef pair<int, int> P;
typedef long double ld;
void Ans(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}

const ll INF=1001001001;
const ll mod=1000000007;

int main(){
  ll n,m,k;
  cin>>n>>m>>k;
  ll a[n],b[m];
  rep(i,n) cin>>a[i];
  rep(i,m) cin>>b[i];
  int nn=0,nm=0;
  int ans=0;
  
  while(a[nn]<=k&&nn<n){
    k-=a[nn];
    nn++;
  }
  while(b[nm]<=k&&nm<m){
    k-=b[nm];
    nm++;
  }
  ans=nm+nn;

  while(nn>0){
    nn--;
    k+=a[nn];
    while(b[nm]<=k&&nm<m){
    	k-=b[nm];
    	nm++;
  	}
    ans=max(nm+nn,ans);
  }
  
  cout<<ans<<endl;
}



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

int gcd(int x, int y) {
  int a = max(x, y);
  int b = min(x, y);
  if(a % b == 0) {
    return b;
  }
  else {
    return gcd(b, a % b);
  }
}

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  vector<bool> judge(1000000, false);
  bool stop = false;
  for(int i = 0; i < N; i++) {
    int x = A.at(i);
    for(int j = 2; j * j <= A.at(i); j++) {
      if(x % j == 0) {
        if(judge.at(j - 1)) {
          stop = true;
          break;
        }
        else {
          judge.at(j - 1) = true;
          while(x % j == 0) {
            x /= j;
          }
        }
      }
    }
    int64_t y = x;
    int64_t z = A.at(i);
    if(y * y > z) {
      if(judge.at(x - 1)) {
        stop = true;
      }
      else {
        judge.at(x - 1) = true;
      }
    }
    if(stop) {
      break;
    }
    if(i == N - 1) {
      cout << "pairwise coprime" << endl;
      return 0;
    }
  }
  int keep = gcd(A.at(0), A.at(1));
  for(int i = 2; i < N; i++) {
    keep = gcd(keep, A.at(i));
  }
  if(keep == 1) {
    cout << "setwise coprime" << endl;
    return 0;
  }
  cout << "not coprime" << endl;
}

Measured memory_bytes: 7208
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <bitset>
#include <climits>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define RFOR(i,a,b) for (int i=(a)-1;i>=(b);i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int INF = 1e9;
const int MOD = 1e9 + 7;

using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
	int s[100003],t[50003];
	int n,q;
	cin>>n;REP(i,n)cin>>s[i];
	cin>>q;REP(i,q)cin>>t[i];
	int ct = 0;
	REP(i,q){
		int l = 0;
		int r = n;
		while(abs(r-l) > 1){
			int mid = (r+l)/2;
			if(t[i]<s[mid])r = mid;
			else l = mid;
		}
		if(s[(r+l)/2]==t[i])ct++;
	}
	cout << ct << endl;
  return 0;
}

Measured memory_bytes: 3756
#include<stdio.h>

int main(void)
{
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(a<=b)
	{
		if(b<=c)
		{
			printf("%d %d %d\n",a,b,c);
		}
		else if(a<=c)
		{
			printf("%d %d %d\n",a,c,b);
		}
		else if(a>=c)
		{
			printf("%d %d %d\n",c,a,b);
		}
	}
	else
	{
		if(a<=c)
		{
			printf("%d %d %d\n",b,a,c);
		}
		else if(b<=c)
		{
			printf("%d %d %d\n",b,c,a);
		}
		else if(b>=c)
		{
			printf("%d %d %d\n",c,b,a);
		}
	}

	return 0;
}	


Measured memory_bytes: 2668
X = int(input())

while True:
    isDivisible = False
    divider = 2
    while not isDivisible or divider < X:
        isDivisible = (X % divider == 0)

        if isDivisible:
            break
        else:
            divider += 1

    if divider == X:
        break
    else:
        X += 1

print(X)


Measured memory_bytes: 38768
#include <iostream>
#include <cstdint>
#include <algorithm>

int64_t a[100000];

int main() {
	int n, x;
	std::cin >> n >> x;

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

	int64_t ans = 0;
	if (a[0] > x) {
		ans += a[0] - x;
		a[0] = x;
	}
	for (int i = 1; i < n; ++i) {
		auto dec = std::max<int64_t>(0, (a[i] + a[i - 1]) - x);
		ans += dec;
		a[i] -= dec;
	}

	std::cout << ans << std::endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>
#include<list>
#include<bitset>

#define FOR(i, a, b) for(int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000

using namespace std;

int main(void) {
	int n, k;
	int sum = 1;

	cin >> n >> k;

	FOR(i, 1, n) {
		if (sum + k > sum * 2) {
			sum *= 2;
			
		}
		else {
			sum += k;
		}
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<map> 

using namespace std;

typedef pair<int,string> P;

vector<P> product;

int main(){
  int n;
  
  cin >> n;
  map<string,int> A;
  product.clear();

  for(int i=0;i<n;i++){
  	
    string name; int num;
    cin >> name >> num;
    
    if( A[name] == 0 ) 
	product.push_back(P(name.size(), name));
    A[name] += num;
    
  }
  sort(product.begin(), product.end());
  
  for(int i=0;i<product.size();i++)
    cout << product[i].second << " " << A[product[i].second] << endl;
    
  return 0;
}


Measured memory_bytes: 3232
n, q = map(int, input().split(' '))
s = str(input())
checker = [0]
counter = 0
for i in range(1, n):
    if s[i-1] == 'A' and s[i] =='C':
        counter += 1
    checker.append(counter)
result = []
for i in range(q):
    L, r = map(int, input().split(' '))
    a = checker[L-1]
    b = checker[r-1]
    result.append(b-a)
for i in result:
    print(i)

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

int main(){
	int a;
	int ans;
	cin>>a;
	ans=a+a*a+a*a*a;
	cout<<ans<<endl;

	return 0;
}

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

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(in.readLine());
    String s = in.readLine();
    in.close();
    String ans = "";
    
    for(int i = 0; i < s.length(); i++) {
      int count = (s.charAt(i)-'A' + n) % 26;
      ans += String.valueOf((char)('A' + count));
    }
    
    System.out.println(ans);
  }
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define rep(i, n) REP(i, 0, n)
const int INF=1e9;
const int MAX=100005;
const int MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define ALL(v) v.begin(), v.end()
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbgmap(mp) for (auto i = mp.begin(); i != mp.end(); ++i) { cout << i->first <<":"<<i->second << endl;}
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

ll ans=0;
ll n,m,k;
Vec swistatus ; //m番目の電球がついている合計値
VV swiconnect ; //i番目のスイッチにはmが所属
Vec p;

void dfs(ll i,ll flag, Vec &status){
    //dbg(i);
    if(flag){
        Vec &target = swiconnect[i];
        rep(i,target.size()){
            status[target[i]]++;
        }
       // dbg(status);
    }
    if(i<n){
        dfs(i+1,0,status);
        dfs(i+1,1,status);
    }else{
        bool comp = true;
        //dbg(status.size());
        rep(i,status.size()){
//            dbg(status[i]);
//            dbg(p[i]);
            if(status[i]%2 != p[i]){
                comp = false;
            }
        }
        //dbg(comp);
        if(comp){
//            dbg(status);
//            dbg(p);
            ans ++;
        }
    }
}

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

    cin>>n>>m;
    swistatus.resize(m);
    swiconnect.resize(n+1);
    p.resize(m);
    rep(i,m){
        cin>>k;
        rep(j,k){
            ll tmp;
            cin>>tmp;
            swiconnect[tmp].pb(i);
        }
    }
    rep(i,m){
        cin>>p[i];
    }
    //dbg(swiconnect);
    //1番スイッチに電球0,2版スイッチに電球0,1.....

    dfs(1,0,swistatus);
    dfs(1,1,swistatus);
    cout<<ans<<endl;
    return  0;
}


Measured memory_bytes: 256
/* Simplicity and Goodness */

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>

// using namespace __gnu_pbds;
using namespace std;
// typedef tree<int, null_type, less<int>, rb_tree_tag,
//             tree_order_statistics_node_update> indexed_set;

void my_dbg() { cout << endl; }
template<typename Arg, typename... Args> void my_dbg(Arg A, Args... B)
{ cout << ' ' << A; my_dbg(B...); }
#define dbg(...)  cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)

#define scn(n) scanf("%d", &n)
#define lscn(n) scanf("%lld", &n)
#define pri(n) printf("%d ", (int)(n))
#define prin(n) printf("%d\n", (int)(n))
#define lpri(n) printf("%lld ", n)
#define lprin(n) printf("%lld\n", n)
#define rep(i,a,b) for(int i=(int)(a); i<(int)(b); i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;

const int inf = INT_MAX;
const int ninf = INT_MIN;
const int mod = 1e9+7;
const int maxN = 2e5+2;


void solve()
{
    int n;
    scn(n);

    vi a(n);

    rep(i, 0, n)
    scn(a[i]);

    // buy stocks only when the next element is greater
    // sell stocks only when the next element is smaller

    ll stocks = 0, have = 1000;

    rep(i, 0, n - 1) {
        if(a[i + 1] > a[i]) {
            stocks += have / a[i];
            have %= a[i];
        }
        if(a[i + 1] < a[i]) {
            have += stocks * a[i];
            stocks = 0;
        }
    }

    have += 1LL * stocks * a[n - 1];

    lprin(have);
}

int main()
{
    int t = 1;
    // scn(t);
    while(t --) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3784
#include <iostream>
#include <cassert>
#include <stack>
#include <math.h>
#define INF 500050
typedef long long ll;
using namespace std;
int a[INF];
int main() 
{
	int n;
	cin>>n;
	for(int i=1; i<=n; i++) {
		cin>>a[i];
	}

	int ans = 0;
	int tot = 1;
	for(int i=1; i<=n; i++)	 {
		if(a[i] == tot) {
			ans++;
			tot++;
		}
	}
	if(tot==1) {
		cout<<"-1"<<endl;
	}else{
		cout<<n-ans<<endl;
	}
	
    return 0;
}


Measured memory_bytes: 1024
N, x = map(int, input().split())
A = [int(x) for x in input().split()]
ans = 0
if A[0] > x:
    ans += A[0] - x
    A[0] = x
for i in range(0, N - 1):
    if A[i] + A[i + 1] > x:
        ans += A[i] + A[i + 1] - x
        A[i + 1] = x - A[i]
print(ans)


Measured memory_bytes: 14252
x,y,z,k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

lis=[]
for i in a:
    for j in b:
        lis.append(i+j)
lis.sort(reverse=True)
ab = lis[:k]

kouho=[]
for sm in ab:
    for tmp in c:
        kouho.append(sm+tmp)

kouho.sort(reverse=True)
kouho = kouho[:k]
for ans in kouho:
    print(ans)

Measured memory_bytes: 151768
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int main(void){
	int n,i;
	ll ans,tmp=0ll;
	string s;
	cin >> s;
	n = s.l_ength();
	reverse(s.begin(),s.end());
	for(i=1; i<n; ++i){
		if(s[i-1]=='C' && s[i]=='B'){
			++tmp;
		}else if(i+1<n && s[i]=='C' && s[i+1]=='B'){
			continue;
		}else if(s[i]=='A'){
			ans += tmp;
		}else{
			tmp = 0ll;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<vector>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main()
{
    int n;
    cin>>n;
    vector<int> P(n+1,0);
    vector<int> dp(n+1,-1);
    P[0]=0;
    for (int i = 1; i < n+1; i++) cin>>P[i];
    dp[0]=0;
    dp[1]=1;
    int min=P[1];
    for (int i = 2; i < n+1; i++)
    {
        if(min>=P[i])
        {
            dp[i]=dp[i-1]+1;
            min=P[i];
        }
        else dp[i]=dp[i-1];
    }
    cout<<dp[n]<<endl;

    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cmath>
#include <complex>
#include <cctype>
#include <cassert>
#include <sstream>
 
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
 
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
 
typedef long long ll;
typedef complex<double> P;
typedef complex<double> Vec;
typedef pair<int, int> pii;
typedef pair<int, pii> p;
 
#define INF (1<<29)
#define INFL (1ll<<60)
#define EPS (1e-10)
#define PI (acos(-1))
const ll MOD = 1000000007ll;

int main() {
	int n;
	string s;
	cin >> n >> s;
	
	int d[112345];
	REP(i, 2) REP(j, 2) {
		d[0] = i;
		d[1] = j;
		
		FOR(k, 2, n) d[k] = d[k - 2] ^ (d[k - 1] == 0) ^ (s[k - 1] == 'o');
		
		
		if (((d[n - 2] == d[0]) ^ d[n - 1]) == (s[n - 1] == 'o') && ((d[1] == d[n - 1]) ^ d[0]) == (s[0] == 'o')) {
			REP(k, n) putchar(d[k]?'W':'S');
			puts("");
			return 0;
		}
	}
	puts("-1");
	return 0;
}


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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b, c; cin >> a >> b >> c;
  int A = (a+b+c)/2;
  if((a+b+c)%2 == 0 && (a == A || b == A || c == A)){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3580
#include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define REP rep
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define eb emplace_back

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
const ll MOD=1e9+7;

#define rall(X) (X).rbegin(),(X).rend()
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}

int N;
int A[114514];

signed main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);

  cin >> N;
  int tot = 0;
  multiset<int> st;
  rep(i, N) {
    cin >> A[i];
    st.insert(A[i]);
    tot += abs(A[i]);
  }

  if (*st.begin() >= 0) {
    tot -= 2**st.begin();
    cout << tot << "\n";
    int v = *st.begin();
    st.erase(st.begin());
    while (st.size() >= 2) {
      int y = *st.rbegin(); st.erase(st.find(y));
      cout << v << " " << y << endl;
      v -= y;
    }
    assert(st.size() == 1);
    cout << *st.rbegin() << " " << v << endl;
    assert(*st.rbegin() - v == tot);
  } else if (*st.rbegin() < 0) {
    tot -= 2*abs(*st.rbegin());
    cout << tot << "\n";
    int v = *st.rbegin();
    st.erase(st.find(v));
    while (st.size() >= 1) {
      int y = *st.rbegin(); st.erase(st.find(y));
      cout << v << " " << y << endl;
      v -= y;
    }
    assert(st.size() == 0);
    assert(v == tot);
  } else {
    cout << tot << "\n";
    int v = *st.begin();
    st.erase(st.begin());
    int t = *st.rbegin();
    st.erase(st.find(t));
    while (!st.empty() && *st.rbegin() >= 0) {
      int y = *st.rbegin(); st.erase(st.find(y));
      cout << v << " " << y << endl;
      v -= y;
    }
    cout << t << " " << v << endl;
    t -= v;
    while (!st.empty()) {
      int y = *st.rbegin(); st.erase(st.find(y));
      assert(y <= 0);
      cout << t << " " << y << endl;
      t -= y;
    }
    assert(st.size() == 0);
    assert(t == tot);
  }
}


Measured memory_bytes: 7040
import java.util.*;

public class Main {

	private static List<Long> getStrings(Scanner sc, int num) {
		List<Long> stringList = new ArrayList<>();
		while(num>0) {
			long nextInt = sc.nextLong();
			stringList.add(nextInt);
			num--;
		}
		return stringList;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		List<Long> array = getStrings(sc, n);
		int q = sc.nextInt();
		long sum = 0;
		Map<Long, Integer> map = new HashMap<>();
		for (int i = 0; i < array.size(); i++) {
			long key = array.get(i);
			if (!map.containsKey(key)) {
				map.put(key, 1);
			} else {
				int times = map.get(key);
				map.put(key, times+1);
			}
			sum+=key;
		}
		while(q > 0) {
			long b = sc.nextLong();
			long c = sc.nextLong();
			if (map.containsKey(b)) {
				int t = map.get(b);
				sum = sum + t*(c-b);
				map.remove(b);
				if (map.containsKey(c)) {
					map.put(c, t+map.get(c));
				} else {
					map.put(c, t);
				}
			}
			System.out.println(sum);
			q--;
		}
	}

}


Measured memory_bytes: 69168
#include<stdio.h>

int main(void){
        int a,b,m;
        char op;

        while(1){
                scanf("%d %c %d",&a,&op,&b);

                if(op == '?')
                        break;
                else if(op == '+')
                        m = a + b;
                else if(op == '-')
                        m = a - b;
                else if(op == '*')
                        m = a * b;
                else if(op == '/')
                        m = a / b;

                printf("%d\n",m);
        }
        return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int main() {
	int i, j, k, n;
	double length;
	int dx, dy;
	int* x;
	int* y;
	length = 0.0;
	cin >> n;
	x = new int[n];
	y = new int[n];
	for (i = 0; i < n; i++) {
		cin >> x[i] >> y[i];
	}

	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			if (i != j) {
				dx = x[i] - x[j];
				dy = y[i] - y[j];
				length += sqrt(pow(dx, 2) + pow(dy, 2));
			}
		}
	}
	length /= n;
	cout  << fixed << setprecision(10) <<  length;

	delete[] x;
	delete[] y;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <map>
#include <utility>
#include <list>
#include <string>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

#define LL long long

int main() {
    int s, t, u;
    cin >> s >> t >> u;

    cout << s * t / 2 << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include <bits/stdc++.h>
#include <cstdio>
#include<set>
using namespace std;
#define PI 3.141592653589
int main()
{
    int A, B, X;
    cin >> A >> B >> X;
    double Y = X/(double)A;
//    fprintf(stderr, "%f, %f\n",
//            2 * (A * B - Y)/(double)(A * A),
//            B * B/(2.0 * (A * B - Y)));
//    fprintf(stderr, "%d, %d, %f\n", A, B, Y);
    if (Y >= A * B/2.0){
        fprintf(stdout, "%.15f\n",
            atan(2.0 * (A * B - Y)/(double)(A * A)) * 180.0/PI);
    } else {
       fprintf(stdout, "%.15f\n",
            atan(B * B/(2.0 * Y)) * 180.0/PI);
    }
    return 0;    
}


Measured memory_bytes: 256
N, low_A, up_B = map(int, input().split())
ans = 0

for i in range(1, N + 1):
    keta = list(str(i))
    summ = sum([int(i) for i in keta])
    
    if (low_A <= summ and summ <= up_B):
        ans += i

print(ans)

Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main{
  public static void main(String[] args) {
    try {
      BufferedReader stdReader =
        new BufferedReader(new InputStreamReader(System.in));
      String line0;
      line0 = stdReader.readLine();

      String Array[]=line0.split(" ");
      int a =Integer.parseInt(Array[0]);
      int b =Integer.parseInt(Array[1]);
      int c =Integer.parseInt(Array[2]);
      if(a<b&&b<c){
          System.out.println("Yes");
	  }else{
          System.out.println("No");
	  }
	  
	  
      stdReader.close();
    } catch (Exception e) {
      e.getStackTrace();
      /*?????´??????0??????*/
      System.exit(0); 
    }
  }
}

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

#define rep(i,n) for(int i=0; i<int(n); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int>P;

map<ll, ll> m;
ll a[1010], b[1010], c[1010], d[1010];

int main() {
	ll N, V;
	cin >> N >> V;

	for (int i = 0; i < N; i++)cin >> a[i];
	for (int i = 0; i < N; i++)cin >> b[i];
	for (int i = 0; i < N; i++)cin >> c[i];
	for (int i = 0; i < N; i++)cin >> d[i];

	map<ll, ll> m1, m2;
	for (int i = 0; i < N; i++)
		for (int j = 0; j < N; j++)
			m1[a[i] + b[j]]++;
	for (int i = 0; i < N; i++)
		for (int j = 0; j < N; j++)
			m2[c[i] + d[j]]++;

	ll ans = 0;
	map<ll, ll>::iterator it;
	for (it = m1.begin(); it != m1.end(); it++) {
		ans += it->second * m2[V - it->first];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 190564
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<ll, ll> P;
int main()
{
    int N, M;
    cin >> N >> M;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];

    vector<P> CB(M);
    rep(i, M) {
        int B, C;
        cin >> B >> C;
        CB[i] = {C, B};
    }

    sort(all(CB));
    reverse(all(CB));
    sort(all(A));

    ll cnt = 0;
    rep(i, M) {
        ll C = CB[i].first, B = CB[i].second;
        ll index = upper_bound(all(A), C) - A.begin();
        if (cnt < index) {
            cnt += min(index - cnt, B);
        }
        else break;
    }

    ll sum = 0;
    repd(i, cnt, N) sum += A[i];

    rep(i, M) {
        ll minus = min(cnt, CB[i].second);
        cnt -= minus;
        sum += max(0LL, minus) * CB[i].first;
    }

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 2560
#include<stdio.h>
int main(){
  int a,b,i;
  scanf("%d %d",&a,&b);
  if(a>b){
    for(i=0;i<a;i++)printf("%d",b);
  }
  else for(i=0;i<b;i++)printf("%d",a);
  return 0;
}

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

using namespace std;
//using namespace __gnu_pbds;
//typedef tree<
//        pair<int, int>, // change type
//        null_type,
//        less<pair<int, int> >, // change type
//        rb_tree_tag,
//        tree_order_statistics_node_update>
//        ordered_set;

typedef long long ll;
#define rep(i, start, end) for(int i = start; i < end; ++i)
#define sz(x) (int)(x).size()
#define pb push_back
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define clr(d, v) memset(d, v, sizeof(d))
#define pii pair<int, int>
const double PI = 3.14159265358979323846;
const double eps = (1e-9);
int dcmp(long double x, long double y)
{
    if (abs(x - y) < eps)
        return 0;
    if (x > y)
        return 1;
    return -1;
}



int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
 //   freopen("input.txt", "r", stdin);
//    freopen("facebook.txt", "w", stdout);
#endif
    int n, k;
    cin >> n >> k;
    if (k == 1)
        cout << 0;
    else
        cout << n - k;
    return 0;
}

Measured memory_bytes: 892
class UnionFind:
    def __init__(self, length):
        self.length = length
        self.parent = list(range(length))
        self.rank = [0] * length

    def find(self, x):
        "根を求める"
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

    def unite(self, x, y):
        "xの木とyの木を併合"
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return

        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
        else:
            self.parent[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def same(self, x, y):
        "x と y が同じかどうか判定"
        return self.find(x) == self.find(y)


N, M = map(int, input().split())
uf = UnionFind(N)

for i in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    uf.unite(a, b)

kosuu = 0
for i in range(1, N):
    if uf.same(0, i):
        continue
    else:
        kosuu += 1
        uf.unite(0, i)

print(kosuu)


Measured memory_bytes: 75160
n,m=(map(int,input().split()))
x = []
y = []
for i in range(m):
    x1,y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)
ans=min(y)-max(x)+1
print(ans if min(y)-max(x)>=0 else 0)

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;


int main() {
    string bit1, bit2, s;
    int b1=0, b2=0;
    cin >> s;
    rep(i, s.size() / 2) {
        bit1 += "01";
        bit2 += "10";
    }
    if (s.size() % 2 == 1) {
        bit1 += "0";
        bit2 += "1";
    }
    rep(i, s.size()) {
        if (bit1[i] != s[i])b1++;
        if (bit2[i] != s[i])b2++;
    }
    cout << min(b1, b2) << endl;
    return 0;
}

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

int main(){
	int n,k,q;
	cin>>n>>k>>q;
	int correct[n+1]={0};
	int total = q;
	while(q--){
		int a;
		cin>>a;
		correct[a]++;
	}
	for(int i=1; i<=n; i++){
		int score = k-(total-correct[i]);
		if(score<=0) cout<<"No"<<'\n';
		else cout<<"Yes"<<'\n';
	}
}


Measured memory_bytes: 4036
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    bool f = true;
    rep(i, 0, s.size()){
        if(i % 2 == 0){
            if(s[i] == 'L') f = false;
        }else{
            if(s[i] == 'R') f = false;
        }
    }
    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main() {
	int n;
	string s;
	int q;
	int k;
	
	cin >> n >> s >> q;
	for(int times = 0; times < q; times++){
		cin >> k;
		long int r = 0;
		long int nowd = 0;
		long int nowm = 0;
		long int nowdm = 0;
		for (int i = 0; i < n; i++){
			if(s[i] == 'D'){nowd++;}
			if(s[i] == 'M'){nowm++; nowdm += nowd;}
			if(s[i] == 'C'){r += nowdm;}
			if(i >= k-1){
				if(s[i-k+1] == 'D'){nowd--; nowdm -= nowm;}
				if(s[i-k+1] == 'M'){nowm -= 1;}
			}
		}
		cout << r << endl;
	}
	return 0;
}

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

int main(void) {
    int N;
    cin >> N;
    vector<long long> L(N);
    for (int i = 0; i < N; i++) {
        cin >> L[i];
    }

    int ans = 0;
    for (int i = 0; i < N - 2; i++) {
        for (int j = i + 1; j < N - 1; j++) {
            for (int k = j + 1; k < N; k++) {
                long long a = L[i], b = L[j], c = L[k];
                if (a != b && b != c && a != c && a + b > c && b + c > a &&
                    c + a > b) {
                    ans++;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,n) for(int i=(int)(n-1);i>=1;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x"=" << x <<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<int, P> PIP;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;
typedef set<int> S;

#define INF INT_MAX/3

#define MAX_N 1000000001

int main(){
	cin.sync_with_stdio(false);
	int n, a;
	cin >> n >> a;

	ll sum[2501][51] = {};
	rep(i, n) {
		int x;
		cin >> x;
		repr(j, 2501) {
			if (j + x > 2500) continue;
			repl(k, 1, 51) {
				if (sum[j][k] > 0) {
					sum[j + x][k + 1] += sum[j][k];
				}
				if (k == 1 && j == x) {
					sum[j][k]++;
				}
			}
		}
	}

		ll  cnt = 0;
		repl(i, 1, n + 1) {
			int tmp = i * a;
			cnt += sum[tmp][i];
		}

		cout << cnt << endl;

		return 0;
	}

Measured memory_bytes: 1280
#include<iostream>

using namespace std;

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

long long k;
long long a[50];

int main(){
    cin >> k;
    long long n = k/50;
    long long r = k%50;

    REP(i, 50){
        a[i] = i + n;
    }

    REP(i, r){
        a[i] += 51;
        REP(j, 50){
            a[j] -= 1;
        }
    }

    cout << 50 << endl;

    REP(i, 50){
        cout << a[i] << " ";
    }
    cout << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int sort(int *,int *);
int main(void){
  int n;
  scanf("%d",&n);
  int a[n+1];
  for(int i=0;i<n;i++){
scanf("%d",&a[i]);
  }
qsort(a,n,sizeof(int),sort);
  
  for(int i=0;i<n-1;i++){
    if(a[i]==a[i+1]){
      printf("NO");
      return 0;
    }
         }
         printf("YES");
         return 0;
         }
int sort(int *a, int *b){
  return *a-*b;
}

Measured memory_bytes: 1788
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<queue>

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF ((long long)1e18)
#define MOD ((int)1e9+7)
#define endl "\n"

#define yn(f) ((f)?"Yes":"No")
#define YN(f) ((f)?"YES":"NO")

#define MAX 1100

int cost[MAX][MAX];
string mp[MAX];
int sy, sx, gy, gx;
int H, W, A, B;
int dxy[4] = {1,-1,0,0};

string solve(){
	priority_queue<pair<int,pair<int,int>>,vector<pair<int,pair<int,int>>>, greater<pair<int,pair<int,int>>>> Q;
	
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			cost[i][j] = INF;
		}
	}
	
	Q.push(make_pair(0,make_pair(sy,sx)));
	
	cost[sy][sx] = 0;
	
	while(!Q.empty()){
		pair<int,pair<int,int>> P = Q.top(); Q.pop();
		int y = P.second.first, x = P.second.second, tcost = P.first;
		bool b = false, w = false;
		
		// cout<<y<<" "<<x<<endl;
		// cout<<" cost "<<tcost<<" "<<mp[y][x]<<endl;
		if(tcost < cost[y][x]) continue;
		if(y == gy && x == gx) return to_string(tcost);
		
		for(int i = -1; i <= 1; i++){
			for(int j = -1; j <= 1; j++){
				if(y+i < 0 || y+i >= H || x+j < 0 || x+j >= W) continue;
				// cout<<y+i<<"  TTT "<<x+j<<endl;
				if(mp[y+i][x+j] == '*') b = true;
			}
		}
		// cout<<"GGGGG "<<endl;
		for(int i = 0; i < 4; i++){
			int ny = y + dxy[i], nx = x + dxy[3-i];
			// cout<<" ny nx "<<ny<<" "<<nx<<endl;
			if(ny < 0 || ny >= H || nx < 0 || nx >= W) continue;
			
			// if(mp[ny][nx] == '#' || mp[ny][nx] == '*') continue;
			if(mp[ny][nx] == '#') continue;
			
			// cout<<cost[ny][nx]<<"  cost"<<cost[y][x] + A<<endl;
			if(cost[ny][nx] <= cost[y][x] + A) continue;
			
			Q.push(make_pair(cost[y][x] + A,make_pair(ny,nx)));
			
			cost[ny][nx] = cost[y][x] + A;
		}
		
		if(b == true) continue;
		// cout<<"FFFFF"<<endl;
		for(int i = -1; i <= 1; i++){
			for(int j = -1; j <= 1; j++){
				if(i == j && i == 0) continue;
				int ny = y + i, nx = x + j, co = A+B;
			
				if(i&&j) co += A;
				
				if(ny < 0 || ny >= H || nx < 0 || nx >= W) continue;
			
				if(cost[ny][nx] <= cost[y][x] + co) continue;
			
				Q.push(make_pair(cost[y][x] + co,make_pair(ny,nx)));
			
				cost[ny][nx] = cost[y][x] + co;
			}
		}
		
	}
	return "INF";
}

signed main(){
	// cin.tie(0);
	// ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	
	cin>>H>>W>>A>>B;
	
	for(int i = 0; i < H; i++){
		cin>>mp[i];
		for(int j = 0; j < W; j++){
			if(mp[i][j] == 's'){
				sy = i, sx = j;
			}
			if(mp[i][j] == 'g'){
				gy = i, gx = j;
			}
		}
	}
	
	cout<<solve()<<endl;
	
	return 0;
}


Measured memory_bytes: 12728
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (int i = 0; i < (n); i++)
#define IREP(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, k, n) for (int i = (k); i < (n); i++)
#define REPEACH(itr, k) for (auto &&itr : k)
#define MOD 1000000007

using namespace std;
typedef long long ll;

const ll INF = 1ll << 60;


int main()
{
    int h,w;
    cin >> h >> w;
    vector<vector<char>> v(h+2,vector<char>(w+2,'#'));
    int ans=0;
    REP(i,h) REP(j,w){
        cin >> v[i+1][j+1];
        if(v[i+1][j+1]=='.'){
            ans++;
        }
    }
    queue<pair<int,int>> q;
    q.push(make_pair(1,1));
    queue<int> count;
    count.push(0);
    while(!q.empty()){
        int x = q.front().first;
        int y = q.front().second;
        if (v[x][y]=='#'){
            q.pop();
            count.pop();
            continue;
        }
        v[x][y]='#';
        int c = count.front();
        count.pop();
        q.pop();
        if(x==h&&y==w){
            cout << ans-c-1 << endl;
            return 0;
        }
        if(v[x - 1][y]=='.'){
            q.push(make_pair(x-1,y));
            count.push(c+1);
        }
        if (v[x + 1][y] == '.')
        {
            q.push(make_pair(x + 1, y));
            count.push(c+1);
        }
        if (v[x][y-1] == '.')
        {
            q.push(make_pair(x, y-1));
            count.push(c+1);
        }
        if (v[x][y+1] == '.')
        {
            q.push(make_pair(x, y+1));
            count.push(c+1);
        }
    }
    cout << -1 << endl;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<math.h>
#include<iomanip>
#include<functional>
using namespace std;

#define ll long long
using vt = ll; //ここで数値の型を変えられる
#define rep(i, n) for (vt i = 0; i < (vt)(n); i++)
#define reps(i, s, n) for(vt i = (vt) (s); i < (vt) (n); i++) 
#define all(v) v.begin(), v.end()
#define P pair<int, int>
const ll  MOD = 1000000007;

int main() {
	double w, h, x, y; ll ans = 0;
	cin >> w >> h >> x >> y;
	if (x == w / 2 && y == h / 2) ans++;
	cout << w * h / 2 << " " << ans;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

#define maxSize 3003

string s, t;
int sl, tl;
int cache[maxSize][maxSize];

int max(int a, int b, int c) {
    return max(a, max(b, c));
}

int rec(int i, int j) {
    if (i >= sl || j >= tl) return 0;
    if (cache[i][j] != -1) return cache[i][j];
    return cache[i][j] = max(
            (s[i] == t[j]) + rec(i+1, j+1),
            rec(i+1, j),
            rec(i, j+1));
}

int main() {
    cin >> s >> t;
    sl = s.size(), tl = t.size();
    for (auto &i : cache) {
        for (int &j : i) {
            j = -1;
        }
    }
    int m = rec(0, 0);
    int i = 0, j = 0;
    while (i < sl && j < tl) {
        if (s[i] == t[j]) {
            cout << s[i];
            i++;
            j++;
            continue;
        }
        int wanted = cache[i][j];
        if (cache[i+1][j] == wanted) i++;
        else j++;
    }
    return 0;
}

Measured memory_bytes: 35968
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ans = 0
for i in reversed(range(1, n+1)):
    if A[i] <= B[i-1]:
        ans += A[i]
        B[i-1] -= A[i]
        if A[i-1] >= B[i-1]:
            ans += B[i-1]
            A[i-1] -= B[i-1]
        else:
            ans += A[i-1]
            A[i-1] = 0
    else:
        ans += B[i-1]
        B[i-1] = 0
print(ans)

Measured memory_bytes: 82148
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

const int INF = 1001001001;
int sum[200005];

int main(){
    int n;
    string s;
    cin >> n >> s;
    
    for(int i = 0; i < n; ++i){
        sum[i + 1] = sum[i];
        if(s[i] == '#'){
            ++sum[i + 1];
        }
    }
    
    int ans = INF;
    for(int i = 0; i <= n; ++i){
        int cnt = 0;
        cnt += sum[i];
        cnt += n - i - (sum[n] - sum[i]);
        
        ans = min(ans, cnt);
    }

    cout << ans << endl;
}

Measured memory_bytes: 1412
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>

#define rep(i,n) for(int i=0;i<n;i++)
#define dup(x,y) (((x)+(y)-1)/(y)) // dup * y >= x なる最小のdup.
using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;



int main() {
	ll N;
	cin >> N;
	vector<ll> T(5); // A, B ,...
	vector<ll> P(6, 0);
	rep(i, 5) cin >> T[i];

	ll BN = *min_element(T.begin(), T.end());

	ll ans;
	if(BN>=N) ans = 5;
	else ans = dup(N, BN) + 4;	

	cout << ans << endl;

	return 0;
}

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

N=int(input())
P=[list(map(int,input().split())) for i in range(N)]
ANS=[1<<60]*(N+1)
ANS[-1]=0
DP1=[20000]*N

S=0
for i in range(N):
    x,y,p=P[i]
    DP1[i]=min(abs(x),abs(y))
    S+=DP1[i]*p

ANS[0]=S

def dfs(DP,now,used):
    for next_town in range(now,N):
        x,y,p=P[next_town]

        DP2=list(DP)
        S=0
        for i in range(N):
            DP2[i]=min(DP2[i],abs(P[i][0]-x))
            S+=DP2[i]*P[i][2]

        ANS[used+1]=min(ANS[used+1],S)
        dfs(DP2,next_town+1,used+1)

        DP2=list(DP)
        S=0
        for i in range(N):
            DP2[i]=min(DP2[i],abs(P[i][1]-y))
            S+=DP2[i]*P[i][2]

        ANS[used+1]=min(ANS[used+1],S)
        dfs(DP2,next_town+1,used+1)

dfs(DP1,0,0)

for i in range(1,N):
    ANS[i]=min(ANS[i],ANS[i-1])

print(*ANS)

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

struct node { int t,next; }a[200010];

int head[100010],f[100010],n,tot;

inline int rd()
{
	int x=0;char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar());
	for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x;
}

inline void add(int x,int y) { a[++tot].t=y;a[tot].next=head[x];head[x]=tot; }

inline void dfs(int x,int y)
{
	f[x]=0;
	for (int i=head[x];i;i=a[i].next)
	{
		int t=a[i].t;
		if (t==y) continue;
		dfs(t,x);f[x]^=f[t]+1;
	}
}

int main()
{
	n=rd();tot=0;
	for (int i=1;i<n;i++) { int x=rd(),y=rd();add(x,y);add(y,x); }
	dfs(1,0);
	puts(f[1]?"Alice":"Bob");
	return 0;
}

Measured memory_bytes: 4992
#include "bits/stdc++.h"
using namespace std;
#define long int64_t

struct Solver {
	Solver() {
		ios::sync_with_stdio( false );
		cout << fixed << setprecision( 10 );
	}

	void solve() {
		string S;
		cin >> S;

		if( S[2] == S[3] && S[4] == S[5] ) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
};

int main() {
	Solver().solve();
	return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i, n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i, n) for(ll i=(ll)(n-1);i>=0;i--)
#define FOR(i, a, b) for(ll i=(ll)(a); i<=(ll)(b); i++)
#define RFOR(i, a, b) for(ll i=(ll)(a);i>=(ll)(b); i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

signed main()
{
	ll A, B, C;
	cin >> A >> B >> C;
	bool poor=true;
	if(A==B and B==C){
		poor=false;
	}
	if(A!=B and B!=C and C!=A){
		poor=false;
	}
	if(poor){
		cout << "Yes";
	}else{
		cout << "No";
	}
	cout << endl;
}


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

using namespace std;

typedef long long ll;

int main() {
  stack<int> st;
  string c;
  while(cin >> c) {
    if(c == "+") {
      int a = st.top(); st.pop();
      int b = st.top(); st.pop();
      st.push(a+b);
    }
    else if(c == "-") {
      int a = st.top(); st.pop();
      int b = st.top(); st.pop();
      st.push(b-a);
    }
    else if(c == "*") {
      int a = st.top(); st.pop();
      int b = st.top(); st.pop();
      st.push(a*b);
    }
    else {
      st.push(atoi(c.c_str()));
    }
  }
  cout << st.top() << endl;
}

Measured memory_bytes: 3156
import sys
import pprint
sys.path.append('C:\\ARIHON')

# from Kraskal import compute_mst_kruskal
# import UnionFind
import array
import collections
from operator import itemgetter

class UnionFind(object):
 
    def __init__(self, number_of_nodes):  # 初期化
        self.par = array.array("L", range(number_of_nodes))
        self.rank = array.array("L", (0 for i in range(number_of_nodes)))
 
    def root(self, node):  # 根を求める
        if self.par[node] == node:
            return node
        else:
            r = self.root(self.par[node])
            self.par[node] = r  # 経路圧縮
            return r
 
    def in_the_same_set(self, node1, node2):  # 同じ集合に属するか
        return self.root(node1) == self.root(node2)
 
    def unite(self, node1, node2):  # 属する集合を併合
        x = self.root(node1)
        y = self.root(node2)
        if x == y:
            pass
        elif self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
 
 
# Kruskal法により最小全域木を求める
def compute_mst_kruskal(max_v, edges):
    edges.sort(key=lambda edge: edge.weight)
    uf = UnionFind(max_v)
    mst = []
    for edge in edges:
        if not uf.in_the_same_set(edge.start, edge.end):
            uf.unite(edge.start, edge.end)
            mst.append(edge)
    return mst
 
Edge = collections.namedtuple("Edge", "start end weight")

def main():
    n = int(input())
    l = []
    for i in range(n):
        x,y = map(int,input().split())
        l.append((x,y,i))
    
    edges = []

    lxsort = sorted(l,key=itemgetter(0))
    for i in range(n-1):
        edges.append(Edge(lxsort[i][2],lxsort[i+1][2],lxsort[i+1][0]-lxsort[i][0]))
    
    lysort = sorted(l,key=itemgetter(1))
    for i in range(n-1):
        edges.append(Edge(lysort[i][2],lysort[i+1][2],lysort[i+1][1]-lysort[i][1]))
    
    mst = compute_mst_kruskal(n,edges)

    print(sum(edge.weight for edge in mst))
 
if __name__ == '__main__':
    main()

Measured memory_bytes: 142152