#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <unordered_map>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=998244353;
ll powmod(ll a, ll k){
    ll ap=a, ans=1;
    while(k){
        if(k&1){
            ans*=ap;
            ans%=MOD;
        }
        ap=ap*ap;
        ap%=MOD;
        k>>=1;
    }
    return ans;
}
ll inv(ll a){
	return powmod(a, MOD-2);
}
int main()
{
	int n, m;
  cin>>n>>m;
  if(n<m) swap(m, n);
  ll f[1000001]; f[0]=1;
  for(ll i=1; i<=n+m; i++) f[i]=f[i-1]*i%MOD;
  ll invf[1000001];
  invf[n+m]=inv(f[n+m]);
  for(ll i=n+m-1; i>=0; i--) invf[i]=invf[i+1]*(i+1)%MOD;
  ll ans=n;
  ll tot=f[n+m]*invf[n]%MOD*invf[m]%MOD;
  ll tinv=inv(tot);
  for(int i=0; i<m; i++){
    ans+=f[n-m+2*i]*invf[i]%MOD*invf[n-m+i]%MOD*f[2*m-2*i-1]%MOD*invf[m-i]%MOD*invf[m-i-1]%MOD*tinv%MOD;
    ans%=MOD;
  }
  cout<<ans<<endl;
  return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>
#define llint long long
#define mod 1000000007

using namespace std;

llint n;
llint a[500005], s[500005];
llint z[500005];
vector<llint> vec[500005];
llint sum[500005];
llint dp[500005];

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

	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	for(int i = 1; i <= n; i++) s[i] = s[i-1] ^ a[i];

	bool flag = false;
	for(int i = 1; i <= n; i++){
		if(s[i] == 0) flag = true;
	}
	if(!flag){
		cout << 1 << endl;
		return 0;
	}

	vector<llint> comp;
	for(int i = 1; i <= n; i++) comp.push_back(s[i]);
	sort(comp.begin(), comp.end());
	comp.erase(unique(comp.begin(), comp.end()), comp.end());
	for(int i = 1; i <= n; i++) s[i] = lower_bound(comp.begin(), comp.end(), s[i]) - comp.begin();

	llint S = s[n];

	for(int i = 1; i <= n; i++) vec[s[i]].push_back(i);
	for(int i = 1; i <= n; i++){
		z[i] = z[i-1];
		if(s[i] == 0) z[i]++, z[i] %= mod;
	}

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

	llint ans = 0;
	for(int i = 1; i < 500005; i++){
		llint N = vec[i].size();
				if(N == 0) continue;
		llint have = 0, sum = 0;
		dp[0] = 1, have++;
		for(int j = 1; j < N; j++){
			sum += have * (z[vec[i][j]] - z[vec[i][j-1]] + mod) % mod, sum %= mod;
			dp[j] = sum+1;
			have += dp[j], have %= mod;
		}
		if(S == 0){
			for(int j = 0; j < N; j++) ans += dp[j], ans %= mod;
		}
		else{
			if(i == S) ans += dp[N-1], ans %= mod;
		}
		//for(int j = 0; j < N; j++) cout << dp[j] << " "; cout << endl;
	}
	//cout << ans << endl;
	if(S == 0){
		llint tmp = 1;
		for(int i = 1; i < vec[0].size(); i++) tmp *= 2, tmp %= mod;
		ans += tmp, ans %= mod;
	}
	cout << ans << endl;

	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 all(x) (x).begin(),(x).end()
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
using Graph = vector<vector<int>>;
double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}
struct edge{ll to, cost;};
typedef pair<ll,ll> P;
struct graph{
  ll V;
  vector<vector<edge> > G;
  vector<ll> d;

  graph(ll n){
    init(n);
  }

  void init(ll n){
    V = n;
    G.resize(V);
    d.resize(V);
    rep(i,V){
      d[i] = INF;
    }
  }

  void add_edge(ll s, ll t, ll cost){
    edge e;
    e.to = t, e.cost = cost;
    G[s].push_back(e);
  }

  void dijkstra(ll s){
    rep(i,V){
      d[i] = INF;
    }
    d[s] = 0;
    priority_queue<P,vector<P>, greater<P> > que;
    que.push(P(0,s));
    while(!que.empty()){
      P p = que.top(); que.pop();
      ll 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));
        }
      }
    }
  }
};
class UnionFind
{
public:
  int par[100005];
  int depth[100005];
  int nGroup[100005];

  UnionFind(int n) {
    init(n);
  }

  void init(int n) {
    for(int i=0; i<n; i++) {
      par[i] = i;
      depth[i] = 0;
      nGroup[i] = 1;
    }
  }

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

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

  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if(x == y) return;

    if(depth[x] < depth[y]) {
      par[x] = y;
      nGroup[y] += nGroup[x];
      nGroup[x] = 0;
    } else {
      par[y] = x;
      nGroup[x] += nGroup[y];
      nGroup[y] = 0;
      if(depth[x] == depth[y])
        depth[x]++;
    }
  }
};
const ll MAX = 510000;
ll fac[MAX], finv[MAX], inv[MAX];

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

// 二項係数計算
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

vector<ll> depth;
vector<ll> f;
vector<ll> g;
void dfs(const Graph &G, ll v, ll p, ll d) {
    depth[v] = d;
    for (auto nv : G[v]) {
        if (nv == p) continue; // nv が親 p だったらダメ
        dfs(G, nv, v, d+1);
    }

    // 帰りがけ時に、部分木サイズを求める
    f[v] = 1;
    g[v] = 1;// 自分自身
    for (auto c : G[v]) {
        if (c == p) continue;
        f[v]*=g[c];
        f[v]%=MOD;
        g[v]*=f[c];
        g[v]%=MOD;
        }
    f[v]+=g[v];
    f[v]%=MOD;
}

int main() {
ll n,m; cin>>n>>m;
ll a[n]={};
rep(i,n) cin>>a[i];
map<ll,ll> b;
ll ca = 0;
rep(i,n){
ca+=a[i];
ll r = ca%m;
ca%=m;
b[r]++;}
ll ans = 0;
for(auto p : b){
if(p.fi==0)
ans+=p.se*(p.se+1)/2;
else
ans+=p.se*(p.se-1)/2;}
cout << ans << endl;}

#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch Test | diff Test.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address Test.cpp && ./a.out

/*

 5/25/2020

 16:11-

 */

const int MAX_N=1e6+1;
LL A[MAX_N];
int N,M;

void solve() {
  LL res=0;
  map<int,int> cnt;
  cnt[0]=1;
  LL cur=0;
  REP(i,N) {
    cur+=A[i];
    res+=cnt[cur%M];
    cnt[cur%M]++;
  }
  cout<<res<<endl;
}

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

  cin>>N>>M;
  REP(i,N) cin>>A[i];
  solve();

  return 0;
}


#include<iostream>
#include <algorithm>
#include <cmath>
#include <set>
#include<map>
#include<cstring>
#include<iomanip>
#include <string>
#include <vector>
#include<unordered_map>
#include<unordered_set>
using namespace std;

typedef long long unsigned llu;
typedef long double ld;
#define ll long long
#define PI 3.14159265358979323846
#define For(i, a, b) for (int i = a, sz = (int)b; i < sz; i++)
#define rFor(i, a, b, c) for (int i = (a); i >= (b); i -= (c))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define fill(a, b) memset(a, b, sizeof(a))
#define IO ios_base::sync_with_stdio(false), cin.tie(0),cout.tie(0)
const int mod = 1000000007;
const ll inf = 1000000000009;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) { return a*b/gcd(a,b);}

//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdoutn

int main() {
    IO;
    int a, b, x, y, r, c, ans;
    cin >> a >> b;
    x = a / 1000, y = b / 1000, r = (a / 100) % 10, c = (b / 100) % 10;
    ans = (y - x - 1) * 10 + 10 - r + c + 1;
    if (a > (a / 100) * 100 + ((a / 1000) % 10) * 10 + (a / 10000))
        ans--;
    if (b < (b / 100) * 100 + ((b / 1000) % 10) * 10 + (b / 10000))
        ans--;
    printf("%d\n", ans);
   // system("pause");
    return 0;
}

#include<iostream>
#include<algorithm>
using namespace std;
int main (void)
{
 int n,r,k;
  cin>>n>>r;
  k=10;
  if(n<10){k=n;}
  r=r+100*(10-k);
  cout<<r;
  return 0;
}


#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
#define endl "\n"
//#define int long long
#define ALL(x) begin(x),end(x)
#define RALL(a) (a).rbegin(), (a).rend()
#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
const int MOD = 1e9 + 7;
const ll INF = 1LL << 60;
const int inf = 1 << 25;
constexpr long double pi = 3.141592653589793238462643383279;
int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };
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;
}
ll fact(ll i) {
    if (i == 0) return 1;
    return ((fact(i - 1)) * i) % MOD;
}
ll gcd(ll a, ll b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
    return a * b / gcd(a, b);
}
ll keta(ll n) {
    if (n == 0) return 1;
    ll count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {
    ll sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
ll mch(ll n) {
    if (n == 1) return 1;
    else return n * mch(n - 1);
}
ll modpow(ll a, ll n, ll mod) {
    ll hi = 1;
    while (n > 0) {
        if (n & 1) hi = hi * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return hi;
}
bool is_prime(const unsigned n) {
    switch (n) {
    case 0: // fall-through
    case 1: return false;
    case 2: // fall-through
    case 3: return true;
    } // n > 3 が保証された
    if (n % 2 == 0 || n % 3 == 0) return false;
    for (unsigned i = 5; i * i <= n; i += 6) {
        if (n % i == 0) return false; // (6の倍数)-1
        if (n % (i + 2) == 0) return false; // (6の倍数)+1
    }
    return true;
}
/*signed*/int main(void) {
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> p(m);
    rep(i, m) {
        int s, c;
        cin >> s >> c;
        s--;
        p[i] = make_pair(s, c);
    }
    rep(i, 1000) {
        string s = to_string(i);
        if (s.size() == n) {
            bool ans = true;
            rep(j, m) {
                if ((s[p[j].first] - '0') != p[j].second)ans = false;
            }
            if (ans) {
                cout << i << endl;
                return 0;
            }
        }
    }
    cout << -1 << endl;
    return 0;
}

#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) for(int sz=0;sz<int(vec.size());sz++) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

using PI = P<int, int>;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, t; cin >> n >> t;
    V<PI> ab(n);
    for (int i = 0; i < n; i++) cin >> ab[i].first >> ab[i].second;
    sort(ALL(ab), [&](PI &i, PI &j){
        return i.first < j.first;
    });

    V< V<int> > dp(n + 1, V<int>(t + 1, 0));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= t; j++) {
            chmax(dp[i + 1][j], dp[i][j]);
            if (j < t) chmax(dp[i + 1][min(j + ab[i].first, t)], dp[i][j] + ab[i].second);
        }
    }
    cout << *max_element(ALL(dp[n])) << '\n';
    return 0;
}


#include <cstdio>
#include <cstring>

#define MAX_N 105

