akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

int a[5][5];
int b[20];
bool c[5][5];
signed main()
{
    REP(i,3) REP(j,3) cin>>a[i][j];
    int n;
    cin>>n;
    REP(i,n) cin>>b[i];
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            for (int k = 0; k < 3; k++)
            {
                if(a[j][k]==b[i]) c[j][k]=true;
            }
            
        }
        
    }
    if ((c[0][0] & c[1][1] & c[2][2]) || (c[0][2] & c[1][1] & c[2][0])){
        cout<<"Yes"<<endl;
        return 0;
    }

        for (int i = 0; i < 3; i++)
        {
           
                if(c[i][0] & c[i][1] & c[i][2]){
                    cout<<"Yes"<<endl;
                    return 0;
                }
            
        }

        for (int i = 0; i < 3; i++)
        {

            if (c[0][i] & c[1][i] & c[2][i])
            {
                cout << "Yes" << endl;
                return 0;
            }
        }
    cout<<"No"<<endl;
        return 0;
}

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

int main() {
  int A,B,C,D,L,R;
  cin >> A >> B >> C >> D;
  L = A + B;
  R = C + D;
  if(L > R) {
    cout << "Left" << endl;
  }else if(L == R) {
    cout << "Balanced" << endl;
  }else{
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a);i<(b);++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
#define INF 1000000000000000
#define MOD 1000000007
using PII = pair<int64_t, int64_t>;
using VI = vector<int64_t>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;
using i64 = int64_t;
template<typename T> void invec(vector<T> &A){for(T& a : A) cin >> a;} 

VI dist; 
queue<int> que;
bool bfs(const vector<VP> &G){
    while (!que.empty()) {
        int v = que.front(); 
        que.pop();
        for (PII nv : G[v]) {
            i64 d = dist[v] + nv.second;
            if (dist[nv.first] != -INF) {
                if (d != dist[nv.first]) return false;
                else continue;
            }
            dist[nv.first] = d;
            que.push(nv.first);
        }
    }
    return true;
}

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

int N, M; cin >> N >> M;
dist.assign(N+1, -INF);
vector<VP> pos(N+1);
set<int> vs;
rep(i, 0, M){
    int l, r, d; cin >> l >> r >> d;
    vs.insert(l);
    vs.insert(r);
    pos[l].emplace_back(r, d);
    pos[r].emplace_back(l, -d);
}
for(int v: vs){
    if (dist[v] != -INF) continue;
    dist[v] = 0;
    queue<int>().swap(que);
    que.push(v);
    if (!bfs(pos)) {
        cout << "No\n";
        return 0;
    }
}
cout << "Yes\n";

return 0;
}
// 書いて考える．場合分け．情報整理．
// 単純に分かる量から．愚直解を実装して研究．
// 境界，出力文字列 チェック．行末にスペース入れない．
// 可読性優先．高速化次点．
// まずは全探索，分割，次にDP
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性，二分探索
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// テストケース作成は数表あり
// 実行エラー：vector添え字超え．0割り．



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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

    int N,K;
    Scd2(N,K);
    vi p(N);
    Rep(i,N){
        Scd(p[i]);
    }

    vector<double> q(N);
    Rep(i,N){
        q[i] = 1.0*(p[i]+1)/2;
    }

    double tmp = 0.0;
    Rep(i,K){
        tmp += q[i];
    }
    double ans = tmp;

    Repe(i,N,K){
        tmp += q[i];
        tmp -= q[i-K];
        ans = max( tmp, ans );
    }

    printf ("%.11lf\n", ans );

    return 0;
}



Measured memory_bytes: 2560
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<30;

typedef pair<int,int> pii;

pii gcd(int a, int b) {
  if (b == 0) {
    return pii(a, 0);
  }
  pii p = gcd(b,a%b);
  return pii(p.first, p.second + 1);
}

int main() {
  int a, b;
  while(cin >> a >> b, a||b) {
    if (a<b)
      swap(a,b);
    pii p = gcd(a,b);
    cout << p.first << " " << p.second << endl;
  }
}

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


double dp[3010][3010];  //dp[表の枚数][裏の枚数]

int main() {
  int n;
  cin >> n;
  memset(dp,0.0,sizeof(dp));
  dp[0][0] = 1.0;
  for(int i = 0; i < n; i++) { 
    double p;
    cin >> p;
    for(int j = 0; j <= i; j++) {  //jは表の枚数
      dp[j+1][i-j] += dp[j][i-j]*p;
      dp[j][i-j+1] += dp[j][i-j]*(1.0-p);
    }
  }
  double ans = 0.0;
  for(int i = n; i > n/2; i--) {
     ans += dp[i][n-i];
  }
  printf("%.10f\n", ans);
  return 0;
}

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

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

using namespace std;

