Problem:
Score : 100 points

Problem Statement

This contest is CODEFESTIVAL, which can be shortened to the string CF by deleting some characters.

Mr. Takahashi, full of curiosity, wondered if he could obtain CF from other strings in the same way.

You are given a string s consisting of uppercase English letters.
Determine whether the string CF can be obtained from the string s by deleting some characters.

Constraints

2 ≤ |s| ≤ 100

All characters in s are uppercase English letters (A-Z).

Input

The input is given from Standard Input in the following format:

s

Output

Print Yes if the string CF can be obtained from the string s by deleting some characters.
Otherwise print No.

Sample Input 1

CODEFESTIVAL

Sample Output 1

Yes

CF is obtained by deleting characters other than the first character C and the fifth character F.

Sample Input 2

FESTIVALCODE

Sample Output 2

No

FC can be obtained but CF cannot be obtained because you cannot change the order of the characters.

Sample Input 3

CF

Sample Output 3

Yes

It is also possible not to delete any characters.

Sample Input 4

FCF

Sample Output 4

Yes

CF is obtained by deleting the first character.

Solution in Ruby (2.3.3) (judge verdict: Runtime Error)

def cost(c, j)
  cost = 0
  c.size.times do |i|
    next if c[i][j] =='0'

    (j-1).downto(0) do |jj|
      if c[i][jj] == c[i][j]
        cost += 1
      else
        break
      end
    end

    (j+1).upto(c[i].size-1) do |jj|
      if c[i][jj] == c[i][j]
        cost += 1
      else
        break
      end
    end
  end

  (c.size-1).downto(1) do |i|
    c[i][j] = c[i-1][j]
  end

  c[0][j] = '0'
  cost
end

def min_cost(c, hash)
  key = c.join('.')
  return hash[key] if hash[key]

  costs = []
  c[0].size.times do |j|
    next if c.all? { |e| e[j] == '0' }
    c_clone = Marshal.load(Marshal.dump(c))
    j_cost = cost(c_clone, j)
    next if costs.min && j_cost >= costs.min
    
    costs.push (j_cost + min_cost(c_clone, hash))
  end

  hash[key] = costs.min || 0
end

H, W = gets.split.map(&:to_i)

c = Array.new(H)

H.times do |h|
  c[h] = gets.chomp
end

puts min_cost(c, {})