@staticmethod
def d():
    (k, m) = map(int, sys.stdin.readline().split())
    a = np.array([int(x) for x in sys.stdin.readline().split()])
    c = np.array([int(x) for x in sys.stdin.readline().split()])
    mask = ((1 << 32) - 1)
    d = (np.eye(k, k, (- 1), dtype=np.uint32) * mask)
    d[0] = c
    if (m <= k):
        print(a[(m - 1)])
        return
    print(Algebra.bitwise_dot(Algebra.bitwise_mat_pow(d, (m - k)), a[::(- 1)].reshape((- 1), 1))[0][0])
@staticmethod
def d():
    (k, m) = map(int, sys.stdin.readline().split())
    a = np.array([int(x) for x in sys.stdin.readline().split()])
    c = np.array([int(x) for x in sys.stdin.readline().split()])
    mask = ((1 << 32) - 1)
    d = (np.eye(k, k, (- 1), dtype=np.uint32) * mask)
    d[0] = c
    if (m <= k):
        print(a[(m - 1)])
        return
    print(Algebra.bitwise_dot(Algebra.bitwise_mat_pow(d, (m - k)), a[::(- 1)].reshape((- 1), 1))[0][0])