#include<bits/stdc++.h>
using namespace std;
inline int read(){
    int res=0;
    char c;
    bool zf=0;
    while(((c=getchar())<'0'||c>'9')&&c!= '-');
    if(c=='-')zf=1;
    else res=c-'0';
    while((c=getchar())>='0'&&c<='9')res=(res<<3)+(res<<1)+c-'0';
    if(zf)return -res;
    return res;
}
const int maxn=1e5+5;
int v[maxn];
int p[maxn],r;
int f[maxn];
signed main(){
	int n=read();
	f[1]=1;
	for(register int i=2;i<=n;++i){
		if(!v[i]){
			p[++r]=i,f[i]=2;
		}
		for(register int j=1;j<=r&&i*p[j]<=n;++j){
			v[i*p[j]]=1,f[i*p[j]]=f[i]+1;
			if(i%p[j]==0){
				break;
			}
		}
	}
	for(register int i=1;i<=n;++i){
		printf("%d ",f[i]);
	}
	puts("");
	return 0;
}

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

typedef int_fast32_t int32;
typedef int_fast64_t int64;

const int32 inf = 1e9+7;
const int32 MOD = 1000000007;
const int64 llinf = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define all(obj) (obj).begin(),(obj).end()
#define rall(obj) (obj).rbegin(),(obj).rend()
#define fi first
#define se second
#define pb(a) push_back(a)
typedef pair<int32,int32> pii;
typedef pair<int64,int64> pll;

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

int32 n,m;
vector<vector<pii>> uc;
vector<int32> ans;

void dfs(int v, int p = -1, int pc = -1, bool selected = true){
  if(selected){
    if(pc == 1){
      ans[v] = 2;
    }else{
      ans[v] = 1;
    }
  }else{
    ans[v] = pc;
  }
  for(auto [u,c] : uc[v]){
    if(ans[u] !=-1)continue;
    dfs(u,v,c,ans[v] == c);
  }
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> m;
  uc.resize(n);
  REP(i,m){
    int32 u,v,c;
    cin >> u >> v >> c;
    --u;--v;
    uc[v].emplace_back(u,c);
    uc[u].emplace_back(v,c);
  }

  ans.resize(n,-1);
  dfs(0);
  REP(i,n)ANS(ans[i]);
  return 0;
}


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

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

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

void run() {
  i64 n, m;
  cin >> n >> m;
  vi64 hs(n), ws(m);
  rep(i, 0, n) { cin >> hs[i]; }
  rep(i, 0, m) { cin >> ws[i]; }
  sort(begin(hs), end(hs));
  sort(begin(ws), end(ws));
  hs.push_back(numeric_limits<i64>::max());
  vi64 rsum(n + 1);
  rsum[n] = 0;
  for (i64 i{n - 2}; - 1 < i; i -= 2) {
    rsum[i] = hs[i + 1] - hs[i] + rsum[i + 2];
  }
  i64 ret{numeric_limits<i64>::max()}, iw{0}, lsum{0};
  for (i64 ih{0}; ih < n; ih += 2) {
    i64 cut_min{numeric_limits<i64>::max()};
    for (; iw < m; ++iw) {
      i64 cut{lsum + abs(hs[ih] - ws[iw]) + rsum[ih + 1]};
      if (cut < cut_min) {
        cut_min = cut;
      } else if (cut_min < cut) {
        --iw;
        break;
      }
    }
    iw = min(iw, m - 1);
    ret = min(ret, cut_min);
    lsum += hs[ih + 1] - hs[ih];
  }
  cout << ret << endl;
}

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

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=(n)-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,0,1,-1,-1};
const ll dx[8]={0,1,0,-1,0,-1,1,-1};
template <typename T> inline bool chmax(T &a, T b) {
  return ((a < b) ? (a = b, true) : (false));
}
template <typename T> inline bool chmin(T &a, T b) {
  return ((a > b) ? (a = b, true) : (false));
}

int main(){
  ll n;cin >> n;
  vl a(n),b(n),c(n);
  rep(i,n){
    cin >> a[i];a[i]--;
  }
  rep(i,n){
    cin >> b[i];b[i]--;
  }
  rep(i,n)cin >> c[i],c[i]--;
  rep(i,n)c[i]=b[c[i]];
  map<ll,ll> mp;
  rep(i,n)mp[a[i]]++;
  ll ans=0;
  rep(i,n){
    ans+=mp[c[i]];
  }
  cout << ans <<endl;
}


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

using namespace std;

const int N = 2e5 + 8;
const int K = 301;
const int MOD = 998244353;

int add(int a, int b) {
    if (a + b < MOD) {
        return a + b;
    }
    return a + b - MOD;
}

int sub(int a, int b) {
    if (a >= b) {
        return a - b;
    }
    return a - b + MOD;
}

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

int binpow(int a, int b) {
    int res = 1;
    while (b) {
        if (b & 1) res = mul(res, a);
        a = mul(a, a);
        b /= 2;
    }
    return res;
}

int divv(int a, int b) {
    return mul(a, binpow(b, MOD - 2));
}

int a[N];
int s[K];
int ans[K];
int C[K][K];

void init() {
    for (int i = 0; i < K; i++) {
        C[i][0] = 1;
        for (int j = 1; j <= i; j++) {
            C[i][j] = add(C[i - 1][j], C[i - 1][j - 1]);
        }
    }
}

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

    init();

    int n, k;
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        int c = 1;
        for (int j = 0; j < K; j++) {
            s[j] = add(s[j], c);
            c = mul(c, a[i]);
        }
    }
    for (int i = 0; i < K; i++) {
        for (int j = 0; i + j < K; j++) {
            int S = mul(s[i], s[j]);
            S = sub(S, s[i + j]);
            S = divv(S, 2);
            ans[i + j] = add(ans[i + j], mul(C[i + j][j], S));
        }
    }
    for (int i = 1; i <= k; i++) {
        cout << ans[i] << '\n';
    }
}

#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb emplace_back
#define mp make_pair
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define run ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0);
#define mod 1000000007
#define decimal(n,k) cout<<fixed<<setprecision(k)<<n<<endl
#define LL_MAX LLONG_MAX
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
int exp(int x,int y){int res=1;x=x%mod;while(y>0){if(y&1)res=(res*x)%mod;y=y>>1;x=(x*x)%mod;}return res;}
int modinv(int x){return exp(x,mod-2);}
int add(int a,int b){a%=mod,b%=mod;a=((a+b)%mod+mod)%mod;return a;}
int sub(int a,int b){a%=mod,b%=mod;a=((a-b)%mod+mod)%mod;return a;}
int mul(int a,int b){a%=mod,b%=mod;a=((a*b)%mod+mod)%mod;return a;}
int gcd(int a, int b){if (b == 0)return a; return gcd(b, a % b);}
int log2n( int n){ return (n > 1) ? 1 + log2n(n / 2) : 0;}
int fac[1000009];int ncr_mod(int n,int k){int ans=fac[n];ans*=modinv(fac[k]);ans%=mod;ans*=modinv(fac[n-k]);ans%=mod;return ans;}
vector<int>v_prime;void Sieve(int n){bool prime[n + 1];memset(prime,true,sizeof(prime));for (int p = 2; p*p <=n;p++){if(prime[p] ==true) {for(int i = p*p; i<= n; i += p)prime[i]=false;}}for(int p = 2;p<= n;p++)if (prime[p])v_prime.pb(p);}
vector<int>v_factor;void factor(int n){ for (int i=1; i<=sqrt(n); i++) {if (n%i == 0) {if (n/i == i) v_factor.pb(i);else { v_factor.pb(i),v_factor.pb(n/i);};} } sort(all(v_factor)); }
void out(vector<int>&a){for(int i=0;i<a.size();i++) cout<<a[i]<<" "; }
void sout(set<int>s){for(auto it=s.begin();it!=s.end();++it)cout<<*it<<" ";  cout<<endl;}
void mout(map<int,int>mm){for(auto it=mm.begin();it!=mm.end();++it) cout<<it->fi<<" "<<it->se<<endl;}
int power(int x, int y){int temp;if( y == 0)return 1; temp = power(x, y / 2);if (y % 2 == 0) return temp * temp;else return x * temp * temp;}

// s.top().second;

signed main()
{

      run;

/*
open for mod factorial

     fac[0]=1;
      for(int i=1;i<1000009;i++)
      {
          fac[i]=mul(fac[i-1],i);

      }
*/

/*
  for sieve open this and use v_prime

          int pp=pow(10,6)+100000;
               Sieve(pp);
*/

 //   factor(n)  &&   USE v_factor For calculating factors

int  t=1;
//cin>>t;
while(t--)
{
             //  map<int,int>mp; // x.second-->frequency

             int  n,i,x,y,ok=0,sum=0,ans=0,j,k,cnt=0,m,c=0;
             int  h[100009]={0};

                  cin>>x>>y;

            vector<int>a(y,0),v,b(x,0);
           int  x1=-power(10,6);

            for(i=0;i<y;i++)
              {
                  a[i]=x1;
                  x1++;
                  sum+=a[i];

              }

              for(i=0;i<x-1;i++)
              {
                  b[i]=i+1;
                  sum+=b[i];
              }

              b[x-1]=abs(sum);
              out(a);

              out(b);

}
}


#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;}
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}
struct UnionFind{
    vl par,dist;
    UnionFind(int x){par.assign(x,-1); dist.assign(x,0);}
    ll find(ll x){return par[x]<0?x:find(par[x]);}
    ll depth(ll x){return par[x]<0?0:depth(par[x])+dist[x];}
    bool same(ll x,ll y){return find(x)==find(y);}
    ll size(ll x){return -par[find(x)];}
    ll diff(ll x,ll y){return same(x,y)?depth(x)-depth(y):LINF;}
    void unite(ll x,ll y,ll k=0){
        k+=depth(y); k-=depth(x); k=-k;
        x=find(x); y=find(y);
        if(x==y)return;
        if(size(x)<size(y)){swap(x,y);k=-k;}
        par[x]+=par[y]; par[y]=x; dist[y]=k;
    }
};
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin>>n;
	vd x(n),y(n);
	vector<tuple<double,ll,ll>> v;
	rep(i,n)cin>>x[i]>>y[i];
	rep(i,n){
		range(j,i+1,n){
			v.emplace_back(hypot(y[i]-y[j],x[i]-x[j]),i,j);
		}
		v.emplace_back(100-y[i],i,n);
		v.emplace_back(y[i]+100,i,n+1);
	}
	sort(all(v));
	UnionFind u(n+2);
	rep(i,v.size()){
		u.unite(get<1>(v[i]),get<2>(v[i]));
		if(u.same(n,n+1)){
			fcout(7)<<get<0>(v[i])/2<<endl;
			return 0;
		}
	}
}

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

ll gcd(ll a, ll b){
    ll m = max(a,b);
    ll n = min(a,b);
    if(n == 0) return m;
    else return gcd(n, m%n);
}

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

