Source Code
while True:
    n = int(input())
    if n >=1 and n<=10**5:
        break

l = (input())
l = l.split(" ")
sm = 0
flag=True
for i in range (len(l)):
    if int(l[i])>=0 and int(l[i])<=10**18:
        sm += int(l[i])
    else:
        flag=False    
if flag:
    if sm < 10:
        print (sm)
    else:
        while True:
            x = str(sm)
            sm = 0
            for i in range (len(x)):
                sm += int(x[i])
            if sm < 10:
                print (sm)
                break
Copy
The Tale of a Generous Prince massoud01
Python 3
119 ms
14.2 MB
Accepted