using System.Collections.Generic;
public static void Main()
int [] A = new int[6] { 1, 2, 3, 5, 2, 5};
Dictionary<int, KeyValuePair<int, int>> dic = new Dictionary<int, KeyValuePair<int, int>>();
for (int i = 0; i < A.Length; i++)
if (!dic.ContainsKey(A[i]))
dic.Add(A[i], new KeyValuePair<int, int>(0,0));
KeyValuePair<int,int> valDic = dic[A[i]];
KeyValuePair<int, int> newVal;
newVal = new KeyValuePair<int, int>(1, 1);
int preIdenticalPair = valDic.Value;
int preReptation = valDic.Key;
int newRepetation = ++preReptation;
int newIdenticalPair = preIdenticalPair + newRepetation;
newVal = new KeyValuePair<int, int>(newRepetation, newIdenticalPair);
foreach (KeyValuePair<int, KeyValuePair<int, int>> pair in dic)
identical += pair.Value.Value;
Console.WriteLine(identical);