removed +1 in 'len(A)+1' when defining for loop