int main(){
	int n; scanf("%d",&n);
	int t=0,x=0,y=0;
	rep(i,n){
		int t2,x2,y2; scanf("%d%d%d",&t2,&x2,&y2);
		int d=abs(x2-x)+abs(y2-y);
		if(t2-t<d || (t2-t)%2!=d%2){ cout<<"No"<<endl; return 0; }
	}
	cout<<"Yes"<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef std::vector<ll> lls;
#define MIN(a, b) ( ((a)<(b)) ? (a) : (b) )
#define MAX(a, b) ( ((a)>(b)) ? (a) : (b) )

void cinv(lls& llVec, ll n) {
	ll val;
	llVec.reserve((size_t)(n));
	for (ll i = 0; i < n; i++) {
		cin >> val;
		llVec.push_back(val);
	}
}


int main()
{
	ll A, B, C;  cin >> A >> B >> C;

	ll r = C - (A - B);

	if (r < 0) r = 0;

	cout << r << '\n';

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#include <vector>
#include <queue>
#include <iomanip>
#include <string>
#include <algorithm>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep_1 (i,j,n) for(int i=j;i<n;i++)
typedef long long ll;
typedef long l;
const ll l_INF = 101010101000;
const int INF = 1010101010;
const int dx[4] = {-1,0,1,0};
const int dy[4] = {0,-1,0,1};
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;

int main(){
  ll n;
  cin>>n;
  if(n%2==1) cout << 0;
  else{
    ll count=0;
    n/=2;
    ll n_2 = n;
    while(n>0){
      count+=n/5;
      n/=5;
    }
    cout << count;
  }
}


Measured memory_bytes: 3600
#gcdは3.4.3だとfractionsにある
from fractions import gcd
import math

from math import factorial as f

from math import ceil,floor,sqrt


import bisect
import re
import heapq


from copy import deepcopy
import itertools

from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

def main():
            
    n,k,s = mi()
    a = []
    if s == 10**9:
        for i in range(k):
            a.append(s)
        for i in range(n-k):
            a.append(1)
    else:
        for i in range(k):
            a.append(s)
        for i in range(n-k):
            a.append(10**9)
    print(*a)




main()


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

int cmb(int n, int k) {
  if(n==k || k==0)
    return 1;
  else
    return cmb(n-1, k-1) + cmb(n-1, k);
}

int cp(int s) {
  int sum = 0;
  for(int i=0; i<s; i++)
    sum += cmb(s-1, i);
  return sum;
}

void cf(string &s, vector<string> &f, int sz) {
  int i;
  if(sz == 1) {
    for(i=0; i<f.size(); i++)
      f.at(i).push_back(s.at(s.size()-1));
    return;
  }
  
  for(i=0; i<f.size(); i++) {
    f.at(i).push_back(s.at(s.size()-sz));
    int w = pow(2, s.size()-sz+1);
    if(i%w < w/2)
      f.at(i).push_back('+');
  }
  cf(s, f, sz-1);
  return;
}

long long f_sum(vector<string> f) {
  long long sum = 0;
  for(string &fl : f) {
    long psum=0, esum=0;
    for(int i=0; i<fl.size(); i++) {
      if(fl.at(i) == '+') {
        psum += esum;
        esum = 0;
      } else {
        esum *= 10;
        esum += fl.at(i) - '0';
      }
      if(i == fl.size()-1)
        psum += esum;
    }
    sum += psum;
  }
  return sum;
}

int main() {
  string s;
  cin >> s;
  int pt = cp(s.size());
  
  vector<string> f(pt);
  cf(s, f, s.size());
  cout << f_sum(f) << endl;
}

Measured memory_bytes: 256
<?php
/*
    Problem URL : https://beta.atcoder.jp/contests/abc064/tasks/abc064_a

    Score  :
    Result :
    Time   : ms
    Memory : KB
 */

// define('DEBUG', true);
define('DEBUG', false);

ini_set('error_reporting', E_ALL & ~E_NOTICE);

fscanf(STDIN, "%d %d %d", $X, $A, $B);

if ($A >= $B) {
    echo "delicious\n";
} else if ($X + $A >= $B) {
    echo "safe\n";
} else {
    echo "dangerous\n";
}


Measured memory_bytes: 4604
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
     ll n;
     cin>>n;
     map< string, ll > m;
     for(int i=0;i<n;i++)
     {
         string s;
         cin>>s;
         sort( s.begin() ,s.end() );
         m[s] ++;
     }
     ll ans =0;
     auto it = m.begin();
     for(;it!= m.end();it++)
     {
         ll temp = it->second;
         ans += (( temp*(temp-1) )/2);
     }
     cout<<ans;
}

Measured memory_bytes: 11300
import sys
from fractions import gcd
from functools import reduce

def solve():
    n = int(input())
    a = [int(i) for i in input().split()]

    ans = reduce(lcm, a, 1)

    print(ans)

def lcm(a, b):
    return a * b // gcd(a, b)

if __name__ == '__main__':
    solve()

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

int main() {
    int n, k, q; cin >> n >> k >> q;
    vector<int> a(q);
    vector<int> b(n);
    int tmp;
    rep(i, q) {
        cin >> tmp;
        b.at(tmp-1)++;
    }
    rep(i, n) {
       if (b.at(i) - q + k > 0)
            cout << "Yes" << endl;
        else
            cout << "No"  << endl;
    }

    return 0;
}

Measured memory_bytes: 1408
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;
use nalgebra::max;
use std::mem::swap;
use std::time::Instant;
use rand::random;

const MIN: i64 = std::i64::MIN;

fn score(t: &Vec<usize>, c: &Vec<i64>, s: &Vec<Vec<i64>>) -> i64 {
    let mut last = vec![0; 26];
    let mut score = 0;
    for i in 0..t.len() {
        score += s[i][t[i]] - (0..26).fold(0, |acc, x| acc + (i as i64 + 1 - last[x]) * c[x]);
        last[t[i]] = i as i64;
    }
    score
}

#[fastout]
fn main() {
    input! {
    d: usize,
    c: [i64; 26],
    s: [[i64; 26]; d]
    }
    let start = Instant::now();
    let mut dp = vec![vec![vec![vec![]; 27]; 26]; d + 1];
    for i in 0..=d {
        for j in 0..26 {
            for k in 0..27 {
                dp[i][j][k].push(MIN)
            }
        }
    }
    for i in 0..26 {
        for j in 0..27 {
            dp[0][i][j][0] = 0;
        }
    }
    for i in 0..d {
        for j in 0..26 {
            for k in 0..26 {
                let t = dp[i][k][0][0] - (1..27)
                    .fold(0, |acc, x| acc + if j != x - 1 { (i as i64 + 1 - dp[i][k][x][dp[i][k][x].len() - 1]) * c[x - 1] } else { 0 }) + s[i][j];
                if t > dp[i + 1][j][0][0] {
                    dp[i + 1][j][0][0] = t;
                    for l in 1..27 {
                        dp[i + 1][j][l] = dp[i][k][l].clone();
                        if j == l - 1 {
                            dp[i + 1][j][l].push(i as i64 + 1);
                        }
                    }
                }
            }
        }
    }
    let mut ans = vec![vec![]; 26];
    ans[0].push(MIN);
    for i in 0..26 {
        if ans[0][0] < dp[d][i][0][0] { swap(&mut ans, &mut dp[d][i]) }
    }
    let mut t = vec![0; d];
    for i in 1..27 {
        for j in 0..ans[i].len() {
            if ans[i][j] == 0 { continue; }
            t[ans[i][j] as usize - 1] = i - 1;
        }
    }
    let mut end = start.elapsed();
    let mut cur_s = score(&t, &c, &s);
    while end.as_nanos() < 1_860_000_000 {
        let k = random::<usize>() % d;
        let prev_k = t[k];
        t[k] = random::<usize>() % 26;
        if t[k] == prev_k {continue}
        let next_s = score(&t, &c, &s);
        if cur_s > next_s {
            t[k] = prev_k;
        } else {
            cur_s = next_s;
        }
        end = start.elapsed();
    }
    for i in 0..d {
        println!("{}",t[i] + 1);
    }
}


Measured memory_bytes: 29212
#include <stdio.h>

int main()
{
  int a,b,sum;
  
  scanf("%d %d", &a, &b);
  sum = a * b;
  if (sum % 2 == 0) {
    printf("Even\n");
  } else {
    printf("Odd\n");
  }
  return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<cstring>
#include<cmath>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>
#include<iomanip>
#include<random>

#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(int i = 0;i < n;i++)
#define FOR(i,a,b) for(int i = a;i < b;i++)
#define MEM(a,b) memset(a,b,sizeof(a))
#define ALL(x) (x).begin(),(x).end()
#define LMAX 9223372036854775807
#define LMIN -9223372036854775808

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ull, ull> UP;
typedef tuple<int, int, int> T;

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) {}
	void unionSet(int x, int y) {
		x = root(x), y = root(y);
		if (x != y) {
			if (data[y] < data[x])swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	int k = a % b;
	if (k == 1)return 1;
	if (k == 0)return b;
	int ans = gcd(b, k);
	return ans;
}
ll digisum(ll a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}
ll countpow(ll a, ll b) {
	int ans = 0;
	if (b == 0)return -1;
	while (1) {
		if (a % b == 0) {
			a /= b;
			ans++;
		}
		else break;
	}
	return ans;
}


int main() {
	IOS;
	int a;
	cin >> a;
	int ans = 800 * a;
	int z = a / 15;
	ans -= z * 200;
	cout << ans << endl;
}



Measured memory_bytes: 256
def gcd(a, b):
    # ?????§??¬?´???°
    while b > 0:
        a, b = b, a % b
    return a


def lcm(a, b):
    # ????°???¬?????°
    return a * b // gcd(a, b)

n = int(input())
a = list(map(int, input().split()))
ans = a[0]
for i in range(1,n):
    ans = lcm(ans, a[i])
print(ans)

Measured memory_bytes: 7744
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>

using namespace std;

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

int N,Q;
int X[100010];

struct Event {
	int t;
	int type;
	int x;
	Event(int t, int type, int x) : t(t), type(type), x(x) {}
	bool operator<(Event &b) {
		if (t == b.t) {
			return type < b.type;
		}
		return t < b.t;
	}
};

void printEvent(Event &a)
{
	printf("{ t: %lld, type: %lld, x: %lld}\n", a.t,a.type,a.x);
}

signed main()
{
	cin >> N >> Q;

	vector<Event> events;

	rep(i, N) {
		int s, t, x;
		cin >> s >> t >> x;
		events.push_back(Event(s - x, 1, x));
		events.push_back(Event(t - x, -1, x));
	}

	sort(begin(events), end(events));

	multiset<int> se;
	vector<int> ans(Q);

	int cur = 0;
	rep(i, Q) {
		int d; cin >> d;
		while (cur < events.size() and events[cur].t <= d) {
			if (events[cur].type == 1) {
				se.insert(events[cur].x);
			} else {
				auto itr = se.find(events[cur].x);
				se.erase(itr);
			}
			cur++;
		}

		if (se.empty()) {
			ans[i] = -1;
		} else {
			ans[i] = *se.begin();
		}
	}

	rep(i, Q) {
		cout << ans[i] << endl;
	}
}


Measured memory_bytes: 23528
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll t,i,j,n,m,k,r,r1,ans,ck,cnt=0,sum=0,c=0;
    string s,s1,s2,tmp;
    cin>>n>>m;
    if(m%n==0)cout<<m+n<<endl;
    else{cout<<m-n<<endl;}
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF LLONG_MAX/3
#define eps LDBL_EPSILON
#define moder 100000
#define pie 3.141592653589793238462643383279
#define P std::pair<int,int>
#define prique priority_queue
using namespace std;
signed main(){
	int ab,ac,bc;
	cin>>ab>>bc>>ac;
	int ans=ab*bc/2;
	
	cout<<ans<<endl;
	
	
}


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

using namespace std;

int main(){
    int n, m; cin >> n >> m;
    unordered_map<int, int> end_to_start;
    for(int i=0; i<m; ++i){
        int a, b; cin >> a >> b;
        end_to_start[b]=max(a, end_to_start[b]);
    }
    int last_end=1;
    int ans=0;
    for(int i=1; i<=n; ++i){
        if(end_to_start[i]>=last_end){
            ++ans;
            last_end=i;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4388
#include <iostream>
#include <vector>
#include <map>

using namespace std;

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

    map<int, int> M;
    for(int i = 0;i < N; i++){
        if(a[i] < 400){
            M[0]++;
        }else if(a[i] < 800){
            M[1]++;
        }else if(a[i] < 1200){
            M[2]++;
        }else if(a[i] < 1600){
            M[3]++;
        }else if(a[i] < 2000){
            M[4]++;
        }else if(a[i] < 2400){
            M[5]++;
        }else if(a[i] < 2800){
            M[6]++;
        }else if(a[i] < 3200){
            M[7]++;
        }else{
            M[8]++;
        }
    }

    int ans_min = 0;
    int ans_max = 0;
    for(auto p : M){
        if(p.first != 8){
            ans_min++;
            ans_max++;
        }else{
            if(ans_min == 0){
                ans_min++;
            }
            ans_max += p.second;
        }
    }
    cout << ans_min << " " << ans_max << endl;


    return 0;
}

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

int main()
{
	ll n, m, a, b;
	cin >> n >> m;
	a = n == 1 ? 1:n-2;
	b = m == 1 ? 1:m-2;
	cout << a*b << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll A,B,C,D,E,F,G,H,I,J,K,N,i=0,j=0;
ll abc=0;
ll arc=0;
ll cnt=0;
string S,T;
map<char,ll> m;
bool flag;
int main()
{
	cin>>N;
	vector<ll> v(N);
	for(i=0;i<N;i++) cin>>v[i];
	sort(v.begin(),v.end());
	for(ll K=1;K<=v[N-1];K++){
		auto ite=(upper_bound(v.begin(),v.end(),K));
		arc=ite-v.begin();
		abc=N-arc;
		if(abc<arc) break;
		if(abc==arc) cnt++;
	}
	cout<<cnt<<endl;
}

Measured memory_bytes: 1024
n,k,q,*a=map(int,open(0).read().split())
s=sorted
m=1e18
for b in a:
    i=[i for i,t in enumerate(a)if t<b]
    l=s(sum([s(a[i+1:j])[::-1][k-1:]for i,j in zip([-1]+i,i+[n])],[]))
    if len(l)>=q:m=min(m,l[q-1]-b)
print(m)

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

ll inf=9223372036854775806;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	int ans=0,i;
	string a;
	cin>>a;
	for(i=0;i<a.size();i++){
		if (a[i]=='2'){
			ans++;
		}
	}
	cout<<ans;
	return 0;
}

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

using namespace std;

const int DIM = 2010;

int n, i, v[DIM], nr, p, u;

int main(){
    cin >> n;
    for (i = 1; i <= n; ++i) {
        cin >> v[i];
    }
    sort(v + 1, v + n + 1);
    for (i = n; i > 0; --i){
        p = 1;
        u = i - 1;
        while (p < u){
            if (v[p] + v[u] > v[i]) {
                nr += u - p;
                u--;
            } else {
                p++;
            }
        }
    }
    cout << nr << "\n";
    return 0;
}


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

using namespace std;

#define MAX_N 100
#define MAX_C 20
#define MAX_R 10010
#define INF (1<<29)

struct State {
    int d, v;
    
    State(int d, int v) 
        : d(d), v(v) {}
    
    bool operator < (const State &s) const {
        return d > s.d;
    }
};

int N, M, C, mc[MAX_C];
vector<int> q[MAX_C];
int cost[MAX_C][MAX_R];
int dist[MAX_N][MAX_N][MAX_C];

int get_cost(int c, int d)
{
    int n = q[c].size();
    if (q[c][n-1] < d) {
        return cost[c][q[c][n-1]] + (d - q[c][n-1]) * mc[c];
    } else {
        return cost[c][d];
    }
}

int dijkstra(int src, int dst)
{
    int d[MAX_N];
    fill(d, d + MAX_N, INF);    
    d[src] = 0;
    
    priority_queue<State> Q;
    Q.push(State(0, src));
    
    while (!Q.empty()) {
        State s = Q.top(); Q.pop();
        int dd = s.d, v = s.v;
        if (v == dst) return dd;
        for (int i = 0; i < N; i++) {
            if (v == i) continue;
            for (int j = 0; j < C; j++) {
                if (dist[v][i][j] == INF) continue;
                int ncost = get_cost(j, dist[v][i][j]) + d[v];
                if (ncost < d[i]) {
                    d[i] = ncost;
                    Q.push(State(d[i], i));                    
                }
            }
        }
    }
    return -1;
}

void init()
{
    for (int i = 0; i < C; i++) {
        q[i].clear();
    }

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            for (int k = 0; k < C; k++) {
                dist[i][j][k] = (i != j ? INF : 0);
            }
        }
    }

}

void warshall_floyd()
{
    for (int k = 0; k < N; k++) {
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                for (int l = 0; l < C; l++) {
                    dist[i][j][l] = min(dist[i][j][l],
                                        dist[i][k][l] + dist[k][j][l]);
                }
            }
        }
    }
}

