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(input())
t = list(map(int, input().split()))
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
renew = [0] * n
b = 0
for i, h in enumerate(t):
	if b < h:
		renew[i] = h
		b = h
renew[-1] = t[-1]
b = 0
for i, h in enumerate(a[::-1]):
	if b < h:
		if 0 != renew[n - i - 1] != h:
			print(0)
			exit()
		renew[n - i - 1] = h
		b = h
ans = 1
for f, th, ah in zip(renew, t, a):
	if not f:
		ans *= min(th, ah)
		ans %= mod
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
t=list(map(int,input().split()))
a=list(map(int,input().split()))
mod=10**9+7
renew=[0]*n
b=0
for i,h in enumerate(t):
	if b<h:
		renew[i]=h
		b=h
b=0
for i,h in enumerate(a[::-1]):
	if b<h:
		if 0!=renew[n-i-1]!=h:
			print(0)
			exit()
		renew[n-i-1]=h
		b=h
ans=1
for f,th,ah in zip(renew,t,a):
	if not f:
		ans*=min(th,ah)
		ans%=mod
print(ans)

Submission status: Wrong Answer

Solution code:
p = 10**9+7
N = int(input())
T = list(map(int,input().split()))
A = list(map(int,input().split()))
H = [0 for _ in range(N)]
cnt = 1
H[0] = T[0]
for i in range(1,N):
    if T[i]>T[i-1]:
        H[i] = T[i]
if H[-1]>0 and H[-1]!=A[-1]:
    cnt = 0
else:
    H[-1] = A[-1]
    for i in range(-2,-N-1,-1):
        if H[i]==0 and A[i]>A[i+1]:
            H[i] = A[i]
        elif H[i]>0 and A[i]>A[i+1]:
            if H[i]==A[i]:continue
            else:
                cnt = 0
                break
    if cnt==1:
        for i in range(1,N-1):
            if H[i]==0:
                cnt = (cnt*min(T[i],A[i]))%p
print(cnt)

Submission status: Wrong Answer

Solution code:
MOD = 1000000007

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

H0 = [None for _ in range(N)]
H1 = [None for _ in range(N)]

incorrect = False

if T[-1]!=A[0]:
    incorrect = True

maxh = 0
for i in range(N):
    if maxh < T[i]:
        H0[i] = T[i]
        maxh = T[i]

maxh = 0
for i in reversed(range(N)):
    if maxh < A[i]:
        if H0[i] != None and H0[i] != A[i]:
            incorrect = True
        H1[i] = A[i]
        maxh = A[i]

ans = 1
for i in range(N):
    if H0[i]==None and H1[i]==None:
        ans *= min(A[i],T[i])
        ans %= MOD

print(ans if not incorrect else 0)

Submission status: Wrong Answer

Solution code:
MOD = 1000000007

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

H0 = [None for _ in range(N)]
H1 = [None for _ in range(N)]

incorrect = False

maxh = 0
for i in range(N):
    if maxh < T[i]:
        H0[i] = T[i]
        maxh = T[i]

maxh = 0
for i in reversed(range(N)):
    if maxh < A[i]:
        if H0[i] != None and H0[i] != A[i]:
            incorrect = True
        H1[i] = A[i]
        maxh = A[i]

ans = 1
for i in range(N):
    if H0[i]==None and H1[i]==None:
        ans *= min(A[i],T[i])
        ans %= MOD

print(ans if not incorrect else 0)

Submission status: Wrong Answer

Solution code:
mod = 10 ** 9 + 7

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

H = [0] * N
for i in range(N):
    if i == 0:
        H[i] = T[i]
    elif T[i - 1] < T[i]:
        H[i] = T[i]

for i in range(N - 1, -1, -1):
    if i == N - 1:
        if H[i] == 0 or H[i] == A[i]:
            H[i] = A[i]
        else:
            print(0)
            exit()
    elif A[i] > A[i + 1]:
        if H[i] == 0 or H[i] == A[i]:
            H[i] = A[i]
        else:
            print(0)
            exit()

