akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long
using namespace std;
int mod1,mod2;

int n,tot=0,pos1=1,pos2=1,tot1=0,tot2=0;
int a[200005];

inline int Popcount(int x)
{
	if (x==0)  return 0;
	
	int step=0;
	while (x!=0)
	{
		int cnt=0,k=x;
		while (k!=0)
		{
			if (k%2==1)  cnt++;
			k/=2;
		}
		if (cnt!=0)  x%=cnt;
		else x=0;
		
		step++;
	}
	return step;
}

int quick_power1(int x,int y)
{
	int res=1;
	for (;y;y=y>>1,x=(x*x)%mod1)
	{
		if (y&1)  res=(res*x)%mod1;
	}
	return res;
}

int quick_power2(int x,int y)
{
	int res=1;
	for (;y;y=y>>1,x=(x*x)%mod2)
	{
		if (y&1)  res=(res*x)%mod2;
	}
	return res;
}

signed main()
{
	cin>>n;
	for (int i=1;i<=n;i++)
	{
		char x;
		cin>>x;
		a[i]=x-'0';
	}
	for (int i=1;i<=n;i++)
	{
		if (a[i]==1)  tot++;
	}
	int flag=1;
	for (int i=1;i<=n;i++)
	{
		if (a[i]!=0)
		{
			flag=0;
			break;
		}
	}
	if (flag==1)
	{
		for (int i=1;i<=n;i++)  cout<<1<<endl;
		return 0;
	}
	mod1=tot-1;
	mod2=tot+1;
	
	for (int i=n;i>=1;i--)
	{
		if (mod1!=0)  tot1=(tot1+a[i]*pos1)%mod1,pos1=(pos1*2)%mod1;
		if (mod2!=0)  tot2=(tot2+a[i]*pos2)%mod2,pos2=(pos2*2)%mod2;
	}
	for (int i=1;i<=n;i++)
	{
		if (a[i]==0)//调用的是:1的个数多1，即mod2的情况
		{
			int now;
			if (mod2>0)
			{
				now=(tot2+quick_power2(2,n-i))%mod2;
				cout<<Popcount(now)+1<<endl;
			}
			else cout<<0<<endl;
			//cout<<1<<' '<<now<<endl;
		}
		else
		{
			int now;
			
			if (mod1>0)
			{
				now=((tot1-quick_power1(2,n-i))%mod1+mod1)%mod1;
				cout<<Popcount(now)+1<<endl;
			}
			else cout<<0<<endl;
		}
	}
	return 0;
}

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

using namespace std;

const string words[4] = {
    "dream", "dreamer", "erase", "eraser"
};
const int n[4] = {
    5, 7, 5, 6
};

int main() {
    string s;
    cin >> s;
    int end = s.length();
    bool yes = true;
    while(end > 1) {
        yes = false;
        for(int i=0;i<4;++i) {
            bool ok = true;
            for(int j=0;j<n[i];++j) {
                if(end-1-j < 0 || s[end-1-j] != words[i][n[i]-1-j]) {
                    ok = false;
                    break;
                }
            }
            if(ok) {
                end -= n[i];
                yes = true;
            }
        }
        if(!yes) break;
    }

    cout << (yes?"YES":"NO") << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long;
using P = pair<int, int>;

const int INF = 1001001001;
const vector<int> di = {-1,  0, 1, 0};
const vector<int> dj = { 0, -1, 0, 1};

void chmin(int &a, int b) { if (a > b) a = b; }

ll GCD(ll a, ll b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
ll LCM(ll a, ll b) { return a * b / GCD(a, b); }


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

    vector<int> p(N);
    rep(i, N) cin >> p.at(i), ++p.at(i);

    vector<ll> s(N+1, 0);
    for (int i=0;i<=N;++i) {
        s[i+1] = s[i] + p[i];
    }
    ll res = 0;
    for (int i=0;i<=N-K;++i) {
        res = max(res, s[i+K] - s[i]);
    }

    cout << fixed << setprecision(10) << (double)(res)/2 << endl;
}

Measured memory_bytes: 2560
#include <iostream>
#include <cmath>

int main()
{
    double a, b, c, C;


    std::cin >> a >> b >> C;

    double S, L, h;


    S = a * b / 2.0 * std::sin(C/ 180* 3.1415926535897932);
    c = sqrt((a*a)+(b*b) - 2 * a * b * std::cos(C/180*3.14159265358979));
    L = a + b + c;
    h = S * 2 / a;



    std::printf("%lf\n",S);
    std::printf("%lf\n",L);
    std::printf("%lf\n",h);

    return 0;

}

Measured memory_bytes: 3516
text=input()
K=int(input())
N=len(text)
dic={}
for i in range(N):
  dic[text[i:i+5]]=1
ls=list(dic)
ls.sort()
dic2={}
for e in ls[0:K]:
  for i in range(len(e)):
    dic2[e[0:i+1]]=1
ls2=list(dic2)
ls2.sort()
print(ls2[K-1])

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<P> ans;
  if (n%2) {
    for (int l = 1, r = n-1; l < r; l++, r--) {
      ans.emplace_back(l,r);
    }
  } else {
    bool flag = false;
    for (int l = 1, r = n-1; l < r; l++, r--) {
      if (!flag && r-l <= n/2) {
        --r;
        flag = true;
      }
      ans.emplace_back(l,r);
    }
  }
  rep(i,m) {
    printf("%d %d\n", ans[i].first, ans[i].second);
  }
  return 0;
}


