I am converting letters in a string to their corresponding numbers and printing YES if the result is divisible by 6 or NO. For eg, ab is 12 and will give YES. The program is working fine for small strings but gives wrong answer for very long inputs. I tried to change the datatype for integers to long but nothing changed.
The test case for which it did not work: here#1
Edit: Input restrictions allow only lowercase characters 'a' to 'i' Original problem link: https://www.hackerearth.com/problem/algorithm/encoded-strings-3/
str = raw_input()
n = len(str)
value = 0L
str = str[::-1]
for i in arange(n):
value = value*1L + (10L**i)*(ord(str[i])-96)
if value%6 == 0:
print "YES"
else:
print "NO"