akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<static_cast<int>(n);++i)
#define per(i, n) for(int i=static_cast<int>(n)-1;i>=0;--i)
#define eee(a) (cerr<<"[@"<<__LINE__<<"] "<<(#a)<<": "<<(a)<<'\n');
#define ppp(a) (cout<<(a)<<'\n'); 
#define cop(a) for(auto x:(a)){cerr<<(x)<<'\n';}
using ll = long long;
constexpr int dx[4]={1,0,-1,0};
constexpr int dy[4]={0,1,0,-1};
constexpr ll MOD = 1e9+7;
constexpr ll Mod = 998244353;
constexpr int INF = 1e9;
constexpr ll LINF = 1e18;
constexpr double phi = (1+sqrt(5))/2;
constexpr double pi = 3.14159265358979323846264338327950288;
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;}
inline ll inverse(ll n,ll m=MOD){ll a=n,b=m,x=1,y=0;while(b){ll t=a/b;a-=t*b;swap(a,b);x-=t*y;swap(x,y);}return (a%m+m)%m;}
inline void Yes(){puts("Yes");}
inline void No(){puts("No");}
inline void Judge(bool b){b?Yes():No();}
inline void YES(){puts("YES");}
inline void NO(){puts("NO");}
inline void JUDGE(bool b){b?YES():NO();}
inline ll powmod(ll b, ll e, ll m=MOD){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
inline double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));}
inline double d2r(double d){return d*pi/180;}
inline double r2d(double r){return r*180/pi;}
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(b<a){a=b;return 1;}return 0;}
template<typename T1,typename T2>ostream& operator<<(ostream& s,const pair<T1, T2>& p){return s <<"("<<p.first<<", "<<p.second<<")";}
template<typename T> ostream& operator<<(ostream& s,const vector<T>& v){s<<'[';for(size_t i=0;i<v.size();++i){s<<v[i];if(i<v.size()-1)s<<", ";}s<<']';return s;}
template<typename T> istream& operator>>(istream& s,vector<T>& v){for(T& x:v)s>>x;return s;}

int main(){
    cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);
    
    
    int n;
    cin >> n;
    vector<ll> a(n);
    cin >> a;

    vector<ll> cnt(n+1, 0);
    for(int i = 0; i < n; ++i){
        cnt[a[i]]++;
    }
    ll res = 0;
    for(int i = 1; i <= n; ++i){
        res += cnt[i]*(cnt[i]-1)/2;
    }

    for(int i = 0; i < n; ++i){
        cout << res-cnt[a[i]]+1 << '\n';
    }
    return 0;
}


Measured memory_bytes: 5760
////////////////////////////////////////////
///                                      ///
///        Template ver. 1.2. rapel      ///
/// Fear is Temporary, Regret is Forever ///
///          Must Try and Get AC         ///
///                                      ///
////////////////////////////////////////////
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <iomanip>

#include <algorithm>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>

#include <math.h>
#include <complex>

#include <assert.h>
#include <time.h>
//#include <chrono>
//#include <random>

#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <list>
#include <bitset>

#define F first
#define S second
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define endl '\n'
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

void desperate_optimization(int precision){
  	ios_base::sync_with_stdio(false);
  	cin.tie(0);
  	cout.tie(0);
  	cout.setf(ios::fixed);
  	cout.setf(ios::showpoint);
  	cout.precision(precision);
}

const ll MOD = 998244353;
const int N = 3e5;

ll fct[N + 5], inv[N + 5];

ll fast(ll A, ll B) {
	ll res = 1;
	while(B) {
		if(B & 1) res = res * A % MOD;
		B /= 2;
		A = A * A  % MOD;
	}
	return res;
}

void pre() {
	fct[0] = 1;
	for(int i = 1;i <= N;i++) fct[i] = fct[i - 1] * i % MOD;
	inv[N] = fast(fct[N], MOD - 2);
	for(int i = N - 1;i >= 0;i--) inv[i] = inv[i + 1] * (i + 1) % MOD;
}

ll combin(int n, int r) {
	if(n < r) return 0;
	return fct[n] * inv[r] % MOD * inv[n - r] % MOD;
}

void hora(int tc) {
	ll n, a, b, k;
	cin>>n>>a>>b>>k;
	ll total = 0;
	for(int i = 0;i <= n;i++) {
		ll sisak = k - i * a;
		if(sisak % b) continue;
		if(sisak < 0) continue;
		ll ada = sisak / b;
		if(ada > n) continue;
		total = (total + combin(n, i) * combin(n, ada)) % MOD;
	}
	cout<<total<<endl;
}

