#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define bitCount __builtin_popcount
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
typedef set<int>::iterator sit;
typedef set<char>::iterator sct;
typedef map<int, int>::iterator mit;
typedef vector<int>::iterator vit;
typedef multiset<int>::iterator msit;
const int maxn = 1e5+5;
const ll mod = 1e9+7;
const int alphabet = 26;
const int inf = INT_MAX;
const ll lint = 1e18+9;
#define forn(i, n) for(i = 0; i < (ll)n; i++)
#define for1(i, n) for(i = 1; i <= (ll)n; i++)
#define forv(i, v) for(i = 0; i < v.size(); i++)
#define forab(i, a, b) for(i = a; i <= (ll)b; i++)
#define Sort(v) sort(v.begin(), v.end())
inline ll cnm(char ch){	return (ch-'0'); }
inline ll cap(char ch){	return (ch-'a'); }
inline void instr(string& s, ll& n){ cin>>s;	n = s.length(); }
inline void instr(string& s){ cin>>s; }

ll a[maxn];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll i, j, k, m, n;
	cin>>n;
	for(i = 0; i < n; i++) cin>>a[i];
	sort(a, a+n);
	if(a[n-1] == 1) a[n-1] = 2;
	else a[n-1] = 2;
	sort(a, a+n);
	for(i = 0; i < n; i++) cout<<a[i]<<" ";
    return 0;
}


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

int main()
{
    ll n;
    cin>>n;
    ll a[n];
    ll i;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    cout<<1<<" ";
    for(i=0;i<n-1;i++)
    {
        cout<<a[i]<<" ";
    }
}


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

int main()
{
    ll n;
    cin>>n;
    ll a[n];
    ll i;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    ll sum=0;
    for(i=0;i<n;i++)
    {
        sum+=a[i];
    }
    if(sum==n)
    {
        for(i=0;i<n-1;i++)
        {
            cout<<1<<" ";
        }
        cout<<2;
        return 0;
    }
    sort(a,a+n);
    cout<<1<<" ";
    for(i=0;i<n-1;i++)
    {
        cout<<a[i]<<" ";
    }
}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define f(i,a,b) for(i=a;i<b;i++)
#define YES cout<<"YES\n"
#define NO cout<<"NO\n"
using namespace std;

int main() {

ll n,i,j;
cin>>n;

ll a[n];

f(i,0,n)
{cin>>a[i];}
sort(a,a+n);
j=1;
for(i=n;i-->0;j++)
{
    if(a[i]!=j)
      { a[i]=j;
          break;
      }
}
sort(a,a+n);
f(i,0,n)cout<<a[i]<<' ';

}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define f(i,a,b) for(i=a;i<b;i++)
#define YES cout<<"YES\n"
#define NO cout<<"NO\n"
using namespace std;

int main() {

ll n,i,j;
cin>>n;

ll a[n];
map<ll,int>m;
f(i,0,n)
{cin>>a[i];m[a[i]]++;}
sort(a,a+n);
j=1;
for(i=n;i--;j++)
{
    if(a[i]!=j)
      { a[i]=j;
          break;
      }
}
sort(a,a+n);
f(i,0,n)cout<<a[i]<<' ';

}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define f(i,a,b) for(i=a;i<b;i++)
#define YES cout<<"YES\n"
#define NO cout<<"NO\n"
using namespace std;

int main() {

ll n,i,j;
cin>>n;

ll a[n];

f(i,0,n)
{cin>>a[i];}

if(n==1)
{
    if(a[0]==1)cout<<2;
    else cout<<1;return 0;
}
sort(a,a+n);
j=1;
for(i=n;i-->0;j++)
{
    if(a[i]!=j)
      { a[i]=j;
          break;
      }
}
sort(a,a+n);
f(i,0,n)cout<<a[i]<<' ';

}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define f(i,a,b) for(i=a;i<b;i++)
#define YES cout<<"YES\n"
#define NO cout<<"NO\n"
using namespace std;

int main() {

ll n,i,j;
cin>>n;

ll a[n];

if(n==1)
{
    if(a[0]==1)cout<<2;
    else cout<<1;return 0;
}
f(i,0,n)
{cin>>a[i];}
sort(a,a+n);
j=1;
for(i=n;i-->0;j++)
{
    if(a[i]!=j)
      { a[i]=j;
          break;
      }
}
sort(a,a+n);
f(i,0,n)cout<<a[i]<<' ';

}


#include <iostream>
#include <stdio.h>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <iomanip>
#include <complex>

#define ll long long
#define ld long double
#define debug(x) cerr << (#x) << " " << (x) <<" "<< endl
#define ull unsigned long long
#define endl "\n"
#define MohamedMotaz ios::sync_with_stdio(0); cin.tie(0); ios_base::sync_with_stdio(0);
#define f(a, b, c) for(ll a = b; a < c; a++)
#define fr(a, b, c) for(int a = b; a >= c; a--)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define vll vector<ll>
#define vld vector<ld>
#define vii vector<int>
#define vs vector<string>
#define pii pair<int, int>
#define pll pair<ll,ll>
#define pld pair<ld, ld>
#define vpii vector<pii>
#define vpll vector<pll>
#define vpld vector<pld>
#define vc vector<char>
#define vs vector<string>
#define vp vector<point>
#define vb vector<bool>
#define mll map<ll,ll>
#define mii map<int, int>
#define mllv map<ll, vll>
#define mcll map<char, ll>
#define mci map<char, int>
#define msll map<string, ll>
#define mss map<string, string>
#define mcs map<char, string>
#define sll set<ll>
#define pi acos(-1)
#define point complex<ld>
using namespace std;

int dirX[] = { 0, -1, 0, 1, -1, 1, -1, 1 };
int dirY[] = { -1, 0, 1, 0, 1, -1, -1, 1 };

ll gcd(ll a, ll b) {
    if (!b)return a;
    return gcd(b, a % b);
}
ll lcm (ll a, ll b) {
    return a * b / gcd(a, b);
}

const ll MOD = 998244353;
const ll mod = 1e9 + 7;
const ll N = 1e3 + 7;
const ll llinf = INT64_MAX;
const int intinf = INT32_MAX;

int n;

int main() {
    MohamedMotaz
    cin >> n;
    vii v(n);
    f(i, 0, n) cin >> v[i];
    sort(all(v));
    if (v[n - 1] == 1) v[n - 1] = 2;
    else v[n - 1] = 1;
    sort(all(v));
    for (auto e: v) cout << e << " ";

}


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

const int N=100005;

int vis[N];
int cnt[N];
vector<int> v[N];

int main()
{
	int n;
	cin>>n;
	for(int i=1;i<n;i++)
	{
		int x,y;
		cin>>x>>y;
		v[x].push_back(y);
		v[y].push_back(x);
		cnt[x]++,cnt[y]++;
	}

	memset(vis,0,sizeof(vis));
	for(int i=1;i<=n;i++)
	{
		if(cnt[i]>1)
			continue;

		vis[i]=-1;
		for(int j=0;j<v[i].size();j++)
		{
			int next=v[i][j];
			if(cnt[next]!=1)
				vis[next]++;
		}
	}

	bool flag=true;
	for(int i=1;i<=n;i++)
		if(vis[i]==1 || vis[i]==0)
			flag=false;
	if(n==3)
		flag=false;

	cout<<(flag?"YES":"NO");
	return 0;
}


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

const int N=100005;

int cnt[N];

int main()
{
	int n;
	cin>>n;
	for(int i=1;i<n;i++)
	{
		int x,y;
		cin>>x>>y;
		cnt[x]++,cnt[y]++;
	}

	bool flag=true;
	for(int i=1;i<=n;i++)
		if(cnt[i]==2)
			flag=false;

	cout<<(flag?"YES":"NO");
	return 0;
}


