20211025

目录

A - Elections

题意:

思路:

代码:

B - Make it Divisible by 25

题意:

思路:

代码:

C - Save More Mice

题意:

思路:

代码:

D - All are Same

题意:

思路:

代码:


A - Elections

The elections in which three candidates participated have recently ended. The first candidate received aa votes, the second one received bb votes, the third one received cc votes. For each candidate, solve the following problem: how many votes should be added to this candidate so that he wins the election (i.e. the number of votes for this candidate was strictly greater than the number of votes for any other candidate)?

Please note that for each candidate it is necessary to solve this problem independently, i.e. the added votes for any candidate do not affect the calculations when getting the answer for the other two candidates.

Input

The first line contains one integer tt (1 \le t \le 10^41≤t≤104) — the number of test cases. Then tt test cases follow.

Each test case consists of one line containing three integers aa, bb, and cc (0 \le a,b,c \le 10^90≤a,b,c≤109).

Output

For each test case, output in a separate line three integers AA, BB, and CC (A, B, C \ge 0A,B,C≥0) separated by spaces — the answers to the problem for the first, second, and third candidate, respectively.

Example

Input

5
0 0 0
10 75 15
13 13 17
1000 0 0
0 1000000000 0

Output

1 1 1
66 0 61
5 5 0
0 1001 1001
1000000001 0 1000000001

题意:

有三个候选人分别得到了a,b,c票,问每个候选人需要加多少票才能使票数严格大于另外两个的原票数。

思路:

找到和另外两个人的最大差值,如果是非负数,加一就是答案;如果是负数就输出0

代码:

#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
int main()
{
    ll t;
    cin>>t;
    while(t--)
    {
        ll a,b,c;
        cin>>a>>b>>c;
        ll da=max(b-a,c-a);
        ll db=max(a-b,c-b);
        ll dc=max(a-c,b-c);
        if(da>=0)
            cout<<da+1<<" ";
        else
            cout<<0<<" ";
        if(db>=0)
            cout<<db+1<<" ";
        else
            cout<<0<<" ";
        if(dc>=0)
            cout<<dc+1<<endl;
        else
            cout<<0<<endl;
    }

}

B - Make it Divisible by 25

It is given a positive integer nn. In 11 move, one can select any single digit and remove it (i.e. one selects some position in the number and removes the digit located at this position). The operation cannot be performed if only one digit remains. If the resulting number contains leading zeroes, they are automatically removed.

E.g. if one removes from the number 3292532925 the 33-rd digit, the resulting number will be 32253225. If one removes from the number 2009905020099050 the first digit, the resulting number will be 9905099050 (the 22 zeroes going next to the first digit are automatically removed).

What is the minimum number of steps to get a number such that it is divisible by 2525 and positive? It is guaranteed that, for each nn occurring in the input, the answer exists. It is guaranteed that the number nn has no leading zeros.

Input

The first line contains one integer tt (1 \le t \le 10^41≤t≤104) — the number of test cases. Then tt test cases follow.

Each test case consists of one line containing one integer nn (25 \le n \le 10^{18}25≤n≤1018). It is guaranteed that, for each nn occurring in the input, the answer exists. It is guaranteed that the number nn has no leading zeros.

Output

For each test case output on a separate line an integer kk (k \ge 0k≥0) — the minimum number of steps to get a number such that it is divisible by 2525 and positive.

Example

Input

5
100
71345
3259
50555
2050047

Output

0
3
1
3
2

Note

In the first test case, it is already given a number divisible by 2525.

In the second test case, we can remove the digits 11, 33, and 44 to get the number 7575.

In the third test case, it's enough to remove the last digit to get the number 325325.

In the fourth test case, we can remove the three last digits to get the number 5050.

In the fifth test case, it's enough to remove the digits 44 and 77.

题意:

给你一个数,让你用最少的操作使得它能被25整除,每次操作可以删除这个数的任意一位。

