Buggy python submission (verdict: Time Limit Exceeded):
def solve():
    r1, c1, r2, c2 = map(int, input().split())

    MOD = 10**9+7
    n = r2+c2+1
    fac = [1]*(n+1)
    rev = [1]*(n+1)
    
    for i in range(1,n+1):
      fac[i] = i*fac[i-1]%MOD
      rev[i] = pow(fac[i], MOD-2, MOD)
    
    comb = lambda a,b:(fac[a]*rev[a-b]*rev[b])%MOD

    def f(r, c):
        ans = 0
        for i in range(1, c+2):
            ans += comb(r+i, i)
            ans %= MOD
        return ans

    ans = f(r2, c2) - f(r2, c1-1) - f(r1-1, c2) + f(r1-1, c1-1)
    ans %= MOD

    print(ans)


if __name__ == "__main__":
    solve()


Fixed submission:
def solve():
    r1, c1, r2, c2 = map(int, input().split())

    MOD = 10**9+7
    n = r2+c2+2
    fac = [1]*(n+1)
    rev = [1]*(n+1)
    
    for i in range(1,n+1):
      fac[i] = i*fac[i-1]%MOD
      rev[i] = pow(fac[i], MOD-2, MOD)
    
    comb = lambda a,b:(fac[a]*rev[a-b]*rev[b])%MOD

    def f(r, c):
        return comb(r+c+2, c+1)

    ans = f(r2, c2) - f(r2, c1-1) - f(r1-1, c2) + f(r1-1, c1-1)
    ans %= MOD

    print(ans)


if __name__ == "__main__":
    solve()

Buggy python submission (verdict: Runtime Error):
r1, c1, r2, c2 = map(int, input().split())

MOD = 10**9+7
n = max(r1, c1, r2, c2)
fac = [1]*(n+1)
rev = [1]*(n+1)
 
for i in range(1,n+1):
  fac[i] = i*fac[i-1]%MOD
  rev[i] = pow(fac[i], MOD-2, MOD)
 
comb = lambda a,b:(fac[a]*rev[a-b]*rev[b])%MOD

w = r2 - r1
h = c2 - c1
X, Y = 0, 0
ans = comb(c1+r1, r1)
for i in range(c1+1, c2+1):
    ans += comb(i+r1, r1)
    X += (h-(i-(c1+1)))*comb(i+r1, r1)
for i in range(r1+1, r2+1):
    ans += comb(i+c1, c1)
    Y += (w-(i-(r1+1)))*comb(i+c1, c1)
ans += w*X+h*Y
ans %= MOD
print(ans)

Fixed submission:
def solve():
    r1, c1, r2, c2 = map(int, input().split())

    MOD = 10**9+7
    n = r2+c2+2
    fac = [1]*(n+1)
    rev = [1]*(n+1)
    
    for i in range(1,n+1):
      fac[i] = i*fac[i-1]%MOD
      rev[i] = pow(fac[i], MOD-2, MOD)
    
    comb = lambda a,b:(fac[a]*rev[a-b]*rev[b])%MOD

    def f(r, c):
        return comb(r+c+2, c+1)

    ans = f(r2, c2) - f(r2, c1-1) - f(r1-1, c2) + f(r1-1, c1-1)
    ans %= MOD

    print(ans)


if __name__ == "__main__":
    solve()

Buggy python submission (verdict: Runtime Error):
MOD = 10**9+7
n = 10**5
fac = [1]*(n+1)
rev = [1]*(n+1)
 
for i in range(1,n+1):
  fac[i] = i*fac[i-1]%MOD
  rev[i] = pow(fac[i], MOD-2, MOD)
 
comb = lambda a,b:(fac[a]*rev[a-b]*rev[b])%MOD

r1, c1, r2, c2 = map(int, input().split())
w = r2 - r1
h = c2 - c1
X, Y = 0, 0
ans = comb(c1+r1, r1)
for i in range(c1+1, c2+1):
    ans += comb(i+r1, r1)
    X += (h-(i-(c1+1)))*comb(i+r1, r1)
for i in range(r1+1, r2+1):
    ans += comb(i+c1, c1)
    Y += (w-(i-(r1+1)))*comb(i+c1, c1)
ans += w*X+h*Y
ans %= MOD
print(ans)

Fixed submission:
def solve():
    r1, c1, r2, c2 = map(int, input().split())

    MOD = 10**9+7
    n = r2+c2+2
    fac = [1]*(n+1)
    rev = [1]*(n+1)
    
    for i in range(1,n+1):
      fac[i] = i*fac[i-1]%MOD
      rev[i] = pow(fac[i], MOD-2, MOD)
    
    comb = lambda a,b:(fac[a]*rev[a-b]*rev[b])%MOD

    def f(r, c):
        return comb(r+c+2, c+1)

    ans = f(r2, c2) - f(r2, c1-1) - f(r1-1, c2) + f(r1-1, c1-1)
    ans %= MOD

    print(ans)


if __name__ == "__main__":
    solve()