diff --git a/buggy.py b/buggy.py
--- a/buggy.py
+++ b/buggy.py
@@ -1,6 +1,6 @@
 def d(a, b, c, x):
     t = x // (a + c)
-    return t * (a * b) + (x - ((a + c) * t)) * b
+    return t * (a * b) + min(a, (x - ((a + c) * t))) * b
 
 
 A, B, C, D, E, F, X = map(int, input().split())
