Problem:


Score : 400 points

Problem 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.

Constraints

1 ≤ N ≤ 10^5

1 ≤ T_i ≤ 10^9

1 ≤ A_i ≤ 10^9

T_i ≤ T_{i+1} (1 ≤ i ≤ N - 1)

A_i ≥ A_{i+1} (1 ≤ i ≤ N - 1)

Input

The input is given from Standard Input in the following format:

N
T_1 T_2 ... T_N
A_1 A_2 ... A_N

Output

Print the number of possible sequences of the mountains' heights, modulo 10^9 + 7.

Sample Input 1

5
1 3 3 3 3
3 3 2 2 2

Sample Output 1

4

The possible sequences of the mountains' heights are:

1, 3, 2, 2, 2 

1, 3, 2, 1, 2 

1, 3, 1, 2, 2 

1, 3, 1, 1, 2 

for a total of four sequences.

Sample Input 2

5
1 1 1 2 2
3 2 1 1 1

Sample Output 2

0

The records are contradictory, since Mr. Takahashi recorded 2 as the highest peak after climbing all the mountains but Mr. Aoki recorded 3.

Sample Input 3

10
1 3776 3776 8848 8848 8848 8848 8848 8848 8848
8848 8848 8848 8848 8848 8848 8848 8848 3776 5

Sample Output 3

884111967

Don't forget to compute the number modulo 10^9 + 7.

Sample Input 4

1
17
17

Sample Output 4

1

Some mountain ranges consist of only one mountain.



Sample input:
5
1 3 3 3 3
3 3 2 2 2


Sample output:
4

Submission status: Wrong Answer

Solution code:
N = int(raw_input())
T = raw_input().split(' ')
A = raw_input().split(' ')
check = False
yama = [0] * N
high_think = [0] * N
max_numT = 0
max_numA = 0
sum_num = 1
for i in range(0, N/2):
  temp = int(T[i])
  if max_numT < temp:
    max_numT = temp
    yama[i] = temp
  high_think[i] = max_numT
  temp = int(A[-1 - i])
  if max_numA < temp:
    max_numA = temp
    yama[-1 - i] = temp
  high_think[-1-i] = max_numA

if (N%2 == 1):
  i = i + 1
  if max_numT < int(T[i]):
    yama[i] == int(T[i])
  elif max_numA < int(A[-1-i]):
    yama[i] == int(A[-1-i])
  else:
    high_think[i] = min(max_numT, max_numA)

# print yama
# print high_think
max_numT = 0
max_numA = 0

for i in range(0, N):
  temp = int(T[i])
  if max_numT < temp:
    max_numT = temp
    if yama[i] > max_numT:
      check = True
  temp = int(A[-1-i])
  if max_numA < temp:
    max_numA = temp
    if yama[-1-i] > max_numA:
      check = True
  if yama[i] == 0:
    sum_num *= high_think[i]

if (T[-1] == A[0]) and not check:
  print sum_num % (10**9 + 7)
else:
  print "0"

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
t = map(int, raw_input().split())
a = map(int, raw_input().split())
M = 10**9 + 7
ans = 1
m = [0] * n
if t[n-1] == a[0]:
    for i in xrange(n):
        m = min([t[i], a[i]])
        flag1 = False
        flag2 = False
        if i > 0:
            if t[i-1] < t[i]:
                flag1 = True
        else:
            if a[i+1] < a[i]:
                ans = 0
                break
            flag1 = True
        if i < n-1:
            if a[i+1] < a[i]:
                flag2 = True
        else:
            if t[i-1] < t[i]:
                ans = 0
                break
            flag2  = True
        #print m
        
        if not(flag1 or flag2):
            ans *= m
            ans %= M
else:
    ans = 0
print ans,

Submission status: Wrong Answer

Solution code:
n=int(input())
l= list(map(int, input().split()))
r= list(map(int, input().split()))
l=[0]+l
r.append(0)
 
res=1
for i in range(n):
	if( (l[i]<l[i+1]) or (r[i]>r[i+1]) ):
		if( ( (l[i]<l[i+1]) and (r[i]>r[i+1]) ) and (l[i+1]!=r[i]) ):
			res=0
	else:
		res*=min(l[i+1],r[i])
		res%=1000000007
print(res)

Submission status: Wrong Answer

