Submission #9808

#TimeUsernameProblemLanguageResultExecution timeMemory
9808kkjjkkUniting (kriii2_U)C++98
4 / 4
16 ms2456 KiB
#include <algorithm>
#include <iostream>
#include <cstdio>
using namespace std;
long long h[100005], m = 1000000007;

int main()
{
    int n;
    scanf("%d", &n);
    for(int i = 0; i < n; i++) scanf("%lld", &h[i]);
    if(n == 1) { printf("0\n"); printf("1"); }
    else if(n == 2) { printf("%lld\n", h[0] * h[1]); printf("2"); }
    else {
         long long a = h[0] + h[1];
         long long b = h[0] * h[1];
         long long c, s = 1;
         for(int i = 2; i < n; i++) {
              c = a * h[i];
              a += h[i]; b += c;
         }
         printf("%lld\n", b);
         
         for(int i = 2; i <= n; i++) { s *= ( (i % m) * ((i - 1) % m) ) % m; s %= m; }
         printf("%lld", s);
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...