Equal Coins CodeChef Solution

Hello Programmers In this post, you will know how to solve the Equal Coins CodeChef Solution.Which is a part of CodeChef Solutions.

Equal Coins CodeChef Solution
Equal Coins CodeChef Solution

One more thing to add, don’t directly look for the solutions, first try to solve the problems of Codechef by yourself. If you find any difficulty after trying several times, then you can look for solutions.

Problem

Chef has X coins worth 1 rupee each and Y coins worth 2 rupees each. He wants to distribute all of these X+Y coins to his two sons so that the total value of coins received by each of them is the same. Find out whether Chef will be able to do so.

Input

  • The first line of input contains a single integer T, denoting the number of testcases. The description of T test cases follows.
  • Each test case consists of a single line of input containing two space-separated integers X and Y.

Output

  • For each test case, print “YES” (without quotes) if Chef can distribute all the coins equally and “NO” otherwise. You may print each character of the string in uppercase or lowercase (for example, the strings “yEs”, “yes”, “Yes” and “YES” will all be treated as identical).

Constraints

  • 1 ≤ T ≤ 103
  • 0 ≤ X, Y ≤ 108
  • X + Y > 0

Subtasks

Subtask 1 (100 points): Original constraints

Example

Input:
4
2 2
1 3
4 0
1 10


Output:
YES
NO
YES
NO

Explanation

Test case 11: Chef gives each of his sons 11 coin worth one rupee and 11 coin worth two rupees.

Test case 33: Chef gives each of his sons 22 coins worth one rupee.

Equal Coins CodeChef Solution in JAVA

/* package codechef; // don't place package name! */
import java.util.Scanner;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
    public static void main (String[] args) throws java.lang.Exception
    {
        Scanner input = new Scanner(System.in);
        int test = input.nextInt();
        while (test > 0){
            int x = input.nextInt();
            int y = input.nextInt();
            if (x == 0 && y % 2 == 0){
                System.out.println("YES");
            }
            else if (x == 0 && y % 2 != 0){
                System.out.println("NO");
            }
            else if ((x + (2 * y)) % 2 == 0){
                System.out.println("YES");
            }
            else {
                System.out.println("No");
            }
            test = test - 1;
        }
    }
}

Equal Coins CodeChef Solution in CPP

#include<bits/stdc++.h>
using namespace std;
int main() {
    int t;
    cin >> t;
    while(t--) {
        long long x,y;
        cin >> x >> y;
        if(x == 0 && y%2 != 0) {
            cout << "NO" << endl;
        }
        else if((x+(2*y)) % 2 == 0) {
            cout << "YES" << endl;
        }
        else {
            cout << "NO" << endl;
        }
    }
}

Equal Coins CodeChef Solution in Python

T = int(input())
while T > 0:
    x, y = map(int, input().split())
    if (x == 0 and y % 2 == 0):
        print("YES")
    elif (x == 0 and y % 2 != 0):
        print("NO")
    elif ((x + (2 * y)) % 2 == 0):
        print("YES")
    else:
        print("NO")
    T = T - 1
Ezoicreport this ad

Disclaimer: The above Problem (Equal coin CodeChef) is generated by CodeChef but the solution is provided by BrokenProgrammers. This tutorial is only for Educational and Learning purpose.

Note:- I compile all programs, if there is any case program is not working and showing an error please let me know in the comment section. If you are using adblocker, please disable adblocker because some functions of the site may not work correctly.

Next: Carvans Codechef Solution

Sharing Is Caring

Leave a Comment

Ezoicreport this ad