Buggy python submission (verdict: Time Limit Exceeded):


def pow_mod(x, y):
    MOD = 1000000007
    if y == 0: return 1
    ans = 1
    while y > 1:
        if y % 2 != 0: 
            ans *= x
            ans %= MOD
        x *= x
        x %= MOD
        y //= 2
    return ans * x % MOD

def main():
  MOD = 1000000007
  r1, c1, r2, c2 = map(int, input().split()) 

  points = {r2 + c2 + 2, r2 + 1, c2 + 1, r2 + c1 + 1, c1, r1 + c2 + 1, r1, r1 + c1}

  factorial_map = {0: 1}
  factorial_inv_map = {0: 1}
  for i in range(1, r2 + c2 + 3):
    factorial_map[i] = (factorial_map[i - 1] * i) % MOD
    factorial_inv_map[i] = (factorial_inv_map[i - 1] * pow_mod(i, MOD - 2)) % MOD
    if i > 1 and (i - 2) not in points:
      del factorial_map[i-2]
      del factorial_inv_map[i-2]

  a = 1
  a *= factorial_map[r2 + c2 + 2]
  a %= MOD
  a *= factorial_inv_map[r2 + 1]
  a %= MOD
  a *= factorial_inv_map[c2 + 1]
  a %= MOD

  b = 1
  b *= factorial_map[r2 + c1 + 1]
  b %= MOD
  b *= factorial_inv_map[r2 + 1]
  b %= MOD
  b *= factorial_inv_map[c1]
  b %= MOD

  c = 1
  c *= factorial_map[r1 + c2 + 1]
  c %= MOD
  c *= factorial_inv_map[r1]
  c %= MOD
  c *= factorial_inv_map[c2 + 1]
  c %= MOD

  d = 1
  d *= factorial_map[r1 + c1]
  d %= MOD
  d *= factorial_inv_map[r1]
  d %= MOD
  d *= factorial_inv_map[c1]
  d %= MOD

  ans = a
  ans -= b
  ans %= MOD
  ans -= c 
  ans %= MOD
  ans += d
  ans %= MOD

  print(ans)


if __name__ == "__main__":
  main()

Fixed submission:


def pow_mod(x, y):
    MOD = 1000000007
    if y == 0: return 1
    ans = 1
    while y > 1:
        if y % 2 != 0: 
            ans *= x
            ans %= MOD
        x *= x
        x %= MOD
        y //= 2
    return ans * x % MOD

def main():
  MOD = 1000000007
  r1, c1, r2, c2 = map(int, input().split()) 

  points = {r2 + c2 + 2, r2 + 1, c2 + 1, r2 + c1 + 1, c1, r1 + c2 + 1, r1, r1 + c1}

  factorial_map = {0: 1}
  for i in range(1, r2 + c2 + 3):
    factorial_map[i] = (factorial_map[i - 1] * i) % MOD
    if i > 1 and (i - 2) not in points:
      del factorial_map[i-2]

  a = 1
  a *= factorial_map[r2 + c2 + 2]
  a %= MOD
  a *= pow_mod(factorial_map[r2 + 1], MOD - 2)
  a %= MOD
  a *= pow_mod(factorial_map[c2 + 1], MOD - 2)
  a %= MOD

  b = 1
  b *= factorial_map[r2 + c1 + 1]
  b %= MOD
  b *= pow_mod(factorial_map[r2 + 1], MOD - 2)
  b %= MOD
  b *= pow_mod(factorial_map[c1], MOD - 2)
  b %= MOD

  c = 1
  c *= factorial_map[r1 + c2 + 1]
  c %= MOD
  c *= pow_mod(factorial_map[r1], MOD - 2)
  c %= MOD
  c *= pow_mod(factorial_map[c2 + 1], MOD - 2)
  c %= MOD

  d = 1
  d *= factorial_map[r1 + c1]
  d %= MOD
  d *= pow_mod(factorial_map[r1], MOD - 2)
  d %= MOD
  d *= pow_mod(factorial_map[c1], MOD - 2)
  d %= MOD

  ans = a
  ans -= b
  ans %= MOD
  ans -= c 
  ans %= MOD
  ans += d
  ans %= MOD

  print(ans)


