fork download
  1. def stick(N, K, L):
  2. """
  3. Calculates the area of the union of N squares.
  4.  
  5. Args:
  6. N: The number of squares.
  7. K: The side length of each square.
  8. L: The distance between the bottom-left corners of consecutive squares.
  9.  
  10. Returns:
  11. The area of the union of the squares.
  12. """
  13.  
  14. # Calculate the area of each square
  15. square_area = K * K
  16.  
  17. # Calculate the overlap between consecutive squares
  18. overlap = (K - L) * (K - L)
  19.  
  20. # Calculate the total area
  21. total_area = N * square_area - (N - 1) * overlap
  22.  
  23. return total_area
  24.  
  25. # Read input
  26. N, K, L = map(int, input().split())
  27.  
  28. # Calculate and print the output
  29. print(stick(N, K, L))
Success #stdin #stdout 0.03s 9844KB
stdin
4 1 2
stdout
1