#include<bits/stdc++.h>
#define read() Read<int>()
namespace pb_ds{
    namespace io{
        const int MaxBuff=1<<15;
        const int Output=1<<23;
        char B[MaxBuff],*S=B,*T=B;
		#define getc() ((S==T)&&(T=(S=B)+fread(B,1,MaxBuff,stdin),S==T)?0:*S++)
        char Out[Output],*iter=Out;
        inline void flush(){
            fwrite(Out,1,iter-Out,stdout);
            iter=Out;
        }
    }
    template<class Type> inline Type Read(){
        using namespace io;
        register char ch;
        register Type ans=0;
        register bool neg=0;
        while(ch=getc(),(ch<'0' || ch>'9') && ch!='-');
        ch=='-'?neg=1:ans=ch-'0';
        while(ch=getc(),'0'<= ch && ch<='9') ans=ans*10+ch-'0';
        return neg?-ans:ans;
    }
    template<class Type> inline void Print(register Type x,register char ch='\n'){
        using namespace io;
        if(!x) *iter++='0';
        else{
            if(x<0) *iter++='-',x=-x;
            static int s[100];
            register int t=0;
            while(x) s[++t]=x%10,x/=10;
            while(t) *iter++='0'+s[t--];
        }
        *iter++=ch;
    }
}
using namespace pb_ds;
using namespace std;
typedef long long ll;
const int N=2e6+5;
const int Mod=998244353;
inline void ad(int &x,int y){
	x+=y;
	if (x>=Mod) x-=Mod;
}
inline int Pow(int x,int y){
	int res=1;
	while (y){
		if (y&1) res=1ll*res*x%Mod;
		x=1ll*x*x%Mod;
		y>>=1;
	}
	return res;
}
int fac[N],inv[N];
inline void math_init(int nn){
	fac[0]=1;
	for (int i=1;i<=nn;++i)
		fac[i]=1ll*fac[i-1]*i%Mod;
	inv[nn]=Pow(fac[nn],Mod-2);
	for (int i=nn;i;--i)
		inv[i-1]=1ll*inv[i]*i%Mod;
}
inline int C(int x,int y){
	if (x<y || x<0 || y<0) return 0;
	return 1ll*(1ll*fac[x]*inv[y]%Mod)*inv[x-y]%Mod;
}
int n,ans=1,m,tot,k;
int p[N],a[N],cnt[N];
int main(){
//	freopen("e.in","r",stdin);
//	freopen("e.out","w",stdout);
	math_init(N-5);
	n=k=read();
	for (int i=1;i<=n;++i)
		m=max(m,a[i]=read());
	for (int i=1;i<=n;++i){
		++p[a[i]+1];
		for (int j=a[i]+1;j<=m;j+=n)
			++cnt[j];
	}
	for (int i=1;i<=m;++i){
		++tot,k-=p[i];
		if (tot<cnt[i]) break;
		tot-=cnt[i];
		ad(ans,C(tot+n-1,n-1));
		ad(ans,Mod-C(tot-k+n-1,n-1));
	}
	printf("%d\n",ans);
	return 0;
}


#include<bits/stdc++.h>
#define read() Read<int>()
namespace pb_ds{
    namespace io{
        const int MaxBuff=1<<15;
        const int Output=1<<23;
        char B[MaxBuff],*S=B,*T=B;
		#define getc() ((S==T)&&(T=(S=B)+fread(B,1,MaxBuff,stdin),S==T)?0:*S++)
        char Out[Output],*iter=Out;
        inline void flush(){
            fwrite(Out,1,iter-Out,stdout);
            iter=Out;
        }
    }
    template<class Type> inline Type Read(){
        using namespace io;
        register char ch;
        register Type ans=0;
        register bool neg=0;
        while(ch=getc(),(ch<'0' || ch>'9') && ch!='-');
        ch=='-'?neg=1:ans=ch-'0';
        while(ch=getc(),'0'<= ch && ch<='9') ans=ans*10+ch-'0';
        return neg?-ans:ans;
    }
    template<class Type> inline void Print(register Type x,register char ch='\n'){
        using namespace io;
        if(!x) *iter++='0';
        else{
            if(x<0) *iter++='-',x=-x;
            static int s[100];
            register int t=0;
            while(x) s[++t]=x%10,x/=10;
            while(t) *iter++='0'+s[t--];
        }
        *iter++=ch;
    }
}
using namespace pb_ds;
using namespace std;
typedef long long ll;
const int N=2e6+5;
const int Mod=998244353;
inline void ad(int &x,int y){
	x+=y;
	if (x>=Mod) x-=Mod;
}
inline int Pow(int x,int y){
	int res=1;
	while (y){
		if (y&1) res=1ll*res*x%Mod;
		x=1ll*x*x%Mod;
		y>>=1;
	}
	return res;
}
int fac[N],inv[N];
inline void math_init(int nn){
	fac[0]=1;
	for (int i=1;i<=nn;++i)
		fac[i]=1ll*fac[i-1]*i%Mod;
	inv[nn]=Pow(fac[nn],Mod-2);
	for (int i=nn;i;--i)
		inv[i-1]=1ll*inv[i]*i%Mod;
}
inline int C(int x,int y){
	if (x<y || x<0 || y<0) return 0;
	return 1ll*(1ll*fac[x]*inv[y]%Mod)*inv[x-y]%Mod;
}
int n,ans=1,m,tot,k;
int p[N],a[N],cnt[N];
int main(){
//	freopen("e.in","r",stdin);
//	freopen("e.out","w",stdout);
	math_init(N-5);
	n=k=read();
	for (int i=1;i<=n;++i)
		m=max(m,a[i]=read());
	for (int i=1;i<=n;++i){
		++p[a[i]+1];
		for (int j=a[i]+1;j<=n;j+=n)
			++cnt[j];
	}
	for (int i=1;i<=n;++i){
		++tot,k-=p[i];
		if (tot<cnt[i]) break;
		tot-=cnt[i];
		ad(ans,C(tot+n-1,n-1));
		ad(ans,Mod-C(tot-k+n-1,n-1));
	}
	printf("%d\n",ans);
	return 0;
}


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

using ll=long long;
#define int ll

#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=a;i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#ifdef LOCAL
#define dmp(x) cerr<<__LINE__<<" "<<#x<<" "<<x<<endl
#else
#define dmp(x) void(0)
#endif

template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

template<class t,class u>
ostream& operator<<(ostream& os,const pair<t,u>& p){
	return os<<"{"<<p.a<<","<<p.b<<"}";
}

template<class t> ostream& operator<<(ostream& os,const vc<t>& v){
	os<<"{";
	for(auto e:v)os<<e<<",";
	return os<<"}";
}

using uint=unsigned;
using ull=unsigned long long;

const uint mod=998244353;
//const uint mod=1000000007;
struct mint{
	uint v;
	mint(ll vv=0){s(vv%mod+mod);}
	mint& s(uint vv){
		v=vv<mod?vv:vv-mod;
		return *this;
	}
	mint operator-()const{return mint()-*this;}
	mint& operator+=(const mint&rhs){return s(v+rhs.v);}
	mint&operator-=(const mint&rhs){return s(v+mod-rhs.v);}
	mint&operator*=(const mint&rhs){
		v=ull(v)*rhs.v%mod;
		return *this;
	}
	mint&operator/=(const mint&rhs){return *this*=rhs.inv();}
	mint operator+(const mint&rhs)const{return mint(*this)+=rhs;}
	mint operator-(const mint&rhs)const{return mint(*this)-=rhs;}
	mint operator*(const mint&rhs)const{return mint(*this)*=rhs;}
	mint operator/(const mint&rhs)const{return mint(*this)/=rhs;}
	mint pow(int n)const{
		mint res(1),x(*this);
		while(n){
			if(n&1)res*=x;
			x*=x;
			n>>=1;
		}
		return res;
	}
	mint inv()const{return pow(mod-2);}
	/*mint inv()const{
		int x,y;
		int g=extgcd(v,mod,x,y);
		assert(g==1);
		if(x<0)x+=mod;
		return mint(x);
	}*/
	friend ostream& operator<<(ostream&os,const mint&m){
		return os<<m.v;
	}
	bool operator<(const mint&r)const{return v<r.v;}
};

const int Vmax=(1<<21)+10;
mint fact[Vmax],finv[Vmax],inv[Vmax];
void initfact(){
	fact[0]=1;
	rng(i,1,Vmax){
		fact[i]=fact[i-1]*i;
	}
	finv[Vmax-1]=fact[Vmax-1].inv();
	for(int i=Vmax-2;i>=0;i--){
		finv[i]=finv[i+1]*(i+1);
	}
	for(int i=Vmax-1;i>=1;i--){
		inv[i]=finv[i]*fact[i-1];
	}
}
mint choose(int n,int k){
	return fact[n]*finv[n-k]*finv[k];
}
mint binom(int a,int b){
	return fact[a+b]*finv[a]*finv[b];
}
mint catalan(int n){
	return binom(n,n)-(n-1>=0?binom(n-1,n+1):0);
}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout<<fixed<<setprecision(20);

	initfact();

	int k;cin>>k;
	vi a(k);rep(i,k)cin>>a[i];
	sort(all(a));

	rep(i,k)if(i>a[i]){
		int mx=a[i];
		int cnt=0;
		mint ans=0;
		rep(x,mx+1){
			while(a[cnt]<x)cnt++;
			ans+=choose(x-cnt+k-1,k-1);
		}
		cout<<ans<<endl;
		return 0;
	}

	int sum=0;
	vi cnt(k);
	for(auto v:a){
		sum+=v/k;
		cnt[v%k]++;
	}
	mint ans=0;
	rep(i,k){
		ans+=choose(sum+k-1,k-1);
		sum--;
		sum+=cnt[k-1-i];
	}
	cout<<ans<<endl;
}


#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
template <typename T>
struct modular
{
	constexpr modular() : val(0){}
	constexpr modular(const modular<T>& _m) : val(_m.val) {}
	template <typename U> constexpr modular(const U& _r = U())
	{
		val = -MOD <= _r && _r < MOD ? _r: _r % MOD;
		if (val < 0)
		{
			val += MOD;
		}
	}
	const T operator()()
	{
		return val;
	}
	template <typename U> explicit operator U() const
	{
		return static_cast<U>(val);
	}
	modular<T>& operator+=(const modular<T>& _m)
	{
		if ((val += _m.val) >= MOD)
		{
			val -= MOD;
		}
		return *this;
	}
	modular<T>& operator-=(const modular<T>& _m)
	{
		if ((val -= _m.val) < 0)
		{
			val += MOD;
		}
		return *this;
	}
	modular<T>& operator*=(const modular<T>& _m)
	{
		val = modular<T>(static_cast<int64_t>(val) * static_cast<int64_t>(_m.val)).val;
		return *this;
	}
	modular<T>& operator/=(const modular<T>& _m)
	{
		T a = _m.val, b = MOD, u = 0, v = 1;
		while (a != 0) {
			T q = b / a;
			b -= q * a; swap(a, b);
			u -= q * v; swap(u, v);
		} return *this *= u; }
	modular<T>& operator =(const modular<T>& _m)
	{
		val = _m.val;
		return *this;
	}
	template <typename U> modular<T>& operator+=(const U& _r)
	{
		return *this += modular<T>(_r);
	}
	template <typename U> modular<T>& operator-=(const U& _r)
	{
		return *this -= modular<T>(_r);
	}
	template <typename U> modular<T>& operator*=(const U& _r)
	{
		return *this *= modular<T>(_r);
	}
	template <typename U> modular<T>& operator/=(const U& _r)
	{
		return *this /= modular<T>(_r);
	}
	template <typename U> modular<T>& operator =(const U& _r)
	{
		val = modular<T>(_r).val;
		return *this;
	}
	modular<T> operator-()
	{
		return modular<T>(-val);
	}
	template <typename U> friend bool operator==(const modular<U>&, const modular<U>&);
	friend std::istream& operator>>(std::istream& os, modular<T>& _m)
	{
		os >> _m.val;
		_m *= 1;
		return os;
	}
	friend std::ostream& operator<<(std::ostream& os, const modular<T>& _m)
	{
		return os << _m.val;
	}
	template <typename U> modular<T> exp(U e)
	{
		modular<T> res = 1;
		modular<T> b = val;
		if (e < 0)
		{
			b = 1/b;
			e *= -1;
		}
		for (; e; e >>= 1)
		{
			if (e & 1)
			{
				res *= b;
			}
			b *= b;
		}
		return res;
	}
private:
	T val;
};
template <typename T> inline modular<T> operator+(const modular<T>& _lhs, const modular<T>& _rhs)
{
	return modular<T>(_lhs) += _rhs;
}
template <typename T, typename U> inline modular<T> operator+(const modular<T>& _lhs, const U& _rhs)
{
	return modular<T>(_lhs) += _rhs;
}
template <typename T, typename U> inline modular<T> operator+(const U& _lhs, const modular<T>& _rhs)
{
	return modular<T>(_lhs) += _rhs;
}
template <typename T> inline modular<T> operator-(const modular<T>& _lhs, const modular<T>& _rhs)
{
	return modular<T>(_lhs) -= _rhs;
}
template <typename T, typename U> inline modular<T> operator-(const modular<T>& _lhs, const U& _rhs)
{
	return modular<T>(_lhs) -= _rhs;
}
template <typename T, typename U> inline modular<T> operator-(const U& _lhs, const modular<T>& _rhs)
{
	return modular<T>(_lhs) -= _rhs;
}
template <typename T> inline modular<T> operator*(const modular<T>& _lhs, const modular<T>& _rhs)
{
	return modular<T>(_lhs) *= _rhs;
}
template <typename T, typename U> inline modular<T> operator*(const modular<T>& _lhs, const U& _rhs)
{
	return modular<T>(_lhs) *= _rhs;
}
template <typename T, typename U> inline modular<T> operator*(const U& _lhs, const modular<T>& _rhs)
{
	return modular<T>(_lhs) *= _rhs;
}
template <typename T> inline modular<T> operator/(const modular<T>& _lhs, const modular<T>& _rhs)
{
	return modular<T>(_lhs) /= _rhs;
}
template <typename T, typename U> inline modular<T> operator/(const modular<T>& _lhs, const U& _rhs)
{
	return modular<T>(_lhs) /= _rhs;
}
template <typename T, typename U> inline modular<T> operator/(const U& _lhs, const modular<T>& _rhs)
{
	return modular<T>(_lhs) /= _rhs;
}
template <typename T> inline bool operator==(const modular<T>& _lhs, const modular<T>& _rhs)
{
	return _lhs.val == _rhs.val;
}
template <typename T, typename U> inline bool operator==(const modular<T>& _lhs, const U& _rhs)
{
	return _lhs == modular<T>(_rhs);
}
template <typename T, typename U> inline bool operator==(const U& _lhs, const modular<T>& _rhs)
{
	return modular<T>(_lhs) == _rhs;
}
template <typename T> inline bool operator!=(const modular<T>& _lhs, const modular<T>& _rhs)
{
	return !(_lhs == _rhs);
}
template <typename T, typename U> inline bool operator!=(const modular<T>& _lhs, const U& _rhs)
{
	return !(_lhs == _rhs);
}
template <typename T, typename U> inline bool operator!=(const U& _lhs, const modular<T>& _rhs)
{
	return !(_lhs == _rhs);
}
typedef modular<int> mint;
struct Comb
{
	int n;
	vector<mint> fac, ifac, inv;
	Comb(int _n=1)
	{
		resize(2);
		fac[0] = fac[1] = ifac[0] = ifac[1] = inv[1] = 1;
		n = 1;
		grow(_n);
	}
	void resize(int _s)
	{
		fac.resize(_s);
		ifac.resize(_s);
		inv.resize(_s);
	}
	bool grow(int _n)
	{
		if (_n <= n) return false;
		resize(_n+1);
		for (int i = n+1; i <= _n; i++)
		{
			fac[i] = fac[i-1] * i;
			inv[i] = (-MOD/i) * inv[MOD%i];
			ifac[i] = ifac[i-1] * inv[i];
		}
		n = _n;
		return true;
	}
	mint c(int N, int K)
	{
		if (N < K || K < 0) return 0;
		if (N > n) grow(N);
		return fac[N] * ifac[N-K] * ifac[K];
	}
	mint p(int S, int K)
	{
		return c(S-1, K-1);
	}
	mint z(int S, int K)
	{
		return p(S+K, K);
	}
};
void solve()
{
	int n; cin >> n;
	vector<int> a(n);
	for (auto& x: a)
	{
		cin >> x;
	}
	sort(a.begin(), a.end());
	Comb c(n);
	int critical = -1;
	for (int i = 0; i < n; i++)
	{
		if (a[i] < i)
		{
			critical = i;
			break;
		}
	}
	mint res;
	if (critical != -1)
	{
		res = 1;
		for (int i = 1; i < critical; i++)
		{
			int p = lower_bound(a.begin(), a.end(), i) - a.begin();
			res += c.z(i-p, n);
		}
	}
	else
	{
		int S = 0;
		int M = 0;
		vector<int> cnt(n, 0);
		for (auto& x: a)
		{
			S += x;
			cnt[x %= n]++;
			M += x;
		}
		for (int i = 1; i < n; i++)
		{
			cnt[i] += cnt[i-1];
		}
		res = 0;
		for (int i = 0; i < n; i++)
		{
			int t = S - (M + 1ll*i*n - 1ll*n*(n - cnt[n-i-1]));
			assert(t%n == 0);
			t /= n;
			res += c.z(t, n);
		}
	}
	cout << res;
}
int main(void)
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	solve();
	cout << endl;
	return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define pll pair <ll, ll>
