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:
#! /usr/bin/env python3

def main():
    d = 10 ** 9 + 7
    ans = 1
    N = int(input())
    T = list(map(int, input().split())) #>>>
    A = list(map(int, input().split())) #<<<
    SH = [-1] * len(T)
    if T[-1] != A[0] : return 0
    h = 0
    c = 0
    for i in T:
        if i > h:
            SH[c] = h = i
        c += 1
    h = 0
    c = len(A) -1
    for i in A[::-1]:
        if i > h:
            if SH[c] > 0 and i != SH[c]:
                ans = 0
                return 0
            SH[c] = h = i
        c -= 1
    for i in range(len(T)):
        if SH[i] < 0:
            ans *= min(T[i], A[i])
    return ans % d
    
if __name__ == '__main__':
    print(main())

Submission status: Wrong Answer

Solution code:

def read():
    return int(input())

def reads(sep=None):
    return list(map(int, input().split(sep)))

def main():
    m = 10**9 + 7
    n = read()
    t = reads()
    a = reads()
    if (t != sorted(t)) or (a != sorted(a, reverse=True)) or (max(t) != max(a)):
        print(0)
        return
    if len([1 for ti,ai in zip(t, a) if ti==ai]) == 0:
        print(0)
        return
    
    b = [0] * n
    o = -1
    for i in range(0, n):
        if o != t[i]:
            b[i] = 1
            o = t[i]
    o = -1
    for i in range(n-1, -1, -1):
        if o != a[i]:
            b[i] = 1
            o = a[i]
    r = 1
    for i in range(0, n):
        if b[i] == 0:
            r = (r * min(t[i], a[i])) % m
    print(r)

main()

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]
    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:

def read():
    return int(input())

def reads(sep=None):
    return list(map(int, input().split(sep)))

def main():
    m = 10**9 + 7
    n = read()
    t = reads()
    a = reads()
    if (t != sorted(t)) or (a != sorted(a, reverse=True)) or (max(t) != max(a)):
        print(0)
        return
    if len([1 for ti,ai in zip(t, a) if ti==ai]) == 0:
        print(0)
    
    b = [0] * n
    o = -1
    for i in range(0, n):
        if o != t[i]:
            b[i] = 1
            o = t[i]
    o = -1
    for i in range(n-1, -1, -1):
        if o != a[i]:
            b[i] = 1
            o = a[i]
    r = 1
    for i in range(0, n):
        if b[i] == 0:
            r = (r * min(t[i], a[i])) % m
    print(r)

main()

Submission status: Wrong Answer

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

p = [False for i in range(n)]
p[0] = True

for i in range(1, n):
    if t[i] > t[i - 1]:
        p[i] = True
        if a[i] < t[i]:
            print(0)
            exit()

p[n - 1] = True

for i in range(n - 2, -1, -1):
    if a[i] > a[i + 1]:
        p[i] = True
        if t[i] < a[i]:
            print(0)
            exit()
h=[min(t[i],a[i]) for i in range(n)]
mod = 10**9 + 7
total = 1
for i in range(1,n-1):
    if not p[i]:
        total = (total * h[i]) % mod
print(total)

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(" "))
INF = 10**9 + 5




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 = 1
    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] = 1

    prev = 1
    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:
            note[i] = 1
            prev = A[i]
            fx[i] = 1

    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:
#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#確定
        b = h
    b = 0
    for j,h in enumerate(a):
        if b != h:
            if m[N-j-1] != 0 and m[N-j-1] != h:
                print(0)
                return
            else:
                m[N-j-1] = h#確定
        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)

main()

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],r[i])
print(res%1000000007)

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
if(max(l)!=max(r)):
	res=0
for i in range(n):
	if( (l[i]<l[i+1]) or (r[i]>r[i+1]) ):
		
			res*=0
	else:
		res*=min(l[i],r[i])
print(res%1000000007)

Submission status: Wrong Answer

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

h = [t[i] for i in range(n)]
p = [False for i in range(n)]
p[0] = True

for i in range(1, n):
    if t[i] > t[i - 1]:
        p[i] = True

h[n - 1] = a[n - 1]
p[n - 1] = True

for i in range(n - 2, -1, -1):
    if a[i] > a[i + 1]:
        p[i] = True
        if t[i] < a[i]:
            print(0)
            exit()
    elif p[i] and t[i] > a[i]:
        print(0)
        exit()
    h[i] = min(t[i], a[i])