int main()
{
    int src, dst;
    while (cin >> N >> M >> C >> src >> dst, N) {
        init();
        src--; dst--;
        for (int i = 0; i < M; i++) {
            int a, b, c, d;
            cin >> a >> b >> d >> c;
            a--; b--; c--;
            dist[a][b][c] = min(dist[a][b][c], d);
            dist[b][a][c] = min(dist[b][a][c], d);
        }        

        warshall_floyd();
        vector<int> p(C);
        for (int i = 0; i < C; i++) {
            cin >> p[i];
        }       
        
        for (int i = 0; i < C; i++) {
            vector<int> r(p[i]);
            q[i].resize(p[i]+1, 0);
            for (int j = 1; j < p[i]; j++) {
                cin >> q[i][j];
            }            
            q[i][p[i]] = q[i][p[i]-1] + 1;
            
            for (int j = 0; j < p[i]; j++) {
                cin >> r[j];
                mc[i] = r[j];
            }
            
            cost[i][0] = 0;
            for (int j = 0; j < p[i]; j++) {
                for (int k = q[i][j]+1; k <= q[i][j+1]; k++) {
                    cost[i][k] = cost[i][k-1] + r[j];
                }
            }
        }
        cout << dijkstra(src, dst) << endl;
    }
    return 0;
}

