#include <iostream>
using namespace std;

void bubbleSort(int arr[], int n){
    for(int i=0;i<n-1;i++){
        bool swap = false;
        for(int j=0;j<n-i-1;j++){
            if(arr[j]>arr[j+1]){
                int temp = arr[j];
                arr[j] = arr[j+1];
                arr[j+1] = temp;
                swap = true;
            }
        }
        if(!swap){
            break;
        }
    }
}

void ssearch(int x[], int y[], int z[], int l, int m, int n){
    int i=0, j=0, k=0;
    while(i<l && j<m && k<n){
        if(x[i]==y[j] && y[j]==z[k]){
            cout << "The smallest common element is " << x[i] << endl;
            return;
        }else if(x[i]<y[j]){
            i++;
        }else if(y[j]<z[k]){
            j++;
        }else{
            k++;
        }
    }
    cout << "Not found!" << endl;
}

int main(){
    int a, b, c;
    cout << "Please input the amount of numbers in the first, second and third array: ";
    cin >> a >> b >> c;
    int *fData = new int[a];
    int *sData = new int[b];
    int *tData = new int[c];
    cout << "Input the elements in array I: ";
    for(int i=0;i<a;i++){
        cin >> fData[i];
    }
    cout << "Input the elements in array II: ";
    for(int i=0;i<b;i++){
        cin >> sData[i];
    }
    cout << "Input the elements in array III: ";
    for(int i=0;i<c;i++){
        cin >> tData[i];
    }
    bubbleSort(fData, a), bubbleSort(sData, b), bubbleSort(tData, c);
    ssearch(fData, sData, tData, a, b, c);
    delete[] fData, sData, tData;
    return 0;
}