akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

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

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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; }

struct UnionFind{
    vector<int> par; // par[i]:iの親の番号
    vector<int> s; // s[i]:iの属する木のノード数
    int n_group; // 木の数
    
    UnionFind(int N) : par(N) {
        for(int i=0; i<N; i++) par[i] = i;
        s.assign(N, 1);
        n_group = N;
    }
    
    int root(int x){ // xが属する木の根
        if(par[x] == x) return x;
        return par[x] = root(par[x]);
    }
    
    void unite(int x, int y){ // xとyの木を併合
        int rx = root(x);
        int ry = root(y);
        if(rx == ry) return;
        par[rx] = ry;
        s[ry] += s[rx];
        s[rx] = 0;
        n_group--;
    }
    
    bool same(int x, int y){ // xとyが同じ木に属するかどうか
        return root(x) == root(y);
    }

    int size(int x){ // xが属する木のノード数
        return s[root(x)];
    }
};

void Main(){
    int N; cin >> N;
    UnionFind uf(100000);
    VVI x(100000), y(100000);
    REP(i,N){
        int a,b; cin >> a >> b; a--; b--;
        x[a].push_back(b); y[b].push_back(a);
    }
    REP(i,100000){
        if(y[i].size() > 1){
            REP(j,y[i].size()-1){
                uf.unite(y[i][0], y[i][j+1]);
            }
        }
    }

    vector<set<int>> par(100000);
    REP(i,100000){
        int r = uf.root(i);
        REP(j,x[i].size()) par[r].insert(x[i][j]);
    }

    ll ans = 0;
    REP(i,100000){
        int r = uf.root(i);
        ans += par[r].size() - x[i].size();
    }
    cout << ans << en;
    return;
}

