static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var A = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); var dic = new ElementCounter <long>(); foreach (long n in A) { dic.Add(n); } long result = 0; foreach (long i in dic.Dic.Values) { result += i * (i - 1) / 2; } foreach (long i in A) { Console.WriteLine(result - dic[i] + 1); } }
static void Main(string[] args) { var N = long.Parse(Console.ReadLine()); var A = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); long sum = A.Sum(n => n); var counter = new ElementCounter <long>(); foreach (int a in A) { counter.Add(a); } var dic = counter.Dic; var Q = long.Parse(Console.ReadLine()); for (int i = 0; i < Q; i++) { var BC = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); var b = BC[0]; var c = BC[1]; if (dic.ContainsKey(b)) { sum += dic[b] * (c - b); if (dic.ContainsKey(c)) { dic[c] += dic[b]; dic[b] = 0; } else { dic.Add(c, dic[b]); dic[b] = 0; } } Console.WriteLine(sum); } }