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;
}
相关推荐
Omics Pro1 小时前
Cell封面|衰老生物学开源AI工具包
数据库·人工智能·算法·机器学习·自然语言处理
UIU1144 小时前
递归算法与汉诺塔
c++·学习·算法·c#·递归
用户979984807189 小时前
200 行代码写一个能跑的 AI Agent:不依赖任何框架,只靠 tool-calling 原理
算法
threerocks9 小时前
【Muse实战】X 流量作战室搭建保姆级教程 - 拥有你自己的运营团队
算法
GreenTea9 小时前
深度拆解 ScienceBuddy:如何用“双层递归自进化”构建高可靠科研 Agent Harness
前端·后端·算法
花椒技术9 小时前
2.46 秒生成 5 秒视频:拆解 H3 Max 的模型、推理栈与硬件协同
算法·音视频开发·视频编码
vivo互联网技术9 小时前
ART:妆容迁移框架,重新定义高保真妆容迁移 | ECCV 2026
人工智能·算法·图像识别
用户0441440924499 小时前
卫星信号模拟器里的四个坐标转换公式
算法
橘和柠9 小时前
阿里 open-code-review (AI代码审查工具)实战:安装、四层规则链、自定义规则格式与实测避坑
算法·面试
得物技术9 小时前
别再只卷向量检索了,得物交易搜索如何用“生成式”实现召回范式跃迁?
人工智能·算法·llm