ans = 1
for i in range(N):
    if H[i] == 0:
        ans *= min(T[i], A[i])
        ans %= mod
print(ans)

Submission status: Wrong Answer

Solution code:
mod = 10 ** 9 + 7

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

H = [0] * N
for i in range(N):
    if i == 0:
        H[i] = T[i]
    elif T[i - 1] < T[i]:
        H[i] = T[i]

for i in range(N - 1, -1, -1):
    if i == N - 1:
        H[i] = A[i]
    elif A[i] > A[i + 1]:
        if H[i] == 0 or H[i] == A[i]:
            H[i] = A[i]
        else:
            print(0)
            exit()

ans = 1
for i in range(N):
    if H[i] == 0:
        ans *= min(T[i], A[i])
        ans %= mod
print(ans)

Submission status: Wrong Answer

Solution code:
mod = 10 ** 9 + 7

N = int(input())
T = [0] + list(map(int, input().split()))
A = list(map(int, input().split())) + [0]

H = [0] * N
for i in range(1, N + 1):
    if T[i - 1] < T[i]:
        H[i - 1] = T[i]
for i in range(N - 1, -1, -1):
    if A[i + 1] < A[i]:
        if H[i] == 0 or H[i] == A[i]:
            H[i] = A[i]
        else:
            print(0)
            exit()

ans = 1
T.pop(0)
A.pop(-1)
for h, t, a in zip(H, T, A):
    if h == 0:
        ans *= min(t, a)
        ans %= mod
print(ans)

Submission status: Wrong Answer

Solution code:
mod = 10 ** 9 + 7

N = int(input())
T = [0] + list(map(int, input().split()))
A = list(map(int, input().split())) + [0]

H = [0] * N
for i in range(1, N):
    if T[i - 1] < T[i]:
        H[i - 1] = T[i]
for i in range(N - 1, -1, -1):
    if A[i + 1] < A[i]:
        if H[i] == 0 or H[i] == A[i]:
            H[i] = A[i]
        else:
            print(0)
            exit()

ans = 1
T.pop(0)
A.pop(-1)
for h, t, a in zip(H, T, A):
    if h == 0:
        ans *= min(t, a)
        ans %= mod
print(ans)

Submission status: Wrong Answer

Solution code:
def examA():
    S = SI()
    ans = "No"
    flag = False
    for s in S:
        if flag:
            if s=="F":
                ans = "Yes"
                break
        else:
            if s=="C":
                flag = True
    print(ans)
    return

def examB():
    K, T = LI()
    A = LI(); A.sort()
    ans = max(0,A[-1]*2-sum(A)-1)
    print(ans)
    return

def examC(mod):
    N = I()
    T = LI(); A = LI()
    H = [-1]*N
    ans = 1
    if T[-1] != A[0]:
        ans = 0
    H[0] = T[0]; H[N-1] = A[N-1]
    for i in range(N-1):
        if T[i+1]>T[i]:
            if H[i+1]==-1:
                H[i+1] = T[i+1]
            elif H[i+1]!=T[i+1]:
                ans = 0
    for i in range(N-1,0,-1):
        if A[i-1]>A[i]:
            if H[i-1]==-1:
                H[i-1] = A[i-1]
            elif H[i-1]!=A[i-1]:
                ans = 0
    flag = False; cur = 0
    for i in H:
        if flag:
            if i==-1:
                cur +=1
            else:
                ans *=(min(now,i)**cur)%mod
                ans %=mod
                flag = False
                cur = 0; now = i
        else:
            if i==-1:
                cur = 1
                flag = True
            else:
                now = i
    print(ans%mod)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examC(mod)

Submission status: Wrong Answer

Solution code:
def examA():
    S = SI()
    ans = "No"
    flag = False
    for s in S:
        if flag:
            if s=="F":
                ans = "Yes"
                break
        else:
            if s=="C":
                flag = True
    print(ans)
    return

def examB():
    K, T = LI()
    A = LI(); A.sort()
    ans = max(0,A[-1]*2-sum(A)-1)
    print(ans)
    return

