solve length for duplicated case