#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <functional>
using namespace std;
template <class InputIterator1, class InputIterator2, class OutputIterator>
OutputIterator _merge (InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2,
OutputIterator result)
{
while (true) {
if (first1==last1) return copy(first2,last2,result);
if (first2==last2) return copy(first1,last1,result);
*result++ = (*first2<*first1)? *first2++ : *first1++;
}
}
int main(){
array<int,8> t1 = {3,5,7,11,13,17,19,23};
array<int,8> t2 = {3,5,7,11,13,17,19,23};
array<int,16> t3;
_merge(t1.begin(),t1.end(),t2.begin(),t2.end(),t3.begin());
for_each(t3.begin(),t3.end(),[](int i){cout<<i<<endl;});
return 0;
}