akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"

#pragma warning(disable:4996)
using namespace std;
using ld =long double;

vector<int>solve(int H,int W,int y,int x) {
	vector<int>anss;

	bool h_swap=false;
	bool hw_swap=false;
	bool w_swap=false;
	bool rot=false;
	if (y % 2 == 0) {
		y=H-1-y;
		h_swap=true;
	}
	else {
		h_swap=false;
	}
	if (x %2== 0) {
		x=W-x-1;
		w_swap=true;
	}
	else {
		w_swap=false;
	}
	if (y == H-1&&x==W-1) {
			for (int k = 0; k < (H + 1) / 2; ++k) {
				if (k) {
					anss.push_back(3);
				}
				for (int n = 0; n < W-1; ++n) {
					anss.push_back(0);
				}
				anss.push_back(3);
				for (int n = 0; n < W-1; ++n) {
					anss.push_back(2);
				}
			}
		
	}
	else {
		if (x==W-1) {
			hw_swap=true;
			swap(x,y);
			swap(H,W);
		}
		else {
			hw_swap = false;
		}
		int l = x;
		int r = W - 1 - x;

		int u = y;
		int d = H - 1 - y;

		for (int k = 0; k < (u + 1) / 2; ++k) {
			if (k) {
				anss.push_back(3);
			}
			for (int n = 0; n < l; ++n) {
				anss.push_back(0);
			}
			anss.push_back(3);
			for (int n = 0; n < l; ++n) {
				anss.push_back(2);
			}
		}
		anss.push_back(2);
		for (int k = 0; k < H / 2; ++k) {
			if (k)anss.push_back(1);
			for (int n = 0; n < r - 1; ++n) {
				anss.push_back(2);
			}
			anss.push_back(1);
			for (int n = 0; n < r - 1; ++n) {
				anss.push_back(0);
			}
		}

		if (d) {
			anss.push_back(0);
			for (int k = 0; k < (d + 1) / 2; ++k) {
				if (k) {
					anss.push_back(3);
				}
				for (int n = 0; n < l; ++n) {
					anss.push_back(0);
				}
				anss.push_back(3);
				for (int n = 0; n < l; ++n) {
					anss.push_back(2);
				}
			}
		}

	}
	

	

	for (auto &ans : anss) {
		if (hw_swap) {
			ans=3-ans;
		}
		if (h_swap&&ans % 2 == 1) {
			ans=4-ans;
		}
		if (w_swap&&ans % 2 == 0) {
			ans=2-ans;
		}
	}
	assert(anss.size() == H*W - 1);
	return anss;
	
}

int main() {
	int H,W;cin>>H>>W;
	vector<string>field(H);

	int sx,sy;
	int num=0;
	for (int i = 0; i < H; ++i) {
		cin>>field[i];
		for (int j = 0; j < W; ++j) {
			if (field[i][j] == '@') {
				sx=j;
				sy=i;
			}
			else if (field[i][j] == '*') {
				num++;
			}
		}
	}

	vector<int>move_ways=solve((H+1)/2,(W+1)/2,(sy+1)/2,(sx+1)/2);

	int nx=sx;
	int ny=sy;
	int dx[] = { -1,0,1,0 };
	int dy[] = { 0,1,0,-1 };
	for (auto m_way : move_ways) {
		for (int ti = 0; ti < 2; ++ti) {
			nx += dx[m_way];
			ny += dy[m_way];

			if (field[ny][nx] == '.') {
				field[ny][nx] = '#';
			}
			else {
				num--;
				if(num==0)break;
			}
		}
		if(num==0)break;
	}

	for (int i = 0; i < H; ++i) {
		cout<<field[i]<<endl;
	}
	return 0;
}


Measured memory_bytes: 3236
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
typedef  long long ll;
int gcd(int f , int s){if(s==0)return f;else return gcd(s,f%s);}
int const N = 600005;
ll const M = 998244353;
long double const ep = .000000000000000001;

int main() {
	
	string s;
	cin >> s;
	int a ;
	 cin >> a;
	 for(int i = 0 ; i < s.length() ; i++){
	 	if(i % a ==0 )cout << s[i];	
	 }
	return 0;	
}

Measured memory_bytes: 256
/**
 * author: Dhakad_123
**/

#include<bits/stdc++.h>
using namespace std;

int gcd(int a , int b){
    if(a == 0){
        return b;
    }
    return gcd(b%a , a);
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
     
    int k; 
    cin >> k;
    
    int sum = 0;
    
    
    for(int a = 1; a <= k; a++){
        for(int b = 1; b <= k; b++){
            for(int c = 1; c <= k; c++){
              int temp = gcd(a,b);
              sum += gcd(temp, c);
           
            }
        }
    }
    
    cout << sum <<"\n";
     
    return 0;
}

Measured memory_bytes: 3656
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<utility>
#include<tuple>
#include<algorithm>
#include<cmath>
using namespace std;

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  rep(i, N) cin >> a[i];
  sort(a.begin(), a.end());
  cout << a[N-1]-a[0] << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define repr(i,x,n) for(int i=x; i<(n); i++)
#define ALL(x) (x).begin(),(x).end()
#define INF 1e9
typedef long long ll;
using VI = vector<int>;
using VS = vector<string>;
using graph = vector<vector<int>>;
int main()
{

ll n,m;
cin>>n>>m;
vector<ll> h(n);
for (int i = 0; i < n; i++)
{
    cin>>h[i];

}
vector<bool>ans(n,true);
	rep(i,m){
    ll a,b;
    cin>>a>>b;
    a--;b--;
    if (h[a]<=h[b]) 
    {
       ans[a]=false;
    }
    if (h[a]>=h[b])
    {
        ans[b]=false;
    }
    
    
    }
    int cnt=0;
    	rep(i,n){
        if (ans[i])
        {
            cnt++;
        }
        }
        cout<<cnt<<endl;

}

Measured memory_bytes: 4008
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define eb(k,v) emplace_back(k,v)
#define ct(res) cout << res << "\n";
#define vi vector<int>
#define vl vector<ll>
using namespace std;
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; }
const int INF = 1e9;
const ll mod = 1000000007;

using Graph = vector<vector<int>>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll h,w;
    cin >> h >> w;
    if ((h==1 && w>1) || (h>1 && w==1)) {
        cout << 1 << "\n";
        return 0;
    }
    ll res = h*w-(h*w/2);
    cout << res << "\n";
    
}


