akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

class DSU {
	std::vector<int> dat;

public:
	DSU(int n) : dat(n, -1) {}

	bool unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y)	return false;
		if (dat[x] > dat[y]) {
			std::swap(x, y);
		}
		dat[x] += dat[y];
		dat[y] = x;
		return true;
	}

	int find(int x) {
		if (dat[x] < 0) {
			return x;
		}
		return dat[x] = find(dat[x]);
	}
};

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

	std::vector<int> xs(n), ys(n);
	std::vector<int> px(n);
	std::vector<int> py(n);
	for (int i = 0; i < n; i++) {
		std::cin >> xs[i] >> ys[i];
		px[i] = i;
		py[i] = i;
	}

	std::sort(px.begin(), px.end(), [&](int i, int j) { return xs[i] < xs[j]; });
	std::sort(py.begin(), py.end(), [&](int i, int j) { return ys[i] < ys[j]; });
	
	std::vector<int> us, vs, ws;
	for (int i = 0; i < n - 1; i++) {
		int u = px[i];
		int v = px[i + 1];
		us.push_back(u);
		vs.push_back(v);
		ws.push_back(xs[v] - xs[u]);
	}
	for (int i = 0; i < n - 1; i++) {
		int u = py[i];
		int v = py[i + 1];
		us.push_back(u);
		vs.push_back(v);
		ws.push_back(ys[v] - ys[u]);
	}

	std::vector<int> ps(us.size());
	for (int i = 0; i < ps.size(); i++) {
		ps[i] = i;
	}
	std::sort(ps.begin(), ps.end(), [&](int i, int j) { return ws[i] < ws[j]; });

	long long ans = 0;

	DSU dsu(n);

	for (int i : ps) {
		int u = us[i];
		int v = vs[i];
		int w = ws[i];
		if (dsu.unite(u, v)) {
			ans += w;
		}
	}
	std::cout << ans << std::endl;
}


Measured memory_bytes: 5344
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

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

using namespace std;

int main() {
  while(1){
    int n,m;
    cin>>n>>m;
    if(!n)break;
    vector<bool> inf(n,false);
    inf[0] = true;
    vector<tuple<int,int,int>> pkt;
    REP(i,m){
      int t,s,d;
      cin>>t>>s>>d;
      --s;--d;
      pkt.emplace_back(t,s,d);
    }
    sort(begin(pkt),end(pkt));
    for (auto p:pkt){
      int t,s,d;
      tie(t,s,d) = p;
      if (inf[s])
        inf[d] = true;
    }
    cout<<count(begin(inf),end(inf),true)<<endl;
  }
  return 0;
}

Measured memory_bytes: 1680
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

N, M = map(int, raw_input().split())

ls = []
for i in range(M):
    P, Y = map(int, raw_input().split())
    ls.append((P, Y, i))

ans = [0] * M

ls.sort()

P_pre = -1
cnt = 1
for P, Y, i in ls:
    if P == P_pre:
        cnt += 1
    else:
        cnt = 1
    S1 = '%06d' % P
    S2 = '%06d' % cnt
    ans[i] = S1 + S2
    P_pre = P

for S in ans:
    print S

Measured memory_bytes: 26864
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a,b,c;
    cin>>a>>b>>c;
    stack<char>sa,sb,sc;
    for(int i=a.size()-1; i>=0; i--)
        sa.push(a[i]);
    for(int i=b.size()-1; i>=0; i--)
        sb.push(b[i]);
    for(int i=c.size()-1; i>=0; i--)
        sc.push(c[i]);
    char r;
    r=sa.top();
    sa.pop();
    while(1)
    {
        if(r=='a')
        {
            if(sa.empty()==true)
            {
                printf("A\n");
                break;
            }
            r=sa.top();
            sa.pop();

        }
        else if(r=='b')
        {
            if(sb.empty()==true)
            {
                printf("B\n");
                break;
            }
            r=sb.top();
            sb.pop();
        }
        else if(r=='c')
        {
            if(sc.empty()==true)
            {
                printf("C\n");
                break;
            }
            r=sc.top();
            sc.pop();
        }
    }
    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
main(){
   
  int a,b,c,x,y,z;
   
  scanf("%d%d%d",&a,&b,&c);
   
  if(a > b){ 
    x = a;
    a = b;
    b = x;
  }
   
  if(b > c){
    y = b;
    b = c;
    c = y;
  }
   
  if(a > b){
    z = a;
    a = b;
    b = z;
  }
   
  printf("%d %d %d\n",a,b,c);
   
  return 0;
}

Measured memory_bytes: 2688
#include <iostream>
#include <vector>
#include <set>

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

typedef long long ll;

using namespace std;

int INF = 1e9;

