akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>
#include <string>
#include <sstream>
#include <stack>
#include <deque>
#define pb push_back
#define make make_pair
#define kaku(a) cout << a << endl
#define isort(a) sort(a.begin(),a.end())
 
using namespace std;
 
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define PI 3.14159265359
long long gcd(long long a,long long b){ return b==0?a:gcd(b,a%b);}
long long lcm(long long a,long long b){ return a/gcd(a,b)*b;}
 
typedef pair<ll,ll> Pair;
const ll inf =1000000007;



int main(){
    ll k;
    cin >> k;
    ll ans=0;
    for(ll i=1;i<=k;i++){
        for(ll j=1;j<=k;j++){
            for(ll K=1;K<=k;K++){
                ans+=gcd(i,gcd(j,K));
            }
        }
    }
    kaku(ans);
}



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

int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	ll n; cin>>n;
	ll arr[n];
	for(ll i=0; i<n; i++){
		cin>>arr[i];
	}
	ll ans = 0;
	for(ll i=1; i<n; i++){
		if(arr[i]<arr[i-1]){
			ans+=(arr[i-1]-arr[i]);
			arr[i]=arr[i-1];
		}
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 5200
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n,x=0;
	scanf("%lld", &n);
	for (int i = 1; i <= n; i++)
	{
		if (i % 3 == 0 || i % 5 == 0)
			continue;
		else
		{
			x += i;
		}
	}
	printf("%lld\n", x);
}

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

using namespace std;

#define SIZE 100000
#define P pair<string, int> 

P que[SIZE];
int head = 0, tail = 0;

void push(P v) {
	que[tail] = v;
	tail = (tail + 1) % SIZE;
}

P pop() {
	P t = que[head];
	head = (head + 1) % SIZE;
	return t;
}

bool isEmpty() {
	if (head == tail)
		return true;
	return false;
}

int main() {
	int n, q, v;
	string s;
	cin >> n >> q;
	while (n--) {
		cin >> s >> v;
		push(P(s, v));
	}
	P p;
	int sum = 0;
	while (!isEmpty()) {
		p = pop();
		if (p.second > q) {
			p.second -= q;
			sum += q;
			push(p);
		}
		else {
			cout << p.first << " " << p.second + sum << endl;
			sum += p.second;
		}
	}

	return 0;
}


Measured memory_bytes: 7040
import Data.Char (digitToInt)

main :: IO ()
main = do
    [n,a,b] <- map read .words <$> getLine
    print . sum $ nums n a b

nums :: Int -> Int -> Int -> [Int]
nums n a b = filter (between a b . sumDigits) [1..n]

between :: Ord a => a -> a -> a -> Bool
between a b s = a <= s && s <= b

sumDigits :: Int -> Int
sumDigits = sum . map digitToInt . show


Measured memory_bytes: 1020
#include <iostream>
#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>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

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


int main() {

    int a, b, c, d;
    cin >> a >> b >> c >> d;

    cout << (min(a, b) + min(c, d)) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

#define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;

	vector<int> sz(n + 1);
	for (int i = 1; i <= n; ++i) {
		cin >> sz[i];
	}

	sort(sz.begin(), sz.end());

	vector<long long> pre_sum(n + 1);
	for (int i = 1; i <= n; ++i) {
		pre_sum[i] = (long long) sz[i] + pre_sum[i - 1];
	}

	// cout << sz;
	// cout << pre_sum;

	int curr_creature = 1, curr_idx = 1;
	while (curr_creature <= n) {
		long long can_eat = 2 * pre_sum[curr_idx];
		watch(can_eat);
		vector<int>::iterator low = lower_bound(sz.begin(), sz.end(), can_eat);
		if (low == sz.end()) {
			watch(curr_creature);
			cout << n - curr_creature + 1 << "\n";
			return 0;
		}

		int i = low - sz.begin();
		if (*low > can_eat) {
			--i;
		}
		watch(*low);
		watch(i);

		if (i == curr_idx) {
			++curr_creature;
			curr_idx = curr_creature;
			watch(curr_idx);
		} else {
			curr_idx = i;
		}
	}

	cout << "0\n";

	return 0;

}

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

typedef pair<int, int> pii;
typedef long long ll;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

#ifdef LOCAL
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else 
#define dump(x) true
#endif

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; }
template<class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

const int maxn = 1000010;

int A[maxn];
int two[maxn];
int B[maxn];

bool solve(int N, int v[]) {
	int x = 0;

	rep(i, N) {
		int c = two[N-1] - two[i] - two[N-1-i];
		if (c == 0) {
			x ^= v[i];
		}
	}
	return x;
}

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

	rep(i, maxn) {
		int x = i;
		while (x) {
			x /= 2;
			two[i] += x;
		}
	}

	string s; cin >> s;
	rep(i, N) A[i] = (s[i] - '0');

	{ //two?
		bool ok = 1;
		rep(i, N-1) {
			B[i] = abs(A[i+1] - A[i]);
			if (B[i] == 1) {
				ok = 0;
				break;
			}
		}
		if (ok) {
			rep(i, N-1) {
				B[i] /= 2;
			}
			ok = solve(N-1, B);
			if (ok) {
				cout << 2 << endl;
				return 0;
			} else {
				cout << 0 << endl;
				return 0;
			}
		}
	}

	//not two
	rep(i, N) A[i] %= 2;
	int pt = solve(N, A);
	cout << pt << endl;

	return 0;
}

Measured memory_bytes: 13060
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		if(A + B < C) {
			System.out.println(B + A + B + 1);
		} else {
			System.out.println(B + C);
		}
	}
}


Measured memory_bytes: 21972
#include <stdio.h>

int main(){
  int n,j=0;
  scanf("%d",&n);
  int data[n];
  
  while(j<n){
    scanf("%d",&data[j]);
    j++;
  }
  
  for(j-=1; j>=0; j--){
    printf("%d",data[j]);
    if(j) printf(" ");
  }
  printf("\n");
  
  return 0;
}

