#include<bits/stdc++.h>
#define inf 1e18
#define endl "\n"
#define mp make_pair
#define pb push_back
#define loop(i,x,y) for(int i = x; i < y ; i++ )
#define all(x) (x).begin(),(x).end()
#define in(n)       int n; cin>>n;
#define inarr(arr,n) vector<int>arr(n); for(int i = 0; i < n ; i++){cin>>arr[i];}
#define maploop(x) for(auto itr = x.begin(); itr != x.end();itr++)
#define int long long
using namespace std;
#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x<<" "; _print(x); cerr << endl;
#else
#define debug(x);
#endif

void _print(int t) {cerr << t;}
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(double t) {cerr << t;}

template <class T, class V> void _print(pair <T, V> p);
template <class T> void _print(vector <T> v);
template <class T> void _print(set <T> v);
template <class T, class V> void _print(map <T, V> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.first); cerr << ","; _print(p.second); cerr << "}";}
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}
/*-------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

const int N = 10001;
int mod = 1000000007;

void Main()
{
	string s;
	cin >> s;
	loop(i, 1, s.size())
	{
		cout << s[i];
	}
	cout << s[0] << endl;
}

int32_t main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int t = 1;
	//cin >> t;
	while (t--)
	{
		Main();
	}
}

#include<bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &x){
	x=0;bool f=false;char ch=getchar();
	while(!isdigit(ch)){f|=ch=='-',ch=getchar();}
	while(isdigit(ch)){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
	x=f?-x:x;
	return ;
}
template <typename T>
inline void write(T x){
	if(x<0) x=-x,putchar('-');
	if(x>9) write(x/10);
	putchar(x%10^48);
	return ;
}
const int N=2e5+25,MOD=998244353;
#define ll long long
int n,a[N],t[N],sta[N],top;
bool vis[N];
signed main(){
	read(n);
	for(int i=1;i<=n;i++) read(a[i]),t[a[i]]=i;
	for(int i=1;i<=n;i++){
		while(t[i]>i){
			if(vis[t[i]-1]){write(-1);return 0;}
			int tmp=t[i];
			t[i]=tmp-1,t[a[tmp-1]]=tmp;
			swap(a[tmp],a[tmp-1]);vis[t[i]]=true;
			sta[++top]=t[i];
		}
		while(t[i]<i){
			if(vis[t[i]]){write(-1);return 0;}
			int tmp=t[i];
			t[i]=tmp+1,t[a[tmp+1]]=tmp;
			swap(a[tmp],a[tmp+1]);vis[tmp]=true;
			sta[++top]=tmp;
		}
	}
	if(top!=n-1) write(-1);
	else{for(int i=1;i<=top;i++) write(sta[i]),putchar('\n');}
	return 0;
}


#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;
long long INF = (1LL<<62);
typedef long long LL;

LL f(LL X, LL x){
	LL u = max(X, x);
	LL v = min(X, x);
	LL r = u % v;
	if(r == 0) return v;
	return f(v, r);
}

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	LL N; cin >> N;
	vector<LL> A;
	for(int i=0; i<N; i++){ LL a; cin >> a; A.push_back(a); }
	sort(A.begin(), A.end());
	LL X = A[A.size()-1];
	LL x = A[0];

	if(N == 1){ printf("%lld\n", A[0]); return 0; }
	LL ans = A[0];
	for(int i=1; i<N; i++) ans = f(ans, A[i]);
	printf("%lld\n", ans);
	return 0;
}

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

#define ffor(i, a, b) for (int i = a ; i <= (int) b ; i++)
#define rfor(i, a, b) for (int i = (int) b ; i >= a ; i--)

#define vec vector
#define PB push_back

#define MP make_pair
#define MT make_tuple
#define F first
#define S second

using ll = long long int; // watch out for overflows in your code
using pii = pair<int,int>;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void debug() { cout << "\n"; };
template <typename T, typename... Targs>
void debug(T t, Targs... args) {
    cout << t << " ";
    debug(args...);
}

template <typename T1, typename T2>
inline ostream& operator << (ostream& os, const pair<T1,T2>& p) {
    return os << "(" << p.F << ", " << p.S << ")";
}

template <typename T>
inline ostream& operator << (ostream& os, const vec<T>& v) {
    for(auto& t : v) {
        os << t << " ";
    }
    return os;
}

template <typename T>
inline ostream& operator << (ostream& os, const vec<vec<T>>& m) {
    for(auto& v : m) {
        for(auto& t : v) {
            os << t << " ";
        }
        os << "\n";
    }
    return os;
}

template <typename T>
inline ostream& operator << (ostream& os, const set<T>& v) {
    for(auto& t : v) {
        os << t << " ";
    }
    return os;
}

template <typename K, typename V>
inline ostream& operator << (ostream& os, const map<K,V>& m) {
    for(auto& p : m) {
        os << p.F << " -> " << p.S << "\n";
    }
    return os;
}

////////////////////////////////////////////////////////////////////////
template <ll mod>
class modular_int {
    private:
    ll x;

    public:
    modular_int(ll y) : x( (y % mod + mod) % mod) {}
    modular_int() : x(0LL) {}

    ll rpr() const { return x; }

    modular_int<mod>& operator += (const modular_int<mod>& rhs) {
        x = (x + rhs.x) % mod;
        return *this;
    }

    friend modular_int<mod> operator + (modular_int<mod> lhs, const modular_int<mod>& rhs) {
        lhs += rhs;
        return lhs;
    }

    modular_int<mod>& operator *= (const modular_int<mod>& rhs) {
        x = (x * rhs.x) % mod;
        return *this;
    }

    friend modular_int<mod> operator * (modular_int<mod> lhs, const modular_int<mod>& rhs) {
        lhs *= rhs;
        return lhs;
    }

    modular_int<mod>& operator -= (const modular_int<mod>& rhs) {
        x = ((x - rhs.x) % mod + mod) % mod;
        return *this;
    }

    friend modular_int<mod> operator - (modular_int<mod> lhs, const modular_int<mod>& rhs) {
        lhs -= rhs;
        return lhs;
    }
};

const ll MOD = 1e9 + 7;
using mint = modular_int<MOD>;

////////////////////////////////////////////////////////////////////////

int N;
vec<int> A;

map<int, int> m;
void compute_m() {
    sort(A.begin()+1, A.end());
    int cur_h = A[N];
    rfor(i, 1, N) {
        int h = A[i];
        int n = N-i+1;
        if(h < cur_h) {
            m[cur_h] = n-1;
            cur_h = h;
        }
    }
    m[cur_h] = N;
}

vec<ll> g;
void compute_g() {
    auto it = m.rbegin();
    int cur_h = it->F;
    int cur_n = it->S;
    advance(it, 1);

    for(; it != m.rend(); ++it) {
        auto [h, n] = *it;
        g.PB((ll) (cur_h-h));
        cur_h = h;
    }
    g.PB((ll) cur_h);
}

////////////////////////////////////////////////////////////////////////

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

    cin >> N;
    A.assign(N+1, 0);
    ffor(i, 1, N) {
        cin >> A[i];
    }

    compute_m();
    compute_g();

    //debug(m);
    //debug(A);
    //debug(g);

    mint ans(1LL);
    for(ll x : g) {
        ans *= mint(x+1LL);
    }
    cout << ans.rpr() << "\n";
}


#include <bits/stdc++.h>

#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i, n) for(ll i=n-1;i>=0;--i)
#define rep1(i, n) for(ll i=1; i<=n; ++i)
#define repitr(itr,mp) for(auto itr=mp.begin();itr!=mp.end();++itr)
#define ALL(a) (a).begin(),(a).end()

template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}

using namespace std;
using ll  = long long;
using ld = long double;
using ull = unsigned long long;
using pll = pair<ll, ll>;

const ll MOD  = 1e9 + 7;
const ll LINF = 1LL << 60;
const int INF = 1e9 + 7;
const double PI = 3.1415926535897932384626;

ll mod(ll a, ll m){return (a + m) % m;}

int main(){
    ll a, b, c;
    cin >> a >> b >> c;

    if(a* a + b * b < c*c)cout << "Yes";
    else cout << "No";
}

#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
#define Test(tt) cout << "Case #" << tt << ": "

using namespace std;

int main() {
#ifdef HOME
    ifstream cin("A.in");
    ofstream cout("A.out");
#endif
    int i;
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    vector<int> arr(4);
    int tot = 0;
    for(i = 0; i < 4; i++) {
    	cin >> arr[i];
    	tot += arr[i];
    }

    for(int conf = 0; conf < 16; conf++) {
    	int sum = 0;
    	for(int i = 0; i < 4; i++) {
    		if(conf & (1 << i)) {
    			sum += arr[i];
    		}
    	}
    	if(sum * 2 == tot) {
    		cout << "Yes";
    		return 0;
    	}
    }

    cout << "No";

    return 0;
}


/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <bits/stdc++.h>

using namespace std;

#define ll long long

int main()
{
    ll n;
    cin>>n;

    ll a[n];
    ll b[n];
    ll c[n];

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

    for(ll i=0;i<n;i++){
        cin>>b[i];
    }

    map<ll,ll>freq;

    for(ll i=0;i<n;i++){
        cin>>c[i];
        freq[c[i]]++;
    }

    sort(a,a+n);

    ll ans=0;

    for(auto i:freq){
        ll temp=upper_bound(a,a+n,b[i.first-1])-lower_bound(a,a+n,b[i.first-1]);
        ans+=(temp*i.second);
    }

    cout<<ans<<'\n';

    return 0;
}

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

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

#define ll long long
#define INF INT_MAX
#define FIO ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
#define mod 1000000007ll
#define forn(i,n) for(int i=0;i<n;i++)
#define forab(i,a,b) for(int i=a;i<=b;i++)
#define forba(i,b,a) for(int i=b;i>=a;i--)
#define debx(x) cout << #x << ": " << x << endl
#define debxy(x,y) cout << #x << ": " << x << ' ' << #y << ": " << y << endl
#define YESp cout << "YES" << endl
#define NOp cout << "NO" << endl
#define Yesp cout << "Yes" << endl
#define Nop cout << "No" << endl
#define write(a) cout << a << endl
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int>>
#define vpi vector<pair<int, int>>
#define pq priority_queue

ll fast_exp(ll base, ll power){ll ans=1;while(power){if(power&1)ans=(ans*base)%mod;base=(base*base)%mod;power=power>>1;}return ans%mod;}
ll modInv(ll a,ll p){return fast_exp(a,p-2)%p;}
bool is_prime(int n){if(n==1){return false;}int i=2;while(i*i<=n){if(n%i==0){return false;}i+=1;}return true;}
ll gcd(ll a,ll b){if(a==0)return b;return gcd(b%a,a);}
ll modFact(ll n){if(n>=mod)return 0;ll result=1;for(ll i = 1; i <= n; i++)result=(result*i)%mod;return result;}

pii moves[] = {{-1, 0}, {1, 0}, {0 ,-1}, {0, 1}};

/****** S ****** X ****** T ****** Y ****** A ****** M ******/

int main() {
  FIO
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", sto");
  int n;
  cin >> n;
  int a[n], b[n], c[n];
  forn(i, n) cin >> a[i];
  forn(i, n) cin >> b[i];
  forn(i, n) cin >> c[i];

  map<int, ll> mp1, mp2, mp3;
  forn(i, n) mp1[c[i]]++;
  forn(i, n) {
    if(mp1.count(i+1)) mp2[b[i]] += mp1[i+1];
    else mp2[b[i]] += 0;
  }
  forn(i, n) mp3[a[i]]++;
  ll ans = 0;
  for(auto it : mp3) {
    if(mp2.count(it.ff)) ans += (mp2[it.ff] * it.ss);
  }
  cout << ans << endl;
}


//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <x86intrin.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define V vector
#define sz(x) int(x.size())
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;}
template<typename T> void print(T a) {cout << a << ' ';}
template<typename T> void printv(T a) {rep(i, sz(a))print(a[i]); cout<<endl;}
template<typename A, size_t N, typename T> void Fill (A (&array)[N], const T & val) {fill ((T*)array, (T*)(array+N), val);}
V<int> dx = {-1, 1,  0, 0, -1, -1,  1, 1};
V<int> dy = { 0, 0, -1, 1, -1,  1, -1, 1};

