akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size())  
#define rep(i, n) for(int i=0;i<n;i++)  
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 19;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

map <int, int> Mx;
vector <int> Vu;
int main() {
	int N, i;
	scanf("%d", &N);
	while (N--) {
		scanf("%d", &i);
		Mx[i]++;
	}
	for (auto it : Mx) for (i = 1; i <= it.second / 2; i++) Vu.push_back(it.first);
	sort(all(Vu));

	ll ans = 0;
	if (Vu.size() >= 2) ans = (ll)Vu.back() * Vu[Vu.size() - 2];
	return !printf("%lld\n", ans);
}

Measured memory_bytes: 4992
#include<stdio.h>

int main(void){
	int n,x,i,j,l,sum,com=0;
	while(1){
		scanf("%d %d",&n,&x);
		if((n==0)&&(x==0))break;
			for(i=1;i<=(n-2);i++){
				for(j=i+1;j<=(n-1);j++){
					for(l=j+1;l<=n;l++){
						if((i!=j)&&(j!=l)&&(l!=i))sum=i+j+l;
						if(sum==x)com=com+1;
					}
				}
			}
	printf("%d\n",com);
	com=0;
	}
	
	return 0;
}


Measured memory_bytes: 2096
#include <bits/stdc++.h>
#define ll long long int
#define mod 1000000007
#define pi 3.141592653589793
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define vfind(a, e) find(a.begin(), a.end(), e)
#define forr(i, n) for (ll i = 0; i < n; i++)
#define rfor(i, n) for (ll i = n - 1; i >= 0; i--)
#define fors(i, b, e, steps) for(ll i = b; i < e; i += steps)
#define rfors(i, e, b, steps) for(ll i = e; i > b; i -= steps)
#define mp make_pair
using namespace std;


bool isVowel(char c){
    return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u';
}

bool isLower(char c){
    return 97 <= c && c <= 122;
}

bool prime[1001];
void sieve() {
    fill(prime, prime + 1000, 1);
    prime[0] = prime[1] = 0;

    fors(i, 2, 1000, 1) {
        if (prime[i]) {
            fors(j, i * 2, 1000, i) prime[j] = 0;
        }
    }
}

bool f(int a, int b) {
    return a <= b;
}



int main() {
//    cout << setprecision(10);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);


    unordered_map<char, char> d;
    d['A'] = 'T';
    d['T'] = 'A';
    d['C'] = 'G';
    d['G'] = 'C';
    
    char c;
    cin >> c;
    cout << d[c];
    

}




Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a,b,c,d,e,i,l,x;
	scanf("%d %d %d %d %d",&a,&b,&c,&d,&e);
	i=a;
	if(b<i){
		i=b;
	}
	if(c<i){
		i=c;
	}
	l=d;
	if(e<l){
		l=e;
	}
	x=i+l-50;
	printf("%d\n",x);
	return 0;
}

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

LL solve(LL x) {
  if (x > 1) return 2 * solve(x / 2) + 1;
  else return 1;
}

int main() {
  LL h; cin >> h;

  cout << solve(h) << endl;
}


Measured memory_bytes: 256
/*
            _ _  ___            __ _ _  _       _     
 _   _  ___| | |/ _ \__      __/ _| | || |  ___| |__  
| | | |/ _ \ | | | | \ \ /\ / / |_| | || |_/ __| '_ \ 
| |_| |  __/ | | |_| |\ V  V /|  _| |__   _\__ \ | | |
 \__, |\___|_|_|\___/  \_/\_/ |_| |_|  |_| |___/_| |_|
 |___/                 

*/

#include <bits/stdc++.h>
using namespace std;
#define sz(x) (ll)(x).size()
#define trav(x) for(auto it: x)
#define all(x) x.begin(), x.end()
#define stp fixed<<setprecision(20)
#define db(x) cout<<#x<<": "<<x<<endl
#define tc ll tt; cin>>tt; while(tt--)
#define For(i, st, en) for(ll i=st; i<en; i++)
#define rFor(i, st, en) for(ll i=st; i>=en; i--)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define printv(x) For(i, 0, sz(x)){cout<<x[i]<<" ";} cout<<endl;
#define print2v(x) For(i, 0, sz(x)){For(j, 0, sz(x[0])){cout<<x[i][j]<<" ";} cout<<endl;}
#define ll long long
#define int long long
#define F first
#define S second
#define pb push_back
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector< vector<int> > vvi;
typedef vector< pair<int, int> > vpi;
#define endl '\n'
#define MAXN 300005
#define MOD 1000000007
#define INF 1000000000000000007


signed main(){
	fast
	int n;
	cin>>n;
	vi v(n);
	For(i, 0, n-1){
		cin>>v[i];
	}

	vi A(n, 0);
	A[0] = v[0];
	A[1] = v[0];
	For(i, 1, n-1){
		A[i+1] = v[i];
		if(v[i]<v[i-1]){
			A[i]=v[i];
		}
	}
	// printv(A);
	int ans=0;
	For(i, 0, n){
		ans+=A[i];
	}
	cout<<ans<<endl;
    return 0;
}
    



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int inf = 1000000000;

int main(){
    string s;
    cin >> s;
    for(int i=0; i<s.size(); i++){
        if(s[i] == '?'){
            s[i]='D';
        }
    }
    cout << s << endl;
}

Measured memory_bytes: 3756
n, m = map(int, input().split())
elec = []
for _ in range(m):
    elec.append([int(i) for i in input().split()])
p = [int(i) for i in input().split()]

num_cases = 0