Measured memory_bytes: 600
#abc054 b
n,m=map(int,input().split())
a=[]
b=[]
for i in range(n):
    a.append(list(input()))
for i in range(m):
    b.append(list(input()))
aaa=True
for i in range(n-m+1):
    for j in range(n-m+1):
        flag=True
        for k in range(m):
            for l in range(m):
                if a[i+k][j+l]!=b[k][l]:
                    flag=False
                    continue
        if flag:
            aaa=False
            break
if aaa:
    print("No")
else:
    print("Yes")


Measured memory_bytes: 3064
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>

using namespace std;

typedef unsigned int uint;
typedef long long llong;
typedef unsigned long long ullong;
typedef long double ldouble;

typedef vector<llong> vecllong;
typedef vector<vecllong> vvecllong;

const llong MOD = 1e9 + 7;
const llong INF = 1e17;

#define FOR(i, n) for (llong i = 0; i < n; i++)
#define FORS(i, a, b) for (llong i = a; i < b; i++)
#define FORR(i, n) for (llong i = n; i > 0; i++)

struct cordinate {
    llong h, w, dist;
};

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

    llong H, W;
    cin >> H >> W;

    vector<vector<bool>> map(H + 2, vector<bool>(W + 2, false));
    vector<pair<llong, llong>> whiteList;
    vector<pair<llong, llong>> blackList;

    FORS(h, 1, H+1) {
        string line;
        cin >> line;
        FORS(w, 1, W+1) {
            if(line[w - 1] == '.') {
                map[h][w] = true;
            } else {
                blackList.push_back(make_pair(h, w));
                map[h][w] = true;
            }
        }
    }

    llong ans = 0;
    queue<cordinate> que;
    vector<vector<bool>> confilm(H + 2, vector<bool>(W + 2, false));

    FOR(i, blackList.size()) {
        que.push({blackList[i].first, blackList[i].second, 0});
    }

    while(!que.empty()) {
        cordinate now = que.front();
        que.pop();

        if(confilm[now.h][now.w]) {
            continue;
        }

        confilm[now.h][now.w] = true;
        ans = max(ans, now.dist);

        if(map[now.h - 1][now.w]) que.push({now.h - 1, now.w, now.dist + 1});
        if(map[now.h + 1][now.w]) que.push({now.h + 1, now.w, now.dist + 1});
        if(map[now.h][now.w - 1]) que.push({now.h, now.w - 1, now.dist + 1});
        if(map[now.h][now.w + 1]) que.push({now.h, now.w + 1, now.dist + 1});
    }

    cout << ans << endl;

    return 0;
}

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

int main(){
    int A,B;
    char op;

    cin >> A >> op >> B;

    if(op=='+'){
        cout << A+B << endl;
    }
    else if(op=='-'){
        cout << A-B << endl;
    }
    else{
        cout << "Error" << endl;
    }
}

Measured memory_bytes: 256
main :: IO ()
main = do
  [h1, w1] <- map read . words <$> getLine
  [h2, w2] <- map read . words <$> getLine
  print $ f h1 w1 h2 w2

f :: Int -> Int -> Int -> Int -> Int
f h1 w1 h2 w2 = h1*w1 - h2*w1 - w2*h1 + h2*w2

Measured memory_bytes: 508
/*
トポロジカルソートができる⇔DAG(閉路がない有向グラフ)である

vector<int>を引数にすることを前提にしている

edgeなどを使う場合には、eの所をe.toにする必要がある
（逆に言えばそれだけでいい）
verify:
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_4_B
参考:
https://ferin-tech.hatenablog.com/entry/2017/01/24/184750
*/

#include <bits/stdc++.h>
using namespace std;
using ll=long long int;
template<class T,class U>constexpr bool chmin(T&a,const U b){if(a<=b)return false;a=b;return true;}
template<class T,class U>constexpr bool chmax(T&a,const U b){if(a>=b)return false;a=b;return true;}

//DAGではない場合、空のvectorを返す
template<typename T>
vector<int> TopologicalSort(vector<T> &v){
    int sz=(int)v.size();
    vector<int> cnt(sz,0);
    vector<int> ret;
    stack<int> st;
    for(int i=0;i<sz;i++){
        for(auto &e:v[i]){
            cnt[e]++;
        }
    }
    for(int i=0;i<sz;i++){
        if(cnt[i]==0) st.push(i);
    }
    while(!st.empty()){
        int now=st.top(); st.pop();
        ret.push_back(now);
        for(auto &e:v[now]){
            cnt[e]--;
            if(cnt[e]==0) st.push(e);
        }
    }
    if(ret.size()!=sz) return vector<int>();
    return ret; 
}

signed main(){
    int v,e;
    cin>>v>>e;
    vector<vector<int>> g(v);
    for(int i=0;i<e;i++){
        int s,t;
        cin>>s>>t;
        g[s].push_back(t);
    }
    vector<int> ret=TopologicalSort(g);
    if(ret.size()==0){
        cout<<1<<endl;
    }else cout<<0<<endl;
}


Measured memory_bytes: 3176
N = gets.to_i
T = gets.split.map(&:to_i)
M = gets.to_i
P = []
X = []
M.times do 
  pm, xm = gets.split.map(&:to_i)
  P << pm 
  X << xm
end 

tot = T.inject(:+)
(0...M).each do |i| 
  puts tot - T[P[i] - 1] + X[i]
end


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

#define pb push_back
#define ss second
#define ff first
#define N 100005
#define inf 1000000009
#define ll long long
#define mid(a,b) (a+b)/2
#define pii pair<int,int>

using namespace std;

int n,k,r,s,p;
ll dp[N][5],ans;
string t;