def examC(mod):
    N = I()
    T = LI(); A = LI()
    H = [-1]*N
    ans = 1
    if N==1:
        if T[0]!=A[0]:
            ans = 0
    H[0] = T[0]; H[N-1] = A[N-1]
    for i in range(N-1):
        if T[i+1]>T[i]:
            if H[i+1]==-1:
                H[i+1] = T[i+1]
            elif H[i+1]!=T[i+1]:
                ans = 0
    for i in range(N-1,0,-1):
        if A[i-1]>A[i]:
            if H[i-1]==-1:
                H[i-1] = A[i-1]
            elif H[i-1]!=A[i-1]:
                ans = 0
    flag = False; cur = 0
    for i in H:
        if flag:
            if i==-1:
                cur +=1
            else:
                ans *=(min(now,i)**cur)%mod
                ans %=mod
                flag = False
                cur = 0; now = i
        else:
            if i==-1:
                cur = 1
                flag = True
            else:
                now = i
    print(ans%mod)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examC(mod)

Submission status: Wrong Answer

Solution code:
def examA():
    S = SI()
    ans = "No"
    flag = False
    for s in S:
        if flag:
            if s=="F":
                ans = "Yes"
                break
        else:
            if s=="C":
                flag = True
    print(ans)
    return

def examB():
    K, T = LI()
    A = LI(); A.sort()
    ans = max(0,A[-1]*2-sum(A)-1)
    print(ans)
    return

def examC(mod):
    N = I()
    T = LI(); A = LI()
    H = [-1]*N
    ans = 1
    if N==1:
        if T[0]!=A[0]:
            ans = 0
    H[0] = T[0]; H[N-1] = A[N-1]
    for i in range(N-1):
        if T[i+1]>T[i]:
            if H[i+1]==-1:
                H[i+1] = T[i+1]
            elif H[i+1]!=T[i+1]:
                ans = 0
    for i in range(N-1,0,-1):
        if A[i-1]>A[i]:
            if H[i-1]==-1:
                H[i-1] = A[i-1]
            elif H[i-1]!=A[i-1]:
                ans = 0
    flag = False; cur = 0
    for i in H:
        if flag:
            if i==-1:
                cur +=1
            else:
                ans *=(min(now,i)**cur)
                ans %=mod
                flag = False
                cur = 0; now = i
        else:
            if i==-1:
                cur = 1
                flag = True
            else:
                now = i
    print(ans%mod)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examC(mod)

Submission status: Wrong Answer

Solution code:
def examA():
    S = SI()
    ans = "No"
    flag = False
    for s in S:
        if flag:
            if s=="F":
                ans = "Yes"
                break
        else:
            if s=="C":
                flag = True
    print(ans)
    return

def examB():
    K, T = LI()
    A = LI(); A.sort()
    ans = max(0,A[-1]*2-sum(A)-1)
    print(ans)
    return

def examC(mod):
    N = I()
    T = LI(); A = LI()
    H = [-1]*N
    ans = 1
    H[0] = T[0]; H[N-1] = A[N-1]
    for i in range(N-1):
        if T[i+1]>T[i]:
            if H[i+1]==-1:
                H[i+1] = T[i+1]
            elif H[i+1]!=T[i+1]:
                ans = 0
    for i in range(N-1,0,-1):
        if A[i-1]>A[i]:
            if H[i-1]==-1:
                H[i-1] = A[i-1]
            elif H[i-1]!=A[i-1]:
                ans = 0
    flag = False; cur = 0
    for i in H:
        if flag:
            if i==-1:
                cur +=1
            else:
                ans *=(min(now,i)**cur)
                ans %=mod
                flag = False
                cur = 0; now = i
        else:
            if i==-1:
                cur = 1
                flag = True
            else:
                now = i
    print(ans%mod)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examC(mod)

Submission status: Wrong Answer

Solution code:
def examA():
    S = SI()
    ans = "No"
    flag = False
    for s in S:
        if flag:
            if s=="F":
                ans = "Yes"
                break
        else:
            if s=="C":
                flag = True
    print(ans)
    return

