You are given a grid with A horizontal rows and B vertical columns, initially all painted white. You can repeatedly add a row or column to the grid and then paint one of the added squares black. The grid eventually has C horizontal rows and D vertical columns. Find the number of ways to paint the squares in the end, modulo 998244353. Constraints: 1 ≤ A ≤ C ≤ 3000, 1 ≤ B ≤ D ≤ 3000. Input format: A B C D. Output: Number of ways to paint the squares. Example: Input: 1 1 2 2, Output: 3 (any two of the three squares other than the bottom-left square can be painted black).

# Buggy version:
A,B,C,D = map(int, input().split())

P=998244353

dp = [[[0 for k in range(2)] for j in range(3002)] for i in range(3002)]
dp[A][B][1] = 1

for row in range(A, C + 1):
    for col in range(B, D + 1):
        dp[row][col + 1][1] += dp[row][col][0] + row * dp[row][col][1]
        dp[row][col + 1][1] %= P
        dp[row + 1][col][0] = col * (dp[row][col][0] + dp[row][col][1])

print((dp[C][D][0]+dp[C][D][1])%P)

# Fixed version:
A,B,C,D = map(int, input().split())

P=998244353

dp = [[0 for j in range(3002)] for i in range(3002)]
dp[A][B] = 1

for row in range(A, C + 1):
    for col in range(B, D + 1):
        dp[row][col] += col * dp[row - 1][col] + row * dp[row][col - 1]
        dp[row][col] -= (row - 1) * (col - 1) * dp[row - 1][col - 1]
        dp[row][col] %= P

print(dp[C][D])

# Buggy version:
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
MOD = 998244353

a, b, c, d = map(int, input().split())

dp = [[0] * d for _ in range(c)]
dp[a-1][b-1] = 1
for i in range(c):
    for j in range(d):
        # Use i, j
        if i - 1 >= 0:
            dp[i][j] += dp[i-1][j]
        if j - 1 >= 0:
            dp[i][j] += dp[i][j-1]
        # Use others
        if i - 1 >= 0:
            dp[i][j] += dp[i][j-1] * i 
        dp[i][j] %= MOD

print(dp[-1][-1])

# Fixed version:
#!/usr/bin/env python3
import sys
input = sys.stdin.readline

a, b, c, d = map(int, input().split())
dp = [[0] * (d - b + 1) for _ in range(c - a + 1)]

dp[0][0] = 1
for i in range(c - a + 1):
    for j in range(d - b + 1):
        if i > 0:
            dp[i][j] += dp[i-1][j] * (b+j)
        if j > 0:
            dp[i][j] += dp[i][j-1] * (a+i)
        if i > 0 and j > 0:
            dp[i][j] -= dp[i-1][j-1] * (b+j-1) * (a+i-1)
        dp[i][j] %= 998244353

print(dp[-1][-1])

# Buggy version:
A,B,C,D = map(int,input().split())

MOD=998244353

#dp[i][j]たてにi回、横にj回追加したときの数
DP=[[0]*(D-B+1) for _ in range(C-A+1)]
DP[0][0]=1

for i in range(1,C-A+1):
    DP[i][0]=DP[i-1][0]*B
    DP[i][0]%=MOD
for i in range(1,D-B+1):
    DP[0][i]=DP[0][i-1]*A
    DP[0][i]%=MOD

print(DP)

for i in range(1,min(C-A,D-B)+1):
    for j in range(i,C-A+1):
        DP[j][i] = DP[j-1][i]*(B+i) + DP[j][i-1]*(A+j)-DP[j-1][i-1]*(B+i-1)*(A+j-1)
        DP[j][i]%=MOD
    for j in range(i+1,D-B+1):
        DP[i][j] = DP[i-1][j]*(B+j) + DP[i][j-1]*(A+i)-DP[i-1][j-1]*(B+j-1)*(A+i-1)
        DP[i][j]%=MOD

print(DP[-1][-1])


# Fixed version:
A,B,C,D = map(int,input().split())

MOD=998244353

#dp[i][j]たてにi回、横にj回追加したときの数
DP=[[0]*(D-B+1) for _ in range(C-A+1)]
DP[0][0]=1

for i in range(1,C-A+1):
    DP[i][0]=DP[i-1][0]*B
    DP[i][0]%=MOD
for i in range(1,D-B+1):
    DP[0][i]=DP[0][i-1]*A
    DP[0][i]%=MOD

for i in range(1,min(C-A,D-B)+1):
    for j in range(i,C-A+1):
        DP[j][i] = DP[j-1][i]*(B+i) + DP[j][i-1]*(A+j)-DP[j-1][i-1]*(B+i-1)*(A+j-1)
        DP[j][i]%=MOD
    for j in range(i+1,D-B+1):
        DP[i][j] = DP[i-1][j]*(B+j) + DP[i][j-1]*(A+i)-DP[i-1][j-1]*(B+j-1)*(A+i-1)
        DP[i][j]%=MOD


