#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int N = 57;
const int A = 26;
int sm[N][A], tmat[N][A];
string c, s, t;
const int L = 1007;
int dp[L][N][N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> c >> s >> t;
  int ns = s.size();
  int nt = t.size();
  s += "-";
  t += "-";
  for (int i = 0; i <= ns; ++i) {
    string sub = s.substr(0, i);
    for (int ch = 0; ch < A; ++ch) {
      string asub = sub + (char)('a' + ch);
      for (int j = i + 1; j >= 0; --j) {
        string temp = s.substr(0, j);
        if (temp == asub.substr(asub.size() - temp.size())) {
          sm[i][ch] = j;
          break;
        }
      }
    }
  }
  for (int i = 0; i <= nt; ++i) {
    string sub = t.substr(0, i);
    for (int ch = 0; ch < A; ++ch) {
      string asub = sub + (char)('a' + ch);
      for (int j = i + 1; j >= 0; --j) {
        string temp = t.substr(0, j);
        if (temp == asub.substr(asub.size() - temp.size())) {
          tmat[i][ch] = j;
          break;
        }
      }
    }
  }
  int n = c.size();
  for (int i = n - 1; i >= 0; --i) {
    int fr, to;
    if (c[i] == '*')
      fr = 0, to = A - 1;
    else
      fr = c[i] - 'a', to = c[i] - 'a';
    for (int ss = 0; ss <= ns; ++ss) {
      for (int tt = 0; tt <= nt; ++tt) {
        dp[i][ss][tt] = -inf;
        for (int ch = fr; ch <= to; ++ch) {
          int pss = sm[ss][ch];
          int ptt = tmat[tt][ch];
          int val = 0;
          if (pss == ns) ++val;
          if (ptt == nt) --val;
          dp[i][ss][tt] = max(dp[i][ss][tt], val + dp[i + 1][pss][ptt]);
        }
      }
    }
  }
  cout << dp[0][0][0] << "\n";
  return 0;
}
