#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
//ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    string s;
    cin >> s;
    int n = s.size();
    if (n != 26) {
        vector<bool> flg(26, false);
        rep(i, n) flg[s[i]-'a'] = true;
        cout << s;
        rep(i, 26) {
            if (!flg[i]) {
                cout << (char)(i + 'a') << endl;
                return 0;
            }
        }
    }
    else {
        string t = s;
        if (!next_permutation(t.begin(), t.end())) {
            cout << -1 << endl;
            return 0;
        }
        rep(i, n) {
            cout << t[i];
            if (t[i] != s[i]) {
                cout << endl;
                break;
            }
        }
    }
    return 0;
}

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

int main() {

  string B;
  cin >> B;

  vector<char>vec(B.size());
  for(int i=0;i<B.size();i++){
    vec.at(i)=B.at(i);
  }
  int count=99999;
    for(int i=2 ;i<B.size();i++){
 int  A=vec.at(i-2)- '0',B=vec.at(i-1)- '0',C=vec.at(i)- '0';
 int D;
D=100*A+10*B+C;
 D=abs(753-D);
count=min(D,count);
  }
  cout << count <<endl;

}


#include <iostream>
#include <cstdio>
#include <algorithm>
#define N 100005
using namespace std;

struct st{
	int l, r;
} a[N];

int n, mx, fl[N], fr[N], bl[N], br[N];

bool cmp(st p, st q) {
	if (p.r != q.r) return p.r < q.r;
	else return p.l < q.l;
}

int main()
{
	int i;
	cin >> n;
	for (i = 0; i < n; i++) {
		scanf("%d %d", &a[i].l, &a[i].r);
	}
	sort(a, a + n, cmp);
	fl[0] = a[0].l; fr[0] = a[0].r;
	for (i = 1; i < n; i++) {
		fl[i] = max(fl[i - 1], a[i].l);
		fr[i] = min(fr[i - 1], a[i].r);
	}
	bl[n - 1] = a[n - 1].l; br[n - 1] = a[n - 1].r;
	for (i = n - 2; i >= 0; i--) {
		bl[i] = max(bl[i + 1], a[i].l);
		br[i] = min(br[i + 1], a[i].r);
	}
	for (i = 0; i < n; i++) {
		mx = max(mx, a[i].r - a[i].l + 1 + max(0, fr[n - 1] - fl[n - 1] + 1));
	}
	for (i = 0; i < n - 1; i++) {
		mx = max(mx, max(0, fr[i] - fl[i] + 1) + max(0, br[i + 1] - bl[i + 1] + 1));
	}
    cout << mx << endl;
    return 0;
}

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

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

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

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

  cout << cnt << endl;
  return 0;

}


//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

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

	int N = getint();
	int A[200000];
	ll goukei = 0;
	rep(i, N) goukei += (A[i] = getint());

	ll kotae = 1e18;

	int q = 1, s = 3;
	ll PQ = A[0] - A[1];
	ll RS = -goukei + A[2] + A[0] + A[1] + A[2] ;
	ll diff = -goukei + A[0] + A[1] + A[0] + A[1];
	for (int r = 2; r < N - 1; r++) {
		while (abs(PQ) > abs(PQ + 2 * A[q])) {
			PQ += 2 * A[q];
			q++;
		}
		while (abs(RS) > abs(RS + 2 * A[s])) {
			RS += 2 * A[s];
			s++;
		}
		ll kari = max(abs(diff) + abs(PQ) + abs(RS), max(abs(PQ), abs(RS)) * 2);
		kotae = min(kotae, kari);

		PQ -= A[r];
		RS -= A[r];
		diff += 2 * A[r];
	}

	printf("%lld", kotae / 2);

	Would you please return 0;
}


#include <bits/stdc++.h>
#include <string>
#include <vector>
#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 MX = 1e18;
    int n,k;
    cin >> n >> k;
    vector<int> neg,pos;
    rep(i,n){
        int temp;cin >> temp;
        if(temp == 0) k--;
        else if(temp < 0) neg.push_back(temp);
        else pos.push_back(temp);
    }
    sort(neg.begin(),neg.end(),greater<int>());
    if(k <= 0){
        cout << 0 << endl;
        return 0;
    }
    int s = pos.size();
    int t = neg.size();
    ll ans = MX;
    ll total = 0;

    if(s >= k){
        total = pos[k-1];
        ans = min(ans,total);
    }
    if(t >= k){
        total = abs(neg[k-1]);
        ans = min(ans,total);
    }

    for(int i = max(0,k-t-1);i<=min(s-1,k-2);i++){
        total = 2*abs(neg[k-i-2]) + pos[i];
        ans = min(ans,total);
    }
    for(int i = max(0,k-s-1);i<=min(t-1,k-2);i++){
        total = 2*pos[k-i-2] + abs(neg[i]);
        ans = min(ans,total);
    }

    cout << ans << endl;
}

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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
using ll = long long;

int main() {
    int n, k; cin >> n >> k;
    V<ll> v(n);
    for(int i = 0; i < n; i++) cin >> v[i];

    ll ans = 1e9;
    for(int l = 0; l <= n - k; l++){
        ll r = l + k - 1;
        ans = min(ans, abs(v[l]) + abs(v[l] - v[r]));
        ans = min(ans, abs(v[r]) + abs(v[r] - v[l]));
    }
    cout << ans << endl;

    return 0;
}


#include<iostream>
using namespace std;

int main(){
	int n=1;
	int a = 0;
	int f = 0;
	int quest[10000] = { 1 };
	double ans[10000];
	int checkc = 0;
	int i = 4;
	double check[3] = { 1, 2, 4 };

	do{
		cin >> quest[a];
		a++;
	} while (quest[a-1] != 0);
	while (a > f+1){
		switch (quest[f]){
		case 1:
			ans[f] = 1;
			break;
		case 2:
			ans[f] = 2;
			break;
		case 3:
			ans[f] = 4;
			break;
		default:
			while (quest[f] >= i){
				ans[f] = check[0] + check[1] + check[2];
				i++;
				check[0] = check[1];
				check[1] = check[2];
				check[2] = ans[f];
			}
		}

		ans[f] = ans[f] / 3650;
		checkc = (int)(ans[f]);

		if (ans[f] > (double)(checkc)){
			checkc++;
		}
		if (ans[f] != 0){
			cout << checkc << endl;
		}
		else{
			cout << endl;
		}
		f++;
	}
	return 0;
}

#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <utility>
#include <set>
#include <cmath>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pi acos(-1)
#define all(v) v.begin(),v.end()
#define EPS (1e-10)
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) (EQ((a).real(),(b).real()) && EQ((a).imag(),(b).imag()))
using namespace std;
typedef pair<int,int> point;
typedef complex<double> P;
typedef long long ll;

const double eps = 1e-8;
const double INF = 1e12;

double dot(P a,P b){
	return a.real()*b.real()+a.imag()*b.imag();
}
double cross(P a,P b){
	return a.real()*b.imag()-a.imag()*b.real();
}

bool is_orthogonal(P a1,P a2,P b1,P b2){
	return EQ(dot(a1-a2,b1-b2),0.0);
}
bool is_parallel(P a1,P a2,P b1,P b2){
	return EQ(cross(a1-a2,b1-b2),0.0);
}

bool is_point_on_line(P a,P b,P c){
	return EQ(cross(b-a,c-a),0.0);
}

bool is_point_on_linesegment3(P a,P b,P c){
	//|a-c| + |c-b|<=|a-b| ???????????????
	return (abs(a-c)+abs(c-b)<abs(a-b)+EPS);
}

double distance_l_p(P a,P b,P c){
	return abs(cross(b-a,c-a))/abs(b-a);
}

double distance_ls_p(P a,P b,P c){
	if(dot(b-a,c-a)<EPS)return abs(c-a);
	if(dot(a-b,c-b)<EPS)return abs(c-b);
	return abs(cross(b-a,c-a))/abs(b-a);
}

int main(){
	long long dt[50];
	rep(i,50)dt[i]=0;
	dt[1]=1;
	dt[2]=1;
	dt[3]=1;
	rep(i,30){
		dt[i+1]+=dt[i];
		dt[i+2]+=dt[i];
		dt[i+3]+=dt[i];
	}
	int n;
	while(cin>>n,n){
		if(dt[n]%3650!=0)cout<<dt[n]/3650+1<<endl;
		else cout<<dt[n]/3650<<endl;
	}
	return 0;
}


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

//type
#define ll long long
typedef pair<int, int> P;
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first      //pairの一つ目の要素
#define S second     //pairの二つ目の要素
#define Z class
// OTHER
// xの二乗を返す (関数テンプレート版)
template <typename T>
T square(T x) { return x * x; }
#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))
// loop
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= ll(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= ll(b); i--)
#define FORA(i, I) for (const auto &i : I)

// vector
#define ALL(x) x.begin(), x.end()

// output
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n", (x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define ln cout << '\n'
template <Z A>
void pr(A a)
{
  cout << a;
  ln;
}
template <Z A, Z B>
void pr(A a, B b)
{
  cout << a << ' ';
}

int ans = 0;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

int main()
{
  string a, b, c, n, x, y;
  cin >> a >> b >> c;
  // cin >> a >> b >> c;
  if ((a[a.length() - 1] == b[0]) && (b[b.length() - 1] == c[0]))
    YES();
  else
    NO();
  return 0;
}


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;

int H,W,K;

const int MOD = 1e9+7;

vector<int> change;
vector<vector<int>> next_w;

void rec(int w){
    if(w == W-1){
        vector<int> n(W,0);
        REP(i,W) n[i] = i;
        REP(i,W-1) if(change[i]==1) swap(n[i],n[i+1]);
        REP(i,W){
            next_w[n[i]][i]++;
        }
        return;
    }

    change[w] = 0;
    rec(w+1);

    change[w] = 1;
    if(w+2 < W) change[w+1]=0, rec(w+2);
    if(w+2 == W) rec(w+1);
}

int main() {
    cin >> H >> W >> K;

    next_w.assign(W, vector<int>(W,0));
    change.assign(W-1,0);

    rec(0);

    vector<vector<ll>> ans(H+1, vector<ll>(W,0));
    ans[0][0] = 1;

    REP(i,H){
        REP(j,W){
            if(j-1>=0){
                ans[i+1][j-1] += ans[i][j] * next_w[j][j-1];
                ans[i+1][j-1] %= MOD;
            }
            ans[i+1][j] += ans[i][j] * next_w[j][j];
            ans[i+1][j] %= MOD;
            if(j+1<=W-1){
                ans[i+1][j+1] += ans[i][j] * next_w[j][j+1];
                ans[i+1][j+1] %= MOD;
            }
        }
    }

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

    return 0;
}

#include<cstdio>
using ull = unsigned long long;
const static int MOD = 1000000007;
const static int MAX_H = 100;
const static int MAX_W = 8;
ull dp[MAX_H+1][MAX_W], fibonacci[8] = {1, 1, 2, 3, 5, 8, 13, 21};

int main(){
    unsigned H, W, K;
    scanf("%u %u %u", &H, &W, &K);
    if(W == 1){
        printf("1\n");
        return 0;
    }
    K--;
    dp[0][0] = 1;
    for (size_t i = 1; i <= H; i++){
        dp[i][0] = (dp[i-1][0]*fibonacci[W-1] + dp[i-1][1]*fibonacci[W-2]) %MOD;
        for (size_t j = 1; j < W-1; j++){
            dp[i][j] = (dp[i-1][j-1]*fibonacci[j-1]*fibonacci[W - j - 1] + dp[i-1][j]*fibonacci[j]*fibonacci[W - j - 1] + dp[i-1][j+1]*fibonacci[j]*fibonacci[W - j - 2]) %MOD;
        }
        dp[i][W-1] = (dp[i-1][W-1]*fibonacci[W-1] + dp[i-1][W-2]*fibonacci[W-2]) %MOD;
    }
    printf("%llu\n", dp[H][K]);
	return 0;
}


//#define NDEBUG
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <utility>
#include <vector>

