0) { depth_picker($arrcopy, $temp_string . $elem[0], $collect); } else { $collect []= $temp_string . $elem[0]; } } } function doTwo($string, $from, $to) { if ($from == $to) { return 1; } if ($from - $to == 1) { if ($string[$to] == $string[$from]) { return 3; } return 2; } $substr = substr($string, $from, $to-$from+1); $nr = strlen($substr); $array = str_split($substr); $total = strlen($substr); $collect = array(); depth_picker($array, "", $collect); //print_r($collect); $c = array_unique($collect); //print_r($c); foreach ($c as $str) { if (strlen($str) == 1) continue; if ($str == strrev($str)) { $total ++; //echo "\ntook $str"; } } return $total; } $line = array_map('intval', explode(' ', trim(fgets($ffffff)))); $n = $line[0]; $q = $line[1]; $currentString = trim(fgets($ffffff)); for ($ii=1; $ii<=$q; $ii++) { $cline = array_map('intval', explode(' ', trim(fgets($ffffff)))); $op = $cline[0]; $line = $cline; if ($op == 1) { $from = $line[1]; $to = $line[2]; $do = $line[3]; $currentString = doOne($currentString, $from, $to, $do); } if ($op == 2) { $from = $line[1]; $to = $line[2]; echo doTwo($currentString, $from, $to) . "\n"; } } function doOne($string, $from, $to, $do) { $letters = []; for ($i='a'; $i<='z'; $i++) { if (strlen($i)==1) { $letters[] = $i; } } $inv = array_combine(array_values($letters), array_keys($letters)); for ($i=$from; $i<=$to; $i++) { $val = $inv[$string[$i]] + $do; $val = $val % 26; $let = $letters[$val]; $string[$i] = $let; } return $string; }