#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <stack>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef unsigned long long int ll;

int main()
{
	ll N,T;
	cin>>N>>T;
	ll sum = T * N;
	ll *t = new ll[N];
	cin>>t[0];
	for(int i = 1; i < N; i++){
		cin>>t[i];
		if( T > (t[i] - t[i-1])){
			ll deltaT = t[i] - t[i-1];
			sum -= (T - deltaT);
		}
	}
	cout<<sum<<endl;
	return 0;
}

#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

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

const int inf = INT_MAX;
const int MOD = 1000000007;
const long long INF = LLONG_MAX;

// -------------------------------------------------------

ll N, T;
vector<Pll> ev;

int main() {
  cin >> N >> T;
  rep(i, 0, N) {
    ll t;
    cin >> t;
    ev.push_back(Pll(t, 1));
    ev.push_back(Pll(t + T, 0));
  }

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

  ll st = 0;
  ll end = T;
  ll ans = 0;
  for (auto e : ev) {
    if (e.second == 1) {
      if (e.first <= end) {
        end = e.first + T;
      } else {
        ans += end - st;
        st = e.first;
        end = e.first + T;
      }
    } else {
      if (e.first <= end) {
        continue;
      } else {
        ans += end - st;
        st = -1;
        end = -1;
      }
    }
  }

  ans += end - st;

  cout << ans;
}


#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <math.h>
#include <set>
#include <deque>
#include <queue>
using namespace std;
typedef long long ll;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int a, b;
    string s;
    cin >> a >> b >> s;
    for (int i = 0 ; i < a ; i++) {
    	if (s[i] < '0' || s[i] > '9') {
    		cout << "No";
    		return 0;
		}
	}
	if (s[a] != '-') {
		cout << "No";
		return 0;
	}
	for (int i = a + 1 ; i < s.length() ; i++) {
		if (s[i] < '0' || s[i] > '9') {
    		cout << "No";
    		return 0;
		}
	}
	cout << "Yes";
}

#include <stdio.h>

int main () {
	int a, b;
	scanf("%d %d", &a, &b);
	int flag = 0;
	char str [a+b+1];
	scanf("%s", str);
	int atr = 0;

	for ( int i = 0 ; i < a+b+1 ; i++) {
		if (str[i] == '-' && i == a ) {
			flag = 1;
		}
		if (str[i] >= '0' && str[i] <= '9') {
			++atr;
		}
	}
	int total = a+b;
	if (flag == 1 && atr == total) {
		printf("Yes\n");
	} else {
		printf("No\n");
	}
	return 0;
}


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

#define ll long long

const int bzmax = 60;

typedef class LinearBasis {
  public:
    ll a[bzmax];

    void insert(ll x) {
      for (int i = bzmax; i-- && x; ) {
        if ((x >> i) & 1) {
          x ^= a[i];
        }
        if ((x >> i) & 1) {
          a[i] = x;
          break;
        }
      }
    }
    bool query(ll x) {
      for (int i = bzmax; i-- && x; ) {
        if ((x >> i) & 1) {
          x ^= a[i];
        }
      }
      return !x;
    }

    void reset() {
      memset(a, 0, sizeof(a));
    }
} LinearBasis;

const int N = 205;

int T, n;
ll a[N];
char s[N];
LinearBasis lb;

void solve() {
  lb.reset();
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", a + i);
  }
  scanf("%s", s + 1);
  for (int i = n; i; i--) {
    if (s[i] == '1') {
      if (!lb.query(a[i])) {
        puts("1");
        return;
      }
    } else {
      lb.insert(a[i]);
    }
  }
  puts("0");
}

int main() {
  scanf("%d", &T);
  while (T--) {
    solve();
  }
  return 0;
}

#include<bits/stdc++.h>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define rrep(i,a) for(int i=(int)a-1;i>=0;--i)
#define REP(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RREP(i,a,b) for(int i=(int)a-1;i>=b;--i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
typedef std::vector<int> vi;
typedef std::vector<std::vector<int>> vvi;
typedef std::vector<long long> vl;
typedef std::vector<std::vector<long long>> vvl;
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

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

ll gcd(ll n, ll m) {
    ll tmp;
    while (m!=0) {
        tmp = n % m;
        n = m;
        m = tmp;
    }
    return n;
}

ll lcm(ll n, ll m) {
    return abs(n) / gcd(n, m)*abs(m);//gl=xy
}

using namespace std;

ll dp[200005][3];
void solve()
{
	int n;
	cin >> n;
	vector<ll> a(n);
	rep(i, n) cin >> a[i];
	rep(i,200005){
		rep(j,3)dp[i][j] = -INF;
	}
	rep(i,3)dp[0][i] = 0;
	if(n%2==1){
		rep(i, n/2)
		{
			int id = 2 * i;
			rep(j,3)
			{
				if(j==0){
					chmax(dp[i + 1][0], dp[i][0] + a[id]);
					chmax(dp[i + 1][1], dp[i][0] + a[id+1]);
					chmax(dp[i + 1][2], dp[i][0] + a[id + 2]);
				}
				else if(j==1){
					chmax(dp[i + 1][1], dp[i][1] + a[id+1]);
					chmax(dp[i + 1][2], dp[i][1] + a[id + 2]);
				}
				else{
					chmax(dp[i + 1][2], dp[i][2] + a[id + 2]);
				}
			}
		}
		ll ans = -INF;
		rep(i,3){
			chmax(ans, dp[n / 2][i]);
		}
		cout << ans;
	}
	else{
		rep(i,n/2){
			int id = i * 2;
			rep(j,2){
				if(j==0){
					chmax(dp[i + 1][0], dp[i][0] + a[id]);
					chmax(dp[i + 1][1], dp[i][0] + a[id + 1]);
				}
				else{
					chmax(dp[i + 1][1], dp[i][1] + a[id + 1]);
				}
			}
		}
		ll ans = -INF;
		rep(i,2){
			chmax(ans, dp[n / 2][i]);
		}
		cout << ans;
	}
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(15);
    solve();
    return 0;
}


#include <bits/stdc++.h>

#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define irrep(i,n) for(int i = (int)(n-1); i > -1; i--)
#define irrep2(i,n,a) for(int i = (int)(n); i >= (int)(a); i--)

#define fi first
#define se second

using namespace std;

using ll = long long;
using v_int = vector<int>;
using v2_int = vector<v_int>;
using v_ll = vector<ll>;
using v2_ll = vector<v_ll>;
using v_string = vector<string>;
using v_bool = vector<bool>;
using v2_bool = vector<v_bool>;
using pii = pair<int, int>;
using mii = map<int, int>;

const double PI = 3.1415926535897932;
const int INF = (int)2e9;
const ll LINF = (ll)2e18;
const ll MOD = 1000000007;
const int dc[8] = {1, -1, 0,  0, 1, -1,  1, -1};
const int dr[8] = {0,  0, 1, -1, 1,  1, -1, -1};

template<typename T, typename U> inline
ostream& operator<<(ostream &o, pair<T,U> &p) {
    return o << "{" << p.first << "," << p.second << "}";
}
template<typename T> inline
istream& operator>>(istream &is, vector<T> &vec) {
    for(auto &v : vec) { is >> v; }
    return is;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<T> &vec) {
    for(auto &v : vec) { os << v << ",";}
    return os;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<vector<T> > &mat) {
    for(auto &row : mat) { os << row << endl; }
    return os;
}
template<typename T> inline
void chmin(T &a, T b) { a = min(a, b); }
template<typename T> inline
void chmax(T &a, T b) { a = max(a, b); }

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

    v_int input(n+5, 0);

    irep(i, m) {
        int l, r;
        cin >> l >> r;
        input[l] += 1;
        input[r+1] -= 1;
    }

    v_int card(n+5, 0);
    irep2(i, 1, n) {
        card[i] = card[i-1] + input[i];
    }

    int ans = 0;
    irep2(i, 1, n) {
        if(card[i] == m) {
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
} /*atcoder*/

#include <iostream>
#include <cstdio>
#include <cstring>
#define ll long long
#define ls(_o) (_o << 1)
#define rs(_o) ((_o << 1) | 1)
#define abs(_o) ((_o < 0) ? -(_o) : _o)
using namespace std;
namespace ywy {
    inline int get() {
        int n = 0;
        char c;
        while ((c = getchar()) || 23333) {
            if (c >= '0' && c <= '9')
                break;
            if (c == '-')
                goto s;
        }
        n = c - '0';
        while ((c = getchar()) || 23333) {
            if (c >= '0' && c <= '9')
                n = n * 10 + c - '0';
            else
                return (n);
        }
    s:
        while ((c = getchar()) || 23333) {
            if (c >= '0' && c <= '9')
                n = n * 10 - c + '0';
            else
                return (n);
        }
    }
    ll min1[1000001], min2[1000001], adds[1000001];
    int x[200001];
    inline void down(int tree) {
        if (!adds[tree])
            return;
        ll c = adds[tree];
        adds[tree] = 0;
        adds[ls(tree)] += c;
        adds[rs(tree)] += c;
        min1[ls(tree)] += c;
        min2[ls(tree)] += c;
        min1[rs(tree)] += c;
        min2[rs(tree)] += c;
    }
    inline void up(int tree) {
        min1[tree] = min(min1[ls(tree)], min1[rs(tree)]);
        min2[tree] = min(min2[ls(tree)], min2[rs(tree)]);
    }
    void setpt(int l, int r, int tree, int pt, ll num) {
        if (l == r) {
            min1[tree] = min(min1[tree], num - l);
            min2[tree] = min(min2[tree], num + l);
            return;
        }
        int mid = (l + r) >> 1;
        down(tree);
        if (pt <= mid)
            setpt(l, mid, ls(tree), pt, num);
        else
            setpt(mid + 1, r, rs(tree), pt, num);
        up(tree);
    }
    ll query1(int rl, int rr, int l, int r, int tree) {
        if (rl == l && rr == r)
            return (min1[tree]);
        int mid = (l + r) >> 1;
        down(tree);
        if (rl > mid)
            return (query1(rl, rr, mid + 1, r, rs(tree)));
        if (rr <= mid)
            return (query1(rl, rr, l, mid, ls(tree)));
        return (min(query1(rl, mid, l, mid, ls(tree)), query1(mid + 1, rr, mid + 1, r, rs(tree))));
    }
    ll query2(int rl, int rr, int l, int r, int tree) {
        if (rl == l && rr == r)
            return (min2[tree]);
        int mid = (l + r) >> 1;
        down(tree);
        if (rl > mid)
            return (query2(rl, rr, mid + 1, r, rs(tree)));
        if (rr <= mid)
            return (query2(rl, rr, l, mid, ls(tree)));
        return (min(query2(rl, mid, l, mid, ls(tree)), query2(mid + 1, rr, mid + 1, r, rs(tree))));
    }
    ll query(int l, int r, int tree) {
        if (l == r)
            return (min1[tree] + l);
        int mid = (l + r) >> 1;
        down(tree);
        return (min(query(l, mid, ls(tree)), query(mid + 1, r, rs(tree))));
    }
    void ywymain() {
        int n = get(), q = get(), a = get(), b = get();
        x[0] = a;
        memset(min1, 0x3f, sizeof(min1));
        memset(min2, 0x3f, sizeof(min2));
        setpt(1, n, 1, b, 0);
        for (register int i = 1; i <= q; i++) {
            x[i] = get();
            ll cjr = min(query1(1, x[i], 1, n, 1) + x[i], query2(x[i], n, 1, n, 1) - x[i]);
            adds[1] += abs(x[i] - x[i - 1]);
            min1[1] += abs(x[i] - x[i - 1]);
            min2[1] += abs(x[i] - x[i - 1]);
            setpt(1, n, 1, x[i - 1], cjr);
        }
        cout << query(1, n, 1) << endl;
    }
}
int main() {
    ywy::ywymain();
    return (0);
}


#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>

using namespace std;

int main() {
  int n,m;
  string s[200],t[200];
  cin >> n;
  for(int i = 0; i < n; i++)
    cin >> s[i];
  cin >> m;
  for(int i = 0; i < m; i++)
    cin >> t[i];

  int sum = 0;
  for(int i = 0; i < n; i++) {
    int cnt = 1;
    for(int j = i+1; j < n; j++)
      if(s[i] == s[j]) cnt++;
    for(int j = 0; j < m; j++)
      if(s[i] == t[j]) cnt--;
    sum = max(sum, cnt);
  }

  cout << sum << endl;
}

#include <iostream>
#include <algorithm>
#include <map>
#include <string>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
#include <random>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <complex>
#include <functional>
using namespace std;
#define rep(i,a,b) for(int i = (a); i < int(b); ++i)
#define rrep(i,a,b) for(int i = (b); i --> int(a);)
#define all(v) v.begin(),v.end()
#define trav(x, v) for(auto &x : v)
#define sz(v) int((v).size())
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long double ld;

void fail(){
	puts("No");
	exit(0);
}

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

	int n;
	cin >> n;
	vector<vi> a(3, vi(n));
	trav(v, a) trav(x, v) cin >> x;
	vi perm(n);
	bool sign[2] = {};
	rep(i,0,n){
		int ix = (a[0][i]-1)/3;
		if(a[1][i] != 3*ix+2) fail();
		if(min(a[0][i], a[2][i]) != 3*ix+1
			|| max(a[0][i],a[2][i]) != 3*ix+3) fail();
		sign[i&1] ^= a[0][i] > a[2][i];
		perm[i] = ix;
		if((i+ix)&1) fail();
	}
	int numofcycles[2] = {};
	vector<bool> vis(n);
	rep(i,0,n) if(!vis[i]){
		++numofcycles[i&1];
		int j = i;
		do {
			vis[j] = 1;
			j = perm[j];
		} while(j != i);
	}
	int nn[2] = {n/2+(n&1), n/2};
	if(sign[0] != (nn[1]+numofcycles[1])%2
		|| sign[1] != (nn[0]+numofcycles[0])%2)
		fail();
	puts("Yes");
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int e;
    cin >>e;

    while(e)
    {
        int x=0;
        int y=0;
        int z=0;
        int m=0;
     for(z=0;z*z*z<=e;z++)
        for(y=0;z*z*z+y*y<=e;y++)
        {
            x = e-z*z*z-y*y;
            if(x<0)
                continue;

                int t = x+y+z;
                if(m ==0||m>t)
                    m=t;
            }

        cout <<m<<endl;

        cin >>e;
    }
    return 0;
}