Solution code:
mod=10**9+7
n=int(raw_input())
t=map(int,raw_input().split())
a=map(int,raw_input().split())

if t[n-1]!=a[0]:
    print(0)
    exit()

ans=1
for i in xrange(n):
    if i==0 or i==n-1 or t[i]>t[i-1]:
        if a[i]<t[i] and a[i]==a[i+1]:
            print(0)
            exit()
        elif a[i]!=t[i] and a[i]!=a[i+1]:
            print(0)
        continue
    else:
        if t[i]==a[i]:
            if a[i]==a[i+1]:
                ans=(ans*t[i])%mod
        elif t[i]>a[i]:
            if a[i]==a[i+1]:
                ans=(ans*a[i])%mod
        elif a[i]>t[i]:
            if a[i]==a[i+1]:
                ans=(ans*t[i])%mod
            else:
                print(0)
                exit()
print(ans%mod)

Submission status: Wrong Answer

Solution code:
N = input()
T = map(int,raw_input().split())
A = map(int,raw_input().split())

if max(T) != max(A):
    print 0
else:
    if N == 1:
        print 1
    else:
        H = [None]*N
        p = -1
        for i in range(N):
            if p != T[i]:
                H[i] = T[i]
                p = T[i]
        p = -1
        for i in range(N)[::-1]:
            if p != A[i]:
                H[i] = A[i]
                p = A[i]
        a = 0
        m = -1
        count = 1
        for i in range(N):
            if m == -1 and H[i] != None:
                m = H[i]
            elif m != -1 and H[i] == None:
                a+=1
            elif m != -1 and H[i] != None:
                M = H[i]
                if a != 0:
                    count = (count*(min(M,m))**a)%(10**9+7)
                a = 0
                m = M
        print count

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
t = map(int, raw_input().split())
a = map(int, raw_input().split())
M = 10**9 + 7
ans = 1
m = [0] * n
if t[n-1] == a[0]:
    for i in xrange(n):
        m = min([t[i], a[i]])
        flag1 = False
        flag2 = False
        if i > 0:
            if t[i-1] < t[i]:
                flag1 = True
        else:
            flag1 = True
        if i < n-1:
            if a[i+1] < a[i]:
                flag2 = True
        else:
            flag2  = True
        #print m
        if flag2 and t[i] == m:
            ans = 0
            break
        if flag1 and a[i] == m:
            ans = 0
            break
        if not(flag1 or flag2):
            ans *= m
            ans %= M
else:
    ans = 0
print ans,

Submission status: Wrong Answer

Solution code:
s = input().split()

size = []
for n in s:
    size.append(int(n))

s2 = input().split()

sT = []
for n in s2:
    sT.append(int(n))

s3 = input().split()

sA = []
for n in s3:
    sA.append(int(n))


sh = [0]*size[0]

tt = 1
for t in range(0, size[0]):
    sh[t] = min (sA[t],sT[t])
for t in range(1,size[0] - 1):
    if (sh[t] == sh[t-1] and sh[t] >= sh[t+1]) or (sh[t] == sh[t+1] and sh[t] <= sh[t-1]):
        tt *= sh[t]
print(tt)

Submission status: Wrong Answer

Solution code:
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]:
			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]:
			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))

Submission status: Wrong Answer

Solution code:
n_mountain = int(input())
changed = [False for i in range(n_mountain)]

t_report = list(map(int, input().split()))
a_report = list(map(int, input().split()))

if max(t_report) != max(a_report):
	print(0)
else:
	for i in range(1, n_mountain):
		if t_report[i - 1] != t_report[i]:
			changed[i] = True
		if a_report[i - 1] != a_report[i]:
			changed[i - 1] = True
	changed[0] = changed[n_mountain -1 ] = True
	min_mountain = [min(a_report[i], t_report[i]) for i in range(n_mountain)]
	ans = 1
	for i in range(n_mountain):
		if changed[i] == False:
			ans *= min_mountain[i]
			ans %= 1000000007
			
	print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin
import numpy as np

n = stdin.readline()
n = n.strip().split(" ")
N = int(n[0])
n = stdin.readline()
n = n.strip().split(" ")
T = []
for t in n:
	T.append(int(t))
T = np.array(T)
n = stdin.readline()
n = n.strip().split(" ")
A = []
for a in n:
	A.append(int(a))
A = np.array(A)

