#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define init(a,i) for(int k=0;k<(i);k++)(a)[k]=0
#define in(a,i) for(int k=0;k<(i);k++)cin>>(a)[k]
#define all(a)  (a).begin(),(a).end()
#define mod 998244353
#define inf 2147483647
#define range(x,a,b) (a)<=x&&x<=(b)
int main(){
	int n;
	string s;
	cin>>n>>s;
	int pair1=0,pair2=0,count=0;
	rep(i,n){
		pair1=0;
		pair2=0;
		for(int j=i;j<n;j++){
			switch(s[j]){
				case 'A':
				pair1++;
				break;
				case 'T':
				pair1--;
				break;
				case 'C':
				pair2++;
				break;
				case 'G':
				pair2--;
				break;
			}
			if(pair1==0&&pair2==0)count++;
		}
	}
	cout<<count;
	return 0;
}

#include<bits/stdc++.h>
#define pb emplace_back
#define AI(i) begin(i), end(i)
using namespace std;
using ll = long long;
template<class T>
bool chmax(T &val, T nv) { return val < nv ? (val = nv, true) : false; }
template<class T>
bool chmin(T &val, T nv) { return nv < val ? (val = nv, true) : false; }
#ifdef KEV
#define DE(args...) kout("[ " + string(#args) + " ] = ", args)
void kout() {cerr << endl;}
template<class T1, class ...T2>
void kout (T1 v, T2 ...e) { cerr << v << ' ', kout(e...); }
template<class T>
void debug(T L, T R) { while (L != R) cerr << *L << " \n"[next(L)==R], ++L; }
#else
#define DE(...) 0
#define debug(...) 0
#endif
const int MAX_N = 2010;
char w[MAX_N][MAX_N];
bool used[MAX_N];
int dis[MAX_N][MAX_N];
int n, m;
vector<pair<int,int>> ap[ MAX_N ];
int solve() {
	memset(dis, -1, sizeof(dis));
	queue<pair<int,int>> q;
	int x, y;
	for (int i = 1;i <= n;++i)
		for (int j = 1;j <= m;++j) {
			if (w[i][j] == 'S')
				q.emplace(i, j), x = i, y = j;
			if (w[i][j] <= 'z' && w[i][j] >= 'a')
				ap[ w[i][j] ].pb(i, j);
		}
	dis[x][y] = 0;
	while (q.size()) {
		auto [x, y] = q.front(); q.pop();
		//DE(x, y, dis[x][y]);
		int d = dis[x][y] + 1;
		auto update = [&](int x, int y) {
			if (x < 1 || y < 1 || x > n || y > m || dis[x][y] != -1 || w[x][y] == '#') return;
			dis[x][y] = d;
			q.emplace(x, y);
		};
		update(x+1, y), update(x-1, y), update(x, y-1), update(x, y+1);
		if (w[x][y] <= 'z' && w[x][y] >= 'a' && !used[ w[x][y] ]) {
			used[ w[x][y] ] = true;
			for (auto [a, b] : ap[w[x][y]])
				update(a, b);
		}
	}
	for (int i = 1;i <= n;++i)
		for (int j = 1;j <= m;++j)
			if (w[i][j] == 'G')
				return dis[i][j];
	assert(false);
}
int32_t main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n >> m;
	for (int i = 1;i <= n;++i)
		cin >> w[i] + 1;
	cout << solve() << '\n';
}


#include <bits/stdc++.h>
#define endl '\n'
#define fr first
#define sc second
#define all(v) v.begin(),v.end()
#define unq(v) sort( all(v) ); v.erase( unique( all(v) ), v.end() )
#define bout(x) cout << bitset<sizeof(x)*8>(x) << endl
#define mkp(a,b) make_pair(a,b)
#define gcd(a,b) __gcd(a,b)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using cpl = complex<ld>;
const ld pi = 3.14159265358979323846264338327950288;
const ld tau = 2 * pi;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, ddy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
const int nx[8] = {1, 2, 2, 1, -1, -2, -2, -1}, ny[8] = {-2, -1, 1, 2, 2, 1, -1, -2};

//#define DEBUG
typedef pair<int, bool> pib;

int arr[400020];
pii srt[400020];
bool add[400020];
stack<pib> st;
vector<int> v1, v2;

void Main(){
	int n; cin >> n;
	for (int i = 1; i <= 2*n; i++){
		cin >> arr[i];
		srt[i] = {i, arr[i]};
	}
	sort(srt+1, srt+2*n+1, [](pii a, pii b){
		return a.sc > b.sc;
	});
	for (int i = 1; i <= n; i++){
		add[ srt[i].fr ] = 1;
		//cout << srt[i].fr << ' ';
	}
	for (int i = 1; i <= 2*n; i++){
		if (st.empty()){ st.push({i, add[i]}); }
		else{
			if (st.top().sc != add[i]){
				v1.push_back(st.top().fr); v2.push_back(i);
				st.pop();
			}
			else{
				st.push({i, add[i]});
			}
		}
	}
	sort(all(v1)); sort(all(v2));
	int p1 = 0, p2 = 0;
	string s = "";
	for (int i = 1; i <= 2*n; i++){
		if (p1 == n){ s += ')'; p2 += 1; }
		else if (p2 == n){ s += '('; p1 += 1; }
		else if (v1[p1] == i){ s += '('; p1 += 1; }
		else{ s += ')'; p2 += 1; }
	}
	cout << s;
}

int main(){
#ifndef DEBUG
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#endif
	cout.setf(ios::fixed);
	cout.precision(0);
	Main();
}


//
// Created by zhujunchao on 2021/4/18.
//

#include <iostream>
#include <cstdio>
using namespace std;
int main(){
    int a, b;
    scanf("%d%d", &a, &b);
    for(int i = 1; i < min(a, b); i++){
        printf("%d %d ",i, -i);
    }
    int u = 0;
    if(a > b){
        for(int i = b; i <= a; i++){
            printf("%d ", i);
            u += i;
        }
        printf("%d ", -u);
    }
    else{
        for(int i = a; i <= b; i++){
            printf("%d ", -i);
            u += i;
        }
        printf("%d ", u);
    }
    printf("\n");
    return 0;
}

/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG
#endif
#include <stdio.h>
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip> //setprecision
#include <map> // map
#include <unordered_map> //unordered_map
#include <queue> // queue, priority_queue
#include <set> // set,multiset
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
#include <numeric> //accumulate,,,
#include <sstream>
#define endl "\n";
using namespace std;

using PLL = pair<long long,long long>;
typedef tuple<int,int,int> TUP;
using P = pair<int,int>;
const long long INF = 4000000000000000001;
const int inf = 1001001001;
const long long MOD = 1000000007;

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M, long long mod) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % mod, M / 2,mod);
    //When end-of-a bit is 1, times simple N.
    if (M & 1) res = (res * N) % mod;
    return res %= mod;
}
long long gcd(long long a, long long b) {
    if (b == 0) return a; else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a / gcd(a, b) * b ;
}
long long get_mod(long long res){
    if(res < 0) res += MOD;
    return res % MOD;
}

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

    long long N,M;cin >> N >> M;
    cout << mod_pow(10,N,M*M)/M << endl;
}


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

#define int long long

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

    int t, n;
    cin >> t >> n;

    int l = 1, r = 1e12;
    int ans = 0;
    while (l <= r) {
        int mid = (l + r) / 2;
        int price = mid * (100 + t) / 100;
        int count = price - mid;
        // cout << mid << ' ' << count << endl;
        if (count >= n)
            ans = mid, r = mid - 1;
        else
            l = mid + 1;
    }
    int price = ans * (100 + t) / 100;
    int count = price - ans;
    cout << price - 1 - (count - n) << '\n';

    return 0;
}

#include "bits/stdc++.h"
#include <chrono>
#include <random>
#define lli long long int
using namespace std;
#define mod 1000000007
#define mod1 998244353
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define INF 1000000000
#define common cout << "Case #" << w+1 << ": "
#define maxn 10010

void setIO(string name) {
	ios_base::sync_with_stdio(0); cin.tie(0);
	freopen((name+".in").c_str(),"r",stdin);
	freopen((name+".out").c_str(),"w",stdout);
}

template< typename T>
void PVecPrint(vector<T>&v)
{
    for(int i=0;i<(int)v.size();i++)
        cout << v[i].first << "," << v[i].second << ' ';
    cout << '\n';
}
template<class T>
void VecPrint(vector<T>&v)
{
    for(int i=0;i<v.size();i++)
        cout << v[i] << ' ';
    cout << '\n';
}
/*-------------------------------------------------------------------Code-----------------------------------------------------------------*/

int main()
{
    int t,n;
    cin >> t >> n;
    set<int>s;
    int p=0,cnt=0,req;
    for(int i=1;i<1000;i++)
    {
        int r=(i*t)%100,q=(i*t)/100;
        if(s.find(r)!=s.end())
        {
            req=i-1;
            break;
        }
        s.insert(r);
        if(p!=q)
        {
            ++cnt;
            p=q;
        }
    }
    // cout << cnt << ' ' << req << '\n';
    if(cnt>=n)
    {
        // cout << "enter\n";
        int r=n,p=0;
        for(int i=1;i<1000;i++)
        {
            int q=(i*t)/100;
            if(p!=q)
            {
                if(r==1)
                {
                    cout << i+q-1 << '\n';
                    break;
                }
                --r;
                p=q;
            }
        }
    }
    else
    {
        int q=n/cnt,r=n%cnt;
        if(r==0)
        {
            q-=1;
            r=cnt;
        }
        lli ev=req*1LL*q;
        // cout << ev << ' ' << r  << '\n';
        lli prev=(ev*t)/100;
        for(lli i=ev+1;i<ev+1000;i++)
        {
            lli val=i+(i*t)/100,a=(i*t)/100;
            if(a!=prev)
            {
                if(r==1)
                {
                    cout << val-1 << '\n';
                    break;
                }
                // cout << val-1 << '\n';
                --r;
                prev=a;
            }
        }
    }
}


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

template <int MOD_> struct modnum {
	static constexpr int MOD = MOD_;
	static_assert(MOD_ > 0, "MOD must be positive");

private:
	using ll = long long;

	int v;

	static int minv(int a, int m) {
		a %= m;
		assert(a);
		return a == 1 ? 1 : int(m - ll(minv(m, a)) * ll(m) / a);
	}

public:

	modnum() : v(0) {}
	modnum(ll v_) : v(int(v_ % MOD)) { if (v < 0) v += MOD; }
	explicit operator int() const { return v; }
	friend std::ostream& operator << (std::ostream& out, const modnum& n) { return out << int(n); }
	friend std::istream& operator >> (std::istream& in, modnum& n) { ll v_; in >> v_; n = modnum(v_); return in; }

	friend bool operator == (const modnum& a, const modnum& b) { return a.v == b.v; }
	friend bool operator != (const modnum& a, const modnum& b) { return a.v != b.v; }

	modnum inv() const {
		modnum res;
		res.v = minv(v, MOD);
		return res;
	}
	friend modnum inv(const modnum& m) { return m.inv(); }
	modnum neg() const {
		modnum res;
		res.v = v ? MOD-v : 0;
		return res;
	}
	friend modnum neg(const modnum& m) { return m.neg(); }

	modnum operator- () const {
		return neg();
	}
	modnum operator+ () const {
		return modnum(*this);
	}

	modnum& operator ++ () {
		v ++;
		if (v == MOD) v = 0;
		return *this;
	}
	modnum& operator -- () {
		if (v == 0) v = MOD;
		v --;
		return *this;
	}
	modnum& operator += (const modnum& o) {
		v += o.v;
		if (v >= MOD) v -= MOD;
		return *this;
	}
	modnum& operator -= (const modnum& o) {
		v -= o.v;
		if (v < 0) v += MOD;
		return *this;
	}
	modnum& operator *= (const modnum& o) {
		v = int(ll(v) * ll(o.v) % MOD);
		return *this;
	}
	modnum& operator /= (const modnum& o) {
		return *this *= o.inv();
	}

	friend modnum operator ++ (modnum& a, int) { modnum r = a; ++a; return r; }
	friend modnum operator -- (modnum& a, int) { modnum r = a; --a; return r; }
	friend modnum operator + (const modnum& a, const modnum& b) { return modnum(a) += b; }
	friend modnum operator - (const modnum& a, const modnum& b) { return modnum(a) -= b; }
	friend modnum operator * (const modnum& a, const modnum& b) { return modnum(a) *= b; }
	friend modnum operator / (const modnum& a, const modnum& b) { return modnum(a) /= b; }
};

