Cities on a map are connected by a number of roads.  The number of roads between each city is in an array and city ${0}$ is the starting location.  The number of roads from city ${0}$ to city ${1}$ is the first value in the array, from city ${1}$ to city $2$ is the second, and so on.  

How many paths are there from city ${0}$ to the last city in the list, modulo $1234567$?

Example 

$n=4$ 

$routes=[3,4,5]$  

There are $3$ roads to city ${1}$, ${4}$ roads to city $2$ and $5$ roads to city $3$.  The total number of roads is $3\times4\times5\mod1234567=60$. 

Note 

Pass all the towns T_{i} for i=1 to n-1 in numerical order to reach T_{n}.  

Function Description  

Complete the connectingTowns function in the editor below.  

connectingTowns has the following parameters:  

int n: the number of towns  
int routes[n-1]: the number of routes between towns  

Returns  

int: the total number of routes, modulo 1234567. 

Input Format 

The first line contains an integer T, T test-cases follow.   

Each test-case has 2 lines. 

  The first line contains an integer N (the number of towns). 

  The second line contains N - 1 space separated integers where the i^{th} integer denotes the number of routes, N_{i}, from the town T_{i} to T_{i+1}  

Constraints 

1 <= T<=1000

2< N <=100

1 <= routes[i] <=1000

Sample Input  

2
3
1 3
4
2 2 2

Sample Output  

3
8

Explanation 

Case 1: 1 route from T_{1} to T_{2}, 3 routes from T_{2} to T_{3}, hence only 3 routes. 

Case 2: There are 2 routes from each city to the next, hence 2 * 2 * 2 = 8.

Difficulty: EASY
Tags: Mathematics

Starter code:

Solutions:
t = int(input())
for i in range(t):
	n = int(input())
	p = 1
	r = input().split(' ')
	for i in range(n - 1):
		p = p * int(r[i])
		p = p % 1234567
	print(p)


n = int(input())
for i in range(n):
	towns = int(input())
	routes = input().strip().split()
	routes = [int(entry) for entry in routes]
	r = 1
	for num_routes in routes:
		r *= num_routes
		r %= 1234567
	print(r)


testcase = int(input())
for x in range(testcase):
	total = 1
	town = int(input())
	num = [int(i) for i in input().split()]
	for y in num:
		total *= y
	print(total % 1234567)


import sys
import functools
import operator
T = int(sys.stdin.readline())
for t in range(T):
	N = int(sys.stdin.readline())
	n = [int(i) for i in sys.stdin.readline().split()]
	print(functools.reduce(operator.mul, n, 1) % 1234567)


import functools
import operator
tests = int(input())
for test in range(tests):
	input()
	print(functools.reduce(operator.mul, map(int, input().split())) % 1234567)


T = int(input())
while T > 0:
	T -= 1
	N = int(input())
	routes = [int(i) for i in input().split()]
	mul = 1
	for i in routes:
		mul *= i
	print(mul % 1234567)


def towns(r):
	total = 1
	for i in r:
		j = int(i)
		total = total * j
	print(total % 1234567)
x = int(input())
for i in range(0, x):
	r = []
	y = int(input())
	x = input()
	r = x.strip().split()
	towns(r)


cases = int(input())
i = 0
result = []
while i < cases:
	ans = 1
	towns = int(input())
	route = input()
	route = route.split(' ')
	j = 0
	while j < towns - 1:
		ans = ans * int(route[j])
		j += 1
	result.append(ans % 1234567)
	i += 1
i = 0
while i < cases:
	print(result[i])
	i += 1


import sys
import operator
from functools import reduce
input_data = [data.strip() for data in sys.stdin.read().split('\n')]
T = int(input_data[0])
for test_case in range(2, len(input_data), 2):
	number_of_choices = reduce(operator.mul, (int(i) for i in input_data[test_case].split()))
	print(number_of_choices % 1234567)