#define pci pair <char, int>
#define ppll pair <pll, pll>
#define vll vector <ll>
#define vvll vector <vll>
#define vpll vector <pll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mll map <ll, ll>
#define fastmap gp_hash_table
#define cd complex <double>
#define vcd vector <cd>
#define PI 3.14159265358979
#pragma 03
using namespace std;
using namespace __gnu_pbds;
// I read the editorial before (when I was a novice, yes, but still it gives away important keypoints...)
ll mod = 998244353;
ll fact[1000005], invfact[1000005], inv[1000005], car[1000005], a[1000005], pre[1000005];
ll nck(ll n, ll k){
	if (n < k) return 0;
	return ((fact[n] * invfact[k]) % mod * invfact[n-k]) % mod;
}
int main(){
	fastio;
	// preset
	fact[0] = 1; fact[1] = 1; invfact[0] = 1; invfact[1] = 1; inv[1] = 1;
	for (ll i = 2; i<1000005; i++){
		fact[i] = (fact[i - 1] * i) % mod;
		inv[i] = (inv[mod % i] * (mod - mod / i)) % mod;
		invfact[i] = invfact[i - 1] * inv[i];
	}
	ll k;
    cin >> k;
    ll sum = 0;
    ll srem = 0;
    for (ll i = 0; i<k; i++){
        cin >> a[i]; sum += a[i];
        ll rem = a[i] % k;
        srem += rem;
        car[rem + 1] += k;
    }
    for (ll i = 0; i<k; i++) pre[a[i]]++;
    for (ll i = 1; i<=k; i++) pre[i] += pre[i-1];
    bool cri = 0;
    ll ans = 0;
    // solve for critical configuration
    for (ll mv = 1; mv<k; mv++){
        if (pre[mv - 1] >= mv + 1){
            cri = true; break;
        }
        ll v = mv - pre[mv - 1];
        (ans += nck(v + k - 1, v)) %= mod;
    }
    if (cri){
    	cout << (ans + 1) % mod;
        return 0;
    }
    // solve for non-critical configuration
    ans = 0;
    for (ll rem = 0; rem<k; rem++){
        if (rem > 0) car[rem] += car[rem-1];
        ll h = (sum - srem - car[rem] + rem * k) / k;
        (ans += nck(h + k - 1, k - 1)) %= mod;
    }
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define pll pair <ll, ll>
#define pci pair <char, int>
#define ppll pair <pll, pll>
#define vll vector <ll>
#define vvll vector <vll>
#define vpll vector <pll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mll map <ll, ll>
#define fastmap gp_hash_table
#define cd complex <double>
#define vcd vector <cd>
#define PI 3.14159265358979
#pragma 03
using namespace std;
using namespace __gnu_pbds;
// I read the editorial before (when I was a novice, yes, but still it gives away important points...)
ll mod = 998244353;
ll fact[1000005], invfact[1000005], inv[1000005], car[1000005], a[1000005], pre[1000005];
ll nck(ll n, ll k){
	if (n < k) return 0;
	return ((fact[n] * invfact[k]) % mod * invfact[n-k]) % mod;
}
int main(){
	fastio;
	// preset
	for (ll i = 0; i<1000005; i++) car[i] = 0, pre[i] = 0;
	fact[0] = 1; fact[1] = 1; invfact[0] = 1; invfact[1] = 1; inv[1] = 1;
	for (ll i = 2; i<1000005; i++){
		fact[i] = (fact[i - 1] * i) % mod;
		inv[i] = (inv[mod % i] * (mod - mod / i)) % mod;
		invfact[i] = (invfact[i - 1] * inv[i]) % mod;
	}
	ll k;
    cin >> k;
    ll sum = 0;
    ll srem = 0;
    for (ll i = 0; i<k; i++){
        cin >> a[i]; sum += a[i];
        ll rem = a[i] % k;
        srem += rem;
        car[rem + 1] += k;
    }
    for (ll i = 0; i<k; i++) pre[a[i]]++;
    for (ll i = 1; i<=k; i++) (pre[i] += pre[i - 1]) % mod;
    bool cri = 0;
    ll ans = 0;
    // solve for critical configuration
    for (ll mv = 1; mv<k; mv++){
        if (pre[mv - 1] >= mv + 1){
            cri = true; break;
        }
        ll v = (mv - pre[mv - 1] + mod) % mod;
        (ans += nck(v + k - 1, v)) %= mod;
    }
    if (cri){
    	cout << (ans + 1) % mod;
        return 0;
    }
    // solve for non-critical configuration
    ans = 0;
    for (ll rem = 0; rem<k; rem++){
        if (rem > 0) (car[rem] += car[rem - 1]) %= mod;
        ll h = (sum - srem - car[rem] + rem * k) / k;
        (ans += nck(h + k - 1, k - 1)) %= mod;
    }
    cout << ans;
    return 0;
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e5+2;
const int M=1e6+2;
const int mod=998244353;
int ar[N],fact[M],inv[M],cnt[N];
int binpow(int x,int y){
	int tich=1;
	while(y){
		if(y&1){
			tich*=x;
			tich%=mod;
		}
		x*=x;
		x%=mod;
		y>>=1;
	}
	return tich;
}
int C(int x,int y){
	return ((fact[y]*inv[y-x])%mod*inv[x])%mod;
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,i,j,k,l,ans=0,sum=0;
	cin>>n;
	for(i=1;i<=n;i++){
		cin>>ar[i];
		cnt[ar[i]%n]++;
		sum+=ar[i];
	}
//	for(i=2;i<=n;i++){
//		cnt[i]+=cnt[i-1];
//	}
	fact[0]=1;
	for(i=1;i<M-1;i++){
		fact[i]=(fact[i-1]*i)%mod;
	}
	inv[M-2]=binpow(fact[M-2],mod-2);
	for(i=M-2;i>0;i--){
		inv[i-1]=(inv[i]*i)%mod;
	}
	sort(ar+1,ar+1+n);
	int pos=0;
	for(i=1;i<n;i++){
		if(ar[i+1]<i){
			pos=i;
			break;
		}
	}
	//less than pos operator ?
	if(pos){
		j=1;
		for(i=0;i<pos;i++){
			while(ar[j]<i){
				j++;
			}
			ans+=C(n-1,i-(j-1)+n-1);		//sum plus n-1 "1" minus the position need to be positive
			if(ans>=mod){
				ans-=mod;
			}
		}
		cout<<ans;
	}
	else{
		for(i=1;i<=n;i++){
			sum-=ar[i]%n;
		}
		sum/=n;
		//cout<<sum<<endl;
		for(i=1;i<=n;i++){		//sum equal to (sigma a(i) - sigma( (a(i)+i)%k ) / k) for i as remainder
			sum=sum+cnt[n-i]-1;		//sum= sum + cnt[n-i]*(n-1) - n + cnt[n-i]
			//cout<<sum<<endl;
			if(sum>=0){
				ans+=C(n-1,sum+n-1);
				if(ans>=mod){
					ans-=mod;
				}
			}
		}
		cout<<ans;
	}
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fast_IO ios::sync_with_stdio(false);
#define DEBUG fprintf(stderr,"Running on Line %d in Function %s\n",__LINE__,__FUNCTION__)
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define fir first
#define sec second
#define mod 998244353
#define ll long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
inline int read()
{
	char ch=getchar(); int nega=1; while(!isdigit(ch)) {if(ch=='-') nega=-1; ch=getchar();}
	int ans=0; while(isdigit(ch)) {ans=ans*10+ch-48;ch=getchar();}
	if(nega==-1) return -ans;
	return ans;
}
typedef pair<int,int> pii;
inline int add(int x,int y){return x+y>=mod?x+y-mod:x+y;}
inline int add(int x,int y,int z){return add(add(x,y),z);}
inline int sub(int x,int y){return x-y<0?x-y+mod:x-y;}
inline int mul(int x,int y){return 1LL*x*y%mod;}
inline int mul(int x,int y,int z){return mul(mul(x,y),z);}
#define N 2000005
int fac[N],inv[N],pinv[N];
void init()
{
	fac[0]=1; for(int i=1;i<N;i++) fac[i]=mul(fac[i-1],i);
	inv[0]=inv[1]=1; for(int i=2;i<N;i++) inv[i]=mul(mod-mod/i,inv[mod%i]);
	pinv[0]=1; for(int i=1;i<N;i++) pinv[i]=mul(pinv[i-1],inv[i]);
}
int C(int x,int y){return x>=y?mul(fac[x],pinv[x-y],pinv[y]):0;}
int a[N],n,ct[N];
signed main()
{
	init();
	cin>>n; for(int i=1;i<=n;i++) a[i]=read(),ct[a[i]]++;
	int maxn=*max_element(a+1,a+n+1);
	int ans=1,sum=0,sum2=0;
	for(int i=1;i<=maxn;i++)
	{
		sum2+=ct[i-1];
		if(i-1>n) ct[i-1]+=ct[i-1-n];
		sum+=ct[i-1];
		if(sum>i) break;
		int r=i-sum;
		// printf("%d %d * %d %d\n",r+n+1,r-1,r+sum2-1,r-1);
		ans=add(ans,sub(C(r+n-1,n-1),C(r+sum2-1,n-1)));
	}
	cout<<ans<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fast_IO ios::sync_with_stdio(false);
#define DEBUG fprintf(stderr,"Running on Line %d in Function %s\n",__LINE__,__FUNCTION__)
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define fir first
#define sec second
#define mod 998244353
#define ll long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
inline int read()
{
	char ch=getchar(); int nega=1; while(!isdigit(ch)) {if(ch=='-') nega=-1; ch=getchar();}
	int ans=0; while(isdigit(ch)) {ans=ans*10+ch-48;ch=getchar();}
	if(nega==-1) return -ans;
	return ans;
}
typedef pair<int,int> pii;
inline int add(int x,int y){return x+y>=mod?x+y-mod:x+y;}
inline int add(int x,int y,int z){return add(add(x,y),z);}
inline int sub(int x,int y){return x-y<0?x-y+mod:x-y;}
inline int mul(int x,int y){return 1LL*x*y%mod;}
inline int mul(int x,int y,int z){return mul(mul(x,y),z);}
#define N 2000005
int fac[N],inv[N],pinv[N];
void init()
{
	fac[0]=1; for(int i=1;i<N;i++) fac[i]=mul(fac[i-1],i);
	inv[0]=inv[1]=1; for(int i=2;i<N;i++) inv[i]=mul(mod-mod/i,inv[mod%i]);
	pinv[0]=1; for(int i=1;i<N;i++) pinv[i]=mul(pinv[i-1],inv[i]);
}
int C(int x,int y){return x>=y?mul(fac[x],pinv[x-y],pinv[y]):0;}
int a[N],n,ct[N];
signed main()
{
	init();
	cin>>n; for(int i=1;i<=n;i++) a[i]=read(),ct[a[i]]++;
	int maxn=*max_element(a+1,a+n+1);
	int ans=1,sum=0,sum2=0;
	for(int i=1;i<=maxn;i++)
	{
		sum2+=ct[i-1];
		if(i-1>n) ct[i-1]+=ct[i-1-n];
		sum+=ct[i-1];
		if(sum>i) continue;
		int r=i-sum;
		// printf("%d %d * %d %d\n",r+n+1,r-1,r+sum2-1,r-1);
		ans=add(ans,sub(C(r+n-1,n-1),C(r+sum2-1,n-1)));
	}
	cout<<ans<<endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

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

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

template <typename T>
void resize(int n, vector<T> &u) {
  u.resize(n);
}

template <typename Head, typename... Tail>
void resize(int n, Head &H, Tail&... T) {
  resize(n, H);
  resize(n, T...);
}

template <typename T, typename Head>
void to_dimension(T m, Head &u, int n) {
  u.resize(n, m);
}

template <typename T>
void set_dimension(T &u, int n) {
  u.resize(n);
}

template <typename T, typename Head, typename... Tail>
void to_dimension(T m, Head &u, int n, Tail... F) {
  u.resize(n);
  for(auto &i : u) {
    to_dimension(m, i, F...);
  }
}

template <typename Head, typename... Tail>
void set_dimension(Head &u, int n, Tail... F) {
  u.resize(n);
  for(auto &i : u) {
    set_dimension(i, F...);
  }
}

template <typename T>
void unique(vector<T> &u) {
  sort(u.begin(), u.end());
  u.resize(unique(u.begin(), u.end()) - u.begin());
}

template <typename T>
void debug_out(T t) {
  cerr << t;
}

template <typename A, typename B>
void debug_out(pair<A, B> u) {
  cerr << "(" << u.first << " " << u.second << ")";
}

template <typename T>
void debug_out(vector<T> t) {
  int sz = t.size();
  for(int i = 0; i < sz; i++) {
    debug_out(t[i]);
    if(i != sz - 1) cerr << ", ";
  }
}

template <typename T>
void debug_out(vector<vector<T>> t) {
  int sz = t.size();
  for(int i = 0; i < sz; i++) {
    debug_out(t[i]);
    if(i != sz - 1) cerr << endl;
  }
}

template<typename T>
T maxest(T a, T b) {
  return (a > b ? a : b);
}

template<typename T, typename... Tail>
T maxest(T a, T b, Tail... c) {
  return maxest(maxest(a, b), c...);
}

template<typename T>
T minest(T a, T b) {
  return (a < b ? a : b);
}

template<typename T, typename... Tail>
T minest(T a, T b, Tail... c) {
  return minest(minest(a, b), c...);
}

vector<char> lowchar = {'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'};
vector<char> hichar = {'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'};
vector<char> base_10 = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
vector<int> dx = {0, 0, 1, -1}, dy = {1, -1, 0, 0};

template <typename T>
string to_string(T t) {
  ostringstream ss;
  ss << t;
  return ss.str();
}

long long to_num(string t) {
  long long res = 0;
  for(int i = 0; i < (int) t.length(); i++) {
    res *= 10;
    res += t[i] - '0';
  }
  return res;
}

string to_base(long long n, int base) {
  string res;
  while(n) {
    res += to_string(n % base);
    n /= base;
  }
  reverse(res.begin(), res.end());
  return res;
}

inline int next_bit_perm(int v) {
  int t = v | (v - 1);
  return (t + 1) | (((~t & -~t) - 1) >> (__builtin_ctz(v) + 1));
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:" << endl, debug_out(__VA_ARGS__), cerr << endl;
#define range(i, m, n) for(int i = m; i < n; i++)
#define husk(i, m, n) for(int i = m; i > n; i--)
#define sub_mask(i, mask) for(int i = mask; ~i; i = (i == 0 ? -1 : (i - 1) & mask))
#define card_mask(i, n) for(int k = 1; k <= n; k++) for(int i = (1 << k) - 1; i < (1 << n); i = next_bit_perm(i))

template <typename T>
T inverse(T a, T m) {
  T u = 0, v = 1;
  while (a != 0) {
    T t = m / a;
    m -= t * a; swap(a, m);
    u -= t * v; swap(u, v);
  }
  assert(m == 1);
  return u;
}

template <typename T>
class Modular {
 public:
  using Type = typename decay<decltype(T::value)>::type;

  constexpr Modular() : value() {}
  template <typename U>
  Modular(const U& x) {
    value = normalize(x);
  }

  template <typename U>
  static Type normalize(const U& x) {
    Type v;
    if (-mod() <= x && x < mod()) v = static_cast<Type>(x);
    else v = static_cast<Type>(x % mod());
    if (v < 0) v += mod();
    return v;
  }

  const Type& operator()() const { return value; }
  template <typename U>
  explicit operator U() const { return static_cast<U>(value); }
  constexpr static Type mod() { return T::value; }

  Modular& operator+=(const Modular& other) { if ((value += other.value) >= mod()) value -= mod(); return *this; }
  Modular& operator-=(const Modular& other) { if ((value -= other.value) < 0) value += mod(); return *this; }
  template <typename U> Modular& operator+=(const U& other) { return *this += Modular(other); }
  template <typename U> Modular& operator-=(const U& other) { return *this -= Modular(other); }
  Modular& operator++() { return *this += 1; }
  Modular& operator--() { return *this -= 1; }
  Modular operator++(int) { Modular result(*this); *this += 1; return result; }
  Modular operator--(int) { Modular result(*this); *this -= 1; return result; }
  Modular operator-() const { return Modular(-value); }

  template <typename U = T>
  typename enable_if<is_same<typename Modular<U>::Type, int>::value, Modular>::type& operator*=(const Modular& rhs) {
#ifdef _WIN32
    uint64_t x = static_cast<int64_t>(value) * static_cast<int64_t>(rhs.value);
    uint32_t xh = static_cast<uint32_t>(x >> 32), xl = static_cast<uint32_t>(x), d, m;
    asm(
      "divl %4; \n\t"
      : "=a" (d), "=d" (m)
      : "d" (xh), "a" (xl), "r" (mod())
    );
    value = m;
#else
    value = normalize(static_cast<int64_t>(value) * static_cast<int64_t>(rhs.value));
#endif
    return *this;
  }
  template <typename U = T>
  typename enable_if<is_same<typename Modular<U>::Type, int64_t>::value, Modular>::type& operator*=(const Modular& rhs) {
    int64_t q = static_cast<int64_t>(static_cast<long double>(value) * rhs.value / mod());
    value = normalize(value * rhs.value - q * mod());
    return *this;
  }
  template <typename U = T>
  typename enable_if<!is_integral<typename Modular<U>::Type>::value, Modular>::type& operator*=(const Modular& rhs) {
    value = normalize(value * rhs.value);
    return *this;
  }

  Modular& operator/=(const Modular& other) { return *this *= Modular(inverse(other.value, mod())); }

  template <typename U>
  friend bool operator==(const Modular<U>& lhs, const Modular<U>& rhs);

  template <typename U>
  friend bool operator<(const Modular<U>& lhs, const Modular<U>& rhs);

  template <typename U>
  friend std::istream& operator>>(std::istream& stream, Modular<U>& number);

 private:
  Type value;
};

template <typename T> bool operator==(const Modular<T>& lhs, const Modular<T>& rhs) { return lhs.value == rhs.value; }
template <typename T, typename U> bool operator==(const Modular<T>& lhs, U rhs) { return lhs == Modular<T>(rhs); }
template <typename T, typename U> bool operator==(U lhs, const Modular<T>& rhs) { return Modular<T>(lhs) == rhs; }

template <typename T> bool operator!=(const Modular<T>& lhs, const Modular<T>& rhs) { return !(lhs == rhs); }
template <typename T, typename U> bool operator!=(const Modular<T>& lhs, U rhs) { return !(lhs == rhs); }
template <typename T, typename U> bool operator!=(U lhs, const Modular<T>& rhs) { return !(lhs == rhs); }

template <typename T> bool operator<(const Modular<T>& lhs, const Modular<T>& rhs) { return lhs.value < rhs.value; }

template <typename T> Modular<T> operator+(const Modular<T>& lhs, const Modular<T>& rhs) { return Modular<T>(lhs) += rhs; }
template <typename T, typename U> Modular<T> operator+(const Modular<T>& lhs, U rhs) { return Modular<T>(lhs) += rhs; }
template <typename T, typename U> Modular<T> operator+(U lhs, const Modular<T>& rhs) { return Modular<T>(lhs) += rhs; }

template <typename T> Modular<T> operator-(const Modular<T>& lhs, const Modular<T>& rhs) { return Modular<T>(lhs) -= rhs; }
template <typename T, typename U> Modular<T> operator-(const Modular<T>& lhs, U rhs) { return Modular<T>(lhs) -= rhs; }
template <typename T, typename U> Modular<T> operator-(U lhs, const Modular<T>& rhs) { return Modular<T>(lhs) -= rhs; }

template <typename T> Modular<T> operator*(const Modular<T>& lhs, const Modular<T>& rhs) { return Modular<T>(lhs) *= rhs; }
template <typename T, typename U> Modular<T> operator*(const Modular<T>& lhs, U rhs) { return Modular<T>(lhs) *= rhs; }
template <typename T, typename U> Modular<T> operator*(U lhs, const Modular<T>& rhs) { return Modular<T>(lhs) *= rhs; }

template <typename T> Modular<T> operator/(const Modular<T>& lhs, const Modular<T>& rhs) { return Modular<T>(lhs) /= rhs; }
template <typename T, typename U> Modular<T> operator/(const Modular<T>& lhs, U rhs) { return Modular<T>(lhs) /= rhs; }
template <typename T, typename U> Modular<T> operator/(U lhs, const Modular<T>& rhs) { return Modular<T>(lhs) /= rhs; }

template<typename T, typename U>
Modular<T> power(const Modular<T>& a, const U& b) {
  assert(b >= 0);
  Modular<T> x = a, res = 1;
  U p = b;
  while (p > 0) {
    if (p & 1) res *= x;
    x *= x;
    p >>= 1;
  }
  return res;
}

template <typename T>
string to_string(const Modular<T>& number) {
  return to_string(number());
}

template <typename T>
std::ostream& operator<<(std::ostream& stream, const Modular<T>& number) {
  return stream << number();
}

template <typename T>
std::istream& operator>>(std::istream& stream, Modular<T>& number) {
  typename common_type<typename Modular<T>::Type, int64_t>::type x;
  stream >> x;
  number.value = Modular<T>::normalize(x);
  return stream;
}

constexpr int md = (int) 998244353;
using Mint = Modular<std::integral_constant<decay<decltype(md)>::type, md>>;

const int MAX = 1e6 + 2e5 + 5;
vector<Mint> per(MAX);
vector<Mint> iper(MAX);

Mint c(int x, int y) {
  if(y > x || y < 0) return Mint(0);
  return per[x] * iper[y] * iper[x - y];
}

int n;

int main() {
  per[0] = iper[0] = 1;
  range(i, 1, MAX) {
    per[i] = per[i - 1] * i;
    iper[i] = 1 / per[i];
  }
  cin >> n;
  vector<int> a(n);
  vector<int> cnt(n);
  range(i, 0, n) {
    cin >> a[i];
    if(a[i] < n) cnt[a[i]]++;
  }
  bool endgame = false;
  int stk = 0;
  Mint res = 1;
  range(i, 1, n) {
    stk++;
    stk -= cnt[i - 1];
    if(stk < 0) {
      endgame = true;
      break;
    }
    res += c(stk + n - 1, n - 1);
  }
  if(endgame) {
    cout << res;
    return 0;
  }
  res = 0;
  int sum = 0;
  fill(cnt.begin(), cnt.end(), 0);
  range(i, 0, n) {
    sum += a[i];
    a[i] %= n;
    cnt[a[i]]++;
  }
  int foo = 0;
  range(i, 0, n) foo += a[i];
  range(i, 0, n) {
    if(i) {
      foo -= n;
      foo += n * cnt[i - 1];
    }
    assert(foo >= 0);
    int f = (sum - foo) / n;
    res += c(f + n - 1, n - 1);
  }
  cout << res;
  return 0;
}


#include<bits/stdc++.h>

using namespace std;
#define ll long long

const int N = 100005, M = 1000005, P = 998244353;
int n, sum, cnt[N], f[N], a[N], fac[M], ifac[M];
int Pow(ll x, int y=P-2){
	int ans=1;
	for(; y; y>>=1, x=x*x%P) if(y&1) ans=ans*x%P;
	return ans;
}
void work(int x){
	for(int i=1; i<=x; ++i) if(a[i]<x) ++f[a[i]+1];
	int now=0, ans=0;
	for(int i=0; i<x; ++i){
		now+=f[i];
		ans=(ans+(ll)fac[i-now+n-1]*ifac[n-1]%P*ifac[i-now])%P;
	}
	printf("%d\n", ans);
}
int main() {
	fac[0]=1;
	for(int i=1; i<=1000000; ++i) fac[i]=(ll)fac[i-1]*i%P;
	ifac[1000000]=Pow(fac[1000000]);
	for(int i=1000000; i; --i) ifac[i-1]=(ll)ifac[i]*i%P;
	scanf("%d", &n);
	for(int i=1; i<=n; ++i) scanf("%d", a+i);
	sort(a+1, a+n+1);
	for(int i=1; i<=n; ++i) if(a[i]<i-1) return work(i-1), 0;
	for(int i=1; i<=n; ++i) ++cnt[a[i]%n], sum+=a[i]-a[i]%n;
	sum/=n;
	int ans=0;
	for(int i=0; i<n; ++i){
		ans=(ans+(ll)fac[sum+n-1]*ifac[n-1]%P*ifac[sum])%P;
		sum=sum-1+cnt[n-i-1];
	}
	printf("%d\n", ans);
	return 0;
}


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

typedef long long lint;
typedef long double louble;

template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return a<b?b:a;}
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}

const char lf = '\n';

namespace ae86
{
	const int bufl = 1 << 15;

	char buf[bufl],*s=buf,*t=buf;

	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}

	inline int ty()
	{
		int a=0;int b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}
}
using ae86::ty;

const int _ = 100007 , __ = 2000007 , mo = 998244353;

template<typename T1,typename T2> inline T1 ad(T1 &a,T2 b){return a=a+b>=mo?a+b-mo:a+b;}
template<typename T1,typename T2> inline T1 dl(T1 &a,T2 b){return a=a>=b?a-b:a-b+mo;}
template<typename T1,typename T2> inline T1 add(T1 a,T2 b){return a+b>=mo?a+b-mo:a+b;}
template<typename T1,typename T2> inline T1 del(T1 a,T2 b){return a>=b?a-b:a-b+mo;}

lint powa(lint a,lint t)
{
	lint b=1;a=(a+mo)%mo;
	while(t){if(t&1)b=b*a%mo;a=a*a%mo,t>>=1;}
	return b;
}

inline lint inva(lint a)
{
	return powa(a,mo-2);
}

lint jc[__],rjc[__];

void fuck(int n=__-1)
{
	jc[0]=jc[1]=rjc[0]=1;
	for(int i=2;i<=n;i++)jc[i]=jc[i-1]*i%mo;
	rjc[n]=inva(jc[n]);
	for(int i=n-1;i>=1;i--)rjc[i]=rjc[i+1]*(1ll+i)%mo;
}

lint C(int n,int m)
{
	if(n<m || n<0 || m<0)return 0;
	return jc[n]*rjc[m]%mo*rjc[n-m]%mo;
}

int n,val[_]={0},mxval=0,cnt[__]={0};
lint ned[__]={0};

int main()
{
	ios::sync_with_stdio(0),cout.tie(nullptr);

	fuck();

	n=ty();
	for(int i=1;i<=n;i++)val[i]=ty(),mxval=max(mxval,val[i]),cnt[val[i]+1]++;

	for(int i=1;i<=n;i++)for(int j=val[i]+1;j<=mxval;j+=n)ned[j]++;

	lint ans=1,los=0,res=n;
	for(int i=1;i<=mxval;i++)
	{
		los++,res-=cnt[i];
		if(los<ned[i])break;
		los-=ned[i],ad(ans,C(los+n-1,n-1));
		if(los>=res)dl(ans,C(los+n-1-res,n-1));
	}
	cout<<ans<<lf;

	return 0;
}


// Author -- xyr2005

#include<bits/stdc++.h>

#define lowbit(x) ((x)&(-(x)))
#define Finline __inline__ __attribute__ ((always_inline))
#define DEBUG fprintf(stderr,"Running on Line %d in Function %s\n",__LINE__,__FUNCTION__)
#define SZ(x) ((int)x.size())
#define mkpr std::make_pair
#define pb push_back

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef std::pair<int,int> pi;
typedef std::pair<ll,ll> pl;
using std::min;
using std::max;

const int inf=0x3f3f3f3f,Inf=0x7fffffff;
const ll INF=0x3f3f3f3f3f3f3f3f;

Finline uint rnd(){static uint seed=416;return seed+=0x71dad4bfu,seed^=seed>>5,seed+=0xc6f74d88u,seed^=seed<<17,seed+=0x25e6561u,seed^=seed>>13;}
template <typename _Tp>_Tp gcd(const _Tp &a,const _Tp &b){return (!b)?a:gcd(b,a%b);}
template <typename _Tp>Finline _Tp abs(const _Tp &a){return a>=0?a:-a;}
template <typename _Tp>Finline void chmax(_Tp &a,const _Tp &b){(a<b)&&(a=b);}
template <typename _Tp>Finline void chmin(_Tp &a,const _Tp &b){(b<a)&&(a=b);}
template <typename _Tp>Finline void read(_Tp &x)
{
	char ch(getchar());bool f(false);while(!isdigit(ch)) f|=ch==45,ch=getchar();
	x=ch&15,ch=getchar();while(isdigit(ch)) x=(((x<<2)+x)<<1)+(ch&15),ch=getchar();
	f&&(x=-x);
}
template <typename _Tp,typename... Args>Finline void read(_Tp &t,Args &...args){read(t);read(args...);}
template <typename _Tp,typename... Args>Finline _Tp min(const _Tp &a,const _Tp &b,const Args &...args){return a<b?min(a,args...):min(b,args...);}
template <typename _Tp,typename... Args>Finline _Tp max(const _Tp &a,const _Tp &b,const Args &...args){return a<b?max(b,args...):max(a,args...);}
Finline int read_str(char *s)
{
	char ch(getchar());while(ch==' '||ch=='\r'||ch=='\n') ch=getchar();
	char *tar=s;*tar=ch,ch=getchar();while(ch!=' '&&ch!='\r'&&ch!='\n'&&ch!=EOF) *(++tar)=ch,ch=getchar();
	return tar-s+1;
}
const int N=2000005;
const int mod=998244353;
template<typename _Tp1,typename _Tp2>Finline void add(_Tp1 &a,_Tp2 b){(a+=b)>=mod&&(a-=mod);}
template<typename _Tp1,typename _Tp2>Finline void sub(_Tp1 &a,_Tp2 b){(a-=b)<0&&(a+=mod);}
ll fac[N],inv[N],ifac[N];
Finline ll C(int n,int m)
{
	if(n<m||m<0||n<0) return 0;
	return fac[n]*ifac[m]%mod*ifac[n-m]%mod;
}
int a[N],c[N];
ll b[N];
Finline int calc(int n,int m,int k)
{
	return (C(k+n-1,n-1)-C(k-m+n-1,n-1)+mod)%mod;
}
int main()
{
	fac[0]=fac[1]=inv[0]=inv[1]=ifac[0]=ifac[1]=1;
	for(int i=2;i<N;++i) fac[i]=fac[i-1]*i%mod,inv[i]=inv[mod%i]*(mod-mod/i)%mod,ifac[i]=ifac[i-1]*inv[i]%mod;
	int n;read(n);
	int maxx=0;
	for(int i=1;i<=n;++i) read(a[i]),chmax(maxx,a[i]),++b[a[i]+1],++c[a[i]];
	for(int i=n;i<=maxx;++i) b[i]+=b[i-n];
	for(int i=1;i<=maxx;++i) b[i]+=b[i-1];
	for(int i=maxx;i>=0;--i) c[i]+=c[i+1];
	int ans=0;
	for(int t=0;t<=maxx;++t)
	{
		if(b[t]>t) break;
		add(ans,calc(n,c[t],t-b[t]));
	}
	printf("%d\n",ans);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll MOD = 998244353;
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;
}
ll bin_pow(ll x, ll p) {
	if (p == 0) return 1;
	if (p & 1) return mult(x, bin_pow(x, p - 1));
	return bin_pow(mult(x, x), p / 2);
}
ll rev(ll x) {
	return bin_pow(x, MOD - 2);
}

const int N = (int)2e6 + 3;
int k;
ll f[N], rf[N];

ll getC(int n, int m) {
	if (m < 0 || m > n) return 0;
	return mult(f[n], mult(rf[m], rf[n - m]));
}

int a[N], b[N];

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

	f[0] = 1;
	for (int i = 1; i < N; i++)
		f[i] = mult(f[i - 1], i);
	rf[N - 1] = rev(f[N - 1]);
	for (int i = N - 1; i > 0; i--)
		rf[i - 1] = mult(rf[i], i);

	scanf("%d", &k);
	for (int i = 0; i < k; i++) {
		int x;
		scanf("%d", &x);
		a[x]++;
	}
	int m = k;
	ll ans = 1;
	int sum = 0;
	for (int i = 0;; i++) {
		m -= a[i];
		sum += a[i] + b[i];
		b[i + k] += a[i] + b[i];
		if (sum > i + 1) break;
		if (m == 0) break;
		int S = i + 1 - sum;
		ans = add(ans, sub(getC(S + k - 1, S), getC(S - m + k - 1, S - m)));
	}
	printf("%lld\n", ans);

	return 0;
}


// https://codeforces.com/contest/1188/submission/56588689 (rainboy)
import java.io.*;
import java.util.*;

public class CF1188E extends PrintWriter {
	CF1188E() { super(System.out, true); }
	static class Scanner {
		Scanner(InputStream in) { this.in = in; } InputStream in;
		int k, l; byte[] bb = new byte[1 << 15];
		byte getc() {
			if (k >= l) {
				k = 0;
				try { l = in.read(bb); } catch (IOException e) { l = 0; }
				if (l <= 0) return -1;
			}
			return bb[k++];
		}
		int nextInt() {
			byte c = 0; while (c <= 32) c = getc();
			int a = 0;
			while (c > 32) { a = a * 10 + c - '0'; c = getc(); }
			return a;
		}
	}
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		CF1188E o = new CF1188E(); o.main(); o.flush();
	}

	static final int MD = 998244353;
	int d_, x_, y_;
	void gcd_(int a, int b) {
		if (b == 0) {
			d_ = a;
			x_ = 1; y_ = 0;
		} else {
			gcd_(b, a % b);
			int tmp = x_ - (a / b) * y_; x_ = y_; y_ = tmp;
		}
	}
	int inv(int a, int b) {
		gcd_(a, b);
		return x_;
	}
	int[] ff, gg;
	void init(int m) {
		ff = new int[m];
		gg = new int[m];
		for (int j = 0, f = 1; j < m; j++) {
			gg[j] = inv(ff[j] = f, MD);
			f = (int) ((long) f * (j + 1) % MD);
		}
	}
	int choose(int n, int k) {
		return n < k ? 0 : (int) ((long) ff[n] * gg[k] % MD * gg[n - k] % MD);
	}
	void main() {
		int n = sc.nextInt();
		int[] aa = new int[n];
		int a_ = 0;
		for (int i = 0; i < n; i++) {
			int a = sc.nextInt();
			a_ = Math.max(a_, aa[i] = a);
		}
		ArrayList[] ii = new ArrayList[a_ + 1];
		for (int a = 0; a <= a_; a++)
			ii[a] = new ArrayList<Integer>();
		for (int i = 0; i < n; i++) {
			int a = aa[i];
			ii[a].add(i);
		}
		init(a_ + n);
		boolean[] used = new boolean[n];
		int ans = 0;
		for (int a = 0, b = 0, c = n; ; b++) {
			while (a <= a_ && ii[a].isEmpty())
				a++;
			if (a < b || a > a_)
				break;
			int i = (int) ii[a].remove(ii[a].size() - 1);
			ans = (ans + choose(a - b + n - 1, n - 1)) % MD;
			if (!used[i]) {
				used[i] = true;
				c--;
			} else
				ans = (ans - choose(a - b - c + n - 1, n - 1)) % MD;
			if (a + n <= a_)
				ii[a + n].add(i);
		}
		if (ans < 0)
			ans += MD;
		println(ans);
	}
}


// https://codeforces.com/contest/1188/submission/56588689 (rainboy)
import java.io.*;
import java.util.*;

public class CF1188E extends PrintWriter {
	CF1188E() { super(System.out, true); }
	static class Scanner {
		Scanner(InputStream in) { this.in = in; } InputStream in;
		int k, l; byte[] bb = new byte[1 << 15];
		byte getc() {
			if (k >= l) {
				k = 0;
				try { l = in.read(bb); } catch (IOException e) { l = 0; }
				if (l <= 0) return -1;
			}
			return bb[k++];
		}
		int nextInt() {
			byte c = 0; while (c <= 32) c = getc();
			int a = 0;
			while (c > 32) { a = a * 10 + c - '0'; c = getc(); }
			return a;
		}
	}
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		CF1188E o = new CF1188E(); o.main(); o.flush();
	}

	static final int A = 1000000, MD = 998244353;
	int d_, x_, y_;
	void gcd_(int a, int b) {
		if (b == 0) {
			d_ = a;
			x_ = 1; y_ = 0;
		} else {
			gcd_(b, a % b);
			int tmp = x_ - (a / b) * y_; x_ = y_; y_ = tmp;
		}
	}
	int inv(int a, int b) {
		gcd_(a, b);
		return x_;
	}
	int[] ff, gg;
	void init(int m) {
		ff = new int[m];
		gg = new int[m];
		for (int j = 0, f = 1; j < m; j++) {
			gg[j] = inv(ff[j] = f, MD);
			f = (int) ((long) f * (j + 1) % MD);
		}
	}
	int choose(int n, int k) {
		return n < k ? 0 : (int) ((long) ff[n] * gg[k] % MD * gg[n - k] % MD);
	}
	void main() {
		int n = sc.nextInt();
		int[] aa = new int[n];
		int a_ = 0;
		for (int i = 0; i < n; i++) {
			int a = sc.nextInt();
			a_ = Math.max(a_, aa[i] = a);
		}
		ArrayList[] ii = new ArrayList[a_ + 1];
		for (int a = 0; a <= a_; a++)
			ii[a] = new ArrayList<Integer>();
		int[] kk = new int[a_ + 1];
		for (int i = 0; i < n; i++) {
			int a = aa[i];
			ii[a].add(i); kk[a]++;
		}
		init(a_ + n);
		boolean[] used = new boolean[n];
		int ans = 0;
		for (int a = 0, b = 0, c = n; ; b++) {
			while (a <= a_ && kk[a] == 0)
				a++;
			if (a < b || a > a_)
				break;
			int i = (int) ii[a].remove(ii[a].size() - 1); kk[a]--;
			ans = (ans + choose(a - b + n - 1, n - 1)) % MD;
			if (!used[i]) {
				used[i] = true;
				c--;
			} else
				ans = (ans - choose(a - b - c + n - 1, n - 1)) % MD;
			if (a + n <= a_) {
				ii[a + n].add(i); kk[a + n]++;
			}
		}
		if (ans < 0)
			ans += MD;
		println(ans);
	}
}