namespace n91 {

using i8 = std::int_fast8_t;
using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
using u8 = std::uint_fast8_t;
using u32 = std::uint_fast32_t;
using u64 = std::uint_fast64_t;
using isize = std::ptrdiff_t;
using usize = std::size_t;

struct rep {
  struct itr {
    usize i;
    constexpr itr(const usize i) noexcept : i(i) {}
    void operator++() noexcept { ++i; }
    constexpr usize operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
  };
  const itr f, l;
  constexpr rep(const usize f, const usize l) noexcept
      : f(std::min(f, l)), l(l) {}
  constexpr auto begin() const noexcept { return f; }
  constexpr auto end() const noexcept { return l; }
};
struct revrep {
  struct itr {
    usize i;
    constexpr itr(const usize i) noexcept : i(i) {}
    void operator++() noexcept { --i; }
    constexpr usize operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
  };
  const itr f, l;
  constexpr revrep(const usize f, const usize l) noexcept
      : f(l - 1), l(std::min(f, l) - 1) {}
  constexpr auto begin() const noexcept { return f; }
  constexpr auto end() const noexcept { return l; }
};
template <class T> auto md_vec(const usize n, const T &value) {
  return std::vector<T>(n, value);
}
template <class... Args> auto md_vec(const usize n, Args... args) {
  return std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
}
template <class T> constexpr T difference(const T &a, const T &b) noexcept {
  return a < b ? b - a : a - b;
}
template <class T> void chmin(T &a, const T &b) noexcept {
  if (b < a)
    a = b;
}
template <class T> void chmax(T &a, const T &b) noexcept {
  if (a < b)
    a = b;
}
template <class F> class rec_lambda {
  F f;

public:
  rec_lambda(F &&f) : f(std::move(f)) {}
  template <class... Args> auto operator()(Args &&... args) const {
    return f(*this, std::forward<Args>(args)...);
  }
};
template <class F> auto make_rec(F &&f) { return rec_lambda<F>(std::move(f)); }
template <class T> T scan() {
  T ret;
  std::cin >> ret;
  return ret;
}
constexpr char eoln = '\n';

} // namespace n91

#include <cassert>

namespace n91 {

void main_() {
  /*
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  //*/
  constexpr usize Inf = std::numeric_limits<usize>::max() / 2;
  const usize n = scan<usize>();
  const usize m = scan<usize>();
  auto g = md_vec(n, n, Inf);
  for (const usize i : rep(0, m)) {
    const usize a = scan<usize>() - 1;
    const usize b = scan<usize>() - 1;
    g[a][b] = 1;
  }
  for (const usize i : rep(0, n)) {
    for (const usize j : rep(0, n)) {
      for (const usize k : rep(0, n)) {
        chmin(g[j][k], g[j][i] + g[i][k]);
      }
    }
  }
  usize st = 0;
  for (const usize i : rep(0, n)) {
    if (g[i][i] < g[st][st]) {
      st = i;
    }
  }
  if (g[st][st] >= Inf) {
    std::cout << "-1" << eoln;
    return;
  }
  std::vector<usize> ans;
  usize v = st;
  do {
    for (const usize i : rep(0, n)) {
      if (g[v][i] == 1 && ans.size() + 1 + g[i][st] == g[st][st]) {
        ans.push_back(i);
        v = i;
        break;
      }
    }
  } while (ans.size() != g[st][st] - 1);
  ans.push_back(st);
  std::cout << ans.size() << eoln;
  for (const auto e : ans) {
    std::cout << e + 1 << eoln;
  }
}

} // namespace n91

int main() {
  n91::main_();
  return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>
#define pii pair<int,int>
#define F first
#define S second

using namespace std;
const int MAX_N = 1e4+10;
const int INF = 1e9+10;
typedef long long ll;
vector <int> vec[MAX_N];
bool ans[MAX_N];
int dp[MAX_N],depth[MAX_N];
void dfs(int v,int cnt,int p){
	depth[v]=cnt+1;
	dp[v]=depth[v];
	int nd=0;
	for(int u:vec[v]){
		if(u==p)
            continue;
		if(dp[u])
			dp[v]=min(dp[v],depth[u]);
		else{
			dfs(u,cnt+1,v);
			dp[v]=min(dp[v],dp[u]);
			if(dp[u]>=depth[v])
                ans[v]=true;
            nd++;
		}
	}
    if(p==-1&&nd<2)
        ans[v]=false;
}
int main(){
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        vec[a].push_back(b);
        vec[b].push_back(a);
    }
    dfs(0,0,-1);
    for(int i=0;i<n;i++)
        if(ans[i])
            cout<<i<<endl;
}


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

#define INF (1<<29)

int G[101][101];
int n, k;

void init(){
  for(int i = 0 ; i < n ; i++){
    for(int j = 0 ; j < n ; j++){
      G[i][j] = INF;
      if(i == j) G[i][j] = 0;
    }
  }
}

int main(){
  while(cin >> n >> k){
    if(n == 0 && k == 0) break;
    init();

    int op, a, b, e;
    for(int cs = 0 ; cs < k ; cs++){
      cin >> op;
      if(op == 1){
	cin >> a >> b >> e;
	a--, b--;
	G[a][b] = min(G[a][b], e);
	G[b][a] = min(G[b][a], e);
	//	Warshall_Floyd();
	  for(int i = 0 ; i < n ; i++){
	    for(int j = 0 ; j < n ; j++){
	      G[i][j] = min(G[i][j], G[i][a] + G[a][b] + G[b][j]);
	      G[j][i] = G[i][j];
	    }
	  }
      }
      else if(op == 0){
	cin >> a >> b;
	a--, b--;
	if(G[a][b] == INF) cout << -1 << endl;
	else cout << G[a][b] << endl;
      }
    }
  }
  return 0;
}

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

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

int main(){
    int a[5];
    while(scanf("%d,%d,%d,%d,%d",&a[0],&a[1],&a[2],&a[3],&a[4])!=EOF){
        sort(a,a+5);
        int n=0;
        rep(i,4)loop(j,i+1,5){
            if(a[i]==a[j])n++;
        }
        bool st=true;
        rep(i,4)if(a[i]+1!=a[i+1])st=false;
        if(a[0]==1&&
           a[1]==10&&
           a[2]==11&&
           a[3]==12&&
           a[4]==13) st=true;

        string ans;
        if(n==6)
            ans="four card";
        else if(n==4)
            ans="full house";
        else if(st)
            ans="straight";
        else if(n==3)
            ans="three card";
        else if(n==2)
            ans="two pair";
        else if(n==1)
            ans="one pair";
        else
            ans="null";
        cout<<ans<<endl;
    }
}


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

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

#define m0(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define rep(i, n) for(int i = 0; i < (n); i++)
#define asort(x) sort(all(x));
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>());
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define MINS(m, s) m.insert(make_pair(s, 1));
#define MFIN(m, s) m.find(s) != m.end()
const int mod = 1000000007;

vector<ll> divisor(ll n) {
    vector<ll> res;
    for(ll i = 1; i * i <= n; i++) {
        if(n % i == 0) {
            res.push_back(i);
            if(i * i != n) {
                res.push_back(n / i);
            }
        }
    }
    sort(begin(res), end(res));
    return res;
}

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

bool isPrime(ll x) {
    ll i;
    if(x < 2)
        return 0;
    else if(x == 2)
        return 1;
    if(x % 2 == 0)
        return 0;
    for(i = 3; i * i <= x; i += 2)
        if(x % i == 0)
            return 0;
    return 1;
}

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

    ll ab_gcd = gcd(A, B);
    vector<ll> ab_divisor;
    ab_divisor = divisor(ab_gcd);

    ll cnt = 1;
    for(ll i = 0; i < ab_divisor.size(); i++) {
        if(isPrime(ab_divisor[i])) {
            cnt++;
        }
    }

    cout << cnt << endl;

    return 0;
}

#include <iostream>

using namespace std;

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

signed main() {
  int a, b;
  cin >> a >> b;

  int s = 0, n = (int)1e6;
  rep(i0,n) {
    int i = i0 + 2, fa = 0, fb = 0;
    while(a % i == 0) a /= i, fa = 1;
    while(b % i == 0) b /= i, fb = 1;
    s += (fa && fb);
  }

  cout << s + 1 + (a != 1 && a == b) << endl;
  return 0;
}


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

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

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

using namespace std;

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

  cout << 0 << "\n";
  string p;
  int pos = 0;
  cin >> p;
  if(p[0] == 'V'){
    cout << 0 << "\n";
    return 0;
  }

  int le = N+1;
  int ri = 0;
  while(1){
    int mid = (ri+le)/2;
    cout << mid << "\n";
    string s;
    cin >> s;
    if(s[0] == 'V'){
      return 0;
    }

    if(abs(pos-mid)%2 == 0){
      if(s == p) ri = mid;
      else le = mid;
    }else{
      if(s != p) ri = mid;
      else le = mid;
    }
  }

  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;
  scanf("%d", &n);
  int l = 0, r = n;
  printf("%d\n", l);
  fflush(stdout);
  string sl;
  cin >> sl;
  while (sl != "Vacant") {
    int m = (l + r) / 2;
    printf("%d\n", m);
    fflush(stdout);
    string sm;
    cin >> sm;
    if (sm == "Vacant" || l % 2 == m % 2 && sl == sm || l % 2 != m % 2 && sl != sm) {
      l = m;
      sl = sm;
    } else {
      r = m;
    }
  }
  printf("%d\n", l);
  fflush(stdout);
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//(a+b-1)/b

signed main(){
	string s; cin>>s;
	int n=s.size();
	ll ans=0;
	ll cnt=0;
	rep(i,0,n){
		if(s[i]=='S')cnt++;
		else if(cnt>0){
			cnt--;
			ans++;
		}
	}
	cout<<n-(ans*2)<<endl;

	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MOD 1000000007

void solve()
{
	ll x;
	cin>>x;
	if(x<=6)
		cout<<1;
	else if(x<=11)
		cout<<2;
	else if(x%11>6)
		cout<<(x/11)*2+2;
	else if(x%11==0)
		cout<<(x/11)*2;
	else
		cout<<(x/11)*2+1;
	return;
}

int main()
{
	fast;
	ll q=1;
	// cin>>q;
	while(q--)
		solve();
	return 0;
}


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

int main() {
    int n;
    cin >> n;
    n -= 2;
    cout << n * 180 << endl;
}

#include<bits/stdc++.h>
#define For(i,x,y) for (register int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (register int i=(x);i<(y);i++)
#define Dow(i,x,y) for (register int i=(x);i>=(y);i--)
#define Debug(v) for (auto i:v) printf("%lld ",i);puts("")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fil(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pa;
typedef pair<ll,ll> PA;
typedef vector<int> poly;
inline ll read(){
    ll x=0,f=1;char c=getchar();
    while ((c<'0'||c>'9')&&(c!='-')) c=getchar();
    if (c=='-') f=-1,c=getchar();
    while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    return x*f;
}

int main(){
	int n=read();
	printf("%d\n",(n-2)*180);
}


#include <bits/stdc++.h>

using namespace std;

template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

template< typename G >
struct LowLink {
  const G &g;
  vector< int > used, ord, low;
  vector< int > articulation;
  vector< pair< int, int > > bridge;

  LowLink(const G &g) : g(g), used(g.size()), ord(g.size()), low(g.size()) {}

  int build(int idx = 0, int k = 0, int par = -1) {
    used[idx] = true;
    ord[idx] = k++;
    low[idx] = ord[idx];
    bool is_articulation = false;
    int cnt = 0, ordmax = k;
    for(auto &to : g[idx]) {
      if(!used[to]) {
        ++cnt;
        ordmax = build(to, ordmax, idx);
        low[idx] = min(low[idx], low[to]);
        is_articulation |= ~par && low[to] >= ord[idx];
        if(ord[idx] < low[to]) bridge.emplace_back(idx, to);
      } else if(to != par) {
        low[idx] = min(low[idx], ord[to]);
      }
    }
    is_articulation |= par == -1 && cnt > 1;
    if(is_articulation) articulation.push_back(idx);
    return ordmax;
  }
};

int main() {
  int V, E;
  scanf("%d %d", &V, &E);
  UnWeightedGraph g(V);
  for(int i = 0; i < E; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    g[x].push_back(y);
    g[y].push_back(x);
  }
  LowLink< UnWeightedGraph > lowlink(g);
  lowlink.build();
  sort(lowlink.articulation.begin(), lowlink.articulation.end());
  for(auto &v : lowlink.articulation) printf("%d\n", v);
}

#include <bits/stdc++.h>
using namespace std;
int main(){
  int H, W;
  cin >> H >> W;
  vector<vector<int>> a(H, vector<int>(W));
  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      cin >> a[i][j];
    }
  }
  vector<tuple<int, int, int, int>> op;
  for (int i = 0; i < H; i++){
    for (int j = 0; j < W - 1; j++){
      if (a[i][j] % 2 == 1){
        a[i][j]--;
        a[i][j + 1]++;
        op.push_back(make_tuple(i + 1, j + 1, i + 1, j + 2));
      }
    }
  }
  for (int i = 0; i < H - 1; i++){
    if (a[i][W - 1] % 2 == 1){
      a[i][W - 1]--;
      a[i + 1][W - 1]++;
      op.push_back(make_tuple(i + 1, W, i + 2, W));
    }
  }
  int N = op.size();
  cout << N << endl;
  for (int i = 0; i < N; i++){
    cout << get<0>(op[i]) << ' ' << get<1>(op[i]) << ' ' << get<2>(op[i]) << ' ' << get<3>(op[i]) << endl;
  }
}