#include <bits/stdc++.h>

template <typename T> inline void rd(T& x) {
	int si = 1; char c = getchar(); x = 0;
	while(!isdigit(c)) si = c == '-' ? -1 : si, c = getchar();
	while(isdigit(c)) x = x * 10 + c - 48, c = getchar();
	x *= si;
}
template <typename T, typename... Args>
inline void rd(T& x, Args&... args) { rd(x); rd(args...); }

#define fi first
#define se second

typedef long long ll;
typedef double ff;
typedef std::pair<int, int> pii;

const int kN = 1e5 + 5;

int a[kN], n;
int Gcd(int x, int y) { return y ? Gcd(y, x % y) : x; }
void Div() {
	int g = a[1];
	for(int i = 2; i <= n; ++i) g = Gcd(g, a[i]);
	for(int i = 1; i <= n; ++i) a[i] /= g;
}

int main() {
	int cur = 0; rd(n);
	for(int i = 1; i <= n; ++i) rd(a[i]);
	while(true) {
		int cnt = 0, ecnt = 0, p; bool flag = false;
		for(int i = 1; i <= n; ++i) {
			if(a[i] % 2 == 0) ++cnt;
			else p = i, ++ecnt;
			if(a[i] == 1) flag = true;
		}
		if(flag) return printf((cnt % 2 == 1) ^ cur ? "First" : "Second"), 0;
		if(cnt % 2 == 1) return printf(cur ? "Second" : "First"), 0;
		if(ecnt > 1 && cnt % 2 == 0) return printf(cur ? "First" : "Second"), 0;
		--a[p]; Div(); cur ^= 1;
	}
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

const int maxN = 1000009;
int N, X, b[maxN], p[maxN], l[maxN], r[maxN];
/*int lg, N, X, aib[2 * maxN], val[2 * maxN];
long long aibSum[2 * maxN], ans = 1LL << 60;
pair < int, int > h[2 * maxN];
pair < int, pair < int, int > > v[maxN];

set < int > S;
void able (int pos, int x)
{
    ///val = +-1 (aka enable or disable)
    if (x < 0) S.erase (pos);
    else S.insert (pos);
    int y = val[pos] * x;
    while (pos <= 2 * N)
        aibSum[pos] += y,
        aib[pos] += x,
        pos += pos - (pos & (pos - 1));
}

void attempt (long long need)
{
    ///max aibSum * X < need
    int pos = 0, used = 0;
    for (int i=lg; i>=0; i--)
        if (pos + (1 << i) <= 2 * N && 1LL * X * aibSum[pos + (1 << i)] < need)
            pos |= 1 << i, need -= 1LL * X * aibSum[pos], used += aib[pos];
    for (auto it : S)
        printf ("%d ", it);
    printf ("? >= %d\n", pos);
    auto it = S.lower_bound (pos + 1);
    assert (it != S.end ());
    int leftover = (need + val[*it] - 1) / val[*it];
    long long curr = 1LL * X * used + leftover;
    if (curr < ans)
        ans = curr;
}*/

long long f (int i)
{
    return 1LL * (X - b[i]) * r[i] + 1LL * b[i] * l[i];
}

bool cmp (int i, int j)
{
    return f (i) > f (j);
}

bool ok (long long moves)
{
    int cnt = moves / X, smth = moves % X;
    long long toOvercome = 0;
    for (int i=1; i<=N; i++)
        toOvercome += 1LL * l[i] * b[i];
    long long firstCntSum = 0;
    for (int i=1; i<=cnt; i++)
        firstCntSum += f(p[i]);
    for (int i=1; i<=N; i++)
    {
        ///assume i is smth
        long long curr = toOvercome;
        int pos = p[i];
        if (b[pos] >= smth) curr -= 1LL * smth * l[pos];///unimportant
        else curr += 1LL * b[pos] * (r[pos] - l[pos]), curr -= (1LL * smth * r[pos]);
        curr -= firstCntSum;
        if (i <= cnt)
            curr -= f (p[cnt + 1]) - f (pos); ///this should've been in firstCntSum
        if (curr <= 0)
            return 1;
    }
    return 0;
}

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d %d", &N, &X);
/*for (int i=1; i<=N; i++)
    scanf ("%d %d %d", &v[i].first, &v[i].second.first, &v[i].second.second);
sort (v + 1, v + N + 1, cmp);
for (int i=1; i<=N; i++)
    h[2 * i - 1] = {-v[i].second.first, i},
    h[2 * i] = {-v[i].second.second, -i};
sort (h + 1, h + 2 * N + 1);
for (int i=1; i<=2 * N; i++)
{
    val[i] = -h[i].first;
    if (h[i].second > 0) v[h[i].second].second.first = i;
    else v[-h[i].second].second.second = i;
}
lg = 0;
while ((2 << lg) <= 2 * N)
    lg ++;
long long opponentValue = 0;
for (int i=1; i<=N; i++)
    opponentValue += 1LL * v[i].first * val[v[i].second.first],
    able (v[i].second.first, +1); ///all unimportant
attempt (opponentValue);
for (int i=1; i<=N; i++)
    opponentValue += 1LL * v[i].first * (val[v[i].second.second] - val[v[i].second.first]),
    able (v[i].second.first, -1),
    able (v[i].second.second, +1),
    attempt (opponentValue);
printf ("%lld\n", ans);*/
for (int i=1; i<=N; i++)
    scanf ("%d %d %d", &b[i], &l[i], &r[i]), p[i] = i;
sort (p + 1, p + N + 1, cmp);
{
    long long p = 0, u = 1LL * N * X - 1, mid, ras = 1LL * N * X;
    while (p <= u)
    {
        mid = (p + u) >> 1;
        if (ok (mid))
            ras = mid, u = mid - 1;
        else p = mid + 1;
    }
    printf ("%lld\n", ras);
}
return 0;
}

#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

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;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

typedef complex<double> Point, Vector;
typedef pair<Point, Point> Segment, Line;
typedef vector<Point> Polygon;
typedef pair<Point, double> Circle;

#define X real()
#define Y imag()
#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)

namespace std{
    bool operator<(const Point &a, const Point &b){
        return !equals(a.X, b.X) ? a.X < b.X : a.Y < b.Y;
    }

    bool cmp_y(const Point &a, const Point &b) {
        return !equals(a.Y, b.Y) ? a.Y < b.Y : a.X < b.X;
    }
}

double dot(Vector a, Vector b){
    return a.X * b.X + a.Y * b.Y;
}

double cross(Vector a, Vector b){
    return a.X * b.Y - a.Y * b.X;
}

double norm(Vector a){
    return a.X * a.X + a.Y * a.Y;
}

double abs(Vector a){
    return sqrt(norm(a));
}

static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;

