s = 'CDEFGABC' S = gets.chomp list = [] s.each_char do |c| list << c if %w(A C D F G).include?(c) list << c + '#' end end idx = list.index(S) puts list[idx + 1]