Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

#!/usr/bin/python
# -*- coding: UTF-8 -*-

import sys


def get_ints():
    return map(int, sys.stdin.readline().strip().split())


def _main():
    h, w, a, b = get_ints()

    from collections import defaultdict

    dd = defaultdict(lambda: 1)

    for i in range(1, h-a):
        for j in range(1, w):
            dd[j] = dd[j] + dd[j - 1]

    for i in range(h-a, h):
        for j in range(b+1, w):
            dd[j] = dd[j] + dd[j - 1]

    print(dd[w-1] % (10**9 + 7))


if __name__ == "__main__":
    _main()


### FIXED CODE ###

#!/usr/bin/python
# -*- coding: UTF-8 -*-

import sys


def get_ints():
    return map(int, sys.stdin.readline().strip().split())


def mul(x, y, mod):
    x %= mod
    y %= mod
    return x * y % mod


def div(x, y, mod):
    x %= mod
    y %= mod
    return x * mod_pow(y, mod - 2, mod) % mod


def mod_pow(a, p, mod):
    if p == 0:
        return 1
    if p % 2 == 0:
        root = mod_pow(a, p / 2, mod)
        return root * root % mod
    else:
        return a * mod_pow(a, p - 1, mod) % mod


def pre_factorial_divs(n, mod, factorials):
    factorial_divs = [0] * (n + 1)

    factorial_divs[n] = div(1, factorials, mod)
    for i in reversed(range(n)):
        factorial_divs[i] = mul(factorial_divs[i+1], i+1, mod)
    return factorial_divs


def pre_factorials(n, mod):
    factorials = [0] * (n + 1)
    factorials[0] = 1
    for i in range(n):
        factorials[i + 1] = (i + 1) * factorials[i] % mod
    return factorials


def fast_fast_fermat_comb(a, b, mod, factorials, factorial_divs):
    if len(factorials) == 0:
        raise
    af = factorials[a]
    bf = factorial_divs[b]
    abf = factorial_divs[a - b]
    return mul(mul(af, bf, mod), abf, mod)


def main():
    h, w, a, b = get_ints()

    ans = 0
    mod = 10 ** 9 + 7

    factorials = pre_factorials(h+w-2, mod)
    factorial_divs = pre_factorial_divs(h+w-2, mod, factorials[h+w-2])

    for i in range(h-a):
        x = fast_fast_fermat_comb(b-1+i, b-1, mod, factorials, factorial_divs)
        y = fast_fast_fermat_comb(h+w-3-(b-1+i), w-b-1, mod, factorials, factorial_divs)
        ans += x * y % mod
        ans %= mod

    print(ans)


if __name__ == "__main__":
    main()
### BUGGY CODE ###

H, W, N = map(int, input().split())
sh, sw = map(int, input().split())

S = input()
T = input()

def canTakaWin(toS, isInc, toT, R, c):
    mask = ((1 << (R + 1)) - 1) ^ 1
    now = 1 << c

    for s, t in zip(S, T):
        if now == 0:
            return True
        if s == toS:
            now = (now << 1) if isInc else (now >> 1)
        now &= mask

        direct = 0
        for i, k in enumerate(toT):
            if k == t:
                direct = (-1)**i
        if direct != 0:
            now |= (now << 1) if direct > 0 else (now >> 1)
        now &= mask

    return now == 0

ans = False
ans = ans or canTakaWin('U', False, 'DU', H, sh)
ans = ans or canTakaWin('D', True, 'DU', H, sh)
ans = ans or canTakaWin('L', False, 'RL', W, sw)
ans = ans or canTakaWin('R', True, 'RL', W, sw)

print('NO' if ans else 'YES')


### FIXED CODE ###

H, W, N = map(int, input().split())
sr, sc = map(int, input().split())
S = input()
T = input()

left = 1
right = W
bottom = 1
top = H

if S[-1] == 'L':
    left += 1
elif S[-1] == 'R':
    right -= 1
elif S[-1] == 'U':
    bottom += 1
elif S[-1] == 'D':
    top -= 1