int ccw(Point p0, Point p1, Point p2){
    Vector a = p1 - p0;
    Vector b = p2 - p0;
    if(cross(a, b) > EPS) return COUNTER_CLOCKWISE;
    if(cross(a, b) < -EPS) return CLOCKWISE;
    if(dot(a, b) < -EPS) return ONLINE_BACK;
    if(norm(a) < norm(b)) return ONLINE_FRONT;

    return ON_SEGMENT;
}

Polygon convexHull(Polygon ps){
    int n = ps.size();
    sort(ps.begin(), ps.end(), cmp_y);
    int k = 0;
    Polygon convex(n * 2);
    for(int i=0; i<n; i++){
        while(k >= 2 && ccw(convex[k-2], convex[k-1], ps[i]) == CLOCKWISE) k--;
        convex[k++] = ps[i];
    }
    for(int i=n-2, t=k; i>=0; i--){
        while(k > t && ccw(convex[k-2], convex[k-1], ps[i]) == CLOCKWISE) k--;
        convex[k++] = ps[i];
    }
    convex.resize(k-1);
    return convex;
}

double arg(Vector p){
    return atan2(p.Y, p.X);
}

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

    int n; cin>>n;
    Polygon pol;
    vector<double> x(n), y(n);
    for(int i=0; i<n; i++){
        cin>>x[i]>>y[i];
        pol.emplace_back(x[i], y[i]);
    }

    pol = convexHull(pol);

    int m = pol.size();

    map<pair<double, double>, double> ans;
    for(int i=0; i<m; i++){
        Vector A = pol[(i+1)%m] - pol[i];
        Vector B = pol[(i-1+m)%m] - pol[i];
        Vector C = pol[(i+1)%m] - pol[(i-1+m)%m];

        double cos_i = (abs(A) * abs(A) + abs(B) * abs(B) - abs(C) * abs(C)) / (2 * abs(A) * abs(B));
        double theta = acos(cos_i);
        theta = pi - theta;
        double alpha = theta / 2 / pi;
        ans[make_pair(pol[i].X, pol[i].Y)] = alpha;
    }

    for(int i=0; i<n; i++){
        printf("%.8f\n", ans[make_pair(x[i], y[i])]);
    }
}


#include <bits/stdc++.h>
#include <math.h>

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
using Graph = vector<vector<int>>;
const int MOD = 1000000007;
const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val)
{
    std::fill((T*)array, (T*)(array + N), val);
}

// dp[c1][c2][c3]: (1個の皿がc1枚，2個の皿がc2枚，3個の皿がc3枚の状態ですべて食べるまでの操作回数の期待値)
double dp[305][305][305];
int N;

double rec(int c1, int c2, int c3)
{
    if (dp[c1][c2][c3] != -1.0)
        return dp[c1][c2][c3];

    double ret = N;
    if (c1 >= 1) {
        ret += c1 * rec(c1 - 1, c2, c3);
    }
    if (c2 >= 1) {
        ret += c2 * rec(c1 + 1, c2 - 1, c3);
    }
    if (c3 >= 1) {
        ret += c3 * rec(c1, c2 + 1, c3 - 1);
    }
    ret /= (c1 + c2 + c3);

    return dp[c1][c2][c3] = ret;
}
int main()
{
    cin >> N;
    Fill(dp, -1.0);
    dp[0][0][0] = 0;
    int c1, c2, c3;
    c1 = c2 = c3 = 0;
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        if (a == 1)
            c1++;
        if (a == 2)
            c2++;
        if (a == 3)
            c3++;
    }

    cout << fixed << setprecision(9);
    cout << rec(c1, c2, c3) << endl;

    return 0;
}

#include "bits/stdc++.h"
#define ll long long
#define mp(a, b) make_pair(a, b)
using namespace std;
typedef pair<ll, ll> pairs;
typedef pair<ll, pairs> tpl;
ll c[4];
double dp[301][301][301];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n, a;
    cin >> n;
    for (ll i = 0; i < n; i++)
        cin >> a, c[a]++;
    dp[0][0][0] = 0;
    for (ll i = 0; i <= n; i++)
    {
        for (ll j = 0; j <= n; j++)
        {
            for (ll k = 0; k <= n; k++)
            {
                double z = n - (i + j + k), val = 1;
                if (z == n)
                    continue;
                if (i + j + k > n)
                    continue;
                if (i > 0)
                    val += (1.0 * i / n) * dp[i - 1][j + 1][k];
                if (j > 0)
                    val += (1.0 * j / n) * dp[i][j - 1][k + 1];
                if (k > 0)
                    val += (1.0 * k / n) * dp[i][j][k - 1];
                if (z > 0)
                    val /= (1.0 - 1.0 * z / n);
                dp[i][j][k] = val;
            }
        }
    }

    cout << setprecision(9) << fixed << dp[c[3]][c[2]][c[1]];
}


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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<int> AB(2);
    for (int i=0;i<2;++i) cin >> AB[i];
    int K; cin >> K;
    for (int i=0;i<K;++i){
        if (AB[i&1]&1) --AB[i&1];
        AB[(i&1)^1]+=AB[i&1]/2;
        AB[i&1]/=2;
    }
    cout << AB[0] << ' ' << AB[1] << '\n';
}

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

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

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


#include<bits/stdc++.h>
typedef long long ll;
typedef std::pair<ll,ll> P;

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

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

constexpr ll mod = 1e9 + 7;

struct UnionFind {
public:
	vector <ll> par; //
	vector <ll> siz; //

	UnionFind() {}

	UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
		for (ll i = 0; i < sz_; ++i) par[i] = i;
	}
	void init(ll sz_) {
		par.resize(sz_);
		siz.assign(sz_, 1LL);
		for (ll i = 0; i < sz_; ++i) par[i] = i;
	}

	ll root(ll x) {
		while (par[x] != x) {
			x = par[x] = par[par[x]];
		}
		return x;
	}

	bool merge(ll x, ll y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;
		if (siz[x] < siz[y]) swap(x, y);
		siz[x] += siz[y];
		par[y] = x;
		return true;
	}

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

	ll size(ll x) {
		return siz[root(x)];
	}
};

int main() {
	ll n;
	cin >> n;
	vector<int> ans;
	for (int i = 0; i < 60; i++) {
		ll m = n % (1LL << (i+1));
		if (m) {
			ans.push_back(1);
			ll sub = 1LL << i;
			if (i % 2 == 1) {
				sub *= -1;
			}
			n -= sub;
		}
		else ans.push_back(0);
		if (n == 0) break;
	}
	reverse(ans.begin(), ans.end());
	for (auto a : ans) {
		cout << a;
	}
	cout << endl;
	return 0;
}

//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INTINF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007

int main() {
	ll ans = 0;
	ll tmp = 0;
	ll n;
	cin >> n;
	string s = "";
	if(n==0) cout << 0 << endl;
	else {
		while(tmp != n){
			//cout << s.size() << " " << tmp << " " << s << endl;
			if(abs(n-tmp)%((ll)1<<(s.size()+1))==0) s = "0" + s;
			else {
				tmp += (ll)pow(-1, s.size()) * ((ll)1<<s.size());
				s = "1" + s;
			}
		}
		cout << s << endl;
	}
}


#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
using namespace std;

typedef long long ll;
typedef double db;
typedef long double ldb;

template<class T> inline void checkmin(T &a,const T &b){if(b<a) a=b;}
template<class T> inline void checkmax(T &a,const T &b){if(b>a) a=b;}

const int inf=1e9+10;
const int maxn=2e5+10;

const ll base=1e9+7;
const ll mod=2038077799;

ll ha,hb,a[maxn],b[maxn],difa[maxn],difb[maxn];
int n;

ll getval(ll x,ll k,ll mod){
	if(k==0) return 1ll;
	if(k==1) return x;
	ll res=getval(x,k/2,mod);
	res=(res*res)%mod;
	if(k&1) res=(res*x)%mod;
	return res;
}

int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++) scanf("%lld",&a[i]);
	for(int i=0;i<n;i++) scanf("%lld",&b[i]);
	for(int i=0;i<n;i++) difa[i]=a[i]^a[(i+1)%n];
	for(int i=0;i<n;i++) difb[i]=b[i]^b[(i+1)%n];
	ha=hb=0;
	for(int i=0;i<n;i++){
		ha*=base; ha%=mod;
		ha+=difa[i]; ha%=mod;
	}
	for(int i=0;i<n;i++){
		hb*=base; hb%=mod;
		hb+=difb[i]; hb%=mod;
	}
	ll val=getval(base,n-1,mod);
	vector <int> ans;
	for(int i=0;i<n;i++){
		if(ha==hb){
			ans.pb(i);
		}
		ll now=val*difa[i]; now%=mod;
		ha+=mod-now; ha%=mod;
		ha*=base; ha%=mod;
		ha+=difa[i]; ha%=mod;
	}
	for(int i=0;i<ans.size();i++){
		cout<<ans[i]<<" "<<(a[0]^b[(n-ans[i])%n])<<endl;
	}
	return 0;
}

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

struct Stat {
    int unmatchedOpening, unmatchedClosing, index;
    Stat(int _uo, int _uc, int _index): unmatchedOpening(_uo), unmatchedClosing(_uc), index(_index) {}
};

//Comparing two stats which unmatchedOpening - unmatchedClosing >= 0
bool cmpFirst(Stat a, Stat b) {
    return a.unmatchedClosing < b.unmatchedClosing;
}

//Comparing two stats which unmatchedOpening - unmatchedClosing < 0
bool cmpSecond(Stat a, Stat b) {
    return a.unmatchedOpening > b.unmatchedOpening;
}

//{unmatchedOpening, unmatchedClosing}
pair<int, int> getStat(string s) {
    int unmatchedOpening = 0;
    int unmatchedClosing = 0;

    for (int i = 0; i < s.length(); i++) {
        if (s[i] == '(') {
            unmatchedOpening += 1;
        } else {
            if (unmatchedOpening > 0)
                unmatchedOpening -= 1;
            else
                unmatchedClosing += 1;
        }
    }

    return make_pair(unmatchedOpening, unmatchedClosing);
}

int main() {
    int n;
    vector<Stat> first; //unmatchedOpening - unmatchedClosing >= 0
    vector<Stat> second; //unmatchedOpening - unmatchedClosing < 0

    cin >> n;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;

        auto stat = getStat(s);
        if (stat.first - stat.second >= 0)
            first.push_back(Stat(stat.first, stat.second, i));
        else
            second.push_back(Stat(stat.first, stat.second, i));
    }

    sort(first.begin(), first.end(), cmpFirst);
    sort(second.begin(), second.end(), cmpSecond);

    bool valid = true;
    int balance = 0;

    for (auto f: first) {
        if (balance - f.unmatchedClosing < 0) {
            valid = false;
            break;
        }

        balance -= f.unmatchedClosing;
        balance += f.unmatchedOpening;
    }

    for (auto s: second) {
        if (balance - s.unmatchedClosing < 0) {
            valid = false;
            break;
        }

        balance -= s.unmatchedClosing;
        balance += s.unmatchedOpening;
    }

    if (balance != 0)
        valid = false;

    if (valid) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
}

