Macro Pitfalls

Points 100 1.0s 256M

Many people learning the C++ #define macro misuse it by treating #define F(X) as a function.

Consider the following problem:

You are given two points \(A\) and \(B\) in the 2D plane. \(A\) has coordinates \((A_x,A_y)\), and \(B\) has coordinates \((B_x, B_y)\). Compute the square of the Euclidean distance between \(A\) and \(B\).

We know the distance is \(\sqrt{(A_x - B_x)^2 + (A_y - B_y)^2}\), so its square is \((A_x - B_x)^2 + (A_y - B_y)^2\). The squaring appears twice. Some programmers choose to denote squaring with a macro, writing code as follows:

#include<iostream>
using namespace std;
#define SQR(X) X * X
int main() {
    int A_x, A_y, B_x, B_y;
    cin >> A_x >> A_y >> B_x >> B_y;
    cout << SQR(A_x - B_x) + SQR(A_y - B_y) << endl;
    return 0;
}

However, this produces a wrong answer. For example, when \(A=(2, 1)\) and \(B=(-2, -2)\), the program outputs \(13\), but the correct value is \((2-(-2))^2 + (1 - (-2))^2 = 25\).

This happens because the compiler replaces \(SQR(A\_x - B\_x) + SQR(A\_y - B\_y)\) with \(A\_x - B\_x * A\_x - B\_x + A\_y - B\_y * A\_y - B\_y\). The correct macro should be

#define SQR(X) ((X) * (X))

In this problem, you will reproduce the behavior of both the incorrect and the correct macro. Given the coordinates of points \(A\) and \(B\), output the value produced by the incorrect code above, followed by the correct value.

Input

The input contains a single line with four integers \(A_x, A_y, B_x, B_y\). The constraints are \(-10,000 \le A_x, A_y, B_x, B_y \le 10,000\).

Output

Output one line with two integers: the first is the result printed by the incorrect code in the statement, and the second is the correct value.

Scoring

This problem is worth \(20\) points.

Sample Input 1

2 1 -2 -2

Sample Output 1

13 25

Problem page help

Keyboard shortcuts

Main features

  • Sample tests — Runs the sample cases bundled with the problem and auto-compares against the expected output.
  • Custom test — Run your code with your own stdin. Optionally tick the "Compare with expected (diff)" box to verify against expected output line-by-line.
  • Template — Paste the default code template you set on your profile page.
  • Collab — Edit this problem together with classmates in real time.
  • Auto-draft — Editor contents auto-save to your browser every 1.5 seconds (per account / problem / language).
  • Submit — Send your code to the judge for grading; returns AC / WA / TLE etc.

Limits

  • Source code: at most 65,536 characters
  • Custom test stdin and expected output: at most 1 MB each (≈1 million characters)
  • Custom test and sample test share the sandbox; about 1 request per 3 s per user (sample test: 1 per 1 s)
  • Custom test and sample test both have a 15 second wall-clock cap (the official judge still uses the problem time limit)
  • Interactive problems do not offer custom test (cannot simulate interaction with the judge).
  • Submitting has no rate limit, but rapid repeated submissions on the same problem are treated as score farming.