for i in range(2 ** n):
    flag = 0
    num_on_e = 0
    for j, k in zip(elec, p):
        if flag:
            break
        else:
            switches = j[1:]
            num_on_switch = 0
            for s in switches:
                if i & (1 << s - 1):
                    num_on_switch += 1

            if num_on_switch % 2 == k:
                num_on_e += 1
            else:
                flag = 1
    if num_on_e == m:
        num_cases += 1
print(num_cases)

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

int main() {
  int n;
  cin >> n;
  vector<double> v(n);
  rep(i,n) cin >> v.at(i);
  sort(v.begin(), v.end());
  double ans = 0;
    rep(i,n-1) {
    ans = (v.at(i) + v.at(i+1)) / 2;
    v.at(i+1) = ans;
  }
  cout << fixed << setprecision(10) << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
#include<iomanip>
#include<functional>
#include<deque>

using namespace std;
typedef long long int ll;

#define C cout<<
#define E <<endl
#define CE cout<<endl
#define pb push_back

ll n,m,a,b,c,x,y,z,aa[200010],ab[200010],ac[2];
bool r,ra,rb,rc[200010];
string s,sa,sb,sc;
char ca,cb,cc,cd[1010][1010];
vector<ll> va,vb,vc,vd,ve,vaa,vbb;
double res;

int main(){
    cin>>n;
    res=1;
    a=0;b=0;
    for(int i=1;i<=n;i++){
        if(i%2)a++;
        else b++;
    }

    C double(a)/double(a+b) E;
    


}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

sub_num = dict()
for a in A:
    if a - 1 in sub_num:
        sub_num[a - 1] += 1
    else:
        sub_num[a - 1] = 1
        
for i in range(N):
    if i in sub_num:
        print(sub_num[i])
    else:
        print(0)

Measured memory_bytes: 38744
#include <bits/stdc++.h>
#ifdef HIRO
#define d(f_, ...) printf((f_), ##__VA_ARGS__)
#else
#define d(f_, ...)
#endif

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector< pair<int, int> > vii;
typedef vector< pair<long long, long long> > vllll;
typedef map<int, int> mii;
typedef map<long long, long long> mllll;
typedef queue<int> qi;
typedef queue< pair<int, int> > qp;
#define mp make_pair
#define pi 3.14159265358979323846
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
#define gt(T) greater<T>()
#define sum(v) accumulate(v.begin(), v.end(), 0)
#define uni(v) do{ \
  sort(v.begin(), v.end()); \
  decltype(v)::iterator result = unique(v.begin(), v.end()); \
  v.erase(result, v.end()); \
}while(0)
#define fi(init, n) for(int i = init; i < n; ++i)
#define fj(init, n) for(int j = init; j < n; ++j)
#define fk(init, n) for(int k = init; k < n; ++k)
#define zero(x) memset(x, 0, sizeof(x))
#define negative(x) memset(x, ~0, sizeof(x))
#define bitsum(x) __builtin_popcount(x)
const ll MOD = 1e9 + 7;
const int INF = 1e9;
const int di[] = { 0, 1, 0, -1 };
const int dj[] = { 1, 0, -1, 0 };