int main(){
    ll t;
    cin >> t;
    vector<ll> A(t);
    for(int i=0; i<t; i++){
        ll n,s,k;
        cin >> n >> s >> k;
        //sにkを足して行ってnの倍数になれば終わり
        k=k%n;
        ll d = gcd(k,n);
        if(d!=1){
            if(s%d!=0){
                A.at(i) = -1;
                continue;
            }
            else{
                k = k/d;
                n = n/d;
                s = s/d;
            }
        }
        // s + xk = 0(modn)
        // kの逆元を求める
        // nx + ky = 1
        ll x,y;
        ll g = extgcd(n,k,x,y);
        ll ans = -s*y;
        ans %= n;
        if(ans<0) ans+=n;
        A.at(i) = ans;
    }
    for(int i=0; i<t; i++){
        cout  << A.at(i) << endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
double k;
double a,b,c,d,s,p;
double f(double x)
{
	return -b/k+a;
}
int main()
{

    cin>>a>>b>>c>>d;
    b=-b;
    k=(b-d)/(a-c);
    s=f(0);
    printf("%.10lf",s);
	return 0;

}

#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
using namespace std;
int main()
{
    double x1,y1,x2,y2;
    cin >> x1 >> y1 >> x2 >> y2;
    double t = (((x1 * y2) + (x2 * y1))/(y1 + y2));
    cout <<fixed << setprecision(10) <<t << endl;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<iomanip>
#include <string>
#include <math.h>
using namespace std;
int main(){
    int x,y,z;
    cin>>x>>y>>z;
    for(int i=0;;i++){
        if(y*z<=x*i){
            cout<<i-1<<endl;
            break;
        }
    }
    return 0;
}

#include<bits/stdc++.h>
using ll = long long int;
using namespace std;
#define sync ios_base::sync_with_stdio(false); cin.tie(NULL)
using ld = long double;
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define mod 1000000007
#define F first
#define S second
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
//recursions\
#pragma comment(linker, "/stack:200000000")
//loops\
#pragma GCC optimize("unroll-loops")
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val)->(strictly less than val) *s.find_by_order(ind)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

vector<string> split(const string& s, char c) {
    vector<string> v; stringstream ss(s); string x;
    while (getline(ss, x, c)) v.push_back(x); return move(v);
}
template<typename T, typename... Args>
inline string arrStr(T arr, int n) {
    stringstream s; s << "[";
    for(int i = 0; i < n - 1; i++) s << arr[i] << ",";
    s << arr[n - 1] << "]";
    return s.str();
}
#define EVARS(args...) {__evars_begin(__LINE__); __evars(split(#args, ',').begin(), args);}
inline void __evars_begin(int line) { cerr << "#" << line << ": "; }
template<typename T> inline void __evars_out_var(vector<T> val) { cerr << arrStr(val, val.size()); }
template<typename T> inline void __evars_out_var(T* val) { cerr << arrStr(val, 10); }
template<typename T> inline void __evars_out_var(T val) { cerr << val; }
inline void __evars(vector<string>::iterator it) { cerr << endl; }
template<typename T, typename... Args>
inline void __evars(vector<string>::iterator it, T a, Args... args) {
    cerr << it->substr((*it)[0] == ' ', it->length()) << "=";
    __evars_out_var(a);
    cerr << "; ";
    __evars(++it, args...);
}
const int N = 1e6 + 5;

int main()
{
	sync;
	clock_t clk = clock();
    int x, y, z;
    cin >> x >> y >> z;
    int ans = (y * z) / x - ((y * z) % x == 0);
    cout << ans;

 	//cerr << '\n'<<"Time (in s): " << double(clock() - clk) * 1.0 / CLOCKS_PER_SEC << '\n';
}


//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define FIO ios_base::sync_with_stdio(false); cin.tie(0);
#define trav(x,a) for (auto& x: a)
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define case(t) cout << "Case #" << (t) << ": "
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define st first
#define nd second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int mod = 998244353;
const int inf = 1e9 + 7;
const int N = 1e6 + 5;
const ld eps = 1e-9;

template<class T> void read(T& x) { cin >> x; }
template<class X, class Y> void read(pair<X,Y>& a) { read(a.first), read(a.second); }
template<class T, size_t U> void read(array<T,U>& x) { for (int i = 0; i < U; i++) read(x[i]); }
template<class T> void read(vector<T>& x) { trav(y, x) read(y); }
template<class T, class... O> void read(T& x, O&... y) { read(x), read(y...); }

string to_string(const char& x) { return string(1,x); }
string to_string(const char*& x) { return (string)x; }
string to_string(const string& x) { return x; }
template<class T, class U> string to_string(const pair<T,U>& x) { return to_string(x.first) + " " + to_string(x.second); }
template<class T, size_t U> string to_string(const array<T,U>& x) { string ret = ""; for (int i = 0; i < U; i++) ret += (!i ? "" : " ") + to_string(x[i]); return ret; }
template<class T> string to_string(const vector<T>& x) { string ret = ""; bool f = 0; trav(y, x) ret += (!f ? "" : " ") + to_string(y), f = 1; return ret; }
template<class T> string to_string(const set<T>& x) { string ret = ""; bool f = 0; trav(y, x) ret += (!f ? "" : " ") + to_string(y), f = 1; return ret; }
void print() { cout << endl; }
template<class T> void pr(const T& x) { cout << to_string(x); }
template<class T, class... O> void print(const T& x, const O&... y) { pr(x); if (sizeof...(y)) pr(" "); print(y...); }

int inv[N], ifac[N], fac[N];

inline int add(int x, int y) { return x+y < mod ? x+y : x+y-mod; }
inline int sub(int x, int y) { return x-y >= 0 ? x-y : x-y+mod; }
inline int mul(int x, int y) { return x * 1ll * y % mod; }
template<class T, class... O> inline int add(T x, O... y) { return add(x, add(y...)); }
template<class T, class... O> inline int mul(T x, O... y) { return mul(x, mul(y...)); }
inline int norm(int x) { return x >= 0 ? (x < mod ? x : x-mod) : x+mod; }
inline int pw(int x, int y) {
  int r = 1;
  for (; y; x = mul(x, x), y /= 2)
    if (y & 1)
      r = mul(r, x);
  return r;
}
inline int inverse(int x) { return pw(x, mod-2); }
inline int ncr(int n, int k) {
  if (n < k || k < 0) return 0;
  if (n < N) return mul(fac[n], ifac[n-k], ifac[k]);
  int r = 1;
  for (int i = 1; i <= k; i++)
    r = mul(r, n-i+1, inv[i]);
  return r;
}

void precomputeInverse(int n) {
  inv[1] = ifac[0] = ifac[1] = fac[0] = fac[1] = 1;
  for (int i = 2; i < n; i++) {
    inv[i] = mod - mul(mod / i, inv[mod % i]);
    fac[i] = mul(fac[i-1], i);
    ifac[i] = mul(ifac[i-1], inv[i]);
  }
}

int dp[2][55][55 * 105];
int v[55];

int main() {
  FIO
  precomputeInverse(N);
  int n; read(n);
  vector<int> a(n); read(a);
  // int n = 100;
  // vector<int> a(n, 100);
  int ans = 0;
  int s = 0;
  for (int i: a) s += i;
  if (s & 1) {
    print(0);
    return 0;
  }
  s /= 2;
  dp[0][0][0] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= min(i, n / 2); j++) {
      for (int k = 0; k <= s; k++) {
        dp[i & 1][j][k] = dp[(i & 1)^1][j][k];
        if (j > 0 && k >= a[i-1])
          dp[i & 1][j][k] = add(dp[i & 1][j][k], dp[(i & 1)^1][j - 1][k - a[i-1]]);
      }
    }
  }
  for (int i = 1; i <= n / 2; i++)
    ans = add(ans, mul(1 + (2 * i != n), dp[n & 1][i][s], fac[i], fac[n-i]));
  print(ans);
}

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod = (int)1e9+7;
signed main(){
	cin.tie(nullptr)->sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int>arr(n+1);
	for(int i = 1; i<=n; i++){
		cin >> arr[i];
	}
	vector<vector<int>>dp(n+1,vector<int>(n+1));// current ans as we iterate through
	dp[1][0] = 1;
	// dp[i][j] is ans of currently being in ith subarray with sum of j under modulus of i
	vector<int>inc(n+1);//actual index of j modulus i is inc[i]+j; so index j holds the value of index j-inc[i]
	//each iteration you either slap the current number into a new subarray, or you continue current subarray
	for(int i = 2; i<=n; i++){

		for(int j = n-1; j>=1; j--){
			int realind = (j+0*arr[i]-inc[j])%j;realind+=j; realind%=j;
			int realind2 = (j+1-0*arr[i]-inc[j+1])%(j+1); realind2+=(j+1); realind2%=(j+1);
			dp[j+1][realind2]+=dp[j][realind];dp[j+1][realind2]%=mod;
		}
		for(int j = n; j>=1; j--){
			inc[j]+=arr[i]; inc[j]%=j;
		}
	}
	int ans = 0;
	for(int j = 1; j<=n; j++){
		for(int k = 0; k<j; k++){
			int idx = (j+k-inc[j])%j;
			if(k==0)ans+=dp[j][idx];
			ans%=mod;
			//cout << dp[j][idx] << " ";
		}
		//cout << "\n";
		}
	cout << ans << "\n";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (long long i = 0; i < (long long)(n); i++)
typedef long long  ll;
const long long MOD=1e9+7;
int main(){
    int n;
    cin>>n;
    n*=108;
    n/=100;
    if(n<206)cout<<"Yay!"<<endl;
    else if(n==206)cout<<"so-so"<<endl;
    else cout<<":("<<endl;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<pll> vpll;
typedef vector<bool> vbl;
typedef vector<vector<bool>> vvbl;

void INX(){}
template<typename Head, typename... Tail>
void INX(Head&& head, Tail&&... tail)
{
    cin >> head;
    INX(forward<Tail>(tail)...);
}
void OUTX(){}
template<typename Head, typename... Tail>
void OUTX(Head&& head, Tail&&... tail)
{
    cout << head << endl;
    OUTX(forward<Tail>(tail)...);
}

#define ADD emplace_back
#define MP make_pair
#define VVEC(type) vector<vector<type>>

//#define MOD 1000000007 // 10^9 + 7
//setprecision(10)

ll EuclideanAlgorithm(ll A, ll B)
{
    if(A > B) swap(A, B);

    ll r = 0;
    while(true)
    {
        r = B % A;
        if(r == 0)
        {
            return A; //このときのAが最大公約数
        }
        else
        {
            B = A;
            A = r;
        }
    }
}

ll modinv(ll a, ll m)
{
    ll b = m, u = 1, v = 0;
    while(b)
    {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }

    u %= m;
    if(u < 0) u += m;
    return u;
}

int main()
{
    ll T;
    INX(T);

    for (ll query = 0; query < T; query++)
    {
        ll N, S, K;
        INX(N, S, K);

        // S + Kx ≡ 0 mod N
        // Kx ≡ N - S mod N
        // A = K, B = N - S, M = N

        // Ax ≡ B mod M
        // d = gcd(A, B, M)
        // A = A / d, B = B / d, M = M / d
        // if gcd(A, M) != 1 then 解なし
        // else (if gcd(A, M) == 1) then x = A^(-1) * B

        ll A = K;
        ll B = N - S;
        ll M = N;

        ll d = EuclideanAlgorithm(EuclideanAlgorithm(A, B), M);
        A /= d;
        B /= d;
        M /= d;

        if(EuclideanAlgorithm(A, M) != 1)
        {
            OUTX(-1);
        }
        else
        {
            //Aの逆元とそこから答えを計算
            ll result = modinv(A, M) * B;
            result %= M;
            OUTX(result);
        }
    }

    return 0;
}


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

int main() {
  int a,N;
  string b;
  cin>>N;
  vector<pair<int, string>> p(N);
  for (int i = 0; i < N; i++) {
    cin>>b>>a;
    p.at(i)=make_pair(a,b);
  }
  sort(p.begin(), p.end());
//  tie(a,b) = data;
  cout<<p.at(N-2).second<<endl;
}

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

int main(){
  int a,b;
  cin>>a>>b;
  cout<<2*a+100-b<<endl;
}


#line 2 "header.hpp"

//%snippet.set('header')%
//%snippet.fold()%
#ifndef HEADER_H
#define HEADER_H

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

// varibable settings
template <class T> constexpr T inf = numeric_limits<T>::max() / 2.1;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define _rrep(i, n) rrepi(i, 0, n)
#define rrepi(i, a, b) for (ll i = (ll)((b)-1); i >= (ll)(a); --i)
#define r_rep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define each(i, a) for (auto &&i : a)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(...) make_tuple(__VA_ARGS__)
#define ub upper_bound
#define lb lower_bound
#define lpos(A, x) (lower_bound(all(A), x) - A.begin())
#define upos(A, x) (upper_bound(all(A), x) - A.begin())
template <class T, class U> inline void chmax(T &a, const U &b) { if ((a) < (b)) (a) = (b); }
template <class T, class U> inline void chmin(T &a, const U &b) { if ((a) > (b)) (a) = (b); }
template <typename X, typename T> auto make_table(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto make_table(X x, Y y, Z z, Zs... zs) { auto cont = make_table(y, z, zs...); return vector<decltype(cont)>(x, cont); }

template <class T> T cdiv(T a, T b){ assert(a >= 0 && b > 0); return (a+b-1)/b; }

#define is_in(x, a, b) ((a) <= (x) && (x) < (b))
#define uni(x) sort(all(x)); x.erase(unique(all(x)), x.end())
#define slice(l, r) substr(l, r - l)

typedef long long ll;
typedef long double ld;
using vl = vector<ll>;
using vvl = vector<vl>;
using pll = pair<ll, ll>;

template <typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;
void check_input() { assert(cin.eof() == 0); int tmp; cin >> tmp; assert(cin.eof() == 1); }

#if defined(PCM) || defined(LOCAL)
#else
#define dump(...) ;
#define dump_1d(...) ;
#define dump_2d(...) ;
#define cerrendl ;
#endif

#endif /* HEADER_H */
//%snippet.end()%
#line 2 "solve.cpp"
template<class T=ll> using vec = vector<T>;
struct Fast { Fast() { std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

int solve() {
    ll n;cin>>n;
    dump(n);

    ll mul = 3;
    for(ll a = 1; mul < n; a++){
        ll rem = n - mul;
        dump(a, rem);
        int b = 0;
        while (rem % 5 == 0){
            rem /= 5;
            b++;
        }
        if (rem == 1 && b >= 1){
            cout << a << " " << b << endl;
            return 0;
        }
        mul *= 3;
    }
    cout << -1 << endl;

    return 0;
}

int main(){/*{{{*/
    solve();

    #if defined(PCM) || defined(LOCAL)
    check_input();
    #endif

    return 0;
}/*}}}*/

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

#define ffor(i, a, b) for (int i = a ; i <= (int) b ; i++)
#define rfor(i, a, b) for (int i = (int) a ; i >= b ; i--)

#define vec vector
#define PB push_back

#define MP make_pair
#define MT make_tuple
#define F first
#define S second

using ll = long long int; // watch out for overflows in your code
using pii = pair<int,int>;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void debug() { cout << "\n"; };
template <typename T, typename... Targs>
void debug(T t, Targs... args) {
    cout << t << " ";
    debug(args...);
}

template <typename T1, typename T2>
inline ostream& operator << (ostream& os, const pair<T1,T2>& p) {
    return os << "(" << p.F << ", " << p.S << ")";
}

template <typename T>
inline ostream& operator << (ostream& os, const vec<T>& v) {
    for(auto& t : v) {
        os << t << " ";
    }
    return os;
}

template <typename T>
inline ostream& operator << (ostream& os, const vec<vec<T>>& m) {
    for(auto& v : m) {
        for(auto& t : v) {
            os << t << " ";
        }
        os << "\n";
    }
    return os;
}

template <typename T>
inline ostream& operator << (ostream& os, const set<T>& v) {
    for(auto& t : v) {
        os << t << " ";
    }
    return os;
}

template <typename K, typename V>
inline ostream& operator << (ostream& os, const map<K,V>& m) {
    for(auto& p : m) {
        os << p.F << " -> " << p.S << "\n";
    }
    return os;
}

const ll INF = 9 * 1e18;

int N;
vec<ll> lo, hi;

ll dist(ll st, ll fn, ll x) {
    return abs(x-st) + abs(st-fn);
}

vec<vec<ll>> dp;

void compute_dp() {
    dp.assign(N+1, vec<ll>(2,0));
    ffor(c, 1, N) {
        if(lo[c] == lo[c-1] && hi[c] == hi[c-1]) {
            dp[c][0] = dp[c-1][0];
            dp[c][1] = dp[c-1][1];
        }
        else {
            dp[c][0] = min(dp[c-1][0] + dist(hi[c], lo[c], lo[c-1]), dp[c-1][1] + dist(hi[c], lo[c], hi[c-1]));
            dp[c][1] = min(dp[c-1][0] + dist(lo[c], hi[c], lo[c-1]), dp[c-1][1] + dist(lo[c], hi[c], hi[c-1]));
        }
        //debug("c=", c, "dp(c,0)=", dp[c][0], "dp(c,1)=", dp[c][1]);
    }
}

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

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

    cin >> N;
    lo.assign(N+1, INF);
    hi.assign(N+1, -INF);
    lo[0] = hi[0] = 0;
    ffor(i, 1, N) {
        ll x; int c;
        cin >> x >> c;
        lo[c] = min(lo[c], x);
        hi[c] = max(hi[c], x);
    }

    ffor(c, 1, N) {
        if(lo[c] == INF) lo[c] = lo[c-1];
        if(hi[c] == -INF) hi[c] = hi[c-1];
    }

    //debug("lo=", lo);
    //debug("hi=", hi);

    compute_dp();
    cout << min(dp[N][0] + abs(lo[N]), dp[N][1] + abs(hi[N])) << "\n";
}


/*
 * 答え見た
 * https://atcoder.jp/contests/keyence2021/submissions/19465975
 */
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define debug(x)      cerr << "L" << __LINE__ << ": " << #x << " = " << (x) << endl
#define debugvec(v)   rep(i, v.size()) cerr << "L" << __LINE__ << ": " << #v << "[" << i << "] = " << v[i] << endl;
#define debugvec2(v)  cerr << "L" << __LINE__ << ": " << #v << " = { "; rep(i, v.size()) cerr << v[i] << (i + 1 == v.size() ? "" : ", "); cerr << " }" << endl;
typedef long long ll;  /* 10^18 くらいまでいける */

int mod = 998244353;
char grid[5005][5005];
ll   dp[5005][5005];

// (x^y) % mod
long long modpow(long long x, long long y){
    if (y == 0) return 1;
    if (y % 2) return x * modpow(x, y - 1) % mod;
    long long res = modpow(x, y / 2);
    return res * res % mod;
}

int main(){
  ll h, w, k;
  cin >> h >> w >> k;
  rep(i, k){
	ll x, y;
	char c;
	cin >> x >> y >> c;
	x--; y--;
	grid[x][y] = c;
  }
  // 開始マスの初期値は 3^(h*w-k)
  dp[0][0] = modpow(3, h*w-k);
  ll div_three = modpow(3, mod-2);  // 1/3 を表す
  rep(i, h){
	rep(j, w){
	  // 空白マスの場合
	  // 2/3 を掛ける
	  if (!grid[i][j]){
		ll plus = (dp[i][j] * div_three) % mod;
		if (j + 1 != w)
		{
			dp[i][j + 1] += plus;
			dp[i][j + 1] %= mod;
		}
		if (i + 1 != h)
		{
			dp[i + 1][j] += plus;
			dp[i + 1][j] %= mod;
		}
		if (j + 1 != w)
		{
			dp[i][j + 1] += plus;
			dp[i][j + 1] %= mod;
		}
		if (i + 1 != h)
		{
			dp[i + 1][j] += plus;
			dp[i + 1][j] %= mod;
		}
	  }
	  else
	  {
	  	if (grid[i][j] == 'R')
	  	{
	  		if (j + 1 != w)
	  		{
	  			dp[i][j + 1] += dp[i][j];
	  			dp[i][j + 1] %= mod;
	  		}
	  	}
	  	if (grid[i][j] == 'D')
	  	{
	  		if (i + 1 != h)
	  		{
	  			dp[i + 1][j] += dp[i][j];
	  			dp[i + 1][j] %= mod;
	  		}
	  	}
	  	if (grid[i][j] == 'X')
	  	{
	  		if (j + 1 != w)
	  		{
	  			dp[i][j + 1] += dp[i][j];
	  			dp[i][j + 1] %= mod;
	  		}
	  		if (i + 1 != h)
	  		{
	  			dp[i + 1][j] += dp[i][j];
	  			dp[i + 1][j] %= mod;
	  		}
	  	}
	  }
	}
  }
  cout << dp[h - 1][w - 1] << endl;
}

#include <bits/stdc++.h>

#define int long long
using namespace std;

const int MAX = 5005, MOD = 998244353;
int m, n, k, f[MAX][MAX];
char a[MAX][MAX];

int mul(int x, int k) {
    if (k == 0)
        return 1;
    int tmp = mul(x, k / 2);
    if (k % 2 == 0)
        return tmp * tmp % MOD;
    return tmp * tmp % MOD * x % MOD;
}

int32_t main() {
#ifdef ACM
    freopen("input", "r", stdin);
#endif
    cin >> m >> n >> k;
    for (int i = 1; i <= m; i++)
        for (int j = 1; j <= n; j++)
            a[i][j] = '*';
    int x, y;
    char c;
    for (int i = 0; i < k; i++) {
        cin >> x >> y >> c;
        a[x][y] = c;
    }
    f[1][1] = 1;
    int rev3 = mul(3, MOD - 2);
    for (int i = 1; i <= m; i++)
        for (int j = 1; j <= n; j++) {
            if (i + j == 2)
                continue;
            if (i > 1) {
                if (a[i - 1][j] == 'D' || a[i - 1][j] == 'X')
                    f[i][j] = (f[i][j] + f[i - 1][j]) % MOD;
                if (a[i - 1][j] == '*')
                    f[i][j] = (f[i][j] + f[i - 1][j] * 2 % MOD * rev3) % MOD;
            }
            if (j > 1) {
                if (a[i][j - 1] == 'R' || a[i][j - 1] == 'X')
                    f[i][j] = (f[i][j] + f[i][j - 1]) % MOD;
                if (a[i][j - 1] == '*')
                    f[i][j] = (f[i][j] + f[i][j - 1] * 2 % MOD * rev3) % MOD;
            }
        }
    cout << f[m][n] * mul(3, m * n - k) % MOD;
}


																//  SMOKE SHISHA PLAY FIFA  //
#include<bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef long double ld;

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pll pair<ll,ll>
#define MP make_pair
#define ff first
#define ss second
#define PB push_back
#define mod 1000000007
#define lp(i,start,end) for(ll i=start;i<=end;i++)
#define deb1(a) cout<<#a<<" = "<<(a)<<endl;
#define deb2(a,b) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<endl;
#define deb3(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;

ll modu(ll a, ll b)
{
	ll ans =1;
	while(b>0)
	{
		if(b&1)
		ans = (ans*a)%mod;
		b/=2;
		a = (a*a)%mod;
	}
	return ans;
}

int main()
{
	fastio
	ll n,q;
	cin>>n>>q;
	vector<pair<ll,ll>>fi;
	fi.PB({0,0});
	lp(i,0,n-1){
		ll x;
		cin>>x;
		fi.PB({x,0});
	}
	sort(fi.begin(),fi.end());
	lp(i,1,n){
		fi[i].ss=fi[i-1].ss+fi[i].ff-fi[i-1].ff-1;
	}
	while(q--){
		ll y;
		cin>>y;
		ll l=0,r=n,m;
		while(l<r){
			m=(l+r)/2;
			if(fi[m].ss<y)
				l=m+1;
			else
				r=m;
		}
		//cout<<l<<" ";
		if(fi[l].ss>=y)
			l--;
		cout<<fi[l].ff+y-fi[l].ss<<endl;
	}
	return 0;
}

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define MAXN 110000
#define MOD
using namespace std;
int T,n,m;
LL a[MAXN];
int sum[MAXN];
LL work(LL x)
{
    LL L=1,R=2e18;

    while(L!=R)
    {
        LL mid=(L+R)/2;
        int loc = upper_bound(a+1,a+n+1,mid) - (a+1);
        if(mid-sum[loc] >= x)
            R=mid;
        else
            L=mid+1;
    }
    return L;
}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)scanf("%lld",&a[i]);

    sort(a+1,a+n+1);

    for(int i=1;i<=n;i++)
    {
        if(i==1||a[i]!=a[i-1])
            sum[i]++;
        sum[i]+=sum[i-1];
    }

    for(int i=1;i<=m;i++)
    {
        LL x;
        scanf("%lld",&x);
        printf("%lld\n",work(x));
    }
    return 0;
}


#include <bits/stdc++.h>
#define pii pair<int,int>
#define S second
#define F first
using namespace std;
const int maxn=2e5+5;
struct node{
    int x,id;
}a[maxn];
bool cmp(node a,node b){
    return a.x<b.x;
}
vector<pii> ans;
int n,b[maxn],p[maxn],Id[maxn],cnt;
main(){
    ios::sync_with_stdio(0),cin.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i].x,a[i].id=i;
    for(int i=1;i<=n;i++)cin>>b[i];
    for(int i=1;i<=n;i++){
        cin>>p[i],Id[p[i]]=i;
        if(b[p[i]]>=a[i].x&&p[i]!=i){
            cout<<-1;
            return 0;
        }
    }
    sort(a+1,a+n+1,cmp);
    for(int i=1;i<=n;i++){
        if(p[a[i].id]!=a[i].id){
            int now=a[i].id;
            ans.push_back({now,Id[now]});
            p[Id[now]]=p[now];
            Id[p[now]]=Id[now];
        }
    }
    cout<<ans.size()<<'\n';
    for(auto i:ans)
        cout<<i.F<<" "<<i.S<<'\n';
}


#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
template <typename X, typename Y> istream& operator>>(istream& is, pair<X, Y>& p) { return is >> p.first >> p.second; }
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, m, k;
    cin >> n >> m >> k;
    vector<int> a(k), max_consec(k);
    cin >> a;
    if(k > 0) {
        max_consec[0] = 1;
    }
    for(int i = 1; i < k; i++) {
        max_consec[i] = (a[i] == a[i - 1] + 1 ? max_consec[i - 1] : 0) + 1;
    }
    if(k > 0 and *max_element(max_consec.begin(), max_consec.end()) >= m) {
        cout << -1 << endl;
    } else {
        vector<pair<double, double>> E(n + m + 1);
        pair<double, double> psum = {0, 0};
        for(int i = n - 1; i >= 0; i--) {
            psum.first -= E[i + m + 1].first / m;
            psum.second -= E[i + m + 1].second / m;
            if(find(a.begin(), a.end(), i) != a.end()) {
                E[i] = {1.0, 0};
            } else {
                E[i] = {psum.first, psum.second + 1};
            }
            psum.first += E[i].first / m;
            psum.second += E[i].second / m;
        }
        cout << fixed << setprecision(3) << E[0].second / (1 - E[0].first) << endl;
    }
    return 0;
}