int main()
{
	scanf("%d%d%d%d%d",&n,&k,&r,&s,&p);
	cin >> t;
	for(int i = 0;i < t.size();i++){
		if(t[i] == 'r')
			dp[i][1] = p;
		else if(t[i] == 'p')
			dp[i][2] = s;
		else dp[i][0] = r;
		
		if(i >= k){
			dp[i][0] += max(dp[i - k][1],dp[i - k][2]);
			dp[i][1] += max(dp[i - k][0],dp[i - k][2]);
			dp[i][2] += max(dp[i - k][0],dp[i - k][1]);
		}
	}
	for(int i = n - 1;i >= n-k;i--)
		ans += max(dp[i][0],max(dp[i][1],dp[i][2]));
	printf("%d",ans);
}

Measured memory_bytes: 4352
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>

using namespace std;

long long h;
long long ans;
long long cnt=1;
int main()
{
	scanf("%lld",&h);
	while(h>1)
	{
		ans+=cnt;
		cnt*=2;
		h/=2;
	}
	ans+=cnt;
	printf("%lld",ans);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define repp(i,n) for(int (i) = 1; (i) <= (n); ++(i))
#define popcnt __builtin_popcount
#define all(v) v.begin(),v.end()
#define _Pi 3.1415926535
#define _MOD = 1e9+7;
using namespace std;
using ll = long long;
using pint = pair<int,int>;
using itn = int;
using vint = vector<int>;
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b; return true;} return false;}
template<class T> T gcd(T a, T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a, T b){return a*b/gcd(a,b);}

int main(){
    double n,t,a; cin >> n >> t >> a;
   vector<double> h(n); rep(i,n) cin >> h[i];
    int ans = 0;
    double mn = 10000000;
    rep(i,n){
        if(chmin(mn,abs(t-h[i]*0.006-a))) ans = i;
    }
    cout << ++ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main(void){
  unsigned long long a=0,b=0,c=0,ans;
  scanf("%llu%llu%llu",&a,&b,&c);
  ans=(a*b<b*c)?(a*b<a*c)?a*b:a*c:(b*c<a*c)?b*c:a*c;
  if(a%2*b%2*c%2)printf("%llu",ans);
  else puts("0");
  return 0;
}

Measured memory_bytes: 128
//daddy's back in town, back to rolling the damn hash yoooo babeeeeees//
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define x first
#define y second
#define pi pair <int, int>
#define vi vector <int>
#define L nod<<1
#define R ((nod<<1)|1)
#define int ll
const ll mod = 998244353;
int n, m, a[88][88];
bool dp[88][88][88*88];

int32_t main(){
	ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	cin>>n>>m;
	for(int i=1; i<=n; i++) for(int j=1; j<=m; j++) cin>>a[i][j];
	for(int i=1; i<=n; i++) for(int j=1, x; j<=m; j++) cin>>x, a[i][j]-=x;
	dp[0][1][0]=1LL;
	for(int i=1; i<=n; i++){
		for(int j=1; j<=m; j++){
			for(int k=0; k<=80*80; k++){
				if(dp[i-1][j][k] || dp[i][j-1][k]){
					if(abs(k+a[i][j])<=80*80) dp[i][j][abs(k+a[i][j])]=1;
					if(abs(k-a[i][j])<=80*80) dp[i][j][abs(k-a[i][j])]=1;
				}
			}
		}
	}
	for(int k=0; ; k++) if(dp[n][m][k]) return cout<<k, 0;
}


Measured memory_bytes: 54656
#include<iostream>
#define _USE_MATH_DEFINES
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;
typedef pair<ll,ll> P;
typedef map<ll,ll> MP;
typedef priority_queue<ll> PQ;
typedef stack<ll> ST;
typedef queue<ll> QUE;
#define pb push_back
#define st first
#define nd second
#define SZ(x) ((int)(x).size())
#define FOR(i,s,n) for(int i=(int)(s); i< (int)(n); i++)
#define rep(i,n) FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
#define each(x,c) for(auto x: (c))
#define LB(x,a) lower_bound(all(x), a)
#define UB(x,a) upper_bound(all(x), a)
const ll mod=1e9+7;
const ll INF=1e18;
const double EPS=1.0e-10;
const double PI=M_PI;

struct edge{int to; ll cost;};
//隣接リスト
vector<vector<edge>> G;
//最短距離
vec d;

void dijkstra(int s){
    priority_queue<P,vector<P>,greater<P>> que;
    fill(all(d),INF); d[s]=0;
    que.push(P(0,s));

    while(!que.empty()){
        P p=que.top(); que.pop();
        int v=p.nd;
        if(d[v]<p.st) continue;
        each(e,G[v]){
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                que.push(P(d[e.to],e.to));
            }
        }
    }
}

int main(){
    int N,M; cin>>N>>M;
    d.resize(N+1), G.resize(N+1);
    rep(i,M){
        int L,R; cin>>L>>R;
        ll C; cin>>C;
        G[L].pb({R,C});
    }
    FOR(i,1,N){
        G[i+1].pb({i,0});
    }
    dijkstra(1);
    if(d[N]==INF) cout<<-1<<endl;
    else          cout<<d[N]<<endl;
    return 0;
}

Measured memory_bytes: 9340
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <queue>
#include <math.h>
#include <cmath>
#include <unordered_map>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;


// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    char C;
    std::cin >> C;
    C=C+1;
    cout<<C<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <queue>
#include <stack>
using namespace std;

const long long MOD = 1000000007;

int main(){
    int n;
    cin >> n;
    int p[n];
    for(int i = 0; i < n; i++){
        cin >> p[i];
    }
    int count = 0;
    for(int i = 1; i < n-1; i++){
        if(p[i-1] < p[i] && p[i] < p[i+1]){
            count++;
        }else if(p[i-1] > p[i] && p[i] > p[i+1]){
            count++;
        }
    }

    cout << count << endl;
    
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}