template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a * b / gcd(a, b);
}
template<typename T>
int finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) return 1;
	else return 0;
}
ll frac(ll n){
	if (n == 0) return 1;
	return (n * frac(n - 1)) % MOD;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main(int argc, char** argv) {
#ifdef HIRO
  string quiz(argv[1]);
  string id(argv[2]);
  string filename("input/" + quiz + "/" + id + ".txt");
  ifstream fin(filename);
  if (fin.peek() == ifstream::traits_type::eof()) {
    cout << "No input.";
    return 0;
  }
  ifstream cin(filename);
  std::cin.rdbuf(cin.rdbuf());
#endif
  ll ans;
  ll n, a, b;
  cin >> n;
  // ll n, m;
  // cin >> n >> m;
  // ll n, m, k;
  // cin >> n >> m >> k;
  int arr[n];
  fi(0, n) {
    cin >> arr[i];
  }
  a = arr[0];
  b = accumulate(arr + 1, arr + n, 0ll);
  ans = abs(a - b);
  fi(1, n - 1) {
    a += arr[i];
    b -= arr[i];
    chmin(ans, abs(a - b));
  }
  cout << ans << endl;
  return 0;
}



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

using namespace std;

#define N_CONTEST   (26)
#define N_DAY       (365)

static void get_input (int &D, vector<int> &c, vector<vector<int>> &s) {
    cin >> D;
    assert(D == N_DAY);
    for ( int i = 1; i <= N_CONTEST; i++ ) {
        cin >> c.at(i);
    }
    for ( int i = 1; i <= N_DAY; i++ ) {
        for ( int j = 1; j <= N_CONTEST; j++ ) {
            cin >> s.at(i).at(j);
        }
    }
}

static long long calc_score (vector<int> &c, vector<vector<int>> &s, vector<int> &t) {
    vector<int> last(N_CONTEST+1, 0);

    long long score = 0;

    for ( int d = 1; d <= N_DAY; d++ ) {
        score += s.at(d).at(t.at(d));
        last.at(t.at(d)) = d;
        for ( int con = 1; con <= N_CONTEST; con++ ) {
            score -= c.at(con) * (d - last.at(con));
        }
        cout << score << endl;
    }

    return score;
}

int main (void) {
    int D;
    vector<int> c(N_CONTEST+1);
    vector<vector<int>> s(N_DAY+1, vector<int>(N_CONTEST+1, 0));

    get_input(D, c, s);

//    for ( int i = 0; i < N_DAY; i++ ) {
//        cout << i % 26 + 1 << endl;
//    }

    vector<int> t(N_DAY+1, 0);
    for ( int i = 1; i <= N_DAY; i++ ) {
        cin >> t.at(i);
    }

    calc_score(c, s, t);

    return 0;
}


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

int main(){
    int n;
    string s;
    cin >> n >> s;
    string t;
    t.push_back(s[0]);
    for(int i=1;i<n;++i){
        if(t.back() != s[i]) t.push_back(s[i]);
    }
    cout << t.size() << endl;
    
    return 0;
}

Measured memory_bytes: 512
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<set>
#include<vector>
#include<cstring>
#define INF 1000000000
using namespace std;
int main(){
    int a,b,c,d,time=0;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    while(a>0&&c>0){
        if(time%2==0)
            c-=b;
        else
            a-=d;
        time++;
    }
    if(a>0)
        cout<<"Yes";
    else
        cout<<"No";
    
    
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define rep(i,s,n) for(int i=s;i<n;i++)
#define pb push_back
#define all(x) (x).begin(),(x).end()
using namespace std;
using P=pair<int,int>;
using G=vector<vector<int>>;
using ll=long long;




int main(){
    int h,w; cin>>h>>w;
    char a[h+2][w+2];
    rep(i,0,w+2) a[0][i]='#';
    rep(i,0,w+2) a[h+1][i]='#';

    rep(i,0,h){
        a[1+i][0]='#';
        a[1+i][w+1]='#';
        rep(j,0,w) cin>>a[1+i][1+j];
    }

    rep(i,0,h+2){
        rep(j,0,w+2){
            cout<<a[i][j];
        }
        cout<<endl;
    }

}/*
        bool able=true;
        string num=to_string(i);
        for(int j=0;j<m;j++){
            if(s[i]>n){
                able=false;
                break;
            }
            if(num[s[i]-1]!=c[i]){
                able=false;
                break;
            }
        }

        if(able){
            cout<<i<<endl;
            return 0;
        }
    }

    cout<<-1<<endl;
}*/


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

using namespace std;

int main() {

	while (1) {
		int n;
		cin >> n;

		if (n == 0) { return 0; }

		vector<struct tm> tms(n);
		vector<struct tm> tme(n);

		string in1, in2;

		vector<int> jikoku(86401);

		for (int i = 0; i < n; i++) {
			cin >> in1 >> in2;

			tms[i].tm_year = 70;
			tms[i].tm_mon = 0;
			tms[i].tm_mday = 1;
			tms[i].tm_hour = stoi(in1.substr(0, 2)) + 9;
			tms[i].tm_min = stoi(in1.substr(3, 2));
			tms[i].tm_sec = stoi(in1.substr(6, 2));

			tme[i].tm_year = 70;
			tme[i].tm_mon = 0;
			tme[i].tm_mday = 1;
			tme[i].tm_hour = stoi(in2.substr(0, 2)) + 9;
			tme[i].tm_min = stoi(in2.substr(3, 2));
			tme[i].tm_sec = stoi(in2.substr(6, 2));


			jikoku[mktime(&tms[i])]++;
			jikoku[mktime(&tme[i])]--;

		}

		int res = 0;
		int resmax = 0;
		for (int i = 0; i < 86401; i++) {
			res += jikoku[i];
			resmax = max(resmax, res);
		}

		cout << resmax << endl;
	}
	return 0;
}


Measured memory_bytes: 4640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)
#define RREP(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define ALL(v) (v).begin(), (v).end()
template<class T>
using reverse_priority_queue = priority_queue<T, vector<T>, greater<T>>;


int main(){
    ll n;
    cin >> n;
    ll ans = (n + 1) * n / 2;
    for(ll l = 1; l <= n; ++l){
        ans += (n - l + 1) * (n + l) / 2;
        ans -= l * (n - l + 1);
    }

    REP(i, n - 1){
        ll ui, vi;
        cin >> ui >> vi;
        if(ui > vi){
            swap(ui, vi);
        }
        ans -= ui * (n - vi + 1);
    }

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


Measured memory_bytes: 3524
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int X = scan.nextInt();
        int div500 = X/500;
        X = X - 500*div500;
        int div5 = X/5;
        System.out.println(1000*div500+5*div5);
    }
}

Measured memory_bytes: 23892
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();

        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] a = new int[n];

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

        PrintWriter pw = new PrintWriter(System.out);
        int t = 0;
        for (int i = k; i < n; i++) {
            if (a[t] < a[i])
                pw.println("Yes");
            else
                pw.println("No");
            t++;
        }

        pw.flush();
    }

    static class MyScanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}

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

// template {{{
#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); (i) += 1)
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); (i) -= 1)

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

// constexpr i32 mod   = 998244353;
constexpr i32 mod   = 1e9 + 7;
constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

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