if __name__ == "__main__":
  main()

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

MOD = 1000000007

def pow_mod(x, y):
    if y == 0: return 1
    ans = 1
    while y > 1:
        if y % 2 != 0: 
            ans *= x
            ans %= MOD
        x *= x
        x %= MOD
        y //= 2
    return ans * x % MOD

points = {r2 + c2 + 2, r2 + 1, c2 + 1, r2 + c1 + 1, c1, r1 + c2 + 1, r1, r1 + c1}

factorial_map = {0: 1}
factorial_inv_map = {0: 1}
for i in range(1, r2 + c2 + 3):
  factorial_map[i] = (factorial_map[i - 1] * i) % MOD
  factorial_inv_map[i] = (factorial_inv_map[i - 1] * pow_mod(i, MOD - 2)) % MOD
  if i > 1 and (i - 2) not in points:
    del factorial_map[i-2]
    del factorial_inv_map[i-2]


a = 1
a *= factorial_map[r2 + c2 + 2]
a %= MOD
a *= factorial_inv_map[r2 + 1]
a %= MOD
a *= factorial_inv_map[c2 + 1]
a %= MOD

b = 1
b *= factorial_map[r2 + c1 + 1]
b %= MOD
b *= factorial_inv_map[r2 + 1]
b %= MOD
b *= factorial_inv_map[c1]
b %= MOD

c = 1
c *= factorial_map[r1 + c2 + 1]
c %= MOD
c *= factorial_inv_map[r1]
c %= MOD
c *= factorial_inv_map[c2 + 1]
c %= MOD

d = 1
d *= factorial_map[r1 + c1]
d %= MOD
d *= factorial_inv_map[r1]
d %= MOD
d *= factorial_inv_map[c1]
d %= MOD

ans = a
ans -= b
ans %= MOD
ans -= c 
ans %= MOD
ans += d
ans %= MOD

print(ans)

Fixed submission:


def pow_mod(x, y):
    MOD = 1000000007
    if y == 0: return 1
    ans = 1
    while y > 1:
        if y % 2 != 0: 
            ans *= x
            ans %= MOD
        x *= x
        x %= MOD
        y //= 2
    return ans * x % MOD

def main():
  MOD = 1000000007
  r1, c1, r2, c2 = map(int, input().split()) 

  points = {r2 + c2 + 2, r2 + 1, c2 + 1, r2 + c1 + 1, c1, r1 + c2 + 1, r1, r1 + c1}

  factorial_map = {0: 1}
  for i in range(1, r2 + c2 + 3):
    factorial_map[i] = (factorial_map[i - 1] * i) % MOD
    if i > 1 and (i - 2) not in points:
      del factorial_map[i-2]

  a = 1
  a *= factorial_map[r2 + c2 + 2]
  a %= MOD
  a *= pow_mod(factorial_map[r2 + 1], MOD - 2)
  a %= MOD
  a *= pow_mod(factorial_map[c2 + 1], MOD - 2)
  a %= MOD

  b = 1
  b *= factorial_map[r2 + c1 + 1]
  b %= MOD
  b *= pow_mod(factorial_map[r2 + 1], MOD - 2)
  b %= MOD
  b *= pow_mod(factorial_map[c1], MOD - 2)
  b %= MOD

  c = 1
  c *= factorial_map[r1 + c2 + 1]
  c %= MOD
  c *= pow_mod(factorial_map[r1], MOD - 2)
  c %= MOD
  c *= pow_mod(factorial_map[c2 + 1], MOD - 2)
  c %= MOD

  d = 1
  d *= factorial_map[r1 + c1]
  d %= MOD
  d *= pow_mod(factorial_map[r1], MOD - 2)
  d %= MOD
  d *= pow_mod(factorial_map[c1], MOD - 2)
  d %= MOD

  ans = a
  ans -= b
  ans %= MOD
  ans -= c 
  ans %= MOD
  ans += d
  ans %= MOD

  print(ans)