int main(){
	pre();
	desperate_optimization(10);
	int ntc = 1;
	//cin>>ntc;
	for(int tc = 1;tc <= ntc;tc++) hora(tc);
	return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<ctime>
#include<set>
#include<iomanip>
#define sqr(x) (x)*(x)
#define fz1(i,n) for ((i)=1;(i)<=(n);(i)++)
#define fd1(i,n) for ((i)=(n);(i)>=1;(i)--)
#define fz0g(i,n) for ((i)=0;(i)<=(n);(i)++)
#define fd0g(i,n) for ((i)=(n);(i)>=0;(i)--)
#define fz0k(i,n) for ((i)=0;(i)<(n);(i)++)
#define fd0k(i,n) for ((i)=(long long)((n)-1);(i)>=0;(i)--)
#define fz(i,x,y) for ((i)=(x);(i)<=(y);(i)++)
#define fd(i,y,x) for ((i)=(y);(i)>=(x);(i)--)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len){static char ss[len];scanf(" %s",ss);(st)=ss;}
//#define T_ int
using namespace std;
//struct bit{T_ arr[1000005];int lowbit(int x){return x&(-x);}void add(int x,T_ y){for (int i=x;i<=n;i+=lowbit(i)) arr[i]+=y;}T_ query(int x){T_ s=0;for (int i=x;i>0;i-=lowbit(i)) s+=arr[i];return s;}};
//struct seg{struct treedot{int l,r;T_ sum,add;void update(T_ x){sum+=(r-l+1)*x; add+=x;}}c[800005];void pushdown(int id){if (c[id].add){c[id*2].update(c[id].add);c[id*2+1].update(c[id].add);c[id].add=0;}}void pushup(int id){c[id].sum=c[id*2].sum+c[id*2+1].sum;}void build(int id,int l,int r){if (l>r) return;c[id].l=l;c[id].r=r;c[id].sum=0;c[id].add=0;if (l==r) c[id].sum=0;else{int mid=l+(r-l)/2;build(id*2,l,mid);build(id*2+1,mid+1,r);pushup(id);}}void update(int id,int le,int ri,T_ x){if (le>c[id].r||ri<c[id].l) return;if (le<=c[id].l&&c[id].r<=ri) c[id].update(x);else{pushdown(id);update(id*2,le,ri,x);update(id*2+1,le,ri,x);pushup(id);}}T_ query(int id,int le,int ri){if (ri<c[id].l||c[id].r<le) return 0;if (le<=c[id].l&&c[id].r<=ri) return c[id].sum;T_ ans=0;pushdown(id);ans+=query(id*2,le,ri);ans+=query(id*2+1,le,ri);pushup(id);return ans;}};
//struct bit_2d{T_ a[2005][2005];int lowbit(int x){return x&(-x);}void add(int x,int y,T_ z){int i,j;for (i=x;i<=2000;i+=lowbit(i)){for (j=y;j<=2000;j+=lowbit(j)){a[i][j]+=z;}}}T_ query(int x,int y){int i,j;T_ s=0;for (i=x;i;i-=lowbit(i)){for (j=y;j;j-=lowbit(j)){s+=a[i][j];}}return s;}T_ query(int x,int y,int xx,int yy){return query(xx,yy)-query(x-1,yy)-query(xx,y-1)+query(x-1,y-1);}};
long long a,b,k,s;
int main()
{
	cin>>k>>a>>b;
	s=1;
	long long t=max(0ll,min(a-s,k));
	s+=t;k-=t;
	if (k&1)
	{
		k--;
		s++;
	}
	s+=max((b-a)*(k/2),k);
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 256
import numpy as np
N = int(input())
A = np.array(list(map(int,input().split())))
B = np.array(list(map(int,input().split())))
diff = A-B
lack = diff[diff<0].sum()
lack_number = diff[diff<0].shape[0]
rich = np.sort(diff[A>B])[::-1]
count = 0
if A.sum() < B.sum():
    count = -1
else:
    if lack_number == 0:
        count = 0
    else:
        count = lack_number
        for i in range(rich.shape[0]):
            lack += rich[i]
            count += 1
            if lack >= 0:
                break
print(count)


Measured memory_bytes: 31444
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;

class Node {
public:
  int location;
  int p, l, r;
  Node() {}
};

class Point {
public:
  int id, x, y;
  Point() {}
  Point(int id, int x, int y): id(id), x(x), y(y) {}
  bool operator < ( const Point &p) const {
    return id < p.id;
  }

  void print() {
    printf("%d\n", id);
  }
};

static const int MAX = 1000000;
static const int NIL = -1;

int N;
Point P[MAX];
Node T[MAX];
int np;

bool lessX(const Point &p1, const Point &p2) { return p1.x < p2.x; }
bool lessY(const Point &p1, const Point &p2) { return p1.y < p2.y; }

int makeKDTree(int l, int r, int depth) {
  if ( !(l < r) ) return NIL;
  int mid = ( l + r ) / 2;
  int t = np++;
  if ( depth % 2 == 0 )
    sort(P + l, P + r, lessX);
  else
    sort(P + l, P + r, lessY);
  T[t].location = mid;
  T[t].l = makeKDTree(l, mid, depth + 1);
  T[t].r = makeKDTree(mid + 1, r, depth + 1);

  return t;
}

void find(int v, int sx, int tx, int sy, int ty, int depth, vector<Point> &ans ) {
  int x = P[T[v].location].x;
  int y = P[T[v].location].y;

  if ( sx <= x && x <= tx && sy <= y && y <= ty )
    ans.push_back(P[T[v].location]);

  if ( depth % 2 == 0 ) {
    if ( T[v].l != NIL )
      if ( sx <= x ) find(T[v].l, sx, tx, sy, ty, depth + 1, ans);
    if ( T[v].r != NIL )
      if ( x <= tx ) find(T[v].r, sx, tx, sy, ty, depth + 1, ans);
  } else {
    if ( T[v].l != NIL )
      if ( sy <= y ) find(T[v].l, sx, tx, sy, ty, depth + 1, ans);
    if ( T[v].r != NIL )
      if ( y <= ty ) find(T[v].r, sx, tx, sy, ty, depth + 1, ans);
  }
}

int main() {
  int x, y;
  scanf("%d", &N);
  for ( int i = 0; i < N; i++ ) {
    scanf("%d %d", &x, &y);
    P[i] = Point(i, x, y);
    T[i].l = T[i].r = T[i].p = NIL;
  }

  np = 0;

  int root = makeKDTree(0, N, 0);

  int q;
  scanf("%d", &q);
  int sx, tx, sy, ty;
  vector<Point> ans;
  for ( int i = 0; i < q; i++ ) {
    scanf("%d %d %d %d", &sx, &tx, &sy, &ty);
    ans.clear();
    find(root, sx, tx, sy, ty, 0, ans);
    sort(ans.begin(), ans.end());
    for ( int j = 0; j < ans.size(); j++ )
      ans[j].print();
    printf("\n");
  }

  return 0;
}


Measured memory_bytes: 16024
#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)
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;

int main()
{
    int N;
    cin >> N;
    vector<int> L(N);
    rep(i, N) cin >> L[i];

    sort(L.begin(), L.end());

    int sum = 0;
    rep(i, N - 1) {
        sum += L[i];
    }

    if (sum > L[N - 1]) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
	int n, x;
	int i = 0;
	int j, k, l, m;
	int sum,count[64];

	while(1) {
		scanf("%d %d", &n, &x);
		if (n == 0 && x == 0) {
			break;
		}
		count[i] = 0;
		for (k = 1; k <= n; k++) {
            
			for (l = k + 1; l <= n; l++){

				for (m = l + 1; m <= n; m++) {
					
					sum = k + l + m;
					if (sum == x) {
						count[i]++;
					}
				}
			}
		}
		i++;
	}

	for (j = 0; j < i; j++) {
		printf("%d\n", count[j]);
	}

	return 0;
}


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

typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

//container util
//------------------------------------------
#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair

//repetition
//------------------------------------------
#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)

enum{U = 0, D = 1, N = 2, E = 3, W = 4, S = 5};
int dice[] = {1, 6, 5, 3, 4, 2};

void rotate(int a, int b, int c, int d){
    int t = dice[a];
    dice[a] = dice[b];
    dice[b]= dice[c];
    dice[c] = dice[d];
    dice[d] = t;
}

int main(){
    int n;
    while(cin >> n, n){
        int ans = 0;
        dice[0] = 1; dice[1] = 6; dice[2] = 5; dice[3] = 3; dice[4] = 4; dice[5] = 2;
        rep(i, n){
            string s;
            cin >> s;


            if(s[0] == 'N') rotate(U, S, D, N);
            else if(s[0] == 'E') rotate(E, U, W, D);
            else if(s[0] == 'W') rotate(U, E, D, W);
            else if(s[0] == 'S') rotate(U, N, D, S);
            else if(s[0] == 'R') rotate(S, E, N, W);
            else if(s[0] == 'L') rotate(S, W, N, E);

            ans += dice[U];
        }
        cout << ans+1 << endl;
    }
}

Measured memory_bytes: 1208
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#define PB push_back
#define MP make_pair
#define sz(v) (in((v).size()))
#define forn(i,n) for(in i=0;i<(n);++i)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
typedef long long in;
typedef vector<in> VI;
typedef vector<VI> VVI;
in n,a,b;
VI h;
bool isk(in c){
  in nd=0;
  forn(i,n){
    nd+=(max(h[i]-c*b,0LL)+a-1)/a;
  }
  return nd<=c;
}
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin>>n>>a>>b;
  a-=b;
  h.resize(n);
  forn(i,n)
    cin>>h[i];
  in mn=0;
  in mx=1e9+10;
  in md;
  while(mx-mn>1){
    md=(mx+mn)/2;
    if(isk(md))
      mx=md;
    else
      mn=md;
  }
  cout<<mx<<endl;
  return 0;
}


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

using namespace std;

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int m=123456*2+1;
vector<bool> is_prime(m,true);

void Sieve(){
	is_prime[1]=false;
	for (int p = 2; p*p < m; p++){
		if(!is_prime[p])continue;
		for (int q = p*p; q < m; q+=p){
			is_prime[q]=false;
		}
	}
}

int main()
{
	Sieve();
	int n;
	while(cin>>n,n!=0){
		int ans=0;
		repi(i,n+1,2*n+1)
			if(is_prime[i]) ans++;
		cout<<ans<<endl;	
	}
	return 0;
}


Measured memory_bytes: 3140
fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let n: usize = sc.read();
    let a: Vec<u64> = sc.vec(n);
    let b: Vec<u64> = sc.vec(n);

    if solve(a, b) {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn solve(a: Vec<u64>, b: Vec<u64>) -> bool {
    let n = a.len();
    let mut ba: Vec<_> = (0..n).map(|i| (b[i], a[i])).collect();
    ba.sort();

    let mut a: Vec<_> = ba.iter().enumerate().map(|(i, &(_, a))| (a, i)).collect();
    a.sort();

    for i in 0..n {
        if a[i].0 > ba[i].0 {
            return false;
        }
    }

    let mut cur = 0;
    let mut vis = vec![false; n];
    while !vis[cur] {
        vis[cur] = true;
        cur = a[cur].1;
    }

    if vis.contains(&false) {
        return true;
    }

    for i in 1..n {
        if a[i].0 <= ba[i - 1].0 {
            return true;
        }
    }

    false
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 12540
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#ifdef ONLINE_JUDGE
#define D(...)
#else
#define D(...)cerr<<__LINE__<<":"<<"["<<#__VA_ARGS__<<"]->",P(__VA_ARGS__)
#endif
void P(){cerr<<endl;} 
template<typename H,typename...T>void P(H h,T...t){cerr<<h<<" ";P(t...);}
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);
    int n;cin>>n;
    vector<int>v(n);
    for(auto &x:v)
        cin>>x;
    auto it=minmax_element(v.begin(),v.end());
    cout<<*(it.second)-*(it.first)<<endl;



}

Measured memory_bytes: 3596
#include <stdio.h>
int max(int a, int b){
    if(a > b)
    return a;
    else
    return b;
}

int main(){
    while(1 == 1){
	int n, m, i, j, k, tmp;
	int result = 0;
	scanf("%d%d", &n, &m);
	if(n == 0 && m ==0)
	    break;
	int a[n];
	for (i = 0; i < n; i++){
		scanf("%d", &a[i]);
	}
	for(int i = 0; i < n; i++){
	    for (j = i + 1; j < n; j++){
	        tmp = a[i] + a[j];
	        if(tmp <= m){
	            result = max(result, tmp);
	        }
	    }
	}
	if(result != 0){
	    printf("%d\n", result);
	}else{
	printf("NONE\n");
    }
    }
	return 0;	
}

Measured memory_bytes: 2664
import Control.Applicative
import Control.Monad
import Data.List
strToInt s = (read :: String -> Int) s

main :: IO ()
main = do
    -- 整数の入力
    n <- getLine
    -- スペース区切り整数の入力
    l <- map strToInt . words <$> getLine
    let l' = group $ sort l
    let len = map length l'
    let ls = zip (map head l') len
    -- 出力
    putStrLn . show $ solve ls

solve :: [(Int, Int)] -> Int
solve = foldl (\acc (x, y) -> if x > y then acc + y else acc + y - x) 0


Measured memory_bytes: 39676
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
typedef long long ll;
bool aaa[11111111];
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}


int main() {
  int a;
  ll k,x,y=0,b,c,m,memo=1,sx=1,sy=1,gx,gy;
  string ka,ss;
  ll n,ans=0;
  cin>>n>>x>>y;
  cout<<y<<" "<<n<<" "<<x<<endl;
  //vector<vector<bool>> sinsetsu(15,vector<bool>(14)),usotsuki(15,vector<bool>(14));
  //vector<vector<int>> sss(15,vector<int>(14))
  //vector<vector<int>> sss(h,vector<int>(w));
  //vector<int> a(k),b(k);
  //char x;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card {
 char suit;
 int value;
 };
 
 struct Card L[MAX / 2+2], R[MAX / 2+2];
 
 void merge(struct Card A[], int n, int left, int mid, int right) {
   int i, j, k;
   int n1 = mid - left;
   int n2 = right - mid;
   for ( i = 0; i < n1; i++ ) L[i] = A[left + i];
   for ( i = 0; i < n2; i++ ) R[i] = A[mid + i];
   L[n1].value = R[n2].value = SENTINEL;
   i = j = 0;
   for ( k = left; k < right; k++ ) {
    if ( L[i].value <= R[j].value ) {
      A[k] = L[i++];
      } else {
      A[k] = R[j++];
        }
       }
    }
      
   void mergeSort(struct Card A[], int n, int left, int right) {
      int mid;
      if ( left + 1 < right ) {
       mid = (left + right) / 2;
       mergeSort(A, n, left, mid);
       mergeSort(A, n, mid, right);
       merge(A, n, left, mid, right);
       }
    }
    
    int partition(struct Card A[], int n, int p, int r) {
     int i, j;
     struct Card t, x;
     x = A[r];
     i = p - 1;
     for ( j = p; j < r; j++ ) {
     if ( A[j].value <= x.value ) {
      i++;
      t = A[i]; A[i] = A[j]; A[j] = t;
      }
     }
   t = A[i+1]; A[i+1] = A[r]; A[r] = t;
   return i + 1;
   }
   
  void quickSort(struct Card A[], int n, int p, int r) {
  int q;
  if ( p < r) {
   q = partition(A, n, p, r);
   quickSort(A, n, p, q-1);
   quickSort(A, n, q+1, r);
   }
   }
   
 int main() {
   int n, i, v;
   struct Card A[MAX], B[MAX];
   char S[10];
   int stable = 1;
   
   scanf("%d", &n);
   
   for ( i = 0; i < n; i++ ) {
    scanf("%s %d", S, &v);
    A[i].suit = B[i].suit = S[0];
    A[i].value = B[i].value = v;
   }
   
   mergeSort(A, n, 0, n);
   quickSort(B, n, 0, n-1);
   
   for ( i = 0; i < n; i++ ) {
    
    if ( A[i].suit != B[i].suit ) stable = 0;
   }
   
   if ( stable == 1 ) printf("Stable\n");
   else printf("Not stable\n");
   for ( i = 0; i < n; i++) {
     printf("%c %d\n", B[i].suit, B[i].value);
     }
     
     return 0;
     }
    


Measured memory_bytes: 4188
#include<iostream>
#include<cmath>
#include<iomanip>
#include<algorithm>
#include<set>
using namespace std;
#define ll long long

int gcd(int a, int b){
    
    if(b==0)
    return a;
    
    return gcd(b, a%b);
    
}
int main(){
int K;
cin>>K;

ll ans=0;
//cout<<gcd(2,5);
for(int i=1;i<=K;i++){
    for(int j=1;j<=K;j++){
        for(int k=1;k<=K;k++){
                ans+=gcd(gcd(i,j),k);   
        }
    }
}
cout<<ans;

}

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

namespace adaptor = boost::adaptors;*/


void Main()
{
	double n; cin>>n;
	vector<double> a(n);
	rep(i,n) cin>>a.at(i);
	rep(i,n) a.at(i)=1.0/a.at(i);
	double sum = 0.0;
	rep(i,n) sum+= a.at(i);
	cout << 1.0/sum <<endl;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(0)
#define loop(i, a, b) for(lli i=a; i<b; i++)
#define loopb(i, a, b) for(lli i=a; i>=b; i--)
#define pb push_back
#define umap unordered_map
typedef long long int lli;
typedef pair<lli, lli> pii;
typedef vector<lli> vll;
typedef tree<lli, null_type, less<lli>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// use to avoid collision
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
// for pair in unordered_map
struct hash_pair {
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        return hash1 ^ hash2;
    }
};
lli power(lli x, lli y){
    lli res = 1;
    x = x ;
    while (y > 0) {
        if (y & 1)
            res = (res*x) ;
        y = y>>1;
        x = (x*x);
    }
    return res;
}
lli M = 1e9 + 7;
lli solve(){
	lli n;
	cin>>n;
	vll A(n);
	loop(i, 0, n)	cin>>A[i];
	lli ans = 1;
	lli r=0, b=0, c=0;
	loop(i, 0, n){
//		lli count = 0;
//		lli d = -1;
//		if(A[i] == id[0]){
//			count++;
//			d = 0;
//		}
//		if(A[i] == id[1]){
//			count++;
//			d = 1;
//		}
//		if(A[i] == id[2]){
//			count++;
//			d = 2;
//		}
		if(A[i] == 0 && r == 0){
			ans = (ans * 3)%M;
			r++;
		}
		else if(A[i] == 0 && b == 0){
			b++;
			ans = (ans*2)%M;
		}
		else if(A[i] == 0 && c == 0)
			c++;
		else if(A[i] == r && A[i] != b && A[i] != c)
			r++;
		else if(A[i] == b && A[i] != r && A[i] != c)
			b++;
		else if(A[i] != b && A[i] != r && A[i] == c)
			c++;
		else if(A[i] == r && A[i] == b && A[i] != c){
			r++;
			ans = (ans * 2)%M;
		}
		else if(A[i] == r && A[i] != b && A[i] == c){
			r++;
			ans = (ans * 2)%M;
		}
		else if(A[i] != r && A[i] == b && A[i] == c){
			b++;
			ans = (ans * 2)%M;
		}
		else if(A[i] == r && A[i] == b && A[i] == c){
			r++;
			ans = (ans*3)%M;
		}
      	else{
          cout<<0<<"\n";
          return 0;
        }
	}
	cout<<ans<<"\n";
	return 0;
}
int main(){
	fastio;
	lli t;
//	cin>>t;
	t = 1;
	while(t>0){
		t--;
		solve();
	}
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <cstdlib>  
#include <algorithm>
#include <string>

using namespace std;
 
int main() {
    int N;cin>>N;
    int ko = 0;
    for(int i = 1;i<=N;i++){
    	for(int j = 1;j<=N;j++){
          if(i*j <N){
          	ko++;
          }
          else{
          	break;
          }
        }
    }
    cout<<ko;
    return 0;
}

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

int main() {
  string S;
  cin >> S;
  int longest = 0, current = 0;
  for (int i = 0; i < S.length(); ++i) {
    if (S[i] == 'S') {
      if (current > longest)
        longest = current;
      current = 0;
    } else {
      ++current;
    }
  }
  if (current > longest)
    longest = current;
  printf("%d", longest);
  return 0;
}


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

int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> ranges(M); // <right, left>
  for (int i = 0; i < M; i++) {
    int left, right;
    cin >> left >> right;
    ranges[i] = make_pair(right, left);
  }
  
  sort(ranges.begin(), ranges.end());
  
  int cnt = 0;
  int last_cut = 1;
  for (int i = 0; i < M; i++) {
    int right = ranges[i].first;
    int left = ranges[i].second;
    if (left >= last_cut) {
      cnt++;
      last_cut = right;
    }
  }
  
  cout << cnt << endl;
}

Measured memory_bytes: 1024
N = int(input())
H = [int(x) for x in input().split()]

H.reverse()
#print(H)
cnt = 0
for i in range(1,N):
  if H[i]-H[i-1] == 1:
    H[i] = H[i]-1
  elif H[i]-H[i-1] > 1:
    cnt += 1
if cnt == 0:
  print('Yes')
else:
  print('No')


Measured memory_bytes: 14396
#include <iostream>
#include <algorithm>
//#include <tuple>
#include <string>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long
#define pb push_back
using namespace std;


int n;
int l[10];

int main(){
	cin >>n;
	rep(i, n) {
		cin >> l[i];
	}

	sort(l, l + n, greater<int>());
	int z1 = l[0];
	int z2=0;
	rep(i, n-1) {
		z2 += l[i + 1];
	}
	
	if (z1 >= z2) cout << "No\n";
	else cout << "Yes\n";

	return 0;
}


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

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  int ans = 0;
  cin >> n >> m;
  long long h[n];
  for(auto&q:h){
    cin >> q;
  }
  vector<set<int> > all(n+1);
  for(int i = 0; i < m; i++){
    int a, b;
    cin >> a >> b;
    all[a].insert(b);
    all[b].insert(a);
  }
  for(int i = 1; i <= n; i++){
    if(all[i].size() == 0){
      ans++;
    }else{
      bool se = true;
      for(set<int>::iterator it = all[i].begin(); it != all[i].end(); it++){
        if(h[*it-1] >= h[i-1]){
          se = false;
          break;
        }
      }
      if(se){
        ans++;
      }
    }
  }
  cout << ans;
  return 0;
}

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