Measured memory_bytes: 4728
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define printVector(v) rep(i, v.size()) cout << v[i] << endl;

int main()
{
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> students(N);
  vector<pair<int, int>> check_points(M);
  rep(i, N)
  {
    cin >> students[i].first >> students[i].second;
  }
  rep(i, M)
  {
    cin >> check_points[i].first >> check_points[i].second;
  }

  vector<int> ans(N);
  rep(i, N)
  {
    pair<int, int> min_dist;
    min_dist = make_pair(INT32_MAX, 0);
    rep(j, M)
    {
      int dist = abs(students[i].first - check_points[j].first) + abs(students[i].second - check_points[j].second);
      if (dist < min_dist.first)
        min_dist = make_pair(dist, j);
    }
    ans[i] = min_dist.second + 1;
  }
  printVector(ans);
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int h, w;
    int i, j;
    while(1){
        scanf("%d %d ", &h, &w);
        if(h==0&&w==0)break;
        for(i=0;i<h;i++){
            for(j=0;j<w;j++){
                if((i%2==0&&j%2==0)||(i%2==1&&j%2==1)){
                    printf("#");
                }else{
                    printf(".");
                }
            }
            printf("\n");
        }
        printf("\n");
    }

    return 0;
}

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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] s = new int[n];
        for (int i = 0; i < n; i++) {
            s[i] = sc.nextInt();
        }
        int q = sc.nextInt();
        int[] t = new int[n];
        for (int i = 0; i < q; i++) {
            t[i] = sc.nextInt();
        }
        int c = 0;
        for (int i = 0; i < q; i++) {
            if (Arrays.binarySearch(s, t[i]) >= 0) {
                c++;
            }
        }
        System.out.println(c);
    }
}

