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

bool check(int a,int b,int c)
{
    if((a+b)>c && (c+b)>a && (a+c)>b)
        return true;
    return false;
}

int main()
{
    // freopen("input01.txt", "r", stdin);
    // freopen("output01.txt", "w", stdout);
    int n;
    cin>>n;
    map<ll int,int> mp;
    ll int a;
    int l,ct=0;
    for(l=0;l<n;l++)
    {
        cin>>a;
        mp[a]++;
    }

    if(mp.size()<3)
    {
        cout<<0;
        return 0;
    }

    for(auto i=mp.begin();next(next(i))!=mp.end();i++)
    {
        for(auto j=next(i);next(j)!=mp.end();j++)
        {
            for(auto k=next(j);k!=mp.end();k++)
            {
                if(check(i->first,j->first,k->first))
                    ct+=(i->second*j->second*k->second);
            }
        }
    }

    cout<<ct;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    int res=0;
    for(int i=0;i<n-2;i++)
    {
        for(int j=i+1;j<n-1;j++)
        {
            for(int k=j+1;k<n;k++)
            {
                if(a[i]==a[j] || a[j]==a[k])
                continue;
                if(a[i]+a[j]>a[k] && a[i]+a[k]>a[j] && a[j]+a[k]>a[i])
                res++;
            }
        }
    }
    cout<<res<<endl;
}


#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int A, B, C;
	cin >> A >> B >> C;
	cout << A + B + C - max({A, B, C}) << endl;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll int64_t
#define rep(i,n) for(int64_t i=0;i<n;++i)
#define P pair<ll,ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr int64_t INF=(1ll<<60);
constexpr int64_t mod=1000000007;
constexpr double pi=3.14159265358979323846;
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

Graph G;
ll n;

void bfs(vector<ll> &dist,queue<ll> que,ll start){
    vector<bool> visit(n,false);
    que.push(start);

    while(!que.empty()){
        ll now=que.front();
        que.pop();
        visit[now]=true;
        for(ll next:G[now]){
            if(visit[next]==true) continue;

            visit[next]=true;
            que.push(next);

            dist[next]=dist[now]+1;
        }
    }

    return;
}

