diff --git a/buggy.py b/buggy.py
--- a/buggy.py
+++ b/buggy.py
@@ -19,7 +19,7 @@
 ans = [S]
 for i, c in enumerate(S):
     if c == "p":
-        for j in range(i + 1, N):
+        for j in range(i + 1, N + 1):
             ans.append(S[:i] + swap(S[i:j]) + S[j:])
         break
 print(sorted(ans)[0])
