akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <bitset>
#include <random>
#include <chrono>
#include <complex>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip> 

using namespace std;

#define sqr(x) ((x)*(x))
#define mp make_pair
#define pb push_back
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define RE(i, n) FOR(i,1,n)
#define REP(i,n) FOR(i, 0, (int)(n)-1)
#define fst first
#define snd second

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
typedef tuple<int,int,int> iii;

string to_string(string s) {
    return '"' + s + '"';
}
    
string to_string(const char* s) {
    return to_string((string) s);
}
    
string to_string(bool b) {
    return (b ? "true" : "false");
}
    
template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
    
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

void fastIO() {
    cin.sync_with_stdio(false);
    cin.tie(0);
}


int XMOV[4] = {0, 0, 1, -1};
int YMOV[4] = {1, -1, 0, 0};

//#############################
const int MAXN = 1000005;

int main() {
    int n, m, accs = 0, was = 0, p;
    string s;
    map<int, int> state, carry;
    map<string, int> cd;
    cd["AC"] = 1;
    cd["WA"] = -1;
    cin >> n >> m;
    for (int i = 0; i < m; i++){
        cin >> p >> s;
        if(state.count(p) < 1){
            state[p] = cd[s];
            if (cd[s] == 1)
                accs++;
            else if (cd[s] == -1)
                carry[p]++;
        }else if (state[p] == -1 && cd[s] ==  1){
            state[p] = 1;
            was += carry[p];
            accs++;
        }else if (state[p] == -1 && cd[s] == -1) {
            carry[p]++;
        }
    }
    cout << accs << " " << was << endl;
    return 0;
}

Measured memory_bytes: 6144
let rev_iter (f : int -> unit) (a : int array) =
  for i = Array.length a - 1 downto 0 do
    f a.(i)
  done

let counting_sort a b k =
  let c = Array.make (k + 1) 0 in
  Array.iter (fun e -> c.(e) <- c.(e) + 1) a;
  Array.iteri (fun i _ -> if i <> 0 then c.(i) <- c.(i) + c.(i-1)) c;
  rev_iter (fun e -> b.(c.(e)-1) <- e; c.(e) <- c.(e) - 1) a

let () =
  let n = read_int () in
  let a = Array.init n (fun _ -> Scanf.scanf "%d " (fun e -> e)) in
  let b = Array.make n 0 in
  counting_sort a b 10000;
  Array.iteri (fun i e -> if i <> 0 then print_string " "; print_int e) b;
  print_newline ()

Measured memory_bytes: 36248
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
#define fi first
#define se second
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define yn(x, ok, ng) cout << ((x)?(ok):(ng)) << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
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;}
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int const INF = 1001001001;

int N;
int d, cnt;

void dfs(vector<int> table, int v) {
    table.push_back(v);
    if(SZ(table) == d) {
        set<int> st;
        rep(i,d) st.insert(table[i]);
        if(SZ(st) == 3) {
            int cur = 0;
            rep(i,d) cur += table[i] * pow(10, i);
            if(cur <= N) cnt++;
        }
    }
    else {
        dfs(table, 3);
        dfs(table, 5);
        dfs(table, 7);
    }
}


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

cin >> N;

auto dig = [&](int c) {
    int res = 0;
    while (c) {
        c /= 10;
        ++res;
    }
    return res;
};
d = dig(N);

cnt = 0;
rep(i, d) {
    if(i >= 3) cnt += pow(3, i) - 3 * (pow(2, i) - 2) - 3;
}

dfs({}, 3);
dfs({}, 5);
dfs({}, 7);

cout << cnt << endl;
return 0;
}

Measured memory_bytes: 512
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS

tuplify2 (x:y:_) = (x,y)
tuplify2 _ = undefined

--Input functions with ByteString
readInt = fst . fromJust . BS.readInteger
readIntTuple = tuplify2 . map readInt . BS.words
readIntList = map readInt . BS.words

getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntNList n = map readIntList <$> replicateM (fromIntegral n) BS.getLine
getIntMatrix = map readIntList . BS.lines <$> BS.getContents
getIntTuple = readIntTuple <$> BS.getLine
getIntNTuples n = map readIntTuple <$> replicateM (fromIntegral n) BS.getLine
getIntTuples = map readIntTuple . BS.lines <$> BS.getContents

main = do
    [n,a,b] <- getIntList
    let p = n `div` (a+b)
        q = min a $ n `mod` (a+b)
    print $ a*p+q

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

// 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("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &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 (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int main() {

    int d;
    string s;
    Scd(d);
    switch(d){
        case 25 :
            s = "Christmas";
            break;
        case 24 :
            s = "Christmas Eve";
            break;
        case 23 :
            s = "Christmas Eve Eve";
            break;
        case 22 :
            s = "Christmas Eve Eve Eve";
            break;
    }
    cout << s << endl;

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <map>
#include <iomanip>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;
class UF
{
private:
public:
    UF *root;
    int value;
    UF(int n = 0)
    {
        root = this;
        value = n;
    }
    void showInfo(void)
    {
        cout << "rootNode:" << root << ",value:" << value << endl;
    }
};

