Codeforces Round #307 (Div. 2) B. Zgukistringz

Source: Internet
Author: User

Professor Gukiz doesn ' t accept string as they is. He likes to swap some letters in string to obtain a new one.

Gukiz has stringsa,b, andC. He wants to obtain stringkBy swapping some letters ina, so thatkShould contain as many non-overlapping substrings equal either tobOrCAs possible. Substring of Stringxis a string formed by consecutive segment of characters fromx. Substrings of stringxOverlap If there is positionIIn stringxoccupied by both of them.

Gukiz was disappointed because none of he students managed to solve the problem. Can you help them and find one of possible strings K?

Input

The first line contains stringa, the second line contains stringb, and the third line contains stringC(1?≤?| a|,?| b|,?| C|? ≤?105 , where| S|denotes the length of strings).

All three strings consist only of lowercase Chinese letters.

It's possible that B and C coincide.

Output

Find one of possible strings K, as described in the problem statement. If There is multiple possible answers, print any of them.

Sample Test (s) input
Aaaab
Output
Aaa
Input
Pozdravstaklenidodirinistedobri
Output
Nisteaadddiiklooprrvz
Input
Abbbaacccaabaca
Output
Ababacabcc
Note

In the third sample, this optimal solutions have three non-overlaping substrings equal to eitherbOrCOn positions1?–?2(AB),3?–?4(AB),5?–?7(ACA). In this sample, there exist many other optimal solutions, one of the them would beACAABABBCC.

Because the letters can be exchanged at will, so first count the number of letters in all the A,b,c three strings, and then see how many B string minx can be filled, and then populate the 0~minx string, and then see how many C strings can be populated in the current situation, calculate the maximum value.

#include <stdio.h> #include <string.h>char s1[100006],s2[100006],s3[100006];int a[30],b[30],c[30],a1[30 ];int Main () {int n,m,i,j,len1,len2,len3,minx1,minx2,maxx,minx,t1,t2;while (scanf ("%s", S1)!=eof) {scanf ("%s%s", S2, S3); Len1=strlen (S1); Len2=strlen (S2); Len3=strlen (S3); Memset (A,0,sizeof (a)); Memset (b,0,sizeof (b)); Memset (c,0, sizeof (c)); Memset (a1,0,sizeof (A1)); for (i=0;i<len1;i++) {a[s1[i]-' a ']++;a1[s1[i]-' a ']++;} for (i=0;i<len2;i++) {b[s2[i]-' a ']++;} for (i=0;i<len3;i++) {c[s3[i]-' a ']++;} Minx1=200006;for (i=0;i<=25;i++) {if (b[i]==0) continue;if (minx1> (A[i]/b[i])) minx1=a[i]/b[i];} Minx2=200006;for (i=0;i<=25;i++) {if (c[i]==0) continue;if (minx2> (A[i]/c[i])) minx2=a[i]/c[i];} Maxx=minx2;t1=0;t2=minx2;for (i=1;i<=minx1;i++) {minx=200006;for (j=0;j<=25;j++) {a[j]-=b[j];} for (j=0;j<=25;j++) {if (c[j]==0) continue;if (minx> (A[j]/c[j])) minx=a[j]/c[j];} if (maxx<minx+i) {Maxx=minx+i;t1=i;t2=minx;}} for (i=1;i<=t1;i++) printf ('%s ', S2), for (i=1;i<=t2;i++) printf ('%s ', S3); for (i=0;i<=25;i++) {a1[i]=a1[i]-t1*b[i]-t2*c[i];for (j=1;j<=a1[i];j++) {printf ("%c", ' a ' +i);}} printf ("\ n");} return 0;}


Codeforces Round #307 (Div. 2) B. Zgukistringz

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.