from functools import reduce
from operator import mul
output = []
t = int(input())
for _ in range(0, t):
	input()
	count = reduce(mul, map(int, input().split()))
	output.append(count % 1234567)
print('\n'.join(map(str, output)))


rem = 1234567
T = int(input())
for i in range(T):
	n = int(input())
	vals = [int(j) for j in input().split()]
	count = 1
	for j in vals:
		count *= j
		count %= rem
	print(count)


def parse():
	return int(input().strip())

def parse_list():
	return list(map(int, input().strip().split()))
T = parse()
for i in range(T):
	n = parse()
	a = parse_list()
	total = 1
	for j in a:
		total *= j
	print(total % 1234567)


num_testcases = int(input())
num_routes = []
for i_testcase in range(num_testcases):
	num_towns = int(input())
	routes = 1
	town_routes = input().strip().split()
	for route in town_routes:
		routes *= int(route)
	num_routes.append(routes)
for num_route in num_routes:
	print(num_route % 1234567)


for i in range(int(input())):
	a = int(input())
	b = input().split()
	h = 1
	for g in b:
		h = h * int(g)
	print(h % 1234567)


t = int(input())
for i in range(t):
	n = int(input())
	rs = input().strip()
	rs = list(map(int, rs.split(' ')))
	akh = 1
	for j in range(0, len(rs)):
		akh = akh * rs[j]
	print(akh % 1234567)


import functools as ft
T = int(input())
for i in range(T):
	n = int(input())
	nums = [int(x) for x in input().strip().split(' ')]
	print(ft.reduce(lambda a, b: a * b % 1234567, nums, 1))


for case in range(int(input())):
	(_, nums) = (input(), map(int, input().split()))
	prod = 1
	for num in nums:
		prod *= num
	print(prod % 1234567)


T = int(input())
for t in range(0, T):
	N = int(input())
	Ns = [int(x) for x in input().strip().split(' ')]
	c = 1
	for n in Ns:
		c *= n
	print(c % 1234567)


from sys import stdin
input_list = stdin.readlines()
test_cases = int(input_list[0])
del input_list[0]
towns = []
for i in range(test_cases):
	routes = input_list[2 * i + 1].split()
	for j in range(len(routes)):
		routes[j] = int(routes[j])
	towns.append([int(input_list[2 * i]), routes])
for i in towns:
	result = 1
	for j in i[1]:
		result = result * j
	print(result % 1234567)


import functools, operator as op, sys
T = int(sys.stdin.readline())
for _ in range(T):
	int(sys.stdin.readline())
	N = [int(x) for x in sys.stdin.readline().split()]
	print(functools.reduce(op.mul, N, 1) % 1234567)


def find_ways():
	test_cases = int(input())
	for i in range(test_cases):
		num_integers = int(input())
		str_in = str(input()).strip()
		int_list = [int(x) for x in str_in.split(' ')]
		output = 1
		for j in int_list:
			output = output * j
		print(output % 1234567)

def main():
	find_ways()
main()


from functools import reduce
caseCnt = int(input())
for caseNr in range(caseCnt):
	input()
	res = [int(x) for x in input().split()]
	res = reduce(lambda x, y: x * y, res)
	print(res % 1234567)


from operator import mul
from functools import reduce
import sys
next(sys.stdin)
try:
	while True:
		_ = next(sys.stdin)
		routes = map(int, next(sys.stdin).strip().split())
		print(reduce(mul, routes) % 1234567)
except:
	pass


import sys
from functools import reduce
from operator import mul

def main():
	t = int(sys.stdin.readline())
	for _ in range(t):
		towns = int(sys.stdin.readline())
		roads = (int(n) for n in sys.stdin.readline().split())
		print(reduce(mul, roads) % 1234567)
main()


T = int(input())
for t in range(T):
	N = int(input())
	Ni = [int(v) for v in input().split()]
	r = 1
	for n in Ni:
		r = r * n % 1234567
	print(r)


numtests = int(input())
tests = []
for i in range(numtests):
	cities = int(input())
	routes = [int(x) for x in input().split(' ')]
	tests.append((cities, routes))