int main(){
  
  int n,m;
  cin>>n>>m;
  vector<int> a(n);
  vector<int> b(m);
  REP(i,n){
    cin>>a[i];
  }
  REP(i,m){
    cin>>b[i];
  }
  sort(ALL(a),greater<int>());
  sort(ALL(b),greater<int>());
  
  vector<int> ua,ub;
  ua = a;
  ub = b;
  ua.erase(unique(ua.begin(), ua.end()), ua.end());
  ub.erase(unique(ub.begin(), ub.end()), ub.end());
  if(ua.size()<n || ub.size()<m){
    cout<<0<<endl;
    return 0;
  }
  
  if(a[0] != n*m || b[0] != n*m){
    cout<<0<<endl;
    return 0;
  }
  
  int row_index = 0, col_index = 0;
  long long ans = 1;
  for(int i=n*m;i>=1;i--){
    while(row_index<n){
      if(row_index==n-1)break;
      if(a[row_index+1]>=i){
        row_index++;
      }else{
        break;
      }
    }
    while(col_index<m){
      if(col_index==m-1)break;
      if(b[col_index+1]>=i){
        col_index++;
      }else{
        break;
      }
    }
    
    if(a[row_index]==i && b[col_index]==i){
      ans *= 1LL;
    }else if(a[row_index]==i){
      ans *= (long long)col_index + 1LL;
      ans = mod(ans);
    }else if(b[col_index]==i){
      ans *= (long long)row_index + 1LL;
      ans = mod(ans);
    }else{
      if((1+row_index)*(1+col_index)-(n*m-i)<=0){
        ans = 0;
        break;
      }
      ans *= (1LL+(long long)row_index)*(1LL+(long long)col_index)-((long long)n*(long long)m-(long long)i);
      ans = mod(ans);
    }
  }
  
  cout<<ans<<endl;
      
  return 0;
}


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

int X;
long long gozyozu[301];
int a, b;

long long Gozyo (int x) {
  long long tmp = x;
  long long res = x;
  for (int j = 0; j < 4; j++) {
    res *= tmp;
  }
  return res;
}

int main() {
  std::cin >> X;
  for (int i = 0; i < 301; i++) {
    gozyozu[i] = Gozyo(i-150);
  }
  for (int i = -150; i < 151; i++) {
    for (int j = -150; j < 151; j++) {
      if (gozyozu[j+150]-gozyozu[i+150] == X) {
        b = i;
        a = j;
        std::cout << a << " " << b << std::endl;
        return 0;
      }   
    }
  }
  std::cout << a << "not found " << b << std::endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) (x).begin(),(x).end()
using ll = long long;
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() {
	
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	
	double l;cin >> l;

	
	
	cout << std::fixed << std::setprecision(15) << l*l*l/27 << endl;
	
	return 0;
}


Measured memory_bytes: 256
// #include <iostream>
// #include <cstring>

// using namespace std;

// int n, s;
// int dp[11][340][1 << 11];


// int dfs(int idx, int sum, int bit)
// {
//     int res = 0;

//     if (dp[idx][sum][bit] >= 0)
//         return dp[idx][sum][bit];

//     if (idx == n) {
//         if (sum == s)
//             return 1;
//         else
//             return 0;
//     }

//     for (int u = 0; u < 10; u++) {
//         if (!(bit >> u & 1)) {
//             if (sum + (idx + 1) * u <= s)
//                 res += dfs(idx + 1, sum + (idx + 1) * u, (bit | 1 << u));
//         }
//     }

//     return dp[idx][sum][bit] = res;
// }

// int main()
// {
//     while (cin >> n >> s) {
//         memset(dp, -1, sizeof(dp));
//         cout << dfs(0, 0, 0) << endl;
//     }

//     return 0;
// }
#include<iostream>
using namespace std;

int ans[12][1024];

void dfs(int bit,int d,int s){
	ans[d][s]++;
	for(int i=0;i<10;i++){
		if(bit&(1<<i))
			dfs(bit-(1<<i),d+1,s+(i*(d+1)));
	}
}

int main(){
	int n,s;
	dfs((1<<10)-1,0,0);
	while(cin>>n>>s)cout<<(s>1023?0:ans[n][s])<<endl;
}

Measured memory_bytes: 1200
n=int(input())
p_list=[-1]*n
s_list=[-1]*n
c_list=[0]*n
degree=[0]*n
depth=[0]*n
height=[0]*n
type=[0]*n
for _ in range(n):
    id,l,r=map(int,input().split())
    c_list[id]=[l,r]
    if l!=-1 and r!=-1:
        degree[id]=2
        type[id]="internal node"
        p_list[l]=id
        p_list[r]=id
        s_list[l]=r
        s_list[r]=l
    elif r!=-1:
        degree[id]=1
        type[id]="internal node"
        p_list[r]=id
        s_list[r]=l
    elif l!=-1:
        degree[id]=1
        type[id]="internal node"
        p_list[l]=id
        s_list[l]=r
    else:
        degree[id]=0
        type[id]="leaf"
root=p_list.index(-1)
type[root]="root"
def dsf1(v,d):
    if v!=-1:
        depth[v]=d
        dsf1(c_list[v][0],d+1)
        dsf1(c_list[v][1],d+1)
dsf1(root,0)
def dsf2(v):
    if c_list[v]==[-1,-1]:
        height[v]=0
    else:
        dsf2(c_list[v][0])
        dsf2(c_list[v][1])
        height[v]=max(height[c_list[v][0]],height[c_list[v][1]])+1
dsf2(root)
for i in range(n):
    print("node {}: parent = {}, sibling = {}, degree = {}, depth = {}, height = {}, {}".format(i,p_list[i],s_list[i],degree[i],depth[i],height[i],type[i]))


Measured memory_bytes: 5616
#include<stdio.h>

