제출 #9429

#제출 시각아이디문제언어결과실행 시간메모리
9429maniacUniting (kriii2_U)C++98
0 / 4
0 ms1676 KiB
#include<cstdio>
#include<cassert>
#include<cstring>
#include<map>
#include<set>
#include<time.h>
#include<algorithm>
#include<stack>
#include<queue>
#include<utility>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<limits>
   
using namespace std;
#define LL long long 
#define mod 1000000007
LL n,re,cnt;
queue <LL> q;

long long gcd( long long b, long long s ){
	return (s!=0) ? gcd( s, b%s ) : b;
}


void solve(){
	scanf("%lld",&n);
	cnt = 1;
	for(LL i = 1; i <= n; i++){
		cnt *=i;
		cnt %= mod;
		LL a ;
		scanf("%lld",&a);
		q.push(a);
	}
	if( n == 1){
		re = 0;
		cnt = 1;
		printf("%lld\n%lld\n",re,cnt);
		return ;
	}

	while( !q.empty() ){
		LL a,b;
		a = q.front(); q.pop();
		b = q.front(); q.pop();
		re += (a*b)%mod;
		re%=mod;
		if( !q.empty() )
			q.push( (a+b)%mod);
	}
	printf("%lld\n%lld\n",re,cnt);
}

int main(){
	//freopen("in.txt", "r", stdin);
	//freopen("input.txt", "r", stdin);
	solve();

}
#Verdict Execution timeMemoryGrader output
Fetching results...