//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<bits/stdc++.h>
using namespace std;
auto ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); };
const int MAXN = 1e5+7;
int n;
vector<int> G[MAXN];
bool dfs(int u, int fa){
    if(G[u].size()==1) return true;
    int cnt = 0;
    for(int v : G[u]){
        if(v==fa) continue;
        if(!dfs(v,u)) return false;
        cnt++;
    }
    if(cnt>2||(cnt==2&&fa)) return true;
    return false;
}
int main(){
    ____();
    cin >> n;
    for(int i = 1; i < n; i++){
        int u,v;
        cin >>u >> v;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    for(int i = 1; i <= n; i++){
        if(G[i].size()!=1){
            if(dfs(i,0)) cout << "YES" << endl;
            else cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;          //n==2
    return 0;
}


//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<bits/stdc++.h>
using namespace std;
auto ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); };
const int MAXN = 1e5+7;
int n;
vector<int> G[MAXN];
int leave;
bool dfs(int u, int fa){
    if(G[u].size()==1) return true;
    int cnt = 0;
    for(int v : G[u]){
        if(v==fa) continue;
        if(!dfs(v,u)) return false;
        cnt++;
    }
    if(cnt>=2) return true;
    return false;
}
int main(){
    ____();
    cin >> n;
    for(int i = 1; i < n; i++){
        int u,v;
        cin >>u >> v;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    for(int i = 1; i <= n; i++) if(G[i].size()==1) leave++;

    if(n==2){
        cout << "YES" << endl;
        return 0;
    }
    if(leave<=2){
        cout << "NO" << endl;
        return 0;
    }
    for(int i = 1; i <= n; i++){
        if(G[i].size()!=1){
            if(dfs(i,0)) cout << "YES" << endl;
            else cout << "NO" << endl;
            return 0;
        }
    }
    return 0;
}


//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<bits/stdc++.h>
using namespace std;
auto ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); };
const int MAXN = 1e5+7;
int n;
vector<int> G[MAXN];
int leave;
bool dfs(int u, int fa){
    if(G[u].size()==1) return true;
    int cnt = 0;
    for(int v : G[u]){
        if(v==fa) continue;
        if(!dfs(v,u)) return false;
        cnt++;
    }
    if(cnt>=2) return true;
    return false;
}
int main(){
    ____();
    cin >> n;
    for(int i = 1; i < n; i++){
        int u,v;
        cin >>u >> v;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    for(int i = 1; i <= n; i++) if(G[i].size()==1) leave++;
    if(leave<=2){
        cout << "NO" << endl;
        return 0;
    }
    if(n==2){
        cout << "YES" << endl;
        return 0;
    }
    for(int i = 1; i <= n; i++){
        if(G[i].size()!=1){
            if(dfs(i,0)) cout << "YES" << endl;
            else cout << "NO" << endl;
            return 0;
        }
    }
    return 0;
}


//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<bits/stdc++.h>
using namespace std;
auto ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); };
const int MAXN = 1e5+7;
int n;
vector<int> G[MAXN];
int leave;
bool dfs(int u, int fa){
    if(G[u].size()==1) return true;
    int cnt = 0;
    for(int v : G[u]){
        if(v==fa) continue;
        if(!dfs(v,u)) return false;
        cnt++;
    }
    if(cnt>2||(cnt==2&&fa)) return true;
    return false;
}
int main(){
    ____();
    cin >> n;
    for(int i = 1; i < n; i++){
        int u,v;
        cin >>u >> v;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    for(int i = 1; i <= n; i++) if(G[i].size()==1) leave++;
    if(n==2){
        cout << "YES" << endl;
        return 0;
    }
    for(int i = 1; i <= n; i++){
        if(G[i].size()!=1){
            if(dfs(i,0)) cout << "YES" << endl;
            else cout << "NO" << endl;
            return 0;
        }
    }
    return 0;
}


#include <cstdio>
#include <vector>
#include <map>
#include<algorithm>
using namespace std;

int valeur[1000*1000];
long long res;
int N,n,K,k,m;
vector<int> frere[1000*1000];

signed main() {
	scanf("%d",&N);
	for(int i=0;i<N-1;i++){
		int a,b;
		scanf("%d%d",&a,&b);a--;b--;
		frere[a].push_back(b);
		frere[b].push_back(a);
	}
	for(int i=0;i<N;i++)res+=frere[i].size()==1;
	res=res*(res-1)/2;
	if(res>=N-1)
		printf("YES");
	else
		printf("NO");
}


#include <cstdio>
#include <vector>
#include <map>
#include<algorithm>
using namespace std;

int valeur[1000*1000];
int res;
int N,n,K,k,m;
vector<int> frere[1000*1000];

signed main() {
	scanf("%d",&N);
	for(int i=0;i<N-1;i++){
		int a,b;
		scanf("%d%d",&a,&b);a--;b--;
		frere[a].push_back(b);
		frere[b].push_back(a);
	}
	for(int i=0;i<N;i++)res+=frere[i].size()==1;
	res=res*(res-1)/2;
	if(res>=N-1)
		printf("YES");
	else
		printf("NO");
}


#include <cstdio>
#include <vector>
#include <map>
#include<algorithm>
using namespace std;

int valeur[1000*1000];
long long res;
int N,n,K,k,m;
vector<int> frere[1000*1000];

signed main() {
	scanf("%d",&N);
	for(int i=0;i<N-1;i++){
		int a,b;
		scanf("%d%d",&a,&b);a--;b--;
		frere[a].push_back(b);
		frere[b].push_back(a);
	}
	for(int i=0;i<N;i++)if(frere[i].size()==2){
		printf("NO\n");
		return 0;
	}
	for(int i=0;i<N;i++)res+=frere[i].size()==1;
	res=res*(res-1)/2;
	if(res>=N-1)
		printf("YES");
	else
		printf("NO");
}


#include <cstdio>
const int MAXN = 100005;
int n;
int du[MAXN];
int main()
{
	scanf ( "%d", &n );
	for ( int i = 1;i < n;i ++ )
    {
		int u, v;
		scanf ( "%d %d", &u, &v );
		du[u] ++;
		du[v] ++;
	}
	for ( int i = 1;i <= n;i ++ )
		if ( du[i] == 2 )
			return ! printf ( "NO" );
	printf ( "YES" );
	return 0;
}


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

int cnt[100050];

int main(){
	int n;
	scanf("%d", &n);
	for(int u, v, i = 1; i < n; i++) {
		scanf("%d %d", &u, &v);
		cnt[u]++, cnt[v]++;
	}
	for(int i = 1; i <= n; i++) if(cnt[i]==2) {
		printf("NO");return 0;
	}
	printf("YES");
}


#include <cstdio>
#include <cctype>
typedef long long ll;
template <class _T>
void r(_T &x)
{
    #define gc getchar()
    x = 0;
    int f = 1;
    char c = gc;
    while (!isdigit(c)) {if (c == '-') f = -1; c = gc;}
    while (isdigit(c)) x = (x << 3) + (x << 1) + (c ^ 48), c = gc;
    x *= f;
}
const int M = 1e5 + 5;
int degree[M];
int n;
int main()
{
    // openfile();
    r(n);
    for (int i = 1;i < n; i++)
    {
        int u, v;
        r(u), r(v);
        degree[u]++;
        degree[v]++;
    }
    for (int i = 1;i <= n; i++)
        if (degree[i] == 2)
            return !puts("NO");
    puts("YES");
    return 0;
}


#include <cstdio>

const int MAXN = 100000;

int num[MAXN + 5];

int main() {
	int n;
	scanf("%d", &n);
	for(int i = 1; i < n; i++) {
		int u, v;
		scanf("%d %d", &u, &v);
		++num[u], ++num[v];
	}
	bool flag = true;
	for(int i = 1; i <= MAXN; i++)
		if(num[i] == 2)
			flag = false;
	puts(flag ? "YES" : "NO");
}


#include<cstdio>
#include<iostream>
using namespace std;
int n,cnt=0;
struct bian{
	int ne;
	int x;
	int y;
}b[200010];
int d[100010],du[100010];
inline void add(int x,int y){
	b[++cnt].x=x;
	b[cnt].y=y;
	b[cnt].ne=d[x];
	d[x]=cnt;
}
void dfs(int x,int fa){
	for(int i=d[x];i;i=b[i].ne){
		int y=b[i].y;
		++du[x];
		if(y==fa) continue;
		dfs(y,x);
	}
}
int main()
{
	scanf("%d",&n);
	int u,v;
	for(int i=1;i<n;++i){
		scanf("%d%d",&u,&v);
		add(u,v);
		add(v,u);
	}
	dfs(1,0);
	for(int i=1;i<=n;++i){
		if(d[i]==2){
			printf("NO");
			return 0;
		}
	}
	printf("YES");
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=200010;
int n,cou[maxn];
int main(){
	int x,y;
	scanf("%d",&n);
	for(int i=1;i<n;i++){
		scanf("%d%d",&x,&y);
		cou[x]++;
		cou[y]++;
	}
	for(int i=1;i<=n;i++){
		if(cou[i]==2) {
			printf("NO");
			return 0;
		}
	}
	printf("YES");
}


#include<cstdio>
#include<iostream>
const int Maxn=100000+20,inf=0x3f3f3f3f;
int d[Maxn],n;
inline int read()
{
	int s=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0' && ch<='9')s=(s<<3)+(s<<1)+(ch^48),ch=getchar();
	return s*w;
}
bool check()
{
	for(int i=1;i<=n;++i)
	if(d[i]==2)return 0;
	return 1;
}
int main()
{
	//freopen("in.txt","r",stdin);
	n=read();
	for(int i=1;i<n;++i)
	{
		int x=read(),y=read();
		d[x]++,d[y]++;
	}
	if(check())printf("YES\n");
	else printf("NO\n");
	return 0;
}


#include <cstdio>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <iostream>
#include <queue>
#include <stack>
#include <bitset>
#include <map>
using namespace std;
template <typename _TP> inline void read(_TP &x){
	x = 0;int f = 1;char c = getchar();
	for(;c < '0' || '9' < c; c = getchar()) if(c == '-') f = -1;
	for(;'0' <= c && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
	x *= f;return;
}
template <typename _TP> inline void print(_TP x){
	if(x < 0) putchar('-'),x = -x;
	if(x > 9) print(x / 10);
	putchar(x % 10 + 48);
	return;
}
#define rg register
#define ll long long
#define r_2(a,b) read(a),read(b)
#define r_3(a,b,c) read(a),read(b),read(c)
#define print_n(a) print(a),puts("")
#define print_(a) print(a),putchar(' ')
const int inf = 2147483647;
const int maxn = 3e5 + 7;
int n,tot,in_a,in_b;
int head[maxn],deg[maxn];
bool ans = true;
struct edge{int nxt,v;}e[maxn << 1];
inline void add(int u,int v){
	e[++tot].nxt = head[u];
	e[tot].v = v;
	head[u] = tot;
	deg[u]++;
	return;
}
int main()
{
	read(n);
	for(rg int i = 1;i < n; i++) r_2(in_a,in_b),add(in_a,in_b),add(in_b,in_a);
	for(rg int i = 1;i <= n; i++) if(deg[i] == 2) ans = false;
	puts(ans ? "YES" : "NO");
	return 0;
}


#include <cstdio>
#define MAXN 100005
int n;
int du[MAXN];
int main() {
	scanf ( "%d", &n );
	for ( int i = 1;i < n;i ++ ) {
		int u, v;
		scanf ( "%d %d", &u, &v );
		du[u] ++;
		du[v] ++;
	}
	for ( int i = 1;i <= n;i ++ )
		if ( du[i] == 2 )
			return ! printf ( "NO" );
	printf ( "YES" );
	return 0;
}


#include <cstdio>
#define Int register int
const int N = 1e5;
static inline char Get_Char() {
	static char buffer[100000], *S = buffer, *T = buffer;
	if (S == T) {
		T = (S = buffer) + fread(buffer, 1, 100000, stdin);
		if (S == T) return EOF;
	}
	return *S++;
}

//#define Get_Char() getchar()

static inline int Read() {
	int f = 1, x = 0;
	register char sign = Get_Char();
	for (; sign > '9' || sign < '0'; sign = Get_Char())
		if (sign == '-') f = -1;
	for (; sign >= '0' && sign <= '9'; sign = Get_Char())
		x = (x << 3) + (x << 1) + (sign ^ 48);
	return x * f;
}

int node[N + 1];
int main() {
	int n = Read();
	for(Int i = 1, x, y; i < n; ++ i) {
		x = Read(), y = Read();
		node[x]++, node[y]++;
	}

	for (Int i = 1; i <= n; ++ i) {
		if (node[i] & 1 == 0) {
			return !printf("NO\n");
		}
	}
	printf("YES\n");

	return 0;
}


#include <map>
#include <queue>
#include <string>
#include <vector>
#include <cstdio>
#include <cstring>
#include <utility>
#include <iostream>
#include <algorithm>

using namespace std;

template <typename T>
T Max(T x, T y) {return x > y ? x : y;}

template <typename T>
T Min(T x, T y) {return x < y ? x : y;}

template <typename T>
T Fabs(T x) {return x < 0 ? -x : x;}

int n, x, y;
int d[100005];

int main() {
    scanf("%d", &n);
    for(int i = 1; i <= n - 1; i ++) {
        scanf("%d %d", &x, &y);
        d[x] ++, d[y] ++;
    }
    for(int i = 1; i <= n; i ++)
        if(d[i] == 2) {
            printf("NO\n");
            return 0;
        }
    printf("YES\n");
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int n,u,v,flag;
int in[N];
int main(){
	scanf("%d",&n);
	for(int i=1;i<n;i++) scanf("%d%d",&u,&v),in[u]++,in[v]++;
	for(int i=1;i<=n;i++) if(in[i]==2){ flag=1; break; }
	if(flag) puts("NO");
	else puts("YES");
}


#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#define FOR(i, n) for(int i = 0; i < n; i++)
using namespace std;

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

const int MAXN = 100100;

int n;
vector<int> graf[MAXN];

void load() {
	scanf("%d", &n);
	FOR(i, (n-1)) {
		int u, v; scanf("%d%d", &u, &v); u--; v--;
		graf[u].push_back(v);
		graf[v].push_back(u);
	}
}

bool solve() {
	int cnt = 0;
	FOR(i, n) {
		cnt += graf[i].size() == 1;
	}
	return (ll) cnt * (cnt - 1) / 2 >= n - 1;
}

int main() {
	load();
	if (solve()) printf("YES\n");
	else printf("NO\n");
	return 0;
}


#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#define FOR(i, n) for(int i = 0; i < n; i++)
using namespace std;

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

const int MAXN = 100100;

int n;
vector<int> graf[MAXN];

void load() {
	scanf("%d", &n);
	FOR(i, (n-1)) {
		int u, v; scanf("%d%d", &u, &v); u--; v--;
		graf[u].push_back(v);
		graf[v].push_back(u);
	}
}

bool solve() {
	int cnt = 0;
	FOR(i, n) {
		cnt += graf[i].size() == 1;
		if (graf[i].size() == 2) return false;
	}
	return (ll) cnt * (cnt - 1) / 2 >= n - 1;
}

int main() {
	load();
	if (solve()) printf("YES\n");
	else printf("NO\n");
	return 0;
}


#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#define FOR(i, n) for(int i = 0; i < n; i++)
using namespace std;

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

const int MAXN = 100100;

int n;
vector<int> graf[MAXN];

void load() {
	scanf("%d", &n);
	FOR(i, (n-1)) {
		int u, v; scanf("%d%d", &u, &v); u--; v--;
		graf[u].push_back(v);
		graf[v].push_back(u);
	}
}

bool solve() {
	int cnt = 0;
	FOR(i, n) {
		cnt += graf[i].size() == 1;
	}
	return cnt * (cnt - 1) / 2 >= n - 1;
}

int main() {
	load();
	if (solve()) printf("YES\n");
	else printf("NO\n");
	return 0;
}


#include<iostream>
#include<cstdio>

using namespace std;

const int MAXX = 100000;

int n;
int du[MAXX+5];

int main()
{
	scanf("%d",&n);
	for(int i=1,u,v;i<n;i++)
	{
		scanf("%d %d",&u,&v);
		du[u]++,du[v]++;
	}
	for(int i=1;i<=n;i++)
		if(du[i]==2)
		{
			puts("NO");
			return 0;
		}
	puts("YES");
	return 0;
}


#include<iostream>
#include<cstdio>

using namespace std;

const int MAXX = 100000;

int n;
int du[MAXX+5];

int main()
{
	scanf("%d",&n);
	for(int i=1,u,v;i<=n;i++)
	{
		scanf("%d %d",&u,&v);
		du[u]++,du[v]++;
	}
	for(int i=1;i<=n;i++)
		if(du[i]==2)
		{
			puts("NO");
			return 0;
		}
	puts("YES");
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define DEBUG cout<<",here\n";
using namespace std;

struct A
{
    vector<int>to;
    int f,s;
};A a[100005];

int n,u,v,root;

int dfs(int x)
{
    for(auto &i:a[x].to){
        if(i==a[x].f)continue;
        a[i].f=x;
        a[x].s+=dfs(i);
    }
    return a[x].s+1;
}

int main()
{
    cin>>n;
    for(int i=1;i<=n-1;i++){
        cin>>u>>v;
        a[u].to.push_back(v);
        a[v].to.push_back(u);
    }

    root=1;
    dfs(1);

    int jug=0;
    for(int i=1;i<=n;i++){
        if(i!=root&&a[i].s==1){jug=1;break;}
        if(i==root&&a[i].s==2){jug=1;break;}
    }
    if(jug==0){cout<<"YES\n\n";}
    else {cout<<"NO\n\n";}

    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define DEBUG cout<<",here\n";
using namespace std;

struct A
{
    vector<int>to;
    int f,s;
};A a[100005];

int n,u,v,root;

int main()
{
    cin>>n;
    for(int i=1;i<=n-1;i++){
        cin>>u>>v;
        a[u].to.push_back(v);
        a[v].to.push_back(u);
    }

    root=1;

    int jug=0;
    for(int i=1;i<=n;i++){
        if(a[i].to.size()==2){jug=1;break;}
    }
    if(jug==0){cout<<"YES\n\n";}
    else {cout<<"NO\n\n";}

    return 0;
}


#include <bits/stdc++.h>

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

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

#define pb push_back
#define si set<int>::iterator

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

using namespace std;

namespace io {
    const int SI = 1 << 21 | 1;
    char IB[SI], *IS, *IT, OB[SI], *OS = OB, *OT = OS + SI - 1, c, ch[100];
    int f, t;
    #define gc() (IS == IT ? (IT = (IS = IB) + fread(IB, 1, SI, stdin), IS == IT ? EOF : *IS++) : *IS++)
    inline void flush() {
        fwrite(OB, 1, OS - OB, stdout), OS = OB;
    }
    inline void pc(char x) {
        *OS++ = x;
        if (OS == OT) flush();
    }
    template<class I>
    inline void rd(I &x) {
        for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
        for (x = 0; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + (c & 15), c = gc());
        x *= f;
    }
    template<class I>
    inline void print(I x, char k = '\n') {
        if (!x) pc('0');
        if (x < 0) pc('-'), x = -x;
        while (x) ch[++t] = x % 10 + '0', x /= 10;
        while (t) pc(ch[t--]);
        pc(k);
    }
    struct Flush {
        ~Flush() {
            flush();
        }
    } flusher;
}
using io::rd;
using io::print;

template<class I>
inline I Min(I x, I y) {
    return x < y ? x : y;
}

template<class I>
inline I Max(I x, I y) {
    return x > y ? x : y;
}

template<class I>
inline void Swap(I &x, I &y) {
    x ^= y ^= x ^= y;
}

const int N = 1e5 + 6;
int n, d[N];

int main() {
	cin >> n;
	for (int i = 1; i < n; i++) {
		int x, y;
		scanf("%d %d", &x, &y);
		d[x]++, d[y]++;
	}
	for (int i = 1; i <= n; i++) {
		if (d[i] == 2) return puts("NO"), 0;
	}
	puts("YES");
	return 0;
}


#include<iostream>
using namespace std;

int main(){
	int p;

	cin >> p;

	int arr[2][p-1];

	for (int n = 0; n < p - 1; n++) {
		cin>>arr[0][n]>>arr[1][n];
	}

	int d_arr[p];

	for(int i=0;i<p;i++){
		d_arr[i]=0;
	}

	for(int g=0;g<p-1;g++){
		d_arr[arr[0][g]-1]++;
		d_arr[arr[1][g]-1]++;
	}

	bool n= false;

	for(int i=0;i<p;i++){
		if(d_arr[i]==2){
			n = true;
		}
	}

	if(n){
		cout<<"NO"<<endl;
	}
	else{
		cout<<"YES"<<endl;
	}

}


#include<iostream>
using namespace std;

int main(){
	int p;

	cin >> p;

	int arr[2][p-1];

	for (int n = 0; n < p - 1; n++) {
		cin>>arr[0][n]>>arr[1][n];
	}

	if(p%2==0){
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}
}


#include<iostream>
#include<cstring>
using namespace std;
const int N = 1e5 + 5;
int d[N];
int main()
{
    int n;
    cin >> n;
    for(int i = 1; i < n; i ++)
    {
        int u, v;
        cin >> u >> v;
        d[u] ++;
        d[v] ++;
    }
    for(int i = 1; i <= n; i ++)
    {
        if(d[i] == 2)
        {
            puts("NO");
            return 0;
        }
    }
    puts("YES");
    return 0;
}


#include<iostream>
#include<cstring>
using namespace std;
const int N = 1e5 + 5;
struct edge
{
    int v, next;
}e[N * 2];
int n, eid, p[N], d[N];
void init()
{
    eid = 0;
    memset(p, -1, sizeof p);
}
void insert(int u, int v)
{
    e[eid].v = v;
    e[eid].next = p[u];
    p[u] = eid ++;
}
void insert2(int u, int v)
{
    insert(u, v);
    insert(v, u);
}
bool st[N];
int main()
{
    init();
    int n;
    cin >> n;
    for(int i = 1; i < n; i ++)
    {
        int u, v;
        cin >> u >> v;
        insert2(u, v);
        d[u] ++;
        d[v] ++;
    }
    if(n == 2)
    {
        puts("YES");
        return 0;
    }
    bool ans = 1;
    for(int i = 1; i <= n; i ++)
    {
        if(d[i] > 2) continue;
        bool succ = 0;
        for(int j = p[i]; j + 1; j = e[j].next)
        {
            if(d[e[j].v] > 2)
            {
                succ = 1;
                break;
            }
        }
        if(!succ)
        {
         //   cout << i << endl;
            ans = 0;
            break;
        }
    }
    if(ans) puts("YES");
    else puts("NO");
    return 0;
}


//#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef  long long ll ;
const int maxn=3e3+3;
vector<int>v[maxn];
bool mark[maxn];
int par[maxn],ch[maxn],s[maxn];
string ans;
void dfs(int u){
    mark[u]=1;
    s[u]--;
    for(int i=0;i<v[u].size();i++){
        int z=v[u][i];
        if(!mark[z]){
            par[z]=u;
            dfs(z);
        }
    }
    if(s[u]==0)ch[par[u]]++;
}
int main() {
    int n,m;
    cin>>n;
    m=n-1;
    if(n==2){
        cout<<"YES";
        return 0;
    }
    if(n==3){
        cout<<"NO";
        return 0;
    }
    while(m){
        int x,y;
        cin>>x>>y;
        v[x].push_back(y);
        v[y].push_back(x);
        m--;
        s[x]++;
        s[y]++;
    }
    dfs(1);
    for(int i=1;i<n+1;i++){
       //cout<<ch[i]<<" ";
        if(ch[i]==1){
            cout<<"NO";
            return 0;
        }
    }
    cout<<"YES";
    return 0;
}


//#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef  long long ll ;
const int maxn=1e5+3;
vector<int>v[maxn];
bool mark[maxn];
int par[maxn],ch[maxn],s[maxn],c[maxn];
string ans;
void dfs(int u){
    mark[u]=1;
   // s[u]--;
    for(int i=0;i<v[u].size();i++){
        int z=v[u][i];
        if(!mark[z]){
            par[z]=u;
            c[u]++;
            dfs(z);
        }
    }
    if(s[u]==1 && c[u]==0)ch[par[u]]++;
}
int main() {
    int n,m;
    cin>>n;
    m=n-1;
    if(n==2){
        cout<<"YES";
        return 0;
    }
    if(n==3){
        cout<<"NO";
        return 0;
    }
    while(m){
        int x,y;
        cin>>x>>y;
        v[x].push_back(y);
        v[y].push_back(x);
        m--;
        s[x]++;
        s[y]++;
    }
    dfs(1);
    for(int i=1;i<n+1;i++){
      // cout<<ch[i]<<" ";
        if(ch[i]==1){
            cout<<"NO";
            return 0;
        }
    }
    cout<<"YES";
    return 0;
}


#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
typedef  long long ll ;
const int maxn=1e5+3;
int main() {
    int  n;
    cin>>n;
    int a[n+1]={0};
    for(int i=1;i<n;i++){
        int x,y;
        cin>>x>>y;
        a[x]++;
        a[y]++;
    }
    for(int i=1;i<n+1;i++)if(a[i]==2){
        cout<<"NO";
            return  0;
    }
    cout<<"YES";
    return 0;
}


//#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef  long long ll ;
const int maxn=1e5+3;
vector<int>v[maxn];
bool mark[maxn];
int par[maxn],ch[maxn],s[maxn];
string ans;
void dfs(int u){
    mark[u]=1;
    s[u]--;
    for(int i=0;i<v[u].size();i++){
        int z=v[u][i];
        if(!mark[z]){
            par[z]=u;
            dfs(z);
        }
    }
    if(s[u]==0)ch[par[u]]++;
}
int main() {
    int n,m;
    cin>>n;
    m=n-1;
    if(n==2){
        cout<<"YES";
        return 0;
    }
    if(n==3){
        cout<<"NO";
        return 0;
    }
    while(m){
        int x,y;
        cin>>x>>y;
        v[x].push_back(y);
        v[y].push_back(x);
        m--;
        s[x]++;
        s[y]++;
    }
    dfs(1);
    for(int i=1;i<n+1;i++){
       //cout<<ch[i]<<" ";
        if(ch[i]==1){
            cout<<"NO";
            return 0;
        }
    }
    cout<<"YES";
    return 0;
}


#include<bits/stdc++.h>
#define LL long long
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
using namespace std;
inline int read(){
	int v=0,f=1;
	char c=getchar();
	while (c<'0' || c>'9'){
		if (c=='-') f=-1;
		c=getchar();
	}
	while (c>='0' && c<='9'){
		v=v*10+c-'0';
		c=getchar();
	}
	return v*f;
}
const int Maxn=1000005;
const LL mod=998244353;
LL fact[Maxn],ivf[Maxn];
LL qp(LL x,LL p){
	LL ret=1;
	while (p){
		if (p&1) ret=ret*x%mod;
		x=x*x%mod;
		p>>=1;
	}
	return ret;
}
LL inv(LL x){
	return qp(x,mod-2);
}
LL C(LL x,LL y){
	return fact[x]*ivf[y]%mod*ivf[x-y]%mod;
}
int a[Maxn],k,l[Maxn];
vector<int> nd[Maxn];
int main(){
	fact[0]=1;
	for (int i=1;i<Maxn;i++){
		fact[i]=fact[i-1]*i%mod;
	}
	for (int i=0;i<Maxn;i++) ivf[i]=inv(fact[i]);

	scanf("%d",&k);
	int M=0;
	for (int i=1;i<=k;i++){
		scanf("%d",&a[i]);
		M=max(M,a[i]);
		int tmp=a[i]+1;
		for (int j=tmp;j<Maxn;j+=k){
			nd[j].pb(i);
		}
	}
	LL ans=1;
	int sl=0,c=k;
	for (int i=1;i<=M;i++){
		for (int j=0;j<nd[i].size();j++){
			int v=nd[i][j];
			if (!l[v]) c--;
			l[v]++;
			sl++;
		}
		if (sl>i) break;
		int t=i-sl;
		ans+=C(t+k-1,k-1);
		if (t>=c){
			ans-=C(t-c+k-1,k-1);
		}
		ans=(ans%mod+mod)%mod;
	}
	printf("%lld\n",ans);
	return 0;
}


#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) true
#define dump(x) true
#endif
template<unsigned int mod_>
struct ModInt{
	using uint = unsigned int;
	using ll = long long;
	using ull = unsigned long long;

	constexpr static uint mod = mod_;

	uint v;
	ModInt():v(0){}
	ModInt(ll _v):v(normS(_v%mod+mod)){}
	explicit operator bool() const {return v!=0;}
	static uint normS(const uint &x){return (x<mod)?x:x-mod;}		// [0 , 2*mod-1] -> [0 , mod-1]
	static ModInt make(const uint &x){ModInt m; m.v=x; return m;}
	ModInt operator+(const ModInt& b) const { return make(normS(v+b.v));}
	ModInt operator-(const ModInt& b) const { return make(normS(v+mod-b.v));}
	ModInt operator-() const { return make(normS(mod-v)); }
	ModInt operator*(const ModInt& b) const { return make((ull)v*b.v%mod);}
	ModInt operator/(const ModInt& b) const { return *this*b.inv();}
	ModInt& operator+=(const ModInt& b){ return *this=*this+b;}
	ModInt& operator-=(const ModInt& b){ return *this=*this-b;}
	ModInt& operator*=(const ModInt& b){ return *this=*this*b;}
	ModInt& operator/=(const ModInt& b){ return *this=*this/b;}
	ModInt& operator++(int){ return *this=*this+1;}
	ModInt& operator--(int){ return *this=*this-1;}
	ll extgcd(ll a,ll b,ll &x,ll &y) const{
		ll p[]={a,1,0},q[]={b,0,1};
		while(*q){
			ll t=*p/ *q;
			rep(i,3) swap(p[i]-=t*q[i],q[i]);
		}
		if(p[0]<0) rep(i,3) p[i]=-p[i];
		x=p[1],y=p[2];
		return p[0];
	}
	ModInt inv() const {
		ll x,y;
		extgcd(v,mod,x,y);
		return make(normS(x+mod));
	}
	ModInt pow(ll p) const {
		if(p<0) return inv().pow(-p);
		ModInt a = 1;
		ModInt x = *this;
		while(p){
			if(p&1) a *= x;
			x *= x;
			p >>= 1;
		}
		return a;
	}
	bool operator==(const ModInt& b) const { return v==b.v;}
	bool operator!=(const ModInt& b) const { return v!=b.v;}
	friend istream& operator>>(istream &o,ModInt& x){
		ll tmp;
		o>>tmp;
		x=ModInt(tmp);
		return o;
	}
	friend ostream& operator<<(ostream &o,const ModInt& x){ return o<<x.v;}
};
using mint = ModInt<998244353>;
V<mint> fact,ifact;
mint Choose(int a,int b){
	if(b<0 || a<b) return 0;
	return fact[a] * ifact[b] * ifact[a-b];
}
void InitFact(int N){
	fact.resize(N);
	ifact.resize(N);
	fact[0] = 1;
	rep1(i,N-1) fact[i] = fact[i-1] * i;
	ifact[N-1] = fact[N-1].inv();
	for(int i=N-2;i>=0;i--) ifact[i] = ifact[i+1] * (i+1);
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);
	InitFact(2000010);

	int N; cin >> N;
	V<int> a(N); rep(i,N) cin >> a[i]; sort(all(a));
	int XX = a[N-1];
	rep1(i,N-1) if(a[i] <= i-1){
		XX = i-1;
		break;
	}
	VV<int> need(XX+1);
	rep(i,N){
		for(int x = a[i]+1; x <= XX; x += N) need[x].pb(i);
	}
	int need_num = 0, need_sum = 0;
	mint ans = 0;
	rep(X,XX+1){
		for(int v: need[X]){
			chmax(need_num,v+1);
			need_sum++;
		}
		ans += Choose(X-need_sum + N-1, N-1) - Choose(X-need_sum-(N-need_num) + N-1, N-1);
	}
	cout << ans << endl;
}


#include<bits/stdc++.h>
#define rep(i, l, r) for(int i = (l), i##end = (r);i <= i##end;++i)
using std::cin; using std::cout;
const int maxn = 1100100;
typedef long long ll;
const int mod = 998244353;
inline ll pow(ll a,int b,int ans = 1) {
	for(;b;b >>= 1,a = a * a % mod) if(b & 1)
		ans = ans * a % mod;
	return ans;
}
inline ll inverse(int x){ return pow(x, mod - 2); }
int fac[maxn], ifac[maxn], inv[maxn];
inline int c(int n, int m) {
	return (ll) fac[n] * ifac[m] % mod * ifac[n - m] % mod;
}
ll cnt[maxn];
int k;
int main() {
	std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	fac[0] = ifac[0] = fac[1] = ifac[1] = inv[1] = 1;
	for(int i = 2;i < maxn;++i) {
		inv[i] = ll(mod - mod / i) * inv[mod % i] % mod;
		fac[i] = (ll) fac[i - 1] * i % mod;
		ifac[i] = (ll) ifac[i - 1] * inv[i] % mod;
	}
	cin >> k;
	for(int i = 0, x;i < k;++i) {
		cin >> x; ++ cnt[x];
	}
	for(int i = 0;i < k;++i) {
		for(int j = i + k;j < maxn;j += k) {
			cnt[j] += cnt[j - k];
		}
	}
	int end = -1;
	for(int j = 1;j + 1 < maxn;++j) {
		cnt[j] += cnt[j - 1];
		if(cnt[j - 1] > j) {
			end = j;
			break;
		}
	}
	ll ans = 0;
	if(end > 0) {
		ans = 1;
		for(int i = 1;i < end;++i){
			ans += c(i - cnt[i - 1] + k - 1, k - 1);
		}
	} else {
		for(int i = 1e6 - k;i < 1e6;++i) {
			ans += c(i - cnt[i - 1] + k - 1, k - 1);
		}
	}
	cout << ans << '\n';
}


#include<bits/stdc++.h>
#define rep(i, l, r) for(int i = (l), i##end = (r);i <= i##end;++i)
using std::cin; using std::cout;
const int maxn = 1100100;
typedef long long ll;
const int mod = 998244353;
inline ll pow(ll a,int b,int ans = 1) {
	for(;b;b >>= 1,a = a * a % mod) if(b & 1)
		ans = ans * a % mod;
	return ans;
}
inline ll inverse(int x){ return pow(x, mod - 2); }
int fac[maxn], ifac[maxn], inv[maxn];
inline int c(int n, int m) {
	return (ll) fac[n] * ifac[m] % mod * ifac[n - m] % mod;
}
ll cnt[maxn];
int k;
int main() {
	std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	fac[0] = ifac[0] = fac[1] = ifac[1] = inv[1] = 1;
	for(int i = 2;i < maxn;++i) {
		inv[i] = ll(mod - mod / i) * inv[mod % i] % mod;
		fac[i] = (ll) fac[i - 1] * i % mod;
		ifac[i] = (ll) ifac[i - 1] * inv[i] % mod;
	}
	cin >> k;
	for(int i = 0, x;i < k;++i) {
		cin >> x; ++ cnt[x];
	}
	for(int i = 0;i < k;++i) {
		for(int j = i + k;j < maxn;j += k) {
			cnt[j] += cnt[j - k];
		}
	}
	int end = -1;
	for(int j = 1;j + 1 < maxn;++j) {
		cnt[j] += cnt[j - 1];
		if(cnt[j - 1] > j) {
			end = j;
			break;
		}
	}
	ll ans = 0;
	if(end > 0) {
		ans = 1;
		for(int i = 1;i < end;++i){
			ans += c(i - cnt[i - 1] + k - 1, k - 1);
		}
	} else {
		for(int i = 1e6 + 1 - k;i < 1e6 + 1;++i) {
			ans += c(i - cnt[i - 1] + k - 1, k - 1);
		}
	}
	cout << ans % mod << '\n';
}


#include<bits/stdc++.h>
#define rep(i, l, r) for(int i = (l), i##end = (r);i <= i##end;++i)
using std::cin; using std::cout;
const int maxn = 1100100;
typedef long long ll;
const int mod = 998244353;
inline ll pow(ll a,int b,int ans = 1) {
	for(;b;b >>= 1,a = a * a % mod) if(b & 1)
		ans = ans * a % mod;
	return ans;
}
inline ll inverse(int x){ return pow(x, mod - 2); }
int fac[maxn], ifac[maxn], inv[maxn];
inline int c(int n, int m) {
	return (ll) fac[n] * ifac[m] % mod * ifac[n - m] % mod;
}
ll cnt[maxn];
int k;
int main() {
	std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	fac[0] = ifac[0] = fac[1] = ifac[1] = inv[1] = 1;
	for(int i = 2;i < maxn;++i) {
		inv[i] = ll(mod - mod / i) * inv[mod % i] % mod;
		fac[i] = (ll) fac[i - 1] * i % mod;
		ifac[i] = (ll) ifac[i - 1] * inv[i] % mod;
	}
	cin >> k;
	for(int i = 0, x;i < k;++i) {
		cin >> x; ++ cnt[x];
	}
	for(int i = 0;i < k;++i) {
		for(int j = i + k;j < maxn;j += k) {
			cnt[j] += cnt[j - k];
		}
	}
	int end = -1;
	for(int j = 1;j + 1 < maxn;++j) {
		cnt[j] += cnt[j - 1];
		if(cnt[j - 1] > j) {
			end = j;
			break;
		}
	}
	ll ans = 0;
	if(end > 0) {
		ans = 1;
		for(int i = 1;i < end;++i){
			ans += c(i - cnt[i - 1] + k - 1, k - 1);
		}
	} else {
		for(int i = 1e6 + 1 - k;i < 1e6 + 1;++i) {
			ans += c(i - cnt[i - 1] + k - 1, k - 1);
		}
	}
	cout << ans << '\n';
}


#include "bits/stdc++.h"
#define FI first.first
#define SE first.second
#define TH second
#define fi first
#define se second
#define th second

using namespace std;

class DebugStream {}LOG;
template <typename T>DebugStream &operator<<(DebugStream &s, const T&) { return s; }
#ifdef DEBUG
#define LOG clog
#endif

typedef long long ll;
typedef pair<ll, ll> ii;
typedef long double ld;

const int maxN = 1e5 + 9, maxV = 1.1e6 + 9, MOD = 998244353, SQ = 335, lg = 20, bs = 29;

ll fac[maxV][2];

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

ll ncr(int n, int k) {
	if(n < k) return 0;
	return fac[n][0] * fac[n - k][1] % MOD * fac[k][1] % MOD;
}

int k, arr[maxN], bct[maxN];

ll desmadra(int x) {
	return ncr(x + k - 1, k - 1);
}

ll limited() {
	ll ret = 0;
	for(int i = 0; i < k; i++) {
		bct[arr[i] + 1]++;
	}
	for(int i = 1; i <= k; i++) bct[i] += bct[i - 1];

	for(int i = 0; i < k; i++) {
		int sobran = i - bct[i];
		if(sobran < 0) break;
		ret = (ret + desmadra(sobran)) % MOD;
	}
	return ret;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifdef DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif

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

	priority_queue<int> pq;
	int S = 0, tot = 0;
	ll ans = 0;
	for(int i = 0; i < k; i++) pq.push(arr[i] % k), tot += arr[i] % k, S += arr[i];

	fac[0][0] = fac[0][1] = 1;
	for(int i = 1; i <= S + k; i++) {
		fac[i][0] = fac[i - 1][0] * i % MOD;
		fac[i][1] = fastPow(fac[i][0], MOD - 2);
	}

	for(int i = 0; i < k; i++) {
		if(arr[i] < i) {
			cout << limited() << '\n';
			return 0;
		}
	}

	for(int i = 0; i < k; i++) {
		if((S - tot) % k == 0) {
			int amo = (S - tot) / k;
			ans = (ans + desmadra(amo)) % MOD;
		}
		if(i + 1 == k) break;
		tot += k;
		while(pq.top() + i + 1 == k) {
			tot -= k;
			pq.pop();
			pq.push(0);
		}
	}

	cout << ans << '\n';
}


#include<bits/stdc++.h>
using namespace std;
const int mod=998244353;
inline int add(int a,int b)
{
	if((a+=b)>=mod)a-=mod;
	return a;
}
inline int dec(int a,int b)
{
	if((a-=b)<0)a+=mod;
	return a;
}
inline int mult(int a,int b)
{
	long long t=1ll*a*b;
	if(t>=mod)t%=mod;
	return t;
}
inline int power(int a,int b)
{
	int out=1;
	while(b)
	{
		if(b&1)out=mult(out,a);
		a=mult(a,a);
		b>>=1;
	}
	return out;
}
int k,fac[1100010],ifac[1100010],a[100010],cnt[1000010],mx,lft[1000010];
inline int C(int a,int b)
{
	if(a<b)return 0;
	return mult(fac[a],mult(ifac[b],ifac[a-b]));
}
int main()
{
	scanf("%d",&k);
	fac[0]=1;
	for(int i=1;i<=1100000;i++)fac[i]=mult(fac[i-1],i);
	ifac[1100000]=power(fac[1100000],mod-2);
	for(int i=1099999;i>=0;i--)ifac[i]=mult(ifac[i+1],i+1);
	for(int i=1;i<=k;i++)
	{
		scanf("%d",&a[i]);
		cnt[a[i]]++;
		mx=max(mx,a[i]);
	}
	for(int i=1;i<=k;i++)
		for(int j=a[i]+1;j<=mx;j+=k)lft[j]++;
	int ans=1,count=k,empt=0;
	for(int s=1;s<=mx;s++)
	{
		empt++;count-=cnt[s-1];
		if(empt<lft[s])break;
		empt-=lft[s];
		ans=add(ans,C(empt+k-1,k-1));
		ans=dec(ans,C(empt-count+k-1,k-1));
	}
	printf("%d\n",ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int mod=998244353;
inline int add(int a,int b)
{
	if((a+=b)>=mod)a-=mod;
	return a;
}
inline int dec(int a,int b)
{
	if((a-=b)<0)a+=mod;
	return a;
}
inline int mult(int a,int b)
{
	long long t=1ll*a*b;
	if(t>=mod)t%=mod;
	return t;
}
inline int power(int a,int b)
{
	int out=1;
	while(b)
	{
		if(b&1)out=mult(out,a);
		a=mult(a,a);
		b>>=1;
	}
	return out;
}
int fac[1100010],ifac[1100010],a[100010],cnt[1000010],mx,lft[1000010];
inline int C(int a,int b)
{
	if(a<b)return 0;
	return mult(fac[a],mult(ifac[b],ifac[a-b]));
}
int k;
int main()
{
	fac[0]=1;
	for(int i=1;i<=1100000;i++)fac[i]=mult(fac[i-1],i);
	ifac[1100000]=power(fac[1100000],mod-2);
	for(int i=1099999;i>=0;i--)ifac[i]=mult(ifac[i+1],i+1);
	scanf("%d",&k);
	for(int i=1;i<=k;i++)
	{
		scanf("%d",&a[i]);
		cnt[a[i]]++;
		mx=max(mx,a[i]);
	}
	for(int i=1;i<=k;i++)
	{
		for(int j=a[i]+1;j<=mx;j+=k)lft[j]++;
	}
	int ans=1,count=k,empt=0;
	for(int s=1;s<=mx;s++)
	{
		empt++;count-=cnt[s-1];
		if(empt<lft[s])break;
		empt-=lft[s];
		ans=add(ans,C(empt+k-1,k-1));
		ans=dec(ans,C(empt-count+k-1,k-1));
	}
	printf("%d\n",ans);
	return 0;
}


#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

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

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

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

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= (a); i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto& a : x)

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rsz resize

const int MOD = 998244353;
const ll INF = 1e18;
const int MX = 200005;
const ld PI = 4*atan((ld)1);

template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }

namespace input {
    template<class T> void re(complex<T>& x);
    template<class T1, class T2> void re(pair<T1,T2>& p);
    template<class T> void re(vector<T>& a);
    template<class T, size_t SZ> void re(array<T,SZ>& a);

    template<class T> void re(T& x) { cin >> x; }
    void re(double& x) { string t; re(t); x = stod(t); }
    void re(ld& x) { string t; re(t); x = stold(t); }
    template<class Arg, class... Args> void re(Arg& first, Args&... rest) {
        re(first); re(rest...);
    }

    template<class T> void re(complex<T>& x) { T a,b; re(a,b); x = cd(a,b); }
    template<class T1, class T2> void re(pair<T1,T2>& p) { re(p.f,p.s); }
    template<class T> void re(vector<T>& a) { F0R(i,sz(a)) re(a[i]); }
    template<class T, size_t SZ> void re(array<T,SZ>& a) { F0R(i,SZ) re(a[i]); }
}

using namespace input;

namespace output {
    template<class T1, class T2> void pr(const pair<T1,T2>& x);
    template<class T, size_t SZ> void pr(const array<T,SZ>& x);
    template<class T> void pr(const vector<T>& x);
    template<class T> void pr(const set<T>& x);
    template<class T1, class T2> void pr(const map<T1,T2>& x);

    template<class T> void pr(const T& x) { cout << x; }
    template<class Arg, class... Args> void pr(const Arg& first, const Args&... rest) {
        pr(first); pr(rest...);
    }

    template<class T1, class T2> void pr(const pair<T1,T2>& x) {
        pr("{",x.f,", ",x.s,"}");
    }
    template<class T> void prContain(const T& x) {
        pr("{");
        bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; // const needed for vector<bool>
        pr("}");
    }
    template<class T, size_t SZ> void pr(const array<T,SZ>& x) { prContain(x); }
    template<class T> void pr(const vector<T>& x) { prContain(x); }
    template<class T> void pr(const set<T>& x) { prContain(x); }
    template<class T1, class T2> void pr(const map<T1,T2>& x) { prContain(x); }

    void ps() { pr("\n"); }
    template<class Arg> void ps(const Arg& first) {
        pr(first); ps(); // no space at end of line
    }
    template<class Arg, class... Args> void ps(const Arg& first, const Args&... rest) {
        pr(first," "); ps(rest...); // print w/ spaces
    }
}

using namespace output;

namespace io {
    void setIn(string s) { freopen(s.c_str(),"r",stdin); }
    void setOut(string s) { freopen(s.c_str(),"w",stdout); }
    void setIO(string s = "") {
        ios_base::sync_with_stdio(0); cin.tie(0); // fast I/O
        if (sz(s)) { setIn(s+".in"), setOut(s+".out"); } // for USACO
    }
}

using namespace io;

template<class T> T invGeneral(T a, T b) {
    a %= b; if (a == 0) return b == 1 ? 0 : -1;
    T x = invGeneral(b,a);
    return x == -1 ? -1 : ((1-(ll)b*x)/a+b)%b;
}

template<class T> struct modular {
    T val;
    explicit operator T() const { return val; }
    modular() { val = 0; }
    template<class U> modular(const U& v) {
        val = (-MOD <= v && v <= MOD) ? v : v % MOD;
        if (val < 0) val += MOD;
    }
    friend ostream& operator<<(ostream& os, const modular& a) { return os << a.val; }
    friend bool operator==(const modular& a, const modular& b) { return a.val == b.val; }
    friend bool operator!=(const modular& a, const modular& b) { return !(a == b); }

    modular operator-() const { return modular(-val); }
    modular& operator+=(const modular& m) { if ((val += m.val) >= MOD) val -= MOD; return *this; }
    modular& operator-=(const modular& m) { if ((val -= m.val) < 0) val += MOD; return *this; }
    modular& operator*=(const modular& m) { val = (ll)val*m.val%MOD; return *this; }
    friend modular exp(modular a, ll p) {
        modular ans = 1; for (; p; p /= 2, a *= a) if (p&1) ans *= a;
        return ans;
    }
    friend modular inv(const modular& a) {
        auto i = invGeneral(a.val,MOD); assert(i != -1);
        return i;
    } // equivalent to return exp(b,MOD-2) if MOD is prime
    modular& operator/=(const modular& m) { return (*this) *= inv(m); }

    friend modular operator+(modular a, const modular& b) { return a += b; }
    friend modular operator-(modular a, const modular& b) { return a -= b; }
    friend modular operator*(modular a, const modular& b) { return a *= b; }

    friend modular operator/(modular a, const modular& b) { return a /= b; }
};

typedef modular<int> mi;
typedef pair<mi,mi> pmi;
typedef vector<mi> vmi;
typedef vector<pmi> vpmi;

template<int SZ> struct Combo {
    mi smallInv[SZ], fac[SZ], ifac[SZ];
    vpi factors; vi cnt[SZ];

    void genInv() {
        if (sz(factors) == 1 && factors[0].s == 1) {
            F0R(i,2) smallInv[i] = i;
            FOR(i,2,SZ) { // use only O(SZ) operations for MOD a prime
                int x = (MOD+i-1)/i;
                smallInv[i] = smallInv[i*x-MOD]*x;
            }
        } else {
            F0R(i,SZ) {
                int x = invGeneral(i,MOD);
                if (x == -1) smallInv[i] = 0;
                else smallInv[i] = x;
            }
        }
    }

    void init() {
        // factors = factor(MOD);
        factors = {{MOD,1}};
        genInv(); cnt[0] = vi(sz(factors)); fac[0] = ifac[0] = 1;
        FOR(i,1,SZ) {
            cnt[i] = cnt[i-1]; int I = i;
            F0R(j,sz(factors)) while (I % factors[j].f == 0)
                I /= factors[j].f, cnt[i][j] ++;
            fac[i] = fac[i-1]*I; ifac[i] = ifac[i-1]*smallInv[I];
        }
    }

    mi comb(int a, int b) {
        if (a < b || b < 0) return 0;
        auto tmp = fac[a]*ifac[b]*ifac[a-b];
        F0R(i,sz(factors)) {
            int t = cnt[a][i]-cnt[a-b][i]-cnt[b][i];
            tmp *= exp(mi(factors[i].f),t);
        }
        return tmp;
    }
};

Combo<2000005> C;
int k, cnt[1000001];
vi a;

int main() {
    C.init();
    setIO(); re(k); a.rsz(k); re(a); sort(all(a));
    int ind = 0;
    while (ind < k && a[ind] >= ind) ind ++;
    mi ans = 0;
    if (ind == k) {
        int sum = 0;
        trav(t,a) {
            sum += t-t%k;
            cnt[t%k] ++;
        }
        F0R(j,k) {
            sum -= k;
            sum += k*cnt[k-1-j];
            ans += C.comb(sum/k+k-1,k-1);
            // those equal to k-1-j
        }
    } else {
        int cur = 0;
        F0R(j,ind) {
            while (cur < sz(a) && a[cur] < j) cur ++;
            ans += C.comb(j-cur+k-1,k-1);
            // add[0]+add[1]+...+add[k-1] = j-(#<j)
            // j-cur
        }
    }
    ps(ans);
}

/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?), set tle
    * do smth instead of nothing and stay organized
*/


//#pragma GCC optimize("O3")
//#pragma GCC target("arch=corei7-avx")
#include <bits/stdc++.h>
#ifndef ONLINE_JUDGE
# include <sys/time.h>
# include <sys/resource.h>
#endif

/*** TEMPLATE CODE STARTS HERE ***/

#ifndef M_PI
#define M_PI 3.1415926535897932384626433832795028841971693993751
#endif

using namespace std;

typedef vector<string> vs;
typedef long long ll;
typedef complex<double> pnt;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define RA(x) begin(x), end(x)
#define FE(i, x) for (auto i = begin(x); i != end(x); ++i)
#define SZ(x) ((ll) (x).size())

template<class T>
void splitstr(const string &s, vector<T> &out)
{
    istringstream in(s);
    out.clear();
    copy(istream_iterator<T>(in), istream_iterator<T>(), back_inserter(out));
}

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

static void redirect(int argc, const char **argv)
{
#ifndef ONLINE_JUDGE
    struct rlimit rlim;
    getrlimit(RLIMIT_STACK, &rlim);
    rlim.rlim_cur = 256 * 1024 * 1024;
    setrlimit(RLIMIT_STACK, &rlim);
#ifndef __SANITIZE_ADDRESS__
    getrlimit(RLIMIT_DATA, &rlim);
    rlim.rlim_cur = 256 * 1024 * 1024;
    setrlimit(RLIMIT_DATA, &rlim);
#endif
#endif

    ios::sync_with_stdio(false);
    cin.tie(NULL);
    if (argc > 1)
    {
        static filebuf f;
        f.open(argv[1], ios::in);
        cin.rdbuf(&f);
        if (!cin)
        {
            cerr << "Failed to open '" << argv[1] << "'" << endl;
            exit(1);
        }
    }

    if (argc > 2)
    {
        static filebuf f;
        f.open(argv[2], ios::out | ios::trunc);
        cout.rdbuf(&f);
        if (!cout)
        {
            cerr << "Failed to open '" << argv[2] << "'" << endl;
        }
    }
}

/*** TEMPLATE CODE ENDS HERE */

// Undefined sign for negative inputs
template<typename T> static constexpr T wrap_pos(T a, T m) { return a < 0 ? a + m : a; }
template<typename T> static constexpr T sqr(T a) { return a * a; }
// m must be positive
template<typename T> static constexpr T mod(T a, T m) { return wrap_pos(a % m, m); }

template<typename T>
static constexpr T inverse2(T a, T m) { return a <= 1 ? a : mod((1 - inverse2(m % a, a) * m) / a, m); }

// a must be relatively prime to m, m > 0
template<typename T>
static constexpr T inverse(T a, T m) { return inverse2(mod(a, m), m); }

template<typename T, typename P>
static constexpr T power(T a, P b) { return b == 0 ? T(1) : (b % 2) ? power(a, b - 1) * a : sqr(power(a, b / 2)); }

template<typename T, typename C, T Modulus>
class MR
{
private:
    struct tag_plus {}; // indicates value is in range [0, 2 * Modulus)
    struct tag_minus {}; // indicates value is in range (-Modulus, Modulus)
    struct tag_good {}; // indicates value is in range

    T value;

    static_assert(std::numeric_limits<C>::max() / Modulus / Modulus > 0, "compute type is too small");
    static_assert(Modulus < std::numeric_limits<T>::max() / 2, "storage type is too small");

    static constexpr T reduce(T value, tag_plus)
    {
        return value >= Modulus ? value - Modulus : value;
    }

    static constexpr T reduce(T value, tag_minus)
    {
        return value < 0 ? value + Modulus : value;
    }

    static constexpr T reduce(T value, tag_good) { return value; }

public:
    typedef T value_type;
    typedef C compute_type;
    static constexpr T modulus = Modulus;

    constexpr MR() : value(0) {}
    constexpr MR(C value) : value(reduce(value % Modulus, tag_minus())) {}
    template<typename tag_t>
    constexpr MR(T value, tag_t tag) : value(reduce(value, tag)) {}

    MR &operator=(C value) { this->value = reduce(value % Modulus, tag_minus()); return *this; }

    constexpr MR operator +(MR b) const { return MR(value + b.value, tag_plus()); }
    constexpr MR operator -(MR b) const { return MR(value - b.value, tag_minus()); }
    constexpr MR operator *(MR b) const { return MR(C(value) * C(b.value) % Modulus, tag_good()); }
    constexpr MR operator -() const { return MR(-value, tag_minus()); }

    MR &operator +=(MR b) { value = reduce(value + b.value, tag_plus()); return *this; }
    MR &operator -=(MR b) { value = reduce(value - b.value, tag_minus()); return *this; }
    MR &operator *=(MR b) { value = C(value) * C(b.value) % Modulus; return *this; }

    constexpr bool operator==(MR b) const { return value == b.value; }
    constexpr bool operator!=(MR b) const { return value != b.value; }

    constexpr T get() const { return value; }

    // These are only valid if the dividend is relatively prime to the modulus
    constexpr MR inverse() const
    {
        return MR(::inverse(C(value), C(Modulus)), tag_good());
    }
    constexpr MR operator /(MR b) const { return *this * b.inverse(); }
    MR &operator /=(MR b) { return *this *= b.inverse(); }
};

template<typename T, typename C, T Modulus>
static inline std::ostream &operator<<(std::ostream &o, MR<T, C, Modulus> mr)
{
    return o << mr.get();
}

typedef MR<int, ll, 998244353> mr;

int main(int argc, const char **argv)
{
    redirect(argc, argv);
    int K;
    cin >> K;
    vi a(K);
    for (int i = 0; i < K; i++)
        cin >> a[i];
    int S = accumulate(RA(a), 0);
    sort(RA(a));
    vi orig_freq(S + 1);
    vi freq(S + 1);
    vi label(S + 1);
    int nonce = 0;
    auto get_freq = [&](int idx) -> int&
    {
        if (nonce != label[idx])
        {
            freq[idx] = orig_freq[idx];
            label[idx] = nonce;
        }
        return freq[idx];
    };
    for (int v : a)
        orig_freq[v]++;

    vi taps(S + 1);
    for (int i = 0; i < K; i++)
    {
        if (a[i] < i)
            break;
        int lose = i;
        nonce++;
        for (int x = i; x <= a[i]; x++)
        {
            if (lose <= x)
                taps[x - lose]++;
            int cur = get_freq(x);
            lose += cur;
            if (x + K <= a[i])
                get_freq(x + K) += cur;
        }
        orig_freq[a[i]]--;
        if (a[i] + K <= S)
            orig_freq[a[i] + K]++;
    }

    mr ans = 0;
    mr p = 1;
    for (int t = 0; t <= S; t++)
    {
        ans += p * taps[t];
        p = p * (K + t - 1) / (t + 1);
    }
    cout << ans << '\n';

    return 0;
}


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


// ███▓▓▓▓▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓▓▓╬╬╬╬╬╬▓█
// ███▓███████▓▓╬╬╬╬╬╬╬╬╬╬╬╬▓███▓▓▓▓█▓╬╬╬▓█
// ███████▓█████▓▓╬╬╬╬╬╬╬╬▓███▓╬╬╬╬╬╬╬▓╬╬▓█
// ████▓▓▓▓╬╬▓█████╬╬╬╬╬╬███▓╬╬╬╬╬╬╬╬╬╬╬╬╬█
// ███▓▓▓▓╬╬╬╬╬╬▓██╬╬╬╬╬╬▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓█
// ████▓▓▓╬╬╬╬╬╬╬▓█▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓█
// ███▓█▓███████▓▓███▓╬╬╬╬╬╬▓███████▓╬╬╬╬▓█
// ████████████████▓█▓╬╬╬╬╬▓▓▓▓▓▓▓▓╬╬╬╬╬╬╬█
// ███▓▓▓▓▓▓▓╬╬▓▓▓▓▓█▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓█
// ████▓▓▓╬╬╬╬▓▓▓▓▓▓█▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓█
// ███▓█▓▓▓▓▓▓▓▓▓▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓█
// █████▓▓▓▓▓▓▓▓█▓▓▓█▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓█
// █████▓▓▓▓▓▓▓██▓▓▓█▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██
// █████▓▓▓▓▓████▓▓▓█▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██
// ████▓█▓▓▓▓██▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██
// ████▓▓███▓▓▓▓▓▓▓██▓╬╬╬╬╬╬╬╬╬╬╬╬█▓╬▓╬╬▓██
// █████▓███▓▓▓▓▓▓▓▓████▓▓╬╬╬╬╬╬╬█▓╬╬╬╬╬▓██
// █████▓▓█▓███▓▓▓████╬▓█▓▓╬╬╬▓▓█▓╬╬╬╬╬╬███
// ██████▓██▓███████▓╬╬╬▓▓╬▓▓██▓╬╬╬╬╬╬╬▓███
// ███████▓██▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬████
// ███████▓▓██▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓████
// ████████▓▓▓█████▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓█████
// █████████▓▓▓█▓▓▓▓▓███▓╬╬╬╬╬╬╬╬╬╬╬▓██████
// ██████████▓▓▓█▓▓▓╬▓██╬╬╬╬╬╬╬╬╬╬╬▓███████
// ███████████▓▓█▓▓▓▓███▓╬╬╬╬╬╬╬╬╬▓████████
// ██████████████▓▓▓███▓▓╬╬╬╬╬╬╬╬██████████
// ███████████████▓▓▓██▓▓╬╬╬╬╬╬▓███████████
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define pb push_back
#define x first
#define y second
#define mp make_pair
#define len(a) int(a.size())
#define files(FILENAME) read(FILENAME); write(FILENAME)
#define read(FILENAME) freopen((string(FILENAME) + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((string(FILENAME) + ".out").c_str(), "w", stdout)
using namespace std;

template<typename T1, typename T2>inline void chkmin(T1 &x, T2 y) { if (x > y) x = y; }
template<typename T1, typename T2>inline void chkmax(T1 &x, T2 y) { if (x < y) x = y; }
template<typename T, typename U> inline ostream &operator<< (ostream &_out, const pair<T, U> &_p) { _out << _p.first << ' ' << _p.second; return _out; }
template<typename T, typename U> inline istream &operator>> (istream &_in, pair<T, U> &_p) { _in >> _p.first >> _p.second; return _in; }
template<typename T> inline ostream &operator<< (ostream &_out, const vector<T> &_v) { if (_v.empty()) { return _out; } _out << _v.front(); for (auto _it = ++_v.begin(); _it != _v.end(); ++_it) { _out << ' ' << *_it; } return _out; }
template<typename T> inline istream &operator>> (istream &_in, vector<T> &_v) { for (auto &_i : _v) { _in >> _i; } return _in; }
template<typename T> inline ostream &operator<< (ostream &_out, const set<T> &_s) { if (_s.empty()) { return _out; } _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; } return _out; }
template<typename T> inline ostream &operator<< (ostream &_out, const multiset<T> &_s) { if (_s.empty()) { return _out; } _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; } return _out; }
template<typename T> inline ostream &operator<< (ostream &_out, const unordered_set<T> &_s) { if (_s.empty()) { return _out; } _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; } return _out; }
template<typename T> inline ostream &operator<< (ostream &_out, const unordered_multiset<T> &_s) { if (_s.empty()) { return _out; } _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; } return _out; }
template<typename T, typename U> inline ostream &operator<< (ostream &_out, const map<T, U> &_m) { if (_m.empty()) { return _out; } _out << '(' << _m.begin()->first << ": " << _m.begin()->second << ')'; for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) { _out << ", (" << _it->first << ": " << _it->second << ')'; } return _out; }
template<typename T, typename U> inline ostream &operator<< (ostream &_out, const unordered_map<T, U> &_m) { if (_m.empty()) { return _out; } _out << '(' << _m.begin()->first << ": " << _m.begin()->second << ')'; for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) { _out << ", (" << _it->first << ": " << _it->second << ')'; } return _out; }