Measured memory_bytes: 69036
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  long long int ans=0;
  vector<int>v(n+1);
  vector<int>w(n+1);
  for(int i=0;i<n;++i){
    cin>>v[i]>>w[i];
  }
  sort(v.begin(),v.end());
  reverse(v.begin(),v.end());
  sort(w.begin(),w.end());
  for(int i=0;i<n+1;++i){
    if(v[i]>w[i]) ans+=(v[i]-w[i])*2;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 1024
#define _GLIBCXX_DEBUG
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<string>
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rep2(i,s,n) for(int i=s;i< (int)n; i++)
#define ll long long 
#define all(v) v.begin(),v.end()
using namespace std;
const ll inf = 1000000007;
int main() {
  int  w,h,n; cin >>w>>h>>n;
  int XL=0;
  int XR=w;
  int YU=0;
  int YT=h;
  rep(i,n){
    int x,y,a; cin >>x>>y>>a;
    if(a==1)XL=max(XL,x);
    if(a==2)XR=min(XR,x);
    if(a==3)YU=max(YU,y);
    if(a==4)YT=min(YT,y);
  }
  if(XL<XR&&YT>YU)cout<<(XR-XL)*(YT-YU)<<endl;
  else cout <<0<<endl;
  //cout <<XR<<XL<<YT<<YU<<endl;
}

Measured memory_bytes: 256
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)
#define FORR(i,n,m) for(int i=n-1;i>=m;i--)
#define all(in) in.begin(),in.end()
#define ALL(in,K) in,in+K
#define INF 1e18
#define MOD 100000007
#define SIZE 10005
#define PI 	3.14159265358979323846

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k;
    cin >> n >> k;
    ll num[100000]={0};
    REP(i,n){
        int a,b;
        cin >> a >> b;
        num[a] += b;
    }
    ll sum=0;
    REP(i,100001){
        sum += num[i];
        if(sum >= k){
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 1024
import sys

INF = 10 ** 8
N = int(input())
S = []
for _ in range(N):
    S.append(list(map(int,list(input()))))

color = [0] * N

def dfs(x, c):
    color[x] = c
    for i in range(N):
        if S[x][i] and color[i] == c:
            return False
        if S[x][i] and color[i] == 0 and not dfs(i, -c):
            return False
    return True

for i in range(N):
    if color[i] == 0 and not dfs(i, 1):
        print(-1)
        sys.exit()

d = [[INF if S[i][j] == 0 else S[i][j] for i in range(N)] for j in range(N)]

for k in range(N):
    for i in range(N):
        for j in range(N):
            if i != j:
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])

