#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using namespace std;
using P = complex<double>;
using lli = long long int;
using T = lli;
bool cmp_x(const P& p, const P& q)
{
    if (p.real() != q.real())
        return p.real() < q.real();
    return p.imag() < q.imag();
}
T dot(P a, P b)
{
    //内積
    return (conj(a) * b).real();
}
T cross(P a, P b)
{
    //det
    return (conj(a) * b).imag();
}
vector<P> convex_hull(P* ps, int n)
{
    sort(ps, ps + n, cmp_x);
    int k = 0;
    vector<P> qs(n * 2);
    rep(i, n)
    {
        while (k > 1 && cross((qs[k - 1] - qs[k - 2]), (ps[i] - qs[k - 1])) <= 0)
            k--;
        qs[k++] = ps[i];
    }
    for (int i = n - 2, t = k; i >= 0; i--) {
        while (k > t && cross((qs[k - 1] - qs[k - 2]), (ps[i] - qs[k - 1])) <= 0)
            k--;
        qs[k++] = ps[i];
    }
    qs.resize(k - 1);
    return qs;
}
P x[100005];
int main()
{
    int n;
    cin >> n;
    T a, b;

    map<lli,map<lli,int>> idx;
    map<lli,map<lli,int>> prev;

    vector<P> Y;
    rep(i, n)
    {
        cin >> a >> b;
        x[i] = P(a, b);
        Y.push_back(x[i]);
        prev[a][b] = i;
    }

    vector<P> con = convex_hull(x, n);
    if(n==2){
        cout << 0.5 << "\n" << 0.5 << endl;
        return 0;
    }
    int cnt = 0;
    for(auto s:con)
    {
        idx[s.imag()][s.real()] = cnt++;
    }
    int k = con.size();
    vector<double> ans ;
    rep(i,n){
        if(idx[Y[i].imag()].find(Y[i].real())==idx[Y[i].imag()].end()){
            ans.push_back(0.0);
            continue;
        }
        int id = idx[Y[i].imag()][Y[i].real()];
        P l = con[(id-1+k)%k];
        P c = Y[i];
        P r = con[(id+1+k)%k];
        using Pd = complex<double>;
        Pd l_c = (l+c);l_c/=2.0;
        Pd r_c = (r+c);r_c/=2.0;
        double rad =    M_PI - abs(arg((r_c - c) / (l_c - c)));
        ans.push_back(rad);
    }
    double total = 0.0;
    rep(i,n)total += ans[i];
    rep(i,n){
        printf("%.10f\n",ans[i]/total);
    }
}

#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#include<map>
#include<set>
using namespace std;
int g[100005];
int F(int x)
{
	return g[x]==x?g[x]:g[x]=F(g[x]);
}
void U(int x,int y)
{
	g[F(x)]=F(y);
}
int n;
pair <pair<int,int>,int> a[100005];
vector <pair<int,pair<int,int> > > v;
long long ans=0;
int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d%d",&a[i].first.first,&a[i].first.second);
		a[i].second=i;
		g[i]=i;
	}
	sort(a,a+n);
	for(int i=0;i<n-1;i++)
	    v.push_back(make_pair(a[i+1].first.first-a[i].first.first,
		make_pair(a[i].second,a[i+1].second)));
	for(int i=0;i<n;i++)
	    swap(a[i].first.first,a[i].first.second);
	sort(a,a+n);
	for(int i=0;i<n-1;i++)
	    v.push_back(make_pair(a[i+1].first.first-a[i].first.first,
		make_pair(a[i].second,a[i+1].second)));
	sort(v.begin(),v.end());
	for(int i=0;i<v.size();i++)
	{
		int k22=v[i].second.second;
		int k21=v[i].second.first;
		//cout<<v[i].first<<' '<<k21<<' '<<k22<<endl;
		int aaa=F(k21),bbb=F(k22);
		//cout<<k21<<':'<<aaa<<' '<<k22<<':'<<bbb<<endl;
		if(aaa==bbb)
		    ;
		else
	    {
	    	//cout<<aaa<<' '<<bbb<<endl;
	    	U(k21,k22);
	    	ans+=v[i].first;
	    	//cout<<v[i].first<<endl;
		}
	}
	cout<<ans;
	return 0;
}


#include<cstdio>
#define C(x,y) (fct[x]*ifct[y]%TT*ifct[(x)-(y)]%TT)
using namespace std;
const int maxn=2005,TT=1e9+7;
int n,K,m,F[maxn][maxn];
long long fct[maxn*maxn],ifct[maxn*maxn];
inline int read(){
	int ret=0;bool f=0;char ch=getchar();
	while(ch>'9'||ch<'0') f^=ch=='-',ch=getchar();
	while(ch<='9'&&ch>='0') ret=ret*10+ch-'0',ch=getchar();
	return f?-ret:ret;
}
inline long long pow(int x,int y){
	long long ret=1,w=x;
	while(1){
		if(y&1) ret=ret*w%TT;
		if(!(y>>=1)) return ret;
		w=w*w%TT;
	}
}
inline void add(int&x,int y){if((x+=y)>=TT) x-=TT;}
int main(){
	n=read(),K=read();m=n*K;
	if(K==1) return puts("1")&0;
	for (int i=fct[0]=1;i<=m;i++) fct[i]=fct[i-1]*i%TT;
	ifct[m]=pow(fct[m],TT-2);
	for (int i=m;i;i--) ifct[i-1]=ifct[i]*i%TT;
	F[0][0]=1;
	for (int i=1;i<=n;i++)
	for (int j=0;j<=i;j++){
		if(j<i) add(F[i][j],F[i-1][j]);
		if(j) add(F[i][j],C(m-i-(j-1)*(K-1)-1,K-2)*F[i][j-1]%TT);
	}
	printf("%lld\n",fct[n]*F[n][n]%TT);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MOD=1000000007;
int n,k;
LL fac[4000000],inv_fac[4000000],dp[2001];
void check_mod(LL &a) { if (a>=MOD) a%=MOD; }
int ksm(LL a, int b)
{
	LL ret=1ll;
	while (b) {
		if (b&1) ret*=a;
		check_mod(ret);
		a*=a;
		check_mod(a);
		b>>=1;
	}
	return ret;
}
int main()
{
	LL lt;
	int t;
	scanf("%d%d",&n,&k);
	if (k==1) {
		printf("1\n");
		return 0;
	}
	fac[0]=1;
	t=n*k;
	for (int i = 1; i < t; ++i) {
		fac[i]=1ll*i*fac[i - 1];
		check_mod(fac[i]);
	}
	inv_fac[t-1]=ksm(fac[t-1],MOD-2);
	for (int i=t-2;i;--i) {
		inv_fac[i]=1ll*(i+1)*inv_fac[i+1];
		check_mod(inv_fac[i]);
	}
	inv_fac[0]=1;
	dp[0]=1;
	t=-2;
	for (int i=1;i<=n;++i) {
		t+=k-1;
		for (int j=0;j<=i;++j) {
			++t;
			lt=fac[t]*inv_fac[t-k+2];
			check_mod(lt);
			lt*=inv_fac[k-2];
			check_mod(lt);
			dp[j]*=lt;
			if (j) dp[j]+=dp[j - 1];
			check_mod(dp[j]);
		}
		t-=i+1;
	}
	printf("%lld\n",dp[n]*fac[n]%MOD);
	return 0;
}


#include <stdio.h>
int a[1000000];
long long int ans=0;
void mergesort(int l,int r){
	if(l==r)return;
	if(l==r-1){
		if(a[r]<a[l]){
			int temp;
			temp=a[l];
			a[l]=a[r];
			a[r]=temp;
			ans++;
		}
		return;
	}
	int mid=(l+r)/2,now=0,b[r-l+1];
	mergesort(l,mid-1);
	mergesort(mid,r);
	for(int i=0;i<=r-l;i++){
	if(a[l+i-now]<a[mid+now]){
		b[i]=a[i+l-now];
		if(i+l-now==mid-1){
			for(i++;i<=r-l;i++)b[i]=a[i+l];
		}
	}
	else{
		ans+=mid-i+now-l;
		b[i]=a[mid+now];
		now++;
		if(mid+now>r){
			for(i++;i<=r-l;i++){
				b[i]=a[i+l-now];
			}
		}
	}
	}
	for(int i=0;i<=r-l;i++)a[i+l]=b[i];
}
int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%d",&a[i]);
	mergesort(0,n-1);
	printf("%lld\n",ans);
}

/* * * * * * * * * * * **
*                      *
*	   saurabh8522	   *
*	  I will handle	   *
*		   IT.		   *
*                      *
* * * * * * * * * * * **/
#include<bits/stdc++.h>
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define ld long double
#define zero(a) memset((a),0,sizeof((a)))
#define one(a) memset((a),1,sizeof((a)))
#define minus(a) memset((a),-1,sizeof((a)))
#define all(g) g.begin(),g.end()
#define ppb pop_back
using namespace std;
typedef long long int ll;
#define MOD 1000000007
ll extgcd(ll a,ll b,ll& x,ll& y){if(b==0){x=1;y=0;return a;}else{int g=extgcd(b,a%b,y,x);y-=a/b*x;return g;}}
ll modpow(ll a,ll b) {ll res=1;a%=MOD;for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}
ll numdigit(ll n){return floor(log10(n)) + 1;}
bool isPowerTwo (ll x) { return x && (!(x&(x-1))); }
const ll INF=1e16;
vector<ll>v(200005,-INF);
ll dp[200005][2][2];
bool vis[200005][2][2];
ll n;
ll find(ll pos,ll flag1,ll flag2){
	// cout<<pos<<" "<<flag1<<" "<<flag2<<endl;
	if(pos>=n) return 0ll;
	ll &ans=dp[pos][flag1][flag2];
	if(vis[pos][flag1][flag2]) return ans;
	vis[pos][flag1][flag2]=1;
	if(flag2==0){
		if(pos==n-3){
			if(flag1==0) return ans=max(v[pos],max(v[pos+1],v[pos+2]));
			else         return ans=max(v[pos+1],v[pos+2]);
		}
		if(flag1==0){
			ll ans1=find(pos+2,0ll,1ll);
			ll ans2=v[pos]+find(pos+2,0ll,0ll);
			ll ans3=v[pos+1]+find(pos+2,1ll,0ll);
			ans=max(ans1,max(ans2,ans3));
		}
		else{
			ll ans1=find(pos+2,0ll,1ll);
			ll ans2=v[pos+1]+find(pos+2,1ll,0ll);
			ans=max(ans1,ans2);
		}
	}
	else{
		if(flag1==0){
			ll ans1=v[pos]+find(pos+2,0ll,1ll);
			ll ans2=v[pos+1]+find(pos+2,1ll,1ll);
			ans=max(ans1,ans2);
		}
		else{
			ans=v[pos+1]+find(pos+2,1ll,1ll);
		}
	}
	// cout<<pos<<" "<<flag1<<" "<<flag2<<" "<<ans<<endl;
	return ans;
}
int main(){
	FastRead;
	ll t=1;
	while(t--){
		cin>>n;
		for(ll i=0;i<n;i++){
			cin>>v[i];
		}
		for(ll i=0;i<n;i++){
			vis[i][0][0]=vis[i][0][1]=0;
			vis[i][1][0]=vis[i][1][1]=0;
		}
		if(n&1){
			cout<<find(0,0ll,0ll)<<endl;
		}
		else{
			cout<<find(0,0ll,1ll)<<endl;
		}
	}
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i)
#define reprev(i, n) for(int i = (n-1LL); i >= 0; --i)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

struct UnionFind {
    vector< int > data;
    UnionFind(int sz) {
        data.assign(sz, -1);
    }
    bool unite(int x, int y) {
        x = find(x), y = find(y);
        if(x == y) return (false);
        if(data[x] > data[y]) swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return (true);
    }
    int find(int k) {
        if(data[k] < 0) return (k);
        return (data[k] = find(data[k]));
    }
    int size(int k) {
        return (-data[find(k)]);
    }
};

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m; cin >> n >> m;
    UnionFind uf(2 * n);
    rep (i, m) {
        int a, b; cin >> a >> b; a--; b--;
        uf.unite(2 * a, 2 * b + 1);
        uf.unite(2 * b, 2 * a + 1);
    }
    if (uf.find(0) != uf.find(1)) {
        ll x[2] = {};
        rep (i, n) x[(uf.find(2 * i) != uf.find(0))]++;
        eprintf("%lld %lld\n", x[0], x[1]);
        cout << x[0] * x[1] - m << "\n";
    } else {
        cout << n * (n - 1) / 2 - m << "\n";
    }
    return 0;
}

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