#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e6 + 5;
const int P = 998244353;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); }
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
int fac[MAXN], inv[MAXN];
int power(int x, int y) {
	if (y == 0) return 1;
	int tmp = power(x, y / 2);
	if (y % 2 == 0) return 1ll * tmp * tmp % P;
	else return 1ll * tmp * tmp % P * x % P;
}
int binom(int x, int y) {
	if (y > x) return 0;
	else return 1ll * fac[x] * inv[y] % P * inv[x - y] % P;
}
void init(int n) {
	fac[0] = 1;
	for (int i = 1; i <= n; i++)
		fac[i] = 1ll * fac[i - 1] * i % P;
	inv[n] = power(fac[n], P - 2);
	for (int i = n - 1; i >= 0; i--)
		inv[i] = inv[i + 1] * (i + 1ll) % P;
}
int a[MAXN], b[MAXN], cnt[MAXN];
void update(int &x, int y) {
	x += y;
	if (x >= P) x -= P;
}
int main() {
	int n, sum = 0, Max = 0; read(n);
	for (int i = 1; i <= n; i++) {
		read(a[i]);
		b[a[i] + 1]++;
		sum += a[i];
		chkmax(Max, a[i]);
	}
	init(sum + n);
	for (int i = 1; i <= n; i++)
	for (int j = a[i] + 1; j <= Max; j += n)
		cnt[j]++;
	int ans = 1, empty = 0, lft = n;
	for (int i = 1; i <= Max; i++) {
		empty++, lft -= b[i];
		if (empty < cnt[i]) break;
		empty -= cnt[i];
		update(ans, binom(empty + n - 1, n - 1));
		if (empty >= lft) update(ans, P - binom(empty - lft + n - 1, n - 1));
	}
	writeln(ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e6 + 5;
const int P = 998244353;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); }
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
int fac[MAXN], inv[MAXN];
int power(int x, int y) {
	if (y == 0) return 1;
	int tmp = power(x, y / 2);
	if (y % 2 == 0) return 1ll * tmp * tmp % P;
	else return 1ll * tmp * tmp % P * x % P;
}
int binom(int x, int y) {
	if (y > x) return 0;
	else return 1ll * fac[x] * inv[y] % P * inv[x - y] % P;
}
void init(int n) {
	fac[0] = 1;
	for (int i = 1; i <= n; i++)
		fac[i] = 1ll * fac[i - 1] * i % P;
	inv[n] = power(fac[n], P - 2);
	for (int i = n - 1; i >= 0; i--)
		inv[i] = inv[i + 1] * (i + 1ll) % P;
}
int a[MAXN], b[MAXN], cnt[MAXN];
void update(int &x, int y) {
	x += y;
	if (x >= P) x -= P;
}
int main() {
	int n, Max = 0; read(n);
	for (int i = 1; i <= n; i++) {
		read(a[i]);
		b[a[i] + 1]++;
		chkmax(Max, a[i]);
	}
	init(Max + n);
	for (int i = 1; i <= n; i++)
	for (int j = a[i] + 1; j <= Max; j += n)
		cnt[j]++;
	int ans = 1, empty = 0, lft = n;
	for (int i = 1; i <= Max; i++) {
		empty++, lft -= b[i];
		if (empty < cnt[i]) break;
		empty -= cnt[i];
		update(ans, binom(empty + n - 1, n - 1));
		if (empty >= lft) update(ans, P - binom(empty - lft + n - 1, n - 1));
	}
	writeln(ans);
	return 0;
}


