#include <iostream>
#include <string>
#include <vector>
#include <cstring>
#include <map>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <fstream>
#include <set>
#include <limits>
#include "print.hpp"

using namespace std;

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)

typedef long long ll;

template<typename T>
class Segment {
public:
  T sum;
  T range_min;
  T left_min;
  T right_min;
  T mn;
  Segment(): sum(0),
	     range_min(std::numeric_limits<T>::max()),
	     left_min(std::numeric_limits<T>::max()),
	     right_min(std::numeric_limits<T>::max()),
	     mn(std::numeric_limits<T>::max()){}
  Segment(T x) : sum(x), range_min(x), left_min(x), right_min(x), mn(x){}
  Segment<T> operator=(const T& x);
  Segment<T> operator+=(const Segment<T>& b);
private:
  T add(T a, T b);
  void Swap(Segment<T>& tmp);
};

template <typename T>
Segment<T> Segment<T>::operator=(const T& x) {
  sum = x;
  range_min = x;
  left_min = x;
  right_min = x;
  mn = x;
  return *this;
}

template <typename T>
void Segment<T>::Swap(Segment<T>& a) {
  swap(sum, a.sum);
  swap(range_min, a.range_min);
  swap(left_min, a.left_min);
  swap(right_min, a.right_min);
  swap(mn, a.mn);
}

template <typename T>
T Segment<T>::add(T a, T b) {
  T ret;
  if(a == std::numeric_limits<T>::max() || b == std::numeric_limits<T>::max()) {
    ret = std::numeric_limits<T>::max();
  }else {
    ret = a + b;
  }
  return ret;
}

// This operator is inspired by this code.
// http://www.codeforces.com/contest/150/submission/1193366
template <typename T>
Segment<T> Segment<T>::operator+=(const Segment<T>& b) {
  Segment<T> tmp(*this);
  tmp.sum = this->sum + b.sum;
  tmp.range_min = min(min(this->range_min, b.range_min), this->right_min+b.left_min);
  tmp.left_min = min(this->left_min, add(this->sum, b.left_min));
  tmp.right_min = min(add(this->right_min, b.sum), b.right_min);
  tmp.mn = min(this->mn, b.mn);
  Swap(tmp);
  return *this;
}

template <typename T>
Segment<T> operator+(const Segment<T>& a, const Segment<T>& b) {
  Segment<T> ret(a);
  ret += b;
  return ret;
}

/**
 * rmq processes the following qeries
 * (1) update the value
 * (2) return the minimum value of [a, b)
 */
template<typename T>
class RMQ {
private:

  /**
   * val : n
   * the number of underlying sequence
   */
  int n;

  /**
   * val : nn
   * nn is the minimum value which satisfies the following conditions
   * (1) nn is some power of 2
   * (2) n <= nn;
   */
  int nn;

  /**
   * function : query
   * used in function mn below
   */
  Segment<T> query(int a, int b, int k, int l, int r){
    if(r <= a || b <= l) {
      return Segment<T>();
    }
    if(a <= l && r <= b) {
      return val[k];
    }else {
      Segment<T> vl = query(a, b, k*2+1, l, (l+r)/2);
      Segment<T> vr = query(a, b, k*2+2, (l+r)/2, r);
      return vl+vr;
    }
  }

  bool bound_check(int a, int b) {
    if(a >= b) {
      return false;
    }
    if(a < 0 || n < b) {
      return false;
    }
    return true;
  }
  /**
   * structure of val is as follows
   *  where val is the undermost sequence
   *           0
   *      1          2
   *    3   4     5     6
   *   7 8 9 10 11 12 13 14
   */
  std::vector<Segment<T> > val;

public:
  RMQ(int _n) : n(_n){
    nn = 1;
    while(n > nn) nn *= 2;
    val.resize(nn*2-1);
    for(size_t i = 0; i < val.size(); ++i){
      val[i] = (std::numeric_limits<T>::max());
    }
  }
  RMQ(){}
  RMQ(const std::vector<T>& v) {
    n = static_cast<T>(v.size());
    nn = 1;
    while(n > nn) nn *= 2;
    val.resize(nn*2-1);
    for(size_t i = 0; i < val.size(); ++i){
      val[i] = (std::numeric_limits<T>::max());
    }
    for(size_t i = 0; i < v.size(); ++i) {
      update(i, v[i]);
    }
  }

  inline size_t size(){return n;}

  /**
   * return the value of underlying seq
   * in the example above
   * rmq[0+j] = val[7+j]
   */
  T operator[](int idx){
    if(idx < 0 || n < idx) {
      throw "out of range";
    }
    return val[idx+nn-1].mn;
  }

  /**
   * update the value so that rmq[i] = x
   */
  void update(int i, T x){
    if(i < 0 || n < i) {
      throw "out of range";
    }
    i += nn-1;
    val[i] = x;
    while(i > 0){
      i = (i-1)/2;
      val[i] = val[i*2+1] + val[i*2+2];
    }
  }

  /**
   * return the minimum value in rmq[a,b)
   */
  T mn(int a, int b){
    if(!bound_check(a, b)) {
      throw "invalid range";
    }
    return query(a, b, 0, 0, nn).mn;
  }

  /**
   * return min_{a<=i<j<b} sum[i,j)
   */
  T range_min(int a, int b){
    if(!bound_check(a, b)) {
      throw "invalid range";
    }
    return query(a, b, 0, 0, nn).range_min;
  }

  /**
   * return sum[a,b)
   */
  T sum(int a, int b){
    if(!bound_check(a, b)) {
      return T();
    }
    return query(a, b, 0, 0, nn).sum;
  }
};

const static int inf = 10000000;
const static int mod = 1000000007;

vector<vector<int> > stat;
vector<int> a;
vector<int> ans_f;
vector<int> ans_t;

void go(int from, int to, int level, RMQ<int>& rmq) {
  //  cout << "go " << from << " " << to << " " << level << endl;
  if(from >= to) {
    return;
  }
  if(from+1 == to) {
    rep(i, a[from]-level) {
      ans_f.pb(from);
      ans_t.pb(from);
    }
    return;
  }
  int mn = rmq.mn(from, to);
  //  cout << "mn : " << mn << endl;
  //  print(stat[mn]);
  rep(i, mn-level) {
    ans_f.pb(from);
    ans_t.pb(to-1);
  }
  int pos_f = lower_bound(stat[mn].begin(), stat[mn].end(), from) - stat[mn].begin();
  int pos_t = upper_bound(stat[mn].begin(), stat[mn].end(), to) - stat[mn].begin();
  //  cout << "pos result : " << pos_f << " " << pos_t << endl;

  if(from < stat[mn][pos_f]) {
    go(from, stat[mn][pos_f], mn, rmq);
  }
  for(int i = pos_f; i < pos_t-1; ++i) {
    //    cout << "pos : " <<  i << endl;
    go(stat[mn][i]+1, stat[mn][i+1], mn, rmq);
  }
  if(stat[mn][pos_t-1]+1 < to) {
    go(stat[mn][pos_t-1]+1, to, mn, rmq);
  }
}

int main(){
  int n;
  while(cin >> n){
    stat.clear(); stat.resize(111111);
    a.clear(); a.resize(n);
    ans_f.clear();
    ans_t.clear();
    RMQ<int> rmq(n);

    //    print(stat);
    rep(i, n) {
      cin >> a[i];
      stat[a[i]].pb(i);
      rmq.update(i, a[i]);
    }
    go(0, n, 0, rmq);
    cout << ans_f.size() << endl;
    rep(i, ans_f.size()) {
      cout << ans_f[i]+1 << " " << ans_t[i]+1 << endl;
    }
    //    cout << endl;
  }
  return 0;
}


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

#define debug

#define ll long long
#define pii pair<int,int>
#define pdd pair<double,double>
#define ldouble long double
const ll MOD = 1e9+7;
const int INF = 0x7f7f7f7f;
const ll INFLL = 0x7f7f7f7f7f7f7f7f;

#define End return 0; }
#define of ios::sync_with_stdio(0); cin.tie(0);
#define story int main() {
#define The

int dfs(int curr, int prev, const vector<vector<pair<int,int>>>& graph, const set<int>& bad, set<int>& ans, vector<bool>& visited) {
	if (visited[curr])
		return 0;
	visited[curr] = true;
	int pc = 0;
	if (bad.count(curr))
		pc = 1;
	for (pair<int,int> neighbour: graph[curr]) {
		if (neighbour.first == prev) continue;
		int temp = dfs(neighbour.first, curr, graph, bad, ans, visited);
		// keep even weighted edges
		//cerr << "got " << temp << " from " << neighbour.first+1 << endl;
		if (temp%2 == 0) {
			ans.insert(neighbour.second);
		}
		pc += temp;
	}
	//cerr << "visit " << curr+1 << ", return " << pc << endl;
	return pc;
}

The story of lame:

	int n, m;
	cin >> n >> m;
	set<int> bad;
	// neighbour, index
	vector<vector<pair<int,int>>> graph(n);
	int residue[n];
	int wild = -1;
	for (int i = 0; i < n; i++) {
		cin >> residue[i];
		if (residue[i] == -1)
			wild = i;
	}
	int a, b;
	for (int i = 0; i < m; i++) {
		cin >> a >> b;
		graph[a-1].push_back(pair<int,int>(b-1, i+1));
		graph[b-1].push_back(pair<int,int>(a-1, i+1));
	}
	// count bad
	for (int i = 0; i < n; i++) {
		if (residue[i] != -1 && graph[i].size()%2 != residue[i])
			bad.insert(i);
	}
	if (bad.size()%2 == 1) {
		if (wild == -1) {
			cout << -1 << endl;
			return 0;
		}
		else {
			bad.insert(wild);
		}
	}
	//cerr << "bad: "; for(int it: bad) //cerr << it+1 << " "; //cerr << endl;
	if (bad.empty()) {
		cout << m << endl;
		for (int i = 1; i <= m; i++)
			cout << i << endl;
	}
	else {
		// dfs
		set<int> ans;
		vector<bool> visited(n);
		dfs(*bad.begin(), -1, graph, bad, ans, visited);
		cout << ans.size() << endl;
		for (int e: ans)
			cout << e << endl;
	}

The End


#include<bits/stdc++.h>

using namespace std;

long long kq=0,
int n,j=1;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n;
    for(int i=1; i<=n-2; i++) kq+=(long long)j*(j+1),j++;
    cout << kq;
}


#include<bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

using namespace std;

#define endl '\n'
#define all(C) C.begin(),C.end()
#define allr(C) C.rbegin(),C.rend()
#define PB push_back
#define EB emplace_back
#define present(container, element) (container.find(element) != container.end())
#define spresent(container, element) (container.find(element) != std::string::npos)
#define cpresent(container, element) (find(all(container),element) != container.end())
#define MOD 1000000007

//New Macros
#define F first
#define S second
#define REP(i,a,b) for(int i=a;i<=b;i++)

typedef int64_t ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

void lscan(ll &num) {
	bool n = false;
	num = 0;
	register int c = _getchar_nolock();

	if (c == '-') {
		n = true;
		c = getchar();
	}
	for (; c>47 && c<58; c = _getchar_nolock())
		num = num * 10 + c - 48;
	if (n)
		num *= -1;
}

// a*b%c
ll mulmod(ll a, ll b, ll c) {
	ll x = 0, y = a%c;
	while (b > 0) {
		if (b & 1)
			x = (x + y) % c;
		y = (y << 1) % c;
		b >>= 1;
	}
	return x%c;
}

//a^b%c
ll expmod(ll a, ll b, ll c) {
	if (b) {
		if (b & 1)
			return mulmod(a, expmod(a, b - 1, c), c);
		else
			return expmod(mulmod(a, a, c), b >> 1, c);
	}
	else {
		return 1;
	}
}

int main() {
	/*cout << "Hello World!" << endl;
	cout << expmod(2, 5, MOD);
	*/
	ll N,sum=9,cache;
	lscan(N);
	int rem;
	pair<char,int> temp;
	vector<pair<char,int> >vec(ll(1e8),{'3',0});
	for(int i=0;i<10;i++){
		vec[i].F='1';
		vec[i].S=1<<(i+1);
	}
	if(N>9){
		for(ll i=10;i<=N;i++ ){
			cache = i/10;
			rem = i%10;
			temp = vec[cache-1];
			if(temp.F == '3'){
				i+=9;
			}
			else{
				if(temp.F == '1'){
					rem = 1<<rem;
					if(temp.S & rem){
						if(i<=ll(1e8)){
							vec[i-1]={'1',temp.S};
						}
					}
					else{
						if(i<=ll(1e8)){
							vec[i-1]={'2',temp.S|rem};
						}
					}
					sum++;
				}
				else if (temp.F == '2'){
					rem = 1<<rem;
					if(temp.S & rem){
						if(i<=ll(1e8)){
							vec[i-1]={'2',temp.S};
						}
						sum++;
					}
					else{
						if(i<=ll(1e8)){
							vec[i-1]={'3',0};
						}
					}
				}
			}
		}
	}
	// for(int i=0;i<N;i++){
	// 	cout<<i+1<<" - "<<vec[i].F<<' '<<vec[i].S<<endl;
	// }
	cout<<sum<<endl;
	return 0;
}


#include <iostream>
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fro(i,a,b) for(int i=a;i<b;i++)
#define all(v) v.begin(),v.end()
#define PI              acos(-1.0)
#define vi vector<int>
#define mp make_pair
bool isPrime(int n)
{
    // Corner cases
    if (n <= 1)  return false;
    if (n <= 3)  return true;

    // This is checked so that we can skip
    // middle five numbers in below loop
    if (n%2 == 0 || n%3 == 0) return false;

    for (int i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;

    return true;
}
ll gcd(ll a, ll b)
{
    if(b==0)
        return a;
    else
        return gcd(b,a%b);
}
bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second < b.second);
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
    std::cout.precision(15);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ll p,d;
    cin >> p >> d;
    int n = ((p%10)+1)%10;
    vector<ll> v;
    for(ll i=n;i<=d;i=i+10)
    {
        v.pb(p-i);
    }
    int m=0; ll ans=p;
    for(ll i=0;i<v.size();i++)
    {
        ll x=v[i];
        int c=0;
        while(x>0 && x%10==9)
        {
            c++;
            x=x/10;
        }
        if(c>m)
           {
               m=c;
               ans=v[i];
           }
        else if(m==c)
            {
                if(v[i]>ans)
                    ans=v[i];
            }
    }
    cout << ans;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<unordered_map>