int N, A, B, C, D, S[MAX_N + 1];

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

	for (int i = 0; i < (N * N - N) / 2; i++)
	{
		scanf("%d", &A);
		scanf("%d", &B);
		scanf("%d", &C);
		scanf("%d", &D);

		if (C > D) { S[A] += 3; }
		if (C < D) { S[B] += 3; }
		if (C == D) { S[A] += 1; S[B] += 1; }
	}

	int rank;

	for (int i = 1; i <= N; i++)
	{
		rank = 1;

		for (int j = 1; j <= N; j++)
		{
			if (S[i] < S[j]) { rank += 1; }
		}

		printf("%d\n", rank);
	}

	return 0;
}

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

using namespace std;

struct comparator {
  int operator() (const pair<int, int>& l, const pair<int, int>& r) {
    return l.second < r.second;
  }
};

int main(int argc, char *argv[]) {
  // second = team's number
  vector<pair<int, int> >team;
  int n, a, b, c, d, game;
  cin >> n;
  for (int i = 0; i < n; i++)
    team.push_back(pair<int, int>(0, i));
  game = n * (n-1) / 2;

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

  sort(team.rbegin(), team.rend());
  int points = -1, rank = 1;
  for (int i = 0; i < n; i++)
    if (team[i].first == points) {
      team[i].first = rank;
    } else {
      points = team[i].first;
      team[i].first = i+1;
      rank = i+1;
    }
  struct comparator comp;
  sort(team.begin(), team.end(), comp);

  for (int i = 0; i < n; i++)
    cout << team[i].first << endl;
  return 0;
}


#include <iostream>
#include <cmath>
#include <map>
#include <set>
using namespace std;

int main() {
    int n;
    scanf("%d", &n);
    map<pair<int, int>, set<int>> pair_index;
    for(int i=0; i<n; i++){
        double x;
        int pow2=0, pow5=0;
        unsigned long long val;
        scanf("%lf", &x);
        val=llround(x*1e9);
        while(val%2==0){
            pow2++;
            val/=2;
        }
        while(val%5==0){
            pow5++;
            val/=5;
        }
        pair_index[*new pair(pow2, pow5)].insert(i);
    }
    unsigned long long counter=0;
    for(auto i=pair_index.begin(); i!=pair_index.end(); i++){
        for(auto j=i; j!=pair_index.end(); j++){
            if(min(i->first.first+j->first.first, i->first.second+j->first.second)>=18){
                if(i==j){
                    counter+=i->second.size()*(j->second.size()-1)/2;
                }else if(*i<*j){
                    counter+=(i->second.size()*j->second.size());
                }
            }
        }
    }
    printf("%llu\n", counter);
    return 0;
}

/*Logic:
 * Since floating points are stored as approximate value.
 * Direct multiplication will result in some anomaly.
 * To avoid that we multiplied the given floating point or regular number
 * with 10^9, because the highest number of digits after decimal is 9.
 * This will make the numbers to be in the form
 * number/10^9.
 * Now, if we multiply say (x/10^9 * y/10^9) then we get
 * xy/10^18.
 * To get an integer, all we have to do is cancel out the denominator.
 * So xy has be z*(10^(>=9)).
 * Now we also know that 10^p is basically (2^p)*(5^p).
 * Here, p has to be equal to or greater that 9.
 *
 * Now, comes to the problem of handling TLE.
 * Since the dataset is 2*10^6 and 2 sec, regular brute force gave me TLE.
 * So in order to handle that a map with key (2^p)*(5^q) where p varies and q varies
 * and as value stores the indices of where key was found.
 * Now, for any pair of keys min(p1+p2, q1+q2) >=18, then all we multiply the number
 * of values from the keys.
 * If for the same key min(p1+p1, q1+q1) >=18, then all possible combinations are required.
 * Thus number of values*(number of values-1)/2.
 * Summation of all of these results in the answer.
 */

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define REP(NAME, NUM) for (int NAME = 0; NAME < (NUM); ++NAME)
#define BREP(NAME, NUM) for (int NAME = (NUM)-1; NAME >= 0; --NAME)
#define ALL(NAME) (NAME).begin(), (NAME).end()

#define cMOD 998244353;

int main()
{
	ll n = 0;
	cin >> n;
	vector<ll> a( n, 0 );
	REP(i,n)cin>>a[i];
	ll sum = 0;
	REP(i,n) sum += a[i];

	vector<ll> dp( sum + 1, 0 );
	vector<ll> dp2( sum + 1, 0 );

	dp[0] = 1;
	dp2[0] = 1;
	REP( i, n ) BREP( j, sum + 1 )
	{
		dp[j] *= 2;
		if( a[i] <= j ) dp[j] += dp[j - a[i]];
		dp[j] %= cMOD;

		if( a[i] <= j ) dp2[j] += dp2[j - a[i]];
		dp2[j] %= cMOD;
		//cout << i << " " << j << " " << dp2[j] << endl;
	}

	ll ans = 0;
	for( int i= ( sum + 1 ) / 2; i <= sum; ++i )
		ans = ( ans + dp[i] ) % cMOD;

	ll all = 1;
	REP( i, n ) all = ( all * 3 ) % cMOD;

	ans = all - ans * 3;
	if( sum % 2 == 0 ) ans = ans + dp2[sum/2] * 3;
	while( ans < 0 ) ans += cMOD;
	ans %= cMOD;

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


#include <bits/stdc++.h>
typedef long long       ll;
#define PI                acos(-1)
#define pb                push_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define F first
#define S second
#define fore(i,b,e)		  for(int i=(int)b;i<(int)e;++i)
#define forr(i,b,e)		  for(int i=(int)b;i<(int)e;++i)
int faster_in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -faster_in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;

typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
const int INF = 1234567890;

ll toLL(string s) {
	ll res = 0;
	fore (i,0,s.length()) {
		res *= 10LL;
		res += s[i] - '0';
	}
	return res;
}

ll pot[45][20][10];

int main()
{
    std::ios::sync_with_stdio(false); cin.tie(0);
    //freopen("","r",stdin);
    //freopen("","w",stdout);
    int n;
    cin >> n;
    ll res = 0;
    fore(i, 0, n) {
    	string s;
    	cin >> s;
    	int decimal = 0;
    	fore(j, 0, s.length()) {
    		decimal++;
    		if (s[j] == '.') {
    			decimal = 0;
    		}
    	}
    	if (decimal == (int)s.length()) {
    		decimal = 0;
    	}
    	string s2 = "";
    	fore(j, 0, s.length()) {
    		if (s[j] != '.') {
    			s2 += s[j];
    		}
    	}
    	ll a = toLL(s2);
    	int p2 = 0, p5 = 0;
    	while (a%2 == 0) {
    		p2++;
    		a /= 2;
    	}
    	while (a%5 == 0) {
    		p5++;
    		a /= 5;
    	}
    	//cout << "2^" << p2 << " 5^" << p5 << " con " << decimal << " decimales" << endl << endl;
		pot[p2][p5][decimal]++;
		//if (min(p2, p5) >= decimal*2) res--;
    }
    ll ans = 0;
    res = 0;
    fore(a, 0, 45) {
    	fore(b, 0, 20) {
    		fore(c, 0, 10) {
    			fore(x, 0, 45) {
    				fore(y, 0, 20) {
    					fore(z, 0, 10) {
    						if (x == a && y == b && z == c) {
    							if (pot[a][b][c] > 1 && min(2*a, 2*b) >= 2*c) {
    								ans += pot[a][b][c] * (pot[a][b][c]-1) / 2;
    							}
    						}
    						else if ( min( a+x, b+y ) >= c + z ) {
    							res += pot[a][b][c] * pot[x][y][z];
    						}
    					}
    				}
    			}
    		}
    	}
    }
    cout << res/2 + ans << '\n';
    return 0;
}
// PLUS ULTRA!

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

using namespace std;

typedef long long int ll;

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

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
	int n;
	cin >> n;
	vector<int> v(n);
	for(int i = 0; i < n; i++){
		cin >> v[i];
	}
	map<int,int> even,odd; //mapで各数列での要素の出現数を記録する
	for(int i = 0; i < n; i++){
		if(i%2==0) odd[v[i]]++;
		else even[v[i]]++;
	}

	int even_1=0,even_2=0,odd_1=0,odd_2=0;
	int e1=0,e2=0,o1=0,o2=0;
	int cnt = 0;
	for(auto itr = even.begin();  itr != even.end() ; ++itr){
		if(itr->second > cnt){
			cnt = itr->second;
			even_1 = itr->first;
		}
	}
	e1 = cnt;
	cnt = 0;
	for(auto itr = even.begin();  itr != even.end() ; ++itr){
		if(itr->second > cnt && itr->first != even_1){
			cnt = itr->second;
			even_2 = itr->first;
		}
	}
	e2 = cnt;

	cnt = 0;
	for(auto itr = odd.begin();  itr != odd.end() ; ++itr){
		if(itr->second > cnt){
			cnt = itr->second;
			odd_1 = itr->first;
		}
	}
	o1= cnt;
	cnt = 0;
	for(auto itr = odd.begin();  itr != odd.end() ; ++itr){
		if(itr->second > cnt && itr->first != odd_1){
			cnt = itr->second;
			odd_2 = itr->first;
		}
	}
	o2=cnt;

	if(even_1 == odd_1){
		cout << min(n-e1-o2, n-e2-o1) << endl;
	}else{
		cout << n-e1-o1 << endl;
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define erep(i,N) for(int i = N - 1; i >= 0; i--)
const ll INF = 1000000000;
//const ll MOD = 1000000007;
const ld PI = (acos(-1));
using Graph = vector<vector<int>>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true;} return false;}
typedef pair<int, int> P;
typedef pair<ll,ll> PLL;
double rad(double a) {return a * 180 / PI;}

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

//dpTable
int dp[100050];

int main(){
    ll N;
    cin >> N;
    int sqrtN = sqrt(N);
    int A,B;
    for (int i = sqrtN; i >= 1; i--) {
        if (N % i == 0) {
            A = i;
            B = N / i;
            break;
        }
    }
    int cntA = 0,cntB = 0;
    while (A != 0) {
        A /= 10;
        cntA++;
    }
    while (B != 0) {
        B /= 10;
        cntB++;
    }
    cout << max(cntA,cntB) << endl;
    return 0;
}

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