int main(){
    ll u,v;cin>>n>>u>>v;
    u--;v--;
    G.resize(n);
    rep(i,n-1){
        ll a,b;cin>>a>>b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    queue<ll> que;
    vector<ll> takahashi(n),aoki(n);

    bfs(takahashi,que,u);
    bfs(aoki,que,v);

    ll ans=0,key=0;
    rep(i,n){
        if(aoki[i]>takahashi[i]){
            chmax(ans,aoki[i]);
        }
    }

    ans--;

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


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

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

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

int main() {

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

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

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

/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using Pair = pair<int64_t, int64_t>;
constexpr int64_t kInf = INT64_MAX / 2L;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  int64_t N, M;
  cin >> N >> M;
  int64_t result = 1;
  for (int64_t d = 1; d * d <= M; ++d) {
    if (M % d == 0 && M / d >= N) {
      result = max(result, d);
    }
    if (M % d == 0 && d >= N) {
      result = max(result, M / d);
    }
  }
  cout << result << endl;
  return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define ld long double
#define PI 3.141592653L
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const ll INF = (ll)1e18;
const int N = 2e5 + 5;
const ll MOD = 1e9+7;

int parent[N];

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

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

ll pow(ll x, ll y, ll p) {
    if(y == 0) return 1;
    ll res = 1;
    x %= p;
    if(x == 0) return 0LL;
    while(y > 0) {
        if(y & 1) res = (res*x) % p;
        y >>= 1;
        x = (x*x) % p;
    }
    return res;
}

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

void Union(int x, int y) {
    int xPar = find(x), yPar = find(y);
    if(xPar != yPar) parent[xPar] = yPar;
}

ll nCr(ll n, ll r) {
    ll res = 1;
    for(ll i=1;i<=r;i++) {
        res = res * (n - r + i) / i;
        // is different from
        // res *= (n -r + i) / i;
    }
    return res;
}

int ask(int i, int j) {
    cout << "? " << i + 1 << ' ' << j + 1 << endl;
    int v;
    cin >> v;
    return v;
}

void solve() {
    int n, x, t;
    cin >> n >> x >> t;
    cout << (int)(ceil)(n / (double)x) * t << endl;
    return;
}

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


#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <tuple>
#include <cstring>
#include <map>
#include <iomanip>
#include <ctime>
#include <complex>
#include <cassert>
#include <climits>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define _ << " " <<
#define all(X) (X).begin(), (X).end()
#define len(X) (X).size()
#define Pii pair<int, int>
#define Pll pair<ll, ll>
#define Tiii tuple<int, int, int>
#define Tlll tuple<ll, ll, ll>

bool dual = 1;
int d[100020] = {};
vector<int> G[100010];
vector<bool> vis;

void dfs(int k, int dep) {
    vis[k] = 1;
    if (d[k] == 0) {
        if (dep % 2) d[k] = 1;
        else d[k] = 2;
    }
    for (auto &i : G[k]) {
        if (!vis[i]) {
            dfs(i, dep + 1);
        }
        else if (d[i] % 2 == dep % 2) {
            dual = 0;
            return;
        }
    }
}

int main() {
    ll n, m;
    cin >> n >> m;
    int x[m], y[m];
    vis.assign(n, 0);
    for (int i = 0; i < m; i++) {
        cin >> x[i] >> y[i];
        x[i]--;  y[i]--;
        G[x[i]].push_back(y[i]);
        G[y[i]].push_back(x[i]);
    }

    dfs(0, 0);
    if (dual) {
        ll p = 0, q = 0;
        for (int i = 0; i < n; i++) {
            if (d[i] == 1) p++;
            else q++;
        }
        ll ans = p * q;
        for (int i = 0; i < m; i++) {
            if (d[x[i]] != d[y[i]]) ans--;
        }
        cout << ans << endl;
    }
    else {
        cerr << 0 << endl;
        cout << n * (n - 1) / 2 - m << endl;
    }
}

#include<bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl #define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl #define no cout<<"no"<<endl
#define vec(a,y,x)  vector<vector<char>> a (y,vector<char>(x))
const vector<int> dx={1,0,-1,0};
const vector<int> dy={0,1,0,-1};

in sum_vec(vector<int> a){
  in sum=0;
  rep(i,a.size())
    sum+=a.at(i);
  return sum;
}

vector<int> color;
bool dfs (vector<vector<int>>&G,int v,int cur){
  color.at(v)=cur;
  for(int next_v : G.at(v)){
    //cout<<"v:"<<v<<" next_v:"<<next_v<<" ";
    if(color.at(next_v)==-1){
      //cout<<"未探索"<<endl;
      if(!dfs(G,next_v,1-cur)) return false;
    }
    else{
      if(color.at(next_v)==cur) {/*cout<<"矛盾"<<endl;*/ return false;}
      if(color.at(next_v)==1-cur){/*cout<<"矛盾無し"<<endl;*/ continue;}
    }
  }
  return true;
}

int main(){
  in m;
  in n;
  cin>>n>>m;
  vector<vector<int>> G(n);

  rep(i,m){
    int a,b;
    cin>>a>>b;
    G.at(a-1).push_back(b-1);
    G.at(b-1).push_back(a-1);
  }
  color.assign(n,-1);
  in sum;

  if(dfs(G,0,0)){
    sum=sum_vec(color);
    printf("%ld \n",sum*(n-sum)-m);
  }
  else
    printf("%ld \n",(n*(n-1))/2-m);
  //color.assign(n,-1);
  //cout<<dfs(G,0,0)<<endl;
  //cout<<sum<<endl;
  //rep(i,n)
    //cout<<color.at(i);

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll n,ans=0,a,b;
int main()
{
	cin>>n;
	cin>>a;
	for(int i=1;i<=n-1;i++)
	{
		cin>>b;
		if(b<a) ans+=a-b;
		else a=b;
	}
	cout<<ans;
return 0;
}

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

using namespace std;
using p=pair<int,int>;
typedef long long ll;

int main() {
  int n,r;
  cin >> n >> r;
  int ans=0;
  if(n<=9){
    ans=r+100*(10-n);
  }
  else{
    ans=r;
  }
  cout << ans << endl;

  return 0;

}


#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << (x) << endl
#define debugArray(x, n)                                      \
  cerr << __LINE__ << ": " << #x << " = {";                   \
  for (long long hoge = 0; (hoge) < (long long)(n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];                   \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  int N;
  cin >> N;
  long long L[N], R[N];
  for (int i = 0; i < N; i++) cin >> L[i] >> R[i];
  int idx[N];
  iota(idx, idx + N, 0);
  // debugArray(idx, N);
  auto step = [&]() {
    long long leftl[N + 1], leftr[N + 1], rightl[N + 1], rightr[N + 1];
    leftl[0] = 0, leftr[0] = INT_MAX;
    for (int i = 0; i < N; i++) {
      int j = idx[i];
      leftl[i + 1] = max(leftl[i], L[j]);
      leftr[i + 1] = min(leftr[i], R[j]);
    }
    rightl[N] = 0, rightr[N] = INT_MAX;
    for (int i = N - 1; i >= 0; i--) {
      int j = idx[i];
      rightl[i] = max(rightl[i + 1], L[j]);
      rightr[i] = min(rightr[i + 1], R[j]);
    }
    // debugArray(leftl, N + 1);
    // debugArray(leftr, N + 1);
    // debugArray(rightl, N + 1);
    // debugArray(rightr, N + 1);
    long long ret = 0;
    for (int i = 0; i < N - 1; i++) {
      ret = max(ret, max(0ll, leftr[i + 1] - leftl[i + 1] + 1)
                         + max(0ll, rightr[i + 1] - rightl[i + 1] + 1));
    }
    for (int i = 0; i < N; i++) {
      int j = idx[i];
      int ll = max(leftl[i], rightl[i + 1]);
      int rr = min(leftr[i], rightr[i + 1]);
      ret = max(ret, max(0, rr - ll + 1) + R[j] - L[j] + 1);
    }
    return ret;
  };
  long long ans = 0;
  sort(idx, idx + N,
       [&](int l, int r) { return L[l] == L[r] ? R[l] > R[r] : L[l] < L[r]; });
  ans = max(ans, step());
  sort(idx, idx + N,
       [&](int l, int r) { return R[l] == R[r] ? L[l] > L[r] : R[l] < R[r]; });
  ans = max(ans, step());
  cout << ans << '\n';
  return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;

#define f first
#define s second
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define pb push_back

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (int i = (b); i >= (a); i--)
#define R0F(i, a) ROF(i, 0, a-1)
#define trav(x, a) for (auto& x: a)

const int MX  = 2e5+5;
const int MOD = 1e9+7;
const ll  INF = 1061109567; // 4557430888798830399LL
const ld  EPS = 1e-9;
const ld  PI  = acos(-1);

ll arr[18][18],dp[1<<18],cost[1<<18];

int main() {

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

    int N; cin >> N;

    F0R(i,N) F0R(j,N) {
        cin >> arr[i][j];
    }

    memset(dp,-1,sizeof dp);
    F0R(i,N) dp[i] = 0;

    F0R(mask,1<<N) {
        F0R(i,N) {
            FOR(j,i+1,N) {
                if (mask&(1<<i) && mask&(1<<j)) {
                    cost[mask] += arr[i][j];
                }
            }
        }
    }

    F0R(mask,1<<N) {
        for (int smask = mask; smask; smask = (smask-1)&mask) {
            dp[mask] = max(dp[mask],dp[mask^smask]+cost[smask]);
        }
    }

    cout << dp[(1<<N)-1] << "\n";

}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll MOD=1000000007;
int main(void){
    int n;
    cin>>n;
    int ans=0;
    int a;
    set<int> s;
    while(n--){
        cin>>a;
        auto itr=s.lower_bound(a);
        if(a==(*itr)){
            ans--;
            s.erase(a);
        }else{
            ans++;
            s.insert(a);
        }
    }
    cout<<ans<<endl;

}

#include <bits/stdc++.h>

using namespace std;

int main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   int n;
   cin >> n;
   map<int, int> mp;
   for(int i = 0; i < n; i++) {
       int foo;
       cin >> foo;
       mp[foo]++;
   }
   int ans = 0;
   for(auto p : mp) {
       if(p.second & 1) ans++;
   }
   cout << ans << endl;
}


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

int main(){
	int n,m,x[10001],y[10001],c;
	bool tomo[600][600],party[600][2];
	while(true){
		memset(tomo,false,sizeof(tomo));
		memset(party,false,sizeof(party));
		cin>>n;
		cin>>m;
		c=0;
		if(n==0 && m==0){
			break;
		}
		for(int i=0;i<m;i++){
			cin>>x[i]>>y[i];
			tomo[x[i]][y[i]]=true;
			tomo[y[i]][x[i]]=true;
		}
		for(int i=2;i<=n;i++){
			if(tomo[1][i]==true){
				party[i][0]=true;
			}
		}
		for(int i=2;i<=n;i++){
			if(party[i][0]==true){
				for(int j=2;j<=n;j++){
					if(tomo[i][j]==true){
						party[j][1]=true;
					}
				}
			}
		}
		for(int i=2;i<=n;i++){
			if(party[i][0]==true || party[i][1]==true){
				c++;
			}
		}
		cout<<c<<endl;
	}
	return 0;
}


# include<bits/stdc++.h>

using namespace std;

# define int long long
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, int> pdi;
typedef pair<ll, ll> pll;

# define S second
# define F first
# define kill(x) return(cout << x << endl, 0)
# define debug(x) cerr<< #x << " : " << x << endl
# define ddebug(x, y) cerr<< #x << " : " << x  << ", " << #y << " : " << y << endl
# define sz(s) (int)s.size()
# define sq(x) (x) * (x)
# define PB(x) push_back(x)
# define smax(x, y) (x) = max((x), (y))
# define smin(x, y) (x) = min((x), (y))
# define all(x) x.begin(), x.end()
# define SP fixed << setprecision(10)

const int MAXN = 2000 + 10;
int cnt[MAXN][MAXN], a1[MAXN][MAXN], a2[MAXN][MAXN];
string s[MAXN];

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

	int n, m, q;
	cin >> n >> m >> q;
	for (int i = 0; i < n; i ++)
		cin >> s[i];

	for (int i = 0; i < n; i ++)
		for (int j = 0; j < m; j ++)
			cnt[i + 1][j + 1] = cnt[i + 1][j] + cnt[i][j + 1] - cnt[i][j] + (s[i][j] - '0');

	for (int i = 0; i < n; i ++)
		for (int j = 1; j < m; j ++)
			a1[i + 1][j + 1] = a1[i + 1][j] + a1[i][j + 1] - a1[i][j] + (s[i][j] == '1' && s[i][j - 1] == '1');

	for (int i = 1; i < n; i ++)
		for (int j = 0; j < m; j ++)
			a2[i + 1][j + 1] = a2[i + 1][j] + a2[i][j + 1] - a2[i][j] + (s[i][j] == '1' && s[i - 1][j] == '1');

	while (q --)
	{
		int x1, y1, x2, y2;
		cin >> x1 >> y1 >> x2 >> y2;
		cout << (cnt[x2][y2] - (cnt[x2][y1 - 1] + cnt[x1 - 1][y2] - cnt[x1 - 1][y1 - 1])) -
			((a1[x2][y2] - (a1[x2][y1] + a1[x1 - 1][y2] - a1[x1 - 1][y1])) +
			 (a2[x2][y2] - (a2[x1][y2] + a2[x2][y1 - 1] - a2[x1][y1 - 1]))) << endl;
	}

	return 0;
}

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
#define double long double
typedef pair<double, string> P;

bool solve(){
	int n;
	string name;
	int p, a, b, c, d, e, f, s, m;
	P data[50];

	cin >> n;
	if( n == 0 ) return false;
	for( int i = 0; i < n; i++ ){
		cin >> name >> p >> a >> b >> c >> d >> e >> f >> s >> m;
		int income = s * f * m - p;
		int timer = a + b + c + m * (d + e);
		double effect = (double)income / timer;
		data[i].first = -effect;	//Swap Order Technic.
		data[i].second = name;
	}
	sort(data, data + n);

	for( int i = 0; i < n; i++ ){
		cout << data[i].second << endl;
	}
}

int main(){
	while(1){
		if( !solve() )
			break;
		else
			cout << "#" << endl;
	}
	return 0;
}


// J'aime
// Chemise Blanche

#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()
#define dbg(x) cerr << __LINE__ << " > " << #x << " = " << (x) << endl

void MAIN() {
  int a, b;
  cin >> a >> b;
  cout << max(max(a + b, a - b), a * b) << '\n';
}

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

#include <iostream>
#include <vector>

using namespace std;

int main(){
    int N, M; cin >> N >> M;
    vector<vector<long long>> dp(3*N+1, vector<long long>(N+1, 0));
    dp[3*N][0] = 1;
    for(int i=3*N;i>0;i--){
        for(int j=0;j<=N;j++){
            long long m = 1;
            for(int k=1;k<=3;k++){
                if(i-k < 0) break;
                if(j+k/2 > N) break;
                dp[i-k][j+k/2] += dp[i][j] * m;
                dp[i-k][j+k/2] %= M;
                m = m * (i-k) % M;
            }
        }
    }
    long long res = 0;
    for(int i=0;i<=N;i++) res = (res + dp[0][i]) % M;
    cout << res << endl;
}


#include <bits/stdc++.h>
using namespace std;
int n,r,ans;
int main()
{
    scanf("%d%d",&n,&r);
    if(n<10){
        ans=r+100*(10-n);
        printf("%d",ans);
    }else{
        ans=r;
        printf("%d",ans);
    }
    return 0;
}

#include <iostream>
#include <vector>

using namespace std;

void abc_150a();

void abc_151a();

void abc_152a();

void abc_154a();

void abc_156a();

int main()
{
  //abc_150a();
  //abc_151a();
  //abc_152a();
  //abc_154a();
  abc_156a();

}

void abc_150a()
{
  int K, X;
  cin >> K >> X;

  if (500 * K >= X) cout << "Yes\n";
  else cout << "No\n";
}

void abc_151a()
{
  char C;
  cin >> C;

  cout << (char)((int)C + 1) << "\n";
}

void abc_152a()
{
  int N, M;
  cin >> N >> M;
  if (N == M) cout << "Yes\n";
  else cout << "No\n";
}

void abc_154a()
{
  string S, T;
  cin >> S >> T;
  int a, b;
  cin >> a >> b;
  string U;
  cin >> U;

  if (S == U) cout << a - 1 << " " << b << "\n";
  else cout << a << " " << b - 1 << "\n";

}

void abc_156a()
{
  int N, R;
  cin >> N >> R;

  if (N >= 10) cout << R << "\n";
  else cout << R + 100 * (10 - N) << "\n";
}


#include<bits/stdc++.h>
using namespace std;
int n,t,a[505050],tr[505050],ans[505050],lt[505050];
vector<int>q[505050],qq[505050];
void gx(int x,int vl)
{
	while(x<=n)
	{
		tr[x]+=vl;
		x+=x&(-x);
	}
}
int sm(int x)
{
	int rt=0;
	while(x>0)
	{
		rt+=tr[x];
		x-=x&(-x);
	}
	return rt;
}
int main()
{
	cin>>n>>t;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	for(int i=1;i<=t;i++)
	{
		int l,r;
		cin>>l>>r;
		q[r].push_back(l);
		qq[r].push_back(i);
	}
	for(int i=1;i<=n;i++)
	{
		if(lt[a[i]]!=0)
		{
			gx(lt[a[i]],-1);
		}
		lt[a[i]]=i;
		gx(i,1);
		for(int j=0;j<q[i].size();j++)
		{
			ans[qq[i][j]]=sm(i)-sm(q[i][j]-1);
		}
	}
	for(int i=1;i<=t;i++)
	{
		cout<<ans[i]<<endl;
	}
	return 0;
}

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

const int MAXN = 5e5 + 10;
const int MAX_NODE_CNT = MAXN << 6;

int n, m, lst[MAXN];

struct Persistent_Segment_Tree {
    #define mid ((l + r) >> 1)
    #define ls(_) t[_].ls
    #define rs(_) t[_].rs
    #define lq(_) t[_].ls, l, mid
    #define rq(_) t[_].rs, mid + 1, r
    int node_cnt, rt[MAXN];
    int& operator [](const int& x) { return rt[x]; }
    struct node { int ls, rs, data; } t[MAX_NODE_CNT];
    int build(int l, int r) {
        int cur = ++node_cnt;
        if (l == r) return cur;
        ls(cur) = build(l, mid), rs(cur) = build(mid + 1, r);
        return cur;
    }
    int modify(int pre, int l, int r, int pos, int val) {
        int cur = ++node_cnt; t[cur] = t[pre], t[cur].data += val;
        if (l == r) { return cur; }
        if (pos <= mid) ls(cur) = modify(ls(pre), l, mid, pos, val);
        else rs(cur) = modify(rs(pre), mid + 1, r, pos, val);
        return cur;
    }
    int query(int cur, int l, int r, int ql, int qr) {
        if (ql <= l && r <= qr) return t[cur].data;
        int ret = 0;
        if (ql <= mid) ret += query(lq(cur), ql, qr);
        if (qr > mid) ret += query(rq(cur), ql, qr);
        return ret;
    }
} t;

int main() {
    scanf("%d %d", &n, &m);
    t[0] = t.build(1, n);
    for (int i = 1, x; i <= n; ++i) {
        scanf("%d", &x); t[i] = t.modify(t[i - 1], 1, n, i, 1);
        if (lst[x]) t[i] = t.modify(t[i], 1, n, lst[x], -1);
        lst[x] = i;
    }
    int pre_ans = 0;
    for (int i = 1, u, v; i <= m; ++i) {
        scanf("%d %d", &u, &v);
        printf("%d\n", (t.query(t[v], 1, n, u, v)));
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,d,ans;
    while(cin >> a >> b >> c >> d){
        ans = 0;
        ans+=min(a,b);
        ans+=min(c,d);
        cout << ans << endl;
    }
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,n,a[5],b[5];
    n=2;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(i=0;i<n;i++)
    {
        cin>>b[i];
    }
    sort(a,a+n);
    sort(b,b+n);
    cout<<a[0]+b[0]<<endl;
    return 0;
}


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

int main(){
    ll x,y;
    cin >> x >> y;
    ll ans;
    // 1回目に符号を反転させる場合
    ll A = 1 + y - (-x);
    // 最後に符号を反転させる場合
    ll B = (-y) - x + 1;
    // 最初と最後に符号を反転させる場合
    ll C = 2 + (-y) - (-x);
    // 反転させない場合
    ll D = y - x;
    if(A<0) A = INF;
    if(B<0) B = INF;
    if(C<0) C = INF;
    if(D<0) D = INF;
    ans = min(min(A,B),min(C,D));
    cout << ans << endl;
    return 0;
}

#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <string.h>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#include <random>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define gep(i,g,j) for(int i = g.head[j]; i != -1; i = g.e[i].next)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcount
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define df(x) int x = in()
#define dame { puts("-1"); return 0;}
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,vector<T>,greater<T> >
#define bn(x) ((1<<x)-1)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
inline void priv(vi a) { rep(i,sz(a)) printf("%d%c",a[i],i==sz(a)-1?'\n':' ');}
template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(vector<T>&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,vector<T>&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;

int main() {
  int a,b;
  scanf("%d%d",&a,&b);
  if (a == b) {
    cout<<0<<endl;
    return 0;
  }
  if (abs(a) == abs(b)) {
    cout<<1<<endl;
    return 0;
  }
  if (abs(a) < abs(b)) {
    int ans = abs(b)-abs(a);
    if (a < 0) ans++;
    if (b < 0) ans++;
    cout<<ans<<endl;
    return 0;
  } else {
    int ans = abs(a)-abs(b);
    if (a > 0) ans++;
    if (b > 0) ans++;
    cout<<ans<<endl;
    return 0;
  }
  return 0;
}


#include <iostream>
using namespace std;
int main(void){
    int a,b;
    cin>>a>>b;
    if (a<b){
        int tmp =a;
        a=b;b=tmp;
    }
    int ans = a;
    a--;
    if (a<b){
        int tmp =a;
        a=b;b=tmp;
    }
    ans+=a;
    cout<<ans;
}

#include "iostream"
using namespace std;
int main(){
  int a; int b;
  cin>>a>>b;
  if(a==b){
    cout<<2*a<<endl;

  }
  else if(a>b){
    cout<<a+(a-1)<<endl;
  }
  else{
    cout<<b+(b-1)<<endl;
  }
}


#include <bits/stdc++.h>		//万能头文件
using namespace std;

int main()
{
	string a;
	int pos=0;		//记录位置
	cin>>a;
	a=a+"D";		//为防止最后一个字母是"A",添加一个不是"C"的字母
	while(1)
	{
		pos=a.find("A",pos);		//find()函数查找位置
		if(pos<0)		//如果没找到，返回-1
		{
			cout<<"No"<<endl;		//endl养成好习惯
			break;		//跳出循环
		}
		if(a[pos+1]=='C')		//判断"A"下一个是不是"C"
		{
			cout<<"Yes"<<endl;
			break;		//跳出循环
		}
		pos++;		//下一次从pos+1找起
	}
	return 0;
}

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

int main(){
  string s;cin>>s;
  int r=0;
  for(int i=1;i<s.size();++i){
    if(s[i]=='C'&&s[i-1]=='A'){r=1;break;}
  }
  cout<<(r?"Yes":"No");
}


#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

void abc_160a();

void abc_161a();

void abc_162a();

void abc_163a();

int main()
{
  //abc_160a();
  //abc_161a();
  //abc_162a();
  abc_163a();

}

void abc_160a()
{
  string S;
  cin >> S;

  if (S[2] == S[3] && S[4] == S[5]) cout << "Yes\n";
  else cout << "No\n";
}

void swap(int& a, int& b)
{
  int tmp;
  tmp = a;
  a = b;
  b = tmp;
}

void abc_161a()
{
  int x, y, z;
  cin >> x >> y >> z;

  swap(x, y);
  swap(x, z);

  cout << x << " " << y << " " << z << "\n";
}

void abc_162a()
{
  string s;
  cin >> s;
  for (char c : s)
  {
    if (c == '7')
    {
      cout << "Yes\n";
      return;
    }
  }

  cout << "No\n";
}

void abc_163a()
{
  int R;
  cin >> R;

  cout << (double)(2 * R * M_PI);
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using i64 = int64_t;
using ll = long long;
int main() {
  string S;
  cin >> S;
  int count = 0;
  rep(i,3){
    if(S.at(i) == 'R'){
      count ++;
    }
  }
  if(count == 2){
    if(S.at(1) == 'S'){
      count --;
    }
  }
  cout << count << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef struct _dot{
    int x;
    int y;
}Dot;
bool Check(vector<Dot> list,int Assumption[]){

    for(int i=0;i<list.size();i++){
        if(Assumption[list[i].x ] != list[i].y) return false;
    }
    return true;
}
int main(){

    int N; cin >> N;
    vector<vector<Dot>> list(N);

    for(int i=0;i<N;i++){
        int k; cin >> k;
        for(int j=0;j<k;j++){
            int x,y; cin >> x >> y;
            Dot k; k.x = x-1; k.y = y;
            list.at(i).push_back(k);
        }
    }

    int ans = 0;
    int size = pow(2,N) - 1;
    for (int bits = size;bits >=0; bits--) {

        int Assumption[N];
        int num = 0;
        for(int i=0;i<N;i++){
            int mask = 1 << i;
            if(bits & mask){Assumption[i] = 1;num++;}
            else{Assumption[i] = 0;}
        }
        for (int i=0;i<N;i++) {
            int mask = 1 << i;
            if (bits & mask) {

                if(Check(list.at(i),Assumption) == false) break;
            }
            if(i== N-1 && ans < num) ans = num;
        }

    }
    cout << ans << endl;
}

#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
typedef pair<int,int> P;
const int MOD = 1000000007;
const ll INF = 1e10;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)};

////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////

int n,m,a[310][310], ans;
int cnt[310];bool used[310];
void j(){
  P mx;
  while(true){
    rep(i,m)cnt[i] = 0;
    rep(i,n){
      rep(j,m){
        if(!used[a[i][j]]){
          cnt[a[i][j]]++;
          break;
        }
      }
    }
    mx = P(-1, -1);
    rep(i,m)if(mx.first < cnt[i])mx = P(cnt[i], i);
    chmin(ans, mx.first);
    used[mx.second] = true;
    bool r = false;rep(i,m)if(!used[i])r = true;
    if(!r)return;
  }
}

signed main(){
  cin>>n>>m;
  rep(i,n)rep(j,m){
    cin>>a[i][j];a[i][j]--;
  }
  ans = INF;j();
  cout << ans << endl;
}


#include<bits/stdc++.h>
using namespace std;
#define int            int64_t
#define double         long double
#define nitro          ios_base::sync_with_stdio(false);cin.tie(0);
#define vi             vector<int64_t>
#define pub            push_back
#define puf            push_front
#define pob            pop_back
#define pof            pop_front
#define PI             3.1415926535897932384626433832795
#define read(a)        for(auto& x : a) cin>> x
#define endl           '\n'
#define gap            ' '
#define min3(a,b,c)    min(a, min(b, c))
#define max3(a,b,c)    max(a, max(b, c))
#define MOD            1000000007
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
int32_t main()
{
    nitro
    int n;cin>>n;
    int a=ceil(sqrt(n));
    for(int i=a;~i;--i)
    if(i*i<=n) return cout<<i*i,0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
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; }
const ll INF=1LL<<60;
const int inf=1<<30;
const int mod=1e9+7;
const int MOD=998244353;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin >> n;
    cout << n/3 << endl;
}


#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;
#define vec(s) vector<s>
#define vvec(s) vector<vector<s>>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes(x) cout<<(x?"Yes":"No")<<endl;
#define YES(x) cout<<(x?"YES":"NO")<<endl;
#define out(s) cout<<s<<endl;
#define Reverse(x) reverse(all(x));
#define Sort(x) sort(all(x));
#define pb(s) push_back(s);
#define sp " "
#define INF 10000000000
#define LINF 9000000000000000000
#define all(s) s.begin(),s.end()
void vout(vi v){
    for(lli i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    cout << std::fixed << std::setprecision(10);
    lli a, b,k;
    cin >> a >> b >> k;
    lli c = true;
    rep(i, k) {
        if(c)
        {
            if(a%2!=0)
            {
                a--;

            }
            b += a / 2;
            a -= a / 2;
            c = false;
        }
        else
        {
            if(b%2!=0)
            {
                b--;

            }
            a += b / 2;
            b -= b / 2;
            c = true;
        }
    }
    out(a << sp << b);
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
int main() {
  cout << fixed << setprecision(10);
  double n,k;
  cin >> n >> k;
  cout << (int)(ceil(n/k)-floor(n/k)) << endl;
}

#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <map>
#include <tuple>
#include <cmath>
#include <cstdio>
#include <cassert>
#include <functional>
#define _LIBCPP_DEBUG 0
using namespace std;

int main(void){
    int l,r;
    cin >> l >> r;
    int mi=2018*2018;
    for (int  i = l; i<r; i++)
    {
        int L=i%2019;
        for (int j = i+1; j <= r; j++)
        {
            int R=j%2019;
            int ama=(L*R)%2019;
            if (ama<mi)
            {
                mi=ama;
                if (mi==0)
                {
                    cout << 0 << endl;
                    return 0;
                }
            }
        }
    }
    cout << mi << endl;

}


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

void solve(){
    int n, x, ans=0;
    map<int, int> mp;
    cin >> n;
    while(n--){
        cin >> x;
        if(!mp[x]){
            mp[x]=1;
            ans++;
        }else mp[x]=0, ans--;
    }
    cout << ans << endl;
}
int main(){
   solve();
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int main() {
    int n;
    cin >> n;
    vector<int>a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    int ans=n;
    for(int i=1;i<n;i++){
        if(a[i-1]==a[i]){
            ans-=2;
            i++;
        }
    }
    cout << ans << endl;
}


#include <iostream>
using namespace std;
int num=0;
int liner_search(int x,int S[],int N){
	int n=0;
	while(n<N && S[n]!=x){
		n++;
	}
	if(n<N){
		++num;
		return n;
	}
	else
		return -1;
}
int main(){

	int num1;
	cin>>num1;
	int a[num1];
	for(int i=0;i<num1;i++)
		cin>>a[i];
	int num2;
	cin>>num2;
	int b[num2];
	for(int i=0;i<num2;i++)
		cin>>b[i];
	int x[num2];
	for(int i=0;i<num2;i++){
		x[i]=liner_search(b[i],a,num1-1);
	}
	cout<<num<<endl;

	return 0;
}

#include <cstdio>
#include <cstdlib>
#define N 10000
#define Q 500

using namespace std;

int main(){
	int *a,*b;
	a = new int[N];
	b = new int[Q];
	int n,q;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf(" %d", &a[i]);
	}
	scanf("%d",&q);
	for(int i=0;i<q;i++){
		scanf(" %d", &b[i]);

	}
	int ans = 0;
	for(int i=0;i<q;i++){
		for(int j=0;j<n;j++){
			if(a[j] == b[i] ){
				ans++;
				break;
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}


#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    int n, k;
    cin >> n >> k;
    int v = 1;
    rep(i, n) {
        v = min(v * 2, v + k);
    }
    put(v)

    return 0;
}

#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
#define rep(i,n) for (ll i = 0; i < (ll)(n); ++i)
#define rrep(i,j,n) for(ll i = (ll)(j); i < (ll)(n); i++)
#define mrep(i,n) for (ll i = (ll)(n-1); i > 0; i--)
#define be(v) (v).begin(), (v).end()
#define scout cout << fixed << setprecision(20)
ll INF = 1LL << 60;
ll mod = 1e9 + 7;

int main() {
	vint a(3);
	rep(i,3) cin >> a[i];
	int k; cin >> k;
	sort(be(a));
	rep(i,k) a[2]=a[2]*2;
	cout << a[0]+a[1]+a[2] << endl;
}


#include<cstdio>
#include<vector>
#include<algorithm>
#include<utility>
#include<numeric>
#include<iostream>
#include<array>
#include<string>
#include<sstream>
#include<stack>
#include<queue>
#include<list>
#include<functional>
#define _USE_MATH_DEFINES

#include<math.h>
#include<map>

#define SENTINEL 1000000001

#define min(a,b) ((a)>(b)?(b):(a))
#define max(a,b) ((a)>(b)?(a):(b))

#define INF 200000000000

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;

struct OwnEdge
{
	ll from, to, cost;
	OwnEdge() :from(-1), to(-1), cost(-1) {}
	OwnEdge(ll from, ll to, ll cost) : from(from), to(to), cost(cost) {}
};

OwnEdge edges[10000];
ll tod[100][100];

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

	int V, E;
	scanf("%d %d", &V, &E);

	for (int i = 0; i < V; i++)for (int j = 0; j < V; j++)
	{
		tod[i][j] = INF;
	}

	for (int i = 0; i < E; i++)
	{
		int s, t, d;
		scanf("%d %d %d", &s, &t, &d);

		edges[i] = OwnEdge(s, t, d);
	}

	for (int k = 0; k < V; k++)
	{
		tod[k][k] = 0;

		bool ns = false;
		for (int i = 0; i < V; i++)
		{
			for (int j = 0; j < E; j++)
			{
				OwnEdge t = edges[j];
				if (tod[k][t.from] != INF&&tod[k][t.to]>(tod[k][t.from] + t.cost))
				{
					tod[k][t.to] = (tod[k][t.from] + t.cost);
					if (i == (V - 1))
					{
						ns = true;
					}
				}
			}
		}
		if (ns)
		{
			printf("NEGATIVE CYCLE\n");
			return 0;
		}
	}

	for (int i = 0; i < V; i++)
	{
		for (int j = 0; j < V; j++)
		{
			if (j == 0)
			{
				printf(tod[i][j] == INF ? "INF" : "%lld", tod[i][j]);
			}
			else
			{
				printf(tod[i][j] == INF ? " INF" : " %lld", tod[i][j]);
			}
		}
		printf("\n");
	}

	return 0;
}

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
const int maxn = 100 + 10;

int n, m, a[maxn];
int main() {
	scanf("%d%d", &n, &m);
	int cnt = 0;
	for(int i = 1;i <= m;i ++) scanf("%d", &a[i]), cnt = cnt + ((a[i] & 1) ? (1) : (0));
	if(cnt > 2) puts("Impossible");
	else {
	  for(int i = 1;i <= m;i ++) {
	    if(a[i] & 1) {
	      if(a[1] & 1) swap(a[i],a[m]);
	      else swap(a[1],a[i]);
			}
		}
		for(int i = 1;i <= m;i ++) printf("%d ", a[i]);
		puts("");
		if(m == 1) a[++ m] = a[1], a[1] = 0;
		a[1] ++;
		a[m] --;
		if(!a[m]) m --;
		printf("%d\n", m);
		for(int i = 1;i <= m;i ++) printf("%d ", a[i]);
		puts("");
	}
  return 0;
}


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

int func(int N){// 例: 11221213312, 12,  432,  8
  if (N < 10) return N;
  return func(N/10) + N % 10;
}

int main()
{
  int n;
  cin >> n;
  int s = func(n);
  if (n % s == 0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;

}

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

int main() {
  string s;
  cin >> s;
  for(int i=0; i < s.size()-1; i++) {
    if(s.substr(i,2) == "AC"){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}


// 問題の URL を書いておく
//

#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>

using namespace std;

//#define ENABLE_PRINT

#if defined(ENABLE_PRINT)

#define Print(v) \
do {\
    cout << #v << ": " << v << endl; \
}while(0)

#define PrintVec(v) \
do {\
    for(int __i = 0; __i < v.size(); ++__i) \
    { \
        cout << #v << "[" << __i << "]: " << v[__i] << endl; \
    }\
}while(0)

#else

#define Print(v) ((void)0)
#define PrintVec(v) ((void)0)

#endif

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

using ll = int64_t;

int main(int, const char**)
{
    string s;
    cin >> s;
    int ans;
    if(s == "RRR")
    {
        ans = 3;
    }
    else if(s == "RRS" || s == "SRR")
    {
        ans = 2;
    }
    else if(s == "SSS")
    {
        ans = 0;
    }
    else
    {
        ans = 1;
    }

    cout << ans << endl;

    return 0;
}

//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
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;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    rep(i,8)s.pop_back();
    cout<<s<<"\n";
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
const int MAXN=100005;
int n,m;
int head[MAXN];
struct node
{
    int from;
    int to;
    int next;
}edge[MAXN<<1];
int edge_cnt;
void add_edge(int fr,int to)
{
    edge[++edge_cnt].from=fr;
    edge[edge_cnt].to=to;
    edge[edge_cnt].next=head[fr];
    head[fr]=edge_cnt;
}
int col[MAXN];
bool flag;
void dfs(int x)
{
    for(int i=head[x];i;i=edge[i].next)
    {
        int u=edge[i].to;
        if(col[u]==-1)
        {
            col[u]=col[x]^1;
            dfs(u);
        }
        else if(col[x]==col[u]) flag=1;
    }
}
bool check()
{
    for(int i=1;i<=n;i++) col[i]=-1;
    for(int i=1;i<=n;i++)
    {
        if(col[i]==-1)
        {
            col[i]=0;
            dfs(i);
        }
    }
    return !flag;
}
long long ans;
signed main()
{
    cin>>n>>m;
    for(int i=1;i<=m;i++)
    {
        int u,v;
        scanf("%lld%lld",&u,&v);
        add_edge(u,v),add_edge(v,u);
    }
    if(check())
    {
        int temp=0;
        for(int i=1;i<=n;i++)
        {
            if(col[i]) temp++;
        }
        ans=temp*(n-temp)-m;
    }
    else ans=n*(n-1)/2-m;
    cout<<ans<<endl;
    // system("pause");
    return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    long long N;
    cin >> N;
    vector<long long> s(N);
    long long ans = 0;
    for(int i = 0; i < N; i++){
        long long a, b;
        cin >> a >> b;
        ans -= b;
        s[i] = a + b;
    }
    sort(s.begin(), s.end());
    int f = 0;
    for(int i = 0; i < N; i++){
        if(f % 2 == 0) ans += s[N - 1 - i];
        f++;
    }
    cout << ans << endl;
}


#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <string>
#include <queue>
#include <iomanip>
#include <iterator>

#define MOD 1000000007
#define INF 1000000001

using namespace std;
typedef unsigned long long ull;
typedef long long ll;

template <class T>
ostream &operator<<(ostream &o, const vector<T>&obj) {
    o << "["; for (int i = 0; i < (int)obj.size(); ++i) o << (i > 0 ? ", " : "") << obj[i]; o << "]"; return o;
}
template <class T, class U>
ostream &operator<<(ostream &o, const pair<T, U>&obj) {
    o << "(" << obj.first << ", " << obj.second << ")"; return o;
}
template <class T, class U>
ostream &operator<<(ostream &o, const map<T, U>&obj) {
    o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;
}
template <class T>
ostream &operator<<(ostream &o, const set<T>&obj) {
    o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;
}
template <class T>
ostream &operator<<(ostream &o, const queue<T>&obj) {
    queue<T> obj_cp = obj;
    bool first = true;
    o << "{";
    while (!obj_cp.empty()) { o << (!first ? ", " : "") << obj_cp.front(); obj_cp.pop(); first = false; }
    o << "}"; return o;
}

void print() {
    cout << "\n";
}
template<class Head, class... Body>
void print(Head head, Body... body) {
    cout << head << " ";
    print(body...);
}

int H, W, K;
vector<int> pattern_nums;

void init_pnums() {
    pattern_nums.resize(W);
    pattern_nums[0] = 1;
    pattern_nums[1] = 2;
    for (int i = 0; i <= W-2; ++i) {
        pattern_nums[i+2] = pattern_nums[i] + pattern_nums[i+1];
    }
}

int get_pnum(int h) {
    if (h < 0) return 1;
    return pattern_nums[h];
}

int main(int argc, char const *argv[]) {
    cin >> H >> W >> K;
    init_pnums();
    // print(pattern_nums);

    vector<vector<ull>> dp(H+1, vector<ull>(W, 0));
    dp[0][0] = 1;
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            dp[i+1][j] = (dp[i][j] * get_pnum(j-1) * get_pnum(W-j-2)) % MOD;
            // print(i, j, "center", dp[i][j] * get_pnum(j-1) * get_pnum(W-j-2));
            if (j > 0) {
                dp[i+1][j] = (dp[i+1][j] + dp[i][j-1] * get_pnum(j-2) * get_pnum(W-j-2)) % MOD;
                // print(i, j, "left", dp[i][j-1] * get_pnum(j-2) * get_pnum(W-j-2));
            }
            if (j < W-1) {
                dp[i+1][j] = (dp[i+1][j] + dp[i][j+1] * get_pnum(j-1) * get_pnum(W-j-3)) % MOD;
                // print(i, j, "right", dp[i][j+1] * get_pnum(j-1) * get_pnum(W-j-3));
            }
        }
        // print(i+1, dp[i+1]);
    }

    cout << dp[H][K-1] << endl;

    return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

//dp[i][j][k],i番目の高さで,左からj列目、k：見ている箇所の左側に橋がかかっている。
lli dp[110][10];

signed main(){

	lli h,w,k;
	cin>>h>>w>>k;
	dp[0][0]=1;

	REP(i,1,h+1){
		REP(bit,0,(1LL)<<(w-1)){
			if(DEBUG)cout<<"bit="<<bit<<endl;

			//cout<<endl;
			bool ok=false;
			REP(j,0,w){
				//cout<<(bit&(1LL<<j))<<" ";
				if(bit&(1LL<<j) && bit&(1LL<<(j+1))){
					ok=true;
					break;
				}
			}
			if(ok)continue;
			REP(j,0,w+1){
				bool flag=false;
				if(bit&(1LL<<j)){
					dp[i][j+1] += dp[i-1][j];
					dp[i][j]   += dp[i-1][j+1];
					flag=true;
				}
				else{
					dp[i][j] += dp[i-1][j];
				}

				dp[i][j]%=MOD;
				dp[i][j+1]%=MOD;
				if(flag)j++;
			}
		}
	}

	if(DEBUG){
		cout<<"show"<<endl;
		REP(i,0,h+1){
			REP(j,0,w){
				cout<<dp[i][j]%MOD<<" ";
			}
			cout<<endl;
		}
	}

	cout<<dp[h][k-1]%MOD<<endl;

	return 0;

}


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

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int main() {
	int l[10],v1,v2;
	for(;~scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n",l,l+1,l+2,l+3,l+4,l+5,l+6,l+7,l+8,l+9,&v1,&v2);){
		int sum=0;
		int i;
		for(i=0;i<10;i++){
			sum+=l[i];
			//cout<<l[i]<<endl;
		}
		int len=0;
		for(i=0;i<10;i++){
			len+=l[i];
			if(len*v2>=(sum-len)*v1){
				cout<<i+1<<endl;
				break;
			}
		}
	}
	return 0;
}

#include<cstdio>
#include<vector>
#include<numeric>

using namespace std;

int main()
{
	int l[10],v[2];
	while(~scanf("%d",l)){
		for(int i=1;i<10;i++)	scanf(",%d",l+i);
		scanf(",%d,%d",v,v+1);
		int len=accumulate(l,l+10,0);
		vector<int> rail(len);
		for(int i=0,cnt=0;i<10;i++){
			for(int j=0;j<l[i];j++,cnt++){
				rail[cnt]=i+1;
			}
		}
		double x=1.0*v[0]/(v[0]+v[1])*len;
		if(-1e-9<(x-(int)x) && (x-(int)x)<1e-9)	x-=0.1;
		printf("%d\n",rail[(int)x]);
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <cassert>
#include <random>
#include <tuple>

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

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

const int MOD = 1e9 + 7;

const int MAX = 1100;
ll 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;
    }
}

ll 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 modpow(ll a, ll n, ll MOD) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
    ll n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;

    vector<ll> dp(n+1, 0);
    dp[0] = 1;

    COMinit();

    for (int i = a; i <= b; i++) {
        for (int j = n; j >= 0; j--) {
            for (int k = c; i*k <= j && k <= d; k++) {
                dp[j] += dp[j-i*k] * fac[n-(j-i*k)] % MOD * finv[n-j] % MOD * finv[k] % MOD * modpow(finv[i], k, MOD) % MOD;
                dp[j] %= MOD;
            }
        }
    }

    cout << dp[n] << endl;

    return 0;

}

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

#define ll long long
const int N = 2005;
const int mod = 1e9+7;
int fac[N],combi[N][N];

int add(int x,int y) {
   int ret = ((x+y)%mod + mod)%mod;
   return ret;
}
int mul(int x,int y) {
   ll ret = (ll)x*y;
   ret%=mod;
   return ret;
}

int num[2];
int group[2];
int dp[N][N];
int inv[N];

int invFac[N];

int solveDp(int x,int rem) {
   if(rem==0) {
      return 1;
   }
   if(x>num[1]) {
      return 0;
   }
   int &ret = dp[x][rem];
   if(ret != -1) {
      return ret;
   }
   ret = solveDp(x+1,rem);
   int cur = 1;
   for(int j = 0;j<group[0];++j) {
      cur = mul(cur, invFac[x]);
   }
   for(int f = group[0];f<=group[1] && f*x<=rem;++f) {
      int tot = f*x;
      int m = fac[tot];
      int t = cur;
      t = mul(t, invFac[f]);
      m = mul(t,m);
      m = mul(combi[rem][tot],m);
      ret = add(ret, mul(m,solveDp(x+1,rem-tot)));
      cur = mul(cur,invFac[x]);
   }
   return ret;
}

int myPow(int x,int c) {
   int ret = 1;
   while(c>0) {
      if(c&1) {
         ret = mul(ret,x);
      }
      x = mul(x,x);
      c/=2;
   }
   return ret;
}
void solve() {
   int n;
   memset(dp,-1,sizeof(dp));
   scanf("%d",&n);
   for(int i=0;i<2;++i) {
      scanf("%d",&num[i]);
   }
   for(int i=0;i<2;++i) {
      scanf("%d",&group[i]);
   }
   fac[0] = 1;
   inv[0] = 1;
   invFac[0] = 1;
   for(int i=1;i<N;++i) {
      fac[i] = mul(fac[i-1],i);
      inv[i] = myPow(i,mod-2);
      invFac[i] = myPow(fac[i],mod-2);
   }
   for(int i=0;i<N;++i) {
      combi[i][i] = combi[i][0] = 1;
      for(int j = 1;j<i;++j) {
         combi[i][j] = add(combi[i-1][j],combi[i-1][j-1]);
      }
   }
   printf("%d\n", solveDp(num[0],n));
}

int main()
{
   //freopen("input.txt","r",stdin);
   solve();
}


#include <iostream>
#include <algorithm>
#include <numeric>
const int NUM = 10000;

using namespace std;

int main() {
    int n, a[NUM];
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    cout << *min_element(a, a + n) << " "
         << *max_element(a, a + n) << " "
         << accumulate(a, a + n, 0LL) << endl;
    return 0;
}

#include<iostream>
#include<cstdio>
using namespace std;
int main(){
	long long Min,Max,sum=0,n,m;
	scanf("%lld%lld",&n,&Max);
	Min=sum=Max;
	for(int i=1;i<n;i++){
		scanf("%lld",&m);
		if(m>Max) Max=m;
		if(m<Min) Min=m;
		sum+=m;
	}
	printf("%lld %lld %lld\n",Min,Max,sum);
	return 0;
}


#include <bits/stdc++.h>
#include <fstream>
using namespace std;
typedef long long lint;
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(lint (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
const lint MOD =1000000007;
const lint MAX = 1000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
typedef map<lint,lint> M;

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

void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint 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(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;

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

    return 1;
}
   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;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    }

  int main(){
    int h,w;
    cin>>h>>w;
    int x[h][w];
    rep(i,h){
        rep(j,w){
            cin>>x[i][j];
        }
    }
    vector<tuple<lint,lint,lint,lint>>ans;
        rep(i,h){
            rep(j,w){
                if(x[i][j]%2==1){
                    if(i!=(h-1)&&j!=(w-1)){
                        if(x[i][j+1]%2==1){
                            x[i][j]--;
                            x[i][j+1]++;
                            ans.push_back(make_tuple(i,j,i,j+1));
                        }else {
                              x[i][j]--;
                            x[i+1][j]++;
                            ans.push_back(make_tuple(i,j,i+1,j));
                        }
                    }else if(i==(h-1)&&j==(w-1));
                    else if(i==(h-1)){
                          x[i][j]--;
                            x[i][j+1]++;
                            ans.push_back(make_tuple(i,j,i,j+1));
                    }else{
                        x[i][j]--;
                            x[i+1][j]++;
                            ans.push_back(make_tuple(i,j,i+1,j));
                    }
                }
            }
        }
        cout<<ans.size()<<endl;
       rep(i,ans.size()){
           lint a,b,c,d;
           tie(a,b,c,d)=ans[i];
           cout<<a+1<<" "<<b+1<<" "<<c+1<<" "<<d+1<<endl;
       }
     }

#include <bits/stdc++.h>

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

int main() {
  in(int, h, w);
  vector a(h, vector(w, 0));
  rep(i, h) rep(j, w) cin >> a[i][j];
  int r = 0, c = 0;
  vector<string> moves;
  while (true) {
    dbg(r, c);
    int nr = r, nc = c + ((r & 1) ? -1 : 1);
    if (nc < 0 || w <= nc) {
      ++nr;
      if (nr == h) break;
      nc = c;
    }
    if (a[r][c] & 1) {
      stringstream ss;
      ss << (r + 1) << " " << (c + 1) << " " << (nr + 1) << " " << (nc + 1);
      moves.push_back(ss.str());
      --a[r][c];
      ++a[nr][nc];
    }
    r = nr;
    c = nc;
  }
  out(moves.size());
  for (auto& m : moves) out(m);
}


// F.

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

using namespace std;
typedef long long LL;

const int INF = 1 << 30;

int solve(vector<int> x, vector<int> y, vector<string> dir) {
	int ans = INF;
	int n = (int)x.size();
	map<int, set<int>> a, b, v, h;
	for (int i = 0; i < n; ++i) {
		if (dir[i] == "L") {
			a[x[i] - y[i]].insert(x[i]);
			h[y[i]].insert(x[i]);
		}
		if (dir[i] == "R") {
			b[x[i] + y[i]].insert(x[i]);
		}
		if (dir[i] == "D") {
			v[x[i]].insert(y[i]);
		}
	}
	for (int i = 0; i < n; ++i) {
		if (dir[i] == "R") {
			if (h.find(y[i]) != h.end()) {
				set<int>& s = h[y[i]];
				auto it = s.lower_bound(x[i]);
				if (it != s.end()) {
					ans = min(ans, (*it - x[i]) * 5);
				}
			}
		}
		if (dir[i] != "U") {
			continue;
		}
		int key = x[i] - y[i];
		if (a.find(key) != a.end()) {
			set<int>& s = a[key];
			auto it = s.lower_bound(x[i]);
			if (it != s.end()) {
				ans = min(ans, (*it - x[i]) * 10);
			}
		}
		key = x[i] + y[i];
		if (b.find(key) != b.end()) {
			set<int>& s = b[key];
			auto it = s.lower_bound(x[i]);
			if (it != s.begin()) {
				--it;
				ans = min(ans, (x[i] - *it) * 10);
			}
		}
		if (v.find(x[i]) != v.end()) {
			set<int>& s = v[x[i]];
			auto it = s.lower_bound(y[i]);
			if (it != s.end()) {
				ans = min(ans, (*it - y[i]) * 5);
			}
		}
	}
	return ans;
}

int main(int argc, char* argv[]) {
	cout.precision(20);
#ifdef _MSC_VER
	while (true)
#endif
	{
		int ans = INF;
		LL n = -1;
		cin >> n;
		if (n < 0) return 0;
		vector<int> x(n), y(n);
		vector<string> dir(n);
		for (int i = 0; i < n; ++i) {
			cin >> x[i] >> y[i] >> dir[i];
		}
		ans = solve(x, y, dir);
		map<string, string> t;
		t["D"] = "U";
		t["U"] = "D";
		t["L"] = "R";
		t["R"] = "L";
		for (int i = 0; i < n; ++i) {
			x[i] = -x[i];
			y[i] = -y[i];
			dir[i] = t[dir[i]];
		}
		ans = min(ans, solve(x, y, dir));
		if (ans == INF) {
			cout << "SAFE" << endl;
		} else {
			cout << ans << endl;
		}
	}
	return 0;
}

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i ++)
#define irep(i,n) for (int i = (int)(n) - 1;i >= 0;--i)
#define rep2(i,a,b) for (int i = (int)(a); i < (int)(b); ++i)
using namespace std;
using ll = long long;
using PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr ll INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007;// = 998244353;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;
const int MAXD = 200010;

ll compare(vector<vector<int>> &A,vector<vector<int>> &B,int sz = MAXD * 2) {
    int ans = INF;
    rep(i,sz) {
        sort(B[i].begin(),B[i].end());
        for (int a:A[i]) {
            int idx = lower_bound(B[i].begin(),B[i].end(),a + 1) - B[i].begin();
            if (idx >= (int)B[i].size()) continue;
            ans = min(ans,B[i][idx] - a);
        }
    }
    return ans;
}

int main() {
    int N; cin >> N;
    vector<vector<int>> XU(MAXD),XD(MAXD),YR(MAXD),YL(MAXD),mR(2*MAXD),mD(2*MAXD),mU(2*MAXD),mL(2*MAXD),aR(2*MAXD),aU(2*MAXD),aD(2*MAXD),aL(2*MAXD);
    rep(i,N) {
        int x,y; char s;
        cin >> x >> y >> s;
        if (s == 'U') {
            XU[x].push_back(y);
            mU[y - x + MAXD].push_back(x);
            aU[y + x].push_back(x);
        } else if (s == 'R'){
            YR[y].push_back(x);
            mR[y - x + MAXD].push_back(x);
            aR[y + x].push_back(x);
        } else if (s == 'D') {
            XD[x].push_back(y);
            mD[y - x + MAXD].push_back(x);
            aD[y + x].push_back(x);
        } else {
            YL[y].push_back(x);
            mL[y - x + MAXD].push_back(x);
            aL[y + x].push_back(x);
        }
    }
    ll ans = INF;
    ans = min(ans,compare(XU,XD,MAXD)*5LL);
    ans = min(ans,compare(YR,YL,MAXD)*5LL);
    ans = min(ans,compare(mR,mD)*10LL);
    ans = min(ans,compare(mU,mL)*10LL);
    ans = min(ans,compare(aR,aU)*10LL);
    ans = min(ans,compare(aD,aL)*10LL);
    if (ans == INF) cout << "SAFE" << '\n';
    else cout << ans << '\n';
    return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef vector<vector<P>> vvP;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

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

    vl a(n);
    ll sum = 0;
    rep(i, n) {
        cin >> a[i];
        sum += a[i];
    }

    vector<P> p(n);
    rep(i, n) {
        p[i] = make_pair(abs(sum - n*a[i]), i);
    }
    sort(all(p));

    out(p[0].second);
    re0;
}

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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define fi first
#define se second
#define setpre(x) cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ cout << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , ";
    logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 100005;

/* ...o(^-^)o... */
int main(){
    int n; cin >> n;
    string s; cin >> s;
    int o[] = {0, 3, 1, 2};
    int x[] = {1, 2, 0, 3};
    string sr[] = {"SS", "SW", "WS", "WW"};
    rep(t, 4){
        int u = t; vector<int> v;
        rep(i, n){
            v.push_back(u);
            if(s[i] == 'o') u = o[u];
            else u = x[u];
        }
        if(u != t) continue;
        string ans = "";
        rep(i, n){
            if(v[i] % 2) ans += "W";
            else ans += "S";
        }
        out(ans); return 0;
    }
    out(-1);
}


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

int cnt[50];
int main() {
	int n, p;
	while (scanf("%d%d", &n, &p), n) {
		int k = p;
		memset(cnt, 0, sizeof(cnt));
		for (int i = 0;; i = (i + 1) % n) {
			if (k == 1 && cnt[i] == p - 1) {
				printf("%d\n", i);
				break;
			}
			if (k) { cnt[i]++; k--; }
			else { k = cnt[i]; cnt[i] = 0; }
		}
	}
}

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

using namespace std;

int main(){

	int n,m;
	while(cin>>n>>m&&!(n==0&&m==0)){
		int scores[1001];
		vector<int> comb;
		for(int i = 0; i < n; i++){
			cin>>scores[i];
		}
		scores[n]=0;
		for(int i = 0; i < n+1; i++){
			for(int j = 0; j < n+1; j++){
				int sum=scores[i]+scores[j];
				if(sum<=m)
					comb.push_back(sum);
			}
		}
		sort(comb.begin(),comb.end());
		int maxNum=0;
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				int left = (scores[i]+scores[j]);
				if(left<=m&&comb[0]+left<=m){
					vector<int>::iterator it = lower_bound(comb.begin(),comb.end(),m-left);
					if(it==comb.end()){
						maxNum=max(maxNum,comb[comb.size()-1]+left);
					}
					else{
						if(*it==(m-left)){
							maxNum=m;
						}
						else{
							it--;
							maxNum=max(maxNum,*it+left);
						}
					}
				}
			}
		}
		cout<<maxNum<<endl;
	}

	return 0;
}


#include <bits/stdc++.h>

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

//#define int long long
//signed main(){
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin >> s;
    cout << "2018";
    for(int i = 4; i < s.size(); i++) cout << s[i];
    cout << "\n";
    return 0;
}

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

int main(){
  string A;
  cin >> A;
  cout << 2018 << "/" << 0 << 1 << "/" << A.at(8) << A.at(9) << endl;
}


# define _CRT_SECUREj_NO_WARNINGS 1
# define _USE_MATH_DEFINES
# include <iostream>
# include <numeric>
# include <string>
# include <bitset>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iomanip>
# include <queue>
# include <sstream>
# include <climits>
# include <cmath>
# include <list>
# include <functional>
# include <string>
# include <ctime>
# include <set>
# include <forward_list>
# include <map>
# include <stack>
using namespace std;
# define INF ((int)(1<<25))
# define REP(i,n) for(int i=0;i<(int)n;i++)
# define FOR(i,n) REP(i,n)
# define FORI(i,k,n) for(int i=k;i<(int)n;i++)
# define TORAD 2.0*M_PI/360.0
# define INT(x) int x;cin>>x;
# define ALL(x) (x).begin(),(x).end()
# define RALL(x) (x).rbegin(),(x).rend()
# define DEBUG(x) cout<<#x<<":"<<x<<endl;
# define EPS 1e-12
#ifdef _MSC_VER
#include <intrin.h>
#define __builtin_popcount __popcnt
#endif
#define int long long
typedef long long lint;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
const int dx[4] = { 0,1,0,-1 }, dy[4] = { -1,0,1,0 };
template<class T> void debug(T a) { for (auto i : a)cout << i << endl; }

const int M = 110;
int f[M][M];
int v, e, r;

signed main()
{
	cin >> v >> e;
	FOR(i, M)FOR(j, M)f[i][j] = INT_MAX;
	FOR(i, M)f[i][i] = 0;
	FOR(i, e)
	{
		int s, t, d;
		cin >> s >> t >> d;
		f[s][t] = d;
	}

	FOR(k, M)
	{
		FOR(i, M)
		{
			FOR(j, M)
			{
				if (f[i][k] == INT_MAX || f[k][j] == INT_MAX)continue;
				f[i][j] = min(f[i][j], f[i][k] + f[k][j]);
			}
		}
	}
	FOR(i, M)if (f[i][i] < 0) { cout << "NEGATIVE CYCLE" << endl; return 0; }

	FOR(i, v)
	{
		FOR(j, v)
		{
			if (j)cout << " ";
			if (f[i][j] == INT_MAX)cout << "INF";
			else cout << f[i][j];
		}
		cout << endl;
	}
}


#include<bits/stdc++.h>
using std::cout;
using std::cin;
using std::endl;

std::vector<std::string> split(const std::string &str, char sep)
{
    std::vector<std::string> v;
    std::stringstream ss(str);
    std::string buffer;
    while( std::getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

int Stoi(const std::string &str)
{
    int num=0, i=0;
    std::string s = str;
    while (i<s.size())
    {
        if (s[i]<'0'||s[i]>'9')
            break;
        num = num * 10 + (str[i] - '0');
        i++;
    }

    return num;
}

std::string replace(const std::string &str1, int a, int b, const std::string &str2)
{
    std::string s1, s2;
    s1 = str1; s2 = str2;

    s1 = s1.erase(a, b-a+1);
    //cout << s1 << endl;
    s1 = s1.insert(a, s2);
    //cout << s1 << endl;
    return s1;
}

int main(){
    int a, b, count=1;
    long long n;
    std::string str, line, doubt, s;
    cin >> str;
    cin >> n;
    std::getline(cin, doubt);

    std::vector<std::string> Priope, v;
    std::vector<int> num(n);

    for (int i = 0; i < n; i++)
    {
        std::getline(cin, line);
        v = split(line, ' ');

        a = Stoi(v[1]); b = Stoi(v[2]);

        if (v[0] == "print")
        {
            s = str.substr(a, b-a+1);
            Priope.push_back(s);
            num.push_back(i);
            //cout << s << endl;
        }
        else if (v[0] == "reverse")
            {std::reverse(str.begin()+a, str.begin()+b+1); }//cout << str << endl;}
        else if(v[0] == "replace")
            str = replace(str, a, b, v[3]);
        else
        {
            cout << "Wrong Command:" << v[0] << endl;
            i--;
        }

    }
/*
    for (int i = 0; i < num.size(); i++)
        cout << Priope(i) << endl;
*/
    std::vector<std::string>::iterator itr;
    itr = Priope.begin();
    while (itr != Priope.end())
    {
        cout << *itr << endl;
        itr++;
    }

    return 0;
}

#include<iostream>
#include<cstdio>
#define eps 10e-9
using namespace std;
int main()
{
    int data[10],sum=0;
    int v1,v2;
    while(scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",&data[0],&data[1],&data[2],&data[3],&data[4],&data[5],&data[6],&data[7],&data[8],&data[9],&v1,&v2)!=EOF)
    {
        sum=data[0];
        for(int i = 1; i < 10; ++i)
        {
            sum+=data[i];
            data[i]=sum;
        }
        //cout<<"sum="<<data[9]<<endl;
        double t=data[9]/(double)(v1+v2);
        //printf("t=%.9lf\n",t);
        for(int i = 0; i < 10; ++i)
        {
            if(v1*t<(double)data[i]+eps)
            {
                cout<<i+1<<endl;
                break;
            }
        }
    }
  return 0;
}


#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N=6100;
int n,mod,fac[N],inv[N],tot[4][N],invtot[4][N];
int p[N];
inline void add(int &a,int b){a=(a+b)%mod;}
inline void del(int &a,int b){a=(a-b+mod)%mod;}
inline void mul(int &a,int b){a=(a*b)%mod;}
inline int C(int n,int m){return fac[n]*inv[n-m]%mod*inv[m]%mod;}
inline int m_pow(int a,int b)
{
	int ans=1;
	while (b)
	{
		if (b&1) mul(ans,a);
		b>>=1;
		mul(a,a);
	}
	return ans;
}
signed main()
{
	scanf("%lld%lld",&n,&mod);n*=3;
	fac[0]=1;
	for (int i=1;i<=n;i++) fac[i]=(fac[i-1]*i)%mod;
	inv[n]=m_pow(fac[n],mod-2);
	for (int i=n-1;i>=0;i--) inv[i]=(inv[i+1]*(i+1))%mod;
	p[0]=1;
	for (int i=1;i<=n;i++) p[i]=(p[i-1]*2)%mod;
	for (int i=1;i<=3;i++)
	{
		for (int j=0;j<i;j++) tot[i][j]=1;
		for (int j=i;j<=n;j++) tot[i][j]=(tot[i][j-i]*C(j,i))%mod;
		for (int j=0;j<=n;j++) invtot[i][j]=m_pow(tot[i][j],mod-2);
	}
	int ans=0;
	for (int i=0;i<=n;i++)
	{
		for (int j=0;j<=i;j++)
		{
			int k=n-i-2*j,num=1,tmp=n;
			if (k<0) break;
			if (k%3!=0) continue;
			k/=3;
			mul(num,tot[1][tmp]*invtot[1][tmp-i]%mod);tmp-=i;
			mul(num,tot[2][tmp]*invtot[2][tmp-2*j]%mod);tmp-=2*j;
			mul(num,tot[3][tmp]);
			mul(num,inv[i]);mul(num,inv[j]);mul(num,inv[k]);
			mul(num,p[k]);
//			printf("1:%d 2:%d: %d\n",i,j,num);
			add(ans,num);
		}
	}
	printf("%lld\n",ans);
}

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

typedef long long Int;
typedef pair<Int,Int> PII;
typedef vector<int> VInt;

#define FOR(i, a, b) for(i = (a); i < (b); ++i)
#define RFOR(i, a, b) for(i = (a) - 1; i >= (b); --i)
#define EACH(it, a) for(auto it = (a).begin(); it != (a).end(); ++it)
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define SIZE(a) int((a).size())
#define ALL(a) (a).begin(),(a).end()
#define MP make_pair

#define MAX (6 << 10)

Int R[MAX][MAX + MAX];

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

	CLEAR(R, 0);
	R[0][MAX] = 1;
	int i, j;
	FOR(i, 0, 3*n)
	FOR(j, 0, MAX + MAX)
	if(R[i][j] != 0)
	{
		R[i + 1][j + 1] = (R[i + 1][j + 1] + R[i][j]) % m;
		if(i + 2 <= 3*n) R[i + 2][j - 1] = (R[i + 2][j - 1] + R[i][j]*(i + 1)) % m;
		if(i + 3 <= 3*n) R[i + 3][j] = (R[i + 3][j] + R[i][j]*(i + 1)*(i + 2)) % m;
	}

	Int res = 0;
	FOR(i, MAX, MAX + MAX) res += R[3*n][i];
	res %= m;
	cout << res << endl;
	return 0;
}


#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<string>

using namespace std;

set<string>mo;
int N,k;
bool use[15];
map<string,int>memo;
string n[10];
void g(int m,string a){
    if(m==k){
        memo[a]=1;
    return;
    }
        for(int i=0;i<N;i++){
        if(!use[i]){
                string _a=a+n[i];
            use[i]=1;
            g(m+1,_a);
            use[i]=0;
        }
    }
}
//??¨??????????????????(????????????)
int main(){
while(1){
        int ans=0;
        cin >> N >> k;
    if(N==0&&k==0)break;
    for(int y=0;y<N;y++){
        cin >> n[y];
    }
    fill(use,use+15,0);
    memo.clear();
    g(0,"");
    cout << memo.size() << endl;
}

return 0;
}

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

int n,k,card[10],count;
int check[10001];

// used[i]==1ÈçÎ iÍgÁÄ¢é
// used[i]==1ÈçÎ card[i]ÍgÁÄ¢é

void func(int a[],int now)
{
	int i,j,temp,keta=0,flg;

	if(now == k){
		char str[9];
		for(i=0;i<k;i++){
			temp=sprintf(str+keta,"%d",a[i]);
			keta+=temp;
		}
		temp=atoi(str);
		check[count]=temp;
		count++;
	}

	else {
		int used[10] = { 0 };

		for(i=0; i<now; i++){
			for(j=0;j<n;j++){
				if(a[i]==card[j] && used[j]==0){
					used[j]=1;
					break;
				}
			}
		}

		for(i=0;i<n;i++){
			if(used[i] == 0){
				a[now] = card[i];
				func(a,now+1);
			}
		}
	}
}

int main(void)
{
	int i,j,array[5];
	while(scanf("%d",&n),n){
		scanf("%d",&k);
		for(i=0;i<n;i++){
			scanf("%d", &card[i]);
		}

		func(array,0);
		for(i=0;i<count;i++){
			for(j=0;j<count;j++){
				if(check[i]==check[j] && i!=j && check[i]!=0){
					check[j]=0;
				}
			}
		}

		count=0;
		for(i=0;i<10000;i++){
			if(check[i]!=0){
				count++;
			}
		}
		printf("%d\n",count);

		for(i=0;i<10001;i++){
			check[i]=0;
		}
		count=0;
		for(i=0;i<10;i++){
			card[i]=0;
		}

	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

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

    vector<string> vec = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};

    int cnt = 0;
    for (string x:vec) {
        if (S == x) {
            cout << 7 - cnt << endl;
        } else {
            cnt++;
        }
    }
}

#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

ll a[60];

int main() {
	ll k;
	cin>>k;
	ll p = k/50, r = k-50*p;
	int n = 50;
	REP(i,1,n) a[i] = p+49;
	REP(i,1,r) a[i]+=n-r+1;
	REP(i,r+1,n) a[i]-=r;
	printf("%d\n",n);
	REP(i,1,n) printf("%lld ",a[i]);hr;
}


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

int main() {
  int n,ans;
  cin >> n;
  if (n <= 111) ans = 111;
  else if (n <= 222) ans = 222;
  else if (n <= 333) ans = 333;
  else if (n <= 444) ans = 444;
  else if (n <= 555) ans = 555;
  else if (n <= 666) ans = 666;
  else if (n <= 777) ans = 777;
  else if (n <= 888) ans = 888;
  else ans = 999;

  cout << ans << endl;

  return 0;
}

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

class dice {
public:
	dice(int* a) {
		set(a[0], a[1], a[2], a[3], a[4], a[5]);
	}
	dice(int& a, int& b, int& c, int& d, int &e, int& f) {
		set(a, b, c, d, e, f);
	}
	void turn(int n) {
		if (n < 4)
		{
			turndice(n);
			return;
		}
		switch (n)
		{
		case 'N':
			turndice(0);
			break;
		case 'E':
			turndice(1);
			break;
		case 'S':
			turndice(2);
			break;
		case 'W':
			turndice(3);
			break;
		}

	}

	void turn(const char* str)
	{
		for (size_t i = 0; str[i] != '\0' ; i++)
		{
			turn(str[i]);
		}
	}

	int getcurrent(int n = 0) { return label[n]; }

public:
	int topfronttoright(const int & top, const int & front) {
		char n3[] = { "NES" };
		const char ne[][3] = { "N","N","N","E","EE" };

		for (size_t i = 0; i < 6; i++)
		{
			if (top == getcurrent())
				for (size_t j = 0; j < 4; j++)
				{
					if (front == getcurrent(1))
					{
						return  getcurrent(2);
					}
					turn(n3);
				}
			turn(ne[i]);
		}

		return 0;
	}

	bool cmper(dice b) {
		char n3[] = { "NES" };
		const char ne[][3] = { "N","N","N","E","EE" };

		for (size_t i = 0; i < 6; i++)
		{
			if (b.getcurrent() == getcurrent())
				for (size_t j = 0; j < 4; j++)
				{
					if (b.getcurrent(1) == getcurrent(1) &&
						b.getcurrent(2) == getcurrent(2) &&
						b.getcurrent(3) == getcurrent(3) &&
						b.getcurrent(4) == getcurrent(4) &&
						b.getcurrent(5) == getcurrent(5) )
					{
						return  true;
					}
					turn(n3);
				}
			turn(ne[i]);
		}

		return false;
	}

private:
	int label[6];

	void set(int& a, int& b, int& c, int& d, int &e, int& f) {
		label[0] = a;
		label[1] = b;
		label[2] = c;
		label[3] = d;
		label[4] = e;
		label[5] = f;
	}
	void turndice(int n)
	{
		int m = (n > 1) ? n - 2 : n + 2;
		int f[] = { 1, 3, 4, 2 };
		int tmp;

		tmp = label[0];
		label[0] = label[f[n]];
		label[f[n]] = label[5];
		label[5] = label[f[m]];
		label[f[m]] = tmp;
	}

};

#define D

#ifdef D
int main(void)
{
	int n;
	cin >> n;
	vector<dice> arr;
	arr.reserve(n);
	int label[6];
	for (size_t i = 0; i < n; i++)
	{
		for (auto &a : label)
			cin >> a;
		dice d(label);
		arr.push_back(d);
	}

	bool flag = true;
	for (size_t i = 0; i < n -1 && flag; i++)
	{
		for (size_t j = i+1; j < n; j++)
		{
			if (arr[i].cmper(arr[j]))
				flag = false;
		}
	}
	if (!flag)
		cout << "No" << endl;
	else
		cout << "Yes" << endl;
	return 0;
}
#endif // D


#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\b.answer"
int main() {
	string st; cin >> st;
	int ans = 0;
	for (int l = 0; l < st.size(); ++l) {
		if (st[l] == 'O') {
			int r = l;
			while (r!=st.size()&&st[r] == 'O') {
				r++;
			}
			int len = r - l;
			if (l - len >= 0 && r + len <= st.size()) {
				bool ok = true;
				for (int t = 0; t < len; ++t) {
					if (st[l - t - 1] != 'J')ok = false;
					if (st[r + t] != 'I')ok = false;
				}
				if (ok)ans = max(ans, len);
			}
			l += len - 1;
		}
	}
	cout << ans << endl;
	return 0;
}

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

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 long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007

//ここから編集する
class Solve {
public:

    Int modmul(Int a, Int b) {
        return a * b % MOD;
    }

    void solve() {
        Int N;
        string S;

        cin >> N >> S;
        N *= 2;

        vector<int> LR(N);
        if (S[0] == 'W' || S.back() == 'W') {
            cout << 0 << endl;
            return;
        }

        LR[0] = 0;
        for (int i = 1; i < N; ++i) {
            if (S[i - 1] == S[i]) {
                LR[i] = 1 - LR[i - 1];
            } else {
                LR[i] = LR[i - 1];
            }
        }

        Int ans = 1;
        Int tapi = 0;
        for (int i = 0; i < N; ++i) {
            if (LR[i] == 0) {
                tapi++;
            } else {
                ans = modmul(ans, tapi);
                tapi--;
            }
        }

        if (tapi != 0) {
            cout << 0 << endl;
            return;
        }

        for (int i = 0; i < N / 2; ++i) {
            ans = modmul(ans, i + 1);
        }

        cout << ans << endl;

    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();

    return 0;
}


#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<map>
#define PRE std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;
const int Max = 1e6 + 5;
const int Mod = 1e9 + 7;
ll ls1[Max], ls2[Max],ls3[Max],sum[Max];

int main()
{
	PRE;
	int n;
	cin >> n;
	for (int i = 1;i <= n;i++)cin >> ls1[i];
	for (int i = 1;i <= n;i++)cin >> ls2[i];
	for (int i = 1;i <= n;i++)cin >> ls3[i];
	sort(ls1 + 1, ls1 + 1 + n);
	sort(ls2 + 1, ls2 + 1 + n);
	for (int i = 1;i <= n;i++)
	{
		int g = lower_bound(ls1 + 1, ls1 + 1 + n, ls2[i]) - ls1-1;
		sum[i] = sum[i - 1] + lower_bound(ls1 + 1, ls1 + 1 + n, ls2[i]) - ls1-1;
	}
	ll res = 0;
	for (int i = 1;i <= n;i++)
	{
		res += sum[lower_bound(ls2 + 1, ls2 + n + 1, ls3[i]) - ls2-1];
	}
	cout << res;
}

#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    ll n;
    cin >> n;
    vector<ll> A(n);
    rep(i, n) cin >> A[i];
    vector<ll> B(n);
    rep(i, n) cin >> B[i];
    vector<ll> C(n);
    rep(i, n) cin >> C[i];

    sort(all(A));
    sort(all(B));
    sort(all(C));

    vector<int> Ia(n);
    vector<int> Ic(n);

    ll sum = 0;
    rep(i, B.size()) {
        ll b = B[i];
        // b以上Aのインデックスの最後
        Ia[i] = lower_bound(all(A), b) - A.begin();
        // bより大きいBのインデックスの最初
        Ic[i] = upper_bound(all(C), b) - C.begin();

        sum += Ia[i] * (n - Ic[i]);
    }

    put(sum);
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll mod = 1e9+7;
int main()
{
    int n;
    cin>>n;
    vector<ll> a(n);
    ll s1 = 0, s2 = 0;
    for (int i=0; i<n; i++) {
        cin>>a[i];
        s1 += a[i];
        s2 += (a[i] * a[i]);
        s1 %= mod;
        s2 %= mod;
    }
    ll res = (s1 * s1 - s2);
    res %= mod;
    while (res < 0) res += mod;
    ll ans;
    if (res % 2) ans = (res + mod) / 2;
    else ans = res / 2;

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

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

using namespace std;

#define INF 10000001

int main()
{
	int a, n;
	int maxi, mini;
	int i;
	long long sum = 0ll;

	mini = INF;
	maxi = -10000001;

	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &a);
		maxi = max(a, maxi);
		mini = min(a, mini);
		sum += a;
	}

	printf("%d %d ", mini, maxi);
	cout << sum << endl;

	return (0);
}


#include<bits/stdc++.h>
#define L long long
#define pb push_back
#define pi pair<int,int>
#define pii pair<pair<int,int>,int>
#define aa first
#define bb second
#define xx aa.aa
#define yy aa.bb
#define zz bb
#define mp make_pair
#define mpp(a,b,c) mp(mp(a,b),c)
using namespace std;
int n;
L p,q;
inline void dfs(L x,L n,L m)
{
	//cout<<x<<" "<<n<<" "<<m<<"\n";
	if(x==0)
	  {
	   if(!n)
	     p+=m;
	   return;
	  }
	if(x==1)
	  {
	   if(!n)
	     p+=m*10;
	   return;
	  }
	int k=(10-n%10)%10;
	dfs(x/100,abs(n-k*x+k)/10,m*(10-abs(k)-(x==q)));
}
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	scanf("%d",&n);
	for(L k=1;k<=100000000000000000ll;k*=10)
	  q=k,dfs(k,n,1);
	printf("%lld\n",p);
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,l;
  cin>>n;
  if(n%3 == 0){
    cout<<n/3<<'\n';
  }
  else{
    cout<<n/3<<'\n';
  }
}


#include<bits/stdc++.h>
using namespace std;
signed main(void){
	string s;
	while(getline(cin,s)){
		while(s.find("this")==s.npos&&s.find("that")==s.npos&&s.find("the")==s.npos)
			for(int i=0;i<(int)s.length();i++){
				if(s[i]>'z'||s[i]<'a')continue;
				if(s[i]!='z')s[i]++;
				else s[i]='a';
			}
		cout<<s<<endl;
	}
}

#include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define NCLR(a) memset((a), -1 ,sizeof(a))
#define dump(x) cout << #x << " = " << (x) << "\n";
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
typedef complex<double> P;
static const double EPS = 1e-10;
static const double PI = acos( -1.0 );
static const int mod = 1000000007;
static const int INF = 1 << 30;
static const LL LL_INF = 1152921504606846976;
static const int dx[] = { -1, 0, 1, 0, 1, -1, 1, -1 };
static const int dy[] = { 0, -1, 0, 1, 1, 1, -1, -1 };

string str;
map<char, char> change;

int main() {
	for ( int i = 0; i < 26; i++ ) {
		change[ i + 'a' ] = ( i + 25 ) % 26 + 'a';
	}
	while ( getline( cin, str ) ) {
		for ( ;; ) {
			for ( int j = 0; j < str.size(); j++ ) {
				if ( str[ j ] >= 'a' && str[ j ] <= 'z' ) {
					str[ j ] = change[ str[ j ] ];
				}
			}
			bool is_can = false;
			for ( int j = 2; j < str.size(); j++ ) {
				if ( str.substr( j - 2, 3 ) == "the" ) {
					is_can = true;
					break;
				}
			}
			for ( int j = 3; j < str.size(); j++ ) {
				if ( str.substr( j - 3, 4 ) == "that" || str.substr( j - 3, 4 ) == "this" ) {
					is_can = true;
					break;
				}
			}
			if ( is_can ) {
				break;
			}

		}
		printf( "%s\n", str.c_str() );
	}
	return 0;
}


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

void solve()
{
    int d, g;
    cin >> d >> g;
    vector<int> p(d), c(d);
    rep(i, d) cin >> p[i] >> c[i];
    reverse(p.begin(), p.end());
    reverse(c.begin(), c.end());
    int ans = 1e9;
    rep(bit, 1 << d)
    {
        int score = 0, cnt = 0;
        rep(i, d)
        {
            if (bit & (1 << i))
            {
                bool ok = true;
                rep(j, p[i])
                {
                    score += (d - i) * 100;
                    cnt++;
                    if (score >= g)
                    {
                        ok = false;
                        ans = min(ans, cnt);
                        break;
                    }
                }
                if (ok)
                {
                    score += c[i];
                    if (score >= g)
                    {
                        ans = min(ans, cnt);
                    }
                }
            }
        }
    }
    cout << ans << endl;
}

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

#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<cstdint>
#include<bits/stdc++.h>
#include<queue>
#include<set>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep_r(i, n) for(int i = n-1; i >= 0; i--)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((ll)(x).size())
#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define INF bit(60)
#define pb push_back
#define mod 1000000007

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 namespace std;
using uif=uint_fast64_t;
using ll=long long int;

int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mod;a=1ll*a*a%mod;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

ll uf[100000];

struct edge{int u,v,cost;};

bool comp(const edge& e1,const edge& e2){
  return e1.cost < e2.cost;
}

ll root(ll i){
  if( uf[i] == i ) return i;
  else{
    ll t=root(uf[i]);
    uf[i] = t;
    return uf[i];
  }
}

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

void unite(ll x,ll y){
  ll x_r=root(x);
  ll y_r=root(y);
  if(x_r == y_r) return;
  uf[x_r] = uf[y_r];
}

int main(void){

  ll n;
  cin>>n;
  vector<ll> x(n);
  vector<ll> y(n);
  vector< pair<ll,ll> > p_x(n);
  vector< pair<ll,ll> > p_y(n);
  vector<ll> mincost(n);
  vector<bool> used(n);
  vector<edge> es(0);

  rep(i,n){
    cin>>x[i];
    cin>>y[i];
    pair<ll,ll> p;
    p.first=x[i];
    p.second=i;
    p_x[i]=p;
    p.first=y[i];
    p_y[i]=p;
    mincost[i] = INF;
    used[i] = false;
    uf[i]=i; // UnionFind init
  }
  mincost[0]=0;
  ll ans=0;
  sort(all(p_x));
  sort(all(p_y));
  /*
  rep(i,n){
    cout << p_x[i].first << "," << p_x[i].second << endl;
  }
  cout << endl;
  rep(i,n){
    cout << p_y[i].first << "," << p_y[i].second << endl;
  }
  */
  rep(i,n){
    if(i==0) continue;
    edge e;
    e.u=p_x[i-1].second;
    e.v=p_x[i].second;
    e.cost=min(abs(x[e.u]-x[e.v]),abs(y[e.u]-y[e.v]));
    es.pb(e);
    e.u=p_y[i-1].second;
    e.v=p_y[i].second;
    e.cost=min(abs(x[e.u]-x[e.v]),abs(y[e.u]-y[e.v]));
    es.pb(e);
  }
  sort(all(es),comp);
  for(auto e:es){
    //cout << e.u << "," << e.v << "," << e.cost << endl;
    if(!same(e.u,e.v)){
      unite(e.u,e.v);
      //cout << "unite!"<< endl;
      ans+=e.cost;
    }
  }
  /*
  while(true){
    ll v=-1;
    rep(u,n){
      if(!used[u] && (v==-1 || mincost[u] < mincost[v])){
        v=u;
        //cout << "v update into " << v << endl;
      }
    }
    if(v == -1){
      //cout << "break!" << endl;
      break;
    }
    used[v]=true;
    //cout << v << ":" << mincost[v] << endl;
    ans+=mincost[v];

    rep(u,n){
      if(u==v) continue;
      mincost[u] = min(mincost[u], min(abs(x[u]-x[v]),abs(y[u]-y[v])) );
    }

  }
  */

  cout << ans << endl;

  return 0;
}


// review
#include <iostream>

using namespace std;

int n, m;

void solve() {
  int second = m & 1 ? m + 1 : m + 2;
  int cnt = 1;
  int cnt2 = 0;
  for (int i=0;i<m;i++) {
    if (i < m / 2) {
      cout << cnt << " " << (second - cnt) << endl;
      cnt++;
    } else {
      cout << cnt2 + second << " " << (2 * m + 1 - cnt2) << endl;
      cnt2++;
    }
  }
}

int main() {
  cin >> n >> m;
  solve();
}

// skip until line 65
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <istream>
#include <iterator>
#include <sstream>
#include <list>
#include <map>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iomanip>
using namespace std;

#define BR "\n"
#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define ALL(cont) begin(cont),end(cont)
#define AS_MOD(a, b) ((((a) % (b) ) + (b)) % (b))
#define FEACH(it, cont) for(auto (it) = begin(cont); it!=end(cont);++it)
#define FEACHR(it, cont) for(auto (it) = rbegin(cont); it!=rend(cont);++it)
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define getll() ([](){ll s;scanf("%lld", &s);return s;})()
#define getld() ([](){ld s;scanf("%Lf", &s);return s;})()
#define prl(P) printf("%lld", P)
#define prd(P) printf("%.10Lf", P)
#define pr(P) printf(P)
#define MAX(V, T) V=max(V,T)
#define MIN(V, T) V=min(V,T)

#define DumpArray(cont, from, to) for(int __i=from;__i<to;++__i) {cout<<"(" <<__i<<": " << cont[__i]<<")";} cout<<endl;

/*
 * ***_bound(6)
 * 5 6 6 6 6 6 7 7 7
 *   ^lower    ^upper
 * void reverse(c.begin(), c.end())
 *
 * graph
 * seg tree
 * dp
 * brute force
 */
struct Comparator{
    int operator()(int l, int r) const {
        return r<l;
    }
};
struct Vec{
    double v[2];
    string to_s(){
        return "("+to_string(v[0])+","+to_string(v[1])+")";
    }
    double& operator[](int t){
        return v[t];
    }
    Vec operator+(Vec t) {
        return {v[0]+t[0],v[1]+t[1]};
    }
    Vec& operator+=(Vec t) {
        v[0]+=t[0];v[1]+=t[1];
        return *this;
    }
    Vec operator-(Vec t) {
        return {v[0]-t[0],v[1]-t[1]};
    }
    Vec& operator-=(Vec t) {
        v[0]-=t[0];v[1]-=t[1];
        return *this;
    }
    Vec operator*(double t) {
        return {v[0]*t,v[1]*t};
    }
    Vec& operator*=(double t) {
        v[0]*=t;v[1]*=t;
        return *this;
    }
    double operator*(Vec t) {
        return v[0]*t[0]+v[1]*t[1];
    }
    Vec operator-(){
        return {-v[0],-v[1]};
    }
    static Vec Z;
};
Vec Vec::Z={0,0};
//set<int, Comparator> S;

// solution below
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;

int main() {
    ll N,M;
    cin>>N>>M;
    vector<int> arr;
    arr.pb(1);
    REP(i,M-1){
        int n=arr.back()+2;
        if (N%2==0&&(n==N/2||N/2+1==n))++n;
        arr.pb(n);
    }
    REP(i,M) {
        cout << N/2 -i << " " << N/2-i + arr[i]<<endl;
    }
}


#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=1e18;
const ll mod=1e9+7;

int main(){
    ll h,w;
    cin >> h >> w;
    ll dx[4]={-1,1,0,0};
    ll dy[4]={0,0,-1,1};
    vector<vector<char>> s(h,vector<char>(w));
    rep(i,h){
        rep(j,w){
            cin >> s[i][j];
        }
    }
    vector<vector<ll>> used(h,vector<ll>(w));
    ll ans=0;
    rep(i,h){
        rep(j,w){
            if(used[i][j]) continue;
            queue<pll> que;
            que.push({i,j});
            ll white=0,black=0;
            used[i][j]=1;
            while(!que.empty()){
                pll x=que.front();
                que.pop();
                if(s[x.fi][x.se]=='#') black++;
                else white++;
                rep(k,4){
                    ll nx=x.fi+dx[k];
                    ll ny=x.se+dy[k];
                    if(0<=nx && nx<=h-1 && 0<=ny && ny<=w-1 && s[x.fi][x.se]!=s[nx][ny] && used[nx][ny]==0){
                        que.push({nx,ny});
                        used[nx][ny]=1;
                    }
                }
            }
            ans+=white*black;
        }
    }
    cout << ans << endl;
    return 0;
}