#define BUG
#include <bits/stdc++.h>

using namespace std;

#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fi first
#define se second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fore(i, a, b) for (int i = (a), _b = (b); i < _b; ++i)
#define fort(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define ford(i, a, b) for (int i = (a), _b = (b); i >= _b; --i)
#ifdef BUG
#define bug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << ": " << arg1 << '\n';
}
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...);
}
#endif

template <class T> bool mini(T& a, T b) { return a > b ? (a = b, 1) : 0; }
template <class T> bool maxi(T& a, T b) { return a < b ? (a = b, 1) : 0; }

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vii> vvii;

const int INF = (int)1e9 + 7;

int main() {
#ifdef LOCAL
    freopen("CP.inp", "r", stdin);
//    freopen("CP.out", "w", stdout);
#endif // LOCAL
    ios_base::sync_with_stdio(0); cin.tie(0);
    int h, w, a, b; cin >> h >> w >> a >> b;
    const int N = 2e5 + 3;
    const ll M = 1e9 + 7;
    auto mpow = [&](ll a, ll b) {
        ll res = 1;
        for (a %= M; b; a = a * a % M, b >>= 1) if (b & 1) res = res * a % M;
        return res;
    };
    vi fac(N), inv(N);
    fac[0] = 1;
    fore(i, 1, N) fac[i] = fac[i - 1] * i % M;
    inv[N - 1] = mpow(fac[N - 1], M - 2);
    ford(i, N - 2, 0) inv[i] = inv[i + 1] * (i + 1) % M;
    auto C = [&](int n, int k) {
        return fac[n] * inv[n - k] % M * inv[k] % M;
    };
    ll ans = 0;
    fort(i, b + 1, w) {
        (ans += C(h - a - 1 + i - 1, i - 1) * C(w - i + a - 1, w - i)) %= M;
    }
    cout << ans << '\n';
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define U 998244353
#define N 1000005
#define int long long
#define sz(c) (int)c.size()
#define fr first
#define ll long long
#define sc second
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a ; i<n ; i++)
#define r0 return 0;
#define endl '\n'
#define INF (int)1e15

/* Debug Begins */
# define trace(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
  stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
string to_string(char c) { return "'" + string(1, c) + "'";}
string to_string(string s) { return '"' + s + '"';}
string to_string(bool f) { if(f) return "True"; else return "False";}
string to_string(const char* s) { return to_string((string) s);}
template<typename A> string to_string(A);
template<typename A, typename B> string to_string(pair<A, B> p){
  return "(" + to_string(p.first) + ": " + to_string(p.second) + ")";}
template<typename A> string to_string(A v) {bool f = false; string r = "{";
  for (auto x: v) {if (f) r += ", "; r += to_string(x); f = true;} return r += "}";}
template<typename A> string to_string(vector<vector<A>> v) {string r;
  for (auto x: v) r += "\n" + to_string(x); return r;}
int Nerr;
template<typename A> string to_string(A *p) {return to_string(vector<A>(p, p + Nerr));}
void err(istream_iterator<string>) { cerr << endl; }
template<typename T,typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << to_string(a) << "; "; err(++it, args...); }
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
#define Lu(...) [&] (auto &&u) { return __VA_ARGS__; }
#define Luv(...) [&] (auto &&u, auto &&v) { return __VA_ARGS__; }
/***************************************************************/

int fact[N];
int power(int x, unsigned int y, unsigned int m)
{
    if (y == 0)
        return 1;
    int p = power(x, y/2, m) % m;
    p = (p *1ll* p) % m;
    return (y%2 == 0)? p : (x *1ll* p) % m;
}
int ncr(int n, int r){
    int ans = fact[n];
    ans = (ans * power(fact[n-r], M-2,M)) % M;
    ans = (ans * power(fact[r], M-2,M)) % M;
    return ans;
}
int find_ans(int i1, int j1, int i2, int j2){
    return ncr(i2-i1+j2-j1,i2-i1);
}

signed main()
{
    ios_base::sync_with_stdio(0);
    int TESTS=1;
    fact[0] = 1;
    rep(i,1,N) fact[i] = (fact[i-1] * i) % M;
    // cin>>TESTS;
    while(TESTS--)
    {
        int h,w,a,b;
        cin >> h >> w >> a >> b;
        int ans = 0;
        rep(i,1,h-a+1){
            int ni = i;
            int nj = b;
            // trace(ni, nj);
            ans = (ans + find_ans(1,1,ni,nj) * find_ans(ni,nj+1,h,w)) % M;
        }
        cout << ans << endl;
    }

}


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

int main(){
    int k;
    string s;
    cin >> k >> s;
    if(s.length() <= k){
        cout << s << endl;
    }else if(s.length() > k){
        rep(i,k){
        cout << s[i] ;
        }
        cout << "..." << endl;
    }
}

#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
#include <list>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

long long fac[MAX], finv[MAX], inv[MAX];

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

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
long long gcd(long long x, long long y){
    if(y==0) return x;
    else return gcd(y,x%y);
}
//最小公倍数
long long lcm(long long x, long long y){
    return x / gcd(x, y) * y;
}
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    int K,X; cin >> K >> X;
    int a=X-K+1;
    if(K==1){
        cout << X << endl;
        return 0;
    }
    for(int i=a;i<X+K;i++){
        cout << i << " ";
    }
    return 0;
}


#include <stdio.h>
#include <vector>

int judge( const int* number_table1 , const int* number_table2 )
{
	const int right_side_table[ 6 ][ 6 ] =
	{
		//front=
		// 1    2    3    4    5    6
		{ -1 ,  3 ,  5 ,  2 ,  4 , -1 },	//top=1
		{  4 , -1 ,  1 ,  6 , -1 ,  3 },	//2
		{  2 ,  6 , -1 , -1 ,  1 ,  5 },	//3
		{  5 ,  1 , -1 , -1 ,  6 ,  2 },	//4
		{  3 , -1 ,  6 ,  1 , -1 ,  4 },	//5
		{ -1 ,  4 ,  2 ,  5 ,  3 , -1 },	//6
	};

	for( int top = 0 ; top < 6 ; top++ )
	{
		for( int front = 0 ; front < 6 ; front++ )
		{
			int right = right_side_table[ top ][ front ] - 1;
			if( right < 0 )
			{
				continue;
			}
			if( number_table1[ 0 ] != number_table2[ top ] )
			{
				continue;
			}
			if( number_table1[ 1 ] != number_table2[ front ] )
			{
				continue;
			}
			if( number_table1[ 2 ] != number_table2[ right ] )
			{
				continue;
			}
			if( number_table1[ 3 ] != number_table2[ 5 - right ] )
			{
				continue;
			}
			if( number_table1[ 4 ] != number_table2[ 5 - front ] )
			{
				continue;
			}
			if( number_table1[ 5 ] != number_table2[ 5 - top ] )
			{
				continue;
			}
			return 1;
		}
	}
	return 0;
}

struct NumberTableEntry
{
	int table[ 6 ];
};
typedef std::vector<NumberTableEntry> NumberTable;

int main( int argc , char** argv )
{
	NumberTable number_table;

	int data_size;
	scanf( "%d" , &data_size );
	number_table.reserve( data_size );

	for( int i = 0 ; i < data_size ; i++ )
	{
		NumberTableEntry entry;
		scanf( "%d %d %d %d %d %d" ,
			&entry.table[ 0 ] ,
			&entry.table[ 1 ] ,
			&entry.table[ 2 ] ,
			&entry.table[ 3 ] ,
			&entry.table[ 4 ] ,
			&entry.table[ 5 ] );

		number_table.push_back( entry );
	}

	for( NumberTable::const_iterator itr = number_table.begin() ; itr != number_table.end() ; itr++ )
	{
		NumberTable::const_iterator itr2 = itr;
		itr2++;

		for( ; itr2 != number_table.end() ; itr2++ )
		{
			if( judge( &itr->table[ 0 ] , &itr2->table[ 0 ] ) )
			{
				printf( "No\n" );
				return 0;
			}
		}
	}
	printf( "Yes\n" );
	return 0;
}

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

int main(){
  string str;

  while(getline(cin,str)){
    int flg = 0;

    while(true){
      for(int i = 0 ; i < str.length() ; i++){
	string key1 = str.substr(i,3),key2 = str.substr(i,4);
	if(key1 == "the" || key2 == "that" || key2 == "this") flg = 1;
      }

      if(flg) break;
      else{
	for(int j = 0 ; j < str.length() ; j++){
	  if('a' <= str[j] && str[j] <= 'z'){
	    str[j] -= 'a' - 'A';
	    str[j] = (char)('A'+(str[j]-'A'+26+1)%26);
	    str[j] += 'a' - 'A';
	  }
	  else continue;
	}
      }
    }
    cout << str << endl;
  }

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define deb(x) cout<< #x << " " << x << "\n";
#define MAX 9223372036854775807
#define MIN -9223372036854775807
#define PI 3.141592653589
#define setbits(n) __builtin_popcountll(n)
const ll mod=1e9+7;

const int N=1e5+1;
ll dp[N][101][2],d,n;
string s;

ll go(ll pos, ll k, ll mx){
    if(pos==n){
        if(k==0) return 1;
        else return 0;
    }
    if(dp[pos][k][mx]!=-1)
        return dp[pos][k][mx];
    ll ans=0,lim=s[pos]-'0';
    if(mx==0) lim=9;
    for(int i=0;i<lim;i++)
        ans=(ans+go(pos+1,(k+i)%d,0))%mod;
    if(mx==1) ans=(ans+go(pos+1,(k+lim)%d,1))%mod;
    else ans=(ans+go(pos+1,(k+lim)%d,0))%mod;
    return dp[pos][k][mx]=ans;
}

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll T=clock();

    cin>>s;
    cin>>d;
    n=s.size();
    memset(dp,-1,sizeof(dp));
    cout<<(go(0,0,1)-1+mod)%mod;

    cerr<<"\n\nTIME: "<<(double)(clock()-T)/CLOCKS_PER_SEC<<" sec\n";
    T = clock();
    return 0;
}

#include "bits/stdc++.h"

using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define int ll
typedef pair<int,int> pii;
#define fi first
#define se second
#define Sort(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++)
#define REP(i,n) for(int i = 0;i < (n) ; i++)
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/4
#define INTINF INT_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
template<class T> inline bool chmax(T &a, T b){if(a < b){a = b;return true;}return false;}
template<class T> inline bool chmin(T &a, T b){if(a > b){a = b;return true;}return false;}
/*----------------------------------------------------------------*/
// const int MOD = 998244353;
const int MOD = 1000000007;

/*----------------------------------------------------------------*/
signed main(){

	int n;
	cin >> n;

	cout << 0 << endl;
	string s1;
	cin >> s1;
	if(s1 == "Vacant")return 0;
	string x = s1;
	int S = 0;
	int G = n-1;

	while(1){
		int nx = (S+G)-(S+G)/2;
		cout << nx << endl;
		string s;
		cin >> s;
		if(s == "Vacant")return 0;
		if((s == x && S%2 == nx%2) || (s != x && S%2 != nx%2)){
			S = nx;
			x = s;
		}else{
			G = nx-1;
		}
	}

	return 0;
}
/*----------------------------------------------------------------*/

// g++ -std=gnu++17 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// rm -r -f test;oj dl https://code-festival-2017-qualb.contest.atcoder.jp/tasks/code_festival_2017_qualb_b
// rm -r -f test;oj dl https://abc146.contest.atcoder.jp/tasks/abc146_d


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

#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << ", " << #y << "=" << y << endl

void solve() {
  ll n;
  cin >> n;
  ll sm = 0;
  for (int i = 1; i <= n; i++) {
    if (i % 3 == 0 || i % 5 == 0)
      continue;
    sm += i;
  }
  cout << sm << '\n';
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  ll test = 1;
  // cin >> test;
  while (test--) {
    solve();
  }
  return 0;
}