int main(){
  int n;
  string s;
  cin >> n >> s;
  char b = '!';
  int ans = 0;
  for(auto &c: s){
    if( b == c ) continue;
    b = c;
    ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define debug(x) cerr<<#x<<": "<<x<<endl
#define trav(a,x) for(auto &a:x)
#define all(x) x.begin(),x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    const int N=301;
    vector<double> memo(N*N*N);
    vector<bool> found(N*N*N);
    function<double(int,int,int)> f = [&](int num1, int num2, int num3) {
        if(num1==0 && num2==0 && num3==0) return 0.0;
        int code = N*N*num1+N*num2+num3;
        if(found[code]) return memo[code];
        double back = (1.0*(n-num1-num2-num3))/n;
        double ans = 1+back/(1-back);
        double p = 1.0/(num1+num2+num3);
        if(num1>0) ans+=p*num1*f(num1-1,num2,num3);
        if(num2>0) ans+=p*num2*f(num1+1,num2-1,num3);
        if(num3>0) ans+=p*num3*f(num1,num2+1,num3-1);
        memo[code] = ans;
        found[code] = true;
        return ans;
    };
    vector<int> fr(4);
    rep(i,0,n) {
        int a;
        cin >> a;
        ++fr[a];
    }
    double ans = f(fr[1],fr[2],fr[3]);
    cout<<setprecision(12);
    cout << ans << "\n";
    
}


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

int main() {
	char c;
	cin>>c;

	if(c =='a'){
		cout << "vowel" <<endl;
	}
	else	if(c =='i'){
		cout << "vowel" <<endl;
	}
	else	if(c =='u'){
		cout << "vowel" <<endl;
	}
	else	if(c =='e'){
		cout << "vowel" <<endl;
	}
	else	if(c =='o'){
		cout << "vowel" <<endl;
	}
	else {
		cout << "consonant"<<endl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define mod_ceil(a, b) (a % b) ? a / b + 1 : a / b
using namespace std;

ll U[100010];

ll root(ll x)
{
    while (x != U[x])
    {
        U[x] = U[U[x]];
        x = U[x];
    }
    return x;
}

void Union(ll x, ll y)
{
    ll root_x = root(x);
    ll root_y = root(y);
    U[root_x] = root_y;
}

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

    ll n, m, x, y;
    cin >> n >> m;
    vector<ll> P(n + 1);
    for (ll i = 1; i <= n; i++)
    {
        cin >> P[i];
    }
    // initialize dsu
    for (ll i = 1; i <= n; i++)
    {
        U[i] = i;
    }
    for (ll i = 0; i < m; i++)
    {
        cin >> x >> y;
        Union(x, y);
    }
    ll ans = 0;
    for (ll i = 1; i <= n; i++)
    {
        if (root(i) == root(P[i]))
            ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <complex>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using std::cin;
using std::cout;
using std::endl;
using std::cerr;

using std::string;
using std::to_string;
using std::vector;
using std::set;
using std::queue;
using std::stack;
using std::priority_queue;

using std::min;
using std::max;
using std::sort;
using std::abs;

typedef long long int ll;
const int MOD = 1e9 + 7;

ll pow_mod(ll x, ll n) {
    ll ans = 1;
    ll xx = x;
    for (ll m = n; m > 0; m >>= 1) {
        if (m & 1) {
            ans = ans * xx % MOD;
        }
        xx = xx * xx % MOD;
    }
    return ans;
}

ll inv_mod(ll n) {
    ll ans = pow_mod(n, MOD - 2);
    return ans;
}

vector<ll> fact_memo(200000 + 1, -1);
ll fact_mod(ll n) {
    if (fact_memo[n] > 0) {
        return fact_memo[n];
    }
    if (n == 0) {
        return fact_memo[0] = 1;
    }
    return fact_memo[n] = n * fact_mod(n - 1) % MOD;
}

ll eval(ll x, ll y) {
    ll ans = fact_mod(x + y);
    ans = ans * inv_mod(fact_mod(x)) % MOD;
    ans = ans * inv_mod(fact_mod(y)) % MOD;
    return ans;
}

int main() {
    int h, w, a, b;
    cin >> h >> w >> a >> b;

    ll ans = 0;
    int x = b;
    int y = h - a - 1;
    while (x < w && y >= 0) {
        ll cnt = (eval(x - 0, y - 0) * eval((w - 1) - x, (h - 1) - y)) % MOD;
        ans = (ans + cnt) % MOD;
        x++;
        y--;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4224
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <memory>
#include <string>

#include <algorithm>
#include <complex>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
#endif

#define ITER(c)             __typeof__((c).begin())
#define FOREACH(it, c)      for (ITER(c) it=(c).begin(); it != (c).end(); ++it)
#define RITER(c)            __typeof__((c).rbegin())
#define RFOREACH(it, c)     for (RITER(c) it=(c).rbegin(); it != (c).rend(); ++it)
#define REP(i, n)           REPEAT(i, 0, n)
#define RREP(i, n)          RREPEAT(i, 0, n);
#define REPEAT(i, k, n)     for(int i = (k); i < (k+n); ++i)
#define RREPEAT(i, k, n)    for(int i = (k)+(n)-1; i >= (k); ++i)
#define ALL(c)              (c).begin(), (c).end()
#define LLPOW(p1,p2)        ((ll)pow((double)(p1), (int)p2))
#define ESIZEOF(A)          (sizeof(A)/sizeof((A)[0]))
#define MIN(p1,p2)          (((p1)<(p2))?(p1):(p2))
#define MAX(p1,p2)          (((p1)>(p2))?(p1):(p2))
#define CIN_NO_SYNC         do { cin.tie(0); ios_base::sync_with_stdio(false); } while(0)
#define GETSTR(p)           fgets((p), sizeof(p), stdin)
#define CHOMP(p)            do{ char *_q = (p) + strlen(p)-1; if(*_q == '\n' || *_q == '\r') *_q = 0; } while(0)
#define mp                  make_pair

typedef long long ll;
typedef unsigned long long ull;

#define X real()
#define Y imag()
typedef double D;
typedef complex<D> P;
#define EPS (1e-9)

#ifdef _DEBUG
#define pf printf
#define pr(n) do { cout << #n " = " << (n) << endl; } while(0)
#else
#define pf(...) /* */
#define pr(...) /* */
#endif

inline D inprd(const P &a, const P &b){ return (conj(a) * b).X; }
inline D outprd(const P &a, const P &b){ return (conj(a) * b).Y; }

void doit(vector<P> &v){
    int num = v.size();

    int now = 0;
    REP(i,num){
        if(v[now].Y < v[i].Y || (v[now].Y == v[i].Y && v[now].X > v[i].X)){
            now = i;
        }
    }
    int start = now;
    double tmin = -1e9;
    int count = 0;

    while(1){
        double min = 1e9;
        int minidx = now;
        for(int j = 1; j < num; j++){
            int k = (now+j)%num;
            P vec = v[k] - v[now];
            D arg1 = arg(vec);
            if(tmin < arg1){
                if(min > arg1){
                    min = arg1;
                    minidx = k;
                }
                pf("%d %d : (%+6.1f,%+6.1f) %+.3f\n", now+1, k+1, vec.X, vec.Y, arg1);
            }
        }
        tmin = min;
        now = minidx;
        count++;
        if(start == now) break;
    }
    cout << num-count << endl;
}

int main(){
    while(1){
        int n;
        cin >> n;
        if(n == 0) break;
        vector<P> v;
        string s;
        REP(i,n){
            cin >> s;
            double a,b;
            sscanf(s.c_str(), "%lf,%lf", &a, &b);
            v.push_back(P(a,b));
        }
        doit(v);
        v.clear();
    }
    return 0;
}

Measured memory_bytes: 1368
from string import ascii_lowercase
from sys import stdin, exit
S = stdin.readline().rstrip()
set_s = set(S)

if len(S) < 26:
  for c in ascii_lowercase:
    ans = S+c
    if set_s != set(ans) and S < ans:
      print(ans)
      exit()
else:
  for i in range(len(S)-1, -1, -1):
    for c in ascii_lowercase:
      if S[i] < c and c not in S[:i]:
        print(S[:i]+c)
        exit()
print(-1)

Measured memory_bytes: 3768
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] s = sc.next().toCharArray();
        int bsta = 0;
        int wsta = 0;
        for (int i = 0; i  < s.length; i ++) {
            if(i % 2 == 0){
                if(s[i] == '0') bsta++;
                else wsta++;
            }else{
                if(s[i] == '1') bsta++;
                else wsta++;
            }
        }
        System.out.println(Math.min(bsta, wsta));
        sc.close();

    }

}


Measured memory_bytes: 26472
import java.util.*;

public class Main {
    public static void main(String[] args) {
        try(Scanner scn = new Scanner(System.in)) {
            int price, money;
            while((price = scn.nextInt()) > 0 | (money = scn.nextInt()) > 0) {
                int change  = money - price;
                int jpy1000 = change / 1000;
                int jpy500  = change % 1000 / 500;
                int jpy100  = change % 500 / 100;
                System.out.println(jpy100 + " " + jpy500 + " " + jpy1000);
            }
        }
    }
}

Measured memory_bytes: 34252
use std::io::stdin;

#[allow(dead_code)]
fn input_strs() -> Vec<char> {
    let mut s = String::new();
    match stdin().read_line(&mut s) {
        Ok(_) => s.chars().collect(),
        Err(_) => panic!("err"),
    }
}

#[allow(dead_code)]
fn input_ints() -> Vec<i64> {
    let mut st = String::new();
    match stdin().read_line(&mut st) {
        Ok(_) => {
            st.split_whitespace()
                .map(|s| s.parse().unwrap())
                .collect()
        }
        Err(_) => panic!("err"),
    }
}

fn main() {
    let l = input_ints();
    let n = l[0];
    let t = l[1];
    let mut ts = input_ints();
    let mut te: Vec<i64> = ts.iter().map(|s| s + t).collect();
    ts.remove(0);
    te.pop();

    let mut diff = 0;
    for (s, e) in ts.iter().zip(te.iter()) {
        let d = e - s;
        if d > 0 {
            diff += d;
        }
    }

    println!("{}", n * t - diff);
}

Measured memory_bytes: 10492
#include <iostream>
#include <stdio.h>
using namespace std;
int main(){
  int nr;
  double v,n;
  while(scanf("%lf",&v)!=EOF){
    n=(v*v+98)/98;
    nr=n;
    if(n-nr>0) cout << nr+1 << endl;
    else cout << nr << endl;
  }
  return 0;
}

Measured memory_bytes: 1232
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
using namespace std;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.10f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 1010;

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX_N; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll dx[4] = { 0,0,-1,1 };
ll dy[4] = { -1,1,0,0 };
ll dp[101010];
ll a[1010][1010];

//long longしか使わない
//素数は1より大きい
int main() {
	ll sx, sy, gx, gy;
	cin >> sx >> sy >> gx >> gy;
	ll x = gx - sx;
	ll y = gy - sy;
	string ans;
	rep(i, y) {
		ans.push_back('U');
	}
	rep(i, x) {
		ans.push_back('R');
	}
	rep(i, y) {
		ans.push_back('D');
	}
	rep(i, x) {
		ans.push_back('L');
	}
	ans.push_back('L');
	rep(i, y + 1) {
		ans.push_back('U');
	}
	rep(i, x + 1) {
		ans.push_back('R');
	}
	ans.push_back('D');
	ans.push_back('R');
	rep(i, y + 1) {
		ans.push_back('D');
	}
	rep(i, x + 1) {
		ans.push_back('L');
	}
	ans.push_back('U');
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>

#define int long

const int INF = 1000000009;
const long LINF = 1123456789012345678;

int k, a, b;


signed main(){
	scanf("%ld %ld %ld", &k, &a, &b);
	if(a > k+1 || b-a <= 2){
		printf("%ld\n", k+1);
		return 0;
	}
	if((k-a+1) % 2 == 0){
		printf("%ld\n", a + (b-a) * (k-a+1) / 2);
	}else{
		printf("%ld\n", a + (b-a) * (k-a) / 2 + 1);
	}
	return 0;
}


Measured memory_bytes: 256
N = int(input())
S = input()

E_cnt = S.count('E')
S_cnt = 0
l_change_cnt = 0

min_cnt = 10 ** 6
for i in range(N):
    cnt = 0
    if S[i] == 'E':
        E_cnt -= 1
        cnt = S_cnt + E_cnt
    else:
        cnt = S_cnt + E_cnt
        S_cnt += 1
    min_cnt = min(min_cnt, cnt)

print(min_cnt)



Measured memory_bytes: 3676
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

a, b = map(int, input().split())

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)

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

print(lcm(a, b))


Measured memory_bytes: 61724
#include <algorithm>
#include <iostream>
#include <vector>
#include <iterator>
using namespace std;

int main() {
    int n; cin >> n;
    vector<int> a(n);
    for (int &ai: a) cin >> ai;
    int q; cin >> q;
    while (q--) {
        int b, e, t; cin >> b >> e >> t;
        swap_ranges(a.begin() + b, a.begin() + e, a.begin() + t);
    }
    copy(a.begin(), a.end() - 1, ostream_iterator<int>(cout, " "));
    cout << a.back() << endl;
    return 0;
}


Measured memory_bytes: 3088
using System;
using System.Linq;

class B
{
	static void Main()
	{
		var a = new int[3].Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()).ToArray();
		var b = new int[int.Parse(Console.ReadLine())].Select(_ => int.Parse(Console.ReadLine())).ToHashSet();

		var r3 = new[] { 0, 1, 2 };
		Console.WriteLine(a.Any(ai => ai.All(b.Contains)) || r3.Any(j => a.All(ai => b.Contains(ai[j]))) || r3.All(i => b.Contains(a[i][i])) || r3.All(i => b.Contains(a[i][2 - i])) ? "Yes" : "No");
	}
}


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

s = [list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))

ans = 0
for i in range(1 << n):
    tmp = 0
    for j in range(m):
        on = 0
        for k in range(1, s[j][0]+1):
            if i & (1 << s[j][k]-1):
                on += 1
        if p[j] % 2 == on % 2:
            tmp += 1
    if tmp == m:
        ans += 1

print(ans)


Measured memory_bytes: 9140
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N;
    cin >> N;
    long A[N];
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
        A[i] -= i + 1;
    }
    sort(A, A + N);
    long median = N % 2 == 0 ? (A[N / 2] + A[N / 2 - 1]) / 2 : A[N / 2];
    long sadness = 0;
    for (int i = 0; i < N; i++)
    {
        sadness += abs(A[i] - median);
    }
    cout << sadness << endl;
}


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