mod = 10**9 + 7
total = 1
for i in range(1,n-1):
    if not p[i]:
        total = (total * h[i]) % mod
print(total)

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

main()

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()
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]
    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:

def read():
    return int(input())

def reads(sep=None):
    return list(map(int, input().split(sep)))

def main():
    m = 10**9 + 7
    n = read()
    t = reads()
    a = reads()
    if (t != sorted(t)) or (a != sorted(a, reverse=True)) or (max(t) != max(a)):
        print(0)
        return
    
    b = [0] * n
    o = -1
    for i in range(0, n):
        if o != t[i]:
            b[i] = 1
            o = t[i]
    o = -1
    for i in range(n-1, -1, -1):
        if o != a[i]:
            b[i] = 1
            o = a[i]
    r = 1
    for i in range(0, n):
        if b[i] == 0:
            r = (r * min(t[i], a[i])) % m
    print(r)

main()

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
t = map(int, raw_input().split())
a = map(int, raw_input().split())
mi = [1 for i in range(n)]
ma = [10**9 for i in range(n)]
for i, e in enumerate(t):
    if i == 0:
        mi[i] = e
        ma[i] = e
    else:
        if e > t[i-1]:
            mi[i] = e
            ma[i] = e
        elif e == t[i-1]:
            ma[i] = e
        else:
            print 0
            exit()

a = a[::-1]
mi = mi[::-1]
ma = ma[::-1]

for i, e in enumerate(a):
    if i == 0:
        if mi[i] <= e <= ma[i]:
            mi[i] = e
            ma[i] = e
        else:
            print mi
            print ma
            print 0
            exit()
    else:
        if e > a[i-1]:
            if mi[i] <= e <= ma[i]:
                mi[i] = e
                ma[i] = e
            else:
                print 0
                exit()
        elif e == a[i-1]:
            if mi[i] <= e <= ma[i]:
                ma[i] = e
        else:
            print 0
            exit()
res = 1
for i in range(n):
    res *= ma[i] - mi[i] + 1
    res = res % (10**9+7)
print res % (10**9+7)

Submission status: Wrong Answer

Solution code:
N = int(input())
T = list(map(int, input().split()))
A = list(map(int, input().split()))
if T[-1] != A[0]:
	print(0)
else:
	h = [0 for i in range(N)]
	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])
			else:
				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])
			else:
				h[i] = -A[i]
a = 0
for n in h:
	if n < -1:
		a *= -(n+1)
print(a)

Submission status: Wrong Answer

Solution code:
import bisect
import sys
import math
import itertools
sys.setrecursionlimit(10000)

INF = float('inf')

# input macro
def i():
    return int(raw_input())
def ii():
    return map(int,raw_input().split(" "))
def s():
    return raw_input()
def ss():
    return raw_input().split(" ")
def slist():
    return list(raw_input())
def join(s):
    return ''.join(s)

#memoize macro
def memoize(f):
    cache = {}
    def helper(*args):
        if args not in cache:
            cache[(args)] = f(*args)
        return cache[args]
    return helper

nh=zip([1,0,-1,0],[0,1,0,-1])
mod=1000000007

###########
n=i()
t=ii()
a=ii()
just=[0]*n
ub=[INF]*n
lb=[0]*n
just[0]=t[0]
just[n-1]=a[n-1]

def justa(x,y):
    if just[x] in [0,y]:
        just[x]=y
    else:
        print '0'
        sys.exit()
        
for j in range(1,n):
    if t[j]!=t[j-1]:
        justa(j,t[j])
    else:
        ub[j]=t[j]
for j in reversed(range(0,n-1)):
    if a[j]!=a[j+1]:
        justa(j,a[j])
    else:
        ub[j]=min(ub[j],a[j])

ans=1
for j in range(1,n):
    if just[j]==0:
        ans=ans*ub[j]%mod
    elif just[j]<=ub[j]:
        ans=ans
    else:
        print '0'
        sys.exit()

print ans

Submission status: Wrong Answer

Solution code:
import bisect
import sys
import math
import itertools
sys.setrecursionlimit(10000)

INF = float('inf')

# input macro
def i():
    return int(raw_input())
def ii():
    return map(int,raw_input().split(" "))
def s():
    return raw_input()
def ss():
    return raw_input().split(" ")
def slist():
    return list(raw_input())
def join(s):
    return ''.join(s)

#memoize macro
def memoize(f):
    cache = {}
    def helper(*args):
        if args not in cache:
            cache[(args)] = f(*args)
        return cache[args]
    return helper