#include <bits/stdc++.h>
#include <string>
//#define local
#ifdef local
#include "dbg-macro/dbg.h"
#endif
#define ll long long
#define pi (acos(-1))
#define rep(i, n) for (unsigned long long i = 0; i < (unsigned long long)(n); ++i)
using namespace std;
std::vector<unsigned ll> genprimevec(const unsigned ll N);

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> wavec(n, 0);
    vector<bool> aced(n, false);
    ll ac = 0;
    ll wa = 0;
    while (m--)
    {
        int p;
        string s;
        cin >> p >> s;
        if (aced[p]) { continue; }
        if (s == "AC")
        {
            aced[p] = true;
            ++ac;
            wa += wavec[p];
        }
        else
        {
            wavec[p]++; // WA
        }
    }

    cout << ac << ' ' << wa << endl;
    return 0;
}

ll extgcd(ll a, ll b, ll &x, ll &y)
{
    if (b == 0)
    {
        x = 1, y = 0;
        return a;
    }
    ll d = extgcd(b, a % b, y, x);
    y -= a / b * x;
    return d;
}

std::vector<unsigned ll> genprimevec(const unsigned ll N)
{
    std::vector<bool> is_prime(N + 1);
    for (unsigned ll i = 0; i <= N; i++) { is_prime[i] = true; }
    std::vector<unsigned ll> P;
    for (unsigned ll i = 2; i <= N; i++)
    {
        if (is_prime[i])
        {
            for (unsigned ll j = 2 * i; j <= N; j += i) { is_prime[j] = false; }
            P.emplace_back(i);
        }
    }
    return P;
}

/***
coded by adarsh
***/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vec;
typedef vector<vector<ll>> vec2;
typedef pair<ll,ll> pair1;
typedef pair<string,ll> pair2;
typedef pair<ll,string> pair3;
typedef pair<string,string> pair4;
#define fl(i,a,b) for(i=a;i<b;i++)
#define rfl(i,a,b) for(i=b-1;i>=a;i--)
#define f first
#define s second

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,m,i;cin>>n>>m;
    map<ll,ll> b;
    set<ll> a;ll c=0;
    fl(i,0,m)
    {
        ll p;string s;
        cin>>p>>s;
        if(a.count(p)==0&&s=="WA")
        {
            b[p]++;
        }
        else if(a.count(p)==0&&s=="AC")
        {
            c+=b[p];
            a.insert(p);
        }
    }
    cout<<a.size()<<" "<<c;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#define PI 3.141592653589793
using namespace std;
int main(){
	int n;
	string str;
	cin>>n;
	for(int i=0;i<n;i++){
		int cnt=0,num=0;
		int rui[5]={0};
		while(cin>>str){
			if(str=="HIT"){
				rui[4]=rui[3];
				rui[3]=rui[2];
				rui[2]=rui[1];
				rui[1]=1;
				if(rui[4]==1){
					rui[4]=0;
					cnt++;
				}
			}else if(str=="HOMERUN"){
				for(int j=1;j<=3;j++){
					if(rui[j]==1){
						rui[j]=0;
						cnt++;
					}
				}
				cnt++;
			}else{
				num++;
				if(num==3)break;
			}
		}
		cout<<cnt<<endl;
	}
	return 0;
}

#include<iostream>
#include<string>
using namespace std;
int main(){
  int n;
  cin>>n;
  string event;
  getline(cin,event,'\n');
  int i=0,out,b,score;
  while(n>0){
    out = 0;
    b = 0;
    score=0;
    while(out<3){
      getline(cin,event,'\n');
      if(event=="HIT"){
	b*=2;
	b+=1;
	if(b>8){
	  b-=8;
	  score++;
	}
      }
      if(event=="HOMERUN"){
	while(b>0){
	  score+=b%2;
	  b/=2;
	}
	score++;
      }
      if(event=="OUT"){
	out++;
      }
    }
    cout<<score<<endl;
    n--;
  }
  return 0;
}


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

using namespace std;

void darts();

void longest_dis();

void sum_of_three_integers();

void otoshidama();

int main()
{
  //darts();
  //longest_dis();
  //sum_of_three_integers();
  otoshidama();
}

void darts()
{
  while (true)
  {
    int n, m;
    cin >> n >> m;

    // stop cond
    if (n == 0) break;

    vector<int> p(n);
    for (int i = 0; i < n; ++i) cin >> p[i];

    // 2 darts combination
    // p = q, 0, p + q
    vector<int> q = p;
    q.push_back(0);
    for (int i = 0; i < n; ++i)
    {
      for (int j = 0; j <= i; ++j)
      {
        q.push_back(p[i] + p[j]);
      }
    }

    sort(q.begin(), q.end());

    // q's size = 1 + n + n(n + 1) / 2
    //cout << q.size() << "\n";
    //for (auto x : q) cout << x << " ";

    int ret = 0;
    int j = q.size() - 1;
    //i:q linear scan
    for (int i = 0; i < q.size(); ++i)
    {
      if (q[i] > m) break;
      while (q[i] + q[j] > m) --j;
      ret = max(ret, q[i] + q[j]);
    }

    cout << ret << "\n";
  }
}

void longest_dis()
{
  int n;
  cin >> n;

  vector<pair<int, int>> p(n);
  for (int i = 0; i < n; ++i) cin >> p[i].first >> p[i].second;

  double v_max = 0.0;
  for (int i = 0; i < n; ++i)
  {
    for (int j = 0; j < n; ++j)
    {
      if ((p[i].first - p[j].first) * (p[i].first - p[j].first)
        + (p[i].second - p[j].second) * (p[i].second - p[j].second)
        >  v_max * v_max)
      {
        v_max = sqrt((p[i].first - p[j].first) * (p[i].first - p[j].first)
          + (p[i].second - p[j].second) * (p[i].second - p[j].second));
      }
    }
  }

  cout << v_max << "\n";
}

void sum_of_three_integers()
{
  int k, s;
  cin >> k >> s;

  int cnt = 0;
  //for (int i = 0; i <= k; ++i)
  //{
  //  for (int j = 0; j <= k; ++j)
  //  {
  //    for (int m = 0; m <= k; ++m)
  //    {
  //      if (i + j + m == s) ++cnt;
  //    }
  //  }
  //}
  for (int i = 0; i <= k; ++i)
  {
    for (int j = 0; j <= k; ++j)
    {
      int m = s - i - j;
      if (0 <= m && m <= k) ++cnt;
    }
  }

  cout << cnt << "\n";
}

void otoshidama()
{
  int n, Y;
  cin >> n >> Y;

  for (int x = 0; x <= n; ++x)
  {
    for (int y = 0; x + y <= n; ++y)
    {
      int z = n - x - y;
      if (x * 10000 + y * 5000 + z * 1000 == Y)
      {
        cout << x << " "<< y << " " << z << "\n";
        return;
      }
    }
  }

  cout << "-1 -1 -1\n";
}

#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
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(){
	int n,y;
	cin >> n >> y;

	for(int i=0; i<=n; i++){
		for(int j=0; j<=n; j++){
			int k = n - (i+j);
			if(k < 0) continue;
			if(y == 10000*i + 5000*j + 1000*k){
				printf("%d %d %d\n",i,j,k);
				return 0;
			}
		}
	}

	printf("-1 -1 -1\n");

	return 0;
}


#include <iostream>
#include <cctype>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <queue>
#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

#include <set>

using namespace std;

char encode(int n){
  if(n < 26) return 'a' + n;
  return 'A' + n - 26;
}

int decode(char c){
  if(islower(c)) return c - 'a';
  return c - 'A' + 26;
}

int main(){
  while(const int n = getInt()){
    vector<int> v(n);
    REP(i,n) v[i] = getInt();

    char buff[256];
    scanf("%s", buff);

    for(char *s = buff; *s; s++){
      cout << encode((decode(*s) + 52 - v[(s - buff) % v.size()]) % 52);
    }
    cout << endl;
  }
  return 0;
}

#include <iostream>
#include <set>

using namespace std;

int main()
{
	int n, k, a[11], b[11];
	while(1)
	{
		set<int> s;
		cin >> n >> k;
		if(n==0 && k==0) break;
		else
		{
			for(int i=0; i<n; i++)
			{
				cin >> a[i];
				if(a[i]>9) b[i]=2;
				else b[i]=1;
			}
			for(int i=0; i<n; i++)
			{
				int x=0;
				x=a[i];
				x*=10;
				for(int j=0; j<n; j++)
				{
					int y=x;
					if(j==i) continue;
					if(b[j]==2) y*=10;
					y+=a[j];
					if(k==2) s.insert(y);
					y*=10;
					for(int l=0; l<n; l++)
					{
						int z=y;
						if(l==i || l==j) continue;
						if(b[l]==2) z*=10;
						z+=a[l];
						if(k==3) s.insert(z);
						z*=10;
						for(int m=0; m<n; m++)
						{
							int w=z;
							if(m==i || m==j || m==l) continue;
							if(b[m]==2) w*=10;
							w+=a[m];
							if(k==4) s.insert(w);
						}
					}
				}
			}
			cout << s.size() << endl;
		}
	}
	return 0;
}


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

#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define MP make_pair
#define pb push_back
#define ff first
#define ss second
#define sz(x) x.size()
#define all(c) c.begin(),c.end()
#define int long long
#define fr(i,j,x) for(int i=j;i<x;i++)
#define rep(i,j,x) for(int i=j;i<=x;i++)
#define mem(x,val) memset(x,val,sizeof(x))
//#define endl '\n'
#define vi vector<int>
#define pii pair<int,int>
#define piii pair<int,pii>

const int mod=1e9+7;
const int N=1e5+10;
const int MAXN=2e6+10;
const int INF=1e18;

string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A> string to_string(A);
template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A> string to_string(A v) {bool f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cerr << " " << to_string(H); debug_out(T...);}
#define pr(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

int a[N];

string getbase(int x,int b){
    string ans;
    int d;
    while(x){
        d=x%b;
        ans=char('0'+d)+ans;
        x/=b;
    }
    return ans;
}

string L,R;
int d,dp[10010][2][2][101];

int rec(int ind,int tlo,int thi,int rem){
    if(ind>=L.length()){
        if(rem==0){
            return 1;
        }
        return 0;
    }
    if(dp[ind][tlo][thi][rem]==-1){
        int blo=0;
        int bhi=9;
        if(tlo){
            blo=L[ind]-'0';
        }
        if(thi){
            bhi=R[ind]-'0';
        }
        int ans=0;
        for(int i=blo;i<=bhi;i++){
            int ntlo=tlo;
            int nthi=thi;
            if(i>L[ind]-'0'){
                ntlo=0;
            }
            if(i<R[ind]-'0'){
                nthi=0;
            }
            ans+=rec(ind+1,ntlo,nthi,(rem+i)%d);
            ans%=mod;
        }
        dp[ind][tlo][thi][rem]=ans;
    }
    return dp[ind][tlo][thi][rem];
}

void solve(){
    string l,r;
    l="1";
    cin>>r>>d;
    L=l;
    R=r;
    reverse(all(L));
    reverse(all(R));
    while(L.length()<R.length()){
        L+='0';
    }
    while(L.length()>R.length()){
        R+='0';
    }
    reverse(all(L));
    reverse(all(R));
    mem(dp,-1);
    cout<<rec(0,1,1,0)<<endl;
}

int32_t main()
{
    // #ifndef ONLINE_JUDGE
    //     freopen("inputf.in", "r", stdin);
    //     //freopen("outputf.in", "w", stdout);
    // #endif
    SPEED;
    int T=1;
    //cin>>T;
    int t1=1;
    while(true)
    {
        //cout<<"Case #"<<t1<<": ";
        solve();
        t1++;
        if(t1>T)
            break;
    }
}

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    const int mod=1000000007;
    string k;
    int d;
    cin >> k >> d;
    int n=k.size();
    vector<int> now(d,0);
    int val=0;
    for(int i=0;i<n;i++)
    {
        vector<int> nxt(d,0);
        int x=(k[i]-'0');
        for(int a=0;a<x;a++) nxt[(val+a)%d]=(nxt[(val+a)%d]+1)%mod;
        val=(val+x)%d;
        for(int j=0;j<d;j++)
        {
            for(int a=0;a<=9;a++) nxt[(j+a)%d]=(nxt[(j+a)%d]+now[j])%mod;
        }
        now=nxt;
    }
    cout << (now[0]+(val==0)-1+mod)%mod << "\n";
    return 0;
}