//#define DEBUG
//#define USEPB_DS
#define USETR1
#define CPPELEVEN
#define GPP

/*
 * temp.cpp
 *
 *  Created on: 2012-7-18
 *      Author: BSBandme
 */
//#pragma comment(linker, "/STACK:1024000000,1024000000")

#include <bits/stdc++.h>

using namespace std;

#ifndef CPPELEVEN
#ifdef USETR1
#include <tr1/unordered_map>
#include <tr1/unordered_set>
using namespace tr1;
#endif
#else
#include <unordered_map>
#include <unordered_set>
#endif

#ifdef USEPB_DS
#include <ext/pb_ds/priority_queue.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
// binomial_heap_tag, rc_binomial_heap_tag, thin_heap_tag, binary_heap_tag
typedef __gnu_pbds::priority_queue<int, greater<int>, pairing_heap_tag> pq_type;
// splay_tree_tag, ov_tree_tag
typedef tree <int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update> tree_type;
#endif

#define mpr make_pair
typedef unsigned int ui;
typedef unsigned long long ull;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <double, double> pdd;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <double> vd;
typedef vector <string> vs;
typedef map <string, int> mpsi;
typedef map <double, int> mpdi;
typedef map <int, int> mpii;

const double pi = acos(0.0) * 2.0;
const long double eps = 1e-10;
const int step[8][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}, {-1, 1}, {1, 1}, {1, -1}, {-1, -1}};

