Subarray with distict elements

https://ide.codingblocks.com/s/68203
test case failing

Wrong test case
5
1 2 3 4 4
your output
35
Correct output
21