template <typename T>
T pow(T a, long long n, T e = 1) {
    T ret = e;
    while (n) {
        if (n & 1) ret *= a;
        a *= a;
        n >>= 1;
    }
    return ret;
}

template <int mod>
struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(long long x_) {
        if ((x = x_ % mod + mod) >= mod) x -= mod;
    }
    ModInt& operator+=(ModInt rhs) {
        if ((x += rhs.x) >= mod) x -= mod;
        return *this;
    }
    ModInt& operator-=(ModInt rhs) {
        if ((x -= rhs.x) < 0) x += mod;
        return *this;
    }
    ModInt& operator*=(ModInt rhs) {
        x = (unsigned long long)x * rhs.x % mod;
        return *this;
    }
    ModInt& operator/=(ModInt rhs) {
        x = (unsigned long long)x * rhs.inv().x % mod;
        return *this;
    }

    ModInt operator-() const { return -x < 0 ? mod - x : -x; }
    ModInt operator+(ModInt rhs) const { return ModInt(*this) += rhs; }
    ModInt operator-(ModInt rhs) const { return ModInt(*this) -= rhs; }
    ModInt operator*(ModInt rhs) const { return ModInt(*this) *= rhs; }
    ModInt operator/(ModInt rhs) const { return ModInt(*this) /= rhs; }
    bool operator==(ModInt rhs) const { return x == rhs.x; }
    bool operator!=(ModInt rhs) const { return x != rhs.x; }
    ModInt inv() const { return pow(*this, mod - 2); }

    friend ostream& operator<<(ostream& s, ModInt<mod> a) {
        s << a.x;
        return s;
    }
    friend istream& operator>>(istream& s, ModInt<mod>& a) {
        s >> a.x;
        return s;
    }
};

