Calculate length of String
int n = s . Length ; int [ , ] pref = new int [ 26 , n ] ; List < int > [ ] pos = new List < int > [ 26 ] ; for ( int i = 0 ; i < pos . Length ; i ++ ) pos [ i ] = new List < int > ( ) ; pref [ s [ 0 ] - ' a ' , 0 ] ++ ; pos [ s [ 0 ] - ' a ' ] . Add ( 0 ) ;