A. Riptide

time limit per test

1 second

memory limit per test

256 megabytes

Alice, Bob, and Charlie are playing a game with tokens. They start with a, b, and c tokens, respectively.

The game is played in rounds. Before the beginning of each round, they check the number of tokens everyone has:

  • If any two players have the exact same number of tokens, the game immediately ends.
  • Otherwise, the round begins, all three players have a strictly different number of tokens. The player with the strictly most tokens gives exactly 1 token to the player with the strictly fewest tokens.

Given the starting tokens a, b, and c, determine exactly how many rounds the game will last before it ends.

Input

The first line contains a single integer t (1≤t≤103) --- the number of test cases.

Each test case consists of a single line containing three integers a, b, and c (1≤a,b,c≤10).

Output

For each test case, output a single integer --- the number of rounds the game will last before it ends.

Example

Input

Copy

复制代码

6

1 2 3

4 6 1

3 3 7

1 7 10

6 1 9

1 1 1

Output

Copy

复制代码

1

2

0

3

3

0

Note

In the first test case:

  • No two players have the same number of tokens.
  • Charlie has the most tokens (3 tokens), and Alice has the fewest tokens (1 token). Therefore, Charlie gives Alice a token.
  • Now, Alice has 2 tokens, Bob has 2 tokens, and Charlie has 2 tokens. Since there are two players (or more) with the same number of tokens, the game ends.

The game ended after 1 round, so the answer is 1.

In the second test case, the game is played as follows:

  • Bob gives Charlie a token, now Alice has 4 tokens, Bob has 5 tokens, and Charlie has 2 tokens.
  • Bob gives Charlie a token, now Alice has 4 tokens, Bob has 4 tokens, and Charlie has 3 tokens. Since two players have the same number of tokens, the game ends.

The game lasted 2 rounds.

In the third test case, two players already have the same number of tokens. So the answer is 0 since no rounds were played.

解题说明:水题,找到差值最小的两个数即可。

cpp 复制代码
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) 
    {
        int a, b, c, count = 0;
        scanf("%d%d%d", &a, &b, &c);
        count = abs(a - b);
        if (count > abs(b - c)) 
        {
            count = abs(b - c);
        }
        if (count > abs(c - a))
        {
            count = abs(c - a);
        }
        printf("%d\n", count);
    }
    return 0;
}
相关推荐
青少儿编程课堂14 小时前
第十八届蓝桥杯青少组图形化真题:校园分形雪花绘制解析(全国青少年信息素养大赛·电子学会图形化考级冲刺)
c++·python·算法·bfs·信息学竞赛
geovindu16 小时前
python: KNeighborsClassifier K
开发语言·后端·python·算法
让我们一起加油好吗18 小时前
【数据结构】线段树详解
数据结构·c++·算法·线段树·洛谷
凌冰_18 小时前
数据结构 - 队列(五)
数据结构·算法·软件工程
让我们一起加油好吗19 小时前
【数据结构】ST 表
数据结构·c++·算法·动态规划·洛谷·st表
让我们一起加油好吗20 小时前
【算法刷题】LeetCode 力扣 Hot 100 刷题记录
数据结构·c++·算法·leetcode·面试·笔试
lisw051 天前
稀疏算法概述!
算法·机器人·无人机
YLCHUP1 天前
【括号匹配+dp优化】题解:双端括号(brackets)_动态规划_状态优化_数学建模_贪心_性质挖掘_STLmap_C++算法竞赛
数据结构·c++·笔记·算法·数学建模·贪心算法·动态规划
郝学胜-神的一滴1 天前
Effective STL 条款09:慎重选择删除元素的方法
开发语言·网络·数据结构·c++·算法·stl