#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <climits>
using namespace std;

#define MOD 1000000007
#define PI 3.14159265358979323846264338327950288419

#define int long long
#define ll long long
#define pint pair<ll, ll>
#define pll pair<ll, ll>
#define pb push_back
#define mpair make_pair
#define pm(first, second) pb(mpair(first, second))
#define pff first.first
#define pfs first.second
#define psf second.first
#define pss second.second

#define all(X) (X).begin(), (X).end()
#define rall(X) (X).rbegin(), (X).rend()
#define divceil(a, b) (((a) + ((b) - 1)) / (b))
#define outyn(flag) cout << ((flag)? "Yes": "No") << endl
#define outYN(flag) cout << ((flag)? "YES": "NO") << endl
#define out(output) cout << (output) << endl

//pは素数,aのb乗をpで割った余り
ll powsur(ll a, ll b, ll p) {
	if (b == 0) {
		return 1;
	}
	else if (b%2 == 0) {
		ll d = powsur(a, b / 2, p);
		return ((d%p) * (d%p))%p;
	}
	else {
		return ((a%p) * (powsur(a, b - 1, p)%p))%p;
	}
}

void solve(){

    int N, P;
    cin >> N >> P;
    ll ans = (P - 1) * powsur(P - 2, N - 1, MOD);
    ans %= MOD;
    out(ans);

}

#undef int
int main(){

    solve();

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mkp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define M1 1000000007
#define M2 998244353

#define fl(i,a,b)  for(ll i=a;i<b;i++)
#define bfl(i,a,b) for(ll i=b-1;i>=a;i--)
#define f(i,n)     for(int i=0;i<n;i++)
#define bf(i,n)    for(int i=n-1;i>=0;i--)
#define f1(i,n)    for(int i=1;i<=n;i++)
#define bf1(i,n)   for(int i=n;i>=1;i--)

#define all(v)      v.begin(),v.end()
#define pll         pair<long,long>
#define pii         pair<int,int>
#define vi          vector<int>
#define vll          vector<ll>

#define p0(a)       cout << a << " "
#define p1(a)       cout << a << bn
#define p2(a, b)    cout << a << " " << b << bn
#define p3(a, b, c) cout << a << " " << b << " " << c << bn
#define p4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << bn
#define debug(x)    cerr << #x << " = " << x << endl;

#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)

#define bn          "\n"
#define pbn         cout<<"\n"

#define TRACE
#ifdef TRACE
    #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cerr << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ',');
        cerr.write(names, comma - names) << " : " << arg1<<" | ";
        __f(comma+1, args...);
    }
#else
    #define trace(...) 1
#endif

ll modI(ll a,ll m);
ll gcd(ll a,ll b);
ll powM(ll x,ll y,ll m);

void py(int ok)
{
    if(ok==1){
        cout<<"YES"<<bn;
    }else{
        cout<<"NO"<<bn;
    }
}

void swap(ll& a,ll& b)
{
    ll tp=a;
    a=b;
    b=tp;
}

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

ll lcm(ll x, ll y)
{
    if(x==0 || y==0){
        cout<<"Not valid lcm"<<bn;
    }

    ll LCM= x/gcd(x,y);
    LCM=LCM*y;

    return LCM;
}

ll powM(ll x,ll y,ll m)
{
    ll ans=1,r=1;
    x%=m;
    while(r>0&&r<=y)
    {
        if(r&y)
        {
            ans*=x;
            ans%=m;
        }
        r<<=1;
        x*=x;
        x%=m;
    }
    return ans;
}

ll modI(ll a, ll m)
{
    ll m0=m,y=0,x=1;
    if(m==1) return 0;
    while(a>1)
    {
        ll q=a/m;
        ll t=m;
        m=a%m;
        a=t;
        t=y;
        y=x-q*y;
        x=t;
    }
    if(x<0) x+=m0;
    return x;
}

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

int main()
{

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
	int tt=1;
    // cin>>tt;
   f1(testcase_no,tt)
   {
       //   cout<<"test case no. "<<testcase_no<<bn;

      double a,b;
      cin>>a>>b;

      double ans=a*(b/100);
      p1(ans);

        // cout << fixed << setprecision(25);

   }

	return 0;
}


#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

const int maxN = 5e3; int n, m, k;
char mat[maxN][maxN + 1];

const lli mod = 998244353;

lli base;
lli solve1(int i = 0, int j = 0)
{
  if (i >= n || j >= m) return 0;
  if (i == n - 1 && j == m - 1) return 1;

  lli ans = 0;
  if (mat[i][j] == 'R')
    ans = (ans + solve1(i, j + 1)) % mod;
  else if (mat[i][j] == 'D')
    ans = (ans + solve1(i + 1, j)) % mod;
  else if (mat[i][j] == 'X')
    ans = (ans + solve1(i, j + 1) + solve1(i + 1, j)) % mod;
  else
    ans = 0;

  return ans;
}
lli memo[maxN][maxN];
lli modPow(lli x, lli y)
{
  lli ans = 1;
  while (y)
  {
    if (y & 1LL) ans = ans * x % mod;
    x = x * x % mod, y >>= 1LL;
  }
  return ans;
}
lli inv(lli x)
{
  return modPow(x, mod - 2);
}
lli pot[maxN*maxN + 1];
lli inv3;
lli solve2(int i = 0, int j = 0, int unknown = 0)
{
  if (i >= n || j >= m) return 0;
  if (i == n - 1 && j == m - 1) return pot[(n*m - k) - 0];
  lli &ans = memo[i][j];
  if (ans != -1) return ans;

  ans = 0;
  if (mat[i][j] == 'R')
    ans = solve2(i, j + 1, unknown);
  else if (mat[i][j] == 'D')
    ans = solve2(i + 1, j, unknown);
  else if (mat[i][j] == 'X')
  {
    ans = (solve2(i, j + 1, unknown) + solve2(i + 1, j, unknown)) % mod;
  }
  else
  {
    lli a = 2LL * solve2(i, j + 1, unknown + 1) % mod;
    lli b = 2LL * solve2(i + 1, j, unknown + 1) % mod;
    ans = (a + b) * inv3 % mod;
  }
  return ans;
}

int main()
{
  inv3 = inv(3);
  while (~scanf("%d %d %d", &n, &m, &k))
  {
    pot[0] = 1;
    for (int i = 1; i <= n*m; i++)
      pot[i] = 3LL * pot[i - 1] % mod;

    memset(mat, '.', sizeof(mat));
    for (int i = 0; i < n; i++)
      mat[i][n] = '\0';
    for (int kk = 0; kk < k; kk++)
    {
      int i, j; char c; scanf("%d %d %c", &i, &j, &c); i--, j--;
      mat[i][j] = c;
    }

    DEBUG
      for (int i = 0; i < n; i++)
        printf("\t%s\n", mat[i]);

    memset(memo, -1, sizeof(memo));
    lli ans = solve2();
    printf("%lld\n", ans);
  }
  return 0;
}

#include<bits/stdc++.h>
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define pii pair<int,int>
#define fi first
#define se second
#define PB push_back
#define ll long long
#define ull unsigned long long
#define pll pair<ll,ll>
#define y1 orzkcz
using namespace std;
const int mo=998244353;
const int N=5005;
int n,m,K;
char s[N][N];
int f[N][N];
int main(){
	scanf("%d%d%d",&n,&m,&K);
	For(i,1,K){
		int x,y; char v[10];
		scanf("%d%d%s",&x,&y,v+1);
		s[x][y]=v[1];
	}
	f[1][1]=1;
	For(i,1,n) For(j,1,m){
		int v=f[i][j];
		if (!s[i][j]){
			v=1ll*v*(mo+1)/3%mo;
			f[i+1][j]=(f[i+1][j]+2ll*v)%mo;
			f[i][j+1]=(f[i][j+1]+2ll*v)%mo;
		}
		if (s[i][j]=='R'||s[i][j]=='X')
			f[i][j+1]=(f[i][j+1]+v)%mo;
		if (s[i][j]=='D'||s[i][j]=='X')
			f[i+1][j]=(f[i+1][j]+v)%mo;
	}
	int re=f[n][m];
	For(i,1,n*m-K) re=3ll*re%mo;
	cout<<re<<endl;
}


#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
using i64 = int64_t;
using vi64 = vector<i64>;
using vvi64 = vector<vi64>;
using vvvi64 = vector<vvi64>;
using u64 = uint64_t;

#define rep(i, s, n) for (i64 i = (s); i < (n); ++i)

void mul(vvi64& c, const vvi64& a, const vvi64& b) {
  rep(i, 0, 3) {
    rep(j, 0, 3) {
      rep(k, 0, 3) { c[i][j] += a[i][k] * b[k][j]; }
    }
  }
}

const vvi64 m1_of() { return {{0, 1, 0}, {-1, 0, 0}, {0, 0, 1}}; }

const vvi64 m2_of() { return {{0, -1, 0}, {1, 0, 0}, {0, 0, 1}}; }

const vvi64 m3_of(i64 p) { return {{-1, 0, 2 * p}, {0, 1, 0}, {0, 0, 1}}; }

const vvi64 m4_of(i64 p) { return {{1, 0, 0}, {0, -1, 2 * p}, {0, 0, 1}}; }

void run() {
  i64 n;
  cin >> n;
  vi64 xs(n), ys(n);
  rep(i, 0, n) { cin >> xs[i] >> ys[i]; }
  i64 m;
  cin >> m;
  vvvi64 trs(m + 1, vvi64(3, vi64(3, 0)));
  rep(i, 0, 3) { trs[0][i][i] = 1; }
  rep(i, 1, m + 1) {
    i64 op;
    cin >> op;
    if (op == 1) {
      mul(trs[i], m1_of(), trs[i - 1]);
    } else if (op == 2) {
      mul(trs[i], m2_of(), trs[i - 1]);
    } else if (op == 3) {
      i64 p;
      cin >> p;
      mul(trs[i], m3_of(p), trs[i - 1]);
    } else if (op == 4) {
      i64 p;
      cin >> p;
      mul(trs[i], m4_of(p), trs[i - 1]);
    }
  }
  i64 q;
  cin >> q;
  rep(i, 0, q) {
    i64 a, b;
    cin >> a >> b;
    --b;
    i64 x{trs[a][0][0] * xs[b] + trs[a][0][1] * ys[b] + trs[a][0][2] * 1},
        y{trs[a][1][0] * xs[b] + trs[a][1][1] * ys[b] + trs[a][1][2] * 1};
    cout << x << " " << y << endl;
  }
}

int main() {
  cin.tie(nullptr);
  cout.precision(std::numeric_limits<double>::max_digits10);
  run();
  return 0;
}

//Never stop trying
#include "bits/stdc++.h"
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

typedef long long ll;
#define int ll
typedef string str;
typedef long double ld;
typedef pair<int, int> pi;
#define fi first
#define se second
typedef vector<int> vi;
typedef vector<pi> vpi;
#define pb push_back
#define eb emplace_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define endl "\n"
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)

const int MOD = 1e9 + 7; //998244353
const ll INF = 1e18;
const int MX = 2e5 + 10;
const int nx[4] = {0, 0, 1, -1}, ny[4] = {1, -1, 0, 0}; //right left down up

template<class T> using V = vector<T>;
template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
ll cdiv(ll a, ll b) { return a / b + ((a ^ b) > 0 && a % b); } // divide a by b rounded up
//constexpr int log2(int x) { return 31 - __builtin_clz(x); } // floor(log2(x))

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
//mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
ll random(ll a, ll b){
    return a + rng() % (b - a + 1);
}
#ifndef LOCAL
#define cerr if(false) cerr
#endif
#define dbg(x) cerr << #x << " : " << x << endl;
#define dbgs(x,y) cerr << #x << " : " << x << " / " << #y << " : " << y << endl;
#define dbgv(v) cerr << #v << " : " << "[ "; for(auto it : v) cerr << it << ' '; cerr << ']' << endl;
#define here() cerr << "here" << endl;

void IO() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
/////////////////////////ONLY CLEAN CODES ALLOWED/////////////////////////

const int C=1e15;

bool reasonable(int x){
	return x>=-C && x<=C;
}

