program main character(100)::SA,SB character(10000)::PA,PB character::XA,XB integer::i,len_pa,len_pb read *, SA, PA, XA read *, SB, PB, XB len_pa = len_trim(PA) len_pb = len_trim(PB) if (len_pa.gt.len_pb) then print '(a)', trim(SA) return else if (len_pa.lt.len_pb) then print '(a)', trim(SB) return end if do i=len_pa,1,-1 if (PA(i:i).gt.PB(i:i)) then print '(a)', trim(SA) return else if (PA(i:i).lt.PB(i:i)) then print '(a)', trim(SB) return end if end do print '(a)',"-1" end program main