I have saved the code
there are 2 test cases out of which one of the test case is working fine but the 2nd test case shows run-error
@pranav_sharma See the Constraints: N < 1000 but you have restricted the size of the 2d array to 10 x 10 which is causing run error in 2nd test case.