Measured memory_bytes: 4184
N = int(input())
nums = list(map(int,input().split()))
ans = []
for _ in range(N):
    ma = -1
    ma_ind = -1
    l = len(nums)

    for i in range(l):
        if nums[i] == i + 1:
            ma_ind = i
    if ma_ind == -1:
        print(-1)
        exit(0)
    temp = nums.pop(ma_ind)
    ans.append(temp)
ans.reverse()
print("\n".join(map(str,ans)))

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

#define MOD 1000000007

#define int long long

int n;
vector<int> graph[200010];

int dp1[200010];
int dp2[200010];


int zi[200010];

int pow_mod(int i, int j){
    int ans = 1;
    while(j > 0){
        if(j & 1) ans = (ans * i) % MOD;
        i = (i*i) % MOD;
        j >>= 1;
    }

    return ans;
}


void dp(int idx, int par){
    int ans = 1;
    int ans2 = zi[n-1];

    for(int i = 0;i < graph[idx].size();i++){
        int child = graph[idx][i];
        if(child == par) continue;

        dp(child, idx);

        ans += dp1[child];
        ans2 -= (MOD+zi[dp1[child]]-1)%MOD;
        if(ans2 < 0) ans2 = MOD+ans2;
    }

    dp1[idx] = ans;
    ans2 -= zi[n-ans];
    if(ans2 < 0) ans2 = MOD+ans2;

    dp2[idx] = ans2;
    return;
}

