#include <cstdlib>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define vc vector<char>
#define vs vector<string>
#define vd vector<double>
#define vll vector<ll>
#define vvi vector<vi>
#define vvii vector<vii>
#define vvc vector<vc>
#define vvs vector<vs>
#define vvll vector<vll>
#define vvd vector<vd>
#define FOR(x,n) for(int x=0;x<n;x++)
#define FORS(x,n) for(int x=1;x<=n;x++)
#define FORE(x,a) for(auto &x: a)
#define ALL(x) x.begin(),x.end()
#define REP(n) for(int _ = 0; _ < n; _++)
#define MT make_tuple
#define pb push_back
#define endl '\n'
#define F first
#define S second

vvi con;
vi vis;

void dfs(int u) {
  if(vis[u]) return;
  vis[u] = 1;
  for(auto x: con[u]) dfs(x);
}

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

  int h,w;
  cin >> h >> w;
  vs b(h);
  FOR(i,h) cin >> b[i];
  con.resize(h+w);
  vis.resize(h+w);
  FOR(i,h) {
    FOR(j,w) {
      if(b[i][j] == '#') {
        con[i].pb(h+j);
        con[h+j].pb(i);
      }
    }
  }

  int t = 0;
  int th=0,tw=0;
  con[0].pb(h);
  con[0].pb(h-1);
  con[0].pb(h+w-1);
  con[h].pb(0);
  con[h-1].pb(0);
  con[h+w-1].pb(0);
  dfs(0);
  FOR(i,h) {
    if(con[i].size() && !vis[i]) {
      dfs(i);t++;
    } else if(con[i].empty()) {
      th++;
    }
  }
  FOR(i,w) {
    if(con[h+i].size() && !vis[h+i]) {
      dfs(h+i);t++;
    } else if(con[h+i].empty()) {
      tw++;
    }
  }
  //cerr << t << " " << th << " " << tw << endl;
  cout << t + min(th,tw) << endl;
}

#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(){
	using t = array<long double,2>;
	int n,m; cin>>n>>m;
	int k; cin>>k;
	vi v(n+1,0); fore(i,0,k){int a; cin>>a; v[a]=1;}
	fore(i,0,n){
		if(v[i]==0)continue;
		int j = i;
		while(j<=n and v[j])j++;
		if(j-i>=m){cout<<-1<<ENDL;return;}
		i = j-1;
	}
	vc<t>dp(n+m);
	t sum = {0,0};
	for(int i = n+m-1;i>=0;i--){
		if(i>=n)dp[i]={0,0};
		else if(v[i])dp[i]={1,0};
		else dp[i]={sum[0]/(1.0*m),sum[1]/(1.*m)+1};
		sum[0]+=dp[i][0];
		sum[1]+=dp[i][1];
		if(i+m<n+m)sum[0]-=dp[i+m][0],sum[1]-=dp[i+m][1];
	}
	long double ans = dp[0][1]/(1.0-dp[0][0]);

	cout<<fixed<<setprecision(7)<<ans<<ENDL;

}

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


#include<bits/stdc++.h>
#define ll long long int
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpii vector< pii >
#define vpll vector< pll >
#define mpii map<int,int>
#define mpll map<ll,ll>
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define s(v) v.size()
#define test ll t;cin>>t;while(t--)
#define vec vector<ll>
#define read0(v,n) for(int i=0;i<n;i++)cin>>v[i];
#define read1(v,n) for(int i=1;i<=n;i++)cin>>v[i];
#define trav(a,x) for (auto& a: x)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define cut(x) {cout<<x;return 0;}
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORB(i,a,b) for(int i=a;i>=b;i--)

#define mp make_pair
#define pb push_back
#define eb emplace_back
#define f first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define nl '\n'
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
#define oset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
ll gcd(ll a, ll b)
{
	if (b==0)return a;
	return gcd(b, a % b);
}
ll lcm(ll a,ll b)
{
    return (a*b)/gcd(a,b);
}
ll pow(ll a, ll b)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%MOD;
		b/=2;
		a=(a*a)%MOD;
	}
	return ans;
}

const int N=2005;
ll a[N][N],row[N][N],col[N][N],dia[N][N];
char g[N][N];
int main()
{
	fast
	ll n,m;
    cin>>n>>m;
    FOR(i,1,n)
    {
        string s;
        cin>>s;
        FOR(j,1,m)
        {
            g[i][j]=s[j-1];
        }
    }
    FOR(i,1,n)
    {
        FOR(j,1,m)
        {
            if(i==1 and j==1){a[i][j]=0;row[i][j]=1;col[i][j]=1;dia[i][j]=1;continue;}
            if(g[i][j]=='#')
            {
                row[i][j]=0;col[i][j]=0;row[i][j]=0;
                a[i][j]=0;
            }
            else
            {
                ll x=0,y=0,z=0;
                if(i-1>=1)x=col[i-1][j];
                if(i-1>=1 and j-1>=1)y=dia[i-1][j-1];
                if(j-1>=1)z=row[i][j-1];
                a[i][j]=x+y+z;
                row[i][j]=a[i][j]+(j-1>=1?row[i][j-1]:0);
                col[i][j]=a[i][j]+(i-1>=1?col[i-1][j]:0);
                dia[i][j]=a[i][j]+(j-1>=1 and i-1>=1?dia[i-1][j-1]:0);
                row[i][j]%=MOD;
                col[i][j]%=MOD;
                dia[i][j]%=MOD;
                a[i][j]%=MOD;
            }
        }
    }

   // FOR(i,1,n)FOR(j,1,m)cout<<dp[i][j]<<(j==m?nl:' ');
    cout<<a[n][m];

}


#define _CRT_SECURE_NO_WARNINGS
#define _SCL_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <utility>
#include <algorithm>
#include <functional>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <limits>
#include <numeric>
#include <valarray>
#include <fstream>
#include <array>
#include <random>
#include <unordered_set>
#include <unordered_map>

using namespace std;
using uint = uint32_t;
using LL = int64_t;
using ULL = uint64_t;
using PP = pair<LL, LL>;
template <typename T> using PriorityQ = priority_queue<T, vector<T>, greater<T> >;
#define REP(i, a, n) for(LL i = (a), i##_max_ = (n); i < i##_max_; ++i)
#define REM(i, a, n) for(LL i = (LL)(n) - 1, i##_min_ = (a); i >= i##_min_; --i)
#define FLOAT fixed << setprecision(16)
#define SPEEDUP { cin.tie(NULL); ios::sync_with_stdio(false); }
const int INF = 0x3FFFFFFF;
const LL INFLL = 0x3FFFFFFF3FFFFFFF;
const double INFD = 1.0e+308;
const double EPS = 1.0e-9;

void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
template <class T, class U> istream& operator>>(istream& ist, pair<T, U>& right) { return ist >> right.first >> right.second; }
template <class T, class U> ostream& operator<<(ostream& ost, const pair<T, U>& right) { return ost << right.first << ' ' << right.second; }
template <class T, class TCompatible, size_t N> void Fill(T(&dest)[N], const TCompatible& val) { fill(dest, dest + N, val); }
template <class T, class TCompatible, size_t M, size_t N> void Fill(T(&dest)[M][N], const TCompatible& val) { for (int i = 0; i < M; ++i) Fill(dest[i], val); }
template <class T> T Next() { T buf; cin >> buf; return buf; }
istream& Ignore(istream& ist) { string s; ist >> s; return ist; }
bool Inside(int i, int j, int h, int w) { return i >= 0 && i < h && j >= 0 && j < w; }

#ifdef ONLY_MY_ENVIR
#include "Accumulator.h"
#include "Algebraic.h"
#include "BinaryMatrix.h"
#include "BinaryTree.h"
#include "Bipartite.h"
#include "BIT.h"
#include "Compressor.h"
#include "Decompositions.h"
#include "DiscreteLog.h"
#include "DominatorTree.h"
#include "DynamicMod.h"
#include "Exponential.h"
#include "Factorization.h"
#include "FFT.h"
#include "Field.h"
#include "FlatTree.h"
#include "FlowSolver.h"
#include "Geometric2D.h"
#include "Geometric2DFloat.h"
#include "Geometric3D.h"
#include "Geometric3DFloat.h"
#include "Graph.h"
#include "GraphUtil.h"
#include "HLD.h"
#include "Interpolation.h"
#include "IntMod.h"
#include "KDTree.h"
#include "LazySegmentTree.h"
#include "LCA.h"
#include "LIS.h"
#include "List.h"
#include "Math.h"
#include "MathUtil.h"
#include "Matrix.h"
#include "MinCostFlowSolver.h"
#include "MinMax.h"
#include "Numbers.h"
#include "Optimize.h"
#include "Permutation.h"
#include "Polynomial.h"
#include "Position.h"
#include "Quadratic.h"
#include "Random.h"
#include "Range.h"
#include "Rational.h"
#include "RollingHash.h"
#include "RuntimeMod.h"
#include "SafeInt.h"
#include "SegmentTree.h"
#include "SegmentTree2D.h"
#include "Sets.h"
#include "Shortest.h"
#include "SlidingWindow.h"
#include "SpanningTree.h"
#include "StringSearching.h"
#include "SuffixArray.h"
#include "SwitchList.h"
#include "Timer.h"
#include "Tree.h"
#include "TreeUtil.h"
#include "UnionFind.h"
#include "Util.h"
#include "VectorUtil.h"
#endif

#ifdef __GNUC__
typedef __int128 LLL;
istream& operator>>(istream& ist, __int128& val) { LL tmp; ist >> tmp; val = tmp; return ist; }
ostream& operator<<(ostream& ost, __int128 val) { LL tmp = val; ost << tmp; return ost; }
#endif

int main() {
	int K;
	cin >> K;
	int cnt = 0;
	REP(i, 1, K + 1) {
		REP(j, 1, K + 1) {
			if (i * j > K) break;
			REP(k, 1, K + 1) {
				if (i * j * k > K) break;
				++cnt;
			}
		}
	}
	cout << cnt << endl;
	return 0;
}

#include<bits/stdc++.h>
#define int long long
#define forr(i,l,r) for(int i=l;i<=r;i++)
#define ffor(i,r,l) for(int i=r;i>=l;i--)
using namespace std;
signed main()
{
	int a,b,c;
	cin>>a>>b>>c;
	cout<<a+b+c-min(a,min(b,c))<<endl;
	return 0;
}


/**
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */
#include <bits/stdc++.h>
using namespace std;

const bool ready = [](){
    ios_base::sync_with_stdio(false); cin.tie(0);
    cout << fixed << setprecision(12);
    return true;
}();

using ld=long double;
const ld PI = acos((ld)-1);
using ll= long long;
#define int ll
#define all(v) (v).begin(), (v).end()
#define fori(n) for(int i=0; i<int(n); i++)

#define cini(i) int i; cin>>i;
#define cins(s) string s; cin>>s;
#define cind(d) ld d; cin>>d;
#define cinai(a,n) vi a(n); fori(n) { cin>>a[i]; }
#define cinas(s,n) vs s(n); fori(n) { cin>>s[i]; }
#define cinad(a,n) vd a(n); fori(n) { cin>>a[i]; }

using pii= pair<int, int>;
using pdd= pair<ld, ld>;
using vd= vector<ld>;
using vb= vector<bool>;
using vi= vector<int>;
using vvi= vector<vi>;
using vs= vector<string>;

#define endl "\n"

/*
 * dijkstra?
 * I mean, why not?
 * ->There are 500^2 vertex, so a lot of edges...
 *
 * Is it ever beneficial to go north?
 * -> Yes, can be :/
 *
 * Can we implement the North moves somewhat faster?
 * What about starting from the other end?
 * ...nothing
 *
 * Try dijkstra
 */
