import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { public static long pow(long n, long p, long m) { long result = 1; if (p == 0) return 1; if (p == 1) return n; while (p != 0) { if (p % 2 == 1) result *= n; if (result >= m) result %= m; p >>= 1; n *= n; if (n >= m) n %= m; } return result; } public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int mod = (int) 1e9+7; int[] m = new int[n]; for(int m_i=0; m_i < n; m_i++){ m[m_i] = in.nextInt(); } int prev = m[0]; boolean rflag = true; boolean fflag = true; for(int m_i=1; m_i < n; m_i++){ rflag = rflag&&(prev > m[m_i]); fflag = fflag&&(prev < m[m_i]); prev = m[m_i]; } long ans=0; if(fflag){ while(n>0){ ans+=pow(2,n-1,mod); ans%=mod; n-=3; } } if(rflag) ans=1; System.out.println(ans); // your code goes here } }