int MX = 100005;
vector<int> parents(MX);
vector<int> in(MX);
vector<vector<int>> tree(MX,vector<int>());

int main() {
  int n,m;
  cin >> n >> m;
  rep(i,n-1+m){
    int a,b;
    cin >> a >> b;
    --a; --b;
    tree.at(a).push_back(b);
    in.at(b) ++;
  }
  int parent = 0;
  rep(i,n){
    if(in.at(i) == 0){
      parent = i;
      break;
    }
  }
  parents.at(parent) = -1;
  queue<int> q;
  q.push(parent);
  while(!q.empty()){
    int now = q.front();
    q.pop();
    for(auto i:tree.at(now)){
      in.at(i) --;
      if(in.at(i) == 0){
        parents.at(i) = now;
        q.push(i);
      }
    }
  }

  rep(i,n) cout << parents.at(i)+1 << endl;

  return 0;
}


#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define F first
#define S second

using namespace std;
using P = pair<int,int>;
using ivec = vector<int>;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

const int MOD=1000000007;
int INF=100100100100100;

int a[100010];
signed main(){
  int n;cin>>n;
  ivec dp(n+1,INF);
  rep(i,n)cin>>a[n-1-i];
  rep(i,n){
    *lower_bound(all(dp),a[i]+1)=a[i];
  }
  cout<<lower_bound(all(dp),INF)-dp.begin()<<endl;
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={1,0,-1,0,1,-1,-1,1};
int dy[]={0,1,0,-1,1,1,-1,-1};
const int MOD = 1e9+7;
const long long INF = 1e18+10;

/*--------------------------------------------------------------------*/
signed main(){
	int n;
	cin>>n;
	int a[17];
	int x[17][17];
	int y[17][17];
	rep(i,n){
		cin>>a[i];
		rep(j,a[i]){
			cin>>x[i][j]>>y[i][j];
		}
	}
	int ans=0;
	rep(bit,1<<n){
		int shoujiki[17];
		rep(i,n){
			if(bit&(1<<i)) shoujiki[i]=1;
			else shoujiki[i]=0;
		}
		int to[17][17];
		int ok=1;
		rep(i,n){
			if(shoujiki[i]){
				rep(j,a[i]){
					if(y[i][j]){
						if(shoujiki[x[i][j]-1]==0) ok=0;
					}else{
						if(shoujiki[x[i][j]-1]==1) ok=0;
					}

				}
			}
		}
		if(ok){
			int cnt=0;
			rep(i,n){
				if(shoujiki[i]==1) cnt++;
			}
			chmax(ans,cnt);
		}
	}

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


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const int INF = 2e9;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
  ll n;
  cin >> n;
  string a, b, c;
  cin >> a >> b >> c;
  ll ans = 0;
  rep(i,n){
    if(a[i]==b[i]&&b[i]==c[i]){
      continue;
    }
    else if(a[i]!=b[i]&&b[i]!=c[i]&&c[i]!=a[i]){
      ans += 2;
    }
    else{
      ans++;
    }
  }
  print(ans);
}

#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,b) for(ll i=(b)-1; i>=a; --i)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define scanv(n,v) v.resize(n); rep(i,n){ cin>>v[i];}
#define MOD 1000000007ll
#define Yes(flag) cout<<((flag)? "Yes":"No");
#define YES(flag) cout<<((flag)? "YES":"NO");
#define be begin
#define pb push_back
#define fi first
#define se second
#define square(x) x*x
#include<bits/stdc++.h>
using ll = long long;
using namespace std;
template<class T>T
chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T>T
chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
//------------------------------------------------------
int eq(char a,char b,char c){
    vector<char> k{a,b,c};
    sort(ALL(k));
    return distance(k.begin(),unique(ALL(k)))-1;
}

int n;
string a,b,c;
void input(){
    cin>>n>>a>>b>>c;
}
void src(){
    int ans=0;
    rep(i,n){
        ans+=eq(a[i],b[i],c[i]);
    }
    cout<<ans;
}
int main(int argc,char* argv[]){
    ios::sync_with_stdio(false);
   // ifstream in( argv[1] ); cin.rdbuf(in.rdbuf());
    input();
    src();
}


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

typedef long long ll;
using namespace std;
template<class T> inline void chmax(T &a, const T &b) {if(a < b) a = b;}
template<class T> inline void chmin(T &a, const T &b) {if(a > b) a = b;}
const long long INF = 1LL<<60;

const ll MAXN = (ll)2e3+10;
const ll DIV = (ll)1e9+7;

int main(void) {
   ll N;
   cin>>N;
   string S;
   cin>>S;
   vector<int> ar(2*N);
   if (S[0]=='W' || S[2*N-1]=='W') {
      cout<<0<<endl;
      return 0;
   }
   ar[0] = 1;
   ar[2*N-1] = -1;
   rep(i,1,2*N) {
      if (S[i] == S[i-1]) {
         if (ar[i-1]==1) ar[i]=-1;
         else ar[i]=1;
      } else {
         if (ar[i-1]==1) ar[i] = 1;
         else ar[i] = -1;
      }
   }
   // rep(i,0,2*N) cout<<ar[i]<<endl;

   ll sum = 0;
   rep(i,0,2*N) sum+=ar[i];
   if (sum!=0) {
      cout<<0<<endl;
      return 0;
   }
   ll ans = 1;
   ll tmp = 0;
   for(int i = 2*N-1;i>=0;i--) {
      if (ar[i]==-1) {
         tmp++;
      } else {
         ans *= tmp;
         ans = ans%DIV;
         tmp--;
      }
   }
   // cout<<ans<<endl;
   rep(i,1,N+1) {
      ans *= i;
      ans = ans%DIV;
   }
   cout<<ans<<endl;

   return 0;
}

#include <iostream>
#include <string>

using namespace std;

const int MOD = 1000000007;

int solve(const string& s){
    const int N = s.size()/2;
    long long res = 1;
    int numS = 0, sumS = 0, inc = 0;
    for(auto& c : s){
        if(c == 'B'){
            if(inc%2 == 0){
                ++inc;
                ++numS;
                ++sumS;
            } else {
                if(numS == 0) return 0;
                --inc;
                res = (res * numS) % MOD;
                --numS;
            }
        } else {
            if(inc%2 == 0){
                if(numS == 0) return 0;
                --inc;
                res = (res * numS) % MOD;
                --numS;
            } else {
                ++inc;
                ++numS;
                ++sumS;
            }
        }
    }
    if(sumS != N) return 0;
    for(int i=1;i<=N;i++) res = (res*i)%MOD;
    return res;
}

int main(){
    int N;
    while(cin >> N){
        string s; cin >> s;
        cout << solve(s) << endl;
    }
}


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

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

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;

long long N;
map<long long, long long> mp;

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> N ;
	for(int i=0; i<N; i++){
		long long a;
		cin >> a;
		if(mp.count(a)==0){
			mp[a] = 1;
		}
		else{
			mp[a]++;
		}
	}
	vector<pair<long long, long long>> v;

	for(auto itr = mp.begin(); itr != mp.end(); itr++){
		long long k = itr->first;
		long long u = itr->second;
		v.push_back(make_pair(k, u));
	}

	sort(v.begin(), v.end());
	int found = 0;
	long long ans = 0;
	for(int i=v.size()-1; i>=0; i--){
		if(v[i].second < 2) continue;
		if(v[i].second >=4){
			if(found == 2){
				ans = ans*(v[i].first);
			}
			else{
				ans = (v[i].first)*(v[i].first);
			}
			found = 4;
			break;
		}
		if(v[i].second == 2 || v[i].second == 3){
			found += 2;
			if(found == 4){
				ans = ans * v[i].first;
				break;
			}
			else{
				ans = v[i].first;
			}
		}

	}
	if(found < 4) ans = 0;
	printf("%lld\n", ans);
	return 0;
}

#include <bits/stdc++.h>

#define nl '\n'

using namespace std;

typedef long long ll;

void solve() {
  int N;
  cin >> N;
  int A[N];
  for (int& i: A) cin >> i;

  ll ans = 0;
  const int mod = 1e9 + 7;
  int suff[N] = {0};
  suff[N - 1] = A[N - 1];
  for (int i = N - 2; i >= 0; i--)
    suff[i] = (A[i] + suff[i + 1]) % mod;
  for (int i = 0; i < N - 1; i++) ans = (ans + (1ll * A[i] * suff[i + 1]) % mod) % mod;

  cout << ans;
}

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

  // int t;
  // cin >> t;
  // while (t--) {
  solve();
  // cout << nl;
  // }

  return 0;
}


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

int main(){
  int n;
  cin >> n;
  int h,w;
  cin >> h >> w;
  int ans=(n-h+1)*(n-w+1);
  cout << ans << endl;
  return 0;
}

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  string S; cin >> S;
  int ans = 1000;
  rep(i,S.size()-2) {
    int t = int(S[i]-48) * 100 + int(S[i+1]-48) * 10 + int(S[i+2]-48);
    ans = min(ans, abs(t - 753));
  }
  cout << ans << endl;
  return 0;
}


#include <iostream>
#include <cstdio>
#include <climits>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#define MAX 10000
#define INFTY 1<<30 // 2^30
#define N 8
using namespace std;
typedef long long llong;
static const int NIL = -1;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

static const int NOT_FREE = 0;
static const int FREE = 1;
static const int FIXED = 2;

bool X[N][N];
vector<pair<int, int> > ans;

void init()
{
  for(int i = 0; i < N; i++)
    for(int j = 0; j < N; j++)
      X[i][j] = false;
}

bool can_pos(int x, int y)
{
  for(int i = 0; i < ans.size(); i++)
  {
    int tx = ans[i].first;
    int ty = ans[i].second;
    if(x == tx) return false;
    if(y == ty) return false;
    if((x-tx)*(x-tx) == (y-ty)*(y-ty)) return false;
  }
  return true;
}

void printBoard()
{
  for(int i = 0; i < ans.size(); i++)
    X[ans[i].first][ans[i].second] = true;
  for(int i = 0; i < N; i++)
  {
    for(int j = 0; j < N; j++)
      cout << (X[i][j] ? "Q" : ".");
    cout << endl;
  }
}

bool recursive(int p)
{
  for(; p < N * N; p++)
  {
    int i = p%N;
    int j = p/N;
    if(!(can_pos(i,j))) continue;
    pair<int, int>tmp = make_pair(i, j);
    ans.push_back(tmp);
    if(!recursive((j+1)*N)) ans.pop_back();
  }
  if(ans.size() == N) return true;
  return false;
}

int main()
{
  init();
  int k, r, c; cin >> k;
  for(int i = 0; i < k; i++)
  {
    cin >> r >> c;
    pair<int, int> tmp = make_pair(r, c);
    ans.push_back(tmp);
  }
  if(recursive(0)) printBoard();
  return 0;
}

#include <iostream>
#include <cstdio>
#include <cstdlib>

using namespace std;

const char Q = 'Q';
const char _ = '.';

char board[8][9] = {
    "........",
    "........",
    "........",
    "........",
    "........",
    "........",
    "........",
    "........",
};

int n;
bool pre_x[8], pre_y[8];

inline bool check(int x, int y) {
    int p = x, q = y;
    while (--p >= 0 && --q >= 0) {  // upper left
        if (board[q][p] == Q) return false;
    }

    p = x; q = y;
    while (++p < 8 && --q >= 0) {   // upper right
        if (board[q][p] == Q) return false;
    }

    p = x; q = y;
    while (++p < 8 && ++q < 8) {    // lower right
        if (board[q][p] == Q) return false;
    }

    p = x; q = y;
    while (--p >= 0 && ++q < 8) {   // lower left
        if (board[q][p] == Q) return false;
    }

    return true;
}