Measured memory_bytes: 256
import math

n = int(input())
x = []
y = []
for i in range(n):
    a , b=map(int, input().split())
    x.append(a)
    y.append(b)
    
dist = 0

for j in range(n):
    for k in range(n):
        dist += math.sqrt(((x[j] - x[k])**2) +  ((y[j] - y[k])**2))
        
fac = math.factorial(n)
kaz = n * (n-1) / 2

bas = dist / 2
print (bas * (n-1) / kaz )

Measured memory_bytes: 3064
// cout << "Case #" << k << ": ";
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;
int main() {
    int x, y, z;
    cin >> x >> y >> z;
    swap(x, y);
    swap(x, z);
    cout << x << " " << y << " " << z << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cmath>
#include <set>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
using namespace std;
typedef long long ll;
int main()
{
    //freopen("a.in","r",stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int x,y,z;
    cin>>x>>y>>z;
    swap(x,y);
    swap(x,z);
    cout<<x<<" "<<y<<" "<<z<<"\n";
    return 0;
}

Measured memory_bytes: 256
N = int(input())
S = input()

r = 0; g = 0; b = 0
for i in range(N):
    if S[i] == "R":
        r+=1
    elif S[i] == "G":
        g+=1
    else:
        b+=1

all = r*g*b; sub = 0
for i in range(N):
    for j in range(i+1, N):
        if S[i] == S[j]:
            continue
        else:
            k = 2 * j - i
            if k >= N:
                continue
            else:
                if (S[j] == S[k]) or (S[i] == S[k]):
                    continue
                else:
                    sub+=1

print(all - sub)

Measured memory_bytes: 9244
while True:
    n=str(input())
    if n=='0':
        break
    B=len(n)
    N=list(n)
    a=0
    b=0
    for i in range(B-1):
        C=N[i+1]
        if C=='A':
            a=a+1
        else:
            b=b+1
    if a>b:
        a=a+1
    else:
        b=b+1
    print(a,b)


Measured memory_bytes: 5556
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rrep(i, n) for(ll i = n - 1; i > -1; i--)
#define all(v) v.begin(), v.end()
#define pb push_back
#define fi first
#define se second
template <class X> void print(X x) { cout << x << endl; }
void print(vl x) {
    for(ll i : x) {
        cout << i << " ";
    }
    cout << endl;
}
const ll INF = (1LL << 61) - 1;
const ll MOD = 1000000007 /*998244353*/;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, h, x, y, z, p, q, n, t, r, k, w, l, ans, i, j, u, v, m;
ll codeforces = 1;
string S, T;
vl A, B;
void input() { cin >> h >> w >> t; }
void solve() {
    ll masu[h][w];
    rep(i, h) {
        cin >> S;
        rep(j, w) {
            if(S[j] == '.')
                masu[i][j] = 0;
            else
                masu[i][j] = 1;
        }
    }

    rep(i, (1 << h)) {
        rep(j, (1 << w)) {
            a = 0;
            rep(k, h) {
                rep(l, w) {
                    if(masu[k][l] == 1 && !((1 << k) & i) && !((1 << l) & j))
                        a++;
                }
            }
            if(a == t) {
                // cout << i << " " << j << endl;
                ans++;
            }
        }
    }

    print(ans);
}
int main() {
    // cout<<fixed<<setprecision(15);
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    while(codeforces--) {
        solve();
    }
}

Measured memory_bytes: 3636
n, a, b = map(int, input().split())

total_sum = 0

for x in range(1, n+1):
    x_str = str(x)
    x_str = map(int, x_str)
    sum_dig = sum(x_str)
    if(a<=sum_dig and sum_dig<=b):
        total_sum+=x

print(total_sum)


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>
using namespace std;
typedef long long i64;
typedef long double ld;
typedef pair<i64,i64> P;
#define rep(i,s,e) for(int i = (s);i <= (e);i++)

int h,w;

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

    vector<int> cou(256,0);

    rep(i,1,h)
    {
        string s;
        cin >> s;
        for(char c : s)
            cou[c]++;
    }

    int q = 0;
    int p = 0;
    int odd = 0;

    for(int c : cou)
    {
        q += c / 4;
        c %= 4;
        p += c / 2;
        odd += c % 2;
    }

    int mod_h = h % 2;
    h -= mod_h;
    int mod_w = w % 2;
    w -= mod_w;

    int need = h * w / 2 / 2;
    q -= need;

    if(q < 0)
    {
        cout <<"No" << endl;
        return 0;
    }

    p += q * 2;
    q = 0;


    if(mod_h == 1 && mod_w == 0)
    {
        p -= w / 2;        
    }
    if(mod_h == 0 && mod_w == 1)
    {
        p -= h / 2;

    }
    if(mod_h == 1 && mod_w == 1)
    {
        p -= w / 2 + h / 2;
        odd--;
    }

    if(q == 0 && p == 0 && odd == 0)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

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

int main(){
  int N;
  cin>>N;
  vector<int> num(N);
  for(int i=0;i<N;i++){
    cin>>num.at(i);
  }
  int count =0;
  bool judge = true;
  while(judge){
    judge = false;
    for (int j=N-1;1<=j;j--){
      if(num[j]<num[j-1]){
        int v=num[j],w=num[j-1];
        num[j]=w;
        num[j-1]=v;
        judge = true;
        count++;
      }
    }
  }
  for(int i=0;i<N;i++){
    if(i==N-1){
      cout<<num[N-1]<<endl;
      break;
    }
    cout<<num[i]<<" ";
  }
  cout<<count<<endl;
}


Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
#define maxn 55
#define maxm 125005
#define int long long
#define INF 1e9 + 10
int n, X, D, ans, cnt, dp[maxm];
int w[maxn], val[maxn], pos[maxn];
int tot, V[maxn * maxn], W[maxn * maxn];
     
int read()
{
    int x = 0, k = 1;
    char c; c = getchar();
    while(c < '0' || c > '9') { if(c == '-') k = -1; c = getchar(); }
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * k;
}
     
struct edge
{
    int cnp, to[maxn], last[maxn], head[maxn];
    edge() { cnp = 1; }
    void add(int u, int v) 
    { to[cnp] = v, last[cnp] = head[u], head[u] = cnp ++; }
}E1;
     
void dfs(int u)
{
    val[u] = 1;
    for(int i = E1.head[u]; i; i = E1.last[i])
    {
    	int v = E1.to[i];
    	dfs(v);
    	w[u] += w[v]; val[u] += val[v];
    }
    cnt += val[u] * n; pos[u] = u;
}
     
bool cmp(int x, int y) { return val[x] * w[y] > val[y] * w[x]; }
void Get_min(int &x, int y) { x = x < y ? x : y; }
     
signed main()
{
    n = read(), X = read(), D = read();
    w[1] = read();
    for(int i = 2; i <= n; i ++)
    {
    	w[i] = read(); int x = read();
    	E1.add(x, i);
    }
    dfs(1);
    sort(pos + 1, pos + n + 1, cmp);
    int tmp = min(n, D);
    for(int i = 1; i <= cnt; i ++) dp[i] = INF;
    for(int i = 1; i <= n; i ++)
	{
		int len = 1, lim = tmp;
		while(lim >= len)
		{
			V[++ tot] = len * val[pos[i]];
			W[tot] = len * w[pos[i]];
			lim -= len, len <<= 1;
		}
		if(lim) V[++ tot] = lim * val[pos[i]], W[tot] = lim * w[pos[i]];
	}
    for(int i = 1; i <= tot; i ++)
    	for(int j = cnt; ~j; j --)
    			if(j >= V[i]) Get_min(dp[j], dp[j - V[i]] + W[i]); // k件物品 
    int ans = 0;
    for(int i = 0; i <= cnt; i ++)
   	{
    	if(dp[i] > X) continue;
    	int ret = i, left = X - dp[i];
    	for(int j = 1; j <= n; j ++)
    	{
    		int tem = pos[j], used = min(max(D - n, 0LL), left / w[tem]);
    		if(tem == 1) used = left / w[tem];
    		left -= w[tem] * used;
    		ret += val[tem] * used;
    	}
    	ans = max(ans, ret);
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 768
#include<stdio.h>
int main()
{
    int X,Y,Z;
    scanf("%d%d%d",&X,&Y,&Z);
    X = X + Y + Z;
    Y = X - (Y+Z);
    Z = X - (Y+Z);
    X = X - (Y+Z);
    printf("%d %d %d",X,Y,Z);
    return 0;
}


Measured memory_bytes: 1648
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|s| s.parse().ok().unwrap())
        .collect()
}

fn main() {
    let input = read_vec::<usize>();
    let (n, m) = (input[0], input[1]);
    let mut lights = vec![];
    for _ in 0..m {
        let input = read_vec::<usize>();
        let light = input.into_iter().skip(1).collect::<Vec<_>>();
        lights.push(light);
    }
    let ps = read_vec::<usize>();

    let mut count = 0;

    'o: for i in 0..1 << n {
        for (light, &p) in lights.iter().zip(ps.iter()) {
            let switch_on = light.iter().filter(|&x| i & (1 << (x-1)) == (1 << (x-1))).count();
            if switch_on % 2 != p {
                continue 'o;
            }
        }
        count += 1;
    }
    println!("{}", count);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using P = pair<lint, lint>;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
void yes(bool expr) {
  cout << (expr ? "Yes" : "No") << "\n";
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  lint ai, ao, at, aj, al, as, az;
  cin >> ai >> ao >> at >> aj >> al >> as >> az;
  lint K = ao;
  lint tmp = ai/2*2 + aj/2*2 + al/2*2;
  if(ai > 0 && aj > 0 && al > 0) tmp = max(tmp, (ai-1)/2*2 + (aj-1)/2*2 + (al-1)/2*2 + 3);
  K += tmp;
  cout << K << endl;
}

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


#define ll long long
#define pll pair <ll,ll>
#define fi first
#define se second
#define endl "\n"
#define sqr(b) (b)*(b)


using namespace std;



int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//    freopen("", "r", stdin);
//    freopen("", "w", stdout);

    ll n, w;
    ll a[111][2];

    cin >> n >> w;
    for (int i = 1; i <= n; i++) {
        cin >> a[i][0] >> a[i][1];
    }

    ll dp[111111];
    for (int i = 1; i <= w; i++) dp[i] = -2e9;

    for (int i = 1; i <= n; i++) {
        for (int j = w; j > 0; j--) if (j - a[i][0] >= 0) {
            dp[j] = max(dp[j], dp[j - a[i][0]] + a[i][1]);
        }
    }


    ll ans = 0;
    for (int i = 0; i <= w; i++) ans = max(ans, dp[i]);

    cout << ans << endl;

    return 0;
}


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