using mint = ModInt<1000000007>;

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

    int n;
    cin >> n;
    int cur = -1;
    mint ans = 1;
    int hito = 0;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        if (a >= cur + 2) {
            cur += 2;
            hito++;
        } else if (a == cur + 1) {
            if (i == n - 1) {
                hito++;
            } else {
                ans *= (hito + 1);
            }
        }
    }
    for (int i = hito; i >= 1; i--) {
        ans *= i;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
    //Mitsui Sumitomo
    static final int DIV = 100000007;
    static final int MAX = 2000000000;

    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        System.out.println(6-a-b);
    }
}

Measured memory_bytes: 22608
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
using namespace std;
using LL = long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = 1000000000;
const double PI = acos(-1);

int main() {
	int n;
	while (cin >> n) {
		bool a[1100] = {};
		int maxl = 0;
		for (int i = 512; i >= 1; i /= 2) {
			if (n >= i) {
				n -= i;
				a[i] = true;
				maxl = max(maxl, i);
			}
		}
		for (int i = 1; i <= 512; i *= 2) {
			if (a[i]) {
				if (i == maxl) {
					cout << i << endl;
				}
				else {
					cout << i << " ";
				}
			}
		}
	}
}

Measured memory_bytes: 3060
def main():
    N = int(input())
    statusDict = {"AC":0, "WA":0, "TLE":0, "RE":0}
    
    for i in range(N):
        status = input()
        statusDict[status] = statusDict[status] + 1

    for key in statusDict.keys():
        print(key + " x " + str(statusDict[key]))

