# [kattis] Combination Lock >題目連結:https://open.kattis.com/problems/combinationlock Now that you’re back to school for another term, you need to remember how to work the combination lock on your locker. A common design is that of the Master Brand, shown at right. The lock has a dial with $40$ calibration marks numbered $0$ to $39$ with $0$ at the top and then increasing in clockwise order. A combination consists of $3$ of these numbers; for example: $15$-$25$- $8$. To open the lock, the following steps are taken: :::success 現在你又回到學校上課了,你需要記住如何操作你儲物櫃上的組合鎖。一個常見的設計是Master品牌的,如右圖所示。這個鎖上有一個刻度盤,有$40$個刻度,從$0$到$39$編號,$0$位於頂部,然後按順時針方向增加。一個組合包括其中的$3$個數字,例如:$15$-$25$-$8$。要打開這個鎖,需要按照以下步驟進行操作: ::: - turn the dial clockwise $2$ full turns - stop at the first number of the combination - turn the dial counter-clockwise $1$ full turn - continue turning counter-clockwise until the $2$nd number is reached - turn the dial clockwise again until the $3$rd number is reached - pull the shank and the lock will open. :::success - 將刻度盤順時針轉$2$圈 - 停在組合的第一個數字 - 將刻度盤逆時針轉$1$圈 - 繼續逆時針轉,直到到達組合的第二個數字 - 再次將刻度盤順時針轉到組合的第三個數字 - 拉動插鉤,鎖將打開。 ::: Given the initial position of the dial and the combination for the lock, how many degrees is the dial rotated in total (clockwise plus counter-clockwise) in opening the lock? :::success 給定刻度盤的初始位置和鎖的組合,請問打開鎖時刻度盤總共需要轉動多少度(包括順時針和逆時針方向)? ::: ## Input Input consists of several test cases, at most $2000$. For each case there is a line of input containing $4$ numbers between $0$ and $39$. The first number is the position of the dial. The next three numbers are the combination. Consecutive numbers in the combination will be distinct. A line containing four zeros follows the last case. :::success 輸入包含多個測試案例,最多 $2000$ 個。對於每個案例,輸入中有一行包含 $4$ 個介於 $0$ 和 $39$ 之間的數字。第一個數字是刻度盤的位置。接下來的三個數字是組合的數字。組合中的連續數字將不同。在最後一個案例之後,會有一行包含四個零。 ::: ## Output For each case, print a line with a single integer: the number of degrees that the dial must be turned to open the lock. :::success 對於每個案例,請輸出一行,包含一個整數:刻度盤需要轉動多少度才能打開鎖。 ::: ### Sample Input 1 ``` 0 30 0 30 5 35 5 35 0 20 0 20 7 27 7 27 0 10 0 10 9 19 9 19 0 0 0 0 ``` ### Sample Output 1 ``` 1350 1350 1620 1620 1890 1890 ``` ###### 翻譯錯誤請留言告知