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

pair<long long, long long> range(long long b, long long c) {
    long long n = c / 2;
    if (c % 2 == 0) {
        if (c == 0) return {b, b};
        else return {b - n, b + n - 1};
    } else {
        return {-b - n, -b + n};
    }
}

int main() {
    long long b, c;
    cin >> b >> c;
    auto [l1, r1] = range(b, c);
    auto [l2, r2] = range(b, c - 1);
    long long ans = (r1 - l1 + 1) + (r2 - l2 + 1) - max(0LL, min(r1, r2) - max(l1, l2) + 1);
    cout << ans << '\n';
}

#include <bits/stdc++.h>
using namespace std;
//using namespace atcoder;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define pb push_back
#define fi first
#define se second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void chOut(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using v_bool = vector<bool>;
using v_Pii = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;

signed main(){

    int B, C; cin >> B >> C;
    int ans = 0;
    if(B > 0){
        //[-B,B]
        if(C >= 2 * B) ans++;
        ans += min(B, C / 2 + 1);
        ans += min(B, (C - 1) / 2 + 1);
        //(-INF,-B)
        ans += (C - 1) / 2;
        //(B,INF)
        if(C >= 4) ans += (C - 4) / 2 + 1;
    }else if(B < 0){
        //(-INF,B]
        ans += C / 2 + 1;
        //[-B,INF)
        ans += (C - 1) / 2 + 1;
        //(B,-B)
        if(C >= 2 * (-B) + 1) ans++;
        ans += min(-B - 1, (C - 1) / 2);
        if(C >= 2) ans += min(-B - 1, (C - 2) / 2);

    }else if(B == 0){
        ans += C / 2 + 1;
        ans += (C - 1) / 2;
    }
    Out(ans);

    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define setbits(x)          __builtin_popcountll(x)
#define lp(a,n) for(ll i=a; i<n; i++)
#define lpi(a,n) for(int i=a; i<n; i++)
#define w(t) int t; cin>>t; while(t--)
#define vi vector<int>
#define vll vector<ll>
#define pll pair<ll, ll>
#define pii pair<int, int>
#define inf 1e9
#define LB lower_bound
#define UB upper_bound
const int mod = 1000000007;
using namespace std;
ll gcd(ll a,ll b){
    if(a==0)return b;
    return gcd(b%a,a);
}
ll lcm(ll a, ll b){
    return (a*b)/gcd(a,b);
}

int prime[100007];
void SieveOfEratosthenes(int n)
{
    memset(prime, -1, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {

        if (prime[p] == -1)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = p;
        }
    }

}
int lps(string s){
    int len = 0;
    int n = s.length();
    int dp[n];
    dp[0] = 0;
    for(int i=1; i<n; i++){
        if(s[i] == s[len]){
            len++;
            dp[i] = len;
            continue;
        }
        if(len!=0){
            len = dp[len-1];
            i--;
            continue;
        }
        dp[i]=0;
    }
    return dp[n-1];
}

ll power(unsigned ll x,unsigned  ll y)
{
    ll res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = res*x;

        y = y>>1;
        x = x*x;
    }
    return res;
}

//to calculate p1^x  *  p2^x2  *p3^x3 ----------
//i.e. prime factorization and store pi and xi in vector
vector<pair<ll, ll>> pFactor;

void factorize(long long n)
{
    int count = 0;

    // count the number of times 2 divides
    while (!(n % 2)) {
        n >>= 1; // equivalent to n=n/2;
        count++;
    }

    // if 2 divides it
    if (count)
        pFactor.pb({2,count});

    // check for all the possible numbers that can
    // divide it
    for (long long i = 3; i <= sqrt(n); i += 2) {
        count = 0;
        while (n % i == 0) {
            count++;
            n = n / i;
        }
        if (count)
            pFactor.pb({i,count});
    }

    // if n at the end is a prime number.
    if (n > 2)
        pFactor.pb({n,1});
}

int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
    ll n;
    cin>>n;
    vector<string> v(n+1);
    int mx = -1;
    lp(1,n+1){
        cin>>v[i];
        if(v[i]=="OR"){
            mx = i;
        }
    }

    ll ans = 0;
    for(int i=n; i>=1; i--){
        if(v[i]=="AND"){
            continue;
        }
        ans += (1ll<<i);
    }
    ans++;
    cout<<ans<<endl;
}

#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(),v.end()
#define MP make_pair
#define MT make_tuple
typedef int64_t ll;
#define PA pair<ll,ll>
#define TU tuple<ll,ll,ll>
#define vi vector<ll>
#define vii vector<vector<ll> >
#define rep(i,n) for(ll (i)=0; (i)<(ll)(n); (i)++)
#define rep2(i,m,n) for(ll (i)=(m); (i)<(ll)(n); (i)++)
const ll INF = 1ll<<30;
const ll INF2 = 1ll<<32;

int main() {
  ll n;
  cin >> n ;
  vector<bool> b(n,true);
  //ANDならfalse、ORならtrue
  rep(i,n) {
    string s;
    cin >>s;
    if(s=="AND") b.at(i) =false;
  }

  ll ans =0;
  for(ll i=n-1; i>=0; i--) {
    if(b.at(i)) ans += 1ll<<i+1;
  }
  cout << ans+1 << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define lli long long int
#define tc int t;cin>>t;while(t--)
#define all(x) x.begin(),x.end()
#define f first
#define s second
#define pb push_back
#define vi vector<int>
#define vll vector<lli>
#define vpi vector<pair<int,int> >
#define vpll vector<pair<lli,lli> >
#define vvi vector<vector<int> >
#define vvll vector<vector<lli> >
#define maxn 100005

int main(){
    fastio;
    int n;
    string s;
    cin>>n>>s;
    int ans=0;
    for(int i=0;i<n;i++)
    {
        int fra=0,frt=0,frc=0,frg=0;
        for(int j=i;j<n;j++){
            if(s[j]=='A') fra++;
            if(s[j]=='T') frt++;
            if(s[j]=='C') frc++;
            if(s[j]=='G') frg++;
            if(fra==frt and frc==frg)
            ans++;
        }
    }
    cout<<ans<<"\n";
    return 0;
}

#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <map>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    int n;
    string s;
    cin >> n >> s;
    pair<int, int> cnt = {0, 0};
    map< pair<int, int>, int > m;
    m[cnt] = 1;
    for (int i = 0; i < n; ++i) {
        switch (s.at(i)) {
            case 'A': ++cnt.first; break;
            case 'T': --cnt.first; break;
            case 'C': ++cnt.second; break;
            case 'G': --cnt.second; break;
        }
        ++m[cnt];
    }
    cout << accumulate(m.begin(), m.end(), 0, [](int init, pair< pair<int, int>, int> i) {
        return init += i.second * (i.second - 1) / 2;
    }) << endl;
    return 0;
}


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

int main() {
    string s;
    cin >> s;
    int n = s.length();
    vector<int> cnt(26);
    ll ans = 0;

    for (int i = n - 1; ~i; i--) {
        int m = n - i;
        int c = s[i] - 'a';
        cnt[c]++;
        if (i > n - 3) continue;
        if (s[i] == s[i + 1] && s[i] != s[i + 2]) {
            ans += m - cnt[c];
            for (int i = 0; i < 26; i++) cnt[i] = 0;
            cnt[c] = m;
        }
    }
    cout << ans;
}

#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define REPO(i,x) for(int i=x-1;i>=0;i--)
#define T int tc; cin>>tc;while(tc--)
#define READ   freopen("input.txt","r", stdin)
#define mem(a,b)     memset(a, b, sizeof(a))
#define lcm(a, b) ((a / __gcd(a, b) ) * b)
#define PI 2*acos(0.0)
#define pb push_back
#define eb emplace_back
#define ll long long
#define MAX 1e9
#define inf 1e18
#define MOD 1000000007
#define n0  cout<<"\n"
#define N 200001
int main()
{
    int n; string s;cin>>s; n=s.size(); int cnt[26]={0}; ll an=0;
    for(int i=n-1;i>=0;i--)
    { cnt[s[i]-'a']++;
        if(i<n-1)
        {
            if(s[i]==s[i+1])
            {
                 an+=n-i-cnt[s[i]-'a'];
                 memset(cnt,0,sizeof(cnt)); cnt[s[i]-'a']=n-i;
            }
        }
    } cout<<an<<endl;
}


#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)
#define bit(n,k) ((n>>k)&1) //nのk　bit目
#define vec(T) vector<T>
#define vvec(T) vector<vector<T>>
using ll = long long;
using P = pair<int,int>;
using Pll = pair<ll,ll>;

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 ll llINF = 1LL << 60;
const int iINF = 1e9;

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

struct Solver{

    void solve(){
        ll K;
        cin >>K;

        ll ans=0;
        rep1(a,K){
            rep1(d,K){
                if(a*d>K) break;
                for(ll b=1; b*b<=d; b++){
                    if(d%b!=0) continue;
                    if(d/b==b) ans++;
                    else ans+=2;
                }
            }
        }
        cout << ans << endl;

        /*
        ll ans = 0;
        rep1(kk,K){
            //cout << kk << endl;
            rep1(a,kk){
                if(kk%a!=0) continue;
                ll l=kk/a;
                for(ll b=1; b*b<=l; b++){
                    if(l%b!=0) continue;
                    if(l/b==b) ans++;
                    else ans+=2;
                    //cout << a << ","<<b <<"," << l/b<<" : " << ans << endl;
                }
            }
        }
        cout << ans << endl;
        */
    }
};

int main(){
    int testcasenum=1;
    //cin >> testcasenum;
    rep1(ti,testcasenum){
        Solver solver;
        solver.solve();
    }
    return 0;
}

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

template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define PB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define ALL(a)  (a).begin(),(a).end()
#define CLR(a) memset((a), 0 ,sizeof(a))
//constant
//--------------------------------------------
//clear memory

struct edge{LL to,cost,k;};
typedef pair<LL,LL> P;//firstは最短距離,secondは頂点番号

const int MAX_V=1e5+3;
const LL INF=LONG_MAX;

int main(){
    int K;
    cin>>K;
    LL res=0;
    for(LL A=1;A<=K;A++){
        for(LL B=1;A*B<=K;B++){
            for(LL C=1;A*B*C<=K;C++){
                if(A*B*C<=K)res++;
            }
        }
    }
    cout<<res<<endl;
    return 0;
}


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

  int v,t,s,d;
    cin>>v>>t>>s>>d;
    int st=v*t;
    int en=v*s;
    if(d<st||d>en)
    cout<<"Yes";
    else
    cout<<"No";
    return 0;
}

#include<iostream>

using namespace std;

int main()
{
   long long n,m,t;
   cin>>n>>m>>t;
   long long answer = n;
   int start,end;
   cin>>start>>end;
   answer -= (start);
   if(answer<1){
      cout<<"No"<<endl;
      return 0;
   }
   answer+= (end-start);
   if(answer>n){
      answer=n;
   }
   for(int i = 1 ; i < m ; i++){
      long long l = end;
      cin>>start>>end;
      answer-=(start-l);
      if(answer<1){
         cout<<"No"<<endl;
         return 0;
      }
      answer+= (end-start);
      if(answer>n){
         answer=n;
      }
   }
   answer-=(t-end);
   answer<=0 ? cout<<"No":cout<<"Yes"<<endl;
   return 0;
}