typedef long long base;
typedef pair<int, int> point;
typedef complex<double> comp;

const int N = 1e5 + 5;
const int M = 2e6 + 5;
const int p = 998244353;

int sum(int a, int b) {
	a += b;
	return a < p ? a : a - p;
}

int mul(long long a, int b) {
	return a * b % p;
}

int powx(int a, int b) {
	int ans = 1;
	while (b) {
		if (b & 1) ans = mul(ans, a);
		a = mul(a, a);
		b >>= 1;
	}
	return ans;
}

int n;
vector<int> a;
int f[2][M];

int cnk(int n, int k) {
	return mul(f[0][n], mul(f[1][n - k], f[1][k]));
}

int func(int n, int k) {
	return cnk(n + k - 1, k - 1);
}

int cnt[M];

long long sumw = 0, sumw2 = 0;

int r[M];

int main() {
    ios::sync_with_stdio(0);
    srand(time(0));
    cin >> n;
    a.resize(n);
    cin >> a;
    sort(a.begin(), a.end());
    f[0][0] = 1;
    for (int i = 1; i < M; ++i) {
    	f[0][i] = mul(f[0][i - 1], i);
    }
    f[1][M - 1] = powx(f[0][M - 1], p - 2);
    for (int i = M - 1; i--;) {
    	f[1][i] = mul(f[1][i + 1], i + 1);
    }
    for (auto i : a) {
    	cnt[i]++;
    	sumw += i;
    	r[i % n]++;
    	sumw2 += i % n;
    }
    for (int i = 1; i + 1 <= n; ++i) {
    	if (a[i] < i) {
    		int ans = 1;
    		int mod = 0;
    		for (int j = 1; j < i; ++j) {
    			mod += cnt[j - 1];
    			assert(mod <= j);
    			ans = sum(ans, func(j - mod, n));
    		}
    		cout << ans << '\n';
    		return 0;
    	}
    }
    int ans = 0;
    for (int i = 0; i < n; ++i) {
    	if (sumw >= sumw2 && (sumw - sumw2) % n == 0) {
    		ans = sum(ans, func((sumw - sumw2) / n, n));
		}
    	sumw2 -= n - r[i];
    	sumw2 += 1LL * (n - 1) * r[i];
    }
    cout << ans << '\n';
}