const int INF=1e18;
void solve() {
    cini(r);
    cini(c);

    vvi a(r, vi(c-1));
    for(int i=0; i<r; i++)
        for(int j=0; j<c-1; j++)
            cin>>a[i][j];

    vvi b(r-1, vi(c));
    for(int i=0; i<r-1; i++)
        for(int j=0; j<c; j++)
            cin>>b[i][j];

    vvi dp(r, vi(c, INF));
    dp[0][0]=0;
    using t3=tuple<int,int,int>;
    priority_queue<t3> q;   /* c, i, j */
    q.emplace(0, 0, 0);
    while(q.size()) {
        auto [cost,i,j]=q.top();
        if(i==r-1 && j==c-1) {
            cout<<dp[r-1][c-1]<<endl;
            return;
        }
        q.pop();
        if(-cost!=dp[i][j])
            continue;

        if(j+1<c && dp[i][j]+a[i][j]<dp[i][j+1]) {
            dp[i][j+1]=dp[i][j]+a[i][j];
            q.emplace(-dp[i][j+1], i, j+1);
        }
        if(j>0 && dp[i][j-1]>dp[i][j]+a[i][j-1]) {
            dp[i][j-1]=dp[i][j]+a[i][j-1];
            q.emplace(-dp[i][j-1], i, j-1);
        }
        if(i+1<r && dp[i+1][j]>dp[i][j]+b[i][j]) {
            dp[i+1][j]=dp[i][j]+b[i][j];
            q.emplace(-dp[i+1][j], i+1, j);
        }
        for(int k=0; k<i; k++) {
            if(dp[k][j]>dp[i][j]+1+i-k) {
                dp[k][j]=dp[i][j]+1+i-k;
                q.emplace(-dp[k][j], k, j);
            }
        }
    }

    assert(false);
}

signed main() {
    solve();
}

#include <bits/stdc++.h>

#include <random>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#pragma GCC target("avx2")
#pragma GCC optimize("O3,unroll-loops")
using ll = long long;
using ull = unsigned long long;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) for (int(i) = 0; (i) < int(n); (i)++)
#define repi(i, a, b) for (int(i) = (a); (i) < int(b); (i)++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep)(__VA_ARGS__)
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;
}
constexpr int dy[4] = {-1, 0, 1, 0};
constexpr int dx[4] = {0, -1, 0, 1};
constexpr ll MOD = 1'000'000'007LL; /*998'244'353LL;*/

template <typename T>
struct Dijkstra {
    vector<vector<pair<int, short>>> e;
    vector<T> cost;
    Dijkstra(int V) : e(V) {}
    void add(int u, int v, T weight) {
        e[u].push_back({v, weight});
        e[v].push_back({u, weight});
    }
    void add_directed(int from, int to, T weight) {
        e[from].push_back({to, weight});
    }
    vector<T>& calculate(int s, T def) {
        cost.resize(e.size(), def);
        priority_queue<pair<T, int>> pq;
        cost[s] = 0;
        pq.push({0, s});
        while (!pq.empty()) {
            int n = pq.top().second;
            if (-pq.top().first != cost[n]) {
                pq.pop();
                continue;
            }
            pq.pop();
            for (int i = 0; i < e[n].size(); i++) {
                if (cost[e[n][i].first] > cost[n] + e[n][i].second) {
                    cost[e[n][i].first] = cost[n] + e[n][i].second;
                    pq.push({-cost[e[n][i].first], e[n][i].first});
                }
            }
        }
        return cost;
    }
};

int R, C;
Dijkstra<int> G(0);

signed main() {
    cin >> R >> C;
    G = Dijkstra<int>(2 * R * C);
    rep(i, R) {
        rep(j, C - 1) {
            int a;
            cin >> a;
            G.add(i * C + j, i * C + j + 1, a);
        }
    }
    rep(i, R - 1) {
        rep(j, C) {
            int a;
            cin >> a;
            G.add_directed(i * C + j, (i + 1) * C + j, a);
        }
    }
    rep(i, R) {
        rep(j, C) {
            G.add_directed(i * C + j, R * C + i * C + j, 1);
            G.add_directed(R * C + i * C + j, i * C + j, 0);
            if (i - 1 >= 0)
                G.add_directed(R * C + i * C + j, R * C + (i - 1) * C + j, 1);
        }
    }
    cout << G.calculate(0, 2e9)[R * C - 1] << endl;
}


#include<bits/stdc++.h>
// no of bits to store no 2e5 is 19
// 2e5 ka 5 times square root lene se 2 or 3 ke pass pahunch jate hai
using namespace std;

#define int               long long
#define mod               1000000007
#define MAX               1000000000
#define ff                first
#define ss                second
#define mp                make_pair
#define pb                push_back
#define pii               pair<int,int>
#define sp(x,y)           fixed<<setprecision(y)<<x
#define setbits(x)        __builtin_popcount(x)
#define fast_in_out       ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define rep(i,a,b)        for(int i=a;i<b;i++)
#define ll                long long

//   powermod(a,b,m) ==  powermod(a,b%(m-1),m)  when m is prime fermat's theorem a^(p-1) %p=1 p is prime
int powermod(int a,int b,int c) //  gives (a^b)%c
{
    int ans = 1,tempans=a%c;
    while(b>0)
    {
        if(b&1==1)
        {
            ans=(ans*tempans)%c;
        }
             tempans=(tempans*tempans)%c;
             b=b>>1;
    }
    return ans;
}

int modinverse(int a,int m)   // gives a inverse wrt m and m is prime
{
    return powermod(a,m-2,m);
}

ll add(ll x, ll y) {
   x += y;
   if (x >= mod) return x - mod;
   return x;
}
ll sub(ll x, ll y) {
   x -= y;
   if (x < 0) return x + mod;
   return x;
}
ll mult(ll x, ll y) {
   return (x * y) % mod;
}
// my template                                              m
// prime factorization                                      pf
// ncr and factorials                                       ncr
// matrix exponentiation of fibonacci series in log(n)      matexpofib
// cycles in a graph                                        cycle

bool compare(pii p1,pii p2)
{
   int x1=p1.ff,y1=p1.ss;
   int x2=p2.ff,y2=p2.ss;
   int on= 2*x1 + y1;
   int se=2*x2 + y2;
   return on>se;
}

void solve()
{
   int n;
   cin>>n;
   pii a[n];int sum=0;
   rep(i,0,n)
   {
      cin>>a[i].ff>>a[i].ss;
      sum+=a[i].ff;
   }
   sort(a,a+n,compare);
   int temp=0;int ans=0;
   for(int i=0;i<n;i++)
   {
      int x=a[i].ff;
      int y=a[i].ss;
      sum-=x;
      temp+=(x+y);ans++;
      if(temp>sum)
      {
         break;
      }
   }
   cout<<ans<<endl;

}

int32_t main()
{
  fast_in_out;

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

   while(t--)
   {
       count++;
       solve();
   }
}

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

int main() {
    int n;
    cin >> n;
    int a[n],b[n],c[n];
    for(int i=0; i<n; i++) {
        cin >> a[i];
        a[i]--;
    }
    for(int i=0; i<n; i++) {
        cin >> b[i];
        b[i]--;
    }
    for(int i=0; i<n; i++) {
        cin >> c[i];
        c[i]--;
    }
    vector<int>cnt(n);
    for(int j=0; j<n; j++) {
        cnt[b[c[j]]]++;
    }
    long long ans=0;
    for(int i=0; i<n; i++) ans+=cnt[a[i]];
    cout << ans << endl;
}


#include <bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define vl vector<long long>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_lr(i, f, n) for (int i = f; i < (int)(n); i++)
#define maxe(v) *max_element(v.begin(),v.end())
#define mine(v) *min_element(v.begin(),v.end())
#define sorts(v) sort(v.begin(),v.end())
#define sortg(v) sort(v.begin(),v.end(),greater<int>)
using namespace std;

string replace_all(string &s, string from, string to) {
    ll pos = s.find(from);
    while(true){
      pos = s.find(from, pos);
      if(pos==-1) break;
      s.replace(pos, from.length(), to);
      pos += to.length();
    }
    return s;
}

void solve(){

    setprecision(15);

    int N;
    cin >> N;
    vl x(N);
    rep(i,N){
        cin>>x.at(i);
        x.at(i) = abs(x.at(i));
    }

    ll ans=0;
    rep(i,N){
        ans += x.at(i);
    }
    cout << ans << endl;

    ans = 0;
    rep(i,N){
        ans += pow(x.at(i),2);
    }
    cout << setprecision(20) << sqrtl(ans) << endl;

    cout << maxe(x) << endl;
}

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

#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <iterator>
#include <numeric>
#include <cstdint>
#include <cmath>
#include <bitset>
#include <string>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <random>
#include <chrono>
#include <cassert>

#define N_TIMES(i, n)     for ( uint64_t i = 0;     i <  n; ++i )
#define N_TIMES_REV(i, n) for (  int64_t i = n - 1; i >= 0; --i )

template<typename T>
std::istream& operator>>(std::istream &is, std::vector<T> &v)
{
  for (typename std::vector<T>::size_type i = 0; i < v.size(); ++i) {
    is >> v[i];
  }
  return is;
}

template<typename T>
const T& max(const std::vector<T> &v)
{
  return *std::max_element(v.begin(), v.end());
}

template<typename T>
const T& min(const std::vector<T> &v)
{
  return *std::min_element(v.begin(), v.end());
}

using namespace std;

ostream& operator<<(ostream &os, const vector<int64_t> &a)
{
  for (vector<int64_t>::size_type i = 0; i < a.size(); ++i) {
    os << a[i];
    if (i + 1 < a.size()) { os << ' '; }
  }
  return os;
}

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

  string S;
  cin >> S;

  vector<int64_t> A(N + 1);
  cin >> A;

  vector<int64_t> D(N, 0);
  N_TIMES(n, N) { D[n] = abs(A[n + 1] - A[n]); }
  int64_t min_D = min(D);

  vector< vector<int64_t> > Bs(min_D, vector<int64_t>(N + 1, 0));
  N_TIMES(n, N + 1) {
    N_TIMES(i, min_D) {
      Bs[i][n] = (A[n] / min_D) + (i < (A[n] % min_D) ? 1 : 0);
    }
  }

  cout << Bs.size() << endl;
  for (const vector<int64_t> &B : Bs) {
    cout << B << endl;
  }

  return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
using namespace std;
#define int long long
#define double long double
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define M2 1000000009
#define M1 998244353
#define inf 1e18
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

using namespace __gnu_pbds;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> new_data_set;
bool isprime(int n){
    	if(n==1) return false;
    	for(int i = 2;i*i<=n;i++){
    		if(n%i==0) return false;
		}
		return true;
}
int lcm(int a,int b){
	return (a*b)/__gcd(a,b);
}
int gcd(int a, int b){
    if (b == 0){
    	return a;
	}
    return gcd(b, a % b);

}
int power(int x,int y,int p){
    int res=1;
    if(x==0)return 0;
    while(y>0){
        if(y&1){
        	res*=x;
        	res%=p;
		}
        y=y>>1;
        x=(x*x);
		x%=p;
		res%=p;
    }
    return res;
}
int modInverse(int n, int p){
    return power(n, p-2,p);
}
struct node{
	int a,b;
};

/*    BAAP BAAP HOTA HAI
      Author : Sagar          */

signed main(){
	FAST
	int n;
	cin>>n;
	int ans=n;
	int tp=1;
	for(int i=1;i<60;i++){
		tp*=2;
		if(tp>n)break;
		int a=n/tp;
		int c=n%tp;
		ans=min(ans,a+i+c);
	}
	cout<<ans;
}

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

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

  int64_t a, b, c;
  int64_t kai;
  int64_t ans = -1;

  if(N == 1) cout << 1 << endl;
  else
  {
    b = 0;
    kai = 1;
    while(true)
    {
      b++;
      kai *= 2;
      if(N < kai) break;
      a = N / kai;
      c = N - a * kai;

      if(ans == -1) ans = a + b + c;
      else if(a + b + c < ans) ans = a + b + c;
    }

    cout << ans << endl;
  }
}


#include<bits/stdc++.h>
//#include <atcoder/all>

#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define ALL(a)  (a).begin(),(a).end()
#define pb push_back
#define fi first
#define se second
#define sz(x) ((int)x.size())

using namespace std;
//using namespace atcoder;
using ld = long double;
using ll = long long;
using P = pair<ll, ll>;

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

const ll ZER = 0;
const ll MOD = 1e9 + 7;
const ll INF = 1e9;
const ll LINF = 1e18;

int main(){
    ll od = 0, ev = 0;
    int n, k;
    cin >> n >> k;
    rep(i, n){
        int cnt = 0;
        string s;
        cin >> s;
        rep(j, sz(s)){
            if(s[j] == '1')cnt++;
        }
        // cout << cnt << endl;
        if(cnt % 2 == 1)od++;
        else ev++;
    }
    cout << ev * od << endl;
}

#include<bits/stdc++.h>

