akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define revrep(i, n) for(ll i = (n)-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
/*
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll max3(ll a, ll b, ll c){return max(a, max(b, c));};
ll min3(ll a, ll b, ll c){return min(a, min(b, c));};
ll max4(ll a, ll b, ll c, ll d){return max(max(a, b), min(c, d));};
ll min4(ll a, ll b, ll c, ll d){return min(min(a, b), min(c, d));};
ll max5(ll a, ll b, ll c, ll d, ll e){return max(max(a, b), max3(c, d, e));};
ll min5(ll a, ll b, ll c, ll d, ll e){return min(min(a, b), min3(c, d, e));};
*/
const ll INFL = 1LL << 60;//10^18 = 2^60
const int INF = 1 << 30;//10^9
ll MOD = 1000000007;
//ll MOD = 998244353;

vector<ll> dy = {0, 0, 1, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, -1, 0, 0, 1, -1, 1, -1, 0};

//デバッグ
void BinarySay(ll x, ll y = 60){rep(i, y) cout << (x>>(y-1-i) & 1); cout << endl;}

ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}
ll pow_mod(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}

ll inverse(ll x){return pow_mod(x, MOD - 2);};

ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b, a % b);
}

ll lcm(ll x, ll y){return x / gcd(x, y) * y;};

ll kai_mod(ll x){
  if(x == 0) return 1;
  return x * kai_mod(x-1) % MOD;
}

/*
//コンビネーション
const int MAXcomb = 200010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; 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;
    }
}
ll comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}
*/



ll N, M;
vector<ll> A, B;
vector<ll> C[1010];
ll dp[1<<13];

void solve(){
  rep(i, (1<<13)) dp[i] = INFL;
  dp[0] = 0;
  vector<ll> D(M, 0);
  rep(i, M){
    rep(j, B[i]){
      D[i] += 1<<(C[i][j]);
    }
  }

  rep(i, (1<<N)){
    rep(j, M){
      dp[i | D[j]] = min(dp[i | D[j]], dp[i] + A[j]);
    }
  }
  if(dp[(1<<N)-1] == INFL){
    cout << -1 << endl;
  }else{
    cout << dp[(1<<N)-1] << endl;
  }

}


int main(){
  cin >> N >> M;
  A.resize(M), B.resize(M);
  rep(i, M){
    cin >> A[i] >> B[i];
    rep(j, B[i]){
      ll c;
      cin >> c;
      c--;
      C[i].pb(c);
    }
  }
  solve();
}


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