#include <iostream>
using namespace std;
int main(){
	char c[21];
	int n = 0;
	while(cin >> c[n]){n++;}
	for(int i=n-1;i>=0;i--) cout << c[i];
	cout << endl;
}

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
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(){
  int a, b; cin >> a >> b;
  int num = 1, cnt = 0;
  while(num < b){
      num += a - 1;
      cnt++;
  }
  cout << cnt << ln;
}


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

using namespace std;
typedef long long ll;
ll a[1005][1005];
int n;
int pri[10005],tot;
bool mk[10005];
ll lcm(ll a,ll b) {
	if((!a)||(!b)) return a+b;
	return 1ll*a/__gcd(a,b)*b;
}
int main() {
	scanf("%d",&n);
	if(n==2) {
		printf("4 7\n23 10");
		return 0;
	}
	mk[1] = mk[0] = 1;
	for(int i=2;i<=10000;i++) {
		if(!mk[i]) { pri[++tot]=i; }
		if(tot==1000) break;
		for(int j=1;j<=tot&&1ll*pri[j]*i<=10000;j++) {
			int k = pri[j] * i;
			mk[k] = 1;
			if(i%pri[j]==0) break;
		}
	}
	for(int i=1;i<=n;i++) {
		for(int j=1;j<=n;j++) {
			if((i+j)%2==0) a[i][j] = pri[(i + j) / 2] * pri[n+((i-j)/2+(n+1)/2)];
		}
	}
	for(int i=1;i<=n;i++) {
		for(int j=1;j<=n;j++) {
			if((i+j)%2==1) a[i][j] = lcm( lcm(a[i-1][j],a[i+1][j]),lcm(a[i][j-1],a[i][j+1]) ) + 1;
			printf("%lld ",a[i][j]);
		}
		puts("");
	}
}

#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
struct item{
    string name;
    int p,s1,s2,x,r,m;
    double y;
    item(){
        int a,b,c,d,e;
        cin>>name>>p>>a>>b>>c>>d>>e>>x>>r>>m;
        s1=a+b+c;s2=d+e;
        y=(double)(x*r*m-p)/(s1+s2*m);
    }
};

int main(){
    int n;
    while(cin>>n,n){
        vector<item> v(n);
        sort(all(v),[](item a, item b){return a.y>b.y || (a.y==b.y && a.name<b.name);});
        for(auto p : v)cout<<p.name<<endl;
        cout<<"#"<<endl;
    }
}


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

int w, h;
int map[20][20];
int ans = 11;
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, -1, 1};

int dfs(int x, int y, int move){
//	printf("x:%d y:%d move:%d\n", x, y, move);
	if(move == 11) return 0;
	for(int i=0; i<4; i++){
//		printf(" direction:%d\n", i);
		int nx = x, ny = y;
		if(0<=x+dx[i] && x+dx[i]<w && 0<=y+dy[i] && y+dy[i]<h && map[x+dx[i]][y+dy[i]] != 1){
//			printf(" Start moving\n");
			while(1){
//				printf("  %d %d\n", nx, ny);
				if(nx+dx[i]<0 || w<=nx+dx[i] || ny+dy[i]<0 || h<=ny+dy[i]) break;
//				printf("  On board\n");
				if(map[nx+dx[i]][ny+dy[i]] == 3){
					ans = min(ans, move+1);
//					printf("Goal! move=%d\n", move+1);
					break;
				}
//				printf("  Not Goal\n");
				if(nx+dx[i]<0 || w<=nx+dx[i] || ny+dy[i]<0 || h<ny+dy[i]){
//					printf("  Fall from board\n");
					break;
				}
				if(map[nx+dx[i]][ny+dy[i]] == 1){
//					printf("  Stop moving\n");
					map[nx+dx[i]][ny+dy[i]] = 0;
					dfs(nx, ny, move+1);
					map[nx+dx[i]][ny+dy[i]] = 1;
					break;
				}
//				printf("  Continue moving\n");
				nx += dx[i];
				ny += dy[i];
//				printf("  next:%d, %d\n", nx, ny);
			}
		}
	}
	return 0;
}

int main(){
	while(1){
		scanf("%d %d", &w, &h);
		if(w == 0 && h == 0) break;

		ans = 11;
		for(int i=0; i<20; i++){
			for(int j=0; j<20; j++){
				map[i][j] = 0;
			}
		}

		for(int i=0; i<h; i++){
			for(int j=0; j<w; j++){
				scanf("%d", &map[j][i]);
			}
		}

		int sx, sy;
		for(int i=0; i<h; i++){
			for(int j=0; j<w; j++){
				if(map[j][i] == 2){
					sx = j;
					sy = i;
					map[j][i] = 0;
				}
			}
		}
		dfs(sx, sy, 0);

		if(ans == 11) printf("-1\n");
		else printf("%d\n", ans);
	}

	return 0;
}

#include <iostream>
#include <utility>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <stack>

using namespace std;

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

const int INF = 1 << 28;

int w, h;
int field[32][32];
int sx, sy;
int gx, gy;

int ofs[4][2] = {
  {0,1},
  {1,0},
  {-1,0},
  {0,-1}
};

bool ok(int p, int n)
{
  return 0 <= p && p < n;
}

bool dfs(int x, int y, int d, int n)
{
  if( d >= n ) {
    return false;
  }

  bool res = false;
  rep(i, 4) {
    int dx = ofs[i][0];
    int dy = ofs[i][1];
    int nx = x;
    int ny = y;
    int idx = 0;
    while(ok(nx, w) && ok(ny, h) && !field[ny][nx]) {
      nx += dx;
      ny += dy;
      if(nx == gx && ny == gy) {
        return true;
      }
      ++idx;
    }
    if( idx > 1 && ok(nx, w) && ok(ny, h) ) {
      field[ny][nx] = 0;
      res |= dfs(nx - dx, ny - dy, d + 1, n);
      field[ny][nx] = 1;
    }
  }
  return res;
}

int idfs(int sx, int sy)
{
  int idx = 1;
  while( idx <= 10 && !dfs(sx, sy, 0, idx) ) {
    ++idx;
  }
  if( idx > 10 ) {
    return -1;
  } else {
    return idx;
  }
}

int main()
{
  while( cin >> w >> h, (h|w) ) {
    rep(i, h) rep(j, w) {
      int v;
      cin >> v;
      field[i][j] = v & 1;
      if( v & 2 ) {
        if( v & 1 ) {
          gx = j;
          gy = i;
        } else {
          sx = j;
          sy = i;
        }
      }
    }

    cout << idfs(sx, sy) << endl;
  }
  return 0;
}


#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<set>
#include<map>

using namespace std;

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

	vector<pair<char, int>> v;

	char last = s[0];
	int cnt = 1;
	for (int i = 1; i < s.size(); i++) {
		if (s[i] == last) {
			cnt++;
		}
		else {
			v.push_back(make_pair(last, cnt));
			last = s[i];
			cnt = 1;
		}
	}
	v.push_back(make_pair(last, cnt));

	int ans = 0;
	for (int i = 1; i < v.size() - 1; i++) {
		if (v[i - 1].first == 'J' && v[i].first == 'O' && v[i + 1].first == 'I') {
			if (v[i - 1].second >= v[i].second && v[i].second <= v[i + 1].second) {
				ans = max(ans, v[i].second);
			}
		}
	}

	cout << ans << endl;

	return 0;
}

#include<bits/stdc++.h>
#define endl enjoy_codeforces
int main(){
    std::string s;std::cin>>s;
    std::cout<<s.substr(0,s.length()-8)<<'\n';
}


#include<stdio.h>
#include<iostream>
#include<string.h>
using namespace std;
typedef long long ll;
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define CHMIN(a,b) (a) = min((a),(b))
#define CHMAX(a,b) (a) = max((a),(b))

int main()
{
    int n,p;
    while(1==1)
    {
        scanf("%d %d\n",&n,&p);
        if(n==0&&p==0)return 0;
        int ko[55]={};
        int zan=p;
        int poi=0;
        int judge=0;
        while(judge==0)
        {
            for(int i=0;i<n;i++)ko[i]+=zan/n;
            zan-=(zan/n)*n;
            while(zan>0)
            {
                ko[poi]++;
                if(ko[poi]==p)
                {
                    printf("%d\n",poi);
                    judge=1;
                    break;
                }
                zan--;
                poi++;
                if(poi>=n)poi-=n;
            }
            if(judge==1)break;
            while(zan==0)
            {
                if(ko[poi]>0)
                {
                    zan=ko[poi];
                    ko[poi]=0;
                }
                poi++;
                if(poi>=n)poi-=n;
            }
        }
    }
    return 0;
}

#include<bits/stdc++.h>

using namespace std;
const int mod = 1e9+7;
int ad(int x,int y) { x+=y; return x>=mod?x-mod:x; }
int sb(int x,int y) { x-=y; return x<0?x+mod:x; }
int mu(int x,int y) { return 1ll*x*y%mod; }
int ksm(int a,int b) {
	int ans = 1;
	for(;b;b>>=1,a=mu(a,a))
		if(b&1) ans = mu(ans,a);
	return ans;
}
int fac[4000005],piv[4000005],n,k;
int GC(int a,int b) {
	if(a<b) return 0;
	return mu(fac[a],mu(piv[b],piv[a-b]));
}
int f[2005][2005];
int main() {
	scanf("%d%d",&n,&k);
	if(k==1) {
		puts("1"); return 0;
	}
	fac[0] = 1;
	for(int i=1;i<=n*k;i++) fac[i] = mu(fac[i-1],i);
	piv[n*k] = ksm(fac[n*k],mod-2);
	for(int i=n*k-1;i>=0;i--) piv[i] = mu(piv[i+1],i+1);
	f[0][0] = 1;
	for(int i=1;i<=n;i++) {
		f[i][0] = 1;
		for(int j=1;j<=i;j++) {
			f[i][j] = ad(f[i-1][j],mu(GC((n-i)+(n-j+1)*(k-1)-1,k-2),mu(f[i][j-1],n-j+1)));
		}
	}
	printf("%d",f[n][n]);
}


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

int main() {
  int N,K;
  cin >> N >> K;
  vector<int>p(N);
  for (int i = 0; i < N; i++) {
    cin >> p.at(i);
  }
  vector<int>sum1(N,0);
  for (int i = 0; i < N; i++) {
    if (i == 0){
      sum1.at(i) = p.at(i);
    }
    else {
      sum1.at(i) = sum1.at(i-1) + p.at(i);
    }
  }

  vector<int>sum2(N-K+1);
  for (int i = 0; i < N-K+1; i++) {
    sum2.at(i) = sum1.at(K-1+i) - sum1.at(i) + p.at(i);
  }
  sort(sum2.begin(), sum2.end());

  double A = (0.5*K + 1.0*sum2.at(N-K)/2);
  printf("%.8lf\n", A);
}

#include<bits/stdc++.h>

using namespace std;

typedef long long LL;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937 mrand(random_device{}());

#define rep(i , l , r) for (int i = (l); i < (r); ++i)

const int N = 2e6 + 5;
const int mod = 998244353;

int n , m;
int fac[N] , ifac[N];

template <typename T> inline void chkmin(T &x , T y) { x = min(x , y); }
template <typename T> inline void chkmax(T &x , T y) { x = max(x , y); }
template <typename T> inline void read(T &x) {
   T f = 1; x = 0;
   char c = getchar();
   for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
   for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - '0';
   x *= f;
}