if __name__ == "__main__":
    main()

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

int main()
{
	int n, m, k;
	cin >> n >> m >> k;
	vector<long long> a(n + 1), b(m + 1);
	for(int i = 0; i < n; i++){
		cin >> a[i + 1];
		a[i + 1] += a[i];
	}
	for(int i = 0; i < m; i++){
		cin >> b[i + 1];
		b[i + 1] += b[i];
	}
	long long ans = 0;
	for(int i = 0; i <= n; i++){
		if(a[i] > k) continue;
		long long tmp = upper_bound(b.begin(), b.end(), k - a[i]) - b.begin();
		ans = max(ans, tmp + i - 1);
	}
	cout << ans << endl;
}

Measured memory_bytes: 6424
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  char f = 'a';
  string a, b, c;
  in3(a, b, c);
  ll i, j, k;
  i = 0;
  j = 0;
  k = 0;
  while(true){
    if(f == 'a'){
      if(i == a.size()){
        out('A');
        memi;
        return 0;
      }
      else{
        f = a[i];
        i++;
      }
    }
    else if(f == 'b'){
      if(j == b.size()){
        out('B');
        memi;
        return 0;
      }
      else{
        f = b[j];
        j++;
      }
    }
    else if(f == 'c'){
      if(k == c.size()){
        out('C');
        memi;
        return 0;
      }
      else{
        f = c[k];
        k++;
      }
    }
  }
}