#include <bits/stdc++.h>
#define gcd std::__gcd
#define EB emplace_back

typedef std::vector <int> vector;
const int N = 100054;

int n;
vector a;

inline bool judge(const vector &v) {
	int c[2] = {0}, g = 0; bool one = false; vector u(v);
	for (int x : v) ++c[x & 1], one |= x == 1;
	if (*c & 1) return true;
	if (one || c[1] > 1) return false;
	for (int &x : u) g = gcd(g, x &= -2);
	for (int &x : u) x /= g;
	return !judge(u);
}

int main() {
	int i, x;
	scanf("%d", &n), a.reserve(n);
	for (i = 1; i <= n; ++i) scanf("%d", &x), a.EB(x);
	return puts(judge(a) ? "First" : "Second"), 0;
}

#include<iostream>
#include<algorithm>
using namespace std;
const int N=1e5+10;
int n,a[N];
void Put(int p) {p&1?puts("First"):puts("Second");exit(0);}
void dfs(int p)
{
    int od=0,ov=0,g=0,mn=1e9;
    for(int i=1;i<=n;i++) a[i]&1?od++:ov++,mn=min(mn,a[i]);
    if(ov&1) Put(p);
    if(od>1||mn==1) Put(p^1);
    for(int i=1;i<=n;g=__gcd(g,a[i]),i++) if(a[i]&1) a[i]--;
    for(int i=1;i<=n;i++) a[i]/=g;
    dfs(p^1);
}
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    if(n==1) Put(a[1]-1);dfs(1);
}


#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

const ll MOD = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

using namespace std;

int N, M;
vector<int> A, B;

long long solve()
{
    ll res = 1;
    int biggerX_a = 0, biggerX_b = 0; // A,B でxより大きい数値の個数

    for (int x = N * M; x >= 1; x--)
    {
        /*if (A[biggerX_a] > x)
            return 0;
        if (B[biggerX_b] > x)
            return 0;
        */
        long long tmp = 1;
        if (A[biggerX_a] == x && B[biggerX_b] == x)
        {
            tmp = 1;
            ++biggerX_a, ++biggerX_b;
        }
        else if (A[biggerX_a] == x)
        {
            tmp = biggerX_b;
            ++biggerX_a;
        }
        else if (B[biggerX_b] == x)
        {
            tmp = biggerX_a;
            ++biggerX_b;
        }
        else
        {
            tmp = biggerX_a * biggerX_b - (N * M - x);
            if (tmp <= 0)
                return 0;
        }
        res = (res * tmp) % MOD;
    }
    return res;
}
int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> N >> M;
    A.resize(N+1);
    B.resize(M+1);
    rep(i, N) cin >> A[i];
    rep(i, M) cin >> B[i];
    sort(ALL(A), greater<int>());
    sort(ALL(B), greater<int>());
    cout << solve() << endl;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

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

  vvll a(n,vll(m));
  REP(i,n)REP(j,m)cin>>a[i][j];

  vector<queue<ll>> b(n);
  REP(i,n){
    REP(j,m){
      a[i][j]--;
      b[i].push(a[i][j]);
    }
  }

  ll ans=LLINF;
  vll removed(m);
  REP(i,m){
    vpl picked(m);
    REP(j,m)picked[j].SE=j;

    REP(j,n){
      ll t=b[j].front();
      picked[t].FI++;
    }

    sort(ALL(picked), greater<pll>());
    ll now=picked[0].FI;
    ll max_a=picked[0].SE;
    ans=min(ans,now);

    //remove most picked
    removed[max_a]=1;
    REP(j,n){
      while(!b[j].empty()){
        ll t=b[j].front();

        if(removed[t])
          b[j].pop();
        else
          break;
      }
    }

  }

  cout<<ans<<endl;
}


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

int main(){
    int N,M;
    int count = 0;
    int score = 0;
    cin >> N;
    vector<string> s(N);
    for(int i=0;i<N;i++){
        cin >> s.at(i);
    }
    cin >> M;
    vector<string> t(M);
    for(int i=0;i<M;i++){
        cin >> t.at(i);
    }
    for(int i=0;i<N;i++){
        count = 0;
        for(int j=0;j<N;j++){
            if(s.at(i) == s.at(j)) count++;
        }
        for(int j=0;j<M;j++){
            if(s.at(i) == t.at(j)) count--;
        }
        score = max(score,count);
    }
    cout << score << endl;

}

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

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

  vector<long> a(N);
  for (int i=0; i<N; i++) {
    cin >> a.at(i);
  }

  sort(a.begin(), a.end());

  int cnt=0;
  for (int i=0; i<N; i++) {
    cnt++;
    x -= a.at(i);
    if (x<=0) {
      break;
    }
  }
  if (x!=0) cnt--;

  cout << cnt << endl;
  return 0;
}


#include <iostream>
#include <string>

//class
class Baseball{
public:
	int firstbase, secondbase, thirdbase;
	int inningNumber, out, score;

	Baseball(int num){
		inningNumber = num;
		firstbase = 0;
		secondbase = 0;
		thirdbase = 0;
		out = 0;
		score = 0;
	}

	void playball(){
		for(int i = 0; i < inningNumber; ++i)
			inning();
	}

	void inning(){
		out = 0;
		firstbase = 0;
		secondbase = 0;
		thirdbase = 0;
		score = 0;

		while(out != 3){
			std::string str;
			std::cin >> str;

			if(str == "HIT")
				hit();
			if(str == "HOMERUN")
				homerun();
			if(str == "OUT")
				out++;
		}

		std::cout << score << std::endl;
	}

	void hit(){
		score += thirdbase;
		thirdbase = secondbase;
		secondbase = firstbase;
		firstbase = 1;
	}

	void homerun(){
		score += thirdbase + secondbase + firstbase + 1;
		firstbase = 0;
		secondbase = 0;
		thirdbase = 0;
	}
};
//main
int main(){
	int n;
	std::cin >> n;

	Baseball *baseball = new Baseball(n);
	baseball->playball();
	delete baseball;

	return 0;
}

#include <iostream>
using namespace std;
int main(){
	int m,d;
	while(cin>>m>>d){
		if(!m) break;
		int daym[12]={0,31,60,91,121,152,182,213,244,274,305,335};
		int wd = (daym[m-1] + d + 2)%7;
		switch(wd){
		case 0:
			cout <<"Monday"<<endl;
			break;
		case 1:
			cout<<"Tuesday"<<endl;
			break;
		case 2:
			cout<<"Wednesday"<<endl;
			break;
		case 3:
			cout<<"Thursday"<<endl;
			break;
		case 4:
			cout<<"Friday"<<endl;
			break;
		case 5:
			cout<<"Saturday"<<endl;
			break;
		case 6:
			cout<<"Sunday"<<endl;
			break;
		}
	}
	return 0;
}


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

int main()
{
	int n,m;
	while(cin>>n>>m&&n)
	{
		vector<int> a;
		int ans=0;
		for(int i=0;i<n;i++)
		{
			int x;
			cin>>x;
			a.push_back(x);
		}
		sort(a.begin(),a.end());
		for(int i=0;i<n%m;i++)
		{
			ans+=a[0];;
			a.erase(a.begin());
		}
		n-=n%m;
		for(int i=0;i<a.size();i++)ans+=a[i];
		for(int i=0;i<n/m;i++)
		{
			ans-=a[i*m];
		}
		cout<<ans<<endl;
	}

}

//
//  main.cpp

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int n,k,cards[11];
bool selected[11];
vector<vector<int>> selectlist;
vector<int> makelist;

void reset(){
	n = k = 0;
	selectlist.clear();
	makelist.clear();
	for(int i=0;i<11;i++){
		cards[i] = 0;
		selected[i] = false;
	}
}

void select_dfs_(int depth,int top,vector<int> vec){
	if(depth == k){
		selectlist.push_back(vec);
		return;
	}
	for(int i=top+1;i<n;i++){
		vec.push_back(cards[i]);
		select_dfs_(depth+1,i,vec);
		vec.pop_back();
	}
}

void makeint_dfs_(int depth,int makedint,vector<int> source){
	if(depth == k){
		makelist.push_back(makedint);
		return;
	}
	for(int i=0;i<k;i++){
		if(!selected[i]){
			selected[i] = true;
			int maked;
			if(source[i]/10 > 0){
				maked = makedint*100+source[i];
			}else{
				maked = makedint*10+source[i];
			}
			makeint_dfs_(depth+1,maked,source);
			selected[i] = false;
		}
	}
}

int main(){
	while(1){
		reset();

		cin >> n >> k;
		if(n == 0 && k == 0)break;
		for(int i=0;i<n;i++){
			cin >> cards[i];
		}

		for(int i=0;i<n-k+1;i++){
			vector<int> vec;
			vec.push_back(cards[i]);
			select_dfs_(1,i,vec);
		}

		for(int i=0;i<selectlist.size();i++){
			for(int j=0;j<selectlist[i].size();j++){
				selected[j] = true;
				makeint_dfs_(1,selectlist[i][j],selectlist[i]);
				selected[j] = false;
			}
		}

		sort(makelist.begin(),makelist.end());

		int answer=0,memo=-1;
		for(int i=0;i<makelist.size();i++){
			if(memo != makelist[i]){
				answer ++;
				memo = makelist[i];
			}
		}

		cout << answer << endl;

	}

	return 0;
}


//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_5_D
#include <iostream>
using namespace std;

bool div(int n){
  if(n % 3 == 0) return true;
  else return false;
}
bool isIn3(int n){
  if((n-3) % 10 == 0) return true;
  else return false;
}

bool in3(int n){
  while(n > 10){
    n /= 10;
    if(isIn3(n)) return true;
  }
  return false;
}

int main(){
  int n;
  cin >> n;
  for(int i=1; i <= n; i++){
    if(div(i) || isIn3(i)|| in3(i)) cout << " " << i;
  }
  cout << endl;
}

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

#define pb(s) push_back(s)
#define ALL(v) v.begin(), v.end()
#define ALLA(arr, sz) arr, arr + sz
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr, sz) sort(ALLA(arr, sz))
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz))
#define PI 3.14159265358979323846264338327950L

typedef long long ll;

const ll MOD =1e9+7;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll x;
    cin>>x;
    ll ans=0;
    ans+=2*(x/11);
    x%=11;
    if(x>0)ans++;
    if(x>6)ans++;
    cout<<ans;
    return 0;
}


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

long long N,ans;
string S;
string S1,S2;
vector <string> V1,V2;

string convstr(string str,long long key){
  string f="";string l="";
  for (long long i=0;i<N;i++){
    if ((key&(1<<i))!=0){
      f=f+str[i];
    } else l=str[i]+l;
  }
  return f+" "+l;
}

