个人赛 2019-10-11

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/weixin_44056753/article/details/102510865

A - BowWow and the Timetable

In the city of Saint Petersburg, a day lasts for 2^100 minutes. From the main station of Saint Petersburg, a train departs after 1 minute, 4 minutes, 16 minutes, and so on; in other words, the train departs at time 4k for each integer k≥0. Team BowWow has arrived at the station at the time s and it is trying to count how many trains have they missed; in other words, the number of trains that have departed strictly before time s. For example if s=20, then they missed trains which have departed at 1, 4 and 16. As you are the only one who knows the time, help them!

Note that the number s will be given you in a binary representation without leading zeroes.

Input

The first line contains a single binary number s (0≤s<2100) without leading zeroes.

Output

Output a single number — the number of trains which have departed strictly before the time s.

Examples

Input

100000000

Output

4

Input

101

Output

2

Input

10100

Output

3

Note

In the first example 1000000002=25610, missed trains have departed at 1, 4, 16 and 64.

In the second example 1012=510, trains have departed at 1 and 4.

The third example is explained in the statements.

思路

水题+1,但是要注意因为二进制串最大达到2^100,所以不能化成十进制按题意模拟,其实只要细心分心就可以直接在二进制串上计算。


#include<iostream>
#include<string>
#include<stack>
#include<vector>
#include<cstdio>
#include<cstring>
#include<map>
#include<queue>
#include<algorithm>
using namespace std;
int main()
{
    string s;
    cin>>s;
    long long ans=0;
    int k=s.size();
    if(s=="0")
        ans=0;
    else
    {
        if((k-1)%2==0)
        {for(int i=1; i<k; i++)
        {
            if(s[i]!='0')
                ans=1;
        }}
        ans=ans+k/2;
    }
    cout<<ans<<endl;
}

B - Mislove Has Lost an Array

Mislove had an array a1, a2, ⋯, an of n positive integers, but he has lost it. He only remembers the following facts about it:

The number of different numbers in the array is not less than l and is not greater than r;
For each array’s element ai either ai=1 or ai is even and there is a number ai2 in the array.
For example, if n=5, l=2, r=3 then an array could be [1,2,2,4,4] or [1,1,1,1,2]; but it couldn’t be [1,2,2,4,8] because this array contains 4 different numbers; it couldn’t be [1,2,2,3,3] because 3 is odd and isn’t equal to 1; and it couldn’t be [1,1,2,2,16] because there is a number 16 in the array but there isn’t a number 162=8.

According to these facts, he is asking you to count the minimal and the maximal possible sums of all elements in an array.

Input

The only input line contains three integers n, l and r (1≤n≤1000, 1≤l≤r≤min(n,20)) — an array’s size, the minimal number and the maximal number of distinct elements in an array.

Output

Output two numbers — the minimal and the maximal possible sums of all elements in an array.

Examples

Input

4 2 2

Output

5 7

Input

5 1 5

Output

5 31

Note

In the first example, an array could be the one of the following: [1,1,1,2], [1,1,2,2] or [1,2,2,2]. In the first case the minimal sum is reached and in the last case the maximal sum is reached.

In the second example, the minimal sum is reached at the array [1,1,1,1,1], and the maximal one is reached at the array [1,2,4,8,16].

思路

水题+2,按照题意贪心的模拟,最后求和

#include<iostream>
#include<string>
#include<stack>
#include<vector>
#include<cstdio>
#include<cstring>
#include<map>
#include<queue>
#include<algorithm>
using namespace std;
int _pow(int n,int r)
{ int ans=1;
    if(r==0)
   return ans;
    while(r--)
        ans*=n;
        return ans;
}
int main()
{
    int n,l,r;
    cin>>n>>l>>r;
    int _min=min(l,r),_max=max(l,r);
    int ans1,ans2;
    ans1=-2*(1-_pow(2,_min-1))+1;
    ans1+=n-_min;
    ans2=-2*(1-_pow(2,_max-1))+1;
    ans2+=(n-_max)*_pow(2,_max-1);
    cout<<ans1<<" "<<ans2<<endl;
}


猜你喜欢

转载自blog.csdn.net/weixin_44056753/article/details/102510865