Measured memory_bytes: 256
n = int(input())
s = list(map(int, input()))
ans = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            preindex = 0
            flag1 = 0
            flag2 = 0
            flag3 = 0 
            while preindex < n:
                if s[preindex] == i:
                    preindex += 1
                    flag1 = 1
                    break
                preindex += 1

            while preindex < n:
                if s[preindex] == j:
                    preindex += 1
                    flag2 = 1
                    break
                preindex += 1

            while preindex < n:
                if s[preindex] == k:
                    flag3 = 1
                    break
                preindex += 1
            if flag1 and flag2 and flag3:
                ans += 1
print(ans)
             



Measured memory_bytes: 43100
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
    long long n;
    cin>>n;

    long long ar[n];
    long long ans=0;

    for(int i=0;i<n;i++)
    {
        cin>>ar[i];

        if(i!=0)
        {
            ans+=max(ar[i-1]-ar[i],0ll);

            ar[i]=max(ar[i],ar[i-1]);
        }


    }

    cout<<ans;
}

Measured memory_bytes: 5148
#include <bits/stdc++.h>
using namespace std;
#define PI 3.1415926535
const long long int MOD = 1000000007;
#define pb push_back
#define mp make_pair
#define fill(a)  memset(a, 0, sizeof (a))
#define SORT(v)  sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define MAX(v) *max_element(v.begin(), v.end())
#define MIN(v) *min_element(v.begin(), v.end())
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define watch(x) cout << (#x) << " is " << (x) << endl;
const long long int MAXX = 2e6 + 5;
const long long int MINN = 2e5 + 5;
const long long int inf = 1e6;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<ll,ll> ii;
typedef pair<int,ii> iii;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef vector< iii > viii;

ll lcm(ll a, ll b) {
   return a / __gcd(a, b) * b;
}
int XOR(int x, int y){
  return (x | y) & (~x | ~y);
}
bool cmp(const pair<int,int> &a,const pair<int,int> &b) {
    return (a.second < b.second);
}
// bool isl = binary_search(x.begin(), x.end(), 5);
// __builtin_popcount(x)  - Returns the number of set bits in x
const long long int N = 10050;
const int MAXN = 105;
int binsearch(int lo, int hi){
	while(lo<hi){
		int mid=(lo+hi)/2;
		if((mid))   // check(mid)
			hi=mid;
		else
			lo=mid+1;
	}
	return lo;
}
ll power(ll x,ll y){
    ll res=1;
    while(y>0){
      if(y&1) res=((res*x));

      y/=2;
      x=((x*x));
    }
    return res;
}

int main(){
    FAST
    int n;
    cin>>n;
    ll sum = 0;
    for(int i=1;i<=n;i++){
        if(i%3 !=0 && i%5 !=0){
            sum+=i;
        }
    }
    cout<<sum;
    return 0;
}


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

using namespace std;

int main()
{
	int n;
    cin>>n;
    int arr[n];
    
    for(int i=0;i<n;i++)
    {
    	cin>>arr[i];
	}
    
    int mini=INT_MAX,ans=-1;
	for(int i=1;i<=100;i++)
	{
		int sum=0;
		for(int j=0;j<n;j++){
			sum+=(i-arr[j])*(i-arr[j]);
		}
		if(mini>sum)
		{
			mini=sum;
			ans=i;
		}
	
	}
	cout<<mini<<endl;
	
     
     



}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    cout << a + b + c - max({a,b,c}) << endl;
}


Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"