/*
Test cases:

4
(
))(((
)((
)))
*/


#include<iostream>
#include<algorithm>
using namespace std;
int a[105];

int bubble_sort(int a[], int n)
{
	bool flag = true;
	int cnt = 0;
	for(int i = n-1; i >= 0; i--)
	{
		flag = true;
		for(int j = 0; j < i; j++)
		{
			if(a[j+1] < a[j])
			{
				swap(a[j+1], a[j]);
				cnt++;
				flag = false;
			}
		}
		if(flag)
		{
			for(int i = 0; i < n; i++)
			{
				if(i)
					cout << " ";
				cout << a[i];
			}
			cout << endl;
			return cnt;
		}
	}
}

int main ()
{
	int n;
	cin >> n;
	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	cout << bubble_sort(a, n) << endl;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define all(x) x.begin(), x.end()
#define watch(x) cout<<#x<<" : "<<x<<endl
#define tr(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define testCases int tt;cin>>tt; while(tt--)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<pair<int, int>> vpii;
typedef vector<string> vs;

int main() {
    fastio;
    int n;
    cin >> n;
    set<int> s;
    for (int i = 0; i < n; i++) {
        int temp;
        cin >> temp;
        s.insert(temp);
    }
    if (s.size() == n) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}


#include <iostream>
using namespace std;
int main()
{
 double U = 3.14;
 int R;
cin >> R  >> U;
 cout <<  R * 2 * U <<"\n";
}


#include <bits/stdc++.h>
using namespace std;
#define REP(i,N) for(i=0;i<N;i++)
typedef long long ll;
typedef pair<int, int> P;
typedef struct{
  int first;
  int second;
  int third;
}T;

//昇順
bool comp_Se(T& l, T& r){
  return l.second < r.second;
}

ll mod =  1e9+7;
int main(void){
  int i,j,N,X;
  cin >> N >> X;
  vector<ll> v(N);
  REP(i,N) cin >> v[i];
  sort(v.begin(),v.end());

  //dp[i][j]:jをXの最初として，i+1回操作(ただしi+1番目まで)を行った時の総和
  ll dp[N][X+1];
  REP(j,X+1){
    dp[0][j] = j%v[0];
  }
  for(i=1;i<N;i++){
    REP(j,X+1){
      //dp[i-1][j%v[i]]:最初に行う場合
      //dp[i-1][j]*i 最初に行わない場合
      dp[i][j] = dp[i-1][j%v[i]] + dp[i-1][j] * i;
      dp[i][j] %= mod;
    }
  }
  cout << dp[N-1][X] << endl;
  return 0;
}

#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <list>
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;

#define PB push_back
#define MP make_pair
#define SZ(v) ((int)(v).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n) FORE(i,0,n)
#define FORSZ(i,a,v) FOR(i,a,SZ(v))
#define REPSZ(i,v) REP(i,SZ(v))
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a%b); }

const int MAXN=200;
const int MAXX=100000;
const int MOD=1000000007;
void inc(int &a,int b) { if((a+=b)>=MOD) a-=MOD; }

int n,sx;
int a[MAXN];

int ways[MAXN+1][MAXX+1];

int solve() {
	sort(a,a+n); reverse(a,a+n);
	memset(ways,0,sizeof(ways)); ways[0][sx]=1;
	REP(i,n) REPE(x,sx) if(ways[i][x]!=0) {
		inc(ways[i+1][x],(ll)(n-i-1)*ways[i][x]%MOD);
		inc(ways[i+1][x%a[i]],ways[i][x]);
	}
	int ret=0; REPE(x,sx) inc(ret,(ll)x*ways[n][x]%MOD); return ret;
}

void run() {
	scanf("%d%d",&n,&sx);
	REP(i,n) scanf("%d",&a[i]);
	printf("%d\n",solve());
}

int main() {
	run();
	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>;
const int INF = 1e9;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};
#define PI 3.14159265358979323846264338327950L
#define MOD 1000000007
//setprecision(15)

int main() {
	int A, B; cin >> A >> B;
	if (B == 1) {
		cout << "0" << endl; return 0;
	}
	if (B - A <= 0) {
		cout << "1" << endl; return 0;
	}
	B -= A;
	int cnt = 1;
	while (1) {
		cnt++;
		if (B - (A - 1) <= 0) {
			cout << cnt << endl;
			return 0;
		} else {
			B -= A - 1;
		}
	}
}

#include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define EPS (1e-10)

using namespace std;

int main(int argc, char *argv[]) {

	int A,B; cin >> A >> B;
	int skt = 1;
	int ans = 0;
	while(B > skt) {
		skt--;
		skt += A;
		ans++;
	}
	cout << ans << endl;

	return 0;
}


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

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;

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

const ll MOD = 1000000007;
const int INF = 1<<30;
//const ll INF = (ll)1e18 + 1;

int main(){
  int N, K; cin >> N >> K;
  vector<ll> x(N); rep(i, N) cin >> x[i];

  ll ans = INF;
  for (int i = 0; i < N; ++i){
    if (i + K - 1 >= N) continue;
    ll tmp = min(abs(x[i]) + abs(x[i + K - 1] - x[i]), abs(x[i + K - 1]) + abs(x[i + K - 1] - x[i]));
    //cout << x[i] << " " << x[i + K] << endl;
    ans = min(ans, tmp);
  }
  cout << ans << endl;
}

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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll , ll> 			pll;
typedef pair<ld, ld> 			pld;
typedef unordered_map<ll, ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5 + 7;
const ll 	MAX7 	= 	1e+7 + 7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9 + 7;

// <------------- Declare Variables Here ------------> //

ll T = 1;
ll n, x, m, y, k, z, N;
string s, t, d, c;

// <------------- Implement Functions Here ----------> //

// <------------- Start of main() -------------------> //

void MAIN() {
	cin >> n >> k ;
	vll pos,neg;
	bool zero = false;
	for(ll i=0;i<n;i++) {
		cin>>x;
		if(x == 0) zero = true;
		if(x > 0) pos.pb(x);
		if(x < 0) neg.pb(x);
	}
	reverse(all(neg));

	//for(ll i=1;i<pos.size();i++) pos[i]+=pos[i-1];
	//for(ll i=1;i<neg.size();i++) neg[i]+=neg[i-1];
	for(ll i=0;i<neg.size();i++) neg[i]=-neg[i];

	k-=zero;

	ll ans = INT_MAX;
	ll i=k,j=0;
	while(i>=0) {
		if(neg.size() >= i && pos.size() >= j) {
			ll val = ((i)?neg[i-1]:0) + ((j)?pos[j-1]:0);
			//cout<<i<<" "<<j<<" "<<val;newl;
			if(i && j) val += min(neg[i-1],pos[j-1]);
			//cout<<i<<" "<<j<<" "<<val;newl;
			ans = min(ans, val);

		}
		i--;
		j++;
	}
	cout<<ans;
}

int main() {
	fastio; randomINT;
	//cin >> T;
	while (T--) {
		MAIN();
	}
	return 0;
}


#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define INF 1000000
using namespace std;
int main(){
    //木曜日を０とする
    int table[12][31];
    int cnt=0,day;
    for(int i=1; i<=12; i++){
        if(i == 4 || i == 6 || i == 9 || i == 11) day = 30;
        else if(i == 2) day = 29;
        else day = 31;
        for(int j=1; j<=day; j++) {
            if(cnt == 7) cnt = 0;
            table[i-1][j-1] = cnt;
            cnt++;
        }
    }
    int a,b;
    while(cin >> a >> b){
        if(a == 0 && b == 0) break;
        if(table[a-1][b-1] == 0) cout << "Thursday" << endl;
        if(table[a-1][b-1] == 1) cout << "Friday" << endl;
        if(table[a-1][b-1] == 2) cout << "Saturday" << endl;
        if(table[a-1][b-1] == 3) cout << "Sunday" << endl;
        if(table[a-1][b-1] == 4) cout << "Monday" << endl;
        if(table[a-1][b-1] == 5) cout << "Tuesday" << endl;
        if(table[a-1][b-1] == 6) cout << "Wednesday" << endl;
    }
    return 0;
}

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

int main()
{
    string day[]={"Wednesday","Thursday","Friday","Saturday","Sunday","Monday","Tuesday"};
    int Mon[12]={31,29,31,30,31,30,31,31,30,31,30,31};
    int m,d;
    while(cin>>m>>d,m*d){
        int allDay=d;
        for(int i=0;i<m-1;i++){
            allDay += Mon[i];
        }
        cout<<day[allDay%7]<<endl;
    }
}


#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;
    cin >> n;
    string s, t;
    cin >> s >> t;
    int ans = n;
    rep(i, n) {
        bool ok = true;
        rep(j, n - i) {
            if (s[i+j] != t[j]) {
                ok = false;
            }
        }
        if (ok) {
            cout << ans << endl;
            return 0;
        }
        ++ans;
    }
    cout << ans << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define uni(e) e.erase(unique(e.begin(),e.end()),e.end())
#define double long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int INF=1e10;
int MOD=1e9+7;
signed main(){
  int a,b,c;
  cin>>a>>b>>c;
  cout<<max(a+b,max(a-b,a*b))<<endl;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll n;
  cin >> n;
  cout << n / 3 << endl;
}

#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    string s,t;
    cin>>s>>t;
    cout<<t<<s;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

char ans[1252][1252];
string three[3]={"aa.", "..a", "..a"};
string four[4]={"aabc", "ddbc", "bcaa", "bcdd"};
string five[5]{"aabba", "bcc.a", "b..cb", "a..cb", "abbaa"};
string six[6]={"aabc..", "ddbc..", "..aabc", "..ddbc", "bc..aa", "bc..dd"};
string seven[7]={"aabbcc.", "dd.dd.a", "..d..da", "..d..db", "dd.dd.b", "..d..dc", "..d..dc"};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // cout<<setprecision(10)<<fixed;
  int n;
  cin>>n;
  REP(i, n){
    REP(j, n){
      ans[i][j]='.';
    }
  }
  if(n==2){
    cout<<-1<<'\n';
    return 0;
  }
  int cur=n;
  while(cur>7){
    REP(i, 4){
      REP(j, 4){
        ans[i+n-cur][j+n-cur]=four[i][j];
      }
    }
    cur-=4;
  }
  if(cur==3){
    REP(i, 3){
      REP(j, 3){
        ans[i+n-cur][j+n-cur]=three[i][j];
      }
    }
  }
  else if(cur==4){
    REP(i, 4){
      REP(j, 4){
        ans[i+n-cur][j+n-cur]=four[i][j];
      }
    }
  }
  else if(cur==5){
    REP(i, 5){
      REP(j, 5){
        ans[i+n-cur][j+n-cur]=five[i][j];
      }
    }
  }
  else if(cur==6){
    REP(i, 6){
      REP(j, 6){
        ans[i+n-cur][j+n-cur]=six[i][j];
      }
    }
  }
  else{
    REP(i, 7){
      REP(j, 7){
        ans[i+n-cur][j+n-cur]=seven[i][j];
      }
    }
  }
  REP(i, n){
    REP(j, n){
      cout<<ans[i][j];
    }
    cout<<'\n';
  }
  return 0;
}