int32_t main() {
    boost; IO();

    int N; cin>>N;
    vi X(N),Y(N);
    FOR(i,0,N) cin>>X[i]>>Y[i];

    int M; cin>>M;
    vpi vec;
    FOR(i,0,M){
    	int t,p=-1; cin>>t;
    	if(t>=3) cin>>p;
    	vec.eb(t,p);
    }

    int a[M],b[M],v[M],v2[M],c[M],d[M];

    int cur_a=1,cur_b=1,cur_v=0,cur_v2=1,cur_c=0,cur_d=0;
    FOR(i,0,M){
    	int t=vec[i].fi,p=vec[i].se;
    	if(t==2){
    		swap(cur_a,cur_b);
    		swap(cur_v,cur_v2);
    		swap(cur_c,cur_d);
    		cur_a*=-1;
    		cur_c*=-1;
    	}
    	else if(t==1){
    		swap(cur_a,cur_b);
    		swap(cur_v,cur_v2);
    		swap(cur_c,cur_d);
    		cur_b*=-1;
    		cur_d*=-1;
    	}
    	else if(t==3){
    		cur_a*=-1;
    		cur_c*=-1;
    		cur_c+=2*p;
    	}
    	else if(t==4){
    		cur_b*=-1;
    		cur_d*=-1;
    		cur_d+=2*p;
    	}

    	a[i]=cur_a; b[i]=cur_b;
    	v[i]=cur_v; v2[i]=cur_v2;
    	c[i]=cur_c; d[i]=cur_d;

    	/*dbg(cur_a)
    	dbg(cur_v)
    	dbg(cur_c)*/
    }

    int Q; cin>>Q;
    while(Q--){
    	int op,i; cin>>op>>i;
    	op--; i--;
    	if(op<0){
    		cout << X[i] << ' ' << Y[i] << endl;
    		continue;
    	}

    	int x=X[i],y=Y[i];

    	cur_a=a[op];
    	cur_b=b[op];
    	cur_c=c[op];
    	cur_d=d[op];

    	dbgs(cur_a,cur_b)

    	if(v[op]==0){
    		cout << cur_a*x+cur_c << ' ' << cur_b*y+cur_d << endl;
    	}
    	else{
    		cout << y*cur_a+cur_c << ' ' << cur_b*x+cur_d << endl;
    	}

    }

    return 0;
}
//Change your approach


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

#define ll long long
#define ld long double
#define ar array
#define all(c) (c).begin(), (c).end()
#define length(x) (int)(x).size()
#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define R_EP(i, a, b, s) for(int i=(a); (s)>0?i<=(b):i>=(b); i+=(s))
#define R_EP1(e) R_EP(i, 1, e, 1)
#define R_EP2(i, e) R_EP(i, 1, e, 1)
#define R_EP3(i, b, e) R_EP(i, b, e, 1)
#define R_EP4(i, b, e, s) R_EP(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define R_EPC(...) GET5(__VA_ARGS__, R_EP4, R_EP3, R_EP2, R_EP1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto& x: a)
#define REP(...) R_EPC(__VA_ARGS__)(__VA_ARGS__)
template<class TypeInt> void read(TypeInt &x) {
    bool neg=false;
    int c;
    x=0;
    c=getchar();
    if(c=='-') {
        neg=true;
        c=getchar();
    }
    for(; (c>47&&c<58); c=getchar()) {
        x=(x<<1)+(x<<3)+c-48;
    }
    if(neg)
        x*=-1;
}

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

    int a, b, c;
    read(a);
    read(b);
    read(c);
    if(c%2==0)
        a=abs(a), b=abs(b);
    if(a>b)
        cout << ">";
    else if(a<b)
        cout << "<";
    else
        cout << "=";
    cout << "\n";
}

#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
int main(){
    lli a,b,c;
    cin>>a>>b>>c;
    if(c%2==0){
        if(abs(a)>abs(b))
        cout<<">";
        else if(abs(a)==abs(b))
        cout<<"=";
        else if(abs(a)<abs(b))
        cout<<"<";
    }
    else{
        if(a>b)
          cout<<">";
          else if(a==b)
          cout<<"=";
          else if(b>a)
          cout<<"<";
    }
    }


#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define FastIO cin.sync_with_stdio(false), cin.tie(nullptr)
#define pb push_back
#define fs first
#define sc second
#define mkp make_pair
#define endl '\n'

// IO
#define multitest signed __T; cin >> __T; while(__T--)
template<typename T>
void _read(T& t);
template<typename T>
void _read(vector<T>& v);
template<typename T1, typename T2>
void _read(pair<T1, T2>& p);
template<typename T>
void _read(T& t) { cin >> t; }
template<typename T>
void _read(vector<T>& v) { for (unsigned _i = 0; _i < v.size(); _i++)_read(v[_i]); }
template<typename T1, typename T2>
void _read(pair<T1, T2>& p) { _read(p.first); _read(p.second); }
void _masterread() {}
template<typename T, typename... V>
void _masterread(T& t, V& ... v) { _read(t); _masterread(v...); }
#define re(...)_masterread(__VA_ARGS__)

template<typename T>
void _print(T t);
template<typename T>
void _print(vector<T>& v);
template<typename T1, typename T2>
void _print(pair<T1, T2>& p);
template<typename T>
void _print(T t) { cout << t; }
template<typename T>
void _print(vector<T>& v) { for (unsigned _i = 0; _i < v.size(); _i++)_print(v[_i]), cout << (_i == v.size() - 1 ? "" : " "); }
template<typename T1, typename T2>
void _print(pair<T1, T2>& p) { _print(p.first); cout << " "; _print(p.second); }
void _masterprint() { cout << endl; }
template<typename T, typename... V>
void _masterprint(T t, V... v) { _print(t); if (sizeof...(v))cout << " "; _masterprint(v...); }
#define pr(...)_masterprint(__VA_ARGS__)

// DEBUG
// colored output???
template <typename T> // start forward declaration
void _debug(T t);
template<typename T1, typename T2>
void _debug(pair<T1, T2> p);
template<typename T>
void _debug(vector<T>v);
template <typename T> // end forward declaration
void _debug(T t) { cerr << t; }
template<typename T1, typename T2>
void _debug(pair<T1, T2> p) { cerr << "{"; _debug(p.first); cerr << ", "; _debug(p.second); cerr << "}"; }
template<typename T>
void _debug(vector<T>v) { cerr << "("; for (unsigned _i = 0; _i < v.size(); _i++)_debug(v[_i]), cerr << (_i == v.size() - 1 ? "" : ", "); cerr << ")"; }
void _masterdebug() { cerr << "]\n"; }
template<typename T, typename... V>
void _masterdebug(T t, V... v) { _debug(t); if (sizeof...(v))cerr << ", "; _masterdebug(v...); }
#define debug(...) cerr<<"["<<#__VA_ARGS__<<"] = [";_masterdebug(__VA_ARGS__)
#define int long long

void solve() {
	int n, c; re(n, c);
	vector<pair<int, pair<int, int>>> A(n); re(A);
	set<int> els;
	for (int i = 0; i < n; i++)
		els.insert(A[i].fs), els.insert(A[i].sc.fs);
	map<int, int> from, to;
	int idx = 0;
	for (int val : els) {
		to[idx] = val;
		from[val] = idx++;
	}
	//for (auto val : from)
	//	cout << val.fs << ' ' << val.sc << endl;
	for (int i = 0; i < n; i++)
		A[i].fs = from[A[i].fs], A[i].sc.fs = from[A[i].sc.fs];
	//debug(A);
	vector<int> P(idx + 1, 0);
	vector<int> E(idx + 1, 0);
	for (int i = 0; i < n; i++) {
		P[A[i].fs] += A[i].sc.sc;
		P[A[i].sc.fs] -= A[i].sc.sc;
		E[A[i].sc.fs] += A[i].sc.sc;
	}
	//debug(P);
	for (int i = 1; i <= idx; i++)
		P[i] += P[i - 1];
	//debug(P);
	int ans = 0;
	int prev = 0;
	for (int i = 0; i <= idx - 1; i++) {
		int cur = to[i];
		int nxt = to[i + 1];
		ans += min(c, E[i] + P[i]);
		ans += (nxt - cur - 1) * min(c, P[i]);
	}
	pr(ans);
}

signed main() {
	FastIO;
	/*int t;
	cin >> t;
	while (t--)*/
		solve();
}

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

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using ull = uint64_t;

using f32 = double;
using f64 = long double;

using u8 = unsigned char;
using u16 = unsigned short;
using u32 = unsigned int;
using u64 = unsigned long long;

using i16 = signed short;
using i32 = signed int;
using i64 = signed long long;

using vi = vector<int>;
using vb = vector<bool>;
using pii = pair<int, int>;
using vpi = vector<pii>;

using rng = default_random_engine;

template <typename T>
using minpq = priority_queue<T, vector<T>, greater<T>>;

#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define np next_permutation
#define sz(v) int(v.size())
#define all(v) begin(v), end(v)
#define popcnt __builtin_popcount

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

const int INF = 2000069420;
const int M1 = 1'000'000'007;
const int M2 =	 998'244'353;
const int maxn = 1'000'005;
const int maxg = 2'005;
const int maxk = 19;

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <class T> using Tree = tree<T, null_type, less<T>,
	rb_tree_tag, tree_order_statistics_node_update>;

int a[maxn];

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

	ll S = 0, T = 0;
	for (int i = 0; i < n; ++i)
		T += a[i]*ll(i) - S, S += a[i];
	cout << T << '\n';
}

int main() {
	cin.tie(nullptr) ->
	sync_with_stdio(false);

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


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

#define  int               long long int
#define  ld                long double
#define  f(i,j,n)            for(int i = j; i <= n; i++)
#define  r(i,n,j)           for(int i = n; i >= j; i--)
#define  all(container)       container.begin() , container.end()
#define  sz(container)        (int)container.size()
#define  ff                first
#define  ss                second
#define  pii               pair <int , int>
#define  sp(x)              setprecision(x)
#define  mod              1000000007
#define  endl            "\n"
#define  pb              push_back
#define  mp             make_pair
#define  T             int ttt; cin >> ttt; while(ttt--)
#define fast           ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);

int32_t main()
{
    fast
    int n;  cin>>n;
    int a[n+1],b[n+1];
    f(i,1,n)    cin>>a[i];
    f(i,1,n)    cin>>b[i];
    int ans=0,id=0;
    f(i,1,n){
        id=max(id,a[i]);
        ans=max(ans,id*b[i]);
        cout<<ans<<endl;
    }
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=3e5+10;
struct BIT{
	int n,tr[N];
	void init(int _n){
		n=_n;
		memset(tr,0,sizeof tr);
	}
	void add(int x,int v){
		for(int i=x;i<=n;i+=i&-i)
		tr[i]+=v;
	}
	int sum(int x){
		int ans=0;
		for(int i=x;i;i-=i&-i)
		ans+=tr[i];
		return ans;
	}
}tr;
int n,a[N];
ll ans;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		scanf("%d",&a[i]);
		a[i]++;
	}
	tr.init(n+2);
	for(int i=1;i<=n;++i){
		int v=i-1-tr.sum(a[i]);
		ans+=v;
		tr.add(a[i],1);
	}
	for(int i=1;i<=n;++i){
		printf("%lld\n",ans);
		tr.add(a[i],-1);
		int v=tr.sum(a[i]);
		ans-=v;
		v=tr.sum(n+2)-tr.sum(a[i]);
		ans+=v;
		tr.add(a[i],1);
	}
	return 0;
}


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

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

#define ll long long
#define yes cout<<"YES"<<"\n"
#define no cout<<"NO"<<"\n"
using namespace std;

const ll MOD = 1000000007;
const ll mod = 1000000007;
const int Nmax=1000005;

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

    return gcd(b%a,a);
}

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

bool isPrime(ll n){
	for(int i = 2; i <=sqrt(n); i++)
		if(n % i == 0)
			return 0;
	return 1;
}

void binaryRepresentation(int x)
{
    for (int i = 31; i >= 0; i--)
    {
        if (x&(1<<i)) cout << "1";
        else cout << "0";
    }
}

ll combination(ll n,ll r){
    if(r==n || r==0)
    {
        return 1LL;
    }

    return combination(n-1,r-1) + combination(n-1,r);
}

bool isPowerOfTwo(ll n)
{
   if(n==0)
        return false;

   return (ceil(log2(n)) == floor(log2(n)));
}

ll power(ll a,ll b)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a);
		b/=2;
		a=(a*a);
	}
	return ans;
}

ll inverse(ll i)
{
    if(i==1) return 1;
    return (MOD-((MOD/i)*inverse(MOD%i))%MOD+MOD)%MOD;
}

bool cmp(const pair<ll,ll> &a,const pair<ll,ll> &b)
{
    if(a.first==b.first)
        return a.second<b.second;
    return a.first>b.first;
}

string toString(ll a)
{
    ostringstream temp;
    temp << a;
    return temp.str();
}

