Problem:
C： たったひとつの部分列 - Unique Subsequence -
問題
ある日えびちゃんは、机の上に長さ
n
のテキスト文字列
T
と長さ
m
のパターン文字列
P
(
m \leq n
) が置かれていることに気づきました。えびちゃんは、文字列に現れる「たったひとつの部分列」が大好きであるため、
P
が
T
のたったひとつの部分列であるかどうかをすぐに調査し始めました。
P
が
T
のたったひとつの部分列であるという性質は以下のように表されます。ここで、文字列
X
の
i
文字目を
X_i
と書きます。
長さ
m
の数列
S = (s_1, ..., s_m)
(ただし、
s_1 < s_2 < ... < s_m
) で、各
i
(
i = 1, ..., m
) について
T_{s_i} = P_i
である数列
S
が一意に定まる。
調査を始めてから数時間、えびちゃんは文字列をぐっと睨んでいましたが、文字列が長すぎるために疲れてしまったようです。それを見かねたあなたは、えびちゃんを手伝ってあげることにしました。えびちゃんのために、
P
が
T
のたったひとつの部分列であるならば “yes” を、そうでないならば “no” を出力するプログラムを作成してください。
入力形式
T
P
1
行目には、テキスト文字列
T
が与えられる。
2
行目には、パターン文字列
P
が与えられる。
制約
1 \leq |P| \leq |T| \leq 5 \times 10^5
T
および
P
は英字小文字 ‘a’-’z’ で構成される。
出力形式
P
が
T
のたったひとつの部分列であるならば “yes” を、そうでないならば “no” を1行に出力してください。
入力例1
aizucamp
azu
出力例1
yes
入力例2
abracadabra
rada
出力例2
no
入力例3
hokkaido
dekai
出力例3
no

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll,ll>;
const ll LINF = 0x1fffffffffffffff;
#define name3(_1,_2,_3,name,...) name
#define rep1(n) for(ll i=0;i<(n);++i)
#define rep2(i,n) for(ll i=0;i<(n);++i)
#define rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(...) name3(__VA_ARGS__,rep3,rep2,rep1)(__VA_ARGS__)
#define rrep(i,a,b) for(ll i=(b)-1;i>=(a);i--)
#define each(i,a) for(auto &i : a)
#define sum(a) accumulate(all(a), 0LL)
#define all(i) begin(i), end(i)
template<class T, class U> inline bool chmin(T &a, const U &b){ if(a > b) { a = b; return 1; } else return 0; }
template<class T, class U> inline bool chmax(T &a, const U &b){ if(a < b) { a = b; return 1; } else return 0; }


int main(){
    string s, t;
    cin >> s >> t;
    ll n=t.size(),m=s.size();
    vector<ll>a(n);
    ll at=-1;
    rep(n){
        at++;
        while(at<m&&s[at]!=t[i])at++;
        if(at==m)return!puts("no");
        a[i]=at;
    }
    reverse(all(s));
    reverse(all(t));
    at=-1;
    rep(n){
        at++;
        while(at<m&&s[at]!=t[i])at++;
        if(a[n-1-i]!=m-1-at)return!puts("no");
    }
    puts("yes");
}
accuracy: 1
time_ms: 20
memory_kb: 7912
final_rank: 9

code_snippet: #include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
constexpr ll MOD = 1000000007;
//---------------------------------//