#define  all(v)            v.begin(), v.end()
#define  sz(x)             (int)x.size()
#define  debug(x)          cout << #x << ':' << x << endl;
#define  rep(i,n)          for(long long i = 0; i <  n ; i++)
#define  reps(i,n)         for(long long i = 1; i <= n ; i++)
#define  make_unique(v)    sort(all(v));v.erase(unique(all(v)), v.end());
#define  REMOVE(v,a)       v.erase(remove(v.begin(),v.end(), a), v.end());
#define  pb                push_back
#define  mp                make_pair
#define  endl              '\n'
#define  fi                first
#define  se                second

using namespace std;
typedef long long          ll;
typedef vector<long long>  vll;
typedef pair<ll,ll>        pll;
const ll MOD = 1e9+7;
bool cmp(int X, int Y) {return X > Y;}

ll gcd(ll a, ll b) {return !b ? a : gcd(b, a % b);}
ll lcm(ll a, ll b) {return (a / gcd(a, b)) * b;}
ll modpow(ll a, ll b, ll m=MOD){a %= m; ll res = 1; while (b) {if (b & 1)res = (res * a) % m; a = (a * a) % m; b >>= 1;} return res;}
ll bpow(ll a, ll b){if(b<0){return 0;}ll res = 1; while (b) {if (b & 1)res = res * a; a = a * a; b >>= 1;} return res;}
ll modinv(ll a, ll m = MOD) {return modpow(a, m - 2, m);}

const int N = 100005;
const int dx4[4] = {0, 1, 0, -1};
const int dy4[4] = {-1, 0, 1, 0};

ll vis[N];

ll fact(ll x){
  ll res = 1;
  for(ll i = 1; i<=x ; i++){
    res*=i;
    res = (res+MOD)%MOD;
  }
  return res;
}

int main(){ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
string s;cin>>s;
ll len = s.length();
if(len<3){
  int y = stoi(s);
  if(y%8 == 0){cout<<"Yes"<<endl;}
  else{
    reverse(all(s));
    int tt = stoi(s);
    if(tt%8 == 0){cout<<"Yes";}
    else{
      cout<<"No";
    }
  }
  return 0;
}
vector<ll>se[112];
ll k = 0;

for(ll i = 101; i<1000; i++){
  if(i%8 == 0){
    ll n = i;
    while(n>0){
      ll num = n%10;
      se[k].push_back(num);
      n = n/10;
    }
    k++;

  }
}
map<ll,ll>cnt;
rep(i,(ll)s.length()){
  cnt[(ll)(s[i] - '0')]++;
}
bool check = false;
for(ll i = 0; i<112; i++){
  bool ch = true;
  map<ll,ll>cnt2;
  for(auto u : se[i]){
    cnt2[u]++;

  }
  for(auto u : se[i]){
    if(cnt[u] < cnt2[u]){ch = false;}
  }
  if(ch && (se[i].size() > 0)){check = true;}
}
if(check){
  cout<<"Yes"<<endl;
}else{
  cout<<"No"<<endl;
}

}


#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

int main() {
	int x, y, z;
	cin >> x >> y >> z;

	cout << (y * z - 1) / x << endl;
}

//#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cctype>
#include<vector>
#include<map>
#include<deque>
#include<queue>
using namespace std;

#define re register
#define inf 0x3f3f3f3f
//#define inf 0x3f3f3f3f3f3f3f3f
#define ll long long
//#define int ll
//#define x first
//#define y second

typedef pair<int,int> PII;

