Given a number n, find count of all binary sequences of length 2n such that sum of first n bits is same as sum of last n bits.
The anwer can be very large. So, you have to return answer modulo 10^{9}+7.
Example:
Input: n = 2
Output: 6
Explanation: There are 6 sequences of length 
2*n, the sequences are 0101, 0110, 1010, 1001, 
0000 and 1111.
Example:
Input: n = 1
Output: 2
Explanation: There are 2 sequence of length 
2*n, the sequence are 00 and 11.
 
Your Task:
You don't need to read or print anyhting. Your task is to complete the function compute_value() which takes n as input parameter and returns count of all binary sequence of length 2*n such that sum of first n bits is same as sum of last n bits modulo 10^{9} + 7.
 
Expected Time Complexity: O(n * log(n))
Expected Space Complexity:  O(1)
 
Constraints:
1 <= n <= 10^{5}

Source: geeksforgeeks | Difficulty: MEDIUM

Starter code: #User function Template for python3



class Solution:

	def compute_value(self, n):

		# Code here

Solutions:
import math

class Solution:

	def compute_value(self, n):
		mod = 10 ** 9 + 7
		a = math.factorial(2 * n)
		b = math.factorial(n)
		return a // b ** 2 % mod


import math

class Solution:

	def compute_value(self, n):
		mod = 1000000007
		a = math.factorial(2 * n)
		b = math.factorial(n)
		return a // b ** 2 % mod


import math

class Solution:

	def compute_value(self, n):
		t = math.factorial(n)
		return math.factorial(2 * n) // t // t % (10 ** 9 + 7)


class Solution:

	def compute_value(self, n):
		mod = 10 ** 9 + 7
		if n == 1:
			return 2
		val = 2
		for i in range(1, n):
			val = val * (2 * i + 1) * 2 % mod
			x = pow(i + 1, mod - 2, mod)
			val = val * x % mod
		return val


import math

class Solution:

	def compute_value(self, n):
		count1 = math.factorial(2 * n)
		count2 = math.factorial(n)
		count3 = count2 ** 2
		ans = count1 // count3
		return ans % (10 ** 9 + 7)


import math

class Solution:
	mod = 10 ** 9 + 7

	def euclidean(self, mod, r, x_y_list):
		if r == 0:
			x_y_list[0] = 1
			x_y_list[1] = 0
			return (x_y_list[0], x_y_list[1])
		(x1, y1) = self.euclidean(r, mod % r, x_y_list)
		x_y_list[0] = y1
		x_y_list[1] = x1 - mod // r * y1
		return (x_y_list[0], x_y_list[1])

	def modinverse(self, mod, r):
		x_y_list = [1, 0]
		(x, y) = self.euclidean(mod, r, x_y_list)
		return y

	def compute_value(self, n):
		res = 2
		ncr = 1
		for r in range(0, n - 1):
			ncr = ncr % self.mod * (n - r) % self.mod % self.mod
			x = self.modinverse(self.mod, r + 1)
			ncr = ncr % self.mod * x % self.mod % self.mod
			res = (res % self.mod + ncr % self.mod * ncr % self.mod % self.mod % self.mod) % self.mod
		return int(res)


from math import factorial as f

class Solution:

	def compute_value(self, n):
		return f(n << 1) // f(n) ** 2 % (10 ** 9 + 7)


import math

class Solution:
	mod = 10 ** 9 + 7

	def modinverse(self, r):
		m0 = self.mod
		y = 1
		x = 0
		M = m0
		if self.mod == 1:
			return 0
		while M > 1:
			q = M // r
			temp = r
			r = M % r
			M = temp
			temp = y
			y = x - q * y
			x = temp
		if x < 0:
			x += m0
		return x

	def compute_value(self, n):
		res = 2
		ncr = 1
		for r in range(0, n - 1):
			ncr = ncr % self.mod * (n - r) % self.mod % self.mod
			x = self.modinverse(r + 1)
			ncr = ncr % self.mod * x % self.mod % self.mod
			res = (res % self.mod + ncr % self.mod * ncr % self.mod % self.mod % self.mod) % self.mod
		return int(res)


import math

class Solution:

	def compute_value(self, n):
		x = math.factorial(n * 2)
		y = math.factorial(n)
		return x // y ** 2 % 1000000007


import math

def verify(x):
	for i in range(2, math.floor(math.sqrt(x))):
		if x % i == 0:
			return False
	return True
M = 1000 * 1000 * 1000 + 7