void InsertionSort(int N, int *A)
{
    int j, i, v;
    for(i=0;i<N;i++)
    {
        v = A[i];
        j = i-1;
        while(j>=0 && A[j]>v)
        {
            A[j+1] = A[j];
            j--;
        }
        A[j + 1]=v;
        for(int k=0;k<N;k++)
        {
            if(k>0)
            {
                printf(" ");
            }
            printf("%d",A[k]);
        }
        printf("\n");
    }
}

int main()
{
    int N;
    int A[110];
   
    scanf("%d",&N);
    for(int i=0;i<N;i++)
    {
        scanf("%d",&A[i]);
    }
    InsertionSort(N,A);
    return 0;
}


Measured memory_bytes: 2764
n=int(input())
Min=1000000001
Max=0
t=list(map(int,input().split()))
i=0
while i<n:
    if(t[i]>Max):
        Max=t[i]
    if(t[i]<Min):
        Min=t[i]
    i=i+1
print(Max-Min)


Measured memory_bytes: 3060
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<bitset>
#include<numeric>
#define INF 1e+100
#define EPS 1e-9
#define PB push_back
#define fi first
#define se second
#define reps(i,j,k) for(int i = j; i < k; i++)
#define rep(i,j) reps(i,0,j)
using namespace std;
const int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
typedef long long ll;
typedef pair<int,int> Pii;
class Data{
    public:
    int id;
    int dist;
    int money;
    Data(){}
    Data(int a,int b,int c){
        id = a;
        dist = b;
        money = c;
    }
};
vector < Data > D;
double dp[16][1<<16];
vector < int > path[16][1<<16];
vector < int > ans;
int main(){
    int n;
    scanf("%d",&n);
    rep(i,n){
        int x,y,z;
        scanf("%d%d%d",&x,&y,&z);
        D.PB(Data(x,y,z));
    }
    int weight[1<<16];
    double cost[16][16];
    rep(i,n){
        rep(j,1<<n){
            dp[i][j] = INF;
        }
    }
    rep(i,n){
        rep(j,n){
            cost[i][j] = (double)abs(D[i].dist-D[j].dist);
        }
    }
    rep(i,n){
        dp[i][1<<i] = 0;
        path[i][1<<i].PB(i);
    }
    rep(i,1<<n){
        int res = 0;
        rep(j,n){
            if(i>>j&1)res += D[j].money;
        }
        weight[i] = 20*res;
    }
    rep(i,1<<n){
        double res = (double)2000.0/(70+weight[i]);
        rep(j,n){
            int now = 1<<j;
            if((now&i)!=0){
                rep(k,n){
                    int next = 1<<k;
                    if((next&i)<=0){
                        double sub=cost[j][k]/res;
                        if(dp[k][i|next] > dp[j][i]+sub){
                            dp[k][i|next] = dp[j][i]+sub;
                            path[k][i|next] = path[j][i];
                            path[k][i|next].PB(k);
                        }
                    }
                }
            }
        }
    }
    double mi = INF;
    int len;
    rep(i,n){
        if(mi > dp[i][(1<<n)-1]){
            mi = dp[i][(1<<n)-1];
            ans = path[i][(1<<n)-1];
        }
    }
    len=ans.size();
    rep(i,len){
        printf("%d%c",D[ans[i]].id,i==len-1?'\n':' ');
    }
    return 0;
}

Measured memory_bytes: 50432
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>

using namespace std;

const int MAXN = 300 + 10;
const int MOD = 1000000000 + 7;

int n, m;
vector<pair<int, int> > lim[MAXN];
int f[MAXN][MAXN][MAXN];

void work()
{
	int ans = 0;
	f[0][0][0] = 1;
	for(int x = 0; x <= n; x++)
		for(int y = 0; y <= n; y++)
			for(int z = 0; z <= n; z++)
			{
				int r = max(x, max(y, z));
				for(int i = 0; i < lim[r].size(); i++)
				{
					int tmp = (lim[r][i].first <= x) + (lim[r][i].first <= y) + (lim[r][i].first <= z);
					if(tmp != lim[r][i].second)
						f[x][y][z] = 0;
				}
				if(r == n)
				{
					ans = (ans + f[x][y][z]) % MOD;
					continue;
				}
				f[r + 1][y][z] = (f[r + 1][y][z] + f[x][y][z]) % MOD;
				f[x][r + 1][z] = (f[x][r + 1][z] + f[x][y][z]) % MOD;
				f[x][y][r + 1] = (f[x][y][r + 1] + f[x][y][z]) % MOD;
			}
	cout << ans << endl;
}

int main()
{
	ios::sync_with_stdio(false);
	// freopen("1.in", "r", stdin);
	// freopen("1.out", "w", stdout);

	cin >> n >> m;
	for(int i = 1; i <= m; i++)
	{
		int l, r, x;
		cin >> l >> r >> x;
		lim[r].push_back(make_pair(l, x));
	}

	work();

	return 0;
}


Measured memory_bytes: 114944
import java.util.Scanner;
import java.util.Collections;
import java.util.List;
import java.util.ArrayList;
public class Main {
  public static void main(String... args) {
    Scanner scan = new Scanner(System.in);
    int count = scan.nextInt();
    List<Integer> list = new ArrayList<>();
    while (scan.hasNextInt()) {
      list.add(scan.nextInt());
    }
    Collections.sort(list);
    double x = 0;
    for (int num : list) {
      x = x==0?num:(num+x)/2;
    }
    System.out.println(x);
  }
}

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

using namespace std;

#define countof(a) (sizeof(a)/sizeof(*a))

#define vi vector<int>
#define vvi vector<vector<int> >
#define vpi vector<pi >
#define pi pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define all(n) n.begin(), n.end()

#define FROMTO(var, from, to) for (register int var = (from), var##down = ((int)(to)) < ((int)(from));var##down ? (var >= (int)(to)) : (var <= (int)(to));var##down ? var-- : var++)
#define UPTO(var, from, to)   for (register int var = (from); var <= ((int)to); var++)
#define DOWNTO(var, from, to) for (register int var = (from); var >= ((int)to); var--)
#define FOR(var, to)          UPTO(var, 0, (to)-1)
#define DOWN(var, from)       DOWNTO(var, (from)-1, 0) 