#include<bits/stdc++.h>
#define N 60
#define A(i,m,n) for(int i=m;i<=n;++i)
using namespace std;
typedef long long LL;
const LL mod=998244353;
int a[N][N],n,k;
inline bool check1(int x,int y){
	A(i,1,n)if(a[x][i]+a[y][i]>k)return 0;
	return 1;
}
inline bool check2(int x,int y){
	A(i,1,n)if(a[i][x]+a[i][y]>k)return 0;
	return 1;
}
LL fc[N];
int fa[N],siz[N];
int findfa(int x){
	if(fa[x]!=x)fa[x]=findfa(fa[x]);
	return fa[x];
}
inline void mer(int x,int y){
	int tx=findfa(x),ty=findfa(y);
	if(tx!=ty){
		fa[tx]=ty;
		siz[ty]+=siz[tx];
	}
}
int main(){
	cin>>n>>k;
	fc[1]=1;
	A(i,2,n)fc[i]=(fc[i-1]*i)%mod;
	A(i,1,n){
		A(j,1,n)cin>>a[i][j];
		fa[i]=i;
		siz[i]=1;
	}
	A(i,1,n)
		A(j,i+1,n)
			if(findfa(i)!=findfa(j)&&check1(i,j)==1)mer(i,j);
	LL ans=1;
	A(i,1,n)
		if(findfa(i)==i)ans=ans*fc[siz[i]]%mod;
	A(i,1,n)fa[i]=i,siz[i]=1;
	A(i,1,n)
		A(j,i+1,n)
			if(findfa(i)!=findfa(j)&&check2(i,j)==1)mer(i,j);
	A(i,1,n)
		if(findfa(i)==i)ans=ans*fc[siz[i]]%mod;
	printf("%lld\n",ans);
	return  0;
}

#include<bits/stdc++.h>
#include<iostream>
#include<map>
#include<math.h>
#include<string>
#include<string.h>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
#define _GLIBCXX_DEBUG
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
using namespace std;
using ll=long long;
const ll INF=5000000000000;
const ll dx[8]={1,0,-1,0,1,1,-1,-1};
const ll dy[8]={0,1,0,-1,1,-1,1,-1};
ll mod(ll x,ll m){return x & m;}
ll modinv(ll a,ll m){ll b=m,u=1,v=0;while(b){ll t=a/b;a-=t*b;swap(a,b);u-=t*v;swap(u,v);}u%=m;if(u<0){u+=m;}return u;}
ll modpow(ll a,ll n,ll m){ll res=1;while(n>0){if(n&1){res=res*a%m;}a=a*a%m;n>>=1;}return res;}
ll npow(ll a,ll n){ll res=1;while(n>0){if(n&1){res=res*a;}a=a*a;n>>=1;}return res;}
ll yaku(ll x){ll cnt=0;for(int i=1;i*i<=x;i++){if(x%i==0){if(i==x/i){cnt++;}else{cnt+=2;}}}return cnt;}
ll modwaru(ll a, ll b, ll m){a%=m;return a*modinv(b,m)%m;}
ll gcd(ll x, ll y){if(x%y==0){return y;}else{return gcd(y, x % y);}}
ll lcm(ll a, ll b){return a/gcd(a, b)*b;}
struct UnionFind{vector<ll>par;UnionFind(ll N):par(N){for(ll i=0;i<N;i++)par[i]=i;}ll root(ll x){if(par[x]==x){return x;}return par[x]=root(par[x]);}void unite(ll x,ll y){ ll rx=root(x);ll ry=root(y);if(rx==ry){return;}par[rx]=ry;}bool same(ll x,ll y){ll rx=root(x);ll ry=root(y);return rx==ry;}};

int main(){
    ll N, K;
    cin >> N >> K;
    vector<vector<ll>> A(N, vector<ll>(N));
    UnionFind iti(N), ni(N);
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++) cin >> A[i][j];
    }
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            if(i == j) continue;
            bool b = true;
            for(int k = 0; k < N; k++){
                if(A[i][k] + A[j][k] > K) b = false;
            }
            if(b){iti.unite(i, j);}
        }
    }
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            if(i == j) continue;
            bool b = true;
            for(int k = 0; k < N; k++){
                if(A[k][i] + A[k][j] > K) b = false;
            }
            if(b){ni.unite(i, j);}
        }
    }
    ll ans1 = 1, ans2 = 1, mo = 998244353;
    map<ll,ll> cnt1, cnt2;
    for(int i = 0; i < N; i++){
        cnt1[iti.root(i)]++;
        cnt2[ni.root(i)]++;
    }
    for(pair<ll,ll> a : cnt1){
        for(int i = 1; i <= a.second; i++){
            ans1 *= i;
            ans1 %= mo;
        }
    }
    for(pair<ll,ll> a : cnt2){
        for(int i = 1; i <= a.second; i++){
            ans2 *= i;
            ans2 %= mo;
        }
    }
    cout << ans1 * ans2 % mo << endl;
}


#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	int n = ri();
	int a[n];
	for (auto &i : a) i = ri();

	int res = 2000000000;
	for (int i = 0; i < 1 << (n - 1); i++) {
		int xored = 0;
		int ored = 0;
		for (int j = 0; j <= n; j++) {
			if (j < n) ored |= a[j];
			if (j == n || (i >> j & 1)) xored ^= ored, ored = 0;
		}
		res = std::min(res, xored);
	}

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

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

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 INF = 1LL << 60;

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

  REP(i, 0, n-3){
    REP(j, i+1, n-2){
      REP(k, j+1, n-1){
        if((y[j]-y[i])*(x[k]-x[j]) == (x[j]-x[i])*(y[k]-y[j])){
          cout << "Yes" << endl;
          return 0;
        }
      }
    }
  }

  cout << "No" << endl;

  return 0;
}


#include <bits/stdc++.h>
// #include <atcoder/all>
// using namespace atcoder;
using namespace std;
#define rep2(i, m, n) for (int i = (m); i < (n); ++i)
#define rep(i, n) rep2(i, 0, n)
#define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i)
#define drep(i, n) drep2(i, n, 0)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#ifdef LOCAL
void debug_out() { cerr << endl; }
template <class Head, class... Tail> void debug_out(Head H, Tail... T) { cerr << ' ' << H; debug_out(T...); }
#define debug(...) cerr << 'L' << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define dump(x) cerr << 'L' << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif
template<class T> using V = vector<T>;
template<class T> using P = pair<T, T>;
using ll = long long;
using ld = long double;
using Vi = V<int>;  using VVi = V<Vi>;
using Vl = V<ll>;   using VVl = V<Vl>;
using Vd = V<ld>;   using VVd = V<Vd>;
using Vb = V<bool>; using VVb = V<Vb>;
using Pi = P<int>;
using Pl = P<ll>;
using Pd = P<ld>;
template<class T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
template<class T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }
template<class... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }
template<class T> inline int sz(const T &x) { return x.size(); }
template<class T> inline bool chmin(T &a, const T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T &a, const T b) { if (a < b) { a = b; return true; } return false; }
template<class T1, class T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; }
template<class T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
template<class T> inline void deduplicate(vector<T> &a) { sort(all(a)); a.erase(unique(all(a)), a.end()); }
template<class T> inline int count_between(const vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline ll cDiv(const ll x, const ll y) { return (x+y-1) / y; } // ceil(x/y)
inline int fLog2(const ll x) { assert(x > 0); return 63-__builtin_clzll(x); } // floor(log2(x))
inline int cLog2(const ll x) { assert(x > 0); return (x == 1) ? 0 : 64-__builtin_clzll(x-1); } // ceil(log2(x))
inline int popcount(const ll x) { return __builtin_popcountll(x); }
inline void fail() { cout << -1 << '\n'; exit(0); }
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
// const int INF  = (1<<30) - 1;
// const ll INFll = (1ll<<60) - 1;
// const ld EPS   = 1e-10;
// const ld PI    = acos(-1.0);

int main() {
  char s, t; cin >> s >> t;
  if (s == 'Y') t +=  'A' - 'a';
  cout << t << '\n';
}

//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define mod 1000000007
#define maxn 100011
#define el "\n"
#define pi acos(-1.0)
using namespace std;
#define lcm(a,b) (a/__gcd(a,b))*b
#define ios  ios_base::sync_with_stdio(false);   cin.tie(NULL)
int main()
{
    ios;
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //cout<<fixed<<showpoint<<setprecision(7);
    char s,t,a;
    cin>>s>>t;
    if(s=='Y'){
            if(t=='a') a='A';
            else  if(t=='b') a='B';
            else a='C';
    }
    else a=t;
    cout<<a<<el;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD = 1e9 + 7;
ll modpow(ll a, ll b){
	ll ans = 1;
	while (b > 0){
		if (b % 2 == 1){
			ans *= a;
			ans %= MOD;
		}
		a *= a;
		a %= MOD;
		b /= 2;
	}
	return ans;
}
ll modinv(ll a){
	return modpow(a, MOD - 2);
}
vector<ll> mf = {1};
vector<ll> mfi = {1};
ll modfact(ll n){
	if (mf.size() > n){
		return mf[n];
	} else {
		for (ll i = mf.size(); i <= n; i++){
			ll next = mf.back() * i % MOD;
			mf.push_back(next);
			mfi.push_back(modinv(next));
		}
		return mf[n];
	}
}
ll modfactinv(ll n){
	if (mfi.size() > n){
		return mfi[n];
	} else {
		return modinv(modfact(n));
	}
}
ll modbinom(ll n, ll k){
	if (n < 0 || k < 0 || k > n){
		return 0;
	} else {
		return modfact(n) * modfactinv(k) % MOD * modfactinv(n - k) % MOD;
	}
}
int main(){
  ll N, M, K;
  cin >> N >> M >> K;
  if (N > M + K){
    cout << 0 << endl;
  } else {
    ll ans = modbinom(N + M, N);
    ll a = N - K - 1, b = K + M + 1;
    ans -= modbinom(a + b, a);
    if (ans < 0){
      ans += MOD;
    }
    cout << ans << endl;
  }
}

#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define pii pair<ll,ll>
#define inf 1000000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define autoitr(x,it) for(auto it = x.rbegin(); it != x.rend(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>

using namespace std;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());

int main()
{
  FAST/**/

   ll n = 4;

   ll arr[n];
   rep(n)
        cin>>arr[i];

   ll lim = (1ll<<(n));
   bool pos = 0;
   repi(mask,lim)
   {
       ll sum = 0;
       ll sum1 = 0;
       repi(j,n)
       {
           sum1+=arr[j];
           if((1ll<<j)&mask)
                sum+=arr[j];
       }
       //cout<<sum<<" "<<sum1<<"\n";
       if(sum == sum1/2 && sum1%2 == 0)
            pos = 1;
   }

   if(pos)
        cout<<"Yes\n";
   else cout<<"No\n";

  return 0;

}


/*
    Code written by Talant I.D.
*/

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

//~ using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
//~ typedef tree <ll, null_type, less_equal <ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define precision(n) fixed << setprecision(n)
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
#define eps (double)1e-9
#define PI 2*acos(0.0)
#define endl "\n"
#define sz(v) int((v).size())
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define OK cout << "OK" << endl;

const int mod = 998244353;

ll mode(ll a) {
    while (a < 0) {
        a += mod;
    }
    return a % mod;
}

ll subt(ll a, ll b) {
    return mode(mode(a)-mode(b));
}

ll add(ll a, ll b) {
    return mode(mode(a)+mode(b));
}

ll mult(ll a, ll b) {
    return mode(mode(a)*mode(b));
}

ll binpow(ll a, ll b) {
    ll res = 1;
    while (b) {
        if (b&1) res = mult(res, a);
        a = mult(a, a);
        b >>= 1;
    }
    return res;
}

ll dp[10003][103];
ll fact[10003];

int main() {
    do_not_disturb

    fact[0] = fact[1] = 1;
    for (ll i = 2; i < 10003; i++) {
        fact[i] = mult(fact[i-1], i);
    }
    dp[0][0] = 1;

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

    for (auto to : a) {
        for (int i = 5000; i >= to; i--) {
            for (int j = 0; j < 100; j++) {
                dp[i][j+1] = add(dp[i][j+1], dp[i-to][j]);
            }
        }
    }

    ll ans = 0;
    ll sum = 0;
    for (auto to : a) sum += to;
    if (sum&1) {
        cout << 0;
        return 0;
    }
    sum /= 2;

    for (int i = 0; i <= 100; i++) {
        ans = add(ans, mult(dp[sum][i], mult(fact[i], fact[n-i])));
    }

    cout << ans;

    return 0;
}

#include <bits/stdc++.h>

using namespace std;
using int64 = long long;

#define endl '\n'
#define INF  0x3f3f3f3f
#define LINF  1LL<<62
#define MSET(a) memset(a, 0, sizeof(a))
#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define key first
#define val second
#define pb push_back

template <typename T> bool ckmax(T &x, T y) {return x < y? (x = y, 1): 0;}
template <typename T> bool ckmin(T &x, T y) {return x > y? (x = y, 1): 0;}

inline int lc(int x) { return (x << 1);}
inline int rc(int x) { return (x << 1) + 1;}
inline int lowbit(int x) { return x&(-x);}

void extend_gcd(int64 a, int64 b, int64& d, int64& x, int64& y) {
  if (b) {
    extend_gcd(b, a%b, d, y, x);
    y -= a/b*x;
  } else d = a, x = 1, y = 0;
}

auto power(int64 a, int64 b, int64 mod) {
  int64 res = a % mod;
  while(b) {
    if (b&1) res = res * a % mod;
    a = a*a % mod;
    b >>= 1;
  }
  return res;
}

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

void Main();

int main() {
  SetupIo();
  Main();
  return 0;
}

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

const int N = 2e4 + 10;
const int64 MOD = 998244353;

int n, m;
int a[N];

int64 dp[110][N];

int64 fac[N];

void pre() {
  fac[0] = 1;

  for(int i = 1; i < N; ++i) {
    fac[i] = fac[i-1]*i % MOD;
  }
  //for(int i = 0; i < 20; ++i) cout << fac[i] << endl;
}

int64 Ans() {
  int sum = 0;
  for(int i = 0; i < n; ++i) sum += a[i];

  if(sum % 2 == 1) return 0;

  int s = sum / 2;
  memset(dp, 0, sizeof(dp));
  dp[0][0] = 1;

  for(int i = 1; i <= n; ++i) {
    int v = a[i-1];
    for (int k = i; k >= 1; --k) {
      for(int j = s; j - v >= 0; --j) {
        dp[k][j] += dp[k-1][j-v];
        if (dp[k][j] >= MOD) dp[k][j] -= MOD;
      }
    }
  }

  int64 ans = 0;
  for(int i = 0; i <= n; ++i) {
    if (dp[i][s] != 0) {
      //cout << i << " " << s << ": " << dp[i][s] << endl;
      int64 x = fac[i]*fac[n-i] % MOD;
      ans += x*dp[i][s]%MOD;
      ans %= MOD;
    }
  }
  return ans;
}

void Main() {
  pre();
  cin >> n;
  for(int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  cout << Ans() << endl;
}


#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

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

	int H, W, X, Y;
	cin >> H >> W >> X >> Y;

	string S[100];
	rep(i, H) cin >> S[i];

	X--;
	Y--;
	int kotae = 1;
	for (int i = X + 1; i < H; i++) {
		if (S[i][Y] == '#') break;
		else kotae++;
	}
	for (int i = X - 1; i >= 0; i--) {
		if (S[i][Y] == '#') break;
		else kotae++;
	}
	for (int i = Y + 1; i < W; i++) {
		if (S[X][i] == '#') break;
		else kotae++;
	}
	for (int i = Y - 1; i >= 0; i--) {
		if (S[X][i] == '#') break;
		else kotae++;
	}

	co(kotae);

	Would you please return 0;
}

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

int main(){
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int ans;

	ans = min(a, b);
	ans = min(ans, c);
	ans = min(ans, d);

	cout << ans << endl;
}


#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front

typedef long long ll;
typedef unsigned long long ull;
typedef short int si;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int nMax = 1e6+5;
const ll mod = 1e9+7;

string s,x;

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

	cin >> s;
	for (int i=0;i<s.size();i++) {
		if (s[i] == '.')
			break;
		x += s[i];
	}
	cout << x << "\n";

	return 0;
}

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

