#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 100000000000000 //10^14
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;
}

vector<vector<vector<ll>>> dp(51, vector<vector<ll>>(51, vector<ll>(101, 0)));

int main()
{
    ll N, K;
    cin >> N >> K;
    vector<ll> V(N);
    rep(i, N) cin >> V.at(i);
    ll ans = 0;
    rep(l, min(N, K)+1){
        rep(r, min(N, K)+1){
            rep(d, l+r+1){
                if(l+r+d > K){
                    continue;
                }
                if(l+r > N){
                    continue;
                }
                vector<ll> get(0);
                rep(i, l){
                    get.push_back(V.at(i));
                }
                rep(i, r){
                    get.push_back(V.at(N-1-i));
                }
                sort(all(get));
                get.erase(get.begin(), get.begin()+d);
                ll tmp = 0;
                rep(i, sz(get)){
                    tmp += get.at(i);
                }
                chmax(ans, tmp);
            }
        }
    }
    cout << ans << endl;
}

#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
#define MOD 1000000007
#define MOD2 998244353
#define MOD3 1000000009
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18)
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
//ifstream cinn("in.in");ofstream coutt("out.out");
int poww(const int &a,int b,const int &m=MOD){if(b==0)return 1;int x=poww(a,b/2,m);x=x*x%m;if(b&1)x=x*a%m;return x;}
int ceil(const int &a,const int &b){return (a+b-1)/b;}
////Read:
//Check corner cases, n==1;
//
////Some function:
//__builtin_popcountll(),

int n,c,dp[55][55][55][55];
vi v;

int f(int i,int cnt,int mxgap,int lst){
    if(i==n){
        mxgap=max(mxgap,i-lst-1);
        if(cnt+(n-cnt-mxgap)*2<=c)return 0;
        return -INF;
    }
    int &ans=dp[i][cnt][mxgap][lst+1];
    if(ans!=-INF)return ans;
    ans=v[i]+f(i+1,cnt+1,max(mxgap,i-lst-1),i);
    ans=max(ans,f(i+1,cnt,mxgap,lst));
    return ans;
}

signed main(){
    FASTER;
    cin>>n>>c;
    v=vi(n);cin>>v;
    for(int i=0;i<55;i++){
        for(int j=0;j<55;j++){
            for(int k=0;k<55;k++){
                for(int l=0;l<55;l++){
                    dp[i][j][k][l]=-INF;
                }
            }
        }
    }
    cout<<f(0,0,0,-1);
}


#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <vector>
#include <map>
#include<cstdio>
#include<functional>
#include <bitset>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define ll long long
using namespace std;
template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;

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

int lcm(int a, int b)
{
	return a * b / gcd(a, b);
}

int main()
{
	int n;
	cin >> n;
	vector<int> wl(n);
	vector<int> el(n);
	string s;
	cin >> s;
	rep(i, n) {
		if (i - 1 >= 0) {
			wl[i] = wl[i - 1];
			el[i] = el[i - 1];
		}
		if (s[i] == 'W') {
			wl[i]++;
		}
		else{
			el[i]++;
		}
	}
	int ans = 1000000000;
	rep(i, n) {
		int ec = 0;
		int wc = 0;
		if (i - 1 > 0) {
			wc = wl[i - 1];
		}
		ec = el[el.size() - 1] - el[i];
		ans = min(ans, ec + wc);
	}
	cout << ans << endl;
	//cout << fixed << setprecision(10) << ans << endl;
	system("pause");
}

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

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

    int a[n+1],sum[n+1];
    memset(a,0,sizeof(a));
    memset(sum,0,sizeof(sum));

    rep(i,n){
        if(s[i]=='W'){
        ++a[i];
        --a[n];
        }
        else{
        ++a[0];
        --a[i+1];
        }
    }

    sum[0]=a[0];
    rep(i,n)sum[i+1]=a[i+1]+sum[i];

    sort(sum,sum+n);
    cout<<sum[0]-1<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p;
}
int main() {
  int K,T;
  cin>>K>>T;
  vector<int>a(T);
  for(int i=0;i<T;i++){
    cin>>a[i];
  }

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

  int cnt=0;
  for(int i=0;i<T;i++){
    int cap=K-a[i];
    cnt+=max(a[i]-1-cap,0);
  }
  cout<<cnt<<endl;
  return 0;
}

// includes
#include "bits/stdc++.h"
using namespace std;
// macros
#define ll long long
#define MOD  998244353 //1000000007 // 100000000  //
#define pii pair<ll, ll>
#define piii pair<ll, pii>
#define sz(x) ((ll)(x).size())
#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 popc __builtin_popcount
#define ANS(s) {cout << s << "\n"; return;}
// functions
template <typename T> void unique(T& c){c.erase(std::unique(c.begin(), c.end()), c.end());}
template <class T>bool chmax(T &a, const T &b){if(a < b){a = b; return 1;} return 0;}
template <class T>bool chmin(T &a, const T &b){if(a > b){a = b; return 1;} return 0;}
template <typename T> istream &operator>>(istream &is, vector<T> &vec){for(auto &v: vec)is >> v; return is;}
template <typename T> ostream &operator<<(ostream &os, const vector<T>& vec){for(int i = 0; i < vec.size(); i++){ os << vec[i]; if(i + 1 != vec.size())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p){os << "(" << p.first << ", " << p.second << ")"; return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << "(" << itr->first << ", " << itr->second << ")"; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const unordered_map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << "(" << itr->first << ", " << itr->second << ")"; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}
// constants
const ll N = 1e5+5;
const ll M = 1e6+5;
const ll A = 1e7+5;
const ll inf = 1e9;
const long long linf = 1LL << 60;
const double er = 1e-10;
const double pi = 3.141592653589793238463;
const ll lx[4] = {0, 1, -1, 0};
const ll ly[4] = {1, 0, 0, -1};
const ll dx[8] = {0, 0, 1, -1, 1, -1, 1, -1};
const ll dy[8] = {1, -1, 0, 0, 1, 1, -1, -1};
// io
struct fast_io{
  fast_io(){ios_base::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20);}
} fast_io_;

void solve()
{
    ll n, m;
    cin >> n >> m;
    vector<ll> a(m); cin >> a;
    sort(allr(a));
    ll s = 0;
    for(ll i = 1; i < m; i++) s += a[i];
    if(s >= a[0]) ANS(0);

    cout << a[0]-s-1;
}

int main(int argc, char const* argv[])
{
    ll t = 1; //cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}


#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  string S;
  cin>>S;
  map<char, int> amap;
  for(int i=0;i<S.size();++i) {
    amap[S[i]]++;
  }
  if(S.size()<26) {
    for(char i='a';i<='z';++i) {
      if(amap[i]==0) {
        S.push_back(i);
        break;
      }
    }
    cout<<S<<endl;
    return 0;
  }
  else {
    int num;
    bool can = false;
    vector<char> arr;
    arr.push_back(S[S.size()-1]);
    for(int i=S.size()-2;i>=0;--i) {
      for(int j=0;j<arr.size();++j) {
        if(S[i]<arr[j]) {
          can = true;
          num = S.size()-i;
          S[i] = arr[j];
          break;
        }
      }
      if(can) break;
      arr.push_back(S[i]);
      sort(arr.begin(), arr.end());
    }
    if(!can) {
      cout<<-1<<endl;
      return 0;
    }
    for(int i=0;i<num-1;++i) S.pop_back();
    cout<<S<<endl;
    return 0;
  }
}

#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>
#include<stack>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> getPrimeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

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

// 繰り返し二乗法
ll pow2(ll n, ll p, ll mod) {
	if (p == 0 || n == 1) {
		return 1;
	}
	else {
		ll ret = pow2(n * n % mod, p / 2, mod);
		if (p % 2 == 1) {
			ret *= n;
		}
		return ret % mod;
	}
}

#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)

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

	vector<set<char>> vs(S.size()+1);
	rep(i, 0, S.size()) {
		vs[i + 1] = vs[i];
		vs[i+1].insert(S[i]);
	}

	char next = 'a'-1;
	for (ll i = S.size(); i >=0; i--) {
		for (char c = next+1; c <= 'z'; c++) {
			if (vs[i].find(c) == vs[i].end()) {
				cout << S.substr(0,i) << c << endl;
				return 0;
			}
		}
		next = S[i - 1];
	}

	cout << -1 << endl;
	return 0;

}


#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define ll long long
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define vi vector<int>
using namespace std;
const int INF = 1001001001;
const int MOD = 1e9+7;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }

int main(){
	cin.tie(0), ios::sync_with_stdio(false);
	int n,m,d; cin >> n >> m >> d;
	if(d) cout << setprecision(10) << 2.0*(n-d)/n/n*(m-1);
	else cout << setprecision(10) << 1.0/n*(m-1);
	cout << "\n";
	return 0;
}

#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}

int main() {
    string sa, sb, sc; cin >> sa >> sb >> sc;
    char nx = 'a';
    while (true) {
        if (nx == 'a') {
            if (sa.size() == 0) {
                cout << "A" << endl;
                return 0;
            }
            nx = sa[0];
            sa = sa.substr(1, sa.size()-1);
        } else if (nx == 'b') {
            if (sb.size() == 0) {
                cout << "B" << endl;
                return 0;
            }
            nx = sb[0];
            sb = sb.substr(1, sb.size()-1);
        } else {
            if (sc.size() == 0) {
                cout << "C" << endl;
                return 0;
            }
            nx = sc[0];
            sc = sc.substr(1, sc.size()-1);
        }
    }
    return 0;
}


#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
	for (;;) {
		int N, Q; cin >> N >> Q;
		if (N == 0 && Q == 0) break;
		vector<int> a(100);
		while (N--) {
			int M; cin >> M;
			while (M--) {
				int i; cin >> i;
				a[i]++;
			}
		}
		int _i = 0; Q--;
		for (int i = 1; i < 100; i++)
			if (a[i] > Q) {
				_i = i;
				Q = a[i];
			}
		cout << _i << endl;
	}
}

#include<vector>
using namespace std;

int N, Q;
int num[110];
int mnum, mday;

int main(){
	while(cin>>N>>Q, N||Q){
		for(int i = 0; i < 110; i++)num[i] = 0;

		for(int n = 0; n < N; n++){
			int M;
			cin>>M;
			for(int m = 0; m < M; m++){
				int tmp;
				cin>>tmp;
				num[tmp] += 1;
			}
		}
		int i;
		mday = 110, mnum = 0;
		for(i = 0; i < 110; i++){
			if(num[i] >= Q ){
				if(mnum < num[i]){
					mnum = num[i];
					mday = i;
				}
			}
		}
		cout<<(mnum?mday:0)<<endl;
	}
	return 0;
}


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