#include<bits/stdc++.h>

int main(){
    using namespace std;
    unsigned long N, M, K;
    cin >> N >> M >> K;
    const auto unavailable{[&N, &M, &K]{
        vector<unsigned long> unavailable(N + 1);
        vector<unsigned long> ban;
        for(unsigned long i{0}, a; i < K; ++i){
            cin >> a;
            unavailable[a] = 1;
            ban.push_back(a);
        }
        sort(begin(ban), end(ban));
        for(unsigned long i{M - 1}; i < K; ++i)if(ban[i - M + 1] + M - 1 == ban[i])exit(puts("-1") & 0);
        return unavailable;
    }()};
    const auto iteration{[&N, &M, &unavailable](long double x) -> long double {
        vector<long double> dp(N + 1);
        long double now{0}, c{0}, tmp{0}, y{0};
        for(unsigned long i{N}; i--; ){
            dp[i] = unavailable[i] ? x : now / M + 1;
            now += dp[i];
            now -= dp[min(N, i + M)];
        }
        return dp[0];
    }};
    constexpr long double eps{1e-10};
    cout << setprecision(15) << [&iteration]{
        auto tmp{[&iteration]{
            auto [l, r]{[&iteration]{
                if(2 > iteration(2))return make_pair(1.0L, 2.0L);
                long double r{2};
                while(r * r < iteration(r * r))r *= r;
                return make_pair(r, r * r);
            }()};
            for(unsigned long i{0}; i < 100; ++i){
                long double m{sqrt(l) * sqrt(r)};
                (m < iteration(m) ? l : r) = m;
            }
            return l;
        }()};
        for(unsigned long i{0}; i < 100; ++i)tmp = iteration(tmp);
        return tmp;
    }() << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define endl "\n"
ll mod=1000000007;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    IOS;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    //ll t;cin>>t;while(t--)
    {
        ll a,b,c,d,i,j,k,l,m,n,sum=0,temp=0,f=0,cnt=0;
        cin>>a>>b>>c>>d;
        k=(a*d)-(b*c);
        cout<<k<<endl;

    }
}

