Hmm. Oh, we're live. What's up guys? Mine is Michael and welcome to my YouTube channel today I have not actually done any competitive programming at all So today, you know, we're gonna do a virtual contest of 675 Sorry guys, if I haven't been uploading at all, it's been pretty hectic for the past two weeks and I couldn't upload any any Videos at all. But so yeah, I'm gonna do live stream today just cuz cuz I also haven't I have not been practicing competitive programming at all So yeah, this is this is a good way to get back into the zone. You know what I mean? So, yeah Pretty good. Yeah, I've been dealing with a lot of school work and stuff like that. Yeah So let's let's just do this code forces round 675. I Have not seen any of these problems yet. I haven't even done any of these problems yet. So yeah Well, we're gonna do it Let me know if there's any thoughts on new Boston reappearance new Boston is reappearing. I did not know that Really He's coming back. Oh my gosh This is crazy. This is actually crazy The new Boston is coming back. It's crazy. I thought he got I thought you just got a job or something and you just left But yeah, him coming back is pretty cool. I used to watch him when I was a kid For like learning basic basic programming, but not not Not not like I did I didn't watch him when I was like a kid. I just like I used to watch some of his videos on like Photoshop or something. You said videos on that. I think I don't know Of course, I never actually did any of this stuff here with him But yeah, wow, hmm, I didn't expect him to come back But yeah, it's good. It's good if he's coming back All right, let's get started. Let's do this Let's do this. I have not been practicing at all so this is gonna be a Very hectic for me I've not been practicing at all But this is it is something like that, you know I Gotta get rid of this. I gotta get release gotta get rid of this I'll get rid of this okay, so we got rid of those and Yeah Okay, so let's do this One minute oh two seconds Feel like technically I feel like I feel like I could get to green Actually, if I just like practice look at a little more faster. I'm pretty sure I could get to green Cuz green is not actually that far away from my skill level. I think like I'm green on um You should be green on top coder So I did that I think that I did one of the contest there and I got I was green and then I got to high gray again But I'm pretty sure my level was like I Think I could get back to green on code forces like I don't know What are your guys's ratings? But yeah Don't know Feel like ad coder is probably the hardest in terms of Difficulty that's just me though. Maybe I'm just not as good as math Acoders way more difficult in my opinion All right, let's get started Fence I want to build a fence you already you got three straight fence segments of ABC You want to find some possible length D of the fourth fence segment So that you could build a fence using these four segments in other words The fence should have a quadrilateral shape with side lengths equal to ABC Dandy Find any possible side of the fourth side what One two three four It just has to be a quadrilateral Fence would have a quadrilateral shape with side lengths equal to ABC and D fence I Should have a quadrilateral shape with side lengths equal to a B and C and D Um Can you take the average? I don't know. Let's see. Let's see. What is 12 plus 34 plus 56 over 3? 34 Well, that's 42 Let's see How do you get 42? 56 minus 12 would get you 44 no Hmm, what do they mean by fourth straight fence segment Quadrilateral shape with sidelines equal to ABC and D So and like like a trapezoid Can you take any number hold up pretty sure side lengths are always Properties of rhombus. Let's see if I sec each other perpendicular opposites are equal Opposites are parallel. No, that's not what I want hmm Okay, you know what I'm gonna read in the test cases first and Then we could think about that soon. Okay, so while T minus minus Let's read in ABC Okay, so now we have ABC So they said all sidelines are equal. Is that what they say? Is a quadrilateral that no three of its corners lie on the same line should have a quadrilateral shape with sidelines equal to ABC and D Okay, so let's say we have 34 One two and three and four works Seven plus two is five five over four. No five plus one is six five five divided by Plus three six No, that's not right 12 plus 34 is 46 plus 42 is 484 If there are multiple answers print anyone that exists hmm Okay, so I think you could just print any of them such that The number is greater than So they can't lie on the same line, right? and That only happens if two of them are Three of them are the same Same sidelines, right? No, no, that's not right If the fourth one is equal to the sum of the first three then you can't do it, right? Like three plus three six fourth one six, then it's not possible. We know that's a triangle hold up if the fourth one Yeah, yeah, yeah, wait If it's equal to six Three plus three. I need to draw it.  Yeah Is there a way to do it is there a program is there a program I could do Let's say the first one is two the second one is Three they said three, right? I can't do that. Let's say any So one is three Third-side length is four So like that To so it's one to so two three It's two three one two and three one Two, let's do three here. That's about four Okay, let's let's just test let's just test it. Okay, so like um, I Don't know a plus people see I'm not sure if this works So we have five one of one I don't think that's right. Um Let's see six divided by three is two two plus 34 How do you get okay? How do you get 42 12 plus 34? See 12 plus 34 is 46. Let's say divided by two is 23 23 plus No 36 56 minus 36 is 20. No, that's not right How do you get 42 that's that's a big question for 56 minus 34 is 22 That's 32 22 plus 12 is 22 plus 12 is 34. That's all right 42 plus Okay, let's let's see. What is the average of 12 plus 34 plus? 56 144 divided by 3 144 divided by 4 is 36 6 to 4 10 4 is 2.7. All right, actually, let's just see if this works. I don't even know I'm not even sure if this works actually But did I get accepted? Wait, what that was it? Okay. Yeah, I didn't expect that but Some of them all did minus one.  Now we have matrix that n by m is nice If all rows and columns of the matrix are palindromes, okay, that's okay rows and columns are palindromes. Okay, okay Sequence of a 1 to a k is a palindrome If it equals the ak minus. Okay. Yeah, I know that now Sasha owns n by m one operation You can increase or decrease by one you want to make the matrix a Nice, so then you want to make it a palindrome. Okay, what is a mental number of operations she needs? Okay, so you could go over row by column, okay, so So first you okay, so we have four rows two columns One two three four So this is our original four rows and two columns one two three four. Okay, so You can make this into a palindrome by changing it into two four four Two four four two four four two So if you make the Row and columns of palindrome, okay, so we can make 42 operations Hmm Let's see. What could you do you could subtract the beginning from the end and then I'll get you your Okay, so we're gonna loop through each of them, right? Here we're gonna take the first number and subtract it with the end Right, and then we're also gonna take the last number from the column section and subtract it with the first value of the beginning one and We're gonna add them up and then we're just gonna keep doing that And then each time we're gonna update that when we go down a row So Okay, so if I do like How about I get my thing to draw it out Okay, so if we do like Let's see Let's say we do four two. What was it four two Four two four two two four and then four two Okay, so what if we go row by row so from this row we're gonna compare to this to the mat last Subtract it until we get to the middle, right? Once we get to the middle we're done and then While we're getting to the middle this way, we're also going to subtract each row Downwards so we're gonna subtract this by this wait for two Four four four two four two. Oh, whoops my bad. I drew it wrong so four two Four two two four Four two two four, so we're gonna loop through this way So I'm gonna loop through this way and then we're gonna subtract this from the end While we're looping through this way So each time we're gonna go Through each of the individual columns from here to end we're also going to subtract that each individual with its end so they'll get rid of that and Yeah We're just gonna keep doing that until we get to the end So like if we had like I don't know one two three four five six seven eight nine I'm gonna start from this row Subtract here to hit this end, right? So then three minus two would be two so then I'm gonna change this into like a three, right? then I'm gonna compare this with its last column here last row here. So that's three four seven ooh, okay So it takes four moves to get it to three just give them seven Like takes more moves if I want to change both of these right I have to take four another four moves So it's actually better if I make seven back to three so love Make this three So there's at this point we have Two moves to get one to three and then we have four moves to get seven down to three Right and then after that I'm gonna get to the here So remember I'm looping through from each individual road to the right So now I'm here and then I need to check this. This is a done with the end So I'm gonna take this one and with its last one and change two to six So then eight is gonna become to two and then I think I am done With that so it becomes six the problem is that Wouldn't it be better if we I'm trying to think What if we make and we make all rows to become the same number? Yeah, hold up like this. Okay, so we have one so let's say we have this one two three four, okay, so we have One two three second test case for example Three four one two three four one two three four one two three one two three four. Okay, so here They made all of them to become five five and six Why did they do that? Maybe it's the average actually seven plus two ten divided by two Five four is two point five. No, that's all right Um Median let's see. What is a median? No median six and seven What is the average of two plus three one plus two plus three four five six five? Okay, what is the average of this one plus two plus three plus four? One plus two plus three plus four five six seven It was eight plus Was it nine ten eleven eighteen? Eighty four and now we're gonna divide it by how many rows? One two three four five six seven eight nine ten twelve twelve Eighteen divided by twelve. Oh, we know but it wasn't on eighty eighty four divided by twelve. That's seven Average is seven Why would it be better to do it to five and six? Okay, let's see. Hmm. Make it the total Total sum two four. No, that's not right um Maybe it is the average. I'm trying to think Thirteen divided by two is six. It's a middle numbers average. What is it about this row? Twelve divided by four is three now Seven plus two is ten. No, three plus three is six plus four is ten. No, that's not right Six plus nine is fourteen divided by three.  Actually, it would be surprising if it was just pretty one Don't fall for the average test cases set up like that Don't fall for average test cases like that, huh? Don't fall for average So don't use average Should I just like make it into a palindrome then? Like I was thinking of just like subtracting going through and just making into a palindrome But like I don't even know if that's right on it. Okay Let's try it. Okay. It's because originally I just go and go through every single row and just make it into a palindrome You know, I mean Because you technically could just do that go through every row make into a palindrome then go through every column Like you can make this like back to one two three four five six. I make this into a palindrome make this into a palindrome Yeah, so I get like six And then here it wait hold up. Yeah. Yeah, then the rest of the rows you could just make it into wait, hold up Yeah, you have to go through so Okay, so if you have like hold up This is difficult. Okay, one two three four five six seven eight nine. Okay, let's go back one two three Seven eight nine ten eleven twelve. Okay, let's say it was like this right Make this into a palindrome By comparing this and this so I compare this and make it this into a three Okay, and I need to make this into a palindrome so I compare this with this last row So make this into a three also so currently I have like seven plus two The number of operations I did Yeah, then I'm gonna go to here. I'll make this into a palindrome pairing here and That's last row. So make this into a two so I need to make this one nine Make this into a palindrome compare three make this into Three so then now we have Nine again, okay But then I need to after I'm done with this row I Have to go to the second row. So I can't just go through row and column like that. So Yeah, yeah, okay. So I Went through here. So the first row then now I'm in the second row Let's make this into a palindrome compared this to this so make this into a Four or two actually doesn't matter it doesn't make it six. So now we have plus two Then I need to compare this minus this So this and this instead. So now this is gonna become Six, yeah, six So it's actually better if you make the make it the larger number or is it better to make it smaller? Actually the larger larger number is better. Yeah Yeah, yeah 66 and then this one let's make this into a palindrome. So make this into like a five And then at this point once you're here you make this into a palindrome to make this back to a six Then you would have like One three two three five six five six six five six three two three Okay, so yeah, I'm gonna do this algorithm. Okay, so Yeah, let's do that actually I Don't know if it's the smallest number of operations required But might as well try so for so let's read in and an M Okay, so we've read in these two Read in these two and let's look at em. Yeah, okay, so we need to create like Yeah, okay, so data. Let's do like Yeah, data and Rose and then for every Okay, so now we're just gonna do data at i is gonna equal to new a vector M and Then now we're gonna read in data at ij Okay, so now we have our data now. Let's try to just try to find the minimum number of operations Okay, so Okay, I'm gonna do our actually is for row and column. So we start at the number of rows I Want to go until I get to the middle actually so I don't want to go all the I don't want to go all the way So I'm gonna do like an over two Um For every row for every column. I want to go halfway also. So this is gonna be M over two and I want to make sure for every column. I'm going to subtract C minus Data at RC minus length minus one I think and minus Hold on. So this is zero. This is zero one two one two zero one two, right? So I'm gonna take the last row and subtract by the index minus one Yeah, okay, so it will be last row minus index minus one number of rows so we have three minus Minus the current index zero minus one. So that'd be two. Okay, so last row So That's gonna be M minus C minus one right, so I'm gonna take data at Row and this column so I'm gonna take this column and I'm gonna subtract this from At the current column. Yeah, okay, so that would get me the This is gonna be the number of operations Yeah, and then I'm gonna make Whichever one to be the larger one So if it's the larger one, I'll make the smaller one to become the larger one So I need to check which one's larger. So Yeah, four relates to three two one Okay, yeah, so if data at RC is greater than data at the end minus one Then I set data at our MC minus one is gonna equal to data at RC Otherwise I set data at RC is gonna equal to Data at our M minus C minus one. Yeah, okay, so I'm gonna do that for all the columns But then for every row I have to do that the same thing, right? Because while I'm going through the columns, I need to do the rows also Right so I have to do like M N minus R minus RC I think So while this is doing the whole thing thing Majigui So I'll compare the first first and the last and then it originally it's original column in row with its last row Okay, so Yeah, okay, so after After this I also need to compare So remember back over here if I do want to do like one two three I'm gonna compare this with this right and make this into a three I also want to compare this with the it's corresponding N to make this with three So that way when I go through to the middle, it'll be able to do it And then after it does that it will go to the next column and I'll make it Do N minus? Yeah, okay, so yeah, I think that will work that'll work That would work. I think it would work actually Yeah, okay, so While it's doing that I also have to compare so I'm gonna do like another operation. So here I'm gonna do Now whether it's gonna be a minimum operation, I don't know actually so this is gonna be second operation It's gonna be RC data at the row and column the last row so it's gonna be data at N minus R minus one same column right minus this Right. Yeah, okay, then what we're gonna do is we are gonna do the same thing as here. Okay Except it's not this anymore. It's gonna be if RC is greater than N minus R minus one. Yeah Then we do C RC is greater than N minus one minus one then we're gonna set our this is gonna equal to whatever is greater Yeah, so whichever is greater than we're gonna set that to equal. So otherwise this one is gonna equal to The last row minus one so equal to this. Yeah, so we're just this is just setting whichever is greater Right. So if this is greater, it's gonna set the other one into it Otherwise we set itself into it. Yeah, okay So it's gonna do that and then now what we're gonna do is where we're gonna add the number operations together So let's do like a total Op equals zero and then we're gonna add So we're gonna do sec ops plus Ops, okay Total op Total I just misspelled it total op, okay total Total Total yeah, okay. So now now once we have that At the end it should be fine Ideally unless I miss a boundary, but then yeah, and then let's just see out total op I'm not a hundred percent sure this works, but I don't know Okay, so I got six and sixteen. So that's not right Think a little bit off Let's see Let's actually print out the array at the end to make sure that we're not actually going crazy So at the end, let's print out the whole array Okay, so once we print out the whole array, let's let's see All right, what's the problem here? 910 34 wait, why is this? What am I doing wrong so I set the first one to be nine Something's not right. Okay, hold up. I need to print another new line Let's see Okay 910 34 So I did this to make it nine that I made this 10 Ah, so 34 doesn't get changed and it doesn't it doesn't get changed with the rest of these either Okay, so the problem is that it did not finish changing the rest of them Hmm, let's debug this, okay 910 34 so let's do let's do one test case of this initially, okay Okay So one test case 34 and then let's do this. Let's do Yeah, this Okay, let's see what's going on. Okay, so we got initially Okay, so this is gonna operations subtracted Let's see what it did subtract. Okay. Uh, so r minus and m minus c minus one Yeah, that should be right so that I'll get you RC equals data of r minus and minus one so M row is number of rows. Oh Wait No, no, okay. Wait. What did this do? Let's see. What did it do? It made the first one to a four. Yeah, okay, so I made This and this to be a four. Okay, so then now it should make the nine Yeah, let's see. Ah, then it made the first one to a nine. Okay, that's not right Okay, so if if the first one is a four if both these are four You have to make the last one to a four also So you can't just take the the largest one Yeah, you have to take the you just have to make the Okay, um, yes, we can't we cannot do the larger one here. We would have to just make and n minus r minus one Uh, yeah, we just have to add that So we would just have to do this Because if you make it the largest one you would have to you have more problems Yeah, you just have to do this. Um, you would have just have to subtract with its original one. Yeah, okay So that's for the row part part why it's not right. Um, hold up. So let's try it again three four And then let's look at the test cases again Okay, so let's see. What did it change? So four two three four and last row should be four. Yeah, okay, so that's right Okay, so then it should continue So what did it print out? Well, what's the final array? four three three five What is it Five six seven eight. Okay, that's not right. That means we have to continue doing it four three eleven eighteen It's still not right. Okay. So that means that we have to actually continue doing it until we get to the middle Which means um We have to make this into an equal sign So let's try it again So let's do one three four and let's do this Four three three four four three three eighteen. Why is the last one not working? um What if we don't make it equal?  I messed that up Okay, so we got it. I think that's right Okay. Yeah, I think that's right. Um You might be able to do a proof of this Greedy stays ahead 842 is that right? Yeah, 842. That's right. Okay. So yeah, we got this answer.  Wrong answer on two. What is the problem? 842 works Um And what situation would this not work? What if it's already a palindrome? Let's see what happens zero, okay now um Hmm. Um, no actually I'm kind of stumped Hmm What is the problem? Just keep going back here Whatever you're assuming We are assuming that when we go through the whole array and that we just set the larger value here That the larger value is always going to be the one That has the most operations What if you want to set the smaller value? In fact, what if you want to set The bottom most value Maybe you should make it to the median. I don't know. What do you guys think? Test cases set up like that. It's not an actual median. Don't fall for average. Should you use median then? what if I hold up, let's Let's go back to here What if I do this But I get the same number No, I would get out of bounds Uh No Hey What if the last row is equal to the previous one? What if that's a problem? I'm trying to think of many different test cases that that could happen. Um, let's see Four four four four four four Nine six, what if it's six? I'm trying to think One two three four What if we make them all ones Would that work? I don't even know one plus two Okay, so we have one One plus two plus three plus four plus five plus six plus seven plus eight plus nine plus ten plus 17 No, that's not right You get 72 seven one nine one Seven plus one plus one plus one plus one plus one plus one I don't think that's right either This gives you 17 So I write How do I know if it's minimal? That's a big question median Make it the five. Let's see four three two one Wait, hold up. What is the median six? It's a median six actually five plus four plus three plus two plus one Let's see five plus four plus three plus two plus one What else? um Plus one plus two plus three plus four plus five 18 minus six is 12 plus 12 Oh Just make them all to the median Oh, what the I think that'll work. I think that'll work How do you get the median though? You have to make it into an array and just get the middle number. Okay, um Let's try to get the median uh Mead Mead about pushback Okay, so now I've mead. Okay, so I'm gonna do a completely different thing I'm just gonna make everything into the median. All right So the mean so now we push everything into one giant array Now what we're gonna do is we're gonna get the middle number um That's Well, what is that? Mead at Mead dot size over two Right I think that's right. Oh, no, but oh no, no, no, no If it's odd Hold up if it's odd then we have to do plus two over Let's see. This was one two three four five six. This is 12, right? So one two three four five So we had to do six plus seven over two. So if it's even We have to take Okay, so if it's even If it's even we're gonna do Median is going to equal to Mead dot size over two Floor So that's going to be One two three four five six seven eight nine ten eleven twelve third one two Twelve oh, so third one two three four five six seven eight nine ten Three times four is twelve twelve. All right two is six. So be zero one two three four five six So it's going to be six Plus six minus one zero one two three four five over two, right? So Med dot size Then we're going to do a minus one Yeah, and then we divided by two This is going to get us a median. So here we're going to do Um, otherwise it'll just be me dot size Over two divided by two. I think so it'll be like It'll be zero one two three four five six seven eight nine ten 11 so originally if it was like Ended here It'll be zero one. So it'll be one So if this doesn't exist it will be one two three four It'll be we hold up one We hold up one two three Four Five so it'll be here. So zero one two three four five Six seven eight nine ten. So it'll just be ten over two. Okay Yeah, so it'll be five. Okay. So then Yeah, so Let's actually use a ternary operator So if me dot size Mod two is equal to zero Then we're going to equal to this Gigantic number Otherwise, we're going to make it equal to Me that size over two So this Yeah, okay because that just gives us a median Once we have the median, let's just go through all the values and subtract it from the median So Let's go through all values. I'm going to take this minus median Right and then we're going to do total ops and we're going to do like an abs Uh, yeah, then total op. I think this would work, but I'm not 100 sure But it seems right Let's see if this works 842. Okay. So that worked Let's see if this works when I submit it It's taking a while Did my internet die? Which code forces it down Should at least get through the first one. I don't know. I think maybe code forces it down Maybe my internet's down Is my internet down? Yeah, I was thinking about the median I was thinking about the median That was well the second part Now I haven't read the chat at all. So I don't know. I wouldn't know if it's that's right or not I think code forces down Why is it taking so long? Is this pushback? I mean, I didn't even Pretty sure this is how you calculate median though, right if it's mod by two is equal to zero So that means even so if it's even we take the smaller number here We add it with the the other middle number and we divide it by two Right is that how you do it Otherwise you just take the middle number But I don't know. I don't know what's taking so long It's taking awfully a long time I see something Is my algorithm too slow? Whoops I'm trying to think I mean, we could just get rid of the data at I don't know. We still need that Maybe my internet is just slow I don't know. Let me just close everything It's really weird that that the fact that It's taking it awfully a long time. Oh, no. I got Wrong answer. Oh no It's still Vertic is running Give me something Why is it taking so long? Maybe I should try resubmitting it I mean I don't know why it's taking so long Already submitted it once. Okay, um In that case, let's just make median equal to size over two Maybe it's just maybe it's just the weird I have no idea why it's taking so long Now both of them are running Not stopping I don't know. Maybe something's wrong with their like thing. Maybe we go to see. Okay. Let's go to see So that's easy to come to Oregon with a bargain You can't come with agreement Sasha makes the price as high as policy wants to move and as many digits from the price as possible If more details she names some integer price and removes an unempty substring from the place The remaining digits close the gap and the resulting integer is the price If you're one two one three one two one you can remove one three two one and the result is one two one You remove all digits and the price would be zero She wants to come up with the constraint so that you can't move all the digits But she wants some arguments appointing the constraints to do starves She wants to compute the sum of all the resulting after remove What? Or wrong answer on two Okay, so now now it works So both of these are wrong answer on two Okay, so median does not work So track them all to make the median For some reason that both of those did not work What if we try average Let's try average If median doesn't work and average isn't a median doesn't work. So let's try average Okay, we're gonna do um Maybe it was because of Floating point error actually Wait, hold up. See what was the problem? Could be this floating point Rounded up or round down 2.7 divided by 2 is 13 divided 2 is 6 uh round down So this this would work if it was median. Let's try average then Okay, we're gonna try average. Um Make all the numbers average Okay, so we're gonna do average plus equal data at ij um now we're gonna do average divided is equal to average divided by data uh n times m Yeah, okay, um then just subtract average So let's see if this works Okay, we still get the same number I still feel like median makes more sense but Still wrong answer on two mode Make it to the mode What if you make it to the mode? um What is the mode though? If it's all the same then you have to use the average or the mode is too. What would have hit the mode is four Okay, let's say let's make it to the mode. Okay So the one with the most number of occurrences Let's do that If that doesn't if if If the maximum mode is one then we use the average How about that? So let's actually get all the occurrences of each number To do that Yeah, let's use a map So let's do map occur And then now we're going to do add data at i j and we add up Um, yeah, so now we have the occurrences and now we need the maximum occurrences. So that's You need to loop through the max occurrences So let's loop through the map Okay, so if uh, why can't I do this occur? if x dot Second is greater than occur. I don't know number whatever Whatever this number is let's let's make max occur equal to negative infinity or something long long under So if it's greater than this then we said max occur is going to equal to the number which is the first pair um Yeah, so that'll be the mode and then Yeah, let's just continue Once you get the mode So once we get the mode if the mode is equal to crap, okay, so if the mode is If the mode is equal to each other At the mode of okay if all the values in the mode is equal to one Then we're going to use average. So we actually need to Okay, so we have to go through the map again If If all the values of the mode. So if second is not equal to one So let's say it's not equal to one Then we break We say use average Don't use average. Don't so don't don't average So don't average equals the true No, no, no, no, it's not one You don't want all the values to be the same max occurrences That's what you don't want. You don't want to make it an equal one. Ah Okay, so if the mode because okay, you don't want all the occurrences equal to to Okay, so the mode if we use the mode Okay, so like if we go back to here and we use the mode, right There is no mode here because they're all have they're all equal to one But let's say there's two of each of each then there's still no mode, right? Because they're all equal to each other. So we have to check if All the occurrences don't equal to the previous occurrences. So we're gonna have to have like a variable I believe it's a curl. Let's say it's negative one. Ah, not negative one Uh underscore infinity min. Okay negative infinity. Um This is so difficult It's got it harder and harder. Okay Check if okay, hold up check if All of if second Pair in map is the same In c++ second Uh, boy, that's really difficult. Um Check if second That's not what I want. It's got complicated and complicated very complicated too complicated actually Very complicated. Oh check if all values in map are the same Oh You have to do this That was stupid Okay, well, I don't have to loop through it again I should do this uh string So let's create a set news, uh, don't we don't need new we just create a new set This set is going to equal to Dot values so it's going to be occur dot get all values in a map Oh push every value check if there are there Okay, okay, we could do this We could do this push every value into a Wait, let's create a set of key values Then we're gonna insert It dot second And that's it. So values that insert What is my value ock? Oh Okay, and then now we do if values Dot size is equal to one That means there's no mode Right no mode. So that means we're going to use the average. So we'll do this Okay, otherwise we're going to actually use the mode. So then we're going to use the mode. So we'll use Now we're going to use the mode. So we're going to take Max occur So we're going to copy this and paste here And then we're going to add um Subtract by mode Uh, yeah, where is it? Okay, and yeah, that'll be pretty much it Okay, let's see if this works What's the problem? total ops redefinition, um Yeah, that's the same thing. Okay, let's try this Damn mode doesn't work Dang, so how how do you use this then? If mode is not working. Okay, so if mode doesn't work Average doesn't work Then what is it? doesn't work How many number of occurrences? Mode doesn't work average doesn't work How do you do this? We're trying mode. We're trying average. We're trying median We try we try to every single possible Central tendency. What was it called? Central tendencies How do you get this equality to hold? I tried it Now things working Okay, let's go back to our original definition this Making it into a palindrome What is the minimum number of ways to make it into a palindrome? That's basically what this problem boils down to Minimum ways to make it into a palindrome. Oh, I got it. I got it. I got it. I got it. Okay Okay Go back to our original thing Okay, we have two choices Let's get back Okay, I think I got it. I think I got it So let's say we have um one two three four five six seven eight nine. We have two choices This one I can make this the same as this and this Right Are you I either can make this the same as this or I can make Okay, if I want to make this We need the minimum number of operations that take to make this right So in the beginning this one I could either make this one into a three Or I can make this one into a seven right So if I make this one into a three I have to make this seven into a three So the operations this would take would be three minus one Plus seven minus three. So this is going to give you Two plus four which are equal to six right So that's one case The other case I could do So remember we have three minus one plus Seven minus three right that gives us six the other cases to do is to make this into a seven Right So if we're going to make this into a seven this is going to be six Seven minus one Gives us six plus We have to make this into a seven also and that's seven minus Three which is going to give us four Seven minus three which gives us four. So this would give us six plus four which gives us 10 okay or We could make Okay, so we could make one into three or seven We could make seven equal to one and three equal to one We could also do that So we have three cases right so we have um Let's do this three minus one plus seven minus three So if we go back, uh I want to make this Right, so this is one of our cases Ah No Yeah, whatever so Or I could do I could make All these into one so I could make this seven into a one and I could make this three into one right, so So remember we had three minus one Plus seven minus three right or we could have um Make them both into threes so then uh, no not threes Make them both into seven so seven minus one plus seven minus three which gives us 10 Or we could make each of these into ones so that would be seven minus one Plus three minus one which gives us six plus two which gives us eight Okay so It's actually better if you make it into the largest number right So Actually, is it the largest number? Seven minus one plus three minus one so seven minus one plus three minus one So it doesn't make the smallest this one make it to the middle number This one make it into Seven minus one seven minus one This one is uh This will make it into three right seven minus one plus seven minus three seven minus one No, this is making it to to sevens Wait, hold up. So three minus. Okay Back it up. My brain just got even more confused My brain is getting so confused now. Okay, so we let's let's go back to Okay, so We have a few cases Let's make this into a three right So let's make it the middle number then we do Three minus one plus seven minus three Which gives us six Okay Or we can make it the largest number So make it to seven so this becomes seven This becomes seven. So now we have seven minus one plus seven minus three which gives us Six plus four which gives us ten Or we could make this into the smallest number So make three into one seven into one so then we get seven minus One plus three minus one which gives us Okay, so it's actually better to make it into the middle number the median Okay, so let's actually do that instead. I think the median Subject make it into the middle number is actually the best So originally all we did was we just made it into Whatever is right most And I think that's what somehow worked That's not always the case. So it's actually better if we get the middle number. So When I say medium, I mean like the median of This this and this right so one three and seven Okay So, yeah, let's do that Okay, so We could just take um Yeah, okay So if we're gonna do it the median of the middle number of all three of the cases Yeah, okay, so we need like First case is the the end. This is the initial row We need to find which one is larger. So we need to do like um So if data C is greater than data at r and data at r And minus c minus one is greater than data at r data at n minus r minus 1 c So what would be the middle middle middle number? So in this case, let's actually rewrite this Because it's a little confusing And this is greater than data. So data at this is less than Okay, so data r c is greater than r m minus c minus 1 and data at n minus r minus c is less than this.  I'm gonna sort Okay, um, then we're just take the middle one. So it's there's only three numbers. So three Zero one two, so it'll just be zero one. So it'll be the first number um mead at one so Mead at one is going to be the middle number. So Okay, so now what we're going to do is we are going to Just subtract Each values from the mead and add them up Yeah, and then we're gonna convert them all equal to the mead. So Every one of these just becomes the mead. So we're also going to do Uh, total op total op is going to be plus equal to Um data at r minus mead Why can't I do this mead is I'll middle yeah, so we're gonna repeat this three times. Uh, this is gonna be Too lazy to write this I repeated this that's not what I wanted to do No I lost something What was the math thing? Um It was this n minus r minus one n minus r minus one See, yeah Okay, so we add all those and then we just can make All of them you become the middle Okay, so uh, this huge equal sign just makes this to equal to the right So this makes you a middle this equal to the middle this equal to middle. Yeah, okay Uh, add them up Yeah, I think this would work Not 100 sure though But I think it would work 8 and 46 dang it Ah, okay. What what is the what is it? What does it give me? Let's see the code 4334 8778 4334 It's not just the middle. What whichever is the middle number one four nine two What if we just subtract every case and see if it which one's the smallest? Because we don't know if the middle number would give you the the smallest every time Right Yeah, so let's just How do you know which one would give you the smallest 1 3 7? Did I sort it? I did sort it right 7 minus 3 7 minus 1 7 minus 2 I just don't understand I don't understand All right, um, they say don't find the median of the whole matrix A of n minus r of c minus 1 We need to think of the perfect destination for these four numbers I mean, that's what I was trying to do. I don't know 1 2 so we have this this this then we have this this and this This this and this so We've got a place the first four numbers We still got 30 minutes left. Um Let's think the more we think the better. Oh my gosh Oh my gosh typo Maybe this will work now That was the it works Yes It worked guide guys it worked sorting it Finding the best finding the middle number of this this and this Actually puts it at the best area. So like 1 3 and 7 find the middle number that will always get Subtracting it would work. Okay. So like 1 7 3 8. So yeah, that worked. Wow My problem was this typo Yeah, but it worked. So Yeah, that worked um That's crazy Yes, that worked. Oh, that was crazy. All right, let's go to Let's go to the next one bargain bargain. Okay Okay bargain. We still got more time We still got more time. We still got more time. We still got more time Okay, let's go back to here Okay, um Let's see if we could finish this Very difficult. These problems are difficult. It took me five tries Four tries five tries. Yeah, five tries and that's an hour and a 30 minutes also. Jesus Louise Up I did better than this guy though No, no Well, he's solving 19 minutes, but I don't know Yeah That was that was difficult difficult difficult. Okay, let's do this Okay, it is not easy to come to an agreement in a bargain so she can't come to agreement Sasha names Price as high as possible But then novella wants to remove as many digits from the price as possible The more details she names some digits n it removes a non empty substring from the price Okay, the remaining digits close the gap and the resulting digit is a price So if you name 1 2 1 3 1 2 1 If you remove 1 3 2 1 this you move that the result is 1 2 1 It's out to for the result of results to contain leading zeros if you remove all digits the price is zero Sasha wants to come up with a constraint so that Vova Vova can't just remove all digits But she needs some arguments to support the constraints to start what she wants to compile the sum of all Possible resulting prices after Vova's move um So we've got 107 Why is it 40 so you could choose to remove zero one seven one two zero two The resultings are zero seven one seven one zero seven one zero their sum is 42 17 24 zero zero seven zero 17 one one seven seven um Move so we remove Remove the one we get zero seven remove zero we get one seven Remove seven we get one zero we remove What else could remove one zero you get seven Remove zero seven you get one remove zero seven you get one Uh, we'll let zero we remove all of them you get zero So the number of ways you can remove one two three four five six, so it's three times two so it's n factorial, right? Oh lord I think you need to use Dynamic programming actually you might need to use dynamic programming um Okay, um Move one Resulting is zero seven Remove zero Resulting is 17 Move seven 10 Let's see. Let's see. Let's think how many different stages can you have? Let's say I loop through zero one two three three stages right If I remove the first one, this is the optimal solution Then the answer would be zero seven I remove the second one 17 would be the optimal solution With the third one 10 would be the optimal solution But if I remove 10 seven would be the optimal solution. So if you Oh wait Divide and conquer Yeah, I think it might be divide and conquer actually Okay, hold up So we have one zero one zero seven I remove so if I choose one So what if I split this into halves? One and zero seven. So I have to add one plus zero seven regardless I can learn to understand you much better if I can get familiar with the way you talk What was that? That was weird That was super weird. Okay Then what if I split it over here? Right, but then what if I split over here? Oh, but that's one oh seven. Now you can't do that This is answer 42 Seven eight 25 No seven Oh, because you can remove the middle rats So we have 107 you remove this plus 17 Is this 42 now eight plus 25? It is 42 Okay, so but the problem is what if I have like one zero one seven Huh So now that here's a problem that now if you You split this then you have one plus zero seven right Then you split this so so okay, so so so let here one plus zero seven Now let's say I have one zero one seven right and we split here then we added 10 17 Then what if I have one zero one seven we split here and now we have one oh one seven But then now you have to think about what if I have one oh one seven and I want to split Remove both of these then I have to add 17 again right And then what if I want to remove this one? Like what if I one more one one seven remove this one only 107 again Can we remove as many digits? Yeah, hello.  What is that gonna get you? Let's bring out our trusty calculator Okay, um, so we pull this out and let's do uh Whoops one plus 17 plus 10 plus 17 Plus 101 plus seven plus 17 plus 107 277 That's not right. Is that right? Hold up. Let's try their largest solution here This 10015 I don't know what this is Let's see if this works. I can't even draw on this for some reason um I can't even draw on this one zero one five Why can't I draw on this? Ah, whatever. Okay. Well At least I tried one zero But uh one zero zero five zero zero one zero zero Five zero zero. Let's try splitting. Okay. So we split this here and we have one plus five zero zero one zero zero five zero zero Then let's split over here So then we have 10 plus this same thing No, uh, wait actually it is the same thing Let's split over here 100 plus The exact same thing Uh, let's split over here. So this is different now Wait, how how many did they get? Okay, that's really weird. Uh one zero zero five Plus zero zero one zero zero five zero zero Uh, let's come here one zero zero five zero Wait One zero zero five zero. Yeah, plus One zero zero five zero zero one zero zero five Okay, so now let's take this whole thing. Okay. Um Let's cut this part one zero zero five zero zero zero plus One zero zero five zero zero Now let's cut this part One zero zero five zero zero one Plus five zero zero one zero zero five Let's split here One zero zero five zero zero one zero plus zero five zero zero Is it greater than the other one? I'm gonna pull out my trusty calculator because I'm not I don't trust this. Let's see Okay, so I already got over 225 million Is that 428 let's see One two one two Okay, wait, I got way more than that one Two four hundred the other I got I got way too much That's not that's not that's not right But I think splitting might actually be the thing that is The way to solve this problem What if we don't add re add the same number? So let's say we had This Then we take this and we don't add this again. So we just plus 10 We split this don't add this again. So we just plus 100 We split this now. We do have to add the rest. So now we do 100500 Okay We split this now we have 10050 And uh, we don't add this again 10050. Yeah, let's don't add it split this 100500 Don't add again Now we have to add it Plus one zero zero five zero zero one Do the one here? Okay One zero zero five zero zero one, but we also have to add 500 Okay, this one we added another zero so plus One zero zero five zero zero one zero All right, and we don't add the 500. Okay Uh, then we don't add the 500 again So this is we're just going to add the same number but with another zero Um now we Don't add the 500 and we're done So this added a five So like that. Okay. So let's just add all up all these numbers and see where they where that takes us I got way more It's all right four two eight one zero one nine four eight four. Yeah, that's when I got way too much Okay, I'm not gonna use this. I'm not Let's not look at the chat Because the dp solution there's definitely Oh, but we're modeling modding by 10 to the ninth plus seven We're modding by 10 to the ninth plus seven. Let's see Um I don't know I don't know actually. I don't know It's definitely use this is definitely a dynamic programming question though because you have multiple ways to choosing um Who's opcode opcode Who's this guy? He's trying so hard to get to expert I could feel it He's gonna get to expert one day. So you're gonna get to expert One day you're gonna get to expert Who's ray hon? Yeah, I want to get to specialist I'm my goal is to get to specialist actually First I gotta get to green then to specialist. I think that's why my long-term goal is actually to probably just specialist I don't know. I feel like I don't have the ability to get to expert And we'll see but yeah, that's That was these two questions are pretty tough. It took me a while to figure it out Maybe one day I'll I'll get like very high Probably when I'm an old man, maybe I don't know One day I will be able to solve a b and c one day Yeah, these the so I I realized the top when it was My ranking has dropped pretty badly, but it's because of the weird time zones Like one day it was at 5 a.m. Where I live I just stayed up and then I just couldn't solve the problem The other day it was like at I don't know 3 a.m. Where I lived Whatever Like some days it's like I don't know how you're able to do these problems when it's a different time zone.  Uh, we only have eight minutes left I don't know if I could figure out the dp solution um But let's see We want the maximum closing digits Do we do we want the max we want the sum of the resulting prices after removed so um What if at the current digit? Did I go through I removed that digit? So the The number is going to be one one three one two one One plus five thousand one oh one. I think you have a divide and conquer, but not actually think about dp It is modular about 10 to the ninth Split this okay if I split this Split this Split this it's too awkward here. Um Remove if I remove that Then you also have to think about what's before it Hmm Plus the current optimal solution will get you your right solution. Duh Plus the optimal solution All you got to do is add the optimal solution. I'll get you your dp Ah one plus 87 What's wrong with this 18 plus seven Let's go back to here. Let's try one of seven Let's actually try 107 one plus oh seven 10 plus seven 17 Is 42 Just 41 I don't know I don't know I don't know Maybe Maybe maybe maybe I don't know Wow Yeah, I'll always end up solving only a problem Well that Is it possible to get past newbie? One day Maybe I'll put it post. Is it possible to get past newbie? Is it possible to only be able to solve problem A? Not possible possible is it possible to get to I wanted to vote. I don't know. I cannot do this. I cannot do this. I cannot do this I don't know You just got to keep solving What if you just like do a virtual contest every like every day? What if I do a virtual contest every day, you know, let's see what happens if I do that, you know All right guys from now on I'll do a virtual contest every day. All right Daily dose of virtual contest Maybe one day one one one of the live streams. I'll be able to solve three one day One day I believe I believe inside my heart. I won't Basically right now. I'm just wasting the time because until I read the editorial because I don't know how to do C I absolutely lost It's not 42 This is not right I feel like one of those guys who like during the exam, they just don't know anything so they just submit they just turn in the paper empty That's what i'm doing on this problem Like I don't know Just just submit the paper empty. Like I don't know how to do this During any college, you know what I mean There's some people who are like that Like I don't know how to do this Too bad Too bad. Jose. He's not working What if I just submit whatever that's just that's just Let's just try okay, let's try 107 okay read an end What we're gonna do is we're gonna at the i-value. We're gonna take the i minus one the previous Not including it and we're gonna add by n divided by 10 no We need to cut the first part off Or the last part maybe we start at the end. Maybe we should start at the end Don't include this Here we don't include the middle How do you do that n over 10? n over 10 to the i What if that's the answer? You know what? I just try I mean we're at this point where like might as well try anything.  Let's mod this by by the the what was it called? One e seven one e nine plus seven What if this is the answer? I'll be wild like that just does this this this This recursion doesn't even make any sense That'll be wild. Ah, it does doesn't work.  Well, we tried we tried We tried let's look at the tutorial Let's count each digit each digit as many times including the first final sum into what place That's so and there's a length of the number and consider the digit a i at the place I am as if one some part of the number is the left of the digits removed And the remaining time is remaining in place and we add the number of weights to remove the same as the left Time multiplied by the current digit and we'll change to then j plus y So then we summation from 10 to a because it's jb is we got the full value I don't get it Maybe I do. I don't know. Let's look at this I knew it. I knew it median that worked. Hell. Yeah, that worked but I don't know Let's look at fence Quadrilateral is the can be built when the max Some of the three numbers is greater than the max to do this. You choose the max a plus b abc or a plus b as d I don't know. I just guessed on this For a i just completely guessed I don't know Let's look at c Count digit how many times will be included in the sum would it be? to know m as the length of the number n Of the number n Consider the ai at the digit i from the emma in some if some part of the number of the left digit is removed Then the current digit will remain in its place We add the number of ways to choose remove the sub-segment to the left To the answer multiplied by the current digit wait, what? The number of ways to remove the sub-segment to the left Multiply by the current digit why Why will change don't understand I don't understand So if we move like 107 Let's start at this Length is equal to m m is equal to three Right So they're at the ith position one to m Some of the number to the left the digits is removed and the current digital may remain its place So if this is removed Okay, let's start with seven seven is removed. No some digit on the left is removed. This seven will remain in place We need to add the number of ways to remove the sub-segment to the left of the answer multiplied by the current digit how many ways to the left multiplied by Seven and how do you get the number of ways to the left? I times i minus one over two times 10 to the m minus i m minus i Let's see zero one two m three minus i is two so that gives us 10 So then now number of ways to do it is i which is the current i two two times two minus one over two Multiply by 10 Two times two minus one over two. This is the number of different ways you could do it Ah, because it's two plus one dot dot dot down to zero down to one So that's why it's i times i minus one over two. That's why this works right right Then you multiply by 10. Why do you multiply by 10? The dimensions doesn't make any sense Why do you multiply by 10 to the m minus one? Why? Oh because of the number of digits That was close sort of no, no, it wasn't it was not close at all. Okay. Okay that number of digits Because it's 10 digits to the left No, why do you multiply by 10? Three minus two is one 10 why you multiply by 10? Oh because we're at the 10th digit here. No, that doesn't make any sense If the segment of the right is deleted Then the place of the digit will change So the place of the digit come j plus one times 10 to the j minus i from zero to m minus i which equals to Summation of zero to m minus i minus one of j plus one times 10 to the j times a of i. What the heck does that even mean? j plus one times 10 to the a j times eight of i What does that even mean? That makes no sense I don't know. How long have I been streaming two hours? I've been streaming for two hours. All right Guys, I think that'll end this live stream. We did We still have day and be ready to come subscribe. Maybe I'll do another live tomorrow. I'll check you guys later