#define INIT(var, val) FOR(i,countof(var)) var[i] = val
#define INPUT(var) FOR(i,countof(var)) cin >> var[i]
#define INPUT1(var) FOR(i,countof(var)) cin >> var[i], var[i]--

#define SORT(v) qsort(v,countof(v),sizeof(*v),int_less)
#define SORTT(v) qsort(v,countof(v),sizeof(*v),int_greater)
#define QSORT(v,b) qsort(v,countof(v),sizeof(*v),b)

#define MOD 1000000007
#define INF ((1 << 30)-1)
#define LINF ((1LL << 62)-1)

typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;

struct Comb {
    vector<vector<s64> > data;
    Comb(int n) { // O(n^2)
        data = vector<vector<s64> >(n+1,vector<s64>(n+1,1));
        UPTO(i,1,n) {
            FOR(j,i+1) {
                if (!j || j == i) data[i][j] = 1;
                else data[i][j] = data[i-1][j-1] + data[i-1][j];
            }
        }
    }
    
    s64 ncr(int n, int r) {
        return data[n][r];
    }
};

static inline int ri() {
  int a;
  scanf("%d", &a);
  return a;
}

int int_less(const void *a, const void *b) {
  return (*((const int*)a) - *((const int*)b));
}
int int_greater(const void *a, const void *b) {
  return (*((const int*)b) - *((const int*)a));
}

int main() {
	string a,b; cin >> a >> b;
	if (a.size() != b.size()) {
		cout << (a.size()<b.size() ? "LESS" : "GREATER") << endl;
		return 0;
	}
	int r = strcmp(a.c_str(), b.c_str());
	if (!r) cout << "EQUAL" << endl;
	else if (r > 0) cout << "GREATER" << endl;
	else cout << "LESS" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 9223372036854775807;
const ll mininf = -9223372036854775807;
const ll nax = 0;
int n, a, b;
string s;

int main(){
	cin >> n >> a >> b;
	ll lolos=0;
	int overseas=1;
	char arr[n+5];
	cin >> arr;
	for(int i=1;i<=n;i++){
		if(arr[i-1]=='c'){
			cout << "No" << '\n';
		}
		else if(arr[i-1]=='a'){
			if(lolos<a+b){
				cout << "Yes" << '\n';
				lolos++;
			}
			else{
				cout << "No" << '\n';
			}
		}
		else{	
			if(overseas<=b&&lolos<a+b){
				overseas++;
				lolos++;
				cout << "Yes" << '\n';
			}
			else{
				cout << "No" << '\n';
			}
		}
	}
	return 0;
}

Measured memory_bytes: 768
from collections import deque
n = int(input())
stack = deque()
ans =[]
while n > 0:
    if 1<= n <= 26:
        stack.append(n)
        break
    mod = n%26
    if mod == 0:
        mod = 26
    stack.append(mod)
    if mod == 26:
        n = (n//26) - 1
    else:
        n = n//26
while stack:
    tmp = stack.pop()
    alp = chr(tmp+96)
    ans.append(alp)
anss = ''.join(ans)
print(anss)

Measured memory_bytes: 9424
D = int(input())
c = list(map(int, input().split()))
s = []
for i in range(D):
    s.append(list(map(int, input().split())))

def getGreedy():
    t = []
    last = [-1 for _ in range(26)]
    for d in range(D):
        v_max = -1
        t_max = -1
        for t_ in range(26):
            v_ = 0
            v_ += s[d][t_]
            last[t_]=d
            for i in range(26):
                v_ -= c[i] * (d - last[i])
            if v_ > v_max or t_ == 0:
                t_max = t_
                v_max = v_
        t.append(t_max+1)
    return t
def printResult(t):
    for tt in t:
        print(tt)
def calc(t):
    v = 0
    last = [-1 for _ in range(26)]
    for d in range(D):
        v += s[d][t[d]]
        last[t[d]]=d
        for i in range(26):
            v -= c[i] * (d - last[i])
    return v

t = getGreedy()
printResult(t)
# while 時間のある限り:
#     d と q をランダムに選ぶ。
#     old = t[d] # 後で戻せるように元の値を記憶しておく
#     t[d] = q
#     if 変形前より解が悪化:
#         t[d] = old

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

int main()
{
 int n,i;
 cin>>n;
 set<string>s;
  for(i=0;i<n;i++)
  {
      string r;
      cin>>r;
      s.insert(r);
  }
  cout<<s.size()<<endl;
 return 0;

}


Measured memory_bytes: 19148
import java.util.Scanner;

class Main{



	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		int N= sc.nextInt();
		int ans = 0;
		for(int i = 1;i <= N;i= i+2){
			int count = 0;
			for(int j = 1;j <= N;j++){
				if(i%j == 0){
					count++;
				}
			}
			if(count == 8){
				ans++;
			}
		}
			System.out.println(ans);
		
	
	}


}

class Pair implements Comparable{
	int from;		//p
	int end;		//y
	int num;
	int bango;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return from - otherpair.from;
	}
}



Measured memory_bytes: 23124
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

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

    for(int i = 0;i < N;i++)
        cin >> A.at(i);
    sort(A.begin(),A.end());

    for(int i = 0;i < K;i++)
        ans += A.at(i);

    cout << ans << endl;
    
    
}

Measured memory_bytes: 3628
n,m=map(int,input().split())
ks=[[] for i in range(m)]
for i in range(m):
    ks[i]=list(map(int,input().split()))
p=list(map(int,input().split()))
ans=0
for i in range(2**n):
    a=[0 for _ in range(n)]
    for j in range(n):
        if (i>>j)&1:
            a[j]=1
    f=0
    for j in range(m):
        x=0
        for q in range(ks[j][0]):
            
            if a[ks[j][q+1]-1]==1:
                x+=1
        if x%2==p[j]:
            f+=1
    if f==m:
        ans+=1
