CodeForces - 825D

You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters.

Suitability of string s is calculated by following metric:

Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulting strings s, you choose the one with the largest number of non-intersecting occurrences of string t. Suitabilityis this number of occurrences.

You should replace all '?' characters with small Latin letters in such a way that the suitability of string s is maximal.

Input

The first line contains string s (1 ≤ |s| ≤ 106).

The second line contains string t (1 ≤ |t| ≤ 106).

Output

Print string s with '?' replaced with small Latin letters in such a way that suitability of that string is maximal.

If there are multiple strings with maximal suitability then print any of them.

Examples

Input

?aa?
ab

Output

baab

Input

??b?
za

Output

azbz

Input

abcd
abacaba

Output

abcd

Note

In the first example string "baab" can be transformed to "abab" with swaps, this one has suitability of 2. That means that string "baab" also has suitability of 2.

In the second example maximal suitability you can achieve is 1 and there are several dozens of such strings, "azbz" is just one of them.

In the third example there are no '?' characters and the suitability of the string is 0.

第一个串的位置可以随便交换,问在把所有的问好填满使得第一个s串里有最多个t串。

#include<set>
#include<map>
#include<stack>
#include<queue>
#include<math.h>
#include<vector>
#include<string>
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#define mem(a,b) memset(a,b,sizeof(a))
#define ll long long
#define inf 0x3f3f3f
using namespace std;
string s1,s2,s3,s4;
const int maxn=2005;
int vis1[maxn];
int vis2[maxn];
int a;
bool judge(int x){
    int b=0;
    for(int i='a';i<='z';i++){
       if(vis2!=0){
        b+=max(0,x*vis2[i]-vis1[i]);
       }
    }
    if(b<=a)return true;
    else
        return false;
}
void judge1(int x){
    for(int i='a';i<='z';i++){
       if(vis2!=0){
        vis2[i]=max(0,x*vis2[i]-vis1[i]);
       }
       for(int j=0;j<vis2[i];j++)
        s3+=i;
    }
}
int main(){
    cin>>s1>>s2;
    int len1=s1.size();
    int len2=s2.size();
    for(int i=0;i<len1;i++){
        if(s1[i]!='?')vis1[s1[i]]++;
        else a++;
    }
    int x=len1/len2;
    if(x==0){
        for(int i=0;i<s1.size();i++)
            if(s1[i]=='?')s1[i]=s2[0];
        cout<<s1<<endl;
        return 0;
    }
    for(int i=0;i<s2.size();i++){
        vis2[s2[i]]++;
    }
    int l=0,r=x,m;
    while(l<=r){
        int mid=(l+r)/2;
        if(judge(mid)){
            l=mid+1;m=mid;}
        else
        r=mid-1;
    }
    judge1(m);
    int l1=0;
    for(int i=0;i<len1;i++){
        if(s1[i]=='?'&&l1<s3.size()){
            s1[i]=s3[l1++];
        }
        else if(s1[i]=='?'&&l1>=s3.size())
            s1[i]='z';
    }
    cout<<s1<<endl;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值