There are three arrays *a*, *b* and *c*. Each of them consists of *n* integers. SmallY wants to find three integers *u*, *v*, *w* (0 ≤ *u*, *v*, *w* ≤ *n*) such that the following condition holds: each number that appears in the union of *a*, *b* and *c*, appears either in the first *u* elements of *a*, or in the first *v* elements of *b*, or in the first *w* elements of *c*. Of course, SmallY doesn't want to have huge numbers *u*, *v* and *w*, so she wants sum *u* + *v* + *w* to be as small as possible.

Please, help her to find the minimal possible sum of *u* + *v* + *w*.
The first line contains a single integer *n* (1 ≤ *n* ≤ 10<sup class="upper-index">5</sup>). The second line contains *n* space-separated integers *a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">2</sub>, ..., *a*<sub class="lower-index">*n*</sub> — array *a*. The third line contains the description of array *b* in the same format. The fourth line contains the description of array *c* in the same format. The following constraint holds: 1 ≤ *a*<sub class="lower-index">*i*</sub>, *b*<sub class="lower-index">*i*</sub>, *c*<sub class="lower-index">*i*</sub> ≤ 10<sup class="upper-index">9</sup>.
import fileinput
import copy

i=0
for line in fileinput.input():
    if i==0:
        n = int(line)
        myLists = [[0]*n for i in range(3)]
        i+=1
    else:
        myLists[i-1] = [int(i) for i in line.split()]
        i+=1

myListsCopy = copy.deepcopy(myLists)

def sortUnion(A,B,C):
    A.extend(B)
    A.extend(C)
    ans=list(set(A))
    ans.sort()
    return ans

myUnionList = sortUnion(myListsCopy[0],myListsCopy[1],myListsCopy[2])

L1 = len(myUnionList)
L = len(myLists[0])
myUnionDict = {}

for i in range(L1):
    k = []
    for j in range(3):
        if myUnionList[i] in myLists[j]:
            k.append(myLists[j].index(myUnionList[i]))
        else:
            k.append(L)
    myUnionDict[myUnionList[i]] = k

#print(myUnionDict)
   



def myMiniMax(myLists,myDict, L):
    valuesL = list(myDict.values())
    if len(valuesL) == 0:
        return [L]
    myMin = [ min(i) for i in valuesL ]
    myMax = max(myMin)
    relNum = [myLists[j][myMax] for j in range(len(myLists))]
    maxRelNum = max(relNum)
    myMaxVec = [i == maxRelNum for i in relNum]
    return [myMax, myMaxVec]

def myPruneFunc(myLists, myDict, myListIndex, myIndex):
    valuesToRemove = list(set(myLists[myListIndex][0:(myIndex+1)]))
    for i in valuesToRemove:
        if i in list(myDict.keys()):
            myDict.pop(i)
    for i in list(myDict.keys()):
        del myDict[i][myListIndex]
    del myLists[myListIndex]

def myRecFunc(myLists, myDict, currentSum, L):
    myMax = myMiniMax(myLists,myDict,L)
    if myMax[0] == L:
        return currentSum
    if len(myLists) == 0:
        return currentSum
    if len(myLists[0])==1:
        return currentSum+1+myMax[0]
    else:
        numCandidates = sum(myMax[1])
        candIndex = []
        for i in range(0, len(myMax[1])):
            if myMax[1][i]:
                candIndex.append(i)
        ansList = []
        copiedLists = []
        copiedDict = []
        for i in range(len(candIndex)):
            copiedLists.append(copy.deepcopy(myLists))
            copiedDict.append(copy.deepcopy(myDict))
            myPruneFunc(copiedLists[i],copiedDict[i],candIndex[i],myMax[0])
            ansList.append(myRecFunc(copiedLists[i],copiedDict[i],currentSum+1+myMax[0],L))
        return min(ansList)

print(myRecFunc(myLists,myUnionDict,0,L))
        
            
        

        









def operate(A):
    myMin = [ min(i) for i in list(A.values())]
    myIndex = myMin.index(max(myMin))
    valueInterest = max(A[myIndex])
    indexInterest = A[myIndex].index(valueInterest)
    for i in range(myIndex+1):
        A.pop(myLists[indexInterest][i])
    