int main(){
  cin >> N >> S;
  S1="";S2="";
  for (long long i=0;i<N;i++){
    S1=S1+S[i];
    S2=S2+S[2*N-1-i];
  }

  for (long long i=0;i<(1<<N);i++){
    V1.push_back(convstr(S1,i));
  }
  sort(&V1[0],&V1[1<<N]);
  /*
  for (int i=0;i<V1.size();i++){
    cout << V1[i] << endl;
  }
  */
  for (long long i=0;i<(1<<N);i++){
    V2.push_back(convstr(S2,i));
  }
  sort(&V2[0],&V2[1<<N]);
  /*
  for (int i=0;i<V2.size();i++){
    cout << V2[i] << endl;
  }
  */
  long long idx1=0,idx2=0;
  long long mul1=0,mul2=0;
  ans=0;
  while(idx1<(1<<N) && idx2<(1<<N)){
    if (V1[idx1]>V2[idx2]){
      idx2++;continue;
    }
    if (V1[idx1]<V2[idx2]){
      idx1++;continue;
    }

    mul1=0;mul2=0;
    while(idx1+mul1<(1<<N) && V1[idx1]==V1[idx1+mul1]){
      mul1++;
    }
    while(idx2+mul2<(1<<N) && V2[idx2]==V2[idx2+mul2]){
      mul2++;
    }
    ans+=mul1*mul2;
    //cout << V1[idx1] << " " << V2[idx2]<<" " << mul1*mul2 <<endl;
    idx1+=mul1;idx2+=mul2;
  }
  cout << ans << endl;
}

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

string s;
int memo[310][310][310];

int dp(int l, int r, int k){
    if(l > r){
        return 0;
    }

    if(l == r){
        return 1;
    }

    if(memo[l][r][k] != -1) return memo[l][r][k];

    int ans = 0;
    ans = max(ans, dp(l+1, r, k));
    ans = max(ans, dp(l, r-1, k));

    if(s[l] == s[r]){
        ans = max(ans, dp(l+1, r-1, k)+2);
    }else if(k > 0){
        ans = max(ans, dp(l+1, r-1, k-1)+2);
    }

    return memo[l][r][k] = ans;
}

int main(){
    cin >> s;
    int k;
    cin >> k;
    memset(memo, -1, sizeof(memo));
    cout << dp(0, s.size()-1, k) << endl;
    return 0;
}


#include<iostream>
#include<algorithm>

using namespace std;
typedef long long ll;

int N, K;
const ll MOD = 998244353;
ll F[4002], F_inv[4002];

ll modpow(ll a, ll b) {
	ll rtn = 1, kakeru = a;
	while (b > 0) {
		if (b & 1)rtn *= kakeru;
		kakeru *= kakeru;
		kakeru %= MOD;
		rtn %= MOD;
		b >>= 1;
	}
	return rtn;
}

void calc_fac() {
	F[0] = 1, F[1] = 1;
	for (int i = 2; i <= 4001; i++) {
		F[i] = F[i - 1] * i;
		F[i] %= MOD;
	}

	F_inv[4001] = modpow(F[4001], MOD - 2);
	for (int j = 4000; j >= 0; j--) {
		F_inv[j] = F_inv[j + 1] * (j + 1);
		F_inv[j] %= MOD;
	}

}

ll comb(ll a, ll b) {
	if (a < 0)return 0;
	if (b < 0)return 0;
	if (b > a)return 0;
	ll ans = (F[a] * F_inv[b])%MOD * F_inv[a - b];
	return ans % MOD;
}

ll hcomb(ll a, ll b) {
	return comb(a + b - 1, b);
}

int main() {

	calc_fac();

	cin >> K >> N;

	for (int i = 2; i <= 2 * K; i++) {
		if (i % 2 == 1) {
			ll cnt = 0;
			int A = min((i - 1) / 2, (2 * (K + 1) - i) / 2);
			for (int j = 0; j <= A; j++) {
				ll tmp = 1;
				tmp *= (modpow(2, j) * comb(A, j)) % MOD;
				tmp *= hcomb(K - 2 * A + j, N - j);
				tmp %= MOD;
				cnt += tmp;
				cnt %= MOD;
			}
			cout << cnt << endl;
		}
		else {
			ll cnt = 0;
			int A = min((i) / 2, (2 * (K + 1) - i) / 2) - 1;
			for (int j = 0; j <= A; j++) {
				ll tmp = 1;
				tmp *= (modpow(2, j) * comb(A, j)) % MOD;
				ll a = hcomb(K - 2 * A + j - 1, N - j) + hcomb(K - 2 * A + j - 1, N - j - 1);
				a %= MOD;
				tmp *= a;
				tmp %= MOD;
				cnt += tmp;
				cnt %= MOD;
			}
			cout << cnt << endl;
		}
	}

	return 0;
}


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

int main(){
	int md[11] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30};
	int m, d;
	string str[7] = {"Wednesday", "Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday"};

	while(true){
		cin >> m >> d;

		if(m == 0 && d == 0) return 0;

		for(int i = 1; i < m; i++){
			d += md[i - 1];
		}

		cout << str[d % 7] << endl;
	}
}

#include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int l[10],v1,v2;
  int result,ans;
  double total, time, distance;

  while(scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",&l[0],&l[1],&l[2],&l[3],&l[4],&l[5],&l[6],&l[7],&l[8],&l[9],&v1,&v2) != EOF){

    total=0;
    for(int i=0; i<10; i++)
      total += l[i];
    time = (double)total/(v1+v2);
    distance = v1 * time;
    result = 0;
    for(ans=0; result < distance; ans++)
      result += l[ans];
    cout << ans << endl;
  }
}


#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>

#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define int long long

const int INF = 1e18;
const int MOD = 1e9+7;
//const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで

using namespace std;

//typedef pair<int, int> P;
//priority_queue< P, vector<P>, greater<P> > q;//ダイクストラの時、greaterで小さい順
//cout << fixed << setprecision(10) << ans << endl;
//int gcd(int a,int b){return b?gcd(b,a%b):a;}

int a[200000];
int b[200000];
signed main(){
  int n,m,v,p;
  cin >> n >> m >> v >> p;
  REP(i,n){
    cin >> a[i];
  }
  sort(a,a+n);
  reverse(a,a+n);

  int left = 0;
  int right = n;
  while(right - left >= 2){
    int v2 = v;
    int mid = (left+right)/2;
    if(mid < p){
      left = mid;
      continue;
    }
    v2 -= p-1;
    v2 -= n-mid;
    if(v2 <= 0 && a[mid] + m-a[p-1]>=0){
      left = mid;
      continue;
    }
    else if(v2 <= 0 && a[mid] + m-a[p-1]<0){
      right = mid;
      continue;
    }
    int nokori = 0;
    int f = 0;
    for(int i = p-1;i<=mid-1;i++){
      int now = a[mid] + m - a[i];
      if(now < 0) f=1;
      nokori += min(now,m);
    }
    if(f==1){
      right = mid;
      continue;
    }
    if(nokori >= m*v2){
      left = mid;
      continue;
    }
    else{
      right = mid;
      continue;
    }
  }
  cout << right << endl;

    return 0;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

ll nextLong() { ll x; scanf("%lld", &x); return x;}

ll rev(ll n) {
  ll res = 0;
  while (n > 0) {
    int r = n % 10;
    res = res * 10 + r;
    n /= 10;
  }
  return res;
}

bool check(ll N, ll D) {
  return rev(N) == N + D;
}

ll ways0(int m) {
  if (m < 0) return 0;
  return 9-m;
}

ll ways(int m) {
  return 10-abs(m);
}

ll ten[20];
ll total = 0;
void rec(ll L, ll R, ll D, ll curr) {
  if (curr == 0) return;

  if (L == R) {
    if (D == 0) {
      total += curr * 10;
    }
    return;
  }
  if (L < R) {
    if (D == 0) {
      total += curr;
    }
    return;
  }

  ll C = ten[L] - ten[R];
  if (D < -C*10 || C*10 < D) return;
  if (R == 0) {
    for (int a = 0; a <= 9; a++) {
      rec(L-1, R+1, D - (ten[L]-ten[R]) * a, curr * ways0(a));
    }

  } else {
    for (int a = -9; a <= 9; a++) {
      rec(L-1, R+1, D - (ten[L]-ten[R]) * a, curr * ways(a));
    }
  }
}

ll solve(ll D, ll k) {
  if (k <= 6) {
    ll res = 0;
    for (int n = ten[k-1]; n < ten[k]; n++) {
      if (check(n, D)) ++res;
    }
    return res;
  }
  total = 0;
  rec(k-1, 0, D, 1);
  return total;

}

int main2() {
  ll D = nextLong();
  ll ans = 0;
  for (int k = 1; k <= 18; k++) {
    ans += solve(D, k);
  }
  cout << ans << endl;
  return 0;
}

int main() {

  ten[0] = 1;
  for (int i = 1; i < 20; i++) ten[i] = ten[i-1] * 10;

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
const long double eps = 1e-8;

long double a = 25.0;
long double b = 26.0;
long double c = 1.0;

long long seek(long long Ntemp){

    long double X = a*( (long double)  Ntemp ) + b ;

    return (long long) ceil( log10(X)/log10(b) - c );
}

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

    string S;

    long long n = seek(N);
    N = N - ( (long long) ( pow(b, ((long double) n) ) - b + eps ) /a );

    //cout << "N n " << N << " " << n << endl;

    // # S is n characters

    long long ntemp = n;

    for(int i=0; i<n; i++){
        ntemp = ntemp - 1;
        long long A = (long long) ( pow( b, (long double) (ntemp) ) + eps );
        int ctmp = (int) ( (N-1)/A );

        char ctmp2 = 'a' + ctmp;

        S.push_back(ctmp2);

        //cout << "i ntemp  A ctmp N S " << i << " " << ntemp << " " << A << " " << ctmp << " " << N << " " << S << endl;
        N = N - ( (long long) ctmp )*A;
    }

    cout << S << endl;

    return 0;
}

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

int main(){
    cin >> n;
    string ans = "";
    while(n>0){
        n--;
        ans = char((n)%26+'a')+ans;
        n/=26;
    }
    cout << ans << endl;
}


#include <iostream>
using namespace std;
int main() {
	int n, m, i, point[1000] = { 0 }, kyougi[1000] = { 0 }, ans = 0, tmp = 0, j;
	cin >> n >> m;
	for (i = 0; i < n; i++) {
		cin >> kyougi[i];
	}
	for (i = 0; i < m; i++) {
		int sinsa;
		cin >> sinsa;
		for (j = 0; j < n; j++) {
			if (kyougi[j] <= sinsa) {
				point[j]++;
				break;
			}
		}
	}
	for (i = 0; i < m; i++) {
		if (tmp < point[i]) {
			tmp = point[i];
			ans = i;
		}
	}
	cout << ans+1 << endl;
	return 0;
}

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

using namespace std;

int main(){

    while(true){
    int n,m;
    cin >> n ;
    if(cin.eof()) break;
    cin >> m;

    vector<int> a(1000);
    vector<int> b(1000);
    vector<int> c(1000);
    vector<bool> u(1000);
    vector<int> ans(1000);
    fill(u.begin(),u.end(),true);
    for(int i=0;i<n;i++){
	cin >> a[i];
    };
    for(int i=0;i<m;i++){
	cin >> b[i];
    }
    for(int i=0;i<n;i++){
	for(int j=0;j<m;j++){
	    if(u[j] && a[i] <= b[j]){
		u[j] = false;
		ans[i]++;
	    }
	}
    }
    int res = -1,ansnum = 0;;
    for(int i=0;i<n;i++){
	if(res < ans[i]){
	    res = ans[i];
	    ansnum = i + 1;
	}
    }

    cout << ansnum << endl;
    }

    return 0;
}


/*
  Contest 091
  B - Two Colors Card Game
  Rakesh Kumar --> 21/09/2020
 */

#include <bits/stdc++.h>

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

    std::unordered_map<std::string, int> dict;
    int n = 0;
    std::cin >> n;
    std::cin.ignore();
    while (n--) {
        std::string s;
        std::getline(std::cin, s);
        ++dict[s];
    }
    std::cin >> n;
    std::cin.ignore();
    while (n--) {
        std::string s;
        std::getline(std::cin, s);
        --dict[s];
    }

    int max = 0;
    for (auto it : dict)
        max = std::max(max, it.second);
    std::cout << max << std::endl;

    return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <map>
#include <iomanip>

using ll = long long;
using ld = long double;
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))