template<typename T, typename U>
using pv=vector<pair<T,U>>;
template<typename T>
using matrix=vector<vector<T>>;
template<typename T>
using pque=priority_queue<T>;
template<typename T>
using lpque=priority_queue<T,vector<T>,greater<T>>;

using ll=long long;
using intpair=pair<int,int>;
using llpair=pair<ll,ll>;
using ilpair=pair<int,ll>;
using lipair=pair<ll,int>;
using intvec=vector<int>;
using llvec=vector<ll>;
using intq=queue<int>;
using llq=queue<ll>;
using intmat=vector<intvec>;
using llmat=vector<llvec>;

#define PI 3.141592653589793
#define INTINF 1<<30
#define LLINF 1LL<<60
#define MPRIME 1000000007
#define MPRIME9 998244353
#define MMPRIME (1ll<<61)-1

#define len length()
#define pushb push_back
#define fi first
#define se second

#define setpr fixed<<setprecision(15)
#define all(name) name.begin(),name.end()
#define rall(name) name.rbegin(),name.rend()
#define gsort(vbeg,vend) sort(vbeg,vend,greater<>())

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

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

template<class T>
inline void outmat(T& a, int y, int x) {
	for(int i=0; i<y; i++) {
		for(int j=0; j<x; j++) cout<<a[i][j]<<" ";
		cout<<endl;
	}
}

template<class T>
inline void init(T& v) {
	for(auto &a: v) cin>>a;
}
template<class T, class U>
inline void init(vector<pair<T,U>>& v) {
	for(auto &a: v) cin>>a.first>>a.second;
}
template<class T, class N>
inline void init(T& v, N n) {
	v.resize(n);
	for(auto &a: v) cin>>a;
}
template<class T, class U, class N>
inline void init(vector<pair<T,U>>& v, N n) {
	v.resize(n);
	for(auto &a: v) cin>>a.first>>a.second;
}

template<class N>
void resiz(N n) {
	//empty
}
template<class N, class T, class... U>
void resiz(N n, T&& hd, U&&... tl) {
	hd.resize(n);
	resiz(n,forward<U>(tl)...);
}

ll binpow(ll a, ll ex, ll p) { //繰り返し二乗法
	ll result=1;
	while(ex>0) {
		if(ex&1) result=result*a%p;
		ex>>=1;
		a=a*a%p;
	}
	return result;
}

string S;
int alp[26];

void input() {
	cin>>S;
}

void solve() {
	ll res=(ll)S.len*(S.len-1)/2+1;
	for(int i=0; i<S.len; i++) {
		res-=alp[S[i]-'a'];
		alp[S[i]-'a']++;
	}
	cout<<res<<endl;
}

int main() {
	int t=1;
	while(t) {
		input();
		solve();
		t--;
	}
}

#include<iostream>
#include<vector>

using namespace std;

int foot(int);

int main() {

	int n;
	vector<int>floor;

	cin >> n;
	while (n != 0) {
		floor.push_back(n);
		cin >> n;
	}
	floor.push_back(0);

	int i = 0;
	while (floor[i] != 0) {

		int res = 0;
		res = foot(floor[i]) / 3650;
		if( foot(floor[i]) % 3650 != 0) res++;

		cout << res << endl;
		i++;
	}

	cin >> n;

	return 0;
}

int foot(int n) {

	if (n == 1)return 1;
	if (n == 2)return 2;
	if (n == 3)return 4;
	if (n < 1)return 0;

	return foot(n - 1) + foot(n - 2) + foot(n - 3);

}


#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 25;
const int MOD = 1e9+7;

int main() {
	string x;
	cin >> x;
	int n = x.size();

	stack<char> s;
	int cnt = 0;
	rep(i,n) {
		if (x[i] == 'S') s.push(x[i]);
		if (x[i] == 'T' && s.empty()) s.push(x[i]);
		if (x[i] == 'T' && s.top() == 'S') {
			s.pop();
			cnt += 2;
		}
	}
	cout << n-cnt << endl;
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
typedef vector < vector<ll> > Mat;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

bool ans[60];

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

  for (int i = 0; i < 60; i++){
    ll now = (ll) 1 << (i + 1);
    if (N % now != 0){
      ans[i] = true;
      if (i % 2 == 0) N -= now / 2;
      else N += now / 2;
    }

    if (N == 0){
      for (int j = i; j >= 0; j--) cout << ans[j];
      cout << endl;
      return 0;
    }
  }

  return 0;
}


#include <bits/stdc++.h>

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define dump_1(x1) cerr << #x1 << ": " << x1 << endl
#define dump_2(x1, x2) \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define dump_3(x1, x2, x3)                                                \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << endl
#define dump_4(x1, x2, x3, x4)                                            \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << ", " #x4 << ": " << x4 << endl
#define dump_5(x1, x2, x3, x4, x5)                                        \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#define dump(...) \
  CHOOSE((__VA_ARGS__, dump_5, dump_4, dump_3, dump_2, dump_1, ~))(__VA_ARGS__)
#define check(s) cerr << s << endl

#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 all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

using namespace std;

using ll = long long;

vector<int> dx = {0, 1, 0, -1};
vector<int> dy = {1, 0, -1, 0};

const ll LINF = 2e18;
const int INF = 1e9;

void solve(ll sx, ll sy, ll tx, ll ty) {
  ll dx = tx - sx;
  ll dy = ty - sy;

  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() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  ll sx;
  scanf("%lld", &sx);
  ll sy;
  scanf("%lld", &sy);
  ll tx;
  scanf("%lld", &tx);
  ll ty;
  scanf("%lld", &ty);
  solve(sx, sy, tx, ty);
  return 0;
}

#include <iostream>

using namespace std;

int main() {
    int sx, sy, tx, ty; cin >> sx >> sy >> tx >> ty;

    for (int i = 0; i < ty-sy; i++)
        cout << 'U';
    for (int i = 0; i < tx-sx; i++)
        cout << 'R';
    for (int i = 0; i < ty-sy; i++)
        cout << 'D';
    for (int i = 0; i < tx-sx; i++)
        cout << 'L';
    cout << 'L';
    for (int i = 0; i <= ty-sy; i++)
        cout << 'U';
    for (int i = 0; i <= tx-sx; i++)
        cout << 'R';
    cout << 'D';
    cout << 'R';
    for (int i = 0; i <= ty-sy; i++)
        cout << 'D';
    for (int i = 0; i <= tx-sx; i++)
        cout << 'L';
    cout << 'U' << endl;
    return 0;
}


#include <bits/stdc++.h>
#include <cstdlib>  //abs()で絶対値を取得する（整数）
#include <cmath>    //abs()かfabs()で絶対値を取得する（少数）
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
int main(){
    int n, r;
    cin >> n >> r;
    if (n >= 10){
        cout << r << endl;
    }else{
        int ans = 100 * (10 - n) + r;
        cout << ans << endl;
    }
}

//                             In The Name Of Allah
#include <bits/stdc++.h>
#define ss second
#define ff first
#define use_fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ret(n) return cout << n, 0
#define se(n) cout << setprecision(n) << fixed
#define pb push_back
#define int long long
#define ld long double
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;

const int N = 4e6 + 100, T = 2e3 + 100, OO = 1e12 + 10, M = 1e9 + 7, P = 49157, sq = 360, lg = 30;
typedef pair <int, int> pii;
int dp[T][T];
int fac[N], inv[N];

int pw(int x, int y) {
	if(y == 0)
		return 1;
	int cnt = pw(x, y / 2);
	cnt = (cnt * cnt) % M;
	cnt = (cnt * (y % 2 == 1 ? x : 1)) % M;
	return cnt;
}

void prepro() {
	fac[0] = 1;
	for(int i = 1; i <= N - lg; i++)
		fac[i] = (fac[i - 1] * i) % M;
	inv[N - lg] = pw(fac[N - lg], M - 2);
	for(int i = N - lg - 1; i > -1; i--)
		inv[i] = (inv[i + 1] * (i + 1)) % M;
}

int c(int x, int y) {
	if(x == y || y == 0)
		return 1;
	return ((fac[x] * inv[y] % M) * inv[x - y]) % M;
}

int32_t main() {
	use_fast;
	prepro();
	int n, k;
	cin >> n >> k;
	if(k == 1)
		return cout << 1, 0;
	dp[0][0] = 1;
	for(int i = 1; i <= n; i++) {
		for(int j = i; j >= 1; j--)
			dp[i][j] = (dp[i][j + 1] + (dp[i - 1][j - 1] * i) % M * c(i * k - 1 - j, k - 2)) % M;
		dp[i][0] = dp[i][1];
	}
	cout << dp[n][0] << endl;
	return 0;
}
/*
be carefull :
1- if not solve after 20 min, read again twice
2- after submit read the code again
3- fun with contest
4- ...
*/


        #include <bits/stdc++.h>
        using namespace std;
        #define int long long
const int MAX = 1000001;
const int MOD = 1000000007;

        signed main() {
           int n;
           cin>>n;
           int a[n],b[n];
           for(int i=0;i<n;i++)cin>>a[i];
           for(int i=0;i<n;i++)cin>>b[i];
           int x[3*n],y[3*n];
           for(int i=0;i<n;i++)x[i]=b[i%n]^(b[(i+1)%n]);
           for(int i=0;i<n;i++){
               x[i+n]=a[i%n]^a[(i+1)%n];
               x[i+2*n]=a[i%n]^a[(i+1)%n];
           }
           y[0] = 3*n;
int i = 1, j = 0;
while (i < 3*n) {
  while (i+j < 3*n && x[j] == x[i+j]) ++j;
  y[i] = j;
  if (j == 0) { ++i; continue;}
  int k = 1;
  while (i+k < 3*n && k+y[k] < j) y[i+k] = y[k], ++k;
  i += k; j -= k;
}
for(int i=n;i<2*n;i++){
    if(y[i]>=n)cout<<i-n<<' '<<(a[i-n]^b[0])<<endl;
}

         return 0;

        }