bool solve(int row) {
    if (row == 8)
        return true;
    if (pre_y[row] && solve(row + 1)) {
        return true;
    }
    else {
        for (int i = 0; i < 8; ++i) {
            if (!pre_x[i] && check(i, row)) {
                board[row][i] = Q;
                pre_x[i] = true;
                if (solve(row + 1)) {
                    return true;
                }
                else {
                    board[row][i] = _;
                    pre_x[i] = false;
                }
            }
        }
    }
    return false;
}

int main(void) {

    scanf("%d", &n);

    for (int i = 0, x, y; i < n; ++i) {
        scanf("%d %d", &y, &x);
        board[y][x] = Q;
        pre_y[y] = pre_x[x] = true;
    }

    solve(0);

    for (int i = 0; i < 8; ++i) {
        printf("%s\n", board[i]);
    }

    return 0;
}


#include <cstdio>
#include <algorithm>
#include <string>
#include <iostream>

#define inf 1001001001
using namespace std;
int n, c;
size_t s, t, dp[1001][1001];
string a, b;
int main() {
	cin >> a >> b;
	s = a.length(), t = b.length();
	for (size_t i = 1; i <= s; ++i) dp[i][0] = i;
	for (size_t i = 1; i <= t; ++i) dp[0][i] = i;
	for (size_t i = 0; i < s; ++i) {
		for (size_t j = 0; j < t; ++j) {
			if (a[i]==b[j]) c = 0; else c = 1;
			dp[i+1][j+1] = min(dp[i][j+1]+1, dp[i+1][j]+1);
			dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j]+c);
		}
	}
	printf("%ld\n", dp[s][t]);
}


#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;

int main() {
    int N, ans = 0;
    string A, B, C;
    cin >> N >> A >> B >> C;
    for (int i = 0; i < N; i++){
        set<char> T;
        T.insert(A.at(i));
        T.insert(B.at(i));
        T.insert(C.at(i));
        if (T.size() == 2){
            ans++;
        }
        else if (T.size() == 3){
            ans += 2;
        }
    }
    cout << ans << endl;
}

#include <bits/stdc++.h>
using namespace std;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)

int main(){

    // 1. 入力情報.
    int N;
    char A[111], B[111], C[111];
    scanf("%d %s %s %s", &N, A, B, C);

    // 2. 操作回数を保存.
    int ans = 0;
    rep(i, N){
        set<char> s;
        s.insert(A[i]);
        s.insert(B[i]);
        s.insert(C[i]);
        ans += s.size() - 1;
    }

    // 3. 出力.
    printf("%d\n", ans);
    return 0;

}


#include<bits/stdc++.h>
#define del(a,i) memset(a,i,sizeof(a))
#define ll long long
#define inl inline
#define il inl void
#define it inl int
#define ill inl ll
#define re register
#define ri re int
#define rl re ll
#define mid ((l+r)>>1)
#define lowbit(x) (x&(-x))
#define INF 0x3f3f3f3f
using namespace std;
template<class T>il read(T &x){
	int f=1;char k=getchar();x=0;
	for(;k>'9'||k<'0';k=getchar()) if(k=='-') f=-1;
	for(;k>='0'&&k<='9';k=getchar()) x=x*10+k-'0';
	x*=f;
}
template<class T>il _print(T x){
	if(x>=10) _print(x/10);
	putchar(x%10+'0');
}
template<class T>il print(T x){
	if(x<0) putchar('-'),x=-x;
	_print(x);
}
ll mul(ll a,ll b,ll mod){long double c=1.;return (a*b-(ll)(c*a*b/mod)*mod)%mod;}
it qpow(int x,int k,int mod){
	int res=1,bas=x;
	while(k){
		if(k&1) res=1ll*res*bas%mod;
		bas=1ll*bas*bas%mod,k>>=1;
	}
	return res;
}
const int N = 2e5+5,mod = 1e9+7;
it add(int x,int y){return x+y>=mod?x+y-mod:x+y;}
it mul(int x,int y){return 1ll*x*y%mod;}
il inc(int &x,int y){x=add(x,y);}
int n,m,k,ans,fac[N],ifac[N];
it C(int n,int m){return mul(mul(ifac[n-m],ifac[m]),fac[n]);}
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	read(n),read(m),read(k),fac[0]=1;
	for(ri i=1;i<=n*m;++i) fac[i]=mul(fac[i-1],i);
	ifac[n*m]=qpow(fac[n*m],mod-2,mod);
	for(ri i=n*m-1;i>=0;--i) ifac[i]=mul(ifac[i+1],i+1);
	for(ri i=1;i<=n-1;++i) inc(ans,mul(mul(mul(m,m),n-i),i));
	for(ri i=1;i<=m-1;++i) inc(ans,mul(mul(mul(n,n),m-i),i));
	print(mul(ans,C(n*m-2,k-2)));
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9+7;

struct Combination {
	vector<long long> inv,finv,fac;
	Combination(int n, int kmax) : inv(kmax+1),finv(kmax+1),fac(kmax){
		if(kmax>=1){
			inv.at(1)=1;
			finv.at(1)=1;
			fac.at(0) = n;
		}
	for(int i=2; i<=kmax; i++) inv.at(i) = MOD - inv.at(MOD%i) * (MOD/i) %MOD;
	for(int i=2; i<=kmax; i++) finv.at(i) = finv.at(i-1) * inv.at(i) % MOD;
	for(int i=1; i<kmax; i++) fac.at(i) = fac.at(i-1) * (n-i) % MOD;
	}
	int comb(int k) {return (k ? fac.at(k-1) * finv.at(k) % MOD : 1 );}
};
ll exgcd(ll a,ll b,ll &x,ll &y){
	while(b){
		ll t{a/b};
		swap(a-=t*b, b);
		swap(x-=t*y, y);
	}
	return a;
}
ll exgcd(ll a,ll b){
	ll x{1},y{0};
	return exgcd(a,b,x,y);
}
ll inverse(ll a,ll mod){
	ll x{1},y{0};
	exgcd(a,mod,x,y);
	return (x%mod+mod)%mod;
}
int main(){
	int n,m,k; cin>>n>>m>>k;
	ll sum{};
	Combination c(n*m-2,k-2);
	for(ll i=0; i<n; i++){
		for(ll j=0; j<m; j++){
			sum += (i*(i+1)/2+(n-i)*(n-i-1)/2)*m;
			sum %= MOD;
			sum += (j*(j+1)/2+(m-j)*(m-j-1)/2)*n;
			sum %= MOD;
		}
	}
	sum *= c.comb(k-2);
	sum %= MOD;
	sum *= inverse(2,MOD);
	sum %= MOD;
	cout << sum << endl;

}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>

using namespace std;

const int MAXN = 100000 + 1000;

int n;
int s[4][MAXN];
int id[MAXN], rev[MAXN];
int s1, s2, f1, f2;
bool vis[MAXN];

void no()
{
	cout << "No" << endl;
	exit(0);
}

void yes()
{
	cout << "Yes" << endl;
	exit(0);
}

int main()
{
	ios::sync_with_stdio(false);
	// freopen("1.in", "r", stdin);
	// freopen("1.out", "w", stdout);

	cin >> n;
	for(int i = 1; i <= 3; i++)
		for(int j = 1; j <= n; j++)
			cin >> s[i][j];

	for(int i = 1; i <= n; i++)
	{
		if(s[1][i] % 3 == 0 && s[3][i] + 1 == s[2][i] && s[2][i] + 1 == s[1][i])
			id[i] = s[1][i] / 3, rev[i] = true;
		else if(s[3][i] % 3 == 0 && s[1][i] + 1 == s[2][i] && s[2][i] + 1 == s[3][i])
			id[i] = s[3][i] / 3, rev[i] = false;
		else
			no();
	}

	// for(int i = 1; i <= n; i++)
	// 	cout << id[i] << endl;

	for(int i = 1; i <= n; i++)
		if(id[i] % 2 != i % 2)
			no();

	for(int i = 1; i <= n; i++)
		(i & 1 ? f1 : f2) ^= rev[i];

	for(int i = 1; i <= n; i++)
		if(!vis[i])
		{
			int cur = i, cnt = 0;
			do
			{
				vis[cur] = true;
				cnt++;
				cur = id[cur];
			}
			while(cur != i);
			(i & 1 ? s1 : s2) ^= ((cnt - 1) & 1);
		}

	if((s1 ^ f2) || (s2 ^ f1))
		no();

	yes();

	return 0;
}

#include <iostream>
#include <cassert>
#include <cstring>
#include <vector>

using namespace std;

vector<vector<vector<double>>> dp;
int n;

double find(int i, int j, int k){

    if(dp[i][j][k]!=-1) return dp[i][j][k];

    dp[i][j][k] = 0.0;
    if(i==0 && j==0 && k==0){
        return dp[i][j][k];
    }
    dp[i][j][k] += n;
    if(k){
        dp[i][j][k] += k*find(i,j+1,k-1);
    }
    if(j){
        dp[i][j][k] += j*find(i+1,j-1,k);
    }
    if(i){
        dp[i][j][k] += i*find(i-1,j,k);
    }
    dp[i][j][k] /= 1.0*(i+j+k);
    return dp[i][j][k];
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    t = 1;
    while(t--){
        cin >> n;
        dp = vector<vector<vector<double>>> (n+1,vector<vector<double>>(n+1,vector<double>(n+1,-1)));

        vector<int> count(4,0);
        for(int i=0 ; i<n ; i++){
            int in;
            cin >> in;
            count[in]++;
        }
        cout.precision(16);
        cout << find(count[1],count[2],count[3]) << "\n";
    }
    return 0;
}


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

char arr[405][405];
bool vis[405][405];
int h, w;
int cb;
int cw;

bool f(int i, int j, int l, int m){
	if(l<0 || l>=h || m<0 || m>=w){
		return 0;
	}
	if(vis[l][m]==1){
		return 0;
	}
	if(arr[i][j]==arr[l][m]){
		return 0;
	}
	return 1;
}

void dfs(int i, int j){
	vis[i][j]=1;
	if(arr[i][j]=='#'){
		cb++;
	}
	else{
		cw++;
	}
	if(f(i, j, i+1, j)){
		dfs(i+1, j);
	}
	if(f(i, j, i, j+1)){
		dfs(i, j+1);
	}
	if(f(i, j, i-1, j)){
		dfs(i-1, j);
	}
	if(f(i, j, i, j-1)){
		dfs(i, j-1);
	}
}

main() {
	cin>>h>>w;
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			cin>>arr[i][j];
		}
	}
	int ans=0;
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			if(vis[i][j]==0){
				dfs(i, j);
				ans+=(cb*cw);
				cb=0;
				cw=0;
			}
		}
	}
	cout<<ans;
	return 0;
}

#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

const ll INF = 1LL << 50;

struct UnionFind {
  vll par;
  vll wcnt;
  vll bcnt;
  ll cnt;
  UnionFind(ll N, vector<string>& mp) : par(N), wcnt(N, 0), bcnt(N, 0), cnt(N) {
    for (ll i = 0; i < N; i++) {
      par[i] = i;
      ll w = (ll)mp[0].size();
      if (mp[i / w][i % w] == '.')
        wcnt[i] = 1;
      else
        bcnt[i] = 1;
    }
  }

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

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

  ll get_wcnt(ll x) { return wcnt[find(x)]; }
  ll get_bcnt(ll x) { return bcnt[find(x)]; }

  void unite(ll x, ll y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    ll sizex = wcnt[x] + bcnt[x];
    ll sizey = wcnt[y] + bcnt[y];
    if (sizex < sizey) swap(x, y);
    par[y] = x;
    wcnt[x] += wcnt[y];
    bcnt[x] += bcnt[y];
    cnt--;
  }

  ll count() const { return cnt; }
};

