#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=4005,mod=998244353;
int k,n,c[N][N];
ll C(int n,int m)
{
    if(m==0||n==m) return 1;
    if(m==1) return n;
    if(c[n][m]) return c[n][m];
    return c[n][m]=(C(n-1,m-1)+C(n-1,m))%mod;
}
ll solve(int x)
{
    ll ans=0;
    int up=0;
    for(int i=1;i<=x/2;i++)
        if(i<=k&&x-i<=k)
        up++;
    for(int j=0,f=1;j<=up&&n-2*j>=0;j++,f*=-1)
        ans=(ans+f*C(up,j)%mod*C(n-2*j+k-1,k-1))%mod;
    return (ans+mod)%mod;
}
int main()
{
    scanf("%d%d",&k,&n);
    for(int i=2;i<=2*k;i++)
        printf("%lld\n",solve(i));
}

#include <bits/stdc++.h>

using namespace std;

#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fileio freopen("in.in", "r", stdin),freopen("out.out", "w", stdout);
#define ll long long int
#define FF first
#define SS second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define pss printf
#define MOD 998244353
#define INF 1e18
#define eps 0.00001
#define endl '\n'
#define debug(n1) cout<<n1<<endl

int n,k;
ll dp[2005][2005];
ll pre[2005];
ll dp1[2005][2005];

int rec(int i,int j)
{
	return dp[i][j];
}

int rec1(int i,int j)
{
	if(j==0)
		return 1;
	if(i==0)
		return (j==0);
	if(dp1[i][j]!=-1)
		return dp1[i][j];
	int an=(rec1(i-1,j)+rec1(i,j-1))%MOD;
	return dp1[i][j]=an;
}

