Hello coders, Today we will see how to solve the ” **Coin Piles CSES Solution** “. The problems from CSES are a little bit trickier in comparison to HackerRank. So I suggest you, don’t hurry your self looking for a solution. Try to give extra time and write the approaches you can apply. And If you still didn’t find the solution CodeSagar has your back.

Let’s first understand the problem statement.

## Problem statement:

You have two coin piles containing aa and bb coins. On each move, you can either remove one coin from the left pile and two coins from the right pile or two coins from the left pile and one coin from the right pile.

Your task is to efficiently find out if you can empty both the piles.

**Input**

The first input line has an integer tt: the number of tests.

After this, there are tt lines, each of which has two integers aa and bb: the numbers of coins in the piles.

**Output**

For each test, print “YES” if you can empty the piles and “NO” otherwise.

**Constraints**

- 1≤t≤1051≤t≤105
- 0≤a,b≤1090≤a,b≤109

**Example**

Input:`3`

2 1

2 2

3 3

Output:`YES`

NO

YES

## Coin Piles CSES Solution in java

//Coin Piles CSES Solution in java import java.util.*; import java.lang.Math.*; import java.io.*; public class CoinP { public static void main(String args[]) throws IOException{ BufferedReader sc=new BufferedReader(new InputStreamReader(System.in)); int t=Integer.parseInt(sc.readLine()); while(t>0){ String input[]=(sc.readLine()).split(" "); int a=Integer.parseInt(input[0]); int b=Integer.parseInt(input[1]); System.out.println(((a + b) % 3 == 0 && (Math.min(a, b) * 2 >= Math.max(a, b)) ? "YES" : "NO")); t--; } } } //Coin Piles CSES Solution in java

**Disclaimer:** This problem(**Coin Piles CSES Solution**) is originally created by CSES. Codesagar only provides a solution for it. This solution is only for Educational and learning purposes.