#include <iostream>

int* mergeArrays(int* A, int sizeA, int* B, int sizeB, int& sizeC) {
    int* C = new int[sizeA + sizeB];
    int i = 0, j = 0, k = 0;

    while (i < sizeA && j < sizeB) {
        if (A[i] <= B[j]) {
            C[k] = A[i];
            i++;
        } else {
            C[k] = B[j];
            j++;
        }
        k++;
    }
    while (i < sizeA) {
        C[k] = A[i];
        i++;
        k++;
    }

    while (j < sizeB) {
        C[k] = B[j];
        j++;
        k++;
    }

    sizeC = sizeA + sizeB;
    return C;
}

int main() {
    int A[] = {1, 3, 5};
    int B[] = {2, 4, 6};
    int sizeA = 3;
    int sizeB = 3;
    int sizeC;

    int* C = mergeArrays(A, sizeA, B, sizeB, sizeC);

    std::cout << "C = {";
    for (int i = 0; i < sizeC; ++i) {
        std::cout << C[i];
        if (i < sizeC - 1) {
            std::cout << ", ";
        }
    }
    std::cout << "}" << std::endl;

    delete[] C;

    return 0;
}

