import java.util.Scanner; /** * Created by naum_ on 18-Feb-17. */ public class Solution { public static void main(String[] args) { 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(); } System.out.println(count(m,1)); } public static int count(int[] m,int pos){ int current = m[m.length - pos]; int l = 1; int count = 1; for (int i = pos + 1; i <= m.length; i++) { if (m[m.length - i] <= current) { l++; current = m[m.length - i]; count += count(m, i + 1, l); } else break; } return count; } public static int count(int[] m,int pos,int countArrays){ if (countArrays == 1) return 1; if (pos > m.length) return 1; int current = m[m.length - pos]; int l = 1; int count = countArrays; for (int i = pos + 1; i <= m.length; i++) { if (m[m.length - i] <= current) { l++; current = m[m.length - i]; int mult = 1; for (int j = 0; j < l; j++) { mult *= countArrays - j; } count += mult * count(m, i + 1, l); if (l == countArrays) break; } else break; } return count; } }