int main() {
  long long x,y;
  cin >> x >> y;

  long long a=x;
  long long count = 0;

  while(a <= y) {
    a *= 2;
    count++;
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <cmath>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <complex>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <list>
#include <unordered_map>

using namespace std;

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

	int maxval = 1;

	for (int i = 2; i < X; ++i) {
		for (int j = 2; pow(i, j) <= X; ++j) {
			int ref = pow(i, j);
			if (maxval < ref)
				maxval = ref;
		}
	}

	cout << maxval << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include<algorithm>
#include <string>
#include <cmath>
#include<queue>
#define PI 3.141592653589793238
#define ll long long
using namespace std;

int main()
{
	int n, k;
	string str;
	int max = 0;
	int point[3];

	vector<int> que;
	vector<int>win;

	cin >> n >> k >> point[0] >> point[1] >> point[2];
	cin >> str;

	for (int i = 0; i < n; i++) {
		switch (str[i])
		{
		case 'r':
			win.emplace_back(2);
			break;
		case 's':
			win.emplace_back(0);
			break;
		case 'p':
			win.emplace_back(1);
		default:
			break;
		}
	}

	for (int i = 0; i < k; i++) {
		//printf("case 0(+%d)\n", point[win[i]]);
		max += point[win[i]];
		que.emplace_back(win[i]);
	}

	for (int i = k; i < n; i++) {
		if (win[i] == que.front()) {
			//printf("case 1\n");
			que.emplace_back(-1);
		} else {
			//printf("case 2(+%d)\n", point[win[i]]);

			que.emplace_back(win[i]);
			max += point[win[i]];
		}
		que.erase(que.begin());
	}

	cout << max;

	return 0;
}

Measured memory_bytes: 1528
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
	int N, i;
	int ans = 0;
	int cnt = 0;
	double a;
	scanf("%d", &N);

	if (N < 10) {
		printf("%d", N);
		return 0;
	}
	else {
		ans += 9;
	}

	for (i = 10; i <= N; i++) {
		cnt = 0;
		a = i;
		while(a >= 10){
			a /= 10;
			cnt++;
		}
		cnt++;
		if (cnt % 2 == 1) {
			ans++;
		}
	}

	printf("%d\n", ans);

	return 0;
}

Measured memory_bytes: 128
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<numeric>
#include<bitset>
#include<limits>
#include<unordered_map>
#include<functional>
using namespace std;

#define rep(i,s,n) for(int i=s;i<n;i++)
#define dow(i,n,s) for(int i=n-1;i>=s;i--)
#define all(a) a.begin(),a.end()
#define Sort(a) sort(all(a))
#define Qsort(a,size) qsort(a,size,sizeof(*a),compare_int)
#define DEBUG
typedef pair<int,int> II;
typedef unsigned long ul;
typedef long long ll;
typedef unsigned long long ull;
bool compare_int(const void *a,const void *b) { return *(int *)a-*(int *)b; }
bool compare_by_second(II a,II b) { return a.second!=b.second?a.second<b.second:a.first<b.first; }

const int INF = 1e+9;
const int MAX_N = 1e+3;
const int MAX_M = 5e+2;

int N,m;
int c,d;
int cd[MAX_N+1];
int mn = INF,mx = 0,res = 0;
int bmx = 0;
bool flag;

int main() {
  cin>>N>>m;
  memset(cd,-1,sizeof(cd));
  rep(i,0,m) {
    cin>>c>>d;
    cd[c] = max(cd[c],d);
  }

  rep(i,0,N+1) {
    if(cd[i] > mx) mx = cd[i];
    if(cd[i] != -1) {
      mn = min(i,mn);
      cd[i] = -1;
    }
    if(i != 0 && i == mx) {
      res += (3*mx-2*mn-bmx);
      bmx = mx;
      flag = true;
      rep(j,i+1,N+1) {
        if(cd[j] != -1) { flag = false; break; }
      }
      if(flag) break;
      mx = 0;
      mn = INF;
    }
  }
  res+=(N+1-mx);
  cout<<res<<endl;
  return 0;
}



Measured memory_bytes: 3088
//shara's here
//私は私は大きい男の子
//SPEEEEEEEEEED IS KEEEEEEEEEEY
//REEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEAAAAAAAAAAAAAAAAAAAADDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD
#include <bits/stdc++.h>
using namespace std;
//fold
typedef string s;
typedef long long ll;
typedef long double ld;
const ll INF = 1e18 + 10;
const ll MINF = -(1e18 + 10);
#if defined(BANYANYA)
#include "/home/xsharawi/Desktop/cpp/debug.hpp"
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define pb push_back
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
//endfold
int main(){
	ll t,cnt=0;
	cin>>t;
	map<s,ll>mep;
	for(ll i=0;i<t;i++){
	s ss;
	cin>>ss;	
	mep[ss]++;
	cnt=max(cnt,mep[ss]);
	}
	for(auto ele:mep){
	if(ele.second==cnt)cout<<ele.first<<endl;	
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	





return 0;}
/*
███████████████████████████████████████████████████
███████████████████████████████████████████████████
██████████████████████████████████▀████████████████
██████████████████████████████████░▀███████████████
██████████████████████████████▌███░░░▀▀████████████
██▀████████████████████▐██████░▐██░░░░░░▀▀█████████
██░████████████████████▐█████▌░██▌▄░░░░▄▄░▄████▀███
█▌░███████████████████▀░█████░░░█░░░▄████░░███▀▐███
█▌░▐██████████████████░░████▌░░░▀░░▀███▀▀░▐███▄████
██░▀██████████████▌▐█▐▄▄████▌░░░░░░░░░░░░░▌████████
███░███████████████▀░▄▄██▀█▐░░░░░░░░░░░░░░▐████████
███▄░██████████████▄░░░░░░▀▀▀░░░░░░░░░░░░░█▐███████
████▄░██████████████████▄▄▄▄▄▄▐▄░░░░░░░░░░░████████
█████▄█████████████████▀▀▀▀▀▀░░░░░░░░░░░░░░████████
████████████████████████▄░░░░░░░░░░░░░░░▄░░████████
██████████████████████████▄▄▄░░░░░░░░░▄█░▄█████████
████████████████████████████████▄░░░░██▄███▀░░▀████
█████████████████████████████▀█████▄███▀▀▀░░▄▄░████
████████████████████████████▀░░▀░░▀▀░░░░▄▄▄██▀░░▀▀█
███████████████████████████▌░░░░░░░░░░░███████░░░▄█
███████████████▄░▀████████▀░░░░░░▀░░░░███████▌░░░██
███▄▄████████████▄░▀██████▄░░░░░█░░░░████████░░░▀▀
░▀█████████████████▄░▀█████░░░░██░░░░▀██████░░░░░▄█
▐█▄▀█████████████████▄░▀████░░░██▌░░░▐████▀░░░░▄███
▐███▄▀▀█████████████████▄░▀▀░░░░▀██▌▄█▀▀░░░▄▄██████
▀▀▀▀▀░░░▀▀▀▀▀░░░▀▀▀▀▀▀▀▀▀▀▀░░░░░░░▀▀░░░░░░▀▀▀▀▀▀▀▀▀
*/


Measured memory_bytes: 25216
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
long long n,k,ans;
long long calc(long long a,long long b,long long c)
{
	if (a%b>=c) return a/b+1;
	else return a/b;
}
int main()
{
	scanf("%lld%lld",&n,&k);
	for (long long i=1;i<=n;i++)
	{
		long long x=i%k,y=k-x;
		if ((y+y)%k!=0) continue;
		else ans+=calc(n,k,y)*calc(n,k,y);
	}
	printf("%lld\n",ans);
	return 0;
}

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

int i;

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

    int intmax = max(a, max(b, c));

    if ((intmax * 3 - a - b - c) % 2 == 1)
    {
        intmax++;
    }

    cout << (intmax * 3 - a - b - c) / 2;
}

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

int my_gcd(int n, int m){
    if(n < m) swap(n, m);
    if(m == 0) return n;
    return my_gcd(m, n%m);
}

signed main(){
    // cout << fixed << setprecision(10) << flush;

    int n;
    cin >> n;
    vector<int> a(n);
    int maxa = 0;
    for(int i=0; i<n; i++){
        cin >> a[i];
        maxa = (maxa < a[i])? a[i] : maxa;
    }

    vector<int> primes;
    vector<int> min_prime_factor(maxa+1, 0);
    
    primes.push_back(2);
    for(int j=2; j<=maxa; j+=2){
        min_prime_factor[j] = 2;
    }
    
    int i;
    for(i=3; i*i<=maxa; i+=2){
        if(min_prime_factor[i] != 0) continue;
        primes.push_back(i);
        for(int j=i; j<=maxa; j+=i){
            if(min_prime_factor[j] == 0){
                min_prime_factor[j] = i;
            }
        }
    }
    
    for(; i<=maxa; i+=2){
        if(min_prime_factor[i] == 0){
            primes.push_back(i);
            min_prime_factor[i] = i;
        }
    }

    int ggcd = a[0];
    for(int i=1; i<n; i++){
        ggcd = my_gcd(a[i], ggcd);
        if(ggcd == 1) break;
    }

    if(ggcd != 1){
        cout << "not coprime" << endl;
        return 0;
    }

    map<int, int> mp_prime;
    for(int j=0; j<primes.size(); j++){
        mp_prime[primes[j]] = j;
    }

    vector<bool> c(primes.size(), false);
    for(int i=0; i<n; i++){
        while(a[i] != 1){
            int p = min_prime_factor[a[i]];
            if(c[mp_prime[p]] != false){
                cout << "setwise coprime" << endl;
                return 0;
            }
            c[mp_prime[p]] = true;
            a[i] /= p;
            while(a[i] % p == 0) a[i] /= p;
        }
    }
    cout << "pairwise coprime" << endl;

    return 0;
}

Measured memory_bytes: 24436
from collections import defaultdict

def find(tab, a):
    if tab[a] == -1: return a
    tab[a] = find(tab, tab[a])
    return tab[a]

def union(tab, a, b):
    pa, pb = (find(tab, a), find(tab, b))
    if pa!=pb:
        tab[pb] = pa

N, M = [int(a) for a in input().split(" ")]
P = [int(v) for v in input().split(" ")]
xys = [[int(a) for a in input().split(" ")] for i in range(M)]

tab = [-1]*N
for x, y in xys:
    union(tab, x-1, y-1)

indices = defaultdict(list)
ps = defaultdict(set)

for i in range(N):
    root = find(tab, i)
    indices[root].append(i+1)
    ps[root].add(P[i])

ans = 0
for root, idxs in indices.items():
    s = ps[root]
    for idx in idxs:
        if idx in s:
            ans += 1

print(ans)

Measured memory_bytes: 77892
import sys
import time
import math
st = time.perf_counter()
def inpl():
    return list(map(int, input().split()))
# ------------------------------

N = int(input())
ls = inpl()

a = 0
for i in ls:
    a = a ^ i

for i in ls:
    print(i ^ a, end=' ')
print()

# ------------------------------
ed = time.perf_counter()
print('time:', ed-st, file=sys.stderr)


Measured memory_bytes: 30816
#include<iostream>
#include<string>
#include<vector>

using namespace std;

int main(){
  int N;
  string S;
  cin >> N >> S;

  if (S.length()<=N) cout<<S<<endl;
  else{
    cout << S.substr(0,N) << "..." <<endl;
  }
  return 0;
}


Measured memory_bytes: 3628
#include<iostream>
#include<cstdint>
using namespace std; // 575

const int MAX = 100000;
const int64_t MAX2 = 1099511627776; // 2^40
int main() {
	int N;
	int64_t K, A[MAX];
	cin >> N >> K;
	for (int i = 0;i < N;++ i) cin >> A[i];
	int64_t ans = 0;
	for (int64_t i = MAX2;i > 0;i >>= 1) {
		int c = 0;
		for (int j = 0;j < N;++ j) if (A[j] & i) ++ c; // cは0を選ぶと増える数
		if (i <= K && c < N - c) { // そのbitは1にする
			ans += (N - c) * i;
			K -= i;
		} else ans += c * i; // そのbitは0にする
	}
	cout << ans;
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

まず、各bit独立に考えられるのでそうします
まず最初の1bitについて考えれば残りも同様に解けるので、それを考えます
サンプルの1, 6, 3だと1, 0, 1に等しいので、1とxorするより0とxorする方が1個分得です
以下同様に求めれば終了
*/

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s,t;
  cin>>s>>t;
  string a = "abcdefghijklmnopqrstuvwxyz";
  int i,j,ans =0 ,ii,ij,c=0;
  for(i=0;i<= s.length()-t.length();i++)
  {
      for(j=0;j<t.length();j++)
      {
          ii=i;
          //ij=j;
          if(s[i+j] == t[j])
            c++;
      }
      ans = max(ans,c);
      c=0;
  }



  cout<<t.length()-ans;
  return 0;
}


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

int main() {
  int N, K; cin >> N >> K;
  string S; cin >> S;
  int ans = 0;
  for (int i = 0; i < N-1; i++) {
    if (S.at(i) == S.at(i+1)) ans++;
  }
  cout << min(ans + 2*K, N-1) << endl;
}

Measured memory_bytes: 512
#include<iostream>

int main() {
    char b;
    std::cin >> b;

    if (b == 'A') std::cout << 'T' << std::endl;
    if (b == 'T') std::cout << 'A' << std::endl;
    if (b == 'C') std::cout << 'G' << std::endl;
    if (b == 'G') std::cout << 'C' << std::endl;
}

Measured memory_bytes: 256
N,x= map(int,input().split())
array = list(map(int,input().split()))
array2=array.copy()
result=0
#TLE pattern
# for i in range(0,N-1):
#     #i と i+1 が閾値以下じゃなかったら 
#     while array[i] + array[i+1] > x:
#         if array[i+1]!=0:
#             array[i+1]-=1
#         else:
#             array[i]-=1
#         result+=1
# print(result)

for i in range(0,N-1):
    if array[i] + array[i+1] > x:
        # if array[i+1] - (array[i] + array[i+1] - x) >= 0:
        #     array[i+1]=array[i+1] - (array[i] + array[i+1] - x)
        if (array[i]+array[i+1])-x <= array[i+1]:
            array[i+1]= array[i+1] - (array[i]+array[i+1]-x)
        else:
            # array[i]=array[i] - (array[i]+array[i+1]) - x - array[i+1]
            array[i]= array[i]-(array[i]-x)
            array[i+1]=0

# print(array2)
# print(array)
print(sum(array2)-sum(array))

Measured memory_bytes: 14068
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>

using namespace std;

int binarySearch(int S[], int n, int key) {
    int left_search_index = 0;
    int right_search_index = n;

    while(left_search_index < right_search_index) {
        int search_index = (left_search_index + right_search_index) / 2;
        if (S[search_index] == key) return 1;
        if (S[search_index] < key) left_search_index = search_index + 1;
        else right_search_index = search_index;
    }
    return 0;
}


int main(void) {
    int n, S[100001], q, key;
    int count = 0;

    cin >> n;
    for (int ni =0; ni < n; ni++) cin >> S[ni];

    cin >> q;

    for (int qi =0; qi < q; qi++) {
        scanf("%d",&key);
        count += binarySearch(S, n, key);
    }

    cout << count << endl;

    return 0;
}


Measured memory_bytes: 3424
N=int(input())
A=[int(x) for x in input().split()]

ans=0
s=0
for i in range(N):
  s+=A[i]
  if i % 2 ==0:
    if s<=0:
      ans+=(abs(s)+1)
      s=1
  else:
    if s>=0:
      ans+=(abs(s)+1)
      s=-1

ans2=0
s2=0
for i in range(N):
  s2+=A[i]
  if i % 2 ==0:
    if s2>=0:
      ans2+=(abs(s2)+1)
      s2=-1
  else:
    if s2<=0:
      ans2+=(abs(s2)+1)
      s2=1
print(min(ans,ans2))

Measured memory_bytes: 14468
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a=0;
	string s;
	cin>>s;
	for(int i=0;i<s.size()-1;i++) if(s[i]=='A'&&s[i+1]=='C') a++;
	if(a) cout<<"Yes";
	else cout<<"No";
	return 0;
}