template <typename T> T pow(T a, long long b) {
	assert(b >= 0);
	T r = 1; while (b) { if (b & 1) r *= a; b >>= 1; a *= a; } return r;
}

using num = modnum<998244353>;

vector<num> fact, ifact;

void init(){
	int N = 1100000;
	fact = {1};
	for(int i = 1; i < N; i++) fact.push_back(i * fact[i-1]);
	ifact.resize(N);
	ifact.back() = 1 / fact.back();
	for(int i = N - 1; i > 0; i--) ifact[i-1] = i * ifact[i];
}

num ncr(int n, int k){
	if(k < 0 || k > n) return 0;
	return fact[n] * ifact[k] * ifact[n-k];
}

int main(){
	ios_base::sync_with_stdio(false), cin.tie(nullptr);
	init();
	int n, m;
	cin >> n >> m;
	num ans = pow(num(m), n) * n;
	vector<num> r(m, 1);
	for(int len = 1; len < n; len++){
		num mult = pow(num(m), n-1-len) * (n-len);
		num v = 0;
		for(int a = 0; a < m; a++){
			v += r[a];
			r[a] *= a;
		}
		ans -= mult * v;
	}
	cout << ans << '\n';
}


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

int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

	int n;
	cin>>n;
	vi out;
	out.pb(6);
	out.pb(10);
	out.pb(15);
	loop(i,16,10001){
		if(out.size()==n)break;
		if(i%6==0||i%10==0||i%15==0)out.pb(i);
	}
	rep(i,n)rep(j,i)if(gcd(out[i],out[j])==1)assert(0);
	show1d(out);
}

#include <iostream>
using namespace std;

