Help me in solving TOOFAR problem

My issue

Anyone help me with this question.
Pls give a approach for this and explain with a test case

My code

#include <bits/stdc++.h>
using namespace std;

int main() {
	// your code goes here

}

Problem Link: Too Far For Comfort Practice Coding Problem