arr = np.ones((len(A),))
res = 1
if max(A) != max(T):
	res = 0
else:
	for t in range(T.shape[0]):
		if t > 0 and T[t] == T[t-1] and t != T.shape[0]-1:
			arr[t] = T[t]
	for a in range(A.shape[0])[::-1]:
		if a < A.shape[0]-1 and a != 0 and arr[a] != 1:
			if A[a] > A[a+1]:
				arr[a] = 1
			elif A[a] < arr[a]:
				arr[a] = A[a]
			# elif A[a] == arr[a]:
			# 	pass
			# elif A[a] < arr[a]:
			# 	arr[a] = A[a]
	for j in arr:
		res *= j

res = res % ((10**9) + 7)
print int(res)

Submission status: Wrong Answer

Solution code:
N = int(input())
T = [int(t) for t in input().split()]
A = [int(a) for a in input().split()]

if(T[N-1]!=A[0]):
    print(0)
    exit()

P = 1

for i in range(1,N-1):
    t = 1 if T[i-1]<T[i] else T[i]
    a = 1 if A[i]>A[i+1] else A[i]
    P*=min(t,a)
    P%=1000000007

print(P)

Submission status: Wrong Answer

Solution code:
import sys

n = int(input())
t = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]

if t[n-1]!=a[0]:
    print(0)
    sys.exit()

m =[]
for i in range(n):
    mx = min(t[i],a[i])
    mn = 1
    if i == 0:
        mn = t[i]
    elif i == n-1:
        mn = a[i]
    else :
        if t[i]!=t[i-1] and mx == t[i]:
            mn=t[i]
        if a[i]!=a[i+1] and mx == a[i]:
            mn=a[i]
    m.append([mx,min(mx,mn)])

ans = 1
for i in range(n):
    ans = (ans * (m[i][0]-m[i][1]+1))%(10**9+7)
print(ans)

Submission status: Wrong Answer

Solution code:
N = input()
T = map(int,raw_input().split())
A = map(int,raw_input().split())

if max(T) != max(A):
    print 0
else:
    if N == 1:
        print 1
    else:
        H = [None]*N
        p = -1
        for i in range(N):
            if p != T[i]:
                H[i] = T[i]
                p = T[i]
        p = -1
        for i in range(N)[::-1]:
            if p != A[i]:
                H[i] = A[i]
                p = A[i]
        a = 0
        m = -1
        count = 0
        for i in range(N):
            if m == -1 and H[i] != None:
                m = H[i]
            elif m != -1 and H[i] == None:
                a+=1
            elif m != -1 and H[i] != None:
                M = H[i]
                if a != 0:
                    count = (count + (min(M,m))**a)%(10**9+7)
                a = 0
                m = M
        print count

Submission status: Wrong Answer

Solution code:
mod=10**9+7
n=int(raw_input())
t=map(int,raw_input().split())
a=map(int,raw_input().split())

if t[n-1]!=a[0]:
    print(0)
    exit()

ans=1
for i in xrange(n):
    if i==0 or i==n-1 or t[i]>t[i-1]:
        continue
    else:
        if t[i]==a[i]:
            if a[i]==a[i+1]:
                ans=(ans*t[i])%mod
        elif t[i]>a[i]:
            if a[i]==a[i+1]:
                ans=(ans*a[i])%mod
        elif a[i]>t[i]:
            if a[i]==a[i+1]:
                ans=(ans*t[i])%mod
            else:
                print(0)
                exit()
print(ans%mod)

Submission status: Wrong Answer

Solution code:
import sys

n = int(input())
t = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]

if t[n-1]!=a[0]:
    print(0)
    sys.exit()

m =[]
for i in range(n):
    mx = min(t[i],a[i])
    mn = 1
    if i == 0:
        mn = t[i]
    elif i == n-1:
        mn = a[i]
    else :
        if t[i]!=t[i-1]:
            mn=t[i]
        if a[i]!=a[i+1]:
            mn=a[i]
    m.append([mx,min(mx,mn)])

ans = 1
for i in range(n):
    ans = (ans * (m[i][0]-m[i][1]+1))%(10**9+7)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
n = input()
t = map(int, raw_input().split())
a = map(int, raw_input().split())
ans = 0
if max(t) != max(a):
    print ans
    sys.exit()