using ll = long long;
using ull = unsigned long long;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define all(a) begin(a),end(a)
template<class T> inline void sort_uniq(T& c) { sort(ALL(c)); c.erase(unique(ALL(c)), c.end()); }
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_v(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << endl; }
template<class T> void cout_h(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
inline int powi(int x,int y) {int p=1; while(y--) p*=x; return p;}
inline ll powll(ll x,ll y) {ll p=1; while(y--) p*=x; return p;}
template<class T> inline bool is_overlap(const T& a, const T& b, const T& p, const T& q)
{ return p <=b && a <= q; }

#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 

#define countof(a) (sizeof(a)/sizeof(a[0]))
ll dp[100010];


ll rec(int n)
{
    if (n == 0)
        return 0;

    if (dp[n] != LLONG_MAX)
        return dp[n];

    ll r = LLONG_MAX;
    chmin(r, rec(n - 1) + 1);
    for (int x = 1; x <= n; x *= 6) {
        chmin(r, rec(n - x) + 1);
    }
    for (int x = 1; x <= n; x *= 9) {
        chmin(r, rec(n - x) + 1);
    }

    return dp[n] = r;
}

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

    int N; cin >> N;

    rep(i, countof(dp)) {
        dp[i] = LLONG_MAX;
    }

    cout << rec(N) << endl;
}


Measured memory_bytes: 4224
#include<stdio.h>
#include<stdlib.h>
  
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef node* Node;
#define NIL NULL
 
node array[500000];
int size=0;
 
Node root = NIL;
  
Node treeMinimum(Node x){
  while(x->left!=NIL)x=x->left;
  return x;
}
  
Node treeSearch(Node u, int k){
  Node i=u;
  while(i!=NIL){
    if(i->key==k)return i;
    else if(i->key<k)i=i->right;
    else i=i->left;     
  }
  return NIL;
}
  
Node treeSuccessor(Node x){
  return treeMinimum(x->right);
}
  
