# frozen_string_literal: true C = 100_000 def solve c = Array.new(2 * C, [nil, nil]) c[C] = [C-1, C-1] d = C S.each_with_index do |s, i| s ? (d += 1) : (d -= 1) #pp d if c[d][0].nil? c[d] = [C + i, C + i] else c[d][1] = C + i end end #pp c.select{_1&&_2} c.select { _1 && _2 }.map { (_1 - _2).abs }.max end S = gets.chomp.chars.map { _1 == 'A' } puts solve