Problem p02629 (python)

Fixed submission:
import sys                                                                                                                                                                                                  
                                                                                                                                                                                                            
l = sys.stdin.readline().rstrip('\n').split(' ')                                                                                                                                                            
N = int(l[0])                                                                                                                                                                                               
                                                                                                                                                                                                            
digits = 1                                                                                                                                                                                                  
                                                                                                                                                                                                            
while True:                                                                                                                                                                                                 
    ub = 26 ** digits                                                                                                                                                                                       
    if N <= ub:                                                                                                                                                                                             
        break                                                                                                                                                                                               
    N -= ub                                                                                                                                                                                                 
    digits += 1                                                                                                                                                                                             
                                                                                                                                                                                                            
ans = ''                                                                                                                                                                                                    
N -= 1                                                                                                                                                                                                      
                                                                                                                                                                                                            
for pos in range(digits):                                                                                                                                                                                   
    offset = N % 26                                                                                                                                                                                         
    digit = chr(ord('a') + offset)                                                                                                                                                                          
    ans = digit + ans                                                                                                                                                                                       
    N //= 26                                                                                                                                                                                                
                                                                                                                                                                                                            
print(ans)

Buggy submission (verdict: Runtime Error):
import sys

l = sys.stdin.readline().rstrip('\n').split(' ')
N = int(l[0])

digits = 1

while True:
    ub = 26 ** digits
    if N <= ub:
        break
    N -= ub
    digits += 1

ans = ''
N -= 1

for pos in range(digits):
    offset = N % 26
    digit = chr(ord('a') + offset)
    ans = digit + ans
    N /= 26

print(ans)