#!/bin/python import sys import itertools import itertools n = int(raw_input().strip()) m = map(int, raw_input().strip().split(' ')) # your code goes here def get_array_combinations(n, m): arrays = [] for l in range(1, n + 1): for subset in itertools.combinations(m, l): arrays.append(list(subset)) # print arrays combs = [] for l in range(1, n + 1): # print l for subset in itertools.combinations(arrays, l): combs.append(list(subset)) # print list(subset) return combs def test_array(array): m = [] i = 0 coll = [] max_elem_len = len(max(array, key=len)) while i < max_elem_len: tmp = [] for a in array: a_len = len(a) if i < a_len: tmp.append(a[i]) coll.append(tmp) i += 1 for c in coll: c.sort() m += c # print 'c =', coll # print 'm =', m return m def my_main(m, n): combs = get_array_combinations(n, m) # t_arr = [[3, 5], [1], [2, 4]] # t_arr = [[2,1]] i = 0 for c in combs: m_test = test_array(c) if m_test == m: i += 1 print i % 1000000007 my_main(m, n)