蓝桥训练6

一、Codehorses T-shirts

Codehorses has just hosted the second Codehorses Cup. This year, the same as the previous one, organizers are giving T-shirts for the winners.

The valid sizes of T-shirts are either "M" or from 00 to 33 "X" followed by "S" or "L". For example, sizes "M", "XXS", "L", "XXXL" are valid and "XM", "Z", "XXXXL" are not.

There are nn winners to the cup for both the previous year and the current year. Ksenia has a list with the T-shirt sizes printed for the last year cup and is yet to send the new list to the printing office.

Organizers want to distribute the prizes as soon as possible, so now Ksenia is required not to write the whole list from the scratch but just make some changes to the list of the previous year. In one second she can choose arbitrary position in any word and replace its character with some uppercase Latin letter. Ksenia can't remove or add letters in any of the words.

What is the minimal number of seconds Ksenia is required to spend to change the last year list to the current one?

The lists are unordered. That means, two lists are considered equal if and only if the number of occurrences of any string is the same in both lists.

Input

The first line contains one integer nn (1≤n≤1001≤n≤100 ) — the number of T-shirts.

The ii -th of the next nn lines contains aiai — the size of the ii -th T-shirt of the list for the previous year.

The ii -th of the next nn lines contains bibi — the size of the ii -th T-shirt of the list for the current year.

It is guaranteed that all the sizes in the input are valid. It is also guaranteed that Ksenia can produce list bb from the list aa .

Output

Print the minimal number of seconds Ksenia is required to spend to change the last year list to the current one. If the lists are already equal, print 0.

Examples

Input

3
XS
XS
M
XL
S
XS

Output

2

Input

2
XXXL
XXL
XXL
XXXS

Output

1

Input

2
M
XS
XS
M

Output

0

Note

In the first example Ksenia can replace "M" with "S" and "S" in one of the occurrences of "XS" with "L".

In the second example Ksenia should replace "L" in "XXXL" with "S".

In the third example lists are equal.


题意:先后输入数组a[i], b[i],  输出b数组中与a不同的字符串的个数;


C++:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
using namespace std;
int n;
string a[100], b[100];
int flag[100];
int sum = 0;
int main()
{
    memset(flag, 0, sizeof(flag));
    scanf("%d", &n);
    for(int i=0; i<n; i++)
    {
        cin>>a[i];
    }
    for(int i=0; i<n; i++)
    {
        cin>>b[i];
    }
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<n; j++)
        {
                if(b[i]==a[j]&&flag[j]==0)
                {
                    flag[j] = 1;
                    sum++;
                    break;
                }
        }
    }
    int summ = n-sum;
    printf("%d\n", summ);
    return 0;
}

 Java:

import java.util.Arrays;
import java.util.Scanner;
public class Main 
{
	public static int sum;
	public static void main(String[] args) 
	{
		// TODO Auto-generated method stub
		Scanner cin = new Scanner (System.in);
		int []flag = new int[100];
		int summ;
		String []a = new String[100];
		String []b = new String[100];
		int n = cin.nextInt();
		for(int i=0; i<n; i++)
			flag[i] = 0;
		for(int i=0; i<n; i++)
		{
			a[i] = cin.next();//特别注意 不要写成cin.nextLine(会吸收回车)
		}
		for(int i=0; i<n; i++)
		{
			b[i] = cin.next();//
		}
		for(int i=0; i<n; i++)
		{
			for(int j=0; j<n; j++)
			{
				if(b[i].equals(a[j])&&flag[j]==0)
				{
					flag[j] = 1;
					sum++;
					break;
				}
			}
		}
		summ = n-sum;
		System.out.println(summ);
	}
}

二、Delete from the Left 

You are given two strings ss and tt. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by 11. You can't choose a string if it is empty.

For example:

  • by applying a move to the string "where", the result is the string "here",
  • by applying a move to the string "a", the result is an empty string "".

You are required to make two given strings equal using the fewest number of moves. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the initial strings.

Write a program that finds the minimum number of moves to make two given strings ss and tt equal.

Input

The first line of the input contains ss. In the second line of the input contains tt. Both strings consist only of lowercase Latin letters. The number of letters in each string is between 1 and 2⋅1052⋅105, inclusive.

Output

Output the fewest number of moves required. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the given strings.

Examples

Input

test
west

Output

2

Input

codeforces
yes

Output

9

Input

test
yes

Output

7

Input

b
ab

Output

1

Note

In the first example, you should apply the move once to the first string and apply the move once to the second string. As a result, both strings will be equal to "est".

In the second example, the move should be applied to the string "codeforces" 88 times. As a result, the string becomes "codeforces" →→ "es". The move should be applied to the string "yes" once. The result is the same string "yes" →→ "es".

In the third example, you can make the strings equal only by completely deleting them. That is, in the end, both strings will be empty.

In the fourth example, the first character of the second string should be deleted.


题意:从左边删除,一共删除几个字符 才可以使两个字符串相同;

思路:所以可以从右边开始比较,两个字符串到第几个时出现不同;


C++:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
	char s[200010],t[200010];
	cin>>s>>t;
	int sum=0;
    int len1 = strlen(s);
    int len2 = strlen(t);
    int len = min(len1, len2);
    for(int i=0; i<len; i++)
    {
    	if(s[len1-1-i]==t[len2-1-i])
    	{
    		sum++;
		}
		else
        {
            break;
        }
	}
	printf("%d\n",len1+len2-2*sum);
	return 0;
}

Java:

import java.util.Scanner;
public class Main 
{