int main()
{
    //vector<vector<int> >ar(n,vector<int> (m,0));
    //vector<int>::iterator ptr;

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

    ll h,w,x,y;
    cin>>h>>w>>x>>y;
    --x;--y;
    vector<string>ar(h);
    for(ll i=0;i<h;i++)
        cin>>ar[i];
    ll ans=0;
    if(ar[x][y]=='.')
        ans++;
    for(ll i=x;i<=x;i++)
    {
        bool flag=true;
        for(ll j=y+1;j<w;j++)
        {
            if(ar[i][j]=='.')
                ans++;
            else
            {
                flag=false;
                break;
            }
        }
    }

    for(ll i=x;i<=x;i++)
    {
        bool flag=true;
        for(ll j=y-1;j>=0;j--)
        {
            if(ar[i][j]=='.')
                ans++;
            else
            {
                flag=false;
                break;
            }
        }
    }

    for(ll i=y;i<=y;i++)
    {
        bool flag=true;
        for(ll j=x+1;j<h;j++)
        {
            if(ar[j][i]=='.')
                ans++;
            else
            {
                flag=false;
                break;
            }
        }
    }

    for(ll i=y;i<=y;i++)
    {
        bool flag=true;
        for(ll j=x-1;j>=0;j--)
        {
            if(ar[j][i]=='.')
                ans++;
            else
            {
                flag=false;
                break;
            }
        }
    }

    cout<<ans;
    return 0;
}

/**
 *    author:  otera
**/
#include<bits/stdc++.h>
using namespace std;

#define int long long
typedef long long ll;
typedef long double ld;
#define rep(i, n) for(int i = 0; i < n; ++ i)
#define per(i,n) for(int i=n-1;i>=0;i--)
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int inf = 1'000'000'007;
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};

void solve() {
    int h, w; cin >> h >> w;
    vector<vector<char>> a(h, vector<char>(w));
    int sx = -1, sy = -1, gx = -1, gy = -1;
    vector<vector<int>> tpos(26, vector<int>());
    rep(i, h) {
        rep(j, w) {
            cin >> a[i][j];
            if(a[i][j] == 'S') sx = i, sy = j;
            else if(a[i][j] == 'G') gx = i, gy = j;
            else if(a[i][j] != '.' and a[i][j] != '#') {
                int c = a[i][j] - 'a';
                tpos[c].push_back(i * w + j);
            }
        }
    }
    vector<int> dist(h * w + 26, inf);
    dist[sx * w + sy] = 0;
    priority_queue<P, vector<P>, greater<P>> pque;
    pque.push({0, sx * w + sy});
    while(pque.size()) {
        P p = pque.top(); pque.pop();
        int pos = p.sc, di = p.fr;
        if(di > dist[pos]) continue;
        if(pos < h * w) {
            int x = pos / w, y = pos % w;
            rep(k, 4) {
                int nx = x + dx[k], ny = y + dy[k];
                // cerr << nx << " " << ny << "\n";
                if(0 <= nx and nx < h and 0 <= ny and ny < w and a[nx][ny] != '#') {
                    if(chmin(dist[nx * w + ny], di + 1)) {
                        pque.push({di + 1, nx * w + ny});
                    }
                }
            }
            if(a[x][y] != '.' and a[x][y] != 'S' and a[x][y] != 'G') {
                // teleport
                int c = a[x][y] - 'a';
                if(chmin(dist[h * w + c], di)) {
                    pque.push({di, h * w + c});
                }
            }
        } else {
            int c = pos - h * w;
            for(int np: tpos[c]) {
                if(chmin(dist[np], di + 1)) {
                    pque.push({di + 1, np});
                }
            }
        }
    }
    if(dist[gx * w + gy] == inf) dist[gx * w + gy] = -1;
    cout << dist[gx * w + gy] << "\n";
}

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


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pi (3.141592653589)
#define pb push_back
#define mp make_pair
#define INF 1000000000000000000
#define MOD 1000000007
#define vll vector<ll>
#define vpll vector<pair<ll,ll> >
#define pll pair<ll , ll>
#define ff first
#define ss second
#define mMul(a , b , m) (a * b) % m
#define mSub(a , b , m) (a - b + m) % m
#define mAdd(a , b , m) (a + b) % m
ll dp[62][62];
string fun(ll i,ll j,ll k)
{
    if(i==0)
    {
        string s;
        while(j--)
        s.pb('b');
        return s;
    }
    if(j==0)
    {
        string s;
        while(i--)
        s.pb('a');
        return s;
    }
    ll cn=dp[i+j-1][j];
    if(cn>=k)
    return 'a'+fun(i-1,j,k);
    else
    return 'b'+fun(i,j-1,k-dp[i+j-1][j]);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
for(ll j=0;j<=60;j++)
dp[0][j]=0;
for(ll j=1;j<=60;j++)
dp[j][0]=1;
for(ll j=1;j<=60;j++)
{
    for(ll k=1;k<=60;k++)
    {
        if(k>j)
        dp[j][k]=0;
        else if(k==j)
        dp[j][k]=1;
        else
        dp[j][k]=dp[j-1][k]+dp[j-1][k-1];
    }
}
ll x,y,k;
cin>>x>>y>>k;
cout<<fun(x,y,k)<<"\n";
return 0;
}

#include<bits/stdc++.h>

using namespace std;

int H,W,A,B;
int tatami[16][16];

int dfs(int y,int x){
    //cout<<x<<","<<y<<endl;
    if(y>=H){
        if(A==0&&B==0) return 1;
        return 0;
    }
    int nx=x+1;
    int ny=y;
    if(nx>=W){
        nx=0;
        ny++;
    }
    int ans=0;
    if(tatami[y][x]==1){
        return dfs(ny,nx);
    }
    tatami[y][x]=1;
    B--;
    if(B>=0) ans+=dfs(ny,nx);
    B++;
    A--;
    if(A>=0&&y!=H-1&&tatami[y+1][x]==0){
        tatami[y+1][x]=1;
        ans+=dfs(ny,nx);
        tatami[y+1][x]=0;
    }
    if(A>=0&&x!=W-1&&tatami[y][x+1]==0){
        tatami[y][x+1]=1;
        ans+=dfs(ny,nx);
        tatami[y][x+1]=0;
    }
    A++;
    tatami[y][x]=0;
    return ans;
}

int main(){
    cin>>H>>W>>A>>B;
    cout<<dfs(0,0)<<endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define vt vector
#define pb push_back
#define mp make_pair
#define rep(i, n) for (int i = 0; i < n; i++)
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
const int64_t MOD = 1000000007;

// 🚩
// 20201204 00:47~
//
int main()
{
    ll H, W;
    cin >> H >> W;
    vt<string> S(H);
    rep(i, H) cin >> S.at(i);
    vt<vt<ll>> dp(H, vt<ll>(W, 0)), dpX(H, vt<ll>(W, 0)), dpY(H, vt<ll>(W, 0)), dpXY(H, vt<ll>(W, 0));
    dp.at(0).at(0) = 1;
    dpX.at(0).at(0) = 1;
    dpY.at(0).at(0) = 1;
    dpXY.at(0).at(0) = 1;
    rep(i, H)
    {
        rep(j, W)
        {
            if (S.at(i).at(j) == '#') continue;
            if (j > 0) dp.at(i).at(j) += dpX.at(i).at(j - 1);
            if (i > 0) dp.at(i).at(j) += dpY.at(i - 1).at(j);
            if (i > 0 && j > 0) dp.at(i).at(j) += dpXY.at(i - 1).at(j - 1);
            dp.at(i).at(j) %= MOD;
            dpX.at(i).at(j) = dp.at(i).at(j);
            dpY.at(i).at(j) = dp.at(i).at(j);
            dpXY.at(i).at(j) = dp.at(i).at(j);
            if (j > 0) dpX.at(i).at(j) += dpX.at(i).at(j - 1);
            if (i > 0) dpY.at(i).at(j) += dpY.at(i - 1).at(j);
            if (i > 0 && j > 0) dpXY.at(i).at(j) += dpXY.at(i - 1).at(j - 1);
            dpX.at(i).at(j) %= MOD;
            dpY.at(i).at(j) %= MOD;
            dpXY.at(i).at(j) %= MOD;
        }
    }
    cout << dp.at(H - 1).at(W - 1) << endl;
}

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

const int MOD = 1000000007;
const int INF = 1e9;
const long long INFLL = 1e18;
using ll = long long;

int main(){
  int h, w;
  cin >> h >> w;
  const int MAX = 2000;
  char s[MAX][MAX];
  for(int i = 0; i < h; i++) {
    for(int j = 0; j < w; j++){
      cin >> s[i][j];
    }
  }

  vector<vector<ll>> dp(h, vector<ll>(w, 0));
  dp[0][0] = 1;
  vector<ll> sita(w, 0);
  ll migi;
  vector<vector<ll>> naname(h, vector<ll>(w, 0));
  for(int i = 0; i < h; i++){
    migi = 0;
    for(int j = 0; j < w; j++){
      if(s[i][j] == '#'){
        // dp[i][j] = -1;
        migi = 0;
        sita[j] = 0;
        naname[i][j] = 0;
      }else{
        if(i == 0){
          if(j == 0) {
            migi = dp[i][j];
          }else{
            dp[i][j] = migi;
            migi += dp[i][j];
          }
          sita[j] = dp[i][j];
          naname[i][j] = dp[i][j];
        }else{
          if(j == 0){
            dp[i][j] = sita[j];
            sita[j] += dp[i][j];
            naname[i][j] = dp[i][j];
          }else{
            // cout << naname[i-1][j-1] << endl;
            dp[i][j] = migi + sita[j] + naname[i-1][j-1];
            sita[j] += dp[i][j];
            naname[i][j] = naname[i-1][j-1] + dp[i][j];
          }
          migi += dp[i][j];
        }
      }
      if(dp[i][j] != -1) dp[i][j] %= MOD;
      migi %= MOD;
      sita[j] %= MOD;
      naname[i][j] %= MOD;
      // cout << dp[i][j];
    }
    // cout << endl;
  }

  cout << dp[h-1][w-1] << endl;

  return 0;
}


#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

void solve() {
	long long n;
	cin >> n;
	int comma = 0;
	int cnt = 2;
	long long curr = 1000, res = 0;
	while (curr <= n) {
		cnt++;
		comma = cnt / 3;
		long long a = curr, b = min(n, curr * 10 - 1);
		res += comma * (b - a + 1);
		debug() << imie(res) imie(a) imie(b) imie(cnt);
 		curr *= 10;
	}
	cout << res << "\n";
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int tt = 1;
	//cin >> tt;
	while (tt--) {
		solve();
	}
}


#include <bits/stdc++.h>

//#include <atcoder/modint>

#define inc(i, n) for (int i = 0; i < (n); i++)
#define incs(i, s, n) for (int i = (s); i < (n); i++)

//#define yes printf("Yes\n")
//#define no printf("No\n")

using namespace std;
//using mint = atcoder::modint998244353;
//using pii = pair<int, int>;F
using ll = long long;

const int ARR_SIZE = 5e3+2;
const double epsilon = 0.5;

int main(int argc, char const *argv[])
{
    int N;
    scanf("%d", &N);

    ll ans = 0;
    inc(i, N) {
        ll A, B;
        scanf("%lld%lld", &A, &B);

        ans += (A+B)*(B-A+1)/2;
    }
    printf("%lld\n", ans);

    return 0;
}

#include <bits/stdc++.h>

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

using namespace std;
using ll = long long;

template<typename T>
T pown(T b, ll e) {
    if(e == 0) return 1;
    T p = pown(b, e / 2);
    if(e % 2 == 0) return p * p;
    return p * p * b;
}

template<const int mod>
struct Intmod {
    ll a;
    Intmod(ll a = 0): a(((a % mod) + mod) % mod) {}

    Intmod operator-() const {return Intmod(-a);}

    Intmod& operator+=(const Intmod b) {
        if((a += b.a) >= mod) a -= mod;
        return *this;
    }
    Intmod& operator+=(const ll b) {
        if((a += b) >= Intmod(mod).a) a -= mod;
        return *this;
    }
    Intmod& operator-=(const Intmod b) {
        if((a -= b.a) < 0) a += mod;
        return *this;
    }
    Intmod& operator-=(const ll b) {
        if((a -= Intmod(b).a) < 0) a += mod;
        return *this;
    }
    Intmod& operator*=(const Intmod b) {
        (a *= b.a) %= mod;
        return *this;
    }
    Intmod& operator*=(const ll b) {
        (a *= Intmod(b).a) %= mod;
        return *this;
    }

    template<typename T> Intmod operator+(const T b) const {return Intmod(*this) += b;}
    template<typename T> Intmod operator-(const T b) const {return Intmod(*this) -= b;}
    template<typename T> Intmod operator*(const T b) const {return Intmod(*this) *= b;}

    // Valid for prime mod. pown() needs to be included.
    int i = 0;
    Intmod inv() {
        if(a == 0) throw "Inverse of zero does not exist.";
        if(!i) i = pown(*this, mod - 2).a;
        return Intmod(i);
    }
    Intmod& operator/=(const Intmod b) {return *this *= b.inv();}
    Intmod& operator/=(const ll b) {return *this *= Intmod(b).inv();}
    template<typename T> Intmod operator/(const T b) const {return Intmod(*this) /= b;}
};
template<const int mod> Intmod<mod> operator+(const ll b, Intmod<mod> a) {return a += b;}
template<const int mod> Intmod<mod> operator-(const ll b, Intmod<mod> a) {return a -= b;}
template<const int mod> Intmod<mod> operator*(const ll b, Intmod<mod> a) {return a *= b;}
template<const int mod> Intmod<mod> operator/(const ll b, Intmod<mod> a) {return a /= b;} //Valid for prime mod.

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

    const int MOD = 1000000007;

    int t;
    cin >> t;
    ll n, a, b;
    Intmod<MOD> mul1 = 1, mul2 = 1, sab = 0, sab1 = 0, sab2 = 0, ans = 0;
    rep(i, t) {
        cin >> n >> a >> b;

        if(n < a + b) {
            printf("0\n");
            continue;
        }

        mul1 = 1;
        mul2 = 1;
        mul1 *= n - a + 1;
        mul1 *= n - b + 1;
        mul1 *= 2;
        sab = n;
        sab -= a;
        sab -= b;
        sab1 = sab;
        sab1 += 1;
        sab2 = sab;
        sab2 += 2;
        mul2 *= sab2;
        mul2 *= sab1;
        ans = mul1;
        ans -= mul2;
        ans *= mul2;

        printf("%lld\n", ans.a);
    }

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define ff              first
#define ss              second
#define ll              int64_t
#define ld              long double
#define nl              cout<<"\n"
#define all(v)          v.begin(),v.end()
#define mset(a,v)       memset((a),(v),sizeof(a))
#define forn(i,a,b)     for(int64_t i=int64_t(a);i<int64_t(b);++i)
#define forb(i,a,b)     for(int64_t i=int64_t(a);i>=int64_t(b);--i)
#define fastio()        ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ordered_set     tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>

#define mod         1000000007
#define mod2        998244353
#define inf         1000000000000007
#define pi          3.14159265358979323846

template<class L,class R> ostream& operator<<(ostream& out,pair<L,R> &p)        {return out<<"("<<p.ff<<", "<<p.ss<<")";}
template<class T> ostream& operator<<(ostream& out,vector<T> &v)                {out<<"[";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())out<<", ";out<<*it;}return out<<"]";}
template<class T> ostream& operator<<(ostream& out,deque<T> &v)                 {out<<"[";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())out<<", ";out<<*it;}return out<<"]";}
template<class T> ostream& operator<<(ostream& out,set<T> &s)                   {out<<"{";for(auto it=s.begin();it!=s.end();++it){if(it!=s.begin())out<<", ";out<<*it;}return out<<"}";}
template<class L,class R> ostream& operator<<(ostream& out,map<L,R> &m)         {out<<"{";for(auto it=m.begin();it!=m.end();++it){if(it!=m.begin())out<<", ";out<<*it;}return out<<"}";}

