#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
vector<int> interlace_vectors(const vector<int>& v1, const vector<int>& v2)
{
vector<int> result;
for(size_t n = 0; n < max(v1.size(), v2.size()); ++n)
{
if(n < v1.size()) result.push_back(v1[n]);
if(n < v2.size()) result.push_back(v2[n]);
}
return result;
}
int main()
{
vector<int> v1 = {4,7,9,3,1};
vector<int> v2 = {3,6,9};
vector<int> v3 = interlace_vectors(v1, v2);
// for(int n: v3)
// cout << n << ' ';
// LWS is down at the moment, IDEone has an old compiler, so another way to loop:
for_each(v3.begin(), v3.end(), [](int n){cout << n << ' ';});
cout << '\n';
}
I2luY2x1ZGUgPHZlY3Rvcj4KI2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8YWxnb3JpdGhtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKdmVjdG9yPGludD4gaW50ZXJsYWNlX3ZlY3RvcnMoY29uc3QgdmVjdG9yPGludD4mIHYxLCBjb25zdCB2ZWN0b3I8aW50PiYgdjIpCiB7CiAgICAgIHZlY3RvcjxpbnQ+IHJlc3VsdDsKICAgICAgZm9yKHNpemVfdCBuID0gMDsgbiA8IG1heCh2MS5zaXplKCksIHYyLnNpemUoKSk7ICsrbikKICAgICAgewogICAgICAgICAgIGlmKG4gPCB2MS5zaXplKCkpIHJlc3VsdC5wdXNoX2JhY2sodjFbbl0pOwogICAgICAgICAgIGlmKG4gPCB2Mi5zaXplKCkpIHJlc3VsdC5wdXNoX2JhY2sodjJbbl0pOwogICAgICB9CiAgICAgIHJldHVybiByZXN1bHQ7CiB9CiAKIGludCBtYWluKCkKIHsKICAgICB2ZWN0b3I8aW50PiB2MSA9IHs0LDcsOSwzLDF9OwogICAgIHZlY3RvcjxpbnQ+IHYyID0gezMsNiw5fTsKICAgICB2ZWN0b3I8aW50PiB2MyA9IGludGVybGFjZV92ZWN0b3JzKHYxLCB2Mik7CiAgICAgCiAgICAgLy8gZm9yKGludCBuOiB2MykKICAgICAvLyAgICAgY291dCA8PCBuIDw8ICcgJzsKICAgICAvLyBMV1MgaXMgZG93biBhdCB0aGUgbW9tZW50LCBJREVvbmUgaGFzIGFuIG9sZCBjb21waWxlciwgc28gYW5vdGhlciB3YXkgdG8gbG9vcDoKICAgICBmb3JfZWFjaCh2My5iZWdpbigpLCB2My5lbmQoKSwgW10oaW50IG4pe2NvdXQgPDwgbiA8PCAnICc7fSk7CiAgICAgY291dCA8PCAnXG4nOwogICAgIAogfQ==