template<typename T>
inline void read(T &x){
	re char ch=getchar();re bool f=false;x=0;
	while(!isdigit(ch)){if(ch=='-'){f=true;}ch=getchar();}
	while(isdigit(ch)){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
	x=f?-x:x; return ;
}

template<typename T>
inline void write(T x){
	if(x<0){putchar('-');x=-x;}
	if(x>=10){write(x/10);}
	putchar(x%10+'0');
}

signed main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	int x,y,z; read(x),read(y),read(z);
	int ans;
	ans=z*y;
	if(ans%x==0) ans=ans/x-1;
	else ans/=x;
	write(ans);
	return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <cmath>
using namespace std;

const int INF = 2000000000;
double X,Y,Z;

int main() {
    // Step #1. Input
    cin >> X >> Y >> Z;
    double ans=Y*Z/X;
    int re;
    if(ans-floor(ans)==0){
        re=ans-1;
    }else{
        re=ans;
    }
    cout << re << endl;

}

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

int main(){
  int a,b,Xcor,Xstep;
  cin >> a >> b >> Xcor >> Xstep;

  int Xupdown= min(2*Xcor, Xstep);

  int ans= (a <= b) ? Xupdown*(b-a) + Xcor
                    : Xupdown*(a-b-1)+ Xcor;

  cout << ans << endl;
}


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

int main(){
  char S,T;
  cin >> S;
  cin >> T;

  if(S=='Y'){
    if(T=='a') cout << "A" << endl;
    if(T=='b') cout << "B" << endl;
    if(T=='c') cout << "C" << endl;
  }else{
    cout << T << endl;
  }
}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
const int MAXN=2e5+10;
const ll MOD=17;
ll _gcd(ll a,ll b){if(b==0)return a;return _gcd(b,a%b);}
ll gcd(ll a,ll b){a=abs(a),b=abs(b);if(a<b)swap(a,b);return _gcd(a,b);}
ll qpow(ll a,ll n){ll rt=1;while(n){if(n&1)rt=(rt*a)%MOD;a=a*a%MOD;n>>=1;}return rt;}
ll factor[MAXN];
void cal_factor(){factor[0]=1;for(int u=1;u<MAXN;u++){factor[u]=(factor[u-1]*u)%MOD;}}
ll C(ll n,ll k){if(n<k)return 0;return factor[n]*qpow(factor[n-k],MOD-2)%MOD*qpow(factor[k],MOD-2)%MOD;}
void solve(){
    multiset<int>dig;
    string s;
    cin>>s;
    for(char c:s){
        dig.insert(c-'0');
    }
    vector<int>m8[4];
    for(int m=8;m<1000;m+=8){
        int len=0;
        int t=m;
        while(t){
            t/=10;
            len++;
        }
        m8[len].push_back(m);
    }
    if(dig.size()==1){
        if(*dig.begin()==8){
            cout<<"Yes\n";
        }else {
            cout<<"No";
        }
        return;
    }else {
        int f=dig.size()>2?3:2;
        bool match=false;
        for(int m:m8[f]){
            int t=m;
            multiset<int>tdig=dig;
            bool ed=true;
            while(t){
                if(tdig.count(t%10)==0){
                    ed=false;break;
                }else tdig.erase(tdig.find(t%10));
                t/=10;
            }
            if(ed){
                match=true;
                break;
            }
        }
        if(match)cout<<"Yes\n";
        else cout<<"No\n";
    }
}
// #define LOCAL
int main()
{
#ifdef LOCAL
    freopen("in.txt","r",stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    solve();
}

#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
//using mint = modint1000000007;
//using mint = modint998244353;
template <typename T> bool chmax(T &u, const T z) { if (u < z) {u = z; return true;} else return false; }
template <typename T> bool chmin(T &u, const T z) { if (u > z) {u = z; return true;} else return false; }
#define ll long long
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef pair<ll, int> P;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll a, ll b){return a * b / gcd(a, b);}
//解説写し
int main(){
  int n;
  cin>>n;
  int m=5;
  vector<vector<int>>a(n,vector<int>(m));
  rep(i,n)rep(j,m)cin>>a[i][j];
  int l=0,r=1001001001;
  while(r-l>1){
    int mid=(l+r)/2;
    vector<int>s;
    rep(i,n){
      int x=0;
      rep(j,m){
        if(a[i][j]>=mid)x|=1<<j;
      }
      s.push_back(x);
    }
    sort(s.begin(),s.end());
    s.erase(unique(s.begin(),s.end()),s.end());
    bool ok=false;
    rep(i,s.size())rep(j,i+1)rep(k,j+1){
      if((s[i]|s[j]|s[k])==(1<<m)-1)ok=true;
    }
    if(ok)l=mid;else r=mid;
  }
  cout<<l<<endl;
  return 0;
}


#include <bits/stdc++.h>
using Int = long long;  // clang-format off
using pii = std::pair<Int, Int>;
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define RREP_(i, a_, b_, a, b, ...) for (Int i = Int(b) - 1, low##i = (a); i >= low##i; i--)
#define RREP(i, ...) RREP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define ALL(v) std::begin(v), std::end(v)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef dump
#define dump(...)
#endif  // clang-format on
struct in {
    template <class T> operator T() {
        T t;
        std::cin >> t;
        return t;
    }
};
void out() { std::cout << "\n"; }
template <class Head, class... Tail> void out(Head&& h, Tail&&... t) {
    std::cout << h << (sizeof...(Tail) == 0 ? "" : " "), out(std::forward<Tail>(t)...);
}
template <class T> bool chmin(T& a, const T& b) { return a > b ? a = b, true : false; }
template <class T> bool chmax(T& a, const T& b) { return a < b ? a = b, true : false; }
template <class T> using V = std::vector<T>;

/**
 *    author:  knshnb
 *    created: Sun May 23 20:22:56 JST 2021
 **/

/// @docs src/DataStructure/SegmentTree.md
template <class T, class F> struct SegmentTree {
    const F op;
    const T e;
    SegmentTree(F op_, T e_) : op(op_), e(e_) {}
    int n;
    std::vector<T> t;
    void set_by_identity(int n_) {
        n = n_;
        t.clear(), t.resize(2 * n, e);
    }
    void set_by_vector(const std::vector<T>& a) {
        n = a.size();
        t.clear(), t.resize(2 * n, e);
        for (int i = 0; i < n; i++) t[i + n] = a[i];
        build();
    }
    void build() {
        for (int i = n - 1; i; --i) t[i] = op(t[2 * i], t[2 * i + 1]);
    }
    T& operator[](int i) { return t[i + n]; }
    // [l, r)
    T query(int l, int r) const {
        assert(0 <= l && l <= r && r <= n);
        T resl = e, resr = e;
        for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
            if (l & 1) resl = op(resl, t[l++]);
            if (r & 1) resr = op(t[--r], resr);
        }
        return op(resl, resr);
    }
    // i番目をxに変更
    void update(int i, const T& x) {
        assert(0 <= i && i < n);
        t[i += n] = x;
        while (i >>= 1) t[i] = op(t[2 * i], t[2 * i + 1]);
    }
    // i番目にxを作用 (a[i] = op(a[i], x))
    void operate(int i, const T& x) {
        assert(0 <= i && i < n);
        i += n;
        t[i] = op(t[i], x);
        while (i >>= 1) t[i] = op(t[2 * i], t[2 * i + 1]);
    }
    friend std::string to_string(const SegmentTree<T, F>& seg) {
        return to_string(std::vector<T>(seg.t.begin() + seg.n, seg.t.end()));
    }
};
template <class T, class F> auto make_segment_tree(F op, T e) { return SegmentTree<T, F>(op, e); }

signed main() {
    Int n = in();
    V<Int> a(n), b(n);
    REP(i, n) a[i] = in();
    REP(i, n) b[i] = in();
    std::reverse(ALL(a));
    std::reverse(ALL(b));
    REP(i, n) a[i] -= i;
    REP(i, n) b[i] -= i;
    std::map<Int, std::set<Int>> mpb;
    V<Int> idx(n);
    REP(i, n) { mpb[b[i]].insert(i); }
    REP(i, n) {
        auto it = mpb[a[i]].begin();
        if (it == mpb[a[i]].end()) {
            out(-1);
            return 0;
        }
        idx[i] = *it;
        mpb[a[i]].erase(it);
    }
    dump(idx);
    Int ans = 0;
    auto seg = make_segment_tree<Int>([](Int x, Int y) { return x + y; }, 0);
    seg.set_by_identity(n);
    REP(i, n) {
        ans += i - seg.query(0, idx[i]);
        seg.operate(idx[i], 1);
    }
    out(ans);
}

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>
#include<climits>
#include<complex>
using namespace std;
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')';}
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) {os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#define int long long
template<typename T>
void dbg_a(T *a,int l,int r){cout<<" {";for(int i = l;i<r;i++) cout<<a[i]<<", ";cout<<a[r]<<"}"<<endl;}
typedef long long ll;
template<typename T = int>
inline T read(){
    T f = 1,r = 0;
    char c = getchar();
    while(c<'0'||c>'9'){if(c == '-') f = -1; c = getchar();}
    while(c>='0'&&c<='9'){ r = (r<<1) + (r<<3) + c - '0';c = getchar();}
    return f*r;
}
typedef pair<int,int> PII;
#define fi first
#define se second
#define mst(a,b) memset(a,b,sizeof(a))
#define For(i,a,b) for(int i = a;i<=b;i++)
#define For_(i,a,b) for(int i = a;i>=b;i--)
#define _for(i,a) for(int i = 0;i<a;i++)
#define All(x) x.begin(),x.end()

//    For(i,1,n) For(j,1,m) printf("f[%lld][%lld] = %lld\n",a,b,c);

const int N = 50 + 2,M = N*2 + 10,INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;

int n,m,x;
int a[N],mx[N],dp[N][2],k[N];
signed main(){
    n = read();x = read();
    For(i,1,n) a[i] = read();
    For(i,1,n-1) mx[i] = a[i+1]/a[i];
    For_(i,n,1){
        k[i] = x/a[i];
        x %= a[i];
    }

    dp[1][0] = 1;
    if(k[1]) dp[1][1] = 1;
    For(i,1,n-1){
        dp[i+1][0] = dp[i][0];
        if(k[i + 1]) dp[i+1][1] = dp[i][0];
        dp[i+1][1] += dp[i][1];
        if(k[i+1] + 1 != mx[i + 1]) dp[i+1][0] += dp[i][1];
    }
    cout<<dp[n][0]<<"\n";
    return 0;
}


//dragon->emperor
#include <bits/stdc++.h>

using namespace std;

/**********************************************************************************/

#define mod 1000000007
#define mod2 998244353
const double pi = acos(-1);
#define inf 1e18+5
#define iinf 1e9+5

#define ll long long
#define ld  long double
#define floop(i,a,n) for(ll i=a;i<n;i++)
#define loopf(i,a,n) for(ll i=n-1;i>=a;i--)
#define space " "
#define TEST(t) ll t; cin>>t; while(t--)
#define r(n) ll n; cin>>n;
#define r1(a,n) ll a[n]; for(ll i=0;i<n;i++) cin>>a[i];
#define p1(a,n) for(ll i=0;i<n;i++) cout<<a[i]<<" "; cout<<endll;
#define p2(n) cout<<n<<" ";
#define p(n) cout<<n<<endll;

#define endll "\n"
#define pb push_back
#define mp make_pair
#define dec(n) fixed<<setprecision(n)
#define F first
#define S second
#define I insert
#define E end()
#define B begin()

#define all(x) x.begin(), x.end()
#define sortall(x) sort(all(x))
#define reverseall(x) reverse(all(x))

typedef vector<ll> vl;
typedef pair<ll,ll> pll;
typedef map<ll,ll> mll;

/************************************FUNCTIONS*************************************/

bitset<200000>vis(0);
vector<bool> prime;

void primes(ll n)
{
    prime.resize(n+1);
    prime.assign(n+1,true);
    prime[0]=0;
    prime[1]=0;
    for(ll i=2; i*i<=n; i++)
    {
        if(prime[i])
        {
            for(ll j=(i*i); j<n; j=j+i) prime[j]=false;
        }
    }
}

void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

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

ll powM(ll x, ll y, ll m)
{
    ll ans=1, r=1;
    x=x%m;
    while(r>0 && r<=y)
    {
        if(r & y)
        {
            ans=ans*x;
            ans=ans%m;
        }
        r=r<<1;
        x=x*x;
        x=x%m;
    }
    return ans;
}

ll powN(ll a, ll n)
{
    ll ans=1;
    while(n>0)
    {
        if(n & 1) ans=ans*a;
        a=a*a;
        n >>= 1;
    }
    return ans;
}

ll modinv(ll a,ll m)
{
    return powM(a,m-2,m);
}

ll ncr(ll n, ll r, ll m)
{
    if(n<r) return 0;
    if(n==r || r==0) return 1;
    if(r==1) return n;
    if(n-r<r) return ncr(n,n-r,m);
    ll a=n;
    ll b=r;
    for(ll i=1; i<r; i++)
    {
        a=(a*(n-i))%m;
        b=(b*(r-i))%m;
    }
    b=modinv(b,m);
    a=(a*b)%m;
    return a;
}

ll countbits(ll n)
{
    ll cot=0;
    while(n)
    {
        cot++;
        n >>= 1;
    }
    return cot;
}

ll check_prime(ll n)
{
    ll ans=1;
    for(ll i=2; i*i<=n; i++)
    {
        if(n%i==0) { ans=0; break;}
    }
    if(n==0) ans=0;
    return ans;
}

/*************************************CODE*****************************************/

int main()
{
    fast();
    ll t=1;
    // cin>>t;
    while(t--)
    {
        ll n; cin>>n;
        vector<ll> a(n);
        floop(i,0,n) cin>>a[i];
        sortall(a);
        ll ans;
        ans=gcd(a[0],a[1]);
        floop(i,2,n)
        {
            ans=gcd(ans,a[i]);
        }
        p(ans);
    }
    return 0;
}

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

#define PB push_back
#define ll long long
#define endl "\n"
#define uwu                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define F0R(i, a, b) for (int i=a; i<(b); i++)
#define FOR(i, a) for (int i=0; i<(a); i++)

void solve() {
    int n;
    cin >> n;
    cout << n - 1 << endl;
}

int main() {
    uwu
    ll t = 1;
    while (t--) {
        solve();
    }
    return 0;
}


//Coded by Chirath Nirodha
#include<bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define MP make_pair
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
using namespace std;
const ll mod=1e9+7;
inline void io(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
}
pair<int,int> s;
int t[50][50];
ll p[50][50];
ll dp[50][50];
bool visited[50][50];
string path[50][50];
void makevisit(int a,int b){
	visited[a][b]=true;
	if(a!=49 && t[a+1][b]==t[a][b])visited[a+1][b]=true;
	if(a!=0 && t[a-1][b]==t[a][b])visited[a-1][b]=true;
	if(b!=49 && t[a][b+1]==t[a][b])visited[a][b+1]=true;
	if(b!=0 && t[a][b-1]==t[a][b])visited[a][b-1]=true;
}
void makeunvisit(int a,int b){
	visited[a][b]=false;
	if(a!=49 && t[a+1][b]==t[a][b])visited[a+1][b]=false;
	if(a!=0 && t[a-1][b]==t[a][b])visited[a-1][b]=false;
	if(b!=49 && t[a][b+1]==t[a][b])visited[a][b+1]=false;
	if(b!=0 && t[a][b-1]==t[a][b])visited[a][b-1]=false;
}
ll ans=dp[s.F][s.S];
string as;
void dfs(int a,int b){
	if(a!=49 && t[a+1][b]!=t[a][b] && visited[a+1][b]==false){
		if(dp[a][b]+p[a+1][b]+10>=dp[a+1][b]){
			path[a+1][b]=path[a][b];
			path[a+1][b].PB('D');
			dp[a+1][b]=dp[a][b]+p[a+1][b];
			if(ans<dp[a+1][b]){
				ans=dp[a+1][b];
				as=path[a+1][b];
			}
			makevisit(a+1,b);
			dfs(a+1,b);
			makeunvisit(a+1,b);
		}
	}
	if(a!=0 && t[a-1][b]!=t[a][b] && visited[a-1][b]==false){
		if(dp[a][b]+p[a-1][b]+10>=dp[a-1][b]){
			path[a-1][b]=path[a][b];
			path[a-1][b].PB('U');
			dp[a-1][b]=dp[a][b]+p[a-1][b];
			if(ans<dp[a-1][b]){
				ans=dp[a-1][b];
				as=path[a-1][b];
			}
			makevisit(a-1,b);
			dfs(a-1,b);
			makeunvisit(a-1,b);
		}
	}
	if(b!=49 && t[a][b+1]!=t[a][b] && visited[a][b+1]==false){
		if(dp[a][b]+p[a][b+1]+10>=dp[a][b+1]){
			path[a][b+1]=path[a][b];
			path[a][b+1].PB('R');
			dp[a][b+1]=dp[a][b]+p[a][b+1];
			if(ans<dp[a][b+1]){
				ans=dp[a][b+1];
				as=path[a][b+1];
			}
			makevisit(a,b+1);
			dfs(a,b+1);
			makeunvisit(a,b+1);
		}
	}
	if(b!=0 && t[a][b-1]!=t[a][b] && visited[a][b-1]==false){
		if(dp[a][b]+p[a][b-1]+10>=dp[a][b-1]){
			path[a][b-1]=path[a][b];
			path[a][b-1].PB('L');
			dp[a][b-1]=dp[a][b]+p[a][b-1];
			if(ans<dp[a][b-1]){
				ans=dp[a][b-1];
				as=path[a][b-1];
			}
			makevisit(a,b-1);
			dfs(a,b-1);
			makeunvisit(a,b-1);
		}
	}
}
void solve(){
	cin>>s.F>>s.S;
	for(int i=0;i<50;i++)for(int j=0;j<50;j++)cin>>t[i][j];
	for(int i=0;i<50;i++)for(int j=0;j<50;j++){cin>>p[i][j];dp[i][j]=p[i][j];}
	int a=s.F,b=s.S;
	makevisit(a,b);
	dfs(a,b);
	cout<<as<<endl;
}
int main(){
    io();
	solve();
	//int t;cin>>t;for(int i=0;i<t;i++)solve();
    return 0;
}

#pragma GCC optimize("O3", "unroll-loops")
#define fs first
#define sc second
#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> pii;

const int maxn = 2e5 + 10;

long long n, m, h[maxn], wi, pre1[maxn], pre2[maxn], pos, ans = 1e18;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n >> m;
	for (int i = 1; i <= n; i++)
		cin >> h[i];
	sort(h + 1, h + n + 1);
	for (int i = 2; i <= n; i += 2) {
		pre1[i] = pre1[i - 2] + (h[i] - h[i - 1]);
		pre2[i + 1] = pre2[i - 1] + (h[i + 1] - h[i]);
	}
	for (int j = 0; j < m; j++) {
		cin >> wi, pos = lower_bound(h + 1, h + n + 1, wi) - h;
		if (pos % 2)
			ans = min(ans, pre1[pos - 1] + (h[pos] - wi) + (pre2[n] - pre2[pos]));
		else
			ans = min(ans, pre1[pos - 2] + (wi - h[pos - 1]) + (pre2[n] - pre2[pos - 1]));
	}
	cout << ans << '\n';
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define forn(i, n) for (int i = 0; i < n; i++)
#define fori(i, a, b) for (int i = a; i <= b; i++)
#define ff first
#define ss second

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    LL n, m;
    cin >> n >> m;
    vector<LL> a(n), b(m);
    forn(i, n) cin >> a[i];
    forn(i, m) cin >> b[i];
    LL dp[1005][1005];
    forn(i, n + 1) forn(j, m + 1)
    {
        if (i == 0)
            dp[i][j] = j;
        else if (j == 0)
            dp[i][j] = i;
        else
            dp[i][j] = min(dp[i][j - 1] + 1, min(dp[i - 1][j] + 1, dp[i - 1][j - 1] + (a[i - 1] != b[j - 1])));
    }
    cout << dp[n][m] << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
	cin.tie(nullptr)->sync_with_stdio(false);
	int n,k;
	cin >> n >> k;
	for(int i = 0; i<k; i++){
		string s = to_string(n);
		sort(s.begin(),s.end());
		int low = stoll(s);
		reverse(s.begin(),s.end());
		int high = stoll(s);
		n = high-low;
	}
	cout << n << "\n";
	return 0;
}


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

#define ll long long int
#define ull unsigned long long int

/**********************************************/

void solve(ll n, ll k) {
	ll x = n;
	while (k--) {
		string s = to_string(x);
		sort(s.begin(), s.end(), greater<char>());
		ll g1 = stoll(s);

		reverse(s.begin(), s.end());
		ll g2 = stoll(s);

		x = g1 - g2;
	}

	cout << x << endl;
}

int main() {

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

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	ll t = 1;
	// cin >> t;
	while (t--) {
		ll n, k;
		cin >> n >> k;

		solve(n, k);
	}
}

#include <bits/stdc++.h>

#define int             long long int
#define vi              vector<int>
#define vvi             vector<vector<int>>
#define u_m             unordered_map<int,int>
#define u_s             unordered_set<int>
#define pii             pair<int,int>
#define pb(a)           push_back(a)
#define forr(a,n)       for(int i=a;i<n;i++)
#define forrr(j,a,n)    for(int j=a;j<n;j++)
#define mp              make_pair
#define ff              first
#define ss              second
#define clr(val)        memset(val, 0, sizeof(val))

#define read(a) for(auto &i:a) cin>>i
#define display(a) for(auto i:a) cout<<i<<" "
#define MOD 1000000007

