akhauriyash/Code-Regression huggingface dataset:
#ifndef ___Rank_Union_Find
#define ___Rank_Union_Find

#include <vector>

// ------ Class ------ //
class UnionFind {
private:
	unsigned size_; std::vector<unsigned> par, rank;
public:
	UnionFind() : size_(0), par(std::vector<unsigned>()), rank(std::vector<unsigned>()) {};
	UnionFind(unsigned size__) : size_(size__) {
		par.resize(size_); rank.resize(size_);
		for (unsigned i = 0; i < size_; i++) par[i] = i, rank[i] = 0;
	}
	unsigned size() { return size_; }
	unsigned root(unsigned x) { return par[x] == x ? x : par[x] = root(par[x]); }
	bool same(unsigned x, unsigned y) { return root(x) == root(y); }
	void unite(unsigned x, unsigned y) {
		x = root(x), y = root(y);
		if (x == y) return;
		if (rank[x] < rank[y]) par[x] = y;
		else if (rank[x] == rank[y]) par[y] = x, rank[x]++;
		else par[y] = x;
	}
	bool operator==(const UnionFind &u) { return par == u.par; }
	bool operator!=(const UnionFind &u) { return par != u.par; }
};

#endif

#include <cstdio>
#include <vector>
#pragma warning(disable : 4996)
using namespace std;
int N, M, b, x;
int main() {
	scanf("%d%d", &N, &M);
	vector<vector<int> > R(M);
	for (int i = 0; i < N; i++) {
		scanf("%d", &b);
		while (b--) {
			scanf("%d", &x);
			R[--x].push_back(i);
		}
	}
	UnionFind uf(N);
	for (int i = 0; i < M; i++) {
		for (int j = 1; j < R[i].size(); j++) {
			uf.unite(R[i][j - 1], R[i][j]);
		}
	}
	int r = uf.root(0);
	bool flag = true;
	for (int i = 1; i < N; i++) {
		if (r != uf.root(i)) flag = false;
	}
	printf(flag ? "YES\n" : "NO\n");
	return 0;
}

Measured memory_bytes: 4608
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define put(a) cout<<a<<"\n"
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }


int main() {
	int n, d;
	cin >> n >> d;
	put((n + 2 * d)/(2 * d + 1));
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int sum = 0;
		for (int i = 0; i < M; i++) {
			sum += sc.nextInt();
		}
		if (N - sum >= 0) {
			System.out.println(N - sum);
		} else {
			System.out.println(-1);
		}
	}

}


Measured memory_bytes: 46144
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 30000000001;

int main(){
  int x, y, z, k;
  cin >> x >> y >> z >> k;
  vector<ll> ax(x), by(y), cz(z);
  for(int i=0; i<x; ++i) cin >> ax[i];
  for(int i=0; i<y; ++i) cin >> by[i];
  for(int i=0; i<z; ++i) cin >> cz[i];
  sort(ax.rbegin(),ax.rend());
  sort(by.rbegin(),by.rend());
  sort(cz.rbegin(),cz.rend());
  vector<ll> ans;
  for(int i1=0; i1<x; ++i1){
    if(i1+1 > k) break;
    for(int i2=0; i2<y; ++i2){
      if((i1+1)*(i2+1) > k) break;
      for(int i3=0; i3<z; ++i3){
        if((i1+1)*(i2+1)*(i3+1) > k) break;
        ans.push_back(ax[i1] +by[i2] +cz[i3]);
      }
    }
  }
  sort(ans.rbegin(),ans.rend());
  for(int i=0; i<k; ++i){
    printf("%lld\n",ans[i]);
  }
}

Measured memory_bytes: 4332
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
const long double pi = acos(-1);
const long double eps = 1e-10;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    ll n, a, b; cin >> n >> a >> b;
    n %= 12;
    FOR(i, 0, n) {
        if (i % 2 == 0)a = a - b;
        else b = a + b;
    }
    cout << a << " " << b << "\n";
}



Measured memory_bytes: 3120
#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(i=a;i<b;i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define F first
#define S second
#define lb lower_bound
#define vi vector < ll  int >
#define CLR(a) memset((a),0,sizeof(a))
#define mp make_pair
#define hell 1000000007
#define pc __builtin_popcount
using namespace std;

void solve()
{
    ll i,j=0,r=200,p,q,k,d,y=0,h,flag=1,n,m=0,a=hell,b=hell,h1,h2,a1,b1,a2,w,x,u,f,l,c,z;
    cin>>n;
    vector < int > v(n);rep(i,0,n) cin>>v[i];
    rep(i,0,n)
    {

        rep(j,i+1,n)
        {
            y+=v[i]*v[j];
        }
    }
    cout<<y;

}


signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    //cin>>t;
    while(t--)
    solve();
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
     
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define repn(i,a,b)   for(int i=a;i>=b;i--)
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define mp  make_pair
#define all(v) (v).begin(), (v).end()
#define hell 1000000007  
#define hell2 998244353 
#define pi 3.14159265358979323846

int solve(){
    int n,k;
    cin>>n>>k;
    int a[n];
    rep(i,0,n) cin>>a[i];
    sort(a,a+n);
    int s=0;
    rep(i,0,k) s+=a[i];
    cout<<s;

        
    return 0;
}   
     
signed main(){
    IOS;
    int t=1;
    //cin>>t;
    while(t--){
        solve();
        cout<<"\n";
    }
//    return 0;
} 

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

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

#define ll long long
#define pii pair<int,int>
#define pll pair<long long, long long>
#define rep(i,l,r) for(int i = l;i<r;i++)

#define SSTR( x ) static_cast< std::ostringstream & >( \
        ( std::ostringstream() << std::dec << x ) ).str()

#define fastout  ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;

const int INF = (int)1e9 + 7;
const long long LLINF = (long long)1e18 + 7;

void kekek()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    #ifdef EBUCHKA
        freopen("in.txt", "r", stdin), freopen("out.txt", "w", stdout);
    #endif
}