if __name__ == "__main__":
  main()

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

MOD = 1000000007

def pow_mod(x, y):
    if y == 0: return 1
    ans = 1
    while y > 1:
        if y % 2 != 0: 
            ans *= x
            ans %= MOD
        x *= x
        x %= MOD
        y //= 2
    return ans * x % MOD

factorial_map = {0: 1}
factorial_inv_map = {0: 1}
for i in range(1, r2 + c2 + 3):
  factorial_map[i] = (factorial_map[i - 1] * i) % MOD
  factorial_inv_map[i] = (factorial_inv_map[i - 1] * pow_mod(i, MOD - 2)) % MOD


a = 1
a *= factorial_map[r2 + c2 + 2]
a %= MOD
a *= factorial_inv_map[r2 + 1]
a %= MOD
a *= factorial_inv_map[c2 + 1]
a %= MOD

b = 1
b *= factorial_map[r2 + c1 + 1]
b %= MOD
b *= factorial_inv_map[r2 + 1]
b %= MOD
b *= factorial_inv_map[c1]
b %= MOD

c = 1
c *= factorial_map[r1 + c2 + 1]
c %= MOD
c *= factorial_inv_map[r1]
c %= MOD
c *= factorial_inv_map[c2 + 1]
c %= MOD

d = 1
d *= factorial_map[r1 + c1]
d %= MOD
d *= factorial_inv_map[r1]
d %= MOD
d *= factorial_inv_map[c1]
d %= MOD

ans = a
ans -= b
ans %= MOD
ans -= c 
ans %= MOD
ans += d
ans %= MOD

print(ans)

Fixed submission:


def pow_mod(x, y):
    MOD = 1000000007
    if y == 0: return 1
    ans = 1
    while y > 1:
        if y % 2 != 0: 
            ans *= x
            ans %= MOD
        x *= x
        x %= MOD
        y //= 2
    return ans * x % MOD

def main():
  MOD = 1000000007
  r1, c1, r2, c2 = map(int, input().split()) 

  points = {r2 + c2 + 2, r2 + 1, c2 + 1, r2 + c1 + 1, c1, r1 + c2 + 1, r1, r1 + c1}

  factorial_map = {0: 1}
  for i in range(1, r2 + c2 + 3):
    factorial_map[i] = (factorial_map[i - 1] * i) % MOD
    if i > 1 and (i - 2) not in points:
      del factorial_map[i-2]

  a = 1
  a *= factorial_map[r2 + c2 + 2]
  a %= MOD
  a *= pow_mod(factorial_map[r2 + 1], MOD - 2)
  a %= MOD
  a *= pow_mod(factorial_map[c2 + 1], MOD - 2)
  a %= MOD

  b = 1
  b *= factorial_map[r2 + c1 + 1]
  b %= MOD
  b *= pow_mod(factorial_map[r2 + 1], MOD - 2)
  b %= MOD
  b *= pow_mod(factorial_map[c1], MOD - 2)
  b %= MOD

  c = 1
  c *= factorial_map[r1 + c2 + 1]
  c %= MOD
  c *= pow_mod(factorial_map[r1], MOD - 2)
  c %= MOD
  c *= pow_mod(factorial_map[c2 + 1], MOD - 2)
  c %= MOD

  d = 1
  d *= factorial_map[r1 + c1]
  d %= MOD
  d *= pow_mod(factorial_map[r1], MOD - 2)
  d %= MOD
  d *= pow_mod(factorial_map[c1], MOD - 2)
  d %= MOD

  ans = a
  ans -= b
  ans %= MOD
  ans -= c 
  ans %= MOD
  ans += d
  ans %= MOD

  print(ans)