int main(){
    // 制約見て！！！デカかったらlong longにすること！
    string s;
    cin >> s;
    int m = 753;
    rep(i,s.size()-2){
        string sub = s.substr(i,3);
        int x = stoi(sub);
        m = std::min(m,abs(x-753));
    }
    cout << m <<endl;
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

int main(){
  int n, m;
  while((n = getInt()) + (m = getInt())){
    vector<int> v(n);
    int ans = 0;
    REP(i,n) v[i] = getInt();
    sort(v.rbegin(), v.rend());
    REP(i,n) if(i % m != (m - 1))
      ans += v[i];
    print(ans);
  }
  return 0;
}

#include <iostream>
#include <set>

int main(){
    while (true) {
        int n;  // I will buy n vegetables.
        int m;  // One bag contains m vegetables.

        std::cin >> n >> m;
        std::cin.ignore();
        if ( n==0 && m==0 ) {
            return 0;
        }

        // input vegetable's cost.
        std::multiset<int, std::greater<int> > buy;
        int in;
        for (int i=0; i < n ; ++i) {
            std::cin >> in;
            buy.insert(in);
        }

        int cost = 0;  // How much must I pay?
        int x = 1;  // This is the 'x'th vegetable in the bag.
        while ( ! buy.empty() ) {
            // the first item in 'buy' is the most expensive.
            std::set<int>::iterator it = buy.begin();
            // the 'm'th item in the bag is free!
            if ( x > m-1 ) {
                x = 1;
            }else{
                cost += *it;
                ++x;
            }
            buy.erase(it);
        }

        // output
        std::cout << cost << std::endl;
    }

    return 0;
}


//Boxes and Candies

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define YN(flag) (flag?"Yes":"No")
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
using P = pair<ll,ll>;
using graph = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

signed main (){
    int n,x,ans=0;cin>>n>>x;
    vecrep(n,a,int);
    int t=a[0];
    rep(i,1,n){
        t+=a[i];
        if(t>x){
            int s=t-x;
            if(s>a[i]){
                s-=a[i];
                t-=a[i];
                ans+=a[i];
                a[i]=0;
                a[i-1]-=s;
            }else{
                a[i]-=s;
            }
            ans+=s;
            t-=s;
        }
        t-=a[i-1];
    }
    cout<<ans<<nnn;
    return 0;
}

#include <iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
#include<set>
#include<queue>
#include<deque>
#include<iomanip>
#include<sstream>
#include<cmath>
#include<tuple>
#include<bitset>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define req(i,n) for(int i = 1;i <=  n; i++)
#define rrep(i,n) for(int i = n -1;i >= 0;i--)
#define ALL(obj) begin(obj), end(obj)
typedef long long int ll;
typedef long double ld;
const ll INF = (1LL << 62);
ll n,k, m, t; string s;
const ld PI = acos(-1);
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
    std::fill((T*)array, (T*)(array + N), val);
}bool visit[410][410],b[410][410]; vector<vector<char>> c;
ll cc[2],ans = 0;
int dx[4] = { 0,0,1,-1 }, dy[4] = { 1,-1,0,0 };
void dfs(int x,int y) {
    cc[b[y][x]]++;
    rep(i, 4) {
        int nx = x + dx[i], ny = y + dy[i];
        if (nx < 0 || ny < 0 || nx >= m || ny >= n) continue;
        if (visit[ny][nx] || b[ny][nx] == b[y][x])continue;
        visit[ny][nx] = 1;
        dfs(nx, ny);
    }
}
int main() {
    cin >> n >> m; vector<vector<char>> c(n, vector<char>(m));
    Fill(visit, 0);
    rep(i, n) {
        rep(j, m) {
            cin >> c[i][j];
            b[i][j] = (c[i][j] == '#');
        }
    }
    rep(i, n) {
        rep(j, m) {
            if (visit[i][j]) continue;
            visit[i][j] = 1;
            cc[0] = 0; cc[1] = 0;
            dfs(j, i);
            ans += cc[0] * cc[1];
        }
    }cout << ans << endl;
}


#include <bits/stdc++.h>

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;
typedef tuple<ll, ll, ll, ll, ll> t5;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

using namespace std;

static const ll INF = 1e15;

template<typename T>
static inline void chmin(T& ref, const T  value) {
    if (ref > value) ref = value;
}

template<typename T>
static inline void chmax(T& ref, const T value) {
    if (ref < value) ref = value;
}

constexpr ll mod = 1000000007;

class modint {
	static constexpr std::int_fast64_t Modulus = 1e9 + 7;
	using u64 = std::int_fast64_t;

public:
	u64 a;
	constexpr modint(const u64 x = 0) noexcept : a(x% Modulus) {}
	constexpr u64& value() noexcept { return a; }
	constexpr const u64& value() const noexcept { return a; }
	constexpr modint operator+(const modint rhs) const noexcept {
		return modint(*this) += rhs;
	}
	constexpr modint operator-(const modint rhs) const noexcept {
		return modint(*this) -= rhs;
	}
	constexpr modint operator*(const modint rhs) const noexcept {
		return modint(*this) *= rhs;
	}
	constexpr modint& operator+=(const modint rhs) noexcept {
		a += rhs.a;
		if (a >= Modulus) {
			a -= Modulus;
		}
		return *this;
	}
	constexpr modint& operator-=(const modint rhs) noexcept {
		if (a < rhs.a) {
			a += Modulus;
		}
		a -= rhs.a;
		return *this;
	}
	constexpr modint& operator*=(const modint rhs) noexcept {
		a = a * rhs.a % Modulus;
		return *this;
	}
};

int main() {
    int n;
    cin >> n;
    vector<int> vs(n);
    rep(i, n) {
        cin >> vs[i];
    }
    vector<int> colors(3, 0);
    modint all = 1;
    rep(i, n) {
		int same = 0;
		rep(j, 3) {
			if (colors[j] == vs[i]) same++;
		}
		all *= same;
		rep(j, 3) {
			if (colors[j] == vs[i]) {
				colors[j]++;
				break;
			}
		}
    }
	cout << all.a << endl;
    return 0;
}

#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000

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

    int N;
    cin >> N;
    ll MOD = pow(10, 9) + 7;
    vector<ll> A(N);
    rep(i, N) {
        cin >> A[i];
        A[i]++;
    }

    vector<ll> dp(N, 0);
    ll ans = 1;
    dp[0] = 3;

    for (int i = 0; i < N; i++) {
        if (dp[A[i] - 1] == 0) {
            cout << 0 << endl;
            return 0;
        }

        ans *= dp[A[i] - 1];
        ans %= MOD;
        dp[A[i] - 1]--;
        dp[A[i]]++;
    }

    cout << ans << endl;
}


#include <iostream>
#include <tuple>
#include <vector>

int main()
{
    int h, w; std::cin >> h >> w;
    std::vector<std::vector<int>> a(h, std::vector<int>(w, 0));
    std::vector<std::tuple<int, int, int, int>> t;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            std::cin >> a[i][j];
            a[i][j] %= 2;
        }
    }
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w-1; j++) {
            if (a[i][j] == 1) {
                t.push_back(std::make_tuple(i+1, j+1, i+1, j+2));
                a[i][j+1] = (a[i][j+1] + 1) % 2;
                a[i][j] = 0;
            }
        }
    }

    for (int i = 0; i < h-1; i++) {
        if (a[i][w-1] == 1) {
            t.push_back(std::make_tuple(i+1, w, i+2, w));
            a[i+1][w-1] = (a[i+1][w-1] + 1) % 2;
            a[i][w-1] = 0;
        }
    }

    std::cout << t.size() << std::endl;
    for (const auto& tt: t) {
        std::cout
            << std::get<0>(tt) << " "
            << std::get<1>(tt) << " "
            << std::get<2>(tt) << " "
            << std::get<3>(tt) << std::endl;
    }

    return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
#define llong long long
int n,m;
int pos[200200];
int nxt[200200];
llong K;

bool vis[200200];
int sta[200200],top;

double ans[100100];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;++i) scanf("%d",&pos[i]),nxt[i]=i;
    for(int i=n;i;--i)pos[i]-=pos[i-1];
    scanf("%d%lld",&m,&K);
    int xx;
    for(int i=1;i<=m;++i)
        scanf("%d",&xx),swap(nxt[xx],nxt[xx+1]);
    for(int i=1;i<=n;++i)
        if(!vis[i])
        {
            xx=i; top=0;
            while(!vis[xx]) vis[xx]=1,sta[top++]=xx,xx=nxt[xx];
            for(int j=0;j<top;++j)
                ans[sta[j]]=pos[sta[(K+j)%top]];
        }
    for(int i=1;i<=n;++i)
    {
        ans[i]+=ans[i-1];
        printf("%.1lf ",ans[i]);
    }
    puts("");
    return 0;
}

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    vector<int> a(N);
    rep(i,N) cin >> a[i];
    double s = 0;
    rep(i,N) {
        s += a[i];
    }
    s /= N;
    double min = 10000;
    int min_num = 10000;
    for(int i = N-1; i >= 0; i--) {
        if (abs(s-a[i]) <= min){
            min = abs(s-a[i]);
            min_num = i;
        }
    }
    cout << min_num << endl;
    return 0;
}


// https://atcoder.jp/contests/nomura2020/tasks/nomura2020_a

#include<iostream>
#include<vector>//可変長配列
#include<algorithm>//sort,二分探索,など
#include<map>//map(辞書)

using namespace std;

int main(void){
    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    int wake = h1 * 60 + m1;
    int sleep = h2 * 60 + m2;
    int diff = sleep - wake - k;
    cout << diff << endl;
    return 0;
}

#define TEMPLATE_USED
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(ll)(a);i<(ll)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(ll)(n);++i)
#define _repe3(i,a,b) for(ll i=(ll)(a);i<=(ll)(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(ll)(b)-1;i>=(ll)(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#define _rrepe2(i,n) for(ll i=(ll)(n);i>=0;i--)
#define _rrepe3(i,a,b) for(ll i=(ll)(b);i>=(ll)(a);i--)
#define rrepe(...) _overload3(__VA_ARGS__,_rrepe3,_rrepe2)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
template<class T>
bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>
bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
template<class T>
using pq=priority_queue<T,vector<T>,greater<T>>;

vl H;
vl M;
ll K;

void solve();

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    H = vl(2);
    M = vl(2);
    for(int i = 0; i < 2; ++i){
        cin >> H[i];
        cin >> M[i];
    }
    cin >> K;
    solve();
}

// 0 < H_1, H_2 < 23
// 0 < M_1, M_2 < 59
// H_1 時 M_1 分は H_2 時 M_2 分より前の時刻である
// K > 1
// 高橋君が起きている時間の長さは K 分以上である
// 入力は全て整数である

// vl H, vl M, ll K
// 答えを整数として出力せよ。
void solve(){
    ll t=H[1]*60+M[1]-(H[0]*60+M[0]);
    cout<<t-K<<endl;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, v;
  cin >> n;
  int* ohash = (int*) calloc(100000, sizeof(int));
  int* ehash = (int*) calloc(100000, sizeof(int));
  for (int i = 0; i < n/2; i++) {
    cin >> v;
    ohash[v - 1]++;
    cin >> v;
    ehash[v - 1]++;
  }
  int omax = 0, emax = 0;
  for (int i = 0; i < 100000; i++) {
    if (ohash[i] > ohash[omax]) omax = i;
    if (ehash[i] > ehash[emax]) emax = i;
  }
  if (omax != emax) {
    cout << n - ohash[omax] - ehash[emax];
  }
  else {
    int omax2 = 0, emax2 = 0;
    for (int i = 0; i < 100000; i++) {
      if (ohash[i] > ohash[omax2] && i != omax) omax2 = i;
      if (ehash[i] > ehash[emax2] && i != emax) emax2 = i;
    }
    if (ohash[omax] == n/2 && ehash[emax] == n/2) {
      cout << n/2;
    }
    else if (ohash[omax] == n/2) {
      cout << n/2 - ehash[emax2];
    }
    else if (ehash[emax] == n/2) {
      cout << n/2 - ohash[omax2];
    }
    else {
      cout << min(n - ohash[omax] - ehash[emax2], n - ohash[omax2] - ehash[emax]);
    }
  }
  free(ohash);
  free(ehash);
  return 0;
}

#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