Measured memory_bytes: 256
from collections import Counter

n = int(input())

ps = []
while n % 2 == 0:
    ps.append(2)
    n //= 2
f = 3
while f * f <= n:
    if n % f == 0:
        ps.append(f)
        n //= f
    else:
        f += 2
if n != 1:
    ps.append(n)

ans = 0
for p, x in Counter(ps).items():
    i = 1
    j = 1
    if x != 1:
        while i <= x:
            j += 1
            i += j
        ans += j-1
    else:
        ans += 1

print(ans)


Measured memory_bytes: 9468
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

h = {}
def dfs(n,i,j,k,f):
    if (n,i,j,k,f) in h:
        return h[(n,i,j,k,f)]
    for e in range(11):
        if 10**e>n:
            break
    p = n//(10**(e-1))
    if e==1:
        s = i+j+k
        if s>1:
            return 0
        elif s==1:
            if i==1 and n>=7 or j==1 and n>=5 or k==1 and n>=3:
                return 1
            else:
                return 0
        else:
            if n>=7:
                return 3
            elif n>=5:
                return 2
            elif n>=3:
                return 1
            else:
                return 0
    sm = 0
    x = 10**(e-1)-1
    y = n-p*(10**(e-1))
    if p>7:
        sm += dfs(x,0,j,k,0)
    elif p==7:
        sm += dfs(y,0,j,k,0)
    if p>5:
        sm += dfs(x,i,0,k,0)
    elif p==5:
        sm += dfs(y,i,0,k,0)
    if p>3:
        sm += dfs(x,i,j,0,0)
    elif p==3:
        sm += dfs(y,i,j,0,0)
    if f>0:
        sm += dfs(x,i,j,k,1)
    h[(n,i,j,k,f)] = sm
    #ddprint(f"n {n} i {i} j {j} k {k} ret {sm}")
    return sm