inline int quickpow(int a , int n) {
	int res = 1;
	for (; n; n >>= 1 , a = 1LL * a * a % mod)
		if (n & 1) res = 1LL * res * a % mod;
	return res;
}
inline void inc(int &x , int y) {
	x = x + y < mod ? x + y : x + y - mod;
}
inline void dec(int &x , int y) {
	x = x - y >= 0 ? x - y : x - y + mod;
}
inline void init(int n) {
	fac[0] = 1;
	for (int i = 1; i <= n; ++i)
		fac[i] = 1LL * fac[i - 1] * i % mod;
	ifac[n] = quickpow(fac[n] , mod - 2);
	for (int i = n - 1; i >= 0; --i)
		ifac[i] = 1LL * ifac[i + 1] * (i + 1) % mod;
	return;
}
inline int binom(int n , int m) {
	if (n < m) return 0;
	else return 1LL * fac[n] * ifac[m] % mod * ifac[n - m] % mod;
}
inline int F(int n , int m , int k) {
	int ret = 0;
	for (int i = 0; i <= k; ++i) {
		if ((m - i) & 1) continue;
		int val = 1LL * binom(n , i) * binom((m - i) / 2 + n - 1 , n - 1) % mod;
		inc(ret , val);
	}
	return ret;
}

int main() {

   	init(2e6);
   	read(n) , read(m);
   	int ans = F(n , 3 * m , m);
   	dec(ans , 1LL * n * F(n , m , m) % mod);
   	inc(ans , 1LL * n * F(n - 1 , m , m) % mod);
   	printf("%d\n" , ans);
    return 0;
}


//
// Created by hide on 2020/05/15.
//

//参考：http://ehafib.hatenablog.com/entry/2015/12/23/164517
//インクルード(アルファベット順,bits/stdc++.hは使わない派閥)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
//#define PB push_back //vectorヘの挿入
//#define MP make_pair //pairのコンストラクタ
//#define F first //pairの一つ目の要素
//#define S second //pairの二つ目の要素

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

    int r=0;
    for(int i=1; i<N; i++) {
        if (S[i] == 'E')
            r++;
    }
    int answer = r;

    int l = S[0] == 'W' ? 1:0;
    for(int i=1; i<N; i++){
        if(S[i]=='E')
            r--;
        answer = min(answer, l+r);

        if(S[i]=='W')
            l++;
    }

    cout << answer << endl;

    return 0;
}

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

#define inf 1e+9
#define endl "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define rep_rev(i, n) for (int i = n-1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()

#define pb push_back
#define eb emplace_back
#define Size(c) (int)(c).size()

#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))

template <class T> using pq = priority_queue<T>;
template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>;

template <class T, class S> inline bool chmax(T &a, S b) {
    if(a < b) {a = b;return 1;} return 0;
}
template <class T, class S> inline bool chmin(T &a, S b) {
    if(a > b) {a = b;return 1;} return 0;
}
template <class T>
void line(vector<T> &x){for (auto&& xi : x) cin >> xi;}

inline void IN(void){ return;}

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

#define INT(...) int __VA_ARGS__; IN (__VA_ARGS__)
#define LINT(...) lint __VA_ARGS__; IN (__VA_ARGS__)
#define STR(...) string __VA_ARGS__; IN(__VA_ARGS__)

template <class T> void UNIQUE(vector<T> &x) {
    sort(all(x)); x.erase(unique(all(x)), x.end());
}
template <class T> void print_vec(T first, T end){
    for (auto i = first; i < end - 1; i++) cout << *i << " ";
    cout << *(end-1) << endl;
}

template<class... T>
void debug_print(T... args){
    vector<lint> tmp = initializer_list<lint>{args...};
    print_vec(all(tmp));
}
template<class T>
void print(T a){ cout << a << endl;}

vector<string> Yes = {"No", "Yes"};
vector<string> YES = {"NO", "YES"};

int ord(char x){ return (int)(x - 'a');}
char chr(lint x){ return (char)(x + (lint)('a'));}
lint mod = 1e9+7;
// lint mod =

lint sum(vlint a){lint ret = 0; for(auto&& v:a) ret += v; return ret;}
lint vmini(vlint a, lint &index){
    lint ret = LLONG_MAX;
    rep(i, Size(a)){ if (chmin(ret, a[i])) index = i;}
    return ret;
}
lint vmaxi(vlint a, lint &index){
    lint ret = -LLONG_MAX;
    rep(i, Size(a)){ if (chmax(ret, a[i])) index = i;}
    return ret;
}

lint vmin(vlint a){
    lint ret = LLONG_MAX; for (auto && v : a) chmin(ret, v); return ret;
}
lint vmax(vlint a){
    lint ret = -LLONG_MAX; for (auto && v : a) chmax(ret, v); return ret;
}

int main(){
    INT(n); STR(s);
    vlint leftw(n+1, 0), rightw(n+1, 0);
    vlint lefte(n+1, 0), righte(n+1, 0);
    rep(i, n){
        if (s[i] == 'W'){
            leftw[i] ++;
        }
        else{
            lefte[i] ++;
        }
        leftw[i+1] += leftw[i]; lefte[i+1] += lefte[i];
    }
    for (int i = n-1; i > 0; --i){
        if (s[i] == 'W'){
            rightw[i]++;
        }
        else{
            righte[i]++;
        }
        rightw[i-1] += righte[i];
        righte[i-1] += righte[i];
    }

    lint ans = 2 * n;
    rep1(i, n-1){
        chmin(ans, leftw[i-1] + righte[i+1]);
    }
    chmin(ans, righte[1]); chmin(ans, leftw[n-2]);
    print(ans);

}


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

void solve () {
    long long n;
    cin >> n;
    long long mn = 1e15 + 1;
    long long pos = 0;
    for (int i = 0; i < 5; i++) {
        long long x;
        cin >> x;
        if (mn > x) {
            pos = i;
            mn = x;
        }
    }
    cout << (n % mn > 0) + (n / mn) + (4ll - pos) + pos;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    solve();
    return 0;
}

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

int main(){
  int h1, m1, h2, m2, k;
  cin >> h1 >> m1 >> h2 >> m2 >> k;
  int hour;
  int min;

  int t1, t2, t3;
  t3 = h2 * 60 + m2;
  t2 = t3 - k;
  t1 = h1 * 60 + m1;

  int ans;

  ans = t2 - t1;

  cout << ans << endl;

}


#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <cstring>
using namespace std;
#define ref goto refrain
int main(){
	char str[1000];
	cin>>str;
	int q;
	cin>>q;
	string order;
	int a,b;
	char rep[1000];
	for(int i=0;i<q;i++){
		cin>>order;
		cin>>a;
		cin>>b;
		if(order=="replace"){
			cin>>rep;
			for(int j=0;a<=b;j++){
				str[a]=rep[j];
				a++;
			}
		}
		else if(order=="reverse"){
			while(a<=b){
				char temp=str[a];
				str[a]=str[b];
				str[b]=temp;
				a++;
				b--;
			}
		}
		else if(order=="print"){
			for(a=a;a<=b;a++){
				printf("%c",str[a]);
			}
			cout<<endl;
		}
	}
	return 0;
}

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