for i in range(numtests):
	value = 1
	for el in tests[i][1]:
		value = el * value
	print(value % 1234567)


from operator import mul
from functools import reduce
for _ in range(int(input())):
	input()
	paths = [int(x) for x in input().split()]
	a = 1
	for p in paths:
		a = a * p % 1234567
	print(a)


T = int(input())
for i in range(T):
	N = int(input())
	numbers = list(input().split())
	sum = 1
	for e in numbers:
		sum *= int(e)
	print(sum % 1234567)


def count_routes(route_map):
	n = 1
	for r in route_map:
		n *= r
	return n
T = int(input().strip())
for t in range(T):
	n = int(input().strip())
	route_map = list(map(int, input().strip().split()))
	print(count_routes(route_map) % 1234567)


T = int(input())
for _ in range(T):
	input()
	ar = [int(e) for e in str(input()).split()]
	ret = 1
	for x in ar:
		ret *= x
	print(ret % 1234567)


test = int(input())
for i in range(test):
	n = input()
	z = input().split()
	d = 1
	for i in z:
		d = int(i) * d
	print(d % 1234567)


t = int(input())
for i in range(t):
	input()
	towns = map(int, input().split(' '))
	nRoutes = 1
	for town in towns:
		nRoutes *= town
		nRoutes %= 1234567
	print(nRoutes)


T = int(input())
for i in range(T):
	N = int(input())
	nums = map(int, input().split())
	r = 1
	for n in nums:
		r *= n % 1234567
	print(r % 1234567)


T = int(input())
import functools
import operator
modval = 1234567
for i in range(T):
	N = int(input())
	Ni = [int(x) for x in input().split()]
	print(functools.reduce(operator.mul, Ni) % modval)


for i in range(int(input())):
	n = int(input())
	ans = 1
	a = list(map(int, input().split()))
	for k in a:
		ans = ans * k
	print(ans % 1234567)


test_cases = int(input())
for _ in range(test_cases):
	routes = 1
	input()
	queue = [int(x) for x in input().split(' ')]
	for item in queue:
		routes = routes * item % 1234567
	print(routes)


from functools import reduce
for i in range(int(input())):
	n = int(input())
	print(reduce(lambda x, y: x * y, (int(e) for e in input().split()), 1) % 1234567)


test = int(input())
for t in range(test):
	n = int(input())
	a = map(int, input().split())
	c = 1
	for i in a:
		c = c * i % 1234567
	print(c)


t = int(input())
for _ in range(t):
	n = int(input())
	ans = 1
	for path in input().split():
		ans *= int(path)
	print(ans % 1234567)


test = int(input())
for i in range(test):
	k = input()
	a = input().split(' ')
	ans = 1
	for j in a:
		ans = ans * int(j)
	print(ans % 1234567)


cases = int(input())
for case in range(cases):
	total_routes = 1
	input()
	routes = input().split()
	for route in routes:
		total_routes = total_routes * int(route) % 1234567
	print(total_routes)


def counttown(a):
	route = 1
	for i in range(len(a)):
		route *= int(a[i])
		route %= 1234567
	return route
for t in range(int(input())):
	nop = int(input())
	temp = input()
	a = temp.split()
	print(counttown(a))


T = int(input())
for i in range(T):
	N = int(input())
	values = input().split(' ')
	answer = 1
	for j in range(len(values)):
		answer = int(answer * (int(values[j]) % 1234567)) % 1234567
	print(answer)


import functools, operator
T = int(input())
for _ in range(T):
	input()
	routes = [int(x) for x in input().split(' ')]
	res = 1
	for x in routes:
		res = res * x % 1234567
	print(res)


n = int(input())
x = []
for i in range(n):
	t = int(input())
	inp = input().split()
	x.append(inp)
for a in x:
	p = 1
	for b in a:
		p = p * int(b)
	print(int(p % 1234567))