class Solution:

	def pow1(self, x, y):
		if y == 0:
			return 1
		if y % 2 == 0:
			return self.pow(x, y // 2) ** 2 % M
		return self.pow(x, y // 2) ** 2 * x % M

	def pow(self, x, y):
		val = 1
		while y:
			if y & 1:
				val = val * x % M
			y = y >> 1
			x = x * x % M
		return val

	def compute_value(self, n):
		cur = 1
		ans = 0
		inverse = []
		for i in range(0, n):
			inverse.append(pow(i, M - 2, M))
		for i in range(1, n):
			cur = cur * (n - i + 1) * inverse[i] % M
			ans += cur * cur % M
			ans = ans % M
		ans += 2
		return ans % M

	def compute_value1(self, n):
		return math.factorial(2 * n) // math.factorial(n) ** 2 % M


import math
mod = 10 ** 9 + 7

class Solution:

	def compute_value(self, n):
		num = math.factorial(2 * n)
		den = math.factorial(n) ** 2
		return num // den % mod


import math

class Solution:

	def compute_value(self, n):
		MOD = 10 ** 9 + 7
		denominator = math.factorial(2 * n)
		numerator = math.factorial(n)
		ans = denominator // numerator ** 2 % MOD
		return ans


import math

class Solution:

	def ncr(self, n, r, p):
		num = den = 1
		for i in range(r):
			num = num * (n - i) % p
			den = den * (i + 1) % p
		return num * pow(den, p - 2, p) % p

	def compute_value(self, n):
		return self.ncr(2 * n, n, 1000000007)


class Solution:

	def compute_value(self, n):
		ans = 0
		m = 1000000007
		num = 1
		den = 1
		for r in range(0, n + 1):
			val = num % m * pow(den, m - 2, m) % m % m
			ans = (ans % m + val % m * val % m % m) % m
			num = num % m * (n - r) % m % m
			den = den % m * (r + 1) % m % m
		return ans


import math as m

class Solution:

	def compute_value(self, n):
		ans = 0
		a = m.factorial(n)
		b = m.factorial(2 * n)
		return b // (a * a) % (10 ** 9 + 7)


import math

class Solution:

	def compute_value(self, n):
		a = math.factorial(2 * n)
		b = math.factorial(n)
		return a // b ** 2 % int(1000000000.0 + 7)


import math
mod = 10 ** 9 + 7

class Solution:

	def compute_value(self, n):
		a1 = math.factorial(2 * n)
		a2 = math.factorial(n)
		return a1 // a2 ** 2 % mod


class Solution:

	def compute_value(self, n):
		k = 1
		for i in range(1, n + 1):
			k = k * (n + i) // i
		k = int(k)
		k = k % (10 ** 9 + 7)
		return k


import math

class Solution:

	def compute_value(self, n):
		x = math.factorial(n * 2)
		y = math.factorial(n)
		return int(x // y ** 2 % (10 ** 9 + 7))


mod = int(1000000000.0 + 7)
mx = int(300000.0 + 3)
fact = [1 for n in range(mx)]
for n in range(1, mx):
	fact[n] = fact[n - 1] * n % mod

def bnp(base, pw):
	res = 1
	while pw:
		if pw & 1:
			res = res * base % mod
		pw >>= 1
		base = base * base % mod
	return res

def ncr(n, r):
	denom = fact[r] * fact[n - r] % mod
	denomInv = bnp(denom, mod - 2)
	res = fact[n] * denomInv
	return res % mod

class Solution:

	def compute_value(self, x):
		res = ncr(2 * x, x)
		return res


import math

class Solution:

	def compute_value(self, n):
		s = 0
		c = math.factorial(2 * n)
		d = math.factorial(n)
		d *= d
		c = c // d
		c = c % 1000000007
		return c


import math
mod = 10 ** 9 + 7

class Solution:

	def compute_value(self, n):
		ans = math.factorial(2 * n)
		ob = math.factorial(n)
		return ans // ob ** 2 % mod


mod = int(1000000000.0) + 7

def gcd(a, b):
	if b == 0:
		return (1, 0, a)
	(x, y, r) = gcd(b, a % b)
	(x, y) = (y, x - a // b * y)
	return (x, y, r)

def nCk(n, k):
	ans = 1
	for i in range(n, n - k, -1):
		ans *= i
		ans %= mod
	for i in range(k):
		(x, _, _) = gcd(i + 1, mod)
		ans *= x % mod
		ans %= mod
	return ans

class Solution:

	def compute_value(self, n):
		return nCk(n + n, n)