int main() {
    string s;
    cin>>s;
    if(s.find('.') != s.npos) {
        s=s.substr(0,s.find('.'));
    }
    cout<<s<<endl;
}


#include <bits/stdc++.h>
#define for0(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define forc(i, l, r) for (int i = (int)(l); i <= (int)(r); ++i)
#define forr0(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define forr1(i, n) for (int i = (int)(n); i >= 1; --i)

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

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

#define tr(c,i) for(__typeof__((c)).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define sz(a) int((a).size())

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef double ld;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a,b;
    cin>>a>>b;
    double c = (double)(a-b)/a * 100;
    cout<<setprecision(24)<<c<<endl;
    return 0;
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

template <class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define int long long int
#define pb push_back
#define pi pair<int, int>
#define pii pair<int, pi>
#define fir first
#define sec second
#define MAXN 2002
#define mod 1000000007

int modpow(int x, int y)
{
  int z = 1;
  while (y)
  {
    if (y & 1)
      z = (z * x) % mod;
    x = (x * x) % mod;
    y >>= 1;
  }
  return z;
}
int subtract(int a, int b)
{
  return (a - b < 0) ? a - b + mod : a - b;
}
int multiply(int x, int y)
{
  return (x * y) % mod;
}
signed main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, p;
  cin >> n >> p;
  int ans = multiply(subtract(p, 1), modpow(subtract(p, 2), subtract(n, 1)));
  cout << ans << endl;
  return 0;
}
// prefix sum nunca pode dar 0
// primeiro cara = (p - 1) possibilidades
// segundo cara = (p - 2) possibilidades
// terceiro cara = (p - 2) possibilidades
// ...
// (p - 1) * (p - 2)^n - 1


#include<bits/stdc++.h>
#include <string>
#include<vector>
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
int main()
{
  	int n;
  	cin>>n;
  	int a[n],i;
  	for(i=0;i<n;i++)
      cin>>a[i];

  	set<int> s(a,a+n);
  	if(s.size()==n)
      cout<<"Yes";
  	else
      cout<<"No";
	return 0;
}

// ConsoleApplication1.cpp : Defines the entry point for the console application.
//

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

#define MAXCHAR 255
#define ll long long

using namespace std;
const ll dividend = 1000000007;
const ll limit = pow(10, 18);
const ll bigNum = pow(10, 9);
const int intMax = 2147483647;

ll funcComb(int n, int k)
{
	ll output = 1;
	int sum = n + k;
	vector<int> dividends;
	for (int i = 0; i < k; i++)
	{
		dividends.push_back(k - i);
	}
	for (int i = 0; i < k; i++)
	{
		output *= sum - i;
		for (auto it = dividends.begin(); it != dividends.end(); it++)
		{
			if (*it == 0)
				continue;
			if (output % *it == 0)
			{
				output /= *it;
				*it = 0;
			}
		}
		if (output > dividend)
		{
			output %= dividend;
		}
	}

	return output;
}

ll funcPow(int n, int r)
{
	ll ret = 1;
	for (int i = 1; i <= r; i++)
	{
		ret *= n;
		if (ret > dividend)
			ret %= dividend;
	}
	return ret;
}

vector<int> A;
vector<int> Ns;

int main()
{
	int N;
	cin >> N;
	for (int i = 0; i < N; ++i)
	{
		int a;
		cin >> a;
		A.push_back(a);
		Ns.push_back(i + 1);
	}
	sort(A.begin(), A.end());
	if (A == Ns)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}


//* Jai shree Ram
#include <bits/stdc++.h>
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define lli                                 long long int
#define ll                                  long long
#define FOR(i,a,b)                          for(int i=(a);i<(b);i++)
#define vi                                  vector<int>
#define vll                                 vector<ll>
#define all(a)                              a.begin(),a.end()
#define sz(a)                               (int)a.size()
#define pb                                  push_back
#define ppb                                 pop_back
#define pf                                  push_front
#define fr                                  first
#define sc                                  second
#define uniq(v)                             (v).erase(unique(all(v)),(v).end())
using namespace std;

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

template<typename T,typename T1>T amax(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T amin(T &a,T1 b){if(b<a)a=b;return a;}
// __builtin_popcountll(x);
// __builtin_clz(x) // Count Leading zeros
// __builtin_ctz(x) // Trailing zeros
const int MM = 998244353;
const int mod = 1e9 + 7;
const int INF = 1e9 + 5;
const int N = 1e5 + 5;

void solve()
{
    int n;
    cin >> n;
    vll a(n);
    map<ll,ll> mpp;
    for(ll &x : a) {
        cin >> x;
        mpp[x%200]++;
    }
    ll ans = 0;
    for(auto x : mpp) {
        ans += x.sc*(x.sc-1)/2;
    }
    cout << ans << "\n";

}

signed main()
{
    ios;
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #ifdef SIEVE
          sieve();
    #endif
    #ifdef NCR
          init();
    #endif
    int t;
    t=1;
    // cin>>t;
    while(t--)
    {
        solve();
    }
}
/* stuff you should look for
  * int overflow, array bounds
  * special cases (n=1?)
  * remember out of bounds case mainly in if else
  * do smth instead of nothing and stay organized
  * WRITE STUFF DOWN
*/

#include <vector>
#include <stdio.h>
using namespace std;
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll = long long;
using P = pair<int,int>;
#define pcnt __builtin_popcount//1ビットがたっている数を数える

int main() {
	int n;
	cin >> n;
	int a[n];
	ll b[200] = {0};
	rep(i,n)
	{
		cin >> a[i];
		b[a[i]%200]++;
	}

	ll ans = 0;
	rep(i,200)
	{
		ans += (b[i]*(b[i]-1))/2;
	}
	cout << ans << endl;
	return 0;
}


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

int main() {
    int n;
    string s,t;
    cin >> n >> s >> t;

    vector<int> sz,tz;
    rep(i,n){
        if(s[i] == '0') sz.push_back(i);
        if(t[i] == '0') tz.push_back(i);
    }

    int ans = 0;
    if(sz.size() != tz.size()) cout << -1 << endl;
    else{
        rep(i,sz.size()){
            if(sz[i] != tz[i]) ans++;
        }
        cout << ans << endl;
    }
}

#include <iostream>
#include <string>
#include <vector>
int main()
{
    int N;
    std::string S, T;
    std::cin >> N >> S >> T;
    int SS = 0, TT = 0;
    for (int i = N - 1; i >= 0; i--)
    {
        if (S[i] == '1')
        {
            SS++;
        }
    }
    for (int i = N - 1; i >= 0; i--)
    {
        if (T[i] == '1')
        {
            TT++;
        }
    }

    if (SS != TT)
    {
        std::cout << "-1" << std::endl;
        return 0;
    }

    int AT = 0, COUNT = 0, tmp;
    while (AT < N)
    {

        if (S[AT] == T[AT])
        {
            AT++;
            continue;
        }
        else
        {
            if (S[AT] == '1')
            {
                tmp = AT + 1;
                while (S[tmp] == '1')
                {

                    tmp++;
                }
                S[AT] = '0';
                S[tmp] = '1';
                COUNT++;
                AT++;
            }
            else
            {
                tmp = AT + 1;
                while (T[tmp] == '1')
                {

                    tmp++;
                }
                T[AT] = '0';
                T[tmp] = '1';
                COUNT++;
                AT++;
            }
        }
    }

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


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

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }

  friend ostream& operator<<(ostream& os, const mint& m){
    os << m.x;
    return os;
  }
};

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i=0;i<N;i++)cin >> A[i];
    vector<vector<mint>> dp1(N+1,vector<mint>(2)),dp2(N+1,vector<mint>(2));
    dp1[1][0] = 1;
    dp2[1][0] = A[0];
    for(int i=2; i<=N; i++){
        dp1[i][0] += dp1[i-1][0] + dp1[i-1][1];
        dp1[i][1] += dp1[i-1][0];
        dp2[i][0] += dp2[i-1][0] + dp2[i-1][1]  + dp1[i][0]*A[i-1];
        dp2[i][1] += dp2[i-1][0] - dp1[i][1]*A[i-1];
    }
    cout << dp2[N][0] + dp2[N][1] << endl;
    return 0;
}

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

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