using namespace std;
unordered_map<int, int> mp;
vector<int> g[10]; vector<int> G[10];
struct node
{
	int id; int s; int cd;
};
bool cmp(node a, node b)
{
	return a.s > b.s;
}
node k[10];
int main()
{
	int n; int m; cin >> n >> m;
	for (int i = 1; i <= m; i++)
	{
		int x; int y; cin >> x >> y; g[x].push_back(y);
	}
	int ans = 0;
	for (int i = 1; i <= n; i++)
	{
		k[i].id = i; k[i].s = g[i].size();
	}
	sort(k + 1, k + n+1, cmp);
	for (int i = 1; i <= n; i++)
	{
		mp[k[i].id] = i;
	}
	for (int i = 1; i <= n; i++)
	{
		for (int j = 0; j < g[i].size(); j++)
		{
			G[mp[i]].push_back(mp[g[i][j]]);
		}
	}
	int flag = 0;
	for (int i = 1; i <= n; i++)
	{
		for (int j = 0; j < g[i].size(); j++)
		{
			if (G[i][j] < 7)ans++;
			if (G[i][j] == 7)flag = 1;
		}
	}
	cout << ans + flag;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define FAST ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD  1000000007

int Result = 0;

void DFS(int Idx, vector<vector<int> >& Adj, vector<int>& Temp, vector<int>& Set)
{
    int i, j;

    if(Idx == Temp.size())
    {
        j = 0;
        for(i = 0; i < Set.size(); i++)
        {
            if(Set[i])
            {
                j++;
            }
        }

        Result = max(Result, j);
        return;
    }

    for(i = 0; i < 6; i++)
    {
        vector<int> Temp1 = Set;
        Temp[Idx] = i;

        for(j = 0; j < Idx; j++)
        {
            if(Adj[Idx][j])
            {
                Temp1[((min(Temp[Idx], Temp[j]) * Temp.size()) + max(Temp[Idx], Temp[j]))] = 1;
            }
        }

        DFS((Idx + 1), Adj, Temp, Temp1);
    }
}

int main()
{
    FAST;
    //mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count());

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

    vector<vector<int> > Adj(N, vector<int>(N));

    int i;
    for(i = 0; i < M; i++)
    {
        int a, b;
        cin >> a >> b;

        a--;
        b--;

        Adj[a][b] = 1;
        Adj[b][a] = 1;
    }

    vector<int> Temp(N);
    vector<int> Set(N * N);

    DFS(0, Adj, Temp, Set);

    cout << Result << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
typedef pair<int, int> pi;
typedef pair<pi, int> ppi;
//const int M = 100;
const int M = 1000000007;
#define PI 3.14159265358979
int n, m, k, dots = 0, cou = 0, yes = 0, d, r;
int a, b;

int main()
{

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int i, lim, q, p,mn = INT_MAX, mx = INT_MIN,j,x,y, t, sum = 0, sal = 0, ii, jj, cnt= 0;

	cin >> n;
	if(n % 2 == 0)
	{
		cout << "white" << endl;
		if(n == 2)
			cout << "1 2";
 	}
 	else
 		cout << "black" ;

}


#include <cstdio>
#include <cstdlib>
#include <map>
#include <cmath>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long int ll;
int main(){
    while(true){
        int x,y,z,xx[1000000/2+5],i,te;
        scanf("%d%d%d",&x,&y,&z);
        for(i=0; i<=(x+1)/2; i++){
            int ii=x-i;
            int ss=y-i,ss2=z-i;
            //printf("  %d %d %d\n",i,ss,ii);
            if(ii<0||ss<0)goto v;
            if(z-ss == ii){
                printf("%d %d %d\n",i,ss,ii);
                goto z3;
            }
            v:
            if(ss2<0)continue;
            if(y-ss2 == ii){
                printf("%d %d %d\n",ii,ss2,i);
                goto z3;
            }
        }
        /*te = x;x=y;y=z;z=te;
        for(i=1; i<=(x+1)/2; i++){
            int ii=x-i;
            int ss=y-i,ss2=z-i;
            //printf("  %d %d %d\n",i,ss,ii);
            if(ii<0||ss<0)goto v2;
            if(z-ss == ii){
                printf("%d %d %d\n",ss,ii,i);
                goto z3;
            }
            v2:
            if(ss2<0)continue;
            if(y-ss2 == ii){
                printf("%d %d %d\n",ss2,i,ii);
                goto z3;
            }
        }
         te = x;x=y;y=z;z=te;
        for(i=1; i<=(x+1)/2; i++){
            int ii=x-i;
            int ss=y-i,ss2=z-i;
            //printf("  %d %d %d\n",i,ss,ii);
            if(ii<0||ss<0)goto v3;
            if(z-ss == ii){
                printf("%d %d %d\n",i,ii,ss);
                goto z3;
            }
            v3:
            if(ss2<0)continue;
            if(y-ss2 == ii){
                printf("%d %d %d\n",i,ii,ss2);
                goto z3;
            }
        }*/
        printf("Impossible\n");
        z3:
          continue;
    }
    return 0;
}


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

int main()
{
	int n, a[999], b[999];
	int count;
	cin >> n;
	// delete zero number after...
	while (n % 10 == 0)
	{
		n /= 10;
	}
	int n1 = n;
	// change posible among number...
	int i = 0;
	while (n > 0)
	{
		a[i] = n % 10;
		n /= 10;
		i++;
	}
	// count ...
	while (n1 > 0)
	{
		n1 /= 10;
		count++;
	}
	for (int j = 0; j < count; ++j)
	{
		b[j] = a[count - j - 1];
	}
	int ck = 0;
	for (int j = 0; j < count; ++j)
	{
		if (a[j] - b[j] == 0)
		{
			ck += 0;
		}
		else
			ck++;
		/*cout << "a[" << j << "] = " << a[j];
		cout << endl;
		cout << "b[" << j << "] = " << b[j];
		cout << endl;*/
	}
	if (ck == 0)
		cout << "YES";
	else
		cout << "NO";
}


#include <bits/stdc++.h>
using namespace std;
#define file "yzy"
typedef long long ll;
int read(){
	char c=getchar();
	while(c<'0' || c>'9')
		c=getchar();
	int x=0;
	while(c>='0' && c<='9'){
		x=x*10+c-'0';
		c=getchar();
	}
	return x;
}
const int mod=1000000007;
ll pw[300002];
ll dp[505][505],coff[505];
int main(){
	//freopen(file".in","r",stdin);
	//freopen(file".out","w",stdout);
	int n,m;
	scanf("%d%d",&n,&m);
	pw[0]=1;
	for(int i=1;i<=n*n;i++)
		pw[i]=pw[i-1]*2%mod;
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++)
			coff[j]=pw[(j-i-1)*i]*(pw[j]-pw[i])%mod;
		dp[i][1]=(dp[i][1]+pw[i]-1)%mod;
		for(int j=1;j<=i;j++)
			if (dp[i][j]){
				//printf("dp[%d][%d]=%d\n",i,j,dp[i][j]);
				for(int k=i+1;k<=n;k++)
					dp[k][j+1]=(dp[k][j+1]+dp[i][j]*coff[k])%mod;
			}
	}
	for(int i=1;i<=n;i++)
		ans=(ans+dp[i][m]*pw[(n-i)*i])%mod;
	printf("%lld\n",(ans%mod+mod)%mod);
	//fprintf(stderr,"%.5f",(double)clock()/CLOCKS_PER_SEC);
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 503;
const long long MOD = 1e9 + 7;

int n, k;
void read()
{
	cin >> n >> k;
}

long long dp[MAXN][MAXN], next_dp[MAXN][MAXN], suffix_dp[MAXN][MAXN];
long long pow2[MAXN];

long long add(long long a, long long b)
{
	a += b;

	if (a >= MOD)
		a -= MOD;

	return a;
}
i
void solve()
{
	pow2[0] = 1;
	for (int i = 1; i < MAXN; i++)
		pow2[i] = pow2[i-1] * 2 % MOD;

	dp[1][1] = dp[0][2] = 1;
	for (int i = 0; i <= k; i++)
		for (int j = n + 1; j >= 1; j--)
			suffix_dp[i][j] = suffix_dp[i][j + 1] + dp[i][j];

	for (int i = 2; i <= n; i++)
	{
		memset(next_dp, 0, sizeof(next_dp));

		next_dp[0][i + 1] = 1;
		for (int j = 1; j <= k; j++)
			{
				for (int p = 2; p <= i; p++)
					next_dp[j][p] = dp[j][p-1] * pow2[i - p + 1] % MOD;

				for (int l = i; l >= 1; l--)
						next_dp[j][1] = add(next_dp[j][1], pow2[l - 1] * suffix_dp[j-1][i - l + 1] % MOD);
			}

		for (int j = 0; j <= k; j++)
			for (int p = 0; p <= i + 1; p++)
				dp[j][p] = next_dp[j][p];

		memset(suffix_dp, 0, sizeof(suffix_dp));

		for (int i = 0; i <= k; i++)
			for (int j = n + 1; j >= 1; j--)
				suffix_dp[i][j] = add(suffix_dp[i][j + 1], dp[i][j]);
	}

	int ans = 0;

	for (int i = 1; i <= n + 1; i++)
		ans = add(ans, dp[k][i]);

	cout << ans << endl;
}

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

	read();
	solve();
}


#include<iostream>
#include<iomanip>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
const int mod=998244353;
const int maxn=4001;
int n,l,k;
int dp[2005][2005][2];
long long fir[4005],inv[4005];
int adds(int v)
{
	return (v>=mod)?v-mod:v;
}
long long ksm(long long x,long long n)
{
	long long ans=1;
	while(n)
	{
		if(n&1) ans=ans*x%mod;
		x=x*x%mod;
		n>>=1;
	}
	return ans;
}
void pre()
{
	fir[0]=1;
	for(int i=1;i<=maxn;i++) fir[i]=fir[i-1]*i%mod;
	inv[maxn]=ksm(fir[maxn],mod-2)%mod;
	for(int i=maxn-1;i>=0;i--) inv[i]=inv[i+1]*(i+1)%mod;
}
long long C(int n,int m)
{
	return fir[n]*inv[m]%mod*inv[n-m]%mod;
}
int main()
{
	pre();
	scanf("%d%d%d",&n,&k,&l);
	dp[0][0][0]=1;
	for(int i=0;i<=n;i++)
	for(int j=0;j<=i;j++)
	for(int op=0;op<=1;op++)
	{
		if(!dp[i][j][op]) continue;
		if(j<i) dp[i][j+1][op]=adds(dp[i][j+1][op]+dp[i][j][op]*(i-j)%mod);
		if(i<n) dp[i+1][j][op]=adds(dp[i+1][j][op]+dp[i][j][op]);
		if(!op&&i-j>=k) dp[i][j][op+1]=adds(dp[i][j][op+1]+dp[i][j][op]);
	}
	long long ans=dp[n][n][1]*ksm(2,n)%mod*fir[n]%mod*inv[2*n+1]%mod*l%mod;
	printf("%lld\n",ans);
}


#include <stdio.h>
#include <stdbool.h>

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

	bool even_bd = false;

	for (int i = 0; i < elements; i++){
		int n;
		scanf("%d",&n);

		if(n == 1 || n == elements)
			if(n%2 == 0)
				even_bd = true;
	}

	if(elements%2 == 0 || even_bd)
			printf("%s \n", "No");
		else
			printf("%s \n", "Yes");
	return 0;
}


// cf29b
#include <iostream>
using namespace std;