int main() {
	kekek();
	int n;
	cin >> n;
	vector<int> h(n);
	vector<int> dp(n);
	if (n == 1) {
		cout << 0;
		return 0;
	}
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}
	dp[1] = abs(h[1] - h[0]);
	for (int i = 2; i < n; i++) {
		dp[i] = min(dp[i - 1] + abs(h[i - 1] - h[i]), dp[i - 2] + abs(h[i - 2] - h[i]));
	}
	cout << dp[n - 1];
}

Measured memory_bytes: 1024
// /*
//ID: C4551DY
//TASK: friday
//LANG: C++14
//*/
/*  CF_CC
        4U7H0R:_C4551DY */

#include <bits/stdc++.h>
#include <fstream>

using namespace std;

#define IC ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define f(ia) for(int i=0;i<a;i++)
#define lb lower_bound
#define ll long long
#define pii pair<int,int>
#define vec vector<ll>
#define fir first
#define sec second
#define pb push_back
const int mxi=1e6+7;
const int mod=1e9+7;

ll a,ans;

int main()
{
    IC
    //ofstream cout ("-_-.out");
    //ifstream cin ("-_-.in");
    cin >> a;
    int n[a] ;
    for(int i=0;i<a;i++){
        cin >> n[i] ;
    }
    for(int i=0;i<a;i++)
        if (i<n[i]){
            cout << -1;
            return 0;
    }
    for (int i=1;i<a;i++){
        if (n[i]!=n[i-1]+1){
            if (n[i]>n[i-1]+1){
                cout << -1;
                return 0;
            }
            ans+=n[i-1] ;
        }
    }
    ans+=n[a-1];
    cout << ans ;
}



Measured memory_bytes: 1024
import java.util.Scanner;

public class Main{
  static int h, w, n;
  static int[] a;

  static final boolean DEBUG = false;

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

    h = sc.nextInt();
    w = sc.nextInt();
    n = sc.nextInt();
    a = new int[n];
    for(int i = 0; i < n; i++){
      a[i] = sc.nextInt();
    }

    int[][] table = new int[h][w];
    int r = 0, c = 0;
    boolean flag = false;
    for(int i = 0; i < n; i++){
      for(int j = 0; j < a[i]; j++){
        if(DEBUG){
          System.out.println("r = " + r + " c = " + c);
        }
        table[r][c] = i + 1;
        if(!flag){
          if(c + 1 == w){
            r++;
            flag = !flag;
          }
          else{
            ++c;
          }
        }
        else{
          if(c - 1 == -1){
            ++r;
            flag = !flag;
          }
          else{
            --c;
          }
        }
      }
    }

    StringBuilder sb = new StringBuilder();
    for(int i = 0; i < h; i++){
      for(int j = 0; j < w; j++){
        sb.append(table[i][j] + " ");
      }
      sb.append(System.lineSeparator());
    }

    System.out.print(sb);
  }
}

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

int field[10][10];
int f2[10][10];
int f3[10][10];

int dx[] = {
	1, 0, -1, 0
};
int dy[] = {
	0, -1, 0, 1
};

bool inside(int x, int y){
	if(x >= 0 && x < 10 && y >= 0 && y < 10)
		return true;
	else return false;
}

int main(){
	int n;
	cin >> n;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < 10; j++){
			for(int k = 0; k < 10; k++){
				cin >> field[j][k];
			}
		}
		for(int j = 0; j < 1024; j++){
			for(int k = 0; k < 10; k++){
				for(int l = 0; l < 10; l++){
					f2[k][l] = field[k][l];
					f3[k][l] = 0;
				}
			}
			for(int k = 0; k < 10; k++){
				if(((j >> k) & 1) == 1){
					for(int l = 0; l < 4; l++){
						if(inside(k + dx[l], dy[l]))
							f2[dy[l]][k+dx[l]] = (f2[dy[l]][k+dx[l]] + 1) % 2;
					}
					f2[0][k] = (f2[0][k] + 1) % 2;
					f3[0][k] = 1;
				}
			}
			for(int k = 1; k < 10; k++){
				for(int l = 0; l < 10; l++){
					if(f2[k-1][l] == 1){
						f3[k][l] = 1;
						for(int m = 0; m < 4; m++){
							if(inside(k + dy[m], l + dx[m]))
								f2[k+dy[m]][l+dx[m]] = (f2[k+dy[m]][l+dx[m]] + 1) % 2;
						}
						f2[k][l] = (f2[k][l] + 1) % 2;
					}
				}
			}
			bool f = true;
			for(int k = 0; k < 10; k++){
				if(f2[9][k] == 1){
					f = false;
					break;
				}
			}
			if(f) break;
		}
		for(int j = 0; j < 10; j++){
			for(int k = 0; k < 9; k++){
				cout << f3[j][k] << " ";
			}
			cout << f3[j][9] << endl;
		}

	}
	return 0;
}

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

 
int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	
	double w, h, x, y;
	
	cin >> w >> h >> x >> y;
	
	double res = w*h / 2.0;
	
	cout << fixed << setprecision(6) << res << " ";
	
	if((y*w) == res && (x*h) == res) cout << 1 << "\n";
	else cout << 0 << "\n";
	
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<vector>
#include<list>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<climits>
#include<ctime>
#include<cstring>
#define REP(i,p,n) for(int i=p;i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define rep_split(tok,a_str,re) for(char *tok = strtok((char *)a_str.c_str(),re); tok != NULL; tok = strtok(NULL,re))
#define ALL(c) (c).begin(), (c).end()
#define dump(a) cerr << #a << "=" << (a) << endl

template<class T> void chmin(T &t, T f) { if (t > f) t = f; } //t=min 
template<class T> void chmax(T &t, T f) { if (t < f) t = f; } //t=max

using namespace std;

