As we all know Barney's job is "PLEASE" and he has not much to do at work. That's why he started playing "cups and key". In this game there are three identical cups arranged in a line from left to right. Initially key to Barney's heart is under the middle cup. [Image] 

Then at one turn Barney swaps the cup in the middle with any of other two cups randomly (he choses each with equal probability), so the chosen cup becomes the middle one. Game lasts n turns and Barney independently choses a cup to swap with the middle one within each turn, and the key always remains in the cup it was at the start.

After n-th turn Barney asks a girl to guess which cup contains the key. The girl points to the middle one but Barney was distracted while making turns and doesn't know if the key is under the middle cup. That's why he asked you to tell him the probability that girl guessed right.

Number n of game turns can be extremely large, that's why Barney did not give it to you. Instead he gave you an array a_1, a_2, ..., a_{k} such that  $n = \prod_{i = 1}^{k} a_{i}$ 

in other words, n is multiplication of all elements of the given array.

Because of precision difficulties, Barney asked you to tell him the answer as an irreducible fraction. In other words you need to find it as a fraction p / q such that $\operatorname{gcd}(p, q) = 1$, where $gcd$ is the greatest common divisor. Since p and q can be extremely large, you only need to find the remainders of dividing each of them by 10^9 + 7.

Please note that we want $gcd$ of p and q to be 1, not $gcd$ of their remainders after dividing by 10^9 + 7.


-----Input-----

The first line of input contains a single integer k (1 ≤ k ≤ 10^5) — the number of elements in array Barney gave you.

The second line contains k integers a_1, a_2, ..., a_{k} (1 ≤ a_{i} ≤ 10^18) — the elements of the array.


-----Output-----

In the only line of output print a single string x / y where x is the remainder of dividing p by 10^9 + 7 and y is the remainder of dividing q by 10^9 + 7.


-----Examples-----
Input
1
2

Output
1/2

Input
3
1 1 1

Output
0/1

Difficulty: HARD
Tags: Combinatorics

Implementation

Dynamic programming

Mathematics

Matrices
Skill types: Dynamic programming

Starter code:

Solutions:
3

class Matrix:

	def __init__(self, n, m, arr=None):
		self.n = n
		self.m = m
		self.arr = [[0] * m for i in range(n)]
		if arr is not None:
			for i in range(n):
				for j in range(m):
					self.arr[i][j] = arr[i][j]

	def __mul__(self, other):
		assert self.m == other.n
		ans = Matrix(self.n, other.m)
		for i in range(self.n):
			for j in range(other.m):
				for k in range(self.m):
					ans.arr[i][j] = (ans.arr[i][j] + self.arr[i][k] * other.arr[k][j]) % (10 ** 9 + 7)
		return ans

	def __imul__(self, other):
		self = self * other
		return self

	def __pow__(self, n):
		if n == 0:
			ans = Matrix(self.n, self.n)
			for i in range(self.n):
				ans.arr[i][i] = 1
			return ans
		elif n & 1 == 1:
			return self * self ** (n - 1)
		else:
			t = self ** (n >> 1)
			return t * t

	def __ipow__(self, n):
		self = self ** n
		return self

	def __eq__(self, other):
		if self.n != other.n or self.m != other.m:
			return False
		for i in range(self.n):
			for j in range(self.m):
				if self.arr[i][j] != other.arr[i][j]:
					return False
		return True

def fpow(a, n):
	if n == 0:
		return 1
	elif n & 1 == 1:
		return a * fpow(a, n - 1) % (10 ** 9 + 7)
	else:
		t = fpow(a, n >> 1)
		return t * t % (10 ** 9 + 7)
transform = Matrix(2, 2, [[1, 1], [0, 4]])
mtx = transform
k = int(input())
a = list(map(int, input().split()))
x = 1
for j in a:
	x = x * j % (10 ** 9 + 6)
