diff --git a/buggy.py b/buggy.py
--- a/buggy.py
+++ b/buggy.py
@@ -105,7 +105,7 @@
 for a, b, c in E:
     g.add_edge(a, b + 150, 1, INF - c)
 ans = [0]
-for i in range(1, N):
+for i in range(1, N + 1):
     c = g.minimum_cost_flow(s, t, 1, -(ans[-1] - INF * (i - 1)))
     if c is None:
         break