/*
    Author:zeke

    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <bitset>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
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;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
//ll mod = 1e9 + 7;
//ll MOD = 1e9 + 7;
ll INF = 1e18;

struct RollingHash
{
    typedef long long lint;
    const string str;
    const lint base, mod;
    const V tempvec;
    vector<lint> hash, pw;

    RollingHash(V &s, lint h = 1000000007, lint b = 1009) : tempvec(s), mod(h), base(b)
    {
        int l = s.size();
        hash.assign(l + 1, 0);
        pw.assign(l + 1, 0);
        pw[0] = 1;
        for (int i = 0; i < l; ++i)
        {
            pw[i + 1] = pw[i] * base % mod;
            hash[i + 1] = (hash[i] * base + s[i]) % mod;
        }
    }

    lint const get_hash(int l, int r)
    {
        return ((hash[r] - hash[l] * pw[r - l]) % mod + mod) % mod;
    }
};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    V Vec1(n);
    rep(i, n) cin >> Vec1[i];
    V Vec2(n);
    rep(i, n) cin >> Vec2[i];
    V vec1(n);
    V vec2(n);
    rep(i, n)
    {
        vec1[i] = Vec1[i] ^ Vec1[(i + 1) % n];
        vec2[i] = Vec2[i] ^ Vec2[(i + 1) % n];
    }
    rep(i,n){
        vec1.push_back(vec1[i]);
    }
    RollingHash tree(vec1, 1e9 + 7, 1e3 + 7);
    RollingHash tree2(vec1, 999999937, 1e3 + 7);
    RollingHash tree5(vec1, 1000000033, 1e3 + 7);
    RollingHash tree3(vec2, 1e9 + 7, 1e3 + 7);
    RollingHash tree4(vec2, 999999937, 1e3 + 7);
    RollingHash tree6(vec2, 1000000033, 1e3 + 7);
    VP res;
    //  cout<<s<<" "<<t<<endl;
    rep(i, n)
    {
        ll s_hash = tree.get_hash(i, i + n);
        ll t_hash = tree3.get_hash(0, n);
        ll s_hash2 = tree2.get_hash(i, i + n);
        ll t_hash2 = tree4.get_hash(0, n);
        ll s_hash3 = tree5.get_hash(i, i + n);
        ll t_hash3 = tree6.get_hash(0, n);
        if (s_hash == t_hash && s_hash2 == t_hash2 && s_hash3 == t_hash3)
        {
            res.push_back({i, Vec1[i] ^ Vec2[0]});
        }
    }
    rep(i, res.size())
    {
        cout << res[i].F << " " << res[i].S << endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};

int h, w;
int grid[20][20];
int sx, sy, gx, gy;

bool ok(int x, int y)
{
	return x >= 0 && y >= 0 && x < h && y < w;
}

bool search(int d, int x, int y)
{
	if (d == 0){
		return x == gx && y == gy;
	}

	for (int dir = 0; dir < 4; dir++){
		int k = 0;
		while (true){
			int nx = x + dx[dir] * k;
			int ny = y + dy[dir] * k;
			int nnx = nx + dx[dir];
			int nny = ny + dy[dir];
			if (!ok(nx, ny)) break;
			if (grid[nx][ny] == 3){
				return true;
			}
			if (!ok(nnx, nny)) break;
			if (grid[nnx][nny] == 1){
				if (k == 0) break;
				grid[nnx][nny] = 0;
				if (search(d - 1, nx, ny)){
					grid[nnx][nny] = 1;
					return true;
				}
				grid[nnx][nny] = 1;
				break;
			}
			k++;
		}
	}

	return false;
}

int solve()
{
	for (int d = 1; d <= 10; d++){
		if (search(d, sx, sy)){
			return d;
		}
	}
	return -1;
}

int main()
{
	while (scanf("%d %d", &w, &h), w){
		fill_n(*grid, 20 * 20, 0);
		for (int i = 0; i < h; i++){
			for (int j = 0; j < w; j++){
				scanf("%d", &grid[i][j]);
				if (grid[i][j] == 2){
					sx = i;
					sy = j;
				}
				else if (grid[i][j] == 3){
					gx = i;
					gy = j;
				}
			}
		}
		printf("%d\n", solve());
	}

	return 0;
}

#include <cstdio>
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	int n, m;
	int veg[1024];
	int sum;

	while (1){
		sum = 0;
		scanf("%d%d", &n, &m);

		if (n == 0 && m == 0){
			break;
		}

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

		sort(veg, veg + n);
		reverse(veg, veg + n);

		for (int i = 0; i < n; i++){
			if ((i + 1) % m != 0){
				sum += veg[i];
			}
		}

		cout << sum << endl;
	}

	return (0);
}


#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
typedef long long ll;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

bool check(string s, vector<char> &res, char c1, char c2) {
    res[0] = c1, res[1] = c2;
    int n = s.size();
    for(int i = 1; i < s.size() - 1; i++) {
        if(s[i] == 'o' && res[i] == 'S')
            res[i + 1] = res[i - 1];
        else if(s[i] == 'o' && res[i] == 'W')
            res[i + 1] = (res[i - 1] == 'W' ? 'S' : 'W');
        else if(s[i] == 'x' && res[i] == 'S')
            res[i + 1] = (res[i - 1] == 'W' ? 'S' : 'W');
        else if(s[i] == 'x' && res[i] == 'W')
            res[i + 1] = res[i - 1];
    }
    bool ret = false;
    if((res[0] == 'W' && s[0] == 'o') || (res[0] == 'S' && s[0] == 'x')) {
        ret = !(res[1] == res[s.size() - 1]);
        if((res[n - 1] == 'W' && s[n - 1] == 'o') ||
           (res[n - 1] == 'S' && s[n - 1] == 'x')) {
            ret &= !(res[0] == res[n - 2]);
        } else {
            ret &= (res[0] == res[n - 2]);
        }
        return ret;
    } else {
        ret = (res[1] == res[s.size() - 1]);
        if((res[n - 1] == 'W' && s[n - 1] == 'o') ||
           (res[n - 1] == 'S' && s[n - 1] == 'x')) {
            ret &= !(res[0] == res[n - 2]);
        } else {
            ret &= (res[0] == res[n - 2]);
        }
        return ret;
    }
}

int main() {
    int N;
    string s;
    cin >> N;
    cin >> s;
    vector<char> res(N);
    if(check(s, res, 'S', 'S')) {
        rep(i, N) cout << res[i];
        cout << endl;
        return 0;
    }
    if(check(s, res, 'S', 'W')) {
        rep(i, N) cout << res[i];
        cout << endl;
        return 0;
    }
    if(check(s, res, 'W', 'S')) {
        rep(i, N) cout << res[i];
        cout << endl;
        return 0;
    }
    if(check(s, res, 'W', 'W')) {
        rep(i, N) cout << res[i];
        cout << endl;
        return 0;
    }
    cout << -1 << endl;
    return 0;
}

#include<iostream>
#include<string>
#include<map>
using namespace std;
int main() {
	map <char, int> a;
	a.insert(map<char, int>::value_type('I', 1));
	a.insert(map<char, int>::value_type('V', 5));
	a.insert(map<char, int>::value_type('X', 10));
	a.insert(map<char, int>::value_type('L', 50));
	a.insert(map<char, int>::value_type('C', 100));
	a.insert(map<char, int>::value_type('D', 500));
	a.insert(map<char, int>::value_type('M', 1000));
	string c;
	while (cin >> c) {
		string d="";
		for (int i = c.length() - 1; i >= 0; i--)
			d += c[i];
		int sum = 0, e = 0;
		for (int i = 0; i < c.length(); i++) {
			if (a[d[i]] >= e) {
				sum += a[d[i]];
				e = a[d[i]];
			}
			else {
				sum -= a[d[i]];
			}
		}
		cout << sum << endl;
	}
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ll n,i,j,c,d,an=0,k,mod;
    mod=1000000007;
    cin>>n;
    ll ar[n+2];
    for(i=0;i<n;i++)
    {
        cin>>ar[i];
    }
    for(i=0;i<60;i++)
    {
        k=(1LL<<i);
        c=0;
        d=0;
        for(j=0;j<n;j++)
        {
            if((ar[j] & k)==0)
                c++;
            else
                d++;
        }
        an=an+((k%mod)*((c*d)%mod))%mod;
        an=an%mod;
    }
     cout<<an<<endl;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define F first
#define S second

const int sz = 1e5+5;
int n, m, a[sz];

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

    ll ans = 0;
    map<int, int> cnt;
    cnt[0] = 1;
    int sum = 0;
    for(int i = 0; i < n; ++i){
        sum = (sum + a[i]) % m;
        ans += cnt[sum];
        cnt[sum]++;
    }

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}


//list index out of rangeエラー表示用
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep1(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
  int x;
  cin >> x;
  int c500 = 500;
  int c5 = 5;
  int ans = (x / 500) * 1000 + ((x % 500) / 5) *5;
  cout << ans;

}

#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define showmap(is, js, x) {rep(i, is){rep(j, js){cout << x[i][j] << " ";}cout << endl;}}
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> llP;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}

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

    map<int, int> num;
    ll ans = 0;
    rep(i, s.size()){
        if (num.find(s[i]-'a') == num.end()){
            num.insert({s[i]-'a', 1});
        } else {
            num[s[i]-'a']++;
        }
        ans += i+1-num[s[i]-'a'];
    }
    cout << ans+1 << endl;
}


#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
template<class T> ostream& operator<<(ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }

int main() {
    vector<int> ab(2);
    for (auto &abi: ab) cin >> abi;
    int k; cin >> k;
    for (int i = 0; i < k; i++) {
        ab[(i & 1) ^ 1] += ab[i & 1] >>= 1;
    }
    cout << ab << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, a;
    cin >> n;
    vector<int> v;
    for (int i = 0; i < n; i++)
    {
        cin >> a;
        v.push_back(a);
    }
    reverse(v.begin(), v.end());
    for (int i = 0; i < n - 1; i++)
    {
        cout << v[i] << " ";
    }
    cout << v[n - 1] << endl;
}


#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
const double PI=acos(-1);

template<typename T>
istream& operator>> (istream& is, vector<T> &vec){
    for(T& x: vec) is >> x;
    return is;
}

int main(){
    string s; cin >> s;
    ll length = s.length();
    reverse(s.begin(), s.end());
    ll tcnt = 0;
    rep(i, s.length()){
        if(s[i] == 'S') {
            if(tcnt > 0){
                length -= 2;
                tcnt--;
            }
        }else{
            tcnt++;
        }
    }
    cout << length << endl;
    return 0;
}

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

int main() {
    int N; cin >> N;
    long long x; cin >> x;
    vector<long long> a(N);
    for (int i = 0; i < N; ++i) cin >> a[i];
    sort(a.begin(), a.end());
    int res = 0;
    for (int i = 0; i < N; ++i) {
        if (x >= a[i]) ++res, x -= a[i];
        else break;
    }
    if (res == N && x) --res;
    cout << res << endl;
}


#include <iostream>

using namespace std;

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

int main() {
    int n,k;
    cin >> n >> k;
    long GCD;
    cin >> GCD;
    long _max = GCD;
    bool f = k == GCD;
    for (int i=1; i<n; i++) {
        long a;
        cin >> a;
        f = f || k==a;
        GCD = gcd(GCD, a);
        _max = max(_max, a);
    }

    if (f || (k%GCD==0 && k <= _max)) {
        cout << "POSSIBLE" << endl;
    } else {
        cout << "IMPOSSIBLE" << endl;
    }

}

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

#define rep(i, m, n) for(int(i) = (int)(m); i < (int)(n); ++i)
#define rep2(i, m, n) for(int(i) = (int)(n)-1; i >= (int)(m); --i)
#define REP(i, n) rep(i, 0, n)
#define REP2(i, n) rep2(i, 0, n)
#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll)1e9 + 7;
//constexpr long long MOD = 998244353LL;
using ld = long double;
static const ld pi = 3.141592653589793L;
typedef vector<ll> Array;
typedef vector<Array> Matrix;

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

struct Edge {
    ll to, rev;
    long double cap;
    Edge(ll _to, long double _cap, ll _rev) {
        to = _to;
        cap = _cap;
        rev = _rev;
    }
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(Graph &G, ll from, ll to, long double cap, bool revFlag,
              long double revCap) {
    G[from].push_back(Edge(to, cap, (ll)G[to].size()));
    if(revFlag)
        G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

void solve() {
    ll n, k;
    cin >> n >> k;
    vec<ll> a(n);
    ll d = 0;
    REP(i, n) {
        cin >> a[i];
        d = gcd(d, a[i]);
    }

    REP(i, n) {
        if(a[i] < k)
            continue;
        if((k - a[i]) % d)
            continue;
        cout << "POSSIBLE" << en;
        return;
    }
    cout << "IMPOSSIBLE" << en;
}

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

    solve();
    /*
    ll t;
    cin >> t;
    REP(i, t) { solve(); }*/

    return 0;
}


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

