#include<cstdio> #include<algorithm> #include<vector> #include<cstring> #include<stack> using namespace std; #define maxn 100000 + 10 #define modu 1000000007 #define INF 2000000000 vector<int> G[maxn], G2[maxn]; vector<int> S; int vis[maxn], sccno[maxn], scc_cnt; int val[maxn]; int num[maxn],ans[maxn]; int max(int a,int b) { if(a>b) return a; else return b; } void dfs1(int u) { if(vis[u]) return; vis[u] = 1; for(int i = 0; i < G[u].size(); i++) dfs1(G[u][i]); S.push_back(u); } void dfs2(int u) { if(sccno[u]) return; sccno[u] = scc_cnt; for(int i = 0; i < G2[u].size(); i++) dfs2(G2[u][i]); } void find_scc(int n) { int i; scc_cnt = 0; S.clear(); memset(sccno, 0, sizeof(sccno)); memset(vis, 0, sizeof(vis)); for(i = 0; i < n; i++) dfs1(i); for(i = n-1; i >= 0; i--) if(!sccno[S[i]]) { scc_cnt++; dfs2(S[i]); } } int main() { int i,j,n,m; int x,y; __int64 way=1; __int64 sum=0; scanf("%d",&n); for(i=0;i<n;i++) scanf("%d",&val[i]); for(i=0;i<n;i++) { G[i].clear(); G2[i].clear(); } scanf("%d",&m); for(i=1;i<=m;i++) { scanf("%d%d",&x,&y); x--;y--; G[x].push_back(y); G2[y].push_back(x); } find_scc(n); memset(num,0,sizeof(num)); for(i=1;i<=scc_cnt;i++) ans[i]=INF; for(i=0;i<n;i++) { if(val[i]==ans[ sccno[i] ]) num[ sccno[i] ]+=1; else if(val[i]<ans[ sccno[i] ]) { num[ sccno[i] ]=1; ans[ sccno[i] ]=val[i]; } } //printf("%d ",scc_cnt); for(i=1;i<=scc_cnt;i++) { sum+=ans[i]; way=(way*num[i])%modu; } printf("%I64d %I64d ",sum,way); return 0; }