akhauriyash/Code-Regression huggingface dataset:
<?php
list($n) = ints();
for ($i = 0; $i < $n; ++$i) list($a[]) = ints();
$ends = [$a[0]];
for ($i = 1; $i < $n; ++$i) {
    $l = count($ends);
    $ok = $l;
    $ng = -1;
    while (abs($ok - $ng) > 1) {
        $mid = intdiv($ok + $ng, 2);
        if ($ends[$mid] < $a[$i]) $ok = $mid;
        else $ng = $mid;
    }
    if ($ok === $l) $ends[] = $a[$i];
    else $ends[$ok] = $a[$i];
}
echo count($ends);
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Measured memory_bytes: 24012
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repp(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define rrep(i, n, m) for (int i = n; i >= m; i--)
#define p(a,b) printf(a,b);
#define c(s) cout<< (s) << endl;
#define yes cout<<"Yes"<<endl;
#define no cout<<"No"<<endl;
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
#define cyn(c) cout<<(c?"Yes":"No")<<endl;
#define cYN(c) cout<<(c?"YES":"NO")<<endl;
#define pyn(o,c) printf(o,c?"Yes":"No");
#define pYN(o,c) printf(o,c?"YES":"NO");
typedef long long LL;
template <class T>
bool contain(const std::string &s, const T &v)
{
    return s.find(v) != std::string::npos;
}

int main()
{
    string s; cin>>s;
    if(s.size()==2){
        c(s);
    }else{
        reverse(s.begin(),s.end());
        c(s);
    }
}


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

typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define MP make_pair
#define MT make_tuple
#define F first
#define S second
#define PB push_back
#define dump(x)  cout << #x << " = " << (x) << endl;	//debug
#define SZ(x) ((ll)(x).size())
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (ll i = (a); i >= (b); i--)
#define ps(s) cout << #s << endl;
#define pv(v) cout << (v) << endl;
#define pvd(v) cout << setprecision(16) << (v) << endl;
#define ALL(a)  (a).begin(),(a).end()
#define RANGE(a, start_index, num)  (a).begin()+(start_index),(a).begin()+(num)


int main() {
	int n, q;
	cin >> n >> q;
	string s;
	cin >> s;
	vector<int> memo(n + 1);
	FOR(i, 2, n) {
		memo[i] = memo[i - 1];
		if (s[i - 2] == 'A'&&s[i - 1] == 'C') {
			memo[i]++;
		}
	}
	FOR(i, 1, q) {
		int l, r;
		cin >> l >> r;
		pv(memo[r] - memo[l]);
	}
	return 0;
}

Measured memory_bytes: 3816
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()

int main() {
  int n;
  cin>>n;
  vector<int> s(n);
  rep(i,n) cin>>s[i];
  int sum=0;
  rep(i,n) sum+=s[i];
  int m=101;
  rep(i,n){
    if(s[i]<m&&s[i]%10!=0) m=s[i];
  }
    if(sum%10!=0) cout<<sum<<endl;
    if(sum%10==0){
rep(i,n){
  if(s[i]%10!=0){
    cout<<sum-m<<endl;
    return 0;
  }
}
   cout<<0<<endl;
    }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>

typedef std::vector<int> vi;
typedef std::vector<long> vl;

struct Node
{
  vi to;
  vl dist;
  bool checked;
};

int main()
{
  int N;
  std::cin >> N;
  std::vector<Node> tree(N);
  for (int i = 0; i < N-1; i++)
  {
    int tmp1, tmp2;
    long tmp3;
    std::cin >> tmp1 >> tmp2 >> tmp3;
    tree.at(tmp1-1).to.push_back(tmp2-1);
    tree.at(tmp2-1).to.push_back(tmp1-1);
    tree.at(tmp1-1).dist.push_back(tmp3);
    tree.at(tmp2-1).dist.push_back(tmp3);
  }
  vl dist(N);
  std::queue<int> que;
  for (int i = 0; i < N; i++)
  {
    dist.at(i) = -1;
    tree.at(i).checked = false;
  }
  dist.at(0) = 0;
  que.push(0);
  while (!que.empty())
  {
    int now = que.front();
    que.pop();
    if (tree.at(now).checked) continue;
    // std::cout << "now = " << now << std::endl;
    for (int i = 0; i < tree.at(now).to.size(); i++)
    {
      // std::cout << "i = " << i << ", tree.at(now).to.at(i) = " << tree.at(now).to.at(i) << std::endl;
      if (dist.at(tree.at(now).to.at(i)) != -1) continue;
      // std::cout << "    " << i << ", tree.at(now).to.at(i) = " << tree.at(now).to.at(i) << std::endl;
      dist.at(tree.at(now).to.at(i)) = dist.at(now) + tree.at(now).dist.at(i);
      que.push(tree.at(now).to.at(i));
    }
    tree.at(now).checked = true;
  }
  for (int i = 0; i < N; i++) std::cout << dist.at(i)%2 << std::endl;
}


Measured memory_bytes: 13568
#include <bits/stdc++.h>
using namespace std;
int main () {
    int N;
    cin >> N;
    int list[N];
    for(int i = 0; i<N;i++) {
        cin >> list[i];
    }
    sort(list, list + N, greater<int>());

    int a = 0;
    int b = 0;
    for(int i = 0; i<N; i++) {
        if(i == 0 || i % 2 == 0) { 
            a += list[i];
        } else {
            b += list[i];
        }
    }
    cout << a - b << endl;
    return 0;
}

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

class UnionFind:
    def __init__(self, n):
        '木の初期化をする'
        self.p = [-1] * n
        self.rank = [1]*n
    def find(self, x):
        'x の親を返す'
        if self.p[x] == -1:
            return x
        else:
            self.p[x] = self.find(self.p[x])
            return self.p[x]

    def unite(self, x, y):
        'rankの低い親を高い方のの親にする'
        if not self.same(x,y):
            x = self.find(x)
            y = self.find(y)
            if self.rank[x] > self.rank[y]:
                x,y = y,x
            elif self.rank[x] == self.rank[y]:
                self.rank[y] += 1
            self.p[x] = y
            return True
        else:
            return False

    def same(self, x, y):
        return self.find(x) == self.find(y)

n,m = map(int,input().split())
uf = UnionFind(n+m)
for i in range(n):
    kl = list(map(int,input().split()))
    k,L = kl[0],kl[1:]
    for l in L:
        uf.unite(i,l+n-1)
p = uf.find(0)
ans = 'YES'
for i in range(1,n):
    if p != uf.find(i):
        ans = 'NO'
print(ans)


Measured memory_bytes: 67416
#include<stdio.h>
	int str_count(const char s[]){
		int count=0;
		while(s[count])
		count++;
		return count;
	}
	
	int main(void){
		char str[20];
		int i;
		scanf("%s",str);
		for(i=str_count(str)-1;i>=0;i--){
			printf("%c",str[i]);
		}
		printf("\n");
		return 0;
}

Measured memory_bytes: 524
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

typedef long long ll;

#define MOD 1000000007

class Comb{
public:
  ll *fac,*finv,*inv;
  Comb(){
    fac = new ll[1000001];
    finv = new ll[1000001];
    inv = new ll[1000001];
    fac[0] = 1;
    for(int i=1;i<1000001;i++){
      fac[i] = i*fac[i-1];
      fac[i] %= MOD;
    }
    inv[1] = 1;
    for(int i=2;i<1000001;i++){
      inv[i] = MOD-inv[MOD%i]*(MOD/i)%MOD;
    }
    finv[0] = 1;
    for(int i=1;i<1000001;i++){
      finv[i] = inv[i]*finv[i-1];
      finv[i] %= MOD;
    }
  }
  ll calc(ll n,ll k){
    ll c = fac[n];
    c *= finv[k];c %= MOD;
    c *= finv[n-k];c %= MOD;
    return c;
  }
};

int main(){
  int n;
  cin >> n;
  ll a[n];
  for(int i=0;i<n;i++) cin >> a[i];
  unordered_map<ll,ll> table;
  for(int i=0;i<n;i++){
    table[i-a[i]]++;
  }
  ll ans = 0;
  for(int i=0;i<n;i++){
    ans += table[i+a[i]];
    table[i-a[i]]--;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 20096
#include <iostream>
using namespace std;
int main(void){
    long long L0=2,L1 = 1,Ln=0;
    int n;
    cin >> n;
    if(n <= 1){
        if(n == 0) cout<<2;
        else cout<<1;
        return 0;
    }
    else{
        for(int i=2;i<=n;i++){
            Ln = L0+L1;
            L0 = L1;
            L1 = Ln;
        }
    }
    cout<<Ln;
    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(x) x.begin(),x.end()
#define REVERSE(x) reverse(x.begin(),x.end())
#define SORT(x,n) sort(x,x)
#define P pair<int,int>
typedef long long LL;
const int INF=1000000007;
using namespace std;
int gcd(int a,int b){
  if(a%b==0){return b;}
  else{return gcd(b,a%b);}
}
int main(){
int r;
cin>>r;
int ans=3*r*r;
cout<<ans;
}

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

#define MAX_N 10001
#define INF (1<<28);

typedef struct Node * NodePointer;

typedef struct Node {
	NodePointer next;
	int v, c;
} Node;

int N;
NodePointer E[MAX_N] = {};
NodePointer tail[MAX_N] = {};
int C[MAX_N];

NodePointer makeNode(int v, int c) {
	NodePointer node = (NodePointer)malloc(sizeof(Node));
	node->next = NULL;
	node->v = v;
	node->c = c;
	return node;
};
void init() {
	for (int ix = 0; ix < MAX_N; ++ix) {
		E[ix] = makeNode(-1,-1);
		tail[ix] = E[ix];
	}
};
void addEdge(int u, int v, int c) {
	tail[u]->next = makeNode(v,c);
	tail[u] = tail[u]->next;
};
int sssp() {
	int mini, id, jx;
	int V[MAX_N];
	NodePointer np;
	for (int ix = 0; ix < N; ++ix) {
		C[ix] = INF;
		V[ix] = 0;
	}
	C[0] = 0;
	while(1) {
		mini = INF;
		id = -1;
		for (int ix = 0; ix < N; ++ix) {
			if( V[ix]) continue;
			if( C[ix] < mini ) {
				mini = C[ix];
				id = ix;
			}
		}
		if(id == -1) break;
		V[id] = 1;
		for ( np = E[id]->next ; np != NULL ; np = np->next ) {
			if (V[np->v]) continue;
			jx = C[id] + np->c;
			if ( jx < C[np->v] ) C[np->v] = jx;
		}
	}
}

int main() {
	int id, v, c, kx;
	int tmp;
	init();
	scanf("%d\n", &N);
	for(int ix = 0; ix < N; ++ix) {
		scanf("%d %d", &id, &kx);
		while(kx--) {
			scanf("%d %d", &v, &c);
			addEdge(id,v,c);
		}
	}
	sssp();
	for (int ix = 0; ix < N; ++ix)
		printf("%d %d\n", ix, C[ix]);
	return 0;
}


Measured memory_bytes: 17812
#include<stdio.h>
#include<string.h>

char s[100005];
int main(){
	int len,i;
	int a,b,c,t;
	while(scanf("%s",s)!=EOF){
		a=0;b=0;c=0;
		len=strlen(s);
		for(i=0;i<len;i++){
			if(s[i]=='a')
				a++;
			else if(s[i]=='b')
				b++;
			else
				c++;
		}
		if(a<b){
			t=a;a=b;b=t;}
		if(a<c){
			t=a;a=c;c=t;}
		if(b<c){
			t=b;b=c;c=t;}
		
		if(a-c>=2)
			printf("NO\n");
		else
			printf("YES\n");
	}
	return 0;
}

Measured memory_bytes: 256
use std::io;

fn procon_read<T: std::str::FromStr>() ->  Vec<T> {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let iter = buf.split_whitespace();
	let mut v: Vec<T> = Vec::new();
	for i in iter {
		v.push(i.parse().ok().unwrap());
	}
	v
}

fn main() {
	let v:Vec<u64> = procon_read();
	let n = v[0];
	let mut L0:u64 = 2;
	let mut L1:u64 = 1;
	let mut ret:u64 = 1;
	for i in 0..(n-1) {
		ret = L1 +L0;
		L0 = L1;
		L1 = ret;
	}
	println!("{}", ret);
}

Measured memory_bytes: 4352
fn read_stdin() -> String {
    use std::io::Read;
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();
    input
}

fn scan<'a, I: Iterator<Item = &'a str>, T: std::str::FromStr>(tokens: &mut I) -> T {
    tokens.next().unwrap().parse().ok().unwrap()
}

fn main() {
    let input = read_stdin();
    let tokens = &mut input.split_whitespace();
    let n: usize = scan(tokens);
    let m: usize = scan(tokens);
    let mut nexts = vec![Vec::new(); n];
    for _ in 0..m {
        let a: usize = scan(tokens);
        let b: usize = scan(tokens);
        nexts[a - 1].push(b - 1);
    }
    let mut p: Vec<f64> = vec![0.0; n];
    p[0] = 1.0;
    for i in 0..n {
        let x = p[i] / nexts[i].len() as f64;
        for &j in &nexts[i] {
            p[j] += x;
        }
    }
    let mut e: Vec<f64> = vec![0.0; n];
    let mut max: f64 = 0.0;
    for i in (0..n - 1).rev() {
        let k = nexts[i].len() as f64;
        let mut sum = 0.0;
        for &j in &nexts[i] {
            sum += e[j];
        }
        e[i] = 1.0 + sum / k;
        if nexts[i].len() > 1 {
            for &j in &nexts[i] {
                max = max.max(p[i] * (sum / k - (sum - e[j]) / (k - 1.0)));
            }
        }
    }
    println!("{}", e[0] - max);
}


Measured memory_bytes: 8444
function f()
    n = parse(Int, chomp(readline()))
    v = map(x -> parse(Int, x), split(chomp(readline()), " "))
    c = map(x -> parse(Int, x), split(chomp(readline()), " "))

    id = v .> c
    ret = sum(v[id]) - sum(c[id])
    print(ret)
end
f()

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

using namespace std;

typedef vector<int> Node;
typedef vector<Node> Graph;

typedef unsigned long long ULL;

inline int trail0(ULL s) { return (s ? __builtin_ctzll(s) : 64); }

int BronKerbosch(const vector<ULL>& g, ULL cur, ULL allowed, ULL forbidden, const vector<int>& weights) {
    if (allowed == 0 && forbidden == 0) {
        int res = 0;
        for (int u = trail0(cur); u < g.size(); u += trail0(cur >> (u + 1)) + 1)
            res += weights[u];
        return res;
    }
    if (allowed == 0) return -1;
    int res = -1;
    int pivot = trail0(allowed | forbidden);
    ULL z = allowed & ~g[pivot];
    for (int u = trail0(z); u < g.size(); u += trail0(z >> (u + 1)) + 1) {
        res = max(res, BronKerbosch(g, cur | (1ULL << u), allowed & g[u], forbidden & g[u], weights));
        allowed ^= 1ULL << u;
        forbidden |= 1ULL << u;
    }
    return res;
}

int maximum_clique(const Graph& G, const vector<int>& weights) {
    int n = G.size();
    assert(n < 64);
    vector<ULL> g(n, 0);
    REP(i, n) for(int j : G[i]) g[i] |= (1ULL << j);
    return BronKerbosch(g, 0, (1ULL << n) - 1, 0, weights);
}

int maximum_independet_set(const Graph& G, const vector<int>& weights) {
    int n = G.size();
    assert(n < 64);
    vector<ULL> g(n);
    REP(i, n) REP(j, n) if(i != j) g[i] |= (1ULL << j);
    REP(i, G.size()) for(int j : G[i]) g[i] ^= (1ULL << j);
    return BronKerbosch(g, 0, (1ULL << n) - 1, 0, weights);
}
int main(){
    int N;
    while(cin >> N && N > 0) {
        vector<string> name(N);
        vector<int> weight(N);
        vector<string> next[50];
        REP(i, N) {
            cin >> name[i] >> weight[i];
            int M;
            cin >> M;
            while(M--) {
                string s;
                cin >> s;
                next[i].push_back(s);
            }
        }
        map<string, int> idx;
        REP(i, N) idx[name[i]] = i;

        Graph G(N - 1);
        vector<int> nweight(N - 1);
        for(int i = 1; i < N; i++) {
            for(string s : next[i]) {
                G[i - 1].push_back(idx[s] - 1);
            }
            nweight[i - 1] = weight[i];
        }

        for(string s : next[0]) {
            nweight[idx[s] - 1] = 0;
        }

        cout << maximum_independet_set(G, nweight) + weight[0] << endl;
    }
    return 0;
}

Measured memory_bytes: 1380
import heapq
n,m=map(int,input().split())
jobs = [[] for _ in range(10**5+1)]
for i in range(n):
    a,b =map(int,input().split())
    jobs[a].append(b)

heap = []
ans = 0
for i in range(m+1):
    if jobs[i]:
        for x in jobs[i]:
            heapq.heappush(heap,-x)
    if heap:
        ans += -heapq.heappop(heap)


print(ans)

Measured memory_bytes: 18492
#include<queue>
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}
struct Dinic {
    typedef int Flow;
    static const Flow INF = 1<<29;
    struct Edge {
	int src, dst;
	Flow cap;
	int rev;
    };
    typedef vector<vector<Edge> > Graph;
    Graph G;
    vector<int>len, iter;
    Dinic(int N) : G(N) {}
    void add_edge(int u, int v, Flow c) {
	G[u].push_back((Edge){ u, v, c, (int)G[v].size() });
	G[v].push_back((Edge){ v, u, c, (int)G[u].size()-1 });
    }
    Flow dfs(int v, int s, Flow c) {
	if (v == s || c == 0) return c;
	Flow ret = 0;
	for (int &i=iter[v]; i<(int)G[v].size(); i++) {
	    Edge &e = G[v][i], &re = G[e.dst][e.rev];
	    if (re.cap > 0 && len[v] > len[e.dst]) {
		Flow f = dfs(e.dst, s, min(c-ret, re.cap));
		ret += f;
		e.cap += f; re.cap -= f;
		if (ret == c) break;
	    }
	}
	return ret;
    }
    void bfs(int s) {
	len.assign(G.size(), -1);
	queue<int>qu;
	qu.push(s);
	len[s] = 0;
	for (;!qu.empty();) {
	    int v = qu.front(); qu.pop();
	    for (int i=0; i<(int)G[v].size(); i++) {
		const Edge &e = G[v][i];
		if (e.cap > 0 && len[e.dst] == -1) {
		    len[e.dst] = len[v] + 1;
		    qu.push(e.dst);
		}
	    }
	}
    }
    Flow _flow;
    Flow flow(int source, int sink, Flow limit=-1) {
	if (limit == -1) limit = INF;
	Flow ret = 0;
	while (true) {
	    bfs(source);
	    if (len[sink] == -1 || limit == 0) return _flow = ret;
	    iter.assign(G.size(), 0);
	    Flow tmp = dfs(sink, source, limit);
	    ret += tmp;
	    limit -= tmp;
	}
    }
};
const Dinic::Flow Dinic::INF;

int H, W;
char F[111][111];

void MAIN() {
    scanf("%d%d", &H, &W);
    REP (i, H) scanf("%s", F[i]);

    int SRC = H + W, SNK = SRC + 1;
    Dinic D(SNK+1);

    REP (i, H) REP (j, W) {
	if (F[i][j] != '.') {
	    D.add_edge(i, H+j, 1);
	}
	if (F[i][j] == 'S') {
	    D.add_edge(SRC, i, 1000);
	    D.add_edge(SRC, H+j, 1000);
	}
	if (F[i][j] == 'T') {
	    D.add_edge(i, SNK, 1000);
	    D.add_edge(H+j, SNK, 1000);
	}
    }

    int f = D.flow(SRC, SNK);
    if (f >= 1000) {
	puts("-1");
    } else {
	printf("%d\n", f);
    }
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 640
#include <cstdio>
#include <iostream>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;


int main(void) {
  int n;
  scanf("%d", &n);
  int res = 0;
  REP(i, n) {
    int lb, ub;
    scanf("%d%d", &lb, &ub);
    res += ub - lb + 1;
  }
  printf("%d\n", res);
  return 0;
}


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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


template<typename T>
struct UnionFind {
    i64 sz;

    vector<T> parent;
    vector<i64> rank;

    UnionFind(i64 n) : sz(n) {
        parent.assign(n, 0);
        REP(i, n) {
            parent[i] = i;
        }
        rank.assign(n, 1);
    }

    T find(T t) {
        if (parent[t] == t) return t;
        return parent[t] = find(parent[t]);
    }

    bool unite(T t1, T t2) {
        t1 = find(t1);
        t2 = find(t2);
        if (t1 == t2) return false;

        if (rank[t1] < rank[t2]) swap(t1, t2);
        parent[t2] = t1;
        rank[t1] += rank[t2];
        return true;
    }

    bool same(T t1, T t2) {
        return find(t1) == find(t2);
    }
};


#define MAX_N 50
#define MAX_M 1225
i64 N, M;
typedef pair<i64, i64> P;
P E[MAX_M];

int main() {
    cin >> N >> M;

    i64 u, v;
    REP(i, M) {
        cin >> u >> v;
        u--; v--;
        E[i] = mp(u, v);
    }

    i64 cnt = 0;
    REP(m, M) {
        UnionFind<i64> uf(N);
        REP(i, M) {
            if (i == m) continue;
            uf.unite(E[i].F, E[i].S);
        }
        if (uf.rank[uf.find(0)] < N) cnt++;
    }
    cout << cnt << endl;

    return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> vec(N);
  for(int i=0; i<N; ++i){
    cin >> vec.at(i);
  }
  
  int ans=0, shou=N+1;
  for(int i=0; i<N; ++i){
    if(vec.at(i) < shou){
      ++ans;
      shou = min(vec.at(i),shou);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
N, M, X, Y = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

if min(y) > max(x):
    # max(x) + 1 <= z <= min(y)
    if (Y >= max(x) + 1) and (X < min(y)):
        print("No War")
    else:
        print("War")

else:
    print("War")


Measured memory_bytes: 2940
n, m = map(int, input().split())
a = []
b = []
for _ in range(n):
  a.append(input())
for _ in range(m):
  b.append(input())

def detect(i, j):
  flag = True
  for k in range(len(b)):
    for l in range(len(b)):
      if i+k >= n or j+l >= n or a[i+k][j+l] != b[k][l]:
        flag = False
        break
    if not flag:
      break
  return flag
  
ans = "No"
for i in range(len(a)):
  for j in range(len(a)):
    if detect(i, j):
      ans = "Yes"
      break
  if ans == "Yes":
    break
print(ans)

Measured memory_bytes: 71304
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    string s;
    int num;
    priority_queue<int> pq;
    while(cin>>s){
        if(s=="insert"){
            cin>>num;
            pq.push(num);
        }
        else if(s=="extract"){
            cout<<pq.top()<<'\n';
            pq.pop();
        }
        else{
            while(!pq.empty())
                pq.pop();
        }
    }
    return 0;
}



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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define PI 3.14159265358979
#define MOD 1000000007 // = 10^9 + 7

using namespace std;
using ll = long long;


void solve()
{
	int n, ans= 0;
	cin >> n;
	vector<int> a(n), b(n), c(n);
	for(int i = 0; i < n; ++i) cin >> a[i];
	for(int i = 0; i < n; ++i)
	{
		cin >> b[i];
		ans += b[i];
	}
	for(int i = 0; i < n; ++i) cin >> c[i];

	for(int i = 1; i < n; ++i)
	{
		if (a[i - 1] + 1 == a[i])
		{
			ans += c[a[i - 1] - 1];
		}
	}
	cout << ans;
}

int main()
{
	fastio;
	solve();

	return 0;
}

Measured memory_bytes: 3620
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		String s = sc.next();
		String [] str = s.split("");
		int[] n = new int[s.length()];
		for (int i = 0; i < s.length(); i++) {
			n[i] = Integer.parseInt(str[i]);
		}
		int cnt = 0;
		for (int i = 0; i < s.length() - 1; i++) {
			if (n[i] == n[i+1]) {
				cnt++;
				if(n[i+1] == 0){
					n[i+1] = 1;
				}else{
					n[i+1] = 0;
				}
			}
		}
		System.out.println(cnt);
	}
}

Measured memory_bytes: 32836
#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)a
#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;
    cout << a * b;
}
/************************************** END OF PROGRAM ******************************************/
/** Stuff you should look for:
 * int overflow, array bounds, over-counting
 * special cases (n=1?), set/unordered_set TLE, multi-set/set error
 * do something instead of nothing and stay organized
 */


Measured memory_bytes: 3660
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <cstring>
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <numeric>
#include <float.h>
#include <math.h>
#include <sstream>
using namespace std;
// repマクロの定義
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
// allマクロの定義
#define all(v) v.begin(), v.end()
const unsigned long long INF = 1LL << 60;
typedef  long long ll;
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;
}

int ctoi(char c) {
 	switch (c) {
		case '0': return 0;
		case '1': return 1;
		case '2': return 2;
		case '3': return 3;
		case '4': return 4;
		case '5': return 5;
		case '6': return 6;
		case '7': return 7;
		case '8': return 8;
		case '9': return 9;
		default: return 0;
	}
}


int main(){ 
int N; cin >> N;
vector<pair<int, int>> p(N);
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    p.at(i) = make_pair(a, b);  // a, b の順でペアにする
  }
  sort(all(p));
  int m = p[N-1].second;
  int n = p[0].first;
  int cnt = m + n-1;
  
  rep(i,N-1){
	  cnt += p[i+1].first - p[i].first - 1;
  }
  cout << cnt + N<< endl;
}


Measured memory_bytes: 1024
a, b, c, d, e, f=gets.split.map(&:to_i)

def gen(x, y, ub)
  ret, sx=[], 0
  while sx<=ub
    sy=0
    while sx+sy<=ub
      ret.push(sx+sy)
      sy+=y
    end
    sx+=x
  end
  ret
end

waters=gen(a*100, b*100, f)
sugars=gen(c, d, f)
tot, su=a*100, 0
waters.each do |water|
  sugars.each do |sugar|
    next if sugar*100>water*e
    total=water+sugar
    next if total>f
    if su*total<tot*sugar
      tot=total
      su=sugar
    end
  end
end

puts "#{tot} #{su}"

Measured memory_bytes: 4220
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define all(x) (x.begin()),(x.end())
#define sz(x)  ((ll)x.size())
#define FAST_IO ios_base :: sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
using namespace std;
#ifdef LOCAL
#include "uj.h"
#endif

	
const ll oo = 1e15;
const int maxn  = 1e6;
int N,K;
void test_case(){
	cin >> N >> K;
	vector<int> v(N);
	for(int & el :v)
		cin >> el;
	vector<ll> dp(maxn,oo);
	dp[0] = 0;
	for(int i = 0;i<N;++i){
		for(int j = i+1;j<=i+K;++j)
			dp[j] = min(dp[j],dp[i] + (ll)abs(v[j] - v[i]));
	}
	cout << dp[N-1] << endl;
}

	





int main(){
	FAST_IO;
	int tt;
	//cin>>tt;
	tt = 1;
	while(tt--){
		test_case();
	}
#ifndef ONLINE_JUDGE
 	cerr << "Running Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}


Measured memory_bytes: 11392
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstdio>
#define MN 100000
using namespace std;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
pair<int,int> q[MN*2+5];
int top,n,R,C,s[MN+5],b[MN+5],ha[MN+5];
int Calc(int x,int y)
{
    if(x==0) return y;
    if(y==C) return x+C;
    if(x==R) return R+C+C-y;
    if(y==0) return R+R+C+C-x;
    return -1;
}
int main()
{
    R=read();C=read();n=read();srand((long long)new char);
    for(int i=1;i<=n;++i)
    {
        int x=read(),y=read(),X=read(),Y=read();ha[i]=(rand()<<15|rand())^(rand()<<7);
        int p=Calc(x,y),P=Calc(X,Y);if(p==-1||P==-1) continue;
        q[++top]=make_pair(p,i);q[++top]=make_pair(P,i);
    }
    sort(q+1,q+top+1);
    for(int i=1,v=0;i<=top;++i)
    {
        v^=ha[q[i].second];
       // cout<<i<<" "<<q[i].first<<" "<<q[i].second<<endl;
        if(b[q[i].second]&&(v^s[q[i].second]^ha[q[i].second])) return 0*puts("NO");
        else b[q[i].second]=1,s[q[i].second]=v;
    }
    puts("YES");
    return 0;
}


Measured memory_bytes: 2944
//dlang template---{{{
import std.stdio;
import std.conv;
import std.string;
import std.array;
import std.algorithm;
import std.typecons;
import std.math;
import std.range;

// MIT-License https://github.com/kurokoji/nephele
class Scanner
{
  import std.stdio : File, stdin;
  import std.conv : to;
  import std.array : split;
  import std.string;
  import std.traits : isSomeString;

  private File file;
  private char[][] str;
  private size_t idx;

  this(File file = stdin)
  {
    this.file = file;
    this.idx = 0;
  }

  this(StrType)(StrType s, File file = stdin) if (isSomeString!(StrType))
  {
    this.file = file;
    this.idx = 0;
    fromString(s);
  }

  private char[] next()
  {
    if (idx < str.length)
    {
      return str[idx++];
    }

    char[] s;
    while (s.length == 0)
    {
      s = file.readln.strip.to!(char[]);
    }

    str = s.split;
    idx = 0;

    return str[idx++];
  }

  T next(T)()
  {
    return next.to!(T);
  }

  T[] nextArray(T)(size_t len)
  {
    T[] ret = new T[len];

    foreach (ref c; ret)
    {
      c = next!(T);
    }

    return ret;
  }

  void scan()()
  {
  }

  void scan(T, S...)(ref T x, ref S args)
  {
    x = next!(T);
    scan(args);
  }

  void fromString(StrType)(StrType s) if (isSomeString!(StrType))
  {
    str ~= s.to!(char[]).strip.split;
  }
}

//Digit count---{{{
int DigitNum(int num) {
  int digit = 0;

  while (num != 0) {
    num /= 10;
    digit++;
  }

  return digit;
}
//}}}
//}}}

void main() {
  Scanner sc = new Scanner;

  int A, B, C;

  sc.scan(A, B, C);

  if (B / A < C) {
    writeln(B / A);
  } else {
    writeln(C);
  }
}


Measured memory_bytes: 256
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<vector>
using namespace std;

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//infinity
#define INTINF 2000000000
#define LONGINF 2000000000

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(){
	int n;
	cin >> n;
	int a[n];
	REP(i, n) cin >> a[i];
	sort(a, a+n);

	int A = 100000;
	int ans = 0;
	REP(i, A - 2){
		int l = lower_bound(a, a+n, i) - a;
		int h = upper_bound(a, a+n, i+2) - a;
		ans = max(ans, h - l);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#define rep(i, n)   for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main(){
    int n,k;    cin >> n >> k;
    string s;   cin >> s;
    ll ans = 0;
    ll RL = 0;
    char r = s[n-1], l = s[0];
    rep(i, n-1){
        if(s[i] == 'R' && s[i+1] == 'L'){
            RL++;
        }
    }
    ans = n - RL*2;
    if(n == 1){
        ans = 0;
    }else{
        if(l == 'L')    ans--;
        if(r == 'R')    ans--;
    }
    if(l == 'R'){
        if(r == 'R'){
            if(RL <= k) ans += 2*RL;
            else        ans += 2*k;
        }else{
            if(RL <= k){
                if(RL == 1) ans += 1;
                else        ans += 2*(RL-1);
            }
            else        ans += 2*k;
        }
    }else{
        if(r == 'R'){
            if(RL < k)          ans += 2*RL + 1;
            else if(RL == k)    ans += 2*RL;
            else                ans += 2*k;
        }else{
            if(RL <= k)         ans += 2*RL;
            else                ans += 2*k;
        }
    }
    cout << ans << endl;
}


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

using ll = long long int;
using P = pair<int, int>;
using P3 = pair<ll,P>;
using PP = pair<P, P>;
constexpr int INF = 1 << 30;
constexpr ll MOD = ll(1e9) + 7;
constexpr int di[] = {0, 1, 0, -1};
constexpr int dj[] = {1, 0, -1, 0};
constexpr double EPS = 1e-8;


bool solve(){
    ll n, a, b;
    cin >> n >> a >> b;
    cout << n/(a+b)*a + min(n%(a+b), a);
    return false;
}

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

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

using namespace std;

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


    int d;
    int a;

    int ans[100];

    for (int i = 0; i < 100; i++) {
        ans[i] = 0;
    }

    for (int i = 0; i < k; i++) {
        cin >> d;
        for (int j = 0; j < d; j++) {
            cin >> a;
            ans[a-1]++;
        }
    }

    int aa = 0;
    for (int i = 0; i < n; i++) {
        if (ans[i] == 0)aa++;
    }


    cout << aa;


    return 0;
}

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

int main(){
  int N;
  cin >> N;
  long long L0=2,L1=1,L2;
  for(int i=0;i<N;i++){
    L2 = L1+L0;
    L0 = L1,L1 = L2;
  }
  cout << L0 << endl;
}




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

int n,a[N],b[N],f[2]; ll A,B,dp[N][70009];
int calc(int i,int k,int u,int v){
	if (k&1)
		if (u<a[i]) return 0; else if (u>a[i]) k^=1;
	if (k&2)
		if (u>b[i]) return 0; else if (u<b[i]) k^=2;
	if (k&4)
		if (v<a[i]) return 0; else if (v>a[i]) k^=4;
	if (k&8)
		if (v>b[i]) return 0; else if (v<b[i]) k^=8;
	return 1<<k;
}
int main(){
	scanf("%lld%lld",&A,&B);
	int i,j,k,x,y;
	for (i=59; i>=0; i--) if (B>=(1ll<<i)){
		a[++n]=A>>i&1;
		b[n]=B>>i&1;
	}
	dp[0][1<<15]=1;
	for (i=0; i<n; i++)
		for (j=1; j<65536; j++) if (dp[i][j]){
			for (x=f[0]=f[1]=0; x<2; x++)
				for (y=0; y<2; y++)
					for (k=0; k<16; k++)
						if (j>>k&1) f[x|y]|=calc(i+1,k,x,y);
			for (x=0; x<2; x++) dp[i+1][f[x]]+=dp[i][j];	
		}
	ll ans=0;
	for (i=1; i<65536; i++) ans+=dp[n][i];
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 33152
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>

using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
int N;
vector <int > p;
vector <int > a;
vector <int > b;
vector <int > c;


void rec(int i){
	if(i == N-1)
		return ;
	int A = a[i+1] - a[i];
	int B = b[i+1] - b[i];
	int m;
	if(A>0 && B<0)
		return;
	if(A <= 0&& B >= 0) {
		m = max(abs(A),abs(B))+1;
	} else if(A <= 0) {
		m = abs(A) +1;
	} else if(B >= 0) {
		m = abs(B)+1;
	}
	a[i+1] += m;
	b[i+1] -= m;
	rec(i+1);
}



int main()
{

	cin >> N;

	p.resize(N);
	a.resize(N);
	b.resize(N);
	c.resize(N);

	REP(i,N){
		cin >> p[i];
		a[i] = i;
		b[i] = -i;
		c[i] = N/2 - i;
	}

	REP(i,N){
		if(c[i] > 0) {
			a[p[N-i-1]-1] += c[i];
			rec(p[N-i-1]-1);
		} else if(c[i] < 0) {
			b[p[N-i-1]-1] += c[i];
			rec(p[N-i-1]-1);
		}
	}

	REP(i,N) {
//		cout << a[i] << " ";
		cout << 1+a[i] << " ";
	}
	cout << endl;

	REP(i,N) {
		cout <<  (1 - b[N-1]) + b[i] << " ";
//		cout <<  b[i] << " ";
	}
	cout << endl;



}


Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <algorithm>
#include <list>
using namespace std;

int main()
{
    int n;
    string s;
    cin >> n >> s;
    // change to number
    int * pN = new int[n];
    for (int i = 0; i < n; i++)
    {
        pN[i] = (s[i] - '0');
    }
    // make before and after array
    int * pBefore = new int[n];
    int * pAfter = new int[n];
    pBefore[0] = 0;
    for (int i = 1; i < n; i++)
    {
        pBefore[i] = pBefore[i - 1] | (1 << pN[i - 1]);
    }
    pAfter[n - 1] = 0;
    for (int i = n - 2; i >= 0; i--)
    {
        pAfter[i] = pAfter[i + 1] | (1 << pN[i + 1]);
    }
    // calculate
    bool has[1000];
    for (int i = 0; i < 1000; i++)
        has[i] = false;
    for (int i = 1; i < n - 1; i++)
    {
        int now = pN[i] * 10;
        for (int before = 0; before < 10; before++)
        {
            if ((pBefore[i] & (1 << before)) == 0)
                continue;
            for (int after = 0; after < 10; after++)
            {
                if ((pAfter[i] & (1 << after)) == 0)
                    continue;
                has[before * 100 + now + after] = true;
            }
        }
    }
    // count
    int count = 0;
    for (int i = 0; i < 1000; i++)
        count += has[i];
    cout << count << endl;

    delete[] pN;
    delete[] pBefore;
    delete[] pAfter;
    return 0;
}


Measured memory_bytes: 3788
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)n;i++)
int main(){
    int n;cin>>n;
    vector<int> a,b;
    rep(i,n){
        int x;cin>>x;
        if(i%2==0)a.push_back(x);
        else b.push_back(x);
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    
    int g = a[0],k = 0,max1 = 0,max2 = 0;
    int max11 = -1, max22 = -1;
    priority_queue<int> que1,que2;
    que1.push(0);que2.push(0);
    
    rep(i,a.size()){
        if(g != a[i]||i==a.size()-1){
            if(i==a.size()-1&&g==a[i])k++;
            que1.push(k);
            if(max1<k){
                max11 = g;
                max1 = k;
            }
            k = 1;
            g = a[i];
            continue;
        }else{
            k++;
        }
    }
    g = b[0],k=0;
    rep(i,b.size()){
        if(g != b[i]||i==b.size()-1){
            if(i==b.size()-1&&g==b[i])k++;
            que2.push(k);
            if(max2<k){
                max22 = g;
                max2 = k;
            }
            g = b[i];
            k = 1;
            continue;
        }else{
            k++;
        }
    }
    int c,d;
    c = que1.top();
    que1.pop();
    d = que2.top();
    que2.pop();
    if(max11 != max22){
        int y = n - c-d;
        cout<<y<<endl;
    }else{
        int e,f;
        e = que1.top();
        f = que2.top();
        int y = n - e - d;
        int z = n - c - f;
        cout<<min(y,z)<<endl;
    }
}

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

int main(){
	int n, k;
	cin >> n >> k;
	vector<int> h(n);
	rep(i, n) cin >> h[i];
	int count = 0;
	rep(i, n) {
		if (h[i] >= k) count++;
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 640
import java.io.*;
import java.util.*;

public class Main {
    private static int n, m;
    private static ArrayList[] graph;
    private static int[] max;

    private static int dfs(int i) {
        if (max[i] != -1) {
            return max[i];
        }
        int dist = 0;
        for (Integer neigh : (ArrayList<Integer>) graph[i]) {
            dist = Math.max(dist, 1 + dfs(neigh));
        }
        return max[i] = dist;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        m = sc.nextInt();
        max = new int[n + 1];
        Arrays.fill(max, -1);
        graph = new ArrayList[n + 1];
        for (int i = 0; i <= n; i++) {
            graph[i] = new ArrayList<Integer>();
        }

        for (int i = 1; i <= m; i++) {
            int p = sc.nextInt();
            int q = sc.nextInt();
            graph[p].add(q);
        }

        for (int i = 1; i <= n; i++) {
            dfs(i);
        }
        int ans = 0;
        for (int i = 1; i <= n; i++) {
            ans = Math.max(ans, max[i]);
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 107144
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<utility>
#include<math.h>
#include<cstdlib>
#define rep(i, n) for(int i=0;i<n;i++)
#define repb(i, a, b) for(int i=a;i<b;i++)

using namespace std;
typedef pair<int, int> P;
typedef long long int ll;

const int INF = 1<<30;

int main(){
  int n;ll k;cin>>n>>k;
  vector<int> bit_cnt(41, 0);
  vector<int> k_bit;
  k_bit.push_back(-1);
  rep(i, 41){
    if(k&(1LL<<i))k_bit.push_back(i);
  }
  rep(i, n){
  	ll a;cin>>a;
    rep(j, 41){
      bit_cnt[j]+=bool(a&(1LL<<j));
    }
  }
  ll ans = 0LL;
  for(auto& e: k_bit){
    ll ret = 0LL;
    ll t = 1LL;
    rep(i, e){
      ret += t*max(bit_cnt[i], n-bit_cnt[i]);
      t *= 2;
    }
    if(e!=-1){
      ret += t*bit_cnt[e];t *= 2;
    }
    repb(i, e+1, 41){
      ret += t*(k&(1LL<<i)?n-bit_cnt[i]:bit_cnt[i]);
      t *= 2;
    }
    ans = max(ans, ret);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream> //cinなど
#include<string> //文字列
#include<algorithm> //sort など
#include<math.h> //paw(冪乗など)
#include<set> // 集合
#include<map> //写像
#include<stdio.h> //printf
#include<stack>

using namespace std;
int main(){
  string c;
  cin>>c;

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


Measured memory_bytes: 256
"""
https://atcoder.jp/contests/dp/tasks/dp_f
"""
from collections import defaultdict
s = input()
t = input()
ls = len(s)
lt = len(t)
dp = [[0] * (lt + 1) for _ in range(ls + 1)]
for i in range(ls):
    for j in range(lt):
        if s[i] == t[j]:
            dp[i + 1][j + 1] = 1 + dp[i][j]
        else:
            dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1])

# print(dp[ls][lt])
N = dp[ls][lt]
y = ls
x = lt
ans = []
while N:
    if dp[y][x] == dp[y - 1][x]:
        y -= 1
        continue
    if dp[y][x] == dp[y][x - 1]:
        x -= 1
        continue
    else:
        ans.append(s[y - 1])
        N -= 1
        x -= 1
        y -= 1

print(''.join(ans[::-1]))


Measured memory_bytes: 112220
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>

using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(a) (a).begin(),(a).end()

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

   bool used[10000] = {false};
   used[s] = true;

   int i = 1;
   while(1){
       i++;
       if(s % 2 == 0)s = s/2;
       else s = 3*s + 1;
       if(used[s])break;
       used[s] = true;
   }
   cout << i << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long int
int32_t main(){
	string s,t;
	cin>>s>>t;
	sort(s.begin(),s.end());
	sort(t.begin(),t.end());
	reverse(t.begin(),t.end());
	if(s<t){
		cout<<"Yes";
	}
	else {
		cout<<"No";
	}
}


Measured memory_bytes: 256
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())
    
    
    for n in range(N, 0, -1):
        m = n
        while m % 2 == 0:
            m //= 2
        if m == 1:
            ans = n
            break
        
    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9172
s = list(input())
n = len(s)
even0 = s[1::2].count("0")
even1 = n // 2 - even0
odd0 = s[::2].count("0")
odd1 = n - even0 - even1 - odd0
print(n - max(even0 + odd1, even1 + odd0))

Measured memory_bytes: 4268
def examA():
    N = LI()
    N.sort()
    if N==[1,4,7,9]:
        print("YES")
    else:
        print("NO")
    return

def examB():
    S = SI()
    K = "keyence"
    for i in range(7):
        if S[:i]+S[-7+i:]==K:
            print("YES")
            return
    if S[:7]==K:
        print("YES")
        return
    print("NO")
    return

def examC():
    N = I()
    A = LI()
    B = LI()
    if sum(A)<sum(B):
        print(-1)
        return
    dis = [A[i]-B[i] for i in range(N)]
    dis.sort()
#    print(dis)
    cur = 0
    ans = bisect.bisect_left(dis,0)
    need = -sum(dis[:bisect.bisect_left(dis,0)])
    for i in range(N):
        if need<=cur:
            break
        cur += dis[-i-1]
        ans += 1
    print(ans)
    return

def examD():
    N, M = LI()
    A = LI()
    B = LI()
    DA = {}
    DB = {}
    for i in range(N):
        if A[i] in DA:
            print(0)
            return
        DA[A[i]] = i
    for i in range(M):
        if B[i] in DB:
            print(0)
            return
        DB[B[i]] = i
    ans = 1
    h = 0; w = 0
    for i in range(N*M,0,-1):
        if i in DA:
            if i in DB:
                h += 1
                w += 1
            else:
                ans *= w
                h += 1
        elif i in DB:
            ans *= h
            w += 1
        else:
            if h*w<=N*M-i:
                ans = 0
            ans *= (h*w - (N*M-i))
        ans %= mod
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math,random
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examD()

"""

"""

Measured memory_bytes: 10288