int main() {
	string T, P;
	cin >> T >> P;
	
	bool ans = true;
	puts([&] {
		vector<int> v[2];
		REP(times, 2) {
			int pos = 0, idx = 0;
			while (pos < T.size() && idx < P.size()) {
				if (T[pos] == P[idx]) {
					v[times].emplace_back(pos);
					++pos; ++idx;
				}
				else ++pos;
			}
			if (idx < P.size()) return false;
			reverse(ALL(T));
			reverse(ALL(P));
		}
		
		for (int &u : v[1]) u = T.size() - 1 - u;
		reverse(ALL(v[1]));
		return v[0] == v[1];
		
		
	}() ? "yes": "no");
	
	return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 8996
final_rank: 13

code_snippet: #include <bits/stdc++.h>
// aya_seは起床のプロ
using namespace std;

//@ebi's definition

#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n - 1)); i >= (int)(a); i--)
#define all(v) (v).begin(), (v).end()

using ll = long long;

struct Edge
{
    int to;
    ll weight;
    Edge(int t, ll w) : to(t), weight(w) {}
};

using Graph = vector<vector<Edge>>;
using graph = vector<vector<ll>>;

// xxpoxx's definition
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define RES(a, n) (a).resize(n)
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 2.0 * asin(1.0);
const ll INF = 1L << 60;
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const ll MAX = 10000000;
/****** define constant end ********/

// aya_se's definition
vl fac, finv, inv;
void COMinit(ll N)
{
    fac.resize(N);
    finv.resize(N);
    inv.resize(N);
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < N; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
ll COM(ll n, ll k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll modinv(ll a, ll m)
{
    ll b = m, u = 1, v = 0;
    while (b)
    {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0)
        u += m;
    return u;
}

template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

int main()
{
    cout << std::fixed << std::setprecision(10);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string t, p;
    cin >> t >> p;
    ll pite = 0;
    string now = "";
    REP(i, t.size())
    {
        if (t.substr(i, 1) == now && p.substr(pite, 1) != t.substr(i, 1))
        {
            cout << "no" << endl;
            return 0;
        }
        if (p.substr(pite, 1) != t.substr(i, 1))
        {
            continue;
        }
        now = t.substr(i, 1);
        pite++;
    }
    if (pite == p.size())
        cout << "yes" << endl;
    else
        cout << "no" << endl;
}
accuracy: 1
time_ms: 50
memory_kb: 4260
final_rank: 8

code_snippet: #include <algorithm>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <string>
#include <vector>

using usize = std::size_t;
using u64 = std::uint64_t;

static constexpr u64 mod = 1000000007;

int main() {
  std::string t, p;
  std::cin >> t >> p;
  const usize n = t.size();

  bool flag = true;

  const auto match = [&]() {
    std::vector<bool> v(n, false);
    usize i = 0;
    for (const auto c : p) {
      while (i != n && t[i] != c) {
        i += 1;
      }
      if (i == n) {
        flag = false;
        break;
      }
      v[i] = true;
      i += 1;
    }
    return std::move(v);
  };

  auto f = match();
  if (!flag) {
    std::cout << "no\n";
    return 0;
  }
  std::reverse(t.begin(), t.end());
  std::reverse(p.begin(), p.end());
  auto b = match();
  std::reverse(b.begin(), b.end());

  for (usize i = 0; i != n; ++i) {
    if (f[i] != b[i]) {
      std::cout << "no\n";
      return 0;
    }
  }
  std::cout << "yes\n";

  return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 4252
final_rank: 3

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll,ll>;
const ll LINF = 0x1fffffffffffffff;
#define name3(_1,_2,_3,name,...) name
#define rep1(n) for(ll i=0;i<(n);++i)
#define rep2(i,n) for(ll i=0;i<(n);++i)
#define rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(...) name3(__VA_ARGS__,rep3,rep2,rep1)(__VA_ARGS__)
#define rrep(i,a,b) for(ll i=(b)-1;i>=(a);i--)
#define each(i,a) for(auto &i : a)
#define sum(a) accumulate(all(a), 0LL)
#define all(i) begin(i), end(i)
template<class T, class U> inline bool chmin(T &a, const U &b){ if(a > b) { a = b; return 1; } else return 0; }
template<class T, class U> inline bool chmax(T &a, const U &b){ if(a < b) { a = b; return 1; } else return 0; }


int main(){
    string s, t;
    cin >> s >> t;
    ll n=t.size(),m=s.size();
    vector<ll>a(n);
    ll at=-1;
    rep(n){
        at++;
        while(at<m&&s[at]!=t[i])at++;
        if(at==m)return!puts("no");
        a[i]=at;
    }
    reverse(all(s));
    reverse(all(t));
    at=-1;
    rep(n){
        at++;
        while(at<m&&s[at]!=t[i])at++;
        if(a[n-1-i]!=m-1-at)return!puts("no");
    }
    puts("yes");
}
accuracy: 1
time_ms: 20
memory_kb: 7912
final_rank: 9

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int lli;
const lli mod = 1e9+7;

int main(){
    string t,p;
    cin >> t >> p;
    t = "." + t + ".";
    vector<int> a,b;
    int n=t.length(), m=p.length();
    for(int i=0,j=0; i<m; i++){
        while(j<n and p[i]!=t[j]) j++;
        if(p[i] == t[j]){
            a.push_back(j);
            j++;
        }
    }
    if((int)a.size() < m){
        cout << "no" << endl;
        return 0;
    }

    for(int i=m-1,j=n-1; i>=0; i--){
        while(j>=0 and p[i]!=t[j]) j--;
        if(p[i] == t[j]){
            b.push_back(j);
            j--;
        }
    }
    reverse(b.begin(), b.end());

    if(a == b){
        cout << "yes" << endl;
    }else{
        cout << "no" << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 8916
final_rank: 12

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int lli;
const lli mod = 1e9+7;

int main(){
    string t,p;
    cin >> t >> p;
    t = "." + t + ".";
    vector<int> a,b;
    int n=t.length(), m=p.length();
    int j = 0;
    for(int i=0; i<m; i++){
        while(j<n and p[i]!=t[j]) j++;
        if(p[i] == t[j]){
            a.push_back(j);
        }
    }
    if((int)a.size() < m){
        cout << "no" << endl;
        return 0;
    }

    j = n-1;
    for(int i=m-1; i>=0; i--){
        while(j>=0 and p[i]!=t[j]) j--;
        if(p[i] == t[j]){
            b.push_back(j);
        }
    }
    reverse(b.begin(), b.end());
    if(a == b){
        cout << "yes" << endl;
    }else{
        cout << "no" << endl;
    }
    return 0;
}
accuracy: 0.22580645161290322
time_ms: 20
memory_kb: 4452
final_rank: 20

code_snippet: #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main(){
  string s, t;
  cin >> s >> t;
  int n = s.length();
  vector<int> F;
  {
    int j = 0;
    for(int i = 0; i < n; ++i){
      if(j == t.length()) break;
      if(s[i] != t[j]) continue;
      F.push_back(i);
      ++j;
    }
  }
  if(F.size() != t.length()){
    puts("no");
    return 0;
  }
  vector<int> B;
  {
    int j = t.length()-1;
    for(int i = n-1; i >= 0; --i){
      if(j == -1) break;
      if(s[i] != t[j]) continue;
      B.push_back(i);
      --j;
    }
    reverse(B.begin(), B.end());
  }
  if(B.size() != t.length()){
    puts("no");
    return 0;
  }
  if(F != B){
    puts("no");
    return 0;
  }
  puts("yes");
}
accuracy: 1
time_ms: 20
memory_kb: 9000
final_rank: 14

code_snippet: #include<bits/stdc++.h>
using namespace std;

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
int main()
{
  string t,p;cin>>t>>p;
  int nowi=0;
  vector<int> use_front(0);
  vector<int> use_back(0);
  int i;
  rep(i,t.size())
  {
    if(t[i]==p[nowi])
    {
      use_front.emplace_back(i);
      nowi++;
    }
    if(nowi>=p.size())break;
  }
  nowi=p.size()-1;
  for(i=t.size()-1;i>=0;i--)
  {
    if(t[i]==p[nowi])
    {
      use_back.emplace_back(i);
      nowi--;
    }
    if(nowi<0)break;
  }
  if(use_front.size()<p.size()||use_back.size()<p.size())
  {
    cout<<"no"<<endl;
  }
  else
  {
    reverse(all(use_back));
    if(use_back==use_front)cout<<"yes"<<endl;
    else cout<<"no"<<endl;
  }
  
}
accuracy: 1
time_ms: 20
memory_kb: 9044
final_rank: 15

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;


int main(){
 string t,p;
 cin>>t>>p;
 int f=0,s=-1;// second 
 vector<bool> used(26,false);
 vector<int> alpha(26,-1);//最後に使われた位置
 for(ll i=0;i<t.size();i++){
  
  if( s != -1 ){
   if( t[i] == p[s] ) s++;
  }

  if( alpha[ t[i]-'a' ] != -1 ){
   s = max( s , alpha[t[i]-'a' ] );
  }



  if( f<p.size() && t[i] == p[f] ){
   f++;
   alpha[t[i]-'a'] = f;
  }


  if( s == p.size() ){
   cout<<"no"<<endl;
   return 0;
  }

 }

 if( f == p.size() ){
  cout<<"yes"<<endl;
 }else{
  cout<<"no"<<endl;
 }

    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 4256
final_rank: 4

code_snippet: #include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

int main() {
  
  string s, t; cin >> s >> t;
  t = '*' + t;

  int id = 1;
  for (int i = 0; i < s.size(); i++) {
    if (id < t.size() and t[id] == s[i]) {
      id++;
    } else if (t[id - 1] == s[i]) {
      id = 1;
    }
  }
  if (id == t.size()) {
    cout << "yes" << endl;
  } else {
    cout << "no" << endl;
  }
  return 0;
}
accuracy: 0.5483870967741935
time_ms: 20
memory_kb: 4320
final_rank: 19

code_snippet: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

void no(){
    cout << "no" << endl;
    exit(0);
}

int main(){
    string t, p;
    cin >> t >> p;
    vector<int> v[26];
    for(int i = 0; i < t.length(); i++){
        v[t[i]-'a'].push_back(i);
    }
    int n = p.length();
    vector<int> l(n), r(n);
    int now = 0;
    for(int i = 0; now < n && i < t.length(); i++){
        if(t[i] == p[now]){
            l[now++] = i;
        }
    }
    if(now != n)    no();
    now = n-1;
    for(int i = t.length()-1; now >= 0 && i >= 0; i--){
        if(t[i] == p[now]){
            r[now--] = i;
        }
    }
    if(now != -1)   no();
    if(v[p[0]-'a'][0] != l[0] || v[p.back()-'a'].back() != r[n-1])  no();
    for(int i = 1; i+1 < n; i++){
        int cind = p[i]-'a';
        int j = *upper_bound(v[cind].begin(),v[cind].end(),l[i-1]);
        int k = *(--lower_bound(v[cind].begin(), v[cind].end(),r[i+1]));
        if(j != k)  no();
    }
    cout << "yes" << endl;
    return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 11136
final_rank: 17

code_snippet: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;



int main()
{
	string A,B;cin>>A>>B;
	
	vector<vector<int>>places(26);
	for (int i = 0; i < A.size(); ++i) {
		places[A[i]-'a'].push_back(i);
	}

	vector<int>v;
	{
		 int now=-1;
		for (int i = 0; i < B.size(); ++i) {
			int ch(B[i]-'a');

			auto it=upper_bound(places[ch].begin(),places[ch].end(),now);
			if (it == places[ch].end()) {
				v.clear();
				break;
			}
			else {
				v.push_back(*it);
				now=*it;
			}
		}
	}
	if (v.empty()) {
		cout<<"no"<<endl;
	}
	else {
		bool ok = true;
		int N=B.size();
		for (int i = 0; i < B.size(); ++i) {
			int pre=i==0?0:v[i-1]+1;
			int nex=i==N-1?A.size()-1:v[i+1]-1;

			{
				auto lt=lower_bound(places[B[i]-'a'].begin(),places[B[i]-'a'].end(),pre);
				auto rt=upper_bound(places[B[i]-'a'].begin(),places[B[i]-'a'].end(),v[i]-1);

				if(lt!=rt)ok=false;
			}
			{
				auto lt = lower_bound(places[B[i] - 'a'].begin(), places[B[i] - 'a'].end(), v[i]+1);
				auto rt = upper_bound(places[B[i] - 'a'].begin(), places[B[i] - 'a'].end(), nex);

				if (lt != rt)ok = false;
			}
		}
		if(ok)cout<<"yes"<<endl;
		else cout<<"no"<<endl;
	}
	
	return 0;
}
accuracy: 1
time_ms: 120
memory_kb: 8908
final_rank: 18

code_snippet: // g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	string s,t;cin>>s>>t;
	int n=s.size();
	vi a(n),b(n);
	int r=0;
	rep(i,n){
		if(r<n&&s[i]==t[r]){
			r++;
			a[i]=1;
		}
	}
	r=t.size()-1;
	rep(i,n){
		int j=n-1-i;
		if(r>=0&&s[j]==t[r]){
			r--;
			b[j]=1;
		}
	}
	
	bool h=true;
	rep(i,s.size())if(a[i]!=b[i])h=false;
	if(h)cout<<"yes"<<endl;
	else cout<<"no"<<endl;
}
accuracy: 1
time_ms: 30
memory_kb: 7916
final_rank: 11

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int main(){
    string t,p;
    cin>>t>>p;
    int n=t.size(),m=p.size();
    int cur=0;
    rep(i,n){
        if(cur<m&&t[i]==p[cur]) ++cur;
        else if(t[i]==p[cur-1]){
            cout<<"no"<<endl;
            return 0;
        }
    }
    if(cur==m)cout<<"yes"<<endl;
    else cout<<"no"<<endl;
    return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 4188
final_rank: 5

code_snippet: #include <bits/stdc++.h>
#include <sys/time.h>
using namespace std;

#define rep(i,n) for(long long i = 0; i < (long long)(n); i++)
#define repi(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define mt make_tuple
#define mp make_pair
template<class T1, class T2> bool chmin(T1 &a, T2 b) { return b < a && (a = b, true); }
template<class T1, class T2> bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

using ll = long long; using vll = vector<ll>; using vvll = vector<vll>; using P = pair<ll, ll>;
using ld = long double;  using vld = vector<ld>; 
using vi = vector<int>; using vvi = vector<vi>; vll conv(vi& v) { vll r(v.size()); rep(i, v.size()) r[i] = v[i]; return r; }

inline void input(int &v){ v=0;char c=0;int p=1; while(c<'0' || c>'9'){if(c=='-')p=-1;c=getchar();} while(c>='0' && c<='9'){v=(v<<3)+(v<<1)+c-'0';c=getchar();} v*=p; }
template <typename T, typename U> ostream &operator<<(ostream &o, const pair<T, U> &v) {  o << "(" << v.first << ", " << v.second << ")"; return o; }
template<size_t...> struct seq{}; template<size_t N, size_t... Is> struct gen_seq : gen_seq<N-1, N-1, Is...>{}; template<size_t... Is> struct gen_seq<0, Is...> : seq<Is...>{};
template<class Ch, class Tr, class Tuple, size_t... Is>
void print_tuple(basic_ostream<Ch,Tr>& os, Tuple const& t, seq<Is...>){ using s = int[]; (void)s{0, (void(os << (Is == 0? "" : ", ") << get<Is>(t)), 0)...}; }
template<class Ch, class Tr, class... Args> 
auto operator<<(basic_ostream<Ch, Tr>& os, tuple<Args...> const& t) -> basic_ostream<Ch, Tr>& { os << "("; print_tuple(os, t, gen_seq<sizeof...(Args)>()); return os << ")"; }
ostream &operator<<(ostream &o, const vvll &v) { rep(i, v.size()) { rep(j, v[i].size()) o << v[i][j] << " "; o << endl; } return o; }
template <typename T> ostream &operator<<(ostream &o, const vector<T> &v) { o << '['; rep(i, v.size()) o << v[i] << (i != v.size()-1 ? ", " : ""); o << "]";  return o; }
template <typename T> ostream &operator<<(ostream &o, const deque<T> &v) { o << '['; rep(i, v.size()) o << v[i] << (i != v.size()-1 ? ", " : ""); o << "]";  return o; }
template <typename T>  ostream &operator<<(ostream &o, const set<T> &m) { o << '['; for (auto it = m.begin(); it != m.end(); it++) o << *it << (next(it) != m.end() ? ", " : ""); o << "]";  return o; }
template <typename T>  ostream &operator<<(ostream &o, const unordered_set<T> &m) { o << '['; for (auto it = m.begin(); it != m.end(); it++) o << *it << (next(it) != m.end() ? ", " : ""); o << "]";  return o; }
template <typename T, typename U>  ostream &operator<<(ostream &o, const map<T, U> &m) { o << '['; for (auto it = m.begin(); it != m.end(); it++) o << *it << (next(it) != m.end() ? ", " : ""); o << "]";  return o; }
template <typename T, typename U, typename V>  ostream &operator<<(ostream &o, const unordered_map<T, U, V> &m) { o << '['; for (auto it = m.begin(); it != m.end(); it++) o << *it; o << "]";  return o; }
vector<int> range(const int x, const int y) { vector<int> v(y - x + 1); iota(v.begin(), v.end(), x); return v; }
template <typename T> istream& operator>>(istream& i, vector<T>& o) { rep(j, o.size()) i >> o[j]; return i;}
template <typename T, typename S, typename U> ostream &operator<<(ostream &o, const priority_queue<T, S, U> &v) { auto tmp = v; while (tmp.size()) { auto x = tmp.top(); tmp.pop(); o << x << " ";} return o; }
template <typename T> ostream &operator<<(ostream &o, const queue<T> &v) { auto tmp = v; while (tmp.size()) { auto x = tmp.front(); tmp.pop(); o << x << " ";} return o; }
template <typename T> ostream &operator<<(ostream &o, const stack<T> &v) { auto tmp = v; while (tmp.size()) { auto x = tmp.top(); tmp.pop(); o << x << " ";} return o; }
template <typename T> unordered_map<T, ll> counter(vector<T> vec){unordered_map<T, ll> ret; for (auto&& x : vec) ret[x]++; return ret;};
string substr(string s, P x) {return s.substr(x.fi, x.se - x.fi); }
void vizGraph(vvll& g, int mode = 0, string filename = "out.png") { ofstream ofs("./out.dot"); ofs << "digraph graph_name {" << endl; set<P> memo; rep(i, g.size())  rep(j, g[i].size()) { if (mode && (memo.count(P(i, g[i][j])) || memo.count(P(g[i][j], i)))) continue; memo.insert(P(i, g[i][j])); ofs << "    " << i << " -> " << g[i][j] << (mode ? " [arrowhead = none]" : "")<< endl;  } ofs << "}" << endl; ofs.close(); system(((string)"dot -T png out.dot >" + filename).c_str()); }
size_t random_seed; namespace std { using argument_type = P; template<> struct hash<argument_type> { size_t operator()(argument_type const& x) const { size_t seed = random_seed; seed ^= hash<ll>{}(x.fi); seed ^= (hash<ll>{}(x.se) << 1); return seed; } }; }; // hash for various class
struct timeval start; double sec() { struct timeval tv; gettimeofday(&tv, NULL); return (tv.tv_sec - start.tv_sec) + (tv.tv_usec - start.tv_usec) * 1e-6; }
struct init_{init_(){ ios::sync_with_stdio(false); cin.tie(0); gettimeofday(&start, NULL); struct timeval myTime; struct tm *time_st; gettimeofday(&myTime, NULL); time_st = localtime(&myTime.tv_sec); srand(myTime.tv_usec); random_seed = RAND_MAX / 2 + rand() / 2; }} init__;
#define ldout fixed << setprecision(40) 

#define EPS (double)1e-14
#define INF (ll)1e18
#define mo  (ll)(1e9+7)

int main(void) {
    string t, p; cin >> t >> p;
    ll n = t.size(), m = p.size();
    vll pos;
    ll j;
    
    j = 0; rep(i, n) if (j < m) if (t[i] == p[j]) { pos.pb(i); j++; }
    if (j != m) {
        cout << "no" << endl;
        return 0;
    }

    vll rpos;
    reverse(all(t)), reverse(all(p));
    j = 0; rep(i, n) if (j < m) if (t[i] == p[j]) { rpos.pb(i); j++; }
    rep(i, m) rpos[i] = n - 1 - rpos[i];
    reverse(all(rpos));

    if (rpos == pos) {
        cout << "yes"<<endl;
    } else {
        cout << "no"<<endl;
    }




    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 13976
final_rank: 16

code_snippet: #include <functional>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

int main()
{
    string t, p;
    cin >> t;
    cin >> p;

    t += "$";
    p += "$";

    vector<bool> exists(p.size());
    bool duplicated = false;
    int i = 0;
    char tmp = '!';
    // P: aab, T: aaab ??????????????´???, ????????? a ??? OK ??????, 2????????? a ???????????????
    for (char j : t) {
        // ?????¨??????????????????????????¨?????´??????, ????????????????????????????????£????????????
        if (p[i] == j && !exists[i]) {
            exists[i] = true;
            // ?????????????´¢?????????????????????
            tmp = p[i];
            i += 1;
        }
        // ???????????????
        else if (tmp == j) {
            duplicated = true;
        }
    }

    if (accumulate(begin(exists), end(exists), true, logical_and<>())) {
        if (!duplicated) {
            cout << "yes" << endl;
            return 0;
        }
    }
    cout << "no" << endl;
}
accuracy: 1
time_ms: 40
memory_kb: 4168
final_rank: 7

code_snippet: #include <functional>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

int main()
{
    string t, p;
    cin >> t;
    cin >> p;


    t += "$";
    p += "$";

    vector<bool> exists(p.size());
    bool duplicated = false;
    int i = 0;
    char tmp = '!';
    // P: aab, T: aaab ??????????????´???, ????????? a ??? OK ??????, 2????????? a ???????????????
    for (char j : t) {
        // ?????¨??????????????????????????¨?????´??????, ????????????????????????????????£????????????
        if (p[i] == j && !exists[i]) {
            exists[i] = true;
            // ?????????????´¢?????????????????????
            tmp = p[i];
            i += 1;
        }
        // ???????????????
        else if (tmp == j) {
            duplicated = true;
        }
        else if (exists[i]) {
            i += 1;
            cout << "aa" << endl;
        }
    }

    if (accumulate(begin(exists), end(exists), true, logical_and<>())) {
        if (!duplicated) {
            cout << "yes" << endl;
            return 0;
        }
    }
    cout << "no" << endl;
}
accuracy: 1
time_ms: 20
memory_kb: 4168
final_rank: 1

code_snippet: #include <functional>
#include <iostream>
#include <numeric>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

int main()
{
    string t, p;
    cin >> t;
    cin >> p;

    t += "$";
    p += "$";

    vector<bool> exists(p.size());
    bool duplicated = false;
    int i = 0;
    char tmp = '!';
    for (int j = 0; j < t.size(); ++j) {
        if (p[i] == t[j]) {
            if (!exists[i]) {
                exists[i] = true;
                tmp = p[i];
                i += 1;
            }
        }
        else if (tmp == t[j]) {
            duplicated = true;
        }
        else {
            if (exists[i]) {
                i += 1;
            }
        }
    }

    if (accumulate(begin(exists), end(exists), true, logical_and<>())) {
        if (!duplicated) {
            cout << "yes" << endl;
            return 0;
        }
    }
    cout << "no" << endl;
}
accuracy: 1
time_ms: 30
memory_kb: 4204
final_rank: 6

code_snippet: #include <functional>
#include <iostream>
#include <numeric>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

#define NDEBUG

int main()
{
    string t, p;
#ifdef NDEBUG
    cin >> t;
    cin >> p;
#else
    t = "aizucamp";
    p = "azu";
    // t = "abracadabra";
    // p = "rada";
    t = "aabc";
    p = "aabc";
#endif

    t += "$";
    p += "$";

    auto ppc = [](const std::string& s, int n, const std::vector<bool>& v) {
        stringstream ss;
        for (int i = 0; i < s.size(); ++i) {
            if (v[i]) {
                ss << "\033[31m";
            }
            if (i == n) {
                ss << "[" << s[i] << "]";
            }
            else {
                ss << s[i];
            }
            if (v[i]) {
                ss << "\033[0m";
            }
        }
        return ss.str();
    };
    auto pp = [](const std::string& s, int n) {
        stringstream ss;
        for (int i = 0; i < s.size(); ++i) {
            if (i == n) {
                ss << "[" << s[i] << "]";
            }
            else {
                ss << s[i];
            }
        }
        return ss.str();
    };

    vector<bool> exists(p.size() - 1);
    bool duplicated = false;
    int i = 0;
    int j = 0;
    char tmp = '!';
    while (j != t.size()) {
#ifndef NDEBUG
        cout << "T " << pp(t, j) << endl;
        cout << "P " << ppc(p, i, exists) << endl;
        cout << tmp << endl;
        cout << boolalpha << "duplicate: " << duplicated << "\n" << endl;
#endif
        if (p[i] == t[j]) {
            if (!exists[i]) {
                exists[i] = true;
                tmp = p[i];
                i += 1;
            }
        }
        else if (tmp == t[j]) {
            duplicated = true;
        }
        else {
            if (exists[i]) {
                i += 1;
            }
        }
        j += 1;
    }
#ifndef NDEBUG
    cout << "T " << pp(t, j) << endl;
    cout << "P " << ppc(p, i, exists) << endl;
    cout << tmp << endl;
    cout << boolalpha << "duplicate: " << duplicated << "\n" << endl;
#endif
    if (accumulate(begin(exists), end(exists), true, logical_and<>())) {
        if (!duplicated) {
            cout << "yes" << endl;
            return 0;
        }
    }
    cout << "no" << endl;
}
accuracy: 1
time_ms: 20
memory_kb: 4204
final_rank: 2