// ref. https://img.atcoder.jp/dwacon5th-prelims/editorial.pdf

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << 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; }

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

ll n;
string s;

ll solve(ll k) {
  ll d_cnt = 0, m_cnt = 0;
  ll now = 0; // current contribution
  ll ans = 0;
  rep(i, n) {
    // At first, decrease from i-k
    if (i >= k) {
      char target = s[i-k];
      if (target == 'D') {
        --d_cnt;
        now -= m_cnt; // decrease contribution by this D
      } else if (target == 'M') {
        --m_cnt;
      } else {
        // Do nothing
      }
    }

    // Next, add contribution from i
    if (s[i] == 'D') {
      ++d_cnt;
    } else if (s[i] == 'M') {
      ++m_cnt;
      now += d_cnt; // increase contribution by this M
      // cout << "d_cnt:" << d_cnt << endl;
    } else if (s[i] == 'C') {
      // cout << "now:" << now << endl;
      ans += now;
    }
  }
  return ans;
}

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  cin >> n;
  cin >> s;
  ll q;
  cin >> q;
  rep(iter, q) {
    ll k;
    cin >> k;
    ll ans = solve(k);
    cout << ans << endl;
  }
}


#include <bits/stdc++.h>
using namespace std;
bool gt(int h1,int w1,int h2,int w2) {
    return h1*h1+w1*w1>h2*h2+w2*w2||(h1*h1+w1*w1==h2*h2+w2*w2&&h1>h2);
}
int main() {
    int h,w;
    while(scanf("%d %d",&h,&w),h) {
        int ans_h=514,ans_w=514;
        for(int H=1;H<=150;H++) {
            for(int W=H+1;W<=150;W++) {
                if(gt(H,W,h,w)&&gt(ans_h,ans_w,H,W)) {
                    ans_h=H,ans_w=W;
                }
            }
        }
        printf("%d %d\n",ans_h,ans_w);
    }
}

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

bool primenumver(int a){
	for (int b = 2;; b += 2) {
		if (a%b == 0)return false;
		if ((b + 1)*(b+ 1) >a)return true;
		if (b == 2)b--;
	}
}
int main()
{
	while (1) {
		int a;
		cin >> a;
		if (a == 0)break;
		if (a % 2 == 0) {
			for (int b = a-1;; b -= 2) {
				if (primenumver(b) && primenumver(b - 2)) { cout << b - 2 << " " << b<<endl; break; }
			}
		}
		else {
			for (int b = a;; b -= 2) {
				if (primenumver(b) && primenumver(b - 2)) { cout << b - 2 << " " << b<<endl; break; }
			}
		}
	}
}


#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

using ll = long long;

class Stream{
public:
    Stream(){

    }
    //配列以外の入力を受け取る
    void read(){

    }
    template<typename First, typename... Rest>
    void read(First& first, Rest&... rest){
        cin >> first;
        read(rest...);
    }
    //配列を区切って出力する
    template<typename T>
    void write_vec(vector<T>& v, char divider){
        for(size_t i = 0; i < v.size(); i++){
            cout << v[i] << divider;
        }
    }
};

int main(){
    Stream io;

    int A, B, C, D;
    io.read(A, B, C, D);
    string ans;
    if(A + B < C + D){
        ans = "Right";
    }
    else if(A + B == C + D){
        ans = "Balanced";
    }
    else{
        ans = "Left";
    }
    cout << ans;
    return 0;
}

#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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

const ll INF=1e9+7;