#include<bits/stdc++.h>
using namespace std;
const int N=3e6+7,p=998244353;
int n,ans,w[N],g[N],q[N],fac[N],ifac[N]; bool fl[N];
inline int read(){
	int num=0; char g=getchar(); while(g<48||57<g) g=getchar();
	while(47<g&&g<58) num=(num<<1)+(num<<3)+g-48,g=getchar(); return num;
}
inline int pows(long long u,int v){
	long long ans=1;
	while(v>0){
		if(v&1) ans=ans*u%p; u=u*u%p,v=v>>1;
	}
	return ans;
}
inline int binom(int a,int b){
	if(a<b) return 0; return 1ll*fac[a]*ifac[b]%p*ifac[a-b]%p;
}
int main(){
	n=read(),fac[0]=ifac[0]=1;
	for(int i=1;i<=n;i++) w[i]=read()+1;
	for(int i=1;i<=2000000;i++) fac[i]=1ll*fac[i-1]*i%p,ifac[i]=pows(fac[i],p-2);
	sort(w+1,w+n+1),w[n+1]=1919810;
	for(int i=1;i<=n;i++){
		if(w[i]<i) break; fl[i]=1;
	}
	for(int i=1;i<=n;i++){
		int op=i-1; if(!fl[i]) continue;
		for(int j=0;j<w[i];j++){
			q[j%n]+=g[j];
			ans=(ans+binom(j-op+n-2,n-2))%p;
			op+=q[(j+1)%n];
		}
		g[w[i]]++;
		for(int j=1;j<=w[i];j++) g[j%n]=0;
	}
	cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
const int N=3e6+7,p=998244353;
int n,ans,w[N],g[N],q[N],fac[N],ifac[N]; bool fl[N];
inline int read(){
	int num=0; char g=getchar(); while(g<48||57<g) g=getchar();
	while(47<g&&g<58) num=(num<<1)+(num<<3)+g-48,g=getchar(); return num;
}
inline int pows(long long u,int v){
	long long ans=1;
	while(v>0){
		if(v&1) ans=ans*u%p; u=u*u%p,v=v>>1;
	}
	return ans;
}
inline int binom(int a,int b){
	if(a<b) return 0; return 1ll*fac[a]*ifac[b]%p*ifac[a-b]%p;
}
int main(){
	n=read(),fac[0]=ifac[0]=1;
	for(int i=1;i<=n;i++) w[i]=read()+1;
	for(int i=1;i<=2000000;i++) fac[i]=1ll*fac[i-1]*i%p,ifac[i]=pows(fac[i],p-2);
	sort(w+1,w+n+1),w[n+1]=1919810;
	for(int i=1;i<=n;i++){
		if(w[i]<i) break; fl[i]=1;
	}
	for(int i=1;i<=n;i++){
		int op=i-1; if(!fl[i]) continue;
		for(int j=0;j<w[i];j++){
			q[j%n]+=g[j];
			ans=(ans+binom(j-op+n-2,n-2))%p;
			op+=q[(j+1)%n];
		}
		g[w[i]]++;
		for(int j=1;j<=w[i];j++) q[j%n]=0;
	}
	cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
const int N=1e6+7,p=998244353;
int n,ans,w[N],g[N],q[N],fac[N],ifac[N]; bool fl[N];
inline int read(){
	int num=0; char g=getchar(); while(g<48||57<g) g=getchar();
	while(47<g&&g<58) num=(num<<1)+(num<<3)+g-48,g=getchar(); return num;
}
inline int pows(long long u,int v){
	long long ans=1;
	while(v>0){
		if(v&1) ans=ans*u%p; u=u*u%p,v=v>>1;
	}
	return ans;
}
inline int binom(int a,int b){
	if(a<b) return 0; return 1ll*fac[a]*ifac[b]%p*ifac[a-b]%p;
}
int main(){
	n=read(),fac[0]=ifac[0]=1;
	for(int i=1;i<=n;i++) w[i]=read()+1;
	for(int i=1;i<=1000000;i++) fac[i]=1ll*fac[i-1]*i%p,ifac[i]=pows(fac[i],p-2);
	sort(w+1,w+n+1),w[n+1]=1919810;
	for(int i=1;i<=n;i++){
		if(w[i]<i) break; fl[i]=1;
	}
	for(int i=1;i<=n;i++){
		int op=i-1; if(!fl[i]) continue;
		for(int j=0;j<w[i];j++){
			q[j%n]+=g[j];
			ans=(ans+binom(j-op+n-2,n-2))%p;
			op+=q[(j+1)%n];
		}
		g[w[i]]++;
		for(int j=1;j<=w[i];j++) g[j%n]=0;
	}
	cout<<ans<<endl;
}


#ifdef ONPC
# define _GLIBCXX_DEBUG
#define deb(a) cerr << "nu smotri pidor " << #a << " = " << a << endl;
#else
#define deb(a)
#endif
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;

typedef long long ll;
typedef long double ld;
ll MOD = 998244353;

ll st(ll t, ll id, ll mod){
    ll res = 1, a = t, n = id;
    while (n) {
        if (n & 1)
            res = (res * a) % mod;
        a = (a * a) % mod;
        n >>= 1;
    }
    return res % mod;
}
ll del(ll a, ll b){
    return (a * st(b, MOD - 2, MOD)) % MOD;
}

ll fac[3000000];

ll ch(ll a, ll b){
    return del(fac[b], (fac[a] * fac[b - a]) % MOD) % MOD;
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0), cout << fixed << setprecision(20);
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    fac[0] = 1;
    for (int i = 1; i < 3000000; i++){
        fac[i] = (fac[i - 1] * i) % MOD;
    }
    sort(a.begin(), a.end());
    ll ans = -1;
    for (int i = 0; i < n; i++){
        if (a[i] < i){
            ans = i - 1;
            break;
        }
    }
    if (ans != -1) {
        ll res = 0;
        ll lf = 0;
        for (int i = 0; i <= ans; i++) {
            while (a[lf] < i){
                lf++;
            }
            res += ch(n - 1, n + i - lf - 1);
            res %= MOD;
        }
        cout << res % MOD;
    }
    else{
        //cout << "mem";
        ll sm = 0;
        for (int i = 0; i < n; i++){
            sm += a[i] - a[i] % n;
        }
        ll res = ch(n - 1, sm / n + n - 1);
        ll ls = n - 1;
        for (int t = 1; t < n; t++){
            ll kl = 0;
            while (ls >= 0 && t + a[ls] % n >= n){
                ls--;
                kl++;
            }
            sm += kl * n;
            sm -= n;
            sm /= n;
            res += ch(n - 1, sm + n - 1);
            res %= MOD;
            sm *= n;
        }
        cout << res % MOD;
    }

#ifdef ONPC
    cerr << endl << "finished in " << clock() * 1.0 / CLOCKS_PER_SEC << " sec" << endl;
#endif
}
//egor lox


#ifdef ONPC
# define _GLIBCXX_DEBUG
#define deb(a) cerr << "nu smotri pidor " << #a << " = " << a << endl;
#else
#define deb(a)
#endif
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;

typedef long long ll;
typedef long double ld;
ll MOD = 998244353;

ll st(ll t, ll id, ll mod){
    ll res = 1, a = t, n = id;
    while (n) {
        if (n & 1)
            res = (res * a) % mod;
        a = (a * a) % mod;
        n >>= 1;
    }
    return res % mod;
}
ll del(ll a, ll b){
    return (a * st(b, MOD - 2, MOD)) % MOD;
}

ll fac[3000000];

ll ch(ll a, ll b){
    return del(fac[b], (fac[a] * fac[b - a]) % MOD) % MOD;
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0), cout << fixed << setprecision(20);
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    fac[0] = 1;
    for (int i = 1; i < 3000000; i++){
        fac[i] = (fac[i - 1] * i) % MOD;
    }
    sort(a.begin(), a.end());
    ll ans = -1;
    for (int i = 0; i < n; i++){
        if (a[i] < i){
            ans = i - 1;
            break;
        }
    }
    if (ans != -1) {
        ll res = 0;
        ll lf = 0;
        for (int i = 0; i <= ans; i++) {
            while (a[lf] < i){
                lf++;
            }
            res += ch(n - 1, n + i - lf - 1);
            res %= MOD;
        }
        cout << res % MOD;
    }
    else{
        ll sm = 0;
        for (int i = 0; i < n; i++){
            sm += a[i] - a[i] % n;
        }
        sm /= n;
        ll res = ch(n - 1, sm + n - 1);
        ll ls = 0;
        for (int t = 1; t < n; t++){
            ll kl = 0;
            while (ls < n && (a[ls] % n) <= t + 1){
                ls++;
                kl++;
            }
            sm += kl;
            sm -= 1;
            res += ch(n - 1, sm + n - 1);
            res %= MOD;
        }
        cout << res % MOD;
    }

#ifdef ONPC
    cerr << endl << "finished in " << clock() * 1.0 / CLOCKS_PER_SEC << " sec" << endl;
#endif
}
//egor lox