def examB():
    K, T = LI()
    A = LI(); A.sort()
    ans = max(0,A[-1]*2-sum(A)-1)
    print(ans)
    return

def examC(mod):
    N = I()
    T = LI(); A = LI()
    H = [-1]*N
    ans = 1
    H[0] = T[0]; H[N-1] = A[N-1]
    for i in range(N-1):
        if T[i+1]>T[i]:
            if H[i+1]==-1:
                H[i+1] = T[i+1]
            elif H[i+1]!=T[i+1]:
                ans = 0
    for i in range(N-1,0,-1):
        if A[i-1]>A[i]:
            if H[i-1]==-1:
                H[i-1] = A[i-1]
            elif H[i-1]!=A[i-1]:
                ans = 0
    flag = False; cur = 0
    for i in H:
        if flag:
            if i==-1:
                cur +=1
            else:
                ans *=min(now,i)**cur
                ans %=mod
                flag = False
                cur = 0; now = i
        else:
            if i==-1:
                cur = 1
                flag = True
            else:
                now = i
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examC(mod)

Submission status: Wrong Answer

Solution code:
import sys
N=int(input())
T=[int(i) for i in input().split()]
A=[int(i) for i in input().split()]

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

max_=T[-1]
MAX=[max_ for _ in range(N)]
MIN=[1 for _ in range(N)]

MAX[0] = T[0]
MIN[0] = T[0]
for i in range(1,N):
    MAX[i] = T[i]
    if T[i] > T[i-1]:
        MIN[i] = T[i]
    else:
        MIN[i] = 1 

#print(MAX)
#print(MIN)   
        
MAX[-1] = A[-1]
MIN[-1] = A[-1]
for i in range(0,N-1)[::-1]:
    MAX[i] = min(MAX[i],A[i])
    if A[i] > A[i+1]:
        MIN[i] = min(MAX[i],A[i])
    else:
        MIN[i] = max(1,MIN[i])
        
#print(MAX)
#print(MIN)

sum_= 1
lim = 10**9 + 7
for i in range(N):
    sum_ = (sum_ * (MAX[i]-MIN[i]+1)) % lim
print(sum_)

Submission status: Wrong Answer

Solution code:
n=int(input())
t=list(map(int,input().split()))
a=list(map(int,input().split()))
MOD=10**9+7

if t[0]<=a[0]:
    ans=1
else:
    ans=0

for i in range(1,n):
    if t[i-1]<t[i] :
        if t[i]<=a[i]:
            ans*=1
        else:
            ans*=0
    else:
        ans*=min(t[i],a[i])%MOD

print(ans%MOD)

Submission status: Wrong Answer

Solution code:
n= int(input())
t = [0]+list(map(int, input().split( )))
tmx = max(t)
a = [tmx]+list(map(int, input().split( )))+[0]

if a[0]!= a[1]:
    print(0)
    exit()
ans = 1

for i in range(1,n+1):
    if t[i]>t[i-1] or a[i]>a[i+1]:
        continue
    else:
        ans *= min(t[i],a[i])
        ans %=10**9+7
print(ans)

Submission status: Wrong Answer

Solution code:
n= int(input())
t = [0]+list(map(int, input().split( )))
tmx = max(t)
a = [tmx]+list(map(int, input().split( )))+[0]

if a[0]!= a[1]:
    print(0)
    exit()
ans = 1

for i in range(1,n+1):
    if t[i]>t[i-1] or a[i]>a[i+1]:
        continue
    else:
        ans *= min(t[i],a[i])
        ans %=10**9+7
print(ans)

Submission status: Wrong Answer

Solution code:
MOD = 10**9 + 7
N = int(input())
*T, = map(int, input().split())
*A, = map(int, input().split())
ans = 1
for i in range(N):
    temp1 = -1
    temp2 = -1
    if i == 0 or T[i-1] < T[i]:
        temp1 = T[i]
    if i == N-1 or A[i] > A[i+1]:
        temp2 = A[i]
    if temp1 == -1:
        ans = (ans * (1 if temp2 != -1 else min(T[i], A[i]))) % MOD
    else:
        if temp2 != -1 and temp1 != temp2:
            ans = 0
            break