signed main(){
    cin >> n;

    for(int i = 0;i < n-1;i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    zi[0] = 1;
    for(int i = 1;i < 200010;i++){
        zi[i] = zi[i-1] * 2 % MOD;
    }

    dp(0, -1);

    int ans = 0;
    for(int i = 0;i < n;i++){
        ans += dp2[i];
        ans %= MOD;
    }

    cout << ans * pow_mod(zi[n], MOD-2) % MOD << endl;
    return 0;
}



Measured memory_bytes: 27264
#include<iostream>
#include<cstdio>
#include<math.h>
#include<string>
#include<algorithm>
#include<functional>
#include<vector>
#include<set>
#include<map>
#define INF 999999
#define EPS 1.0e-6

using namespace std;

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

int a,b,c;

int main()
{
	cin>>a>>b>>c;
	if(a==b)cout<<c<<endl;
	else if(b==c)cout<<a<<endl;
	else if(a==c)cout<<b<<endl;

	return 0;
}

Measured memory_bytes: 256
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let (A, B) = read!(i64, i64);

    let u = max((A * 100 + 7) / 8, B * 100 / 10);
    let v = min(((A + 1) * 100 + 7) / 8, (B + 1) * 100 / 10) - 1;

    if u <= v {
        println!("{}", u)
    } else {
        println!("-1")
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
 
using namespace std;
int main() {
  int N,A,B;
  int keep,sum = 0;
  int i,y;
  cin >> N >> A >> B;
  for (i = 0; i <= N; i++) {
    keep = 0;
    y = i;
    while(y > 0){
      keep += (y % 10);
      y = y / 10;
    }
    if (A <= keep){
      if(keep <= B){
        sum += i; 
      }
    }
  }
  cout << sum;
}

Measured memory_bytes: 3596
#define LOCAL
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rrep(i, n) for(int i=(n-1); i>=0; --i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define memr(dp, val) memset(dp, val, sizeof(dp))
using namespace std;
typedef long long ll;
static const int INTINF = (INT_MAX >> 1); // 10^9 + 10^7
static const ll LLINF = (LLONG_MAX >> 1);
static const int MAX = 1e5+1;
static const ll MOD = 1e9+7;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
string to_string(string s) { return '"' + s + '"'; }
string to_string(bool b) { return b ? "true" : "false"; }
template <size_t N> string to_string(bitset<N> bs) {
  string res;
  for (size_t i = 0; i < N; ++i) res += '0' + bs[i];
  return res;
}
string to_string(vector<bool> v) {
  string res = "{";
  for (bool e : v) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p);
template <class C> string to_string(C c) {
  string res = "{";
  for (auto e : c) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
void debug() { cerr << '\n'; }
template <class Head, class... Tail> void debug(Head head, Tail... tail) {
  cerr << '\t' << to_string(head), debug(tail...);
}
#ifdef LOCAL
#define DEBUG(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

ll N, M, R;
vector<ll> r;
vector<ll> g[300];
ll dist[300][300];

ll dp[1 << 8];

// s -> all, v -> now
ll bitdfs(ll s, ll v){
	if(dp[s] >= 0) return dp[s];

	if(s == (1 << R) -1){
		return dp[s] = 0;
	}

	ll res = LLINF;
	rep(i, r.size()){
		ll u = r[i];
		if(!(s >> i & 1)) {
			res = min(bitdfs(s | 1 << i, u) + dist[v][u], res);
		}
	}

	return dp[s] = res;
}

int main(int argc, const char * argv[]) {
	std::cout << std::fixed << std::setprecision(15);

	cin >> N >> M >> R;
	r.resize(R);
	rep(i, R) {
		ll a; cin >> a;
		a--;
		r[i] = a;
	}

	rep(i, 300){
		fill(dist[i], dist[i]+300, LLINF);
	}
	rep(i, 300){
		dist[i][i] = 0;
	}


	rep(i, M){
		ll a, b, c; cin >> a >> b >> c;
		a--; b--;
		g[a].push_back(c);
		g[b].push_back(c);
		dist[a][b] = c;
		dist[b][a] = c;
	}

	rep(k, N){
		rep(i, N){
			rep(j, N){
				dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
			}
		}
	}


	ll ans = LLINF;
	sort(ALL(r));
	do{
		ll res = 0;
		rep(i, r.size()-1){
			res += dist[r[i]][r[i+1]];
		}
		ans = min(res, ans);
	} while(next_permutation(ALL(r)));


	cout << ans << endl;

	return 0;
}


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

int main (void) {
    long long i;
    long long n_answerer, first_points, n_right;
    scanf("%lld%lld%lld", &n_answerer, &first_points, &n_right);

    long long each_right[n_answerer];
    memset(each_right, 0, sizeof(long long)*n_answerer);

    long long idx;
    for ( i=0; i<n_right; i++ ) {
        scanf("%lld", &idx);
        assert(idx <= n_answerer);
        each_right[idx-1]++;
    }

    for ( i=0; i<n_answerer; i++ ) {
        /* compare first points and number of right answer by other answerer */
        if ( first_points > (n_right - each_right[i]) )
            printf("Yes\n");
        else
            printf("No\n");
    }

    return EXIT_SUCCESS;
}


Measured memory_bytes: 1280
import sys
import copy

def main():
	input = sys.stdin.readline

	N, M = list(map(int,input().split()))
	st = [list(map(int,input().split())) for i in range(M)]

	neighbor = [[] for i in range(N)]
	for s,t in st:
		neighbor[s-1].append(t-1)

	INF = 100100100
	ev = [INF]*N
	ev[N-1] = 0
	for i in range(N-2,-1,-1):
		dsum = 0
		dcount = 0
		for j in neighbor[i]:
			dsum += ev[j]
			dcount += 1
		ev[i] = dsum/dcount + 1

	ans = ev[0]
	for i in range(N-1):
		evmax = -1
		if len(neighbor[i])==1: continue
		for j in neighbor[i]:
			if ev[j]>evmax:
				tn = j
				evmax = ev[j]

		# ntmp = copy.deepcopy(neighbor)
		# ntmp[i].remove(tn)
		evtmp = [INF]*N
		evtmp[i+1::] = ev[i+1::]
		for ii in range(i,-1,-1):
			dsum = 0
			dcount = 0
			for jj in neighbor[ii]:
				if ii==i and jj==tn: continue
				dsum += evtmp[jj]
				dcount += 1
			evtmp[ii] = dsum/dcount + 1

		if evtmp[0]<ans:
			ans = evtmp[0]

	print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 79084
// https://atcoder.jp/contests/abc159/tasks/abc159_a

#include <iostream>
#include <vector>

using namespace std;

int nC2(int n) {
    if (n == 1) return 0;
    return (n * (n-1) / 2);
}

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

    int N, M;
    cin >> N >> M;

    int ans = nC2(N) + nC2(M);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
ll f(ll n){
    if (n == 1) return 1;
    ll x = f(n/2);
    return 1+2*x;
}

int main(){
    ll n;
    scanf("%lld",&n);
    printf("%lld",f(n));


}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<set>
#include<ctime>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;
inline void write(long long a){
	if(a>=10)write(a/10);
	putchar('0'+a%10);
}
inline void writeln(long long a){
	write(a); puts("");
}
inline long long read()//不管是正负数，都可以 
{
	long long x = 0; char ch = getchar(); bool positive = 1;
	for (; !isdigit(ch); ch = getchar())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = getchar())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
char ch[205];
int flag;
int main(){
	scanf("%s",&ch); int len=strlen(ch);
	for(int i=(len&1)?len-2:len-3;i>=0;i-=2){flag=1;
		for(int j=0;j<=i/2;j++){
			if(ch[j]!=ch[(i+1)/2+j]){
				flag=0; break;
			}
		}
		if(flag){
			cout<<i+1<<endl; return 0;
		}
	}
}

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

using namespace std;

int main() {
    int n;
    cin >> n;
    switch (n % 10) {
    case 2:
    case 4:
    case 5:
    case 7:
    case 9:
        cout << "hon" << endl;
        break;
    case 0:
    case 1:
    case 6:
    case 8:
        cout << "pon" << endl;
        break;
    default:
        cout << "bon" << endl;
        break;
    }
    return 0;
}


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

int main() {
  ll x,ans;
  cin >> x;
  ans = (x/11)*2;
  if(x%11 != 0){
    if(x%11 < 7) ans++;
    else ans += 2;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n, m;
    while(cin >> n >> m, n){
        vector<int> v(m);
        for (int i = 0; i < n; ++i) {
            int d, x;
            cin >> d >> x;
            v[d-1] = max(v[d-1], x);
        }
        cout << accumulate(v.begin(),v.end(), 0) << "\n";
    }
    return 0;
}


Measured memory_bytes: 3088
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
x,k,d  =ma()
if abs(x) > k*d:
    ans = abs(x)-k*d
else:
    if x<0:
        x*=-1
    t1 = x%d
    t2 = abs(x%d-d)
    pal = (x-t1)//d
    if pal%2==k%2:
        ans = t1
    else:
        ans=t2
print(ans)


Measured memory_bytes: 9368
//0;35
#include <string.h>
#include <stdio.h>
#include <algorithm>
int A[100000];
int main(){
        int N;
        scanf("%d",&N);
        int a;
        for(int i = 0; i < N; i++){
                scanf("%d", A+i);
        }

        std::sort(A,A+N);

        int ledge=0,sedge=0;
        int l = N-1;
        char first = 1;
        while(l > 0){
                if(A[l] == A[l-1]){
                        if(first){
                                ledge = A[l];
                                first = 0;
                        }else{
                                sedge = A[l];
                                break;
                        }
                        l--;
                }
                l--;
        }
        printf("%lld\n",(long long)ledge*(long long)sedge);
}

Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<vector>
#include<utility>

using namespace std;

int main(){

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

	float ave = 0;
	for(int i=0;i<n;i++)ave+=a[i];
	ave/=n;
	int ave2 = round(ave);
	int ans2 = 0;
	for(int i=0;i<n;i++){
		ans2+=(a[i]-ave2)*(a[i]-ave2);
	}


	cout<<ans2;

	cout<<endl;

	return 0;
}


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

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;

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

const ll mod = (ll)1e9 + 7;
const ll mxN = 200200;




int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(20);
	cout << fixed;

	string s;

	cin>>s;
	set<char> S;
	for(auto i: s) S.insert(i);
	puts(S.size()==s.length()?"yes":"no");

}


Measured memory_bytes: 256
#include<cstdio>
#include<queue>
using namespace std;

static const int MAX_N = 100;
static const int INFTY = (1<<21);

int n, adj[MAX_N][MAX_N];
int d[MAX_N];

void dfs(int s){
	queue<int> q;
	q.push(s);
	for(int i = 0; i < n; i++){
		d[i] = INFTY;
	}
	d[s] = 0;
	int u;
	while(!q.empty()){
		u = q.front(); q.pop();
		for(int v = 0; v < n; v++){
			if(adj[u][v] == 0) continue;
			if(d[v] != INFTY) continue;
			d[v] = d[u] + 1;
			q.push(v);
		}
	}
	for(int i = 0; i < n; i++){
		printf("%d %d\n", i + 1, ((d[i] == INFTY) ? (-1) : d[i]));
	}
}

int main(void){
	int u, k, v;
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		scanf("%d", &u);
		u--;
		scanf("%d", &k);
		for(int j = 0; j < k; j++){
			scanf("%d", &v);
			v--;
			adj[u][v] = 1;
		}
	}

	dfs(0);
	return 0;
}

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

using namespace std;


int main() {
	int w, a, b;
	cin >> w >> a >> b;
	int mx, mn; 
	mx = max(a, b);
	mn = min(a, b);
	if(mx-(mn+w) <= 0)
		cout << 0;
	else 
		cout << mx-(mn+w);
	return 0;
}


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

int main(){
    string s;
    cin >> s;
    for(int i = 0;i<s.size();i++){
        if(i % 2 == 0 && s[i] == 'L' || i % 2 == 1 && s[i] == 'R'){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

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

#define N 3030

int n, L, t[N];

const double ep = 1e-8;
const double pi = 3.14159265358979323846264338327950288L;
struct pnt {
    double x, y;
    pnt(double x = 0, double y = 0) : x(x), y(y) {}
    pnt operator + (const pnt &b) {
        return pnt(x + b.x, y + b.y);
    }
    pnt operator - (const pnt &b) {
        return pnt(x - b.x, y - b.y);
    }
    pnt operator * (const double &b) {
        return pnt(x * b, y * b);
    }
    pnt operator / (const double &b) {
        return pnt(x / b, y / b);
    }
    double operator & (const pnt &b) {
        return x * b.x + y * b.y;
    }
    double operator ^ (const pnt &b) {
        return x * b.y - b.x * y;
    }
    bool operator < (const pnt &b) const {
        return abs(x - b.x) > ep ? x < b.x : y < b.y;
    }
    bool operator == (const pnt &b) {
        return abs(x - b.x) < ep && abs(y - b.y) < ep;
    }
    bool operator != (const pnt &b) {
        return abs(x - b.x) > ep || abs(y - b.y) > ep;
    }
} p[N];

pnt circle(double d) {
    return pnt(cos(2 * pi * d / L), sin(2 * pi * d / L));
}


int main() {
    scanf("%d %d", &n, &L);
    for (int i = 1; i <= n; i ++) scanf("%d", &t[i]);
    pnt O;
    for (int i = 1; i <= n; i ++) {
        pnt cur, p = circle(t[i]);
        for (int j = 1; j < i; j ++) {
            pnt pt = circle(0.5 * (t[i] + t[j]));
            double R = 2 * sin(0.5 * (t[i] - t[j]) * pi / L);
            pnt q = (p - pt) / R;
            pt = pt * (j - 1) + pnt(cur & q, cur ^ q) * R;
            O = O + pt;
            cur = cur + circle(0.5 * (t[i] - t[j] + L));
        }
    }
    O = O / (1ll * n * (n - 1) * (n - 2) / 6);
    printf("%.12lf %.12lf\n", O.x, O.y);
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
 int n;
 cin >> n;
 for (int i= 1; i <= n; ++i)
 {
  if ( i % 3 == 0 ) cout << " " << i;
  else
  {
	  for(int x = i; x > 0; x/=10)
	  {
		  if ( x % 10 == 3 ){ cout << " " << i; break;}		  
	  }
  }
 }
 cout << endl;
 return 0;
}

Measured memory_bytes: 3100
#!/usr/bin/python
i = input()
n = map(int, raw_input().split())
cnt=0

for i in xrange(len(n)):
    for j in xrange(len(n)-1, i, -1):
        if n[j] < n[j-1]:
            n[j], n[j-1] = n[j-1], n[j]
            cnt+=1
print ' '.join(map(str,n))
print cnt

Measured memory_bytes: 4220
#include<stdio.h>
#include<algorithm>
using namespace std;
long long pow10[13];
int get(long long a){
	a--;
	int at=0;
	while(a>=pow10[at]*9*(at+1)){
		a-=pow10[at]*9*(at+1);
		at++;
	}
	int p=a/(at+1);
	int num=pow10[at]+p;
	//printf("(%d)",num);
	return num%pow10[at-a%(at+1)+1]/pow10[at-a%(at+1)];
}
int main(){
	int a,b;
	pow10[0]=1;
	for(int i=1;i<13;i++)pow10[i]=pow10[i-1]*10;
	while(scanf("%d%d",&a,&b),a){
		for(int i=0;i<b;i++)printf("%d",get(a+i));
		printf("\n");
	}
}

Measured memory_bytes: 1032
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int N;
    vector<int> A[1000];
    cin >> N;
    for(int i=0; i<N; i++){
        for(int j=0; j<N-1; j++){
            int a;
            cin >> a;
            a--;
            A[i].push_back(a);
        }
        reverse(A[i].begin(), A[i].end());
    }
 
    vector<int> day(N, 1e9);
    queue<vector<int>> que;
    for(int i=0; i<N; i++){
        int j = A[i].back();
        if(j > i && A[j].back() == i) que.push({i, j, 1});
    }
    while(que.size()){
        auto v = que.front(); que.pop();
        int i = v[0], j = v[1], d = v[2];
        for(int v : {i, j}){
            A[v].pop_back();
            if(A[v].size()){
                int x = A[v].back();
                if(A[x].back() == v){
                    que.push({x, v, d+1});
                }
            }else{
                day[v] = d;
            }
        }
    }
    int ans = *max_element(day.begin(), day.end());
    cout << (ans == 1e9 ? -1 : ans) << endl;
    return 0;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N,M;
vint G[111111];
bool used[111111];

signed main(){
    cin>>N>>M;
    rep(i,M){
        int a,b;
        cin>>a>>b;
        a--;b--;
        G[a].pb(b);G[b].pb(a);
    }

    int a=0,b=0;
    deque<int>P={0};
    used[0]=1;
    while(true){
        bool f=false;
        for(auto u:G[a]){
            if(used[u])continue;
            a=u;
            used[u]=true;
            f=true;
            P.pb(u);
            break;
        }
        if(!f)break;
    }

    while(true){
        bool f=false;
        for(auto u:G[b]){
            if(used[u])continue;
            b=u;
            used[u]=true;
            f=true;
            P.push_front(u);
            break;
        }
        if(!f)break;
    }

    cout<<P.size()<<endl;
    rep(i,P.size()){
        if(i)cout<<" ";
        cout<<P[i]+1;
    }cout<<endl;
    return 0;

}


Measured memory_bytes: 7424
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <map>
#include <vector>
#include <stack>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;++i)
#define mod 1000000007

ll n;

ll ran[100100],p[100100];

void makeset(ll x){
  p[x]=x;
  ran[x]=0;
}

ll findset(ll x){
  if(x!=p[x])p[x]=findset(p[x]);
  return p[x];
}

ll size[100100]={0};

void unite(ll x,ll y){
  x=findset(x);
  y=findset(y);
  if(x==y)return;
  if(ran[x]>ran[y]){
    p[y]=x;
    size[x]+=size[y];
  }else{
    p[x]=y;
    if(ran[x]==ran[y])ran[y]++;
    size[y]+=size[x];
  }
}

int main(){
  ll m;
  cin >> n >> m;
  ll res=n*(n-1)/2;
  rep(i,n+1){
    if(i>0){
      makeset(i);
      size[i]=1ll;
    }
  }
  ll ans[100100]={0};
  ll a,b;
  ll reva[100100],revb[100100];
  rep(i,m){
    cin >> a >> b;
    reva[m-1-i]=a;
    revb[m-1-i]=b;
  }
  rep(i,m){
    ans[m-i-1]=res;
    if(findset(reva[i])!=findset(revb[i])){
      res-=(ll)size[findset(reva[i])]*size[findset(revb[i])];
    }
    unite(reva[i],revb[i]);
  }
  rep(i,m)cout << ans[i] << endl;
}


Measured memory_bytes: 6016
import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }




void main() {
  try {
    for (; ; ) {
      const N = readInt();
      writeln(180 * (N - 2));
    }
  } catch (EOFException e) {
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/









int N; 
ll A[101010], B[101010];
ll C[101010];
int vis[101010];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;
    rep(i, 0, N) cin >> A[i];
    rep(i, 0, N) cin >> B[i];
 
    ll smA = 0;
    rep(i, 0, N) smA += A[i];
 
    int ans = 0;
    rep(i, 0, N) C[i] = B[i];
    
    ll smB = 0;
    rep(i, 0, N) smB += B[i];
 
    if (smA < smB) {
        printf("-1\n");
        return;
    }
 
    ll d = smA - smB;
    vector<pair<int,int>> up;
    int ng = 0;
    int same = 0;
    rep(i, 0, N) {
        if (A[i] < B[i]) ng++;
        else if (B[i] < A[i]) up.push_back({ A[i] - B[i],i });
        else same++;
    }
 
    sort(all(up));
    int upuse = 0;
    fore(p, up) {
        if (p.first <= d) {
            d -= p.first;
            C[p.second] = A[p.second];
            upuse++;
        }
    }
 
    rep(i, 0, N) if (A[i] != C[i]) ans++;
    if (d) {
        if (ng == 0 and upuse == up.size()) ans++;
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 3196
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>

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

using namespace std;
int mod = 1000000007;

int N;

int main() {
  cin >> N;
  cout << ((N%2 == 0) ? N : (ll)N*2) << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define pb push_back
#define fr first
#define se second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

mt19937 rng (chrono::steady_clock::now().time_since_epoch().count() );

const int MOD = 1e9 + 7;
const ll INF = 1e18;
const int MX = 3e5 + 12; //check the limits, dummy

int main()
{

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

    ll n;
    cin >> n;
    string s, t;
    cin >> s >> t;

    string ans = "";
    FOR (i, 0, n) {
        ans += s[i];
        ans += t[i];
    }

    cout << ans << '\n';
    return  0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define mt make_tuple
#define pb push_back
const int N = 1e5 + 10;

int main(){
    int n,heights[N],dp[N];
    cin>>n;
    for(int i=1;i<=n;i++)    cin>>heights[i];
    dp[1] = 0;
    dp[2] = abs(heights[2]-heights[1]);
    for(int i=3;i<=n;i++){
        dp[i] = min(dp[i-1] + abs(heights[i] - heights[i-1]), dp[i-2] + abs(heights[i] - heights[i-2]));
    }
    cout<<dp[n]<<endl;
    return 0;
}

Measured memory_bytes: 1024
N,x = map(int,input().split())
a = list(map(int,input().split()))

a = sorted(a, reverse = False)

count = 0
if sum(a) < x:
    count = N -1
else:
    for i in a:
        x -= i
        if x < 0:
            break
        elif x == 0:
            count += 1
            break
        elif x > 0:
            count+=1

print(count)

Measured memory_bytes: 9052
#include <iostream>
#include<vector>
#include<algorithm>
#include <queue>
#include <string>
#include <set>
using namespace std;
#define ff(i,n,m) for(int i=n;i<m;i++)
#define i64 int64_t

int main() {
	i64 a, b, x;
	cin >>a >> b >> x;
	i64 ans=0;
	i64 a1 = a % x;
	if (a1 == 0) {
		ans++;
	}
	i64 b1 = b % x;
	a -= a1;
	
	b -= b1;
	ans += (b - a) / x;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int const N = 2e5 + 5;
int n;
ll arr[N], dp[N][3];
int lst;
ll solve(int idx, int state) {
    if (idx >= n)
        return 0;
    ll &ret = dp[idx][state];
    if (ret != -1)
        return ret;
    ret = -1e18;
    if (state < 2)
        ret = solve(idx + 1, state + 1);
    if (idx != n - 1 || state)
        ret = max(ret, arr[idx] + solve(idx + 2, state));
    return ret;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> arr[i];
    }
    memset(dp, -1, sizeof dp);
    if (n % 2 == 1)
        cout << solve(0, 0);
    else
        cout << solve(0, 1);
    return  0;
}

Measured memory_bytes: 17696
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>


#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979
#define MAXI 7500000

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;

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


int main(void) {
	long long int n, m;
	long long int maxi = 1;

	cin >> n >> m;

	maxi = m / n;

	if (m%n == 0) {
		cout << maxi << endl;
	}
	else {
		LRFOR(i, maxi, 1) {
			if (m%i == 0) {
				cout << i << endl;
				break;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<string>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#include <iomanip>
#include<set>
#include <numeric>
#pragma region Macros
#define int long long
#define double long double
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define LAST(x) x[x.size()-1]
#define ALL(x) (x).begin(),(x).end()
#define swap(a,b) (a += b,b = a - b,a -= b)
#define DIVCEIL(a,b) ((a+b-1)/b)
//int CHMAX

int FACT(int a) {
	if (a == 0)
		return 1;
	else
		return a * FACT(a - 1);
}
int MODFACT(int a, int mod) {
	if (a == 0)
		return 1;
	else
		return (a * FACT(a - 1))%mod;
}
int nPr(int n, int r) {
	int s = n - r + 1;
	int sum = 1;
	for (int i = s; i <= n; i++)
		sum *= i;
	return sum;
}
int MODnPr(int n, int r, int mod) {
	int s = n - r + 1;
	int sum = 1;
	for (int i = s; i <= n; i++) {
		sum *= i;
		sum = sum % MOD;
	}
	return sum;
}
//int nCr(int n, int r)
int nCr2(int n, int r) {
	return FACT(n) / (FACT(r) * FACT(n - r));
}
int GCD(int a, int b)
{
	if (a < b)
		swap(a, b);
	if (b == 0)
		return a;
	if (a % b == 0)
		return b;
	return GCD(b, a % b);
}
int LCM(int a, int b)
{
	return  a * b / GCD(a, b);
}
int NUMOFDIV(int n) {
	//約数の数（だっけ？）
	int ans = 0;
	REP(i, n) {
		if (n % i == 0)
			ans++;
	}
	return ans;
}
int CEIL1(int n) {
	//1桁目切り上げ
	return (n + 9) / 10 * 10;
}
int DIGIT(int n,int k) {
	//nのk桁目
	rep(i, k-1)
		n /= 10;
	return n % 10;
}
int DIGITSUM(int n) {
	int sum = 0, dig;
	while (n) {
		dig = n % 10;
		sum += dig;
		n /= 10;
	}
	return sum;
}
int DIVTIME(int n, int k) {
	//nをkで何回割れるか的な
	int div = 0;
	while (n % k == 0) {
		div++;
		n /= k;
	}
	return div;
}
int MODPOW(int a, int n, int mod) {
	// a^n mod
	int ans = 1;
	while (n > 0) {
		if (n & 1)
			ans = ans * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return ans;
}
double LOG(int a, int b) {
	return log(b) / log(a);
}
inline bool BETWEEN(int x, int min, int max) {
	if (min <= x && x <= max)
		return true;
	else
		return false;
}
inline bool between(int x, int min, int max) {
	if (min < x && x < max)
		return true;
	else
		return false;
}
inline bool PRIMEOR(int x) {
	if (x == 1)
		return false;
	if (x == 2)
		return true;
	if (x % 2 == 0)
		return false;
	double sqrtx = sqrt(x);
	for (int i = 3; i <= sqrtx; i += 2) {
		if (x % i == 0)
			return false;
	}
	return true;
}
bool SQRTOR(int n) {
	if (sqrt(n) == (int)sqrt(n))
		return true;
	else
		return false;
}
// 順位付け
using namespace std;
#pragma endregion
signed main() {
	int N, M, X,st=0,go=0,x;
	cin >> N >> M >> X;
	rep(i, M) {
		cin >> x;
		if (x < X)
			st++;
		else
			go++;
	}
	cout << min(st, go) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 100100
using namespace std;
typedef long long LL;
int prime[2200],len;
int n,m,ans;
LL l[N],r[N];
map<LL,int> ma;
int main(){
	for(int i=2;i<2200;i++){
		int fla=1;
		for(int j=2;j<i;j++)
			if(i%j==0) fla=0;
		if(fla) prime[len++]=i;
	}
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		long long a,els=1,f=1;
		scanf("%lld",&a);
		for(int j=0;j<len;j++){
			int t=0;
			while(a%prime[j]==0) a/=prime[j],t++;
			t%=3;
			if(t){
				for(int i=t;i<3;i++){
					els*=prime[j];
					if(els>1e10) els=0;
				}
				while(t) f*=prime[j],t--;
			}
		}
		ma[f*a]++;
		l[i]=f*a,r[i]=els;
		long long w=(LL)sqrt(a);
		if(w*w!=a){
			if(a*r[i]<=1e10) r[i]*=a;
			else r[i]=0;
			if(a*r[i]<=1e10) r[i]*=a;
			else r[i]=0;
		}
		else{
			if(r[i]*w<=1e10) r[i]*=w;
			else r[i]=0;
		}
	}
	for(int i=0;i<n;i++){
		if(l[i]==1) continue;
		ans+=max(ma[l[i]],ma[r[i]]);
		ma[l[i]]=ma[r[i]]=0;
	}
	ans+=(ma[1]>0);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 12032
while 1:
    n=int(raw_input())
    if n==0:
        break
    ans=1
    for i in range(1,n+1):
        ans*=i
    ans=str(ans)[::-1]
    cnt=0
    for i in ans:
        if i=='0':
            cnt+=1
        else:
            break
    print cnt

Measured memory_bytes: 6844
#![allow(non_snake_case)]

#[allow(unused_macros)]
macro_rules! debug {
    ( $x:ident [ $i:expr ] ) => {
        if cfg!(debug_assertions) {
            println!("{}[{}] = {:?}", stringify!($x), $i, $x[$i]);
        }
    };
    ( $x:ident [ $i:expr ][ $j:expr ] ) => {
        if cfg!(debug_assertions) {
            println!("{}[{}][{}] = {:?}", stringify!($x), $i, $j, $x[$i][$j]);
        }
    };
    ( $x:expr ) => {
        if cfg!(debug_assertions) {
            println!("{}:{} {} = {:?}", line!(), column!(), stringify!($x), $x);
        }
    };
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin = my::io::InputReader::new(stdin.lock());
    
    let n: usize = stdin.read();
    let S: Vec<String> = (0..n).map(|_| stdin.read::<String>()).collect();
    let mut result = Vec::<u8>::new();
    for c in b'a'..b'z'+1 {
        let m = (0..n).map(|i| S[i].as_bytes().iter().filter(|&&x| x == c).count()).min().unwrap();
        result.append(&mut vec![c; m]);
    }
    let result = String::from_utf8(result).unwrap();
    println!("{}", result);
}

#[allow(dead_code, unused_must_use)]
mod my {
    pub mod io {
        use std::io::{BufRead, ErrorKind, Result};
        use std::str::{FromStr, from_utf8};
        use std::fmt::Debug;

        pub fn read_word<R: BufRead>(r: &mut R, buf: &mut Vec<u8>)
                                              -> Result<usize> {
            let mut read = 0;
            loop {
                let (done, used) = {
                    let available = match r.fill_buf() {
                        Ok(n) => n,
                        Err(ref e) if e.kind() == ErrorKind::Interrupted => continue,
                        Err(e) => return Err(e)
                    };
                    match available.iter().position(|&x| x == b'\n' || x == b' ') {
                        Some(i) => {
                            buf.extend_from_slice(&available[..i]);
                            (true, i + 1)
                        }
                        None => {
                            buf.extend_from_slice(available);
                            (false, available.len())
                        }
                    }
                };
                r.consume(used);
                read += used;
                if done || used == 0 {
                    return Ok(read);
                }
            }
        }

        pub struct InputReader<R: BufRead> {
            reader: R,
            buf: Vec<u8>,
        }

        impl<R: BufRead> InputReader<R> {
            pub fn new(reader: R) -> InputReader<R> {
                InputReader {
                    reader: reader,
                    buf: Vec::<u8>::new(),
                }
            }

            pub fn read_word(&mut self) {
                read_word(&mut self.reader, &mut self.buf);
            }
            
            pub fn read<T>(&mut self) -> T
                where T: FromStr,
                      T::Err: Debug
            {
                self.buf.clear();
                self.read_word();
                from_utf8(&self.buf).unwrap().trim().parse().unwrap()
            }
        }
    }
}

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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    ll x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;

    vector<ll> red(a), green(b), white(c);
    REP(i, a) cin >> red[i];
    REP(i, b) cin >> green[i];
    REP(i, c) cin >> white[i];
    
    sort(rall(red));
    sort(rall(green));
    sort(rall(white));

    priority_queue<ll, vector<ll>, greater<ll>> qr, qg;

    REP(i, x){
        qr.push(red[i]);
    }
    REP(i, y){
        qg.push(green[i]);
    }

    REP(i, c){
        ll apple = white[i];
        if(apple < qr.top() && apple < qg.top()){
            break;
        }
        if(apple - qr.top() > apple - qg.top()){
            qr.pop();
            qr.push(apple);
        }else{
            qg.pop();
            qg.push(apple);
        }
    }

    ll ans = 0;

    while(!qr.empty()){
        ans += qr.top();
        qr.pop();
    }
    while(!qg.empty()){
        ans += qg.top();
        qg.pop();
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4852
#include <stdio.h>

#define SMAX 100000
#define TMAX 50000
#define NOT_FAUND -1

int binarySearch(int*,int,int);

int main(){

  int i,n,q,S[SMAX],T[TMAX],count=0;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }

  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&T[i]);
  }

  for(i=0;i<q;i++){
    if(binarySearch(S,n,T[i])!=NOT_FAUND){
      count++;
    }
  }

  printf("%d\n",count);
  return 0;
}

int binarySearch(int* A,int n,int key){

  int right=n,left=0,mid;
  while(left<right){
    mid=(left+right)/2;
    if(key==A[mid]) return mid;
    if(key>A[mid]) left=mid+1;
    else right=mid;
  }
  return NOT_FAUND;
  
}

Measured memory_bytes: 1188
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}

	return i
}
func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	k := nextInt()
	var l int
	l = len(strconv.FormatInt((int64)(n), k))
	fmt.Println(l)
}


Measured memory_bytes: 640
f=lambda:map(int,input().split())
n,d,a=f()
lt=sorted([tuple(f()) for _ in range(n)])
from collections import *
q=deque()
c=s=0
for x,h in lt:
  while q and q[0][0]<x:
    s+=q.popleft()[1]
  h-=s
  if h<1: continue 
  t=-h//a
  c-=t
  s-=t*a
  q.append((x+d*2,t*a))
print(c)

Measured memory_bytes: 81752
#include <iostream>
using namespace std;
  char field[8+3*2][8+3*2];

void bomb(int x, int y) {
  field[x][y] = '0';
  for(int i=1;i<4;i++) {
    if(field[x+i][y] == '1') bomb(x+i,y);
    if(field[x-i][y] == '1') bomb(x-i,y);
    if(field[x][y+i] == '1') bomb(x,y+i);
    if(field[x][y-i] == '1') bomb(x,y-i);
  }
}


int main () {
  int n,firstx,firsty;
  string str;
  cin >> n;
  for(int k=0;k<n;k++) {
    for(int i=0;i<8;i++) {
      for(int j=0;j<8;j++) {
        cin >> field[3+j][3+i];
      }
    }

    cin >> firstx;
    cin >> firsty;
    bomb(firstx-1+3,firsty-1+3);
    cout << "Data " << k+1 << ":" << endl;
    for(int i=0;i<8;i++) {
      for(int j=0;j<8;j++) {
        cout << field[3+j][3+i];
      }
      cout << endl;
    }
  }
}

Measured memory_bytes: 0
n, m = map(int, input().split(" "))
(n, m) = (n, m) if n>m else (m, n)
M=1000000007

def newfact(n):
    ans=1
    for i in range(1, n+1):
        ans = (ans*i)%M
    return ans

if n > m+1:
    print(0)
elif n == m:
    print((2 * newfact(n) * newfact(m)) % M)
else:
    print((newfact(n) * newfact(m)) % M)

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


int main()
{
	int n, t=0, h=0;
	string A, H;
	cin >> n;
	for (int i = 0;i < n; i++) {
		cin >> A >> H;
		if (A == H) {
			t++;
			h++;
		}
		else if (A > H)
			t = t + 3;
		else
			h = h + 3;
	}
	cout << t <<" "<< h << endl;

    return 0;
}



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

int main() {
    long long X, K, D;
    cin >> X >> K >> D;
    long long ans = abs(X) / D;
    if (K < ans) {
        cout << abs(X) - D * K << endl;
        return 0;
    }
    long long pos = abs(X) - D * ans;
    K -= ans;
    if (K % 2 == 0) cout << pos << endl;
    else cout << abs(pos - D) << endl;
}

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

using namespace std;

int main()
{
    int t;
//    cin >> t;
    t = 1;
    while(t--) {
        char str[222];
        scanf("%s", str);
        int n = strlen(str);
        for (int i = n-2; i>=0; i-=2) {
            if (strncmp(str,str+i/2,i/2) == 0) {
                printf("%d",i);
                break;
            }
        }

    }
    return 0;
}


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

using namespace std ; 

int main () { 
	int  t ; 
	ios_base::sync_with_stdio(false);
	cin.tie(NULL) ;
	long long n , a , b ; 
	cin >> n >> a >> b; 
	if ( n <= a ){
		cout << n << endl ;
		return 0 ;
	}
	if ( n <= a + b)
		{
			cout << a << endl ; 
			return 0 ;
		}
		
	 long long sum  = 0 ; 
	 long long div = n / (a+b ); 
	sum += a * div ; 
	n = n - (a+b)*div;
	if ( n <= a ) {
		sum+= n ;
		cout << sum << endl ;
		return  0 ;  
	}
	else if ( n > a ) {
		sum += a ; 
	}
	
	cout << sum << endl ;
	
}



Measured memory_bytes: 256