double dp[3009][3009], p[3009],ans=0.0;

int main() {
    int n;
    cin>>n;
    dp[0][0]=1.0;
    for(int i=1;i<=n;i++)
        cin>>p[i];
    for(int i=1;i<=n;i++){
        for(int j=0;j<=i;j++){                
            dp[i][j] = dp[i-1][j]*(1-p[i]);
            if(j!=0)
                dp[i][j] += dp[i-1][j-1]*p[i];
            // cout<<dp[i][j]<<" ";
        }
        // cout<<endl;
    }
    for(int i=0;i<=(n/2);i++)
        ans+=dp[n][n-i];
    printf("%.10lf",ans);
}

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

int main(){
  int N,T,A,H[1000],a[1000],min=10000000000,ans;
  cin>>N>>T>>A;
  for(int i=1;i<=N;i++){
    cin>>H[i];
  }
  for(int i=1;i<=N;i++){
    a[i]=T*1000-H[i]*6;
  }
  for(int i=1;i<=N;i++){
    if(min>abs(a[i]-A*1000)){
      min=abs(a[i]-A*1000);
     ans=i;}
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <stdlib.h>
using namespace std;
int main()
{   
	int n,i;
	int a[100005];
	int xixi[100005] = {0};
	int sum = 0;
	scanf("%d", &n);
	a[0] = 0;
	a[n + 1] = 0;
	for(i = 1 ; i <= n ; i++)
	{
		scanf("%d", &a[i]);
	}
	int fuzu = 1;
	for(i = 1 ; i <= n + 1; i++)
	{
		sum = sum + abs(a[i] - a[i - 1]);
	}
	for(i = 1 ; i <= n ; i++)
	{
		printf("%d\n", sum - abs(a[i - 1] - a[i]) - abs(a[i] - a[i + 1]) + abs(a[i - 1] - a[i + 1]));
	}
	return 0;
}

Measured memory_bytes: 1536
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split())) + [0]
sums = sum(A)
subs = 0
tmp = 0
for i in range(N+1):
    A[i] = max(0,A[i]-tmp)
    cmp = A[i] - B[i]
    if cmp > 0:
        subs += cmp
        tmp = 0
    else:
        tmp = -cmp