ans = 0

for i in range(N):
    for j in range(N):
        if d[i][j] != INF:
            ans = max(ans, d[i][j]+1)
print(ans)

Measured memory_bytes: 75100
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#define endl "\n"
#define mod 1000000007
#define ll long long int
using namespace std;

int main()
{
    ll n;
    cin >> n;

    map <ll, ll> mp;

    ll i, data;
    for(i = 0; i < n; i ++)
    {
    	cin >> data;
    	mp[data] ++;
    }
    
    ll count = 0;
    ll flag = 0;
    ll ans = 1;
    if(n % 2 == 0)
    {
    	for(i = 0; i < n / 2; i ++)
    	{
    		if(mp[2 * i + 1] == 2)
    		{
    			ans = (ans % mod * 2) % mod;
    			count ++;
    		}
    		else
    		{
    			flag = 1;
    			break;
    		}
    	}

    	if(flag == 0 && count == n / 2)
    		cout << ans << endl;
    	else
    		cout << "0" << endl; 
    }
    else if(n % 2 == 1)
    {
    	if(mp[0] != 1)
    		flag = 1;
    	for(i = 1; i <= n / 2; i ++)
    	{
    		if(mp[2 * i] == 2)
    		{
    			ans = (ans % mod * 2) % mod;
    			count ++;
    		}
    		else
    		{
    			flag = 1;
    			break;
    		}
    	}

    	if(flag == 0)
    		cout << ans << endl;
    	else
    		cout << "0" << endl; 
    }
}

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

#define sysp system("pause")

int a,b,c;
string s,t,u;

int main(){
	cin>>s>>t;
	for(int i=0;i<s.size();i++){
		string tmp;
		for(int j=i;j<s.size()+i;j++)tmp+=s[j%s.size()];
		if(tmp==t){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
} 

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

using namespace std;

#define loop(i,a,b) for(int i=(a);i<int(b);i++)
#define rep(i,b) loop(i,0,b)

string replaceAll(string s, const string &f, const string& t) {
    string r;
    for (int p = 0; (p = s.find(f)) != s.npos;) {
        r += s.substr(0, p) + t;
        s = s.substr(p + f.size());
    }
    return r + s;
}

int main(){
    int n;
    int const inf = 1 << 29;
    while (cin >> n && n){
        string a[10], b[10];
        rep(i, n)cin >> a[i] >> b[i];
        queue<pair<int,string>> q;
        string src, dst;
        cin >> src >> dst;
        set<string> dp;
        q.emplace(0, src);
        dp.insert(src);
        int ans = inf;
        while (q.size()){
            auto state = q.front(); q.pop();
            string s = state.second;
            int d = state.first;
            if (s == dst){
                ans = d;
                break;
            }
            auto it = dp.insert(s);
            if (!it.second && d != 0) continue;
            rep(i, n){
                string t = replaceAll(s, a[i], b[i]);
                if (t.size() > dst.size()) continue;
                q.emplace(d + 1, t);
            }
        }
        if (ans == inf)ans = -1;
        cout << ans << endl;
    }
}

Measured memory_bytes: 1600
import math
import sys
#####sorting a dictionary by the values#####
def dict_sort(ans):
    ans=sorted(ans.items(),reverse=True,key=lambda kv:(kv[1]))
#####Primes till Nth#####
def seive_primes(n):
    flag=[0]*(n+10)
    flag[1]=flag[0]=1
    i=2
    while i*i<=n+1:
        if flag[i]==0:
            j=i*i
            while j<=n+1:
                flag[j]=1
                j+=i
        i+=1
    return flag
##### naive method for testing prime or not#####
def is_prime(n):
    if n==1:
        return 0
    for i in range(2,int(math.sqrt(n))+1):
        if n%i==0:
            return False
    return True
#####greatest common divisor of two numbers#####
def gcd(a,b):
    if b==0:
        return a
    return gcd(b,a%b)
#####least common multiplyer of two numbers#####
def lcm(a,b):
    return (a*b)//gcd(a,b)
#####factorial of a number#####
def fact(n):
    if n==1:
        return n
    return fact(n-1)*n
#####all the powers of two till nth#####
def pow_2s(n):
    ls=[]
    for i in range(1,n+1):
        ls.append(2**i)
    return ls
#####function that return all the letters#####
def alphbates():
    return "abcdefghijklmnopqrstuvwxyz"
#####taking an array/list as input#####
def inp():
    ls=list(map(int,input().split()))
    return ls
#####taking multiple inputs#####
def mult_inp():
    return map(int,input().split())
#####Main function starts from here#####
n,m=mult_inp()
ls=inp()
print(max(n-sum(ls),-1))

Measured memory_bytes: 9880
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
inline long long mod(long long n,long long m){return(n%m+m)%m;}
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};


int main(){
    int a,b,c; cin>>a>>b>>c;
    if(a<b&&b<c) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}



Measured memory_bytes: 3076
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int a = int.Parse(s[0]);
            int b = int.Parse(s[1]);
            int c = int.Parse(s[2]);
            if (c >= a && c <= b) Console.WriteLine("Yes");
            else Console.WriteLine("No");
        }
    }
}