inline int add(int a, int b){ int c = (a%MOD) + (b%MOD); if(c >= MOD) c -= MOD; return c; }
inline int mul(int a, int b){ return ((a%MOD) * 1ll * (b%MOD)) % MOD; }
inline int sub(int a, int b){ int c = (a%MOD) - (b%MOD); if(c < 0) c += MOD; return c; }

using namespace std;
void solve();
int32_t main()
{

    solve();

}
void solve(){
   string n;int k;
   cin>>n>>k;
   int a = stoi(n);
   while(k--){
        int b=0;
        sort(n.begin(),n.end());
        string x = n;
        reverse(n.begin(),n.end());
        string y =n;
        b = stoi(y)-stoi(x);
        if(a==b)
            break;
        else
        {a = b;n=to_string(b);}
   }
    cout<<a<<endl;
}


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

int main(){

  int a,b,c;
  cin>>a>>b>>c;

  if(a!=b && b!=c && c!=a){
  cout<<"0"<<endl;
  }
  else{
   //  int sum=a+b+c;
    if(a==b)
      	cout<<c<<endl;
    else if(b==c)
      	cout<<a<<endl;
    else
      	cout<<b<<endl;
  }

  return 0;
}

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

#define debug(args...) (Debugger()), args
class Debugger {
   public:
    Debugger(const std::string &_separator = " => ") : first(true), separator(_separator) {}

    template <typename ObjectType>
    Debugger &operator,(const ObjectType &v) {
        if (!first)
            cerr << separator;
        cerr << v;
        first = false;
        return *this;
    }
    ~Debugger() {
        cerr << endl;
    }

   private:
    bool first;
    string separator;
};
#define debug_var(x) debug(#x, x)

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

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

#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(container) container.begin(), container.end()
#define rall(container) container.rbegin(), container.rend()
#define forin(it, container) for (auto it = container.begin(); it != container.end(); it++)
#define rforin(it, container) for (auto it = container.rbegin(); it != container.rend(); it++)

typedef long l;
typedef long long ll;
typedef pair<int, int> ipi;
typedef pair<ll, ll> lpl;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;

#define MOD 1'000'000'007

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

ll xpow(ll a, ll b, ll m) {
    ll res = 1;
    while (b > 0) {
        if (b & 1) {
            res = (res * a) % m;
        }
        a = (a * a) % m;
        b /= 2;
    }
    return res;
}

ll xmul(ll a, ll b, ll m) {
    ll res = 0;
    ll v = 1, k;
    while (b > 0) {
        if (b & 1) {
            k = (a * v) % m;
            res = (res + k) % m;
        }
        v = (v * 2) % m;
        b /= 2;
    }
    return res;
}

int main() {
    int n;
    ll ans = LONG_LONG_MAX;
    ll a, p, x;
    cin >> n;
    rep(i, 0, n) {
        cin >> a >> p >> x;
        if (x > a) {
            chmin(ans, p);
        }
    }
    cout << (ans == LONG_LONG_MAX ? -1 : ans);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int tt;
    cin >> tt;
    while (tt--) {
        int n;
        cin >> n;
        vector<string> s(3);
        vector<int> a(4);
        for (int i = 0; i < 3; i++) {
            cin >> s[i];
            a[(s[i][0] - '0') * 2 + (s[i].back() - '0')] = 1;
        }
        for (int i = 0; i < 4; i++) {
            if (!a[i]) {
                string ans;
                if (i == 0) {
                    ans += string(n, '0');
                    ans += "1";
                    ans += string(n, '0');
                } else if (i == 1) {
                    ans += string(n, '1');
                    ans += string(n, '0');
                    ans += "1";
                } else if (i == 2) {
                    ans += string(n, '0');
                    ans += string(n, '1');
                    ans += "0";
                } else {
                    ans += string(n, '1');
                    ans += "0";
                    ans += string(n, '1');
                }
                cout << ans << '\n';
                break;
            }
        }
    }
    return 0;
}

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

int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        string s;
        cin >> s >> s >> s;
        for (int i = 0; i < n; i++)
            cout << "1";
        for (int i = 0; i < n; i++)
            cout << "0";
        cout << 1 << endl;
    }
    return 0;
}


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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#define itrout(x) for(int i=0;i<x.size();i++) {cout << x[i] << (i==x.size()-1 ? "\n" : " ");}
#ifdef LOCAL
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define debugbit(x, n) cerr << #x << " = " << bitset<n>(x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define itrdebug(x) cerr << #x << " "; for (auto & el : (x)) {cerr << (el) << " ";} cerr << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define debug(x)
#define debugbit(x, n)
#define itrdebug(x)
#define dassert(...)
#endif
//#define int long long
//using mint = atcoder::modint;

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

void solve(long long x){
    cout << ((x >= 0) ? x : 0) << endl;
}

signed main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    long long x;
    scanf("%lld",&x);
    solve(x);
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ndl cout << '\n';
#define yes cout<<"YES"<<'\n';
#define no cout << "NO" << '\n';
#define TC int ___T,case_n = 1;scanf("%d ",&___T);while(___T-->0)
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll x;
    cin>>x;
    if(x>=0)cout << x<< endl;
    else cout << 0 << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
const int maxN = 1e2 + 10;
int n, a[maxN], k = 1e4;
int read();
string s;
int main(){
	n = read(); n++;
	cin >> s; a[0] = read();
	int t = 0;
	for(int i = 1; i < n; i++){
		a[i] = read();
		k = min(k, abs(a[i] - a[i - 1]));
	}
	printf("%d\n", k);
	while(k--){
		for(int i = 0; i < n; i++){
			printf("%d ", a[i] / (k + 1));
			a[i] -= a[i] / (k + 1);
		}
		printf("\n");
	}
	return 0;
}
int read(){
	int s = 0, f = 1; char ch = getchar();
	while(!isdigit(ch)){
		if(ch == '-') f = -1;
		ch = getchar();
	}
	while(isdigit(ch)) s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar();
	return s * f;
}

#include <iostream>
#include <string>
#include <complex>
#include <cstdio>
#include<functional>
#include<cmath>
#include<string>
#include<ctime>
#include<cstring>
#include<algorithm>
using namespace std;
typedef complex<double> cp;
#define ll long long
#define sci(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define scf(x) scanf("%lf",&x)
#define fo(a,b,c)for(int a=b;a<=c;a++)
#define getname(x) #x
template<typename T>
inline void printT(T *arr,int n)
{
	for(int i=0;i<n;i++)
	cout<<arr[i]<<' ';
	cout<<endl;
}
inline void printcarr(cp *arr,int n,string d)
{
    for(int i=0;i<n;i++)
    {
        cout<<(int)arr[i].real()<<' ';
    }
    cout<<d<<endl;
}
inline void printBit(int x)
{
	for(int i=0;i<20;i++)
		cout<<bool(x&(1<<i));
	cout<<endl;
}
inline void copyarr(int *arr1,int *arr2,int n)
{
    for(int i=0;i<n;i++)*(arr1+i)=*(arr2+i);
}
inline void randarr(int *arr,int n)
{
	srand(time(0));
	for(int i=0;i<n;i++)*(arr+i)=rand()%100;
}
inline void qsctr(char *a,int &len)
{
    len=0;
    char c;
    while(c=getchar(),!isdigit(c));
    while(isdigit(c)){a[len++]=c;c=getchar();}
    a[len]='\0';
}
inline void showint(int *arr,int n)
{
	for(int i=0;i<n;i++)
	cout<<arr[i]<<' ';
	cout<<endl;
}
inline ll read(ll mod)//快速输入（取模)
{
     char ch;
    ll ans=0;bool isN=false;
    while(ch=getchar(),!isdigit(ch)&&ch!='-');
    if(ch=='-')isN=true;
    else ans=(ch^48);
    while(ch=getchar(),isdigit(ch)){ans=(ans<<3)+(ans<<1)+(ch^48);ans%=mod;}
    if(isN)ans*=-1;
    return ans;
}
inline ll QJY(ll *a,ll n,ll x,ll mod)//秦九韶算法 快速计算多项式的和(02n)取模
{
    ll ans=0;
    for(int i=n;i>0;i--)
        ans=(ans*x%mod+a[i-1])%mod;
    return ans;
}
inline void init(ll* eular,ll maxn)//埃氏筛 不能用欧拉 欧拉不全面 而且从 j=i开始
{
    for(int i=0;i<1e5+5;i++)eular[i]=i;
    for(int i=2;i<1e5+5;i++)
    {
        if(eular[i]==i)
            for(int j=i;j<=maxn;j+=i)
            eular[j]=eular[j]/i*(i-1);
    }
}
inline void elp(ll *jug,ll *pri,ll maxn)//欧拉筛 jug为最小质因子 maxn为数据范围
{
    for(ll i=2;i<maxn;i++)
    {
        if(!jug[i])
        {
            pri[++pri[0]]=i;
            jug[i]=i;
        }
        for(ll j=1;j<=pri[0];j++)
        {
            if(1LL*i*pri[j]>maxn)break;
            jug[i*pri[j]]=pri[j];
            if(i%pri[j]==0)break;//放后面
        }
    }
}
inline void dispose(ll x,ll *pri,ll *ert,ll *stp)//分解质因子 数据 质因子集合 质因子个数集合 分解后质因子集合
{
    for(ll j=1;j<=pri[0]&&x>=pri[j]*pri[j];j++)
    {
        if(x%pri[j]==0)
        {
            stp[++stp[0]]=pri[j];++ert[0];
            while(x%pri[j]==0){x/=pri[j];ert[ert[0]]++;}
        }
    }
    if(x>1)
        {ert[++ert[0]]++;stp[++stp[0]]=x;}
}
inline void disposefact(ll x,ll *p,ll *ans)//分解阶乘的质因子 p为x的质因子集合 ans为答案集合
{

	for(int i=1;i<=p[0];i++)//阶乘分解的原理 x的幂在(1~n)自身的倍数中，出现总次数恰好等于幂次。
	{
		ll now=p[i];
		ans[i]=0;
		while(now<=x)
		{
			ans[i]+=x/now;
			now*=p[i];
		}
	}
}
inline ll ext_gcd(ll a,ll b,ll &x,ll &y)
{
	if(b==0)
	{
		x=1;y=0;
		return a;
	}
	ll r=ext_gcd(b,a%b,y,x);//x=y' y=x'-(a/b)*y' ->  y=x' x=y'
	y-=(a/b)*x;
	return r;
}