int main()
{
  int l,d,v,g,r,cycles;
  double timetolights,timefromlights,totaltime,remainder;

#ifndef ONLINE_JUDGE
  FILE *stream;
  freopen_s(&stream,"testfile","r",stdin);
#endif
  cin >> l >> d >> v >> g >> r;
  timetolights=d;
  timetolights/=v;
  timefromlights=l-d;
  timefromlights/=v;
  cycles=(int)timetolights/(g+r);
  remainder=timetolights-cycles*(g+r);
  if(remainder>g) timetolights+=(g+r-remainder);
  totaltime=timetolights+timefromlights;
  cout.precision(8);
  cout.setf(ios::fixed,ios::floatfield);
  cout << totaltime << '\n';
  return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>

using namespace std;

int hm,am,dm;
int hy,ay,dy;
int ch,ca,cd;

struct Status {
    int h,a,d;
    int c;
    Status(int hh, int aa, int dd, int cc) {
	h = hh, a = aa, d = dd, c = cc;
    }
    bool operator < (const Status& xx) const{
	return c > xx.c;
    }
};

bool judge(Status x) {
    int temp = 0;
    if(x.a <= dm) return false;
    if(hm % (x.a-dm) == 0) temp = hm / (x.a - dm);
    else temp = (int)(hm / (x.a - dm)) + 1;
    return (am-x.d)*temp < x.h;
}

bool vis[505][505][505];

bool check(int x, int y , int z) {
    return x < 505 && y < 505 && z < 505;
}

Status bfs() {
    priority_queue <Status> heap;
    vis[hy][ay][dy] = true;
    heap.push(Status(hy,ay,dy,0));
    while(!heap.empty()) {
	Status cur = heap.top();
	heap.pop();
	if(judge(cur)) {
	    return cur;
	}
	if(check(cur.h+1, cur.a, cur.d)){
	    if(!vis[cur.h+1][cur.a][cur.d]) {
		vis[cur.h+1][cur.a][cur.d] = true;
	        heap.push(Status(cur.h+1, cur.a, cur.d, cur.c + ch));
	    }
	} else {
	    heap.push(Status(cur.h+1, cur.a, cur.d, cur.c + ch));
	}

	if(check(cur.h, cur.a+1, cur.d)) {
	    if(!vis[cur.h][cur.a+1][cur.d]) {
		vis[cur.h][cur.a+1][cur.d] = true;
		heap.push(Status(cur.h, cur.a+1, cur.d, cur.c + ca));
	    }
	} else {
	    heap.push(Status(cur.h, cur.a+1, cur.d, cur.c + ca));
	}

	if(check(cur.h, cur.a, cur.d+1)) {
	    if(!vis[cur.h][cur.a][cur.d+1]) {
		vis[cur.h][cur.a][cur.d+1] = true;
		heap.push(Status(cur.h, cur.a, cur.d+1, cur.c + cd));
	    }
	} else {
	    heap.push(Status(cur.h, cur.a, cur.d+1, cur.c + cd));
	}
    }
    return Status(0,0,0,0);
}

int main() {
    memset(vis, false, sizeof(vis));
    cin >> hy >> ay >> dy;
    cin >> hm >> am >> dm;
    cin >> ch >> ca >> cd;
    cout << bfs().c << endl;
    return 0;
}


#include <cstdio>

using namespace std;

const int MOD = 1000000007, MAXN = 550;
typedef long long llint;

int mul (int a, int b) { return (llint)a * b % MOD; }
int add (int a, int b) { return ((llint)a + b + (llint)2 * MOD) % MOD; }

int n, k, dp[MAXN][MAXN], pw[MAXN*MAXN];

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

    pw[0] = 1;
    for (int i = 1; i < MAXN * MAXN; ++i)
        pw[i] = mul(pw[i-1], 2);

    dp[0][0] = 1;

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < k; ++j) {
            for (int ii = i; ii < n; ++ii) {
                int t = pw[(ii-i+1)*(n-1-ii)];
                t = mul( add(dp[ii-i+1], -1), t );
                dp[i+1][ii+1] = add(dp[i+1][ii+1], mul(t, dp[i][ii]));
            }
        }
    }

    int ans = 0;
    for (int i = 0; i <= n; ++i)
        ans = add(ans, dp[i][k]);

    printf ("%d\n", ans);

    return 0;
}


#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define w while
#define elif else if
#define con continue
#define br break
#define ld long double
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define forn(a) for (ll i = 0; i < a; i++)
#define prec(a) fixed << setprecision(a)
#define INF 1000000000000000000
#define inf 1000000000
#define eps 1e-4
#define EPS 1e-8
#define MOD 1000000007

const ll hp1 = 359657;
const ll hm1 = 1000000007;
const ll hp2 = 307;
const ll hm2 = 1000000009;

pair <vector <ll>, vector <ll>> phash(const string &s, ll p, ll m) {
    vector <ll> ans(s.size() + 1, 0);
    vector <ll> ppow(s.size() + 1, 1);
    for (ll i = 0; i < s.size(); i++) {
        ans[i + 1] = (s[i] + ans[i] * p) % m;
        ppow[i + 1] = (ppow[i] * p) % m;
    }
    return {ans , ppow};
}

ll substrhash(pair <vector <ll>, vector <ll>> hash, ll fi, ll la, ll m) {
    return (hash.first[la + 1] - hash.first[fi] * hash.second[la - fi] + m * m) % m;
}

vector <ll> zfu(const string &s) {
    vector <ll> z(s.size(), 0);
    ll l = 0, r = 0;
    for (ll i = 1; i < s.size(); i++) {
        z[i] = max(0ll, min(r - i, z[i - l]));
        w(i + z[i] < s.size() && s[z[i]] == s[z[i] + i])
            z[i]++;
        if (i + z[i] > r) {
            l = i;
            r = i + z[i];
        }
    }
    z[0] = s.size();
    return z;
}

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

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

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

bool in(set <ll> aaa, set <ll> bbb) {
    for (auto i : aaa) {
        if (bbb.find(i) == bbb.end())
            return 0;
    }
    return 1;
}

ll delta(set <ll> aaa, set <ll> bbb) {
    ll su = 0;
    for (auto i : aaa) {
        if (bbb.find(i) == bbb.end()) {
            su++;
        }
    }
    return su;
}

string deleter(string a, ll m) {
    string neww;
    for (ll i = 0; i < m; i++) {
        neww += a[i];
    }
    for (ll i = m + 1; i < a.size(); i++) {
        neww += a[i];
    }
    return neww;
}

vector <vector <ll>> g, gr;
vector <pair <bool, bool>> expaths;
vector <ll> pa;
vector <ll> dpth;

signed main() {
    ll n, m, a, b, k;
    cin >> n >> m;
    dpth.resize(n + 1, inf);
    expaths.resize(n + 1);
    g.resize(n + 1);
    gr.resize(n + 1);
    forn(m) {
        cin >> a >> b;
        gr[b].push_back(a);
        g[a].push_back(b);
    }
    cin >> k;
    pa.resize(k);
    vector <ll> nxt(n + 1);
    nxt[pa[0]] = -1;
    forn(k) {
        cin >> pa[i];
        if (i != 0) {
            nxt[pa[i - 1]] = pa[i];
            nxt[pa[i]] = -1;
        }
    }
    nxt[0] = pa[0];

    queue <pair <pair <ll, ll>, ll>> bfs;
    ll d;
    bfs.push({{pa.back(), 0}, 0});
    w(bfs.size()) {
        pair <ll, ll> v = bfs.front().first;
        ll d = bfs.front().second;
        bfs.pop();
        if (dpth[v.first] < d)
            con;
        elif(dpth[v.first] > d) {
            dpth[v.first] = d;
            expaths[v.first] = {0, 0};
            if (v.second == nxt[v.first])
                expaths[v.first].first = 1;
            else
                expaths[v.first].second = 1;
        } else {
                if (v.second == nxt[v.first])
                    expaths[v.first].first = 1;
                else
                    expaths[v.first].second = 1;
        }
        for (auto ii : gr[v.first]) {
            bfs.push({{ii, v.first}, d + 1});
        }
    }
    ll mx = 0, mn = 0;
    for (ll i = 0; i < pa.size() - 1; i++) {
        if (!expaths[pa[i]].first)
            mn++;
        if (expaths[pa[i]].second)
            mx++;
    }
    cout << mn << " " << mx;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define int long long

int32_t main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int> > a(n);
    for (int i = 0; i < m; ++i) {
        int u, v;
        cin >> u >> v;
        a[v - 1].push_back(u - 1);
    }
    vector<int> p;
    int k;
    cin >> k;
    for (int i = 0; i < k; ++i) {
        int t;
        cin >> t;
        p.push_back(t - 1);
    }
    vector<set<int> > prev(n);
    vector<int> q = {p[p.size() - 1]};
    vector<int> dist(n, 10000000);
    dist[p[p.size() - 1]] = 0;
    vector<bool> used(n);
    int j = 0;
    while (q.size() - j != 0) {
        int now = q[j];
        j += 1;
        used[now] = true;
        for (int i = 0; i < a[now].size(); ++i) {
            int to = a[now][i];
            if (!used[to] && dist[to] >= dist[now] + 1) {
                prev[to].insert(now);
                q.push_back(to);
                dist[to] = dist[now] + 1;
            }
        }
    }
    int ans1 = 0;
    int ans2 = 0;
    for (int i = 0; i < k - 1; ++i) {
        if (prev[p[i]].count(p[i + 1])) {
            if (prev[p[i]].size() > 1) {
                ans2 += 1;
            }
        } else {
            ans1 += 1;
            ans2 += 1;
        }
    }
    cout << ans1 << " " << ans2;
}


#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define p 1000000007
#define pb push_back
#define mp make_pair
typedef long long Int;
typedef pair<Int,Int> pii;
typedef vector<Int> vi;
typedef vector<pii> vii;
Int ah,am;
Int a,ta,b,tb,dh,dm,ahs,ams,dhs,dms;
void fun()
{
	am=dm;
	ah=dh;
	for(Int i=1;i<=ta;i++)
	{
		if(am+1==60)
		{
			if(ah+1==24)
				ah=0;
			else
				ah++;
			am=0;
		}
		else
			am++;
	}
//	cout<<" am and ah "<<ah<<":"<<am<<endl;
}
void fun1()
{
	ams=am;
	ahs=ah;
	for(Int i=1;i<=tb;i++)
	{
		if(ams-1==-1)
		{
			if(ahs-1==0)
				ahs=24;
			else
				ahs--;
			ams=59;
		}
		else
			ams--;
	}
	ams=am;
	ahs=ah;

//	cout<<" ams and ahs "<<ahs<<":"<<ams<<endl;

}
void fun2()
{
	 dms=dm;
	dhs=dh;
	for(Int i=1;i<=tb;i++)
	{
		if(dms-1==-1)
		{
			if(dhs-1==0)
				dhs=24;
			else
				dhs--;
			dms=59;
		}
		else
			dms--;
	}
//	cout<<" dms and dhs "<<dhs<<":"<<dms<<endl;

}
void fun3 ()
{
	Int hour=5;
	Int min=0;
	Int cunt=0,temp=0,previous=0;
	while(1)
	{

	 if(hour>=5){
		if(ahs!=0)
		{
			if(hour>dhs&&hour<ahs)
			cunt++;
			else if(hour==dhs||hour==ahs)
			{
				if(dhs!=ahs)
				{
					if(hour==dhs)
					{
						if(min>dms)
						cunt++;
					}
						if(hour==ahs)
					{
						if(min<ams)
						cunt++;
					}

				}
				else
				if(min<ams&&min>dms)
				cunt++;
			}

		}
		else
		{
			if(hour>ahs&&hour>dhs)
			cunt++;
			else if(hour==dhs||hour==ahs)
			{
				if(dhs!=ahs)
				{
					if(hour==dhs)
					{
						if(min>dms)
						cunt++;
					}
					if(hour==ahs)
					{
						if(min<ams)
						cunt++;
					}

				}
				else
				if(min<ams&&min>dms)
				cunt++;
			}

		}

		}

/*		if(cunt!=previous)
		{
			cout<<hour<<':'<<min<<" ans "<<endl;
			previous=cunt;
		}
		else
		{
				cout<<hour<<':'<<min<<endl;
		}*/
		if(min+b>=60)
		{
			Int add=(min+b)/60;
			temp+=add;
			if(temp==24)
			break;
			if(hour+add>=24)
				hour=hour+add-24;
			else
				hour+=add;
			min=(min+b)%60;

		}
		else
		{
			min+=b;
		}

	}
	cout<<cunt<<endl;

}
int main()
{
	char ch;
	cin>>a>>ta>>b>>tb;
	cin>>dh>>ch>>dm;
	fun();fun1();fun2();
	fun3();

}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll minprime[11];
vector<ll> m;
int main()
{ ll fact[10],i,j;
fact[0]=1;
for(i=1;i<10;i++)
fact[i]=fact[i-1]*i;
minprime[0]=minprime[1]=INT_MAX;
for(i=2;i<10;i++)
if(minprime[i]==0)
{minprime[i]=i;
for(j=i*i;j<10;j+=i)
minprime[j]=i;}
ll n;
cin>>n;
string s;
cin>>s; ll temp;
for(i=0;i<s.size();i++)
{ll temp1=s[i]-48;
if(temp1==1||temp1==0) continue;
while(minprime[temp1]!=temp1)
{temp=temp1;ll c2=0,c3=0;
while(temp!=1)
{
if(minprime[temp]==2) c2++;
else c3++;
temp/=minprime[temp];
}
temp1--; c2-=c3; while(c3--)m.push_back(3); while(c2--) m.push_back(2);
} m.push_back(temp1);
}
sort(m.rbegin(),m.rend());
for(i=0;i<m.size();i++)
cout<<m[i];
return 0;
}