supermax = max(t)
flagt = 0
flaga = 0
for i in range(n):
    if flagt == 0 and t[i] == supermax:
        flagt = i
    if flaga == 0 and a[n-1-i] == supermax:
        flaga = n-1-i
if flagt > flaga:
    print ans
    sys.exit()


ans = 1
tmx = t[0]
dummy_a = a[0]
amx = a[n-1]
dummy_t = t[n-1]
if (n%2)==0:
    loop = n/2-1
else:
    loop = n/2
for i in range(loop):
    if t[i+1] <= a[i+1]:
        if t[i+1] == tmx:
            ans *= t[i+1]
    elif a[i+1] < dummy_a:
        print 0
        sys.exit()
    tmx = t[i+1]
    dummy_a = a[i+1]
    ans %= 1000000007
    if a[(n-1)-(i+1)] <= t[(n-1)-(i+1)]:
        if a[(n-1)-(i+1)] == amx:
            ans*= a[(n-1)-(i+1)]
    elif t[(n-1)-(i+1)] < dummy_t:
        print 0
        sys.exit()
    amx = a[(n-1)-(i+1)]
    dummy_t = t[(n-1)-(i+1)]
    ans %= 1000000007
print ans

Submission status: Wrong Answer

Solution code:
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]:
			h[i] = T[i]
		else:
			if h[i] < 0:
				h[i] = max(h[i],-T[i])
			elif h[i] == 0:
				h[i] = -T[i]
		if A[-i-1] > A[-i]:
			h[-i-1] = A[-i-1]
		else:
			if h[-i-1] < 0:
				h[-i-1] = max(h[-i-1],-A[-i-1])
			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))

Submission status: Wrong Answer

Solution code:
N = input()
T = map(int,raw_input().split())
A = map(int,raw_input().split())

if max(T) != max(A):
    print 0
else:
    if N == 1:
        print 1
    else:
        H = [None]*N
        p = -1
        for i in range(N):
            if p != T[i]:
                H[i] = T[i]
                p = T[i]
        p = -1
        for i in range(N)[::-1]:
            if p != A[i]:
                H[i] = A[i]
                p = A[i]
        print H
        a = 0
        m = -1
        count = 0
        for i in range(N):
            if m == -1 and H[i] != None:
                m = H[i]
            elif m != -1 and H[i] == None:
                a+=1
            elif m != -1 and H[i] != None:
                M = H[i]
                if a != 0:
                    count = (count + (min(M,m))**a)%(10**9+7)
                a = 0
                m = M
        print count

Submission status: Wrong Answer

Solution code:
N = int(raw_input())
T = map(int, raw_input().split())
A = map(int, raw_input().split())

ans = 1

if max(A) != max(T):
    ans = 0
else:
    for i in range(1, N-1):

        if T[i] > A[i]:
            ans *= A[i]
        elif T[i] < A[i]:
            ans *= T[i]

print ans % (10 ** 9 + 7)

Submission status: Wrong Answer

Solution code:
mod=10**9+7
n=int(raw_input())
t=map(int,raw_input().split())
a=map(int,raw_input().split())
"""
if t[n-1]!=a[0]:
    print(0)
    exit()
"""
ans=1
for i in xrange(n):
    if i==0 or i==n-1 or t[i]>t[i-1]:
        continue
    else:
        if t[i]==a[i]:
            if a[i]==a[i+1]:
                ans=(ans*t[i])%mod
        elif t[i]>a[i]:
            if a[i]==a[i+1]:
                ans=(ans*a[i])%mod
        elif a[i]>t[i]:
            if a[i]==a[i+1]:
                ans=(ans*t[i])%mod
            else:
                print(0)
                exit()
print(ans%mod)

Submission status: Wrong Answer

Solution code:
# def makelist(n, m):
# 	return [[0 for i in range(m)] for j in range(n)]

# n = int(input())
# a, b = map(int, input().split())
# s = input()


n = int(input())
T = list(map(int, input().split()))
A = list(map(int, input().split()))

Tsa = [0]*n
Asa = [0]*n

if n == 1:
	if T[0] != A[0]:
		print(0)
	else:
		print(1)
elif T[0] != A[-1]:
	print(0)