void dbg_out() {cerr<<"]\n";}
template<typename Head,typename... Tail>
void dbg_out(Head H,Tail... T) {cerr<<H;if(sizeof...(Tail))cerr<<", ";dbg_out(T...);}
#ifdef LOCAL
	#define dbg(...) cerr<<"["<<#__VA_ARGS__<<"] = [",dbg_out(__VA_ARGS__)
#else
	#define dbg(...)
#endif

ll count_digits(ll n)     {ll dig=floor(log10(n)+1);return dig;}
ll mpow(ll x,ll y,ll p)   {ll r=1;x=x%p;while(y>0){if(y&1)r=(r*x)%p;y=y>>1;x=(x*x)%p;}return r;}
ll mod_inv(ll a,ll m)     {ll m0=m,y=0,x=1;if(m==1)return 0;while(a>1){ll q=a/m,t=m;m=a%m,a=t;t=y;y=x-q*y;x=t;}if(x<0)x+=m0;return x;}
/* const ll MAXN=1000007;ll spf[MAXN+5];vector<ll> prime; */
/* void sieve(ll n)        {forn(i,2,MAXN+1)spf[i]=i;for(ll i=2;i*i<=n;i++)if(spf[i]==i)for(ll j=i*i;j<=n;j+=i)if(spf[j]==j)spf[j]=i;forn(i,2,MAXN+1)if(spf[i]==i)prime.push_back(i);} */

//-------------------------------L_I_Erq34-------------------------------

vector<vector<ll>> dp;
vector<ll> cnt,max1;

ll calc(ll i,bool carry)
{
	if(i==cnt.size()-1)
		return 1;
	if(dp[i][carry]!=-1)
		return dp[i][carry];
	ll r=cnt[i]+carry;
	if(r==max1[i])
		return dp[i][carry]=calc(i+1,true);
	else if(!r)
		return dp[i][carry]=calc(i+1,false);
	return dp[i][carry]=calc(i+1,true)+calc(i+1,false);
}

int main()
{
	fastio();
	ll z,n,m,t,k,i,j,l,d,h,r;
	cin>>n>>k;
	vector<ll> a(n);
	for(ll &i:a)
		cin>>i;
	cnt=max1=vector<ll>(n);
	dp=vector<vector<ll>>(n,vector<ll>(2,-1));
	r=k;
	forb(i,n-1,0)
	{
		cnt[i]=r/a[i];
		r-=a[i]*cnt[i];
		if(i<n-1)
			max1[i]=a[i+1]/a[i];
	}
	cout<<calc(0,false)<<"\n";
	cerr<<"\nTime elapsed: "<<1000*clock()/CLOCKS_PER_SEC<<"ms\n";
	return 0;
}

#pragma region Macros
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define REP2(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; ++i)
#define REP3(i, l, r) for (int i = (l), i##_len = (int)(r); i < i##_len; ++i)
#define GET_MACRO_REP(_1, _2, _3, NAME, ...) NAME
#define REP(...) GET_MACRO_REP(__VA_ARGS__, REP3, REP2) (__VA_ARGS__)
#define RREP2(i, n) for (int i = (n - 1); i >= 0; --i)
#define RREP3(i, l, r) for (int i = (r - 1), i##_len = (l); i >= i##_len; --i)
#define GET_MACRO_RREP(_1, _2, _3, NAME, ...) NAME
#define RREP(...) GET_MACRO_REP(__VA_ARGS__, RREP3, RREP2) (__VA_ARGS__)
#define IN(type, n) type n; cin >> n
#define INALL(type, v) REP(i, v.size()) { IN(type, _tmp); v.at(i) = _tmp; }
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

#ifdef _DEBUG
#define DEBUG(x) cout << #x << ": " << x << endl
#else
#define DEBUG(x)
#endif

template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
void yes() { cout << "Yes" << endl; }
void no() { cout << "No" << endl; }
#pragma endregion

int main() {
  IN(int, N);
  IN(ll, X);
  vector<ll> A(N);
  vector<ll> max_use(N);
  REP(i, N) {
    IN(ll, a);
    A.at(i) = a;
    if (i > 0) max_use.at(i - 1) = a / A.at(i - 1);
  }

  if (X == A.at(N - 1)) {
    cout << "1" << endl;
    return 0;
  }
  vector<map<ll, ll> > dp(N);
  dp.at(N - 1)[X - (X / A.at(N - 1)) * A.at(N - 1)]++;
  dp.at(N - 1)[X - (X / A.at(N - 1) + 1) * A.at(N - 1)]++;
  RREP(i, N - 1) {
    for (auto itr = dp.at(i + 1).begin(); itr != dp.at(i + 1).end(); ++itr) {
      ll rem = itr->first;
      ll amount = rem / A.at(i);
      rem -= amount * A.at(i);
      if (abs(rem) < A.at(i))
        dp.at(i)[rem] += itr->second;
      if (abs(amount + 1) < max_use.at(i) && abs(rem - A.at(i)) < A.at(i))
        dp.at(i)[rem - A.at(i)] += itr->second;
      if (abs(amount - 1) < max_use.at(i) && abs(rem + A.at(i)) < A.at(i))
        dp.at(i)[rem + A.at(i)] += itr->second;
    }
  }

  cout << dp.at(0)[0] << endl;

  return 0;
}


/*********************************************************************************\
*  _________  _      _  ________  _       _       __       ________               *
* |___   ___|| |    | ||  ______|| |     | |     /  \     |  ____  |              *
*     | |    | |    | || |______ | |_____| |    / /\ \    | |____| |              *
*     | |    | |    | ||______  ||  _____  |   / /__\ \   |  __  __|              *
*     | |    | |____| | ______| || |     | |  / ______ \  | |  \ \                *
*     |_|    |________||________||_|     |_| /_/      \_\ |_|   \_\               *
*                                                                                *
*   Department of Computer Science & Engineering                                  *
*   Student ID : 18CSE035                                                         *
*   Bangabnadhu Sheikh Mujibur Rahman Science & Technology University,Gopalgonj.  *
*                                                                                *
\*********************************************************************************/

//Now Write to Code ___________________________

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

typedef    long long             ll;
typedef    long double           ld;
typedef    unsigned long long    ull;
typedef    pair<int,int>         pii;
typedef    pair<ll,ll>           pll;
typedef    vector<int>           vi;
typedef    vector<ll>            vll;
typedef    vector<vector<int>>   vvi;

inline     int         Int(){int x; cin >> x; return x;}
inline     ll          Long(){ll x; cin >> x; return x;}
inline     float       Float(){float x; cin >> x; return x;}
inline     double      Double(){double x; cin >> x; return x;}
inline     void        Yes(){cout << "Yes" << endl;}
inline     void        No(){cout << "No" << endl;}
inline     void        YES(){cout << "YES" << endl;}
inline     void        NO(){cout << "NO" << endl;}

const      int N       =(int)2e5 + 5;
const      int maxN    =(int)1e6 + 6;
const      ll  Mod     =(ll)1e9 + 7;
const      int inf     =(int)2e9;
const      ll  Inf     =(ll)1e18;

#define    T           int t,q; cin >> t; for(q=1;q<=t;q++)
#define    Forn(i,n)   for(int i=0;i<n;i++)
#define    ForN(i,n)   int i;for(i=n-1;n>=0;i--)
#define    forn(i,n)   for(int i=1;i<=n;i++)
#define    forN(i,n)   int i;for(i=n;n>=1;i--)
#define    fors(i,s)   for(int i=0;i<s.size();i++)
#define    Sort(s)     sort(s.begin(),s.end())
#define    debug(x)    cerr << #x << " = " << x << '\n' ;
#define    rep(i,b,e)  for(__typeof(e) i=(b); i!=(e+1)-2*(b>e); i=i+1-2*(b>e))
#define    gcd(a,b)    __gcd(a , b)
#define    lcm(a,b)    (a*(b/__gcd(a,b)))
#define    gt          greater<int>()
#define    Int         Int()
#define    Long        Long()
#define    Float       Float()
#define    Double      Double()
#define    all(x)      x.begin() , x.end()
#define    sz(x)       (int)x.size()
#define    ff          first
#define    ss          second
#define    pb          push_back
#define    eb          emplace_back
#define    mp          make_pair
#define    mem(a)      memset(a,0,sizeof a)
#define    memn(a)     memset(a,-1,sizeof a)
#define    biday       return 0
#define    nl          endl
#define    sp(n)       fixed<<setprecision(n)
#define    pi          acos(-1)
#define    PI          3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342

int main()
{
    T{
    	ll n,i,c1=0,c2=0;
    	cin >> n;

    	if(n==2)cout << "Same" << endl;
    	else if(n%2)cout << "Odd" << endl;
    	else
    	{
            if(n%2==0 && (n/2)%2==0)cout << "Even" << endl;
            else cout << "Same" << endl;
    	}
    }

    biday;
}

//...............BYE BYE................

// -- //
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 1e5+228;

