program main implicit none integer::T,len,i,j,k,m,diff,minimum character*100::S read *,T do i=1,T read *,S len = LEN_TRIM(S) minimum = 11 do j=1,len-10 do k=j+4,len-6 minimum = MIN(minimum, & hamming_dist(S(j:j+3),"good") + & hamming_dist(S(k:k+6),"problem")) end do end do print '(i0)',minimum end do contains function hamming_dist(S1,S2) result (dist) character(*)::S1,S2 integer::len,dist,i len = LEN_TRIM(S1) dist= 0 do i=1,len if(S1(i:i).ne.S2(i:i)) dist = dist + 1 end do end function hamming_dist end program main