else:
	##
	dai = T[0]
	shou = T[0]
	Tsa[0] = (shou, dai)

	for i in range(1, n):
		if T[i] == dai:
			Tsa[i] = (shou, dai)
		else:
			shou = dai
			dai = T[i]
			Tsa[i] = (dai, dai)

	##
	dai = A[-1]
	shou = A[-1]
	Asa[-1] = (shou, dai)

	for i in reversed(range(-n, -1)):
		if A[i] == dai:
			Asa[i] = (shou, dai)
		else:
			shou = dai
			dai = A[i]
			Asa[i] = (dai, dai)

	ans = 1
	for i in range(n):
		d = max(Tsa[i][0], Asa[i][0])
		u = min(Tsa[i][1], Asa[i][1])

		if d > u:
			ans = 0
			break
		else:
			ans *= u - d + 1
	print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    takahashi = list(map(int, input().split()))
    aoki = list(map(int, input().split()))

    if max(takahashi) != max(aoki):
        print("0")
        return

    result = [-1 for i in range(N)]

    previous_value = -1
    for i, value in enumerate(takahashi):
        if previous_value < value:
            result[i] = value
            previous_value = value

    previous_value = -1
    for i, value in enumerate(reversed(aoki)):
        index = N-i-1
        if previous_value < value:
            result[index] = value
            previous_value = value

    min_value = -1
    counter = 0
    r_value = 1
    for i in range(N):
        if result[i] == -1:
            counter += 1
        elif counter>0:
            mlt = min(min_value, result[i])
            r_value *= mlt**counter
            min_value = result[i]
            counter = 0
        else:
            min_value = result[i]
    print(r_value%(10**9+7))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = input()
t = map(int, raw_input().split())
a = map(int, raw_input().split())

c = [False] * n
c[0], c[-1] = True, True
m = [0] * n
m[0] = t[0]
m[-1] = a[-1]
old = -1
i = 1
if n > 1:
    if a[0] != a[1] and a[0] != t[0]:
        print 0
        exit()
    elif t[-1] != t[-2] and t[-1] != a[-1]:
        print 0
        exit()

while i < n:
    if t[i] < t[i-1] or a[i] > a[i-1]:
        print 0
        exit()
    if t[i] != t[i-1]:
        c[i] = True
        m[i] = t[i]
    if a[i] != a[i-1]:
        if c[i-1] == True and m[i-1] != a[i-1]:
            print 0
            exit()
        m[i-1] = a[i-1]
        c[i-1] = True
    if c[i-1] == False:
        m[i-1] = min(a[i-1], t[i-1])
    i += 1
# print c
# print m
p = 1
for cc, mm in zip(c,m):
    if cc:
        continue
    p *= mm
    p %= (10**9)+7
print p

Submission status: Wrong Answer

Solution code:
N = int(raw_input())
T = raw_input().split(' ')
A = raw_input().split(' ')
yama = [0] * N
high_think = [0] * N
max_numT = 0
max_numA = 0
sum_num = 1
for i in range(0, N/2):
  temp = int(T[i])
  if max_numT < temp:
    max_numT = temp
    yama[i] = temp
  high_think[i] = max_numT
  temp = int(A[-1 - i])
  if max_numA < temp:
    max_numA = temp
    yama[-1 - i] = temp
  high_think[-1-i] = max_numA

if (N%2 == 1):
  i = i + 1
  if max_numT < int(T[i]):
    yama[i] == int(T[i])
  elif max_numA < int(A[-1-i]):
    yama[i] == int(A[-1-i])
  else:
    high_think[i] = min(max_numT, max_numA)

print yama
print high_think

for i in range(0, N):
  if yama[i] == 0:
    sum_num *= high_think[i]

if (T[-1] == A[0]):
  print sum_num % (10**9 + 7)
else:
  print "0"

Submission status: Wrong Answer

Solution code:
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]:
			h[i] = T[i]
		else:
			if h[i] < 0:
				h[i] = max(h[i],-T[i])
			elif h[i] == 0:
				h[i] = -T[i]
		if A[-i-1] > A[-i]:
			h[-i-1] = A[-i-1]
		else:
			if h[-i-1] < 0:
				h[-i-1] = max(h[-i-1],-A[-i-1])
			elif h[-i-1] == 0:
				h[-i-1] = -A[-i-1]
print(h)
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))

Submission status: Wrong Answer

