 What's up guys, my name is Michael and welcome to my YouTube channel. Today we are going to go over code forces round 696 puzzle from the future division two. Okay, so basically you have two numbers A and B their length of N. Okay, and A and B just has digits zero and one. Okay. Now what we're going to do is we're going to add A and B together. And then we're going to call it C. Okay, that's what it is. Now, what Michael's going to do is that he's going to remove all the consecutive digits, which is like digits side by side that are the same. And we're going to call that a new number D. Okay, now, unfortunately, we lost the integer a before we could calculate D. So now what we want to do is we want to find the any arbitrary number a of length N such that D is the maximum as possible. I'll actually go over go over what I mean by that. So like, we have two integers a and then two integers B. Right. So let's actually go over an example. So here, let's say we have 0 1 1 0 is a so 0 1 1 0. This is a. Okay. And B is equal to 1 1 0 1. So 1 1 0 1. Okay. So these are this is a this is a number a and this is a number B. Okay, what we're going to do is we're going to have C is going to equal to a plus B. Okay, that's what this is going to do. So what this is doing is that it's just going to add them up. So this is going to be they actually calculate this for us. I think I don't want to I don't want to do math myself. Okay, whatever. 1 plus 0 is 1. 1 plus 0 is 1. 1 plus 1 is 2. 0 plus 1 is 1. Okay, so this is going to give us C. Okay, now what we're going to do is we're going to get another integer called D. Okay, so now what we're going to do is we're going to find the create a new new number D and it's going to get rid of the consecutive numbers. So here the consecutive equal numbers. So like we have 1 2 1 1. Basically what that means is that it's going to repeat the repeated values. So it's going to get rid of the repeated values. So we have 1 2 1 1. So if I get rid of the repeated values, I'm just going to have 1 2 1, right? Because 1 was repeated. This one was repeated. So I'm going to get rid of that. So that's what this number D is. Okay, that's what this number D is. So now now the problem is asking is that unfortunately now Mike lost to the original A. So this original value of A, he lost this, right? This is he doesn't know what this is. Okay. But he does give you B, right? So he gives you B. So he tells you what this is, what this, this, this value B is. And he wants to know what a value a what is the value of a to maximize this D, this number D, right? So this we want to make this as large as possible, right? So we want to make this D as large as possible, max, largest as possible. So we want to give you, we want to find this, the A such that this D is as large as possible, right? So when you add A plus B, and then you remove the consecutive equal numbers, this D would be as large as possible. Okay. Okay, so I actually don't remember what I put, but I did solve this during the contest. So let's just actually just go over what I did. Okay. So how do you solve this problem? How do you actually solve this problem? Okay. So remember, we have to think back what the problem statement is asking. So they want this D to be as large as possible. So how do I get D as large as possible? Well, think about, think, think he's very good. Okay. So remember, we have this value of B, right? We're given this. And we need to get this value as large as possible. So what is the largest possible value you could have, right? Of D? Well, the largest possible value you could have, because these are all zeros and ones, digits zeros and ones, largest possible values, if there is, there are all twos, right? Do you guys understand? Because if I had like one, one, one, one, and I add one, one, one, one, like assuming both of these are assuming me a and B are just as large as possible, like completely as large as possible. If I add both of them up, there's going to give me a bunch of twos, right? Because we know that from the input statement that A and B only have digits zero and one. So the largest possible I could actually have is going to be a bunch of twos, right? So how do I get a bunch of twos in the end? Well, I don't know if it's going to be a bunch of twos, right? Because we don't know what, what, what's going to have, right? Because it could be a bunch of twos, it could, it could not be. But we do know what B is, right? So we know what B is. B is one, one, zero, one, right? B, B is a value they give us, they give us this, right? So if I want to get the largest as possible, given that this B now is not, not, if this B value is not a bunch of ones, what do I have to do? It's like simple. You would add by a bunch of ones, right? You would, you would take B and you add a bunch of ones. And the reason why is because think about this. To get to maximum, the maximum possible you could possibly get, right? With a bunch of ones in a bunch of ones, right? If you add them together, there's a bunch of twos, right? All twos, right? Because we have only digits zero and one. So the maximum possible value of A could be, this A could be, right? Because given this B, it's just going to be a bunch of ones, right? So what did I do first? So first in the code, what I did was I first created a new, a new string, this, I actually messed up this, the notation of B and A, but just, just, this is supposed to be A, okay? So in this case, I just created a initial string of all ones, okay? Of A to have all ones, okay? So initially, A is going to have is, A is going to have is just going to be full of all ones. So here, it'll be all ones, right? And all ones, the length of N, because we know what, we know what the two strings lengths are, right? We know they're both lengths of N. So I make them all ones, okay? So now what do I do? What I do is I take this string of all ones, right? And I add it with my string of B. So here, remember, what was our string of B? I don't actually remember. What was the example they gave us? Okay, so the string of B they gave us was 0, 1, 1, 0. I think, no, no, 1, 1, 0, 1, 1, 0, 1, okay? So 1, 1, 0, 1, okay? So what I do is I take A, I fill a bunch of ones, and I add it to B, okay? So these are just basically, basically implementing it, right? The maximum possible value I could have if A is just all ones, I just take this and add it with B. So I add these together. So this is going to see is going to equal to both these add together. So it's going to be 2, right? 2, 1, and then 2, right? 2, 2, 1, 2, okay? So that's just that's just adding the two numbers together. So that's what I do here, right? I create a new string of C. It's going to equal to the string of my the input value of B plus equal to converted the string of A converted, right? So this B is actually supposed to be A. Just don't mind it, right? This is just a bunch of ones, okay? So what we do is here, what this code is doing is it's going to convert, it's going to loop through, loop through both of the strings, and it's going to convert it to the number value, right? Because it's a string, I read it as a string. So I'm going to convert it to its original number. So this is just going to convert each individual digits to its digit values, and it's going to add them up. And it's just going to convert into a string. So that's what the C is going to equal to. Okay, now what do I have to do? Remember, we have to get rid of the get rid of the values, right? So we have to the problem doesn't end here, because if you look back at the problem statement, we have to get rid of the consecutive equal digits in C, right? So if they have the same digit, right? The same digits of like 1100, right? We have to get rid of that. If we get rid of a digit, it makes the values super small. And that's not what we want. Right? Remember, we want to make the digit D as large as possible, maximum as possible. So we don't want equal digits in our answer. So if we go back to this, go back to this case, right? Our answer, like if I just just guess that A is going to be all ones, right? What's this going to do is it's going to get C is equal to two, two, one, two, right? But then our D, remember, our D is going to remove the equal consecutive digits, the ones that are right next to each other and they're equal. So what this is going to return is it's going to get rid of this two, and because this two and this two are the same, right? It's going to get rid of this two. So it's going to give us one, two, one, two. And this is way smaller than C. Remember, we want our D to be as maximum as possible, largest as possible, right? That's that's what they want. So we cannot have consecutive equal digits here, two, two, one, two. We cannot have consecutive equal digits. So how do I make it remain maximum as possible without completely getting rid of, without the without just changing it completely, right? You're just just getting rid of the consecutive digits. How do I make this D as maximum as possible, right? Simple. We don't allow consecutive digits in C. So in when we see two, two, one, two, we don't allow that, right? We don't want consecutive digits in C. So how do I prevent a consecutive digit in C, right? If, what do I do? I'm going to subtract one from A, right? So whatever digit that was repeated, this two, two, one, two, right? Two, two, one, two. This two was repeated. I'm going, instead of having this A as a value of one, I'm going to have this A as a value of zero, okay? So that's going to prevent, that's going to get rid of this consecutive digit. So in this end, this two is actually going to be a one, right? Because we have zero plus one is will be one, right? So this sum is now actually going to be, it gets rid of the consecutive digit and we will have two, one, one, two, right? Now let's look at this next one. Okay, we have one, one. Well, we don't actually have a consecutive digit here, one and two, one, one, two. These are not consecutive digits, right? These are not equal digits. These digits are not the same, not equal consecutive digits. So we're done, right? So if I want to print out the original value, it'll just be a now. I have the maximum of the right value of a to add to be to get D as large as possible, right? Because in this end, in the end, this D is not going to be two, one, two, it's going to be two, one, one, two. Okay, that's what this D is going to equal to. That's what this D is going to equal to. So in the case of our example, what I did in the code is basically just that. So here, here, we, what I do is here is, this C is just created by adding them together, right? And then here, I check if there's a consecutive digit, right? So I loop from one to the end. And if it is equal, I'm going to replace the value with a zero in the original value. So here, in the original value of a, I'm going to replace the original digit set is going to now equal to zero. Right? So that's what this does. This does. So this loop checks if I find a consecutive digit in my new C value, right, in new C, I'm going to set the original value of my original value of a is going to be equal to zero. Okay. And then I'm going to, what I'm going to do is I'm going to, a C is for the value of C, I'm going to convert it into its number format. Okay. If the update the new value of C, so what this does is the C original was two, I'm going to change it into a one, right? That's what this does because now the updated value is going to be zero plus one is going to give me one, right? This place of zero plus this place of one is going to give me one. So that's what this does. Okay. So that's what this C does. It updates the value. Okay. Then what I do is I'm going to update it again to check if I run this again. And the reason why I run this again is that sometimes you, we don't actually, there's some issues that might occur with some few test cases that might occur. So I basically do this again in case if I had like a repeated digit that needs to get removed. Okay. So that's what I did here. So yeah, I pretty much did I set C equal to an empty string, and I just redid this exactly one more time. So I basically just update, I add up the two values of A and B again, call that my C. If, if the value is equal to a repeated character right one next to each other, I'm going to set it back to zero of my original value to zero, and then I just print out the value. And that's going to get you the optimal a value added to be such that this D is going to be as large as possible. Right. So I hope you guys enjoyed this video. Rate com subscribe. That was pretty much the gist of it. Rate com subscribe. I'll check you guys later. Peace.