void connectNode(UF *a, UF *b)
{
    while (b->root != b)
        b = b->root;
    while (a->root != a)
        a = a->root;

    if (a > b)
    {
        a->root = b;
    }
    if (a < b)
    {
        b->root = a;
    }
    return;
}
bool hasSameRoot(UF *a, UF *b)
{

    UF *pa = a;
    UF *pb = b;
    while (a->root != a)
        a = a->root;
    while (b->root != b)
        b = b->root;
    pa->root = a;
    pb->root = b;

    return a == b;
}
int main()
{
    int n, m;
    cin >> n >> m;
    UF u[n];
    rep(i, n)
    {
        u[i].value = i;
        u[i].root = &u[i];
    }
    rep(i, m)
    {
        int x, y, z;
        cin >> x >> y >> z;
        x--;
        y--;
        connectNode(&u[x], &u[y]);
        //   cerr << hasSameRoot(&u[x], &u[y]) << endl;
        //  cerr << x << "," << y << endl;
    }
    map<int, bool> mp;
    int ans = 0;
    rep(i, n)
    {
        UF *p = &u[i];
        while (p->root != p)
            p = p->root;
        if (mp[p->value] == false)
        {
            ans++;
            mp[p->value] = true;
            //  cerr << i << endl;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6528
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <iostream>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <stack>
#include <list>
#include <deque>
using namespace std;
long long n, m, i, j, k, t, ans;
long long Dis[310][310]={0};
long long dis[310][310]={0};
int main(){
	cin>>n;
	for(i=1;i<=n;i++){
		for(j=1;j<=n;j++){
			cin>>Dis[i][j];
			dis[i][j]=Dis[i][j];
		}
	}
	for(i=1;i<=n;i++){
		for(j=1;j<=n;j++){
			for(k=1;k<=n;k++){
				if(Dis[i][j]+Dis[j][k]<Dis[i][k]){
					cout<<"-1";
					return 0;
				}
				if(Dis[i][j]+Dis[j][k]==Dis[i][k]&&i!=j&&j!=k){
					dis[i][k]=2147483647;
				}
			}
		}
	}
	ans=0;
	for(i=1;i<=n;i++){
		for(j=1;j<=n;j++){
				if(dis[i][j]!=2147483647) ans+=dis[i][j];
		}
	}
	ans=ans/2;
	cout<<ans;
	return 0;
}


Measured memory_bytes: 1664
k=int(input())
q=[i for i in range(1,10)]
ans=0
c=0
for i in range(k):
    ans=q.pop(0)
    p=10*ans+int(str(ans)[-1])
    if(p%10!=0):q.append(p-1)
    q.append(p)
    if(p%10!=9):q.append(p+1)
    if(i+len(q)>k):break
    c+=1
for i in range(k-c-1):
    ans=q.pop(0)

print(ans)

Measured memory_bytes: 5876
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		
		// GET INPUT
		int N = sc.nextInt();
		
		
		// GET INPUT END
		
		sc.close();
		
		if(N % 10 == 9 || N >= 90) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

	}

}


Measured memory_bytes: 21844
import math

if __name__ == '__main__':
    N = int(input())
    ans = N % 10
    if ans == 2 or ans == 4 or ans == 5 or ans == 7 or ans == 9:
        print('hon')
    elif ans == 0 or ans == 1 or ans == 6 or ans == 8:
        print('pon')
    else:
        print('bon')


Measured memory_bytes: 9168
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
//#include <utility>
//#include <memory>
//#include <functional>
//#include <deque>
//#include <cctype>
//#include <ctime>
//#include <numeric>
//#include <list>
//#include <iomanip>

//#if __cplusplus >= 201103L
//#include <array>
//#include <tuple>
//#include <initializer_list>
//#include <forward_list>
//
//#define cauto const auto&
//#else

//#endif

using namespace std;


typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

string fi = "First";
string se = "Second";


bool mainmain(){
	string s;
	cin>>s;
	char a = s[0];
	char b = s.back();
	if(a==b){
		return s.size()%2 == 0;
	}
	int cnt = 0;
	rep(i,s.size()){
		if(cnt&1){
			if(s[i] == b) cnt++;
		}
		else{
			if(s[i] == a) cnt++;
		}
	}
	return (s.size()-cnt)%2;
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(20);
    if(mainmain()){
    	cout << fi << endl;
    }
    else{
    	cout << se << endl;
    }
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define inf 1e16
#define MOD 1e9+7
#define gcd __gcd //最大公約数,gcd(x,y)
int lcm(int a, int b){return a/gcd(a, b)*b;} //(int)最小公倍数,lcm(x,y)
ll llcm(ll a, ll b){return a/gcd(a, b)*b;}//(ll)最小公倍数,lcm(x,y)


int main(){
  int A,B,C;
  cin >> A >> B >> C;
  if(((A<C)&&(C<B))||((B<C)&&(C<A))){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    long long int l,r;

    scanf("%lld %lld",&l,&r);

    if (- l + r >= 2018)
    {
       printf("0"); 
    }
    else
    {
        long long int min = 2019 * 2019;
        for (long long int i = l; i < r; i++)
        {
            for (long long int j = i + 1; j <= r; j++)
            {
                if (min > (i * j) % 2019)
                {
                    min = (i * j) % 2019;
                }
            }
        }
        printf("%lld",min);
    }   
}


Measured memory_bytes: 128
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    mod = 10**9 + 7

    h,w,k = map(int, input().split())
    dp = [[0]*w for _ in range(h+1)]
    dp[0][0] = 1

    pattern = []
    if w > 2:
        for i in range(1<<(w-1)):
            for j in range(w-2):
                if ((i>>j) & 1) and ((i>>(j+1)) & 1):
                    break
            else:
                pattern.append(i)
    else:
        print(1)
        exit()
    
    for i in range(h):
        for j in range(w):
            for p in pattern:
                if j == 0:
                    if p & 1:
                        dp[i+1][j+1] += dp[i][j] % mod
                    else:
                        dp[i+1][j] += dp[i][j] % mod
                elif j == w-1:
                    if (p>>(w-2)) & 1:
                        dp[i+1][j-1] += dp[i][j] % mod
                    else:
                        dp[i+1][j] += dp[i][j] % mod
                else:
                    if (p>>(j-1)) & 1:
                        dp[i+1][j-1] += dp[i][j] % mod
                    elif (p>>j) & 1:
                        dp[i+1][j+1] += dp[i][j] % mod
                    else:
                        dp[i+1][j] += dp[i][j] % mod
    print(dp[-1][k-1] % mod)


if __name__ == '__main__':
    main()

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

using namespace std;

#define intt long long
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int N = 25;

int n, m;

char a[N][N];
int d[N][N];
bool used[N][N];

int posx[] = {1, -1, 0, 0};
int posy[] = {0, 0, 1, -1};

bool valid (int x, int y) {
	return (x >= 1 && x <= n && y >= 1 && y <= m);
}

void bfs (int x, int y) {
	queue <pair <int, int>> q;
	q.push({x, y});
	d[x][y] = 0;
	used[x][y] = true;
	while (!q.empty()) {
		pair <int, int> p = q.front();
		int px = p.first;
		int py = p.second;
		q.pop();
		for (int i = 0; i < 4; i ++) {
			int tox = px + posx[i];
			int toy = py + posy[i];
			if (valid(tox, toy) && a[tox][toy] == '.' && !used[tox][toy]) {
				d[tox][toy] = d[px][py] + 1;
				used[tox][toy] = true;
				q.push({tox, toy});
			}
		}
	}
}

void init() {
	for (int i = 1; i <= n; i ++) {
		for (int j = 1; j <= m; j ++) {
			d[i][j] = 0;
			used[i][j] = false;
		}
	}
}

int main() {

	FAST;
	cin >> n >> m;
	for (int i = 1; i <= n; i ++) {
		for (int j = 1; j <= m; j ++) {
			cin >> a[i][j];
		}
	}
	int ans = 0;
	for (int x1 = 1; x1 <= n; x1 ++) {
		for (int y1 = 1; y1 <= m; y1 ++) {
			if (a[x1][y1] == '#') {
				continue;
			}
			init();
			bfs(x1, y1);
			for (int x2 = 1; x2 <= n; x2 ++) {
				for (int y2 = 1; y2 <= m; y2 ++) {
					if ((x1 != x2) || (y1 != y2)) {
						if (a[x2][y2] == '.') {
							ans = max(ans, d[x2][y2]);
						}
					}
				}
			}
		}
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)
#define REV(X, Y, Z) for (ll(X) = (Y); (X) > (Z); (X)--)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMax = 1e12 + 1;
constexpr ll kMod = 1e9 + 7;
constexpr long double kPI = 3.14159265358979323846;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  string T;
  cin >> T;

  if (T.size() == 1) {
    if (T[0] == '?') {
      cout << "D" << endl;
    } else {
      cout << T << endl;
    }
    return 0;
  }

  REP(i, 0, T.size()) {
    switch (T[i]) {
      case 'P':
      case 'D':
        cout << T[i];
        break;
      default: // '?'
        cout << 'D';
        break;
    }
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 3752
#include <iostream>
#include<algorithm>
#include<vector>
#include<deque>
#include <numeric>
#include<cmath>
#include<string>
using namespace std;
#define ll long long

int main(void){
    string s;
    cin >> s;
    int num = 0;
    int cnt1=0,cnt2=0;
    string a = "01";

    for(int i=0;i<s.length();i++){
        if(s[i]!=a[num]){
            cnt1 += 1;
        }
        num = (num+1)%2;
    }
    num = 1;
    for(int i=0;i<s.length();i++){
        if(s[i] != a[num]){
            cnt2 += 1;
        }
        num = (num+1)%2;
    }
    // cout << cnt1 << ' '<< cnt2<<endl;
    int ans;
    if(cnt1 < cnt2){
        ans = cnt1;
    } else{
        ans = cnt2;
    }
    cout << ans<< endl;
    return 0;
}


Measured memory_bytes: 512
#include <map>
#include <set>
#include <ctime>
#include <queue>
#include <stack>
#include <cmath>
#include <vector>
#include <bitset>
#include <cstdio>
#include <cctype>
#include <string>
#include <numeric>
#include <cstring>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std ;
//#define int long long
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define loop(s, v, it) for (s::iterator it = v.begin(); it != v.end(); it++)
#define cont(i, x) for (int i = head[x]; i; i = e[i].nxt)
#define clr(a) memset(a, 0, sizeof(a))
#define ass(a, sum) memset(a, sum, sizeof(a))
#define lowbit(x) (x & -x)
#define all(x) x.begin(), x.end()
#define ub upper_bound
#define lb lower_bound
#define pq priority_queue
#define mp make_pair
#define pb push_back
#define pof pop_front
#define pob pop_back
#define fi first
#define se second
#define iv inline void
#define enter cout << endl
#define siz(x) ((int)x.size())
#define file(x) freopen(x".in", "r", stdin),freopen(x".out", "w", stdout)
typedef long long ll ;
typedef unsigned long long ull ;
typedef pair <int, int> pii ;
typedef vector <int> vi ;
typedef vector <pii> vii ;
typedef queue <int> qi ;
typedef queue <pii> qii ;
typedef set <int> si ;
typedef map <int, int> mii ;
typedef map <string, int> msi ;
const int N = 100010 ;
const int INF = 0x3f3f3f3f ;
const int iinf = 1 << 30 ;
const ll linf = 2e18 ;
const int MOD = 1000000007 ;
const double eps = 1e-7 ;
void douout(double x){ printf("%lf\n", x + 0.0000000001) ; }
template <class T> void print(T a) { cout << a << endl ; exit(0) ; }
template <class T> void chmin(T &a, T b) { if (a > b) a = b ; }
template <class T> void chmax(T &a, T b) { if (a < b) a = b ; }
template <class T> void upd(T &a, T b) { (a += b) %= MOD ; }
template <class T> void mul(T &a, T b) { a = (ll) a * b % MOD ; }

int T, a, b, c, d, x ;

bool check(int mid) {
	int cb = mid / (x + 1) ;
	int ca = mid - cb ;
	if (b - cb > 1ll * (a - ca) * x) return 1 ;
	else return 0 ;
}

signed main(){
//	file("test") ;
	scanf("%d", &T) ;
	while (T--) {
		scanf("%d%d%d%d", &a, &b, &c, &d) ;
		x = (max(a, b) - 1) / (min(a, b) + 1) + 1 ;
		int l = 0, r = a + b, pos = a + b + 1 ;
		// a 尽可能的放前面，二分那个b带a和a带b的边界
		while (l <= r) {
			int mid = (l + r) >> 1 ;
			if (check(mid)) r = mid - 1, pos = mid ;
			else l = mid + 1 ;
		}
		rep(i, c, min(pos, d)) putchar((i % (x + 1)) ? 'A' : 'B') ;
		rep(i, max(c, pos + 1), d) putchar((a + b - i + 1) % (x + 1) ? 'B' : 'A') ;
		enter ;
	}
	return 0 ;
}

/*
写代码时请注意：
	1.ll？数组大小，边界？数据范围？
	2.精度？
	3.特判？
	4.至少做一些
思考提醒：
	1.最大值最小->二分？
	2.可以贪心么？不行dp可以么
	3.可以优化么
	4.维护区间用什么数据结构？
	5.统计方案是用dp？模了么？
	6.逆向思维？
*/




Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main()
{
	bool f;
	string o[2];
	o[0]="No\n";
	o[1]="Yes\n";
	string a,b;
    getline(cin,a);
	getline(cin,b);
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    reverse(b.begin(),b.end());
    if(a<b) f=1;
    else f=0;
    cout<<o[f];
    return 0;
}

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

const int MAX = 1000000;
const int MOD = 1000000007;

signed main() {
 int x;
 cin>>x;
 int a=1;
 while(true){
     if(a*(a+1)/2>=x){
         cout<<a;
         return 0;
     }
     a++;
 }

return 0;
}


Measured memory_bytes: 256
import bisect
N = int(input())
L = list(map(int,input().split()))
L = sorted(L,reverse = False)

cnt = 0
# a の index
for a in range(len(L)):
    # b の index
    for b in range(a+1,len(L)):
        # c が取りうる最大の index
        c_idx = bisect.bisect_left(L,L[a]+L[b]) - 1
        cnt += c_idx - b
print(cnt)

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

int main()
{
    int a, b, c;
    cin >> a >> b >> c;

    if (a == b && b == c)
    {
        cout << 1;
    }
    else if (a == b || b == c || c == a)
    {
        cout << 2;
    }
    else
    {
        cout << 3;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define IOS ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define PI acos(-1)
#define EPS 1e-5
#define sz(v) ((int)(v).size())
#define all(v) v.begin(),v.end()
#define forn(i, n) for(ll i=0;i<(ll)n;i++)
#define fi first
#define se second
 

int main() {
	int n;
	cin >> n;
	ll k; 
	cin >> k;
	vector<int> a(n);
	for(int i = 0; i < n; i++) {
		cin >> a[i];
		a[i]--;
	}

	if(k < n) {
		int now = 0;
		for(int i = 0; i < k; i++){
			now = a[now];
		}
		cout << now+1 << endl;
		return 0;
	}
	
	vector<int> used(n, -1);
	int li = 0;
	used[0] = 0;
	int now = 0;
	for(int i = 1; i < n; i++) {
		li = i;
		now = a[now];
		if(used[now] != -1)
			break;
		used[now] = i;
	}
	
	int diff = li - used[now];
	k -= li;
	k %= diff;
	for(int i = 0; i < k; i++) {
		now = a[now];
	}
	cout << now + 1 << endl;
	return 0;
}



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

int main() {
  long A, B, C, K, sum = 0;
  cin >> A >> B >> C >> K;
  if (K < A) {
    sum = K;
  } else if (K <= A + B) {
    sum = A;
  } else {
    sum = A - (K - A - B);
  }
  cout << sum << endl; 
}


Measured memory_bytes: 3636
#include<stdio.h>
#include<stdlib.h>

#define N 500000
#define INFTY 1000000001

void merge(int[],int,int,int);
void mergeSort(int[],int,int);

int count=0,S[N];

int main(){
  int n;
  int i;

  /*   i n p u t   */
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }


  /*    m e r g e S o r t    */
  mergeSort(S, 0, n);


  /*   o u t p u t   */
  for(i=0;i<n;i++){
    if(i!=0) printf(" ");
    printf("%d",S[i]);
  }
  printf("\n");
  printf("%d\n",count);

  return 0;
}

void merge(int *A, int left, int mid, int right){
  int n1,n2;
  int i,j,k;
  int *L,*R;

  n1=mid-left;
  n2=right-mid;

  L=(int *)malloc(sizeof(int)*(n1+1));
  R=(int *)malloc(sizeof(int)*(n2+1));

  for(i=0;i<n1;i++){
    L[i]=A[left+i];
  }
  for(i=0;i<n2;i++){
    R[i]=A[mid+i];
  }

  L[n1] = INFTY;
  R[n2] = INFTY;

  i=0;
  j=0;

  for(k=left;k<right;k++){
    count++;
    if(L[i]<=R[j]){
      A[k]=L[i];
      i=i+1;
    }
    else{
      A[k]=R[j];
      j=j+1;
    }
  }

  free(L);
  free(R);

  return;
}

void mergeSort(int *A,int left,int right){
  int mid;

  if(left+1<right){
    mid=(left+right)/2;
    mergeSort(A,left,mid);
    mergeSort(A,mid,right);
    merge(A,left,mid,right);
  }

  return;
}

Measured memory_bytes: 4480
use std::io::Read;
use std::collections::HashMap;

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

    let answer = solve(&buf);

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

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

    let s = iterator.next().unwrap();

    if s.len() <= 1 {
        return "YES".to_string();
    }

    let mut counts: HashMap<char, usize> = HashMap::new();
    for c in s.chars() {
        *counts.entry(c).or_insert(0) += 1;
    }

    let limit = (s.len() + 2) / 3;
    for (_, count) in counts {
        if count > limit {
            return "NO".to_string();
        }
    }

    return "YES".to_string();
}


Measured memory_bytes: 4352
o = input()
e = input()

chars = [''] * (len(o) + len(e))
for i in range(len(chars)):
    if i % 2 == 0:
        chars[i] = o[i//2]
    else:
        chars[i] = e[i//2]

ans = ''.join(chars)
print(ans)


Measured memory_bytes: 2940
def main():
    import sys
    input = sys.stdin.readline
    N = int(input())
    W = list(map(int, input().split()))
    left = W[0]
    right = sum(W) - W[0]
    diff = abs(left - right)
    answer = 1
    for i in range(1,N):
        left += W[i]
        right -= W[i]
        tmp = abs(left - right)
        if diff >= tmp:
            diff = tmp
    print(diff)
    
    
main()

Measured memory_bytes: 38340
s = input()
a = []
b = []
n = 0

for i in range(len(s)):
    if i % 2 == 0:
        a.append(s[i])
    else:
        b.append(s[i])
        
for i in range(len(a)):
    if a[i] == "0":
        n += 1
        
for i in range(len(b)):
    if b[i] == "1":
        n += 1
        
m = len(s) - n

if n > m:
    print(m)
else:
    print(n)


Measured memory_bytes: 4092
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <array>
#include <list>
#include <stack>
#include <valarray>

using namespace std;

typedef unsigned uint;
typedef long long Int;
typedef unsigned long long UInt;

const int INF = 1001001001;
const Int INFLL = 1001001001001001001LL;

template<typename T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<typename T> void chmin(T& a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T& a, T b) { if (a < b) a = b; }
int in() { int x; scanf("%d", &x); return x; }
double fin() { double x; scanf("%lf", &x); return x; }
Int lin() { Int x; scanf("%lld", &x); return x; }

int N, K;
Int memo[128][11111];

const Int MO = 1000000007;

Int powmod(Int x, int e) {
  Int v = 1;
  for (; e; e=e>>1, x=(x*x)%MO) {
    if (e&1) v=(v*x)%MO;
  }
  return v;
}

Int solve(int pos, int add) {
  if (pos < 0) return 0;
  if (memo[pos][add] >= 0) {
    return memo[pos][add];
  }
  Int& res = memo[pos][add];
  res = 0;

  for (int u = 0; u <= K; ++u) {
    if (u <= pos + 1) {
      int last = (u + add) % (pos + 1);
      int aa = (u + add) / (pos + 1);
      (res += solve(pos - 1, aa + add)) %= MO;
      (res += powmod(K + 1, pos) * last % MO) %= MO;
    } else {
      int last = (u + add);
      (res += solve(pos - 1, add)) %= MO;
      (res += powmod(K + 1, pos) * last % MO) %= MO;
    }
  }
  return res;
}

int main() {
  N = in();
  K = in();
  for (int i = 0; i < 128; ++i) {
    for (int j = 0; j < 11111; ++j) {
      memo[i][j] = -1;
    }
  }

  printf("%lld\n", solve(N - 1, 0));

  return 0;
}


Measured memory_bytes: 11392
#include<stdio.h>

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


Measured memory_bytes: 2112
#include<bits/stdc++.h>
using namespace std;
#define max1 1000005
#define siz 100000
#define mod 998244353
#define inf 1e18+5
#define ll long long int
#define debug(x) cout<<#x<<" "<<x<<endl
#define jam(x) cout<<"Case #"<<x<<": "
typedef pair<ll,ll> pr;
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  /*#ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif*/
  ll n,k;
  cin>>n>>k;
  vector<ll> a(n);
  for(ll i=0;i<n;i++)
  {
    cin>>a[i];
  }
  vector<ll> dp(n,inf);
  ll k1=k;
  dp[0]=0;
  for(ll i=0;i<n;i++)
  {
    for(ll j=i-1;(j>=0&&k1>0);k1--,j--)
    {
      dp[i]=min(dp[i],dp[j]+abs(a[i]-a[j]));
    }
    k1=k;
  }
  cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i,l,r) for(i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define P pair<ll,ll>
#define F first
#define S second
signed main(){
  ll N,MIN,i,res;cin>>N>>MIN;
  REP(i,4){cin>>res;MIN=min(MIN,res);}
  cout<<5+(N-1)/MIN<<endl;
  return 0;
}

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

using namespace std;

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

const static long long int MOD = 1000000000 + 7;
const static int dy[] = {0, 1, 0, -1};
const static int dx[] = {1, 0, -1, 0};

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

    int n, sum = 0;
    priority_queue<int> l;
    cin >> n;
    rep(i, n) {
        int tmp;
        cin >> tmp;
        l.push(tmp);
        sum += tmp;
    }

    int longest = l.top();
    sum -= longest;
    if (longest >= sum) {
            cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<functional>
#include<fstream>
#include<utility>
#include<bitset>
#include<map>
#include<deque>
#include<cmath>
#include<random>
#include<string.h>
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define rep(N) for (int i = 0; i < N; ++i)
#define Rep(a, b) for (int i = a; i < b; ++i)
#define For(i, N) for (int i = 0; i < N; ++i)
#define all(v) v.begin(), v.end()
#define rev(v) v.rbegin(), v.rend()
#define makei(N) int N; cin >> N;
#define makel(N) ll N; cin >> N;
#define makes(s) string s; cin >> s;
#define maked(d) double d; cin >> d;
#define makev(v, N) vi v(N); rep(N)cin >> v[i];
#define mod 1000000007
#define re return 0

using namespace std;
using ll = long long int;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using msi = map<string, int>;

template<typename T>
void say(T s) {
	cout << s << "\n";
}

template<typename T>
void say(vector<T> s) {
	auto itr = s.begin();
	cout << *(itr++);
	while (itr != s.end()) {
		cout << " " << *(itr++);
	}
	cout << "\n";
}

void saybool(bool b) {
	if (b)say("Yes");
	else say("No");
}

int main() {
	int ans = 0;
	makei(N);
	msi m;
	rep(N) {
		string s;
		cin >> s;
		++m[s];
	}
	makei(M);
	rep(M) {
		string t;
		cin >> t;
		--m[t];
	}
	for (pair<string, int> p : m) {
		ans = max(ans, p.second);
	}
	say(ans);
}

Measured memory_bytes: 256
/////////////////////////   _LeMur_
#include <iostream>
#include <algorithm>
#include <time.h>
#include <stack>
#include <string>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <set>

using namespace std;

const int N = 200005;
const int inf = 1000 * 1000 * 1000;
const int mod = 1000 * 1000 * 1000 + 7;

int n;

int main(){
    cin>>n;
    int a = 0 , b = 0 , l = 0;
    for(int i=1;i<=n;i++){
        int t , x , y;
        cin>>t>>x>>y;
        int s = abs(x - a) + abs(y - b);
        if(s > t - l || s % 2 != (t - l) % 2){
            cout<<"No"<<endl;
            return 0;
        }
        a = x;
        b = y;
        l = t;
    }
    cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pii pair<int,int>
#define F first
#define S second
#define mp make_pair 
using namespace std;
const int N=1005;
queue<int>q;
int n,m,dist[N][N],ans;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
char c[N][N];
inline bool ok(int x,int y){return (x>=0&&y>=0&&x<n&&y<m);}
int main()
{
	for(int i=0;i<N;i++)
		for(int j=0;j<N;j++)
			dist[i][j]=1e9;
	cin>>n>>m;
	for(int i=0;i<n;i++)cin>>c[i];
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			if(c[i][j]=='#')
			{
				q.push(i);
				q.push(j);
				q.push(0);
				dist[i][j]=0;
			}
		}
	}
	while(!q.empty())
	{
		int x=q.front();q.pop();
		int y=q.front();q.pop();
		int z=q.front();q.pop();
		for(int i=0;i<4;i++)
		{
			int x2=x+dx[i];
			int y2=y+dy[i];
			if(!ok(x2,y2)||dist[x2][y2]<=z+1)continue;
			q.push(x2);
			q.push(y2);
			q.push(z+1);
			dist[x2][y2]=z+1;
		}
	}
	for(int i=0;i<n;i++)
		for(int j=0;j<m;j++)
			ans=max(ans,dist[i][j]);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 17424
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SHIFT_LEFT(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a,b;cin>>a>>b;
  if(abs(a) != a && abs(b) == b){
    cout<<"Zero"<<endl;
  }else if(a == 0){
    cout<<"Zero"<<endl;
  }else if(b < 0){
    if((b-a)%2)cout<<"Positive"<<endl;
    else cout<<"Negative"<<endl;
  }else{
    cout<<"Positive"<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N,Q;
  string s;
  cin >> N >> Q >> s;
  vector<int> a(N+1,0);
  FOR(i,1,N){
    a[i] += a[i-1];
    if(s[i-1]=='A' && s[i]=='C') a[i]++;
  }
  REP(q,Q){
    int l,r;
    cin >> l >> r;
    cout << a[r-1]-a[l-1] << '\n';
  }
  
  return 0;
}


Measured memory_bytes: 1488
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define dbg(x) cout<<#x"="<<x<<endl

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, int> ppi;

#define INF 1000000000

char t[9][5] = {
  {'.',',','!','?',' '},
  {'a','b','c',0,0},
  {'d','e','f',0,0},
  {'g','h','i',0,0},
  {'j','k','l',0,0},
  {'m','n','o',0,0},
  {'p','q','r','s',0},
  {'t','u','v',0,0},
  {'w','x','y','z',0}};
int sz[9] = {5,3,3,3,3,3,4,3,4};

int main(){
  int n;
  scanf("%d\n", &n);

  rep(i,n){
    char last=0; int cnt=0;
    while(true){
      char c;
      scanf("%c",&c);
      if(c==last){
	cnt++;
      }
      else if(c=='0' && last!=0){
	printf("%c", t[last-'1'][cnt%sz[last-'1']]);
	last=0;
	cnt=0;
      }
      else if(c=='\n'){
	break;
      }

      if(c!='0') last = c;
      else last = 0;
    }
    cout << endl;
  }
}

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

typedef long long ll;
const ll INF = 1010000000000000017LL;
const ll MOD = 1000000007LL;

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

//#define DEBUG(fmt, ...)
#define DEBUG(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__)

struct P{
   int a;
   int b;
   int c;
   int d;
};

vector<P> conditions;

ll dfs(vector<ll>& nums, int i, int m){
   if( i >= nums.size() ){
      ll p = 0;
      for( int j = 0; j < conditions.size(); j++ ){
          if( (nums[ conditions[j].b ] - nums[ conditions[j].a ]) == conditions[j].c ){
             p+= conditions[j].d;
          }
      }
      return p;
   }

   ll maximum = 0;
   for(int j = (i>0?nums[i-1]:1) ; j <= m; j++ ){
        nums[i] = j;
        maximum = max(maximum, dfs(nums, i+1, m));
   }
   return maximum;
}

int main(){
    std::cout<<std::fixed<<std::setprecision(10);

    ll N, M, Q;
    cin >> N >> M >> Q;

    REP(i,Q){
        P p;
        cin >> p.a >> p.b >> p.c >> p.d;
        p.a--;
        p.b--;
        conditions.push_back(p);
    }

    vector<ll> nums(N,1);

    ll ans = dfs(nums, 0, M);

    cout << ans << endl;

}


Measured memory_bytes: 3636
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <cmath>
#include <climits>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <numeric>
#include <sstream>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())

using namespace std;
typedef long long ll;

int main() {
#ifdef RUN_LOCAL
  ifstream in("../input.txt");
  cin.rdbuf(in.rdbuf());
#endif

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

  int n, m;
  cin >> n >> m;
  vector<int> h(n);
  for (int i = 0; i < n; ++i) {
    cin >> h[i];
  }
  vector<set<int>> loads_set(n);
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    loads_set[a].insert(b);
    loads_set[b].insert(a);
  }

  int cnt_good = 0;
  for (int i = 0; i < n; ++i) {
    bool good = true;
    for (auto x : loads_set[i]) {
      if (h[x] >= h[i]) {
        good = false;
        break;
      }
    }
    if (good) cnt_good++;
  }

  cout << cnt_good << endl;


  return 0;
}


Measured memory_bytes: 15064
import math
N=int(input())
a=list(map(int,input().split()))
a=sorted(a)
alice=0
bob=0
if(N%2==0):
    for i in range(0,N-1,2):
        alice=a[i+1]+alice
        bob=a[i]+bob
else:
    for i in range(1,N-1,2):
        alice=a[i+1]+alice
        bob=a[i]+bob
    alice=alice+a[0]
print(alice-bob)

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

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

  bool f = false;
  int n = 1;
  int d;
  while(n > 0) {
    d = k*n;
    if (d >= a && d <= b) {
      f = true;
    } else if (d >= b) {
      break;
    }
    n++;
  }    

  if(f) {
    cout << "OK" << endl;
  } else {
    cout << "NG" << endl;     
  }
  
  return 0;
}


Measured memory_bytes: 3636
let pow_base x y mult =
  let rec f m n odd b = match n with
      0 -> 1
    | 1 -> mult m odd
    | _ -> let t = if n mod 2 = 1 then mult odd b else odd
           in f (mult m m) (n/2) t (mult b b)
  in f x y 1 x;;

let mpow x y z =
  let mult x1 y1 = ((x1 mod z)*(y1 mod z)) mod z in
  pow_base x y mult;;

let pow x y = pow_base x y ( * );;

let is_composite d n s =
  let l = [2;3;5;7] in
  let rec loop a = match a with
      [] -> false
    | h::t -> if (mpow h d n) = 1 then loop t
              else
                if not (let rec loop2 = function
                    i when i = s -> false
                  | i -> if mpow h ((pow 2 i) * d) n = n-1 then true
                         else loop2 (i+1) in loop2 0) then true
                else
                  loop t
  in loop l;;

let is_prime n = match n with
    2|3|5|7 -> true
    | n ->
       if n=1 || n mod 2 = 0 || n mod 3 = 0 || n mod 5 = 0 || n mod 7 = 0 then
         false
       else begin
           let rec loop d s = match (d, s) with
               (d, s) when d mod 2 = 1 -> (d,s)
             | (d, s) -> loop (d asr 1) (s+1) in
           let (d,s) = loop (n-1) 0 in
           not (is_composite d n s)
         end;;

let () =
  let n = read_int () in
  let rec read ct = function
      0 -> ct
    | i ->
       let m = read_int () in
       read (if is_prime m then ct+1 else ct) (i-1)
  in
  Printf.printf "%d\n" (read 0 n)

Measured memory_bytes: 4388
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
using vs = vector<string>;
using vb = vector<bool>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\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;}
template<class T> inline void prn(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << ' ';}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int r, c, k;
    cin >> r >> c >> k;
    vvl g(r, vl(c, 0));
    int y, x;
    ll v;
    REP(i, k) {
        cin >> y >> x >> v;
        y--;
        x--;
        g[y][x] = v;
    }
    // printvv(g);

    vector<vector<vector<ll>>> dp(r, vvl(c, vl(4, 0)));
    dp[0][0][0] = 0;
    dp[0][0][1] = g[0][0];
    REP(i, r) {
        REP(j, c) {
            REP(k, min(4, j + 2)) {
                // go right
                if (j != 0) {
                    // without picking up
                    chmax(dp[i][j][k], dp[i][j - 1][k]);
                    // go right with picking up
                    if (g[i][j] and k != 3) chmax(dp[i][j][k + 1], dp[i][j - 1][k] + g[i][j]);
                }

                // go down
                if (i != 0) {
                    chmax(dp[i][j][0], dp[i - 1][j][k]);
                    if (g[i][j]) chmax(dp[i][j][1], dp[i - 1][j][k] + g[i][j]);
                }
            }
        }
    }
    // for (auto d : dp) {
    //     printvv(d);
    //     cout << endl;
    // }
    ll ans = 0;
    REP(i, 4) chmax(ans, dp[r - 1][c - 1][i]);
    cout << ans << endl;
}


Measured memory_bytes: 706716
#include<cstdio>
#include<bits/stdc++.h>
typedef long long int ll;
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR_IN(i, a, b) for(int i = (a); i < (b); i++)
#define BETWEEN(x, a, b) ((x) >= (a) && (x) <= (b))
#define BIT(b, i) (((b) >> (i)) & 1)
#define LOG_F 1
#define LOG(...) if(LOG_F) fprintf(stderr, __VA_ARGS__)

using namespace std;

ll pow(int x, int n){
  return n == 0 ? 1 : x * pow(x, n - 1);
}


/*
n
c1 s1 f1
...
cn-1 sn-1 fn-1

n 500
ci 100
si 10^5
fi 100
 */
int n, c[1000], s[1000], f[1000];
int main(){
  cin>>n;
  REP(i,n-1){
    cin>>c[i]>>s[i]>>f[i];
  }

  REP(i,n-1){
    int t=s[i];
    FOR_IN(j,i,n-1){
      if(t <= s[j])
        t = s[j];
      else if(t%f[j]==0);
      else
        t = (t/f[j] + 1) * f[j];

      t += c[j];

      //LOG("t=%d\n", t);
    }
    cout << t << endl;
  }
  cout << 0 << endl;

  return 0;
}


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

int main(){
	int j,i;
	cin >> j >> i;
	if( (j+i) % 3 == 0)cout << "Possible" << endl;
	else if(j % 3 == 0)cout << "Possible" << endl;
	else if(i % 3 == 0)cout << "Possible" << endl;
	else cout << "Impossible" << endl;
	return 0;
		  }


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

vector<unsigned long long> next_p_mod(unsigned N, long long mod) { //next_permutation
  vector<unsigned long long> Next_p(N);
  unsigned long long Next_p_buff = 1;
  for (int i = 0; i < N; i++)
  {
    Next_p_buff *= (i + 1) % mod;
    Next_p.at(i) = Next_p_buff % mod;
  }
  return Next_p;
}
unsigned long long modpow(unsigned long long a, unsigned long long n, unsigned long long mod) {
   unsigned long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
void comb(vector<vector <long long int> > &v,unsigned long long mod) {
  //vector<入れたい型> v(配列の個数(x),vector<入れたい型> (配列の個数,初期値));
  for (int i = 0; i < v.size(); i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (int k = 1; k < v.size(); k++) {
    for (int j = 1; j < k; j++) {
      v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%mod;
    }
  }
}
// a^{-1} mod を計算する
unsigned long long modinv(unsigned long long a, unsigned long long mod) {
    return modpow(a, mod - 2, mod);
}


// modinv
/*void modinv(unsigned long long N, unsigned long long mod,unsigned long long *inv) {
 // unsigned long long inv[N] ;
  for (unsigned long long i = 1; i < N; i++) {
    inv[i] = (i == 1) ? 1 : (mod - (mod / i) * inv[mod % i] % mod);
    assert(inv[i] * i % mod == 1);
  }
  //return 0;
}*/

int main() {
  unsigned long long N, K;
  unsigned long long mod = 1000000000 + 7;
  cin >> N >> K;
  unsigned long long C=0;
  unsigned long long Ci=0;
  vector<vector<long long int> > v(N + 1, vector<long long int>(N + 1, 0));
  comb(v,mod);
  for(int i=1;i<K+1;i++){
    C=v[K-1][i-1]%mod;
    Ci=v[N-K+1][i]%mod;
    cout<<C*Ci%mod<<endl;
  }
  vector<unsigned long long> np = next_p_mod(N, mod);
  //modinv(N, mod,inv);
    
  return 0;
}

Measured memory_bytes: 31616