提交时间:2023-08-14 12:38:23
运行 ID: 98233
#include <iostream> #include <cstdio> using namespace std; typedef long long i64; const i64 SIZE = 5e5+5; int n, m; i64 a[SIZE]; int f(i64 x) { int ret = 0; while (x) { ret += x % 10; x /= 10; } return ret; } namespace o3 { using :: n; using :: m; using :: a; int main() { int sum1 = 0, sum2 = 0, k = 0; for (int i = 1; i <= n; ++i) { if (a[i] >= 5) sum2 += a[i] - 5, ++k; sum1 += a[i]; } int ans = k * k; for (int i = 1; i <= n; ++i) { if (a[i] >= 5) { ans += sum2 + k * (a[i] - 5) + sum1 - (sum2 + k * 5) + n * a[i]; } else { ans += a[i] * n + sum1; } } printf("%d\n",ans); return 0; } } int main() { #ifdef fio freopen("../test.in","r",stdin); #endif cin >> n; bool fgb = true, fga = true; for (int i = 1; i <= n; ++i) { scanf("%lld",a+i); i64 cp = a[i]; while (cp) { if (cp % 10 > 4) fgb = false; cp /= 10; } } if (n <= 5e3) { puts("1"); } else if (fgb) { int sum = 0; for (int i = 1; i <= n; ++i) { sum += f(a[i]); } printf("%d\n",2 * n * sum); } else if (fga) { return o3::main(); } return 0; }