#define ran 1001001

struct Node {
	int pre, det, suf;
	Node() {}
} info[ran];

int n;
char s[ran];

Node analysis() {
	int len = strlen(s);

	int h = 0;
	int mi = 0;
	for(int i=0;i<len;i++) {
		if(s[i]=='(') h++;
		else h--;
		mi = min(mi, h);
	}

	Node res;
	res.pre = -mi;
	res.det = h;
	res.suf = res.pre + res.det;
	return res;
}

int cmp(const Node &a, const Node &b) {
	bool fa = (a.det>=0), fb = (b.det>=0);
	if(fa!=fb) return fa;
	if(fa) return a.pre<b.pre;
	return a.suf > b.suf;
}

bool chk() {
	int sum = 0;
	for(int i=0;i<n;i++)
		sum += info[i].det;
	if(sum!=0) return false;

	sort(info, info+n, cmp);

	int cur = 0;
	for(int i=0;i<n;i++) {
		if(cur<info[i].pre) return false;
		cur += info[i].det;
	}
	return true;
}

int main() {
	scanf("%d", &n);

	for(int i=0;i<n;i++) {
		scanf("%s", s);
		info[i] = analysis();
	}

	puts(chk() ? "Yes" : "No");

	return 0;
}

#include<iostream>
#include<vector>
#include<set>
#include<algorithm>
using namespace std;
int main(){
int n,i,j,k,p,count=0;
set<int>::iterator it;
vector<int>x,y;
cin>>n;
for(i=0;i<n;i++){
    cin>>p;
    x.push_back(p);
}
sort(x.begin(),x.end());

for(i=0;i<n;i++){
        if(x[i]==x[i+1]){
    x[i]=0;
    x[i+1]=0;
}
}
for(i=0;i<n;i++){
    if(x[i]!=0){
        count++;
    }
}
cout<<count;
}


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

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

    bool ok = true;
    if (S.size() % 2 == 1) ok = false;
    for (int i = 0; i < S.size() / 2; i += 2) {
        if (S.substr(i, 2) != "hi") {
            ok = false;
        }
    }

    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main() {
	string s;
	cin >> s;
	if(s[0] != 'A' || isupper(s[1]) || isupper(s[s.size() - 1])){
		cout << "WA" << endl;
		return 0;
	}
	bool isFoundC = false;
	for(int i = 2; i < s.size() - 1; i++){
		if(!isFoundC && s[i] == 'C') isFoundC = true;
		else if(s[i] == 'C'){
			cout << "WA" << endl;
			return 0;
		}else if(isupper(s[i])){
			cout << "WA" << endl;
			return 0;
		}
	}
	cout << (isFoundC ? "AC" : "WA") << endl;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
//datatypes
	#define ll 			long long
	#define vi 			vector<int>
	#define vll 		vector<ll>
	#define si 			set<int>
	#define vii 		vector<ii>
	#define ii 			pair<int,int>
	#define vpll		vector<pll>
	#define pii 		pair<int,int>
	#define pll 		pair<ll, ll>
	#define mii 		map<int,int>
	#define ord_set		tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
	#define M 			1000000007
	#define narak 		998244353
	#define pi 			acos(-1)
	#define inf 		2147483647
	#define infl 		9223372036854775807
	#define infd 		1.7e308
	#define invd 		1.7e-308
	#define sz(x) 		(ll)x.size()
	#define fr 			first
	#define sc 			second
	#define pb 			push_back
	#define mkp 		make_pair
	#define rep(i,a,b) 	for(int i=a; i<b; ++i)
	#define rep0(i,a)	for(int i=0; i<a; ++i)
	#define rep1(i,a)	for(int i=1; i<=a; ++i)
	#define trav(a) 	for(auto &x:a)
	#define test 		cout<<"hello\n";
	#define all(x) 		(x).begin(),(x).end()
	#define mem(x,val)	memset(x, val, sizeof(x))
	#define sa(x) 		std::sort(all(x))
	#define endl 		'\n'
	#define __lcm(m,n) 	m*(n/__gcd(m,n))
	#define fill(a,n) 	for(int xxx=0;xxx<n;++xxx) cin>>(a)[xxx]
	#define maxa(v)		*(max_element(all(v)))
	#define mina(v)		*(min_element(all(v))
	#define inputFile 	freopen("input.txt", "r", stdin);
	#define outputFile	freopen("output.txt", "w", stdout);
	#define disp(a) 	trav(a) cout<<x<<" "; cout<<endl;
  	//#define int long long

template<typename T, typename U> static inline void amin(T &x, U y){ if(y<x) x=y; }
template<typename T, typename U> static inline void amax(T &x, U y){ if(x<y) x=y; }
template<typename T,typename U> std::ostream& operator<<(std::ostream& out, std::pair<T,U> a) {out<<a.fr<<" "<<a.sc; return out;}
template<typename T,typename U> std::istream& operator>>(std::istream& in, std::pair<T,U> &a) {in>>a.fr>>a.sc; return in;}
template<typename T> static inline void sd(vector<T> &x) {sort(all(x), greater<T>()) ; }
const int N=301;
int n;
double dp[N][N][N]={};

signed solve()
{
	cin>>n;
    int cnt[4]={};
    rep(i,0,n){int x;
    	cin>>x;
    	cnt[x]++;
    }
    dp[0][0][0]=0;
    for(int three=0; three<=n; ++three)
    {
    	for(int two=0; two<=n; ++two)
    	{
    		for(int one=0; one<=n; ++one)
    		{
    			int zero = n -(three+two+one);
    			if(zero == n)
    				continue;
    			if(three+two+one > n)
    				continue;
    			double val = 1;
    			if(three>0)
    			val += (1.0*three/n)*(dp[three-1][two+1][one]);
    			if(two>0)
    			val += (1.0*two/n)*(dp[three][two-1][one+1]);
    			if(one>0)
    			val += (1.0*one/n)*(dp[three][two][one-1]);
    			val /= (1.0-1.0*zero/n);
    			dp[three][two][one] = val;
    		}
    	}
    }
    cout<<fixed<<setprecision(12)<<dp[cnt[3]][cnt[2]][cnt[1]];
	return 0;
}

signed main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int t=1;
	//cin>>t;
	while(t--)
	{

		solve();

	}
	//cout << "\nTime : " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MX = 400;

int h, w;
string s;

int grid[MX][MX];
ll black[MX*MX], white[MX*MX];
bool used[MX][MX];
ll ans;

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

void dfs(int x, int y) {
	used[x][y] = true;
	if (grid[x][y]) black[curGroup]++;
	else white[curGroup]++;
	for (int i = 0; i < 4; i++) {
		int a = x + dx[i], b = y + dy[i];
		if (a < 0 || a >= h || b < 0 || b >= w) continue;
		if (grid[a][b] == grid[x][y]) continue;
		if (used[a][b]) continue;
		dfs(a, b);
	}
}

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
    cin >> h >> w;
    for (int i = 0; i < h; i++) {
		cin >> s;
		for (int j = 0; j < w; j++) {
			if (s[j] == '#') grid[i][j] = 1;
			else grid[i][j] = 0;
		}
	}

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			curGroup++;
			if (!used[i][j]) dfs(i, j);
		}
	}

	for (int i = 0; i <= curGroup; i++) {
		ans += white[i] * black[i];
	}
	cout << ans;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i, n) for(int i =0 ; i < n; ++i)
#define pii pair < int, int >
typedef vector<int> vi;
typedef   long long ll;
const int mod =1e9+7;

void solve(){
	int a,b;
	cin>>a>>b;
	if(a>8 || b>8)cout<<":(";
	else cout<<"Yay!";

}

int main(){
	Red;
	int t=1;
	//cin>>t;
	while(t--)
	solve();
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
const int mod=1e9+7;

int main(){
  int N,K;
  cin>>N>>K;
  vector<char>D(K);
  for(int i=0;i<K;i++){
    cin>>D[i];
  }
  for(int i=N;;i++){
    string t=to_string(i);
    bool use=true;
    for(int k=0;k<t.size();k++){
      bool ok=true;
      for(int j=0;j<K;j++){
        if(t[k]==D[j]){
          ok=false;
        }
      }
      if(!ok){use=false;}
    }
    if(use){cout<<t<<endl;return 0;}
  }
  return 0;
}


#include <iostream>

using namespace std;

int main() {
  int a;
  cin >> a;
  int res = 0;
  for (int i = 0; i < 3; ++i) res = (res + 1) * a;
  cout << res << endl;
}

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

int main(void){
    int a;
    cin >> a;
    cout << a+a*a+a*a*a << endl;
    return 0;
}


#include <iostream>
#include <queue>
#include <utility>
using namespace std;

int a[100][100];
bool r[100];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    for(int i=0; i<n; i++) {
        for(int j=0; j<n; j++) {
            cin>>a[i][j];
        }
    }
    priority_queue<pair<int,int>, vector<pair<int,int> >, greater<pair<int,int> > >q;
    q.push(make_pair(0,0));
    int cost=0;
    pair<int,int> e;
    while(!q.empty()) {
        e=q.top();
        q.pop();
        if(r[e.second]) continue;
        r[e.second]=true;
        cost+=e.first;
        for(int i=0; i<n; i++) {
            if(a[e.second][i]!=-1) q.push(make_pair(a[e.second][i], i));
        }
    }
    cout<<cost<<'\n';
    return 0;
}

