public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine().trim());
StringTokenizer st = new StringTokenizer(br.readLine().trim());
int[] lastPosition = new int[100001];
long sum = 0;
int start = 0;
for (int i = 1; i <= n; i++) {
int num = Integer.parseInt(st.nextToken());
if (start < lastPosition[num]) {
start = lastPosition[num];
}
lastPosition[num] = i;
sum += (i - start);
}
System.out.println(sum);
}
출처:https://www.acmicpc.net/problem/13144