struct IoSetup { IoSetup(int x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }

template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// }}}

void solver() {
    i64 a, v, b, w, t;
    cin >> a >> v >> b >> w >> t;

    if (v <= w) {
        cout << "NO" << endl;
        return;
    }

    if (abs(a - b) <= t * (v - w)) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

signed main(int argc, char *argv[]) {
    solver();
}


Measured memory_bytes: 3664
def actual(s):
    odd_steps = set(s[::2])
    even_steps = set(s[1::2])

    cond1 = odd_steps.issubset({'U', 'D', 'R'})
    cond2 = even_steps.issubset({'U', 'D', 'L'})

    if cond1 and cond2:
        return 'Yes'

    return 'No'

s = input()

print(actual(s))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(int)(a); i++)
typedef long long ll;

int main()
{
  ll n; cin >> n;
  vector<ll> a(n+1);
  rep(i, n+1) cin >> a[i];
  vector<ll> b(n);
  rep(i, n) cin >> b[i];

  ll ans = 0;
  rep(i, n) {
    ans += min(a[i], b[i]);
    b[i] = max(0LL, b[i]-a[i]);
    ans += min(a[i+1], b[i]);
    a[i+1] = max(0LL, a[i+1]-b[i]);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
using namespace std;

int main() {
  int N, R;
  cin >> N >> R;
  int ans;
  if (N < 10) {
    ans = R + 100 * (10 - N);
  } else {
    ans = R;
  }

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


Measured memory_bytes: 256
N,M,C = map(int,input().split())
B = list(map(int,input().split()))

cnt = 0
for i in range(N):
  A = list(map(int,input().split()))
  AB = 0
  for j in range(M):
    AB += A[j] * B[j]
  if AB + C > 0:
    cnt += 1
    
print(cnt)

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

int sqd(vector<int> a, vector<int> b, int d)
{
    int res = 0;
    for (int i = 0; i < d; i++)
    {
        res += pow(a[i] - b[i], 2);
    }
    return res;
}

bool sq_check(int n)
{
    int sqr = sqrt(n);
    if (pow(sqr, 2) == n)
        return true;
    else
        return false;
}

int main()
{
    int n, d;
    cin >> n >> d;
    vector<vector<int>> x(n, vector<int>(d));
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < d; j++)
        {
            cin >> x[i][j];
        }
    }

    int res = 0;
    for (int i = 0; i < n - 1; i++)
    {
        for (int j = i + 1; j < n; j++)
        {
            int dist = sqd(x[i], x[j], d);
            if (sq_check(dist) == true)
                res++;
        }
    }

    cout << res << endl;
}

Measured memory_bytes: 3672
import sys
input=sys.stdin.buffer.readline
q=int(input())
from heapq import heapify, heappop, heappush
L=[]
R=[]
s=0
ans=0
c=0
l,r=-10**10,10**10
for i in range(q):
    j=tuple(map(int ,input().split()))
    if j[0]==1:
        x,y=j[1],j[2]
        s+=1
        ans+=y
        if not(l<=x<=r):ans+=min(abs(l-x),abs(r-x))
        if s==1:
            heappush(L,-x)
            l,r=x,x
        elif s%2:
            if -L[0]>=x:
                heappush(L,-x)
                l,r=-L[0],-L[0]
            else:
                heappush(R,x)
                l=heappop(R)
                r=l
                heappush(L,-l)
        else:
            if -L[0]<=x:
                heappush(R,x)
            else:
                heappush(L,-x)
                heappush(R,-heappop(L))    
            l,r=-L[0],R[0]
    else:
        print(l,ans)
        #continue


Measured memory_bytes: 11284
/* C++標準ヘッダファイル */
/* 文字列ライブラリ */
#include <string>

/* コンテナライブラリ */
#include <array>
#include <vector>
#include <deque>
#include <list>
#include <forward_list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>

/* アルゴリズムライブラリ */
#include <algorithm>

/* 数値演算ライブラリ */
#include <cmath>
#include <math.h>

/* 入出力ライブラリ */
#include <iostream>

/* std使用<-namespace */
using namespace std;

/* define */
#define rpt(i, n) for(ll i = 0; i < (n); i++)  // リピート
#define PI (acos(-1))  // 円周率pi

/* typedef */
// long long
typedef long long ll;

// pair
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
typedef pair<double, double> d_d;


/* main関数 */
int main(void) {
	int n;
	cin >> n;
	vector<int> l;
	l.reserve(n);
	rpt(i, n) {
		int e;
		cin >> e;
		l.push_back(e);
	}
	sort(l.begin(), l.end());
	ll count = 0;
	for (int i = 0; i < n - 2; i++) {
		for (int j = i + 1; j < n - 1; j++) {
			for (int k = j + 1; k < n; k++) {
				if (l[i] + l[j] <= l[k]) break;
				else count++;
			}
		}
	}
	cout << count;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[4];
    if(n<1000||n>=10000){cout<<"No"<<endl;exit(0);}
    for(int i=0;i<4;i++)
    {
        a[i]=n%10;
        n/=10;
    }
    if(a[1]!=a[2]){cout<<"No"<<endl;exit(0);}
    if(a[0]!=a[1]&&a[2]!=a[3]){cout<<"No"<<endl;exit(0);}
    cout<<"Yes"<<endl;
return 0;
}


Measured memory_bytes: 256
import collections

def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)
    
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

a, b = list(map(int,(input().split())))
d = gcd(a, b)
c = collections.Counter(prime_factorize(d))
print(len(c)+1)

Measured memory_bytes: 3316
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

static class Program
{
    class Modular
    {
        private const int M = 1000000007;
        private long value;
        public Modular(long value) { this.value = value; }
        public static implicit operator Modular(long a)
        {
            var m = a % M;
            return new Modular((m < 0) ? m + M : m);
        }
        public static Modular operator +(Modular a, Modular b)
        {
            return a.value + b.value;
        }
        public static Modular operator -(Modular a, Modular b)
        {
            return a.value - b.value;
        }
        public static Modular operator *(Modular a, Modular b)
        {
            return a.value * b.value;
        }
        public static Modular Pow(Modular a, int n)
        {
            switch (n)
            {
            case 0:
                return 1;
            case 1:
                return a;
            default:
                var p = Pow(a, n / 2);
                return p * p * Pow(a, n % 2);
            }
        }
        public static Modular operator /(Modular a, Modular b)
        {
            return a * Pow(b, M - 2);
        }
        private static readonly List<int> facs = new List<int> { 1 };
        private static Modular Fac(int n)
        {
            for (int i = facs.Count; i <= n; ++i)
            {
                facs.Add((int)(Math.BigMul(facs.Last(), i) % M));
            }
            return facs[n];
        }
        public static Modular Ncr(int n, int r)
        {
            return (n < r) ? 0
                 : (n == r) ? 1
                            : Fac(n) / (Fac(r) * Fac(n - r));
        }
        public static explicit operator int(Modular a)
        {
            return (int)a.value;
        }
    }