signed main(){
	cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
    ll q;
    cin >> q;
    while(q--){
        ll n;
        cin >> n;
        ll u = n&-n;
        ll l = 1, e=0;
        while(l<u){
            l<<=1;
            e++;
        }
        if(e==0) cout<<"Odd\n";
        else if(e==1) cout<<"Same\n";
        else cout<<"Even\n";
    }
}


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

using namespace std;

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

    vector<int> a(n);
    rep(i, n) cin >> a.at(i);

    ll ans = 0;
    ll nc = 0;
    ll sum = 0;
    ll m = 0;
    for (int i = 1; i <= n; i++) {
        sum = sum + a.at(i - 1);
        m = max(m, sum);
        ans = max(ans, nc + m);
        nc += sum;
    }

    cout << ans << endl;

    return 0;
}

#include <bits/stdc++.h>
//#include <chrono>
//#pragma GCC optimize("O3")
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second

using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

ll N, M, K, H, W, A, B, C, D;
string S;
const ll INF = 1LL<<60;

int main(){
    cin>>N;
    ll res(0);
    rep(i, N){
        cin>>A>>B;
        res += (A + B) * (B - A + 1) / 2;
    }
    cout<<res<<endl;
}


#pragma GCC optimize("O3")
#pragma GCC target("avx2")
#pragma GCC optimize("unroll-loops")

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

typedef long double ld;
typedef long long int ll;
typedef pair<int, int> pi;
typedef pair<long long, long long> pll;

#define ff first
#define ss second
#define pb push_back
#define int long long   // Make sure to use ll everywhere while commenting this, to avoid overflow
#define sz(v) (int)v.size()
#define inf 2147483647
#define llinf 9223372036854775807
#define all(v) v.begin(),v.end()
#define bp(n) __builtin_popcountll(n)
#define f(i,l,r) for(long long i=l;i<=r;i++)
#define rf(i,r,l) for(long long i=r;i>=l;i--)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)

template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void dbg_out() { cout << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cout << ' ' << H; dbg_out(T...); }

const int N = 16385, mod = 1e9 + 7, bit = 61;

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

int getRand(int l, int r)
{
	uniform_int_distribution<int> uid(l, r);
	return uid(rng);
}

signed main()
{
	fast;

	int t = 1;
	// cin>>t;
	f(tc, 1, t)
	{
		int n;
		cin >> n;
		int a[n + 1], b[n + 1], c[n + 1];
		map<int, int> mp;
		int ans = 0;
		f(i, 1, n)
		{
			cin >> a[i];
		}
		f(i, 1, n)
		{
			cin >> b[i];
		}
		f(i, 1, n)
		{
			cin >> c[i];
			mp[b[c[i]]]++;
		}
		f(i, 1, n)
		{
			ans += mp[a[i]];
		}
		cout << ans << endl;
	}
	return 0;
}

#include<bits/stdc++.h>
#define rep(i, n) for (Int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(Int i=(n)-1;i>=0;i--)
#define FOR(i,a,b) for(Int i=a;i<=Int(b);i++)
#define __MAGIC__ ios::sync_with_stdio(false);cin.tie(nullptr);
//#include <atcoder/all>
//using namespace atcoder;
typedef long long Int;
const long long INF = 1ll << 60;
using namespace std;
using p = pair<int,int>;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main(){
  __MAGIC__
  int n; cin >> n;
  int A[n], B[n];

  rep(i,n)cin >> A[i];
  rep(i,n)cin >> B[i];
  Int sums = 0;
  rep(i,n){
    sums += A[i]*B[i];
  }
  if(sums == 0)cout << "Yes" <<endl;
  else cout << "No" <<endl;

//  cout << ans << endl;
//  cout << (ans ? "Yes" : "No") << endl;

  return 0;
}


/*
	JAI JAGANNATH!
*/
//@Author : zanj0

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

#define int 			long long int

#define ff              first
#define ss              second
#define pb              push_back
#define MOD             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(x)            int x; cin>>x; while(x--)
#define endl       		"\n"
#define timetaken cerr<<"Time : "<<1000*(long double)clock()/(long double)CLOCKS_PER_SEC<<"ms\n"

void zanj0()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
int nCr(int n, int r) {
	int ret = 1;
	for (int i = 1; i <= r; i++) {
		ret = ret  * (n - i + 1);
		ret /= i;
	}
	return ret;
}
void solve() {
	int a, b, k;
	cin >> a >> b >> k;
	string ret = "";
	int n = a + b;
	for (int i = 0; i < n; i++) {
		int posAfter = n - 1 - i;
		int notPutA = nCr(posAfter, b);
		if (notPutA < k) {
			k -= notPutA;
			ret += 'b';
			b--;
		} else {
			ret += 'a';
			a--;
		}

	}
	cout << ret << endl;
}
int32_t main()
{
	zanj0();
	solve();
	timetaken;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vll = vector<long long>;
using vb = vector<bool>;
using vd = vector<double>;
using vc = vector<char>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long>>;
using vvc = vector<vector<char>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename T> using graph = vector<vector<pair<T, int>>>;// pair of weight and vertex
template<typename T> inline bool chmax(T& a, const T b){if(a < b){ a = b; return true; } return false; }
template<typename T> inline bool chmin(T& a, const T b){if(a > b){ a = b; return true; } return false; }
void my_answer(){

   int n;
   cin >> n;

   vi a(n);
   ll rem[200] = {0};

   for(auto& x: a){
       cin >> x;
       ++rem[x % 200];
   }

   ll ans = 0;
   for(int i = 0; i < 200; ++i){
       if(rem[i] == 0) continue;
       ans += (rem[i]*(rem[i]-1LL))/2LL;
   }

   cout << ans << endl;

}
void best_answer(){

}
int main(){

    my_answer();
    // best_answer();
}


#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <cstring>
#include <istream>
#include <algorithm>
#include <map>
#include <cmath>
#include <unordered_map>
using namespace std;

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

bool vis[1000000005];

int main() {
	memset(vis, false, sizeof(vis));
	int n;
	cin >> n;
	map<int, int>mp;
	vector<int>a(n);
	for (auto& i : a)cin >> i;
	int min = 0x3F3F3F3F;
	for (auto i : a)if (min > i)min = i;
	mp[min] = 1;
	for (auto i : a) {
		for (int j = 1; j * j <= i && j < min; j++) {
			int ans = i;
			if (i % j == 0 && vis[j] == 0) {
				vis[j] = 1;
				for (auto k : a) {
					if (k % j == 0)ans = gcd(ans, k);
					if (ans == j) {
						mp[j] = 1; break;
					}
				}
			}
			ans = i;
			if (i % j == 0 && vis[i / j] == 0 && i / j < min) {
				vis[i / j] = 1;
				int ccc = i / j;
				for (auto k : a) {
					if (k % ccc == 0)ans = gcd(ans, k);
					if (ans == ccc) {
						mp[ccc] = 1; break;
					}
				}
			}
		}
	}
	cout << mp.size() << endl;
	return 0;
}


#include "bits/stdc++.h"
using namespace std;
using ll=int64_t;
using ld=long double;
using ull=unsigned long long;
template <class T>
using grid=vector<vector<T>>;
#define ALL(x) x.begin(),x.end()
#define rep(iter,from,to) for(ll iter=from;iter<to;++iter)

#ifndef ONLINE_JUDGE
#define local true;
#endif

const ll MOD = 1e9 + 7;
const ll INF = 1e17;
//#######################################################################
vector<vector<ll>> input(ll N, ll width) {
    string str;
    vector<vector<ll>> vec(N, vector<ll>(width));
    for (ll i = 0; i < N; ++i) {
        cin >> str;
        reverse(ALL(str));
        for (ll j = 0; j < width; ++j) {
            vec[i][j] = str.back();
            str.pop_back();
        }
    }
    return vec;
}
void op(vector<ll> vec) {
    ll size = (ll)vec.size();
    for (ll i = 0; i < size - 1; ++i) cout << vec[i] << " ";
    cout << vec.back() << endl;
}

void op(vector<vector<ll>> vec) {
    ll height = (ll)vec.size();
    ll width = (ll)vec[0].size();
    for (ll i = 0; i < height; ++i) {
        for (ll j = 0; j < width - 1; ++j) cout << vec[i][j] << " ";
        cout << vec[i].back() << endl;
    }
}
//########################################################################

struct in{
    ll len;
    string str;
    ll num;
};

bool compare(const in& fr, const in& se){
    if(fr.len!=se.len) return fr.len<se.len;
    else return fr.num>se.num;
}

int solve(){
    ll N,M;
    cin>>N>>M;
    random_device rnd;
    mt19937 mt(rnd());
    uniform_int_distribution<> pick(0,M-1);
    vector<in> dict;
    set<string> checker;
    in inserter;
    rep(i,0,M){
        string s;
        cin>>s;
        if(checker.count(s)==0){
            inserter.len=s.size();
            inserter.str=s;
            inserter.num=1;
            checker.insert(s);
            dict.push_back(inserter);
        }
        else {
            rep(c,0,dict.size()) if(dict[c].str==s) {dict[c].num++; break;}
        }
    }
    grid<char> res(N,vector<char>(N,'.'));
    sort(ALL(dict),compare);
    //if(local) for(auto a:dict) cout<<a.str<<" "<<a.num<<endl;
    ll iter=0;
    for(ll i=0;i<N;++i) {
        ll cnt=0;
        ll start=0;
        while(true) {
            rep(j,0,dict[iter].len) {
                if(cnt>=N) break;
                res[i][start+j]=dict[iter].str[j];
                cnt++;
            }
            iter++;
            if(iter>=dict.size()) iter-=dict.size();
            start+=dict[iter].len;
            if(cnt>=N-1) break;
        }
    }
    uniform_int_distribution<> rand7(0, 7);
    vector<char> alpha{'A','B','C','D','E','F','G','H'};
    rep(i,0,N) {
        rep(j,0,N) {
            if(res[i][j]=='.') res[i][j]=alpha[rand7(mt)];
            cout<<res[i][j];
        }
        cout<<endl;
    }
    return 0;
}

int main(void){
    std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	solve();
}

#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
//#include <atcoder/all>
#define rep(i, n) for (int i = 0; i < ll(n); ++i)
typedef int64_t lint;
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using lb = long double;

#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define all(x) (x).begin(), (x).end()
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
#define debug(x) cerr << #x << ": " << x << "\n"
#define debugV(x)                              \
    for (int i = 0; i < ((ll)(x).size()); i++) \
    cerr << #x << "at:" << i << ": " << x[i] << "\n"
#define YES(c) cout << ((c) ? "YES\n" : "NO\n"), 0
#define Yes(c) cout << ((c) ? "Yes\n" : "No\n"), 0
#define O(p) cout << p << "\n", 0
#define OS(p) cout << p << " ", 0
#define ON(p) cout << p, 0
#define INF 1000000000000
#define MOD 1000000007
#define pb emplace_back
#define mp make_pair
#define F first
#define S second
#define CST(x) cout << fixed << setprecision(x)
#define uoset unordered_set
#define vec vector
#define str string
const int dy[4] = {-1, 0, 1, 0};
const int dx[4] = {0, 1, 0, -1}; //^>v<
const string dstr="URDL";

const int Dy[5]={0,-1, 0, 1, 0};
const int Dx[5]={0,0, 1, 0, -1};

struct RandomNumberGenerator
{
    mt19937 mt;

    RandomNumberGenerator() : mt(chrono::steady_clock::now().time_since_epoch().count()) {}

    int operator()(int a, int b)
    { // [a, b]
        uniform_int_distribution<int> dist(a, b);
        return dist(mt);
    }

    int operator()(int b)
    { // [0, b]
        return (*this)(0, b);
    }
};
struct Timer
{
    chrono::high_resolution_clock::time_point st;

    Timer() { reset(); }

    void reset()
    {
        st = chrono::high_resolution_clock::now();
    }

    chrono::milliseconds::rep elapsed()
    {
        auto ed = chrono::high_resolution_clock::now();
        return chrono::duration_cast<chrono::milliseconds>(ed - st).count();
    }
};

ll chatoi(char a)
{
    string s = "";
    s += a;
    return stoi(s);
}

//------------------------------------------------------------
ll N,M;

bool comp(const std::string& lh, const std::string& rh) {
     // 文字列lhの長さが文字列rhより短かったらtrueを返す
     return lh.length() < rh.length();
}

bool write(vec<str> &Mat,int piv,int sta,str &s,bool isX){
    if(isX){
        rep(i,s.size()){
            int x=(sta+i)%N;
            if(!(Mat[piv][x]=='.'||Mat[piv][x]==s[i])){
                return false;
            }
        }
    }else{
        rep(i,s.size()){
            int y=(sta+i)%N;
            if(!(Mat[y][piv]=='.'||Mat[y][piv]==s[i])){
                return false;
            }
        }
    }

    if(isX){
        rep(i,s.size()){
            int x=(sta+i)%N;
            Mat[piv][x]=s[i];
        }
    }else{
        rep(i,s.size()){
            int y=(sta+i)%N;
            Mat[y][piv]=s[i];
        }
    }
    return true;
}

//------------------------------------------------------------
int main()
{
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    //--------------------------------------------------------
    auto Rand=RandomNumberGenerator();
    auto Tim=Timer();

    cin>>N>>M;

    vec<str> Mat(N,"");
    vec<str> S(M);
    rep(i,N){
        rep(j,N){
            Mat[i]+='.';
        }
    }
    rep(i,M){
        str s;cin>>s;
        S[i]=s;
    }
    sort(all(S),comp);

    int y=0,x=0,Snow=0;
    while(Snow!=M){
        rep(i,N){
            rep(j,N){
                if(write(Mat,i,j,S[Snow],true)){
                    Snow++;
                    goto A;
                }else if(write(Mat,j,i,S[Snow],false)){
                    Snow++;
                    goto A;
                }
            }
        }
        Snow++;
        A:;
        if(Tim.elapsed()>2990){
            O("ASAS");
            break;
        }
    }

    rep(i,N){
        O(Mat[i]);
    }

    return 0;
}


#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <string>
#include <iomanip>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <complex>
#include <ctime>
#include <bitset>
// #include <atcoder/all>
#include <fstream>
#include <random>
#include <cassert>

//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;
// using namespace atcoder;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef int itn;
const ll LINF = 1e16;
const int INF = 1e9;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(ll i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用
#define ret return 0

template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

#define ketasitei setprecision(15) //15桁表示

const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const long double PI = 3.1415926535897932;

using Graph = vector<vector<ll>>;

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

	string s;
	cin >> s;

	ll ans = 0;

	for (int i = 0; i < s.size() - 3; i++)
	{
		if (s[i] == 'Z' && s[i + 1] == 'O' && s[i + 2] == 'N' && s[i + 3] == 'e')
			ans++;
	}

	cout << ans << endl;

	return 0;
}

#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	ll ans = 0, cur = 0;
	vector<ll> a(n), sum(n+1, 0LL), mx(n+1, 0LL);
	rep(i,n){
		cin >> a[i];
		sum[i+1] = sum[i] + a[i];
		mx[i+1] = max(mx[i], sum[i+1]);
	}
	for(int i = 1; i <= n; ++i){
		chmax(ans, cur + mx[i]);
		cur += sum[i];
	}
	chmax(ans, cur);
	cout << ans << endl;
	return 0;
}