using vi = vector<int>;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define show(x) cout << #x << " = " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define sz(x) (int)(x).size()
#define YesNo {cout<<"Yes";}else{cout<<"No";}
#define YESNO {cout<<"YES";}else{cout<<"NO";}
#define v(T) vector<T>

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> bool lcmp(const pair<T, T>& l, const pair<T, T>& r) {
  return l.first < r.first;
}
template<class T> istream& operator>>(istream& i, v(T)& v) {
  F0R(j, sz(v)) i >> v[j];
  return i;
}
template<class A, class B> istream& operator>>(istream& i, pair<A, B>& p) {
  return i >> p.first >> p.second;
}
template<class A, class B, class C> istream& operator>>(istream& i, tuple<A, B, C>& t) {
  return i >> get<0>(t) >> get<1>(t) >> get<2>(t);
}
template<class T> ostream& operator<<(ostream& o, const vector<T>& v) {
  F0R(i, v.size()) {
    o << v[i] << ' ';
  }
  o << newl;
  return o;
}
template<class T1, class T2> ostream& operator<<(ostream& o, const map<T1, T2>& m) {
  for (auto& p : m) {
    o << p.first << ": " << p.second << newl;
  }
  o << newl;
  return o;
}

#if 1

// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int n;
  cin >> n;

  unordered_map<int, int> a, b;

  F0R(i, n) {
    int v;
    cin >> v;
    if (i & 1) {
      ++a[v];
    }
    else {
      ++b[v];
    }
  }
  vector<pair<int,int>> c, d;
  for (auto& p : a) c.emplace_back(p.second, p.first);
  for (auto& p : b) d.emplace_back(p.second, p.first);
  sort(rrng(c), lcmp<int>);
  sort(rrng(d), lcmp<int>);
  c.emplace_back(0, -1);
  d.emplace_back(0, -1);

  int r;
  if (c[0].second != d[0].second)
    r = n - c[0].first - d[0].first;
  else {
    r = n - max(c[0].first + d[1].first, c[1].first + d[0].first);
  }
  cout << r;
}
#endif


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

long long mod = 1e9+7;

int main(){
  int N;
  cin >> N;
  vector<long long> A(N);
  for(int i = 0; i < N; i++)
    cin >> A[i];
  long long ans = 0;
  long long sum = 0;
  long long sum2 = 0;

  for(int i = 0; i < N; i++){
    sum2 = (sum2 + A[i]*A[i]) % (2*mod);
    sum = (sum + A[i]) % (2*mod);
  }

  ans = (sum*sum - sum2)  % (2*mod) / 2;

  cout << ans << endl;
}

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template < typename T > using oset = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;
// find_by_order(k) (k+1)th largest element
// order_of_key(k) no of elements <=k

typedef long long ll;
typedef long double ld;
#define endl '\n'
#define rep(i,n)  for(ll i = 0; i < (n); ++i)
#define repA(i, a, n)  for(ll i = a; i <= (n); ++i)
#define repD(i, a, n)  for(ll i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (ll)(x).size()
#define ff first
#define ss second
#define pb push_back
typedef vector<ll> vll;
typedef vector<pair<ll,ll>> vpl;
const ld PI = 4*atan((ld)1);
const ll INF = LLONG_MAX;
const ll mod = 1e9+7;

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    ll tt=1;
        // cin >> tt;
    repA(qq,1,tt){
        ll n; cin >> n;
        vll a(n),suf(n);
        rep(i,n){
            cin >> a[i];
        }
        suf[n-1] = a[n-1];
        repD(i,n-2,0){
            suf[i] = suf[i+1]+a[i];
        }
        ll ans =0;
        rep(i,n-1){
            // cout << a[i] << " " << suf[i] << endl;
            ans += a[i]*(suf[i+1]%mod);
            ans %=mod;
        }

        cout << ans << endl;
    }
}


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

static const int NIL = -1;

struct Vertex {
    vector<int> link;
    int parent = NIL;
    int ord;
    int lowlink;
    bool is_visit = false;
};

class ArticulationPoint {
private:
    int n;
    vector<Vertex> graph;
    int timer = 1;

public:
    ArticulationPoint() {}

    ArticulationPoint(int n)
    {
        this->n = n;
        graph.resize(n);
        int edge;
        cin >> edge;
        int s, t;
        for (int e = 0; e < edge; e++)
        {
            cin >> s >> t;
            graph[s].link.push_back(t);
            graph[t].link.push_back(s);
        }
    }

    void dfs(int current)
    {
        graph[current].is_visit = true;
        graph[current].ord = graph[current].lowlink = timer;
        timer++;

        for(int next : graph[current].link)
        {
            if(!graph[next].is_visit)
            {
                graph[next].parent = current;
                dfs(next);
                graph[current].lowlink = min(graph[current].lowlink, graph[next].lowlink); // 3.
            }
            else if(next != graph[current].parent)
            {
                // １回の移動で行くことのできる訪問済みの頂点は，Backedgeを除けば自分の親しかいない
                // つまりこのブロックにくるのはnextがBackedgeを通った訪問済みの頂点のとき
                graph[current].lowlink = min(graph[current].lowlink, graph[next].ord);
            }

        }
    }

    void articulation_point()
    {
        set<int> art_point;
        int root = 0;

        dfs(root);

        int root_child_num = 0;
        for(int u = 0; u < n; u++)
        {
            int p = graph[u].parent;
            if(p == NIL) continue;
            if(p == root)
            {
                root_child_num++;
                if(root_child_num >= 2)
                    art_point.insert(root);
            }
            else if(graph[p].ord <= graph[u].lowlink)
            {
                art_point.insert(p);
            }
        }

        for(int x : art_point)
            cout << x << endl;
    }
};

int main()
{
    int n;
    cin >> n;
    ArticulationPoint articulationPoint(n);
    articulationPoint.articulation_point();
}

#include<bits/stdc++.h>
using namespace std;
#define INF 100010
typedef pair<int,int> P;
vector<int> G[100010];
vector<int> GG[100010];
int V,E,n;
int ord[100010];
int low[100010];
int par[100010];

int lowlink(int x,int p){
  ord[x]=n++,par[x]=p;
  int ans=ord[x];
  for(int i=0;i<G[x].size();i++){
    if(G[x][i]==p)continue;
    if(ord[G[x][i]]!=INF)ans=min(ord[G[x][i]],ans);
    else {
      ans=min(ans,lowlink(G[x][i],x));
      GG[x].push_back(G[x][i]);
    }
  }
  return low[x]=ans;
}

int main(){
  for(int i=0;i<100010;i++)
    low[i]=ord[i]=INF;
  cin>>V>>E;
  P p[100010];
  for(int i=0;i<E;i++){
    int s,t;
    cin>>s>>t;
    G[s].push_back(t);
    G[t].push_back(s);
    if(s>t)swap(s,t);
    p[i]=P(s,t);
  }
  sort(p,p+E);
  lowlink(0,-1);
  for(int i=0;i<V;i++){
    int f=0;
    if(i==0&&GG[0].size()>1)f=1;
    if(i!=0)
      for(int j=0;j<GG[i].size();j++){
	if(GG[i][j]==par[i])continue;
	if(low[GG[i][j]]>=ord[i])f=1;
	//cout<<i<<" "<<G[i][j]<<" "<<low[i]<<" "<<low[G[i][j]]<<" "<<f<<endl;
      }
    //cout<<low[i]<<endl;
    if(f)cout<<i<<endl;
  }
  return 0;
}


#include<iostream>
using namespace std;
int main(){
    unsigned long long int a,b,c,k;
    cin>>a>>b>>c>>k;
    unsigned long long int sum=a+b+c;
    unsigned long long int term=max(a,max(b,c));
    sum-=term;
    while(k)
    {
        term*=2;
        k--;
    }
    cout<<sum+term;
}

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793

int main(){
ll x;
cin >> x;
ll n=x%11;
ll m=x/11;
if(n==0)cout<< 2*m << endl;
else if(n<=6)cout << 2*m+1 << endl;
else cout << 2*m+2 << endl;

}


#include<bits/stdc++.h>

using namespace std;

inline int read() {
	int res=0,fh=1;
	char ch=getchar();
	while((ch>'9'||ch<'0')&&ch!='-')ch=getchar();
	if(ch=='-')fh=-1,ch=getchar();
	while(ch>='0'&&ch<='9')res=res*10+ch-'0',ch=getchar();
	return fh*res;
}

const int maxn=16;
int n,m,mxs,sum[(1<<16)+12],a[maxn][maxn];
int f[(1<<maxn)][maxn];
inline int Max(int a,int b){return a>b?a:b;}

int main(){
	n=read(),m=read();
	mxs=(1<<n)-1;
	for(int i=1;i<=m;i++){
		int x=read()-1,y=read()-1,z=read();
		a[x][y]=a[y][x]=z;
	}
	for(int i=0;i<=mxs;i++){
		sum[i]=0;
		for(int j=0;j<n;j++)
			if((i&(1<<j)))
				for(int k=j+1;k<n;k++)
					if((i&(1<<k))) sum[i]+=a[j][k];
	}
	memset(f,-1,sizeof f);
	f[1][0]=0;
	for(int i=1;i<=mxs;i+=2){
		for(int j=0;j<n;j++){
			if(f[i][j]==-1) continue;
			if(!(i&(1<<j))) continue;
			for(int k=0;k<n;k++)
				if(a[j][k]&&(!(i&(1<<k))))
					f[i|(1<<k)][k]=Max(f[i|(1<<k)][k],f[i][j]+a[j][k]);
			int c=(mxs-i)|(1<<j);
			for(int k=c;k>=0;k=(k==0?-1:(k-1)&c))
				f[i|k][j]=Max(f[i][j]+sum[k],f[i|k][j]);
		}
	}
	int ans=0;
	for(int i=(mxs>>1)+2;i<=mxs;i+=2)
		ans=Max(ans,f[i][n-1]);
	printf("%d\n",sum[mxs]-ans);
	return 0;
}

#include <stdio.h>
#include <vector>
#include <set>
#include <utility>
using namespace std;
typedef long long ll;

int main(void) {
  ll i, j, k, l, n, m, a, b, now, min;
  scanf("%lld%lld", &n, &m);
  vector<ll> vec[n], rev[n];
  ll d[n], be[n];
  pair<ll, ll> p;
  for(i = 0; i < m; ++i) {
    scanf("%lld%lld", &a, &b);
    vec[--a].push_back(--b);
    rev[b].push_back(a);
  }
  for(i = 0; i < n; ++i) {
    set< pair<ll, ll> > s;
    for(j = 0; j < n; ++j) d[j] = 1e9;
    d[i] = 0;
    for(j = 0; j < n; ++j) s.insert(make_pair(d[j], j));
    while(s.size()) {
      p = *s.begin(), s.erase(s.begin());
      if(p.first == 1e9) break;
      for(j = 0; j < vec[p.second].size(); ++j) if(d[vec[p.second][j]] > p.first + 1) {
        s.erase(make_pair(d[vec[p.second][j]], vec[p.second][j]));
        d[vec[p.second][j]] = p.first + 1;
        be[vec[p.second][j]] = p.second;
        s.insert(make_pair(p.first + 1, vec[p.second][j]));
      }
    }
    for(j = 0; j < rev[i].size(); ++j) if(d[rev[i][j]] != 1e9) {
      vector<ll> ans;
      now = rev[i][j];
      while(now != i) ans.push_back(now), now = be[now];
      ans.push_back(i);
      min = ans.size();
      ll flg[n];
      for(k = 0; k < n; ++k) flg[k] = ans.size();
      flg[i] = ans.size() - 1;
      for(now = ans.size() - 2; now >= 0; --now) {
        for(k = 0; k < vec[ans[now]].size(); ++k) if(flg[vec[ans[now]][k]] < min) min = flg[vec[ans[now]][k]];
        if(min != ans.size()) break;
        flg[ans[now]] = now;
      }
      printf("%lld\n", min - now + 1);
      for(k = min; k >= now; --k) printf("%lld\n", ans[k] + 1);
      return 0;
    }
  }
  printf("-1");
  return 0;
}


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

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

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

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

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

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

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

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

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

