#define DEBUG 1 #include #define loop(n) for (lint ngtkana_is_a_genius = 0; ngtkana_is_a_genius < lint(n); ngtkana_is_a_genius++) #define rep(i, begin, end) for (lint i = lint(begin); (i) < lint(end); i++) #define all(v) v.begin(), v.end() #define rand(l, r) std::uniform_int_distribution<>(l, r)(mt) using lint = long long; auto mt = std::mt19937_64(std::random_device{}()); auto cmn = [](auto&& a, auto b){ if (a > b) {a = b; return true;} return false; }; auto cmx = [](auto&& a, auto b){ if (a < b) {a = b; return true;} return false; }; void debug_impl() { std::cerr << std::endl; } template void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); } #if DEBUG #define debug(...)\ do {\ std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\ debug_impl(__VA_ARGS__);\ std::cerr << std::noboolalpha;\ } while (false) #else #define debug(...) {} #endif int main() { std::cin.tie(0); std::cin.sync_with_stdio(false); int inf = std::numeric_limits::max(); int q; std::cin >> q; loop(q) { int a, b, c; std::cin >> a >> b >> c; int ans = -2; if (a > c) std::swap(a, c); if (a==c) { if (a==b) { ans = 3 <= a ? 3 : -1; } else if (b==a-1) { ans = 2 <= b ? 2 : -1; } else { ans = 2 <= a ? 1 : -1; } } else { if (b < a || c < b) { ans = 0; } else { int now = inf; if (2 <= a) cmn(now, b - a + 1); if (2 <= b - a) cmn(now, c - b + 1); if (now==inf) { ans = -1; } else { ans = now; } } } std::cout << ans << std::endl; } return 0; } /* a <= c としてよいです。 a = c の場合: 3 つとも同じ場合は、値が 3 以上なら答えは 3、2以下なら不可能です。 b = a - 1 の場合は、 b が 2 以上なら a, b をそれぞれ 1 ずつ下げるので 2、1 なら不可能です。 その他の場合は、a だけ下げれば良いので、2<=a ? 1 : -1 です。 a < c の場合: b < a or a < c の場合は、もともと門松なので、0 です。 それ以外の場合は、b か c の好きな方を下げます。 2 <= a のとき、b を a - 1 まで下げられるので、b - a + 1 が候補です。 2 <= b - a のとき、c を b - 1 まで下げられるので、c - b + 1 が候補です。 どちらもできないときは、詰んでいます。 */