import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
{
// your code goes here
int[] arr={1,1,2,2,2,1};
HashMap
<Integer,Integer
> hm
= new HashMap
<>(); int ans=0;
for(int i =0;i<arr.length;i++){
if(hm.containsKey(arr[i])){
ans
=Math.
max(ans,i
-hm.
get(arr
[i
])); }
else{
hm.put(arr[i],i);
}
}
}
}
IAppbXBvcnQgamF2YS51dGlsLio7CmltcG9ydCBqYXZhLmxhbmcuKjsKaW1wb3J0IGphdmEuaW8uKjsKIAovKiBOYW1lIG9mIHRoZSBjbGFzcyBoYXMgdG8gYmUgIk1haW4iIG9ubHkgaWYgdGhlIGNsYXNzIGlzIHB1YmxpYy4gKi8KY2xhc3MgSWRlb25lCnsKCXB1YmxpYyBzdGF0aWMgdm9pZCBtYWluIChTdHJpbmdbXSBhcmdzKSB0aHJvd3MgamF2YS5sYW5nLkV4Y2VwdGlvbgoJewoJCS8vIHlvdXIgY29kZSBnb2VzIGhlcmUKCQlpbnRbXSBhcnI9ezEsMSwyLDIsMiwxfTsKCQlIYXNoTWFwPEludGVnZXIsSW50ZWdlcj4gaG0gPSBuZXcgSGFzaE1hcDw+KCk7CgkJaW50IGFucz0wOwoJCWZvcihpbnQgaSA9MDtpPGFyci5sZW5ndGg7aSsrKXsKCQkgICAgaWYoaG0uY29udGFpbnNLZXkoYXJyW2ldKSl7CgkJICAgICAgICBhbnM9TWF0aC5tYXgoYW5zLGktaG0uZ2V0KGFycltpXSkpOwoJCSAgICB9CgkJICAgIGVsc2V7CgkJICAgICAgICBobS5wdXQoYXJyW2ldLGkpOwoJCSAgICB9CgkJfQoJCVN5c3RlbS5vdXQucHJpbnQoYW5zKTsKCX0KfQ==