n = gets.to_i
a = gets.chomp.split("")

opt = 0

k = 0
inum = a.count(?I)
a.each do |c|
    if c == ?O
        k += inum
    elsif c == ?I
        inum -= 1
    end
end
opt = k if k > opt

k = 0
jnum = a.count(?J)
a.reverse.each do |c|
    if c == ?O
        k += jnum
    elsif c == ?J
        jnum -= 1
    end
end
opt = k if k > opt

inum = a.count(?I)
jnum = 0
a.each do |c|
    if c == ?J
        jnum += 1
    elsif c == ?I
        inum -= 1
    end
    k = jnum * inum
    opt = k if k > opt
end

h = {:_ => 1, :J => 0, :O => 0, :I => 0}
a.each do |c|
    new_h = h.dup
    case c
    when ?J then new_h[:J] += h[:_]
    when ?O then new_h[:O] += h[:J]
    when ?I then new_h[:I] += h[:O]
    end
    h = new_h
end
p opt + h[:I]

