This code takes n,m,x as input which are rows, columns, x respectively. This x is used to apply a distance condition(irrelevant to the question)
#include