Problem Description

A subsequence of length |x| of string s = s1s2... s|s| (where |s| is the length of string s) is a string x = sk1sk2... sk|x| (1 ≤ k1 < k2 < ... < k|x| ≤ |s|).

You've got two strings — s and t. Let's consider all subsequences of string s, coinciding with string t. Is it true that each character of string s occurs in at least one of these subsequences? In other words, is it true that for all i (1 ≤ i ≤ |s|), there is such subsequence x = sk1sk2... sk|x| of string s, that x = t and for some j (1 ≤ j ≤ |x|) kj = i.

Input

The first line contains string s, the second line contains string t. Each line consists only of lowercase English letters. The given strings are non-empty, the length of each string does not exceed 2·105.

Output

Print "Yes" (without the quotes), if each character of the string s occurs in at least one of the described subsequences, or "No" (without the quotes) otherwise.

Examples

Input

abab
ab

Output

Yes

Input

abacaba
aba

Output

No

Input

abc
ba

Output

No

Note

In the first sample string t can occur in the string s as a subsequence in three ways: abab, abab and abab. In these occurrences each character of string s occurs at least once.

In the second sample the 4-th character of the string s doesn't occur in any occurrence of string t.

In the third sample there is no occurrence of string t in string s.

题意:给出两个字符串 S、T,对于 S 的每一个字符寻找一个长度与 T 相同的子串,如果这些子串均与 T 相同,那么输出 Yes,否则输出 No

思路:记录字符串 S 中每一个字符在 T 串向前、向后能匹配的位置,然后对位置进行求和比较,如果向前的位置+向后的位置大于字符串 T 的长度,则说明匹配成功

Source Program

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
const int MOD = 1E9+7;
const int N = 500000+5;
const int dx[] = {-1,1,0,0,-1,-1,1,1};
const int dy[] = {0,0,-1,1,-1,1,-1,1};
using namespace std;char s[N],t[N];
int bucketS[N],bucketT[N];
int pre[N],suf[N];
int main(){scanf("%s",s);scanf("%s",t);int sLen=strlen(s);int tLen=strlen(t);for(int i=0,j=0;i<sLen;i++){if(s[i]==t[j]&&j<tLen){bucketS[s[i]]=j;j++;}pre[i]=bucketS[s[i]];}for(int i=sLen-1,j=tLen-1;i>=0;i--){if(s[i]==t[j]&&j>=0){bucketT[s[i]]=tLen-j;j--;}suf[i]=bucketT[s[i]];}bool flag=true;for(int i=0;i<sLen;i++){if(pre[i]+suf[i]<tLen){flag=false;break;}}if(flag)printf("Yes\n");elseprintf("No\n");return 0;
}

Two Strings(CF-223B)相关推荐

  1. 【解题报告】随便练练二(CF 2300)

    [解题报告]随便练练二(CF 2300) A:Antimatter | CF383D 题意 思路 :DP 代码 B:Physical Education Lessons | CF915E 题意 思路一 ...

  2. Commentator problem(CF 2)

    题目链接 题目大意: 给定三个圆,询问是否存在点满足该点与三个圆夹角均相等,若存在多组解返回夹角最大值. 圆外一点到两圆夹角均相等: 即 sina = sinb = r1 / d1 = r2 / d2 ...

  3. 2021牛客暑期多校训练营5 D-Double Strings(dp+组合数)

    D-Double Strings fi,jf_{i,j}fi,j​表示a中前i个字符,b中前j个字符相同子序列的数量,容斥转移 fi,j=fi−1,j+fi,j−1−fi−1,j−1+{(1+fi−1 ...

  4. UVA455 - Periodic Strings(周期串)

    题目:Periodic Strings A character string is said to have period k if it can be formed by concatenating ...

  5. D. Make a Power of Two(cf#739DIV3)

    D. Make a Power of Two 链接: link. 题意: 找出将数字转换为 2 的任意幂的最小移动次数. 题解: 先将2的xxx次幂的结果以字符串形式保存,输入字符串nnn后,因为存在 ...

  6. Web of Lies(CF 1548A)

    这是今天在打个人赛时碰见的一道题,是一道半图论半思维的题. Web of Lies 题目大意不难理解,在这里只需要注意一些细节.在加边时,只有当cnt[min]的值为1时答案才应该减1,而不是当cnt ...

  7. Magic Powder - 2 (CF 670_D)

    http://codeforces.com/problemset/problem/670/D2 The term of this problem is the same as the previous ...

  8. hdu6208 The Dominator of Strings(AC自动机)

    题意: 给定n个串,问其中是否存在一个串,满足其他串都是它的子串. 如果存在这样的串,输出这个串,否则输出No 数据范围:所有串长度不超过1e5 解法: 答案串一定是最长的串, 如果只有一个最长的串, ...

  9. E. You Are Given Some Strings...(AC自动机)

    题目地址 题目思路很明确,求t上每个位置以其结尾的串有多少个,以其为开头的串有多少个,然后遍历一遍算出贡献就行了.最后正解的思路非常简单,但我硬是整了几个假算法浪费时间,下面说一下我的心路历程. 第一 ...

  10. 【解题报告】博弈专场 (CF 2000~2200)前五题

    [解题报告]博弈专场 (CF 2000+)前五题 A:Fox and Card Game | CF388C 题意 思路 代码 B:Berzerk | CF786A 题意 思路 代码 C:Ithea P ...

最新文章

  1. 面向 Photoshop 的英特尔® Texture Works 插件
  2. CSS设置文字不能被选中
  3. SAP UI5框架渲染的顺序
  4. 解决启动Biee控制台乱码问题
  5. 这 4 款实用小工具,能让你的电脑变得好用又骚气
  6. [WinError 10061] 由于目标计算机积极拒绝,无法连接错误解决办法
  7. newcondition java_Java并发Condition接口
  8. 前端请求进化之路--从form表单到JSONP
  9. stringbuffer常用方法_第八讲:常用类库API
  10. 翻译【ElasticSearch Server】第一章:开始使用ElasticSearch集群(2)
  11. 【Hive】性能调优 - EXPLAIN
  12. 如何看待绿色数据中心
  13. Winform界面中实现通用工具栏按钮的事件处理
  14. 计算机学院实验室安全管理办法,江苏大学计算机学院实验室安全管理制度
  15. 由于没有远程桌面授权服务器可以提供许可证,远程会话被中断。
  16. linux无线网卡模拟ap,在 openSUSE 上使用 create_ap 创建虚拟 WiFi 热点来方便使用 KDE Connect 连接手机...
  17. Mstar 平台(648)唤醒之串口唤醒
  18. 最短路径算法之Dijkstra算法(java实现)
  19. javaee实训报告总结_javaee实训总结
  20. 零基础如何从零开始运营微信公众号

热门文章

  1. [技术回顾系列]--认识WebService全貌
  2. 智能驾驶系统是怎样看懂交通标志的?3张流程图给你讲明白
  3. Adidas、金拱门、KFC、乐天玛特,零售巨头的选址秘诀都在数据里了
  4. 深入理解RocketMQ是如何做到高性能的?
  5. 再有人问你为什么MySQL用B+树做索引,就把这篇文章发给她
  6. “如果产品经理躺平接受需求,那程序员免不了想打一架”
  7. 面向犯罪编程,9名程序员锒铛入狱
  8. JEEWX 使用ngrok将本地Web服务映射到外网
  9. JEECG v3视频陆续更新
  10. Oracle执行外部文件: