diff --git a/buggy.py b/buggy.py
--- a/buggy.py
+++ b/buggy.py
@@ -19,8 +19,8 @@
         imos[(R[i] + 1) % D] += S[i] - S[i - 1]
     if -R[i] >= -m:
         r = (-R[i]) % D
-        imos[r] += S[i - 1]
         if r > 0:
+            imos[r] += S[i - 1]
             imos[r] -= S[i]
 ans = score = imos[0]
 for i in range(1, D):