int main(){
    int a,b;
    string s;
    vector<char> lst(10);
    cin>>a>>b>>s;
    bool ans=true;
    // for(int i=0;i<s.size();i++){
    //     cin>>lst.at(i);
    // {

    for(int i=0;i<s.size();i++){
        if (i!=a && s[i]=='-'){
            ans=false;
            break;
        }
        if (i==a && s[i]!='-'){
            ans=false;
            break;
        }
    }
    if(ans==true){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}


// 2020-09-14 20:57:26
// clang-format off
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

// clang-format on
void answer() {
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> b[i];
  int d = 0;
  rep(ai, n) {
    auto itr = lower_bound(ALL(b), a[ai]);
    if (itr != b.end() && a[ai] == *itr) {
      chmax(d, ai - int(itr - b.begin() - 1));
    }
  }
  bool ok = true;
  rep(i, n) ok &= (a[i] != b[(n + i - d) % n]);
  if (ok) {
    cout << "Yes" << '\n';
    rep(i, n) {
      if (i) cout << ' ';
      cout << b[(n + i - d) % n];
    }
    cout << '\n';
  } else {
    cout << "No" << '\n';
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

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

using ll = long long;

constexpr ll MOD = 1e9+7;
constexpr ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

int main(int argc, char **argv)
{
	ll N; cin >> N;

	ll MAX = 1;
	ll WOM = 2;

	vector<string> isu(N);

	string S;
	ll l = 0;
	ll r = N-1;

	std::cout << l << std::endl;
	cin >> S;
	if (S == "Vacant") return 0;
	isu[l] = S;

	while (true)
	{
		if (r - l <= 1)
		{
			std::cout << r << std::endl;
			cin >> S;
			if (S == "Vacant") return 0;
		}

		ll mid = (l + r) / 2;

		std::cout << mid << std::endl;
		cin >> S;
		if (S == "Vacant") return 0;
		isu[mid] = S;

		ll diff = mid - l - 1;;

		if (diff % 2 == 0)
		{
			if (isu[l] == isu[mid])
			{
				r = mid - 1;
			}
			else
			{
				l = mid;
			}
		}
		else
		{
			if (isu[l] == isu[mid])
			{
				l = mid;
			}
			else
			{
				r = mid - 1;
			}
		}
	}
}


#include<iostream>
#include<algorithm>
using namespace std;
typedef long long int llint;
llint v[1000005],dp[1000005],n;
int x[25][25];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	for(int i=0;i<n;i++) {
		for(int j=0;j<n;j++) {
			cin >> x[i][j];
		}
	}
	for(int i=0;i<(1 << n);i++) {
		for(int j=0;j<n;j++) {
			for(int k=j+1;k<n;k++) {
				v[i]+=((i & (1 << j)) && (i & (1 << k)))*x[j][k];
			}
		}
	}
	for(int i=0;i<(1 << n);i++) {
		dp[i]=max(dp[i],v[i]);
		for(int j=i;j>0;j=(j-1) & i) {
			dp[i]=max(dp[i],dp[j]+dp[i ^ j]);
		}
	}
	cout << dp[(1 << n)-1];
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll MOD = 998244353;
const ll MAXN = 303;

ll dp[MAXN][MAXN*MAXN];

main(){
	int n;
	cin >> n;
	ll arr[n];
	int S = 0;
	for(int i=0;i<n;++i){
		cin >> arr[i];
		S += arr[i];
	}
	fill(&dp[0][0], &dp[0][0] + MAXN*MAXN*MAXN, 0);
	dp[0][0] = 1;
	for(auto i=0;i<n;++i){
		for(auto j=0;j<MAXN*MAXN;++j){
			dp[i+1][j+arr[i]] += dp[i][j];
			dp[i+1][j+arr[i]]%=MOD;
			dp[i+1][j] += 2LL*dp[i][j];
			dp[i+1][j]%=MOD;
		}
	}
	ll K = 0;
	for(auto i=(S+1)/2;i<=S;++i){
		K += dp[n][i];
	}
	fill(&dp[0][0], &dp[0][0] + MAXN*MAXN*MAXN, 0);
	dp[0][0] = 1;
	ll L = 0;
	if(S%2==0){
		for(auto i=0;i<n;++i){
			for(auto j=0;j<MAXN*MAXN;++j){
				dp[i+1][j+arr[i]] += dp[i][j];
				dp[i+1][j+arr[i]]%=MOD;
				dp[i+1][j] += dp[i][j];
				dp[i+1][j]%=MOD;
			}
		}
		L = dp[n][S/2];
	}
	ll ans = 1;
	for(int i=0;i<n;++i){
		ans *= 3LL;
		ans %= MOD;
	}
	ans += MOD - (3*K)%MOD;
	ans %=MOD;
	ans += 3*L;
	ans %=MOD;
	cout << ans << endl;
}


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

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(0)
#define all(ct) ct.begin() , ct.end()
#define endl "\n"
#define fr(i,a) for(auto i:a)
#define f(i,a,b) for(int i=a;i<b;++i)
#define fd(i,a,b) for(int i=a;i>=b;--i)
#define pb push_back
#define in(d,v) d.find(v)!=d.end()
#define mp make_pair
#define size(a) int(a.size())

const int mod = 1e9 + 7;
const ll inf = ll(1e18);
const double PI = acos(-1);

ll modexp(ll x,ll n,int md){
    if(n==0)return 1;
    if(n%2==0)return modexp((x*x)%md,n/2,md);
    return (x*modexp((x*x)%md,n/2,md))%md;
}

set<int> g[200001];
int main(){
    fastio;
    //clock_t tm = clock();
    int n;
    cin>>n;
    vi a(n),b(n),na(n+1,0),nb(n+1,0);
    priority_queue<pii>g1;
    f(i,0,n){
        cin>>a[i];na[a[i]]++;
        g[a[i]].insert(i);
    }
    f(i,0,n){
        cin>>b[i];nb[b[i]]++;
    }
    priority_queue<pii>g2;
    f(i,1,n+1){
        if(na[i]+nb[i]>n){
            cout<<"No"<<endl;
            return 0;
        }
        if(nb[i]>0){
            g2.push({nb[i],-i});
        }
        if(na[i]>0){
            g1.push({na[i],i});
        }
    }
    reverse(all(b));
    vi ans(n,0);
    while(!g2.empty()){
        auto pr=g2.top();
        g2.pop();
        if(pr.first>1){
            --pr.first;
            g2.push(pr);
        }
        pr.second*=-1;
        auto qr=g1.top();
        g1.pop();
        if(qr.second!=pr.second) {
            if (qr.first > 1) {
                --qr.first;
                g1.push(qr);
            }
            ans[*g[qr.second].begin()]=pr.second;
            g[qr.second].erase(*g[qr.second].begin());
        }
        else{
            if(g1.empty())break;
            auto qr1=g1.top();
            g1.pop();g1.push(qr);qr=qr1;
            if (qr.first > 1) {
                --qr.first;
                g1.push(qr);
            }
            ans[*g[qr.second].begin()]=pr.second;
            g[qr.second].erase(*g[qr.second].begin());
        }
    }
    cout<<"Yes"<<endl;
    fr(i,ans)cout<<i<<" ";
    cout<<endl;
    //cout<<((clock()-tm)*1.0)/CLOCKS_PER_SEC<<endl;
}

#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll=long long;
using ld=long double;
//#define int long long
#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
#define ALL(x) (x).begin(), (x).end()
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279;
int fact(int i) {
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int keta(int n) {
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
int ketasum(int n) {
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
char toSmall(char c) { // 大文字を小文字へ
    return (c + 0x20);
}
char toLarge(char c) { // 小文字を大文字へ
    return (c - 0x20);
}
float myPower(int a, int n) { // aのn乗の計算
    float x = 1;
    while (n > 0) { // 全てのbitが捨てられるまで
        if (n & 1) { // 一番右のbitが１のとき
            x *= a;
        }
        a *= a;
        n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
    }
    return x;
}
bool is_prime(const unsigned n) {
    switch (n) {
    case 0: // fall-through
    case 1: return false;
    case 2: // fall-through
    case 3: return true;
    } // n > 3 が保証された

    if (n % 2 == 0 || n % 3 == 0) return false;
    // n は 2 と 3 のいずれの倍数でもないことが保証された
    // これより n は (6の倍数)-1 か (6の倍数)+1 である
    // 6の倍数前後の数を使って試し割りをする
    for (unsigned i = 5; i * i <= n; i += 6) {
        if (n % i == 0) return false; // (6の倍数)-1
        if (n % (i + 2) == 0) return false; // (6の倍数)+1
    }

    return true;
}
int main(void){
    int saidai = 0;
    int N;
    cin >> N;
    vector<string> s(N);
    for (int i = 0; i < N; i++) cin >> s[i];
    int M;
    cin >> M;
    vector<string> t(M);
    for (int i = 0; i < M; i++) cin >> t[i];
    for (int i = 0; i < N; i++) {
        string a = s.at(i);
        int c = 0;
        for (int i = 0; i < N; i++) {
            if (a == s.at(i)) c++;
        }
        for (int i = 0; i < M; i++) {
            if (a == t.at(i)) c--;
        }
        if (saidai < c) saidai = c;
    }
    cout << saidai << endl;
    return 0;
}


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

int main(){
	int N, K;
	cin >> N >> K;
	int ans = 0;
	for(int i = 1; i <= N - K + 1; ++i) {
		ans++;
	}
	cout << ans << endl;
}

#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <list>
#include <numeric>
#include <map>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
//================================================

int a = 0, b = 0, c, d, n, k=0;
string s, t;

long long kaizyou(int x)
{
	if (x == 1)
		return 1;
	else
		return x * kaizyou(x - 1);
}

int main()
{
	cin >> n >> k;
	cout << n-k+1 << endl;
	return 0;
}


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

int H, W;
vector<string> fi;

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

int main() {
    cin >> H >> W;
    fi.resize(H);
    for (int i = 0; i < H; ++i) cin >> fi[i];

    // 多点をスタートとして扱う
    vector<vector<int> > dist(H, vector<int>(W, -1));
    using pint = pair<int,int>;
    queue<pint> que;
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            if (fi[i][j] == '#') {
                dist[i][j] = 0;
                que.push(pint(i, j));
            }
        }
    }

    // BFS
    while (!que.empty()) {
        auto cur = que.front();
        que.pop();
        for (int dir = 0; dir < 4; ++dir) {
            int nx = cur.first + dx[dir];
            int ny = cur.second + dy[dir];
            if (nx < 0 || nx >= H || ny < 0 || ny >= W) continue;
            if (dist[nx][ny] == -1) {
                dist[nx][ny] = dist[cur.first][cur.second] + 1;
                que.push(pint(nx, ny));
            }
        }
    }
    int res = 0;
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            res = max(res, dist[i][j]);
        }
    }
    cout << res << endl;
}

#include <bits/stdc++.h>

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

//#define int long long
//signed main(){
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int h,w;
    cin >> h >> w;
    vector<bool> a(h*w,false);

    queue<int> que;
    for(int i = 0; i < h; i++) {
        string tmp;
        cin >> tmp;
        for(int j = 0; j < w; j++) {
            int idx=i*w+j;
            if(tmp[j]=='#'){
                a[idx]=true;
                que.push(idx);
            }
        }
    }

    int cnt=0;
    int ans=0;
    while(cnt<h*w) {
        int n=que.size();
        cnt+=n;
        for(int i = 0; i < n; i++) {
            int idx=que.front();
            int add[4]={1,-1,w,-w};
            for(int j = 0; j < 4; j++) {
                int t=idx+add[j];
                int r=idx/w+add[j]/w;
                int c=idx%w+add[j]%w;
                if(r<0||r>=h||c<0||c>=w||a[t]==true) continue;
                a[t]=true;
                que.push(t);
            }
            que.pop();
        }
        ans++;
    }
    cout << ans-1 << "\n";

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const long long r = 1e9 + 7;

long long fac[200001];

long long f(long long a, long long p) {
	if (p == 1)
		return a;

	long long ret = f(a, p / 2);
	ret = ret * ret % r;
	if (p % 2 == 1)
		ret = ret * a % r;

	return ret;
}

long long c(int n, int m) {
	return fac[n] * f(fac[m] * fac[n - m] % r, r - 2) % r;
}

int main() {
	fac[0] = 1;
	for (int i = 1; i <= 200000; ++i)
		fac[i] = fac[i - 1] * i % r;

	int n, m, a, b;
	scanf("%d %d %d %d", &n, &m, &a, &b);
	a = n - a;

	long long ans = 0;
	for (int i = 1; i <= a; ++i)
		ans = (ans + c(b + i - 2, b - 1) * c(m - b + n - i - 1, n - i) % r) % r;

	printf("%lld", ans);

	return 0;
}

#include <bits/stdc++.h>

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll = long long;

const double PI = 3.14159265358979;

void solve()
{
  int h1, m1, h2, m2, k;
  cin >> h1 >> m1 >> h2 >> m2 >> k;
  cout << (h2 * 60 + m2) - (h1 * 60 + m1) - k;
}

int main()
{
  fastio;
  solve();

  return 0;
}


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

void solve(){
	ll n;
	cin>>n;
	ll k,p,x,ans;
	ans = (n*(n+1))/2;
    k = n/3;
    p = n/5;
    x = n/15;
    ans = ans - 3*(k*(k+1)/2) - 5*(p*(p+1))/2 + 15*(x*(x+1))/2;
    cout<<ans<<endl;
}
int main()
{

  solve();

return 0;
}

#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
const long long inf=0x3f3f3f3f;
long long bs[maxn];
long long d,dx1[maxn],dx2[maxn];
long long a[maxn],an,ans;
void dfs(long long x,long long v,long long c)
{
	if(x==an)
	{
		ans+=(v==d)*c;
		return ;
	}
	if(abs(v-d)>a[x]*20)
		return ;
	for(long long i=0;i<20;i++)
	{
		long long cnt;
		if(x==0)
			cnt=dx1[i];
		else
			cnt=dx2[i];
		if(a[x]==0)
			cnt=i<10;
		if(cnt==0)
			continue;
		dfs(x+1,v+(i-10)*a[x],c*cnt);
	}
}
void solve(long long n)
{
	an=0;
	for(long long i=0;i<n;i++)
	{
		if(i>n-i-1)
			break;
		a[an++]=bs[n-i-1]-bs[i];
	}
	dfs(0,0,1);
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    for(long long i=0;i<=9;i++)
    	for(long long j=0;j<=9;j++)
    		dx2[i-j+10]++;
    for(long long i=0;i<=9;i++)
    	for(long long j=1;j<=9;j++)
    		dx1[i-j+10]++;
    bs[0]=1;
    for(long long i=1;i<19;i++)
    	bs[i]=bs[i-1]*10;
    cin>>d;
    for(long long i=1;i<=19;i++)
    	solve(i);
    cout<<ans<<endl;
	return 0;
}


#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <stdio.h>
#include <string>
#include <vector>

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

/* a と b の最大公約数を返す関数 */
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

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

	vector<int> Li(N, 0);
	rep(i, N) cin >> Li.at(i);

	sort(Li.begin(), Li.end());
	reverse(Li.begin(), Li.end());

	int ans = 0;
	rep(i, K)
	{
		ans += Li.at(i);
	}

	cout << ans << endl;

	return 0;
}

#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<cmath>
#include<cstring>
#include<set>
#include<climits>
#include<deque>
#include<cstdio>
using namespace std;

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


#include <bits/stdc++.h>

using namespace std;

int main()
{

	float D, T, S;
	cin >> D >> T >> S;
	if((D/S) <= T)
		cout << "Yes\n";
	else
		cout << "No\n";
}

#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int A, B;
  cin>>A>>B;
  string S;
  cin>>S;
  string tmp1=S.substr(0, A), tmp2=S.substr(A+1, B);
  bool can = true;
  for(int i=0;i<tmp1.size();++i) {
    if(tmp1[i]=='-') can = false;
  }
  if(S[A]!='-') can = false;
  for(int i=0;i<tmp2.size();++i) {
    if(tmp2[i]=='-') can = false;
  }
  if(can) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <cassert>
using namespace std;
string s,t;
int dp[310][310][310] = {};
int main(){
	int i,j,l,n,k;
	cin >> s >> k; n = s.size();
	for(i=0;i<n;i++){
		t.push_back(s[n - 1 - i]);
	}
	for(i=1;i<=n;i++){
		for(j=1;j<=n;j++){
			for(l=0;l<=k;l++){
				if(s[i - 1]==t[j - 1]){
					dp[i][j][l] = dp[i - 1][j - 1][l] + 1;
				}else{
					int x = max(dp[i - 1][j][l],dp[i][j - 1][l]);
					if(l>0) x = max(x,dp[i - 1][j - 1][l - 1] + 1);
					dp[i][j][l] = x;
				}
			}
		}
	}
	int ans = 0;
	for(i=0;i<n;i++){
		ans = max(ans,2*dp[i][n - i][k]);
		ans = max(ans,2*dp[i][n - 1 - i][k] + 1);
	}
	cout << ans << endl;
}

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>

using namespace std;
#define rint register int
#define gc() getchar()
inline int read(rint ans = 0, rint sgn = ' ', rint ch = gc())
{
	for(; ch < '0' || ch > '9'; sgn = ch, ch = gc());
	for(; ch >='0' && ch <='9';(ans*=10)+=ch-'0', ch = gc());
	return sgn-'-'?ans:-ans;
}
char T[305]; int n, K, f[305][305][305]; inline int Cmax(int &x, int v){x < v ? x = v : 0;}
int main()
{
	scanf("%s",T+1), n = strlen(T+1), K = read();
	for(rint i = 1, k; i <= n; i++) for(k = 0; k <= K; f[i][i][k] = 1, k++);
	for(rint d = 2, l, r, k; d <= n; d++)
		for(l = 1, r = d; r <= n; l++, r++)
			for(k = 0; k <= K; k++)
			{
				Cmax(f[l][r][k],f[l][r-1][k]);
				Cmax(f[l][r][k],f[l+1][r][k]);
				T[l]==T[r] ? Cmax(f[l][r][k],f[l+1][r-1][k]+2) : 0;
				k ? Cmax(f[l][r][k],f[l+1][r-1][k-1]+2) : 0;
				k ? Cmax(f[l][r][k],f[l][r][k-1]) : 0;
			}	printf("%d\n",f[1][n][K]); return 0;
}


#include <bits/stdc++.h>
#define repp(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//ミョ(-ω- ?)
int main() {
    ll n;
    cin >> n;
    vector<ll> a(n,0);
    rep(i,n)cin >> a[i];
    map<ll,ll> odds;
    for(ll i = 0;i < n;i+=2)odds[a[i]]++;
    pair<ll,ll> of = {0,0};
    pair<ll,ll> os = {0,0};
    for(auto t : odds){
        if(t.second > of.second){
            os = of;
            of = t;
            continue;
        }else if(t.second > os.second){
            os = t;
            continue;
        }
    }

    map<ll,ll> even;
    for(ll i = 1;i < n;i+=2)even[a[i]]++;
    ll e = 0;
    pair<ll,ll> ef = {0,0};
    pair<ll,ll> es = {0,0};
    for(auto t : even){
        if(t.second > ef.second){
            es = ef;
            ef = t;
            continue;
        }else if(t.second > es.second){
            es = t;
            continue;
        }
    }
    if(of.first != ef.first){
        cout << (n/2 - of.second) + (n/2 - ef.second) << "\n";
    }else{
        cout << min((n/2 - os.second)+(n/2 - ef.second) , (n/2 - of.second) + (n/2 - es.second)) << "\n";
    }

    return 0;
}

#include <bits/stdc++.h>

#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FILL0(x) memset(x,0,sizeof(x))

using namespace std;

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

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()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    int n;
    cin >> n;
    vector<int> v[2];
    rep(i, n)
    {
        int tmp;
        cin >> tmp;
        v[i%2].push_back(tmp);
    }

    if(n==2)
    {
        if(v[0][0]==v[1][0])
        {
            cout << 1 << endl;
        }
        else
        {
            cout << 0 << endl;
        }

    }

    int tab0[100010];
    FILL0(tab0);
    rep(i, v[0].size())
    {
        tab0[v[0][i]]++;
    }

    vector<P> freq0;

    rep(i, 100001)
    {
        if(tab0[i]!=0)
        {
            freq0.push_back(P(tab0[i], i));
        }
    }

    int tab1[100010];
    FILL0(tab1);
    rep(i, v[1].size())
    {
        tab1[v[1][i]]++;
    }

    vector<P> freq1;

    rep(i, 100001)
    {
        if(tab1[i]!=0)
        {
            freq1.push_back(P(tab1[i], i));
        }
    }

    sort(freq0.begin(), freq0.end());
    reverse(freq0.begin(), freq0.end());

    sort(freq1.begin(), freq1.end());
    reverse(freq1.begin(), freq1.end());

    if(freq0[0].second==freq1[0].second)
    {
        if(freq0[0].first-freq0[1].first>freq1[0].first-freq1[1].first)
        {
            cout << n-(freq0[0].first+freq1[1].first) << endl;
        }
        else
        {
            cout << n-(freq1[0].first+freq0[1].first) << endl;
        }

    }
    else
    {
        cout << n-(freq0[0].first+freq1[0].first) << endl;
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

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

	ll n, lbuf, rbuf, mi;
	cin >> n;
	P lr[n];
	ll ans = 0;
	zep(i, 0, n){
		cin >> lbuf >> rbuf;
		lr[i] = P(rbuf, lbuf);
		if(rbuf-lbuf+1 > ans){
			ans = rbuf-lbuf+1;
			mi = i;
		}
	}
	ll lm = 0;
	ll rm = 1e9;
	zep(i, 0, n){
		if(i != mi){
			lm = max(lr[i].second, lm);
			rm = min(lr[i].first, rm);
		}
	}
	ans += max(rm-lm+1, 0LL);

	sort(lr, lr+n);
	zep(i, 0, n){
		ll tmp = lr[i].first;
		lr[i].first = lr[i].second;
		lr[i].second = tmp;
	}

	ll al[n], dl[n], ar[n], dr[n];
	al[0] = lr[0].first;
	ar[0] = lr[0].second;
	zep(i, 1, n){
		al[i] = max(lr[i].first, al[i-1]);
		ar[i] = min(lr[i].second, ar[i-1]);
	}

	dl[n-1] = lr[n-1].first;
	dr[n-1] = lr[n-1].second;
	rrep(i, n-2, 0){
		dl[i] = max(lr[i].first, dl[i+1]);
		dr[i] = min(lr[i].second, dr[i+1]);
	}

	zep(i, 0, n-1){
		ans = max(ar[i]-al[i]+1+dr[i+1]-dl[i+1]+1, ans);
	}
	print(ans)
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define re register
#define ll long long
#define int ll
#define get getchar()
#define in inline
in int read()
{
	int t=0; char ch=get;
	while(ch<'0' || ch>'9') ch=get;
	while(ch<='9' && ch>='0') t=t*10+ch-'0', ch=get;
	return t;
}
const int _=2e5+5;
int n,q,A,B,x[_];
ll lazy[_<<4],min1[_<<4],min2[_<<4];
in void pushdown(int k)
{
	if(lazy[k]==0) return ;
	int x=lazy[k];
	lazy[k]=0;
	lazy[k<<1]+=x;
	lazy[k<<1|1]+=x;
	min1[k<<1]+=x;
	min1[k<<1|1]+=x;
	min2[k<<1]+=x;
	min2[k<<1|1]+=x;
}
in void update(int k,int l,int r,int x,int y)
{
	if(l==r)
	{
		min1[k]=min(min1[k],(ll)(y-l));
		min2[k]=min(min2[k],(ll)(y+l));
		return;
	}
	pushdown(k);
	int mid=l+r>>1;
	if(x<=mid) update(k<<1,l,mid,x,y);
	else update(k<<1|1,mid+1,r,x,y);
	min1[k]=min(min1[k<<1],min1[k<<1|1]);
	min2[k]=min(min2[k<<1],min2[k<<1|1]);
}
/*#define ls(_o) (_o << 1)
#define rs(_o) ((_o << 1) | 1)
ll query1(int rl, int rr, int l, int r, int tree) {
        if (rl == l && rr == r)
            return (min1[tree]);
        int mid = (l + r) >> 1;
        pushdown(tree);
        if (rl > mid)
            return (query1(rl, rr, mid + 1, r, rs(tree)));
        if (rr <= mid)
            return (query1(rl, rr, l, mid, ls(tree)));
        return (min(query1(rl, mid, l, mid, ls(tree)), query1(mid + 1, rr, mid + 1, r, rs(tree))));
    }
ll query2(int rl, int rr, int l, int r, int tree) {
        if (rl == l && rr == r)
            return (min2[tree]);
        int mid = (l + r) >> 1;
        pushdown(tree);
        if (rl > mid)
            return (query2(rl, rr, mid + 1, r, rs(tree)));
        if (rr <= mid)
            return (query2(rl, rr, l, mid, ls(tree)));
        return (min(query2(rl, mid, l, mid, ls(tree)), query2(mid + 1, rr, mid + 1, r, rs(tree))));
		}*/

  in int query1(int k,int l,int r,int x,int y)
{
//	cout<<1<<":: "<<k<<' '<<l<<' '<<r<<' '<<x<<' '<<y<<endl;
	if(l==x && r==y) return min1[k];
	pushdown(k);
	int mid=l+r>>1,minn=0x3f3f3f3f;
	if(y<=mid) return query1(k<<1,l,mid,x,y);
	if(x>mid) return query1(k<<1|1,mid+1,r,x,y);
	return min(query1(k<<1,l,mid,x,mid),query1(k<<1|1,mid+1,r,mid+1,y));
	}
in int query2(int k,int l,int r,int x,int y)
{
//	cout<<2<<":: "<<k<<' '<<l<<' '<<r<<' '<<x<<' '<<y<<endl;
	if(l==x && r==y) return min2[k];
	pushdown(k);
	int mid=l+r>>1,minn=0x3f3f3f3f;
	if(y<=mid) return query2(k<<1,l,mid,x,y);
	if(x>mid) return query2(k<<1|1,mid+1,r,x,y);
	return min(query2(k<<1,l,mid,x,mid),query2(k<<1|1,mid+1,r,mid+1,y));
	}
in int getans(int k,int l,int r)
{
	if(l==r) return min1[k]+l;
	pushdown(k);
	int mid=l+r>>1;
	return min(getans(k<<1,l,mid), getans(k<<1|1,mid+1,r));
}
signed main()
{
	n=read(),q=read(),A=read(),B=read();
	x[0]=A;
	memset(min1,0x3f,sizeof(min1));
	memset(min2,0x3f,sizeof(min2));
	update(1,1,n,B,0);
	for(re int i=1;i<=q;i++)
	{
		x[i]=read();
		//int qwe=min(query1(1, x[i], 1, n, 1) + x[i], query2(x[i], n, 1, n, 1) - x[i]);
		int qwe=min(query1(1,1,n,1,x[i])+x[i],query2(1,1,n,x[i],n)-x[i]);
		lazy[1]+=abs(x[i]-x[i-1]);
		min1[1]+=abs(x[i]-x[i-1]);
		min2[1]+=abs(x[i]-x[i-1]);
		update(1,1,n,x[i-1],qwe);
	}
	cout<<getans(1,1,n);
}


#include<bits/stdc++.h>
using namespace std;
using lli = long long;
#define rep(i,n) for(int i=0;i<n;i++)
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; }

lli n;

int main(void){
    cin >> n;
    vector<vector<pair<lli, lli>>> t(n);
    rep(i, n){
        lli ai;
        cin >> ai;
        rep(j, ai){
            lli x, y;
            cin >> x >> y;
            t[i].push_back({x-1, y});
        }
    }
    lli ans = 0;
    rep(b, (1<<n)){
        bool ok = true;
        rep(j, n){
            if(b>>j&1){
                rep(k, t[j].size()){
                    lli u = t[j][k].second;
                    lli v = b>>t[j][k].first&1;
                    if(u != v){
                        ok = false;
                    }
                }
            }
        }
        if(ok){
            ans = max(ans, (lli)__builtin_popcount(b));
        }
    }
    cout << ans << endl;
    return 0;
}

#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n;
    cin >> n;
    VVI x(n), y(n);
    REP(i,n){
        int a = in();
        REP(j,a){
            x[i].push_back(in() - 1);
            y[i].push_back(in());
        }
    }
    int ans = 0;
    REP(mask,1<<n){
        bool f = true;
        int cnt = 0;
        REP(i,n) if ((mask >> i) & 1) cnt++;

        REP(i,n){
            if (((mask >> i) & 1) == 0) continue;
            REP(j,x[i].size()){
                if (((mask >> x[i][j]) & 1) != y[i][j]) f = false;
            }
        }
        if (f) chmax(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}


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

long long  INF=1000000000000000000;
long long mod=1000000007;
using namespace std;

long long stair(int N){
long long i=1;
for(int k=2;k<=N;k++){
    i*=k;
    if(i>mod){
        i%=mod;
    }
}
return i;

}

int main(){
int N;
cin>>N;
string s;
cin>>s;
char white='W';
char black='B';
if(s[0]==white || s[2*N-1]==white){
    cout<<"0"<<endl;
    return 0;
}

bool LorR[2*N];

LorR[0]=false;//L=false,R=trueとする

for(int i=1;i<2*N;i++){
    if(s[i-1]==s[i]){
        LorR[i]=!LorR[i-1];
    }
    else{
        LorR[i]=LorR[i-1];
    }
}
int countL[2*N+1];//Lの個数の累積和
int countR[2*N+1];//Lの個数の累積和
countL[0]=0;
countR[0]=0;
for(int i=0;i<2*N;i++){
    if(LorR[i]){
        countR[i+1]=countR[i]+1;
        countL[i+1]=countL[i];
    }
    else{
        countR[i+1]=countR[i];
        countL[i+1]=countL[i]+1;
    }
}

if(countL[2*N]!=countR[2*N]){
    cout<<"0"<<endl;
    return 0;
}
long long ans=1;
for(int i=1;i<=2*N;i++){
    if(LorR[i-1]){
        if(countL[i]<countR[i]){
           cout<<"0"<<endl;
            return 0;
        }
        ans*=(countL[i]-countR[i-1]);
    }

    if(ans>mod){
        ans%=mod;
    }
}
//順列なのでnの階乗をかける
ans=(ans*stair(N))%mod;

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

#include <bits/stdc++.h>

using namespace std;
using i64 = std::int_fast64_t;

const int MOD = 1000000007;

template <typename T>
ostream &operator<<(ostream &os, const std::vector<T> &vec) {
  for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
  return os;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int H, W, K;
  cin >> H >> W >> K;

  vector<vector<i64>> dp(H + 1, vector<i64>(W + 1, 0));
  dp[0][0] = 1;
  for (int h = 0; h < H; h++) {
    for (int w = 0; w < W; w++) {
      for (int bit = 0; bit < (1 << (W - 1)); bit++) {
        auto check = [bit, W]() -> bool {
          for (int b = 0; b < W - 2; b++) {
            if ((bit >> b) & 1 && (bit >> (b + 1)) & 1) return false;
          }
          return true;
        };

        if (!check()) continue;

        int nw = w;
        if ((bit >> w) & 1) {
          nw++;
        } else if (w > 0 && (bit >> (w - 1)) & 1) {
          nw--;
        }

        dp[h + 1][nw] = (dp[h + 1][nw] + dp[h][w]) % MOD;
      }
    }
  }

  cout << dp[H][K - 1] << '\n';
  return 0;
}


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

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

ll modinv(ll a, ll mod){
    return modpow(a, mod-2, mod);
}

int main() {
    ll N,M,K,ans;
    cin>>N>>M>>K;
    ll mod = 998244353;
    ll kakuk = M*modpow(M-1,N-1,mod)%mod;
    ans = kakuk;
    ll gyakuM = modinv(M-1,mod);
    rep(i,K){
        kakuk = (kakuk * (N-i-1))%mod;
        kakuk = (kakuk * modinv(i+1,mod))%mod;
        kakuk = (kakuk * gyakuM)%mod;
        ans += kakuk;
        ans = ans%mod;
    }
    if(M==1&&N-1==K) cout << 1 << endl;
    else cout << ans << endl;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1'000'000'007;
const ld PI = acos(-1);
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define rep(i, n) for(ll i=0; i<(ll)(n); i++)
#define repd(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=b-1; (ll)(a)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

class FactorialMod{
    void calc_inverse(){
        inverse[0] = 0;
        inverse[1] = 1;
        for(int i=2; i<=max_num; i++){
            inverse[i] = md-((md/i)*inverse[md%i]%md);
        }
    }

    void calc_factorial_inverse(){
        factorial[0] = factorial_inverse[0] = 1;
        for (int i=1; i<=max_num; i++) {
            factorial[i] = (factorial[i-1]*i)%md;
            factorial_inverse[i] = (factorial_inverse[i-1]*inverse[i])%md;
        }
    }

    public:
        ll max_num, md;
        vector<ll> inverse;
        vector<ll> factorial;
        vector<ll> factorial_inverse;
        FactorialMod(ll _max_num, ll _md=MOD){
            max_num = _max_num;
            md = _md;
            inverse = vector<ll>(max_num+1);
            factorial = vector<ll>(max_num+1);
            factorial_inverse = vector<ll>(max_num+1);
            calc_inverse();
            calc_factorial_inverse();
        }

        ll combination(int n, int k){
            return (((factorial[n]*factorial_inverse[k])%md)*factorial_inverse[n-k])%md;
        }

        ll multiChoose(int n, int k){
            return combination(n+k-1, k);
        }
};

ll modpow(ll x, ll n, ll md=MOD){
    ll res=1, dig=x;
    while(n){
        if(n&1) res = res*dig%md;
        dig = dig*dig%md;
        n /= 2;
    }
    return res;
}
ll comb(ll N_, ll C_, ll mo) {
	const int NUM_=400001;
	static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];
	if (fact[0]==0) {
		inv[1]=fact[0]=factr[0]=1;
		for (int i=2;i<=NUM_;++i) inv[i] = inv[mo % i] * (mo - mo / i) % mo;
		for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%mo, factr[i]=factr[i-1]*inv[i]%mo;
	}
	if(C_<0 || C_>N_) return 0;
	return factr[C_]*fact[N_]%mo*factr[N_-C_]%mo;
}
int main(){
    ll n, m, k; cin >> n >> m >> k;
    //重複組み合わせは配列倍(n+k)にする
    ll mod = 998244353, res=0;
    FactorialMod calc_mod(n, mod);
    rep(i, k+1){
        res += m*calc_mod.combination(n-1, i)%mod*modpow(m-1, n-1-i, mod)%mod;
        res %= mod;
    }
    cout << res << endl;

}


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

int main()
{

	int n = 1;
	std::cin >> n;

	while (n)
	{
		std::vector<int32_t> num_list{};

		while (n--)
		{
			int tmp = 0;
			std::cin >> tmp;
			num_list.push_back(tmp);
		}

		std::vector<int32_t> comfarm_list{};
		std::vector<int32_t> sum_list{};
		for( auto num : num_list )
		{
			for (auto& sum : sum_list)
			{
				if (num < 0)
				{
					comfarm_list.push_back(sum);
				}
				sum += num;
			}
			sum_list.push_back(num);
		}

		for (auto sum : sum_list)
		{
			comfarm_list.push_back(sum);
		}

		int32_t max_sum = *( std::max_element(comfarm_list.begin(),comfarm_list.end()) );
		std::cout << max_sum << std::endl;

		std::cin >> n;
	}

	return 0;
}

#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;

int main() {
	int n,i,j,d,m[11][11];
	while(cin >> n) {
		if (n==0) break;
		memset(m,0,sizeof(m));
		for (i=0;i<n;i++) for (j=0;j<n;j++) {
			cin >> d;
			m[i][j]=d; m[i][n]+=d; m[n][j]+=d; m[n][n]+=d;
		}
		for (i=0;i<=n;i++) {
			for (j=0;j<=n;j++) printf("%5d",m[i][j]);
			printf("\n");
		}
	}
	return 0;
	}


#include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
const int MOD = 1000000007;
const int INF = 1e18;
using Graph = vector<vector<int>>;

signed main() {
  int N, T;
  cin >> N >> T;
  vector<pair<int, int>> dish(N);
  for( int i = 0; i < N; i++ ){
    int A, B;
    cin >> A >> B;
    dish[i] = make_pair(A, B);
  }

  sort(dish.begin(), dish.end());

  vector<int> dp(10000);
  dp[0] = 0;
  for( int i = 0; i < N; i++ ){
    for( int j = T-1; j >= 0;  j-- ){
      int A = dish[i].first;
      int B = dish[i].second;
      dp[j+A] = max(dp[j+A], dp[j]+B);
    }
  }

  int ans = 0;
  for( int i = 0; i < 10000; i++ ){
    ans = max(ans, dp[i]);
  }
  cout << ans << endl;

}

#include<bits/stdc++.h>

using namespace std;

#define N 2005

int n,m,f[N][N],L[N],R[N],ans,stk[N];
bool a[N][N];
char s[N];

int main(){
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;++i){
		scanf("%s",s+1);
		for (int j=1;j<=m;++j) a[i][j]=s[j]=='.';
	}
	for (int i=n;i;--i){
		for (int j=1;j<m;++j)
			if ((a[i][j]^a[i][j+1])==(a[i+1][j]^a[i+1][j+1])) f[i][j]=f[i+1][j]+1;
			else f[i][j]=1;
	}
	ans=n;
	for (int i=1;i<=n;++i){
		int tp=0; stk[tp]=0;
		for (int j=1;j<m;++j){
			for (;tp&&f[i][j]<f[i][stk[tp]];--tp);
			L[j]=stk[tp];
			stk[++tp]=j;
		}
		tp=0; stk[tp]=m;
		for (int j=m-1;j;--j){
			for (;tp&&f[i][j]<=f[i][stk[tp]];--tp);
			R[j]=stk[tp];
			stk[++tp]=j;
		}
		for (int j=1;j<m;++j)
			ans=max(ans,f[i][j]*(R[j]-L[j]));
	}
	printf("%d\n",ans);

	return 0;
}


#include <iostream>
#include <vector>
#include<algorithm>
#include<iomanip>
#include<queue>
#include<map>
#include<bitset>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
typedef pair<int,int> pint;
typedef long long ll;
const int inf   = 1e9+7;
const ll  longinf = 1LL<<60;
const int mod=1e9+7;
int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};

ll dp[300001][3][3];
ll all[300001];
int m,s[300003];
string t;

ll rec(int n,int a,int b){
  if(dp[n][a][b]!=-1)return dp[n][a][b];
  ll ret=0;
  if(a!=0&&b!=0)ret+=all[n+2];
  if(a!=0&&b!=1){
    if(n==m-3)ret+=rec(n+2,s[n+2],0);
    else {
      if(s[n+2]!=0)ret+=rec(n+2,1,s[n+3]);
      if(s[n+2]!=1)ret+=rec(n+2,1,0)*max(s[n+3],1);
      }
    }
  if(a!=1&&b!=0)
      ret=(ret+rec(n+2,s[n+2],s[n+3]))%mod;
    if(a!=1&&b!=1)
      ret=(ret+rec(n+2,0,s[n+3])*max(s[n+2],1))%mod;
  return dp[n][a][b]=ret%mod;
  }

int main(){
  cin>>t;
   m=t.size();
  rep(i,m){
    if(t[i]=='0')s[i]=0;
    if(t[i]=='1')s[i]=1;
    if(t[i]=='?')s[i]=2;
    }
  s[m]=0;
  rep(i,m+1)rep(j,3)rep(k,3){
    dp[i][j][k]=-1;
    }
  dp[m-1][0][0]=0;
  dp[m-1][2][0]=1;
  dp[m-1][1][0]=1;

  all[m]=1;
  rep(i,m){
    if(s[m-i-1]==2)all[m-i-1]=2*all[m-i]%mod;
    else all[m-i-1]=all[m-i];
    }
  cout<<rec(0,s[0],s[1])<<endl;
  return 0;
  }

#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>

using namespace std;

#define int long long

const int N = 3e5 + 5 , mod = 1e9 + 7;

//void add(int &x , int y){
//	x += y;
//	if(x >= mod)
//		x -= mod;
//}

char s[N];

long long n , ans;

long long f[N][3][3];

void add(long long &a, long long b) {
	a += b, ((a > mod) ? (a -= mod) : 0);
}

main() {
	scanf("%s", s + 1);
	n = strlen(s + 1);
	f[0][0][0] = 1;
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < 3; j++) {
			for(int k = 0; k < 3; k++) {
				if(s[i + 1] != '0') {
					if(k)
						add(f[i + 1][j][k - 1], f[i][j][k]);
					else add(f[i + 1][min(j + 1, (long long)2)][k], f[i][j][k]);
				}
				if(s[i + 1] != '1') {
					if(k == 2)
						add(f[i + 1][j][1], f[i][j][k]);
					else add(f[i + 1][j][k + 1], f[i][j][k]);
				}
			}
		}
	}
	for(int i = 0; i < 3; i++)
		for(int j = 0; j <= i; j++)
			add(ans, f[n][i][j]);
	cout << 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;