int main () {
    int n, m; cin >> n >> m;
    V<V<int>> p(n);
    rep(i, n) p[i].emplace_back(0);
    rep(i, n) {
        int a; cin >> a;
        p[a].emplace_back(i+1);
    }
    rep(i, n) p[i].emplace_back(n+1);
    V<int> d(n, 0);
    rep(i, n) {
        rep(j, sz(p[i])-1) chmax(d[i], p[i][j+1] - p[i][j]);
    }
    int ans = n;
    rep(i, n) {
        if (d[i] >= m+1) chmin(ans, i);
    }
    cout << ans << endl;

    return 0;
}

#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
// please, read the question correctly (do you need set or multiset)???
const int N=2000010; //check the limits, dummy
int a[N];
int n, m;
vector<int> pos[N];
int main(){
	scanf("%d%d",&n,&m);
	for(int i=0; i<=n; ++i){
		pos[i].push_back(-1);
	}
	for(int i=0; i<n; ++i){
		scanf("%d",a+i);
		pos[a[i]].push_back(i);
	}
	int ans = -1;
	for(int i=0;i<=n; ++i){
		pos[i].push_back(n);
		for(int j=0; j+1<pos[i].size(); ++j){
			if(pos[i][j+1]-pos[i][j]-1>=m){
				ans = i;
				break;
			}
		}
		if(ans!=-1)break;
	}
	cout<<ans<<endl;
}


#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <iomanip>
#include <functional>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,n) for (ll i = 0; i < (ll)(n); i++)
#define REP(i,n) for (ll i = 1; i <= (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define fcout cout<<fixed<<setprecision(15)
#define PI 3.1415926535897932384626433832795028841971693993751058209749445923078160628620899
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;
const ll NIL = -1;

ll N;
vector<ll> prime;

bool isPrime(ll N) {
	ll T = sqrt(N);
	for (int i = 2; i <= T; i++) {
		if (N % i == 0) return false;
	}
	return true;
}

int main() {
	cin >> N;
	ll p = 0;
	for (int i = 2; i <= N; i++) {
		if (isPrime(i)) {
			prime.push_back(i);
		}
	}
	REP(i, N) {
		if (i > 1) cout << " ";
		ll Z = 1;
		ll k = 0;
		ll U = i;
		while (U > 1) {
			if (U % prime[k] == 0) {
				U /= prime[k];
				Z++;
			}
			else k++;
		}
		cout << Z;
	}
	cout << endl;
	return 0;
}

#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

using ll = long long;
using ld = long double;
using ull = unsigned long long;

using namespace std;

/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cout.setf(ios::fixed), cout.precision(20);
	int n;
	cin >> n;
	if (n == 1) {
		cout << 1 << " " << 1 << "\n";
		return 0;
	}
	int k = 0;
	while ((1 << k) < n) {
		++k;
	}
	int mod = (1 << k);
	for (int i = 0; i < n; ++i) {
		int l = (i * 2) % mod;
		int r = (i * 2 + 1) % mod;
		if (l >= n) {
			l -= (1 << (k - 1));
		}
		if (r >= n) {
			r -= (1 << (k - 1));
		}
		cout << l + 1 << " " << r + 1 << "\n";
	}
	return 0;
}


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

#define ios			ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR(i,m)		for(int i = 0 ;i  < m ;i++)
#define mem(a ,b)		memset(a,  (b) , sizeof(a))
#define all(cont)		cont.begin(),cont.end()
#define mp			make_pair
#define pb			push_back
#define F			first
#define S			second
#define cn			cout<<'\n'
#define re			return

typedef pair<int,int>		pi;
typedef	vector<int>		vi;
typedef long long 		ll;
typedef long double		ld;
typedef unsigned long long int  ull;

const int mod = 1e9 +7;
const int maxN = 1e5 + 1;

int n , m , w;

void solve(){
	cin >> n ;
	int a[n];
	ll sum = 0;
	for(int i= 0 ;i < n;i++){
		cin >> a[i];
		sum += a[i];
	}

	bool dp[n + 1][sum + 1];
	memset(dp , 0 , sizeof(dp));

	dp[0][0] = true;

	for(int i = 1 ;i <= n ;i++){
		for(int j = 0 ;j <= sum ;j++){
			dp[i][j] = dp[i-1][j];

			if(j - a[i-1] >= 0)dp[i][j] |= dp[i-1][j-a[i-1]];
		}
	}

	for(int j=  sum/2 ; j>= 0 ;j--){
		if(dp[n][j]){
			cout<<sum-j<<"\n";
			return;
		}
	}

}

int32_t main(){

	ios;

	int _t = 1;
//	cin >> _t;

	for(int i = 1 ; i  <= _t ;i++){
//		cout<< "Case #"<<i<<": ";
		solve();
	}

	return 0;
}

#include <bits/stdc++.h>

using namespace std;

#ifndef aa
#define trace(...)
#define endl '\n'
#endif
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define fi first
#define se second
#define int long long
typedef long long ll;
typedef long double ld;
#define double long double
#define pii pair<int,int>
#define pdd pair<double,double>
#define pll pair<ll,ll>
#define sz(x) ((long long)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define frev(a,b,c) for(int a=c; a>=b; a--)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define trav(a,x) for(auto &a:x)
#define all(con) con.begin(),con.end()
#define deb(x) cout << x << endl
#define done(x) {cout << x << endl;return;}
#define mini(x,y) x=min(x,y)
#define maxi(x,y) x=max(x,y)
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
//const int mod = 998244353;
const int mod = 1e9 + 7;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<int>> vvi;
typedef vector<pair<int, int>> vpii;
typedef map<int, int> mii;
typedef set<int> si;
typedef set<pair<int,int>> spii;
typedef queue<int> qi;

const int N = 20;

int x[N], y[N], z[N], dp[1<<N];
vi g[1<<N];

int d(int i, int j){
   return abs(x[j]-x[i])+abs(y[j]-y[i])+max(0ll,z[j]-z[i]);
}

void solve() {

   int n;
   cin>>n;
   rep(i,0,n) cin>>x[i]>>y[i]>>z[i];
   dp[1] = 0;
   g[1] = {0,0};

   rep(msk, 3, 1<<n){
       if(msk%2==0)
          continue;
       vi v;
       int val = infl;
       rep(i,1,n){
          if(msk>>i&1 == 0) continue;
          int msk1 = msk ^ (1<<i);
          rep(j,0,sz(g[msk1])-1){
              int dis = dp[msk1] - d(g[msk1][j],g[msk1][j+1]) + d(g[msk1][j], i) + d(i, g[msk1][j+1]);
              //cout<<dis<<endl;
              if(dis>=val)continue;
              val = dis;
              v.clear();
              rep(k,0,j+1) v.pb(g[msk1][k]);
              v.pb(i);
              rep(k,j+1,sz(g[msk1])) v.pb(g[msk1][k]);
          }
       }
       dp[msk] = val;
       g[msk] = v;
       //cout<<dp[msk]<<endl;
   }

   cout<<dp[(1<<n)-1];

}

signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    //srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    cout << fixed << setprecision(15);
    int t = 1;
    //cin >> t;
    while (t--)
        solve();
#ifdef aa
    cout << endl << endl << endl << endl << "Time elapsed: " << (double)(clock() - clk) / CLOCKS_PER_SEC << endl;
#endif
    return 0;
}

int powm(int a, int b) {
    int res = 1;
    while (b) {
        if (b & 1)
            res = (res*a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return res;
}

int divide(int a, int b) {
    return (a % mod) * powm(b, mod - 2) % mod;
}

int norm(int a) {
    while (a >= mod) a -= mod;
    while (a < 0) a += mod;
    return a;
}

int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}


#include <bits/stdc++.h>

using namespace std;

// using mint = long double;
// using mint = modint998244353;
// using mint = modint1000000007;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> T;
typedef pair<ll, vector<ll>> Pd;

const ll INF = 1e18;
const ll fact_table = 820000;

priority_queue<ll> pql;
priority_queue<P> pqp;
// big priority queue
priority_queue<ll, vector<ll>, greater<ll>> pqls;
priority_queue<P, vector<P>, greater<P>> pqps;

// small priority queue
// top pop

ll dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
ll dy[8] = {0, 1, 0, -1, -1, 1, 1, -1};
//↓,→,↑,←

#define p(x) cout << x << "\n";
#define el cout << "\n";
#define pe(x) cout << x << " ";
#define ps(x) cout << fixed << setprecision(25) << x << endl;
#define pu(x) cout << (x);
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define pc(x) cout << x << ",";
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = a; i <= (b); i++)
#define rep3(i, a, b) for (ll i = a; i >= (b); i--)
#define all(c) begin(c), end(c)
#define sorti(v) sort(all(v))
#define sortd(v)                                                               \
    sort(all(v));                                                              \
    reverse(all(v));
#define SUM(v) accumulate(all(v), 0LL)
#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))

typedef vector<ll> vec;
typedef vector<vector<ll>> mat;

// vec v(n) -> 長さnのベクトルを宣言
// mat dp(h, vec(w)) -> h * w の行列を宣言

const ll mod = 1000000007ll;
// const ll mod = 998244353ll;

ll mypow(ll a, ll b, ll m = mod) {
    ll x = 1;
    while (b) {
        while (!(b & 1)) {
            (a *= a) %= m;
            b >>= 1;
        }
        (x *= a) %= m;
        b--;
    }
    return x;
}
vec rv(ll read) {
    vec res(read);
    for (int i = 0; i < read; i++) {
        cin >> res[i];
    }
    return res;
}
/*
ll fact[fact_table + 5], rfact[fact_table + 5];

void c3_init() {
    fact[0] = rfact[0] = 1;
    for (ll i = 1; i <= fact_table; i++) {
        fact[i] = (fact[i - 1] * i) % mod;
    }
    rfact[fact_table] = mypow(fact[fact_table], mod - 2, mod);
    for (ll i = fact_table; i >= 1; i--) {
        rfact[i - 1] = rfact[i] * i;
        rfact[i - 1] %= mod;
    }
    return;
}

ll c3(ll n, ll r) {
    return (((fact[n] * rfact[r]) % mod) * rfact[n - r]) % mod;
}
*/

bool icpc = false;
bool multicase = false;

ll n;
ll x[100005];
ll dp[100005];

bool solve() {
    cin >> n;
    vec v = rv(n);
    sorti(v);
    ll mid = v[(n + 1) / 2 - 1];

    ll sum2 = mid * n;
    sum2 += SUM(v) * 2ll;
    for (auto e : v) {
        sum2 -= min(e, mid) * 2ll;
    }

    long double ans = sum2 / 2.0;
    ans /= n;
    ps(ans);

    return true;
}
/*

*/

int main() {
    // ios::sync_with_stdio(false);
    // cin.tie(nullptr);
    if (icpc) {
        while (solve())
            ;
        return 0;
    }
    ll q, testcase = 1;
    if (multicase) {
        cin >> q;
    } else {
        q = 1;
    }
    while (q--) {
        // cout << "Case #" << testcase << ": ";
        solve();
        testcase++;
    }

    // solve();
    return 0;
}

#include <iostream>
#include <vector>
//#include <string>
#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;

//#define MOD 1000000007
//#define MOD 998244353
//#define MAX 200100
//#define NIL -1
//#define INFTY 1000000000000000000

int main(){
    LL n;
    cin >> n;
    vector<LL> a(n);
    for(LL i=0; i<n; i++){
        cin >> a[i];
    }

    sort(a.begin(),a.end());
    while(a[0]!=a[n-1]){
        for(LL i=1; i<n; i++){
            if(a[i]%a[0]==0){
                a[i]=a[0];
            }else{
                a[i]=a[i]-(a[i]/a[0])*a[0];
            }
        }
        sort(a.begin(),a.end());
    }

    cout << a[0] << endl;

    return 0;
}


