public static void main(String args[]) throws Throwable {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		for (StringTokenizer st;(st=new StringTokenizer(in.readLine()))!=null;) {
			int D=parseInt(st.nextToken()),A=parseInt(st.nextToken()),B=parseInt(st.nextToken()),C=parseInt(st.nextToken()),s=40*3;
			if(D==0&&A==0&&B==0&&C==0)break;
			s+=(A>D?D+40-A:D-A)+(A>B?B+40-A:B-A)+(C>B?B+40-C:B-C);
			System.out.println(s*9);
		}
	}