template <class T> inline T abs1(T a) {return a < 0 ? -a : a;}

#ifndef CPPELEVEN
template <class T> inline T max1(T a, T b) { return b < a ? a : b; }
template <class T> inline T max1(T a, T b, T c) { return max1(max1(a, b), c); }
template <class T> inline T max1(T a, T b, T c, T d) { return max1(max1(a, b, c), d); }
template <class T> inline T max1(T a, T b, T c, T d, T e) { return max1(max1(a, b, c, d), e); }
template <class T> inline T min1(T a, T b) { return a < b ? a : b; }
template <class T> inline T min1(T a, T b, T c) { return min1(min1(a, b), c); }
template <class T> inline T min1(T a, T b, T c, T d) { return min1(min1(a, b, c), d); }
template <class T> inline T min1(T a, T b, T c, T d, T e) { return min1(min1(a, b, c, d), e); }
#else
template <typename t, typename t1>
t min1(t a, t1 b) { return a < b ? a : b; }
template <typename t, typename... arg>
t min1(t a, arg... arr) { return min1(a, min1(arr...)); }
template <typename t, typename t1>
t max1(t a, t1 b) { return a > b ? a : b; }
template <typename t, typename... arg>
t max1(t a, arg... arr) { return max1(a, max1(arr...)); }
#endif

inline int jud(double a, double b){
  if(abs(a) < eps && abs(b) < eps) return 0;
  else if(abs1(a - b) / max(abs1(a), abs1(b)) < eps) return 0;
  if(a < b) return -1;
  return 1;
}
template <typename t> inline int jud(t a, t b){
  if(a < b) return -1;
  if(a == b) return 0;
  return 1;
}

// f_lb == 1代表返回相同的一串的左边界，f_small == 1代表返回如果没有寻找的值返回小的数
template <typename it, typename t1>
inline int find(t1 val, it a, int na, bool f_small = 1, bool f_lb = 1){
  if(na == 0) return 0;
  int be = 0, en = na - 1;
  if(*a <= *(a + na - 1)){
    if(f_lb == 0) while(be < en){
      int mid = (be + en + 1) / 2;
      if(jud(*(a + mid), val) != 1) be = mid;
      else en = mid - 1;
    }else while(be < en){
      int mid = (be + en) / 2;
      if(jud(*(a + mid), val) != -1) en = mid;
      else be = mid + 1;
    }
    if(f_small && jud(*(a + be), val) == 1) be--;
    if(!f_small && jud(*(a + be), val) == -1) be++;
  } else {
    if(f_lb) while(be < en){
      int mid = (be + en + 1) / 2;
      if(jud(*(a + mid), val) != -1) be = mid;
      else en = mid - 1;
    }else while(be < en){
      int mid = (be + en) / 2;
      if(jud(*(a + mid), val) != 1) en = mid;
      else be = mid + 1;
    }
    if(!f_small && jud(*(a + be), val) == -1) be--;
    if(f_small && jud(*(a + be), val) == 1) be++;
  }
  return be;
}

template <class T> inline T lowb(T num) {return num & (-num); }
#ifdef GPP
inline int bitnum(ui nValue) { return __builtin_popcount(nValue); }
inline int bitnum(int nValue) { return __builtin_popcount(nValue); }
inline int bitnum(ull nValue) { return __builtin_popcount(nValue) + __builtin_popcount(nValue >> 32); }
inline int bitnum(ll nValue) { return __builtin_popcount(nValue) + __builtin_popcount(nValue >> 32); }
inline int bitmaxl(ui a) { if(a == 0) return 0; return 32 - __builtin_clz(a); }
inline int bitmaxl(int a) { if(a == 0) return 0; return 32 - __builtin_clz(a); }
inline int bitmaxl(ull a) { int temp = a >> 32; if(temp) return 32 - __builtin_clz(temp) + 32; return bitmaxl(int(a)); }
inline int bitmaxl(ll a) { int temp = a >> 32; if(temp) return 32 - __builtin_clz(temp) + 32; return bitmaxl(int(a)); }
#else
#endif

long long pow(long long n, long long m, long long mod = 0){
  if(m < 0) return 0;
  long long ans = 1;
  long long k = n;
  while(m){
    if(m & 1) {
      ans *= k;
      if(mod) ans %= mod;
    }
    k *= k;
    if(mod) k %= mod;
    m >>= 1;
  }
  return ans;
}

#define  MOD 1000000007
template <class t1, class t2>
inline void add(t1 &a, t2 b, int mod = -1) {
  if(mod == -1) mod = MOD;
  a += b;
  while(a >= mod) a -= mod;
  while(a < 0) a += mod;
}
template <class t>
void output1(t arr) {
  for(int i = 0; i < (int)arr.size(); i++)
    cerr << arr[i] << ' ';
  cerr << endl;
}
template <class t>
void output2(t arr) {
  for(int i = 0; i < (int)arr.size(); i++)
    output1(arr[i]);
}

//....................密..........封..........线..........下..........禁..........止..........hack...............................................

const int mod = 998244353;
const int maxn = 100100;
int arr[maxn], nxtbig[maxn];
ll fac[maxn * 11], invfac[maxn * 11];
ll dp[maxn * 11];
int n;

ll c(int a, int b) {
  if (a < b) return 0;
  return fac[a] * invfac[a - b] % mod * invfac[b] % mod;
}

int main() {
  //............................不要再忘了检查maxn大小了！！！！BSBandme你个SB！！！！........................................
  ios_base::sync_with_stdio(0);
  #ifdef DEBUG //......................................................................................................
  freopen("input.txt", "r", stdin);
  #endif //...........................................................................................................

  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", arr + i);
  fac[0] = 1;
  for (int i = 1; i < maxn * 11; i++) {
    fac[i] = fac[i - 1] * i % mod;
  }
  invfac[maxn * 11 - 1] = pow(fac[maxn * 11 - 1], mod - 2, mod);
  for (int i = maxn * 11 - 2; i >= 0; i--) {
    invfac[i] = invfac[i + 1] * (i + 1) % mod;
  }
  sort(arr, arr + n);
//  n = 100000;
//  for (int i = 0; i < n; i++) {
//    arr[i] = 0;
//  }
//  arr[n - 1] = 1000000;

  nxtbig[n - 1] = n;
  for (int i = n - 2; i >= 0; i--) {
    if (arr[i + 1] > arr[i]) nxtbig[i] = i + 1;
    else nxtbig[i] = nxtbig[i + 1];
  }

  int zero_idx = n - 1;
  for (int i = 0; i < n; i++) {
    if (arr[i] < i) {
      zero_idx = i;
      while (zero_idx < n - 1 && arr[zero_idx + 1] == arr[zero_idx]) zero_idx++;
      break;
    }
  }

  dp[0] = 1;
  for (int i = 1; i <= maxn * 10; i++) {
    dp[i] = dp[i - 1] + c(n - 2 + i, n - 2);
    dp[i] %= mod;
  }

  ll ans = 0;
  for (int i = 0; i <= zero_idx; i++) {
    ll added = 0;
    ll sum = 0, need_cnt = i;
    for (int j = 0; j < i; j = nxtbig[j]) {
      sum += (1ll * (arr[i] - arr[j]) / n + 1) * (min(nxtbig[j], i) - j);
    }
    for (; added * n + arr[i] <= arr[zero_idx]; ) {
      ll left = arr[i] + added * n - sum - added;
      if (left < 0) break;
      ans += dp[left];
      if (added != 0 && left >= n - (need_cnt + 1)) {
         ans -= dp[left - (n - (need_cnt + 1))];
      }
      ans %= mod;
//      while (left >= 0) {
//        ans += c(n - 2 + left, left);
//        if (added != 0 && left >= n - (need_cnt + 1)) {
//          ans -= c(left + n - 2 - (n - (need_cnt + 1)), n - 2);
//        }
//        ans %= mod;
//        left--;
//      }

      added++;
      while (need_cnt + 1 < n &&
          arr[need_cnt + 1] < added * n + arr[i])
        need_cnt = nxtbig[need_cnt + 1] - 1;
      sum += need_cnt;
    }
  }
  cout << (ans + mod) % mod << endl;

  return 0;
}


//#define DEBUG
//#define USEPB_DS
#define USETR1
#define CPPELEVEN
#define GPP

/*
 * temp.cpp
 *
 *  Created on: 2012-7-18
 *      Author: BSBandme
 */
//#pragma comment(linker, "/STACK:1024000000,1024000000")

#include <bits/stdc++.h>

using namespace std;

#ifndef CPPELEVEN
#ifdef USETR1
#include <tr1/unordered_map>
#include <tr1/unordered_set>
using namespace tr1;
#endif
#else
#include <unordered_map>
#include <unordered_set>
#endif

#ifdef USEPB_DS
#include <ext/pb_ds/priority_queue.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
// binomial_heap_tag, rc_binomial_heap_tag, thin_heap_tag, binary_heap_tag
typedef __gnu_pbds::priority_queue<int, greater<int>, pairing_heap_tag> pq_type;
// splay_tree_tag, ov_tree_tag
typedef tree <int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update> tree_type;
#endif

#define mpr make_pair
typedef unsigned int ui;
typedef unsigned long long ull;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <double, double> pdd;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <double> vd;
typedef vector <string> vs;
typedef map <string, int> mpsi;
typedef map <double, int> mpdi;
typedef map <int, int> mpii;

const double pi = acos(0.0) * 2.0;
const long double eps = 1e-10;
const int step[8][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}, {-1, 1}, {1, 1}, {1, -1}, {-1, -1}};

template <class T> inline T abs1(T a) {return a < 0 ? -a : a;}

