Binary search is an algorithm used to locate a specific element within a sorted array. Below is the pseudocode for a binary search algorithm, where indicates integer division:
input: a_0, a_1, \ldots, a_{n-1},
l = 0;
r = n;
while (l < r - 1) {
m = (l + r) / 2;
if (a_m \leq x)
l = m;
else
r = m;
}
if (a_l == x)
return true;
else
return false;
Occasionally, binary search may successfully find an element in the array even if the array is not sorted. You are given a number . Your task is to determine the number of pairs , where is an array of length containing integers from to , and is an integer from to , such that the above procedure returns true when executed with the array and the integer as inputs.
The input consists of a single integer (1 \leq n \leq 1000).
Output a single integer — the solution to the problem.
Example 1