fork download
  1. def solve(N, K, L):
  2. # If there's only one square
  3. if N == 1:
  4. return 4 * L * L
  5.  
  6. # Calculate coordinates for each square and find max and min points
  7. min_x = min_y = float('inf')
  8. max_x = max_y = float('-inf')
  9.  
  10. for i in range(N):
  11. # Bottom-left corner
  12. x1, y1 = i * K - L, i * K - L
  13. # Top-right corner
  14. x2, y2 = i * K + L, i * K + L
  15.  
  16. min_x = min(min_x, x1)
  17. min_y = min(min_y, y1)
  18. max_x = max(max_x, x2)
  19. max_y = max(max_y, y2)
  20.  
  21. # Calculate area of the bounding rectangle
  22. width = max_x - min_x
  23. height = max_y - min_y
  24. return width * height
  25.  
  26. def main():
  27. # Read input
  28. N, K, L = map(int, input().split())
  29.  
  30. # Calculate and output result
  31. result = solve(N, K, L)
  32. print(result)
  33.  
  34. if __name__ == "__main__":
  35. main()
Success #stdin #stdout 0.04s 9760KB
stdin
4 1 2
stdout
49