using P = pair<int,int>;

int main(){
    int l, r;
    cin >> l >> r;
    if(r - l >= 2019) cout << 0 << endl;
    else{
        vector<int> n;
        for(int i = l; i <= r; i++){
            n.push_back(i % 2019);
        }
        vector<int> m;
        rep(i,n.size()){
            for(int j = i+1; j < n.size(); j++) m.push_back((n[i]*n[j])%2019);
        }
        sort(m.begin(), m.end());
        cout << m[0] << endl;
    }
}

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

int main() {
    ll l, r;
    cin >> l >> r;
    r = min(l+2019, r);
    ll ans = INF;
    for (ll i = l; i <= r; i++) {
        for (ll j = i+1; j <= r; j++) {
            //i = i%2019;
            //j = j%2019;
            ans = min(ans, (i*j)%2019);
        }
    }
    cout << ans << endl;
    return 0;
}


// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")

#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <cassert>
#include <unordered_set>
#include <unordered_map>
#include <set>
#include <map>
#include <queue>
#include <random>
#include <numeric>
#include <time.h>
#include <stack>
#include <bitset>

#define prev asasddlsa
#define rank aljds

#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i >= l; i++)

using namespace std;

typedef long long ll;
typedef double dbl;

template<typename T>
void print(const vector<T>& s){
    for (auto x : s)
        cout << x << " ";
    cout << endl;
}

