-
-
Save aiwas/73b90431bccfa6150ca0f694e217fecd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
class Program { | |
static void Main() { | |
int n = int.Parse(Console.ReadLine()); | |
int[] a = Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray(); | |
var d = new Dictionary<int, int>(); | |
foreach (int ax in a) { | |
if (d.ContainsKey(ax)) { | |
d[ax] += 1; | |
} else { | |
d.Add(ax, 1); | |
} | |
} | |
long dup = 0; | |
foreach ((_, int count) in d) { | |
if (count > 1) { | |
dup += (count * (count - 1) / 2); | |
} | |
} | |
long all = n * (n - 1) / 2; | |
Console.WriteLine(all - dup); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
7/14しか通らないが原因がわからない