Imperative & procedural programming: statements, loops, mutation, procedures
#C++ began as procedural C and still compiles straight-line loops over contiguous data to very fast code, which is why imperative style dominates performance-sensitive work. Range-based for, structured bindings and std::map::operator[] keep the procedural version short.
Complete program
Complete program.
In practice: pass inputs by const reference and return results by value (the compiler moves or elides the copy); keep mutable variables local; prefer a named function or a standard algorithm to a long block of loose statements.
map::operator[] inserts a value-initialised element for a missing key, which is what an accumulator wants and a surprise in a plain lookup (use find or contains there).
std::map keeps keys sorted; std::unordered_map is faster for large inputs but iterates in an unspecified order.