Odd One Subsequence

AtCoder
IDabc429_c
Time2000ms
Memory256MB
Difficulty
You are given an integer sequence of length $N$, $A=(A_1,A_2,\ldots,A_N)$. Find the number of triples of integers $(i,j,k)$ satisfying $1\leq i<j<k\leq N$ that satisfy the following condition: > Exactly two distinct values are contained in $A_i,A_j,A_k$. That is, two of $A_i,A_j,A_k$ are equal, and the remaining one is different. ## Constraints * $3 \leq N \leq 2\times 10^5$ * $1 \leq A_i \leq N$ * All input values are integers. ## Input The input is given from Standard Input in the following format: $N$ $A_1$ $A_2$ $\ldots$ $A_N$ [samples]
Samples
Input #1
5
3 2 5 2 2
Output #1
6

For example, $(i,j,k)=(1,2,4)$ satisfies the condition because exactly two distinct values, $2$ and $3$, are contained in $A_1=3$, $A_2=2$, and $A_4=2$.  
Including this, the six triples $(i,j,k)=(1,2,4),(1,2,5),(1,4,5),(2,3,4),(2,3,5),(3,4,5)$ satisfy the condition.  
Therefore, print $6$.
Input #2
3
1 1 1
Output #2
0

There may be no triples that satisfy the condition.
API Response (JSON)
{
  "problem": {
    "name": "Odd One Subsequence",
    "description": {
      "content": "You are given an integer sequence of length $N$, $A=(A_1,A_2,\\ldots,A_N)$.   Find the number of triples of integers $(i,j,k)$ satisfying $1\\leq i<j<k\\leq N$ that satisfy the following condition: > Ex",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "abc429_c"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You are given an integer sequence of length $N$, $A=(A_1,A_2,\\ldots,A_N)$.  \nFind the number of triples of integers $(i,j,k)$ satisfying $1\\leq i<j<k\\leq N$ that satisfy the following condition:\n\n> Ex...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments