Page Contents

**The Rating Dilemma Codechef Solution**

Chef really likes to compete on Codechef, and he has gained an impressive rating of X, where X>0. There is also a parallel universe, where ratings on Codechef are negative instead. The only thing that remains unchanged in the parallel universe is Chef’s love for competing on Codechef. Chef’s rating on Codechef in the parallel universe is Y, where Y<0.

Due to some cosmic event, the parallel universe has been destroyed, resulting in Chef forgetting both X and Y. He only remembers the sum S=X+Y. He wonders what the maximum possible product of his ratings is, given that he knows the sum of his ratings.

Input Format

The first line of input will contain an integer T — the number of test cases. The description of T test cases follows.

The first and only line of each test case contains an integer S, the sum of Chef’s ratings.

Output Format

For each test case, output the maximum possible product of Chef’s ratings, given that he knows the sum of his ratings.

Constraints

1≤T≤103

0≤S≤109

Subtasks

Subtask #1 (100 points): Original constraints

Sample Input 1

2

0

1

Sample Output 1

-1

-2

Explanation

Test case 1: We have X>0 and X+Y=0. This implies that Y=−X. The product of ratings is −X2, and the maximum possible product is −1.

**SOLUTION**

**Program:** **The Rating Dilemma Codechef Solution** in Python

for i in range(int(input())): x=int(input()) if(x>=0): print((x+1)*(-1)) else: print(x-1)

**Program:** **The Rating Dilemma Codechef Solution** in C++

#include <iostream> using namespace std; void cC(int s) { cout<<-(s+1)<<endl; } int main() { int t; cin>>t; while(t--) { int s; cin>>s; cC(s); } }

**Program:** **The Rating Dilemma Codechef Solution** in Java

import java.util.*; import java.lang.*; import java.io.*; class Codechef { public static void main (String[] args) throws java.lang.Exception { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ long s=sc.nextLong(); long x=s+1; long y=s-x; System.out.println(x*y); } } }

**Related:**

*Perfect Imperfections 2 Codechef Solution**Kostomuksha and AESC MSU Codechef Solution**Minimum Longest Substring Codechef Solution**Same Parity Swaps in Binary Strings Codechef Solution**Missing Numbers Codechef Solution**The Rating Dilemma Codechef Solution**Chef and Races Codechef Solution**The Three Topics Codechef Solution**Increase IQ Codechef Solution*