diff --git a/buggy.py b/buggy.py
--- a/buggy.py
+++ b/buggy.py
@@ -10,7 +10,7 @@
 for n in range(N - 1):
     fsum = fsum - fnsum + m[(n + mid) % N] * (mid - 1) + m[n]
     fnsum = fnsum + m[(n + mid) % N] - m[n]
-    lsum = lsum + lnsum + m[n] - m[(n + mid) % N] * (mid + 1)
+    lsum = lsum + lnsum + m[n] - m[(n + mid) % N] * (N - mid + 1)
     lnsum = lnsum + m[n] - m[(n + mid) % N]
     ans = min(ans, fsum + lsum)
 print(ans)