void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  if(z->left==NIL||z->right==NIL)y=z;
  else y=treeSuccessor(z);
    
  if(y->left!=NIL)x=y->left;
  else x=y->right;
  
  if(x!=NIL)x->parent=y->parent;
    
  if(y->parent==NIL)root=x;
  else if(y==y->parent->left)y->parent->left=x;
  else y->parent->right=x;
  
  if(y!=z)z->key=y->key;
    
  //free(y);
}
  
void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
  
  z = &array[size++];
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  
  while(x!=NIL){
    y=x;
    if(z->key<x->key)x=x->left;
    else x=x->right;
  }
  z->parent=y;
  if(y==NIL)root=z;
  else if(z->key<y->key)y->left=z;
  else y->right=z;   
}
 
 
void inorder(Node u){
  if(u==NIL)return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
 
void preorder(Node u){
  if(u==NIL)return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}
 
 
int main(){
  int n,x;
  char str[20];
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%s", str);
    if(str[0]=='f'){
      scanf("%d",&x);
      Node t=treeSearch(root,x);
      if (t!=NIL) printf("yes\n");
      else printf("no\n");
    }else if(str[0]=='i'){
      scanf("%d",&x);
      insert(x);
    }else if(str[0]=='p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }else if(str[0]=='d'){
      scanf("%d",&x);
      treeDelete(treeSearch(root,x));
    }
  }
 
  return 0;
}

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

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


Measured memory_bytes: 3644
#include <stdio.h> 
 
 
 int main(){ 
     int a, b, d, r; 
     double f; 
     scanf("%d %d", &a, &b); 
     d=a/b; 
     r=a%b; 
     f=(double)a/(double)b; 
     printf("%d %d %f\n", d, r, f); 
     return 0; 
 } 



Measured memory_bytes: 2144
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ll;
const int INF = 1<<30;

int main(){
  string a, b, c;cin>>a>>b>>c;
  cout<<char(a[0]+'A'-'a')<<char(b[0]+'A'-'a')<<char(c[0]+'A'-'a')<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <unordered_map>

using namespace std;

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

    vector<int> IDs;
    IDs.resize(N,0);
//    result.resize(N,0);

    for(int i = 1; i < N ; i++){
        int id;
        cin>>id;
        IDs[i] = id;
    }

    // Find all Ids equal to 1 and
    // when 1's are finised increment it and
    // search for that and so on

    unordered_map<int,int> count;
    for(int id:IDs){
        if(id == 0){continue;}
        if(count.find(id) == count.end()){
            count[id] = 1;
        }else{
            count[id] += 1;
        }
    }

    for(int i = 0 ; i < N ; i++){
        if(count.find(i+1) == count.end()){
            cout<<0<<endl;
        }else{
            cout<<count[i+1]<<endl;
        }
    }

    return 0;
}


Measured memory_bytes: 12156
#include <set>
#include <cstdio>
#include <numeric>
#include <algorithm>
#include <queue>

inline int getInt(){ int s; scanf("%d", &s); return s; }

typedef long long ll;

using namespace std;

int check(int a, int m){
  vector<int> visit(m);
  int now = 0;

  while(!visit[now]){
    visit[now] = 1;
    now = (now + a) % m;
  }

  return accumulate(visit.begin(), visit.end(), 0);
}

int main(){
  int m = getInt();
  int n = getInt();
  int a = getInt();
  int b = getInt();
  int c = getInt();
  int d = getInt();

  a %= m;
  b %= n;
  c %= m;
  d %= n;

  int acnt = check(a, m);
  int bcnt = check(b, n);

  ll ans1 = ((ll)acnt * bcnt) / __gcd(acnt, bcnt);
  ll ans2 = 0;

  vector<int> h(m, -1);
  int hh = 0;
  int xx = 0;
  int yy = 0;

  while(h[xx] == -1){
    h[xx] = yy;
    xx = (xx + a) % m;
    yy = (yy + b) % n;
    hh++;
  }

  int ym = ans1 / hh;
  int yd = n / ym;

  xx = c;
  yy = d;

  while(true){
    ans2++;

    if(ans2 == 1000 * n){
      int ccnt = check(c, m);
      int dcnt = check(d, n);
      ans2 = ((ll)ccnt * dcnt) / __gcd(ccnt, dcnt);
      break;
    }

    if(h[xx] != -1){
      if((yy - h[xx] + n) % yd == 0)
        break;
    }

    xx = (xx + c) % m;
    yy = (yy + d) % n;
  }

  printf("%lld\n", ans1 * ans2 - 1);

  return 0;
}

Measured memory_bytes: 0
#include<cstdio>
#include<cctype>
#define RI register int
#define CI const int&
#define Tp template <typename T>
using namespace std;
const int N=100005;
struct edge
{
	int to,nxt,id;
}e[N<<1]; int head[N],n,cnt,m,x[N],y[N],out[N],ansx[N],ansy[N],anc[N]; bool vis[N],cs[N];
class FileInputOutput
{
	private:
		static const int S=1<<21;
		#define tc() (A==B&&(B=(A=Fin)+fread(Fin,1,S,stdin),A==B)?EOF:*A++)
		#define pc(ch) (Ftop!=Fend?*Ftop++=ch:(fwrite(Fout,1,S,stdout),*(Ftop=Fout)++=ch))
		char Fin[S],Fout[S],*A,*B,*Ftop,*Fend; int pt[15];
	public:
		FileInputOutput() { Ftop=Fout; Fend=Fout+S; }
		Tp inline void read(T& x)
		{
			x=0; char ch; while (!isdigit(ch=tc()));
			while (x=(x<<3)+(x<<1)+(ch&15),isdigit(ch=tc()));
		}
		Tp inline void write(T x,const char& ch)
		{
			RI ptop=0; while (pt[++ptop]=x%10,x/=10);
			while (ptop) pc(pt[ptop--]+48); pc(ch);
		}
		inline void flush(void)
		{
			fwrite(Fout,1,Ftop-Fout,stdout);
		}
		#undef tc
		#undef pc
}F;
inline void addedge(CI x,CI y,CI z)
{
	e[++cnt]=(edge){y,head[x],z}; head[x]=cnt;
	e[++cnt]=(edge){x,head[y],z}; head[y]=cnt;
}
#define to e[i].to
inline void DFS1(CI now=1)
{
	vis[now]=1; for (RI i=head[now];i;i=e[i].nxt)
	if (!vis[to]) cs[e[i].id]=1,anc[to]=e[i].id,DFS1(to);
}
inline void DFS2(CI now=1,CI fa=0)
{
	for (RI i=head[now];i;i=e[i].nxt) if (cs[e[i].id]&&to!=fa) DFS2(to,now);
	if (out[now]&1) ansx[anc[now]]=now,ansy[anc[now]]=fa;
	else ansx[anc[now]]=fa,ansy[anc[now]]=now,++out[fa];
}
#undef to
int main()
{
	//freopen("CODE.in","r",stdin); freopen("CODE.out","w",stdout);
	RI i; for (F.read(n),F.read(m),i=1;i<=m;++i)
	F.read(x[i]),F.read(y[i]),addedge(x[i],y[i],i);
	if (m&1) return puts("-1"),0;
	for (DFS1(),i=1;i<=m;++i) if (!cs[i])
	++out[x[i]],ansx[i]=x[i],ansy[i]=y[i];
	for (DFS2(),i=1;i<=m;++i) F.write(ansx[i],' '),F.write(ansy[i],'\n');
	return F.flush(),0;
}