t = int(input())
for asdfas in range(t):
	n = int(input())
	tab = list(map(int, input().split()))
	result = 1
	for item in tab:
		result *= item
	print(result % 1234567)


T = int(input())
for _ in range(T):
	a = int(input())
	total = 1
	for i in [int(x) for x in input().split()]:
		total *= i
	print(total % 1234567)


from functools import reduce
T = int(input())
while T:
	input()
	L = map(int, input().split())
	print(reduce(lambda x, y: x * y, L) % 1234567)
	T -= 1


for i in range(int(input())):
	n = input()
	arr = [int(j) for j in input().split()]
	res = 1
	for k in arr:
		res *= k
	print(res % 1234567)


no_test = int(input())
for i in range(no_test):
	N = int(input())
	town_routes = input().split(' ')
	no_routes = 1
	for n in range(N - 1):
		no_routes = no_routes * int(town_routes[n])
	print(no_routes % 1234567)


__author__ = 'neki'
import sys
modulo = 1234567
nTest = int(input())
for t in range(nTest):
	n = int(input())
	ways = 1
	numbers = input().split()
	for i in range(n - 1):
		roads = int(numbers[i])
		ways *= roads
		ways %= modulo
	print(ways)


for _ in range(int(input())):
	n = input()
	num = 1
	for x in input().split():
		num = num * int(x)
	num = num % 1234567
	print(num)


constmod = 1234567
t = int(input())
for caset in range(t):
	n = int(input())
	a = [int(item) for item in input().strip().split()]
	res = 1
	for i in a:
		res *= i
		res %= constmod
	print(res)


t = int(input())
for i in range(t):
	n = int(input())
	s = input().split()
	ans = 1
	for j in range(n - 1):
		ans = ans * int(s[j]) % 1234567
	print(ans)


T = int(input())
for i in range(0, T):
	N = int(input())
	list1 = [int(i) for i in input().split()]
	x = 1
	for i in list1:
		x = x * i
	print(int(x % 1234567))


for t in [1] * int(input()):
	input()
	f = lambda ar: int(ar[0]) * f(ar[1:]) if len(ar) != 0 else 1
	print(f(input().split()) % 1234567)


T = int(input())
MOD = 1234567
for t in range(T):
	N = int(input())
	R = [int(c) for c in input().split(' ')]
	res = 1
	for r in R:
		res = res * r % MOD
	print(res)


from operator import mul
from functools import reduce
T = int(input())
for i in range(T):
	input()
	print(reduce(mul, map(int, input().split())) % 1234567)


T = int(input())
for i in range(0, T):
	N = int(input())
	roads = [int(s) for s in input().split()]
	path = 1
	for road in roads:
		path = path * road
	path = path % 1234567
	print(path)


__author__ = 'nolanemirot'

def connectingTown():
	nbTown = int(input())
	line = input()
	routes = list(map(int, line.split()))
	res = 1
	for i in range(0, len(routes)):
		res *= routes[i]
	print(res % 1234567)
nbTestCase = int(input())
for i in range(0, nbTestCase):
	connectingTown()


def main():
	n = int(input())
	listS = [1] * n
	for i in range(n):
		s = int(input())
		m = input()
		m = m.split()
		for j in range(s - 1):
			listS[i] *= int(m[j])
			listS[i] %= 1234567
	for i in range(n):
		print(listS[i])
main()


from operator import mul
from functools import reduce
for _ in range(int(input())):
	int(input())
	print(reduce(mul, [int(i) for i in input().split()]) % 1234567)


tCases = int(input(''))
for i in range(tCases):
	input('')
	routes = [int(n) for n in input('').split(' ')]
	paths = 1
	for r in routes:
		paths = paths * r % 1234567
	print(paths)


for _ in range(int(input())):
	n = int(input())
	N = map(int, input().split())
	routes = 1
	for choices in N:
		routes *= choices
	print(routes % 1234567)


from functools import reduce
T = int(input())
for i in range(T):
	input()
	print(reduce(lambda x, y: x * y, map(int, input().split())) % 1234567)


