# AtCoder Grand Contest 005

URL: https://atcoder.jp/contests/agc005/ (opens new window)

# A

x = gets.chomp

# 最終形は T...TS...S になる
s_count = 0
t_count = 0
x.each_char do |c|
  if c == "T"
    if s_count > 0
      # STで相殺
      s_count -= 1
    else
      t_count += 1
    end
  else
    s_count += 1
  end
end

# TとSの個数は同じ
puts t_count * 2
Last Updated: 2020/08/10 21:46