diff --git a/buggy.py b/buggy.py
--- a/buggy.py
+++ b/buggy.py
@@ -21,7 +21,7 @@
 
 answer = 0
 for i in range(N):
-    answer += (1 - A_dp[i][-1]) * T_dp[i + 1][-1]
+    answer += (1 - A_dp[i][-1]) * (T_dp[i + 1][-1] - T_dp[i][-1])
     answer %= mod
 
 print(answer % mod)
