Ada School Codechef Solution|Problem Code: ADASCOOL

Hello coders, today we are going to solve Ada School Codechef Solution|Problem Code: ADASCOOL

Ada School Codechef Solution
Ada School Codechef Solution

Problem

Ada’s classroom contains N⋅MN⋅M tables distributed in a grid with NN rows and MM columns. Each table is occupied by exactly one student.

Before starting the class, the teacher decided to shuffle the students a bit. After the shuffling, each table should be occupied by exactly one student again. In addition, each student should occupy a table that is adjacent to that student’s original table, i.e. immediately to the left, right, top or bottom of that table.

Is it possible for the students to shuffle while satisfying all conditions of the teacher?

Input

  • The first line of the input contains a single integer TT denoting the number of test cases. The description of TT test cases follows.
  • The first and only line of each test case contains two space-separated integers NN and MM.

Output

For each test case, print a single line containing the string "YES" if it is possible to satisfy the conditions of the teacher or "NO" otherwise (without quotes).

Constraints

  • 1≤T≤5,0001≤T≤5,000
  • 2≤N,M≤502≤N,M≤50

Sample Input 1 

2
3 3
4 4

Sample Output 1 

NO
YES

Explanation

Example case 2: The arrows in the following image depict how the students moved.

Ada School Codechef Solution|Problem Code: ADASCOOL

Ada School CodeChef Solution in JAVA

import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int T = sc.nextInt();
		for (int tc = 0; tc < T; tc++) {
			int N = sc.nextInt();
			int M = sc.nextInt();
			System.out.println(solve(N, M) ? "YES" : "NO");
		}
		sc.close();
	}
	static boolean solve(int N, int M) {
		return N % 2 == 0 || M % 2 == 0;
	}
}

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

Sharing Is Caring

Leave a Comment