I=input N=int(I()) S=I() b=c=0 for t in S: b+=t=='H' c+=t=='Q' R=int(c**0.5) T=S[:0if R<1else N//R] print([-1,T][[S,b,c]==[T*R,0,R*R]])