nh=zip([1,0,-1,0],[0,1,0,-1])
mod=1000000007

###########
n=i()
t=ii()
a=ii()
just=[0]*n
ub=[INF]*n
lb=[0]*n
just[0]=t[0]
just[n-1]=a[n-1]

def justa(x,y):
    if just[x] in [0,y]:
        just[x]=y
    else:
        print '0'
        sys.exit()
        
for j in range(1,n):
    if t[j]!=t[j-1]:
        justa(j,t[j])
    else:
        ub[j]=t[j]
for j in reversed(range(0,n-1)):
    if a[j]!=a[j+1]:
        justa(j,a[j])
    else:
        ub[j]=min(ub[j],a[j])

ans=1
print just
print ub
print lb
for j in range(1,n):
    if just[j]==0:
        ans=ans*ub[j]%mod
    elif just[j]<=ub[j]:
        ans=ans
    else:
        print '0'
        sys.exit()

print ans

Submission status: Wrong Answer

Solution code:
N = int(input())
T = list(map(int, input().split()))
A = list(map(int, input().split()))
if T[-1] != A[0]:
	print(0)
else:
	h = [0 for i in range(N)]
	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])
			else:
				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])
			else:
				h[i] = -A[i]
a = 0
for n in h:
	if n < 0:
		a *= -n
print(a)

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
flag = [False] * n
if t[n-1] == a[0]:
    for i in xrange(n):
        m[i] = min([t[i], a[i]])
        if (i > 0 and t[i-1] >= t[i]) and (i < n-1 and a[i+1] >= a[i]):
            ans *= m[i]
            ans %= M
else:
    ans = 0
print ans,

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())
Tmax = list(map(int, input().split()))
Amax = list(map(int, input().split()))

Tmin = [0]*n
Amin = [0]*n

sto = Tmax[0]
Tmin[0] = Tmax[0]
for i in range(1, n):
	if i == n:
		Tmin[i] == Tmax[i]
	elif Tmax[i] == sto:
		Tmin[i] = Tmax[i]
	else:
		if Tmax[i+1] == Tmax[i]:
			Tmin[i] = sto
		else:
			sto = Tmax[i]
			Tmin = Tmax[i]

sto = Amax[-1]
Amin[-1] = Amax[-1]
for i in reversed(range(-n, -1)):
	if i == -n:
		Amin[-n] == Amax[-n]
	elif Amax[i] == sto:
		Amin[i] = Amax[i]
	else:
		if Amax[i-1] == Amax[i]:
			Amin[i] = sto
		else:
			sto = Amax[i]
			Amin = Amax[i]

sa = [0]*n
for i in range(n):
	maxi = min(Tmax[i], Amax[i])
	mini = max(Tmin[i], Amin[i])

	sa[i] = (maxi, mini)

if Tmax[-1] != Amax[-1]:
	print(0)
else:
	ans = 1
	for i in range(n):
		now = sa[i]
		if now[1] > now[0]:
			ans = 0
			break
		else:
			ans *= (now[0] - now[1] + 1)
	print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import math,string,itertools,fractions,heapq,collections,re,array,bisect

def s():
    return raw_input().strip()
def n():
    return int(raw_input())
def d():
    return float(raw_input())

def ls():
    return raw_input().strip().split()
def ln():
    return map(int, raw_input().strip().split())
def ld():
    return map(float, raw_input().strip().split())

def fs():
    return [raw_input().strip() for i in xrange(input())]
def fn():
    return [int(raw_input().strip()) for i in xrange(input())]
def fd():
    return [float(raw_input().strip()) for i in xrange(input())]

EPS = 1e-9

#http://www.deqnotes.net/acmicpc/2d_geometry/lines
def dot(a, b):
    return a.real * b.real + a.imag * b.imag

def cross(a, b):
    return a.real * b.imag - a.imag * b.real

def distance(a, b, c):
    if dot(b-a, c-a) <= EPS:
        return abs(c-a)
    if dot(a-b, c-b) <= EPS:
        return abs(c-b)
    return abs(cross(b-a, c-a)/(b-a))

N = n()
T = ln()
A = ln()

fixed = [-1] * N

before = -1
lte = [10**10] * N

for i in xrange(N):
    if T[i] > before:
        fixed[i] = T[i]
        before = T[i]
        if T[i] > A[i]:
            ok = False
    else:
        if lte[i] > before:
            lte[i] = before

ok = True