#include <vector>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <iostream>
#include <random>
#include <queue>
#include <algorithm>
#include <climits>
#include <map>
#include <set>
#include <stack>
#include <sstream>
#include <cstring>
#include <bitset>
#include <deque>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;

typedef vector<ld> vd;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<pd> vpd;
typedef vector<cd> vcd;
typedef vector<string> vs;

#define FOR(i, a, b) for (int i = a; i < b; i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = b; i > a; i--)
#define F0Rd(i, a) for (int i = a; i > -1; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define pob pop_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
#define que queue
#define pa pair
#define ex(m, i) m.find(i) != m.end()
#define nex(m, i) m.find(i) == m.end()

typedef vector<int> vi1;
typedef vector<vector<int>> vi2;
typedef vector<vector<vector<int>>> vi3;
typedef vector<vector<vector<vector<int>>>> vi4;
typedef vector<vector<vector<vector<vector<int>>>>> vi5;

typedef vector<ll> vl1;
typedef vector<vector<ll>> vl2;
typedef vector<vector<vector<ll>>> vl3;
typedef vector<vector<vector<vector<ll>>>> vl4;
typedef vector<vector<vector<vector<vector<ll>>>>> vl5;

#define uniq(x) x.resize(unique(all(x)) - x.begin())

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

const int MOD = 1000000007;
const ll INF = 1e18;
const int inf = 1e9;
const int MX = 100001; //check the limits, dummy
const double epsilon = 1e-12;
const int ds[4][2] = {
    {-1, 0},
    {1, 0},
    {0, -1},
    {0, 1}};

const int dds[8][2] = {
    {-1, 0},
    {1, 0},
    {0, -1},
    {0, 1},
    {-1, 1},
    {-1, -1},
    {1, -1},
    {1, 1},
};

const int ks[8][2] = {
    {2, 1},
    {2, -1},
    {-2, 1},
    {-2, -1},
    {1, 2},
    {1, -2},
    {-1, 2},
    {-1, -2}};

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

/*

 */

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

    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);

    int a, b, c ,d; cin >> a >> b >> c >> d;
    printf("%d",a*d-b*c);

    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(v) for (auto &e : v) { cin >> e; }
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

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

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

ll s2ll(string num, ll base = 10000) {
  ll ans = 0;
  size_t dot_idx = 0;
  bool is_negative = false;

  for (size_t idx = 0; idx < num.size(); ++idx) {
    if (num.at(idx) == '.') {
      dot_idx = idx;
      break;
    } else if (num.at(idx) == '-') {
      is_negative = true;
    } else {
      ans *= 10;
      ans += num.at(idx) - '0';
    }
  }
  ans *= base;

  if (dot_idx != 0) {
    for (int i = 1; base > 1; ++i) {
      if (dot_idx + i >= num.size()) break;
      base /= 10;
      ans += (num.at(dot_idx + i) - '0') * base;
    }
  }

  if (is_negative) ans *= -1;

  return ans;
}

ll floor_base(ll num, ll base = 10000) {
  return (num / base) * base;
}

int main() {
  IN(string, X);
  ll xl = abs(s2ll(X));
  IN(string, Y);
  ll yl = abs(s2ll(Y));
  IN(string, R);
  ll rl = s2ll(R);

  if (xl - rl <= 0) xl += floor_base(rl - xl + 10000);
  if (yl - rl <= 0) yl += floor_base(rl - yl + 10000);

  ll ans = 0;
  for (ll pos_x = floor_base(xl + rl); pos_x >= xl - rl; pos_x -= 10000) {
    ll len_x = pos_x - xl;
    ll len_y;
    if (len_x == 0) len_y = rl;
    else len_y = (ll)sqrtl(rl * rl - len_x * len_x);
    ans += (yl + len_y) / 10000 - (yl - len_y - 1) / 10000;
  }

  cout << ans << endl;

  return 0;
}

#include <bits/stdc++.h>

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

const int N = 2e5 + 5;
ll h[N], w;
ll l[N], r[N];
int n, m;
ll ans = LLONG_MAX;
set<int> st;

int main() {
    cin >> n >> m;
    for (int i = 0; i < n; ++i) {
        cin >> h[i];
    }
    sort(h, h + n);
    ll sum = 0;
    for (int i = 0; i < n; i += 2) {
        l[i] = sum;
        sum += abs(h[i + 1] - h[i]);
    }
    sum = 0;
    for (int i = n - 1; i >= 0; i -= 2) {
        r[i] = sum;
        sum += abs(h[i] - h[i - 1]);
    }
    for (int i = 0; i < m; ++i) {
        cin >> w;
        st.insert(w);
    }
    st.insert(INT_MAX);
    st.insert(INT_MIN);
    for (int i = 0; i < n; i += 2) {
        auto it = st.lower_bound(h[i]);
        ll mi = abs(*it - h[i]);
        --it;
        mi = min(mi, abs(*it - h[i]));

        ll res = l[i] + r[i] + mi;
        ans = min(ans, res);
    }
    cout << ans << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
#define SIZE(x) ll(x.size())
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; }
typedef long long ll;
const long long INF = 1LL << 60;
const long long MOD = 1000000007;
typedef pair<ll, ll> P;
int main()
{
    ll N, K;
    cin >> N >> K;
    vector<P> AB(N);
    rep(i, N) {
        ll a, b;
        cin >> a >> b;
        AB[i] = {a, b};
    }

    sort(all(AB));

    ll ans = 0;
    ll place = 0;
    rep(i, N) {
        ll diff = place + K;
        if (AB[i].first <= diff) {
            K -= (AB[i].first - place);
            place = AB[i].first;
            K += AB[i].second;
        }
        else {
            break;
        }
    }

    cout << place + K << endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long n,w;cin>>n>>w;
  long long a[200001]={},i,j,x,y,z;
  for(i=0;i<n;i++)
  {
    cin>>x>>y>>z;
    a[x]+=z;
    a[y]-=z;
  }
  for(i=1;i<=200000;i++)
  {
    a[i]+=a[i-1];

  }
  for(i=0;i<=200000;i++)
  {
       if(a[i]>w) break;
  }
  if(i==200001)
    cout<<"Yes\n";
  else
    cout<<"No\n";
  return 0;
}


using namespace std;
#include <cstdio>
#include <cstring>
#include <algorithm>
#define N 105
int n;
char s[N];
int e[N][N];
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;++i){
		scanf("%s",s+1);
		for (int j=1;j<=n;++j)
			e[i][j]=s[j]-'0';
	}
	for (int i=1;i<=n;++i)
		e[i][i]=1;
	for (int k=1;k<=n;++k)
		for (int i=1;i<=n;++i)
			for (int j=1;j<=n;++j)
				e[i][j]|=(e[i][k]&&e[k][j]);
	double ans=0;
	for (int i=1;i<=n;++i){
		int cnt=0;
		for (int j=1;j<=n;++j)
			if (e[j][i])
				cnt++;
		ans+=1.0/cnt;
	}
	printf("%.10lf\n",ans);
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define finf -0x3f3f3f3f
#define scNO printf("NO\n");
#define scNo printf("No\n");
#define scno printf("no\n");
#define sc0 printf("0\n");
#define sc1 printf("1\n");
#define	scf1 printf("-1\n");
#define	scz1 printf("1\n");
#define scYES printf("YES\n");
#define scyes printf("yes\n");
#define scYes printf("Yes\n");
#define scyes printf("yes\n");
#define ll long long
#define bug(a)  printf("%d \n ",a);
#define bugg(a,b)  printf("%d * %d \n",a,b);
#define buggg(a,b,c)  printf("%d * %d * %d \n",a,b,c);
#define bugggg(a,b,c,d)  printf("%d * %d * %d* %d\n",a,b,c,d);

const long N = 200000;
long prime[N] = {0},num_prime = 0;
int isNotPrime[N] = {1, 1};
int   read()  //read quickly
{
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
	return x*f;
}
void sushushai()
{
     	for(long i = 2 ; i < N ; i ++)
       	{
		if(! isNotPrime[i])
	 		prime[num_prime ++]=i;
		for(long j = 0 ; j < num_prime && i * prime[j] <  N ; j ++)
    		{
		      	isNotPrime[i * prime[j]] = 1;
	  		if( !(i % prime[j] ) )
				break;
		}
	}
}

