#include <vector>
#include <iostream>
void replace2(std::vector <int>& a, int n){
for (int i = n-1; i >= 0; --i){
if (a[i] == 2){
a.erase(a.begin() + i);
for(int j = 0; j < 4; ++j){
a.insert(a.begin() + i, 5);
}
}
}
}
int main()
{
std::vector<int> a{2, 2, 2};
replace2(a, 3);
for(auto item : a )
{
std::cout << item;
}
std::cout << std::endl;
}
I2luY2x1ZGUgPHZlY3Rvcj4KI2luY2x1ZGUgPGlvc3RyZWFtPgoKdm9pZCByZXBsYWNlMihzdGQ6OnZlY3RvciA8aW50PiYgYSwgaW50IG4pewogICBmb3IgKGludCBpID0gbi0xOyBpID49IDA7IC0taSl7CiAgICAgIGlmIChhW2ldID09IDIpewogICAgICAgICBhLmVyYXNlKGEuYmVnaW4oKSArIGkpOwogICAgICAgICBmb3IoaW50IGogPSAwOyBqIDwgNDsgKytqKXsKICAgICAgICAgICAgYS5pbnNlcnQoYS5iZWdpbigpICsgaSwgNSk7CiAgICAgICAgIH0KICAgICAgfQogICB9Cn0KCmludCBtYWluKCkKewogICBzdGQ6OnZlY3RvcjxpbnQ+IGF7MiwgMiwgMn07CiAgIHJlcGxhY2UyKGEsIDMpOwoKICAgZm9yKGF1dG8gaXRlbSA6IGEgKQogICB7CiAgICAgIHN0ZDo6Y291dCA8PCBpdGVtOwogICB9CgogICBzdGQ6OmNvdXQgPDwgc3RkOjplbmRsOwp9Cg==