int main(){
	ll n;
	cin >> n;
	vector<ll> a(n);
	ll sigma = 0;
	ll p = 0;
	ll maxd = 0;
	ll ans = 0;
	for(ll i=0;i<n;i++){
		cin >> a.at(i);
		sigma += a.at(i);
		maxd = max(maxd,sigma);
		ans = max(ans,p+maxd);
		p += sigma;
		ans = max(ans,p);
	}
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>
#define f first
#define s second
#define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define all(s) begin(s), end(s)
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(s) int(s.size())
#define ENDL '\n'
#define vv(type, name, h, ...) vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...) vector<vector<vector<type>>> name(h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
using namespace std;
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
typedef long long lli;
typedef pair<int,int> ii;
typedef vector<int> vi;
#define deb(x) cout << #x": " << (x) << endl;

lli gcd(lli a, lli b){return (b?gcd(b,a%b):a);}
lli lcm(lli a, lli b){ if(!a || !b) return 0; return a * b / gcd(a, b); }
int popcount(lli x) { return __builtin_popcountll(x); }

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// int rnd(int n){return uniform_int_distribution<int>(0, n-1)(rng);}

lli poww(lli a, lli b){
	lli res =1;
	while(b){ if(b&1) res = res * a; a = a*a; b/=2; }
	return res;
}

vvc<int> graph(int n, int m, bool dir=1){
	vv(int,v,n+1,0);
	fore(i,0,m){
		int a,b; cin>>a>>b;
		v[a].pb(b);
		if(dir)v[b].pb(a);
	}
	return v;
}
template <typename T> static constexpr T inf = numeric_limits<T>::max() / 2;
// ---- コーディングはここから！ ('-')7

void solve(){
	int n,m; cin>>n>>m;
	vv(int,v,n,n,inf<int>);
	fore(i,0,m){
		int a,b,c; cin>>a>>b>>c;a--,b--;
		v[a][b]=min(v[a][b],c);
	}
	vv(ii,g,n+1);
	fore(i,0,n)fore(j,0,n)if(v[i][j]!=inf<int>)g[i].pb({j,v[i][j]});

	auto dij=[&](int a){
		using pp  = pair<int,lli>;
		priority_queue<pp>q;
		q.push({0,n});
		g[n]=g[a];
		vc<lli>dp(n+1,inf<lli>);
		dp[n]=0;
		while(!q.empty()){
			auto p=q.top(); q.pop();
			auto [y,x]=p;
			y*=-1;
			if(y!=dp[x])continue;
			if(x==a)return y;
			for(auto [i,j]:g[x])if(dp[i]>y+j){
				dp[i]=y+j;
				q.push({-dp[i],i});
			}
		}
		return -1;
	};
	fore(i,0,n)cout<<dij(i)<<ENDL;

}

int main(){_
	//int t; cin>>t; while(t--)
	solve();
}

//BISMILLAHIR RAHMANIR RAHIM
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define mem(a, b) (memset(a, b, sizeof(a)))
#define pb push_back
#define mk make_pair
#define ff first
#define ss second
#define PI acos(-1)
#define INF 2147483647
#define MOD 1000000007
#define MAX 2005
using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ii, int> pii;
typedef vector<ii> vii;
typedef priority_queue<int,vector<int>,greater<int> > PQ;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int setBit(int mask, int pos){return mask = mask | (1<<pos);}
bool checkBit(int mask, int pos){return (bool)(mask & (1<<pos));}

vector<pair<int, int> > adj[MAX];
ll dist[MAX][MAX];
int n;

void dijkstra(int src) {
	priority_queue<ii> q;

	q.push(mk(-0, src));
	dist[src][src] = 0;

	while (!q.empty()) {
		ii x = q.top();
		q.pop();
		int cur = x.ss;

		int sz = adj[cur].size();

		for (int i = 0; i < sz; i++) {
            if (dist[src][adj[cur][i].ff] > dist[src][cur] + adj[cur][i].ss) {
                dist[src][adj[cur][i].ff] = dist[src][cur] + adj[cur][i].ss;
                q.push(mk(-dist[src][adj[cur][i].ff], adj[cur][i].ff));
            }
		}
	}
}

int main() {
	int m;

	scanf("%d %d", &n, &m);
	vector<ll> ans(n + 1, INF);
	for(int i = 0; i <= n; i++) {
        for(int j = 0; j <= n; j++) {
            dist[i][j] = 1e12;
        }
	}

	map<ii, int> mp;
	for (int i = 0; i < m; i++) {
		int x, y, w;
		scanf("%d %d %d", &x, &y, &w);
		if(x == y) {
            ans[x] = min(ans[x], (ll) w);
		}
		else {
            if(mp.count(mk(x, y))) {
                mp[mk(x, y)] = min(mp[mk(x, y)], w);
            }
            else{
                mp[mk(x,y)] = w;
            }
		}
	}

	for(map<ii, int> :: iterator it = mp.begin(); it != mp.end(); it++) {
        adj[it->ff.ff].pb(mk(it->ff.ss, it->ss));
	}
	for(int i = 1; i <= n; i++) {
        dijkstra(i);
	}

	for(int j = 1; j <= n; j++) {
        for(int i = 1; i <= n; i++) {
            if(i != j) {
                ans[i] = min(ans[i], dist[i][j] + dist[j][i]);
            }
        }
	}

	for(int i = 1; i <= n; i++) {
        if(ans[i] == INF)
            printf("-1\n");
        else
            printf("%d\n", ans[i]);
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    string s;
    set<char> ele;
    cin >> s;
    for (auto i: s)
    {
        ele.insert(i);
    }
    if (ele.size() == 1)
        cout << "Won";
    else
        cout << "Lost";
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main(){
    string str;
    cin>>str;
    if(str[0]==str[1]&&str[1]==str[2]) cout<<"Won";
    else cout<<"Lost";
    return 0;
}


/*
 * @Author: Luisvacson
 * @LastEditors: Luisvacson
 * @Descriptions: None
 * @Date: 2021-06-12 19:05:10
 * @LastEditTime: 2021-06-12 19:38:21
 * @FilePath: \C++\Public\ABC203D - Pond.cpp
 */
#include <bits/stdc++.h>
using namespace std;

int n, k, t;
int a[805][805], b[805][805];
int sum[805][805];

inline bool check(int mid) {
    register int i, j;
    memset(b, 0, sizeof(b));
    memset(sum, 0, sizeof(sum));

    for (i = 1; i <= n; ++i) {
        for (j = 1; j <= n; ++j) {
            if (a[i][j] > mid) b[i][j] = 1;
        }
    }

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

    for (i = 0; i <= n - k; ++i) {
        for (j = 0; j <= n - k; ++j) {
            if ((sum[i + k][j + k] + sum[i][j] - sum[i][j + k] -
                 sum[i + k][j]) < t)
                return true;
        }
    }
    return false;
}

signed main() {
    scanf("%d%d", &n, &k);
    t = ((k * k) >> 1) + 1;
    register int i, j;
    int l = 0, r = 0, mid, ans = 0;

    for (i = 1; i <= n; ++i) {
        for (j = 1; j <= n; ++j) {
            scanf("%d", &a[i][j]);
            r = max(r, a[i][j]);
        }
    }

    while (l <= r) {
        mid = l + r >> 1;
        if (check(mid)) {
            r = mid - 1;
            ans = mid;
        } else
            l = mid + 1;
    }

    printf("%d\n", ans);
    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;

#define mp make_pair
#define fr first
#define sc second

template<class T> T T_INF(){ return 1000000000000000000; }
template<> int T_INF<int>(){ return 1000000000; }

template<int MOD> struct modint{
	ull val;
	modint(ull x){ val=x%MOD; }
	modint(){}
	friend modint modpow(modint x,ull k){
		modint ret(1ULL);
		while(k>0){
			if(k&1ULL)ret*=x;
			x*=x;
			k>>=1;
		}
		return ret;
	}
	modint& operator +=(const modint& rhs){
		this->val+=rhs.val;
		if(this->val>=MOD)this->val-=MOD;
		return *this;
	}
	friend modint operator+(modint lhs, const modint& rhs){
		lhs+=rhs;
		return lhs;
	}
	modint& operator -=(const modint& rhs){
		this->val+=MOD-rhs.val;
		if(this->val>=MOD)this->val-=MOD;
		return *this;
	}
	friend modint operator-(modint lhs, const modint& rhs){
		lhs-=rhs;
		return lhs;
	}
	modint& operator *=(const modint& rhs){
		this->val*=rhs.val;
		this->val%=MOD;
		return *this;
	}
	friend modint operator*(modint lhs, const modint& rhs){
		lhs*=rhs;
		return lhs;
	}
	static vector<modint> inv_;
	static void precalc_inv_(int k){
		int t=inv_.size();
		inv_.resize(k);
		for(int i=t;i<k;i++){
			inv_[i]=modpow(modint(i),MOD-2);
		}
	}
	modint& operator /=(const modint& rhs){
		//if(rhs.val<inv_.size()){
		//	(*this)*=inv_[rhs.val];
		//}
		//else {
			(*this)*=modpow(rhs,MOD-2);
		//}
		return *this;
	}
	friend modint operator/(modint lhs, const modint& rhs){
		lhs/=rhs;
		return lhs;
	}

	static vector<vector<modint>> C_;
	static vector<modint> fac,inv_fac;
	static void precalc_C_(int k){
		C_.resize(k,vector<modint>(k));
		for(int i=0;i<k;i++){
			C_[i][0]=C_[i][i]=1;
			for(int j=1;j<=i-1;j++){
				C_[i][j]=C_[i-1][j-1]+C_[i-1][j];
			}
		}
	}
	static void precalc_fac(int k){
		fac.resize(k);
		inv_fac.resize(k);
		fac[0]=inv_fac[0]=1;
		for(int i=1;i<k;i++){
			fac[i]=fac[i-1]*i;
			inv_fac[i]=modpow(fac[i],MOD-2);
		}
	}
	static modint C(ll n,ll k,int type=0){
		if(k<0||k>n)return 0;
		if(type==0){
			return C_[n][k];
		}
		else {
			return fac[n]*inv_fac[k]*inv_fac[n-k];
		}
	}
};
template<int MOD> vector<modint<MOD>> modint<MOD>::inv_;
template<int MOD> vector<vector<modint<MOD>>> modint<MOD>:: C_;
template<int MOD> vector<modint<MOD>> modint<MOD>::fac;
template<int MOD> vector<modint<MOD>> modint<MOD>::inv_fac;

const int MOD=1000000007;
typedef modint<MOD> mi;

int n;
int a[100010];

mi dp[100010][2];

mi f(int i){
	if(i==-2)return 0;
	if(i<=0)return 1;
	return dp[i][0]+dp[i][1];
}

int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%d",&a[i]);

	dp[1][0]=dp[1][1]=1;
	for(int i=2;i<100010;i++){
		dp[i][0]=dp[i-1][0]+dp[i-1][1];
		dp[i][1]=dp[i-1][0];
	}

	mi ret=0;
	for(int i=0;i<n;i++){
		ret+=f(i-1)*f(n-1-i)*a[i];
		ret-=f(i-2)*f(n-2-i)*a[i];
	}
	cout<<ret.val<<endl;
}


#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 1000000007;
// constexpr int MOD = 998244353;
constexpr int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
constexpr int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  constexpr int N = 2;
  int candy[N]; REP(i, N) cin >> candy[i];
  int c; cin >> c;
  while (true) {
    if (candy[c] == 0) {
      cout << (c == 0 ? "Aoki\n" : "Takahashi\n");
      return 0;
    }
    --candy[c];
    c ^= 1;
  }
}

#define    as(array)    (sizeof(array)/sizeof(array[0]))
#define    ll           long long
#define    dd           double
#define    mp           make_pair
#define    pb           push_back
#define    se           second
#define    fi           first
#define    mod          10000007
#define    sob(v)       v.begin(),v.end()
#define    sobr(v)      v.rbegin(),v.rend()
#define    fr(i,a,b)    for(int i=a;i<=b;++i)
#define    frr(i,a,b)   for(int i=a;i>=b;--i)
#define    pi           acos(-1.00)
#define    check        cout<<"*"<<endl
#define    ffix(x)      cout<<fixed<<setprecision(x)
#define    fast         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)

// Ascending sort: sort(arra, arra+n)
// Descending sort: sort(arra, arra+n, greater<int>())

#include <bits/stdc++.h>

using namespace std;

bool binarySearch(int arra[],int arraySize, int key){
    int startPoint, endPoint;
    int location;

    startPoint = 0;
    endPoint = arraySize - 1;

    while(startPoint <= endPoint){
        int midPoint = (startPoint + endPoint) / 2;

        if(arra[midPoint] == key){
            return true;
            break;
        }
        else if(arra[midPoint] < key){
            startPoint = midPoint + 1;
        }
        else
        {
            endPoint = midPoint - 1;
        }
    }
    return false;
}

void insert(int arra[], int arraySize, int position, int item){
    for(int i = arraySize - 1; i >= position-1; i--){
        arra[i+1] = arra[i];
    }
    arra[position-1] = item;
}

int count = 0;

int main() {
    int A, B, W;

    cin >> A >> B >> W;

    int hi, lo;

    W *= 1000;

    hi = (W / A);

    if(W % A > hi * (B - A)){
        cout << "UNSATISFIABLE";
        return 0;
    }else if(W % B == 0){
        lo = W / B;
    }else{
        lo = (W / B) + 1;
    }

    cout << lo << " " << hi;
}


#include <iostream>
using namespace std;
int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    int sum;
    sum = 21 - a - b - c;
    cout << sum << endl;
    return 0;
}

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

int main () {
	int a, b, c, d;
	cin >> a >> b >> c >> d;

 	cout << a*d - b*c << endl;

}


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

int main()
{
    ll ans=0,n,k;cin>>n>>k;
    map<ll,ll>a;
    while(n--)
    {
        ll x,y;cin>>x>>y;
            a[x]+=y;
    }
    ll pre=0,j=0;
    for(auto i=a.begin();i!=a.end();i++)
    {
        if(k>=(i->first)-pre)
        {
            k=k-(i->first)+pre;

            /*
            3 2
            2 3
            5 5
            */

            pre=(i->first);
            k=k+i->second;
        }
        else
        {
            cout<<k+pre;
            j=1;
            break;
        }
    }
    if(j==0)
        cout<<k+pre;
}

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

#define ff              first
#define ss              second
#define int             long long
#define w(x)            int x; cin>>x; while(x--)
#define mii             map<int,int>
#define endl            ("\n")
#define vi              vector<int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define pii             pair<int,int>
#define f(i, a, n)      for(int i=a; i<n; i++)
#define fd(i, a, n, d)  for(int i=a; i<n; i+=d)
#define in(a,n)         f(i,0,n){cin>>a[i];}
#define pb              push_back
#define yy              cout<<"YES\n"
#define nn              cout<<"NO\n"
#define kk              cout<<"-1\n"
#define inf             (long long)1e18
#define mod             1000000007LL
#define cc(r)           cout<<r<<" "
#define ce(r)           cout<<r<<endl
#define out(a,n)        f(i,0,n){cc(a[i]);}

//No use
void inout()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
//No use
void ovector_n() {
    ce(1);
}

int32_t main()
{
    inout();
    int T = clock();
    int n, k, a, b;
    cin >> n >> k;
    mii m;
    int tb = k;
    f(i, 0, n) {
        cin >> a >> b;
        m[a] += b;

    }
    for (auto it : m) {
        //cc(a);
        //ce(b);
        a = it.ff;
        b = it.ss;
        if (tb < a)
            break;

        tb += b;
    }

    ce(tb);

}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=100005;
ll a[N],n,m,k;
int check(ll x)
{
	int now=upper_bound(a+1,a+1+n,x)-a-1;
	return x-now>=k;
}
void solve()
{
	cin>>k;
	ll l=1,r=2e18+10LL;
	while(r-l>1)
	{
		ll mid=(l+r)>>1;
		if(check(mid)) r=mid;
		else l=mid;
	}
	if(check(l)) printf("%lld\n",l);
	else printf("%lld\n",r);
}
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++) cin>>a[i];
	while(m--) solve();
}