using namespace std;

const long long int MOD = 1000000007;
const long long int exa = 1000000000000000000;
//const int MOD = 1000000007;
//const int MOD = 998244353;

long long int N, M, K, H, W, L, R;
//int N, M, K, H, W, L, R;


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

	cin >> N;
	string s;
	cin >> s;
	for (auto i : s)M += i == 'R';

	K = N - M;
	if (M > K) {
		cout << "Yes\n";
		return 0;
	}
	cout << "No\n";

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
vector<int> f(30);
bool kyotu(int a,int b){
  int check =0;
  for(int i=a;i<b-1;i++){
    if(f[i-1]==f[i]) check++;
  }
  if(check == b-a-1) return true;
  return false;
}
bool cubecheck(){
  if(kyotu(1,9)&&kyotu(10,12)&&kyotu(13,15)&&kyotu(16,18)&&kyotu(19,21)&&kyotu(22,30)){
    return true;
  }else{
    return false;
  }
}
void fr(){
  swap(f[13-1],f[18-1]);
  swap(f[9-1],f[24-1]);
  swap(f[7-1],f[22-1]);
  swap(f[8-1],f[23-1]);
  swap(f[10-1],f[12-1]);
}
void ri(){
  swap(f[13-1],f[15-1]);
  swap(f[3-1],f[22-1]);
  swap(f[6-1],f[25-1]);
  swap(f[9-1],f[28-1]);
  swap(f[12-1],f[19-1]);
}

void le(){
  swap(f[1-1],f[24-1]);
  swap(f[4-1],f[27-1]);
  swap(f[7-1],f[30-1]);
  swap(f[10-1],f[21-1]);
  swap(f[16-1],f[18-1]);
}

void ba(){
  swap(f[1-1],f[28-1]);
  swap(f[2-1],f[29-1]);
  swap(f[3-1],f[30-1]);
  swap(f[15-1],f[16-1]);
  swap(f[19-1],f[21-1]);
}
int main(){
  int n;
  cin >> n;
  int q_size;
  for(int j=0;j<n;j++){
   queue< vector<int> > q;
   for(int i=0;i<30;i++){
     cin >>f[i];
   }
   q.push(f);

   for(int l=0;l<9;l++){
     q_size=q.size();

     for(int k=0;k<q_size;k++){
       for(int i=0;i<30;i++){
         f[i]=q.front()[i];
       }
       if(cubecheck()){
         cout << l <<endl;
         break;
       }
       fr();
       q.push(f);
       fr();
       ri();
       q.push(f);
       ri();
       le();
       q.push(f);
       le();
       ba();
       q.push(f);
       ba();
       q.pop();
    }
    if(cubecheck()){
      break;
    }
   }
 }
 return 0;
}

Measured memory_bytes: 14676
w, h, n = map(int, input().split())

# initial area
area = [[0, 0], [w, h]]

for _ in range(n):
    # new point
    x, y, a = map(int, input().split())
    
    if (a == 1):
        if (area[1][0] < x):
            area[1][0] = area[0][0]
            break
        elif (area[0][0] < x):
            area[0][0] = x
    elif (a == 2):
        if (x < area[0][0]):
            area[0][0] = area[1][0]
            break
        elif (x < area[1][0]):
            area[1][0] = x
    elif (a == 3):
        if (area[1][1] < y):
            area[1][1] = area[0][1]
            break
        elif (area[0][1] < y):
            area[0][1] = y
    else:
        if (y < area[0][1]):
            area[0][1] = area[1][1]
            break
        elif (y < area[1][1]):
            area[1][1] = y

print((area[1][0] - area[0][0]) * (area[1][1] - area[0][1]))


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);

    ll N, K;
    cin >> N >> K;
    vector<vector<ll> > s(N); // s[i] := 種類 i の美味しさの集合

    for (ll i = 0; i < N; ++i) {
        ll t, d;
        cin >> t >> d;
        t--;
        s[t].push_back(d);
    }

    // 各種類について、美味しい順に並べる
    for (auto &v : s) {
        sort(v.begin(), v.end(), greater<ll>());
        if (v.empty()) v.push_back(-INF); // 番兵
    }

    // 「美味しさの最大値」の大きいネタ順
    sort(s.begin(), s.end(), [&](vector<long long> a, vector<long long> b) {
            return a[0] > b[0];});
 
    // まず K 種類選ぶ場合
    ll cur = 0;
    priority_queue<ll> que;
    for (ll i = 0; i < K; ++i) {
        cur += s[i][0];
        // 最初の一つ以外はqueに入れる
        for (int j = 1; j < s[i].size(); ++j) que.push(s[i][j]);
    }
    // 選ばれていない集合はすべてqueに入れる
    for (int i = K; i < N; ++i){
        for (int j = 0; j < s[i].size(); ++j){
            que.push(s[i][j]);
        }
    }

    // 走査
    // 初期値は別の集合からK個選んだとき
    ll res = cur + K*K;

    // 一つずつ集合を減らしていく
    for (ll x = K-1; x >= 1; --x) {
        ll v = s[x][0]; // 今集合に入っている値で一番小さいもの
        ll w = que.top(); // 集合に入っていないもので一番大きいもの
        if (v < w) {
            que.pop(); cur += w;
            que.push(v); cur -= v;
        }
        res = max(res, cur + x*x);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 8696
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  int n; readV(n);
  string s; readV(s);

  auto t = s.map!(si => si == 'o').array;

  auto calc(bool[] a)
  {
    foreach (i; 1..n-1) a[i+1] = a[i-1]^a[i]^t[i];
    if (a[0] == (a[$-2]^a[$-1]^t[$-1]) && a[1] == (a[$-1]^a[0]^t[0]))
      return true;
    else
      return false;
  }

  auto a = new bool[](n);
  foreach (i0; 0..2)
    foreach (i1; 0..2) {
      a[0] = i0 == 1;
      a[1] = i1 == 1;
      if (calc(a)) {
        foreach (i; 0..n)
          write(a[i] ? "S" : "W");
        writeln;
        return;
      }
    }

  writeln(-1);
}