int n;
string s;
const int maxn=200;
int st[maxn];
bool judge(int mid)
{
    for(int i=1;i<n;i++){
        if(st[i]/mid==st[i+1]/mid)
            return false;
    }
    return true;
}
int main()
{
    cin>>n;
    n++;
    cin>>s;for(int i=1;i<=n;i++)sci(st[i]);
    int l=10001;
    for(int i=1;i<n;i++){
        l=min(l,abs(st[i+1]-st[i]));
    }
    cout<<l<<endl;
    for(int i=1;i<=l;i++){
        for(int j=1;j<=n;j++)
        cout<<(st[j]+i-1)/l<<' ';
    cout<<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //int:2*10**9
typedef long double ld;
typedef pair<ll,ll> P;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define vec2(name,i,j,k) vector<vector<ll>> name(i,vector<ll>(j,k))
#define vec3(name,i,j,k,l) vector<vector<vector<ll>>> name(i,vector<vector<ll>>(j,vector<ll>(k,l)))
#define pb push_back
#define MOD 1000000007
#define PI 3.141592653
#define INF 100000000000000 //14
//cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);

void solve() {
  ll n, a, b; cin >> n >> a >> b;
  if (a<b) swap(a,b);
  if (n<a+b){
    cout << 0 << endl;
    return;
  }
  ll x = ((n-a-b+1)*(n-a-b+2)/2)%MOD;
  ll z;
  if (n-a>=b) {
    z=(((b-1)*b/2)%MOD+((n-a-b+1)*(b-1))%MOD)%MOD;
  }
  else {
    z=((n-a)*(n-a+1)/2)%MOD;
  }
  ll y = (((a-b+1)*(n-a+1))%MOD+(2*z%MOD))%MOD;
  ll ans = (((4*x)%MOD)*((x+y)%MOD))%MOD;
  cout << ans << endl;
}

int main(){
  ll t; cin >> t;
  REP(i,t) {
    solve();
  }
  return 0;
}

#include<bits/stdc++.h>

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

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

template<long long mod>
class modint{
public:
  long long num;
  long long extgcd(long long a, long long b, long long&x, long long&y)const {
    long long d = a;
    if(b != 0){d = extgcd(b, a%b, y, x);  y -= (a/b) * x;}
    else{x = 1; y = 0;}
    return d;
  }
  long long modinverse()const{
    long long x, y;
    extgcd(num, mod, x, y);
    return (mod + x%mod)%mod;
  }
  modint():num(0){}
  modint(const long long x):num((x < 0?(x+mod):x)%mod ){}
  friend modint operator+(const modint&a, const modint&b)
  {    return modint(a.num + b.num);  }
  friend modint operator-(const modint&a, const modint&b)
  {    return modint(a.num - b.num);  }
  friend modint operator*(const modint&a, const modint&b)
  {    return modint(a.num * b.num);  }
  friend modint operator/(const modint&a, const modint&b)
  {    return modint(a*b.modinverse());  }
  modint& operator+=(const modint&b)
  {    return (*this) = (*this) + b;  }
  modint& operator-=(const modint&b)
  {    return (*this) = (*this) - b;  }
  modint& operator*=(const modint&b)
  {    return (*this) = (*this) * b;  }
  modint& operator/=(const modint&b)
  {    return (*this) = (*this) / b;  }
  modint& operator++()
  {    (*this)+=1; return (*this);  }
  modint& operator--()
  {    (*this)-=1; return (*this);  }
  modint operator++(int){
    modint tmp(*this);
    ++(*this);
    return tmp;
  }
  modint operator--(int){
    modint tmp(*this);
    --(*this);
    return tmp;
  }
  modint pow(unsigned long long i){
    if(i == 0) return 1;
    if(i & 1){
      return (*this) * (this->pow(i-1));
    }
    modint<mod>hpow = (this->pow(i>>1));
    return hpow * hpow;
  }
  friend ostream& operator<<(ostream&os, const modint&a){
    os << a.num;
    return os;
  }
  friend istream& operator>>(istream&is, modint&a){
    long long x; is >> x;
    a = x;
    return is;
  }
};

constexpr int mod = 1'000'000'007;
using mint = modint<mod>;

mint S(mint n, mint a,mint b){
  mint x = n - (a+b) + 1;
  return x*(x+1);
}

int main(){
  int t; cin >> t;
  for(int sdfafds = 0; sdfafds < t; ++sdfafds){
    mint n,a,b; cin >> n >> a >> b;
    if(a.num+b.num > n.num){
      cout<< 0 << endl;
      continue;
    }
    mint x = S(n,a,b);
    cout << (n-a+1)*(n-b+1)*x*2-x*x << endl;
  }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
#define SIZE(x) ll(x.size())
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
const long long MOD = 1000000007;
typedef pair<int, int> P;
int main()
{
    int H, W, A, B;
    cin >> H >> W >> A >> B;

    vector<vector<int>> Y, T;
    rep(bit, 1 << (H * W)) {
        vector<int> t;
        rep(i, H * W) {
            if ((1 << i) & bit) {
                t.push_back(i);
            }
        }

        vector<vector<int>> check(H, vector<int>(W + 1)), check2(H + 1, vector<int>(W));
        bool yb = true, tb = true;

        rep(i, t.size()) {
            int h = t[i] / W;
            int w = t[i] - (h * W);
            if ((W - 1) == w) yb = false;
            if ((H - 1) == h) tb = false;
            check[h][w] += 1; check[h][w + 1] += 1;
            check2[h][w] += 1; check2[h + 1][w] += 1;
        }

        rep(i, H) {
            rep(j, W) {
                if (check[i][j] >= 2) yb = false;
                if (check2[i][j] >= 2) tb = false;
            }
        }

        if (tb) {
            T.push_back(t);
        }
        if (yb) {
            Y.push_back(t);
        }
    }

    ll ans = 0;

    rep(i, Y.size()) {
        int cy = (int)Y[i].size();
        rep(j, T.size()) {
            int ct = (int)T[j].size();
            if ((cy + ct) != A) continue;
            vector<vector<int>> check(H, vector<int>(W));
            bool flag = true;
            rep(k, Y[i].size()) {
                int h = Y[i][k] / W;
                int w = Y[i][k] - (h * W);
                check[h][w]++; check[h][w + 1]++;
            }
            rep(k, T[j].size()) {
                int h = T[j][k] / W;
                int w = T[j][k] - (h * W);
                if (check[h][w] >= 1 || check[h + 1][w] >= 1) {
                    flag = false;
                    break;
                }
            }
            if (flag) ans++;/*
            if (flag) {
                cout << "Y: ";
                rep(k, Y[i].size()) {
                    cout << Y[i][k] << " ";
                }cout << endl;
                cout << "T: ";
                rep(k, T[j].size()) {
                    cout << T[j][k] << " ";
                }cout << endl;
            }*/
        }
    }

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


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

#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define MAXX 300005
#define pb push_back
#define fixx(n) fixed << setprecision(n)
#define F first
#define S second
#define PI  3.14159265358979323846
#define ll   long long int
#define int ll
#define double long double
const int mod = 1e6 + 11;
const int N = 1e10;

int solve(double &x, double &y, double &r) {
    int ans = 0;
    r = nextafter(r, 1e9);
    int y2 = floor(y + r), y1 = ceil(y - r);
    for(; y1 <= y2; y1 ++) {
        double l = sqrt(r * r  -  (y - y1)*(y - y1));
        int x1 = ceil(x - l), x2 = floor(x  + l);
        ans +=  x2 - x1 + 1;
    }
    return ans;
}

signed main()
{
    FAST;

    double x, y, r;
    cin >> x >> y >> r;

    cout << solve(x, y , r);
    return 0;

}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mii map <int, int>
#define mll map <ll, ll>
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vi vector <int>
#define vd vector <double>
#define vll vector <ll>
#define fi first
#define se second
#define si set <int>
#define sll set <ll>
#define spii set <pii>
#define vs vector <string>
#define vpii vector <pair <int, int> >
#define vpll vector <pair <long long, long long> >
#define vvi vector <vector <int> >
#define vvpii vector <vector <pii > >
#define vb vector <bool>
#define vvb vector <vb>
#define mp make_pair
#define vvll vector <vll>
#define vsi vector <si>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define MANX MAXN
#define itn int
#define dbg(x); {cout << #x << "=" << x << ", ";}
#define in(x); { for (auto &to : x) cin >> to;}
#define out(x); { for (auto &to : x) cout << to << " "; cout << '\n'; }

const ll INFLL = 1e18;
const int MAXN = 1e6+100;
const ll INF = 1e9;
const int mod1 = 1e9+7;
const int mod2 = 1e9+21;

void solve()
{
    int n,m;
    cin>>n>>m;
    vvi g(n);
    while (m--){
        int u,v;
        cin>>u>>v;
        u--,v--;
        g[u].pb(v);
        g[v].pb(u);
    }
    int k;
    cin>>k;
    if (k==1){
        cout<<1<<'\n';
        return;
    }
    vector <vector <int> > dist(k);
    vector <int> c(k);
    rep(i,k)
        cin>>c[i],c[i]--;
    for (int i=0;i<k;i++){
        vector <int> d(n,INF);
        d[c[i]]=0;
        queue<int> q;
        q.push(c[i]);
        while (!q.empty())
        {
            int f=q.front();
            q.pop();
            for (auto to:g[f])
            {
                if (d[to]!=INF)
                    continue;
                d[to]=d[f]+1;
                q.push(to);
            }
        }
        swap(dist[i],d);
    }
    vector <vi> dp((1<<k),vi(k,INF));
    for (int i=0;i<k;i++)
        dp[(1<<i)][i]=1;
    for (int i=0;i<k-1;i++)
    {
        for (int mask=(1<<k)-1;mask>=0;mask--)
        {
            for (int was=0;was<k;was++)
            {
                if (dp[mask][was]==INF)
                    continue;
                for (int j=0;j<k;j++)
                {
                    dp[mask|(1<<j)][j]=min(dp[mask|(1<<j)][j],dp[mask][was]+dist[was][c[j]]);
                }
            }
        }
    }
    int ans=INF;
    for (int i=0;i<k;i++)
        ans=min(ans,dp[(1<<k)-1][i]);
    cout<<(ans==INF?-1:ans)<<'\n';
}

int main() {
    #ifdef Mip182
    freopen("a.in", "r", stdin);
    #else
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    #endif
    int _t;
    _t=1;
//    cin>>_t;
    while (_t--)
        solve();
    #ifdef Mip182
    cout<<'\n'<<"Time : "<<(double)(clock())/CLOCKS_PER_SEC<<'\n';
    #endif
}

#include<bits/stdc++.h>
using namespace std;
#define pb emplace_back
#define st first
#define nd second
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;
#define sz(a) int((a).size())
#define all(c) (c).begin(),(c).end()
#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 rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>b;i--)
#define endl "\n"
#define fre freopen("in.txt","r",stdin);freopen("out.txt","w",stdout)
#define start ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
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
#define N 200005

//2 4 4 +1
//

ll yen[20][1<<20];
queue<pair<int,int>> q;
vector<int> v[N];
ll vis[N];
ll dp[20][20];
ll k;
int idx[N];
vector<int> c;
ll sum=0;
bool check=true;

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

rep(i,0,m)
{
	int a,b;
	cin>>a>>b;
	v[a].pb(b);v[b].pb(a);
}

cin>>k;
memset(idx,-1,sizeof(idx));
rep(i,0,k)
{
	int a;
	cin>>a;
	c.pb(a);
	idx[c[i]]=i;
}

rep(i,0,k)
{
	memset(vis,0,sizeof(vis));
	q.push(make_pair(c[i],0));

	rep(j,0,k)
	{
		dp[i][j]=N;
	}
	while(!q.empty())
	{
		ll temp=q.front().st;
		ll cur=q.front().nd;
		q.pop();
		if(vis[temp])
			continue;
		vis[temp]=1;
		if(idx[temp] != -1) dp[i][idx[temp]] = cur;
		rep(j,0,v[temp].size())
		{
			if(vis[v[temp][j]])
				continue;
			q.push({v[temp][j],cur+1});
		}
	}
}

memset(yen, N, sizeof(yen));
    for (int i=0; i<k; i++) yen[i][1<<i] = 0;

    for (int j=0; j<(1<<k); j++) {
        for (int i=0; i<k; i++) if (j & (1<<i)) {
            int cur = j & ~(1<<i);
            for (int l=0; l<k; l++) if (cur & (1<<l)) {
                yen[i][j] = min(yen[i][j], yen[l][cur] + dp[l][i]);
            }
        }
    }

    ll ans = N;
    for (int i=0; i<k; i++) ans = min(ans, yen[i][(1<<k)-1]);

    if (ans == N) cout<<-1<<endl;
    else cout<<ans+1<<endl;

}

int main(){
	start

	int t=1;
	//cin>>t;
	rep(i,0,t)
	solve();
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define sz(v) int((v).size())
#define all(x) (x).begin(), (x).end()
#define forn(i, n) for (int i = 1; i <= int(n); ++i)
//출처: https://codeforces.com/blog/entry/68809
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
#define int ll

const int MOD = 998244353;
int power(int a, int n) {
    int res = 1;
    for (;n; n >>= 1, a = (a * a) % MOD)
        if (n & 1) res = (res * a) % MOD;
    return res;
}
void add(int& a, int b){a = (a%MOD + b%MOD)%MOD;}
int h, w, k;
char grid[5050][5050];
int dp[5050][5050][4];
int f(char c)
{
    return c == 'R'? 2 : (c== 'D');
}
void solve()
{
    cin>>h>>w>>k;
    forn(_, k)
    {
        int a, b; char c; cin>>a>>b>>c;
        grid[a][b] = c;
    }
    int r = h*w - k;

    if (grid[1][1]) dp[1][1][f(grid[1][1])] = power(3, r);
    else dp[1][1][3] = power(3, r);

    int p3 = power(3, MOD - 2);
    forn(i, h) forn(j, w)
    {
        if (grid[i+1][j])
        {
            add(dp[i + 1][j][f(grid[i+1][j])], dp[i][j][f('D')]);
            add(dp[i + 1][j][f(grid[i+1][j])], dp[i][j][f('X')]);
            add(dp[i + 1][j][f(grid[i+1][j])], dp[i][j][3] * p3);
            add(dp[i + 1][j][f(grid[i+1][j])], dp[i][j][3] * p3);
        }
        else
        {
            add(dp[i + 1][j][3], dp[i][j][f('D')]);
            add(dp[i + 1][j][3], dp[i][j][f('X')]);
            add(dp[i + 1][j][3], dp[i][j][3] * p3);
            add(dp[i + 1][j][3], dp[i][j][3] * p3);
        }
        if (grid[i][j+1])
        {
            add(dp[i][j + 1][f(grid[i][j+1])], dp[i][j][f('R')]);
            add(dp[i][j + 1][f(grid[i][j+1])], dp[i][j][f('X')]);
            add(dp[i][j + 1][f(grid[i][j+1])], dp[i][j][3] * p3);
            add(dp[i][j + 1][f(grid[i][j+1])], dp[i][j][3] * p3);
        }
        else
        {
            add(dp[i][j + 1][3], dp[i][j][f('R')]);
            add(dp[i][j + 1][3], dp[i][j][f('X')]);
            add(dp[i][j + 1][3], dp[i][j][3] * p3);
            add(dp[i][j + 1][3], dp[i][j][3] * p3);
        }
        // for (int k = 0; k < 4; ++k) debug(i, j, k, dp[i][j][k]);
    }

    if (grid[h][w]) cout << dp[h][w][f(grid[h][w])] << '\n';
    else cout << dp[h][w][3] << '\n';
}
signed main(void)
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int T = 1; //cin >> T;
    while (T--) solve();
    return 0;
}

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

int main(){
    ll n, k;
    cin >> n >> k;
    vvl t(n, vl(n));
    rep(i,n)rep(j,n) cin >> t[i][j];
    ll ans = 0;
    vl v(n-1);
    rep(i,n-1) v[i] = i+1;
    do{
        ll sum = 0;
        rep(i,n){
            if(i==0) sum += t[0][v[i]];
            else if(i == n-1) sum += t[v[i-1]][0];
            else sum += t[v[i-1]][v[i]];
            if(sum == k) ans ++;
        }
    }while(next_permutation(v.begin(),v.end()));

    cout << ans << endl;
}


#ifdef LC
#include "pch.h"
#else
#include <bits/stdc++.h>
#endif
using namespace std;
using ll = long long;
#define int ll
#define all(x) x.begin(), x.end()
#define x first
#define y second
#define mp make_pair
#define mt make_tuple

signed main() {
#ifdef LC
    assert(freopen("input.txt", "r", stdin));
#endif
    ios::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
    	cout << (2 * i) % n + 1 << " " << (2 * i + 1) % n + 1 << "\n";
    }
    return 0;
}

#pragma GCC target("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
#define DEBUG
#ifdef DEBUG
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << '(' << p.first << ',' << p.second << ')';
    return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << '{';
    for(int i = 0; i < (int)v.size(); i++) {
        if(i) { os << ','; }
        os << v[i];
    }
    os << '}';
    return os;
}
void debugg() { cerr << endl; }
template <class T, class... Args>
void debugg(const T &x, const Args &... args) {
    cerr << " " << x;
    debugg(args...);
}
#define debug(...)                                                             \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]: ", debugg(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = (1<<30) - 1;
const ll linf = 1LL<<61;
const int MAX = 510000;
int dy[8] = {0,1,0,-1,1,-1,-1,1};
int dx[8] = {-1,0,1,0,1,-1,1,-1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    int sz = a.size();
    for(auto itr = a.begin(); itr != a.end(); itr++){
		cout << *itr;
        sz--;
        if(sz) cout << " ";
	}
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){
	cout << a << " " << b << "\n";
}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
void mark() {cout << "#" << "\n";}
ll pcount(ll x) {return __builtin_popcountll(x);}
//const int mod = 1e9 + 7;
const int mod = 998244353;

int main(){
    int n; cin >> n;
    rep(i,n) cout << i/2+1 << " " << (i+n)/2+1 << "\n";
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define f first
#define s second
#define all(c) begin(c),end(c)
using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

using pll = pair<ll, ll>;
using tll = tuple<ll, ll, ll>;

const ll MAXN = 1e5;
const ll INF = 1e17;
const ll MOD = 1e9 + 7;
const ll EPS = 1e-9;

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

ll xs[] = {-1, 1, 0, 0, -1, 1, 1, -1};
ll ys[] = {0, 0, -1, 1, -1, 1, -1, 1};

ll ipow(ll b, ll p, ll mod){
	if(p == 0) return 1;
	if(p == 1) return b%mod;
	if(p&1) return ((b%mod)*(ipow((b%mod * b%mod)%mod,p>>1,mod)))%mod;
	return ipow((b%mod * b%mod)%mod,p>>1,mod);
}

int main(){
	cin.sync_with_stdio(false);
	cin.tie(0);
	ll a, b, c;
	cin >> a >> b >> c;
	a %= 10;
	if(a == 1 or a == 5 or a == 6 or a == 0)
		cout << a;
	else{
		vector<ll> A[] = {{0},{1},{6,2,4,8},{1,3,9,7},{6,4},{5},{6},{1,7,9,3},{6,8,4,2},{1,9}};
		ll q = ipow(b,c,A[a].size());
		cout << A[a][q];
	}
	return 0;
}

#include <bits/stdc++.h>

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

int main(){
    ll a,b,c;
    cin >> a >> b >> c;
    ll x=a%10;
    if(x==0 || x==1|| x==5 || x==6 )cout << x << endl;
    else if(x==4){
        if(b%2==0){
            cout << 6 << endl;
        }
        else if(b%2==1){
            cout << 4 << endl;
        }
    }
    else if(x==9){
        if(b%2==0){
            cout << 1 << endl;
        }
        else if(b%2==1){
            cout << 9 << endl;
        }
    }
    else if(x==2){
        if(b%4==0){
            cout << 6 << endl;
        }
        else if(b%4==2){
            if(c>=2)cout << 6 << endl;
            else  cout << 4 << endl;
        }
        else{
            if(b%4==1)cout << 2 << endl;
            else{
                if(c%2==0)cout << 2 << endl;
                else if(c%2==1) cout << 8 << endl;
            }
        }
    }
    else if(x==3){
        if(b%4==0){
            cout << 1 << endl;
        }
        else if(b%4==2){
            if(c>=2)cout << 1 << endl;
            else cout << 9 << endl;
        }
        else{
            if(b%4==1)cout << 3 << endl;
            else{
                if(c%2==0)cout << 3 << endl;
                else if(c%2==1)cout << 7 << endl;
            }
        }
    }
    else if(x==7){
        if(b%4==0){
            cout << 1 << endl;
        }
        else if(b%4==2){
            if(c>=2)cout << 1 << endl;
            else cout << 9 << endl;
        }
        else{
            if(b%4==1)cout << 7 << endl;
            else{
                if(c%2==0)cout << 7 << endl;
                else if(c%2==1)cout << 3 << endl;
            }
        }
    }
    else if(x==8){
        if(b%4==0){
            cout << 6 << endl;
        }
        else if(b%4==2){
            if(c>=2)cout << 6 << endl;
            else cout << 4 << endl;
        }
        else{
            if(b%4==1)cout << 8 << endl;
            else{
                if(c%2==0)cout << 8 << endl;
                else if(c%2==1)cout << 2 << endl;
            }
        }
    }
}


// E - White Pawn
#include <bits/stdc++.h>
using namespace std;

int main(){
	int N, M; cin>>N>>M;
	int C = min(N, M), L = C*2 + 1;

	auto ixOk = [&](int y){ return 0 <= y && y < L; };

	vector<pair<int,int>> D;
	while(M--){
		int x, y; cin>>x>>y;
		y -= N - C;
		if(ixOk(y)) D.emplace_back(x, y);
	}
	sort(D.begin(), D.end());

	vector<int> Y, S(L); S[C] = 1;

	auto update = [&](){
		vector<int> A;
		for(int&y:Y)
			if((ixOk(y-1) && S[y-1]) || (ixOk(y+1) && S[y+1])) A.push_back(y);
		for(int&y:Y) S[y] = 0;
		for(int&y:A) S[y] = 1;
	};

	int px = 0;
	for(auto&[x, y]:D){
		if(px != x) update(), Y.clear(), px = x;
		Y.push_back(y);
	}
	update();
	cout<< accumulate(S.begin(), S.end(), 0) <<endl;
}

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

#define F first
#define S second

int main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    ll n, m; cin >> n >> m;
    map<ll, vector<ll>> mp;
    for(int i = 0; i < m; i++){
    	ll x, y; cin >> x >> y;
    	mp[x].push_back(y);
    }
    set<ll> s;
    s.insert(n);
    for(auto &i: mp){
    	vector<ll> rem, ins;
    	for(auto &j: i.S){
    		ll l = s.count(j + 1);
    		ll r = s.count(j - 1);
    		if(l + r == 0) rem.push_back(j);
    		else ins.push_back(j);
    	}
    	for(auto &j: rem) s.erase(j);
    	for(auto &j: ins) s.insert(j);
    }
	cout << s.size() << '\n';
    return 0;
}


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

int main(){
    int H,W;
    cin >> H >> W;
    int block_min=101;
    int block_grid=0;
    int block_mins=0;
    vector<int> A(W);
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin >> A[j];
            int a=A[j];
            if(a<block_min){
                block_min=a;
            }
        }
        if(block_min<block_mins){
            block_grid+=W*i*(block_mins-block_min);
        }
        for(int k=0;k<W;k++){
            block_grid+=A[k]-block_min;
        }
        block_mins=block_min;
    }
    cout << block_grid << endl;
}

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

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

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

    int a, b;
    cin>>a>>b;
    int ans = 2*a+100;
    ans-=b;
    cout<<ans;

    return 0;
}