Measured memory_bytes: 12160
#include<iostream>
using namespace std;
int main(){
    int a,b,c,d;
    cin>> a >> b >> c;
    if(a>b){
    d=a;
    a=b;
    b=d;
}
    if(b>c){
    d=b;
    b=c;
    c=d;
}
    if(a>b){
    d=a;
    a=b;
    b=d;
}
    cout<< a << " " << b << " " << c <<endl;
    return 0;

}


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

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

    for(int i = 0;i<S.size();i++){
        
            if(S[i]==S[i+1]){
                cout << "Bad";
                return 0;
            
        }
    }

cout << "Good" ;
    
}



Measured memory_bytes: 256
# -*- coding: utf-8 -*-
# 
import math
import sys
import itertools
import numpy as np

# いっこ入力
n =int(input())

# 空白区切りの数列をリストに代入
a = [int(i) for i in input().split()]
b =[0]
# if b1 were 0
b.append(2*a[0])
for i in range(2,n):
    b.append(2*a[i-1]-b[i-1])
suma=0
sumb=0
for i in range(n):
    suma += a[i]
    sumb += b[i]
#print(b)
a1 = sumb - suma
for i in range(n):
    if i % 2 ==0:
        b[i] -= a1
    else:
        b[i] += a1
#print(b)
for i in range(n):
    print(b[i],end=" ")
print("")


Measured memory_bytes: 23108
from collections import Counter as C 
n=int(input())
A=list(map(int,input().split()))+[0,1,2,3]
A=sorted(C(list(map(lambda x:x%4,A))).most_common())
if A[2][1]==1:
  print('Yes' if A[0][1]+2>=A[1][1]+A[3][1] else 'No')
else:
  print('Yes' if A[0][1]+1>=A[1][1]+A[3][1] else 'No')

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

using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

vector<bool> isPrime;

void sieve(size_t MAX) {
    if (MAX + 1 > isPrime.size()) isPrime.resize(MAX + 1, true);
    isPrime[0] = false;
    isPrime[1] = false;
    for (int_fast64_t i = 2; i * i <= MAX; ++i) {
        if (isPrime[i]) {
            for (int_fast64_t j = 2; i * j <= MAX; ++j) isPrime[i * j] = false;
        }
    }
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    sieve(int(1e5) + 10);

    vector<int> cum(int(1e5) + 10);
    for (size_t i = 1; i <= int(1e5); ++i) {
        cum[i] = cum[i - 1];
        if (isPrime[i] && isPrime[(i + 1) / 2]) cum[i]++;
    }

    int Q; cin >> Q;
    while (Q--) {
        int l, r; cin >> l >> r;
        cout << cum[r] - cum[l - 1] << "\n";
    }

    return 0;
}


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

namespace AIZUproject08
{
    //128B
    /*class Data
    {
        public int ID { get; set; }
        public string Name { get; set; }
        public int Evaluation { get; set; }
    }
    class Program
    {
        static void Main()
        {
            List<Data> datalist = new List<Data>();
            Data data;
            int N = int.Parse(Console.ReadLine());
            for (int i=0;i< N;i++)
            {
                var temp = Console.ReadLine().Split(' ');
                data = new Data();
                data.ID = i + 1;
                data.Name = temp[0];
                data.Evaluation = int.Parse(temp[1]);
                datalist.Add(data);
            }
            datalist = datalist.OrderBy(n => n.Name).ThenByDescending(n => n.Evaluation).ToList();
            foreach (var ans in datalist)
            {
                Console.WriteLine(ans.ID);
            }
        }
    }*/
    //127B
    /*class Program
    {
        static void Main()
        {
            int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int r = input[0];
            int D = input[1];
            int X = input[2];
            for (int i=0;i<10;i++)
            {
                var ans = r * X - D;
                Console.WriteLine(ans);
                X = ans;
            }
        }
    }*/
    //126B
    class Program
    {
        static void Main()
        {
            List<int> mae = new List<int>();
            List<int> ushiro = new List<int>();
            string input = Console.ReadLine();
            var rabel = "NA";
            for (int i = 0; i < 2; i++)
            {
                char moji = input[i];
                mae.Add(int.Parse(string.Join("",moji)));
            }
            for (int i = 2; i < 4; i++)
            {
                char moji = input[i];
                ushiro.Add(int.Parse(string.Join("", moji)));
            }
            int A = 10 * mae[0] + 1 * mae[1];
            int B = 10 * ushiro[0] + 1 * ushiro[1];

            if (0 <= A && A <= 99 && 0 < B && B < 13)
            {
                rabel = "YYMM";
                if (0 < A && A < 13 && 0 < B && B < 13)
                {
                    rabel = "AMBIGUOUS";
                }
            }
            else if (0 <= B && B <= 99 && 0 < A && A < 13)
            {
                 rabel = "MMYY";
                if (0 < A && A < 13 && 0 < B && B < 13)
                {
                    rabel = "AMBIGUOUS";
                }
            }



            Console.WriteLine(rabel);
        }
    }
}



Measured memory_bytes: 11220
def read_int():
    return int(input())


def read_ints():
    return map(int, input().split(' '))


n = read_int()
a = []
b = []
for i in range(n):
    ai, bi = read_ints()
    a.append(ai)
    b.append(bi)