    static Dictionary<int, int> Factorize(int a)
    {
        var dict = new Dictionary<int, int>();
        for (int i = 2; i <= 1000 && a > 1; ++i)
        {
            int cnt = 0;
            while ((a % i) == 0)
            {
                a /= i;
                ++cnt;
            }
            if (cnt > 0) { dict[i] = cnt; }
        }
        if (a > 1) { dict[a] = 1; }
        return dict;
    }

    static int Solve(int N, int[] A)
    {
        var dict = new Dictionary<int, int>();
        foreach (var b in Array.ConvertAll(A, Factorize))
        {
            foreach (var pair in b)
            {
                if (!dict.ContainsKey(pair.Key) || dict[pair.Key] < pair.Value)
                {
                    dict[pair.Key] = pair.Value;
                }
            }
        }
        var lcm = new Modular(1);
        foreach (var pair in dict)
        {
            lcm *= Modular.Pow(pair.Key, pair.Value);
        }
        var sum = new Modular(0);
        foreach (var a in A)
        {
            sum += lcm / a;
        }
        return (int)sum;
    }

    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        var A = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        Console.WriteLine(Solve(N, A));
    }
}


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

using namespace std;

#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

using ll = long long;
int N;
ll f(vector<int> a, int cnt) {
    vector<int> vec1(a.begin(), a.begin() + N + cnt);
    vector<int> vec2(a.begin() + N + cnt, a.end());
    sort(all(vec1));
    sort(all(vec2));
    ll s = 0;
    rep(i, vec1.size()) if (cnt <= i) s += vec1[i];
    // cout << vec1.size() << ", " << vec2.size() << ": " << s << endl;
    rep(i, vec2.size() - (N - cnt)) s -= vec2[i];
    // cout << vec1.size() << ", " << vec2.size() << ": " << s << endl;
    return s;
}
vector<ll> f2(const vector<int> &a, int m) {
    priority_queue<int> que;
    rep(i, N) que.push(m * a[i]);
    vector<ll> s(N + 1);
    rep(i, N) s[0] += a[i];
    rep(i, N) {
        que.push(m * a[i + N]);
        int t = que.top();
        que.pop();
        s[i + 1] = s[i] - m * t + a[i + N];
    }
    return s;
}
int main() {
    vector<int> a;
    cin >> N;
    a.resize(3 * N);
    rep(i, 3 * N) cin >> a[i];
    vector<ll> s1 = f2(a, -1);
    reverse(all(a));
    vector<ll> s2 = f2(a, 1);
    ll ans = -1e18;

    reverse(all(s2));
    // rep(i, s1.size()) cout << s1[i] << ", " << s2[i] << endl;
    rep(i, s1.size()) ans = max(ans, s1[i] - s2[i]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3832
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
  static InputReader in;
  static PrintWriter out;

  static class Solution {
    void solve() throws IOException {
       while (true) {
    	   int a = in.nextInt();
    	   String op = in.next();
    	   int b = in.nextInt();
    	   if (op.equals("?")) break;
    	   
    	   switch (op) {
    	   	case "+":
    	   		out.println(a+b);
    	   		break;
    	   	case "-":
    	   		out.println(a-b);
    	   		break;
    	   	case "*":
    	   		out.println(a*b);
    	   		break;
    	   	case "/":
    	   		out.println(a/b);
    	   		break;	
    	    default:
    	    	break;
    	   }
       }
  }
}
    
  public static void main(String[] args) throws IOException {
    in = new InputReader(System.in);
    out = new PrintWriter(System.out);
    Solution solver = new Solution();
    solver.solve();
    out.close();
}

  static class InputReader {
    public BufferedReader br;
    public StringTokenizer st;

    public InputReader(InputStream stream) {
      br = new BufferedReader(new InputStreamReader(stream));
    }

    public int nextInt() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return Integer.parseInt(st.nextToken());
    }

    public long nextLong() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return Long.parseLong(st.nextToken());
    }

    public String next() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return st.nextToken();
    }

    public double nextDouble() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return Double.parseDouble(st.nextToken());
    }

  }

}

Measured memory_bytes: 24524
#include "bits/stdc++.h"

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

string solve(string s){
    
    rep(i,s.size()-5+1){
        if(s.substr(i,5)=="apple")s.replace(i,5,"peach");
        else if(s.substr(i,5)=="peach")s.replace(i,5,"apple");
    }
    return s;
}



int main(){
    string s;
    getline(cin,s);
    
    cout<<solve(s)<<endl;
    
    return 0;
}

Measured memory_bytes: 1184
PN = [i for i in range(100001)]
i = 2
while True:
    if i >= len(PN):
        break
    j = i * 2
    while True:
        if j >= len(PN):
            break
        PN[j] = 0
        j += i
    while True:
        i += 1
        if i >= len(PN):
            break
        if PN[i] != 0:
            break
PN[1] = 0
PN_2 = [0]
DPN = [0]
for i in range(1, 100001):
    if PN[i] != 0 and PN[int((PN[i] + 1) / 2)] != 0:
        PN_2.append(PN[i])
        DPN.append(DPN[i - 1] + 1)
    else:
        PN_2.append(0)
        DPN.append(DPN[i - 1])

#print(PN[1:30])
#print(PN_2[1:30])
#print(DPN[1:30])