before = -1
for i in xrange(N - 1, -1, -1):
    if A[i] > before:
        fixed[i] = A[i]
        before = A[i]
        if A[i] > T[i]:
            ok = False
    else:
        if lte[i] > before:
            lte[i] = before

comb = 1

for i in xrange(N):
    if fixed[i] == -1:
        comb *= lte[i]
        comb %= 10**9 + 7

if ok:
    print comb
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
flag = [False] * n
if t[n-1] == a[0]:
    for i in xrange(n):
        m[i] = min([t[i], a[i]])
        if (i > 0 and t[i-1] >= t[i]) and (i < n-1 and a[i+1] >= a[i]):
            ans *= m[i]
            ans %= M
print ans,

Submission status: Wrong Answer

Solution code:
import math
import sys

N = input()
T = [int(i) for i in raw_input().split()]
A = [int(i) for i in raw_input().split()]

ans = 1

for i in range(N):
#    if(i==0 or i==N-1):
#        continue
    
    if(T[i-1]!=T[i] and T[i]>A[i]):
        print '0'
        sys.exit()
    
    if(T[i-1]>T[i]):
        continue

    if(i==N-1):
        continue

    if(A[i+1]!=A[i] and A[i]>T[i]):
        print '0'
        sys.exit()
    
    if(A[i+1]>A[i]):
        continue

    if(i==0):
        continue

    if((T[i-1]!=T[i])or(A[i+1]!=A[i])):
        continue

    else:
        ans *= min(T[i],A[i])
        ans %= 1000000007

    

print ans

Submission status: Wrong Answer

Solution code:
def times(A):
    ret = A[0]
    for i in A[1:]:
        ret = (i * ret) % 1000000007
    return ret % 1000000007

N = input()
T = map(int, raw_input().strip().split(' '))
A = map(int, raw_input().strip().split(' '))
limit = [1000000005 for i in xrange(N)]

cur = T[0]
limit[0] = 1
limit[-1] = 1
flag = True
for i in xrange(1, N):
    if T[i] > cur:
        if T[i] > A[i]:
            print 0
            flag = False
            break
        cur = T[i]
        limit[i] = 1
    elif T[i] == cur:
        if i == N-1 and T[i] < A[i]:
            print 0
            flag = False
            break
        limit[i] = min(limit[i], T[i])
    else:
        print 0
        flag = False
        break
# print limit
cur = A[-1]
if flag:
    for i in xrange(N-2, -1, -1):
        if A[i] > cur:
            if A[i] > T[i]:
                print 0
                flag = False
                break
            limit[i] = 1
            cur = A[i]
        elif A[i] == cur:
            if i == 0 and A[i] < T[i]:
                print 0
                flag = False
                break
            limit[i] = min(limit[i], A[i])
        else:
            print 0
            flag = False
            break
# print limit
if flag: print times(limit)

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)]
h[0] = t[0]
p = [False for i in range(n)]
p[0] = True

for i in range(1, n):
    if t[i] > t[i - 1]:
        p[i] = True
    elif t[i] < t[i - 1]:
        print(0)
        exit()
    h[i] = t[i]

h[n - 1] = a[n - 1]
p[n - 1] = True

for i in range(n - 2, -1, -1):
    if a[i] > a[i + 1]:
        p[i] = True
        if t[i] < a[i]:
            print(0)
            exit()
    elif a[i] < a[i + 1]:
        print(0)
        exit()
    elif p[i] and t[i] > a[i]:
        print(0)
        exit()
    h[i] = min(t[i], a[i])

mod = 10**9 + 7
total = 1
for i in range(n):
    if not p[i]:
        total = (total * h[i]) % mod
print(total)

Submission status: Wrong Answer

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

fixed_peek_t = {}
unfixed_peek_t = {}
fixed_peek_a = {}
unfixed_peek_a = {}

lp = 0
for idx, height in enumerate(T):
    if lp < height:
        fixed_peek_t[idx] = height
    elif idx not in fixed_peek_t:
        unfixed_peek_t[idx] = height
    lp = height

lp = 0
for _idx, height in enumerate(reversed(A)):
    idx = N-1 - _idx
    if lp < height:
        fixed_peek_a[idx] = height
    elif idx not in fixed_peek_a:
        unfixed_peek_a[idx] = height
    lp = height

# print(unfixed_peek_t)
# print(fixed_peek_t)
# print(unfixed_peek_a)
# print(fixed_peek_a)

if max(A) != max(T):
    print(0)
