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. # If squares are completely separated
  7. if K > 2 * L:
  8. return N * 4 * L * L
  9.  
  10. # If squares overlap
  11. # Calculate the total area
  12. # Width is constant (2L)
  13. # Length is (N-1)*K + 2L (from leftmost edge to rightmost edge)
  14. length = (N - 1) * K + 2 * L
  15. width = 2 * L
  16.  
  17. return length * width
  18.  
  19. def main():
  20. # Read input
  21. N, K, L = map(int, input().split())
  22.  
  23. # Calculate and output result
  24. result = solve(N, K, L)
  25. print(result)
  26.  
  27. if __name__ == "__main__":
  28. main()
Success #stdin #stdout 0.03s 9856KB
stdin
4 1 2
stdout
28