int main() {
  int K, T;
  cin >> K >> T;
  vector<int> a(T);
  cin >> a;
  auto itr = max_element(a.begin(), a.end());
  int ans = *itr - (K - *itr) - 1;
  cout << max(0, ans) << endl;
  return 0;
}

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

int main() {
  int N, K; cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  for (int i = 0; i < K; i++) {
    vector<int> B(N+1, 0);
    for (int j = 0; j < N; j++) {
      int left = max(0, j - A.at(j));
      int right = min(N, j + A.at(j) + 1);
      B.at(left)++; B.at(right)--;
    }
    for (int j = 0; j < N; j++) B.at(j+1) += B.at(j);
    B.pop_back();
    if (A == B) break;
    A = B;
  }
  for (int i = 0; i < N; i++) {
    if (i) cout << " ";
    cout << A.at(i);
  }
  cout << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define INF 1e8
typedef long long int ll;
const double PI = acos(-1);

using Graph = vector<vector<int>>;
int main() {
  int n, m;
  cin >> n >> m;
  int s[m];
  char c[m];
  rep(i, m) { cin >> s[i] >> c[i]; }
  for (int i = 0; i < pow(10, n); i++) {
    string str = to_string(i);
    bool flag = true;
    rep(j, m) {
      if (str[s[j] - 1] != c[j]) {
        flag = false;
        break;
      }
    }
    if (flag && str.length() == n) {
      cout << str << endl;
      return 0;
    }
  }
  cout << "-1" << endl;
}

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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n, m;
    cin >> n >> m;
    vi s(m), c(m);
    rep(i, m) {
        cin >> s[i] >> c[i];
        s[i]--;
    }
    vi q(n, -1);
    rep(i, m) {
        if (q[s[i]]!=-1 && q[s[i]]!=c[i]) {
            cout << -1 << endl;
            return 0;
        }
        else q[s[i]] = c[i];
    }
    if (n>1 && q[0]==0) {
        cout << -1 << endl;
        return 0;
    }
    int b = 1, e = 10;
    rep(i, n-1) {
        b *= 10; e *= 10;
    }
    if (n == 1) b = 0;
    for (int i=b; i<e; ++i) {
        int i2 = i;
        bool ok = true;
        repr(j, n) {
            if (q[j]!=-1 && i2%10!=q[j]) ok = false;
            i2 /= 10;
        }
        if (ok) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=1e5+7;
LL jmp,a,k,n,m,x[N],y[N],p[N],g[N],siz[N],tot,cnt,sum;
bitset <N> vis;
int main()
{
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)scanf("%lld",&x[i]),p[i]=i;
	for(int i=1;i<=n;i++)y[i]=x[i]-x[i-1];
	scanf("%lld%lld",&m,&k);
	for(int i=1;i<=m;i++)
	{
		scanf("%lld",&a);
		swap(p[a],p[a+1]);
	}
	for(int i=1;i<=n;i++)if(!vis[i])
	{
		++cnt;int res=i;
		while(!vis[res])
			g[res]=cnt,vis[res]=1,res=p[res],++siz[cnt];
	}
	for(int i=1;i<=n;i++)
	{
		jmp=k%siz[g[i]];
		int res=i;
		if(jmp)while(jmp--)res=p[res];
		sum+=y[res];
		printf("%lld.0\n",sum);
	}
}

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

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

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007

//ここから編集する
class Solve {
public:
    void input() {

    }

    vector<int> mul(vector<int> f, vector<int> g) {
        int n = f.size();
        vector<int> ret(n);
        rep(i, 0, n) {
            ret[i] = g[f[i]];
        }
        return ret;
    }

    void solve() {
        input();
        int N;
        cin >> N;
        vector<ll> x(N);
        rep(i, 0, N) cin >> x[i];

        int M;
        ll K;
        cin >> M >> K;
        vector<int> a(M);
        rep(i, 0, M) {
            cin >> a[i];
        }

        vector<int> base(N - 1);
        rep(i, 0, N - 1) base[i] = i;
        vector<int> f = base;

        for (int i = 0; i < M; ++i) {
            swap(base[a[i] - 2], base[a[i] - 1]);
        }

        ll rest = K;
        while (rest > 0) {
            if (rest & 1) f = mul(f, base);
            base = mul(base, base);
            rest >>= 1;
        }

        vector<ll> d(N - 1);
        vector<ll> neko(N - 1);
        for (int i = 0; i < N - 1; ++i) {
            d[i] = x[i + 1] - x[i];
        }
        for (int i = 0; i < N - 1; ++i) {
            neko[i] = d[f[i]];
        }
        vector<ll> ans(N);
        ans[0] = x[0];
        for (int i = 1; i < N; ++i) {
            ans[i] = ans[i - 1] + neko[i - 1];
        }

        for (int i = 0; i < N; ++i) {
            cout << ans[i] << endl;
        }

        return;

    }
};

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

    Solve().solve();

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,k,s=1;cin>>n>>k;
    for(int i=0;i<n;i++)
        if(s*2<=s+k)
        s*=2;
    else s+=k;
    cout<<s;
    return 0;
   }

#include "bits/stdc++.h"

using namespace std;

void Main() {
    int A, B;
    cin >> A >> B;

    if (A <= 8 && B <= 8) {
        cout << "Yay!" << endl;
    }
    else {
        cout << ":(" << endl;
    }
}

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


#include<bits/stdc++.h>
using namespace std;
int main(){
long long int n;
cin>>n;
cout<<fixed<<setprecision(20)<<n*6.28318530717958623200<<endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long int x;
    cin>>x;
    if (x<=6) {
        cout<<1<<endl;
    } else {
        if (x%11==0) {
            cout<<2*(x/11)<<endl;
        } else if (x%11<=6) {
            cout<<2*(x/11)+1<<endl;
        } else {
            cout<<2*(x/11)+2<<endl;
        }
    }
}


#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
double PI = 3.1415926535897932;
const double EPS = 1e-9;
const ll MOD = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;

vector<pl> toppo (pl *p, int si) {
    sort(p, p+si);
    vector<pl> ret;
    ret.push_back(p[0]);
    for (int i = 1; i < si; i++) {
        while (ret.size() > 1) {
            int tmp = ret.size()-1;
            if ((p[i].second-ret[tmp-1].second)*(ret[tmp].first-ret[tmp-1].first) >=
                (ret[tmp].second-ret[tmp-1].second)*(p[i].first-ret[tmp-1].first)) {
                ret.pop_back();
            } else {
                break;
            }
        }
        ret.push_back(p[i]);
    }
    vector<pl> ret2;
    ret2.push_back(p[si-1]);
    for (int i = si-2; i >= 0; i--) {
        while (ret2.size() > 1) {
            int tmp = ret2.size()-1;
            if ((p[i].second-ret2[tmp-1].second)*(ret2[tmp].first-ret2[tmp-1].first) >=
                (ret2[tmp].second-ret2[tmp-1].second)*(p[i].first-ret2[tmp-1].first)) {
                ret2.pop_back();
            } else {
                break;
            }
        }
        ret2.push_back(p[i]);
    }
    ret2.pop_back();
    for (int i = 1; i < ret2.size(); i++) ret.push_back(ret2[i]);
    return ret;
}

int n;
pl pos[100], tmp[100];
double ans[100];

int main() {
    cin >> n;
    rep(i,n) cin >> pos[i].first >> pos[i].second;
    rep(i,n) tmp[i] = pos[i];
    vector<pl> topp = toppo(tmp, n);
    int si = topp.size();
    for (int i = 0; i < si; i++) {
        pl pre = topp[(i-1+si)%si];
        pl now = topp[i];
        pl nxt = topp[(i+1)%si];
        double dy1 = now.second-pre.second, dx1 = now.first-pre.first;
        double dy2 = nxt.second-now.second, dx2 = nxt.first-now.first;
        double d1 = atan2(dy1, dx1);
        double d2 = atan2(dy2, dx2);
        double d = abs(d1-d2);
        if (d > PI) d = 2*PI-d;
        rep(j,n) {
            if (topp[i] == pos[j]) {
                ans[j] = d/(2*PI);
            }
        }
    }
    rep(i,n) {
        printf("%.9f\n", ans[i]);
    }
}

#include <bits/stdc++.h>
using namespace std;
#define int long long
// Big two primes
#define X 1001100011100001111ll
#define mod 1000000007
#define ll long long
#define all(a) a.begin(),a.end()
#define sortall(a) sort(all(a))
#define fo(i, n) for (int i = 0; i < n; i++)
#define fo1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define nloop(i,a,b) for (int i = a ; i>=b;i--)
#define tc(t) int t; cin >> t; while (t--)
#define arrip(a,n)  int a[n]; fo(i, n) cin >> a[i];
#define arrop(n)  fo(i,n) cout<<a[i]<<" ";
#define pb push_back
#define mp make_pair
#define itr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626

#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define rr return 0
#define prec(n) fixed<<setprecision(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define inf (int)(1e18)
#define ini(a, i) memset(a, i, sizeof(a))
#define vi vector<int>
#define fi first
#define se second
#define endl "\n"
#define pi pair<int, int>
#define vpi vector<pi>
#define sz(s) s.size()
#define bits(n) __builtin_popcount(n)//Count set bits

const int MAXN = (int)((1e5) + 100);
int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a);}
int max(int a, int b) {if (a > b) return a; else return b;}
int min(int a, int b) {if (a < b) return a; else return b;}

int32_t main()
{
#ifndef ONLINE_JUDGE
	freopen("atcoderi.txt", "r", stdin);
	freopen("atcodero.txt", "w", stdout);
#endif
	fio;

	int n = 5, k;
	arrip(a, n);
	cin >> k;
	bool f = true;
	fo(i, 5)
	{
		for (int j = i + 1; j < 5; j++)
		{
			int res = abs(a[i] - a[j]);
			if (res > k)
				f = false;
		}
	}
	if (f == false)
		cout << ":(" << endl;
	else
		cout << "Yay!" << endl;
}


#include <bits/stdc++.h>

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

using namespace std;