else:
    failflag = 0
    for k,v in fixed_peek_t.items():
        if k not in fixed_peek_a:
            continue
        if v != fixed_peek_a[k]:
            failflag = 1
            break
    if failflag == 0:
        cnt = 1
        for k,v in unfixed_peek_t.items():
            if k not in unfixed_peek_a:
                continue
            cnt *= min(v, unfixed_peek_a[k])
            cnt %= 10**9 + 7

        print(cnt)
    else:
        print(0)

Submission status: Wrong Answer

Solution code:
import math
import sys

N = input()
T = [int(i) for i in raw_input().split()]
A = [int(i) for i in raw_input().split()]

ans = 1

for i in range(N):
#    if(i==0 or i==N-1):
#        continue
    
    if(T[i-1]!=T[i] and T[i]>A[i]):
        print '0'
        sys.exit()
        
    if(i==N-1):
        continue

    if(A[i+1]!=A[i] and A[i]>T[i]):
        print '0'
        sys.exit()
    
    if(i==0):
        continue

    if((T[i-1]!=T[i])or(A[i+1]!=A[i])):
        continue

    else:
        ans *= min(T[i],A[i])
        ans %= 1000000007
print ans

Submission status: Wrong Answer

Solution code:
def times(A):
    ret = A[0]
    for i in A[1:]:
        ret = (i * ret) % 1000000007
    return ret % 1000000007

N = input()
T = map(int, raw_input().strip().split(' '))
A = map(int, raw_input().strip().split(' '))
limit = [1000000005 for i in xrange(N)]

cur = T[0]
limit[0] = 1
limit[-1] = 1
flag = True
for i in xrange(1, N):
    if T[i] > cur:
        if T[i] > A[i]:
            print 0
            flag = False
            break
        cur = T[i]
        limit[i] = 1
    elif T[i] == cur:
        if i == N-1 and T[i] < A[i]:
            print 0
            flag = False
            break
        limit[i] = min(limit[i], T[i])
    else:
        print 0
        flag = False
        break
# print limit
cur = A[-1]
if flag:
    for i in xrange(N-2, -1, -1):
        if A[i] > cur:
            if A[i] > T[i]:
                print 0
                flag = False
                break
            limit[i] = 1
            cur = A[i]
        elif A[i] == cur:
            if i == 0 and A[i] < T[i]:
                print 0
                flag = False
                break
            limit[i] = min(limit[i], A[i])
        else:
            print 0
            flag = False
            break

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
if(max(l)!=max(r)):
	res=0
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],r[i])
		res%=1000000007
print(res)

Submission status: Wrong Answer

Solution code:
import sys
def range_union(al,ah,bl,bh):
    cl = max(al,bl)
    ch = min(ah,bh)
    if cl > ch:
        return 0
    else:
        return ch-cl +1

N = int(sys.stdin.readline())
T = map(int,sys.stdin.readline().strip().split())
A = map(int,sys.stdin.readline().strip().split())

p = 1
if N >= 2:
    if A[0] > A[1] and A[0] != T[0]\
     or  A[0] == A[1] and A[0] < T[0]\
     or A[0] < A[1] :
        print 0
        exit(0)
    if T[-1] > T[-2] and A[-1] != T[-1]\
     or  T[-1] == T[-2] and T[-1] < A[-1]\
     or T[-1] < T[-2] :                                                                                                                                                                                                               
        print 0
        exit(0)
        
        
for i in xrange(1,N-1):
    if T[i-1] < T[i]:
        Tl = T[i]
        Th = T[i]
    elif T[i-1] == T[i]:
        Tl = 1
        Th = T[i]
    else:
        p = 0
        break
        
    if A[i] > A[i+1]:
        Al = A[i]
        Ah = A[i]
    elif A[i+1] == A[i]:
        Al = 1
        Ah = A[i]
    else:
        p = 0
        break

    r = range_union(Tl,Th,Al,Ah)
    if not r:
        p = 0
        break
    else:
        p = (p*r) % 1000000007

print p

Submission status: Wrong Answer

Solution code:
def times(A):
    ret = A[0]
    for i in A[1:]:
        ret = (i * ret) % 1000000007
    return ret % 1000000007

N = input()
T = map(int, raw_input().strip().split(' '))
A = map(int, raw_input().strip().split(' '))
limit = [1000000005 for i in xrange(N)]

cur = T[0]
limit[0] = 1
limit[-1] = 1
flag = True
for i in xrange(1, N):
    if T[i] > cur:
        if T[i] > A[i]:
            print 0
            flag = False
            break
        cur = T[i]
        limit[i] = 1
    else:
        if i == N-1 and T[i] < A[i]:
            print 0
            flag = False
            break
        limit[i] = min(limit[i], T[i])
