#!/bin/python3 import sys def longestSequence(a): k=[] for i in range(n): c=0 l=[] for j in range(1,a[i]): if a[i]%j==0: l.append(j) if len(l)==2: k.append(l[i]+1) if len(l)==1: k.append(1) else: t=a[i]/l[-2] m=1 while(m!=a[i]): m=m+t*2 t=t*2 k.append(m) for i in range(len(k)): return(k[i]) # Return the length of the longest possible sequence of moves. if __name__ == "__main__": n = int(input().strip()) a = list(map(int, input().strip().split(' '))) result = longestSequence(a) print(result)