int main() {
	int N,Q;
	int M,date;
	bool dates[100][50]; //date N

	while(cin >> N >> Q) {
		if (N == 0 && Q == 0) break;
		fill_n((bool *)dates,sizeof(dates)/sizeof(bool),false);
		rep(n,N) {
			cin >> M;
			rep(m,M) { //Dates
				cin >> date;
				dates[date][n] = true;
			}
		}

		/*
		rep(n,N) {
			rep(d,20) {
				cout << dates[d][n];
			}
			cout << endl;
		}
		cout << endl; */

		int cnt=0;
		int max_cnt=0;
		int max_d=0;
		rep(d,100) {
			cnt = 0;
			rep(n,N) { //縦に見る
				if(dates[d][n]) {
					cnt++;
				}
			}
			if (cnt > max_cnt) {
				max_cnt = cnt;
				max_d = d;
			}
		}
		if (max_cnt >= Q) {
			cout << max_d << endl;
		}
		else {
			cout << 0 << endl;
		}
	}
	

	return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> l(n);
    for (int i = 0; i < n; i++) cin >> l[i];
    sort(l.begin(), l.end());
    long long ans = 0;
    for (int i = 2; i < n; i++){
        for (int j = 1; j < i; j++){
            int ok = j;
            int ng = - 1;
            while (abs(ok - ng) > 1){
                int mid = (ok + ng) / 2;
                if (l[mid] + l[j] > l[i]) ok = mid;
                else ng = mid;
            }
            ans += j - ok;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
a_list = [int(x) for x in input().split()]

temp_list = [0] * (n + 1)
for i in range(1, n + 1):
    temp_list[i] = a_list[i - 1] + temp_list[i - 1]
 
l = 1
r = 3
ans = temp_list[-1]
for m in range(2, n - 1):
    gap_min = abs((temp_list[m] - temp_list[l]) - (temp_list[l] - temp_list[0]))
    while l < m:
        l += 1
        gap = abs((temp_list[m] - temp_list[l]) - (temp_list[l] - temp_list[0]))
        if gap < gap_min:
            gap_min = gap
        else:
            l -= 1
            break
    else:
        l -= 1
    
    gap_min = abs((temp_list[n] - temp_list[r]) - (temp_list[r] - temp_list[m]))
    while r < n:
        r += 1
        gap = abs((temp_list[n] - temp_list[r]) - (temp_list[r] - temp_list[m]))
        if gap < gap_min:
            gap_min = gap
        else:
            r -= 1
            break
    else:
        r -= 1
    
    num_list = sorted([temp_list[l] - temp_list[0], temp_list[m] - temp_list[l], temp_list[r] - temp_list[m], temp_list[n] - temp_list[r]])
    ans_temp = num_list[3] - num_list[0]
    if ans_temp < ans:
        ans = ans_temp
print(ans)

Measured memory_bytes: 25676
N=int(input())
A,B=list(map(int,input().split()))
ans=0
min_n=float("INF")
l_A = list(map(int,input().split()))
for i in range(N):
    C=A-l_A[i]*0.006
    if min_n > abs(B-C):
        ans=i
        min_n=abs(B-C)
print(ans+1)

Measured memory_bytes: 3064
N = int(input())
*A, = map(int, input().split())
ans = 0
flg = True
while flg:
    for i in range(N):
        if A[i] % 2 != 0:
            flg = False
            break
        A[i] = A[i] // 2
    if flg == False:
        break
    ans += 1
print(ans)

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

int main(){
    ll n,a,b;
    cin>>n>>a>>b;
    ll t=n/(a+b);
    ll tt=n%(a+b);
    ll sum=t*a;
    if(tt){
        a=min(a,tt);
        sum+=a;
    }
    cout<<sum;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            string s = Console.ReadLine();
            int slen = s.Length;
            char[] Alp = "abcdefghijklmnopqrstuvwxyz".ToCharArray();
            int result = int.MaxValue;
            foreach (var item in Alp)
            {
                string[] splitS = s.Split(item);
                int maxLength = splitS.Select(elem => elem.Length).Max();
                result = Math.Min(result, maxLength);
            }
            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 11348
h, w = list(map(int, input().split()))
s = [0 for i in range(h)]
for i in range(h):
    s[i] = input()

flag = False

for i in range(h):
    if flag:
        break
    for j in range(w):
        if s[i][j] == '.':
            continue
        #ue
        if i > 0 and s[i-1][j] == '#':
            continue
        #shita
        if i < h-1 and s[i+1][j] == '#':
            continue
        #hidari
        if j > 0 and s[i][j-1] == '#':
            continue
        #migi
        if j < w-1 and s[i][j+1] == '#':
            continue
        flag = True
        break

if flag:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define i64 long long
#define input freopen("input.txt", "r", stdin)
#define output freopen("output.txt", "w", stdout)
#define fast_io ios_base::sync_with_stdio(0);cin.tie(0);
#define mp make_pair
#define pb push_back

int main()
{
    fast_io

    vector <int>vt;
    vector <pair<int ,int> >xy;
    int x,y,t;
    int n;
    cin >>n;
    int tn=n;
    while(tn--){
        cin >>t>>x>>y;
        vt.pb(t);xy.pb(mp(x,y));
    }
    if(n==1){
        int a = xy[0].first+xy[0].second;
        int b = vt[0];
        int c = b-a;
        if(c<0){cout <<"No"<<endl;return 0;}

        else if(c%2){cout <<"No"<<endl;return 0;}
    }
    for(int i=0;i<n;i++){
        if(i==0)continue;
        else{
            int dif=abs(xy[i].first-xy[i-1].first) + abs(xy[i].second-xy[i-1].second);
            int timee = vt[i]-vt[i-1];
            int ch =  timee-dif;
            if (ch<0){
                cout <<"No"<<endl;
                return 0;
            }
            else if(ch%2){
                cout <<"No"<<endl;
                return 0;
            }
        }

    }
    cout <<"Yes"<<endl;
    return 0;

}



Measured memory_bytes: 1780
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i ,n) for(int i = 0 ; i < (n) ; i ++ )
#define all(x) (x).begin(),(x).end()
using ll = long long;
using namespace std;
using Graph = vector<vector<int>>;


int main() {
  int n,m ;
  cin>>n>>m;
  vector<int> h(n);
  rep(i,n) cin>>h[i];
  vector<int> a(m),b(m);
  rep(i,m) cin>>a[i]>>b[i];
  ////////////////////////
  Graph g(n);
  rep(i,m){
    g[a[i]-1].push_back(b[i]-1);
    g[b[i]-1].push_back(a[i]-1);
  }
  
  
   
  int ans=0;
  rep(i,n){
    //cout<<ans<<endl;
    bool yoi=true;
    for(auto v:g[i]){
      if(h[i]<=h[v]){
        yoi=false;
        break;
      }
        
    }
    if(yoi) ans++;
    
  }
  cout<<ans<<endl;  
}

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

int main(){
    int x, y;
    cin >> x >> y;
    if (y % 2 == 0 && (x * 2 <= y && x * 4 >= y))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

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

int main() {
int N,K;
  int a = 0;
cin >> N >> K;

 vector<int> A(N);
  for (int h = 0; h < N; h++) {
    cin >> A.at(h);
  }

  for (int h = 0; h < N; h++) {
if(A.at(h) >= K )
{
a++;
} 
 }
cout << a << endl;
}

Measured memory_bytes: 640
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0029&lang=jp

strings = gets.split(" ")
hash = Hash.new(0)
strings.each_with_index do |e,i|
  #各ハッシュ要素には、　配列[出現数、文字の長さ]　を与える
    hash[e] =
    [
      hash[e][0] + 1,
      e.length
    ]
end

max_s = 0
longest_size = 0


hash.each do |s, (num_i, size_i)|
  # puts "#{s} #{num_i} #{size_i}"
  if num_i > max_s
    max_s = num_i
    @max_s_string = s
  end

  if size_i > longest_size
    longest_size = size_i
    @longest_size_string = s
  end
end

puts "#{@max_s_string} #{@longest_size_string}"


Measured memory_bytes: 8908
from functools import lru_cache
N, = map(int, input().split())
X = list(map(int, input().split()))
t = 0
for x in X:
    t = t^x
inf = float('inf')
@lru_cache(None)
def it(x, y, z):
    xm, ym, zm = x%2, y%2, z%2
    if xm ^ ym != zm:
        return inf
    if x^y == z:
        return 0
    Rz = 2*it(x>>1, y>>1, z>>1)
    Ro = inf
    if x:
        Ro = 2*it((x-1)>>1, (y+1)>>1, z>>1)+1
    Rz = min(Rz, Ro)
    return Rz

r = it(X[0], X[1], t^X[0]^X[1])
if 0 <= r < X[0]:
    print(r)
else:
    print(-1)


Measured memory_bytes: 67000
void main()
{
  problem();
}

void problem()
{
  const N = scan!int;
  const M = scan!int;
  const Pathes = M.iota
    .map!(_ => scan!int(2))
    .array;
  
  int[][] Routes;
  Routes.length = N;
  foreach(p; Pathes) {
    Routes[p[0] - 1] ~= p[1] - 1;
    Routes[p[1] - 1] ~= p[0] - 1;
  }

  Routes.deb;

  void solve()
  {
    int[] distances = new int[N];
    int[] previousNode = new int[N];

    {
      int[] queue = [0];
      int distance;
      int visitedCount;

      distances[] = -1;
      distances[0] = 0;
      while(true) {
        bool changed;
        distance++;

        queue.deb;
        foreach(from; queue[visitedCount..$]) {
          visitedCount++;
          Routes[from].deb;

          foreach(next; Routes[from]) {
            if (distances[next] != -1) continue;

            distances[next] = distance;
            previousNode[next] = from;
            queue ~= next;
            changed = true;
          }
        }

        if (!changed) break;
      }
    }

    distances.deb;
    previousNode.deb;

    writeln("Yes");
    foreach(n; previousNode[1..$]) {
      writeln(n + 1);
    }
  }

  solve();
}

// ----------------------------------------------

import std.stdio, std.conv, std.array, std.string, std.algorithm,
  std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric;

T[][] combinations(T)(T[] s, in int m)
{
  if (!m)
    return [[]];
  if (s.empty)
    return [];
  return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m);
}

string scan()
{
  static string[] ss;
  while (!ss.length)
    ss = readln.chomp.split;
  string res = ss[0];
  ss.popFront;
  return res;
}

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

T[] scan(T)(int n)
{
  return n.iota.map!(i => scan!T()).array;
}

void deb(T...)(T t)
{
  debug writeln(t);
}

alias Point = Tuple!(long, "x", long, "y");
import std.bigint, std.functional;

// -----------------------------------------------


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll A, B;
    cin >> A >> B;
    cout << max({A + B, A - B, A * B}) << endl;
    return 0;
}


Measured memory_bytes: 3600
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp1
{
    public static class MyExtensions
    {
        public static string Slice(this string str, int start = 0, int stop = 0)
        {
            if (start > str.Length || stop > str.Length || start < 0 || stop < 0)
                return "";

            if (stop == 0) stop = str.Length;
            return str.Substring(start, stop - start);
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            B();
        }

        static void B()
        {
            var w = Read();
            var hash = new HashSet<char>();
            foreach (var a in w)
            {
                hash.Add(a);
            }

            foreach (var h in hash)
            {
                if (w.Count(x => x == h) % 2 != 0)
                {
                    Println("No");
                    return;
                }
            }
            Println("Yes");
        }

        static IEnumerable<int> Range(int start, int stop)
        {
            if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0))
                return new List<int>();

            return Enumerable.Range(start, stop - start);
        }

        static bool IsDigit(string str)
        {
            var i = 0;
            return int.TryParse(str, out i);
        }

        static int DigitsSum(long num)
        {
            return num.ToString().Select(x => x.ToString()).Sum(int.Parse);
        }

        static int[] ToIntArray(string str)
        {
            return str.Select(x => x.ToString()).Select(int.Parse).ToArray();
        }

        static string Read() => Console.ReadLine();
        static int ReadInt() => int.Parse(Read());
        static long ReadLong() => long.Parse(Read());

        static List<string> ReadSplit() => Read().Split().ToList();
        static List<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList();

        static void Print(object value = null) => Console.Write(value.ToString());
        static void Println(object value = null) => Console.WriteLine(value.ToString());
    }
}


