akhauriyash/Code-Regression huggingface dataset:
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

const ll INF = 1LL << 50;

static const long long mod = 1000000007;

ll const siz = 1LL << 21;
ll const ofst = siz >> 1LL;
vvll seg(siz, vll(26, 0));

void change(ll i, char c) {
  i += ofst;
  rep(ii, 26) seg[i][ii] = (ii == c - 'a');
  while (true) {
    i /= 2;
    if (i == 0) break;
    rep(ii, 26) seg[i][ii] = seg[2 * i][ii] + seg[2 * i + 1][ii];
  }
}

ll get(ll l, ll r) {
  vll ans(26, 0);
  l += ofst, r += ofst + 1;
  while (l < r) {
    if (l % 2 == 1) {
      rep(ii, 26) ans[ii] += seg[l][ii];
      l++;
    }
    l /= 2;
    if (r % 2 == 1) {
      rep(ii, 26) ans[ii] += seg[r - 1][ii];
      r--;
    }
    r /= 2;
  }
  ll ret = 0;
  rep(ii, 26) ret += (ans[ii] > 0);
  return ret;
}

int main() {
  ll n, q;
  string s;
  cin >> n >> s >> q;

  rep(i, n) change(i, s[i]);

  rep(i, q) {
    ll t;
    cin >> t;
    if (t == 1) {
      ll i;
      char c;
      cin >> i >> c;
      i--;
      change(i, c);
    } else {
      ll l, r;
      cin >> l >> r;
      l--;
      r--;
      cout << get(l, r) << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 510852
N=int(input())
A=[0 for i in range(N)]
B=[0 for i in range(N)]
for i in range(N):
    A[i],B[i]=map(int,input().split())
X=sorted([(B[i]+A[i],A[i],B[i],i) for i in range(N)])
Y=sorted([(A[i]+B[i],B[i],A[i],i) for i in range(N)])
used=[0 for i in range(N)]
tkhs=0
aoki=0
while(len(X)>0 and len(Y)>0):
    while(True):
        if len(X)>0 and used[X[-1][3]]==1:
            X.pop()
        else:
            break
    if len(X)==0:
        break
    tkhs+=X[-1][1]
    used[X[-1][3]]=1
    X.pop()
    while(True):
        if len(Y)>0 and used[Y[-1][3]]==1:
            Y.pop()
        else:
            break
    if len(Y)==0:
        break
    aoki+=Y[-1][1]
    used[Y[-1][3]]=1
    Y.pop()
print(tkhs-aoki)


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

int main(){
	float pi=3.14;
	int r;
	cin >> r;

	int circleArea = (int)pi*r*r;
	int unitCircleArea = (int)pi*1*1;
	int multipleNumber = circleArea/unitCircleArea;

	cout <<  multipleNumber;
	return 0;
}

Measured memory_bytes: 256
void main()
{
    long[] tmp = rdRow;
    long n = tmp[0], m = tmp[1];
    long[] a = rdRow;

    long rem;
    long[long] lists;
    lists[0] = 1;
    long result;
    foreach (x; a)
    {
        rem = (rem + x) % m;
        result += lists[rem]++;
    }

    result.writeln;
}

enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;

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

using namespace std;

const int maxn = 510;

int ans = 0, n;

int dis[maxn][maxn], oc[maxn][maxn];
int p[maxn * maxn];

void upd(int x, int y) {
	if (x - 1 >= 1 && dis[x-1][y] > oc[x-1][y] + dis[x][y]) {
		dis[x-1][y] = oc[x-1][y] + dis[x][y];
		upd(x-1, y);
	}
	if (x + 1 <= n && dis[x+1][y] > oc[x+1][y] + dis[x][y]) {
		dis[x+1][y] = oc[x+1][y] + dis[x][y];
		upd(x+1, y);
	}
	if (y - 1 >= 1 && dis[x][y-1] > oc[x][y-1] + dis[x][y]) {
		dis[x][y-1] = oc[x][y-1] + dis[x][y];
		upd(x, y-1);
	}
	if (y + 1 <= n && dis[x][y+1] > oc[x][y+1] + dis[x][y]) {
		dis[x][y+1] = oc[x][y+1] + dis[x][y];
		upd(x, y+1);
	}
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n * n; i++) scanf("%d", &p[i]);
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			oc[i][j] = 1;
			dis[i][j] = min(min(i, j), min(n-i+1, n-j+1));
		}
	}
	for (int i = 1; i <= n*n; i++) {
		int x = (p[i] - 1) / n + 1;
		int y = (p[i] - 1) % n + 1;
		oc[x][y] = 0, -- dis[x][y];
		upd(x, y);
		ans += dis[x][y];
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 29420
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>

using namespace std;
using ll = long long;

#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)
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;}
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
/*----------------------------------------------------------------------------------*/

// mod pにおけるi(1<=i<=n)の逆元
vector<ll> list_minv(ll n, ll m) {
    vector<ll> inv(n + 1);
    inv[1] = 1;
    for (int i = 2; i <= n; ++i) {
        inv[i] = inv[m % i] * (m - m / i) % m;
    }
    return inv;
}

int main() {
    int n; cin >> n;
    vector<int> x(n);
    rep(i,n) cin >> x[i];
    const ll mod = 1e9+7;

    vector<ll> inv;
    inv = list_minv(n, mod);

    vector<ll> kaijo(n+1);
    kaijo[1] = 1;
    repf(i,1,n) kaijo[i+1] = (kaijo[i]*(i+1))%mod;
    
    ll p = 0;
    ll ans = 0;
    repf(i,1,n) {
        p = (p+kaijo[n-1]*inv[i]%mod)%mod;
        (ans += p*(x[i]-x[i-1])) %= mod;
        // cout << p << ' ' << kaijo[n-1] << endl;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
ll modpow(ll a, ll n) {
    ll res = 1;
    while(n > 0) {
        if(n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }

    return res;
}

ll comb(ll a, ll b) {
    ll ans = 1;

    for(ll i = a; i > a - b; i--) {
        ans = ans * i % mod;
    }
    for(ll i = 1; i <= b; i++) {
        ans = (ans * modpow(i, mod - 2)) % mod;
    }
    return ans;
}

int main() {
    int N, A, B;
    cin >> N >> A >> B;

    cout << (modpow(2, N) % mod - comb(N, A) % mod - comb(N, B) % mod - 1 + mod + mod) % mod;
    return 0;
}

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

int main(){
  ll a, b, i, ans = 0;
  cin >> a >> b;
  if(a < b){
    rep(i, b){
      ans *= 10;
      ans += a;
    }
  } else {
    rep(i, a){
      ans *= 10;
      ans += b;
    }
  }
  
  cout << ans << endl;
  return 0;
}

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

/*
7 5 2
2 1 4 3 5 6 7

7 5 3
7 6 1 2 3 4 5

*/

int main() {
  ll n, a, b;
  cin >> n >> a >> b;
  if (1ll * a * b < n) return puts("-1"), 0;
  if (a + b > n + 1) return puts("-1"), 0;
  if (a == 1) {
    int f = 0;
    for (int i = n; i; i--) {
      if (f++) putchar(' ');
      printf("%d", i);
    }
    return 0;
  }
  int x = (n - b) / (a - 1);
  vector<int> res;
  for (int i = b; i; i--) res.push_back(i);
  int pos = b;
  for (int i = 1; i < a; i++) {
    int cnt = x + (i <= (n - b) % (a - 1));
    for (int j = cnt; j; j--) res.push_back(pos + j);
    pos += cnt;
  }
  int f = 0;
  for (auto &x : res) {
    if (f++) putchar(' ');
    printf("%d", x);
  }
  puts("");
  return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

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

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long N,i;
    cin >> N;
    long long A[N];

    long long cnt = 0;
    cin>>A[0];
    long long MAX = A[0];
  for(i=1;i<N;i++){
      cin>>A[i];
      if(A[i]>MAX){
        MAX = A[i];
      }else{
        cnt += MAX - A[i];
      }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 5116
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
int main(void){
	int n, t;
	cin >> n >> t;
	vector<P> d;
	int f = 0;
	for(int i = 0; i < n; i++){
		int a, b;
		cin >> a >> b;
		if(b <= t) d.push_back(P(a, b)), f = 1;
	}
	if(f){
		sort(d.begin(), d.end()); 
		cout << d[0].first << endl;
	}
	else cout << "TLE" << endl;
	return 0;
}

Measured memory_bytes: 256
import itertools
N = int(input())
item = []
for i in range(N):
    A = int(input())
    s = []
    for ii in range(A):
        x, y = map(int, input().split())
        s.append((x, y))
    item.append(s)

Ps = itertools.product([0, 1], repeat=N)
ans = 0
for P in Ps:
    right = True
    for i, p in enumerate(P):
        if p == 1:
            for x, y in item[i]:
                if (y == 1 and P[x - 1] == 0) or (y == 0 and P[x - 1] == 1):
                    right = False
    if right:
        ans = max(ans, sum(P))

print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<stack> 
#include<queue>
#include<cmath>
#include<map>
#include<set>
#define LL long long
#define N 100100
#define MOD 1000000007
#define FOR(i,l,r) for (int i = (l); i <= (r); i ++)
#define CLR(a,x) memset(a,x,sizeof(a))
#define INF 0x7fffffff
#define pb push_back
#define X first
#define Y second
using namespace std;
int a[N],d[N];
int main(){
	int n;
	scanf("%d",&n);
	LL sum = 0;
	FOR(i,1,n){
		scanf("%d",&a[i]);
		sum += (LL)a[i];
	}
	LL s = (LL)(1 + n) * n / 2;
	if (sum % s != 0) printf("NO\n");
	else{
		a[n + 1] = a[1];
		int flag = 1;
		FOR(i,1,n){
			d[i] = a[i] - a[i + 1];
			LL t = sum / s;
			if ((d[i] + t) % n != 0 || d[i] + t < 0){
			   flag = 0;
			   break;
			}
		}
		if (flag) printf("YES\n");
		else printf("NO\n");
	}
	
}

Measured memory_bytes: 1024
# Problem https://atcoder.jp/contests/abc081/tasks/abc081_b
# Reference https://www.javadrive.jp/ruby/array/index3.html
# Reference https://atcoder.jp/contests/abc081/submissions/8063993
# Ruby 1st Try
N = gets.to_i 
A = gets.chomp.split(' ').map(&:to_i)
# p A
# p A.size
oddFlag = false
answer = 0
while true
   for j in 0..(N-1) do
     data = A[j]
     mod = data % 2
    if (mod != 0) 
        oddFlag = true
    end
   end
   if(oddFlag) 
        break
   else
    answer=answer+1
   end
   for j in 0..(N-1) do
       A[j] = A[j] / 2
   end
end
puts(answer)

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

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define PN printf("\n")
#define MODV 1000000007

typedef long long ll;
typedef double dbl;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
void addmod(int &a, ll b){a=(a+b); if(a>=MODV)a-=MODV;}
void mulmod(int &a, ll b){a=(a*b)%MODV;}
template<class T>bool domin(T &a, const T &b){return a>b?a=b,1:0;}
template<class T>bool domax(T &a, const T &b){return a<b?a=b,1:0;}
int gi(){int a;scanf("%d",&a);return a;}
ll gll(){ll a;scanf("%lld",&a);return a;}

int main() {
  int n=gi();
  ll a=gi(), b=gi();
  vll h(n);
  for(auto i=0;i<n;i++){ h[i]=gi(); }
  sort(h.begin(), h.end());
  ll lo=0, hi=MODV, md;
  while(lo+1<hi){
    md=(lo+hi)/2;
    ll tt=0;
    for(int i=0;i<n;i++)
    if(b*md<h[i]){
     ll t = h[i]-b*md;
     tt+=((t-1)/(a-b)+1);
    }
    if(tt<=md)hi=md;
    else lo=md;
  }
  cout<<hi<<endl;

  return 0;
}

Measured memory_bytes: 1024
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <iostream>

using namespace std;

int main() {
    long N, Q;
    cin >> N >> Q;
    //priority_queue<vector<long>, vector<vector<long>>, greater<vector<long>>> tl;
    vector<vector<long>> tl {};
    for (int i=0; i<N; i++) {
        long S, T, X;
        cin >> S >> T >> X;
        tl.push_back({T-X, 0, X});
        tl.push_back({S-X, 1, X});
    }
    for (int i=0; i<Q; i++) {
        long D;
        cin >> D;
        tl.push_back({D, 2, 0});
    }
    sort(tl.begin(), tl.end());

    vector<long> ans {};
    multiset<long> Xset {};
    for (auto itl=tl.begin(); itl!=tl.end(); itl++) {
        long mode = (*itl)[1];
        long X = (*itl)[2];
        //cout << t[0] << ' ' << mode << ' ' << X << endl;
        if (mode == 0) {
            // T
            Xset.erase(X);
        } else if (mode == 1) {
            // S
            Xset.insert(X);
        } else {
            // D
            if (not Xset.empty()) {
                auto it = Xset.begin();
                ans.push_back(*it);
            } else {
                ans.push_back(-1);
            }
        }
    }

    for (auto it=ans.begin(); it!=ans.end(); it++) {
        cout << *it << endl;
    }
}


Measured memory_bytes: 47652
n = int(input())
G = [[] for i in range(n+1)] #G(i): 頂点iと隣接する頂点のlist
for i in range(n):
    a = [int(i) for i in input().split()]
    G[a[0]] = a[2:]
    G[a[0]].sort()

d = [0] * (n+1)
f = [0] * (n+1)

seen = [0] * (n+1) #頂点iが訪問済みの場合 seen[i] = 1
t = 0

def dfs(s):
    global t
    seen[s] = 1
    d[s] = t
    for i in G[s]:
        if seen[i] == 0:
            t += 1
            dfs(i)
    t += 1
    f[s] = t

for i in range(1, n+1):
    if not seen[i]:
        t += 1
        dfs(i)

for i in range(1, n+1):
    print(i, d[i], f[i])


Measured memory_bytes: 5652
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstdlib>
#include <cstring>

using namespace std;

// from,toÌpair
typedef pair<int,int> P;

int getTime(string time){
	int hour=atoi(time.substr(0,2).c_str());
	int minute=atoi(time.substr(2,2).c_str());
	return hour*60+minute;
}

int main(){

	int n;
	string start,fin;
	while(cin>>n>>start>>fin&&!(n==0&&start=="0"&&fin=="0")){
		int maxTime=0;
		vector<P> bangumis[1001];
		int st,ft;
		st=getTime(start);
		ft=getTime(fin);
		for(int i = 0; i < n; i++){
			int t;
			cin>>t;

			int bs=st;
			string tmp;
			cin>>tmp;
			int bf=getTime(tmp);
			bangumis[i].push_back(make_pair(bs,bf));

			for(int j = 0; j < t-1; j++){
				P p;
				string s1,s2;
				cin>>s1>>s2;
				bs=getTime(s1);
				bf=getTime(s2);
				bangumis[i].push_back(make_pair(bs,bf));
			}
			cin>>tmp;
			bs=getTime(tmp);
			bf=ft;
			bangumis[i].push_back(make_pair(bs,bf));
		}

		// ¢Ü»ê¼êÌ`lÌÇ±ÜÅ²×½©
		int watch[1001];
		fill(watch,watch+1001,-1);
		// eê©çÝÄ¢­
		for(int i = 0; i < n; i++){
			for(int j = 0; j < bangumis[i].size(); j++){
				// »ÝÌê
				pair<int,int> cp;
				cp.first=i;cp.second=j;
				// »Ý
				int ctime=bangumis[cp.first][cp.second].first;

				int init=ctime;
				// ÔgÌÅãÜÅ©Ä¢­
				while(1){
					ctime=bangumis[cp.first][cp.second].second;
					bool f=false;
					for(int l = 0; l < n; l++){
						if(l==cp.first)
							continue;
						for(int k = 0; k < bangumis[l].size(); k++){
							// àµ»ÝÅIíÁÄ¢È¢Ôgª êÎ
							pair<int,int> &bg=bangumis[l][k];
							if(bg.first<=ctime&&bg.second>ctime){
								cp.first=l;
								cp.second=k;
								f=true;
								break;
							}
						}
						if(f)
							break;
					}
					// startn_©çÌ·ªðßé
					if(!f){
						maxTime=max(maxTime,ctime-init);
						break;
					}
				}
			}
		}
		cout<<maxTime<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=998244353 ;
#define pai 3.141592653589793238462643383279

int modpow(ll a, ll n, ll p){
	if(n==0) return 1;
	if(n%2) return (a*modpow(a, n-1, p))%p;
	if(!(n%2)){
		ll t=modpow(a, n/2, p);
		return (t*t)%p;
	}
}

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main(){
    int N, S; cin >> N >> S; ll A[N];
    rep(i, N){
        cin >> A[i];
    }
   ll res = 0; ll dp[3010][3010] = {};
   dp[0][0] = 1;
   rep(i, N){
       rep(j, S+1){
           dp[i+1][j]+=dp[i][j];
           dp[i+1][j]%=mod;
       }
       if(A[i]<=S){
         dp[i+1][A[i]] += modpow(2, N-1, mod);
         dp[i+1][A[i]]%=mod;
       }
       for(int j=1; j<=S; ++j){
          if(A[i]+j<=S){
            dp[i+1][j+A[i]]+=dp[i][j]*modinv(2, mod);
            dp[i+1][j+A[i]]%=mod;
          } 
       }
   }
  cout << dp[N][S] << endl;
}

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

int N;

string solve(){
    for(int i = 1; i <= 9; ++i){
        for(int j = 1; j <= 9; ++j){
            if(N == i * j)return  "Yes";
        }
    }
    return "No";
}

int main(){
    cin >> N;
    cout << solve() << endl;
    return 0;
}

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

int N;

int main(){
    cin >> N;

    int ans = 1;

    for(int i=0;i<7;i++){
        ans *= 2;

        if(ans>N){
            ans /=2;
            cout << ans << endl;
            break;

        }

    }
}

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

long int N;
int sum = 0;
void dfs(long int s,bool flag3, bool flag5, bool flag7){
  if(s > N){ return; }
  
  if(flag3 && flag5 && flag7){ sum++; }
  dfs(10 * s + 3, true, flag5, flag7);
  dfs(10 * s + 5, flag3, true, flag7);
  dfs(10 * s + 7, flag3, flag5, true);

}
int main(){
  cin >> N;
  dfs(0,false, false, false);
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
use proconio::input;

fn main() {
    input! {
        n:usize,
        m:usize
    }
    let mut a: Vec<usize> = vec![0; m];
    let mut b: Vec<usize> = vec![0; m];
    // 奇数おきの組み合わせと偶数おきのくみあわせ。
    // m=6ならnは14以上、1-6,2-5,3-4 & (6+)1-7,2-6,3-5
    // m=7ならnは15以上、1-7,2-6,3-5 & (7+)1-8,2-7,3-6,4-5
    // よって、m=2*kなら、   (a,b)=(1,m+1-1),,(k,m+1-k) and (2*k+)で、  (1,m+2-1),,(k,m+2-k)
    // よって、m=2*k+1なら、 (a,b)=(1,m+1-1),,(k,m+1-k) and (2*k+1+)で、(1,m+2-1),,(k,m+2-k),(k+1,m+2-k-1)
    // m=1 (k=0)                       (1,2),
    let k = m / 2;
    for i in 1..(k + 2) {
        a[i - 1] = i;
        b[i - 1] = m + 1 - i;
    }
    for i in 1..((m + 1) / 2 + 1) {
        a[k + i - 1] = m + i;
        b[k + i - 1] = m + m + 2 - i;
    }
    //println!("{:?}", a);
    //println!("{:?}", b);
    for i in 0usize..(m as usize) {
        println!("{} {}", a[i], b[i]);
    }
}


Measured memory_bytes: 3256
N = int(input())
A = list(map(int,input().split()))
A.sort()
if A[0] == 0:
    print(0)
else:
    m = 10**18
    total = A[0]
    for i in range(1,N):
        total *= A[i]
        if m < total:
            print(-1)
            break
    else:
        print(total)

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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int h,w;
char mp[302][302];

int co[302][302][302];

int dp[302][302];
int calc(int x){
  REP(i,h+1)REP(j,h+1)dp[i][j]=MOD;
  dp[0][0] = 0;
  REP(i,h+1)REP(j,h+1){
    if(i>0){
      CHMIN(dp[i][j],dp[i-1][j] + co[x][i][j]);
    }
    if(j>0){
      CHMIN(dp[i][j],dp[i][j-1] + co[x][i][j]);
    }
  }
  return dp[h][h];
}

int main(){
  scanf("%d%d",&h,&w);
  REP(i,h)scanf("%s",mp[i]);
  // O(WH^2)
  REP(x,w-1){
    REP(i,h+1)co[x][i][0] = co[x][0][i] = 0;
    REP(i,h+1)REP(j,h+1){
      if(i==0 || j==0)continue;
      co[x][i][j] = co[x][i-1][j-1] + (int)(mp[i-1][x]==mp[j-1][x+1]);
    }
  }
  int ans = 0;
  REP(i,w-1)ans += calc(i);
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 107264
typedef long long ll;
#include "bits/stdc++.h"
using namespace std;
int main() {
	ll n;
	cin >> n;
	
	int cnt = 0;
	for (ll i = 357; i <= n;)
	{
		string sn = to_string(i);
		int size = sn.size();
		
		for (size_t j = 0; j < size - 2; j++) //start
		{
			bool ok = true;
			bool three = false;
			bool five = false;
			bool seven = false;
			for (size_t k = 0; k < size; k++) 
			{
				if (sn.at(k) != '3' && sn.at(k) != '5' && sn.at(k) != '7') {
					ok = false;
					i += pow(10,(size - k - 1));
					i -= (i % 10) - 1;
					break;
				}

				if (sn.at(k) == '3') three = true;
				if (sn.at(k) == '5') five = true;
				if (sn.at(k) == '7') seven = true;
			}
			if (ok) {
			}
			else
			{
				i += 2;
				break;
			}
			if (j == size - 3) {
				i += 2;
				if (three && five && seven) cnt++;
				break;
			}
		}

	}
	cout << cnt << endl;
}


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

int main() {
  int n;
  ll ans=0;
  cin >> n;
  vector<int> a(n), b(n), c(n);
  rep (i, n) cin >> a[i];
  rep (i, n) cin >> b[i];
  rep (i, n) cin >> c[i];
  sort(a.begin(), a.end());
  sort(c.begin(), c.end());
  
  rep (i, n) {
    if (lower_bound(a.begin(), a.end(), b[i]) != a.begin()) {
      ll x = (lower_bound(a.begin(), a.end(), b[i]) - a.begin());
      ll y = (c.end() - upper_bound(c.begin(), c.end(), b[i]));
      ans += x * y;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 1408
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

#define int64 long long

int main()
{
	int64 nn, mm, xx;
	scanf("%lld %lld %lld", &nn, &mm, &xx);
	int64 cc[nn], aa[nn][mm];
	for(int64 ii = 0;ii < nn;ii++)
	{
		scanf("%lld", &cc[ii]);
		for(int64 jj = 0;jj < mm;jj++)
		{
			scanf("%lld", &aa[ii][jj]);
		}
	}
	int64 ans = 10000000, tmp[mm], cnt, flag = 0, tariteru;
	for(int64 bit = 1;bit < (1 << nn);bit++)
	{
		cnt = 0;
		tariteru = 1;
		for(int64 ii = 0;ii < mm;ii++)
		{
			tmp[ii] = 0;
		}
		for(int64 ii = 0;ii < nn;ii++)
		{
			if(bit & 1 << ii)
			{
				for(int64 jj = 0;jj < mm;jj++)
				{
					tmp[jj] += aa[ii][jj];
				}
				cnt += cc[ii];
			}
		}
		for(int64 ii = 0;ii < mm;ii++)
		{
			if(tmp[ii] < xx)
			{
				tariteru = 0;
			}
		}
		if(ans > cnt && tariteru)
		{
			ans = cnt;
			flag = 1;
		}
	}
	if(flag)
	{
		printf("%lld\n", ans);
	}
	else
	{
		puts("-1");
	}
	
	return 0;
}

Measured memory_bytes: 1728
import sys
input = sys.stdin.readline

a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
a3 = list(map(int, input().split()))

n = int(input())
for i in range(n):
    b = int(input())

    if b in a1:
        a1[a1.index(b)] = 0
    if b in a2:
        a2[a2.index(b)] = 0
    if b in a3:
        a3[a3.index(b)] = 0

# 結果確認
if (a1[0] == a1[1] == a1[2] == 0) or (a2[0] == a2[1] == a2[2] == 0) or (a3[0] == a3[1] == a3[2] == 0) \
    or (a1[0] == a2[0] == a3[0] == 0) or (a1[1] == a2[1] == a3[1] == 0) or (a1[2] == a2[2] == a3[2] == 0) \
    or (a1[0] == a2[1] == a3[2] == 0) or (a1[2] == a2[1] == a3[0] == 0):
    print("Yes")
else:
    print("No")

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

signed main(){
	int n;
	cin>>n;
	vi c(9);
	rep(i,n){
		int a;cin>>a;
		a=min(a,3200ll);
		c[a/400]++;
	}
	int co=0;
	rep(i,8)if(c[i])co++;
	cout<<max(1ll,co)<<" "<<co+c[8]<<endl;
}





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

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
#define F first
#define S second
#define pb push_back

inline int in(){int x, y; y = scanf("%d", &x); return x;}

const int N = 404;

vector<int> g[N];
int match[N];
bool mark[N];

bool dfs (int v){
	mark[v] = true;
	for (int u : g[v]){
		if (match[u] == -1 || (!mark[match[u]] && dfs(match[u]))){
			match[v] = u;
			match[u] = v;
			return true;
		} 
	}
	return false;
} 
int maxMatching(int n){
	int ret=0;
	fill(match, match + N, -1);
	while(true)
	{
		fill(mark, mark + n, false);
		int lret = ret;
		for(int i = 0; i < n; i++)
			if(!mark[i] && match[i] == -1)
				ret += dfs(i);
		if(ret == lret)
			break;
	}
	return ret;
}

int main(){
	int n = in(), m = in(), es = in();
	while(es--)
	{
		int u = in(), v = in();
		g[u].push_back(n + v);
	}
	cout << maxMatching(n) << endl;
	return 0;
}




Measured memory_bytes: 3276
use std::io::Read;

fn main() {
    let mut buf = String::new();

    std::io::stdin().read_to_string(&mut buf).unwrap();

    let mut iter = buf.split_whitespace();
    let ab: usize = iter.next().unwrap().parse().unwrap();
    let bc: usize = iter.next().unwrap().parse().unwrap();
    let _ca: usize = iter.next().unwrap().parse().unwrap();

    println!("{}", ab * bc / 2);
}


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

int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    cout.tie(NULL);
    ll t,i,j,temp1,temp2,x,y,z,sum=0,o,n,m,k,d;
    string a,b;
    cin >> a >> b;
    if(b.size()==a.size()+1 && a==b.substr(0,b.size()-1)){
        cout << "Yes\n";
    }
    else cout << "No\n";
}

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


int main()
{
	    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    ll n;
    cin>>n;
    vector<ll>v,v1(3,0);
    ll t;
    for(int i=0;i<3;i++)
    {
    	 cin>>t;
    	 v.push_back(t);
    }
      n--;
      ll a,b,c;
      for(int i=0;i<n;i++)
      {
      	  cin>>a>>b>>c;
      	  v1[0]=a+max(v[1],v[2]);
      	  v1[1]=b+max(v[0],v[2]);
      	  v1[2]=c+max(v[1],v[0]);
      	 
      	  v[0]=v1[0];
      	  v[1]=v1[1];
      	  v[2]=v1[2];
      	        	
      	  v1.clear();

      }
      ll p=max(v[0],max(v[1],v[2]));
      cout<<p<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const int INF = 1e9;
const int MOD = 1e9+7;
using Graph = vector<vector<ll>>;
template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true;} return false;}

// 0 false, 1 true 
// string to int : -48
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp

int main() {
    std::cout << std::fixed << std::setprecision(15);
    string s;
    cin >> s;
    char c = s[s.size()-1];
    if(c == '0' || c == '1' || c == '6' || c == '8'){
        cout << "pon" << endl;
    }

    if(c == '2' || c == '4' || c == '5' || c == '7' || c == '9'){
        cout << "hon" << endl;
    }

    if(c == '3'){
        cout << "bon" << endl;
    }

}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define FOR0(i,n) for(ll i=0;i<n;i++)
#define FOR1(i,n) for(ll i=1;i<=n;i++)
#define FORl(i,l,n) for(ll i=l;i<n;i++)
using namespace std;
#define pi pair<ll,ll>
#define pb push_back
#define ll long long
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define mst0(x) memset(x,0,sizeof(x));
#define vi vector<ll>
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define sp <<" "<<
#define intmax 1e14

ll power(ll num,ll g,ll mod){
  if(g==0)return 1;
  if(g%2==1)return (num*power((num*num)%mod,g/2,mod))%mod;
  return power((num*num)%mod,g/2,mod);
}
 


int main() {

	int n;
	cin >> n;
	int a[n], b[n], c[n];
	FOR1(i, n) a[i-1] = i;
	FOR0(i, n) cin >> b[i];
	FOR0(i, n) cin >> c[i];
	int first = -1, flag1 = 0;
	int cnt = 1;
	int second = -1, flag2 = 0;
	do{
		// FOR0(i, n) cout << a[i] << " ";
		// cout << endl;
		flag1 = 0, flag2 = 0;
		FOR0(i, n){
			if (a[i]!=b[i]){
				flag1 = -1;
				break;
			}

		}
		if (flag1==0) first = cnt;
		FOR0(i, n){
			if (a[i]!=c[i]){
				flag2 = -1;
				break;
			}
		}
			if (flag2==0) second = cnt;
	cnt++;

	}while(next_permutation(a, a+n));
	// cout << first sp second << endl;
	cout << abs(first - second);

}
	




Measured memory_bytes: 256
package main
import "fmt"

func main(){
  var az, ah, bz, bh, t, k, h int64
  
  fmt.Scanf("%d %d", &az, &ah)
  fmt.Scanf("%d %d", &bz, &bh)
  fmt.Scanf("%d", &t)
  if ah <= bh{
    fmt.Println("NO")
    return
  }
  
  if az > bz{
    k = az - bz
  } else {
    k = bz - az
  }
  
  h = ah - bh  
  
  if float64(t) >= float64(k)/float64(h){
    fmt.Println("YES")
    return
  }else{
    fmt.Println("NO")
    return
  }
}

Measured memory_bytes: 1820
// copied by Nurstan Duisengaliev
// skatal
#include <bits/stdc++.h>
 
#define ll long long
#define all(x) x.begin(), x.end()
#define in insert
#define mp make_pair
#define F first
#define S second
#define ppf pop_front
#define pb push_back
#define ppb pop_back
#define pf push_front
#define pii pair <int, int>
#define boost() ios_base::sync_with_stdio(0), cin.tie(0)
#define sz(x) x.size()
 
using namespace std;
 
const int N = (int)2e5 + 123;
const int mod = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;

void solve () {
	ll a, b, c;
	cin >> a >> b >> c;
	ll sum = 0;
	if (c >= b) {
		sum += b * 2;
		c -= b;
		sum += min (a, c);
		if (c > a) {
			sum ++;
		}
		cout << sum;
	}
	else {
		cout << b + c;
		return;
	}
	
}
 
main () {
//	freopen (".in", "r", stdin);
//	freopen (".out", "w", stdout);
	boost ();
	int TT = 1;
//	cin >> TT;
	while (TT --) {
		solve ();
	}
	return 0;	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define MOD 1000000007

using namespace std;
using ll = long long;

int main() {
	ll n, k, ans = -10000000000;
	cin >> n >> k;
	vector<ll> p(n), c(n);
	rep(i,n) {
		cin >> p[i];
		--p[i];
	}
	rep(i,n) cin >> c[i];
	vector<ll> dp(n);
	for (ll i = 0; i < n; i++) {
		ll now = i, start = i, count = 0;
		rep(j,k) {
			now = p[now];
			count++;
			dp[i] += c[now];
			ans = max(ans,dp[i]);
			if (now == start) {
				j = k;
				ll loop = (k - 1) / count;
				dp[i] = dp[i] * loop;
				ll kp = k - (count * loop);
				rep(r,kp) {
					now = p[now];
					dp[i] += c[now];
					ans = max(ans,dp[i]);
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3688
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

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

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using edge = struct {
  int to;
  int cost;
};
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end());
#define MIN(vec) *std::min_element(vec.begin(), vec.end());
#define MAXI(vec)                                                              \
  std::distance(vec.begin(), *std::max_element(vec.begin(), vec.end()));
#define MINI(vec)                                                              \
  std::distance(vec.begin(), *std::min_element(vec.begin(), vec.end()));
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

template <typename T, typename U> U read(ll V, T a, U b) {
  REP(i, V) {
    cin >> a;
    b.push_back(a);
  }
  return b;
}

bool asc(const pair<ll, ll> &left, const pair<ll, ll> &right) {
  return left.first == right.first ? left.second < right.second
                                   : left.first < right.first;
}

int main() {
  ll N, M;
  vector<pair<ll, ll>> m;
  bool table[M + 100];
  cin >> N >> M;
  REP(i, M) {
    ll a, b;
    cin >> a >> b;
    m.push_back(make_pair(b, a));
  }
  ll count = 0;
  sort(ALL(m), asc);
  REP(i, M) {
    if (!table[i]) {
      table[i] = true;
      count++;
      REP(j, M) {
        if (m[j].second < m[i].first) {
          table[j] = true;
        }
      }
    }
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 4080
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder_solve
{
    class Program
    {
        public const ulong mod = 1000000007;

        static void Main(string[] args)

        {

            var nm = Input3();
            var n = nm[0];
            var m = nm[1];

            var ans = ((m + n) * (m + n - 1))/2 - m * n;
            Console.WriteLine(ans);




        }

       
        static public long Input()
        {
            return long.Parse(Console.ReadLine());
        }

        static public string[] Input2()
        {
            return Console.ReadLine().Split();
        }

        static public ulong[] Input3()
        {
            string[] data = Console.ReadLine().Split();
            ulong[] res = new ulong[data.LongLength];
            for(long i = 0; i < data.LongLength; i++)
            {
                res[i] = ulong.Parse(data[i]);
            }
            return res;
        }
        public static long Choose(long n, long a)
        {
            long x = 1;
            long y = 1;
            for (long i = 0; i < a; i++)
            {
                x *= n - i;
                y *= i + 1;
            }
            return x / y;
        }
    }
}


Measured memory_bytes: 11092
#include<iostream>
#include<string>
using namespace std;
string S;
int total = 0;
int scount[4];
bool add[3] = {true};
bool found = false;

void judge (int pre_sum,int depth){
    if (depth == 4){
        if (pre_sum == 7){
            found = true;
            return;
        } else {
            return;
        }
    } else {
        if (!found){
            int plussum = pre_sum + scount[depth];
            add[depth - 1] = true;
//            cout << plussum << "," << depth + 1 << found << endl;
            judge (plussum, depth + 1);
        }
        if (!found){
            int minussum = pre_sum - scount[depth];
            add[depth - 1] = false;
//            cout << minussum << "," << depth + 1 << found << endl;
            judge (minussum, depth + 1);
        }
    }
}

main(){

    cin >> S;

    int A = S[0]-'0';
    int B = S[1]-'0';
    int C = S[2]-'0';
    int D = S[3]-'0';

    scount[0] = A;
    scount[1] = B;
    scount[2] = C;
    scount[3] = D;

    judge (scount[0],1);


    string answer = "";
    answer += S[0];
    if (add[0]) answer += "+";
    else answer += "-";
    answer += S[1];
    if (add[1]) answer += "+";
    else answer += "-";
    answer += S[2];
    if (add[2]) answer += "+";
    else answer += "-";
    answer += S[3];

    cout << answer << "=7" << endl;

    return 0;
}

Measured memory_bytes: 256
while True:
    H,W=map(int,input().split())
    if H==0 and W==0:
        break
    else:
        for i in range(H):
            if i == 0 or i == H-1:
                print('#'*W)
            else:
                print('#' + '.'*(W-2) + '#')
    print()


Measured memory_bytes: 5608
#![allow(unused_imports)]
use std::io;
use std::cmp::*;
use std::collections::*;
#[allow(dead_code)]
const M: i64 = 1e9 as i64 + 7;

fn read_line() -> String {
    let stdin = io::stdin();
    let mut buf = String::new();
    stdin.read_line(&mut buf).unwrap();
    buf
}
#[allow(dead_code)]
fn read<T>() -> T where T: std::str::FromStr, T::Err : std::fmt::Debug {
    read_line().trim().parse().unwrap()
}
#[allow(dead_code)]
fn readv<T>() -> Vec<T> where T: std::str::FromStr, T::Err : std::fmt::Debug {
    read_line().split(' ').map(|a| a.trim().parse().unwrap()).collect()
}

fn main() {
    let _ = read::<usize>();
    let aa = readv::<usize>();
    let bb = readv::<usize>();
    let x = aa.iter().fold(0, |acc, &a| acc ^ a);
    let (mut aa, bb): (Vec<_>, Vec<_>) = aa.iter().zip(bb.iter()).filter(|&(&a, &b)| a != b).unzip();
    let n = aa.len();
    aa.push(x);
    let mut nums: HashMap<_, i32> = aa.iter()
        .fold(HashMap::new(), |mut acc, &a| { *acc.entry(a).or_insert(0) += 1; acc });
    for &b in &bb {
        *nums.entry(b).or_insert(0) -= 1;
        if nums[&b] < 0 {
            println!("{}", -1);
            return;
        }
    }

    let mp = aa.iter().collect::<BTreeSet<_>>().into_iter().enumerate()
        .map(|(a, b)| (b, a)).collect::<HashMap<_, _>>();
    let a2: Vec<_> = aa.iter().map(|a| mp[a]).collect();
    let b2: Vec<_> = bb.iter().map(|b| mp[b]).collect();
    // let mut dests = b2.iter().enumerate()
    //     .fold(HashMap::new(), |mut acc, (a, b)| { (acc.entry(b).or_insert(Vec::new())).push(a); acc });
    let mut dests: Vec<Vec<_>> = b2.iter().enumerate()
        .fold(vec![Vec::new(); n + 1], |mut acc, (a, &b)| { acc[b].push(a); acc });
    let mut q: VecDeque<_> = std::iter::once(n).collect();
    let mut rems: HashSet<_> = (0..n + 1).collect();
    let mut ans = n;
    #[cfg(local)] println!("{}: {:?}", "(mp, dests)", (mp, &dests));
    #[cfg(local)] println!("{}: {:?}", "(a2, b2)", (&a2, &b2));
    while !rems.is_empty() {
        while let Some(s_idx) = q.pop_front() {
            if !rems.remove(&s_idx) { continue; }
            let s_num = a2[s_idx];
            for &dest in &dests[s_num] {
                q.push_back(dest);
            }
            dests[s_num].clear();
            // if let Some(destv) = dests.remove(&s_num) {
            //     for dest in destv {
            //         q.push_back(dest);
            //     }
            // }
        }
        if let Some(&rem) = rems.iter().next() {
            q.push_back(rem);
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 28272
#include <stdio.h>
#include <stdlib.h>

#define int long long
#define p (int)(1e9 + 7)

int MOD(int a){
	if(a >= 0){
		return a % p;
	}
	else{
		return p + a % p;
	}
}

int power(int a, int n){
	if(n == 0){
		return 1;
	}
	else if(n % 2 == 1){
		return MOD(a * power(a, n - 1));
	}
	else{
		return power(MOD(a * a), n / 2);
	}
}

int inverse(int a){
	return power(a, p - 2);
}
/*
typedef struct {
	int x;
	int y;
}pair;

//a ≠ 0 かつ b / a ≠ 0 を仮定
pair inverse_sub(int a, int b){
	pair ans, sub;
	if(a == 1){
		ans.x = 1;
		ans.y = 0;
	}
	else{
		sub = inverse_sub(b % a, a);
		ans.x = MOD(sub.y - (b / a) * sub.x);
		ans.y = sub.x;
	}
	return ans;
}

int inverse(int a){
	return inverse_sub(a, p).x;
}*/

signed main(){
	int n, a, i, l, r, ans;
	scanf("%lld", &n);
	int *aplace = (int *)malloc(sizeof(int) * n);
	for(i = 0; i < n; i++){
		aplace[i] = -1;
	}
	for(i = 0; i <= n; i++){
		scanf("%lld", &a);
		a--;
		if(aplace[a] != -1){
			l = aplace[a];
			r = i;
		}
		aplace[a] = i;
	}
	int *fact = (int *)malloc(sizeof(int) * (n + 2));
	int *fact_inv = (int *)malloc(sizeof(int) * (n + 2));
	fact[0] = 1;
	fact_inv[0] = 1;
	for(i = 1; i <= n + 1; i++){
		fact[i] = MOD(i * fact[i - 1]);
		fact_inv[i] = inverse(fact[i]);
	}/*
	for(i = 0; i <= n + 1; i++){
		printf("fact[%lld] = %lld\n", i, fact[i]);
	}
	printf("\n");
	for(i = 0; i <= n + 1; i++){
		printf("fact_inv[%lld] = %lld\n", i, fact_inv[i]);
	}
	printf("\n");
	for(i = 0; i <= n + 1; i++){
		printf("fact[%lld] * fact_inv[%lld] = %lld\n", i, i, MOD(fact[i] * fact_inv[i]));
	}
	printf("\n");
	printf("(l, r) = (%lld, %lld)\n", l, r);*/
	for(i = 1; i <= n + 1; i++){
		ans = MOD(fact[n + 1] * MOD(fact_inv[i] * fact_inv[n + 1 - i]));
		if(l + n - r >= i - 1){
			ans = MOD(ans - MOD(fact[l + n - r] * MOD(fact_inv[i - 1] * fact_inv[l + n - r - i + 1])));
		}
		printf("%lld\n", ans);
	}
}

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

int main()
{
    int n;
    cin >> n;
    
    char c;
    bool f;
    for (int i = 0; i < n; i++) {
        cin >> c;
        f |= c == 'Y';
    }

    cout << (f ? "Four" : "Three") << endl;

    return 0;
}


Measured memory_bytes: 256
/*Template by hemnath_d(Enlightened by chamow)*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define vec vector<ll>
#define pll pair<ll,ll>
#define fastread ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define fx first
#define sx second
#define inf 100000000000000
#define minf -100000000000000
#define maxi 100005

int main()
{	
    fastread;
    ll n;
    cin>>n;
    set<ll> se;
    map<ll,ll> ma;
    vec arr;
    int prev=0;
    for(int i=0;i<n;i++){
    	ll temp;
    	cin>>temp;
    	ma[temp]++;
    	se.insert(temp);
    	if(se.size()!=prev){
    		arr.pb(temp);
    		prev=se.size();
    	}
    }
    sort(arr.begin(),arr.end());
    if(n%3==0){
    	if(se.size()==3){
    			if(ma[arr[1]] == ma[arr[0]] && ma[arr[1]] == ma[arr[2]]){
    			ll temp = arr[0] ^ arr[1];
    			if(temp == arr[2]){
    				cout<<"Yes"<<endl;
    				return 0;
    			}
    		}
    	}
    	else if(se.size()==2){
    		if(arr[0]==0){
    			if(ma[arr[1]]==(2*ma[0]))
    			{
    				cout<<"Yes"<<endl;
    				return 0;
    			}
    		}
    	}
    	else if(se.size()==1)
    		if(arr[0]==0){
    			cout<<"Yes"<<endl;
    			return 0;
    		}
    }
    else{
    	if(se.size()==1){
    		if(arr[0]==0){
    			cout<<"Yes"<<endl;
    			return 0;
    		}

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

Measured memory_bytes: 9332
#include <stdio.h>

int main(){
	double xa1,ya1,xa2,ya2,xb1,yb1,xb2,yb2;
	while(scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&xa1,&ya1,&xa2,&ya2,&xb1,&yb1,&xb2,&yb2)!=EOF){
		if(xb1<=xa2&&xa1<=xb2&&yb1<=ya2&&ya1<=yb2){
			printf("YES\n");
		}else{
			printf("NO\n");
		}
	}
	return 0;
}

Measured memory_bytes: 612
#include <stdio.h>
#include <string>
#include <queue>
#include <utility>
#include <iostream>
#define rep(i, n) for(int i = 0; i < n; ++i)
using namespace std;

typedef pair<string, int> psi;
 
int main(void) {
  int n, q, now = 0;
  queue< psi > que;
  scanf("%d%d", &n, &q);
  rep(i, n) {
    string s;
    int t;
    cin >> s >> t;
    psi p = make_pair(s, t);
    que.push(p);
  }
  while( !que.empty() ) {
    psi p = que.front();
    que.pop();
    if(p.second > q) {
      now += q;
      p.second -= q;
      que.push(p);
    } else {
      now += p.second;
      cout << p.first << " " << now << "\n";
    }
  }
  return 0;
}


Measured memory_bytes: 6416
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef double dd;
const int N = 2e5+5;
const dd eps = 1e-8;
const int mod = 1e9+7;

ll vis[N],now,ans,qu[N],a[N];
int n;

int main(){
  // freopen("input.txt","r",stdin);
  scanf("%d",&n);
  for(int i = 1;i <= n;i++){
    scanf("%lld",&qu[i]);
    a[i] = qu[i];
    qu[i] += i;
  }
  sort(qu+1,qu+1+n);
  for(int i = 1;i <= n;i++){
    int inx = lower_bound(qu+1,qu+1+n,i-a[i])-qu;
    int inx2 = upper_bound(qu+1,qu+1+n,i-a[i])-qu;
    if(inx == n+1) continue;    
    if(qu[inx] == i-a[i]){
      ans += inx2-inx;
    }
  }
  printf("%lld\n",ans);
  return 0;
}


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

int main(){
  int n, m, s=0, a; cin>>n >>m;
  for(int i=0;i<m;i++){
    cin>>a;
    s+=a;
  }
  
  if(s>n)cout<<-1<<endl;
  else cout<<n-s<<endl;
  
  return 0;
}

Measured memory_bytes: 3620
// #define STOPIT
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;

void debug_impl() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { cerr << " " << head; debug_impl(tail...); }
#ifndef STOPIT
    #define debug(...)\
    do {\
        cerr << boolalpha << "[" << #__VA_ARGS__ << "]:";\
        debug_impl(__VA_ARGS__);\
        cerr << std::noboolalpha;\
    } while (false)
#else
    #define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, enable_if_t<!is_same< Container, string >::value, nullptr_t> = nullptr>
istream& operator>> (istream& is, Container& v)
  { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, enable_if_t<!is_same< Container, string >::value, nullptr_t> = nullptr >
ostream& operator<< (ostream& os, Container const& v) {
  os << "{";
  for (auto it = v.begin(); it != v.end(); it++)
    {os << (it != v.begin() ? "," : "") << *it;}
  return os << "}";
}
int main()
{
    int a, b;
    cin >> a >> b;
    if (a>b) swap(a, b);
    string res = "";
    rep(i, 0, b)
        res += (char)'0'+a;
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>

int main(){
  int N,A,B;
  int train, taxi;
  scanf("%d %d %d",&N,&A,&B);
  
  train=N*A;
  taxi=B;
  if(train<taxi){
    printf("%d\n",train);
  } else {
    printf("%d\n",taxi);
  }
  return 0;
}

Measured memory_bytes: 128