Solution code:
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]:
			h[i] = T[i]
		else:
			if h[i] < 0:
				h[i] = max(h[i],-T[i])
			elif h[i] == 0:
				h[i] = -T[i]
		if A[-i] > A[-i+1]:
			h[-i] = A[-i]
		else:
			if h[-i] < 0:
				h[-i] = max(h[-i],-A[-i])
			elif h[-i] == 0:
				h[-i] = -A[-i]
print(h)
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))

Submission status: Wrong Answer

Solution code:
n = input()
t = map(int, raw_input().split())
a = map(int, raw_input().split())

c = [False] * n
c[0], c[-1] = True, True
m = [0] * n
m[0] = t[0]
m[-1] = a[-1]
old = -1
i = 1
if a[0] != a[1] and a[0] != t[0]:
    print 0
    exit()
elif t[-1] != t[-2] and t[-1] != a[-1]:
    print 0
    exit()
    
while i < n:
    if t[i] < t[i-1] or a[i] > a[i-1]:
        print 0
        exit()
    if t[i] != t[i-1]:
        c[i] = True
        m[i] = t[i]
    if a[i] != a[i-1]:
        if c[i-1] == True and m[i-1] != a[i-1]:
            print 0
            exit()
        m[i-1] = a[i-1]
        c[i-1] = True
    if c[i-1] == False:
        m[i-1] = min(a[i-1], t[i-1])
    i += 1
# print c
# print m
p = 1
for cc, mm in zip(c,m):
    if cc:
        continue
    p *= mm
    p %= (10**9)+7
print p

Submission status: Wrong Answer

Solution code:
N = int(input())
l = input()
tm = [int(x) for x in l.split()]
l = input()
am = [int(x) for x in l.split()]
prev = -1
th = []
ah = []
rh = []
for t in tm:
	if t!=prev:
		rh.append([t,t])
		prev = t
	else:
		rh.append([1,t])
print(rh)
prev = -1
am.reverse()
rh.reverse()
p = 1
for i in range(len(am)):
	a = am[i]
	print(a)
	print(rh[i])
	if a!=prev:
		if rh[i][0]<=a<=rh[i][1]:
			rh[i] = [a,a]
			print(a,'->',rh[i])
		else:
			p*=0
			break
		prev = a
	else:
		if rh[i][1] == rh[i][0]:
			pass
		elif rh[i][1]>=a:
			rh[i] = [1,a]
			print(a,'=>',rh[i])
			p*=a
		else:
			p*=0
			break
print(p)

Submission status: Wrong Answer

Solution code:
mod=10**9+7
n=int(raw_input())
t=map(int,raw_input().split())
a=map(int,raw_input().split())

if t[n-1]!=a[0]:
    print(0)
    exit()

ans=1
for i in xrange(n):
    if i==0 or i==n-1 or t[i]>t[i-1]:
        continue
    elif t[i]==t[i-1]:
        if t[i]==a[i]:
            if a[i]==a[i+1]:
                ans=(ans*t[i])%mod
        elif t[i]>a[i]:
            if a[i]==a[i+1]:
                ans=(ans*a[i])%mod
        elif a[i]>t[i]:
            if a[i]==a[i+1]:
                ans=(ans*t[i])%mod
    else:
        print(0)
        exit()
print(ans%mod)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

import functools


MOD = 10 ** 9 + 7
INF = MOD


def product_mod(seq, mod=MOD):
    return functools.reduce(lambda x, y: x * y % mod, seq, 1) % mod


class Mountain(object):

    def __init__(self, ub=INF, lb=1):
        self.ub = ub
        self.lb = lb

    def __repr__(self):
        return "({}, {})".format(self.lb, self.ub)


def main():
    n = int(input())
    xs = [int(x) for x in input().split()]
    ys = [int(y) for y in input().split()]
    if xs[-1] != ys[0]:
        print(0)
        return
    ms = [Mountain() for _ in range(n)]
    ms[0].ub = ms[0].lb = xs[0]
    ms[-1].ub = ms[-1].lb = ys[-1]
    for idx in range(1, n - 1):
        if xs[idx - 1] < xs[idx]:
            ms[idx].ub = ms[idx].lb = xs[idx]
        else:
            ms[idx].ub = xs[idx]
    for idx in range(1, n - 1)[::-1]:
        if ys[idx + 1] < ys[idx]:
            ms[idx].ub = ms[idx].lb = ys[idx]
        else:
            ms[idx].ub = ys[idx]
    ans = product_mod(m.ub - m.lb + 1 for m in ms)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
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]:
			h[i] = T[i]
		else:
			if h[i] < 0:
				h[i] = max(h[i],-T[i])
			elif h[i] == 0:
				h[i] = -T[i]
		if A[-i] > A[-i+1]:
			h[-i] = A[-i]
		else:
			if h[-i] < 0:
				h[-i] = max(h[-i],-A[-i])
			elif h[-i] == 0:
				h[-i] = -A[-i]