# print limit
cur = A[-1]
if flag:
    for i in xrange(N-2, -1, -1):
        if A[i] > cur:
            if A[i] > T[i]:
                print 0
                flag = False
                break
            limit[i] = 1
            cur = A[i]
        else:
            if i == 0 and A[i] < T[i]:
                print 0
                flag = False
                break
            limit[i] = min(limit[i], A[i])
# print limit
if flag: print times(limit)

Submission status: Wrong Answer

Solution code:
import sys

N = int(sys.stdin.readline())
Ts = list(map(int, sys.stdin.readline().split()))
As = list(map(int, sys.stdin.readline().split()))

lt_T = [False] + list(map(lambda t_t2: t_t2[0] == t_t2[1], zip(Ts, Ts[1:])))
lt_A = list(map(lambda t_t2: t_t2[0] == t_t2[1], zip(As, As[1:]))) + [False]

res = 1
for lt_t, lt_a, t, a in zip(lt_T, lt_A, Ts, As):
    if lt_t:
        if lt_a:
            p = min(t, a)
        else:
            if a <= t:
                p = 1
            else:
                p = 0
    else:
        if lt_a:
            if t <= a:
                p = 1
            else:
                p = 0
        else:
            if t == a:
                p = 1
            else:
                p = 0
    res *= p
    res %= (1e9+7)

print(int(res))

Submission status: Wrong Answer

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

fixed_peek_t = {}
unfixed_peek_t = {}
fixed_peek_a = {}
unfixed_peek_a = {}

lp = 0
for idx, height in enumerate(T):
    if lp < height:
        fixed_peek_t[idx] = height
    elif idx not in fixed_peek_t:
        unfixed_peek_t[idx] = height
    lp = height

lp = 0
for _idx, height in enumerate(reversed(A)):
    idx = N-1 - _idx
    if lp < height:
        fixed_peek_a[idx] = height
    elif idx not in fixed_peek_a:
        unfixed_peek_a[idx] = height
    lp = height

# print(unfixed_peek_t)
# print(fixed_peek_t)
# print(unfixed_peek_a)
# print(fixed_peek_a)

if max(A) != max(T):
    print(0)
else:
    cnt = 1
    for k,v in unfixed_peek_t.items():
        if k not in unfixed_peek_a:
            continue
        cnt *= min(v, unfixed_peek_a[k])
        cnt %= 10**9 + 7

    print(cnt)

Submission status: Wrong Answer

Solution code:
import math
import sys

N = input()
T = [int(i) for i in raw_input().split()]
A = [int(i) for i in raw_input().split()]

ans = 1

for i in range(N):
    if(i==0 or i==N-1):
        continue
    
    if(T[i-1]!=T[i] and T[i]>A[i]):
        print '0'
        sys.exit()

    if(A[i+1]!=A[i] and A[i]>T[i]):
        print '0'
        sys.exit()

    if((T[i-1]!=T[i])or(A[i+1]!=A[i])):
        continue

    else:
        ans *= min(T[i],A[i])
        ans %= 1000000007
print ans

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding:utf-8 -*-

from __future__ import division, print_function, absolute_import, unicode_literals

import sys

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

h = [None] * N

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

odd = False
h[0] = T[0]
for i, (a, b) in enumerate(zip(T[1:], T[:-1]), 1):
    if a != b:
        h[i] = a
    if a < b:
        odd = True
        break

if odd is True:
    print(0)
    sys.exit()

if h[-1] is None:
    h[-1] = A[-1]
elif h[-1] != A[-1]:
    print(0)
    sys.exit()

for i, (a, b) in enumerate(zip(A[::-1][1:], A[::-1][:-1]), 1):
    if a != b:
        if h[N-i-1] is None:
            h[N-i-1] = a
        elif h[N-i-1] != a:
            odd = True
            break
    if a < b:
        odd = True
        break

if odd is True:
    print(0)
    sys.exit()

i = 1
a, b = 0, 0
cnt = 0
ans = 1
flag = False
while i < N-1:
    if h[i] is None:
        flag = True
        a = h[i-1]
        cnt = 0
        while h[i] is None:
            i += 1
            cnt += 1
        b = h[i]
        # print(a, b, cnt)
        ans = (ans * (min(a, b) ** cnt)) % (10 ** 9 + 7)
        # print(ans)
    else:
        i += 1
print(ans)