C. Binary Search

problem_index: C

time_limit: 1 second

memory_limit: 256 megabytes

solutions: ["import bisect\nimport math\n\ndef binsearch(arr, x):\n\tleft = 0\n\tright = len(arr)\n\tbig = 0\n\tsmall = 0\n\twhile left < right:\n\t\tmiddle = int((left + right) / 2)\n\t\tif arr[middle] < x:\n\t\t\tleft = middle + 1\n\t\t\tsmall += 1\n\t\telif arr[middle] == x:\n\t\t\tleft = middle + 1\n\t\telse:\n\t\t\tright = middle\n\t\t\tbig += 1\n\treturn (big, small)\n\tpass\n\ndef solve(n, x, pos):\n\tp = 10 ** 9 + 7\n\tarr = [int(x) for x in range(n)]\n\t(big, small) = binsearch(arr, pos)\n\tk1 = math.factorial(small) * math.comb(x - 1, small)\n\tk2 = math.factorial(big) * math.comb(n - x, big)\n\tper = math.factorial(n - (small + big + 1))\n\treturn k1 % p * k2 % p * per % p % p\n\tpass\nt = 1\nans = []\nfor i in range(t):\n\ts = [int(x) for x in input().split()]\n\tn = s[0]\n\tx = s[1]\n\tpos = s[2]\n\tans.append(solve(n, x, pos))\nfor a in ans:\n\tprint(a)\n", "mod = 10 ** 9 + 7\n\nclass Combi:\n\n\tdef __init__(self, N, mod):\n\t\tself.power = [1 for _ in range(N + 1)]\n\t\tself.rev = [1 for _ in range(N + 1)]\n\t\tself.mod = mod\n\t\tfor i in range(2, N + 1):\n\t\t\tself.power[i] = self.power[i - 1] * i % self.mod\n\t\tself.rev[N] = pow(self.power[N], self.mod - 2, self.mod)\n\t\tfor j in range(N, 0, -1):\n\t\t\tself.rev[j - 1] = self.rev[j] * j % self.mod\n\n\tdef C(self, K, R):\n\t\tif K < R:\n\t\t\treturn 0\n\t\telse:\n\t\t\treturn self.power[K] * self.rev[K - R] * self.rev[R] % self.mod\n\n\tdef P(self, K, R):\n\t\tif K < R:\n\t\t\treturn 0\n\t\telse:\n\t\t\treturn self.power[K] * self.rev[K - R] % self.mod\n\n\tdef Pow(self, X):\n\t\treturn self.power[X]\n\ndef main():\n\t(n, x, pos) = map(int, input().split())\n\tc = Combi(1100, mod)\n\tque = []\n\tl = 0\n\tr = n\n\t(upper, lower) = (0, 0)\n\twhile r > l:\n\t\tm = (r + l) // 2\n\t\tif m <= pos:\n\t\t\tque.append((m, 'a[middle]<=x'))\n\t\t\tl = m + 1\n\t\telif m > pos:\n\t\t\tque.append((m, 'a[middle]>x'))\n\t\t\tr = m\n\tfor (v, comment) in que:\n\t\tif v > pos:\n\t\t\tupper += 1\n\t\telif v < pos:\n\t\t\tlower += 1\n\tans = c.P(n - x, upper) * c.P(x - 1, lower) * c.Pow(n - upper - lower - 1) % mod\n\tprint(ans)\n\treturn\nmain()\n", "(n, x, a) = map(int, input().split())\nans = 1\ncnt = 0\ncnt1 = 0\nleft = 0\nright = n\nmod = 1000000007\nwhile left < right:\n\tmid = (left + right) // 2\n\tif mid < a:\n\t\tans *= x - 1 - cnt1\n\t\tans %= mod\n\t\tcnt1 += 1\n\t\tleft = mid + 1\n\telif mid > a:\n\t\tans *= n - x - cnt\n\t\tans %= mod\n\t\tcnt += 1\n\t\tright = mid\n\telse:\n\t\tleft = mid + 1\ncr = n - cnt - cnt1 - 1\nfor i in range(1, cr + 1):\n\tans *= i\n\tans %= mod\nprint(ans)\n", "(n, x, pos) = map(int, input().split())\na = [i for i in range(n)]\nzero = 0\none = 0\nleft = 0\nright = n\nwhile left < right:\n\tmiddle = (left + right) // 2\n\tif a[middle] <= pos:\n\t\tzero += 1\n\t\tleft = middle + 1\n\telse:\n\t\tone += 1\n\t\tright = middle\nres = 1\nmod = 10 ** 9 + 7\nfor i in range(zero - 1):\n\tres *= x - 1 - i\n\tres %= mod\nfor i in range(one):\n\tres *= n - x - i\n\tres %= mod\nfor j in range(n - zero - one):\n\tres *= j + 1\n\tres %= mod\nprint(res)\n", "import array\n(n, x, p) = map(int, input().split())\n(s0, s1) = (x - 1, n - x)\n\ndef find(l, r, s0, s1):\n\tif l == r:\n\t\treturn (s0, s1)\n\tmid = (l + r) // 2\n\tif mid > p:\n\t\ts1 -= 1\n\tif mid < p:\n\t\ts0 -= 1\n\tif mid <= p:\n\t\t(s0, s1) = find(mid + 1, r, s0, s1)\n\telse:\n\t\t(s0, s1) = find(l, mid, s0, s1)\n\treturn (s0, s1)\n(s0, s1) = find(0, n, s0, s1)\nif s0 < 0 or s1 < 0:\n\tprint(0)\nelse:\n\tans = 1\n\tfor i in range(1, s0 + s1 + 1):\n\t\tans = ans * i\n\tfor i in range(1, s0 + 1):\n\t\tans = ans // i\n\tfor i in range(1, s1 + 1):\n\t\tans = ans // i\n\tfor i in range(1, x - 1 + 1):\n\t\tans = ans * i\n\tfor i in range(1, n - x + 1):\n\t\tans = ans * i\n\tprint(ans % 1000000007)\n", "import sys, math, itertools, collections, copy\ninput = sys.stdin.readline\nMOD = 10 ** 9 + 7\n(n, x, pos) = map(int, input().split())\n(lo, hi, smaller, bigger) = (0, n, x - 1, n - x)\nlow_bigger = bigger\nlow_smaller = smaller\ncnt = 0\n\ndef f(n):\n\tif n <= 1:\n\t\treturn 1\n\tans = 1\n\tfor i in range(2, n + 1):\n\t\tans *= i % MOD\n\treturn ans\nwhile lo < hi:\n\tmid = lo + hi >> 1\n\tif pos < mid:\n\t\tlow_bigger -= 1\n\t\thi = mid\n\telif pos == mid:\n\t\tlo = mid + 1\n\telse:\n\t\tlow_smaller -= 1\n\t\tlo = mid + 1\n\tcnt += 1\nif low_smaller < 0 or low_bigger < 0:\n\tprint(0)\nelse:\n\tans1 = f(bigger) // f(low_bigger) % MOD\n\tans2 = f(smaller) // f(low_smaller) % MOD\n\tprint(ans1 * ans2 * f(n - cnt) % MOD)\n", "from __future__ import division, print_function\nfrom fractions import Fraction\nimport sys\nimport os\nfrom io import BytesIO, IOBase\nfrom itertools import *\nimport bisect\nfrom heapq import *\nfrom math import ceil, floor\nfrom copy import *\nfrom collections import deque, defaultdict\nfrom collections import Counter as counter\nfrom itertools import combinations\nfrom itertools import permutations as permutate\nfrom bisect import bisect_left as bl\nfrom operator import *\nfrom bisect import bisect_right as br\nfrom bisect import bisect\nBUFSIZE = 8192\nfrom sys import stderr\n\nclass FastIO(IOBase):\n\tnewlines = 0\n\n\tdef __init__(self, file):\n\t\tself._fd = file.fileno()\n\t\tself.buffer = BytesIO()\n\t\tself.writable = 'x' in file.mode or 'r' not in file.mode\n\t\tself.write = self.buffer.write if self.writable else None\n\n\tdef read(self):\n\t\twhile True:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tif not b:\n\t\t\t\tbreak\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines = 0\n\t\treturn self.buffer.read()\n\n\tdef readline(self):\n\t\twhile self.newlines == 0:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tself.newlines = b.count(b'\\n') + (not b)\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines -= 1\n\t\treturn self.buffer.readline()\n\n\tdef flush(self):\n\t\tif self.writable:\n\t\t\tos.write(self._fd, self.buffer.getvalue())\n\t\t\t(self.buffer.truncate(0), self.buffer.seek(0))\n\nclass IOWrapper(IOBase):\n\n\tdef __init__(self, file):\n\t\tself.buffer = FastIO(file)\n\t\tself.flush = self.buffer.flush\n\t\tself.writable = self.buffer.writable\n\t\tself.write = lambda s: self.buffer.write(s.encode('ascii'))\n\t\tself.read = lambda : self.buffer.read().decode('ascii')\n\t\tself.readline = lambda : self.buffer.readline().decode('ascii')\n\ndef print(*args, **kwargs):\n\t(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))\n\tat_start = True\n\tfor x in args:\n\t\tif not at_start:\n\t\t\tfile.write(sep)\n\t\tfile.write(str(x))\n\t\tat_start = False\n\tfile.write(kwargs.pop('end', '\\n'))\n\tif kwargs.pop('flush', False):\n\t\tfile.flush()\nif sys.version_info[0] < 3:\n\t(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))\nelse:\n\t(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))\nfrom types import GeneratorType\n\ndef iterative(f, stack=[]):\n\n\tdef wrapped_func(*args, **kwargs):\n\t\tif stack:\n\t\t\treturn f(*args, **kwargs)\n\t\tto = f(*args, **kwargs)\n\t\twhile True:\n\t\t\tif type(to) is GeneratorType:\n\t\t\t\tstack.append(to)\n\t\t\t\tto = next(to)\n\t\t\t\tcontinue\n\t\t\tstack.pop()\n\t\t\tif not stack:\n\t\t\t\tbreak\n\t\t\tto = stack[-1].send(to)\n\t\treturn to\n\treturn wrapped_func\nmod = 1000000007\n\ndef inp():\n\treturn sys.stdin.readline().rstrip('\\r\\n')\n\ndef out(var):\n\tsys.stdout.write(str(var))\n\ndef lis():\n\treturn list(map(int, inp().split()))\n\ndef stringlis():\n\treturn list(map(str, inp().split()))\n\ndef sep():\n\treturn map(int, inp().split())\n\ndef strsep():\n\treturn map(str, inp().split())\n\ndef fsep():\n\treturn map(float, inp().split())\n\ndef nextline():\n\tout('\\n')\n\ndef testcase(t):\n\tfor p in range(t):\n\t\tsolve()\n\ndef pow(x, y, p):\n\tres = 1\n\tx = x % p\n\tif x == 0:\n\t\treturn 0\n\twhile y > 0:\n\t\tif y & 1 == 1:\n\t\t\tres = res * x % p\n\t\ty = y >> 1\n\t\tx = x * x % p\n\treturn res\nfrom functools import reduce\n\ndef factors(n):\n\treturn set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))\n\ndef lcm(a, b):\n\treturn abs(a // gcd(a, b) * b)\n\ndef gcd(a, b):\n\tif a == b:\n\t\treturn a\n\twhile b > 0:\n\t\t(a, b) = (b, a % b)\n\treturn a\nN = 100000\nmod = 10 ** 9 + 7\nfac = [1, 1]\nfinv = [1, 1]\ninv = [0, 1]\nfor i in range(2, N + 1):\n\tfac.append(fac[-1] * i % mod)\n\tinv.append(mod - inv[mod % i] * (mod // i) % mod)\n\tfinv.append(finv[-1] * inv[-1] % mod)\n\ndef comb(n, r):\n\tif n < r:\n\t\treturn 0\n\telse:\n\t\treturn fac[n] * (finv[r] * finv[n - r] % mod) % mod\n\ndef prefix_sum(ar):\n\treturn list(accumulate(ar))\n\ndef suffix_sum(ar):\n\treturn list(accumulate(ar[::-1]))[::-1]\n\ndef N():\n\treturn int(inp())\nfrom collections import defaultdict\n\ndef numberOfSetBits(i):\n\ti = i - (i >> 1 & 1431655765)\n\ti = (i & 858993459) + (i >> 2 & 858993459)\n\treturn ((i + (i >> 4) & 252645135) * 16843009 & 4294967295) >> 24\n\ndef yes():\n\tprint('Yes')\n\ndef no():\n\tprint('No')\n\ndef YES():\n\tprint('YES')\n\ndef NO():\n\tprint('NO')\nfrom math import *\n\ndef binary(n, x):\n\tl = 0\n\tr = n\n\tcl = 0\n\tcr = 0\n\twhile l < r:\n\t\tm = (l + r) // 2\n\t\tif m == x:\n\t\t\tl = m + 1\n\t\telif m < x:\n\t\t\tl = m + 1\n\t\t\tcl += 1\n\t\telse:\n\t\t\tr = m\n\t\t\tcr += 1\n\treturn (cl, cr)\n\ndef solve():\n\t(n, x, pos) = sep()\n\t(cl, cr) = binary(n, pos)\n\ta = x - 1\n\tb = n - x\n\tt = comb(a, cl) * comb(b, cr) * fac[n - cl - cr - 1] * fac[cl] * fac[cr]\n\tprint(t % mod)\nsolve()\n", "mod = 1000000007\nbig = 0\nsmall = 0\nfact = []\n\ndef c(n: int, k: int):\n\tif n < k:\n\t\treturn 0\n\treturn fact[n] // (fact[k] * fact[n - k]) % mod\n\ndef binary(n: int, pos: int):\n\tl = 0\n\tr = n\n\twhile l < r:\n\t\tmid = (l + r) // 2\n\t\tif mid <= pos:\n\t\t\tif mid != pos:\n\t\t\t\tglobal small\n\t\t\t\tsmall += 1\n\t\t\tl = mid + 1\n\t\telse:\n\t\t\tr = mid\n\t\t\tglobal big\n\t\t\tbig += 1\nfVal = 1\nfor i in range(1, 1005):\n\tfact.append(fVal)\n\tfVal = fVal * i\n(n, x, pos) = map(int, input().split())\nbinary(n, pos)\nans = c(x - 1, small) * fact[small] * c(n - x, big) * fact[big] * fact[n - small - big - 1]\nprint(int(ans % mod))\n", "M = 10 ** 9 + 7\n(n, c, k) = map(int, input().split())\ns = c - 1\nb = n - c\nl = 0\nr = n\nm = (l + r) // 2\nans = 1\ncount = 0\nwhile l < r:\n\tm = (l + r) // 2\n\tif m < k:\n\t\tl = m + 1\n\t\tans *= s\n\t\ts -= 1\n\telif m == k:\n\t\tl = m + 1\n\telse:\n\t\tr = m\n\t\tans *= b\n\t\tb -= 1\nk = s + b\nwhile k:\n\tans = ans * k % M\n\tk -= 1\nprint(ans % M)\n", "import os\nimport sys\nfrom io import BytesIO, IOBase\nimport math\nfrom collections import defaultdict, deque\nfrom itertools import combinations\nimport random\nBUFSIZE = 8192\n\nclass FastIO(IOBase):\n\tnewlines = 0\n\n\tdef __init__(self, file):\n\t\tself._fd = file.fileno()\n\t\tself.buffer = BytesIO()\n\t\tself.writable = 'x' in file.mode or 'r' not in file.mode\n\t\tself.write = self.buffer.write if self.writable else None\n\n\tdef read(self):\n\t\twhile True:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tif not b:\n\t\t\t\tbreak\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines = 0\n\t\treturn self.buffer.read()\n\n\tdef readline(self):\n\t\twhile self.newlines == 0:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tself.newlines = b.count(b'\\n') + (not b)\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines -= 1\n\t\treturn self.buffer.readline()\n\n\tdef flush(self):\n\t\tif self.writable:\n\t\t\tos.write(self._fd, self.buffer.getvalue())\n\t\t\t(self.buffer.truncate(0), self.buffer.seek(0))\n\nclass IOWrapper(IOBase):\n\n\tdef __init__(self, file):\n\t\tself.buffer = FastIO(file)\n\t\tself.flush = self.buffer.flush\n\t\tself.writable = self.buffer.writable\n\t\tself.write = lambda s: self.buffer.write(s.encode('ascii'))\n\t\tself.read = lambda : self.buffer.read().decode('ascii')\n\t\tself.readline = lambda : self.buffer.readline().decode('ascii')\n(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))\ninput = lambda : sys.stdin.readline().rstrip('\\r\\n')\n(n, a, b) = map(int, input().split(' '))\nm = pow(10, 9) + 7\nans = 1\n(l, h) = (0, n)\nc = 0\n(p, q) = (n - a, a - 1)\nwhile l < h:\n\tz = (l + h) // 2\n\tif b == z:\n\t\tl = z + 1\n\telif b > z:\n\t\tans *= q\n\t\tq -= 1\n\t\tc += 1\n\t\tl = z + 1\n\telse:\n\t\tans *= p\n\t\tp -= 1\n\t\tc += 1\n\t\th = z\nans %= m\nfor i in range(2, n - c):\n\tans *= i\n\tans %= m\nprint(ans % m)\n", "import math\nMOD = int(1000000000.0 + 7)\n\ndef permutations(n, k):\n\tif n >= k:\n\t\treturn math.factorial(n) // math.factorial(n - k)\n\treturn 0\n(n, x, pos) = list(map(int, input().split()))\n(mins, maxs) = (0, 0)\n(l, r) = (0, n)\nwhile l < r:\n\tm = (l + r) // 2\n\tif m <= pos:\n\t\tl = m + 1\n\t\tif m < pos:\n\t\t\tmins += 1\n\telif m > pos:\n\t\tmaxs += 1\n\t\tr = m\nif mins < x and maxs <= n - x:\n\tp1 = permutations(x - 1, mins)\n\tp2 = permutations(n - x, maxs)\n\tprint(p1 * p2 * math.factorial(n - maxs - mins - 1) % MOD)\nelse:\n\tprint(0)\n", "mod = 1000000007\n(n, x, pos) = map(int, input().split())\n(top, bot, lo, hi) = (n, 0, 0, 0)\nwhile top > bot:\n\tmid = top + bot >> 1\n\tif mid > pos:\n\t\thi += 1\n\t\ttop = mid\n\telse:\n\t\tif mid < pos:\n\t\t\tlo += 1\n\t\tbot = mid + 1\n(F, I) = ([1 for _ in range(n + 1)], [1 for _ in range(n + 1)])\nfor i in range(1, n + 1):\n\tF[i] = i * F[i - 1] % mod\nfor i in range(2, n + 1):\n\tI[i] = (mod - mod // i) * I[mod % i] % mod\nfor i in range(1, n + 1):\n\tI[i] = I[i] * I[i - 1] % mod\n\ndef binom(n, k):\n\tif n < k or k < 0:\n\t\treturn 0\n\telse:\n\t\treturn F[n] * I[k] % mod * I[n - k] % mod\nans = binom(n - x, hi) * F[hi] % mod * binom(x - 1, lo) % mod * F[lo] % mod * F[n - hi - lo - 1] % mod\nprint(ans)\n", "import math\nmod = 10 ** 9 + 7\n(n, x, pos) = list(map(int, input().split()))\n(l, h) = (0, n)\ngv = n - x\nlv = x - 1\nout = 1\ncnt = 0\nwhile l < h:\n\tm = (l + h) // 2\n\tcnt += 1\n\tif m == pos:\n\t\tl = m + 1\n\telif m < pos:\n\t\tl = m + 1\n\t\tout *= lv\n\t\tlv -= 1\n\telse:\n\t\th = m\n\t\tout *= gv\n\t\tgv -= 1\n\tout %= mod\nout *= math.factorial(n - cnt) % mod\nout %= mod\nprint(out)\n", "prime = 10 ** 9 + 7\n\ndef process(n, x, pos):\n\ts = 0\n\te = n\n\tsmaller = []\n\tlarger = []\n\twhile s < e:\n\t\tm = (s + e) // 2\n\t\tif m <= pos:\n\t\t\tif m < pos:\n\t\t\t\tsmaller.append(m)\n\t\t\ts = m + 1\n\t\telse:\n\t\t\tlarger.append(m)\n\t\t\te = m\n\tif x - 1 < len(smaller):\n\t\treturn 0\n\tnum1 = 1\n\tnum2 = 1\n\tnum3 = 1\n\tfor i in range(len(smaller)):\n\t\tnum1 = num1 * (x - 1 - i) % prime\n\tfor i in range(len(larger)):\n\t\tnum2 = num2 * (n - x - i) % prime\n\tfor i in range(1, n - (len(smaller) + len(larger))):\n\t\tnum3 = num3 * i % prime\n\tanswer = num1 * num2 * num3 % prime\n\treturn answer\n(n, x, pos) = [int(x) for x in input().split()]\nprint(process(n, x, pos))\n", "(n, x, p) = map(int, input().split())\nans = 1\nl = x - 1\nr = n - x\nb = 0\ne = n\nwhile b < e:\n\tm = b + e\n\tm //= 2\n\tif p < m:\n\t\te = m\n\t\tans = ans * r % 1000000007\n\t\tr -= 1\n\t\tn -= 1\n\telif p > m:\n\t\tb = m + 1\n\t\tans = ans * l % 1000000007\n\t\tl -= 1\n\t\tn -= 1\n\telse:\n\t\tb = m + 1\nfor i in range(1, n):\n\tans = ans * i % 1000000007\nprint(ans)\n", "from collections import defaultdict as dd\nimport sys\nmod = 10 ** 9 + 7\ninput = sys.stdin.readline\n(n, x, pos) = map(int, input().split())\nl = x - 1\nr = n - x\nlo = 0\nhi = n\nres = 1\nwhile hi - lo >= 1:\n\tcmid = (lo + hi) // 2\n\tif pos < cmid:\n\t\tres = res * r % mod\n\t\tr -= 1\n\t\thi = cmid\n\telif pos > cmid:\n\t\tres = res * l % mod\n\t\tl -= 1\n\t\tlo = cmid + 1\n\telse:\n\t\tlo = cmid + 1\nleft = l + r\nfor i in range(1, left + 1):\n\tres = res * i % mod\nprint(res)\n", "def ncr(n, r, p):\n\tif r > n:\n\t\treturn 0\n\tnum = den = 1\n\tfor i in range(r):\n\t\tnum = num * (n - i) % p\n\t\tden = den * (i + 1) % p\n\treturn num * pow(den, p - 2, p) % p\n\ndef fac(n, p):\n\tif n >= p:\n\t\treturn 0\n\tresult = 1\n\tfor i in range(1, n + 1):\n\t\tresult = result * i % p\n\treturn result\n(n, x, pos) = list(map(int, input().split(' ')))\ns = g = 0\na = 0\nb = n\nwhile a < b:\n\tmid = (a + b) // 2\n\tif mid <= pos:\n\t\ts += 1\n\t\ta = mid + 1\n\telse:\n\t\tg += 1\n\t\tb = mid\np = 1000\np = p * p * p + 7\nprint(ncr(x - 1, s - 1, p) * fac(s - 1, p) * ncr(n - x, g, p) * fac(g, p) * fac(n - s - g, p) % p)\n", "import math\n(n, x, pos) = map(int, input().split())\nl = 0\nr = n\na = 0\nb = 0\np = 1000000007\nwhile l < r:\n\tm = math.floor((l + r) / 2)\n\tif m < pos:\n\t\ta = a + 1\n\t\tl = m + 1\n\telif m > pos:\n\t\tb = b + 1\n\t\tr = m\n\telif m == pos:\n\t\tl = m + 1\nn1 = x - 1\nn2 = n - x\nif n1 - a < 0 or n2 - b < 0:\n\tprint('0')\nelse:\n\tans = math.factorial(n1) // math.factorial(n1 - a) % p\n\tans = ans * math.factorial(n2) // math.factorial(n2 - b) % p\n\tans = ans * math.factorial(n - a - b - 1) % p\n\tprint(ans)\n", "MOD = int(1000000000.0 + 7)\nfrom math import factorial\n(n, x, p) = input().split()\n(n, x, p) = (int(n), int(x), int(p))\ns = 0\ne = n\n\ndef perm(n, k):\n\tif k <= n:\n\t\treturn factorial(n) // factorial(n - k)\n\telse:\n\t\treturn 0\npos_greater_than = 0\npos_less_than = 0\nwhile s < e:\n\tmid = (s + e) // 2\n\tif p < mid:\n\t\tpos_greater_than += 1\n\t\te = mid\n\telif p >= mid:\n\t\ts = mid + 1\n\t\tif p > mid:\n\t\t\tpos_less_than += 1\nans1 = perm(n - x, pos_greater_than)\nans2 = perm(x - 1, pos_less_than)\nans3 = factorial(n - pos_greater_than - pos_less_than - 1)\nans = ans1 * ans2 * ans3 % MOD\nprint(ans)\n", "(n, x, pos) = map(int, input().split())\nu = [0] * n\nu[pos] = x\nfor i in range(pos + 1, n):\n\tu[i] = x + 1\nL = 0\nR = n\ncnt1 = cnt2 = 0\na = []\nb = []\nwhile L < R:\n\tM = (L + R) // 2\n\tif u[M] <= x:\n\t\tif M != pos:\n\t\t\tcnt1 += 1\n\t\t\ta.append(M)\n\t\tL = M + 1\n\telse:\n\t\tcnt2 += 1\n\t\tb.append(M)\n\t\tR = M\nans = 1\nq = 10 ** 9 + 7\nz = x - 1\nfor i in range(cnt1):\n\tans *= z\n\tz -= 1\n\tans %= q\nz = n - x\nfor i in range(cnt2):\n\tans *= z\n\tz -= 1\n\tans %= q\nz = n - cnt1 - cnt2 - 1\nfor i in range(z):\n\tans *= z\n\tz -= 1\n\tans %= q\nprint(ans)\n", "(n, x, pos) = map(int, input().split())\n(l, r) = (0, n)\n(hasS, hasB) = (x - 1, n - x)\nmod = 1000000007\nans = 1\nfact = []\nfact.append(1)\nfor i in range(n + 1):\n\tfact.append(fact[i] * (i + 1))\nwhile l < r:\n\tmid = (l + r) // 2\n\tif pos >= mid:\n\t\tl = mid + 1\n\t\tif mid != pos:\n\t\t\tans *= hasS\n\t\t\thasS -= 1\n\telse:\n\t\tr = mid\n\t\tans *= hasB\n\t\thasB -= 1\nans *= fact[hasS + hasB]\nprint(ans % mod)\n", "(n, x, pos) = map(int, input().split())\na = [i for i in range(n)]\nmod = 10 ** 9 + 7\nlower = 0\nhigher = 0\nleft = 0\nright = n\nwhile left < right:\n\tmiddle = (left + right) // 2\n\tif a[middle] <= pos:\n\t\tlower += 1\n\t\tleft = middle + 1\n\telse:\n\t\thigher += 1\n\t\tright = middle\nres = 1\nnum_l = x - 1\nnum_h = n - x\nlower -= 1\nfor i in range(lower):\n\tres *= num_l\n\tres %= mod\n\tnum_l -= 1\nfor i in range(higher):\n\tres *= num_h\n\tres %= mod\n\tnum_h -= 1\nfor i in range(1, n - lower - higher):\n\tres *= i\n\tres %= mod\nprint(res)\n", "import math\n\ndef fact(n):\n\tprod = 1\n\tfor i in range(2, n + 1):\n\t\tprod = prod * i % mod\n\treturn prod\n(n, x, p) = (int(i) for i in input().split())\nmod = 1000000007\nprod = 1\ng = n - x\nl = x - 1\nc = 0\nleft = 0\nright = n\nwhile left < right:\n\tmid = (left + right) // 2\n\tif mid > p:\n\t\tprod = prod * g % mod\n\t\tg -= 1\n\t\tright = mid\n\t\tc += 1\n\telif mid < p:\n\t\tprod = prod * l % mod\n\t\tl -= 1\n\t\tleft = mid + 1\n\t\tc += 1\n\telse:\n\t\tleft = mid + 1\n\t\tc += 1\nprint(prod * fact(n - c) % mod % mod)\n", "import math\n(n, x, pos) = [int(x) for x in input().split()]\ngreater = n - x\nsmaller = x - 1\nans = 1\narr = [int(x) for x in range(1, n + 1)]\n\ndef binarysearch1(arr, si, ei, qi, smaller, greater, ans):\n\tmid = (si + ei) // 2\n\tif si == ei:\n\t\tprint(ans * math.factorial(greater + smaller) % (10 ** 9 + 7))\n\t\treturn True\n\tif qi == mid:\n\t\tbinarysearch1(arr, mid + 1, ei, qi, smaller, greater, ans)\n\tif qi < mid:\n\t\tans = ans * greater\n\t\tgreater -= 1\n\t\tbinarysearch1(arr, si, mid, qi, smaller, greater, ans)\n\telif qi > mid:\n\t\tans = ans * smaller\n\t\tsmaller -= 1\n\t\tbinarysearch1(arr, mid + 1, ei, qi, smaller, greater, ans)\nbinarysearch1(arr, 0, n, pos, smaller, greater, ans)\n", "MOD = int(1000000000.0 + 7)\n(n, x, pos) = map(int, input().split())\nunder_cnt = x - 1\nover_cnt = n - x\nunder = 0\nover = 0\nleft = 0\nright = n\nwhile left < right:\n\tmiddle = (left + right) // 2\n\tif middle < pos:\n\t\tleft = middle + 1\n\t\tunder += 1\n\telif middle > pos:\n\t\tright = middle\n\t\tover += 1\n\telse:\n\t\tleft = middle + 1\nif under > under_cnt or over_cnt < over:\n\tprint(0)\nelse:\n\tanswer = 1\n\tfor i in range(under):\n\t\tanswer = answer * (under_cnt - i) % MOD\n\tfor i in range(over):\n\t\tanswer = answer * (over_cnt - i) % MOD\n\tfor i in range(1, n - under - over):\n\t\tanswer = answer * i % MOD\n\tprint(answer)\n", "MAXN = 1005\nmod = 10 ** 9 + 7\n\ndef nCr(n, r):\n\tglobal fact\n\tif r > n:\n\t\treturn 0\n\tnum = fact[n]\n\tdenom = fact[r] * fact[n - r] % mod\n\treturn num * pow(denom, mod - 2, mod) % mod\n(n, x, pos) = map(int, input().split())\nbits = len(bin(n)[2:])\nif (1 << 30) % n == 0:\n\tbits -= 1\nfact = [1] * MAXN\nfor i in range(1, MAXN):\n\tfact[i] = fact[i - 1] * i % mod\nbinary = ''\narr = [i for i in range(n)]\nleft = 0\nright = n\nmore = n - x\nless = x - 1\nwhile left < right:\n\tmiddle = (left + right) // 2\n\tif arr[middle] <= pos:\n\t\tleft = middle + 1\n\t\tbinary += '0'\n\telse:\n\t\tright = middle\n\t\tbinary += '1'\nless = binary.count('0')\nmore = binary.count('1')\na = nCr(x - 1, less - 1) * fact[less - 1]\nb = nCr(n - x, more) * fact[more]\nprint(a * b * fact[n - (more + less)] % mod)\n", "pr = []\n\ndef ok(n, t):\n\tleft = 0\n\tright = n\n\twhile left < right:\n\t\tm = int((left + right) / 2)\n\t\tpr.append(m)\n\t\tif m <= t:\n\t\t\tleft = m + 1\n\t\telse:\n\t\t\tright = m\n\treturn\nmod = int(1000000000.0) + 7\n(n, m, idx) = map(int, input().split())\nok(n, idx)\n(big, small, res) = (n - m, m - 1, 1)\nfor i in pr:\n\tif i > idx:\n\t\tres = res * big % mod\n\t\tbig -= 1\n\telif i < idx:\n\t\tres = res * small % mod\n\t\tsmall -= 1\n\telse:\n\t\tres = res % mod\nfor i in range(1, n - len(pr) + 1):\n\tres = res * i % mod\nprint(res)\n", "import sys\nMAX = 1000000007\n\ndef getSteps(n, pos):\n\tleft = 0\n\tright = n\n\tops = []\n\twhile left < right:\n\t\tcurPos = (left + right) // 2\n\t\tif curPos <= pos:\n\t\t\tif curPos == pos:\n\t\t\t\tops.append('X')\n\t\t\telse:\n\t\t\t\tops.append('S')\n\t\t\tleft = curPos + 1\n\t\telse:\n\t\t\tright = curPos\n\t\t\tops.append('L')\n\treturn ops\n\ndef solve(n, x, pos):\n\tsmallerNums = x - 1\n\tlargerNums = n - x\n\topsList = getSteps(n, pos)\n\ttotal = 1\n\tfor op in opsList:\n\t\tif op == 'L':\n\t\t\ttotal *= largerNums\n\t\t\tlargerNums -= 1\n\t\telif op == 'S':\n\t\t\ttotal *= smallerNums\n\t\t\tsmallerNums -= 1\n\t\tif total == 0:\n\t\t\treturn 0\n\tremainingNums = smallerNums + largerNums\n\twhile remainingNums > 1:\n\t\ttotal = total * remainingNums % MAX\n\t\tremainingNums -= 1\n\treturn total\n\ndef readinput():\n\t(n, x, pos) = map(int, sys.stdin.readline().rstrip().split(' '))\n\tprint(solve(n, x, pos))\nreadinput()\n", "import sys\nimport math\ninput = lambda : sys.stdin.readline().rstrip()\n(n, x, pos) = map(int, input().split())\nless = x - 1\nmore = n - x\nl = 0\nr = n\nc = 1\navail = n - 1\nmod = 10 ** 9 + 7\nwhile l < r:\n\tmid = (l + r) // 2\n\tif mid == pos:\n\t\tl = mid + 1\n\telif mid < pos:\n\t\tc *= less\n\t\tless -= 1\n\t\tl = mid + 1\n\t\tavail -= 1\n\telse:\n\t\tc *= more\n\t\tmore -= 1\n\t\tr = mid\n\t\tavail -= 1\nless += more\nc *= math.factorial(less)\nprint(c % mod)\n", "mod = 10 ** 9 + 7\n(n, x, pos) = map(int, input().split())\nans = 1\n(a, b, c) = (list(range(1, n + 1)), 0, 0)\n(l, r) = (0, n)\nwhile l < r:\n\tm = (l + r) // 2\n\tif a[m] <= pos + 1:\n\t\tif a[m] != pos + 1:\n\t\t\tb += 1\n\t\tl = m + 1\n\telse:\n\t\tr = m\n\t\tc += 1\nfor i in range(x - 1, max(x - 1 - b, -1), -1):\n\tans = ans * i % mod\nfor i in range(n - x, max(n - x - c, -1), -1):\n\tans = ans * i % mod\nfor i in range(n - c - b - 1, 0, -1):\n\tans = ans * i % mod\nprint(ans % mod)\n", "from functools import reduce\n\ndef count_choices(a, x):\n\t(left_b, right_b) = (0, 0)\n\tleft = 0\n\tright = a\n\twhile left < right:\n\t\tmiddle = int((left + right) / 2)\n\t\tif middle <= x:\n\t\t\tleft = middle + 1\n\t\t\tright_b += 1\n\t\telse:\n\t\t\tright = middle\n\t\t\tleft_b += 1\n\treturn [left_b, right_b - 1]\n(n, x, pos) = map(int, input().split(' '))\nlower_bound = x - 1\nupper_bound = n - x\n[gt_x, lt_x] = count_choices(n, pos)\nif lower_bound - lt_x < 0 or upper_bound - gt_x < 0:\n\tprint(0)\nelse:\n\tprint(reduce(lambda a, b: a * b % (10 ** 9 + 7), [*range(lower_bound, lower_bound - lt_x, -1)] + [*range(upper_bound, upper_bound - gt_x, -1)] + [*range(1, n - gt_x - lt_x)], 1))\n", "from sys import stdin, stdout\nfrom math import factorial as f\nfrom random import randint, shuffle\ninput = stdin.readline\nmod = 10 ** 9 + 7\n\ndef inv(x):\n\treturn pow(x, mod - 2, mod)\n\ndef c(n, k):\n\tif k < 0 or n < k:\n\t\treturn 0\n\treturn f[n] * inv(f[n - k]) % mod\n(n, x, p) = map(int, input().split())\nf = [1]\nfor i in range(1, n + 1):\n\tf.append(f[-1] * i % mod)\nl = 0\nr = n\na = b = 0\nwhile l < r:\n\tm = l + r >> 1\n\tif m == p:\n\t\tl = m + 1\n\telif m > p:\n\t\tr = m\n\t\ta += 1\n\telse:\n\t\tl = m + 1\n\t\tb += 1\nprint(c(x - 1, b) * c(n - x, a) * f[n - a - b - 1] % mod)\n", "from sys import stdin, stdout\n\ndef INI():\n\treturn int(stdin.readline())\n\ndef INL():\n\treturn [int(_) for _ in stdin.readline().split()]\n\ndef INS():\n\treturn stdin.readline()\n\ndef OPS(ans):\n\tstdout.write(str(ans) + '\\n')\n\ndef OPL(ans):\n\t[stdout.write(str(_) + ' ') for _ in ans]\n\tstdout.write('\\n')\nfrom math import factorial as F\n(n, x, pos) = INL()\nl = 0\nr = n\na = 0\nb = 0\nans = 1\nwhile l < r:\n\tm = (l + r) // 2\n\tif m <= pos:\n\t\tl = m + 1\n\t\ta += m != pos\n\telse:\n\t\tr = m\n\t\tb += 1\nfor _ in range(a):\n\tans *= x - 1 - _\nfor _ in range(b):\n\tans *= n - x - _\nans *= F(n - a - b - 1)\nOPS(ans % (pow(10, 9) + 7))\n", "import sys\nimport re\nimport random\nimport math\nimport copy\nfrom heapq import heappush, heappop, heapify\nfrom functools import cmp_to_key\nfrom bisect import bisect_left, bisect_right\nfrom collections import defaultdict, deque, Counter\ninput = sys.stdin.readline\ngetS = lambda : input().strip()\ngetN = lambda : int(input())\ngetList = lambda : list(map(int, input().split()))\ngetZList = lambda : [int(x) - 1 for x in input().split()]\nINF = float('inf')\nMOD = 10 ** 9 + 7\ndivide = lambda x: pow(x, MOD - 2, MOD)\n\ndef solve():\n\t(n, x, pos) = getList()\n\tdai = n - x\n\tsyo = x - 1\n\tans = 1\n\tl = 0\n\tr = n\n\twhile l < r:\n\t\tmid = (l + r) // 2\n\t\tif mid == pos:\n\t\t\tl = mid + 1\n\t\telif mid > pos:\n\t\t\tans *= dai\n\t\t\tans %= MOD\n\t\t\tdai -= 1\n\t\t\tr = mid\n\t\telse:\n\t\t\tans *= syo\n\t\t\tans %= MOD\n\t\t\tsyo -= 1\n\t\t\tl = mid + 1\n\tzan = dai + syo\n\tfor i in range(1, zan + 1):\n\t\tans *= i\n\t\tans %= MOD\n\tprint(ans)\n\ndef main():\n\tn = getN()\n\tfor _ in range(n):\n\t\tsolve()\n\treturn\nsolve()\n", "st = input().split()\nn = int(st[0])\nx = int(st[1])\npos = int(st[2])\nmniejsze = 0\nwieksze = 0\nleft = 0\nright = n\nwhile left < right:\n\tmiddle = (left + right) // 2\n\tif middle > pos:\n\t\twieksze += 1\n\t\tright = middle\n\telse:\n\t\tif middle < pos:\n\t\t\tmniejsze += 1\n\t\tleft = middle + 1\nl_wiekszych = n - x\nl_mniejszych = n - 1 - l_wiekszych\nresult = 1\nm = n - 1 - mniejsze - wieksze\nwhile m > 0:\n\tresult = m * result % 1000000007\n\tm -= 1\nm = l_wiekszych\nwhile wieksze > 0:\n\tresult = m * result % 1000000007\n\tm -= 1\n\twieksze -= 1\nm = l_mniejszych\nwhile mniejsze > 0:\n\tresult = m * result % 1000000007\n\tm -= 1\n\tmniejsze -= 1\nprint(result)\n", "from math import factorial\n(n, x, pos) = map(int, input().split())\nl = 0\nr = n\n(cng, cg) = (x - 1, n - x)\nansg = 1\nansng = 1\nwhile l < r:\n\tm = (l + r) // 2\n\tif m > pos:\n\t\tansg *= cg\n\t\tcg -= 1\n\t\tr = m\n\telif m < pos:\n\t\tansng *= cng\n\t\tcng -= 1\n\t\tl = m + 1\n\telse:\n\t\tl = m + 1\nans = 0\nif cg >= 0 and cng >= 0:\n\tans = ansg * ansng\n\tans *= factorial(cg + cng)\nprint(ans % (10 ** 9 + 7))\n", "vals = input().split()\nn = int(vals[0])\nx = int(vals[1])\npos = int(vals[2])\nbig = 0\nsmall = 0\nans = 1\n(l, r) = (0, n)\nwhile l < r:\n\tmid = (l + r) // 2\n\tif mid == pos:\n\t\tl = mid + 1\n\telif mid > pos:\n\t\tr = mid\n\t\tbig += 1\n\telse:\n\t\tl = mid + 1\n\t\tsmall += 1\nif small >= x or big > n - x:\n\tprint(0)\nelse:\n\tMOD = int(1000000000.0 + 7)\n\tfor i in range(1, small + 1):\n\t\tans = ans * (x - i) % MOD\n\tfor i in range(1, big + 1):\n\t\tans = ans * (n - x + 1 - i) % MOD\n\tfor i in range(1, n - small - big):\n\t\tans = ans * i % MOD\n\tprint(ans)\n", "(n, x, pos) = map(int, input().split())\n\ndef factoriel(n):\n\tif n < 2:\n\t\treturn 1\n\tb = n - 1\n\twhile b > 0:\n\t\tn *= b\n\t\tb -= 1\n\treturn n\n\ndef test():\n\tlow = 0\n\tbig = 0\n\tleft = 0\n\tright = n\n\twhile left < right:\n\t\tmiddle = (left + right) // 2\n\t\tif middle > pos:\n\t\t\tright = middle\n\t\t\tbig += 1\n\t\telse:\n\t\t\tleft = middle + 1\n\t\t\tlow += 1\n\treturn (low, big)\n(low, big) = test()\nlow -= 1\nans = 1\nt = x - 1\nfor i in range(low):\n\tans *= t\n\tt -= 1\nt = n - x\nfor i in range(big):\n\tans *= t\n\tt -= 1\nprint(ans * factoriel(n - 1 - (low + big)) % (10 ** 9 + 7))\n", "import sys\nfrom collections import defaultdict as dd\nfrom collections import Counter as cc\nfrom queue import Queue\nimport math\nimport itertools\ntry:\n\tsys.stdin = open('input.txt', 'r')\n\tsys.stdout = open('output.txt', 'w')\nexcept:\n\tpass\ninput = lambda : sys.stdin.buffer.readline().rstrip()\n\ndef pm(m, n, mod):\n\tk = 1\n\tfor i in range(m + 1, n + 1):\n\t\tk = k * i % mod\n\treturn k\nmod = 10 ** 9 + 7\n(n, x, p) = map(int, input().split())\nw = [2] * n\nleft = 0\nright = n\nwhile left < right:\n\tmiddle = (left + right) // 2\n\tif middle <= p:\n\t\tleft = middle + 1\n\t\tw[middle] = -1\n\telse:\n\t\tright = middle\n\t\tw[middle] = 1\na = 0\nb = 0\nc = 0\nw[p] = 0\nfor i in w:\n\tif i == 2:\n\t\ta += 1\n\telif i == 1:\n\t\tb += 1\n\telif i == -1:\n\t\tc += 1\nz = pm(0, a, mod) * pm(x - 1 - c, x - 1, mod) * pm(n - x - b, n - x, mod)\nprint(z % mod)\n", "import sys\nimport math\n\ndef II():\n\treturn int(sys.stdin.readline())\n\ndef LI():\n\treturn list(map(int, sys.stdin.readline().split()))\n\ndef MI():\n\treturn map(int, sys.stdin.readline().split())\n\ndef SI():\n\treturn sys.stdin.readline().strip()\n\ndef FACT(n, mod):\n\ts = 1\n\tfacts = [1]\n\tfor i in range(1, n + 1):\n\t\ts *= i\n\t\ts %= mod\n\t\tfacts.append(s)\n\treturn facts[n]\n\ndef C(n, k, mod):\n\treturn FACT(n, mod) * pow(FACT(k, mod) * FACT(n - k, mod) % mod, mod - 2, mod) % mod\n(n, x, pos) = MI()\nleft = 0\nright = n\nless = 0\nmore = 0\nwhile left < right:\n\tmiddle = (left + right) // 2\n\tif middle <= pos:\n\t\tif middle < pos:\n\t\t\tless += 1\n\t\tleft = middle + 1\n\telse:\n\t\tmore += 1\n\t\tright = middle\nhasLess = x - 1\nhasBig = n - x\nif less > hasLess or more > hasBig:\n\tprint(0)\nelse:\n\tmod = 10 ** 9 + 7\n\tans = FACT(less, mod) * C(hasBig, more, mod) % mod\n\tans = ans * FACT(more, mod) % mod\n\tans = ans * C(hasLess, less, mod) % mod\n\tans *= FACT(n - less - more - 1, mod)\n\tans %= mod\n\tprint(ans)\n", "def ncr(n, r, p):\n\tnum = den = 1\n\tfor i in range(r):\n\t\tnum = num * (n - i) % p\n\t\tden = den * (i + 1) % p\n\treturn num * pow(den, p - 2, p) % p\nmod = 10 ** 9 + 7\nt = 1\nfor _ in range(t):\n\t(n, x, pos) = map(int, input().split())\n\tleft = 0\n\tright = n\n\ta = 0\n\tb = 0\n\twhile left < right:\n\t\tmid = (left + right) // 2\n\t\tif pos < mid:\n\t\t\ta += 1\n\t\t\tright = mid\n\t\telif pos > mid:\n\t\t\tb += 1\n\t\t\tleft = mid + 1\n\t\telse:\n\t\t\tleft = mid + 1\n\tif n - x < a or x - 1 < b:\n\t\tprint(0)\n\telse:\n\t\tval1 = ncr(n - x, a, mod)\n\t\tval2 = ncr(x - 1, b, mod)\n\t\tans = val1 * val2 % mod\n\t\tfor i in range(1, a + 1):\n\t\t\tans = ans * i % mod\n\t\tfor i in range(1, b + 1):\n\t\t\tans = ans * i % mod\n\t\tfor i in range(1, n - (a + b)):\n\t\t\tans = ans * i % mod\n\t\tprint(ans)\n", "(n, a, b) = map(int, input().split())\nmod = 1000000000 + 7\nans = 1\n(cnt, cnt1) = (0, 0)\n(i, j) = (0, n)\nwhile i < j:\n\tmid = (i + j) // 2\n\tif mid < b:\n\t\tans *= a - 1 - cnt1\n\t\tans %= mod\n\t\tcnt1 += 1\n\t\ti = mid + 1\n\telif mid > b:\n\t\tans *= n - a - cnt\n\t\tans %= mod\n\t\tcnt += 1\n\t\tj = mid\n\telse:\n\t\ti = mid + 1\ncr = n - cnt - cnt1 - 1\nfor i in range(1, cr + 1):\n\tans *= i\n\tans %= mod\nprint(ans)\n", "(n, x, pos) = map(int, input().split())\nmo = int(1000000000.0 + 7)\nA = [1]\nfor i in range(1, 1010):\n\tA.append(A[-1] * i % mo)\n\ndef exgcd(a, b):\n\tif not b:\n\t\treturn (1, 0)\n\t(y, x) = exgcd(b, a % b)\n\ty -= a // b * x\n\treturn (x, y)\n\ndef getinv(a, m):\n\t(x, y) = exgcd(a, m)\n\treturn --1 if x == 1 else x % m\n\ndef comb(n, b):\n\tres = 1\n\tb = min(b, n - b)\n\tfor i in range(b):\n\t\tres = res * (n - i) * getinv(i + 1, mo) % mo\n\treturn res % mo\nlows = []\nhighs = []\nl = 0\nr = n\nwhile l < r:\n\tmid = l + r >> 1\n\tif mid <= pos:\n\t\tlows.append(mid)\n\t\tl = mid + 1\n\telse:\n\t\thighs.append(mid)\n\t\tr = mid\nalllow = x\nallhigh = n - x\nh = len(highs)\nl = len(lows)\nif alllow < l or allhigh < h:\n\tans = 0\nelse:\n\tans = comb(allhigh, h) * A[h] % mo * comb(alllow - 1, l - 1) * A[l - 1] % mo * A[n - h - l]\nprint(ans % mo)\n", "from math import factorial as f\n(n, x, pos) = list(map(int, input().split()))\ncg = n - x\ncl = x - 1\npg = 0\npl = 0\nl = 0\nr = n\nwhile l < r:\n\tm = (l + r) // 2\n\tif m <= pos:\n\t\tl = m + 1\n\t\tpl += 1\n\telse:\n\t\tr = m\n\t\tpg += 1\npl -= 1\nt1 = 1\nfor i in range(cg - pg + 1, cg + 1):\n\tt1 *= i\nt2 = 1\nfor i in range(cl - pl + 1, cl + 1):\n\tt2 *= i\ncount = t1 * t2 * f(n - 1 - pl - pg)\ncount %= 10 ** 9 + 7\nprint(count)\n", "from __future__ import print_function\nfrom collections import Counter, OrderedDict\nfrom itertools import permutations as perm\nfrom collections import deque\nfrom sys import stdin\nfrom bisect import *\nfrom heapq import *\nimport math\ng = lambda : stdin.readline().strip()\ngl = lambda : g().split()\ngil = lambda : [int(var) for var in gl()]\ngfl = lambda : [float(var) for var in gl()]\ngcl = lambda : list(g())\ngbs = lambda : [int(var) for var in g()]\nmod = int(1000000000.0) + 7\ninf = float('inf')\n(n, x, pos) = gil()\n(l, r) = (0, n)\n(inc, dec) = (0, 0)\nwhile l < r:\n\tmid = (l + r) // 2\n\tif mid <= pos:\n\t\tif mid != pos:\n\t\t\tdec += 1\n\t\tl = mid + 1\n\telse:\n\t\tr = mid\n\t\tinc += 1\n(INC, DEC, others) = (n - x, x - 1, max(0, n - 1 - inc - dec))\nans = 1\nfor i in range(dec):\n\tans *= DEC\n\tDEC -= 1\nfor i in range(inc):\n\tans *= INC\n\tINC -= 1\nleft = n - (inc + dec) - 1\nlt = left\nfor i in range(lt):\n\tans *= left\n\tleft -= 1\nprint(ans % mod)\n", "(n, x, pos) = input().split()\nn = int(n)\nx = int(x)\npos = int(pos)\nmod = 1000000000.0 + 7\nbig = n - x\nsmall = x - 1\nleft = 0\nright = n\nans = 1\nwhile left < right:\n\tmiddle = (left + right) // 2\n\tn -= 1\n\tif middle == pos:\n\t\tleft = middle + 1\n\t\tcontinue\n\telif middle > pos:\n\t\tans = ans * big % mod\n\t\tright = middle\n\t\tif big == 0:\n\t\t\tprint(0)\n\t\t\texit()\n\t\tbig -= 1\n\telif middle < pos:\n\t\tleft = middle + 1\n\t\tans = ans * small % mod\n\t\tif small == 0:\n\t\t\tprint(0)\n\t\t\texit()\n\t\tsmall -= 1\nfor i in range(1, n + 1):\n\tans = ans * i % mod\nprint(int(ans))\n", "from functools import reduce\n(n, x, p) = list(map(int, input().split()))\na = 0\nb = -1\nleft = 0\nright = n\nwhile left < right:\n\tmiddle = (left + right) // 2\n\tif p >= middle:\n\t\tleft = middle + 1\n\t\tb += 1\n\telse:\n\t\tright = middle\n\t\ta += 1\nf = 1\nF1 = 1\nF2 = 1\nF3 = 1\nF4 = 1\nF5 = 1\nfor i in range(1, n + 1):\n\tf *= i\n\tif i == x - 1:\n\t\tF1 = f\n\tif i == x - b - 1:\n\t\tF2 = f\n\tif i == n - x:\n\t\tF3 = f\n\tif i == n - x - a:\n\t\tF4 = f\n\tif i == n - a - b - 1:\n\t\tF5 = f\nans = F1 * F3 * F5 // (F2 * F4)\nif x - 1 - b < 0 or n - x - a < 0 or n - a - b - 1 < 0:\n\tprint(0)\nelse:\n\tprint(ans % (10 ** 9 + 7))\n", "from functools import reduce\nimport os\nimport sys\nfrom collections import *\nfrom math import *\nfrom bisect import *\nfrom heapq import *\nfrom io import BytesIO, IOBase\ninput = lambda : sys.stdin.readline().rstrip('\\r\\n')\n\ndef value():\n\treturn tuple(map(int, input().split()))\n\ndef arr():\n\treturn [int(i) for i in input().split()]\n\ndef sarr():\n\treturn [int(i) for i in input()]\n\ndef starr():\n\treturn [str(x) for x in input().split()]\n\ndef inn():\n\treturn int(input())\n\ndef svalue():\n\treturn tuple(map(str, input().split()))\n\ndef parr():\n\treturn [value() for i in range(n)]\nmo = 1000000007\ninf = 1e+18\ndiv = 998244353\n\ndef ncr(n, r):\n\tp = 1\n\tk = 1\n\tif n - r < r:\n\t\tr = n - r\n\tif r != 0:\n\t\twhile r:\n\t\t\tp *= n\n\t\t\tk *= r\n\t\t\tm = gcd(p, k)\n\t\t\tp //= m\n\t\t\tk //= m\n\t\t\tn -= 1\n\t\t\tr -= 1\n\telse:\n\t\tp = 1\n\treturn p\n(n, x, pos) = value()\nl = 0\nh = n\nsmall = x - 1\nbig = n - x\nans = 1\nwhile l < h:\n\tm = (l + h) // 2\n\tif m == pos:\n\t\tl = m + 1\n\telif m < pos:\n\t\tans = ans * small % mo\n\t\tsmall -= 1\n\t\tl = m + 1\n\telse:\n\t\tans = ans * big % mo\n\t\tbig -= 1\n\t\th = m\nval = big + small\nres = 1\nfor i in range(1, val + 1):\n\tres = res * i % mo\nprint(ans * res % mo)\n", "mod = 10 ** 9 + 7\nfact = [0] * 1001\nfact[0] = 1\nfor i in range(1, 1001):\n\tfact[i] = fact[i - 1] * i % mod\nncr = [[0] * 16 for i in range(1001)]\nncr[0][0] = 1\nncr[1][0] = 1\nncr[1][1] = 1\nfor i in range(2, 1001):\n\tncr[i][0] = 1\n\tfor j in range(1, min(i + 1, 16)):\n\t\tncr[i][j] = (ncr[i - 1][j - 1] + ncr[i - 1][j]) % mod\n\ndef bs(x, n):\n\tl = 0\n\tr = n\n\tleft = 0\n\tright = 0\n\twhile l < r:\n\t\tmid = (l + r) // 2\n\t\tif mid > x:\n\t\t\tr = mid\n\t\t\tright += 1\n\t\telse:\n\t\t\tif mid != x:\n\t\t\t\tleft += 1\n\t\t\tl = mid + 1\n\treturn [left, right]\n(n, x, pos) = map(int, input().split())\n(l, r) = bs(pos, n)\nans = fact[n - (l + r) - 1]\nans = ans * ncr[n - x][r] * fact[r] % mod\nans = ans * ncr[x - 1][l] * fact[l] % mod\nprint(ans % mod)\n", "[n, k, pos] = [int(i) for i in input().split()]\nl = 0\nr = n\nc1 = 0\nc2 = 0\nwhile l < r:\n\tm = (l + r) // 2\n\tif m <= pos:\n\t\tc1 += 1\n\t\tl = m + 1\n\telse:\n\t\tc2 += 1\n\t\tr = m\nans = 1\nfor i in range(n - (c1 + c2)):\n\tans = ans * (i + 1)\n\tans = ans % 1000000007\nc1 -= 1\np1 = k - 1\np2 = n - k\nfor i in range(c1):\n\tans = ans * p1\n\tans = ans % 1000000007\n\tp1 -= 1\nfor i in range(c2):\n\tans = ans * p2\n\tans = ans % 1000000007\n\tp2 -= 1\nprint(ans)\n", "import sys\ninput = sys.stdin.readline\n(n, x, pos) = list(map(int, input().split()))\nmod = 10 ** 9 + 7\nANS = [0] * n\nleft = 0\nright = n\nwhile left < right:\n\tmiddle = (left + right) // 2\n\tif pos >= middle:\n\t\tANS[middle] = -1\n\t\tleft = middle + 1\n\telse:\n\t\tANS[middle] = 1\n\t\tright = middle\nANS[pos] = 9\nP = ANS.count(1)\nM = ANS.count(-1)\nMINUS = x - 1\nPLUS = n - x\nA = 1\nfor i in range(P):\n\tA = A * PLUS % mod\n\tPLUS -= 1\nfor i in range(M):\n\tA = A * MINUS % mod\n\tMINUS -= 1\nfor i in range(1, n - P - M):\n\tA = A * i % mod\nprint(A)\n", "import math\nteststring = '123 42 24\\n'\nonline = 'Problem_C' not in __file__\n(true, false) = (True, False)\nif True:\n\n\tdef spitout():\n\t\tfor c in teststring.splitlines():\n\t\t\tyield c\n\t_ito = spitout()\n\tif not online:\n\n\t\tdef input():\n\t\t\treturn next(_ito)\n\n\tdef build_enum(*a):\n\t\tbuilt = dict()\n\t\tfor (i, c) in enumerate(a):\n\t\t\tbuilt[c] = i\n\t\treturn lambda x: built[x]\n\ndef egcd(a, b):\n\tif a == 0:\n\t\treturn (b, 0, 1)\n\telse:\n\t\t(g, y, x) = egcd(b % a, a)\n\t\treturn (g, x - b // a * y, y)\n\ndef modinv(a):\n\t(g, x, y) = egcd(a, P)\n\tif g != 1:\n\t\traise Exception('modular inverse does not exist')\n\telse:\n\t\treturn x % P\n[n, x, pos] = map(int, input().split(' '))\nP = 1000000007\na = b = 0\nl = 0\nr = n\nwhile l < r:\n\tm = int((l + r) / 2)\n\tif m <= pos:\n\t\tl = m + 1\n\t\tif m < pos:\n\t\t\ta += 1\n\telse:\n\t\tr = m\n\t\tb += 1\nif a > x - 1 or b > n - x:\n\tans = 0\nelse:\n\tans = 1\n\tfac = [1] * (n + 1)\n\tfor i in range(n):\n\t\tfac[i + 1] = fac[i] * (i + 1) % P\n\tans = ans * fac[x - 1] % P\n\tans = ans * fac[n - x] % P\n\tans = ans * fac[n - a - b - 1] % P\n\tans = ans * modinv(fac[x - 1 - a]) % P\n\tans = ans * modinv(fac[n - x - b]) % P\nprint(ans)\n", "import sys\ninput = sys.stdin.buffer.readline\n\ndef fact(x):\n\ty = 1\n\tfor i in range(1, x + 1):\n\t\ty *= i\n\t\ty %= 10 ** 9 + 7\n\treturn y\n\ndef solution():\n\t(n, x, pos) = map(int, input().split())\n\tbeg = 0\n\tend = n\n\tmod = 10 ** 9 + 7\n\tans = 1\n\tbig = n - x\n\tsmall = x - 1\n\tmid = (beg + end) // 2\n\twhile beg < end:\n\t\tmid = (beg + end) // 2\n\t\tif mid == pos:\n\t\t\tbeg = mid + 1\n\t\telif mid > pos:\n\t\t\tans *= big\n\t\t\tans = ans % mod\n\t\t\tif big > 0:\n\t\t\t\tbig -= 1\n\t\t\tend = mid\n\t\telse:\n\t\t\tans *= small\n\t\t\tans %= mod\n\t\t\tif small > 0:\n\t\t\t\tsmall -= 1\n\t\t\tbeg = mid + 1\n\tif beg <= 0:\n\t\tprint(0)\n\t\treturn\n\tans *= fact(big + small)\n\tans %= mod\n\tprint(ans)\nt = 1\nfor _ in range(t):\n\tsolution()\n", "(a, e, x) = [int(i) for i in input().split()]\n(b, s) = (a - e, e - 1)\n(l, r, c, res) = (0, a, a - 1, 1)\nmodulo = 10 ** 9 + 7\nwhile l < r:\n\tm = (l + r) // 2\n\tif m < x:\n\t\tc -= 1\n\t\tl = m + 1\n\t\tres *= s % (10 ** 9 + 7)\n\t\ts -= 1\n\telif m == x:\n\t\tres = res\n\t\tl = m + 1\n\telse:\n\t\tc -= 1\n\t\tres *= b % modulo\n\t\tb -= 1\n\t\tr = m\nf = 1\nfor i in range(1, c + 1):\n\tf *= i % modulo\nprint(res * f % modulo)\n", "import sys, math, itertools\nfrom collections import Counter, deque, defaultdict\nfrom bisect import bisect_left, bisect_right\nmod = 10 ** 9 + 7\nINF = float('inf')\n\ndef inp():\n\treturn int(sys.stdin.readline())\n\ndef inpl():\n\treturn list(map(int, sys.stdin.readline().split()))\n\nclass Combination:\n\n\tdef __init__(self, n_max, mod=10 ** 9 + 7):\n\t\tself.mod = mod\n\t\tself.modinv = self.make_modinv_list(n_max)\n\t\t(self.fac, self.facinv) = self.make_factorial_list(n_max)\n\n\tdef __call__(self, n, r):\n\t\treturn self.fac[n] * self.facinv[r] % self.mod * self.facinv[n - r] % self.mod\n\n\tdef make_factorial_list(self, n):\n\t\tfac = [1]\n\t\tfacinv = [1]\n\t\tfor i in range(1, n + 1):\n\t\t\tfac.append(fac[i - 1] * i % self.mod)\n\t\t\tfacinv.append(facinv[i - 1] * self.modinv[i] % self.mod)\n\t\treturn (fac, facinv)\n\n\tdef make_modinv_list(self, n):\n\t\tmodinv = [0] * (n + 1)\n\t\tmodinv[1] = 1\n\t\tfor i in range(2, n + 1):\n\t\t\tmodinv[i] = self.mod - self.mod // i * modinv[self.mod % i] % self.mod\n\t\treturn modinv\ncomb = Combination(1010)\n(n, x, pos) = inpl()\nl = 0\nr = n\nlcnt = rcnt = 0\nwhile l < r:\n\tmid = (l + r) // 2\n\tif mid == pos:\n\t\tl = mid + 1\n\telif mid < pos:\n\t\tlcnt += 1\n\t\tl = mid + 1\n\telse:\n\t\trcnt += 1\n\t\tr = mid\nif x - 1 < lcnt or n - x < rcnt:\n\tprint(0)\n\tquit()\nelse:\n\tres = 1\n\tif not x - 1 == lcnt == 0:\n\t\tres *= comb(x - 1, lcnt)\n\t\tres %= mod\n\tif not n - x == rcnt == 0:\n\t\tres *= comb(n - x, rcnt)\n\t\tres %= mod\n\tfor i in range(1, lcnt + 1):\n\t\tres *= i\n\t\tres %= mod\n\tfor i in range(1, rcnt + 1):\n\t\tres *= i\n\t\tres %= mod\n\tfor i in range(1, n - lcnt - rcnt):\n\t\tres *= i\n\t\tres %= mod\n\tprint(res)\n", "(n, val, pos) = map(int, input().split())\nless = val - 1\nlarge = n - val\ns = 0\ne = n\nans = 1\nwhile s < e:\n\tmid = (s + e) // 2\n\tif mid < pos:\n\t\ts = mid + 1\n\t\tans *= less\n\t\tless -= 1\n\telif mid > pos:\n\t\te = mid\n\t\tans *= large\n\t\tlarge -= 1\n\telse:\n\t\ts = mid + 1\nless += large\nif less > 0:\n\tfor i in range(less, 0, -1):\n\t\tans *= i\nprint(ans % (10 ** 9 + 7))\n", "import sys\nfrom math import gcd, sqrt, ceil, log2\nfrom collections import defaultdict, Counter, deque\nfrom bisect import bisect_left, bisect_right\nimport math\nimport heapq\nfrom itertools import permutations\nimport os\nimport sys\nfrom io import BytesIO, IOBase\nBUFSIZE = 8192\n\nclass FastIO(IOBase):\n\tnewlines = 0\n\n\tdef __init__(self, file):\n\t\tself._fd = file.fileno()\n\t\tself.buffer = BytesIO()\n\t\tself.writable = 'x' in file.mode or 'r' not in file.mode\n\t\tself.write = self.buffer.write if self.writable else None\n\n\tdef read(self):\n\t\twhile True:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tif not b:\n\t\t\t\tbreak\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines = 0\n\t\treturn self.buffer.read()\n\n\tdef readline(self):\n\t\twhile self.newlines == 0:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tself.newlines = b.count(b'\\n') + (not b)\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines -= 1\n\t\treturn self.buffer.readline()\n\n\tdef flush(self):\n\t\tif self.writable:\n\t\t\tos.write(self._fd, self.buffer.getvalue())\n\t\t\t(self.buffer.truncate(0), self.buffer.seek(0))\n\nclass IOWrapper(IOBase):\n\n\tdef __init__(self, file):\n\t\tself.buffer = FastIO(file)\n\t\tself.flush = self.buffer.flush\n\t\tself.writable = self.buffer.writable\n\t\tself.write = lambda s: self.buffer.write(s.encode('ascii'))\n\t\tself.read = lambda : self.buffer.read().decode('ascii')\n\t\tself.readline = lambda : self.buffer.readline().decode('ascii')\n(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))\ninput = lambda : sys.stdin.readline().rstrip('\\r\\n')\n\ndef get_sum(bit, i):\n\ts = 0\n\ti += 1\n\twhile i > 0:\n\t\ts += bit[i]\n\t\ti -= i & -i\n\treturn s\n\ndef update(bit, n, i, v):\n\ti += 1\n\twhile i <= n:\n\t\tbit[i] += v\n\t\ti += i & -i\n\ndef modInverse(b, m):\n\tg = math.gcd(b, m)\n\tif g != 1:\n\t\treturn -1\n\telse:\n\t\treturn pow(b, m - 2, m)\n\ndef primeFactors(n):\n\tsa = set()\n\tsa.add(n)\n\twhile n % 2 == 0:\n\t\tsa.add(2)\n\t\tn = n // 2\n\tfor i in range(3, int(math.sqrt(n)) + 1, 2):\n\t\twhile n % i == 0:\n\t\t\tsa.add(i)\n\t\t\tn = n // i\n\treturn sa\n\ndef seive(n):\n\tpri = [True] * (n + 1)\n\tp = 2\n\twhile p * p <= n:\n\t\tif pri[p] == True:\n\t\t\tfor i in range(p * p, n + 1, p):\n\t\t\t\tpri[i] = False\n\t\tp += 1\n\treturn pri\n\ndef check_prim(n):\n\tif n < 0:\n\t\treturn False\n\tfor i in range(2, int(sqrt(n)) + 1):\n\t\tif n % i == 0:\n\t\t\treturn False\n\treturn True\n\ndef getZarr(string, z):\n\tn = len(string)\n\t(l, r, k) = (0, 0, 0)\n\tfor i in range(1, n):\n\t\tif i > r:\n\t\t\t(l, r) = (i, i)\n\t\t\twhile r < n and string[r - l] == string[r]:\n\t\t\t\tr += 1\n\t\t\tz[i] = r - l\n\t\t\tr -= 1\n\t\telse:\n\t\t\tk = i - l\n\t\t\tif z[k] < r - i + 1:\n\t\t\t\tz[i] = z[k]\n\t\t\telse:\n\t\t\t\tl = i\n\t\t\t\twhile r < n and string[r - l] == string[r]:\n\t\t\t\t\tr += 1\n\t\t\t\tz[i] = r - l\n\t\t\t\tr -= 1\n\ndef search(text, pattern):\n\tconcat = pattern + '$' + text\n\tl = len(concat)\n\tz = [0] * l\n\tgetZarr(concat, z)\n\tha = []\n\tfor i in range(l):\n\t\tif z[i] == len(pattern):\n\t\t\tha.append(i - len(pattern) - 1)\n\treturn ha\n\ndef mergeIntervals(arr):\n\tarr.sort(key=lambda x: x[0])\n\tm = []\n\ts = -10000\n\tmax = -100000\n\tfor i in range(len(arr)):\n\t\ta = arr[i]\n\t\tif a[0] > max:\n\t\t\tif i != 0:\n\t\t\t\tm.append([s, max])\n\t\t\tmax = a[1]\n\t\t\ts = a[0]\n\t\telif a[1] >= max:\n\t\t\tmax = a[1]\n\tif max != -100000 and [s, max] not in m:\n\t\tm.append([s, max])\n\treturn m\n\ndef ncr(n, r, p):\n\tnum = den = 1\n\tfor i in range(r):\n\t\tnum = num * (n - i) % p\n\t\tden = den * (i + 1) % p\n\treturn num * pow(den, p - 2, p) % p\n\ndef sea(a, x):\n\tleft = 0\n\tright = len(a)\n\twhile left < right:\n\t\tmiddle = (left + right) // 2\n\t\tif a[middle] <= x:\n\t\t\tleft = middle + 1\n\t\telse:\n\t\t\tright = middle\n\tif left > 0 and a[left - 1] == x:\n\t\treturn True\n\telse:\n\t\treturn False\n(n, x, p) = map(int, input().split())\nla = [i for i in range(1, n + 1)]\nl = 0\nr = n\npos1 = 0\nsm = x - 1\nbi = n - x\npos2 = 0\nwhile l < r:\n\tmid = (l + r) // 2\n\tif mid < p:\n\t\tl = mid + 1\n\t\tpos1 += 1\n\telif mid == p:\n\t\tl = mid + 1\n\telse:\n\t\tr = mid\n\t\tpos2 += 1\nz = n - pos1 - pos2 - 1\nans = 0\nmod = 10 ** 9 + 7\nfa = [1]\nfor i in range(1, n + 10):\n\tfa.append(i * fa[i - 1] % mod)\nans += fa[z] * ncr(sm, pos1, mod) * ncr(bi, pos2, mod) * fa[pos2] * fa[pos1]\nprint(ans % mod)\n", "from sys import stdin, stdout\nimport math, sys, heapq\nfrom itertools import permutations, combinations\nfrom collections import defaultdict, deque, OrderedDict\nfrom os import path\nimport random\nimport bisect as bi\n\ndef yes():\n\tprint('YES')\n\ndef no():\n\tprint('NO')\nif path.exists('input.txt'):\n\tsys.stdin = open('input.txt', 'r')\n\tsys.stdout = open('output.txt', 'w')\n\n\tdef I():\n\t\treturn int(input())\n\n\tdef In():\n\t\treturn map(int, input().split())\nelse:\n\n\tdef I():\n\t\treturn int(stdin.readline())\n\n\tdef In():\n\t\treturn map(int, stdin.readline().split())\n\ndef dict(a):\n\td = {}\n\tfor x in a:\n\t\tif d.get(x, -1) != -1:\n\t\t\td[x] += 1\n\t\telse:\n\t\t\td[x] = 1\n\treturn d\n\ndef find_gt(a, x):\n\ti = bi.bisect_left(a, x)\n\tif i != len(a):\n\t\treturn i\n\telse:\n\t\treturn -1\n\ndef ncr(n, r, p):\n\tnum = den = 1\n\tfor i in range(r):\n\t\tnum = num * (n - i) % p\n\t\tden = den * (i + 1) % p\n\treturn num * pow(den, p - 2, p) % p\n\ndef main():\n\ttry:\n\t\t(n, x, pos) = In()\n\t\tlow = 0\n\t\thigh = n\n\t\tt = []\n\t\t(noH, noS) = (0, 0)\n\t\twhile low < high:\n\t\t\tmid = (low + high) // 2\n\t\t\tif mid <= pos:\n\t\t\t\tlow = mid + 1\n\t\t\t\tt.append(['S', low])\n\t\t\t\tnoS += 1\n\t\t\telse:\n\t\t\t\thigh = mid\n\t\t\t\tt.append(['H', high])\n\t\t\t\tnoH += 1\n\t\tnoS -= 1\n\t\ttotalH = n - x\n\t\ttotalL = x - 1\n\t\tif totalH < noH or totalL < noS:\n\t\t\tprint(0)\n\t\telse:\n\t\t\tans = ncr(totalH, noH, P) * ncr(totalL, noS, P)\n\t\t\tfact = n - 1 - noH - noS\n\t\t\tfor i in range(1, fact + 1):\n\t\t\t\tans = i % P * (ans % P) % P\n\t\t\tfor i in range(1, noH + 1):\n\t\t\t\tans = i % P * (ans % P) % P\n\t\t\tfor i in range(1, noS + 1):\n\t\t\t\tans = i % P * (ans % P) % P\n\t\t\tprint(ans)\n\texcept:\n\t\tpass\nM = 998244353\nP = 1000000007\nfor _ in range(1):\n\tmain()\n", "(n, x, pos) = map(int, input().split())\n\ndef fact(n):\n\tif n == 1 or n == 0:\n\t\treturn 1\n\treturn n * fact(n - 1) % (pow(10, 9) + 7)\narr = []\nc = 0\nfor i in range(n):\n\tif i < pos:\n\t\tarr.append(x - c)\n\t\tc = c + 1\n\telif i > pos:\n\t\tarr.append(x + c)\n\t\tc = c + 1\n\telse:\n\t\tarr.append(x)\n\ndef bs(arr, x, s):\n\twhile True:\n\t\tl = 0\n\t\tr = len(arr)\n\t\twhile l < r:\n\t\t\tmid = (l + r) // 2\n\t\t\ts.add(mid)\n\t\t\tif arr[mid] <= x:\n\t\t\t\tl = mid + 1\n\t\t\telse:\n\t\t\t\tr = mid\n\t\tif l > 0 and arr[l - 1] == x:\n\t\t\treturn True\n\t\telse:\n\t\t\treturn False\ns = set()\nbs(arr, x, s)\ncrr = []\nfor i in s:\n\tif i < pos:\n\t\tcrr.append(-1)\n\telif i > pos:\n\t\tcrr.append(1)\nans = 1\nbc = n - x\ncc = x - 1\nfor i in crr:\n\tif i == 1:\n\t\tans = ans * bc\n\t\tbc = bc - 1\n\tif i == -1:\n\t\tans = ans * cc\n\t\tcc = cc - 1\nans = ans * fact(n - len(crr) - 1) % (pow(10, 9) + 7)\nprint(ans)\n", "def bs(a, x):\n\tleft = 0\n\tright = len(a)\n\t(b, s) = (0, 0)\n\twhile left < right:\n\t\tmiddle = (left + right) // 2\n\t\tif a[middle] <= x:\n\t\t\tleft = middle + 1\n\t\t\tif a[middle] != x:\n\t\t\t\ts += 1\n\t\telse:\n\t\t\tright = middle\n\t\t\tb += 1\n\treturn (b, s)\n\ndef fac(n):\n\ta = 1\n\tfor i in range(1, n + 1):\n\t\ta = a * i\n\t\ta = a % (10 ** 9 + 7)\n\treturn a\n\ndef rfac(n):\n\ta = 1\n\tfor i in range(1, n + 1):\n\t\ta = a * i\n\treturn a\n\ndef choice(x, y):\n\treturn rfac(x) // (rfac(y) * rfac(x - y))\n\ndef f(n, x, pos):\n\ta = [x - pos + i for i in range(n)]\n\t(b, s) = bs(a, x)\n\ttb = n - x\n\tts = n - tb - 1\n\tif tb < b or ts < s:\n\t\treturn 0\n\tret = 0\n\tret = choice(tb, b) * choice(ts, s) * fac(tb - b + ts - s) * fac(b) * fac(s)\n\tret = ret % (10 ** 9 + 7)\n\treturn ret\n(n, x, pos) = [int(i) for i in input().split(' ')]\nprint(f(n, x, pos))\n", "import sys\ninput = sys.stdin.readline\nmax_n = 1000\n(fact, inv_fact) = ([0] * (max_n + 1), [0] * (max_n + 1))\nfact[0] = 1\nmod = 10 ** 9 + 7\n\ndef make_nCr_mod():\n\tglobal fact\n\tglobal inv_fact\n\tfor i in range(max_n):\n\t\tfact[i + 1] = fact[i] * (i + 1) % mod\n\tinv_fact[-1] = pow(fact[-1], mod - 2, mod)\n\tfor i in reversed(range(max_n)):\n\t\tinv_fact[i] = inv_fact[i + 1] * (i + 1) % mod\nmake_nCr_mod()\n\ndef nPr_mod(n, r):\n\tif r > n:\n\t\treturn 0\n\treturn fact[n] * inv_fact[n - r] % mod\n(n, x, pos) = map(int, input().split())\nleft = 0\nright = n\nsmaller_required = 0\nlarger_required = 0\nwhile left < right:\n\tmid = (left + right) // 2\n\tif pos >= mid:\n\t\tleft = mid + 1\n\t\tif pos != mid:\n\t\t\tsmaller_required += 1\n\telse:\n\t\tlarger_required += 1\n\t\tright = mid\ntotal_smaller = x - 1\ntotal_larger = n - x\nno_restriction = n - smaller_required - larger_required - 1\nprint(nPr_mod(total_larger, larger_required) * nPr_mod(total_smaller, smaller_required) * fact[no_restriction] % mod)\n", "from math import *\nmod = 1000000007\n\ndef nCr(n, r):\n\tif r > n:\n\t\treturn 0\n\tnum = factorial(n)\n\tden = factorial(r)\n\tan = factorial(n - r)\n\tval = den * an\n\treturn num // val\n(n, x, pos) = map(int, input().split())\nleft = 0\nright = n\n(cnts, cntb) = (0, 0)\nwhile left < right:\n\tmid = (left + right) // 2\n\tif mid > pos:\n\t\tcntb += 1\n\tif mid < pos:\n\t\tcnts += 1\n\tif mid <= pos:\n\t\tleft = mid + 1\n\telse:\n\t\tright = mid\na = nCr(x - 1, cnts) % mod\nb = nCr(n - x, cntb) % mod\nc = factorial(n - 1 - cnts - cntb) % mod\nd = factorial(cnts) % mod\ne = factorial(cntb) % mod\nprint(a * b * c * d * e % mod)\n", "import sys\nfrom functools import lru_cache, cmp_to_key\nfrom heapq import merge, heapify, heappop, heappush, nsmallest\nfrom math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf\nfrom collections import defaultdict as dd, deque, Counter as C\nfrom itertools import combinations as comb, permutations as perm\nfrom bisect import bisect_left as bl, bisect_right as br, bisect\nfrom time import perf_counter\nfrom fractions import Fraction\nfrom decimal import Decimal\nmod = pow(10, 9) + 7\n\ndef data():\n\treturn sys.stdin.readline().strip()\n\ndef out(var):\n\tsys.stdout.write(str(var) + '\\n')\n\ndef outa(*var, end='\\n'):\n\tsys.stdout.write(' '.join(map(str, var)) + end)\n\ndef l():\n\treturn list(sp())\n\ndef sl():\n\treturn list(ssp())\n\ndef sp():\n\treturn map(int, data().split())\n\ndef ssp():\n\treturn map(str, data().split())\n\ndef l1d(n, val=0):\n\treturn [val for i in range(n)]\n\ndef l2d(n, m, val=0):\n\treturn [l1d(n, val) for j in range(m)]\nfact = [1] * 1001\nrev = [1] * 1001\nfor i in range(2, 1001):\n\tfact[i] = fact[i - 1] * i % mod\n\trev[i] = pow(fact[i], mod - 2, mod)\n(n, x, k) = sp()\n(low, high) = (0, n)\n(g, s) = (0, 0)\nwhile low < high:\n\tmid = (low + high) // 2\n\tif mid <= k:\n\t\ts += 1\n\t\tlow = mid + 1\n\telse:\n\t\tg += 1\n\t\thigh = mid\ns -= 1\n(greater, smaller) = (n - x, x - 1)\nif g > greater or s > smaller:\n\tout(0)\n\texit()\ntot = n - 1 - s - g\nanswer = fact[tot]\nanswer = answer * fact[greater] % mod\nanswer = answer * fact[smaller] % mod\nanswer = answer * rev[greater - g] % mod\nanswer = answer * rev[smaller - s] % mod\nout(answer)\n", "import sys\nfrom os import path\nMOD = 1000000000.0 + 7\n\ndef open_inputs():\n\tif path.exists('input.txt'):\n\t\tsys.stdin = open('input.txt', 'r')\n\t\tsys.stdout = open('output.txt', 'w')\n\ndef get_int():\n\treturn int(sys.stdin.readline().strip())\n\ndef get_ints():\n\treturn list(map(int, sys.stdin.readline().strip().split()))\n\ndef com(_n: int, _x: int, _p: int):\n\ttotal_less = 0\n\ttotal_great = 0\n\tL = 0\n\tR = _n\n\twhile L < R:\n\t\tmiddle = int((L + R) / 2)\n\t\tif middle == _p:\n\t\t\tL = middle + 1\n\t\telif middle > _p:\n\t\t\tR = middle\n\t\t\ttotal_great += 1\n\t\telse:\n\t\t\tL = middle + 1\n\t\t\ttotal_less += 1\n\tresult = 1\n\tfor i in range(total_less):\n\t\tval = _x - 1 - i\n\t\tresult *= val\n\t\tresult %= MOD\n\tfor i in range(total_great):\n\t\tval = _n - _x - i\n\t\tresult *= val\n\t\tresult %= MOD\n\tbalance = _n - total_great - total_less - 1\n\tfor i in range(2, balance + 1):\n\t\tresult *= i\n\t\tresult %= MOD\n\tprint(int(result))\n\ndef main():\n\topen_inputs()\n\t[a, b, c] = get_ints()\n\tcom(a, b, c)\nmain()\n", "def search(a, x):\n\tleft = 0\n\tright = len(a)\n\twhile left < right:\n\t\tmiddle = (left + right) // 2\n\t\tif a[middle] <= x:\n\t\t\tleft = middle + 1\n\t\telse:\n\t\t\tright = middle\n\tif left > 0 and a[left - 1] == x:\n\t\treturn True\n\telse:\n\t\treturn False\n\ndef perm(n, r):\n\tif n < r:\n\t\treturn 0\n\tans = 1\n\tk = n\n\twhile k > n - r:\n\t\tans *= k\n\t\tk -= 1\n\treturn ans\n\ndef fact(x):\n\tif x < 0:\n\t\treturn 0\n\tans = 1\n\twhile x:\n\t\tans *= x\n\t\tx -= 1\n\treturn ans\n(n, x, p) = map(int, input().split())\nb = [0] * n\nleft = 0\nright = n\nsmall = -1\nlarge = 0\nwhile left < right:\n\tmiddle = (left + right) // 2\n\tif middle <= p:\n\t\tleft = middle + 1\n\t\tb[middle] = -1\n\t\tsmall += 1\n\telse:\n\t\tright = middle\n\t\tb[middle] = 1\n\t\tlarge += 1\nans = perm(x - 1, small) * perm(n - x, large) * fact(n - 1 - small - large)\nprint(ans % (10 ** 9 + 7))\n", "from sys import stdout\nfrom sys import stdin\n\ndef get():\n\treturn stdin.readline().strip()\n\ndef getf(sp=' '):\n\treturn [int(i) for i in get().split(sp)]\n\ndef put(a, end='\\n'):\n\tstdout.write(str(a) + end)\n\ndef putf(a, sep=' ', end='\\n'):\n\tstdout.write(sep.join([str(i) for i in a]) + end)\n\ndef fact_mod(n):\n\tans = 1\n\tm = 10 ** 9 + 7\n\tfor i in range(2, n + 1):\n\t\tans = ans * i % m\n\treturn ans\n\ndef main():\n\t(n, x, pos) = getf()\n\tl = 0\n\tr = n\n\tusd = [False] * n\n\tusd[pos] = True\n\tcan = [1] * n\n\tcan_l = x - 1\n\tcan_r = n - x\n\twhile l < r:\n\t\tmid = (l + r) // 2\n\t\tif mid <= pos:\n\t\t\tif usd[mid] == False:\n\t\t\t\tusd[mid] = True\n\t\t\t\tcan[mid] = can_l\n\t\t\t\tcan_l -= 1\n\t\t\tl = mid + 1\n\t\telse:\n\t\t\tif usd[mid] == False:\n\t\t\t\tusd[mid] = True\n\t\t\t\tcan[mid] = can_r\n\t\t\t\tcan_r -= 1\n\t\t\tr = mid\n\tans = fact_mod(can_l + can_r)\n\tm = 10 ** 9 + 7\n\tfor i in range(n):\n\t\tans = ans * can[i] % m\n\tput(ans)\nmain()\n", "from math import factorial\n(n, x, pos) = map(int, input().split())\nMOD = 10 ** 9 + 7\n(small, big, ans) = (x - 1, n - x, 1)\n(l, r) = (0, n)\nwhile l < r:\n\tmid = (l + r) // 2\n\tif mid < pos:\n\t\tans *= small\n\t\tsmall -= 1\n\t\tl = mid + 1\n\telif mid > pos:\n\t\tans *= big\n\t\tbig -= 1\n\t\tr = mid\n\telse:\n\t\tl = mid + 1\nans *= factorial(small + big)\nprint(ans % MOD)\n", "from sys import stdin, stdout\nmod = 10 ** 9 + 7\n\ndef binarySearch(arr, x, pos):\n\tl = 0\n\tr = len(arr)\n\tleft = 0\n\tright = 0\n\twhile l < r:\n\t\tmid = (l + r) // 2\n\t\tif mid < pos:\n\t\t\tleft += 1\n\t\tif mid > pos:\n\t\t\tright += 1\n\t\tif arr[mid] <= x:\n\t\t\tl = mid + 1\n\t\telse:\n\t\t\tr = mid\n\treturn (left, right)\nfact = [1, 1]\n\ndef fac(n):\n\tif n < 0:\n\t\treturn 0\n\tfor i in range(len(fact), n + 1):\n\t\tfact.append(fact[len(fact) - 1] * i % mod)\n\treturn fact[n]\n\ndef powe(a, b):\n\tp = 1\n\twhile b > 0:\n\t\tif b & 1 == 1:\n\t\t\tp = p * (a % mod) % mod\n\t\ta = a * a % mod\n\t\tb = b >> 1\n\treturn p\n\ndef ncr(n, r):\n\tif r > n:\n\t\treturn 0\n\tans = fac(n) * powe(fac(n - r), mod - 2) % mod\n\treturn ans\n(n, x, pos) = map(int, stdin.readline().split())\narr = [i + 1 for i in range(n)]\n(le, re) = binarySearch(arr, arr[pos], pos)\nn1 = x - 1\nn2 = n - x\nans = ncr(n1, le) * ncr(n2, re) % mod * fac(n - le - re - 1) % mod\nprint(ans)\n", "import math\n(a, b, c) = map(int, input().split())\nd1 = 0\nd2 = 0\ne = 0\nf = a\nwhile e < f:\n\tg = (e + f) // 2\n\tif g <= c:\n\t\te = g + 1\n\t\tif g < c:\n\t\t\td1 += 1\n\telse:\n\t\tf = g\n\t\td2 += 1\nh = 1\nfor i in range(b - 1, b - 1 - d1, -1):\n\th *= i\nfor i in range(a - b, a - b - d2, -1):\n\th *= i\nfor i in range(1, a - d1 - d2):\n\th *= i\nprint(h % 1000000007)\n", "from bisect import *\nimport math\nfrom collections import *\nfrom heapq import *\nfrom itertools import *\ninf = 10 ** 18\nmod = 10 ** 9 + 7\n(n, x, pos) = map(int, input().split())\nl = 0\nr = n\nbache = n - 1\nbade = n - x\nchotte = x - 1\nans = 1\nwhile l < r:\n\tmid = (l + r) // 2\n\tif mid == pos:\n\t\tl = mid + 1\n\telif mid > pos:\n\t\tans = ans * bade % mod\n\t\tbade -= 1\n\t\tbache -= 1\n\t\tr = mid\n\telse:\n\t\tans = ans * chotte % mod\n\t\tchotte -= 1\n\t\tbache -= 1\n\t\tl = mid + 1\nfor i in range(1, bache + 1):\n\tans = ans * i % mod\nprint(ans)\n", "from math import factorial\nmod = 1000000007\n(n, x, pos) = list(map(int, input().split()))\nbiggerNeeded = 0\nlowerNeeded = 0\nleft = 0\nright = n\nwhile left < right:\n\tmiddle = (left + right) // 2\n\tif middle < pos:\n\t\tleft = middle + 1\n\t\tlowerNeeded += 1\n\telif middle > pos:\n\t\tright = middle\n\t\tbiggerNeeded += 1\n\telse:\n\t\tleft = middle + 1\nif x + biggerNeeded > n or x - lowerNeeded <= 0:\n\tprint(0)\n\treturn\nans = factorial(x - 1) // factorial(x - 1 - lowerNeeded)\nans %= mod\nans *= factorial(n - x) // factorial(n - x - biggerNeeded)\nans %= mod\nans *= factorial(n - biggerNeeded - lowerNeeded - 1)\nans %= mod\nprint(ans)\n", "def fact(n):\n\tans = 1\n\twhile n > 1:\n\t\tans *= n % 1000000007\n\t\tn -= 1\n\treturn ans\n\ndef solve(up, dw):\n\tmi = up - dw\n\tans = 1\n\twhile up > mi:\n\t\tans *= up\n\t\tup -= 1\n\treturn ans\narr = [int(x) for x in input().split()]\n(n, ele, x) = (arr[0], arr[1], arr[2])\n(l, r) = (0, n)\n(cb, cs) = (0, 0)\nwhile l < r:\n\tmid = (l + r) // 2\n\tif mid > x:\n\t\tcb += 1\n\tif mid < x:\n\t\tcs += 1\n\tif mid <= x:\n\t\tl = mid + 1\n\telse:\n\t\tr = mid\nup1 = n - ele\nup2 = ele - 1\ns1 = solve(up1, cb)\ns2 = solve(up2, cs)\nf = fact(n - cb - cs - 1)\nprint(s1 * s2 * f % 1000000007)\n", "(n, x, p) = list(map(int, input().split()))\nsmallc = 0\nlargec = 0\nleft = 0\nright = n\nwhile left < right:\n\tmid = (left + right) // 2\n\tif mid < p:\n\t\tsmallc += 1\n\t\tleft = mid + 1\n\telif mid > p:\n\t\tlargec += 1\n\t\tright = mid\n\telse:\n\t\tleft = mid + 1\nlargeAv = n - x\nsmallAv = x - 1\nmod = 1000000007\n\ndef permutations(n, c):\n\tv = 1\n\tfor i in range(n - c + 1, n + 1):\n\t\tv = v * i % mod\n\treturn v\nv = permutations(largeAv, largec) * permutations(smallAv, smallc) % mod\noc = n - (largec + smallc + 1)\nv = v * permutations(oc, oc) % mod\nprint(v)\n", "M = 10 ** 9 + 7\nN = 10 ** 3 + 1\nfact = [0 for i in range(N)]\nfact[0] = 1\nfor i in range(1, N):\n\tfact[i] = i % M * fact[i - 1] % M % M\ninvfact = [0 for i in range(N)]\ninvfact[N - 1] = pow(fact[N - 1], M - 2, M)\nfor i in range(N - 2, -1, -1):\n\tinvfact[i] = invfact[i + 1] % M * (i + 1) % M % M\n\ndef ncr(n, r):\n\tif n < 0 or r > n or r < 0:\n\t\treturn 0\n\treturn fact[n] % M * invfact[r] % M % M * (invfact[n - r] % M) % M % M\nfor _ in range(1):\n\t(n, x, pos) = map(int, input().split())\n\tcntb = 0\n\tcnts = 0\n\t(left, right) = (0, n)\n\twhile left < right:\n\t\tmiddle = (left + right) // 2\n\t\tif middle < pos:\n\t\t\tcnts = cnts + 1\n\t\t\tleft = middle + 1\n\t\telif middle > pos:\n\t\t\tcntb = cntb + 1\n\t\t\tright = middle\n\t\telse:\n\t\t\tleft = middle + 1\n\tans = ncr(n - x, cntb) % M\n\tans = ans % M * fact[cntb] % M % M\n\tans = ans % M * ncr(x - 1, cnts) % M\n\tans = ans % M * fact[cnts] % M % M\n\tans = ans % M * fact[n - cnts - cntb - 1] % M % M\n\tprint(ans % M)\n", "def BinarySearch(a, x):\n\tleft = 0\n\tright = len(a)\n\tans = []\n\twhile left < right:\n\t\tmiddle = (left + right) // 2\n\t\tans.append(middle)\n\t\tif a[middle] <= x:\n\t\t\tleft = middle + 1\n\t\telse:\n\t\t\tright = middle\n\treturn ans\nmod = int(1000000000.0 + 7)\n\ndef fact(n):\n\tans = 1\n\tfor i in range(2, n + 1):\n\t\tans = ans * i % mod\n\treturn ans\n\ndef binPow(a, b):\n\tans = 1\n\twhile b > 0:\n\t\tif b % 2:\n\t\t\tans *= a\n\t\ta *= a\n\t\ta %= mod\n\t\tans %= mod\n\t\tb //= 2\n\treturn ans\n\ndef A(n, k):\n\treturn fact(n) * binPow(fact(n - k), mod - 2) % mod\n(n, x, pos) = map(int, input().split())\nused = BinarySearch([i for i in range(n)], pos)\n(cntL, cntU) = (0, 0)\nfor i in used:\n\tif i < pos:\n\t\tcntL += 1\n\telif i > pos:\n\t\tcntU += 1\nif x - 1 >= cntL and n - x >= cntU:\n\tprint(A(x - 1, cntL) * A(n - x, cntU) % mod * fact(n - cntL - cntU - 1) % mod)\nelse:\n\tprint(0)\n", "m = 1000000007\n\ndef P(a, b):\n\tres = 1\n\ti = a - b + 1\n\twhile i <= a:\n\t\tres = res * i % m\n\t\ti += 1\n\treturn res\n(n, x, pos) = input().split()\nn = int(n)\nx = int(x)\npos = int(pos)\n(l, r) = (0, n)\n(gc, lec) = (0, 0)\nwhile l < r:\n\tmid = int((l + r) / 2)\n\tif pos == mid:\n\t\tl = mid + 1\n\telif pos + 1 <= mid:\n\t\tr = mid\n\t\tgc += 1\n\telif pos + 1 > mid:\n\t\tl = mid + 1\n\t\tlec += 1\nans = P(n - x, gc) * P(x - 1, lec) % m * P(n - lec - gc - 1, n - lec - gc - 1) % m\nprint(ans)\n", "def solve(n, val, pos):\n\tl = 0\n\tr = n\n\tsmall = val - 1\n\tbig = n - val\n\t(pos1, pos2) = (0, 0)\n\twhile l < r:\n\t\tmid = (l + r) // 2\n\t\tif mid <= pos:\n\t\t\tpos1 += 1\n\t\t\tl = mid + 1\n\t\telif mid > pos:\n\t\t\tpos2 += 1\n\t\t\tr = mid\n\t(ans, mod) = (1, 10 ** 9 + 7)\n\tfor i in range(n - (pos1 + pos2)):\n\t\tans = ans * (i + 1)\n\t\tans = ans % mod\n\tpos1 -= 1\n\tfor _ in range(pos1):\n\t\tans = ans * small\n\t\tans = ans % mod\n\t\tsmall -= 1\n\tfor _ in range(pos2):\n\t\tans = ans * big\n\t\tans = ans % mod\n\t\tbig -= 1\n\tprint(ans)\n(n, x, pos) = map(int, input().split())\nsolve(n, x, pos)\n", "import sys, math\nfrom math import factorial as fact\nfrom collections import defaultdict as dd\ninput = lambda : sys.stdin.readline().strip()\ninp = lambda : list(map(int, input().split()))\nmod = 10 ** 9 + 7\n\ndef C(n, r):\n\tif r > n:\n\t\treturn 0\n\treturn fact(n) // (fact(n - r) * fact(r))\n\ndef P(n, r):\n\tif r > n:\n\t\treturn 0\n\treturn fact(n) // fact(n - r)\n(n, x, pos) = inp()\na = [i for i in range(n)]\ng = 0\nl = 0\n\ndef bins(a, x, n):\n\tglobal g, l\n\tleft = 0\n\tright = n\n\twhile left < right:\n\t\tmid = (left + right) // 2\n\t\tif a[mid] == x:\n\t\t\tleft = mid + 1\n\t\telif a[mid] < x:\n\t\t\tleft = mid + 1\n\t\t\tl += 1\n\t\telse:\n\t\t\tright = mid\n\t\t\tg += 1\n\tif left > 0 and a[left - 1] == x:\n\t\treturn\n\telse:\n\t\treturn\nbins(a, pos, n)\ndc = n - g - l - 1\nactg = n - x\nactl = x - 1\nans = P(actg, g) * P(actl, l) * P(n - g - l - 1, dc)\nprint(ans % mod)\n", "mod = 1000000007\n\ndef power(n, x):\n\tval = 1\n\twhile x != 0:\n\t\tif x & 1:\n\t\t\tval = val * n % mod\n\t\tn = n * n % mod\n\t\tx //= 2\n\treturn val\n\ndef fact(n):\n\tval = 1\n\tfor i in range(1, n + 1):\n\t\tval = val * i % mod\n\treturn val\n\ndef comb(n, x):\n\ty1 = power(fact(x), mod - 2) % mod\n\ty2 = power(fact(n - x), mod - 2) % mod\n\ty = fact(n) % mod\n\treturn y * y1 % mod * y2 % mod % mod\n(n, x, pos) = map(int, input().split())\n(less, more) = (0, 0)\n(l, h) = (0, n)\nwhile l < h:\n\tmid = (l + h) // 2\n\tif mid <= pos:\n\t\tless += 1\n\t\tl = mid + 1\n\telse:\n\t\tmore += 1\n\t\th = mid\nless -= 1\nif less <= x - 1 and more <= n - x:\n\tans = comb(x - 1, less) * fact(less) % mod * (comb(n - x, more) * fact(more)) % mod % mod * fact(n - 1 - (less + more)) % mod % mod\n\tprint(ans)\nelse:\n\tprint(0)\n", "(n, x, p) = map(int, input().split())\nl = 0\nr = n\nMOD = 1000000000.0 + 7\n(gt, ls) = (0, 0)\nwhile l < r:\n\tm = (l + r) // 2\n\tif p < m:\n\t\tgt += 1\n\t\tr = m\n\tif p >= m:\n\t\tif p > m:\n\t\t\tls += 1\n\t\tl = m + 1\nif n - x < gt or x - 1 < ls:\n\tans = 0\n\tprint(0)\n\texit()\nans = 1\nc = n - x + 1\nfor i in range(1, gt + 1):\n\tans = ans * (c - i) % MOD\nc = x\nfor i in range(1, ls + 1):\n\tans = ans * (x - i) % MOD\nfor i in range(1, n - gt - ls):\n\tans = ans * i % MOD\nprint(int(ans))\n", "import sys\n\ndef input():\n\treturn sys.stdin.readline().strip()\n\ndef list2d(a, b, c):\n\treturn [[c for j in range(b)] for i in range(a)]\n\ndef list3d(a, b, c, d):\n\treturn [[[d for k in range(c)] for j in range(b)] for i in range(a)]\n\ndef list4d(a, b, c, d, e):\n\treturn [[[[e for l in range(d)] for k in range(c)] for j in range(b)] for i in range(a)]\n\ndef ceil(x, y=1):\n\treturn int(-(-x // y))\n\ndef INT():\n\treturn int(input())\n\ndef MAP():\n\treturn map(int, input().split())\n\ndef LIST(N=None):\n\treturn list(MAP()) if N is None else [INT() for i in range(N)]\n\ndef Yes():\n\tprint('Yes')\n\ndef No():\n\tprint('No')\n\ndef YES():\n\tprint('YES')\n\ndef NO():\n\tprint('NO')\nINF = 10 ** 19\nMOD = 10 ** 9 + 7\nEPS = 10 ** (-10)\n\nclass CombTools:\n\n\tdef __init__(self, MAX, MOD):\n\t\tMAX += 1\n\t\tself.MAX = MAX\n\t\tself.MOD = MOD\n\t\tfactorial = [1] * MAX\n\t\tfactorial[0] = factorial[1] = 1\n\t\tfor i in range(2, MAX):\n\t\t\tfactorial[i] = factorial[i - 1] * i % MOD\n\t\tinverse = [1] * MAX\n\t\tinverse[MAX - 1] = pow(factorial[MAX - 1], MOD - 2, MOD)\n\t\tfor i in range(MAX - 2, -1, -1):\n\t\t\tinverse[i] = inverse[i + 1] * (i + 1) % MOD\n\t\tself.fact = factorial\n\t\tself.inv = inverse\n\n\tdef nCr(self, n, r):\n\t\tif n < r:\n\t\t\treturn 0\n\t\tr = min(r, n - r)\n\t\tnumerator = self.fact[n]\n\t\tdenominator = self.inv[r] * self.inv[n - r] % self.MOD\n\t\treturn numerator * denominator % self.MOD\n\n\tdef nPr(self, n, r):\n\t\tif n < r:\n\t\t\treturn 0\n\t\treturn self.fact[n] * self.inv[n - r] % self.MOD\n\ndef calc(N, pos):\n\tl = 0\n\tr = N\n\tlcnt = rcnt = 0\n\twhile l < r:\n\t\tm = (l + r) // 2\n\t\tif m <= pos:\n\t\t\tif m != pos:\n\t\t\t\tlcnt += 1\n\t\t\tl = m + 1\n\t\telse:\n\t\t\tif m != pos:\n\t\t\t\trcnt += 1\n\t\t\tr = m\n\treturn (lcnt, rcnt)\n(N, x, pos) = MAP()\n(lneed, rneed) = calc(N, pos)\nltotal = x - 1\nrtotal = N - x\nlrest = ltotal - lneed\nrrest = rtotal - rneed\nif lrest < 0 or rrest < 0:\n\tprint(0)\n\texit()\nct = CombTools(N, MOD)\nothers = lrest + rrest\nans = ct.nPr(ltotal, lneed) * ct.nPr(rtotal, rneed) * ct.fact[others] % MOD\nprint(ans)\n", "import os\nimport sys\nfrom collections import *\nfrom heapq import *\nfrom bisect import *\nfrom io import BytesIO, IOBase\n\ndef vsInput():\n\tsys.stdin = open('input.txt', 'r')\n\tsys.stdout = open('output.txt', 'w')\nBUFSIZE = 8192\n\nclass FastIO(IOBase):\n\tnewlines = 0\n\n\tdef __init__(self, file):\n\t\tself._fd = file.fileno()\n\t\tself.buffer = BytesIO()\n\t\tself.writable = 'x' in file.mode or 'r' not in file.mode\n\t\tself.write = self.buffer.write if self.writable else None\n\n\tdef read(self):\n\t\twhile True:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tif not b:\n\t\t\t\tbreak\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines = 0\n\t\treturn self.buffer.read()\n\n\tdef readline(self):\n\t\twhile self.newlines == 0:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tself.newlines = b.count(b'\\n') + (not b)\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines -= 1\n\t\treturn self.buffer.readline()\n\n\tdef flush(self):\n\t\tif self.writable:\n\t\t\tos.write(self._fd, self.buffer.getvalue())\n\t\t\t(self.buffer.truncate(0), self.buffer.seek(0))\n\nclass IOWrapper(IOBase):\n\n\tdef __init__(self, file):\n\t\tself.buffer = FastIO(file)\n\t\tself.flush = self.buffer.flush\n\t\tself.writable = self.buffer.writable\n\t\tself.write = lambda s: self.buffer.write(s.encode('ascii'))\n\t\tself.read = lambda : self.buffer.read().decode('ascii')\n\t\tself.readline = lambda : self.buffer.readline().decode('ascii')\n(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))\ninput = lambda : sys.stdin.readline().rstrip('\\r\\n')\nALPHA = 'abcdefghijklmnopqrstuvwxyz/'\nM = 1000000007\nEPS = 1e-06\n\ndef Ceil(a, b):\n\treturn a // b + int(a % b > 0)\n\ndef value():\n\treturn tuple(map(int, input().split()))\n\ndef array():\n\treturn [int(i) for i in input().split()]\n\ndef Int():\n\treturn int(input())\n\ndef Str():\n\treturn input()\n\ndef arrayS():\n\treturn [i for i in input().split()]\n\ndef nCr(n, r, p=M):\n\tnum = 1\n\tden = 1\n\tfor i in range(r):\n\t\tnum = num * (n - i) % p\n\t\tden = den * (i + 1) % p\n\treturn num * pow(den, p - 2, p) % p\nfact = [1]\nf = 1\nfor i in range(1, 1001):\n\tf = f * i % M\n\tfact.append(f)\n(n, x, pos) = value()\na = [x - 1] * pos + [x] + [x + 1] * (n - pos - 1)\nsmall = -1\nlarge = 0\nlow = 0\nhigh = n\nwhile low < high:\n\tmid = (low + high) // 2\n\tif a[mid] <= x:\n\t\tsmall += 1\n\t\tlow = mid + 1\n\telse:\n\t\tlarge += 1\n\t\thigh = mid\nrem = n - small - large - 1\nsmalls = x - 1\nlarges = n - smalls - 1\na1 = nCr(smalls, small) * fact[small] % M\na2 = nCr(larges, large) * fact[large] % M\na3 = fact[rem] * a1 % M\nans = a3 * a2 % M\nprint(ans)\n", "import os\nfrom io import BytesIO, IOBase\nimport sys\nBUFSIZE = 8192\n\nclass FastIO(IOBase):\n\tnewlines = 0\n\n\tdef __init__(self, file):\n\t\tself._fd = file.fileno()\n\t\tself.buffer = BytesIO()\n\t\tself.writable = 'x' in file.mode or 'r' not in file.mode\n\t\tself.write = self.buffer.write if self.writable else None\n\n\tdef read(self):\n\t\twhile True:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tif not b:\n\t\t\t\tbreak\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines = 0\n\t\treturn self.buffer.read()\n\n\tdef readline(self):\n\t\twhile self.newlines == 0:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tself.newlines = b.count(b'\\n') + (not b)\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines -= 1\n\t\treturn self.buffer.readline()\n\n\tdef flush(self):\n\t\tif self.writable:\n\t\t\tos.write(self._fd, self.buffer.getvalue())\n\t\t\t(self.buffer.truncate(0), self.buffer.seek(0))\n\nclass IOWrapper(IOBase):\n\n\tdef __init__(self, file):\n\t\tself.buffer = FastIO(file)\n\t\tself.flush = self.buffer.flush\n\t\tself.writable = self.buffer.writable\n\t\tself.write = lambda s: self.buffer.write(s.encode('ascii'))\n\t\tself.read = lambda : self.buffer.read().decode('ascii')\n\t\tself.readline = lambda : self.buffer.readline().decode('ascii')\n(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))\ninput = lambda : sys.stdin.readline().rstrip('\\r\\n')\nmod = 1000000007\nfactorials = [1] * (2 * 10 ** 3 + 1)\nfor i in range(1, len(factorials)):\n\tfactorials[i] = factorials[i - 1] * i % mod\ninv_factorials = [1] * (2 * 10 ** 3 + 1)\nfor i in range(2, len(inv_factorials)):\n\tinv_factorials[i] = pow(factorials[i], mod - 2, mod)\n\ndef egcd(a, b):\n\tif a == 0:\n\t\treturn (b, 0, 1)\n\telse:\n\t\t(g, y, x) = egcd(b % a, a)\n\t\treturn (g, x - b // a * y, y)\n\ndef modinv(a):\n\t(g, x, y) = egcd(a, mod)\n\tif g != 1:\n\t\traise Exception('modular inverse does not exist')\n\telse:\n\t\treturn x % mod\n(n, x, pos) = map(int, input().split())\nassigned_left = 0\nassigned_right = 0\nleft = 0\nright = n\nwhile left < right:\n\tmiddle = (left + right) // 2\n\tif middle <= pos:\n\t\tleft = middle + 1\n\t\tassigned_left += 1\n\telse:\n\t\tassigned_right += 1\n\t\tright = middle\nif left > 0 and left - 1 == pos:\n\tassigned_left -= 1\nelse:\n\tprint(0)\n\texit(0)\nif n - x < assigned_right or x - 1 < assigned_left:\n\tprint(0)\nelse:\n\tinitial = 1\n\tinitial *= factorials[n - x] * (inv_factorials[n - x - assigned_right] % mod)\n\tinitial %= mod\n\tinitial *= factorials[x - 1] * (inv_factorials[x - 1 - assigned_left] % mod)\n\tinitial %= mod\n\tinitial *= factorials[n - assigned_left - assigned_right - 1]\n\tinitial %= mod\n\tprint(initial)\n", "(n, x, pos) = [int(k) for k in input().split()]\nans = 1\ngreater = n - x\nsmaller = x - 1\nleft = 0\nright = n\nmid = n\nwhile left < right:\n\tmid = (left + right) // 2\n\tif mid < pos:\n\t\tans *= smaller\n\t\tans = ans % 1000000007\n\t\tsmaller -= 1\n\t\tleft = mid + 1\n\telif mid > pos:\n\t\tans *= greater\n\t\tans = ans % 1000000007\n\t\tgreater -= 1\n\t\tright = mid\n\telse:\n\t\tleft = mid + 1\nfor i in range(1, smaller + greater + 1):\n\tans *= i\n\tans = ans % 1000000007\nprint(ans)\n", "lm = 1010\nf = {0: 1}\nmod = 10 ** 9 + 7\nfor i in range(1, lm):\n\tf[i] = i * f[i - 1] % mod\n\ndef BnS(pos, n):\n\t(l, r) = (0, n)\n\t(sm, bg) = (0, 0)\n\twhile l < r:\n\t\tm = (l + r) // 2\n\t\tif m <= pos:\n\t\t\tsm += 1\n\t\t\tl = m + 1\n\t\telse:\n\t\t\tbg += 1\n\t\t\tr = m\n\treturn (sm, bg)\n(N, x, pos) = map(int, input().split())\n(small, big) = BnS(pos, N)\n\ndef p(n, r):\n\tif r > n:\n\t\treturn 0\n\tans = f[n] * pow(f[n - r], mod - 2, mod)\n\tans %= mod\n\treturn ans\nans = p(x - 1, small - 1) * p(N - x, big) % mod\nans = ans * f[N - (small + big)]\nans %= mod\nprint(ans)\n", "import os\nimport sys\nfrom io import BytesIO, IOBase\nBUFSIZE = 8192\n\nclass FastIO(IOBase):\n\tnewlines = 0\n\n\tdef __init__(self, file):\n\t\tself._fd = file.fileno()\n\t\tself.buffer = BytesIO()\n\t\tself.writable = 'x' in file.mode or 'r' not in file.mode\n\t\tself.write = self.buffer.write if self.writable else None\n\n\tdef read(self):\n\t\twhile True:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tif not b:\n\t\t\t\tbreak\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines = 0\n\t\treturn self.buffer.read()\n\n\tdef readline(self):\n\t\twhile self.newlines == 0:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tself.newlines = b.count(b'\\n') + (not b)\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines -= 1\n\t\treturn self.buffer.readline()\n\n\tdef flush(self):\n\t\tif self.writable:\n\t\t\tos.write(self._fd, self.buffer.getvalue())\n\t\t\t(self.buffer.truncate(0), self.buffer.seek(0))\n\nclass IOWrapper(IOBase):\n\n\tdef __init__(self, file):\n\t\tself.buffer = FastIO(file)\n\t\tself.flush = self.buffer.flush\n\t\tself.writable = self.buffer.writable\n\t\tself.write = lambda s: self.buffer.write(s.encode('ascii'))\n\t\tself.read = lambda : self.buffer.read().decode('ascii')\n\t\tself.readline = lambda : self.buffer.readline().decode('ascii')\n(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))\ninput = lambda : sys.stdin.readline().rstrip('\\r\\n')\n\ndef list2d(a, b, c):\n\treturn [[c] * b for i in range(a)]\n\ndef list3d(a, b, c, d):\n\treturn [[[d] * c for j in range(b)] for i in range(a)]\n\ndef list4d(a, b, c, d, e):\n\treturn [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]\n\ndef ceil(x, y=1):\n\treturn int(-(-x // y))\n\ndef Yes():\n\tprint('Yes')\n\ndef No():\n\tprint('No')\n\ndef YES():\n\tprint('YES')\n\ndef NO():\n\tprint('NO')\nINF = 10 ** 18\nMOD = 10 ** 9 + 7\nRi = lambda : [int(x) for x in sys.stdin.readline().split()]\nri = lambda : sys.stdin.readline().strip()\n(n, x, pos) = Ri()\nnob = n - x\nnos = x - 1\nans = 1\n(l, r) = (0, n)\ncnt = 0\nwhile l < r:\n\tmid = (l + r) // 2\n\tif mid > pos:\n\t\tans = ans * nob\n\t\tans = ans % MOD\n\t\tnob -= 1\n\t\tr = mid\n\telif mid < pos:\n\t\tans = ans * nos\n\t\tans = ans % MOD\n\t\tnos -= 1\n\t\tl = mid + 1\n\telse:\n\t\tflag = True\n\t\tl = mid + 1\nfor i in range(1, nos + nob + 1):\n\tans = ans * i % MOD\nprint(ans)\n", "import math\nfrom collections import deque\nfrom sys import stdin, stdout, setrecursionlimit\nfrom string import ascii_letters\nletters = ascii_letters[:26]\nfrom collections import defaultdict\ninput = stdin.readline\n(n, x, pos) = map(int, input().split())\nl = 0\nr = n\nres = 1\nhigher = 0\nlower = 0\nwhile l < r:\n\tm = l + (r - l) // 2\n\tif m == pos:\n\t\tl = m + 1\n\t\tcontinue\n\tif pos < m + 1:\n\t\tr = m\n\t\thigher += 1\n\telse:\n\t\tl = m + 1\n\t\tlower += 1\nres = 1\nhh = n - x\nhl = x - 1\nfor i in range(higher):\n\tres = res * hh % 1000000007\n\thh -= 1\nfor i in range(lower):\n\tres = res * hl % 1000000007\n\thl -= 1\nost = n - 1 - lower - higher\nfor i in range(1, ost + 1):\n\tres = res * i % 1000000007\nprint(res)\n", "bigmod = 10 ** 9 + 7\n\ndef Bserach(n, pos, x):\n\tleft = 0\n\tright = n\n\tl = 0\n\tr = -1\n\twhile left < right:\n\t\tmiddle = (left + right) // 2\n\t\tif middle <= pos:\n\t\t\tr += 1\n\t\t\tleft = middle + 1\n\t\telse:\n\t\t\tl += 1\n\t\t\tright = middle\n\tanswer = 1\n\tfor i in range(l):\n\t\tanswer *= n - x - i\n\t\tanswer %= bigmod\n\tfor i in range(r):\n\t\tanswer *= x - 1 - i\n\t\tanswer %= bigmod\n\tfor i in range(1, n - l - r):\n\t\tanswer *= i\n\t\tanswer %= bigmod\n\treturn answer\n[n, x, pos] = list(map(int, input().split()))\nprint(Bserach(n, pos, x))\n", "from bisect import *\nfrom collections import *\nfrom math import gcd, ceil, sqrt, floor, inf\nfrom heapq import *\nfrom typing import List\nfrom itertools import *\nfrom operator import add, mul, sub, xor, truediv, floordiv\nfrom functools import *\nimport os\nimport sys\nfrom io import BytesIO, IOBase\nBUFSIZE = 8192\n\nclass FastIO(IOBase):\n\tnewlines = 0\n\n\tdef __init__(self, file):\n\t\tself._fd = file.fileno()\n\t\tself.buffer = BytesIO()\n\t\tself.writable = 'x' in file.mode or 'r' not in file.mode\n\t\tself.write = self.buffer.write if self.writable else None\n\n\tdef read(self):\n\t\twhile True:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tif not b:\n\t\t\t\tbreak\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines = 0\n\t\treturn self.buffer.read()\n\n\tdef readline(self):\n\t\twhile self.newlines == 0:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tself.newlines = b.count(b'\\n') + (not b)\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines -= 1\n\t\treturn self.buffer.readline()\n\n\tdef flush(self):\n\t\tif self.writable:\n\t\t\tos.write(self._fd, self.buffer.getvalue())\n\t\t\t(self.buffer.truncate(0), self.buffer.seek(0))\n\nclass IOWrapper(IOBase):\n\n\tdef __init__(self, file):\n\t\tself.buffer = FastIO(file)\n\t\tself.flush = self.buffer.flush\n\t\tself.writable = self.buffer.writable\n\t\tself.write = lambda s: self.buffer.write(s.encode('ascii'))\n\t\tself.read = lambda : self.buffer.read().decode('ascii')\n\t\tself.readline = lambda : self.buffer.readline().decode('ascii')\n(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))\ninput = lambda : sys.stdin.readline().rstrip('\\r\\n')\n\ndef RL():\n\treturn map(int, sys.stdin.readline().rstrip().split())\n\ndef RLL():\n\treturn list(map(int, sys.stdin.readline().rstrip().split()))\n\ndef N():\n\treturn int(input())\n\n@lru_cache(None)\ndef fact(x):\n\tif x < 2:\n\t\treturn 1\n\treturn fact(x - 1) * x % mod\n\n@lru_cache(None)\ndef per(i, j):\n\treturn fact(i) // fact(i - j)\n\n@lru_cache(None)\ndef com(i, j):\n\treturn per(i, j) // fact(j)\n\ndef linc(f, t, l, r):\n\twhile l < r:\n\t\tmid = (l + r) // 2\n\t\tif t > f(mid):\n\t\t\tl = mid + 1\n\t\telse:\n\t\t\tr = mid\n\treturn l\n\ndef rinc(f, t, l, r):\n\twhile l < r:\n\t\tmid = (l + r + 1) // 2\n\t\tif t < f(mid):\n\t\t\tr = mid - 1\n\t\telse:\n\t\t\tl = mid\n\treturn l\n\ndef ldec(f, t, l, r):\n\twhile l < r:\n\t\tmid = (l + r) // 2\n\t\tif t < f(mid):\n\t\t\tl = mid + 1\n\t\telse:\n\t\t\tr = mid\n\treturn l\n\ndef rdec(f, t, l, r):\n\twhile l < r:\n\t\tmid = (l + r + 1) // 2\n\t\tif t > f(mid):\n\t\t\tr = mid - 1\n\t\telse:\n\t\t\tl = mid\n\treturn l\n\ndef isprime(n):\n\tfor i in range(2, int(n ** 0.5) + 1):\n\t\tif n % i == 0:\n\t\t\treturn False\n\treturn True\n\ndef binfun(x):\n\tc = 0\n\tfor w in arr:\n\t\tc += ceil(w / x)\n\treturn c\n\ndef lowbit(n):\n\treturn n & -n\n\ndef inverse(a, m):\n\ta %= m\n\tif a <= 1:\n\t\treturn a\n\treturn (1 - inverse(m, a) * m) // a % m\n\nclass BIT:\n\n\tdef __init__(self, arr):\n\t\tself.arr = arr\n\t\tself.n = len(arr) - 1\n\n\tdef update(self, x, v):\n\t\twhile x <= self.n:\n\t\t\tself.arr[x] += v\n\t\t\tx += x & -x\n\n\tdef query(self, x):\n\t\tans = 0\n\t\twhile x:\n\t\t\tans += self.arr[x]\n\t\t\tx &= x - 1\n\t\treturn ans\n\nclass smt:\n\n\tdef __init__(self, l, r, arr):\n\t\tself.l = l\n\t\tself.r = r\n\t\tself.value = (1 << 31) - 1 if l < r else arr[l]\n\t\tmid = (l + r) // 2\n\t\tif l < r:\n\t\t\tself.left = smt(l, mid, arr)\n\t\t\tself.right = smt(mid + 1, r, arr)\n\t\t\tself.value &= self.left.value & self.right.value\n\n\tdef setvalue(self, x, val):\n\t\tif self.l == self.r:\n\t\t\tself.value = val\n\t\t\treturn\n\t\tmid = (self.l + self.r) // 2\n\t\tif x <= mid:\n\t\t\tself.left.setvalue(x, val)\n\t\telse:\n\t\t\tself.right.setvalue(x, val)\n\t\tself.value = self.left.value & self.right.value\n\n\tdef ask(self, l, r):\n\t\tif l <= self.l and r >= self.r:\n\t\t\treturn self.value\n\t\tval = (1 << 31) - 1\n\t\tmid = (self.l + self.r) // 2\n\t\tif l <= mid:\n\t\t\tval &= self.left.ask(l, r)\n\t\tif r > mid:\n\t\t\tval &= self.right.ask(l, r)\n\t\treturn val\n\nclass DSU:\n\n\tdef __init__(self, n):\n\t\tself.c = [-1] * n\n\n\tdef same(self, x, y):\n\t\treturn self.find(x) == self.find(y)\n\n\tdef find(self, x):\n\t\tif self.c[x] < 0:\n\t\t\treturn x\n\t\tself.c[x] = self.find(self.c[x])\n\t\treturn self.c[x]\n\n\tdef union(self, u, v):\n\t\t(u, v) = (self.find(u), self.find(v))\n\t\tif u == v:\n\t\t\treturn False\n\t\tif self.c[u] < self.c[v]:\n\t\t\t(u, v) = (v, u)\n\t\tself.c[u] += self.c[v]\n\t\tself.c[v] = u\n\t\treturn True\n\n\tdef size(self, x):\n\t\treturn -self.c[self.find(x)]\n\nclass UFS:\n\n\tdef __init__(self, n):\n\t\tself.parent = [i for i in range(n)]\n\t\tself.ranks = [0] * n\n\n\tdef find(self, x):\n\t\tif x != self.parent[x]:\n\t\t\tself.parent[x] = self.find(self.parent[x])\n\t\treturn self.parent[x]\n\n\tdef union(self, u, v):\n\t\t(pu, pv) = (self.find(u), self.find(v))\n\t\tif pu == pv:\n\t\t\treturn False\n\t\tif self.ranks[pu] >= self.ranks[pv]:\n\t\t\tself.parent[pv] = pu\n\t\t\tif self.ranks[pv] == self.ranks[pu]:\n\t\t\t\tself.ranks[pu] += 1\n\t\telse:\n\t\t\tself.parent[pu] = pv\n\ndef Prime(n):\n\tc = 0\n\tprime = []\n\tflag = [0] * (n + 1)\n\tfor i in range(2, n + 1):\n\t\tif not flag[i]:\n\t\t\tprime.append(i)\n\t\t\tc += 1\n\t\tfor j in range(c):\n\t\t\tif i * prime[j] > n:\n\t\t\t\tbreak\n\t\t\tflag[i * prime[j]] = prime[j]\n\t\t\tif i % prime[j] == 0:\n\t\t\t\tbreak\n\treturn prime\n\ndef dij(s, graph):\n\td = {}\n\td[s] = 0\n\theap = [(0, s)]\n\tseen = set()\n\twhile heap:\n\t\t(dis, u) = heappop(heap)\n\t\tif u in seen:\n\t\t\tcontinue\n\t\tfor v in graph[u]:\n\t\t\tif v not in d or d[v] > d[u] + graph[u][v]:\n\t\t\t\td[v] = d[u] + graph[u][v]\n\t\t\t\theappush(heap, (d[v], v))\n\treturn d\n\ndef perm(m, n):\n\tif m < n:\n\t\treturn 0\n\tans = 1\n\tfor i in range(m - n + 1, m + 1):\n\t\tans = ans * i % mod\n\treturn ans\n(n, x, p) = RL()\nl = 0\nr = n\ns = b = 0\nwhile l < r:\n\tmid = (l + r) // 2\n\tif mid < p:\n\t\tl = mid + 1\n\t\ts += 1\n\telif mid > p:\n\t\tr = mid\n\t\tb += 1\n\telse:\n\t\tl = mid + 1\nmod = 10 ** 9 + 7\nans = perm(n - x, b) * perm(x - 1, s) * fact(n - s - b - 1) % mod\nprint(ans)\n", "import sys\nfrom array import array\n\ndef input():\n\treturn sys.stdin.buffer.readline().decode('utf-8')\n(n, x, pos) = map(int, input().split())\nmod = 10 ** 9 + 7\n(low, high) = (x - 1, n - x)\nans = 1\n(l, r) = (0, n)\nwhile l < r:\n\tmid = l + r >> 1\n\tif mid <= pos:\n\t\tif mid < pos:\n\t\t\tans = ans * low % mod\n\t\t\tlow -= 1\n\t\tl = mid + 1\n\telse:\n\t\tans = ans * high % mod\n\t\thigh -= 1\n\t\tr = mid\nassert l > 0 and l - 1 == pos\nfor i in range(low + high, 0, -1):\n\tans = ans * i % mod\nprint(ans)\n", "(n, x, pos) = map(int, input().split())\nmod = 10 ** 9 + 7\nfactorials = [1]\nfor i in range(1, n + 1):\n\tfactorials.append(factorials[-1] * i % mod)\ninverses = [pow(v, mod - 2, mod) for v in factorials]\n\ndef cnk(n, k):\n\treturn factorials[n] * inverses[n - k] * inverses[k]\n\ndef split(pos, n):\n\tleft = 0\n\tright = n\n\tlefts = []\n\trights = []\n\twhile left < right:\n\t\tmid = (left + right) // 2\n\t\tif mid <= pos:\n\t\t\tif mid != pos:\n\t\t\t\trights.append(mid)\n\t\t\tleft = mid + 1\n\t\telse:\n\t\t\tlefts.append(mid)\n\t\t\tright = mid\n\treturn (lefts, rights)\n(lefts, rights) = split(pos, n)\nsmaller = x - 1\nbigger = n - x\nif len(rights) > smaller or len(lefts) > bigger:\n\tprint(0)\nelse:\n\tres = cnk(smaller, len(rights)) * cnk(bigger, len(lefts))\n\tres *= factorials[len(rights)]\n\tres *= factorials[len(lefts)]\n\tres %= mod\n\tfor i in range(n - 1 - len(rights) - len(lefts)):\n\t\tres *= i + 1\n\t\tres %= mod\n\tprint(res)\n", "import math\n\ndef nPr(n, r):\n\treturn math.factorial(n) // math.factorial(n - r)\n(n, x, p) = map(int, input().split())\nsm = x - 1\nbig = n - x\nleft = 0\nright = n\nl = r = 0\nmod = 10 ** 9 + 7\nwhile left < right:\n\tmid = (left + right) // 2\n\tif mid <= p:\n\t\tif mid != p:\n\t\t\tl += 1\n\t\tleft = mid + 1\n\telse:\n\t\tr += 1\n\t\tright = mid\nans = 0\nif l > sm or r > big or left - 1 != p:\n\tprint(0)\nelse:\n\tans = nPr(sm, l) % mod\n\tans %= mod\n\tans *= nPr(big, r) % mod\n\tans %= mod\n\tans *= math.factorial(n - (l + r + 1)) % mod\n\tprint(ans % mod)\n", "import math\n(size, x, pos) = list(map(int, input().split()))\nleft = 0\nright = size\nmiddle = (left + right) // 2\nres = 1\nval_gt_x = size - x\nval_lt_x = size - val_gt_x - 1\nmod_val = 1000000007\nwhile left < right:\n\tif pos < middle:\n\t\tright = middle\n\t\tif val_gt_x == 0:\n\t\t\tprint(0)\n\t\t\texit()\n\t\tres *= val_gt_x\n\t\tval_gt_x -= 1\n\telif pos == middle:\n\t\tleft = middle + 1\n\telse:\n\t\tleft = middle + 1\n\t\tif val_lt_x == 0:\n\t\t\tprint(0)\n\t\t\texit()\n\t\tres *= val_lt_x\n\t\tval_lt_x -= 1\n\tmiddle = (left + right) // 2\n\tres = res % mod_val\nres *= math.factorial(val_gt_x + val_lt_x)\nres = res % mod_val\nprint(res)\n", "import bisect\nimport collections\nimport copy\nimport functools\nimport heapq\nimport itertools\nimport math\nimport random\nimport re\nimport sys\nimport time\nimport string\nfrom typing import List\nsys.setrecursionlimit(99999)\n(n, x, p) = map(int, input().split())\nlx = x - 1\nrx = n - x\nmod = 10 ** 9 + 7\nl = 0\nr = n\nans = 1\nwhile l < r:\n\tmid = (l + r) // 2\n\tif mid > p:\n\t\tr = mid\n\t\tans *= rx\n\t\trx -= 1\n\telse:\n\t\tif mid < p:\n\t\t\tans *= lx\n\t\t\tlx -= 1\n\t\tl = mid + 1\n\tans %= mod\nf = [1] * 1001\nfor i in range(2, 1001):\n\tf[i] = f[i - 1] * i % mod\nprint(ans * f[lx + rx] % (10 ** 9 + 7))\n", "import sys, math\ninput = sys.stdin.readline\n\ndef perm(a, b):\n\tif a < b:\n\t\treturn 0\n\tnum = fact[a]\n\tdenom = pow(fact[a - b], mod - 2, mod)\n\treturn num * denom % mod\n\ndef bs(arr, pos):\n\tleft = 0\n\tright = len(arr)\n\tl = 0\n\tr = 0\n\twhile left < right:\n\t\tmid = (left + right) // 2\n\t\tif arr[mid] < arr[pos]:\n\t\t\tleft = mid + 1\n\t\t\tl += 1\n\t\telif arr[mid] == arr[pos]:\n\t\t\tleft = mid + 1\n\t\telse:\n\t\t\tright = mid\n\t\t\tr += 1\n\treturn (l, r)\n(n, x, pos) = map(int, input().split())\nmod = int(1000000000.0 + 7)\narr = [i for i in range(1, n + 1)]\nfact = [1]\nfor i in range(1, 1005):\n\tfact.append(fact[i - 1] * i % mod)\n(l, r) = bs(arr, pos)\nans = perm(n - x, r) * perm(x - 1, l) % mod\nans = ans * fact[n - r - l - 1] % mod\nprint(ans)\n", "import sys, os, io\n\ndef rs():\n\treturn sys.stdin.readline().rstrip()\n\ndef ri():\n\treturn int(sys.stdin.readline())\n\ndef ria():\n\treturn list(map(int, sys.stdin.readline().split()))\n\ndef ws(s):\n\tsys.stdout.write(s + '\\n')\n\ndef wi(n):\n\tsys.stdout.write(str(n) + '\\n')\n\ndef wia(a):\n\tsys.stdout.write(' '.join([str(x) for x in a]) + '\\n')\nimport math, datetime, functools, itertools, operator, bisect, fractions, statistics\nfrom collections import deque, defaultdict, OrderedDict, Counter\nfrom fractions import Fraction\nfrom decimal import Decimal\nfrom sys import stdout\nfrom heapq import heappush, heappop, heapify, _heapify_max, _heappop_max\n\ndef main():\n\tmod = 1000000007\n\tstarttime = datetime.datetime.now()\n\tif os.path.exists('input.txt'):\n\t\tsys.stdin = open('input.txt', 'r')\n\t\tsys.stdout = open('output.txt', 'w')\n\n\tdef factorialMod(n, modulus):\n\t\tans = 1\n\t\tfor i in range(1, n + 1):\n\t\t\tans = ans * i % modulus\n\t\treturn ans % modulus\n\tfor _ in range(1):\n\t\t(n, x, pos) = ria()\n\t\tleft = 0\n\t\tright = n\n\t\tsmaller = x - 1\n\t\tgreater = n - x\n\t\tsum = 1\n\t\trest = n - 1\n\t\twhile left < right:\n\t\t\tmiddle = (left + right) // 2\n\t\t\tif middle == pos:\n\t\t\t\tleft = middle + 1\n\t\t\telif middle > pos:\n\t\t\t\tsum = sum * greater % mod\n\t\t\t\tgreater -= 1\n\t\t\t\trest -= 1\n\t\t\t\tright = middle\n\t\t\telse:\n\t\t\t\tsum = sum * smaller % mod\n\t\t\t\tsmaller -= 1\n\t\t\t\trest -= 1\n\t\t\t\tleft = middle + 1\n\t\tif left > 0 and left - 1 == pos:\n\t\t\tsum = sum * factorialMod(rest, mod) % mod\n\t\telse:\n\t\t\tsum = 0\n\t\tprint(sum)\n\tendtime = datetime.datetime.now()\n\ttime = (endtime - starttime).total_seconds() * 1000\n\tif os.path.exists('input.txt'):\n\t\tprint('Time:', time, 'ms')\n\nclass FastReader(io.IOBase):\n\tnewlines = 0\n\n\tdef __init__(self, fd, chunk_size=1024 * 8):\n\t\tself._fd = fd\n\t\tself._chunk_size = chunk_size\n\t\tself.buffer = io.BytesIO()\n\n\tdef read(self):\n\t\twhile True:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))\n\t\t\tif not b:\n\t\t\t\tbreak\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines = 0\n\t\treturn self.buffer.read()\n\n\tdef readline(self, size=-1):\n\t\twhile self.newlines == 0:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))\n\t\t\tself.newlines = b.count(b'\\n') + (not b)\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines -= 1\n\t\treturn self.buffer.readline()\n\nclass FastWriter(io.IOBase):\n\n\tdef __init__(self, fd):\n\t\tself._fd = fd\n\t\tself.buffer = io.BytesIO()\n\t\tself.write = self.buffer.write\n\n\tdef flush(self):\n\t\tos.write(self._fd, self.buffer.getvalue())\n\t\t(self.buffer.truncate(0), self.buffer.seek(0))\n\nclass FastStdin(io.IOBase):\n\n\tdef __init__(self, fd=0):\n\t\tself.buffer = FastReader(fd)\n\t\tself.read = lambda : self.buffer.read().decode('ascii')\n\t\tself.readline = lambda : self.buffer.readline().decode('ascii')\n\nclass FastStdout(io.IOBase):\n\n\tdef __init__(self, fd=1):\n\t\tself.buffer = FastWriter(fd)\n\t\tself.write = lambda s: self.buffer.write(s.encode('ascii'))\n\t\tself.flush = self.buffer.flush\nsys.stdin = FastStdin()\nsys.stdout = FastStdout()\nmain()\n", "import sys\ninput = sys.stdin.readline\n\ndef bs(r, x):\n\tleft = 0\n\tright = r\n\twhile left < right:\n\t\tm = (left + right) // 2\n\t\tif m <= x:\n\t\t\tleft = m + 1\n\t\t\tarr[m] = 'S'\n\t\telse:\n\t\t\tright = m\n\t\t\tarr[m] = 'G'\nmod = 10 ** 9 + 7\nfact = [1] * 1001\nfor i in range(1, len(fact)):\n\tfact[i] = fact[i - 1] * i % mod\n\ndef c(n, r):\n\tnum = fact[n]\n\tdeno = fact[n - r] % mod\n\tdeno = pow(deno, mod - 2, mod)\n\treturn num * deno % mod\n(n, x, pos) = list(map(int, input().split(' ')))\narr = [0] * n\nbs(n, pos)\nl = -1\ng = 0\nfor i in range(n):\n\tif arr[i] == 'S':\n\t\tl += 1\n\telif arr[i] == 'G':\n\t\tg += 1\nif l < x and n - x >= g:\n\ttemp = 1\n\ttemp *= c(x - 1, l)\n\ttemp = temp % mod\n\ttemp *= c(n - x, g)\n\ttemp = temp % mod\n\ttemp *= fact[n - l - g - 1]\n\ttemp = temp % mod\n\tprint(temp)\nelse:\n\tprint(0)\n", "def algo(arr, y):\n\tans = []\n\tleft = 0\n\tright = len(arr)\n\twhile left < right:\n\t\tmiddle = (left + right) // 2\n\t\tans.append(arr[middle])\n\t\tif arr[middle] <= y:\n\t\t\tleft = middle + 1\n\t\telse:\n\t\t\tright = middle\n\tif left > 0 and arr[left - 1] == y:\n\t\treturn (True, ans)\n\treturn (False, ans)\nmod = 1000000000 + 7\n\ndef C(n, k):\n\tif 0 <= k <= n:\n\t\tnn = 1\n\t\tkk = 1\n\t\tfor t in range(1, min(k, n - k) + 1):\n\t\t\tnn *= n\n\t\t\tkk *= t\n\t\t\tn -= 1\n\t\treturn nn // kk % mod\n\telse:\n\t\treturn 0\n\ndef fact(n):\n\tans = 1\n\tfor i in range(1, n + 1):\n\t\tans *= i\n\t\tans %= mod\n\treturn ans\n(n, x, pos) = list(map(int, input().split()))\na = []\nfor i in range(n):\n\tif i < pos:\n\t\ta.append(x - 1)\n\telif i == pos:\n\t\ta.append(x)\n\telse:\n\t\ta.append(x + 1)\n(res, seq) = algo(a, x)\nassert res\nsum1 = 0\nsum2 = 0\nfor elem in seq:\n\tif elem < x:\n\t\tsum1 += 1\n\telif elem > x:\n\t\tsum2 += 1\nanswer = fact(n - 1 - sum1 - sum2) * C(x - 1, sum1)\nanswer %= mod\nanswer *= fact(sum1)\nanswer %= mod\nanswer *= C(n - x, sum2)\nanswer %= mod\nanswer *= fact(sum2)\nanswer %= mod\nprint(answer)\n", "from bisect import bisect_left as bl\nfrom bisect import bisect_right as br\nfrom heapq import heappush, heappop\nimport math\nfrom collections import *\nfrom functools import reduce, cmp_to_key\nimport sys\ninput = sys.stdin.readline\nM = mod = 10 ** 9 + 7\n\ndef factors(n):\n\treturn sorted(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))\n\ndef inv_mod(n):\n\treturn pow(n, mod - 2, mod)\n\ndef li():\n\treturn [int(i) for i in input().rstrip('\\n').split()]\n\ndef st():\n\treturn input().rstrip('\\n')\n\ndef val():\n\treturn int(input().rstrip('\\n'))\n\ndef li2():\n\treturn [i for i in input().rstrip('\\n')]\n\ndef li3():\n\treturn [int(i) for i in input().rstrip('\\n')]\n\ndef givecount(low, high, ind):\n\tup = set()\n\tless = set()\n\twhile low < high:\n\t\tmid = low + high >> 1\n\t\tif mid <= ind:\n\t\t\tif mid != ind:\n\t\t\t\tless.add(mid)\n\t\telse:\n\t\t\tup.add(mid)\n\t\tif mid <= ind:\n\t\t\tlow = mid + 1\n\t\telse:\n\t\t\thigh = mid\n\tif low > 0:\n\t\treturn [len(less), len(up)]\n\treturn [1000, 1000]\n\ndef ncr(n, r, p=mod):\n\tnum = den = 1\n\tfor i in range(r):\n\t\tnum = num * (n - i) % p\n\t\tden = den * (i + 1) % p\n\treturn num * pow(den, p - 2, p) % p\nfacts = [1]\nfor i in range(1, 1005):\n\tfacts.append(facts[-1] * i % mod)\n(n, x, pos) = li()\nans = 0\nreq = givecount(0, n, pos)\n(a, b) = req\nans = ncr(x - 1, a) * ncr(n - x, b) * facts[n - a - b - 1] * facts[a] * facts[b] % mod\nprint(ans)\n", "mod = 1000000007\n(n, x, pos) = map(int, input().split())\nans = 1\nleft = 0\nright = n\ntoLeft = n - x\ntoRight = x - 1\nfailed = False\nc = 0\nwhile left < right:\n\tmiddle = (left + right) // 2\n\tif middle == pos:\n\t\tleft = middle + 1\n\t\tc += 1\n\telif middle > pos:\n\t\tif toLeft == 0:\n\t\t\tfailed = True\n\t\t\tbreak\n\t\telse:\n\t\t\tans *= toLeft\n\t\t\tans %= mod\n\t\t\ttoLeft -= 1\n\t\t\tright = middle\n\t\t\tc += 1\n\telif toRight == 0:\n\t\tfailed = True\n\t\tbreak\n\telse:\n\t\tans *= toRight\n\t\tans %= mod\n\t\ttoRight -= 1\n\t\tleft = middle + 1\n\t\tc += 1\nif failed:\n\tprint(0)\nelse:\n\tfor i in range(n - c):\n\t\tans *= i + 1\n\t\tans %= mod\n\tprint(ans)\n", "(n, x, p) = [int(x) for x in input().split(' ')]\na = [-1 for x in range(n)]\nM = int(1000000000.0) + 7\n(l, r) = (0, n)\nsm = x - 1\ngr = n - x\nwhile l < r:\n\tmid = (l + r) // 2\n\tif mid <= p:\n\t\tif mid == p:\n\t\t\ta[mid] = 1\n\t\telse:\n\t\t\ta[mid] = sm\n\t\t\tsm -= 1\n\t\t\tsm = max([0, sm])\n\t\tl = mid + 1\n\telif mid > p:\n\t\ta[mid] = gr\n\t\tgr -= 1\n\t\tgr = max([0, gr])\n\t\tr = mid\nanswer = 1\nrem = sm + gr\nfor i in range(n):\n\tif a[i] == -1:\n\t\tanswer *= rem\n\t\tanswer %= M\n\t\trem -= 1\n\telse:\n\t\tanswer *= a[i]\n\t\tanswer %= M\nprint(answer)\n", "import math\nyes = 'YES'\nno = 'NO'\nlower = 'L'\nhigher = 'H'\nsame = 'O'\n\ndef bin_search(a, x):\n\tleft = 0\n\tright = len(a)\n\tres = []\n\twhile left < right:\n\t\tmid = (left + right) // 2\n\t\tif a[mid] < x:\n\t\t\tleft = mid + 1\n\t\t\tres.append(higher)\n\t\telif a[mid] == x:\n\t\t\tleft = mid + 1\n\t\t\tres.append(same)\n\t\telse:\n\t\t\tright = mid\n\t\t\tres.append(lower)\n\treturn res\n\ndef solve():\n\tnumbers = list(map(int, input().split(' ')))\n\toptions = bin_search([i for i in range(numbers[0])], numbers[2])\n\tres = 1\n\t(higher_numbers, lower_numbers) = (numbers[0] - numbers[1], numbers[1] - 1)\n\tfor o in options:\n\t\tif o == higher:\n\t\t\tres *= lower_numbers\n\t\t\tlower_numbers -= 1\n\t\telif o == lower:\n\t\t\tres *= higher_numbers\n\t\t\thigher_numbers -= 1\n\tres *= math.factorial(numbers[0] - len(options))\n\tprint(res % (10 ** 9 + 7))\n\treturn None\nsolve()\n", "mod = 10 ** 9 + 7\n(n, x, pos) = list(map(int, input().split()))\nm = n - x\nl = x - 1\nans = 1\ni = 0\nj = n\nwhile i < j:\n\tmid = (i + j) // 2\n\tif mid > pos:\n\t\tans = ans * m % mod\n\t\tm = m - 1\n\t\tj = mid\n\telif mid <= pos:\n\t\tif mid == pos:\n\t\t\tans = ans * 1\n\t\telse:\n\t\t\tans = ans * l % mod\n\t\t\tl = l - 1\n\t\ti = mid + 1\nfor i in range(1, l + m + 1):\n\tans = ans * i % mod\nprint(ans % mod)\n", "import math\nimport sys, bisect\nfrom heapq import *\nfrom itertools import *\nfrom collections import *\nsys.setrecursionlimit(10 ** 6)\nI = lambda : int(sys.stdin.readline())\nneo = lambda : map(int, sys.stdin.readline().split())\nNeo = lambda : list(map(int, sys.stdin.readline().split()))\n(n, val, pos) = neo()\nless = val - 1\nlarge = n - val\ns = 0\ne = n\nAns = 1\nwhile s < e:\n\tmid = (s + e) // 2\n\tif mid < pos:\n\t\ts = mid + 1\n\t\tAns *= less\n\t\tless -= 1\n\telif mid > pos:\n\t\te = mid\n\t\tAns *= large\n\t\tlarge -= 1\n\telse:\n\t\ts = mid + 1\nless += large\nfor i in range(less, 0, -1):\n\tAns *= i\nprint(Ans % (10 ** 9 + 7))\n", "def fact(n):\n\tans = 1\n\tfor i in range(2, n + 1):\n\t\tans *= i\n\treturn ans\n(n, m, k) = [int(x) for x in input().split()]\nl = m - 1\ng = n - l - 1\nans = 1\nstart = 0\nend = n\nwhile start < end:\n\tmid = (start + end) // 2\n\tif mid == k:\n\t\tstart = mid + 1\n\telif mid < k:\n\t\tans *= l\n\t\tl -= 1\n\t\tstart = mid + 1\n\telse:\n\t\tans *= g\n\t\tg -= 1\n\t\tend = mid\nans *= fact(l + g)\nprint(ans % (10 ** 9 + 7))\n", "M = 10 ** 9 + 7\n\ndef inv(n):\n\treturn power(n, M - 2)\n\ndef power(x, y):\n\tans = 1\n\twhile y > 0:\n\t\tif y % 2 == 1:\n\t\t\tans = ans * x % M\n\t\ty = y // 2\n\t\tx = x * x % M\n\treturn ans % M\n\ndef com(n, r):\n\tif r == 0:\n\t\treturn 1\n\telse:\n\t\treturn f[n] * inv(f[n - r]) % M % M\nf = [1]\nx = 1\nfor i in range(1, 10 ** 5 + 3):\n\tx = x * i % M\n\tf.append(x)\n(n, x, pos) = map(int, input().split())\nl = []\nfor i in range(1, n + 1):\n\tl.append(i)\ncnthigh = 0\ncntlow = 0\nlow = 0\nhigh = n\nele = l[pos]\nwhile low < high:\n\tmid = (low + high) // 2\n\tif l[mid] <= ele:\n\t\tcntlow += 1\n\t\tlow = mid + 1\n\telse:\n\t\tcnthigh += 1\n\t\thigh = mid\nr = 0\nif low > 0 and l[low - 1] == ele:\n\tr = 1\nelse:\n\tprint(0)\n\texit()\ntlow = 0\nthigh = 0\ncntlow -= 1\nfor i in range(1, n + 1):\n\tif i > x:\n\t\tthigh += 1\n\tif i < x:\n\t\ttlow += 1\nif tlow < cntlow or thigh < cnthigh:\n\tprint(0)\n\texit()\nrlow = tlow - cntlow\nrhigh = thigh - cnthigh\nrtotal = rlow + rhigh\nans = f[rtotal]\nans1 = com(tlow, cntlow) % M\nans2 = com(thigh, cnthigh) % M\nanst = ans1 * ans2 % M\nanst = anst * ans % M\nprint(anst)\n", "import math\ng = lambda : map(int, input().split())\nmod = 10 ** 9 + 7\n(n, x, pos) = g()\nans = 1\nr = n\nl = 0\nans = 1\nup = n - x\nsm = x - 1\ncount = 0\nwhile l < r:\n\tm = (l + r) // 2\n\tif m <= pos:\n\t\tif m != pos:\n\t\t\tans = ans * sm\n\t\t\tsm -= 1\n\t\tl = m + 1\n\telse:\n\t\tif m != pos:\n\t\t\tans = ans * up\n\t\t\tup -= 1\n\t\tr = m\n\tcount += 1\n\tans = ans % mod\nans *= math.factorial(n - count) % mod\nans %= mod\nprint(ans)\n", "from collections import *\nfrom functools import *\nimport math\nimport sys\ninp = sys.stdin.readline\nout = sys.stdout.write\n\ndef mi():\n\treturn map(int, inp().split())\n\ndef li():\n\treturn list(mi())\n\ndef ii():\n\treturn int(inp())\n\ndef main():\n\tmod = 10 ** 9 + 7\n\n\tdef bi(n, x, p):\n\t\tans = 1\n\t\tleft = 0\n\t\tright = n\n\t\tx1 = x - 1\n\t\tn1 = n - x\n\t\tco = 0\n\t\twhile left < right:\n\t\t\tm = (left + right) // 2\n\t\t\tif m < p:\n\t\t\t\tans *= x1 % mod\n\t\t\t\tx1 -= 1\n\t\t\t\tleft = m + 1\n\t\t\telif m > p:\n\t\t\t\tans *= n1 % mod\n\t\t\t\tn1 -= 1\n\t\t\t\tright = m\n\t\t\telse:\n\t\t\t\tleft = m + 1\n\t\t\tco += 1\n\t\treturn (ans, co)\n\t(n, x, p) = mi()\n\t(ans, co) = bi(n, x, p)\n\tim = math.factorial(n - co)\n\tprint(im % mod * (ans % mod) % mod)\nmain()\n", "import os\nfrom io import BytesIO, IOBase\nimport sys\nfrom collections import defaultdict, deque, Counter\nfrom bisect import *\nfrom math import sqrt, pi, ceil, log\nimport math\nfrom itertools import permutations\nfrom copy import deepcopy\nfrom sys import setrecursionlimit\n\ndef main():\n\t(n, x, pos) = map(int, input().split())\n\tmod = 10 ** 9 + 7\n\tf = [1]\n\tfor i in range(1, 1001):\n\t\tf.append(f[-1] * i % mod)\n\tlo = 0\n\thi = n\n\tb = x - 1\n\tc = n - x\n\tans = 1\n\twhile lo < hi:\n\t\tmid = (lo + hi) // 2\n\t\tif mid < pos:\n\t\t\tans = ans * b % mod\n\t\t\tb -= 1\n\t\t\tlo = mid + 1\n\t\telif mid > pos:\n\t\t\tans = ans * c % mod\n\t\t\tc -= 1\n\t\t\thi = mid\n\t\telse:\n\t\t\tlo = mid + 1\n\tprint(ans * f[b + c] % mod)\nBUFSIZE = 8192\n\nclass FastIO(IOBase):\n\tnewlines = 0\n\n\tdef __init__(self, file):\n\t\tself._fd = file.fileno()\n\t\tself.buffer = BytesIO()\n\t\tself.writable = 'x' in file.mode or 'r' not in file.mode\n\t\tself.write = self.buffer.write if self.writable else None\n\n\tdef read(self):\n\t\twhile True:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tif not b:\n\t\t\t\tbreak\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines = 0\n\t\treturn self.buffer.read()\n\n\tdef readline(self):\n\t\twhile self.newlines == 0:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tself.newlines = b.count(b'\\n') + (not b)\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines -= 1\n\t\treturn self.buffer.readline()\n\n\tdef flush(self):\n\t\tif self.writable:\n\t\t\tos.write(self._fd, self.buffer.getvalue())\n\t\t\t(self.buffer.truncate(0), self.buffer.seek(0))\n\nclass IOWrapper(IOBase):\n\n\tdef __init__(self, file):\n\t\tself.buffer = FastIO(file)\n\t\tself.flush = self.buffer.flush\n\t\tself.writable = self.buffer.writable\n\t\tself.write = lambda s: self.buffer.write(s.encode('ascii'))\n\t\tself.read = lambda : self.buffer.read().decode('ascii')\n\t\tself.readline = lambda : self.buffer.readline().decode('ascii')\n(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))\ninput = lambda : sys.stdin.readline().rstrip('\\r\\n')\nmain()\n", "from sys import stdin, stdout\ninput = stdin.readline\nprint = lambda x: stdout.write(str(x) + '\\n')\n\ndef bs(n, pos):\n\ta = list(range(n))\n\t(l, r) = (0, n)\n\t(low, high) = (0, 0)\n\ttaken = set()\n\twhile l < r:\n\t\tm = (l + r) // 2\n\t\tif a[m] < pos:\n\t\t\tl = m + 1\n\t\t\tif m not in taken:\n\t\t\t\tlow += 1\n\t\telif a[m] > pos:\n\t\t\tr = m\n\t\t\tif m not in taken:\n\t\t\t\thigh += 1\n\t\telse:\n\t\t\tl = m + 1\n\t\ttaken.add(m)\n\treturn (low, high)\n(n, x, pos) = map(int, input().split())\n(low, high) = bs(n, pos)\n(xl, xh) = (x - 1, n - x)\nrem = xl + xh - low - high\nif xl < low or xh < high:\n\tprint(0)\n\texit()\nM = 1000000007\n\ndef nCr(n, r, M):\n\treturn fact[n] * inv[n - r] % M * inv[r] % M\nfact = [1] * (n + 1)\nfor i in range(1, n + 1):\n\tfact[i] = fact[i - 1] * i % M\ninv = [1] * (xl + 1)\ninv[xl] = pow(fact[xl], M - 2, M)\nfor i in range(xl - 1, -1, -1):\n\tinv[i] = inv[i + 1] * (i + 1) % M\nres1 = nCr(xl, low, M) * fact[low] % M\ninv = [1] * (xh + 1)\ninv[xh] = pow(fact[xh], M - 2, M)\nfor i in range(xh - 1, -1, -1):\n\tinv[i] = inv[i + 1] * (i + 1) % M\nres2 = nCr(xh, high, M) * fact[high] % M\nres3 = fact[rem]\nans = res1 * res2 * res3 % M\nprint(ans)\n", "import sys\ninput = sys.stdin.readline\nMOD = 10 ** 9 + 7\nN = 2000\nfact = [0 for _ in range(N)]\ninvfact = [0 for _ in range(N)]\nfact[0] = 1\nfor i in range(1, N):\n\tfact[i] = fact[i - 1] * i % MOD\ninvfact[N - 1] = pow(fact[N - 1], MOD - 2, MOD)\nfor i in range(N - 2, -1, -1):\n\tinvfact[i] = invfact[i + 1] * (i + 1) % MOD\n\ndef nCk(n, k):\n\tif k < 0 or n < k:\n\t\treturn 0\n\telse:\n\t\treturn fact[n] * invfact[k] * invfact[n - k] % MOD\n\ndef main():\n\t(n, x, pos) = map(int, input().split())\n\tb = 0\n\ts = 0\n\tl = 0\n\tr = n\n\twhile l < r:\n\t\tm = (l + r) // 2\n\t\tif m <= pos:\n\t\t\tl = m + 1\n\t\t\tif m != pos:\n\t\t\t\ts += 1\n\t\telse:\n\t\t\tr = m\n\t\t\tif m != pos:\n\t\t\t\tb += 1\n\tb_cnt = n - x\n\ts_cnt = x - 1\n\tc = n - 1 - b - s\n\tans = fact[c] * nCk(b_cnt, b) * nCk(s_cnt, s) * fact[b] * fact[s]\n\tprint(ans % MOD)\nfor _ in range(1):\n\tmain()\n", "import bisect\nimport math\nimport sys\ninput = sys.stdin.readline\n\ndef inp():\n\treturn int(input())\n\ndef inlt():\n\treturn list(map(int, input().split()))\n\ndef insr():\n\ts = input()\n\treturn list(s[:len(s) - 1])\n\ndef invr():\n\treturn map(int, input().split())\n\ndef solution():\n\t(n, x, pos) = inlt()\n\tsolve(n, x, pos)\n\ndef solve(n, x, pos):\n\ta = 0\n\tb = 0\n\tleft = 0\n\tright = n\n\twhile left < right:\n\t\tmiddle = (left + right) // 2\n\t\tif middle <= pos:\n\t\t\tleft = middle + 1\n\t\t\ta += 1\n\t\telse:\n\t\t\tright = middle\n\t\t\tb += 1\n\ta -= 1\n\tl = math.factorial(x - 1) // math.factorial(x - 1 - a) if x - 1 >= a else 0\n\tr = math.factorial(n - x) // math.factorial(n - x - b) if n - x >= b else 0\n\tmod = 10 ** 9 + 7\n\tl %= mod\n\tr %= mod\n\tprint(l * r * math.factorial(n - 1 - a - b) % mod)\nsolution()\n", "PRIME = int(1000000000.0 + 7)\n\ndef perm(k, n, mod):\n\tres = 1\n\tfor i in range(n, n - k, -1):\n\t\tres = res * i % mod\n\treturn res\n\ndef BinarySearch(a, x):\n\tbranches = []\n\tleft = 0\n\tright = len(a)\n\twhile left < right:\n\t\tmiddle = int((left + right) // 2)\n\t\tif a[middle] <= x:\n\t\t\tbranches.append(1)\n\t\t\tleft = middle + 1\n\t\telse:\n\t\t\tbranches.append(0)\n\t\t\tright = middle\n\treturn branches\n(n, x, pos) = tuple(map(int, input().split()))\npath = BinarySearch(list(range(1, n + 1)), pos + 1)\nn_ones = sum(path)\nn_zeros = len(path) - n_ones\na1 = perm(n_ones - 1, x - 1, PRIME)\na0 = perm(n_zeros, n - x, PRIME)\nn_other = n - (n_ones + n_zeros)\na_other = perm(n_other, n_other, PRIME)\nres = a1 * a0 % PRIME\nres = res * a_other % PRIME\nprint(res)\n", "import sys, string\nfrom collections import deque, defaultdict\nfrom math import sqrt, factorial, gcd, ceil, atan, pi, log2\n\ndef input():\n\treturn sys.stdin.buffer.readline().decode('utf-8')\nfrom bisect import bisect_left, bisect_right\nfrom operator import add\nMOD = int(1000000000.0) + 7\nINF = float('inf')\n\ndef prod(a, b):\n\tans = 1\n\tfor x in range(a, b + 1):\n\t\tans *= x\n\t\tans %= MOD\n\treturn ans\n\ndef fact(x):\n\tans = 1\n\twhile x:\n\t\tans *= x\n\t\tans %= MOD\n\t\tx -= 1\n\treturn ans\n\ndef coef(n, k):\n\tif k > n:\n\t\treturn 0\n\treturn prod(n - k + 1, n) * pow(fact(k) % MOD, MOD - 2, MOD) % MOD\n\ndef solve():\n\t(n, x, pos) = [int(x) for x in input().split()]\n\tl = 0\n\tr = n\n\tless = x - 1\n\tgreater = n - x\n\tans = 1\n\tcnt = 0\n\twhile l < r:\n\t\tm = (l + r) // 2\n\t\tif m < pos:\n\t\t\tl = m + 1\n\t\t\tans *= less\n\t\t\tless -= 1\n\t\telif m > pos:\n\t\t\tr = m\n\t\t\tans *= greater\n\t\t\tgreater -= 1\n\t\telse:\n\t\t\tl = m + 1\n\t\tcnt += 1\n\tprint(ans * fact(n - cnt) % MOD)\nT = 1\nfor case in range(1, T + 1):\n\tans = solve()\n", "from __future__ import division, print_function\nimport os, sys\nfrom io import BytesIO, IOBase\nif sys.version_info[0] < 3:\n\tfrom __builtin__ import xrange as range\n\tfrom future_builtins import ascii, filter, hex, map, oct, zip\n\ndef ii():\n\treturn int(input())\n\ndef si():\n\treturn input()\n\ndef mi():\n\treturn map(int, input().strip().split(' '))\n\ndef msi():\n\treturn map(str, input().strip().split(' '))\n\ndef li():\n\treturn list(mi())\n\ndef dmain():\n\tsys.setrecursionlimit(1000000)\n\tthreading.stack_size(1024000)\n\tthread = threading.Thread(target=main)\n\tthread.start()\nimport sys\ninput = sys.stdin.readline\nscanner = lambda : int(input())\nstring = lambda : input().rstrip()\nget_list = lambda : list(read())\nread = lambda : map(int, input().split())\nget_float = lambda : map(float, input().split())\n\ndef ceil(x):\n\tif x != int(x):\n\t\tx = int(x) + 1\n\treturn x\n\ndef factorial(x, m):\n\tval = 1\n\twhile x > 0:\n\t\tval = val * x % m\n\t\tx -= 1\n\treturn val\n\ndef fact(x):\n\tval = 1\n\twhile x > 0:\n\t\tval *= x\n\t\tx -= 1\n\treturn val\n\ndef swaparr(arr, a, b):\n\ttemp = arr[a]\n\tarr[a] = arr[b]\n\tarr[b] = temp\n\ndef gcd(a, b):\n\tif b == 0:\n\t\treturn a\n\treturn gcd(b, a % b)\n\ndef lcm(a, b):\n\treturn a * b // math.gcd(a, b)\n\ndef is_integer(n):\n\treturn math.ceil(n) == math.floor(n)\n\ndef nCr(n, k):\n\tif k > n:\n\t\treturn 0\n\tif k > n - k:\n\t\tk = n - k\n\tres = 1\n\tfor i in range(k):\n\t\tres = res * (n - i)\n\t\tres = res / (i + 1)\n\treturn int(res) % MOD\n\ndef comb(n, x):\n\t(a, b) = (1, 1)\n\tfor i in range(1, x + 1):\n\t\ta *= n + 1 - i\n\t\tb *= i\n\treturn a // b % MOD\n\ndef primefs(n):\n\tprimes = {}\n\twhile n % 2 == 0 and n > 0:\n\t\tprimes[2] = primes.get(2, 0) + 1\n\t\tn = n // 2\n\tfor i in range(3, int(n ** 0.5) + 2, 2):\n\t\twhile n % i == 0 and n > 0:\n\t\t\tprimes[i] = primes.get(i, 0) + 1\n\t\t\tn = n // i\n\tif n > 2:\n\t\tprimes[n] = primes.get(n, 0) + 1\n\treturn primes\n\ndef power(x, y, p):\n\tif y == 0:\n\t\treturn 1\n\tres = 1\n\tx = x % p\n\tif x == 0:\n\t\treturn 0\n\twhile y > 0:\n\t\tif y & 1 == 1:\n\t\t\tres = res * x % p\n\t\ty = y >> 1\n\t\tx = x * x % p\n\treturn res\n\ndef swap(a, b):\n\ttemp = a\n\ta = b\n\tb = temp\n\treturn (a, b)\n\ndef find(x, link):\n\tp = x\n\twhile p != link[p]:\n\t\tp = link[p]\n\twhile x != p:\n\t\tnex = link[x]\n\t\tlink[x] = p\n\t\tx = nex\n\treturn p\n\ndef union(x, y, link, size):\n\tx = find(x, link)\n\ty = find(y, link)\n\tif size[x] < size[y]:\n\t\t(x, y) = swap(x, y)\n\tif x != y:\n\t\tsize[x] += size[y]\n\t\tlink[y] = x\n\ndef sieve(n):\n\tprime = [True for i in range(n + 1)]\n\t(prime[0], prime[1]) = (False, False)\n\tp = 2\n\twhile p * p <= n:\n\t\tif prime[p] == True:\n\t\t\tfor i in range(p * p, n + 1, p):\n\t\t\t\tprime[i] = False\n\t\tp += 1\n\treturn prime\n\ndef phi(n):\n\tresult = n\n\tp = 2\n\twhile p * p <= n:\n\t\tif n % p == 0:\n\t\t\twhile n % p == 0:\n\t\t\t\tn = n // p\n\t\t\tresult = result * (1.0 - 1.0 / float(p))\n\t\tp = p + 1\n\tif n > 1:\n\t\tresult = result * (1.0 - 1.0 / float(n))\n\treturn int(result)\n\ndef is_prime(n):\n\tif n == 0:\n\t\treturn False\n\tif n == 1:\n\t\treturn True\n\tfor i in range(2, int(n ** (1 / 2)) + 1):\n\t\tif not n % i:\n\t\t\treturn False\n\treturn True\n\ndef next_prime(n, primes):\n\twhile primes[n] != True:\n\t\tn += 1\n\treturn n\nMAXN = int(100000.0 + 5)\n\ndef spf_sieve():\n\tspf[1] = 1\n\tfor i in range(2, MAXN):\n\t\tspf[i] = i\n\tfor i in range(4, MAXN, 2):\n\t\tspf[i] = 2\n\tfor i in range(3, ceil(MAXN ** 0.5), 2):\n\t\tif spf[i] == i:\n\t\t\tfor j in range(i * i, MAXN, i):\n\t\t\t\tif spf[j] == j:\n\t\t\t\t\tspf[j] = i\nspf = [0 for i in range(MAXN)]\n\ndef factoriazation(x):\n\tres = []\n\tfor i in range(2, int(x ** 0.5) + 1):\n\t\twhile x % i == 0:\n\t\t\tres.append(i)\n\t\t\tx //= i\n\tif x != 1:\n\t\tres.append(x)\n\treturn res\n\ndef factors(n):\n\tres = []\n\tfor i in range(1, int(n ** 0.5) + 1):\n\t\tif n % i == 0:\n\t\t\tres.append(i)\n\t\t\tres.append(n // i)\n\treturn list(set(res))\n\ndef int_array():\n\treturn list(map(int, input().strip().split()))\n\ndef float_array():\n\treturn list(map(float, input().strip().split()))\n\ndef str_array():\n\treturn input().strip().split()\n\ndef binary_search(low, high, w, h, n):\n\twhile low < high:\n\t\tmid = low + (high - low) // 2\n\t\tif check(mid, w, h, n):\n\t\t\tlow = mid + 1\n\t\telse:\n\t\t\thigh = mid\n\treturn low\n\ndef check(moves, n):\n\tval = (moves + 1) // 2\n\trem = moves - val\n\tsol = (val + 1) * (rem + 1)\n\treturn sol < n\n\ndef sortSecond(val):\n\treturn val[1]\nMOD = int(1000000000.0) + 7\nCMOD = 998244353\nINF = float('inf')\nNINF = -float('inf')\nsmall = 'abcdefghijklmnopqrstuvwxyz'\nlarge = small.upper()\nfrom itertools import permutations\nimport math\nimport bisect as bis\nimport random\nimport sys\nimport collections as collect\nimport functools as fnt\nfrom decimal import Decimal\n\ndef solve():\n\t(n, x, pos) = read()\n\t(low, high) = (0, n)\n\tless = 0\n\tmore = 0\n\twhile low < high:\n\t\tmid = (low + high) // 2\n\t\tif mid <= pos:\n\t\t\tlow = mid + 1\n\t\t\tless += 1\n\t\telse:\n\t\t\thigh = mid\n\t\t\tmore += 1\n\tless -= 1\n\tif less <= x - 1 and more <= n - x:\n\t\tans = comb(x - 1, less) * factorial(less, MOD) % MOD * (comb(n - x, more) * factorial(more, MOD) % MOD) * factorial(n - 1 - (less + more), MOD) % MOD\n\t\tprint(ans)\n\telse:\n\t\tprint(0)\nBUFSIZE = 8192\n\nclass FastIO(IOBase):\n\tnewlines = 0\n\n\tdef __init__(self, file):\n\t\tself._fd = file.fileno()\n\t\tself.buffer = BytesIO()\n\t\tself.writable = 'x' in file.mode or 'r' not in file.mode\n\t\tself.write = self.buffer.write if self.writable else None\n\n\tdef read(self):\n\t\twhile True:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tif not b:\n\t\t\t\tbreak\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines = 0\n\t\treturn self.buffer.read()\n\n\tdef readline(self):\n\t\twhile self.newlines == 0:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tself.newlines = b.count(b'\\n') + (not b)\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines -= 1\n\t\treturn self.buffer.readline()\n\n\tdef flush(self):\n\t\tif self.writable:\n\t\t\tos.write(self._fd, self.buffer.getvalue())\n\t\t\t(self.buffer.truncate(0), self.buffer.seek(0))\n\nclass IOWrapper(IOBase):\n\n\tdef __init__(self, file):\n\t\tself.buffer = FastIO(file)\n\t\tself.flush = self.buffer.flush\n\t\tself.writable = self.buffer.writable\n\t\tself.write = lambda s: self.buffer.write(s.encode('ascii'))\n\t\tself.read = lambda : self.buffer.read().decode('ascii')\n\t\tself.readline = lambda : self.buffer.readline().decode('ascii')\n\ndef print(*args, **kwargs):\n\t(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))\n\tat_start = True\n\tfor x in args:\n\t\tif not at_start:\n\t\t\tfile.write(sep)\n\t\tfile.write(str(x))\n\t\tat_start = False\n\tfile.write(kwargs.pop('end', '\\n'))\n\tif kwargs.pop('flush', False):\n\t\tfile.flush()\nif sys.version_info[0] < 3:\n\t(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))\nelse:\n\t(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))\ninput = lambda : sys.stdin.readline().rstrip('\\r\\n')\nt = 1\nfor i in range(t):\n\tsolve()\n", "MOD = 10 ** 9 + 7\n(n, x, pos) = map(int, input().split())\nlt = 0\ngt = 0\nleft = 0\nright = n\nwhile left < right:\n\tmiddle = (left + right) // 2\n\tif pos >= middle:\n\t\tif pos > middle:\n\t\t\tlt += 1\n\t\tleft = middle + 1\n\telse:\n\t\tgt += 1\n\t\tright = middle\nif x - 1 >= lt and n - x >= gt:\n\tc = 1\n\tfor i in range(x - 1, x - 1 - lt, -1):\n\t\tc *= i\n\tc %= MOD\n\tans = c\n\tc = 1\n\tfor i in range(n - x, n - x - gt, -1):\n\t\tc *= i\n\tc %= MOD\n\tans = ans * c % MOD\n\tc = 1\n\tfor i in range(1, n - lt - gt):\n\t\tc = c * i % MOD\n\tans = ans * c % MOD\nelse:\n\tans = 0\nprint(ans)\n", "def aranjamente(n, k) -> int:\n\tmodulo = 10 ** 9 + 7\n\toutput = 1\n\tif k > n:\n\t\treturn 0\n\tfor x in range(n - k + 1, n + 1):\n\t\toutput = output * x % modulo\n\treturn output\n\ndef reorder():\n\t(n, k, pos) = [int(x) for x in input().split(' ')]\n\tleft = 0\n\tright = n\n\tmodulo = 10 ** 9 + 7\n\tans = 1\n\tleft_val = 0\n\tright_val = 0\n\twhile left < right:\n\t\tmiddle = (left + right) // 2\n\t\tif middle <= pos:\n\t\t\tleft = middle + 1\n\t\t\tleft_val += 1\n\t\telse:\n\t\t\tright = middle\n\t\t\tright_val += 1\n\tal = aranjamente(k - 1, left_val - 1)\n\tar = aranjamente(n - k, right_val)\n\tfor x in range(1, n - left_val - right_val + 1):\n\t\tans = ans * x % modulo\n\tans = ans * al % modulo\n\tans = ans * ar % modulo\n\tprint(ans)\nreorder()\n", "(n, x, pos) = [int(a) for a in input().split()]\nfactorials = [1]\nfor i in range(1, 1033):\n\tfactorials.append(factorials[-1] * i)\n\ndef fac(n):\n\treturn factorials[n]\nmod = int(1000000000.0 + 7)\ncount_left = 0\ncount_right = 0\n\ndef binary_search(a, x):\n\tglobal count_left, count_right\n\tleft = 0\n\tright = len(a)\n\twhile left < right:\n\t\tmiddle = (left + right) // 2\n\t\tif a[middle] <= x:\n\t\t\tleft = middle + 1\n\t\t\tif a[middle] != x:\n\t\t\t\tcount_left += 1\n\t\telse:\n\t\t\tright = middle\n\t\t\tcount_right += 1\nnums = list(range(n))\nbinary_search(nums, pos)\nif x <= count_left or x > n - count_right:\n\tprint(0)\n\timport sys\n\tsys.exit()\n\ndef binomial(n, k):\n\treturn 1 if n <= 0 else fac(n) // fac(n - k)\nleft = max(1, binomial(x - 1, count_left) % mod)\nright = max(1, binomial(n - x, count_right) % mod)\nprint(fac(n - count_left - count_right - 1) * left * right % mod)\n", "from math import factorial\n\ndef combo(n, x, pos):\n\tmod = 10 ** 9 + 7\n\tleft = 0\n\tright = n\n\tmore = n - x\n\tless = x - 1\n\tanswer = 1\n\twhile left < right:\n\t\tmid = (left + right) // 2\n\t\tif mid < pos:\n\t\t\tanswer *= less\n\t\t\tless -= 1\n\t\t\tleft = mid + 1\n\t\telif mid > pos:\n\t\t\tanswer *= more\n\t\t\tmore -= 1\n\t\t\tright = mid\n\t\telse:\n\t\t\tleft = mid + 1\n\tanswer *= factorial(more + less)\n\treturn answer % mod\n(a, b, c) = map(int, input().strip().split())\nprint(combo(a, b, c))\n", "from __future__ import division, print_function\nfrom fractions import Fraction\nimport sys\nimport os\nfrom io import BytesIO, IOBase\nfrom functools import cmp_to_key\nfrom heapq import *\nfrom math import gcd, factorial, floor, ceil\nfrom copy import deepcopy\nfrom collections import deque\nfrom bisect import bisect_left as bl\nfrom bisect import bisect_right as br\nfrom bisect import bisect\nBUFSIZE = 8192\n\nclass FastIO(IOBase):\n\tnewlines = 0\n\n\tdef __init__(self, file):\n\t\tself._fd = file.fileno()\n\t\tself.buffer = BytesIO()\n\t\tself.writable = 'x' in file.mode or 'r' not in file.mode\n\t\tself.write = self.buffer.write if self.writable else None\n\n\tdef read(self):\n\t\twhile True:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tif not b:\n\t\t\t\tbreak\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines = 0\n\t\treturn self.buffer.read()\n\n\tdef readline(self):\n\t\twhile self.newlines == 0:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tself.newlines = b.count(b'\\n') + (not b)\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines -= 1\n\t\treturn self.buffer.readline()\n\n\tdef flush(self):\n\t\tif self.writable:\n\t\t\tos.write(self._fd, self.buffer.getvalue())\n\t\t\t(self.buffer.truncate(0), self.buffer.seek(0))\n\nclass IOWrapper(IOBase):\n\n\tdef __init__(self, file):\n\t\tself.buffer = FastIO(file)\n\t\tself.flush = self.buffer.flush\n\t\tself.writable = self.buffer.writable\n\t\tself.write = lambda s: self.buffer.write(s.encode('ascii'))\n\t\tself.read = lambda : self.buffer.read().decode('ascii')\n\t\tself.readline = lambda : self.buffer.readline().decode('ascii')\n\ndef print(*args, **kwargs):\n\t(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))\n\tat_start = True\n\tfor x in args:\n\t\tif not at_start:\n\t\t\tfile.write(sep)\n\t\tfile.write(str(x))\n\t\tat_start = False\n\tfile.write(kwargs.pop('end', '\\n'))\n\tif kwargs.pop('flush', False):\n\t\tfile.flush()\nif sys.version_info[0] < 3:\n\t(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))\nelse:\n\t(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))\nfrom types import GeneratorType\n\ndef iterative(f, stack=[]):\n\n\tdef wrapped_func(*args, **kwargs):\n\t\tif stack:\n\t\t\treturn f(*args, **kwargs)\n\t\tto = f(*args, **kwargs)\n\t\twhile True:\n\t\t\tif type(to) is GeneratorType:\n\t\t\t\tstack.append(to)\n\t\t\t\tto = next(to)\n\t\t\t\tcontinue\n\t\t\tstack.pop()\n\t\t\tif not stack:\n\t\t\t\tbreak\n\t\t\tto = stack[-1].send(to)\n\t\treturn to\n\treturn wrapped_func\n\ndef inp():\n\treturn sys.stdin.readline().rstrip('\\r\\n')\n\ndef out(var):\n\tsys.stdout.write(str(var))\n\ndef lis():\n\treturn list(map(int, inp().split()))\n\ndef stringlis():\n\treturn list(map(str, inp().split()))\n\ndef sep():\n\treturn map(int, inp().split())\n\ndef strsep():\n\treturn map(str, inp().split())\n\ndef zerolist(n):\n\treturn [0] * n\n\ndef nextline():\n\tout('\\n')\n\ndef testcase(t):\n\tfor pp in range(t):\n\t\tsolve(pp)\n\ndef printlist(a):\n\tfor p in range(0, len(a)):\n\t\tout(str(a[p]) + ' ')\n\ndef google(p):\n\tprint('Case #' + str(p) + ': ', end='')\n\ndef lcm(a, b):\n\treturn a * b // gcd(a, b)\n\ndef power(x, y, p):\n\tres = 1\n\tx = x % p\n\tif x == 0:\n\t\treturn 0\n\twhile y > 0:\n\t\tif y & 1 == 1:\n\t\t\tres = res * x % p\n\t\ty = y >> 1\n\t\tx = x * x % p\n\treturn res\n\ndef ncr(n, r):\n\treturn factorial(n) // (factorial(r) * factorial(max(n - r, 1)))\n\ndef isPrime(n):\n\tif n <= 1:\n\t\treturn False\n\tif n <= 3:\n\t\treturn True\n\tif n % 2 == 0 or n % 3 == 0:\n\t\treturn False\n\ti = 5\n\twhile i * i <= n:\n\t\tif n % i == 0 or n % (i + 2) == 0:\n\t\t\treturn False\n\t\ti = i + 6\n\treturn True\ninf = pow(10, 20)\nmod = 10 ** 9 + 7\n\ndef solve(case):\n\t(n, x, pos) = sep()\n\tlo = 0\n\thi = n\n\tmid = (lo + hi) // 2\n\tless = 0\n\tmore = 0\n\twhile mid != pos:\n\t\tif mid > pos:\n\t\t\tmore += 1\n\t\t\thi = mid\n\t\telse:\n\t\t\tless += 1\n\t\t\tlo = mid + 1\n\t\tmid = (lo + hi) // 2\n\tlo = (lo + hi) // 2 + 1\n\twhile hi > lo:\n\t\thi = (lo + hi) // 2\n\t\tif hi != pos:\n\t\t\tmore += 1\n\tif less > x - 1 or more > n - x:\n\t\tprint(0)\n\telse:\n\t\ttemp = 1\n\t\ttemp *= ncr(n - x, more) % mod\n\t\ttemp *= ncr(x - 1, less) % mod\n\t\ttemp *= factorial(less) % mod\n\t\ttemp *= factorial(more) % mod\n\t\ttemp *= factorial(n - (more + less + 1)) % mod\n\t\tprint(temp % mod)\ntestcase(1)\n", "from sys import maxsize, stdout, stdin, stderr\nmod = int(1000000000.0 + 7)\n\ndef tup():\n\treturn map(int, stdin.readline().split())\n\ndef I():\n\treturn int(stdin.readline())\n\ndef lint():\n\treturn [int(x) for x in stdin.readline().split()]\n\ndef S():\n\treturn input().strip()\n\ndef grid(r, c):\n\treturn [lint() for i in range(r)]\n\ndef debug(*args, c=6):\n\tprint('\\x1b[3{}m'.format(c), *args, '\\x1b[0m', file=stderr)\nfact = [0] * 1001\nfact[0] = 1\nfact[1] = 1\nfor i in range(1, 1001):\n\tfact[i] = i * fact[i - 1] % mod\n(n, x, p) = tup()\nsm = x - 1\ngr = n - x\nl = 0\nh = n\nans = 1\nwhile l < h:\n\tm = (l + h) // 2\n\tif m == p:\n\t\tl = m + 1\n\telif m > p:\n\t\th = m\n\t\tans = ans * gr % mod\n\t\tgr -= 1\n\telse:\n\t\tans = ans * sm % mod\n\t\tl = m + 1\n\t\tsm -= 1\n\tn -= 1\nif ans > 0:\n\tans = ans * fact[n] % mod\n\tprint(ans)\nelse:\n\tprint(0)\n", "import sys\nfrom collections import deque\nfrom copy import *\nfrom itertools import permutations as prm, product\n\ndef eprint(*args):\n\tprint(*args, file=sys.stderr)\nzz = 1\nif zz:\n\tinput = sys.stdin.readline\nelse:\n\tsys.stdin = open('input.txt', 'r')\n\tsys.stdout = open('all.txt', 'w')\ndi = [[-1, 0], [1, 0], [0, 1], [0, -1]]\n\ndef string(s):\n\treturn ''.join(s)\n\ndef fori(n):\n\treturn [fi() for i in range(n)]\n\ndef inc(d, c, x=1):\n\td[c] = d[c] + x if c in d else x\n\ndef bo(i):\n\treturn ord(i) - ord('A')\n\ndef li():\n\treturn [int(xx) for xx in input().split()]\n\ndef fli():\n\treturn [float(x) for x in input().split()]\n\ndef comp(a, b):\n\tif a > b:\n\t\treturn 2\n\treturn 2 if a == b else 0\n\ndef gi():\n\treturn [xx for xx in input().split()]\n\ndef cil(n, m):\n\treturn n // m + int(n % m > 0)\n\ndef fi():\n\treturn int(input())\n\ndef pro(a):\n\treturn reduce(lambda a, b: a * b, a)\n\ndef swap(a, i, j):\n\t(a[i], a[j]) = (a[j], a[i])\n\ndef si():\n\treturn list(input().rstrip())\n\ndef mi():\n\treturn map(int, input().split())\n\ndef gh():\n\tsys.stdout.flush()\n\ndef isvalid(i, j, n, m):\n\treturn 0 <= i < n and 0 <= j < m\n\ndef bo(i):\n\treturn ord(i) - ord('a')\n\ndef graph(n, m):\n\tfor i in range(m):\n\t\t(x, y) = mi()\n\t\ta[x].append(y)\n\t\ta[y].append(x)\nt = 1\nmod = 10 ** 9 + 7\nf = [1 for i in range(1001)]\ninf = [1 for i in range(1001)]\nfor i in range(0, 1001):\n\tf[i] = f[i - 1] * max(i, 1) % mod\n\tinf[i] = pow(f[i], mod - 2, mod)\n\ndef ncr(n, r):\n\tif n < r:\n\t\treturn 0\n\treturn f[n] * inf[r] * inf[n - r] % mod\nwhile t > 0:\n\tt -= 1\n\t(n, x, pos) = mi()\n\tu = d = 0\n\tl = 0\n\tr = n\n\twhile l < r:\n\t\tmid = (l + r) // 2\n\t\tif mid > pos:\n\t\t\tu += 1\n\t\tif mid < pos:\n\t\t\td += 1\n\t\tif mid <= pos:\n\t\t\tl = mid + 1\n\t\telse:\n\t\t\tr = mid\n\tans = ncr(x - 1, d) * f[d] * ncr(n - x, u) * f[u] * f[n - u - d - 1] % mod\n\tprint(ans)\n", "def C(n, k):\n\tans = 1\n\tfor i in range(n, n - k, -1):\n\t\tans *= i\n\t\tans %= 10 ** 9 + 7\n\tans = max(1, ans)\n\treturn ans\n(n, m, k) = map(int, input().split())\nl = 0\nr = int(n)\nx1 = 0\nx2 = 0\nwhile l < r:\n\tmid = (l + r) // 2\n\tif mid < k:\n\t\tl = mid + 1\n\t\tx1 += 1\n\telif mid == k:\n\t\tl = mid + 1\n\telse:\n\t\tr = mid\n\t\tx2 += 1\nif x1 > m - 1 or x2 > n - m:\n\tprint(0)\nelse:\n\tAns = 1\n\tAns *= C(m - 1, x1)\n\tAns *= C(n - m, x2)\n\tAns %= 10 ** 9 + 7\n\tfor i in range(1, n - x1 - x2):\n\t\tAns *= i\n\t\tAns %= 10 ** 9 + 7\n\tprint(Ans)\n", "(n, x, p) = map(int, input().split())\n(l, r) = (0, n)\nbig = small = 0\nwhile l < r:\n\tm = (l + r) // 2\n\tif p < m:\n\t\tr = m\n\t\tbig += 1\n\telse:\n\t\tl = m + 1\n\t\tif m != p:\n\t\t\tsmall += 1\nans = 1\nmod = 1000000007\nfor i in range(big):\n\tans = ans * (n - x - i) % mod\nfor i in range(1, small + 1):\n\tans = ans * (x - i) % mod\nfor i in range(1, n - small - big):\n\tans = ans * i % mod\nprint(ans)\n", "from sys import stdin, stdout\ninput = stdin.readline\nfrom collections import defaultdict as dd\nimport math\n\ndef geti():\n\treturn map(int, input().strip().split())\n\ndef getl():\n\treturn list(map(int, input().strip().split()))\n\ndef gets():\n\treturn input()\n\ndef geta():\n\treturn int(input())\n\ndef print_s(s):\n\tstdout.write(s + '\\n')\n\ndef solve():\n\t(n, x, pos) = geti()\n\tmod = int(1000000000.0 + 7)\n\tstart = 0\n\tend = n\n\tans = 1\n\tleft = x - 1\n\tright = n - x\n\trem = n - 1\n\twhile start < end:\n\t\tmid = start + (end - start) // 2\n\t\tif mid == pos:\n\t\t\tstart = mid + 1\n\t\telif mid < pos:\n\t\t\trem -= 1\n\t\t\tans *= left\n\t\t\tleft -= 1\n\t\t\tans %= mod\n\t\t\tstart = mid + 1\n\t\telse:\n\t\t\trem -= 1\n\t\t\tans *= right\n\t\t\tright -= 1\n\t\t\tans %= mod\n\t\t\tend = mid\n\tfor i in range(rem, 0, -1):\n\t\tans *= i\n\t\tans %= mod\n\tprint(ans)\nsolve()\n", "import math\nimport sys\nsys.setrecursionlimit(1000000)\n(n, x, pos) = map(int, input().split())\nleft = 0\nright = n\nans = 1\ntx = x - 1\nty = n - x\nwhile left < right:\n\tmid = (left + right) // 2\n\tif mid > pos:\n\t\tans = ans * ty % (10 ** 9 + 7)\n\t\tty -= 1\n\t\tright = mid\n\telif mid < pos:\n\t\tans = ans * tx % (10 ** 9 + 7)\n\t\ttx -= 1\n\t\tleft = mid + 1\n\telse:\n\t\tleft = mid + 1\nfor i in range(1, tx + ty + 1):\n\tans = ans * i % (10 ** 9 + 7)\nprint(ans)\n", "mod = 10 ** 9 + 7\n(n, x, pos) = map(int, input().split())\n(left, right) = (0, n)\n(lower, higher, ans) = (x - 1, n - x, 1)\nwhile left < right:\n\tmid = (left + right) // 2\n\tif mid == pos:\n\t\tleft = mid + 1\n\telif mid > pos:\n\t\tans = ans * higher % mod\n\t\tright = mid\n\t\thigher -= 1\n\telse:\n\t\tans = ans * lower % mod\n\t\tlower -= 1\n\t\tleft = mid + 1\nlower += higher\nwhile lower > 0:\n\tans = ans * lower % mod\n\tlower -= 1\nprint(ans % mod)\n", "from math import perm as A, factorial as P\nMOD = 1000 * 1000 * 1000 + 7\n\ndef solve():\n\t(n, x, pos) = map(int, input().split())\n\tleft_count = 0\n\tright_count = 0\n\tleft = 0\n\tright = n\n\twhile left < right:\n\t\tmiddle = (left + right) // 2\n\t\tif middle <= pos:\n\t\t\tleft = middle + 1\n\t\t\tleft_count += 1\n\t\telse:\n\t\t\tright = middle\n\t\t\tright_count += 1\n\tleft_count -= 1\n\tans = A(x - 1, left_count) % MOD\n\tans *= A(n - x, right_count) % MOD\n\tans *= P(n - 1 - left_count - right_count) % MOD\n\tprint(ans % MOD, end='')\nsolve()\n", "import math\n(n, x, p) = map(int, input().split())\n(low, high, less_count, more_count) = (0, n, 0, 0)\nwhile low < high:\n\tmid = (low + high) // 2\n\tif mid > p:\n\t\tmore_count += 1\n\t\thigh = mid\n\telse:\n\t\tless_count += int(p != mid)\n\t\tlow = mid + 1\n(left, avail_less, avail_more) = (n - less_count - more_count - 1, x - 1, n - x)\n(less_choices, more_choices) = (math.comb(avail_less, less_count) * math.factorial(less_count) % (10 ** 9 + 7), math.comb(avail_more, more_count) * math.factorial(more_count) % (10 ** 9 + 7))\nprint(less_choices * more_choices * math.factorial(left) % (10 ** 9 + 7))\n", "import math\nimport sys\nsys.setrecursionlimit(1000)\n_MODER = 10 ** 9 + 7\n\ndef solve(n: int, x: int, p: int) -> int:\n\n\tdef per(lo, hi, small_count, large_count):\n\t\tif lo >= hi:\n\t\t\treturn math.factorial(small_count + large_count)\n\t\tmid = (lo + hi) // 2\n\t\tif p == mid:\n\t\t\treturn per(mid + 1, hi, small_count, large_count)\n\t\telif p < mid:\n\t\t\tif large_count == 0:\n\t\t\t\treturn 0\n\t\t\treturn large_count * per(lo, mid, small_count, large_count - 1) % _MODER\n\t\telse:\n\t\t\tif small_count == 0:\n\t\t\t\treturn 0\n\t\t\treturn small_count * per(mid + 1, hi, small_count - 1, large_count) % _MODER\n\tres = per(0, n, x - 1, n - x)\n\treturn res\n(n, x, p) = map(int, input().split())\nr = solve(n, x, p)\nprint(r)\n", "mod = int(1000000000.0 + 7)\nfac = [1]\nfor i in range(1, 1001):\n\tfac.append(fac[-1] * i % mod)\ninverse_fac = [pow(fac[-1], mod - 2, mod)]\nfor i in range(1000, 0, -1):\n\tinverse_fac.append(inverse_fac[-1] * i % mod)\ninverse_fac.reverse()\n\ndef ncr(n, r):\n\tif n < r:\n\t\treturn 0\n\treturn fac[n] * inverse_fac[n - r] % mod\n(n, x, pos) = map(int, input().split())\nreq_b = 0\nreq_s = 0\nhave_b = n - x\nhave_s = x - 1\nl = 0\nh = n\nwhile l < h:\n\tmid = (l + h) // 2\n\tif mid > pos:\n\t\th = mid\n\t\treq_b += 1\n\telif mid < pos:\n\t\tl = mid + 1\n\t\treq_s += 1\n\telse:\n\t\tl = mid + 1\nbi = ncr(have_b, req_b)\nsm = ncr(have_s, req_s)\nremain = fac[n - req_b - req_s - 1]\nans = bi * sm % mod\nans = ans * remain % mod\nprint(ans)\n", "(n, x, pos) = map(int, input().split())\ngt = []\n(l, r) = (0, n)\nwhile l < r:\n\tmid = (l + r) // 2\n\tif mid <= pos:\n\t\tgt.append(False)\n\t\tl = mid + 1\n\telse:\n\t\tgt.append(True)\n\t\tr = mid\n(a, b) = (gt.count(True), gt.count(False))\n(aa, bb) = (n - x, x)\nbb -= 1\nb -= 1\nsol = 1\nfor i in range(a):\n\tsol *= aa - i\n\tsol %= 10 ** 9 + 7\nfor i in range(b):\n\tsol *= bb - i\n\tsol %= 10 ** 9 + 7\nfor i in range(n - len(gt)):\n\tsol *= i + 1\n\tsol %= 10 ** 9 + 7\nprint(sol)\n", "def c(n, k):\n\tif k > n:\n\t\treturn 0\n\ts = 1\n\tfor i in range(max(n - k, k) + 1, n + 1):\n\t\ts *= i\n\tfor i in range(2, min(k, n - k) + 1):\n\t\ts //= i\n\treturn s % mod\n\ndef fa(k):\n\ts = 1\n\tfor i in range(2, k + 1):\n\t\ts *= i\n\t\ts %= mod\n\treturn s\n(n, x, pos) = map(int, input().split())\nmod = 10 ** 9 + 7\nbol = 0\nmen = 0\nl = 0\nr = n\nwhile l < r:\n\tm = (l + r) // 2\n\tif pos > m:\n\t\tmen += 1\n\t\tl = m + 1\n\telif m == pos:\n\t\tl = m + 1\n\telse:\n\t\tbol += 1\n\t\tr = m\nprint(c(x - 1, men) * c(n - x, bol) * fa(n - bol - men - 1) * fa(bol) * fa(men) % mod)\n", "def read_ints():\n\treturn map(int, input().split(' '))\n\ndef comb(n, k):\n\tans = 1\n\tfor i in range(k):\n\t\tans *= n - i\n\tfor i in range(k):\n\t\tans //= i + 1\n\treturn ans\n\ndef perm(n, k):\n\tans = 1\n\tfor i in range(k):\n\t\tans *= n - i\n\treturn ans\nmod = 1000000007\n(n, x, pos) = read_ints()\nleft = 0\nright = n\nsmaller = x - 1\nlarger = n - x\nschosen = 0\nlchosen = 0\nwhile left < right:\n\tmid = (left + right) // 2\n\tif mid == pos:\n\t\tleft = mid + 1\n\telif mid < pos:\n\t\tschosen += 1\n\t\tif schosen > smaller:\n\t\t\tprint(0)\n\t\t\texit(0)\n\t\tleft = mid + 1\n\telse:\n\t\tlchosen += 1\n\t\tif lchosen > larger:\n\t\t\tprint(0)\n\t\t\texit(0)\n\t\tright = mid\nrem = n - schosen - lchosen - 1\nans = perm(smaller, schosen) * perm(larger, lchosen) * perm(rem, rem) % mod\nprint(ans)\n", "import math\n\ndef binary_search(a, x):\n\tleft = 0\n\tright = len(a)\n\tn_less = 0\n\tn_greater = 0\n\twhile left < right:\n\t\tmiddle = (left + right) // 2\n\t\tif a[middle] <= x:\n\t\t\tleft = middle + 1\n\t\t\tif x != middle:\n\t\t\t\tn_less += 1\n\t\telse:\n\t\t\tright = middle\n\t\t\tn_greater += 1\n\tif left > 0 and a[left - 1] == x:\n\t\treturn (True, n_less, n_greater)\n\telse:\n\t\treturn (False, n_less, n_greater)\n\ndef combination(n, k):\n\tif k > n:\n\t\treturn 0\n\telse:\n\t\treturn math.factorial(n) // (math.factorial(k) * math.factorial(n - k))\nnxpos = input().split(' ')\nn = int(nxpos[0])\nx = int(nxpos[1])\npos = int(nxpos[2])\nn_smaller_numbers = x - 1\nn_bigger_numbers = n - x\na = [i for i in range(n)]\n(_, n_less, n_greater) = binary_search(a, pos)\nc1 = combination(n_smaller_numbers, n_less) * math.factorial(n_less)\nc2 = combination(n_bigger_numbers, n_greater) * math.factorial(n_greater)\nres = c1 * c2 * math.factorial(n - n_less - n_greater - 1)\nprint(res % (1000000000 + 7))\n", "(f, t) = (-1, 0)\nINT = 10 ** 9 + 7\n\ndef mult(a, b):\n\tans = 1\n\tfor i in range(b):\n\t\tans *= a - i\n\t\tans %= INT\n\treturn ans\n\ndef fact(a):\n\tans = 1\n\tfor i in range(a):\n\t\tans *= i + 1\n\t\tans %= INT\n\treturn ans\nL = []\n\ndef BinarySearch(num, pos):\n\tglobal f, t\n\ta = [i for i in range(num)]\n\tleft = 0\n\tright = num\n\twhile left < right:\n\t\tmiddle = (left + right) // 2\n\t\tif a[middle] <= pos:\n\t\t\tleft = middle + 1\n\t\t\tf += 1\n\t\t\tL.append(False)\n\t\telse:\n\t\t\tright = middle\n\t\t\tt += 1\n\t\t\tL.append(True)\n(n, x, pos) = map(int, input().split())\nBinarySearch(n, pos)\nX = x - 1\nY = n - X - 1\nif X < f or Y < t:\n\tprint(0)\n\texit()\nprint(mult(X, f) * mult(Y, t) * fact(X + Y - t - f) % INT)\n", "import math\nfor _ in range(1):\n\t(n, x, pos) = map(int, input().split())\n\tfact = []\n\tmod = 1000000007\n\tfact.append(1)\n\tfor i in range(n + 1):\n\t\tfact.append(fact[i] % mod * (i + 1) % mod % mod)\n\tl = 0\n\tr = n\n\t(small, big) = (x - 1, n - x)\n\tans = 1\n\twhile l < r:\n\t\tmid = (l + r) // 2\n\t\tif mid > pos:\n\t\t\tr = mid\n\t\t\tans *= big\n\t\t\tans %= mod\n\t\t\tbig -= 1\n\t\telif mid <= pos:\n\t\t\tl = mid + 1\n\t\t\tif mid != pos:\n\t\t\t\tans *= small\n\t\t\t\tans %= mod\n\t\t\t\tsmall -= 1\n\tans *= fact[small + big]\n\tans %= mod\n\tprint(ans % mod)\n", "import os\nimport sys\nimport math\nfrom io import BytesIO, IOBase\nfrom fractions import Fraction\nimport collections\nfrom itertools import permutations\nfrom collections import defaultdict\nfrom collections import deque\nimport threading\nBUFSIZE = 8192\n\nclass FastIO(IOBase):\n\tnewlines = 0\n\n\tdef __init__(self, file):\n\t\tself._fd = file.fileno()\n\t\tself.buffer = BytesIO()\n\t\tself.writable = 'x' in file.mode or 'r' not in file.mode\n\t\tself.write = self.buffer.write if self.writable else None\n\n\tdef read(self):\n\t\twhile True:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tif not b:\n\t\t\t\tbreak\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines = 0\n\t\treturn self.buffer.read()\n\n\tdef readline(self):\n\t\twhile self.newlines == 0:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tself.newlines = b.count(b'\\n') + (not b)\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines -= 1\n\t\treturn self.buffer.readline()\n\n\tdef flush(self):\n\t\tif self.writable:\n\t\t\tos.write(self._fd, self.buffer.getvalue())\n\t\t\t(self.buffer.truncate(0), self.buffer.seek(0))\n\nclass IOWrapper(IOBase):\n\n\tdef __init__(self, file):\n\t\tself.buffer = FastIO(file)\n\t\tself.flush = self.buffer.flush\n\t\tself.writable = self.buffer.writable\n\t\tself.write = lambda s: self.buffer.write(s.encode('ascii'))\n\t\tself.read = lambda : self.buffer.read().decode('ascii')\n\t\tself.readline = lambda : self.buffer.readline().decode('ascii')\n(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))\ninput = lambda : sys.stdin.readline().rstrip('\\r\\n')\n\nclass Factorial:\n\n\tdef __init__(self, MOD):\n\t\tself.MOD = MOD\n\t\tself.factorials = [1, 1]\n\t\tself.invModulos = [0, 1]\n\t\tself.invFactorial_ = [1, 1]\n\n\tdef calc(self, n):\n\t\tif n <= -1:\n\t\t\tprint('Invalid argument to calculate n!')\n\t\t\tprint('n must be non-negative value. But the argument was ' + str(n))\n\t\t\texit()\n\t\tif n < len(self.factorials):\n\t\t\treturn self.factorials[n]\n\t\tnextArr = [0] * (n + 1 - len(self.factorials))\n\t\tinitialI = len(self.factorials)\n\t\tprev = self.factorials[-1]\n\t\tm = self.MOD\n\t\tfor i in range(initialI, n + 1):\n\t\t\tprev = nextArr[i - initialI] = prev * i % m\n\t\tself.factorials += nextArr\n\t\treturn self.factorials[n]\n\n\tdef inv(self, n):\n\t\tif n <= -1:\n\t\t\tprint('Invalid argument to calculate n^(-1)')\n\t\t\tprint('n must be non-negative value. But the argument was ' + str(n))\n\t\t\texit()\n\t\tp = self.MOD\n\t\tpi = n % p\n\t\tif pi < len(self.invModulos):\n\t\t\treturn self.invModulos[pi]\n\t\tnextArr = [0] * (n + 1 - len(self.invModulos))\n\t\tinitialI = len(self.invModulos)\n\t\tfor i in range(initialI, min(p, n + 1)):\n\t\t\tnext = -self.invModulos[p % i] * (p // i) % p\n\t\t\tself.invModulos.append(next)\n\t\treturn self.invModulos[pi]\n\n\tdef invFactorial(self, n):\n\t\tif n <= -1:\n\t\t\tprint('Invalid argument to calculate (n^(-1))!')\n\t\t\tprint('n must be non-negative value. But the argument was ' + str(n))\n\t\t\texit()\n\t\tif n < len(self.invFactorial_):\n\t\t\treturn self.invFactorial_[n]\n\t\tself.inv(n)\n\t\tnextArr = [0] * (n + 1 - len(self.invFactorial_))\n\t\tinitialI = len(self.invFactorial_)\n\t\tprev = self.invFactorial_[-1]\n\t\tp = self.MOD\n\t\tfor i in range(initialI, n + 1):\n\t\t\tprev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p\n\t\tself.invFactorial_ += nextArr\n\t\treturn self.invFactorial_[n]\n\nclass Combination:\n\n\tdef __init__(self, MOD):\n\t\tself.MOD = MOD\n\t\tself.factorial = Factorial(MOD)\n\n\tdef ncr(self, n, k):\n\t\tif k < 0 or n < k:\n\t\t\treturn 0\n\t\tk = min(k, n - k)\n\t\tf = self.factorial\n\t\treturn f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD\n(n, x, a) = map(int, input().split())\nans = 1\ncnt = 0\ncnt1 = 0\ni = 0\nj = n\nmod = 1000000007\nwhile i < j:\n\tmid = (i + j) // 2\n\tif mid < a:\n\t\tans *= x - 1 - cnt1\n\t\tans %= mod\n\t\tcnt1 += 1\n\t\ti = mid + 1\n\telif mid > a:\n\t\tans *= n - x - cnt\n\t\tans %= mod\n\t\tcnt += 1\n\t\tj = mid\n\telse:\n\t\ti = mid + 1\ncr = n - cnt - cnt1 - 1\nfor i in range(1, cr + 1):\n\tans *= i\n\tans %= mod\nprint(ans)\n", "(n, x, pos) = map(int, input().split())\n(x1, x2) = (0, n)\nans = []\nf = 2000000 * [0]\np = int(1000000000.0 + 7)\n\ndef call(a, b):\n\tif a == 0 or b == 0 or a == b:\n\t\treturn 1\n\tif b == 1:\n\t\treturn a\n\tif f[a * 1001 + b]:\n\t\treturn f[a * 1001 + b]\n\tf[a * 1001 + b] = (call(a - 1, b) % p + call(a - 1, b - 1) % p) % p\n\treturn f[a * 1001 + b]\nwhile x1 < x2:\n\tm = int((x1 + x2) / 2)\n\tans.append(m)\n\tif m <= pos:\n\t\tx1 = m + 1\n\telse:\n\t\tx2 = m\n(big, small, v) = (0, 0, 1)\nfor i in range(len(ans)):\n\tif ans[i] > pos:\n\t\tbig += 1\n\telif ans[i] < pos:\n\t\tsmall += 1\n\ndef fac(x):\n\tv = 1\n\tfor i in range(2, x + 1):\n\t\tv *= i\n\t\tv %= p\n\treturn v\nif big > n - x or small > x - 1:\n\tprint(0)\n\texit(0)\nl = fac(big) * (fac(small) * fac(n - small - big - 1)) % p % p\nprint(call(n - x, big) * call(x - 1, small) % p * l % p)\n", "(n, x, pos) = map(int, input().split())\n\ndef binarysearch(n, pos, x):\n\tleft = 0\n\tright = n\n\tans = 1\n\tl = 0\n\tr = 0\n\twhile left < right:\n\t\tmiddle = (left + right) // 2\n\t\tif middle < pos:\n\t\t\tr += 1\n\t\t\tleft = middle + 1\n\t\telif middle == pos:\n\t\t\tleft = middle + 1\n\t\telse:\n\t\t\tright = middle\n\t\t\tl += 1\n\tfor i in range(l):\n\t\tans *= n - x - i\n\tfor i in range(r):\n\t\tans *= x - i - 1\n\tfor i in range(1, n - l - r):\n\t\tans *= i\n\treturn ans % (10 ** 9 + 7)\n\tprint(a, x, k, ans, i, j)\n\treturn factorial(a - i - j) * ans % 1000000007\nprint(binarysearch(n, pos, x))\n", "MOD = 10 ** 9 + 7\n\ndef fact(n):\n\tpdt = 1\n\tfor i in range(1, n + 1):\n\t\tpdt *= i\n\t\tpdt %= MOD\n\treturn pdt\n\ndef nPr(n, r):\n\tpdt = 1\n\tfor i in range(r):\n\t\tpdt *= n\n\t\tpdt %= MOD\n\t\tn -= 1\n\treturn pdt\n(n, x, pos) = [int(x) for x in input().split()]\nsmallerCnts = x - 1\nlargerCnts = n - x\nrequiredSmallerCnts = 0\nrequiredLargerCnts = 0\nl = 0\nr = n\nwhile True:\n\tif l - 1 == pos:\n\t\twhile l < r:\n\t\t\tm = (l + r) // 2\n\t\t\tr = m\n\t\t\trequiredLargerCnts += 1\n\t\tbreak\n\tm = (l + r) // 2\n\tif m == pos:\n\t\tl = m + 1\n\telif m < pos:\n\t\trequiredSmallerCnts += 1\n\t\tl = m + 1\n\telse:\n\t\trequiredLargerCnts += 1\n\t\tr = m\nif requiredLargerCnts > largerCnts or requiredSmallerCnts > smallerCnts:\n\tans = 0\nelse:\n\tremainder = n - 1 - requiredLargerCnts - requiredSmallerCnts\n\tans = nPr(smallerCnts, requiredSmallerCnts) * nPr(largerCnts, requiredLargerCnts)\n\tans %= MOD\n\tans *= fact(remainder)\n\tans %= MOD\nprint(ans)\n", "from collections import Counter\n\ndef get_search_sequence(n, pos):\n\n\tdef binary_search(arr, x):\n\t\tleft = 0\n\t\tright = len(arr)\n\t\texpected_conditions = []\n\t\twhile left < right:\n\t\t\tmiddle = (left + right) // 2\n\t\t\tif arr[middle] <= x:\n\t\t\t\tleft = middle + 1\n\t\t\t\tif arr[middle] != x:\n\t\t\t\t\texpected_conditions.append('LTE')\n\t\t\telse:\n\t\t\t\tright = middle\n\t\t\t\texpected_conditions.append('GT')\n\t\tif left > 0 and arr[left - 1] == x:\n\t\t\treturn expected_conditions\n\t\telse:\n\t\t\treturn expected_conditions\n\tarr = [i for i in range(n)]\n\treturn binary_search(arr, pos)\n(n, x, pos) = map(int, input().split())\ncomparisons = Counter(get_search_sequence(n, pos))\nlte_comp = comparisons.get('LTE', 0)\ngt_comp = comparisons.get('GT', 0)\nbigger_than_x = n - x\nsmaller_than_x = x - 1\nfrom math import factorial\nif smaller_than_x < lte_comp or bigger_than_x < gt_comp:\n\tprint(0)\n\texit(0)\nsmaller = factorial(smaller_than_x) // factorial(smaller_than_x - lte_comp) % int(1000000000.0 + 7)\nbigger = factorial(bigger_than_x) // factorial(bigger_than_x - gt_comp) % int(1000000000.0 + 7)\nthe_rest = factorial(bigger_than_x + smaller_than_x - lte_comp - gt_comp) % int(1000000000.0 + 7)\nprint(smaller * bigger * the_rest % int(1000000000.0 + 7))\n", "from operator import le\nimport os, sys\nfrom io import IOBase, BytesIO\npy2 = round(0.5)\nif py2:\n\tfrom future_builtins import ascii, filter, hex, map, oct, zip\n\trange = xrange\nBUFSIZE = 8192\n\nclass FastIO(BytesIO):\n\tnewlines = 0\n\n\tdef __init__(self, file):\n\t\tself._file = file\n\t\tself._fd = file.fileno()\n\t\tself.writable = 'x' in file.mode or 'w' in file.mode\n\t\tself.write = super(FastIO, self).write if self.writable else None\n\n\tdef _fill(self):\n\t\ts = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\tself.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])\n\t\treturn s\n\n\tdef read(self):\n\t\twhile self._fill():\n\t\t\tpass\n\t\treturn super(FastIO, self).read()\n\n\tdef readline(self):\n\t\twhile self.newlines == 0:\n\t\t\ts = self._fill()\n\t\t\tself.newlines = s.count(b'\\n') + (not s)\n\t\tself.newlines -= 1\n\t\treturn super(FastIO, self).readline()\n\n\tdef flush(self):\n\t\tif self.writable:\n\t\t\tos.write(self._fd, self.getvalue())\n\t\t\t(self.truncate(0), self.seek(0))\n\nclass IOWrapper(IOBase):\n\n\tdef __init__(self, file):\n\t\tself.buffer = FastIO(file)\n\t\tself.flush = self.buffer.flush\n\t\tself.writable = self.buffer.writable\n\t\tif py2:\n\t\t\tself.write = self.buffer.write\n\t\t\tself.read = self.buffer.read\n\t\t\tself.readline = self.buffer.readline\n\t\telse:\n\t\t\tself.write = lambda s: self.buffer.write(s.encode('ascii'))\n\t\t\tself.read = lambda : self.buffer.read().decode('ascii')\n\t\t\tself.readline = lambda : self.buffer.readline().decode('ascii')\n(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))\ninput = lambda : sys.stdin.readline().rstrip('\\r\\n')\nimport sys\n\nclass ostream:\n\n\tdef __lshift__(self, a):\n\t\tsys.stdout.write(str(a))\n\t\treturn self\ncout = ostream()\nendl = '\\n'\n\ndef get_input(a=str):\n\treturn a(input())\n\ndef get_int_input():\n\treturn get_input(int)\n\ndef get_input_arr(a):\n\treturn list(map(a, input().split()))\n\ndef get_int_input_arr():\n\treturn get_input_arr(int)\nimport operator as op\nfrom functools import reduce\nimport math\n\ndef ncr(n, r):\n\tr = min(r, n - r)\n\tnumer = reduce(op.mul, range(n, n - r, -1), 1)\n\tdenom = reduce(op.mul, range(1, r + 1), 1)\n\treturn numer // denom\n\ndef egcd(a, b):\n\tif a == 0:\n\t\treturn (b, 0, 1)\n\telse:\n\t\t(g, y, x) = egcd(b % a, a)\n\t\treturn (g, x - b // a * y, y)\n\ndef modinv(a, m):\n\t(g, x, y) = egcd(a, m)\n\tif g != 1:\n\t\traise Exception('modular inverse does not exist')\n\telse:\n\t\treturn x % m\n\ndef factorialMod(n, modulus):\n\tans = 1\n\tif n <= modulus // 2:\n\t\tfor i in range(1, n + 1):\n\t\t\tans = ans * i % modulus\n\telse:\n\t\tfor i in range(n + 1, modulus):\n\t\t\tans = ans * i % modulus\n\t\tans = modinv(ans, modulus)\n\t\tans = -1 * ans + modulus\n\treturn ans % modulus\n\ndef solve():\n\t(n, x_val, pos) = get_int_input_arr()\n\tMOD = 10 ** 9 + 7\n\n\tdef bs(a, x):\n\t\tlower_pos = set()\n\t\thigher_pos = set()\n\t\tleft = 0\n\t\tright = len(a)\n\t\twhile left < right:\n\t\t\tmiddle = (left + right) // 2\n\t\t\tif a[middle] <= x:\n\t\t\t\tlower_pos.add(middle)\n\t\t\t\tleft = middle + 1\n\t\t\telse:\n\t\t\t\thigher_pos.add(middle)\n\t\t\t\tright = middle\n\t\treturn (lower_pos, higher_pos)\n\tarr = [x for x in range(1, n + 1)]\n\t(lower_pos, higher_pos) = bs(arr, arr[pos])\n\tl_len = len(lower_pos)\n\th_len = len(higher_pos)\n\tfac_1 = 1\n\tif x_val - 1 >= l_len - 1:\n\t\tfac_1 = ncr(x_val - 1, l_len - 1) * factorialMod(l_len - 1, MOD)\n\telse:\n\t\tfac_1 = 0\n\tfac_2 = 1\n\tif n - x_val >= h_len:\n\t\tfac_2 = ncr(n - x_val, h_len) * factorialMod(h_len, MOD)\n\telse:\n\t\tfac_2 = 0\n\tfac_3 = 1\n\tif n - l_len - h_len > 0:\n\t\tfac_3 = factorialMod(n - l_len - h_len, MOD)\n\tres = fac_1 * fac_2 % MOD * fac_3 % MOD\n\tcout << res << endl\n\ndef main():\n\tsolve()\nmain()\n", "def inv(x):\n\treturn pow(x, 1000000005, 1000000007)\n\ndef ncr(n, r):\n\tif r > n:\n\t\treturn 0\n\tz = fact[n] * inv(fact[r])\n\tz %= 1000000007\n\tz = z * inv(fact[n - r])\n\tz %= 1000000007\n\treturn z\nfact = [0 for i in range(1005)]\nfact[0] = 1\nfact[1] = 1\nfor i in range(2, 1005):\n\tfact[i] = fact[i - 1] * i\n\tfact[i] %= 1000000007\nl = input().split()\nn = int(l[0])\nx = int(l[1])\npos = int(l[2])\ngreater = 0\nlesser = 0\nleft = 0\nright = n\nwhile left < right:\n\tm = (left + right) // 2\n\tif m <= pos:\n\t\tlesser += 1\n\t\tleft = m + 1\n\telse:\n\t\tgreater += 1\n\t\tright = m\nz = fact[lesser - 1] * fact[greater]\nz %= 1000000007\nz = z * fact[n - greater - lesser]\nz %= 1000000007\nz = z * ncr(n - x, greater)\nz %= 1000000007\nz = z * ncr(x - 1, lesser - 1)\nz %= 1000000007\nprint(z)\n", "import sys\ninput = sys.stdin.readline\n\ndef inp():\n\treturn int(input())\n\ndef inlt():\n\treturn list(map(int, input().split()))\nM = 10 ** 9 + 7\nF = [0 for i in range(1000)]\nF[0] = 1\nfor i in range(1, 1000):\n\tF[i] = i % M * F[i - 1] % M\nC = [[0 for i in range(1000)] for j in range(1000)]\nfor i in range(0, 1000):\n\tC[i][0] = 1\n\tC[i][1] = i\n\tC[i][i] = 1\n\tfor j in range(2, i):\n\t\tC[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % M\n(n, x, pos) = inlt()\n(smaller, bigger) = (x - 1, n - x)\n(cntBig, cntSmall) = (0, 0)\n(left, right) = (0, n)\nwhile left < right:\n\tmiddle = (left + right) // 2\n\tif middle == pos:\n\t\tleft = middle + 1\n\telif middle < pos:\n\t\tcntSmall += 1\n\t\tleft = middle + 1\n\telse:\n\t\tcntBig += 1\n\t\tright = middle\nothers = n - 1 - cntBig - cntSmall\nmultiply = C[smaller][cntSmall] * F[cntSmall] % M * (C[bigger][cntBig] * F[cntBig] % M) % M\nans = multiply * F[others] % M\nprint(ans)\n", "import math\nimport sys\nMOD_BASE = 10 ** 9 + 7\n(n, x, pos) = map(int, input().split())\nleft = 0\nright = n\ncompared_from_left = set()\ncompared_from_right = set()\nwhile left < right:\n\tmiddle = (left + right) // 2\n\tif middle <= pos:\n\t\tif middle < pos:\n\t\t\tcompared_from_left.add(middle)\n\t\tleft = middle + 1\n\telse:\n\t\tcompared_from_right.add(middle)\n\t\tright = middle\nnum_left = len(compared_from_left)\nnum_right = len(compared_from_right)\nnum_greater = n - x\nnum_lesser = x - 1\nif num_left > num_lesser or num_right > num_greater:\n\tprint(0)\n\tsys.exit(0)\npermutations_left = math.factorial(num_lesser) // math.factorial(num_lesser - num_left)\npermutations_right = math.factorial(num_greater) // math.factorial(num_greater - num_right)\npermutations_leftover = math.factorial(n - num_left - num_right - 1)\nprint(permutations_left * permutations_right * permutations_leftover % MOD_BASE)\n", "mod = 1000000007\n\ndef facto(f, q):\n\tfacto = 1\n\tfor i in range(f, q + 1):\n\t\tfacto = facto * i % mod\n\treturn facto\n(n, x, p) = map(int, input().split())\nleft = 0\nright = n\nr = 0\nl = 0\nwhile left < right:\n\tmiddle = (left + right) // 2\n\tif middle == p:\n\t\tleft = middle + 1\n\telif middle > p:\n\t\tright = middle\n\t\tr += 1\n\telse:\n\t\tleft = middle + 1\n\t\tl += 1\nif l <= x - 1 and r <= n - x:\n\tans = facto(1, n - 1 - r - l) * facto(n - x - r + 1, n - x) * facto(x - 1 - l + 1, x - 1)\n\tans = ans % mod\n\tprint(ans)\nelse:\n\tprint('0')\n", "(n, x, pos) = map(int, input().split())\n(l, h) = (0, n)\nr = 1\nz = 0\n(p, q) = (x - 1, n - x)\nwhile l < h:\n\tm = (l + h) // 2\n\tif m == pos:\n\t\tz += 1\n\t\tl = m + 1\n\telif m > pos:\n\t\tz += 1\n\t\tr *= q\n\t\tq -= 1\n\t\th = m\n\telse:\n\t\tz += 1\n\t\tr *= p\n\t\tp -= 1\n\t\tl = m + 1\nfor i in range(2, n - z + 1):\n\tr = r * i % 1000000007\nprint(r)\n", "from math import factorial\n(a, b, c) = map(int, input().split())\nans = 1\nleft = 0\nright = a\ngr = sm = 0\nwhile left < right:\n\tmid = (left + right) // 2\n\tif mid == c:\n\t\tleft = mid + 1\n\telif mid < c:\n\t\tsm += 1\n\t\tleft = mid + 1\n\telse:\n\t\tgr += 1\n\t\tright = mid\nans = 1\nt = a - b\nfor i in range(gr):\n\tans *= t - i\n\tans %= 10 ** 9 + 7\nfor j in range(1, sm + 1):\n\tans *= b - j\n\tans %= 10 ** 9 + 7\nq = a - (sm + gr + 1)\nfor i in range(1, q + 1):\n\tans *= i\n\tans %= 10 ** 9 + 7\nprint(ans)\n", "import math\nimport random\nimport heapq, bisect\nimport sys\nfrom collections import deque, defaultdict\nfrom fractions import Fraction\nimport sys\nimport threading\nfrom collections import defaultdict\nmod = 10 ** 9 + 7\nmod1 = 998244353\nimport os\nimport sys\nfrom io import BytesIO, IOBase\nBUFSIZE = 8192\n\nclass FastIO(IOBase):\n\tnewlines = 0\n\n\tdef __init__(self, file):\n\t\tself._fd = file.fileno()\n\t\tself.buffer = BytesIO()\n\t\tself.writable = 'x' in file.mode or 'r' not in file.mode\n\t\tself.write = self.buffer.write if self.writable else None\n\n\tdef read(self):\n\t\twhile True:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tif not b:\n\t\t\t\tbreak\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines = 0\n\t\treturn self.buffer.read()\n\n\tdef readline(self):\n\t\twhile self.newlines == 0:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tself.newlines = b.count(b'\\n') + (not b)\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines -= 1\n\t\treturn self.buffer.readline()\n\n\tdef flush(self):\n\t\tif self.writable:\n\t\t\tos.write(self._fd, self.buffer.getvalue())\n\t\t\t(self.buffer.truncate(0), self.buffer.seek(0))\n\nclass IOWrapper(IOBase):\n\n\tdef __init__(self, file):\n\t\tself.buffer = FastIO(file)\n\t\tself.flush = self.buffer.flush\n\t\tself.writable = self.buffer.writable\n\t\tself.write = lambda s: self.buffer.write(s.encode('ascii'))\n\t\tself.read = lambda : self.buffer.read().decode('ascii')\n\t\tself.readline = lambda : self.buffer.readline().decode('ascii')\n(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))\ninput = lambda : sys.stdin.readline().rstrip('\\r\\n')\n\nclass TreeNode:\n\n\tdef __init__(self, k, v):\n\t\tself.key = k\n\t\tself.value = v\n\t\tself.left = None\n\t\tself.right = None\n\t\tself.parent = None\n\t\tself.height = 1\n\t\tself.num_left = 1\n\t\tself.num_total = 1\n\nclass AvlTree:\n\n\tdef __init__(self):\n\t\tself._tree = None\n\n\tdef add(self, k, v):\n\t\tif not self._tree:\n\t\t\tself._tree = TreeNode(k, v)\n\t\t\treturn\n\t\tnode = self._add(k, v)\n\t\tif node:\n\t\t\tself._rebalance(node)\n\n\tdef _add(self, k, v):\n\t\tnode = self._tree\n\t\twhile node:\n\t\t\tif k < node.key:\n\t\t\t\tif node.left:\n\t\t\t\t\tnode = node.left\n\t\t\t\telse:\n\t\t\t\t\tnode.left = TreeNode(k, v)\n\t\t\t\t\tnode.left.parent = node\n\t\t\t\t\treturn node.left\n\t\t\telif node.key < k:\n\t\t\t\tif node.right:\n\t\t\t\t\tnode = node.right\n\t\t\t\telse:\n\t\t\t\t\tnode.right = TreeNode(k, v)\n\t\t\t\t\tnode.right.parent = node\n\t\t\t\t\treturn node.right\n\t\t\telse:\n\t\t\t\tnode.value = v\n\t\t\t\treturn\n\n\t@staticmethod\n\tdef get_height(x):\n\t\treturn x.height if x else 0\n\n\t@staticmethod\n\tdef get_num_total(x):\n\t\treturn x.num_total if x else 0\n\n\tdef _rebalance(self, node):\n\t\tn = node\n\t\twhile n:\n\t\t\tlh = self.get_height(n.left)\n\t\t\trh = self.get_height(n.right)\n\t\t\tn.height = max(lh, rh) + 1\n\t\t\tbalance_factor = lh - rh\n\t\t\tn.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)\n\t\t\tn.num_left = 1 + self.get_num_total(n.left)\n\t\t\tif balance_factor > 1:\n\t\t\t\tif self.get_height(n.left.left) < self.get_height(n.left.right):\n\t\t\t\t\tself._rotate_left(n.left)\n\t\t\t\tself._rotate_right(n)\n\t\t\telif balance_factor < -1:\n\t\t\t\tif self.get_height(n.right.right) < self.get_height(n.right.left):\n\t\t\t\t\tself._rotate_right(n.right)\n\t\t\t\tself._rotate_left(n)\n\t\t\telse:\n\t\t\t\tn = n.parent\n\n\tdef _remove_one(self, node):\n\t\treplacement = node.left or node.right\n\t\tif node.parent:\n\t\t\tif AvlTree._is_left(node):\n\t\t\t\tnode.parent.left = replacement\n\t\t\telse:\n\t\t\t\tnode.parent.right = replacement\n\t\t\treplacement.parent = node.parent\n\t\t\tnode.parent = None\n\t\telse:\n\t\t\tself._tree = replacement\n\t\t\treplacement.parent = None\n\t\tnode.left = None\n\t\tnode.right = None\n\t\tnode.parent = None\n\t\tself._rebalance(replacement)\n\n\tdef _remove_leaf(self, node):\n\t\tif node.parent:\n\t\t\tif AvlTree._is_left(node):\n\t\t\t\tnode.parent.left = None\n\t\t\telse:\n\t\t\t\tnode.parent.right = None\n\t\t\tself._rebalance(node.parent)\n\t\telse:\n\t\t\tself._tree = None\n\t\tnode.parent = None\n\t\tnode.left = None\n\t\tnode.right = None\n\n\tdef remove(self, k):\n\t\tnode = self._get_node(k)\n\t\tif not node:\n\t\t\treturn\n\t\tif AvlTree._is_leaf(node):\n\t\t\tself._remove_leaf(node)\n\t\t\treturn\n\t\tif node.left and node.right:\n\t\t\tnxt = AvlTree._get_next(node)\n\t\t\tnode.key = nxt.key\n\t\t\tnode.value = nxt.value\n\t\t\tif self._is_leaf(nxt):\n\t\t\t\tself._remove_leaf(nxt)\n\t\t\telse:\n\t\t\t\tself._remove_one(nxt)\n\t\t\tself._rebalance(node)\n\t\telse:\n\t\t\tself._remove_one(node)\n\n\tdef get(self, k):\n\t\tnode = self._get_node(k)\n\t\treturn node.value if node else -1\n\n\tdef _get_node(self, k):\n\t\tif not self._tree:\n\t\t\treturn None\n\t\tnode = self._tree\n\t\twhile node:\n\t\t\tif k < node.key:\n\t\t\t\tnode = node.left\n\t\t\telif node.key < k:\n\t\t\t\tnode = node.right\n\t\t\telse:\n\t\t\t\treturn node\n\t\treturn None\n\n\tdef get_at(self, pos):\n\t\tx = pos + 1\n\t\tnode = self._tree\n\t\twhile node:\n\t\t\tif x < node.num_left:\n\t\t\t\tnode = node.left\n\t\t\telif node.num_left < x:\n\t\t\t\tx -= node.num_left\n\t\t\t\tnode = node.right\n\t\t\telse:\n\t\t\t\treturn (node.key, node.value)\n\t\traise IndexError('Out of ranges')\n\n\t@staticmethod\n\tdef _is_left(node):\n\t\treturn node.parent.left and node.parent.left == node\n\n\t@staticmethod\n\tdef _is_leaf(node):\n\t\treturn node.left is None and node.right is None\n\n\tdef _rotate_right(self, node):\n\t\tif not node.parent:\n\t\t\tself._tree = node.left\n\t\t\tnode.left.parent = None\n\t\telif AvlTree._is_left(node):\n\t\t\tnode.parent.left = node.left\n\t\t\tnode.left.parent = node.parent\n\t\telse:\n\t\t\tnode.parent.right = node.left\n\t\t\tnode.left.parent = node.parent\n\t\tbk = node.left.right\n\t\tnode.left.right = node\n\t\tnode.parent = node.left\n\t\tnode.left = bk\n\t\tif bk:\n\t\t\tbk.parent = node\n\t\tnode.height = max(self.get_height(node.left), self.get_height(node.right)) + 1\n\t\tnode.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)\n\t\tnode.num_left = 1 + self.get_num_total(node.left)\n\n\tdef _rotate_left(self, node):\n\t\tif not node.parent:\n\t\t\tself._tree = node.right\n\t\t\tnode.right.parent = None\n\t\telif AvlTree._is_left(node):\n\t\t\tnode.parent.left = node.right\n\t\t\tnode.right.parent = node.parent\n\t\telse:\n\t\t\tnode.parent.right = node.right\n\t\t\tnode.right.parent = node.parent\n\t\tbk = node.right.left\n\t\tnode.right.left = node\n\t\tnode.parent = node.right\n\t\tnode.right = bk\n\t\tif bk:\n\t\t\tbk.parent = node\n\t\tnode.height = max(self.get_height(node.left), self.get_height(node.right)) + 1\n\t\tnode.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)\n\t\tnode.num_left = 1 + self.get_num_total(node.left)\n\n\t@staticmethod\n\tdef _get_next(node):\n\t\tif not node.right:\n\t\t\treturn node.parent\n\t\tn = node.right\n\t\twhile n.left:\n\t\t\tn = n.left\n\t\treturn n\n\nclass SegmentTree1:\n\n\tdef __init__(self, data, default=300006, func=lambda a, b: min(a, b)):\n\t\tself._default = default\n\t\tself._func = func\n\t\tself._len = len(data)\n\t\tself._size = _size = 1 << (self._len - 1).bit_length()\n\t\tself.data = [default] * (2 * _size)\n\t\tself.data[_size:_size + self._len] = data\n\t\tfor i in reversed(range(_size)):\n\t\t\tself.data[i] = func(self.data[i + i], self.data[i + i + 1])\n\n\tdef __delitem__(self, idx):\n\t\tself[idx] = self._default\n\n\tdef __getitem__(self, idx):\n\t\treturn self.data[idx + self._size]\n\n\tdef __setitem__(self, idx, value):\n\t\tidx += self._size\n\t\tself.data[idx] = value\n\t\tidx >>= 1\n\t\twhile idx:\n\t\t\tself.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])\n\t\t\tidx >>= 1\n\n\tdef __len__(self):\n\t\treturn self._len\n\n\tdef query(self, start, stop):\n\t\tif start == stop:\n\t\t\treturn self.__getitem__(start)\n\t\tstop += 1\n\t\tstart += self._size\n\t\tstop += self._size\n\t\tres = self._default\n\t\twhile start < stop:\n\t\t\tif start & 1:\n\t\t\t\tres = self._func(res, self.data[start])\n\t\t\t\tstart += 1\n\t\t\tif stop & 1:\n\t\t\t\tstop -= 1\n\t\t\t\tres = self._func(res, self.data[stop])\n\t\t\tstart >>= 1\n\t\t\tstop >>= 1\n\t\treturn res\n\n\tdef __repr__(self):\n\t\treturn 'SegmentTree({0})'.format(self.data)\n\nclass SegmentTree:\n\n\tdef __init__(self, data, default=0, func=lambda a, b: max(a, b)):\n\t\tself._default = default\n\t\tself._func = func\n\t\tself._len = len(data)\n\t\tself._size = _size = 1 << (self._len - 1).bit_length()\n\t\tself.data = [default] * (2 * _size)\n\t\tself.data[_size:_size + self._len] = data\n\t\tfor i in reversed(range(_size)):\n\t\t\tself.data[i] = func(self.data[i + i], self.data[i + i + 1])\n\n\tdef __delitem__(self, idx):\n\t\tself[idx] = self._default\n\n\tdef __getitem__(self, idx):\n\t\treturn self.data[idx + self._size]\n\n\tdef __setitem__(self, idx, value):\n\t\tidx += self._size\n\t\tself.data[idx] = value\n\t\tidx >>= 1\n\t\twhile idx:\n\t\t\tself.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])\n\t\t\tidx >>= 1\n\n\tdef __len__(self):\n\t\treturn self._len\n\n\tdef query(self, start, stop):\n\t\tif start == stop:\n\t\t\treturn self.__getitem__(start)\n\t\tstop += 1\n\t\tstart += self._size\n\t\tstop += self._size\n\t\tres = self._default\n\t\twhile start < stop:\n\t\t\tif start & 1:\n\t\t\t\tres = self._func(res, self.data[start])\n\t\t\t\tstart += 1\n\t\t\tif stop & 1:\n\t\t\t\tstop -= 1\n\t\t\t\tres = self._func(res, self.data[stop])\n\t\t\tstart >>= 1\n\t\t\tstop >>= 1\n\t\treturn res\n\n\tdef __repr__(self):\n\t\treturn 'SegmentTree({0})'.format(self.data)\n\nclass Factorial:\n\n\tdef __init__(self, MOD):\n\t\tself.MOD = MOD\n\t\tself.factorials = [1, 1]\n\t\tself.invModulos = [0, 1]\n\t\tself.invFactorial_ = [1, 1]\n\n\tdef calc(self, n):\n\t\tif n <= -1:\n\t\t\tprint('Invalid argument to calculate n!')\n\t\t\tprint('n must be non-negative value. But the argument was ' + str(n))\n\t\t\texit()\n\t\tif n < len(self.factorials):\n\t\t\treturn self.factorials[n]\n\t\tnextArr = [0] * (n + 1 - len(self.factorials))\n\t\tinitialI = len(self.factorials)\n\t\tprev = self.factorials[-1]\n\t\tm = self.MOD\n\t\tfor i in range(initialI, n + 1):\n\t\t\tprev = nextArr[i - initialI] = prev * i % m\n\t\tself.factorials += nextArr\n\t\treturn self.factorials[n]\n\n\tdef inv(self, n):\n\t\tif n <= -1:\n\t\t\tprint('Invalid argument to calculate n^(-1)')\n\t\t\tprint('n must be non-negative value. But the argument was ' + str(n))\n\t\t\texit()\n\t\tp = self.MOD\n\t\tpi = n % p\n\t\tif pi < len(self.invModulos):\n\t\t\treturn self.invModulos[pi]\n\t\tnextArr = [0] * (n + 1 - len(self.invModulos))\n\t\tinitialI = len(self.invModulos)\n\t\tfor i in range(initialI, min(p, n + 1)):\n\t\t\tnext = -self.invModulos[p % i] * (p // i) % p\n\t\t\tself.invModulos.append(next)\n\t\treturn self.invModulos[pi]\n\n\tdef invFactorial(self, n):\n\t\tif n <= -1:\n\t\t\tprint('Invalid argument to calculate (n^(-1))!')\n\t\t\tprint('n must be non-negative value. But the argument was ' + str(n))\n\t\t\texit()\n\t\tif n < len(self.invFactorial_):\n\t\t\treturn self.invFactorial_[n]\n\t\tself.inv(n)\n\t\tnextArr = [0] * (n + 1 - len(self.invFactorial_))\n\t\tinitialI = len(self.invFactorial_)\n\t\tprev = self.invFactorial_[-1]\n\t\tp = self.MOD\n\t\tfor i in range(initialI, n + 1):\n\t\t\tprev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p\n\t\tself.invFactorial_ += nextArr\n\t\treturn self.invFactorial_[n]\n\nclass Combination:\n\n\tdef __init__(self, MOD):\n\t\tself.MOD = MOD\n\t\tself.factorial = Factorial(MOD)\n\n\tdef ncr(self, n, k):\n\t\tif k < 0 or n < k:\n\t\t\treturn 0\n\t\tk = min(k, n - k)\n\t\tf = self.factorial\n\t\treturn f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD\n\ndef powm(a, n, m):\n\tif a == 1 or n == 0:\n\t\treturn 1\n\tif n % 2 == 0:\n\t\ts = powm(a, n // 2, m)\n\t\treturn s * s % m\n\telse:\n\t\treturn a * powm(a, n - 1, m) % m\n\ndef sort_list(list1, list2):\n\tzipped_pairs = zip(list2, list1)\n\tz = [x for (_, x) in sorted(zipped_pairs)]\n\treturn z\n\ndef product(l):\n\tpor = 1\n\tfor i in range(len(l)):\n\t\tpor *= l[i]\n\treturn por\n\ndef binarySearchCount(arr, n, key):\n\tleft = 0\n\tright = n - 1\n\tcount = 0\n\twhile left <= right:\n\t\tmid = int((right + left) / 2)\n\t\tif arr[mid] <= key:\n\t\t\tcount = mid + 1\n\t\t\tleft = mid + 1\n\t\telse:\n\t\t\tright = mid - 1\n\treturn count\n\ndef countdig(n):\n\tc = 0\n\twhile n > 0:\n\t\tn //= 10\n\t\tc += 1\n\treturn c\n\ndef binary(x, length):\n\ty = bin(x)[2:]\n\treturn y if len(y) >= length else '0' * (length - len(y)) + y\n\ndef countGreater(arr, n, k):\n\tl = 0\n\tr = n - 1\n\tleftGreater = n\n\twhile l <= r:\n\t\tm = int(l + (r - l) / 2)\n\t\tif arr[m] >= k:\n\t\t\tleftGreater = m\n\t\t\tr = m - 1\n\t\telse:\n\t\t\tl = m + 1\n\treturn n - leftGreater\n\nclass TrieNode:\n\n\tdef __init__(self):\n\t\tself.children = [None] * 26\n\t\tself.isEndOfWord = False\n\nclass Trie:\n\n\tdef __init__(self):\n\t\tself.root = self.getNode()\n\n\tdef getNode(self):\n\t\treturn TrieNode()\n\n\tdef _charToIndex(self, ch):\n\t\treturn ord(ch) - ord('a')\n\n\tdef insert(self, key):\n\t\tpCrawl = self.root\n\t\tlength = len(key)\n\t\tfor level in range(length):\n\t\t\tindex = self._charToIndex(key[level])\n\t\t\tif not pCrawl.children[index]:\n\t\t\t\tpCrawl.children[index] = self.getNode()\n\t\t\tpCrawl = pCrawl.children[index]\n\t\tpCrawl.isEndOfWord = True\n\n\tdef search(self, key):\n\t\tpCrawl = self.root\n\t\tlength = len(key)\n\t\tfor level in range(length):\n\t\t\tindex = self._charToIndex(key[level])\n\t\t\tif not pCrawl.children[index]:\n\t\t\t\treturn False\n\t\t\tpCrawl = pCrawl.children[index]\n\t\treturn pCrawl != None and pCrawl.isEndOfWord\n\nclass Node:\n\n\tdef __init__(self, data):\n\t\tself.data = data\n\t\tself.count = 0\n\t\tself.left = None\n\t\tself.right = None\n\nclass BinaryTrie:\n\n\tdef __init__(self):\n\t\tself.root = Node(0)\n\n\tdef insert(self, pre_xor):\n\t\tself.temp = self.root\n\t\tfor i in range(31, -1, -1):\n\t\t\tval = pre_xor & 1 << i\n\t\t\tif val:\n\t\t\t\tif not self.temp.right:\n\t\t\t\t\tself.temp.right = Node(0)\n\t\t\t\tself.temp = self.temp.right\n\t\t\t\tself.temp.count += 1\n\t\t\tif not val:\n\t\t\t\tif not self.temp.left:\n\t\t\t\t\tself.temp.left = Node(0)\n\t\t\t\tself.temp = self.temp.left\n\t\t\t\tself.temp.count += 1\n\t\tself.temp.data = pre_xor\n\n\tdef query(self, xor):\n\t\tself.temp = self.root\n\t\tfor i in range(31, -1, -1):\n\t\t\tval = xor & 1 << i\n\t\t\tif not val:\n\t\t\t\tif self.temp.left and self.temp.left.count > 0:\n\t\t\t\t\tself.temp = self.temp.left\n\t\t\t\telif self.temp.right:\n\t\t\t\t\tself.temp = self.temp.right\n\t\t\telif self.temp.right and self.temp.right.count > 0:\n\t\t\t\tself.temp = self.temp.right\n\t\t\telif self.temp.left:\n\t\t\t\tself.temp = self.temp.left\n\t\t\tself.temp.count -= 1\n\t\treturn xor ^ self.temp.data\n\ndef npr(n, r):\n\tif r > n:\n\t\treturn 0\n\tfact = 1\n\tfact1 = 1\n\tfor i in range(n):\n\t\tfact *= i + 1\n\t\tfact %= mod\n\tfor i in range(n - r):\n\t\tfact1 *= i + 1\n\t\tfact1 %= mod\n\tfact *= pow(fact1, mod - 2, mod)\n\treturn fact % mod\n(n, x, pos) = map(int, input().split())\nleft = 0\nright = n\na = [-2000 + i for i in range(pos)]\na.append(x)\nb = [x + i + 1 for i in range(n - pos - 1)]\na += b\ne = []\ns = Combination(mod)\nwhile left < right:\n\tmiddle = (left + right) // 2\n\te.append(middle)\n\tif a[middle] <= x:\n\t\tleft = middle + 1\n\telse:\n\t\tright = middle\ne.sort()\nle = []\nle1 = []\nfor i in range(len(e)):\n\tif e[i] < pos:\n\t\tle.append(e[i])\n\tif e[i] > pos:\n\t\tle1.append(e[i])\nans = npr(x - 1, len(le))\nans1 = npr(n - x, len(le1))\nans2 = npr(n - len(le) - len(le1) - 1, n - len(le) - len(le1) - 1)\nprint(ans * ans1 * ans2 % mod)\n", "(n, x, pos) = map(int, input().split())\na = [0] * n\n(low, high) = (x - 1, n - x)\n(l, r) = (0, n)\nfound = False\nans = 0\nwhile l < r:\n\tm = (l + r) // 2\n\tif pos < m:\n\t\tif high == 0:\n\t\t\tans = -1\n\t\t\tbreak\n\t\ta[m] = high\n\t\thigh -= 1\n\t\tr = m\n\telse:\n\t\tif m != pos:\n\t\t\tif low == 0:\n\t\t\t\tans = -1\n\t\t\t\tbreak\n\t\t\ta[m] = low\n\t\t\tlow -= 1\n\t\tl = m + 1\nmod = 10 ** 9 + 7\nif ans == -1:\n\tprint(0)\nelse:\n\tfans = 1\n\tfor i in range(n):\n\t\tif a[i]:\n\t\t\tfans = fans * a[i] % mod\n\tleft = low + high\n\twhile left:\n\t\tfans = fans * left % mod\n\t\tleft -= 1\n\tprint(fans)\n", "import typing\nimport sys\nimport math\nimport collections\nimport bisect\nimport itertools\nimport heapq\nimport decimal\nINF = 10 ** 20\nMOD = 10 ** 9 + 7\n\ndef ni():\n\treturn int(sys.stdin.buffer.readline())\n\ndef ns():\n\treturn map(int, sys.stdin.buffer.readline().split())\n\ndef na():\n\treturn list(map(int, sys.stdin.buffer.readline().split()))\n\nclass ModCombination:\n\n\tdef __init__(self, maxN, MOD):\n\t\tself._maxN = maxN\n\t\tself._MOD = MOD\n\t\tself.facts = [1]\n\t\tself.invs = [1] * (self._maxN + 1)\n\t\tfact = 1\n\t\tfor i in range(1, self._maxN + 1):\n\t\t\tfact *= i\n\t\t\tfact %= self._MOD\n\t\t\tself.facts.append(fact)\n\t\tinv = pow(fact, self._MOD - 2, self._MOD)\n\t\tself.invs[self._maxN] = inv\n\t\tfor i in range(self._maxN, 1, -1):\n\t\t\tinv *= i\n\t\t\tinv %= self._MOD\n\t\t\tself.invs[i - 1] = inv\n\n\tdef nCr(self, n, r):\n\t\treturn self.facts[n] * self.invs[r] * self.invs[n - r] % self._MOD\n\ndef main():\n\t(n, x, pos) = ns()\n\tmc = ModCombination(n, MOD)\n\tlcnt = 0\n\trcnt = 0\n\tl = 0\n\tr = n\n\twhile l < r:\n\t\tmiddle = int((l + r) / 2)\n\t\tif middle <= pos:\n\t\t\tl = middle + 1\n\t\t\tif middle != pos:\n\t\t\t\tlcnt += 1\n\t\telse:\n\t\t\tr = middle\n\t\t\trcnt += 1\n\tif lcnt > x - 1 or rcnt > n - x:\n\t\tprint(0)\n\t\texit(0)\n\tans = 1\n\tif lcnt > 0:\n\t\tans *= mc.nCr(x - 1, lcnt) * math.factorial(lcnt)\n\t\tans %= MOD\n\tif rcnt > 0:\n\t\tans *= mc.nCr(n - x, rcnt) * math.factorial(rcnt)\n\t\tans %= MOD\n\tans *= math.factorial(n - 1 - lcnt - rcnt)\n\tans %= MOD\n\tprint(ans)\nmain()\n", "import sys\n\ndef mul(val, times, M):\n\tans = 1\n\tfor i in range(0, times):\n\t\tans *= val\n\t\tans %= M\n\t\tval -= 1\n\treturn ans\n\ndef input():\n\treturn sys.stdin.readline().rstrip()\n[n, x, pos] = list(map(int, input().split()))\ngt = 0\nlt = 0\nM = 10 ** 9 + 7\nl = 0\nr = n\nwhile l < r:\n\tmid = int((l + r) // 2)\n\tif pos >= mid:\n\t\tif pos != mid:\n\t\t\tlt += 1\n\t\tl = mid + 1\n\telse:\n\t\tgt += 1\n\t\tr = mid\nans = 1\nans = ans * mul(n - x, gt, M)\nans %= M\nans = ans * mul(x - 1, lt, M)\nans %= M\nans = ans * mul(n - gt - lt - 1, n - gt - lt - 1, M)\nans %= M\nprint(ans)\n", "import os\nimport sys\nfrom io import BytesIO, IOBase\nBUFSIZE = 8192\n\nclass FastIO(IOBase):\n\tnewlines = 0\n\n\tdef __init__(self, file):\n\t\tself._fd = file.fileno()\n\t\tself.buffer = BytesIO()\n\t\tself.writable = 'x' in file.mode or 'r' not in file.mode\n\t\tself.write = self.buffer.write if self.writable else None\n\n\tdef read(self):\n\t\twhile True:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tif not b:\n\t\t\t\tbreak\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines = 0\n\t\treturn self.buffer.read()\n\n\tdef readline(self):\n\t\twhile self.newlines == 0:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tself.newlines = b.count(b'\\n') + (not b)\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines -= 1\n\t\treturn self.buffer.readline()\n\n\tdef flush(self):\n\t\tif self.writable:\n\t\t\tos.write(self._fd, self.buffer.getvalue())\n\t\t\t(self.buffer.truncate(0), self.buffer.seek(0))\n\nclass IOWrapper(IOBase):\n\n\tdef __init__(self, file):\n\t\tself.buffer = FastIO(file)\n\t\tself.flush = self.buffer.flush\n\t\tself.writable = self.buffer.writable\n\t\tself.write = lambda s: self.buffer.write(s.encode('ascii'))\n\t\tself.read = lambda : self.buffer.read().decode('ascii')\n\t\tself.readline = lambda : self.buffer.readline().decode('ascii')\n(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))\ninput = lambda : sys.stdin.readline().rstrip('\\r\\n')\n(n, x, pos) = map(int, input().split())\nans = []\nmod = 10 ** 9 + 7\nleft = 0\nright = n\nwhile left < right:\n\tmid = (left + right) // 2\n\tif mid == pos:\n\t\tleft = mid + 1\n\telif mid < pos:\n\t\tans.append('r')\n\t\tleft = mid + 1\n\telse:\n\t\tans.append('l')\n\t\tright = mid\nfact = [1]\nfor s in range(1, n + 1):\n\tfact.append(fact[-1] * s % mod)\nif len(ans) == 0:\n\tprint(fact[n - 1])\nelse:\n\touty = 1\n\tless = x - 1\n\tmore = n - x\n\tfor s in range(len(ans)):\n\t\tif ans[s] == 'r':\n\t\t\touty *= less\n\t\t\tless -= 1\n\t\telse:\n\t\t\touty *= more\n\t\t\tmore -= 1\n\t\touty = outy % mod\n\touty *= fact[less + more]\n\touty = outy % mod\n\tprint(outy)\n", "(n, x, pos) = list(map(int, input().split()))\nmiddle = n // 2\nleft = 0\nright = n\nlarger = []\nsmaller = []\n\ndef fact(p, y=1):\n\tif p <= 1:\n\t\treturn y\n\telse:\n\t\treturn fact(p - 1, y * p)\nwhile left < right:\n\tmiddle = (left + right) // 2\n\tif middle <= pos:\n\t\tif middle < pos:\n\t\t\tsmaller.append(middle)\n\t\tleft = middle + 1\n\telse:\n\t\tlarger.append(middle)\n\t\tright = middle\nl = len(larger)\ns = len(smaller)\nif n - x - l < 0 or x - 1 - s < 0:\n\tprint(0)\nelse:\n\tres = 1\n\tlg = n - x\n\tfor _ in range(l):\n\t\tres *= lg\n\t\tres %= 10 ** 9 + 7\n\t\tlg -= 1\n\tsm = x - 1\n\tfor _ in range(s):\n\t\tres *= sm\n\t\tres %= 10 ** 9 + 7\n\t\tsm -= 1\n\tres *= fact(n - l - s - 1)\n\tres %= 10 ** 9 + 7\n\tprint(int(res))\n", "import math as m\n(n, x, pos) = map(int, input().split())\nans = 1\nsmall = x - 1\nl = 0\nr = n\nmod = pow(10, 9) + 7\ngreat = n - x\nspace = n - 1\nwhile l < r:\n\tmid = (l + r) // 2\n\tif mid == pos:\n\t\tl = mid + 1\n\telif mid > pos:\n\t\tans *= great\n\t\tgreat -= 1\n\t\tspace -= 1\n\t\tr = mid\n\telse:\n\t\tans *= small\n\t\tsmall -= 1\n\t\tspace -= 1\n\t\tl = mid + 1\nif l > 0 and l - 1 == pos:\n\tans = ans % mod * m.factorial(space) % mod % mod\nelse:\n\tans = 0\nprint(ans)\n", "mod = int(1000000000.0 + 7)\n(n, x, pos) = map(int, input().split())\n\ndef bs(pos):\n\tl = 0\n\tr = n\n\tsmall = set()\n\tlarge = set()\n\teq = 0\n\twhile l < r:\n\t\tmid = l + r >> 1\n\t\tif mid <= pos:\n\t\t\tif mid != pos:\n\t\t\t\tsmall.add(mid)\n\t\t\telse:\n\t\t\t\teq += 1\n\t\t\tl = mid + 1\n\t\telse:\n\t\t\tr = mid\n\t\t\tif mid < n:\n\t\t\t\tlarge.add(mid)\n\tif l != pos and l < n:\n\t\tlarge.add(l)\n\treturn (eq, len(small), len(large))\n(eq, small, large) = bs(pos)\nlr = n - x\nsm = n - lr - 1\nfact = [1] * (n + 1)\nfor i in range(2, n + 1):\n\tfact[i] = fact[i - 1] * i % mod\n\ndef inv(x):\n\treturn pow(x, mod - 2, mod)\n\ndef ncr(n, r):\n\tif n < r:\n\t\treturn 0\n\tif n <= r or r == 0 or r == n:\n\t\treturn 1\n\treturn fact[n] % mod * inv(fact[r]) % mod * inv(fact[n - r]) % mod\nprint(fact[n - large - small - 1] % mod * ncr(n - lr - 1, small) % mod * fact[small] % mod * ncr(lr, large) % mod * fact[large] % mod)\n", "(n, x, pos) = map(int, input().split())\n(fact, inv, invf) = ([0] * (n + 5), [0] * (n + 5), [0] * (n + 5))\nMOD = 10 ** 9 + 7\n\ndef mod(x):\n\treturn (x % MOD + x) % MOD\n\ndef init(n):\n\tfact[0] = fact[1] = 1\n\tinv[0] = inv[1] = 1\n\tinvf[0] = invf[1] = 1\n\tfor i in range(2, n + 1):\n\t\tfact[i] = fact[i - 1] * i\n\t\tinv[i] = inv[MOD % i] * (MOD - MOD // i) % MOD\n\t\tinvf[i] = inv[i] * invf[i - 1] % MOD\n\ndef P(n, r):\n\treturn fact[n] * invf[n - r] % MOD\n\ndef bin_search(n, x, pos):\n\tless = 0\n\tmore = 0\n\tleft = 0\n\tright = n\n\twhile right > left:\n\t\tmiddle = (left + right) // 2\n\t\tif middle <= pos:\n\t\t\tif middle < pos:\n\t\t\t\tless += 1\n\t\t\tleft = middle + 1\n\t\telse:\n\t\t\tif middle > pos:\n\t\t\t\tmore += 1\n\t\t\tright = middle\n\treturn P(x - 1, less) * P(n - x, more) * fact[n - less - more - 1] % MOD\ninit(n)\nprint(bin_search(n, x, pos))\n", "def binarysearch(pos, smaller, bigger):\n\tans = 1\n\tleft = 0\n\tright = smaller + bigger + 1\n\twhile left < right:\n\t\tmid = (left + right) // 2\n\t\tif pos < mid:\n\t\t\tright = mid\n\t\t\tif mid != pos:\n\t\t\t\tans *= bigger\n\t\t\t\tbigger -= 1\n\t\telse:\n\t\t\tleft = mid + 1\n\t\t\tif left - 1 != pos:\n\t\t\t\tans *= smaller\n\t\t\t\tsmaller -= 1\n\treturn (ans, bigger, smaller)\n(n, x, pos) = [int(x) for x in input().split()]\n(ans, bigger, smaller) = binarysearch(pos, x - 1, n - x)\nn = bigger + smaller\nfor i in range(1, n + 1):\n\tans *= i\n\tans %= 10 ** 9 + 7\nprint(ans)\n", "from sys import stdin, exit\n\ndef BS(A, x):\n\tleft = 0\n\tright = len(A)\n\tmids = []\n\tsmal = []\n\twhile left < right:\n\t\tmiddle = (left + right) // 2\n\t\tmids.append(middle)\n\t\tif A[middle] <= x:\n\t\t\tleft = middle + 1\n\t\t\tsmal.append(1)\n\t\telse:\n\t\t\tright = middle\n\t\t\tsmal.append(0)\n\treturn (mids, smal)\nMOD = 1000000000.0\nMOD += 7\nMOD = int(MOD)\n(n, x, pos1) = map(int, stdin.readline().split())\nA = [i for i in range(n)]\n(idxs, smal) = BS(A, pos1)\npos = 1\nless = x - 1\ngreat = n - x\nfor (j, ix) in enumerate(idxs):\n\tif less < 0 or great < 0:\n\t\tbreak\n\tif ix != pos1:\n\t\tif smal[j]:\n\t\t\tpos = pos * less % MOD\n\t\t\tless -= 1\n\t\telse:\n\t\t\tpos = pos * great % MOD\n\t\t\tgreat -= 1\nif less < 0 or great < 0:\n\tprint(0)\n\texit()\nrest = less + great\nwhile rest > 0:\n\tpos = pos * rest % MOD\n\trest -= 1\nprint(pos)\n", "def main():\n\t(n, x, pos) = map(int, input().split())\n\t(zero, one) = (0, 0)\n\t(l, r) = (0, n)\n\twhile l < r:\n\t\tmiddle = (l + r) // 2\n\t\tif middle <= pos:\n\t\t\tzero += 1\n\t\t\tl = middle + 1\n\t\telse:\n\t\t\tone += 1\n\t\t\tr = middle\n\tres = 1\n\tmod = 10 ** 9 + 7\n\tfor i in range(zero - 1):\n\t\tres *= x - 1 - i\n\t\tres %= mod\n\tfor i in range(one):\n\t\tres *= n - x - i\n\t\tres %= mod\n\tfor j in range(n - zero - one):\n\t\tres *= j + 1\n\t\tres %= mod\n\tprint(res)\nmain()\n", "import sys\nimport math\n\ndef fact(n, k):\n\ta = math.factorial(n) // math.factorial(n - k)\n\treturn a\n\ndef fn(n, x, p):\n\tleft = 0\n\tright = n\n\tmid = (left + right) / 2\n\ty = mid\n\tgreaterx = 0\n\tlesserx = -1\n\twhile left < right:\n\t\tmid = (left + right) // 2\n\t\tif mid <= p:\n\t\t\tleft = mid + 1\n\t\t\tlesserx = lesserx + 1\n\t\telse:\n\t\t\tright = mid\n\t\t\tgreaterx = greaterx + 1\n\ttry:\n\t\tans = fact(n - x, greaterx) * fact(x - 1, lesserx) * math.factorial(n - 1 - greaterx - lesserx)\n\t\treturn ans % (10 ** 9 + 7)\n\texcept:\n\t\treturn 0\ninput = sys.stdin.read()\ndata = list(map(int, input.split()))\nn = data[0]\nx = data[1]\np = data[2]\nprint(fn(n, x, p))\n", "import math\n[n, x, pos] = list(map(int, input().split()))\n\ndef binarySearch(a, x):\n\tleft = 0\n\tright = len(a)\n\tcount = 0\n\tlcount = 0\n\twhile left < right:\n\t\tmiddle = (left + right) // 2\n\t\tif a[middle] <= x:\n\t\t\tleft = middle + 1\n\t\t\tif a[middle] < x:\n\t\t\t\tlcount += 1\n\t\telse:\n\t\t\tright = middle\n\t\t\tcount += 1\n\tif left > 0 and a[left - 1] == x:\n\t\treturn [True, count, lcount]\n\telse:\n\t\treturn [False, count, lcount]\n\ndef binomial(n, k):\n\treturn 1 if n <= 0 else int(math.factorial(n)) // int(math.factorial(n - k))\nmod = 10 ** 9 + 7\n\ndef permutationCount(n, x, pos):\n\t[good, count, lcount] = binarySearch(range(1, n + 1), pos + 1)\n\tif n - x - count < 0 or x - 1 - lcount < 0:\n\t\treturn 0\n\treturn binomial(n - x, count) % mod * (binomial(x - 1, lcount) % mod) * int(math.factorial(n - count - lcount - 1) % mod)\nprint(permutationCount(n, x, pos) % mod)\n", "from sys import stdin\nfrom math import factorial as f\nMOD = 1000000007\n\ndef bs(a, x):\n\tleft = 0\n\tright = len(a)\n\tinds = []\n\twhile left < right:\n\t\tmid = (left + right) // 2\n\t\tif a[mid] <= x:\n\t\t\tinds.append((mid, 'lower'))\n\t\t\tleft = mid + 1\n\t\telse:\n\t\t\tinds.append((mid, 'higher'))\n\t\t\tright = mid\n\treturn inds\n(n, x, pos) = map(int, stdin.readline().split())\nfake = [i for i in range(n)]\ninds = bs(fake, pos)\nhigherNums = n - x\nlowerNums = x - 1\nfinal = 1\nfor (tmp, name) in inds:\n\tif tmp == pos:\n\t\tcontinue\n\telif name == 'lower':\n\t\tfinal *= lowerNums\n\t\tlowerNums -= 1\n\telse:\n\t\tfinal *= higherNums\n\t\thigherNums -= 1\n\tfinal %= MOD\nremain = higherNums + lowerNums\nfinal *= f(remain) % MOD\nprint(final % MOD)\n", "(n, x, p) = map(int, input().split())\nmod = 1000000007\nsmall = x - 1\nlarge = n - x\narr = [-1 for x in range(n)]\n(l, r) = (0, n)\nwhile l < r:\n\tmid = (l + r) // 2\n\tif mid <= p:\n\t\tif mid == p:\n\t\t\tarr[mid] = 1\n\t\telse:\n\t\t\tarr[mid] = small\n\t\t\tsmall -= 1\n\t\t\tsmall = max([0, small])\n\t\tl = mid + 1\n\telif mid > p:\n\t\tarr[mid] = large\n\t\tlarge -= 1\n\t\tlarge = max(0, large)\n\t\tr = mid\nrem = small + large\nans = 1\nfor i in range(n):\n\tif arr[i] == -1:\n\t\tans *= rem\n\t\tans %= mod\n\t\trem -= 1\n\telse:\n\t\tans *= arr[i]\n\t\tans %= mod\nprint(ans)\n", "(N, x, pos) = map(int, input().split())\nmod = 10 ** 9 + 7\n\ndef nPr(n, r):\n\tif n < r:\n\t\treturn 0\n\tif n == 0 or r == 0:\n\t\treturn 1\n\tfact = 1\n\tfor i in range(n, n - r, -1):\n\t\tfact = fact * i % mod\n\treturn fact\ngt = 0\nlt = 0\nleft = 0\nright = N\ns = set()\nwhile left < right:\n\tmid = (right + left) // 2\n\tif mid < pos:\n\t\tif mid not in s:\n\t\t\tlt += 1\n\t\t\ts.add(mid)\n\t\tleft = mid + 1\n\telif mid == pos:\n\t\tleft = mid + 1\n\telse:\n\t\tif mid not in s:\n\t\t\tgt += 1\n\t\t\ts.add(mid)\n\t\tright = mid\nl = x - 1\ng = N - x\nm = N - 1 - lt - gt\nans = nPr(l, lt) * nPr(g, gt) % mod * nPr(m, m) % mod\nprint(ans)\n", "from sys import stdin, stdout\nfrom collections import *\nst = lambda : list(stdin.readline().strip())\nli = lambda : list(map(int, stdin.readline().split()))\nmp = lambda : map(int, stdin.readline().split())\ninp = lambda : int(stdin.readline())\npr = lambda n: stdout.write(str(n) + '\\n')\nmod = 1000000007\nINF = float('inf')\nma = 10 ** 3 + 1\nfact = [0 for i in range(ma)]\ninvfact = [0 for i in range(ma)]\nfact[0] = 1\nfor i in range(1, ma):\n\tfact[i] = i % mod * fact[i - 1] % mod % mod\ninvfact[ma - 1] = pow(fact[ma - 1], mod - 2, mod)\nfor i in range(ma - 2, -1, -1):\n\tinvfact[i] = invfact[i + 1] % mod * (i + 1) % mod % mod\n\ndef ncr(n, r):\n\tif r > n or n < 0 or r < 0:\n\t\treturn 0\n\treturn fact[n] % mod * invfact[r] % mod % mod * (invfact[n - r] % mod) % mod % mod\n\ndef solve():\n\t(n, x, p) = mp()\n\t(l, r) = (0, n)\n\t(s, b) = (0, 0)\n\twhile l < r:\n\t\tm = (l + r) // 2\n\t\tif m < p:\n\t\t\ts += 1\n\t\t\tl = m + 1\n\t\telif m > p:\n\t\t\tb += 1\n\t\t\tr = m\n\t\telse:\n\t\t\tl = m + 1\n\tans = 1\n\tans = ans % mod * ncr(x - 1, s) % mod % mod\n\tans = ans % mod * ncr(n - x, b) % mod % mod\n\tans = ans % mod * fact[s] % mod % mod\n\tans = ans % mod * fact[b] % mod % mod\n\tans = ans % mod * fact[n - s - b - 1] % mod % mod\n\tpr(ans)\nfor _ in range(1):\n\tsolve()\n", "mod = 1000 * 1000 * 1000 + 7\nfac = [1] * 10001\nfor i in range(2, 1001):\n\tfac[i] = fac[i - 1] * i\n\ndef comb(a, b):\n\tif a < b:\n\t\treturn 0\n\treturn fac[a] // fac[a - b]\n\ndef solve(n, x, pos):\n\tsmaller = 0\n\tgreater = 0\n\tl = 0\n\tr = n\n\twhile l < r:\n\t\tmid = (l + r) // 2\n\t\tif mid < pos:\n\t\t\tsmaller += 1\n\t\t\tl = mid + 1\n\t\telif mid > pos:\n\t\t\tgreater += 1\n\t\t\tr = mid\n\t\telse:\n\t\t\tl = mid + 1\n\tnsmaller = x - 1\n\tnbigger = n - x\n\tans = 1\n\tans = ans * comb(nsmaller, smaller) % mod * comb(nbigger, greater) % mod\n\tans = ans * fac[n - smaller - greater - 1] % mod\n\treturn ans\n(n, x, pos) = map(int, input().split())\nprint(solve(n, x, pos))\n", "import math\n(n, x, pos) = map(int, input().split())\nl = 0\nr = n\ngt = 0\nlt = 0\nwhile l < r:\n\tm = (l + r) // 2\n\tif m > pos:\n\t\tr = m\n\t\tgt += 1\n\telif m < pos:\n\t\tl = m + 1\n\t\tlt += 1\n\telse:\n\t\tl = m + 1\n\ndef perm(nn, kk=None):\n\trr = math.factorial(nn)\n\tif kk is not None:\n\t\trr //= math.factorial(nn - kk)\n\treturn rr\nif lt > x - 1 or gt > n - x:\n\tres = 0\nelse:\n\tres = perm(x - 1, lt) * perm(n - x, gt) * perm(n - lt - gt - 1) % 1000000007\nprint(res)\n", "def bi(a, x, p):\n\tu = x - 1\n\tv = len(a) - x\n\tl = 0\n\tr = len(a)\n\twhile l < r:\n\t\tm = (l + r) // 2\n\t\tif m <= p:\n\t\t\tl = m + 1\n\t\telse:\n\t\t\tr = m\n\t\tif m < p:\n\t\t\ta[m] = u\n\t\t\tu -= 1\n\t\tif m > p:\n\t\t\ta[m] = v\n\t\t\tv -= 1\n\tif u < 0 or v < 0:\n\t\treturn False\n\treturn True\n(n, x, p) = map(int, input().split())\na = [0] * n\na[p] = 1\ns = bi(a, x, p)\nif s:\n\tc = a.count(0)\n\tfor i in range(n):\n\t\tif a[i] == 0:\n\t\t\ta[i] = c\n\t\t\tc -= 1\n\tz = 1\n\tfor i in range(n):\n\t\tz = z * a[i] % 1000000007\n\tprint(z)\nelse:\n\tprint(0)\n", "from sys import stdin\nfrom math import perm\nmod = 10 ** 9 + 7\n\ndef fact(num):\n\tf = 1\n\tfor i in range(2, num + 1):\n\t\tf = f * i % mod\n\treturn f\n(n, x, pos) = map(int, input().split())\n(high, low) = (n - x, x - 1)\n(h, l, mid) = (n, 0, n)\nwhile l < h:\n\tmid = (h + l) // 2\n\tif mid > pos:\n\t\thigh -= 1\n\t\th = mid\n\telif mid < pos:\n\t\tlow -= 1\n\t\tl = mid + 1\n\telse:\n\t\tl = mid + 1\nans = perm(n - x, n - x - high) * perm(x - 1, x - 1 - low) * fact(high + low)\nprint(ans % mod)\n", "def bin_search(a, x):\n\tleft = 0\n\tright = len(a)\n\tj = 0\n\tl = 0\n\twhile left < right:\n\t\tj += 1\n\t\tmiddle = (left + right) // 2\n\t\tif a[middle] <= x:\n\t\t\tl += 1\n\t\t\tleft = middle + 1\n\t\telse:\n\t\t\tright = middle\n\tif left > 0 and a[left - 1] == x:\n\t\treturn (j, l)\n(n, x, pos) = map(int, input().split())\nmod = int(1000000000.0 + 7)\nfact = [1]\nk = 1\nfor i in range(1, n + 1):\n\tk *= i\n\tk = k % mod\n\tfact.append(k)\narr = []\nfor i in range(n):\n\tarr.append(i)\n(j, l) = bin_search(arr, pos)\nu = j - l\nans_u = 1\nup = n - x\nans_l = 1\nlow = x - 1\nl -= 1\nwhile u > 0:\n\tans_u *= up\n\tans_u = ans_u % mod\n\tup -= 1\n\tu -= 1\nwhile l > 0:\n\tans_l *= low\n\tans_l = ans_l % mod\n\tlow -= 1\n\tl -= 1\nans = ans_u * ans_l * fact[n - j] % mod\nprint(ans)\n", "import os\nimport sys\nfrom io import BytesIO, IOBase\nmod = int(1000000000.0 + 7)\n\ndef main():\n\t(n, k, p) = map(int, input().split(' '))\n\tlow = 0\n\thigh = n\n\tans = [0 for x in range(n)]\n\tans[p] = 100\n\twhile low < high:\n\t\tmid = (low + high) // 2\n\t\tif p < mid:\n\t\t\tans[mid] = 1\n\t\t\thigh = mid\n\t\telse:\n\t\t\tans[mid] = -1\n\t\t\tlow = mid + 1\n\tans[p] = 100\n\tchote = 0\n\tbade = 0\n\tfor x in range(1, n + 1):\n\t\tif x > k:\n\t\t\tbade += 1\n\t\tif x < k:\n\t\t\tchote += 1\n\trealans = 1\n\tfor x in range(n):\n\t\tif ans[x] == 1:\n\t\t\trealans = realans * bade % mod\n\t\t\tbade -= 1\n\t\telif ans[x] == -1:\n\t\t\trealans = realans * chote % mod\n\t\t\tchote -= 1\n\tleft = bade + chote\n\tfor x in ans:\n\t\tif x == 0:\n\t\t\trealans = realans * left % mod\n\t\t\tleft -= 1\n\tprint(realans)\nBUFSIZE = 8192\n\nclass FastIO(IOBase):\n\tnewlines = 0\n\n\tdef __init__(self, file):\n\t\tself._fd = file.fileno()\n\t\tself.buffer = BytesIO()\n\t\tself.writable = 'x' in file.mode or 'r' not in file.mode\n\t\tself.write = self.buffer.write if self.writable else None\n\n\tdef read(self):\n\t\twhile True:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tif not b:\n\t\t\t\tbreak\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines = 0\n\t\treturn self.buffer.read()\n\n\tdef readline(self):\n\t\twhile self.newlines == 0:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tself.newlines = b.count(b'\\n') + (not b)\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines -= 1\n\t\treturn self.buffer.readline()\n\n\tdef flush(self):\n\t\tif self.writable:\n\t\t\tos.write(self._fd, self.buffer.getvalue())\n\t\t\t(self.buffer.truncate(0), self.buffer.seek(0))\n\nclass IOWrapper(IOBase):\n\n\tdef __init__(self, file):\n\t\tself.buffer = FastIO(file)\n\t\tself.flush = self.buffer.flush\n\t\tself.writable = self.buffer.writable\n\t\tself.write = lambda s: self.buffer.write(s.encode('ascii'))\n\t\tself.read = lambda : self.buffer.read().decode('ascii')\n\t\tself.readline = lambda : self.buffer.readline().decode('ascii')\n(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))\ninput = lambda : sys.stdin.readline().rstrip('\\r\\n')\nmain()\n", "mod = 10 ** 9 + 7\nfrom math import *\nimport threading\nimport sys\n\ndef npr(n, r):\n\treturn factorial(n) // factorial(n - r) if n >= r else 0\n\ndef fact(x):\n\tprod = 1\n\tfor i in range(1, x + 1):\n\t\tprod *= i\n\treturn prod\n\ndef lower_bound(li, num):\n\tanswer = -1\n\tstart = 0\n\tend = len(li) - 1\n\twhile start <= end:\n\t\tmiddle = (end + start) // 2\n\t\tif li[middle] >= num:\n\t\t\tanswer = middle\n\t\t\tend = middle - 1\n\t\telse:\n\t\t\tstart = middle + 1\n\treturn answer\n\ndef upper_bound(li, num):\n\tanswer = -1\n\tstart = 0\n\tend = len(li) - 1\n\twhile start <= end:\n\t\tmiddle = (end + start) // 2\n\t\tif li[middle] <= num:\n\t\t\tanswer = middle\n\t\t\tstart = middle + 1\n\t\telse:\n\t\t\tend = middle - 1\n\treturn answer\n\ndef abs(x):\n\treturn x if x >= 0 else -x\n\ndef binary_search(li, val, lb, ub):\n\tans = -1\n\twhile lb <= ub:\n\t\tmid = (lb + ub) // 2\n\t\tif li[mid] > val:\n\t\t\tub = mid - 1\n\t\telif val > li[mid]:\n\t\t\tlb = mid + 1\n\t\telse:\n\t\t\tans = mid\n\t\t\tbreak\n\treturn ans\n\ndef kadane(x):\n\tsum_so_far = 0\n\tcurrent_sum = 0\n\tfor i in x:\n\t\tcurrent_sum += i\n\t\tif current_sum < 0:\n\t\t\tcurrent_sum = 0\n\t\telse:\n\t\t\tsum_so_far = max(sum_so_far, current_sum)\n\treturn sum_so_far\n\ndef pref(li):\n\tpref_sum = [0]\n\tfor i in li:\n\t\tpref_sum.append(pref_sum[-1] + i)\n\treturn pref_sum\n\ndef graph(n, m):\n\tadj = dict()\n\tfor i in range(1, n + 1):\n\t\tadj.setdefault(i, 0)\n\tfor i in range(m):\n\t\t(a, b) = map(int, input().split())\n\t\tadj[a] += 1\n\t\tadj[b] += 1\n\treturn adj\n\ndef SieveOfEratosthenes(n):\n\tprime = [True for i in range(n + 1)]\n\tp = 2\n\tli = []\n\twhile p * p <= n:\n\t\tif prime[p] == True:\n\t\t\tfor i in range(p * p, n + 1, p):\n\t\t\t\tprime[i] = False\n\t\tp += 1\n\tfor p in range(2, len(prime)):\n\t\tif prime[p]:\n\t\t\tli.append(p)\n\treturn li\nsys.setrecursionlimit(300000)\nprimes = SieveOfEratosthenes(1300000)\n\ndef fn(n):\n\ti = 2\n\tres = n - 1\n\tval = 0\n\tfor i in range(int(sqrt(n)) + 1, 1, -1):\n\t\tval = i - 1 + int(ceil((n - i) / i))\n\t\tif val <= res:\n\t\t\tres = val\n\t\telse:\n\t\t\tbreak\n\treturn res\n\ndef solve(a, b, c):\n\tdis = b ** 2 - 4 * a * c\n\tans1 = (-b - sqrt(dis)) / (2 * a)\n\tprint(int(ans1))\n\treturn\nfor _ in range(1):\n\t(n, x, pos) = map(int, input().split())\n\ta = [i for i in range(1, n + 1)]\n\t(l, r) = (0, n)\n\tans = 0\n\t(less, more) = (0, 0)\n\twhile l < r:\n\t\tmid = (l + r) // 2\n\t\tif mid == pos:\n\t\t\tl = mid + 1\n\t\telif mid < pos:\n\t\t\tless += 1\n\t\t\tl = mid + 1\n\t\telse:\n\t\t\tmore += 1\n\t\t\tr = mid\n\tans += npr(n - x, more) * npr(x - 1, less)\n\tans *= factorial(n - less - more - 1)\n\tprint(ans % mod)\n", "from collections import Counter\nimport string\nimport math\nimport sys\nfrom fractions import Fraction\n\ndef array_int():\n\treturn [int(i) for i in sys.stdin.readline().split()]\n\ndef vary(arrber_of_variables):\n\tif arrber_of_variables == 1:\n\t\treturn int(sys.stdin.readline())\n\tif arrber_of_variables >= 2:\n\t\treturn map(int, sys.stdin.readline().split())\n\ndef makedict(var):\n\treturn dict(Counter(var))\n\ndef printDivisors(n):\n\tdivisors = []\n\ti = 1\n\twhile i <= math.sqrt(n):\n\t\tif n % i == 0:\n\t\t\tif n // i == i:\n\t\t\t\tdivisors.append(i)\n\t\t\telse:\n\t\t\t\tdivisors.extend((i, n // i))\n\t\ti = i + 1\n\treturn divisors\n\ndef countTotalBits(num):\n\tbinary = bin(num)[2:]\n\treturn len(binary)\n\ndef isPrime(n):\n\tif n <= 1:\n\t\treturn False\n\tif n <= 3:\n\t\treturn True\n\tif n % 2 == 0 or n % 3 == 0:\n\t\treturn False\n\ti = 5\n\twhile i * i <= n:\n\t\tif n % i == 0 or n % (i + 2) == 0:\n\t\t\treturn False\n\t\ti = i + 6\n\treturn True\nfact = [1] * 1001\nc = 1\nmod = 10 ** 9 + 7\nfor i in range(1, 1001):\n\tfact[i] = fact[i - 1] * i % mod\n\ndef ncr(n, r):\n\tif n < r:\n\t\treturn 0\n\tnumer = fact[n]\n\tdenm = fact[n - r] * fact[r]\n\treturn numer * pow(denm, mod - 2, mod)\nif 1:\n\t(n, x, pos) = vary(3)\n\tleft = 0\n\tright = n\n\tsc = bc = 0\n\twhile left < right:\n\t\tmiddle = (right + left) // 2\n\t\tif middle == pos:\n\t\t\tleft = middle + 1\n\t\telif middle < pos:\n\t\t\tsc += 1\n\t\t\tleft = middle + 1\n\t\telse:\n\t\t\tright = middle\n\t\t\tbc += 1\n\tans = 1\n\tans = ans * ncr(n - x, bc) % mod\n\tans = ans * ncr(x - 1, sc) % mod\n\tans = ans * fact[n - (sc + bc + 1)] % mod\n\tans = ans * fact[sc] % mod\n\tans = ans * fact[bc] % mod\n\tprint(ans)\n", "import sys\nfrom math import *\nm = 10 ** 9 + 7\n\ndef f(n):\n\tans = 1\n\tfor i in range(1, n + 1):\n\t\tans = ans * i % m\n\treturn ans\n(n, x, pos) = map(int, input().split())\nleft = 0\nright = n\nl = x - 1\ng = n - x\nans = 1\nwhile left < right:\n\tmid = (left + right) // 2\n\tif mid < pos:\n\t\tans *= l\n\t\tl -= 1\n\t\tleft = mid + 1\n\telif mid > pos:\n\t\tans *= g\n\t\tg -= 1\n\t\tright = mid\n\telse:\n\t\tleft = mid + 1\nif l < 0 or g < 0:\n\tprint(0)\nelse:\n\tprint(ans * f(l + g) % m)\n", "MOD = int(1000000000.0 + 7)\nfrom math import factorial\n\ndef comb(n, k):\n\tif k <= n:\n\t\treturn factorial(n) // (factorial(k) * factorial(n - k))\n\telse:\n\t\treturn 0\n\ndef perm(n, k):\n\tif k <= n:\n\t\treturn factorial(n) // factorial(n - k)\n\telse:\n\t\treturn 0\nfor case in range(1):\n\t(n, x, pos) = map(int, input().split())\n\tlo = 0\n\thi = n\n\tlt_count = 0\n\tgt_count = 0\n\twhile lo < hi:\n\t\tmid = (lo + hi) // 2\n\t\tif mid <= pos:\n\t\t\tif mid < pos:\n\t\t\t\tlt_count += 1\n\t\t\tlo = mid + 1\n\t\telse:\n\t\t\tgt_count += 1\n\t\t\thi = mid\n\tgt_size = n - x\n\tlt_size = x - 1\n\tans = 1\n\tans *= perm(gt_size, gt_count)\n\tans %= MOD\n\tans *= perm(lt_size, lt_count)\n\tans %= MOD\n\tans *= factorial(gt_size - gt_count + lt_size - lt_count)\n\tans %= MOD\n\tprint(ans)\n", "(n, x, pos) = [int(x) for x in input().split()]\n\ndef fact(n):\n\tif n == 0:\n\t\treturn 1\n\tbr = 1\n\tfor i in range(1, n + 1):\n\t\tbr *= i\n\treturn br\nres = 0\nleft = 0\nright = n\ncountbigger = 0\ncountsmaller = 0\nwhile left < right:\n\tmiddle = (left + right) // 2\n\tif middle == pos:\n\t\tleft = middle + 1\n\telif middle < pos:\n\t\tleft = middle + 1\n\t\tcountsmaller += 1\n\telif middle > pos:\n\t\tright = middle\n\t\tcountbigger += 1\nbiggerkol = n - x\nsmallerkol = x - 1\nif smallerkol < countsmaller or biggerkol < countbigger:\n\tprint(0)\n\texit()\nsmes = 0\nsmes = fact(biggerkol) // fact(biggerkol - countbigger)\nsmes2 = fact(smallerkol) // fact(smallerkol - countsmaller)\nsmes2 = round(smes2)\nsmes *= smes2\nkolkol = n - countsmaller - countbigger - 1\nkol = fact(kolkol)\nres = smes * kol % (10 ** 9 + 7)\nprint()\nprint(res)\nprint()\n", "import itertools\nimport math\nimport sys\nimport os\nfrom collections import defaultdict\n\ndef is_debug():\n\treturn 'PYPY3_HOME' not in os.environ\n\ndef stdin_wrapper():\n\tdata = '123 42 24\\n\\n'\n\tfor line in data.split('\\n'):\n\t\tyield line\nif not is_debug():\n\n\tdef stdin_wrapper():\n\t\twhile True:\n\t\t\tyield sys.stdin.readline()\ninputs = stdin_wrapper()\n\ndef input_wrapper():\n\treturn next(inputs)\n\ndef get_str():\n\tif is_debug():\n\t\treturn input_wrapper()\n\treturn input()\n\ndef get(_type):\n\tif _type == str:\n\t\treturn get_str()\n\treturn _type(input_wrapper())\n\ndef get_arr(_type):\n\treturn [_type(x) for x in input_wrapper().split()]\n\ndef tuplerize(method):\n\n\tdef wrap(*args, **kwargs):\n\t\tres = method(*args, **kwargs)\n\t\tif not isinstance(res, (tuple, list)):\n\t\t\tres = (res,)\n\t\treturn res\n\treturn wrap\n\n@tuplerize\ndef solve(n, x, pos):\n\n\tdef binary_analyzer(n, pos):\n\t\trights = 0\n\t\tlefts = 0\n\t\ta = list(range(n))\n\t\tx = a[pos]\n\t\tl = 0\n\t\tr = len(a)\n\t\twhile l < r:\n\t\t\tm = (l + r) // 2\n\t\t\tif a[m] <= x:\n\t\t\t\tl = m + 1\n\t\t\t\tif a[m] != x:\n\t\t\t\t\tlefts += 1\n\t\t\telse:\n\t\t\t\tif a[m] != x:\n\t\t\t\t\trights += 1\n\t\t\t\tr = m\n\t\treturn (rights, lefts)\n\t(rights, lefts) = binary_analyzer(n, pos)\n\t(actual_rights, actual_lefts) = (0, 0)\n\tfor d in range(n):\n\t\tt = d + 1\n\t\tif t == x:\n\t\t\tcontinue\n\t\tif t > x:\n\t\t\tactual_rights += 1\n\t\telse:\n\t\t\tactual_lefts += 1\n\tif actual_rights < rights or actual_lefts < lefts:\n\t\treturn 0\n\tMOD = 10 ** 9 + 7\n\n\tdef replacements(n, k):\n\t\treturn math.factorial(n) // math.factorial(n - k)\n\treturn replacements(actual_rights, rights) * replacements(actual_lefts, lefts) * math.factorial(n - rights - lefts - 1) % MOD\nprint(*solve(*get_arr(int)))\n", "import sys\ninput = sys.stdin.readline\nmod = 1000000007\n\ndef gcd(a, b):\n\tif a == 0:\n\t\treturn b\n\treturn gcd(b % a, a)\n\ndef lcm(a, b):\n\treturn a * b / gcd(a, b)\n\ndef binsimul(x, n):\n\tgive = {}\n\ta = [i for i in range(n)]\n\tleft = 0\n\tright = n\n\twhile left < right:\n\t\tmiddle = (left + right) // 2\n\t\tif a[middle] <= x:\n\t\t\tgive[middle] = 'LE'\n\t\t\tleft = middle + 1\n\t\telse:\n\t\t\tgive[middle] = 'G'\n\t\t\tright = middle\n\treturn give\n\ndef main():\n\t(n, x, pos) = map(int, input().split())\n\td = {}\n\td = binsimul(pos, n)\n\tgreat = n - x\n\tless = x - 1\n\tans = 1\n\tfor i in d:\n\t\tif d[i] == 'G':\n\t\t\tans *= great % mod\n\t\t\tgreat -= 1\n\t\telif i != pos:\n\t\t\tans *= less % mod\n\t\t\tless -= 1\n\t\tn -= 1\n\tfor i in range(1, n + 1):\n\t\tans *= i % mod\n\tans %= mod\n\tprint(ans)\n\treturn\nmain()\n", "def fast_factorial(mod=None):\n\tres = [1, 1]\n\tsize = 2\n\n\tdef ff(k):\n\t\tnonlocal size\n\t\twhile k >= size:\n\t\t\tres.append(res[-1] * size)\n\t\t\tsize += 1\n\t\treturn res[k]\n\n\tdef ff_mod(k):\n\t\tnonlocal size\n\t\twhile k >= size:\n\t\t\tres.append(res[-1] * (size % mod) % mod)\n\t\t\tsize += 1\n\t\treturn res[k]\n\tif mod == None:\n\t\treturn ff\n\telse:\n\t\treturn ff_mod\nMOD = 10 ** 9 + 7\nff = fast_factorial(mod=MOD)\n(n, x, pos) = map(int, input().split())\nlower = x - 1\nhigher = n - x\n\ndef solve(n, lower, higher, pos):\n\tres = 1\n\t(left, right) = (0, n)\n\twhile left < right:\n\t\tmid = (left + right) // 2\n\t\tif mid == pos:\n\t\t\tleft = mid + 1\n\t\telif mid < pos:\n\t\t\tleft = mid + 1\n\t\t\tres *= lower\n\t\t\tres %= MOD\n\t\t\tlower -= 1\n\t\telse:\n\t\t\tright = mid\n\t\t\tres *= higher\n\t\t\tres %= MOD\n\t\t\thigher -= 1\n\tif left > 0 and left - 1 == pos and (res >= 1) and (higher >= 0) and (lower >= 0):\n\t\treturn res * ff(lower + higher) % MOD\n\telse:\n\t\treturn 0\nprint(solve(n, lower, higher, pos))\n", "import sys\nfrom collections import defaultdict as dc\nfrom collections import Counter\nfrom bisect import bisect_right\nimport math\n\ndef fun(a):\n\ts = 1\n\ti = 1\n\twhile i <= a:\n\t\ts = s * i % m\n\t\ti += 1\n\treturn s\n(n, x, d) = map(int, input().split())\n(p, q) = (n - x, x - 1)\n(l, r) = (0, n)\nc = 1\nm = pow(10, 9) + 7\nf = 0\nwhile l < r:\n\tt = (l + r) // 2\n\tif t == d:\n\t\tl = t + 1\n\t\tf = 1\n\tif t > d:\n\t\tc = p * c % m\n\t\tp -= 1\n\t\tr = t\n\telif t < d:\n\t\tc = c * q % m\n\t\tq -= 1\n\t\tl = t + 1\nif f:\n\tc = c * fun(p + q) % m\n\tprint(c)\nelse:\n\tprint(0)\n", "import io\nimport os\nimport sys\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\n\ndef printd(*args, **kwargs):\n\tpass\n\ndef get_str():\n\treturn input().decode().strip()\n\ndef rint():\n\treturn map(int, input().split())\n\ndef oint():\n\treturn int(input())\ndiv = 10 ** 9 + 7\n\ndef get_p(n, r):\n\tret = 1\n\tfor i in range(r):\n\t\tret *= n - i\n\t\tret %= div\n\tprintd('n r ret', n, r, ret)\n\treturn ret\n(n, x, pos) = rint()\nleft = 0\nright = n\nbc = 0\nlc = 0\nwhile left < right:\n\tmid = (left + right) // 2\n\tprintd('mid', mid)\n\tif mid == pos:\n\t\tleft = mid + 1\n\telif mid < pos:\n\t\tlc += 1\n\t\tleft = mid + 1\n\telse:\n\t\tbc += 1\n\t\tright = mid\n\tprintd('l r', left, right)\nbig = n - x\nlit = x - 1\nrem = n - bc - lc - 1\nprintd(big, lit, rem)\nprintd(bc, lc)\nans = get_p(big, bc) * get_p(lit, lc) * get_p(rem, rem)\nprint(ans % div)\n", "import sys\nsys.setrecursionlimit(10 ** 5)\nint1 = lambda x: int(x) - 1\np2D = lambda x: print(*x, sep='\\n')\n\ndef II():\n\treturn int(sys.stdin.buffer.readline())\n\ndef MI():\n\treturn map(int, sys.stdin.buffer.readline().split())\n\ndef LI():\n\treturn list(map(int, sys.stdin.buffer.readline().split()))\n\ndef LLI(rows_number):\n\treturn [LI() for _ in range(rows_number)]\n\ndef BI():\n\treturn sys.stdin.buffer.readline().rstrip()\n\ndef SI():\n\treturn sys.stdin.buffer.readline().rstrip().decode()\n\ndef nCr(com_n, com_r):\n\tif com_n < com_r:\n\t\treturn 0\n\treturn fac[com_n] * ifac[com_r] % md * ifac[com_n - com_r] % md\n\ndef nPr(com_n, com_r):\n\tif com_n < com_r:\n\t\treturn 0\n\treturn fac[com_n] * ifac[com_n - com_r] % md\nmd = 10 ** 9 + 7\nn_max = 1005\nfac = [1]\nfor i in range(1, n_max + 1):\n\tfac.append(fac[-1] * i % md)\nifac = [1] * (n_max + 1)\nifac[n_max] = pow(fac[n_max], md - 2, md)\nfor i in range(n_max - 1, 1, -1):\n\tifac[i] = ifac[i + 1] * (i + 1) % md\n(n, x, p) = MI()\ncl = cr = 0\n(l, r) = (0, n)\nwhile l < r:\n\tm = (l + r) // 2\n\tif m > p:\n\t\tr = m\n\t\tcr += 1\n\telse:\n\t\tl = m + 1\n\t\tif m != p:\n\t\t\tcl += 1\n(s, b) = (x - 1, n - x)\nans = nPr(s, cl) * nPr(b, cr) % md * nPr(n - cl - cr - 1, n - cl - cr - 1) % md\nprint(ans)\n", "MOD = 10 ** 9 + 7\n\ndef mul_range_mod(x_range):\n\tif MOD in x_range:\n\t\treturn 0\n\tresult = 1 % MOD\n\tfor x in x_range:\n\t\tresult *= x\n\t\tresult %= MOD\n\treturn result\n\ndef read_ints():\n\treturn map(int, input().split())\n(n, x, pos) = read_ints()\nlower_x_n = x - 1\nhigher_x_n = n - x\nconditions = [-1] * n\nleft = 0\nright = n\nwhile left < right:\n\tmiddle = (left + right) // 2\n\tleft_if_update = middle + 1\n\tif left_if_update - 1 <= pos:\n\t\tconditions[middle] = 0\n\t\tleft = left_if_update\n\telse:\n\t\tconditions[middle] = 1\n\t\tright = middle\nfree_n = conditions.count(-1)\nle_need = conditions.count(0)\nhigher_need = conditions.count(1)\nlower_need = le_need - 1\nif lower_x_n < lower_need or higher_x_n < higher_need:\n\tresult = 0\nelse:\n\tresult = mul_range_mod(range(lower_x_n + 1 - lower_need, lower_x_n + 1)) * mul_range_mod(range(higher_x_n + 1 - higher_need, higher_x_n + 1)) * mul_range_mod(range(1, free_n + 1)) % MOD\nprint(result)\n", "(a, e, x) = map(int, input().split())\nbig = a - e\nsmall = e - 1\nl = 0\nr = a\nc = a - 1\nans = 1\nwhile l < r:\n\tm = (l + r) // 2\n\tif m < x:\n\t\tc -= 1\n\t\tl = m + 1\n\t\tans *= small % (10 ** 9 + 7)\n\t\tsmall -= 1\n\telif m == x:\n\t\tans = ans\n\t\tl = m + 1\n\telse:\n\t\tc -= 1\n\t\tans *= big % (10 ** 9 + 7)\n\t\tbig -= 1\n\t\tr = m\nf = 1\nfor i in range(1, c + 1):\n\tf *= i % (10 ** 9 + 7)\nprint(ans * f % (10 ** 9 + 7))\n", "import os\nimport sys\nfrom io import BytesIO, IOBase\n_str = str\nBUFSIZE = 8192\n\ndef str(x=b''):\n\treturn x if type(x) is bytes else _str(x).encode()\n\nclass FastIO(IOBase):\n\tnewlines = 0\n\n\tdef __init__(self, file):\n\t\tself._fd = file.fileno()\n\t\tself.buffer = BytesIO()\n\t\tself.writable = 'x' in file.mode or 'r' not in file.mode\n\t\tself.write = self.buffer.write if self.writable else None\n\n\tdef read(self):\n\t\twhile True:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tif not b:\n\t\t\t\tbreak\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines = 0\n\t\treturn self.buffer.read()\n\n\tdef readline(self):\n\t\twhile self.newlines == 0:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tself.newlines = b.count(b'\\n') + (not b)\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines -= 1\n\t\treturn self.buffer.readline()\n\n\tdef flush(self):\n\t\tif self.writable:\n\t\t\tos.write(self._fd, self.buffer.getvalue())\n\t\t\t(self.buffer.truncate(0), self.buffer.seek(0))\n\nclass IOWrapper(IOBase):\n\n\tdef __init__(self, file):\n\t\tself.buffer = FastIO(file)\n\t\tself.flush = self.buffer.flush\n\t\tself.writable = self.buffer.writable\n\t\tself.write = lambda s: self.buffer.write(s.encode('ascii'))\n\t\tself.read = lambda : self.buffer.read().decode('ascii')\n\t\tself.readline = lambda : self.buffer.readline().decode('ascii')\n\ndef inp():\n\treturn sys.stdin.readline().rstrip()\n\ndef mpint():\n\treturn map(int, sys.stdin.readline().split(' '))\n\ndef itg():\n\treturn int(sys.stdin.readline())\nMOD = 10 ** 9 + 7\nMAX_N = 2 * 10 ** 5\nMAX_N = min(MAX_N, MOD - 1)\n(fac, i_fac) = ([0] * (MAX_N + 1), [0] * (MAX_N + 1))\nfac[0] = 1\nfor i in range(MAX_N):\n\tfac[i + 1] = fac[i] * (i + 1) % MOD\ni_fac[-1] = pow(fac[-1], MOD - 2, MOD)\nfor i in reversed(range(MAX_N)):\n\ti_fac[i] = i_fac[i + 1] * (i + 1) % MOD\nA000142 = fac.__getitem__\n\ndef ncr(n, r):\n\treturn 0 if n < r else fac[n] * i_fac[r] % MOD * i_fac[n - r] % MOD\n\ndef npr(n, r):\n\treturn 0 if n < r else fac[n] * i_fac[n - r] % MOD\n\ndef main():\n\t(n, x, pos) = mpint()\n\t(lo, hi) = (0, n)\n\tlower = higher = 0\n\twhile lo < hi:\n\t\tmid = (lo + hi) // 2\n\t\tif mid > pos:\n\t\t\thi = mid\n\t\t\thigher += 1\n\t\telse:\n\t\t\tlo = mid + 1\n\t\t\tif mid != pos:\n\t\t\t\tlower += 1\n\tlower_than_pos = x - 1\n\thigher_than_pos = n - x\n\tother = n - 1 - lower - higher\n\tp1 = npr(lower_than_pos, lower)\n\tp2 = npr(higher_than_pos, higher)\n\tp3 = A000142(other)\n\treturn p1 * p2 * p3 % MOD\n(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))\nprint(main())\n", "import sys\nimport math\nfrom bisect import bisect_right as br\nfrom statistics import mode\nfrom itertools import combinations as cb\n\ndef int_arr():\n\treturn list(map(int, sys.stdin.readline().strip().split()))\n\ndef str_arr():\n\treturn list(map(str, sys.stdin.readline().strip().split()))\n\ndef input():\n\treturn sys.stdin.readline().strip()\n(n, x, pos) = int_arr()\ni = 0\nj = n\nans = 1\nl = x - 1\nr = n - x\nmod = 10 ** 9 + 7\nwhile i < j:\n\tmid = (i + j) // 2\n\tif mid < pos:\n\t\ti = mid + 1\n\t\tans = ans * l % mod\n\t\tl -= 1\n\telif mid > pos:\n\t\tj = mid\n\t\tans = ans * r % mod\n\t\tr -= 1\n\telse:\n\t\ti = mid + 1\nrem = l + r\nfor i in range(1, rem + 1):\n\tans = ans * i % mod\nprint(ans)\n", "M = 10 ** 9 + 7\n\ndef mpow(x, y):\n\tr = 1\n\twhile y > 0:\n\t\tif y & 1:\n\t\t\tr = r * x % M\n\t\tx = x * x % M\n\t\ty = y // 2\n\treturn r\n\ndef nCr(a, b):\n\tif b > a or a < 0 or b < 0:\n\t\treturn 0\n\treturn fact[a] * mpow(fact[b], M - 2) % M * mpow(fact[a - b], M - 2) % M\n(n, x, pos) = list(map(int, input().split()))\nfact = [1 for i in range(n + 1)]\nfor i in range(1, n + 1):\n\tfact[i] = fact[i - 1] * i % M\nlo = 0\nhi = n\nless = 0\nhigh = 0\nwhile lo < hi:\n\tmi = (lo + hi) // 2\n\tif mi <= pos:\n\t\tless = less + 1\n\t\tlo = mi + 1\n\telse:\n\t\thigh = high + 1\n\t\thi = mi\nans = nCr(x - 1, less - 1) * fact[less - 1] % M\nans = ans * nCr(n - x, high) % M\nans = ans * fact[high] % M\nans = ans * fact[n - less - high] % M\nprint(ans)\n", "(n, x, pos) = map(int, input().split())\nlow = 0\nhigh = n\nbig = n - x\nsmall = x - 1\ncntbig = 0\ncntsmall = 0\nans = 1\nmod = 10 ** 9 + 7\nwhile low < high:\n\tmid = (low + high) // 2\n\tif mid < pos:\n\t\tans *= small - cntsmall\n\t\tans %= mod\n\t\tcntsmall += 1\n\t\tlow = mid + 1\n\telif mid > pos:\n\t\tans *= big - cntbig\n\t\tans %= mod\n\t\tcntbig += 1\n\t\thigh = mid\n\telse:\n\t\tlow = mid + 1\nleftnum = n - cntsmall - cntbig - 1\nfor i in range(1, leftnum + 1):\n\tans *= i\n\tans %= mod\nprint(ans)\n", "(n, x, pos) = map(int, input().split())\nMax_m = x - 1\nMax_b = n - x\nkol_m = 0\nkol_b = 0\nl = 0\nr = n\nwhile l < r:\n\tm = (l + r) // 2\n\tif m <= pos:\n\t\tl = m + 1\n\t\tif pos == m:\n\t\t\tcontinue\n\t\tif m < pos:\n\t\t\tkol_m += 1\n\t\tif m > pos:\n\t\t\tkol_b += 1\n\telse:\n\t\tr = m\n\t\tif m < pos:\n\t\t\tkol_m += 1\n\t\tif m > pos:\n\t\t\tkol_b += 1\nif kol_m > Max_m or kol_b > Max_b:\n\tprint(0)\nelse:\n\tanswer = 1\n\tkol = n - 1\n\tfor i in range(Max_b, Max_b - kol_b, -1):\n\t\tanswer *= i\n\tkol -= kol_b\n\tfor i in range(Max_m, Max_m - kol_m, -1):\n\t\tanswer *= i\n\tkol -= kol_m\n\tfor i in range(kol, 1, -1):\n\t\tanswer *= i\n\tprint(answer % 1000000007)\n", "import sys\nimport math\nfrom collections import defaultdict, Counter\nmod = pow(10, 9) + 7\n(n, x, pos) = map(int, input().split())\nlow = 0\nhigh = n\nl = 0\nh = 0\nwhile low < high:\n\tmid = (low + high) // 2\n\tif mid == pos:\n\t\tlow = mid + 1\n\t\twhile low < high:\n\t\t\tmid = (low + high) // 2\n\t\t\th += 1\n\t\t\thigh = mid\n\t\tbreak\n\tif mid < pos:\n\t\tl += 1\n\t\tlow = mid + 1\n\telse:\n\t\th += 1\n\t\thigh = mid\nif l > x - 1 or h > n - x:\n\tprint(0)\nelse:\n\tans = 1\n\tfor i in range(x - 1, x - 1 - l, -1):\n\t\tans = ans * i % mod\n\tfor i in range(n - x, n - x - h, -1):\n\t\tans = ans * i % mod\n\tfor i in range(n - (l + h) - 1, 0, -1):\n\t\tans = ans * i % mod\n\tprint(ans)\n", "import sys, math\nmod = 10 ** 9 + 7\n\ndef binomialCoeff(n, k):\n\tC = [0 for i in range(k + 1)]\n\tC[0] = 1\n\tfor i in range(1, n + 1):\n\t\tj = min(i, k)\n\t\twhile j > 0:\n\t\t\tC[j] = (C[j] + C[j - 1]) % mod\n\t\t\tj -= 1\n\treturn C[k]\n\ndef fact(n):\n\tif n == 1 or n == 0:\n\t\treturn 1\n\telse:\n\t\treturn n * fact(n - 1) % mod\n(n, x, pos) = list(map(int, sys.stdin.readline().strip().split()))\n(l_cnt, r_cnt) = (0, 0)\n(l, r) = (0, n)\nwhile l < r:\n\tm = (l + r) // 2\n\tif m <= pos:\n\t\tl_cnt += 1\n\t\tl = m + 1\n\telse:\n\t\tr_cnt += 1\n\t\tr = m\nl_cnt -= 1\nl_cmb = binomialCoeff(x - 1, l_cnt) * fact(l_cnt)\nr_cmb = binomialCoeff(n - x, r_cnt) * fact(r_cnt)\ncmb = fact(n - l_cnt - r_cnt - 1) * l_cmb % mod * r_cmb % mod\nprint(cmb)\n", "import sys\ninput = sys.stdin.buffer.readline\nri = lambda : int(input())\nrl = lambda : list(map(int, input().split()))\nrs = lambda : input().decode().rstrip('\\n\\r')\nwrt = sys.stdout.write\npr = lambda *args, end='\\n': wrt(' '.join([str(x) for x in args]) + end)\nenum = enumerate\ninf = float('inf')\ncdiv = lambda x, y: -(-x // y)\nmod = 10 ** 9 + 7\nf = [1]\nfor i in range(1, 10005):\n\tf.append(f[-1] * i % mod)\nCases = 1\nfor Case in range(Cases):\n\t(n, x, pos) = rl()\n\ta = [0 for i in range(n)]\n\ta[pos] = x\n\tcp = x + 1\n\tfor i in range(pos + 1, n):\n\t\ta[i] = cp\n\t\tcp += 1\n\tcp = x - 1\n\tfor i in reversed(range(0, pos)):\n\t\ta[i] = cp\n\t\tcp -= 1\n\t(l, r) = (0, n)\n\tdepth = 0\n\tmids = []\n\tposs = True\n\twhile l < r:\n\t\tdepth += 1\n\t\tm = (l + r) // 2\n\t\tmids.append(m)\n\t\tif a[m] <= x:\n\t\t\tl = m + 1\n\t\telse:\n\t\t\tr = m\n\tif l > 0 and a[l - 1] == x:\n\t\tposs = True\n\telse:\n\t\tposs = False\n\tans = 1\n\t(a, b) = (1, 1)\n\tbig = n - x\n\tsmall = x - 1\n\tfor i in mids:\n\t\tif i == pos:\n\t\t\tcontinue\n\t\telif i > pos:\n\t\t\tans *= big\n\t\t\tbig -= 1\n\t\t\tans %= mod\n\t\telse:\n\t\t\tans *= small\n\t\t\tsmall -= 1\n\t\t\tans %= mod\n\tif poss:\n\t\tpr(ans * f[n - len(mids)] % mod)\n\telse:\n\t\tpr(0)\n", "import sys\nfrom math import factorial, comb\ninput = sys.stdin.readline\nmod = 10 ** 9 + 7\n(n, x, pos) = map(int, input().split())\nleft = 0\nright = n\na = 0\nb = 0\nwhile left < right:\n\tmiddle = left + (right - left) // 2\n\tif pos == middle:\n\t\tleft = middle + 1\n\telif pos < middle:\n\t\tb += 1\n\t\tright = middle\n\telse:\n\t\ta += 1\n\t\tleft = middle + 1\nrem = factorial(n - 1 - a - b) % mod\na = comb(x - 1, a) % mod * factorial(a)\nb = comb(n - x, b) % mod * factorial(b)\nprint(a * b % mod * rem % mod)\n", "(n, x, pos) = list(map(int, input().split()))\nlo = 0\nhi = n\ngreater = n - x\nsmaller = x - 1\nans = 1\nmod = 10 ** 9 + 7\nwhile lo < hi:\n\tmid = (lo + hi) // 2\n\tif mid < pos:\n\t\tans = ans * smaller % mod\n\t\tsmaller -= 1\n\t\tlo = mid + 1\n\telif mid == pos:\n\t\tlo = mid + 1\n\telse:\n\t\tans = ans * greater % mod\n\t\tgreater -= 1\n\t\thi = mid\nleft = smaller + greater\nfor i in range(1, left + 1):\n\tans = ans * i % mod\nprint(ans)\n", "import math\n\ndef bins(a, x, pos):\n\tposl = []\n\t(left, right) = (0, len(a))\n\twhile left < right:\n\t\tmiddle = math.floor((left + right) / 2)\n\t\tif a[middle] <= x:\n\t\t\tleft = middle + 1\n\t\t\tif middle != pos:\n\t\t\t\tposl.append('l')\n\t\telse:\n\t\t\tright = middle\n\t\t\tif middle != pos:\n\t\t\t\tposl.append('r')\n\treturn posl\n(n, x, pos) = list(map(int, input().split()))\na = [0] * pos\na.append(x)\na.extend([x + 1] * (n - pos - 1))\nb = bins(a, x, pos)\n(r, l) = (b.count('r'), b.count('l'))\nrcount = n - x\nlcount = x - 1\ncount = n - 1\nres = 1\nfor i in range(r):\n\tres *= rcount\n\trcount -= 1\n\tcount -= 1\nfor i in range(l):\n\tres *= lcount\n\tlcount -= 1\n\tcount -= 1\nfor i in range(1, count + 1):\n\tres *= i % 1000000007\nprint(res % 1000000007)\n", "(n, x, pos) = map(int, input().split())\nmod = 10 ** 9 + 7\nleft = 0\nright = n\nmoves = []\nmiddles = []\nmiddle = (left + right) // 2\nwhile left < right:\n\tmiddle = (left + right) // 2\n\tif middle <= pos:\n\t\tleft = middle + 1\n\t\tmoves.append(1)\n\telse:\n\t\tright = middle\n\t\tmoves.append(-1)\n\tmiddles.append(middle)\nnegcount = 0\nposcount = 0\nfor i in range(len(moves)):\n\tif moves[i] == -1:\n\t\tnegcount += 1\n\telse:\n\t\tposcount += 1\nmorethan = n - x\nlessthan = x - 1\nans = 1\nfor i in range(negcount):\n\tans *= morethan\n\tans %= mod\n\tmorethan -= 1\nfor i in range(poscount - 1):\n\tans *= lessthan\n\tans %= mod\n\tlessthan -= 1\nfor i in range(1, n - len(moves) + 1):\n\tans *= i\n\tans %= mod\nprint(ans)\n", "from collections import *\nfrom itertools import *\nfrom bisect import *\nfrom math import comb, perm, factorial\n\ndef inp():\n\treturn int(input())\n\ndef arrinp():\n\treturn [int(x) for x in input().split()]\nM = int(10 ** 9 + 7)\n\ndef checks(n, pos):\n\tx = pos + 1\n\tA = [i + 1 for i in range(n)]\n\t(left, right) = (0, len(A))\n\t(sm_c, bi_c) = (0, 0)\n\twhile left < right:\n\t\tmiddle = (left + right) // 2\n\t\tif A[middle] < x:\n\t\t\tleft = middle + 1\n\t\t\tsm_c += 1\n\t\telif A[middle] == x:\n\t\t\tleft = middle + 1\n\t\telse:\n\t\t\tright = middle\n\t\t\tbi_c += 1\n\treturn (sm_c, bi_c)\n\ndef main():\n\t(n, x, pos) = arrinp()\n\t(sm_c, bi_c) = checks(n, pos)\n\tlower = x - 1\n\tupper = n - x\n\tx = perm(lower, sm_c)\n\tx *= perm(upper, bi_c)\n\tx *= factorial(n - (sm_c + bi_c + 1))\n\tprint(x % (10 ** 9 + 7))\nmain()\n", "import os\nimport sys\nfrom io import BytesIO, IOBase\nBUFSIZE = 8192\n\nclass FastIO(IOBase):\n\tnewlines = 0\n\n\tdef __init__(self, file):\n\t\tself._fd = file.fileno()\n\t\tself.buffer = BytesIO()\n\t\tself.writable = 'x' in file.mode or 'r' not in file.mode\n\t\tself.write = self.buffer.write if self.writable else None\n\n\tdef read(self):\n\t\twhile True:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tif not b:\n\t\t\t\tbreak\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines = 0\n\t\treturn self.buffer.read()\n\n\tdef readline(self):\n\t\twhile self.newlines == 0:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tself.newlines = b.count(b'\\n') + (not b)\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines -= 1\n\t\treturn self.buffer.readline()\n\n\tdef flush(self):\n\t\tif self.writable:\n\t\t\tos.write(self._fd, self.buffer.getvalue())\n\t\t\t(self.buffer.truncate(0), self.buffer.seek(0))\n\nclass IOWrapper(IOBase):\n\n\tdef __init__(self, file):\n\t\tself.buffer = FastIO(file)\n\t\tself.flush = self.buffer.flush\n\t\tself.writable = self.buffer.writable\n\t\tself.write = lambda s: self.buffer.write(s.encode('ascii'))\n\t\tself.read = lambda : self.buffer.read().decode('ascii')\n\t\tself.readline = lambda : self.buffer.readline().decode('ascii')\n(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))\ninput = lambda : sys.stdin.readline().rstrip('\\r\\n')\nfrom math import gcd, ceil\n\ndef prod(a, mod=10 ** 9 + 7):\n\tans = 1\n\tfor each in a:\n\t\tans = ans * each % mod\n\treturn ans\n\ndef lcm(a, b):\n\treturn a * b // gcd(a, b)\n\ndef binary(x, length=16):\n\ty = bin(x)[2:]\n\treturn y if len(y) >= length else '0' * (length - len(y)) + y\nfor _ in range(int(input()) if not True else 1):\n\t(n, x, pos) = map(int, input().split())\n\tleft = 0\n\tright = n\n\t(low, high) = (0, 0)\n\tpossible = False\n\twhile left < right:\n\t\tmiddle = (left + right) // 2\n\t\tif middle < pos:\n\t\t\tlow += 1\n\t\t\tleft = middle + 1\n\t\telif middle > pos:\n\t\t\thigh += 1\n\t\t\tright = middle\n\t\telse:\n\t\t\tleft = middle + 1\n\tif left - 1 == pos:\n\t\tpossible = True\n\tif not possible:\n\t\tprint(0)\n\t\tquit()\n\tfrom math import factorial\n\n\tdef nPr(n, r):\n\t\treturn factorial(n) // factorial(n - r) if n >= r else 0\n\tprint(nPr(n - x, high) * nPr(x - 1, low) * factorial(n - 1 - high - low) % (10 ** 9 + 7))\n", "from math import factorial\n\ndef P(n, k):\n\tif k <= n:\n\t\treturn factorial(n) // factorial(n - k)\n\telse:\n\t\treturn 0\n(n, x, pos) = map(int, input().split())\nMOD = 10 ** 9 + 7\nl = 0\nu = n\ncnt_less = 0\ncnt_big = 0\nwhile l < u:\n\tmid = (l + u) // 2\n\tif mid <= pos:\n\t\tif mid < pos:\n\t\t\tcnt_less += 1\n\t\tl = mid + 1\n\telse:\n\t\tcnt_big += 1\n\t\tu = mid\nhasBig = n - x\nhasLess = x - 1\nans = 1\nans *= P(hasBig, cnt_big)\nans %= MOD\nans *= P(hasLess, cnt_less)\nans %= MOD\nans *= factorial(hasBig - cnt_big + hasLess - cnt_less)\nprint(ans % MOD)\n", "def binary_search(start, number, find):\n\twhile start < number:\n\t\tmid = (start + number) // 2\n\t\tif mid <= find:\n\t\t\tstart = mid + 1\n\t\telse:\n\t\t\tnumber = mid\n\t\tcheck.append(mid)\nm = 1000000007\n\ndef factorial(number):\n\tans = 1\n\tfor i in range(2, number + 1):\n\t\tans = ans % m * (i % m) % m\n\treturn ans % m\ncheck = []\n(n, num, pos) = map(int, input().split())\nbinary_search(0, n, pos)\ntot = 1\nhigh = n - num\nlow = num - 1\nif check[-1] == pos:\n\tfor i in check:\n\t\tif i == pos:\n\t\t\ttot = tot % m * factorial(n - 1) % m\n\t\telif i > pos:\n\t\t\ttot = tot % m * (high % m) % m\n\t\t\thigh -= 1\n\t\t\tn -= 1\n\t\telse:\n\t\t\ttot = tot % m * (low % m) % m\n\t\t\tlow -= 1\n\t\t\tn -= 1\n\t\tif tot == 0:\n\t\t\tbreak\n\tprint(tot)\nelif n == 1:\n\tprint(1)\nelse:\n\tif len(check) > 2:\n\t\tfor i in check:\n\t\t\tif i > pos and i != pos + 1:\n\t\t\t\ttot = tot % m * (high % m) % m\n\t\t\t\thigh -= 1\n\t\t\t\tn -= 1\n\t\t\telif i < pos:\n\t\t\t\ttot = tot % m * (low % m) % m\n\t\t\t\tlow -= 1\n\t\t\t\tn -= 1\n\t\ttot = tot % m * (high % m) * factorial(n - 2) % m\n\telse:\n\t\ttot = tot % m * (high % m) * factorial(n - 2) % m\n\tprint(tot)\n", "import io\nimport os\nfrom collections import Counter, defaultdict, deque\nMAX_N = 2000\nMOD = 10 ** 9 + 7\n\ndef modInverse(a, p):\n\treturn pow(a, p - 2, p)\nfact = [1]\nfor i in range(1, MAX_N + 1):\n\tfact.append(fact[-1] * i % MOD)\ninvFact = [0] * (MAX_N + 1)\ninvFact[MAX_N] = modInverse(fact[MAX_N], MOD)\nfor i in range(MAX_N - 1, -1, -1):\n\tinvFact[i] = invFact[i + 1] * (i + 1) % MOD\ninv = [0] * (MAX_N + 1)\nfor i in range(1, MAX_N + 1):\n\tinv[i] = fact[i - 1] * invFact[i] % MOD\n\ndef nCr(n, r):\n\tif n < r:\n\t\treturn 0\n\treturn fact[n] * invFact[r] * invFact[n - r] % MOD\n\ndef check(a, x):\n\tleft = 0\n\tright = N\n\twhile left < right:\n\t\tmiddle = (left + right) // 2\n\t\tif a[middle] <= x:\n\t\t\tleft = middle + 1\n\t\telse:\n\t\t\tright = middle\n\tif left > 0 and a[left - 1] == x:\n\t\treturn True\n\treturn False\n\ndef solve(N, X, P):\n\tindices = []\n\tleft = 0\n\tright = N\n\twhile left < right:\n\t\tmiddle = (left + right) // 2\n\t\tif middle <= P:\n\t\t\tindices.append((middle, 1))\n\t\t\tleft = middle + 1\n\t\telse:\n\t\t\tindices.append((middle, -1))\n\t\t\tright = middle\n\tpos = 0\n\tneg = 0\n\tfor (i, sign) in indices:\n\t\tif i == P:\n\t\t\tcontinue\n\t\tif sign < 0:\n\t\t\tpos += 1\n\t\telse:\n\t\t\tneg += 1\n\tassert left > 0 and left - 1 == P\n\tposCand = N - X\n\tnegCand = X - 1\n\treturn nCr(posCand, pos) * fact[pos] * nCr(negCand, neg) * fact[neg] * fact[N - pos - neg - 1] % MOD\nDEBUG = False\nif DEBUG:\n\tfrom itertools import permutations\n\timport random\n\trandom.seed(0)\n\tfor _ in range(300):\n\t\tN = random.randint(1, 5)\n\t\tX = random.randint(1, N)\n\t\tP = random.randint(0, N - 1)\n\t\tans = solve(N, X, P)\n\t\texpected = 0\n\t\tfor perm in permutations(list(range(1, N + 1))):\n\t\t\tif perm[P] == X and check(perm, X):\n\t\t\t\texpected += 1\n\t\tif expected != ans:\n\t\t\tprint('bad', expected, ans)\n\t\t\tprint(N, X, P)\n\t\t\texit()\n\t\telse:\n\t\t\tprint('good')\n\texit()\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\n(N, X, P) = [int(x) for x in input().split()]\nans = solve(N, X, P)\nprint(ans)\n", "import sys\nsys.setrecursionlimit(10 ** 5 + 5)\nfrom collections import defaultdict as dft\n\ndef ml():\n\treturn list(map(int, input().split()))\n\ndef mp():\n\treturn map(int, input().split())\nmxn = 10 ** 9 + 7\n\ndef solve():\n\t(n, x, pos) = mp()\n\tpos = pos + 1\n\tleft = 0\n\tright = n\n\tpro = 1\n\tchote = x - 1\n\tbde = n - x\n\tcount = 0\n\twhile left < right:\n\t\tcount += 1\n\t\tm = (left + right) // 2\n\t\tif m + 1 <= pos:\n\t\t\tleft = m + 1\n\t\t\tif left == pos:\n\t\t\t\tpro = pro * 1 % mxn\n\t\t\telse:\n\t\t\t\tpro = pro * chote % mxn\n\t\t\t\tchote -= 1\n\t\telse:\n\t\t\tpro = pro * bde % mxn\n\t\t\tbde -= 1\n\t\t\tright = m\n\ttemp = 1\n\twhile count < n:\n\t\tpro = pro * temp % mxn\n\t\ttemp += 1\n\t\tcount += 1\n\tprint(pro)\nt = 1\nfor _ in range(t):\n\tsolve()\n", "def factorial(n, p):\n\tif n >= p:\n\t\treturn 0\n\tresult = 1\n\tfor i in range(1, n + 1):\n\t\tresult = result * i % p\n\treturn result\np = 10 ** 9 + 7\n(n, m, pos) = map(int, input().split())\nlesser = m - 1\ngreater = n - m\nl = 0\nh = n\nans = 1\nwhile l < h:\n\tm = (l + h) // 2\n\tif pos < m:\n\t\tans = ans * greater\n\t\tans = ans % p\n\t\tgreater += -1\n\t\th = m\n\telif pos > m:\n\t\tans = ans * lesser\n\t\tans = ans % p\n\t\tlesser += -1\n\t\tl = m + 1\n\telse:\n\t\tl = m + 1\nans = ans * factorial(lesser + greater, p)\nans = ans % p\nprint(ans % p)\n", "import math\n(n, x, p) = map(int, input().split())\nleft = 0\nright = n\nmore = n - x\nless = n - more - 1\nanswer = 1\nwhile left < right:\n\tmid = (left + right) // 2\n\tif mid < p:\n\t\tanswer *= less\n\t\tless -= 1\n\t\tleft = mid + 1\n\telif mid > p:\n\t\tanswer *= more\n\t\tmore -= 1\n\t\tright = mid\n\telse:\n\t\tleft = mid + 1\nanswer *= math.factorial(more + less)\nprint(answer % 1000000007)\n", "from math import factorial\n\ndef fun(pos, x, n):\n\tgs = 0\n\tls = 0\n\tleft = 0\n\tright = n\n\twhile left < right:\n\t\tmiddle = (left + right) // 2\n\t\tif middle <= pos:\n\t\t\tleft = middle + 1\n\t\t\tls += 1 if middle != pos else 0\n\t\telse:\n\t\t\tright = middle\n\t\t\tgs += 1\n\ttotal = n - 1\n\tgreater = n - x\n\tlesser = total - greater\n\tans = 1\n\tfor _ in range(gs):\n\t\tans *= greater\n\t\tgreater -= 1\n\t\ttotal -= 1\n\tfor _ in range(ls):\n\t\tans *= lesser\n\t\tlesser -= 1\n\t\ttotal -= 1\n\tans *= factorial(total)\n\tprint(ans % 1000000007)\ninp = input().split()\nn = int(inp[0])\nx = int(inp[1])\npos = int(inp[2])\nfun(pos, x, n)\n", "factorial = [1, 1, 2]\nfor i in range(3, 1001):\n\tfactorial.append(i * factorial[-1])\n\ndef comb(n, r):\n\tc = factorial[n] // factorial[n - r]\n\treturn int(c)\n(n, x, pos) = map(int, input().split())\nleft = 0\nright = n\nsmaller = 0\nequal = 0\nlarger = 0\nwhile left != right:\n\tmid = (left + right) // 2\n\tif pos < mid:\n\t\tlarger += 1\n\t\tright = mid\n\telif pos > mid:\n\t\tsmaller += 1\n\t\tleft = mid + 1\n\telif pos == mid:\n\t\tequal += 1\n\t\tleft = mid + 1\nif larger > n - x:\n\tprint(0)\nelif smaller > x - 1:\n\tprint(0)\nelse:\n\ts = comb(x - 1, smaller)\n\tl = comb(n - x, larger) % 1000000007\n\tfact = factorial[n - smaller - larger - 1] % 1000000007\n\tnum = s * l * fact\n\tnum %= 1000000007\n\tprint(int(num))\n", "mod = 10 ** 9 + 7\n(n, x, pos) = map(int, input().split())\nl = 0\nr = n\nlcheck = 0\nucheck = 0\nwhile l < r:\n\tmid = (l + r) // 2\n\tif mid <= pos:\n\t\tl = mid + 1\n\t\tif mid != pos:\n\t\t\tlcheck += 1\n\telse:\n\t\tr = mid\n\t\tucheck += 1\nll = x - 1\nrr = n - x\nans = 1\nfor i in range(lcheck):\n\tans *= ll\n\tll -= 1\nfor i in range(ucheck):\n\tans *= rr\n\trr -= 1\nleft = n - (lcheck + ucheck) - 1\nlt = left\nfor i in range(lt):\n\tans *= left\n\tleft -= 1\nprint(ans % mod)\n", "def modFact(n, p):\n\tif n >= p:\n\t\treturn 0\n\tresult = 1\n\tfor i in range(1, n + 1):\n\t\tresult = result * i % p\n\treturn result\n\ndef nCrModp(n, r, p):\n\tif r > n - r:\n\t\tr = n - r\n\tC = [0 for i in range(r + 1)]\n\tC[0] = 1\n\tfor i in range(1, n + 1):\n\t\tfor j in range(min(i, r), 0, -1):\n\t\t\tC[j] = (C[j] + C[j - 1]) % p\n\treturn C[r]\n(n, x, pos) = map(int, input().split())\nvisited = [-1] * n\nl = 0\nr = n\nwhile l < r:\n\tm = (l + r) // 2\n\tif m > pos:\n\t\tvisited[m] = 1\n\t\tr = m\n\telse:\n\t\tvisited[m] = 0\n\t\tl = m + 1\nvisited[pos] = 555\ngreater = visited.count(1)\nsmaller = visited.count(0)\nrandom = visited.count(-1)\nmodulo = 10 ** 9 + 7\nif greater > n - x or x - 1 < smaller or n - 1 - (greater + smaller) < 0:\n\tprint(0)\nelse:\n\tprint(nCrModp(n - x, greater, modulo) * nCrModp(x - 1, smaller, modulo) * modFact(greater, modulo) * modFact(smaller, modulo) * modFact(n - 1 - (greater + smaller), modulo) % modulo)\n", "(n, x, pos) = map(int, input().split())\npermutations = [0] * n\nmodulo = 10 ** 9 + 7\n\ndef binary_search(copy_of_the_x):\n\tleft_numbers = x - 1\n\tright_numbers = n - x\n\tleft = 0\n\tright = n\n\twhile left < right:\n\t\tmiddle = (left + right) // 2\n\t\tif middle < pos:\n\t\t\tpermutations[middle] = left_numbers\n\t\t\tleft_numbers -= 1\n\t\t\tleft = middle + 1\n\t\telif middle == pos:\n\t\t\tpermutations[middle] = 1\n\t\t\tleft = middle + 1\n\t\telse:\n\t\t\tpermutations[middle] = right_numbers\n\t\t\tright_numbers -= 1\n\t\t\tright = middle\n\treturn left_numbers + right_numbers\nremainder = binary_search(x)\nnum_of_valid_permutations = 1\nfor ind in range(n):\n\tif permutations[ind] == 0:\n\t\tnum_of_valid_permutations = num_of_valid_permutations * remainder % modulo\n\t\tremainder -= 1\n\telse:\n\t\tnum_of_valid_permutations = num_of_valid_permutations * permutations[ind] % modulo\nprint(num_of_valid_permutations)\n", "import math\nfrom collections import Counter, defaultdict, deque\nMAX_N = 2000\nMOD = 10 ** 9 + 7\n\ndef modInverse(a, p):\n\treturn pow(a, p - 2, p)\nfact = [1]\nfor i in range(1, MAX_N + 1):\n\tfact.append(fact[-1] * i % MOD)\ninvFact = [0] * (MAX_N + 1)\ninvFact[MAX_N] = modInverse(fact[MAX_N], MOD)\nfor i in range(MAX_N - 1, -1, -1):\n\tinvFact[i] = invFact[i + 1] * (i + 1) % MOD\ninv = [0] * (MAX_N + 1)\nfor i in range(1, MAX_N + 1):\n\tinv[i] = fact[i - 1] * invFact[i] % MOD\n\ndef nCr(n, r):\n\tif n < r:\n\t\treturn 0\n\treturn fact[n] * invFact[r] * invFact[n - r] % MOD\n\ndef f(n, x, pos):\n\tcnts = 0\n\tcntb = 0\n\tleft = 0\n\tright = n\n\twhile left < right:\n\t\tmiddle = (left + right) // 2\n\t\tif middle > pos:\n\t\t\tcntb += 1\n\t\tif middle < pos:\n\t\t\tcnts += 1\n\t\tif middle <= pos:\n\t\t\tleft = middle + 1\n\t\telse:\n\t\t\tright = middle\n\tans = nCr(x - 1, cnts) * nCr(n - x, cntb) * fact[n - cnts - cntb - 1] * fact[cnts] * fact[cntb] % MOD\n\treturn ans\np = 10 ** 9 + 7\nt = 1\nresult = []\nfor i in range(t):\n\t(n, x, pos) = list(map(int, input().split()))\n\tresult.append(f(n, x, pos))\nfor i in range(t):\n\tprint(result[i])\n", "from math import factorial as fac\nper = lambda xi, yi: fac(xi) // fac(xi - yi)\ninf = int(1000000000.0 + 7)\n(n, x, p) = list(map(int, input().split()))\nf = p + 1\nans = 1\n\ndef bins(a, m, x):\n\tlef = 0\n\tp = 1\n\trig = len(a)\n\twhile lef < rig:\n\t\tmid = (lef + rig) // 2\n\t\tif a[mid] <= x:\n\t\t\tlef = mid + 1\n\t\telse:\n\t\t\trig = mid\n\t\tm[mid] = p\n\t\tp += 1\n\tif lef > 0 and a[lef - 1] == x:\n\t\treturn True\n\telse:\n\t\treturn False\nk = [0 for i in range(n)]\nl = [i + 1 for i in range(n)]\nbins(l, k, f)\nmx = max(k)\nls = 0\nrs = 0\nfor i in range(f - 1):\n\tif k[i] != 0 and k[i] < mx:\n\t\tls += 1\nfor i in range(f, n):\n\tif k[i] != 0 and k[i] <= mx:\n\t\trs += 1\n\ndef debug():\n\tprint(mx)\n\tprint(k)\n\tprint(l)\n\tprint(n - k.count(0))\n\tprint(ls, rs)\n\tprint(x, n - x)\nif x - 1 >= ls:\n\tans = ans * per(x - 1, ls)\nelse:\n\tans = 0\nif n - x >= rs:\n\tans = ans * per(n - x, rs)\nelse:\n\tans = 0\nif n - rs - ls - 1 != 0:\n\tans = ans * per(n - rs - ls - 1, n - rs - ls - 1)\nprint(ans % inf)\n", "from math import comb\nfrom math import factorial as fac\n\ndef calc(n, p):\n\t(l, h) = (0, 0)\n\tleft = 0\n\tright = n\n\twhile left < right:\n\t\tmiddle = (left + right) // 2\n\t\tif middle <= p:\n\t\t\tif middle != p:\n\t\t\t\tl += 1\n\t\t\tleft = middle + 1\n\t\tif middle > p:\n\t\t\tright = middle\n\t\t\th += 1\n\treturn [l, h]\n(n, x, p) = [*map(int, input().split())]\n(l, h) = calc(n, p)\nif n - x < h or x - 1 < l:\n\tprint(0)\nelse:\n\tans = comb(n - x, h) * fac(h) * comb(x - 1, l) * fac(l) * fac(n - (1 + l + h))\n\tMOD = 10 ** 9 + 7\n\tprint(ans % MOD)\n", "import math\n(n, x, pos) = map(int, input().split())\n\nclass Node:\n\n\tdef __init__(self, val) -> None:\n\t\tself.val = val\n\t\t(self.left, self.right) = (None, None)\n\ndef buildTree(left, right) -> Node:\n\tif left >= right:\n\t\treturn None\n\tmid = (left + right) // 2\n\tresult = Node(mid)\n\t(newRight, newLeft) = (mid, mid + 1)\n\tleftChild = buildTree(left, newRight)\n\tif leftChild is not None:\n\t\tresult.left = leftChild\n\trightChild = buildTree(newLeft, right)\n\tif rightChild is not None:\n\t\tresult.right = rightChild\n\treturn result\nroot = buildTree(0, n)\n(a, b) = (0, 0)\ncurr = root\nwhile curr is not None and curr.val != pos:\n\tif curr.left is not None and pos < curr.val:\n\t\tb += 1\n\t\tcurr = curr.left\n\telse:\n\t\ta += 1\n\t\tcurr = curr.right\nif curr.right is not None:\n\tb += 1\n\tcurr = curr.right\n\twhile curr.left is not None:\n\t\tb += 1\n\t\tcurr = curr.left\nMOD = 10 ** 9 + 7\n\ndef P(n, r):\n\tif n < r:\n\t\treturn 0\n\treturn math.factorial(n) // math.factorial(n - r)\nresult = 1 * P(x - 1, a) * P(n - x, b) * math.factorial(n - a - b - 1)\nprint(result % MOD)\n", "from sys import stdin\n\nclass Input:\n\n\tdef __init__(self):\n\t\tself.it = iter(stdin.readlines())\n\n\tdef line(self):\n\t\treturn next(self.it).strip()\n\n\tdef array(self, sep=' ', cast=int):\n\t\treturn list(map(cast, self.line().split(sep=sep)))\n\ndef testcases(unknown=False):\n\tinpt = Input()\n\n\tdef testcases_decorator(func):\n\t\t(cases,) = [float('Inf')] if unknown else inpt.array()\n\t\twhile cases > 0:\n\t\t\ttry:\n\t\t\t\tfunc(inpt)\n\t\t\t\tcases -= 1\n\t\t\texcept StopIteration:\n\t\t\t\tbreak\n\treturn testcases_decorator\nMOD = 1000000007\n\ndef p(n, r=None):\n\tif r == None:\n\t\tr = n\n\tif n < 0 or r < 0 or n < r:\n\t\treturn 0\n\tf = 1\n\tfor i in range(n, n - r, -1):\n\t\tf = f * i % MOD\n\treturn f\n\n@testcases(unknown=True)\ndef solve(inpt):\n\t(n, x, pos) = inpt.array()\n\tleft = 0\n\tright = n\n\tgt = 0\n\tlt = 0\n\twhile left < right:\n\t\tmiddle = (left + right) // 2\n\t\tif middle == pos:\n\t\t\tleft = middle + 1\n\t\telif middle < pos:\n\t\t\tleft = middle + 1\n\t\t\tlt += 1\n\t\telse:\n\t\t\tright = middle\n\t\t\tgt += 1\n\tans = p(x - 1, lt) * p(n - x, gt) * p(n - 1 - lt - gt) % MOD\n\tprint(ans)\n", "def perm(n, r):\n\tif n < r:\n\t\treturn 0\n\tans = 1\n\tk = n\n\twhile k > n - r:\n\t\tans *= k\n\t\tk -= 1\n\treturn ans\n\ndef fact(x):\n\tif x < 0:\n\t\treturn 0\n\tans = 1\n\twhile x:\n\t\tans *= x\n\t\tx -= 1\n\treturn ans\n(n, x, p) = map(int, input().split())\nb = [0] * n\nleft = 0\nright = n\nsmall = -1\nlarge = 0\nwhile left < right:\n\tmiddle = (left + right) // 2\n\tif middle <= p:\n\t\tleft = middle + 1\n\t\tb[middle] = -1\n\t\tsmall += 1\n\telse:\n\t\tright = middle\n\t\tb[middle] = 1\n\t\tlarge += 1\nans = perm(x - 1, small) * perm(n - x, large) * fact(n - 1 - small - large)\nprint(ans % (10 ** 9 + 7))\n", "from collections import deque, defaultdict\nmod = 10 ** 9 + 7\n\ndef solve():\n\t(n, x, pos) = map(int, input().split())\n\tlft = 0\n\trt = n\n\tlss = grt = 0\n\twhile lft < rt:\n\t\tmid = (lft + rt) // 2\n\t\tif mid <= pos:\n\t\t\tlft = mid + 1\n\t\t\tif mid != pos:\n\t\t\t\tlss += 1\n\t\telif mid > pos:\n\t\t\tgrt += 1\n\t\t\trt = mid\n\tif lss >= x or grt > n - x:\n\t\tprint(0)\n\t\treturn None\n\tans = 1\n\tfor i in range(lss):\n\t\tans *= x - 1 - i\n\t\tans %= mod\n\tfor i in range(grt):\n\t\tans *= n - x - i\n\t\tans %= mod\n\tfor i in range(n - lss - grt - 1):\n\t\tans *= i + 1\n\t\tans %= mod\n\tprint(ans)\n\ndef main():\n\tt = 1\n\tfor _ in range(t):\n\t\tsolve()\nmain()\n", "import sys\ninput = sys.stdin.readline\n\ndef inp():\n\treturn int(input())\n\ndef inara():\n\treturn list(map(int, input().split()))\n\ndef insr():\n\ts = input()\n\treturn list(s[:len(s) - 1])\n\ndef invr():\n\treturn map(int, input().split())\n(n, x, pos) = invr()\nboro = [0] * n\nlo = 0\nhi = n\nwhile lo < hi:\n\tmid = (hi + lo) // 2\n\tif mid <= pos:\n\t\tboro[mid] = -1\n\t\tlo = mid + 1\n\telse:\n\t\tboro[mid] = 1\n\t\thi = mid\nC = [[0 for i in range(n + 1)] for j in range(n + 1)]\nmod = int(1000000000.0 + 7)\nfor i in range(0, n + 1):\n\tfor j in range(i + 1):\n\t\tif j == 0:\n\t\t\tC[i][j] = 1\n\t\telif j == i:\n\t\t\tC[i][j] = 1\n\t\telse:\n\t\t\tC[i][j] = C[i - 1][j] + C[i - 1][j - 1]\n\t\t\tif C[i][j] >= mod:\n\t\t\t\tC[i][j] -= mod\nfact = [1] * (n + 1)\nfor i in range(1, n + 1):\n\tfact[i] = fact[i - 1] * i\n\tif fact[i] >= mod:\n\t\tfact[i] %= mod\nbig = n - x\nsmall = x - 1\nchotoKoyta = -1\nboroKoyta = 0\njekono = 0\nfor num in boro:\n\tif num == -1:\n\t\tchotoKoyta += 1\n\telif num == 1:\n\t\tboroKoyta += 1\n\telse:\n\t\tjekono += 1\nans = C[big][boroKoyta] * C[small][chotoKoyta]\nif ans >= mod:\n\tans %= mod\nans *= fact[jekono]\nif ans >= mod:\n\tans %= mod\nans *= fact[boroKoyta]\nif ans >= mod:\n\tans %= mod\nans *= fact[chotoKoyta]\nif ans >= mod:\n\tans %= mod\nprint(ans)\n", "mod = 10 ** 9 + 7\n\ndef inverse(i):\n\treturn pow(i, mod - 2, mod)\nfact = [1] * (10 ** 5 + 1)\nifact = [1] * (10 ** 5 + 1)\nfor i in range(2, 10 ** 5 + 1):\n\tfact[i] = fact[i - 1] * i\n\tifact[i] = ifact[i - 1] * inverse(i)\n\tfact[i] %= mod\n\tifact[i] %= mod\n\ndef ncr(n, k):\n\tans = fact[n] * ifact[k] * ifact[n - k]\n\treturn ans % mod\n(n, x, pos) = map(int, input().split())\nleft = 0\nright = n\nels = []\nbig = []\nwhile left < right:\n\tmiddle = (left + right) // 2\n\tif middle <= pos:\n\t\tels.append(middle)\n\t\tleft = middle + 1\n\telse:\n\t\tright = middle\n\t\tbig.append(middle)\nif len(els) > x or len(big) > n - x:\n\tprint(0)\nelse:\n\tels = len(els) - 1\n\tbig = len(big)\n\tans = 1\n\tans *= ncr(x - 1, els)\n\tans %= mod\n\tans *= ncr(n - x, big)\n\tans %= mod\n\tans *= fact[n - big - els - 1]\n\tans %= mod\n\tans *= fact[els]\n\tans %= mod\n\tans *= fact[big]\n\tans %= mod\n\tprint(ans)\n", "import os, sys\nfrom io import BytesIO, IOBase\nmod = 10 ** 9 + 7\nfac = [1]\nfor i in range(1, 1001):\n\tfac.append(fac[-1] * i % mod)\nfac_in = [pow(fac[-1], mod - 2, mod)]\nfor i in range(1000, 0, -1):\n\tfac_in.append(fac_in[-1] * i % mod)\nfac_in.reverse()\n\ndef comb(a, b):\n\tif a < b:\n\t\treturn 0\n\treturn fac[a] * fac_in[a - b] % mod\n\ndef main():\n\t(n, x, pos) = map(int, input().split())\n\t(ch, bd) = (0, 0)\n\t(l, r) = (0, n)\n\twhile l < r:\n\t\tmid = (l + r) // 2\n\t\tif mid < pos:\n\t\t\tl = mid + 1\n\t\t\tch += 1\n\t\telif mid == pos:\n\t\t\tl = mid + 1\n\t\telse:\n\t\t\tr = mid\n\t\t\tbd += 1\n\tprint(comb(x - 1, ch) * comb(n - x, bd) * fac[n - ch - bd - 1] % mod)\nBUFSIZE = 8192\n\nclass FastIO(IOBase):\n\tnewlines = 0\n\n\tdef __init__(self, file):\n\t\tself._fd = file.fileno()\n\t\tself.buffer = BytesIO()\n\t\tself.writable = 'x' in file.mode or 'r' not in file.mode\n\t\tself.write = self.buffer.write if self.writable else None\n\n\tdef read(self):\n\t\twhile True:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tif not b:\n\t\t\t\tbreak\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines = 0\n\t\treturn self.buffer.read()\n\n\tdef readline(self):\n\t\twhile self.newlines == 0:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tself.newlines = b.count(b'\\n') + (not b)\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines -= 1\n\t\treturn self.buffer.readline()\n\n\tdef flush(self):\n\t\tif self.writable:\n\t\t\tos.write(self._fd, self.buffer.getvalue())\n\t\t\t(self.buffer.truncate(0), self.buffer.seek(0))\n\nclass IOWrapper(IOBase):\n\n\tdef __init__(self, file):\n\t\tself.buffer = FastIO(file)\n\t\tself.flush = self.buffer.flush\n\t\tself.writable = self.buffer.writable\n\t\tself.write = lambda s: self.buffer.write(s.encode('ascii'))\n\t\tself.read = lambda : self.buffer.read().decode('ascii')\n\t\tself.readline = lambda : self.buffer.readline().decode('ascii')\n(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))\ninput = lambda : sys.stdin.readline().rstrip('\\r\\n')\nmain()\n", "import math\n(n, x, pos) = map(int, input().split())\nsmallNum = x - 1\nbigNum = n - x\nfixed_small = 0\nfixed_big = 0\n\ndef A(n, r):\n\tans = 1\n\tp = int(math.pow(10, 9) + 7)\n\tfor i in range(n, n - r, -1):\n\t\tans = ans * i % p\n\treturn ans\nleft = 0\nright = n\nwhile left < right:\n\tmiddle = (left + right) // 2\n\tif middle <= pos:\n\t\tleft = middle + 1\n\t\tif middle < pos:\n\t\t\tfixed_small += 1\n\telse:\n\t\tright = middle\n\t\tfixed_big += 1\nans = A(smallNum, fixed_small) * A(bigNum, fixed_big) * A(n - fixed_big - fixed_small - 1, n - fixed_big - fixed_small - 1) % int(math.pow(10, 9) + 7)\nprint(int(ans))\n", "import sys\nimport math\nfrom collections import defaultdict, deque\ninput = sys.stdin.readline\n\ndef inar():\n\treturn [int(el) for el in input().split()]\n\ndef nCr(n, r, p):\n\tnum = den = 1\n\tfor i in range(r):\n\t\tnum = num * (n - i) % p\n\t\tden = den * (i + 1) % p\n\treturn num * pow(den, p - 2, p) % p\n\ndef main():\n\tmod = 10 ** 9 + 7\n\tfact = [1, 1]\n\tfor i in range(2, 100000 + 2):\n\t\tfact.append(fact[-1] * i % mod)\n\t(n, x, pos) = inar()\n\tleft = 0\n\tright = n\n\tarr = [i for i in range(1, n + 1)]\n\tcount = 0\n\tl = 0\n\tr = 0\n\twhile left < right:\n\t\tmiddle = (left + right) // 2\n\t\tif middle <= pos:\n\t\t\tif middle != pos:\n\t\t\t\tl += 1\n\t\t\tleft = middle + 1\n\t\telse:\n\t\t\tr += 1\n\t\t\tright = middle\n\tans = 1\n\tans = ans * nCr(x - 1, l, mod)\n\tans *= nCr(n - x, r, mod)\n\tans *= fact[l] % mod\n\tans *= fact[r] % mod\n\tans *= fact[n - 1 - l - r] % mod\n\tprint(ans % mod)\nmain()\n", "def solve(n):\n\tans_arr = [[0 for _ in range(n)] for _ in range(n)]\n\tfor i in range(0, n, 2):\n\t\tans_arr[i][i] = 1\n\t\tans_arr[i][i + 1] = 1\n\t\tans_arr[i + 1][i] = 1\n\t\tans_arr[i + 1][i + 1] = 1\n\t\tif n - i == 3:\n\t\t\tfor j in range(3):\n\t\t\t\tans_arr[i + 2][i + j] = 1\n\t\t\t\tans_arr[i + j][i + 2] = 1\n\t\t\tbreak\n\treturn ans_arr\n(n, number, pos) = list(map(int, input().split()))\n\ndef solve(n, number, pos):\n\tleft = 0\n\tright = n\n\tpos_dict = {}\n\tfind = False\n\twhile left < right:\n\t\tmid = (left + right) // 2\n\t\tif find:\n\t\t\tpos_dict[mid] = True\n\t\t\tright = mid\n\t\t\tcontinue\n\t\tif mid == pos:\n\t\t\tfind = True\n\t\t\tleft = mid + 1\n\t\telif mid > pos:\n\t\t\tpos_dict[mid] = True\n\t\t\tright = mid\n\t\telse:\n\t\t\tpos_dict[mid] = False\n\t\t\tleft = mid + 1\n\tlarge_slot = 0\n\tsmall_slot = 0\n\tfor (k, v) in pos_dict.items():\n\t\tif v:\n\t\t\tlarge_slot += 1\n\t\telse:\n\t\t\tsmall_slot += 1\n\tlarge_set = n - number\n\tsmall_set = number - 1\n\tif large_set < large_slot or small_set < small_slot:\n\t\treturn 0\n\tMOD = 10 ** 9 + 7\n\tlarge_v = 1\n\tfor i in range(large_slot):\n\t\tlarge_v = large_set * large_v % MOD\n\t\tlarge_set -= 1\n\tsmall_v = 1\n\tfor i in range(small_slot):\n\t\tsmall_v = small_set * small_v % MOD\n\t\tsmall_set -= 1\n\tremain_set = large_set + small_set\n\tremain_v = 1\n\twhile remain_set > 0:\n\t\tremain_v = remain_v * remain_set % MOD\n\t\tremain_set -= 1\n\tv = large_v * small_v % MOD\n\tv = v * remain_v % MOD\n\treturn v\nprint(solve(n, number, pos))\n", "import sys\nimport math\nfrom collections import deque\nfrom bisect import bisect_left, bisect_right\nI = sys.stdin.readline\nIN = lambda x: map(int, x.split())\nL = lambda x: list(IN(x))\n\ndef P(*x, end='\\n'):\n\tprint(*x, end=end)\nM = 1000000007\n\ndef npr(n, r):\n\tc = 1\n\ti = n - r + 1\n\twhile i <= n:\n\t\tc = c * i % M\n\t\ti += 1\n\treturn c\n(n, x, pos) = IN(I())\nleft = 0\nright = n\nf = False\nsmallmax = x - 1\nlargemax = n - x\nsmall = large = 0\nwhile left < right:\n\tmiddle = (left + right) // 2\n\tif middle < pos:\n\t\tsmall += 1\n\t\tif small > smallmax:\n\t\t\tf = True\n\t\t\tbreak\n\t\tleft = middle + 1\n\telif middle == pos:\n\t\tleft = middle + 1\n\telse:\n\t\tlarge += 1\n\t\tif large > largemax:\n\t\t\tf = True\n\t\t\tbreak\n\t\tright = middle\nif f:\n\tP(0)\n\texit()\na = npr(smallmax, small)\nb = npr(largemax, large)\nc = npr(n - small - large - 1, n - small - large - 1)\nres = a * b % M\nres = res * c % M\nP(res)\n", "(a, b, c) = map(int, input().split())\n(l, h) = (0, a)\nr = 1\nz = 0\n(p, q) = (b - 1, a - b)\nwhile l < h:\n\tm = (l + h) // 2\n\tif m == c:\n\t\tz += 1\n\t\tl = m + 1\n\telif m > c:\n\t\tz += 1\n\t\tr *= q\n\t\tq -= 1\n\t\th = m\n\telse:\n\t\tz += 1\n\t\tr *= p\n\t\tp -= 1\n\t\tl = m + 1\nfor i in range(2, a - z + 1):\n\tr = r * i % 1000000007\nprint(r)\n", "import sys, os\nfrom io import BytesIO, IOBase\nimport collections, itertools, bisect, heapq, math, string\nfrom decimal import *\nBUFSIZE = 8192\nBUFSIZE = 8192\n\nclass FastIO(IOBase):\n\tnewlines = 0\n\n\tdef __init__(self, file):\n\t\tself._fd = file.fileno()\n\t\tself.buffer = BytesIO()\n\t\tself.writable = 'x' in file.mode or 'r' not in file.mode\n\t\tself.write = self.buffer.write if self.writable else None\n\n\tdef read(self):\n\t\twhile True:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tif not b:\n\t\t\t\tbreak\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines = 0\n\t\treturn self.buffer.read()\n\n\tdef readline(self):\n\t\twhile self.newlines == 0:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tself.newlines = b.count(b'\\n') + (not b)\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines -= 1\n\t\treturn self.buffer.readline()\n\n\tdef flush(self):\n\t\tif self.writable:\n\t\t\tos.write(self._fd, self.buffer.getvalue())\n\t\t\t(self.buffer.truncate(0), self.buffer.seek(0))\n\nclass IOWrapper(IOBase):\n\n\tdef __init__(self, file):\n\t\tself.buffer = FastIO(file)\n\t\tself.flush = self.buffer.flush\n\t\tself.writable = self.buffer.writable\n\t\tself.write = lambda s: self.buffer.write(s.encode('ascii'))\n\t\tself.read = lambda : self.buffer.read().decode('ascii')\n\t\tself.readline = lambda : self.buffer.readline().decode('ascii')\n(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))\ninput = lambda : sys.stdin.readline().rstrip('\\r\\n')\n\ndef main():\n\t(n, x, pos) = map(int, input().split())\n\tindex = []\n\n\tdef bsearch(a, x):\n\t\t(left, right) = (0, len(a))\n\t\twhile left < right:\n\t\t\tm = (left + right) // 2\n\t\t\tindex.append(m)\n\t\t\tif a[m] <= x:\n\t\t\t\tleft = m + 1\n\t\t\telse:\n\t\t\t\tright = m\n\t\tif left > 0 and a[left - 1] == x:\n\t\t\treturn True\n\t\telse:\n\t\t\treturn False\n\tmod = 10 ** 9 + 7\n\ta = [i for i in range(0, n)]\n\tbsearch(a, pos)\n\tsindex = sorted(index)\n\t(cnt1, cnt2) = (0, 0)\n\tfor i in sindex:\n\t\tif i < pos:\n\t\t\tcnt1 += 1\n\t\tif i > pos:\n\t\t\tcnt2 += 1\n\tans = 1\n\tfor i in range(1, cnt1 + 1):\n\t\tans *= x - i\n\tfor i in range(cnt2):\n\t\tans *= n - x - i\n\tans = ans * math.factorial(n - len(sindex))\n\tprint(ans % mod)\nmain()\n", "import sys\ntry:\n\t(sys.stdin, sys.stdout) = (open('in.txt', 'r'), open('out.txt', 'w'))\nexcept:\n\tpass\nii1 = lambda : int(sys.stdin.readline().strip())\nis1 = lambda : sys.stdin.readline().strip()\niia = lambda : list(map(int, sys.stdin.readline().strip().split()))\nisa = lambda : sys.stdin.readline().strip().split()\nmod = int(1000000000.0 + 7)\nfrom collections import *\nfrom math import *\n(n, x, pos) = iia()\nans = [0] * n\n(low, high) = (0, n)\nwhile low < high:\n\tmid = (low + high) // 2\n\tif pos >= mid:\n\t\tans[mid] = -1\n\t\tlow = mid + 1\n\telse:\n\t\tans[mid] = 1\n\t\thigh = mid\nans[pos] = 9\nP = ans.count(1)\nM = ans.count(-1)\nminus = x - 1\nplus = n - x\na = 1\nfor i in range(P):\n\ta = a * plus % mod\n\tplus -= 1\nfor i in range(M):\n\ta = a * minus % mod\n\tminus -= 1\nfor i in range(1, n - P - M):\n\ta = a * i % mod\nprint(a)\n", "M = int(1000000000.0) + 7\n\ndef fact(n):\n\tres = 1\n\tfor i in range(2, n + 1):\n\t\tres *= i\n\t\tres %= M\n\treturn res\n\ndef modinv(a):\n\treturn int(pow(a, M - 2, M))\n\ndef moddiv(a, b):\n\tbb = modinv(b)\n\ta *= bb\n\ta %= M\n\treturn a\n\ndef npr(n, r):\n\tif n <= 0 or r <= 0:\n\t\treturn 1\n\tres = fact(n)\n\tres = moddiv(res, fact(n - r))\n\treturn res\n(n, x, pos) = map(int, input().split())\n(nb, ns, b, s) = (0, 0, n - x, x - 1)\nleft = 0\nright = n\nwhile left < right:\n\tmiddle = (left + right) // 2\n\t(pleft, pright) = (left, right)\n\tif middle <= pos:\n\t\tns += 1\n\t\tleft = middle + 1\n\telse:\n\t\tnb += 1\n\t\tright = middle\n\tif left == pleft and right == pright:\n\t\tleft = 0\n\t\tbreak\nif left > 0 and left - 1 == pos:\n\tns -= 1\n\tif ns > s or nb > b:\n\t\tprint(0)\n\telse:\n\t\tres = npr(b, nb)\n\t\tres *= npr(s, ns)\n\t\tres *= npr(n - 1 - ns - nb, s + b - ns - nb)\n\t\tprint(res % M)\nelse:\n\tprint(0)\n", "M = int(1000000000.0 + 7)\n\ndef mod_pow(a, p):\n\tres = 1\n\ta %= M\n\twhile p:\n\t\tif p & 1:\n\t\t\tres = res * a % M\n\t\ta = a * a % M\n\t\tp >>= 1\n\treturn res % M\n\ndef mod_inverse(a):\n\treturn mod_pow(a, M - 2)\n\ndef mod_comb(n, k):\n\tif n < 0 or k < 0 or n < k:\n\t\treturn 0\n\tif k > n // 2:\n\t\tk = n - k\n\tres = 1\n\tfor i in range(k):\n\t\tres = res * (n - i) % M\n\t\tres = res * mod_inverse(i + 1) % M\n\treturn res % M\n\ndef mod_fact(n):\n\tres = 1\n\tfor i in range(2, n + 1):\n\t\tres = res * i % M\n\treturn res % M\n\ndef solve(n, x, pos):\n\tL = 0\n\tR = n\n\twantGt = 0\n\twantLt = 0\n\twhile L < R:\n\t\tmid = (L + R) // 2\n\t\tif pos == mid:\n\t\t\tL = mid + 1\n\t\telif pos > mid:\n\t\t\twantLt += 1\n\t\t\tL = mid + 1\n\t\telse:\n\t\t\twantGt += 1\n\t\t\tR = mid\n\tgtx = n - x\n\tltx = x - 1\n\tif gtx < wantGt or ltx < wantLt:\n\t\treturn 0\n\treturn mod_comb(gtx, wantGt) * mod_fact(wantGt) % M * (mod_comb(ltx, wantLt) * mod_fact(wantLt) % M) * (mod_fact(gtx - wantGt + ltx - wantLt) % M) % M\n(n, x, pos) = map(int, input().split())\nprint(solve(n, x, pos))\n", "(n, x, pos) = list(map(int, input().split()))\nmax = 7 + 1000000000.0\nrem = 1\nstart = 0\nend = n\nleft_value = x - 1\nright_value = n - x\nwhile start < end:\n\tmid = (start + end) // 2\n\tif mid > pos:\n\t\trem = rem * right_value % max\n\t\tright_value -= 1\n\t\tn -= 1\n\t\tend = mid\n\telif mid < pos:\n\t\trem = rem * left_value % max\n\t\tleft_value -= 1\n\t\tn -= 1\n\t\tstart = mid + 1\n\telse:\n\t\tstart = mid + 1\nfor i in range(1, n):\n\trem = rem * i % max\nrem = rem % max\nprint(int(rem))\n", "from math import factorial\n(n, x, pos) = map(int, input().split())\nmiddle = 0\ncnt = 0\nleft = 0\nright = n\n(big, small) = (0, 0)\nwhile left < right:\n\tmiddle = (left + right) // 2\n\tif middle <= pos:\n\t\tleft = middle + 1\n\t\tsmall += 1\n\telse:\n\t\tright = middle\n\t\tbig += 1\nsmall -= 1\ncnt = big + small\npr_big = 1\nfor i in range(big):\n\tpr_big = pr_big * (n - x - i)\npr_small = 1\nfor i in range(small):\n\tpr_small = pr_small * (x - 1 - i)\nans = factorial(n - cnt - 1) * pr_small * pr_big % (10 ** 9 + 7)\nprint(ans)\n", "def modFact(n, p):\n\tif n >= p:\n\t\treturn 0\n\tresult = 1\n\tfor i in range(1, n + 1):\n\t\tresult = result * i % p\n\treturn result\n\ndef ncr(n, r, p):\n\t(num, den) = (1, 1)\n\tfor i in range(r):\n\t\tnum = num * (n - i) % p\n\t\tden = den * (i + 1) % p\n\treturn num * pow(den, p - 2, p) % p\nl = list(map(int, input().split()))\n(n, x, pos) = (l[0], l[1], l[2])\nstart = 0\nend = n\nless = 0\nmore = 0\np = 1000000007\nlesses = []\nmores = []\nwhile start < end:\n\tmid = (start + end) // 2\n\tif mid == pos:\n\t\tstart = mid + 1\n\telif mid < pos:\n\t\tmores.append(mid)\n\t\tmore += 1\n\t\tstart = mid + 1\n\telse:\n\t\tless += 1\n\t\tlesses.append(mid)\n\t\tend = mid\ncount = ncr(x - 1, more, p) * modFact(more, p) % p\ncountk = ncr(n - x, less, p) * modFact(less, p) % p\ncountf = modFact(n - more - less - 1, p)\nprint(count * countk * countf % p)\n", "(le, num, pos) = list(map(int, input().split()))\nneedBigger = 0\nneedLower = 0\nmod = 1000000000.0 + 7\nl = 0\nr = le\nwhile l < r:\n\tmid = (l + r) // 2\n\tif mid <= pos:\n\t\tif mid != pos:\n\t\t\tneedLower += 1\n\t\tl = mid + 1\n\telse:\n\t\tr = mid\n\t\tneedBigger += 1\namountOfLess = num - 1\namountOfBigger = le - num\nif amountOfLess < needLower or amountOfBigger < needBigger:\n\tprint(0)\n\texit(0)\nm = 1\nfor i in range(needLower):\n\tm *= amountOfLess - i\n\tm %= mod\nfor i in range(needBigger):\n\tm *= amountOfBigger - i\n\tm %= mod\nother = le - 1 - needLower - needBigger\nfor i in range(1, other + 1):\n\tm *= i\n\tm %= mod\nprint(int(m))\n", "pri = pow(10, 9) + 7\nfact = [1, 1]\nfor i in range(2, 1002):\n\tfact.append(i * fact[i - 1])\n\tfact[-1] %= pri\n\ndef npr(n, r):\n\tif r > n:\n\t\treturn 0\n\tnum = den = 1\n\tfor i in range(r):\n\t\tnum = num * (n - i) % pri\n\t\tden = den * (i + 1) % pri\n\treturn num * pow(den, pri - 2, pri) % pri * fact[r] % pri\n(n, x, p) = map(int, input().split())\ns = 0\nb = 0\nl = 0\nr = n\nwhile l < r:\n\tmid = (l + r) // 2\n\tif 2 == 1:\n\t\tprint('sadf')\n\telif mid <= p:\n\t\tl = mid + 1\n\t\tif mid < p:\n\t\t\tb += 1\n\telse:\n\t\tr = mid\n\t\ts += 1\nsmall = x - 1\nlarge = n - x\nprint(npr(small, b) * npr(large, s) * fact[n - 1 - (s + b)] % pri)\n", "(n, x, pos) = map(int, input().split())\nMOD = 10 ** 9 + 7\n(l, r, a, b) = (0, n, 0, 0)\nwhile l < r:\n\tm = (l + r) // 2\n\tif pos == m:\n\t\tl = m + 1\n\telif pos < m:\n\t\tb += 1\n\t\tr = m\n\telse:\n\t\ta += 1\n\t\tl = m + 1\n(aa, bb) = (x - 1, n - x)\nif aa < a or bb < b:\n\tprint(0)\n\texit(0)\n\ndef A(n, k):\n\tret = 1\n\tfor i in range(n - k + 1, n + 1):\n\t\tret = ret * i % MOD\n\treturn ret\n\ndef fact(n):\n\tret = 1\n\tfor i in range(2, n + 1):\n\t\tret = ret * i % MOD\n\treturn ret\nans = A(aa, a) * A(bb, b) * fact(n - 1 - a - b)\nprint(ans % MOD)\n", "from math import factorial\n(n, x, pos) = [int(p) for p in input().split()]\nMOD = 10 ** 9 + 7\nless = x - 1\nmore = n - x\nleft = 0\nright = n\nans = 1\nwhile left < right:\n\tmiddle = (left + right) // 2\n\tif middle < pos:\n\t\tans *= less\n\t\tless -= 1\n\t\tleft = middle + 1\n\telif middle > pos:\n\t\tans *= more\n\t\tmore -= 1\n\t\tright = middle\n\telse:\n\t\tleft = middle + 1\nans *= factorial(less + more)\nprint(ans % MOD)\n", "import math\n(n, x, pos) = [int(k) for k in input().split()]\nans = 1\ngreater = n - x\nsmaller = x - 1\nleft = 0\nright = n\nwhile left < right:\n\tmid = (left + right) // 2\n\tif mid < pos:\n\t\tans *= smaller\n\t\tsmaller -= 1\n\t\tleft = mid + 1\n\telif mid > pos:\n\t\tans *= greater\n\t\tgreater -= 1\n\t\tright = mid\n\telse:\n\t\tleft = mid + 1\nans *= math.factorial(smaller + greater)\nans = ans % 1000000007\nprint(ans)\n", "import sys\nimport bisect as bi\nimport math\nfrom collections import defaultdict as dd\nimport heapq\nimport itertools\nimport io\nimport os\ninput = sys.stdin.readline\nmo = 10 ** 9 + 7\n\ndef cin():\n\treturn map(int, sin().split())\n\ndef ain():\n\treturn list(map(int, sin().split()))\n\ndef sin():\n\treturn input()\n\ndef inin():\n\treturn int(input())\n\ndef modFact(n, p):\n\tif n < 0:\n\t\treturn 0\n\tif n >= p:\n\t\treturn 0\n\tresult = 1\n\tfor i in range(1, n + 1):\n\t\tresult = result * i % p\n\treturn result\n\ndef binary_search(arr, x):\n\tlow = 0\n\thigh = len(arr)\n\tmid = 0\n\tc = 0\n\tb = 0\n\twhile low < high:\n\t\tmid = (high + low) // 2\n\t\tif arr[mid] < x:\n\t\t\tlow = mid + 1\n\t\t\tc += 1\n\t\telif arr[mid] == x:\n\t\t\tlow = mid + 1\n\t\telse:\n\t\t\thigh = mid\n\t\t\tb += 1\n\tif low == 0:\n\t\tb = -1\n\treturn (b, c)\n\ndef ncr(n, r, p):\n\tif n < r or n < 0:\n\t\treturn 0\n\tnum = den = 1\n\tfor i in range(r):\n\t\tnum = num * (n - i) % p\n\t\tden = den * (i + 1) % p\n\treturn num * pow(den, p - 2, p) % p\nfor _ in range(1):\n\t(n, x, p) = cin()\n\tl = [-i for i in range(p, 0, -1)]\n\tl += [x]\n\tl += [x + 1 + i for i in range(n - p - 1)]\n\ts = binary_search(l, x)\n\tb = s[0]\n\tc = s[1]\n\tans = ncr(x - 1, c, mo) * ncr(n - x, b, mo)\n\tans *= modFact(n - b - c - 1, mo) % mo * (modFact(b, mo) % mo) * (modFact(c, mo) % mo) % mo\n\tprint(ans % mo)\n", "(n, x, p) = map(int, input().split())\nMOD = 1000000007\nnums = [i + 1 for i in range(n)]\n(left, right) = (0, n)\n(a, b) = (-1, 0)\nwhile left < right:\n\tmiddle = (left + right) // 2\n\tif nums[middle] <= nums[p]:\n\t\tleft = middle + 1\n\t\ta += 1\n\telse:\n\t\tright = middle\n\t\tb += 1\ntotal = 1\nfor i in range(x - 1, x - a - 1, -1):\n\ttotal = total * i % MOD\nfor i in range(n - x, n - x - b, -1):\n\ttotal = total * i % MOD\nfor i in range(1, n - a - b):\n\ttotal = total * i % MOD\nprint(total)\n", "def fact(n):\n\tans = 1\n\tfor i in range(1, n + 1):\n\t\tans *= i\n\t\tans %= mod\n\treturn ans\n\ndef binary_search(n, x, idx):\n\tl = 0\n\tr = n\n\tans = 1\n\tbigger = 0\n\tsmaller = 0\n\twhile l < r:\n\t\tmid = (l + r) // 2\n\t\tif mid > idx:\n\t\t\tans *= n - x - bigger\n\t\t\tans %= mod\n\t\t\tbigger += 1\n\t\t\tr = mid\n\t\telif mid < idx:\n\t\t\tl = mid + 1\n\t\t\tans *= x - 1 - smaller\n\t\t\tans %= mod\n\t\t\tsmaller += 1\n\t\telse:\n\t\t\tl = mid + 1\n\tans *= fact(n - smaller - bigger - 1)\n\treturn ans % mod\nmod = 1000000007\n(n, x, pos) = map(int, input().split())\nprint(binary_search(n, x, pos))\n", "def comb(n, x):\n\t(a, b) = (1, 1)\n\tfor i in range(1, x + 1):\n\t\ta *= n + 1 - i\n\t\tb *= i\n\treturn a // b % mod\n\ndef fact(n):\n\tval = 1\n\tfor i in range(1, n + 1):\n\t\tval = val * i % mod\n\treturn val % mod\nmod = 1000000007\n(n, x, pos) = map(int, input().split())\n(less, more) = (0, 0)\n(l, h) = (0, n)\nwhile l < h:\n\tmid = (l + h) // 2\n\tif mid <= pos:\n\t\tless += 1\n\t\tl = mid + 1\n\telse:\n\t\tmore += 1\n\t\th = mid\nless -= 1\nif less <= x - 1 and more <= n - x:\n\tans = comb(x - 1, less) * fact(less) % mod * (comb(n - x, more) * fact(more)) % mod % mod * fact(n - 1 - (less + more)) % mod % mod\n\tprint(ans)\nelse:\n\tprint(0)\n", "(n, x, pos) = map(int, input().split())\nsmaller = 0\nlarger = 0\nfor i in range(1, n + 1):\n\tif i > x:\n\t\tlarger += 1\n\telif i < x:\n\t\tsmaller += 1\nl = 0\nr = n\nans = 1\nwhile l < r:\n\tmid = (l + r) // 2\n\tif mid < pos:\n\t\tans = ans * smaller\n\t\tsmaller -= 1\n\t\tl = mid + 1\n\telif mid == pos:\n\t\tans = ans * 1\n\t\tl = mid + 1\n\telse:\n\t\tr = mid\n\t\tans = ans * larger\n\t\tlarger -= 1\nsmaller += larger\nif smaller > 0:\n\tfor i in range(smaller, 0, -1):\n\t\tans *= i\nprint(ans % (10 ** 9 + 7))\n", "MOD = 10 ** 9 + 7\n\ndef per(n, k):\n\tif n < k:\n\t\treturn 0\n\tif k == 0:\n\t\treturn 1\n\tans = 1\n\tfor i in range(k):\n\t\tans = ans * (n - i) % MOD\n\treturn ans\n\ndef solve(n, x, pos):\n\tle = 0\n\tgt = 0\n\tleft = 0\n\tright = n\n\twhile left < right:\n\t\tmid = (left + right) // 2\n\t\tif pos > mid:\n\t\t\tleft = mid + 1\n\t\t\tle += 1\n\t\telif pos < mid:\n\t\t\tright = mid\n\t\t\tgt += 1\n\t\telse:\n\t\t\tleft = mid + 1\n\tre = n - le - gt - 1\n\treturn per(x - 1, le) * per(n - x, gt) % MOD * per(re, re) % MOD\n(n, x, pos) = map(int, input().split())\nprint(solve(n, x, pos))\n", "(n, x, pos) = map(int, input().split())\nlarge = 0\nsmall = 0\nmod = 10 ** 9 + 7\n(l, h) = (0, n)\nwhile l < h:\n\tm = (l + h) // 2\n\tif m <= pos:\n\t\tif m != pos:\n\t\t\tsmall += 1\n\t\tl = m + 1\n\telse:\n\t\th = m\n\t\tlarge += 1\n(great, less) = (n - x, x - 1)\nans = 1\nfor i in range(large):\n\tans = ans * great % mod\n\tgreat -= 1\nfor i in range(small):\n\tans = ans * less % mod\n\tless -= 1\ntot = less + great\nfor i in range(1, 1 + tot):\n\tans = ans * i % mod\nprint(ans)\n", "(n, x, pos) = list(map(int, input().split()))\nmod = 10 ** 9 + 7\na = 0\nb = 0\nleft = 0\nright = n\narr = range(1, n + 1)\nwhile left < right:\n\tmiddle = (left + right) // 2\n\tif middle <= pos:\n\t\tleft = middle + 1\n\t\ta += 1\n\telse:\n\t\tright = middle\n\t\tb += 1\na -= 1\nfactorial = [1]\nfor i in range(1, n + 1):\n\tfactorial.append(i * factorial[-1])\nnum = factorial[x - 1] * factorial[n - x] * factorial[n - a - b - 1]\ndeno = factorial[x - 1 - a] * factorial[n - x - b]\nans = num // deno\nprint(ans % mod)\n", "def power(a, b, mod):\n\tres = 1\n\twhile b:\n\t\tif b % 2:\n\t\t\tres = res * a % mod\n\t\tb //= 2\n\t\ta = a * a % mod\n\treturn res % mod\n\ndef choose(n, k, fac, MOD):\n\tres = fac[n] % MOD\n\tres = res * power(fac[n - k], MOD - 2, MOD) % MOD\n\treturn res\n(n, x, pos) = map(int, input().split())\nMOD = 10 ** 9 + 7\nfac = [1, 1]\nfor i in range(2, n + 1):\n\tfac.append(fac[-1] * i % MOD)\na = [i for i in range(n)]\nvalid_greater = n - x\nvalid_lesser = x - 1\ngreater_pos = 0\nlesser_pos = 0\nleft = 0\nright = len(a)\ntarg = pos\nwhile left < right:\n\tmid = (left + right) // 2\n\tif a[mid] <= targ:\n\t\tleft = mid + 1\n\t\tif a[mid] != targ:\n\t\t\tlesser_pos += 1\n\telse:\n\t\tright = mid\n\t\tgreater_pos += 1\nans = not (greater_pos + x > n or x - lesser_pos < 1)\nans = ans * choose(valid_greater, greater_pos, fac, MOD) * choose(valid_lesser, lesser_pos, fac, MOD) % MOD\nans = ans * fac[n - greater_pos - lesser_pos - 1] % MOD\nprint(ans)\n", "(n, x, pos) = map(int, input().split())\nleft = 0\nright = n\nlarger_count = 0\nsmaller_count = 0\nmod = 10 ** 9 + 7\n\ndef fact(p, y=1):\n\tif p <= 1:\n\t\treturn y\n\telse:\n\t\treturn fact(p - 1, y * p)\nwhile left < right:\n\tmiddle = (left + right) // 2\n\tif middle <= pos:\n\t\tif middle < pos:\n\t\t\tsmaller_count += 1\n\t\tleft = middle + 1\n\telse:\n\t\tlarger_count += 1\n\t\tright = middle\nif n - x - larger_count < 0 or x - 1 - smaller_count < 0:\n\tprint(0)\nelse:\n\tres = 1\n\tlg = n - x\n\tfor _ in range(larger_count):\n\t\tres *= lg\n\t\tres %= mod\n\t\tlg -= 1\n\tsm = x - 1\n\tfor _ in range(smaller_count):\n\t\tres *= sm\n\t\tres %= mod\n\t\tsm -= 1\n\tres *= fact(n - larger_count - smaller_count - 1)\n\tres %= mod\n\tprint(res)\n", "def fact(n):\n\tans = 1\n\tfor i in range(1, n + 1):\n\t\tans *= i\n\treturn ans\nmod = 10 ** 9 + 7\n\ndef search(A, x):\n\tlo = 0\n\thi = len(A)\n\tfixed = set()\n\twhile lo < hi:\n\t\tmid = (lo + hi) // 2\n\t\tfixed.add(mid)\n\t\tif A[mid] <= x:\n\t\t\tlo = mid + 1\n\t\telse:\n\t\t\thi = mid\n\treturn fixed\n(n, x, pos) = [int(x) for x in input().split()]\nA = list(range(n))\nfixed = search(A, pos)\nsmaller = greater = 0\nfor f in fixed:\n\tif f < pos:\n\t\tsmaller += 1\n\tif f > pos:\n\t\tgreater += 1\nans = 1\nfor i in range(smaller):\n\tans *= x - 1 - i\nfor i in range(greater):\n\tans *= n - x - i\nans *= fact(n - smaller - greater - 1)\nprint(ans % mod)\n", "import math\n(n, x, pos) = map(int, input().split())\nleft = 0\nright = n\nsmall = 0\nbig = 0\nmod = 1000000007\nwhile left < right:\n\tmid = (left + right) // 2\n\tif mid <= pos:\n\t\tleft = mid + 1\n\t\tif mid < pos:\n\t\t\tsmall += 1\n\telse:\n\t\tright = mid\n\t\tbig += 1\nif n - x < big or x - 1 < small:\n\tprint(0)\nelse:\n\ttb = math.factorial(n - x) // math.factorial(n - x - big)\n\tts = math.factorial(x - 1) // math.factorial(x - 1 - small)\n\ty = math.factorial(n - big - small - 1)\n\tprint(tb * ts * y % mod)\n", "import sys\nfrom math import factorial as f\ninput = sys.stdin.readline\nmod = int(1000000000.0) + 7\n\ndef solve():\n\t(n, x, pos) = map(int, input().split())\n\tANS = [0] * n\n\t(lb, hb) = (0, n)\n\twhile lb < hb:\n\t\tmid = (lb + hb) // 2\n\t\tif pos >= mid:\n\t\t\tANS[mid] = -1\n\t\t\tlb = mid + 1\n\t\telse:\n\t\t\tANS[mid] = 1\n\t\t\thb = mid\n\tANS[pos] = 9\n\tP = ANS.count(1)\n\tM = ANS.count(-1)\n\tminus = x - 1\n\tplus = n - x\n\ta = 1\n\tfor i in range(P):\n\t\ta = a * plus % mod\n\t\tplus -= 1\n\tfor i in range(M):\n\t\ta = a * minus % mod\n\t\tminus -= 1\n\tfor i in range(1, n - P - M):\n\t\ta = a * i % mod\n\tprint(a)\nsolve()\n", "(n, x, p) = map(int, input().split())\nmod = 10 ** 9 + 7\nans = 1\n(left, right) = (0, n)\n(c1, c2) = (0, 0)\nwhile left < right:\n\tmid = left + (right - left) // 2\n\tif mid <= p:\n\t\tc1 += 1\n\t\tleft = mid + 1\n\telse:\n\t\tc2 += 1\n\t\tright = mid\nans = 1\nfor i in range(1, n - c1 - c2 + 1):\n\tans = ans * i % mod\nc1 -= 1\n(p1, p2) = (x - 1, n - x)\nfor i in range(p1, p1 - c1, -1):\n\tans = ans * p1 % mod\n\tp1 -= 1\nfor i in range(p2, p2 - c2, -1):\n\tans = ans * p2 % mod\n\tp2 -= 1\nprint(ans)\n", "def perm(N, R):\n\ttemp = 1\n\twhile R > 0:\n\t\ttemp *= N\n\t\tR -= 1\n\t\tN -= 1\n\treturn temp\n\ndef BinarySearch(n, x, pos):\n\t(left, right) = (0, n)\n\t(l, r) = (0, 0)\n\twhile left < right:\n\t\tmiddle = (left + right) // 2\n\t\tif middle <= pos:\n\t\t\tif not middle == pos:\n\t\t\t\tl += 1\n\t\t\tleft = middle + 1\n\t\telse:\n\t\t\tr += 1\n\t\t\tright = middle\n\tif l >= x or r > n - x:\n\t\treturn 0\n\t(t1, t2, t3) = (perm(x - 1, l), perm(n - x, r), perm(n - l - r - 1, n - l - r - 1))\n\treturn t1 * t2 * t3 % (10 ** 9 + 7)\n(n, x, pos) = input().split()\nprint(BinarySearch(int(n), int(x), int(pos)))\n", "from enum import Enum, auto\nMOD = 10 ** 9 + 7\n\nclass State(Enum):\n\tLOWER = (auto(),)\n\tHIGHER = (auto(),)\n\tNO_CARE = (auto(),)\n\ndef include_states(n, pos, states):\n\tleft = 0\n\tright = n\n\twhile left < right:\n\t\tmiddle = (left + right) // 2\n\t\tif middle <= pos:\n\t\t\tleft = middle + 1\n\t\t\tstates[middle] = State.LOWER\n\t\telse:\n\t\t\tright = middle\n\t\t\tstates[middle] = State.HIGHER\n\tif left - 1 != pos:\n\t\treturn -1\n(n, x, pos) = (int(x) for x in input().split())\nstates = n * [State.NO_CARE]\nif include_states(n, pos, states) == -1:\n\tprint(0)\n\texit(0)\nhigher = [i for (i, state) in enumerate(states) if state is State.HIGHER and i != pos]\nlower = [i for (i, state) in enumerate(states) if state is State.LOWER and i != pos]\nno_care = [i for (i, state) in enumerate(states) if state is State.NO_CARE and i != pos]\nstart = n\nresults = [1] * n\n(higher_len, lower_len, no_care_len) = (len(higher), len(lower), len(no_care))\ntmp_high = n - x\nfor index in higher:\n\tresults[index] = tmp_high\n\ttmp_high -= 1\ntmp_lower = x - 1\nfor index in lower:\n\tresults[index] = tmp_lower\n\ttmp_lower -= 1\ntmp_no_care = tmp_high + tmp_lower\nfor index in no_care:\n\tresults[index] = tmp_no_care\n\ttmp_no_care -= 1\nresult = 1\nfor elem in results:\n\tresult = result * elem % MOD\nprint(result)\n", "def binSrc(n, x):\n\t(left, right) = (0, n)\n\td = {0: [], 1: [], 2: []}\n\twhile left < right:\n\t\tmid = (left + right) // 2\n\t\tif mid < x:\n\t\t\tleft = mid + 1\n\t\t\td[1].append(mid)\n\t\telif mid > x:\n\t\t\tright = mid\n\t\t\td[2].append(mid)\n\t\telse:\n\t\t\tleft = mid + 1\n\t\t\td[0].append(mid)\n\treturn d\np = 10 ** 9 + 7\n\ndef ncr(n, r, p):\n\tnum = den = 1\n\tfor i in range(r):\n\t\tnum = num * (n - i) % p\n\t\tden = den * (i + 1) % p\n\treturn num * pow(den, p - 2, p) % p\n\ndef fact(n):\n\tprod = 1\n\tfor i in range(2, n + 1):\n\t\tprod = prod * i % p\n\treturn prod\n(n, num, x) = map(int, input().split())\nd = binSrc(n, x)\nlow = ncr(num - 1, len(d[1]), p) * fact(len(d[1]))\nhigh = ncr(n - num, len(d[2]), p) * fact(len(d[2]))\nval = fact(n - len(d[1]) - len(d[2]) - 1) * low * high % p\nprint(val)\n", "from math import *\nmod = 1000000007\n(n, x, pos) = map(int, input().split())\nleft = 0\nright = n\n(cnts, cntb) = (0, 0)\nwhile left < right:\n\tmid = (left + right) // 2\n\tif mid > pos:\n\t\tcntb += 1\n\tif mid < pos:\n\t\tcnts += 1\n\tif mid <= pos:\n\t\tleft = mid + 1\n\telse:\n\t\tright = mid\na = comb(x - 1, cnts) % mod\nb = comb(n - x, cntb) % mod\nc = factorial(n - 1 - cnts - cntb) % mod\nd = factorial(cnts) % mod\ne = factorial(cntb) % mod\nprint(a * b * c * d * e % mod)\n", "MOD = 1000000007\n\ndef f(n, cnt):\n\tans = 1\n\tfor _ in range(cnt):\n\t\tans = ans * n % MOD\n\t\tn -= 1\n\treturn ans\n\ndef main():\n\t(n, x, pos) = map(int, input().split())\n\tchk1 = 0\n\tchk_r = 0\n\tleft = 0\n\tright = n\n\twhile left < right:\n\t\tmiddle = (left + right) // 2\n\t\tif middle <= pos:\n\t\t\tif middle < pos:\n\t\t\t\tchk1 += 1\n\t\t\tleft = middle + 1\n\t\telse:\n\t\t\tchk_r += 1\n\t\t\tright = middle\n\tif chk1 > x - 1 or chk_r > n - x:\n\t\tprint(0)\n\telse:\n\t\trest = n - chk1 - chk_r - 1\n\t\tprint(f(x - 1, chk1) * f(n - x, chk_r) * f(rest, rest) % MOD)\nmain()\n", "from __future__ import division, print_function\nimport math\nimport os\nimport sys\nfrom fractions import *\nfrom sys import *\nfrom io import BytesIO, IOBase\nfrom itertools import *\nfrom collections import *\nif sys.version_info[0] < 3:\n\tfrom __builtin__ import xrange as range\n\tfrom future_builtins import ascii, filter, hex, map, oct, zip\nBUFSIZE = 8192\n\nclass FastIO(IOBase):\n\tnewlines = 0\n\n\tdef __init__(self, file):\n\t\tself._fd = file.fileno()\n\t\tself.buffer = BytesIO()\n\t\tself.writable = 'x' in file.mode or 'r' not in file.mode\n\t\tself.write = self.buffer.write if self.writable else None\n\n\tdef read(self):\n\t\twhile True:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tif not b:\n\t\t\t\tbreak\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines = 0\n\t\treturn self.buffer.read()\n\n\tdef readline(self):\n\t\twhile self.newlines == 0:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tself.newlines = b.count(b'\\n') + (not b)\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines -= 1\n\t\treturn self.buffer.readline()\n\n\tdef flush(self):\n\t\tif self.writable:\n\t\t\tos.write(self._fd, self.buffer.getvalue())\n\t\t\t(self.buffer.truncate(0), self.buffer.seek(0))\n\nclass IOWrapper(IOBase):\n\n\tdef __init__(self, file):\n\t\tself.buffer = FastIO(file)\n\t\tself.flush = self.buffer.flush\n\t\tself.writable = self.buffer.writable\n\t\tself.write = lambda s: self.buffer.write(s.encode('ascii'))\n\t\tself.read = lambda : self.buffer.read().decode('ascii')\n\t\tself.readline = lambda : self.buffer.readline().decode('ascii')\n\ndef print(*args, **kwargs):\n\t(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))\n\tat_start = True\n\tfor x in args:\n\t\tif not at_start:\n\t\t\tfile.write(sep)\n\t\tfile.write(str(x))\n\t\tat_start = False\n\tfile.write(kwargs.pop('end', '\\n'))\n\tif kwargs.pop('flush', False):\n\t\tfile.flush()\nif sys.version_info[0] < 3:\n\t(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))\nelse:\n\t(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))\ninput = lambda : sys.stdin.readline().rstrip('\\r\\n')\n\ndef inp():\n\treturn sys.stdin.readline().rstrip('\\r\\n')\n\ndef out(var):\n\tsys.stdout.write(str(var))\n\ndef lis():\n\treturn list(map(int, inp().split()))\n\ndef stringlis():\n\treturn list(map(str, inp().split()))\n\ndef sep():\n\treturn map(int, inp().split())\n\ndef strsep():\n\treturn map(str, inp().split())\n\ndef fsep():\n\treturn map(float, inp().split())\n\ndef inpu():\n\treturn int(inp())\n\ndef regularbracket(t):\n\tp = 0\n\tfor i in t:\n\t\tif i == '(':\n\t\t\tp += 1\n\t\telse:\n\t\t\tp -= 1\n\t\tif p < 0:\n\t\t\treturn False\n\telse:\n\t\tif p > 0:\n\t\t\treturn False\n\t\telse:\n\t\t\treturn True\n\ndef binarySearchCount(arr, n, key):\n\tleft = 0\n\tright = n - 1\n\tcount = 0\n\twhile left <= right:\n\t\tmid = int((right + left) / 2)\n\t\tif arr[mid] <= key:\n\t\t\tcount = mid + 1\n\t\t\tleft = mid + 1\n\t\telse:\n\t\t\tright = mid - 1\n\treturn count\n\ndef reverse1(string):\n\tpp = ''\n\tfor i in string[::-1]:\n\t\tpp += i\n\tif pp == string:\n\t\treturn True\n\treturn False\n\ndef reverse2(list1):\n\tl = []\n\tfor i in list1[::-1]:\n\t\tl.append(i)\n\tif l == list1:\n\t\treturn True\n\treturn False\n\ndef mex(list1):\n\tp = max(list1) + 1\n\tfor i in range(len(list1)):\n\t\tif list1[i] != i:\n\t\t\tp = i\n\t\t\tbreak\n\treturn p\n\ndef sumofdigits(n):\n\tn = str(n)\n\ts1 = 0\n\tfor i in n:\n\t\ts1 += int(i)\n\treturn s1\n\ndef perfect_square(n):\n\ts = math.sqrt(n)\n\tif s == int(s):\n\t\treturn True\n\treturn False\n\ndef roman_number(x):\n\tif x > 15999:\n\t\treturn\n\tvalue = [5000, 4000, 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1]\n\tsymbol = ['F', 'MF', 'M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I']\n\troman = ''\n\ti = 0\n\twhile x > 0:\n\t\tdiv = x // value[i]\n\t\tx = x % value[i]\n\t\twhile div:\n\t\t\troman += symbol[i]\n\t\t\tdiv -= 1\n\t\ti += 1\n\treturn roman\n\ndef soretd(s):\n\tfor i in range(1, len(s)):\n\t\tif s[i - 1] > s[i]:\n\t\t\treturn False\n\treturn True\n\ndef countRhombi(h, w):\n\tct = 0\n\tfor i in range(2, h + 1, 2):\n\t\tfor j in range(2, w + 1, 2):\n\t\t\tct += (h - i + 1) * (w - j + 1)\n\treturn ct\n\ndef countrhombi2(h, w):\n\treturn h * h // 4 * (w * w // 4)\n\ndef binpow(a, b):\n\tif b == 0:\n\t\treturn 1\n\telse:\n\t\tres = binpow(a, b // 2)\n\tif b % 2 != 0:\n\t\treturn res * res * a\n\telse:\n\t\treturn res * res\n\ndef binpowmodulus(a, b, m):\n\ta %= m\n\tres = 1\n\twhile b > 0:\n\t\tif b & 1:\n\t\t\tres = res * a % m\n\t\ta = a * a % m\n\t\tb >>= 1\n\treturn res\n\ndef coprime_to_n(n):\n\tresult = n\n\ti = 2\n\twhile i * i <= n:\n\t\tif n % i == 0:\n\t\t\twhile n % i == 0:\n\t\t\t\tn //= i\n\t\t\tresult -= result // i\n\t\ti += 1\n\tif n > 1:\n\t\tresult -= result // n\n\treturn result\n\ndef prime(x):\n\tif x == 1:\n\t\treturn False\n\telse:\n\t\tfor i in range(2, int(math.sqrt(x)) + 1):\n\t\t\tif x % i == 0:\n\t\t\t\treturn False\n\t\telse:\n\t\t\treturn True\n\ndef luckynumwithequalnumberoffourandseven(x, n, a):\n\tif x >= n and str(x).count('4') == str(x).count('7'):\n\t\ta.append(x)\n\telif x < 1000000000000.0:\n\t\tluckynumwithequalnumberoffourandseven(x * 10 + 4, n, a)\n\t\tluckynumwithequalnumberoffourandseven(x * 10 + 7, n, a)\n\treturn a\n\ndef luckynuber(x, n, a):\n\tp = set(str(x))\n\tif len(p) <= 2:\n\t\ta.append(x)\n\tif x < n:\n\t\tluckynuber(x + 1, n, a)\n\treturn a\n\ndef interact(type, x):\n\tif type == 'r':\n\t\tinp = input()\n\t\treturn inp.strip()\n\telse:\n\t\tprint(x, flush=True)\n\ndef findTrailingZeros(n):\n\tcount = 0\n\twhile n >= 5:\n\t\tn //= 5\n\t\tcount += n\n\treturn count\n\ndef mergeSort(arr):\n\tif len(arr) > 1:\n\t\tmid = len(arr) // 2\n\t\tL = arr[:mid]\n\t\tR = arr[mid:]\n\t\tmergeSort(L)\n\t\tmergeSort(R)\n\t\ti = j = k = 0\n\t\twhile i < len(L) and j < len(R):\n\t\t\tif L[i] < R[j]:\n\t\t\t\tarr[k] = L[i]\n\t\t\t\ti += 1\n\t\t\telse:\n\t\t\t\tarr[k] = R[j]\n\t\t\t\tj += 1\n\t\t\tk += 1\n\t\twhile i < len(L):\n\t\t\tarr[k] = L[i]\n\t\t\ti += 1\n\t\t\tk += 1\n\t\twhile j < len(R):\n\t\t\tarr[k] = R[j]\n\t\t\tj += 1\n\t\t\tk += 1\nres = set()\n\ndef solve(p, l, a, b, n):\n\tif p > n or l > 10:\n\t\treturn\n\tif p > 0:\n\t\tres.add(p)\n\tsolve(p * 10 + a, l + 1, a, b, n)\n\tsolve(p * 10 + b, l + 1, a, b, n)\n\ndef main():\n\t(n, x, poss) = sep()\n\tless = x - 1\n\tlarge = n - x\n\ts = 0\n\te = n\n\tans = 1\n\twhile s < e:\n\t\tmid = (s + e) // 2\n\t\tif mid < poss:\n\t\t\ts = mid + 1\n\t\t\tans *= less\n\t\t\tless -= 1\n\t\telif mid > poss:\n\t\t\te = mid\n\t\t\tans *= large\n\t\t\tlarge -= 1\n\t\telse:\n\t\t\ts = mid + 1\n\tless += large\n\tif less > 0:\n\t\tfor i in range(less, 0, -1):\n\t\t\tans *= i\n\tprint(ans % (10 ** 9 + 7))\nmain()\n", "from math import factorial, perm\nimport sys\n\ndef input_int_arr():\n\treturn map(int, sys.stdin.readline().split())\n\ndef print_ln(num):\n\tsys.stdout.write(str(num) + '\\n')\n\ndef binary_search(left, right, x, pos):\n\tcount_less = count_bigger = 0\n\twhile left < right:\n\t\tmid = left + (right - left) // 2\n\t\tif pos >= mid:\n\t\t\tif pos != mid:\n\t\t\t\tcount_less += 1\n\t\t\tleft = mid + 1\n\t\telse:\n\t\t\tright = mid\n\t\t\tcount_bigger += 1\n\treturn (count_less, count_bigger)\n\ndef main():\n\tMOD = 1000000007\n\t(n, x, pos) = input_int_arr()\n\t(count_less, count_bigger) = binary_search(0, n, x, pos)\n\t(smaller_numbers, bigger_numbers) = (x - 1, n - x)\n\tsmaller_count = perm(smaller_numbers, count_less) % MOD\n\tbigger_count = perm(bigger_numbers, count_bigger) % MOD\n\tother_count = factorial(n - 1 - count_less - count_bigger) % MOD\n\tres = int(smaller_count * bigger_count * other_count % MOD)\n\tprint_ln(res)\nmain()\n", "def binarySearch(a, x, status):\n\tleft = 0\n\tright = len(a)\n\twhile left < right:\n\t\tmid = (left + right) // 2\n\t\tif a[mid] <= x:\n\t\t\tleft = mid + 1\n\t\t\tstatus[mid] = -1\n\t\telse:\n\t\t\tright = mid\n\t\t\tstatus[mid] = 1\n\ndef inv(n, p):\n\treturn pow(n, p - 2, p)\nfact = [1] * 1010\np = int(1000000000.0 + 7)\nfor i in range(2, len(fact)):\n\tfact[i] = fact[i - 1] * i % p\n(n, x, pos) = map(int, input().split())\nstatus = [0] * n\n(g, l) = (0, 0)\ntest = list()\nfor _ in range(pos):\n\ttest.append(0)\ntest.append(x)\nfor _ in range(n - (pos + 1)):\n\ttest.append(2000)\nbinarySearch(test, x, status)\nfor i in range(n):\n\tif status[i] == 1 and i != pos:\n\t\tg += 1\n\telif status[i] == -1 and i != pos:\n\t\tl += 1\nanything = n - 1 - (g + l)\ngreater = n - x\nless = n - greater - 1\nif greater < g or less < l:\n\tprint(0)\nelse:\n\tp1 = fact[greater] * inv(fact[greater - g], p) % p\n\tp2 = fact[less] * inv(fact[less - l], p) % p\n\tans = p1 * p2 % p\n\tans = ans * fact[n - 1 - (g + l)] % p\n\tprint(ans)\n", "(n, x, pos) = map(int, input().split())\nmod = 10 ** 9 + 7\nN = 10 ** 5\nmod = 10 ** 9 + 7\nfac = [1] * (N + 1)\nfinv = [1] * (N + 1)\nfor i in range(N):\n\tfac[i + 1] = fac[i] * (i + 1) % mod\nfinv[-1] = pow(fac[-1], mod - 2, mod)\nfor i in reversed(range(N)):\n\tfinv[i] = finv[i + 1] * (i + 1) % mod\n\ndef cmb1(n, r, mod):\n\tif r < 0 or r > n:\n\t\treturn 0\n\tr = min(r, n - r)\n\treturn fac[n] * finv[r] * finv[n - r] % mod\n\ndef prm1(n, r, mod):\n\tif r < 0 or r > n:\n\t\treturn 0\n\treturn fac[n] * finv[n - r] % mod\nl = [0]\nr = [0]\n\ndef BinarySearch(a, x):\n\tleft = 0\n\tright = len(a)\n\twhile left < right:\n\t\tmiddle = (left + right) // 2\n\t\tif a[middle] <= x:\n\t\t\tl[0] += 1\n\t\t\tleft = middle + 1\n\t\telse:\n\t\t\tr[0] += 1\n\t\t\tright = middle\n\tif left > 0 and a[left - 1] == x:\n\t\treturn True\n\telse:\n\t\treturn False\nA = [0] * n\nA[pos] = x\nfor i in range(pos + 1, n):\n\tA[i] = 1001\nBinarySearch(A, x)\nans = prm1(x - 1, l[0] - 1, mod)\nans *= prm1(n - x, r[0], mod)\nans *= fac[n - l[0] - r[0]]\nans %= mod\nprint(ans)\n", "(n, x, pos) = map(int, input().split())\nleft = 0\nright = n\nmod = 10 ** 9 + 7\nN = 2000\ng1 = [1, 1]\ng2 = [1, 1]\ninverse = [0, 1]\n\ndef cmb(n, r, mod):\n\tif r < 0 or r > n:\n\t\treturn 0\n\tr = min(r, n - r)\n\treturn g1[n] * g2[r] * g2[n - r] % mod\nfor i in range(2, N + 1):\n\tg1.append(g1[-1] * i % mod)\n\tinverse.append(-inverse[mod % i] * (mod // i) % mod)\n\tg2.append(g2[-1] * inverse[-1] % mod)\na = []\nwhile left < right:\n\tmiddle = (left + right) // 2\n\ta.append(middle)\n\tif middle <= pos:\n\t\tleft = middle + 1\n\telse:\n\t\tright = middle\ncount = 0\nlower = 0\nupper = 0\nfor i in a:\n\tif i > pos:\n\t\tupper += 1\n\telif i < pos:\n\t\tlower += 1\n\tcount += 1\nans = cmb(n - x, upper, mod)\nans *= cmb(x - 1, lower, mod)\nans %= mod\nfor i in range(1, n - count + 1):\n\tans *= i\n\tans %= mod\nfor i in range(1, upper + 1):\n\tans *= i\n\tans %= mod\nfor i in range(1, lower + 1):\n\tans *= i\n\tans %= mod\nprint(ans)\n", "import os\nimport sys\nfrom io import BytesIO, IOBase\nimport heapq as h\nfrom bisect import bisect_left, bisect_right\nfrom types import GeneratorType\nBUFSIZE = 8192\n\nclass FastIO(IOBase):\n\tnewlines = 0\n\n\tdef __init__(self, file):\n\t\timport os\n\t\tself.os = os\n\t\tself._fd = file.fileno()\n\t\tself.buffer = BytesIO()\n\t\tself.writable = 'x' in file.mode or 'r' not in file.mode\n\t\tself.write = self.buffer.write if self.writable else None\n\n\tdef read(self):\n\t\twhile True:\n\t\t\tb = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tif not b:\n\t\t\t\tbreak\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines = 0\n\t\treturn self.buffer.read()\n\n\tdef readline(self):\n\t\twhile self.newlines == 0:\n\t\t\tb = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tself.newlines = b.count(b'\\n') + (not b)\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines -= 1\n\t\treturn self.buffer.readline()\n\n\tdef flush(self):\n\t\tif self.writable:\n\t\t\tself.os.write(self._fd, self.buffer.getvalue())\n\t\t\t(self.buffer.truncate(0), self.buffer.seek(0))\n\nclass IOWrapper(IOBase):\n\n\tdef __init__(self, file):\n\t\tself.buffer = FastIO(file)\n\t\tself.flush = self.buffer.flush\n\t\tself.writable = self.buffer.writable\n\t\tself.write = lambda s: self.buffer.write(s.encode('ascii'))\n\t\tself.read = lambda : self.buffer.read().decode('ascii')\n\t\tself.readline = lambda : self.buffer.readline().decode('ascii')\n(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))\ninput = lambda : sys.stdin.readline().rstrip('\\r\\n')\nimport collections as col\nimport math, string\n\ndef getInts():\n\treturn [int(s) for s in input().split()]\n\ndef getInt():\n\treturn int(input())\n\ndef getStrs():\n\treturn [s for s in input().split()]\n\ndef getStr():\n\treturn input()\n\ndef listStr():\n\treturn list(input())\nMOD = 10 ** 9 + 7\nimport itertools\n\ndef solve():\n\t(N, X, pos) = getInts()\n\t(left_arr, right_arr) = ([], [])\n\t(left, right) = (0, N)\n\twhile left < right:\n\t\tmid = (left + right) // 2\n\t\tif mid <= pos:\n\t\t\tleft_arr.append(mid)\n\t\t\tleft = mid + 1\n\t\telse:\n\t\t\tright_arr.append(mid)\n\t\t\tright = mid\n\tans = 1\n\t(L, R) = (X - 1, N - X)\n\tfor i in range(len(left_arr) - 1):\n\t\tans *= L\n\t\tL -= 1\n\t\tans %= MOD\n\tfor i in range(len(right_arr)):\n\t\tans *= R\n\t\tR -= 1\n\t\tans %= MOD\n\tfor i in range(1, N - len(left_arr) - len(right_arr) + 1):\n\t\tans *= i\n\t\tans %= MOD\n\treturn ans\nprint(solve())\n", "def bis(a, x):\n\tleft = 0\n\tright = len(a)\n\tcnt_1 = cnt_2 = 0\n\twhile left < right:\n\t\tmiddle = (left + right) // 2\n\t\tif a[middle] <= x:\n\t\t\tleft = middle + 1\n\t\t\tcnt_1 += 1\n\t\telse:\n\t\t\tright = middle\n\t\t\tcnt_2 += 1\n\treturn (cnt_1, cnt_2)\nmod = 10 ** 9 + 7\n(N, X, pos) = map(int, input().split())\n(cnt_1, cnt_2) = bis(list(range(N)), pos)\nans = 1\nfor i in range(cnt_1 - 1):\n\tans = ans * (X - 1 - i) % mod\nfor i in range(cnt_2):\n\tans = ans * (N - X - i) % mod\nfor i in range(1, N - cnt_1 - cnt_2 + 1):\n\tans = ans * i % mod\nprint(ans)\n", "import sys\n\ndef Ints():\n\treturn map(int, sys.stdin.readline().strip().split())\n\ndef Strs():\n\treturn map(str, sys.stdin.readline().strip().split())\n\ndef Array():\n\treturn list(map(int, sys.stdin.readline().strip().split()))\n\ndef Str():\n\treturn sys.stdin.readline().strip()\n\ndef Int():\n\treturn int(sys.stdin.readline().strip())\n\ndef MOD():\n\treturn 1000000007\nmod = 10 ** 9 + 7\n(n, x, pos) = Ints()\nans = 1\n(a, b, c) = (list(range(1, n + 1)), 0, 0)\n(l, r) = (0, n)\nwhile l < r:\n\tm = (l + r) // 2\n\tif a[m] <= pos + 1:\n\t\tif a[m] != pos + 1:\n\t\t\tb += 1\n\t\tl = m + 1\n\telse:\n\t\tr = m\n\t\tc += 1\nfor i in range(x - 1, max(x - 1 - b, -1), -1):\n\tans = ans * i % mod\nfor i in range(n - x, max(n - x - c, -1), -1):\n\tans = ans * i % mod\nfor i in range(n - c - b - 1, 0, -1):\n\tans = ans * i % mod\nprint(ans % mod)\n", "(n, x, pos) = map(int, input().split())\nmod = 10 ** 9 + 7\nA = [0] * pos + [x] + [x + 1] * (n - pos - 1)\nleft = 0\nright = n\nL = x - 1\nR = n - x\na = [0] * n\na[pos] = 1\nans = 1\nwhile left < right:\n\tmiddle = (left + right) // 2\n\tif A[middle] <= x:\n\t\tif a[middle] == 0:\n\t\t\ta[middle] = 1\n\t\t\tans *= L\n\t\t\tans %= mod\n\t\t\tL -= 1\n\t\tleft = middle + 1\n\telse:\n\t\tif a[middle] == 0:\n\t\t\ta[middle] = 1\n\t\t\tans *= R\n\t\t\tans %= mod\n\t\t\tR -= 1\n\t\tright = middle\nfor i in range(1, R + L + 1):\n\tans *= i\n\tans %= mod\nprint(ans)\n", "import sys, math\ninput = sys.stdin.readline\nri = lambda : int(input())\nrl = lambda : list(map(int, input().split()))\nrs = lambda : input()\nfor _ in range(1):\n\tMOD = 10 ** 9 + 7\n\t(n, x, pos) = rl()\n\tls = x - 1\n\tgt = n - x\n\tl = 0\n\tr = n\n\tans = 1\n\twhile l < r:\n\t\tmid = (l + r) // 2\n\t\tif mid == pos:\n\t\t\tans *= 1\n\t\t\tl = mid + 1\n\t\telif mid > pos:\n\t\t\tans *= gt\n\t\t\tgt -= 1\n\t\t\tr = mid\n\t\telse:\n\t\t\tans *= ls\n\t\t\tls -= 1\n\t\t\tl = mid + 1\n\tans *= math.factorial(ls + gt)\n\tprint(ans % MOD)\n", "from sys import stdin\n(n, x, pos) = map(int, stdin.readline().strip().split())\n\ndef bin(a, x):\n\tl = 0\n\tr = n\n\taux = [0 for i in range(n)]\n\twhile l < r:\n\t\tmid = (l + r) // 2\n\t\tif mid < pos:\n\t\t\taux[mid] = 1\n\t\t\tl = mid + 1\n\t\telif pos == mid:\n\t\t\tl = mid + 1\n\t\telse:\n\t\t\taux[mid] = -1\n\t\t\tr = mid\n\treturn aux\n\tif l > 0 and l - 1 == pos:\n\t\treturn True\n\telse:\n\t\treturn False\nmod = 10 ** 9 + 7\nfac = [1 for i in range(n + 10)]\nfor i in range(1, len(fac)):\n\tfac[i] = fac[i - 1] * i % mod\n\ndef comb(n, r):\n\tif r > n:\n\t\treturn 0\n\tnum = fac[n]\n\tden = fac[n - r] * fac[r] % mod\n\treturn num * pow(den, mod - 2, mod) % mod\nw = bin([], x)\nz = w.count(0) - 1\nq = w.count(1)\ny = w.count(-1)\nans = fac[q] * fac[y] * comb(n - x, y) % mod * comb(x - 1, q) * fac[z] % mod\nprint(ans)\n", "import os\nimport sys\nfrom io import BytesIO, IOBase\nBUFSIZE = 8192\n\nclass FastIO(IOBase):\n\tnewlines = 0\n\n\tdef __init__(self, file):\n\t\tself._fd = file.fileno()\n\t\tself.buffer = BytesIO()\n\t\tself.writable = 'x' in file.mode or 'r' not in file.mode\n\t\tself.write = self.buffer.write if self.writable else None\n\n\tdef read(self):\n\t\twhile True:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tif not b:\n\t\t\t\tbreak\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines = 0\n\t\treturn self.buffer.read()\n\n\tdef readline(self):\n\t\twhile self.newlines == 0:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tself.newlines = b.count(b'\\n') + (not b)\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines -= 1\n\t\treturn self.buffer.readline()\n\n\tdef flush(self):\n\t\tif self.writable:\n\t\t\tos.write(self._fd, self.buffer.getvalue())\n\t\t\t(self.buffer.truncate(0), self.buffer.seek(0))\n\nclass IOWrapper(IOBase):\n\n\tdef __init__(self, file):\n\t\tself.buffer = FastIO(file)\n\t\tself.flush = self.buffer.flush\n\t\tself.writable = self.buffer.writable\n\t\tself.write = lambda s: self.buffer.write(s.encode('ascii'))\n\t\tself.read = lambda : self.buffer.read().decode('ascii')\n\t\tself.readline = lambda : self.buffer.readline().decode('ascii')\n(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))\ninput = lambda : sys.stdin.readline()\n\ndef RL():\n\treturn map(int, sys.stdin.readline().split())\n\ndef RLL():\n\treturn list(map(int, sys.stdin.readline().split()))\n\ndef N():\n\treturn int(input())\n\ndef print_list(l):\n\tprint(' '.join(map(str, l)))\n(n, x, p) = RL()\nM = 1000000007\n(a, b) = (x - 1, n - x)\n(l, r) = (0, n)\nans = 1\nwhile l < r:\n\tm = l + r >> 1\n\tif m == p:\n\t\tl = m + 1\n\t\tcontinue\n\tif m < p:\n\t\tans *= a\n\t\tans %= M\n\t\ta -= 1\n\t\tl = m + 1\n\telse:\n\t\tans *= b\n\t\tans %= M\n\t\tb -= 1\n\t\tr = m\nt = a + b\nfor i in range(t, 0, -1):\n\tans *= i\n\tans %= M\nprint(ans)\n", "import math\n\ndef binary_search(l, p):\n\ta = [i for i in range(l)]\n\tle = 0\n\tri = l\n\tcu = set()\n\tcl = set()\n\twhile le < ri:\n\t\tm = (le + ri) // 2\n\t\tif a[m] <= p:\n\t\t\tcl.add(m)\n\t\t\tle = m + 1\n\t\telse:\n\t\t\tcu.add(m)\n\t\t\tri = m\n\treturn [len(cl) - 1, len(cu)]\n(n, x, pos) = [int(i) for i in input().split()]\nch = binary_search(n, pos)\nfixed = math.perm(x - 1, ch[0]) % (10 ** 9 + 7) * (math.perm(n - x, ch[1]) % (10 ** 9 + 7)) % (10 ** 9 + 7)\nrest = math.factorial(n - ch[0] - ch[1] - 1) % (10 ** 9 + 7)\nprint(fixed * rest % (10 ** 9 + 7))\n", "import time, math as mt, bisect as bs, sys\nfrom sys import stdin, stdout\nfrom collections import deque\nfrom fractions import Fraction\nfrom collections import Counter\nfrom collections import OrderedDict\npi = 3.141592653589793\n\ndef II():\n\treturn int(stdin.readline())\n\ndef IP():\n\treturn map(int, stdin.readline().split())\n\ndef L():\n\treturn list(map(int, stdin.readline().split()))\n\ndef P(x):\n\treturn stdout.write(str(x) + '\\n')\n\ndef PI(x, y):\n\treturn stdout.write(str(x) + ' ' + str(y) + '\\n')\n\ndef lcm(a, b):\n\treturn a * b // gcd(a, b)\n\ndef gcd(a, b):\n\tif a == 0:\n\t\treturn b\n\telif b == 0:\n\t\treturn a\n\tif a > b:\n\t\treturn gcd(a % b, b)\n\telse:\n\t\treturn gcd(a, b % a)\n\ndef bfs(adj, v):\n\tvisited = [False] * (v + 1)\n\tq = deque()\n\twhile q:\n\t\tpass\n\ndef sieve():\n\tli = [True] * (2 * 10 ** 5 + 5)\n\t(li[0], li[1]) = (False, False)\n\tfor i in range(2, len(li), 1):\n\t\tif li[i] == True:\n\t\t\tfor j in range(i * i, len(li), i):\n\t\t\t\tli[j] = False\n\tprime = []\n\tfor i in range(2 * 10 ** 5 + 5):\n\t\tif li[i] == True:\n\t\t\tprime.append(i)\n\treturn prime\n\ndef setBit(n):\n\tcount = 0\n\twhile n != 0:\n\t\tn = n & n - 1\n\t\tcount += 1\n\treturn count\nmx = 10 ** 7\nspf = [mx] * (mx + 1)\n\ndef SPF():\n\tspf[1] = 1\n\tfor i in range(2, mx + 1):\n\t\tif spf[i] == mx:\n\t\t\tspf[i] = i\n\t\t\tfor j in range(i * i, mx + 1, i):\n\t\t\t\tif i < spf[j]:\n\t\t\t\t\tspf[j] = i\n\treturn\n\ndef readTree(n, e):\n\tadj = [set() for i in range(n + 1)]\n\tfor i in range(e):\n\t\t(u1, u2) = IP()\n\t\tadj[u1].add(u2)\n\treturn adj\nmod = 10 ** 9 + 7\n\ndef solve():\n\t(n, x, pos) = IP()\n\t(low, high) = (0, n)\n\t(big, small) = (0, 0)\n\tans = 1\n\twhile high - low >= 1:\n\t\tmid = (low + high) // 2\n\t\tif mid > pos:\n\t\t\thigh = mid\n\t\t\tans = ans * (n - x - big)\n\t\t\tbig += 1\n\t\telse:\n\t\t\tlow = mid + 1\n\t\t\tif mid != pos:\n\t\t\t\tans = ans * (x - 1 - small)\n\t\t\t\tsmall += 1\n\t\tans = ans % mod\n\tused = big + small + 1\n\tleft = n - used\n\tfor i in range(left, 0, -1):\n\t\tans = ans * i\n\t\tans = ans % mod\n\tprint(ans)\n\treturn\nt = 1\nfor i in range(t):\n\tsolve()\n", "import sys\nimport bisect as bi\nimport itertools as it\nimport math as mt\nimport collections as cc\nimport heapq as hp\ninput = sys.stdin.readline\nI = lambda : list(map(int, input().split()))\n\ndef inv(x):\n\tmo = 10 ** 9 + 7\n\treturn pow(x, mo - 2, mo)\nfact = [1]\nifact = [inv(1)]\nfor i in range(1, 10001):\n\tfact.append(fact[-1] * i)\n\tifact.append(inv(fact[-1]))\n\ndef ncr(n, x):\n\tif n < x:\n\t\treturn 0\n\treturn fact[n] * ifact[n - x] * ifact[x] % (10 ** 9 + 7)\n(n, x, p) = I()\nar = []\nl = 0\nr = n\nmod = 10 ** 9 + 7\nwhile l < r:\n\tmid = (l + r) // 2\n\tar.append(mid)\n\tif mid <= p:\n\t\tl = mid + 1\n\telse:\n\t\tr = mid\nxx = 0\nyy = 0\nfor i in ar:\n\tif i > p:\n\t\txx += 1\n\telif i < p:\n\t\tyy += 1\nprint(ncr(x - 1, yy) * ncr(n - x, xx) * fact[xx] * fact[yy] * fact[n - xx - yy - 1] % mod)\n", "MOD = 1000000007\n(n, x, pos) = map(int, input().split())\nL = [-1] * n\nL[pos] = 1\nc0 = 0\nc1 = 0\nlow = 0\nhigh = n\nans = 1\nwhile low < high:\n\tmid = low + high >> 1\n\tif mid < pos:\n\t\tc0 += 1\n\t\tlow = mid + 1\n\telif mid > pos:\n\t\tc1 += 1\n\t\thigh = mid\n\telse:\n\t\tlow = mid + 1\nif c0 >= x or c1 > n - x:\n\tans = 0\nelse:\n\ttt1 = 1\n\tval = x - 1\n\tfor i in range(c0):\n\t\ttt1 = tt1 * val % MOD\n\t\tval = (val - 1) % MOD\n\trem = val\n\ttt2 = 1\n\tval = n - x\n\tfor i in range(c1):\n\t\ttt2 = tt2 * val % MOD\n\t\tval = (val - 1) % MOD\n\trem = (rem + val) % MOD\n\ttt3 = 1\n\tfor i in range(n - c0 - c1 - 1):\n\t\ttt3 = tt3 * rem % MOD\n\t\trem = (rem - 1) % MOD\n\tans = tt1 * tt2 % MOD\n\tans = ans * tt3 % MOD\nprint(ans)\n", "def solve():\n\t(n, x, p) = map(int, input().split())\n\ta = [i for i in range(n)]\n\tleft = 0\n\tright = n\n\tb = []\n\twhile left < right:\n\t\tm = (left + right) // 2\n\t\tb.append(m)\n\t\tif a[m] <= p:\n\t\t\tleft = m + 1\n\t\telse:\n\t\t\tright = m\n\tk = 0\n\tm = 0\n\tfor i in b:\n\t\tk += i > p\n\t\tm += i < p\n\tif n - x - k < 0 or x - 1 - m < 0 or n - k - m - 1 < 0:\n\t\tprint(0)\n\t\treturn\n\tf = [1 for i in range(1001)]\n\tM = 10 ** 9 + 7\n\n\tdef po(d, e=M - 2):\n\t\tr = 1\n\t\twhile e > 0:\n\t\t\tif e % 2:\n\t\t\t\tr = r * d % M\n\t\t\td = d * d % M\n\t\t\te //= 2\n\t\treturn r\n\tfor i in range(1, 1001):\n\t\tf[i] = f[i - 1] * i % M\n\tans = f[n - x] * po(f[n - x - k])\n\tans %= M\n\tans *= f[x - 1] * po(f[x - 1 - m])\n\tans %= M\n\tans *= f[n - k - m - 1]\n\tans %= M\n\tprint(ans)\n\ndef main():\n\tt = 1\n\tfor _ in range(t):\n\t\tsolve()\nmain()\n", "import sys, math\nimport io, os\nfrom bisect import bisect_left as bl, bisect_right as br, insort\nfrom heapq import heapify, heappush, heappop\nfrom collections import defaultdict as dd, deque, Counter\nfrom itertools import permutations, combinations\n\ndef data():\n\treturn sys.stdin.readline().strip()\n\ndef mdata():\n\treturn list(map(int, data().split()))\n\ndef outl(var):\n\tsys.stdout.write(' '.join(map(str, var)) + '\\n')\n\ndef out(var):\n\tsys.stdout.write(str(var) + '\\n')\nINF = 10 ** 9\nmod = int(1000000000.0) + 7\nf = [1]\nfor i in range(1, 1000 + 1):\n\tf.append(f[-1] * i % mod)\n(n, x, pos) = mdata()\ng = s = 0\nleft = 0\nright = n\nwhile left < right:\n\tmid = (left + right) // 2\n\tif mid <= pos:\n\t\ts += 1\n\t\tleft = mid + 1\n\telif mid > pos:\n\t\tg += 1\n\t\tright = mid\ns -= 1\nif x - 1 < s or n - x < g:\n\tout(0)\nelse:\n\tans = f[x - 1] * pow(f[x - 1 - s], mod - 2, mod) * f[n - x] * pow(f[n - x - g], mod - 2, mod) * f[n - s - g - 1] % mod\n\tout(ans)\n", "import sys\nreader = (s.rstrip() for s in sys.stdin)\ninput = reader.__next__\nimport math\n(n, x, pos) = list(map(int, input().split()))\nmod = 10 ** 9 + 7\nans = 1\nleft = 0\nright = n\ncounter = 0\nbigger = n - x\nsmaller = x - 1\nwhile left < right:\n\tmiddle = (left + right) // 2\n\tif middle > pos:\n\t\tif bigger > 0:\n\t\t\tans = ans * bigger % mod\n\t\t\tbigger -= 1\n\t\t\tright = middle\n\t\telse:\n\t\t\tans = 0\n\t\t\tbreak\n\telif middle < pos:\n\t\tif smaller > 0:\n\t\t\tans = ans * smaller % mod\n\t\t\tsmaller -= 1\n\t\t\tleft = middle + 1\n\t\telse:\n\t\t\tans = 0\n\t\t\tbreak\n\telse:\n\t\tleft = middle + 1\n\t\tbreak\nwhile left < right:\n\tmiddle = (left + right) // 2\n\tif middle > pos:\n\t\tif bigger > 0:\n\t\t\tans = ans * bigger % mod\n\t\t\tbigger -= 1\n\t\t\tright = middle\n\t\telse:\n\t\t\tans = 0\n\t\t\tbreak\n\telse:\n\t\tbreak\nif ans == 0:\n\tprint(0)\nelse:\n\tfor i in range(1, bigger + smaller + 1):\n\t\tans = ans * i % mod\n\tprint(ans)\n", "import math\n\ndef xx(n, r):\n\tf = math.factorial\n\treturn f(n) // f(r) // f(n - r)\n(n, x, pos) = map(int, input().split())\nlow = 0\nhigh = 0\nleft = 0\nright = n\nmod = 10 ** 9 + 7\nwhile left < right:\n\tmiddle = (left + right) // 2\n\tif middle <= pos:\n\t\tleft = middle + 1\n\t\tif middle < pos:\n\t\t\tlow += 1\n\telse:\n\t\tright = middle\n\t\thigh += 1\nif low > x - 1 or high > n - x:\n\tprint(0)\nelse:\n\ta = xx(x - 1, low) * math.factorial(low)\n\tb = xx(n - x, high) * math.factorial(high)\n\tc = math.factorial(n - (high + low + 1))\n\tprint(a * b * c % mod)\n", "(n, x, pos) = map(int, input().split())\nans = 1\nm = 10 ** 9 + 7\na = x - 1\nb = n - x\nl = 0\nh = n\nc = 0\nwhile l < h:\n\tmid = (l + h) // 2\n\tc += 1\n\tif pos >= mid:\n\t\tif pos == mid:\n\t\t\tl = mid + 1\n\t\telse:\n\t\t\tans *= a\n\t\t\tans %= m\n\t\t\tl = mid + 1\n\t\t\ta -= 1\n\telse:\n\t\tans *= b\n\t\tans %= m\n\t\th = mid\n\t\tb -= 1\nfor j in range(n - c):\n\tans *= j + 1\n\tans %= m\nif l > 0 and l - 1 == pos:\n\tprint(ans)\nelse:\n\tprint(0)\n", "def nCr(n, r):\n\treturn fact(n) // (fact(r) * fact(n - r))\n\ndef nPr(n, r):\n\treturn fact(n) // fact(n - r)\n\ndef fact(n):\n\tres = 1\n\tfor i in range(2, n + 1):\n\t\tres = res * i\n\treturn res\nmod = 1000000007\n(n, x, pos) = map(int, input().split())\nleft = 0\nright = n\ngr = 0\nsm = 0\nwhile left < right:\n\tmiddle = (left + right) // 2\n\tif middle <= pos:\n\t\tleft = middle + 1\n\t\tgr += 1\n\telif middle > pos:\n\t\tright = middle\n\t\tsm += 1\ngr -= 1\nif gr > x - 1 or sm > n - x:\n\tprint(0)\nelse:\n\tprint(nPr(x - 1, gr) % mod * (nPr(n - x, sm) % mod) * (fact(n - gr - sm - 1) % mod) % mod)\n", "from math import factorial\n\ndef ncr(n, r, p):\n\tnum = den = 1\n\tfor i in range(r):\n\t\tnum = num * (n - i) % p\n\t\tden = den * (i + 1) % p\n\treturn num * pow(den, p - 2, p) % p\n(n, x, pos) = [int(i) for i in input().split()]\nbig = n - x\nsmall = x - 1\nb = 0\ns = 0\nl = 0\nr = n\ncurr = -1\nwhile l < r:\n\tcurr = (l + r) // 2\n\tif pos < curr:\n\t\tb += 1\n\t\tr = curr\n\t\tcurr = (l + r) // 2\n\telif pos > curr:\n\t\ts += 1\n\t\tl = curr + 1\n\t\tcurr = (l + r) // 2\n\telse:\n\t\tl = curr + 1\nans = 1\nmod = 10 ** 9 + 7\nif s != 0:\n\tcs = ncr(small, s, mod)\n\tcs *= factorial(s)\n\tcs %= mod\n\tans *= cs\nif b != 0:\n\tcb = ncr(big, b, mod)\n\tcb *= factorial(b)\n\tcb %= mod\n\tans *= cb\n\tans %= mod\nsmall -= s\nbig -= b\nmf = 1\nfor i in range(1, small + big + 1):\n\tmf *= i\n\tmf %= mod\nans *= mf\nans %= mod\nprint(ans)\n", "(n, x, pos) = map(int, input().split())\nl = 0\nr = n\nsub = n - x\npro = 1\nsmall = x - 1\ncnt = 0\nwhile l < r:\n\tmid = (l + r) // 2\n\tif mid > pos:\n\t\tpro = pro * sub\n\t\tsub -= 1\n\t\tr = mid\n\t\tcnt += 1\n\telif mid < pos:\n\t\tl = mid + 1\n\t\tpro *= small\n\t\tsmall -= 1\n\t\tcnt += 1\n\telse:\n\t\tl = mid + 1\n\t\tcnt += 1\nfor i in range(2, n - cnt + 1):\n\tpro = pro * i % 1000000007\nprint(pro)\n", "from sys import stdin\ninput = stdin.readline\n\ndef A():\n\tt = int(input())\n\tfor __ in range(t):\n\t\t(n, m) = map(int, input().split())\n\t\ta = list(map(int, input().split()))\n\t\tif sum(a) == m:\n\t\t\tprint('YES')\n\t\telse:\n\t\t\tprint('NO')\n\ndef B():\n\tt = int(input())\n\tfor __ in range(t):\n\t\tn = int(input())\n\t\tx = [[0 for j in range(n)] for i in range(n)]\n\t\tfor i in range(n // 2):\n\t\t\tx[i][i] = 1\n\t\t\tx[i][n - 1 - i] = 1\n\t\t\tx[n - 1 - i][i] = 1\n\t\t\tx[n - 1 - i][n - 1 - i] = 1\n\t\tif n % 2 == 1:\n\t\t\tx[n // 2 - 1][n // 2] = 1\n\t\t\tx[n // 2 + 1][n // 2] = 1\n\t\t\tx[n // 2][n // 2 + 1] = 1\n\t\t\tx[n // 2][n // 2 - 1] = 1\n\t\tfor i in range(n):\n\t\t\tprint(*x[i])\n\ndef C():\n\t(n, x, pos) = map(int, input().split())\n\tnumLess = x - 1\n\tnumMore = n - x\n\tnume = 1\n\tdenom = 1\n\tleft = 0\n\tright = n\n\tmod = pow(10, 9) + 7\n\twhile left < right:\n\t\tmid = (left + right) // 2\n\t\tif mid < pos:\n\t\t\tnume *= numLess\n\t\t\tdenom *= numLess + numMore\n\t\t\tnumLess -= 1\n\t\t\tleft = mid + 1\n\t\telif mid > pos:\n\t\t\tnume *= numMore\n\t\t\tdenom *= numLess + numMore\n\t\t\tnumMore -= 1\n\t\t\tright = mid\n\t\telse:\n\t\t\tleft = mid + 1\n\t\tnume %= mod\n\t\tdenom %= mod\n\tfact = 1\n\tfor i in range(2, n):\n\t\tfact *= i\n\t\tfact %= mod\n\tfract = nume * pow(denom, mod - 2, mod) % mod\n\tprint(fract * fact % mod)\n\ndef D():\n\tt = int(input())\n\tfor __ in range(t):\n\t\t_ = 0\nC()\n", "import sys\ninput = sys.stdin.readline\nI = lambda : list(map(int, input().split()))\n\ndef ncr(n, r, p=10 ** 9 + 7):\n\tif n < r:\n\t\treturn 0\n\tnum = 1\n\tr = min(r, n - r)\n\tct = 1\n\twhile ct <= r:\n\t\tnum = num * n % p\n\t\tnum = num * pow(ct, p - 2, p) % p\n\t\tct += 1\n\t\tn -= 1\n\treturn num % p\n(n, x, pos) = I()\nmd = 10 ** 9 + 7\nft = [1, 1, 2]\nfor i in range(3, 1003):\n\tft.append(ft[-1] * i % md)\nan = 0\nar = []\nlo = 0\nri = n\nwhile lo < ri:\n\tmd = (lo + ri) // 2\n\tar.append(md)\n\tif md <= pos:\n\t\tlo = md + 1\n\telse:\n\t\tri = md\nmd = 10 ** 9 + 7\na = b = 0\nfor i in ar:\n\tif i > pos:\n\t\ta += 1\n\telif i < pos:\n\t\tb += 1\nprint(ncr(x - 1, b) * ncr(n - x, a) * ft[a] * ft[b] * ft[n - a - b - 1] % md)\n", "import sys\ninput = sys.stdin.readline\n(n, x, pos) = map(int, input().split())\npos += 1\nmod = 1000000007\nsmaller = 0\nbigger = 0\nleft = 0\nright = n\nwhile left < right:\n\tmiddle = (left + right) // 2\n\tif middle < pos:\n\t\tleft = middle + 1\n\t\tif middle < pos - 1:\n\t\t\tsmaller += 1\n\telse:\n\t\tbigger += 1\n\t\tright = middle\nposs = True\nif smaller >= x:\n\tposs = False\nif bigger > n - x:\n\tposs = False\nif poss:\n\tsol = 1\n\tnum = x - 1\n\tfor i in range(smaller):\n\t\tsol *= num\n\t\tsol %= mod\n\t\tnum -= 1\n\tnum2 = n - x\n\tfor i in range(bigger):\n\t\tsol *= num2\n\t\tsol %= mod\n\t\tnum2 -= 1\n\tnum += num2\n\twhile num > 0:\n\t\tsol *= num\n\t\tsol %= mod\n\t\tnum -= 1\n\tprint(sol)\nelse:\n\tprint(0)\n", "import sys\nimport math\nimport bisect\nfrom sys import stdin, stdout\nfrom math import gcd, floor, sqrt, log2, ceil\nfrom collections import defaultdict as dd\nfrom bisect import bisect_left as bl, bisect_right as br\nfrom bisect import insort\nfrom collections import Counter\nfrom collections import deque\nfrom heapq import heappush, heappop, heapify\nfrom itertools import permutations, combinations\nmod = int(1000000000.0) + 7\nip = lambda : int(stdin.readline())\ninp = lambda : map(int, stdin.readline().split())\nips = lambda : stdin.readline().rstrip()\nout = lambda x: stdout.write(str(x) + '\\n')\n\ndef bin(a, x):\n\tl = 0\n\tr = len(a)\n\twhile l < r:\n\t\tprint(l, r)\n\t\tmid = (l + r) // 2\n\t\tif a[mid] <= x:\n\t\t\tl = mid + 1\n\t\telse:\n\t\t\tr = mid\n\tif l > 0 and a[l - 1] == x:\n\t\treturn True\n\telse:\n\t\treturn False\nt = 1\nfor _ in range(t):\n\t(n, x, pos) = inp()\n\tele_less = x - 1\n\tele_great = n - x\n\tl = 0\n\tr = n\n\tans = 1\n\twhile l < r:\n\t\tmid = (l + r) // 2\n\t\tif pos < mid:\n\t\t\tans *= ele_great\n\t\t\tans %= mod\n\t\t\tele_great -= 1\n\t\t\tr = mid\n\t\telif pos == mid:\n\t\t\tl = mid + 1\n\t\telse:\n\t\t\tans *= ele_less\n\t\t\tans %= mod\n\t\t\tele_less -= 1\n\t\t\tl = mid + 1\n\trem = ele_less + ele_great\n\twhile rem > 0:\n\t\tans = ans * rem\n\t\tans %= mod\n\t\trem -= 1\n\tout(ans)\n", "def f(n):\n\ts = 1\n\tfor i in range(1, n + 1):\n\t\ts *= i\n\t\ts %= 10 ** 9 + 7\n\treturn s\n(n, x, pos) = map(int, input().split())\nlow = x - 1\nup = n - x\nmid = 1\nl = 0\nr = n\nvar = 1\nwhile l < r:\n\tm = (l + r) // 2\n\tif m < pos:\n\t\tvar *= low\n\t\tvar %= 10 ** 9 + 7\n\t\tlow -= 1\n\t\tl = m + 1\n\telif m == pos:\n\t\tmid -= 1\n\t\tl = m + 1\n\telse:\n\t\tvar *= up\n\t\tvar %= 10 ** 9 + 7\n\t\tup -= 1\n\t\tr = m\nif low >= 0 and up >= 0 and (mid >= 0):\n\tprint(var * f(up + low) % (10 ** 9 + 7))\nelse:\n\tprint(0)\n", "(n, X, pos) = [int(x) for x in input().split(' ')]\na = [i for i in range(n)]\nx = pos\nsmaller = 0\nlarger = 0\npositions_checked = set()\nleft = 0\nright = len(a)\nmiddle = None\nwhile left < right:\n\tif (left + right) % 2 == 0:\n\t\tmiddle = round((left + right) / 2)\n\telse:\n\t\tmiddle = int((left + right) / 2)\n\tpositions_checked.add(middle)\n\tif a[middle] <= x:\n\t\tif middle != pos:\n\t\t\tsmaller += 1\n\t\tleft = middle + 1\n\telse:\n\t\tlarger += 1\n\t\tright = middle\nif left > 0 and a[left - 1] == x:\n\tans = True\nelse:\n\tans = False\n\ndef ncr(n, r, p):\n\tnum = den = 1\n\tfor i in range(r):\n\t\tnum = num * (n - i) % p\n\t\tden = den * (i + 1) % p\n\treturn num * pow(den, p - 2, p) % p\n\ndef fact(n, p):\n\tq = 1\n\ti = 1\n\twhile i <= n:\n\t\tq *= i\n\t\tq %= p\n\t\ti += 1\n\treturn q\nactual_larger = n - X\nactual_smaller = X - 1\nmod = 1000000007\nif actual_smaller < smaller:\n\tprint(0)\nelif actual_larger < larger:\n\tprint(0)\nelse:\n\ta1 = ncr(actual_larger, larger, mod) % mod\n\ta2 = ncr(actual_smaller, smaller, mod) % mod\n\ta3 = fact(n - len(positions_checked), mod) % mod\n\ta4 = fact(larger, mod) % mod\n\ta5 = fact(smaller, mod) % mod\n\tprint(a1 * a2 % mod * a3 % mod * a4 % mod * a5 % mod)\n", "import math\nmod = 10 ** 9 + 7\n(n, x, pos) = [int(x) for x in input().split()]\nl = 0\nr = n\ngrtVal = n - x\nsmlVal = x - 1\ncnt = n\nans = 1\nwhile l < r:\n\tmid = int((l + r) / 2)\n\tif mid == pos:\n\t\tl = mid + 1\n\telif mid < pos:\n\t\tans = ans * smlVal % mod\n\t\tsmlVal -= 1\n\t\tl = mid + 1\n\telse:\n\t\tans = ans * grtVal % mod\n\t\tgrtVal -= 1\n\t\tr = mid\n\tcnt -= 1\nif cnt > 0:\n\tans = ans * math.factorial(cnt) % mod\nprint(ans)\n", "import sys\n\ndef minp():\n\treturn sys.stdin.readline().strip()\n\ndef mint():\n\treturn int(minp())\n\ndef mints():\n\treturn map(int, minp().split())\n\ndef BinarySearch(a, x):\n\tleft = 0\n\tright = len(a)\n\twhile left < right:\n\t\tmiddle = (left + right) // 2\n\t\tif a[middle] <= x:\n\t\t\tleft = middle + 1\n\t\telse:\n\t\t\tright = middle\n\tif left > 0 and a[left - 1] == x:\n\t\treturn True\n\telse:\n\t\treturn False\n\ndef stupid(pos, a, x, was, ppos):\n\tif pos == len(a):\n\t\tif a[ppos] != x:\n\t\t\treturn 0\n\t\treturn int(BinarySearch(a, x))\n\tres = 0\n\tfor i in range(1, len(a) + 1):\n\t\tif not was[i]:\n\t\t\twas[i] = True\n\t\t\ta[pos] = i\n\t\t\tres += stupid(pos + 1, a, x, was, ppos)\n\t\t\twas[i] = False\n\treturn res\n\ndef stupid1(n, x, pos):\n\treturn stupid(0, [0] * n, x, [False] * (n + 1), pos)\n\ndef BinarySearch1(left, right, ppos):\n\tres = []\n\tif left < right:\n\t\tmiddle = (left + right) // 2\n\t\tres = []\n\t\tfor ans in BinarySearch1(middle + 1, right, ppos):\n\t\t\tres.append([(1, middle)] + ans)\n\t\tfor ans in BinarySearch1(left, middle, ppos):\n\t\t\tres.append([(2, middle)] + ans)\n\t\treturn res\n\telif left == ppos + 1:\n\t\treturn [[]]\n\telse:\n\t\treturn []\n\ndef stupid2(pos, a, x, was, ppos, cc):\n\tif pos == len(a):\n\t\tif a[ppos] != x:\n\t\t\treturn 0\n\t\tfor (s, p) in cc:\n\t\t\tif s == 1 and a[p] > x or (s == 2 and a[p] <= x):\n\t\t\t\treturn 0\n\t\t\treturn 1\n\tres = 0\n\tfor i in range(1, len(a) + 1):\n\t\tif not was[i]:\n\t\t\twas[i] = True\n\t\t\ta[pos] = i\n\t\t\tres += stupid(pos + 1, a, x, was, ppos)\n\t\t\twas[i] = False\n\treturn res\n\ndef solve():\n\t(n, x, pos) = mints()\n\tqw = BinarySearch1(0, n, pos)\n\tc = [0, 0]\n\tfor (s, p) in qw[0]:\n\t\tif p == pos:\n\t\t\tif s == 2:\n\t\t\t\tprint(0)\n\t\t\t\treturn\n\t\telse:\n\t\t\tc[s - 1] += 1\n\tabove = n - x\n\tbelow = x - 1\n\tif c[0] > below or c[1] > above:\n\t\tprint(0)\n\t\treturn\n\tMOD = int(1000000000.0 + 7)\n\tres = 1\n\tk = n - 1\n\tfor i in range(c[0]):\n\t\tk -= 1\n\t\tres = res * (below - i) % MOD\n\tfor i in range(c[1]):\n\t\tk -= 1\n\t\tres = res * (above - i) % MOD\n\tfor i in range(1, k + 1):\n\t\tres = res * i % MOD\n\tprint(res)\nsolve()\n", "mod = 10 ** 9 + 7\n(n, x, pos) = map(int, input().split())\n(left, right) = (0, n)\nr = 1\nz = 0\n(p, q) = (x - 1, n - x)\nwhile left < right:\n\tmid = (left + right) // 2\n\tz += 1\n\tif pos == mid:\n\t\tleft = mid + 1\n\telif pos < mid:\n\t\tright = mid\n\t\tr *= q\n\t\tq -= 1\n\telse:\n\t\tleft = mid + 1\n\t\tr *= p\n\t\tp -= 1\nfor i in range(2, n - z + 1):\n\tr = r * i % mod\nprint(r)\n", "import math\nfrom math import factorial\np = int(1000000000.0 + 7)\n\ndef ncr(n, r, p):\n\tnum = den = 1\n\tfor i in range(r):\n\t\tnum = num * (n - i) % p\n\t\tden = den * (i + 1) % p\n\treturn max(num * pow(den, p - 2, p) % p, 0)\n(n, x, pos) = map(int, input().split())\n(l, r) = (0, n)\n(cs, cb) = (0, 0)\nwhile l < r:\n\tm = (l + r) // 2\n\tif m < pos:\n\t\tcs += 1\n\tif m > pos:\n\t\tcb += 1\n\tif m <= pos:\n\t\tl = m + 1\n\telse:\n\t\tr = m\nans = ncr(x - 1, cs, p) * ncr(n - x, cb, p) % p * factorial(n - cs - cb - 1) % p * factorial(cs) % p * factorial(cb) % p\nprint(ans)\n", "modulo = 10 ** 9 + 7\n(n, x, pos) = map(int, input().split())\nbigger = 0\nsmaller = 0\n(l, r) = (0, n)\nwhile l < r:\n\tmid = (l + r) // 2\n\tif mid > pos:\n\t\tr = mid\n\t\tbigger += 1\n\telif mid < pos:\n\t\tl = mid + 1\n\t\tsmaller += 1\n\telse:\n\t\tl = mid + 1\nres = 1\nfor i in range(smaller):\n\tres *= x - 1 - i\n\tres %= modulo\nfor i in range(bigger):\n\tres *= n - x - i\n\tres %= modulo\nfor i in range(n - bigger - smaller - 1):\n\tres *= i + 1\n\tres %= modulo\nprint(res)\n", "import math\n\ndef ncr(a, b):\n\tif a < b or a < 0 or b < 0:\n\t\treturn 0\n\tc = math.factorial(a) // math.factorial(a - b)\n\tc = int(c)\n\treturn c % 1000000007\n\ndef bs(n, x):\n\tleft = 0\n\tright = n\n\t(c1, c2) = (0, 0)\n\twhile left < right:\n\t\tmid = (left + right) // 2\n\t\tif mid <= x:\n\t\t\tif mid != x:\n\t\t\t\tc1 += 1\n\t\t\tleft = mid + 1\n\t\telse:\n\t\t\tc2 += 1\n\t\t\tright = mid\n\treturn (c1, c2)\n(n, x, pos) = map(int, input().split())\n(c1, c2) = bs(n, pos)\nb = n - x\nx -= 1\nd = ncr(x, c1)\ne = ncr(b, c2)\na = int(math.factorial(n - c1 - c2 - 1))\nm = 1000000007\nprint(a % m * d % m * e % m % m)\n", "def solve():\n\t(n, x, pos) = map(int, input().split())\n\tl = 0\n\tr = n\n\tsmaller = 0\n\tlarger = 0\n\twhile l < r:\n\t\tm = (l + r) // 2\n\t\tif m < pos:\n\t\t\tsmaller += 1\n\t\t\tl = m + 1\n\t\telif m > pos:\n\t\t\tlarger += 1\n\t\t\tr = m\n\t\telse:\n\t\t\tl = m + 1\n\tif smaller >= x or larger > n - x:\n\t\tprint(0)\n\telse:\n\t\tmod = int(1000000000.0 + 7)\n\n\t\tdef fact(n):\n\t\t\tres = 1\n\t\t\tfor i in range(1, n + 1):\n\t\t\t\tres = res * i % mod\n\t\t\treturn res\n\n\t\tdef p(n, r):\n\t\t\tres = 1\n\t\t\tfor i in range(n - r + 1, n + 1):\n\t\t\t\tres = res * i % mod\n\t\t\treturn res\n\t\tprint(p(x - 1, smaller) * p(n - x, larger) * fact(n - larger - smaller - 1) % mod)\nsolve()\n", "import math\nmod = 10 ** 9 + 7\n\ndef ncr(n, r):\n\tp = 1\n\tk = 1\n\tif n - r < r:\n\t\tr = n - r\n\tif r != 0:\n\t\twhile r:\n\t\t\tp *= n\n\t\t\tk *= r\n\t\t\tm = math.gcd(p, k)\n\t\t\tp //= m\n\t\t\tk //= m\n\t\t\tn -= 1\n\t\t\tr -= 1\n\telse:\n\t\tp = 1\n\treturn p\n(n, x, pos) = map(int, input().split())\nindexesToBeCheckedLeft = 0\nindexesToBeCheckedRight = 0\nleft = 0\nright = n\nmiddle = -1\nwhile left < right:\n\tmiddle = (left + right) // 2\n\tif middle <= pos:\n\t\tindexesToBeCheckedLeft += 1\n\t\tleft = middle + 1\n\telif middle > pos:\n\t\tright = middle\n\t\tindexesToBeCheckedRight += 1\nindexesToBeCheckedLeft -= 1\nleftElements = x - 1\nrightElements = n - x\nif leftElements < indexesToBeCheckedLeft or rightElements < indexesToBeCheckedRight:\n\tprint(0)\nelse:\n\twaysOfPickingRight = ncr(rightElements, indexesToBeCheckedRight) % mod\n\twaysOfPickingLeft = ncr(leftElements, indexesToBeCheckedLeft) % mod\n\tshuffleLeft = math.factorial(indexesToBeCheckedLeft)\n\tshuffleRight = math.factorial(indexesToBeCheckedRight)\n\tans = waysOfPickingLeft * waysOfPickingRight % mod\n\tans = ans * shuffleLeft % mod\n\tans = ans * shuffleRight % mod\n\trest = n - indexesToBeCheckedLeft - indexesToBeCheckedRight - 1\n\tfor i in range(2, rest + 1):\n\t\tans = ans * i % mod\n\tprint(ans)\n", "import os\nimport sys\nfrom io import BytesIO, IOBase\nimport math\n\ndef main():\n\tpass\nBUFSIZE = 8192\n\nclass FastIO(IOBase):\n\tnewlines = 0\n\n\tdef __init__(self, file):\n\t\tself._fd = file.fileno()\n\t\tself.buffer = BytesIO()\n\t\tself.writable = 'x' in file.mode or 'r' not in file.mode\n\t\tself.write = self.buffer.write if self.writable else None\n\n\tdef read(self):\n\t\twhile True:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tif not b:\n\t\t\t\tbreak\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines = 0\n\t\treturn self.buffer.read()\n\n\tdef readline(self):\n\t\twhile self.newlines == 0:\n\t\t\tb = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n\t\t\tself.newlines = b.count(b'\\n') + (not b)\n\t\t\tptr = self.buffer.tell()\n\t\t\t(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))\n\t\tself.newlines -= 1\n\t\treturn self.buffer.readline()\n\n\tdef flush(self):\n\t\tif self.writable:\n\t\t\tos.write(self._fd, self.buffer.getvalue())\n\t\t\t(self.buffer.truncate(0), self.buffer.seek(0))\n\nclass IOWrapper(IOBase):\n\n\tdef __init__(self, file):\n\t\tself.buffer = FastIO(file)\n\t\tself.flush = self.buffer.flush\n\t\tself.writable = self.buffer.writable\n\t\tself.write = lambda s: self.buffer.write(s.encode('ascii'))\n\t\tself.read = lambda : self.buffer.read().decode('ascii')\n\t\tself.readline = lambda : self.buffer.readline().decode('ascii')\n(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))\ninput = lambda : sys.stdin.readline().rstrip('\\r\\n')\n\ndef binary(n):\n\treturn bin(n).replace('0b', '')\n\ndef decimal(s):\n\treturn int(s, 2)\n\ndef pow2(n):\n\tp = 0\n\twhile n > 1:\n\t\tn //= 2\n\t\tp += 1\n\treturn p\n\ndef primeFactors(n):\n\tl = []\n\twhile n % 2 == 0:\n\t\tl.append(2)\n\t\tn = n / 2\n\tfor i in range(3, int(math.sqrt(n)) + 1, 2):\n\t\twhile n % i == 0:\n\t\t\tl.append(i)\n\t\t\tn = n / i\n\tif n > 2:\n\t\tl.append(int(n))\n\treturn l\n\ndef isPrime(n):\n\tif n == 1:\n\t\treturn False\n\telse:\n\t\troot = int(n ** 0.5)\n\t\troot += 1\n\t\tfor i in range(2, root):\n\t\t\tif n % i == 0:\n\t\t\t\treturn False\n\t\treturn True\n\ndef maxPrimeFactors(n):\n\tmaxPrime = -1\n\twhile n % 2 == 0:\n\t\tmaxPrime = 2\n\t\tn >>= 1\n\tfor i in range(3, int(math.sqrt(n)) + 1, 2):\n\t\twhile n % i == 0:\n\t\t\tmaxPrime = i\n\t\t\tn = n / i\n\tif n > 2:\n\t\tmaxPrime = n\n\treturn int(maxPrime)\n\ndef countcon(s, i):\n\tc = 0\n\tch = s[i]\n\tfor i in range(i, len(s)):\n\t\tif s[i] == ch:\n\t\t\tc += 1\n\t\telse:\n\t\t\tbreak\n\treturn c\n\ndef fact(n):\n\tm = 1000000007\n\tf = 1\n\tif n == 0:\n\t\treturn 1\n\telse:\n\t\tfor i in range(1, n + 1):\n\t\t\tf = f * i\n\t\t\tf %= m\n\t\treturn int(f)\n(n, x, pos) = map(int, input().split())\nl = 0\nr = n\nless = 0\nmore = 0\nmod = 1000000007\ntm = n - x\ntl = x - 1\nlt = mt = 1\nwhile l < r:\n\tmid = (l + r) // 2\n\tif mid < pos:\n\t\tl = mid + 1\n\t\tlt *= tl\n\t\tlt %= mod\n\t\ttl -= 1\n\telif mid > pos:\n\t\tr = mid\n\t\tmt *= tm\n\t\tmt %= mod\n\t\ttm -= 1\n\telse:\n\t\tl = mid + 1\nt1 = fact(tm + tl)\nprint(t1 * mt * lt % mod)\n", "from math import comb, factorial\nmod = 10 ** 9 + 7\n(n, x, pos) = map(int, input().split())\nlt = 0\ngt = 0\nleft = 0\nright = n\nwhile left < right:\n\tmiddle = (left + right) // 2\n\tif middle <= pos:\n\t\tif middle < pos:\n\t\t\tlt += 1\n\t\tleft = middle + 1\n\telse:\n\t\tgt += 1\n\t\tright = middle\nrem = factorial(n - 1 - lt - gt) % mod\nlt = comb(x - 1, lt) % mod * factorial(lt)\ngt = comb(n - x, gt) % mod * factorial(gt)\nprint(lt * gt % mod * rem % mod)\n", "def A(k, n):\n\tans = 1\n\tif k >= 1:\n\t\tfor i in range(n - k + 1, n + 1):\n\t\t\tans *= i\n\treturn ans\n\ndef f(n):\n\tans = 1\n\tfor i in range(n):\n\t\tans *= i + 1\n\treturn ans\n\ndef solve(n, x, pos):\n\tcntBig = 0\n\tcntLess = 0\n\tleft = 0\n\tright = n\n\tans = 1\n\tmod = 1000000007\n\twhile left < right:\n\t\tmid = (left + right) // 2\n\t\tif mid < pos:\n\t\t\tleft = mid + 1\n\t\t\tans *= x - 1 - cntLess\n\t\t\tans % mod\n\t\t\tcntLess += 1\n\t\telif mid > pos:\n\t\t\tright = mid\n\t\t\tans *= n - x - cntBig\n\t\t\tcntBig += 1\n\t\telse:\n\t\t\tleft = mid + 1\n\tans *= f(n - cntLess - cntBig - 1)\n\tprint(ans % mod)\n(n, x, pos) = map(int, input().split())\nsolve(n, x, pos)\n", "from sys import stdin, exit\nfrom bisect import bisect_left as bl, bisect_right as br\ninput = lambda : stdin.readline()[:-1]\nintput = lambda : int(input())\nsinput = lambda : input().split()\nintsput = lambda : map(int, sinput())\n\ndef dprint(*args, **kwargs):\n\tif debugging:\n\t\tprint(*args, **kwargs)\nmod = 10 ** 9 + 7\ndebugging = 1\n(n, x, pos) = intsput()\n(l, r) = (0, 0)\nleft = 0\nright = n\nwhile left < right:\n\tmiddle = (left + right) // 2\n\tif middle <= pos:\n\t\tleft = middle + 1\n\t\tif middle < pos:\n\t\t\tl += 1\n\telse:\n\t\tright = middle\n\t\tr += 1\n\ndef modfact(k):\n\tr = 1\n\tfor i in range(1, k + 1):\n\t\tr *= i\n\t\tr %= mod\n\treturn r\nans = 1\nif x - 1 - l < 0:\n\tprint(0)\n\texit()\nif n - x - r < 0:\n\tprint(0)\n\texit()\nfor i in range(x - 1, x - 1 - l, -1):\n\tans *= i\n\tans %= mod\nfor i in range(n - x, n - x - r, -1):\n\tans *= i\n\tans %= mod\nans *= modfact(n - 1 - l - r)\nans %= mod\nprint(ans)\n", "from sys import stdin, stdout\nfrom math import gcd, sqrt, factorial, pi, inf\nfrom collections import deque, defaultdict\ninput = stdin.readline\nR = lambda : map(int, input().split())\nI = lambda : int(input())\nS = lambda : input().rstrip('\\n')\nL = lambda : list(R())\nP = lambda x: stdout.write(str(x) + '\\n')\nlcm = lambda x, y: x * y // gcd(x, y)\nhg = lambda x, y: (y + x - 1) // x * x\npw = lambda x: 1 if x == 1 else 1 + pw(x // 2)\nchk = lambda x: chk(x // 2) if not x % 2 else True if x == 1 else False\nsm = lambda x: (x ** 2 + x) // 2\nN = 10 ** 9 + 7\n\ndef combi(n, r):\n\treturn n * factorial(r) % N\n\ndef solve(n, r):\n\treturn combi(factorial(n) // (factorial(r) * factorial(n - r)) % N, r)\n(n, x, p) = R()\na = [-1] * n\nl = 0\nr = n\ncnt = 0\ncnt1 = 0\nans = 1\nwhile l < r:\n\tm = (l + r) // 2\n\tif m < p:\n\t\ta[m] = 0\n\t\tl = m + 1\n\t\tans *= x - 1 - cnt\n\t\tans %= N\n\t\tcnt += 1\n\telif m > p:\n\t\ta[m] = 1\n\t\tr = m\n\t\tans *= n - x - cnt1\n\t\tans %= N\n\t\tcnt1 += 1\n\telse:\n\t\tl = m + 1\nfor i in range(1, n - cnt - cnt1):\n\tans *= i\n\tans %= N\nprint(ans)\n", "mod = 10 ** 9 + 7\n\ndef modExp(a, n, m=10 ** 9 + 7):\n\tif n == 0:\n\t\treturn 1\n\telif n == 1:\n\t\treturn a\n\telse:\n\t\twhile n >= 2:\n\t\t\tif n % 2 == 0:\n\t\t\t\tn = n // 2\n\t\t\t\treturn modExp(a % m * (a % m) % m, n, m)\n\t\t\telse:\n\t\t\t\tn = (n - 1) // 2\n\t\t\t\treturn a % m * modExp(a % m * (a % m) % m, n, m) % m % m\n\ndef nCr(n, r):\n\treturn dic[n] * modExp(dic[n - r] * dic[r] % mod, mod - 2) % mod\n(n, x, p) = map(int, input().split())\ndic = {0: 1}\nfor i in range(1, 1001):\n\tdic[i] = dic[i - 1] * i\n\tdic[i] %= mod\n\ndef binS(n, p):\n\tl = 0\n\tr = n\n\tg = 0\n\ts = 0\n\twhile l < r:\n\t\tm = (l + r) // 2\n\t\tif m > p:\n\t\t\tr = m\n\t\t\tg += 1\n\t\telse:\n\t\t\tif m != p:\n\t\t\t\ts += 1\n\t\t\tl = m + 1\n\treturn (s, g)\n(s, g) = binS(n, p)\nif n - x < g or x - 1 < s:\n\tprint(0)\nelse:\n\tout = nCr(n - x, g) * dic[g] % mod\n\tout *= nCr(x - 1, s) * dic[s] % mod\n\tout %= mod\n\tout *= dic[n - g - s - 1]\n\tout %= mod\n\tprint(out)\n"]

difficulty: MEDIUM

source: codeforces

raw_problem:
C. Binary Search

time limit per test
1 second

memory limit per test
256 megabytes

input
standard input

output
standard output

Andrey thinks he is truly a successful developer, but in reality he didn't know about the binary search algorithm until recently. After reading some literature Andrey understood that this algorithm allows to quickly find a certain number $$$x$$$ in an array. For an array $$$a$$$ indexed from zero, and an integer $$$x$$$ the pseudocode of the algorithm is as follows:

Note that the elements of the array are indexed from zero, and the division is done in integers (rounding down).

Andrey read that the algorithm only works if the array is sorted. However, he found this statement untrue, because there certainly exist unsorted arrays for which the algorithm find $$$x$$$!

Andrey wants to write a letter to the book authors, but before doing that he must consider the permutations of size $$$n$$$ such that the algorithm finds $$$x$$$ in them. A permutation of size $$$n$$$ is an array consisting of $$$n$$$ distinct integers between $$$1$$$ and $$$n$$$ in arbitrary order.

Help Andrey and find the number of permutations of size $$$n$$$ which contain $$$x$$$ at position $$$pos$$$ and for which the given implementation of the binary search algorithm finds $$$x$$$ (returns true). As the result may be extremely large, print the remainder of its division by $$$10^9+7$$$.

Input

The only line of input contains integers $$$n$$$, $$$x$$$ and $$$pos$$$ ($$$1 \le x \le n \le 1000$$$, $$$0 \le pos \le n - 1$$$) — the required length of the permutation, the number to search, and the required position of that number, respectively.

Output

Print a single number — the remainder of the division of the number of valid permutations by $$$10^9+7$$$.

Examples

Input

4 1 2

Output

6

Input

123 42 24

Output

824071958

Note

All possible permutations in the first test case: $$$(2, 3, 1, 4)$$$, $$$(2, 4, 1, 3)$$$, $$$(3, 2, 1, 4)$$$, $$$(3, 4, 1, 2)$$$, $$$(4, 2, 1, 3)$$$, $$$(4, 3, 1, 2)$$$.

question:
Andrey thinks he is truly a successful developer, but in reality he didn't know about the binary search algorithm until recently. After reading some literature Andrey understood that this algorithm allows to quickly find a certain number $$$x$$$ in an array. For an array $$$a$$$ indexed from zero, and an integer $$$x$$$ the pseudocode of the algorithm is as follows:
 ![image](1.png) Note that the elements of the array are indexed from zero, and the division is done in integers (rounding down).
Andrey read that the algorithm only works if the array is sorted. However, he found this statement untrue, because there certainly exist unsorted arrays for which the algorithm find $$$x$$$!
Andrey wants to write a letter to the book authors, but before doing that he must consider the permutations of size $$$n$$$ such that the algorithm finds $$$x$$$ in them. A permutation of size $$$n$$$ is an array consisting of $$$n$$$ distinct integers between $$$1$$$ and $$$n$$$ in arbitrary order.
Help Andrey and find the number of permutations of size $$$n$$$ which contain $$$x$$$ at position $$$pos$$$ and for which the given implementation of the binary search algorithm finds $$$x$$$ (returns true). As the result may be extremely large, print the remainder of its division by $$$10^9+7$$$.

Input
The only line of input contains integers $$$n$$$, $$$x$$$ and $$$pos$$$ ($$$1 \le x \le n \le 1000$$$, $$$0 \le pos \le n - 1$$$) — the required length of the permutation, the number to search, and the required position of that number, respectively.

Output
Print a single number — the remainder of the division of the number of valid permutations by $$$10^9+7$$$.

Examples
Input
4 1 2

Output
6

Input
123 42 24

Output
824071958

Note
All possible permutations in the first test case: $$$(2, 3, 1, 4)$$$, $$$(2, 4, 1, 3)$$$, $$$(3, 2, 1, 4)$$$, $$$(3, 4, 1, 2)$$$, $$$(4, 2, 1, 3)$$$, $$$(4, 3, 1, 2)$$$.

skill_types: ['Sorting']

data_split: test