print(ans)

Submission status: Wrong Answer

Solution code:
MOD = 10**9 + 7
N = int(input())
*T, = map(int, input().split())
*A, = map(int, input().split())
heights = [-1] * N
heights[0] = T[0]
heights[-1] = A[-1]
admissible = True
for i, (t1, t2) in enumerate(zip(T, T[1:])):
    if t1 < t2:
        if heights[i+1] == -1:
            heights[i+1] = t2
        elif heights[i+1] != t2:
            admissible = False
            break
for i, (a1, a2) in reversed(list(enumerate(zip(A, A[1:])))):
    if a1 > a2:
        if heights[i] == -1:
            heights[i] = a1
        elif heights[i] != a1:
            admissible = False
            break
if admissible:
    ans = 1
    for i, h in enumerate(heights):
        if h == -1:
            ans = (ans * min(T[i], A[i])) % MOD
    print(ans)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    T = list(map(int, input().split()))
    A = list(map(int, input().split()))
    MOD = 10 ** 9 + 7
    if max(T) != max(A):
        print(0)
        exit()

    ans = [0] * N
    tmp = 0
    for i in range(N):
        if tmp < T[i]:
            tmp = T[i]
            ans[i] = 1
        else:
            ans[i] = T[i]

    tmp = 0
    for i in range(N-1,-1,-1):
        if tmp < A[i]:
            tmp = A[i]
            ans[i] = min(ans[i],1)
        else:
            ans[i] = min(A[i],ans[i])

    cnt = 1
    for i in ans:
        cnt *= i
        cnt %= MOD
    
    print(cnt)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


class Mod:
    def __init__(self, m):
        self.m = m

    def add(self, a, b):
        return (a + b) % self.m

    def sub(self, a, b):
        return (a - b) % self.m

    def mul(self, a, b):
        return ((a % self.m) * (b % self.m)) % self.m

    def div(self, a, b):
        return self.mul(a, pow(b, self.m-2, self.m))

    def pow(self, a, b):
        return pow(a, b, self.m)

@mt
def slv(N, T, A):
    if max(T) != max(A):
        return 0
        
    M = Mod(10**9+7)
    T[-1] = A[-1]
    F = [False] * N
    F[0] = True
    F[-1] = True
    for i in range(1, N):
        if T[i-1] < T[i]:
            F[i] = True
    for i in range(N-2, -1, -1):
        if A[i] > A[i+1]:
            F[i] = True
            T[i] = A[i]
        else:
            T[i] = min(T[i], A[i])
    ans = 1
    for f, h in zip(F, T):
        if not f:
            ans = M.mul(ans, h)
    return ans


def main():
    N = read_int()
    T = read_int_n()
    A = read_int_n()
    print(slv(N, T, A))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
mod = 10**9 + 7
N = int(input())
T = list(map(int, input().split()))
A = list(map(int, input().split()))

Min = [1] * N
Max = [float("inf")] * N
tp = 0
for i, t in enumerate(T):
    if t != tp:
        Min[i] = max(Min[i], t)
    Max[i] = min(Max[i], t)
    tp = t
ap = 0
for i, a in zip(range(N-1, -1, -1), A[::-1]):
    if a != ap:
        Min[i] = max(Min[i], a)
    Max[i] = min(Max[i], a)
    ap = a
ans = 1
for mi, ma in zip(Min, Max):
    ans = ans * (ma-mi+1) % mod
print(ans)

Submission status: Wrong Answer

Solution code:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
T = list(map(int, input().split()))
confirm = [None]*N
confirm[0] = A[0]
confirm[-1] = T[-1]

if max(A) != max(T):
    print(0)
    exit()
for i, prev, cur in zip(range(1, N), A, A[1:]):
    if prev < cur:
        if confirm[i] is None:
            confirm[i] = cur
        else:
            if confirm[i] < cur:
                print(0)
                exit()

for i, prev, cur in zip(reversed(range(N-1)), reversed(T[:-1]), reversed(T)):
    if prev > cur:
        if confirm[i] is None:
            confirm[i] = prev
        else:
            if confirm[i] < prev:
                print(0)
                exit()
