Problem:
Score : 100 points

Problem Statement

Given an integer a as input, print the value a + a^2 + a^3.

Constraints

1 \leq a \leq 10

a is an integer.

Input

Input is given from Standard Input in the following format:

a

Output

Print the value a + a^2 + a^3 as an integer.

Sample Input 1

2

Sample Output 1

14

When a = 2, we have a + a^2 + a^3 = 2 + 2^2 + 2^3 = 2 + 4 + 8 = 14.

Print the answer as an input. Outputs such as 14.0 will be judged as incorrect.

Sample Input 2

10

Sample Output 2

1110

Solution in Java (OpenJDK 11.0.6) (judge verdict: Runtime Error)

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		long K = sc.nextLong();
		int[] A = new int[N];
		int[] B = new int[M];
		
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
		}
		for (int i = 0; i < M; i++) {
			B[i] = sc.nextInt();
		}
		
		
		//aから始まる場合
		long minAStart = 0;
		int countAAStart = 0;
		int countBAStart = 0;
		
		//事前準備
		for (int i = 0; i < N; i++) {
			if(minAStart + A[countAAStart] > K) break;
			minAStart += (long)A[i];
			countAAStart++;
		}
		
		if(countAAStart == N) {
			for (int j = 0; j < M; j++) {
				if(minAStart + B[countAAStart] > K) break;
				minAStart += (long)B[j];
				countBAStart++;
			}
		}
		
		//Bに置き換えていく
		long maxNumAStart = countAAStart + countBAStart;
		for (int i = countBAStart; i < M; i++) {
			while(minAStart + B[countBAStart] > K) {
				if(countAAStart == 0) {
					break;
				}
				minAStart -= A[countAAStart];
				countAAStart--;
			}
			if(minAStart + B[countBAStart] > K) {
				break;
			}
			minAStart += B[countBAStart];
			countBAStart++;
			if(countAAStart + countBAStart >= maxNumAStart) {
				maxNumAStart = countAAStart + countBAStart;
			}
			
		}
		
		//bから始まる場合
		long minBStart = 0;
		int countBBStart = 0;
		int countABStart = 0;
		
		//事前準備
		for (int i = 0; i < N; i++) {
			if(minBStart + B[countBBStart] > K) break;
			minBStart += (long)B[i];
			countBBStart++;
		}
		
		if(countBBStart == N) {
			for (int j = 0; j < N; j++) {
				if(minBStart + A[countABStart] > K) break;
				minBStart += (long)A[j];
				countABStart++;
			}
		}
		//Aに置き換えていく
		long maxNumBStart = countBBStart + countABStart;
		for (int i = countABStart; i < N; i++) {
			while(minBStart + A[countABStart] > K) {
				if(countBBStart == 0) {
					break;
				}
				minBStart -= B[countBBStart];
				countBBStart--;
			}
			if(minAStart + A[countABStart] > K) {
				break;
			}
			minBStart += A[countABStart];
			countABStart++;
			if(countABStart + countBBStart >= maxNumBStart) {
				maxNumBStart = countABStart + countBBStart;
			}
		}
		
		
		System.out.println(Math.max(maxNumAStart, maxNumBStart));
	}

}