Source Code
#include<iostream>
#include<math.h>
using namespace std ;
int main()
{
  long long n ;
  bool of =0;
  cin>>n ;
  long long num[n], sum =0 ;
  for(long long i= 0 ; i<n ;i++)
  {

      cin>>num[i];
      long long r = pow (10,9);
      if((num[i] % r)==1) of=1;
      sum+=num[i];
  }
  long long sum2=0;
  long long temp=0;

if(sum <= 9)cout<<sum;

else
{
 
    if(of== 1)sum2=1;
  while(1)
  {
      temp=sum%10;
      sum=sum/10;
      sum2=sum2+temp;
     
      if(sum==0)
      {
          if(sum2>=0 && sum2<=9)
          {
              cout<<sum2<<endl;
              return 0;
          }
          sum=sum2;
          sum2=0;
      }
  }
}


}
Copy
The Tale of a Generous Prince Joud
GNU G++17
58 ms
1.5 MB
Wrong Answer