#if __INCLUDE_LEVEL__ == 0 #include __BASE_FILE__ void Solve() { int64_t a, b, c, x, y, z; IN(a, b, c, x, y, z); auto f = [&](int64_t t) -> int64_t { int64_t ret = 0; ret += abs(t - a) * x; ret += abs(t - b) * y; ret += abs(t - c) * z; return ret; }; int64_t l = min({a, b, c}) - 1; int64_t r = max({a, b, c}) + 1; while (r - l > 2) { int64_t ml = DivFloor(l + l + r, 3); int64_t mr = DivCeil(l + r + r, 3); if (f(ml) < f(mr)) { r = mr; } else { l = ml; } } OUT(f(l + 1)); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t; IN(t); while (t--) { Solve(); } } #elif __INCLUDE_LEVEL__ == 1 #include template concept MyRange = std::ranges::range && !std::convertible_to; template concept MyTuple = std::__is_tuple_like::value && !MyRange; namespace std { istream& operator>>(istream& is, MyRange auto&& r) { for (auto&& e : r) is >> e; return is; } istream& operator>>(istream& is, MyTuple auto&& t) { apply([&](auto&... xs) { (is >> ... >> xs); }, t); return is; } ostream& operator<<(ostream& os, MyRange auto&& r) { auto sep = ""; for (auto&& e : r) os << exchange(sep, " ") << e; return os; } ostream& operator<<(ostream& os, MyTuple auto&& t) { auto sep = ""; apply([&](auto&... xs) { ((os << exchange(sep, " ") << xs), ...); }, t); return os; } } // namespace std using namespace std; #define LAMBDA2(x, y, ...) ([&](auto&& x, auto&& y) -> decltype(auto) { return __VA_ARGS__; }) #define DivFloor(...) LAMBDA2(x, y, x / y - ((x ^ y) < 0 && x % y != 0))(__VA_ARGS__) #define DivCeil(...) LAMBDA2(x, y, x / y + ((x ^ y) >= 0 && x % y != 0))(__VA_ARGS__) #define IN(...) (cin >> forward_as_tuple(__VA_ARGS__)) #define OUT(...) (cout << forward_as_tuple(__VA_ARGS__) << '\n') #endif // __INCLUDE_LEVEL__ == 1