 How you guys doing Mike the coder here today? We're gonna go over coin piles Um, I'm having issues with like using the computer because of the the mouse pad is really hard to control on paint So I'm gonna use pen and paper like old school. Okay, so on so in CSES coin piles What is um, what is coin piles? So essentially is is that we're given a pile of coins of a and a pile of coins of B Okay, so in one operation we could either minus one from a or Minus two from B and minus two from B. So this is the first operation. It we could do so. This is the first In one operation, we can minus one from a and minus two from B or This is the second operation the second operation. We could minus two from a Or minus N minus one from B. Right? So this is the first operation we could do Okay, and then this is the second one. Okay. This is the second operation. We could do okay So our job is is that is it possible that we could empty both of these piles of A and B? Okay? Either using the first operation or the second operation. Okay, so let's just go over a few test cases Okay, I'm gonna go over a few test cases So in the most basic test case you could have is that you have let's say we have We have a is gonna have two piles of points and B is gonna have four piles of points. So we have one two three four because it's two times The this is the two times eight. Okay? So for the sake of this one, I'm gonna assume. I'm just gonna always use the first operation Okay, I'm gonna use always use the first operation. Okay, so in this case I'm just gonna always use this operation of minus one from a and minus two from B. So If I just always minus one from a so I'm gonna remove one coin from a and then I'm gonna remove minus two from B I'm gonna remind us to from B That's gonna be one operation. Okay And if I'm minus one from a I'm gonna move this coin and then minus two from B. I'll be another operation in the end We see that we are able to empty both of these coins using the first operation Right of subtracting one from a and subtracting two from B Because in the end both of these coins Become zero right both these coins from zero, right? So this is what happened when a was equal to two and B was equal to four Okay, so in the end when a was equal to two like a had two coins You see a had one two two coins and B had one two three four coins, right when this happened We were able to get to zero. Okay, but now let's say That's showing us a situation where we it cannot happen So back we're still gonna use the first operation Okay, we're still gonna use the first operation because of the second operation is basically just flipping the first operation All right, so let's say I instead this time I have a is gonna equal to two and B is gonna equal to like six or Yeah, let's do six So a is equal to two coins and B is equal to six. Okay, so in one operation. I remove One from a one point from a and then two coins from B Another operation. I remove one point from a and then two coins from B So in the end you see we still have we have a leftover of values of B right we have two left over from B So as you can see here If if one of the piles is two greater than two times the second pile Then this is not possible because in the end what happens is that what? You're gonna have some amount of coins left over from this operation So if this as in as you could see here a is a smaller pile, right and B is a larger pile All right, so if If B is greater than two times a And this is not possible Assuming a is the smallest pile. So a is a smaller pile And B is a larger one Right If a is a smaller pile and B is a larger one And B is greater than two times a this is not possible Because in the end if we keep subtracting one from a and two from B And one from a and two from B We're going to get something left over And uh, if you don't believe me you could try other situations of a is equal to like Two and B is equal to five. So I could show you that also So a is equal to two and B is equal to five one two three four five right So if I subtract one from a and then subtract two from B And then subtract one from a and subtract two from B I'm going to have a leftover Again, so this is also not possible and it's because B is greater than two times a right B is greater than two times a so this is not possible So if B is greater than two times a it is not possible Okay, and this is what assuming that a is a smaller pile and B is a larger one Okay, so now let's go back to the first part of This equation. Okay. So now what are the other situations when It is not possible. Okay So, um, the first operation is that we're subtracting one from a And subtracting two from um B So if we repeat this certain number of times over and over again Let's let's say x is the number of times we're subtracting Um, we're doing the first operation. So so let's do let x is equal to The number of times Doing the first operation. So Yeah, sorry, my left hand is holding the camera. It's pretty hard here. So let x Uh is equal to number of times Of first operation. Okay And let y is equal to the number of times the second operation second operation so in the Using the number of times So we're going to do a certain number of operations of the first time Right for x is going to be the number of times the first operation And y it's going to be the number of times second operation Okay, so um since we are subtracting a x number of times of the first operation one from a and then B we're going to subtract two from b certain x number of times over and over again What that means is that in the end it's going to get to zero, right? So if we're going to use this, um, we could write an equation for this So if I do a minus Since we're doing one Time in each operation and x is number of times for the first operation It's going to be a minus one times x right Because we're subtracting a certain this number of times and then This is going to equal to zero. Okay Right Because if I subtract a x number of times using this a minus one this certain number of times we're going to get to zero, right A is pile is going to be zero And what about b well b is going to be b minus two times x Is going to equal to zero, okay And that's the number of times using um b's operation Because if we subtract b minus two x, uh minus To the certain number of times using the first operation since x is uh the number of times the first operation we're going to In the end we're going to get zero, okay? So if we were to add these equations up We're going to get a Well, let's actually just solve this so a is going to equal to x and then b is going to equal to 2x Okay, and then if we were to add these equations up A plus b is going to equal to 3x Right because x plus 2x is going to give us 3x. Okay So this is the first equation for the first operation. Okay first operation the first operation Now what about the second operation? It's the exact same thing if I do um A is the number of coins on the in the first part We're going to minus two Y number of times right and it's going to get get us to zero because um This is the number of times we're minusing two over and over and over again for the second operation, right? and then b minus One times y one times y because we're minusing one from b The certain number of times over and over again y times which is the Number of times we're doing the second operation. Sorry. This is the number of times second operation is going to get us to zero So then if we do a we do the exact same thing we're going to get um A plus b is going to equal to three times y So now we have a plus b is equal to three times y and a plus b is the three times x So if we were to combine both of these equations we're going to have A plus b is going to equal to three times y and a plus three times x What we see is that we could um we could factor Uh, we could plug this in. Okay, so we could literally plug this in. So if we were to um Um, yeah, yeah, so if we were to add Uh, wait, no not add. Yeah. Yeah, if we were to add these equations up technically um, we would get uh Here so let's add these equations up We get two a plus two uh two times a plus b is going to equal to six times x plus y Right two times a plus b is going to equal to six times x plus y and if we were divided by two on both sides we're going to get a plus b Right we've divided two on both sides of of uh This by this and divided by two this is going to be a plus b is going to equal to three times x plus y Okay, a plus b is going to equal to three times x plus y Okay So if a plus b is going to equal to three times x plus y What does that mean? It means that if you divide three on both sides So a plus b divided by three is going to equal to x plus y It means that if we're going to Do a certain number of operations on the x for the x and the y using um Both of these first operation and the second operation A plus b has to be divisible by three Right as you can see here after we divided by uh x plus y on both sides Otherwise this these two operations will not work right So the two equations we have is that um if If b is greater than two times a Or a plus b is not divisible by three then it's not possible Otherwise it is possible. Okay, so if the um, so in this case a is a smaller pile and b is a larger one. Okay So I'll I'll just rewrite it again in the Back of this so I'll just rewrite this here. So if if b is greater than two times a Where a is the smaller pile right a is a smaller pile or A plus b is not divisible by three Right is not equal to not equal to zero Not divisible by three then it's not possible. No Otherwise it is possible. Okay, so um in order to maintain that um a is a smaller pile We could swap it if a is larger than b Right because uh remember our condition was when a was this uh I believe a was a smaller pile. Let's go back to here Yeah, a is a smaller pile and b is a larger one, right? If the larger pile is greater than two times a smaller pile Then it's um not possible So if we want to do that we could actually just swap a and b If we're not sure of uh, which one's the larger and which one is the smaller one So we could always maintain if a is uh Uh If a is larger than b we could swap it to make sure a is always a smaller pile to check this condition Right because that doesn't affect this other equation Yeah, all right. That's the essentially the gist of this, uh problem I'm going to show you guys a code now and that's it. All right guys. So this is basically the code for the um coin coin files We read in the number of test cases. We decorate while we decorate the number of test cases We're going to read in a and b reading in a and b Um, if a is greater than b, we're going to swap a and b and the reason why we do that is because we want to Make make sure that a is going to have the small pile Small pile of coins and b has the large pile of coins. Okay so if the smaller pile of coins multiply by two is uh Still smaller than b. So b is greater than two times a or The um the sum of a and b is not divisible by three. We print out no Okay, and otherwise we print out yes And that's basically the gist of how to do this problem I hope you guys enjoyed this video rate comp subscribe. I'll check you guys later. Peace