#include using namespace std; using ll = long long; int main(){ ios::sync_with_stdio(false); cin.tie(0); int n; ll ans = 0; cin >> n; vector a(n), cnt(9); for(int i = 0; i < n; i++){ cin >> a[i]; cnt[a[i]]++; } for(int i = 1; i <= 8; i++){ ll d = 1, v = 0; for(int j = 1; j <= 8; j++){ d *= i; v += cnt[j] * d; } ans += cnt[i] * v; } cout << ans << '\n'; }