for i in range(N - 1)[:: -1]:
    if T[i] == 'L':
        right = min(W, right + 1)
    elif T[i] == 'R':
        left = max(1, left - 1)
    elif T[i] == 'U':
        top = min(H, top + 1)
    elif T[i] == 'D':
        bottom = max(1, bottom - 1)

    if S[i] == 'L':
        left += 1
    elif S[i] == 'R':
        right -= 1
    elif S[i] == 'U':
        bottom += 1
    elif S[i] == 'D':
        top -= 1

    if left > right or bottom > top:
        print('NO')
        break
else:
    if left <= sc <= right and bottom <= sr <= top:
        print('YES')
    else:
        print('NO')
### BUGGY CODE ###

n,a,b = (int(x) for x in input().split())
c = 0
b_flg = True
while True:
  if n <= 0:
    break
  if b_flg:
    n -= a
    c += a
    if n <= 0:
      c += n
    b_flg = False
  else:
    n -= b
    b_flg = True
print(c)



### FIXED CODE ###

n,a,b = (int(x) for x in input().split())

count = (int(n/(a+b)))*a
count += min(n%(a+b),a)
print(count)
### BUGGY CODE ###

#coding:utf-8
N,M=map(int,raw_input().split())
A=map(int,raw_input().split())
for i in range(M):
    b,c=map(int,raw_input().split())
    for _ in range(b):
        A.append(c)
A.sort()
A.reverse()        
print(sum(A[:N]))

### FIXED CODE ###

#coding:utf-8
import sys
N,M=map(int,raw_input().split())
A=map(int,raw_input().split())
p=0
Q=[]
for a in A: Q.append((a,1))
for i in range(M):
    b,c=map(int,sys.stdin.readline().split())
    Q.append((c,b))
Q.sort();Q.reverse()
n=0;s=0
for c,b in Q:
    if b+n<=N:
        s+=c*b
        n+=b
    else:
        s+=c*(N-n)
        break
print(s)
### BUGGY CODE ###

#!/usr/bin/env python3
import sys


def solve(s: str):
    
    s = s.replace('BC', 'X')

    ans = 0
    while('AX' in s):
        ans += s.count('AX')
        s = s.replace('AX', 'XA', len(s))
        

    print(ans)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = next(tokens)  # type: str
    solve(s)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys


def solve(s: str):
    
    s = s.replace('BC', 'X')

    ans = 0
    cur = 0
    for i in range(len(s)):
        if(s[i] == 'A'):
            cur += 1
        elif(s[i] == 'X'):
            ans += cur
        else:
            cur = 0    

    print(ans)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = next(tokens)  # type: str
    solve(s)

if __name__ == '__main__':
    main()
### BUGGY CODE ###

N, K = map( int, input().split() )
ps = list( map( int, input().split() ) ) 
s=0
for i in range( N-K+1 ) :
  l=sum(ps[i:i+K])
  if l > s:
         s=l
print( (s+K)/2 )

### FIXED CODE ###

N, K = map( int, input().split() )
ps = list( map( int, input().split() ) ) 
s=sum(ps[0:K])
ans=s
for i in range( 1, N-K+1 ) :
  s = s + ps[i-1+K] - ps[i-1]
  if s > ans:
    ans=s
print( (ans+K)/2 )
### BUGGY CODE ###

#!/usr/bin/env python3
import sys
import math
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = 10**15

n, k = [int(item) for item in input().split()]
a = [int(item) for item in input().split()]
f = [int(item) for item in input().split()]
a.sort()
f.sort(reverse=True)

l = -1; r = 10**12 + 1 
while r - l > 1:
    mid = (l + r) // 2
    syugyo = 0
    for aa, ff in zip(a, f):
        target = mid // ff
        syugyo += max(aa - target, 0)
    if syugyo <= k:
        r = mid
    else:
        l = mid
print(r)

### FIXED CODE ###

#!/usr/bin/env python3
import sys
import math
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = 10**15

n, k = [int(item) for item in input().split()]
a = [int(item) for item in input().split()]
f = [int(item) for item in input().split()]
a.sort()
f.sort(reverse=True)