ans = sums - subs
print(ans)

Measured memory_bytes: 19116
#include<bits/stdc++.h>
#define mo 1000000007
using namespace std;
struct mat
{
	int a[3][3];
	friend mat operator *(mat a,mat b)
	{
		mat c;
		for (int i=0;i<3;i++)
		for (int j=0;j<3;j++)
		{
			c.a[i][j]=0;
			for (int k=0;k<3;k++)
				c.a[i][j]=(c.a[i][j]+(long long)a.a[i][k]*b.a[k][j])%mo;
		}
		return c;
	}
};
mat getmi(mat a,int x)
{
	mat ans=(mat){1,0,0,0,1,0,0,0,1};
	while (x)
	{
		if (x&1) ans=ans*a;
		a=a*a;
		x>>=1;
	}
	return ans;
}
int w[100010];
int main()
{
	int n,m;scanf("%d%d",&n,&m);
	for (int i=1;i<=m;i++) scanf("%d",&w[i]);
	w[++m]=n;
	mat ans=(mat){1,2,1,0,0,0,0,0,0}
		,can=(mat){1,2,1,0,1,1,1,2,2}
		,cant=(mat){1,2,1,0,1,1,0,0,1};
	for (int i=1;i<m;i++) ans=ans*getmi(can,w[i]-(w[i-1]+1))*cant;
	ans=ans*getmi(can,w[m]-(w[m-1]+1));
	cout<<ans.a[0][2]<<endl;
}
	
	
	
	
	
	
	

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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define fi first
#define se second
#define setpre(x) cout << fixed << setprecision(x)