n = inn()
print(dfs(n,1,1,1,1))


Measured memory_bytes: 38384
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll = long long;

int main(){
  int N;
  cin >> N;
  
  vector<double> v(N);
  for( int i = 0; i < N; i++ ) cin >> v.at(i);
  sort( v.begin(), v.end() );
  
  double sum = 0;
  sum += v.at(0) / pow(2,(N-1));
  for( int i = 1; i < N; i++ ) sum += v.at(i) / pow(2,(N-i));

  cout << sum;
  return 0;
}


Measured memory_bytes: 256
n=int(input())
s={}
ans=[]
max=0
for i in range(n):
    st=input()
    if st in s:
        s[st]+=1
    else:
        s[st]=1
    if max<s[st]:
        max=s[st]
        ans=[st]
    elif max==s[st]:
        ans.append(st)
ans.sort()
for i in ans:
    print(i)


Measured memory_bytes: 33416
#include <iostream>

using namespace std;

int a, b, c;
int main(){
    bool answer = false;
    cin >> a >> b >> c;
    if(a + b == c) answer = true;
    if(b + c == a) answer = true;
    if(c + a == b) answer = true;
    if(answer){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <sstream>
#include <string>
#include <map>
#include <set>
#include <stdlib.h>
#include <cmath>
#include <math.h>
#include <fstream>
#include <bitset>
#include <time.h>
#include <queue>
#include <cassert>
#include <cstdio>
#define int long long
using namespace std;
signed main()
{
    int h, w;
    cin >> h >> w;
    char matrix[h][w];
    for (int i=0; i < h; i++){
        for (int j=0; j < w ; j++){
            cin >> matrix[i][j];
        }
    }
    int v[26];
    for (int i=0; i < 26; i++){
        v[i] = 0;
    }
    for (int i=0; i < h; i++){
        for (int j=0; j < w ; j++){
            v[matrix[i][j] - 'a']++;
        }
    }
    int oo = 0;
    for (int i=0; i < 26; i++){
        if (v[i] % 2 != 0) oo++;
    }
    if (oo >= 2){
        cout << "No" << endl;
        return 0;
    }
    if (oo == 1){
        if (h % 2 == 0 || w % 2 == 0){
            cout << "No" << endl;
            return 0;
        }
        for (int i=0; i < 26; i++){
            if (v[i] % 2 != 0) v[i]--;
        }
    }
    int tw = 0;
    if (w % 2 != 0){
        tw += h/2;
    }
    if (h % 2 != 0){
        tw += w/2;
    }
    int pl = 0;
    for (int i=0; i<26; i++){
        if (v[i] % 4 != 0) pl++;
    }
    if (pl > tw){
        cout << "No" << endl;
        return 0;
    }
    int nn = tw - pl;
    if (nn % 2 != 0){
        cout << "No" << endl;
    }
    else cout << "Yes" << endl;
    return 0;
}

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

using namespace std;

int main(){
	string s;
	bool flag = false;
	cin>>s;
	for(int i = 0; i < (int)s.size(); i++){
		if(s[i] == '7') flag = true;
	}
	if(flag) cout<<"Yes\n";
	else{
		cout<<"No\n";
		}
}


Measured memory_bytes: 3628
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <fstream>
#include <set>
#include <utility>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <numeric>
#include <sstream>
#include <list>
#include <map>

#define rep(i,p,n) for(int i=(int)p;i<(int)n;i++)
#define repp(i,p,n) for(int i=(int)p;i>=(int)n;i--)
#define Sort(x) sort(x.begin(),x.end());
#define ll long long 
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvvi <vector<vector<vector<int>>> 
#define vc vector<char> 
#define vvc vector<vector<char>>
#define vvvc vector<vector<vector<char>>> 

using namespace std;

int main() {
	string s;
	cin >> s;
	rep(i, 0, s.length() - 1) {
		if (s[i]=='A' && s[i+1]=='C') {
			cout << "Yes" << endl;
			return 0;
		}
	}

	cout << "No" << endl;

	return 0;
}


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

signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int A, B;
    cin >> A >> B;
    if ((A + B) % 2 == 0) {
        cout << (A + B) / 2 << endl;
    } else {
        cout << "IMPOSSIBLE" << endl;
    }
    
    
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    
    for(int i = 0 ; i < 100 / 7 ; i++ ){
      for(int j = 0; j< 100/ 4 ; j++){
        if(N==(i*7) + (j*4)){
          System.out.println("Yes");
          return;
        }
      }
    }
    System.out.println("No");
  }
}
      
           

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

