data Tree = NilNode | Node Integer Tree Tree segWidth = 2 ^ 17 segVal NilNode = 0 segVal (Node val _ _) = val segUpdate = f 0 segWidth where f l r k v NilNode = f l r k v (Node 0 NilNode NilNode) f l r k v (Node val left right) | r - l == 1 = Node (val + v) NilNode NilNode | otherwise = let mid = (l + r) `quot` 2 in if k < mid then let newLeft = f l mid k v left in Node (segVal newLeft + segVal right) newLeft right else let newRight = f mid r k v right in Node (segVal left + segVal newRight) left newRight segQuery = f 0 segWidth where n = 2 ^ 17 f l r a b NilNode = 0 f l r a b (Node val left right) | r <= a || b <= l = 0 | a <= l && r <= b = val | otherwise = let mid = (l + r) `quot` 2 vl = f l mid a b left vr = f mid r a b right in vl + vr main = getLine >>= print . solve solve = fst . foldr f (0, NilNode) . flip zip [0..] where f (v, i) (s, tree) | v == 'c' = let num = segQuery (i + 1) segWidth tree in (s + num * (num - 1) `quot` 2, tree) | v == 'w' = (s, segUpdate i 1 tree) | otherwise = (s, tree)