#include <bits/stdc++.h>
using namespace std;
int a[1000005];
vector<int> z_function(string s) {
  int n = (int)s.length();
  vector<int> z(n);
  for (int i = 1, l = 0, r = 0; i < n; ++i) {
    if (i <= r) z[i] = min(r - i + 1, z[i - l]);
    while (i + z[i] < n && s[z[i]] == s[i + z[i]]) ++z[i];
    if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1;
  }
  return z;
}
int match1, match2;
string str, s, t;
int dp[1001][51][51];
int ncurs[1001][26], ncurt[1001][26];
int rec(int id, int curs, int curt) {
  int an = 0;
  int ps = curs, pt = curt;
  if (curs == s.length()) {
    curs = match1;
    an++;
  }
  if (curt == t.length()) {
    curt = match2;
    an--;
  }
  if (id == str.length()) {
    return an;
  }
  if (dp[id][ps][pt] != -1e9) {
    return dp[id][ps][pt];
  }
  int curs2, curt2;
  if (str[id] != '*') {
    int i = str[id] - 'a';
    curs2 = ncurs[curs][i];
    curt2 = ncurt[curt][i];
    return dp[id][ps][pt] = an + rec(id + 1, curs2, curt2);
  } else {
    int an2 = -1e9;
    for (int i = 0; i < 26; i++) {
      curs2 = ncurs[curs][i];
      curt2 = ncurt[curt][i];
      an2 = max(an2, rec(id + 1, curs2, curt2));
    }
    return dp[id][ps][pt] = an2 + an;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  int i, j, k, l, m, n;
  cin >> str;
  cin >> s >> t;
  vector<int> zs = z_function(s);
  for (i = 0; i < s.length(); i++) {
    if (i + zs[i] == s.length()) {
      match1 = zs[i];
      break;
    }
  }
  for (int curs = 0; curs < s.length(); curs++) {
    for (int j = 0; j < 26; j++) {
      string ns = s.substr(0, curs) + (char)(j + 'a');
      ncurs[curs][j] = 0;
      for (i = 0; i < ns.length(); i++) {
        string toComp = ns.substr(i, ns.length() - i);
        if (toComp == s.substr(0, toComp.length())) {
          ncurs[curs][j] = toComp.length();
          break;
        }
      }
    }
  }
  for (int curt = 0; curt < t.length(); curt++) {
    for (int j = 0; j < 26; j++) {
      string nt = t.substr(0, curt) + (char)(j + 'a');
      ncurt[curt][j] = 0;
      for (i = 0; i < nt.length(); i++) {
        string toComp = nt.substr(i, nt.length() - i);
        if (toComp == t.substr(0, toComp.length())) {
          ncurt[curt][j] = toComp.length();
          break;
        }
      }
    }
  }
  vector<int> zt = z_function(t);
  for (i = 0; i < t.length(); i++) {
    if (i + zt[i] == t.length()) {
      match2 = zt[i];
      break;
    }
  }
  for (i = 0; i < 1001; i++) {
    for (j = 0; j < 51; j++) {
      for (k = 0; k < 51; k++) {
        dp[i][j][k] = -1e9;
      }
    }
  }
  cout << rec(0, 0, 0) << endl;
}