t = int(input())
for i in range(t):
	n = int(input())
	s = []
	p = 1
	s = [int(i) for i in input().split()]
	for k in range(n - 1):
		p = p * s[k]
	r = p % 1234567
	print(r)


def towns():
	T = int(input())
	ANSWER = [1] * T
	for i in range(T):
		towns = int(input())
		lst = [int(j) for j in input().split()]
		for j in range(towns - 1):
			ANSWER[i] *= lst[j]
		del lst
	for i in range(T):
		print(ANSWER[i] % 1234567)
towns()


test_count = int(input())
for i in range(0, test_count):
	city_count = int(input())
	connections = list(map(int, input().split()))
	output = 1
	for connection in connections:
		output = output * connection % 1234567
	print(output)


import operator
import functools
import sys
l = []
t = int(input())
for i in range(t):
	j = int(input())
	k = input()
	l = k.split()
	l = map(int, l)
	k = functools.reduce(operator.mul, l, 1)
	print(k % 1234567)


T = int(input())
for i in range(T):
	N = int(input())
	d = input().split()
	routes = [int(x) for x in d]
	total = 1
	for r in routes:
		total *= r
	total = total % 1234567
	print(total)


t = int(input())
for i in range(t):
	n = int(input())
	rcs = input().strip().split()
	assert n - 1 == len(rcs), 'Number of towns must be one more than the number of route counts.'
	tot = 1
	for rc in rcs:
		tot = tot * int(rc) % 1234567
	print(tot)


for i in range(int(input())):
	input()
	l = list(map(int, input().split()))
	p = 1
	for j in l:
		p = p * j % 1234567
	print(str(p))


for _ in range(int(input())):
	n = int(input())
	a = map(int, input().split())
	res = 1
	for x in a:
		res = res * x % 1234567
	print(res)


def towns():
	T = int(input())
	ANSWER = [1] * T
	for i in range(T):
		towns = int(input())
		lst = [int(j) for j in input().split()]
		for j in range(towns - 1):
			ANSWER[i] *= lst[j]
		del lst
	for i in range(T):
		print(ANSWER[i] % 1234567)
towns()


import itertools

def prod(A):
	x = 1
	for i in A:
		x = x * i % 1234567
	return x
T = int(input())
for _ in range(T):
	N = int(input())
	Ni = [int(i) for i in input().split()]
	print(prod(Ni) % 1234567)


T = int(input())
for t in range(T):
	input()
	N = [int(x) for x in input().split()]
	sol = 1
	for n in N:
		sol *= n
	print(sol % 1234567)


tests = int(input())
numCities = []
routes = []
for t in range(tests):
	numCities.append(int(input()))
	routes.append(input().split(' '))
for t in range(tests):
	R = list(map(int, routes[t]))
	totalRoutes = 1
	for r in R:
		totalRoutes *= r
	print(totalRoutes % 1234567)


from sys import stdin
numcases = int(stdin.readline().strip())
for i in range(numcases):
	towns = int(stdin.readline().strip())
	paths = [int(s) for s in stdin.readline().strip().split(' ')][:towns - 1]
	result = 1
	for path in paths:
		result *= path
		result %= 1234567
	print(result)


N = int(input())
A = list()
B = list()

def product(a):
	p = 1
	for i in a:
		i = int(i)
		p *= i
	return p
for i in range(N):
	i = int(input())
	a = input()
	a = a.split()
	A.append(i)
	B.append(a)
for b in B:
	print(product(b) % 1234567)


n = int(input())
while n > 0:
	n -= 1
	routes = int(input())
	options = 1
	routeL = list(map(int, input().split()))
	for i in routeL:
		options = options * i % 1234567
	print(options)


def compute_routes(Ns):
	routes = 1
	for n in Ns:
		routes = routes * n % 1234567
	return routes
for t in range(int(input())):
	input()
	print(compute_routes(map(int, input().split())))


