Problem p02588 (python)

Fixed submission:
import sys
import math
import bisect

def query_value(s):
    #print('s: %s' % s)
    pos = s.find('.')
    if (pos == -1):
        return int(s) * 10 ** 9
    ans = int(s[:pos])
    #print('ans: %d' % ans)
    for i in range(pos + 1, pos + 10):
        #print('i: %d' % i)
        #print('len(%s): %d' % (s, len(s)))
        if i >= len(s):
            ans *= 10
        else:
            #print('s[%d] = %s' % (i, s[i]))
            ans = ans * 10 + ord(s[i]) - ord('0')
            #ans *= 10
    return ans

def main():
    n = 18
    A = []
    for i in range(2*n):
        A.append([0] * (2*n))
    #print('A: %s' % str(A))
    for _ in range(int(input())):
        a = query_value(input())
        #print('a: %d' % a)
        p2 = 0
        p5 = 0
        while a % 2 == 0:
            p2 += 1
            a /= 2
        while a % 5 == 0:
            p5 += 1
            a /= 5
        A[p2][p5] += 1
        #print('p2: %d, p5: %d' % (p2, p5))
    ans = 0
    for x1 in range(2*n):
        for y1 in range(2*n):
            for x2 in range(2*n):
                for y2 in range(2*n):
                    if x1 == x2 and y1 == y2:
                        if A[x1][y1] > 0 and x1 + x2 >= n and y1 + y2 >= n:
                            #print('A[%d][%d]: %d, A[%d][%d]: %d' % (x1, y1, A[x1][y1], x2, y2, A[x2][y2]))
                            ans += A[x1][y1] * (A[x2][y2] - 1)
                            #print('ans: %d' % ans)
                    else:
                        if A[x1][y1] > 0 and A[x2][y2] > 0 and x1 + x2 >= n and y1 + y2 >= n:
                            #print('A[%d][%d]: %d, A[%d][%d]: %d' % (x1, y1, A[x1][y1], x2, y2, A[x2][y2]))
                            ans += A[x1][y1] * A[x2][y2]
                            #print('ans: %d' % ans)
    ans //= 2
    print(ans)
    '''
    for i in range(n):
        print('A[%d]: %s' % (i, str(A[i])))
    '''

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys
import math
import bisect

def query_value(s):
    #print('s: %s' % s)
    pos = s.find('.')
    if (pos == -1):
        return int(s) * 10 ** 9
    ans = int(s[:pos])
    #print('ans: %d' % ans)
    for i in range(pos + 1, pos + 10):
        #print('i: %d' % i)
        #print('len(%s): %d' % (s, len(s)))
        if i >= len(s):
            ans *= 10
        else:
            #print('s[%d] = %s' % (i, s[i]))
            ans = ans * 10 + ord(s[i]) - ord('0')
            #ans *= 10
    return ans

def main():
    n = 18
    A = []
    for i in range(n):
        A.append([0] * n)
    #print('A: %s' % str(A))
    for _ in range(int(input())):
        a = query_value(input())
        #print('a: %d' % a)
        p2 = 0
        p5 = 0
        while a % 2 == 0:
            p2 += 1
            a /= 2
        while a % 5 == 0:
            p5 += 1
            a /= 5
        A[p2][p5] += 1
        #print('p2: %d, p5: %d' % (p2, p5))
    ans = 0
    for x1 in range(n):
        for y1 in range(n):
            for x2 in range(n):
                for y2 in range(n):
                    if x1 == x2 and y1 == y2:
                        if A[x1][y1] > 0 and x1 + x2 >= n and y1 + y2 >= n:
                            #print('A[%d][%d]: %d, A[%d][%d]: %d' % (x1, y1, A[x1][y1], x2, y2, A[x2][y2]))
                            ans += A[x1][y1] * (A[x2][y2] - 1)
                            #print('ans: %d' % ans)
                    else:
                        if A[x1][y1] > 0 and A[x2][y2] > 0 and x1 + x2 >= n and y1 + y2 >= n:
                            #print('A[%d][%d]: %d, A[%d][%d]: %d' % (x1, y1, A[x1][y1], x2, y2, A[x2][y2]))
                            ans += A[x1][y1] * A[x2][y2]
                            #print('ans: %d' % ans)
    ans //= 2
    print(ans)
    '''
    for i in range(n):
        print('A[%d]: %s' % (i, str(A[i])))
    '''

if __name__ == "__main__":
    main()