Buggy python submission (verdict: Runtime Error):
v=[4,1,4,1,2,1,2,1]
while True:
    x=raw_input()
    x=x[0:len(x)-1]
    p=map(int,x.split(" "))
    min=[]
    min_value=0

    for i in range(8):
        count=0
        for j in range(8):
            if p[(j)%8]-v[(j+i)%8]>=0:
                count+=p[(j)%8]-v[(j+i)%8]
        if len(min)==0:
            min_value=count
            min.append(i)
        else:
            if count<min_value:
                min_value=count
                min=[]
                min.append(i)
            elif count==min_value:
                min.append(i)
    min1_value=41412122
    for i in range(len(min)):
        value=""
        for j in range(8):
            value+=str(v[(j+min[i])%8])
        if min1_value>int(value):
            min1_value=int(value)
            min1=min[i]
    solve=[]
    for i in range(8):
        solve.append(str(v[(i+min1)%8]))
    print " ".join(solve)

Fixed submission:
v=[4,1,4,1,2,1,2,1]
while True:
    try:
        p=map(int,raw_input().split(" "))
        min=[]
        min_value=0
        
        for i in range(8):
            count=0
            for j in range(8):
                if p[(j)%8]-v[(j+i)%8]>=0:
                    count+=p[(j)%8]-v[(j+i)%8]
            if len(min)==0:
                min_value=count
                min.append(i)
            else:
                if count<min_value:
                    min_value=count
                    min=[]
                    min.append(i)
                elif count==min_value:
                    min.append(i)
        min1_value=41412122
        for i in range(len(min)):
            value=""
            for j in range(8):
                value+=str(v[(j+min[i])%8])
            if min1_value>int(value):
                min1_value=int(value)
                min1=min[i]
        solve=[]
        for i in range(8):
            solve.append(str(v[(i+min1)%8]))
        print " ".join(solve)
    except:
        break

Buggy python submission (verdict: Runtime Error):
v=[4,1,4,1,2,1,2,1]
while True:
    p=map(int,raw_input().split(" "))
    min=[]
    min_value=0

    for i in range(8):
        count=0
        for j in range(8):
            if p[(j)%8]-v[(j+i)%8]>=0:
                count+=p[(j)%8]-v[(j+i)%8]
        if len(min)==0:
            min_value=count
            min.append(i)
        else:
            if count<min_value:
                min_value=count
                min=[]
                min.append(i)
            elif count==min_value:
                min.append(i)
    min1_value=41412122
    for i in range(len(min)):
        value=""
        for j in range(8):
            value+=str(v[(j+min[i])%8])
        if min1_value>int(value):
            min1_value=int(value)
            min1=min[i]
    solve=[]
    for i in range(8):
        solve.append(str(v[(i+min1)%8]))
    print " ".join(solve)

Fixed submission:
v=[4,1,4,1,2,1,2,1]
while True:
    try:
        p=map(int,raw_input().split(" "))
        min=[]
        min_value=0
        
        for i in range(8):
            count=0
            for j in range(8):
                if p[(j)%8]-v[(j+i)%8]>=0:
                    count+=p[(j)%8]-v[(j+i)%8]
            if len(min)==0:
                min_value=count
                min.append(i)
            else:
                if count<min_value:
                    min_value=count
                    min=[]
                    min.append(i)
                elif count==min_value:
                    min.append(i)
        min1_value=41412122
        for i in range(len(min)):
            value=""
            for j in range(8):
                value+=str(v[(j+min[i])%8])
            if min1_value>int(value):
                min1_value=int(value)
                min1=min[i]
        solve=[]
        for i in range(8):
            solve.append(str(v[(i+min1)%8]))
        print " ".join(solve)
    except:
        break