#!/bin/python3
def match(a, b):
    return a == b or a.upper() == b

def isdeletable(a):
    return a.islower()
    
def abbreviation(a, b):
    m, n = len(a), len(b)
    dp = [[False] * (n + 1) for _ in range (m + 1)]
    dp[0][0] = True
    for i in range(m):
        if isdeletable(a[i]): dp[i+1][0] = dp[i][0]
    
    for i in range(m):
        for j in range(n):
            if match(a[i], b[j]):
                dp[i+1][j+1] = dp[i][j] or (dp[i][j+1] and isdeletable(a[i]))
            elif isdeletable(a[i]):
                dp[i+1][j+1] = dp[i][j+1]
    return "YES" if dp[m][n] else "NO"



#include <bits/stdc++.h>

using namespace std;

bool match(char a, char b) {
    return (a == b) || (toupper(a) == b);
}

bool is_abbrev(string &a, string &b) {
    int m = a.length();
    int n = b.length();
    vector<vector<bool>> dp(m + 1, vector<bool>(n + 1, false));
    dp[0][0] = true;
    for (int i = 0; i < m; ++i) {
        if (islower(a[i])) dp[i+1][0] = dp[i][0];        
    }
    for (int i = 0; i < m; ++i) {
        for (int j = 0; j < n; ++j) {
            if (match(a[i], b[j])) {
                dp[i+1][j+1] = dp[i][j] || (islower(a[i]) && dp[i][j+1]);
            } else if (islower(a[i])) {
                dp[i+1][j+1] = dp[i][j+1];
            }
        }        
    }
    return dp[m][n];
}

string abbreviation(string a, string b) {
    string result = is_abbrev(a, b) ? "YES" : "NO";
    cout << result << endl;
    return result;
}