a = 1
for n in h:
	if n < -1:
		a *= -n
print(a%(10**9+7))

Submission status: Wrong Answer

Solution code:
n = input()
t = map(int, raw_input().split())
a = map(int, raw_input().split())

c = [False] * n
c[0], c[-1] = True, True
m = [0] * n
m[0] = t[0]
m[-1] = a[-1]
old = -1
i = 1
while i < n:
    if t[i] < t[i-1] or a[i] > a[i-1]:
        print 0
        exit()
    if t[i] != t[i-1]:
        c[i] = True
        m[i] = t[i]
    if a[i] != a[i-1]:
        if c[i-1] == True and m[i-1] != a[i-1]:
            print 0
            exit()
        m[i-1] = a[i-1]
        c[i-1] = True
    if c[i-1] == False:
        m[i-1] = min(a[i-1], t[i-1])
    i += 1
# print c
# print m
p = 1
for cc, mm in zip(c,m):
    if cc:
        continue
    p *= mm
    p %= (10**9)+7
print p

Submission status: Wrong Answer

Solution code:
import sys
n = input()
t = map(int, raw_input().split())
a = map(int, raw_input().split())
ans = 0
if max(t) != max(a):
    print ans
    sys.exit()
supermax = max(t)
flagt = 0
flaga = 0
for i in range(n):
    if flagt == 0 and t[i] == supermax:
        flagt = i
    if flaga == 0 and a[n-1-i] == supermax:
        flaga = n-1-i
if flagt > flaga:
    print ans
    sys.exit()


ans = 1
tmx = t[0]
amx = a[n-1]
if (n%2)==0:
    loop = n/2-1
else:
    loop = n/2
for i in range(loop):
    if t[i+1] <= a[i+1]:
        if t[i+1] == tmx:
            ans *= t[i+1]
    tmx = t[i+1]
    ans %= 1000000007
    if a[(n-1)-(i+1)] <= t[(n-1)-(i+1)]:
        if a[(n-1)-(i+1)] == amx:
            ans*= a[(n-1)-(i+1)]
    amx = a[(n-1)-(i+1)]
    ans %= 1000000007
print ans

Submission status: Wrong Answer

Solution code:
N = input()
T = map(int,raw_input().split(" "))
A = map(int,raw_input().split(" "))




note = [1 for i in range(N)]
fx = [0 for i in range(N)]

def solve():
    global note
    if T[-1] != A[0]:
        return 0
    
    prev = 0
    for i in range(N):
        if prev > T[i]:
            return 0
        elif prev == T[i]:
            note[i] = prev
        else:
            note[i] = 1
            prev = T[i]
            fx[i] = T[i]
    prev = 0
    for i in range(N-1,-1,-1):
        if prev > A[i]:
            return 0
        elif prev == A[i]:
            if not fx[i]:
                note[i] = min(note[i],prev)
        else:
            if fx[i] and fx[i] != A[i]:
                return 0
            note[i] = 1
            prev = A[i]

    ans = 1
    for i in range(N):
        if not fx[i]:
            ans = (ans * note[i])%(10**9+7)
    return ans



    





print solve()

Submission status: Wrong Answer

Solution code:
def work(n, t, a):
    if t[-1] != a[0]:
        return 0
    for i in xrange(n):
        if t[i] == a[i]:
            if t[i] != t[-1] or t[i] != a[0]:
                return 0
            break

    record = [None] * n
    left, right = 0, n - 1

    while left <= right and t[left] < a[left]:
        if not left or t[left] > t[left-1]:
            record[left] = 1
        else:
            record[left] = t[left]
        left += 1
    
    record[left] = 1
    while left < right and a[right] <= t[right]:
        if right == n - 1 or a[right] > a[right+1]:
            record[right] = 1
        else:
            record[right] = a[right]
        right -= 1

    ans = 1
    for i in xrange(n):
        ans = (ans*record[i]) % (10**9+7)
    return ans


