Mukesh has given an array π1,π2,β¦,ππ to Mahesh. Mahesh can remove at most one subsegment from it. The remaining elements should be pairwise distinct.

In other words, at most one time Mahesh can choose two integers π and π (1β€πβ€πβ€π) and delete integers ππ,ππ+1,β¦,ππ from the array. The remaining elements should be pairwise distinct.

**Input:**
The first line contains a single integer π β the number of elements in the given array.
The next line contains π spaced integers π1,π2,β¦,ππ β the elements of the array.
**Output:**
Print the output, the minimum size of the subsegment to remove to make all elements of the array pairwise distinct. If no subsegment needs to be removed, print 0

#include <stdio.h> int compare(const void *a, const void *b) {if(*(int *)a == *(int *)b){return 1;} else{return 0;} } int main() {int n,i,j,count=0; scanf("%d",&n); int arr[n]; for(i=0;i < n;i++){ scanf("%d",&arr[i]);} for(i=0;i<n;i++){ for(j=i+1;j<n;j++){ if(compare(&arr[i],&arr[j])) count++;} } printf("%d",count); return 0; }

**INPUT_1:**

5

3 4 2 4 9

**OUTPUT:**

1

**INPUT_2:**

4

1 1 2 2

**OUTPUT:**

2

**ILLUSTRATION:**

**Morae Q!**

- Find the length of the array’s longest increasing sub-sequence.
- Arrange numbers in a circle so that any two neighbouring numbers differ by 1.
- Find partial names and count the total numbers.
- Find the minimized sum of non-deleted elements of the array after the end of the game.
- Find the maximum number of good sleeping times optimally.
- Sort the elements of the array in the order in which they are required.
- Find the minimum number of flats, monkey needs to visit to catch ninjas.
- Convert the square matrix to matrix in Z form.
- Shift the K elements of each row to right of the matrix.
- Find maximum possible number of students in a balanced team with skills.
- Find the Maximum number of pairs of points you can match with each other.
- Calculate the number of non-empty good subarrays of given array.
- Transform the binary string A into the string B using finite operations.
- Find the number of potion must the character take to jump the hurdles.
- Count the total number of vowels and consonants.
- Return all elements of the matrix in spiral order.
- Return all palindromic paths of the matrix.
- Write the code to change the display in reverse order using pointer.
- Find the number of days the expedition can last.
- Find the minimum size of the sub-segment to make the array pairwise distinct.