if __name__ == "__main__":
  main()

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

MOD = 1000000007

def pow_mod(x, y):
    if y == 0: return 1
    ans = 1
    while y > 1:
        if y % 2 != 0: 
            ans *= x
            ans %= MOD
        x *= x
        x %= MOD
        y //= 2
    return ans * x % MOD

factorial_map = {0: 1}
factorial_inv_map = {0: 1}
for i in range(1, r2 + c2 + 3):
  factorial_map[i] = (factorial_map[i - 1] * i) % MOD
  factorial_inv_map[i] = (factorial_inv_map[i - 1] * pow_mod(i, MOD - 2)) % MOD


a = 1
a *= factorial_map[r2 + c2 + 2]
a %= MOD
a *= factorial_inv_map[r2 + 1]
a %= MOD
a *= factorial_inv_map[c2 + 1]
a %= MOD

b = 1
b *= factorial_map[r2 + c1 + 1]
b %= MOD
b *= factorial_inv_map[r2 + 1]
b %= MOD
b *= factorial_inv_map[c1]
b %= MOD

c = 1
c *= factorial_map[r1 + c2 + 1]
c %= MOD
c *= factorial_inv_map[r1]
c %= MOD
c *= factorial_inv_map[c2 + 1]
c %= MOD

d = 1
d *= factorial_map[r1 + c1]
d %= MOD
d *= factorial_inv_map[r1]
d %= MOD
d *= factorial_inv_map[c1]
d %= MOD

ans = a
ans -= b
ans %= MOD
ans -= c 
ans %= MOD
ans += d
ans %= MOD

print(ans)

Fixed submission:


def pow_mod(x, y):
    MOD = 1000000007
    if y == 0: return 1
    ans = 1
    while y > 1:
        if y % 2 != 0: 
            ans *= x
            ans %= MOD
        x *= x
        x %= MOD
        y //= 2
    return ans * x % MOD

def main():
  MOD = 1000000007
  r1, c1, r2, c2 = map(int, input().split()) 

  points = {r2 + c2 + 2, r2 + 1, c2 + 1, r2 + c1 + 1, c1, r1 + c2 + 1, r1, r1 + c1}

  factorial_map = {0: 1}
  for i in range(1, r2 + c2 + 3):
    factorial_map[i] = (factorial_map[i - 1] * i) % MOD
    if i > 1 and (i - 2) not in points:
      del factorial_map[i-2]

  a = 1
  a *= factorial_map[r2 + c2 + 2]
  a %= MOD
  a *= pow_mod(factorial_map[r2 + 1], MOD - 2)
  a %= MOD
  a *= pow_mod(factorial_map[c2 + 1], MOD - 2)
  a %= MOD

  b = 1
  b *= factorial_map[r2 + c1 + 1]
  b %= MOD
  b *= pow_mod(factorial_map[r2 + 1], MOD - 2)
  b %= MOD
  b *= pow_mod(factorial_map[c1], MOD - 2)
  b %= MOD

  c = 1
  c *= factorial_map[r1 + c2 + 1]
  c %= MOD
  c *= pow_mod(factorial_map[r1], MOD - 2)
  c %= MOD
  c *= pow_mod(factorial_map[c2 + 1], MOD - 2)
  c %= MOD

  d = 1
  d *= factorial_map[r1 + c1]
  d %= MOD
  d *= pow_mod(factorial_map[r1], MOD - 2)
  d %= MOD
  d *= pow_mod(factorial_map[c1], MOD - 2)
  d %= MOD

  ans = a
  ans -= b
  ans %= MOD
  ans -= c 
  ans %= MOD
  ans += d
  ans %= MOD

  print(ans)


if __name__ == "__main__":
  main()