#include <iostream>

using namespace std;

const int MAX = 100000;
int seq[MAX];

int partition(int a[], int l, int r) {
    int x = a[r];
    int i = l - 1;
    for (int j = l; j < r; ++j) {
        if (a[j] <= x) {
            ++i;
            swap(a[j], a[i]);
        }
    }
    swap(a[i+1], a[r]);
    return i + 1;
}

int
main(int argc, const char *argv[])
{
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) cin >> seq[i];
    int q = partition(seq, 0, n-1);

    for (int i = 0; i < n; ++i) {
        if (i) cout << " ";
        if (i == q) cout << "[";
        cout << seq[i];
        if (i == q) cout << "]";
    }
    cout << endl;

    return 0;
}

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

  typedef long long int ll;
  typedef pair<int,int> pi;
  typedef pair<ll,ll> pll;
  typedef vector<int> vi;
  typedef vector<ll> vll;
  typedef vector<pi> vpi;
  typedef vector<pll> vpll;

  #define  ff           first
  #define  ss           second
  #define  pb           push_back
  #define  IOS          ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  #define  D(x)         cout << #x << " - " << x << endl;
  #define  D2(x)        cout << "[" << #x << ": "; for(auto it:x) cout << it << " "; cout << "]" << endl;
  #define  all(x)       (x).begin(), (x).end()
  #define  D2p(x)       cout << #x << " ~ [ "; for(auto n: x) cout << n.first << "-" << n.second << " / "; cout << "]" << endl;
  #define  ps(x,y)      fixed<<setprecision(y)<<x
  #define  rep(i,a,b)   for(ll i=a ; i<b ; ++i)

  const ll MOD = 1e9 + 7;
  const ll INF = 1e18;
  const ll maxn = 1e6 + 4;

  void solve(){
	ll n;
	cin >> n;
	vector<ll> v(n);
	vi bits(64);
	for(int i=0;i<n;i++){
		cin >> v[i];
	}
	for(int i=0;i<n;i++){
		ll k = v[i];
		int j =0;
		while(k>0){
		   bits[j++] += (k%2);
		   k/=2;
		}
	}
	ll prod = 1;
	ll lst=0;
	ll finalans=0;
	for(int i=0;i<63;i++){
		ll k = bits[i]*(n-bits[i]);
		ll st = (lst+k)%2;
		lst = (lst+k)/2;
		finalans = (finalans + (st*prod))%MOD;
		prod = (prod%MOD*2%MOD)%MOD;
	}

	while(lst>0){
		ll st = (lst)%2;
		finalans = (finalans+(st)*prod)%MOD;
		lst=(lst)/2;
		prod = (prod%MOD*2%MOD)%MOD;
	}

	cout << finalans;
  }

  int main(){
    IOS
    solve();
    cerr <<endl <<"[ Time : " << (float)clock() / CLOCKS_PER_SEC << " secs ]" << endl;
  }

// integer overflow
// remember to clear visited array
// take input as vector<string> while using grid
// don't assign after modifying


#include<bits/stdc++.h>
#define reg register int
#define il inline
#define fi first
#define se second
#define mk(a,b) make_pair(a,b)
#define numb (ch^'0')
#define pb push_back
#define solid const auto &
#define enter cout<<endl
#define pii pair<int,int>
using namespace std;
typedef long long ll;
template<class T>il void rd(T &x){
    char ch;x=0;bool fl=false;while(!isdigit(ch=getchar()))(ch=='-')&&(fl=true);
    for(x=numb;isdigit(ch=getchar());x=x*10+numb);(fl==true)&&(x=-x);}
template<class T>il void output(T x){if(x/10)output(x/10);putchar(x%10+'0');}
template<class T>il void ot(T x){if(x<0) putchar('-'),x=-x;output(x);putchar(' ');}
template<class T>il void prt(T a[],int st,int nd){for(reg i=st;i<=nd;++i) ot(a[i]);putchar('\n');}
namespace Modulo{
const int mod=1e9+7;
int ad(int x,int y){return (x+y)>=mod?x+y-mod:x+y;}
void inc(int &x,int y){x=ad(x,y);}
int mul(int x,int y){return (ll)x*y%mod;}
void inc2(int &x,int y){x=mul(x,y);}
int qm(int x,int y=mod-2){int ret=1;while(y){if(y&1) ret=mul(x,ret);x=mul(x,x);y>>=1;}return ret;}
}
using namespace Modulo;
namespace Miracle{
const int N=2002;
const int M=4000000+5+N+N;
int n,k;
int f[2][N];
int jie[M],inv[M];
int C(int n,int m){
    if(n<0||m<0||n<m) return 0;
    return mul(jie[n],mul(inv[m],inv[n-m]));
}
int main(){
    rd(n);rd(k);
    if(k==1){
        puts("1");return 0;
    }
    int lim=n*k+n+n;
    jie[0]=1;
    for(reg i=1;i<=lim;++i) jie[i]=mul(jie[i-1],i);
    inv[lim]=qm(jie[lim]);
    for(reg i=lim-1;i>=0;--i) inv[i]=mul(inv[i+1],i+1);
    int tmp=0;
    f[0][0]=1;
    for(reg i=2*n;i>=1;--i){
        tmp^=1;
        memset(f[tmp],0,sizeof f[tmp]);
        int re=2*n-i;
        for(reg j=0;j<=min(re,n);++j){
            if(!f[tmp^1][j]) continue;
            int le=re-j;
            if(le+1<=j) f[tmp][j]=ad(f[tmp][j],f[tmp^1][j]);
            if(j!=n){
                f[tmp][j+1]=ad(f[tmp][j+1],mul(f[tmp^1][j],C(k-2+le+j*(k-1),le+j*(k-1))));
            }
        }
    }
    ll ans=mul(f[tmp][n],jie[n]);
    ot(ans);
    return 0;
}

}
signed main(){
    Miracle::main();
    return 0;
}

/*
   Author: *Miracle*
*/

#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef vector<vector<ll>> mat;
typedef vector<ll> vec;

void debug(vec &v) {
	int n = v.size();
	rep(i, n) {
		if (i > 0)cout << " ";
		cout << v[i];
	}
	cout << endl;
}

ll mod_pow(ll x, ll n) {
	ll ret = 1;
	while (n > 0) {
		if (n % 2)ret = ret * x%mod;
		x = x * x%mod; n >>= 1;
	}
	return ret;
}
struct perm {
private:
	int sz;
	vector<ll> p, invp;
public:
	perm(int n) {
		sz = n + 1;
		p.resize(sz), invp.resize(sz);
		p[0] = 1;
		rep1(i, sz - 1) {
			p[i] = p[i - 1] * i%mod;
		}
		invp[sz - 1] = 1;
		ll cop = mod - 2, x = p[sz - 1];
		while (cop) {
			if (cop % 2)invp[sz - 1] = invp[sz - 1] * x%mod;
			cop >>= 1; x = x * x % mod;
		}
		per(i, sz - 1) {
			invp[i] = invp[i + 1] * (i + 1) % mod;
		}
	}
	ll comb(ll x, ll y) {
		if (x < y || y < 0)return 0;
		ll ret = p[x];
		(ret *= invp[y]) %= mod;
		(ret *= invp[x - y]) %= mod;
		return ret;
	}
	ll combP(ll x, ll y) {
		if (x < y || y < 0)return 0;
		return p[x] * invp[x - y] % mod;
	}
};
perm pm(1 << 22);

ll dp[2001];
ll rdp[2002];
ll nex[2001];

void solve() {
	int n, k; cin >> n >> k;
	if (k == 1) {
		cout << 1 << endl; return;
	}
	dp[1] = 1;
	for (int i = 2; i < 2002; i++)rdp[i] = 1;
	rep1(i, n - 1) {
		for (int j = 1; j <= i + 1; j++) {
			int num = i * k - (j - 1);
			nex[j] = (rdp[i + 1] - rdp[j - 1])*pm.comb(num + k - 2, num);
			nex[j] = (nex[j] % mod + mod) % mod;
		}
		for (int j = 1; j <= i + 1; j++) {
			dp[j] = nex[j];
			rdp[j + 1] = (rdp[j] + dp[j]) % mod;
		}
	}
	ll ans = rdp[n + 1];
	rep1(i, n)ans = ans * i%mod;
	cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(12);
	//init();
	//int t; cin >> t; rep(i, t)solve();
	solve();
	//stop
	return 0;
}


#include <bits/stdc++.h>

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

int parent[N];

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

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

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

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

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

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

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

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

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

#include <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 dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
const ll INF=1e18;

int main() {
	double n,x,t;
	cin >> n >> x >> t;
	x = ceil(n/x);
	cout << int(x * t) << endl;
}


#include <bits/stdc++.h>
//#include <atcoder/all>
#define ll long long int
#define MOD 1000000007
#define P pair<ll,ll>
#define INF 1000000000000000000

//using namespace atcoder;
using namespace std;

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

  vector<ll> a(5);
  for (int i = 0; i < 5; i++){
    cin >> a[i];
  }
  sort(a.begin(), a.end());

  cout << (n + a[0] - 1)/a[0] + 4 << endl;

  return 0;
}

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

typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define MP make_pair
#define F first
#define S second
#define PB push_back
#define dump(x)  cout << #x << " = " << (x) << endl;	// debug
#define SZ(x) ((ll)(x).size())
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (ll i = (a); i >= (b); i--)
#define ps(s) cout << #s << endl;
#define pv(v) cout << (v) << endl;
#define pvd(v) cout << setprecision(16) << (v) << endl;
#define ALL(a)  (a).begin(),(a).end()
#define RANGE(a, left, right)  (a).begin()+(left),(a).begin()+(right)	// left to (right-1)

int main() {
	ll n, a, b, c, d, e;
	cin >> n >> a >> b >> c >> d >> e;
	ll bn = min({ a, b, c, d, e });
	ll res = (n + bn - 1) / bn + 4;
	pv(res)
	return 0;
}