int const nmax = 200000;
std::vector<std::pair<int,int>> v;
std::map<std::pair<int,int>,int> mp;

int main() {
  int n;
  std::cin >> n;
  for(int i = 1;i <= n; i++) {
    ld init;
    std::cin >> init;
    ll number = llround(1000000000LL * init);
    std::pair<int,int> basic(0, 0);

    while(number % 2 == 0) {
      number /= 2;
      basic.first++;
    }
    while(number % 5 == 0) {
      number /= 5;
      basic.second++;
    }
    mp[basic]++;
    if(mp[basic] == 1)
      v.push_back(basic);
  }
  ll result = 0;

  for(int i = 0; i < v.size(); i++)
    for(int j = i; j < v.size(); j++)
      if(18 <= v[i].first + v[j].first && 18 <= v[i].second + v[j].second) {
        if(i == j)
          result += 1LL *  mp[v[i]] * (mp[v[i]] - 1) / 2;
        else
          result += 1LL * mp[v[i]] * mp[v[j]];
      }
  std::cout << result;
}


#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int n;
  cin >> n;
  vi a(n+1),b(n+1,0),ans;
  rep(i,n)cin >> a[i+1];
  for(int i = n;i>=1;i--){
    int sum = 0;
    for(int j = i;j<=n;j+=i){
      sum+=b[j];
    }
    if(sum%2 != a[i]){
      b[i] = 1;
      ans.push_back(i);
    }
  }
  cout<<sz(ans)<<endl;
  rep(i,sz(ans))cout<<ans[i]<<" ";
  cout<<endl;
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define X ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FIXED_FLOAT(x) std::fixed <<std::setprecision(2)<<(x)

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

// long long p = 1e9+7;

typedef long long ll;
typedef pair<ll,ll> pl;
typedef vector<int> VI;
typedef vector<pair<ll,ll>> VP;
typedef vector<ll> VL;
typedef vector<bool> VB;

// typedef pair<ll, ll> PL;
typedef unordered_map<ll, ll> UMP;
#define FOR(i,b) for(i=0;i<b;i++)
#define pb push_back
#define mp make_pair

// typedef  unordered_set<ll>;

void printa(VI &x,ll n){
    ll i;
    FOR(i, n){
        cout<<x[i]<<" ";
    }
    cout<<endl;
}

/////GLOABLS VARS
ll MOD = 1e9+7;
ll gmx = 1e6+7;

VL fact(gmx, 1);
//////FUNCTIONS
ll powp(ll val, ll deg)
{
    // debug(val, deg);
    if (!deg)
        return 1;
    if (deg & 1)
        return (powp(val, deg - 1) * val) % MOD;
    ll res = powp(val, deg >> 1);
    // debug(res);
    return (res * res) % MOD;
}

//It is not easy but it can be fun, if you think!!!

//
// ll mx = 2*1e5+7;

int main(){
      ios::sync_with_stdio(0);
      cin.tie(0);
        // #ifndef ONLINE_JUDGE
        //     freopen("input.txt", "r", stdin);
        //     freopen("output.txt", "w", stdout);
        //     #define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
        // #endif
    ll n,i,j;
    cin>>n;
    // priority_queue<ll> l;
    VL l(n+1);
    FOR(i,n){
        ll u;
        cin>>u;
        l[i+1] = u;
    }
    VL arr(n+1);
    ll m = sqrt(n)+1;
    VL ans;
    for(i=n;i>=1;i--){
        // debug(arr,l);
        if(l[i]!=arr[i]){
            // debug(i);
            ans.pb(i);
            unordered_set<ll> seen;
            for(j = 1;j<m;j++){
                if(i%j==0){
                    ll p =i/j;
                    // debug(p,j);
                    if(p==j){
                        if(seen.find(p)==seen.end()){
                        arr[p]  =1-arr[p];
                        seen.insert(p);
                    }
                        // ans.pb(p);

                    }
                    else{
                        if(seen.find(p)==seen.end()){
                        arr[p]  =1-arr[p];seen.insert(p);
                    }
                        if(seen.find(j)==seen.end()){
                        arr[j]  =1-arr[j];seen.insert(j);
                    }
                        // ans.pb(p);
                        // ans.pb(j);
                    }
                }
            }
        }
    }
    cout<<ans.size()<<'\n';
    for(auto k:ans){
        cout<<k<<'\n';
    }

    // }

}


#include<bits/stdc++.h>
using namespace std;
int n,m,v,p,u,ans;
long long g,a[200005],sy,d,s[200005];
int main()
{
	scanf("%d%d%d%d",&n,&m,&v,&p);
	for (int i=1;i<=n;i++)
		scanf("%lld",&a[i]);
	sort(a+1,a+n+1);
	g=a[n-p+1];
	for (int i=1;i<=n;i++)
		s[i]=s[i-1]+a[i];
	ans=p;
	for (int i=1;i<=n-p;i++)
	{
		if (g>a[i]+m)
			continue;
		sy=(long long)m*(long long)(v-1);
		d=(long long)m*(long long)(n-1);
		d-=s[n-p+1]-s[i-1]-(long long)(n-p-i+2)*a[i];
		if (sy<=d)
			ans++;
	}
	printf("%d\n",ans);
	return 0;
}

///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>

#define                           int                         long long
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<int,int>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const int inf=1e18;
const int mod=1e9+7;
const int M=100009;