	public static void main(String[] args) 
	{
		// TODO Auto-generated method stub
		Scanner cin = new Scanner(System.in);
		String s = cin.next();
		String t = cin.next();
		int sum = 0;
		int len1 = s.length();
		int len2 = t.length();
		int len;
		if(len1<len2)
			len = len1;
		else
			len = len2;
		for(int i=0; i<len; i++)
		{
			if(s.charAt(len1-1-i)==t.charAt(len2-1-i))
			{
				sum++;
			}
			else
				break;
		}
		System.out.println(len1+len2-2*sum);

三、 Polycarp's Practice 

Polycarp is practicing his problem solving skill. He has a list of nn problems with difficulties a1,a2,…,ana1,a2,…,an , respectively. His plan is to practice for exactly kk days. Each day he has to solve at least one problem from his list. Polycarp solves the problems in the order they are given in his list, he cannot skip any problem from his list. He has to solve all nn problems in exactly kk days.

Thus, each day Polycarp solves a contiguous sequence of (consecutive) problems from the start of the list. He can't skip problems or solve them multiple times. As a result, in kk days he will solve all the nn problems.

The profit of the jj -th day of Polycarp's practice is the maximum among all the difficulties of problems Polycarp solves during the jj -th day (i.e. if he solves problems with indices from ll to rr during a day, then the profit of the day is maxl≤i≤raimaxl≤i≤rai ). The total profit of his practice is the sum of the profits over all kk days of his practice.

You want to help Polycarp to get the maximum possible total profit over all valid ways to solve problems. Your task is to distribute all nn problems between kk days satisfying the conditions above in such a way, that the total profit is maximum.

For example, if n=8,k=3n=8,k=3 and a=[5,4,2,6,5,1,9,2]a=[5,4,2,6,5,1,9,2] , one of the possible distributions with maximum total profit is: [5,4,2],[6,5],[1,9,2][5,4,2],[6,5],[1,9,2] . Here the total profit equals 5+6+9=205+6+9=20 .

Input

The first line of the input contains two integers nn and kk (1≤k≤n≤20001≤k≤n≤2000 ) — the number of problems and the number of days, respectively.

The second line of the input contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤20001≤ai≤2000 ) — difficulties of problems in Polycarp's list, in the order they are placed in the list (i.e. in the order Polycarp will solve them).

Output

In the first line of the output print the maximum possible total profit.

In the second line print exactly kk positive integers t1,t2,…,tkt1,t2,…,tk (t1+t2+⋯+tkt1+t2+⋯+tk must equal nn ), where tjtj means the number of problems Polycarp will solve during the jj -th day in order to achieve the maximum possible total profit of his practice.

If there are many possible answers, you may print any of them.

Examples

Input

8 3
5 4 2 6 5 1 9 2

Output

20
3 2 3

Input

5 1
1 1 1 1 1

Output

1
5

Input

4 2
1 2000 2000 2

Output

4000
2 2

Note

The first example is described in the problem statement.

In the second example there is only one possible distribution.

In the third example the best answer is to distribute problems in the following way: [1,2000],[2000,2][1,2000],[2000,2] . The total profit of this distribution is 2000+2000=40002000+2000=4000 .


题意:将n个数,分为k个区间,每个区间内的最大数 都是 n个数中前k大数,

先从小到大排序一下 , 后k个值相加 , 把这k个值的下标标记一下 ,最后再拿上一个被标记的减去当前标记的。



#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
    int n, k;
    int a[2010], b[2010], flag[2010], biao[2010];
    int t=1, ans=0, sum=0;
    scanf("%d %d",&n, &k);
    memset(flag, 0 , sizeof(flag));
    for(int i=1; i<=n ; i++)
    {
 	scanf("%d",&a[i]);
 	b[i] = a[i];
    }
    sort(a+1, a+n+1);
    for(int i=n; i>n-k; i--)
    {
        sum+=a[i];
	flag[a[i]]++;
    }
    printf("%d\n", sum);
    for(int i=1; i<=n; i++)
    {
        if(flag[b[i]]>0)
        {
            flag[b[i]]--;
            biao[t++]=i;
        }
    }
    if(k == 1)
    {
	printf("%d\n", n);
    }
    else
    {
    	printf("%d ", biao[1]);
        for(int i=1; i<t-2; i++)
        {
            printf("%d ",biao[i+1]-biao[i]);
        }
        printf("%d\n",n-biao[t-2]);
    }
    return 0;
 }

Java:

import java.util.Arrays;
import java.util.Scanner;
public class Main 
{

	public static void main(String[] args) 
	{
		// TODO Auto-generated method stub
		Scanner cin = new Scanner(System.in);
		int []a = new int[2010];
		int []b = new int[2010];
		int []flag = new int[2010];
		int []biao = new int[2010];
		int t = 1, ans = 0, sum = 0;
		int n = cin.nextInt();
		int k = cin.nextInt();
		for(int i=1; i<=n; i++)
		{
			a[i] = cin.nextInt();
			flag[i] = 0;
			b[i] = a[i];
		}
		Arrays.sort(a, 1, n+1);
		for(int i=n; i>n-k; i--)
		{
			sum+=a[i];
			flag[a[i]]++;
		}
		System.out.println(sum);
		for(int i=1; i<=n; i++)
		{
			if(flag[b[i]]>0)
			{
				flag[b[i]]--;
				biao[t++]=i;
			}
		}
		if(k==1)
			System.out.println(n);
		else
		{
			System.out.print(biao[1]+" ");
			for(int i=1; i<t-2; i++)
			{
				System.out.print(biao[i+1]-biao[i]+" ");
			}
			System.out.println(n-biao[t-2]);
		}
	}
}

猜你喜欢

转载自blog.csdn.net/qq_42569807/article/details/88378554