inline void logger(){ cout << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , ";
    logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 100005;

/* ...o(^-^)o... */

long long modinv(long long a) {
    long long b = MOD, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= MOD; 
    if (u < 0) u += MOD;
    return u;
}

long long modpow(long long a, long long n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

map<int, int> fac[10005];
void factorize(int x, int i){
    /*
    int k = 2;
    while(x > 1){
        if(x % k == 0){
            fac[i+1][k]++;
            x /= k;
        }
        else k++;
    }
    */

    for(int k = 2; k*k <= x; k++){
        while(x % k == 0){
            fac[i+1][k]++;
            x /= k;
        }
    }
    if(x != 1) fac[i+1][x]++;

    for(auto& p : fac[i+1]){
        fac[0][p.fi] = max(fac[0][p.fi], p.se);
    }
}

int main(){
    int n; cin >> n;
    vector<lint> a;
    rep(i, n){
        lint x; cin >> x; a.push_back(x);
        factorize(x, i);
    }

    lint lcm = 1;
    for(auto & p : fac[0]){
        lcm *= modpow(p.fi, p.se);
        lcm %= MOD;
    }

    lint ans = 0;
    rep(i, n){
        lint b = (lcm * modinv(a[i])) % MOD;
        ans += b;
        ans %= MOD;
    }
    cout << ans << endl;
}


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

int main() {
	int a[300];
	int n;
	cin>>n;
	n=n*2;
	for(int i=0;i<300;i++){a[i]=0;}
	for(int i=0;i<n;i++){cin>>a[i];}
	sort(a,a+n);
	int ans=0;
	n=n/2;
	for(int i=0;i<n;i++){ans+=a[2*i];}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
N, Q = gets.chomp.split().map(&:to_i)
S = gets.chomp.split('')
AC_ind = Array.new(N+1, 0)

N.times do |i|
  if S[i] == 'A' && S[i+1] == 'C'
    AC_ind[i+1] = AC_ind[i] + 1
  else
    AC_ind[i+1] = AC_ind[i]
  end
end

Q.times do
  s, f = gets.chomp.split().map(&:to_i)
  puts AC_ind[f-1] - AC_ind[s-1]
end


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

int min(int a,int b){return a > b ? b : a;}

int main()
{
    char s[100001];

    scanf("%s",s);

    int len = strlen(s);
    int i,j;
    int red = 0,blue = 0;

    for (i = 0; i < len; i++)
    {
        if(s[i] == '0')red++;
        else blue++;
    }

    printf("%d",min(red,blue) * 2);
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string>
#include<stdlib.h>
#include<math.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<string.h>

using namespace std;

typedef pair<int,int> pii;

#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<=k;i++)



void pr(vector<int> *r,int d){
	rep(i,d+1)printf("%d%c",(*r)[i],i==d?'\n':' ');
}

void f(vector<int> *r,int d,int m,int n){
	(*r)[d]=min(m,n);
	if(n==0)pr(r,d-1);
	if(d < r->size())for(int i=(*r)[d];i-->0;(*r)[d]--)
		f(r,d+1,(*r)[d],n-(*r)[d]);
}

int main(){
	int n;
	for(;;){
		scanf("%d",&n);
		if(n==0)break;
		vector<int> v(n);
		f(&v,0,n,n);
	}
	return 0;
}

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

typedef long long ll;

using namespace std;

#define swap(a, b)    do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while(0)
#define repd(i, a, b) for(typeof(b) i = a; i < (b); ++i)
#define rep(i, n)     repd(i, 0, n)
#define dump(x)       cerr << #x << " = " << (x) << endl
#define debug(x)      cerr << "L" << __LINE__ << ": " << #x << " = " << (x) << endl
#define YesNo(x)      cout << ((x) ? "Yes" : "No") << endl
#define YESNO(x)      cout << ((x) ? "YES" : "NO") << endl
#define absi(x)       ( ((x) >= 0) ? (x) : (-(x)) )

int main(int argc, const char* argv[]) {
	vector<ll> x(4), y(4);
	cin >> x[0] >> y[0] >> x[1] >> y[1];

	x[2] = x[1] - (y[1] - y[0]);
	y[2] = y[1] + (x[1] - x[0]);
	x[3] = x[2] - (y[2] - y[1]);
	y[3] = y[2] + (x[2] - x[1]);

	cout << x[2] << " " << y[2] << " " << x[3] << " " << y[3] << endl;

	return 0;
}


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

int main() {
    int n, m;
    scanf("%d%d",&n,&m);
    int L = -1, R = 1e6;
    REP(i, m) {
        int l, r;
        scanf("%d%d",&l,&r);
        L = max(l, L);
        R = min(r, R);
    }
    int ans = max(0, R - L + 1);
    cout << ans << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define PRINT(x) cout<<(x)<<endl
#define INF 1000000000000 // 10^12
#define MOD 1000000007 // 10^9+7
#define PB push_back
#define MP make_pair



int main() {
    char alpha; cin >> alpha;
    if (alpha >= 'A' && alpha <= 'Z') PRINT("A");
    else PRINT("a");
    return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define repc2(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define inf 2e9
#define linf 9000000000000000000ll
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int n, m, q, l, r;
int sum[501][501];

int main() {
    scanf("%d%d%d", &n, &m, &q);
    rep(i, m) {
        scanf("%d%d", &l, &r);
        sum[l][r]++;
    }
    reps(i, n) {
        reps(j, n) { sum[i][j] += sum[i][j - 1]; }
    }
    reps(i, n) {
        reps(j, n) { sum[i][j] += sum[i - 1][j]; }
    }
    rep(i, q) {
        scanf("%d%d", &l, &r);
        printf("%d\n", sum[r][r] - sum[r][l - 1] - sum[l - 1][r] + sum[l - 1][l - 1]);
    }
    return 0;
}

Measured memory_bytes: 1920
fn solve(wvs: Vec<(usize, usize)>, maxw: usize) -> usize {
    use std::cmp::min;
    let n = wvs.len();

    let mut dp = vec![vec![std::usize::MAX; n + 1]; 100001];

    for i in 0..dp[0].len() {
        dp[0][i] = 0;
    }

    for i in 1..dp.len() {
        for j in 1..dp[0].len() {
            let (w, v) = wvs[j - 1];

            if (v > i || dp[i - v][j - 1] == std::usize::MAX) {
                dp[i][j] = dp[i][j - 1];
            } else {
                dp[i][j] = min(dp[i][j - 1], dp[i - v][j - 1] + w);
            }
        }
    }

    for i in (1..dp.len()).rev() {
        let mut minw = std::usize::MAX;
        for j in 1..dp[0].len() {
            if dp[i][j] < minw {
                minw = dp[i][j];
            }
        }

        if minw <= maxw {
            return i;
        }
    }

    return 0;
}

#[test]
fn solve_test() {
    assert_eq!(solve(vec![(3, 30), (4, 50), (5, 60)], 8), 90);
    assert_eq!(
        solve(vec![(6, 5), (5, 6), (6, 4), (6, 6), (3, 5), (7, 2)], 15),
        17
    );
}

#[allow(unused_macros)]
macro_rules! parse_line {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            iter.next().unwrap().parse::<$t>().unwrap()
        }
    );

    ( $( $t:ty), +) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ( $(iter.next().unwrap().parse::<$t>().unwrap()),* )
        }
    );
}

#[allow(unused_macros)]
macro_rules! read_line {
    () => {{
        let mut line = String::new();
        ::std::io::stdin().read_line(&mut line).unwrap();
        line.pop();
        line
    }};
}

#[allow(unused_macros)]
macro_rules! parse_vec {
    ( $t:ty ) => {{
        let mut line = String::new();
        ::std::io::stdin().read_line(&mut line).unwrap();
        let iter = line.split_whitespace();
        iter.map(|v| v.parse::<$t>().unwrap()).collect::<Vec<_>>()
    }};
}

fn main() {
    let (n, w) = parse_line!(usize, usize);
    let wvs = (0..n)
        .map(|_| parse_line!(usize, usize))
        .collect::<Vec<_>>();
    println!("{}", solve(wvs, w));
}


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

using namespace std;

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
// cout << fixed << setprecision(20);

signed main() {
    int K, X;
    cin >> K >> X;
    for (int i = X - K + 1; i <= X + K - 1; i++) {
        cout << i << " ";
    }
    cout << endl;
}

Measured memory_bytes: 256
while True:
    a, op, b = input().split()
    a = int(a)
    b = int(b)
    if op == "+":
        print(a+b)

    elif op == "-":
        print(a-b)

    elif op == "*":
        print(a*b)
    
    elif op == "/":
        print(a//b)

    else:
        break



Measured memory_bytes: 5592
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

const int MAX = 1e5 + 10;
int N;
int cnt[MAX];

int main(void) {
    memset(cnt, 0, sizeof(cnt));
    scanf("%d", &N);
    REP(i, N) {
        int a;
        scanf("%d", &a);
        cnt[a]++;
    }
    if (*max_element(begin(cnt), end(cnt)) <= 1) {
        printf("%d\n", N);
        return 0;
    }
    priority_queue<PII> pq;
    REP(i, MAX) {
        if (cnt[i]) pq.push(MP(cnt[i], i));
    }
    int ans = N;
    while (!pq.empty()) {
        if (pq.top().first <= 1) {
            break;
        }
        auto First = pq.top(); pq.pop();
        if (pq.empty()) {
            ans = 1;
            break;
        }
        auto Second = pq.top(); pq.pop();
        if (First.first > 2 && Second.first > 2) {
            First.first--;
            Second.first--;
            pq.push(First);
            pq.push(Second);
        } else if (First.first > 2 && Second.first <= 2) {
            First.first--;
            Second.first--;
            pq.push(First);
            pq.push(Second);
        } else if (First.first <= 2 && Second.first <= 2) {
            First.first--;
            Second.first--;
            pq.push(First);
            pq.push(Second);
        }
        ans -= 2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 896
#!/usr/bin/env python3
import sys


def solve(N: int, K: int):
    print(sum(
        N // b * (b - K) + max(0, N % b - max(0, K - 1))
        for b in range(K + 1, N + 1)
    ))


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
from collections import defaultdict
n = int(input())
L_dict, R_dict = defaultdict(int), defaultdict(int)
i = 0
for ipt in input().split():
    L_dict[i + int(ipt)] += 1
    R_dict[i - int(ipt)] += 1
    i += 1
cnt = 0
for Lk, Lv in L_dict.items():
        cnt += R_dict[Lk] * Lv
print(cnt)

Measured memory_bytes: 66228
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  int n;
  cin>>n;
  int tmp=n;
  bool one=true;
  int pos=0;
  for(int i=0;i<tmp && i<s.size();++i){
    if(s[i]!='1'){
      one=false;
      break;
    }
    ++pos;
  }
  if(one && pos>=n) cout<<1<<endl;
  else if(pos+1==s.size()) cout<<s[pos]<<endl;
  else cout<<s[pos]<<endl;
  return 0;
}

Measured memory_bytes: 256
/*Read the problem carefully before starting to work on it*/
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

//ll ncr(ll n,ll r){ll ans=1;r=min(r,n-r);for (int i=1;i<=r;i++){ans*=(n-r+i);ans/=i;}return ans;}

#define pb push_back
#define eb emplace_back
#define mp(x,y) make_pair(x,y)
#define mod 1000000007

double PI=3.1415926535897932384626;

//template<typename T> T power(T x,T y,ll m=mod){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}

#define bip(n) __builtin_popcount(n)//no of ones bit in binary!!
#define bictz(n) __builtin_ctz(n)//no of trailing zeroes in binary!!
#define biclz(n) __builtin_clz(n)//no of leading zeroes in binary!!
#define bffs(n) __builtin_ffs(n)//index of first one bit!!

typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;

typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ld> vd;
typedef vector<ll> vl;

//#define fi1 ifstream fin("input.txt")
//#define of1 ofstream fout("output.txt")
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ost;

#define fi first
#define se second

vector<int>arr(55);
int dp[55][55][105];

int calculateanswer(int i,int j,int k)
{
    if(k<0)
        return (-1e9);
    if(i>j || k==0)
        return 0;
    if(dp[i][j][k]!=-1)
        return dp[i][j][k];
    int ans=0;
    ans=max(ans,arr[i]+calculateanswer(i+1,j,k-1));
    ans=max(ans,arr[j]+calculateanswer(i,j-1,k-1));
    ans=max(ans,calculateanswer(i+1,j,k-2));
    ans=max(ans,calculateanswer(i,j-1,k-2));
    return dp[i][j][k]=ans;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n,k;
	cin>>n>>k;
	memset(dp , -1 , sizeof(dp)) ;
	for(int i=0;i<n;i++)
	{
		cin>>arr[i];
	}
	
	cout<<calculateanswer(0,n-1,k);
    return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);

int main() {
  string S;
  cin >> S;
  int ans = 0;
  for(auto c : S) {
    if(c == '(') ans++;
    else if(c == ')') ans--;
    else {
      cout << ans << endl;
      return 0;
    }
  }
    return 0;
}


Measured memory_bytes: 3216
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
void dout(double d){printf("%.12f\n",d);}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 1e5;
int n, m;
V<pair<bool, int>> v[1000000];
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> m;
  FOR(i, 0, n){
    int a;
    cin >> a;
    v[a-1].pb(mp(true, i));
  }
  FOR(i, 0, m){
    int a;
    cin >> a;
    v[a-1].pb(mp(false, i));
  }
  ll ans = 1;
  int h=0, w=0, c=0;
  FORR(i, n*m-1, 0){
    switch (sz(v[i])){
      case 0:
        ans = ans*(h*w-c)%MOD;
        c++;
        break;
      case 1:
        if(v[i][0].fi){
          ans = ans*w%MOD;
          h++;
        }else{
          ans = ans*h%MOD;
          w++;
        }
        c++;
        break;
      case 2:
        sort(all(v[i]));
        if(v[i][0].fi == v[i][1].fi){
          cout << 0 << endl;
          return 0;
        }
        h++;
        w++;
        c++;
        break;
      default:
        cout << 0 << endl;
        return 0;
    }
  }
  if(n!=h || m!=w){
    cout << 0 << endl;
    return 0;
  }
  cout << ans << endl;
}

Measured memory_bytes: 23808
#include<bits/stdc++.h>
#define ll long long int 
using namespace std;
int main()
{
  ll n;
  cin>>n;
  ll a[n],b[n];
  for(ll i=0;i<n;i++)
  {
    cin>>a[i]>>b[i];
  }
  sort(a,a+n);
  sort(b,b+n);
  if(n%2==0)
  {
    cout<<b[n/2-1]+b[n/2]-a[n/2-1]-a[n/2]+1<<endl;
  }
  else
  {
    cout<<b[n/2]-a[n/2]+1<<endl;
  }
  return 0;
}


Measured memory_bytes: 6728
#include<bits/stdc++.h>
typedef long long i64;
const int N=1e5+7,P=1e9+7;
i64 A,B,v[N];
int n,d1=0,d2=0;
int f1[N],f2[N];
int main(){
	scanf("%d%lld%lld",&n,&A,&B);
	for(int i=1;i<=n;++i)scanf("%lld",v+i);
	int p1=0,p2=0,s1=1,s2=1;
	f1[0]=f2[0]=1;
	for(int i=1;i<n;++i){
		while(v[i+1]-v[p1+1]>=A)s1=(s1+f2[++p1])%P;
		while(v[i+1]-v[p2+1]>=B)s2=(s2+f1[++p2])%P;
		f1[i]=s1;
		f2[i]=s2;
		if(p1!=i){
			for(int j=d1;j<i;++j){
				if(j<=p2)s2=(s2-f1[j])%P;
				f1[j]=0;
			}
			d1=i;
		}else s1=(s1+f2[i])%P;
		if(p2!=i){
			for(int j=d2;j<i;++j){
				if(j<=p1)s1=(s1-f2[j])%P;
				f2[j]=0;
			}
			d2=i;
		}else s2=(s2+f1[i])%P;
	}
	while(p1<n)s1=(s1+f2[++p1])%P;
	while(p2<n)s2=(s2+f1[++p2])%P;
	printf("%d\n",((s1+s2)%P+P)%P);
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

// ここからライブラリ //


class weighted_union_find_tree {
private:
    vector<ll> par;
    vector<ll> ran;
    vector<ll> m_size;
    vector<ll> diff_weght;
public:
    weighted_union_find_tree(int n);
    int find(int x);
    ll weight(int x);
    ll diff(int x, int y);
    bool unite(int x, int y, int w);
    bool same(int x, int y);
    ll size(int x);
};

weighted_union_find_tree::weighted_union_find_tree(int n){
    par.resize(n);
    iota(par.begin(), par.end(), 0);
    ran.resize(n, 0);
    diff_weght.resize(n, 0);
    m_size.resize(n, 1);
};

int weighted_union_find_tree::find(int x) {
    if (par[x] == x) return x;
    else {
        int r = find(par[x]);
        diff_weght[x] += diff_weght[par[x]];
        return par[x] = r;
    }
};

ll weighted_union_find_tree::weight(int x) {
    find(x);
    return diff_weght[x];
}

ll weighted_union_find_tree::diff(int x, int y) {
    return weight(y)-weight(x);
}

bool weighted_union_find_tree::unite(int x, int y, int w) {
    w += weight(x);
    w -= weight(y);
    x = find(x);
    y = find(y);
    if (x == y) return false;
    if (ran[x] < ran[y]) swap(x,y), w *= -1;
    par[y] = x;
    m_size[x] += m_size[y];
    diff_weght[y] = w;
    if (ran[x]==ran[y]) ran[x]++;
    return true;
};

ll weighted_union_find_tree::size(int x) {
    return m_size[find(x)];
}

bool weighted_union_find_tree::same(int x, int y) {
    return (find(x) == find(y));
};
// ここまでライブラリ //

int main(int argc, char const *argv[]) {
    int n, q;
    cin >> n >> q;
    weighted_union_find_tree wuf(n);
    REP(i,q) {
        int c;
        cin >> c;
        if (!c) {
            int x,y,z;
            cin >> x >> y >> z;
            wuf.unite(x,y,z);
        }
        else {
            int x,y;
            cin >> x >> y;
            if (wuf.same(x,y)) {
                cout << wuf.diff(x,y) << endl;
            }
            else cout << "?" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 5988
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define SPEED ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FOR(i, a, b) for (ll i = a; i < b; ++i)
#define RFOR(i, b, a) for (ll i = b; i >= a; --i)
#define ALL(x) x.begin(), x.end()
#define DEBUG(args...) { string _s = #args; replace(ALL(_s), ' ', '\0');\
replace(ALL(_s), ',', ' ');\
stringstream _ss(_s); istream_iterator<string> _it(_ss); _debug(_it, args);}
#define endl "\n"
#define F first
#define S second
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)

using namespace std;
using namespace __gnu_pbds;

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

void _debug(istream_iterator<string>) {}
template<typename T, typename... Args>
void _debug(istream_iterator<string> it, T first, Args... args) {
    cerr << ">> " << *it << " : " << first << endl; _debug(++it, args...);
}
template <typename T1, typename T2>
inline ostream& operator << (ostream& out, const pair<T1, T2>& p) {
    return out << "(" << p.F << ", " << p.S << ")";
}
template<typename T>
inline ostream& operator << (ostream& out, const vector<T>& v) {
    if (v.empty()) return out << "[]";
    else { out << '['; for (auto& e : v) { out << e << ", "; } return out << "\b\b]"; }
}
template<typename T>
inline ostream& operator << (ostream& out, const set<T>& s) {
    if (s.empty()) return out << "{}";
    else { out << '{'; for (auto& e : s) { out << e << ", "; } return out << "\b\b}"; }
}
template<typename T>
inline ostream& operator << (ostream& out, const unordered_set<T>& s) {
    return out << set<T>(ALL(s));
}
template<typename T1, typename T2>
inline ostream& operator << (ostream& out, const map<T1, T2>& m) {
    if (m.empty()) return out << "{}";
    out << '{'; for (auto& p : m) { out << p << ", "; } return out << "\b\b}";
}
template<typename T1, typename T2>
inline ostream& operator << (ostream& out, const unordered_map<T1, T2>& m) {
    return out << map<T1, T2>(ALL(m));
}
template<typename T>
inline ostream& operator << (ostream& out, const ordered_set<T>& s) {
    return out << set<T>(ALL(s));
}

typedef long long ll;
typedef long double ld;
typedef vector<long long> vll;
typedef pair<ll, ll> pll;
typedef vector<pair<ll, ll>> vpll;
typedef unordered_map<ll, ll> STll;
/************************************** MAIN PROGRAM ********************************************/

int main()
{
    //freopen("input.txt", "r", stdin);
    SPEED
    int a, b;
    cin >> a >> b;
    int ans = max(a - 2 * b, 0);
    cout << ans;
}
/************************************** END OF PROGRAM ******************************************/
/** Stuff you should look for:
 * int overflow, array bounds, over-counting, graph is not a tree/connected
 * special cases (n=1?), set/unordered_set TLE, multi-set/set error
 * do something instead of nothing and stay organized
 */


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char a[100005];
int x=0,y=0,ans=0;
int main()
{
    cin>>a;
    for(int i=0;i<sizeof(a);i++)
    	if(x==y)
		{
			x++;
			if(a[i]=='p') ans--;
		}
     	else
		{
			y++;
			if(a[i]=='g') ans++;
		}
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 384