program pairpair integer::n,m,l=12,cnt=1 character(1),dimension(13)::a character(13)::S character(10)::Imp='Impossible' read *,S do n=1,13 a(n)=S(n:n) end do do n=1,13 do m=1,l if(a(n)==a(n+m)) then cnt=cnt+1 if(cnt==3) exit end if end do if(cnt==3) exit cnt=1 l=l-1 end do if(cnt==3) then print *,Imp else l=12 do n=1,13 do m=1,l if(a(n)==a(n+m)) then a(n)='#' a(n+m)='#' end if end do end do if(count(a(:)=='#')==12) then do n=1,13 if(a(n)=='#') cycle print *,a(n) end do else print *,Imp end if end if end program pairpair