int main() {
  ll h, w;
  cin >> h >> w;
  vector<string> mp(h);
  rep(i, h) { cin >> mp[i]; }

  UnionFind uf(h * w, mp);
  rep(i, h) rep(j, w) rep(k, 4) {
    ll y = i + dy[k];
    ll x = j + dx[k];
    bool cond = 0 <= x && x < w && 0 <= y && y < h;
    if (!cond) continue;
    if (mp[y][x] != mp[i][j]) {
      uf.unite(x + y * w, j + i * w);
    }
  }
  ll ans = 0;
  rep(i, h * w) {
    if(i == uf.find(i)){
      ans += uf.get_bcnt(i) * uf.get_wcnt(i);
    }
  }

  cout << ans << endl;

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int cnt[100005];
bool ac[100005];

char s[5];

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

    int pen = 0;
    int res = 0;

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

        if (s[0] == 'A') {
            if (!ac[x]) {
                res++;
                pen += cnt[x];
            }
            ac[x] = 1;
        }
        else {
            cnt[x]++;
        }
    }

    printf("%d %d\n", res, pen);
}

#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (ll i = 0; i < n; i++)
#define IREP(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define all(v) v.begin(), v.end()
#define SENTINEL 2000000000
#define NIL -1
using namespace std;
typedef long long ll;

const ll MAX = 510000;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template <class T>inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}

int h, w;
vector<string> v(400);
class UnionFind
{
public:
    vector<ll> par; // 各元の親を表す配列
    vector<ll> siz; // 素集合のサイズを表す配列(1 で初期化)
    vector<ll> siz_B;
    // Constructor
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1), siz_B(sz_,0)
    {
        for (ll i = 0; i < sz_; ++i)
            par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_)
    {
        par.resize(sz_);
        siz.assign(sz_, 1);
        siz_B.assign(sz_, 0);
        for (ll i = 0; i < sz_; ++i){
            par[i] = i;
            if (v[i / w][i % w] == '#')
            {
                siz_B[i]=1;
            }
        }
    }

    // Member Function
    // Find
    ll root(ll x)
    { // 根の検索
        while (par[x] != x)
        {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y)
    {
        x = root(x);
        y = root(y);
        if (x == y)
            return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y])
            swap(x, y);
        siz[x] += siz[y];
        siz_B[x]+=siz_B[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y)
    { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x)
    { // 素集合のサイズ
        return siz[root(x)];
    }
    ll size_B(ll x){
        return siz_B[root(x)];
    }
};

int main()
{
    cin >> h >> w;
    REP(i,h){
        cin >> v[i];
    }
    UnionFind uf(h * w);
    uf.init(h*w);
    REP(i,h){
        REP(j,w){
            if(j!=w-1&&v[i][j]!=v[i][j+1]){
                uf.merge(i*w+j,i*w+j+1);
            }
            if(i!=h-1&&v[i][j]!=v[i+1][j]){
                uf.merge(i*w+j,(i+1)*w+j);
            }
        }
    }
    set<ll> ne;
    REP(i,h){
        REP(j,w){
            ne.insert(uf.root(i*w+j));
        }
    }
    ll ans=0;
    for(auto& k:ne){
        ans+=(uf.size(k)-uf.size_B(k))*(uf.size_B(k));
    }
    cout << ans << endl;
}


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

#define V(a) a.begin(), a.end()
typedef vector<int> vi;

int main()
{
	vi a[2], C;

	for (auto &i : a) {
		int n;
		cin >> n;
		i = vi(n);
		for (int &j : i)
			cin >> j;
		sort(V(i));
	}

	set_intersection(V(a[0]), V(a[1]), inserter(C, C.end()));

	cout << C.size() << endl;
}

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <set>

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

int main(void){
	int s,t,r=0;
	cin>>s;
	vi sv(s);
	rep(i,s)cin>>sv[i];
	cin>>t;
	vi tv(t);
	rep(i,t){
		cin>>tv[i];
		rep(j,s){
			if(sv[j] == tv[i]){
				r++;
				break;
			}
		}
	}
	cout<<r<<endl;
}


#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll mod=1000000007;
const int MAX_N = 1000;         // n の最大値

// nCk を取得
double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}

int main() {
ll h,w,n;
cin>>h>>w>>n;
ll ans=0;
if(h>w){
if(n%h==0){
ans = n/h;}
else{
ans = n/h +1;}}
else{
if(n%w==0){
ans = n/w;}
else{
ans = n/w +1;}}
cout << ans << endl;}

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

int main() {

	ll n; cin >> n;
	const ll p = 26;
	string  ans = "";
	ll tmp = n;
	while (true) {
		tmp--;
		ll mod = tmp % p;
		string mod_s{ (char)('a' + mod) };
		ans += mod_s;
		if (tmp / p == 0) break;
		tmp /= p;
	}
	reverse(ans.begin(), ans.end());
	cout << ans << endl;
    return 0;
}


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

struct UnionFind {
    vector<int> data;
    int sz;
    UnionFind(int sz) : data(sz, -1), sz(sz) { }
    bool unionSet(int x, int y) {
        if ((x = root(x)) == (y = root(y))) return false;
        if (data[x] > data[y]) swap(x, y);
        data[x] += data[y]; data[y] = x; sz--;
        return true;
    }
    bool findSet(int x, int y) { return root(x) == root(y); }
    int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
    int size(int x) { return -data[root(x)]; }
    int size() { return sz; }
};

int main() {
    int n, m; cin >> n >> m;
    UnionFind uf(n * 2);
    for (int i = 0; i < m; i++) {
        int a, b; cin >> a >> b; a--, b--;
        uf.unionSet(a, b + n);
        uf.unionSet(a + n, b);
    }
    long long all = 0;
    if (uf.findSet(0, n)) {
        all = 1LL * n * (n - 1) / 2;
    } else {
        for (int i = 0; i < n; i++) all += uf.findSet(0, i);
        all *= n - all;
    }
    cout << all - m << endl;
    return 0;
}

#include <iostream>
#include <vector>
#include <map>
using namespace std; using P=pair<int,int>; using ll=long long;
const int mx=1e5; vector<vector<int>> v(mx); vector<int> c(mx); int n; bool noco=false;
void dfs(int from, int to, int color) {
	if (from == -1) for(int i=0;i<n;i++) c[i]=-1;
	if (c[to] == 0 || c[to] == 1) {
		if (c[to] != color) noco=true; return;
	} else c[to]=color;
	for(int next:v[to]) {
		if (from == next) continue;
		dfs(to, next, color^1);
	}
}
int main() {
	int m; cin>>n>>m;
	for(int i=0;i<m;i++) {
		int a,b; cin>>a>>b; a--; b--; v[a].push_back(b); v[b].push_back(a);
	}
	dfs(-1,0,0);
	ll w=0,h=0,used=0;
	for(int i=0;i<n;i++) {
		if (c[i] == 0) w++;
		if (c[i] == 1) h++;
	}
	if (noco) {
		for(int i=0;i<n;i++) {
			if (c[i] == -1) continue;
			used+=v[i].size();
		}
		used/=2;
		cout<<(w+h)*(w+h-1)/2-used<<endl;
	} else {
		for(int i=0;i<n;i++) {
			if (c[i] == -1) continue;
			for(int x:v[i]) {
				if (c[i]^1 == c[x]) used++;
			}
		}
		used/=2;
		cout<<w*h-used<<endl;
	}
}


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

typedef long long ll;

int main() {
  double ans = 0;
  int count = 0;
  int N;
  cin >> N;
  vector<pair<int, int>> points;
  for(int i=0;i<N;i++){
    pair<int, int> p;
    cin >> p.first;
    cin >> p.second;
    points.push_back(p);
  }
  sort(points.begin(), points.end());
  do{
    int sx = points[0].first;
    int sy = points[0].second;
    for(int i=1; i<N; i++){
      ans += sqrt(pow((sx-points[i].first), 2) + pow((sy-points[i].second), 2));
      sx = points[i].first;
      sy = points[i].second;
    }
    count++;
  }while(next_permutation(points.begin(), points.end()));
  cout << setprecision(10) << (double)ans/count << endl;
  return 0;
}

#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#define my_abs(x) ((x) < 0 ? -(x) : (x))
using namespace std;
typedef long long ll;
ll ans, fact[25];
int arr[25];
inline void chk(int len)
{
	ll res = 9 - my_abs(arr[0]);
	for (int i = 1; i <= len - 1 >> 1; i++)
		res *= 10 - my_abs(arr[i]);
	ans += res;
}
void dfs(int cur, int len, ll rem)
{
	if (cur == len >> 1)
	{
		if (!rem)
		{
			arr[cur] = 0;
			chk(len);
		}
		return;
	}
	ll diff = fact[len - cur - 1] - fact[cur];
	ll r = ceil((double)rem / diff), l = floor((double)rem / diff);
	if (-9 <= r && r <= 9)
	{
		arr[cur] = r;
		dfs(cur + 1, len, rem - diff * r);
	}
	if (l != r && -9 <= l && l <= 9)
	{
		arr[cur] = l;
		dfs(cur + 1, len, rem - diff * l);
	}
}
int main()
{
	// freopen("ARC075-F.in", "r", stdin);
	ll d;
	scanf("%lld", &d);
	fact[0] = 1;
	for (int i = 1; i <= 18; i++)
		fact[i] = fact[i - 1] * 10;
	for (int cnt = 1; cnt <= 18; cnt++)
	{
		memset(arr, 0, sizeof(arr));
		dfs(0, cnt, d);
	}
	printf("%lld\n", ans);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
typedef vector < vector<ll> > Mat;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int H, W;
char C[405][405];
bool visited[405][405];
int di[4] = {0, 1, 0, -1}, dj[4] = {1, 0, -1, 0};
ll ans = 0, b = 0, w = 0;

int Solve(int i, int j){
  b = 0; w = 0;
  if (C[i][j] == '.') w++;
  else b++;
  visited[i][j] = true;

  queue <Pii> que; que.push({i, j});
  while (!que.empty()){
    Pii Q = que.front(); que.pop();
    for (int k = 0; k < 4; k++){
      int I = Q.fi + di[k], J = Q.se + dj[k];
      if (0 <= I && I < H && 0 <= J && J < W){
        if (visited[I][J]) continue;
        if (C[I][J] == C[Q.fi][Q.se]) continue;

        que.push({I, J});
        visited[I][J] = true;
        if (C[I][J] == '.') w++;
        else b++;
      }
    }
  }

  ans += b * w;
  return 0;
}

int main(){
  cin >> H >> W;
  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      cin >> C[i][j];
    }
  }

  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      if (!visited[i][j]) Solve(i, j);
    }
  }
  cout << ans << endl;

  return 0;
}

/*The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep.*/

//PRABHJOT SINGH A.K.A. PRABHI
//~~~~~conquizztador~~~~~

#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007
const int maxn= 100010;
int h,w;
string s[440];
bool vis[440][440]={false};
int typ[2];
int dx[4]={1,0,-1,0};
int dy[4]={0,-1,0,1};
void dfs(int i, int j)
{
	vis[i][j]=true;
	if(s[i][j]=='#')
		++typ[0];
	else
		++typ[1];
	for(int k=0;k<4;++k)
	{
		int x=i+dx[k];
		int y=j+dy[k];
		if(x>=0&&x<h&&y>=0&&y<w&&vis[x][y]==false&&s[i][j]!=s[x][y])
			dfs(x,y);
	}
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lli res=0ll;
    cin>>h>>w;
    for(int i=0;i<h;++i)
    	cin>>s[i];
    for(int i=0;i<h;++i)
    	for(int j=0;j<w;++j)
    	{
    		if(vis[i][j])
    			continue;
    		if(s[i][j]=='.')
    			continue;
    		typ[0]=0;
    		typ[1]=0;
    		dfs(i,j);
    		res+=1ll*typ[0]*typ[1];
    	}
    cout<<res<<endl;
}


#include<iostream>
#include<cstring>
using namespace std;
int main()
{
    char str[25];
    cin>>str;
    char rev[25];
    for(int i=0;i<strlen(str);i++)
        rev[i]=str[strlen(str)-i-1];
    rev[strlen(str)]='\0';
    cout<<rev<<endl;
}

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

