function main() n, x, y = int(inputs()) wantA = zeros(Int, x + y) wantB = zeros(Int, x + y) for i = 1:n p, c = inputs() if c == "A" wantA[(i-1)%(x+y)+1] += int(p) else wantB[(i-1)%(x+y)+1] += int(p) end end ans = 0 tmp = [(abs(wantA[i] - wantB[i]), i) for i = 1:x+y] sort!(tmp, by=x -> x[1], rev=true) ischecked = falses(x + y) for (_, group) = tmp if ischecked[group] continue end ischecked[group] = true if wantA[group] > wantB[group] if x > 0 ans += wantA[group] x -= 1 else ans += wantB[group] y -= 1 end else if y > 0 ans += wantB[group] y -= 1 else ans += wantA[group] x -= 1 end end end println(ans) end # --------input func---------- input() = readline() inputs() = split(readline()) int(s::AbstractChar) = parse(Int, s) int(s::AbstractString) = parse(Int, s) int(v::AbstractArray) = map(x -> parse(Int, x), v) debug(x...) = println(stderr, x...) if abspath(PROGRAM_FILE) == @__FILE__ main() else mystdin = joinpath(abspath(@__DIR__), "myinput.txt") mystdout = stdout redirect_stdio(stdin=mystdin, stdout=mystdout) do main() end end