思路:

一个数肯定可以拆分成n*100+m(n>=0,m<100),n*100肯定能被25整除,只要看m即可,所以可以被25整除的数最后两位只能是00,25,50,75;枚举每一种情况取最小操作数即可。

代码:

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
int main()
{
    ll t;
    cin>>t;
    while(t--)
    {
        string s;
        cin>>s;
        ll ans=1e18;
        reverse(s.begin(),s.end());
        ll k=0;
        ll flag=0;
        for(ll i=0;i<s.size();i++)
        {
            if(s[i]!='0')
            {
                k+=1;
            }
            else
            {
                for(ll j=i+1;j<s.size();j++)
                {
                    if(s[j]!='0')
                    {
                        k+=1;
                    }
                    else
                    {
                        flag=1;
                        break;
                    }
                }
                break;
            }
        }
        if(flag)
        {
            ans=min(ans,k);
        }
        k=0;
        flag=0;
        for(ll i=0;i<s.size();i++)
        {
            if(s[i]!='0')
            {
                k+=1;
            }
            else
            {
                for(ll j=i+1;j<s.size();j++)
                {
                    if(s[j]!='5')
                    {
                        k+=1;
                    }
                    else
                    {
                        flag=1;
                        break;
                    }
                }
                break;
            }
        }
        if(flag)
        {
            ans=min(ans,k);
        }
        k=0;
        flag=0;
        for(ll i=0;i<s.size();i++)
        {
            if(s[i]!='5')
            {
                k+=1;
            }
            else
            {
                for(ll j=i+1;j<s.size();j++)
                {
                    if(s[j]!='2')
                    {
                        k+=1;
                    }
                    else
                    {
                        flag=1;
                        break;
                    }
                }
                break;
            }
        }
        if(flag)
        {
            ans=min(ans,k);
        }
        k=0;
        flag=0;
        for(ll i=0;i<s.size();i++)
        {
            if(s[i]!='5')
            {
                k+=1;
            }
            else
            {
                for(ll j=i+1;j<s.size();j++)
                {
                    if(s[j]!='7')
                    {
                        k+=1;
                    }
                    else
                    {
                        flag=1;
                        break;
                    }
                }
                break;
            }
        }
        if(flag)
        {
            ans=min(ans,k);
        }
        cout<<ans<<endl;
    }
}

C - Save More Mice

There are one cat, kk mice, and one hole on a coordinate line. The cat is located at the point 00, the hole is located at the point nn. All mice are located between the cat and the hole: the ii-th mouse is located at the point x_ixi​ (0 < x_i < n0<xi​<n). At each point, many mice can be located.

In one second, the following happens. First, exactly one mouse moves to the right by 11. If the mouse reaches the hole, it hides (i.e. the mouse will not any more move to any point and will not be eaten by the cat). Then (after that the mouse has finished its move) the cat moves to the right by 11. If at the new cat's position, some mice are located, the cat eats them (they will not be able to move after that). The actions are performed until any mouse hasn't been hidden or isn't eaten.

In other words, the first move is made by a mouse. If the mouse has reached the hole, it's saved. Then the cat makes a move. The cat eats the mice located at the pointed the cat has reached (if the cat has reached the hole, it eats nobody).

Each second, you can select a mouse that will make a move. What is the maximum number of mice that can reach the hole without being eaten?

Input

The first line contains one integer tt (1 \le t \le 10^41≤t≤104) — the number of test cases. Then tt test cases follow.

Each test case consists of two lines. The first line contains two integers nn and kk (2 \le n \le 10^92≤n≤109, 1 \le k \le 4 \cdot 10^51≤k≤4⋅105). The second line contains kk integers x_1, x_2, \dots x_kx1​,x2​,…xk​ (1 \le x_i < n1≤xi​<n) — the initial coordinates of the mice.

It is guaranteed that the sum of all kk given in the input doesn't exceed 4 \cdot 10^54⋅105.