#include<bits/stdc++.h>
#include<bits/extc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
using namespace __gnu_pbds;
#ifndef DEBUG
#define cerr while(false) cerr
#endif
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define priority_queue std::priority_queue
#define F first
#define S second

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
vector<pii>adj[5000005];
char a[2005][2005];
int INF=1e9;
ll dist[5000005];
int get(int x, int y){
	if(a[x][y]=='S') return 0;
	if(a[x][y]=='G') return 1;
	return x*2005+y+2;
}
void dijkstra(int src){
	for(int i=0;i<5000005;i++) dist[i]=INF;
	priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq;
	dist[src]=0;
	pq.push({0, src});
	while(!pq.empty()){
		auto [w, x]=pq.top(); pq.pop();
		if(dist[x]<w) continue;
		for(auto [y, cw]: adj[x]){
			if(dist[y]>w+cw){
				dist[y]=w+cw;
				pq.push({dist[y], y});
			}
		}
	}
}
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int h, w;
	cin>>h>>w;
	for(int i=0;i<h;i++)
		for(int j=0;j<w;j++) cin>>a[i][j];
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(a[i][j]=='#') continue;
			for(int k=0;k<4;k++){
				int ci=i+dx[k], cj=j+dy[k];
				if(ci>=0 && ci<h && cj>=0 && cj<w && a[ci][cj]!='#'){
					//cout<<get(i, j)<<" "<<get(ci, cj)<<" "<<2<<endl;
					adj[get(i, j)].push_back({get(ci, cj), 2});
				}
			}
			if(a[i][j]>='a' && a[i][j]<='z'){
				int c=4500000+(int)(a[i][j]-'a');
				adj[get(i, j)].push_back({c, 1});
				adj[c].push_back({get(i, j), 1});
			}
		}
	}
	dijkstra(0);
	cout<<(dist[1]==INF ? -1 : dist[1]/2)<<endl;
}

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

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

	int n,m;
	cin>>n>>m;
	vs in(n);
	rep(i,n)cin>>in[i];
	vvp w(26);
	vvi dp(n,vi(m,inf));
	vi used(26);
	queue<pii>q;
	rep(i,n)rep(j,m){
		if(in[i][j]=='S'){
			dp[i][j]=0;
			q.push({i,j});
		}
		if(islower(in[i][j])){
			w[in[i][j]-'a'].pb({i,j});
		}
	}
	while(!q.empty()){
		int x=q.front().first;
		int y=q.front().second;
		q.pop();
		if(in[x][y]=='G'){
			cout<<dp[x][y]<<endl;
			return 0;
		}
		rep(i,4){
			int nx=x+dx[i];
			int ny=y+dy[i];
			if(nx<0||ny<0||nx>=n||ny>=m)continue;
			if(in[nx][ny]=='#')continue;
			if(dp[nx][ny]!=inf)continue;
			dp[nx][ny]=dp[x][y]+1;
			q.push({nx,ny});
		}
		if(islower(in[x][y])){
			int a=in[x][y]-'a';
			if(used[a])continue;
			rep(j,w[a].size()){
				pii ax=w[a][j];
				if(dp[ax.first][ax.second]-inf)continue;
				dp[ax.first][ax.second]=dp[x][y]+1;
				q.push(ax);
			}
			used[a]=1;
		}
	}
	cout<<-1<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{

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

  int tsc=1;
 //cin>>tsc;
  while(tsc--){
    int t,n;
    cin>>t>>n;
    int a=(n*100+t-1)/(t);
    cout<<a+n-1;

cout<<endl;}}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn=1e6+5;

int main() {
    ll t,n;cin>>t>>n;n--;
    ll need=n%t+1,start=100*(n/t)+1,last=((100+t)*(start-1)/100);
    for(;need;) {
        ll now=((100+t)*start/100);
        if(now!=last+1) need--;
        start++;last=now;
    }
    cout<<last-1<<endl;
    return 0;
}


#include <bits/stdc++.h>
        #include <math.h>

        using namespace std;
        typedef long long ll;
        typedef unsigned long long ull;
        # define M_PI  3.14159265358979323846

        const int M=1e9+7;
        long long mod(long long x){
            return ((x%M + M)%M);
        }
        long long add(long long a, long long b){
            return mod(mod(a)+mod(b));
        }
        long long mul(long long a, long long b){
            return mod(mod(a)*mod(b));
        }

        ll modPow(ll a, ll b){
            if(b==0)
                return 1LL;
            if(b==1)
                return a%M;
            ll res=1;
            while(b){
                if(b%2==1)
                    res=mul(res,a);
                a=mul(a,a);
                b=b/2;
            }
            return res;
        }

        void solve (){
            ll n;
            cin>>n;
            n=2*n;
            ll ans=0;
            for(ll i=1;i*i<=n;i++){
                if(n%i==0){
                    ll f1=i;
                    ll f2=n/i;
                    if((f2+1-f1)%2==0) ans++;
                    if(n/i != i){
                    ll f1=n/i;
                    ll f2=i;
                    if((f2+1-f1)%2==0) ans++;
                    }
                }
            }
            cout<<ans;
        }
        int main(){
            ios::sync_with_stdio(0);
            cin.tie(0);
            cout.tie(0);
            cout<<fixed;
            cout<<setprecision(10);
    //        freopen("timber_input.txt", "r", stdin);
    //        freopen("timber_output.txt", "w", stdout);
            int t=1;
            // cin>>t;
            for(int i=1;i<=t;i++){
            //    cout<<"Case #"<<i<<": ";
                solve();
            }
            return 0;
        }

#include <bits/stdc++.h>
using namespace std;
#define rep(i, l, n) for (int i = (int)(l); i < (int)(n); i++)
#define drep(i, n, l) for (int i = (int)(n); i > (int)(l); i--)
#define INF INT_MAX
#define INFF (pow(2,64))
#define def (200007)
#define MOD (1000000007)
typedef int64_t intt;
typedef vector<int> veci;
typedef vector<vector<int>> Veci;
typedef vector<int64_t> vecit;
typedef vector<vector<int64_t>> Vecit;
typedef vector<vector<double>> Vecd;
typedef vector<double> vecd;
typedef pair<intt, intt> P;
typedef unordered_set<int> uset;
typedef unordered_set<intt> usett;
int main(){
  intt N;cin>>N;
  intt sum=0;
  veci allgcd(pow(N,0.5)+1,0);
  intt at_n=N;
  rep(i,2,pow(N,0.5)+1){
    if(N%i==0){
      while(at_n%i==0){
        allgcd[i]++;
        at_n/=i;
      }
    }
  }

  intt at_sum=1;
  rep(i,3,allgcd.size()){
    if(allgcd[i]>=1)at_sum*=(allgcd[i]+1);
  }
  if(at_n>2)at_sum*=2;
  sum+=at_sum;
  sum*=2;

  cout<<sum<<endl;

}


#include <iostream>
#include <queue>

using namespace std;

const int DIR_X[2] = {-1, 0};
const int DIR_Y[2] = {0, -1};

int h, w;
int a[2001][2001];

pair<int,int> ans[2001][2001];
bool used[2001][2001];
void calc() {
    queue<pair<int, pair<int,int>>> que;

    int start = 1;
    if ((w+h-2) % 2 != 0) {
        start = -1;
    }
    que.push(make_pair(start, make_pair(w-1,h-1)));

    while(que.size()) {
        pair<int , pair<int, int>> now = que.front();
        que.pop();

        int my = now.first;
        int nowX = now.second.first;
        int nowY = now.second.second;

        // cout << nowX << ", " << nowY << endl;

        for (int i = 0;i < 2;i++) {
            int toX = nowX + DIR_X[i];
            int toY = nowY + DIR_Y[i];

            if (toX < 0 || toY < 0) continue;

            if (used[toX][toY]) {
                if (my == 1) {
                    int ansDiff = ans[toX][toY].second - ans[toX][toY].first;
                    int nowDiff = ans[nowX][nowY].second - ans[nowX][nowY].first + a[nowX][nowY];

                    if (nowDiff > ansDiff) {
                        ans[toX][toY] = ans[nowX][nowY];
                        ans[toX][toY].second += a[nowX][nowY];
                    }
                } else {
                    int ansDiff = ans[toX][toY].first - ans[toX][toY].second;
                    int nowDiff = ans[nowX][nowY].first - ans[nowX][nowY].second + a[nowX][nowY];

                    if (nowDiff > ansDiff) {
                        ans[toX][toY] = ans[nowX][nowY];
                        ans[toX][toY].first += a[nowX][nowY];
                    }
                }
            } else {
                used[toX][toY] = true;
                ans[toX][toY] = ans[nowX][nowY];
                if (my == 1) {
                    ans[toX][toY].second += a[nowX][nowY];
                } else {
                    ans[toX][toY].first += a[nowX][nowY];
                }
                que.push(make_pair(-my, make_pair(toX, toY)));
            }
        }
    }
    // cout << ans[2][2].first << ", " << ans[2][2].second << endl;

    // cout << ans[0][0].first << ", " << ans[0][0].second << endl;

    if (ans[0][0].first == ans[0][0].second) {
        cout << "Draw" << endl;
    } else if (ans[0][0].first > ans[0][0].second) {
        cout << "Takahashi" << endl;
    } else {
        cout << "Aoki" << endl;
    }
}

int main() {
    string str;
    cin >> h >> w;
    for (int i = 0;i < h;i++) {
        cin >> str;
        for (int j = 0;j < w;j++) {
            if (str[j] == '+') {
                a[j][i] = 1;
            } else {
                a[j][i] = -1;
            }
        }
    }

    calc();

    return 0;
}

//#include <iostream>
//#include <vector>
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;

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

