Source Code
#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 sum2 = 0;
	while(sum>0|| sum2>9){
		if (sum == 0) {
			sum = sum2;
			sum2 = 0;
		}
		sum2 += sum % 10;
		sum /= 10;
	}
	


	
	cout << sum2;
}
Copy
The Tale of a Generous Prince hadeelYasir
GNU G++17
19 ms
1.2 MB
Wrong Answer