Measured memory_bytes: 13396
import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main ()
{
	int a, b;
	while (readf (" %s %s", &a, &b) > 0)
	{
		int res = 0;
		foreach (c; 0..2)
		{
			if (a > b)
			{
				res += a;
				a -= 1;
			}
			else
			{
				res += b;
				b -= 1;
			}
		}
		writeln (res);
	}
}


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


enum FACE { TOP, BOTTOM, FRONT, BACK, LEFT, RIGHT };

class dice {
private:
	int num[6];

	void roll(FACE a, FACE b, FACE c, FACE d) {
		int tmp = num[a];
		num[a] = num[b];
		num[b] = num[c];
		num[c] = num[d];
		num[d] = tmp;
	}

public:
	dice() {
		num[TOP] = 1;
		num[BOTTOM] = 6;
		num[FRONT] = 5;
		num[BACK] = 2;
		num[RIGHT] = 3;
		num[LEFT] = 4;
	}

	const int& operator[] (FACE f) const { return num[f]; }

	void north() { roll(TOP, BACK, BOTTOM, FRONT); }
	void east() { roll(TOP, LEFT, BOTTOM, RIGHT); }
	void west() { roll(TOP, RIGHT, BOTTOM, LEFT); }
	void south() { roll(TOP, FRONT, BOTTOM, BACK); }
	void right() { roll(BACK, RIGHT, FRONT, LEFT); }
	void left() { roll(BACK, LEFT, FRONT, RIGHT); }
};

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

	for(int n; cin >> n, n;) {
		dice d;

		int ans = 1;
		for(int i = 0; i < n; ++i) {
			string ope;
			cin >> ope;

			switch(ope[0]) {
			case 'N':
				d.north();
				break;
			case 'E':
				d.east();
				break;
			case 'W':
				d.west();
				break;
			case 'S':
				d.south();
				break;
			case 'R':
				d.right();
				break;
			case 'L':
				d.left();
			}

			ans += d[TOP];
		}

		cout << ans << endl;
	}


	return EXIT_SUCCESS;
}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define Fast_IO ios::sync_with_stdio(false);
#define fir first
#define sec second
#define mod 998244353
inline int read()
{
	char ch=getchar(); int nega=1; while(!isdigit(ch)) {if(ch=='-') nega=-1; ch=getchar();}
	int ans=0; while(isdigit(ch)) {ans=ans*10+ch-48;ch=getchar();}
	if(nega==-1) return -ans;
	return ans;
}
typedef pair<int,int> pii;
int add(int x,int y){return x+y>=mod?x+y-mod:x+y;}
int sub(int x,int y){return x-y<0?x-y+mod:x-y;}
int mul(int x,int y){return 1LL*x*y%mod;}
#define N 5005
int f[N],a[N];
signed main()
{
#ifdef __LOCAL__
	freopen("in.txt","r",stdin);
#endif
	int n,k,sum=0;
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		a[i]=min(read(),k);
		sum+=a[i];
	}
	f[0]=1;
	sort(a+1,a+n+1);
	for(int i=n;i>=0;i--)
	{
		bool ok=0;
		for(int j=k-1;j>=k-sum&&j>=0;j--)
		{
			if(f[j]) ok=1;
		}
		if(!ok)
		{
			cout<<i<<endl;
			return 0;
		}
		for(int j=k;j>=a[i];j--) f[j]|=f[j-a[i]];
		sum-=a[i];
	}