x = (x - 1) % (10 ** 9 + 6)
if x % 2 == 0:
	ans = transform ** (x // 2) * Matrix(2, 1, [[0], [1]])
	print('%d/%d' % (ans.arr[0][0], fpow(2, x)))
else:
	y = (x - 1) % (10 ** 9 + 6)
	ans = transform ** (y // 2) * Matrix(2, 1, [[0], [1]])
	print('%d/%d' % ((ans.arr[0][0] * 2 + 1) % (10 ** 9 + 7), ans.arr[1][0] * 2 % (10 ** 9 + 7)))


import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
threading.stack_size(10 ** 8)
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
sys.setrecursionlimit(300000)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n

class SegmentTree1:

	def __init__(self, data, default=2 ** 51, func=lambda a, b: a & b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] < key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater

def multiply(a, b):
	mul = [[0 for x in range(2)] for y in range(2)]
	for i in range(2):
		for j in range(2):
			mul[i][j] = 0
			for k in range(2):
				mul[i][j] += a[i][k] * b[k][j]
				mul[i][j] %= mod
	for i in range(2):
		for j in range(2):
			a[i][j] = mul[i][j]
	return a

def power(M, n):
	if n == 0:
		res = [[0 for i in range(2)] for j in range(2)]
		res[0][0] = 1
		res[1][1] = 1
		return res
	if n == 1:
		return M
	else:
		res = [[1, 0], [0, 1]]
		if n % 2 == 1:
			res = multiply(res, M)
		re = power(M, n // 2)
		re = multiply(re, re)
		re = multiply(re, res)
		return re
n = int(input())
l = list(map(int, input().split()))
req = 1
for i in l:
	req *= i
	req %= mod - 1
if req == 0:
	req = mod - 1
if req == 1:
	print('0/1')
	sys.exit(0)
M = [[0 for i in range(2)] for j in range(2)]
M[0][0] = 1
M[0][1] = 2
M[1][0] = 1
M[1][1] = 0
M = power(M, req - 2)
num = M[0][0] % mod
de = pow(2, req - 1, mod)
print(str(num) + '/' + str(de))


k = int(input())
n = list(map(int, input().split()))
for i in range(k):
	n[i] = bin(n[i])
	n[i] = n[i][2:]
magic = 1000000007

def par(s):
	if s[-1] == '0':
		return True
	else:
		return False

def mod_pow(x, s, p):
	ans = 1
	for i in range(len(s)):
		if s[i] == '1':
			ans = ans * ans % p * x % p
		else:
			ans = ans * ans % p
	return ans

def div_in_field(a, b, p):
	b_op = pow(b, p - 2, p)
	return b_op * a % p
denominator = 2
n_par = False
for i in range(len(n)):
	denominator = mod_pow(denominator, n[i], magic)
	if par(n[i]):
		n_par = True
denominator = div_in_field(denominator, 2, magic)
numerator = 0
if n_par:
	numerator = div_in_field(1 + denominator, 3, magic)
else:
	numerator = div_in_field(-1 + denominator, 3, magic)
ans = str(numerator) + '/' + str(denominator)
print(ans)


from functools import reduce
mod = 1000000007
n = input()
num = list(map(int, input().split()))
flag = 1 if len(list([x for x in num if x % 2 == 0])) else -1
b = reduce(lambda x, y: pow(x, y, mod), num, 2)
b = b * pow(2, mod - 2, mod) % mod
a = (b + flag) * pow(3, mod - 2, mod) % mod
print('%d/%d' % (a, b))


mod = int(1000000000.0 + 7)
k = int(input())
top = 1
yoink = 1
a = list(map(int, input().split()))
for thing in a:
	top *= thing
	yoink *= thing
	yoink %= 2
	top %= mod - 1

def extended_gcd(aa, bb):
	(lastremainder, remainder) = (abs(aa), abs(bb))
	(x, lastx, y, lasty) = (0, 1, 1, 0)
	while remainder:
		(lastremainder, (quotient, remainder)) = (remainder, divmod(lastremainder, remainder))
		(x, lastx) = (lastx - quotient * x, x)
		(y, lasty) = (lasty - quotient * y, y)
	return (lastremainder, lastx * (-1 if aa < 0 else 1), lasty * (-1 if bb < 0 else 1))

def modinv(a, m):
	(g, x, y) = extended_gcd(a, m)
	if g != 1:
		raise ValueError
	return x % m
if top == 0:
	bot = modinv(2, mod)
else:
	bot = pow(2, top - 1, mod)
if yoink % 2 == 0:
	blah = modinv(3, mod)
	blah *= bot + 1
	blah %= mod
	print(str(blah) + '/' + str(bot))
else:
	blah = modinv(3, mod)
	blah *= bot + 2
	blah %= mod
	print(str(blah - 1) + '/' + str(bot))


mod = 10 ** 9 + 7
k = int(input())
arr = [int(j) for j in input().split()]
findeven = 0
for i in range(k):
	if arr[i] % 2 == 0:
		findeven = 1
cur = pow(2, arr[0], mod)
for i in range(1, k):
	cur = pow(cur, arr[i], mod)
inv2 = pow(2, mod - 2, mod)
inv3 = pow(3, mod - 2, mod)
if findeven == 1:
	lr = (cur - 1) * inv3
	m = (cur - 1) * inv3 + 1
else:
	lr = (cur - 2) * inv3 + 1
	m = (cur - 2) * inv3
lr = lr * inv2 % mod
m = m * inv2 % mod
cur = cur * inv2 % mod
print(m, '/', cur, sep='')


k = int(input())
MOD = 10 ** 9 + 7
antithree = pow(3, MOD - 2, MOD)
antitwo = pow(2, MOD - 2, MOD)
power = 1
parity = False
for t in map(int, input().split()):
	power *= t
	power %= MOD - 1
	if t % 2 == 0:
		parity = True
q = pow(2, power, MOD) * antitwo
q %= MOD
if parity:
	p = (q + 1) * antithree
	p %= MOD
else:
	p = (q - 1) * antithree
	p %= MOD
print(p, q, sep='/')


mod = 1000000007
input()
numbers = list(map(int, input().split()))
b = 2
flag = 1 if len(list(filter(lambda x: x % 2 == 0, numbers))) else -1
for num in numbers:
	b = pow(b, num, mod)
b = b * pow(2, mod - 2, mod) % mod
a = (b + flag) * pow(3, mod - 2, mod) % mod
print('%d/%d' % (a, b))


n = int(input())
ls = [int(x) for x in input().split(' ')]
t = 1
mod = 1000000007

def qpow(n: int, m: int):
	m %= mod - 1
	ans = 1
	while m:
		if m & 1:
			ans = ans * n % mod
		n = n * n % mod
		m >>= 1
	return ans
k = 0
r = mod * 2 - 2
for x in ls:
	t = t * x % (mod * 2 - 2)
	if x % 2 == 0:
		k = 1
t = (t - 1 + r) % r
fz = (qpow(4, t >> 1) - 1) * qpow(3, mod - 2) % mod
if k == 1:
	fz = (fz * 2 + 1) % mod
fm = qpow(2, t)
print('{}/{}'.format(fz, fm))


m = 1000000007
input()
(n, d) = (2, 1)
for q in map(int, input().split()):
	(d, n) = (q & d, pow(n, q, m))
n = n * pow(2, m - 2, m) % m
k = (n + 1 - 2 * d) * pow(3, m - 2, m) % m
print(str(k) + '/' + str(n))


p = int(1000000000.0) + 7
inv2 = int(500000000.0) + 4
inv3 = (p + 1) // 3

def binpower(b, e):
	r = 1
	while e:
		if e & 1:
			r = r * b % p
		e = e >> 1
		b = b * b % p
	return r

def f(l):
	r = 2
	odd = True
	for a in l:
		odd = odd and a % 2
		r = binpower(r, a % (p - 1))
	fm = r * inv2 % p
	fz = fm + (-1 if odd else 1)
	fz = fz * inv3 % p
	return '%d/%d' % (fz, fm)
_ = input()
l = list(map(int, input().split()))
print(f(l))


from functools import reduce
MOD = 10 ** 9 + 7
(n, a) = (int(input()), map(int, input().split()))
n = reduce(lambda x, y: x * y % (MOD - 1), a, 1)
k = n % 2
q = pow(2, n, MOD) * 500000004 % MOD
if k == 0:
	p = (q + 1) * 333333336 % MOD
else:
	p = (q - 1) * 333333336 % MOD
print('%d/%d' % (p, q))