fork download
  1. def solve_stick(N, K, L):
  2. # If there's only one square
  3. if N == 1:
  4. # Return the area of a single square
  5. return 4 * L * L
  6.  
  7. # Check if squares overlap
  8. # Distance between centers of consecutive squares is K
  9. # Each square has side length 2L
  10. if K <= 2 * L:
  11. # Squares overlap or touch
  12. # Calculate the total length covered
  13. total_length = (N - 1) * K + 2 * L
  14. # Area will be total_length × (width of squares)
  15. return total_length * 2 * L
  16. else:
  17. # Squares don't overlap
  18. # Simply multiply area of one square by number of squares
  19. return N * 4 * L * L
  20.  
  21. def main():
  22. # Read input
  23. N, K, L = map(int, input().split())
  24.  
  25. # Calculate and print result
  26. result = solve_stick(N, K, L)
  27. print(result)
  28.  
  29. if __name__ == "__main__":
  30. main()
Success #stdin #stdout 0.05s 9776KB
stdin
4 1 2
stdout
28