import java.util.Scanner; public class Jump { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int totalScore = 0; int preScore = 0; while(sc.hasNextInt()){ int flag = sc.nextInt(); int score = 0; if(flag == 0){ break; }else if(flag == 1){ //跳上方块没有跳到中心,总分+1 score +=1; preScore = 1; totalScore += score; }else if(flag == 2){ //跳上方块并且跳到中心,上次分数+2+总分 if(preScore == 1){ score = 2; }else{ score = preScore + 2; } preScore = score; totalScore += score; } } System.out.println(totalScore); } }