#include <bits/stdc++.h>
using namespace std;
#define int ll
#define FOR(i,s,e) for(ll i = s; i <= (ll)e; ++i)
#define DEC(i,s,e) for(ll i = s; i >= (ll)e; --i)
#define IAMSPEED ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef LOCAL
#define db(x) cerr << #x << "=" << x << "\n"
#define db2(x, y) cerr << #x << "=" << x << " , " << #y << "=" << y << "\n"
#define db3(a,b,c) cerr<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c<<"\n"
#define dbv(v) cerr << #v << ":"; for (auto ite : v) cerr << ite << ' '; cerr <<"\n"
#define dbvp(v) cerr << #v << ":"; for (auto ite : v) cerr << "{"  << ite.f << ',' << ite.s << "} "; cerr << "\n"
#define dba(a,ss,ee) cerr << #a << ":"; FOR(ite,ss,ee) cerr << a[ite] << ' '; cerr << "\n"
#define reach cerr << "LINE: " << __LINE__ << "\n";
#else
#define db(x)
#define db2(x,y)
#define db3(a,b,c)
#define dbv(v)
#define dbvp(v)
#define dba(a,ss,ee)
#define reach
#endif
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
#define g0(x) get<0>(x)
#define g1(x) get<1>(x)
#define g2(x) get<2>(x)
#define g3(x) get<3>(x)
typedef pair <ll, ll> pi;
typedef tuple<ll,ll,ll> ti3;
typedef tuple<ll,ll,ll,ll> ti4;
ll rand(ll a, ll b) { return a + rng() % (b-a+1); }
const int MOD = 1e9 + 7;
const int inf = (int)1e9 + 500;
const long long oo = (ll)1e18 + 500;
template <typename T> bool chmax(T& a, const T b) { return a<b ? a = b, 1 : 0; }
template <typename T> bool chmin(T& a, const T b) { return a>b ? a = b, 1 : 0; }
const int MAXN = -1;
vector<int> v;
int n,Q;
int k;
bool check(int x) {
	int smaller = upper_bound(all(v), x) - v.begin();
	if(x-smaller<k)return 1;
	else return 0;
}

int32_t main()
{
	IAMSPEED
	cin >> n >> Q;
	FOR(i,1,n) {
		int x; cin >> x;
		v.pb(x);
	}
	sort(all(v));
	while(Q--) {
		cin >> k;
		int lo = 0, hi = (ll)2e18;
		while(lo < hi-1) {
			int mid=(lo+hi)/2;
			if(check(mid))lo=mid;
			else hi=mid;
		}
		cout << lo+1 << '\n';
	}
}


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

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int T;
int N;
int P[555];

vector<int> R;
void go(int x) {
	swap(P[x],P[x+1]);
	R.push_back(x);
}

void solve() {
	int i,j,k,l,r,x,y; string s;

	cin>>T;
	while(T--) {
		cin>>N;
		FOR(i,N) {
			cin>>P[i];
			P[i]--;
		}
		R.clear();
		int step=0;

		for(i=N-1;i>=3;i--) {
			FOR(j,N) if(P[j]==i) break;
			if(j==i) continue;

			if(i==3&&j==2&&step==1) {
				go(1);
				go(2);
				j=1;
			}

			while(j<i) {
				if(step==j%2) {
					go(j);
					j++;
				}
				else if(step==0) {
					if(j==1) go(2);
					else go(0);
				}
				else {
					if(j==2) go(3);
					else go(1);
				}
				step^=1;
			}
		}

		while(1) {
			for(j=N-1;j>=0;j--) if(P[j]!=j) break;
			if(j<0) break;
			assert(j<3);
			swap(P[step],P[step+1]);
			R.push_back(step);
			step^=1;
		}

		cout<<R.size()<<endl;
		FOR(i,R.size()) {
			assert(R[i]%2==i%2);
			cout<<(R[i]+1)<<" ";
		}
		cout<<endl;
		FOR(i,N) assert(P[i]==i);

	}
}

int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}

#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
#define FOR(i, a, b) for(ll i = (a); i < (b); i++)
#define REP(i, a) FOR(i, 0, a)

ll T, X, Y, P, Q;

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

ll gcd(ll a, ll b){
	ll x, y;
	return extgcd(a, b, x, y);
}

ll mod_inverse(ll a, ll m){
	ll x, y;
	extgcd(a, m, x, y);
	return (m + x % m) % m;
}

int main(){
	cin >> T;
	REP(cs, T){
		cin >> X >> Y >> P >> Q;
		ll ans = -1;
		REP(y, Y){
			REP(q, Q){
				ll x = X + y, m = 2 * (X + Y), b1 = P + q, m1 = P + Q;
				ll b = b1 - x, d = gcd(m1, m);
				if(b % d != 0) continue;
				ll t = b / d * mod_inverse(m / d, m1 / d) % (m1 / d);
				x = x + m * t;
				m *= m1 / d;
				x = (m + x % m) % m;
				if(ans == -1){
					ans = x;
				}else{
					ans = min(ans, x);
				}
			}
		}
		if(ans == -1){
			cout << "infinity" << endl;
		}else{
			assert(ans >= 0);
			cout << ans << endl;
		}
	}

}


#include <bits/stdc++.h>

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

const i64 P = 998244353;
const int maxn = 3100;
i64 dp[maxn][maxn];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "rt", stdin);
#endif

    dp[0][0] = 1;
    for1(i, maxn - 1) ford(j, maxn) {
        if (j) dp[i][j] = dp[i - 1][j - 1];
        if (2 * j < maxn) (dp[i][j] += dp[i][2 * j]) %= P;
    }

    int n, k;
    cin >> n >> k;
    cout << dp[n][k] << '\n';

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}

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

//========================[define]=======================

#define ll long long
//#define File
#define ull unsigned long long
#define loop(i,a,b,k) for(register int i = a;i<=b;i+=k)
#define ii(a) scanf("%d",&a);
#define oi(a) printf("%d",a);
#define ic(a) scanf("%c",&a);
#define oc(a) printf("%c",a);
#define ill(a) scanf("%lld",&a);
#define oll(a) printf("%lld",a);
#define pl() printf("\n");
#define pk() printf(" ");
#define it (int)
#define db (double)
#define lng (long long)
#define debug(x) cerr<<#x<<" = "<<x<<'\n';

//=========================[const]=======================

using namespace std;

const int N=1000+10;
const int M=100000+10;
const int MOD=1e9+7;
const double PI = acos(-1.0);
const double EXP = 1E-8;
const int INF = 0x3f3f3f3f;

//================================[begin]=====================

int add,Minus;

//=================================[end]======================