using ll = long long;

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

    int N, K;
    cin >> N >> K;
    K = min(K, 50);
    vector<int> A(N);
    REP(i, N) cin >> A[i];

    while (K-- > 0) {
        vector<int> B(N + 1);
        REP(i, N) {
            B[max(i - A[i], 0)] += 1;
            B[min(i + A[i] + 1, N)] -= 1;
        }
        REP(i, N) {
            B[i + 1] += B[i];
        }
        A = B;
    }

    REP(i, N) {
        cout << A[i] << " ";
    }
    cout << endl;

    return 0;
}

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

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

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

  vector<int> b(n+1);
  vector<int> c(n);
  int count = 0;

  for(int i=1; i<=k; i++){

      for(int i=0; i<n; i++){
        b[max(1,1+i-a[i])-1]++;
        b[min(n,1+i+a[i])]--;
      }

      for(int i=0; i<n; i++){
        if(i == 0) c[i] = b[i];
        else c[i] += c[i-1] + b[i];
      }

      for(int i=0; i<n; i++){
       a[i] = c[i];
       b[i] = 0;
       c[i] = 0;
      }

      for(int i=0; i<n; i++){
        if(a[i] == n) count++;
     }

     if(count == n){
            break;
     }

        count = 0;

  }

  if(n == 1) cout << a[0] << endl;
  else{
    for(int i=0; i<n-1; i++) cout << a[i] << " ";
    cout << a[n-1] << endl;
  }
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+5;
int n,q;
char s[N];
ll dp[N],f[N],sumd[N],summ[N];
int main()
{
    scanf("%d",&n);
    scanf("%s",s+1);
    scanf("%d",&q);
    for(int i=1;i<=n;i++)
    {
        sumd[i]=sumd[i-1]+(s[i]=='D');
        summ[i]=summ[i-1]+(s[i]=='M');
        dp[i]=dp[i-1];
        f[i]=f[i-1];
        if(s[i]=='M') dp[i]+=sumd[i];
        if(s[i]=='C') f[i]+=dp[i];
    }
    while(q--)
    {
        ll ans=f[n];
        int k;scanf("%d",&k);
        for(int i=k;i<=n;i++)
            if(s[i]=='C')
            ans-=dp[i-k]+(summ[i]-summ[i-k])*sumd[i-k];
        printf("%lld\n",ans);
    }
}

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <list>
#include <utility>
#include <tuple>
#include <cstdio>
#include <set>
#include <queue>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <cmath>
#define _GLIBCXX_DEBUG
using namespace std;
const long long INF = 1LL << 60;
typedef long long ll;
int main() {
    int A,B,M;
    cin >> A >> B >> M;
    //
    vector<int> a(A);
    for(int i=0;i<A;i++){
        cin >> a[i];
    }
    //
    vector<int> b(B);
    for(int i=0;i<B;i++){
        cin >> b[i];
    }
    //
    vector<int> x(M);
    vector<int> y(M);
    vector<int> c(M);
    for(int i=0;i<M;i++){
        cin >> x[i] >> y[i] >> c[i] ;
    }
    //
    ll price;
    ll min_price;
    for(int i=0;i<M;i++){
        price = a[x[i]-1] + b[y[i]-1] - c[i];
        if(i==0){
            min_price = price;
        }
        else if(min_price > price){
            min_price = price;
        }
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    price = a[0] + b[0];
    if(min_price > price){
        min_price = price;
    }
    cout << min_price << endl;
}


#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;

int main(void) {
    int n, i, j, l[30] = {};
    ll ans = 1;
    string a;

    cin >> a;

    n = a.size();

    for (i = 0; i < n; i++) {
        l[a[i] - 'a']++;
    }

    for (i = 0; i < 26; i++) for (j = i + 1; j < 26; j++) {
        ans += (ll)l[i] * l[j];
    }

    cout << ans << endl;

    return 0;
}

#pragma GCC optimize ("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
#define all(x) x.begin(), x.end()
#define trav(i,a) for(auto &i:a)
inline int in(){int x;scanf("%lld",&x);return x;}
int f[26];
const int N=2e5+4;
int32_t main()
{
	string s;
	cin>>s;
	int n=s.length();
	int ans=1;
	for(int i=0;i<n;i++)
	{
		int cur=s[i]-'a';
		int len=i+1;

		ans+=i-f[cur];
		f[cur]++;
	}
	cout<<ans;
}


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

vector< int >apply(const vector< int >&v) {
    int n = v.size();
    vector< int >cu(n, 0);
    for (int i = 0; i < n; i++) {
        int l = max(i-v[i], 0);
        int r = min(i+v[i], n-1);
        cu[l]++;
        if (r+1 < n) cu[r+1]--;
    }
    for (int i = 1; i < n; i++) cu[i] += cu[i-1];
    return cu;
}

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

    vector< int >a(n);
    for (int &x : a) cin >> x;

    while (k--) {
        vector< int >r = apply(a);
        if (a == r) break;
        swap(a, r);
    }

    for (int i = 0; i < n; i++) cout << a[i] << " ";

    return 0;
}

#include<bits/stdc++.h>
typedef  long long int ll;
typedef  long double ld;
#define sync ios_base::sync_with_stdio(false); cin.tie(NULL)
#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) *s.find_by_order(ind)
using namespace std;

const int N = 1e6 + 5;
int main()
{
	sync;
	ll n;
	cin >> n;
	ll a[n], b[n], c[n];
	input(a, n);
	input(b, n);
	sort(b, b + n, greater<ll>());
	ll l = 1e9, r = -1;
	for(ll i = 0 ; i < n; i++)
	{
		if(a[i] == b[i])
		{
			l = min(l, i);
			r = max(r, i);
		}
	}
	if(r != -1)
	{
		for(ll i = 0; i < n; i++)
		{
			if(l > r)
				break;
			if(a[i] != a[r] && b[i] != a[r])
			{
				swap(b[l], b[i]);
				l++;
			}
		}
	}
	if(l <= r)
		cout << "No";
	else
	{
		cout << "Yes\n";
		for(ll i = 0; i < n; i++)
			cout << b[i] << " ";
	}
}


#include <iostream>
#include <vector>
#include <set>
#include <deque>
#include <map>
#include <iomanip>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <utility>
using namespace std;
int ky[8] = {-1,1,-2,2,-2,2,-1,1};
int kx[8] = {-2,-2,-1,-1,1,1,2,2};
int dy[4] = {-1,0,1,0};
int dx[4] = {0,1,0,-1};
int ddy[8] = {-1,0,1,-1,1,-1,0,1};
int ddx[8] = {-1,-1,-1,0,0,1,1,1};
typedef long long ll;
#define pi pair
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define rep1(i,a,b) for(int i = a; i < b; i++)
#define rep2(i,a,b) for(int i = a; i <= b; i++)
#define INF 999999999999
const double PI = acos(-1.0);
ll n;
ll num;
ll cnt;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    cin >> n;
    num = 26;
    cnt = 1;
    while(n > num){
        n -= num;
        num *= 26;
        cnt++;
    }

    string ans(cnt, '0');
    --n;
    for(int i = cnt - 1; i >= 0; i--){
        ans[i] = (n % 26) + 'a';
        n /= 26;
    }
    cout << ans;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1e17;
const int inf = 1e5;
typedef long double ld;
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; }
ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

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

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};
struct SegmentTree{
  int N;
  vector<int> node;
  public :
    void intit(vector<int>v){
      int sz = v.size();
      N=1;
      while(N<sz) N*=2;
      node.resize(N);
      for(int i=0 ; i<sz ; i++) node[i+N-1] = v[i];
      for(int i=N-2 ; i>=0 ; i--) node[i] = min(node[i*2+1], node[i*2+2]);
    }
    void update(int x, int val){
      x += N-1;
      node[x+N-1] = val;
      while(x>0){
        x = (x-1)/2;
        node[x] = min(node[x*2+1], node[x*2+2]);
      }
    }
    int getmin(int a, int b, int k, int l, int r){
      if(b<=l || r<=a) return inf;
      else if(a<=l && r<=b) return node[k];
      else{
        int vl = getmin(a, b, 2*k+1, l, (l+r)/2);
        int vr = getmin(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
      }
    }
};
vector<ll> divisor(ll n){
  vector<ll> res;
  for(ll i=1; i*i<=n ; i++){
    while(n%i==0){
      ++res[i];
      n /= i;
    }
  }
  if(n!=1) res[n]=1;
  return res;
}
int main(){
  ll n; cin >> n;
  ll k = n;
  int cnt = 1;
  while(true){
    ll now = pow(26, cnt);
    if(k - now > 0){
        k -= now;
        cnt++;
    }else{
        break;
    }
  }

  string ans = "";
  k--;
  for(int i=cnt-1 ; i>=0 ; i--){
      ll now = pow(26, i);
      ll st = k / now;
      for(char c='a' ; c<='z' ; c++){
          if(c - 'a' == st){
              ans += c;
          }
      }
      k -= now * st;
  }
  cout << ans << endl;
  return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <string>
#include <sstream>
using namespace std;

#define MAX_N 10

int n, k;
vector<int> cs;
set<string> ps;

string to_s(int r) {
	ostringstream os;
	os << r;
	return os.str();
}

bool used[MAX_N];
void enumerate(int k_) {
	if (k_ == k) {
		vector<string> part;
		for (int i = 0; i < n; i++) {
			if (used[i]) {
				part.push_back(to_s(cs[i]));
			}
		}
		sort(part.begin(), part.end());
		do {
			string p = "";
			for (int i = 0; i < k; i++) p.append(part[i]);
			ps.insert(p);
		} while (next_permutation(part.begin(), part.end()));
		return;
	}
	for (int i = 0; i < n; i++) {
		if (!used[i]) {
			used[i] = true;
			enumerate(k_ + 1);
			used[i] = false;
		}
	}
}

int main() {
	while (cin >> n >> k) {
		if (n == 0 && k == 0) break;
		cs.clear();
		cs.resize(n);
		ps.clear();
		for (int i = 0; i < MAX_N; i++) used[i] = false;
		for (int i = 0; i < n; i++) cin >> cs[i];
		enumerate(0);
		cout << ps.size() << endl;
	}
	return 0;
}

#include <iostream>
using namespace std;

int main(){
    while(1){
        int n, nums[10] = {0};
        cin >> n;
        if(!n) break;

        for(int i = 0;i < n;i++){
            int k;
            cin >> k;
            nums[k]++;
        }

        for(int i = 0;i < 10;i++){
            if(nums[i] == 0) cout << "-";
            else{
                for(int j = 0;j < nums[i];j++) cout << "*";
            }
            cout << endl;
        }
    }
    return 0;
}


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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  int N, K;
while(
  cin >> N >> K,N){
  VI xs(N);
  REP(i,N) cin >> xs[i];

  SORT(xs);
  set<int> ans;
  do{
	int s = 0;
	REP(i,K){
	  s = s * (xs[i] >= 10? 100: 10) + xs[i];
	}
	ans.insert(s);
  }while(next_permutation(ALL(xs)));

  cout << SZ(ans) << endl;
 }
  return 0;
}

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

template < class BidirectionalIterator >
bool next_combination(BidirectionalIterator first1,
	BidirectionalIterator last1,
	BidirectionalIterator first2,
	BidirectionalIterator last2)
{
	if ((first1 == last1) || (first2 == last2)) {
		return false;
	}
	BidirectionalIterator m1 = last1;
	BidirectionalIterator m2 = last2; --m2;
	while (--m1 != first1 && !(*m1 < *m2)) {
	}
	bool result = (m1 == first1) && !(*first1 < *m2);
	if (!result) {
		// ???
		while (first2 != m2 && !(*m1 < *first2)) {
			++first2;
		}
		first1 = m1;
		std::iter_swap(first1, first2);
		++first1;
		++first2;
	}
	if ((first1 != last1) && (first2 != last2)) {
		// ???
		m1 = last1; m2 = first2;
		while ((m1 != first1) && (m2 != last2)) {
			std::iter_swap(--m1, m2);
			++m2;
		}
		// ??¢
		std::reverse(first1, m1);
		std::reverse(first1, last1);
		std::reverse(m2, last2);
		std::reverse(first2, last2);
	}
	return !result;
}

template < class BidirectionalIterator >
bool next_combination(BidirectionalIterator first,
	BidirectionalIterator middle,
	BidirectionalIterator last)
{
	return next_combination(first, middle, middle, last);
}

int main() {
	while (1) {
		int N; cin >> N; int K; cin >> K;
		if (!N)break;
		vector<string>sts;
		for (int i = 0; i < N; ++i) {
			string st; cin >> st;
			sts.emplace_back(st);
		}
		vector<int>nums(N);
		iota(nums.begin(), nums.end(), 0);
		set<string>anss;
		do {
			vector<int>anums(K);
			iota(anums.begin(), anums.end(), 0);
			do {
				string ans;
				for (int i = 0; i < K; ++i) {
					ans += sts[nums[anums[i]]];
				}
				anss.emplace(ans);
			} while (next_permutation(anums.begin(), anums.end()));
		} while (next_combination(nums.begin(),nums.begin()+K, nums.end()));
		cout << anss.size() << endl;
	}
	return 0;
}


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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    int ans = 0;
    multiset<int> s(a.begin(), a.end());
    while(!s.empty()) {
        auto it = prev(s.end());
        int a = *it;
        s.erase(it);
        int b = (1LL << (32 - __builtin_clz(a))) - a;
        it = s.find(b);
        if(it != s.end()) {
            ans++;
            s.erase(it);
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  int ans = 1e9;
  rep(i, n) {
    int c = 0;
    while (a[i] % 2 == 0) {
      a[i] /= 2;
      c++;
    }
    ans = min(ans, c);
  }
  cout << ans << endl;
  return 0;
}


#include <bits/stdc++.h>
#define len(v) ((int)((v).size()))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define chmax(x, v) x = max((x), (v))
#define chmin(x, v) x = min((x), (v))
using namespace std;
using ll = long long;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s; cin >> s;
	vector<char> r;
	for (char c : s) {
		if (r.empty() || r.back() == 'T' || c == 'S')
			r.push_back(c);
		else
			r.pop_back();
	}
	cout << len(r) << "\n";
}

#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <random>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;

typedef
tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> orderedSet;

#define pb push_back
#define F first
#define S second
#define all(a) (a).begin(), (a).end()

#define for1(i0, l0, r0) for (int i0 = l0; i0 < r0; ++i0)
#define for2(i0, l0, r0) for (int i0 = l0; i0 <= r0; ++i0)
#define forn(i0, n0) for (int i0 = 0; i0 < n0; ++i0)
#define forn1(i0, n0) for (int i0 = 1; i0 < n0; ++i0)
#define forr(i0, n0) for (int i0 = n0; i0 >= 0; --i0)
#define forr1(i0, r0, l0) for (int i0 = r0; i0 > l0; --i0)
#define forr2(i0, r0, l0) for (int i0 = r0; i0 >= l0; --i0)

#define Sort(a) sort(all(a))
#define Reverse(a) reverse(all(a))
#define relaxMax(a, b) a = max(a, b)
#define relaxMin(a, b) a = min(a, b)

typedef long double ld;
#define ui unsigned int
#define ull unsigned long long

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef pair<string, string> pss;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<bool> vb;
typedef vector<string> vs;

typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<pdd> vpdd;

typedef vector<vi> vvi;
typedef vector<vd> vvd;
typedef vector<vll> vvll;
typedef vector<vb> vvb;

#define vpss vector<pss>
#define vvs vector<vs>
#define vvpii vector<vpii>
#define vvpll vector<vpll>
#define vpt vector<pt>
#define vvvi vector<vvi>
#define vsi vector<set<int>>
#define ss second
#define ff first

#define printvi(arr) for (int x0 : arr) cout << x0 << ' '; cout << '\n';
#define printvll(arr) for (ll x0 : arr) cout << x0 << ' '; cout << '\n';
#define printpair(pair0) cout << pair0.F << ' ' << pair0.S << '\n';
#define printvp(arr) for (auto pair0 : arr) printpair(pair0);
#define initArray(arr, N0, X0) memset(arr, X0, N0 * sizeof(int))
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void init() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //cout.precision(16);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
}

