#include<iostream>
#include<cstrinf>
#include<algorithm>
#define For(i,l,r) for(int i=(l);i<=(r);++i)
#define mem0(a) memset(a,0,sizeof(a))
#define int long long
using namespace std;
const int N=5e3+10,mod=998244353;
int n,a[N],k,f[N][N],g[N],tim=1,ans=0,temp[N];
void dp(){
For(i,1,n)k=max(k,min(a[i],i));
int t=a[k+1];
f[0][0]=1;
For(i,1,k)
For(j,0,t){
if(j)f[i][j]=f[i-1][j-1]*(t-j+1)%mod;
f[i][j]=(f[i][j]+f[i-1][j]*(a[i]-(t-j))%mod)%mod;
}
ans+=f[k][t];
}
signed main(){
cin>>n;
For(i,1,n){cin>>a[i];temp[i]=a[i];}
reverse(a+1,a+1+n);
dp();mem0(a);
For(i,1,temp[n])For(j,1,n)if(temp[j]>=i) a[i]++;
mem0(f);dp();
For(i,1,k)tim=tim*i%mod;
cout<<k<<" "<<(ans-tim+mod)%mod<<endl;
return 0;
}