#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; // 00:00からの差が何分かを考える // 日またぎ // 起きた時間 <= 寝た時間 // 日またぎしない // 1日は24*60分 // 起きた時間 >= 寝た時間 int asMinute(int h, int m) { return h * 60 + m; } vector split(string s, const string &delimiter) { size_t pos_start = 0, pos_end, delim_len = delimiter.length(); string token; vector res; while ((pos_end = s.find(delimiter, pos_start)) != string::npos) { token = s.substr(pos_start, pos_end - pos_start); pos_start = pos_end + delim_len; res.push_back(token); } res.push_back(s.substr(pos_start)); return res; } int main() { int N; cin >> N; int result = 0; for (int i = 0; i < N; ++i) { string S1, S2; cin >> S1 >> S2; vector ss1 = split(S1, ":"); vector ss2 = split(S2, ":"); int H = stoi(ss1[0]); int M = stoi(ss1[1]); int h = stoi(ss2[0]); int m = stoi(ss2[1]); int sleep = asMinute(H, M); int wakeUp = asMinute(h, m); if (sleep < wakeUp) { result += (wakeUp - sleep); } else if (wakeUp == sleep) { continue; } else { result += ((wakeUp + 24 * 60) - sleep); } } cout << result << endl; return 0; }