int main() {
    int H, W;
    cin >> H >> W;
    vector<vector<int>> A(H, vector<int>(W));
    char a;
    for(int i = 0; i < H; ++i) {
        for(int j = 0; j < W; ++j) {
            cin >> a;
            if(a == '+') A.at(i).at(j) = 1;
            else A.at(i).at(j) = -1;
        }
    }

    vector<vector<int>> dp(H+1, vector<int>(W+1, 0));

    for(int i = H-1; i >= 0; --i) {
        for(int j = W-1; j >= 0; --j) {
            // mr. takahashi
            if((i + j) % 2 == 0) {
                if(i+1 < H && j+1 < W) {
                    dp.at(i).at(j) = max(dp.at(i+1).at(j) + A.at(i+1).at(j), dp.at(i).at(j+1) + A.at(i).at(j+1));
                }
                else if(i+1 == H && j+1 < W) {
                    dp.at(i).at(j) = dp.at(i).at(j+1) + A.at(i).at(j+1);
                }
                else if(i+1 < H && j+1 == W) {
                    dp.at(i).at(j) = dp.at(i+1).at(j) + A.at(i+1).at(j);
                }
            }
            else {
                if(i+1 < H && j+1 < W) {
                    dp.at(i).at(j) = min(dp.at(i+1).at(j) - A.at(i+1).at(j), dp.at(i).at(j+1) - A.at(i).at(j+1));
                }
                else if(i+1 == H && j+1 < W) {
                    dp.at(i).at(j) = dp.at(i).at(j+1) - A.at(i).at(j+1);
                }
                else if(i+1 < H && j+1 == W) {
                    dp.at(i).at(j) = dp.at(i+1).at(j) - A.at(i+1).at(j);
                }
            }
        }
    }

    if(dp.at(0).at(0) > 0) cout << "Takahashi" << endl;
    else if(dp.at(0).at(0) < 0) cout << "Aoki" << endl;
    else cout << "Draw" << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(size_t i=(l); i<(r); i++)
#define REP(i,n) FOR(i,0,n)
#define endl "\n"
#define debug(x) cout<<x<<endl;
typedef long long ll;
static const ll INF = 1ll<<60;

int main(){
    int N,S,D;
    cin>>N>>S>>D;
    vector<int> X(N),Y(N);
    REP(i,N) cin>>X[i]>>Y[i];

    bool flag = false;

    REP(i,N){
        if(X[i]  >= S) continue;
        if(Y[i] <= D) continue;
        flag = true;
    }

    cout<<(flag ? "Yes" : "No")<<endl;
}

#include <iostream>

using namespace std;

int n;
string s , t;
int a[500010] , cnt;

int main()
{
	ios::sync_with_stdio(false);
	cin >> n >> s >> t;
	for(int i = 0; i < n; i++)
		if(s[i] == '1')
			a[++cnt] = i;
	int temp = 1;
	long long ans = 0;
	for(int i = 0; i < n; i++)
		if(t[i] == '1')
		{
			while(a[temp] < i && temp <= cnt)
			{
				if(temp == cnt)
				{
					cout << -1 << endl;
					return 0;
				}
				ans += a[temp + 1] - a[temp] , temp += 2;
			}
			if(temp == cnt + 1)
			{
				cout << -1 << endl;
				return 0;
			}
			ans += a[temp] - i , temp++;
		}
	while(temp <= cnt)
	{
		if(temp == cnt)
		{
			cout << -1 << endl;
			return 0;
		}
		ans += a[temp + 1] - a[temp] , temp += 2;
	}
	cout << ans << endl;
	return 0;
}


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

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int j=6;
    if(n==3)
    {
        cout<<"6 10 15";
        return 0;
    }
    for(int i=0;i<n;i++)
    {
        cout<<j<<' ';
        j++;
        while((j%6!=0&&j%10!=0&&j%15!=0))
        {
            j++;
        }
    }
    return 0;
}

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

int main()
{
    vector <int> ans;
    for(int i = 1; i <= 10000; i++)
        if(i%6 == 0 || i%10 == 0 || i%15 == 0)
            ans.push_back(i);
    swap(ans[2] ,ans[3]);
    int n;
    scanf("%d",&n);
    for(int i = 0; i < n; i++)
        printf("%d ",ans[i]);
    printf("\n");
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>

#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<vector<ll> > mat;

const int N=2e5+5;

ll a[N],b[N],k[N],t[N],d[N],n,m,x,y;

vector<pll> v[N];

int main()
{ios_base::sync_with_stdio(false);
cin.tie(0);
rep(i,0,N-1)d[i]=1e18+7;
cin>>n>>m>>x>>y;

rep(i,0,m-1)
{
	cin>>a[i]>>b[i]>>t[i]>>k[i];
	v[a[i]].pb({b[i],i});
	v[b[i]].pb({a[i],i});
}

priority_queue<pll> q;
d[x]=0;
q.push({0,x});

while(!q.empty())
{
	ll dis=-q.top().ff,at=q.top().ss;
	q.pop();
	if(dis>d[at])continue;
	tr(v[at],it)
	{
		ll to=it->ff,id=it->ss;
		ll dis2=dis+(k[id]-dis%k[id])%k[id]+t[id];
		if(dis2<d[to])
		{
			d[to]=dis2;
			q.push({-dis2,to});
		}
	}
}
if(d[y]<1e17)
{
	ol(d[y]);
}
else
{
	ol("-1");
}
return 0;
}

#include <bits/stdc++.h>
#define fi first
#define se second
#define lc (x << 1)
#define rc (x << 1 | 1)
#define gc getchar() //(p1==p2&&(p2=(p1=buf)+fread(buf,1,size,stdin),p1==p2)?EOF:*p1++)
#define mk make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define IT iterator
#define vi vector<int>
#define TP template <class o>
#define SZ(a) ((int)a.size())
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int N = 110, S = N * N * N / 2, size = 1 << 20, inf = 2e9;

// char buf[size],*p1=buf,*p2=buf;
template <class o> void qr(o& x) {
    char c = gc;
    x = 0;
    int f = 1;
    while (!isdigit(c)) {
        if (c == '-')
            f = -1;
        c = gc;
    }
    while (isdigit(c))
        x = x * 10 + c - '0', c = gc;
    x *= f;
}
template <class o> void qw(o x) {
    if (x / 10)
        qw(x / 10);
    putchar(x % 10 + '0');
}
template <class o> void pr1(o x) {
    if (x < 0)
        x = -x, putchar('-');
    qw(x);
    putchar(' ');
}
template <class o> void pr2(o x) {
    if (x < 0)
        x = -x, putchar('-');
    qw(x);
    putchar('\n');
}

int n, k, p, f[N][S], sum[N], s[N], ou[N];

void ad(ll& x, ll y) {
    x += y;
    if (x >= p)
        x -= p;
}

int main() {
    qr(n);
    qr(k);
    qr(p);
    f[0][0] = 1;
    for (int i = 1; i <= n; i++) {
        sum[i] += sum[i - 1] + i * k;
        for (int j = 0; j < i; j++)
            s[j] = 0;
        for (int j = 0; j <= sum[i]; j++) {
            int x = j % i;
            s[x] = (s[x] + f[i - 1][j]) % p;
            if (j - (k + 1) * i >= 0)
                s[x] = (s[x] - f[i - 1][j - (k + 1) * i] + p) % p;
            f[i][j] = s[x];
        }
    }
    for (int i = 1, j = n; i <= j; i++, j--) {
        ll ans = 0;
        for (int j = 0; j <= sum[i - 1]; j++)
            ad(ans, (ll)f[i - 1][j] * f[n - i][j] % p);
        ou[i] = ou[j] = ((ans * (k + 1) + p) - 1) % p;
    }
    for (int i = 1; i <= n; i++)
        pr2(ou[i]);
    return 0;
}


//
// Created by whq on 2021/2/21.
//

#include <bits/stdc++.h>

#define uset unordered_set
#define umap unordered_map
#define debug cout<<"ok"<<endl
#define ll long long
#define ii pair<ll, ll>
#define fi first
#define se second
#define vi vector<int>
#define vb vector<bool>
#define vvi vector<vector<int>>
#define vvb vector<vector<bool>>
#define vvl vector<vector<ll>>
#define vl vector<ll>
#define mod 1000000007
#define inf 0x3f3f3f3f
#define For(i, n) for (int i = 0; i < n; i++)
#define forn(i, a, b) for(int i=a;i<=b;i++)
#define pb(a) push_back(a)
#define all(a) a.begin(),a.end()
#define lowbit(x) x&(-x)
using namespace std;
class A{
public:
    void solve(){
        ll k;
        cin>>k;
        ll res=0;
        for(ll i=1;i*i*i<=k;i++) res++;
        for(ll i=1;i*(i+1)<=k;i++){
            for(ll j=i+1;j*i<=k;j++){
                if(i*i*j<=k) res+=3;
                if(i*j*j<=k) res+=3;
            }
        }
        for(ll i=1;i*(i+1)<=k;i++){
            for(ll j=i+1;j*i<=k;j++){
                for(ll l=j+1;l*j*i<=k;l++) res+=6;
            }
        }
        cout<<res<<endl;
    }
};
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    A ans;
    ans.solve();
    return 0;
}

#include <bits/stdc++.h>

using ull = unsigned long long int;
using ll = long long;
using ld = long double;
using pii = std::pair<int,int>;
using pll = std::pair<ll, ll>;
using vi = std::vector<int> ;
using vvi = std::vector<vi> ;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vd = std::vector<double> ;
using vvd = std::vector<vd> ;
using qi = std::queue<int> ;
using vpii = std::vector<std::pair<int, int> >;
using vpll = std::vector<pll>;
using namespace std;

#define rep(i,j) for(int (i)=0;(i)<(j);(i)++)
#define drep(i,j) for(int (i)=(j);(i) >= 0;(i)--)

template<class T1, class T2> inline void chmin(T1 &a, T2 b){if(a > b) a = b;}
template<class T1, class T2> inline void chmax(T1 &a, T2 b){if(a < b) a = b;}
template<class T> inline void pri(T a){cout << a << endl;}
template<class Z> using vec = vector<Z>;
template<class T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

inline void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

inline void OUT(void){
 cout << endl;
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
cout << first << " " ;
OUT(rest...);
   return;
}
const int max_n = 3 * (1e5) + 1;
const int max_m = 83 * (1e5) + 1;
const int INF = int(1e9);

int n,m,k;
string S;
int ans;

void solve()
{
  int n;
  IN(n);
  int ans = 100 - n %100;
  cout << ans << endl;
}

signed main (int argc, char* argv[]) {
   cin.tie(0);
   ios::sync_with_stdio(false);
   int cases=1;
   //IN(cases);
   while(cases--)solve();
   //pri(ans);
   //for(auto c : ans){cout << c << endl;}
   //cout << fixed << setprecision(15) << ans << endl;
   return 0;
}


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

const int N = 200010, mod = 1e9 + 7;

ll dp[N][20], k, num[N];
char s[N];

ll dfs(int pos, bool limit, bool lead, int cnt, ll state){
	if(!pos)	return cnt == k;
	if(cnt > k)	return 0;
	if(!limit && !lead && ~dp[pos][cnt])	return dp[pos][cnt];
	ll ans = 0;
	int up = limit ? num[pos] : 15;
	for(int i = 0; i <= up; ++ i){
		if(lead && !i)	ans = (ans + dfs(pos - 1, limit && i == up, true, 0, 0)) % mod;
		else{
			if((state >> i) & 1)	ans = (ans + dfs(pos - 1, limit && i == up, false, cnt, state)) % mod;
			else	ans = (ans + dfs(pos - 1, limit && i == up, false, cnt + 1, state | (1 << i))) % mod;
		}
	}
	if(!limit && !lead)	dp[pos][cnt] = ans;
	return ans;
}

ll solve(){
	int len = strlen(s + 1);
	for(int i = 1, j = len; i < j; ++ i, -- j)	swap(s[i], s[j]);
	for(int i = 1; i <= len; ++ i){
		if(s[i] >= '0' && s[i] <= '9')	num[i] = s[i] - '0';
		else	num[i] = s[i] - 'A' + 10;
	}
	return dfs(len, true, true, 0, 0);
}

int main(){
	scanf("%s", s + 1);
	cin >> k;
	memset(dp, -1, sizeof dp);
	cout << solve();
	return 0;
}

//CODE YOUR WAY ;) -->>

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

#define ll long long int
#define Loopi for(ll i=0;i<n;i++)
#define Loopj for(ll j=0;j<m;j++)
#define LoopLR(l,r) for(ll i=l;i<=r;i++)
#define pb push_back
#define Umap unordered_map<ll,ll> M
#define Omap map<int,int> M;
#define read(a,n) Loopi{  cin>> a[i];  }
#define print(a,n) Loopi{  cout<<a[i]<<" ";  }
#define findsum(a,n) Loopi{  sum+=a[i];  }

