> File Name: 5760.cpp
> Author: jiangyuzhu
> Mail: 834138558@qq.com
> Created Time: 2016/9/29 20:42:46
************************************************************************/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<int, int>p;
const int maxn = 5e3 + 5, mod = 1e9 + 7;
p dp[maxn][maxn];
int a[maxn], na[maxn];
int nxt[maxn][maxn], pre[maxn][maxn];
int main (void)
{
int n;
while(~scanf("%d", &n)){
for(int i = 1; i <= n; ++i) scanf("%d", &a[i]), na[i] = a[i];
memset(nxt, -1, sizeof(nxt));
memset(pre, -1, sizeof(pre));
for(int i = 1; i <= n; ++i){
dp[i][i] = p(1, 1);
for(int j = i + 1; j <= n; ++j){
dp[i][j] = p(0, 0);
}
}
sort(na + 1, na + n + 1);
int nn = unique(na + 1, na + n + 1) - (na + 1);
for(int i = 1; i <= n; ++i){
a[i] = lower_bound(na, na + nn, a[i]) - na;
}
for(int i = 0; i <= n + 1; ++i){
for(int j = i + 1; j <= n; ++j){
if(nxt[i][a[j]] == -1) nxt[i][a[j]] = j;
}
for(int j = i - 1; j >= 1; j--){
if(pre[i][a[j]] == -1) pre[i][a[j]] = j;
}
}
for(int i = n; i >= 1; --i){
p tmp = p(0, 0);
for(int j = i + 1; j <= n; ++j){
if(a[i] == a[j]){
if(tmp.first == 0) dp[i][j] = p(2, 1);
else dp[i][j] = p(tmp.first + 2, tmp.second);
}
if(a[i] >= a[j]){
int f = nxt[i][a[j]];
if(dp[f][j].first > tmp.first) tmp = dp[f][j];
else if(dp[f][j].first == tmp.first){
(tmp.second += dp[f][j].second) %= mod;
int q = pre[j][a[j]];
if(q == -1) continue;
if(dp[f][j].first == dp[f][q].first) tmp.second -= dp[f][q].second;
if(tmp.second < 0) tmp.second += mod;
}
}
}
}
p ans = p(0, 0);
for(int i = 1; i <= nn; ++i){
int aa = nxt[0][i];
int bb = pre[n + 1][i];
if(aa == -1 || bb == -1) continue;
if(dp[aa][bb].first > ans.first) ans = dp[aa][bb];
else if(dp[aa][bb].first == ans.first) (ans.second += dp[aa][bb].second) %= mod;
}
printf("%d %d\n", ans.first, ans.second);
}
return 0;
}