l = -1; r = 10**12 + 1 
while r - l > 1:
    mid = (l + r) // 2
    syugyo = 0
    for aa, ff in zip(a, f):
        target = mid // ff
        syugyo += max(aa - target, 0)
    if syugyo <= k:
        r = mid
    else:
        l = mid
print(r)
### BUGGY CODE ###

import numpy as np

my_input = lambda : map(int, input().split(" "))

N, M = my_input()
dist = 100 * 1000 * np.ones([N, N])

edges = []
for i in range(M):
    a, b, c = my_input()
    dist[a-1][b-1] = c
    dist[b-1][a-1] = c
    edges.append((a, b, c))

for k in range(N):
    for i in range(N):
        for j in range(N):
            dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])

print(len([e for e in edges if e[2] != dist[e[0]-1][e[1]-1]]))

### FIXED CODE ###

import numpy as np
from scipy.sparse.csgraph import dijkstra

my_input = lambda : map(int, input().split(" "))

N, M = my_input()
dist = 100 * 1000 * (np.ones([N, N]) - np.eye(N)).astype(int)

edges = []
for i in range(M):
    a, b, c = my_input()
    dist[a-1][b-1] = c
    dist[b-1][a-1] = c
    edges.append((a, b, c))

dist = dijkstra(dist, directed=False)
print(len([e for e in edges if e[2] != dist[e[0]-1][e[1]-1]]))
### BUGGY CODE ###

s = str(input())

num_moto = int(len(s))
flag = True

for ctr in range(50000):
    if s.find('10') == -1 or s.find('01') == -1 or int(len(s)) == 0:
        flag == False
    if flag == True:
        s = s.replace('10','')
        s = s.replace('01','')
        
num_kekka = int(len(s))
print(num_moto - num_kekka)

### FIXED CODE ###

s = input()
count_0 = s.count('0')
count_1 = s.count('1')
print(2*min(count_0,count_1))
### BUGGY CODE ###

# 問題文の意味がわからんコンテスト
# 0の場合も自分自身を照らす、っての気づくところからやっと読解
# Kを5000兆回やったあとはすべての要素がNになっとる この収束はわりと早いらしい
n, k = map(int, input().split())
a = list(map(int, input().split()))

for _ in range(k):
    b = [0] * (n + 1)
    for i in range(n):
        b[max(0, i - a[i])] += 1
        b[min(n, i + a[i] + 1)] -= 1
    for i in range(n):
        b[i + 1] += b[i]
    a = b[:n]
    if b[-1] == n:
        break
print(" ".join(list(map(str, a))))

### FIXED CODE ###

# 問題文の意味がわからんコンテスト
# 0の場合も自分自身を照らす、っての気づくところからやっと読解
# Kを5000兆回やったあとはすべての要素がNになっとる この収束はわりと早いらしい
n, k = map(int, input().split())
a = list(map(int, input().split()))

for _ in range(min(k, 100)):
    b = [0] * (n + 1)
    for i in range(n):
        b[max(0, i - a[i])] += 1
        b[min(n, i + a[i] + 1)] -= 1
    for i in range(n):
        b[i + 1] += b[i]
    a = b[:n]
print(" ".join(list(map(str, a))))
### BUGGY CODE ###

import sys
input = sys.stdin.readline
h, w = map(lambda x: int(x)+2, input().split())
MAZE = ['#'*w]
for _ in range(h-2):
    MAZE.append('#'+input()+'#')
else:
    MAZE.append('#'*w)

L = [[0]*w for _ in range(h)]
R = [[0]*w for _ in range(h)]
U = [[0]*w for _ in range(h)]
D = [[0]*w for _ in range(h)]

LAMP = [[0]*w for _ in range(h)]

for i in range(1, h-1):
    for j in range(1, w-1):
        if MAZE[i][j] == '.':
            L[i][j+1] = L[i][j]+1
        if MAZE[i][w-j] == '.':
            R[i][w-j-1] = R[i][w-j]+1

for j in range(1, w-1):
    for i in range(1, h-1):
        if MAZE[i][j] == '.':
            U[i+1][j] = U[i][j]+1
        if MAZE[h-i][j] == '.':
            D[h-i-1][j] = D[h-i][j]+1

