In C++ we have map. In C# the equivalent of map is Dictionary. However it's not sorted. So we use SortedDictionary instead. Following is an example of mapping. using System; using System.Collections.Generic; namespace PracticeApp { class Program { static void Main(string[] args) { var s = Console.ReadLine()?.Split('+'); var myDictionary = new SortedDictionary<int, int>(); foreach (var item in s) { int a = int.Parse(item); myDictionary.TryGetValue(a, out var x); myDictionary[a] = x + 1; } ...