#ifdef ONPC
# define _GLIBCXX_DEBUG
#define deb(a) cerr << "nu smotri pidor " << #a << " = " << a << endl;
#else
#define deb(a)
#endif
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;

typedef long long ll;
typedef long double ld;
ll MOD = 998244353;

ll st(ll t, ll id, ll mod){
    ll res = 1, a = t, n = id;
    while (n) {
        if (n & 1)
            res = (res * a) % mod;
        a = (a * a) % mod;
        n >>= 1;
    }
    return res % mod;
}
ll del(ll a, ll b){
    return (a * st(b, MOD - 2, MOD)) % MOD;
}

ll fac[3000000];

ll ch(ll a, ll b){
    return del(fac[b], (fac[a] * fac[b - a]) % MOD);
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0), cout << fixed << setprecision(20);
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    fac[0] = 1;
    for (int i = 1; i < 1000000; i++){
        fac[i] = (fac[i - 1] * i) % MOD;
    }
    sort(a.begin(), a.end());
    ll ans = -1;
    for (int i = 0; i < n; i++){
        if (a[i] < i){
            ans = i - 1;
            break;
        }
    }
    if (ans != -1) {
        ll res = 0;
        ll lf = 0;
        for (int i = 0; i <= ans; i++) {
            while (a[lf] < i){
                lf++;
            }
            res += ch(n - 1, n + i - lf - 1);
            res %= MOD;
        }
        cout << res % MOD;
    }
    else{
        //cout << "mem";
        ll sm = 0;
        for (int i = 0; i < n; i++){
            sm += a[i] - a[i] % n;
        }
        ll res = ch(n - 1, sm / n + n - 1);
        ll ls = n - 1;
        for (int t = 1; t < n; t++){
            ll kl = 0;
            while (ls >= 0 && t + a[ls] % n >= n){
                ls--;
                kl++;
            }
            sm += kl * n;
            sm -= n;
            sm /= n;
            res += ch(n - 1, sm + n - 1);
            res %= MOD;
            sm *= n;
        }
        cout << res % MOD;
    }