void cheng(int *a,int c)		//High precision multiplication
{
	int jw=0;
	for(int i=1;i<=1000;i++)
	{
		a[i]=a[i]*c+jw;
		jw=a[i]/10;
		a[i]%=10;
	}
}
int cl(int x,int n) //High precision Division
{
	int s=0,i=0,w[101];
	while(x>=1)
	{
		w[++i]=x%n;
		x=x/n;
	}
	for(int j=i;j>=1;j--)
	   s=s*10+w[j];
	return s;
}
void pplus(int *a,int *c) //High precision addition
{
	int jw=0;
	for(int i=1;i<=1000;i++)
	{
		c[i]+=a[i]+jw;
		jw=c[i]/10;
		c[i]%=10;
	}
}
long long A(int n,int m) //(n)*(n-1)*(n-2)*....(n-m)
{
    long long ret=1;
    for(int i=0;i<m;++i)
    {
        ret*=(n-i);
       // ret%=mod;
    }
    return ret;
}

int c( int m,int n ) //c(5,1)==c(5,4)
{
	int a = 1,b = 1;
	n = min(n,m-n);
	if( n == 0 )
		return 1;
	for( int i = m ; i >=m-n+1 ; i--  )
		a = a*i;
	for( int i = 1 ; i <= n ; i++ )
		b = b*i;
	return a/b;
}

long long quickpow(long long a,long long b){

        long long ret=1;
        while(b){
            if(b&1){
                ret=ret*a;
                //%modd;
            }
            a=a*a;
            //%modd;
            b>>=1;
        }
        return ret;
}
const int MAXN=200005;
const long long mod=1e9+7;

int main()
{
    string s1;
    cin>>s1;
    int d1=s1.length();
    string s2;
    int flag=0;
    for(int i=0;i<=d1+1;i++){
        string s3=s2;
        s3+=s1;
        string s4=s3;
        reverse(s4.begin(),s4.end());
        if(s4==s3){
            scYes;
            flag=1;
            break;
        }
        s2+='0';
    }
    if(flag==0){
        scNo;
    }
}


#include <bits/stdc++.h>
using namespace std;
// BEGIN LIB
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef vector<vector<ll>> matrix;
typedef pair<ll, ll> pll;
// END LIB
void dfs(unordered_map<int, vi> &adj, vector<bool> &visited, int root, int &reached){
    if(visited[root])   return;
    reached++;
    visited[root]=true;
    for(auto next:adj[root])
        dfs(adj, visited, next, reached);
    return;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    int N, M, u, v, ans=0, INF=1000000;
    cin >> N >> M;
    vector<bool> visited(N);
    unordered_map<int, vi> adj;
    rep(i,0,M){
        cin >> u >> v;
        adj[u-1].push_back(v-1);
    }
    rep(i,0,N){
        int reached=0;
        rep(j,0,N) visited[j]=false;
        dfs(adj, visited, i, reached);
        ans+=reached;
    }
    cout <<ans<<endl;
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

template<typename T>
void debug(vector<T> item) {

	for (auto& i : item) {
		cout << i << " ";
	}

	cout << endl;
}

int64_t dfs(int n, vector<vector<int>>& neb, vector<bool>& vis) {
	if (vis[n]) return 0;

	vis[n] = true;

	int64_t ret = 1;

	for (int nxt : neb[n]) {
		if (!vis[nxt]) {
			ret += dfs(nxt, neb, vis);
		}
	}

	return ret;
}

int main() {
	int N, M;

	cin >> N >> M;
	vector<vector<int>> adj(N);

	for (int i = 0; i < M; ++i) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;

		adj[a].push_back(b);
	}

	int64_t ret = 0;

	for (int i = 0; i < N; ++i) {
		vector<bool> vis(N, false);
		ret += dfs(i, adj, vis);
	}

	cout << ret << endl;

	return 0;
}


#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
#include <random>
#include <cassert>
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using namespace std;
#define int long long
#define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define REPE(i, n) for (int (i)=0; (i) <= (n); (i)++)
#define CONTAINS_MAP(m, a) ((m).find((a)) != m.end())
#define CONTAINS_SET(m, a) ((m).find((a)) != m.end())
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; exit(0); }
void Yes() { cout << "Yes" << endl; exit(0); }
void No() { cout << "No" << endl; exit(0); }

int N, M;
int X[101];
vector<int>Y[20];
vector<int>Z[20];

int _dp[1000000];

int bit_count(ull v)
{
	ull count = (v & 0x5555555555555555ULL) + ((v >> 1ULL) & 0x5555555555555555ULL);
	count = (count & 0x3333333333333333ULL) + ((count >> 2ULL) & 0x3333333333333333ULL);
	count = (count & 0x0f0f0f0f0f0f0f0fULL) + ((count >> 4ULL) & 0x0f0f0f0f0f0f0f0fULL);
	count = (count & 0x00ff00ff00ff00ffULL) + ((count >> 8ULL) & 0x00ff00ff00ff00ffULL);
	count = (count & 0x0000ffff0000ffffULL) + ((count >> 16ULL) & 0x0000ffff0000ffffULL);
	return (int)((count & 0x00000000ffffffffULL) + ((count >> 32ULL) & 0x00000000ffffffffULL));
}

signed main()
{
	cin >> N >> M;
	//REP(i, M) cin >> X[i] >> Y[i] >> Z[i];
	REP(i, M)
	{
		int x, y, z;
		cin >> x >> y >> z;

		Y[x].push_back(y);
		Z[x].push_back(z);
	}

	int dp_max = (1LL << N);
	_dp[0] = 1;

	for (int i = 0; i < dp_max; i++)
	{
		int prev = _dp[i];

		for (int j = 0; j < N; j++)
		{
			int cur = (1LL << j);
			if ((i & cur) == 0)
			{
				int bitcnt = bit_count(i | cur);
				if (Y[bitcnt].size() == 0)
				{
					_dp[i | cur] += _dp[i];
				}
				else
				{
					bool is_valid = true;
					for (int k = 0; k < Y[bitcnt].size(); k++)
					{
						int y = Y[bitcnt][k];
						int z = Z[bitcnt][k];
						int mask = (1LL << y) - 1;
						int b = ((i | cur) & mask);
						int cnt = bit_count(b);
						if (cnt > z)
						{
							is_valid = false;
						}
					}
					if (is_valid)
					{
						_dp[i | cur] += _dp[i];
					}
				}
			}
			else
			{
			}
		}
	}

	cout << _dp[(1LL << N) - 1] << endl;
}

// Created at 2021/02/07 22:38
// {TODO}WA, {TODO}min, {TODO}diff
// goal: {TODO}min
#include <bits/stdc++.h>
//#include <atcoder/all>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define rep(i, n) for (lint i = 0, i##_len = n; i < i##_len; i++)
#define rep2(i, n) for (lint i = 1, i##_len = n; i <= i##_len; i++)
#define rep3(i, s, e) for (lint i = s, i##_len = e; i < i##_len; i++)
#define all(i) (i).begin(), (i).end()
#define print(s) cout << s << '\n';
#define print2(s1, s2) cout << s1 << ' ' << s2 << '\n';
#define mk_p make_pair
using namespace std;
//using namespace atcoder;
using lint = long long;
using pi = pair<int, int>;
using pl = pair<lint, lint>;
using vi = vector<int>;
using vl = vector<lint>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using qi = queue<int>;
using ql = queue<lint>;
constexpr int INF = 1 << 30;
constexpr lint INFl = 1LL << 62;

template<class T, class U>
istream &operator>>(istream &is, pair<T, U> &pair) {
    is >> pair.first >> pair.second;
    return is;
}

template<class T, class U>
ostream &operator<<(ostream &os, pair <T, U> &pair) {
    os << pair.first << " " << pair.second;
    return os;
}

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

template<class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << '[';
    for (auto v : vec) os << v << ',';
    os << ']';
    return os;
}

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

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    // cout << fixed << setprecision(15);
    /*----------------------------------------------------*/
    int n, m; cin >> n >> m;
    vvi g(n);
    rep(i, m) {
        int ai, bi; cin >> ai >> bi;
        ai--; bi--;
        g.at(ai).push_back(bi);
        g.at(bi).push_back(ai);
    }
    int k; cin >> k;
    vi c(k); cin >> c;
    for (int &ci : c) ci--;

    vvi dist(k, vi(k, INF));

    rep(i, k) {
        int start = c.at(i);
        vi disti(n, INF);
        qi q;
        disti.at(start) = 0;
        q.push(start);
        while (!q.empty()) {
            int now = q.front();
            q.pop();

            for (int next : g.at(now)) {
                if (chmin(disti.at(next), disti.at(now) + 1)) {
                    q.push(next);
                }
            }
        }
        rep(j, k) {
            dist.at(i).at(j) = disti.at(c.at(j));
        }
    }

//    print(g)
//    print(dist)

    vvi dp(1 << k, vi(k, INF));
    rep(start, k) {
        dp.at(1 << start).at(start) = 1;
    }
    rep(went, 1 << k) rep(now, k) {
        rep(next, k) {
            if (dist.at(now).at(next) != INF) {
                chmin(dp.at(went|1 << next).at(next), dp.at(went).at(now) + dist.at(now).at(next));
            }
        }
    }
    int ans = INF;
    rep(last, k) {
        chmin(ans, dp.back().at(last));
    }
    if (ans == INF) print(-1)
    else print(ans)
}
// break? continue?
// 時間? メモリ?
// map->bucket?
// あまり->非負か確認
// set? multiset?
// オーバーフロー確認(最大値を求める)
// 入力確認
// 型確認
// ループ回数確認(TLE)
// 小数の計算は避けよう(割り算)(0割りだめ！絶対！)
// Python を使っては?
// 擬似コードを作っては?
// 汚くてもok


#include <bits/stdc++.h>
using namespace std;
const long long INF = 10000000000000007;
const long long mod = 1000000007;
typedef long long ll;
typedef pair<int, int> P;

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

vector<int> table(2500);
vector<vector<int>> tile(2500);
vector<vector<bool>> seen(50,vector<bool>(50,0));
vector<vector<int>>point(50,vector<int>(50));

int now_x, now_y;
int si, sj;
// ll sum = 0;
vector<int> dx = {1, 0, -1, 0};
vector<int> dy = {0, 1, 0, -1};
vector<int>ans;

void solve(int now_x, int now_y) {
  int cnt = 0;
  while (1) {
    cnt++;
    if (cnt%20==0) {
      si = rand()%50;
      sj = rand()%50;
    }
    int num = table[now_x+now_y*50];
    for (int j = 0; j < tile[num].size(); j++) {
      int k = tile[num][j];
      seen[k/50][k%50] = 1;
    }

    int nx,ny,index=-1;
    ll ma = -1;
    for (int i = 0; i < 4; i++) {
      nx = now_x + dx[i];
      ny = now_y + dy[i];
      if (nx<0||nx>=50||ny<0||ny>=50) continue;
      if (seen[ny][nx]==1) continue;
      ll score = 0;
      if (i==0) score += 50-si;
      else if (i==1) score += 50-sj;
      else if (i==2) score += si;
      else if (i==3) score += sj;
      score += point[ny][nx] / 10;
      if (chmax(ma, score)) {
        index = i;
      }
    }
    if (index==-1) break;
    now_x = now_x + dx[index];
    now_y = now_y + dy[index];
    ans.push_back(index);
  }
  return;
}

int main()
{
  cin >> sj >> si;
  now_x = si;
  now_y = sj;

  for (int i = 0; i < 2500; i++) {
    int num;
    cin >> num;
    table[i] = num;
    tile[num].push_back(i);
  }
  for (int i = 0; i < 2500; i++) {
    int x = i%50;
    int y = i/50;
    cin >> point[y][x];
  }

  solve(now_x, now_y);

  // 出力
  for (int i = 0; i < ans.size(); i++) {
    if (ans[i]==0) cout << 'R';
    else if (ans[i]==1) cout << 'D';
    else if (ans[i]==2) cout << 'L';
    else if (ans[i]==3) cout << 'U';
  }
  cout << endl;
}

#include <bits/stdc++.h>

const long long INF = 1e9;
const long long MOD = 1e9 + 7;
//const long long MOD = 998244353;
const long long LINF = 1e18;
using namespace std;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define dump(x)  cout << #x << " = " << (x) << endl
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define COUT(x) cout<<(x)<<endl
#define SCOUT(x) cout<<(x)<<" "
#define VECCOUT(x) for(auto&youso_: (x) )cout<<right<<setw(10)<<youso_<<" ";cout<<endl
#define ENDL cout<<endl
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) long long __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define mp make_pair
#define PQ priority_queue<long long>
#define PQG priority_queue<long long,V,greater<long long>>