#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; }
//---------------------------------------------------------------------------------------------------
template<int MOD> struct ModInt {
    static const int Mod = MOD; unsigned x; ModInt() : x(0) { }
    ModInt(signed sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    ModInt(signed long long sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    int get() const { return (int)x; }
    ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
    ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }
    ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
    ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
    ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
    ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }
    ModInt inverse() const { long long a = x, b = MOD, u = 1, v = 0;
        while (b) { long long t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); }
        return ModInt(u); }
    bool operator==(ModInt that) const { return x == that.x; }
    bool operator!=(ModInt that) const { return x != that.x; }
    ModInt operator-() const { ModInt t; t.x = x == 0 ? 0 : Mod - x; return t; }
};
template<int MOD> ostream& operator<<(ostream& st, const ModInt<MOD> a) { st << a.get(); return st; };
template<int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) {
    ModInt<MOD> r = 1; while (k) { if (k & 1) r *= a; a *= a; k >>= 1; } return r; }
typedef ModInt<1000000007> mint;
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/

int N; ll A[3010];
mint dp[3010][3010];  // dp[i][k] := i番目まででk組作った
mint tot[3010][3010]; // tot[k][mo] := k組作っていてこれまでの総和を(k+1)で割った余りがmoである
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;
    rep(i, 0, N) cin >> A[i];

    dp[0][0] = 1;
    tot[0][0] = 1;
    ll sum = 0;
    rep(i, 0, N) {
        sum += A[i];
        rep(k, 1, N + 1) dp[i + 1][k] = tot[k - 1][sum % k];
        rep(k, 1, N + 1) tot[k][sum % (k + 1)] += dp[i + 1][k];
    }

    mint ans = 0;
    rep(k, 1, N + 1) ans += dp[N][k];
    cout << ans << endl;
}

#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using vi = vector<int>;
using pi = pair<int, int>;
using vpi = vector<pair<int, int>>;
using pl = pair<ll, ll>;
using vl = vector<ll>;

#define all(v) (v).begin(), (v).end()
#define ar array
#define PB push_back
#define sz(x) (int)(x).size()

template <typename T>
using pqg = priority_queue<T, vector<T>, greater<T>>;
template <typename A, typename B>
ostream &operator<<(ostream &os, const pair<A, B> &p)
{
    return os << '(' << p.first << ", " << p.second << ')';
}
template <typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type>
ostream &operator<<(ostream &os, const T_container &v)
{
    os << '{';
    string sep;
    for (const T &x : v)
        os << sep << x, sep = ", ";
    return os << '}';
}
void dbg_out()
{
    cerr << endl;
}
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T)
{
    cerr << ' ' << H;
    dbg_out(T...);
}
#ifdef LOCAL
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