n = int(raw_input())
t = map(int, raw_input().split())
a = map(int, raw_input().split())

print work(n, t, a)

Submission status: Wrong Answer

Solution code:
n = int(input())
ts = list(map(int, input().split()))
xs = list(map(int, input().split()))


if n == 1:
    print(1)
else:
    m = 10**9 + 7
    if xs[0]!=xs[1] and xs[0]!=ts[0]:
        a = 0
    elif ts[-1]!=ts[-2] and ts[-1]!=xs[-1]:
        a = 0
    else:
        a = 1
    for i in range(1, n-1):
        if ts[i-1]==ts[i] and xs[i]==xs[i+1]:
            a = a*min(ts[i], xs[i]) % m
        else:
            if ts[i-1]<ts[i] and xs[i]>xs[i+1]:
                if ts[i]!=xs[i]:
                    a = 0
            elif ts[i-1]<ts[i]:
                if xs[i]<ts[i]:
                    a = 0
            else:
                if ts[i]<xs[i]:
                    a = 0
    print(a)

Submission status: Wrong Answer

Solution code:
n = input()
t = map(int, raw_input().split())
a = map(int, raw_input().split())

c = [False] * n
c[0], c[-1] = True, True
m = [0] * n
m[0] = t[0]
m[-1] = a[-1]
old = -1
i = 1
while i < n:
    if t[i] < t[i-1] or a[i] > a[i-1]:
        print 0
        exit()
    if t[i] != t[i-1]:
        c[i] = True
        m[i] = t[i]
    if a[i] != a[i-1]:
        if c[i-1] == True and m[i-1] != a[i-1]:
            print 0
            exit()
        m[i-1] = a[i-1]
        c[i-1] = True
    if c[i-1] == False:
        m[i-1] = min(a[i-1], t[i-1])
    i += 1
print c
print m
p = 1
for cc, mm in zip(c,m):
    if cc:
        continue
    p *= mm
    p %= (10**9)+7
print p

Submission status: Wrong Answer

Solution code:
N = int(input())
T = list(map(int,input().split()))
A = list(map(int,input().split()))
B = [0] * N

h = 0
for i in range(N):
    if h < T[i]:
        B[i] = T[i] 
        h = T[i] 
h = 0
check = True
for i in range(N):
    if h < A[N-i-1]:
        if B[N-i-1] != 0 and B[N-i-1] != A[N-i-1]:
            check = False
        else:
            B[N-i-1] = A[N-i-1]
            h = A[N-i-1]

for i in range(N):
    if B[i] == 0:
        B[i] = min((T[i],A[i]))
    else:
        B[i] = 1

if check:
    ans = 1
    for i in range(N):
        ans = (ans * B[i]) % (int(1e9 + 7))
    print(ans)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
#coding: utf-8

def main():
    N = int(input())
    t = list(map(int, input().split()))
    a = list(reversed(list(map(int, input().split()))))

    m = [0] * N

    b = 0
    for i,h in enumerate(t):
        if b != h:
            m[i] = h#確定
            if a[i] < h:
                print(0)
                return
        b = h
    b = 0
    for j,h in enumerate(a):
        p = N-j-1
        if b != h:
            if m[p] != 0 and m[p] != h:
                print(0)
                return
            else:
                m[p] = h#確定
                if t[p] < h:
                    print(0)
                    return
        b = h
    res = 1
    for k,h in enumerate(m):
        if h == 0:
            res = res * min(a[N-k-1], t[k]) % (pow(10, 9) + 7)
    print(res)
    return

main()

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
t = map(int, raw_input().split())
a = map(int, raw_input().split())
M = 10**9 + 7
ans = 1
m = [0] * n
if t[n-1] == a[0]:
    for i in xrange(n):
        m = min([t[i], a[i]])
        flag1 = False
        flag2 = False
        if i > 0:
            if t[i-1] < t[i]:
                flag1 = True
        else:
            flag1 = True
        if i < n-1:
            if a[i+1] < a[i]:
                flag2 = True
        else:
            flag2  = True
        #print m
        if not(flag1 or flag2):
            ans *= m
            ans %= M
else:
    ans = 0
print ans,