typedef long long ll;
typedef vector<long long> vl;
typedef vector<long long> vi;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef vector<vb> vvb;
typedef vector<vc> vvc;
typedef pair<long long, long long> pll;

#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}
template<class T>
void mod(T &x) {
    x %= MOD;
    x += MOD;
    x %= MOD;
}

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

struct COMB{
    vl fact, fact_inv, inv;
    void init_nCk(long long SIZE) {
        fact.resize(SIZE + 5);
        fact_inv.resize(SIZE + 5);
        inv.resize(SIZE + 5);
        fact.at(0) = fact.at(1) = fact_inv.at(0) = fact_inv.at(1) = inv.at(1) = 1;
        for(long long i = 2; i < SIZE + 5; i++) {
            fact.at(i) = fact.at(i - 1)*i%MOD;
            inv.at(i) = MOD - inv.at(MOD%i)*(MOD/i)%MOD;
            fact_inv.at(i) = fact_inv.at(i - 1)*inv.at(i)%MOD;
        }
    }
    long long nCk (long long n, long long k) {
        assert(!(n < k));
        assert(!(n < 0 || k < 0));
        return fact.at(n)*(fact_inv.at(k)*fact_inv.at(n - k)%MOD)%MOD;
    }
};
ll extGCD(ll a, ll b, ll &x, ll &y) {
    if(b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a/b*x;
    return d;
}

void Main() {
    ll ans = 0;
    LCIN(N, M, K);
    COMB c;
    c.init_nCk(3000000);
    ans = c.nCk(N + M, M);
    if(N > M + K) {
        cout << 0 << endl;
        return;
    }
    if(M + N >= M + K + 1) ans -= c.nCk(M + N,  M + K + 1);
    cout << (ans%MOD + MOD)%MOD << endl;
    return;

    if(N == 0) {
        cout << 1 << endl;
        return;
    }
    if(M == 0) {
        return;
    }
    for(ll i = 0; i <= N + M; i++) {
        if(K <= i && i < 2*N - K) {
            if((i - K)%2 == 0) {
                ll n = (i + K)/2;
                ll m = (i - K)/2;
                ans -= c.nCk(N + M - n - m - 1, N - n - 1);
                ans %= MOD;
            }
        }
        /*
        if(i > K) {
            ans -= c.nCk(N + M - i - 1, M - 1);
            ans %= MOD;
        } */
    }
    cout << (ans%MOD + MOD)%MOD << endl;
}

int main() {
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << 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; }

using namespace std;
typedef long long ll;

void solve(){
    ll l, r; cin >> l >> r;
    if(2*l > r) {
        cout << 0 << endl;
        return;
    }
    ll x = r-2*l+1;
    cout << (x*(x+1))/2 << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int t; cin >> t;
    for(int i = 0; i < t; i++)  solve();
}

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

//UnionFindテンプレ
class UnionFind {
    // まとめる 判定 サイズを知る
    public:
    // Aから見た親の番号を格納する。rootだったら-1*その集合のサイズ。
    vector<int> Parent;

    // 初期化
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }

    // Aのrootを調べる
    int root(int A) {
        if (Parent[A] < 0) return A;  // マイナスならそれはroot
        return Parent[A] = root(Parent[A]);
    }

    // rootの値をプラスに戻して返す(サイズ)
    int size(int A) {
        return -Parent[root(A)];
    }

    // くっつける関数
    bool connect(int A, int B) {
        // AとBのroot同士をくっつける
        A = root(A);  // ここのAは、"rootの場所"の意味
        B = root(B);
        if (A == B) return false;  // 既にくっついている
        if (size(A) < size(B))
        swap(A, B);            // 大きい方にくっつけるために中身交換
        Parent[A] += Parent[B];  // 中身更新
        Parent[B] = A;
        return true;
    }

    //連結か調べる関数
    bool issame(int A, int B) {
        return root(A) == root(B);
    }
};

//chmin,chmax関数(DP用)
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;
}

//aのZ/mZでの逆元
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

//最大公約数
int64_t gcd(int64_t a, int64_t b) {
    if (a % b == 0) {
        return b;
    }
    return gcd(b, a%b);
}

//エラストテレスのふるい
vector<bool> make_is_prime(int N) {
    vector<bool> prime(N + 1, true);
    if (N >= 0) prime[0] = false;
    if (N >= 1) prime[1] = false;
    for (int i = 2; i * i <= N; i++) {
        if (!prime[i]) continue;
        for (int j = i * i; j <= N; j += i) {
            prime[j] = false;
        }
    }
    return prime;
}
//累乗a^b
int64_t pow(int a, int b) {
    int64_t ans = (int64_t)1;
    for (int i = 0; i < b; i++) {
        ans *= (int64_t)a;
    }
    return ans;
}

//ここから

int main() {
    int T; cin>>T;
    vector<int64_t> answer(T);
    for (int i = 0; i < T; i++) {
        int64_t L,R; cin>>L>>R;
        int64_t ans = 0;
        if (2*L > R) {
            answer.at(i) = 0;
            continue;
        } else {
            answer.at(i) = (R-2*L+2)*(R-2*L+1)/2;
        }

    }
    for (int i = 0; i < T; i++) {
        cout << answer.at(i) << endl;
    }
}


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<int> vsize;

    UnionFind(int size) : par(size), rank(size), vsize(size) {
        REP(i, size) {
            par[i] = i;
            rank[i] = 0;
            vsize[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 (rank[x] < rank[y]) {
            par[x] = y;
        } else {
            par[y] = x;
            if (rank[x] == rank[y]) rank[x]++;
        }
        vsize[x] += vsize[y];
        vsize[y] = vsize[x];
    }

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

    int size(int x) { return vsize[find(x)]; }
};

class CKeepGraphConnected {
public:
    vector<int> res;
    vector<vector<P>> G;

    void dfs(int n, int p) {
        for (auto to: G[n]) {
            if (to.first == p) continue;
            if (res[n] == to.second) {
                res[to.first] = to.second == 1 ? 2 : 1;
            } else {
                res[to.first] = to.second;
            }
            dfs(to.first, n);
        }
    }

    void solve(std::istream& cin, std::ostream& cout) {
        int N, M;
        cin >> N >> M;
        G.resize(N);
        UnionFind uf(N);

        REP(i, M) {
            int u, v, c;
            cin >> u >> v >> c;
            u--, v--;
            if (uf.same(u, v)) continue;
            uf.unite(u, v);
            G[u].push_back({v, c});
            G[v].push_back({u, c});
        }
        res.resize(N);
        res[0] = 1;
        dfs(0, -1);
        REP(i, N) {
            cout << res[i] << endl;
        }
    }
};

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    CKeepGraphConnected solver;
    solver.solve(in, out);
    return 0;
}

/**
*    author:  shu8Cream
*    created: 18.04.2021 12:10:02
**/

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

template<typename T>
struct BIT{
public:
    int n; vector<T> a;
    BIT(int n_):n(n_),a(n+1,0){}

    void add(int idx, T x){
        idx++;
        if(idx<=0 || n<idx){ cerr << "Index error" << endl; return; }
        for(int i=idx; i<=n; i+=i&(-i)){
            a[i]+=x;
        }
    }

    T sum(int idx){
        T res = 0;
        idx++;
        if(idx<0 || n<idx){ cerr << "Index error" << endl; return 0; }
        if(idx==0) return 0;
        for(int i=idx; i>0; i-=(i&-i)){
            res+=a[i];
        }
        return res;
    }

    T sum(int l, int r){
        if(l==0) return sum(r-1);
        return sum(r-1)-sum(l-1);
    }
};

BIT<ll> a_cnt(440000);
BIT<ll> b_cnt(440000);
BIT<ll> a_sum(440000);
BIT<ll> b_sum(440000);

int a[220000];
int b[220000];

vi decomp;
ll ts[220000], xs[220000], ys[220000];

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,m,q,t,x,y;
    cin >> n >> m >> q;
    a_cnt.add(0,n);
    b_cnt.add(0,m);

    decomp.push_back(0);

    rep(i,q){
        cin >> ts[i] >> xs[i] >> ys[i];
        decomp.push_back(ys[i]);
    }

    sort(all(decomp));
    decomp.erase(unique(all(decomp)), decomp.end());

    rep(i,q){
        ys[i] = lower_bound(all(decomp), ys[i]) - decomp.begin();
    }

    ll ans = 0;
    rep(i,q){
        t = ts[i], x = xs[i], y = ys[i];
        if(t==1){
            int before = a[x];
            int after = y;
            int m = min(before, after),
                M = max(before, after);
            ll diff = -b_sum.sum(m,M)
                    + b_cnt.sum(m,M) * decomp[M]
                    + (decomp[M]-decomp[m])*b_cnt.sum(0,m);
            if(before<=after) ans += diff;
            else ans-=diff;
            a_sum.add(before, -decomp[before]);
            a_cnt.add(before, -1);
            a_sum.add(after, decomp[after]);
            a_cnt.add(after, 1);
            a[x]=y;
        }
        if(t==2){
            int before = b[x];
            int after = y;
            int m = min(before, after),
                M = max(before, after);
            ll diff = -a_sum.sum(m,M)
                    + a_cnt.sum(m,M) * decomp[M]
                    + (decomp[M]-decomp[m])*a_cnt.sum(0,m);
            if(before<=after) ans += diff;
            else ans-=diff;
            b_sum.add(before, -decomp[before]);
            b_cnt.add(before, -1);
            b_sum.add(after, decomp[after]);
            b_cnt.add(after, 1);
            b[x]=y;
        }
        cout << ans << endl;
    }
}


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

struct dijkstra{
    vector<long long> min_dst;
    vector<vector<pair<long long, long long>>> G;

    dijkstra(int n){
        min_dst.resize(n);
        G.resize(n);
    }

    void append(int u, int v, long long cost){G[u].push_back(make_pair(v, cost));}

    void run(int s){
        priority_queue<pair<long long, long long>, vector<pair<long long, long long>>, greater<pair<long long, long long>>> que;
        fill(min_dst.begin(), min_dst.end(), -1);
        min_dst[s] = 0;
        que.push(make_pair(0, s));

        while(!que.empty()){
            auto p = que.top(); que.pop();
            int at = p.second;
            if(min_dst[at] < p.first){continue;}
            for(int i = 0; i < G[at].size(); i++){
                int to = G[at][i].first;
                long long cost = G[at][i].second;
                if(min_dst[to] == -1 || min_dst[at] + cost < min_dst[to]){
                    min_dst[to] = min_dst[at] + cost;
                    que.push(make_pair(min_dst[to], to));
                }
            }
        }
    }

    long long get(int at){return min_dst[at];}
};

ll r, c, a[505][505], b[505][505];

ll encode(ll i, ll j){
    return i * c + j;
}

ll encode2(ll i, ll j){
    return i * c + j + r * c;
}

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

    cin >> r >> c;
    zep(i, 0, r)zep(j, 0, c - 1)cin >> a[i][j];
    zep(i, 0, r - 1)zep(j, 0, c)cin >> b[i][j];

    dijkstra d(2 * r * c);

    zep(i, 0, r)zep(j, 0, c - 1){
        d.append(encode(i, j), encode(i, j + 1), a[i][j]);
        d.append(encode(i, j + 1), encode(i, j), a[i][j]);
    }

    zep(i, 0, r)zep(j, 0, c){
        d.append(encode(i, j), encode2(i, j), 1);
        d.append(encode2(i, j), encode(i, j), 0);
    }

    zep(i, 0, r - 1)zep(j, 0, c){
        d.append(encode(i, j), encode(i + 1, j), b[i][j]);
        d.append(encode2(i + 1, j), encode2(i, j), 1);
    }

    d.run(0);
    //zep(i, 0, r){zep(j, 0, c)cout << d.get(encode(i, j)) << " "; cout << endl;}
    print(d.get(encode(r - 1, c - 1)))

    return 0;
}