#ifdef __LOCAL__
	cout<<"Time Used : "<<clock()<<endl;
#endif
	return 0;
}



Measured memory_bytes: 256
def solve():
    N, T = map(int, input().split())
    t = list(map(int, input().split()))
    
    ans = 0
    for i in range(N - 1):
        if t[i + 1] < t[i] + T:
            ans += t[i + 1] - t[i]
        else:
            ans += T
    ans += T
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 26708
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod=1e9+7;
void write(ll ans)
{
    if(ans>9) write(ans/10);
    putchar(ans%10+'0');
}
inline int read()
{
    char c=getchar();int x=0;
    while(c<'0'||c>'9') c=getchar();
    while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+c-'0',c=getchar();
    return x;
}
int n,v=0,x,a[205];
ll ans=0,dp[2][100005];
bool vis[100005];
vector<int>vv;
int main()
{
    n=read();x=read();
    for(int i=1;i<=n;i++)
        a[i]=read();
    sort(a+1,a+1+n);
    reverse(a+1,a+1+n);
    dp[v][x]=1;
    vis[x]=true;
    vv.push_back(x);
    for(int i=1;i<=n;i++,v^=1)
        for(int j=0;j<vv.size();j++)
        {
            int x=vv[j],y=vv[j]%a[i];
            if(!vis[y]) vv.push_back(y),vis[y]=true;
            dp[v^1][y]=(dp[v^1][y]+dp[v][x])%mod;
            dp[v^1][x]=(dp[v^1][x]+dp[v][x]*(n-i))%mod;
            dp[v][x]=0;
        }
    for(int i=0;i<vv.size();i++)
        ans=(ans+dp[v][vv[i]]*vv[i])%mod;
    write(ans);
}


Measured memory_bytes: 896
h,w = map(int,input().split())
res = float('inf')

