import sys input = sys.stdin.readline N=int(input()) A=list(map(int,input().split())) X=[0] Z=1 for i in range(1,4): Z*=i X.append(i**Z) if 0 in A: print(0) else: ANS=1 for a in A: if a>3 or ANS>10**9+7: print(10**9+7) else: ANS*=X[a] print((10**9+7)%ANS)