#include<iostream>
using namespace std;
#define N 105
#define INF 1<<21
int n;
int a[N][N];
int d[N],p[N],color[N];              //0.未访问的节点   1.正在访问的节点  2.已经访问过的节点
int prim(){
	int u ,minv;
	for (int i = 0;i < n;i++){
		d[i] = INF;
		p[i] = -1;
		color[i] = 0;
	}
	d[0] = 0;
	while (1){
		minv = INF;
		u = -1;
		for (int i = 0;i < n;i++){
			if (minv > d[i] && color[i] != 2){
				u = i;
				minv = d[i];
			}
		}
		if ( u == -1) break;
		color[u] = 2;
		for (int v = 0;v < n;v++){
			if (color[v] != 2 && a[u][v] != INF){
				if (d[v] > a[u][v]){
					d[v] = a[u][v];
					p[v] = u;
					color[v] = 1;
				}
			}
		}
	}
	int sum = 0;
	for (int i = 0;i < n;i ++){
		if (p[i] != -1){
			sum = sum + a[i][p[i]];
		}
	}
	return sum;
}

int main()
{
	cin >> n;
	int x;
	for (int i = 0;i < n;i++){
		for (int j = 0;j < n;j++){
			cin >> x;
			if (x == -1){
				a[i][j] = INF;
			}
			else{
				a[i][j] = x;
			}
		}
	}
	cout << prim() << endl;
	return 0;
}


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

#define rep(i,n) for(int i = 0; i < n; i++)
#define Rep(i,n) for(int i = 1; i <= n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
template<class T> using V = vector<T>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(){
    int n;
    cin >> n;
    V<P> p(n);
    rep(i,n) cin >> p[i].fi >> p[i].se;
    double ans = 0;
    rep(i,n)rep(j,n) {
        if(i == j) continue;
        ans += sqrt((p[i].fi-p[j].fi)*(p[i].fi-p[j].fi) + (p[i].se-p[j].se)*(p[i].se-p[j].se)) * (n-1);
    }
    ans /= n*(n-1);
    printf("%.10f", ans);
}

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

int main() {
	int N;
    long double dx,dy,RR,avdist,prt;
    cin >>N;
    int arrive[N];
    vector<vector<long double>> b(N, vector<long double>(2));
    vector<vector<long double>> dist(N, vector<long double>(N,0));
    for(int i=0;i<N;i++){
      arrive[i]=i;
      cin >> b.at(i).at(0) >> b.at(i).at(1);
    }
    for(int i=0;i<N;i++){
      for(int j=0;j<N;j++){
        dx=b.at(i).at(0)-b.at(j).at(0);
        dy=b.at(i).at(1)-b.at(j).at(1);
        RR=pow(pow(dx,2)+pow(dy,2),0.5);
        dist.at(i).at(j)= RR;
        //cout << RR << endl;
    	}
    }
  avdist=0;
  prt=0;
   do{
    for(int k=0;k<N-1;k++){
     avdist+=dist.at(arrive[k]).at(arrive[k+1]);
     }
         prt+=1;
     }while(next_permutation(arrive, arrive + N));
       cout << fixed << setprecision(10) << avdist/prt << endl;
   return 0;

}


#include <iostream>
#include <unordered_map>
#include <cmath>

void FactrizePrime(int x, std::unordered_map<int, int> &count)
{
    while (x % 2 == 0)
    {
        ++count[2];
        x /= 2;
    }
    for (int i = 3; i <= x; i += 2)
    {
        while (x % i == 0)
        {
            ++count[i];
            x /= i;
        }
    }
}

constexpr int32_t MOD = 1000000007;

int main()
{
    int n;
    std::cin >> n;
    if (n == 1 || n == 2)
    {
        std::cout << n << std::endl;
        return 0;
    }

    std::unordered_map<int, int> factor;
    for (int i = 2; i <= n; ++i)
    {
        FactrizePrime(i, factor);
    }

    int64_t count = 1;
    for (const auto &p : factor)
    {
        count *= p.second + 1;
        count %= MOD;
    }

    std::cout << count << std::endl;
    return 0;
}

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

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

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define what_is(x) cerr << #x << " is " << x << endl;
#define MT make_tuple
#define eb emplace_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define REP(i,a,b) for (int i = a; i <= b; i++)
#define FOR(i,n) for (int i=0;i < n ; i++)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
ll mod=1e9+7;

bool* sieve(ll n){
	bool* a=new bool[n+1];
	for(ll i=0;i <n+1;i++) a[i]=true;
	for(ll i=2;i<n/2;i++){
		if(a[i]==false) continue;
		ll k=2;
		while(i*k <=n){
			a[i*k]=false;
			k++;
		}
	}

	return a;
}

int main(){
	ll n;
	cin >> n;
	bool* b=sieve(n);
	ll ans=1;
	for(ll i=2; i <n+1;i++){
		if(b[i]){
			ll j=i;
			ll count=0;
			while(j<=n){
				count+=n/j;
				j*=i;
			}
			ans*=count+1;
			ans%=mod;
		}
	}
	cout << ans;
	return 0;
}


#include <iostream>
using namespace std;

long long cnt = 0; //for counting num of invensions

void merge(int *a, int left, int mid, int right) {

    int nL = mid - left;
    int nR = right - mid;

    int L[nL], R[nR];

    for(int i=0; i<nL; i++) {
        L[i] = a[left + i];
    }
    for(int i=0; i<nR; i++) {
        R[i] = a[mid + i];
    }

    int indexL = 0, indexR = 0;
    int k = left;
    while(k<right) {

        if( indexL>=nL ) { //in case that L[] has no element
            a[k] = R[indexR]; //this is not inversion
            indexR++;
        } else if( indexR>=nR ) { //in case that R[] has no element
            a[k] = L[indexL]; //this is not inversion
            indexL++;
        } else if( L[indexL] <= R[indexR] ) {
            a[k] = L[indexL]; //this is not inversion
            indexL++;
        } else if( L[indexL] > R[indexR] ) { //actually, this condition is not needed
            a[k] = R[indexR]; //this is inversion
            indexR++;
            cnt += nL - indexL; //num of inversion = num of elements remaining in L[]
        }

        k++;
    }

//    //display info. about this step
//    cout << "-----\n";
//    cout << "merge(" << left << ", " << mid << ", " << right <<")" << endl;
//
//    cout << "L" << " = "; for(int i=0; i<nL; i++) {cout << L[i] << " ";} cout << endl;
//    cout << "R" << " = "; for(int i=0; i<nR; i++) {cout << R[i] << " ";} cout << endl;
//
//    cout << "cnt = " << cnt << endl;

    return;
}

void mergeSort(int *a, int left, int right) {

    if(left+1  <  right) {
        int mid = (left + right) / 2;

        mergeSort(a, left, mid);
        mergeSort(a, mid, right);

        merge(a, left, mid, right);

    }

    return;
}

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

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

//    //display a[] before sorting
//    cout << "a[] = ";
//    for(int i=0; i<N; i++) {
//        cout << a[i] << " ";
//    }
//    cout << endl;

    //merge sort a[]
    mergeSort(a, 0, N);

//    //display a[] after sorting
//    cout << "a[] = ";
//    for(int i=0; i<N; i++) {
//        cout << a[i] << " ";
//    }
//    cout << endl;

//    cout << "Num of inversions = ";
    cout << cnt << endl;

    return 0;
}

#include <cstdio>
#include <vector>
#include <algorithm>

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

using namespace std;

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

int n;
int a[200000];
int b[200001];

void add(int i, int x){
	while(i <= n){
		b[i] += x;
		i += i & -i;
	}
}

int sum(int i){
	int s = 0;
	while(i > 0){
		s += b[i];
		i -= i & -i;
	}
	return s;
}

int main(){
	scanf("%d", &n);
	rep(i, n){
		scanf("%d", &a[i]);
	}

	vector<P> v;
	rep(i, n){
		v.push_back(P(a[i], i));
	}
	sort(v.begin(), v.end());
	a[v[0].second] = 0;
	rep(i, n - 1){
		a[v[i + 1].second] = a[v[i].second] + (v[i].first != v[i + 1].first);
	}

	ll ans = 0;
	for(int i = n - 1; i >= 0; --i){
		ans += sum(a[i]);
		add(a[i] + 1, 1);
	}
	printf("%lld\n", ans);
	return 0;
}


#include<bits/stdc++.h>
#define rint register int
#define rep(i,a,b) for (rint i=(a),_E=(b); i<=_E; ++i)
#define per(i,a,b) for (rint i=(a),_E=(b); i>=_E; --i)
#define REP(i,n) for (rint i=(0),_E=(n); i<_E; ++i)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

const int N = 100005;
priority_queue<int> Q;
int n, res;
pii a[N];
ll now;

int main() {
	scanf("%d", &n);
	rep (i, 1, n) {
		scanf("%d%d", &a[i].fi, &a[i].se);
		a[i].fi += a[i].se;
	}
	sort(a + 1, a + n + 1);
	rep (i, 1, n) {
		now += a[i].se;
		Q.push(a[i].se);
		if (now > a[i].fi) {
			now -= Q.top();
			Q.pop();
		}
	}
	cout << Q.size() << endl;
	return 0;
}

#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
#define MOD (1000000007)
//#define MOD (998244353)
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18)
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
//ifstream cinn("input.txt");ofstream coutt("output.txt");

vii v;
int n,dp[5000][5001];

int f(int i,int k){// f(i,j) min price when j items taken and i items included
    if(k<0)return INF;
    if(i==-1){
        if(k>0)return INF;
        return 0;
    }

    int &ans=dp[i][k];
    if(ans!=-1)return ans;

    ans=INF;
    int picheka=f(i-1,k-1);
    if(picheka<=v[i].first)ans=min(ans,picheka+v[i].second);
    ans=min(ans,f(i-1,k));

    return ans;
}

