#include <iostream>
using namespace std;
int main() {
longlongint a, b, c, d, e, f=0, h, i, g=0;
while ((cin >> a >> b >> c >> d)&&(a || b || c || d)) {
if (a>b) {
f = (b - a) * 9 + 360;
}
else {
f = (b - a) * 9;
}
if (b>c) {
h = (c - b) * 9;
}
else {
h = (c - b) * 9 + 360;
}
if (c>d) {
i = (d - c) * 9 + 360;
}
else {
i = (d - c) * 9;
}
e = 720 + f + 360 + h + i;
cout << e << endl;
}
}