#ifdef ONPC
    cerr << endl << "finished in " << clock() * 1.0 / CLOCKS_PER_SEC << " sec" << endl;
#endif
}
//egor lox


#ifdef ONPC
# define _GLIBCXX_DEBUG
#define deb(a) cerr << "nu smotri pidor " << #a << " = " << a << endl;
#else
#define deb(a)
#endif
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;

typedef long long ll;
typedef long double ld;
ll MOD = 998244353;

ll st(ll t, ll id, ll mod){
    ll res = 1, a = t, n = id;
    while (n) {
        if (n & 1)
            res = (res * a) % mod;
        a = (a * a) % mod;
        n >>= 1;
    }
    return res % mod;
}
ll del(ll a, ll b){
    return (a * st(b, MOD - 2, MOD)) % MOD;
}

ll fac[3000000];

ll ch(ll a, ll b){
    return del(fac[b], (fac[a] * fac[b - a]) % MOD) % MOD;
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0), cout << fixed << setprecision(20);
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    fac[0] = 1;
    for (int i = 1; i < 3000000; i++){
        fac[i] = (fac[i - 1] * i) % MOD;
    }
    sort(a.begin(), a.end());
    ll ans = -1;
    for (int i = 0; i < n; i++){
        if (a[i] < i){
            ans = i - 1;
            break;
        }
    }
    if (ans != -1) {
        ll res = 0;
        ll lf = 0;
        for (int i = 0; i <= ans; i++) {
            while (a[lf] < i){
                lf++;
            }
            res += ch(n - 1, n + i - lf - 1);
            res %= MOD;
        }
        cout << res % MOD;
    }
    else{
        ll sm = 0;
        for (int i = 0; i < n; i++){
            sm += a[i] / n;
        }
        ll ls = 0;
        ll res = 0;
        for (int t = 0; t < n; t++){
            ll kl = 0;
            while (ls < n && (a[ls] % n) <= t){
                ls++;
                kl++;
            }
            sm -= kl;
            sm += 1;
            res += ch(n - 1, sm + n - 1);
            res %= MOD;
        }
        cout << res % MOD;
    }

