https://online.codingblocks.com/app/player/199544/content/197161/5063/code-challenge
import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
int arr[][] = new int[n][m];
for(int i=0 ; i<n ; i++)
for(int j=0 ; j<m ; j++)
arr[i][j] = sc.nextInt(); // input
int item = sc.nextInt();
int row=0;
for(int i=0 ; i<n ; i++){
if(arr[i][m-1] >= item) // finding row
row = i;
}
int flag = 0;
int low = 0, high = m-1; // simple binary search
while(low <= high){
int mid = (low+high)/2;
if(item < arr[row][mid])
high = mid -1;
else if(item > arr[row][mid])
low = mid +1 ;
else{
flag = 1;
break;
}
}
System.out.println(flag);
}
}