 What's up guys? Mike the code here today. We're gonna go over another problem called the cards on spodge. Basically you have some You you're given the level n and you want to build a pyramid of cards with it And your your job is just output how many how many cards it would take to build a pyramid of Level n. Okay, so for example here we have The input examples three, so we have two input statements to and then there's three There's a two input statements. So the first one's three and then the second one's seven, right? So how many cards would take to build a pyramid of level three? So in this case, this is a pyramid of level three and the reason why is because we have if you look on the top Cursor, there's a look at my cursor. There's one level here There's two level here, and there's three level here the bottom level The top level the middle level and the bottom level So now if we count all the cards would take one two three four five six seven eight nine ten eleven twelve thirteen forty fifteen It would take fifteen cards to make And it's the same thing over here. If you do seven it would get seventy seven So basically this problem just tests your mathematical ability to I don't know just come up with like Come up with a number of cards would take so like we could just draw out the cards. It's pretty it's not a bad So here let's try a first level so with first level with there's two cards, right? There's two cards right here. We have two cards. Oh, I'm using paint instead. That's crazy All right, we have two cards here. So that's two cards and the next level and so this is level one right level one One to the level one right so now we want to see level two. So this is level two level two. We're gonna have one two three Four five six seven. I believe it would be seven. Yeah one two. Yeah, so it'd be seven for level two Okay, assuming I'm counting this correctly and now for level three Let's just see what level three was. So I think we said it was 15 But I want to make sure that I'm counting this correctly. So we have this one two three four five six Okay, yeah, so sorry about my drawing skills, but these are supposed to be cards supposed to be cards Okay, so we have one two three four five six seven eight nine ten eleven twelve thirteen fourteen. I'm missing one Oh, yeah, this one right here 15 yeah, okay, so we have one two three four five six seven eight nine ten eleven twelve thirteen forty fifteen wait I'm missing one. Yeah, so we know we know for three levels to fifteen though. Let's look at four So that's I'm gonna go back to just look at the drawing one two three four five six seven eight nine ten eleven twelve thirteen fifteen, okay Yeah, okay. Yeah, so now let's look at let's look at four. So before let's let's see what it looks like So remember we have a second stuff from the bottom. So one two three four five, okay So there's one two three four five six things like this for this now we have a Gotta make sure I'm drawing this correctly now. This is really this is really difficult Takes a lot of time It's a lot of effort a lot of energy To make sure these are the right number of cards Okay, so I think that's right. I think hopefully it's right. All right, so let's see how many cards we take to take one two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen sixteen seventeen Eighteen nineteen twenty twenty one twenty two twenty three and four twenty five twenty six, so I think four would take twenty six Okay, so given this we need to find the bad. It's not that difficult So let's ignore the first case because like this is pretty difficult for the first case, but um, so let's look at this so Look at the other levels Free for let's for each of the Triangles it takes three three cards, right? So like look at this top triangle takes three cards one two three right and then this this top triangle takes three cards Also one two three right so all the other cards All the truck all the triangles take three cards, right? So every triangle is three three cards, so it takes three cards for each like triangle now for the ones on the bottom The ones on the bottom except for the ones on the bottom, right? So the ones on the bottom there's no they don't have the three cards because uh, yeah for the last row You see there's no there's no card on the bottom or just one two three four, right? There's no cards on the bottom right for the last row so pretty much except for all like the levels There's always three cards then the bottom one. There's no there's no cards, right? So then that's why for every triangle There's three cards and the bottom one is not right, so that's that let's just count how many cards it would take for like Ignoring the last row, okay, so in this case how many triangles are there people? There's for the first second level right for this this case here There's one triangle right so this would take three cards, so assuming we're not we're gonna ignore a lot of the last row So this would take three cards, right and then let's look at this one, okay for this one How many triangles are there well? There are there are one two three there's three triangles, right so then this Because for each of those three and three triangles and then there's for each card is there's takes three cards and make a Triangle so it's gonna be three times three so it'd be nine and you could count it one two three four five six seven eight nine So the top one would take nine. Okay. Now. Let's look at this one. Okay, so let's count how many triangles there are so in this case We have It's a little difficult. Okay, so we have one here two three four Five six, right there's six triangles, right? We're just counting the triangles For the cards, right? So six triangles and then there's three cards per each triangle So three times six is about 18. Okay, so I hope you guys starting to see a pattern, right? so Yeah, so for for each of the rows there's a Wait, could see a pattern here. Basically. We're just adding up for each level the number every single time, right? And then basically for each level we're adding it up and then we're gonna multiply by three So in this case we have three right the first level there's only one level without the bottom not including the bottom level There's only one level, right? So then our answer is gonna be three times one so that's three, right now for this one How many how many levels are there and excluding the last level? There's two levels, right? One two. So now what we're gonna do is we're actually gonna do one plus two Through for three, right, and then we're gonna just multiply it by three and That'll give us nine Right three times three is nine. Now if we look at this one 18 We have a one two three levels right one two three and then now We're just gonna add them up one plus two plus three and then multiple by three So there are one plus two plus three then multiply it by three and that should give us Five plus six six times to 18. Yeah, 18. They'll give us 18. So yeah, that's basically the gist of it And that's just all the cards here. So now for the for the rest of it We just have now have to count the last row. So so for including that just the top rows What we do is just we just sum from one to end. So like whichever level we have so we have four You sum from one to end and then we just multiply it by three So that's basically the not including the last row. So now let's actually talk about how to include the last row include the last row It's basically the same thing as what we just said before but now what we're gonna do is that um, we're just gonna Pretend that we have all the values for the last row, but we're gonna subtract by the number of Level cards on the last row like the last level. So I'll just explain what I mean by that so in this case we have two levels, right two and Remember before we just included the first level one and we just multiply by three, right? But now what we're gonna do is we're gonna assume that every cards you including the last row has like a third a Third bottom card. So we're gonna pretend that there's like a card here and a card here That's what we're gonna do. So in this case, we're just gonna pretend it has it and then after that We're just gonna subtract it. So in this case we have one so we have actually we have Triangle two and then three so we're gonna do one plus two and times by three So that's gonna give us three times use nine So now once we have nine we're gonna subtract the card at the last cards from the last row So we have this this card that we're not gonna include and this card We're not gonna include so we're gonna do nine minus two and that gives you seven So now let's look at the second one. This is basically the same thing So I have one triangle two three and then here we're gonna include this one also So four five and six. So now these are all dots by the way dots dots. So what we're gonna do is we're gonna take like Yeah, so we're gonna do How many levels are there was one two three. So we're gonna do one plus two plus three Multiplied by three. So this should give us Was it one two three four? two three Three times three three plus three six times three is 18 and now we're gonna subtract by the last Cards on the cards on the last row. So that's this one two and three So the last cards on last row, there's three of these three of these dot dotted cards So we're gonna do with 18 minus three. So give us 15 All right. So then now we're gonna do the same thing for fourth. So let's do one two three four five six seven eight nine ten there's ten triangles. So we're gonna do One two three four, so we're gonna what we're gonna do is a four plus three. So is that one fun? I don't even know if I added that right Okay, so what we're gonna do is a we're gonna sum up one to four. So we're gonna do one plus two plus three plus four Multiply by three Okay, so that's gives you so three plus three six for the 30 gives 30. Yeah, and then we're gonna subtract by the bottom Number values of the last row. So that's 30 minus four 26. Yeah, so yeah So now if we just write a math equation for this, it's not that difficult. I mean, let me just clear the whole thing up Select all and still eat it. So if you want to write a math equation It's pretty easy. So what we're gonna do is we're gonna sum for Starting from one up to n which is n is the row Right the levels number of levels So we're gonna sum it up and then after that, we're just gonna subtract. We're gonna multiply by three So we're gonna sum up and then multiply by three and then we're gonna subtract All the last values in the last row all the cards in the last row. So the minus n So yeah, that's all you have to do. You just sum it up and then multiply three and then minus n So yeah, I'm gonna now code it for you guys. I didn't actually didn't actually Be this year. So I'm gonna do this real quick Let me see how many test cases. Oh, there's tea. Okay, so this is good. So Yeah, so to sum up the values you could use the formula for to sum up the values from one to n It's just I times I plus one over two. So yeah, do that multiply three minus n Oh, my battery's running low. But yeah Okay, I'm gonna do this real quick Submit it and then that's it. We'll be on our way Okay, so let's just Call solved see an end called solve All right. So what we're gonna do is here Okay, so here I read in the test cases read in cue read in test cases So keep subtracting each test case right in the number n and now we're gonna call it we're gonna do is a I Use long long because that's a value. Okay, so this is gonna equal to let's sum up all the values So this is gonna be some of the sum so it's gonna be n times n plus one over two Right and this is because that's a formula to solve this summation from one to n right for each I So that's a formula to solve that and then after that we're gonna take this sum see out Three times some and then we're gonna subtract it by Let's see n. So yeah, that should give us the answer correctly. So yeah, okay I'm gonna submit it and then I'll be on my way Yeah, okay, I got a seed. Yeah, okay. So the problem was it was just because of the million And apparently you can't you can't do that before you print it out Yeah, hope you guys enjoy this video or a calm subscribe. I'll check you guys later. And yeah, I'll just show you guys the code again Yeah, so the problem was was that? Look at the solve code You're supposed to mod it afterwards and the mod is supposed to be 1,000,0007 and it's supposed to be long and so yeah Just make sure you mod the value afterwards. Yeah, right come subscribe. I'll check you guys later. Peace