signed main(){
    FASTER;
    memset(dp,-1,sizeof dp);
    cin>>n;
    v=vii(n);cin>>v;
    sort(all(v),[](const pii &a,const pii &b){return a.first+a.second<b.first+b.second;});

    for(int i=n;i>=0;i--){
        if(f(n-1,i)!=INF){
            cout<<i;
            return 0;
        }
    }
}


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

#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 ALL(obj) (obj).begin(), (obj).end()
#define INF 1e16
typedef long long ll;

int main() {
    ll N;
    cin >> N;
    ll m = INF;
    REP(i,5){
        ll t;
        cin >> t;
        m = min(m,t);
    }

    cout << 5 + (N-1)/m << endl;

    return 0;
}

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

void print(vector<int> &v){
    vector<int>::iterator ite = v.begin();
    while(ite != v.end()){
        cout << *ite << endl;
        ite++;
    }
}

int insSort(vector<int> &v, int g){
    int i, j, x, n = v.size(), cnt = 0;
    for(i = g; i < n; i++){
        x = v[i];
        j = i - g;
        while(j >= 0 && v[j] > x){
            v[j+g] = v[j];
            cnt++;
            j -= g;
        }
        v[j+g] = x;
    }
    return cnt;
}

void makeG(vector<int> &v,int n){
    for(int i = 1; ;){
        if(i > n) break;
        v.push_back(i);
        i = 3*i + 1;
    }
}

void shellSort(vector<int> &v){
    int i, cnt = 0;
    vector<int> g;
    makeG(g, v.size());
    int gs = g.size();
    cout << gs << endl;
    for(i = gs - 1; i >= 0; i--){
        if(i != gs - 1)
            cout << " ";
        cout << g[i];
        cnt += insSort(v, g[i]);
    }
    cout << endl <<  cnt << endl;
}

int main(){
    int n, x, i;
    vector<int> v;
    cin >> n;
    for(i = 0; i < n; i++){
        cin >> x;
        v.push_back(x);
    }
    shellSort(v);
    print(v);
    return 0;
}


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

static const int MAX_LENGTH = 1000;

void nreplace(char *input, int start, int end, char *target);
void nswap(char *input, int start, int end);
void nprint(char *input, int start, int end);

int main(void) {
    char *input = new char[MAX_LENGTH+1];
    char *target = new char[MAX_LENGTH+1];
    string command;
    int N, s, e;
    cin >> input;
    cin >> N;

    while(N-- > 0) {
        cin >> command >> s >> e;
        if(command == "replace") {
            cin >> target;
            nreplace(input, s, e, target);
        }
        if(command == "reverse") nswap(input, s, e);
        if(command == "print") nprint(input, s, e);
    }

    return 0;
}

void nreplace(char *input, int start, int end, char *target) {
    for(int i=start; i<=end; i++)
        input[i] = target[i-start];
}

void nswap(char *input, int start, int end) {
    char *st = input;
    char *ed = input;
    char tmp;

    for(int i=0; i<start; i++) st++;
    for(int i=0; i<end; i++) ed++;

    while(st < ed) {
        tmp = *st;
        *st++ = *ed;
        *ed-- = tmp;
    }
}

void nprint(char *input, int start, int end) {
    for(int i=start; i<=end; i++) cout << input[i];
    cout << endl;
}


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

using namespace std;

int main()
{
    cin.tie(0);cout.tie(0);
    ios::sync_with_stdio(false);
    int a,b;
    cin >> a >> b;
    int in = 1,res=0;
    while (in <b){

        in += a - 1;
        res += 1;

    }
    cout << res ;
    return 0;
}

#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>

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

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

const ll MOD = 1000000007;
const int INF = 1<<30;
//const ll INF = (ll)1e18 + 1;

ll choose(ll n){
  return n * (n - 1) / 2;
}
int main(){
  ll N, M; cin >> N >> M;
  vector<ll> a(N); rep(i, N) cin >> a[i];

  vector<ll> s(N + 1, 0);
  rep(i, N) s[i + 1] = s[i] + a[i];
  map<ll, ll> mp;
  for (int i = 1; i < N + 1; ++i) mp[s[i] % M]++;
  ll ans = 0;
  for (auto v: mp){
    ans += choose(v.second);
  }
  ans += mp[0];
  cout << ans << endl;
}


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

int main(void) {
    int N,K;
    cin >> N >> K;
    if(N%K) cout << "1\n";
    else cout << "0\n";
    return 0;
}

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

int main() {
  int N,K;
  cin>>N>>K;
  cout<<((N%K)+K-1)/K<<endl;
}


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

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

  ll tmp = 0;
  for (ll i = 0; i < n + 1; i++)
  {
    if (i == n)
    {
      fee += abs(tmp - 0);
      break;
    }

    fee += abs(tmp - a[i]);
    tmp = a[i];
  }

  for (ll i = 0; i < n; i++)
  {
    ans[i] = fee - (abs(a[i] - a[i - 1]) + abs(a[i + 1] - a[i])) + (abs(a[i + 1] - a[i - 1]));
  }

  for (ll i = 0; i < n; i++)
  {
    cout << ans[i] << endl;
  }
}

#include <iostream>
#include <stack>
#include <algorithm>
#include <cstdio>
#include <sstream>
#include <vector>
#include <string>
#include <cmath>

#define rep(x,to) for(int x=0;x<to;x++)
#define rep2(x,from,to) for(int x=from;x<to;x++)

using namespace std;

int main(void){

string ws;
int n;
	while(cin >> n){
		if(n==0 || cin.eof()) break;
		vector<vector<int> > hg(n+1,vector<int>(n+1,0));
		rep(i,n) rep(j,n) cin >> hg[i][j];
		rep(i,n) rep(j,n){
			hg[n][i] += hg[j][i];
			hg[i][n] += hg[i][j];
		}
		rep(i,n) hg[n][n] += hg[i][n];
		rep(i,n+1){
			rep(j,n+1) printf("%5d",hg[i][j]);
			printf("\n");
		}
	}
	return 0;

}


#include <bits/stdc++.h>

using ll = long long;
using Pii = std::pair<int, int>;
using Pll = std::pair<ll, ll>;

const ll INF = (ll)1e11;
const ll MOD = 998244353;

using namespace std;

int main() {
    ios::sync_with_stdio(false);

    int N;
    cin >> N;

    vector<int> A;
    ll S = 0;
    for (int i = 0, a; i < N; ++i) {
        cin >> a;
        A.push_back(a);
        S += a;
    }

    ll cnt = 1;
    for (int i = 0; i < N; ++i) {
        cnt *= 3;   // all ways to paint stones
        cnt %= MOD;
    }

    // subtract the numbers of ways to paint such that R,G,B cannot construct a triangle from all.

    {   // reduce the number of ways to paint such that R >= G + B, G >= B + R, B >= R + G
        vector<ll> dp(S + 10, 0);
        dp[0] = 1;  // assume that R = max(R,G,B) here
        for (auto a : A) {
            for (ll s = S; s > a - 1; --s) {
                dp[s] += 2 * dp[s-a];   // select a_i in G or B
                dp[s] %= MOD;
            }
        }

        for (ll s = 0; s < S / 2 + 1; ++s) {
            cerr << "----" << endl;
            cnt -= 3 * dp[s];   // subtract sum of R, G, B = max(R,G,B)
            while (cnt < 0) cnt += 3 * MOD;
            cnt %= MOD;

            cerr << cnt << endl;
        }
    }

    cerr << cnt << endl;

    if (S % 2 == 0) {   // add the number of ways to paint such that R == G && B == 0, G == B && R == 0, B == R && G == 0
        vector<ll> dp(S + 10, 0);
        dp[0] = 1;  // assume that R == G && B == 0 here
        for (auto&& a : A) {
            for (ll s = S; s > a - 1; --s) {
                dp[s] = (dp[s] + dp[s-a]) % MOD;   // select a_i in R (G)
                dp[s] %= MOD;
            }
        }

        cnt += 3ll * dp[S/2];   // add sum of R,G,B == 0
        cnt %= MOD;
    }

    cout << cnt << endl;

    return 0;
}

//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define trav(x,a) for (const auto& x: a)
#define sz(x) (int)(x).size()
#define mem(a,v) memset((a), (v), sizeof (a))
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%lld", &(n))
#define nai(a, n) for (int _i = 0; _i < (n); _i++) ni(a[_i])
#define nal(a, n) for (int _i = 0; _i < (n); _i++) nl(a[_i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%lld\n", (n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define st first
#define nd second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int inf = 1e9 + 7;
const int N = 6e3 + 5;
const double eps = 1e-9;
int n, mod;
int add(int x, int y) { return x+y < mod ? x+y : x+y-mod; }
int mul(int x, int y) { return x*1ll*y % mod; }
int dp[N][2*N], fac[N];

int main() {
  scanf("%d %d", &n, &mod);
  dp[0][3*n] = 1;
  for (int i = 1; i <= 3*n; i++) {
    for (int j = 0; j <= 6*n; j++) {
      if (j > 0)
        dp[i][j] = add(dp[i-1][j-1], dp[i][j]);
      if (i > 1)
        dp[i][j] = add(dp[i][j], mul(dp[i-2][j+1], i-1));
      if (i > 2)
        dp[i][j] = add(dp[i][j], mul(dp[i-3][j], mul(i-1,i-2)));
    }
  }
  int ans = 0;
  for (int i = 3*n; i <= 6*n; i++)
    ans = add(ans, dp[3*n][i]);
  printf("%d\n", ans);
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI pair<int,int>
const int maxm=1e6+5;
int a[maxm];
int n;
signed main(){
    cin>>n;
    for(int i=1;i<=n*2;i++)cin>>a[i];
    int ans=0;
    sort(a+1,a+1+n*2);
    for(int i=1;i<=n*2;i+=2){
        ans+=min(a[i],a[i+1]);
    }
    cout<<ans<<endl;
    return 0;
}
/*

*/

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

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<double, int> pdbi;
typedef pair<int,pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<vector<int>> mat;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()

const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const ll INF = 1<<30;
const ll mod = 1000000000 + 7;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

//#define int long long
#define addm(X, Y) (X) = ((X) + ((Y) % mod) + mod) % mod

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    int costa[1005] = {};
    fill(costa, costa + 1005, INF);
    rep(i, n) {
        int c;
        cin >> c;
        bool check = false;
        int mn = i + 1;
        rep2(j, 1, c + 1) {
            mn = min(mn, costa[j]);
        }
        costa[c] = mn;
    }
    int cnt[1005] = {};
    rep(i, m) {
        int c;
        cin >> c;
        int mn = INF;
        rep(j, c + 1) {
            mn = min(mn, costa[j]);
        }
        cnt[mn]++;
    }
    int mx = -1;
    int ans = 0;
    rep(i, 1005) {
        if (cnt[i] > mx) {
            mx = cnt[i];
            ans = i;
        }
    }
    cout << ans << endl;
}


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