template<class T>
void print(const T* s, int n){
    for (int i = 0; i < n; i++)
        cout << s[i] << ' ';
    cout << endl;
}

template<class T>
void print(vector<vector<T>> s){
    for (int i = 0; i < s.size(); i++)
        print(s[i]);
}

int solve(){
    int n;
    cin >> n;
    vector<int> s(2 * n);
    for (int& x : s)
        cin >> x;
    sort(s.begin(), s.end());
    int res = 0;
    for (int i = 0; i < 2 * n; i += 2){
        res += s[i];
    }
    cout << res << endl;
    return 0;
}

int main(){
    srand(time(NULL));
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;
    int t = 1;
    // cin >> t;
    while (t--)
        solve();
    return 0;
}

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

typedef long long ll;

ll maxSubarrayXOR(ll a[], int n) {
    int index = 0;
    for(int i = 60; i >= 0; i--) {
        int pos = index;
        int f = 0;
        for(int j = index; j < n; j++) {
            if(a[j] & (1LL << i)) f = 1, pos = j;
        }
        if(!f) continue;
        swap(a[index], a[pos]);
        for(int j = 0; j < n; j++) {
            if(j != index && (a[j] & (1LL << i))) a[j] ^= a[index];
        }
        index++;
    }
    ll res = 0;
    for(int i = 0; i < n; i++) res ^= a[i];
    return res;
}