#ifdef ONPC
    cerr << endl << "finished in " << clock() * 1.0 / CLOCKS_PER_SEC << " sec" << endl;
#endif
}
//egor lox


#ifdef ONPC
# define _GLIBCXX_DEBUG
#define deb(a) cerr << "nu smotri pidor " << #a << " = " << a << endl;
#else
#define deb(a)
#endif
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;

typedef long long ll;
typedef long double ld;
ll MOD = 998244353;

ll st(ll t, ll id, ll mod){
    ll res = 1, a = t, n = id;
    while (n) {
        if (n & 1)
            res = (res * a) % mod;
        a = (a * a) % mod;
        n >>= 1;
    }
    return res % mod;
}
ll del(ll a, ll b){
    return (a * st(b, MOD - 2, MOD)) % MOD;
}

ll fac[3000000];

ll ch(ll a, ll b){
    return del(fac[b], (fac[a] * fac[b - a]) % MOD);
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0), cout << fixed << setprecision(20);
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    fac[0] = 1;
    for (int i = 1; i < 1000000; i++){
        fac[i] = (fac[i - 1] * i) % MOD;
    }
    sort(a.begin(), a.end());
    ll ans = -1;
    for (int i = 0; i < n; i++){
        if (a[i] < i){
            ans = i - 1;
            break;
        }
    }
    if (ans != -1) {
        ll res = 0;
        ll lf = 0;
        for (int i = 0; i <= ans; i++) {
            while (a[lf] < i){
                lf++;
            }
            res += ch(n - 1, n + i - lf - 1);
        }
        cout << res;
    }
    else{
        //cout << "mem";
        ll sm = 0;
        for (int i = 0; i < n; i++){
            sm += a[i] - a[i] % n;
        }
        ll res = ch(n - 1, sm / n + n - 1);
        ll ls = n - 1;
        for (int t = 1; t < n; t++){
            ll kl = 0;
            while (ls >= 0 && t + a[ls] % n >= n){
                ls--;
                kl++;
            }
            sm += kl * n;
            sm -= n;
            sm /= n;
            res += ch(n - 1, sm + n - 1);
            sm *= n;
        }
        cout << res;
    }

#ifdef ONPC
    cerr << endl << "finished in " << clock() * 1.0 / CLOCKS_PER_SEC << " sec" << endl;
#endif
}
//egor lox


#ifdef ONPC
# define _GLIBCXX_DEBUG
#define deb(a) cerr << "nu smotri pidor " << #a << " = " << a << endl;
#else
#define deb(a)
#endif
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;

typedef long long ll;
typedef long double ld;
ll MOD = 998244353;

ll st(ll t, ll id, ll mod){
    ll res = 1, a = t, n = id;
    while (n) {
        if (n & 1)
            res = (res * a) % mod;
        a = (a * a) % mod;
        n >>= 1;
    }
    return res % mod;
}
ll del(ll a, ll b){
    return (a * st(b, MOD - 2, MOD)) % MOD;
}

ll fac[3000000];

ll ch(ll a, ll b){
    return del(fac[b], (fac[a] * fac[b - a]) % MOD) % MOD;
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0), cout << fixed << setprecision(20);
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    fac[0] = 1;
    for (int i = 1; i < 3000000; i++){
        fac[i] = (fac[i - 1] * i) % MOD;
    }
    sort(a.begin(), a.end());
    ll ans = -1;
    for (int i = 0; i < n; i++){
        if (a[i] < i){
            ans = i - 1;
            break;
        }
    }
    if (ans != -1) {
        if (n == 100)
            cout << "mem2";
        ll res = 0;
        ll lf = 0;
        for (int i = 0; i <= ans; i++) {
            while (a[lf] < i){
                lf++;
            }
            res += ch(n - 1, n + i - lf - 1);
            res %= MOD;
        }
        cout << res % MOD;
    }
    else{

        if (n == 100)
            cout << "mem";
        ll sm = 0;
        for (int i = 0; i < n; i++){
            sm += a[i] - a[i] % n;
        }
        ll res = ch(n - 1, sm / n + n - 1);
        ll ls = n - 1;
        for (int t = 1; t < n; t++){
            ll kl = 0;
            while (ls >= 0 && t + a[ls] % n >= n){
                ls--;
                kl++;
            }
            sm += kl * n;
            sm -= n;
            sm /= n;
            res += ch(n - 1, sm + n - 1);
            res %= MOD;
            sm *= n;
        }
        cout << res % MOD;
    }

#ifdef ONPC
    cerr << endl << "finished in " << clock() * 1.0 / CLOCKS_PER_SEC << " sec" << endl;
#endif
}
//egor lox


#ifdef ONPC
# define _GLIBCXX_DEBUG
#define deb(a) cerr << "nu smotri pidor " << #a << " = " << a << endl;
#else
#define deb(a)
#endif
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;

typedef long long ll;
typedef long double ld;
ll MOD = 998244353;

ll st(ll t, ll id, ll mod){
    ll res = 1, a = t, n = id;
    while (n) {
        if (n & 1)
            res = (res * a) % mod;
        a = (a * a) % mod;
        n >>= 1;
    }
    return res % mod;
}
ll del(ll a, ll b){
    return (a * st(b, MOD - 2, MOD)) % MOD;
}

ll fac[3000000];

ll ch(ll a, ll b){
    return del(fac[b], (fac[a] * fac[b - a]) % MOD) % MOD;
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0), cout << fixed << setprecision(20);
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    fac[0] = 1;
    for (int i = 1; i < 3000000; i++){
        fac[i] = (fac[i - 1] * i) % MOD;
    }
    sort(a.begin(), a.end());
    ll ans = -1;
    for (int i = 0; i < n; i++){
        if (a[i] < i){
            ans = i - 1;
            break;
        }
    }
    if (ans != -1) {
        ll res = 0;
        ll lf = 0;
        for (int i = 0; i <= ans; i++) {
            while (a[lf] < i){
                lf++;
            }
            res += ch(n - 1, n + i - lf - 1);
            res %= MOD;
        }
        cout << res % MOD;
    }
    else{
        ll sm = 0;
        for (int i = 0; i < n; i++){
            sm += a[i] / n;
        }
        ll ls = n - 1;
        ll res = 0;
        for (int t = 0; t < n; t++){
            ll kl = 0;
            while (ls > -1 && (a[ls] % n + t) >= n){
                ls--;
                kl++;
            }
            sm += kl;
            if (t)
                sm -= 1;
            res += ch(n - 1, sm + n - 1);
            res %= MOD;
        }
        cout << res % MOD;
    }

#ifdef ONPC
    cerr << endl << "finished in " << clock() * 1.0 / CLOCKS_PER_SEC << " sec" << endl;
#endif
}
//egor lox


#ifdef ONPC
# define _GLIBCXX_DEBUG
#define deb(a) cerr << "nu smotri pidor " << #a << " = " << a << endl;
#else
#define deb(a)
#endif
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;

typedef long long ll;
typedef long double ld;
ll MOD = 998244353;

ll st(ll t, ll id, ll mod){
    ll res = 1, a = t, n = id;
    while (n) {
        if (n & 1)
            res = (res * a) % mod;
        a = (a * a) % mod;
        n >>= 1;
    }
    return res % mod;
}
ll del(ll a, ll b){
    return (a * st(b, MOD - 2, MOD)) % MOD;
}

ll fac[3000000];

ll ch(ll a, ll b){
    return del(fac[b], (fac[a] * fac[b - a]) % MOD) % MOD;
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0), cout << fixed << setprecision(20);
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    fac[0] = 1;
    for (int i = 1; i < 3000000; i++){
        fac[i] = (fac[i - 1] * i) % MOD;
    }
    sort(a.begin(), a.end());
    ll ans = -1;
    for (int i = 0; i < n; i++){
        if (a[i] < i){
            ans = i - 1;
            break;
        }
    }
    if (ans != -1) {
        ll res = 0;
        ll lf = 0;
        for (int i = 0; i <= ans; i++) {
            while (a[lf] < i){
                lf++;
            }
            res += ch(n - 1, n + i - lf - 1);
            res %= MOD;
        }
        cout << res % MOD;
    }
    else{
        ll sm = 0;
        for (int i = 0; i < n; i++){
            sm += a[i] - a[i] % n;
        }
        sm /= n;
        ll res = ch(n - 1, sm + n - 1);
        ll ls = n - 1;
        for (int t = 1; t < n; t++){
            ll kl = 0;
            while (ls >= 0 && t + a[ls] % n >= n){
                ls--;
                kl++;
            }
            sm += kl;
            sm -= 1;
            res += ch(n - 1, sm + n - 1);
            res %= MOD;
        }
        cout << res % MOD;
    }

#ifdef ONPC
    cerr << endl << "finished in " << clock() * 1.0 / CLOCKS_PER_SEC << " sec" << endl;
#endif
}
//egor lox


#ifdef ONPC
# define _GLIBCXX_DEBUG
#define deb(a) cerr << "nu smotri pidor " << #a << " = " << a << endl;
#else
#define deb(a)
#endif
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;

typedef long long ll;
typedef long double ld;
ll MOD = 998244353;

ll st(ll t, ll id, ll mod){
    ll res = 1, a = t, n = id;
    while (n) {
        if (n & 1)
            res = (res * a) % mod;
        a = (a * a) % mod;
        n >>= 1;
    }
    return res % mod;
}
ll del(ll a, ll b){
    return (a * st(b, MOD - 2, MOD)) % MOD;
}

ll fac[3000000];
ll kol[3000000];

ll ch(ll a, ll b){
    return del(fac[b], (fac[a] * fac[b - a]) % MOD) % MOD;
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0), cout << fixed << setprecision(20);
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
        kol[a[i] % n]++;
    }
    fac[0] = 1;
    for (int i = 1; i < 3000000; i++){
        fac[i] = (fac[i - 1] * i) % MOD;
    }
    sort(a.begin(), a.end());
    ll ans = -1;
    for (int i = 0; i < n; i++){
        if (a[i] < i){
            ans = i - 1;
            break;
        }
    }
    if (ans != -1) {
        ll res = 0;
        ll lf = 0;
        for (int i = 0; i <= ans; i++) {
            while (a[lf] < i){
                lf++;
            }
            res += ch(n - 1, n + i - lf - 1);
            res %= MOD;
        }
        cout << res % MOD;
    }
    else{
        ll sm = 0;
        for (int i = 0; i < n; i++){
            sm += a[i] / n;
        }
        ll res = 0;
        for (int t = 0; t < n; t++){
            if (t)
                sm -= 1;
            if (t)
                sm += kol[n - t];
            res += ch(n - 1, sm + n - 1);
            res %= MOD;
        }
        cout << res % MOD;
    }

#ifdef ONPC
    cerr << endl << "finished in " << clock() * 1.0 / CLOCKS_PER_SEC << " sec" << endl;