int
main()
{
	#ifdef File
		freopen("in.in","r", stdin);
		freopen("out.out","w", stdout);
	#endif
	scanf("%d%d",&add,&Minus);
	printf("%d %d",(add + Minus)/2,(add - Minus)/2);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
struct Edge {
    int to, cost;
    Edge(){};
    Edge(int to, int cost): to(to), cost(cost){};
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

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

    ll n;
    cin >> n;
    int i = 1, j;
    for(ll a = 5; a < n; a *= 5) {
        j = 0;
        ll t = n - a;
        while (t % 3 == 0) {
            j++;
            t /= 3;
        }
        if (t == 1 && j != 0) {
            cout << j << ' ' << i << endl;
            return 0;
        }
        i++;
    }
    cout << -1 << endl;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll qpow(ll a,ll b)
{
	ll ans=1;
	while(b>0)
	{
		if(b&1)
		{
			ans=ans*a;
		}
		a=a*a;
		b>>=1;
	}
	return ans;
}
int main()
{
	ll n;
	scanf("%lld",&n);
	for(ll i = 1;i<=38;i++){
		for(ll j = 1;j<=26;j++){
			if(qpow(3,i) + qpow(5,j) == n && qpow(3,i)>0 && qpow(5,j)>0){
				printf("%lld %lld",i,j);
				return 0;
			}
		}
	}
	printf("-1\n");
	//printf("%lld\n",qpow(3,35));
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define ll long long int
#define sz(x) (int)(x.size())
#define FOR(i,x,y) for(int i=x;i<=y;++i)
#define FORN(i,x,y) for(int i=x;i>=y;--i)
#define debug(x )cout<<'['<<#x<<" is "<<x<<"]"<<endl;
#define yes cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;
#define endl '\n';
void solve() {
    ll arr[3];
    ll mod=998244353;
    cin>>arr[0]>>arr[1]>>arr[2];
    arr[0]%=mod;
    arr[1]%=mod;
    arr[2]%=mod;
    sort(arr,arr+3);
    ll ans=0;
    ans+=(arr[2]*(arr[2]+1)/2)%mod;
    ans%=mod;
    ans*=(arr[1]*(arr[1]+1)/2)%mod;
    ans%=mod;
    ans*=(arr[0]*(arr[0]+1)/2)%mod;
    cout<<ans%mod<<endl;

}
int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#ifdef CLION
    freopen("input.in", "r", stdin);
#endif
    // seive();
   // ll t;cin>>t;while(t--) {
        solve();
    //}
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repp(i, st, en) for (ll i = (ll)st; i < (ll)(en); i++)
#define repm(i, st, en) for (ll i = (ll)st; i >= (ll)(en); i--)
#define all(v) v.begin(), v.end()
void chmax(ll &x, ll y) {x = max(x,y);}
void chmin(ll &x, ll y) {x = min(x,y);}
void Yes() {cout << "Yes" << endl; exit(0);}
void No() {cout << "No" << endl; exit(0);}
template<class in_Cout> void Cout(in_Cout x) {cout << x << endl; exit(0);}
template<class in_vec_cout>
void vec_cout(vector<in_vec_cout> vec) {
    for (in_vec_cout res : vec) {cout << res << " ";}
    cout << endl;
}

const ll inf = 1e18;
const ll mod = 1e9 + 7;

int main() {
    ll a, b, c; cin >> a >> b >> c;
    if (a==b) Cout(c);
    if (b==c) Cout(a);
    if (c==a) Cout(b);
    Cout(0);
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template<class T> bool chmin(T& a,T b){if(a>b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b){if(a<b) {a = b; return true;} return false;}
#define rep(i,n) for(int i=0;i<(n);i++)
#define drep(i,n) for(int i=(n)-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define debug(x)  cerr << #x << " = " << (x) << endl;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vec<ll> A(N),B(N);
    rep(i,N) cin >> A[i];
    rep(i,N) cin >> B[i];
    vec<ll> ans(N+1);
    vec<ll> ma(N+1);
    rep(i,N) ma[i+1] = max(ma[i],A[i]);
    rep(i,N){
        ans[i+1] = max(ans[i],B[i]*ma[i+1]);
    }
    rep(i,N+1) if(i) cout << ans[i] << "\n";
}

#include<bits/stdc++.h>
using namespace std;
using P=pair<int,int>;
constexpr int mod=1000000007;
constexpr int inf=1e9;
int in(){
    int x;
    scanf("%d",&x);
    return x;
}
int main(){
    int n=in();
    long long a[n],b[n];
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<n;i++)cin>>b[i];
    long long amax=0,ans=0;
    for(int i=0;i<n;i++){
        amax=max(amax,a[i]);
        ans=max(ans,amax*b[i]);
        cout<<ans<<endl;
    }
    return 0;
}


/*
　　　　　／＞　 フ
　　　　　| 　_　 _|
　 　　　／`ミ _x 彡
　　 　 /　　　 　 |
　　　 /　  ヽ　　 ?
　／￣|　　 |　|　|
　| (￣ヽ＿_ヽ_)_)
　＼二つ
 */
#pragma GCC optimize("Ofast","inline","-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define pf push_front
#define F first
#define S second
#define SS stringstream
#define sqr(x) ((x)*(x))
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define CC(x) cout << (x) << endl
#define AL(x) x.begin(),x.end()
#define pw(x) (1ull<<(x))
#define NMSL cout << "NMSL" << endl;
#define debug(x) cout << #x << ": " << x << endl;
#define debug2(x, y) cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl;
#define debug3(x, y, z) cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define debug4(a, b, c, d) cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define fio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define in128 __int128_t
using namespace std;
const int N = 2e5+10;
const int INF = 0x7f7f7f7f;
const double EPS = 1e-3;
const long double PI = 3.14159265358979323846;
int n,p,ans=0;
int a[55];
map<pair<signed,int>,int>mp;
int DFS(signed x,int rest)
{
    if(mp[{x,rest}])
        return mp[{x,rest}];
    if(x<=0)
        return 1;
    int fake=rest;
    int ck=abs(rest);
    fake%=a[x];
    ck=ck-abs(fake)+a[x];
    mp[{x,rest}]+=DFS(x-1,fake);
    if(ck<a[x+1])
    {
        if(fake>0)
            mp[{x,rest}]+=DFS(x-1,fake-a[x]);
        else if(fake<0)
            mp[{x,rest}]+=DFS(x-1,fake+a[x]);
    }
    return mp[{x,rest}];
}
signed main()
{
    fio
    cin>>n>>p;
    for(int i=0; i<n; ++i)
        cin>>a[i];
    p%=a[n-1];
    ans+=DFS(n-2,p);
    if(p)
        ans+=DFS(n-2,p-a[n-1]);
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a[]={15,10,3,0};
  int b[]={8,3,0,0};
  int p,q;
  cin>>p>>q;
  p+=q;
  int i,j;
  for(i=0;i<4;i++)
  {
    if(p>=a[i])
      break;
  }
  for(j=0;j<4;j++)
  {
    if(q>=b[j])
      break;
  }
  int ps=max(i,j);
  cout<<ps+1<<"\n";
  return 0;
}

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

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

    if (C >= 15 && B >= 8)
        cout << 1 << endl;
    else if (C >= 10 && B >= 3)
        cout << 2 << endl;
    else if (C >= 3)
        cout << 3 << endl;
    else
        cout << 4 << endl;
}


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

int n,x,y,ans;
string a;
map <pair <int,int>,int> m;

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

	m[{x,y}]++;
	for(auto c:a)
	{
		if(c=='A') x++;
		else if(c=='T') x--;
		else if(c=='C') y++;
		else y--;

		ans+=m[{x,y}];
		m[{x,y}]++;
	}
	cout<<ans;
}

#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <set>
#include <utility>
#include <queue>
#include <map>
#include <assert.h>
#include <stack>
#include <string>
#include <stdlib.h>
#include <stdio.h>
#include <cstring>
#include <cmath>
#include<iomanip>

#define int long long int
using namespace std;
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
int mod(int x)
{
    return (((x)%1000000007)+1000000007)%1000000007;
}

int solve()
{
   int n;
   string s;
   cin>>n>>s;
   int a[n+1],g[n+1],c[n+1],t[n+1];
   for(int i=0;i<n+1;i++)
   {
       a[i]=0;
       c[i]=0;
       g[i]=0;t[i]=0;
   }
   if(s[0]=='A')
   a[1]=1;
   else
   a[1]=0;
   if(s[0]=='G')
   g[1]=1;
   else
   g[1]=0;
   if(s[0]=='C')
   c[1]=1;
   else
   c[1]=0;
   if(s[0]=='T')
   t[1]=1;
   else
   t[1]=0;
   for(int i=2;i<=n;i++)
   {
       if(s[i-1]=='A')
       a[i]=a[i-1]+1;
       else
       a[i]=a[i-1];
   }
   for(int i=2;i<=n;i++)
   {
       if(s[i-1]=='C')
       c[i]=c[i-1]+1;
       else
       c[i]=c[i-1];
   }
   for(int i=2;i<=n;i++)
   {
       if(s[i-1]=='T')
       t[i]=t[i-1]+1;
       else
       t[i]=t[i-1];
   }
   for(int i=2;i<=n;i++)
   {
       if(s[i-1]=='G')
       g[i]=g[i-1]+1;
       else
       g[i]=g[i-1];
   }
   int count=0;
   for(int i=0;i<n;i++)
   {
       for(int j=i;j<n;j++)
       {
           if(a[j+1]-a[i]==t[j+1]-t[i] && c[j+1]-c[i]==g[j+1]-g[i])
           count++;
       }
   }
   cout<<count;
   return 0;
}

signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(NULL); cout.tie(NULL);
	int t;
	//cin >> t;
	t=1;
	while (t--)
	{
		solve();
	}
	return 0;
}


/*
after dusk passed,
there is a starry sky.
*/
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define m_k make_pair
using namespace std;
int n,m;
inline int read()
{
	int f=1,x=0;char s=getchar();
	while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}
	while(s>='0'&&s<='9'){x=x*10+s-'0';s=getchar();}
	return x*f;
}
signed main()
{
	n=read();m=read();
	if (n==1&&m==0)
	{
		printf("1 2\n");
		return 0;
	}
	if (m>=n-1||m<0)
	{
		printf("-1\n");
		return 0;
	}
	printf("1 100000000\n");m++;
	for (int i=1;i<m;i++) printf("%d %d\n",2*i,2*i+1);
	printf("%d %d\n",2*m,m+n);
	for (int i=m+1;i<n;i++) printf("%d %d\n",m+i,n+i);
}

#include <bits/stdc++.h>

using namespace std;

void setup() {
    #ifdef LOCAL
    freopen("input", "r", stdin);
    #else
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    #endif
}

#define int long long
vector<int> getTimes(vector<int> &a, int start, int end) {
    const int n = end - start;
    const int total = 1 << n;
    vector<int> times;
    for (int i = 0; i < total; i++) {
        int timeTook = 0;
        for (int j = 0; j < n; j++) {
            if (i & (1 << j)) {
                timeTook += a[start + j];
            }
        }
        times.push_back(timeTook);
    }
    return times;
}

signed main() {
    setup();
    int n, t;
    cin >> n >> t;
    vector<int> a(n);
    for (int &it : a) cin >> it;

    vector<int> times1 = getTimes(a, 0, n / 2), times2 = getTimes(a, n / 2, n);
    sort(times1.begin(), times1.end());
    sort(times2.begin(), times2.end());
    int r = times2.size() - 1;
    int best = 0;
    for (int i = 0; i < (int)times1.size(); i++) {
        while (r >= 0 && times1[i] + times2[r] > t) {
            r--;
        }
        if (r >= 0) {
            best = max(best, times1[i] + times2[r]);
        } else {
            break;
        }
    }
    cout << best << endl;
}


#include <bits/stdc++.h>

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

using namespace std;
typedef long long LL;
typedef pair<LL, LL> ii;

LL N, L, R;
bool isPrime[1000100];
LL leastFac[1000100];
LL numFac[1000100];
bool freeSquareFaq[1000100];
void main1() {
	cin >> L >> R;

	LL ans = 0;
	for (LL i = 0; i < 1000100; i++) {
		isPrime[i] = true;
	}
	isPrime[0] = false;
	isPrime[1] = false;

	memset(leastFac, -1, sizeof leastFac);
	leastFac[0] = 0;
	leastFac[1] = 1;
	for (LL i = 2; i < 1000100; i++) {
		if (leastFac[i] == -1) {
			leastFac[i] = i;
			for (LL j = i * i; j < 1000100; j += i) {
				if (leastFac[j] == -1) {
					leastFac[j] = i;
				}
				isPrime[j] = false;
			}
		}
	}

	for (LL i = 2; i < 1000100; i++) {
		LL u = i;
		freeSquareFaq[i] = true;

		while (u > 1) {
			numFac[i]++;

			if (leastFac[u] == leastFac[u / leastFac[u]]) {
				freeSquareFaq[i] = false;
			}

			u /= leastFac[u];
		}
	}

	for (LL i = 2; i <= 1000000; i++) {
		if (!freeSquareFaq[i]) {
			continue;
		}

		LL l = ((L + i - 1) / i) * i;

		while (l <= R) {
			LL bawahl = l / l;
			LL atasl = R / l;
			LL numKelipatanl = atasl - bawahl + 1;

			LL bawahi = l / i;
			LL atasi = R / i;
			LL numTotalGCDi = atasi - bawahi + 1;

			if (numFac[i] % 2 == 1) {
				ans += numTotalGCDi - numKelipatanl;
			} else {
				ans -= numTotalGCDi - numKelipatanl;
			}

			// if (numTotalGCDi - numKelipatanl > 0) {
			// 	cout << i << ' ' << l << ' ' << numKelipatanl << ' ' << numTotalGCDi << endl;
			// }

			l += i;
		}
	}

	cout << 2 * ans << endl;
}

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

	// cin >> T2;
	T2 = 1;

	while (T2--) {
		main1();
	}

	return 0;
}


