fork download
  1. #include <iostream>
  2. #include <algorithm> // For min and max
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7. long long N, K, L;
  8. cin >> N >> K >> L;
  9.  
  10. // Initialize the boundaries of the combined area
  11. long long leftmost = 0;
  12. long long rightmost = (N - 1) * (K + L);
  13. long long bottommost = 0;
  14. long long topmost = (N - 1) * (K + L);
  15.  
  16. // Iterate through each square
  17. for (long long i = 0; i < N; ++i) {
  18. // Calculate the boundaries of the current square
  19. long long square_left = i * (K + L);
  20. long long square_right = i * (K + L) + K + L - 1;
  21. long long square_bottom = i * (K + L);
  22. long long square_top = i * (K + L) + K + L - 1;
  23.  
  24. // Update the combined area boundaries
  25. leftmost = min(leftmost, square_left);
  26. rightmost = max(rightmost, square_right);
  27. bottommost = min(bottommost, square_bottom);
  28. topmost = max(topmost, square_top);
  29. }
  30.  
  31. // Calculate the area of the combined area
  32. long long area = (rightmost - leftmost + 1) * (topmost - bottommost + 1);
  33.  
  34. cout << area << endl;
  35.  
  36. return 0;
  37. }
Success #stdin #stdout 0s 5288KB
stdin
4 1 2
stdout
144