Q = int(input())
lr = []
for i in range(Q):
    cnt = 0
    l, r = map(int, input().split())
    print(DPN[r] - DPN[l - 1])
    

Measured memory_bytes: 9068
#include <bits/stdc++.h>
#define sp ' '
#define nyan "(=^・ω・^=)"
#define mkp make_pair
#define intmax 2147483647
#define llmax 9223372036854775807
#define lP pair<ll,ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;
const int mod = 1000000007;
const int mod998 = 998244353;

int A, B, C;

int main() {
	cin >> A >> B >> C;
	if (A == 5 && B == 5 && C == 7 || A == 5 && B == 7 && C == 5 || A == 7 && B == 5 && C == 5) {
		puts("YES");
	}
	else {
		puts("NO");
	}
//	cout << "cout" << 12345 << endl;
}

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

using namespace std;

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

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

    double x;
    string u;
    double ans = 0.00000;
    REP(0, i, N) {
        cin >> x >> u;

        if (u == "BTC") {
            ans += x * 380000.0;
        } else {
            ans += x;
        }
    }

    printf("%.5f\n", ans);

    return 0;
}


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

using namespace std;

#define REP(i, n)   for(int i = 0; i < (n); i++)
#define REPS(i, n)  for(int i = 1; i <= (n); i++)
#define RREP(i, n)  for(int i = (n)-1; i >= 0; i--)
#define RREPS(i, n) for(int i = (n); i > 0; i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

using ll  = long long;
using pi  = pair<int, int>;
using pl  = pair<ll, ll>;
using vi  = vector<int>;
using vl  = vector<ll>;
using vs  = vector<string>;
using vb  = vector<bool>;
using vvi = vector<vi>;
using vvl = vector<vl>;

const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e9 + 7;
const ll  INFL = 1e18;
const double PI = 3.141592653589793;
const double EPS = 1e-9;

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

vl node;

ll root(ll x)
{
    if(node[x] == x) return x;
    return node[x] = root(node[x]);
}

void unite(ll x, ll y)
{
    ll rx = root(x);
    ll ry = root(y);
    node[rx] = ry;
}