int n,m;
int s[5];
int c[5];

int main()
{
    scanf("%d%d",&n,&m);
    for(int i=0;i<m;i++)
    scanf("%d %d",&s[i],&c[i]);

    for(int i=0;i<1000;i++)
    {
        char num[5];
        sprintf(num,"%d",i);
        // itoa(i,num,10);
        if(strlen(num)!=n) continue;
        bool flag=true;
        for(int j=0;j<m;j++)
        {
            if(num[s[j]-1]!=c[j]+'0')
            {
                flag=false;
                break;
            }
        }
        if(flag)
        {
            printf("%d\n",i);
            return 0;
        }
    }
    printf("-1\n");
    return 0;
}

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> ds(N, -1);
  bool isExist = true;
  rep(i, M) {
    int s, c;
    cin >> s >> c;
    s--;
    if (ds[s] == -1) {
      ds[s] = c;
    } else if (ds[s] != c) {
      isExist = false;
    }
  }
  if (!isExist) {
    cout << -1 << endl;
    return 0;
  }
  if (2 <= N) {
    int sum = 0;
    if (ds[0] == 0) {
      cout << -1 << endl;
      return 0;
    } else if (ds[0] == -1) {
      sum = 1;
    } else {
      sum = ds[0];
    }

    for (int i = 1; i < N; i++) {
      if (ds[i] == -1) {
        sum = sum * 10;
      } else {
        sum = sum * 10 + ds[i];
      }
    }
    cout << sum << endl;
    return 0;
  } else {
    if (ds[0] == -1) {
      cout << 0 << endl;
    } else {
      cout << ds[0] << endl;
    }
  }
  return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};

struct Timer{
    chrono::system_clock::time_point start, end;
    Timer(){ start = chrono::system_clock::now(); }
    ~Timer(){
        end = chrono::system_clock::now();
        auto msec = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cerr<<"time : "<<msec<<" ms"<<endl;
    }
};

ll n;
ll a[200010]={};
ll cnt[200010]={};
vll G[200010];
ll ans[200010]={};

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Timer TM;

    ll n;
    ll ans=0;
    string s;
    unordered_map<string,ll> mp;
    cin>>n>>s;
    rep(bit,(1<<n)){
        string u="",t="";
        rep(i,n){
            if(bit&(1<<i)){
                u+=s[i];
            }
            else t+=s[i];
        }
        mp[u+'0'+t]++;
        // cout<<u+'0'+t<<endl;
    }
    rep(bit,(1<<n)){
        string u="",t="";
        rep(i,n){
            if(bit&(1<<i)){
                u=s[i+n]+u;
            }
            else t=s[i+n]+t;
        }
        if(mp[t+'0'+u]>0) ans+=mp[t+'0'+u];
    }
    cout<<ans<<endl;

    return 0;
}

