#define _USE_MATH_DEFINES //M_PI #include //std::cout, std::cin #include //std::string #include //std::vector #include //std::valarray 数値のみの一次配列 #include //std::sort #include //localtime_s #include //abs #include //abs, std::pow, sqrt, sin, cos, #include //std::ifstream #include //std::setprecision #include //std::random(C++11) #include //std::accumulate int main(void) { //test用 //std::ifstream in("test.txt"); //std::cin.rdbuf(in.rdbuf()); int N; std::string str1, str2; std::cin >> N; int ans = 0; for (int i = 0; i < N; i++) { std::cin >> str1 >> str2; std::string temp; int s_h, s_m, w_h, w_m; int j = 0; while (str1[j] != ':') { temp.push_back(str1[j]); j++; } s_h = std::stoi(temp); j++; temp.clear(); while (j < str1.length()) { temp.push_back(str1[j]); j++; } s_m = std::stoi(temp); j = 0; temp.clear(); while (str2[j] != ':') { temp.push_back(str2[j]); j++; } w_h = std::stoi(temp); j++; temp.clear(); while (j < str2.length()) { temp.push_back(str2[j]); j++; } w_m = std::stoi(temp); if (s_h > w_h) { ans += (24 - s_h - 1) * 60 + (60 - s_m) + w_h * 60 + w_m; } else if (s_h < w_h) { ans += (w_h - s_h - 1) * 60 + (60 - s_m) + w_m; } else { if (w_m >= s_m) { ans += w_m - s_m; } else { ans += 23 * 60 + (60 - s_m) + w_m; } } } std::cout << ans << std::endl; }