#!/bin/python3 import itertools MOD = 10 ** 9 + 7 ''' Sherlock's Array Merging Algorithm @param V: array of vectors @return M: Sherlock's result ''' def sherlock(V): M = [] k = len(V) while (len(V) > 0): T = [] i = 1 while i <= k: if V[i] != []: el = V[i][0] V[i] = V[i][1:] T = [el] + T i += 1 T = sorted(T) while T != []: el = T[0] T = T[1:] M = [el] + M return M def solve(n, m): if m == sorted(m): return 2 ** (n - 1) % MOD return 1 n = int(input().strip()) m = list(map(int, input().strip().split(' '))) print(str(solve(n, m)))