#include<iostream>
#include<math.h>
using namespace std;

int main(void){
  int a[100]={};
  int min=INFINITY;

  for(int i=0;i<4;i++){
    cin >> a[i];
  }
  for(int i=0;i<4;i++){
    if(min>a[i]){
      min=a[i];
    }
  }
  cout << min;
  return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define p pair<long long,long long>
#define endl '\n'
#define iof  freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define pi acos(-1)
int fx[]={0,0,1,-1,1,1,-1,-1};
int fy[]={1,-1,0,0,-1,1,-1,1};
const int mxn=1e9+7;

int main(int argc, char const *argv[])
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int mn=min({a,b,c,d});
    cout<<mn<<endl;
}


#include <iostream>
using namespace std;

int main(void)
{
  char S[12];
  cin >> S;
  int number = 0;
  for (int i = 0; i < 12; i++)
  {
    if (S[i] == 'Z' && S[i + 1] == 'O' && S[i + 2] == 'N' && S[i + 3] == 'e')
    {
      number ++;
    }
  }
  cout << number << endl;
  return 0;
}

// template for atcoder beginners
// when you create a *.cpp file, this template is loaded

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

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

	string n_str(to_string(n));
	int zero_count = 0;

	// お尻が0の場合その数分付け足す。
	if (n_str[n_str.size() - 1] == '0') {
		string n_str_temp(n_str);
		do {
			n_str_temp.erase(n_str_temp.size() - 1,1);
			zero_count++;
		} while (n_str_temp.size() != 0 && n_str_temp[n_str_temp.size() - 1] == '0');
    // cout << zero_count << endl;
		n_str = n_str.substr(n_str.size() - zero_count).append(n_str);
	}

	string n_str_reverse(n_str);
	reverse(n_str_reverse.begin(),n_str_reverse.end());

  // cout << n_str << endl;
  // cout << n_str_reverse << endl;

	if (n_str == n_str_reverse) {
		cout << "Yes" << endl;
		return (0);
	}

	cout << "No" << endl;
	return (0);

}


// E - 潜入
#include <bits/stdc++.h>
using namespace std;
#define vec vector
using vi = vec<int>;
using PR = pair<int,int>;
#define rep(i,n) for(int i=0;i<(int)(n);++i)

int V; // 頂点数
vec<vec<PR>> G; // [from]<to, cost> 隣接リスト
int INF = 1e9;

vi dijkstra(int s){
	vi dist(V, INF);
	dist[s] = 0;
	priority_queue<PR, vec<PR>, greater<PR>> pq;
	pq.push({0, s});
	while(pq.size()){
		auto[from_d, from_v] = pq.top(); pq.pop();
		if(dist[from_v] < from_d) continue;
		for(auto[to_u, to_d]:G[from_v]){
			to_d += dist[from_v];
			if(dist[to_u] <= to_d) continue;
			dist[to_u] = to_d;
			pq.push({to_d, to_u});
		}
	}
	return dist;
}

int main(){
	int R, C; cin>>R>>C;
	vec<vi> A(R, vi(C-1)); for(vi&v:A) for(int&x:v) cin>>x;
	vec<vi> B(R-1, vi(C)); for(vi&v:B) for(int&x:v) cin>>x;
	auto rc2id = [&](int r, int c){ return r*C + c; };
	V = R*C*2;
	G.resize(V);
	rep(r, R) rep(c, C){
		int a = rc2id(r, c), b = rc2id(r, c+R*C);
		G[a].emplace_back(b, 1), G[b].emplace_back(a, 0);
		if(r != R-1){
			G[rc2id(r+1, c+R*C)].emplace_back(rc2id(r, c+R*C), 1);
			G[rc2id(r, c)].emplace_back(rc2id(r+1, c), B[r][c]);
		}
		if(c != C-1){
			a = rc2id(r, c), b = rc2id(r, c+1);
			G[a].emplace_back(b, A[r][c]), G[b].emplace_back(a, A[r][c]);
		}
	}
	cout<< dijkstra(0)[rc2id(R-1,C-1)] <<endl;
}

#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define MP make_pair
#define mt make_tuple
#define eb emplace_back
#define ar array
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define mem(arr,x) memset(arr, x, sizeof arr)
#define db(arr) for(auto x : arr) cout << x << " "; cout << "\n";
#define db2d(arr) for(auto x : arr){ for(auto y : x) cout << y << " "; cout << "\n";}
#define read(arr) for(auto &x : arr) cin >> x;
#define sz(x) (int)x.size()
#define MOD 1000000007
#define MOD2 998244353
#define nl '\n'
using namespace std;

// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// order_of_key (k) : Number of items strictly smaller than k
// find_by_order(k) : K-th element in a set (counting from zero)

string to_string(char c) {
	return string(1, c);
}

string to_string(bool b) {
	return b ? "true" : "false";
}

string to_string(const char* s) {
	return string(s);
}

string to_string(string s) {
	return s;
}

string to_string(vector < bool > v) {
	string res;
	for(int i = 0; i < sz(v); i++)
		res += char('0'+v[i]);
	return res;
}

template < size_t S > string to_string(bitset < S > b) {
	string res;
	for(int i = 0; i < S; i++)
		res += char('0' + b[i]);
	return res;
}

template < class T > string to_string(T v) {
    bool f = 1;
    string res;
    for(auto x : v) {
		if(!f)
			res+=' ';
		f=0;
		res += to_string(x);
	}
    return res;
}

void dbvar() { cerr << "]" << endl; }
template<class H, class... T> void dbvar(H h, T... t){
	cerr << to_string(h);
	if(sizeof...(t))
		cerr << ", ";
	dbvar(t...);
}

template<class A> void write(A x) {
	cout << to_string(x);
}

template<class H, class... T> void write(const H& h, const T&... t) {
	write(h);
	write(t...);
}

void print() {
	write("\n");
}

template<class H, class... T> void print(const H& h, const T&... t) {
	write(h);
	if(sizeof...(t))
		write(' ');
	print(t...);
}

template <typename T1, typename T2>
constexpr typename std::common_type<T1, T2>::type floor_div(T1 x, T2 y) {
	assert(y != 0);
	if (y < 0) x = -x, y = -y;
	return x < 0 ? (x - y + 1) / y : x / y;
}

const ll INFL = (ll)1e18;
const int INF = (int)1e9;
const ld eps = (ld)1e-9;
const ld pi = acos(-1.0);
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, 1, 0, -1};

ll power(ll n, ll m){
	if(m == 0) return 1;
	ll val = power(n, m/2);
	if(m % 2 == 0) return (val * val); else return ((val * val) * n);
}

ll powermod(ll n, ll m, ll _MOD){
	if(m == 0) return 1;
	ll val = powermod(n,m/2,_MOD);
	val %= _MOD;
	if(m % 2 == 0) return (val * val) % _MOD; else return (((val * val) % _MOD) * n) % _MOD;
}

const int mxN = 3000;
vector < pair < ll, ll > > graph[mxN];
ll dis[mxN];
void solve(){
	ll n, m; cin >> n >> m;
	for(ll i = 0; i < m; i++){
		ll a, b, c; cin >> a >> b >> c; a--; b--;
		graph[a].pb(MP(b, c));
	}
	priority_queue < pair < ll, ll >, vector < pair < ll, ll > >, greater < pair < ll, ll > > > q;
	for(ll i = 0; i < n; i++){
		for(ll j = 0; j < mxN; j++) dis[j] = INF;
		dis[i] = 0;
		ll ans = INF;
		q.push(MP(0, i));
		while(!q.empty()){
			auto cur = q.top(); q.pop();
			if(cur.first > dis[cur.second]) continue;
			for(auto x : graph[cur.second]){
				if(dis[x.first] > cur.first + x.second){
					dis[x.first] = cur.first + x.second;
					q.push(MP(dis[x.first], x.first));
				}
				if(x.first == i){
					ans = min(ans, cur.first + x.second);
				}
			}
		}
		if(ans == INF) ans = -1;
		print(ans);
	}
}

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

	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif

	// cout << setprecision(10) << fixed;

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

	for(int i = 1; i <= t; i++){
		// cout << "Case #" << i << ": ";
		solve();
	}

	return 0;
}


#include <bits/stdc++.h>

#include <unordered_set>
#include <vector>
// #include <atcoder/all>
// using namespace atcoder;

using namespace std;
using ll = long long;

// using Graph = vector<vector<int>>;
vector<bool> visited;
vector<bool> good;
vector<int> C;
vector<int> G[100009];

void dfs(int v, vector<int> &color) {
    if (0 == color[C[v]]) good[v] = true;
    color[C[v]]++;
    visited[v] = true;
    for (int next_v : G[v]) {
        if (visited[next_v]) continue;
        dfs(next_v, color);
    }
    color[C[v]]--;
}

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

    int N;
    cin >> N;
    vector<int> color(100009, 0);

    // Graph G(N);
    C.resize(N);
    for (int i = 0; i < N; i++) {
        cin >> C[i], C[i]--;
    }

    for (int i = 0; i < N - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    visited.assign(N, false);
    good.assign(N, false);
    dfs(0, color);

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

    return 0;
}

/* code of Ayush Tiwari
    codeforces- servermonk
    codechef- ayush572000
*/

#include <bits/stdc++.h>
#define ll long long

//STL
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define all(v) v.begin(), v.end()

//loops
#define forn(i,a,b) for(int i=a;  i<b; i++)
#define rforn(i,a,b) for(int i=a; i>=b; i--)

// defined values
#define maxn 200004
#define Mod 1000000007

// fast io
#define FIO() ios_base::sync_with_stdio(0);cin.tie(0);

using namespace std;

vector<int> graph[maxn];
map<int,int> m;
int a[maxn];
int vis[maxn];

void dfs(int node,int flag){
    vis[node]=flag;
    m[a[node-1]]+=1;
    for(auto child: graph[node]){
        if(vis[child]) continue;
        if(!m[a[child-1]])
            dfs(child,1);
        else dfs(child,2);
    }
    m[a[node-1]]-=1;
}

void solution(){

    // This is the main code
    int n;
    cin>>n;
    forn(i,0,n) cin>>a[i];
    forn(i,0,n-1){
        int u,v;
        cin>>u>>v;
        graph[u].pb(v);
        graph[v].pb(u);
    }
    dfs(1,1);
    forn(i,1,n+1){
        if(vis[i]==1) cout<<i<<endl;;
    }
}

int main(){

    #ifndef ONLINE_JUDGE
    freopen("D:/competitive-programming/input.txt","r",stdin);
    freopen("D:/competitive-programming/output.txt","w",stdout);
    #endif

    FIO()

    ll t=1;
    // cin>>t;
    while (t--)
    {
        solution();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const ll MOD = 1e9 + 7;
const ll INF = 1e18;

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

    ll n;
    cin >> n;
    ll a, p, x, t = 0, res = INF;
    REP(i, n) {
        cin >> a >> p >> x;
        if (x - a > 0) chmin(res, p);
    }
    if (res == INF) cout << -1 << endl;
    else cout << res << endl;
    return 0;
}

#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-5;

//int N, M, K, T, H, W, L, R;
long long int N, M, K, T, H, W, L, R;

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

	cin >> N;
	long long int ans = MOD * MOD;
	while (N--) {
		cin >> L >> R >> K;
		if (L < K) {
			ans = min(ans, R);
		}
	}
	if (ans == MOD * MOD)ans = -1;
	cout << ans << endl;
}