#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sys/types.h>
#include <unistd.h>
#include <vector>

#pragma region macros
#define _overload(_1, _2, _3, name, ...) name
#define _rep(i, n) _range(i, 0, n)
#define _range(i, a, b) for (int i = int(a); i < int(b); ++i)
#define rep(...) _overload(__VA_ARGS__, _range, _rep, )(__VA_ARGS__)
#define _rrep(i, n) _rrange(i, n, 0)
#define _rrange(i, a, b) for (int i = int(a) - 1; i >= int(b); --i)
#define rrep(...) _overload(__VA_ARGS__, _rrange, _rrep, )(__VA_ARGS__)
#pragma endregion macros

using namespace std;

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

using ll    = long long;
using R     = long double;
const R EPS = 1e-9L;  // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R &r) {
    return (r > EPS) - (r < -EPS);
}
inline R sq(R x) {
    return sqrt(max(x, 0.0L));
}

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

const pid_t pid = getpid();
// Problem Specific Parameter:

int main(void) {
    int t;
    cin >> t;
    rep(loop, t) {
        int n;
        cin >> n;
        string s1, s2, s3;
        cin >> s1 >> s2 >> s3;
        cout << string(n, '1') + string(n, '0') + "1" << endl;
    }
    return 0;
}

#include <bits/stdc++.h>
// #include <atcoder/all>
// #include "icld.cpp"
using namespace std;
using ll = long long int;
using vi = vector<int>;
using si = set<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using ss = string;
using db = double;
template<typename T> using minpq = priority_queue <T,vector<T>,greater<T>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
#define V vector
#define P pair<int,int>
#define rep(i,s,n) for(int i=(s);i<(int)(n);i++)
#define rev(i,s,n) for(int i=(s);i>=(int)(n);i--)
#define reciv(v,n) vi (v)((n)); rep(i,0,(n))cin>>v[i]
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define ci(x) cin >> x
#define cii(x) ll x;cin >> x
#define cci(x,y) ll x,y;cin >> x >> y
#define co(x) cout << x << endl
#define pb push_back
#define eb emplace_back
#define rz resize
#define sz(x) int(x.size())
#define yn cout<<"Yes"<<endl;else cout<<"No"<<endl
#define YN cout<<"YES"<<endl;else cout<<"NO"<<endl
template<class T>void chmax(T &x,T y){x=max(x,y);}
template<class T>void chmin(T &x,T y){x=min(x,y);}

int main(){
  cii(t);

  V<ss> ans;

  while(t--){
    cii(n);
    vvi v(2,vi(2,0));

    V<ss> s(3);
    rep(i,0,3)ci(s[i]);

    rep(i,0,3){
      int fr=s[i][0]-'0';
      int ba=s[i][n*2-1]-'0';

      v[ba][fr]=1;
    }

    ss now;
    ss s0,s1;
    rep(i,0,n){
      s0+="0";
      s1+="1";
    }

    if(v[0][0]==0){
      now=s0+"1"+s0;
    }
    else {
      if(v[1][1]==0){
        now=s1+"0"+s1;
      }
      else {
        if(v[0][1]==0)now=s0+s1+"0";
        else now=s1+s0+"1";
      }
    }

    ans.pb(now);
  }

  for(ss s:ans)co(s);
}


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

