#include<iostream>using namespace std;int main(){int a,b,c,d,n;while(cin>>a>>b>>c>>d , a || b || c || d){if(a>b) n=a-b; else n=a+40-b;if(b>c)n+=c+40-b; else n+=c-b;if(c>d) n+=c-d; else n+=c+40-d;n=n*9;cout<<1080+n<<endl;}}