print(ans)
        
        
        
            
    

    
    

        


Measured memory_bytes: 68960
def solve():
    N = int(input())
    c = [int(i) for i in input().split()]

    if N == 1:
        return c[0] *2
    r = c[0]*2
    x = [c[0]]
    for i in range(1,N):
        r_ = c[i]
        r_n = r_
        for j in range(i):
            b = c[j]
            x_= x[j]

            dt = 2 * ((r_*b)**(1/2))
            x_ += dt
            r_n = max(r_n,x_)
        x.append(r_n)
        if r < r_n + r_:
            r = r_n +r_
    #print(x)
    return r
    
print(solve())



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

string m[3];

string solve(){
	for(int i=0 ; i < 3 ; i++ ){
		if( m[i] == "bbb" )
			return "b";
		if( m[i] == "www" )
			return "w";
		if( m[0][i] == 'b' && m[1][i] == 'b' && m[2][i] == 'b' )
			return "b";
		if( m[0][i] == 'w' && m[1][i] == 'w' && m[2][i] == 'w' )
			return "w";
	}
	if( m[0][0] == 'b' && m[1][1] == 'b' && m[2][2] == 'b' )
		return "b";
	if( m[0][0] == 'w' && m[1][1] == 'w' && m[2][2] == 'w' )
		return "w";
	if( m[0][2] == 'b' && m[1][1] == 'b' && m[2][0] == 'b' )
		return "b";
	if( m[0][2] == 'w' && m[1][1] == 'w' && m[2][0] == 'w' )
		return "w";
	return "NA";
}

int main(){
	string s;
	while( cin >> s , s != "0" ){
		m[0] = s;
		cin >> s;
		m[1] = s;
		cin >> s;
		m[2] = s;
		cout << solve() << endl;
	}
}

Measured memory_bytes: 0
def dp(d,i):
    if sum(d)==n-1:return 1
    x=0
    for j in l[i]:
        if d[j-2]==1:continue
        di=d[:]
        di[j-2]=1
        x+=dp(di,j)
    return x
        
n,m=map(int,input().split())
l=[[] for _ in range(n+1)]
for i in range(m):
    a,b=map(int,input().split())
    if b!=1:l[a].append(b)
    if a!=1:l[b].append(a)
print(dp([0]*(n-1),1))

Measured memory_bytes: 3064
s = str(input())
N = len(s)

for i in range(N-1):
  if s[i] == s[i+1]:
    print(i+1, i+2)
    exit()

for i in range(N-2):
  if s[i] == s[i+2]:
    print(i+1, i+3)
    exit()
    
print(-1, -1)

Measured memory_bytes: 9184
#include<stdio.h>
int main(void){
  int i,n,j,min;
  double a[50],cmp,sum=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%lf",&a[i]);
  }
  for(i=0;i<n-1;i++){
    min=i;
    for(j=i+1;j<n;j++){
      if(a[j]<a[min]){
        min=j;
      }
    }
    cmp=a[i];
    a[i]=a[min];
    a[min]=cmp;
  }
  sum=a[0];
  for(i=1;i<n;i++){
    sum+=a[i];
    sum/=2;
  }
  printf("%lf\n",sum);
  return(0);
}


Measured memory_bytes: 128
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner scn = new Scanner(System.in);
		int row,col;
		int[] cols;
		int cnt_min;

		while(true){
			cnt_min = 10*10000;
			row = scn.nextInt();
			col = scn.nextInt();
			
			if(row==0&&col==0) break;
			
			cols = new int[col];
	
			for(int i=0; i<row; i++) for(int j=0; j<col; j++)
				cols[j] = (cols[j]<<1)+scn.nextInt();
	
			for(int i=0; i<(1<<(row-1)); i++){
				int cnt=0;
				for(int column : cols){
					int tmp=0;
					column=column^i;
					for(int j=0; j<row; j++){
						tmp += column&1;
						column >>= 1;
					}
					cnt += (tmp<(row-tmp))?tmp:(row-tmp);
				}
				cnt_min = (cnt<cnt_min)?cnt:cnt_min;
			}
	
			System.out.println(row*col-cnt_min);
		}
	}
}

Measured memory_bytes: 12000
from collections import Counter
h,w = map(int,input().split())
n=10
c_input = [list(map(int,input().split())) for i in range(10)]
a_input = [int(j) for i in range(h) for j in input().split() if int(j)!=-1]

a_count = Counter(a_input)

dp=[[float('inf') for i in range(n)]for i in range(n)]

for k in range(n):
    for i in range(n):
        for j in range(n):
            c_input[i][j] = min(c_input[i][j],c_input[i][k]+c_input[k][j])
ans=0
for k,v in a_count.items():
    ans+=c_input[k][1]*v
print(ans)

Measured memory_bytes: 3728
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author cherrypi59
 */

#pragma GCC optimize ("O2")
#pragma GCC optimize ("tree-vectorize")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FFOR(i, a, b) FOR(i, a, b+1)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 1, n+1)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define LEN(x) (int)(x).size()
#define DUMP(x) cerr<<__LINE__<<' '<<#x<<"="<<(x)<<endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

using namespace std;
using lint = long long;
using pii =  pair<int, int>;
using pll =  pair<lint, lint>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vector<T>>;
template <typename T> inline bool chmax(T &a, T b){if(a<b){a = b; return true;} return false;}
template <typename T> inline bool chmin(T &a, T b){if(a>b){a = b; return true;} return false;}

constexpr lint ten(int n) {return n==0 ? 1 : ten(n-1)*10;}

class CWalkOnMultiplicationTable {
public:
    void solve(std::istream& in, std::ostream& out){
        ios_base::sync_with_stdio(false);
        in.tie(nullptr), out.tie(nullptr);
        lint N, ans = ten(18);
        in>>N;
        for(lint i=1;i*i<=N;++i){
            if(N%i==0){
                chmin(ans, i+N/i-2);
            }
        }
        out<<ans<<'\n';
    }
};


