#include <iostream>
using namespace std;
int main() {
int h1, m1, h2, m2, result = 0;
cin >> h1 >> m1 >> h2 >> m2;
while(true) {
if(m1 == 0) {
result += h1 > 12 ? h1 - 12 : h1 == 0 ? 12 : h1;
} else if(m1 == 30) {
result++;
}
if(h1 == h2 && m1 == m2) {
break;
}
m1++;
if(m1 == 60) {
m1 = 0;
h1++;
}
}
cout << result << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG1haW4oKSB7CglpbnQgaDEsIG0xLCBoMiwgbTIsIHJlc3VsdCA9IDA7CgljaW4gPj4gaDEgPj4gbTEgPj4gaDIgPj4gbTI7Cgl3aGlsZSh0cnVlKSB7CgkJaWYobTEgPT0gMCkgewoJCQlyZXN1bHQgKz0gaDEgPiAxMiA/IGgxIC0gMTIgOiBoMSA9PSAwID8gMTIgOiBoMTsKCQl9IGVsc2UgaWYobTEgPT0gMzApIHsKCQkJcmVzdWx0Kys7CgkJfQoJCWlmKGgxID09IGgyICYmIG0xID09IG0yKSB7CgkJCWJyZWFrOwoJCX0KCQltMSsrOwoJCWlmKG0xID09IDYwKSB7CgkJCW0xID0gMDsKCQkJaDErKzsKCQl9Cgl9Cgljb3V0IDw8IHJlc3VsdCA8PCBlbmRsOwoJcmV0dXJuIDA7Cn0=