using
System;
using
System.Collections;
using
System.Collections.Generic;
class
GFG
{
static
int
get
(
int
[]arr,
int
n)
{
Dictionary<
int
,
int
> occ =
new
Dictionary<
int
,
int
>();
int
mx = -1;
for
(
int
i = 0; i < n; i++) {
if
(occ.ContainsKey(arr[i]))
{
occ[arr[i]] = occ[arr[i]] + 1;
}
else
{
occ.Add(arr[i], 1);
}
mx = Math.Max(mx, occ[arr[i]]);
}
Dictionary<
int
,
int
> chk =
new
Dictionary<
int
,
int
>();
foreach
(KeyValuePair<
int
,
int
> x
in
occ){
if
(x.Value == mx){
if
(chk.ContainsKey(x.Key)){
chk[x.Key] = chk[x.Key] + 1;
}
else
{
chk.Add(x.Key, 1);
}
}
}
int
fr = Int32.MaxValue, sc = Int32.MinValue;
for
(
int
i = 0; i < n; i++) {
if
(chk.ContainsKey(arr[i])) {
fr = Math.Min(fr, i);
sc = Math.Max(sc, i);
}
}
return
sc - fr + 1;
}
public
static
void
Main()
{
int
[]arr = { 1, 2, 5, 1, 5, 5 };
int
n = arr.Length;
Console.Write(
get
(arr, n));
}
}