diff --git a/buggy.py b/buggy.py
--- a/buggy.py
+++ b/buggy.py
@@ -13,7 +13,7 @@
         if s[l] == "o":
             for mid in range(l + 1, r):
                 if s[mid] == "f" and dp[l + 1][mid] == 0:
-                    mi = min(mi, dp[l + 1][mid] + dp[min(r, mid + k + 1)][r])
+                    mi = min(mi, dp[l + 1][mid] + max(0, dp[mid + 1][r] - k))
         dp[l][r] = mi
 
 print(dp[0][n])