#define FREP(i,a,b) for(long long i=a;i<b;i++)
#define REP(i,n) FREP(i,0,n)
#define PB push_back
#define ll long long
#define MP make_pair
#define mod 1000000007
#define endl "\n"
#define vi vector<ll>
#define si set<ll>
#define mi map<ll,ll>
#define bs binary_search
#define pri(a,n) REP(i,n)cout<<a[i]<<" ";
#define all(x) x.begin(),x.end()
#define sz(a) (ll)a.size()
#define sa(a,n) sort(a,a+n)
#define sra(a,n) sort(a,a+n,greater<ll>())
#define sv(v) sort(all(v))
#define srv(v) sort(v.rbegin(),v.rend())
#define sp(x) fixed<<setprecision(x)
#define mem(a) memset(a,-1,sizeof(a))
#define ff first
#define ss second
#define deb(x) cout<<#x<<' '<<x<<endl;
#define FASTIO ios_base::sync_with_stdio(false);\
               cin.tie(NULL);\
               cout.tie(NULL);

void _a_b_c_d_e_f_g_h_i_j_k_l_m_n_o_p_q_r_s_t_u_v_w_x_y_z()
{
    ll n, k, q = 0, c = 0;
    string s;
    cin >> n;
    FREP(i, 1, 10000001)
    if (((2 * n + i - i * i)) % (2 * i) == 0 && 2 * n + i - i * i > 0)
        ++c;
    cout << c * 2;
}

int main()
{
    FASTIO;
    int t = 1;
    // cin >> t;         // Test Case :-||-: //

    while (t--)
    {
        _a_b_c_d_e_f_g_h_i_j_k_l_m_n_o_p_q_r_s_t_u_v_w_x_y_z();
    }

    return 0;
}

// Thanks for stalking :P

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

using ll=long long;
ll mod=1000000007;

set<ll> enum_divisors(ll N){
   set<ll> res;
   for(ll i=1;i*i<=N;i++){
      if(N%i==0){
         res.insert(i);
         res.insert(N/i);
      }
   }
   return res;
}

int main(){
    ll N,count=0;
    cin >> N;
    const auto &P=enum_divisors(2*N);
    for(auto it=P.begin();it!=P.end();it++){
        if(*it%2==1){
            count+=2;
        }
    }
    cout << count << endl;
}


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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const int MAX_N = (int)(2e2 + 5);

int n;
int a[MAX_N];

int dp[MAX_N][200];

vector<vector<int>> candidates;

int get_valid_modulo() {
  if (dp[n][0] >= 3) return 0;

  for (int i = 1; i < 200; ++i) {
    if (dp[n][i] >= 2) return i;
  }

  return -1;
}

bool dfs(int cur, int modulo, vector<int> &hold) {
  if (cur == 0 && modulo == 0) {
    if (hold.empty()) return false;

    vector<int> tmp(hold);
    candidates.push_back(tmp);

    return candidates.size() >= 2;
  }

  if (cur == 0) return false;

  // do not use
  if (dp[cur - 1][modulo] != 0) {
    bool done = dfs(cur - 1, modulo, hold);
    if (done) return true;
  }

  // use
  hold.push_back(cur);
  int prev_modulo = (modulo - a[cur] + 200) % 200;
  if (dp[cur - 1][prev_modulo] != 0) {
    bool done = dfs(cur - 1, prev_modulo, hold);
    if (done) return true;
  }
  hold.pop_back();

  return false;
}

void retrieve(int modulo) {
  vector<int> hold;
  dfs(n, modulo, hold);
}

int main(void) {
  // Here your code !
  scanf("%d", &n);

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

  // initialize
  for (int i = 0; i <= n; ++i) {
    for (int j = 0; j < 200; ++j) {
      dp[i][j] = 0;
    }
  }
  dp[0][0] = 1;

  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < 200; ++j) {
      if (dp[i - 1][j] == 0) continue;

      int next_modulo = (j + a[i]) % 200;
      dp[i][next_modulo] += dp[i - 1][j];  // use a[i]
      dp[i][j] += dp[i - 1][j];            // do not use a[i]

      dp[i][next_modulo] = min(dp[i][next_modulo], 3);
      dp[i][j] = min(dp[i][j], 3);
    }
  }

  int modulo = get_valid_modulo();

  if (modulo < 0) {
    printf("No\n");
    return 0;
  }

  printf("Yes\n");

  retrieve(modulo);

  printf("%d ", candidates[0].size());
  sort(candidates[0].begin(), candidates[0].end());
  for (auto e : candidates[0]) {
    printf("%d ", e);
  }
  printf("\n");

  printf("%d ", candidates[1].size());
  sort(candidates[1].begin(), candidates[1].end());
  for (auto e : candidates[1]) {
    printf("%d ", e);
  }
  printf("\n");

  return 0;
}

#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <string>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <iterator>
#include <limits>
#include <numeric>
#include <utility>
#include <type_traits>
#include <cmath>
#include <cassert>
#include <cstdio>

using namespace std;
using namespace placeholders;

using LL = long long;
using ULL = unsigned long long;
using VI = vector< int >;
using VVI = vector< vector< int > >;
using VS = vector< string >;
using ISS = istringstream;
using OSS = ostringstream;
using PII = pair< int, int >;
using VPII = vector< pair< int, int > >;
template < typename T = int > using VT = vector< T >;
template < typename T = int > using VVT = vector< vector< T > >;
template < typename T = int > using LIM = numeric_limits< T >;
template < typename T = int > using OSI = ostream_iterator< T >;

template < typename T > inline istream& operator>>( istream &s, vector< T > &v ){ for ( T &t : v ) { s >> t; } return s; }
template < typename T > inline ostream& operator<<( ostream &s, const vector< T > &v ){ for ( int i = 0; i < int( v.size() ); ++i ){ s << ( " " + !i ) << v[i]; } return s; }

void in_impl(){};
template < typename T, typename... TS > void in_impl( T &head, TS &... tail ){ cin >> head; in_impl( tail ... ); }
#define IN( T, ... ) T __VA_ARGS__; in_impl( __VA_ARGS__ );

template < typename T > inline T fromString( const string &s ) { T res; istringstream iss( s ); iss >> res; return res; }
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); }

#define NUMBERED( name, number ) NUMBERED2( name, number )
#define NUMBERED2( name, number ) name ## _ ## number
#define REP1( n ) REP2( NUMBERED( REP_COUNTER, __LINE__ ), n )
#define REP2( i, n ) REP3( i, 0, n )
#define REP3( i, m, n ) for ( int i = ( int )( m ); i < ( int )( n ); ++i )
#define GET_REP( a, b, c, F, ... ) F
#define REP( ... ) GET_REP( __VA_ARGS__, REP3, REP2, REP1 )( __VA_ARGS__ )
#define FOR( e, c ) for ( auto &&e : c )
#define ALL( c ) begin( c ), end( c )
#define AALL( a ) ( remove_all_extents< decltype( a ) >::type * )a, ( remove_all_extents< decltype( a ) >::type * )a + sizeof( a ) / sizeof( remove_all_extents< decltype( a ) >::type )

#define SZ( v ) ( (int)( v ).size() )
#define EXISTS( c, e ) ( ( c ).find( e ) != ( c ).end() )

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

#define PB push_back
#define EM emplace
#define EB emplace_back
#define BI back_inserter

#define MP make_pair
#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

//     Λ   Λ＿_
//  ／(*ﾟーﾟ)／＼
// ／| ￣U U￣|＼／
//   |      |／

int solve()
{
	IN( int, N, S, K );
	K %= N;

	const int b = ceil( sqrt( N ) );

	map< int, int > exps;
	{
		int k = 0;
		REP( i, b + 2 )
		{
			if ( EXISTS( exps, k ) )
			{
				break;
			}
			exps[k] = i;
			( k += K ) %= N;
		}
	}

	REP( i, b + 1 )
	{
		const int s = ( S + LL( K ) * b * i ) % N;
		const int t = N - s;
		if ( EXISTS( exps, t ) )
		{
			return i * b + exps[t];
		}
	}

	return -1;
}

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

	IN( int, T );
	REP( T )
	{
		cout << solve() << '\n';
	}
	cout << flush;

	return 0;
}


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

#define vi vector<int>
#define tests int t; cin>>t; while(t--)
#define ll long long
#define vll vector<long long>
#define srt(v) sort(v.begin(), v.end())
#define srtg(v) sort(v.begin(), v.end(), greater<int> ())
#define FOR(k, n) for(int k=0; k<n; k++)
#define pb push_back
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define printarr(v) for(auto& x : v) cout<<x<<" "; cout<<endl

using namespace std;

char nums[10] = { '0','1','2','3','4','5','6','7','8','9' };
char alphsl[26] = { 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z' };
const int MOD = 1000000007;
char alphs[26] = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' };

bool five(ll n){
    ll curr=5;
    while(curr<n) curr*=5;
    if(curr==n) return true;
    return false;
}

void solve() {

    ll n;
    cin>>n;
    ll curr=3, cnt=1;
    while(curr<n){
        if(five(n-curr)){
            cout<<cnt<<" ";
            n-=curr;
            ll c=0;
            while(pow(5, c)<n) c++;
            cout<<c<<endl;
            return;
        }
        curr*=3;
        cnt++;
    }
    cout<<"-1"<<endl;
}

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0);

       // tests
        solve();

    return 0;
}


#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long; // int64_t
using ull = unsigned long long;
using pii = pair<int,int>;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)

const ll INF = 1e9+7;   //10oku7

int N;
vector<vector<ll>> dist;
vector<vector<ll>> dp;

ll binary(ll x){
    ll ans = 0;
    ll count = 0;
    while ( x >0 ){
      ans = ans + (x%2)*pow(10ll,count);
      x /= 2;
      count ++;
    }
    return ans;
}

ll rec(ll bits, ll j ){
  if (dp.at(bits).at(j) < INF*2) return dp.at(bits).at(j);
  if (bits == 0 && j == 0) return 0;
  if (!((bits >> j ) & 1 )) {
    dp.at(bits).at(j) = INF;
    return INF;
  }
  rep(i,N){
    if ( bits == 1<<i ){
      dp.at(bits).at(i) = dist.at(0).at(j);
      return dp.at(bits).at(i);
    }
  }
  ll temp = INF;

  rep(i,N){
    if (((bits >> i ) & 1) ){
//      cout << binary(bits) << " " << i << endl;
      temp = min (temp, rec(bits - (1<<j), i) + dist.at(i).at(j));
    }
  }

  dp.at(bits).at(j) = temp;
  return temp;
}

int main() {
  cin >> N;
  vector<ll> X(N);
  vector<ll> Y(N);
  vector<ll> Z(N);
  rep(i,N){
    cin >> X.at(i) >> Y.at(i) >> Z.at(i);
  }

  dist = vector<vector<ll>> (N,vector<ll>(N,INF));
  dp = vector<vector<ll>> ((1 << N) ,vector<ll>(N,INF*2));

  rep(i,N){
    rep (j,N){
      dist.at(i).at(j) = abs (X.at(i) - X.at(j) ) + abs( Y.at(i) - Y.at(j)) + max (0ll, Z.at(j) - Z.at(i));
    }
  }

  cout << rec ((1<<N) -1,0) << endl;

}

#include "cstdio"
#include "cstring"
#include "cctype"
#include "queue"
#define R register
#define getchar() (_==__&&(__=(_=___)+fread(___,1,1<<16,stdin),_==__)?EOF:*_++)
char ___[1<<16],*_=___,*__=___;
const int big=100010;
int n;
long long ans,a[big];
std::priority_queue<int>q[2];
inline int read()
{
    char c(getchar());int x(0),f(1);
    for(;!isdigit(c);(c=='-')&&(f=-1),c=getchar());
    for(;isdigit(c);x=(x*10)+(c^48),c=getchar());
    return f*x;
}
int main(void)
{
    // freopen("data.in","r",stdin);
    n=read();
    for(R int i(1);i<=n;++i)a[i]=read(),ans+=a[i];
    for(R int i(1);i<=n;++i)q[i&1].push(read()-a[i]);
    while(!q[0].empty()&&!q[1].empty()&&q[0].top()+q[1].top()>0)ans+=q[0].top()+q[1].top(),q[0].pop(),q[1].pop();
    printf("%lld\n",ans);
    end:return 0;
}