int main(void){
    cin.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t = 1; //cin >> t;
    REP(_,t){
        Main();
    }
    return 0;
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
using lli = long long int;
using ulli = unsigned long long int;
#define debug(x) cerr << #x << ":" << x << endl

namespace atcoder {
	void judge_outer(bool judge_exp, string ok = "Yes", string ng = "No") {
		if (judge_exp) {
			cout << ok << endl;
		}
		else {
			cout << ng << endl;
		}
	}

	template<typename T>
	T ncr(T left, T right) {
		right = min(left - right, right);
		T ans = 1;
		for (T i = 1; i <= right; i++) {
			ans = ans * (left - right + i) / i;
		}
		return ans;
	}

	const int LIMIT = 1000000007;
	const int tenfive = 100000;


}

using namespace atcoder;


int main() {
	int N, K;
	cin >> N >> K;
	K--;
	vector<int> vec(N);
	int ans = LIMIT;
	for (int i = 0; i < N; i++) {
		cin >> vec[i];
	}
	sort(vec.begin(), vec.end());
	
	for (int i = 0; i < N - K; i++) {
		ans = min(ans, vec[i+K] - vec[i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = (1 << 30) - 1;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////

int N, M;
ll dp[MAX_N];
int used[MAX_N];

void solve() {
	cin >> N >> M;
	rep(i, 0, M) {
		int a; cin >> a; used[a] = 1;
	}
	dp[0] = 1;
	rep(i, 1, N + 1) {
		if(used[i]) continue;
		ADD(dp[i], dp[i - 1]);
		if(i > 1) ADD(dp[i], dp[i - 2]);
	}
	cout << dp[N] << "\n";
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
	if(!freopen("in.txt", "rt", stdin)) return 1;
#endif	
	solve();
    cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}



Measured memory_bytes: 2816
#include <cmath>
#include <vector>
#include <iostream>
#include <algorithm>
#pragma warning(disable : 4996)
using namespace std;
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define EVEN(x) (mu[x] == x || (mu[x] != x && phi[mu[x]] != mu[x]))
#define ODD(x)  (mu[x] != x && phi[mu[x]] == mu[x] && phi[x] != x)
#define OUTER(x) (mu[x] != x && phi[mu[x]] == mu[x] && phi[x] == x)
typedef int Weight;
struct Edge {
	int src, dst;
	Weight weight;
	Edge(int src, int dst, Weight weight) :
		src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
	e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;
int maximumMatching(const Graph &g) {
	int n = g.size();
	vector<int> mu(n), phi(n), rho(n), scanned(n);
	REP(v, n) mu[v] = phi[v] = rho[v] = v; // (1) initialize
	for (int x = -1; ; ) {
		if (x < 0) {                        // (2) select even
			for (x = 0; x < n && (scanned[x] || !EVEN(x)); ++x);
			if (x == n) break;
		}
		int y = -1;                         // (3) select incident
		for (int e = 0; e < (int)g[x].size(); e++) if (OUTER(g[x][e].dst) || (EVEN(g[x][e].dst) && rho[g[x][e].dst] != rho[x])) y = g[x][e].dst;
		if (y == -1) scanned[x] = true, x = -1;
		else if (OUTER(y)) phi[y] = x;      // (4) growth
		else {
			vector<int> dx(n, -2), dy(n, -2); // (5,6), !TRICK! x % 2 --> x >= 0
			for (int k = 0, w = x; dx[w] < 0; w = k % 2 ? mu[w] : phi[w]) dx[w] = k++;
			for (int k = 0, w = y; dy[w] < 0; w = k % 2 ? mu[w] : phi[w]) dy[w] = k++;
			bool vertex_disjoint = true;
			REP(v, n) if (dx[v] >= 0 && dy[v] > 0) vertex_disjoint = false;
			if (vertex_disjoint) {            // (5) augment
				REP(v, n) if (dx[v] % 2) mu[phi[v]] = v, mu[v] = phi[v];
				REP(v, n) if (dy[v] % 2) mu[phi[v]] = v, mu[v] = phi[v];
				mu[x] = y; mu[y] = x; x = -1;
				REP(v, n) phi[v] = rho[v] = v, scanned[v] = false;
			}
			else {                          // (6) shrink
				int r = x, d = n;
				REP(v, n) if (dx[v] >= 0 && dy[v] >= 0 && rho[v] == v && d > dx[v]) d = dx[v], r = v;
				REP(v, n) if (dx[v] <= d && dx[v] % 2 && rho[phi[v]] != r) phi[phi[v]] = v;
				REP(v, n) if (dy[v] <= d && dy[v] % 2 && rho[phi[v]] != r) phi[phi[v]] = v;
				if (rho[x] != r) phi[x] = y;
				if (rho[y] != r) phi[y] = x;
				REP(v, n) if (dx[rho[v]] >= 0 || dy[rho[v]] >= 0) rho[v] = r;
			}
		}
	}
	int ret = 0;
	REP(u, n) if (u < mu[u]) ret++;
	return ret;
}
int X, Y, E, x, y; Graph G;
int main() {
	scanf("%d%d%d", &X, &Y, &E); G.resize(X + Y);
	for (int i = 0; i < E; i++) {
		scanf("%d%d", &x, &y);
		G[x].push_back(Edge(x, X + y, 1));
		G[X + y].push_back(Edge(X + y, x, 1));
	}
	printf("%d\n", maximumMatching(G));
}

Measured memory_bytes: 3336
n = int(input())
nn = str(n)
nnn = list(reversed(nn))
nnnn = int(nnn[0])

if nnnn == 2 or nnnn == 4 or nnnn == 5 or nnnn == 7 or nnnn == 9:
    print('hon')
elif nnnn == 0 or nnnn == 1 or nnnn == 6 or nnnn == 8 :
    print('pon')
else:
    print('bon')

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

int main(){
  char c ; cin >> c;
  if(c >= 'a' && c <= 'z') cout << 'a' << endl;
  else cout << 'A' << endl;
}

Measured memory_bytes: 3544
n = int(input())
INF = 10**9
P = [list(map(int, input().split())) for i in range(n)]
m = [[0]*n for i in range(n)]

for l in range(2, n + 1):
    for i in range(n - l + 1):
        j = i + l - 1
        m[i][j] = INF
        for k in range(i, j):
            m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + P[i][0] * P[k][1] * P[j][1])

print(m[0][n - 1])

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

#define MAX 11
#define INF (1<<23)

int G[MAX][MAX];

int main() {
  int n, x, y, c;
  int V;
  
  while(cin >> n, n) {
    fill(G[0], G[MAX], INF);
    
    for(int i=0; i<MAX; i++) {
      G[i][i] = 0;
    }
    
    V = 0;
    for(int i=0; i<n; i++) {
      cin >> x >> y >> c;
      V = max(V, max(x, y));
      G[x][y] = G[y][x] = c;
    }

    V++;
    
    for(int k=0; k<V; k++) {
      for(int i=0; i<V; i++) {
	for(int j=0; j<V; j++) {
	  G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
	}
      }
    }
    
    int sum, ans = INF, id;
    
    for(int i=0; i<V; i++) {
      sum = 0;
      for(int j=0; j<V; j++) {
	sum += G[i][j];
      }
      if(ans > sum) {
	ans = sum;
	id = i;
      }
    }
    
    cout << id << " " << ans << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=998244353;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

void add(ll &a,ll b){
  a=(a+b)%MOD;
}

void mul(ll &a,ll b){
  a%=MOD;b%=MOD;
  a=a*b%MOD;
}

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

  int N,K;
  cin>>N>>K;
  vector<int> L(K),R(K);
  rep(i,K) cin>>L[i]>>R[i];

  vector<ll> dp(N+1,0);
  dp[1]=1;
  vector<ll> sum(N+1,0);
  sum[1]=1;
  for(int i=2;i<=N;i++){
    for(int k=0;k<K;k++){
      if(i-L[k]<=0) continue;

      ll coef=sum[i-L[k]]-sum[max(0,i-R[k]-1)];
      coef=(coef+MOD)%MOD;
      add(dp[i],coef);
    }
    add(sum[i],sum[i-1]);
    add(sum[i],dp[i]);
  }
  cout<<dp[N]<<endl;

  return 0;
}


Measured memory_bytes: 6364
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;

const int N=1e5+1e3+7;

struct node{
	int ne,to;
}edg[N*2+1];

int n,m,cnt,head[N],c[N],flag;

void build(int u,int v)
{
	++cnt;
	edg[cnt].to=v;
	edg[cnt].ne=head[u];
	head[u]=cnt;
}

void dfs(int i,int cur)
{
	for(int tmp=head[i];tmp;tmp=edg[tmp].ne)
	{
		int v=edg[tmp].to;
		if(c[v]==-1)
		{
			c[v]=cur;
			dfs(v,cur^1);
		}
		else
		{
			if(c[v]!=c[i])
				continue;
			else
				flag=true;
		}
	}
}

int main()
{
	memset(c,-1,sizeof(c));
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		build(u,v);
		build(v,u);
	}
	c[1]=1;
	dfs(1,0);
	if(flag)
	{
		cout<<1ll*n*(n-1)/2-m;
	}
	else
	{
		long long cnt=0;
		for(int i=1;i<=n;i++)
			if(c[i])
				cnt++;
		cout<<cnt*(n-cnt)-m;
	}
}

Measured memory_bytes: 3840
#coding:utf-8
n = int(input())
numbers = list(map(int, input().split()))

def selectionSort(ary):
    count = 0
    for i in range(len(ary)):
        minj = i
        for j in range(i, len(ary)):
            if ary[minj] > ary[j]:
                minj = j
        if minj != i:
            ary[minj], ary[i] = ary[i], ary[minj]
            count += 1
    return (ary, count)

result = selectionSort(numbers)
print(*result[0])
print(result[1])

Measured memory_bytes: 6724
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    
    ll n; cin >> n;
    string s[n]; ll t[n]; zep(i, 0, n){cin >> s[i] >> t[i];}
    string x; cin >> x;

    ll ans = 0;
    bool sleep = false;
    zep(i, 0, n){
        if(sleep){
            ans += t[i];
        }
        if(s[i] == x){
            sleep = true;
        }
    }
    print(ans)
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define CIN>>x scanf("%lld",&x);
#define all(v) v.begin(), v.end()
bool chmin(ll & a, ll  b) { if (b < a) { a = b; return 1; } return 0; }
bool chmax(ll & a, ll b) { if (b > a) { a = b; return 1; } return 0; }
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N=500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
int main() {
    cin >> n;
	vl A,B(n,0),C;
	rep(i,n){
		cin>>x;
		A.push_back(x);
	}

	for(ll i=n;i>0;i--){
		a=A[i-1];
		for(ll j=1;j*i<=n;j++){
			a+=B[i*j-1];
		}

		if(a%2==1)B[i-1]++;
	}
	

	rep(i,n){
		if(B[i]==1)C.push_back(i+1);
	}

	cout<<C.size()<<endl;

	rep(i,C.size()){
		cout<<C[i]<<" ";
	}

	cout<<endl;
}


Measured memory_bytes: 5872
#include <bits/stdc++.h>
#define r(i,n) for(int i = 0; i<n; i++)
typedef long long ll;
using namespace std;
const ll mod=1000000007;

int main() {
  ll n,k;
  cin >> n >> k;
  ll s[n+1]={};
  r(i,n)s[i+1]=s[i]+i+1;
  ll ans=0;
  for(int i=k;i<=n+1;i++){
    if(i==n+1)ans+=1;
    else{
      ans+=(s[n]-s[n-i])-s[i-1]+1;
    }
  }
  cout<<ans%mod<<endl;
}

Measured memory_bytes: 5140
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define INF 100000000000
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using P = pair<int, int>;

// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}


int main()
{
    int n, x;
    cin >> n >> x;
    vector<int> a(n);
    rep(i,n) cin >> a[i];

    sort(a.begin(), a.end());
    if (a[0] > x) {
        cout << 0 << endl; return 0;
    }

    int ans = 0;
    int i = 0;
    while (true) {
        x -= a[i];
        i++;
        if (x < 0) {
            break;
        }
        if (x == 0) {
            ans++;
            break;
        }
        if (i == n) {
            break;
        }
        ans++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
//参考：https://qiita.com/DaikiSuyama/items/9dba963ba74396b9b7fd
//インクルード(アルファベット順)
#include <algorithm>     //sort,二分探索,など
#include <bitset>        //固定長bit集合
#include <cmath>         //pow,logなど
#include <complex>       //複素数
#include <deque>         //両端アクセスのキュー
#include <functional>    //sortのgreater
#include <iomanip>       //setprecision(浮動小数点の出力の誤差)
#include <iostream>      //入出力
#include <iterator>      //集合演算(積集合,和集合,差集合など)
#include <map>           //map(辞書)
#include <numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>         //キュー
#include <set>           //集合
#include <stack>         //スタック
#include <string>        //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility>       //pair
#include <vector>        //可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#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--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define FIR first    //pairの一つ目の要素
#define SEC second   //pairの二つ目の要素

signed main()
{
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll A, B, N;
    cin >> A >> B >> N;

    if (N < B - 1)
    {
        cout << floor(A * N / B) - A * floor(N / B) << endl;
    }
    else
    {
        cout << floor(A * (B - 1) / B) << endl;
    }

    return 0;
}


Measured memory_bytes: 3244
#include "bits/stdc++.h"
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/operators.hpp>
#include <boost/dynamic_bitset.hpp>

namespace adaptor = boost::adaptors;
using index_t = std::size_t;

void Main()
{
	int N;
	std::cin >> N;
	std::vector<int> base(N);
	for (auto i : boost::irange(0, N))
	{
		base[i] = i + 1;
	}
	std::vector<int> P(N), Q(N);
	for (auto& p : P)
	{
		std::cin >> p;
	}
	for (auto& q : Q)
	{
		std::cin >> q;
	}
	int a = 0, b = 0;
	int c = 0;
	do
	{
		++c;
		if (base == P)
		{
			a = c;
		}
		if (base == Q)
		{
			b = c;
		}
	} while (boost::next_permutation(base));
	std::cout << std::abs(a - b) << std::endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}

Measured memory_bytes: 256
from collections import namedtuple

Task = namedtuple('Task', ('a', 'b'))

def main():
    n = int(input())
    tasks = []

    for _ in range(n):
        a, b = map(int, input().split())
        tasks.append(Task(a, b))

    if solve(tasks):
        print('Yes')
    else:
        print('No')

def solve(tasks):
    t = 0
    for task in sorted(tasks, key=lambda t: t.b):
        t += task.a
        if t > task.b:
            return False
    
    return True


main()


Measured memory_bytes: 35376
N,K = list(map(int,input().split()))
S = input()
Now = S[0]
switch = 0
happiness = 0
for i in range(N-1):
  if(S[i+1] == Now):
    happiness += 1
  if(S[i+1] != Now):
    Now = S[i+1]
    switch += 1
number = 0
while((switch > 1) and (number < K)):
  number += 1
  happiness += 2
  switch -= 2
if((switch == 1) and (number < K)):
  happiness += 1
print(happiness)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;

struct UnionFind {
    vector<int> d;
    UnionFind(int n): d(n,-1) {}
    int root(int x) {
        if (d[x] < 0) return x;
        return d[x] = root(d[x]);
    }
    bool unite(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (d[x] > d[y]) swap(x,y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x, int y) { return root(x) == root(y);}
    int size(int x) { return -d[root(x)];}
};
int main() {
    int n, m;
    cin >> n >> m;
    UnionFind uf(n);
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        uf.unite(a, b);
    }
    
    int ans = 0;
    for (int i = 0; i < n; i++) {
        ans = max(ans, uf.size(i));
    }
    cout << ans << endl;
    
    return 0;
}


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

void ioinit() { ios::sync_with_stdio(0); cin.tie(0); }

int findAB(const string str) {
    int ret = 0;
  	string subStr = "AB";
    int subStrSize = subStr.size();
  
    int pos = str.find(subStr);
 
    while (pos != std::string::npos) {
        ret++;
        pos = str.find(subStr, pos + subStrSize);
    }
 
    return ret;
}

int main() {
  ioinit();
  int N,beginB = 0,endA = 0,bBeA = 0,sum = 0;
  cin >> N;
  for(int i = 0; i < N; i++){
    string str;
    cin >> str;
    sum += findAB(str);
    if(str[0] == 'B' && str[(int)str.length() - 1] == 'A'){
      bBeA++;
    }else{
      if(str[0] == 'B') beginB++;
      if(str[(int)str.length() - 1] == 'A') endA++;
    }
  }
  if(bBeA > 0){
    sum += (bBeA - 1);
    if(beginB != endA || min(beginB, endA) > 0) sum++;
  }
  sum += min(beginB, endA);

  cout << sum << endl;
}


Measured memory_bytes: 256
n, k = map(int, input().split())

mod = 10 ** 9 + 7
N = n + 1

def power(x, y):
    if   y == 0     : return 1
    elif y == 1     : return x % mod
    elif y % 2 == 0 : return power(x, y // 2) ** 2 % mod
    else            : return power(x, y // 2) ** 2 * x % mod

factorial = [1]
for i in range(1, N):
    factorial.append(factorial[i - 1] * i % mod)

inverseFactorial = [0] * N
inverseFactorial[N - 1] = power(factorial[N - 1], mod - 2)
for i in range(N - 2, -1, -1):
    inverseFactorial[i] = inverseFactorial[i + 1] * (i + 1) % mod

def comb(x, y):
    return factorial[x] * inverseFactorial[y] * inverseFactorial[x - y] % mod

ans = 1
for i in range(1, min(k + 1, n)):
    tmp = comb(n - 1, n - i - 1) * comb(n, i)
    ans += tmp
    ans %= mod
print(ans)


Measured memory_bytes: 62292
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ls rt << 1
#define rs rt << 1 | 1
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
#define X first
#define Y second
#define pcc pair<char, char>
#define rep(i, x, y) for(int i = x; i <= y; i ++)
#define rrep(i, x, y) for(int i = x; i >= y; i --)
#define eps 1e-9
const int P = 1e9 +7;
using namespace std;
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
const int N = 1000010;
string a;
int main()
{
	cin >> a;
	int n = a.size();
	n -= 8;
	rep(i, 0, n - 1)
        cout << a[i];
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<limits.h>
#include<set>
#include<map>
#include<string.h>
#include<queue>
#include<math.h>

using namespace std;

long long solve(long long a,long long b){
    if(a>b){
        return INT_MAX;
    }
   // cout<<a<<" "<<b<<" "<<b-a<<endl;
    return b-a;
}

int main(){
    long long a,b;
    cin>>a>>b;
    cout<<min(solve(a,b),min(1+solve(-a,b),min(1+solve(a,-b),2+solve(-a,-b))))<<endl;
    return 0;
}

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

namespace ABC157
{
    class Program
    {
        static void Main(string[] args)
        {
            a();
        }

        public static void a()
        {
            int n = int.Parse(Console.ReadLine());
            int a = n % 2;
            Console.WriteLine(n / 2 + a);
        }
    }
}


Measured memory_bytes: 11220
#include <stdio.h>

int main(void) {

	int a;
	int b;
    int c;
    int d;
    int e;
    int k;

	scanf("%d", &a);
	scanf("%d", &b);    
    scanf("%d", &c);
    scanf("%d", &d);
    scanf("%d", &e);
    scanf("%d", &k);
  
    int f =  e-a;
    
    if(f <= k){
      puts("Yay!");
    }
    else{
      puts(":(");
    }
	return 0;
}



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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

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

    int N, D;
    std::cin >> N >> D;

    int x = 2 * D + 1;
    int res = (N + x - 1) / x;
    std::cout << res << std::endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
typedef long long ll;
int main() {
  int h,w,k,cnt,ans=0;
  cin>>h>>w>>k;
  vector<string> c(h);
  rep(i,h)cin>>c[i];
  rep(ii,1<<h)rep(jj,1<<w){
    cnt=0;
    rep(i,h)rep(j,w){
      if((ii>>i)&1)continue;
      if((jj>>j)&1)continue;
      if(c[i][j]=='#')cnt++;
    }
    if(cnt==k)ans++;
  }
  cout<<ans;
}

Measured memory_bytes: 3616
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        d: u32,
        n: u32
    }
    let mut cnt = 0;
    for i in 1.. {
        let num = 100u32.pow(d) * i;
        // println!("{}", num);
        if num == 100u32.pow(d+1) {
            continue;
        }
        cnt += 1;
        if cnt == n {
            println!("{}", num);
            return;
        }
    }
}


Measured memory_bytes: 4352
#pragma GCC optimize("Ofast")   //Comment optimisations for interactive problems (use endl)
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>

using namespace std;

#define  fastio         ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
#define  randomINIT     mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define  all(x)         (x).begin(),(x).end()
#define  mset(x,val)    memset(x,val,sizeof(x))
#define  endl           "\n"
#define  pb             push_back
#define  sym(s)         s="#"+s+"#";
#define  mp             make_pair
#define  s              second
#define  f              first
#define  dline          cerr<<"///REACHED///\n";
#define  debv(a)        for(auto it: a)cout<<it<<" ";cout<<endl;
#define  deb1(a)        cout<<a<<endl;
#define  deb2(a,b)      cout<<a<<" "<<b<<endl;
#define  deb3(a,b,c)    cout<<a<<" "<<b<<" "<<c<<endl;
#define  deb4(a,b,c,d)  cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;
#define  uniq(a)        a.resize(unique(a.begin(), a.end()) - a.begin());

typedef  long long             ll;
typedef  unsigned long long    ull;
typedef  long double           ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  vector<pll>           vpll;

const ll   MOD   =  1e+9+7;
const ll   INF   =  0x7f7f7f7f7f7f7f7f;
const int  INFi  =  0x7f7f7f7f;
const ll   N  =  3e+5+7;

vll adj[N];ll vis[N]={};
int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1};
int dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};

//<<-----Declare Variable Here------->>//
int t=1;
ll n,k,max1;
ll a[N];
//<<-----Implement Functions Here---->>//
ll func(ll mid,ll x){
	ll sum1 = 0;
	for(ll i=1;i<=n;i++){
		ld q = a[i]/mid;ll r = a[i]%mid;
		if(r==0)q--;
		sum1+=q;
	}
	if(sum1>x)return 0;
	return 1;
}
ll binsearch(ll l,ll r,ll x)
{
	ll ans = max1;
	while(l<=r)
	{	
		ll mid = (l+r)/2;
		if(func(mid,x)){ans = mid;r = mid-1;}
		else l = mid+1;
	}
	return ans;
}

//<<-----Start of Main--------------->>//
void MAIN(){
		cin>>n>>k;
		for(ll i=1;i<=n;i++){cin>>a[i];max1 = max(max1,a[i]);}
		cout<<binsearch(1,max1,k);
}

int main(){
    fastio;randomINIT;

    //cin>>t;
    while(t--){
        MAIN();
    }

    #ifndef ONLINE_JUDGE
    cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
    #endif
}

Measured memory_bytes: 12188
#include<bits/stdc++.h>
using namespace std;
#define piii pair<int, pair<int, int> >
const int inf=1e9+99;
char a[1009][1009];
int r, c;
vector<pair<int, int> >black;
int dist[1009][1009];
int xx[]={0, -1, 0, 1};
int yy[]={1, 0, -1, 0};
int main(){
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin>>r>>c;
	for(int i=0; i<r; i++){
		for(int j=0; j<c; j++){
			cin>>a[i][j];
			dist[i][j]=inf;
			if(a[i][j]=='#'){ 
				black.push_back({i, j});
				dist[i][j]=0;
			}
		}
	}
	priority_queue<piii, vector<piii>, greater<piii> >pq;
	for(int i=0; i<black.size(); i++){
		pq.push({0, {black[i].first, black[i].second}});
	}
	while(!pq.empty()){
		int di=pq.top().first;
		int cx=pq.top().second.first, cy=pq.top().second.second;
		pq.pop();
		if(di>dist[cx][cy]) continue;
		for(int i=0; i<4; i++){
			int nx=cx+xx[i], ny=cy+yy[i];
			if(nx<0 || nx>=r || ny<0 || ny>=c) continue;
			if(dist[nx][ny]>dist[cx][cy]+1){
				dist[nx][ny]=dist[cx][cy]+1;
				pq.push({dist[nx][ny], {nx, ny}});
			}else continue;
		}
	}
	int maks=-1;
	for(int i=0; i<r; i++){
		for(int j=0; j<c; j++){
			maks=max(maks, dist[i][j]);
		}
	}
	cout<<maks<<endl;
	return 0;
}

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

int n, K;
int tab [107];
int dp [100007];

int main(){
    scanf("%d %d",&n,&K);
    for(int i = 1; i <= n; i++){
        scanf("%d",&tab[i]);
    }
    dp[0] = false;
    for(int k = 1; k <= K; k++){
        dp[k] = false;
        for(int i = 1; i <= n; i++){
            if( (k - tab[i] >= 0) and (!dp[k - tab[i]]) )
                dp[k] = true;
        }
    }

    if(dp[K]) puts("First");
    else puts("Second");
    return 0;
}


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

int main() {
	long long int a,b,c,d;
	cin>>a>>b>>c>>d;
	long long int maxi=-1000000000000000001;
	maxi=max(maxi,a*d);
	maxi=max(maxi,a*c);
	maxi=max(maxi,b*d);
	maxi=max(maxi,b*c);
	cout<<maxi;
	return 0;
}

Measured memory_bytes: 3632
s = int(input())
a = [s]

def f(n):
    if n % 2 == 0:
        return n //2
    else:
        return 3 * n + 1

for i in range(1000000):
    an = f(a[i])
    if an in a:
        m = i + 2
        break
    else:
        a.append(an)

print(m)

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

typedef long long ll;

int main() {
  int N; cin >> N;
  int x[101],y[101],h[101];
  for ( int i = 0; i < N; i++ ) cin >> x[i] >> y[i] >> h[i];

  for ( int posY = 0; posY <= 100; posY++ ) {
    for ( int posX = 0; posX <= 100; posX++ ) {
      int H = -1;
      for ( int i = 0; i < N; i++ ) {
	if ( h[i] > 0 ) {
	  int tmp = h[i] + abs(posX-x[i])+abs(posY-y[i]);
	  if ( H == - 1 ) {
	    H = tmp;
	  }else {
	    if ( H != tmp ) {
	      H = -2;
	    }
	  }
	}
      }
      if ( H == -2 ) continue;
      
      for ( int i = 0; i < N; i++ ) {
	if ( h[i] == 0 ) {
	  int dist = abs(posX-x[i])+abs(posY-y[i]);
	  if ( H > dist ) {
	    H = -2;
	  }
	}
      }
      if ( H == -2 ) continue;
      cout << posX << " " << posY << " " << H << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        String t = sc.nextLine();

        List<NavigableSet<Integer>> positionSets = new ArrayList<>();
        for (int i = 0; i < 26; i++) positionSets.add(new TreeSet<>());

        for (int i = 0; i < s.length(); i++) {
            positionSets.get(s.charAt(i) - 'a').add(i);
        }

        long loops = 0;
        int position = -1;

        for (int i = 0; i < t.length(); i++) {
            NavigableSet<Integer> positions = positionSets.get(t.charAt(i) - 'a');
            if (positions.isEmpty()) {
                System.out.println(-1);
                return;
            }
            Integer next = positions.higher(position);
            if (next == null) {
                loops++;
                position = positions.first();
            } else {
                position = next;
            }
        }

        System.out.println(loops * s.length() + position + 1);
    }

}


Measured memory_bytes: 34420
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long n = Long.parseLong(sc.next());
    long ans = n - 1;
    long a, b;
    for(int i = 1; i <= Math.sqrt(n); i++) {
      if(n % i == 0) {
        a = i;
        b = n / i;
        ans = Math.min(ans, a + b - 2);
      }
    }
    System.out.println(ans);
  }
}


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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

using II = pair<int, int>;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int extgcd(int a, int b, int &x, int &y) { int g = a; x = 1; y = 0; if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; return g; }

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

int A, B;

signed main()
{
  cin >> A >> B;
  cout << max(A+B,max(A-B,A*B)) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;

#define MOD 1000000007
#define INF 1e9+7
#define rep(i, n) for(int i=0; i<n; ++i)
typedef long long ll;

#define MAX_N 100000
#define MAX_M 100000
#define MAX_V 100
#define MAX_E 100

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

int ddx[] = {-1, 0, 1, 0, -1, 1, -1, 1};
int ddy[] = {0, -1, 0, 1, 1, 1, -1, -1};

//--------------------------

int cnt;

bool func(int x) {

  int a = 0;

  while(x!=0) {
    ++a;
    x /= 10;
  }

  if(a%2==1) return true;
  else return false;
}

int main() {

  int n;
  cin >> n;

  for(int i=1; i<=n; ++i) {
    if(func(i)) {
      ++cnt;
    }
  }

  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;

bool func(ii a, ii b){
    return a.second > b.second;
}

int main(){

    int n, k; cin >> n >> k;
    map<int,int> mapa;
    for(int i = 0; i < n; i++){
        int x; cin >> x;
        mapa[x]++;
    }
    if(mapa.size() <= k) cout << 0 << endl;
    else{
        vector<ii> vec(mapa.begin(), mapa.end());
        sort(vec.begin(), vec.end(), func);
        int sum = 0;
        for(int i = k; i < vec.size(); i++)
            sum += vec[i].second;
        cout << sum << endl;
    }
	return 0;
}


Measured memory_bytes: 11136
from collections import defaultdict
d = defaultdict(lambda : 0)
N = int(input())
A = list(input().split())
for a in A: d[a]+=1
cnt = 0
for key in d.keys():
    if d[key]<int(key): cnt+=d[key]
    elif d[key]>int(key): cnt+=(d[key]-int(key))
print(cnt)

Measured memory_bytes: 21228
//file_name:ABC62_D.cpp
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;

    // int scan
    /*
    int x;
    scanf("%d",&x);
    int y;
    scanf("%d",&y);
    int z;
    scanf("%d",&z);

    // matrix scan
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // string scan
    /*
    string s;
    cin >> s;
    */


int main() {
    int n;
    cin >> n;
    ll a[3*n];
    rep(i,3*n){
        cin >> a[i];
    }

    ll sum[n+1] = {};

    priority_queue<ll> q;
    rep(i,n){
        sum[0] += a[i];
        q.push(-a[i]);
    }

    rep(i,n){
        sum[i+1] = sum[i];
        sum[i+1] += a[n+i];
        q.push(-a[n+i]);
        sum[i+1] -= -q.top();
        q.pop();
    }

    ll sum2[n+1] = {};
    priority_queue<ll> q2;
    for(int i=3*n-1;i>=2*n;i--){
        sum2[n] += a[i];
        q2.push(a[i]);
    }

    srep(i,1,n+1){
        sum2[n-i] = sum2[n-i+1];
        sum2[n-i] += a[2*n-i];
        q2.push(a[2*n-i]);
        sum2[n-i] -= q2.top();
        q2.pop();
    }

    ll ans = -99999999999999;

    rep(i,n+1){
        //cout << sum[i] << ' ' << sum2[i] << endl;
        ans = max(ans,sum[i]-sum2[i]);
    }

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



Measured memory_bytes: 6516
#include <bits/stdc++.h>
#define rep(i,n) for ((i)=1;(i)<=(n);(i)++)
#define per(i,n) for ((i)=n;(i)>=(1);(i)--)
using namespace std;
long long a,b;
int main()
{
	cin>>a>>b;
	if(abs(a-b)<=1) puts("Brown"); else puts("Alice");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	const int MIN = 0;
	const int MAX=100000;
	int N;
	cin>>N;

	int min=-1;
	for (int a = 1;a < N /2+1;a++) { // 後半の組み合わせは前半の入れ替えなので不要
		int b=N-a;
		if(a+b!=N)continue;
		// cout<<a<<","<<b<<","<<a+b<<endl;

		// 各位の和の合計を求める
		int aVal=0,bVal=0;
		int aBuf=a,bBuf=b;
		while (aBuf != 0) {
			aVal+=aBuf%10;
			aBuf/=10;
		}

		while (bBuf != 0) {
			bVal += bBuf % 10;
			bBuf /= 10;
		}

		//cout << a << "," << b << ":" << aVal + bVal << endl;
		if (min == -1 || min > aVal + bVal) {
			min=aVal+bVal;
		}
		
	}
	cout << min << endl;
}

Measured memory_bytes: 256
import java.io.*;

public class Main {

    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        while (true) {
            int A = 0;
            int B = 0;
            try {
                String str = br.readLine();
                int x = Integer.parseInt(str);
                if (x == 0) {
                    break;
                }
                for (int i = 0; i < x; i++) {
                    String st = br.readLine();
                    String[] s = st.split(" ", 0);
                    int a = Integer.parseInt(s[0]);
                    int b = Integer.parseInt(s[1]);
                    if (a > b) {
                        A += a + b;
                    } else if (a < b) {
                        B += a + b;
                    } else {
                        A += a;
                        B += b;
                    }
                }
                System.out.println(A + " " + B);
            } catch (IOException ex) {
            }
        }
    }
}

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

int main(){
  int N,work;
  string s="APPROVED";
  cin >> N;
  for(int i=0;i<N;i++){
    cin >>work;
    if(work%2==0&&!(work%3==0||work%5==0))
    { 
      s="DENIED";
      break;
    }
  }
  cout << s << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
const int inf = INT_MAX / 2;
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 main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N;
    cin >> N;
    int H[N][3];
    rep(i, N) cin >> H[i][0] >> H[i][1] >> H[i][2];

    int dp[N][3];
    rep(i, N) rep(j, 3) dp[i][j] = 0;
    dp[0][0] = H[0][0], dp[0][1] = H[0][1], dp[0][2] = H[0][2];
    for (int i = 1; i < N; i++) {
        rep(j, 3) {
            rep(k, 3) {
                if (j == k) continue;
                chmax(dp[i][j], dp[i-1][k] + H[i][j]);
            }
        }
    }

    sort(dp[N-1], dp[N-1]+3, greater<int>());
    cout << dp[N-1][0] << endl;
}

Measured memory_bytes: 5976
s = input()
a = []
for i in range(2**(len(s)-1)):
    p = format(i, "0"+str(len(s)-1)+"b")
    num = ""
    for j in range(len(p)):
        if p[j] == "1":
            num += s[j]
            a.append(int(num))
            num = ""
        else:
            num += s[j]
    num += s[-1]
    a.append(int(num))
if len(s) != 1:
    print(sum(a))
else:
    print(s)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
	cin>>n;
	int ans=0;
	for(int i=1;i<=n;i++) {
		int a;
		cin>>a;
		if(i%2==1 && a%2==1) ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define cmin(a,b) (a>b?a=b:a)
#define cmax(a,b) (a<b?a=b:a)
#define mem(a,k) memset(a,k,sizeof(a))
#define lop(i,t) for(int i=0;i<(t);++i)
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
#define fore(i,v) for(int i=g[v],d=es[i].d;i;i=es[i].nxt,d=es[i].d)
using namespace std;

#define Pr(f,...) fprintf(stderr,f,##__VA_ARGS__),fflush(stderr)

typedef long long ll;

template<typename T>
void read(T &x){
	x=0; 
	char c;
	for(c=getchar();!isdigit(c);c=getchar()); 
	for(;isdigit(c);c=getchar())x=x*10+c-'0'; 
}

const int N = 1005;
int P;  
int mul(int a, int b) { return 1ll * a * b % P; } 
int add(int a, int b) { a += b; return a >= P ? a - P : a; }
void upd(int &a, int b) { a = add(a, b); }

int n, g[N], f[N], ans;

int getF(int i) {
	int x = -1; 
	for (; (x + 1) * (x + 1) + i * i < n * n;++x) ;
	return min(n + n, x + 1);
}

int getG(int i) {
	int x = -1; 
	for (; (x + 1) * (x + 1) + i * i <= n * n * 4; ++x) ; 
	return min(n + n, x + 1);
}

struct Bound { int u, i; } ; 
bool operator<(const Bound &a, const Bound &b) { return a.u < b.u || (a.u == b.u && a.i > b.i); } 

int main(int argc,char *argv[]){
#ifdef CURIOUSCAT
	freopen("d.in", "r", stdin); 
#endif
	cin >> n >> P;
	vector<Bound> v;
	lop(i, n) v.pb(Bound { getF(i), i }); 
	rep(i, n, n + n - 1) v.pb(Bound { getG(i), i });
	lop(i, n) g[i] = getG(i);
	sort(all(v)); 
	lop(k, n + 1) {
		mem(f, 0); 
		f[0] = 1;
		int a = 0, b = 0;
		for (auto e : v) {
			dec(i, k, 0) {
				if (e.i < n) {
					f[i] = mul(f[i], max(0, g[e.i] - (n + k + a - i)));
					if (i) upd(f[i], mul(f[i - 1], max(0, e.u - (b + i - 1))));
				} else {
					f[i] = mul(f[i], max(0, e.u - (b + i)));
				}
			}
			if (e.i < n) ++a; else ++b;	
		}
		upd(ans, k % 2 == 0 ? f[k] : mul(P - 1, f[k])); 
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
	string t;
	cin >> t;
	int n = t.size();
	rep(i, t.size()) {
		if (t[i] == '?') {
			t[i] = 'D';
		}
	}
	cout << t << endl;
}

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

int main() {
    int N, T, L, B;
    while(cin >> N >> T >> L >> B, N){
        vector<int> masu(N+1);
        for(int i=0;i<L;i++){
            int x;
            cin >> x;
            masu[x] = 1;
        }
        for(int i=0;i<B;i++){
            int x;
            cin >> x;
            masu[x] = 2;
        }
        vector<vector<double>> dp(T+2, vector<double>(N+1,0));
        dp[0][0] = 1;
        for(int i=0;i<T;i++){
            for(int j=0;j<N;j++){
                for(int k=1;k<=6;k++){
                    int nxt = N-abs(N-(j+k));
                    if(masu[nxt] == 0){
                        dp[i+1][nxt] += dp[i][j]/6;
                    }
                    else if(masu[nxt] == 1){
                        dp[i+2][nxt] += dp[i][j]/6;
                    }
                    else{
                        dp[i+1][0] += dp[i][j]/6;
                    }
                }
            }
        }
        double ans = 0;
        for(int i=0;i<=T;i++){
            ans += dp[i][N];
        }
        printf("%.10lf\n",ans);
    }
    return 0;
}



Measured memory_bytes: 3360