int main()
{
    ll n,m;
    cin >> n >> m;
    vector<ll> dv;
    for(ll i=1;i*i<=m;i++){
        if(m%i==0){
            if(i*i==m){
                dv.push_back(i);
            }
            else{
                dv.push_back(i);
                dv.push_back(m/i);
            }
        }
    }
    sort(dv.begin(),dv.end());
    auto it=lower_bound(dv.begin(),dv.end(),n)-dv.begin();
    cout << m/dv[it] << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define MAXN 2005
#define open(s) freopen( s".in", "r", stdin ), freopen( s".out", "w", stdout )
#define fp( i, b, e ) for ( int i(b), I(e); i <= I; ++i )
#define fd( i, b, e ) for ( int i(b), I(e); i >= I; --i )
#define go( i, b ) for ( int i(b), v(to[i]); i; v = to[i = nxt[i]] )
template<typename T> inline void cmax( T &x, T y ){ x < y ? x = y : x; }
template<typename T> inline void cmin( T &x, T y ){ y < x ? x = y : x; }
#define getchar() ( p1 == p2 && ( p1 = bf, p2 = bf + fread( bf, 1, 1 << 21, stdin ), p1 == p2 ) ? EOF : *p1++ )
char bf[1 << 21], *p1(bf), *p2(bf);
template<typename T>
inline void read( T &x ){ char t(getchar()), flg(0); x = 0;
	for ( ; !isdigit(t); t = getchar() ) flg = t == '-';
	for ( ; isdigit(t); t = getchar() ) x = x * 10 + ( t & 15 );
	flg ? x = -x : x;
}

clock_t t_bg, t_ed;

int N, M, Q;
int s[MAXN][MAXN];
int s1[MAXN][MAXN], s2[MAXN][MAXN];
#define sum( s, a, b, c, d ) ( s[c][d] + s[a-1][b-1] - s[c][b-1] - s[a-1][d] )

int main(){
	t_bg = clock();
	read(N), read(M), read(Q);
	fp( i, 1, N ) fp( j, 1, M ){
		while( (s[i][j] = getchar()) != '0' && s[i][j] != '1' );
		s[i][j] &= 1;
	}
	fp( i, 1, N ) fp( j, 1, M - 1 ) s1[i][j] = s1[i][j - 1] + s1[i - 1][j] - s1[i - 1][j - 1] + (s[i][j] & s[i][j + 1]);
	fp( i, 1, N - 1 ) fp( j, 1, M ) s2[i][j] = s2[i][j - 1] + s2[i - 1][j] - s2[i - 1][j - 1] + (s[i][j] & s[i + 1][j]);
	fp( i, 1, N ) fp( j, 1, M ) s[i][j] += s[i][j - 1] + s[i - 1][j] - s[i - 1][j - 1];
	while( Q-- ){
		int a, b, c, d;
		read(a), read(b), read(c), read(d);
		printf( "%d\n", sum(s, a, b, c, d) - sum(s1, a, b, c, d - 1) - sum(s2, a, b, c - 1, d) );
	}
	t_ed = clock();
	fprintf( stderr, "\n========info========\ntime : %.3f\n====================\n", (double)( t_ed - t_bg ) / CLOCKS_PER_SEC );
	return 0;
}


#include <bits/stdc++.h>
#define mset(a, b) memset(a, b, sizeof(a))
#define mcpy(a, b) memcpy(a, b, sizeof(a))
#define sor(a, l, r) sort(a + l, a + r + 1);
#define reve(a, l, r) reverse(a + l, a + r + 1)
using namespace std;
typedef long long LL;
const int N = 205;
const int MAXN = 100005;

template <typename T> inline void read(T &AKNOI) {
	T x = 0, flag = 1;
	char ch = getchar();
	while (!isdigit(ch)) {
		if (ch == '-') flag = -1;
		ch = getchar();
	}
	while (isdigit(ch)) {
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	AKNOI = flag * x;
}

namespace ModCalculator {
	const int MOD = 1e9 + 7;
	inline void Inc(int &x, int y) {
		x += y; if (x >= MOD) x -= MOD;
	}
	inline void Dec(int &x, int y) {
		x -= y; if (x < 0) x += MOD;
	}
	inline int Add(int x, int y) {
		Inc(x, y); return x;
	}
	inline int Sub(int x, int y) {
		Dec(x, y); return x;
	}
	inline int Mul(int x, int y) {
		return 1LL * x * y % MOD;
	}
}
using namespace ModCalculator;

int n, X, a[N];
int dp[2][MAXN];

void init() {
	read(n); read(X);
	for (int i = 1; i <= n; ++i) {
		read(a[i]);
	}
	sor(a, 1, n);
}

void solve() {
	int pre = 0, cur = 1;
	dp[pre][X] = 1;
	int ans = 0;
	for (int i = n; i >= 1; --i) {
		mset(dp[cur], 0);
		for (int j = 0; j <= X; ++j) {
			Inc(dp[cur][j], Mul(dp[pre][j], i - 1));
			Inc(dp[cur][j % a[i]], dp[pre][j]);
		}
		swap(pre, cur);
	}
	for (int i = 1; i <= X; ++i) {
		Inc(ans, Mul(i, dp[pre][i]));
	}
	printf("%d\n", ans);
}

int main() {
	init();
	solve();
	return 0;
}

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

const int N_MAX = 100;
const int INF = 1000000;

struct edge{
    int to, cap, rev;
    edge(int t, int c, int r): to(t), cap(c), rev(r){}
};

vector<edge> G[N_MAX * 2];
bool used[N_MAX * 2];

void add_edge(int from, int to, int cap){
    G[from].emplace_back(to, cap, G[to].size());
    G[to].emplace_back(from, 0, G[from].size()-1);
}

int dfs(int v, int t, int f){
    if (v == t) return f;
    used[v] = true;
    for(int i = 0; i < G[v].size(); i++){
        edge &e = G[v][i];
        if (!used[e.to] && e.cap > 0){
            int d = dfs(e.to, t, min(f, e.cap));
            if (d > 0){
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

int max_flow(int s, int t){
    int flow = 0;
    for(;;){
        memset(used, 0, sizeof(used));
        int f = dfs(s, t, INF);
        if (f == 0) return flow;
        flow += f;
    }
}

int main(){
    int n;
    cin >> n;
    vector<pair<int, int>> RED;
    vector<pair<int, int>> BLUE;
    for(int i = 0; i < n; i++){
        int a, b;
        cin >> a >> b;
        RED.emplace_back(a, b);
    }
    for(int i = 0; i < n; i++){
        int c, d;
        cin >> c >> d;
        BLUE.emplace_back(c, d);
    }
    for(int i = 1; i <= n; i++){
        int a = RED[i-1].first, b = RED[i-1].second;
        for(int j = 1; j <= n; j++){
            int c = BLUE[j-1].first, d = BLUE[j-1].second;
            if (a < c && b < d){
                add_edge(i, n+j, 1);
            }
        }
    }
    for(int i = 1; i <= n; i++){
        add_edge(0, i, 1);
        add_edge(n+i, 2 * n + 1, 1);
    }
    cout << max_flow(0, 2 * n + 1) << endl;
    return 0;
}


#include <iostream>
#include <regex>
#include <stdio.h>
#include <string>

using namespace std;

int main() {
  string S;
  cin >> S;
  regex rx(R"(^A[a-z][a-z]*?C[a-z]*?[a-z]$)");
  if (regex_match(S, rx)) {
    printf("AC\n");
  } else {
    printf("WA\n");
  }
}


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

int main(){
int n,k;
  cin >> n >> k;
int x[n];
  for(int i=0;i<n;i++){
  cin >> x[i];
  }
  sort(x,x+n,greater<int>());
int sum=0;
  for(int i=0;i<k;i++){
  sum+=x[i];
  }
  cout << sum << endl;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PLL = pair<ll, ll>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repn(i,n) for(int i = 0; i <= (int)(n); i++)
#define srep(i,l,n) for(int i = l; i < (int)(n); i++)
#define srepn(i,l,n) for(int i = l; i <= (int)(n); i++)
#define drep(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define drepn(i,n) for(int i = (int)(n); i >= 0; i--)
#define size(s) (int)s.size()
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<typename T> inline istream& operator>>(istream &i, vector<T> &v) {rep(j, size(v)) i >> v[j]; return 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; }
template<class T> T gcd(T a, T b) {if(b==0)return a; else return gcd(b,a%b);}
template<class T> T lcm(T a, T b) {return a/gcd(a,b)*b;}
template<class T = int> using V = vector<T>;
template<class T = int> using VV = vector<V<T>>;
bool isIn(int i, int j, int h, int w) {return i >= 0 && i < h && j >= 0 && j < w;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define ep emplace_back

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    V<> a(n);
    cin >> a;
    sort(rall(a));
    int ans = accumulate(a.begin(), a.begin() + k, 0);
    cout << ans << endl;
}


#include <iostream>
#include <vector>
#include <queue>
using namespace std;
struct edge{
    int to;
    int cap;
    int rev;
};
struct Dinic{
    int V;
    vector<int> level, used;
    vector<vector<edge>> G;
    Dinic(int N){
        V = N;
        used.resize(V, 0);
        level.resize(V, -1);
        G.resize(V);
    }
    void add(int u, int v, int c){
        edge e1 = {v, c, (int)G[v].size()};
        G[u].push_back(e1);
        edge e2 = {u, 0, (int)G[u].size() - 1};
        G[v].push_back(e2);
    }
    void bfs(int s){
        level.assign(V, -1);
        queue<int> q;
        q.push(s);
        level[s] = 0;
        while(!q.empty()){
            int v = q.front();
            q.pop();
            for(edge e: G[v]){
                if(e.cap > 0 && level[e.to] < 0){
                    level[e.to] = level[v] + 1;
                    q.push(e.to);
                }
            }
        }
    }
    int dfs(int s, int t, int f){
        if(s == t) return f;
        for(int &i = used[s]; i < (int)G[s].size(); i++){
            edge &e = G[s][i];
            if(e.cap > 0 && level[e.to] > level[s]){
                int d = dfs(e.to, t, min(f, e.cap));
                if(d > 0){
                    e.cap -= d;
                    G[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }
    int solve(int s, int t){
        int flow = 0;
        int INF = 1e9;
        while(1){
            bfs(s);
            if(level[t] < 0) return flow;
            used.assign(V, 0);
            int f;
            while((f = dfs(s, t, INF)) > 0) flow += f;
        }
    }
};

int main(){
    int N;
    cin >> N;
    Dinic Ford(2 * N + 2);
    int can[N][N];//can[i][j] = 1でペアが作れる
    vector<int> a(N), b(N), c(N), d(N);
    for(int i = 0; i < N; i++) cin >> a[i] >> b[i];
    for(int i = 0; i < N; i++) cin >> c[i] >> d[i];
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            if(a[i] < c[j] && b[i] < d[j]) can[i][j] = 1;
            else can[i][j] = 0;
        }
    }
    for(int i = 0; i < N; i++){
        Ford.add(2 * N, i, 1);
        Ford.add(N + i, 2 * N + 1, 1);
    }
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            if(can[i][j]) Ford.add(i, N + j, 1);
        }
    }
    int ans = Ford.solve(2 * N, 2 * N + 1);
    cout << ans << endl;
}

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

int main(){
  int n;
  cin >> n;
  vector<pair<int,int>> ab(n),cd(n);
  for(int i=0;i<n;++i){
    int a,b;
    cin >> a >> b;
    ab[i]=make_pair(b,a);
  }
  for(int i=0;i<n;++i){
    int c,d;
    cin >> c >> d;
    cd[i]=make_pair(c,d);
  }
  sort(ab.begin(),ab.end(),greater<pair<int,int>>());
  sort(cd.begin(),cd.end());

  vector<bool> f(n,false);
  int cnt=0;

  for(int i=0;i<n;++i){
    int c=cd[i].first;
    int d=cd[i].second;
    for(int j=0;j<n;++j){
      int b=ab[j].first;
      int a=ab[j].second;
      if(f[j])continue;
      if(a<c && b<d){
        f[j]=true;
        cnt++;
        break;
      }
    }
  }
  //int cnt=0;
  //for(int i=0;i<n;++i)if(f[i])cnt++;

  cout << cnt << endl;
  return 0;

}


#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF (1<<29)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CLR(a) memset(a,0,sizeof(a))
const int dx[] = {-1,0,0,1},dy[] = {0,1,-1,0};

typedef long long int ll;

using namespace std;

int main(){
    vector<int> w(10);
    vector<int> k(10);
    REP(i,10){
	cin >> w[i];
    }
    REP(i,10){
	cin >> k[i];
    }
    sort(RALL(w));
    sort(RALL(k));
    printf("%d %d\n",w[0]+w[1]+w[2],k[0]+k[1]+k[2]);
    return 0;
}

#include"bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
	int h, w,n,tmp=0;
	cin >> h >> w >> n;
	REP(i, max(h,w)) {
		tmp += max(h, w);
		if (n <= tmp) {
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}


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

using namespace std;
using lint = int64_t;
using P = pair<int, int>;
using D = pair<double, double>;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
#define repn(i, a, b) for(int i = (a); i < (b); ++i)
#define Rep(i, n) for (int i = (n); i >= 0; --i)
#define All(vec) vec.begin(), vec.end()
#define cend printf("\n")

//constexpr lint mod = 998'244'353LL;
constexpr lint mod = 1000'000'007LL;
constexpr lint inf = 3LL * mod * mod;
const double Pi = 2.0 * acos(0.0);

template<class T> using prique     = priority_queue<T>;
template<class T> using prique_inv = priority_queue<T, vector<T>, greater<T>>;
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& rhs) { return is >> rhs.first >> rhs.second; }
template<class T, class U>inline ostream& operator<<(ostream& os, const pair<T, U>& rhs) { return os << rhs.first << " " << rhs.second << "\n"; }
template<class InputIterator> void arrin(InputIterator first, InputIterator last) { for (; first != last; ++first) cin >> (*first); }
template<class InputIterator> void arrout(InputIterator first, InputIterator last) {
	for (; first != last; ++first) {
		cout << (*first) << " ";
	}
	cout << "\n";
}

constexpr bool pri(lint x) { for (lint i = 2; i * i <= x; ++i) if (x % i == 0) return false; return 1 < x; }

inline double dis(D a, D b) { return hypot(a.first - b.first, a.second - b.second); }

lint fact[3000000];
void fact_init(lint n) {
	if (3000000 <= n) return;
	fact[0] = fact[1] = 1;
	for (lint i = 2; i <= n; ++i) {
		fact[i] = i * fact[i - 1];
		if (mod <= fact[i]) fact[i] %= mod;
	}
}

lint modpow(lint x, lint n, lint m = mod) {
	lint res = 1;
	while (n > 0) {
		if (n & 1) {
			res *= x;
			if (m <= res) res %= m;
		}
		x *= x;
		if (m <= x) x %= m;
		n >>= 1;
	}
	return res;
}

lint intpow(lint x, lint n) {
	lint res = 1;
	while (n > 0) {
		if (n & 1) res *= x;
		x *= x;
		n >>= 1;
	}
	return res;
}

lint comb(lint n, lint r) {
	if (r == 0 || r == n) return 1;
	lint res = fact[n] * modpow(fact[n - r], mod - 2) % mod * modpow(fact[r], mod - 2) % mod;
	return res < 0 ? res + mod : res;
}

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

int n, k;
bool f(vector<int>& a) {
	vector<int>b(n + 1);
	rep(i, n) {
		b[max(0, i - a[i])]++;
		b[min(n, i + a[i] + 1)]--;
	}
	rep(i, n) {
		b[i + 1] += b[i];
	}
	bool res = true;
	rep(i, n) {
		a[i] = b[i];
		res &= (a[i] == n);
	}
	return res;
}
int main() {
	cin >> n >> k;
	vector<int>a(n);
	rep(i, n) {
		cin >> a[i];
	}
	rep(i, k) {
		if (f(a)) break;
	}
	for (int e : a) cout << e << " ";
}

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

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


//
// Created by TakahiroYamaji on 2020/08/13.
//
#include<iostream>
#include<queue>
typedef long long ll;
int D;
ll G;
int p[11];
ll c[11];

ll solve(int i){
    ll ans = 0;
    ll sum = 0;
    std::priority_queue<ll>P;
    for (int j=0;j<D;j++){
        //std::cout << j << std::endl;
        if (i & (1 << j)){
            sum += (j + 1) * 100 * p[j] + c[j];
            ans += p[j];
        }else{
            P.push(j);
        }
    }

    //微調整
    while (!P.empty()){
        int s = P.top();
        P.pop();
        for (int i=1;i<=p[s];i++){
            if (sum >= G){
                return ans;
            }
            ans++;
            sum += (s + 1) * 100;
        }
    }
    //std::cout << sum << std::endl;
    if (sum >= G){
        return ans;
    }else{
        return 1e12;
    }
}

int main(){
    std::cin >> D >> G;
    for (int i=0;i<D;i++){
        std::cin >> p[i] >> c[i];
    }

    ll min_v = 1e15;
    //bit 全探索
    for (int i=0;i<(1 << D);i++){
        ll ans1 = solve(i);
        //std::cout << ans1 << std::endl;
        if (min_v > ans1){
            min_v = ans1;
        }
    }
    std::cout << min_v << std::endl;
    return 0;
}

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

int soredake(int point, int kazu, int bonasu, int goal) {
  int tokukazu = goal / point;
  if (goal % point > 0) {
    tokukazu++;
  }
  if (tokukazu > kazu) {
    tokukazu = kazu;
  }
  return tokukazu;
}

int search(vector<vector<int>> questions, int goal) {

  int minimum = 0;
  for (int i = 0; i < questions.size(); i++) {
    minimum += questions.at(i).at(1);
  }
  for (int i = 0; i < questions.size(); i++) {
    int point = questions.at(i).at(0);
    int kazu = questions.at(i).at(1);
    int bonasu = questions.at(i).at(2);
    int goukei = questions.at(i).at(3);

    vector<vector<int>> q = questions;
    q.erase(q.begin() + i);
    if (goukei < goal) {
      int nokori = search(q, goal - goukei) + kazu;
      if (nokori < minimum) {
        minimum = nokori;
      }
    } else {
      int nokori = soredake(point, kazu, bonasu, goal);
      if (nokori < minimum) {
        minimum = nokori;
      }
    }
  }
  return minimum;
}

int main() {
  int d, g;
  cin >> d >> g;

  vector<vector<int>> questions(d, vector<int>(4));
  for (int i = 0; i < d; i++) {
    questions.at(i).at(0) = 100 * (i + 1);
    cin >> questions.at(i).at(1);
    cin >> questions.at(i).at(2);
    questions.at(i).at(3) =
        questions.at(i).at(0) * questions.at(i).at(1) + questions.at(i).at(2);
  }

  cout << search(questions, g) << endl;
}


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

int N;
vector<int> A(210);

int main() {
  cin>>N;
  for(int i=0;i<N;i++) cin>>A.at(i);
  int count=0;

  while(true){
    bool exist_odd=false;
    for(int i=0;i<N;i++){
      if(A.at(i)%2!=0) exist_odd=true;
    }

    if(exist_odd) break;

    for(int i=0;i<N;i++){
     A.at(i)/=2;
    }
    count++;
  }

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

#include<iostream>
using namespace std;
const int BUF = 2000005;
const int MOD = 1000000007;

int add(int a, int b) {
    return (a + b) % MOD;
}

int sub(int a, int b) {
    return (a - b + MOD) % MOD;
}

int mul(int a, int b) {
    return 1LL * a * b % MOD;
}

int nNum;
int a[BUF], b[BUF];

void read() {
    cin >> nNum;
    for (int i = 0; i < nNum; ++i) cin >> a[i];
    for (int i = 0; i < nNum; ++i) cin >> b[i];
}

void work() {
    static int s[BUF];
    static int t[BUF];
    for (int i = 0; i < nNum; ++i) {
        s[i] = a[i] ^ a[(i + 1) % nNum];
        t[i] = b[i] ^ b[(i + 1) % nNum];
    }

    const int P = 1<<30;

    int sHash = 0;
    int tHash = 0;
    for (int i = 0; i < nNum; ++i) {
        sHash = add(mul(sHash, P), s[i]);
        tHash = add(mul(tHash, P), t[i]);
    }

    int pPowNNum = 1;
    for (int i = 0; i < nNum - 1; ++i) {
        pPowNNum = mul(pPowNNum, P);
    }

    for (int shift = 0; shift < nNum; ++shift) {
        if (sHash == tHash) {
            cout << shift << ' ' << (a[shift] ^ b[0]) << endl;
        }
        sHash = sub(sHash, mul(s[shift], pPowNNum));
        sHash = mul(sHash, P);
        sHash = add(sHash, s[shift]);
    }
}

int main() {
    read();
    work();
    return 0;
}


//om namah shivaay
//faith over fear
//no one wants to die,yet death is the destination we all share

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

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,n) for(i=0;i<n;i++)
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define ford(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define fora(it,x) for(auto it:x)
#define PI 3.14159265
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"

typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef long double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

int main(){
    ll a[3];
    cin>>a[0]>>a[1]>>a[2];
    sort(a,a+3);
    cout<<(a[0]+a[1]);

}

#include <iostream>
#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>
#include <math.h>
#define int long long
using namespace std;
signed main() {
    int A,B,C;
    cin>>A>>B>>C;

    if((A<=C&&B>=C)||(B<=C&&A>=C)){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}


#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#include <map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using uld = unsigned long long;
using P = pair<int,int>;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}
//struct area

//function area

//main area
int main(){
    string s;
    cin >> s;
    int n = s.size();
    bool check = true;
    int C_place;

    //一個目
    if(s[0] != 'A'){
        check = false;
    }

    //二個目
    int cnt = 0;
    for(int i=2; i<n-1; i++){
        if(s[i] == 'C'){
            cnt++;
            C_place = i;
        }
    }
    if(cnt != 1) check = false;

    //三個目
    rep(i, n){
        if(i == C_place || i == 0) continue;
        if(!('a' <= s[i] && s[i] <= 'z')){
            check = false;
        }
    }
    cout << (check ? "AC" : "WA") << endl;
}
/*

一個ずつ判定する
・s[0] == 'A'
・2 <= i <= s.size()-2      cnt = 1
・上二つ以外の座標において'a' <= s[i] <= 'z'を満たす

*/

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

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

	string ans = "AC";
	if( S[0] != 'A' ) ans = "WA";
	else {
		string s = S.substr( 2, S.size() - 2 - 1 );
		int n = s.find( 'C' );
		if( n == string::npos ) ans = "WA";
		else if( s.find( 'C', n + 1 ) != string::npos ) ans = "WA";
		else {
			for( int i = 0; i < S.size(); i++ ) {
				if( i == 0 || S[i] == 'C' && 2 <= i && i <= S.size() - 2 ) continue;
				if( islower( S[i] ) == false ) ans = "WA";

			}
		}
	}

	cout << ans << endl;
}


#include<iostream>
using namespace std;
typedef long long ll;
int main(){
    ll n;
    while(cin>>n){
        ll ans,x;
        ans=n/11<<1;
        x=n%11;
        if(x>6)
            ans+=2;
        else if(x)
            ans++;
        cout<<ans<<endl;
    }
    return 0;
}

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
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; }
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;
const double PI = 3.1415926535897932;
const int MOD = 1e9 + 7;

//cin.tie(0);ios::sync_with_stdio(false);
int main() {
  ll x;
  cin >> x;

  ll ans = x / 11 * 2;
  x %= 11;

  if (x != 0) {
    if (x <= 6) {
      ans += 1;
    } else {
      ans += 2;
    }
  }

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


#ifdef __GNUC__
#pragma GCC target("avx2")
#pragma GCC optimize ("O20")
#pragma GCC optimize ("tree-vectorize")
#pragma GCC optimize("unroll-loops")
#define iss std::cin
#endif
#include "bits/stdc++.h"
#define rep(i, times) for(ll i = 0; i < (times); ++i)
#define p(x) (cout << x << "\n")
using ll = long long; using ld = long double; using namespace std;

#ifndef __GNUC__
string text =
R"X(
2
1
2 0
1
1 0
)X";
stringstream iss{text};
#endif

class HonestOrUnkind2
{
	ll N{0};
	vector<bool> h;//正直かどうかの仮定
	vector<vector<ll>> s;//証言
	void inp( ) {
		iss >> N;
		h.resize(N);
		s.resize(N, vector<ll>(N, 3));//3:言及せず 0:不親切呼ばわり 1:正直者認定
		rep(n, N) {
			ll K; iss >> K;//証言個数
			rep(k, K) {
				ll p, hn; iss >> p >> hn;//p番目の人は(n番が言うには)正直か
				s[n][--p] = hn;
			}
		}
	}
	inline bool consistentQ( ) {//仮定と矛盾しないかだけ調べる
		for (ll n = 0; n < N; ++n) {
			if (!h[n]) continue; //不親切なら無視
			for (ll p = 0; p < N; ++p) {//n番目の人がp番目の人に対して証言
				if (s[n][p] == 3) continue;
				if ((s[n][p] == 1) && !h[p]) return false;
				if ((s[n][p] == 0) && h[p]) return false;
			}
		}
		return true;
	}
	void changeSeikaku( ) {
		size_t NH{0}; // 正直者の最大人数
		const ll maxB{(1 << N)};
		for (ll b = 0; b < maxB; ++b) {//全員の状態を変える
			rep(n, N) { h[n] = (b >> n) & 1; }//n番の人が正直と仮定したか
			if (consistentQ( )) NH = max(NH, bitset<32>(b).count( ));
		}
		p(NH);
	}
public:
	void procedures( ) {
		inp( );
		changeSeikaku( );
	}
};

int main( ) {
	cin.tie(0);	ios::sync_with_stdio(0);
	class HonestOrUnkind2 a; a.procedures( );
}

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

inline void rd(int &X){
    X=0;int w=0;char ch=0;
    while(!isdigit(ch))w|=ch=='-',ch=getchar();
    while( isdigit(ch))X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
    X=w?-X:X;
}
int n,m,k;
int x[N],d[N],ans[N],t[N];
double a[N];

signed main()
{
    rd(n);
    for(int i=1;i<=n;i++)
        rd(x[i]),d[i]=i,ans[i]=i;
    rd(m);rd(k);
    for(int x,i=1;i<=m;i++)
        rd(x),swap(d[x],d[x+1]);
        while(k)
        {
            if(k&1)
            {
                for(int i=1;i<=n;++i)t[i]=ans[d[i]];
                for(int i=1;i<=n;++i)ans[i]=t[i];
            }
            for(int i=1;i<=n;++i)t[i]=d[d[i]];
            for(int i=1;i<=n;++i)d[i]=t[i];
            k>>=1;
        }
    for(int i=1;i<=n;i++)
        a[i]=x[ans[i]]-x[ans[i]-1];
    for(int i=1;i<=n;i++)
        printf("%.1f\n",a[i]+=a[i-1]);
}


#include <iostream>
using namespace std;

int main(void){
  int cd=0;
  char c;

  for (int i=0; i<3; i++){
    cin >> c;
    cd = (cd<<1) | (c=='R'?1:0);
  }
  cout << (cd["01121123"]) << endl;
  return 0;
}

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

int main(){

    string S;
    cin >> S;

    int i, l, count, max;
    l = S.length();
    count = 0;
    max = 0;

    for (i = 0; i < l; i++){

        if (S.at(i) == 'S'){
            count = 0;
        } else {
            count += 1;
            if (count > max) max = count;
        }
    }

    cout << max << "\n";

    return 0;
}


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

using namespace std;

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

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

const int INF=1e9;

void print(vi v){
	for(int i = 0; i < v.size(); i++){
		cout<<" "<<v[i];
	}
	cout<<endl;
}

int main(){
	string s;

	cin>>s;

	vi v(s.size(), 1);

	for(int i = 1; i < s.size(); i++){
		if(s[i]==s[i-1]){
			v[i]=v[i-1]+1;
		}
		else{
			reverse(v.begin()+(i-v[i-1]),v.begin()+i);
		}
	}
	reverse(v.begin()+(v.size()-1-v[v.size()-2]),v.begin()+(v.size()));
	//print(v);
	//print(v);
	int ans = 0;
	for(int i = 0; i < s.size(); i++){
		if(s[i]=='J'){
			if(i+v[i]<s.size() && s[i+v[i]]=='O' && v[i+v[i]]==v[i]){
				if(i+v[i]*2<s.size() && s[i+v[i]*2]=='I' && v[i+v[i]*2]>=v[i+v[i]]){
					ans=max(ans,v[i]);
				}
			}
		}
	}
	cout<<ans<<endl;
}

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 200010, INF = 1ll << 45;
int n,q,a,b,que[N];
struct node {
  pair<int,int> lmn,rmn;
  int l,r,tag;
} t[N << 2];
void puttag(int x,int val) {
  t[x].tag += val;
  t[x].lmn.first += val;
  t[x].rmn.first += val;
}
void push_down(int x) {
  puttag(x<<1,t[x].tag);
  puttag(x<<1|1,t[x].tag);
  t[x].tag = 0;
}
void push_up(int x) {
  if (t[x].tag) push_down(x);
  t[x].lmn = min(t[x<<1].lmn,t[x<<1|1].lmn);
  t[x].rmn = min(t[x<<1].rmn,t[x<<1|1].rmn);
}
void build(int l,int r,int x) {
  t[x].l = l, t[x].r = r;
  if (l == r) {
    t[x].lmn = make_pair(l,l);
    t[x].rmn = make_pair(n-l+1,l);
    return;
  }
  int mid = (l + r) >> 1;
  build(l,mid,x<<1);
  build(mid+1,r,x<<1|1);
  push_up(x);
}
int query(int p,int x) {
  if (t[x].l == t[x].r)
    return t[x].lmn.first - t[x].l;
  if (t[x].tag) push_down(x);
  int mid = (t[x].l + t[x].r) >> 1;
  if (p <= mid) return query(p,x<<1);
  else return query(p,x<<1|1);
}
void modify(int l,int r,int x,int val) {
  if (l > t[x].r || r < t[x].l) return;
  if (t[x].l >= l && t[x].r <= r) {
    t[x].lmn.first += val;
    t[x].rmn.first += val;
    t[x].tag += val;
    return;
  }
  if (t[x].tag) push_down(x);
  modify(l,r,x<<1,val);
  modify(l,r,x<<1|1,val);
  push_up(x);
}
pair<int,int> askl(int l,int r,int x) {
  if (l > t[x].r || r < t[x].l) return make_pair(INF,0);
  if (t[x].l >= l && t[x].r <= r)
    return t[x].lmn;
  if (t[x].tag) push_down(x);
  return min(askl(l,r,x<<1),askl(l,r,x<<1|1));
}
pair<int,int> askr(int l,int r,int x) {
  if (l > t[x].r || r < t[x].l) return make_pair(INF,0);
  if (t[x].l >= l && t[x].r <= r)
    return t[x].rmn;
  if (t[x].tag) push_down(x);
  return min(askr(l,r,x<<1),askr(l,r,x<<1|1));
}
void setval(int p,int x,int val) {
  if (t[x].l == t[x].r) {
    t[x].lmn.first = val + t[x].l;
    t[x].rmn.first = val + n - t[x].l + 1;
    return;
  }
  int mid = (t[x].l + t[x].r) >> 1;
  if (t[x].tag) push_down(x);
  if (p <= mid) setval(p,x<<1,val);
  else setval(p,x<<1|1,val);
  push_up(x);
}
signed main() {
  int tmp,t;
  scanf("%lld%lld%lld%lld",&n,&q,&a,&b);
  que[0] = a;
  build(1,n,1);
  for (int i = 1 ; i <= n ; ++ i)
    setval(i,1,abs(i-b));
  for (int i = 1 ; i <= q ; ++ i) {
    scanf("%lld",&que[i]);
    tmp = askl(que[i],n,1).first - que[i];
    t = askr(1,que[i],1).first - n + que[i] - 1;
    tmp = min(tmp,t);
    modify(1,n,1,abs(que[i-1] - que[i]));
    t = query(que[i-1],1);
    tmp = min(tmp,t);
    setval(que[i-1],1,tmp);
  }
  int ans = INF;
  for (int i = 1 ; i <= n ; ++ i)
    ans = min(ans,query(i,1));
  printf("%lld\n",ans);
  return 0;
}


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

  const int MOD = 1000000007;

  //long long
  using ll = long long;

  //出力系
  #define print(x) cout << x << endl
  #define yes cout << "Yes" << endl
  #define YES cout << "YES" << endl
  #define no cout << "No" << endl
  #define NO cout << "NO" << endl

  // begin() end()
  #define all(x) (x).begin(),(x).end()

  //for
  #define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

  //最大公約数（ll）
  ll gcd(ll x, ll y) { return y ? gcd(y,x%y) : x;}

  //素因数分解
  vector<pair<ll, int>>factorize(ll n){
    vector<pair<ll, int>> res;
    for(ll i = 2; i * i <= n; ++i){
      if(n % i) continue;
      res.emplace_back(i, 0);
      while(n % i == 0){
        n /= i;
        res.back().second++;
      }
    }
  if(n != 1) res.emplace_back(n, 1);
  return res;
  }

int main()
{
    string S;
    cin >> S;
    for(int i = 0; S.size() > i; i++){
        if(S.at(i) == 'A' && S.at(i + 1) == 'C') {
        cout << "Yes" << endl;
        return 0;
        }
        }

        cout << "No" << endl;

    }

#include <iostream>
using namespace std;

int main()
{
  string test;
  getline(cin,test);

  if (test[0] == 'A' && test[1] == 'C')
  {
    cout << "Yes" << endl;
  }
  else if(test[1] == 'A' && test[2] == 'C')
  {
    cout << "Yes" << endl;
  }
  else if(test[2] == 'A' && test[3] == 'C')
  {
    cout << "Yes" << endl;
  }
  else if(test[3] == 'A' && test[4] == 'C')
  {
    cout << "Yes" << endl;
  }
  else
  cout << "No" << endl;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <ctype.h>
#include <algorithm>
using namespace std;

#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)
#define all(c) (c).begin(), (c).end()

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main() {
  string s;
  while(getline(cin, s)) {
    int slide = 0;
    rep(i, s.size()-4) {
      if(islower(s[i]) == 0) continue;
      rep(j, 26) {
        string sub;
        rep(k, 4) sub += (s[i+k]-'a'+j+52)%26 + 'a';
        if(sub.substr(0,3) == "the") slide = j;
        else if(sub == "this" || sub == "that") slide = j;
      }
      if(slide != 0) break;
    }
    rep(i, s.size()) {
      if(islower(s[i]) != 0)printf("%c", (s[i]-'a'+slide+52)%26 + 'a');
      else cout << s[i];
    }
    cout << endl;
  }
}

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

int main() {
  string bstr;

  while (getline(cin, bstr)) {
    int n = 26;
    while (n--) {
      if (bstr.find("this", 0) != string::npos) {
        break;
      } else if (bstr.find("that", 0) != string::npos) {
        break;
      } else if (bstr.find("the", 0) != string::npos) {
        break;
      }
      for (int i = 0; i < bstr.size(); i++) {
        if (bstr[i] >= 'a' && bstr[i] <= 'z') {
          if (bstr[i] != 'z')
            bstr[i]++;
          else
            bstr[i] = 'a';
        }
      }
    }
    cout << bstr << endl;
  }

  return 0;
}


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

int main(){
  int map[21][21];
  int dx,dy;
  int get;
  int n,m;
  int x,y;
  int len;
  int i,j;

  string A;

  while(1){
    get = 0;
    dx = 10;
    dy = 10;
    for(i = 0 ; i < 21 ; i++){
      for(j = 0 ; j < 21 ; j++){
	map[i][j]=0;
      }
    }
    cin >> n;
    if(n==0) break;
    for(i = 0 ; i < n ; i++){
      cin >> x >> y;
      map[x][y]=1;
    }

    cin >> m;
    for(i = 0 ; i < m ; i++){
      cin >> A >> len;
      if(A == "N"){
	for(j = 0 ; j < len ; j++){
	  dy++;
	  if(map[dx][dy]==1){
	    map[dx][dy]=0;
	    get++;
	  }
	}
      }

      if(A == "E"){
	for(j = 0 ; j < len ; j++){
	  dx++;
	  if(map[dx][dy]==1){
	    map[dx][dy]=0;
	    get++;
	  }
	}
      }
      if(A == "S"){
	for(j = 0 ; j < len ; j++){
	  dy--;
	  if(map[dx][dy]==1){
	    map[dx][dy]=0;
	    get++;
	  }
	}
      }

      if(A == "W"){
	for(j = 0 ; j < len ; j++){
	  dx--;
	  if(map[dx][dy]==1){
	    map[dx][dy]=0;
	    get++;
	  }
	}
      }

    }

    if(get == n){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }

  return 0;
}


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

int main(){
	int n, m, a[1000], b[1000], vote[1000]={0};
	scanf(" %d %d", &n, &m);
	for(int i=0; i<n; ++i) scanf(" %d", &a[i]);
	for(int i=0; i<m; ++i) scanf(" %d", &b[i]);

	sort(b,b+m, greater<int>());

	int now=0;
	for(int i=0; i<m; ++i){
		for(int j=now; j<n; ++j){
			if(a[j] <= b[i]){
				++vote[j];
				now=j;
				//printf("::%d\n",j);
				break;
			}
		}
	}

	int ans=0, max=0;
	for(int i=0; i<n; ++i){
		if(max < vote[i]){
			max=vote[i];
			ans=i+1;
		}
	}

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

	return 0;
}

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

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

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

int main() {
    ll N,x;
    cin>>N>>x;
    vector<ll> v(N);
    for(ll i = 0; i < N; i++) cin>>v[i];
    ll ans = 0;
    if(v[0]>x){
        ans+=v[0]-x;
        v[0]=x;
    }
    for(ll i = 0; i < N-1; i++){
        if(v[i]+v[i+1]>x){
            ll t = x-v[i];
            ans+=v[i+1]-t;
            v[i+1]=t;
        }
    }
    cout<<ans<<endl;
}


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

int main() {
  long n,sum,fs,bs,fbs;
  cin >> n;
  sum = n,fs = 0, bs = 0, fbs = 0;
  for (int i = 0; i < n; i++) {
    sum += i;
  }
  for (int i = 3; i <= n; i += 3) {
    fs += i;
  }
  for (int i = 5; i <= n; i += 5) {
    bs += i;
  }
  for (int i = 15; i <= n; i += 15) {
    fbs += i;
  }
  cout << sum-fs-bs+fbs << endl;
}

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

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

long long MOD = 10000000000 + 7;

int main(){
  cout << setprecision(10);
  ll N; cin >> N;

  ll ans = 0;
  for(ll i = 1; i <= N; i++){
    if( i%3 == 0 || i%5 == 0){

    } else {
      ans += i;
    }
  }
  cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
    int a, b, c; cin >> a >> b >> c;
    bool ok = true;
    if(a==b && b!=c){ok = false;}
    if(b==c && c!=a){ok = false;}
    if(c==a && a!=b){ok = false;}
    if(!ok){cout << "Yes" << endl;}
    else cout << "No" << endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll power(ll p,ll n){
   ll result=1;
   while(n!=0){
   if(n%2==0){
    n/=2;
    p*=p;
   }
   else{
    n--;
    result=result*p;
   }
   }
    return result;
}
int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);

   ll n,t,a,b,c,d;
   ll mod =1e9+7;
   string s1,s2;
   stack<ll>stck1;
   stack<ll>stck2;

   set<ll>st;
   cin>>a>>b>>c;
   st.insert(a);
   st.insert(b);
   st.insert(c);

   if(st.size()==2){
    cout<<"Yes"<<endl;
   }
   else{
    cout<<"No"<<endl;
   }
}


#include <stdio.h>

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

	int length = A + B + 1, cnt = 0;
	char S[50];
	scanf("%s", S);

	if (S[A] == '-') {
		for(int i = 0; i < length; i++) {
			if (S[i] >= '0' && S[i] <= '9') {
				cnt++;
			}
		}
		if (cnt == length -1) {
			printf("Yes\n");
		} else {
			printf("No\n");
		}
	} else {
			printf("No\n");
		}
	return 0;
}

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#ifdef rd
#define trace(...) cout<<"Line:"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
	cout<<name<<" : "<<arg1<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
	const char *comma=strchr(names+1,',');
	cout.write(names,comma-names)<<" : "<<arg1<<" | ";
	__f(comma+1,args...);
}
#else
#define trace(...)
#define endl '\n'
#endif
#define pb push_back
#define fi first
#define se second
#define int long long
typedef long long ll;
typedef float f80;
#define double long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define sz(x) ((long long)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define trav(a,x) for(auto &a:x)
#define all(con) con.begin(),con.end()
const ll infl=0x3f3f3f3f3f3f3f3fLL;
const int infi=0x3f3f3f3f;
const int mod=998244353;
//const int mod=1000000007;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;
auto clk=clock();
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
	uniform_int_distribution<int> uid(0,lim-1);
	return uid(rang);
}
int powm(int a, int b) {
	int res=1;
	while(b) {
		if(b&1)
			res=(res*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return res;
}

const int N=3e6+5;
int fact[N],ifact[N];
inline int ncr(int n,int r) {
	if(n<r||r<0)
		return 0;
	return (((fact[n]*ifact[r])%mod)*ifact[n-r])%mod;
}
inline int idf(int n, int r) {
	return ncr(n+r-1,r-1);
}
int vals[N];
void solve() {
	fact[0]=1;
	rep(i,1,N)
		fact[i]=(fact[i-1]*i)%mod;
	ifact[N-1]=powm(fact[N-1],mod-2);
	for(int i=N-2; i>=0; i--)
		ifact[i]=(ifact[i+1]*(i+1))%mod;
	int n,m;
	cin>>n>>m;
	int ans=idf(3*m,n);
	for(int i=2*m+1; i<=3*m; i++) {
		ans=(ans-n*idf(3*m-i,n-1))%mod;
	}
	for(int i=m+2; i<=3*m; i+=2) {
		ans=(ans-ncr(n,i)*idf((3*m-i)/2,n))%mod;
	}
	if(ans<0)
		ans+=mod;
	cout<<ans<<endl;
}

signed main() {
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	srand(chrono::high_resolution_clock::now().time_since_epoch().count());
	cout<<fixed<<setprecision(10);
	int t=1;
//	cin>>t;
	fr(i,1,t)
	{
		solve();
	}
#ifdef rd
	cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  int n;
  cin >> n;
  multiset<ll> st;
  rep(i, n) {
    ll a;
    cin >> a;
    st.insert(a);
  }
  ll ans = 0;
  ll p2 = pow(2, 34);
  while(!st.empty()) {
    auto it = st.end();
    it--;
    ll p = p2;
    while(p > *it) {
      p /= 2;
      auto jt = st.lower_bound(p - *it);
      if(jt == it || jt == st.end() || *jt != p - *it) continue;
      st.erase(jt);
      ans++;
      break;
    }
    st.erase(it);
  }
  cout << ans << endl;
}

#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(_i,_a,_n) for(int _i=_a;_i<=_n;++_i)
#define PER(_i,_a,_n) for(int _i=_n;_i>=_a;--_i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(_a) ({REP(_i,1,n) cout<<_a[_i]<<',';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head

#ifdef __APPLE__
const int N = 1e2+50;
#else
const int N = 1e6+50;
#endif

int n, a[N];
map<int,int> v;

int main() {
	scanf("%d", &n);
	REP(i,1,n) scanf("%d", a+i), ++v[a[i]];
	sort(a+1,a+1+n,greater<int>());
	int ans = 0;
	REP(i,1,n) if (v[a[i]]) {
		REP(j,0,30) {
			int t = (1<<j)-a[i];
			if (!v.count(t)) continue;
			if (a[i]!=t&&v[t]||v[t]>=2) {
				++ans, --v[a[i]], --v[t];
				break;
			}
		}
	}
	printf("%d\n", ans);
}


#include <bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(long long i=a; i<b; i+=1)
#define repr(i,a,b) for(long long i=a; i<=b; i+=1)
#define vec vector<ll>
#define mapa map<char,int>
#define repa(p,A) for(auto p:A)
#define pb push_back
/*#define sort(a) sort(a.begin(),a.end())*/
#define reverse(a) reverse(a.begin(),a.end())
const double PI=acos(-1);
using namespace std;

int main( ) {
    vec A,B;
    ll N;
    cin>>N;
    rep(i,0,N) {
        ll a;
        cin>>a;
        if(i%2==0) {
            A.push_back(a);
        }
        else {
            B.push_back(a);
        }
        }
        map<ll,ll> C,D;
        rep(i,0,A.size()) {
            C[A[i]]++;
        }
        rep(i,0,B.size()) {
            D[B[i]]++;
        }
        vector<pair<ll,ll>> E,F;
        for(auto p:C) {
            E.push_back(pair<ll,ll>(p.first,p.second));
            }
        for(auto p:D) {
            F.push_back(pair<ll,ll>(p.first,p.second));
            }
        auto comp = [](pair<int, int> a, pair<int, int> b) {
        return a.second>b.second;
    };
        ll count=0;
        sort(E.begin(),E.end(),comp);
        sort(F.begin(),F.end(),comp);
        if(E[0].first==F[0].first) {
            if(E.size()>=2) {
                count+=E[0].second+max(E[1].second,F[1].second);
                }
            else count+=E[0].second;
        }

        else count+=E[0].second+F[0].second;

        cout<<N-count<<endl;

        }

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

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

    int n;
    cin>>n;

    int m=n;
    int ans=0;

    for(int i=0;i<n;i++)
    {
        int p;
        cin>>p;

        if(p<=m)ans++;
        m=min(p,m);
    }

    cout<<ans<<"\n";

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
string a;
int b;
int main(){
	cin>>a>>b;
	for(int i=0;i<a.size();i+=b)
		cout<<a[i];
	return 0;
}

#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int mod = 1e9+7;
typedef pair<ll,ll> pairs;
vector<pairs> p;

ll gcd(ll A,ll B){
    if (A%B==0)return(B);
    else return(gcd(B,A%B));
}

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

vector<vector<ll>> combination(ll n, ll r){
    vector<vector<ll>> v(n + 1, vector<ll>(n + 1, 0));
    for(ll i=0;i<v.size();++i){
        v[i][0] = 1;
        v[i][i] = 1;
    }
    for(ll i=1;i<v.size();++i){
        for(ll j=0;j<i;++j){
            v[i][j] = (v[i - 1][j - 1] + v[i - 1][j]);
        }
    }
    return v;
}

bool kai(string S){
    bool flag = true;
    for(ll i=0;i<S.size()/2;++i){
        if(S[i] != S[S.size()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}
// ---------------------------------------------

int main(){
    string s;
    cin>>s;
    ll w;
    cin>>w;
    for(ll i=0;i<s.size();i+=w){
        cout<<s[i];
    }
    cout<<endl;

    return 0;
}


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

int main() {
	int n;
	cin >> n;
	vector<char> sL(n), sR(n);
	for (int i = 0; i < n; i++) {
		cin >> sL[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> sR[i];
	}

	map<pair<string, string>, int> mpL;
	for (int bit = 0; bit < 1<<n; bit++) {
		string reds = "", blues = "";
		for (int i = 0; i < n; i++) {
			if (bit & 1<<i) {
				reds.push_back(sL[i]);
			}
			else {
				blues.push_back(sL[i]);
			}
		}
		mpL[make_pair(reds, blues)]++;
	}

	long long ans = 0;
	for (int bit = 0; bit < 1<<n; bit++) {
		string reds = "", blues = "";
		for (int i = 0; i < n; i++) {
			if (bit & 1<<i) {
				reds.push_back(sR[i]);
			}
			else {
				blues.push_back(sR[i]);
			}
		}
		reverse(reds.begin(), reds.end());
		reverse(blues.begin(), blues.end());
		ans += mpL[make_pair(blues, reds)];
	}

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

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define Graph vector<vector<ll>>
#define INF (1ll<<60)
#define mod 1000000007
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(){
    string N;cin>>N;
    reverse(N.begin(),N.end());
    vector<vector<ll>> dp(1000010,vector<ll>(2/*桁上がりあるか*/,INF));
    dp[0][0]=0;

    N.push_back('0');
    for(ll i=0;i<N.size();i++){
        ll now=N[i]-'0';

        //前桁上がり判定ありの時
        ll nowb=now+1;
        if(dp[i][1]!=INF){
            //今equal
            chmin(dp[i+1][0],dp[i][1]+nowb);

            //今もbigger
            chmin(dp[i+1][1],dp[i][1]+(10-nowb));
        }

        //前桁上がり判定無し
        if(dp[i][0]!=INF){
            //今桁上がり判定無し
            chmin(dp[i+1][0],dp[i][0]+now);

            //今桁上がり判定あり
            chmin(dp[i+1][1],dp[i][0]+(10-now));
        }
    }

    cout<<min(dp[N.size()][0],dp[N.size()][1])<<endl;
    return 0;
}


#include<cstdio>
typedef long long ll;
const ll mod=998244353;
inline ll rev(ll x)
{ll k=mod-2,r=1;for(;k;k>>=1,(x*=x)%=mod)if(k&1)(r*=x)%=mod;return r;}
ll fac[1111111],inv[1111111];
inline ll C(int n,int r)
{return((((fac[n]*inv[r])%mod)*inv[n-r])%mod);}
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	if(n<m)n^=m,m^=n,n^=m;
	fac[0]=inv[0]=1;
	register int i;
	for(i=1;i<=n+m;i++)fac[i]=(fac[i-1]*i)%mod;
	inv[n+m]=rev(fac[n+m]);
	for(i=n+m-1;i;i--)inv[i]=inv[i+1]*(i+1)%mod;
	ll ans=0;
	for(i=1;i<=m;i++)
		(ans+=C(i*2,i)*C(n+m-2*i,n-i))%=mod;
	(((ans*=rev(2*C(n+m,n)))%=mod)+=n+mod)%=mod;
	printf("%lld\n",ans);
}

#pragma GCC optimize("Ofast","inline")
#include <bits/stdc++.h>
#define clr(x) memset(x,0,sizeof (x))
#define For(i,a,b) for (int i=a;i<=b;i++)
#define Fod(i,b,a) for (int i=b;i>=a;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define _SEED_ ('C'+'L'+'Y'+'A'+'K'+'I'+'O'+'I')
#define outval(x) printf(#x" = %d\n",x)
#define outvec(x) printf("vec "#x" = ");for (auto _v : x)printf("%d ",_v);puts("")
#define outtag(x) puts("----------"#x"----------")
#define outarr(a,L,R) printf(#a"[%d...%d] = ",L,R);\
						For(_v2,L,R)printf("%d ",a[_v2]);puts("");
using namespace std;
typedef long long LL;
LL read(){
	LL x=0,f=0;
	char ch=getchar();
	while (!isdigit(ch))
		f|=ch=='-',ch=getchar();
	while (isdigit(ch))
		x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return f?-x:x;
}
const int N=2005,mod=998244353;
void Add(int &x,int y){
	if ((x+=y)>=mod)
		x-=mod;
}
void Del(int &x,int y){
	if ((x-=y)<0)
		x+=mod;
}
int del(int x,int y){
	return x-y<0?x-y+mod:x-y;
}
int Pow(int x,int y){
	int ans=1;
	for (;y;y>>=1,x=(LL)x*x%mod)
		if (y&1)
			ans=(LL)ans*x%mod;
	return ans;
}
int n,m;
int dp[N][N];
const int BN=1000005;
int Fac[BN],Inv[BN],Iv[BN];
int C(int n,int m){
	if (m<0||m>n)
		return 0;
	return (LL)Fac[n]*Inv[m]%mod*Inv[n-m]%mod;
}
int IC(int n,int m){
	return (LL)Inv[n]*Fac[m]%mod*Fac[n-m]%mod;
}
void prework(){
	int n=BN-1;
	for (int i=Fac[0]=1;i<=n;i++)
		Fac[i]=(LL)Fac[i-1]*i%mod;
	Inv[n]=Pow(Fac[n],mod-2);
	Fod(i,n,1)
		Inv[i-1]=(LL)Inv[i]*i%mod;
	For(i,1,n)
		Iv[i]=(LL)Inv[i]*Fac[i-1]%mod;
}
namespace so60{
	void prework(){
		int n=3,m=3;
		For(i,0,n)
			For(j,0,m){
				if (i==0&&j==0)
					dp[i][j]=0;
				else if (i>=j){
					dp[i][j]=((LL)dp[i-1][j]*i%mod*Iv[i+j]+dp[i][j])%mod;
					if (j>0)
						dp[i][j]=((LL)(dp[i][j-1]+1)*j%mod*Iv[i+j]+dp[i][j])%mod;
				}
				else {
					dp[i][j]=((LL)dp[i][j-1]*j%mod*Iv[i+j]+dp[i][j])%mod;
					if (i>0)
						dp[i][j]=((LL)(dp[i-1][j]+1)*i%mod*Iv[i+j]+dp[i][j])%mod;
				}
			}
	}
	const int N=500005;
	int a[N],d[N],dd[N],ddd[N];
	int main(){
		prework();
		For(i,1,3){
			a[i]=dp[i][i];
			d[i]=(dp[i][i]-dp[i-1][i-1]+mod)%mod;
			dd[i]=(d[i]-d[i-1]+mod)%mod;
			ddd[i]=(LL)Pow(dd[i],mod-2)*Pow(2,i*2)%mod;
		}
		For(i,4,n){
			ddd[i]=(LL)ddd[i-1]*(i*4-2)%mod*Pow(i-2,mod-2)%mod;
			dd[i]=(LL)Pow(2,i*2)*Pow(ddd[i],mod-2)%mod;
			d[i]=(d[i-1]+dd[i])%mod;
			a[i]=(a[i-1]+d[i])%mod;
		}
		cout<<a[n]<<endl;
		return 0;
	}
}
int main(){
	prework();
	n=read(),m=read();
	if (n>m)
		swap(n,m);
//	if (n==m)
//		return so60::main();
	int ans=(LL)n*C(n+m,n)%mod;
	For(i,1,n)
		Del(ans,(LL)C(i+i-1,i)*C(n-i+m-i,n-i)%mod);
	ans=(LL)ans*IC(n+m,n)%mod;
	ans=(n+m-ans+mod)%mod;
	cout<<ans<<endl;
	return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;

unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

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

    ll size(ll x) {
        return siz[root(x)];
    }
};

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 modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

int main() {
    ll n;
    cin >> n;
    ll a = 11;
    while (n > 0) {
        ll k = 0;
        for (int i = 2; i < sqrt(a)+1; i++) {
            if (a % i == 0)k = 1;
        }
        if (k == 0) {
            cout << a;
            n--;
            if (n == 0)break;
            cout << " ";
        }
        a += 5;
    }
    cout << endl;
}

#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

template<typename T>
vector<T> prime_factorization(T n) {
	vector<T> ret;
	vector<bool> is_prime(n + 1, true);

	for(T i = 2; i <= n; ++i) {

		if( is_prime[i] ) {
			for(T j = 2 * i; j <= n; j += i) {
				is_prime[j] = false;
			}

			if( i % 5 == 1 ) ret.push_back(i);
		}
	}

	return ret;
}

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

	vector<int> primes = prime_factorization(55555);

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

	cout << endl;

	return 0;
}


#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
typedef pair<int, int> P;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,d1,d2;
  cin>>n>>d1>>d2;
  vector<int> SQRT(4*n*n+1,-1);
  for(int i=0;i<=2*n;i++){
    SQRT[i*i]=i;
  }
  vector<vector<int> > alive(2*n, vector<int>(2*n, 1));
  for(int rot=0;rot<2;rot++){
    int d=(rot==0?d1:d2);
    vector<vector<int> > was(2*n, vector<int>(2*n, 0));
    for(int i=0;i<2*n;i++){
      for(int j=0;j<2*n;j++){
        if(was[i][j]||!alive[i][j])continue;
        vector<P> que(1, P(i,j));
        was[i][j]=1;
        for(int b=0;b<(int)que.size();b++){
          int x=que[b].first;
          int y=que[b].second;
          for(int xx=0;xx<2*n;xx++){
            int dy=d-(x-xx)*(x-xx);
            if(dy>=0&&dy<=4*n*n&&SQRT[dy]!=-1){
              dy=SQRT[dy];
              int yy=y-dy;
              if(yy>=0&&yy<2*n&&was[xx][yy]==0&&alive[xx][yy]){
                que.emplace_back(xx, yy);
                was[xx][yy]=3-was[x][y];
              }
              if(dy != 0){
                yy = y + dy;
                if(yy>=0&&yy<2*n&&was[xx][yy]==0&&alive[xx][yy]){
                  que.emplace_back(xx, yy);
                  was[xx][yy]=3-was[x][y];
                }
              }
            }
          }
        }
        vector<int> cc(3, 0);
        for(auto &p : que){
          cc[was[p.first][p.second]]++;
        }
        int best = (cc[1] > cc[2] ? 1 : 2);
        for(auto &p : que){
          if(was[p.first][p.second] != best){
            alive[p.first][p.second] = 0;
          }
        }
      }
    }
  }
  int cc=n*n;
  FOR(i,0,2*n){
    FOR(j,0,2*n){
      if(alive[i][j]){
        cc--;
        cout << i << " " << j << endl;
        if(cc==0) return 0;
      }
    }
  }
}


#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
/********************************************************************/
#define M1 1000000007
#define M2 998244353
const double pi = 3.14159265;

#define ll long long
#define pll pair<ll,ll>

#define forr(i, n) for(ll i=0;i<n;i++)

#define pb push_back
#define ppb pop_back
#define mp make_pair
#define MT make_tuple
#define V(a) vector<a>
#define vi vector<ll>

#define CASE(t) ll t; cin>>t; while(t--)

#define endl '\n'
#define space ' '
#define enter cout<<endl
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl

#define all(x) x.begin(), x.end()
#define sortall(x) sort(all(x))
#define collect(v, n) for(ll i = 0; i < n;i++){cin>>v[i];}

#define deci(n) fixed << setprecision(n)		//sets no of digits to show after decimal
#define setcount(n) __builtin_popcount(n)       //the number of ones in the int
#define setcountll(n) __builtin_popcountll(n)   //the number of ones in the ll
#define parity(n) __builtin_parity(n)			//the parity (even or odd) of the number of ones
#define clz(n) __builtin_clz(n)					//the number of zeros at the beginning of the number
#define clzll(n) __builtin_clzll(n)				//the number of zeros at the beginning of the ll
#define ctz(n) __builtin_ctz(n)					//the number of zeros at the end of the number

void deb(ll x) { cout << x << endl;}
void deb(int x) { cout << x << endl;}
void deb(unsigned int x) { cout << x << endl;}
void deb(unsigned ll x) { cout << x << endl;}
void deb(float x) { cout << x << endl;}
void deb(double x) { cout << x << endl;}
void deb(long double x) { cout << x << endl;}
void deb(char x) {cout << '\'' << x << '\'' << endl;}
void deb(string s) { cout << '\"' << s << '\"' << endl;}
void deb(vector<ll> v) { for (auto x : v) cout << x << ' '; cout << endl;}
void deb(bool bb) {cout << (bb ? "True" : "False") << endl;}
void deb(map<ll, ll> mpp) {for (auto x : mpp) cout << x.first << ' ' << x.second << endl;}
void deb(pair<ll, ll> pp) { cout << "{" << pp.first << "," << pp.second << "}" << endl;}

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

template<typename T>
#define o_set(T) tree<T, null_type,less_equal<T>, rb_tree_tag,tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set
// MULTISET ==> less_equal
// SET ==> less

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

map<long long, long long> factorize(long long n) {
	map<long long, long long> ans;
	for (long long i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ans[i]++;
			n /= i;
		}
	}
	if (n > 1) {
		ans[n]++;
		n = 1;
	}
	return ans;
}

ll countBits(ll n) {
	ll count = 0;
	while (n)
	{
		count++;
		n >>= 1;
	}
	return count;
}

ll isP(ll n) {
	if (n == 0 || n == 1)
		return 0;
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)
			return 0;
	}
	return 1;
}

/* **********END OF TEMPLATE*********** */

ll check(ll ar[], ll mid, ll k, ll n) {
	ll tmp = 0;
	for (ll i = 0; i < n; i++) {
		tmp += (ar[i] / mid + (ar[i] % mid != 0) - 1);

	}
	if (tmp <= k)
		return 1;

	return 0;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n;
	ll k;
	cin >> n >> k;
	double ar[n];
	for (ll i = 0; i < n; i++) {
		cin >> ar[i];
		ar[i] = (double)(ar[i] + 1) / (double)2;
	}
	double prefs[n + 1];
	prefs[0] = 0.0000;
	for (ll i = 0; i < n; i++) {
		prefs[i + 1] = prefs[i] + ar[i];
	}
	double mx = -1;
	for (ll i = k; i <= n; i++) {
		if (prefs[i] - prefs[i - k] > mx)
			mx = (prefs[i] - prefs[i - k]);
	}
	cout << deci(10) << mx << endl;

	return 0;
}

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

int main(){
  int d,g,m;
  m=pow(10,5);
  cin >> d >> g;
  vector<pair<int,int>> v;
  int a,b;
  for(int i=0;i<d;i++){
      cin >> a >> b;
      pair<int,int> p(a,b);
      v.push_back(p);
  }
  for(int i=0; i<(1<<d); i++){
    bitset<10> bit(i);
    bitset<10> check(0);
    int ans,item;
    ans=0;
    item=0;
    for(int j=0; j<d; j++){
      if(bit[j]==1){
        ans+=100*(j+1)*v.at(j).first+v.at(j).second;
        check.set(j,1);
        item+=v.at(j).first;
      }
    }
    int stop = d-1;
    while(true){
      if(ans>=g || stop<0){
        break;
      }
      if(check[stop]==0){
        check.set(stop,1);
        if(ans+100*(stop+1)*(v.at(stop).first-1)>g){
          item+=ceil(1.0*(g-ans)/(100*(stop+1)));
          ans = g;
          break;
        }
        else{
          ans += 100*(stop+1)*(v.at(stop).first-1);
          item+=v.at(stop).first-1;
        }
      }
      stop--;
    }
    if(m>item && ans >= g){
      m=item;
    }
  }
  cout << m << endl;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MAX 100
int min(int,int);
int p[MAX+1]={},m[MAX+1][MAX+1]={};

int min(int n1,int n2){
  if(n1>n2) return n2;
  else return n1;
}

int main()
{
  int n,l,i,j,k;

  scanf("%d",&n);

  for(i=1;i<=n;i++){
    scanf("%d %d",&p[i-1],&p[i]);
  }

  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j=i+l-1;
      m[i][j]=(1<<21);
      for(k=i;k<=j-1;k++){
	m[i][j]=min(m[i][j],m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
      }
    }
  }

  printf("%d\n",m[1][n]);

  return 0;
}

#include <bits/stdc++.h>
#define N 101
using namespace std;
int A[N];

int mem[N][N],used[N][N];
int dfs(int l,int r){
  if(l == r) return 0;
  if(r - l == 1) return A[l]*A[r]*A[r+1];
  if(used[l][r]++) return mem[l][r];

  int res = 1e9;
  for(int i=l;i<r;i++){
    int a = dfs(l,i);
    int b = dfs(i+1,r);
    int c = A[l] * A[i+1] * A[r+1];
    res = min(res,a + b + c);
  }
  return mem[l][r] = res;
}

int main(){

  int n;
  cin>>n;
  for(int i=0,cnt=0;i<n;i++){
    int a,b;
    cin>>a>>b;
    if(i == 0) A[cnt++] = a;
    A[cnt++] = b;
  }

  cout<<dfs(0,n-1)<<endl;

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin(), x.end()
int32_t main()
{
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    vector<int> index;
    int c = 0;
    index.push_back(c);
    for (int i = 0; i < s.size() - 1; i++)
    {
        if (s[i] == 'A')
        {
            if (s[i + 1] == 'C')
            {
                index.push_back(++c);
            }
            else
            {
                index.push_back(c);
            }
        }
        else
        {
            index.push_back(c);
        }
    }
    while (q--)
    {
        int l, r;
        cin >> l >> r;
        cout<< index[--r]-index[--l]<<endl;
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
ll factorial(int i) {       //階乗
    if (i == 0) return 1;
    return (factorial(i - 1)) * i;
}

int main() {
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    vector<int> ac(n);
    vector<int> sum(n + 1, 0);
    rep(i, n) {
        if(i != n) {
            if(s[i] == 'A' && s[i + 1] == 'C') {
                ac[i]++;
                i++;
            }
        }
    }
    rep(i, n) {
        sum[i + 1] += sum[i] + ac[i];
    }
    /*cout << endl;
    rep(i, n) cout << ac[i] << ' ';
    cout << endl;
    rep(i, n + 1) cout << sum[i] << ' ';
    cout << endl;
    //確認済*/
    vector<vector<int>> l(q, vector<int>(2));
    rep(i, q) {
        rep(j, 2) cin >> l[i][j];
    }
    rep(i, q) {
        cout << sum[l[i][1] - 1] - sum[l[i][0] - 1] << endl;
    }

}


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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()

void MAIN() {
  int n, m;
  cin >> n >> m;
  int cnt = 0;
  vector<string> s(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
    s[i] = "-" + s[i];
    for (int j = 1; j <= m; j++) {
      if (s[i][j] == '#') cnt++;
    }
  }
  vector<vector<int>> v(n + 1, vector<int>(m + 1));
  struct tup {
    int fi, sc, th;
    tup() {}
    tup(int fi, int sc, int th):
      fi(fi), sc(sc), th(th) {}
  };
  vector<int> r = {-1, 0, 1, 0};
  vector<int> c = {0, -1, 0, 1};
  queue<tup> q;
  q.push(tup(1, 1, 1));
  while (q.size()) {
    int x = q.front().fi;
    int y = q.front().sc;
    int z = q.front().th;
    q.pop();
    if (x < 1 || x > n || y < 1 || y > m) continue;
    if (v[x][y] || s[x][y] == '#') continue;
    v[x][y] = z;
    for (int i = 0; i < 4; i++) {
      q.push(tup(x + r[i], y + c[i], z + 1));
    }
  }
  if (v[n][m] == 0) {
    cout << -1 << '\n';
    return;
  }
  cout << n * m - cnt - v[n][m] << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
#endif
  // ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}

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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9

int N, M;
vector<vector<int>> graph;
vector<int> deg, order;

void toporo(){
  queue<int> que;
  REP(i, N){
    if(deg[i] == 0){
      que.push(i);
    }
  }
  while(!que.empty()){
    int v = que.front(); que.pop();
    order.push_back(v);

    for(auto nv : graph[v]){
      --deg[nv];
      if(deg[nv] == 0) que.push(nv);
    }
  }
  reverse(order.begin(), order.end());
}

int main(){
  cin >> N >> M;
  deg.resize(N);
  graph.resize(N);
  vector<vector<int>> in(N);

  REP(i, N+M-1){
    int a, b;
    cin >> a >> b;
    a--, b--;
    graph[b].push_back(a);
    deg[a]++;
  }
  toporo();
  vector<int> depth(N);
  REP(i, N){
    depth[order[i]] = i;
  }
  REP(i, N){
    int oya = 0, d = -1;
    for(auto v :graph[i]){
      if(d < depth[v]){
        d = depth[v];
        oya = v+1;
      }
    }
    cout << oya << endl;
  }
  return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma warning(disable : 4996)
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>
#include<array>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), (n))
#define ub(v,n) upper_bound(v.begin(), v.end(), (n))
#define int long long
//#define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
typedef array<int, 3> arr3;
std::random_device rd;
std::mt19937 mt(rd());
constexpr int MOD = 998244353; constexpr int MAX = 2000020;
const double pi = acos(-1); constexpr double EPS = 1e-8;
constexpr ll INF = 1e18;

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;
}
ll add(ll x, ll y) {
	x += y;
	if (x >= MOD) return x - MOD;
	return x;
}
ll sub(ll x, ll y) {
	x -= y;
	if (x < 0) return x + MOD;
	return x;
}
ll mult(ll x, ll y) {
	return (x * y) % MOD;
}
ll bin_pow(ll x, ll p) {
	if (p == 0) return 1;
	if (p & 1) return mult(x, bin_pow(x, p - 1));
	return bin_pow(mult(x, x), p / 2);
}

void solve() {
	int N, M; cin >> N >> M;
	ll ans = 0;
	COMinit();
	REP(k, min(N+1,M + 1)) {
		if (M % 2 != k%2)continue;
		int tmp = COM(N, k);
		int c = (3 * M - k) / 2;
		tmp = mult(tmp, mult(finv[c],mult(finv[N-1],fac[c + N - 1])));

		int c2 = (M - k) / 2;
		int sb1 = mult(mult(COM(N,k),k), mult(fac[c2 + N - 1], mult(finv[c2], finv[N - 1])));
		int c3 = (M - k - 2) / 2;
		if (c3 >= 0) {
			int sb2 = mult(mult(COM(N,k),N - k), mult(fac[c3 + N - 1], mult(finv[c3], finv[N - 1])));
			tmp = sub(tmp, sb2);
		}
		tmp = sub(tmp, sb1);
		ans = add(ans, tmp);
	}
	print(ans);
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q; cin >> q;
	//while (q--)
	solve();
}

#include <bits/stdc++.h>
using i64 = long long;

long long *fact, *inv;

template <typename T, typename U, typename V>
auto pow(T x_, U n_, V mod_) {
    using R = std::common_type_t<T, U, V>;
    R ret = 1, x = x_, n = n_, mod = mod_;
    while(n > 0) {
        if ((n & 1) == 1) ret = (ret * x) % mod;
        x = (x * x) % mod;
        n >>= 1;
    }
    return ret;
}

template <typename T, typename U>
auto inverse(T x, U p) { return pow(x, p - 2, p); }

void init_factorial(int n, long long mod) {
    fact = new long long[n + 1];
    inv = new long long[n + 1];
    fact[0] = 1;
    for (long long i = 1; i <= n; i++) fact[i] = fact[i - 1] * i % mod;
    inv[n] = inverse(fact[n], mod);
    for (long long i = n; i > 0; i--) inv[i - 1] = inv[i] * i % mod;
}

int main() {
    constexpr i64 mod = 998244353;
    int n, m;
    std::cin >> n >> m;
    init_factorial(n + 3 * m, mod);

    i64 ret = 0;
    for (int i = 0; i <= std::min(n, m); i++) {
        int r = 3 * m - i;
        if (r & 1) continue;
        r >>= 1;
        i64 t = fact[r + n - 1] * inv[n - 1] % mod * inv[r] % mod;
        ret = (ret + t * fact[n] % mod * inv[i] % mod * inv[n - i] % mod) % mod;
    }

    for (int i = 0; i <= std::min(n, m); i++) {
        int r = m - i;
        if (r & 1) continue;
        r >>= 1;
        i64 t = fact[r + n - 1] * inv[n - 1] % mod * inv[r] % mod;
        ret = (ret + mod - t * fact[n] % mod * inv[i] % mod * inv[n - i] % mod * n % mod) % mod;
    }

    for (int i = 0; i <= std::min(n - 1, m); i++) {
        int r = m - i;
        if (r & 1) continue;
        r >>= 1;
        i64 t = fact[r + n - 2] * inv[n - 2] % mod * inv[r] % mod;
        ret = (ret + t * fact[n - 1] % mod * inv[i] % mod * inv[n - i - 1] % mod * n % mod) % mod;
    }

    std::cout << ret << std::endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
  int K;
  cin>>K;
  string S;
  cin>>S;
  if(S.size()<=K) cout<<S<<endl;
  else cout<<S.erase(K)+"..."<<endl;
}

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

int main()
{
    int t=1;
    //cin>>t;

    while( t-- )
    {
        int k;
        cin>>k;

        string s;
        cin>>s;

        if( s.size()<=k )
            cout<<s;
        else
        {
            for( int i=0 ; i<k ; i++ )
                cout<<s[i];
            cout<<"..."<<endl;
        }
    }
    return 0;
}


/*
ID: anonymo14
TASK: wormhole
LANG: C++
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {
	int n;
	cin>>n;
	vi arr(n);
	for(int &i:arr)cin>>i;
	sort(arr.rbegin(),arr.rend());
	ll ans=1;
	int cnt = 0;
	for(int i=0;i<n-1;i++) {
		if(arr[i]==arr[i+1])ans*=arr[i],i++,cnt++;
		if(cnt==2)break;
	}
	if(cnt!=2)cout<<0;
	else
	cout<<ans;
}

int main() {

	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////

	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}

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

main()
{
    ios::sync_with_stdio(0);
    cout.tie(0);
    cin.tie(0);
    long long i,j,k,l,m,n,o,p;
 string s;
 while(cin>>n){
    int x[n];
    map<long long,long long>mp;

    for(i=0;i<n;i++){
        cin>>x[i];

    }
    sort(x,x+n);
   long long a=0,b=0;
   for(i=n-1;i>0;i--){
    if(x[i]==x[i-1]){
        if(a==0)a=x[i];
        else if(b==0)b=x[i];
        else break;
        i--;
    }
   }
   cout<<a*b<<endl;
 }
    return 0;

}


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

template<typename T>
struct Segtree {
    int n;
    T e;
    vector<T> dat;
    typedef function<T(T a, T b)> Func;
    Func f;

    Segtree(){}
    Segtree(int n_input, Func f_input, T e_input){
        initialize(n_input, f_input, e_input);
    }
    void initialize(int n_input, Func f_input, T e_input){
        f = f_input;
        e = e_input;
        n = 1;
        while(n < n_input) n <<= 1;
        dat.resize(2*n-1, e);
    }

    void update(int k, T a){
        k += n - 1;
        dat[k] = a;
        while(k > 0){
            k = (k - 1)/2;
            dat[k] = f(dat[2*k+1], dat[2*k+2]);
        }
    }

    T get(int k){
        return dat[k+n-1];
    }

    T between(int a, int b){
        return query(a, b+1, 0, 0, n);
    }

    T query(int a, int b, int k, int l, int r){
        if(r<=a || b<=l) return e;
        if(a<=l && r<=b) return dat[k];
        T vl = query(a, b, 2*k+1, l, (l+r)/2);
        T vr = query(a, b, 2*k+2, (l+r)/2, r);
        return f(vl, vr);
    }
};

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

struct UnionFind {
    vector<int> par;
    vector<int> sz;

    UnionFind(int n=0){
        if(n>0) initialize(n);
    }

    void initialize(int n){
        par.resize(n);
        sz.resize(n);
        for(int i=0; i<n; i++){
            par[i] = i;
            sz[i] = 1;
        }
    }

    int find(int x){
        if(par[x] == x){
            return x;
        }else{
            return par[x] = find(par[x]);
        }
    }

    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y) return;
        if(sz[x] < sz[y]){
            par[x] = y;
            sz[y] += sz[x];
        }else{
            par[y] = x;
            sz[x] += sz[y];
        }
    }

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

int main(){
    int N;
    int64_t D, A[200000];
    cin >> N >> D;
    for(int i=0; i<N; i++) cin >> A[i];

    typedef pair<int64_t, int> P;
    const int64_t INF = 1e18;
    const P INFP = {INF, 0};
    Segtree<P> stL(N, [](P a, P b){ return min(a, b);}, INFP);
    Segtree<P> stR(N, [](P a, P b){ return min(a, b);}, INFP);

    vector<int> order;
    for(int i=0; i<N; i++) order.push_back(i);
    sort(order.begin(), order.end(), [&](int i, int j){ return A[i] < A[j];});
    vector<vector<int64_t>> edges;

    for(int i : order){
        auto p = stL.between(0, i);
        if(p != INFP){
            int64_t cost = p.first + A[i] - (N-i)*D;
            edges.push_back({cost, i, p.second});
        }
        p = stR.between(i, N-1);
        if(p != INFP){
            int64_t cost = p.first + A[i] - i*D;
            edges.push_back({cost, i, p.second});
        }
        stL.update(i, {A[i] + (N-i)*D, i});
        stR.update(i, {A[i] + i*D, i});
    }

    sort(edges.begin(), edges.end());
    UnionFind uf(N);
    int64_t ans = 0;
    for(auto& e : edges){
        if(!uf.same(e[1], e[2])){
            uf.unite(e[1], e[2]);
            ans += e[0];
        }
    }

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

//c++ -std=gnu++14 a.cpp
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <climits>
#include <fstream>
#include <random>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
//typedef pair<ll, ll> P;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define revrep(i, n) for(int i = (n)-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
#define chmin(x, y) x = min(x, y);
#define chmax(x, y) x = max(x, y);
#define sz(x) ((int)(x).size())

//const ll INFL = LLONG_MAX;//10^18 = 2^60
const ll INFL = 1LL<<60;
//const int INF = INT_MAX;
const int INF = 1 << 30;//10^9
//const int MOD = 1000000007;
const int MOD = 998244353;
//int MOD = 1000000007;
double EPS = 1e-10;

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

void pres(double A){printf("%.12lf\n", A);}
void BinarySay(ll x, ll y = 60){rep(i, y) cout << (x>>(y-1-i) & 1); cout << endl;}
ll cnt_bit(ll x){return __builtin_popcountll(x);}

ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x; k /= 2;
  }
  return res;
}

ll pow_mod(ll x, ll k){
  x %= MOD;
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}

ll inverse(ll x){return pow_mod(x, MOD - 2);};

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

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

//コンビネーション
const int MAXcomb = 200010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; 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;
    }
}
ll comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}

const int MAXkai = 200010;
ll kai_memo[MAXkai];
ll kai(ll N){
  if(kai_memo[N] != 0) return kai_memo[N];
  if(N <= 1) return 1;
  return kai_memo[N] = N * kai(N-1) % MOD;
}

ll disit(ll s, ll base = 10){
  ll res = 0;
  while(s){
    res++;
    s /= base;
  }
  return res;
}

//約数の列挙O(√n)
vector<int> divisor(int n){
    vector<int> res(0);
    for(int i = 1; i * i <= n; i++){
        if(n % i == 0){
            res.push_back(i);
            if(i != n/i) res.push_back(n/i);
        }
    }
    sort(res.begin(), res.end());
    return res;
}

int N, X;
struct test{ll b, l, u, up;};
vector<test> T;
ll need;
ll sum[100010];
bool comp_test(test a, test b){
  return a.up < b.up;
}

bool can(ll tar){
  ll all = tar / X;
  if(all >= N) return 1;
  ll rest = tar % X;
  //all個のテストで満点を取る
  rep(i, N){
    //i番目のテストは中途半端にとる
    ll get;
    if(i < all) get = sum[all+1] - T[i].up;
    else get = sum[all];
    get += max(rest * T[i].l, rest * T[i].u - T[i].b * (T[i].u - T[i].l));
    if(get >= need) return 1;
  }
  return 0;
}

void solve(){
  cin >> N >> X;
  rep(i, N){
    ll b, l, u;
    cin >> b >> l >> u;
    ll up = (X - b) * u + b * l;
    T.pb({b, l, u, up});
    need += b * l;
  }
  sort(T.begin(), T.end(), comp_test);
  reverse(T.begin(), T.end());
  rep(i, N){
    sum[i+1] = sum[i] + T[i].up;
  }
  ll ng = -1, ok = INFL;
  while(ok - ng > 1){
    ll mid = (ok + ng) / 2;
    if(can(mid)) ok = mid;
    else ng = mid;
  }
  cout << ok << endl;
}

int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  solve();
}


#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
using namespace std;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<string> vstring;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;
#define all(a) a.begin(),a.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;
#define Pi 3.1415926535897932384626
#define mod llint(1e9+7)
#define Inf 2147483647
#define llInf 9223372036854775807

int main() {
	int h, w, a, b;
	cin >> h >> w >> a >> b;
	string ans = "";
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			if (j <= a && i <= b) {
				ans += "0";
			}
			else if (j > a&& i > b) {
				ans += "0";
			}
			else {
				ans += "1";
			}
		}
		ans += "\n";
	}
	cout << ans << endl;
	return 0;
}

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int h, w;
  cin >> h >> w;
  int a, b;
  cin >> a >> b;
  rep(i, h){
    rep(j, w){
      bool f1 = (i < b);
      bool f2 = (j < a);
      if((f1^f2) == true) cout << 0;
      else cout << 1;
    }
    cout << endl;
  }
  return 0;
}


#include<iostream>
using namespace std;

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

  int a,b,c;
  a=N/100, b=(N/10)%10, c=N%10;

  if (a == 7 || b == 7 || c == 7){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }

  return 0;
}

#include <bits/stdc++.h>
#define boost_io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define int long long
#define num(a) a-'0'
#define charr(a) (a - 'A' + 1)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define maxs(a,b) if(b>a)a=b
#define mins(a,b) if(b<a)a=b
#define debug(x) cerr<<"["<<#x<<":"<<x<<"] "
#define debug2(a,b) debug(a);debug(b)
#define debug3(a,b,c) debug2(a,b);debug(c)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/(__gcd(a,b))
#define print(arr) for(auto it = arr.begin();it < arr.end();it ++){cout << *it << " ";}cout << ln;
#define all(a) (a).begin(), (a).end()
#define vi vector<long long>
#define v vector
#define p pair
#define pb push_back
#define mk make_pair
#define f first
#define s second
#define ln "\n"
typedef long double ld;
typedef double d;
using namespace std;
int modF=1e9+7;
int INF=1e11;

void solve(){
	string n;
	cin>>n;
	int l=n.length();
	for(int i=0;i<l;i++){
		if(n[i]=='7'){
			cout<<"Yes\n";
			return;
		}
	}
	cout<<"No\n";
}

signed main(){
	boost_io;
	solve();
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
const int INF=1001001001;

int main() {
  string s;
  cin>>s;
  int n=s.size();
  stack<char>k;
  for(int i=0;i<n;i++){
    if(k.empty()){k.push(s[i]);}
    else if(s[i]=='S'){k.push(s[i]);}
    else if(s[i]=='T'){
      if(k.top()=='T'){k.push('T');}
      else if(k.top()=='S'){k.pop();}
    }
    //cout<<k.top()<<endl;
  }
  cout<<k.size()<<endl;
  return 0;
}

//#include<bits/stdc++.h>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
/*#define fast ios_base::sync_with_stdio(0); cin.tie(0)*/
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
const double pi = acos(-1);
typedef long long ll;
int main()
{
	//fast;

	ll n,ans;
	cin>>n;
	cout<<n/3;
}


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

class Graph {
    vector<vector<int>> adj;
    vector<int> color;

public:
    Graph(int n) : adj(n), color(n, -1) {}

    void connect(int a, int b) {
        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    bool dfs(int from = 0, int cur = 0) {
        color[from] = cur;
        for (auto to : adj[from]) {
            if (color[to] == cur) return false;
            if (color[to] == -1 && !dfs(to, 1 - cur)) return false;
        }
        return true;
    }

    vector<int> &getColor() {
        return color;
    }
};

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

    Graph graph(n);
    rep(i, 0, m) {
        int a, b;
        cin >> a >> b;
        graph.connect(--a, --b);
    }

    long long ans;
    if (graph.dfs()) {
        int cnt[2] = {0};
        for (auto i : graph.getColor()) cnt[i]++;
        ans = (long long)cnt[0] * cnt[1] - m;
    } else {
        ans = (long long)n * (n - 1) / 2 - m;
    }

    cout << ans << endl;

    return 0;
}

/*====Corycle====*/
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cstdlib>
#include<complex>
#include<cstdio>
#include<vector>
#include<cmath>
#include<ctime>
#include<stack>
#include<queue>
#include<map>
#define ll long long
using namespace std;
const int inf=0x3f3f3f3f;
const int N=1e5+5;
int read(){
	int s=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){s=s*10+c-'0';c=getchar();}
	return s*f;
}
int n,m,a[N],num[2][N],f[2][2],g[2][2];
int main(){
//	freopen("_.in","r",stdin);
//	freopen("_.out","w",stdout);
	n=read();
	for(int i=1;i<=n;i++){a[i]=read();num[i&1][a[i]]++;}
	for(int t=0;t<2;t++){
		for(int i=1;i<N;i++){
			if(f[t][0]<=num[t][i]){
				f[t][1]=num[t][g[t][1]=g[t][0]];
				f[t][0]=num[t][g[t][0]=i];
			}
			else if(f[t][1]<=num[t][i]){
				f[t][1]=num[t][g[t][1]=i];
			}
		}
	}
	if(g[0][0]!=g[1][0])printf("%d\n",n-f[0][0]-f[1][0]);
	else printf("%d\n",min(n-f[0][0]-f[1][1],n-f[0][1]-f[1][0]));
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

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

int intceil(int a, int b) {
    return (a + (b - 1)) / b;
}

signed main() {
    cin >> N;
    vi a(N);
    cin >> a;
    map<int, int> mp;
    vector<ll> v;
    REP(i, N) {
        int x = ++mp[a[i]];
        if ((x & 1) == 0) {
            v.push_back(a[i]);
        }
    }
    sort(v.rbegin(), v.rend());
    if (v.size() >= 2)
        cout << (ll)v[0] * (ll)v[1] << endl;
    else
        cout << 0 << endl;
}

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

int main()
{
  ll N; cin>>N;
  vector<ll> vecA(N);
  rep(i,N)
  {
    cin>>vecA.at(i);
  }
  sort(vecA.begin(),vecA.end());
  reverse(vecA.begin(),vecA.end());
  ll L=0;
  rep(i,N-1)
  {
    if(vecA.at(i)==vecA.at(i+1))
    {
      if(L==0) {L=vecA.at(i); i++; continue;}
      cout<<L*vecA.at(i)<<endl; return 0;
    }
  }
  cout<<0<<endl;
  return 0;
}


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

using namespace std;
#define loop(i,a,b) for(int i=(a);i<int(b);i++)
#define rep(i,b) loop(i,0,b)

typedef pair<int, int> pii;
int main(){
    int n;
    while(cin >> n && n){
        vector<pii> v(n);
        rep(i,n) v[i].second = i;
        int game = n * (n-1) / 2;

        rep(i,game){
            int a,b,c,d;
            cin >> a >> b >> c >> d;
            if(c>d) v[a-1].first += 3;
            else if(c < d) v[b-1].first += 3;
            else v[a-1].first++, v[b-1].first++;
        }

        sort(v.rbegin(), v.rend());
        int score = -1;
        int rank = 1;
        rep(i,n){
            if (v[i].first == score) v[i].first = rank;
            else {
                score=v[i].first;
                v[i].first=i+1;
                rank=i+1;
            }
        }
        sort(v.begin(), v.end(), [](pii l,pii r){
                return l.second < r.second;
            });
        rep(i,n)cout<<v[i].first<<endl;
    }
}

// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define forever for (;;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
template<typename A> using V = std::vector<A>;
template<typename A> using F = std::function<A>;
template<typename A, typename B> using P = std::pair<A, B>;
using pii = P<int, int>;
using vi = V<int>;
using vd = V<double>;
using vs = V<std::string>;
using vpii = V<pii>;
using vvi = V<vi>;
using vvpii = V<vpii>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int n) { return n & 1; }
constexpr bool even(const int n) { return ~n & 1; }
template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> std::istream &operator>>(std::istream &is, std::pair<A, B> &p) { is >> p.first; is >> p.second; return is; }
using namespace std;
// clang-format on

main {
  int n;
  cin >> n;
  vi v(n);
  rep(i, n * (n - 1) / 2) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    --a, --b;
    if (c == d) {
      v[a]++;
      v[b]++;
      continue;
    }
    v[c > d ? a : b] += 3;
  }
  rep(i, n) {
    int r = 1;
    rep(j, n) r += v[i] < v[j];
    cout << r << endl;
  }
}


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

const ll P = 1000000007;
const long long INF = 1LL << 60;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
vector<char> Alphabet = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
vector<char> alphabet = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main()
{
  cout << fixed << setprecision(10);
  int N,K;
  cin >> N >> K;
  vector<char> D(K);
  rep(i,K) cin >> D[i];
  vector<string> vec(100100);
  rep(i,100100)
  {
    int n = i;
    string str;
    str = to_string(n);
    vec[i] = str;
  }
  for(int i=N;i<P;i++)
  {
    int n = vec[i].size();
    bool ok = true;
    rep(j,n)
    {
      rep(k,K)
      {
        if(vec[i][j]==D[k])
        {
          ok = false;
        }
      }
    }
    if(ok)
    {
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}

#include<iostream>
using namespace std;
const int N=2e5+10;
int n,k;
int d[N];
int hs(int x){
	int f=0;
	while(x>0){
		if(d[x%10]) f=1;
		x/=10;
	}
	if(f) return 0;
	else return 1;
}
int main(){
	cin>>n>>k;
	for(int i=1;i<=k;i++){
		int x;
		cin>>x;
		d[x]=1;
	}
	for(int i=n;;i++)
		if(hs(i)){
			printf("%d",i);
			break;
		}
	return 0;
}