void solve() {
    string s;
    cin >> s;
    int n = s.length();
    vi l(n, -1), r(n, -1);
    forn(i, n){
        if (i > 0) l[i] = i - 1;
        if (i + 1 < n) r[i] = i + 1;
    }
    int ans = n;
    queue<int> q;
    forn(i, n - 1){
        if (s[i] == 'S' && s[i + 1] == 'T') q.push(i);
    }
    while (!q.empty()){
        int i = q.front();
        q.pop();
        ans -= 2;
        int j = r[i], i1 = l[i], j1 = r[j];
        if (i1 == -1 || j1 == -1) continue;
        r[i1] = j1;
        l[j1] = i1;
        if (s[i1] == 'S' && s[j1] == 'T') q.push(i1);
    }
    cout << ans << '\n';
}

bool multitest = false;

int main() {
    init();
    int t = 1;
    if (multitest) cin >> t;
    forn(i, t) solve();
}


//Counting of Trees

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
using p = pair<ll, string>;
using graph = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

int mpow(int a,int b,int mod){
    int ans = 1;
    rep(i,0,b)ans=(ans*a)%mod;
    if(b==0)return 0;
    else return ans;
}

signed main (){
    int n;cin>>n;
    map<int,int>m{};
    int t = 0,ans = 1;
    rep(i,0,n){
        int a;cin>>a;
        if(i==0&&a!=0){
            cout<<0<<nnn;
            return 0;
        }
        m[a]++;
        t = max(t,a);
    }
    if(m[0]!=1){
        cout<<0<<nnn;
        return 0;
    }
    rep(i,1,t+1){
        ans=(ans*mpow(m[i-1],m[i],998244353))%998244353;
    }
    cout<<ans<<nnn;
    return 0;
}

/**-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
*-*                                                               *-*
*-*                  Bismillahir Rahmanir Rahim                   *-*
*-*                                                               *-*
*-*                  Author: Ahsan Habib (comrade)                *-*
*-*                    Metropolitan University                    *-*
*-*                         Language: C++                         *-*
*-*                                                               *-*
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**/
#include<bits/stdc++.h>
#include<istream>
#include<cstdio>
#define pii          pair<ll,ll >
#include<string>
#define In freopen("ahsan.txt","r",stdin);
#define ll long long
#define ff first
#define ss second
#define NO cout<<"NO"<<endl
#define m1 cout<<"-1"<<endl
#define No cout<<"No"<<endl
#define cinarr0(n) for(int i = 0;i<n;i++)cin>>a[i];
#define cinarr1(n) for(int i = 1;i<=n;i++)cin>>a[i];
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define pb push_back
#define sorta(a) sort(a,a+n)
#define sortv(v)  sort(v.begin,v.end())
#define bug(a) cerr << #a << " : " << a << endl
#define all(v) (v.begin(), v.end())
#define   sz(x)       x.size()
#define fill(x, y) memset(x, y, sizeof(x))
const int mx = 1e6+5;
const ll md = 1e9+7;
using namespace std;
ll a[200010],m,ans,i,t,k,ev=0,od=0,tt=0,n,cas = 1;
vector<int>vec[mx];
int ar[10000][10000];
vector<pii>v;
bool ok = true;
int main()
{
    //In;
  ///  ios::sync_with_stdio(false);
    ///cin.tie(0);
    ll   n,tot  = 0;

    cin>>n;
    vector<ll>a(n);
    ll ans = 0;
    int md = 1000000007;
    for(int i = 0 ; i <n; i++)
    {
        cin>>a[i];
        tot  = tot + a[i];
        tot = tot % md;
    }

    for(int i = 0 ; i <n; i++)
    {
         tot = tot - a[i];
         if(tot<0)tot+=md;
         ans = ans + a[i]*tot;
         //bug(ans);
         ans = ans%md;
    }
    cout<<ans<<endl;

    return 0;
}


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

typedef long long ll;
using namespace std;
int main()
{
  ll x;
  cin>>x;
  if(x<11){
    if(x<=6){
      cout<<1<<endl;
    }else{
      cout<<2<<endl;
    }
  }else{
    if(x%11==0){
      cout<<2*(x/11)<<endl;
    }else if(x%11<=6){
      cout<<2*(x/11)+1<<endl;
    }else{
      cout<<2*(x/11)+2<<endl;
    }
  }

  return 0;
}

#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  ll x;
  cin >> x;
  ll ans = x/11*2;
  if(x%11>0) ++ans;
  if(x%11>6) ++ans;
  cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;

int main() {
    int n, u, v; cin >> n >> u >> v;
    vector<vector<int>> g(n+1);
    rep(i, n-1){
        int a, b; cin >> a >> b;
        g.at(a).push_back(b);
        g.at(b).push_back(a);
    }

    vector<int> distU(n+1, -1);
    vector<int> distV(n+1, -1);
    queue<int> qu, qv;
    qu.push(u);
    qv.push(v);

    distU.at(u) = 0;
    distV.at(v) = 0;

    while(!qu.empty()){
        int t = qu.front();
        qu.pop();

        for(auto a:g.at(t)){
            if(distU.at(a)!=-1) continue;
            distU.at(a) = distU.at(t) + 1;
            qu.push(a);
        }
    }

    while(!qv.empty()){
        int t = qv.front();
        qv.pop();

        for(auto a:g.at(t)){
            if(distV.at(a)!=-1) continue;
            distV.at(a) = distV.at(t) + 1;
            qv.push(a);
        }
    }

    int fart = v;
    ll dist = 0;
    for(int i=1; i<=n; i++){
        if(distU.at(i)<distV.at(i)){
            if(dist<distV.at(i)){
                dist = distV.at(i);
                fart = i;
            }
        }
    }

    dump(fart);
    if(fart==v){
        cout << 0 << endl;
    }
    else{
        cout << distV.at(fart) - 1 << endl;
    }

    return 0;
}

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

using ll = long long;
using P = pair<ll, ll>;

const ll MOD = 1e9+7;
// const ll MOD = 998244353;
const ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define DEBUG(x) std::cerr << #x << " : " << (x) << std::endl;
//#define DEBUG(x) ;

ll N, u, v;
vector<vector<ll>> G;
vector<ll> du, dv;

int main(int argc, char **argv)
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> N >> u >> v;
	--u, --v;

	G.resize(N);
	du.assign(N, -1);
	dv.assign(N, -1);

	REP(i, N-1)
	{
		ll a, b; cin >> a >> b;
		--a, --b;
		G[a].push_back(b);
		G[b].push_back(a);
	}

	queue<ll> que;
	que.push(v);
	dv[v] = 0;

	while (que.size())
	{
		ll now = que.front();
		que.pop();

		for (auto &nv : G[now])
		{
			if (dv[nv] != -1) continue;
			dv[nv] = dv[now] + 1;
			que.push(nv);
		}
	}

	que.push(u);
	du[u] = 0;

	while (que.size())
	{
		ll now = que.front();
		que.pop();

		for (auto &nv : G[now])
		{
			if (du[nv] != -1) continue;
			du[nv] = du[now] + 1;
			que.push(nv);
		}
	}

	ll res{0};
	REP(n, N)
	{
		if (du[n] < dv[n])
		{
			res = max(res, dv[n] - 1);
		}
	}

	std::cout << res<< std::endl;
	return 0;
}


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

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

