cf----2019-11-25(USB vs. PS/2,Artsem and Saunders,Code obfuscation)

删除回忆录丶 提交于 2019-11-25 23:51:52

如果可以,可以陪你千年不老,千年只想眷顾你倾城一笑;如果愿意,愿意陪你永世不离,永世只愿留恋你青丝白衣。

Due to the increase in the number of students of Berland State University it was decided to equip a new computer room. You were given the task of buying mouses, and you have to spend as little as possible. After all, the country is in crisis!

The computers bought for the room were different. Some of them had only USB ports, some — only PS/2 ports, and some had both options.

You have found a price list of a certain computer shop. In it, for m mouses it is specified the cost and the type of the port that is required to plug the mouse in (USB or PS/2). Each mouse from the list can be bought at most once.

You want to buy some set of mouses from the given price list in such a way so that you maximize the number of computers equipped with mouses (it is not guaranteed that you will be able to equip all of the computers), and in case of equality of this value you want to minimize the total cost of mouses you will buy.

Input

The first line contains three integers ab and c (0 ≤ a, b, c ≤ 105)  — the number of computers that only have USB ports, the number of computers, that only have PS/2 ports, and the number of computers, that have both options, respectively.

The next line contains one integer m (0 ≤ m ≤ 3·105)  — the number of mouses in the price list.

The next m lines each describe another mouse. The i-th line contains first integer vali(1 ≤ vali ≤ 109)  — the cost of the i-th mouse, then the type of port (USB or PS/2) that is required to plug the mouse in.

Output

Output two integers separated by space — the number of equipped computers and the total cost of the mouses you will buy.

Example

input

Copy

2 1 1
4
5 USB
6 PS/2
3 PS/2
7 PS/2

output

Copy

3 14

Note

In the first example you can buy the first three mouses. This way you will equip one of the computers that has only a USB port with a USB mouse, and the two PS/2 mouses you will plug into the computer with PS/2 port and the computer with both ports.

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
vector<pair<int, string> >v;
int a, b, c, m, yx;
string na;
string n1 = "USB";
string n2 = "PS/2";
int main()
{
    scanf("%d%d%d", &a, &b, &c);
    scanf("%d", &m);
    for (int i = 1; i <= m; i++)
    {
        cin >> yx >> na;
        v.push_back({ yx,na });
    }
    sort(v.begin(), v.end());
    int ct = 0;
    ll jg = 0;
    for (int i = 0; i < m; i++)
    {
        if (a&&v[i].second == n1)
        {
            ct++;
            a--;
            jg += v[i].first;
            continue;
        }
        if (b&&v[i].second == n2)
        {
            ct++;
            b--;
            jg += v[i].first;
            continue;
        }
        if (c)
        {
            ct++;
            c--;
            jg += v[i].first;
            continue;
        }
    }
    printf("%d %lld\n", ct, jg);
    return 0;
}

Artsem has a friend Saunders from University of Chicago. Saunders presented him with the following problem.

Let [n] denote the set {1, ..., n}. We will also write f: [x] → [y] when a function f is defined in integer points 1, ..., x, and all its values are integers from 1 to y.

Now then, you are given a function f: [n] → [n]. Your task is to find a positive integer m, and two functions g: [n] → [m], h: [m] → [n], such that g(h(x)) = x for all , and h(g(x)) = f(x) for all , or determine that finding these is impossible.

Input

The first line contains an integer n (1 ≤ n ≤ 105).

The second line contains n space-separated integers — values f(1), ..., f(n) (1 ≤ f(i) ≤ n).

Output

If there is no answer, print one integer -1.

Otherwise, on the first line print the number m (1 ≤ m ≤ 106). On the second line print nnumbers g(1), ..., g(n). On the third line print m numbers h(1), ..., h(m).

If there are several correct answers, you may output any of them. It is guaranteed that if a valid answer exists, then there is an answer satisfying the above restrictions.

Examples

input

Copy

3
1 2 3

output

Copy

3
1 2 3
1 2 3

input

Copy

3
2 2 2

output

Copy

1
1 1 1
2

input

Copy

2
2 1

output

Copy

-1
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
int f[100010],g[100010],h[100010];
int n,ct=1,m,zh,flag=1;
map<int,int>mp;
bool vis[100010];
int main()
{
    scanf("%d",&n);
    for(int i=1; i<=n; i++)
    {
        scanf("%d",&f[i]);
        if(f[i]==i)
            vis[f[i]]=1;
    }
    for(int i=1; i<=n; i++)
        if(vis[i]==1)
        {
            m++;
            h[m]=i;
            mp[i]=m;
        }
    for(int i=1; i<=n; i++)
    {
        if(mp[f[i]]>0)
            g[i]=mp[f[i]];
        else
            flag=0;
    }
    if(flag)
    {
        printf("%d\n",m);
        for(int i=1; i<=n; i++)
        {
            printf("%d",g[i]);
            if(i==n)
                printf("\n");
            else
                printf(" ");
        }
        for(int i=1; i<=m; i++)
        {
            printf("%d",h[i]);
            if(i==m)
                printf("\n");
            else
                printf(" ");
        }
    }
    else
        printf("-1\n");
    return 0;
}

Kostya likes Codeforces contests very much. However, he is very disappointed that his solutions are frequently hacked. That's why he decided to obfuscate (intentionally make less readable) his code before upcoming contest.

To obfuscate the code, Kostya first looks at the first variable name used in his program and replaces all its occurrences with a single symbol a, then he looks at the second variable name that has not been replaced yet, and replaces all its occurrences with b, and so on. Kostya is well-mannered, so he doesn't use any one-letter names before obfuscation. Moreover, there are at most 26 unique identifiers in his programs.

You are given a list of identifiers of some program with removed spaces and line breaks. Check if this program can be a result of Kostya's obfuscation.

Input

In the only line of input there is a string S of lowercase English letters (1 ≤ |S| ≤ 500) — the identifiers of a program with removed whitespace characters.

Output

If this program can be a result of Kostya's obfuscation, print "YES" (without quotes), otherwise print "NO".

Examples

input

Copy

abacaba

output

Copy

YES

input

Copy

jinotega

output

Copy

NO

Note

In the first sample case, one possible list of identifiers would be "number string number character number string number". Here how Kostya would obfuscate the program:

  • replace all occurences of number with a, the result would be "a string a character a string a",
  • replace all occurences of string with b, the result would be "a b a character a b a",
  • replace all occurences of character with c, the result would be "a b a c a b a",
  • all identifiers have been replaced, thus the obfuscation is finished.
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
char a[510];
int vis[510];
int main()
{
    while(~scanf("%s",a))
    {
        memset(vis,0,sizeof(vis));
        int n=strlen(a);
        int xz=1;
        int flag=0;
        for(int i=0; i<n; i++)
        {
            if(vis[i]==0)
            {
                if(xz!=a[i]-'a'+1)flag=1;
                else
                {
                    for(int j=i; j<n; j++)
                        if(a[j]==a[i])
                            vis[j]++;
                }
                xz++;
            }
        }
        if(flag==1)
            printf("NO\n");
        else
            printf("YES\n");
    }
    return 0;
}

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!