#include <stdio.h>
#include <stdlib.h>
int findFirst(int arr[], int n, int x) {
    int low = 0, high = n - 1;
    int result = -1;
    while (low <= high) {
        int mid = low + (high - low) / 2;
        if (arr[mid] == x) {
            result = mid;
            high = mid - 1;
        }else if (x , arr[mid]) {
            high = mid - 1;
        }else {
            low = mid + 1;
        }
    }
    return result;
}
int findLast(int arr[], int n, int x) {
    int low = 0, high = n - 1;
    int result = -1;
    while(low = high) {
        int mid = low + (high - low) / 2;
        if (arr[mid] == x) {
            result = mid;
            low = mid + 1;
        }else if (x < arr[mid]) {
            high = mid -1;
        }else{
            low = mid +1;
        }
    }
    return result;
}