a.sort()
b.sort()
if n % 2 == 0:
    ma = a[n // 2 - 1] + a[n // 2]
    mb = b[n // 2 - 1] + b[n // 2]
    print(mb - ma + 1)
else:
    ma = a[n // 2]
    mb = b[n // 2]
    print(mb - ma + 1)


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

#define INF 1e9
#define rep(i,j,n) for(int (i)=(j);(i)<(n);(i)++)
#define rep2(i,j,n) for(int (i)=(j);(i)<=(n);(i)++)
#define all(i) (i).begin(),(i).end()
#define rall(i) (i).rbegin(),(i).rend()

typedef long long i64;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<vs> vvs;

int main(){
  int n,k;
  cin>>n>>k;
  vi l(n);
  rep(i,0,n) cin>>l[i];
  sort(rall(l));
  int sum=0;
  rep(i,0,k) sum+=l[i];
  cout<<sum<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int sp = sc.nextInt();
		int q = sc.nextInt();
		
		int[] point = new int[n];
		for (int i = 0; i < point.length; i++) {
			point[i] = sp - q;
		}
		
		int[] answer = new int[q];
		for (int i = 0; i < answer.length; i++) {
			answer[i] = sc.nextInt();
			point[answer[i] - 1]++;
		}
		
		for (int i : point) {
			if (i <= 0) {
				System.out.println("No");
			} else {
				System.out.println("Yes");
			}
		}
		
	}
}

Measured memory_bytes: 58352
///                   _ooOoo_
///                  o8888888o
///                  88" . "88
///                  (| -_- |)
///                  O\  =  /O
///               ____/`---'\____
///             .'  \\|     |//  `.
///            /  \\|||  :  |||//  \
///           /  _||||| -:- |||||-  \
///           |   | \\\  -  /// |   |
///           | \_|  ''\---/''  |   |
///           \  .-\__  `-`  ___/-. /
///         ___`. .'  /--.--\  `. . __
///      ."" '<  `.___\_<|>_/___.'  >'"".
///     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
///     \  \ `-.   \_ __\ /__ _/   .-` /  /
///======`-.____`-.___\_____/___.-`____.-'======
///                   `=---='
///^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
///
///         佛祖保佑       永无BUG
///  本模块已经经过开光处理，绝无可能再产生bug
///
///=============================================
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i = j;i <= k;++i)
#define repp(i,j,k) for(int i = j;i >= k;--i)
#define rept(i,x) for(int i = linkk[x];i;i = e[i].n)
#define P pair<int,int>
#define Pil pair<int,ll>
#define Pli pair<ll,int>
#define Pll pair<ll,ll>
#define pb push_back 
#define pc putchar
#define mp make_pair
#define file(k) memset(k,0,sizeof(k)
#define ll long long
int rd()
{
	int num = 0;char c = getchar();bool flag = true;
	while(c < '0'||c > '9') {if(c == '-') flag = false;c = getchar();}
	while(c >= '0' && c <= '9') num = num*10+c-48,c = getchar();
	if(flag) return num;else return -num;
}
int main()
{ 
    int n = rd();
	if(n == 1) printf("Hello World");
	else
	{
		int a = rd(),b = rd();
		printf("%d\n",a+b);
	} 
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <map>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int dx[]={-1,1,0,0},dy[]={0,0,-1,1};
class DICE{
public:
	vector<int> dice;
	DICE(){
		dice.resize(6);
		rep(i,6)dice[i]=i+1;
	}
	// top/front/right/left/back/bottom  
	void back(){
		int to[] = {4,0,2,3,5,1};
		vector<int> tmp(6);
		rep(i,6)tmp[to[i]] = dice[i];
		dice = tmp;
	}
	void left(){
		int to[] = {3,1,0,5,4,2};
		vector<int> tmp(6);
		rep(i,6)tmp[to[i]] = dice[i];
		dice = tmp;
	}
	void rotate(){
		int to[] = {0,3,1,4,2,5};
		vector<int> tmp(6);
		rep(i,6)tmp[to[i]] = dice[i];
		dice = tmp;
	}
	void select(int n){
		if(n==0)left();
		else if(n==1)left(),left(),left();
		else if(n==2)back();
		else if(n==3)back(),back(),back();
	}
};
struct NODE{
	int cost,x,y;
	DICE dice;
	NODE(int a,int b,int c,DICE d){cost = a , x = b , y = c , dice = d;}
};
bool operator<(const NODE &a,const NODE &b){
	if(a.x != b.x)return a.x < b.x;
	if(a.y != b.y)return a.y < b.y;
	if(a.dice.dice != b.dice.dice)return a.dice.dice < b.dice.dice;
	return false;
}
bool operator>(const NODE &a,const NODE &b){
	return a.cost > b.cost;
}
int main(){
	int W,H;
	int data[10][10];
	while(cin >> H >> W , H){
		map<NODE,bool> done;
		priority_queue<NODE,vector<NODE>,greater<NODE> > Q;
		rep(i,H)rep(j,W)
			cin >> data[i][j];
		int sx,sy,gx,gy;
		cin >> sy >> sx >> gy >> gx;
		Q.push(NODE(0,sx,sy,DICE()));
		while(Q.size()){
			NODE q = Q.top(); Q.pop();
			if(done[q])continue;
			else done[q] = true;
			if(q.x == gx && q.y == gy){
				cout << q.cost << endl;
				break;
			}
			rep(i,4){
				NODE next = q;
				next.x = dx[i] + q.x;
				next.y = dy[i] + q.y;
				next.dice.select(i);
				if(next.x < 0 || next.y < 0 || next.y >= H || next.x >= W) continue;
				next.cost = q.cost + next.dice.dice[5] * data[next.y][next.x] ;
				Q.push(next);
			}
		}
	}
}

Measured memory_bytes: 1112
#include<iostream>

using namespace std;

typedef struct{
  int x;
  int y;
}Point;

Point now;
int max_x, max_y;
int dir;
int mx[4] = {0,1,0,-1};
int my[4] = {1,0,-1,0};

void change(string in){
  if(in[0] == 'R'){
    if(dir == 3) dir = 0;
    else dir++;
  }else{
    if(dir == 0) dir = 3;
    else dir--;
  }
}

void move(string s,int num){
  if(s[0] == 'F'){
    for(int i = 0; i < num; i++){
      if(now.x+mx[dir] > max_x || now.x+mx[dir] <= 0 ||
	 now.y+my[dir] > max_y || now.y+my[dir] <= 0) return;
      now.x += mx[dir];
      now.y += my[dir];
    } 
  }else{
    for(int i = 0; i < num; i++){
      if(now.x-mx[dir] > max_x || now.x-mx[dir] <= 0 ||
	 now.y-my[dir] > max_y || now.y-my[dir] <= 0) return;
      now.x -= mx[dir];
      now.y -= my[dir];
    } 
  }
}

int main(){
  while(cin >> max_x >> max_y && max_x+ max_y){
    dir = 0;
    now.x = now.y = 1;
    while(1){
      string s;  int pos;
      cin >> s;
      if(s == "STOP") break;
      if(s == "RIGHT"|| s == "LEFT") change(s);
      else {
	cin >> pos;
	move(s,pos);
      }
    }
    cout << now.x << " " << now.y << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}
template<class A,size_t N,class T>void Fill(A(&a)[N],const T&v){fill((T*)a,(T*)(a+N),v);}

const int MOD = 1e9+7; //998244353;

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m=MOD){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m=MOD){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
V<ll>Fac,Rac;void setF(int n,int m=MOD){Fac=Rac=V<ll>(++n);Fac[0]=1;FOR(i,1,n)Fac[i]=Fac[i-1]*i%m;Rac[n-1]=modInv(Fac[n-1],m);FORR(i,n-1,1)Rac[i-1]=Rac[i]*i%m;}
ll comb(int a,int b,int m=MOD){return a<b||b<0?0:Fac[a]*Rac[b]%m*Rac[a-b]%m;}

const int IINF = 1e9+6;
const ll LINF = 1e18;
const int N = 5e5+1;
int n, m;
ll a[N], b[N];

main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  setF(N*2);
  cin >> n >> m;
  m -= n;
  a[0] = 1;
  FOR(i, 1, n+1){
     a[i] = (a[i-1]*m + b[i-1]*(i-1)) % MOD;
     b[i] = (a[i-1]*(m+1) + b[i-1]*(i-1)) % MOD;
  }
  cout << a[n]*Fac[n+m]%MOD*Rac[m]%MOD << endl;
}

Measured memory_bytes: 26504
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<set>
#include<map>
#include<string>

using namespace std;

	map < pair < string , string > , long long > mapa;
	
	pair < string , string > separate(string a){
		string mali = "", VELIKI = "";
		for(int i = 0; i < a.size(); i++){
			if(a[i] >= 97) mali += a[i];
			else VELIKI = a[i] + VELIKI;
		}
		return make_pair(mali,VELIKI);
	}
	
	pair < string , string > swaping(pair < string , string > a){
		
		string rev_mali = "";
		string rev_veliki = "";
		
		for(int i = 0; i < a.first.size(); i++){
			rev_veliki+=a.first[i] - 32;
		}
		for(int i = 0; i < a.second.size(); i++){
			rev_mali+=a.second[i] + 32;
		}
		return make_pair(rev_mali , rev_veliki);
	}

int main(){

	int n; cin >> n;
	string s; cin >> s;
	string b; b = s.substr(0,n);
	
	for(int i = 0; i < (1<<n); i++){
		b = s.substr(0,n);
		for(int j = 0; j < 20; j++) if(i&(1<<j)) b[j] = s[j] - 32;
		if(mapa.count(separate(b)) == 0) mapa[separate(b)] = 1;	
		else mapa[separate(b)] += 1;	
	//	cout << b << " " << s << endl;
	} 
	
	long long sol = 0;
	for(int i = 0; i < (1<<n); i++){
		b = s.substr(n,n);
		for(int j = 0; j < 20; j++) if(i&(1<<j)) b[j] = s[j+n] - 32;	
		if(mapa.count(swaping(separate(b))) != 0) sol += mapa[swaping(separate(b))];
	//	cout << b << " " << s << endl;
	} cout << sol << endl;





	return 0;
}



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

using namespace std;

typedef long long ll;
typedef pair <ll, ll> II;
#define X first
#define Y second

const int N = 1e5 + 10;
const int oo = 1e9 + 10;

int n;
II a[N];
ll res[N];

int main(){
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i].X;
        a[i].Y = i;
    }
    sort(a + 1, a + 1 + n);
    reverse(a + 1, a + 1 + n);
    ll cur = oo, pos = n + 1;
    for (int l = 1; l <= n; l++) {
        int r = l;
        res[pos] += (cur - a[l].X) * (ll) (l - 1);
        cur = a[l].X;
        while (a[l].X == a[r].X && r <= n)
            pos = min(a[r++].Y, pos);
        l = r - 1;
    }
    res[1] += cur * (ll)n;
    for (int i = 1; i <= n; i++)
        cout << res[i] << endl;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()
#define INF 1<<25

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const int MAX_V = 110 * 110 * 2 + 2;

// 辺を表す構造体（行き先、容量、逆辺）
struct edge{ int to, cap, rev; };

vector<edge> G[MAX_V];	// グラフの隣接リスト表現
int level[MAX_V];		// s からの距離
int iter[MAX_V];		// どこまで調べ終わったか

// from から to へ向かう容量 cap の辺をグラフに追加する
void add_edge (int from, int to, int cap){
	G[from].push_back ((edge){to, cap, G[to].size()});
	G[to].push_back ((edge){from, 0, G[from].size()-1});
}

// s からの最短距離を BFS で計算する
void bfs(int s){
	memset (level, -1, sizeof (level));
	queue<int> que;
	level[s] = 0;
	que.push (s);
	while (!que.empty()){
		int v = que.front(); que.pop();
		rep (i, G[v].size()){
			edge &e = G[v][i];
			if (e.cap > 0 && level[e.to] < 0){
				level[e.to] = level[v] + 1;
				que.push (e.to);
			} // end if
		} // end rep
	} // end while
}

// 増加バスを DFS で探す
int dfs (int v, int t, int f){
	if (v == t) return f;
	for (int &i = iter[v]; i < G[v].size(); ++i){
		edge &e = G[v][i];
		if (e.cap > 0 && level[v] < level[e.to]){
			int d = dfs (e.to, t, min (f, e.cap));
			if (d > 0){
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			} // end if
		} // end if
	} // end for

	return 0;
}

// s から t への最大流を求める
int max_flow (int s, int t){
	int flow = 0;
	for (;;){
		bfs (s);
		if (level[t] < 0) return flow;
		memset (iter, 0, sizeof (iter));
		int f;
		while ((f = dfs (s, t, INF)) > 0){
			flow += f;
		} // end while
	} // end for

	return INF;
}

const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = { 0, 1, 0,-1};

char  b[110][110];
int  in[110][110];
int out[110][110];

int main()
{
	memset (b, 0, sizeof(b));
	memset (in, 0, sizeof(in));
	memset (out, 0, sizeof(out));

	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int H, W; cin >> H >> W;
	for (int i = 1; i <= H; ++i){
		for (int j = 1; j <= W; ++j){
			cin >> b[i][j];
		} // end for
	} // end for

	int cnt = 0;
	for (int i = 0; i <= H + 1; ++i){
		for (int j = 0; j <= W + 1; ++j){
			in[i][j]  = cnt++;
			out[i][j] = cnt++;
		} // end for
	} // end for

	int S = cnt++, T = cnt++;
	for (int r = 0; r <= H + 1; ++r){
		for (int c = 0; c <= W + 1; ++c){
			if (b[r][c] == 0){ // 範囲の外
				add_edge(out[r][c], T, INF);
				add_edge(in[r][c], out[r][c], INF);
			}else
			if (b[r][c] == 'X'){
				add_edge(S, in[r][c], INF);
				add_edge(in[r][c], out[r][c], INF);
			}else{ // if (b[i][j] == '.')
				add_edge(in[r][c], out[r][c], 1);
			} // end if
			rep (k, 4){
				int nr = r + dr[k];
				int nc = c + dc[k];
				if (0 <= nr && nr <= H + 1 && 0 <= nc && nc <= W + 1){
					add_edge(out[r][c], in[nr][nc], INF);
				} // end if
			} // end rep
		} // end for
	} // end for

	int res = max_flow(S,T);
	cout << (res >= INF ? -1 : res) << endl;

	return 0;
}

Measured memory_bytes: 3584
n, m = map(int, input().split())
visited = set()
my_dict = dict()

for i in range(m):
    a, b = map(int, input().split())
    if a in my_dict:
        my_dict[a].append(b)
    else:
        my_dict[a] = [b]
    if b in my_dict:
        my_dict[b].append(a)
    else:
        my_dict[b] = [a]

ret_dict = dict()

queue = [1]
visited.add(1)

while queue:
    item = queue.pop(0)
    if item in my_dict:
        for val in my_dict[item]:
            if val not in visited:
                visited.add(val)
                queue.append(val)
                ret_dict[val] = item

print('Yes')
for i in range(2, n+1):
    print(ret_dict[i])


Measured memory_bytes: 55672
#include<iostream>

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int N, K;
	cin >> N >> K;
	int ans = 0;
	while (N > 0) {
		ans++;
		N /= K;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define LLINF ((long long) 1e18)//1234567890987654321
#define INF 1234567890ll
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second	
#define db 0
#define EPS (1e-7)    //0.0000001 the value
#define PI (acos(-1))
#define MAXN (300006)
#define ll long long int 
#define ld long double
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
#define FOR(ii, ss, ee) for(ll ii = ss; ii < ee; ++ii)
#define space " "
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ((ll)x.size())
#define ph push
#define emp emplace
#define btinpct(x) __builtin_popcountll(x)
#define p2(x) (1LL<<(x))
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
typedef pair <ll, ll> pi;
typedef pair <ll, pi> spi;
typedef pair <pi, pi> dpi;
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss
ll n,m,p[20];
vector<vector<ll>>A;
int main()
{
	FAST
	cin>>n>>m;
	FOR(i,0,m){
		vector<ll>tmp;
		ll k;cin>>k;tmp.resize(k);
		FOR(i,0,k){cin>>tmp[i];tmp[i]--;}
		A.pb(tmp);
	}
	FOR(i,0,m){
		cin>>p[i];
	}
	ll ans=0;
	FOR(i,0,(1<<n)){
		bool no=0;
		FOR(j,0,m){
			ll co=0;
			for(auto k:A[j]){
				if((1<<k)&i){
					co++;
				}
			}
			if(co%2 != p[j]) no=1;
		}
		if(no)continue;
		ans++;
	}
	cout<<ans;
}


Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void main() {
    auto abc = readints;
    int a = abc[0], b = abc[1], c = abc[2];

    int m = max(a, b, c);
    if (m % 2 != (a + b + c) % 2) m++;

    int ans = (3 * m - (a + b + c)) / 2;
    writeln(ans);
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <ctype.h>

const int max_width = 70, max_height = 70;
const int dx[] = {-1, 0, 1, 0}, dy[] = {0, -1, 0, 1};

int width, height;

std::string matrix[max_width][max_height];
std::string memo[max_width][max_height];
std::string ans;

std::string compare(std::string s1, std::string s2);

std::string dfs(int x, int y);

void solve();

int main(){
    while(true){
        ans = -1;
        for(int i = 0; i < max_width; ++i){
            for(int j = 0; j < max_height; ++j)
                memo[i][j] = "A";
        }
        std::cin >> height >> width;
        if(width + height == 0) break;
        for (int i = 0; i < width; ++i){
            for(int j = 0; j < height; ++j){
                char in;
                std::cin >> in;
                matrix[i][j] = in;
            }
        }
        solve();
    } 
    return 0;
}

void solve(){
    for(int i = 0; i < width; ++i){
        for(int j = 0; j < height; ++j){
            if(!isdigit(matrix[i][j][0]) || matrix[i][j] == "0") continue;
            ans = compare(dfs(i, j), ans);
        }
    }
    std::cout << ans << std::endl;
    return;
}

std::string dfs(int x, int y){
    if(memo[x][y] != "A") return memo[x][y];
    std::string res = "";
    for(int i = 2; i < 4; ++i){
        int nx = x + dx[i], ny = y + dy[i];
        if(nx < 0 || nx >= width || ny < 0 || ny >= height) continue;
        if(!isdigit(matrix[nx][ny][0])) continue;
        res = compare(dfs(nx, ny), res);
    }
    return memo[x][y] = matrix[x][y] + res;
}

std::string compare(std::string s1, std::string s2){
    if(s1.length() == s2.length()){
        for(int i = 0; i < s1.length(); ++i){
            if(s1[i] != s2[i])
                return s1[i] > s2[i] ? s1 : s2;
        }
    }
    else if(s1.length() > s2.length()) return s1;
    return s2;
}

Measured memory_bytes: 3564