int main(){

	string str;

	cin >> str;

	std::istringstream stream(str);
	for(int i=str.length()-1; i>=0; i--){
		stream >> str[i];
	}

	cout << str << endl;

	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define db double
#define ld long double
#define pii pair<int,int>
#define vvi vector<vector<int> >
#define vpi vector<pii>
#define F first
#define S second
#define pb push_back
#define INF 0x7fffffff
#define LINF 0x7fffffffffffffff
#define MOD 1000000007
#define mod 998244353
#define lowbit(x) x&(-x)
#define HS 173LL
using namespace std;
int read()
{
	int x=0;
	char ch=getchar();
	while(!isdigit(ch))
		ch=getchar();
	while(isdigit(ch))
	{
		x=x*10+ch-'0';
		ch=getchar();
	}
	return x;
}
int h,w;
map<int,int> mp;
multiset<int> st;
int main()
{
	h=read(),w=read();
	for(int i=1;i<=w;i++)
		mp[i]=0;
	for(int i=1;i<=w;i++)
		st.insert(0);
	for(int i=1;i<=h;i++)
	{
		int l=read(),r=read();
		if(r!=w)
		{
			auto it=mp.upper_bound(r+1);
			if(it!=mp.begin())
			{
				--it;
				if(it->first!=r+1)
				{
					int v=it->second+r+1-it->first;
					mp[r+1]=v;
					st.insert(v);
				}
			}
		}
		auto it=mp.lower_bound(l);
		while(it!=mp.end()&&it->first<=r)
		{
			st.erase(st.find(it->second));
			it=mp.erase(it);
		}
		if(!st.empty())
			cout<<*st.begin()+i<<endl;
		else
			cout<<-1<<endl;
	}
	return 0;
}

#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 998244353
#define INF63 1061109567
#define INF127 9187201950435737471
#define UINF 18446744073709551615
#define F first
#define S second
#define ll long long
#define N 200010
using namespace std;
ll n,m,a[N],b[N];
struct SegT{
	ll l,r,val,pd,pd2;
}dp[8*N];
void build_tree(ll l,ll r,ll x)
{
	if(l>r)
	{
		return;
	}
	dp[x].l=l;
	dp[x].r=r;
	dp[x].val=0;
	dp[x].pd=0;
	dp[x].pd2=-1;
	if(l==r)
	{
		return;
	}
	ll mid=(l+r)>>1,a=x<<1;
	build_tree(l,mid,a);
	build_tree(mid+1,r,a|1);
	return;
}
void push_down(ll x)
{
	ll a=x<<1;
	dp[a].val+=dp[x].pd;
	dp[a|1].val+=dp[x].pd;
	dp[a].pd+=dp[x].pd;
	dp[a|1].pd+=dp[x].pd;
	dp[x].pd=0;
	return;
}
void push_down2(ll x)
{
	ll a=x<<1;
	dp[a].val=dp[x].val;
	dp[a|1].val=dp[a|1].l-dp[a].l+dp[x].val;
	dp[a].pd2=dp[x].pd2;
	dp[a|1].pd2=dp[x].pd2;
	dp[a].pd=0;
	dp[a|1].pd=0;
	dp[x].pd=0;
	dp[x].pd2=-1;
	return;
}
void update(ll l,ll r,ll x)
{
	if(l>r)
	{
		return;
	}
	ll tl=dp[x].l,tr=dp[x].r;
	if(tl>r||tr<l)
	{
		return;
	}
	if(dp[x].pd2!=-1)
	{
		push_down2(x);
	}
	push_down(x);
	if(l<=tl&&tr<=r)
	{
		dp[x].val++;
		dp[x].pd++;
		return;
	}
	ll mid=(tl+tr)>>1,a=x<<1;
	if(mid>=l)
	{
		update(l,r,a);
	}
	if(mid<r)
	{
		update(l,r,a|1);
	}
	dp[x].val=min(dp[a].val,dp[a|1].val);
	return;
}
ll query(ll l,ll r,ll x)
{
	if(l<0||r<0||l>=m||r>=m)
	{
		return LINF;
	}
	ll tl=dp[x].l,tr=dp[x].r;
	if(tl>r||tr<l)
	{
		return LINF;
	}
	if(dp[x].pd2!=-1)
	{
		push_down2(x);
	}
	push_down(x);
	if(l<=tl&&tr<=r)
	{
		return dp[x].val;
	}
	ll mid=(tl+tr)>>1,a=x<<1,ret=LINF;
	if(mid>=l)
	{
		ret=min(ret,query(l,r,a));
	}
	if(mid<r)
	{
		ret=min(ret,query(l,r,a|1));
	}
	dp[x].val=min(dp[a].val,dp[a|1].val);
	return ret;
}
void update2(ll l,ll r,ll x,ll val)
{
	if(l>r)
	{
		return;
	}
	ll tl=dp[x].l,tr=dp[x].r;
	if(l<=tl&&tr<=r)
	{
		dp[x].val=val+tl-l+1;
		dp[x].pd=0;
		dp[x].pd2=l;
		dp[x<<1].pd=0;
		dp[(x<<1)|1].pd=0;
		push_down2(x);
		return;
	}
	if(dp[x].pd2!=-1)
	{
		push_down2(x);
	}
	push_down(x);
	ll mid=(tl+tr)>>1,a=x<<1;
	if(mid>=l)
	{
		update2(l,r,a,val);
	}
	if(mid<r)
	{
		update2(l,r,a|1,val);
	}
	dp[x].val=min(dp[a].val,dp[a|1].val);
	return;
}
int main(){
	ll i,j;
	scanf("%lld%lld",&n,&m);
	for(i=0;i<n;i++)
	{
		scanf("%lld%lld",&a[i],&b[i]);
		a[i]--;
		b[i]--;
	}
	build_tree(0,m-1,1);
	for(i=1;i<=n;i++)
	{
		update(0,a[i-1]-1,1);
		update(b[i-1]+1,m-1,1);
		update2(a[i-1],b[i-1],1,query(a[i-1]-1,a[i-1]-1,1));
//		for(j=0;j<m;j++)
//		{
//			query(j,j,1);
//		}
		j=dp[1].val;
		if(j<INF)
		{
			printf("%lld\n",j);
		}
		else
		{
			puts("-1");
		}
	}
	return 0;
}


#include <iostream>
#include <string>
using namespace std;
int main(void){
    string S;
    cin >> S;
    if(S.length() % 2 == 0){
        for(int i=0;i<S.length();i=i+2){
            if(S[i] == 'h' && S[i+1] == 'i'){
                continue;
            }
            else{
                cout << "No" << endl;
                return 0;
            }
        }
    }
    else{
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repo(i,N) for(int i = 1; i < (N); i++)
//#define int long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define pi acos(-1.0)
//cout << fixed << setprecision (10);   小数点以下１０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//string s = to_string(int数);
//int n = stoi(string文字列);

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

  cout << (a=="hi" || a=="hihi" || a=="hihihi" ||
           a=="hihihihi" || a=="hihihihihi"?"Yes":"No") << endl;

}


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

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

	int n, k; cin >> n >> k;
	vector<int> a(n);
	REP(i, n) cin >> a[i];
	sort(a.begin(), a.end());
	bool odd, even;
	odd = even = true;
	REP(i, n) {
		if (a[i] % 2) even = false;
		else odd = false;
	}
	bool allSame = true;
	bool diffFlag = true;
	int diff = INT_MAX;
	REP(i, n - 1) {
		if (abs(a[i] - a[i+1]))
			diff = min(diff, abs(a[i] - a[i+1]));
	}
	REP(i, n - 1) {
		if (a[i] != a[i+1])
			allSame = false;
		if (abs(a[i] - a[i+1]) % diff)
			diffFlag = false;
	}

	if (k > *max_element(a.begin(), a.end())) {
		cout << "IMPOSSIBLE" << '\n';
	}
	else if (find(a.begin(), a.end(), k) != a.end()) {
		cout << "POSSIBLE" << '\n';
	}
	else if (allSame) {
		cout << ((k == a[0]) ? "POSSIBLE" : "IMPOSSIBLE") << '\n';
	}
	else if (diffFlag) {
		cout << ((k % diff == 0) ? "POSSIBLE" : "IMPOSSIBLE") << '\n';
	}
	else {
		if (k % 2) {
			bool ok = true;
			if (even) ok = false;
			if (k == 1 && (even || odd)) ok = false;
			cout << ((ok) ? "POSSIBLE" : "IMPOSSIBLE") << '\n';
		}
		else {
			cout << "POSSIBLE" << '\n';
		}
	}
    return 0;
}

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

# define ll long long

int fpb(int a, int b){
  return (b == 0 ? a : fpb(b, a%b));
}

int main(){

  int n, k;
  cin >> n >> k;
  int f = 0, largest = 0;
  for(int i=0; i<n; i++){
    int num;
    cin >> num;
    largest = max(largest, num);
    f = fpb(f, num);
  }

  if (k <= largest && k % f == 0) cout << "POSSIBLE" << endl;
  else cout << "IMPOSSIBLE" << endl;
  return 0;
}


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

int main(){
  int sum = 1, a, b, i = 0; cin >> a >> b;
  while(sum < b){
    sum = sum - 1 + a;
    i++;
  }
  cout << i << endl;
}

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

int main() {
    int A, B;
    cin >> A >> B;
    if ((B-1)%(A-1) == 0){
        cout << (B-1)/(A-1) << endl;
    }
    else {
        cout << (B-1)/(A-1) + 1 << endl;
    }
}


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

int main()
{
    ll n, q;
    string s;
    cin >> n >> s >> q;
    for (ll i = 0; i < q; i++)
    {
        ll k;
        ll d, m, dm, dmc;
        d = m = dm = dmc = 0;
        scanf("%d", &k);
        for (ll i = 0; i < n; i++)
        {
            if (i - k >= 0)
            {
                if (s[i - k] == 'D')
                {
                    d--;
                    dm -= m;
                }
                if (s[i - k] == 'M')
                    m--;
            }
            if (s[i] == 'D')
                d++;
            if (s[i] == 'M')
            {
                m++;
                dm += d;
            }
            if (s[i] == 'C')
                dmc += dm;
        }
        cout << dmc << endl;
    }
}

#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <numeric>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <cassert>
#include <random>
#include <time.h>
#include <unordered_set>
//#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const double EPS = 1e-10;
long long const MOD = 998244353;

long long mod_pow(long long x, long long n) {
    long long res = 1;
    for (int i = 0;i < 60; i++) {
        if (n >> i & 1) res = res * x % MOD;
        x = x * x % MOD;
    }
    return res;
}

template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

void fastInput() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

const int MAXN = 1100010;
long long fact[MAXN], inv[MAXN];

void initComb() {
    fact[0] = 1;
    for (int i=1; i<MAXN; i++) {
        fact[i] = (fact[i-1] * i) % MOD;
    }

    inv[MAXN - 1] = mod_pow(fact[MAXN - 1], MOD-2);
    for (int i=MAXN - 2; i>=0; i--) {
        inv[i] = (inv[i+1] * (i+1)) % MOD;
    }
}

long long comb(int n, int r) {
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fact[n] * inv[n-r] % MOD * inv[r] % MOD;
}

Int imos_D[1000005];
Int imos_C[1000005];
Int imos_M[1000005];
Int dp[1000005][5];

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

    for (int i = 0; i < N; i++) {
        if (S[i] == 'D') imos_D[i+1] = 1;
        else imos_D[i+1] = 0;
        imos_D[i+1] += imos_D[i];

        if (S[i] == 'C') imos_C[i+1] = 1;
        else imos_C[i+1] = 0;
        imos_C[i+1] += imos_C[i];

        if (S[i] == 'M') imos_M[i+1] = 1;
        else imos_M[i+1] = 0;
        imos_M[i+1] += imos_M[i];
    }

    for (int i = 0; i < Q; i++) {
        int K; cin >> K;
        memset(dp, 0, sizeof(dp));
        dp[0][0] = 1;
        for (int j = 0; j < N; j++) {
            dp[j+1][0] = dp[j][0];
            dp[j+1][1] = dp[j][1];
            dp[j+1][2] = dp[j][2];
            dp[j+1][3] = dp[j][3];
            dp[j+1][4] = dp[j][4];
            if (S[j] == 'D') {
                dp[j+1][1] += dp[j][0];
            }
            if (S[j] == 'M') {
                dp[j+1][2] += dp[j][1];
            }
            if (S[j] == 'C') {
                dp[j+1][3] += dp[j][2];
            }

            if (S[j] == 'C') {
                if (j+1-K >= 0) {
                    Int NumOfM = imos_M[j+1] - imos_M[j+1-K];
                    dp[j+1][4] += dp[j][2] - NumOfM * dp[j+1-K][1] - dp[j+1-K][2];
                } else {
                    dp[j+1][4] += dp[j][2];
                }
            }
            // cout << NumOfM << endl;
        }
        Int U = dp[N][3];
        cout << dp[N][4] << endl;
    }
}


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

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

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

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

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

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

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