bool same(ll x, ll y)
{
    return root(x) == root(y);
}

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    ll N; cin >> N;
    node.resize(N); REP(i, N) node[i] = i;
    vector<pl> x(N), y(N);
    REP(i, N)
    {
        cin >> x[i].first;
        x[i].second = i;
        cin >> y[i].first;
        y[i].second = i;
    }
    sort(ALL(x));
    sort(ALL(y));

    vector<tuple<ll, ll, ll>> edge;
    REP(i, N-1)
    {
        edge.push_back(mt(x[i+1].first - x[i].first, x[i].second, x[i+1].second));
        edge.push_back(mt(y[i+1].first - y[i].first, y[i].second, y[i+1].second));
    }
    sort(ALL(edge));

    ll ans = 0;
    REP(i, (int)edge.size())
    {
        ll cost, a, b;
        tie(cost, a, b) = edge[i];

        if(!same(a, b))
        {
            ans += cost;
            unite(a, b);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 13384
#include <bits/stdc++.h>
#include <atcoder/dsu>
using namespace std;
using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define rep_rev(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll t1,t2,t3;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;

int main(){
    ll n,q;
    cin >> n >> q;
    dsu uf(n);
    rep(i,q){
        cin >> t1 >> t2 >> t3;
        if(t1 == 0){
            uf.merge(t2,t3);
        }else{
            cout << uf.same(t2,t3) << endl;;
        }
    }
}

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

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(obj) obj.begin(), obj.end()

const int iINF = 1e9;
const long long llINF = 1e18;
const int MOD = 1e9 + 7;

using namespace std;

template <typename T>
int getFormer(const vector<T> &vec, T x) {
    return upper_bound(vec.begin(), vec.end(), x) - vec.begin() - 1;
}

template <typename T>
int getLatter(const vector<T> &vec, T x) {
    return lower_bound(vec.begin(), vec.end(), x) - vec.begin();
}

long long power(long long n, long long p, long long mod) {
    if (p == 0)
        return 1;
    else if (p & 1) {
        return ((n * power(n, p - 1, mod)) % mod);
    } else {
        long long res = power(n, p / 2, mod);
        return ((res * res) % mod);
    }
}

int main() {
    int m, n;
    cin >> m >> n;
    cout << power(m, n, MOD) << endl;
    return 0;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)

using namespace std;
int K, S, T;

int main(void){
	//IO("test.in", "test.out");
	scanf("%d%d", &K, &S);
	for(int i = 0; i <= K && i <= S; i++)
		for(int j = 0; j <= K && i + j <= S; j++)
			if(S - i - j <= K) T++;
	printf("%d\n", T);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
vector<pii> edge;
int main(){
    int n, k;
    scanf("%d%d", &n, &k);
    if(k > (n-1)*(n-2)/2) printf("-1\n");
    else{
        edge.push_back(pii(1, 2));
        int sum = 0, cnt = 1, j = -1;
        for(int i=3;i<=n;i++){
            if(sum+cnt > k){
                j = i;
                break;
            }
            edge.push_back(pii(1, i));
            sum += cnt;
            cnt++;
        }
        if(j != -1){
            if(sum < k){
                sum += cnt;
                edge.push_back(pii(1, j));
                j++;
            }
            int x = 2;
            while(sum > k){
                edge.push_back(pii(x, j-1));
                sum--;
                x++;
            }

            for(int i=j;i<=n;i++){
                for(int k=1;k<i;k++){
                    edge.push_back(pii(k, i));
                }
            }
        }

        printf("%d\n", edge.size());
        for(int i=0;i<edge.size();i++){
            printf("%d %d\n", edge[i].first, edge[i].second);
        }
    }
}

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

#define loop(s, e, i) for (int i = s; i < e; ++i)
#define print(s) cout << s << endl;
#define DIV 1000000007
#define ll long long
using namespace std;

/*
浮動小数点の入力
cout << fixed << setprecision(9) << endl;
*/

int main() {
  int N, K;
  cin >> N >> K;
  vector<ll> A(N);

  loop(0, N, i) cin >> A[i];
  
  ll leastcost = -1;
  for (int bit=0; bit<(1<<N); bit++) {
    int valid = 0;
    vector<ll> D(N);
    for (int i=0; i<N; i++) {
      if (bit&(1<<i)) {
        D[i] = 1;
        valid++;
      }
    }
    if (valid != K) continue;

    ll cost = 0;
    ll maxsize = 0;
    loop(0, N, i) {
      if (D[i] == 0){
        maxsize = max(maxsize, A[i]);
        continue;
      } 

      if (A[i] <= maxsize) {
        cost += maxsize - A[i] + 1;
        maxsize = maxsize+1;
      } else {
        maxsize = A[i];
      }
    }
    if (leastcost == -1 || leastcost > cost) leastcost = cost;
  }
  print(leastcost);
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define ll long long
#define PI 3.141592653589
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define EPS 1e-7
#define f first
#define s second
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;
const ll MOD = 1e9+7;
const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int random_int(int l,int r){return uniform_int_distribution<int>(l,r)(rng);}
ll fast_power(ll x, ll p){
    ll res = 1;
    while(p > 0){
        if(p & 1){
            res = (res * x);
        }
        p = p >> 1;
        x = (x*x);
    }
    return res;
}

int n; double p[3005];
double dp[3005][3005];
int main() {
    IO;
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> p[i];
    dp[0][0] = (1 - p[0]);
    dp[0][1] = p[0];
    for (int i = 1; i < n; i++) {
        for (int j = 0; j <= n; j++) {
            dp[i][j] = dp[i - 1][j] * (1 - p[i]);
            if (j) {
                dp[i][j] += dp[i - 1][j - 1] * p[i];
            }
        }
    }
    double ans = 0;
    int start = n&1?(n/2)+1:n/2;
    for (int i = start; i <= n; i++)
        ans += dp[n - 1][i];
    cout << setprecision(10) << ans;
    return 0;
}


Measured memory_bytes: 70656
h,w = map(int, input().split())
f = [list(input()) for _ in range(h)]
for k in range(h):
    for l in range(w):
        if f[k][l] == ".":
            c = 0
            for i in range(-1,2):
                for j in range(-1,2):
                    xi,yi = k+i,l+j
                    #xi,yiが範囲内で水溜りなら
                    if 0 <= xi < h  and 0 <= yi < w and f[xi][yi] == "#":
                        c += 1
            f[k][l] = str(c)

for m in range(h):
    print(''.join(f[m]))

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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

constexpr int64 P = 1000000007;

struct FiniteField {
 private:
  int64 x;
 public:
  FiniteField(int64 x) : x(x) {
    if (x > P || x < 0) { cerr << "Invalied FiniteField!" << endl; exit(1); }
  }
  FiniteField() : x(0) {}
  int64 Value() const { return x; }
  inline FiniteField operator+(FiniteField o) const {
    FiniteField r(*this); r += o; return r;
  }
  inline FiniteField operator-(FiniteField o) const {
    FiniteField r(*this); r -= o; return r;
  }
  inline FiniteField operator* (FiniteField o) const {
    FiniteField r(*this); r *= o; return r;
  }
  inline FiniteField operator/ (FiniteField o) const {
    FiniteField r(*this); r /= o; return r;
  }
  inline void operator+= (FiniteField o) { x = (x + o.x) % P; }
  inline void operator-= (FiniteField o) { x = (x + P - o.x) % P; }
  inline void operator*= (FiniteField o) { x = (x * o.x) % P; }
  void operator/=(FiniteField o) {
    int64 p = P - 2; while (p) { if (p % 2) { *this *= o; } o *= o; p /= 2; }
  }
};

FiniteField Solve() {
  int h, w;
  cin >> h >> w;
  vector<int> v_to_r(h * w + 1, -1);
  vector<int> v_to_c(h * w + 1, -1);
  vector<int> rs(h);
  vector<int> cs(w);
  for (int i = 0; i < h; i++) {
    cin >> rs[i];
    if (v_to_r[rs[i]] >= 0) return 0;
    v_to_r[rs[i]] = i;
  }
  for (int i = 0; i < w; i++) {
    cin >> cs[i];
    if (v_to_c[cs[i]] >= 0) return 0;
    v_to_c[cs[i]] = i;
  }

  FiniteField ans = 1;
  int r_count = 0;
  int c_count = 0;
  for (int x = h * w; x >= 1; x--) {
    int r = v_to_r[x];
    int c = v_to_c[x];

    if (r >= 0 && c >= 0) {
      r_count++;
      c_count++;
    } else if (r >= 0) {
      ans *= c_count;
      r_count++;
    } else if (c >= 0) {
      ans *= r_count;
      c_count++;
    } else {
      int m = r_count * c_count - (h * w - x);
      if (m <= 0) return 0;
      ans *= m;
    }
  }
  return ans;
}

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

  cout << Solve().Value() << endl;
}

Measured memory_bytes: 8064
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>
#include<string.h>
#include<math.h>

typedef int32_t i32;
typedef int64_t i64;

const i32 mod = 1000000007;

i32 inv (i32 a) {
  i32 t = 1;
  while (a > 1) {
    t = (i64) t * (mod - mod / a) % mod;
    a = mod % a;
  }
  return t;
}

i32 modPow(i32 r, i32 n) {
  i32 t = 1;
  i32 s = r;
  while (n > 0) {
    if (n&1) t = (i64) t * s % mod;
    s = (i64) s * s % mod;
    n >>= 1;
  }
  return t;
}

i32 *fact = NULL;
i32 *iFact = NULL;
void init(const i32 n) {
  fact = (i32 *) calloc (n + 1, sizeof (i32));
  fact[0] = 1;
  for (i32 i = 1; i <= n; ++i) {
    fact[i] = (i64) i * fact[i - 1] % mod;
  }
  iFact = (i32 *) calloc (n + 1, sizeof (i32));
  iFact[n] = inv(fact[n]);
  for (i32 i = n - 1; i >= 0; --i) {
    iFact[i] = (i64) iFact[i + 1] * (i + 1) % mod;
  }
}

i32 comb (i32 n, i32 k) {
  if (!(0 <= k && k <= n)) return 0;
  return (i64) fact[n] * iFact[k] % mod * iFact[n - k] % mod;
}

void run (void) {
  i32 b, w;
  scanf ("%" SCNi32 "%" SCNi32, &b, &w);
  init(b + w);
  i32 l = 0;
  i32 r = 0;
  const i32 p = inv(2);
  for (i32 i = 1; i <= b + w; ++i) {
    printf ("%" PRIi64 "\n", (((i64)2 * mod + 1 - r - l) * p + l) % mod);
    if (i >= w) {
      l = (l + (i64)comb (i - 1, w - 1) * modPow (p, i)) % mod;
    }
    if (i >= b) {
      r = (r + (i64)comb (i - 1, b - 1) * modPow (p, i)) % mod;
    }
  }
}

int main (void) {
  run ();
  return 0;
}


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

using namespace std;
using ll = long long;
const ll inf = 1e18 + 1;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  vector<ll> pre(n);  
  for(int i = 0; i < n; i++) cin >> a[i];
  pre[0] = a[0];
  for(int i = 1; i < n; i++) pre[i] = pre[i - 1] + a[i];  
  vector<vector<ll>> dp(n, vector<ll> (n, inf));
  for(int L = n - 1; L >= 0; L--) {
    for(int R = L; R < n; R++) {
      if(L == R) dp[L][R] = 0;
      else if(R == L + 1) dp[L][R] = a[L] + a[R];
      else {
        ll sum = pre[R] - (L == 0 ? 0 : pre[L - 1]);
        int ff = R - L + 1;
        for(int len = 1; len < ff; len++) {          
          dp[L][R] = min(dp[L][R], dp[L][L + len - 1] + dp[L + len][R] + sum);               
        }
      }
    }
  }  
  cout << dp[0][n - 1] << '\n';
  return 0;
}


Measured memory_bytes: 4516
#include <string>
#include <cstring>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

char m[14][9];

void dfs(int i, int j, vector<pair<int,int> >&v, vector<pair<int,int> >&w){
  v.push_back(make_pair(i,j));
  if(m[i-1][j]==m[i][j]&&find(v.begin(),v.end(),make_pair(i-1,j))==v.end())dfs(i-1,j,v,w);
  if(m[i+1][j]==m[i][j]&&find(v.begin(),v.end(),make_pair(i+1,j))==v.end())dfs(i+1,j,v,w);
  if(m[i][j-1]==m[i][j]&&find(v.begin(),v.end(),make_pair(i,j-1))==v.end())dfs(i,j-1,v,w);
  if(m[i][j+1]==m[i][j]&&find(v.begin(),v.end(),make_pair(i,j+1))==v.end())dfs(i,j+1,v,w);
  if(m[i-1][j]=='O'&&find(w.begin(),w.end(),make_pair(i-1,j))==w.end())w.push_back(make_pair(i-1,j));
  if(m[i+1][j]=='O'&&find(w.begin(),w.end(),make_pair(i+1,j))==w.end())w.push_back(make_pair(i+1,j));
  if(m[i][j-1]=='O'&&find(w.begin(),w.end(),make_pair(i,j-1))==w.end())w.push_back(make_pair(i,j-1));
  if(m[i][j+1]=='O'&&find(w.begin(),w.end(),make_pair(i,j+1))==w.end())w.push_back(make_pair(i,j+1));
}

void main2(){
  int i,j,k,r=0,f;
  memset(m,'X',sizeof(m)); //Iron Puyo
  for(i=1;i<13;i++)scanf("%s",m[i]+1);
  for(i=0;i<14;i++)m[i][7]='X',m[i][8]=0;
  for(i=1;i<7;i++)m[0][i]='.';
  for(;;){
    f=0;
    vector<pair<int,int> >v,w;
    for(i=1;i<13;i++)
      for(j=1;j<7;j++){
        if(m[i][j]=='R'||m[i][j]=='G'||m[i][j]=='B'||m[i][j]=='Y'||m[i][j]=='P'){
          dfs(i,j,v,w);
          if(v.size()>3){
            f=1;
            for(k=0;k<v.size();k++)
              m[v[k].first][v[k].second]='.';
            for(k=0;k<w.size();k++)
              m[w[k].first][w[k].second]='.';
          }
          v.clear(),w.clear();
        }
      }
    if(f){
      for(j=1;j<7;j++)
        for(i=12;i;i--){
          for(k=i;k&&m[k][j]=='.';k--);
          swap(m[i][j],m[k][j]);
        }
      r++;
      continue;
    }
    break;
  }
  printf("%d\n",r);
}
main(){int n;for(scanf("%d",&n);n;n--)main2();}

Measured memory_bytes: 0