#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
// please, read the question correctly (do you need set or multiset)???
const int N=510; //check the limits, dummy
int a[N][N], b[N][N];
int n, m;
int mem[N][N][2];
struct pnt{
  int c, l, x, y;
};
bool operator <(pnt a, pnt b){
  if(a.c==b.c)
    return -a.x-a.y>-b.x-b.y;
  return a.c>b.c;
}
pnt mkk(int c, int l, int x, int y){
  pnt tmp;
  tmp.c=c;
  tmp.l=l;
  tmp.x=x;
  tmp.y=y;
  return tmp;
}
int solve(){
	priority_queue<pnt> q;
	q.push(mkk(0,0,0,0));
	memset(mem, -1, sizeof mem);
	pnt tp;
	int x, y, c, l;
	while(q.size()>0){
		tp = q.top();
		q.pop();
		x = tp.x;
		y = tp.y;
		c = tp.c;
		l = tp.l;
		if(x==n-1 && y==m-1){
			return c;
		}
		if(mem[x][y][l]!=-1)
			continue;
		mem[x][y][l]=c;
		if(y+1<m)
			q.push(mkk(c+a[x][y],0,x,y+1));
		if(y-1>=0)
			q.push(mkk(c+a[x][y-1],0,x, y-1));
		if(x+1<n){
			q.push(mkk(c+b[x][y],0,x+1,y));
		}
		if(x-1>=0){
			if(l)
				q.push(mkk(c+1,1,x-1, y));
			else
				q.push(mkk(c+2,1,x-1, y));
		}
	}
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=0; i<n; ++i){
		for(int j=0; j<m-1; ++j){
			scanf("%d",&a[i][j]);
		}
	}
	for(int i=0; i<n-1; ++i){
		for(int j=0; j<m; ++j){
			scanf("%d",&b[i][j]);
		}
	}
	int ans = solve();
	cout<<ans<<endl;
}


#include<bits/stdc++.h>

typedef long long ll;
using namespace std;
const int N = 2e5 + 5;
const int mod = 998244353;
void solve() {
  int n; cin >> n;
  vector<ll> a(n), sum1(n), sum2(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (!i) {
      sum1[i] = a[i];
      sum2[i] = a[i] * a[i];
    } else {
      sum1[i] = sum1[i - 1] + a[i];
      sum2[i] = sum2[i - 1] + a[i] * a[i];
    }
  }
  ll ans = 0;
  for (int i = 1; i < n; i++) {
    ans += i * a[i] * a[i] - 2  * a[i] * (sum1[i - 1]) + sum2[i - 1];
    //cout << ans << '\n';
  }
  cout << ans << '\n';
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0),  cout.tie(0);
  int T = 1; //cin >> T;
  while(T--) {
    solve();
  }
  return 0;
}

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

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

    vector<ll> A(N);
    ll st1, st2, st3;
    ll sum1 = 0; // sum(A)
    ll sum2 = 0; // sum(A^2)
    rep(i,0,N)
    {
        cin >> A.at(i);
        sum1 += A.at(i);
        sum2 += A.at(i)*A.at(i);
    }
    ll ans = 0;
    ans = N*sum2 - sum1*sum1;
    cout << ans << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef vector <int> vi;
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ff first
#define ss second
#define f(i,a,b) for(int i = a; i < b; i++)
#define fa(i,a,b) for(int i = a; i >= b; i--)
const int inf=1e9+10;
const ll INF = 1e18+10;
const ll N=1e5+5;
const ll M=1e7+5;
const ll mod=1e9+7;

int n, ans;
int a[2005], mini = inf;
vector <ii> divi;

int main(){
    fastio;
    cin >> n;
    f(i,0,n) {
        cin >> a[i];
        mini = min(mini,a[i]);
    }
    f(i,0,n){
        for(int j = 1; j*j <= a[i]; j++){
            if(a[i]%j == 0){
                divi.push_back({j,a[i]});
                if(a[i]/j != j) divi.push_back({a[i]/j,a[i]});
            }
        }
    }
    sort(divi.begin(), divi.end());
    int id = 0;
    while(id < divi.size()){
        int comp = divi[id].ff, d = 0;
        while(divi[id].ff == comp){
            d = __gcd(d, divi[id].ss); id++;
        }
        if(d == comp and d <= mini) ans++;
    }
    cout << ans << '\n';
    return 0;
}

#include<bits/stdc++.h>

#define IOS ios::sync_with_stdio(false);cin.tie(nullptr)
#define all(x) x.begin(),x.end()
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define lc(x) ((x)<<1)
#define rc(x) (((x)<<1)|1)

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

const ll LINF=2e18;
const ll MOD=2e18;
const int INF=0x3f3f3f3f;
const int MAXN=100050;
//35000

int a[MAXN];
map<int,int>gcdd;
int gcd(int x,int y)
{
    return y?gcd(y,x%y):x;
}
void mainwork(int T){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",a+i);
	}
	sort(a+1,a+n+1);
	int minn=a[1];
	int ans=1;
	for(int i=1;i<=n;i++){
		for(int j=1;j<minn&&j*j<=a[i];j++){
			if(a[i]%j==0){
				gcdd[j]=gcd(gcdd[j],a[i]);
				if(a[i]/j<minn)gcdd[a[i]/j]=gcd(gcdd[a[i]/j],a[i]);
			}
		}
	}
	for(auto i:gcdd){
		if(i.first>=minn)break;
		if(i.second==i.first)ans++;
	}
	printf("%d\n",ans);
}
signed main(){
	//IOS;
	#ifndef ONLINE_JUDGE
	//freopen("./in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	#endif
	int t=1;
	//scanf("%d",&t);
	//prework();
	for(int i=1;i<=t;i++){
		mainwork(i);
	}
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define quickread                     \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define pb push_back
#define all(x) x.begin(), x.end()
#define hii cout << "Hii there Sparky! \n"
#define endl '\n'
#define mod 1000000007
//#define mod 998244353
#define maxn 100010 //check the limits, dummy

#define N 200001
#define inputG push_back
vector<int> G[N];
bool visited[N] = {};
int parent[N] = {};
int depth[N] = {};
int intime[N], outtime[N];
vector<int> tim;
int timer = 0;
// int weight[N] = {};
// int op[N] = {};
// int components = 0;
void inp(int a, int b) {
    a--, b--;
    G[a].inputG(b);
    G[b].inputG(a);
}
void dfs(int cur) {
    timer++;
    intime[cur] = timer;
    tim.pb(cur);
    visited[cur] = true;
    depth[cur] = depth[parent[cur]] + 1;
    for (auto u : G[cur]) {
        if (visited[u])
            continue;
        parent[u] = cur;
        dfs(u);
    }
    timer++;
    outtime[cur] = timer;
    tim.pb(cur);
}
void DFS(int n) {
    for (int i = 0; i < n; i++) {
        if (!visited[i]) {
            dfs(i);
        }
    }
}
void clearGraph(int n) {
    for (int i = 0; i < n; i++)
        G[i].clear();
    memset(visited, false, sizeof(visited));
    memset(parent, 0, sizeof(parent));
    memset(depth, 0, sizeof(depth));
    // memset(weight, 0, sizeof(weight));
    // memset(op, 0, sizeof(op));
    // components = 0;
}

unordered_map<int, vector<int>> m;

void solve() {
    int n;
    cin >> n;
    for (int i = 2; i <= n; i++) {
        int x;
        cin >> x;
        inp(i, x);
    }
    DFS(n);
    for (int i = 0; i < tim.size(); i++) {
        tim[i] = depth[tim[i]];
        m[tim[i]].pb(i);
    }
    int q;
    cin >> q;
    while (q--) {
        int u, d;
        cin >> u >> d;
        u--;
        int l = intime[u];
        int r = outtime[u];
        int val = d + 1;
        l--, r--;
        int a = lower_bound(all(m[val]), l) - m[val].begin();
        int b = upper_bound(all(m[val]), r) - m[val].begin();
        cout << (b - a) / 2 << endl;
    }
}

int32_t main() {
    quickread;
    int test = 1;
    //cin >> test;
    for (int i = 0; i < test; i++) {
        solve();
    }
    return 0;
}

#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define lp(i,s,f) for(ll i = s; i < ll(f); i++)
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define endl '\n'
#define MOD 1000000007
#define mm(arr) memset(arr, 0, sizeof(arr))
#define F first
#define S second

const int N = 2e5 + 5;
int Time = 0;
int intime[N];
int outtime[N];
int n;
vector<int> adj[N];
vector<pair<int, int> > depth[N];
int dd[N];

void dfs(int s, int d){
    dd[s] = d;
    pair<int, int> p;
    p = {Time++, 0};
    intime[s] = Time - 1;
    for(int i = 0; i < adj[s].size(); i++){
        dfs(adj[s][i], d + 1);
    }
    Time++;
    p.second = Time;
    outtime[s] = Time;
    depth[d].pb(p);
}
int main(){
    FAST
    cin >> n;
    for(int i = 1; i < n; i++){
        int p; cin >> p;
        p--;
        adj[p].pb(i);
    }
    dfs(0, 0);
    vector<int> depth1[N];
    vector<int> depth2[N];
    for(int i = 0; i < n; i++){
        sort(depth[i].begin(), depth[i].end());
        for(int j = 0; j < depth[i].size(); j++){
            depth1[i].pb(depth[i][j].first);
            depth2[i].pb(depth[i][j].second);
        }
    }
    int q; cin >> q;
    while(q--){
        int U, d;
        cin >> U >> d;
        U--;
        if(depth1[d].size() == 0 || dd[U] > d){
            cout << 0 << endl;
            continue;
        }
        if(dd[U] == d){
            cout << 1 << endl;
            continue;
        }
        //intime[U], outtime[U];
        int a = intime[U], b = outtime[U];
        int num = lower_bound(depth1[d].begin(), depth1[d].end(), a) - depth1[d].begin();
        if(num == depth1[d].size()){
            cout << 0 << endl;
            continue;
        }
        if(depth2[d][num] > b){
            cout << 0 << endl;
            continue;
        }
        int lo = num, hi = depth1[d].size() - 1;
        while(lo < hi){
            int mid = (lo + hi + 1)/2;
            if(depth2[d][mid] > b){
                hi = mid - 1;
            }
            else{
                lo = mid;
            }
        }
        cout << lo - num + 1 << endl;
    }
    return 0;
}


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

#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second
#define cbr cerr<<"hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ll(x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x,y) (lower_bound(all(x),y)-x.begin())
#define ubd(x,y) (upper_bound(all(x),y)-x.begin())
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return rng() % (y+1-x) + x; } //inclusivesss
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); }

using ll=long long;
using ld=long double;
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
using pi=pair<ll,ll>; using spi=pair<ll,pi>; using dpi=pair<pi,pi>;

#define LLINF ((long long)1e18)
#define INF int(1e9+1e6)
#define MAXN (200006)
ll n,k,A[MAXN],C[302][302],mod=998244353,sum[MAXN],ans[302],co[MAXN];
ll qexp(ll x,ll e){
	ll sum=1;
	for(;e;e>>=1,x*=x,x%=mod)if(e&1)sum*=x,sum%=mod;
	return sum;
}
int main(){
	FAST
	cin>>n>>k;
	FOR(i,1,n)cin>>A[i];
	FOR(i,0,300) C[i][0]=1;
	FOR(i,1,300) FOR(j,1,300) C[i][j] = (C[i-1][j] + C[i-1][j-1]) % mod;
	FOR(i,1,n){
		ll co = 1;
		FOR(j,0,k){
			sum[j] += co, sum[j] %= mod;
			co *= A[i], co %= mod;
		}
	}
	fill(co,co+MAXN,1);
	FOR(i,1,k){
		ll ans = 0;
		FOR(j,0,i){
			ans += sum[j] * sum[i-j] % mod * C[i][j] % mod, ans %= mod;
		}
		FOR(z,1,n){
			co[z] *= A[z] * 2 % mod, co[z] %= mod;
			ans -= co[z], ans += mod, ans %= mod;
		}
		ans *= qexp(2, mod-2), ans %= mod;
		cout<<ans<<'\n';
	}
}

