diff --git a/buggy.py b/buggy.py
--- a/buggy.py
+++ b/buggy.py
@@ -18,6 +18,7 @@
             return 0
         idx1, idx2, idx3, idx4 = 0, 0, 0, 0
         cnt = 0
+        cnt1 = 0
         for i in range(N):
             if s[i] == "1":
                 cnt += 1
@@ -25,13 +26,13 @@
                 idx1 = i
                 break
         for i in range(idx1 + 1, N):
-            if s[i] == "0":
+            if s[i] == "1":
                 idx2 = i
                 break
         for i in range(N - 1, -1, -1):
             if s[i] == "1":
-                cnt += 1
-            if cnt == c1 // 3:
+                cnt1 += 1
+            if cnt1 == c1 // 3:
                 idx4 = i
                 break
         for i in range(idx4 - 1, -1, -1):