for ncase in range(int(input())):
	input()
	sq = [int(i) for i in input().split(' ')]
	ans = 1
	for x in sq:
		ans *= x
	print(ans % 1234567)


import sys
import operator
from functools import reduce
n = int(sys.stdin.readline())

def solve():
	sys.stdin.readline()
	connections = list(map(int, sys.stdin.readline().split(' ')))
	return reduce(operator.mul, connections, 1) % 1234567
for i in range(0, n):
	print(solve())


t = int(input())
for x in range(t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	answer = 1
	for x in a:
		answer *= x
	print(answer % 1234567)


import functools, operator as op, sys
T = int(sys.stdin.readline())
for _ in range(T):
	int(sys.stdin.readline())
	N = [int(x) for x in sys.stdin.readline().split()]
	print(functools.reduce(op.mul, N, 1) % 1234567)


T = int(input().strip())
for tests in range(T):
	N = int(input().strip())
	total_routes = 1
	for Ni in input().strip().split():
		total_routes = total_routes * int(Ni) % 1234567
	print(total_routes)


T = int(input().strip())
for t in range(T):
	result = 1
	n = int(input().strip())
	arr = [int(i) for i in input().strip().split()]
	for v in arr:
		result = result * v % 1234567
	print(result)


T = int(input())
for _ in range(T):
	number = int(input())
	route = input().split(' ')
	result = int(route[0])
	for i in range(1, len(route)):
		result *= int(route[i])
		result = result % 1234567
	print(result)


import sys
tests = sys.stdin.readline()
for t in range(int(tests.strip())):
	x = sys.stdin.readline()
	line = sys.stdin.readline()
	routes = 1
	for n in line.split():
		routes = routes * int(n)
	print(routes % 1234567)


T = int(input())
for _ in range(T):
	input()
	routes = [int(i) for i in input().split(' ')]
	count = routes[0]
	for step in routes[1:]:
		count = count * step % 1234567
	print(count)


def towns():
	T = int(input())
	ANSWER = [1] * T
	for i in range(T):
		towns = int(input())
		lst = [int(j) for j in input().split()]
		for j in range(towns - 1):
			ANSWER[i] *= lst[j]
		del lst
	for i in range(T):
		print(ANSWER[i] % 1234567)
towns()


from functools import reduce
for _ in range(int(input())):
	input()
	routes = map(int, input().split())
	result = reduce(lambda a, b: a * b, routes) % 1234567
	print(result)


cases = int(input())
for i in range(cases):
	num = 1
	towns = int(input())
	routes = input().split()
	for route in routes:
		num *= int(route)
	print(num % 1234567)


T = int(input())
for t in range(T):
	n = int(input())
	ns = list(map(int, input().strip().split()))
	res = 1
	for x in ns:
		res = res * x % 1234567
	print(res)


from operator import mul
T = int(input())
for i in range(T):
	N = int(input())
	numbers = map(int, input().split())
	product = 1
	for i in numbers:
		product *= i
	print(product % 1234567)


n = int(input())
for i in range(0, n):
	k = int(input())
	y = input().split()
	prod = 1
	for i in range(0, len(y)):
		prod *= int(y[i])
	print(prod % 1234567)


def answer(inp):
	count = 1
	for i in inp.split():
		count *= int(i)
	return count % 1234567
for i in range(int(input())):
	input()
	print(answer(input()))


def main():
	count = int(input())
	for i in range(count):
		towns = int(input())
		paths = list(map(int, input().strip().split(' ')))
		answer = 1
		for path in paths:
			answer *= path
		print(answer % 1234567)
main()


from functools import reduce
T = int(input())
for i in range(T):
	n = int(input())
	arr = [int(s) for s in input().split()]
	print(reduce(lambda x, y: x * y, arr) % 1234567)


test_cases = int(input())
for _ in range(test_cases):
	T = int(input())
	N = map(int, input().split())
	s = 1
	for x in N:
		s *= x
	print(s % 1234567)