# A. Joysticks

time limit per test：1 second

memory limit per test：256 megabytes

input：standard input

output：standard output

Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at a1 percent and second one is charged at a2 percent. You can connect charger to a joystick only at the beginning of each minute. In one minute joystick either discharges by 2 percent (if not connected to a charger) or charges by 1 percent (if connected to a charger).

Game continues while both joysticks have a positive charge. Hence, if at the beginning of minute some joystick is charged by 1 percent, it has to be connected to a charger, otherwise the game stops. If some joystick completely discharges (its charge turns to 0), the game also stops.

Determine the maximum number of minutes that game can last. It is prohibited to pause the game, i. e. at each moment both joysticks should be enabled. It is allowed for joystick to be charged by more than 100 percent.

Input

The first line of the input contains two positive integers a1 and a2 (1 ≤ a1, a2 ≤ 100), the initial charge level of first and second joystick respectively.

Output

Output the only integer, the maximum number of minutes that the game can last. Game continues until some joystick is discharged.

Examples

Input

`3 5`

Output

`6`

Input

`4 4`

Output

`5`

Note

In the first sample game lasts for 6 minute by using the following algorithm:

• at the beginning of the first minute connect first joystick to the charger, by the end of this minute first joystick is at 4%, second is at 3%;
• continue the game without changing charger, by the end of the second minute the first joystick is at 5%, second is at 1%;
• at the beginning of the third minute connect second joystick to the charger, after this minute the first joystick is at 3%, the second one is at 2%;
• continue the game without changing charger, by the end of the fourth minute first joystick is at 1%, second one is at 3%;
• at the beginning of the fifth minute connect first joystick to the charger, after this minute the first joystick is at 2%, the second one is at 1%;
• at the beginning of the sixth minute connect second joystick to the charger, after this minute the first joystick is at 0%, the second one is at 2%.

After that the first joystick is completely discharged and the game is stopped.

``` 1 #include <bits/stdc++.h>
2 using namespace std;
3 int main()
4 {
5     int a1,a2;
6     cin>>a1>>a2;
7     int ans=0;
8     while(1)
9     {
10         if(a1<=a2)
11             swap(a1,a2);
12         if(a1<2)
13             break;
14         a1-=2;
15         a2+=1;
16         ans++;
17         if(a1<=0||a2<=0)
18             break;
19     }
20     cout<<ans<<endl;
21 }```

# B. Beautiful Paintings

time limit per test：1 second

memory limit per test：256 megabytes

input：standard input

output：standard output

There are n pictures delivered for the new exhibition. The i-th painting has beauty ai. We know that a visitor becomes happy every time he passes from a painting to a more beautiful one.

We are allowed to arranged pictures in any order. What is the maximum possible number of times the visitor may become happy while passing all pictures from first to last? In other words, we are allowed to rearrange elements of a in any order. What is the maximum possible number of indices i (1 ≤ i ≤ n - 1), such that ai + 1 > ai.

Input

The first line of the input contains integer n (1 ≤ n ≤ 1000) — the number of painting.

The second line contains the sequence a1, a2, ..., an (1 ≤ ai ≤ 1000), where ai means the beauty of the i-th painting.

Output

Print one integer — the maximum possible number of neighbouring pairs, such that ai + 1 > ai, after the optimal rearrangement.

Examples

Input

```5
20 30 10 50 40```

Output

`4`

Input

```4
200 100 100 200```

Output

`2`

Note

In the first sample, the optimal order is: 10, 20, 30, 40, 50.

In the second sample, the optimal order is: 100, 200, 100, 200.

``` 1 #include <bits/stdc++.h>
2 using namespace std;
3 int a[1010];
4 int main()
5 {
6     int n,x;
7     int ans=0,t=-1;
8     cin>>n;
9     for(int i=1;i<=n;i++)
10     {
11         cin>>x;
12         a[x]++;
13     }
14     for(int i=1;i<=1000;i++)
15         t=max(t,a[i]);
16     cout<<n-t<<endl;
17     return 0;
18 }```

# C. Watchmen

time limit per test：3 seconds

memory limit per test：256 megabytes

input：standard input

output：standard output

Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are n watchmen on a plane, the i-th watchman is located at point (xi, yi).

They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan considers the distance between watchmen i and j to be |xi - xj| + |yi - yj|. Daniel, as an ordinary person, calculates the distance using the formula

.

The success of the operation relies on the number of pairs (i, j) (1 ≤ i < j ≤ n), such that the distance between watchman i and watchmen j calculated by Doctor Manhattan is equal to the distance between them calculated by Daniel. You were asked to compute the number of such pairs.