int main() {
	CWalkOnMultiplicationTable solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <cmath>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
typedef long long ll;
using namespace std;
int main(){
    ll n;
    cin>>n;
    string s;
    s = to_string(n);
    ll hoge = 0;
    ll piyo = n;
    rep(i,1,s.size()){
        hoge += n%10;
        n = n / 10;
    }

    if(piyo%hoge==0) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

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

using namespace std;
int main(){
	string str,order,space ;
	char temp;
	int q,a,b;
	cin>> str ;
	cin>> q;
	for(int i=0;i<q;i++){
		cin >> order;
		if (order =="print"){
			cin >> a >> b;
			for(int j=a;j<=b;j++){
				cout << str[j];
			}
			cout << "\n";
		}
		
		else if(order == "replace"){
			cin >> a >> b ;
			cin >> space;
			for(int j=a;j<=b;j++){
				str[j]=space[j-a];
			}
		}
		
		else {
			cin >> a >>b ;
			for(int j=0;j<(b-a+1)/2;j++){
					temp=str[a+j];
					str[a+j]=str[b-j];
					str[b-j]=temp;
			}
		}

	}

		return 0;
}

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

int main(){
    int n,x,t;
    cin >> n >> x >> t;
    int ans = n/x*t;
    if(n%x!=0) ans += t;
    cout << ans << endl;
}

Measured memory_bytes: 3632
def switches(N: int, M: int, sw: list, P: list)->int:
    count = 1 << N
    sw_state = [0] * N
    li_state = [0] * M
    for i in range(1 << N):
        for j in range(N):
            sw_state[j] = 1 if (i & 1) != 0 else 0
            i >>= 1

        for m in range(M):
            li_state[m] = 0
            for si in sw[m][1:]:
                li_state[m] += sw_state[si-1]

            if li_state[m] % 2 != P[m]:
                break
        else:
            continue

        count -= 1

    return count


if __name__ == "__main__":
    M = 0

    N, M = map(int, input().split())
    sw = [[int(s) for s in input().split()] for _ in range(M)]
    P = [int(s) for s in input().split()]

    ans = switches(N, M, sw, P)
    print(ans)


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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { std::cout << #a << " = " << a << "\n"; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T, class V> istream& operator>> (istream& ist, pair<T, V>& p) { return ist >> p.first >> p.second; }
template<class T> ostream& operator<< (ostream& ost, pair<T, T>& p) { return ost << p.first << ", " << p.second; }
template<class T> istream& operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) ist >> e; return ist; }

typedef long long ll;
int const inf = INT_MAX / 2;

auto prime_factor = [](ll x){map<ll, int> xfact;for(int i=2; (ll)i*i<=x; i++) {while(x % i == 0) {xfact[i]++;x /= i;}}if(x > 1) xfact[x]++;return std::move(xfact);};

int main() {
  unsigned long long A, B; cin >> A >> B;
  auto G = __gcd(A, B);
  auto m = prime_factor(G);
  cout << m.size() + 1 << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;

/*
*/

ll n,k;
double dp[100010],ans=0;

void init(){
	cin>>n>>k;
}

int main(void){
	init();
	ireg(i,1,k-1){
		if(i*2>=k){
			dp[i]=1.0/2;
		}else{
			dp[i]=dp[i*2]/2;
		}
	}
	reg(i,1,n){
		if(i>=k){
			ans+=1.0/n;
		}else{
			ans+=dp[i]/n;
		}
	}
	cout<<fixed<<setprecision(15)<<ans<<endl;
	return 0;
}

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

using namespace std;

typedef long long int ll;
typedef long double ld;

int main() {
    //freopen("input.txt", "r", stdin);

    int n;
    string s;
    cin >> n >> s;

    deque < int > dq;
    int fr, ba;
    fr = ba = 0;

    for(int i = 0; i < n; i++) {
        if(s[i] == '(') {
            dq.push_back(1);
        } else {
            if(dq.empty()) {
                fr++;
            } else {
                dq.pop_back();
            }
        }
    }

    ba = dq.size();

    for(int i = 1; i <= fr; i++) cout << '(';
    cout << s;
    for(int i = 1; i <= ba; i++) cout << ')';

    cout << "\n"; return 0;
}


Measured memory_bytes: 256
import sys
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

h, w = na()
s = nsn(h)

l = [[0] * w for _ in range(h)]
r = [[0] * w for _ in range(h)]
u = [[0] * w for _ in range(h)]
d = [[0] * w for _ in range(h)]

for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            l[i][j] = 0
            u[i][j] = 0
        else:
            if j == 0:
                l[i][j] = 1
            else:
                l[i][j] = l[i][j - 1] + 1
            
            if i == 0:
                u[i][j] = 1
            else:
                u[i][j] = u[i - 1][j] + 1

for i in range(h - 1, -1, -1):
    for j in range(w - 1, -1, -1):
        if s[i][j] == '#':
            r[i][j] = 0
            d[i][j] = 0
        else:
            if j == w - 1:
                r[i][j] = 1
            else:
                r[i][j] = r[i][j + 1] + 1
            
            if i == h - 1:
                d[i][j] = 1
            else:
                d[i][j] = d[i + 1][j] + 1

ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans, l[i][j] + r[i][j] + u[i][j] + d[i][j] - 3)

print(ans)

Measured memory_bytes: 176648
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue>
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <iomanip> // std::std::setprecision(X)
#include <limits>  //std::numeric_limits<int>::max(), min()

typedef long long ll;

int main (void) {
  int N, K; std::cin >> N >> K;
  if ( N % K == 0 ) std::cout << 0 << std::endl;
  else std::cout << 1 << std::endl;
  return 0;
}


Measured memory_bytes: 256