#include <iostream>
using namespace std;
//B SUM 44+55 = 9
long long split(long long n){
long long sum =0;
while(n>0){
sum+=n%10;
n/=10;
// cout<<" sum = "<<sum;
}
return sum;
}
int main() {
long long n;
cin>>n;
long long a[n];
long long sum=0;
for(int i=0;i<n;i++){
cin>>a[i];
if(a[i]>9){
a[i]=split(a[i]);
// cout<<a[i]<<endl;
}
sum+=a[i];
}
if(sum<9) {
cout<<sum<<endl;
return 0;
}
while(sum>9){
int sum2 = 0;
while(sum>0){
sum2+= sum%10;
sum/= 10;
}
// cout<<endl<<sum2<<" ";
sum = sum2;
}
cout<<sum<<endl;
return 0;
}
Copy