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.

saiujwal13083 | 347 |

isiddhisingh | 252 |

Abhishek_Jadhav | 243 |

_uncle_sam_ | 221 |

c_ocoooo | 217 |

saiujwal13083 | 610 |

SumitSingh27 | 466 |

c_ocoooo | 456 |

rathiarpit29 | 379 |

NaveenKumarNakka | 370 |

blackshadows | 5362 |

Ibrahim Nash | 5242 |

akhayrutdinov | 5111 |

mb1973 | 4931 |

Quandray | 4598 |

Login to report an issue on this page.