#include<iostream>
#include<vector>
#include <bits/stdc++.h>
using namespace std;
double MedianOfArrays(vector<int>& array1, vector<int>& array2)
{
    // Your code goes here
    int m=array1.size();
    int n=array2.size();
    int x=(m+n)/2;
    int i=0,j=0,temp,count=0,x1,x2;
    while(i<m && j<n)
    {   
        if(array1[i]<=array2[j])
        {
            temp=array1[i];
            count++;
            i++;
        }
        else
        {
            temp=array2[j];
            count++;
            j++;
        }
        if(count==x)
        {
            x1=temp;
        }
        if(count==x+1)
        {
            x2=temp;
        }
    }
    while(i<m)
    {
         temp=array1[i];
            count++;
            i++;
            if(count==x)
        {
            x1=temp;
        }
        if(count==x+1)
        {
            x2=temp;
        }
    }
    while(j<n)
    {
        temp=array2[j];
            count++;
            j++;
            if(count==x)
        {
            x1=temp;
        }
        if(count==x+1)
        {
            x2=temp;
        }
    }
    if((m+n)%2==1)
    {
        return x2;
    }
    else
    {
        return (double)((x1+x2)/2.0);
    }
    
}
int main()
{
        vector<int> array1={1,4,7,8,9};
       
        vector<int> array2={8,10,11,11,12};
        
        cout<<MedianOfArrays(array1, array2)<<endl;

    return 0; 
}