using ll = long long;

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

int main(){
  string S;
  cin>>S;
  ll N = S.size();
  map<char,ll> m;
  for(ll i = 0; i < N; i++) m[S[i]]++;
  ll ans = 0LL;
  for(auto x:S){
    ans+=N-m[x];
  }
  cout<<ans/2+1<<endl;
}

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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
}

int h[30];

void solve() {
  string s; cin >> s;
  for (int i = 0; i < (int)s.size(); ++i) {
    ++h[s[i]-'a'];
  }
  long long ans = 1LL*s.size()*(s.size()-1)/2;
  for (int i = 0; i < 30; ++i) {
    if (!h[i]) continue;
    ans -= 1LL*h[i]*(h[i]-1)/2;
  }
  printf("%lld", ans+1);
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


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

int main()
{
    int n;
    int num[3];

    cin >> n;

    if (n == 2){
        cin >> num[0] >> num[1];
        sort(num, num + 1);
        for (int i = 1; i < num[0]; i++){
            if (num[0] % i == 0 && num[1] % i == 0){
                cout << i << endl;
            }
        }
    }

    else if (n == 3){
        cin >> num[0] >> num[1] >> num[2];
        sort(num, num + 3);
        for (int i = 1; i < num[0]; i++){
            if (num[0] % i == 0 && num[1] % i == 0 && num[2] % i == 0){
                cout << i << endl;
            }
        }
    }
    return (0);
}

#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define ALL(a) (a).begin(),(a).end()
#define MOD 10000
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const ull B=100000007;
const int INF=1e9;
int main(){
      int n,a[3];
      cin>>n;
      REP(i,n)cin>>a[i];
      sort(a,a+n);
      REP(i,a[0]){
            bool f=true;
            REP(j,n)if(a[j]%(i+1)!=0)f=false;
            if(f)cout<<i+1<<endl;
      }
}


#include <stdio.h>
#include <algorithm>
int n;
int a[100010];
int b[100010];
int c[100010];
long long psum_b[100010];
long long ans;
long long find_bc(int st,int ed,int x){
	int mid = (st+ed)/2;
	if(ed-st<=1){
		if(x<c[st]) return n-st;
		if(x>=c[ed]) return n-ed-1;
		return n-ed;
	}
	if(c[mid]<=x) return find_bc(mid,ed,x);
	return find_bc(st,mid,x);
}
long long find_ab(int st,int ed,int x){
	int mid = (st+ed)/2;
	if(ed-st<=1){
		if(x<b[st]) return psum_b[st];
		if(x>=b[ed]) return psum_b[ed+1];
		return psum_b[ed];
	}
	if(b[mid]<=x) return find_ab(mid,ed,x);
	return find_ab(st,mid,x);
}
int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	std::sort(a,a+n);
	for(int i=0;i<n;i++){
		scanf("%d",&b[i]);
	}
	std::sort(b,b+n);
	for(int i=0;i<n;i++){
		scanf("%d",&c[i]);
	}
	std::sort(c,c+n);
	for(int i=n-1;i>=0;i--){
		psum_b[i]=psum_b[i+1]+find_bc(0,n-1,b[i]);
	}
	for(int i=0;i<n;i++){
		ans+=find_ab(0,n-1,a[i]);
	}
	printf("%lld\n",ans);
}

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

int N;
int A[3][100001];
LL dp[3][100001] = {};

int main() {
    scanf("%d", &N);
    rep(j, 3) { rep(i, N) scanf("%d", &A[j][i]); A[j][N] = 1000000001; }
    rep(j, 3) sort(A[j], A[j] + N);
    rep(i, N + 1) dp[0][i] = i;
    rep(j, 2) {
        int p = 0;
        rep(i, N) {
            while (A[j][p] < A[j + 1][i]) p++;
            dp[j + 1][i + 1] += dp[j + 1][i] + dp[j][p];
        }
    }
    printf("%lld\n", dp[2][N]);
    return 0;
}


#include <bits/stdc++.h>
#include <stdlib.h>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> P;

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

int main(){
  vector <int> dp(8000);
  rep(i, 8000) dp[i] = 0;
  int N, T; cin >> N >> T;
  vector<pair <int, int>>AB;
  rep(i, N){
    int a, b; cin >> a >> b;
    AB.push_back(make_pair(a, b));
  }
  sort(AB.begin(), AB.end());

  rep(i,  N){
    vector <int> temp;
    copy(dp.begin(), dp.end(), back_inserter(temp));
    rep(t, T){
      dp[t + AB[i].first] = max(temp[t + AB[i].first], temp[t] + AB[i].second);
    }
  }
  int ans = *max_element(dp.begin(), dp.end());
  cout << ans <<endl;
}

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

vi color;
vvi G;

bool dfs(int v, int c) {
    if(color[v]  != -1) {
        if(c%2 == color[v]) {
            return true;
        } else {
            return false;
        }
    }
    color[v] = c%2;
    for(int next:G[v]){
       if(!dfs(next, c+1)) {
           return false;
       }
    }
    return true;
}

int main() {
    ll N, M;
    scanf("%lld%lld", &N, &M);
    G.resize(N);
    rep(i, M) {
        int a, b;
        scanf("%d%d", &a, &b);
        G[a-1].push_back(b-1);
        G[b-1].push_back(a-1);
    }
    color.assign(N, -1);
    if(!dfs(0, 0)) {
        cout << N*(N-1)/2-M << '\n';
        return 0;
    }
    int cc=0;
    rep(i, N) {
        if(color[i]) {
            ++cc;
        }
    }
    cout << (N-cc)*cc-M << '\n';
}


#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair

typedef pair<int, int> ii;

int n;
string s, temp;
vector<int> vec;

int main() {
    cin.tie(0), ios::sync_with_stdio(0);
    cin >> n;
    cout << 0 << "\n";
    cout.flush();
    cin >> s;
    temp = s;
    if(temp == "Vacant")
        exit(0);
    for(int i = 2; i < n; i+=2)
        vec.pb(i);
    int l = 0;
    for(int i = 20; i >= 0; i--){
        if(l + (1 << i) < n){
            cout << l + (1 << i) << "\n";
            cout.flush();
            cin >> s;
            if(s == "Vacant")
                exit(0);
            else{
                if(temp == s)
                    l += (1 << i);
            }
        }
    }
    cout << l + 1 << "\n";
    cout.flush();
    cin >> s;
    exit(0);
}

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

int main(){
  int N;
  cin>>N;
  string temp;
  string A[N];

  cout<<0<<endl;
  cin>>temp;
  if(temp=="Vacant"){
    cout<<0<<endl;
    return 0;
  }
  if(temp=="Male"){
    A[0]="Male";
  }
  if(temp=="Female"){
    A[0]="Female";
  }

  cout<<N-1<<endl;
  cin>>temp;
  if(temp=="Vacant"){
    cout<<N-1<<endl;
    return 0;
  }
  if(temp=="Male"){
    A[N-1]="Male";
  }
  if(temp=="Female"){
    A[N-1]="Female";
  }
  int l=N-1;
  int r=0;
  int k=22;
  while(k){
    k--;
    int m=(l+r)/2;
    cout<<m<<endl;
    cin>>temp;
    if(temp=="Vacant"){
      cout<<m<<endl;
      return 0;
    }
    if(temp=="Male"){
      A[m]="Male";
    }
    if(temp=="Female"){
      A[m]="Female";
    }
    if((l-m)%2 == 0 && A[l] == A[m]){
      l=m;
      continue;
    }
    if((l-m)%2 == 0 && A[l] != A[m]){
      r=m;
      continue;
    }
    if((l-m)%2 == 1 && A[l] == A[m]){
      r=m;
      continue;
    }
    if((l-m)%2 == 1 && A[l] != A[m]){
      l=m;
      continue;
    }

   }
  cout<<3<<endl;

  return 0;
}


/*  */
#include <iostream>
#include <sstream>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <deque>
#include <bitset>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <climits>
#include <cctype>
#include <cassert>
#include <functional>
#include <iterator>
#include <iomanip>
using namespace std;
//#pragma comment(linker,"/STACK:102400000,1024000")

#define sti				set<int>
#define stpii			set<pair<int, int> >
#define mpii			map<int,int>
#define vi				vector<int>
#define pii				pair<int,int>
#define vpii			vector<pair<int,int> >
#define rep(i, a, n) 	for (int i=a;i<n;++i)
#define per(i, a, n) 	for (int i=n-1;i>=a;--i)
#define clr				clear
#define pb 				push_back
#define mp 				make_pair
#define fir				first
#define sec				second
#define all(x) 			(x).begin(),(x).end()
#define SZ(x) 			((int)(x).size())
#define lson			l, mid, rt<<1
#define rson			mid+1, r, rt<<1|1
#define getBits(x)		__builtin_popcount(x)
#define getBitIdx(x)	__builtin_ffs(x)

typedef long long LL;
const int maxn = 45;
int s[maxn][maxn];
int dir[4][2] = {
	-1,0, 1,0, 0,-1, 0,1
};
int n, m;
int stx, sty, edx, edy;
int ansd;

inline bool judge(int x, int y) {
	return x<0 || x>=n || y<0 || y>=m;
}

void init() {
	rep(i, 0, n) {
		rep(j, 0, m) {
			if (s[i][j] == 2) {
				stx = i;
				sty = j;
				s[i][j] = 0;
			} else if (s[i][j] == 3) {
				edx = i;
				edy = j;
				s[i][j] = 0;
			}
		}
	}
}

void dfs(int dep, int x, int y) {
	if (dep >= ansd) return;
	if (x==edx && y==edy) {
		ansd = dep;
		return ;
	}

	int xx, yy;
	int flag;

	rep(i, 0, 4) {
		xx = x;
		yy = y;
		if (judge(xx+dir[i][0], yy+dir[i][1]) || s[xx+dir[i][0]][yy+dir[i][1]] == 1) continue;

		flag = 1;
		while (true) {
			if (judge(xx+dir[i][0], yy+dir[i][1])) {
				flag = 0;
				break;
			}

			if (s[xx+dir[i][0]][yy+dir[i][1]] == 1) {
				flag = -1;
				break;
			}

			xx += dir[i][0];
			yy += dir[i][1];

			if (xx==edx && yy==edy) {
				break;
			}
		}

		if (flag == 0) continue;

		if (flag == -1) {
			s[xx+dir[i][0]][yy+dir[i][1]] = 0;
		}

		dfs(dep+1, xx, yy);

		if (flag == -1) {
			s[xx+dir[i][0]][yy+dir[i][1]] = 1;
		}
	}
}

void solve() {
	init();
	ansd = 11;
	dfs(0, stx, sty);
	if (ansd == 11) ansd = -1;
	printf("%d\n", ansd);
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	// #ifndef ONLINE_JUDGE
		// freopen("data.in", "r", stdin);
		// freopen("data.out", "w", stdout);
	// #endif

	while (scanf("%d %d", &m,&n)!=EOF && (n||m)) {
		rep(i, 0, n)
			rep(j, 0, m)
				scanf("%d", &s[i][j]);
		solve();
	}

	// #ifndef ONLINE_JUDGE
		// printf("time = %ldms.\n", clock());
	// #endif

	return 0;
}