print(DP[-1][-1])

# Buggy version:
mod = 998244353
a, b, c, d = map(int, input().split())

dp0 = [0] * (c-a+1)
dp1 = [1]

for i in range(c-a):
    dp1.append(dp1[-1] * b % mod)

i = [dp0[i] + dp1[i] for i in range(len(dp0))]
print(i)

for j in range(1, d-b+1):
    new_dp0 = [(dp0[0] * a + dp1[0]) % mod]
    new_dp1 = [dp1[0] * (a-1) % mod]
    for i in range(1, c-a+1):
        new_dp0.append((dp0[i] * (a+i) + dp1[i]) % mod)
        new_dp1.append((new_dp0[-2] + new_dp1[-1]) * (b+j) % mod)

    dp0 = new_dp0
    dp1 = new_dp1

    i = [dp0[i] + dp1[i] for i in range(len(dp0))]
    print(i)

print(dp0[-1] + dp1[-1])

# Fixed version:
mod = 998244353
a, b, c, d = map(int, input().split())

dp0 = [0] * (c-a+1)
dp1 = [1]
for i in range(c-a):
    dp1.append(dp1[-1] * b % mod)

for j in range(1, d-b+1):
    new_dp0 = [(dp0[0] * a + dp1[0]) % mod]
    new_dp1 = [dp1[0] * (a-1) % mod]
    for i in range(1, c-a+1):
        new_dp0.append((dp0[i] * (a+i) + dp1[i]) % mod)
        new_dp1.append((new_dp0[-2] + new_dp1[-1]) * (b+j) % mod)

    dp0 = new_dp0
    dp1 = new_dp1

print((dp0[-1] + dp1[-1]) % mod)

# Buggy version:
a, b, c, d = map(int, input().split())
MOD = 998244353

dp = [[0] * (d - b + 1) for _ in range(c - a + 1)]

dp[0][0] = 1

for x in range(1, d - b + 1):
    dp[0][x] = dp[0][x - 1] * a % MOD
for y in range(1, c - a + 1):
    dp[y][0] = dp[y - 1][0] * b % MOD

for x in range(1, c - a + 1):
    for y in range(1, d - b + 1):
        dp[x][y] = (dp[x - 1][y] * (b + y) + dp[x][y - 1] * (a + x)) % MOD
    
print(dp[-1][-1])

# Fixed version:
a, b, c, d = map(int, input().split())
MOD = 998244353

dp = [[0] * (d - b + 1) for _ in range(c - a + 1)]

dp[0][0] = 1

for x in range(1, d - b + 1):
    dp[0][x] = dp[0][x - 1] * a % MOD
for y in range(1, c - a + 1):
    dp[y][0] = dp[y - 1][0] * b % MOD

for x in range(1, c - a + 1):
    for y in range(1, d - b + 1):
        dp[x][y] = (dp[x - 1][y] * (b + y) + dp[x][y - 1] * (a + x) - dp[x - 1][y - 1] * (a + x - 1) * (b + y - 1)) % MOD

print(dp[-1][-1])

# Buggy version:
a,b,c,d = map(int,input().split())
mod = 998244353
dp = [[0]*(d-b+1) for i in range(c-a+1)]
if a == c and b == d:
    print(1)
elif a == c:
    print(a)
elif b == d:
    print(b):
else:
    for i in range(c-a):
        p = 0
        for j in range(d-b+1):
            if i == j == 0:
                dp[i][j] = 1
            dp[i+1][j] = (p + dp[i][j]*(b+j))%mod

            p += dp[i][j]
            p %= mod
            p *= a+i
            p %= mod

    ans = 0
    for d in dp[-1]:
        ans *= c
        ans %= mod
        ans += d
        ans %= mod
    print(ans)

# Fixed version:
a,b,c,d = map(int,input().split())
mod = 998244353
dp = [[0]*(d-b+1) for i in range(c-a+1)]
if a == c and b == d:
    print(1)
elif a == c:
    print(pow(a,d-b,mod))
elif b == d:
    print(pow(b,c-a,mod))
else:
    for i in range(c-a):
        p = 0
        for j in range(d-b+1):
            if i == j == 0:
                dp[i][j] = 1
            dp[i+1][j] = (p + dp[i][j]*(b+j))%mod

            p += dp[i][j]
            p %= mod
            p *= a+i
            p %= mod

    ans = 0
    for d in dp[-1]:
        ans *= c
        ans %= mod
        ans += d
        ans %= mod
    print(ans)