diff --git a/buggy.py b/buggy.py
--- a/buggy.py
+++ b/buggy.py
@@ -5,11 +5,12 @@
     if N & (1 << k):
         rr = (1 << (k + 1)) - 1
         ll = 1 << k
+        if rr < L or R < ll:
+            continue
         nums = rr - ll + 1
         if R < rr:
             nums -= rr - R
         if ll < L:
             nums -= L - ll
         ans += nums
-
 print(ans)