Output

For each test case output on a separate line an integer mm (m \ge 0m≥0) — the maximum number of mice that can reach the hole without being eaten.

Example

Input

3
10 6
8 7 5 4 9 4
2 8
1 1 1 1 1 1 1 1
12 11
1 2 3 4 5 6 7 8 9 10 11

Output

3
1
4

题意:

有一个横坐标,n为老鼠洞的坐标,k为老鼠个数,输入k个老鼠的坐标,猫在坐标0处,每次可以先让一个老鼠前进一步,然后猫再前进一步,猫和老鼠在同一个位置老鼠会被吃掉,老鼠到了老鼠洞就安全了,问最多存活多少个老鼠。

思路:

每次优先让离老鼠洞最近的老鼠回洞,先判断猫是否经过了当前老鼠的位置,经过说明这个老鼠已经die了,没经过就让老鼠回洞并且更新猫的位置。

代码:
 

#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
ll a[500000];
int main()
{
    ll t;
    cin>>t;
    while(t--)
    {
        ll n,k;
        cin>>n>>k;
        for(ll i=0;i<k;i++)
        {
            cin>>a[i];
        }
        sort(a,a+k);
        ll ans=0;
        ll res=0;
        for(ll i=k-1;i>=0;i--)
        {
            if(res<a[i])
            {
                res+=n-a[i];
                ans+=1;
            }
            else
                continue;

        }
        cout<<ans<<endl;

    }

}

D - All are Same

This problem is a simplified version of D2, but it has significant differences, so read the whole statement.

Polycarp has an array of nn (nn is even) integers a_1, a_2, \dots, a_na1​,a2​,…,an​. Polycarp conceived of a positive integer kk. After that, Polycarp began performing the following operations on the array: take an index ii (1 \le i \le n1≤i≤n) and reduce the number a_iai​ by kk.

After Polycarp performed some (possibly zero) number of such operations, it turned out that all numbers in the array became the same. Find the maximum kk at which such a situation is possible, or print -1−1 if such a number can be arbitrarily large.

Input

The first line contains one integer tt (1 \le t \le 101≤t≤10) — the number of test cases. Then tt test cases follow.

Each test case consists of two lines. The first line contains an even integer nn (4 \le n \le 404≤n≤40) (nn is even). The second line contains nn integers a_1, a_2, \dots a_na1​,a2​,…an​ (-10^6 \le a_i \le 10^6−106≤ai​≤106).

It is guaranteed that the sum of all nn specified in the given test cases does not exceed 100100.

Output

For each test case output on a separate line an integer kk (k \ge 1k≥1) — the maximum possible number that Polycarp used in operations on the array, or -1−1, if such a number can be arbitrarily large.

Example

Input

3
6
1 5 3 1 1 5
8
-1 0 1 -1 0 1 -1 0
4
100 -1000 -1000 -1000

Output

2
1
1100

题意:

给你n个数,现在你要找到一个最大的k,使得:每个数可以减任意个k最终使得所有数相等。如果k可以无限大就输出-1。

思路:

所有数都一样就输出-1。不一样就先找到最小的那个数,然后得到其他数和最小的数的差值,对所有的差值取最大公约数gcd即可。

代码:

#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b)
{
    return b>0?gcd(b,a%b):a;
}
ll a[100];
ll cha[100];
int main()
{
    ll t;
    cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        for(ll i=0;i<n;i++)
        {
            cin>>a[i];
        }
        sort(a,a+n);
        int flag=0;
        for(ll i=0;i<n;i++)
        {
            cha[i]=a[i]-a[0];
            if(cha[i]!=0)
                flag=1;
        }
        if(flag==0)
        {
            cout<<-1<<endl;
            continue;
        }

        ll ans=cha[1];
        for(int i=2;i<n;i++)
        {
            ans=gcd(ans,cha[i]);
        }
        cout<<ans<<endl;
    }

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值