you give string s consist n lowercase latin letter some index string mark forbiddenyou want find string value afa maximum possible fa number occurence s occurence end nonforbidden index so example s aaaa aa index 3 forbid fa2 occurence s start index 1 2 3 start index 2 end forbid indexcalculate maximum possible value afa