ans = 1
MOD = 10**9+7
for i, a in enumerate(confirm):
    if a is None:
        ans *= min(A[i], T[i])
        ans %= MOD
print(ans)

Submission status: Wrong Answer

Solution code:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
T = list(map(int, input().split()))
confirm = [None]*N
confirm[0] = A[0]
confirm[-1] = T[-1]

for i, prev, cur in zip(range(1, N), A, A[1:]):
    if prev < cur:
        if confirm[i] is None:
            confirm[i] = cur
        else:
            if confirm[i] < cur:
                print(0)
                exit()

for i, prev, cur in zip(reversed(range(N-1)), reversed(T[:-1]), reversed(T)):
    if prev > cur:
        if confirm[i] is None:
            confirm[i] = prev
        else:
            if confirm[i] < prev:
                print(0)
                exit()
ans = 1
MOD = 10**9+7
for i, a in enumerate(confirm):
    if a is None:
        ans *= min(A[i], T[i])
        ans %= MOD
print(ans)

Submission status: Wrong Answer

Solution code:
mod = 10 ** 9 + 7

n = int(input())
t = tuple(map(int, input().split()))
a = tuple(map(int, input().split()))

ans = 1
for i in range(1, n - 1):
    x = t[i] if t[i] > t[i - 1] else 1
    y = a[i] if a[i] > a[i + 1] else 1
    ans = ans * max(0, min(t[i], a[i]) - max(x, y) + 1) % mod

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.buffer.readline

n = int(input())
t = list(map(int, input().split()))
a = list(map(int, input().split()))
mod = 10**9+7

max_list = [10**9+1] * n
min_list = [0] * n

max_list[0] = t[0]
min_list[0] = t[0]
for i in range(1, n):
    if t[i] > t[i-1]:
        max_list[i] = t[i]
        min_list[i] = t[i]
    else:
        max_list[i] = t[i]
        min_list[i] = 1

max_list[n-1] = a[n-1]
min_list[n-1] = a[n-1]
for i in range(n-2, -1, -1):
    if a[i] > a[i+1]:
        if min_list[i] <= a[i] <= max_list[i]:
            max_list[i] = a[i]
            min_list[i] = a[i]
        else:
            print(0)
            exit()
    else:
        if max_list[i] == min_list[i]:
            if max_list[i] > a[i]:
                print(0)
                exit()
        else:
            max_list[i] = min(max_list[i], a[i])

ans = 1
for i in range(n):
    ans = (ans * (max_list[i] - min_list[i] + 1)) % mod
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

N = int(input())
T = list(map(int, input().split()))
A = list(map(int, input().split()))
mod = 10**9+7

decided = [False for _ in range(N)]
H = [0 for _ in range(N)]

pre = -1
for i, t in enumerate(T):
    if t != pre:
        decided[i] = True
    H[i] = t
    pre = t

ok = True
pre = -1
for i in reversed(range(N)):
    a = A[i]
    if a != pre:
        if decided[i] and H[i] != a:
            ok = False
            break
        decided[i] = True
    if not decided[i]:
        H[i] = min(H[i], a)
    pre = a

if ok:
    ans = 1
    for i in range(N):
        if not decided[i]:
            ans = ans * H[i] % mod
    print(ans)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

N = int(input())
T = list(map(int, input().split()))
A = list(map(int, input().split()))
mod = 10**9+7

decided = [False for _ in range(N)]
H = [0 for _ in range(N)]

pre = -1
for i, t in enumerate(T):
    if t != pre:
        decided[i] = True
    H[i] = t
    pre = t

ok = True
pre = -1
for i in reversed(range(N)):
    a = A[i]
    if a != pre:
        if decided[i] and H[i] != a:
            ok = False
            break
        decided[i] = True
    H[i] = min(H[i], a)
    pre = a

if ok:
    ans = 1
    for i in range(N):
        if not decided[i]:
            ans = ans * H[i] % mod
    print(ans)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

