#include using namespace std; using ll = long long; #define rep(i, s, e) for (int i = (int)s; i < (int)e; ++i) #define all(a) (a).begin(), (a).end() int main() { cin.tie(nullptr); int N; cin >> N; vector cnt(9, 0); rep(i, 0, N) { int A; cin >> A; cnt[A]++; } ll ans = 0; rep(ii, 1, 9) { ll i = (ll)ii; ll fac = i; rep(j, 1, 9) { ans += fac * cnt[j] * cnt[i]; fac *= i; } } cout << ans << '\n'; }