#ifndef CPPELEVEN
template <class T> inline T max1(T a, T b) { return b < a ? a : b; }
template <class T> inline T max1(T a, T b, T c) { return max1(max1(a, b), c); }
template <class T> inline T max1(T a, T b, T c, T d) { return max1(max1(a, b, c), d); }
template <class T> inline T max1(T a, T b, T c, T d, T e) { return max1(max1(a, b, c, d), e); }
template <class T> inline T min1(T a, T b) { return a < b ? a : b; }
template <class T> inline T min1(T a, T b, T c) { return min1(min1(a, b), c); }
template <class T> inline T min1(T a, T b, T c, T d) { return min1(min1(a, b, c), d); }
template <class T> inline T min1(T a, T b, T c, T d, T e) { return min1(min1(a, b, c, d), e); }
#else
template <typename t, typename t1>
t min1(t a, t1 b) { return a < b ? a : b; }
template <typename t, typename... arg>
t min1(t a, arg... arr) { return min1(a, min1(arr...)); }
template <typename t, typename t1>
t max1(t a, t1 b) { return a > b ? a : b; }
template <typename t, typename... arg>
t max1(t a, arg... arr) { return max1(a, max1(arr...)); }
#endif

inline int jud(double a, double b){
  if(abs(a) < eps && abs(b) < eps) return 0;
  else if(abs1(a - b) / max(abs1(a), abs1(b)) < eps) return 0;
  if(a < b) return -1;
  return 1;
}
template <typename t> inline int jud(t a, t b){
  if(a < b) return -1;
  if(a == b) return 0;
  return 1;
}

// f_lb == 1代表返回相同的一串的左边界，f_small == 1代表返回如果没有寻找的值返回小的数
template <typename it, typename t1>
inline int find(t1 val, it a, int na, bool f_small = 1, bool f_lb = 1){
  if(na == 0) return 0;
  int be = 0, en = na - 1;
  if(*a <= *(a + na - 1)){
    if(f_lb == 0) while(be < en){
      int mid = (be + en + 1) / 2;
      if(jud(*(a + mid), val) != 1) be = mid;
      else en = mid - 1;
    }else while(be < en){
      int mid = (be + en) / 2;
      if(jud(*(a + mid), val) != -1) en = mid;
      else be = mid + 1;
    }
    if(f_small && jud(*(a + be), val) == 1) be--;
    if(!f_small && jud(*(a + be), val) == -1) be++;
  } else {
    if(f_lb) while(be < en){
      int mid = (be + en + 1) / 2;
      if(jud(*(a + mid), val) != -1) be = mid;
      else en = mid - 1;
    }else while(be < en){
      int mid = (be + en) / 2;
      if(jud(*(a + mid), val) != 1) en = mid;
      else be = mid + 1;
    }
    if(!f_small && jud(*(a + be), val) == -1) be--;
    if(f_small && jud(*(a + be), val) == 1) be++;
  }
  return be;
}

template <class T> inline T lowb(T num) {return num & (-num); }
#ifdef GPP
inline int bitnum(ui nValue) { return __builtin_popcount(nValue); }
inline int bitnum(int nValue) { return __builtin_popcount(nValue); }
inline int bitnum(ull nValue) { return __builtin_popcount(nValue) + __builtin_popcount(nValue >> 32); }
inline int bitnum(ll nValue) { return __builtin_popcount(nValue) + __builtin_popcount(nValue >> 32); }
inline int bitmaxl(ui a) { if(a == 0) return 0; return 32 - __builtin_clz(a); }
inline int bitmaxl(int a) { if(a == 0) return 0; return 32 - __builtin_clz(a); }
inline int bitmaxl(ull a) { int temp = a >> 32; if(temp) return 32 - __builtin_clz(temp) + 32; return bitmaxl(int(a)); }
inline int bitmaxl(ll a) { int temp = a >> 32; if(temp) return 32 - __builtin_clz(temp) + 32; return bitmaxl(int(a)); }
#else
#endif

long long pow(long long n, long long m, long long mod = 0){
  if(m < 0) return 0;
  long long ans = 1;
  long long k = n;
  while(m){
    if(m & 1) {
      ans *= k;
      if(mod) ans %= mod;
    }
    k *= k;
    if(mod) k %= mod;
    m >>= 1;
  }
  return ans;
}

#define  MOD 1000000007
template <class t1, class t2>
inline void add(t1 &a, t2 b, int mod = -1) {
  if(mod == -1) mod = MOD;
  a += b;
  while(a >= mod) a -= mod;
  while(a < 0) a += mod;
}
template <class t>
void output1(t arr) {
  for(int i = 0; i < (int)arr.size(); i++)
    cerr << arr[i] << ' ';
  cerr << endl;
}
template <class t>
void output2(t arr) {
  for(int i = 0; i < (int)arr.size(); i++)
    output1(arr[i]);
}

//....................密..........封..........线..........下..........禁..........止..........hack...............................................

const int mod = 998244353;
const int maxn = 100100;
int arr[maxn];
ll fac[maxn * 11], invfac[maxn * 11];
ll dp[maxn * 11];
int n;

ll c(int a, int b) {
  if (a < b) return 0;
  return fac[a] * invfac[a - b] % mod * invfac[b] % mod;
}

int main() {
  //............................不要再忘了检查maxn大小了！！！！BSBandme你个SB！！！！........................................
  ios_base::sync_with_stdio(0);
  #ifdef DEBUG //......................................................................................................
  freopen("input.txt", "r", stdin);
  #endif //...........................................................................................................

  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", arr + i);
  fac[0] = 1;
  for (int i = 1; i < maxn * 11; i++) {
    fac[i] = fac[i - 1] * i % mod;
  }
  invfac[maxn * 11 - 1] = pow(fac[maxn * 11 - 1], mod - 2, mod);
  for (int i = maxn * 11 - 2; i >= 0; i--) {
    invfac[i] = invfac[i + 1] * (i + 1) % mod;
  }
  sort(arr, arr + n);

  int zero_idx = n - 1;
  for (int i = 0; i < n; i++) {
    if (arr[i] < i) {
      zero_idx = i;
      while (zero_idx < n - 1 && arr[zero_idx + 1] == arr[zero_idx]) zero_idx++;
      break;
    }
  }

  dp[0] = 1;
  for (int i = 1; i <= maxn * 10; i++) {
    dp[i] = dp[i - 1] + c(n - 2 + i, n - 2);
    dp[i] %= mod;
  }

  ll ans = 0;
  for (int i = 0; i <= zero_idx; i++) {
    ll added = 0;
    ll sum = 0, need_cnt = i;
    for (int j = 0; j < i; j++) sum += (arr[i] - arr[j]) / n + 1;
    for (; added * n + arr[i] <= arr[zero_idx]; ) {
      ll left = arr[i] + added * n - sum - added;
      if (left < 0) break;
      ans += dp[left];
      if (added != 0 && left >= n - (need_cnt + 1)) {
         ans -= dp[left - (n - (need_cnt + 1))];
      }
      ans %= mod;
//      while (left >= 0) {
//        ans += c(n - 2 + left, left);
//        if (added != 0 && left >= n - (need_cnt + 1)) {
//          ans -= c(left + n - 2 - (n - (need_cnt + 1)), n - 2);
//        }
//        ans %= mod;
//        left--;
//      }

      added++;
      while (need_cnt + 1 < n &&
          arr[need_cnt + 1] < added * n + arr[i]) need_cnt++;
      sum += need_cnt;
    }
  }
  cout << (ans + mod) % mod << endl;

  return 0;
}


// =================================
//   author: memset0
//   date: 2019.07.25 19:31:17
//   website: https://memset0.cn/
// =================================
#include <bits/stdc++.h>
#define ll long long
#define rep(i, l, r) for (int i = (l), i##ed = (r); i <= i##ed; ++i)
#define for_each(i, a) for (size_t i = 0, i##ed = a.size(); i < i##ed; ++i)
namespace ringo {

template <class T> inline void read(T &x) {
	x = 0; char c = getchar(); bool f = 0;
	while (!isdigit(c)) f ^= c == '-', c = getchar();
	while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
	if (f) x = -x;
}
template <class T> inline void print(T x) {
	if (x < 0) putchar('-'), x = -x;
	if (x > 9) print(x / 10);
	putchar('0' + x % 10);
}
template <class T> inline void print(T x, char c) { print(x), putchar(c); }
template <class T> inline void print(T a, int l, int r, std::string s = "") {
	if (s != "") std::cout << s << ": ";
	for (int i = l; i <= r; i++) print(a[i], " \n"[i == r]);
}

const int N = 2e6 + 10, mod = 998244353;
int n, m, ans, cnt, used;
int a[N], b[N], mrk[N], inv[N], fac[N], ifac[N];

inline int dec(int a, int b) { a -= b; return a < 0 ? a + mod : a; }
inline int inc(int a, int b) { a += b; return a >= mod ? a - mod : a; }
inline int mul(int a, int b) { return (ll)a * b - (ll)a * b / mod * mod; }
inline int binom(int n, int m) { return n < m ? 0 : mul(fac[n], mul(ifac[m], ifac[n - m])); }

void init_fac(int n) {
	fac[0] = fac[1] = inv[0] = inv[1] = ifac[0] = ifac[1] = 1;
	for (int i = 2; i <= n; i++) fac[i] = mul(fac[i - 1], i);
	for (int i = 2; i <= n; i++) inv[i] = mul(mod - mod / i, inv[mod % i]);
	for (int i = 2; i <= n; i++) ifac[i] = mul(ifac[i - 1], inv[i]);
}

int calc(int s, int m) {
	return dec(binom(s + n - 1, n - 1), binom(s + m - 1, n - 1));
}

void main() {
	read(n);
	for (int i = 1; i <= n; i++) {
		read(a[i]);
		m += a[i], b[i] = a[i];
	}
	init_fac(n + m);
	ans = 1; // for zero operations
	for (int i = 1; i <= m; i++) {
		// for %i operations
		for (int i = 1; i <= n; i++) {
			--b[i];
			if (b[i] < 0) {
				++used, b[i] += n;
				if (!mrk[i]) ++cnt, mrk[i] = 1;
			}
		}
		if (used > i || cnt == n) break;
		ans = inc(ans, calc(i - used, cnt));
	}
	print(ans, '\n');
}

} signed main() {
#ifdef memset0
	freopen("1.in", "r", stdin);
#endif
	return ringo::main(), 0;
}


#include <bits/stdc++.h>

using ul = std::uint32_t;
using li = std::int32_t;
using ll = std::int64_t;
using ull = std::uint64_t;
using lf = double;
using vul = std::vector<ul>;
using vvul = std::vector<vul>;

const ul base = 998244353;

ul plus(ul a, ul b)
{
    return a + b < base ? a + b : a + b - base;
}

ul minus(ul a, ul b)
{
    return a < b ? a + base - b : a - b;
}

ul mul(ul a, ul b)
{
    return ull(a) * ull(b) % base;
}

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

ul inverse(ul a)
{
    li x, y;
    exgcd(a, base, x, y);
    return x < 0 ? li(base) + x : x;
}

ul devide(ul a, ul b)
{
    return mul(a, inverse(b));
}

ul k;
ul a[100001];
ul fact[1000001];
ul factinv[1000001];

ul binomial(ul a, ul b)
{
    return mul(fact[a], mul(factinv[a - b], factinv[b]));
}

int main()
{
    std::scanf("%u", &k);
    fact[0] = 1;
    for (ul i = 1; i <= 1000000; ++i) {
        fact[i] = mul(fact[i - 1], i);
    }
    factinv[1000000] = inverse(fact[1000000]);
    for (ul i = 1000000; i; --i) {
        factinv[i - 1] = mul(factinv[i], i);
    }
    ul critical = 0;
    for (ul i = 1; i <= k; ++i) {
        std::scanf("%u", &a[i]);
    }
    std::sort(a + 1, a + k + 1);
    for (ul i = 1; i <= k; ++i) {
        if (a[i] < i - 1) {
            critical = i - 1;
        }
    }
    if (critical) {
        ul ans = 0;
        for (ul j = 0; j < critical; ++j) {
            ul x = std::lower_bound(a + 1, a + k + 1, j) - a - 1;
            ans = plus(ans, binomial(j - x + k - 1, k - 1));
        }
        std::printf("%u\n", ans);
    } else {
        ul sum = 0;
        ul sum2 = 0;
        for (ul i = 1; i <= k; ++i) {
            sum += a[i];
            a[i] %= k;
            sum2 += a[i];
        }
        std::sort(a + 1, a + k + 1);
        ul ans = 0;
        for (ul t = 0; t != k; ++t) {
            ul x = k - (std::lower_bound(a + 1, a + k + 1, k - t) - a - 1);
            ans = plus(ans, binomial((sum - sum2) / k - t + x + k - 1, k - 1));
        }
        std::printf("%u\n", ans);
    }
    return 0;
}


#include <bits/stdc++.h>

using ul = std::uint32_t;
using li = std::int32_t;
using ll = std::int64_t;
using ull = std::uint64_t;
using lf = double;
using vul = std::vector<ul>;
using vvul = std::vector<vul>;

const ul base = 998244353;

ul plus(ul a, ul b)
{
    return a + b < base ? a + b : a + b - base;
}

ul minus(ul a, ul b)
{
    return a < b ? a + base - b : a - b;
}

ul mul(ul a, ul b)
{
    return ull(a) * ull(b) % base;
}

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

ul inverse(ul a)
{
    li x, y;
    exgcd(a, base, x, y);
    return x < 0 ? li(base) + x : x;
}

ul devide(ul a, ul b)
{
    return mul(a, inverse(b));
}

ul k;
ul a[100001];
ul fact[1000001];
ul factinv[1000001];

ul binomial(ul a, ul b)
{
    return mul(fact[a], mul(factinv[a - b], factinv[b]));
}

