akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"


int main() {
	while (1) {
		int p, n; cin >> p >> n;
		if (!p)break;
		pair<int, int>minp, maxp;
		ld minsa = 1e9, maxsa = 1e9;
		for (long long int bo = 1; bo <= n; ++bo) {
			ld num = sqrt(ld(bo*bo) * p);
			for (int si = max(1, int(num - 2)); si <= min(n, int(num + 1)); ++si) {
				if (si*si < bo*bo*p) {
					if (minsa >sqrt(p)-ld(si)/bo ) {
						minp = (make_pair(si, bo));
						minsa = sqrt(p) - ld(si) / bo;
					}
				}
				else if (si*si > bo*bo*p) {
					if (maxsa > ld(si) / bo - sqrt(p)) {
						maxp = make_pair(si, bo);
						maxsa = ld(si) / bo - sqrt(p);
					}
				}
			}
		}
		cout << maxp.first << "/" << maxp.second << " " << minp.first << '/' << minp.second << endl;
	}
	return 0;
}

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

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

ll mod = (ll)(1e9+7);

const ll MAX_V = 100000;

struct UnionFind{
    vector<ll> d;
    UnionFind(ll n): d(n,-1){}

    ll root (ll x){
        if(d[x] < 0) return x; // 自分が根
        return d[x] = root(d[x]);
    }