inline int bigmod(int B,int P){int R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}
inline int ad(int x,int y){int ret=(x%mod+y%mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
inline int sub(int x,int y){int ret=((x%mod)-(y%mod)+mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
inline int gun(int x,int y){int ret=((x%mod)*(y%mod))%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}

int n,m,v,p;
vector<pi>vec;
int a[M+3];
bool vis[M+3];
bool chk(int idx)
{
   int big=p-1;
   int use=v-1;
   int mn=min(big,use);
   big-=mn;
   use-=mn;
   vector<pi>yo;
   if(vis[idx])return true;
   int mx=vec[idx].fi+m;
   int sum=use*m;
   //cout<<sum<<" ### "<<endl;
   for(int i=p-1;i<n;i++)
   {
       if(i==idx)continue;
       int val=vec[i].fi;
       int gap=mx-val;
       if(gap<0)
       {
           //cout<<i<<" "<<mx<<" "<<val<<endl;
       }
       if(gap<0)return false;
       int can=min(gap,m);
       sum-=can;
   }
   if(sum<=0)return true;
   else return false;
}
 main()

{
    fast
    cin>>n>>m>>v>>p;
    f(i,1,n)
    {
        int x;
        cin>>x;
        a[i]=x;
        vec.pb(mp(x,i));
    }
    sort(vec.rbegin(),vec.rend());
    int last;
    for(int i=0;i<p;i++)
    {
        vis[i]=true;
        last=vec[i].fi;
    }
    for(int i=p;i<n;i++)
    {
        if(vec[i].fi==last)
        {
            vis[i]=true;
        }
        else break;
    }
   // cout<<chk(3)<<"#"<<endl;
    int lo=0,hi=n-1;
    while(hi-lo>=2)
    {
        int mid=(lo+hi)>>1;
        if(chk(mid))lo=mid;
        else hi=mid-1;
    }
    int ses=-1;
    for(int i=lo;i<=hi;i++)
    {
        if(chk(i))ses=i;
    }
    if(ses==-1)
    {
        cout<<"0"<<endl;
        return 0;
    }
    ses=ses+1;
    cout<<ses<<endl;
    return 0;

}


#include <iostream>
#include <vector>

using namespace std;

int dfs(auto& nodes, int current_index, int parent_index, int& time) {
    int children = 0;

    auto& current_node = nodes[current_index];
    current_node.time = time;
    current_node.low = time;

    for (auto adjacent_index : current_node.adjacent) {
        if (adjacent_index == parent_index) {
            continue;
        }

        auto& adjacent_node = nodes[adjacent_index];
        if (adjacent_node.time) {
            current_node.low = min(adjacent_node.time, current_node.low);
        } else {
            ++children;
            dfs(nodes, adjacent_index, current_index, ++time);

            if (current_node.time <= adjacent_node.low) {
                current_node.is_articulation_point = true;
            }

            current_node.low = min(adjacent_node.low, current_node.low);
        }
    }

    return children;
}

int main() {
    int n, m;

    cin >> n >> m;
    if (n == 0 || m == 0) {
        return 0;
    }

    struct node {
        int time{0};
        int low{0};
        bool is_articulation_point{false};
        vector<int> adjacent;
    };

    vector<node> nodes(n);
    for (int i = 0; i < m; ++i) {
        int from, to;
        cin >> from >> to;
        nodes[from].adjacent.push_back(to);
        nodes[to].adjacent.push_back(from);
    }

    int time = 0;
    nodes[0].is_articulation_point = dfs(nodes, 0, -1, ++time) > 1;

    for (int i = 0; i < nodes.size(); ++i) {
        if (nodes[i].is_articulation_point) {
            cout << i << endl;
        }
    }

    return 0;
}

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

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
#define all(x) x.begin(), x.end()
#define rep(i,a,b) for(int i = a; i < b; i++)

int V, E;
vvi conn(100002);
vi vis(100002);
vb trail(100002);
vb cut(100002);

int dfs_min(int v, int depth, int parent) {
  if(vis[v] > 0) return vis[v];
  vis[v] = depth;
  trail[v] = true;

  int minHit = depth;
  rep(i,0,(int)conn[v].size()) {
    if(conn[v][i] != parent && (vis[conn[v][i]] == 0 || trail[conn[v][i]])) {
      int hit = dfs_min(conn[v][i], depth+1, v);
      minHit = min(minHit, hit);
      if(hit >= depth && conn[v].size() > 1)
	cut[v] = true;
    }
  }

  trail[v] = false;
  return minHit;
}

int main() {
  cin >> V;
  cin >> E;
  rep(e,0,E) {
    int s, t;
    cin >> s;
    cin >> t;
    conn[s].push_back(t);
    conn[t].push_back(s);
  }

  dfs_min(0, 1, -1);
  if(V > 1) {
    cut[0] = false;
    bool remember = cut[1];
    fill(all(vis), 0);
    dfs_min(1, 1, -1);
    cut[1] = remember;
  }

  rep(v,0,V)
    if(cut[v])
      cout << v << '\n';
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

ll a[100005],b[100005];
int q[100005];

int main() {
  int n,s;
  scanf("%d%d",&n,&s);
  int id=0;
  for(int i=1;i<=n;i++) {
  	scanf("%lld%lld",&a[i],&b[i]);
  	if (a[i]<s) id=i;
  }
  int cnt=0,l=1,r=n;
  while ((l<=id)^(r<=id))
    if (b[l]>=b[r]) {
    	q[++cnt]=a[r];
    	b[l]+=b[r];
    	r--;
	}
	else {
		q[++cnt]=a[l];
		b[r]+=b[l];
		l++;
	}
  if (r<=id) {
  	for(int i=l;i<=r;i++) q[++cnt]=a[i];
  }
  else {
  	for(int i=r;i>=l;i--) q[++cnt]=a[i];
  }
  q[cnt+1]=s;
  ll ans=0;
  for(int i=1;i<=cnt;i++) ans+=abs(q[i]-q[i+1]);
  printf("%lld\n",ans);
  return 0;
}

#include <bits/stdc++.h>

const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;
const double PI = acos(-1.0);
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct
{
    int to;
    int cost;
};

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

vector<edge> graph;

class UnionFind
{
  private:
    vector<int> par;
    vector<int> sizes;

  public:
    UnionFind(int N) : par(N), sizes(N, 1)
    {
        rep(i, N) par[i] = i;
    }

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

        return par[x] = find(par[x]);
    }

    void unite(int x, int y)
    {
        x = find(x);
        y = find(y);

        if (x == y)
            return;

        if (sizes[x] < sizes[y])
            swap(x, y);

        par[y] = x;
        sizes[x] += sizes[y];
    }

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

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

int main()
{
    int V, E;
    cin >> V >> E;
    vector<tuple<int, int, int>> graph; //cost, from, to
    rep(i, E)
    {
        int s, t, w;
        cin >> s >> t >> w;
        graph.push_back(T{w, s, t});
        graph.push_back(T{w, t, s});
    }

    sort(graph.begin(), graph.end());

    UnionFind uf(V);

    ll ans = 0;

    for(auto e : graph)
    {
        int from, to, cost;
        tie(cost, from, to) = e;

        if(!uf.same(from, to))
        {
            ans += cost;
            uf.unite(from, to);
        }
    }

    cout << ans << endl;

    return 0;
}


#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
#define rep(i, f, n) for (ll i = (f); i < (ll)(n); i++)
#define repe(i, f, n) for (ll i = (f); i <= (ll)(n); i++)
#define accum(x) accumulate((x).begin(), (x).end(), 0)
using namespace std;
using ll = long long;
using pint = pair<int, int>;

const ll MOD = 1e9 + 7;

int a[1001];

void f(int X) {
  int x = X;
  for (int i = 2; i * i <= X; i++) {
    if (x % i != 0) continue;
    while (x % i == 0) {
      a[i]++;
      x /= i;
    }
  }
  if (x != 1) a[x]++;
}

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

  repe(i, 2, n) f(i);

  ll ans = 1;
  repe(i, 2, n) {
    if (a[i] == 0) continue;
    ans *= a[i] + 1;
    ans %= MOD;
  }

  cout << ans << endl;

  return 0;
}

#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    int n;
    cin>>n;
    int cnt = 0;
    if(n<3){
        cout<<0<<endl;
        return 0;
    }
    cnt = 0;
    while(n>=3){
        cnt++;
        n-=3;
    }
    cout<<cnt<<endl;
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <string>
#include <map>
#include <functional>
#include <cmath>
#include <cstdio>
using namespace std;

#define PI 4*atan(1);

int main(){
  int n, a, b, c;
  vector<int> ans;
  ans.push_back(1);
  cin >> n;
  if(n == 2){
    cin >> a >> b;
    for(int i = 2; i < max(a, b); i++){
      if(a % i == 0 && b % i == 0){
        ans.push_back(i);
      }
    }
    for(int i = 0; i < ans.size(); i++){
      cout << ans[i] << endl;
    }
  }else if(n == 3){
    cin >> a >> b >> c;
    for(int i = 2; i < max(max(a, b), c); i++){
      if(a % i == 0 && b % i == 0 && c % i == 0){
        ans.push_back(i);
      }
    }
    for(int i = 0; i < ans.size(); i++){
      cout << ans[i] << endl;
    }
  }
}

#include <iostream>
using namespace std;

int main()
{
    int h,w,t,maxh=0,maxw=0;
    long taikakusen[200][200],max=0;

    //??¢?´¢ i=w j=h
    for(int i=1;i<=150;i++){
        for(int j=1;j<i;j++){
            taikakusen[i][j] = i*i + j*j;
        }
    }

    cin>>h>>w;

    while(h != 0 && w != 0){
        t = h*h + w*w;
        for(int i=1;i<=150;i++){
            for(int j=1;j<i;j++){
                if(t<taikakusen[i][j]){
                    if(max==0){
                        maxh=j;
                        maxw=i;
                        max=taikakusen[i][j];
                    }
                    else if(taikakusen[i][j]==max){
                        if(j<maxh){
                            maxh=j;
                            maxw=i;
                        }
                    }
                    else if(taikakusen[i][j]<max){
                        maxh=j;
                        maxw=i;
                        max=taikakusen[i][j];
                    }
                }
                if(t==taikakusen[i][j] && j>h){
                    maxh=j;
                    maxw=i;
                    max=taikakusen[i][j];
                }
            }
        }

        cout<<maxh<<" "<<maxw<<"\n";
        maxh=0;
        maxw=0;
        max=0;

        cin>>h>>w;
    }

    return 0;
}


#include <stdio.h>
#include <string.h>
#include <string>
#include <iostream>
#include <vector>
#include <sstream>
#include <memory>
#include <iomanip>

std::vector<int> parse_line(std::string const& line) {
    using namespace std;
    vector<int> result;
    istringstream s(line);
    string element;
    while (getline(s, element, ' ')) {
        stringstream buf;
        int value = 0;
        buf << element;
        buf >> value;
        result.push_back(value);
    }
    return std::move(result);
}
int main(int argc, char* argv[])
{
    using namespace std;
    while (true) {
        string line;
        getline(std::cin, line);
        auto elements = parse_line(line);
        auto length = elements[0];
        if (length == 0) break;
        vector<int> total(length + 1);
        size_t width = length + 1;
        for (size_t i = 0; i < length; ++i) {
            getline(cin, line);
            elements = parse_line(line);
            int sum = 0;
            for (size_t n = 0; n < length; ++n) {
                int val = elements[n];
                sum += val;
                total[n] += val;
                cout << setw(5) << val;
            }
            cout << setw(5) << sum << endl;
            total[length] += sum;
        }
        for (size_t i = 0; i < width; ++i) {
            cout << setw(5) << total[i];
        }
        cout << endl;
    }

    return 0;
}

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

int main(){
  int n;

  while(cin>>n,n){
    int t[n+1][n+1];
    memset(t,0,sizeof(t));
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
        cin>>t[i][j];
        t[i][n] += t[i][j];
        t[n][j] += t[i][j];
        t[n][n] += t[i][j];
      }
    }

    for(int i=0;i<=n;i++){
      for(int j=0;j<=n;j++){
        printf("%5d",t[i][j]);
      }
      printf("\n");
    }
  }
}


//Author:xht37
#include <bits/stdc++.h>

#define ui unsigned int
#define ll long long
#define ul unsigned ll
#define ld long double

#define pi pair <int, int>
#define fi first
#define se second
#define mp make_pair

#define ls (p << 1)
#define rs (ls | 1)
#define md ((t[p].l + t[p].r) >> 1)

#define vi vector <int>
#define pb push_back
#define pq priority_queue

#define dbg(x) cerr << #x" = " << x << endl
#define debug(...) fprintf(stderr, __VA_ARGS__)

#define fl(x) freopen(x".in", "r", stdin), freopen(x".out", "w", stdout)

using namespace std;

namespace io {
	const int SI = 1 << 21 | 1;
	char IB[SI], *IS, *IT, OB[SI], *OS = OB, *OT = OS + SI - 1, c, ch[100];
	int f, t;
	#define gc() (IS == IT ? (IT = (IS = IB) + fread(IB, 1, SI, stdin), IS == IT ? EOF : *IS++) : *IS++)
	inline void flush() {
		fwrite(OB, 1, OS - OB, stdout), OS = OB;
	}
	inline void pc(char x) {
		*OS++ = x;
		if (OS == OT) flush();
	}

	template <class I>
	inline void rd(I &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + (c & 15), c = gc());
		x *= f;
	}
	template <class I>
	inline void rd(I &x, I &y) {
		rd(x), rd(y);
	}
	template <class I>
	inline void rd(I &x, I &y, I &z) {
		rd(x), rd(y), rd(z);
	}
	template <class I>
	inline void rda(I *a, int n) {
		for (int i = 1; i <= n; i++) rd(a[i]);
	}
	inline void rdc(char &c) {
		for (c = gc(); c < 33 || c > 126; c = gc());
	}
	inline void rds(char *s, int &n) {
		for (c = gc(); c < 33 || c > 126; c = gc());
		for (n = 0; c >= 33 && c <= 126; s[++n] = c, c = gc());
		s[n+1] = '\0';
	}
	inline void rds(string &s) {
		for (c = gc(); c < 33 || c > 126; c = gc());
		for (s.clear(); c >= 33 && c <= 126; s.pb(c), c = gc());
	}

	template <class I>
	inline void print(I x, char k = '\n') {
		if (!x) pc('0');
		if (x < 0) pc('-'), x = -x;
		while (x) ch[++t] = x % 10 + '0', x /= 10;
		while (t) pc(ch[t--]);
		pc(k);
	}
	template <class I>
	inline void print(I x, I y) {
		print(x, ' '), print(y);
	}
	template <class I>
	inline void print(I x, I y, I z) {
		print(x, ' '), print(y, ' '), print(z);
	}
	template <class I>
	inline void printa(I *a, int n) {
		for (int i = 1; i <= n; i++) print(a[i], " \n"[i==n]);
	}
	inline void printc(char c) {
		pc(c);
	}
	inline void prints(char *s, int n) {
		for (int i = 1; i <= n; i++) pc(s[i]);
		pc('\n');
	}
	inline void prints(string s) {
		int n = s.length();
		while (t < n) pc(s[t++]);
		pc('\n'), t = 0;
	}
	struct Flush {
		~Flush() {
			flush();
		}
	} flusher;
}
using io::rd;
using io::rda;
using io::rdc;
using io::rds;
using io::print;
using io::printa;
using io::printc;
using io::prints;

const int N = 1e5 + 7;
int n, ans;
pi a[N];
int l[N], r[N];

int main() {
//	fl("1");
	rd(n);
	for (int i = 1; i <= n; i++) rd(a[i].fi, a[i].se);
	sort(a + 1, a + n + 1);
	l[0] = r[n+1] = 1e9;
	for (int i = 1; i <= n; i++) l[i] = min(a[i].se, l[i-1]);
	for (int i = n; i; i--) r[i] = min(a[i].se, r[i+1]);
	for (int i = 1; i <= n; i++)
		ans = max(ans, a[i].se - a[i].fi + 1 + max(0, min(l[i-1], r[i+1]) - a[n-(i==n)].fi + 1));
	for (int i = 1; i < n; i++)
		if (a[i].fi <= l[i] && a[n].fi <= r[i+1])
			ans = max(ans, l[i] - a[i].fi + 1 + r[i+1] - a[n].fi + 1);
	print(ans);
	return 0;
}

//
//  main.c
//  ITP1_4_D
//
//  Created by ??±??°?????? on 2015/09/29.
//  Copyright ?? 2015??´ HamadaShogo. All rights reserved.
//

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

long long intSum(int *num, int size);
int intMax(int *num, int size);
int intMin(int *num, int size);

int main(int argc, const char * argv[]) {
    int *num;
    int size;
    long long sum;
    int max;
    int min;
    int i;

    scanf("%d", &size);
    num = (int *)malloc(sizeof(int) * size);
    if (num == NULL) {
        printf("?????¢???????¢??????§????????????\n");
        exit(1);
    }

    for (i=0; i<size; i++) {
        scanf("%d", &num[i]);
    }

    sum = intSum(num, size);
    max = intMax(num, size);
    min = intMin(num, size);

    printf("%d %d %lld\n", min, max, sum);

    free(num);

    return 0;
}

long long intSum(int *num, int size){
    int i;
    long long sum = 0;

    for(i=0; i<size; i++){
        sum += num[i];
    }

    return sum;
}

int intMax(int *num, int size){
    int i;
    int max = num[0];

    for (i=0; i<size; i++) {
        if (max < num[i]) {
            max = num[i];
        }
    }

    return max;
}

int intMin(int *num, int size){
    int i;
    int min = num[0];

    for (i=0; i<size; i++) {
        if (num[i] < min) {
            min = num[i];
        }
    }

    return min;
}


#include<iostream>
using namespace std;
int p = 1000000007;
int log2_p_MAX = 32;
long long felmer(long long a)
{
  long long rem[log2_p_MAX];
  rem[0] = a%p;
  for(int i=1;i<log2_p_MAX;i++)
    rem[i] = (rem[i-1]*rem[i-1])%p;
  long long res = 1;
  long long expo = p-2;
  for(int i=0;i<log2_p_MAX;i++){
	if(expo%2==1){
      res *= rem[i];
      res = res%p;
    }
  	expo /= 2;
  }
  return res;
}
int main()
{
  long long n,m,k,mn,i,res;
  cin >> n >> m >> k;
  res=m*n*(m*(n-1)*(n+1)+n*(m-1)*(m+1));
  res%=p;
  res*=felmer(6);
  res%=p;
  mn=m*n-2;
  k-=2;
  for(i=1;i<=k;i++){
    res*=mn-i+1;
    res%=p;
    res*=felmer(i);
    res%=p;
  }
  cout << res << endl;
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E17;

#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
///////////////////////////////////////
#define N 500004

ll kai[N];
ll kai2[N];
ll po(ll i,ll p){
    if(p==0)return 1;
    else if(p==1)return mod(i);
    else if(p%2==0)return po(mod(mod(i)*mod(i)),p/2);
    else  return mod(mod(i)*po(i,p-1));
}
void calc(){
    kai[0]=1;
    kai2[0]=1;
    rep(i,1,N-1){
        kai[i]=mod(kai[i-1]*i);
    }
    kai2[N-1]=po(kai[N-1],i_5);
    for(ll i=N-2;i>=0;i--){
        kai2[i]=mod(kai2[i+1]*(i+1));
    }
}
ll comb(ll n,ll k){
    if(n<k)return 0;
    else if(n==0)return 1;
    else return mod(mod(kai[n]*kai2[n-k])*kai2[k]);
}
ll bunbo(ll n){
    return po(n,i_5);
}

int main(){fastio
    calc();
    ll n,m,k;cin>>n>>m>>k;
    ll last=kai2[k-2];
    ll nowu=mod(n*m-2);
    rep(i,1,k-2){
        last=mod(last*nowu);
        nowu--;
        if(nowu<0)nowu=mod(nowu);
    }
    ll s[N];s[0]=0;rep(i,1,N-1)s[i]=s[i-1]+i;
    ll sum1=0,sum2=0;
    rep(i,1,m){
        sum1+=s[i-1]+s[m-i];
    }
    sum1=mod(mod(sum1*n)*n);
    rep(i,1,n){
        sum2+=s[i-1]+s[n-i];
    }
    sum2=mod(mod(sum2*m)*m);

    //cout<<sum1<<" "<<sum2<<endl;
    sum1=mod(sum1+sum2);
    last=mod(last*sum1);
    last=mod(last*bunbo(2));
    cout<<last<<endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n,m;
	cin>>n>>m;
	ll ch[3];
	for(ll i=0;i<3;i++){
		ch[i]=-1;
	}
	for(ll i=0;i<m;i++){
		ll x,z;
		cin>>x>>z;
		x--;
		if(ch[x]==-1){
			ch[x]=z;
		}
		else{
			if(ch[x]!=z){
				cout << -1;
				return 0;
			}
		}
	}
	if(ch[0]==0&&n!=1){
		cout <<-1;
		return 0;
	}
	for(ll i=0;i<n;i++){
		if(ch[i]==-1){
			if(i==0&&n!=1){
				cout << 1;
			}
			else{
			cout << 0;
			}
		}
		else{
		cout << ch[i];
		}
	}
	// your code goes here
	return 0;
}

#include<bits/stdc++.h>

using namespace std;

int main()
{
    int N,M;
    cin >> N >> M;
    vector<int> s(M);
    vector<int> c(M);
    int ans=0;

    if(M == 0 && N==1){
        cout << "0" << endl;
        return 0;
    }

    for(int i=0; i<M; i++){
        cin >> s.at(i) >> c.at(i);
        if(N>1 && s.at(i) == 1 && c.at(i) == 0){
            cout << "-1" << endl;
            return 0;
        }
    }

    vector<int> d(N);

    for(int i=0; i<M; i++){
        if(d.at(s.at(i)-1) == 1 && c.at(i) != ans/(int)(pow(10,N-s.at(i))) ) {
            cout << "-1" << endl;
            return 0;
        }
        if(d.at(s.at(i)-1) == 0){
            ans += c.at(i)*(int)pow(10,N-s.at(i)) ;
            d.at(s.at(i)-1)++;
        }
    }

    if(d.at(0) == 0){
        ans += (int)pow(10,N-1);
    }

    cout << ans << endl;

}


#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
    long long min=0,max=0,total=0;

    int x,n;
    cin >>x;
    for (int i=1; i<=x; i++) {

        cin >> n;

        if(i==1){

            min =n;
            max=n;
            total=n;
        }else {
            if(n<min){
                min=n;
            }
            if(n>max){
                max=n;
            }

            total=total+n;
        }
    }
    cout <<min<<" "<<max<<" "<<total<<endl;

    // insert code here...
    //std::cout << "Hello, World!\n";
    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 ull = unsigned long long; using P = pair<int, int>;
const int INF = 1e9; const int MOD = 1000000007;
const int dx[] = {-1,0,1,0}; const int dy[] = {0,-1,0,1};
//const int dx[] = {-1,-1,-1, 0, 0, 1, 1, 1}; const int dy[] = {-1, 0, 1,-1, 1,-1, 0, 1};
#define PI 3.14159265358979323846264338327950L //setprecision(15)

int main() {
	int N; cin >> N;
	string s, t; cin >> s >> t;
	string tmp;
	int ans = INF;
	for (int i = 0; i <= t.length(); i++) {
		tmp = s;
		tmp = s + t.substr(t.length()-i);
		if (tmp.substr(0,N) == s &&
		    tmp.substr(i,N) == t) ans = min(ans, (int)tmp.length());
	}
	cout << ans << endl;
}


#include <iostream>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int64_t N, M;
  cin >> N >> M;
  unordered_map<int64_t, int64_t> count;
  int64_t sum = 0;
  count[sum]++;
  rep(i, N) {
    int a;
    cin >> a;
    sum = (sum + a) % M;
    count[sum]++;
  }

  int64_t answer = 0;
  for (auto& n : count) {
    answer += (n.second) * (n.second - 1) / 2;
  }
  cout << answer << endl;
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define INF 2000000000000000000LL
typedef long long int ll;
typedef pair<ll,ll> ii;
typedef pair<ii,ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
#define getbit(n,i) (((n)&(1LL<<(i)))!=0)
#define setbit0(n,i) ((n)&(~(1LL<<(i))))
#define setbit1(n,i) ((n)|(1LL<<(i)))
#define lastone(n) ((n)&(-(n)))
#define read freopen("debug\\in.txt","r",stdin)
#define write freopen("debug\\out.txt","w",stdout)
#define DBG(a) cout<<#a<<" ->->->-> "<<a<<"\n"
#define EN cout<<"\n"
#define fi first
#define se second
#define PI (acos(-1))
#define fastread ios::sync_with_stdio(false);cin.tie(NULL)
#define mod (1000000007)
#define asz 2000005
template<class T,class V> ostream& operator<<(ostream &s,pair<T,V> a)
{
    s<<a.fi<<' '<<a.se;
    return s;
}
int main()
{
    fastread;
    int T=1;
//    cin>>T;
    for(int qq=1; qq<=T; qq++)
    {
        int n,m;
        cin>>n>>m;
        ll sum=0,ans=0;
        map<ll,ll> mp;
        mp[0]=1;
        for(int i=0;i<n;i++){
            ll x;
            cin>>x;
            sum+=x;
            ans+=mp[sum%m];
            mp[sum%m]++;
        }
        cout<<ans<<endl;
    }
}


//FIRST THINK THEN CODE.

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

//#define MOD 998244353
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define FOR(i,n)  for(ll i=0;i<n;i++)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()
#define rev(p) reverse(p.begin(),p.end());
#define endl "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define popcount(x) __builtin_popcountll(x)
#define sz(x) ((ll)x.size())
const ll M=1000000007;
const ll MM=998244353;
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";

ll newmod(ll a,ll b)
 {
  return ((a%b)+b)%b;
}

ll powM(ll a,ll b,ll m )
{
  if(a<=0)return 0;
  a%=m;
  if(!b)return 1;
  ll ans=1LL;
  while(b)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }

return ans;
}

ll poww(ll a,ll b)
{

  ll ans=1;
  while(b)
  {
    if(b&1)ans=ans*a;
    a=a*a;
    b>>=1;
  }

return ans;

}

template<typename T,typename F>
void chmax( T &a,F b){
  if(b>a)a=b;
}

template<typename T,typename F>
void chmin( T &a,F b){
  if(b<a)a=b;
}

const ll N=1e5+5;

int main()
{

IOS;

ll n;cin>>n;

vl f(N);

ll ans=1;

for(int i=1;i<=n;i++){
  ll x;cin>>x;
  ll temp;
  if(!x){
    temp=3-f[0];
  }
  else {
    temp=f[x-1]-f[x];
  }
  if(temp<=0){
    cout<<0;
    return 0;
  }
  ans=ans*temp%M;
  f[x]++;
}

cout<<ans;

//end_routine();

return 0;

}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll K;
    cin >> K;
    ll N = 50;
    ll a[55] = {};
    rep(i,0,N) a[i] = i;
    ll v = K / N;
    rep(i,0,N) a[i] += v;
    ll amari = K % N;
    rep(i,0,amari){
        rep(j,0,N){
            if(i == j){
                a[j] += N;
            }else{
                a[j]--;
            }
        }
    }
    print(N);
    printa(a,N);

}