int main()
{
    std::scanf("%u", &k);
    fact[0] = 1;
    for (ul i = 1; i <= 1000000; ++i) {
        fact[i] = mul(fact[i - 1], i);
    }
    factinv[1000000] = inverse(fact[1000000]);
    for (ul i = 1000000; i; --i) {
        factinv[i - 1] = mul(factinv[i], i);
    }
    ul critical = 0;
    for (ul i = 1; i <= k; ++i) {
        std::scanf("%u", &a[i]);
    }
    std::sort(a + 1, a + k + 1);
    for (ul i = 1; i <= k; ++i) {
        if (a[i] < i - 1) {
            critical = i - 1;
            break;
        }
    }
    if (critical) {
        ul ans = 0;
        for (ul j = 0; j < critical; ++j) {
            ul x = std::lower_bound(a + 1, a + k + 1, j) - a - 1;
            ans = plus(ans, binomial(j - x + k - 1, k - 1));
        }
        std::printf("%u\n", ans);
    } else {
        ul sum = 0;
        ul sum2 = 0;
        for (ul i = 1; i <= k; ++i) {
            sum += a[i];
            a[i] %= k;
            sum2 += a[i];
        }
        std::sort(a + 1, a + k + 1);
        ul ans = 0;
        for (ul t = 0; t != k; ++t) {
            ul x = k - (std::lower_bound(a + 1, a + k + 1, k - t) - a - 1);
            ans = plus(ans, binomial((sum - sum2) / k - t + x + k - 1, k - 1));
        }
        std::printf("%u\n", ans);
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
mt19937 mrand(random_device{}());
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

const int N=1310000;
const int M=110000;

ll fac[N],fnv[N],inv[N],ans;
int n,a[M],cnt[M];

ll comb(int x,int y) {
	if (y<0||y>x) return 0;
	return fac[x]*fnv[y]%mod*fnv[x-y]%mod;
}

void gao(int step) {
	rep(i,0,n) if (a[i]<step) cnt[a[i]]++;
	rep(i,1,step) cnt[i]+=cnt[i-1];
	ll ans=1;
	rep(i,1,step) {
		ans+=comb(i-cnt[i-1]+n-1,n-1);
	}
	printf("%lld\n",ans%mod);
}

int main() {
	fac[0]=fnv[0]=inv[0]=inv[1]=1;
	rep(i,1,1200001) {
		fac[i]=fac[i-1]*i%mod;
		if (i>=2) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
		fnv[i]=fnv[i-1]*inv[i]%mod;
	}
	scanf("%d",&n);
	rep(i,0,n) scanf("%d",a+i);
	sort(a,a+n);
	// 1,1,1
	rep(i,0,n-1) if (a[i+1]<=i) {
		gao(i+1);
		return 0;
	}
	int ext=0;
	rep(i,0,n) {
		ext+=a[i]/n;
		cnt[a[i]%n]++;
	}
	rep(i,0,n) {
		ans+=comb(ext+n-1,n-1);
//		printf("%d %lld\n",ext,comb(ext+n-1,n-1));
		ext++; ext-=cnt[i];
	}
	printf("%lld\n",ans%mod);
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
mt19937 mrand(random_device{}());
const ll mod=998244353;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

const int N=1310000;
const int M=110000;

ll fac[N],fnv[N],inv[N],ans;
int n,a[M],cnt[M];

ll comb(int x,int y) {
	if (y<0||y>x) return 0;
	return fac[x]*fnv[y]%mod*fnv[x-y]%mod;
}

void gao(int step) {
	rep(i,0,n) if (a[i]<step) cnt[a[i]]++;
	rep(i,1,step) cnt[i]+=cnt[i-1];
	ll ans=1;
	rep(i,1,step) {
		ans+=comb(i-cnt[i-1]+n-1,n-1);
	}
	printf("%lld\n",ans%mod);
}

int main() {
	fac[0]=fnv[0]=inv[0]=inv[1]=1;
	rep(i,1,1200001) {
		fac[i]=fac[i-1]*i%mod;
		if (i>=2) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
		fnv[i]=fnv[i-1]*inv[i]%mod;
	}
	scanf("%d",&n);
	rep(i,0,n) scanf("%d",a+i);
	sort(a,a+n);
	// 1,1,1
	rep(i,0,n-1) if (a[i+1]<=i) {
		gao(i+1);
		return 0;
	}
	int ext=0;
	rep(i,0,n) {
		ext+=a[i]/n;
		cnt[a[i]%n]++;
	}
	rep(i,0,n) {
		ans+=comb(ext+n-1,n-1);
//		printf("%d %lld\n",ext,comb(ext+n-1,n-1));
		ext++; ext-=cnt[i];
	}
	printf("%lld\n",ans%mod);
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
mt19937 mrand(random_device{}());
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

const int N=1310000;
const int M=110000;

ll fac[N],fnv[N],inv[N],ans;
int n,a[M],cnt[M];

ll comb(int x,int y) {
	if (y<0||y>x) return 0;
	return fac[x]*fnv[y]%mod*fnv[x-y]%mod;
}

void gao(int step) {
	rep(i,0,n) if (a[i]<step) cnt[a[i]]+=step;
	rep(i,1,step) cnt[i]+=cnt[i-1];
	ll ans=1;
	rep(i,1,step) {
		ans+=comb(i-cnt[i-1]+n-1,n-1);
	}
	printf("%lld\n",ans%mod);
}

int main() {
	fac[0]=fnv[0]=inv[0]=inv[1]=1;
	rep(i,1,1200001) {
		fac[i]=fac[i-1]*i%mod;
		if (i>=2) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
		fnv[i]=fnv[i-1]*inv[i]%mod;
	}
	scanf("%d",&n);
	rep(i,0,n) scanf("%d",a+i);
	sort(a,a+n);
	// 1,1,1
	rep(i,0,n-1) if (a[i+1]<=i) {
		gao(i+1);
		return 0;
	}
	int ext=0;
	rep(i,0,n) {
		ext+=a[i]/n;
		cnt[a[i]%n]++;
	}
	rep(i,0,n) {
		ans+=comb(ext+n-1,n-1);
//		printf("%d %lld\n",ext,comb(ext+n-1,n-1));
		ext++; ext-=cnt[i];
	}
	printf("%lld\n",ans%mod);
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

#define F first
#define S second

const int MOD = 998244353;
const int MAXN = 1e6 + 2e5;
const int MAXK = 1e5 + 10;

int k, c[MAXK];
int ss[MAXN], tt[MAXN];

int pw(int a, int b){
	int ret = 1;
	while (b){
		if (b & 1)
			ret = 1ll*ret*a%MOD;
		b >>= 1;
		a = 1ll*a*a%MOD;
	}
	return ret;
}

int choose(int a, int b){
	if (a < b) return 0;
	return 1ll*ss[a]*tt[b]%MOD*tt[a-b]%MOD;
}

int cc[MAXN];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ss[0] = 1;
	for (int i = 1; i < MAXN; i++) ss[i] = 1ll*ss[i-1]*i%MOD;
	tt[0] = 1;
	for (int i = 1; i < MAXN; i++) tt[i] = 1ll*tt[i-1]*pw(i, MOD-2)%MOD;

	cin >> k;
	for (int i = 0; i < k; i++) cin >> c[i];
	sort(c, c + k);

	int ans = 0;
	for (int i = 0; i < k; i++){
		if (c[i] < i) break;
		int cur = i+1, rem = 0;
		for (int j = i; j <= c[i]; j++){
			while (cur <= j && rem){
				if (cc[cur]==0)
					cur++;
				else {
					rem--;
					cc[cur]--;
					if (cur + k <= c[i])
						cc[cur+k]++;
				}
			}

			if (cur == j+1){
				ans += choose(rem+(k-2), k-2);
				if (ans >= MOD) ans -= MOD;
			}
			rem++;
		}
		if (i <= c[i]) {
			for (int j = 0; j <= c[i]; j++)
				cc[j] = 0;
			for (int j = 0; j < i; j++)
				if (c[j]+2 <= c[i])
					cc[c[j]+2]++;
		}

		c[i] += k-1;
		cc[c[i]+2]++;
	}
	cout << ans << "\n";
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long INT;

const int mod = 998244353, NN = 3000020;

int inv(int u) {return u<2?u:(INT)mod/u*(mod-inv(mod%u))%mod;}

int fac[NN], rev[NN], s[NN], n, a[NN];

int C(int n, int k) {return (INT)fac[n]*rev[k]%mod*rev[n-k]%mod;}

int main() {
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif

	for (int i=fac[0]=1; i<NN; i++) fac[i]=(INT)fac[i-1]*i%mod;
	rev[NN-1]=inv(fac[NN-1]);
	for (int i=NN-2; i>=0; i--) rev[i]=(INT)rev[i+1]*(i+1)%mod;
	cin>>n;
	for (int i=1; i<=n; i++) scanf("%d", a+i);
	sort(a+1, a+n+1);
	for (int i=1; i<n; i++) if (a[i+1]<i) {
		int ans = 1;
		for (int x=1, k=1; x<i; x++) {
			while (k<=n && a[k]<x) k++;
			ans += C(x-k+n, n-1);
			if (ans>=mod) ans-=mod;
		}
		cout << ans << endl;
		return 0;
	}

	int sum = 0;
	for (int i=1; i<=n; i++) sum+=a[i]-a[i]%n, a[i]%=n;
	sort(a+1, a+n+1);
	int ans = 0; sum/=n;
	for (int t=0, k=n; t<n; t++) {
		while (k && a[k]+t>=n) k--;
		ans += C(sum+n-k+n-1-t, n-1);
		if (ans>=mod) ans-=mod;
	}

	cout << ans << endl;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MOD = 998244353;

template <typename T>
struct modular {
    constexpr modular() : val(0){}
    constexpr modular(const modular<T>& _m) : val(_m.val) {}
    template <typename U> constexpr modular(const U& _r = U()) {
        val = -MOD <= _r && _r < MOD ? _r: _r % MOD;
        if (val < 0) { val += MOD; } }
    const T operator()() { return val; }
    template <typename U> explicit operator U() const { return static_cast<U>(val); }
    modular<T>& operator+=(const modular<T>& _m) { if ((val += _m.val) >= MOD) { val -= MOD; } return *this; }
    modular<T>& operator-=(const modular<T>& _m) { if ((val -= _m.val) < 0) { val += MOD; } return *this; }
    modular<T>& operator*=(const modular<T>& _m) { val = modular<T>(static_cast<int64_t>(val) * static_cast<int64_t>(_m.val)).val; return *this; }
    modular<T>& operator/=(const modular<T>& _m) {
        T a = _m.val, b = MOD, u = 0, v = 1;
        while (a != 0) {
            T q = b / a;
            b -= q * a; swap(a, b);
            u -= q * v; swap(u, v);
        } return *this *= u; }
    modular<T>& operator =(const modular<T>& _m) { val = _m.val; return *this; }
    template <typename U> modular<T>& operator+=(const U& _r) { return *this += modular<T>(_r); }
    template <typename U> modular<T>& operator-=(const U& _r) { return *this -= modular<T>(_r); }
    template <typename U> modular<T>& operator*=(const U& _r) { return *this *= modular<T>(_r); }
    template <typename U> modular<T>& operator/=(const U& _r) { return *this /= modular<T>(_r); }
    template <typename U> modular<T>& operator =(const U& _r) { val = modular<T>(_r).val; return *this; }
    modular<T> operator-() { return modular<T>(-val); }
    template <typename U> friend bool operator==(const modular<U>&, const modular<U>&);
    friend std::istream& operator>>(std::istream& os, modular<T>& _m) { os >> _m.val; _m *= 1; return os; }
    friend std::ostream& operator<<(std::ostream& os, const modular<T>& _m) { return os << _m.val; }
    template <typename U>
    modular<T> exp(U e) {
        modular<T> res = 1;
        modular<T> b = val;
        if (e < 0) { b = 1/b; e *= -1; }
        for (; e; e >>= 1) {
            if (e & 1) { res *= b; }
            b *= b;
        } return res; }
private:
    T val;
};
template <typename T> inline modular<T> operator+(const modular<T>& _lhs, const modular<T>& _rhs) { return modular<T>(_lhs) += _rhs; }
template <typename T, typename U> inline modular<T> operator+(const modular<T>& _lhs, const U& _rhs) { return modular<T>(_lhs) += _rhs; }
template <typename T, typename U> inline modular<T> operator+(const U& _lhs, const modular<T>& _rhs) { return modular<T>(_lhs) += _rhs; }
template <typename T> inline modular<T> operator-(const modular<T>& _lhs, const modular<T>& _rhs) { return modular<T>(_lhs) -= _rhs; }
template <typename T, typename U> inline modular<T> operator-(const modular<T>& _lhs, const U& _rhs) { return modular<T>(_lhs) -= _rhs; }
template <typename T, typename U> inline modular<T> operator-(const U& _lhs, const modular<T>& _rhs) { return modular<T>(_lhs) -= _rhs; }
template <typename T> inline modular<T> operator*(const modular<T>& _lhs, const modular<T>& _rhs) { return modular<T>(_lhs) *= _rhs; }
template <typename T, typename U> inline modular<T> operator*(const modular<T>& _lhs, const U& _rhs) { return modular<T>(_lhs) *= _rhs; }
template <typename T, typename U> inline modular<T> operator*(const U& _lhs, const modular<T>& _rhs) { return modular<T>(_lhs) *= _rhs; }
template <typename T> inline modular<T> operator/(const modular<T>& _lhs, const modular<T>& _rhs) { return modular<T>(_lhs) /= _rhs; }
template <typename T, typename U> inline modular<T> operator/(const modular<T>& _lhs, const U& _rhs) { return modular<T>(_lhs) /= _rhs; }
template <typename T, typename U> inline modular<T> operator/(const U& _lhs, const modular<T>& _rhs) { return modular<T>(_lhs) /= _rhs; }
template <typename T> inline bool operator==(const modular<T>& _lhs, const modular<T>& _rhs) { return _lhs.val == _rhs.val; }
template <typename T, typename U> inline bool operator==(const modular<T>& _lhs, const U& _rhs) { return _lhs == modular<T>(_rhs); }
template <typename T, typename U> inline bool operator==(const U& _lhs, const modular<T>& _rhs) { return modular<T>(_lhs) == _rhs; }
template <typename T> inline bool operator!=(const modular<T>& _lhs, const modular<T>& _rhs) { return !(_lhs == _rhs); }
template <typename T, typename U> inline bool operator!=(const modular<T>& _lhs, const U& _rhs) { return !(_lhs == _rhs); }
template <typename T, typename U> inline bool operator!=(const U& _lhs, const modular<T>& _rhs) { return !(_lhs == _rhs); }
typedef modular<int> mint;

struct Comb {
    int n;
    vector<mint> fac, ifac, inv;

    Comb(int _n=1) {
        resize(2);
        fac[0] = fac[1] = ifac[0] = ifac[1] = inv[1] = 1;
        n = 1; grow(_n);
    }

    void resize(int _s) {
        fac.resize(_s); ifac.resize(_s); inv.resize(_s);
    }
    bool grow(int _n) {
        if (_n <= n) return false;
        resize(_n+1);
        for (int i = n+1; i <= _n; i++) {
            fac[i] = fac[i-1] * i;
            inv[i] = (-MOD/i) * inv[MOD%i];
            ifac[i] = ifac[i-1] * inv[i];
        }
        n = _n;
        return true;
    }
    // choose
    mint c(int N, int K) {
        if (N < K || K < 0) return 0;
        if (N > n) grow(N);
        return fac[N] * ifac[N-K] * ifac[K];
    }
    // sum x = S, x > 0
    mint p(int S, int K) {
        return c(S-1, K-1);
    }
    // sum x = S, x >= 0
    mint z(int S, int K) {
        return p(S+K, K);
    }
};

void solve() {
    int n; cin >> n;
    vector<int> a(n);
    for (auto& x: a) {
        cin >> x;
    }
    sort(a.begin(), a.end());
    Comb c(n);

    int critical = -1;
    for (int i = 0; i < n; i++) {
        if (a[i] < i) {
            critical = i;
            break;
        }
    }

    mint res;
    if (critical != -1) {
        res = 1;
        for (int i = 1; i < critical; i++) {
            int p = lower_bound(a.begin(), a.end(), i) - a.begin();
            res += c.z(i-p, n);
        }
    } else {
        int S = 0;
        int M = 0;
        vector<int> cnt(n, 0);
        for (auto& x: a) {
            S += x;
            cnt[x %= n]++;
            M += x;
        }
        for (int i = 1; i < n; i++) {
            cnt[i] += cnt[i-1];
        }
        res = 0;
        for (int i = 0; i < n; i++) {
            int t = S - (M + 1ll*i*n - 1ll*n*(n - cnt[n-i-1]));
            assert(t%n == 0);
            t /= n;
            res += c.z(t, n);
        }
    }
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


#include <iostream>
using namespace std;
const int N = 220;
int a[N], b[N];
int ans = 3e9, n, m;
bool vis[N][600];
void dfs(int x, int y)
{
    if(vis[x][y])
        return;
    vis[x][y] = true;
    if(x > n)
    {
        ans = min(ans, y);
        return;
    }
    for(int i = 1; i <= m; i++)
    {
        dfs(x + 1, y | (a[x] & b[i]));
    }
}
int main()
{
    cin >> n >> m;
    for(int i = 1; i <= n; i++)
        cin >> a[i];
    for(int i = 1; i <= m; i++)
        cin >> b[i];
    dfs(1, 0);
    cout << ans << endl;
    return 0;
}


/*
               JAI SHREE RAM    */

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

#define ff              first
#define ss              second
#define pb              push_back
#define int             long long
#define mp              make_pair
#define pr              pair<long long,long long>
#define vr              vector<long long>
#define mod1            1000000007
#define mod2            998244353
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define ll              long long
#define ld	            long double
#define w(x)            int x; cin>>x; while(x--)
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

long long maxSubArray(long long a[], int sze)
{
   long long max_so_far = 0, max_ending = 0;
   for (int i = 0; i < sze; i++)
   {
       max_ending = max_ending + a[i];
       if (max_ending < 0)
           max_ending = 0;
       else if (max_so_far < max_ending)
           max_so_far = max_ending;
   }
   return max_so_far;
}

void solve()
{
  int n,m;
  cin>>n>>m;
  int a[n];
  for(int i=0;i<n;i++)
  cin>>a[i];

  int b[m];
  for(int i=0;i<m;i++)
  cin>>b[i];

  for(int ans=0;ans<=512;ans++)
  {
      int f=1;
      for(int j=0;j<n;j++)
      {
          int fl=0;
          for(int k=0;k<m;k++)
          {
              if((ans|(a[j]&b[k]))==ans)
              {
                  fl=1;
                  break;
              }
          }
          if(fl==0)
          {
             f=0;
             break;
          }
      }
      if(f==1)
      {
          cout<<ans<<"\n";
          break;
      }
  }

}

int32_t main()
{

      int test;
      test=1;
      //cin>>test;
      while(test--)
      {
          solve();
      }

    return 0;
	}


/*
               JAI SHREE RAM    */

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

#define ff              first
#define ss              second
#define pb              push_back
#define int             long long
#define mp              make_pair
#define pr              pair<long long,long long>
#define vr              vector<long long>
#define mod1            1000000007
#define mod2            998244353
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define ll              long long
#define ld	            long double
#define w(x)            int x; cin>>x; while(x--)
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

long long maxSubArray(long long a[], int sze)
{
   long long max_so_far = 0, max_ending = 0;
   for (int i = 0; i < sze; i++)
   {
       max_ending = max_ending + a[i];
       if (max_ending < 0)
           max_ending = 0;
       else if (max_so_far < max_ending)
           max_so_far = max_ending;
   }
   return max_so_far;
}

void solve()
{
  int n,m;
  cin>>n>>m;
  int a[n];
  for(int i=0;i<n;i++)
  cin>>a[i];

  int b[m];
  for(int i=0;i<m;i++)
  cin>>b[i];

  for(int ans=0;ans<=1024;ans++)
  {
      int f=1;
      for(int j=0;j<n;j++)
      {
          int fl=0;
          for(int k=0;k<m;k++)
          {
              if((ans|(a[j]&b[k]))==ans)
              {
                  fl=1;
                  break;
              }
          }
          if(fl==0)
          {
             f=0;
             break;
          }
      }
      if(f==1)
      {
          cout<<ans<<"\n";
          break;
      }
  }

}

int32_t main()
{

      int test;
      test=1;
      //cin>>test;
      while(test--)
      {
          solve();
      }

    return 0;
	}


/*
               JAI SHREE RAM    */

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

#define ff              first
#define ss              second
#define pb              push_back
#define int             long long
#define mp              make_pair
#define pr              pair<long long,long long>
#define vr              vector<long long>
#define mod1            1000000007
#define mod2            998244353
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define ll              long long
#define ld	            long double
#define w(x)            int x; cin>>x; while(x--)
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

long long maxSubArray(long long a[], int sze)
{
   long long max_so_far = 0, max_ending = 0;
   for (int i = 0; i < sze; i++)
   {
       max_ending = max_ending + a[i];
       if (max_ending < 0)
           max_ending = 0;
       else if (max_so_far < max_ending)
           max_so_far = max_ending;
   }
   return max_so_far;
}

void solve()
{
  int n,m;
  cin>>n>>m;
  int a[n];
  for(int i=0;i<n;i++)
  cin>>a[i];

  int b[m];
  for(int i=0;i<m;i++)
  cin>>b[i];

  for(int ans=0;ans<=100;ans++)
  {
      int f=1;
      for(int j=0;j<n;j++)
      {
          int fl=0;
          for(int k=0;k<m;k++)
          {
              if((ans|(a[j]&b[k]))==ans)
              {
                  fl=1;
                  break;
              }
          }
          if(fl==0)
          {
             f=0;
             break;
          }
      }
      if(f==1)
      {
          cout<<ans<<"\n";
          break;
      }
  }

}

int32_t main()
{

      int test;
      test=1;
      //cin>>test;
      while(test--)
      {
          solve();
      }

    return 0;
	}


/*
               JAI SHREE RAM    */

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

#define ff              first
#define ss              second
#define pb              push_back
#define int             long long
#define mp              make_pair
#define pr              pair<long long,long long>
#define vr              vector<long long>
#define mod1            1000000007
#define mod2            998244353
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define ll              long long
#define ld	            long double
#define w(x)            int x; cin>>x; while(x--)
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

long long maxSubArray(long long a[], int sze)
{
   long long max_so_far = 0, max_ending = 0;
   for (int i = 0; i < sze; i++)
   {
       max_ending = max_ending + a[i];
       if (max_ending < 0)
           max_ending = 0;
       else if (max_so_far < max_ending)
           max_so_far = max_ending;
   }
   return max_so_far;
}

void solve()
{
  int n,m;
  cin>>n>>m;
  int a[n];
  for(int i=0;i<n;i++)
  cin>>a[i];

  int b[m];
  for(int i=0;i<m;i++)
  cin>>b[i];

  int dp[n][m];

  for(int i=0;i<n;i++)
  {
      for(int j=0;j<m;j++)
      {
          dp[i][j]=a[i] & b[j];
      }
  }

  int ans[m];
  for(int i=0;i<m;i++)
  ans[i]=dp[0][i];

  for(int i=0;i<m;i++)
  {
      for(int j=1;j<n;j++)
      {
          int mi=1e18;
          for(int k=0;k<m;k++)
          {
              mi=min(mi,ans[i] | dp[j][k]);
          }
          ans[i]=mi;
      }
  }
  sort(ans,ans+m);

  cout<<ans[0]<<"\n";
}

int32_t main()
{

      int test;
      test=1;
      //cin>>test;
      while(test--)
      {
          solve();
      }

    return 0;
	}


/*
               JAI SHREE RAM    */

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

#define ff              first
#define ss              second
#define pb              push_back
#define int             long long
#define mp              make_pair
#define pr              pair<long long,long long>
#define vr              vector<long long>
#define mod1            1000000007
#define mod2            998244353
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define ll              long long
#define ld	            long double
#define w(x)            int x; cin>>x; while(x--)
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

long long maxSubArray(long long a[], int sze)
{
   long long max_so_far = 0, max_ending = 0;
   for (int i = 0; i < sze; i++)
   {
       max_ending = max_ending + a[i];
       if (max_ending < 0)
           max_ending = 0;
       else if (max_so_far < max_ending)
           max_so_far = max_ending;
   }
   return max_so_far;
}

void solve()
{
  int n,m;
  cin>>n>>m;
  int a[n];
  for(int i=0;i<n;i++)
  cin>>a[i];

  int b[m];
  for(int i=0;i<m;i++)
  cin>>b[i];

  for(int ans=0;ans<=512;ans+=1)
  {
      int f=1;
      for(int j=0;j<n;j++)
      {
          int fl=0;
          for(int k=0;k<m;k++)
          {
              if((ans|(a[j]&b[k]))==ans)
              {
                  fl=1;
                  break;
              }
          }
          if(fl==0)
          {
             f=0;
             break;
          }
      }
      if(f==1)
      {
          cout<<ans<<"\n";
          break;
      }
  }

}

int32_t main()
{

      int test;
      test=1;
      //cin>>test;
      while(test--)
      {
          solve();
      }

    return 0;
	}


#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <cmath>
#include <map>
#include <string.h>
#include <algorithm>
#include <bits/stdc++.h>
#include <vector>

using namespace std;
#define set_precision cout << fixed << setprecision(10)
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repb(i, a, b) for (int i = a; i >= b; i--)
#define repit(arr) for (auto it = arr.begin(); it != arr.end(); it++)
#define vi vector<int>
#define vl vector<long long int>
#define Vi vector<vector<int>>
#define vpi vector<pair<int,int>>
#define seti set<int>
#define setl set<ll>
#define dseti set<int, greater<int>>
#define dsetl set<ll, greater<ll>>
#define mseti multiset<int>
#define msetl multiset<ll>
#define dmseti multiset<int, greater<int>>
#define dmsetl multiset<ll, greater<ll>>
#define sortA(arr) sort(arr.begin(), arr.end())
#define dsortA(arr) sort(arr.begin(), arr.end(), greater<int>())
#define ssort(arr) stable_sort(arr.begin(), arr.end())
#define nth(v,n) nth_element(v.begin,v.begin+n-1,v.end())
#define dnth(v,n) nth_element(v.begin,v.begin+n-1,v.end(), greater<int>())
#define init(a)  memset((a),0,sizeof(a))
#define pi pair<int,int>
#define pb push_back
#define pl pair<ll,ll>
#define ll long long
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mod 1000000007

/*struct comp {
  bool operator() (const int& lhs, const int& rhs) const
  {return lhs<rhs;}
};*/

ll cel(ll a,int b){return((a-1)/b+1);}
ll gcd(ll a, ll b){
    if (a < b)swap(a, b);
    return (b == 0)? a: gcd(b, a % b);
}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}

int g(int y,int i){
    return (1<<(i-1))&y;
}
int main()
{
    FIO;
    ll n,t,x,m,y,r;
    cin>>n>>m;
    vi chk(512,0),ans(10,1),u;vi A[10],B[10];
    rep(i,0,n){
        cin>>x;
        if(chk[x])continue;
        y=1;r=x;
        while(x){
            if(x%2)A[y].pb(r);
            y++;x/=2;
        }
        chk[r]=1;
    }
    rep(i,0,m){
        cin>>x;
        y=1;u.pb(x);
        r=x;
        while(x){
            if(x%2)B[y].pb(r);
            y++;x/=2;
        }
    }
    int C[512][m];rep(i,0,512){rep(j,0,m)C[i][j]=1;}
    int se[m][10];

    rep(i,0,m){rep(j,1,10){se[i][j]=(g(u[i],j));}}
    //cout<<se[0][1]<<" "<<se[0][2];
    repb(i,9,1){
        if(A[i].empty()){ans[i]=0;}
        else{
            //if(B[i].empty()){ans[i]=0;}
            //{
                int k=1;
                for(int t:A[i]){
                    k=1;
                    rep(j,0,m){
                        if((se[j][i]==0)&&(C[t][j])){k=0;break;}
                    }
                    if(k){break;}
                }
                if(k)ans[i]=1;
                else{
                   for(int t:A[i]){
                    rep(j,0,m){
                        if(se[j][i])C[t][j]=0;
                    }
                    }
                    ans[i]=0;
                }
            //}
        }
    }
    int q=0,z=1;
    rep(i,1,9){
        if(ans[i]){q+=z;}
        z*=2;
    }
    cout<<q;
    return 0;
}