#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
#include <time.h>
#include <complex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

int main(){
  ll N,A[200007],B[200007],T=0;
  cin >> N ;
  rep(i,N){
    cin >> A[i];
  }
  rep(i,N){
    cin >> B[i];
  }
  rep(i,N){
    if(clock()>1900000){
      return 0;
    }
    if(T==0){
      ll K=A[i]^B[0],L=0,P=0;
      if((A[i]^B[0])==(A[(i+1)%N]^B[1])){
        P=1;
      }
      rep(j,N){
        if((A[(i+j)%N]^B[j])!=K){
          L=1;
          break;
        }
      }
      if(L==0){
        cout << i << " " << K << endl;
        T=1;
      }
    }
    else{
      if((A[i]^B[0])==(A[(i+1)%N]^B[1])){
        cout << i << " " << (A[i]^B[0]) << endl;
      }
    }
  }
}

#include<iostream>
using namespace std;

struct Node {
    int key;
    Node* parent;
    Node* left;
    Node* right;
    Node(int key_in){
        key    = key_in;
        parent = NULL;
        left   = NULL;
        right  = NULL;
    }
};

class Tree {
    Node* root;
    void inorder(Node* n){
        if (n == NULL) return;
        inorder(n->left);
        cout << " " << n->key;
        inorder(n->right);
    }
    void preorder(Node* n){
        if (n == NULL) return;
        cout << " " << n->key;
        preorder(n->left);
        preorder(n->right);
    }
public:
    Tree(){
        root = NULL;
    }
    void insert(int key){
        Node* z = new Node(key);
        if (root == NULL) {
            root = z;
            return;
        }
        Node* x = root;
        while (1) {
            Node** child_p;
            if (key < x->key) {
                child_p = &(x->left);
            } else {
                child_p = &(x->right);
            }
            if (*child_p == NULL) {
                *child_p = z;
                z->parent = x;
                return;
            }
            x = *child_p;
        }
    }
    void print(){
        inorder(root);
        cout << endl;
        preorder(root);
        cout << endl;
    }
    Node* find(int key){
        for (Node* x = root; x != NULL;) {
            if (key == x->key) return x;
            if (key < x->key) {
                x = x->left;
            } else {
                x = x->right;
            }
        }
        return NULL;
    }

    void delete_1_child(Node* x){
        Node* child;
        if (x->left == NULL && x->right == NULL) {
            child = NULL;
        } else if (x->left != NULL) {
            child = x->left;
        } else {
            child = x->right;
        }
        if (x == root) {
            root = child;
            delete x;
            return;
        }
        Node* p = x->parent;
        if (x == p->left) {
            p->left = child;
        } else {
            p->right = child;
        }
        if (child != NULL) {
            child->parent = x->parent;
        }
        delete x;
    }

    Node* next_node(Node* x){
        if (x->left == NULL) return x;
        return next_node(x->left);
    }

    void delete_(int key){
        Node* x = find(key);
        if (x == NULL) return;
        if (x->left == NULL || x->right == NULL) {
            delete_1_child(x);
            return;
        }
        Node* y = next_node(x->right);
        x->key = y->key;
        if (y->left == NULL || y->right == NULL) {
            delete_1_child(y);
            return;
        }

    }
};

int main(){
    int m;
    cin >> m;
    Tree T;
    for (int i = 0; i < m; i++) {
        string str;
        cin >> str;
        if (str == "print") {
            T.print();
            continue;
        }
        int num;
        cin >> num;
        if (str == "insert") {
            T.insert(num);
            continue;
        }
        if (str == "find") {
            if (T.find(num) == NULL) {
                cout << "no" << endl;
            } else {
                cout << "yes" << endl;
            }
            continue;
        }
        if (str == "delete") {
            T.delete_(num);
        }
    }
    return 0;
}


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

using ll=int64_t;

int main() {
  int N; cin >>N;
  vector<ll> check;
  rep(i,0,N) {
    ll A; cin >>A;
    check.push_back(A);
  }
  sort(check.rbegin(),check.rend());
  ll temp=0;
  rep(i,1,N) {
    if (check[i-1]==check[i]) {
      if (!temp) {
        temp=check[i];
        i++;
      } else {
        cout <<check[i]*temp <<endl;
        return 0;
      }
    }
  }
  cout <<0 <<endl;
  return 0;
}

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define int long long
using namespace std;
#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 rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr int inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b);
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a / gcd(a, b) * b ;
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */

signed main() {
  int n;cin >> n;
  map<int,int> mp;
  rep(i,n) {
	  int a;cin >> a;
	  mp[a]++;
  }
  vector<P> v;
  for(auto p:mp) v.pb({p.first,p.second});
  resort(v);
  //for(auto p:v) cout << p.first << " " << p.second << endl;
  int k=0,l=0;
  rep(i, v.size()) {
	  //cout << "OK" << endl;
	  if(k>0&&l>0) break;
	  if(k==0&&l==0) {
		  if(v[i].second>=4) k=v[i].first,l=v[i].first;
		  else if(v[i].second>=2) k=v[i].first;
	  }
	  else if(k>0) {
		  if(v[i].second>=2) l=v[i].first;
	  }
  }
  cout << k*l << endl;
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
typedef long long ll;
bool check(int m, char c, int l, int r){
    bool res = true;
    if(m == 0){
        if(c == 'o'){
            if(l != r) res = false;
        }else{
            if(l == r) res = false;
        }
    }else{
        if(c == 'o'){
            if(l == r) res = false;
        }else{
            if(l != r) res = false;
        }
    }
    return res;
}

int main(){
    int n; cin >> n;
    string s; cin >> s;
    string v[4] = {"00", "01", "10", "11"};
    rep(i,4){
        vector<int> t(n);
        rep(j,2) t[j] = (v[i][j] == '0') ? 0 : 1;

        FOR(k, 1, n-1){
            if(t[k] == 0){
                if(s[k] == 'o'){
                    t[k+1] = t[k-1];
                }else{
                    t[k+1] = 1-t[k-1];
                }
            }else{
                if(s[k] == 'o'){
                    t[k+1] = 1-t[k-1];
                }else{
                    t[k+1] = t[k-1];
                }
            }
        }

        if(!check(t[n-1], s[n-1], t[n-2], t[0])) continue;
        if(!check(t[0], s[0], t[n-1], t[1])) continue;

        rep(l, n) printf("%c", t[l] == 0 ? 'S' : 'W');
        cout << endl;
        return 0;
    }

    cout << "-1" << endl;
    return 0;
}

#include <bits/stdc++.h>

const double PI = 3.14159265358979323846;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<ll> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

//const ll mod = 1e10;
//typedef priority_queue<P, vector<P>, greater<P> > PQ_ASK;

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

    vector<vector<int>> v(n, vector<int>(m));
    rep(i, n) rep(j, m) cin >> v[i][j], v[i][j]--;

//    rep(i, n) reverse(v[i].begin(), v[i].end());

    vector<bool> exclude(m, false);

    int ans = INT_MAX;

    while (count(exclude.begin(), exclude.end(), false) > 0) {
        vector<int> join(m);

        rep(i, n) {
            rep(j, m) {
                int t = v[i][j];
                if (!exclude[t]) {
                    join[t]++;
                    break;
                }
            }
        }

        int now = *max_element(join.begin(), join.end());
//        cout << now << endl;
        cmin(ans, now);
        rep(i, m) {
            if (join[i] == now) {
                exclude[i] = true;
            }
        }

    }
    cout << ans << endl;

}


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

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> xs(n + 1), ys(m + 1);
  cin >> xs[0] >> ys[0];
  for (int i = 1; i <= n; ++i)
    cin >> xs[i];
  for (int i = 1; i <= m; ++i)
    cin >> ys[i];
  if (*max_element(xs.begin(), xs.end()) < *min_element(ys.begin(), ys.end()))
    cout << "No War" << endl;
  else
    cout << "War" << endl;
}

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

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

  int x[n],y[m];
  rep(i,n) cin >> x[i];
  rep(i,m) cin >> y[i];

  int flag = 0;
  for(int z = X+1; z <= Y; z++){
    rep(i,n){
      if(z <= x[i]){
        flag = 1;
        break;
      }//if
    }//rep
    rep(i,m){
      if(z > y[i]){
        flag = 1;
        break;
      }//if
    }//rep

    if(flag == 0){
      cout << "No War" << endl;
      return 0;
    }
    flag = 0;
  }//for

  cout << "War" << endl;
}


#include <iostream>
using namespace std;

int a,b,sum,dif,tim;

int main(){
	cin >> a >> b;
	sum = a + b;
	dif = a - b;
	tim = a * b;
	if((sum > dif)&&(sum > tim)){
		cout << sum;
	}else{
		if(dif > tim){
			cout << dif;
		}else{
			cout << tim;
		}
	}
	cout << endl;
}

#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;

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

ll GCD(ll x, ll y) {
    if (y == 0) return x;
    else return GCD(y, x % y);
}

#include <iostream>

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

    int C = A + B;
    int D = A - B;
    int E = A * B;

    cout << max(C,max(D,E)) << endl;
}


#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++)
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)

using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}

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

  return 0 ;
}

#include <bits/stdc++.h>
using namespace std;
#define     LL              long long int
#define     FOR(I,A,B)      for( int I = A; I < B; ++I )
#define     SFI(X)          scanf("%d",&X)
#define     SFL(X)          scanf("%lld",&X)

int main() {

//    SAT, SUN, MON, TUE, WED, THU, FRI
//    1     2    3    4    5    6    7

    string S;

    cin >> S;

    if(S == "MON") {
            printf("6\n");
    } else if(S == "TUE") {
                printf("5\n");
    } else if(S == "WED") {
                printf("4\n");
    } else if(S == "THU") {
                printf("3\n");
    } else if(S == "FRI") {
                printf("2\n");
    } else if(S == "SAT") {
        printf("1\n");
    }else {
        printf("7\n");
    }

    return 0;
}


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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3

#define BV_SIZE 64ULL // 64bit
#define MAX_BV_NUM 100 // m <= 100*64 = 6400