Input

The first line of the input contains the single integer n (1 ≤ n ≤ 200 000) — the number of watchmen.

Each of the following n lines contains two integers xi and yi (|xi|, |yi| ≤ 109).

Some positions may coincide.

Output

Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel.

Examples

Input

```3
1 1
7 5
1 5```

Output

`2`

Input

```6
0 0
0 1
0 2
-1 1
0 1
1 1```

Output

`11`

Note

In the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and

for Daniel. For pairs (1, 1), (1, 5) and (7, 5), (1, 5) Doctor Manhattan and Daniel will calculate the same distances.

``` 1 #include <bits/stdc++.h>
2 using namespace std;
3 typedef long long ll;
4 ll n,x,y,ans;
5 map<ll,ll> a,b;
6 map<pair<ll,ll>,ll> c;
7 int main()
8 {
9     for(cin>>n;cin>>x>>y;)
10         ans+=(a[x]++)+(b[y]++)-(c[make_pair(x,y)]++);
11     cout<<ans<<endl;
12     return 0;
13 }```

``` 1 #include <bits/stdc++.h>
2 using namespace std;
3 struct Node
4 {
5     int a,b;
6 }num[200100];
7 bool cmp1(Node a,Node b)        //第一次排序
8 {
9     if(a.a==b.a)
10     {
11         return a.b<b.b;
12     }
13     return a.a<b.a;
14 }
15 bool cmp2(Node a,Node b)    //第二次排序
16 {
17     if(a.b==b.b)
18     {
19         return a.a<b.a;
20     }
21     return a.b<b.b;
22 }
23 int main()
24 {
25     int n;
26     while(~scanf("%d",&n))
27     {
28         for(int i=0;i<n;i++)
29         {
30             scanf("%d%d",&num[i].a,&num[i].b);
31         }
32         sort(num,num+n,cmp1);
33         __int64 temp=1;       //几个是相同的
34         __int64 tt=1;         //重复的个数
35         __int64 res=0;
36         for(int i=1;i<n;i++)
37         {
38             if(num[i].a==num[i-1].a)      //xi == xi-1
39             {
40                 temp++;
41                 if(num[i].b==num[i-1].b)
42                 {
43                     tt++;
44                 }
45                 else
46                 {
47                     res-=tt*(tt-1)/2;   //去重
48                     tt=1;
49                 }
50             }
51             else
52             {
53                 res+=temp*(temp-1)/2;       //排列组合，从temp个两两组合的个数
54                 res-=tt*(tt-1)/2;
55                 tt=1;
56                 temp=1;
57             }
58         }
59         if(tt!=1)       //判断结尾是不是有些没有去重
60         {
61             res-=tt*(tt-1)/2;
62         }
63         tt=1;
64         if(temp!=1)        //判断结尾有些是不是没有计算
65         {
66             res+=temp*(temp-1)/2;
67         }
68         temp=1;
69         sort(num,num+n,cmp2);       //第二次排序
70         for(int i=1;i<n;i++)
71         {
72             if(num[i].b==num[i-1].b)
73             {
74                 temp++;
75             }
76             else
77             {
78                 res+=temp*(temp-1)/2;
79                 temp=1;
80             }
81         }
82         if(temp!=1)
83         {
84             res+=temp*(temp-1)/2;
85         }
86         printf("%I64d\n",res);
87     }
88     return 0;
89 }```

0 条评论

• ### Codeforces Round #300(A.【字符串，多方法】，B.【思维题】，C.【贪心,数学】)

A. Cutting Banner time limit per test：2 seconds memory limit per test：256 megaby...

• ### HDU 1013 Digital Roots【字符串，水】

Digital Roots Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/3276...

• ### Codeforces 810C Do you want a date?(数学，前缀和)

C. Do you want a date? time limit per test：2 seconds memory limit per test：256 m...

• ### Oops错误

在at91rm9200下写了一个spi的驱动，加载后，运行测试程序时，蹦出这么个吓人的东西： Unable to handle kernel paging r...

• ### 统计学中的区间估计

统计学中有两大分支——描述性统计学（description stats）和推断性统计学（inference stats）。 推断性统计学中，很重要的一点就是...

• ### HDOJ 1163 Eddy's digital Roots（九余数定理的应用）

Problem Description The digital root of a positive integer is found by summing...

• ### Codeforces Round #300(A.【字符串，多方法】，B.【思维题】，C.【贪心,数学】)

A. Cutting Banner time limit per test：2 seconds memory limit per test：256 megaby...

• ### hdu 1805Expressions（二叉树构造的后缀表达式）

Expressions Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 ...