import sys import numpy as np input = sys.stdin.readline def read_values(): return map(int, input().split()) def read_index(): return map(lambda x: int(x) - 1, input().split()) def read_list(): return list(read_values()) def read_lists(N): return [read_list() for _ in range(N)] mod=998244353 def main(): n=int(input()) a=read_list() na=np.array([a],dtype=object) ta=na.T aa=na-ta ans=1 for i in range(n): aa[i][i]=1 ans*=aa[i].prod() ans%=mod if ans==0: print(0) return if n%4==2 or n%4==1: ans=mod-ans s=set() now=1 for i in range(40000): s.add(now) now*=3 now%=mod p=0 rev=pow(now,-1,mod) rev3=pow(3,-1,mod) while not ans in s: p+=40000 ans*=rev ans%=mod while ans>1: p+=1 ans*=rev3 ans%=mod if p%2: p=(p+mod)//2 else: p=p//2 print(pow(3,p,mod)) if __name__ == "__main__": main()