unsigned long long Peq[MAX_BV_NUM][0x100];
int levenshteinDistance(string a,string b) {
  int m=a.size(),n=b.size();
  int num_of_bv = (m + BV_SIZE -1) / BV_SIZE;

  for (int i = 0; i < m; i++) {
    Peq[i / BV_SIZE][a[i]] |= 1ULL << ((unsigned long long)i % BV_SIZE);
  }

  int score = m;
  unsigned long long Pv[MAX_BV_NUM], Mv[MAX_BV_NUM], Ph[MAX_BV_NUM], Mh[MAX_BV_NUM], Xv[MAX_BV_NUM], Xh[MAX_BV_NUM], Eq[MAX_BV_NUM], Xt[MAX_BV_NUM], Xa[MAX_BV_NUM];
  unsigned long long top = 1ULL << (((unsigned long long)m - 1ULL) % BV_SIZE);

  for(int i = 0; i < num_of_bv; i++) {
    Pv[i] = ~0ULL; Mv[i] = 0ULL;
  }

  for (int j = 0; j < n; j++) {
    for(int i = 0; i < num_of_bv; i++){
      Eq[i] = Peq[i][b[j]];
      Xv[i] = Eq[i] | Mv[i];
      Xt[i] = Eq[i] & Pv[i];
    }

    unsigned long long carry = 0ULL;

    for(int i = 0; i < num_of_bv; i++){
      Xa[i] = Xt[i] + Pv[i] + carry;
      if(Xt[i] == ~0ULL && carry == 1ULL){
        carry = 1ULL;
      }else{
        unsigned long long cXt = Xt[i] + carry;
        carry = (((cXt & Pv[i]) | ((cXt | Pv[i]) & ( ~ (cXt + Pv[i]) ))) >> 63ULL) & 1ULL;
      }
    }

    for(int i = 0; i < num_of_bv; i++){
      Xh[i] = (Xa[i] ^ Pv[i]) | Eq[i];

      Ph[i] = Mv[i] | ( ~ (Xh[i] | Pv[i]) );
      Mh[i] = Pv[i] & Xh[i];
    }

    if((Ph[num_of_bv - 1] & top) != 0ULL)score++;
    else if((Mh[num_of_bv - 1] & top) != 0ULL)score--;

    unsigned long long Ph_carry = 1ULL;
    unsigned long long Mh_carry = 0ULL;

    for(int i = 0; i < num_of_bv; i++){
      unsigned long long nxt_Ph_carry = (Ph[i] >> 63ULL) & 1ULL;
      Ph[i] = (Ph[i] << 1ULL) | Ph_carry;
      Ph_carry = nxt_Ph_carry;

      unsigned long long nxt_Mh_carry = (Mh[i] >> 63ULL) & 1ULL;
      Pv[i] = ((Mh[i] << 1ULL) | Mh_carry ) | ( ~ (Xv[i] | Ph[i]) );
      Mh_carry = nxt_Mh_carry;

      Mv[i] = Ph[i] & Xv[i];
    }

  }
  return score;
}

int main(){
	string a,b;
  cin>>a>>b;
  cout<<levenshteinDistance(a,b)<<endl;
	return 0;
}

// C - Grid Repainting 2
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define _GLIBCXX_DEBUG
const lli INF = 2147483647;
const lli MINF = -2147483648;
const lli LINF = 9223372036854775807;
const lli MOD = 1000000007; //10^9+7
const double PI = acos(-1);
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define pb push_back
#define eb emplace_back
#define mp make_pair
#pragma GCC optimize("Ofast")
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using vvli = vector<vlli>;
using vs = vector<string>;
using vvs = vector<vs>;
using vb = vector<bool>;
using vvb = vector<vb>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}
// aよりもbが大きいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T &b)
{
  if (a > b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli a, b, c, h, n, w, ans = 0, count = 0;
  vector<pair<string, pair<lli, lli>>> pr;
  cin >> h >> w;
  vs s(h);
  rep(i, 0, h)
  {
    cin >> s[i];
  }
  vlli dx = {0, 1, 0, -1};
  vlli dy = {1, 0, -1, 0};
  rep(i, 0, h)
  {
    rep(j, 0, w)
    {
      if (s[i][j] == '.')
      {
        continue;
      }
      rep(k, 0, 4)
      {
        a = i + dy[k];
        b = j + dx[k];
        if (a < 0 || a >= h)
          continue;
        if (b < 0 || b >= w)
          continue;
        if (s[a][b] == '#')
          count++;
      }
      if (count == 0)
      {
        cout << "No" << endl;
        return 0;
      }
      count = 0;
    }
  }
  cout << "Yes" << endl;
}


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

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

// 最小公倍数
ll lcm(ll a, ll b){
    return a/gcd(a, b) * b;
}

int main()
{
    cout << fixed << setprecision(15);
    string s;
    cin >> s;

    ll N = s.length();

    REP(i, N-1){
        if(s[i] == s[i+1]){
            cout << i+1 << " " << i+2 << endl;
            return 0;
        }
    }

    REP(i, N-2){
        if(s[i] == s[i+2]){
            cout << i+1 << " " << i+3 << endl;
            return 0;
        }
    }

    cout << -1 << " " << -1 << endl;
    return 0;
}

#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <vector>
#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

int main(){
    string x;
    cin >> x;
    int n = x.length();

    if(n == 2){
        if(x[0] == x[1]){
            printf("1 2");
        }
        else {
            printf("-1 -1");
        }
        return 0;
    }

    for(int i = 0; i < n-2; i++){
        if(x[i] == x[i + 1] || x[i + 1] == x[i + 2] || x[i + 2] == x[i]){
            printf("%d %d", i+1, i+3);
            return 0;
        }
    }
    printf("-1 -1");

    return 0;
}


#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream>
#include<unordered_map>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i>
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>>
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define PN cout << endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (n-1); i >= (int)(m); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)( 998244353))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>())
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - (a))
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - (a))
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

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

/*
ll ncr[100][100];
ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

ll npr[100][100]={};
ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

ll nHr(int n,int r){ret nCr(n+r-1,r);}
*/

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

int main(){
    ll n;
    cin >> n;
    map<ll,ll> d;
    ll max_d= 0;

    rep(i,0,n){
	ll a;
	cin >> a;
	d[a]++;
	if(i == 0){
	    if(a != 0){
		P(0);
		ret 0;
	    }
	}
	max_d = max(max_d,a);
    }

    ll ans = 0;
    if(d[0] == 1){
	ans = 1;
	ll num = 1;

	while(num <= max_d){

	    ans *= modpow( d[num-1] , d[num]);
	    ans = mod(ans);

	    num++;
	}

    }

    P(ans);

    return  0;
}

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

typedef long long ll;
typedef int ii;
//typedef vector<ll> vi;

#define INF 1000000007

#define pi 3.141592654

#define T while(t--)
#define for2(i,a,b) for(i=a;i>=b;i--)
#define for3(i,a,b) for(i=a;i<=b;i=i+2)
#define for1(i,a,b) for(i=a;i<=b;i++)
#define pb push_back
#define mp make_pair

#include<sstream>

#define si set<ll>
#define se multiset<ll>

typedef long double ld;

typedef vector<int64_t> vi;

#define bb(arr,nn,xx) upper_bound(arr,arr+nn,xx)-arr
#define aa(arra,nna,xxa) lower_bound(arra,arra+nna,xxa)-arra

#define all(v) sort(v.begin(),v.end())

#define all1(v) sort(v.rbegin(),v.rend())

ii main()
{

    ios::sync_with_stdio(0);
    cin.tie(0);

    int64_t n,i; cin>>n; vi v; ll x;

    for1(i,1,n)
    {

        cin>>x;

        v.pb(x);

    }

    ll sum1=0; ll sum=0;

    for2(i,n-1,1)
    {

        sum1+=v[i];

        sum+=(((v[i-1]%INF)*(sum1%INF))%INF)%INF;

    }

    cout<<sum%(INF)<<"\n";

}


#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<62;
const int INF = 1<<30;
const double PI=acos(-1);
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];

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

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

int main(){
	COMinit();
	int n,m;
	ll ans=1LL;
	cin >>n>>m;
	int bef=m;
	map<int,int>co;
	int c=0;
	for(int i=2;i<=sqrt(bef);i++){
		c=0;
		while(bef%i==0){
			bef/=i;
			c++;
		}
		if(c){
			co[i]+=0;
			co[i]+=c;
		}
	}
	if(bef!=1){
		co[bef]+=0;
		co[bef]++;
	}
	for(auto itr=co.begin();itr!=co.end();itr++){
		ans*=COM(itr->S + n-1 , n-1);
		ans%=MOD;
	}
	cout<<ans<<endl;
}

#include <bits/stdc++.h>
using namespace std;
string s;
int n, dp[305][305][305];
int go(int l, int r, int k) {
	if (dp[l][r][k] != -1) return dp[l][r][k];
	if (l == r) {
		return dp[l][r][k] = 1;
	}
	if (l + 1 == r) {
		if (s[l] == s[r] || k) {
			return dp[l][r][k] = 2;
		} else {
			return dp[l][r][k] = 1;
		}
	}
	dp[l][r][k] = max(go(l + 1, r, k), go(l, r - 1, k));
	if (s[l] == s[r]) {
		dp[l][r][k] = max(dp[l][r][k], go(l + 1, r - 1, k) + 2);
	} else if (k) {
		dp[l][r][k] = max(dp[l][r][k], go(l + 1, r - 1, k - 1) + 2);
	}
	return dp[l][r][k];
}
int main() {
	int k;
	cin >> s >> k;
	n = s.size();
	memset(dp, -1, sizeof(dp));
	cout << go(0, n - 1, k) << endl;
	return 0;
}


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

int main(){
  int n;
  cin >> n;
  vector<ll> A(n);
  rep(i,n) cin >> A[i];
  sort(A.begin(),A.end());
  rep(i,n-1){
    if(A[i]!=A[i+1])continue;
    cout << "NO" <<endl;
    return 0;
  }
  cout << "YES" << endl;
  return 0;
}

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

int main()
{
  int n,m,x,y,z;
  string ans="War";
  cin>>n>>m>>x>>y;
  vector<int> a(n);
  vector<int> b(m);
  for(int i=0;i<n;i++)
  {
    cin>>a.at(i);
  }
  for(int i=0;i<m;i++)
  {
    cin>>b.at(i);
  }
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  sort(b.begin(),b.end());
  for(int i=x+1;i<=y;i++)
  {
    if((a.at(0)<i)&&(b.at(0)>=i))
    {
      ans="No War";
      break;
    }
  }
  cout<<ans<<endl;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ll mod2 = 998244353;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<ll> A(n); rep(i, n) cin >> A[i];
  vector<vector<int>> B(n+1, vector<int>(60));
  ll ans = 0;
  rep(i, n) {
    rep(j, 60) {
      (ans += ((A[i]>>j)&1 ? i-B[i][j] : B[i][j]) * ((1LL<<j) % mod)) %= mod;
      B[i+1][j] = B[i][j] + ((A[i]>>j)&1);
    }
  }
  cout << ans << endk;
  return 0;
}

#if __has_include("debug.h")
    #include "debug.h"
#else
#include <bits/stdc++.h>
using namespace std;
#define d(...) 2;
#endif

#define int long long int
#define ld long double

#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"

