using System; using System.Collections.Generic; using System.Linq; public class Program { static void Main(string[] args) { var countInput = Console.ReadLine(); if(!int.TryParse(countInput, out int count)) return; var dic = new Dictionary<int, int>(); while(count > 0) { var str = Console.ReadLine(); var strArray = str.Split(" "); var key = int.Parse(strArray[0]); var value = Convert.ToInt32(strArray[1]); if(dic.ContainsKey(key)) { dic[key] += value; } else dic.Add(key, value); --count; } dic = dic.OrderBy(k => k.Key).ToDictionary(x => x.Key, x => x.Value); //dic = (from objDic in dic orderby objDic.Key ascending select objDic).ToDictionary(x=>x.Key, y=>y.Value); foreach(var item in dic) { Console.Write(item.Key); Console.WriteLine(" " + item.Value); } } }