• + 0 comments
    import sys
    
    N, K, L = map(int,input().split())
    mins = list(map(int, input().split()))
    maxs = list(map(int, input().split()))
    
    M = int(1e9 + 7)
    ANY = 0
    UP = 1
    DOWN = -1
    direction = [0] * (N + 1)
    
    for i in mins:
        if direction[i - 1] == UP or direction[i] == DOWN:
            print("0")
            sys.exit(0)
        direction[i - 1] = DOWN
        direction[i] = UP
    for i in maxs:
        if direction[i - 1] == DOWN or direction[i] == UP:
            print("0")
            sys.exit(0)
        direction[i - 1] = UP
        direction[i] = DOWN
    f = []
    for i in range(N + 1):
        f.append([0] * (N + 1))
    
    def interval(a, b):
        if a <= b:
            return range(a, b + 1)
        else:
            return range(a, b - 1, -1)
    
    f[N][0] = 1
    i = N - 1
    while i > 0:
        if direction[i] == UP:
            f[i][0] = 0
            for n in interval(1, N - i):
                f[i][n] = (f[i][n - 1] + f[i + 1][n - 1]) % M       
        elif direction[i] == DOWN:
            f[i][N - i] = 0
            for n in interval(N - i - 1, 0):
                m = N - i - n
                f[i][n] = (f[i][n + 1] + f[i + 1][n]) % M  
        elif direction[i] == ANY:
            s = 0
            for k in interval(0, N - (i + 1)):
                s += f[i + 1][k]
                s %= M
            for n in interval(0, N - i):
                f[i][n] = s
        i -= 1
    
    ret = 0
    for k in interval(0, N - 1):
        ret += f[1][k]
        ret %= M
    print(ret)