using namespace std;

const int MOD = 2019;

set < pair < int, int > > m;

int main()
{
    ios_base::sync_with_stdio(NULL);
    cin.tie(0);
    cout.tie(0);
    int l, r, ans(MOD), pasi(0);
    cin >> l >> r;
    for (int i = l; i < l + MOD && i <= r && ans != 0; ++i) {
        for (int j = i + 1; j < i + 1 + MOD && j <= r && ans != 0; ++j) {
            ++pasi;
            assert(m.find({i, j}) == m.end());
            m.insert({i, j});
            ans = min(1LL * ans, 1LL * i * j % MOD);
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 5248
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <ctime>
using namespace std;
char map[100][100];
int counter=0;
char ch;
int m,n;
void dps(int i,int j)
{
    if(i<1 || i>m || j<1 || j>n)    return ;
    if(map[i][j]!=ch)
        return ;
    map[i][j]='.';
    dps(i+1,j);
    dps(i-1,j);
    dps(i,j-1);
    dps(i,j+1);
}

int main()  
{  
    
    while(cin>>m>>n && m!=0 && n!=0)
    {
        counter=0;
        memset(map,'0',sizeof(map));
        for(int i=1;i<=m;i++)
        {
            for(int j=1;j<=n;j++)
            {
                cin>>map[i][j];
            }
        }
        for(int i=1;i<=m;i++)
        {
            for(int j=1;j<=n;j++)
            {
                if(map[i][j]!='.')
                {
                    ch=map[i][j];
                    counter++;
                    dps(i,j);
                }
            }
        }
        cout<<counter<<endl;
    }
    //system("pause");
    return 0;
}  


Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main(){
    int N;
    cin >> N;
    int l[1000], r[1000];
    for(int i=0;i<N;i++)
        cin >> l[i] >> r[i];
    
    int c[100000] = {}, ans = 0;
    for(int i=0;i<N;i++){
        for(int j=l[i]-1;j<r[i];j++){
            c[j] = 1;
        }
    }
    for(int i=0;i<100000;i++){
        if(c[i] == 1)
            ans++;
    }
    
    cout << ans << endl;

}

Measured memory_bytes: 640
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def main():
	#a = int(input())
	#b , c = tin()
	s = input()
	if ord('A') <= ord(s) and ord(s) <= ord('Z'):
		return 'A'
	return 'a'
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 9108
//Awwawa! Dis cold yis ratten buy tEMMIE!
#include <bits/stdc++.h>
#define ll long long
#define maxn 10000005 /*rem*/
#define mod 1000000007 
#define db double
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define pi pair<int, int>
#define fi first
#define se second

template <typename T> bool chkmax(T &x,T y){return x<y?x=y,true:false;}
template <typename T> bool chkmin(T &x,T y){return x>y?x=y,true:false;}

using namespace std;
ll ksm(ll a, ll b) {
   if (!b) return 1;
   ll ns = ksm(a, b >> 1);
   ns = ns * ns % mod;
   if (b & 1) ns = ns * a % mod;
   return ns;
}
int n, a;
ll jc[maxn], bjc[maxn];
ll bk[20005];
ll pr[5005]; // 恰有
ll tr[5005][5005]; // 有x个自环 钦定若干个不能是 
ll c(int a, int b) {
	if (b > a || b < 0) return 0;
	return 1ll * jc[a] * bjc[b] % mod * bjc[a - b] % mod;
} 
ll dp[5005][5005]; //还剩若干个 要求若干个 
ll s[5005][5005];
int main() {
	jc[0] = bjc[0] = 1;
	for (int i = 1; i < maxn; i++)
		jc[i] = jc[i - 1] * i % mod;
	bjc[maxn - 1] = ksm(jc[maxn - 1], mod - 2);
	for (int j = maxn - 2; j >= 0; j--)
		bjc[j] = bjc[j + 1] * (j + 1) % mod;
	for (int i = 0; i < 20005; i++)	
		bk[i] = ksm(i, mod - 2);
	int n, k;
	cin >> n >> k;
	for (int i = 0; i < k; i++) {
		// 钦定i个数 假
		pr[i] = 1;
		pr[i] = pr[i] * jc[n - i - 1] % mod;
		pr[i] = pr[i] * bjc[k - i - 1] % mod; 
	}
	for (int i = 0; i <= k; i++) // 有i个必须交互 j个数不能和后面交互 
		for (int j = 0; j <= k - i; j++) {
			//要求i不能是 j必须是
			ll er = 0;
			if (i == 0) er = pr[j];
			else {
				er = tr[i - 1][j] - tr[i - 1][j + 1];
				er %= mod;
				if (er < 0) er += mod;
			}
			tr[i][j] = er;
		}
	for (int i = 0; i <= k; i++)
		for (int j = 0; j <= k - i; j++) { // 有j个限制 剩余长度是i 
			ll mt = bk[i];
			if (i == 0) mt = 1;
			dp[i][j] = tr[j][i] * mt % mod;// * bk[i] % mod; // 当前点要求是自环
			if (i) 
				dp[i][j] += (s[i - 1][j] - dp[i - 1][j] + dp[i - 1][j + 1]) % mod * bk[i] % mod;
			dp[i][j] %= mod;
			if (i) s[i][j] = s[i - 1][j];
			s[i][j] = (s[i][j] + dp[i][j]) % mod;
		}
	ll ans = dp[k][0];
	ans %= mod;
	ans = ans * jc[k] % mod;
	ans %= mod;
	if (ans < 0) ans += mod;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 510256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>
 
using namespace std;
 
int n;
vector<int> a;
 
 
int ans = 0;
 
 
 
void func(int tmp){
    if(a[tmp] == 2){
        cout<<ans + 1;
        return ;
    } else if(ans>n){
        cout<< -1;
        return;
    }
    else{
        ans++;
        func(a[tmp]-1 );
    }
}
 
int main(){
 
cin >>n;
a.resize(n);
for(int i=0; i<n; i++){
    cin >> a[i];
}
    func(0);
}

Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>	
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r);
#define TYPE long long
#define MEMSET(a) memset(a,0,sizeof(a))
const int mod=(int)1e09+7;

int in(void){
	int i;scanf("%d",&i);
	return i;
}
long long llin(void){
	long long i;scanf("%lld",&i);
	return i;
}
double din(void){
	double i;scanf("%lf",&i);
	return i;
}
void chin(char s[]){
	scanf("%s",s);
}
void print(int a){
	printf("%d\n",a);
}
void llprint(long long a){
	printf("%lld\n",a);
}
void dprint(double a){
	printf("%.10f\n",a);
}
void print2(int a,int b){
	printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
	return a>b?a:b;
}
long long min(long long a,long long b){
	return a<b?a:b;
}
long long llabs(long long a){
	return a>0?a:-a;
}
double dmax(double a,double b){
	return a>b?a:b;
}
int cmp(const void *a,const void *b){
	return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
	return *(TYPE *)b-*(TYPE *)a;
}
int char_cmp(const void *a,const void *b){
	return strcmp((char *)a,(char *)b);
}
int char_cmp_r(const void *a,const void *b){
	return strcmp((char *)b,(char *)a);
}
void swap(int *a,int *b){
	int t=*a;
	*a=*b;
	*b=t;
}
long long gcd(long long x,long long y){
	return x%y?gcd(y,x%y):y;
}
long long lcm(long long x,long long y){
	return x/gcd(x,y)*y;
}

int main(void){
	int n=in(),a,c1=0,c2=0,c4=0,i;
	rep(i,n){
		a=in();
		if(a%2)c1++;
		else if(!(a%4))c4++;
		else c2++;
	}
	if(c1<=c4)puts("Yes");
	else if(c1==c4+1&&c1+c4==n)puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>

int main(){
  char s1[4], s2[4], s3[4], s4[4];
  
  scanf("%s %s %s", s1, s2, s3);
  
  s4[0] = s1[0];
  s4[1] = s2[1];
  s4[2] = s3[2];
  s4[3] = '\0';
  
  printf("%s", s4);
  
  return 0;
}

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

int main()
{
	int a;
	cin>>a;
	for(int i=a;i<=999;i++)
	{
		if(i/100==i/10%10&&i/100==i%10&&i/10%10==i%10)
		{
			cout<<i<<endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define fs ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int main(){
	ll n,t,x=1,a,b,c,dp[100001][4];
	cin>>n;
        t=n;
	n--;
	cin>>a>>b>>c;
	dp[1][1]=a;
	dp[1][2]=b;
	dp[1][3]=c;
	while(n--){
		x++;
		cin>>a>>b>>c;
		for(ll i=1;i<=3;i++){
			if(i==1)
			  dp[x][i]=max(dp[x-1][2]+a,dp[x-1][3]+a);
			else if(i==2)
			  dp[x][i]=max(dp[x-1][1]+b,dp[x-1][3]+b);
			else if(i==3)
			  dp[x][i]=max(dp[x-1][1]+c,dp[x-1][2]+c);
		}
	}
	ll maxi=0;
	for(ll i=1;i<=3;i++){
            //cout<<dp[t][i]<<endl;
	   maxi=max(maxi,dp[t][i]);
         }
        cout<<maxi;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi >
#define vvvi vector<vvi >
#define pii pair<int,int>
#define INF 1e9
#define MOD 1e9+7
typedef long long llong;
using namespace std;

int main(){
	string s,t;
	cin>>s>>t;
	
	vi start(26,-1),goal(26,-1);
	REP(i,s.size()){
		int a=s[i]-'a';
		int b=t[i]-'a';
		
		if(start[a]!=-1||goal[b]!=-1){
			if(start[a]!=b||goal[b]!=a){
				cout<<"No"<<endl;
				return 0;
			}
		}else{
			start[a]=b;
			goal[b]=a;
		}
	}
	
	cout<<"Yes"<<endl;
}//解説参考.

Measured memory_bytes: 776
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
#include <stack>
#include <cctype>
#include <cmath>
#include <bitset>

using namespace std;

/* typedef */
typedef long long ll;

/* constant */
const int INF = 1 << 30;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;

/* global variables */

/* function */

/* main */
int main(){

    int n, a;
    cin >> n;
    bool can = true;
    for (int i = 0; i < n && can; i++) {
        cin >> a;
        if (a % 2 == 0)
            if (a % 3 != 0 && a % 5 != 0) 
                can = false;
    }
    if (can) 
        cout << "APPROVED" << '\n';
    else 
        cout << "DENIED" << '\n';
}


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

using namespace std;

int main(void)
{
    int H, W;
    cin >> H >> W;
    vector<vector<int>> S(H, vector<int>(W, 0));
    for(int i = 0; i < H; ++i)
    {
        for(int j = 0; j < W; ++j)
        {
            char sij;
            cin >> sij;
            if('#' == sij)
                S[i][j] = -1;
        }
    }
#define INCB(sij) {if(sij != -1) sij++;}
    for(int i = 0; i < H; ++i)
    {
        for(int j = 0; j < W; ++j)
        {
            if(S[i][j] == -1)
            {
                if(i-1 > -1 && j-1 > -1)
                    INCB(S[i-1][j-1]);
                if(i-1 > -1)
                    INCB(S[i-1][j]);
                if(i-1 > -1 && j+1 < W)
                    INCB(S[i-1][j+1]);

                if(j-1 > -1)
                    INCB(S[i][j-1]);
                if(j+1 < W)
                    INCB(S[i][j+1]);

                if(i+1 < H && j-1 > -1)
                    INCB(S[i+1][j-1]);
                if(i+1 < H)
                    INCB(S[i+1][j]);
                if(i+1 < H && j+1 < W)
                    INCB(S[i+1][j+1]);
            }
        }
    }
    for(int i = 0; i < H; ++i)
    {
        for(int j = 0; j < W; ++j)
        {
            if(S[i][j] == -1) cout << '#';
            else cout << S[i][j];
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 888
#include <iostream>
#include <vector>

int main()
{
    int N, T;
    std::cin >> N >> T;

    int minv = 1001;
    for (int i = 0; i < N; i++) {
        int c, t;
        std::cin >> c >> t;
        if (t <= T && minv > c) {
            minv = c;
        }
    }

    if (minv == 1001) std::cout << "TLE" << std::endl;
    else std::cout << minv << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>

int main(){
    int n;
    scanf("%d",&n);
    int p[n];
    for(int i = 0; i < n; i++){
        scanf("%d",&p[i]);
    }
    int mi = 0;
    for(int i = 0; i < n; i++){
        if(p[i] > p[mi]){
            mi = i;
        }
    }

    int sum = 0;
    for(int i = 0; i < n; i++){
        if(i == mi){
            sum += p[i] / 2;
        }else{
            sum += p[i];
        }
    }
    printf("%d\n",sum);

    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using Int = long long;

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n,k;
  cin>>n>>k;
  vector<Int> v(n),w(n),m(n);
  for(Int i=0;i<n;i++) cin>>v[i]>>w[i]>>m[i];
  
  const Int INF=1e9;
  vector<Int> dp(k+1,-INF);
  dp[0]=0;
  for(Int i=0;i<n;i++){
    Int t=1;
    while(m[i]>=t){
      for(Int j=k-w[i]*t;j>=0;j--)
	if(dp[j]!=-INF) chmax(dp[j+w[i]*t],dp[j]+v[i]*t);
      m[i]-=t;
      t<<=1;
    }
    t=m[i];
    if(!t) continue;
    for(Int j=k-w[i]*t;j>=0;j--)
      if(dp[j]!=-INF) chmax(dp[j+w[i]*t],dp[j]+v[i]*t);
  }
  cout<<*max_element(dp.begin(),dp.end())<<endl;
  return 0;
}



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

int main()
{
    int n, m;
    cin >> n >> m;
    int t = m * 1900 + (n - m) * 100;
    int c = 1;
    for(int i = 0; i < m; i++){
        c *= 2;
    }
    cout << t * c << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define long long long
using namespace std;
const int N=4e6,mod=1e9+7;
int big(int b,int p,int m=mod)
{
  int ret=1;
  while(p){if(p&1)ret=(1LL*ret*b)%m;b=(1LL*b*b)%m;p/=2;}
  return ret;
}
int fac[N+2];
void init(int n)
{
  fac[0]=1;
  for(int i=1;i<=n;i++)fac[i]=(1LL*fac[i-1]*i)%mod;
}
int ncr(int n,int r)
{
  int a=fac[n];a=(1LL*a*big(fac[r],mod-2))%mod;
  return (1LL*a*big(fac[n-r],mod-2))%mod;
}
int main()
{
  ios_base::sync_with_stdio(0);cin.tie(0);
  init(N);

  int r1,c1,r2,c2;cin>>r1>>c1>>r2>>c2;

  int ans=0;
  for(int c=c1;c<=c2;c++)
  {
    ans=(ans+ncr(r2+c+1,r2))%mod;
    ans=((ans-ncr(r1+c,r1-1))%mod+mod)%mod;
  }
  cout<<ans<<endl;
  
  return 0;
}

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

int main()
{
    int count=0;
    string s;
    cin>>s;
    string t;
    cin>>t;
    rep(i,s.size())
    {
        if(s[i]==t[i])
        {
            count++;
        }
    }
    cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;
static const ll MAX = 1000001;
static const ll MAXR = 1001;
ll presence[MAX] = {};
ll maxim[MAXR][MAXR] = {};
#define NIL -1

ll upper[MAX] = {};

int main() {
    

    ll n,m;
    cin >> n >> m;
    vector <ll> a,b;
    for (ll i=0;i<n;i++){
        ll p;
        cin >> p;
        a.push_back(p);
    }
    for (ll i=0;i<m;i++){
        ll p;
        cin >> p;
        b.push_back(p);
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    for (ll i=0;i<n;i++){
        for (ll j=0;j<m;j++){
            presence[a[i]] = presence[b[j]] = 1;
            maxim[i][j] = min(a[i], b[j]);
        }
    }
    for (ll i=0;i<n;i++){
        for (ll j=0;j<m;j++){
            if(a[i] == b[j]){
                presence[a[i]] = 2; // used
                maxim[i][j] = NIL;
            }
        }
    }
    for (ll i=0;i<n;i++){
        for (ll j=0;j<m;j++){
            if(maxim[i][j] != NIL){
                upper[maxim[i][j]] += 1;
            }
        }
    }

    ll ans = 1;
    ll alr = 0;
    for (ll i=m*n;i>0;i--){
        if(presence[i] == 1){
            ans *= (upper[i]);
            ans %= mop;
            upper[i]--;
        }
    }

    ll defv = 0;
    for(ll i = MAX-1;i>=0;i--){
        defv += upper[i];
        upper[i] = defv;
    }



    for (ll i=m*n;i>0;i--){
        if(presence[i] == 0){
            ans *= (upper[i] - alr);
            ans %= mop;
            alr += 1;
//            cout << ans << endl;
        }
    }


//    for(ll i=0;i<n;i++){
//        for (ll j=0;j<m;j++){
//            if(j){
//                cout << " ";
//            }
//            cout << maxim[i][j];
//        }
//        cout << endl;
//    }
//    cout << endl;
//    for (ll i=1;i<=n*m;i++){
//        cout << i << " " << presence[i] << endl;
//    }
//    for (ll i=1;i<=n*m;i++){
//        cout << i << " " << upper[i] << " " << presence[i] << endl;
//    }


    cout << ans << endl;
}




Measured memory_bytes: 18688
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<int,int,int> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int a,b;
	cin>>a>>b;
	if(max(a,b)>8)cout<<":("<<endl;
	else cout<<"Yay!"<<endl;
}










Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)    for(long long i = 0; i < (n) ; ++i)
#define orep(i,n)   for(long long i = 1; i <= (n); ++i)   // one rep
#define drep(i,n)   for(long long i = (n)-1; i >= 0; --i) // down rep
#define srep(i,s,t) for(long long i = (s); i < (t); ++i)  // set rep
#define rng(x)  (x).begin(),(x).end()

  // range
#define rrng(a) (a).rbegin(),(a).rend() // reverse range
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define ru(x,y) (((x)+(y)-1)/(y)) // round up
#define fi first
#define se second
#define eb emplace_back
#define fcout cout << fixed << setprecision(15)


using namespace std;
using ll  = long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vvi = vector<vi>;
using vp  = vector<P>;
using vl  = vector<ll>;

template<typename T> void Yes(T flag) {
  cout << (flag ? "Yes" : "No") << endl;
}

template<typename T> void pv(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) { cout << v << ","; }
  cout << "]" << endl;
}

template<>
void pv(vector<P> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << "<" << v.fi << ","<< v.se << ">" << ",";
  }
  cout << "]" << endl;
}

template<typename T> void pv2(vector<vector<T>> vec) {
  for(auto& v : vec) pv(v);
}

int ans;
int n,m;
vvi path(9,vi());

bool inpath(int t,vi mow) {
  bool flag = false;
  rep(i,mow.size()) if(t==mow.at(i)) flag = true;
  return flag;
}

void dfs(vi now) {
  if(now.size()==n) {
    ans++;
    return;
  }
  int bk = now.back();
  rep(i,path.at(bk).size()) {
    int t = path.at(bk).at(i);
    if(inpath(t,now)) {
      continue;
    }
    now.eb(t);
    dfs(now);
    now.pop_back();
  }
}

int main() {
  cin >> n >> m;
  rep(i,m) {
    int a,b;
    cin >> a >> b;
    path[a].eb(b);
    path[b].eb(a);
  }

  dfs(vi (1,1));


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


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

#define N 100000
ll a[N], b[N];

int main(){
	int n;
	cin>>n;
	rep(i, n) cin>>a[i];
	rep(i, n) cin>>b[i];
	ll res = 1;
	rep(i, n){
		ll ex = 0, r = -1, ub = min(a[i], b[i]);
		if(i==0 || a[i-1]!=a[i]){
			ex++;
			r = a[i];
		}
		if(i==n-1 || b[i+1]!=b[i]){
			ex++;
			r = b[i];
		}
		if(ex==2 && a[i]!=b[i]) res = 0;
		if(ex && r>ub) res = 0;
		if(ex) continue;
		(res*=ub)%=mod;
	}
	cout<<res<<endl;

	return 0;
}


Measured memory_bytes: 1792