int n;
ll a[100010], ans = 0;
int main() {
    cin >> n;
    for(int i = 0; i < n; i++) {
        scanf("%lld", a+i);
        ans ^= a[i];
    }
    for(int i = 0; i < n; i++) a[i] &= ~ans;
    cout << ans + 2*maxSubarrayXOR(a, n);
}


#include <bits/stdc++.h>
using namespace std;
int main() {
    string s;
    int a[26];
    for (int i = 0; i < 26; i++) a[i] = 0;
    bool occur = true;
    cin >> s;
    for (int i = 0; i < s.size(); i++)
    {
        a[s[i] - 97]++;
    }
    for (int i = 0; i < 26; i++)
    {
        if (a[i] == 0)
        {
            occur = false;
            cout << char(i + 97);
            break;
        }
    }
    if (occur == true) cout << "None";
}

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

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

	vector<bool> v(26);
	for (int i = 0; i < S.size(); i++) {
		char ch = S.at(i);
		int n = (int)ch - 97;
		v.at(n) = 1;
	}

	string ans = "None";
	for (int i = 0; i < 26; i++) {
		if (v.at(i) == 0) {
			ans = (char)i + 97;
			break;
		}
	}

	cout << ans << endl;
}


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

int main(){
    int n,m;
    cin>>n>>m;
    string ans{};
    rep(i,n) ans.push_back('a');
    bool err=false;
    rep(i,m){
        int s;
        char c;
        cin>>s>>c;
        s--;
        if(ans[s]=='a'||ans[s]==c){
            ans[s]=c;
        }else{
            err=true;
        }
    }
    if(ans[0]=='0'&&n>1) err=true;
    rep(i,n){
        if(ans[i]=='a'){
            if(i==0&&n>1) ans[i]='1';
            else ans[i]='0';
        }
    }
    if(!err) cout<<ans<<endl;
    else cout<<-1<<endl;
}

#include<cmath>
#include<queue>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define INF 1000005
#define MAXN 500000
int read()
{
    int f=1,x=0;char s=getchar();
    while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}
    while(s>='0'&&s<='9'){x=x*10+s-'0';s=getchar();}
    return x*f;
}
struct node{
	int key;
	node *ch[2],*fa;
};
node tree[MAXN+5];
node *Root,*NIL,*ncnt;
void Init()
{
	NIL=&tree[0];
	NIL->fa=NIL->ch[0]=NIL->ch[1]=NIL;
	ncnt=&tree[1];
	Root=NIL;
	return ;
}
inline node *NewNode(int val)
{//插入新的?点
	node *p=++ncnt;
	p->key=val;
	p->fa=p->ch[0]=p->ch[1]=NIL;
	return p;
}
void Insert(node *&rt,node *fa,int val)
{//插入(?造二叉排序?)
	if(rt==NIL)
	{
		rt=NewNode(val);
		rt->fa=fa;
		return ;
	}
	int d=(val>=rt->key);
	Insert(rt->ch[d],rt,val);
	return ;
}
void InOrder(node *rt)
{//?出
	if(rt==NIL) return ;
	InOrder(rt->ch[0]);
	printf(" %d",rt->key);
	InOrder(rt->ch[1]);
	return ;
}
void PreOrder(node *rt)
{//?出
	if(rt==NIL) return ;
	printf(" %d",rt->key);
	PreOrder(rt->ch[0]);
	PreOrder(rt->ch[1]);
	return ;
}
node *Find(node *rt,int val)
{//找一?在??中
	if(rt==NIL) return NIL;
	if(rt->key==val) return rt;
	int d=(val>=rt->key);
	return Find(rt->ch[d],val);
}
node *FindNext(node *rt)
{
	if(rt==NIL) return NIL;
	node *y=rt->ch[1];
	while(y->ch[0]!=NIL)
		y=y->ch[0];
	return y;
}
void Delete(node *rt,int val)
{
	node *x,*y,*z=Find(rt,val);
	if(z==NIL) return ;
	if(z->ch[0]==NIL||z->ch[1]==NIL)
		y=z;
	else
		y=FindNext(z);
	if(y->ch[0]!=NIL)
		x=y->ch[0];
	else
		x=y->ch[1];
	if(x!=NIL)
		x->fa=y->fa;
	if(y->fa==NIL)
		Root=x;
	else
	{
		int d=(y==y->fa->ch[1]);
		y->fa->ch[d]=x;
	}
	if(y!=z)
		z->key=y->key;
	return ;
}
int main()
{
    int n=read(),x;
	char op[20];
	Init();
	for(int i=1;i<=n;i++)
	{
		scanf("%s",op);
		if(op[0]=='i')
		{
			x=read();
			Insert(Root,NIL,x);
		}
		else if(op[0]=='f')
		{
			x=read();
			if(Find(Root,x)==NIL)
				printf("no\n");
			else
				printf("yes\n");
		}
		else if(op[0]=='d')
		{
			x=read();
			Delete(Root,x);
		}
		else
		{
			InOrder(Root);
			puts("");
			PreOrder(Root);
			puts("");
		}
	}
	return 0;
}


#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

// Acknowledgement: Special thanks to kyomukyomupurin, who developed this
// template.
template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  int n = 0;
  for (auto e : vec) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& st) {
  int n = 0;
  for (auto e : st) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) {
  int n = 0;
  for (auto e : mp) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
  for (T& e : vec) is >> e;
  return is;
}

#ifdef LOCAL
#define debug(...) \
  std::cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

using namespace std;
using int64 = long long;

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<int>> a(H, vector<int>(W));
  for (int i = 0; i < H; i++) {
    cin >> a[i];
  }
  int n = 0;
  string ans = "";
  vector<int> od_row_idx;
  for (int i = 0; i < H; i++) {
    vector<int> od_idx;
    for (int j = 0; j < W; j++) {
      if (a[i][j] % 2 == 1) {
        od_idx.push_back(j);
      }
    }
    debug(od_idx);
    if ((int)od_idx.size() == 0) continue;
    for (int j = 0; j < (int)od_idx.size() - 1; j += 2) {
      for (int k = od_idx[j]; k < od_idx[j + 1]; k++) {
        ans += to_string(i + 1) + ' ' + to_string(k + 1) + ' ' +
               to_string(i + 1) + ' ' + to_string(k + 2) + '\n';
        n++;
      }
    }
    if ((int)od_idx.size() % 2 == 1) {
      for (int k = od_idx.back(); k < W - 1; k++) {
        ans += to_string(i + 1) + ' ' + to_string(k + 1) + ' ' +
               to_string(i + 1) + ' ' + to_string(k + 2) + '\n';
        n++;
      }
      od_row_idx.push_back(i);
    }
  }
  if ((int)od_row_idx.size() > 1) {
    for (int j = 0; j < (int)od_row_idx.size() - 1; j += 2) {
      for (int k = od_row_idx[j]; k < od_row_idx[j + 1]; k++) {
        ans += to_string(k + 1) + ' ' + to_string(W) + ' ' + to_string(k + 2) +
               ' ' + to_string(W) + '\n';
        n++;
      }
    }
  }
  cout << n << endl;
  cout << ans << endl;
  return 0;
}

#include <bits/stdc++.h>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
using ld = long double;
ll mod = 1000000007;

int main() {
    ll h, w;
    cin >> h >> w;
    ll a[h][w];
    rep(i, h) {
        rep(j, w) { cin >> a[i][j]; }
    }
    vector<pair<pair<ll, ll>, pair<ll, ll>>> ans;

    rep(i, h) {
        rep(j, w - 1) {
            if (a[i][j] % 2 == 0) {
                continue;
            }
            a[i][j + 1]++;
            pair<ll, ll> before, after;
            before = make_pair(i, j);
            after = make_pair(i, j + 1);
            ans.push_back(make_pair(before, after));
        }
    }

    rep(i, h - 1) {
        if (a[i][w - 1] % 2 == 0) {
            continue;
        }
        a[i + 1][w - 1]++;
        pair<ll, ll> before, after;
        before = make_pair(i, w - 1);
        after = make_pair(i + 1, w - 1);
        ans.push_back(make_pair(before, after));
    }

    cout << ans.size() << endl;
    for (auto p : ans) {
        cout << p.first.first + 1 << " " << p.first.second + 1 << " "
             << p.second.first + 1 << " " << p.second.second + 1 << endl;
    }

    return 0;
}


#include <bits/stdc++.h>
#define rep(i,s,n) for (int i = (s); i < (n); i++)
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n+2, 0);
  rep(i,1,n+1) cin >> a[i];
  int k = 0;
  rep(i,0,n+1) {
    k += abs(a[i] - a[i+1]);
  }
  rep(i,1,n+1) {
    int ans = k - abs(a[i-1] - a[i]) - abs(a[i] - a[i+1]);
    ans += abs(a[i-1] - a[i+1]);
    cout << ans << "\n";
  }
  return 0;
}

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

int main(){
	int n; cin >> n;
	vector<int> a(n);
	rep(i,n) cin >> a[i];
	deque<int> d;
	rep(j,n){
		int i = lower_bound(d.begin(), d.end(), a[j]) - d.begin();
		if(i == 0){
			d.push_front(a[j]);
		}else{
			d[i-1] = a[j];
		}
	}
	int ans = d.size();
	cout << ans << endl;
	return 0;
}