diff --git a/buggy.py b/buggy.py
--- a/buggy.py
+++ b/buggy.py
@@ -19,7 +19,7 @@
     if sum(B[:K]) <= M:
         ans += m
         for j in range(N):
-            if (A[j] >> (maxbit - i)) & 1:
+            if not (A[j] >> (maxbit - i)) & 1:
                 count = m - A[j]
                 A[j] += count
                 C[j] += count