int main()
{
	SPEED;
	cin>>k>>n;
	dp[0][0]=1;
	pre[0]=1;
	for(int j=1;j<=n;j++)
		pre[j]=(pre[j-1]+dp[0][j])%MOD;
	for(int i=1;i<=k;i++)
	{
		dp[i][0]=1;
		for(int j=1;j<=n;j++)
			dp[i][j]=(dp[i-1][j]+2*pre[j-1])%MOD;
		pre[0]=dp[i][0];
		for(int j=1;j<=n;j++)
			pre[j]=(pre[j-1]+dp[i][j])%MOD;
	}
	memset(dp1,-1,sizeof dp1);
	for(int i=2;i<=2*k;i++)
	{
		ll ans=0;
		int moves=0;
		if(i%2)
		{
			if(i<=k)
				moves=i/2;
			else
				moves=i/2-(i-k)+1;
			for(int j=0;j<=n;j++)
			{
				ll x=rec(moves,j);
				ll y=rec1(k-2*moves,n-j);
				ans=(ans+x*y)%MOD;
			}
		}
		else
		{
			if(i<=k)
				moves=(i-1)/2;
			else
				moves=(i-1)/2 - (i-k-1);
			for(int j=0;j<=n;j++)
			{
				ll x=rec(moves,j);
				ll y=rec1(k-2*moves-1,n-j);
				ans=(ans+x*y)%MOD;
				y=0;
				if(n-j-1>=0)
					y=rec1(k-2*moves-1,n-j-1);
				ans=(ans+x*y)%MOD;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

const int MAX = 1000000;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

int main()
{
    cout << fixed << setprecision(15);
    ll N, M, K;
    cin >> N >> M >> K;

    ll A = 1;
    A = (A*N)%MOD;
    A = (A*N)%MOD;
    A = (A*(M-1))%MOD;
    A = (A*M)%MOD;
    A = (A*(M+1))%MOD;

    ll B = 1;
    B = (B*M)%MOD;
    B = (B*M)%MOD;
    B = (B*(N-1))%MOD;
    B = (B*N)%MOD;
    B = (B*(N+1))%MOD;

    // 前処理
    COMinit();

    ll C = COM(N*M-2, K-2) % MOD;

    cout << ((((A+B)%MOD)* modinv(6, MOD) % MOD) * C) % MOD << endl;
    return 0;
}

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#define FAST_IO  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define endl "\n"
#define PI 3.14159265358979323846264338327950288

using namespace std ;
using bigint = long long int ;
using vi = vector<int> ;
using vll = vector<long long int> ;

int pref[1000075] ;
int main(){
    FAST_IO ;
    int D , T , S ; cin >> D >> T >> S ;
    if( S * T >= D )
        cout << "Yes" << endl ;
    else
        cout << "No" << endl ;
    return 0 ;
}


#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

const ll MOD = 1e9 + 7;

int main() {
#ifdef DEBUG
  ifstream cin("in.txt");
#endif
  int N, X;
  while (cin >> N >> X) {
    vector<int> S(N);
    for (int i = 0; i < N; i++) cin >> S[i];
    sort(S.begin(), S.end());
    vector<ll> dp(X + 1, 0);
    for (ll x = 0; x <= X; x++) dp[x] = x;
    for (int i = 0; i < N; i++) {
      int m = S[i];
      vector<ll> ndp(X + 1, 0);
      for (ll x = 0; x <= X; x++) {
        ndp[x] = (dp[x] * i % MOD + dp[x % m]) % MOD;
      }
      dp.swap(ndp);
    }
    cout << dp[X] << endl;
  }
  return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,count=0,i,temp,sum;
	cin>>a>>b;

	for(i=a;i<=b;i++)
	{
		sum=0;
		temp = i;
		while(temp)
		{
			sum*=10;
			sum+=(temp%10);
			temp/=10;
		}

		if(sum==i)
			count++;
	}

	cout<<count<<endl;

	return 0;
}


#include <bits/stdc++.h>

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

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

int main(void){

    string str;
    cin >> str;

    int al[26] = {0};
    roop(i, str.length()) al[str[i]-'a']++;

    roop(i, 26){
        if(al[i] == 0){
            str += (char)(i+'a');
            cout << str << endl;
            return 0;
        }
    }

    string t = str;
    if(next_permutation(t.begin(), t.end()) == false){
        cout << -1 << endl;
        return 0;
    }

    roop(i, str.length()-1){
        cout << t[i];
        if(t[i] != str[i]) break;
    }

    cout << endl;

    return 0;
}

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

int main(void)
{
    string s;

    cin >> s;

    bool flag = false;
    for(int i = 0; i < s.size()-1; ++i)
    {
        if(s[i] == s[i+1])
        {
            cout << i+1 << " " << i+2 << endl;
            return 0;
        }

        if(i+2 < s.size() && s[i] == s[i+2])
        {
            cout << i+1 << " " << i+3 << endl;
            return 0;
        }
    }

    cout << -1 << " " << -1 << endl;

    return 0;
}


#include <iostream>
#include <string>

int main(){
  std::string sent;
  int gyou,num=0;
  std::cin >> gyou;
  getline(std::cin, sent);
  for(int i=0;i<gyou;++i){
    num=0;
    getline(std::cin, sent);
    std::string bef="Hoshino",aft="Hoshina";
    while(num!=-1){
      num=(int)(sent.find(bef));
      if(num!=-1){
      sent.replace(num,bef.size(),aft);
      }
    }
    std::cout << sent << std::endl;
    /*if(i<gyou-1)
    std::cout << std::endl;*/
  }
  return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
int ctoi(char c) {return c-'0';}// char to int
int gcd(ll a,ll b){return b?gcd(b,a%b):a;}//MAX
int lcm(ll a,ll b){return a*b/gcd(a,b);}//MIN

int  main(){
string s;
cin >> s;
int n;
cin >> n;
for(int i=0;i<s.size();i+=n){
    cout<<s.at(i);
}
cout<<endl;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MOD=1e9+7;
const long double Pi=acos(-1);
using  P=pair<ll,ll>;
int main(){
  ll counte=0,countw=0;
  string str;
  cin>>str>>str;
  vector<ll> w((ll)str.size());
  vector<ll> e((ll)str.size());
  for(ll i=0;i<(ll)str.size();i++){
    if(i==0){
      if(str.at(i)=='E'){e.at(i)=1;w.at(i)=0;counte++;}
      else{e.at(i)=0;w.at(i)=1;countw++;}
    }
    else{
      if(str.at(i)=='E'){e.at(i)=e.at(i-1)+1;w.at(i)=w.at(i-1);counte++;}
      else{e.at(i)=e.at(i-1);w.at(i)=w.at(i-1)+1;countw++;}
    }
  }
  ll ans;
  for(ll i=0;i<(ll)str.size();i++){
    if(i==0){ans=counte-e.at(0);}
    else if(i==(ll)str.size()-1){ans=min(ans,w.at(i));}
    else{ans=min(ans,w.at(i-1)+counte-e.at(i));}
  }
  cout<<ans<<endl;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

const int mx=1e6+11;
const double PI = acos(-1);
#define MOD 1000000007

#define nl '\n'
#define pb push_back
#define F first
#define S second
#define I insert
#define mp make_pair

#define sz(x) x.size()
#define tt int t; cin>>t; while(t--)
#define be(a) (a).begin(),(a).end()
#define rbe(a) (a).rbegin(),(a).rend()
#define mem(a,b) memset(a,b,sizeof(a))
#define yes cout<<"YES"<<nl
#define no cout<<"NO"<<nl

#define su ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define frac cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

void f()
{
  int a,b;
  cin>>a>>b;
  cout<<max(a+b,max(2*a-1,2*b-1))<<nl;
}

int main()
{
    su;
    f();
    return 0;
}


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

struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef queue<int> qi;
typedef stack<int> si;
typedef deque<int> dqi;

#define reps(i, a, b) for (int i = a; i < b; ++i)
#define rep(i, n) reps(i, 0, n)
#define REPS(i, a, b) reps(i, a, b)
#define REP(i, n) rep(i, n)
#define deps(i, a, b) for (int i = a; i >= b; --i)
#define dep(i, n) deps(i, n, 0)
#define DEPS(i, a, b) deps(i, a, b)
#define DEP(i, n) dep(i, n)

#define pf push_front
#define pb push_back
#define mp make_pair
#define fst first
#define FST fst
#define sec second
#define SEC sec
#define sz(obj) ((int)(obj).size())
#define all(v) (v).begin(), (v).end()
#define ALL(v) all(v)

const int INF = 999999999;
const int MOD = 1e9 + 7;
const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; std::cin >> x; return x;}
template <typename T>
void print(std::vector<T>& v, char c = ' ') {
  REP(i, v.size()) {
    if (i != 0) std::cout << c;
    std::cout << v[i];
  }
  std::cout << endl;
}
template <typename T> void print(T x) { std::cout << x << '\n'; }

signed main()
{
  vi v(4);

  rep(i, 4) v[i] = in();
  sort(all(v));
  print(v[1] + v[2] + v[3] + max(in(), in()));

  return (0);
}

#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;

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

int main()
{
	vector<int> a(4);
	REP(i, 4) cin >> a[i];

	vector<int> b(2);
	REP(i, 2) cin >> b[i];

	sort(ALL(a), greater<int>());
	sort(ALL(b), greater<int>());

	int sum = 0;

	REP(i, 3) sum += a[i];
	sum += b[0];

	cout << sum << endl;

}


#include<iostream>
#include<string>
#include<vector>
#include<algorithm>//sort,reverse
#include<utility>//pair
#include<queue>//queue,priority_queue
#include<deque>//double_ended queue
#include<map>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;//Pでpair<-,->を表す。
typedef map<LL,LL>::iterator Itr;
LL MOD=1000000007;

struct S{
    LL x;LL y;LL z;
    bool operator<(const S&a)const{
        return x<a.x||(x==a.x&&y<a.y)||(x==a.x&&y==a.y&&z<a.z);
    }
    bool operator==(const S&a)const{
        return (x==a.x)&&(y==a.y)&&(z==a.z);
    }
};

int main()
{
    LL n,Q;
    cin>>n>>Q;
    vector<S> v;
    for(int i=0;i<n;i++){
        LL a,b,c;
        cin>>a>>b>>c;
        S s;
        s.x=c;s.y=a;s.z=b;
        v.push_back(s);
    }
    sort(v.begin(),v.end());
    reverse(v.begin(),v.end());

    /*for(int i=0;i<v.size();i++){
        S s=v[i];
        cout<<s.x<<' '<<s.y<<' '<<s.z<<endl;
    }*/

    map<LL,LL> m;
    for(int i=0;i<Q;i++){
        LL a;
        cin>>a;
        m.insert(P(a,i));
    }
    LL ans[Q];
    for(int i=0;i<n;i++){
        S s=v.back();
        v.pop_back();
        LL begin=s.y-s.x;
        LL end=s.z-s.x;
        vector <LL>d;
        for(Itr itr=m.lower_bound(begin);itr!=m.lower_bound(end);advance(itr,1)){
            ans[(*itr).second]=s.x;
            d.push_back((*itr).first);
        }
        while(!d.empty()){m.erase(d.back());d.pop_back();}
    }
    for(Itr itr=m.begin();itr!=m.end();advance(itr,1)){
        ans[(*itr).second]=-1;
    }
    for(int i=0;i<Q;i++){
        cout<<ans[i]<<endl;
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#pragma region
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << (#x) << "] = [", _print(x)
#else
#define debug(x...)
#endif
#pragma endregion
typedef long long ll;
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define sz(v) int((v).size())
#define int ll
#pragma region
#define f first
#define s second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#pragma endregion

int N,T;
vector<pair<int,int>> p;
int dp[6666];
void solve()
{
    cin>>N>>T;
    p.resize(N);
    forn(i, N) cin>>p[i].f>>p[i].s;
    //
    sort(p.begin(), p.end());
    for(auto& it: p)
    {
        for (int now = T - 1; now>= 0; --now)
        {
            dp[now+it.f] = max(dp[now+it.f], dp[now] + it.s);
        }
    }
    int ans = 0;
    forn(i, 6666) ans = max(ans, dp[i]);
    cout << ans << '\n';
}

signed main()
{
    int T = 1;
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << fixed << setprecision(22);
    // cin >> T;
    for(int i=1;i<=T;++i)
    {
        //cout << "Case #" << i << ": ";
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	int n,l,ans=1e9; cin>>n>>l;
	int S[n], sum=0;
	for(int i=0; i<n; i++){
		S[i] = l+i+1-1;
		sum+=S[i];
	}
	for(int i=0; i<n; i++){
		int x = abs(sum - (sum-S[i]));
		ans = min(ans, x);
	}
	if(sum>=0)cout<<sum-ans<<endl;
	else cout<<sum+ans<<endl;
}

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
int main(){
  int n, l;
  cin >> n >> l;

  int sum = n*(l-1) + (n*(n+1))/2;
  if((l+n-1) < 0) {
    sum -= l+n-1;
  } else if(0 < l) {
    sum -= l;
  }
  cout << sum << endl;
  return 0;
}


#include<iostream>

using namespace std;

const int coin[2] = {5,500};

int main(){
  int money,happy;
  cin >> money;
  int C[2] = {0,0};
  for(int i = 1;i >= 0;i--){
    C[i] = money / coin[i];
    money -= coin[i]*C[i];
  }
  happy = C[0]*5 + C[1]*1000;
  cout << happy << endl;
  return 0;
}

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

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

  int big = x/500;
  int rest = x%500;
  int small = rest/5;

  cout << 1000*big + 5*small << endl;
}


#include <iostream>
#include <iterator>
#include <sstream>
#include <string>

#include <set>
#include <list>
#include <unordered_map>
#include <vector>
#include <stack>
#include <queue>

#include <algorithm>
#include <utility>

using namespace std;
namespace patch
{
    template <typename T>
    string to_string(const T& n)
    {
        ostringstream stm;
        stm << n;
        return stm.str();
    }
    int stoi(string str)
    {
        int ret;
        istringstream stm(str);
        stm >> ret;
        if (stm.fail())
        {
            throw -1;
        }
        return ret;
    }
    vector<string> split(const string &str)
    {
        istringstream stm(str);
        vector<string> ret;
        copy(istream_iterator<string>(stm),
            istream_iterator<string>(),
            back_inserter(ret));
        return ret;
    }
    vector<string> split(const string &str, char delim)
    {
        istringstream stm(str);
        vector<string> ret;
        string buf;
        while (getline(stm, buf, delim))
        {
            ret.push_back(buf);
        }
        return ret;
    }
}

int bubbleSort(vector<int>& vs)
{
    int end = vs.size();
    if (end == 1)
    {
        return 0;
    }
    int cnt = 0;
    for (int j = 0; j < end - 1; ++j)
    {
        for (int i = 0; i < end - j - 1; ++i)
        {
            if (vs[i] > vs[i+1])
            {
                swap(vs[i], vs[i+1]);
                ++cnt;
            }
        }
    }
    return cnt;
}

// bubble sort
int main()
{
    ios::sync_with_stdio(false);

    // line 1
    string s1;
    getline(cin, s1);
    int n = patch::stoi(s1);

    // line 2
    vector<int> vs(n);
    vector<string> ss;
    string s2;
    getline(cin, s2);
    ss = patch::split(s2);
    for (int n = 0, sz = ss.size(); n < sz; ++n)
    {
        vs[n] = patch::stoi(ss[n]);
    }

    int cnt = bubbleSort(vs);

    bool isFirst = true;
    for (int n : vs)
    {
        //cout << n << " ";
        if (isFirst)
        {
            cout << n;
            isFirst = false;
        }
        else
        {
            cout << " " << n;
        }
    }
    cout << "\n";
    cout << cnt << "\n";

    return 0;
}

#include <iostream>
#define    N    101
using namespace std;

void swap(int *x, int *y){
	int z = *x;
	*x = *y;
	*y = z;
}

int bubbleSort(int *A, int n){
	int count = 0, flag = 1;

	while(flag){
		flag = 0;
		for(int j=n-1;j>0;j--){
			if(A[j] < A[j-1]){
				swap(A[j], A[j-1]);
				count++;
				flag = 1;
			}
		}
	}

	return count;
}

int main(){
	int n, A[N], change;

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

	change = bubbleSort(A, n);

	for(int i=0;i<n;i++){
		if(i!=0) cout<<" ";
		cout<<A[i];
	}
	cout<<endl<<change<<endl;

	return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define EPS (1e-15)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define bet(x, a, b) (a) <= (x) && (x) < (b)
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	int N, K;

	cin >> N >> K;
	cout << N - K + 1 << endl;

	return 0;
}

#include <iostream>
#include <cstring>
#include<vector>
#include <algorithm>
#include<cstdlib>
#include<set>
#include<math.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(ll i=0;i<n;i++)

int main()
{
	int a, b;
	cin >> a >> b;
	int ans;
	ans = (b - 1) /(a - 1);
  if((b-1)%(a-1)!=0) ans++;
	cout << ans << "\n";

	return 0;
}


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

int main()
{
  int N, ai;
  cin >> N;
  map <int,int> A;
  for(int i=0;i<N;i++){
    cin >> ai;
    if(A.count(ai) > 0){ cout << "NO" << endl; return 0;}
    else A[ai] = 1;
  }
  cout << "YES" << endl;
}

#include <bits/stdc++.h>
using namespace std;
struct point{int x;int y;};
int i,j,k,count1=0,count2=0;

int main(){
    string s;
    cin>>s;
    for(i=0;i<s.length()-1;i++){
        if(s[i]=='A'&&s[i+1]=='C'){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
}


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

#define int long long int

int32_t main()
{
    string str;
    cin>>str;
    cout<<2018<<str.substr(str.find('7')+1)<<endl;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 1e12

#define PB push_back
#define PF push_front
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vpi vector<pii>
#define vll vector<ll>
#define vpl vector<pll>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))
#define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pr_d(x) cout << fixed << setprecision(15) << x << endl
#define ud(c, x) distance(c.begin(), upper_bound(all(c), x))
#define ld(c, x) distance(c.begin(), lower_bound(all(c), x))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define rep3(i, n) for (int i = (n - 1); i >= 0; --i)
#define rep4(i, a, b) for (int i = (a); i > (b); --i)
#define pb push_back
#define out(x) cout << x << "\n"
bool odd(int i) { return i % 2; }

#define all(v) v.begin(), v.end()
#define size(x) int(x.size())

int gcd(int a, int b) { return __gcd(a, b); }
int lcm(int a, int b) { return a * (b / gcd(a, b)); }
void Yes_No(bool f) {
  if (f)
    printf("Yes\n");
  else
    printf("No\n");
}
void YES_NO(bool f) {
  if (f)
    printf("YES\n");
  else
    printf("NO\n");
}

template <typename T>
void deb1(T x) {
  cout << x << "\n";
}

template <typename T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T& a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
//-------------------ここから回答する-----------------------

void solve(void) {
  string s;
  cin >> s;
  set<char> st;
  rep(i, 26) st.insert('a' + i);
  rep(i, size(s)) st.erase(s[i]);
  if (size(st) != 0)
    out(*st.begin());
  else
    out("None");
}
int main(void) { solve(); }


#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#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 srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl

using namespace std;

template<typename S,typename T>auto&operator<<(auto&o,pair<S,T>p){return o<<"{"<<p.fi<<","<<p.se<<"}";}
template<typename T>auto&operator<<(auto&o,set<T>s){for(auto&e:s)o<<e<<" ";return o;}
template<typename S,typename T,typename U>
auto&operator<<(auto&o,priority_queue<S,T,U>q){while(!q.empty())o<<q.top()<<" ",q.pop();return o;}
template<typename K,typename T>auto&operator<<(auto&o,map<K,T>&m){for(auto&e:m)o<<e<<" ";return o;}
template<typename T>auto&operator<<(auto&o,vector<T>v){for(auto&e:v)o<<e<<" ";return o;}
void ashow(){cout<<endl;}template<typename T,typename...A>void ashow(T t,A...a){cout<<t<<" ";ashow(a...);}
template<typename S,typename T,typename U>
struct TRI{S fi;T se;U th;TRI(){}TRI(S f,T s,U t):fi(f),se(s),th(t){}};
template<typename S,typename T,typename U>
auto& operator<<(auto& o,TRI<S,T,U>& t){return o<<"{"<<t.fi<<","<<t.se<<","<<t.th<<"}";}

typedef pair<int, int> P;
typedef pair<ll, ll> pll;
typedef TRI<int, int, int> tri;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<P> vp;
typedef vector<double> vd;
typedef vector<string> vs;

const int MAX_N = 2005;

int t[MAX_N][MAX_N], a[MAX_N][MAX_N];
int h, w;

int calc()
{
	int ans = 0;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
			if(a[i][j]) t[i+1][j] = 0;
			else t[i+1][j] = t[i][j] + 1;
		}
		t[i+1][w] = 0;
		stack<pair<int, int> > st;
		for(int j = 0; j <= w; j++){
			if(st.empty()){
				st.push({j, t[i+1][j]});
				continue;
			}
			pair<int, int> p = st.top();
			if(p.second < t[i+1][j]){
				st.push({j, t[i+1][j]});
			}else if(p.second > t[i+1][j]){
				int pos;
				while(p.second >= t[i+1][j]){
					ans = max(ans, (p.second+1)*(j-(pos=p.first)+1));
					st.pop();
					if(!st.empty()) p = st.top();
					else break;
				}
				st.push({pos, t[i+1][j]});
			}
		}
	}
	return ans;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> h >> w;
    rep(i,h){
        string s;
        cin >> s;
        rep(j,w){
            t[i][j] = (s[j] == '#');
        }
    }
    h--, w--;
	rep(i,h){
		rep(j,w){
			a[i][j] = (t[i][j]+t[i+1][j]+t[i][j+1]+t[i+1][j+1])%2;
		}
	}
    rep(j,w+1){
        t[0][j] = 0;
    }
	cout << max({h+1, w+1, calc()}) << "\n";
    return 0;
}


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

int main(){
    long long a;
    double b;
    cin >> a >> b;
    int B = b * 100;
    long long c = a * B / 100;
    cout << c << endl;
}

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

int main(){

    ll a,b;
    cin>>a>>b;
    cout << a*b;

}


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

int main() {
  int n;
  cin >> n ;
  int result;
  result = 1;
  int k;
  cin >> k;
    for (int i = 0; i < n; i++)
    {
        if (result+k < result*2)
        {
            result = result + k;
        }
        else if (result*2 <= result+k)
        {
            result = result*2;
        }

    }
cout << result << endl;

  // ここにプログラムを追記

}

#include <bits/stdc++.h>
#define N 1005
#define INF 0x3f3f3f3f
#define mod 1000000007
using namespace std;
typedef long long ll;
ll ans;

int main(){
    ll n, t;
    cin >> n >> t;
    ll arr[n];
    for(int i=0; i<n; i++) cin >> arr[i];
    ans = n*t;
    for(int i=1; i<n; i++){
        if(t-(arr[i]-arr[i-1]) > 0) ans-=t-(arr[i]-arr[i-1]);
    }
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>
#include <stdio.h>
#include <numeric>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
#define INF 9223372036854775807
#define pairint pair<int,int>
int num[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
bool uru(int checkyear){if(checkyear%4==0){if(checkyear%100!=0||checkyear%400==0)return true;}return false;}
int gcd( int x, int y ){return y ? gcd(y, x%y) : x;}
bool pairCompare(const pairint& firstElof, const pairint& secondElof)
{
  if(firstElof.second!= secondElof.second)    return firstElof.second> secondElof.second;
  else return firstElof.first< secondElof.first;
}
signed main() {
int x=0,y=0,z=0,w=0,n=0,m=0;
std::vector<int> v(10);
while (std::cin >> x,x) {
  rep(i,10)v[i]=0;
  rep(i,x){
    std::cin >> y;
    v[y]++;
  }
  rep(i,10){
    if(v[i]>0){
      Rep(j,v[i]){
        std::cout << "*";
     }
      std::cout<< '\n';
  }else std::cout << "-" << '\n';
}
}
}

#include <iostream>
#include <cmath>
#include <map>
#include <string>
using namespace std;

int main()
{
	map<char,int> roman;
	roman['I'] = 1;
    roman['V'] = 5;
    roman['X'] = 10;
    roman['L'] = 50;
    roman['C'] = 100;
    roman['D'] = 500;
    roman['M'] = 1000;

	string s;
	while(cin >> s)
	{
		int ans = 0;
		for(int i=0;i<s.size()-1;i++)
		{
			if(roman[s[i]] >= roman[s[i+1]]) ans += roman[s[i]];
			else ans -= roman[s[i]];
		}
		ans += roman[s[s.size()-1]];
		cout << ans << endl;
	}
	return 0;
}


#include <iostream>
#include <string>

using namespace std;

void swapD(double *a,double *b){
	double tmp = *a;
	*a = *b;
	*b = tmp;
}

void swapString(string *a,string *b){
	string tmp = *a;
	*a = *b;
	*b = tmp;
}

int main(){
	int n;
	string str[60];
	double data[60];
	for(int i=0;i<60;i++){
		data[i]=10000000;
	}

	while(cin>>n){
		if(n==0)break;

	for(int i=0;i<n;i++){
		data[i]=0;
		int p,a,b,c,d,e,f,s,m;

		cin>>str[i]>>p>>a>>b>>c>>d>>e>>f>>s>>m;

		int cnt=0;

		cnt = a+b+c+d+e;
		data[i]=s*f;
		m--;
		for(int j=0;j<m;j++){
			cnt+=(d+e);
			data[i]+=f*s;		}

		data[i]-=p;

		data[i]/=(double)cnt;
	}

	for(int i=0;i<n;i++){
		for(int j=n-1;j>i;j--){
			if(data[j]>=data[j-1] ){
				swapD(&data[j],&data[j-1]);
				swapString(&str[j],&str[j-1]);
			}
		}
	}

	for(int i=0;i<n;i++){
		for(int j=n-1;j>i;j--){
			if(data[j]>=data[j-1] && str[j]<=str[j-1]){
				swapD(&data[j],&data[j-1]);
				swapString(&str[j],&str[j-1]);
			}
		}
	}

	for(int i=0;i<n;i++){
		//cout<<str[i]<<" "<<data[i]<<endl;
		cout<<str[i]<<endl;
	}

	cout<<"#"<<endl;
	}

	return 0;
}

#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

int main() {

    int h, w, a, b;
    cin >> h >> w >> a >> b;

    vector<vector<int>> grid(h, vector<int>(w, 0));
    rep(y, h) rep(x, w) {
            if ((y < b && x < a) || (b <= y && a <= x)) {
                grid[y][x] = 1;
            }
        }

    rep(y, h) {
        rep(x, w) {
            cout << grid[y][x];
        }
        cout << endl;
    }
}


#include<bits/stdc++.h>

using namespace std;
using ll = long long;

template <typename K,typename V>
using umap = unordered_map<K,V>;
template <typename V>
using uset = unordered_set<V>;
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; }
#define REP(i,n) for(int i=0;i<n;i++)
#define REPD(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define ALL(v) v.begin(),v.end()

#define INF 1'000'000'000'000 //10^12
#define MOD 1'000'000'007

int main(){

    int n;
    cin >> n;
    int a[n];

    REP(i,n){
        cin >> a[i];
    }

    uset<int> a_set;

    REP(i,n){
        if(a_set.find(a[i]) == a_set.end()){
            a_set.insert(a[i]);
        }else{
            a_set.erase(a[i]);
        }
    }

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

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
using pii = pair<int, int>;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  int ans = 0;
  set<int> hako;
  map<int, int> s;

  for (int i = 0; i < n; i++) {
    s[a[i]]++;
  }

  for (auto it = s.begin(); it != s.end(); it++) {
    if ((it->second % 2) != 0) {
      ans++;
    }
  }
  cout << ans << endl;
}


#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
typedef long long ll;
using namespace std;

ll n, m;

template < typename T >
inline T read()
{
	T x = 0, w = 1; char c = getchar();
	while(c < '0' || c > '9') { if(c == '-') w = -1; c = getchar(); }
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * w;
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("cpp.in", "r", stdin), freopen("cpp.out", "w", stdout);
#endif
	n = read <ll> (), m = n / 11 * 2ll, n %= 11;
	if(!n) { printf("%lld\n", m); return 0; }
	else if(n <= 6) { printf("%lld\n", m + 1); return 0; }
	else printf("%lld\n", m + 2);
	return 0;
}


#define _USE_MATH_DEFINES
#define INF 100000000

#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>

using namespace std;

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

static const double EPS = 1e-8;

int main(){
	int N,Q;
	while(~scanf("%d %d",&N,&Q)){
		if(N==0 && Q==0) break;
		map<int,int> freq;
		for(int i=0;i<N;i++){
			int num;
			scanf("%d",&num);

			for(int j=0;j<num;j++){
				int day;
				scanf("%d",&day);
				freq[day]++;
			}
		}

		int maxv=0;
		int min_day=INF;
		for(map<int,int>::iterator it = freq.begin(); it!=freq.end();it++){
			if(it->second >= Q){
				if(maxv < it->second){
					maxv = it->second;
					min_day=it->first;
				}
				else if(maxv == it->second){
					min_day=min(min_day,it->first);
				}
			}
		}

		printf("%d\n",min_day >= INF ? 0 : min_day);
	}
}

#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

const int MAX_V=102;
int vote[MAX_V];

int main(){ _;
  int n,q,m,tmp,result,resultCount;
  while(cin>>n>>q,(n|q)!=0){
    REP(i,MAX_V) vote[i]=0;
    REP(i,n){
      cin>>m;
      REP(j,m){
	cin>>tmp;
	vote[tmp]++;
      }
    }
    result=0;
    resultCount=q-1;
    REP(i,MAX_V){
      if(vote[i]>resultCount){
	result=i;
	resultCount=vote[i];
      }
    }
    cout<<result<<endl;
  }
}


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

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

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

const int INF = 1001001001;
const int MOD = 1000000007;
const double PI=acos(-1);

using Edge = pair<ll,ll>;
using Graph = vector<vector<Edge>>;

int N;
Graph G;
vector<ll> res;

void bfs(ll v) {

    queue<vector<ll>> que;
    que.push({v,-1,0});

    while(que.size()) {
        auto p = que.front();
        que.pop();

        if (p[1]!=-1) {
            res[p[0]] = res[p[1]] + p[2];
        }
        else {
            res[p[0]] = 0;
        }

        for (auto e:G[p[0]]) {
            if (res[e.first]==-1) que.push({e.first, p[0], e.second});
        }
    }
}

int main(){
    cin >> N;
    G.assign(N, vector<Edge>());
    for (int i=0; i<N-1; i++) {
        ll a,b,c;
        cin >> a >> b >> c;
        a--;
        b--;
        G[a].push_back(Edge(b,c));
        G[b].push_back(Edge(a,c));
    }

    res.assign(N,-1);

    int Q,K;
    cin >> Q >> K;
    K--;

    bfs(K);

    rep(i,Q) {
        int x,y;
        cin >> x >> y;
        x--,y--;
        cout << res[x] + res[y]   << endl;
    }
}

#include<bits/stdc++.h>
#define ll long long int
#define vec vector<ll>
#define mat vector<vector<ll>>

using namespace std;

const ll mod=1000000007;
const ll inf=LONG_LONG_MAX;
ll dx4[4]={1,0,-1,0};
ll dy4[4]={0,-1,0,1};
ll dx8[8]={1,0,-1,1,-1,1,0,-1};
ll dy8[8]={1,1,1,0,0,-1,-1,-1};

// 二部グラフ判定
vector<ll> color;
bool dfs(mat G,ll v,ll cur = 0) {
  color[v] = cur;
  for(auto next_v : G[v]) {
    // 隣接頂点がすでに色確定していた場合
    if (color[next_v] != -1) {
      if (color[next_v] == cur) return false; // 同じ色が隣接したらダメ
      continue;
    }

    // 隣接頂点の色を変えて、再帰的に探索 (一回でも false が返ってきたら false)
    if (!dfs(G, next_v , 1 - cur)) return false;
  }
  return true;
}

int main(){

  ll n,m;
  cin >> n >> m;

  mat G(n);
  vec a(m),b(m);
  for(ll i=0;i<m;i++){
    cin >> a[i] >> b[i];
    G[a[i]-1].push_back(b[i]-1);
    G[b[i]-1].push_back(a[i]-1);
  }

  vec d(n,-1);
  d[0]=0;
  queue<ll> q;
  q.push(0);
  while(!q.empty()){
    ll v=q.front();
    q.pop();
    for(ll i=0;i<G[v].size();i++){
      if(d[G[v][i]]!=-1)continue;
      d[G[v][i]]=d[v]+1;
      q.push(G[v][i]);
    }
  }
  bool ok=true;
  for(ll i=0;i<m;i++){
    if((d[a[i]-1]-d[b[i]-1])%2==0)ok=false;
  }

  color=vec(n,-1);
  if(!ok){
    cout << n*(n-1)/2-m << endl;
  }
  else{
    ll b=0;
    for(ll i=0;i<n;i++)b+=(d[i]&1);
    cout << b*(n-b)-m << endl;
  }

}


#include <bits/stdc++.h>
#include<cmath>
#define N 100005
#define A 1000005
#define MOD 998244353 //1000000007 // //100000000
#define INF 1000000000000000000
#define ll long long
//#define M_PI 3.141592653589793238463

using namespace std;

#define pii pair<ll, ll>
#define piii pair<ll, pii>
#define ft first
#define sd second
#define pb push_back
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n-1; i >= 0; i--)
#define itr(it, x) for(auto it = x.begin(); it != x.end(); it++)
#define mem(a, b) memset(a, (ll)b, sizeof(a))
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define edge(v, x, y) v[x].pb(y); v[y].pb(x);
#define popcount __builtin_popcount
#define ANS(s) {cout << s << "\n"; return;}

//~~~~~~fancy print~~~~~~~//
#define printpii(a) cout << a.ft << " " << a.sd << endl;
#define printpiii(a) cout << a.ft << " " << a.sd.ft << " " << a.sd.sd << endl;
#define print(a, n) rep(i, n) cout << a[i] << " "; cout << endl;
#define printv(v) for(auto x: v)cout << x << " "; cout << endl;
#define printm(a, n, m) rep(i, n) { rep(j, m) cout << a[i][j] << "\t"; cout << endl;}

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

void fast(){ios_base::sync_with_stdio(false);cin.tie(0);cout << setprecision(12) << fixed;}

void solve(){
    string s;
    cin >> s;
    if(s[0] != 'A') ANS("WA");
    ll f = 0;
    for(ll i = 2; i < s.size()-1; i++){
        if(s[i] == 'C'){
            if(f == 1) {ANS("WA");}
            else f = i;
        }
    }
    if(f == 0) ANS("WA");
    for(ll i = 1; i < s.size(); i++){
        if(i != f && s[i] >= 'A' && s[i] <= 'Z') ANS("WA");
    }
    ANS("AC");

}
main(){
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    fast();
    ll t = 1; //cin >> t;
    while(t--){
        solve();
    }
}

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define sort(a)         sort((a).begin(), (a).end())
#define uniq(a)         SORT(a);(a).erase(unique((a).begin(), (a).end()), (a).end())
#define reverse(a)      reverse((a).begin(), (a).end())
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define Yes()           printf("Yes\n")
#define No()            printf("No\n")
#define YES()           printf("YES\n")
#define NO()            printf("NO\n")
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }

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

const ll MOD = 1000000007; // 10^9 + 7

void solve() {
  string s; cin >> s;
  if (s.size() == 3) reverse(s);
  outl(s);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


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

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

//Zeller's conguence

int main()
{
    int h, y, m, d;
    h = 20;
    y = 4;
    while (true)
    {
        cin >> m >> d;
        if (m == 0 && d == 0)
            break;
        if (m == 1 || m == 2)
        {
            m += 12;
            y--;
        }
        int r = 5 * h + h / 4;
        int w = {d + ((13 * (m + 1)) / 5) +
                 y + y / 4 + r + 5};

        int ans = w % 7 + 1;
        switch (ans)
        {
        case 7:
            cout << "Sunday" << endl;
            break;
        case 1:
            cout << "Monday" << endl;
            break;
        case 2:
            cout << "Tuesday" << endl;
            break;
        case 3:
            cout << "Wednesday" << endl;
            break;
        case 4:
            cout << "Thursday" << endl;
            break;
        case 5:
            cout << "Friday" << endl;
            break;
        case 6:
            cout << "Saturday" << endl;
            break;
        }
    }
    return 0;
}

#include <stdio.h>

int main(void) {
  int i, j, k, m, d, ans;
  int m0[13] = {0, 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335};
  char w[7][25] = {
    "Wednesday",
    "Thursday",
    "Friday",
    "Saturday",
    "Sunday",
    "Monday",
    "Tuesday"
  };
  while( 1 ) {
    scanf("%d%d", &m, &d);
    if(!m && !d) break;
    ans = m0[m] + d;
    ans %= 7;
    printf("%s\n", w[ans]);
  }
  return 0;
}


#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

int main() {
  int N; cin >> N;
  if (N == 0) {
    cout << 0 << endl;
    return 0;
  }

  vector<int> vs;
  while (abs(N) > 0) {
    int r = abs(N) % 2;
    if (r == 1) N--;
    vs.push_back(r);
    N /= -2;
  }
  for (auto it = vs.rbegin(); it != vs.rend(); ++it) {
    cout << *it;
  }
  cout << endl;
}

#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
#include<numeric>
using namespace std;
using ll = long long;
int main(){
  int n;
  cin >> n;
  int q = 0;
  int cnt = 0;
  int left = 0, right = n;
  vector<int> es(n);
  while(true) {
    cout << q << endl;
    string tmp;
    cin >> tmp;
    if(tmp == "Vacant"){
      return 0;
    }else if(tmp =="Male"){
      if(cnt == 0) {
        for(int i = 0; i < n; i++){
          if(i % 2 == 0){
            es[i] = 0;
          }else{
            es[i] = 1;
          }
        }
      } else {
        if(es[q] == 0){
          left = q;
        } else {
          right = q;
        }
      }
    }else{
      if(cnt == 0) {
        for(int i = 0; i < n; i++){
          if(i % 2 == 0){
            es[i] = 1;
          }else{
            es[i] = 0;
          }
        }
      } else {
        if(es[q] == 1){
          left = q;
        } else {
          right = q;
        }
      }
    }
    q = (left + right) / 2;
    cnt++;
  }
  return 0;
}


#include<iostream>
using namespace std;

int main() {
  int n,m;
  cin>>n>>m;
  cout<<n*m<<endl;
}

#include <cstdio>
typedef long long ll;
#define rep(i,a,n) for (int i=a;i<n;i++)
ll mod;
int n;
ll powmod(ll a,ll b) {ll res=1;a%=mod; for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

ll ipw2[10100],ipw3[10100],fac[10100],fnv[10100];
int main() {
  scanf("%d%lld",&n,&mod);
	fac[0]=1;
	rep(i,1,10000) fac[i]=fac[i-1]*i%mod;
	rep(i,0,10000) fnv[i]=powmod(fac[i],mod-2),ipw2[i]=powmod(2,mod-1-i),ipw3[i]=powmod(3,mod-1-i);
	int s=0;
	rep(i,0,n+1) rep(j,0,n-i+1) s=(s+fnv[i]*fnv[j]%mod*fnv[3*n-3*i-2*j]%mod*ipw3[i]%mod*ipw2[j])%mod;
  printf("%d\n",s*fac[3*n]%mod);
}


/*
 * Author: .-O_O-.
 */
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define rep0(a,b) for(int a=0;a<b;a++)
#define rep1(a,b) for(int a=1;a<=b;a++)
#define repp(a,b,c) for(int a=b;a<c;a++)
#define in insert
#define len length()
#define si size()
#define lb lower_bound
#define ub upper_bound
#define beg begin()
#define en end()
#define f first
#define s second
#define pr(a) cout<<a
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define nx cout<<"\n"
#define int long long
// void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]"<<endl;}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
const ll mod = 1000000007;
const ll N = 105;
const ll mm = 1e+18;
bool isprime(long long n){
    if(n<=1) return false;
    for(long long i=2;i<=sqrt(n);i++){
         if(n%i==0) return false;
    }
    return true;
}
void solve()
{
    int n;
    cin>>n;
    int ans=1;
    rep1(i,n){
        if(isprime(i)){
            int ff=0;
            repp(j,i,n+1){
                int x=j;
                while(x%i==0){
                    ff++;
                    x/=i;
                }
            }
            ans=(ans*(ff+1))%mod;
        }
    }
    cout<<ans;
}
signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
    //cin>>t;
    rep1(_i,t){
        //cout<<"Case #"<<_i<<": ";
        solve();
        //nx;
    }
    return 0;
}

//itp1_5-d
#include <iostream>
using namespace std;

int include3(int x){
 return (! x) ? 0 : (x%10==3 || include3(x/10));
}

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

 for(int i=1;i<=n;i++){
  if(i%3==0) cout<<" "<<i;
  else if(include3(i)) cout<<" "<<i;
 }
 cout<<endl;
 return 0;
}


#include<iostream>
#include<vector>

using namespace std;
typedef long long ll;
const ll N = 100005;

int main(){
    //入力
    vector<int> v;
    ll n, m, A[N]; cin >> n >> m;
    for (int i = 0; i < m; i++)
        cin >> A[i];
    vector<int> odds;
    vector<int> ans_A;
    for (int i = 0; i < m; i++) //奇数の抽出
    {
        if (A[i]%2==1)
        {
            odds.emplace_back(A[i]);
        }
        if (odds.size() == 3)
        {
            cout << "Impossible";
            return 0;
        }
    }
    if (odds.size() == 0)
    {
        for (int i = 0; i < m; i++)
        {
            ans_A.emplace_back(A[i]);
        }
    }
    else if (odds.size() != 0)
    {
        ans_A.emplace_back(odds[0]);
        for (int i = 0; i < m; i++)
        {
            if(A[i] % 2 == 1) continue;
            ans_A.emplace_back(A[i]);
        }
        if (odds.size() == 2)
        {
            ans_A.emplace_back(odds[1]);
        }
    }
    for (int i = 0; i < ans_A.size(); i++)
    {
        cout << ans_A[i] << " ";   //aの表示
    }
    cout << endl;
    int B_size = ans_A.size();
    if (ans_A.size()==1){
        B_size++;
        ans_A.emplace_back(1);
    }
    else
    {
        ans_A[ans_A.size()-1]++;
    }
    if (ans_A[0] == 1){
        B_size--;
    }
    cout << B_size << endl; //bの大きさの表示

    if (ans_A[0] != 1)
    {
        cout << ans_A[0]-1 << " ";
    }

    for (int i = 1; i < ans_A.size(); i++)
    {
        cout << ans_A[i] << " " ;
    }
    cout << endl;
}


#include <iostream>
using namespace std;

int func(int x, int y, int z){
//  cout << x << " " << y << " " << z << endl;
  if (x==y||y==z||z==x) return false;
  if (x+y>z&&y+z>x&&z+x>y){
//    cout << "ok" << endl;
    return true;
  }
  return false;
}

int main(void){
  int n,ans;
  int len[200];

  cin >> n;
  for (int i=0; i<n; i++) cin >> len[i];
  ans = 0;
  for (int i=0; i<n; i++){
    for (int j=i+1; j<n; j++){
      for (int k=j+1; k<n; k++){
        ans += func(len[i], len[j], len[k]);
      }
    }
  }
  cout << ans << endl;
  return 0;
}

#define DIN freopen("input.txt","r",stdin);
#define DOUT freopen("output.txt","w",stdout);
#include <bits/stdc++.h>
#include <cstdio>
#define mem(a,b) memset(a,b,sizeof(a))
#define REP(i,a,b) for(int i=(a);i<=(int)(b);i++)
#define REP_(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
using namespace std;
typedef long long LL;
typedef std::vector<int> VI;
typedef std::pair<int,int> P;
int read()
{
    int x=0,flag=1; char c=getchar();
    while((c>'9' || c<'0') && c!='-') c=getchar();
    if(c=='-') flag=0,c=getchar();
    while(c<='9' && c>='0') {x=(x<<3)+(x<<1)+c-'0';c=getchar();}
    return flag?x:-x;
}

int main()
{
    int a[105],n;
    n=read();
    REP(i,1,n) a[i]=read();
    sort(a+1,a+n+1);
    int ans=0;
    for(int i=1;i<n;i++)
        for(int j=i+1;j<n;j++)
            for(int k=j+1;k<=n;k++)
                if(a[i]+a[j]>a[k] && a[i]!=a[j] && a[j]!=a[k])
                    ans++;
    cout<<ans;

    return 0;
}


#include "bits/stdc++.h"

using namespace std;

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

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

int main(){
    int dp[50];
    rep(i,50)dp[i]=0;
    dp[0]=1;
    rep(i,40){
        dp[i+1]+=dp[i];
        dp[i+2]+=dp[i];
        dp[i+3]+=dp[i];
    }

    int n;
    while(cin>>n){
        if(n==0)break;
        int num = (int)((dp[n]-1)/3650)+1;
        cout<<num<<endl;
    }

}

#include <iostream>
#include <algorithm>
using namespace std;
int main(){
      int tmp;
      int dp[100];
      cin>> tmp;
      do{
            fill(dp,dp+100,0);
            dp[0] = 1;
            for (int i = 0; i<tmp;i++)
            {
                  for(int j = 1;j < 4;j++)
                        dp[i+j] += dp[i];
            }
            cout << dp[tmp]/3650 + 1<<endl;
            cin >> tmp;
      }while(tmp);

}


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

using namespace std;

#define INF 1e9
#define MAXN 100005
#define MAXM 100005
#define MOD 1000000007
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pii pair<int, int>

ll ans;
int N;

void solve(){
    cout << 180 * (N - 2) << endl;
}

int main(){
    cin >> N;

    solve();
}


#include <iostream>

#define MAX 1000

using namespace std;

class Contest {
public:
  Contest() {}
  Contest(int _id, int _cost, int _vote) {
    id = _id;
    cost = _cost;
    vote = _vote;
  }

  bool compare_cost(int _cost) {
    return cost <= _cost;
  }

  bool compare_vote(int _vote) {
    return vote < _vote;
  }

  void output_id() {
    cout << id << endl;
  }

  void voting(int _vote) {
    vote += _vote;
  }

  int getVote() {
    return vote;
  }

private:
  int id, cost, vote;
};

int main()
{
  int n, m;
  cin >> n >> m;

  Contest *contests = new Contest[MAX];
  int cost;
  for(int i = 0; i < n; i += 1){
    cin >> cost;
    contests[i] = Contest(i+1, cost, 0);
  }

  for(int i = 0; i < m; i += 1) {
    cin >> cost;

    for(int j = 0; j < n; j += 1) {
      if(contests[j].compare_cost(cost)){
	contests[j].voting(1);
	break;
      }
    }
  }

  Contest contest = contests[0];
  for(int i = 1; i < n; i += 1) {
    if(contest.compare_vote(contests[i].getVote())){
      contest = contests[i];
    }
  }

  contest.output_id();

  delete[] contests;

  return 0;
}

#include <iostream>
using namespace std;

int main() {
int a[1000],t[1000];int n,m;
cin >> n >> m;
for(int i = 0;i<1000;i++){
	a[i]= 0;
	t[i]= 0;
}
for(int i = 0;i<n;i++){
	cin >> a[i];
}
for(int i = 0;i<m;i++){
	int p;
	cin >> p;
	int o = 0;
	while(a[o]>p){o++;}
	t[o]++;
}
int ans = 0;
for(int i = 0;i<n;i++){
	if(t[ans]<t[i]){ans = i;}
}
cout << ans+1 << endl;
	return 0;
}


#include<bits/stdc++.h>

const int MOD = 1e9 + 7;

using namespace std;

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

  int D;
  cin >> D;

  vector<vector<vector<long long>>> dp(K.size() + 1, vector<vector<long long>>(D, vector<long long>(2, 0)));
  dp[0][0][1] = 1;
  for(int i = 0; i < (int)K.size(); i++){
    for(int j = 0; j < D; j++){
      for(int k = 0; k < 10; k++){
        dp[i + 1][(j + k) % D][0] += dp[i][j][0];
        if(k < K[i] - '0'){
          dp[i + 1][(j + k) % D][0] += dp[i][j][1];
        }else if(k == K[i] - '0'){
          dp[i + 1][(j + k) % D][1] += dp[i][j][1];
        }
        dp[i + 1][(j + k) % D][0] %= MOD;
        dp[i + 1][(j + k) % D][1] %= MOD;
      }
    }
  }

  cout << ((dp[K.size()][0][0] + dp[K.size()][0][1] - 1) % MOD + MOD) % MOD << endl;

  return 0;
}

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int mod=1e9+7;
string sa;
ll d,dp[10010][110];
ll dfs_dp(int pos,ll sta,bool lim)
{
	if(pos==sa.size())
		return sta%d==0;
	if(!lim && dp[pos][sta]!=-1)
		return dp[pos][sta];
	ll up=lim?(sa[pos]-'0'):9,res=0;
	for(int i=0;i<=up;i++)
		res=(res+dfs_dp(pos+1,(sta+i)%d,lim&(i==up)))%mod;
	if(!lim)
		dp[pos][sta]=res;
	return res;
}
ll work()
{
	return dfs_dp(0,0,1);
}
int main()
{
	memset(dp,-1,sizeof(dp));
	cin>>sa>>d;
	cout<<(work()+mod-1)%mod<<endl;
	return 0;
}


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

void solve(std::vector<long long> H, std::vector<long long> M, long long K){
    int t = (H[1] * 60 + M[1]) - (H[0] * 60 + M[0]) - K;
    cout << t << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::vector<long long> H(2);
    std::vector<long long> M(2);
    for(int i = 0 ; i < 2 ; i++){
        scanf("%lld",&H[i]);
        scanf("%lld",&M[i]);
    }
    long long K;
    scanf("%lld",&K);
    solve(std::move(H), std::move(M), K);
    return 0;
}

#include<stdio.h>

int main()
{
	int h1, m1, h2, m2, k, ans;

	scanf("%d %d %d %d %d", &h1, &m1, &h2, &m2, &k);

	int sum1 = (h1 * 60) + m1;
	int sum2 = (h2 * 60) + m2;

	if(sum1 > sum2){
		ans = sum1 - sum2 - k;
	}else{
		ans = sum2 - sum1 - k;
	}
	printf("%d\n", ans);
}


#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  string s;
  cin >> s;

  set<ll> mi;
  rep(i, 26) mi.insert(i);

  ll n = s.size();
  string ans = "";
  rep(i, n) {
    ll idx = s[i] - 'a';
    if (mi.find(idx) != mi.end()) {
      mi.erase(idx);
      ans += s[i];
    } else {
      auto citr = mi.begin();
      ans += *citr + 'a';
      mi.erase(citr);
    }
  }  // i

  if (s == ans) {
    if (!mi.empty()) {
      rep(i, 26) {}
      ans += *mi.begin() + 'a';
    } else {
      vector<char> tst;
      rep(i, 26) tst.push_back(s[i]);
      next_permutation(tst.begin(), tst.end());
      string cmp = "";
      for (char c : tst) cmp += c;
      if (cmp < s) {
        puts("-1");
        return 0;
      } else {
        rep(i,26) if(ans[i] != cmp[i]){
          ans = cmp.substr(0, i+1);
          break;
        }
      }
    }
  }

  cout << ans << endl;

  return 0;
}

#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 2100100100;
const int MOD = 1e9 + 7;

int N;

int main() {
    cin >> N;
    vector<ll> A(N);
    vector<ll> sum(N + 1, 0);  // sum[i+1] := A[i] までの和
    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
        sum[i + 1] = sum[i] + A[i];
    }

    ll P, Q, R, S;
    ll ans = 1e18;
    for (int i = 2; i <= N - 2; i++) {  // [0,i) と[i,N) に分ける
        // [0,id) と [id, i)
        int id = lower_bound(ALL(sum), sum[i] / 2) - sum.begin();
        if (i - id < 1) {
            id--;
        } else {
            if (abs(sum[i] - sum[id - 1] * 2) < abs(sum[i] - sum[id] * 2)) id--;
        }
        P = sum[id];
        Q = sum[i] - sum[id];

        // [i, id2) と[id2, N)
        int id2 = lower_bound(ALL(sum), (sum[N] - sum[i]) / 2 + sum[i]) - sum.begin();
        if (N - id2 < 1) {
            id2--;
        } else {
            if (abs((sum[N] - sum[id2 - 1]) - (sum[id2 - 1] - sum[i])) < abs((sum[N] - sum[id2]) - (sum[id2] - sum[i]))) id2--;
        }
        R = sum[N] - sum[id2];
        S = sum[id2] - sum[i];
        //cout << 0 << " " << id << " " << i << " " << id2 << " " << N << " " << P << " " << Q << " " << R << " " << S << " " << ans << endl;
        chmin(ans, max(P, max(Q, max(R, S))) - min(P, min(Q, min(R, S))));
    }
    cout << ans << endl;

    return 0;
}


#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

typedef long long Int;

int main(){
    map<int,Int> table;
    vector<int> ids;
    int n;
    bool flug;

    while(cin >> n, n != 0){
        flug = false;
        table.clear();
        ids.clear();

        for(int i=1; i<=n; i++){
            int id;
            Int tanka;
            Int number;
            cin >> id >> tanka >> number;
            table[id] += (tanka*number);
            vector<int>::iterator fIter = find(ids.begin(), ids.end(), id);
            if(fIter == ids.end()){
                ids.push_back(id);
            }
        }

        for(vector<int>::iterator Iter = ids.begin(); Iter != ids.end(); Iter++){
            if(table[*Iter] >= 1000000){
                cout << *Iter << endl;
                flug = true;
            }
        }

        if(flug == false){
            cout << "NA" << endl;
        }
    }

    return 0;
}

#include <iostream>

int main(int argc, char const* argv[])
{
  int i, n, a, b, a_score, b_score;

  while (true) {
    a_score = 0;
    b_score = 0;

    std::cin >> n;
    if (n == 0) { break; }

    for (i = 0; i < n; i++) {
      std::cin >> a;
      std::cin >> b;

      if (a > b) {
        a_score += (a + b);
      } else if (b > a) {
        b_score += (a + b);
      } else {
        a_score += a;
        b_score += b;
      }
    }
    std::cout << a_score << " " << b_score << std::endl;
  }

  return 0;
}


#include <stdio.h>
#include<bits/stdc++.h>
using namespace std;
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#define mx 1000008

#define pii pair<int,int>
#define pi acos(-1.0)
#define pb push_back
#define ss second
#define ff first
typedef long long int ll;
///adjacent move
int fx[4]={0,+1,0,-1};
int fy[4]={+1,0,-1,0};
///knight
ll prime[mx];
void seive()
{
    for(int i=2;i<mx;i+=2) prime[i]=2;
    for(int i=3;i<mx;i+=2) prime[i]=i;
    ll sq=sqrt(mx);
    for(int i=3;i<=sq;i+=2){
        if(prime[i]==i){
            for(int j=i*i;j<mx;j+=i){
                if(prime[j]==j) prime[j]=i;
            }
        }
    }
}
int a[1000004];
ll f[2000004];
ll po[2000004];
int main()
{
    //seive();
    int t=1;
    //cin>>t;

    int c=0;
    vector<ll>vec;
    for(int i=2;i<mx;i++){
        if(prime[i]==i){
            vec.push_back(i);
        }
    }
    while(t--){
        ll n,m;

        cin>>n;

        ll a[n*2+7];
        for(int i=1;i<=2*n;i++) cin>>a[i];
        ll sum=0;
        sort(a+1,a+2*n+1);
        for(int i=1;i<=2*n;i++){
            if(i&1) sum+=a[i];
        }
        cout<<sum<<endl;
    }
}

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

int main () {
	int n;
  	cin >> n;
  	vector <int> L(2*n);

  	for (int i=0; i<L.size(); i++)
      	cin >>  L[i];

  	sort (L.begin(), L.end());
  	int res = 0;
  	for (int i=0; i<L.size(); i+=2) {
    	res += min (L[i], L[i+1]);
    }

  	cout << res;

}


#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i ++)
using namespace std;
using ll = long long;
using PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;

int main() {
    int H,W; cin >> H >> W;
    vector<vector<int>> A(H,vector<int>(W));
    rep(i,H)rep(j,W) cin >> A[i][j];
    vector<vector<int>> B(H,vector<int>(W));
    rep(i,H)rep(j,W) cin >> B[i][j];

    vector<vector<int>> before(W,vector<int>(12800,0));
    vector<vector<int>> now(W,vector<int>(12800,0));
    before[0][6400] = 1;
    rep(i,H) {
        rep(j,W) {
            int a = A[i][j];
            int b = B[i][j];
            rep(k,12800) {
                if (before[j][k] == 0) continue;
                if (0 <= k + a - b && k + a - b < 12800) {
                    if (j + 1 < W) before[j + 1][k + a - b] = 1;
                    if (i + 1 < H) now[j][k + a - b] = 1;
                }
                if (0 <= k + b - a && k + b - a < 12800) {
                    if (j + 1 < W) before[j + 1][k + b - a] = 1;
                    if (i + 1 < H) now[j][k + b - a] = 1;
                }
            }
        }
        if (i == H - 1) break;
        swap(before,now);
        now = vector<vector<int>>(W,vector<int>(12800,0));
    }
    //rep(i,W)for (int j = 6200;j< 6500;j ++) printf("before[%d][%d]   %d   ",i,j,before[i][j]);

    int ans = INF;
    int a = A[H - 1][W - 1],b = B[H - 1][W - 1];
    rep(i,12800) {
        if ((0 <= i + a - b && i + a - b < 12800 && before[W - 1][i + a - b])
            || (0 <= i + b - a && i + b - a < 12800 && before[W - 1][i + b - a])) {
                ans = min(ans,abs(i - 6400));
            }
    }
    cout << ans << endl;
    return 0;
}

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
#define endn "\n"
typedef pair<int,int> P;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const int MOD = 1000000007;
//const int MOD = 998244353;
template<class T> inline int add(T& a, T b, T M = MOD){a=(a+M)%M;b=(b+M)%M;a=(a+b)%M;return a;};
template<class T> inline int mul(T& a, T b, T M = MOD){if(a>=M)a%=M;if(b>=M)b%=M;a*=b;if(a>=M)a%=M;return a;};
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
const string abc="abcdefghijklmnopqrstuvwxyz";
const string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)};

////////////////////////////////////////////////////////////////////
///////////////////////___modpow___////////////////////
ll modpow(ll a,  ll n, const ll &MOD = MOD){
  ll ret = n == 0 ? 1 : modpow(a, n/2, MOD);
  (ret *= ret);
  if(n%2)((ret *= a));
  return ret;
}
///////////////////////___modinv___////////////////////
ll modinv(ll d, const ll &MOD = MOD){
  return modpow(d, MOD-2, MOD);
}

vector<ll> fac, finv, inv;
void COMinit(const int MAX = 5000000, const ll &MOD = MOD){
  fac.resize(MAX);finv.resize(MAX);inv.resize(MAX);
  fac[0] = fac[1] = finv[0] = finv[1] = inv[1] = 1;
  repd(i,2,MAX){
    fac[i] = fac[i-1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
    finv[i] = finv[i-1] * inv[i] % MOD;
  }
}
ll COM(int n, int k){
  if(n < k)return 0;
  if(n < 0 || k < 0)return 0;
  return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

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

int h,w,a[100][100],b[100][100],c[100][100];
bool dp[85][85][20000];
signed main(){
  cin>>h>>w;
  rep(i,h)rep(j,w)cin>>a[i][j];
  rep(i,h)rep(j,w)cin>>b[i][j];
  rep(i,h)rep(j,w)c[i][j] = abs(a[i][j] - b[i][j]);
  dp[0][0][abs(c[0][0])] = true;
  rep(i,h){
    rep(j,w){
      rep(d,15000){
        if(!dp[i][j][d])continue;
        dp[i][j+1][d+c[i][j+1]] = j+1 < w;
        dp[i][j+1][abs(d-c[i][j+1])] = j+1 < w;
        dp[i+1][j][d+c[i+1][j]] = i+1 < h;
        dp[i+1][j][abs(d-c[i+1][j])] = i+1 < h;
      }
    }
  }
  rep(i,15000){
    if(dp[h-1][w-1][i]){
      cout << i << endl;return 0;
    }
  }
}


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

int main(){
  int n;
  cin>>n;
  string s;
  cin>>s;
  vector<int>sumW(n+1,0);
  for(int i=0;i<n;i++){
    if(s[i]=='W'){
      sumW[i+1]=sumW[i]+1;
    }
    else{
      sumW[i+1]=sumW[i];
    }
  }
  vector<int>sumE(n+1,0);
  for(int i=0;i<n;i++){
    if(s[i]=='E'){
      sumE[i+1]=sumE[i]+1;
    }
    else{
      sumE[i+1]=sumE[i];
    }
  }
  int minn=1e9;
  for(int i=0;i<n+1;i++){
    minn=min(minn,(sumW[i]+sumE[n]-sumE[i]));
  }
  cout<<minn<<endl;

}

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

int main() {
  int N;
  cin >> N;
  vector<int>data(N);
  for(int i;i<N;i++){
    char a;
    cin >> a;
    if(a=='W') data.at(i)=0;
    else data.at(i)=1;
  }
  vector<int>r(N);
  int one=0;
  for(int i=1;i<N;i++){
    one+=data.at(i);
  }
  r.at(0)=one;
  for(int i=1;i<N;i++){
    int a=0;
    if(data.at(i)==1) a--;
    if(data.at(i-1)==0) a++;
    r.at(i)=r.at(i-1)+a;
  }
  sort(r.begin(),r.end());

  cout << r.at(0) << endl;
}


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

int main(){
  int n;
  cin>>n;
  int elem[n];
  int cnt=0;
  for(int i=0;i<n;i++){
    cin>>elem[i];
  }
  for(int i=0;i<n-1;++i){
    for(int j=0;j<n-1-i;++j){
      if(elem[j]>elem[j+1]){
	++cnt;
	elem[j]^=elem[j+1];
	elem[j+1]^=elem[j];
	elem[j]^=elem[j+1];
      }
    }
  }
  for(int i=0;i<n;++i){
    cout<<elem[i];
    if(i!=n-1)cout<<" ";
    else cout<<endl;
  }
  cout<<cnt<<endl;
}

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int bubble_sort(int n,vector<int> &vec);

int main() {
	int n,count;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	count=bubble_sort(n,a);
	for (int i = 0; i < n; i++) {
		cout << a[i];
		if (i != n - 1) { cout << " "; }
	}
	cout << "\n" << count << endl;

}

int bubble_sort(int n,vector<int> &vec) {
	int count = 0;
	bool flag = true;
	while (flag) {
		flag = false;
		for (int j = 1; j < n; j++) {
			if (vec[j] < vec[j - 1]) {
				swap(vec[j], vec[j - 1]);
				count++;
				flag = true;
			}
		}
	}
	return count;
}


//g++ -std=c++14 test.cpp -o test.out

//問題URL
//https://atcoder.jp/contests/agc019/tasks/agc019_b

//参考：
//https://oraclesqlpuzzle.ninja-web.net/kyoupro/kyoupro-10-019-b.html

//ポイント：
//A[i]とA[j]が同じ文字の時、
//それに内包される文字列を反転させたものと
//A[i],A[j]を含んだ文字列を反転させても被るので除外する
//例えば
//文字列eabceにおいてはabc,eabceどちらを反転させても
//同じecbaeができる

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map>
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;

#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

string S;

LL ans = 0;

void solve(){
	LL N = S.size();
	ans = N*(N-1)/2;
	vector<LL> alpha(26,0);
	for(int i=0;i<N;i++) alpha[S[i]-'a']++;
	for(int i=0;i<26;i++) ans -= alpha[i]*(alpha[i]-1)/2;
	ans++;
}

int main(){
    cin >> S;

    solve();

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

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
char s[200005];
int n,cnt[26];
ll ans=0;
int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	for(int i=1;i<=n;i++)cnt[s[i]-'a']++;
	ans=1;
	for(int i=0;i<26;i++)for(int j=i+1;j<26;j++)ans+=1ll*cnt[i]*cnt[j];
	printf("%lld\n",ans);
	return 0;
}


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

int main(){
	int n,k;
	cin>>n>>k;
	vector<int>arr(n);
	for(int i=0; i<n; i++) cin>>arr[i];
	for(int i=0; i<n; i++) arr[i]++;
	for(int i=1; i<n; i++) arr[i]+=arr[i-1];
	int maxsum = arr[k-1];
	for(int i=k; i<n; i++) maxsum = max(maxsum,arr[i]-arr[i-k]);
	cout<<maxsum/2<<".";
	if(maxsum%2) cout<<5;
	else cout<<0;
	cout<<"00000000";
}

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

using namespace std;
using ll = long long;
using v1 = vector<int>;
using vl = vector<long long>;
using v2 = vector<vector<int>>;
using v3 = vector<vector<char>>;

int main(){
    v1 a(1001, 0);
    for(int i = 1; i <1001; i++){
        a[i] = a[i-1] + i;
    }
    int n, k;
    cin >> n >> k;
    vector<double> q(n+1, 0);
    q[0] = 0;
    for(int i = 1; i<=n; i++){
        int p;
        cin >> p;
        double sum = static_cast<double>(a[p]) / static_cast<double>(p) + q[i-1];
        q[i] = sum;
    }
    int j = 0;
    double ans = 0;
    for(int i = k; i <= n; i++){
        ans = max(ans, q[i]-q[j]);
        j++;
    }
    cout <<fixed << setprecision(15) <<  ans << endl;

}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int MOD = 1e9+7;
using ll = long long;
using vi = vector<int>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(x) x.begin(), x.end()

int main() {
  vi a(3);
  rep(i,3){
    cin >> a.at(i);
  }
  sort(ALL(a));
  int b,ans=0;
  cin >> b;
  rep(i,b){
    a.at(2)*=2;
  }
  cout << a.at(0)+a.at(1)+a.at(2);
}

#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;

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

	vector<int> v(3);
	v.at(0) = A;
	v.at(1) = B;
	v.at(2) = C;
	sort(v.begin(), v.end());

	int n = v.back();
	while (K) {
		n *= 2;
		K--;
	}

	cout << v.at(0) + v.at(1) + n << endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;

#define MAX_N 200001

long long par2[MAX_N]; // 親
long long rankuf2[MAX_N]; // 木の深さ
// n要素で初期化
void init2(long long n) {
	for (long long i = 0; i < n; i++) {
		par2[i] = i;
    rankuf2[i] = 0;
	}
}
// 木の根を求める
long long find2(long long x) {
	if (par2[x] == x) {
		return x;
	} else {
		return par2[x] = find2(par2[x]);
	}
}
// xとyの属する集合を併合
void unite2(long long x, long long y) {
	x = find2(x);
	y = find2(y);
	if (x == y) return;
	if (rankuf2[x] < rankuf2[y]) {
		par2[x] = y;
	} else {
		par2[y] = x;
		if (rankuf2[x] == rankuf2[y]) rankuf2[x]++;
	}
}
// xとyが同じ集合に属するか否か
bool same2(long long x, long long y) {
	return find2(x) == find2(y);
}

long long par[MAX_N]; // 親
long long rankuf[MAX_N]; // 木の深さ
// n要素で初期化
void init(long long n) {
	for (long long i = 0; i < n; i++) {
		par[i] = i;
    rankuf[i] = 0;
	}
}
// 木の根を求める
long long find(long long x) {
	if (par[x] == x) {
		return x;
	} else {
		return par[x] = find(par[x]);
	}
}
// xとyの属する集合を併合
void unite(long long x, long long y) {
	x = find(x);
	y = find(y);
	if (x == y) return;
	if (rankuf[x] < rankuf[y]) {
		par[x] = y;
	} else {
		par[y] = x;
		if (rankuf[x] == rankuf[y]) rankuf[x]++;
	}
}
// xとyが同じ集合に属するか否か
bool same(long long x, long long y) {
	return find(x) == find(y);
}

int main(){
	long long K;
	long long N;
	long long L;
	scanf("%lld",&N);
	scanf("%lld",&K);
	init(N+1);
	init2(N+1);
	vector<long long> q(K-1+1);
	vector<long long> p(K-1+1);
	scanf("%lld",&L);
	vector<long long> r(L-1+1);
	vector<long long> s(L-1+1);
	for(int i = 0 ; i <= K-1 ; i++){
		scanf("%lld",&p[i]);
		scanf("%lld",&q[i]);
		unite(p[i]-1, q[i]-1);
	}
	for(int i = 0 ; i <= L-1 ; i++){
		scanf("%lld",&r[i]);
		scanf("%lld",&s[i]);
		unite2(r[i]-1, s[i]-1);
	}
	map<P, ll> m;
	rep(i, N) {
		m[P(find(i), find2(i))]++;
	}
	ll cnt = 0;
	rep(i, N-1) {
		cout << m[P(find(i), find2(i))] << " ";
	}
	cout << m[P(find(N-1), find2(N-1))] << endl;
	return 0;
}

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


#include <stdio.h>
char zf1[1000010],zf2[1000010];
struct SZt
{
	int l,r,h;
	SZt(){}
	SZt(int L,int R,int H)
	{
		l=L;
		r=R;
		h=H;
	}
};
SZt dl[1000010];
int main()
{
//	freopen("a.in","r",stdin);
//	freopen("game.out","w",stdout);
	int n,jg=0,he=0,ta=0,py=0;
	scanf("%d%s%s",&n,zf1,zf2);
	bool bt=false;
	for(int i=0;i<n;i++)
	{
		if(zf1[i]!=zf2[i])
		{
			bt=true;
			break;
		}
	}
	if(!bt)
	{
		printf("0\n");
		return 0;
	}
	for(int i=n-1;i>=0;i--)
	{
		while(he<ta&&dl[he].l-py>i)
			he+=1;
		if(he<ta)
		{
			if(dl[he].h+py+1>jg)
				jg=dl[he].h+py+1;
			if(i>0&&zf2[i]==zf2[i-1])
				continue;
			py+=1;
			dl[he].r=i-1+py;
			int la=dl[ta-1].l-py;
			while(la>=0&&zf1[la]!=zf2[i])
				la-=1;
			if(la==-1)
			{
				printf("-1");
				return 0;
			}
			dl[ta]=SZt(la+py,dl[ta-1].r-1,1-py);
			ta+=1;
		}
		else
		{
			py=0;
			if(jg<1)jg=1;
			if(i>0&&zf2[i]==zf2[i-1])
				continue;
			int la=i;
			while(la>=0&&zf1[la]!=zf2[i])
				la-=1;
			if(la==i)continue;
			if(la==-1)
			{
				printf("-1");
				return 0;
			}
			dl[ta++]=SZt(la,i-1,1);
		}
	}
	printf("%d",jg);
	return 0;
}

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<algorithm>
using namespace std;
int n,x[1000010],p;
char s[1000010],t[1000010];
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int i,j,k,l;
	scanf("%d%s%s",&n,&s,&t);
	for(i=n-1,j=n,k=0,l=0;i>=0;i--)
	  {
	   if(j>i && t[i]!=s[i])
	     j=i;
	   if(j<=i && t[i]!=s[j])
	     {
	      for(;j>=0 && t[i]!=s[j];j--);
	      if(j<0)
	        {
	         printf("-1\n");
	         return 0;
	        }
	      k++;
	      l++;
	      x[j+l]++;
	      p=max(p,k);
	     }
	   k-=x[i+l];
	   x[i+l]=0;
      }
    printf("%d\n",p);
	return 0;
}


#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<functional>
#include<vector>
#include<queue>
using namespace std;
#define f(i,n) for(int i=0;i<(int)n;i++)
#define MOD 1000000009
struct dice{
	int up;
	int down;
	int east;
	int west;
	int north;
	int south;
};
dice a, b;
dice d[100];
char s[101]="NNNNENWNNNNENWNNNNENWNNNNENWENNNNWWNNNNE";
int x;
dice  input(){
	dice c;
	scanf("%d", &x);
	c.up = x;
	scanf("%d", &x);
	c.south = x;
	scanf("%d", &x);
	c.east = x;
	scanf("%d", &x);
	c.west = x;
	scanf("%d", &x);
	c.north = x;
	scanf("%d", &x);
	c.down = x;
	return c;
}
void nr(){
			x = a.north;
			a.north = a.up;
			a.up = a.south;
			a.south = a.down;
			a.down = x;
			return;
}
void sr(){
			x = a.south;
			a.south = a.up;
			a.up = a.north;
			a.north = a.down;
			a.down = x;
			return;
}
void er(){
	x = a.east;
	a.east = a.up;
	a.up = a.west;
	a.west = a.down;
	a.down = x;
	return;
}
void wr(){
	x = a.west;
	a.west = a.up;
	a.up = a.east;
	a.east = a.down;
	a.down = x;
	return;
}
bool comp(){
	if (a.up == b.up&&a.north == b.north&&a.east == b.east&&a.down == b.down&&a.south == b.south&&a.west == b.west)return true;
	else return false;
}
int main(void){
	int n,m;
	scanf("%d", &m);
	f(i, m)d[i] = input();
	n = strlen(s);
	bool ans = false;
	for (int j = 0; j < m; j++){
		for (int k = j + 1; k < m; k++){
	a = d[j];
	b = d[k];
f(i, n){
		if (s[i] == 'N'){
			nr();
		}
		else if (s[i] == 'S'){
			sr();
		}
		else if (s[i] == 'E'){
			er();
		}
		else if (s[i] == 'W'){
			wr();
		}
		ans = comp();
		if (ans == true)break;
	}
if (ans == true)break;
		}
if (ans == true)break;
	}
		if(ans==true)printf("No\n");
		else printf("Yes\n");

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  ll h,m;
  cin >> h >> m;
  ll s=h*60+m;
  cin >> h >> m;
  ll g=h*60+m;
  ll k;
  cin >> k;
  cout << g-s-k << endl;
}

#include<bits/stdc++.h>
#define For(i,x,y) for (register int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (register int i=(x);i<(y);i++)
#define Dow(i,x,y) for (register int i=(x);i>=(y);i--)
#define Debug(v) for (auto i:v) printf("%lld ",i);puts("")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fil(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pa;
typedef pair<ll,ll> PA;
typedef vector<int> poly;
inline ll read(){
    ll x=0,f=1;char c=getchar();
    while ((c<'0'||c>'9')&&(c!='-')) c=getchar();
    if (c=='-') f=-1,c=getchar();
    while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    return x*f;
}

int h1,m1,h2,m2,k;

int main(){
	h1=read(),m1=read(),h2=read(),m2=read(),k=read();
	printf("%d\n",h2*60+m2-h1*60-m1-k);
}


#include <algorithm>
#include <functional>
#include <iostream>
#include <vector>

using namespace std;

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

    auto gcd = [](int mm, int nn) {
        function<int(int, int)> f = [&f](int m, int n) {
            if (n == 0) {
                return m;
            }
            else {
                return f(n, m % n);
            }
        };
        return f(max(mm, nn), min(mm, nn));
    };
    auto gcd3 = [gcd](int n, int m, int o) { return gcd(n, gcd(m, o)); };
    vector<int> r;
    if (n == 2) {
        int a, b;
        cin >> a >> b;
        const auto s = gcd(a, b);
        for (int i = 1; i <= s; ++i) {
            if (a % i == 0 && b % i == 0) {
                r.push_back(i);
            }
        }
    }
    else {
        int a, b, c;
        cin >> a >> b >> c;
        const auto s = gcd3(a, b, c);
        for (int i = 1; i <= s; ++i) {
            if (a % i == 0 && b % i == 0 && c % i == 0) {
                r.push_back(i);
            }
        }
    }
    for (auto i : r) {
        cout << i << endl;
    }
}


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

// Template Headers {{{
using pii = pair<int, int>; using vpii = vector<pii>;
using vi = vector<int>; using vvi = vector<vi>;
using ll = long long; using vll = vector<long long>;
template <class T> using min_queue = priority_queue<T, vector<T>, greater<T>>;
template <class T> istream &operator>>(istream &, vector<T> &);
template <class T> ostream &operator<<(ostream &, const vector<T> &);
template <class T, class U> istream &operator>>(istream &, pair<T, U> &);
template <class T, class U> ostream &operator<<(ostream &, const pair<T, U> &);
template <class T> struct Inf { static constexpr T inf() { return std::numeric_limits<T>::has_infinity() ? std::numeric_limits<T>::infinty() : std::numeric_limits<T>::max(); } };
template <> struct Inf<int> { static constexpr int inf() { return 0x3f3f3f3f; } };
template <> struct Inf<long long> { static constexpr long long inf() { return 0x3f3f3f3f3f3f3f3fLL; } };
constexpr int INF = Inf<int>::inf(); constexpr ll BINF = Inf<ll>::inf();
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// }}}

int solve() {
	int n, m; cin >> n >> m;
	vvi g(n);
	for (int i = 0; i < m; i++) {
		int u, v; cin >> u >> v;
		g[u].push_back(v); g[v].push_back(u);
	}
	int timer = 0;
	vi stTime(n, INF), enTime(n, INF);
	vi low(n);
	vi ans(n);
	function<void(int, int)> dfs = [&] (int u, int p) {
		stTime[u] = timer++;
		low[u] = stTime[u];
		int jai = 0;
		for (int v : g[u]) {
			if (v == p) continue;
			if (stTime[v] >= INF) {
				// tree edge
				dfs(v, u);
				low[u] = min(low[u], low[v]);
				if (low[v] >= stTime[u] && p != -1) ans[u] = 1;
				jai++;
			} else if (enTime[v] >= INF) {
				// back edge
				low[u] = min(low[u], stTime[v]);
			}
		}
		enTime[u] = timer;
		if (p == -1 && jai > 1) ans[u] = 1;
	};
	dfs(0, -1);
	for (int i = 0; i < n; i++) if (ans[i]) cout << i << endl;
	return 0;
}

// Template Main {{{
int main() {
	ios::sync_with_stdio(0);
	// precompute();
	// int t; cin >> t; for (int i=1;i<=t;i++)
	solve();
	// cout << "Case #" << i << ": ", solve();
	return 0;
}

template <class T> istream &operator>>(istream &is, vector<T> &v) {
	for (auto it=v.begin();it!=v.end();++it) is >> *it;
	return is;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
	for (auto it=v.begin();it!=v.end();) os << *it, os << " \n"[++it==v.end()];
	return os;
}

template <class T, class U> istream &operator>>(istream &is, pair<T, U> &p) {
	return is >> p.first >> p.second;
}

template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) {
	return os << p.first << ' ' << p.second;
}
// }}}

// vim: fdm=marker

#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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

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

vector<int> problems;
vector<int> bonus;

int solve(const int bits, const int D, const ll G) {
    ll score = 0;
    int ans = 0;
    priority_queue<int> que;
    for (int i = 0; i < D; i++) {
        if (bits & (1 << i)) {
            score += (i + 1) * 100 * problems[i];
            score += bonus[i];
            ans += problems[i];
        } else {
            for (int j = 0; j < max(0, problems[i] - 1); j++) {
                que.push((i + 1) * 100);
            }
        }
    }

    while (!que.empty() && score < G) {
        auto v = que.top();
        que.pop();
        score += v;
        ans++;
    }

    if (score < G) {
        return -1;
    } else {
        return ans;
    }
}

int main(void) {
    int D;
    ll G;
    cin >> D >> G;

    problems.resize(D);
    bonus.resize(D);
    for (int i = 0; i < D; i++) {
        cin >> problems[i] >> bonus[i];
    }

    int ans = INT_MAX / 2;

    for (int bits = 0; bits < (1 << D); bits++) {
        int cand = solve(bits, D, G);
        if (cand >= 0) {
            // printf("bits: %x, required: %d\n", bits, cand);
            chmin(ans, cand);
        }
    }

    cout << ans << endl;

    return 0;
}


///A drunk man will find his way home, but a drunk bird may get lost forever...
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
//template <typename T>
//using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef tree<double, null_type, less_equal<double>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define int long long
typedef long long ll;
typedef double dd;
typedef long double ldd;
typedef pair <int, int> pii;
typedef pair <pii , int> ppii;
#define pb push_back
#define pf push_front
#define ppb pop_back()
#define ppf pop_front()
#define f first
#define s second
#define sz(x) (int)x.size()
#define smin(x , y) x = min(x , y)
#define smax(x , y) x = max(x , y)
#define mp make_pair
#define all(x) x.begin() , x.end()
#define debug(x) cerr<< #x << " = " << x << endl
#define ddebug(x, y) cerr<< #x << " = " << x  << ", " << #y << " = " << y << endl
#define uop(x, y) pii(min(x, y), max(x, y))
#define out return cout << "No" << endl, 0
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")
const int mx = 6e3 + 10;
int n, m, fact[mx], inv[mx], C[mx][mx], M2[mx], M3[mx], p[mx];
int _pow(int a, int b){
	if(!b)
		return 1;
	return ((_pow((a * a) % m, b >> 1) * ((b & 1) ? a : 1)) % m);
}
void pre(){
	fact[0] = 1;
	for(int i = 1; i <= 3 * n; i++)
		fact[i] = (fact[i - 1] * i) % m;
	inv[3 * n] = _pow(fact[3 * n] , m - 2);
	for(int i = 3 * n - 1; ~i; i--)
		inv[i] = (inv[i + 1] * (i + 1)) % m;
	for(int i = 0; i <= 3 * n; i++)
		for(int j = 0; j <= i; j++)
			C[i][j] = fact[i] * inv[j] % m * inv[i - j] % m;
	M2[0] = 1;
	for(int i = 2; i <= 3 * n; i += 2)
		M2[i] = M2[i - 2] * C[i][2] % m;
	M3[0] = 1;
	for(int i = 3; i <= 3 * n; i += 3)
		M3[i] = M3[i - 3] * C[i][3] % m;
	p[0] = 1;
	for(int i = 1; i <= 3 * n; i++)
		p[i] = p[i - 1] * 2 % m;
	return;
}
int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> m;
	pre();
	int ans = 0;
	for(int a = 0; a <= n; a++)
		for(int b = 0; b <= n; b++){
			int c = 3 * n - 3 * a - 2 * b;
			if(c < b)
				continue;
			int cnt = (C[3 * n][3 * a] * p[a] % m * M3[3 * a] % m * inv[a] % m) % m;
			cnt = cnt * (C[3 * n - 3 * a][2 * b] * M2[2 * b] % m * inv[b] % m) % m;
			ans = (ans + cnt) % m;
		}
	cout << ans << endl;
	return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#define _SCL_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <utility>
#include <algorithm>
#include <functional>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <limits>
#include <numeric>
#include <valarray>
#include <fstream>
#include <array>
#include <random>
#include <unordered_set>
#include <unordered_map>

using namespace std;
using uint = uint32_t;
using LL = int64_t;
using ULL = uint64_t;
using PP = pair<LL, LL>;
template <typename T> using PriorityQ = priority_queue<T, vector<T>, greater<T> >;
#define REP(i, a, n) for(LL i = (a), i##_max_ = (n); i < i##_max_; ++i)
#define REM(i, a, n) for(LL i = (LL)(n) - 1, i##_min_ = (a); i >= i##_min_; --i)
#define FLOAT fixed << setprecision(16)
#define SPEEDUP { cin.tie(NULL); ios::sync_with_stdio(false); }
const int INF = 0x3FFFFFFF;
const LL INFLL = 0x3FFFFFFF3FFFFFFF;
const double INFD = 1.0e+308;
const double EPS = 1.0e-9;

void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
template <class T, class U> istream& operator>>(istream& ist, pair<T, U>& right) { return ist >> right.first >> right.second; }
template <class T, class U> ostream& operator<<(ostream& ost, const pair<T, U>& right) { return ost << right.first << ' ' << right.second; }
template <class T, class TCompatible, size_t N> void Fill(T(&dest)[N], const TCompatible& val) { fill(dest, dest + N, val); }
template <class T, class TCompatible, size_t M, size_t N> void Fill(T(&dest)[M][N], const TCompatible& val) { for (int i = 0; i < M; ++i) Fill(dest[i], val); }
template <class T> T Next() { T buf; cin >> buf; return buf; }
istream& Ignore(istream& ist) { string s; ist >> s; return ist; }
bool Inside(int i, int j, int h, int w) { return i >= 0 && i < h && j >= 0 && j < w; }

#ifdef ONLY_MY_ENVIR
#include "Accumulator.h"
#include "Algebraic.h"
#include "BinaryMatrix.h"
#include "BinaryTree.h"
#include "Bipartite.h"
#include "BIT.h"
#include "Compressor.h"
#include "Decompositions.h"
#include "DynamicMod.h"
#include "Factorization.h"
#include "FFT.h"
#include "FlowSolver.h"
#include "Graph.h"
#include "GraphUtil.h"
#include "IntMod.h"
#include "LazySegmentTree.h"
#include "LIS.h"
#include "Math.h"
#include "MathUtil.h"
#include "Matrix.h"
#include "MinCostFlowSolver.h"
#include "MinMax.h"
#include "Numbers.h"
#include "Optimize.h"
#include "Permutation.h"
#include "Polynomial.h"
#include "Position.h"
#include "Range.h"
#include "Rational.h"
#include "SegmentTree.h"
#include "SegmentTree2D.h"
#include "Sets.h"
#include "Shortest.h"
#include "SlidingWindow.h"
#include "SpanningTree.h"
#include "StringSearching.h"
#include "SuffixArray.h"
#include "Tree.h"
#include "TreeUtil.h"
#include "UnionFind.h"
#include "Util.h"
#include "VectorUtil.h"
#endif

#ifdef __GNUC__
typedef __int128 LLL;
istream& operator>>(istream& ist, __int128& val) { LL tmp; ist >> tmp; val = tmp; return ist; }
ostream& operator<<(ostream& ost, __int128 val) { LL tmp = val; ost << tmp; return ost; }
#endif

int N, MOD;
LL DP[6001][9001];

void add(LL& a, LL b) {
	a += b;
	if (a >= MOD) {
		a -= MOD;
	}
}

int main() {
	cin >> N >> MOD;
	N *= 3;

	const int Q = N / 2;

	DP[0][Q] = 1;
	REP(i, 0, N) {
		REP(k, -(i / 2), i + 1) {
			if (i + 1 <= N) add(DP[i + 1][Q + k + 1], DP[i][Q + k]);
			if (i + 2 <= N) add(DP[i + 2][Q + k - 1], DP[i][Q + k] * (i + 1) % MOD);
			if (i + 3 <= N) add(DP[i + 3][Q + k + 0], DP[i][Q + k] * (i + 1) % MOD * (i + 2) % MOD);
		}
	}

	LL sum = 0;
	REP(k, 0, N + 1) {
		add(sum, DP[N][Q + k]);
	}
	cout << sum << endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pii pair<int,int>
#define pll pair<lli,lli>
#define vi  vector<int>
#define vii vector<pair<int,int>>
#define vll vector<lli>
#define pb  push_back
#define mpr  make_pair
#define ff  first
#define ss  second
#define mod 1000000007
#define pie 3.14159265358979323846264338327950L
#define all(x) x.begin(),x.end()
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define testcase() int t;cin>>t;while(t--)
#define clean(x) memset(x,0,sizeof(x))
#define FOR(x,y) for(int i=x;i<=y;i++)
const lli maxn = 2e5+9;
vector<lli> catlan(int n) {
    vector<lli> dp(n + 1, 0);
    dp[0] = 1;
    dp[1] = 1;
    for (int i = 2; i <= n; i ++) {
        for (int j = 0; j < i; ++ j) {
            dp[i] += dp[j] * dp[i - j - 1];
        }
    }
    return dp;
}
lli b_ex(lli n,lli a){lli res=1;while(n){if(n%2==1)res*=a;n>>=1;a=a*a;}return res;}
lli ncr(lli n,lli k){lli ans=1;if(k>n-k)k=n-k;for(lli i=1;i<=k;i++){ans*=(n-i+1),ans=ans/i;}return ans;}
lli power(lli a , lli n){lli ans = 1;while(n){if(n % 2)ans = (ans * a) % mod;n /= 2;a = (a * a) % mod;}return ans;}
lli lcm(lli a,lli b){lli ans=(a*b)/(__gcd(a,b));return ans;}
lli set_bits(lli n)
{
    int c=0;
    if(n==0)return 0;
    while(n)
    {
        if((n&1)==1)
        {
           cout<<c<<" ";
        }
        c++;
        n=n>>1;
    }
    return c;
}

string X="IF THE CONSTRAINTS ARE LOW JUST BRUTE FORCE IT!!!!!!!!!!!!!!!!!!!!!";
///------------------ALWAYS lli-----TEMP TSF99--------------------------------------------------------------------------------------///

void solve()
{
    string z="";
    int a,b,c,d;cin>>a>>b>>c>>d;
    /// 1st traversal
    int dx=c-a,dy=d-b;
    cout<<string(dy,'U') <<string(dx,'R');
    cout<<string(dy,'D')<<string (dx,'L');
    cout<<'L'<<string(dy+1,'U')<<string(dx+1,'R')<<'D';
    cout<<'R'<<string(dy+1,'D')<<string(dx+1,'L')<<'U';
    cout<<endl;

}
int main()
{
    solve();
}

#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", ans);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

    rep (i, k) {
        if (i % 2 == 0) {
            if (a % 2 == 1) {
                a--;
            }
            a /= 2;
            b += a;
        }
        else {
            if ( b % 2) {
                b--;
            }
            b /= 2;
            a += b;
        }
    }
    cout << a << " " << b << endl;
    return 0;
}