ans = 0
for i in range(1, h-1):
    for j in range(1, w-1):
        if MAZE[i][j] == '#':
            continue
        LAMP[i][j] = L[i][j]+R[i][j]+U[i][j]+D[i][j]+1
        ans = max(ans, LAMP[i][j])

print(ans)

### FIXED CODE ###

import sys
input = sys.stdin.readline
h, w = map(lambda x: int(x)+2, input().split())
MAZE = ['#'*w]
for _ in range(h-2):
    MAZE.append('#'+input()+'#')
else:
    MAZE.append('#'*w)

L = [[0]*w for _ in range(h)]
R = [[0]*w for _ in range(h)]
U = [[0]*w for _ in range(h)]
D = [[0]*w for _ in range(h)]

LAMP = [[0]*w for _ in range(h)]

for i in range(1, h-1):
    for j in range(1, w-1):
        if MAZE[i][j] == '.':
            L[i][j+1] = L[i][j]+1
        if MAZE[i][w-j] == '.':
            R[i][w-j-1] = R[i][w-j]+1

for j in range(1, w-1):
    for i in range(1, h-1):
        if MAZE[i][j] == '.':
            U[i+1][j] = U[i][j]+1
        if MAZE[h-i][j] == '.':
            D[h-i-1][j] = D[h-i][j]+1

ans = 0
for i in range(1, h-1):
    for j in range(1, w-1):
        if MAZE[i][j] == '#':
            continue
        LAMP[i][j] = L[i][j]+R[i][j]+U[i][j]+D[i][j]+1
        ans = max(ans, LAMP[i][j])

print(ans)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
import numpy as np

H, W = map(int, input().split())
S = [input() for x in range(H)]

L = []
R = []
U = []
D = []
for h in range(H):
    ltmp = []
    rtmp = []
    utmp = []
    dtmp = []
    for w in range(W):
        lcnt = 0
        rcnt = 0
        ucnt = 0
        dcnt = 0
        if S[h][w] != '#':
            for i in range(w, W):
                if S[h][i] == '.':
                    rcnt += 1
                else:
                    break
            for i in range(w, -1, -1):
                if S[h][i] == '.':
                    lcnt += 1
                else:
                    break
            for i in range(h, H):
                if S[i][w] == '.':
                    dcnt += 1
                else:
                    break
            for i in range(h, -1, -1):
                if S[i][w] == '.':
                    ucnt += 1
                else:
                    break
        ltmp.append(lcnt)
        rtmp.append(rcnt)
        utmp.append(ucnt)
        dtmp.append(dcnt)
    L.append(ltmp)
    R.append(rtmp)
    U.append(utmp)
    D.append(dtmp)

L = np.array(L)
R = np.array(R)
U = np.array(U)
D = np.array(D)
print(np.max(L+R+U+D)-3)

### FIXED CODE ###

# -*- coding: utf-8 -*-
import numpy as np

H, W = map(int, input().split())
S = [input() for x in range(H)]

L = np.zeros([H, W], dtype=int)
R = np.zeros([H, W], dtype=int)
U = np.zeros([H, W], dtype=int)
D = np.zeros([H, W], dtype=int)

S_ = np.zeros([H, W], dtype=int)
for h in range(H):
    for w in range(W):
        if S[h][w] == '#': S_[h, w] = 0
        else: S_[h, w] = 1
L[:, 0] = S_[:, 0]
for w in range(1, W):
    L[:, w] = (L[:, w-1] + 1) * S_[:, w]
R[:, W-1] = S_[:, W-1]
for w in range(W-2, -1, -1):
    R[:, w] = (R[:, w+1] + 1) * S_[:, w]
U[0] = S_[0]
for h in range(1, H):
    U[h] = (U[h-1] + 1) * S_[h]
D[H-1] = S_[H-1]
for h in range(H-2, -1, -1):
    D[h] = (D[h+1] + 1) * S_[h]

L = np.array(L)
R = np.array(R)
U = np.array(U)
D = np.array(D)
print(np.max(L+R+U+D)-3)
### BUGGY CODE ###

#!/usr/bin/env python

