As a programmer, it is very necessary to maintain balance in the things you work upon. Here is task for you to maintain this balance. Your task is to find whether a given number x is balanced with respect to a given array a[] which is sorted in a non-decreasing order.Given a sorted array, the ceiling of x is the smallest element in array greater than or equal to x, and the floor is the greatest element smaller than or equal to x.The number 'x' is said to be balanced if the floor is equal to ceil of the number in the array a[].

ie. if (x - floor(x,a)) == (ceil(x,a) - x)

Assume one of floor or ceil does not exist assume 'x' to be balanced. If Key exists in the array so it is Balanced.

**Input:**

The first line of input contains an integer T denoting the number of test cases. Each test case contains the number of elements in the array a[] as n and next line contains space separated n elements in the array. The following line consists of the number 'x' for which balance is to be checked.

**Output:**

Output "Balanced" if the number 'x' is balanced otherwise output "Not Balanced".

**Constraints:**

1<=T<=100

1<=n<=100000

1<=a[i]<=100000

1<=x<=100000

**Example:
Input:**

2

7

1 2 8 10 10 12 19

5

8

1 2 5 7 8 11 12 15

9

Balanced

Not Balanced

Author: shashwat jain

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

msriramvarma01 | 25 |

AbhilashKumar2 | 24 |

monusinghal | 24 |

tripurari_IT | 24 |

Abreez Das | 23 |

ARUN_PUNDIR | 609 |

manishgupta8497 | 607 |

KhyatiSoneji | 501 |

Abhimanyu_kumar | 487 |

vvggfggcg | 453 |

blackshadows | 5333 |

Ibrahim Nash | 5221 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4567 |

Login to report an issue on this page.