void Doit()
{
ll n;
cin>>n;
ll a[n];
read(a,n);
ll max=0;
ll min=1000000000000000000;
for(int i=0;i<n;i++)
{
    //max=a[i];
    min=INT_MAX;
    if(min>a[i])
    min=a[i];
    for(int j=i;j<n;j++)
    {
      if(min>a[j])
      min=a[j];
      ll x=min*(j-i+1);
      if(max<x)
      max=x;

    }
}
cout<<max<<endl;
}

int main()
{

ios::sync_with_stdio(false);
cin.tie(NULL);

// ll t;
// cin>>t;

// while(t--)
// {
    Doit();
// }

}


#include<bits/stdc++.h>
#define pb       push_back
#define f        first
#define s       second
#define pi       acos(-1.0)
#define mod      1000000007
#define test     int t; cin>>t ;while(t--)
typedef long long ll;
using namespace std;

int main()
{

      ll a,b,c,d;
      cin>>a>>b>>c>>d;

       double ans;
      ans=(1.*b*(c-a))/(d+b);
      ans+=a;
      printf("%.10lf",ans);

     return 0;

}

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

int main() {
    int sx, sy, gx, gy;
    double res, slope;
    cin >> sx >> sy >> gx >> gy;
    // gのy座標を反転
    gy = -gy;
    // グラフの傾きの逆数 * -1
    slope = -(double)(sx - gx) / (double)(sy - gy);
    res = (double)sx + (double)sy * slope;
    cout << fixed << setprecision(10) << res << endl;
    return 0;
}


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

int Solve(int n, string s)
{
  string t = "";
  for (int i = 0; i < n; ++i)
  {
    t += s[i];
    if (3 <= t.size())
    {
      if (t.substr(t.size() - 3, 3) == "fox")
      {
        for (int i = 0; i < 3; ++i) t.pop_back();
      }
    }
  }
  return t.size();
}

int main() {
  int n;
  string s;
  cin >> n >> s;
  cout << Solve(n, s) << endl;
  return 0;
}

#include <iostream>

using namespace std;

int main()
{
    int N;
    cin>>N;
    int a[N];
    int b[N];
    int c[N];
    int k=0;
    for(int i=0;i<N;i++)
    {
        cin>>a[i];
    }
    for(int i=0;i<N;i++)
    {
        cin>>b[i];
    }
    for(int i=0;i<N;i++)
    {
        c[k]=a[i]*b[i];
        k++;
    }
    int sum=0;
    for(int i=0;i<N;i++)
    {
        sum=sum+c[i];
    }
    if(sum==0)
    {
        cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }
}


#include <bits/stdc++.h>

using namespace std;

const int inf = numeric_limits<int> :: max() / 2;

class dsu {
    private:
    vector<int> par;

    public:
    dsu(int N) : par(N) {
        iota(par.begin(), par.end(), 0);
    }

    int find(int x) {
        return x == par[x] ? x : par[x] = find(par[x]);
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }

    void Union(int x, int y) {
        if(same(x, y)) {
            return;
        }

        x = find(x);
        y = find(y);
        par[x] = y;
    }
};

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

    int n, m;
    cin >> n >> m;

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

    vector<bool> row(n);
    vector<bool> col(m);
    row[0] = row[n - 1] = true;
    col[0] = col[m - 1] = true;
    for (int i = 0; i < n; ++i) {
        if (s[i][0] == '#' || s[i][m - 1] == '#') {
            row[i] = true;
        }
    }
    for (int i = 0; i < m; ++i) {
        if (s[0][i] == '#' || s[n - 1][i] == '#') {
            col[i] = true;
        }
    }

    int ans = inf;

    dsu dsu(n + m);

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            if (s[i][j] == '#') {
                dsu.Union(i, j + n);
            }
        }
    }

    dsu.Union(0, n - 1);
    dsu.Union(n, n + m - 1);
    dsu.Union(n - 1, n);

    int tc = 0;
    for (int i = 0; i < m; ++i) {
        bool same = false;
        for (int j = i + 1; j < m; ++j) {
            if (dsu.same(i + n, j + n)) {
                same = true;
            }
        }
        if (!same) {
            tc ++;
        }
    }

    int tr = 0;
    for (int i = 0; i < n; ++i) {
        bool same = false;
        for (int j = i + 1; j < n; ++j) {
            if (dsu.same(i, j)) {
                same = true;
            }
        }
        if (!same) {
            tr ++;
        }
    }

    cout << min(tr, tc) - 1 << '\n';

    return 0;
}


/*
    More power comes with more responsibilities.

        _.-;;-._.-;;
    '-..-'|   ||   |
    '-..-'|_.-;;-._|
    '-..-'|   ||   |
    '-..-'|_.-''-._|

*/
#define SUP ios::sync_with_stdio(0); cin.tie(0);

#include <bits/stdc++.h>
#include <iostream>
#define ll long long
#define ull unsigned long long
#define modulo 10000003
#define br "\n"
#define pb push_back
using namespace std;

int main()
{
	SUP
    int t; cin >> t;
    while(t--)
    {
        int l, r; cin >> l >> r;
        ll ans=0;
        ans = max(0, (r-l+1)-l);
        ans = ans*(ans+1)/2;
        cout << ans << br;
    }
    return 0;
}

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n) for (int i=1; i < (int)(n); i++)
#define rrep(i, n) for (int i=((int)(n)-1); i>=0; i--)
#define rreps(i, n) for (int i=((int)(n)-1); i>0; i--)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
using lint = long long;
using p = pair<int, int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
  lint T; cin >> T;
  lint l, r;
  rep (i, T) {
    cin >> l >> r;
    if (2*l > r) {
      cout << 0 << endl;
      continue;
    } else {
      cout << (r-2*l+2)*(r-2*l+1) / 2 << endl;
      continue;
    }
  }
  return 0;
}


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

//0-indexed
template<class T, T (*op)(T,T), T(*e)()>
class segtree
{
private:
    int n;
    vector<T> v;
public:
    segtree(int n_)
    {
        int x = 1;
        while (n_ > x) x <<= 1;
        n = x;
        v.resize(2 * n - 1, e());
    }

    void set(int k, T x)
    {
        k += n - 1;
        v[k] = x;
        while (k > 0)
        {
            k = (k - 1) / 2;
            v[k] = op(v[k*2+1],v[k*2+2]);
        }
    }
    T get(int k) { return v[k + n - 1]; }

    //[a,b)
    T query(int a, int b) { return query_sub(a, b, 0, 0, n); }
    T query_sub(int a, int b, int k, int l, int r) {
        if (b <= l || r <= a) return e();
        if (a <= l && r <= b) return v[k];
        T c1 = query_sub(a, b, 2 * k + 1, l, (l + r) / 2);
        T c2 = query_sub(a, b, 2 * k + 2, (l + r) / 2, r);
        return op(c1,c2);
    }

    //display segtree value
    void display(string text = "segtree value")
    {
        cout << text << endl;
        int cnt = 0;
        int end = 1 << cnt;
        int l = v.size();
        for (int i = 0; i < l; ++i)
        {
            cout << v[i] << " ";
            if (i == end - 1)
            {
                ++cnt;
                end += 1<<cnt;
                cout << endl;
            }
        }
        cout << endl;
    }
};

int op(int a, int b) { return a ^ b; }
int e() { return 0; }

int main()
{
	int n,q;
    cin >> n >> q;
    segtree<int,op,e> sg(n);
    rep(i, n)
    {
        int ai; cin >> ai;
        sg.set(i,ai);
    }
    rep(i, q)
    {
        int t, x, y;
        cin >> t >> x >> y;
        --x;
        if (t == 1) sg.set(x, op(sg.get(x), y));
        else printf("%d\n", sg.query(x,y));
    }
	return 0;
}

#include<bits/stdc++.h>
#define ll long long int
#define deb1(x) cout<<#x<<" :: "<<x<<"\n";
#define deb2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define deb3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";
ll mod=1e9+7;
using namespace std;
ll a[1000000],seg[2*1000000];
ll make(ll ind,ll low,ll high){
if(low==high){
seg[ind]=a[low];
return seg[ind];
}
ll mid=(low+high)/2;
ll left=make(2*ind+1,low,mid);
ll right=make(2*ind+2,mid+1,high);
seg[ind]=left^right;
//cout<<ind<<"--"<<seg[ind]<<endl;
return seg[ind];
}
ll query(ll ind,ll low,ll high,ll l, ll r){
if(l<=low && r>=high){

return seg[ind];
}
if(high<l || low>r)return 0;
ll mid=(low+high)/2;
ll left=query(2*ind+1,low,mid,l,r);
ll right=query(2*ind+2,mid+1,high,l,r);
return left^right;
}
ll update(ll ind,ll low,ll high,ll l, ll r){
//cout<<low<<" "<<high<<endl;
if(high<l || low>l){
return seg[ind];
}

if(low==l && high==l){
seg[ind]=seg[ind]^r;
return seg[ind];
}
ll mid=(low+high)/2;
ll left=update(2*ind+1,low,mid,l,r);
ll right=update(2*ind+2,mid+1,high,l,r);
seg[ind]=left^right;
return seg[ind];
}

int main(){
     ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
     ll n,m,fl=0;
    cin>>n>>m;
    for(ll i=0;i<n;i++){
    cin>>a[i];
    }
    make(0,0,n-1);
    ll s,l,r,u;
    for(ll i=0;i<m;i++){
    cin>>u>>l>>r;
    if(u==1){
    update(0,0,n-1,l-1,r);
    }
    else{
    ll ans=query(0,0,n-1,l-1,r-1);
    cout<<ans<<endl;
    }

    }

    }


#include <algorithm>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n, s) for (int i = (s); i < (n); i++)
#define rrep(i, n) for (int i = (n - 1); i >= 0; i--)
#define rreps(i, n, s) for (int i = s; i >= n; i--)

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<ll> p(n);
    map<int, int> m;
    rep(i, n) {
        cin >> p[i];
        p[i]--;
        m[p[i]] = i;
    }
    vector<int> res;
    vector<bool> done(n, false);
    rep(k, n) {
        if (m[k] != k) {
            while (m[k] != k) {
                ll right = m[k];
                ll left = right - 1;
                if (done[left]) break;
                done[left] = true;
                swap(p[right], p[left]);
                m[p[right]] = right;
                m[p[left]] = left;
                res.pb(left);
            }
        }
    }

    bool ok = true;
    rep(i, n - 1) {
        if (p[i + 1] < p[i]) {
            ok = false;
            break;
        }
    }
    if (res.size() != n - 1) { ok = false; }
    if (ok) {
        for (auto idx : res) cout << idx + 1 << endl;
    } else {
        cout << -1 << endl;
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(int i=0;i<n;i++)
#define ALL(v) v.begin(),v.end()
constexpr ll MOD=998244353;
constexpr ll INF=1e18;

struct BIT {
	int N;
	VI dat;
	BIT(int N):N(N){
		dat.resize(N+1,0);
	}
	ll sum(int k) {
		k++;
		if(k==0)
			return 0;
		ll res=0;
		for(;k>0;k-=k&-k)
			res+=dat[k];
		return res;
	}
	ll sum(int l, int r){
		return sum(r)-sum(l-1);
	}
	void add(int k, ll x) {
		k++;
		for(;k<=N;k+=k&-k)
			dat[k]+=x;
	}
	int lowerBound(int w) {
		if (w<=0) return 0;
		int x=0;
		int k=1;
		while(k*2<=N) k*=2;
		for(;k>0;k/=2){
			if(x+k<=N&&dat[x+k]<w){
				w-=dat[x+k];
				x+=k;
			}
		}
		return x;
	}
};

int main(){
	int n; cin >> n;
	VI p(n); REP(i,n) cin >> p[i];
	BIT bt(n);
	VI a(n,0);
	REP(i,n){
		a[p[i]-1]=i;
	}
	set<int> st;
	vector<int> ans(0);
	bool no=0;
	for(int i=n-1;i>=0;i--){
		for(int j=a[i]-bt.sum(a[i]);j<i;j++){
			if(st.count(j)){
				no=1;
				break;
			}
			st.insert(j);
			ans.push_back(j);
		}
		bt.add(a[i],1);
	}
	if(no||ans.size()!=n-1)
		cout << -1 << endl;
	else{
		REP(i,n-1)
			cout << ans[i]+1 << endl;
	}
	return 0;
}