#!/bin/ruby class String def palindrome? self == self.reverse end end n,q = gets.strip.split(' ') n = n.to_i q = q.to_i s = gets.strip a = 97 for a0 in (0..q-1) # your code goes here op, i, j, t = gets.split(' ') # shift r = '' if op == '1' s[i.to_i..j.to_i].each_char do |c| r += (c.ord + t.to_i).chr end s[i.to_i..j.to_i] = r #puts "R #{r} #{s}" else # subsets #puts s num = 0 for x in 1..(s.length) do aa = s[i.to_i..j.to_i].chars.combination(x).to_a aa = aa.map do |c| c.join('') end num += aa.select{|c| c.palindrome?}.length end puts num end end