# H
for i in range(1,h):
    s_h = [i * w]
    s_w = [i * w]
    # のこりは(h-i)*w
    # H
    s_h.append(((h-i)//2) * w)
    s_h.append(((h-i)-(h-i)//2) * w)
    if 0 in ((h-i)//2,((h-i)-(h-i)//2),w):
        s_h.append(float('inf'))
    #print((h-i)//2,w)
    #print(((h-i)-(h-i)//2) , w)
    #print(s_h)
    # W
    s_w.append((h-i) * (w//2))
    s_w.append((h-i) * (w - w//2))
    if 0 in ((h-i),w//2,(w-(w//2))):
        s_w.append(float('inf'))
    #print((h-i) , w//2)
    #print((h-i) , (w - w//2))
    #print(s_w)
    res_h = max(s_h) - min(s_h)
    res_w = max(s_w) - min(s_w)
    res = min(res,res_h)
    res = min(res,res_w)

# W
for i in range(1,w):
    s_h = [h * i]
    s_w = [h * i]
    # のこりはh*(w-i)
    # H
    s_h.append((h//2) * (w-i))
    s_h.append((h - (h//2)) * (w-i))
    if 0 in ((h//2),(w-i),(h-(h//2))):
        s_h.append(float('inf'))
    # W
    s_w.append(h * ((w-i)//2))
    s_w.append(h * ((w-i) - (w-i)//2))
    if 0 in (h,((w-i)//2),((w-i)-(w-i)//2)):
        s_w.append(float('inf'))
    res_h = max(s_h) - min(s_h)
    res_w = max(s_w) - min(s_w)
    res = min(res,res_h)
    res = min(res,res_w)

print(res)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL<<60;

ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}

ll LCM(ll a,ll b){
    return a / GCD(a,b) * b;
}

const int MOD = 1000000007;


int main() {
    int a,b; cin >> a >> b;
    int ans = -1;
    for(int i = 1;i <= 1000;i++){
        if(floor(i * 0.08) == a && floor(i * 0.1) == b){
            ans = i;
            break;
        }
    }
    cout << ans;
}




Measured memory_bytes: 3584
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <sstream>
#include <math.h>
#include <queue>
#include <map>
#include <set>
#include <ios>     // std::left, std::right
#include <iomanip> // std::setw(int), std::setfill(char)
using namespace std;


int main(){
long long N,M;
cin>>N>>M;
long long a,b,c,d;
a=N;
b=1;
if(N%2==0){
    c=N/2-1;
    d=N/2+1;
}
else{
    c=N/2;
    d=N/2+2; 
}
for(int i=0;i<M;++i){
if(i%2==0){
cout<<a<<" "<<b<<"\n";
a-=1;
b+=1;
}
else{
cout<<c<<" "<<d<<"\n";
c-=1;
d+=1;
}

}
return 0;
}

Measured memory_bytes: 3624
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <iostream>
#include <cstdlib>

using namespace std;

int main()
{
    
    int a,b,h;
    // 入力
    cin >> a >> b >> h;
   
    int answer = (a+b)*h/2;
    
    //　出力
    cout << answer << endl;
}


// if (条件式)｛
     
//    }


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

int main(){
	string str;
	cin>>str;
	int i,j,k;
	char jch=str.back();
	char ich=str[0];
	int res=0;
	i=0,j=str.size()-1;

	while(i<=j){
		while(i<=j&&str[i]==ich) i++;
		if(i<=j){
			res++;
			ich=str[i];
		}
		while(j>=i&&str[j]==jch) j--;
		if(j>=i){
			res++;
			jch=str[j];
		}
		if(j==i) break;
	}
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5,M=2e5+5; 
const int  maxn=5e5+5;
int n,m,tot;
ll  head[maxn],ver[maxn],edge[maxn],Next[maxn],d[maxn];
ll dis[2][maxn],ans[2][maxn];
bool v[2][maxn];
int const mod=1e9+7;
int s,t;


void add(int x,int y,int z){
	ver[++tot]=y,edge[tot]=z,Next[tot]=head[x],head[x]=tot;
}
void dijk(int l,ll d[],bool v[],ll a[]){
	priority_queue< pair<ll,int> >q;
	d[l]=0;
	a[l]=1;
	q.push(make_pair(0,l));
	while(q.size()){
		int x=q.top().second;
		q.pop();
		if(v[x])
		continue;
		v[x]=1;
		for(int i=head[x];i;i=Next[i]){
			int y=ver[i],z=edge[i];
			if(d[y]>d[x]+z){
				d[y]=d[x]+z;
				a[y]=a[x];
				
				q.push(make_pair(-d[y],y));
			}
			else if(d[y]==d[x]+z) 
			{  a[y]=(a[x]+a[y])%mod;
			}
		}
	}
}
int main(){
	cin>>n>>m;
	cin>>s>>t;
	tot=0;
	memset(head,-1,sizeof(head));
	memset(dis,0x3f,sizeof(dis));
	for(int i=1;i<=m;i++){
		int x,y,z;
		cin>>x>>y>>z;
		add(x,y,z);
		add(y,x,z);
	} 
	dijk(s,dis[0],v[0],ans[0]);	
	dijk(t,dis[1],v[1],ans[1]);
//	cout<<ans[0][t]<<endl;
	ll num=((ans[0][t]%mod)*(ans[1][s]%mod))%mod;
//	cout<<num<<endl; 
	ll L=dis[0][t];
//	cout<<L<<endl; 
	for(int i=1;i<=n;i++){
		if(dis[0][i]==dis[1][i]&&L==dis[0][i]*2){
//			cout<<i<<endl;
			num=num-((ans[0][i]*ans[0][i]%mod)*(ans[1][i]*ans[1][i]%mod))%mod;
			num=(num+mod)%mod;
//				cout<<num<<endl; 
		}
		for(int j=head[i];~j;j=Next[j]){
				int y=ver[j],z=edge[j];
				ll l1=dis[0][i],l2=dis[1][y];
//				cout<<l1<<" "<<z<<" "<<l2<<endl;
				if(l1+z+l2==L&&l1*2<L&&l2*2<L){
					num=num-((ans[0][i]*ans[0][i]%mod)*(ans[1][y]*ans[1][y]%mod))%mod;
			num=(num+mod)%mod;
//				cout<<num<<endl; 
				}
		}
	}
	cout<<num<<endl;
}

Measured memory_bytes: 29556
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001
#define mod 1000000007
#define pi 3.141592653589793
ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll g=gcd(a,b);
    return a/g*b;
}

ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t=rep_jijo(n,x/2);
        return t*t%mod;
    }
    return n*rep_jijo(n,x-1)%mod;
}
ll com(ll n,ll r){
    ll x=1,y=1;
    ll tmp=n;
    while(tmp>=n-r+1){
        x=x*tmp%mod;
        tmp--;
    }
    while(r>0){
        y=y*r%mod;
        r--;
    }
    return x*rep_jijo(y,mod-2)%mod;
}

int main (){
    int n,h;
    int mx=0;
    int ans=0;
    cin >> n >> h;
    vector<int>b(n);
    rep(i,n){
        int a;
        cin >> a >> b[i];
        mx=max(mx,a);
    }
    sort(b.begin(),b.end());
    reverse(b.begin(),b.end());
    rep(i,n){
        if(h<=0) break;
        if(b[i]<=mx) break;
        h-=b[i];
        ans++;
    }
    if(h<=0){
        cout << ans << endl;
        return 0;
    }
    ans+=(h+mx-1)/mx;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include <stdio.h>

int main(void) {
	int W, H, x, y, r;
	scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
	if(x - r < 0) goto NO;
	if(x + r > W) goto NO;
	if(y - r < 0) goto NO;
	if(y + r > H) goto NO;
	printf("Yes\n");
	return 0;
NO:
	printf("No\n");
	return 0;
}

Measured memory_bytes: 584
import itertools 
from itertools import combinations, chain 
  
def findsubsets(s, n): 
    return list(map(set, itertools.combinations(s, n))) 


arr=[]
n,m,x=list(map(int,input().split(" ")))
book=[]
for i in range(n):
	temp=list(map(int,input().split(" ")))
	book.append(temp)
s=[]
for i in range(0,n):
	s.append(i)
elig=[]
for i in range(1,n+1):
	temp=findsubsets(s,i)
	# print(temp)
	for j in range(len(temp)):
		sub=temp[j]
		algo=[0]*m
		cost=0
		for k in sub:
			b=book[k]
			cost+=b[0]
			for l in range(1,len(b)):
				algo[l-1]+=b[l]

		fl=0
		for k in range(m):
			if(algo[k]<x):
				fl=1
				break
		if(fl==0):
			elig.append(cost)
if(len(elig)==0):
	print(-1)
else:
	print(min(elig))

				




Measured memory_bytes: 10528
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1010000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; 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(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

long long int fact(long long int n){
	long long int f=1;
	for(int i=1;i<=n;i++) f=(f*i)%MOD;
	return f;
}

int main (void){
	COMinit();
	long long int n,m,a[1010],b[1010],i,j,ans=1,def=0;
	cin >> n >> m;
	for(i=0;i<n;i++) cin >> a[i];
	for(i=0;i<m;i++) cin >> b[i];
	sort(a,a+n);
	sort(b,b+m);
	a[n]=2000; b[m]=2000;
	int flag=0;
	for(i=0;i<n;i++){
		if(a[i]<m*(i+1)) flag=1;
	}
	for(i=0;i<m;i++){
		if(b[i]<n*(i+1)) flag=1;
	}
	if(flag==1){
		cout << "0" << endl;
		return 0;
	}
	for(i=0;i<n-1;i++){
		if(a[i]==a[i+1]) flag=1;
	}
	for(i=0;i<m-1;i++){
		if(b[i]==b[i+1]) flag=1;
	}
	if(flag==1){
		cout << "0" << endl;
		return 0;
	}
	i=0; j=0;
	while(i!=n||j!=m){
		def++;
		if(a[i]<b[j]){
			if(a[i]-def<m-j-1){
				cout << "0" << endl;
				return 0;
			}
			ans=(ans*((fact(m-j)*COM(a[i]-def,m-j-1))%MOD))%MOD;
			def+=(m-j-1);
			i++;
		} else if(a[i]>b[j]){
			if(b[j]-def<n-i-1){
				cout << "0" << endl;
				return 0;
			}
			ans=(ans*((fact(n-i)*COM(b[j]-def,n-i-1))%MOD))%MOD;
			def+=(n-i-1);
			j++;
		} else {
			if(a[i]-def<m+n-i-j-2){
				cout << "0" << endl;
				return 0;
			}
			ans=(ans*((fact(m+n-i-j-2)*COM(a[i]-def,m+n-i-j-2))%MOD))%MOD;
			def+=(m+n-i-j-2);
			i++;
			j++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 24064
#include<cstdio>
#include<algorithm>
using namespace std;
#define MAXN 100010
#define LL long long
#define INF 1000000000
int Adj[MAXN],V[MAXN*2],nxt[MAXN*2],W[MAXN*2],c;
void AddEdge(int u,int v,int w)
{
	c++;V[c]=v,W[c]=w,nxt[c]=Adj[u];Adj[u]=c;
}
int siz[MAXN],mx[MAXN],rt,rt2,n,tmp=INF;
LL ans;
void dfs1(int u,int p)
{
	siz[u]=1;
	for(int i=Adj[u];i;i=nxt[i])
		if(V[i]!=p)
		{
			dfs1(V[i],u);
			siz[u]+=siz[V[i]];
			mx[u]=max(mx[u],siz[V[i]]);
		}
	mx[u]=max(mx[u],n-siz[u]);
	if(mx[u]<=n/2)
	{
		if(rt==0) rt=u;
		else rt2=u;
	}
}
void dfs2(int u,int p,LL dep)
{
	ans+=dep*2;
	for(int i=Adj[u];i;i=nxt[i])
		if(V[i]!=p)
		{
			dfs2(V[i],u,dep+W[i]);
			if(V[i]==rt2||(rt2==0&&u==rt))
				tmp=min(tmp,W[i]);
		}
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		int u,v,w;
		scanf("%d%d%d",&u,&v,&w);
		AddEdge(u,v,w);
		AddEdge(v,u,w);
	}
	dfs1(1,0);
	dfs2(rt,0,0);
	ans-=tmp;
	printf("%lld\n",ans);
}


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


using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)
#define repb(i, ed, st) for(int i=ed; i>=st; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI  = 3.141592653589793238463;
const int N = 1e5 + 10;
const ll INF = 1LL << 50;

template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}



// Main Code
ll parent[N], ran[N];
int find(int x)
{
    if(parent[x]==x)return x;
    else return parent[x]=find(parent[x]);
}
// Union()
void unite(int x,int y){
    x=find(x);
    y=find(y);
    if(x==y)return;

    if(ran[x]<ran[y]){
        parent[x]=y;
        ran[y] = ran[y] + ran[x];
    }
    else{
        parent[y]=x;
       	ran[x] = ran[x] + ran[y];
    }
}
int main()
{
	ll n, m;
	cin>>n>>m;
	vector<pair<int, int>> vec(m+2);
	repn(i, 0, n+2)
		parent[i] = i, ran[i] = 1;
	repn(i, 1, m)
	{
		int u, v;
		cin>>u>>v;
		vec[i] = make_pair(u, v);
	}
	ll ans[m+1];
	ans[m] = n*(n-1) / 2;
	repb(i, m-1, 1)
	{
		int u = find(vec[i+1].f);
		int v = find(vec[i+1].s);
		//cout<<u<<" "<<v<<endl;
		if(u != v)
		{
			ans[i] = ans[i+1] - ran[u]*ran[v];
			unite(u, v);
		}
		else
		{
			ans[i] = ans[i+1];
		}
	}
	repn(i, 1, m)
		cout<<ans[i]<<endl;
}


Measured memory_bytes: 4480
#include <stdio.h>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
typedef long long ll;

ll max(ll x, ll y, ll z) {
  if(x >= y && x >= z) return x;
  return y >= z ? y : z;
}

ll min(ll x, ll y, ll z) {
  if(x <= y && x <= z) return x;
  return y <= z ? y : z;
}

int main(void) {
  ll N;
  scanf("%lld", &N);
  ll A[1LL << 18];
  REP(i, 0, 1LL << N) scanf("%lld", A + i);

  ll ans = 0;
  REP(k, 1, 1LL << N) {
    ll p = 0, q = 0;
    ll i = k;
    do {
      ll w = max(p, q, A[i]);
      q = p + q + A[i] - w - min(p, q, A[i]);
      p = w;
      i = (i - 1) & k;
    } while(i != k);
    ans = max(ans, p + q, 0);
    printf("%lld\n", ans);
  }
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
#define maxn 100020
#define rep(i,l,r) for(register int i = l ; i <= r ; i++)
#define repd(i,r,l) for(register int i = r ; i >= l ; i--)
#define rvc(i,S) for(register int i = 0 ; i < (int)S.size() ; i++)
#define rvcd(i,S) for(register int i = ((int)S.size()) - 1 ; i >= 0 ; i--)
#define fore(i,x)for (register int i = head[x] ; i ; i = e[i].next)
#define pb push_back
#define prev prev_
#define stack stack_
#define mp make_pair
#define fi first
#define se second
#define inf 0x3f3f3f3f
typedef long long ll;
typedef pair<int,int> pr;

typedef long long ll;
const ll mod = 1e9 + 7;
int n,a[maxn];
ll f[maxn],fac,inv[maxn];

inline ll power(ll x,ll y){
	ll res = 1;
	while ( y ){
		if ( y & 1 ) res = res * x % mod;
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
int main(){
	scanf("%d",&n);
	rep(i,1,n) scanf("%d",&a[i]);
	if ( n == 1 ){ cout<<a[1] % mod<<endl; return 0; }
	inv[1] = 1 , fac = 1;
	rep(i,2,n) inv[i] = (inv[i - 1] + power(i,mod - 2)) % mod , fac = fac * i % mod;
	ll ans = 0;
	ans = (ans + fac * inv[n] % mod * (a[1] + a[n])) % mod;
	rep(i,2,n - 1){
		ans = (ans + fac * (inv[n - i + 1] + inv[i] - 1) % mod * a[i]) % mod;
	}
	cout<<(ans % mod + mod) % mod<<endl;
}


Measured memory_bytes: 1408
N = gets.to_i
score = gets.split("\s").map {|s|s.to_i}
rate = Array.new(8,0)
ex = 0
min = 0
max = 0

score.each do |d|
  if rate[0]==0 && d >= 1 && d <= 399 then
    rate[0] = 1
    min += 1
  elsif rate[1]==0 && d >= 400 && d <= 799 then
    rate[1] = 1
    min += 1
  elsif rate[2]==0 && d >= 800 && d <= 1199 then
    rate[2] = 1
    min += 1
  elsif rate[3]==0 && d >= 1200 && d <= 1599 then
    rate[3] = 1
    min += 1
  elsif rate[4]==0 && d >= 1600 && d <= 1999 then
    rate[4] = 1
    min += 1
  elsif rate[5]==0 && d >= 2000 && d <= 2399 then
    rate[5] = 1
    min += 1
  elsif rate[6]==0 && d >= 2400 && d <= 2799 then
    rate[6] = 1
    min += 1
  elsif rate[7]==0 && d >= 2800 && d <= 3199 then
    rate[7] = 1
    min += 1
  elsif d >= 3200 then
    ex += 1
  end
end
max = min+ex
#if max > 8 then
#  max = 8
#end
if min == 0 then
  min = 1
end
puts "#{min} #{max}"


Measured memory_bytes: 1788
#import numpy as np
N = int(input())
A = list(map(int, input().split()))

NG = 0
for i in range(N):
    if (A[i] % 2 == 0):
        if (A[i] % 3 != 0) and (A[i] % 5 != 0):
            print("DENIED")
            exit()

print("APPROVED")


Measured memory_bytes: 2940
#include <iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>
#include<cmath>
#include<set>
#include<deque>
#include<iomanip>
using namespace std;
typedef long long ll;

typedef pair<int, int> pii;

const ll MOD_CONST = 1000000007;


const int INF = 1000000000;
const ll BIG_NUM = 1000000000000000000;



int main() {
	int h, w, k;
	cin >> h >> w >> k;

	vector<string> s(h);
	for (int i = 0; i < h; i++) {
		cin >> s[i];
	}

	vector<vector<int>> sum(h+1, vector<int>(w));
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			sum[i + 1][j] = sum[i][j];
			if (s[i][j] == '1') {
				sum[i + 1][j]++;
			}
		}
	}

	int ans = h + w;

	for (int b = 0; b < (1 << h - 1); b++) {
		
		
		vector<int> p;
		p.emplace_back(0);
		for (int i = 0; i < h - 1; i++) {
			if (((b>>i) & 1) == 1) {
				p.emplace_back(i+1);
			}
			
		}
		p.emplace_back(h);
		
		int a = p.size()-2;
		vector<int> cnt(a + 1);
		
		//cout << a << endl;

		bool canConsist = true;
		for (int i = 0; i < w; i++) {
			bool isOver = false;
			for (int j = 0; j < cnt.size(); j++) {
				
				

				cnt[j] += sum[p[j + 1]][i] - sum[p[j]][i];
				if (cnt[j] > k) {
					isOver = true;
					
					break;
				}
			}

			if (isOver) {
				for (int j = 0; j < cnt.size(); j++) {

					cnt[j] = sum[p[j + 1]][i] - sum[p[j]][i];
					
					if (cnt[j] > k) {
						canConsist = false;

						break;
					}
				}
				a++;
			}
			
			
			
		}
		if (!canConsist) {
			continue;
		}
		ans = min(ans, a);
		
	}

	cout << ans << endl;

}




Measured memory_bytes: 256