#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define ff first
#define ss second
#define eps 1e-10
#define PI acos(-1LL)

int MOD = 1e9 + 7;

inline int mul(int a,int b,int mod=MOD){return ((a%mod)*(b%mod))%mod;}
inline int sum(int a,int b,int mod=MOD){return ((a%mod)+(b%mod))%mod;}
int power(int a,int n,int mod=MOD){int ans=1;while(n){if(n&1)ans=mul(ans,a,mod);a=mul(a,a,mod);n>>=1;}return ans;}
inline int sub(int a,int b,int mod=MOD){ return (((a) % mod)-((b) % mod) + mod) % mod; }
int inv[1000006];
void find_inverse(int m)  //m should be prime..
{
	inv[1] = 1;
	for(int i = 2; i < m; ++i)
    	inv[i] = (m - (m/i) * inv[m%i] % m) % m;
}

#define gcd(a,b)            __gcd((a),(b))
#define lcm(a,b)            ((a*b)/gcd(a,b))

void solve();

int32_t main()
{
    #ifdef DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
    #endif

    fast

    int t = 1;
	// cin>>t;

	while(t--)
	    solve();
	return 0;
}

void solve()
{
	int i,j;
	int n;
	cin>>n;

	vector<int>a(n);

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

	int ans=0;

	for(i=0;i<60;i++)
	{
		int cnt=0;
		for(j=0;j<n;j++)
		{
			if(a[j]&(1LL<<i))
			{
				cnt++;
			}
		}

		int one=cnt;
		int zero=n-cnt;

		ans=sum(ans,mul(power(2,i),mul(one,zero)));
	}

	cout<<ans<<endl;

}


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

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

    vector<pair<int, int>> v1(1e5+1);
    vector<pair<int, int>> v2(1e5+1);
    for(int i=0; i<n; i++){
        int in;
        cin>> in;
        if(i % 2 == 0){
            v1[in].first++;
            v1[in].second = in;
        }else{
            v2[in].first++;
            v2[in].second = in;
        }
    }
    sort(v1.begin(), v1.end(), greater<pair<int, int>>());
    sort(v2.begin(), v2.end(), greater<pair<int, int>>());

    int cnt;
    if(v1[0].second != v2[0].second){
        cnt = v1[0].first + v2[0].first;
    }else{
        cnt = max(v1[0].first + v2[1].first, v1[1].first + v2[0].first);
    }

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

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

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

  sort(a.begin(), a.end());
  int ans = 0;
  int last = 0;
  int exist = 0;
  rep(i, n) {
    if (a[i] == last) exist = 1 - exist;
    else {
      ans += exist;
      last = a[i];
      exist = 1;
    }
  }
  ans += exist;
  cout << ans << endl;
  return 0;
}


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

int main(){
    std::vector<string> d(3);
    for(ll i=0;i<3;++i){
        cin>>d[i];
    }
    ll a=0,b=0,c=0;
    char now='a';
    while(1){
        switch(now){
            case 'a':
                if(a>=d[0].length()){
                    cout<<char(now+'A'-'a');
                    return 0;
                }
                now=d[0][a];
                a++;
            break;
            case 'b':
                if(b>=d[1].length()){
                    cout<<char(now+'A'-'a');
                    return 0;
                }
                now=d[1][b];
                b++;
            break;
            case 'c':
                if(c>=d[2].length()){
                    cout<<char(now+'A'-'a');
                    return 0;
                }
                now=d[2][c];
                c++;
            break;
        }
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll ;
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
 const ll inf=1e9+7;
string a,b,c;

queue<char>q[3];

void scan(int n)
{
	char c;
	while((c=getchar() )!='\n')
		{
			q[n].push(c);
		}
}
int main()
{
    fast;

    scan(0);
    scan(1);
    scan(2);

	ll k=0;
	while(!q[k].empty())
	{
		char c=q[k].front();
		q[k].pop();

		k=c-'a';
	}

  cout<<char(k +'A');

}


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

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

    int f = 10;

    for(LL A=1; A*A<=N; A++){

        if(N%A != 0) continue;

        LL a = A;
        LL b = N/A;
        int B_d = 0;
        int A_d = 0;

        while(a>0){
            a /= 10;
            A_d++;
        }

        while(b>0){
            b /= 10;
            B_d++;
        }

        f = min(f,max(A_d,B_d));
    }

    cout << f << endl;

}

#include<vector>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <cmath>
#define INF 100000000000000
using namespace std;
typedef long long llong;

//int isalpha(char ch): ch がアルファベットなら true を返す
//int isdigit(char ch): ch が数字なら true を返す
//int islower(char ch): ch が小文字なら true を返す
//int isupper(char ch): ch が大文字なら true を返す
//int tolower(char ch): ch の小文字を返す
//int toupper(char ch): ch の大文字を返す

//string型
//size()	文字数を返す
//insert()	（指定した場所に）文字・文字列を挿入する
//erase()	（指定した場所の）文字・文字列を削除する
//clear()	すべての文字を削除する
//substr()	文字列の（指定した）部分文字列を返す
//replace()	（指定した）部分文字列を新しい文字列に置換する
//文字列の比較は、<=や==などを使え
//replace関数を使い、簡単に文字列を置換
//リバース関数：reverse(str.begin(), str.end());
//map<type, type> dict;で宣言
//グラフ理論用変数
//vector<vector<llong> > graph(N);

//ソート
//降順sort(v.begin(), v.end(), std::greater<Type>());

//大文字から小文字へんかん
//w[i] = w[i]-'A'+'a';

bool isprime(llong num){
    if(num==1){
        return false;
    }
    if(num==2){
        return true;
    }
    for(int i=2; i<=sqrt(num); i++){
        if(num%i==0){
            return false;
        }
    }
    return true;
}

//約数列挙
void EnumerateFactor(vector<vector<llong> > &factor_list, llong num){
    llong cnt=0;
    for(int i=1; i<=sqrt(num); i++){
        if(num%i==0){
            factor_list[cnt].push_back(i);
            factor_list[cnt].push_back(num/i);
            cnt++;
        }
    }
}

int main(){
    llong n;
    llong ans=INF;
    llong temp=-1*INF;
    vector<vector<llong> > factor_list(100000);
    string A, B;

    scanf("%lld", &n);
    EnumerateFactor(factor_list, n);
    for(int i=0; i<factor_list.size(); i++){
        if(factor_list[i].size()==0){
            break;
        }
        A = to_string(factor_list[i][0]);
        B = to_string(factor_list[i][1]);
        temp = max(A.size(), B.size());
        ans  = min(temp, ans);
    }
    cout << ans << endl;
    return 0;

}


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

int main() {
  int n, m; cin >> n >> m;
  vector<int> p(n+1,0);
  vector<bool> ac(n+1);
  int ac_cnt = 0, pe_cnt = 0;
  rep(i,m) {
    int pi; string si; cin >> pi >> si;
    if (!ac[pi]) {
      if (si == "WA") {
        p[pi]++;
      } else {
        ac_cnt++;
        pe_cnt += p[pi];
        ac[pi] = true;
      }
    }
  }
  cout << ac_cnt << " " << pe_cnt << endl;
  return 0;
}

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

int main () {
  int d, g;
  cin >> d >> g;
  vector<pair<int,int>> p(d);
  for (int i = 0; i < d; i++)
    cin >> p[i].first >> p[i].second;

  vector<int> v(d);
  iota (v.begin(), v.end(), 0);
  int ans = 1000;
  do {
    int sum = 0, c = 0;
    for (int i = 0; i < d; i++) {
      int x = v[i];
      int i100 = 100 * (x+1);
      int pi100 = p[x].first * i100;
      if (g > sum + pi100 + p[x].second) {
        sum += pi100 + p[x].second;
        c += p[x].first;
      }
      else if (sum + pi100 <= g &&
               g <= sum + pi100 + p[x].second) {
        c += p[x].first;
        break;
      }
      else {
        c += (g - sum + i100-1) / i100;
        break;
      }
    }
    ans = min(ans, c);
  }
  while (next_permutation(v.begin(), v.end()));

  cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
#define inputv(v, n)                                                           \
    vl v;                                                                      \
    rep(i, n) {                                                                \
        ll x;                                                                  \
        cin >> x;                                                              \
        v.push_back(x);                                                        \
    }
bool chmin(ll& a, ll  b) { if (b < a) { a = b; return 1; } return 0; }
bool chmax(ll& a, ll b) { if (b > a) { a = b; return 1; } return 0; }
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
struct Gragh {
    ll N;
    vector<vl> G;
    vl visited;

    Gragh(ll n) {
        N = n;
        G.resize(N);
        resetv();
    }

    void add(ll a, ll b) { G[a].push_back(b); }

    void resetv(void) { visited = vl(N, 0); }

    //重さ無し
    void dfs(ll x) {
        visited[x] = 1;
        for (ll i : G[x]) {
            if (visited[i] == 0) {
                dfs(i);
            }
        }
    }
};
int main() {
    cin >> n >> m;
    Gragh G(2 * n);
    rep(i, m) {
        cin >> a >> b;
        a--;
        b--;
        G.add(a * 2, b * 2 + 1);
        G.add(b * 2, a * 2 + 1);
        G.add(a * 2+1, b * 2);
        G.add(b * 2+1, a * 2);
    }

    G.dfs(0);
    vl dp(2, 0);
    rep(i, n * 2) {
        if (G.visited[i] == 1)dp[i % 2]++;
    }

    x=dp[0];
    y=dp[1];
    k=x+y-n;
    ans=k*(n-k)+k*(k-1)/2+(x-k)*(y-k)-m;

    cout << ans << endl;
}


#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<stdio.h>
#include<locale.h>
#include<set>
#include<stack>
#include<queue>
using namespace std;

int main()
{
 int d,g,p[11],c[11],scr[11][1001]={};
 scanf("%d %d",&d,&g);
 int sm=0;
 for(int i=1;i<=d;i++)
 {
	scanf("%d %d",&p[i],&c[i]);
sm+=p[i];
 }
 for(int i=1;i<=d;i++)
 {
	for(int j=0;j<=sm;j++)
	{
	 //scr[i][j]の最大値はscr[i-1][j]かscr[i-1][j-N]+N*i*100かコンプリートが入るやつか
	 	for(int k=0;k<=min(j,p[i]);k++)
		{
		 if(k==p[i]){scr[i][j]=max(scr[i-1][j],(scr[i-1][j-k]+i*100*k+c[i]));}
		 else{scr[i][j]=max(scr[i-1][j],(scr[i-1][j-k]+i*100*k));}
		}
	}
 }
 for(int i=0;i<=1000;i++)
 {
	if(scr[d][i]>=g){printf("%d",i);break;}
 }
}