#include <iostream>
using namespace std;
int main(){
int n0, n1, n2, n3;
while (cin >> n0 >> n1 >> n2 >> n3){
if (n0 == 0 && n1 == 0 && n2 == 0 && n3 == 0) break;
int ans =720;
ans += ((40+n0-n1)%40)*9;
ans += 360;
ans += ((40+n2-n1)%40)*9;
ans += ((40+n2-n3)%40)*9;
cout << ans <<endl;
}
}