import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { public static void main(String[] args) throws FileNotFoundException { Scanner in = new Scanner(System.in); int n = in.nextInt(); int[] m = new int[n]; for(int m_i=0; m_i < n; m_i++){ m[m_i] = in.nextInt(); } // your code goes here Solution s = new Solution(); System.out.println(s.solve(n,m)); } long solve(int n, int[] m) { int maxV = computeMaxV(0, m); long result = 0; for(int i = 1; i <= maxV; i++){ result += solve(m, i, i); } return result; } long solve(int[] m, int i, int maxV) { if(m.length <= i) return 1; if(maxV == 1) return 1; if(lastStepCondition(m.length, i, maxV)) return computePositionPbLastStep(maxV,m.length-i); long result = 0; for(int j = 1; j <= maxV; j++){ long result1 = computePositionPb(maxV,j); result += result1 * solve(m, i+j, j); } return result; } boolean lastStepCondition(int length, int i, int maxV) { return length - i - maxV <= 0; } long computePositionPb(int maxV, int j) { long result = 1; for(int i = 1, maxVRemain = maxV; i <= j; i++, maxVRemain--){ result *= maxVRemain; } return result; } long computePositionPbLastStep(int maxV, int j) { return (long) Math.pow(maxV,j); } int computeMaxV(int i, int[] m) { if(i>= m.length)return 1; int result = 1; int max = m[i]; i++; for(; i max)result++; } return result; } }