Measured memory_bytes: 2812
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int n,l=1,r,ans[100010];
char s[100010];
void check()
{
	int x=l-1;
	while(s[x+1]=='R') ++x;
	for(int i=x;i>=l;--i) (x-i)%2==0?++ans[x]:++ans[x+1];
	for(int i=x+1;i<=r;++i) (i-x)%2==0?++ans[x]:++ans[x+1];
	return;
}
int main()
{
	scanf("%s",s+1),n=strlen(s+1);
	for(int i=1;i<=n;++i)
	{
		if(s[i]=='R'&&s[i-1]=='L') r=i-1,check(),l=i;
	}
	r=n,check();
	for(int i=1;i<=n;++i) printf("%d ",ans[i]);
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

const ll INF = 1e12;

int main() {
    int N;
    cin >> N;
    ll rightTop = -INF;
    ll leftTop = -INF;
    ll rightBottom = INF;
    ll leftBottom = INF;
    rep(i, N) {
        ll x, y;
        cin >> x >> y;
        rightTop = max(rightTop, x+y);
        leftTop = max(leftTop, y-x);
        rightBottom = min(rightBottom, y-x);
        leftBottom = min(leftBottom, x+y);
    }
    ll ans = max(rightTop - leftBottom, leftTop - rightBottom);
    cout << ans << '\n';
    return 0;
    // ll, 0, -, 1i, for s&g, debug
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#define pb push_back
#define mpr make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ll long long
#define ld long double
#define all(arr) arr.begin(), arr.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define fo(i, l, r) for (int i = l; i <= r; i++)
#define INF 1000000001
#define inf1 1000000000000000001
#define MOD 1000000007
#define pie 3.14159265358979323846264338327950L
#define N 100005
#define mid(l, r) l + (r - l) / 2
#define vec vector<int>
#define vecl vector<ll>
#define umap unordered_map<ll,ll>
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;
#define endl "\n"
using namespace std;

int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};  
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}
ll lcm(ll a, ll b) { return (a*b)/ gcd(a,b);}


ll pow2( ll n, ll cnt ){
  if( cnt == 1 ) return n;
  if( cnt == 0 ) return 1;
  if( cnt%2 == 0 ){
    ll tmp = pow2(n,cnt/2);
    return tmp%MOD*tmp%MOD;
  }else{
    ll tmp = pow2(n,cnt/2);
    return tmp%MOD*n%MOD*tmp%MOD;
  }
}
 

ll fac( ll n, ll cnt ){
  if( cnt == 1 ) return n;
  if( cnt == 0 ) return 1;
  return fac(n-1,cnt-1)%MOD*n%MOD;
}


void test_case() {

    ll n, a, b;
    cin>>n >>a >>b;

    ll xa = fac(n,a);
  ll ya = fac(a,a);
  ll amod = xa*pow2(ya,MOD-2)%MOD;
  if( amod < 0 ) amod += MOD;

 
  // nCb mod MOD を計算
  ll xb = fac(n,b);
  ll yb = fac(b,b);
  ll bmod = xb*pow2(yb,MOD-2)%MOD;
  if( bmod < 0 ) bmod += MOD;

 
  ll ans = pow2(2,n);
  if( ans < 0 ) ans += MOD;
  ans -= amod + bmod + 1;
 
  while( ans < 0 )
    ans += MOD;
 
  cout << ans << endl;





    






}


int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout<<fixed<<setprecision(20);

    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);


    int t = 1;
    //cin >> t;
    while(t--)
    {   
        test_case();
    }
}


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

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

    int sn = s.length();
    int tn = t.length();

    int ans = 100000;
    int cou = 0;
    for(int i = 0; i <= sn - tn; i++){
        cou = 0;
        for(int j = 0; j < tn; j++){
            if(s[i + j] != t[j]){
                cou++;
            }
        }

        if(ans > cou){
            ans = cou;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3628
from bisect import bisect_right, bisect_left
from collections import Counter, deque
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import groupby, permutations, combinations, product
from sys import stdin, stderr


# 最大公約数（ユークリッドの互除法）
# Python3.5 で math.gcd()が追加され、
# AtCoder環境と最新環境でパッケージが分かれてしまったので、自分で書いておく
def gcd(x, y):
    return x if y == 0 else gcd(y, x % y)


# 拡張ユークリッド互除法
# 正整数x, y について、a*x + b*y == gcd(x,y)なるa,bを返す。
# 特に、互いに素なるx, yについては a*x + b*y == 1 となる a, b。
def exgcd(x, y):
    if y == 0:
        return 1, 0
    a, b = exgcd(y, x % y)
    return b, a - (x // y) * b


# 最小公倍数
def lcm(x, y):
    m = gcd(x, y)
    return (x // m) * (y // m)


def main():
    n = int(input())
    a = [int(x) for x in input().split()]
    flag = True
    for x in a:
        if x % 2 == 0:
            if not x % 3 == 0 and not x % 5 == 0:
                flag = False

    return "APPROVED" if flag else "DENIED"


if __name__ == "__main__":
    print(main())

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

int main() {
    ll n;
    cin>>n;
    vector<ll> a(n+1),b(n);
    rep(i,n+1)cin>>a[i];
    rep(i,n)cin>>b[i];
    ll sum=0;
    rep(i,n){
        if(a[i]>=b[i]){
            sum+=b[i];
        }else {
            sum+=a[i];
            ll redi=b[i]-a[i];
            if(a[i+1]>=redi){
                a[i+1]-=redi;
                sum+=redi;
            }else{
                sum+=a[i+1];
                a[i+1]=0;
            }
        }
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 1792