    bool unite(ll x, ll y){
        x = root(x); y = root(y);
        if(x == y)return false;
        if(d[x]>d[y])swap(x,y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }

    bool same(ll x, ll y){ //同じグループか判定
        return root(x) == root(y);
    }

    ll size(ll x){
        return -d[root(x)];
    }
};

int main(){
  ll n, m;
  cin >> n >> m;

  UnionFind unionFind(n+5);
  rep(i,m){
    ll a,b;
    cin >> a >> b;
    a--;
    b--;
    if(!unionFind.same(a, b)){
        unionFind.unite(a, b);
    }
  }

  map<ll,ll> mp;
  rep(i,n){
    mp[unionFind.root(i)] ++;
  }

  ll ans =1;
  for(auto iter = begin(mp); iter != end(mp); ++iter){
    ans = max(ans, iter->second);
  }
  cout << ans << endl;


  return 0;
}

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

long long gcd(long long C,long long D){
  if (D==0){
    return C;
  }
  return gcd(D,C%D);
}

int main() {
  long long A,B,C,D;
  cin >> A >> B >> C >> D;
  long long E=C*D/gcd(C,D);
  long long x=B/C-(A+C-1)/C+1;
  long long y=B/D-(A+D-1)/D+1;
  long long z=B/E-(A+E-1)/E+1;
  cout << (B-A+1)-(x+y-z) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define vlli vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vplli vector< pair< ll,ll> >
#define plli pair< ll,ll >
#define vps vector< pair< string, string> >
#define vpi vector< pair< int, int> >
#define all(x) x.begin(), x.end()
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn(i,a,n) for(ll i=a;i<n;i++)
#define scan(arr,a,n) for(ll i=(a);i<(n);i++)cin>>(arr)[i];
#define print(arr,a,n) for(ll i=(a);i<(n);i++)cout<<(arr)[i]<<" ";

ll add(ll x, ll y) {ll res = x + y; return (res >= mod ? res - mod : res);}
ll mul(ll x, ll y) {ll res = x * y; return (res >= mod ? res % mod : res);}
ll sub(ll x, ll y) {ll res = x - y; return (res < 0 ? res + mod : res);}
ll power(ll x, ll y) {ll res = 1; x %= mod; while (y) {if (y & 1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;}
ll mod_inv(ll x) {return power(x, mod - 2);}


int main(){
    fast;
    #ifndef ONLINE_JUDGE
    freopen("input1.txt","r",stdin);
    freopen("output1.txt","w",stdout);
    #endif
    ll n;
    cin>>n;
    ll a[n] = {}, ans = 1000;
    scan(a, 0, n);
    forn(i, 1, n){
        if(a[i]>a[i-1]){
            
            ans=(ans/a[i-1])*a[i] + ans%a[i-1];
        }
        

    }
    cout<<ans<<endl;
    
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define mem(a) memset(a,0,sizeof(a))
#define pd(a) printf("%.10f\n",a)
#define pb(a) push_back(a)
#define in(a) insert(a)
#define pi M_PI
#define R cin>>
#define F first
#define S second
#define C class
#define ll long long
#define ln cout<<'\n'
template<C T>void pr(T a){cout<<a;ln;}
template<C T,C T2>void pr(T a,T2 b){cout<<a<<' '<<b;ln;}
template<C T,C T2,C T3>void pr(T a,T2 b,T3 c){cout<<a<<' '<<b<<' '<<c;ln;}
template<C T>void PR(T a,int n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
bool check(int n,int m,int x,int y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  string s;
  R s;
  int n=s.size();
  if(n>=3) {
    rep(i,n-2) {
      set<char> se;
      REP(j,i,i+3) se.in(s[j]);
      if(se.size()<3) {
        pr(i+1,i+3);
        return;
      }
    }
  } else if(s[0]==s[1]) {
    pr(1,2);
    return;
  }
  pr(-1,-1);
}

int main() {
  ios::sync_with_stdio(0);cin.tie(0);
  Main();return 0;
}


Measured memory_bytes: 512
def collats(n: int) -> int:
    if n % 2 == 0:
        return n // 2
    else:
        return 3 * n + 1


s = int(input())
check = {s: True}
m = 1

while True:
    s = collats(s)
    m += 1

    if s in check:
        print('%d' % m)
        break
    check[s] = True


Measured memory_bytes: 2940
#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>  
#include <chrono>
#include <random>
#include <time.h>
#include <fstream>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define all(c) begin(c),end(c)
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
void print(vec v){for(auto e:v)cout<<e<<" ";cout<<endl;}
void print(map<int,int> mp){for(auto e:mp)cout<<e.first<<" "<<e.second<<endl;cout<<endl;}


#define INF 1e9+7
#define LLINF 1e18+7
#define N 250000
ll MOD=998244353;
struct UnionFind{
    vector<int> par,sizes;
    UnionFind(int n):par(n+1),sizes(n+1,1){
        rep2(i,1,n)par[i]=i;
    }
    int find(int x){
        return (x==par[x]?x:par[x]=find(par[x]));
    }
    void unite(int x,int y){
        x=find(x);y=find(y);
        if(x==y)return ;
        if(sizes[x]<sizes[y]){
            swap(x,y);
        }
        par[y]=x;
        sizes[x]+=sizes[y];
    }
    bool same(int x,int y) {return (find(x)==find(y));}
    int size(int x) {return sizes[find(x)];}
};
main(){
    int n;cin>>n;
    vec a,b;
    rep(i,n){
        a.pb(in());
    }
    rep(i,n)b.pb(in());
    vector<pair<pii,int>> c;
    rep(i,n)c.pb({{b[i],a[i]},i});
    sort(all(c));
    int now=0;
    vector<pii> aa;
    rep(i,n){
        aa.pb({a[i],i});
    }
    sort(all(aa));
    int ap=0;
    bool flag=false;
    UnionFind uf(n+1);
    rep(i,n){
        while(ap<n-1&&c[i].first.first>=aa[ap+1].first)ap++;
        if(ap<i){
            cout<<"No";return 0;
        }
        else if(ap==i&&i<n-1){
            now=aa[ap+1].first;
            if(c[i].first.second==aa[ap].first)flag=true;
        }
        else{
            if(now<=c[i].first.second&&c[i].first.second<=c[i].first.first){
                flag=true;
            }
        }
        uf.unite(aa[i].second,c[i].second);
        // cout<<now<<" "<<ap<<endl;
    }
    int si=0;
    rep(i,n)if(uf.par[i]==i)si++;
    if(si>1)flag=true;
    cout<<(flag?"Yes":"No");
}


Measured memory_bytes: 3952
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>
#include<map>
#include<cstring>
#include<unordered_map>
using namespace std;

int x[20000], y[20000];
signed main() {
	int k = 1;
	int a; cin >> a;
	for (int b = 0; b < a; b++) {
		x[b] = k;
		y[a - b - 1] = k;
		k += 20001;
	}
	for (int i = 0; i < a; i++) {
		int S; scanf("%d", &S);
		S--;
		x[S] += i;
	}
	for (int i = 0; i < a; i++) {
		if (i)cout << " ";
		cout << x[i];
	}
	cout << endl;
	for (int i = 0; i < a; i++) {
		if (i)cout << " ";
		cout << y[i];
	}
	cout << endl;
}

Measured memory_bytes: 768
from itertools import accumulate

N, C = map(int, input().split())
E = [[0] * 100010 for _ in range(C)]
for _ in range(N):
    s, t, c = map(int, input().split())
    E[c-1][s-1] += 1
    E[c-1][t-1] -= 1
F = [0] * 100010
for e in E:
    for i, v in enumerate(e):
        if v == 1:
            F[i] += 1
        if v == -1:
            F[i+1] -= 1
ans = max(list(accumulate(F)))
print(ans)


Measured memory_bytes: 29428
#include<iostream>
using namespace std;
int main()
{
	int te[1000 + 1][3];
	bool ka[1000 + 1]={ 0 };
	int n;
	int cnt;
	int i,j;
	int tmp;

	cin >> n;
	
	for(i=0;i<n;i++)
	{
		cin >> te[i][0] >> te[i][1] >> te[i][2];
		if(te[i][0] > te[i][1])
		{
			tmp = te[i][0];
			te[i][0] = te[i][1];
			te[i][1] = tmp;
		}
		if(te[i][1] > te[i][2])
		{
			tmp = te[i][1];
			te[i][1] = te[i][2];
			te[i][2] = tmp;
			if (te[i][0] > te[i][1])
			{
				tmp = te[i][0];
				te[i][0] = te[i][1];
				te[i][1] = tmp;
			}
		}
	}

	cnt = 0;
	for(i=0;i<n;i++)
	{
		if(!ka[i])
		{
			for(j=i+1;j<n;j++)
			{
				if( te[i][0] == te[j][0] && te[i][1] == te[j][1] && te[i][2] == te[j][2])
				{
					cnt++;
					ka[j]=true;
				}
			}
		}
	}

	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
int main(){
  string n;
  cin >> n;
  if(n[0] == n[1] && n[1] == n[2] || n[1] == n[2] && n[2] == n[3])
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>


typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

using namespace std;

int cnt_digits(ll n) {
	int digits = 0;
	while (n > 0) {
		n /= 10;
		digits++;
	}
	return digits;
}

int main()
{
	ll n,a,b;
	cin >> n;
	ll ans = cnt_digits(n);
	for (ll a = 1; a*a <= n; a++) {
		if (n%a != 0)  continue ;
		b = n / a;
		int cur = max(cnt_digits(a), cnt_digits(b));
		if (cur < ans) {
			ans = cur;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
n,m = (int(i) for i in input().split())
a = []
for i in range(n):
  tp1,tp2 = (int(i) for i in input().split())
  a.append([tp1,tp2])
drink = 0
ans = 0
a.sort()
for i in range(n):
  if drink < m:
    if drink + a[i][1] < m:
      drink += a[i][1]
      ans += a[i][0]*a[i][1]
    else:
      honsuu = m-drink
      drink += honsuu
      ans += a[i][0]*honsuu
      
  
 
print(ans)

Measured memory_bytes: 20076
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll N;
    cin >>N;
    ll ans=1;
    rep(i,N){
        ll t;
        cin>>t;
        ans=lcm(ans,t);
    }
    cout << ans << endl;


    return 0;
    

}

Measured memory_bytes: 3624
#include <stdio.h>
int main() {
	int x, y,num=1;
	scanf("%lld%lld", &x, &y);
	for (int i = 1; i <= x; i++) {
		if (num >= y) { num += y; }
		else { num += num; }
	}
  printf("%lld",num);
}



Measured memory_bytes: 128
import sys
def input():
    return sys.stdin.readline()[:-1]
sys.setrecursionlimit(300000)
class uf:
    def __init__(self,n):
        self.n=n
        self.l=[-1]*n
    def ro(self,n):         #root
        if self.l[n]<0:
            return n
        r=self.ro(self.l[n])
        self.l[n]=r
        return r
    def me(self,a,b):       #merge
        ra=self.ro(a)
        rb=self.ro(b)
        if self.l[ra]>self.l[rb]:
            ra,rb=rb,ra
        if ra!=rb:
            self.l[ra]+=self.l[rb]
            self.l[rb]=ra
    def sa(self,a,b):       #same
        return self.ro(a)==self.ro(b)
N,Q=map(int,input().split())
g=uf(N)
for i in range(Q):
    t,u,v=map(int,input().split())
    if t:
        if g.sa(u,v):
            print(1)
        else:
            print(0)
    else:
        g.me(u,v)

Measured memory_bytes: 11876
#include <stdio.h>

void trace(int A[], int N) {
  int i;
  for (i=0; i<N; i++) {
    if(i>0) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

void bubbleSort(int A[], int N) {
  int j, count = 0, i = 0;
  int flag = 1;
  while (flag) {
    flag = 0;
    for (j = N-1; j > i; j--) {
      if (A[j] < A[j-1]) {
        int tmp = A[j];
        A[j] = A[j-1];
        A[j-1] = tmp;
        flag = 1;
        count++;
      }
    }
    i++;
  }
  trace(A, N);
  printf("%d\n", count);
}

int main() {
  int N, i, j;
  int A[100];

  scanf("%d", &N);
  for (i = 0; i < N; i++) scanf("%d", &A[i]);

  bubbleSort(A, N);



  return 0;
}


Measured memory_bytes: 2760
#include<stdio.h>
int main(void){
    int x[10000];
    int i;
    for(i=0;i<10000;i++){
        scanf("%d",&x[i]);
        if(x[i]<=0){
            break;
        }
    }
    for(i=0;i<10000;i++){
        if(x[i]<=0){
            break;
        }
        printf("Case %d: %d\n",i+1,x[i]);
    }
   
    return 0;
}


Measured memory_bytes: 1936
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)
#define pb push_back
#define deb(x) cout<<#x<<" "<<x<<endl;
#define deb2(x, y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define deb3(x, y, z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;
template<class T, class U> inline void add_self(T &a, U b){a += b;if (a >= mod) a -= mod;if (a < 0) a += mod;}
template<class T, class U> inline void min_self(T &x, U y) { if (y < x) x = y; }
template<class T, class U> inline void max_self(T &x, U y) { if (y > x) x = y; }

template <typename T>void print(T v, bool show_index = false){int w = 2;if(show_index){for(int i=0; i<v.size(); i++)cout<<setw(w)<<i<<" ";cout<<endl;}for(auto i= v.begin(); i!=v.end(); i++)cout<<setw(w)<<*i<<" ";cout<<endl;}
template <typename T>void print_vv(T v){if(v.size()==0) {cout<<"Empty"<<endl; return;} int w = 3;cout<<setw(w)<<" ";for(int j=0; j<v[0].size(); j++)cout<<setw(w)<<j<<" ";cout<<endl;for(auto i= 0; i<v.size(); i++){cout<<i<<" {";for(auto j = 0; j!=v[i].size(); j++){cout<<setw(w)<<v[i][j]<<",";}cout<<"},"<<endl;}cout<<endl;}
template <class T, class U> void print_m(map<T,U> m, int w=3){if(m.empty()){cout<<"Empty"<<endl; return;}for(auto x: m)cout<<"("<<x.first<<": "<<x.second<<"),"<<endl;cout<<endl;}

const ll inf = 1e18;

int main(){
    int n;
    while(cin>>n){
        vi a(n); forn(i,n) cin>>a[i];

        vvl dp(n, vl(n, -inf));

        for(int l=n-1; l>=0; --l){
            dp[l][l] = a[l];
            for(int r=l+1; r<n; ++r){
                max_self(dp[l][r], max({a[l] - dp[l+1][r], a[r] - dp[l][r-1]}));
            }
        }

        cout<<dp[0][n-1]<<endl;
    }
    return 0;
}

Measured memory_bytes: 70656
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

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

    for (int i = 0; i < s.length(); i++) {
        cout << "x";
    }
    
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cstring>
using namespace std;
#define mx 100005
int dp[mx+5];
int v[mx+5];
void memo(int i,int n)
{
    if(i==n) return;
    dp[i] = min(dp[i-2]+abs(v[i-2]-v[i]),dp[i-1]+abs(v[i-1]-v[i]));
    memo(i+1,n);
}
int main()
{
    int N;
    cin>>N;
    memset(dp,0,sizeof(dp));
    for(int i=0;i<N;i++)
    {
        cin>>v[i];
    }
    dp[1] = abs(v[1]-v[0]);
    memo(2,N);
    cout<<dp[N-1]<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>
#include <complex>
#define _USE_CMATH_DEFINES

const long INF = (1l << 30);
const long LINF = (1l << 60); //1.15*10^18

long n, m;
long a[200005], f[200005];

//divCeil
long divCeil(long a, long b){
    return (a-1)/b+1;
}

bool judge(long x){
    long dec = 0;
    for(int i = 0; i < n; i++){
        long res = x / f[i];
        dec += std::max(0l, a[i] - res);
    }
    if(dec <= m){
        return true;
    }else{
        return false;
    }
}

int main(){
    scanf("%ld%ld", &n, &m);
    for(int i = 0; i < n; i++){
        scanf("%ld", a+i);
    }
    for(int i = 0; i < n; i++){
        scanf("%ld", f+i);
    }
    std::sort(a, a+n);
    std::sort(f, f+n, [&](long x, long y){
        return x > y;
    });

    /*
    for(int i = 0; i < n; i++){
        printf("%3ld", a[i]);
    }
    printf("\n");
    for(int i = 0; i < n; i++){
        printf("%3ld", f[i]);
    }
    printf("\n");
    //*/
    long ok = LINF, ng = -1;
    while(ok - ng > 1){
        long mid = (ok + ng) / 2;
        if(judge(mid)){
            ok = mid;
        }else{
            ng = mid;
        }
    }
    printf("%ld\n", ok);
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define sqr(x) ((x) * (x))
#define bit(n) (1LL<<(n))
#define pcnt(x) __builtin_popcountll(x)
#define PB push_back
#define MP make_pair
#define endl "\n"
using Edge = pair<int,int>;
using Graph = vector<vector<Edge>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
// ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main() {
  int n; cin >> n;
  int s[n];
  FOR(i,0,n-1) cin >> s[i];
  int q; cin >> q;
  int t;
  int ans = 0;
  FOR(i,0,q-1) {
    cin >> t;
    ans += binary_search(s,s+n,t);
  }
  cout << ans << endl;
 
}




Measured memory_bytes: 3404
#include<bits/stdc++.h>
#define maxn 100100
using namespace std;
int ans=0, res , num[maxn] ,n , a[maxn];
int main (){
	cin >> n;
	for( int i = 1; i <= n; i++) cin >> a[i], num[a[i]]++;
	for( int i = 0; i <= 100000; i++) {
		res = 0;
		if( i > 0 ) res += num[i-1];
		res+=( num[i] + num[i+1]); 
		if( res > ans ) ans = res;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main(){
	int m = 0, f = 0, r=0;
	char seiseki;
	
	for (int a = 0; a < 51; a++){
		cin >> m >> f >> r;
		if (m == -1 && f == -1 && r == -1){
			break;
		}
		if  (m == -1 || f == -1){
			seiseki = 'F';
			cout << seiseki << endl;
			continue;
		}
		if (m + f >= 80){
			seiseki = 'A';
		}
		if (m + f >= 65 && m + f < 80){
			seiseki = 'B';
		}
		if (m + f >= 50 && m + f < 65){
			seiseki = 'C';
		}
		if (m + f >= 30 && m + f < 50){
			if (r >= 50){
				seiseki = 'C';
				cout << seiseki << endl;
				continue;
			}
			seiseki = 'D';
		}
		if (m + f < 30){
			seiseki = 'F';
		}
		
		cout << seiseki << endl;
	}
	return 0;
}


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

using namespace std;

typedef long long ll;

char str[45][45];

ll f[45][45][45],g[45][45][45];

int main() {
  int n;
  scanf("%d",&n);
  n=2*n;
  for(int i=1;i<=n;i++) scanf("%s",str[i]+1);
  for(int i=1;i<n;i++) {
    f[i][i][i]=1;
    for(int j=i+1;j<=n;j++)
      if (str[i][j]=='1') g[i][i][j]=1;
  }
  for(int i=3;i<n;i+=2)
    for(int j=1;i+j<=n;j++) {
    	int k=i+j-1;
    	for(int l=j;l<=k;l+=2)
    	for(int r=k;r>l;r-=2) {
    		ll s=0;
    		for(int t=r;t<=k;t++) s+=g[j][l][t]*f[r][k][t];
    		for(int t=l+1;t<r;t++) f[j][k][t]+=f[l+1][r-1][t]*s;
		}
		for(int t1=j+1;t1<k;t1++)
		for(int t2=k+1;t2<n;t2++)
		  if (str[t1][t2]=='1') g[j][k][t2]+=f[j][k][t1];
	}
  ll ans=0;
  for(int i=1;i<n;i++)
    if (str[i][n]=='1') ans+=f[1][n-1][i];
  printf("%lld\n",ans);
  return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	map<string, vector<pair<int,int> > > mp;
	for(int i =0;i<n;i++)
	{
		string city;
		int score;
		cin>>city>>score;
		mp[city].push_back(make_pair(score, i + 1));
	}
	for(auto it : mp)
	{
		vector<pair<int,int> > time = mp[it.first];
		sort(time.begin(),time.end());
		reverse(time.begin(),time.end());
		for(int i = 0;i<time.size();i++)
			cout<<time[i].second<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    x = [-1] + [int(i) for i in input().split()]
    x_set = set(x)
    M = int(input())
    A = [int(i) for i in input().split()]
    for i in range(M):
        posi = A[i]
        next_posi = x[posi] + 1
        if next_posi in x_set or next_posi > 2019:
            continue
        x_set.discard(x[posi])
        x_set.add(next_posi)
        x[posi] += 1

    print(*x[1:], sep="\n")


if __name__ == '__main__':
    main()



Measured memory_bytes: 5620
#include <stdio.h>
#include <stdbool.h>

int main()
{
    int n,m,a[200000],b[200000];
    bool start[200000] = {false};

    int i;
    scanf("%d %d",&n,&m);
    for (i = 0; i < m; i++)
    {
        scanf("%d %d",&a[i],&b[i]);
        if(a[i] == 1)start[b[i] - 1] = true;
    }
    for (i = 0; i < m; i++)
    {
        if(b[i] == n && start[a[i] - 1] == true)break;
    }
    printf(i == m ? "IMPOSSIBLE" : "POSSIBLE");
}

Measured memory_bytes: 1920
#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 d;
    cin >> d;
    if (d == 25)
        cout << "Christmas" << endl;
    if (d == 24)
        cout << "Christmas Eve" << endl;
    if (d == 23)
        cout << "Christmas Eve Eve" << endl;
    if (d == 22)
        cout << "Christmas Eve Eve Eve" << endl;
    return 0;
}

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

using namespace std;

#define ldouble long double
#define llong long long int
#define print(x) cout << x << endl
#define ternary(condition, x, y) ((condition) ? x : y) 
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(STL) STL.begin(), STL.end()
#define stl_rep(itr, STL) for (auto itr = STL.begin(); itr != STL.end(); ++itr)

const static long long int MOD = 1000000000 + 7;
const static int dy[] = {0, 1, 0, -1};
const static int dx[] = {1, 0, -1, 0};

int main (int argc, char *argv[]) {
    cin.tie(0); 
    ios::sync_with_stdio(false);

    int cnt[4] = {};
    rep(i, 3) {
        int a, b;
        cin >> a >> b;
        ++cnt[--a];
        ++cnt[--b];
    }
    sort(cnt, cnt+4);
    if (cnt[0] == 1 && cnt[1] == 1 && cnt[2] == 2 && cnt[3] == 2) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}

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

using namespace std;

string s;
long long ans;

int main(){
	cin >> s;

	for(int i = 0; i < 1 << s.size() - 1; ++i){
		string now = s.substr(0, 1);
		int pos = 1;
		for(int j = 0; j < s.size() - 1; ++j){
			if(i & (1 << j)){
				now = now + "+" + s[pos];
			}else{
				now = now + s[pos];
			}
			pos++;
		}

		int spos = 0;
		long long sum = 0;
		while(now.find("+", spos) != string::npos){
			int ppos = now.find("+", spos);
			sum += stoll(now.substr(spos, ppos - spos));
			spos = ppos + 1;
		}
		sum += stoll(now.substr(spos, (int)1e9));
		ans += sum;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

#define COUNT 100
int min(int a,int b){
  if(a<b)return a;
  else return b;
}

int main(){
  int i,j,k,r,num;
  int A[COUNT+1],M[COUNT+1][COUNT+1];
  scanf("%d",&num);
  for(i = 1;i<= num;i++){
    scanf("%d %d",&A[i-1],&A[i]);
    M[i][i] = 0;
  }

  for(j = 2; j<= num;j++){
    for(i = 1; i <=num-j+1;i++){
      r = i + j -1;
      M[i][r] = 100000000;
      for(k = i;k <=r-1;k++){
	M[i][r] = min(M[i][r],M[i][k]+M[k+1][r]+A[i-1]*A[k]*A[r]);
      }
    }
  }
  printf("%d\n",M[1][num]);
  return 0;
}

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

typedef long long ll;

int main(void) {
  int nQuery;
  scanf("%d", &nQuery);
  
  ll bsum = 0;
  priority_queue<ll> q1; // 大きい順に出る
  priority_queue<ll, vector<ll>, greater<ll> > q2; // 小さい順に出る
  const ll INF = 1e10;
  ll sum1 = 0;
  ll sum2 = 0;
  
  REP(iQuery, nQuery) {
    int type;
    scanf("%d", &type);
    if(type == 1) {
      ll a, b;
      scanf("%lld%lld", &a, &b);
      bsum += b;
      if(q1.size() == q2.size()) {
        q2.push(a);
        sum2 += a - (-INF);
        ll t = q2.top(); q2.pop();
        sum2 -= t - (-INF);
        q1.push(t);
        sum1 += INF - t;
      } else {
        q1.push(a);
        sum1 += INF - a;
        ll t = q1.top(); q1.pop();
        sum1 -= INF - t;
        q2.push(t);
        sum2 += t - (-INF);
      }
    } else {
      if(q1.empty()) {
        assert(false);
      } else {
        ll a = q1.top();
        ll v = 0;
        v += sum1 - (INF - a) * (int)q1.size();
        v += sum2 - (a - (-INF)) * (int)q2.size();
        printf("%lld %lld\n", a, v + bsum);
      }
    }
  }
    
  return 0;
}


Measured memory_bytes: 3828
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#define vector1d(type,name,...) vector<type>name(__VA_ARGS__)
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll updivide(ll a,ll b){if(b==1) return a;else if(a%b==0) return a/b;else return (a/b)+1;}

int main(){
    INT(n);
    vector<int> vec(n+1,0);
    vector<int> vec2(n+1,0),ans;
    ll sum=0;
    for(int i=1;i<=n;i++)in(vec[i]);
    for(int i=n;i>=1;i--){
        sum=0;
        for(int j=2*i;j<=n;j+=i){
            sum+=vec2[j];
        }
        if(sum%2!=vec[i]){
            vec2[i]=1;
            ans.push_back(i);
        }
    }
    out(ans.size());
    if(ans.size()>=1)out(ans);
}



Measured memory_bytes: 5344
#include<stdio.h>

int main(){
    int a,b,c;
    
    scanf("%d %d %d", &a, &b, &c);
    
    if (a < b & b < c){
        printf("Yes\n");
    }
    
    else{
        printf("No\n");
    }
    
    return 0;
    
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll mod=1e9+7;
int n;
int root;
bool f[100005];
vector<int> g[100005];
ll dp[100005][2];
void DFS(int u,int par=-1){
	if(g[u].size()==1&&g[u][0]==par){
		dp[u][0]=dp[u][1]=1;
		return ;
	}
	ll x=1,y=1;
	for(int i=0;i<g[u].size();++i){
		int v=g[u][i];
		if(v==par){
			continue;
		}
		DFS(v,u);
		x=(x*(dp[v][0]+dp[v][1])%mod)%mod;
		y=y*dp[v][0]%mod;
	}
	dp[u][0]=x,dp[u][1]=y;
}
int main(){
	cin>>n;
	for(int i=1;i<n;++i){
		int x,y;
		cin>>x>>y;
		g[x].push_back(y),g[y].push_back(x);
		f[y]=1;
	}
	for(int i=1;i<=n;++i){
		if(!f[i]){
			root=i;
			break;
		}
	}
	DFS(root);
	cout<<(dp[root][0]+dp[root][1])%mod<<'\n';
	return 0;
}

Measured memory_bytes: 12672
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""ゲームの参加人数としてありうる最大値を求める問題"""

def main():
    """
    入力: 1行目に情報の数N, 2行目からN+1行目まで，
         空白区切りで得点の大きい方からの何番目の人の得点が何点だったかを"順位 得点"で示す．
         全ての人の得点は異なる非負の整数．
    出力: ゲームの参加人数としてありうる最大値．
    Returns: None.
    方針: 一番低い順番の人の順位と得点の和が答えになる．(その人の得点と同じ人数が参加しうる)
    """
    # 持っている情報の数
    numbers = int(input())
    min_rank = 0
    min_value = 2000000000
    for i in range(numbers):
        current_rank, current_value = [int(item) for item in input().split()]
        if min_rank < current_rank:
            min_rank = current_rank
            min_value = current_value
    print(min_rank + min_value)
    return None

if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include<iostream>
#include<queue>
#include<string.h>
#define inf 1000000001
using namespace std;

int X[4]={0,1,0,-1};
int Y[4]={-1,0,1,0};
int h,w,c[4];
int map[40][40];
int memo[40][40][4];

class State{
public:
  int y,x,muki,cost;
  State(int y,int x,int muki,int cost):y(y),x(x),muki(muki),cost(cost){}
};

bool in(int y,int x)
{
  if(y<0 || x<0 || y>=h || x>=w)return false;
  return true;
}

int main()
{
  queue<State> Q;
  while(1){
    cin>>w>>h;
    if(h+w==0)break;

    for(int i=0;i<40;i++){
      for(int j=0;j<40;j++){
	for(int k=0;k<4;k++)memo[i][j][k]=inf;
      }
    }
    for(int i=0;i<h;i++)for(int j=0;j<w;j++)cin>>map[i][j];
    for(int k=0;k<4;k++)cin>>c[k];

    Q.push(State(0,0,1,0));
    int ans=inf;
    memo[0][0][1]=0;
    while(!Q.empty()){
      State u=Q.front();
      Q.pop();
      //      cout<<u.y<<" "<<u.x<<" "<<u.muki<<" "<<u.cost<<endl;
      if(u.y==h-1 && u.x==w-1){
	ans=min(ans,u.cost);
	continue;
      }

      for(int k=0;k<4;k++){
	int mk=(u.muki+k)%4;
	int a=u.y+Y[mk],b=u.x+X[mk];
        if(!in(a,b))continue;
	if(k==map[u.y][u.x]){
	  if(memo[a][b][mk]>u.cost){
	    memo[a][b][mk]=u.cost;
	    Q.push(State(a,b,mk,u.cost));
	  }
	}
	else {
          if(memo[a][b][mk]>u.cost+c[k]){
	    memo[a][b][mk]=u.cost+c[k];
	    Q.push(State(a,b,mk,u.cost+c[k]));
	  }
	}
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

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

bool solve(vector<int> v, int idx){
  v.erase(v.begin() + idx);
  int diff = v[1] - v[0];
  for(int i = 0 ; i < (int)v.size()-1 ; i++){
    if(diff != v[i+1] - v[i]) return false;
  }
  return true;
}

int main(){
  int n;
  while(cin >> n, n){
    vector<int> v(n+1);
    for(int i = 0 ; i < n+1 ; i++) cin >> v[i];
    
    for(int i = 0 ; i < n+1 ; i++){
      bool ret = solve(v, i);
      if(ret){
	cout << v[i] << endl;
	break;
      }
    }    
  }
  return 0;
}

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

void solve() 
{
    string s;int k;cin>>s>>k;
    REP(i,s.size()){
        if('z'+1-s[i]<=k&&s[i]!='a'){
            k-='z'+1-s[i];
            s[i]='a';
        }
    }
    s[s.size()-1]+=k%26;
    cout<<s<<endl;
}

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

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

using namespace std;

int ans[3];
int a,b,c,k,p,q,r;

int main(){
  cin>>a>>b>>c>>k;
  p=a;
  q=b;
  r=c;
  for(int i=0;i<k;i++){
    p*=2;
    q*=2;
    r*=2;
  }
  if(a>=b&&a>=c)cout<<p+b+c<<endl;
  else if(b>=c&&b>=a)cout<<a+q+c<<endl;
  else if(c>=b&&c>=a)cout<<a+b+r<<endl;
}


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

using namespace std;

int main() {
  int A, B, C, K;
  int result = 0;

  scanf("%d %d %d %d", &A, &B, &C, &K);

  for (int i = 1; i <= K; i++) {
    if (i <= A) {
      result++;
    } else if (i <= (A + B)) {
    } else {
      result--;
    }
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 3656
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
template<class T> inline bool chmax(T& a, T b) { if(a < b){ a=b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if(a > b){ a=b; return 1; } return 0;}

int main(){
	ll n;
	string s;
	cin >> n >> s;
	
	ll numr = 0;
	REP(i,n){
		if(s[i]=='R') numr++;
	}
	ll ans=0;
	REP(i,numr){
		if(s[i]=='W') ans++;
	}
	cout << ans << endl;
	
	return 0;
}

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

// 素数判定
bool is_prime(int x) {
    if(x < 2){
        return false;
    }
    for(int i = 2; i * i <= x; i++) {
        if(x % i == 0){
            return false;
        }
    }
    return true;
}

int main(){

    int n;
    cin >> n;
    int cnt = 0;
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        if(is_prime(a)){
            cnt++;
        }
    }
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ar array
#define vi vector<int>
#define INF 1000000000
 
 
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int N; cin >> N;
	ll nums[N+10];
	for(int i=0; i < N; i++){
		ll n; cin >> n;
		nums[i] = n;
	}
 
	for(int i=0; i<N; i++){
		if(nums[i] == 0){
			cout << 0 << endl;
			return 0;
		}
	}	
 
	unsigned ll limit = 1000000000000000000ULL; 
	unsigned ll product = 1;	
	
	for(int i=0; i<N; i++){
		if(nums[i] <= limit/product){
			product *= nums[i];
		}
		else{
			cout << -1 << endl;
			return 0;
		}
	}	
 
	cout << product << endl;
 
	return 0;
}

Measured memory_bytes: 4384
S = input()
count = 0
a1 = 1
for i in S:
  if count == 2 or count == 4:
    mem = i
  if count == 3 or count == 5:
    if mem == i:
      a1 *= 1
    else:
      a1 *= 0
      
  count += 1
  
  
if a1==1:
  print('Yes')
else:
  print('No')
  

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define ll long long
using namespace std;
 
const ll MOD = 1000000007;

ll memo[2005];
 
ll dp(int x){
  if (memo[x] != -1) return memo[x];
  
  ll total = 0;
  for (int i = 3; i <= x; i++){
    total += dp(x-i);
    total %= MOD;
    //cout << i << " " << total << endl;
  }
  
  memo[x] = total;
  return total;
}

int main(){
  
  memset(memo, -1, sizeof memo);
  memo[0] = 1;
  memo[1] = 0;
  memo[2] = 0;
  memo[3] = 1;
  memo[4] = 1;
  memo[5] = 1;
  
  ll S;
  cin >> S;
  cout << dp(S) << endl;
}
  

Measured memory_bytes: 3668
#include <iostream>
#include <vector>
#include <ios>
using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    long long N, A, B;
    cin >> N >> A >> B;
    vector<long long> X(N, 0);
    for (auto & x : X) cin >> x;
    long long cum = 0LL;
    for (int i = 1; i != N; ++i){
        cum += min(A * (X[i] - X[i - 1]), B);
    }
    cout << cum << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
typedef long long ll;
const ll MOD=1e+9+7;
struct mint{
  ll x;
  mint(ll x=0):x(x%MOD){}
  mint& operator+=(const mint a){
    if((x+=a.x)>=MOD) x-=MOD;
    return *this;
  }
  mint& operator-=(const mint a){
    if((x += MOD-a.x)>=MOD) x-=MOD;
    return *this;
  }
  mint& operator*=(const mint a){
    (x*=a.x)%=MOD;
    return *this;
  }
  mint operator+(const mint a) const{
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const{
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const{
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const{
    if(!t) return 1;
    mint a = pow(t>>1);
    a*=a;
    if(t&1) a*=*this;
    return a;
  }
  
  //for prime mod
  mint inv() const{
    return pow(MOD-2);
  }
  mint& operator/=(const mint a){
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const{
    mint res(*this);
    return res/=a;
  }
};

int main()
{
  int n,m;
  cin >> n >> m;
  //  vector<int> a(n),b(m);
  map<int,int> raw,col;
  bool f = false;
  rep(i,n){
    int a;
    cin >> a;
    raw[a]++;
    //    cin >> a[i];
    if(raw[a]>=2){
      f = true;
      break;
    }
  }
  rep(i,m){
    int b;
    cin >> b;
    col[b]++;
    //    cin >> b[i];
    if(col[b]>=2){
      f = true;
      break;
    }
  }
  if(f){
    cout << 0 << "\n";
    return 0;
  }

  // rep1(i,n*m){
  //   cout << raw[i] << "\n";
  //   raw[i] = 0;
  //   col[i] = 0;
  // }

  // rep(i,n){
  //   raw[a[i]]++;
  // }
  // rep(i,m){
  //   col[b[i]]++;
  // }

  int cntr=0,cntl=0,cnt=0;
  mint res(1);
  for(int i=n*m;i>0;--i){
    int x = raw[i];
    int y = col[i];
    //    cout << i << ":" << x << ":" << y << "\n";
    if(x>=2||y>=2){
      cout << 0 << "\n";
      return 0;
    }
    if(x==1&&y==1){
      cntr++;
      cntl++;
    }
    else if(x==1&&y==0){
      res *= (mint)cntl;
      cntr++;
    }
    else if(x==0&&y==1){
      res *= (mint)cntr;
      cntl++;
    }
    else if(x==0&&y==0){
      res *= (mint)(cntr*cntl-cnt);
    }
    cnt++;
  }

  cout << res.x << "\n";
  
  return 0;
}


Measured memory_bytes: 93952
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;

class Magatro
{
    static int H, W, N;
    static void Main()
    {
        string[] s = Console.ReadLine().Split(' ');
        const long max = 10000000000;
        H = int.Parse(s[0]);
        W = int.Parse(s[1]);
        N = int.Parse(s[2]);
        Dictionary<long, int> Dic = new Dictionary<long, int>();
for(int i = 0; i < N; i++)
        {
            s = Console.ReadLine().Split(' ');
            int y = int.Parse(s[0]);
            int x = int.Parse(s[1]);
            for(int j = -2; j <= 0; j++)
            {
                for(int k = -2; k <= 0; k++)
                {
                    if (y + j > 0 && x + k > 0 && y + j <= H - 2 && x + k <= W - 2)
                    {
                        int cc;
                        long c = (long)(y + j) * max + (long)(x + k);
                        if(Dic.TryGetValue(c,out cc))
                        {
                            Dic[c]++;
                        }
                        else
                        {
                            Dic.Add(c, 0);
                        }
                        
                    }
                }
            }
        }
        int[] cnt = new int[9];
        foreach(var p in Dic)
        {
            cnt[p.Value]++;
        }
        Console.WriteLine(((long)W - 2) * ((long)H - 2) - cnt.Sum());
        for(int i = 0; i < 9; i++)
        {
            Console.WriteLine(cnt[i]);
        }
    }
   
}
struct xy
{
    public int Y, X;
}




Measured memory_bytes: 48552
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
ll a[N];
ll n,k;
bool check(ll x){
    ll cnt=0;
    for(int i=0;i<n;i++){
//        if(x>=a[i]) continue;
//        else if(x>=(a[i]+1)/2) cnt++;
//        else if(x==1) cnt+=a[i]-1;
//        else cnt+=ceil(log(a[i])/log(x));
        //cnt+=a[i]/x;
        cnt+=(a[i]-1)/x;
    }
    return cnt<=k;
}

int main(){
    //cout<<ceil(log(9)/log(2));
    ll r=0;
    cin>>n>>k;
    for(int i=0;i<n;i++) cin>>a[i],r=max(r,a[i]);
    ll l=1;
    while(l<=r){
        ll mid=(l+r)/2;
        //cout<<l<<r<<" "<<check(mid)<<endl;
        if(check(mid)) r=mid-1;
        else l=mid+1;
    }
    cout<<(l==0?1:l);//<<" "<<r<<endl;
    return 0;
}


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

int main() {
  int x, a, b;
  scanf("%d%d%d", &x, &a, &b);

  if (abs(x - a) < abs(x - b)) {
    printf("A");
  } else {
    printf("B");
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.math.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    int n = s.length();

    int[] ten = new int[n+1];
    ten[0] = 1;

    for (int i = 1; i < n+1; i++) {
      ten[i] = (ten[i-1]*10)%2019;
    }

    int[] data = new int[n+1];

    for (int i = 1; i <= n; i++) {
      data[i] = (data[i-1]+Integer.parseInt(s.substring(n-i,n-i+1))*ten[i-1])%2019;
    }

    int[] res = new int[2019];

    for (int i = 0; i <= n; i++) {
      int k = data[i]%2019;
      res[k]++;
    }

    int ans = 0;

    for (int i = 0; i < 2019; i++) {
      ans += res[i]*(res[i]-1)/2;
    }

    System.out.println(ans);

  }

}


Measured memory_bytes: 51288
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>

using namespace std;
const int N = 6;
int a[N];
int main()
{
	int pos;
	for (int i = 1; i <= 5; ++i)
	{
		scanf("%d", &a[i]);
		if (a[i] == 0) pos = i;
	}

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

	return 0;
}

Measured memory_bytes: 3760
<?php
  
fscanf(STDIN,"%d %d",$H,$W);

$S=[];

for($i=0;$i<$H;$i++){
  $S[$i] = trim(fgets(STDIN));
}

//それぞれの黒要素に対して上下左右のいずれかに黒があればOKなければNG

$is_possible = true;
for($i=0;$i<$H;$i++){
  for($j=0;$j<$W;$j++){
    if($S[$i][$j] == "#"){
      if(isBlack($S,$i,$j-1) || isBlack($S,$i,$j+1) || isBlack($S,$i-1,$j) || isBlack($S,$i+1,$j)){

      }else{
        $is_possible = false;
        break;
      }
    }
  }
  if(!$is_possible) break;
}

echo ($is_possible) ? "Yes": "No";



function isBlack($arr,$i,$j){
  return isset($arr[$i][$j]) && $arr[$i][$j] == "#";
}

Measured memory_bytes: 3956
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(A, B):
    if A <= 8 and B <= 8:
        return 'Yay!'
    else:
        return ':('


def main():
    # A = read_int()
    # B = read_int()
    A, B = read_int_n()
    print(slv(A, B))


if __name__ == '__main__':
    main()


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

using namespace std;

#define int long long
#define ll long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl



signed main() {

	char s;
	cin >> s;
	char ret;
	switch (s) {
	case 'A': ret = 'T'; break;
	case 'T': ret = 'A'; break;
	case 'G': ret = 'C'; break;
	case 'C': ret = 'G'; break;
	}
	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 764
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <sstream>
#include <fstream>

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)

using namespace std;
typedef long long unsigned int ll;

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

  int curX = 0, curY = 0, curT = 0;
  int t, x, y;

  bool isValid = true;
  for (int i = 0; i < N; ++i) {
    cin >> t >> x >> y;
    int distance = abs(x - curX) + abs(y - curY);
    int tDiff = t - curT;
    if ((tDiff % 2) != (distance % 2) || distance > tDiff) {
      isValid = false;
    }
    curX = x;
    curY = y;
    curT = t;
  }
  if (isValid) {
    cout << "Yes" << endl;    
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;
using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
int main(){
    //freopen("file.in", "r", stdin);
    int a,b,ans=0;
    scanf("%d%d",&a,&b);
    for(int i=22;i<=b;i++)
    	if(i%10>=2 and (i/10)*(i%10)<=a)
			ans++;
	cout<<ans<<endl;		
	return 0;
}


Measured memory_bytes: 384