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,2,2,7,8,8,8,8,9,10};
int k=8;
System.
out.
print(first
(arr,k
)+" "+last
(arr,k
)); }
public static int first(int[] arr,int k){
int i=0;
int j=arr.length-1;
int ans=-1;
while(i<=j){
int mid=(i+j)/2;
if(arr[mid]==k){
ans=mid;
j=mid-1;
}
else if(arr[mid]>k){
j=mid-1;
}
else{
i=mid+1;
}
}
return ans;
}
public static int last(int[] arr,int k){
int i=0;
int j=arr.length-1;
int ans=-1;
while(i<=j){
int mid=(i+j)/2;
if(arr[mid]==k){
ans=mid;
i=mid+1;
}
else if(arr[mid]>k){
j=mid-1;
}
else{
i=mid+1;
}
}
return ans;
}
}
aW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5sYW5nLio7CmltcG9ydCBqYXZhLmlvLio7CiAKLyogTmFtZSBvZiB0aGUgY2xhc3MgaGFzIHRvIGJlICJNYWluIiBvbmx5IGlmIHRoZSBjbGFzcyBpcyBwdWJsaWMuICovCmNsYXNzIElkZW9uZQp7CglwdWJsaWMgc3RhdGljIHZvaWQgbWFpbiAoU3RyaW5nW10gYXJncykgdGhyb3dzIGphdmEubGFuZy5FeGNlcHRpb24KCXsKCQkvLyB5b3VyIGNvZGUgZ29lcyBoZXJlCgkJaW50W10gYXJyPXsxLDIsMiw3LDgsOCw4LDgsOSwxMH07CgkJaW50IGs9ODsKCQlTeXN0ZW0ub3V0LnByaW50KGZpcnN0KGFycixrKSsiICIrbGFzdChhcnIsaykpOwoJfQoJcHVibGljIHN0YXRpYyBpbnQgZmlyc3QoaW50W10gYXJyLGludCBrKXsKCQlpbnQgaT0wOwoJCWludCBqPWFyci5sZW5ndGgtMTsKCQlpbnQgYW5zPS0xOwoJCXdoaWxlKGk8PWopewoJCQlpbnQgbWlkPShpK2opLzI7CgkJCWlmKGFyclttaWRdPT1rKXsKCQkJCWFucz1taWQ7CgkJ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