#include <iostream>
#include <fstream>
#include <cmath>

using std::cin;
using std::cout;
using std::endl;

int limit(int lim, int exp) {
	int res = 0;
	for (int i = 0; pow(i,exp) < lim+1; i++) {
		res = i;
	}
	return res;
}

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

	while (e != 0) {
		int m = 0;
		int res;
		int en = e;
		int temp;
		int z = limit(en,3);

		for (int i = 0; i < 10 && !((z-i) < 0); i++) {
			m = 0;
			en = e;

			m += z-i;
			en -= pow(z-i,3);

			temp = limit(en,2);
			m += temp;
			en -= pow(temp,2);

			temp = limit(en,1);
			m += temp;

			if (i == 0) {
				res = m;
			}
			else if (m < res) {
				res = m;
			}
		}

		temp = limit(e,2);
		if (temp < res) {
			if (pow(temp,2) == e) {
				res = temp;
			}
		}

		cout << res << endl;
		cin >> e;
	}
	return 0;
}

#include<iostream>
using namespace std;
int e,x,y,MIN,i,j;
int main(){
	while(true){
		MIN=1<<27;
		cin>>e;if(!e){break;}
		for(i=0;i*i*i<=e;i++){
			for(j=0;j*j+i*i*i<=e;j++){
				MIN=min(MIN,i+j+e-(i*i*i+j*j));
			}
		}
		cout<<MIN<<endl;
	}
}


#include <cstdio>
#include <vector>

using namespace std;

int main()
{
    int n, q;
    scanf("%d", &n);
    vector<int> S(n);
    for(auto it=S.begin(); it!=S.end(); it++){
        scanf("%d", &(*it));
    }
    S.push_back(-1);
    scanf("%d", &q);
    int sum=0;
    for(int i=0; i<q; i++){
        int qq;
        scanf("%d", &qq);
        *S.end()=qq;
        auto it=S.begin();
        for(; *it!=qq; it++){
        }
        sum+=it==S.end() ? 0 : 1;
    }
    printf("%d\n", sum);
    return 0;
}

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

void fnInput(vector<int> &rviTrg, vector<int> &rviSch)
{
  int iTrgCnt;
  cin >> iTrgCnt;

  rviTrg.resize(iTrgCnt + 1);
  for (int i = 0; i < iTrgCnt; i++)
    cin >> rviTrg[i];

  int iSchCnt;
  cin >> iSchCnt;

  rviSch.resize(iSchCnt);
  for (int i = 0; i < iSchCnt; i++)
    cin >> rviSch[i];
}

void fnLinSch(vector<int> &rviTrg, const vector<int> &cnrviSch, int &riFnd)
{
  size_t zMaxSiz = rviTrg.size() - 1;
  for (size_t zi = 0; zi < cnrviSch.size(); zi++)
  {
    rviTrg[zMaxSiz] = cnrviSch[zi];
    size_t zj = 0;
    while (rviTrg[zj] != cnrviSch[zi])
      zj++;
    if (zj != zMaxSiz)
      riFnd++;
  }
}

void fnResult(int a_iFnd)
{
  cout << a_iFnd << endl;
}

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

  vector<int> viTrg, viSch;
  int iFnd = 0;

  fnInput(viTrg, viSch);
  fnLinSch(viTrg, viSch, iFnd);
  fnResult(iFnd);

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b
vi vx={-1,0,1,0};
vi vy={0,1,0,-1};
using pi = pair<int,int>;