def dfs(node, edge, vis):
    if vis[node]:
        return 0
    vis[node] = True
    count = 1
    vq = []
    vq.append(node)
    while vq:
        fnode = vq[0]
        del vq[0]
        for b in edge[fnode]:
            if not vis[b]:
                count += 1
                vq.append(b)
                vis[b] = True
    return count

n, m = [int(i) for i in input().split(' ')]

edge = [[] for i in range(n)]

for _ in range(m):
    a, b = [int(i) for i in input().split(' ')]
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)

vis = [False]*n

count = 0

for i in range(n):
    if not vis[i]:
        count = max(count, dfs(i, edge, vis))

print(count)


### FIXED CODE ###

#!/usr/bin/env python

import queue

def dfs(node, edge, vis):
    vis[node] = True
    count = 1
    vq = []
    vq.append(node)
    vq = queue.LifoQueue()
    vq.put(node)
    while not vq.empty():
        fnode = vq.get()
        for b in edge[fnode]:
            if not vis[b]:
                count += 1
                vq.put(b)
                vis[b] = True
    return count

n, m = [int(i) for i in input().split(' ')]

edge = [[] for i in range(n)]

for _ in range(m):
    a, b = [int(i) for i in input().split(' ')]
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)

vis = [False]*n

count = 0

for i in range(n):
    if not vis[i]:
        count = max(count, dfs(i, edge, vis))

print(count)
### BUGGY CODE ###

n,m=map(int,input().split())
a=[int(input()) for i in range(m)]
b=[0]*(n+1)
b[0]=1
if 1 not in a:
    b[1]=1
for i in range(2,n+1):
    if i in a:
        b[i]=0 
    else:
        b[i]=b[i-1]+b[i-2]
print(b[-1]%1000000007)

### FIXED CODE ###

n, m = map(int, input().split())
a = set()
for i in range(m):
    a.add(int(input()))

b = [0] * (n + 1)
b[0] = 1
if 1 not in a:
    b[1] = 1
for i in range(2, n + 1):
    if i in a:
        b[i] = 0
    else:
        b[i] = b[i - 1] + b[i - 2]
print(b[n] % 1000000007)
### BUGGY CODE ###

import itertools
k, s = map(int, input().split())
ans = 0
for i in list(itertools.product(range(k + 1), repeat=3)):
    if sum(i) == s:
        ans += 1
print(ans)

### FIXED CODE ###

k, s = map(int, input().split())
ans = 0
for x in range(k + 1):
    for y in range(k + 1):
        z = s - x - y
        if 0 <= z and z <= k:
            ans += 1
print(ans)
### BUGGY CODE ###

import sys
stdin = sys.stdin
N = int(stdin.readline().rstrip())
A = list(map(int,stdin.readline().split()))
mod = 10**9+7
ans = 0
for i in range(61):
    bits = 0
    for x in A:
        if (x>>i)&1:
            bits += 1
    ans += ((bits*(N-bits))* 2**i) %mod
ans %= mod
print(ans)

### FIXED CODE ###

import sys
stdin = sys.stdin
 
mod = 10**9 + 7
 
def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))
 
def main():
    n = ni()
    a = na()
    ans = 0
    for i in range(61):
        cnt = 0
        for ai in a:
            if (ai >> i) & 1:
                cnt += 1
        ans += ((cnt * (n - cnt)) * 2**i) % mod
    ans %= mod
    print(ans)
 
 
if __name__ == "__main__":
    main()
### BUGGY CODE ###

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