N = int(input())
T = list(map(int, input().split()))
A = list(map(int, input().split()))
mod = 10**9+7

decided = [False for _ in range(N)]
H = [0 for _ in range(N)]

pre = -1
for i, t in enumerate(T):
    if t != pre:
        decided[i] = True
    H[i] = t
    pre = t

ok = True
pre = -1
for i in reversed(range(N)):
    a = A[i]
    if a != pre:
        if decided[i] and H[i] < a:
            ok = False
            break
        decided[i] = True
    H[i] = min(H[i], a)
    pre = a

if ok:
    ans = 1
    for i in range(N):
        if not decided[i]:
            ans = ans * H[i] % mod
    print(ans)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

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

    check = [False] * N
    min_ = [0] * N
    for i in range(N):
        min_[i] = T[i]
        if T[i-1] != T[i] or i == 0:
            check[i] = True
    
    if check[N-1] and min_[N-1] != A[N-1]:
        print(0)
        return
    else:
        check[N-1] = True
        min_[N-1] = A[N-1]

    for i in range(N-2, -1, -1):
        if A[i] != A[i+1]:
            if check[i] and min_[i] != A[i]:
                print(0)
                return
            else:
                check[i] = True
                min_[i] = A[i]
        else:
            min_[i] = min(min_[i], A[i])
    
    ans = 1
    MOD = int(1e9) + 7
    for i in range(N):
        if not check[i]:
            ans *= min_[i]
            ans %= MOD
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:

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

    maxt = t[-1]
    maxa = a[0]
    res = 1
    for i in range(1,n-1):
        if t[i] < a[i]:
            if a[i] != maxa:
                return 0
            if t[i-1] == t[i]:
                res *= t[i]
        elif t[i] > a[i]:
            if t[i] != maxt:
                return 0
            if a[i+1] == a[i]:
                res *= a[i]
        else:
            if a[i] != maxa:
                return 0
            if t[i-1] == t[i] and a[i+1] == a[i]:
                res *= a[i]
    return res % (10**9+7)


print(main())

Submission status: Wrong Answer

Solution code:
n = int(input())
t = list(map(int, input().split(' ')))
a = list(map(int, input().split(' ')))
result = 1
for i in range(n):
    h_max, h_min = min(t[i], a[i])+1, 1
    if i != 0:
        if t[i-1] < t[i]:
            h_min = t[i]
    else:
        h_min = t[0]

    if i != n-1:
        if a[i] > a[i+1]:
            h_min = max(a[i], h_min)
    else:
        h_min = a[n-1]
    result = result * max(h_max - h_min, 0) % (10**9+7)
print(result)

Submission status: Wrong Answer

Solution code:

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


    maxh = t[:]
    minflag = [0 for _ in range(n)]

    if t[-1] != a[0]:
        return 0
    else:
        maxflag = t[-1]
    maxh[0] = t[0]
    minflag[0] = 1

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

    maxh[-1] = a[-1]
    minflag[-1] = 1

    for i in range(n-2,-1,-1):
        if a[i] > t[i]:
            if i == n-2 and a[i] == t[i]:
                break
            return 0
        elif a[i] == t[i]:
            if a[i] != maxflag:
                return 0
            else:
                minflag[i] = 1
                break
        maxh[i] = a[i]
        if a[i] > a[i+1]:
            minflag[i] = 1

    res = 1
    for i in range(n):
        if not minflag[i]:
            res *= maxh[i]
            res %= (10**9+7)
    return res % (10**9+7)

print(main())

Submission status: Wrong Answer

Solution code:
n = int(input())
t = list(map(int, input().split(' ')))
a = list(map(int, input().split(' ')))
result = 1
for i in range(n):
    h_max, h_min = min(t[i], a[i])+1, 1
    if i != 0:
        if t[i-1] < t[i]:
            h_min = t[i]
    else:
        h_min = t[0]

    if i != n-1:
        if a[i] > a[i+1]:
            h_min = a[i]
    else:
        h_min = a[n-1] 
    result = result * max(h_max - h_min, 0) % (10**9+7)
print(result)