int main(int argc, char const *argv[])
{
	int n; cin >> n;
	cout << n-1 << "\n";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=513;
ll a[maxn][maxn];
ll ansa[maxn],ansb[maxn];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			scanf("%lld",&a[i][j]);
		}
	}
	for(int i=2;i<=n;i++){
		int yes=1,ms=a[i][1]-a[i-1][1];
		for(int j=2;j<=n;j++){
			if(a[i][j]-a[i-1][j]!=ms){
				yes=0;
				break;
			}
		}
		if(!yes){
			return printf("No"),0;
		}
	}
	ll mn=1e18;
	int pos=0;
	for(int i=1;i<=n;i++){
		if(a[i][1]<mn) mn=a[i][1],pos=i;
	}
	for(int i=1;i<=n;i++) ansa[i]=a[pos][i];
	for(int i=1;i<=n;i++) ansb[i]=a[i][1]-a[pos][1];
	printf("Yes\n");
	for(int i=1;i<=n;i++) printf("%lld ",ansb[i]);
	puts("");
	for(int i=1;i<=n;i++) printf("%lld ",ansa[i]);
}

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define per(i,a,n) for(int i=a;i>=n;i--)
#define pb push_back
#define mp make_pair
#define mem(a,b) memset(a,b,sizeof(a))
ll gcd(ll a,ll b){if(b==0)return a;else return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const int maxn=500;
ll a[maxn+5][maxn+5];
int main()
{

    int n;
    cin>>n;
    rep(i,0,n)
    {
        rep(j,0,n)
        cin>>a[i][j];
    }
    bool flag=1;
    ll dif[n];
    rep(i,0,n)
    {
        dif[i]=a[i][0]-a[(i+1)%n][0];
    }
    rep(i,0,n)
    {
        rep(j,0,n)
        {
            ll tmp=a[i][j]-a[(i+1)%n][j];
            if(tmp!=dif[i])
            {
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    rep(i,0,n)
    {
        dif[i]=a[0][i]-a[0][(i+1)%n];
    }
    rep(i,0,n)
    {
        rep(j,0,n)
        {
            ll tmp=a[j][i]-a[j][(i+1)%n];
            if(tmp!=dif[i])
            {
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    cout<<"Yes"<<endl;
    ll min=0x3f3f3f3f3f3f3f3f;
    int minum=0;
    ll ans1[maxn+5];
    ll ans2[maxn+5];
    rep(i,0,n)
    {
        if(a[i][0]<min)
        {
            minum=i;
            min=a[i][0];
        }
    }
    rep(i,0,n)
    {
        ans2[i]=a[minum][i];
    }
    rep(i,0,n)
    {
        ans1[i]=a[i][0]-ans2[0];
    }
    rep(i,0,n)
    {
        cout<<ans1[i]<<" ";

    }
    cout<<endl;
    rep(i,0,n)
    {
        cout<<ans2[i]<<" ";
    }
    cout<<endl;
    return 0;
}


#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> //Policy Based Data Structure
// using namespace __gnu_pbds;              //Policy Based Data Structure
using namespace std;
// typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> pbds; //Policy Based Data Structure
// #define gc              getchar_unlocked
// #define pqb             priority_queue<int>
// #define pqs             priority_queue<int, vi, greater<int> >
// #define mk(arr,n,type)  type *arr = new type[n]
#define fo(i,n)         for(i=0;i<n;i++)
#define Fo(i,k,n)       for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define int             long long
#define endl            '\n'
#define w(t)            int t; cin>>t; while(t--)
#define deb(x)          cout << #x << "=" << x << endl
#define deb2(x,y)       cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb              push_back
#define mp              make_pair
#define F               first
#define S               second
#define all(x)          x.begin(), x.end()
#define clr(x)          memset(x, 0, sizeof(x))
#define sortall(x)      sort(all(x))
#define tr(it,a)        for(auto it = a.begin(); it != a.end(); it++)
#define ps(x,y)         fixed<<setprecision(y)<<x
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define PI              3.1415926535897932384626
#define inf             1e18
// mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());  //Random Shuffler
typedef pair<int, int>   pii;
typedef vector<int>     vi;
typedef vector<pii>     vpii;
typedef vector<vi>      vvi;
typedef map<int, int>    mii;
int mpow(int base, int exp);
void ipgraph(int m);
void dfs(int u, int par);
const int mod = 1000000007;
// const int N = 3e5, M = N;
// vi g[N];
//=======================

void sol()
{
	int n, i;
	cin >> n;
	std::vector<int> v;
	v.pb(1);
	for (int i = 2; i * i <= n; i++)
	{
		if (n % i == 0)
		{

			v.pb(i);
			if (i * i != n)
				v.pb(n / i);

		}
	}
	if (n != 1)
		v.pb(n);
	int k = v.size();
	sort(v.begin(), v.end());
	for (i = 0; i < k; i++)
		cout << v[i] << '\n';

}

int32_t main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	sol();

	return 0;
}

int mpow(int base, int exp) {
	base %= mod;
	int result = 1;
	while (exp > 0) {
		if (exp & 1) result = (result * base) % mod;
		base = (base * base) % mod;
		exp >>= 1;
	}
	return result;
}

// void ipgraph(int n, int m){
//     int i, u, v;
//     while(m--){
//         cin>>u>>v;
//         g[u-1].pb(v-1);
//         g[v-1].pb(u-1);
//     }
// }
//
// void dfs(int u, int par){
//     for(int v:g[u]){
//         if (v == par) continue;
//         dfs(v, u);
//     }
// }

#include <bits/stdc++.h>
#define loop(n) for(ll i=0;i<n;i++)
#define loopj(n) for(ll j=0;j<n;j++)
#define loopR(i,a,b,c) for(ll i=a;i>=b;i-=c)
#define rng(i,a,b,c) for(ll i = a; i<b;i+=c)
#define loop2(i,a,b) for(long long i = a; i>=b;i--)
#define loop3(j,a,b) for(int j = a; j<b;j++)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ll long long
#define ld long double
#define SET set<ll>
#define pb push_back
#define mp make_pair
#define gc getchar_unlocked
#define in ll n;cin>>n;

ll mod=pow(10,9)+7;
using namespace std;
//--------------------------\\
//code once think twice

ll gcd(ll a,ll b)
{
	if(b==0)
	return a;

	return gcd(b,a%b);
}

void go()
{
 ll n,w;

 cin>>n;

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

 sort(a,a+n);
 ll ans=0;
 loop(n)
 {
	post-=a[i];
	ans+=abs(post-(a[i]*(n-(i+1))));
 }
 cout<<ans;

}

int main()
{

int t;

fast;
//cin>>t;

//loop(t)
go();
}


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

#define ll long long
#define forin(in ,n) for(ll i=0; i<n; i++) cin>>in[i]
#define forout(out) for(ll i=0; i<(ll)out.size(); i++) cout<<out[i]<<endl
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep_up(i, a, n) for (ll i = a; i < n; ++i)
#define rep_down(i, a, n) for (ll i = a; i >= n; --i)
#define P pair<ll, ll>

#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define vvvll vector<vector<vector<ll>>>
#define vvll vector<vector<ll>>
#define vll vector<ll>
#define pqll priority_queue<ll>
#define pqllg priority_queue<ll, vector<ll>, greater<ll>>

constexpr ll INF = (1ll << 60);
constexpr ll mod = 1000000007;
//constexpr ll mod = 998244353;
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
void pt(T val) {
    cout << val << "\n";
}
template <typename T>
void pt_vll(vector<T> &v) {
    ll vs = v.size();
    rep(i, vs) {
        cout << v[i];

        if (i == vs - 1)
            cout << "\n";
        else
            cout << " ";
    }
}
ll mypow(ll a, ll n) {
    ll ret = 1;
    if(n==0) return 1;
    if(a==0) return 0;
    rep(i, n) {
        if (ret > (ll)(9e18 + 10) / a) return -1;
        ret *= a;
    }
    return ret;
}
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

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

struct UnionFind {
    vector<ll> par,size;

    UnionFind(ll N) : par(N) { //最初はすべてが根であるとして初期化
        size.resize(N,1);
        for(ll i=0;i<N;i++) par[i] = i;
    }

    ll root(ll x){ //データxの木の根を再帰で得る
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(ll x, ll y){ //xとyの木を併合
        ll rx = root(x);
        ll ry = root(y);
        if(rx == ry) return; //同じ木にあるときはそのまま
        if(size[rx]>size[ry]){
            par[ry]=rx;
            size[rx] += size[ry];
        }else{
            par[rx] = ry;
            size[ry] += size[rx];
        }
        return;
    }

    bool same(ll x, ll y){ //2つのデータx,yが属する木が同じならtrue
        ll rx = root(x);
        ll ry = root(y);
        return rx == ry;
    }

    ll treesize(ll x){return size[root(x)];}
};

int main() {
    ll a,b,c,n,m,t=0,x,y,q,k,ans=0;
    cin>>a>>b>>c;
    if(a*a+b*b<c*c) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    //cout<<ans<<endl;
}

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

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


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

int main() {
	ios_base::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL);
	string N;
	getline(cin, N);
	string Nr = N;
	reverse(Nr.begin(), Nr.end());
	//cout << N << " "<< Nr << "\n";
	int i = 0;
	while (Nr[i] == '0') {
		i++;
	}
	//cout << i;
	int chk = 1;
	for (int j = 0; i < Nr.length(); i++, j++) {
		if (Nr[i] != N[j]) {
			chk = 0;
			break;
		}
	}
	if (chk) cout << "Yes";
	else cout << "No";
}


#include<stdio.h>
int n,x,mx; long long s,t;
int main() {
	scanf("%d",&n);
	for (int i=1; i<=n; ++i)
		scanf("%d",&x),s+=x,t+=s,mx<x&&(mx=x),
		printf("%lld\n",t+1ll*i*mx);
	return 0;
}

#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <numeric>
#include <algorithm>
using namespace std;
#define rep(i,n)  for(int i=0 ; i<(n) ; ++i)
typedef long long ll;
typedef pair<int,int> p;
const int INF = 1001001001;

int main(){
  ll N;
  cin >> N;
  ll A[N];
  rep(i,N) cin >> A[i];

  //最大値をiに足したら、次はそのiが最大値になる
  //答えはk*a1+(k-1)*a2+...a_k + k*a_max。
  //dpと、dpの和を記録していく
  ll dp[N],sum[N],MAX;
  dp[0] = A[0];
  sum[0] = dp[0];
  MAX = A[0];
  cout << sum[0]*2 << endl;
  for(int i=1 ; i<N ; ++i){
    MAX = max(MAX,A[i]);
    dp[i] = dp[i-1] + A[i];
    sum[i] = sum[i-1] + dp[i];
    cout << sum[i] + (i+1)*MAX << endl;
  }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define all(c) c.begin(),c.end()
#define sz(x) int(x.size())
#define ar array
typedef long long ll ;
typedef vector<int> vi;
#define mod 1000000007
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll exp(ll x,ll y){
  x%=mod;
  ll res=1;
  while(y){
    if(y&1)
    res=res*x%mod;
    x=x*x%mod;
    y>>=1;
  }
  return res;
}
ll fact(ll n){
  ll res=1;
  for(ll i=2;i<=n;++i)
  (res*=i)%=mod;
  return res;
}
bool isprime(ll n){
  if(n<=1) return 0;
  for(ll i=2;i*i<=n;++i)
  if(n%i==0) return 0;
  return 1;
}

int main()
{
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
ll k,n,m;
cin>>k>>n>>m;
vector<ll>v(k);
for(int i=0;i<k;++i) cin>>v[i];
using ld=long double;
ld l=0,r=1;
for(int _=1;_<=150;++_){
  ld mid=(l+r)/2;
  ll up=0,dn=0;
  for(int i=0;i<k;++i){
  ll mx=0,mn=0;
  mx=(ll)((((ld)(m*v[i]))/n+(mid*(ld)m)));
  mn=(ll)(ceil(((ld)(m*v[i]))/n-(mid*(ld)m)));
  if(mn<0) mn=0;
  if(mx<0) mx=-mod;
  up+=mx;
  dn+=mn;
  }
  if(up>=m&&dn<=m) r=mid;
  else l=mid;
}
 vector<ll>ans(k);
ll req=m;
  for(int i=0;i<k;++i){
  ll mx=0,mn=0;
  mx=(ll)((((ld)(m*v[i]))/n+r*(ld)m));
  mn=(ll)(ceil(((ld)(m*v[i]))/n-r*(ld)m));
  if(mn<0) mn=0;
  req-=mn;
  ans[i]=mn;
  }
    for(int i=0;i<k;++i){
  ll mx=0,mn=0;
  mx=(ll)((((ld)(m*v[i]))/n+r*(ld)m));
  mn=(ll)(ceil(((ld)(m*v[i]))/n-r*(ld)m));
  if(mn<0) mn=0;
  ll p=min(req,mx-ans[i]);
  ans[i]+=p;
  req-=p;
  }
  for(auto c:ans) cout<<c<<" ";
return 0;
}

//#include <atcoder/all>
//using namespace atcoder;
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPR(i, n) for(int i=n-1; i>=0; i--)
#define FOR(i, m, n) for(int i=m; i<n; i++)
#define ALL(v) v.begin(), v.end()
#define bit(n) (1LL<<(n))
#define FIX(d) fixed << setprecision(d)
using P = pair<int, int>;
using LP = pair<ll, ll>;
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; }
const int INF = 1e9;
const ll LINF = (1LL<<60);
const double EPS = 1e-10;

unsigned int xor128(){
  static unsigned int x=123456789,y=362436069,z=521288629,w=88675123;
  unsigned int t = (x^(x<<11));
  x=y; y=z; z=w;
  return( w=(w^(w>>19))^(t^(t>>8)) );
}

int n;
int cx[200], cy[200], r[200];
int a[200], b[200], c[200], d[200];

ll score(){
  double sc = 0.0;
  REP(i,n){
    int area = (c[i]-a[i]) * (d[i]-b[i]);
    double tmp = 1.0 - (double)min(area,r[i])/max(area,r[i]);
    sc += 1.0 - tmp*tmp;
  }
  sc *= 1e9;
  sc /= n;
  return (ll)round(sc);
}

void init(){
  REP(i,n){
    a[i] = cx[i];
    b[i] = cy[i];
    c[i] = cx[i]+1;
    d[i] = cy[i]+1;
  }
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n;
  REP(i,n) cin >> cx[i] >> cy[i] >> r[i];

  int ti = clock();
  init();
  ll mx = score();
  //cout << mx << endl;
  vector<bool> full(n, false);
  while(clock() - ti < 495 * CLOCKS_PER_SEC / 100){
    REP(loop, 300){
      int ind = xor128() % n;
      if(full[ind]) continue;
      int xy = xor128() % 2;
      bool minus = false, plus = false;
      if(xy==0){
        REP(i,n){
          if(i==ind) continue;
          if(max(a[i],a[ind]-1)<min(c[i],c[ind]) && max(b[i],b[ind])<min(d[i],d[ind])){
            minus = true;
          }
          if(max(a[i],a[ind])<min(c[i],c[ind]+1) && max(b[i],b[ind])<min(d[i],d[ind])){
            plus = true;
          }
        }

        if(c[ind]<10000 && !plus){
          c[ind]++;
          if(!chmax(mx, score())) c[ind]--;
        }else if(a[ind]>0 && !minus){
          a[ind]--;
          if(!chmax(mx, score())) a[ind]++;
        }
      }else{
        REP(i,n){
          if(i==ind) continue;
          if(max(a[i],a[ind])<min(c[i],c[ind]) && max(b[i],b[ind]-1)<min(d[i],d[ind])){
            minus = true;
          }
          if(max(a[i],a[ind])<min(c[i],c[ind]) && max(b[i],b[ind])<min(d[i],d[ind]+1)){
            plus = true;
          }
        }
        if(d[ind]<10000 && !plus){
          d[ind]++;
          if(!chmax(mx, score())) d[ind]--;
        }else if(b[ind]>0 && !minus){
          b[ind]--;
          if(!chmax(mx, score())) b[ind]++;
        }
      }

      bool xp = false, xm = false;
      bool yp = false, ym = false;
      REP(i,n){
        if(i==ind) continue;
        if(max(a[i],a[ind]-1)<min(c[i],c[ind]) && max(b[i],b[ind])<min(d[i],d[ind])){
          xm = true;
        }
        if(max(a[i],a[ind])<min(c[i],c[ind]+1) && max(b[i],b[ind])<min(d[i],d[ind])){
          xp = true;
        }
        if(max(a[i],a[ind])<min(c[i],c[ind]) && max(b[i],b[ind]-1)<min(d[i],d[ind])){
          ym = true;
        }
        if(max(a[i],a[ind])<min(c[i],c[ind]) && max(b[i],b[ind])<min(d[i],d[ind]+1)){
          yp = true;
        }
      }
      if(xp&xm&yp&ym) full[ind] = true;

    }
    //cout << mx << endl;
  }
  //cout << mx << endl;
  REP(i,n) cout << a[i] << " " << b[i] << " " << c[i] << " " << d[i] << '\n';
  return 0;
}


#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define int ll
#define pii pair<int,int>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;
const double pi=acos(-1.0);
const double eps=1e-8;
const int INF=0x3f3f3f3f;
const int MAXN=1e6+10;
const int mod=1e9+7;
int quickPower(int a, int b)
{
    int ans = 1;
    while(b)
    {
        if(b & 1)
        {
            ans = ans*a;
        }
        a=a*a;
        b >>= 1;
    }
    return ans;
}

void solve()
{
    int n;
    cin>>n;
    int ans=0;
    for(int i=1;i<=MAXN;++i)
    {
        int tmp=i;
        int sum=0;
        while(tmp)
        {
            sum++;
            tmp/=10;
        }
        int flag=i*quickPower(10,sum)+i;
        if(flag<=n) ans++;
        else break;
        /*cout<<flag<<endl;*/
    }
    cout<<ans;
}
signed main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int _=1;
    /*cin>>_;*/
    for(int i=1; i<=_; ++i)
    {
        solve();
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define irep(n) for (int i=0; i < (n); ++i)
#define irepf1(n) for (int i=1; i <= (n); ++i)
#define jrep(n) for (int j=0; j < (n); ++j)
#define jrepf1(n) for (int j=1; j <= (n); ++j)
#define krep(n) for (int k=0; k < (n); ++k)
#define krepf1(n) for (int k=1; k <= (n); ++k)
#define PI 3.14159265358979323846264338327950288
#define mod 1000000007
//fixed << setprecision(10) <<

int main() {
  int N;
  cin >>N;
  vector<ll> VA(N);
  vector<ll> VMax(N);
  vector<ll> VB(N);
  ll A;
  cin >>A;
  VA[0]=A,VMax[0]=A;
  irep (N-1) {
    cin >>VA[i+1];
    VMax[i+1]=max(VMax[i],VA[i+1]);
  }
  irep (N) cin >>VB[i];
  ll Max=0;
  irep (N) {
    Max=max(Max,VMax[i]*VB[i]);
    cout<<Max<<endl;
  }
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define sz(v) (int)v.size()
#define all(v) v.begin(), v.end()
void dbg_out() { cerr << "\b\b]\n"; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T){ cerr << H << ", "; dbg_out(T...);}
#define watch(...) cerr << "[" << #__VA_ARGS__ << "]: [", dbg_out(__VA_ARGS__)

/****************************** CODE IS HERE ***********************************/

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

    int n, m; cin >> n >> m;
    vector <int> A(n*m);
    for (int &i: A) cin >> i;
    int mn = *min_element(all(A));
    ll ans = 0;
    for (int i: A) {
        ans += i - mn;
    }
    cout << ans;

    return 0;
}

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

#define int long long int
#define double long double
#define pb push_back
#define fi first
#define se second
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pii>
#define pqi priority_queue<int>
#define test int tcase; cin>>tcase; for(int tc = 1; tc <= tcase; tc++)
#define inp(a,n,f) int a[n+f];for(int hh=f;hh<n+f;hh++)cin>>a[hh];
#define printdecimal(k) cout<<fixed<<setprecision(k);
#define mem(a,k) memset(a,k,sizeof(a))
#define ub upper_bound
#define lb lower_bound
#define mii map<int,int>
#define all(v) v.begin(),v.end()
#define mod (int)(1e9+7)
#define inf LLONG_MAX
int exp(int x,int y){int res=1;x=x%mod;while(y>0){if(y&1)res=(res*x)%mod;y=y>>1;x=(x*x)%mod;}return res;}
int modinv(int x){return exp(x,mod-2);}
int add(int a,int b){a%=mod,b%=mod;a=((a+b)%mod+mod)%mod;return a;}
int sub(int a,int b){a=((a-b)%mod+mod)%mod;return a;}
int mul(int a,int b){a%=mod,b%=mod;a=((a*b)%mod+mod)%mod;return a;}

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

    int n,m;
    cin>>n>>m;
    int mn=inf;
    int a[n][m];
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
            cin>>a[i][j],mn=min(mn,a[i][j]);
    int ans=0;
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
            ans+=a[i][j]-mn;
    cout<<ans;
    return 0;
}


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

#define f first
#define s second
#define pb push_back
#define ar array
#define all(x) x.begin(), x.end()
#define siz(x) (int) x.size()
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)
#define FOR(i, a, b) for(auto i=(a); i<(b); i++)
#define ROF(i, a, b) for(auto i=(b)-1; i>=(a); i--)
#define F0R(i, n) FOR(i, 0, n)
#define R0F(i, n) ROF(i, 0, n)

using ll=long long;
using ld=long double;
using pii=pair<int, int>;
using pll=pair<ll, ll>;
using vi=vector<int>;
using vl=vector<ll>;
using vpii=vector<pii>;

template<class T> bool ckmin(T&a, const T&b) {return b<a?a=b,1:0;}
template<class T> bool ckmax(T&a, const T&b) {return b>a?a=b,1:0;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int mxN=1001;
const int MOD=998244353;
const ll infLL=1e18;
const ld eps=1e-6;

template<int mod> struct mint {
	int v; explicit operator int() const{return v;}
	mint() {v=0;}
	mint(ll _v) { v =int((-mod< _v&&_v<mod)?_v:_v%mod);
		if(v < 0) v+=mod;}
	friend bool operator==(const mint& a, const mint& b){
		return a.v==b.v;}
	friend bool operator!=(const mint& a, const mint& b){
		return !(a==b);}
	friend bool operator<(const mint& a, const mint& b){
		return a.v<b.v;}
	mint& operator+=(const mint& m) {
		if((v+=m.v)>=mod) v-=mod;
		return *this;}
	mint& operator-=(const mint& m) {
		if((v-=m.v)<0) v+=mod;
		return *this;}
	mint& operator*=(const mint& m){
		v=int((ll)v*m.v%mod); return *this;}
	mint& operator/=(const mint& m) {return (*this)*=inv(m);}
	friend mint pow(mint a, ll p) {
		mint ans = 1; assert(p >= 0);
		for (;p;p/=2,a*=a) if(p&1) ans*=a;
		return ans;}
	friend mint inv(const mint& a){assert(a.v!=0);
		return pow(a,mod-2);}
	mint operator-() const{return mint(-v);}
	friend mint operator+(mint a, const mint& b) {return a+=b;}
	friend mint operator-(mint a, const mint& b) {return a-=b;}
	friend mint operator*(mint a, const mint& b) {return a*=b;}
	friend mint operator/(mint a, const mint& b) {return a/=b;}
};

using mi=mint<MOD>;

vector<mi> invs, fac, ifac;
void genFac(int SZ=mxN) {
	invs.resize(SZ), fac.resize(SZ), ifac.resize(SZ); vi Invs(SZ);
	Invs[1]=1; invs[1]=fac[0]=ifac[0]=1;
	FOR(i,2,SZ) Invs[i] = int(MOD-(ll)MOD/i*Invs[MOD%i]%MOD), invs[i]=mi(Invs[i]);
	FOR(i,1,SZ) {
		fac[i]=fac[i-1]*i;
		ifac[i]=ifac[i-1]*invs[i];
	}
}

mi choose(int n, int k){
	if(k>n) return 0;
	return fac[n]*ifac[n-k]*ifac[k];
}

int n, m;
string a[mxN];
vpii dist[mxN];
mi ans=1;

int main(){
	cin.tie(0)->sync_with_stdio(0);
	cin >> n >> m;
	F0R(i, n) cin >> a[i];
	F0R(i, n){
		F0R(j, m){
			dist[i+j].pb({i, j});
		}
	}
	F0R(i, n+m-1){
		int cntA=0, cntB=0, M=siz(dist[i]);
		for(auto [x, y]:dist[i]){
			cntA+=a[x][y]=='B';
			cntB+=a[x][y]=='R';
		}
		if(cntA>0&&cntB>0){
			cout << "0\n"; return 0;
		}
		if(cntA==0&&cntB==0){
			ans*=2;
		}
	}
	cout << ans.v << "\n";
	return 0;
}

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<math.h>
#include <algorithm>
#include <iomanip>
#include <string>
#include <functional>
using namespace std;

unsigned long long g2(unsigned long long N) {
	int* ar = new int[(int)log10(N)+1];
	unsigned long long a = 0;

	for (int i = 0; i <= (int)log10(N); i++) {
		ar[i] = (int)(N / pow(10, i)) % 10;
	}

	sort(ar, ar + (int)log10(N) + 1, greater<>());

	for (int i = 0; i < (int)log10(N) + 1; i++) {
		a += ar[i] * pow(10, i);
	}

	return a;
}
unsigned long long g1(unsigned long long N) {
	int* ar = new int[(int)log10(N) + 1];
	unsigned long long a = 0;
	for (int i = 0; i <= (int)log10(N); i++) {
		ar[i] = (int)(N / pow(10, i)) % 10;
	}

	sort(ar, ar + (int)log10(N) + 1);
	for (int i = 0; i < (int)log10(N) + 1; i++) {
		a += ar[i] * pow(10, i);
	}
	return a;
}
int main() {
	unsigned long long N, K,a;

	cin >> N >> K;
	a = N;
	for (int i = 0; i < K; i++) {
		//cout << g1(a) << " " << g2(a) << endl;
		if (!a) break;
		a = g1(a) - g2(a);

	}

	cout << a;
	return 0;
}


#include <map>
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
const ll lim=1000000000LL*1000000000LL;

map<ll,pii> mp;

int n,m;
ll a[100],b[100];

int main()
{
	a[n=0]=b[m=0]=1;
	while(a[n]*3<=lim)
	{
		++n;
		a[n]=a[n-1]*3;
	}
	while(b[m]*5<=lim)
	{
		++m;
		b[m]=b[m-1]*5;
	}

	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			mp[a[i]+b[j]]=pii(i,j);

	ll x;
	scanf("%lld",&x);
	if(mp.find(x)!=mp.end())
		printf("%d %d",mp[x].first,mp[x].second);
	else
		printf("-1");
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;

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

    int n;
    cin >> n;
    double ans = 0;
    for(int i = 1; i < n; i++){
        ans += 1.0/i;
    }
    ans *= n;
    cout << fixed << setprecision(10) << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(),v.end()
#define MP make_pair
#define MT make_tuple
typedef int64_t ll;
#define PA pair<ll,ll>
#define TU tuple<ll,ll,ll>
#define vi vector<ll>
#define vii vector<vector<ll> >
#define rep(i,n) for(ll (i)=0; (i)<(ll)(n); (i)++)
#define rep2(i,m,n) for(ll (i)=(m); (i)<(ll)(n); (i)++)
const ll INF = 1ll<<60;
const ll INF2 = 1ll<<32;
const ll MOD = 998244353;

void cycle(vi &v,ll state, vector<bool> &b,ll &pts) {
  ll ser = state;
  set<ll> s;
  while(!b.at(ser)) {
    s.insert(ser);
    b.at(ser) = true;
    ser = v.at(ser);
  }
  if(s.count(ser)) pts++;
}

int main() {
  ll n;
  cin >>n;
  vi v(n);
  rep(i,n) {
    cin >>v.at(i);
    v.at(i)--;
  }

  vector<bool> b(n,false);
  ll pts =0;

  rep(i,n) {
    cycle(v,i,b,pts);
  }

  ll ans =1;

  rep(i,pts) {
    ans *= 2;
    ans %= MOD;
  }
  ans--;
  ans %= MOD;

  cout <<ans <<endl;
}

using namespace std;
#include <bits/stdc++.h>
const int N=105,mo=998244353;
typedef long long ll;
int n,sum;
int w[N];
int f[N*N][N];
ll fac[N];
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;++i)
		scanf("%d",&w[i]),sum+=w[i];
	if (sum&1){
		printf("0\n");
		return 0;
	}
	sum/=2;
	f[0][0]=1;
	for (int i=1;i<=n;++i)
		for (int s=sum;s>=w[i];--s)
			for (int c=1;c<=i;++c)
				(f[s][c]+=f[s-w[i]][c-1])%=mo;
	fac[0]=1;
	for (int i=1;i<=n;++i)
		fac[i]=fac[i-1]*i%mo;
	ll ans=0;
	for (int c=0;c<=n;++c)
		ans=(ans+f[sum][c]*fac[c]%mo*fac[n-c])%mo;
	printf("%lld\n",ans);
	return 0;
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"

int main(){

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	int n =0 , m = 0;
	cin >> n >> m ;
	if(min(m , n ) + 3 > max(m,n ) ){
		cout <<"Yes" <<endl;}
	else
		cout << "No" <<endl;

return 0;}

#include <iostream>
#include <algorithm>
#include <vector>
//#include <string>
//#include <set>
#include <map>
//#include <math.h>
//#include <queue>
//#include <tuple>
//#include <iomanip>
//#include <numeric>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i,n) for (int i=0;i<(int)(n);i++)
//const ll INF = numeric_limits<ll>::max()/4;
int main () {
    map<int, vector<int>> pos;
    int N, M;
    cin >> N >> M;
    rep(i,N) {
        int a;
        cin >> a;
        pos[a].push_back(i);
    }
    rep(i,N+1) {
        int l = -1;
        for(auto r: pos[i]) {
            if (r-l-1 >= M) {cout << i << endl; return 0;}
            l = r;
        }
        if (N-l-1 >= M) {cout << i << endl; return 0;}
    }
    return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define all(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef unsigned long long int ull ;

const int MOD=1e9+7;
const char nl = '\n';

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
   	int n ;
  	ull ans = 0 ;
  	cin >> n ;
  	while(n--){
      	ull a , b ;
      	cin >> a >> b ;
      	ans += ( (b*(b+1) - a*(a+1 ) ) / 2 + a ) ;
    }
  	cout << ans ;
    return 0;
}

/**
  *  Author: dhruv_gheewala
  *  Problem: C - Swappable
  *  Date:   19.06.2021
  *  Time:   17:37:56
**/

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

#ifndef DEBUG

#define fundri 108
#define debug(...) 1729
#define endl '\n'

#endif

#define int int64_t

typedef pair<int, int> pii;
typedef vector<int> vi;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int rnd(int l = 0, int r = INT_MAX) {return uniform_int_distribution<int>(l, r)(rng);}

bool in_range(int x, int l, int r) {return l <= x && x <= r;}
template<typename H, typename ...T>void inp(H &head) {cin >> head;}
template<typename H, typename ...T>void inp(H &head, T &...tail) {cin >> head;inp(tail...);}
template<typename T>inline istream &operator >>(istream &in, vector<T> &a) {for(T &x : a)in >> x; return in;}
template<typename T, typename U>inline istream &operator >>(istream &in, pair<T, U> &a) {in >> a.first >> a.second; return in;}

// Multi-Dimension Vector
// Usage: vec<n, data-type> dp(dimention-1, dimention-2, ..., dimention-n, default = data-type())
template<int D, typename T> struct vec : public vector<vec<D - 1, T>> {
    static_assert(D >= 1, "Vector dimensions must be greater than zero !!");
    template<typename... Args>
    vec(int n = 0, Args... args) : vector<vec<D - 1, T>>(n, vec<D - 1, T>(args...)){}
};

template<typename T> struct vec<1, T> : public vector<T> {vec(int n = 0, T val = T()) : vector<T>(n, val){}};

const int inf = 1e15;
const bool testcases = false;

const bool ready = []() -> bool {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

#ifdef DHRUV_GHEEWALA
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif

    return true;
}();

void solve(int tc);
int32_t main(int32_t argc, char **argv) {
    int TC = 1;
    if(testcases) cin >> TC;

    // Pre-Processing goes here...
    for(int tc = 1; tc <= TC; ++tc) {
        solve(tc);
        fundri;
    }
    exit(0);
}

void solve(int tc) {
    int n;
    cin >> n;

    vector<int> a(n);
    cin >> a;

    int ans = 0;
    map<int, int> mp;
    for(int i = 0; i < n; i++) {
        mp[a[i]]++;
        ans += (i + 1 - mp[a[i]]);
    }
    cout << ans << endl;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int j,n;
    cin >> n;
    set<int>ans;
    ans.insert(10);
    ans.insert(15);
    for(j=6; j<=1e4  &&  (int)ans.size() < n; j+=6)ans.insert(j);
    for(j=10; j<=1e4  &&  (int)ans.size() < n; j+=10)ans.insert(j);
    for(j=15; j<=1e4  &&  (int)ans.size() < n; j+=15)ans.insert(j);
    for(int it : ans)cout << it << ' ';
    return 0;
}

#include<iostream>
using namespace std;
int main(){
  int L;
  cin >> L;
  L--;
  int64_t ans=1;
  for(int i=1;i<=11;i++){
    ans=ans*(L-i+1);
    ans=ans/i;
  }
  cout<<ans;
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
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; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<62) - 1;

template <typename Monoid>
struct SegTree {
    using F = function<Monoid(Monoid, Monoid)>;
    const F f;
    const Monoid unit;

    int n;
    vector<Monoid> dat;

    SegTree(int n_, const F f_, const Monoid unit_) : f(f_), unit(unit_) {
        n = 1;
        while (n < n_) n *= 2;
        // 1-indexed
        dat.assign(2 * n, unit);
    }

    void set(int i, const Monoid &x) {
        dat[i + n] = x;
    }
    void build() {
        for (int i = n - 1; i >= 0; --i) {
            dat[i] = f(dat[2 * i], dat[2 * i + 1]);
        }
    }

    void update(int i, const Monoid &x){
        i += n;
        dat[i] = x;
        while (i >>= 1){
            dat[i] = f(dat[2 * i], dat[2 * i + 1]);
        }
    }

    // [a, b) 非再帰
    Monoid query(int a, int b) {
        Monoid l = unit, r = unit;
        for (a += n, b += n; a < b; a >>= 1, b >>= 1) {
            if (a & 1) l = f(l, dat[a++]);
            if (b & 1) r = f(dat[--b], r);
        }
        return f(l, r);
    }

    inline Monoid operator[] (int i){
        return dat[i + n];
    }
};
// set(i, v)した後にbuild()でO(n)
// 区間和 : SegTree<int> seg(n, [](int a, int b){ return a + b; }, 0);
// 区間min : SegTree<int> seg(n, [](int a, int b) {return min(a, b); }, INF);

int main(){
    int n, m, k;
    cin >> n >> m >> k;
    vector<int> a(k);
    int modoru[100010] = {};
    for (int i = 0; i < k; ++i) {
        cin >> a[i];
        modoru[a[i]] = 1;
    }

    int cnt = 0;
    for (int i = 0; i <= n; ++i) {
        if (modoru[i]) cnt++;
        else cnt = 0;
        if (cnt >= m) {
            cout << -1 << endl;
            return 0;
        }
    }

    SegTree<double> seg(n + m + 10, [](double a, double b){ return a + b; }, 0);
    SegTree<double> seg2(n + m + 10, [](double a, double b){ return a + b; }, 0);
    for (int i = n-1; i >= 0; --i) {
        double a = seg.query(i + 1, i + m + 1) / m + 1.0;
        double b = seg2.query(i + 1, i + m + 1) / m;

        if (modoru[i]) {
            seg2.update(i, 1.0);
        } else {
            seg.update(i, a);
            seg2.update(i, b);
        }
    }

    // x = seg[0] + seg2[0] * x
    cout << fixed << setprecision(15) << seg[0] / (1 - seg2[0]) << endl;
}

//#pragma GCC optimize(2)
#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
#define DEBUG
#define INF 0x3f3f3f3f3f3f3f3f
#define mod 1000000007
#define PI 3.14159265358979323846
#define Base 23333333
//#define set unordered_set
//#define map unordered_map
#define int long long
#define LL long long
#define NO	cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define Yes cout<<"Yes"<<endl
#define mst(x) memset(x,0,sizeof(x))
#define debug(x) cout<<"DEBUG "<<#x<<" : "<<x<<endl

#define _up(x) ceil(x)
#define _down(x) floor(x)

#define range(x,y) 1

//#define int unsigned long long
using namespace std;
//#define scanf scanf_s
//#define max(a,b) ((a) > (b) ? (a) : (b))
//#define min(a,b) ((a) < (b) ? (a) : (b))
inline int gcd(int a, int b) { return b > 0 ? gcd(b, a%b) : a; }
inline int lcm(int a, int b) { return a * b / gcd(a, b); }
inline int qpow(int a, int n) { int ans = 1;	while (n) { if (n & 1) { ans *= a; }a *= a; n >>= 1; }return ans; }
inline int _qpow(int a, int n) { int ans = 1; while (n) { if (n & 1) { ans *= a % mod;	ans %= mod; }a *= a; a %= mod; n >>= 1; }return ans % mod; }

/*
#define read() _read()
#define cout fout
#define cin fin
ifstream fin("in.txt");fstream fout("out.txt");
int _read() {	int tmp;	fin >> tmp;	return tmp;}
*/
inline int read() { int x = 0, f = 1;	char ch = getchar();	while (ch<'0' || ch>'9') { if (ch == '-') { f = -1; }		ch = getchar(); }	while (ch >= '0'&&ch <= '9') { x = 10 * x + ch - '0';		ch = getchar(); }	return x * f; }

signed main()
{
	int v = read(), t = read(), s = read(), d = read();
	int st = v * t, ed = v * s;
	if (d > ed || d < st)Yes;
	else No;
	return 0;
}


#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include<cstdio>
#include<functional>
#include <bitset>
#include <iomanip>
#include <cctype>
#include <list>
#include <cassert>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define ll long long
#define repi(i,a,b) for(ll i=a;i<b;++i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

using namespace std;
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; }
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;
using vvv = vector<vector<vector<ll>>>;
using vv = vector<vector<ll>>;
using vec = vector<ll>;
using P = pair<ll, ll>;

int main(void){
    ll n; cin >> n;
    vec al(n), bl(n), cl(n);
    rep(i, n) cin >> al[i];
    rep(i, n) cin >> bl[i];
    rep(i, n) cin >> cl[i];
    map<ll, ll> amp;
    map<ll, ll> bmp;

    rep(i, n){
        amp[al[i]]++;
    }

    rep(i, n){
        bmp[bl[cl[i] - 1]]++;
    }

    ll ans = 0;
    for(auto item : amp){
        ans += bmp[item.first] * item.second;
    }
    cout << ans << endl;
}

#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define indexed_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
//find_by_order = returns pointer to element at that pos
//order_of_key = returns pos of the given element
#define indexed_multiset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define all(x)  (x).begin(),(x).end()
#define mem1(a)  memset(a,-1,sizeof(a))
#define mem0(a)  memset(a,0,sizeof(a))
#define int long long
#define endl "\n"
typedef vector<int> vi;
typedef pair<int,int> pi;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define rep(i,a,b) for (int i = a; i <b; i++)
#define MOD 1000000007
#define boost
#define debug1(x) cout<<#x<<" "<<x<<endl;
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
template<typename T1,typename T2>istream& operator>>(istream& in,pair<T1,T2> &a){in>>a.F>>a.S;return in;}
template<typename T1,typename T2>ostream& operator<<(ostream& out,pair<T1,T2> a){out<<a.F<<" "<<a.S;return out;}
template<class _T>inline void read(_T &_a)
{
    bool f=0; char _c=getchar(); _a=0;
    while(_c<'0'||_c>'9'){ if(_c=='-') f=1; _c=getchar(); }
    while(_c>='0'&&_c<='9'){ _a=(_a<<3)+(_a<<1)-'0'+_c; _c=getchar(); }
    if(f) _a=-_a;
}
int pw(int a,int b,int p){
    if(b==0)return 1;
    int t=pw(a,b/2,p);
    if(b%2)return (((a*t)%p)*t)%p;
    else return ((t*t)%p);
}

const long long INF=1e18;
int T=1;
int n;
vi a;

bool good(int x)
{

    rep(i,0,n)
    {
        if(__gcd(x,a[i])==1)
        return false;
    }
    return true;
}
vector<int> pdivs;
void solve2(int x) {
	for(int i=2; i*i <= x; i++) {
		if(x % i == 0) {
			pdivs.push_back(i);
			while(x % i==0) x /= i;
		}
	}
	if(x > 1) pdivs.push_back(x);
}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  /*   cin>>T; */
      while(T--)
   {

       cin>>n;
    a.resize(n);
    int ans=INF;
       rep(i,0,n)
       cin>>a[i];
       vi primes = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47};
       rep(i,0,1LL<<15)
       {
           int x=1;
           rep(j,0,15)
           {
               if(i&(1LL<<j))
               x=x*primes[j];
           }
           bool res = good(x);
           if(res)
           {
               ans=min(ans,x);
           }
       }
       cout<<ans<<endl;

   }

	// you should actually read the stuff at the bottom

/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* DON'T GET STUCK ON ONE APPROACH
*/
return 0;
}


#include <bits/stdc++.h>
#define int long long int
using namespace std;
int power(int x, int y, int p)
{
    int res = 1;     // Initialize result

    x = x % p; // Update x if it is more than or
                // equal to p

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}
signed main(){
    int n , m;
    cin>>n>>m;
    int ans = (power(10 , n , m*m ) - power(10 , n , m ) +m*m )%(m*m );
    ans/= m;
    cout<<ans;
}

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

int main() {
  int A, B;
  cin >> A >> B;
  int C = A + B;

  if(C >= 15 && B >= 8){
    cout << "1" << endl;
  }
  else if(C >=10 && B >= 3){
    cout << "2" << endl;
  }
  else if(C >= 3){
    cout << "3" << endl;
  }
  else{
    cout << "4" << endl;
  }
}


#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
char IO;
int rd(){
	int num=0;bool f=0;
	while(IO=getchar(),IO<48||IO>57)if(IO=='-')f=1;
	do num=(num<<1)+(num<<3)+(IO^48);
	while(IO=getchar(),IO>=48&&IO<=57);
	return f?-num:num;
}
ll A,B,C,D;
int main(){
	A=rd(),B=rd(),C=rd(),D=rd();
	if(C*D<=B){cout<<-1;return 0;}
	cout<<(A-1)/(C*D-B)+1;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;

int n,tp;
char s[N],st[N];

int main() {
#ifdef LOCAL
	freopen("a.in","r",stdin);
	freopen("a.out","w",stdout);
#endif
	ios::sync_with_stdio(0);cin.tie(0);
	cin>>n>>(s+1);
	for(int i=1;i<=n;i++) {
		st[++tp]=s[i];
		if(st[tp-2]=='f'&&st[tp-1]=='o'&&st[tp]=='x') tp-=3;
	}
	cout<<tp;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int32_t main(){
    IOS

    string s,t;
    cin>>s>>t;
    if(s[0]=='Y'){
        t[0] = t[0]-'a'+'A';
    }
    cout<<t[0]<<endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;
ll MOD=1000000007;
int main(){
 ll a,b;
  cin>>a>>b;
  ll d=b-a;
  ll ans=1;
  rep2(i,1,d+1){
    if(a%i==0&&i*(a/i+1)<=b&&i>ans) ans=i;
 else if(a%i!=0&&a<=i*(a/i+1)&&i*(a/i+2)<=b&&i>ans) ans=i;
  }
  cout<<ans;
return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ar array
#define ll long long

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

int n, m, a[MAX_N], mx[MAX_N];
vector<int> adj[MAX_N];

void solve() {
    cin >> n >> m;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 0; i < m; i++) {
        int u, v; cin >> u >> v;
        adj[u].push_back(v);
    }
    int ans = -INF;
    for (int u = n; u > 0; u--) {
        if (adj[u].empty()) {
            mx[u] = a[u];
            continue;
        }
        for (int v : adj[u]) mx[u] = max(mx[u], mx[v]);
        ans = max(ans, mx[u] - a[u]);
        mx[u] = max(mx[u], a[u]);
    }
    cout << ans << "\n";
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int tc = 1;
    // cin >> tc;
    for (int t = 1; t <= tc; t++) {
        // cout << "Case #" << t  << ": ";
        solve();
    }
}

#include"bits/stdc++.h"
using namespace std;
#define ll long long
#define ul unsigned long long
#define ui unsigned int
#define ri register int
#define pb push_back
#define mp make_pair
char p[30]={'0','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
inline ll rd(){
	ll x=0,flag=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-') flag=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+(ch^48);ch=getchar();}
	return x*flag;
}
#define N 100010
int wl,x,y,head[N],a[22][22],dp[132010][19],dis[N],c[22],vis[N],k,n,m,q[N],l,r;
struct node{
	int nxt,to;
}star[N<<1];
inline void add(int from,int to){
	wl++;
	star[wl].to=to;
	star[wl].nxt=head[from];
	head[from]=wl;
}
inline void bfs(int x){
    dis[x]=0;l=1,r=0;
    q[++r]=x;
    while(l<=r){
        int u=q[l++];
        for(ri i=head[u];i;i=star[i].nxt){
            int v=star[i].to;
            if(dis[v]!=0x3f3f3f3f) continue;
            dis[v]=dis[u]+1;q[++r]=v;
        }
    }
}
int main()
{
	n=rd(),m=rd();
	for(ri i=1;i<=m;++i) x=rd(),y=rd(),add(x,y),add(y,x);
	k=rd();
	for(ri i=1;i<=k;++i) c[i]=rd();
	for(ri i=1;i<=k;++i){
        memset(dis,0x3f,sizeof(dis));bfs(c[i]);
        for(ri j=i+1;j<=k;++j) a[i][j]=a[j][i]=dis[c[j]];
    }
    memset(dp,0x3f,sizeof(dp));
    for(ri i=1;i<=k;++i) dp[(1<<(i-1))][i]=1;
    for(ri s=0;s<(1<<k);++s){
        for(ri i=1;i<=k;++i){
            if((s&(1<<(i-1)))==0) continue;
            for(ri j=1;j<=k;++j){
                if(s&(1<<(j-1))) continue;
                dp[s^(1<<(j-1))][j]=min(dp[s^(1<<(j-1))][j],dp[s][i]+a[i][j]);
            }
        }
    }
    int ans=0x3f3f3f3f;
    for(ri i=1;i<=k;++i) ans=min(ans,dp[(1<<k)-1][i]);
    if(ans==0x3f3f3f3f) puts("-1");
    else
    cout<<ans;
    return 0;
}


/*
我的心脏怦怦跳，监管者就在附近
name:
Algorithm:
writer:Lxs(cdx)
place:
nothing is impossible
*/
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
#include<string>
#include<iostream>
#include<cmath>
#include<set>
#include<stack>
#include<queue>
#include<unistd.h>
#include<stdio.h>
#include<cstring>
#define random(a,b) (rand()%(b-a+1)+a)
using namespace std;
bool prime(int x){
	 int i;
	 if(x<2) return 0;
	 for(i=2;i*i<=x;i++){
		if(x%i==0){return 0;}
	 }
	 return 1;
}
bool flag[19999990];
int _prime[19999990];
void get_prime(int maxn)
{
    int i,j;
    for(i=2;i<=maxn;i++)
        if(!flag[i])
        {
            _prime[++_prime[0]]=i;
            for(j=i*i;j<=maxn;j+=i)
                flag[j]=true;
        }
}
long long _do[400001],n_do[400001];
long long aoki[1000000],ta[1000000];
int main()
{
	long long n;
	cin>>n;
	long long i;
	long long ao=0;
	for(i=0;i<n;i++){
		cin>>aoki[i]>>ta[i];
		_do[i]=aoki[i]+ta[i];
		n_do[i]=aoki[i];
		ao-=n_do[i];
		_do[i]=_do[i]+n_do[i];
	}
	sort(_do+0,_do+n);
	long long g=0;
	for(i=n-1;i>=0;i--){
		if(ao<=0){
			ao+=_do[i];
			g++;
		}
		else{
			break;
		}
	}
	if(ao>0) cout<<g<<endl;
	return 0;
}

// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization("unroll-loops")

#include "bits/stdc++.h"
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define endl '\n'
#define F first
#define S second
#define IO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define cf ll testcases;cin>>testcases;while(testcases--)
#define prn(x) if(x) cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define minel(x) (*min_element(all(x)))
#define maxel(x) (*max_element(all(x)))
#define cou dbg=1;cout
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pi;
typedef vector<ll> vi;
typedef vector<ld> vd;
typedef vector<pi> vp;
ll dbg=0;
template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p);
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v);
template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p);
template<typename A> istream& operator>>(istream& cin, vector<A> &v);
int dx[] = {-1, -1, -1,  0, 0,  1, 1, 1};
int dy[] = {-1,  0,  1, -1, 1, -1, 0, 1};

void solve(){
    ll n;
    cin>>n;
    vp arr(n);
    ll sum=0;
    for(ll i=0;i<n;i++){
        ll a,b;
        cin>>a>>b;
        arr[i]={2*a+b,a};
        sum+=a;
    }
    sort(all(arr),greater<pair<ll,ll>>());
    ll ans=0;
    ll sum2=0;
    for(auto i:arr){
        if(sum2>sum) break;
        sum2+=i.F-i.S;
        sum-=i.S;
        ans++;
    }
    cout<<ans<<endl;
}

int main(){
    IO;
    // cf
    solve();
    return 0;
}

template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) {
    if(dbg){dbg=0;
        return cout << "(" << p.F << ", " << p.S << ")";
    }else{
        return cout<<p.F<<' '<<p.S;
    }
        }
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) {
    if(dbg){dbg=0;
        cout << "["; for(ll i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "]";
    }else{
        for(ll i=0;i<v.size()-1;i++) cout<<v[i]<<' ';
        return cout<<v[v.size()-1];
    }
}
template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p) {
   cin >> p.first;
   return cin >> p.second;
}
template<typename A> istream& operator>>(istream& cin, vector<A> &v) {
   for(ll i=0;i<v.size()-1;i++) cin>>v[i];
   return cin >> v[v.size()-1];
}


#include <bits/stdc++.h>

#define fo(i, x, y) for (int i = (x); i <= (y); ++i)
#define fd(i, x, y) for (int i = (x); i >= (y); --i)
using namespace std;

typedef long long ll;

const int maxn = 1e6 + 5, lim = 1e6;

int l, r, tot;
int pri[maxn], v[maxn], cnt[maxn];
vector<int> fac[maxn], s[maxn];

int getint()
{
	char ch;
	int res = 0, p;
	while (!isdigit(ch = getchar()) && ch != '-');
	p = ch == '-'? ch = getchar(), -1 : 1;
	while (isdigit(ch))
		res = res * 10 + ch - '0', ch = getchar();
	return res * p;
}

int cal(int x)
{
	int sz = s[x].size(), allset = (1 << sz) - 1;
	int res = 0;
	fo(i, 1, allset)
	{
		int p = 1, ss = 0;
		fo(j, 0, sz - 1)
			if ((i >> j) & 1) p *= s[x][j], ss++;
		if (ss & 1) res += cnt[p];
		else res -= cnt[p];
	}
	return res;
}

void upd(int x)
{
	int sz = s[x].size(), allset = (1 << sz) - 1;
	fo(i, 1, allset)
	{
		int p = 1;
		fo(j, 0, sz - 1)
			if ((i >> j) & 1) p *= s[x][j];
		cnt[p]++;
	}
}

int main()
{
	//int st = clock();
	//freopen("t.in", "r", stdin);
	fo(i, 1, lim)
		fo(j, 1, lim / i)
			fac[i * j].push_back(i);
	fo(i, 2, lim)
	{
		if (!v[i]) v[i] = i, s[i].push_back(i), pri[++tot] = i;
		fo(j, 1, tot)
		{
			if (pri[j] > v[i] || pri[j] > lim / i) break;
			v[i * pri[j]] = pri[j];
			s[i * pri[j]] = s[i];
			if (pri[j] != v[i]) s[i * pri[j]].push_back(pri[j]);
		}
	}
	/*fo(i, 2, lim)
	{
		int x = i;
		while (x > 1)
		{
			int t = v[x];
			s[i].push_back(t);
			while (x > 1 && !(x % t)) x /= t;
		}
	}*/
	cin >> l >> r;
	if (l == 1) l++;
	ll ans = 0;
	fo(i, l, r)
	{
		upd(i);
		ans += cal(i);
		int cnt = fac[i].end() - lower_bound(fac[i].begin(), fac[i].end(), l);
		ans -= cnt;
	}
	ans <<= 1;
	cout << ans << endl;
	return 0;
}

#include <iostream>
#include <vector>
#include <cmath>
#include <ostream>
#include <list>
#include <map>
#include <algorithm>
#include <climits>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <bitset>
#include <cstring>
#include <deque>
#include <set>
#include <stack>
#include <queue>
#include <chrono>
#include <deque>
#include <string>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define ll long long
#define mod 1000000007
#define cbit __builtin_popcountll
#define pl pair<long, long>
#define pqp priority_queue<pl>
#define mkp make_pair
#define vl vector<ll>
#define vvl vector<vl >
#define pb push_back
#define inf 10000000
#define all(v) v.begin(), v.end()

long long gcd(long long int a, long long int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
long long lcm(ll a, ll b)
{
    return (a / gcd(a, b)) * b;
}

ll mod_power(ll a,ll b)
{
    if(b==0)
    {
        return 1;
    }
    ll temp=mod_power(a,b/2);
    temp%=mod;
    temp*=temp;
    temp%=mod;
    if(b%2==1)
    {
        temp*=a;
        temp%=mod;
    }
    return temp;
}
struct compare {
    bool operator()(const pair<ll,ll > &a,const pair<ll,ll > &b)
    {
        return a.first>b.first;
    }
};

bool comp(const pair<ll,ll > &a,const pair<ll,ll > &b)
{
    if(a.first==b.first)
    {
        return a.second<b.second;
    }
    return a.first<b.first;
}
vl mb(1e6+5,0);
ll calmb(ll n,vl& div)
{
    ll cnt=0;
    while(n>1)
    {
        ll k=0;
        ll d=div[n];
        while(n%d==0)
        {
            n/=d;
            k++;
            if(k>1)
            {
                return 0;
            }
        }
        cnt++;
    }
    if(cnt%2)
    {
        return -1;
    }
    return 1;
}
void seive()
{
    mb[1]=0;
    vl div(1e6+5,0);
    for(ll i=2;i<1e6+5;i++)
    {
        if(div[i]==0)
        {
            for(ll j=i;j<1e6+5;j+=i)
            {
                if(div[j]==0)
                {
                    div[j]=i;
                }
            }
        }
        mb[i]=calmb(i,div);
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    ll t = 1;
    // cin >> t;
    seive();
    while (t--)
    {
        ll l,r;
        cin>>l>>r;
        if(l==1)
        {
            l++;
        }
        ll ans=0;
        for(ll i=1;i<=r;i++)
        {
            ll cnt=r/i-(l-1)/i;
            ans-=mb[i]*cnt*cnt;
        }
        for(ll i=l;i<=r;i++){
            for(ll j=i;j<=r;j+=i)
            {
                ans--;
			    if(i != j) ans--;
            }
        }
        cout<<ans<<"\n";
    }
    return 0;
}


#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long ll;
template<class T,class C> T max(T a,C b){ return std::max(a, (T)b); }
template<class T,class C> T min(T a,C b){ return std::min(a, (T)b); }
#define zt(a,b) (max((a),(b))-min((a),(b)))
int main(){
  ll i,j,r[2],c[2],res=0;
  for(i=0;i<2;i++){
    cin >> r[i] >> c[i];
  }
  if(r[0]==r[1] && c[0]==c[1]){
    res = 0;
  }else if(r[0]+c[0]==r[1]+c[1] || r[0]-c[0]==r[1]-c[1] || abs(r[0]-r[1])+abs(c[0]-c[1])<=3){
    res = 1;
  }else if(abs(r[0]-r[1])+abs(c[0]-c[1])<=6 || zt(r[0]+c[0],r[1]+c[1])<=3 || zt(r[0]-c[0],r[1]-c[1])<=3){
    res = 2;
  }else if((r[0]+c[0])%2==(r[1]+c[1])%2){
    res = 2;
  }else{
    res = 3;
  }
  cout << res << endl;
  return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m,a,b;
    scanf("%d%d%d%d",&n,&m,&a,&b);
    if(n==a&&m==b){
        printf("0\n");
    }
    else if(n+m==a+b||n-m==a-b||abs(n-a)+abs(m-b)<=3){
        printf("1\n");
    }
    else{
        if((abs(n+m)+abs(a+b))%2==0){
            printf("2\n");
        }
        else {
            for(int i=n-3;i<=n+3;i++){
                for(int j=m-3;j<=m+3;j++){
                    if(abs(i-n)+abs(j-m)>3)continue;
                    else if(i+j==a+b||i-j==a-b||abs(i-a)+abs(j-b)<=3){
                        printf("2\n");
                        return 0;
                    }
                }
            }
            printf("3\n");
        }
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <cmath>
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, s, n) for (ll i = s; i < (n); i++)
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> type(2*n, 0);
  vector<vector<int>> p(2*n, vector<int>(2*n, 0));
  bool check = true;
  rep(i, n){
    int a, b;
    cin >> a >> b;
    if (a != -1){
      a--;
      if (type[a] != 0){
        check = false;
        break;
      }
      type[a] = -1;
    }
    if (b != -1){
      b--;
      if (type[b] != 0){
        check = false;
        break;
      }
      type[b] = 1;
    }
    if (a != -1 && b != -1){
      rep(j, 2*n){
        p[a][j] = -1;
        p[j][a] = -1;
        p[b][j] = -1;
        p[j][b] = -1;
      }
      p[a][b] = 1;
    }
  }
  vector<bool> dp(n+1, false);
  dp[0] = true;
  rep2(i, 1, n+1){
    if (!check) break;
    rep(j, i){
      if (!dp[j]) continue;
      ll dist = i - j;
      bool flag = true;
      rep(k, dist){
        if (p[j*2+k][j*2+k+dist] == -1 ||
            (p[j*2+k][j*2+k+dist] == 0 && type[j*2+k] != 0 && type[j*2+k+dist] != 0) ||
            type[j*2+k] == 1 || type[j*2+k+dist] == -1){
          flag = false;
          break;
        }
      }
      if (flag){
        dp[i] = true;
        break;
      }
    }
  }

  if (dp[n]) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define pb push_back
#define f(i,n) for(int i=0; i<n; ++i)
#define fi(i,st,n) for(int i=st; i<=n; ++i)
#define veci vector<int>
#define vecp vector<pair<int,int> >
#define vecl vector<ll>
int prime[100000+10];

ll lcm(ll a, ll b) {
	return a*b/__gcd(a,b);
}

ll power(ll a, ll n, ll mod) {
	ll res = 1;
	while(n > 0) {
		if(n&1) {
			res = (res*a)%mod;
		}
		a = (a*a)%mod;
		n = n/2;
	}
	return res;
}

ll sum(int arr[], int n) {
	ll res = 0;
	f(i,n) {
		res += arr[i];
	}
	return res;
}

void seive() {
	prime[1] = 0;
	for(int i=2; i<=100000; i++) {
		prime[i] = 1;
	}
	for(ll i=2; i<=100000; i++) {
		if(prime[i]) {
			for(ll j=i*i; j<=100000; j+=i) {
				prime[j] = 0;
			}
		}
	}
}

bool check(string s) {
	f(i,s.length()) {
		if(s[i] == '0') return false;
	}
	return true;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t = 1;
//	cin>>t;
	while(t--){
		ll n,m;
		cin>>n>>m;
		ll a[m],b[m];
		f(i,m) {
			cin>>a[i]>>b[i];
		}
		ll k;
		cin>>k;
		ll c[k],d[k];
		f(i,k) {
			cin>>c[i]>>d[i];
		}
		string s = "";
		f(i,k) s += "0";
		int ans = 0;
		while(true) {
			if(check(s)) break;
			ll temp[n+1] = {0};
			f(i,k) {
				if(s[i] == '0') {
					temp[c[i]]++;
				} else {
					temp[d[i]]++;
				}
			}
			int res = 0;
			f(i,m) {

				if(temp[a[i]] and temp[b[i]]) {
					res++;
				}
			}
			ans = max(ans,res);
			f(i,k) {
				if(s[i] == '0') {
					s[i] = '1';
					break;
				}
				else {
					s[i] = '0';
				}
			}
		}
		cout<<ans;
	}
 	return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(x) (int) x.size()
#define cat(x) cerr << #x << " = " << x << endl
#define all(x) x.begin(), x.end()
#define rep(i, j, n) for (int i = j; i <= n; ++i)
#define per(i, j, n) for (int i = n; j <= i; --i)

using ll = long long;
using ld = long double;
using namespace std;

map<ll, int> m;
ll n;

int main() {
	scanf ("%lld", &n);
	ll three = 3, cnt = 1;
	while (three <= n) {
		m[three] = cnt;
		three *= 3;
		cnt++;
	}
	ll five = 5;
	cnt = 1;
	while (five <= n) {
		if (m[n - five]) return !printf ("%d %lld\n", m[n - five], cnt);
		five *= 5;
		cnt++;
	}
	printf ("-1\n");
	return 0;
}

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

#define amax(a, b) a = max(a, b)
#define amin(a, b) a = min(a, b)

using ll = long long;

int pow5(ll x) {
    int cnt = 0;
    while (x % 5 == 0) {
        x /= 5;
        cnt++;
    }
    return (x == 1 ? cnt : 0);
}

int main() {
    ll n;
    std::cin >> n;
    for (ll p3 = 3, a = 1; p3 < n; p3 *= 3, a++) {
        if (int b = pow5(n - p3); b > 0) {
            std::cout << a << ' ' << b << '\n';
            return 0;
        }
    }
    std::cout << -1 << '\n';
    return 0;
}


/*

|\    /| 				||  	00		   00
| \  / |				||	  0	   0 	 0	  0
|  \/  |	======		||	 0      0	0      0
|	   |	======		||	 0      0	0      0
|	   |				||	  0	   0	 0    0
|      |				||	    00         00

*/

#include "bits/stdc++.h"
#define ll long long
#define chl_jldi ios_base::sync_with_stdio(false); cin.tie(0)
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define ff first
#define ss second
#define null NULL
#define sz(xss) (xss.size())
#define uset unordered_set
#define nl "\n"
#define spc " "
#define pnl cout<<"\n"
#define odd(xz2) (xz2&1)
#define umap unordered_map
using namespace std;

void solve(){

int a,b;
cin>>a>>b;
if(a>=b){

ll sum=0;
for(int i=1;i<=a;i++) cout<<i<<spc,sum+=i;
for(int i=1;i<b;i++) cout<<(-1)*i<<spc,sum-=i;
	cout<<(-1*sum);
}
else{
	ll sum=0;
for(int i=1;i<=b;i++) cout<<(-1)*i<<spc,sum+=i;
for(int i=1;i<a;i++) cout<<i<<spc,sum-=i;
	cout<<(sum);

}

pnl;

}

int main(){
	chl_jldi;
#ifndef ONLINE_JUDGE
	freopen("error.txt","w",stderr);
#endif
ll test=1;

// ++++++++++++++++++++++++++++++++++++++++++  //

//cin>>test;

// ++++++++++++++++++++++++++++++++++++++++++  //

while(test--){

solve();

}return 0;}

#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
#include<array>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
constexpr ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acosl(-1.0);

ll mod_pow(ll x, ll n, ll m = mod) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * x % m;
		x = x * x % m; n >>= 1;
	}
	return res;
}
struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n % mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint& a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint& a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint& a, modint b) { a.n = ((ll)a.n * b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, ll n) {
	if (n == 0)return modint(1);
	modint res = (a * a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 2;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}

void solve() {
	char s, t; cin >> s >> t;
	if (s == 'Y')t += 'A' - 'a';
	cout << t << "\n";
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(15);
	//init_f();
	//init();
	//expr();
	//int t; cin >> t; rep(i, t)
	solve();
	return 0;
}


#include<bits/stdc++.h>

using namespace std;
typedef long long int ll;

int main()
{
    string s;
    cin>>s;
    int i=0;
    int cnt=0;
    while(i<9)
    {
        if(s[i] == 'Z')
        {
            if((s[i+1] == 'O') && (s[i+2] == 'N') && (s[i+3] == 'e'))
            {
                i+=4;
                cnt++;
            }
            else
            i++;
        }
        else
        i++;

    }

    cout<<cnt<<endl;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main() {
  string s; cin >> s;
  int t = 0;
  for (int i = 0; i <= s.size() - 4; i++)
    if (s.substr(i, 4) == "ZONe") t++;
  cout << t << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define ll long long
#define ln cout<<endl
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;}
template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);}
template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;

vector<string> C(vector<string> s) {
  ll n=s.size();
  rep(i,n)REP(j,i+1,n) swap(s[i][j],s[j][i]);
  return s;
}

ll n,m;
string s[1000];

ll calc(vector<string> t) {
  ll cnt=0;
  rep(k,m) {
    ll f=0;
    rep(l,2) {
      rep(i,n) {
        rep(j,n) {
          if(t[i].substr(0,s[k].size())==s[k]) f=1;
          rotate(t[i].begin(),t[i].begin()+1,t[i].end());
        }
      }
      t=C(t);
    }
    cnt+=f;
  }
  return cnt;
}

vector<string> ans;
ll MM;

void solve(vector<string> t) {
  ll d=calc(t);
  if(MM<d) {
    MM=d;
    ans=t;
  }
  rep(k,5) {
    random_shuffle(all(t));
    rep(i,n) rotate(t[i].begin(),t[i].begin()+rand()%n,t[i].end());
    ll d=calc(t);
    if(MM<d) {
      MM=d;
      ans=t;
    }
  }
}

void Main() {
  srand((unsigned)time(NULL));
  cin >> n >> m;
  rep(i,m) R s[i];
  vector<string> v[15];
  rep(i,m) v[s[i].size()].pb(s[i]);
  rep(e,30) {
    vector<string> t(n);
    rrep(i,15) {
      random_shuffle(all(v[i]));
      rep(j,v[i].size()) {
        ll M=MAX,x=0;
        string rr;
        rep(k,n) {
          rep(l,t[k].size()+1) {
            string r1=t[k].substr(l);
            if(r1.size()<=v[i][j].size()) {
              string r2=v[i][j].substr(0,r1.size());
              if(r1==r2) {
                ll d=t[k].size()+v[i][j].size()-r1.size();
                if(d<=n&&M>d) {
                  M=d;
                  x=k;
                  rr=t[k]+v[i][j].substr(r1.size());
                }
              }
            }
          }
        }
        if(rand()%8==0) M=MAX;
        if(M!=MAX) t[x]=rr;
      }
    }
    rep(i,n) {
      while(t[i].size()<n) {
        //t[i]+='.';
        t[i]+=(char)(rand()%8+'A');
      }
    }
    solve(t);
  }
  rep(i,n) pr(ans[i]);
}

int main(){Main();return 0;}

// author: immortal3
// github: github.com/immortal3

#include "bits/stdc++.h"
using namespace std;
#define int               long long
#define pb                push_back
#define ppb               pop_back
#define pf                push_front
#define ppf               pop_front
#define all(x)            (x).begin(),(x).end()
#define uniq(v)           (v).erase(unique(all(v)),(v).end())
#define sz(x)             (int)((x).size())
#define fr                first
#define sc                second
#define pii               pair<int,int>
#define rep(i,a,b)        for(int i=a;i<b;i++)
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define ppc               __builtin_popcount
#define ppcll             __builtin_popcountll

template<typename T1,typename T2>istream& operator>>(istream& in,pair<T1,T2> &a){in>>a.fr>>a.sc;return in;}
template<typename T1,typename T2>ostream& operator<<(ostream& out,pair<T1,T2> a){out<<a.fr<<" "<<a.sc;return out;}
template<typename T,typename T1>T amax(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T amin(T &a,T1 b){if(b<a)a=b;return a;}

const long long INF=1e18;
const int32_t M=1e9+7;
const int32_t MM=998244353;

const int MOD = 1e9 + 7;
const long long MOD2 = static_cast<long long>(MOD) * MOD;

void read_vector(vector<int> &a, int n)
{
    rep(i, 0, n)
        cin >> a[i];
}

int s(int a)
{
    int total = 0;
    while(a)
    {
        total += a % 10;
        a = a / 10;
    }
    return total;
}

void solve()
{
    int a, b;
    cin >> a >> b;

    cout << max(s(a), s(b)) << "\n";
}

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

    int t;
    // cin >> t;
    t = 1;
    while (t--)
    {
        solve();
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using V = vector<ll>;

int main()
{
    ll n;
    cin >> n;
    vector<P> town(n);
    V taka(n);
    ll takahashi = 0;
    ll aoki = 0;
    for (int i = 0; i < n; i++)
        cin >> town[i].first >> town[i].second;
    for (int i = 0; i < n; i++)
    {
        aoki += town[i].first;
        taka[i] = town[i].first * 2 + town[i].second;
    }
    sort(taka.begin(), taka.end(), greater<>());
    for (int i = 0; i < n; i++)
    {
        takahashi += taka[i];
        if (takahashi > aoki)
        {
            cout << i + 1 << endl;
            return 0;
        }
    }
}

#define wiwihorz
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma loop-opt(on)

#define rep(i, a, b) for(int i = a; i <= b; i++)
#define rrep(i, a, b) for(int i = b; i >= a; i --)
#define all(x) x.begin(), x.end()
#define ceil(a, b) ((a + b - 1) / (b))

#define MAXN 1000005
#define MOD 1000000007
#define INF 1000000000000000000
#define eps (1e-9)

#define int long long int
#define lld long double
#define pii pair<int, int>
#define random mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count())

using namespace std;
#ifdef wiwihorz
#define print(a...) out("[" + string(#a) +"] = ", a)
void vprint(auto L, auto R) {while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
void out() {cerr << endl;}
template<class T1, class ... T2> void out(T1 a, T2 ... e) {cerr << a <<" ", out(e...);}
#else
#define print(...) 0
#define vprint(...) 0
#endif
int n, s, A, B;
vector<int> a;
signed main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n, s = 0;
	rep(i, 1, n) {
		cin >> A >> B;
		s += A;
		a.push_back(2 * A + B);
	}

		sort(all(a)), reverse(all(a));
//		vprint(all(a)), print(s);
		int ans = 0;
		rep(i, 0, n - 1) {
			s -= a[i];
			if(s < 0) {
				ans = i + 1;
				break;
			}
		}
		cout << ans << "\n";

	return 0;
}


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

int N, Q;
int A[300005];
bool fenwick[35][300005];

void update_bit(int idx, int bit) {
  for (int i = idx; i <= N; i += (i & -i)) {
    fenwick[bit][i] ^= 1;
  }
}

void update(int idx, int y) {
  A[idx] ^= y;
  for (int i = 0; i < 30; i++) {
    if (y & (1 << i)) {
      update_bit(idx, i);
    }
  }
}

int get_bit(int pos, int bit) {
  bool res = 0;
  for (int i = pos; i > 0; i -= (i & -i)) {
    res ^= fenwick[bit][i];
  }
  return res;
}

void query(int l, int r) {
  int ans = 0;
  for (int i = 0; i < 30; i++) {
    if (get_bit(l - 1, i) ^ get_bit(r, i)) {
      ans = ans | (1 << i);
    }
  }
  cout << ans << "\n";
}

int main() {
  ios_base::sync_with_stdio(0);
  cin >> N >> Q;
  int x, y;
  for (int i = 1; i <= N; i++) {
    cin >> y;
    update(i, y);
  }
  int ty;
  while (Q--) {
    cin >> ty >> x >> y;
    if (ty == 1) {
      update(x, y);
    }else {
      query(x, y);
    }
  }
}

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

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

typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//定数
#define INF 1001001001 //10^9:極めて大きい値,∞
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
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<typename T>
struct BIT {
  int n;
  vector<T> d;
  BIT(int n=0):n(n),d(n+1,0) {}
  void init(int nn) {
        n=nn;
        d.resize(nn+1);
        for(int i=0;i<nn+1;i++) d[i]=0;
    }
    void add(int i, T w=1) {
        for (int x = i; x <= n; x += x & -x) d[x] += w;
    }
    T sum(int i) { // [1,x]
        T ret = 0;
        for (int x = i; x > 0; x -= x & -x) ret += d[x];
        return ret;
    }
    T sum(int l, int r) { // [l,r)
        return sum(r-1) - sum(l-1);
    }
};
// BIT配列の宣言 N:配列数, n:各要素数;
// BIT<int> bit[N];
// rep(i,N) bit[i].init(n);

int main(){
    ios::sync_with_stdio(false);
    int N, Q;
    cin >> N >> Q;
    int n=30;
    BIT<int> bit[n];
    rep(i, n) bit[i].init(N);
    rep(i, N){
        int a;
        cin >> a;
        rep(j, n){
            if(a&(1<<j)) bit[j].add(i+1, 1);
        }
    }
    rep(i, Q){
        int t, x, y;
        cin >> t >> x >> y;
        if(t==1){
            rep(j, n){
                if(y&(1<<j)) bit[j].add(x, 1);
            }
        }
        else{
            int ans=0;
            int mul=1;
            rep(j,n){
                if(bit[j].sum(x,y+1)%2==1) ans+=mul;
                mul*=2;
            }
            cout << ans << endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef int int_;
#define int long long

const int mod=998244353;

int qpow(int a,int b){
    int ret=1;
    while(b){
        if(b&1ll)ret=(ret*a)%mod;
        a=(a*a)%mod;
        b>>=1ll;
    }
    return ret%mod;
}

int_ main(){
	int a,b,k;scanf("%lld%lld%lld",&a,&b,&k);
	int ans=0;
	if(a==1){
		printf("%lld\n",qpow(k,b));
		return 0;
	}
	if(b==1){
		printf("%lld\n",qpow(k,a));
		return 0;
	}
	for(int i=1;i<=k;i++){
		// cout<<((qpow(i,a)-qpow(i-1,a))%mod+mod)%mod<<" "<<qpow(k-i+1,b)<<endl;
		ans=(ans+((qpow(i,a)-qpow(i-1,a))%mod+mod)%mod*qpow(k-i+1,b)%mod)%mod;
	}
	printf("%lld",ans%mod);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T1, class T2> inline bool chmax(T1 &a, const T2 &b) {if (a<b) { a=b; return 1;} return 0;}
template<class T1, class T2> inline bool chmin(T1 &a, const T2 &b) {if (b<a) { a=b; return 1;} return 0;}
struct init{init(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}}init_;

#ifdef DEBUG
template <class T> void verr(const set<T> &st) { repa(a, st) cerr << a << " "; cerr << endl; }
template <class S, class T> void verr(const map<S, T> &mp) { repa(a, mp) cerr << "{" << a.first << ", " << a.second << "} "; cerr << endl; }
template <class S, class T, class N> void verr(const vector<pair<S,T>>& a, const N& n) { rep(i, n) cerr << "{" << a[i].first << ", " << a[i].second << "} "; cerr << endl; }
template <class T, class N> void verr(const vector<T>& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << endl; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << endl; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
// const ll MOD = 1e9 + 7;
const ll MOD = 998244353;
//--------------------------------------------------------------------------------//
ll modpow(ll a, ll n, ll mod_) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod_;
        a = a * a % mod_;
        n >>= 1;
    }
    return res;
}

const ll MAX_SIZE = 200005;
array<ll, MAX_SIZE> fac, inv, finv;
struct finit{
    finit(){
        // combination init
        fac[0] = 1;
        for (ll i = 1; i < MAX_SIZE; i++) fac[i] = fac[i - 1] * i % MOD;
        finv[MAX_SIZE - 1] = modpow(fac[MAX_SIZE - 1], MOD - 2, MOD);
        for(ll i = MAX_SIZE - 1; i > 0; i--) finv[i - 1] = finv[i] * i % MOD;

        //inv init
        repe(i, 1, MAX_SIZE) inv[i] = modpow(i, MOD - 2, MOD);
    }
} finit_;

ll perm(ll a, ll b) { return fac[a] * finv[a - b] % MOD; }

ll comb(ll a, ll b) { return fac[a] * finv[b] % MOD * finv[a - b] % MOD; }

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

    if(N == 1){
        ll ans = 0;
        repe(k, 1, K + 1) {
            (ans += modpow(K - k + 1, M, MOD) - modpow(K - k, M, MOD)) %= MOD;
        }
        cout << (ans + MOD) % MOD << endl;
        return 0;
    }else if(M == 1){
        ll ans = 0;
        repe(k, 1, K + 1){
            (ans += modpow(k, N, MOD) - modpow(k - 1, N, MOD)) %= MOD;
        }
        cout << (ans + MOD) % MOD << endl;
        return 0;
    }

    ll ans = 0;
    repe(k, 1, K + 1){
        (ans += (modpow(k, N, MOD) - modpow(k - 1, N, MOD)) * modpow(K - k + 1, M, MOD) % MOD) %= MOD;
    }

    cout << (ans + MOD) % MOD << endl;
}


#pragma GCC optimize("Ofast")
#if 1
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using ll = int64_t;
using db = double;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vpii = vector<pii>;
using vpll = vector<pll>;

constexpr char newl = '\n';

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define show(x) cerr << #x << " = " << (x) << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define sz(x) (int)(x).size()
#define YesNo(x) cout<<((x)?"Yes":"No")<<newl;
#define YESNO(x) cout<<((x)?"YES":"NO")<<newl;
#define v(T) vector<T>
#define vv(T) vector<vector<T>>

template<class A, class B> using umap = unordered_map<A, B>;
template<class A> using uset = unordered_set<A>;

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> bool lcmp(const pair<T, T>& l, const pair<T, T>& r) {
  return l.first < r.first;
}
template<class T> istream& operator>>(istream& i, v(T)& v) {
  F0R(j, sz(v)) i >> v[j];
  return i;
}
template<class A, class B> istream& operator>>(istream& i, pair<A, B>& p) {
  return i >> p.first >> p.second;
}
template<class A, class B, class C> istream& operator>>(istream& i, tuple<A, B, C>& t) {
  return i >> get<0>(t) >> get<1>(t) >> get<2>(t);
}
template<class T> ostream& operator<<(ostream& o, const pair<T, T>& v) {
  o << "(" << v.first << "," << v.second << ")";
  return o;
}
template<class T> ostream& operator<<(ostream& o, const vector<T>& v) {
  F0R(i, v.size()) {
    o << v[i] << ' ';
  }
  o << newl;
  return o;
}
template<class T> ostream& operator<<(ostream& o, const set<T>& v) {
  for (auto e : v) {
    o << e << ' ';
  }
  o << newl;
  return o;
}
template<class T1, class T2> ostream& operator<<(ostream& o, const map<T1, T2>& m) {
  for (auto& p : m) {
    o << p.first << ": " << p.second << newl;
  }
  o << newl;
  return o;
}

constexpr double eps = 1e-5;
int N;

struct Pt {
  db x, y;
  db ata() const {
    return atan2(y, x);
  }
  friend ostream& operator<<(ostream& os, const Pt& p) {
    return os << '(' << p.x << ',' << p.y << ')';
  }
};

v(Pt) read() {
  v(Pt) as(N);
  db cx = 0, cy = 0;
  {
    vpii ab(N);
    F0R(i, N) {
      cin >> ab[i];
      cx += ab[i].first; cy += ab[i].second;
    }
    cx /= N; cy /= N;
    F0R(i, N) {
      as[i] = { ab[i].first - cx,ab[i].second - cy };
    }
  }
  return as;
}

// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  cin >> N;
  auto as = read();
  auto bs = read();
  //show(as);
  //show(bs);
  if (N == 1) {
    cout << "Yes"; return 0;
  }
  int s = 0;
  if (as[0].x == 0 && as[0].y == 0) s++;
  F0R(j, N) {
    //show(j);
    db r = as[s].ata();
    //show(as[0]); show(r);
    db r2 = bs[j].ata();
    //show(bs[j]); show(r2);
    db rot = r2 - r;
    uset<int> us;
    F0R(i, N) {
      // iを回転
      db x = cos(rot) * as[i].x - sin(rot) * as[i].y;
      db y = sin(rot) * as[i].x + cos(rot) * as[i].y;

      // 一致する頂点kを探す
      F0R(k, N) {
        if (abs(x - bs[k].x) < eps && abs(y - bs[k].y) < eps) {
          //if (i==0) show(k);
          us.insert(k); break;
        }
      }
    }
    if (sz(us) == N) {
      cout << "Yes"; return 0;
    }
  }
  cout << "No";
}
#endif

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i, n) for(int i = 0; i < (int)(n); i ++)
#define rrep(i, n) for(int i = (int)(n) - 1; i >= 0; i --)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define sll set<ll>
#define spll set<pll>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define mod 1000000007
#define mod2 998244353
#define inf 1000000000000000000
#define pi acos(-1)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rsort(a) sort(a.rbegin(), a.rend())
#define print(x) for(auto i : (x)) cout << i << " "; cout << endl
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll dx[] = {-1,0,1,0,-1,-1,1,1};
const ll dy[] = {0,-1,0,1,-1,1,-1,1};

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

    ll a, b, c, d;
    vll v(4);
    cin >> v[0] >> v[1] >> v[2] >> v[3];
    rep(i, pow(2, 4)) {
        ll x = 0, y = 0;
        rep(j, 4) {
            if ((i >> j) & 1) x += v[j];
            else y += v[j];
        }
        if (x == y) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;

}


#include <bits/stdc++.h>

using namespace std;

#define int long long

int N;
string S, T;
vector<int> ones;

main() {

    cin >> N >> S >> T;

    int j = 0;
    int cost = 0;
    for (int i = 0; i < N; i++) if (S[i] == '1') ones.push_back(i);
    int M = ones.size();

    for (int i = 0; i < N; i++) {
        if (T[i] == '0') continue;
        while (j+1 < M && ones[j] < i) {
            cost += ones[j+1] - ones[j];
            j += 2;
        }
        if (j >= M || ones[j] < i) {
            cout << "-1\n";
            return 0;
        }
        cost += ones[j] - i;
        j++;
    }

    while (j+1 < M) {
        cost += ones[j+1] - ones[j];
        j += 2;
    }

    //cout << j << "nm";

    if (j != M) {
        cout << "-1\n";
        return 0;
    }

    cout << cost << "\n";

    return 0;
}

#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <ctime>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <memory.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef long double LD;
typedef long long LL;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#ifdef LOCAL
#define DEBUG(x) { cerr << "# " << #x << ": " << x << endl;}
#else
#define DEBUG(x)
#endif
mt19937_64 mt(time(0));
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/
const int MAXN = 62;
LL dp[MAXN][MAXN];
LL combine(int n, int k) {
  assert(n >= k);
  if (n-k < k) return combine(n, n-k);
  if (dp[n][k] != 0) return dp[n][k];
  if (k == 0) return dp[n][k] = 1;
  if (k == 1) return dp[n][k] = n;
  if (k == 2) return dp[n][k] = n * (n-1) / 2;
  return dp[n][k] = combine(n-1, k-1) + combine(n-1, k);
}

string solve(int a, int b, LL k) {
  if (k == 1) {
    string s(a, 'a');
    s += string(b, 'b');
    return s;
  }
  assert (a > 0 && b > 0);
  LL tmp = combine(a+b-1, a-1);
  if (tmp >= k) return "a" + solve(a-1, b, k);
  return "b" + solve(a, b-1, k-tmp);
}

int main() {
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  cout.precision(10); cout << fixed;
#ifdef LOCAL
  freopen("../test.txt", "r", stdin);
    // freopen("../output.txt", "w", stdout);
#endif
  int a, b;
  LL k;
  cin >> a >> b >> k;
  cout << solve(a, b, k) << endl;

/*---------------------------------------Coding Space End------------------------------------------*/
#ifdef LOCAL
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s." << endl;
#endif
  return 0;
}
/* author:  txingml */
/* picture is from hamayanhamayan(CF handle) */