#include<cstdio>
#include<algorithm>
#include<set>
using namespace std;
typedef long long LL;
set<tuple<LL,LL,LL>> s;
LL ans[10000000],poww[10000000],a,b,p,x,anss,ans2[10000000];
int main()
{
	LL i;
	ans[0]=0;poww[0]=1;
	scanf("%lld%lld%lld%lld",&a,&b,&p,&x);
	b%=p;
	for(i=1;i<=x;i++)
	{
		poww[i]=poww[i-1]*a%p;
		ans[i]=a*(ans[i-1]+poww[i-1])%p;
		if(s.count({a,ans[i-1],poww[i-1]})==1)
		{
			anss=i-1;
			break;
		}
		else
			s.insert({a,ans[i-1],poww[i-1]});
		s.find({1,2,3})->get(0);
		ans2[i]=ans2[i-1]+(ans[i]==b);
		printf("f[%lld]=%lld,poww[i]=%lld\n",i,ans[i],poww[i]);
	}
	if(anss==0)
	{
		printf("%lld",ans2[x]);
	}
	else
	{
		printf("%lld",ans2[anss]*(x/anss)+ans2[x%anss]);
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    if(n%2==1) n=(n+1)/2;
    else n=n+1;
    cout<<n<<endl;
    main();

}


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

int main()
{
	int n;
	cin >> n;
	int k = n;
	string stringw;
	for (int i = 1; i<=k; ++i)
		{
			if (i%2!=0)
			{
				if ((n-2)<0)
					{
					stringw =  "Ehab";
					}
				else n-=2;
			}
			else
				{
				if ((n-1)<0)
									{
					stringw = "Mahmoud";
									}
								else n-=1;
				}
		}
	cout << stringw;

}


//in the name of Allah
//#isart
#include<bits/stdc++.h>
using namespace std;
const long long N = 510, mod = 1e9 + 7;
long long dow[N * N], dp[N][N];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, k;
	cin >> n >> k;
	dow[0] = 1;
	for(int i = 1; i <= n * n; i ++)
		dow[i] = dow[i - 1] * 2 % mod;
	dp[0][0] = 1;
	for(int i = 1; i <= n; i ++){
		for(int j = 1; j <= k; j ++){
			for(int x = 0; x < i; x ++){
				dp[i][j] = (dp[i][j] + dp[x][j - 1] * dow[(i - x) * (n - i)] % mod * (dow[i - x] - 1)) % mod;
	long long ans = 0;
	for(int i = 0; i <= n; i ++)
		ans = (ans + dp[i][k]) % mod;
	cout << ans;
	return 0;
}


#include <iostream>
#include <map>
#include <stdio.h>
#include <set>
#include <stack>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <sstream>
#include <list>
#include <fstream>
#include <iomanip>
#include <cstdlib>
#include <string>
#include <string.h>
#include <math.h>
using namespace std;
/**
 * @author: Shamir14 -- Amirhossein Shapoori
 * lordamir14@gmail.com
 * ACM team: AnotherChorMangz
 * Tehran, Iran
 * Still listening to Mark Knopfler...
 * :P
 */
 #define pb push_back

 typedef long long lli;
 const int maxn = 64 + 10, MOD = 1000 * 1000 * 1000 + 7;
 int n, m;
 int ori[maxn][maxn], vis[maxn][maxn], board[maxn][maxn];
 int ax[] = {1, 0, -1, 0}, ay[] = {0, -1, 0, 1};

 bool inrange(int x, int y){
        if(x >= 0 && x < m && y >= 0 && y < n)
            return true;
        return false;
}

 int Check(){
    int ans = n * m / 2, i, j, x, y;
    for(i = 0; i < maxn; i++)
        for(j = 0; j < maxn; j++)
            vis[i][j] = 0;
//  cerr << endl;
//   for(i = 0; i < n; i++){
//       for(j = 0; j < m; j++)
//          cerr << ori[j][i] << " ";
//       cerr << endl;
//   }
//    cerr << ans << endl;
    for(i = 0; i < m; i++)
        for(j = 0; j < n; j++)
            if(!vis[i][j]){
                x = i + ax[ori[i][j]];
                y = j + ay[ori[i][j]];
                vis[i][j] = vis[x][y] = 1;
                if(board[i][j] == board[x][y])
            //        cerr << i << ", " << j << "    ";
                    ans--;
                //if(ans == 9){
                  //  cerr << i << ", " << j << "  ||  " << x << ", " << y << "      ";
                   // break;
               // }
            }
//    if (ans == 9){
//      cerr << endl;
//   for(i = 0; i < n; i++){
//       for(j = 0; j < m; j++)
//          cerr << ori[j][i] << " ";
//       cerr << endl;
//   }
//    }
    return ans;
 }

 int mini;

 void Make(int i, int j){
        int x, y;
        if(ori[i][j] == -1){
            for(int k = 0; k < 4; k++){
                x = i + ax[k];
                y = j + ay[k];
                if(inrange(x, y) && ori[x][y] == -1){
                    ori[i][j] = k;
                    ori[x][y] = (k + 2) % 4;
                    if(i + 1 < m)
                        Make(i + 1, j);
                    else
                        if(j + 1 < n)
                            Make(0, j + 1);
                        else
                            mini = min(Check(), mini);
                    if(mini == 0)
                        break;
                    ori[i][j] = ori[x][y] = -1;
                }
            }
        }else{
            if(i + 1 < m)
                Make(i + 1, j);
            else
                if(j + 1 < n)
                    Make(0, j + 1);
                else
                    mini = min(Check(), mini);
            if(mini == 0)
                break;
        }
 }

int main(){
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    mini = 1000000;
    int i, j;
    cin >> n >> m;
    for(i = 0; i < maxn; i++)
        for(j = 0; j < maxn; j++)
            ori[i][j] = -1;
    for(i = 0; i < n; i++)
        for(j = 0; j < m; j++)
            cin >> board[j][i];

    Make(0, 0);

    cout << mini << endl;

    return 0;
}


#include<bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ll long long
#define all(a) a.begin(),a.end()
#define endl '\n'
#define int ll

using namespace std;

const int N=1e6+3;
const int inf=1e9+3;
const int md=1e9+7;

int a,b,m,x,ans,l,r,mid,vz;
int c[N];

int bin(int a,int n)
{
    int res=1;
    while(n)
    {
        if(n&1)res*=a;
        a*=a;
        res%=m;
        a%=m;
        n/=2;
    }
    return res;
}

bool good(int n)
{
    int res=n*bin(a,n);
    res%=m;
    b%=m;
    return res==b;
}

vector<pair<int,int> > gg;

bool in(int x,int l,int r)
{
    return x>=l&&x<=r;
}

int get_kol(int l,int r,int x)
{
    int l1=0;
    int r1=gg.size()-1;
    while(l1<r1)
    {
        int mid1=(l1+r1)/2;
        if(gg[mid1].ff<x||(gg[mid1].ff==x&&gg[mid1].ss<l))l1=mid1+1;
        else r1=mid1;
    }
    if(gg[l1].ff!=x)return 0;
    if(!in(gg[l1],l,r))return 0;
    int l2=l1;

    l1=0;
    r1=gg.size()-1;
    while(l1<r1)
    {
        int mid1=(l1+r1+1)/2;
        if(gg[mid1].ff>x||
           (gg[mid1].ff==x&&gg[mid1].ss>r))r1=mid1-1;
        else l1=mid1;
    }
    return l1-l2+1;
}

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

    cin>>a>>b>>m>>x;

    for(int i=0;i<m-1;++i)
    {
        c[i]=bin(a,i);
        c[i]=bin(c[i],m-2);
        c[i]=(c[i]*b)%m;
        gg.pb(mp(c[i],i));
    }
    sort(all(gg));

    int anss=0;
    int g1;
    for(int i=0;i<m;++i)
    {
        g1=i;
        if(i==m-1)g1=0;

        l=0;
        r=x/(m)+1;
        while(l<r)
        {
            mid=(l+r+1)/2;
            if(i+mid*(m)<=x)l=mid;
            else r=mid-1;
        }

        if(i+l*(m)>x)continue;

        r=l;
        l=0;
        l+=g1;
        r+=g1;
        if(l%(m-1)<=r%(m-1)&&abs(r-l)<m-1)
        {
            ans+=get_kol(l,r,i);
        }else
        {
            anss+=get_kol(l,m-2,i);
            int p1=r%(m-1);
            ans+=get_kol(0,p1,i);

            r-=p1+1;
            int vgg=r/(m-1);
            ans+=get_kol(0,m-1,i)*vgg;
        }
    }
    cout<<ans-good(0);
}
/*
2 3 5 8
*/


#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e6+10;
int a,b,p,x,inv[N];
int ksm(int x,int y){
	if (!y)return 1;
	int z=ksm(x,y/2);
	z=z*z%p;
	if (y&1)z=z*x%p;
	return z;
}
int main(){
	scanf("%lld%lld%lld%lld",&a,&b,&p,&x);
	for (int i=1;i<p;i++)inv[i]=pow(i,p-2);
	int ans=0;
	for (int i=1;i<p;i++){
		int y=b*inv[Pow(a,i)]%p,M=p*(p-1),n=(p*i%M-(p-1)*y%M+M-1)%M+1;
		if (n<=x)ans+=(x-n)/M+1;
	}
	printf("%lld",ans);
	return 0;
}


#include <bits/stdc++.h>
#define MP make_pair
#define PB push_back
#define int long long
#define st first
#define nd second
#define rd third
#define FOR(i, a, b) for(int i =(a); i <=(b); ++i)
#define RE(i, n) FOR(i, 1, n)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define REP(i, n) for(int i = 0;i <(n); ++i)
#define VAR(v, i) __typeof(i) v=(i)
#define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define __builtin_ctz __builtin_ctzll
#define __builtin_clz __builtin_clzll
#define __builtin_popcount __builtin_popcountll
using namespace std;
template<typename TH> void _dbg(const char* sdbg, TH h) { cerr<<sdbg<<"="<<h<<"\n"; }
template<typename TH, typename... TA> void _dbg(const char* sdbg, TH h, TA... t) {
  while(*sdbg != ',') { cerr<<*sdbg++; } cerr<<"="<<h<<","; _dbg(sdbg+1, t...);
}
#define LOCAL
#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) {{cerr <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<"\n"; }}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define cerr if(0)cout
#endif
#define next ____next
#define prev ____prev
#define left ____left
#define hash ____hash
typedef long long ll;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<pair<int, int> > VPII;
typedef vector<pair<ll, ll> > VPLL;

template<class C> void mini(C&a4, C b4){a4=min(a4, b4); }
template<class C> void maxi(C&a4, C b4){a4=max(a4, b4); }
template<class T1, class T2>
ostream& operator<< (ostream &out, pair<T1, T2> pair) { return out << "(" << pair.first << ", " << pair.second << ")";}
template<class A, class B, class C> struct Triple { A first; B second; C third;
  bool operator<(const Triple& t) const { if (st != t.st) return st < t.st; if (nd != t.nd) return nd < t.nd; return rd < t.rd; } };
template<class T> void ResizeVec(T&, vector<int>) {}
template<class T> void ResizeVec(vector<T>& vec, vector<int> sz) {
  vec.resize(sz[0]); sz.erase(sz.begin()); if (sz.empty()) { return; }
  for (T& v : vec) { ResizeVec(v, sz); }
}
typedef Triple<int, int, int> TIII;
template<class A, class B, class C>
ostream& operator<< (ostream &out, Triple<A, B, C> t) { return out << "(" << t.st << ", " << t.nd << ", " << t.rd << ")"; }
template<class T> ostream& operator<<(ostream& out, vector<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }
template<class T> ostream& operator<<(ostream& out, set<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }
template<class L, class R> ostream& operator<<(ostream& out, map<L, R> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }

const int P = 1e9 + 7;
const int N = 3e6;
int fac[N];
int inv_fac[N];
int k_pow[N];
int spow(int a, int b) {
	int r = 1;
	while (b) {
		if (b % 2) {
			r = a * r % P;
		}
		a = a * a % P;
		b /= 2;
	}
	return r;
}
int Inv(int a) {
	return spow(a, P - 2);
}
int DownFac(int a, int b) {
	if (a < b) { return 0; }
	return fac[a] * inv_fac[a - b] % P;
}
int Go(int k, int w, int min_len) { // ile jest stringow dla ktorych wynik jest <=w
	// nie ma zadnego dlugosci w+1
	int max_len = k + 1 + w;
	int res = 0;
	FOR (len, min_len, max_len) {
		if (len >= 2 * w) {
			int c = len - 2 * w;
			int here = DownFac(k, c);
			int side = DownFac(k - c, w);
			int lol = here * side % P * side % P;
			debug(k, w, len, lol);
			res = (res + lol) % P;
		} else {
			int c = 2 * w - len;
			int side = DownFac(k, w - c);
			int mid = Pow(k, c);
			int lol = side * side % P * mid;
			debug(k, w, len, lol);
			res = (res + lol) % P;
		}
	}
	debug(res);
	return res;
}
int32_t main() {

  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(10);
  cerr << fixed << setprecision(10);
  cin.tie(0);
  int w, k;
  cin>>k>>w;
  fac[0] = 1;
  k_pow[0] = 1;
  RE (i, N - 1) {
  	fac[i] = fac[i - 1] * i % P;
  	k_pow[i] = k_pow[i - 1] * k % P;
  }
  inv_fac[N - 1] = Inv(fac[N - 1]);
  FORD (i, N - 2, 0) {
  	inv_fac[i] = inv_fac[i + 1] * (i + 1) % P;
  }
  cout<<(Go(k, w, w) - Go(k, w - 1, w) + P) % P<<endl;

  return 0;
 }


#include <bits/stdc++.h>
#define MP make_pair
#define PB push_back
#define int long long
#define st first
#define nd second
#define rd third
#define FOR(i, a, b) for(int i =(a); i <=(b); ++i)
#define RE(i, n) FOR(i, 1, n)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define REP(i, n) for(int i = 0;i <(n); ++i)
#define VAR(v, i) __typeof(i) v=(i)
#define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define __builtin_ctz __builtin_ctzll
#define __builtin_clz __builtin_clzll
#define __builtin_popcount __builtin_popcountll
using namespace std;
template<typename TH> void _dbg(const char* sdbg, TH h) { cerr<<sdbg<<"="<<h<<"\n"; }
template<typename TH, typename... TA> void _dbg(const char* sdbg, TH h, TA... t) {
  while(*sdbg != ',') { cerr<<*sdbg++; } cerr<<"="<<h<<","; _dbg(sdbg+1, t...);
}
#define LOCAL
#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) {{cerr <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<"\n"; }}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define cerr if(0)cout
#endif
#define next ____next
#define prev ____prev
#define left ____left
#define hash ____hash
typedef long long ll;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<pair<int, int> > VPII;
typedef vector<pair<ll, ll> > VPLL;

template<class C> void mini(C&a4, C b4){a4=min(a4, b4); }
template<class C> void maxi(C&a4, C b4){a4=max(a4, b4); }
template<class T1, class T2>
ostream& operator<< (ostream &out, pair<T1, T2> pair) { return out << "(" << pair.first << ", " << pair.second << ")";}
template<class A, class B, class C> struct Triple { A first; B second; C third;
  bool operator<(const Triple& t) const { if (st != t.st) return st < t.st; if (nd != t.nd) return nd < t.nd; return rd < t.rd; } };
template<class T> void ResizeVec(T&, vector<int>) {}
template<class T> void ResizeVec(vector<T>& vec, vector<int> sz) {
  vec.resize(sz[0]); sz.erase(sz.begin()); if (sz.empty()) { return; }
  for (T& v : vec) { ResizeVec(v, sz); }
}
typedef Triple<int, int, int> TIII;
template<class A, class B, class C>
ostream& operator<< (ostream &out, Triple<A, B, C> t) { return out << "(" << t.st << ", " << t.nd << ", " << t.rd << ")"; }
template<class T> ostream& operator<<(ostream& out, vector<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }
template<class T> ostream& operator<<(ostream& out, set<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }
template<class L, class R> ostream& operator<<(ostream& out, map<L, R> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }

const int P = 1e9 + 7;
const int N = 3e6;
int fac[N];
int inv_fac[N];
int k_pow[N];
int spow(int a, int b) {
	int r = 1;
	while (b) {
		if (b % 2) {
			r = a * r % P;
		}
		a = a * a % P;
		b /= 2;
	}
	return r;
}
int Inv(int a) {
	return spow(a, P - 2);
}
int DownFac(int a, int b) {
	if (a < 0) { return 0; }
	if (b < 0) { cout<<"dupa"<<endl; }
	if (a < b) { return 0; }
	return fac[a] * inv_fac[a - b] % P;
}
int Go(int k, int w, int min_len) { // ile jest stringow dla ktorych wynik jest <=w
	// nie ma zadnego dlugosci w+1
	int max_len = k + 1 + w;
	int res = 0;
int inv_k = Inv(k);
int mid = -1;
assert(max_len - min_len <= k + 5);
	FOR (len, min_len, max_len) {
		//if (len % 10000 == 0) {
	//		cout<<len<<endl;
	//	}
		if (len >= 2 * w) {
			int c = len - 2 * w;
			int here = DownFac(k, c);

			int side = DownFac(k - c, w);
			int lol = here * side % P * side % P;
			debug(k, w, len, lol);
			res = (res + lol) % P;
		} else {
			int c = 2 * w - len;
			int side = DownFac(k, w - c);
if (mid == -1) { mid = spow(k, c); }
else { mid = mid * inv_k % P; }
			int lol = side * side % P * mid;
			debug(k, w, len, lol);
			res = (res + lol) % P;
		}
	}
	debug(res);
	return res;
}
int32_t main() {

  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(10);
  cerr << fixed << setprecision(10);
  cin.tie(0);
  int w, k;
  cin>>k>>w;
  fac[0] = 1;
  k_pow[0] = 1;
  RE (i, N - 1) {
  	fac[i] = fac[i - 1] * i % P;
  	k_pow[i] = k_pow[i - 1] * k % P;
  }
  inv_fac[N - 1] = Inv(fac[N - 1]);
  FORD (i, N - 2, 0) {
  	inv_fac[i] = inv_fac[i + 1] * (i + 1) % P;
  }
  //cout<<"hehe"<<endl;
  cout<<(Go(k, w, w) - Go(k, w - 1, w) + P) % P<<endl;

  return 0;
 }


#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
#include <cstring>
#define maxk 2000005
#define mod 1000000007
using namespace std;

int k,w;
long long factorial[maxk],inverse[maxk];

long long power(int a,int x) {
  if (!x) return 1;
  long long q = power(a,x/2);
  q = (q * q) % mod;
  if (x & 1) q = (q * a) % mod;
  return q;
}

long long binom(int a,int b) {
  if (a < b) return 0;
  long long denominator = (inverse[b] * inverse[a - b]) % mod;
  return (factorial[a] * denominator) % mod;
}

long long Anom(int a,int b) {
  return (binom(a,b) * factorial[b]) % mod;
}

long long func(int ws,int start) {
  long long ret = 0;
  // length of string is at least w + 1
  for (int len = ws + start; len < ws + k; len++) {
    int r1 = len - ws + 1,l2 = ws;
    if (l2 <= r1) {
      int comlen = r1 - l2 + 1;
      long long f1 = Anom(k,comlen);
      long long f2 = Anom(k - comlen,len - ws + 1 - comlen);
      f2 = (f2 * f2) % mod;
      ret = (ret + f1 * f2) % mod;
    }
    else {
      long long halves = Anom(k,len - ws + 1);
      halves = (halves * halves) % mod;
      long long free = power(k,len - 2 * (len - ws + 1));
      ret = (ret + halves * free) % mod;
    }
  }
  return ret;
}

int main() {
  factorial[0] = 1;
  for (int i = 1; i < maxk; i++) factorial[i] = (factorial[i - 1] * i) % mod;
  for (int i = 0; i < maxk; i++) inverse[i] = power(factorial[i],mod - 2);
  scanf("%d %d", &k, &w);
  cout << (func(w + 1,0) - func(w,1) + mod) % mod;
}


/***

                                Bismillahir Rahmanir Rahim
                                Rabbi Zidni Ilma
                                Author : Saidur Rahman
                                Department of CSE, City University, Bangladesh.

***/

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

typedef         long long           ll;
#define         endl                "\n"
#define         ff                  first
#define         sf                  scanf
#define         pf                  printf
#define         ss                  second
const           int                 MAX=1e8;
#define         log_out             return 0
#define         pb                  push_back
#define         log_in              int main()
#define         PI                  acos(-1.0)
#define         vi                  vector<int>
#define         newline             printf("\n")
#define         pri                 pair<int,int>
#define         sff(a)              scanf("%d",&a)
#define         NO                  printf("NO\n")
#define         no                  printf("no\n")
#define         No                  printf("No\n")
#define         YES                 printf("YES\n")
#define         Yes                 printf("Yes\n")
#define         yes                 printf("yes\n")
#define         sfl(a)              scanf("%lld",&a)
#define         sfl(a)              scanf("%lld",&a)
#define         pff(a)              printf("%d\n",a)
#define         pfl(a)              printf("%lld\n",a)
#define         sfff(a,b)           scanf("%d%d",&a,&b)

#define         f0(i,b)             for(int i=0;i<(b);i++)
#define         sfll(a,b)           scanf("%lld%lld",&a,&b)
#define         sffff(a,b,c)        scanf("%d%d%d",&a,&b,&c)
#define         clock_start         clock_t tStart = clock()
#define         sflll(a,b,c)        scanf("%lld%lld%lld",&a,&b,&c)
#define         input               freopen("input.txt", "r", stdin)
#define         output              freopen("output.txt", "w", stdout)
#define         watch(x)            cout << (#x) << " is " << (x) << endl
#define         show_time           printf("Time taken: %.3fs\n", (double)(clock() - tStart) / CLOCKS_PER_SEC)

int         ToggleBit (int n, int X)    { return n ^ (1 << X); }
int         SetBit (int n, int X)       { return n | (1 << X); }
int         ClearBit (int n, int X)     { return n & ~(1 << X); }
bool        CheckBit (int n, int X)     { return (bool)(n & (1 << X)); }

            ///////////////////////////////////////////////////////////////////////////
        ///////////////////////// DO NOT TOUCH BEFORE THIS LINE //////////////////////////
            //////////////////////////////////////////////////////////////////////////

log_in
{

 #ifndef ONLINE_JUDGE
    input;
    output;
#endif
    int n;
    sff(n);
    vi v;
    for (int i = 0; i < n;i++)
    {
        int x;
        sff(x);
        v.pb(x);
    }
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    bool ok = false;
    for (int i = 0; i < v.size()-2;i++)
    {
        if(v[i]==v[i+1]-1 && v[i]==v[i+2]-2)
        {
            ok = true;
            break;
        }
    }
    ok ? YES : NO;
    log_out;
}


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

int main()
{     int n;
       scanf("%d",&n);
          vector<int>  S;
            int v;
        for(int i = 0;i<n;i++)
        {
            scanf("%d",&v);
             S.push_back(v);
        }
          sort(S.begin(),S.end());
            S.resize(unique(S.begin(), S.end()) - S.begin());
               int h =  0 ;
             for(int i = 0;i<S.size()-2;i++)
             {
                 if(S[i]+1==S[i+1]&&S[i+1]+1==S[i+2]&&h==0)
                        { h =1;
                     cout<<"YES"<<endl;}
             }
              if(!h)
              {
                  cout<<"NO"<<endl;
              }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
   long long int n,k,i,z=0;
   cin>>n>>k;
   string s;
   cin>>s;
   long long int freq[100]={0};
   for(i=0;i<s.length();i++)
   {
       freq[s[i]]++;
   }
   for(i=0;i<100;i++)
   {
       if(freq[i]>0)
       {
           z=max(z,freq[i]);
       }
   }
   if(z<=k)
   cout<<"YES"<<endl;
   else
   cout<<"NO"<<endl;

}


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

long long power(long long a, int b, long long mod){
    long long result = 1;
    while (b) {
        if (b&1) {
            result *= a;
            result %= mod;
        }
        a *= a;
        a %= mod;
        b >>= 1;
    }
    return result;
}

long long inverse (long long a, long long mod) {
	return power(a,mod-2,mod);
}

long long fact(long long a, long long mod) {
	long long res=1;
	while(a) {
		res *= a;
		res %= mod;
		a--;
	}
	return res;
}

const int mod=1e9+7;

int32_t main() {
	#ifdef ONLINE_JUDGE
		ios::sync_with_stdio(0);
		cin.tie(0);
		cout.tie(0);
	#endif
	int N, K;
	cin >> N >> K;
	long long ans=0;
	vector<long long> p(N+1,0);
	for (int j = K+2; j <= N; ++j) {
		ans = (j-K-1) + p[j-1]-p[j-K-1]+mod;
		ans %= mod;
		ans *= fact(j-2, mod);
		ans %= mod;
		p[j] = p[j-1] + (ans*inverse(fact(j-1,mod),mod))%mod;
		p[j] %= mod;
	}
	ans = (fact(N-1,mod)*p[N])%mod;
	cout << ans << "\n";
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
//#define endl '\n'
#define rep(i, l, r) for (int i = l; i<r;i++)
#define vi vector<int>
#define all(v) v.begin(),v.end()
#define pb(c) push_back(c)
#define vii vector<pair<int,int>>
#define vvi vector<vector<int>>
#define ii pair<int,int>
#define mp(i, j) make_pair(i,j)
#define ull unsigned long long int
#define ll  long long int
#define PI  3.141592653589793238
#define MOD ((ll)1e9 + 7)
#define INF ((int)1e9)
#define EPS 1e-14
#define MAXN 1000600
ll D[MAXN];
ll sum;
ll perm[MAXN];
ll invPerm[MAXN];

ll mod_pow(ll x, ll y) {
    // exponentiation by squaring
    ll r = 1;
    while (y > 0) {
        if (y % 2 == 1) {
            r = (r * x) % MOD;
        }
        x = (x * x) % MOD;
        y /= 2;
    }
    return r;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
#ifdef DEBUG
    freopen("input", "r", stdin);//  flush(cout);
#endif
    perm[0] = 1;
    invPerm[0] = 1;
    rep (i,1,MAXN) {
        perm[i] = (perm[i-1]*i)%MOD;
        invPerm[i] = mod_pow(perm[i],MOD-2)%MOD;
    }
    ll n,k;
    cin>>n>>k;
    if (k>=n) {
        cout<<"0";
        return 0;
    }

    rep (i,k,n) {
        int len = i+1;
        ll tempSum = 0;
        rep (h,len-k,len)
            tempSum = (tempSum+ (D[h]*(invPerm[h-1]))%MOD)%MOD;

        assert(sum==tempSum);
        D[len] = (D[len] + ((len-k-1)*perm[len-2])%MOD)%MOD + (sum*perm[len-2])%MOD;
        D[len] = D[len]%MOD;
        sum = (sum + (D[len]*invPerm[len-1])%MOD - (D[len-k]*invPerm[len-k-1])%MOD + MOD)%MOD ;
    }
    ll ans = 0;
       rep (i,k,n) {
        int len = i+1;
        ans = (ans + (((D[len]*perm[n-1])%MOD)*(invPerm[len-1]))%MOD)%MOD ;

    }
    cout<<ans;
    return 0;
}


#include<new>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<cmath>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<utility>
#include<iostream>
#include<algorithm>
using namespace std;

bool judge;
string a,b;

int main()
{
    cin>>a;
    b+=a[0];
    int i=0;
    while(i<a.size())
    {
            if(a[i]=='d')
            {
                         if(a[i+1]=='o'&&a[i+2]=='t')
                         {
                                 b+='.';
                                 i+=3;
                                 continue;
                         }
                         else continue;
            }
            else
            {
                if(a[i]=='a')
                {
                             if(a[i+1]=='t'&&judge==false)
                             {
                                     b+='@';
                                     i+=2;
                                     judge=true;
                                     continue;
                             }
                             else continue;
                }
                else b+=a[i];
                i++;
            }
    }
    cout<<b<<endl;
    return 0;
}


// A.cpp : Defines the entry point for the console application.
//

#include <stdio.h>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <map>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <cstring>

using namespace std;

int main()
{
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	int s=2*c+(b-1)*(c+1);
	printf("%d",s);
	return 0;
}


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

using namespace std;

#define SZN 105
#define MXN 100005
#define _ ios_base::sync_with_stdio(0);
// #define debug
#define x first
#define y second

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

const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-8; // 1e-10 sometimes; check eps when using double
const double pi = acos(-1.0);
const int dx[] = {-1, 1, 0, 0};
const int dy[] = {0, 0, -1, 1};

/* structs */

/* globals */
LLI s;
int a[SZN], num;
map<LLI, LLI> memo[SZN];

/* function declarations */
LLI dfs(int cur, LLI sum) {
    if (sum > s) return 0;
    if (cur == num) {
        if (sum == s) return 1;
        return 0;
    }
    if (memo[cur].count(sum)) return memo[cur][sum];
    LLI res = 0;
    if (a[cur]) res = dfs(cur+1, sum+(1LL<<cur))*2;
    else res = dfs(cur+1, sum) + dfs(cur+1, sum+(1LL<<(cur+1)));
    return memo[cur][sum] = res;
}

/* Problem */
int main() { _ // disable sync with stdio
    LLI x, tmp;
    while (cin >> s >> x) {
        tmp = x;
        num = ceil(log2(s+1));
        for (int i = 0; i < num; ++i) {
            a[i] = tmp & 1;
            tmp >>= 1;
        }
#ifdef debug
        cout << "digits: " << num << "\n";
        for (int i = 0; i < num; ++i) cout << a[i];
        cout << "\n";
#endif
        LLI res = dfs(0, 0);
        if (s == x) res -= 2;
        cout << res << "\n";
        for (int i = 0; i < num; ++i) memo[i].clear();
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mk make_pair
int main(){
	long long int p,d;
	cin >> p;
	cin >> d;
	if(d == 0){
		cout << p << endl;
		return 0;
	}

	vector<pair<long long int, long long int> >v;
	long long int price,ll;
	for(long long int i = 1; i <= d; i++){
		price = p-i;
		ll = price;

		if(price %10 == 9){
			int cnt = 0;
			while(price>0){
				if(price%10 != 9)
					break;
				cnt++;
				price /= 10;
			}
			v.pb(mk(cnt, ll));
		}
	}
	sort(v.begin(), v.end());
	cout << v[v.size()-1].second<<endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mk make_pair
int main(){
	long long int p,d;
	cin >> p;
	cin >> d;
	if(d == 0){
		cout << p << endl;
		return 0;
	}

	vector<pair<long long int, long long int> >v;
	long long int j,price,ll;
	for(long long int i = 1; i <= d; i+=1){
		price = p-i;
		j = i;
		if(price%10 == 9)
			break;
	}

	for(long long int i = j; i <= d;){
		price = p-i;
		ll = price;

		if(price %10 == 9){
			int cnt = 0;
			while(price>0){
				if(price%10 != 9)
					break;
				cnt++;
				price /= 10;
			}
			if(price == 0){
				cout << ll <<endl;
				return 0;
			}

			v.pb(mk(cnt, ll));
		}
	}
	if(v.size() == 0){
		cout << p <<endl;
		return 0;
	}
	sort(v.begin(), v.end());
	cout << v[v.size()-1].second<<endl;
	return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;
typedef long long ll;

int main() {
    ll p, d; cin >> p >> d;
    ll num = p - d, mul = 1;
    ll currD = num;
    while(num <= p && currD) {
       ll d = currD % 10;
       if(d != 9) {
           ll diff = 9 - d;
           if(num + diff * mul <= p) num += diff * mul;
           else break;
       }

       mul *= 10;
       currD /= 10;
    }
    ll rem = p - num;
    while(rem >= mul) {
        ll check = mul/10;
        ll d = (num/check) % 10;
        if(d * mul <= rem) {
            num += d * mul;
        } else if(rem > mul) {
            while(rem > mul) {
                num += mul;
                rem -= mul;
            }
        }
    }
    cout << num << endl;
}


#include <iostream>
#include <stdio.h>
#include<bits/stdc++.h>
#define ll long long
#define fr first
#define sc second
#define ii pair < int , int >
#define mp make_pair
using namespace std;
ll s , x;
map < pair < pair < ll , int > , ii > , ll > memo;
ll solve(ll sum , int bt,int ok1 , int ok2)
{
    if(sum  > s || bt > 40)
        return 0;
    if(sum == s && ok1 && ok2 && bt == 40)
        return 1;
    ll &ret = memo[mp(mp(sum,bt),mp(ok1,ok2))];
    if(ret !=0)
        return ret-1;
    ll y = (1LL<<bt)&x;
    ll x1 = 0 , x2 = 0;
    if(y)
    {
        ll sum1 = 0;
        sum1 = sum +1LL * (1LL<<bt);
        x1 = solve(sum1 , bt+1,ok1,1);
        x2 = solve(sum1 , bt+1,1,ok2);
    }
    else
    {
        ll sum1 = sum + 1LL * (1LL<<bt) * 2;
        x1 = solve(sum,bt+1,ok1,ok2);
        x2 = solve(sum1,bt+1,1,1);
    }
    ret = x1+x2+1;
    return x1+x2;
}
int main()
{
  cin>>s>>x;
  cout<<solve(0,0,0,0);
}


#include <iostream>

using namespace std;

int main()
{
    int n,k;
    cin >> n >> k;
    int P[n+1];
    for (int i=1; i<n+1; i++){
        P[i]=i;
    }
    int ile = 1;
    while (k>ile){
        int ws = n;
        while ( P[ws-1] != ws-1) ws--;
        if (P[ws] == ws){
            P[ws] = ws-1;
            P[ws-1] = ws;
            ile++;
            for (int i=ws+1; i<n+1; i++) P[i] = i;
        }
        else{
            P[ws-1] = ws;
            P[ws] = ws-1;
            ile++;
            for (int i=ws+1; i<n+1; i++) P[i] = i;
        }
    }

    for (int i=1; i<n+1; i++){
        cout << P[i] << " ";
    }

}


#include<stdio.h>

struct node{
	int tos = 0;
	int to[10];
	void add(int x){
		to[++tos] = x;
	}
	bool operator < (node &x){
		return tos <= x.tos;
	}
}a[10];

int main(){
		int n, m;
		scanf("%d%d", &n, &m);
		for(int i = 1; i <= n ;++i){
			int x, y;
			scanf("%d%d", &x, &y);
			a[x].add(y);
			a[y].add(x);
		}
		if(n < 7)
			printf("%d\n", m);
		else if(m>15) printf("%d\n", 16);
		else printf("%d\n", m);

}


include <stdio.h>
#include <stdlib.h>
char str[210];
int main()
{
    int n,u,d,l,r,i,j,ans;
    while(scanf("%d",&n)!=EOF)
    {
        scanf("%s",str);

        for(i=0;i<n;++i)
        {
            for(j=i;j<n;++j)
            {
                u=d=l=r=0;
                  ans=0;
                if(str[j]=='U')
                    u++;
                if(str[j]=='D')
                    d++;
                if(str[j]=='L')
                    l++;
                if(str[j]=='R')
                    r++;
                if(u==d&&l==r)
                    ans++;
            }
        }
        printf("%d\n",ans);
    }

    return 0;
}


#include <bits/stdc++.h>

//BIAR MANTAB LAH YA
#define Willy using
#define Indrayana namespace
#define Komara std

Willy Indrayana Komara;

void king(int a, int b, int c, int d)
{
    int count = 0;
    if (a > c && b < d)
    {
        while (a != c || b != d)
        {
            a--;
            b++;
            count++;
        }
    }
    else if (a < c && b < d)
    {
        while (a != c || b != d)
        {
            a++;
            b++;
            count++;
        }
    }
    else if (a < c && b > d)
    {
        while (a != c || b != d)
        {
            a++;
            b--;
            count++;
        }
    }
    else if (a > c && b > d)
    {
        while (a != c || b != d)
        {
            a--;
            b--;
            count++;
        }
    }
    if (a == c && b != d)
    {
        count += abs(b-d);
    }
    else if (b == d && a != c)
    {
        count += abs(a-c);
    }
    cout << count << '\n';
}

void bishop(int a, int b, int c, int d)
{
    if ((a+b) % 2 != (c+d) % 2)
    {
        cout << "0" << ' ';
    }
    else if (abs(a-c) == abs(b-d))
    {
        cout << "1" << ' ';
    }
    else
    {
        cout << "2" << ' ';
    }

}

void rook(int a, int b, int c, int d)
{
    if (a == c || b == d)
    {
        cout << "1" << ' ';
    }
    else if (a != c && b != d)
    {
        cout << "2" << ' ';
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;
    rook(r1, c1, r2, c2);
    bishop(r1, c1, r2, c2);
    king(r1, c1, r2, c2);
    return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <math.h>
#include <cmath>
using namespace std;

int main() {

	int a[113], n;
	cin >> n;
	for (int i = 1; i <= n; ++ i){
		cin >> a[i];
	}
	if (a[1] % 2 == 1 && a[n] % 2 == 1){
		cout << "YES";
	}
	else {
		cout << "NO";
	}

}


#include <bits/stdc++.h>
using namespace std;
string commands;
int n;
bool moved=0,founded=0;
int solver(int i,int x,int y,int idx){

    if(x==0&&y==0&&idx!=-1){
       founded=1; return 0;
    }
    if(i==n){
        return 0;
       // else return -(int)1e6;
    }

    int ret=0;
  if(commands[i]=='U'){
            ret=max(solver(i+1,x,y+1,1)+1,ret);
moved=1;
    }
    if(commands[i]=='D'){
            ret=max(solver(i+1,x,y-1,2)+1,ret);
moved=1;
    }
    if(commands[i]=='L'){

            ret=max(solver(i+1,x-1,y,3)+1,ret);
moved=1;
    }
    if(commands[i]=='R'){

            ret=max(solver(i+1,x+1,y,4)+1,ret);
moved=1;
    }

        ret=max(solver(i+1,x,y,idx),ret);

  return ret;

}

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

int x=solver(0,0,0,-1);
if(founded)cout<<x;
else cout<<0;

    return 0; }


#include <iostream>
using namespace std;
#include <math.h>
#include <map>
#include <queue>
int main()
{
    float r, x1,y1,x2,y2;
    cin >> r >> x1 >> y1 >> x2 >> y2;
    pair<int,int> temp[13] = {pair<int,int>(-1,1),pair<int,int>(0,1),pair<int,int>(1,1),pair<int,int>(-1,0),pair<int,int>(0,0),pair<int,int>(1,0),pair<int,int>(-1,-1),pair<int,int>(0,1),pair<int,int>(1,-1),pair<int,int>(2,0),pair<int,int>(-2,0),pair<int,int>(0,2),pair<int,int>(0,-2)};
    int res = 0, tx, ty;
    pair<int,int> c;
    queue<int> x,y,step;
    x.push(x1);
    y.push(y1);
    step.push(0);
    queue<int> q;
    map<pair<int,int>,int> check;
    while(1)
    {
        tx = x.front();
        ty = y.front();
        res = step.front();
        if (tx == x2 && ty == y2)
            break;
        step.pop();
        x.pop();
        y.pop();
        for (int i = 0; i < 13; ++i)
        {
            c.first = tx + r * temp[i].first;
            c.second = ty + r * temp[i].second;
            if (check[c] != 1)
            {
                x.push(c.first);
                y.push(c.second);
                step.push(res + 1);
                check[c] = 1;
            }
        }
    }

    cout << res;
    system("Pause");
    return 0;
}


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

int main(){
   long long a,b,c;
   while (1){
   cin>>a>>b>>c;

   if ((b+c)%2)
      cout<<(2*a+b-1)*b<<endl;
   else cout<<(2*a+b-1)*b-(a+b-1)<<endl;
}
   return 0;
}


#include<iostream>
#include<set>
#include<algorithm>
using namespace std;
int main(){
	int x,y;
	set <int> a,b;
	set< pair<int, int>> c;
	for(int i=0;i<8;i++){
		cin>>x>>y;
		a.insert(x);
		b.insert(y);
		c.insert(make_pair(x,y));
}
	/*x=*++a.begin();
	y=*++b.begin();*/
	if(a.size==3 && b.size==3 && c.size==8)
		cout<< "respectable";
	else cout<<"ugly";
	return 0;
}


#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<stack>
#include<map>
#include<queue>
#define ll long long
using namespace std;
int m,b;
int a[10005][10005];
ll work(int x,int y)
{
    ll sum=0;
    for(int i=0;i<=x;i++)
        for(int j=0;j<=y;j++)
            sum+=a[i][j];
    return sum;
}
int main()
{
    while(scanf("%d%d",&m,&b)!=EOF)
    {
        for(int i=0;i<=b;i++)
            for(int j=0;j<=m*b;j++)
                a[i][j]=i+j;
        //ll sum=0;
        ll res=0;
        for(int i=0;i<=b;i++)
          res=max(res,work(i,m*(b-i)));
          cout<<res<<endl;

    }
    return 0;
}


#include <bits/stdc++.h>

typedef long long int lli;

using namespace std;

//#define pi 3.141592653589793238
typedef pair<lli,lli> pll;
typedef map<lli,lli> mll;
typedef set<lli> sl;
typedef map<int,int> mii;
typedef set<int> si;
typedef pair<double,double> pdd;
typedef map<double,lli> mdl;
typedef set<double> sd;
#define x first
#define y second
#define mp make_pair
#define pb push_back
const lli mod = 1e9 + 7;

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

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

vector<lli> getprimes()
{
    vector <lli> pl(101,1);
    for(int i = 2; i<=100; i++)
    {
        if(pl[i] == 1)
        {
            for(int j = 2*i; j<=100; j+=i)
            {
                pl[j] = 0;
            }
        }
    }
    return pl;
}

lli primefactorise(int n)
{
    if(n == 1)
    {
        return 1;
    }
    lli ans = n;
    while (n%2 == 0)
    {
        n = n/2;
        if(n != 1)
        {
            ans += n;
        }
    }

    for (int i = 3; i <= sqrt(n); i = i+2)
    {
        while (n%i == 0)
        {
            n = n/i;
            if(n != 1)
            {
                ans += n;
            }
        }
    }
    ans += 1;
    return ans;
}

lli power(lli a,lli b)
{
    lli ans = 1;
    while(b > 0)
    {
        if(b%2 == 1)
        {
            ans *= a;
            ans = ans%mod;
        }
        b/=2;
        a*=a;
        a = a%mod;
    }
    return ans%mod;
}

vector<lli> getbinary(lli x)
{
    vector <lli> bin(8,0);
    lli iter = 0;
    while(x > 0)
    {
        if(x%2 == 0)
        {
            bin[iter] = 0;
        }
        else
        {
            bin[iter] = 1;
        }
        x/=2;
        iter++;
    }
    return bin;
}

lli dist(pll a, pll b)
{
    return (b.x-a.x)*(b.x-a.x) + (b.y-a.y)*(b.y - a.y);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(20);
    string l,r;
    cin >> l >> r;
    lli p = power(10,r.size()-1);
    lli num = 0,ans = -1,numl = 0;
    for(int i = 0; i<r.size(); i++)
    {
        num += (r[i]-'0')*p;
        p/=10;
    }
    p = power(10,l.size()-1);
    for(int i = 0; i<l.size(); i++)
    {
        numl += (l[i]-'0')*p;
        p/=10;
    }
    p = power(10,r.size()-1);
    lli temp;
    for(int i = max(p,numl); i<=num; i++)
    {
        temp = 1;
        lli num2 = 0;
        lli num1 = i;
        while(num1 > 0)
        {
            num2 +=  (9 - (num1%10))*temp;
            num1/=10;
            temp*=10;
        }
        if(i*num2 > ans)
        {
            ans = i*num2;
        }
    }
    cout << ans << endl;
}


#include <bits/stdc++.h>

#define ull long long
#define ld long double
#define sz size()
#define aull(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
#define uull unsigned long long

using namespace std;

ull norm_ceil(ull n) {
	return n / 4 + (ull)(n % 4 != 0);
}

int main()  {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ull n;
	cin >> n;
	char c;
	cin >> c;
	ull ans = 0;
	if (n % 2 == 0) {
		ld t = (ld)(n);
		ull k = (max(0, (ull)(norm_ceil(t)) - 1) * 2 + 1);

		ans += k*6 + (k / 2)*4 + 1;
	} else {
		ld t = (ld)(n);
		ull k = (max(0, (ull)(norm_ceil(t)) - 1) * 2);
		ans += k*6 + (k / 2)*4;
	}

	if (c == 'f') {
		ans += 1;
	} else if (c == 'e')
		ans += 2;
	else if (c == 'd')
		ans += 3;
	else if (c == 'a')
		ans += 4;
	else if (c == 'b')
		ans += 5;
	else if (c == 'c')
		ans += 6;
	cout << ans << "\n";
	return 0;
}


#include<bits/stdc++.h>
int main(){
    string str;
    cin>>str;
    int n=str.length();
    string tmp=str+str;
    for(int i=1;i<=n;i++){
        string sub=tmp.substr(i,str.size());
        if(sub==str)
        cout<<i;
    }
    cout<<n;

}


#include<iostream>
#include<string>

using namespace std;
int main()
{
    string s;
    cin>>s;
    string r=s;

    int n=s.size();
    int count = 0;
    char tmp[n];
    while(1){
        tmp[0]=s[n-1];
        for(int j=1;j<n;j++){
            tmp[j]=s[j-1];
        }
       s=tmp;
       //cout<<s;
       if(s==r) break;
       else count++;
   }
   cout<<++count<<endl;

    //for(int i=0;i<n;i++) cout<<tmp[i];
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <ctime>
#include <cstdlib>
#define pb push_back
typedef long long unsigned int llu;
typedef long long ll;
using namespace std;
const int N=2e5;

int n,a,ans;

int main(){
    scanf("%d",&n);
    if(n==1){printf("Yes\n");return 0;}
    if(n%2)
        for(int i=0;i<n;i++){
            scanf("%d",&a);
            if(i==0||i==n-1){
                if(a%2)ans++;
            }
        }
    if(ans==2)printf("Yes\n");
    else printf("No\n");
return 0;}


#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define ll long long
#define ld long double
 #define MOD (ll)(pow(10,9)+7)

ll fact(ll n){
    if(n==1) return 1;
    return (n*fact(n-1))%MOD;
}

ll binsearch(ll n,ll x,ll pos,ll l,ll r){
     ll count=1;
     ll small=x-1;
    ll big=n-x;
    while(l<r){
    ll mid=(l+r)/2;
    if(mid>pos){
        count=(count*big)%MOD;
        big--;
        r=mid;
    }else if(mid<pos){
        count=(count*small)%MOD;
        small--;
        l=mid+1;
    }else break;
    }
    count=(count*fact(big+small))%MOD;
    return count;
}

int main() {

      ll n,x,pos;
      cin>>n>>x>>pos;
      ll count=binsearch(n,x,pos,0,n);
      cout<<count%(MOD);

}


#include <bits/stdc++.h>
using namespace std;
map <char, int> mp;
int main()
{
    int i, j, k, n, m, t, p, cas=1;
    char arr[101];
    while(scanf("%s", arr))
    {
        m=0;
        p=strlen(arr);
        for( i=0; i<p; i++)
        {
            mp[arr[i]]++;
        }
        for( i=0; i<p; i++)
        {
            if(mp[arr[i]]>=1)
            {
                m++;
                mp[arr[i]]=0;
            }
        }
        printf("%d\n", m);
        for( i=0; i<p; i++)
        {
            mp[arr[i]]=0;
        }
    }
    return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int a[1000],b[1000],j,i,n,m,r,min,max,k;
	cin >> n >> m >> r;
	for(i=0;i<n;i++)
	{
		cin >> a[i];
	}
	for(i=0;i<m;i++)
	{
		cin >> b[i];
	}
	min =a[0];
	for(i=0;i<n;i++)
	{
		if (min > a[i])
		{
			min =a[i];
		}
		else
         {
		min =min;
	     }
	}
	k=r/min;
	max=b[0];
	for(i=0;i<m;i++)
	{
		if (max < b[i])
		{
			max =b[i];
		}
		else
         {
	    	max =max;
	     }
	 }

	 	j=max*k-k*min+ r ;
	 	if (j>0)
	 	{
	 	  cout <<j;
	    }
	    else
	    {
	      cout <<r;
	     }

		 }


#include <bits/stdc++.h>

using namespace std;

int a[30];
bitset<1000000010> b;
int n;
int cont;

void backtrack(int u) {
		for(int i = a[u]; i > 0; i--) {
	 		if(!b[i]) {
	 			cont += i;
				b[i] = 1;
				if(u == n-1) {
					return;
				}
				break;
			}
		}
		backtrack(u+1);

}

int main() {
	scanf("%d", &n);
	for(int i = 0; i < n; i++) scanf("%d", &a[i]);
	cont = 0;
	backtrack(0);
	printf("%d\n", cont);

}
// 1475066889484


#include <iostream>
#include <vector>
using namespace std;
vector<int> V1;
vector<int> V2;

int start(int a, int n){
    int i=2,m=n;
    while (m<a) {
        m=n*i;
        ++i;
    }
    return m;
}

int main () {
    int x,y,a,b,n,m,cpt=0;
    cin>>x>>y>>a>>b;
    n=start(a,x);
    //m=start(a,y);
    int i=0;
    while ((n+x*i)<=b) {
        V1.push_back(n+x*i);
        ++i;
    }
    /*i=0;
    while ((m+y*i)<=b) {
        V2.push_back(m+y*i);
        ++i;
    }*/
    for (int j=0; j<V1.size();++j) {
        //cout <<V1[j]<<" / "<<y<<" = "<<V1[j]/y<<endl;
        if (V1[j]%y==0) cpt++;
    }
    cout<<cpt<<endl;
    return 0;
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;
vector<int>v;
int main()
{
    long long n;
    int k;
    cin>>n>>k;
    if (k>=n)
    {
        cout<<"1";
        return 0;
    }

    for (int i=0 ; i<k-1 ; i++)
    {
        if (i!=0)
        {
             v.push_back((v[i-1]-1)+(i+2));
        }
        else if (i==0)
        {
            v.push_back(2);
        }
    }
    /*for (int i=0 ; i<k-1 ; i++)
    {
        cout<<my_arr[i]<<" ";
    }*/

   bool found=0;
   int l=0 , h=k-2 ,m;
   while (l<=h)
   {
       m=(l+h)/2;
       if (v[m]==n)
       {
           found=1;
           cout<<m+1;
           break;
       }
       else if (v[m]<n)
       {
           l=m+1;
       }
       else if (v[m]>n)
       {
           h=m-1;
       }
   }
  if (found ==0 && v[h]>=n)
  {
      cout<<h+1;
  }
  else if (found==0 && v[h]<n )
  {
      cout<<"-1";
  }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define MOD 1000000007
#define endl '\n'

int n, ans = 0;
vector<int> adj[10];

void solve(int a, int label[10])
{
	for(int i=0; i<10; i++)
		cerr << label[i] << endl;
	int temp = 0;
	if( a == n + 1 )
	{
		int done[n+1][n+1] = {};
		for(int i=1; i<=n; i++)
		{
			if( !label[i] )
				continue;
			for( int j : adj[i] )
			{
				if( !label[j] || done[ label[i] ][ label[j] ] )
					continue;
				done[ label[i] ][ label[j] ] = true;
				done[ label[j] ][ label[i] ] = true;
				temp++;
			}
		}
		ans = max( ans , temp );
		return;
	}
	for(int i=0; i<=6; i++)
	{
		label[a] = i;
//		cout << "Hello";
		solve( a + 1 , label );
	}
}

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

	int m, a, b;
	cin >> n >> m;
	for(int i=0; i<m; i++)
	{
		cin >> a >> b;
		adj[a].pb(b);
		adj[b].pb(a);
	}
	int label[10] = {};
	solve(1, label);
	cout << ans;
	return 0;
}


//============================================================================
// File        : main.cpp
// Author      : AHMED HANI IBRAHIM
// Copyright   : AHani
// Version     :
// Created on February 5, 2013, 7:44 AM
//============================================================================

#include <cstdlib>
#include <stdio.h>
#include <string.h>
#include <string>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#define Max 200 + 5
#define INF 1000000000
//#define INT_MAX 2147483647
#define FOR(i, N) for( int i = 0 ; i < N ; i++ )
#define FOR1e(i, N) for( int i = 1 ; i <= N ; i++ )
#define FORe(i, N) for(int i = 0 ; i <= N ; i++ )
#define FOR1(i, N) for(int i = 1 ; i < N ; i++ )
#define BLUE 1
#define RED 2
using namespace std;

int N, T;
int Memo[50][50][50][50][50];

int solve(int pos, int last1, int last2, int count1, int count2) {
    if (pos == N) {
        if (count1 == T && count2 == T-1)
            return 1;
        return 0;
    }
    if (count1 > T)
        return 0;
    if (count2 > T - 1)
        return 0;
    int &ret = Memo[pos][last1][last2][count1][count2];
    if (ret < 0) {
        ret = 0;
        FOR(next, 4) if (next != last2) {
            if (last1 == 4 || last2 == 4) {
                ret += solve(pos + 1, last2, next, count1, count2);
            } else {
                int ncount1 = count1;
                int ncount2 = count2;
                if (last1 < last2 && last2 > next)
                    ++ncount1;
                if (last1 > last2 && last2 < next)
                    ++ncount2;
                ret += solve(pos+1, last2, next, ncount1, ncount2);
            }
        }
    }
    return ret;
}

int main(int argc, char** argv) {
      // freopen("Trojan.txt", "r", stdin);
    scanf("%d %d", &N, &T);
    memset(Memo, -1, sizeof(Memo));
    cout << solve(0, 4, 4, 0, 0) << endl;

    return 0;
}


#include <iostream>
#include<cstdio>
using namespace std;
int y[1000];
int main() {
    int x ;
    bool u;
    scanf("%d",&x);
    int cur=0;
    int y[x];
    for(int i=0;i<x;i++){
        scanf("%d",&y[i]);
        if(y[i]==1)cur++;
if(y[i]==0)u=true;

    }
    //printf("%d %d hi\n",x,y[0]);
    int gain=0;
for(int i=0;i<x;i++){

    for(int j=0;j<x;j++){
        int temp=0;
        for(int k=i;k<=j;k++){if(y[k]==1)temp--;else temp++;}
        gain=max(gain,temp);
    }

}
if(!u)printf("%d\n",x-1);
else
printf("%d\n",gain+cur);
}


#include <stdio.h>
int main()
{
    int a,b,c,sum;
    int g,e,f;
    while(scanf("%d%d%d",&a,&b,&c)!=0)
    {//�����N�Ĥ@���ܦ��y�I
        g=a-1;//�Ĥ@���ܦ��y�I�ݭn�h�ּh
        e=b+g;//�t���䪺���ҼW�[
        f=c+g;
        //�ܦ�����|��Ϋ�,�i�H�����Ω�����
        //�����ܦ��y�I������,����[ �W���[�U�� ]���H�� ���H�G
        //���@�����ܦ��y�I,�ҥH�������q�n�A���H�G
        sum=e*f-((1+g)*g/2)*2;
        //printf("a=%d b=%d c=%d sum=%d\n",a,b,c,sum);
        printf("%d\n",sum);
    }
    return 0;
}


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

using namespace std;

int main(int argc, char* argv[]) {
    int n, m, k;
    std::cin >> n >> m >> k;
    cin.get();
    vector < vector< vector<int> > > mas(n, vector<vector<int> >(m, vector<int>(3)));

    for (int i = 0; i < n; ++i) {
        cin >> string();
        for (int j = 0; j < m; ++j) {
            cin >> mas[i][j][0] >> mas[i][j][1] >> mas[i][j][2];
        }
    }

    int ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            priority_queue< pair<int, int> > pq;
            for (int g = 0; g < m; ++g) {
                pq.push(make_pair<int, int>(-mas[i][g][0] + mas[j][g][1], g));
            }
            int _k = k;
            int _ans = 0;
            while (_k > 0 && !pq.empty() && pq.top().first > 0) {
                int thing = pq.top().second;
                int amount = min(mas[i][thing][2], _k);
                int delta = pq.top().first * amount;
                _k -= amount;
                _ans += delta;
                pq.pop();
            }
            if (_ans > ans) ans = _ans;
        }
    }
    cout << ans;
}


#include <iostream>
#include <vector>
using namespace std;
struct prod{
    int a,b,c;
    int type;
};
vector<prod> planets[10], tmp;
int n,m,k, tpb;
string pla[10];
bool cmp(prod a, prod b){
    return (planets[tpb][a.type].b-a.a>planets[tpb][b.type].b-b.a);
}
int getMax(int pa, int pb){
    tpb = pb;
    tmp = planets[pa];
    sort(tmp.begin(), tmp.end(), cmp);
    int g = 0, fill = 0;
    for (int i = 0; i < m && k-fill; i++)
        if (k-fill>=tmp[i].c)
            fill+=tmp[i].c, g+=(planets[pb][tmp[i].type].b-tmp[i].a)*tmp[i].c;//, cout<<"\tADD full "<<tmp[i].type<<" g:->"<<g<<endl;
        else
            g+=(planets[pb][tmp[i].type].b-tmp[i].a)*(k-fill), fill=k;//, cout<<"\tADD "<<(k-fill)<<" "<<tmp[i].type<<" g:->"<<g<<endl;
    return g;
}
int main(){
    cin>>n>>m>>k;
    string name;
    for (int i = 0; i < n; i++){
        cin>>pla[i], planets[i].resize(m);
        for (int j = 0; j < m; j++)
            cin>>planets[i][j].a>>planets[i][j].b>>planets[i][j].c, planets[i][j].type = j;
    }
    int MAX = 0;
    for (int pa = 0; pa < n; pa++)
        for (int pb = 0; pb < n; pb++)
            if (pa!=pb)
                MAX = max(MAX,getMax(pa,pb));
    cout<<MAX<<endl;
    //system("PAUSE");
    return 0;
}


#include<stdio.h>
#include<string>
#include<iostream>
using namespace std;
struct plant
{
    string name;
    int oou[105],in[105],rem[105];
}p[105];
struct node
{
    int pro;
    int index;
}no[105];
int cmp(node a,node b)
{
    return a.pro>b.pro;
}
int main()
{
    int n,i,j,m,k,ans,q,aa;
    scanf("%d%d%d",&n,&m,&aa);
    for(i=0;i<n;i++)
    {
        cin>>p[i].name;
        for(j=0;j<m;j++)
        {
            cin>>p[i].oou[j]>>p[i].in[j]>>p[i].rem[j];
        }
    }
    ans=0;
    int temp=0;
    for(i=0;i<n;i++)//i in,j out
    {
        for(j=0;j<n;j++)
        {
            if(i==j)continue;
            temp=0;
            q=aa;
            for(k=0;k<m;k++)
            {
                no[k].pro=p[j].in[k]-p[i].oou[k];
                no[k].index=k;
            }
            sort(no,no+m,cmp);
            for(k=0;k<m;k++)
            {
                if(no[k].pro<=0)break;
                int t=p[i].rem[no[k].index];
                temp+=no[k].pro*min(t,q);
                if(t>=q)break;
                else q-=t;
            }
            if(temp>ans)ans=temp;
        }
    }printf("%d\n",ans);
    return 0;
}


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

typedef long long i64;

vector<i64> getDivs(i64 N) {
    vector<i64> ret;
    for (int i = 1; (i64) i * i <= N; ++i) {
        if (N % i == 0) {
            ret.push_back(i);
            if ((i64) i * i < N) ret.push_back(N / i);
        }
    }
    sort(ret.begin(), ret.end());
    return ret;
}

map<i64, vector<i64>> powers;

bool goodDiv(i64 x) {
    if (x <= 2) return false;
    x--;
    for (int i = 2; (i64) i * i <= x; ++i) {
        if (x % i == 0) {
            while (x % i == 0) x /= i;
            if (x != 1) return false;
            powers[i].push_back(x);
        }
    }
    if (x > 1) powers[x].push_back(x);
    return true;
}

i64 getAns(const vector<i64>& divs) {
    int N = divs.size();
    vector<i64> dp(N, 0);
    dp[0] = 1;
    i64 maxv = divs.back();

    vector<bool> good(N, 0);
    for (int i = 0; i < N; ++i) {
        good[i] = goodDiv(divs[i]);
    }

    for (const vector<i64>& curr: powers) {
        vector<i64> ndp = dp;
        for (i64 p: curr) {
            ++p;
            for (int j = N - 1; j >= 0; --j) {
                if (divs[j] > maxv / p) continue;
                i64 dv = divs[j] * p;
                int pos = lower_bound(divs.begin(), divs.end(), dv) - divs.begin();
                if (pos >= N || divs[pos] != dv) continue;
                dp[pos] += dp[j];
            }
        }
        dp = ndp;
    }
    return dp[N - 1];
}

int main() {
    #ifndef ONLINE_JUDGE
    freopen("task.in", "r", stdin);
    freopen("task.out", "w", stdout);
    #endif // ONLINE_JUDGE
    ios::sync_with_stdio(false);

    i64 N;
    cin >> N;

    vector<i64> divs = getDivs(N);
    i64 ans = getAns(divs);
    cout << ans << '\n';
}


#include <iostream>
#include <map>
#include <set>
#include <vector>

typedef long long Long;
template <typename K, typename V>
using Map = std::map <K, V>;

const Long N  = 1000000;
const Long N2 = N * N;

#define ALL(v) (v).begin(), (v).end()

std::vector <Long> get_divisors(Long n)
{
    std::vector <Long> divisors;
    for (Long d = 1; d * d <= n; ++ d) {
        if (n % d == 0) {
            divisors.push_back(d);
            if (d * d != n) {
                divisors.push_back(n / d);
            }
        }
    }
    std::sort(ALL(divisors));
    return divisors;
}

std::set <Long> prime_powers;

bool is_prime_power(Long n)
{
    if (n <= 1) {
        return false;
    }
    if (prime_powers.count(n)) {
        return true;
    }
    for (Long d = 2; d * d <= n; ++ d) {
        if (n % d == 0) {
            return false;
        }
    }
    return true;
}

int main()
{
    std::vector <bool> prime(N + 1, true);
    for (int p = 2; p <= N; ++ p) {
        if (prime[p]) {
            for (Long pp = p; pp <= N2; pp *= p) {
                prime_powers.insert(pp);
            }
            if ((long long)p * p <= N) {
                for (int i = p * p; i <= N; i += p) {
                    prime[i] = false;
                }
            }
        }
    }
    Long a;
    std::cin >> a;
    const auto &divisors = get_divisors(a);
    Map <Long, Long> ways;
    ways[a] = 1;
    for (Long d : divisors) {
        if (is_prime_power(d - 1)) {
            Map <Long, Long> new_ways;
            for (const auto &iterator : ways) {
                new_ways[iterator.first] += iterator.second;
                if (iterator.first % d == 0) {
                    new_ways[iterator.first / d] += iterator.second;
                }
            }
            ways.swap(new_ways);
        }
    }
    std::cout << ways[1] << std::endl;
    return 0;
}


#include <cmath>
#include <map>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <set>
#include <bitset>
#include <memory.h>
#include <functional>
#include <queue>
#include <fstream>
#include <ctime>
#include <deque>
#include <utility>
#include <stack>
#include <sstream>
#include <list>
#include <cctype>
#include <numeric>
#include <iomanip>
#include <assert.h>
using namespace std;
#define sqr(_) ((_)*(_))

typedef long long LL;
typedef long double ld;

typedef pair<int, int> Pii;
typedef pair<LL, LL> Pll;
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()

const int MAXN = (int)1e6 + 10;

int hash[MAXN], pr[MAXN], tot;
vector<LL> a;
vector<Pll> b;
LL A, Tohka;

bool prtest(LL x)
{
	if (x < MAXN) return !hash[x];
	for (int i = 2; (LL)i * i <= x; ++i)
		if (x % i == 0) return 0;
	return 1;
}
LL check(LL w)
{
	for (ld i = 1; pow(2.0, (ld)i) <= w; ++i)
	{
		LL x = (LL)pow((ld)w, (ld)1.0 / i);
		if ((LL)pow((ld)x, i) == w)
			if (prtest(x))
				return x;
		++x;
		if ((LL)pow((ld)x, i) == w)
			if (prtest(x))
				return x;
	}
}
void DFS(LL x, LL lim)
{
	if (x == 1)
	{
		++Tohka;
		return ;
	}
	for (int i = 0; i < SZ(b) && b[i].x <= lim; ++i)
		if (x % b[i].y == 0)
			DFS(x / b[i].y, b[i].x);
}
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
#endif

	hash[1] = 1;
	for (int i = 2; i < MAXN; ++i)
		if (!hash[i])
		{
			pr[++tot] = i;
			for (int j = i + i; j < MAXN; j += i)
				hash[j] = 1;
		}
	cin >> A;
	for (int i = 1; (LL)i * i <= A; ++i)
		if (A % i == 0)
		{
			a.pb(i);
			if ((LL)i * i != A)
				a.pb(A / i);
		}
	for (int i = 0; i < SZ(a); ++i)
		if (a[i] != 1)
		{
			LL p = check(a[i] - 1);
			if (p != -1)
				b.pb(mp(p, a[i]));
		}
	sort(ALL(b));
	DFS(A, A);
	cout << Tohka << endl;

	fclose(stdin);
	fclose(stdout);
	return 0;
}


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

long long dp[5000][5000];

int main()
{
    long long n,m,c0,d0,a,b,c,d,j=1,ans,max=0;
    cin >> n >> m >> c0 >> d0;
    long long val[1001]={},val2[1001]={},cost[1001]={};
    for (int i=1; i<=m; i++)
    {
        cin >> a >> b >> c >> d;
        while(a>=b)
        {
            a-=b;
            val[j]=b , val2[j]=c , cost[j]=d;
            j++;
        }
    }

    for (int i=1; i<j; i++)
    {
        for (int k=1; k<=n; k++)
        {
            dp[i][k] = dp[i-1][k];
            if (k>=val2[i]) dp[i][k] = max(dp[i][k] , dp[i-1][k-val2[i]]+cost[i]);
        }
    }

    for (int i=0; i<=n; i++)
    {
        ans = dp[j-1][i] + ((n-i)/c0)*d0;
        if (ans>max) max=ans;
    }
    cout << max << "\n";

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
vector<int> v;
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        int h;
        cin>>h;
        v.push_back(h);
    }
    sort(v.begin(),v.end());
    for(int i=0;i<n;i++)
    {
        if(v[i]==v[i+1])
        {
            v.erase(v.begin()+i);
            i=-1;
        }
        else if(v[i]==v[i+1]-1&&v[i+1]==v[i+2]-1)
        {
            cout<<"YES";
            return 0;
        }
    }
    cout<<"NO";
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <utility>
#include <map>
#include <set>
#include <tuple>
#include <array>
#include <numeric>
#include <bitset>
#define _USE_MATH_DEFINES
#include <math.h>
#include <queue>
#include <cstring>

#define pb push_back

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

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

	cout << (n % 2 ? "black" : "white") << endl;
}


/* @author : mostafa
 * created : 2018-06-18 19:07
 */
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std ;
#define debug(x) cerr<<#x<<" is "<<x<<"\n"
#define SIZE (int)1e9+9

bool arr[SIZE] ;

int main()
{
    cin.sync_with_stdio(false) ;
    cin.tie(0) ;
    int l , r , x , y ;
	cin >> l >> r >> x >> y ;
	int ans = 0 ;
	memset( arr , false , sizeof arr );
	for(int a = l ; a <= r ; a++){
		if( (x*y) % a == 0 && !arr[a] ){
			int b = x * y / a ;

			if( __gcd(a,b) == x && b >= l && b <= r ){
				ans += 2 ;
				if( b <= SIZE )
					arr[b] = true ;
			}
		}
	}
	cout << ans << "\n" ;
    return 0 ;
}


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

int main() {
	int n, m, c, d;
	cin >> n >> m >> cost >> sell;
	int a[n], b[n], c[n], d[n];
	for(int i = 0; i < m; i++){
	    cin >> a[i] >> b[i] >> c[i] >> d[i];
	}
	int dp[n+1][m+1];
	memset(dp, 0, sizeof dp);
	int ans = 0;
	for(int i = 1; i <= n; i++){
	    for(int j = 0; j < m; j++){
	        for(int k = 0; k <= a[j]/b[j]; k++){
	            dp[i][j] = max(dp[i][j], dp[i-k*c[j]] + k*d[j]);
	            ans = max(ans, dp[i][j] + (n-i)/cost *sell);
	        }
	    }
	}
	cout << ans;
	return 0;
}


#define DBG 1
// chrono::system_clock::now().time_since_epoch().count()
#include<bits/stdc++.h>
//#include<ext/pb_ds/tree_policy.hpp>
//#include<ext/pb_ds/assoc_container.hpp>

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define debug(x) if (BDG) cerr << #x << " = " << x << endl;

using namespace std;
//using namespace __gnu_pbds;

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

//template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int MOD = (int)1e9 + 7;
const int MAXN = (int)1e6 + 5;

int rev[MAXN], fact[MAXN];
int dp[MAXN];
int n, k, ans;

int addMod(int a, int b, int m = MOD) {
    a += b;

    if (m <= a) {
        a -= m;
    }

    return a;
}

int mulMod(int a, int b, int m = MOD) {
    return a * 1ll * b % m;
}

int binPow(int a, int b, int m = MOD) {
    int ret = 1;

    while (b > 0) {
        if (b & 1) {
            ret = mulMod(ret, a, m);
        }

        a = mulMod(a, a, m);
        b >>= 1;
    }

    return ret;
}

void pre() {
    fact[0] = rev[0] = 1;

    for (int i = 1; i < MAXN; ++i) {
        fact[i] = mulMod(fact[i - 1], i);
    }

    rev[MAXN - 1] = binPow(fact[MAXN - 1], MOD - 2);

    for (int i = MAXN - 1; i > 0; --i) {
        rev[i - 1] = mulMod(rev[i], i);
    }
}

int C(int n, int k) {
    if (k < 0 || k > n || n < 0) {
        return 0;
    }

    return mulMod(fact[n], mulMod(rev[k], rev[n - k]));
}

int A(int n, int k) {
    if (k < 0 || k > n || n < 0) {
        return 0;
    }

    return mulMod(fact[n], rev[n - k]);
}

void solve() {
    scanf("%d %d", &n, &k);

    for (int i = k + 1; i <= n; ++i) {
        dp[i] = mulMod(i - k - 1, fact[i - 2]);

        for (int j = i - k; j <= i - 1; ++j) {
            dp[i] = addMod(dp[i], mulMod(dp[j], A(i - 2, i - j - 1)));
        }
    }

    for (int i = 1; i <= n; ++i) {
        int cur = mulMod(dp[i], C(n - 1, i - 1));
        cur = mulMod(cur, fact[n - i]);
        ans = addMod(ans, cur);
    }

    printf("%d\n", ans);
}

int main() {
	int tt = 1;
    pre();

	while (tt--) {
		solve();
	}

	return 0;
}