while~0:s=raw_input().split();print[a+2*b+2*c+d for a,b in s for c,d in s if b+c in s][0]