Unable to clear all test cases in Pythagorean Triplet problem

import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner scn = new Scanner(System.in);
int N = scn.nextInt();
int n1,n2,n3;

	if(N<3){
		System.out.print("-1");
	}
	else if(N%2==0){
		int n = 1;
		int m = (int)(N/2);
		n1 = m*m - 1;
		n3 = m*m + n*n;
		System.out.print(n1 + " " + n3);
	}else{
		int n = (int)((N-1)/2);
		int m = (int)((N+1)/2);
		n2 = 2*n*m;
		n3 = m*m + n*n;
		System.out.print(n2 + " " + n3);
	}

}

}

This code is able to pass only 2 of the 4 test cases. Where did i go wrong?

@Raunak-Agrawal-1537545869717573
your code is correct you just need to take long datatype
import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner scn = new Scanner(System.in);
long N = scn.nextLong();
long n1,n2,n3;

if(N<3){
	System.out.print("-1");
}
else if(N%2==0){
	long n = 1;
	long m = (N/2);
	n1 = m*m - 1;
	n3 = m*m + n*n;
	System.out.print(n1 + " " + n3);
}else{
	long n = ((N-1)/2);
	long m = ((N+1)/2);
	n2 = 2*n*m;
	n3 = m*m + n*n;
	System.out.print(n2 + " " + n3);
}

}
}

@Raunak-Agrawal-1537545869717573
because you are squaring a number so it might exceed integer limit.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.