Measured memory_bytes: 13140
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

int main(void) {
    int a, b;
    scanf("%d%d", &a, &b);
    if (a <= b) {
        for (int i = 0; i < b; i++) {
            printf("%d", a);
        }
    } else {
        for (int i = 0; i < a; i++) {
            printf("%d", b);
        }
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<cstdio>

using namespace std;

int main()
{
	int d;
	scanf("%d",&d);
	
	if(d==25)
	{
		cout<<"Christmas"<<endl;
		return 0;
	}
	
	if(d==24)
	{
		cout<<"Christmas Eve"<<endl;
		return 0;
	}
	
	if(d==23)
	{
		cout<<"Christmas Eve Eve"<<endl;
		return 0;
	}
	
	if(d==22)
	{
		cout<<"Christmas Eve Eve Eve"<<endl;
		return 0;
	}
	
	return 0;
 } 

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

int main(){
    int a[5];
    for(int i=0; i<5; i++){
        cin >> a[i];
    }
    int k;
    cin >> k;

    for(int i=0; i<5; i++){
        for(int j=i; j<5; j++){
            if(a[j] - a[i] > k){
                cout << ":(" << endl;
                return 0;
            }
        }
    }
    cout << "Yay!" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
void dfs(int node, vector<int> adj[], int dp[], bool vis[]) 
{ 
    vis[node] = true; 
    for (int i = 0; i < adj[node].size(); i++) { 
  
        if (!vis[adj[node][i]]) 
            dfs(adj[node][i], adj, dp, vis); 
        dp[node] = max(dp[node], 1 + dp[adj[node][i]]); 
    } 
} 
  
int main() {
    int m,n;
    cin>>n>>m;
    vector<int>adj[n+1];
    for(int i=0;i<m;i++)
    {
       int u,v;
       cin>>u>>v;
       adj[u].push_back(v);
    }
    int dp[n + 1]; 
    memset(dp, 0, sizeof dp); 
    bool vis[n + 1]; 
    memset(vis, false, sizeof vis); 
    for (int i = 1; i <= n; i++) { 
        if (!vis[i]) 
            dfs(i, adj, dp, vis); 
    } 
    int ans = 0; 
    for (int i = 1; i <= n; i++) { 
        ans = max(ans, dp[i]); 
    } 
    cout<<ans;
    return 0;
}

Measured memory_bytes: 12976
#include<stdio.h>
#include<stdlib.h>
#include<memory.h>
#include<math.h>

int sprInput(char *retstr, char *str, int strnum)
{
	char buf[256]={};
	int h, i, j;

	i = 0;
	for(h=0;h<strnum;h++){
		memset(buf, '\0', sizeof(buf));
		j = 0;
		if (str[i] == '\0') break;
		while(str[i] != ' ' && str[i] != '\n' && str[i] != '\0')
		{
			buf[j] = str[i];
			i++;
			j++;
		}
		i++;
	}
	memcpy(retstr, buf, sizeof(buf));

	return (retstr[0] == '\0' ? 0 : 1);
}

int main(int argc, char *argv[])
{
	int sInput;
	int a, b, c;
	char str[256]={};
	char buf[256]={};

	fgets(str, 256, stdin);

	sprInput(buf, str, 1);
	a = atoi(buf);
	sprInput(buf, str, 2);
	b = atoi(buf);
	sprInput(buf, str, 3);
	c = atoi(buf);

	if (a < b && b < c) {
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}

	return 0;
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}
const int MOD=1000000007;

int main() {
  int N;
  cin>>N;
  vector<int>A(N),B(N);
  int64_t sumA=0,sumB=0;
  for(int i=0;i<N;i++){
    cin>>A[i];
    sumA+=A[i];
  }
  for(int i=0;i<N;i++){
    cin>>B[i];
    sumB+=B[i];
  }
  if(sumA<sumB){cout<<-1<<endl;return 0;}

  int64_t need=0,ans=0;
  vector<int>amari;
  for(int i=0;i<N;i++){
    if(A[i]<B[i]){need+=B[i]-A[i];ans++;}
    else if(A[i]>B[i]){amari.push_back(A[i]-B[i]);}
  }
  if(need==0){cout<<0<<endl;return 0;}

  sort(amari.rbegin(),amari.rend());
  int cnt=0;
  for(int i=0;i<amari.size();i++){
    if(amari[i]>=need){cnt++;break;}
    else{need-=amari[i];cnt++;}
  }
  ans+=cnt;

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

Measured memory_bytes: 4324
#include <stdio.h>
#include <cmath>
#include <algorithm>

#define NUM 32000

int main(){
	int table[NUM],limit;

	for(int i=0; i < NUM;i++)table[i] = 1;
	table[0] = 0;
	table[1] = 0;

	limit = sqrt(NUM);

	for(int i=2;i<=limit;i++){
		if(table[i] == 1){
			for(int k=2*i;k < NUM; k += i){
				table[k] = 0;
			}
		}
	}

	int n,count = 0;

	scanf("%d",&n);

	printf("%d:",n);
	for(int i=2; i< NUM && n != 1; i++){
		while(table[i] == 1 && n%i == 0 && n != 1){
			printf(" %d",i);
			n /= i;
			count++;
		}
	}
	if(count == 0)printf(" %d",n);
	printf("\n");

	return 0;
}


Measured memory_bytes: 2880
n,m=map(int,input().split())

uf=[i for i in range(n+1)]

def uf_find(x):
    while uf[x]!=x:
        x=uf[x]
    return x

for i in range(m):
    x,y,z=map(int,input().split())
    a,b=uf_find(x),uf_find(y)
    if a>b:
        a,b=b,a
    uf[b]=a

c=set()
for i in range(1,n+1):
    c.add(uf_find(i))
print(len(c))
        

Measured memory_bytes: 21496
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0)
//#define MULTI_TEST
//#define GOOGLE
#ifdef LOCAL
#include "debugger.h"
#else
#define db(...)
#endif
#define ll long long
#define v32 vector<int>
#define v64 vector<ll>
#define s32 set<int>
#define s64 set<ll>
#define p32 pair<int, int>
#define p64 pair<ll, ll>
#define sz(v) (ll)(v).size()
#define fi first
#define se second
#define ln '\n'
const ll MOD = 998244353;
inline ll add(ll a, ll b, ll m) { return (((a % m + b % m) % m + m) % m); }
inline ll mul(ll a, ll b, ll m) { return (((a % m * b % m) % m + m) % m); }

const int N = 3005;
int dp[N][N];
int go(int i, int j, int a, int b)
{
	if (i == a && j == b)
		return 1;
	if (dp[i][j] != -1)
		return dp[i][j];
	int ans = 0;
	if (i - 1 >= a)
	{
		int tmp = mul(j, go(i - 1, j, a, b), MOD);
		ans = add(ans, tmp, MOD);
	}
	if (j - 1 >= b)
	{
		int tmp = mul(i, go(i, j - 1, a, b), MOD);
		ans = add(ans, tmp, MOD);
	}
	if (i - 1 >= a && j - 1 >= b)
	{
		int tmp = mul(i - 1, j - 1, MOD);
		tmp = mul(tmp, go(i - 1, j - 1, a, b), MOD);
		ans = add(ans, MOD - tmp, MOD);
	}
	return dp[i][j] = ans;
}
void solve(int tc)
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	memset(dp, -1, sizeof(dp));
	cout << go(c, d, a, b) << ln;
	return;
}

int main()
{
#ifndef LOCAL
	FASTIO;
#endif
	int t = 1;
#ifdef LOCAL
	clock_t start, stop;
	start = clock();
#endif
#ifdef MULTI_TEST
	cin >> t;
#endif
	for (int tc = 1; tc < t + 1; tc++)
	{
#ifdef GOOGLE
		cout << "Case #" << tc << ": ";
#endif
		solve(tc);
	}
#ifdef LOCAL
	stop = clock();
	cerr << "Time :" << fixed << setprecision(5) << double(stop - start) / double(CLOCKS_PER_SEC) << "s" << ln;
#endif
	return 0;
}


Measured memory_bytes: 39308
#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<ctime> 
using namespace std; 
typedef long long LL;
int main()
{ 
	char a[100];
	scanf("%s",a+1);
	if(a[1]==a[2]&&a[2]==a[3]||a[2]==a[3]&&a[3]==a[4])
	{	printf("Yes");
	}
		else
			printf("No");
			return 0;
			}

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

using namespace std;
using ll = long long;

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

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

  vector<int> l(n);
  rep(i, n) cin >> l[i];
  sort(l.begin(), l.end());

  ll ans = 0;
  rep(i, n) rep(j, i) {
    int d = lower_bound(l.begin(), l.end(), l[i] + l[j]) - l.begin() - (i + 1);
    if (d > 0) ans += d;
  }

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


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(X,Y) ((X)>(Y)?X=(Y),true:false)
#define chmax(X,Y) ((X)<(Y)?X=(Y),true:false)
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}
#define N 30
string s[N][N];
int main(){
	int h, w;
	cin>>h>>w;
	rep(i, h) rep(j, w) cin>>s[i][j];
	rep(i, h){
		rep(j, w){
			if(s[i][j]=="snuke"){
				cout<<(char)('A'+j)<<i+1<<endl;
			}
		}
	}
	
	return 0;
}


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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define RREP(i,s,n) for(lli i=s;i>=n;i--)
#define MOD 1000000007
#define NUM 2520
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define INF (1LL<<50)

lli data[200100];

signed main(){

	lli n;
	cin>>n;
	vector<lli> a(n);
	REP(i,0,n)cin>>a[i];

	vector<lli> b;

	//逆から見るぞ！
	RREP(i,n-1,0)
	{
		if(data[i+1]%2 != a[i]){
			b.push_back(i+1);
			//約数に全部足していく
			for(lli j=1;j*j<=(i+1);j++){
				if((i+1)%j==0){
					data[j]++;
					if((i+1)/j != j)data[(i+1)/j]++;
				}
			}
		}
	}
	cout<<b.size()<<endl;
	reverse(b.begin(),b.end());
	REP(i,0,b.size())cout<<b[i]<<" ";
	cout<<endl;

	return 0;
}

Measured memory_bytes: 4980
function Main(input) {
    const lines = input.split("\n");
    const [H, N] = lines[0].split(' ');
    const totalA = lines[1].split(' ').reduce((acc, current) => acc*1 + current*1);
    
    console.log(H > totalA ? 'No' : 'Yes');
}

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

Measured memory_bytes: 17904
while(1):
    n,x=map(int,input().split(" "))
    if(not n and not x):
        break
    count=0
    for i in range(1,n+1):
        for j in range(1,n+1):
            for k in range(1,n+1):
                if(i+j+k==x and i!=j and j!=k and i!=k):
                    #print(i,j,k)
                    count=count+1
    print(int(count/6))



Measured memory_bytes: 5596