#include #define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false)) #define precise(i) fixed << setprecision(i) #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; int strToMin(string date) { int idx = 0; for (size_t i = 0; i < date.size(); ++i) { if (date[i] == ':') idx = (int)i; } int time = 0; // hour if (idx == 2) { time += stoi(date.substr(0, idx)) * 60; } else { time += (int)(date[0] - '0') * 60; } // min if (idx + 2 == (int)date.size()) { time += (int)(date[idx + 1] - '0'); } else { time += stoi(date.substr(idx + 1)); } return time; } int main() { fastIO; int n; cin >> n; int sum = 0; rep(i, n) { string wake, sleep; cin >> wake >> sleep; int w = strToMin(wake); int s = strToMin(sleep); if (w > s) s += 24 * 60; sum += s - w; } cout << sum << '\n'; }