#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
int n,x,s[205];
int dp[205][100005],tot[100005];

int main(){
	scanf("%d %d",&n,&x);
	for(int i=1;i<=n;i++) scanf("%d",&s[i]);
	sort(s+1,s+n+1);
	for(int i=0;i<=x;i++){
		int l=1,r=n,p=0;
		while(l<=r){
			int mid=(l+r)/2;
			if(s[mid]<=i) p=max(p,mid),l=mid+1;
			else r=mid-1;
		}
		tot[i]=p;
	}
	dp[0][x]=1;
	for(int i=1;i<=n;i++){
		for(int j=0;j<=x;j++){
			if(dp[i-1][j]==0) continue;
			for(int k=1;k<=tot[j];k++) (dp[i][j%s[k]]+=dp[i-1][j])%=mod;
			int p=n-tot[j];
			if(i<=p) (dp[i][j]+=1ll*(p-i+1)*dp[i-1][j]%mod)%=mod;
		}
	}
	int ans=0;
	for(int i=0;i<=x;i++) (ans+=1ll*i*dp[n][i]%mod)%=mod;
	printf("%d\n",ans);

	return 0;
}


#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
	char c=getchar();bool f=0;x=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;return x;
}
template<class t,class ...A> inline void read(t &x,A &...a){
	read(x);read(a...);
}
template<class t> inline void write(t x){
	if(x<0) putchar('-'),write(-x);
	else{if(x>9) write(x/10);putchar('0'+x%10);}
}

int ans,x,y;

signed main(){
	read(x,y);
	if(x==1) ans+=3e5;
	if(x==2) ans+=2e5;
	if(x==3) ans+=1e5;
	if(y==1) ans+=3e5;
	if(y==2) ans+=2e5;
	if(y==3) ans+=1e5;
	if(x==1&&y==1) ans+=4e5;
	write(ans);
}

#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>

struct set {
	int h;
	int w;
	int diagonel;
} all[22500];

int suffix = 0;

void InsSort(int n)
{
	int i, j, temp_dia, temp_h, temp_w;

	for (i = 1; i < n; i++) {
		temp_h = all[i].h;
		temp_w = all[i].w;
		temp_dia = all[i].diagonel;
		for (j = i; j > 0; j--) {
			if (all[j - 1].diagonel > temp_dia) {
				all[j].h = all[j - 1].h;
				all[j].w = all[j - 1].w;
				all[j].diagonel = all[j - 1].diagonel;
			}
			else if (all[j - 1].diagonel == temp_dia) {
				if (all[j - 1].h > temp_h) {
					all[j].h = all[j - 1].h;
					all[j].w = all[j - 1].w;
					all[j].diagonel = all[j - 1].diagonel;
				}
				else {
					break;
				}
			}
			else {
				break;
			}
		}

		all[j].h = temp_h;
		all[j].w = temp_w;
		all[j].diagonel = temp_dia;
	}
}

void search() {
	for (int i = 1; i <= 150; i++) {
		for (int j = 1; j <= 150; j++) {
			if (i >= j) {
				continue;
			}

			all[suffix].h = i;
			all[suffix].w = j;
			all[suffix].diagonel = (i * i) + (j * j);

			suffix++;
		}
	}
}

int main() {
	search();
	InsSort(suffix);

	//FILE *fp;
	//fp = fopen("C:\\Users\\owata\\Desktop\\answer1.txt", "w");

	while (1) {
		int h, w, my;

		scanf("%d %d", &h, &w);

		if (h == 0 && w == 0) {
			break;
		}

		my = (h * h) + (w * w);

		for (int i = 0; i < suffix; i++) {
			if (all[i].h == h && all[i].w == w) {
				continue;
			}

			if (all[i].diagonel > my) {
				printf("%d %d\n", all[i].h, all[i].w);
				//fprintf(fp, "%d %d\n", all[i].h, all[i].w);
				break;
			}
			else if (all[i].diagonel == my && h < all[i].h) {
				printf("%d %d\n", all[i].h, all[i].w);
				//fprintf(fp, "%d %d\n", all[i].h, all[i].w);
				break;
			}
		}
	}

	//fclose(fp);

	return 0;
}


#include<bits/stdc++.h>
#include<string>
#include<vector>
using namespace std;
typedef pair<int, int>P;
typedef long long ll;
#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 = 5000100;
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)
//printf("%.10f\n",なんちゃら)
//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX_N; 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(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll dx[8] = { 0,0,-1,1 };
ll dy[8] = { -1,1,0,0 };
ll dp[101010];

//union-find木について
ll par[101010];
ll rank2[101010];

void init(ll n) {
	rep(i, n) {
		par[i] = i;
		rank2[i] = 0;
	}
}

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

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

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

bool graph[101][101];
bool visit[101010];
vector<ll> to[101010];
vector<ll>ball(101010, 1);
vector<bool>flag(101010);