nCk = [0] * (n+2)
nCk[1] = n + 1
for i in range(2,n+2):
    nCk[i] = (nCk[i-1] * (n+1-i+1) // i)

index = [-1] * (n+1)
l, r = 0, 0
for i, c in enumerate(a):
    if index[c] == -1:
        index[c] = i
    else:
        l = index[c]
        r = i

nb = n-r+l
nb1Ck = [0] * (n + 2)
nb1Ck[0] = 1
nb1Ck[1] = nb 
for i in range(2, nb+2):
    nb1Ck[i] = (nb1Ck[i-1] * ((nb+1)-i) // i)

for i in range(1, n+2):
    print((nCk[i] - nb1Ck[i-1])%(10**9 + 7))

### FIXED CODE ###

n = int(input()) + 1
a = [int(item) for item in input().split()]
MOD = 10**9 + 7

def mod_pow(x, n):
    ans = 1
    while(n != 0):
        if n & 1:
            ans = ans * x % MOD
        x = x * x % MOD
        n = n >> 1
    return ans

fac = [1] + [0] * n
inv_fac = [1] + [0] * n
for i in range(1, n+1):
    fac[i] = fac[i-1] * (i) % MOD
    inv_fac[i] = inv_fac[i-1] * mod_pow(i, MOD-2) % MOD

def mod_nCr(n, r):
    if n == 0 and r == 0:
        return 1
    if n < r or n < 0:
        return 0
    tmp = inv_fac[n-r] * inv_fac[r] % MOD
    return tmp * fac[n] % MOD 

index = [-1] * (n+1)
l, r = 0, 0
for i, c in enumerate(a):
    if index[c] == -1:
        index[c] = i
    else:
        l = index[c]
        r = i

for i in range(1, n+1):
    total = mod_nCr(n, i)
    doubled = mod_nCr(n -(r-l) - 1, i-1)
    ans = total - doubled
    if ans < 0:
        ans += MOD
    print(ans)
### BUGGY CODE ###

import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
import math

i_i = lambda: int(i_s())
i_l = lambda: list(map(int, stdin.readline().split()))
i_s = lambda: stdin.readline().rstrip()

K = i_i()

ans = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            ans += math.gcd(math.gcd(a,b), c)

print(ans)


### FIXED CODE ###

import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
import math

i_i = lambda: int(i_s())
i_l = lambda: list(map(int, stdin.readline().split()))
i_s = lambda: stdin.readline().rstrip()

K = i_i()

res = sum([math.gcd(math.gcd(a, b), c) for a in range(1,K+1) for b in range(1,K+1) for c in range(1,K+1)])
print(res)
### BUGGY CODE ###

l=list(input())
count=0
while True:
    flag=True
    for i in range(len(l)-1):
        if l[i]!=l[i+1]:
            l.pop(i)
            l.pop(i)
            flag=False
            count+=2
            break
    if flag:
        print(count)
        break


### FIXED CODE ###

l=list(input())
o=0
z=0
for i in range(len(l)):
    if l[i]=="0":
        z+=1
    elif l[i]=="1":
        o+=1

if z > o:
    print(2*o)
else:
    print(2*z)
### BUGGY CODE ###

n=int(input())
s=list(map(int,input().split()))
t=list(map(int,input().split()))
f=list(map(int,input().split()))
g=list(map(int,input().split()))
ans=[n*[0]for _ in range(n)]
for b in range(64):
  u=[(a&1<<b)>>b for a in f]
  v=[(a&1<<b)>>b for a in g]
  q=[n*[0]for _ in range(n)]
  l=[0]*n
  m=[0]*n
  for i in range(n):
    for j in range(n):
      if(u[i]&v[j])|((s[i]^1)*u[i])|((t[j]^1)*v[j]):q[i][j]+=1;l[i]+=1;m[j]+=1
  for i in range(n):
    for j in range(n):
      if s[i]*u[i]*(l[i]==0)*(t[j]^1)*(n-m[j]>1):q[i][j]=u[i];l[i]+=1;m[j]+=1
      if t[j]*v[j]*(m[j]==0)*(s[i]^1)*(n-l[i]>1):q[i][j]=v[j];l[i]+=1;m[j]+=1
  for i in range(n):
    for j in range(n):ans[i][j]|=q[i][j]<<b
h=ans[0][:]
w=[i[0]for i in ans]
for i in range(n):
  for j in range(n):
    if s[i]:w[i]|=ans[i][j]
    else:w[i]&=ans[i][j]
    if t[j]:h[j]|=ans[i][j]
    else:h[j]&=ans[i][j]
if(g!=h)|(f!=w):print(-1);exit() 
for i in ans:print(*i)

### FIXED CODE ###

n=int(input())
s=list(map(int,input().split()))
t=list(map(int,input().split()))
u=list(map(int,input().split()))
v=list(map(int,input().split()))
ans=[n*[0]for _ in range(n)]
ss=[u[i]if s[i]==0 else 0 for i in range(n)]
tt=[v[i]if t[i]==0 else 0 for i in range(n)]
son=[[]for _ in range(n)]
ton=[[]for _ in range(n)]
sno=[[n-1]*64 for _ in range(n)]
tno=[[n-1]*64 for _ in range(n)]
for i in range(n):
  for j in range(n):
    ans[i][j]=u[i]&v[j]
    if s[i]==0:
      ans[i][j]|=u[i]
      ss[i]&=ans[i][j]
    else:
      ss[i]|=ans[i][j]
    if t[j]==0:
      ans[i][j]|=v[j]
      tt[j]&=ans[i][j]
    else:
      tt[j]|=ans[i][j]
    if s[i]==0 or t[i]==0:
      for k in range(64):
        if ans[i][j]&1<<k:
          if s[i]==0:sno[i][k]-=1
          if t[j]==0:tno[j][k]-=1
    if j==n-1:
      if s[i]==1:
        if ss[i]|u[i]>u[i]:print(-1);exit()
        if ss[i]!=u[i]:
          for k in range(64):
            if u[i]&1<<k:
              if (ss[i]&1<<k)==0:
                son[i].append(k)
          ss[i]=1
        else:ss[i]=0
      else:
        if ss[i]!=u[i]:print(-1);exit()
        else:ss[i]=2
    if i==n-1:
      if t[j]==1:
        if tt[j]|v[j]>v[j]:print(-1);exit()
        if tt[j]!=v[j]:
          for k in range(64):
            if v[j]&1<<k:
              if (tt[j]&1<<k)==0:
                ton[j].append(k)
          tt[j]=1
        else:tt[j]=0
      else:
        if tt[j]!=v[j]:print(-1);exit()
        else:tt[j]=2
for i in range(n):
  for k in son[i]:
    for j in range(n):
      if t[j]==0:
        if tno[j][k]>0:
          ans[i][j]|=1<<k
          tno[j][k]-=1
          break
      if j==n-1:print(-1);exit()
for j in range(n):
  for k in ton[j]:
    for i in range(n):
      if s[i]==0:
        if sno[i][k]>0:
          ans[i][j]|=1<<k
          sno[i][k]-=1
          break
      if i==n-1:print(-1);exit()
for i in range(n):
  if s[i]==0:uu=ans[i][0]
  else:uu=0
  for j in range(n):
    if s[i]==0:uu&=ans[i][j]
    else:uu|=ans[i][j]
  if uu!=u[i]:print(-1);exit()
for j in range(n):
  if t[j]==0:vv=ans[0][j]
  else:vv=0
  for i in range(n):
    if t[j]==0:vv&=ans[i][j]
    else:vv|=ans[i][j]
  if vv!=v[j]:print(-1);exit()
for i in ans:print(*i)
### BUGGY CODE ###

#atcoder template
def main():
    import sys
    imput = sys.stdin.readline
    #文字列入力の時は上記はerrorとなる。
    #ここにコード
    #input
    N = int(input())
    A = list(map(int, input().split()))

    #output
    answer = 1
    for i in range(N):
        answer *= A[i]

    # %%
    if answer > pow(10, 18):
        print(-1)
    else:
        print(answer)    

    #N = 1のときなどcorner caseを確認！
if __name__ == "__main__":
    main()

### FIXED CODE ###

#atcoder template
def main():
    import sys
    imput = sys.stdin.readline
    #文字列入力の時は上記はerrorとなる。
    #ここにコード
    #input
    N = int(input())
    A = list(map(int, input().split()))

    #output
    A = sorted(A, reverse = True)
    if A[-1] == 0:
        print(0)
        exit()
        
    answer = 1
    limit = pow(10, 18)
    for i in range(N):
        answer *= A[i]
        if answer > limit:
            print(-1)
            exit()
        else:
            continue

    print(answer)

    #N = 1のときなどcorner caseを確認！
if __name__ == "__main__":
    main()