Put all obtained palindromes in a hash map to find only distinct palindromess
m [ string ( 1 , s [ 0 ] ) ] = 1 ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 0 ; j <= 1 ; j ++ ) for ( int rp = R [ j ] [ i ] ; rp > 0 ; rp -- ) m [ s . substr ( i - rp - 1 , 2 * rp + j ) ] = 1 ; m [ string ( 1 , s [ i ] ) ] = 1 ; }