#endif
}
//egor lox


// [I didn't read the editorial or see any failed test cases]
// Read TODO below. Please hack this solution if possible {and this solution passes the existing tests.
// (however Codeforces doesn't support uphacking solutions on old contests)
#ifndef LOCAL
#define NDEBUG
#endif
#include<cassert>
#include<iostream>
#include<vector>
#include<queue>
#include<functional>

int const MOD=998244353;
struct modular {
	int val;
	explicit constexpr operator int() const { return val; }
	constexpr modular():val(){}
#if MODULAR_LESS_EFFICIENT_BUT_EASIER_TO_CODE
	constexpr modular(int64_t v):val(int(v%MOD)){
		if(val<0)val+=MOD;
	}
#else
	constexpr modular(int v):val(v){
		assert(0<=v and v<MOD);
	}
#endif

#define COMPAREOP(OP) bool constexpr operator OP(modular b) const { return val OP b.val; }
	COMPAREOP(==) COMPAREOP(!=) COMPAREOP(<) COMPAREOP(>) COMPAREOP(<=) COMPAREOP(>=)
#undef COMPAREOP

	modular operator-() const { return modular(val ? MOD-val : 0); }
	modular constexpr& operator+=(modular m) { if ((val += m.val) >= MOD) val -= MOD; return *this; }
	modular constexpr& operator-=(modular m) { if ((val -= m.val) < 0) val += MOD; return *this; }
	modular constexpr& operator*=(modular m) { val = int((int64_t)val*m.val%MOD); return *this; }
	modular constexpr pow(int p) const {
		modular a=*this;
		modular ans = 1; for (; p; p /= 2, a *= a) if (p&1) ans *= a;
		return ans;
	}
	modular constexpr inv() const {
		int a=val,b=MOD, ax=1,bx=0;
		while(b){
			int q=a/b, t=a%b;
			a=b; b=t;
			t=ax-bx*q; ax=bx; bx=t;
		}
		assert(a==1);
		if(ax<0)ax+=MOD;
		return ax;
	}
	modular constexpr& operator/=(modular m) { return (*this) *= m.inv(); }

#define ARITHBINARYOP(OP) friend modular constexpr operator OP(modular a, modular b) { return a OP##= b; }
	ARITHBINARYOP(+) ARITHBINARYOP(-) ARITHBINARYOP(*) ARITHBINARYOP(/)
#undef ARITHBINARYOP
};

std::vector<modular> fact{1};
modular binom(int n,int k){
	k=std::min(k,n-k);
	if(k<0)return 0;
	while(n>=(int)fact.size())
		fact.push_back(fact.back()*modular(fact.size()));
	return fact[n]/(fact[k]*fact[n-k]);
}

int main(){
	std::ios::sync_with_stdio(0);std::cin.tie(0);
	int n;std::cin>>n;

	int req=0; // number of "forced blocks"
	std::priority_queue<int,std::vector<int>,std::greater<int>> q; // next positions for increasing req

	std::vector<int> a(n);
	for(int& ai:a){
		std::cin>>ai;
		q.push(ai);
	}

	std::vector<modular> f(1,1); // [i] = number of resulting states reachable from moving i steps
	modular out=0;

	for(int i=0;;++i){
		if(i>=n and f[i]==f[i-n]) // TODO is this okay? What if f[i] - f[i-n] is some nonzero multiple of MOD?
			break;

		out+=f[i];
		if(i>=n) out-=f[i-n];

		assert(f.size()==i+1u);

		while(q.top()==i){
			q.pop();
			q.push(i+n);
			++req;
		} // TODO is the total complexity of this loop O(n)?

		if(req>i+1) break;
		f.push_back(binom(i+1-req + n-1,n-1));
	}

	std::cout<<(int)out<<'\n';
}


// High above the clouds there is a rainbow...

#include<bits/stdc++.h>

#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)

using namespace std;

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

const int maxn=1e6+10,mod=998244353;
const ll inf=1e18;

int a[maxn], n, cnt[maxn], fac[maxn], ifac[maxn];

int C(int n,int k){
    if(n<k) return 0;
    return 1ll*fac[n] *ifac[k] %mod *ifac[n-k] %mod;
}

int solve(int k){
    int ls=0, ans=1;
    for(int i=0;i<k;i++){
	ls+=cnt[i];
	ans=(ans + C(i+n-ls, n-1) ) %mod;
    }
    return ans;
}

int Pow(int a,int b){
    int ans=1;
    for(; b; b>>=1, a=1ll*a*a %mod){
	if(b&1) ans=1ll*ans*a %mod;
    }
    return ans;
}

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

    fac[0]=1;
    for(int i=1;i<maxn;i++)
	fac[i]= 1ll*i* fac[i-1] %mod;
    ifac[maxn-1]= Pow(fac[maxn-1], mod-2);
    for(int i=maxn-2;i>=0;i--)
	ifac[i]= 1ll*(i+1)* ifac[i+1] %mod;

    int sm=0; cin>>n;

    for(int i=0;i<n;i++){
	cin>>a[i];
	sm+=a[i] - (a[i]%n);
	cnt[a[i]]++;
    }
    sm/=n;

    sort(a,a+n);

    for(int i=0;i<n;i++){
	if(a[i]<i){
	    return cout<<solve(a[i])<<endl,0;
	}
    }
    memset(cnt,0,sizeof cnt);
    for(int i=0;i<n;i++){
	cnt[a[i]%n]++;
    }

    int ans=0;
    for(int i=0;i<n;i++){
	ans=(ans + C(sm+n-1,n-1)) %mod;
	sm++;
	sm-=cnt[i];
    }
    return cout<<ans<<endl,0;
}
// Deathly mistakes:
//  * Read the problem curfully.
//  * Check maxn.
//  * Overflows.

// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")


// High above the clouds there is a rainbow...

#include<bits/stdc++.h>

#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)

using namespace std;

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

const int maxn=1e6+10,mod=998244353;
const ll inf=1e18;

int a[maxn], n, cnt[maxn], fac[maxn], ifac[maxn];

int C(int n,int k){
    if(n<k) return 0;
    return 1ll*fac[n] *ifac[k] %mod *ifac[n-k] %mod;
}

int solve(int k){
    int ls=0, ans=1;
    for(int i=0;i<k;i++){
	ls+=cnt[i];
	ans=(ans + C(i+n-ls, n-1) ) %mod;
    }
    return ans;
}

int Pow(int a,int b){
    int ans=1;
    for(; b; b>>=1, a=1ll*a*a %mod){
	if(b&1) ans=1ll*ans*a %mod;
    }
    return ans;
}

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

    fac[0]=1;
    for(int i=1;i<maxn;i++)
	fac[i]= 1ll*i* fac[i-1] %mod;
    ifac[maxn-1]= Pow(fac[maxn-1], mod-2);
    for(int i=maxn-2;i>=0;i--)
	ifac[i]= 1ll*(i+1)* ifac[i+1] %mod;

    int sm=0; cin>>n;

    for(int i=0;i<n;i++){
	cin>>a[i];
	sm+=a[i] - (a[i]%n);
	cnt[a[i]%n]++;
    }
    sm/=n;

    sort(a,a+n);

    for(int i=0;i<n;i++){
	if(a[i]<i){
	    return cout<<solve(a[i])<<endl,0;
	}
    }
    int ans=0;
    for(int i=0;i<n;i++){
	ans=(ans + C(sm+n-1,n-1)) %mod;
	sm++;
	sm-=cnt[i];
    }
    return cout<<ans<<endl,0;
}
// Deathly mistakes:
//  * Read the problem curfully.
//  * Check maxn.
//  * Overflows.

// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")


#include <bits/stdc++.h>

using namespace std;

const int mod = 998244353;
const int maxc = 1000010;
const int base = 1e6+11;
const int maxk = 100010;
const int mod1 = 1145141;
const int mod2 = 1e9+9;

typedef pair<int,int> pi;

int ans = 0;
int inv[maxc], ijc[maxc], jc[maxc], pw1[maxk], pw2[maxk];
int cnt[maxc], mx = 0, v1, v2;
int k, a[maxk], cur_a[maxk];
set<pi> st;

int binom(int n, int m) {
	if (m > n) return 0;
	return 1LL * jc[n] * ijc[m] % mod * ijc[n-m] % mod;
}

struct CMP {
	bool operator()(int x, int y) {
		return cur_a[x] > cur_a[y];
	}
};

priority_queue<int, vector<int>, CMP> pq;

int main() {
	scanf("%d", &k);
	for (int i = 1; i <= k; i++) scanf("%d", &a[i]);
	pw1[0] = pw2[0] = 1;
	for (int i = 1; i <= k; i++) pw1[i] = 1LL * pw1[i-1] * base % mod1, pw2[i] = 1LL * pw2[i-1] * base % mod2;
	inv[1] = 1;
	for (int i = 2; i <= 1000000; i++) inv[i] = mod - 1LL * (mod / i) * inv[mod % i] % mod;
	jc[0] = ijc[0] = 1;
	for (int i = 1; i <= 1000000; i++) jc[i] = 1LL * jc[i-1] * i % mod, ijc[i] = 1LL * ijc[i-1] * inv[i] % mod;
	for (int i = 1; i <= k; i++) cur_a[i] = a[i];
	for (int i = 1; i <= k; i++) {
		v1 = (1LL * cur_a[i] * pw1[i] % mod1 + v1) % mod1;
		v2 = (1LL * cur_a[i] * pw2[i] % mod2 + v2) % mod2;
	}
	for (int i = 1; i <= k; i++) pq.push(i);
	int sum1 = 0, sum2 = 0;
	for (int i = 1; i <= k; i++) sum1 = (sum1 + mod1 - pw1[i]) % mod1, sum2 = (sum2 + mod2 - pw2[i]) % mod2;
	while(1) {
		cnt[mx+1] = cnt[mx];
		while (cur_a[pq.top()] - mx - 1 < 0) {
			int t = pq.top();
			pq.pop();
			++ cnt[mx+1];
			cur_a[t] += k;
			v1 = (v1 + 1LL * k * pw1[t] % mod1) % mod1;
			v2 = (v2 + 1LL * k * pw2[t] % mod2) % mod2;
			pq.push(t);
		}
		v1 = (v1 + sum1) % mod1;
		v2 = (v2 + sum2) % mod2;
		if (st.count(pi(v1, v2))) break;
		if (cnt[mx+1] > mx+1) break;
		st.insert(pi(v1, v2));
		++ mx;
	}
	for (int i = 0; i < k; i++) {
		// i + t * k <= mx
		// t * k <= mx - i
		if (i > mx) break;
		int t = (mx - i) / k;
		int x = i + t * k;
		int c = x - cnt[x];
		ans = (ans + binom(c + k - 1, k - 1)) % mod;
	}
	printf("%d\n", ans);
	return 0;
}


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

#define N 1000100
int n, a[N], b[N], fac[N], rfac[N], ri[N];
const int mod = 998244353;

inline int C(int n, int m) {
    if (n < m) return 0;
    return 1ll * rfac[m] * rfac[n-m] % mod * fac[n] % mod;
}

int main() {
    fac[0] = rfac[0] = ri[1] = 1;
    for (int i = 1; i < N; i ++) {
        fac[i] = 1ll * i * fac[i-1] % mod;
        if (i > 1) ri[i] = 1ll * (mod - mod / i) * ri[mod%i] % mod;
        rfac[i] = 1ll * ri[i] * rfac[i-1] % mod;
    }
    scanf("%d", &n);
    for (int i = 1; i <= n; i ++) scanf("%d", &a[i]);
    sort(a + 1, a + n + 1);
    int k;
    for (k = 1; k <= n; k ++) if (a[k] < k - 1) break;
    if (k <= n) {
        k --;
        int rlt = 0;
        for (int i = 0, j = 1; i < k; i ++) {
            while (a[j] < i) j ++;
            rlt += C(i - j + n, n - 1);
            if (rlt >= mod) rlt -= mod;
        }
        printf("%d\n", rlt);
    }
    else {
        int sum = 0, rlt = 0;
        for (int i = 1; i <= n; i ++) b[a[i]%n] ++, sum += a[i] / n;
        for (int i = 0; i < n; i ++) {
            rlt += C(sum + n - 1, n - 1);
            if (rlt >= mod) rlt -= mod;
            sum += 1 - b[i];
        }
        printf("%d\n", rlt);
    }
}


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

#define N 100100
int n, a[N], b[N], fac[N], rfac[N], ri[N];
const int mod = 998244353;

inline int C(int n, int m) {
    if (n < m) return 0;
    return 1ll * rfac[m] * rfac[n-m] % mod * fac[n] % mod;
}

int main() {
    fac[0] = rfac[0] = ri[1] = 1;
    for (int i = 1; i < N; i ++) {
        fac[i] = 1ll * i * fac[i-1] % mod;
        if (i > 1) ri[i] = 1ll * (mod - mod / i) * ri[mod%i] % mod;
        rfac[i] = 1ll * ri[i] * rfac[i-1] % mod;
    }
    scanf("%d", &n);
    for (int i = 1; i <= n; i ++) scanf("%d", &a[i]);
    sort(a + 1, a + n + 1);
    int k;
    for (k = 1; k <= n; k ++) if (a[k] < k - 1) break;
    if (k <= n) {
        k --;
        int rlt = 0;
        for (int i = 0, j = 1; i < k; i ++) {
            while (a[j] < i) j ++;
            rlt += C(i - j + n, n - 1);
            if (rlt >= mod) rlt -= mod;
        }
        printf("%d\n", rlt);
    }
    else {
        int sum = 0, rlt = 0;
        for (int i = 1; i <= n; i ++) b[a[i]%n] ++, sum += a[i] / n;
        for (int i = 0; i < n; i ++) {
            rlt += C(sum + n - 1, n - 1);
            if (rlt >= mod) rlt -= mod;
            sum += 1 - b[i];
        }
        printf("%d\n", rlt);
    }
}