#include<bits/stdc++.h>
using namespace std;
namespace IO
{
	const int buffer_size=1e5+5;
	char buf[buffer_size],*S,*T;
	bool flag_EOF;
	inline char read_char()
	{
	    if(S==T)
			T=(S=buf)+fread(buf,1,buffer_size,stdin);
	    return S!=T?*(S++):EOF;
	}
	inline int read_int()
	{
	    int flag=1;
	    char c=read_char();
	    while(c<'0'||c>'9')
	    {
	        if(c==EOF)
	        {
	            flag_EOF=true;
	            return 0;
	        }
	        flag=(c=='-'?-1:1);
	        c=read_char();
	    }
	    int x=0;
	    while(c>='0'&&c<='9')
	    {
	        x=x*10+(c^48);
	        c=read_char();
	    }
	    return x*flag;
	}
	char st[13];
	int _top;
	void Write(int x)
	{
		if(!x)
		{
			putchar('0');
			return;
		}
		if(x<0)
		{
			putchar('-');
			x=-x;
		}
		while(x)
		{
			st[++_top]=x%10+'0';
			x/=10;
		}
		while(_top>0)
			putchar(st[_top--]);
	}
}
int main()
{
	long long x,y;
	cin>>x>>y;
	long long ans=1e18;
	for(int k=0;;++k)
	{
		if(k!=0)
			x<<=1;
		long long res=k;
		long long val=x>y?x-y:y-x;
		int now=k;
		while(1)
		{
			while(!(val&1)&&now>0)
				val>>=1,--now;
			if(now==0)
			{
				res+=val;
				break;
			}
			int i=0;
			while(val&(1ll<<i))
				++i;
			i=min(i,now);
			if(i==1)
				++res,val^=1;
			else
			{
				res+=2;
				val^=(1ll<<i)-1;
			}
		}
		ans=min(ans,res);
		if(x>=y)
			break;
	}
	printf("%lld\n",ans);
	return 0;
}

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

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


#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rel register ll
#define rec register char
#define gc getchar
//#define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<23,stdin),p1==p2)?-1:*p1++)
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
char buf[1<<23],*p1=buf,*p2=buf;
inline int read(){
  int x=0,f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return f?x:-x;
  }
template <typename mitsuha>
inline bool read(mitsuha &x){
  x=0;int f=1;char c=gc();
  for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';
  if (!~c) return 0;
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return x=f?x:-x,1;
  }
template <typename mitsuha>
inline int write(mitsuha x){
  if (!x) return 0&pc(48);
  if (x<0) pc('-'),x=-x;
  int bit[20],i,p=0;
  for (;x;x/=10) bit[++p]=x%10;
  for (i=p;i;--i) pc(bit[i]+48);
  return 0;
  }
inline char fuhao(){
  char c=gc();
  for (;isspace(c);c=gc());
  return c;
  }
}using namespace chtholly;
using namespace std;
const int yuzu=4e5;
typedef int fuko[yuzu|10];
fuko fa,sz;
struct dsu {
  int find(int x) {
    return fa[x]?fa[x]=find(fa[x]):x;
  }
  int mg(int u,int v) {
    u=find(u),v=find(v);
    if (sz[u]&&sz[v]) return 0;
    u^v?fa[u]=v,sz[v]|=sz[u]:sz[u]=1;
    return 1;
  }
}zw;
int main() {
  int n,i,a,b,lxy=0;
  read(n);
  for (i=1;i<=n;++i) lxy+=zw.mg(read(),read());
  printf("%d\n",lxy);
}

//#pragma once
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cctype>
#include <cstdlib>      // srand,rand
#include <random>
#include <functional>
#include <list>
#include <stack>
#include <time.h>

#define height 50
#define width 50
#define tile_sum 2500

using namespace std;
#define ll long long
#define ll128 long long
#define lp(i,n) for(ll i=0;i<n;i++)

clock_t start_clock = clock();
clock_t end_clock = clock();

int start_x;
int start_y;

int tile[height][width];
int point[height][width];
int ans_score=0;

string direction_str;
string ans_string;

int GetTileKind(int y,int x){
    return tile[y][x];
}

void Input(){
    cin>>start_y;
    cin>>start_x;
    for(int h=0;h<height;h++){
        for(int w=0;w<width;w++){
            cin>>tile[h][w];
        }
    }
    for(int h=0;h<height;h++){
        for(int w=0;w<width;w++){
            cin>>point[h][w];
        }
    }
}

int CheckScore(string direction_str){
    int now_x=start_x;
    int now_y=start_y;
    int score=point[now_y][now_x];
    for(int i=0;i<direction_str.size();i++){
        if(direction_str[i]=='U')now_y--;
        if(direction_str[i]=='D')now_y++;
        if(direction_str[i]=='L')now_x--;
        if(direction_str[i]=='R')now_x++;
        score+=point[now_y][now_x];
    }
    return score;
}

bool CheckCanGo(int y,int x,bool gone[tile_sum]){
    if(y<0 || height<=y || x<0 || width<=x)return false;
    if(gone[GetTileKind(y,x)]==true)return false;
    return true;
}

string DicidePath(string direction_str){
    bool gone[tile_sum]={};
    int now_x=start_x;
    int now_y=start_y;
    gone[GetTileKind(now_y ,now_x )]=true;
    for(int i=0;i<direction_str.size();i++){//元々決められていたパスの処理
        if(direction_str[i]=='U')now_y--;
        if(direction_str[i]=='D')now_y++;
        if(direction_str[i]=='L')now_x--;
        if(direction_str[i]=='R')now_x++;
        gone[GetTileKind(now_y ,now_x )]=true;
    }
    char pre_direct_x='a';
    char pre_direct_y='a';
    while(true){//追加のパスを決める処理
        string CanGoDirection="";
        if(CheckCanGo(now_y - 1 ,now_x ,gone )==true){
            for(int i=0;i<now_y;i++)CanGoDirection+="U";
        }
        if(CheckCanGo(now_y + 1 ,now_x ,gone )==true){
            for(int i=0;i<49-now_y;i++)CanGoDirection+="D";
        }
        if(CheckCanGo(now_y ,now_x - 1 ,gone )==true){
            for(int i=0;i<now_x;i++)CanGoDirection+="L";
        }
        if(CheckCanGo(now_y ,now_x + 1 ,gone )==true){
            for(int i=0;i<49-now_x;i++)CanGoDirection+="R";
        }
        if(CanGoDirection.empty())break;
        direction_str+=CanGoDirection[rand()%CanGoDirection.size()];
        if(direction_str.back()=='U')now_y--;
        if(direction_str.back()=='D')now_y++;
        if(direction_str.back()=='L')now_x--;
        if(direction_str.back()=='R')now_x++;
        gone[GetTileKind(now_y ,now_x )]=true;
    }
    return direction_str;
}

int main(){
    srand((unsigned int)time(NULL));
    Input();
    direction_str.clear();
    ans_string=DicidePath(direction_str);
    ans_score=CheckScore(ans_string);
    while(true){
        end_clock = clock();
		double tt = (double)((end_clock - start_clock));
		if (tt >= (double)1800.000)break;
        int used_c_num=rand()%ans_string.size();
        direction_str.clear();
        for(int j=0;j<used_c_num;j++)direction_str+=ans_string[j];
        string now_direct_str=DicidePath(direction_str);
        int score=CheckScore(now_direct_str);
        if(ans_score<=score){
            ans_string=now_direct_str;
            ans_score=score;
        }
    }
    cout<<ans_string<<endl;
    return 0;
}


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

int main() {
  int M;
  cin >> M >> M;
  vector<string> s(M);
  map<string, int> m;
  set<string> S;
  vector<vector<char>> a(20, vector<char>(20, 'A'));
  deque<tuple<int, int, string>> t;
  for (int i = 0; i < M; i++) {
    cin >> s.at(i);
    if (m.count(s.at(i))) {
      m.at(s.at(i))++;
    }
    else {
      m[s.at(i)] = 1;
    }
  }
  for (int i = 0; i < M; i++) {
    if (!(S.count(s.at(i)))) {
      S.insert(s.at(i));
      t.push_back(make_tuple(m.at(s.at(i)), (int)s.at(i).size(), s.at(i)));
    }
  }
  sort(t.begin(), t.end());
  for (int i = 0; i < 20; i++) {
    M = 0;
    for (int j = 0; j < 10; j++) {
      if (M + get<1>(t.front()) > 19) {
        break;
      }
      for (int k = 0; k < get<1>(t.front()); k++) {
        a.at(i).at(M + k) = get<2>(t.front()).at(k);
      }
      M += get<1>(t.front());
      t.pop_front();
    }
  }
  for (int i = 0; i < 20; i++) {
    for (int j = 0; j < 20; j++) {
      cout << a.at(i).at(j);
      if (j > 18) {
        cout << endl;
      }
    }
  }
}

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<string.h>
#include<random>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
#define rprintf(fmt, begin, end) do { const auto end_rp = (end); auto it_rp = (begin); for (bool sp_rp=0; it_rp!=end_rp; ++it_rp) { if (sp_rp) putchar(' '); else sp_rp = true; printf(fmt, *it_rp); } putchar('\n'); } while(0)

VI ans;
void rec(LL x, LL y, int dep) {
    if (ans.size() > 130u) return;

    if (x == y) {
	ans.push_back(4);
	REP (i, x) {
	    ans.push_back(1);
	    if (ans.size() > 130u) return;
	}

	// printf("%lld %lld %d\n", x, y, dep);
	return;
    }
    if (x > y) {
	ans.push_back(3);
	rec(x - y, y, dep+1);
    } else {
	ans.push_back(4);
	rec(x,  y - x, dep+1);
    }
}

// const long double GR = 2L / (1L + sqrt(5L));
const long double GR = 0.6180339887498948482045868343656381177203091798057628621354486227L;

bool solve(LL N) {
    ans.clear();
    if (N == 1) {
	ans.push_back(1);
	return true;
    }

    REP (i, 100) {
	LL tmpN = N-i;
	LL y = (long double)tmpN * GR;

	for (LL tmpy = y-30; tmpy <= y+30; tmpy++) {

	    if (tmpy > 0 && tmpy < tmpN && __gcd(tmpN, tmpy) == 1) {
		while ((int)ans.size() != i) ans.pop_back();
		rec(tmpN, tmpy, 0);
		if (ans.size() <= 130) {
		    return true;
		}
	    }
	}

	ans.push_back(1);
    }

    return false;
}

mt19937_64 engine;
void MAIN() {
    assert(solve(1));
    assert(solve(2));

    LL N;
#ifdef LOCALx
    REP (t, 100000) {
	N = engine() % 1000000000000000000LL + 1;
	printf("%lld\n", N);
	assert(solve(N));

    }
#endif

    scanf("%lld", &N);

    bool b = solve(N);
    assert(b);

    reverse(ans.begin(), ans.end());
    printf("%d\n", (int)ans.size());
    REP (i, ans.size()) printf("%d\n", ans[i]);
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<bitset>
#include<deque>
#include<cstdlib>
#include<set>
#include<ctime>
#define ll long long
#define mp make_pair
#define mod 1000000007
using namespace std;
ll read()
{
	ll x=0,f=1;
	char c=getchar();
	while(c>'9'||c<'0')
	{
		if(c=='-') f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		x=x*10+c-'0';
		c=getchar();
	}
	return f*x;
}
int n;
ll a[100003],ans=1;
int main()
{
	n=read();
	for(int i=1;i<=n;++i) a[i]=read();
	sort(a+1,a+1+n);
	for(int i=1;i<=n;++i)
	{
		ans=ans*(a[i]-a[i-1]+1)%mod;
		while(a[i]==a[i+1]) ++i;
	}
	cout<<ans<<'\n';
	return 0;
 }

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

const int N = 400010, mod = 1e9 + 7;

set<LL> s;
int n;

int main(){
    cin >> n;
    s.insert(0);
    for (int i = 0; i < n; i ++)    {
        int x;
        cin >> x;
        s.insert(x);
    }

    LL ans = 1;

    for (auto it = next(s.begin()), i = s.begin(); it != s.end(); it ++, i ++) {
        ans = ans * (*it - *i + 1) % mod;
    }
    cout << ans;
    return 0;
}