using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication70
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string[] s = Console.ReadLine().Split();
            char[] a = new char[n];
            long b = 1;
            int d = 1;
            for (int i = 0; i < n; i++)
            {
                a[i] = char.Parse(s[i]);
            }
            char p = a[0];
            for(int i = 1; i<n; i++)
            {
                if(a[i]==p)
                {
                    d++;
                }
                else
                {
                    if(a[i]>p)
                    {
                        b *= d;
                        d = 1;
                    }
                }
            }
            Console.WriteLine(b % 1000000007);
        }
    }
}