#include <bits/stdc++.h>
#include "algotester.h"
using namespace std;
int main(int argc, char* argv[]) {
auto [test_in, checker_out, ans] = initScorer(argc, argv);
(void)ans;
int n = static_cast<int>(test_in.readInt(1, 5, "n_servers"));
test_in.readEndl();
long double BP = numeric_limits<long double>::infinity();
for (int i = 0; i < n; ++i) {
int serverId = static_cast<int>(test_in.readInt(1, 2147483647, "server_id"));
test_in.readSpace();
long long cpu = test_in.readInt(320000, 1180000, "server_cpu");
test_in.readSpace();
long long mem = test_in.readInt(64000, 1024000, "server_mem");
test_in.readSpace();
long long cost = test_in.readInt(10, 1000, "server_cost");
test_in.readEndl();
(void)serverId;
(void)mem;
BP = min(BP, static_cast<long double>(cost) / static_cast<long double>(cpu));
}
int k = static_cast<int>(test_in.readInt(1, 100, "k_queries"));
test_in.readEndl();
unordered_map<int, long long> queryCpu;
queryCpu.reserve(k * 2 + 1);
for (int i = 0; i < k; ++i) {
int queryId = static_cast<int>(test_in.readInt(1, 2147483647, "query_id"));
test_in.readSpace();
long long cpu = test_in.readInt(10, 100000000, "query_cpu");
test_in.readSpace();
test_in.readInt(1, 100000, "query_mem");
test_in.readSpace();
test_in.readInt(0, 3600, "query_qto");
test_in.readSpace();
test_in.readInt(0, 1, "query_type");
test_in.readEndl();
queryCpu[queryId] = cpu;
}
int m = static_cast<int>(test_in.readInt(1, 10, "m_instances"));
test_in.readEndl();
for (int i = 0; i < m; ++i) {
int instanceId = static_cast<int>(test_in.readInt(1, 2147483647, "instance_id"));
test_in.readSpace();
test_in.readInt(1, 9, "level");
test_in.readSpace();
int b = static_cast<int>(test_in.readInt(1, 100000, "initial_nodes_count"));
for (int j = 0; j < b; ++j) {
test_in.readSpace();
test_in.readInt(1, 2147483647, "node_id");
}
test_in.readEndl();
(void)instanceId;
}
int r = static_cast<int>(test_in.readInt(0, 86400, "request_timestamps_count"));
test_in.readEndl();
long double W = 0.0L;
for (int i = 0; i < r; ++i) {
string line = test_in.readLine();
if (line.empty()) {
cout << 0 << '\n';
return 0;
}
stringstream ss(line);
vector<long long> vals;
long long x;
while (ss >> x) vals.push_back(x);
if (vals.size() < 4 || (vals.size() - 1) % 3 != 0) {
cout << 0 << '\n';
return 0;
}
for (size_t p = 1; p < vals.size(); p += 3) {
int queryId = static_cast<int>(vals[p + 1]);
long long qps = vals[p + 2];
auto it = queryCpu.find(queryId);
if (it == queryCpu.end()) {
cout << 0 << '\n';
return 0;
}
W += static_cast<long double>(it->second) * static_cast<long double>(qps);
}
}
test_in.readInt(100, 1000000000, "cpu_min");
test_in.readSpace();
test_in.readInt(100, 1000000000, "mem_min");
test_in.readEndl();
test_in.readInt(100, 1000000000, "cpu_max");
test_in.readSpace();
test_in.readInt(100, 1000000000, "mem_max");
test_in.readEndl();
test_in.readInt(100, 5000, "g_cpu");
test_in.readSpace();
test_in.readInt(100, 5000, "g_mem");
test_in.readEndl();
test_in.readInt(1, 100, "T_lu");
test_in.readEndl();
test_in.readInt(1, 100, "T_cu");
test_in.readEndl();
test_in.readInt(1, 100, "T_so");
test_in.readEndl();
for (int i = 0; i < 9; ++i) {
test_in.readInt(1, 100, "L_i");
if (i + 1 < 9) test_in.readSpace();
else test_in.readEndl();
}
if (checker_out.isEof(true)) {
cout << 0 << '\n';
return 0;
}
string version = checker_out.readToken("version");
if (version != "HOTDBSCORE_V1") {
cout << 0 << '\n';
return 0;
}
if (checker_out.isEof(true)) {
cout << 0 << '\n';
return 0;
}
long double C_r = checker_out.readDouble("C_r");
long double C_s = checker_out.readDouble("C_s");
long double Cost = C_r + C_s;
long double CostStar = W * BP;
if (!isfinite(Cost) || !isfinite(CostStar) || Cost <= 0.0L || CostStar < 0.0L) {
cout << 0 << '\n';
return 0;
}
long double raw = floor((CostStar / Cost) * 1e7L + 1e-12L);
if (!isfinite(raw) || raw <= 0.0L) {
cout << 0 << '\n';
return 0;
}
if (raw > static_cast<long double>(LLONG_MAX)) {
cout << LLONG_MAX << '\n';
return 0;
}
cout << static_cast<long long>(raw) << '\n';
return 0;
}