struct custom_hash
{
    static uint64_t splitmix64(uint64_t x)
    {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const
    {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

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

const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9 + 7; //998244353
const int N = 3005;
int dp[N][N], mem[N][N];
ll sum[N];

void solve()
{
	int n;
	cin >> n;
	vl a(n+1);
	for (int i=1;i<=n;++i) cin >> a[i], sum[i] = sum[i-1]+a[i];
	mem[1][0] = dp[0][0] = 1;
	for (int i=0;i<n;++i){
		for (int j=1;j<=n;++j){
			dp[i+1][j] = mem[j][sum[i+1]%j];
		}
		for (int j=2;j<=n;++j){
			mem[j][sum[i+1]%j] += dp[i+1][j-1];
			mem[j][sum[i+1]%j]%=MOD;
		}
	}
	ll ans = 0LL;
	for (int i=0;i<=n;++i) ans = (ans+dp[n][i])%MOD;
	cout << ans << "\n";
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    solve();
}


#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (ll)(n); i++)
#define rrep(i,a,b) for (ll i = (a); i < (ll)(b); i++)
#define rng(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define fr first
#define sc second

using namespace std;
template <class T, class U> inline bool chmax(T &a, const U &b) { return (a < b ? a = b, 1 : 0); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return (a > b ? a = b, 1 : 0); }
template <class T> using vc = vector<T>;
template <class T> using vv = vc<vc<T>>;
template <class T> using vvv = vc<vv<T>>;
template <class T> using PQ = priority_queue<T, vc<T>, greater<T>>;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;
using ti3 = tuple<int, int, int>;
using tl3 = tuple<ll, ll, ll>;
using vi = vc<int>;
using vl = vc<ll>;
using vvi = vv<int>;
using vvl = vv<ll>;

const ld pi = 3.141592653589793;
const ll linf = 1001001001001001001LL;
const int inf = 1001001001;

int main() {
  string s;
  cin >> s;
  int n = s.size();
  int ans = inf;
  rrep(i,1,1<<n) {
    ll sum = 0;
    rep(j,n) if (i>>j&1) sum += s[j]-'0';
    if (sum%3 == 0) chmin(ans, n-__builtin_popcountll(i));
  }
  cout << (ans == inf ? -1 : ans) << endl;
}

#include <bits/stdc++.h>

#define ln                 '\n'
#define all(dat)           dat.begin(), dat.end()
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fm, to)    for (int i = fm; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

template<int mod> struct modulo {
	typedef modulo T;
	int w;
	operator int() const { return w; }

	modulo() {}
	modulo(int w) { this->w = w; fix(); }
	template<class A> modulo(A w) { this->w = w % mod; fix(); }
	inline void fix() { if (w >= mod || w < -mod) w %= mod; if (w < 0) w += mod; }

	inline T  operator -  () const { return mod - w; }
	inline T& operator += (const T &b) { if ((w += b.w) >= mod) w -= mod; return *this; }
	inline T& operator -= (const T &b) { if ((w -= b.w) < 0) w += mod; return *this; }
	inline T& operator *= (const T &b) { w = (unsigned long long) w * b.w % mod; return *this; }
	inline T& operator /= (const T &b) { return *this *= b.inv(); }
	#define make_operation(P)\
	friend inline T operator P (const T &a, const T &b) { return T(a) P##= b; }\
	template<class U> friend inline T operator P (const T &a, const U &b) { return T(a) P##= b; }\
	template<class U> friend inline T operator P (const U &a, const T &b) { return T(a) P##= b; }
	make_operation(+) make_operation(-) make_operation(*) make_operation(/)
	#undef make_operation

	inline T inv() const {
		int a = w, m = mod, u = 0, v = 1, t;
		for (; a != 0; t = m / a, m -= t * a, swap(a, m), u -= t * v, swap(u, v));
		return u;
	}

	friend inline T pow(const T &w, num p) {
		T a = w, r = 1; for (; p > 0; a *= a, p >>= 1) if (p & 1) r *= a; return r;
	}
};
const int mod = 998244353;
typedef modulo<mod> rem;

const int nsz = 1e2, asz = 1e2, msz = nsz * asz;
int n, m, a[nsz + 5], pre[nsz + 5];
rem ans, dp[2][nsz + 5][msz + 5];

int main() {
	scanf("%d", &n);
	cont (i, n) scanf("%d", &a[i]), pre[i] = pre[i - 1] + a[i];
	m = pre[n] / 2;
	if (pre[n] & 1) { printf("0\n"); return 0; }

	int o = 0, x = 1;
	dp[o][0][0] = 1;
	loop (i, n) {
		int w = a[i + 1], mx = min(pre[i], m);
		circ (k, 0, i) circ (a, 0, mx) {
			rem val = dp[o][k][a];
			if (!val) continue;
			dp[x][k + 1][a + w] += val * (k + 1);
			dp[x][k][a] += val * (i - k + 1);
		}
		swap(o, x);
		memset(dp[x], 0, sizeof(dp[x]));
	}
	circ (k, 0, n) ans += dp[o][k][m];
	printf("%d\n", ans.w);
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb emplace_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
#define dupli(a) {sort(all(a));a.erase(unique(all(a)),a.end());}
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vvvvi=vector<vvvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const ll INF=1001001001;
const ll mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){ll res=1;a%=mod;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}

int main(){
    ll n;cin>>n;
    vi v(n);
    rep(i,n){
        cin>>v[i];
        v[i]--;
    }
    vi id(n);
    rep(i,n)id[v[i]]=i;
    vi ans;
    rep(i,n-1){
        ll k=id[i];
        for(int j=k;j>=i+1;j--){
            ans.pb(j);
            id[v[j-1]]++;
            id[i]--;
            swap(v[j-1],v[j]);
        }
        if(ans.size()>=n)dame(-1);
    }
    rep(i,n)if(v[i]!=i)dame(-1);
    if(ans.size()!=n-1)dame(-1);
    vi used(n-1,false);
    rep(i,n-1){
        if(used[ans[i]-1])dame(-1);
        used[ans[i]-1]=true;
    }
    for(ll x:ans)out(x);
}

#pragma GCC target("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define DEBUG
#ifdef DEBUG
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << '(' << p.first << ',' << p.second << ')';
    return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << '{';
    for(int i = 0; i < (int)v.size(); i++) {
        if(i) { os << ','; }
        os << v[i];
    }
    os << '}';
    return os;
}
void debugg() { cerr << endl; }
template <class T, class... Args>
void debugg(const T &x, const Args &... args) {
    cerr << " " << x;
    debugg(args...);
}
#define debug(...)                                                             \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]: ", debugg(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = (1<<30)-1;
const ll linf = 1LL<<61;
const int MAX = 10100000;
int dy[8] = {0,1,0,-1,1,-1,-1,1};
int dx[8] = {-1,0,1,0,1,-1,1,-1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    int sz = a.size();
    for(auto itr = a.begin(); itr != a.end(); itr++){
		cout << *itr;
        sz--;
        if(sz) cout << " ";
	}
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){
	cout << a << " " << b << "\n";
}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
void mark() {cout << "#" << "\n";}
ll pcount(ll x) {return __builtin_popcountll(x);}
//const int mod = 1e9 + 7;
const int mod = 998244353;

int main(){
    ll n,k; cin >> n >> k;
    while(k--){
        string s;
        while(n){
            s.push_back(n % 10);
            n /= 10;
        }
        sort(rall(s));
        ll t = 0;
        for(auto c : s){
            t = t * 10 + c - '0';
        }
        reverse(all(s));
        ll u = 0;
        for(auto c : s){
            u = u * 10 + c - '0';
        }
        n = t - u;
    }
    cout << n << "\n";
}


#include <iostream>
#include <cmath>

using namespace std;

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

  for (int i = 0; i < 3; i++){
    int temp;
    cin >> temp;
    minimum = min(minimum, temp);
  }
  cout << minimum << endl;
}


// Author: wlzhouzhuan
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pb push_back
#define fir first
#define sec second
#define rep(i, l, r) for (int i = l; i <= r; i++)
#define per(i, l, r) for (int i = l; i >= r; i--)
#define mset(s, t) memset(s, t, sizeof(s))
#define mcpy(s, t) memcpy(s, t, sizeof(t))
template<typename T1, typename T2> void ckmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> void ckmax(T1 &a, T2 b) { if (a < b) a = b; }
int read() {
  int x = 0, f = 0; char ch = getchar();
  while (!isdigit(ch)) f |= ch == '-', ch = getchar();
  while (isdigit(ch)) x = 10 * x + ch - '0', ch = getchar();
  return f ? -x : x;
}
template<typename T> void print(T x) {
  if (x < 0) putchar('-'), x = -x;
  if (x >= 10) print(x / 10);
  putchar(x % 10 + '0');
}
template<typename T> void print(T x, char let) {
  print(x), putchar(let);
}

int n;
int main(){
	n=read();
	printf("%d\n",(1<<n)-1);
	for(int i=1;i<(1<<n);++i){
		for(int j=0;j<(1<<n);++j){
			putchar((__builtin_popcount(i&j)&1)+'A');
		}
		putchar('\n');
	}
	return 0;
}

/**
 *  created: 16/01/2021, 14:27:24
**/

#include <bits/stdc++.h>

using namespace std;

const int max_n = 1111, inf = 1000111222;

int n, cnt[max_n][max_n];
vector<string> ans;

int c2(int n) {
    return n * (n - 1) / 2;
}

bool get_bit(int mask, int pos) {
    return (mask >> pos) & 1;
}

void check() {
    for (string s : ans) {
        if (!(s.length() == (1 << n))) {
            cout << s.length() << endl;
            cout << (1 << n) << endl;
            exit(2);
        }
        for (int i = 0; i < s.length(); ++i) {
            for (int j = i + 1; j < s.length(); ++j) {
                cnt[i][j] += s[i] == s[j];
            }
        }
    }
    for (int i = 0; i < (1 << n); ++i) {
        for (int j = i + 1; j < (1 << n); ++j) {
            cout << cnt[i][j] << " ";
        }
        cout << endl;
    }
}

vector<string> solve(int n) {
    if (n == 1) {
        return {"AB"};
    }
    vector<string> v = solve(n - 1);
    vector<string> res;
    for (string s : v) {
        string t = s;
        for (int i = 0; i < t.size(); ++i) {
            t[i] ^= 'A' ^ 'B';
        }
        res.push_back(s + s);
        res.push_back(s + t);
    }
    string s;
    for (int i = 0; i < (1 << (n - 1)); ++i) {
        s += 'A';
    }
    for (int i = 0; i < (1 << (n - 1)); ++i) {
        s += 'B';
    }
    res.push_back(s);
    return res;
}

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin >> n;
    /*int a = c2(1 << (n - 1)) * 2;
    int b = c2(1 << n);
    int lc = a / __gcd(a, b) * b;
    cout << a << " " << b << " " << lc << endl << lc / a << endl;*/
    /*
    ans.push_back("AABB");
    ans.push_back("ABAB");
    ans.push_back("ABBA");
    */

    ans = solve(n);

    /*ans.push_back("AAAABBBB");

    ans.push_back("AABBAABB");
    ans.push_back("ABABABAB");
    ans.push_back("ABBAABBA");

    ans.push_back("AABBBBAA");
    ans.push_back("ABABBABA");
    ans.push_back("ABBABAAB");*/

    cout << ans.size() << "\n";
    for (auto s : ans) {
        cout << s << "\n";
    }

    //check();

    return 0;
}


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author NikuKyabe
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define REV(i, a, b) for (int i = (b) - 1; i >= (a); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001l
#define MOD 1000000007
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

/**
 * [l >= 0, r]にある1e4の倍数
 * @param l
 * @param r
 * @return
 */
int g(int l, int r){
    return r / (int)1e4 - l / (int)1e4;
}

/**
 * [l, r]にある，1e4の倍数
 * @param l
 * @param r
 * @return
 */
int f(int l, int r){
    if(r < 0) return g(-r-1, -l);
    if(l > 0) return g(l-1, r);
    return g(0,r) + g(0, -l) + 1;
}

int sqr(int x){
    int r = sqrt(x) - 1;
    while((r+1) * (r+1) <= x)r++;
    return r;
}

class DCircleLatticePoints {
public:
	void solve(std::istream& cin, std::ostream& cout) {
        double x,y,r;
        cin >> x >> y >> r;
        x *= 1e4;
        y *= 1e4;
        r *= 1e4;
        int X = round(x);
        int Y = round(y);
        int R = round(r);
        int now_x = X - R;
        while(now_x % (int)1e4 != 0) now_x++;
        int ans = 0;
        while(now_x <= X + R){
            int t = sqr(R * R - (X - now_x) * (X - now_x));
            ans += f(Y - t, Y + t);
            now_x += 1e4;
        }
        cout << ans << endl;
	}
};

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

#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define rrep(i, n) for (int i = (int)n-1; i >= 0; --i)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;

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

long long pow(long long x, long long n, long long MOD) {
    long long ret = 1;
    while (n > 0) {
        if (n & 1) ret = ret * x % MOD;  // n の最下位bitが 1 ならば x^(2^i) をかける
        x = x * x % MOD;
        n >>= 1;  // n を1bit 左にずらす
    }
    return ret;
}

int main(){

    ll a, b, c;
    cin >> a >> b >> c;
    ll cnt = 0;
    // a は何回かけたら一周するか
    set<int> si;
    ll now = a;

    while(1){
        if(si.count(now*a%10ll)){
            break;
        }else{
            si.insert(now * a % 10ll);
            now *= a % 10;
            now %= 10;
        }
        cnt++;
    }

    ll b_c = pow(b, c, cnt);
    if (!b_c){
        b_c = cnt;
    }
    ll ans = pow(a, b_c, 10);
    cout << ans << endl;
    return 0;
}


#include<bits/stdc++.h>
#define N 200005
#define re register
#define ll long long
#define P 998244353
using namespace std;
int n,m,K,q,u;
inline void Rd(int &res){
	re char c;res=0;bool f=0;
	while(c=getchar(),c<48)(c=='-')&&(f=1);
	do res=(res<<3)+(res<<1)+(c^48);
	while(c=getchar(),c>47);
	f&&(res=-res);
}
int f[25][N],len,fac[N],fac1[N];
inline void Mod(int &x){x>=P&&(x-=P);}
inline int C(int n,int m){
	if(n<m)return 0;
	return 1ll*fac[n]*fac1[m]%P*fac1[n-m]%P;
}
int Pow(int x,int k){
	int res=1;
	while(k){
		if(k&1)res=1ll*res*x%P;
		x=1ll*x*x%P;
		k>>=1;
	}
	return res;
}
int main(){
	Rd(n),Rd(m);
	for(re int i=1;i<=m;i++)f[1][i]=1;
	for(re int i=2;;i++){
		bool bo=0;
		for(re int j=1;j<=m;j++)if(f[i-1][j]){
			for(re int k=2;;k++)
			if(j*k<=m){
				bo=1;
				Mod(f[i][j*k]+=f[i-1][j]);
			}
			else break;
		}
		if(!bo){
			len=i-1;
			break;
		}
	}
	fac[0]=1;for(re int i=1;i<=n;i++)fac[i]=1ll*i*fac[i-1]%P;
	fac1[n]=Pow(fac[n],P-2);for(re int i=n-1;i>=0;i--)fac1[i]=1ll*(i+1)*fac1[i+1]%P;
	int ans=0;
	for(re int i=1;i<=len;i++){
		for(re int j=1;j<=m;j++)if(f[i][j]){
			ans=(ans+1ll*f[i][j]*C(n-1,i-1))%P;
		}
	}
	printf("%d\n",ans);

	return 0;
}

#include<iostream>
#include<cstdio>
#include<map>
using namespace std;
#define N 100012
inline int sgn(int x){return (x==0)?0:((x>0)?1:(-1));}
inline int Abs(int x){return (x>0)?x:(-x);}
int n,L,a[N],b[N],c[N],la[N];bool fl=true;map<int,int>mp;long long ans=0;
inline void Fin(int l,int r)
{
	if(l+1>=r)return;int i,ql=l,qr=r,ls;
	for(i=l+1;i<r-1;i++)if((c[i]==1)&&(c[i+1]==(-1))){fl=false;return;}
	for(i=l;i<=r;i++)if(c[i]==(-1))ql=i;for(i=r;i>=l;i--)if(c[i]==1)qr=i;
	mp.clear();for(i=l;i<=ql;i++){if(c[i]){if(!mp.count(b[i]-i)){fl=false;return;}la[i]=mp[b[i]-i];}mp[a[i]-i]=i;}
	mp.clear();for(i=r;i>=qr;i--){if(c[i]){if(!mp.count(b[i]-i)){fl=false;return;}la[i]=mp[b[i]-i];}mp[a[i]-i]=i;}
	ls=l;for(i=l;i<=r;i++){if(c[i]&&(ls>la[i])){fl=false;return;}if(c[i])ls=max(ls,la[i]);}
	ls=r;for(i=r;i>=l;i--){if(c[i]&&(ls<la[i])){fl=false;return;}if(c[i])ls=min(ls,la[i]);}
	ls=r;for(i=ql;i>=l;i--)if(c[i]&&(la[i]!=ls)){ans+=i-la[i];ls=la[i];}
	ls=l;for(i=qr;i<=r;i++)if(c[i]&&(la[i]!=ls)){ans+=la[i]-i;ls=la[i];}
}
int main(){
	scanf("%d%d",&n,&L);int i,l,r;for(i=1;i<=n;i++)scanf("%d",&a[i]);for(i=1;i<=n;i++)scanf("%d",&b[i]);a[0]=b[0]=0;a[n+1]=b[n+1]=L+1;
	for(i=1;i<=n;i++)c[i]=sgn(b[i]-a[i]);
	for(i=0;(i<=(n+1))&&fl;i=r){l=i;r=i+1;while((r<=n)&&c[r])++r;Fin(l,r);}if(!fl){printf("-1");return 0;}printf("%lld",ans);return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define int long long int
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define endl "\n";
#define rep(i, a, b) for (int i=a; i<b; i++)
#define pre(i, a, b) for (int i=a; i>=b; i--)

const int MAX_N = 1e5+5;
const int MOD = 1e9 + 7;
const int INF = 1e9;

#define pb push_back
#define fi first
#define se second
#define pii pair<int, int>

void solve() {
	int n,m,q; cin>>n>>m>>q;

	vector<pii> a(n);
	int x,y;

	rep(i,0,n){
		cin>>x>>y;
		a[i] = {y,x};
	}

	sort(a.rbegin(),a.rend());

	vector<int> box(m);

	rep(i,0,m) cin>>box[i];
	int l,r;

	rep(i,0,q){
		cin>>l>>r;
		--l,--r;
		multiset<int> ms;

		rep(i,0,m){
			if(i<l || i>r){ ms.insert(box[i]); }
		}

		int ans = 0;

		rep(i,0,n){
			auto itr = ms.lower_bound(a[i].se);
			if(itr!=ms.end()){
				ans+=a[i].fi;
				ms.erase(itr);
			}
		}
		cout<<ans<<endl;
	}
}

signed main() {
    fast

    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif

    cout.precision(10);
    cout<<fixed;

    int t = 1;
    // cin >> t;

    for (int i = 1; i <= t; i++) {
        // cout << "Case #" << i  << ": ";
        solve();
    }
}

// ###### Fri Mar 5 20:57:40 IST 2021

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define forn(ii, a, b) for (int ii = a; ii < b; ii++)
#define scan(any)      for (auto &i : any) cin >> i;
#define debug(x)       cerr << #x << " " << x << " -- \n"
#define int64          long long
#define sized(x)       (int)x.size()
#define all(x)         (x).begin(), (x).end()
#define precise(x)     cout << fixed << setprecision(9) << x << '\n';
using namespace std;
using namespace __gnu_pbds;
template <class T> using indexed_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int N = 3e5+7;
int test(){
    int n,m,q;
    cin >> n  >> m >> q;
    vector <pair<int,int>> baggage(n);
    for(auto& p : baggage)
        cin >> p.first >> p.second;
    sort(all(baggage));

    vector <int> boxes(m);
    scan(boxes);
    int l,r;
    while(q--){
        cin >> l >> r;
        l--,r--;
        int real_ans = 0;
        vector <pair<int,int>> b = baggage;
        vector <int> BOX;
        forn(j,0,l)
            BOX.push_back(boxes[j]);
        forn(j,r+1,m)
            BOX.push_back(boxes[j]);
        sort(all(BOX));
        for(auto p : BOX){
            int ans = -1;
            int last = n;
            int box_size = p;
            forn(i,0,n)
                if( b[i].first <= box_size){
                    last = i;
                    if(b[i].second > 0)
                        ans = max(ans, b[i].second);
                }else
                    break;
            if(ans == -1)
                continue;
            forn(i,0,last+1)
                if(b[i].second == ans){
                    b[i].second = 0;
                    break;
                }
            real_ans += ans;
        }
        cout << real_ans << '\n';
    }
    return 0 ;
}
int main(){
    ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);

    int cases = 1;
    // cin >> cases;

    while(cases--)
        test();
    return 0LL;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,cap,m,t;
    cin>>n>>m>>t;
    cap = n;
    vector<ll> A(m);
    vector<ll> B(m);
    for(int i=0; i<m; i++)
        cin>>A[i]>>B[i];
    ll Time = 0, i=0;
    while(i<m){
        cap -= A[i] - Time;
        //cout<<cap<<endl;
        if(cap <= 0){
            cout<<"No"<<endl;
            return 0;
        }
        cap = min(n,cap + B[i] - A[i]);
        //cout<<cap<<endl;
        Time = B[i];
        i++;
    }
    cap -= t - Time;
    if(cap <= 0){
        cout<<"No"<<endl;
    }
    else{
        cout<<"Yes"<<endl;
    }

    return 0;
}

// Problem: B - Smartphone Addiction
// Contest: AtCoder - AtCoder Beginner Contest 185
// URL: https://atcoder.jp/contests/abc185/tasks/abc185_b
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

// Problem: A - ABC Preparation
// Contest: AtCoder - AtCoder Beginner Contest 185
// URL: https://atcoder.jp/contests/abc185/tasks/abc185_a
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#define ll long long
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
#define fr(i,a,b) for(int i=a;i<b;i++)
#define frr(i,a,b) for(int i=a;i>=b;i--)
//vector
#define pb push_back
#define vi vector<int>
#define vl vector<ll>
#define pp pop_back
//pair
#define pi pair<int ,int >
#define mk make_pair
#define ff first
#define ss second
//set
#define si set<int>
#define sit set<int>::iterator
//bits
#define bp(x)  __builtin_clzll(x)
#define case Case #
using namespace std;
int main()
{

	// #ifndef ONLINE_JUDGE
 //        freopen("input.txt","r",stdin);
 //        freopen("output.txt","w",stdout);
	// #endif

fast;
ll n,m,t;cin>>n>>m>>t;
ll f=1,pre=0,mx=n;
fr(i,0,m)
{
	ll x,y;cin>>x>>y;
	n-=abs(x-pre);
	if(n<=0) f=0;
	n+=abs(x-y);
	n=min(n,mx);
	pre=y;
}
n-=abs(pre-t);
if(n<=0) f=0;
if(f) cout<<"Yes";
else cout<<"No";
return 0;
}


#include <iostream>

using namespace std;
using ll = long long;
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
//atcoder 0,19,3,14,4,5,17  -96
ll ceil(double x);
ll gcd(ll a, ll b);
int main(){
cin.tie(0);
ll n;
cin>>n;
for(ll i=1;i<=n;i++){
  cout<<ceil(double(i-0)/2)<<" "<<n-int((n-i)/2)<<endl;
}
  return 0;
}

ll ceil(double x){
  //cout<<"double:"<<x<<"ll:"<<ll(x)<<endl;
  if(x==ll(x))return ll(x);
  else return ll(x)+1;
}

#include <bits/stdc++.h>
int n;
int main(){
	scanf("%d",&n);
	for (int i=0;i<n;i++)
		printf("%d %d\n",(i*2)%n+1,(i*2+1)%n+1);
}


 //BISMILLAHIR RAHMANIR RAHEEM
//ALLAH IS WATCHING ME

// Shoeb Akibul Islam
// Dept of ICE, NSTU

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#define dua ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define i_love_u_huu dua long long t;cin >> t;while(t--)
#define ses   "\n"
#define whp   " "
#define mxi 200003
#define mp make_pair
#define pii pair<long long, long long>
#define pf printf
#define sf scanf
#define ff first
#define sob(z)  (z).begin(), (z).end()
#define ss second
#define pb push_back
#define rep0(i,a,b) for(int i=a; i<b; i++)
#define rep1(i,a,b) for(int i=a; i<=b; i++)
#define rep0in(i,a,b) for(int i=a-1; i>=b; i--)
#define rep1in(i,a,b) for(int i=a; i>b; i--)
#define repv(i,a) for(auto i=a.begin(); i!=a.end();++i)
#define INF 0x3f3f3f3f
#define CLR(a,b) memset(a,b,sizeof(a));
#define PI acos(-1)
#define what_is(x) cerr<<x<<ses;
//set <int, greater <int> > ::iterator it;
//vector<pair<int,int> >a;
//memset(arr,0,sizeof(hg));
//priority_queue <int, vector<int>, greater<int> > pq;
///  string single character erase-
///             s.erase(s.begin()+x); where s is st ring name
///               ans x is index;
///    transform(sl.begin(), sl.end(), sl.begin(), ::tolower);
///    transform(su.begin(), su.end(), su.begin(), ::toupper);
typedef long long v99;
typedef unsigned long long ull;
using namespace std;
using namespace __gnu_pbds;
v99 fx[4]= {1,-1,0,0};
v99 fy[4]= {0,0,1,-1};
v99 ox8[] = {0, 0, 1, 1, 1, -1, -1, -1};
v99 oy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
bool sort2val(const pii &a,const pii &b)
{
    if(a.second==b.second)return a.first<b.first;
    return a.second<b.second;
}
template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }

typedef tree< v99, null_type, less<v99>, rb_tree_tag,tree_order_statistics_node_update> ott;
typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
/// find_by_order(k) – kth index a ki ache, pointer return korbe.
/// order_of_key(x) – x kon position a ache , oita bole dibe

/**bool prime[10000020];vector<v99>prm;
void SieveOfEratosthenes(v99 n)
{
	memset(prime, true, sizeof(prime));
	for(v99 i=4;i<=n;i+=2)prime[i]=false;
	for (v99 p=3; p*p<=n; p+=2)
	{
		if (prime[p] == true)
		{
			/// Update all multiples of p
			for (v99 i=p*p; i<=n; i += 2*p)
				prime[i] = false;
		}
	}
	rep1(i,2,n)if(prime[i])prm.push_back(i);

}*/
bool isPowerOfTwo (v99 x)
{
    /* First x in the below expression is for the case when x is 0 */
    return x && (!(x&(x-1)));
}
v99 pw(v99 a, v99 b)
{
	v99 ans = 1;
	for(v99 i = 1; i <= b; ++i)
		ans = (ans * a);
	return ans;
}
void vout(auto a)
{
    for(auto i:a)cout<<i<<whp;cout<<ses;
}
void mout(auto a)
{
    for(auto i:a)cout<<i.ff<<whp<<i.ss<<ses;
}
void aout0(v99 a[],v99 n)
{
    rep0(i,0,n)cout<<a[i]<<whp;cout<<ses;
}
void aout1(v99 a[],v99 n)
{
    rep1(i,1,n)cout<<a[i]<<whp;cout<<ses;
}

template <class T> inline T bigmod(T n,T p,T m)
{
    if(p==0)return 1;
    else if(p%2==0)
    {
        v99 val=bigmod(n,p/2,m);
        return (T)((val*val)%m);
    }
    else return (T)(((v99)n*(v99)bigmod(n,p-1,m))%m);
}
///-------------------------------------------------------------------------------------------------------

void solve()
{
    /// code is here->
    v99 n;cin>>n;
    set<v99>s;
    for(v99 i=1;i*i<=n;i++)
    {
        if(n%i==0)s.insert(i),s.insert(n/i);
    }
    for(v99 i:s)cout<<i<<ses;
}

signed main()
{
    //dua
    //freopen("data.out","w",stdout);
    //while(1)
    //i_love_u_huu
    solve();
    return 0;
}

      ///  Alhamdulillah...

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pl;
#define all(a) (a).begin(),(a).end()
#define overload4(_1, _2, _3, _4, name, ...) name
#define rep1(n) for(ll i = 0;i < (n);i++)
#define rep2(i,n) for(ll i = 0;i < (n);i++)
#define rep3(i,a,b) for(ll i = (a);i < (b);i++)
#define rep4(i,a,b,c) for(ll i = (a);i < (b);i += (c))
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep1(n) for(ll i = (n)-1;i >= 0;i--)
#define rrep2(i,n) for(ll i = (n)-1;i >= 0;i--)
#define rrep3(i,a,b) for(ll i = (a)-1;i >= (b);i--)
#define rrep4(i,a,b,c) for(ll i = (a)-1;i >= (b);i -= (c))
#define rrep(...) overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define SHOW(x) cout << #x << ": " << x << endl;
template<class T> ll sumArr(const T& a){ return accumulate(all(a), 0LL);}
template<class T> auto minArr(const T& a){ return *min_element(all(a));}
template<class T> auto maxArr(const T& a){ return *max_element(all(a));}
template<class T> void DEBUG_PRINT(T tmp){cout<<tmp<<endl;}
template<class T1,class... T2> void DEBUG_PRINT(T1 tmp,T2... tmp2){cout<<tmp<<" ";DEBUG_PRINT(tmp2...);}
ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
ll lcm(ll a, ll b){ if(!a || !b) return 0; return a / gcd(a, b) * b; }
const ll INF=1e18,MOD = 1e9+7;
const int iINF = 1e9;

bool dist(ll x1,ll x2,ll y1,ll y2){
    return y1 * x2 == y2 * x1;
}

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

    int n;
    bool ans = false;
    cin>>n;
    vector<ll>x(n),y(n);
    rep(i,n)cin>>x[i]>>y[i];

    rep(i,n)rep(j,i+1,n)rep(k,j+1,n){
        if(ans)break;
        ans = dist(x[i] - x[j],x[i] - x[k],y[i] - y[j],y[i] - y[k]);
    }
    if(ans)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define st first
#define nd second
#define pii pair<int,int>
#define mp make_pair
#define pll pair<long long,long long>

using namespace std;

const int nax = 105;

vector<int> adj[nax];
set<pair<pii, int> > s;
set<pair<pii, int> > zostaly;
int n,m;
int c[nax];
int ans[nax * nax * nax];

bool vis[nax];
set<pii> zero;

int dep[nax];

void dfs(int v,int lvl)
{
    dep[v] = lvl;
    vis[v] = true;
    for(int x : adj[v])
    {
        if(vis[x] == false && c[x] == c[v])
        {
            zero.insert(mp(v,x));
            dfs(x,lvl+1);
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n>>m;
    for(int i=1;i<=m;i++)
    {
        int x,y; cin>>x>>y;
        s.insert(mp(mp(x,y),i));
    }

    for(int i=1;i<=n;i++) cin>>c[i];
    for(auto x : s)
    {
        int fr = x.st.st;
        int to = x.st.nd;
        int nbr = x.nd;

        if(c[fr] != c[to])
        {
            if(c[fr] > c[to]) ans[nbr] = 0;
            else ans[nbr] = 1;
        }
        else
        {
            zostaly.insert(x);
            adj[fr].pb(to);
            adj[to].pb(fr);
        }
    }

    for(int i=1;i<=n;i++)
    {
        if(vis[i] == false) dfs(i,0);
    }

    for(auto x : zostaly)
    {
        pii cur = x.st;
        pii xd = mp(cur.nd,cur.st);
        if(zero.count(cur) || zero.count(xd))
        {
            // w dol

            if(dep[cur.st] < dep[cur.nd]) ans[x.nd] = 0;
            else ans[x.nd] = 1;
        }
        else
        {
            int one = x.st.st;
            int two = x.st.nd;
            if(dep[one] > dep[two]) ans[x.nd] = 0;
            else ans[x.nd] = 1;
        }
    }

    for(int i=1;i<=m;i++)
    {
        if(ans[i] == 0) cout<<"->"<<"\n";
        else cout<<"<-"<<"\n";
    }

    return 0;
}

#include "bits/stdc++.h"
//#include "atcoder/all"
using namespace std;
//using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
//using mint = modint998244353;
//const int mod = 998244353;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n-1); i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define endl "\n"

vector<int>to[100];
bool Check[100];
map<pair<int, int>, int>mp;
vector<string>Ans(10000);
vector<int>A(10000);
vector<int>B(10000);

void dfs(int v, int p = -1) {
	if (Check[v]) {
		return;
	}
	Check[v] = true;
	for (int e : to[v]) {
		if (p == e) {
			continue;
		}
		if (mp.count({ v,e })) {
			if (v == A[mp[{v, e}]]) {
				Ans[mp[{v, e}]] = "->";
			}
			else {
				Ans[mp[{v, e}]] = "<-";
			}
			mp.erase({ v,e });
			mp.erase({ e,v });
		}
		dfs(e, v);
	}
}

int main() {
	int N, M;
	cin >> N >> M;
	rep (i,M) {
		cin >> A[i] >> B[i];
		A[i]--;
		B[i]--;
	}
	vector<int>C(N);
	rep (i,N) {
		cin >> C[i];
	}
	rep(i, M) {
		if (C[A[i]] == C[B[i]]) {
			to[A[i]].push_back(B[i]);
			to[B[i]].push_back(A[i]);
			mp[{ A[i], B[i] }] = i;
			mp[{ B[i], A[i] }] = i;
			continue;
		}
		if (C[A[i]] > C[B[i]]) {
			Ans[i] = "->";
		}
		else {
			Ans[i] = "<-";
		}
	}
	rep(i, N) {
		if (Check[i]) {
			continue;
		}
		dfs(i);
	}
	rep(i, M) {
		cout << Ans[i] << endl;
	}
	return 0;
}


#define _USE_MATH_DEFIMES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007;
const int MOD2 = 998'244'353;
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

template<class T, class S> inline bool chmax(T &a, const S &b){
    if(a < b){
        a = b; return true;
    }
    return false;
}
template<class T, class S> inline bool chmin(T &a, const S &b){
    if(b < a){
        a = b; return true;
    }
    return false;
}

int main(){
    int N; std::cin >> N;
    std::string s, t; std::cin >> s;
    t = s;
    int cnt(0);
    std::vector<int> f(N, -1);
    for(int i(0); i < s.length(); ++i){
        if(s[i] == 'x' && i > 1){
            if(s[i-2] == 'f' && s[i-1] == 'o'){
                s = s.substr(0, i-2) + s.substr(i+1);
                i -= 3;
            }
        }
    }
    std::cout << s.length() << std::endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define en      '\n'
#define endl    '\n'
#define ll      long long signed
#define pb      push_back
#define append  push_back
#define all(v)  (v).begin(),(v).end()
#define FOR(i,a,b,k) for(int i=a; k>0?i<b:i>b; i+=k)
#define fori(a) for(int i=0; i<a; i++)
#define forj(a) for(int j=0; j<a; j++)
#define fork(a) for(int k=0; k<a; k++)
#define MOD     1000000007
#define MAX     1000010
#define mset(a,s,k) memset(a,k,s*sizeof(a[0]))
#define ff      first
#define ss      second
#define __      <<" "<<
#define _       <<en
#define int ll
ll pow_(ll a,ll e,ll m=MOD){ll r=1;while(e){if(e&1)r=r*a%m;a=a*a%m;e>>=1;}return r;}
int inv(ll a) {return (int)(pow_(a,MOD-2,MOD));}int add(ll a, ll b){return (a+b+MOD)%MOD;} int mul(ll a, ll b)
{return (MOD+a*b%MOD)%MOD;}int di(ll a, ll b){return mul(a,inv(b));}ll  ceil(ll a,ll b){return a/b+(a%b!=0);}
template<typename T1,typename T2>ostream&operator<<(ostream&O,pair<T1,T2>a){O<<"( ";O<<a.ff<<", "<<a.ss;O<<" )";return O;}
template<typename T>ostream&operator<<(ostream&O,vector<T>V){O<<"[ ";fori(V.size())O<<V[i]<<(i==V.size()-1?"":", ");O<<" ]";return O;}
template<typename T>ostream&operator<<(ostream&O,set<T>S){O<<"{ ";for(T i:S)O<<i<<", ";O<<" }";return O;}
template<typename T1,typename T2>ostream&operator<<(ostream&O,map<T1,T2>S){O<<"{ ";for(auto i:S)O<<i<<", ";O<<" }";return O;}
template<typename T=int>class print{public:vector<T>V;print(vector<T>v){V=v;cout<<" <"<<V<<"> ";}
print(T*x,int N){fori(N)V.push_back(x[i]);cout<<" <"<<V<<"> ";}friend ostream&operator<<(ostream&O,print p){return O;}};

#define vi vector<int>
#define tp pair<int,int>

int arr[MAX]; int N,M;
void reset();
vector<int> G[MAX];
int mi[MAX];

int dfs(int x){
    int &r=mi[x];
    if(r==INT_MIN){
        for(auto i: G[x]){
            r=max(r,dfs(i));
        }
    }
    return max(r,arr[x]);
}

int solve(){
    cin>>N>>M;
    reset();
    fori(N){ cin>>arr[i];}
    fori(M){
        int a,b;
        cin>>a>>b;
        G[a-1].push_back(b-1);
    }
    int res=INT_MIN;
    fori(N){
        dfs(i);// res=max(res, dfs(i,INT_MAX));
    }
    // cout<<print(mi,N) _;
    fori(N){
        if(mi[i]!=INT_MIN)
            res=max(res,mi[i]-arr[i]);
    }
    cout<<res;
    return 0;
}

void reset(){
    fori(N) {
        G[i].clear();
        mi[i]=INT_MIN;
    }

    // Clear Vectors, maps, sets
    // Set default values of arr
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t=1;
    while(t--){
        solve();
        // cout<<solve()<<en;
        // cout<<(solve()?"Yes":"No")<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

const int N = 210;

PII path[N];
int a[N];
int s[N];
bool st[N];

void print(int x, bool flag) {
    stack<int> sta;
    while(x != 0) {
        sta.push(path[x].second);
        x = path[x].first;
    }
    if (!flag)
    cout << sta.size() << ' ';
    else cout << sta.size() + 1 << ' ';
    while (sta.size()) {
        cout << sta.top() << ' ';
        sta.pop();
    }
}
int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i ++)   cin >> a[i];

    st[0] = 1;
    for (int i = 1; i <= n; i ++) {
        vector<int> v;
        for (int j = 0; j < 200; j ++) {
            if (st[j]) {
                if (s[(a[i] + j) % 200] > 0) {
                    cout << "Yes" << endl;
                    if ((a[i] + j) % 200 == 0) {
                        cout << 1 <<' ';
                        cout << path[(a[i] + j) % 200].second;
                    }
                    else print((a[i] + j) % 200, false);
                    cout << endl;
                    print(j, true);
                    cout << i;
                    return 0;
                }
                s[(a[i] + j) % 200] ++;
                v.push_back((a[i] + j) % 200);
                path[(a[i] + j) % 200] = {j, i};
            }
        }
        for (int i = 0; i < v.size(); i ++) st[v[i]] = 1;
    }
    cout << "No";
    return 0;
}

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

namespace tensor {
	template<typename T, int N, int...args>
	struct static_tensor : std::array<static_tensor<T, args...>, N> {
		static_tensor() : std::array<static_tensor<T, args...>, N>() {}

		void fill(const T &val) {
			for (int i = 0; i < N; i++) {
				(*this)[i].fill(val);
			}
		}
	};

	template<typename T, int N>
	struct static_tensor<T, N> : std::array<T, N> {
		static_tensor() : std::array<T, N>() {}
	};

	template<typename T, int D>
	struct dynamic_tensor : std::vector<dynamic_tensor<T, D - 1>> {
		dynamic_tensor() : std::vector<dynamic_tensor<T, D - 1>>() {}

		template<typename...args>
		dynamic_tensor(size_t n, args...A) : std::vector<dynamic_tensor<T, D - 1>>(n, dynamic_tensor<T, D - 1>(A...)) {}

		dynamic_tensor(const std::initializer_list<dynamic_tensor<T, D - 1>> &list) : std::vector<dynamic_tensor<T, D - 1>>(list) {}

		void fill(const T &val) {
			for (auto it = this->begin(); it != this->end(); it++) {
				it->fill(val);
			}
		}
	};

	template<typename T>
	struct dynamic_tensor<T, 1> : std::vector<T> {
		dynamic_tensor() : std::vector<T>() {}

		dynamic_tensor(size_t n, const T &val = T()) : std::vector<T>(n, val) {}

		dynamic_tensor(const std::initializer_list<T> &list) : std::vector<T>(list) {}

		void fill(const T &val = T()) {
			std::fill(this->begin(), this->end(), val);
		}
	};
}

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

	using tensor::dynamic_tensor;

	int n;
	cin >> n;

	vector<int> a(n);
	for (auto &x : a) cin >> x, x %= 200;

	dynamic_tensor<bool, 4> dp(n + 1, 200, 4, 2);
	//dp[pos][diff][mask][f]

	dynamic_tensor<int, 4> move(n + 1, 200, 4, 2);
	dynamic_tensor<tuple<int, int, int>, 4> back_track(n + 1, 200, 4, 2);

	dp[0][0][0][0] = true;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 200; j++) {
			for (int mask = 0; mask < 4; mask++) {
				for (int f = 0; f < 2; f++) {
					if (!dp[i][j][mask][f]) {
						continue;
					}
					//pick nothing
					dp[i + 1][j][mask][f] = true;
					move[i + 1][j][mask][f] = 0;
					back_track[i + 1][j][mask][f] = make_tuple(j, mask, f);

					//pick for b
					int new_j = (j + a[i]) % 200;
					dp[i + 1][new_j][mask | 1][1] = true;
					move[i + 1][new_j][mask | 1][1] = 1;
					back_track[i + 1][new_j][mask | 1][1] = make_tuple(j, mask, f);

					//pick for c
					new_j = (j + 200 - a[i]) % 200;
					dp[i + 1][new_j][mask | 2][1] = true;
					move[i + 1][new_j][mask | 2][1] = 2;
					back_track[i + 1][new_j][mask | 2][1] = make_tuple(j, mask, f);

					//pick for both
					dp[i + 1][j][mask | 3][f] = true;
					move[i + 1][j][mask | 3][f] = 3;
					back_track[i + 1][j][mask | 3][f] = make_tuple(j, mask, f);
				}
			}
		}
	}

	if (!dp[n][0][3][1]) {
		cout << "No\n";
		return 0;
	}

	vector<int> b, c;

	for (int i = n, j = 0, mask = 3, f = 1; i > 0; i--) {
		if (move[i][j][mask][f] == 1) {
			b.push_back(i);
		} else if (move[i][j][mask][f] == 2) {
			c.push_back(i);
		} else if (move[i][j][mask][f] == 3) {
			b.push_back(i);
			c.push_back(i);
		}
		tie(j, mask, f) = back_track[i][j][mask][f];
	}

	sort(b.begin(), b.end());
	sort(c.begin(), c.end());

	cout << "Yes\n";
	cout << b.size() << ' '; for (auto &x : b) cout << x << ' '; cout << '\n';
	cout << c.size() << ' '; for (auto &x : c) cout << x << ' '; cout << '\n';
	return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

int INF = 1e+15;
int n;
int x[17], y[17], z[17];
int dp[1 << 17][17];

int dist(int i, int j) {
	return abs(x[j] - x[i]) + abs(y[j] - y[i]) + max(0LL, z[j] - z[i]);
}

signed main() {
	int i, j, k;

	cin >> n;
	rep(i, n) cin >> x[i] >> y[i] >> z[i];

	rep(i, (1 << n)) rep(j, n) dp[i][j] = INF;

	dp[1][0] = 0;
	rep(i, (1 << n)) {
		rep(j, n) {
			rep(k, n) {
				dp[i | (1 << k)][k] = min(dp[i | (1 << k)][k], dp[i][j] + dist(j, k));
			}
		}
	}

	int ans = INF;
	rep(i, n) {
		ans = min(ans, dp[(1 << n) - 1][i] + dist(i, 0));
	}
	cout << ans << endl;
	return 0;
}

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

#define int long long
#define print(x) cout << "[" << #x << ": " << x << "]";
#define println(x) cout << "[" << #x << ": " << x << "]\n";
#define pb push_back
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define INF 1e18 + 5
#define MOD 1e9 + 7

void solve(){
    int n; cin >> n;
    string s; cin >> s;
    vector<char> rem;
    for(int i = 0; i < n; i++){
      rem.pb(s[i]);
      if(rem.size() > 2){
        int x = rem.size()-1;
        if(rem[x] == 'x' && rem[x-1] == 'o' && rem[x-2] == 'f'){
//          println(x)
          rem.pop_back();
          rem.pop_back();
          rem.pop_back();
        }
      }
    }
    cout << rem.size() << '\n';
	return;
}

int32_t main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);
	int tt = 1;
	while(tt--){
		solve();
		cout << '\n';
	}
	cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " s" << '\n';
}


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

///* input vector */
//template <typename T>
//istream& operator >>(istream& in, vector<T>& v) {
//    for (size_t i=0; i<v.size(); ++i) {
//        in >> v[i];
//    }
//    return in;
//}
///* output vector */
//template <typename T>
//ostream& operator <<(ostream& out, vector<T>& v) {
//    string sep = "";
//    for (size_t i=0; i<v.size(); ++i, sep=" ") {
//        out << sep << v[i];
//    }
//    return out;
//}

/* shortcuts */
#define all(v) begin(v),end(v)
#define rep(i,n) for(int i=0; i<n; ++i)
#define endl '\n'

/* data types shortened */
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;

int main()
{
    #define ONLINE_JUDGE
    #ifndef ONLINE_JUDGE
        freopen("Input.txt", "r", stdin);
        //freopen("Output.txt", "w", stdout);
        //freopen("Eroor.txt", "w", stderr);
    #endif // ONLINE_JUDGE

    int n, q; cin >> n >> q;
    vector<ull> a(n);
    rep(i,n) cin >> a[i];

    vector<ull> pre(n); // pre_sum: sum of nbr of included nbrs so far, index: zone
    rep(i,n) pre[i] = a[i]-i-1;

    while (q--) {
        ull k; cin >> k;
        int zone = lower_bound(all(pre), k) - pre.begin();
        ull ans;
        if (zone == 0) ans = k;
        else ans = a[zone-1]+(k-pre[zone-1]);
        cout << ans << endl;
    }

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,c,u;
	cin>>a>>c;
	for(int i=1;i<=a;i++)
	{
	cin>>u;
	if(u!=c)
	{
		cout<<u<<" ";
		}
	}
		return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(n);i++)
void chmax(ll& a, ll b) {if (b>a) a=b;}

int main() {
  int N;
  cin >> N;
  vector<int> a(N), b(N);
  rep(i,N) cin >> a[i];
  rep(i,N) cin >> b[i];
  ll ans = 0, maxa = 0;
  rep(i,N) {
    chmax(maxa, a[i]);
    chmax(ans, maxa*b[i]);
    cout << ans << endl;
  }
}

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;

int main() {

  long long N;
  cin >> N;

  vector<long long> A(N);
  map<long long,long long> mpA;

  rep(i,N) {
    cin >> A[i];
    mpA[A[i]]++;
  }

  vector<pair<long long,long long>> B(N);
  rep(i,N) {
    B[i].first = A[i];
    B[i].second = mpA[A[i]];
  }
  sort(B.begin(), B.end());

  long long ans = 0LL;
  ans = N * (N-1LL) / 2LL;

  rep(i,N) {
    if(i>0 && B[i].first==B[i-1].first) continue;
    else if(B[i].second>=2) {
      ans -= B[i].second * (B[i].second-1LL) / 2LL;
    }
  }

  cout << ans << endl;

}


#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <unordered_map>
#include <vector>

using namespace std;

#define MP make_pair
#define PB push_back
#define REP(i, L, R) for (int i = L; i < (R); ++i)
#define SZ(x) (int)x.size()

using ll = long long;
using ld = long double;
using pi = pair<int, int>;
using pl = pair<ll, ll>;

template <typename T>
bool ckmin(T& a, const T& b) {
  return b < a ? a = b, 1 : 0;
}
template <typename T>
bool ckmax(T& a, const T& b) {
  return a < b ? a = b, 1 : 0;
}

ll p[6] = {1, 10, 100, 1000, 10000, 100000};

ll score(const string& s, int d) {
  int f[10];
  fill(f, f + 10, 0);
  ++f[d];
  for (int i = 0; i < s.length() - 1; ++i) {
    f[s[i] - '0']++;
  }
  ll sum = 0;
  for (int i = 1; i <= 9; ++i) {
    sum += (ll)i * p[f[i]];
  }

  return sum;
}

void solve() {
  int k;
  string s, t;
  cin >> k;
  cin >> s;
  cin >> t;

  int f[10];
  fill(f, f + 10, 0);
  for (int i = 0; i < s.length() - 1; ++i) {
    f[s[i] - '0']++;
  }
  for (int i = 0; i < t.length() - 1; ++i) {
    f[t[i] - '0']++;
  }

  // map<pi, bool> w;
  unordered_map<int, bool> w;
  for (int i = 1; i <= 9; ++i) {
    for (int j = 1; j <= 9; ++j) {
      // (i,j) -> i*10+j
      w[i * 10 + j] = (score(s, i) > score(t, j));
    }
  }

  ll cnt = 0;
  for (int i = 1; i <= 9; ++i) {
    ll remi = k - f[i];
    if (remi <= 0) {
      continue;
    }
    for (int j = 1; j <= 9; ++j) {
      ll remj = k - f[j] - (i == j);
      if (remj <= 0) {
        continue;
      }
      if (w[i * 10 + j]) {
        cnt += remi * remj;
      }
    }
  }

  ld total = ((ld)9 * k - 8) * ((ld)9 * k - 9);
  cout << fixed << setprecision(14) << (ld)cnt / total << endl;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int T = 1;
  while (T--) {
    solve();
  }
  return 0;
}

#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i=0; i<(n); i++)
#define ALL(n) n.begin(), n.end()

int main(){
    ll a, b, k;
    cin >> a >> b >> k;

    // パスカルの三角形
    vector<vector<ll>> p(60, vector<ll>(60));
    p[0][0] = 1;

    for(int i=1; i<60; i++)for(int j=0; j<60; j++){
        if(j == 0) p[i][j] = p[i-1][j];
        else p[i][j] = p[i-1][j-1] + p[i-1][j];
    }

    /**
        rep(i,10){
            rep(j,10){
                if(p[i][j] == 0) break;
                else cout << p[i][j] << " ";
            }
            cout << endl;
        }
    **/

    string ans = "";

    // 先頭がaの時、何通りあるか
    for(int i=a+b; 0<a+b; i--){

        ll num = p[a+b-1][b];

        //cout << num << endl;

        // 次の文字がbのとき
        if(k > num){ // 次の文字がbのとき
            ans += 'b';
            k -= num;
            b--;
        }else{ // 次の文字がaのとき
            ans += 'a';
            a--;
        }

        if(a == 0){
            rep(j,b) ans += 'b';
            break;
        }else if(b == 0){
            rep(j,a) ans += 'a';
            break;
        }
    }

    cout << ans << endl;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#include <limits>
#include <stack>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
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(a > b){ a = b; return 1; } return 0; }
template<class T> inline int  sz(T &a) { return a.size(); }
using ll = long long; using ld = long double;
using pi = pair<int,int>; using pl = pair<ll,ll>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
const int inf = numeric_limits<int>::max();
const ll infll = numeric_limits<ll>::max();
int main()
{
  int n; cin >> n;
  vi a(2*n);
  rep(i,2*n) cin >> a[i];
  vector<pi> p(2*n);
  rep(i,2*n) p[i] = {a[i], i};
  sort(p.begin(),p.end());
  vi b(2*n, 0);
  rep(i,n) {
    b[p[i].second] = 1;
  }
  vector<char> res(2*n);
  stack<pi> sta;
  rep(i,2*n) {
    if(!sta.empty()) {
      if(sta.top().first != b[i]) {
        res[sta.top().second] = '(';
        res[i] = ')';
        sta.pop();
      }
      else {
        sta.push({b[i], i});
      }
    }
    else {
      sta.push({b[i], i});
    }
  }
  rep(i,2*n) cout << res[i];
  cout << "\n";
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
const ll INF = 1LL<<60;//1152921504606846976
const int mod = 1000000007;

vector<vector<ll>> G;
vector<bool> vis;
vector<ll> dist;
ll dmax, farnode;
void dfs(ll r, ll d){
    vis[r]=true;
    dist[r]=d;
    if(d>dmax){
        dmax=d;
        farnode=r;
    }
    for(ll c:G[r])if(!vis[c])dfs(c,d+1);

}

ll u,v;
vector<bool> st_has_v;
void dfs_findv(ll r){
    vis[r]=true;
    if(r==v)st_has_v[r]=true;
    for(ll c:G[r])if(!vis[c]){
        dfs_findv(c);
        if(st_has_v[c])st_has_v[r]=true;
    }
}

ll now;
vector<ll> label;
void dfs_labelling(ll r){
    vis[r]=true;
    label[r]=now;
    ll hasv = -1;
    for(ll c:G[r])if(!vis[c]){
        if(st_has_v[c]){hasv=c;continue;}
        now++;
        dfs_labelling(c);
        now++;
    }
    if(hasv!=-1){
        now++;
        dfs_labelling(hasv);
        now++;
    }

}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n; cin>>n;
    G.resize(n);

    rep(i,n-1){
        ll a,b;cin>>a>>b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    //直径と両端u,vを求める
    vis=vector<bool>(n,false);
    dist=vector<ll>(n,INF);
    dmax = 0;
    dfs(0,0);
    u = farnode;
    vis=vector<bool>(n,false);
    dist=vector<ll>(n,INF);
    dmax=0;
    dfs(u,0);
    v = farnode;
    ll R = dmax;
    //uからDFS、subtreeにvがあるか判定
    vis=vector<bool>(n,false);
    st_has_v = vector<bool>(n,false);
    dfs_findv(u);
    //uからDFS、vがあるsubtreeは最後に回す
    //貪欲にラベルをつけていく
    vis=vector<bool>(n,false);
    label=vector<ll>(n);
    now=1;
    dfs_labelling(u);

    for(ll x:label)cout<<x<<" ";

    return 0;
}


#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using pii = pair <int, int>;
using pll = pair <ll, ll>;

#define FIO() ios_base::sync_with_stdio(0);cin.tie(NULL);

const ll inf = 9e18;

int main() {
    FIO();

    string atc = "atcoder";

    int tc; cin >> tc;
    while (tc--) {
        string s; cin >> s;
        ll ans = inf;
        ll temp = 0;

        int m = min(atc.size(), s.size());
        int n = s.size();

        bool ok = true;
        for (int i = 0; i < m; i++) {
            if (s[i] > atc[i]) {
                ans = min(ans, temp);
                break;
            }

            for (int j = i + 1; j < n; j++) {
                if (s[j] > atc[i]) {
                    ans = min(ans, temp + j - i);
                    break;
                }
            }

            bool fnd = false;
            for (int j = i; j < n; j++) {
                if (s[j] != atc[i]) continue;

                fnd = true;
                while (s[i] != atc[i]) {
                    swap(s[j], s[j - 1]);
                    j--;
                    temp++;
                }

                break;
            }

            if (!fnd) {
                ok = false;
                break;
            }
        }

        if (ok and m < s.size()) ans = min(ans, temp);

        if (ans == inf) ans = -1;
        cout << ans << '\n';
    }
}

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

int main() {

  vector<int> cnt(10, 0);
  string s; cin >> s;
  for (auto c : s) {
    cnt[c - '0']++;
  }

  if (s.size() <= 5) {
    sort(ALL(s));
    do {
      int num = stoi(s);
      if (num % 8 == 0) {
        cout << "Yes" << endl;
        return 0;
      }
    } while (next_permutation(ALL(s)));

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

  for (int x = 104; x <= 999; x += 8) {
    vector<int> nums(10, 0);
    // cerr << "x = " << x << endl;
    int y = x;
    while (y) {
      // cerr << y % 10 << endl;
      nums[y % 10]++;
      y /= 10;
    }

    bool ok = true;
    for (int i = 0; i <= 9; i++) {
      if (cnt[i] < nums[i]) ok = false;
    }
    if (ok) {
      cerr << "x = " << x << endl;
      cout << "Yes" << endl;
      return 0;
    }
  }

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


#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define fore(i, a) for (auto &i : a)
using ll = long long;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
const ll INF = 1LL << 60;
const ll mod = 1E9 + 7;

ll gcd(ll a, ll b) {
  if (a < b) {
    ll temp = a;
    a = b;
    b = temp;
  }
  if (b == 0) return a;
  return gcd(b, a % b);
}

int main() {
  int N;
  cin >> N;
  vector<int> a = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47};
  vector<int> x(N);
  rep(i, N) cin >> x[i];
  ll ans = INF;
  for (int bit = 1; bit < (1 << 15); bit++) {
    ll temp = 1;
    rep(i, 15) {
      if (bit & (1 << i)) temp *= a[i];
    }
    rep(i, N) {
      if (gcd(temp, x[i]) == 1) {
        temp = INF;
        break;
      }
    }
    ans = min(temp, ans);
  }
  cout << ans << endl;
  return 0;
}

#include<bits/stdc++.h>
#define ll long long int
#define pi acos(-1)
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;

ll mod=1000000007;
bool sortBysec(pair<ll,ll>a,pair<ll,ll>b)
{
    return a.second>b.second;
}

bool prime[2000010];
vector<ll>vv;
void SieveOfEratosthenes(ll n)
{

    memset(prime, true, sizeof(prime));

    for (ll p=3; p*p<=n; p+=2)
    {

        if (prime[p] == true)
        {

            for (ll i=p*p; i<=n; i +=(2*p))
                prime[i] = false;
        }
    }

}

ll binExp(ll a,ll n)
{
    ll res=1;
    while(n)
    {
        if(n%2==1)
        {
            res=(res*a)%mod;
            n--;
        }
        else
        {
            a=(a*a)%mod;
            n=n/2;
        }
    }
    return res;
}

ll ncr(ll n,ll r)
{
    if(r>n-r)
    {
        r=n-r;
    }
    ll i,j,ans=1;
    for(i=n,j=1; j<=r; j++,i--)
    {
        ans=((ans*i)%mod);
        ans=(ans*binExp(j,mod-2))%mod;
    }
    return ans;
}

ll power(ll n,ll m)
{
    ll ans=1;
    while(m)
    {
        ans*=n;
        m--;
    }
    return ans;
}

ll digsum(ll n)
{
    ll sum=0;
    while(n)
    {
        sum+=n%10;
        n=n/10;
    }
    return sum;
}

ll fact(ll n)
{
    ll ans=1;
    for (ll i=1; i<=n; i++)
    {
        ans*=i;
    }
    return ans;
}
ll npr(ll n,ll r)
{
    ll ans=1;
    for(ll i=n,j=1; j<=r; j++,i--)
    {
        ans=((ans%mod)*(i%mod))%mod;
    }
    return ans;
}

int main()
{
    FAST();
    ll t=1,i,m,n,j,k,x,y,p,c,d,q,a,b;
    //cin>>t;
    while(t--)
    {
      cin>>n;
      vector<ll>v,u,w;

      for(i=0;i<n;i++)
      {
          cin>>k;
          v.push_back(k);
      }
    map<ll,ll>mp;

    for(i=2;i<=25;i++)
    {
        mp[i*2]=1;
    }
    for(i=3;i<=50;i+=2)
    {
        if(mp[i]==0)
        {

            for(j=i*i;j<=50;j+=2*i)
            {
                mp[j]=1;
            }
        }
    }
    for(i=2;i<=50;i++)
    {
        if(mp[i]==0)
        {
            u.push_back(i);
           // cout<<i<<" ";
        }
    }
   // cout<<endl;

       map<ll,ll>mcp;
       for(i=0;i<u.size();i++)
       {
           ll cc=w.size();
           for(j=0;j<cc;j++)
           {
               if(mcp[w[j]*u[i]]==0)
               {
               w.push_back(w[j]*u[i]);
               mcp[w[j]*u[i]]=1;
               }
           }
           if(mcp[u[i]]==0)
           {
           w.push_back(u[i]);
           mcp[u[i]]=1;

           }
       }
//
       sort(w.begin(),w.end());

     ll f,ans;
       for(i=0;i<w.size();i++)
       {
           f=0;
           for(j=0;j<v.size();j++)
           {
               if(__gcd(v[j],w[i])<=1)
               {
                   f=1;
                   break;
               }
               //cout<<__gcd(v[j],w[i])<<" ";
           }
          // cout<<endl;
           if(f==0)
           {
               ans=w[i];
               break;
           }
       }

       cout<<ans<<endl;
    }

    return 0;

}

/*

   ❀(◕‿◕)❀

 */


#include <iostream>
#include <vector>
//#include <string>
#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;

//#define MOD 1000000007
//#define MOD 998244353
//#define MAX 100100
//#define NIL -1
//#define INF 1000000000000000000
//const LL SEG_VAL = 1 << 19;

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

LL gcd(LL a, LL b){
    LL tmp;
    if(a<b){
        tmp = a;
        a = b;
        b = tmp;
    }
    tmp = a%b;
    while(tmp!=0){
        a = b;
        b = tmp;
        tmp = a%b;
    }

    return b;
}

int main(){
    LL t;
    cin >> t;
    vector<LL> n(t);
    vector<LL> s(t);
    vector<LL> k(t);
    for(LL i=0; i<t; i++){
        cin >> n[i] >> s[i] >> k[i];
    }

    for(LL i=0; i<t; i++){
        s[i]=n[i]-s[i];
        LL d=gcd(n[i], gcd(s[i], k[i]));
        n[i]/=d;
        s[i]/=d;
        k[i]/=d;
        if(gcd(k[i],n[i])!=1){
            cout << -1 << endl;
        }else{
            cout << (s[i]*modinv(k[i], n[i]))%n[i] << endl;
        }
    }

    return 0;
}

#include <bits/stdc++.h>

using namespace std;
const int INF = 1e9 + 10;
#define ll long long
#define lowbit(i) ((i) & -(i))

ll exgcd(ll a, ll b, ll &x, ll &y)
{
    if (!b)
    {
        x = 1, y = 0;
        return a;
    }
    ll gd = exgcd(b, a % b, y, x);
    y -= a / b * x;
    return gd;
}

void solve()
{
    ll N, S, K;
    cin >> N >> S >> K;

    if (S % __gcd(K, N) == 0)
    {
        ll x, y;
        exgcd(N,K, x, y);
        ll o=S / __gcd(K, N);
        x*=o,y*=o;
        N/=__gcd(K, N);
        y=-y;
        y=(y%N+N)%N;

        cout <<y<<endl;

    }
    else cout << -1 << endl;

}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T ;
    cin >>T;
    while (T--)
    {
        solve();

    }
}


#include <chrono>
#include <thread>
#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;
#define T top()
#define E end()
#define PS push
#define Q queue
#define PP pop()
#define L0 (LL)0
#define V vector
#define ST stack
#define FI first
#define MAX 4e18
#define MIN -MAX
#define DQ deque
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define SE second
#define DL double
#define G getline
#define IN insert
#define endl "\n"
#define EM empty()
#define cnn continue
#define MD 1000000007
#define PSB push_back
#define PI acos(-1.00)
#define PPB pop_back()
#define PSF push_front
#define ub upper_bound
#define lb lower_bound
#define PPF pop_front()
#define CF cout.flush()
#define line cout<<endl
#define LL long long int
#define one cout<<1<<endl
#define zer cout<<0<<endl
#define PQ priority_queue
#define kth find_by_order
#define nil cout<<-1<<endl
#define N cout<<"NO"<<endl
#define NN cout<<"No"<<endl
#define Y cout<<"YES"<<endl
#define fndidx order_of_key
#define YY cout<<"Yes"<<endl
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#define MAU cout<<"Case "<<mau<<": "
#define SP(pre) fixed<<setprecision(pre)
#pragma GCC optimization ("unroll-loops")
#define MMAU cout<<"Case "<<mau<<":"<<endl
#define __lcm(A1,A2) (A1/(__gcd(A1,A2)))*A2
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout)
#define UOSMOY v.C;w.C;ww.C;uu.C;uo.C;vo.C;vu.C;ab.C;bc.C;cc.C;uuu.C;a.C;b.C;c.C;u.C
typedef tree<LL, null_type, less<LL>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define remembermeforcenturies using namespace std::chrono_literals;std::this_thread::sleep_for(-4611686018427387904ms);
V<LL>v,w,ab,bc;
set<LL>uo;
map<LL,LL>ww,cc,u;
V<pair<LL,LL> >uu,su;
map<LL,V<LL> >uuu;
map<pair<LL,LL>,LL> vo,vu;
map<LL,pair<LL,pair<LL,LL > > > vs;
priority_queue<LL,V<LL>,greater<LL> > moy;
LL dx[]= {-1,0,1,0,1,1,-1,-1};
LL dy[]= {0,1,0,-1,-1,1,1,-1};
LL dxx[]= {2,1,-1,-2,-2,-1,1,2};
LL dyy[]= {1,2,2,1,-1,-2,-2,-1};
LL dp[101][10001];
LL ar[10][10];
int main()
{
//  BRR;
//  file;
    FAST;
    char ch;
    string a,b,c;
    DL x,y,d,e,f,g,h;
    LL n,i,j,k,p,q,o,l,s,tt=1,m,t,z,aa,r=0;
//    cin>>tt;
    for(LL mau=1; mau<=tt; mau++)
    {
        UOSMOY;
        ordered_set os;
        remembermeforcenturies;
        cin>>n;
        k=0;
        l=0;
        for(i=1; ;i++)
        {
            l+=i;
            k++;
            if(l>=n)
            {
                cout<<k<<endl;
                break;
            }
        }

    }
    return 0;
    //IN
    //AL
}

/*************************************************************************
	> File Name: 1.cpp
	> Author: Knowledge_llz
	> Mail: 925538513@qq.com
	> Blog: https://blog.csdn.net/Pig_cfbsl
	> Created Time: 2020/10/11 22:45:26
 ************************************************************************/
#include<bits/stdc++.h>
#define For(i,a,b) for(register int i=(a);i<=(b);++i)
#define pb push_back
#define pr pair<int,int>
#define fi first
#define se second
#define LL long long
#define mk(a,b) make_pair(a,b)
using namespace std;
int read(){
	char x=getchar(); int u=0,fg=0;
	while(!isdigit(x)){ if(x=='-') fg=1; x=getchar(); }
	while(isdigit(x)){ u=(u<<3)+(u<<1)+(x^48); x=getchar(); }
	return fg?-u:u;
}
const int maxx=1e5+10;
int n,m,sum=0,cnt=0,mx,ans=1e9;
int w[10],tmp[10],s[10],dis[10],v[maxx],l[maxx];
int p[10]={0,1,2,3,4,5,6,7,8};
pr a[maxx];
bool cmp(pr x,pr y){
	if(x.fi!=y.fi) return x.fi<y.fi;
	return x.se>y.se;
}
int iso(int x){
	x=lower_bound(v+1,v+cnt+1,x)-v-1;
	return l[x];
}
int solve(){
	s[0]=0;
	For(i,1,n){ tmp[i]=w[p[i]]; s[i]=s[i-1]+tmp[i];  dis[i]=0;}
	For(i,2,n) For(j,1,i-1){
		dis[i]=max(dis[i],dis[j]+iso(s[i]-s[j-1]));
		if(dis[i]>=ans) return dis[i];
	}
	return dis[n];
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.in", "r", stdin);
	freopen("output.out", "w", stdout);
#endif
	int u1,u2;
	n=read(); m=read();
	For(i,1,n){ w[i]=read(); mx=max(w[i],mx);}
	For(i,1,m){
		u1=read(); u2=read();
		a[i]=mk(u2,u1);
		if(u2<mx){ printf("-1\n"); return 0; }
	}
	sort(a+1,a+m+1,cmp);
	v[++cnt]=a[1].fi; l[cnt]=a[1].se;
	For(i,2,m)
		if(a[i].se>l[cnt]){
			v[++cnt]=a[i].fi;
			l[cnt]=a[i].se;
		}
	do{
		ans=min(ans,solve());
	}while(next_permutation(p+1,p+n+1));
	printf("%d\n",ans);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
const ll mod = 1000000007;

int main() {
    int N; cin >> N;
    vector<bool> memo(222222, false);
    int ans = 0;
    rep(i, N) {
        int p; cin >> p;
        memo[p] = true;
        while(true){
            if(!memo[ans]){
                cout << ans << endl;
                break;
            }
            ans++;
        }
    }
    return 0;
}

#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<unordered_map>
using namespace std;

#define max(a,b) (((a) > (b)) ? (a) : (b))
#define min(a,b) (((a) < (b)) ? (a) : (b))

const double pi = acos(-1);
const int N = 2e5 + 100;
const int mod = 1e9 + 7;
typedef long long ll;
template<typename T>
inline void read(T &x) {
	x = 0;
	int  w = 1;
	char ch = 0;
	while (ch < '0' || ch > '9') {
		if (ch == '-') w = -1;
		ch = getchar();
	}
	while (ch >= '0' && ch <= '9') {
		x = (x << 1) + (x << 3) + (ch - 48);
		ch = getchar();
	}
	x *= w;
}

int p[N],a[N],t[N]{0}, x = 0;

void qwq() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; ++i){
		scanf("%d",&p[i]);
		t[p[i]] = 1;
		while(t[x]) x++;
		a[i] = x;
	}
	for(int i = 1; i <= n; ++i){
		printf("%d\n", a[i]);
	}
}

 int main() {
	int _ = 1;
	//read(_);
	while (_--) qwq();
	return 0;
}