#include "bits/stdc++.h" // Tomasz Nowak
using namespace std;     // XIII LO Szczecin
using LL = long long;    // Poland
#define FOR(i, l, r) for(int i = (l); i <= (r); ++i)
#define REP(i, n) FOR(i, 0, (n) - 1)
template<class T> int size(T &&x) {
	return int(x.size());
}
template<class A, class B> ostream& operator<<(ostream &out, const pair<A, B> &p) {
	return out << '(' << p.first << ", " << p.second << ')';
}
template<class T> auto operator<<(ostream &out, T &&x) -> decltype(x.begin(), out) {
	out << '{';
	for(auto it = x.begin(); it != x.end(); ++it)
		out << *it << (it == prev(x.end()) ? "" : ", ");
	return out << '}';
}
void dump() {}
template<class T, class... Args> void dump(T &&x, Args... args) {
	cerr << x << ";  ";
	dump(args...);
}
#ifdef DEBUG
  struct Nl{~Nl(){cerr << '\n';}};
# define debug(x...) cerr << (strcmp(#x, "") ? #x ":  " : ""), dump(x), Nl(), cerr << ""
#else
# define debug(...) 0 && cerr
#endif
mt19937_64 rng(0);
int rd(int l, int r) {
	return uniform_int_distribution<int>(l, r)(rng);
}
// end of templates

constexpr int mod = int(998244353);
int mul(int a, int b) {
	return int((a * LL(b)) % mod);
}
int add(int a, int b) {
	a += b;
	if(a >= mod)
		a -= mod;
	return a;
}
int pot(int a, int b) {
	if(b == 0)
		return 1;
	int x = pot(a, b / 2);
	x = mul(x, x);
	if(b & 1)
		x = mul(x, a);
	return x;
}
int inv(int x) {
	return pot(x, mod - 2);
}

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

	int n, K;
	cin >> n >> K;
	vector<int> a(n);
	for(int &ai : a)
		cin >> ai;

	vector<int> silnia(K + 1, 1);
	FOR(i, 2, K)
		silnia[i] = mul(silnia[i - 1], i);
	vector<int> revsilnia(K + 1, 1);
	revsilnia[K] = inv(silnia[K]);
	for(int i = K - 1; i >= 2; --i)
		revsilnia[i] = mul(revsilnia[i + 1], i + 1);
	auto newton = [&](int x, int y) {
		return mul(silnia[x], mul(revsilnia[y], revsilnia[x - y]));
	};

	vector<int> sum_pot(K + 1);
	FOR(k, 0, K)
		REP(i, n)
			sum_pot[k] = add(sum_pot[k], pot(a[i], k));
	debug(sum_pot);

	/*
	vector<int> sum_2a_pot(K + 1);
	FOR(k, 1, K)
		REP(i, n)
			sum_2a_pot[k] = add(sum_2a_pot[k], pot(2 * a[i], k));
	*/

	int inv2 = inv(2);

	FOR(k, 1, K) {
		int answer = 0;
		FOR(x, 0, k) {
			int nw = newton(k, x);
			int local = mul(sum_pot[x], sum_pot[k - x]);
			local = add(local, mod - sum_pot[k]);
			local = mul(local, inv2);
			debug(x, k - x, k, nw, local);
			answer = add(answer, mul(nw, local));
		}
		cout << answer << '\n';
	}
}


#include <iostream>
#include <cstring>
#include <algorithm>
#include <string>
#include <queue>

using namespace std;

int n, a[3009][5];

int vis[4][1 << 5];
int fu(int x) {
    memset(vis, 0, sizeof(vis));
    vis[0][0] = 1;
    for(int i = 0; i < n; i ++) {
        for(int j = 0; j < 3; j ++) {
            for(int k = 0; k < 1 << 5; k ++) {
                if(vis[j][k] == 0) continue;
                int v = k;
                v |= (a[i][0] >= x) << 0;
                v |= (a[i][1] >= x) << 1;
                v |= (a[i][2] >= x) << 2;
                v |= (a[i][3] >= x) << 3;
                v |= (a[i][4] >= x) << 4;
                vis[j + 1][v] = 1;
            }
        }
    }
    return vis[3][(1 << 5) - 1];
}
int main() {
    cin >> n;
    for(int i = 0; i < n; i ++)
        for(int j = 0; j < 5; j ++)
            cin >> a[i][j];
    int l = 0, r = 1e9;
    while(l < r) {
        int mid = l + r + 1 >> 1;
        if(fu(mid)) l = mid;
        else r = mid - 1;
    }
    cout << l;
    return 0;
}

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

bool join(int p, vector<vector<int>> a){
    int n = a.size();
    vector<uint> vec(32);
    for(vector<int> ai : a){
        uint bit = 0;
        for(int j = 0; j < 5; j++){
            if(ai[j] >= p) bit += (1<<j);
        }
        vec[bit] = bit;
    }
    //for(uint i : vec) cout << i << ","; cout << endl;
    for(uint i : vec){
        for(uint j : vec){
            for(uint k : vec){
                if((i|j|k) == 31) return true;
            }
        }
    }
    return false;
}

int main(){
    int n; cin >> n;
    vector<vector<int>> a(n,vector<int>(5));
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 5; j++){
            cin >> a[i][j];
        }
    }
    vector<int> aa(5*n);
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 5; j++){
            aa[5*i+j] = a[i][j];
        }
    }
    sort(aa.begin(),aa.end());
    reverse(aa.begin(),aa.end());

    for(int i : aa){
        //cout << "___" << i << endl;
        if(join(i,a)){
            cout << i << endl;
            break;
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const int N = 1e5+20;
const int M = 19;
int dis[M][N];
int vis[N];
vector<int> G[N];
int n,m,k,C[N],f[N*2][M];
priority_queue<pair<int,int> >q;
void dij(int *dis,int x)
{
	for(int i=1;i<=n;i++)dis[i]=inf,vis[i]=0;
	dis[x] = 0;
	q.push(make_pair(0,x));
	while(!q.empty())
	{
		int u=q.top().second;q.pop();
		if(vis[u]) continue;
		vis[u] = 1;
		for(int v:G[u])if(dis[v]>dis[u]+1)
		{
			dis[v] = dis[u]+1;
			q.push(make_pair(-dis[v],v));
		}
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1,x,y;i<=m;i++)
		scanf("%d%d",&x,&y),G[x].push_back(y),
		G[y].push_back(x);
	scanf("%d",&k);
	for(int i=0;i<k;i++)
		scanf("%d",&C[i]),dij(dis[i],C[i]);
	int M = 1<<k;
	for(int i=0;i<M;i++)
		for(int j=0;j<k;j++)f[i][j] = inf;
	for(int i=0;i<k;i++)
		f[1<<i][i]=1;
	for(int i=1;i<M-1;i++)for(int l=0;l<k;l++)if(f[i][l]!=inf)
	{
		for(int j=0;j<k;j++)
			if(((i>>j)&1)==0)
			{
				int d = dis[l][C[j]];
				f[i|(1<<j)][j]= min(f[i|(1<<j)][j],f[i][l]+d);
			}
	}
	int ans = inf;
	for(int i=0;i<k;i++) ans = min(ans,f[M-1][i]);
	printf("%d",ans==inf?-1:ans);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
using ll = long long;
struct edge{int to; ll cost;};
using P = pair<ll,int>;
const ll INF = 1e17;

void dijkstra(int n, int s, vector<vector<edge>>& g, vector<ll>& d){
  priority_queue<P,vector<P>,greater<P>> que;
  rep(i,n) d[i] = INF;
  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(auto e : g[v]){
      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(){
  int n, m;
  cin >> n >> m;
  int a[m], b[m];
  vector<vector<edge>> g(n);
  rep(i,m) {
    cin >> a[i] >> b[i];
    a[i]--; b[i]--;
    g[a[i]].push_back(edge{b[i],1});
    g[b[i]].push_back(edge{a[i],1});
  }
  int k;
  cin >> k;
  int c[k];
  rep(i,k) {
    cin >> c[i];
    c[i]--;
  }
  vector<vector<ll>> dist(k,vector<ll>(k,INF));
  rep(i,k) {
    vector<ll> d(n);
    dijkstra(n,c[i],g,d);
    rep(j,k) dist[i][j] = d[c[j]];
  }
  vector<vector<ll>> dp(1<<k,vector<ll>(k,INF));
  rep(i,k) dp[1<<i][i] = 1;
  rep(bit,1<<k) rep(j,k) rep(l,k) dp[(1<<l)|bit][l] = min(dp[(1<<l)|bit][l],dp[bit][j]+dist[j][l]);
  ll ans = INF;
  rep(i,k) ans = min(ans,dp[(1<<k)-1][i]);
  cout << (ans == INF ? -1 : ans) << endl;
  return 0;
}


/**
 * Author: Daniel
 * Created Time: 2021-05-18 18:12:02
**/

#include <bits/stdc++.h>

using namespace std;

#define F first
#define S second
#define ER erase
#define IS insert
#define PI acos(-1)
#define PB pop_back
#define MP make_pair
#define MT make_tuple
#define LB lower_bound
#define UB upper_bound
#define EB emplace_back
#define lowbit(x) (x & -x)
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()
#define SOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout<<fixed<<setprecision(10)

typedef long long LL;
typedef vector<LL> VL;
typedef vector<int> VI;
typedef vector<bool> VB;
typedef pair<LL, LL> PLL;
typedef vector<string> VS;
typedef vector<double> VD;
typedef pair<int, int> PII;
typedef unsigned long long ULL;
typedef pair<double, double> PDD;
typedef vector<pair<LL, LL> > VPLL;
typedef vector<pair<int, int> > VPII;

template <typename A> using VE = vector<A>;
template <typename A> using USET = unordered_set<A>;
template <typename A> using HEAP = priority_queue<A>;
template <typename A, typename B> using PA = pair<A, B>;
template <typename A, typename B> using UMAP = unordered_map<A, B>;
template <typename A> using RHEAP = priority_queue<A, vector<A>, greater<A> >;

template <typename A> A MAX(const A &a) { return a; }
template <typename A> A MIN(const A &a) { return a; }
template <typename A> A MAX(const A *a, const A *b) { return *max_element(a, b); }
template <typename A> A MIN(const A *a, const A *b) { return *min_element(a, b); }
template <typename A, typename... B> A MAX(const A &a, const B&... b) { return max(a, MAX(b...)); }
template <typename A, typename... B> A MIN(const A &a, const B&... b) { return min(a, MIN(b...)); }
template <typename A, typename B = typename std::iterator_traits<A>::value_type> B MAX(A a, A b) { return *max_element(a, b); }
template <typename A, typename B = typename std::iterator_traits<A>::value_type> B MIN(A a, A b) { return *min_element(a, b); }

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

///////////////////////////////////////////////////////////////////////////
//////////////////// DO NOT TOUCH BEFORE THIS LINE ////////////////////////
///////////////////////////////////////////////////////////////////////////

// check the limitation!!!
const int N = 100010, M = 1010;

// read the question carefully!!!
int main()
{
    SOS;

    int n;
    string s, t;
    cin >> n >> s >> t;
    VI a, b;
    for (int i = 0; i < n; i ++ )
    {
        if (s[i] == '0') a.EB(i);
        if (t[i] == '0') b.EB(i);
    }
    if (SZ(a) != SZ(b)) cout << "-1\n";
    else
    {
        int res = 0;
        for (int i = 0; i < SZ(a); i ++ )
            res += (int)(a[i] != b[i]);
        cout << res << '\n';
    }
    return 0;
}

// GOOD LUCK!!!

#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long int ll;

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

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

  int n;cin >> n;
  int ans = 0;
  string s;cin >> s;
  vector<vector<int>> cnt(n + 1, vector<int>(4));
  map<char, int> m;
  m['A'] = 0; m['T'] = 1; m['G'] = 2; m['C'] = 3;
  //ATGC
  for(int i = 0;i < n;i++){
    cnt[i + 1][m[s[i]]]++;
    for(int j = 0;j < 4;j++){
      cnt[i + 1][j] += cnt[i][j];
    }
  }
  for(int i = 1;i <= n;i++){
    for(int j = i;j <= n;j++){
      int a = cnt[j][0] - cnt[i - 1][0];
      int t = cnt[j][1] - cnt[i - 1][1];
      int g = cnt[j][2] - cnt[i - 1][2];
      int c = cnt[j][3] - cnt[i - 1][3];
      bool valid = true;
      if(a > 0 || t > 0){
        if(a != t)valid = false;
      }
      if(g > 0 || c > 0){
        if(g != c)valid = false;
      }
      if(valid)ans++;
    }
  }
  cout << ans << endl;
}