//long longしか使わない
//素数は1より大きい
int main() {
	ll x, y;
	cin >> x >> y;
	ll ans = 0;
	if (y >= x) {
		if (x >= 0) {
			ans = y - x;
		}
		else if (y <= 0) {
			ans = y - x;
		}
		else {
			ll min2 = min(abs(x), abs(y));
			ll max2 = max(abs(x), abs(y));
			ans = max2 - min2 + 1;
		}
	}
	else {
		if (y >= 0) {
			ans = x - y + 2;
			if (y == 0) {
				ans = abs(x) + 1;
			}
		}
		else if (x <= 0) {
			ans = x - y + 2;
			if (x == 0) {
				ans = abs(y) + 1;
			}
		}
		else {
			ll min2 = min(abs(x), abs(y));
			ll max2 = max(abs(x), abs(y));
			ans = max2 - min2 + 1;
		}
	}
	cout << ans << endl;
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-6;
const double PI  = acos(-1.0);
const long INF=pow(2,31)-1;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

const long MOD=1e9+7;
const int MAX_N=1004;
int dp[MAX_N][MAX_N];
int main(){
	string S1,S2;
	cin>>S1>>S2;
	CLR(dp);
	FOR(i,1,MAX_N){
		dp[0][i]=dp[i][0]=i;
	}
	REP(i,SZ(S1)){
		REP(j,SZ(S2)){
			int cost=(S1[i]==S2[j])?0:1;
			dp[i+1][j+1]=min(min(dp[i][j+1]+1,dp[i+1][j]+1),dp[i][j]+cost);
		}
	}
	cout<<dp[SZ(S1)][SZ(S2)]<<endl;
	return 0;
}


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

int main(){
  string s;
  cin >> s;
  int n=s.size();
  bool judge=true;
  if(n%2!=0){
    judge=false;
  }
  for(int i=0;i<n;i+=2){
    if(judge==false){
      break;
    }
    if(s.at(i)!='h'||s.at(i+1)!='i'){
      judge=false;
    }
  }
  if(judge){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
const double pi=3.14159265358979323846;
int ctoi(const char c) {
    if ('0' <= c && c <= '9') return (c - '0');
    return -1;
}
vector<int> input(int n) {
    vector<int> vec(n);
    for (int i = 0; i < n; i++) {
        cin >> vec.at(i);
    }
    return vec;
}
void output(vector<int> vec) {
    for (int i = 0; i < vec.size(); i++) {
        cout << vec[i] << " ";
    }
    return;
}
vector<vector<int>> input(int n, int m) {
    vector<vector<int>> table(n, vector<int>(m));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> table. at(i).at(j);
        }
    }
    return table;
}
void output(vector<vector<int>> table) {
    for (int i = 0; i < table.size(); i++) {
        for (int j = 0; j < table.at(0).size(); j++) {
            cout << table.at(i).at(j) << " ";
        }
        cout << endl;
    }
}
long long perm(int n, int r) {
    if (n < r) {
        cout << "error" << endl;
        return 0;
    }
    long long perm = 1;
    for (int i = n; i > n - r; i--) {
        perm *= i;
    }
    return perm;
}
long long comb(int n, int r) {
    if (n < r) {
        cout << "error" << endl;
        return 0;
    }
    long long comb = perm(n,r);
    for (int i = r; i > 0; i--) {
        comb /= i;
    }
    return comb;
}
long long homo(int n, int r) {
    return comb(n + r - 1, n - 1);
}
long long fact(int n) {
    long long fact = 1;
    for (int i = n; i > 0; i--) {
        fact *= i;
    }
    return fact;
}
int gcd(int a, int b){
    if (a % b == 0){
        return(b);
    }else{
        return(gcd(b, a % b));
    }
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
bool isprime(int n){
    if (n < 2) return false;
    else if (n == 2) return true;
    else if (n % 2 == 0) return false;

    for (int i = 3; i <= sqrt(n); i += 2){
        if (n % i == 0){
            return false;
        }
    }
    return true;
}
void Yes(bool f) {
    if (f) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}
void YES(bool f) {
    if (f) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
}

int main() {
  string s;
  cin >> s;
  Yes(s=="hi"||s=="hihi"||s=="hihihi"||s=="hihihihi"||s=="hihihihihi");
}


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

struct edge
{
	int to, d;
};

vector<vector<edge>> g;
int b[100000];
int n, u, v;

int dfs(int v, int parent) {
	int res = 0;
	for (edge &ne : g[v]) {
		if (ne.to == parent) continue;
		ne.d = 1;
		int now = dfs(ne.to, v) + 1;
		res = max(res, now);
	}
	b[v] = res;
	return res;
}

int main() {
	cin >> n >> u >> v;
	u--; v--;
	g.assign(n, vector<edge>());
	for (int i = 0; i < n-1; i++) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		g[a].push_back({b, 0});
		g[b].push_back({a, 0});
	}
	dfs(v, -1);
	int dist = 0;
	for (int i = u; i != v; ) {
		for (edge e : g[i]) {
			if (e.d == 0) {i = e.to; break;}
		}
		dist++;
	}
	int ans = 0;
	while (dist > 2) {
		for (edge e : g[u]) {
			if (e.d == 0) {u = e.to; break;}
		}
		dist -= 2;
		ans++;
	}
	ans += dist + b[u] - 1;
	cout << ans << endl;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int MOD = 1000000007;

struct edge {int to, cost; };
typedef pair<int, int> P;
int V;
vector <edge> G[100010];
int d[100010];

void dijkstrra(int s){
    priority_queue <P, vector<P>, greater<P> > que;
    fill(d, d + V, 1000000000);
    d[s] = 0;
    que.push(P(0 , s));

    while(!que.empty()){
        P p = que.top(); que.pop();
        int v = p.second;
        if(d[v] < p.first)  continue;
        for(int i = 0; i < G[v].size(); i++){
            edge e = G[v][i];
            if(d[e.to] > d[v] + e.cost){
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

int main(){
    cin >> V;
    int e, r;   cin >> e >> r;
    for(int i = 0; i < e; i++){
        int s, t, d;
        cin >> s >> t >> d;
        G[s].push_back({t, d});
    }
    dijkstrra(r);
    for(int i = 0; i < V; i++){
        if(d[i] == 1000000000)
            cout << "INF" << endl;
        else
            cout << d[i] << endl;
    }
    return 0;
}


#include <cstdio>
#include <algorithm>
#define mod 998244353
#define maxn 200010
#define LL long long
using namespace std;
LL fact[maxn],inv[maxn],ans,t[maxn],p;
int n,m,k,nm;
LL quick_pow(LL a,LL b){//a^b
	LL ans=1;
	while(b){
		if(b&1)ans=ans*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return ans%mod;
}
void init(){
	int i;
	scanf("%d%d%d",&n,&m,&k);
	nm=n,nm=max(nm,m),fact[0]=1;
	for(i=1;i<=nm;i++)fact[i]=fact[i-1]*i%mod;//fact[i]代表i!
	inv[nm]=quick_pow(fact[nm],mod-2);
	for(i=nm-1;i>=0;i--)inv[i]=inv[i+1]*(i+1)%mod;//inv[i]代表i!的乘法逆元
}
LL C(LL a,LL b){//组合数计算
	return fact[a]*inv[a-b]%mod*inv[b]%mod;
}
int main(){
	int i;
	init();
	ans=0,p=quick_pow(m-1,n-k-1);
	for(i=n-k;i<=n;i++){
		ans=(ans+m*p%mod*C(n-1,i-1)%mod)%mod;//C(n-1,i-1)隔板法
		p=p*(m-1)%mod;
	}
	printf("%lld\n",ans);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

#define ff first
#define ss second
#define pb push_back
#define sz size()
#define mp make_pair
#ifndef ONLINE_JUDGE
#include "/home/asif/Codes/Library/debug.h"
#endif
/*--------------------------------------------------------------------*/

const int N = 2e5 + 5;
const int MOD = 998244353;

namespace nCr {
  ll factorial[N], invFactorial[N];
  ll ncr(ll n, ll r){
    return (( (factorial[n] * invFactorial[r]) % MOD) * invFactorial[n - r]) % MOD;
  }
  void init(){
    invFactorial[1] = 1;
    for(int i = 2;i < N;i++)invFactorial[i] = MOD - (MOD / i) * invFactorial[MOD % i] % MOD;
    factorial[0] = factorial[1] = invFactorial[0] = 1;
    for(int i = 2; i < N; i++){
      factorial[i] = (factorial[i - 1] * i) % MOD;
      invFactorial[i] = (invFactorial[i - 1] * invFactorial[i]) % MOD;
    }
  }
}

ll bigmod(ll a, ll p){
  if(p == 0) return 1LL;
  ll ret = bigmod(a, p / 2);
  ret *= ret;
  ret %= MOD;
  if(p & 1) ret = (ret * a) % MOD;
  return ret;

}

int main() {

  ll n, m, k;
  cin >> n >> m >> k;

  nCr::init();

  ll ans = 0LL;
  for(int i = 0; i <= k; i++){
    ans += (((nCr::ncr(n - 1, i) * bigmod(m - 1, n - i - 1)) % MOD) * m) % MOD;
    ans %= MOD;
  }
  cout << ans << endl;

  return 0;
}


#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
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; }

#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;

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

  int keta = 0;
  int sum = 0;

  REP(i, N){
    int a, b;
    cin >> a >> b;

    keta += b;
    sum += a*b;
  }

  cout << (keta-1)+(sum-1)/9 << "\n";

  return 0;
}

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

using namespace std;
using ll = long long;

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

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

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

int main() {
  IN(int, N);
  vector<ll> x(N);
  vector<ll> y(N);
  REP(i, N) {
    IN(ll, tmp_x);
    x.at(i) = tmp_x;
    IN(ll, tmp_y);
    y.at(i) = tmp_y;
  }

  cout << std::fixed << std::setprecision(6);

  vector<vector<long double> > dist(N, vector<long double>(N, 0));
  REP(i, N - 1) {
    REP(j, i + 1, N) {
      dist.at(i).at(j) = sqrtl((long double)(pow(x.at(i) - x.at(j), 2) + pow(y.at(i) - y.at(j), 2)));
      dist.at(j).at(i) = dist.at(i).at(j);
    }
  }

  vector<int> num;
  REP(i, 0, N) {
    num.push_back(i);
  }

  long double sum = 0;
  do {
    REP(i, N - 1) {
      sum += dist.at(num.at(i)).at(num.at(i + 1));
    }
  } while (next_permutation(ALL(num)));

  ll factorial = 1;
  REP(i, 1, N + 1) {
    factorial *= i;
  }

  long double ans = sum / (long double)factorial;
  cout << ans << endl;

  return 0;
}


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

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b) - 1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL) INF;

const int MAX = 1001000;

char S[MAX];
char T[MAX];

int A[MAX];

int main()
{
	//freopen("in.txt", "r", stdin);
	//ios::sync_with_stdio(false); cin.tie(0);

	int n;
	scanf("%d", &n);
	scanf("%s", S);
	scanf("%s", T);

	if ((string)(S) ==(string(T)))
	{
		cout<<0<<endl;
		return 0;
	}

	FILL(A, -1);
	int ind = n-1;
	RFOR(i, n, 0)
	{
		while (ind > i) ind--;
		while(ind >= 0 && S[ind] != T[i])
		{
			ind--;
		}

		if (ind == -1)
		{
			cout<<-1<<endl;
			return 0;
		}

		if (A[ind] == -1) A[ind] = i;
	}

	vector<PII> a;
	FOR (i, 0, n)
	{
		if (A[i] != -1) a.PB(MP(i, A[i]));
	}

	/*FOR (i, 0, SZ(a))
	{
		cout<<a[i].first<<' '<<a[i].second<<endl;
	}
	cout<<endl;*/

	int res = 0;

	ind = 0;
	int ind2 = 0;
	FOR (i, 0, SZ(a))
	{
		while(true)
		{
			if (ind2 == SZ(a)) break;
			if (a[ind2].first <= a[i].second)
			{
				ind2++;
				continue;
			}
			break;
		}
		while(true)
		{
			if (ind == SZ(a)) break;
			if (a[ind].first - (ind - i - 1) <= a[i].second)
			{
				ind++;
				continue;
			}
			break;
		}

		res = max(res, ind - i);
	}

	cout<<res<<endl;

}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>

using namespace std;
typedef long long ll;
typedef pair<int,int> Pi;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) x.begin(), x.end()

char S[1000010], T[1000010];
int N;
void solve(){
	scanf("%d%s%s", &N, S+1, T+1);
	if(!strcmp(S+1, T+1)){
		printf("0");
		return;
	}
	int que[1000010], *fr = que, *re = que, ans = 0;
	for(int i=N, j=N;i>=1;i--)if(T[i] != T[i-1]){
		j = min(i, j);
		while(j > 0 && S[j] != T[i])--j;
		if(j == 0){
			printf("-1");
			return;
		}
		while(re < fr && *re - (fr-re) >= i)re++;
		if(i != j){
			*fr++ = j;
			ans = max(ans, (int)(fr - re));
		}
	}
	printf("%d", ans + 1);
}

int main(){
	int Tc = 1; //scanf("%d\n", &Tc);
	for(int tc=1;tc<=Tc;tc++){
		solve();
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const ll INF = 1023456789;

#define REP(i,n)	for(int i=0;i<n;++i)
#define REPR(i,n)	for(int i=n-1;i>=0;--i)
#define FOR(i,s,n)	for(int i=s;i<n;++i)
#define FORR(i,s,n)	for(int i=n-1;i>=s;--i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define F			first
#define S			second

int main(int argc, char **argv) {
	string s;
	cin >> s;
	bool f = true;
	f &= (s[0] == 'A');
	ll c = 0;
	REP(i, s.length()) if (s[i] >= 'a' && s[i] <= 'z') ++c;
	f &= (c == s.length() - 2);
	if (f) FOR(i, 2, s.length()-1) if (s[i] == 'C') {
		cout << "AC" << endl;
		return 0;
	}
	cout << "WA" << endl;
	return 0;
}

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

void solve(const string& s) {
  for (int i = 0, j = 1; j < s.size(); ++i, ++j) {
    if (s[i] == s[j]) {
      cout << (i + 1) << " " << (j + 1) << "\n";
      return;
    }
  }
  for (int i = 0, j = 2; j < s.size(); ++i, ++j) {
    if (s[i] == s[j]) {
      cout << (i + 1) << " " << (j + 1) << "\n";
      return;
    }
  }
  cout << "-1 -1\n";
}

int main() {
  string s;
  cin >> s;
  solve(s);
  return 0;
}


#include<iostream>

using namespace std;

const int MAXN = 1005, INF = 2e9;
int d[MAXN][MAXN];

int main()
{
	int n, m;
	cin >> n >> m;
	for(int i = 0; i < n; i++)
		for(int j = 0; j < n; j++)
			d[i][j] = INF;
	for(int i = 0; i < n; i++)
		d[i][i] = 0;
	for(int i = 0; i < m; i++)
	{
		int x, y, w;
		cin >> x >> y >> w;
		d[x][y] = w;
	}
	for(int k = 0; k < n; k++)
		for(int i = 0; i < n; i++)
			for(int j = 0; j < n; j++)
				if(d[i][k] < INF && d[k][j] < INF)
					d[i][j] = min(1ll * d[i][j], 1ll * d[i][k] + d[k][j]);
	for(int i = 0; i < n; i++)
		if(d[i][i] < 0)
		{
			cout << "NEGATIVE CYCLE" << endl;
			return 0;
		}
	for(int i = 0; i < n; i++, cout << endl)
		for(int j = 0; j < n; j++)
		{
			if(d[i][j] == INF)
				cout << "INF";
			else
				cout << d[i][j];
			if(j < n - 1)
				cout << ' ';
		}
	return 0;
}

#include <bits/stdc++.h>
#define debug(...) fprintf(stderr, __VA_ARGS__)

using namespace std;
const int N = 605;

inline int input() {
	int x; char ch; while (!isdigit(ch = getchar()));
	for (x = ch ^ 48; isdigit(ch = getchar()); x = x * 10 + (ch ^ 48));
	return x;
}

inline void chkmin(int &x, int y) { x = x < y ? x : y; }
template <class T> T sqr(T x) { return x * x; }

int n, m, D1, D2;
int ansx[N * N], ansy[N * N], tot;
bool col[N][N];

void work(int D) {
	int tmp = 0;
	while(D % 4 == 0) D >>= 2, ++tmp;
	if (D % 4 == 3) return void();
	if (D % 4 == 1) {
		for (int x = 0; x <= n; ++x)
			for (int y = 0; y <= n; ++y)
				if (((x >> tmp) + (y >> tmp)) & 1) col[x][y] = true;
	}
	if (D % 4 == 2) {
		for (int x = 0; x <= n; ++x)
			for (int y = 0; y <= n; ++y)
				if ((x >> tmp) & 1) col[x][y] = true;
	}
}

int main() {
#ifdef local
	freopen("in", "r", stdin);
	freopen("out", "w", stdout);
//	freopen("log", "w", stderr);
#endif
	ios::sync_with_stdio(false);

	cin >> n >> D1 >> D2;
	m = n, n = n * 2 - 1;

	work(D1), work(D2);

	for (int x = 0; x <= n; ++x)
		for (int y = 0; y <= n; ++y) {
			if (!col[x][y]) ansx[++tot] = x, ansy[tot] = y;
			if (tot == m * m) goto Get;
		}
Get:;

	for (int i = 1; i <= tot; ++i)
		printf("%d %d\n", ansx[i], ansy[i]);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int mod=1e9+7;
const int INF=1001001001;

int dp[105][10];
int main() {
  int H,W,K;
  cin>>H>>W>>K;

  dp[0][0]=1;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(dp[i][j]==0){continue;}
      for(int s=0;s<(1<<W-1);s++){
        vector<int>t(W-1);
        for(int k=0;k<W-1;k++){
          if((s>>k)&1){t[k]=1;}
        }
        bool ok=true;
        for(int k=0;k<W-2;k++){
          if(t[k]==1&&t[k+1]==1){ok=false;}
        }
        if(ok){
          if(j<W-1&&t[j]){(dp[i+1][j+1]+=dp[i][j])%=mod;}
          else if(j>0&&t[j-1]){(dp[i+1][j-1]+=dp[i][j])%=mod;}
          else{(dp[i+1][j]+=dp[i][j])%=mod;}
        }
      }
    }
  }

  cout<<dp[H][K-1]<<endl;
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,n,j) for(int i=(j);i<(n);++i)
#define ssort(n) sort((n).begin(),(n).end())
#define rsort(n) sort((n).begin(),(n).end(),greater<int>())
using ll=long long;
using ld=long double;
typedef pair<int,int> P;
typedef pair<P,int> COST;
#define repl(i,n) for(ll i=0;i<(n);++i)
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
using Graf=vector<vector<int>>;
#define MAX 10000000

int main()
{
    string s;
    cin >> s;
    if(s=="SUN"){
        cout << 7 << endl;
    }
    else if(s=="MON"){
        cout << 6 << endl;
    }
    else if(s=="TUE"){
        cout << 5 << endl;
    }
    else if(s=="WED"){
        cout << 4 << endl;
    }
    else if(s=="THU"){
        cout << 3 << endl;
    }
    else if(s=="FRI"){
        cout << 2 << endl;
    }
    else if(s=="SAT"){
        cout << 1 << endl;
    }
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;

  if ((A + B) > (C + D)) {
    cout << "Left" <<endl;
  }

  if ((A + B) == (C + D)) {
    cout << "Balanced" <<endl;
  }

  if ((A + B) < (C + D)) {
    cout << "Right" <<endl;
  }
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll, ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define ppi pair<pii,int>
#define pip pair<int,pii>
#define pdd pair<double, double>
#define f first
#define s second
#define MOD 1000000007
#define mkp make_pair
#define M_PI 3.14159265358979323846
#define FOR(i,l,r) for (int i=l;i<=r;i++)
#define LOR(i,l,r) for (ll i=l;i<=r;i++)
#define FORD(i,r,l) for (int i=r;i>=l;i--)
#define LORD(i,r,l) for (ll i=r;i>=l;i--)
#define INF 1000000000
#define CL(x) memset(x,0,sizeof(x))
#define DEB(x) cout << #x << " : " << x << '\n'
#define ALL(x) x.begin(), x.end()
#define SZ(x) x.size()
#define UI(x) (int)(x-'A')
#define LI(x) (int)(x-'a')
typedef long long ll;

#define MXN 500005
int N,A[MXN];
map<pii,ll> DP;
//for x|x specially
ll psum[MXN];
map<int,ll> lsta;
map<int,int> lstp;
//===
ll Ans;
int xb;

ll modexp(ll x, ll y)
{
    ll Pow = x%MOD, rtn = 1;
    while(y)
    {
        if(y&1)rtn=(rtn*Pow)%MOD;
        y>>=1;
        Pow=(Pow*Pow)%MOD;
    }
    return rtn;
}

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

    cin>>N;
    FOR(i,1,N)
    {
        cin>>A[i];
        xb^=A[i];
    }
    int xf=0;
    Ans=1;
    FOR(i,1,N-1)
    {
        xf^=A[i];
        xb^=A[i];
        //0|0 case
        psum[i]=psum[i-1]+( xf==0 && xb==0 );

        ll za[4];
        za[1]=DP[mkp(xb?xb:xf,1)];
        za[2]=DP[mkp(xb?xb:xf,2)];
        za[3]=DP[mkp(xb,3)];

        //(even x)|x case
        if( xf==0 && xb!=0 )
        {
            Ans=(Ans+za[2])%MOD;
            DP[mkp(xb,1)]=(za[1]+za[2])%MOD;
        }
        //(odd x)|0 case
        if( xf!=0 && xb==0 )
        {
            DP[mkp(xf,2)]=(za[1]+za[2]+1)%MOD;
        }
        //(odd x)|x case
        if( xf==xb && xf )
        {
            if( lstp.find(xf)!=lstp.end() )
            {
                int lp = lstp[xf];
                ll la = lsta[xf];
                ll na = (la+za[3]*(psum[i-1]-psum[lp]))%MOD;
                Ans=(Ans+na)%MOD;

                lsta[xf]=na;
                DP[mkp(xf,3)]=(za[3]+na)%MOD;
            }
            else
            {
                DP[mkp(xf,3)]=lsta[xf]=1;
                Ans=(Ans+1)%MOD;
            }
            lstp[xf]=i;
        }
    }
    if(psum[N-1])
    {
        ll Zans=modexp(2,psum[N-1]);
        Ans=(Ans+Zans-1)%MOD;
    }
    cout<<Ans<<'\n';

    return 0;
}

/*
3
1 2 3

5
0 0 0 0 0
*/

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
typedef long long ll;
const ll MOD=998244353;
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; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
//---------------------------------------------------------------------------------------------------

int main(void){
    // Your code here!
    vector<int> d;
    int n;cin >> n;
    d.resize(n);
    vector<int> v(n,0);
    rep(i,n) {
        cin >> d[i];
        v[d[i]]++;
    }
    if (d[0] != 0) {
        cout << 0 << endl;
        return 0;
    }
    rep(i,n) {
        if(i != 0 && d[i] ==0) {
            cout << 0 << endl;
            return 0;
        }
    }

    ll ans = 1;
    int ma = 0;
    rep(i,n) chmax(ma,d[i]);

    FOR(i,2,ma) {
        ll ex = v[i-1];
        rep(j,v[i]) {
            ans *= ex;
            ans %= MOD;
        }
    }
    cout << ans << endl;
}


#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll N, M;
    cin >> N >> M;
    vec s(M), c(M);
    REP(i,0,M) {
        cin >> s[i] >> c[i];
        --s[i];
    }

    ll d = 1;
    bool f = true;
    REP(i,0,N) d *= 10;
    REP(i,N==1?0:d/10,d) {
        string S = to_string(i);
        f = true;
        REP(j,0,M) {
            if(!(s[j] < SZ(S) && S[s[j]]-'0' == c[j])) {
                f = false;
                break;
            }
        }
        if(f) {
            PR(i);
            break;
        }
    }
    if(!f) PR(-1);

    return 0;
}

/*

*/

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

#define int long long

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

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

void solve() {
  int n, m;
  cin >> n >> m;
  vector<char> res(n, 0);
  for (int i = 1; i <= m; i++) {
    int s; char c;
    cin >> s >> c;
    s--;
    if (res[s] == 0) res[s] = c;
    else if (res[s] != c) {
      cout << -1 << '\n';
      return;
    }
  }
  if (n > 1) {
    if (res[0] == '0') {
      cout << -1 << '\n';
      return;
    }
    if (res[0] == 0) {
      res[0] = '1';
    }
  }
  for (auto &i : res) {
    if (i == 0) cout << '0';
    else cout << i;
  }
  cout << '\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--) solve();
}


#include <stdio.h>
int main(){
	int m,a,b,x,y,r,g,i;
	for(;scanf("%d%d%d%d",&m,&a,&b,&x)>3;){
		for(g=0,i=1;i<m;i++){
			scanf("%d",&y);
			if(a<=i&&i<=b && x-y>=g)g=x-y,r=i;
			x=y;
		}
		printf("%d\n",r);
	}
	return 0;
}

#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main() {
	int m, nmin, nmax;
	while (cin >> m >> nmin >> nmax) {
		if (m == 0 && nmin == 0 && nmax == 0) {
			break;
		}
		vector<int> d(m);
		for (int i = 0; i < m; i++) {
			cin >> d[i];
		}
		int MAX = d[nmin-1]-d[nmin];
		int maxn = nmin;
		for (int i = nmin-1; i <= nmax-1; i++) {
			int mm = d[i]-d[i+1];
			if (mm >= MAX) {
				MAX = mm;
				maxn = i+1;
			}
			//cout << MAX << ' ' << maxn << endl;
		}
		cout << maxn << endl;
	}
	return 0;
}


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

#include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
	return os << "(" << x.first << "," << x.second << ")";
}
typedef long long ll;
typedef long double ld;
int main() {
	int n, k;
	scanf("%d%d", &n, &k);
	vector<int> A(n);
	for (int i = 0; i < n; ++i) scanf("%d", &A[i]);
	for (int i = 0; i < k; ++i) {
		vector<int> D(n + 1);
		for (int j = 0; j < n; ++j) {
			D[max(0, j - A[j])]++;
			D[min(n, j + A[j] + 1)]--;
		}
		bool no = false;
		for (int i = 0; i < n; ++i) {
			if (i) A[i] = A[i - 1];
			else A[i] = 0;
			A[i] += D[i];
			if (A[i] < n) no = true;
		}
		if (!no) break;
	}
	for (int i = 0; i < n; ++i) printf("%d ", A[i]);
}


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

int main(){
  int N,L;
  cin>>N>>L;
  int A[N];
  for(int i=0;i<N;i++){
    A[i]=L+i;
  }
  int sum=0;
  if(L>=0){
    for(int i=1;i<N;i++){
      sum+=A[i];
    }
  }else if(L<=-N){
    for(int i=0;i<N-1;i++){
      sum+=A[i];
    }
    }else{
      for(int i=0;i<N;i++){
        sum+=A[i];
      }
  }
  cout<<sum<<endl;
}

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

#define ll long long

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

vector<pair<ll, ll> > prime_factorize(ll n) {
    vector<pair<ll,ll>> res;
    for (ll a = 2; a * a <= n; ++a) {
        if (n % a != 0) continue;
        ll ex = 0; // 指数

        // 割れる限り割り続ける
        while (n % a == 0) {
            ++ex;
            n /= a;
        }

        // その結果を push
        res.push_back({a, ex});
    }

    // 最後に残った数について
    if (n != 1) res.push_back({n, 1});
    return res;
}

int main() {
  ll A, B;
  cin >> A >> B;

  ll g = GCD(max(A, B), min(A,B));

  vector<pair<ll,ll>> vec_f = prime_factorize(g);

  cout << vec_f.size() + 1 << endl;

}


#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Map = map<string,ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;

int main(){
    ll N;
    cin >> N;
    vector<double> A(N,0);
    for(ll i=0;i<N;i++){
        cin>>A[i]
    ;}
    sort(A.begin(), A.end());
    ll ans=0;
    for(ll i=N-1;i>=1;i--){
        for(ll j=0;j<=40;j++){
            if(upper_bound(A.begin(), A.end()-(N-i), (1<<j)-A[i])!=lower_bound(A.begin(), A.end()-(N-i), (1<<j)-A[i]))
            {*lower_bound(A.begin(), A.end()-(N-i), (1<<j)-A[i])-=0.0000001;ans++;break;}
        }
    ;}
    cout<<ans<<endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long i64;
const int N = 1e5+5;
int n, m, v, p, a[N], ans; i64 s[N];
int main()
{
    scanf("%d%d%d%d", &n, &m, &v, &p), ans = p;
    for(int i = 1; i <= n; ++i) scanf("%d", a+i);
    sort(a+1, a+1+n, greater<int>());
    for(int i = 1; i <= n; ++i) s[i] = s[i-1]+a[i];
    for(int i = p+1; i <= n&&a[i]+m >= a[p]; ++i)
        if((i64)m*v <= (p-1ll)*m+(n-i+1ll)*m+i64(i-p)*(a[i]+m)-(s[i-1]-s[p-1])) ++ans; else break;
    printf("%d\n", ans);
    return 0;
}


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

int main() {
  int k,x;
  cin >> k >> x;
  x = x-k+1;
  rep(i,0,2*k-1){
    cout << x+i;
    if(i != 2*k-2) cout << " ";
    else cout << "" << endl;
  }
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
#define INF 1000000000
#define MOD 1000000007

void solve() {
    string s;
    ll n, ans;
    cin >> n >> s;
    vi r, g;
    for (int i = 0; i < n; ++i) {
        if (s[i] == 'R')
            r.push_back(i);
        else if (s[i] == 'G')
            g.push_back(i);
    }
    ans = (ll)r.size() * (ll)g.size() * (n - (ll)r.size() - (ll)g.size());
    for (auto &i : r) {
        for (auto &j : g) {
            int k1 = 2 * i - j, k2 = 2 * j - i, k3 = (i + j) / 2;
            if (k1 >= 0 && k1 < n && s[k1] == 'B')
                --ans;
            if (k2 >= 0 && k2 < n && s[k2] == 'B')
                --ans;
            if ((i + j) % 2 == 0 && s[k3] == 'B')
                --ans;
        }
    }
    cout << ans << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    int t = 1;
    // cin >> t;
    while (t--)
        solve();
    return 0;
}