#include #define REP(i,b,e) for(int i=b;i3) huge++; } if(zero) puts("-1"); else if(huge) printf("%ld\n", MOD); else{ ll ans = 1; REP(i, 0, n){ REP(j, 1, a[i]+1){ REP(k, 0, j){ ans *= a[i]; if(ans>MOD){ printf("%ld\n", MOD); return 0; } } } } printf("%ld\n", MOD%ans); } return 0; }