signed main(){
	int a,b; cin>>a>>b;
	vvi v(a,vi(b));
	queue<pi> q;
	rep(i,0,a){
		rep(j,0,b){
			char c; cin>>c;
			if(c=='#'){
				v[i][j]=1;
				q.push(make_pair(i,j));
			}
			else v[i][j]=0;
		}
	}
	while(!q.empty()){
		pi p=q.front(); q.pop();
		int k,l; tie(k,l)=p;
		bool ok=false;
		rep(i,0,4){
			k+=vx[i]; l+=vy[i];
			if(k>=0 && k<a){
				if(l>=0 && l<b){
					if(v[k][l]==1)ok=true;
				}
			}
			k-=vx[i]; l-=vy[i];
		}
		if(!ok){
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;

	return 0;
}


#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()

typedef long long ll;
typedef pair<ll, ll> P;

const int mod =  1000000007;  //出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;   // INF = 11

int main()
{
    int n,k; cin >> n >> k;
    int a[n];
    rep(i,n) cin >> a[i];
    int tmp[n];

    for(int t = 0; t < k; t++){
        rep(i,n) tmp[i] = 0;
        rep(i,n){
            if(i - a[i] < 0){
                tmp[0]++;
            }else{
                tmp[i-a[i]]++;
            }
            if(i + 1 + a[i] < n){
                tmp[i+1+a[i]]--;
            }
        }
        a[0] = tmp[0];
        rep(i,n-1){
            a[i+1] = a[i] + tmp[i+1];
        }
        bool f = true;
        rep(i,n) if(a[i] != n) f = false;
        if(f) break;
    }
    rep(i,n) cout << a[i] << ' ';
}

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

void yes() { cout << "Yes" << endl; exit(0); }
void no() { cout << "No" << endl; exit(0); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> void amax(T &x, T y) { x = max(x, y); }
template <typename T> void amin(T &x, T y) { x = min(x, y); }
template <typename T> T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

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

void solve() {
  int n, k;
  cin >> n >> k;
  vi32 a(n);
  cin >> a;
  while (k--) {
    auto p = a;
    a.assign(n, 0);
    rep(i, n) {
      int l = max(0, i - p[i]);
      int r = min(n, i + p[i] + 1);
      a[l] += 1;
      if (r < n) a[r] -= 1;
    }
    rep(i, n - 1) a[i + 1] += a[i];
    if (a == p) {
      break;
    }
  }
  cout << a << endl;
}


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

int main(){
	string S;
	cin >> S;
	vector<bool> alpha(26);
	int N = S.size();
	string s = "abcdefghijklmnopqrstuvwxyz";
	rep(i,N){
		alpha[S[i] - 'a'] = true;
	}
	rep(i,26){
		if(alpha[i] == false){
			cout << s[i] << endl;
			return 0;
		}
	}
	 cout << "None" << endl;
	 return 0;
}


#include<cstring>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#define ll long long
using namespace std;//往左走w-1,往下走h-1
const ll mod=1000000007;
ll f[1000000];
ll quick(ll a,ll b)
{
//	cout<<"a"<<a<<"b"<<b<<endl;
	ll ans=1;
	while(b)
	{
		if(b&1)
		{
			ans=(ans*a)%mod;
		}
		b>>=1;
		a=(a*a)%mod;
	}
//	cout<<"("<<ans<<endl;
	return ans;
}
ll ni(ll a)
{
//	cout<<"ni"<<endl;
	return quick(a,mod-2);
}
ll c(int n,int m)
{
	ll a=f[n];
//	cout<<"a"<<f[n]<<endl;
	ll b=(f[m]*f[n-m])%mod;
//	cout<<"b"<<b<<endl;
	return (a*ni(b))%mod;
}
int main()
{
	int h,w,a,b;
	f[0]=1;
	for(int i=1;i<=200005;i++)
	{
		f[i]=(f[i-1]*i)%mod;
	}
	cin>>h>>w>>a>>b;
	ll ans=0;
	ll t;
	for(int i=b+1;i<=w;i++)
	{
	//	cout<<"-----"<<endl;
	//	cout<<"!"<<c(h-a-1+i-1,h-a-1)<<endl;
	//	cout<<"!"<<c(w-i+a-1,a-1)<<endl;
		t=(c(h-a-1+i-1,h-a-1)*c(w-i+a-1,a-1))%mod;
		ans=(ans+t)%mod;
	}
	cout<<ans<<endl;
}

#include<bits/stdc++.h>
#define reg register
#define F(i,j,k) for(reg int i=j;i<=k;++i)
#define dF(i,j,k) for(reg int i=j;i>=k;--i)
using namespace std;
typedef long long ll;
int n,k;
const int mod=998244353;
const int MN=2005;
int C[MN<<1][MN<<1],pw[MN<<1];
inline ll solve(int i,int n){
	reg int k2=min(k-i/2,(i-1)/2);reg int k1=k-(k2<<1)-((i&1)==0);
	reg ll res=0,pos=1;
	for(reg int j=k2;j+k1>0&&j>=0;j--,pos*=-1)
		res+=pos*C[j+k1+n-1][j+k1-1]*pw[j]%mod*C[k2][j]%mod,
		res%=mod;
	return (res+mod)%mod;
}
int main(){
	cin>>k>>n;C[0][0]=1;pw[0]=1;
	F(i,1,4000){
		C[i][0]=1;pw[i]=(pw[i-1]+pw[i-1])%mod;F(j,1,i)C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
	}
	reg ll ans=0;
	F(i,2,k<<1){
		if(~i&1)ans=(solve(i,n)+solve(i,n-1))%mod;
		else ans=solve(i,n);
		printf("%lld\n",ans);
	}
	return 0;
}


#include<iostream>
#include<vector>
#include<string.h>
#include<queue>
using namespace std;
const int N = 1e5 + 7;
string x[3] = { "RGB","GBR","BRG" };
int y[3][N];
int main() {
	int n, k;
	while (cin >> n >> k) {
		cout << n - k + 1 << '\n';
	}
	return 0;
}

#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
//ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    int n, k;
    cin >> n >> k;
    cout << n - k + 1 << endl;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
	int n;
	while(cin>>n,n)
	{
		int f[n+1][n+1];
		memset(f,0,sizeof(f));
		for(int i = 0; i < n; ++i)
		{
			for(int j = 0; j < n; ++j)
			{
				cin>>f[i][j];
				f[i][n]+=f[i][j];
				f[n][j]+=f[i][j];
				f[n][n]+=f[i][j];
			}
		}
		for(int i = 0; i <= n; ++i)
		{
			for(int j = 0; j <= n; ++j)
			{
				printf("%5d",f[i][j]);
			}
			cout<<endl;
		}
	}
  return 0;
}


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

struct StQuery
{
  StQuery() : m_nLeft(0), m_nRigt(0) { }

  int m_nLeft;
  int m_nRigt;
};

void input(string& rsStr, vector<StQuery>& rvoQuery)
{
  int nStrSiz, nQuerySiz;
  cin >> nStrSiz >> nQuerySiz;
  rvoQuery.resize(nQuerySiz);

  cin >> rsStr;

  for (StQuery& roQuery : rvoQuery)
    cin >> roQuery.m_nLeft >> roQuery.m_nRigt;
}

void calcSubStrACCnt(string sStr, const vector<StQuery>& cnrvoQuery)
{
  vector<int> vnCumlSum(sStr.size() + 1);      // 累積和

  //vnCumlSum_ix 0 1 2 3 4 5 6 7 8
  //sStr_pos      1 2 3 4 5 6 7 8
  //sStr          A C A C T A C G
  //sStr_ix       0 1 2 3 4 5 6 7
  for (int nBgn = 0; nBgn < vnCumlSum.size() - 1; nBgn++)
  {
    vnCumlSum[ nBgn + 2 ] = vnCumlSum[ nBgn + 1 ];
    if (sStr[nBgn] == 'A' && sStr[nBgn + 1] == 'C')
      vnCumlSum[ nBgn + 2 ]++;
  }

 for (int i = 0; i < cnrvoQuery.size(); i++)
  {
    cout << vnCumlSum[ cnrvoQuery[i].m_nRigt ] - vnCumlSum[ cnrvoQuery[i].m_nLeft ];
    cout << endl;
  }
}

int main()
{
  string sStr;
  vector<StQuery> voQuery;

  input(sStr, voQuery);
  calcSubStrACCnt(sStr, voQuery);

  return 0;
}

#include <bits/stdc++.h>
#include <iostream>
typedef long long ll;
#define rep(i,a,b) for(ll i =a ;i <= b;i++)
#define per(i,a,b) for(ll i =a ;i >= b;i--)
using namespace std;
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;

int main()
{
	//ifstream cin("input.txt");
	int n, q;
	string s;
	cin>>n>>q;
	cin>>s;

	vi cnt(n, 0);
	rep(i, 1, n- 1)
	{
		if(s[i-1] == 'A' && s[i] == 'C')
			cnt[i] = 1 + cnt[i-1];
		else
			cnt[i] = cnt[i-1];
	}

	rep(i, 1,q)
	{
		int l,r;
		cin>>l>>r;
		l--;
		r--;
		cout<<cnt[r] - cnt[l]<<"\n";
	}

}


#include<iostream>
#include<map>
#include<vector>
using namespace std;
const int mod=1e9+7;

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

int main(){
	int n;
	cin >> n;
	int a[n];
	for(int i=0;i<n;i++) cin >> a[i];
	int x[n];
	x[0]=a[0];
	for(int i=1;i<n;i++) x[i]=a[i]^x[i-1];
	map<int,vector<int>> m;
	for(int i=0;i<n;i++) if(x[i]) m[x[i]].push_back(i);

	long ans=0;
	if(x[n-1]==0){
		int znum[n];
		znum[0]=(x[0]==0);
		for(int i=1;i<n;i++) znum[i]=znum[i-1]+(x[i]==0);
		long res=0;
		for(auto p:m){
			vector<int> v=p.second;
			long z=1,o=0;
			int cur=0;
			for(int i:v){
				long zero=znum[i]-znum[cur];
				long zn=(o*zero+z)%mod;
				long on=(zn+o)%mod;
				z=zn;
				o=on;
				cur=i;
			}
			(res+=o)%=mod;
		}
		(res+=modpow(2,znum[n-1]-1))%=mod;
		ans=res;
	}else{
		int y=x[n-1];
		long z=1,o=0;
		for(int i=0;i<n;i++){
			if(x[i]==0) (z+=o)%=mod;
			else if(x[i]==y) (o+=z)%=mod;
		}
		ans=z;
	}
	cout << ans << endl;
	return 0;
}

#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

main() {
    int64_t n;
    cin >> n;

    int64_t x = 0;
    vector<int64_t> xx(n);
    for (auto i : irange(0L, n)) {
        int64_t aa;
        cin >> aa;

        x ^= aa;
        xx[i] = x;
    }

    constexpr auto M = 1000000007;

    auto last_x = xx.back();
    cerr << last_x << endl;
    if (last_x > 0) {
        int64_t count = 0;
        int64_t count0 = 0;
        for (auto x : xx) {
            if (x == 0) {
                count0 += count;
                count0 %= M;
            } else if (x == last_x) {
                count += count0 + 1;
                count %= M;
            }
        }
        cout << count0 + 1 << endl;
    } else {
        unordered_map<int64_t, int64_t> count0;
        unordered_map<int64_t, int64_t> count;
        unordered_map<int64_t, int64_t> last_num0;
        int64_t num0 = 0;
        for (auto i : irange(0L, n)) {
            auto x = xx[i];
            if (x == 0) {
                ++num0;
            } else {
                count0[x] += (count[x] * ((num0 - last_num0[x]) % M)) % M;
                count[x] += count0[x] + 1;
                count[x] %= M;
                last_num0[x] = num0;
            }
        }

        int64_t ans = 0;
        for (auto kv : count) {
            ans += kv.second;
            ans %= M;
        }

        int64_t p0 = 1;
        for (auto i : irange(0L, num0 - 1)) {
            p0 *= 2;
            p0 %= M;
        }

        cerr << ans << endl;
        cerr << p0 << endl;
        cout << (ans + p0) % M << endl;
    }
}