output_description: Print the number of possible sequences of the mountains' heights, modulo 10^9
  + 7.
  
  * * *
input_description: The input is given from Standard Input in the following format:
  
      
      
      N
      T_1 T_2 ... T_N
      A_1 A_2 ... A_N
attempt: N = int(input())
  T = list(map(int, input().split()))
  A = list(map(int, input().split()))
  h = [0 for i in range(N)]
  if T[-1] != A[0]:
  	print(0)
  	exit()
  else:
  	h[0] = T[0]
  	h[-1] = A[-1]
  	for i in range(1,N):
  		if T[i] > T[i-1]:
  			if T[i] < h[i]:
  				print(0)
  				exit()
  			else:
  				h[i] = T[i]
  		else:
  			if h[i] < 0:
  				h[i] = max(h[i],-T[i])
  			elif T[i] < h[i]:
  				print(0)
  				exit()
  			elif h[i] == 0:
  				h[i] = -T[i]
  		if A[-i-1] > A[-i]:
  			if A[-i-1] < h[-i-1]:
  				print(0)
  				exit()
  			exit()
  				h[-i-1] = A[-i-1]
  		else:
  			if h[-i-1] < 0:
  				h[-i-1] = max(h[-i-1],-A[-i-1])
  			elif A[-i-1] < h[-i-1]:
  				print(0)
  				exit()
  			elif h[-i-1] == 0:
  				h[-i-1] = -A[-i-1]
  a = 1
  for n in h:
  	if a > 10**9+7:
  		a %= 10**9+7
  	if n < -1:
  		a *= -n
  print(a%(10**9+7))
  
problem_description: Statement
  
  Mountaineers Mr. Takahashi and Mr. Aoki recently trekked across a certain
  famous mountain range. The mountain range consists of N mountains, extending
  from west to east in a straight line as Mt. 1, Mt. 2, ..., Mt. N. Mr.
  Takahashi traversed the range from the west and Mr. Aoki from the east.
  
  The height of Mt. i is h_i, but they have forgotten the value of each h_i.
  Instead, for each i (1 ≤ i ≤ N), they recorded the maximum height of the
  mountains climbed up to the time they reached the peak of Mt. i (including Mt.
  i). Mr. Takahashi's record is T_i and Mr. Aoki's record is A_i.
  
  We know that the height of each mountain h_i is a positive integer. Compute
  the number of the possible sequences of the mountains' heights, modulo 10^9 +
  7.
  
  Note that the records may be incorrect and thus there may be no possible
  sequence of the mountains' heights. In such a case, output 0.
samples: [{"input": "5\n    1 3 3 3 3\n    3 3 2 2 2", "output": "4\n    \n\nThe possible sequences of the mountains' heights are:\n\n  * 1, 3, 2, 2, 2\n  * 1, 3, 2, 1, 2\n  * 1, 3, 1, 2, 2\n  * 1, 3, 1, 1, 2\n\nfor a total of four sequences.\n\n* * *"}, {"input": "5\n    1 1 1 2 2\n    3 2 1 1 1", "output": "0\n    \n\nThe records are contradictory, since Mr. Takahashi recorded 2 as the highest\npeak after climbing all the mountains but Mr. Aoki recorded 3.\n\n* * *"}, {"input": "10\n    1 3776 3776 8848 8848 8848 8848 8848 8848 8848\n    8848 8848 8848 8848 8848 8848 8848 8848 3776 5", "output": "884111967\n    \n\nDon't forget to compute the number modulo 10^9 + 7.\n\n* * *"}, {"input": "1\n    17\n    17", "output": "1\n    \n\nSome mountain ranges consist of only one mountain."}]