#include <cstring>
#include <cctype>
#include <cstdio>
inline int read(int f = 1, int x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
const int N = 1e2+5;
int max(int a, int b) { return a>b?a:b; }
int min(int a, int b) { return a<b?a:b; }
short f[N][N][N][N], g[N][N], h[N][N];
char s[N][N];
int n, m, ans, px, py;
int main()
{
    n = read(), m = read(); memset(f, -1, sizeof(f));
    for(int i = 1; i <= n; ++i) scanf("%s", s[i]+1);
    for(int i = 1; i <= n; ++i)
        for(int j = 1; j <= m; ++j)
        {
            if(s[i][j] == 'E') px = i, py = j;
            g[i][j] = g[i][j-1]+(s[i][j] == 'o');
            h[i][j] = h[i-1][j]+(s[i][j] == 'o');
        }
    f[0][0][0][0] = 0;
    int pl = py-1, pr = m-py, pd = px-1, pu = n-px, p;
    for(int l = 0; l <= pl; ++l)
        for(int r = 0; r <= pr; ++r)
            for(int d = 0; d <= pd; ++d)
                for(int u = 0; u <= pu; ++u)
                {
                    if(!(~f[l][r][d][u])) continue;
                    int cl = max(r+1, py-l), cr = min(m-l, py+r);
                    int cd = max(u+1, px-d), cu = min(n-d, px+u);
                    if((p = py+r+1) <= m-l) f[l][r+1][d][u] = max(f[l][r+1][d][u], f[l][r][d][u]+h[cu][p]-h[cd-1][p]);
                    if((p = py-l-1) >= r+1) f[l+1][r][d][u] = max(f[l+1][r][d][u], f[l][r][d][u]+h[cu][p]-h[cd-1][p]);
                    if((p = px+u+1) <= n-d) f[l][r][d][u+1] = max(f[l][r][d][u+1], f[l][r][d][u]+g[p][cr]-g[p][cl-1]);
                    if((p = px-d-1) >= u+1) f[l][r][d+1][u] = max(f[l][r][d+1][u], f[l][r][d][u]+g[p][cr]-g[p][cl-1]);
                    ans = max(ans, f[l][r][d][u]);
                }
    printf("%d\n", ans);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
string s;
long long  k;

int main(){
    cin>>s;
    for(int i=0;i<s.size();i++){
       if(s[i]=='7')k++;

    }
if(k>0)cout<<"Yes";
else cout<<"No";

    return 0;}

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

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

  if(s.at(0)=='7' ||s.at(1)=='7' || s.at(2)=='7') cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <bitset>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()

#pragma region UnionFind
struct UnionFind
{
	vector<int> par;

	UnionFind(int n) : par(n, -1) {}
	void init(int n) { par.assign(n, -1); }

	int root(int x)
	{
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool issame(int x, int y)
	{
		return root(x) == root(y);
	}

	bool merge(int x, int y)
	{
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x)
	{
		return -par[root(x)];
	}
};
#pragma endregion
#pragma region GCD
int gcd(int a, int b)
{
	if (a%b == 0)return b;
	return gcd(b, a%b);
}
#pragma endregion
#pragma region chmin
template<class T> inline bool chmin(T& a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma region chmax
template<class T> inline bool chmax(T& a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma endregion

int main()
{
	int a, b; cin >> a >> b;
	vector<string> res;
	rep(i, 50)
	{
		string s = "";
		rep(j, 100)s += '.';
		res.push_back(s);
	}
	rep(i, 50)
	{
		string s = "";
		rep(j, 100)s += '#';
		res.push_back(s);
	}
	int x = 0;
	int y = 0;
	--a, --b;
	while (b > 0)
	{
		if (y >= 100)
		{
			x += 2;
			y = 0;
		}
		res[x][y] = '#';
		y += 2;
		--b;
	}
	x = 51;
	y = 0;
	while (a > 0)
	{
		if (y >= 100)
		{
			x += 2;
			y = 0;
		}
		res[x][y] = '.';
		y += 2;
		--a;
	}
	cout << 100 << " " << 100 << endl;
	rep(i, 100)cout << res[i] << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
  os << "{" <<p.first << ", " << p.second << "}";
  return os;
}
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; }

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int N;
    cin >> N;
    string s, t;
    cin >> s >> t;
    string ans = s + t;
    for(int i = 1; i <= N; i++){
        if(s.substr(N-i,i) == t.substr(0,i)){
            ans = s + t.substr(i, N-i);
        }
    }
    cout << ans.size() << endl;
}

#include <bits/stdc++.h>
using namespace std;
int main() {
    long long int N;
    string s,t;
    cin>>N>>s>>t;
    long long len1,len2,count=0;
    len1=s.length();
    len2=t.length();
if(len1==len2&&len1==N&&N>=1&&N<=100){
 if (N>=len1+len2){
        count=N;
 }
else {
    count=len1+len2;
        for(int i=0;i<=len1;i++){
            for(int j=1;j<=len2;j++){
                if(s.substr(i,len1)==t.substr(0,j)&&len1+len2-j>=N){
                    count=min(len1+len2-j,count);
                }
            }
        }
}
cout<<count;
}
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long int cnt=0;
void Merge(int A[],int left,int mid,int right)
{
    int n1=mid-left;
    int n2=right-mid;
    int L[n1+1],R[n2+1];
    int i,j;
    for(i=0;i<n1;++i)
    {
        L[i]=A[left+i];
    }
    for(i=0;i<n2;++i)
    {
        R[i]=A[mid+i];
    }
    L[n1] = R[n2] =  INT_MAX;
    i=0;j=0;
    for(int k=left;k<right;k++)
    {
        if(L[i]<=R[j])
        {
            A[k]=L[i++];
        }
        else
        {
            A[k]=R[j++];
            cnt+=n1-i;
        }
    }
}
void mergesort(int A[],int left,int right)
{
    int mid;
    if(left+1<right)
    {
        mid=(left+right)/2;
        mergesort(A,left,mid);
        mergesort(A,mid,right);
        Merge(A,left,mid,right);
    }
}

int main(){
    int A[500000],n,i;
    scanf("%d",&n);
    for(i=0;i<n;++i)
    {
        scanf("%d",&A[i]);
    }
    mergesort(A,0,n);
    cout<<cnt<<endl;

    return 0;
}

#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
	char c=getchar();bool f=0;x=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;return x;
}
template<class t,class ...A> inline void read(t &x,A &...a){
	read(x);read(a...);
}
template<class t> inline void write(t x){
	if(x<0) putchar('-'),write(-x);
	else{if(x>9) write(x/10);putchar('0'+x%10);}
}

#define int long long

int n,tot,sum;

signed main(){
	read(n);
	for(int i=1,x,y;i<=n;i++){
		read(x,y);
		tot+=y;sum+=x*y;
	}
	write(tot-1+(sum-1)/9);
}


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

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

	int a, b;
	cin >> a >> b;
	cout << 2*b - a;

	return 0;
}

#include <iostream>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <utility>
#include <typeinfo>
#include <tuple>
using namespace std;

#define MOD 1000000007
#define INF 1e9+7
#define INF_LONG 1e18
#define rep(i, n) for(int i=0; i<n; ++i)
#define rep1(i, n) for(int i=1; i<=n; ++i)
#define rrep(i, m, n) for(int i=m; i<n; ++i)
#define countof(array) (sizeof(array) / sizeof(array[0]))
typedef long long ll;

#define MAX_N 100000
#define MAX_M 100000
#define MAX_V 100
#define MAX_E 100
#define MAX_Q 100000

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

int ddx[] = {-1, 0, 1, 0, -1, 1, -1, 1};
int ddy[] = {0, -1, 0, 1, 1, 1, -1, -1};

string ab = {"ABCDEFGHIJKLMNOPQRSTUVWXYZ"};
string as = {"abcdefghijklmnopqrstuvwxyz"};

ll gcd(ll x, ll y) {
  if(y==0) return x;
  else return gcd(y, x%y);
}

ll lcm(ll x, ll y) {
  return (x*y)/gcd(x, y);
}

void yes() {
  cout << "Yes" << endl;
}

void no() {
  cout << "No" << endl;
}

void print_array(int array[], int len) {

  for(int i=0; i<len; ++i) {
    cout << array[i] << endl;
  }

}

ll absolute(ll x) {
  return (x<0)? (-1)*x : x;
}

//g++ AtCoder.cpp -o AtCoder
//AtCoder

//--------------------------

int main() {

  int n;
  cin >> n;

  cout << 180*(n-2) << endl;

  return 0;
}


#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  vl abc(3);
  rep(i, 3) cin >> abc[i];
  ll K;
  cin >> K;

  stable_sort(abc.begin(), abc.end());

  rep(i, K) abc[2] *= 2;

  cout << abc[0] + abc[1] + abc[2] << endl;

  return 0;
}

#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,s,e) for(int i=(s); i<(e); i++)
#define pb(n) push_back((n))
#define mp(n,m) make_pair((n),(m))
#define all(r) r.begin(),r.end()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 10000000;
const int mod = 1e9 + 7;
const double EPS = 1e-9;

int n, k;
set<string> st;
string s;
vi v;

void calc(int c, vi u){
    if(u.size() == k){
    	// rep(i, u.size()){
    	// 	cout<<" "<<u[i];
    	// }
    	// cout<<endl;
    	sort(all(u));
        do{
            string t;
            for(int i = 0; i < k; i++){
                t += to_string(u[i]);
            }
            st.insert(t);
        }while(next_permutation(all(u)));
        return;
    }
    for(int i = c; i<n; i++){
        u.pb(v[i]);
        calc(i+1, u);
        u.pop_back();
    }
}

int main(){
    while(cin>>n>>k){
        if(n == 0 && k == 0) break;
        v = vi(n);
        rep(i, n) cin>>v[i];
        s = "";
        st.clear();
        vi tmp;
        calc(0,tmp);
        // for(auto it = st.begin(); it != st.end(); it++){
        // 	cout<<"  "<<*it<<endl;
        // }
        cout<<st.size()<<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

int main(){
    ll x; cin >> x;
    ll ans = x/11;
    int r = x % 11;
    int add = 0;
    if(r > 0) add = 1;
    if(r > 6) add = 2;
    cout << ans * 2 + add << endl;
}

#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
#include <iomanip>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll ans=0;llfor;///////////////////////////////////////////////////////////
int main(){
  string S;
  cin>>S;
  int N=S.size();
  int m=1000;
  for(int i=0;i<=N-3;i++){
    char a=S[i]-'0';
    char b=S[i+1]-'0';
    char c=S[i+2]-'0';
    int K=100*a+10*b+c;
    m=min(m,abs(K-753));
  }
  cout<<m;
return 0;}


#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = (l); i < (r); i++)
#define ALL(x) (x).begin(), (x).end()     //昇順
#define RALL(x) (x).rbegin(), (x).rend()  // 降順
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
const long long mod = 1e9 + 7;
typedef long long ll;
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<bool> VB;
typedef vector<int> VI;  // VI a(n);
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<VS> VSS;
typedef vector<VC> VCC;
typedef vector<VI> VII;  // VII a(n,vector<int>(m)) n * m
typedef vector<VL> VLL;
typedef pair<int, int> PII;
typedef map<int, int> MP;  // MP a;
typedef vector<pair<ll, ll>> PS;

template <class T, class U>
bool chmax(T &a, U b) {
  if (a <= b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T, class U>
bool chmin(T &a, U b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
  os << "}";
  return os;
}

// g++ -std=c++11 prac.cpp
// operator << (cout,a);
// chmin(min,a)
vector< ll > divisor(ll n) {
  vector< ll > ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

ll fac(ll n){  // 階乗
	ll sum = 1;
	for(ll i=1; i <= n; i++){ sum *= i; }
	return sum;
}

int main() {
  ll n, m, k, x, y = 0, z = 0, h, ans=0, w, sum = 0, Max = -1, Min = 1e9+1;
  string s, t, u;
  bool ok=true;
  cin >> n;
  w = n%11;
  ans = (n/11)*2;
  if(w>=7) ans += 2;
  else if(w>0) ans+=1;
  pri(ans);
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main() {
	queue<int> s[5];
	char winner;
	for(int i=0;i<3;i++) {
		string st;
		cin>>st;
		for(int j=0;j<(int)st.size();j++) s[i].push(st[j]-'a');
	}
	int now=0;
	while(1) {
		if(s[now].empty()) {winner=now+65;break;}
		int t=s[now].front();
		s[now].pop();
		now=t;
	}
	cout<<winner<<endl;
	return 0;
}


/*
t.me/ivanesipovvpered
*/
#pragma ARCENIY_KIRILLOV_POVELITEL_KROKODILOV
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("no-stack-protector")
//#pragma GCC push_options
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC pop_options
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define rng(a) a.begin(), a.end()
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long
using namespace std;
typedef long long ll;

const double EPS = 1e-5;
const int mod = 1e9 + 7;
const ll INFLL = 1e18;
const int INF = 1e9;
const int maxn = 1e6 + 3;

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

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

bool is_prime(ll a){
    if (a == 2 || a == 3 || a == 5 || a == 7) return true;
    if (a % 2 == 0 || a%3 == 0 || a%5 == 0 || a%7 == 0)
        return false;
    for (ll i = 11; i * i <= a; i += 2){
        if (a % i == 0)
            return false;
    }
    return true;
}

ll binpow(ll a, int n){
    if (a == 0)
        return 1;
    if (a % 2 == 0){
        ll q = binpow(a, n / 2);
        return (q * q)  ;
    }else return (a * binpow(a, n - 1) ) ;
}

main(){
    int n;
    cin >> n;
    vector<ll> primes;
    ll a[n][n];
    for (int i = 0; i < n; i++){
        for (int j = 0; j < n; j++){
            a[i][j] = 0;
        }
    }
    int fe = 2;
    while (primes.size() < n + n + 2){
        if (is_prime(fe)) primes.pb(fe);
        fe++;
    }
    int q = 0;
    for (int i = 0; i < n; i++){
        for (int j = 0; j < n; j++){
            if ((i + j) % 2 == 0){
                a[i][j] = primes[(i + j) / 2];
                q = max(q, (i + j) / 2);
            }
        }
    }
    for (int j = n - 1; j > -1; j--){
        for (int i = 0; i < n; i++){
            if ((i + j) % 2 == 0){
                a[i][j] *= primes[q + 1 + (i + (n - j)) / 2];
            }
        }
    }
    map<ll,bool> kek;
    for (int i = 0; i < n; i++){
        for (int j = 0; j < n; j++){
            if (a[i][j]) continue;
            int qe = 1, we = 1;
            if (i)
                qe = a[i-1][j];
            if (i < n - 1)
                qe = lcm(qe, a[i+1][j]);
            if (j)
                we = a[i][j-1];
            if (j < n-1)
                we = lcm(we,a[i][j+1]);
            int ce = lcm(qe, we);
            int flex = ce;
            while (kek[ce]){
                ce += flex;
            }
            kek[ce] = 1;
            a[i][j] = ce + 1;
        }
    }
    for (int i = 0; i < n; i++){
        for (int j = 0 ; j< n; j++){
            cout << a[i][j] << ' ';
        }
        cout << endl;
    }
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
const int N=505;
const int M=4*N;
const int S=10000;
int pr[M],psz;
bool sieve[S];
ll val[N][N];
vector<pair<int,int> > id;
int Find(pair<int,int> x){ return lower_bound(id.begin(),id.end(),x)-id.begin()+1;}
int main()
{
	int i,j;
	for(i=2;i<S;i++) if(!sieve[i]){ pr[++psz]=i;for(j=i;j<S;j+=i) sieve[j]=1;}
	int n;
	scanf("%i",&n);
	if(n==2) return 0*printf("4 7\n23 10\n");
	for(i=1;i<=n;i++) for(j=1;j<=n;j++) if((i+j)&1)
	{
		int a=i+j,b=i-j;
		id.pb(mp(1,a));
		id.pb(mp(2,b));
	}
	sort(id.begin(),id.end());
	id.erase(unique(id.begin(),id.end()),id.end());
	for(i=1;i<=n;i++) for(j=1;j<=n;j++) if((i+j)&1)
	{
        int a=Find(mp(1,i+j));
        int b=Find(mp(2,i-j));
        val[i][j]=(ll)pr[a]*pr[b];
	}
	for(i=1;i<=n;i++) for(j=1;j<=n;j++) if(!((i+j)&1))
	{
		val[i][j]=1;
		if(i-1>0 || j+1<=n) val[i][j]*=pr[Find(mp(2,i-j-1))];
		if(i+1<=n || j-1>0) val[i][j]*=pr[Find(mp(2,i-j+1))];
		if(i-1>0 || j-1>0) val[i][j]*=pr[Find(mp(1,i+j-1))];
		if(i+1<=n || j+1<=n) val[i][j]*=pr[Find(mp(1,i+j+1))];
		val[i][j]++;
	}
	for(i=1;i<=n;i++) for(j=1;j<=n;j++) printf("%lld%c",val[i][j],j==n?'\n':' ');
	return 0;
}


#include <bits/stdc++.h>

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

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

    int64_t n = s.size();

    int64_t ans = 1;
    vector<int64_t> nums('z' - 'a' + 1);
    for (auto i : irange(0L, n)) {
        int64_t c = s[i] - 'a';

        ans += i - nums[c];

        ++nums[c];
    }

    cout << ans << endl;
}

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

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

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

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

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

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

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

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

void solve() {
    string s; cin >> s;
    ll n = s.size();
    unordered_map<char, ll> m;
    rep(i, n){
        m[s[i]]++;
    }
    ll res = 0;
    for(auto p: m){
        res += p.second*(p.second-1)/2;
    }
    cout << n*(n-1)/2 + 1 - res << endl;
}

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