#include<iostream>
using namespace std;
int a[100000];
int main() {
int n;
cin >> n;
int sum = 0;
for (int i = 0;i < n;i++)
{
cin >> a[i];
sum += a[i];
}
int mod = 0;
int out = 0;
int sum2=0;
if (sum <= 9 && sum >= 0) {
cout << sum;
return 0;
}
for (int i = 0;i <1e18;i++) {
if (sum <= 9 && sum >= 0) {
if (sum2+sum <= 9 && sum2+sum >= 0) {
out = mod + sum;
mod = 0;
sum = 0;
sum2 = 0;
break;
}
if (sum == 0) {
sum = sum2;
sum2 = 0;
mod = 0;
}
}
mod += sum %10;
sum2 = mod;
sum = sum / 10;
}
cout << out;
}
Copy