#include <bits/stdc++.h>
using namespace std;
string c, s, t;
int dp[1005][55][55];
vector<int> pt, ps;
vector<vector<int> > ppt, pps;
void KMP(string a, vector<int> &p) {
  int k = 0;
  for (int i = 1; i < a.size(); ++i) {
    while (k > 0 && a[i] != a[k]) k = p[k - 1];
    if (a[k] == a[i]) ++k;
    p[i] = k;
  }
}
void cmp(string a, vector<int> p, vector<vector<int> > &q) {
  for (int i = 0; i < a.size(); ++i)
    for (char r = 'a'; r <= 'z'; ++r) {
      int k = i;
      while (k > 0 && a[k] != r) k = p[k - 1];
      if (a[k] == r) ++k;
      q[r - 'a'][i] = k;
    }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> c >> s >> t;
  s = s + ' ';
  t = t + ' ';
  int lc = c.size(), ls = s.size(), lt = t.size();
  pps.resize(30, vector<int>(s.size() + 5));
  ppt.resize(30, vector<int>(t.size() + 5));
  pt.resize(t.size() + 5, 0);
  ps.resize(s.size() + 5, 0);
  for (int i = 0; i < lc + 5; ++i)
    for (int j = 0; j < ls + 5; ++j)
      for (int k = 0; k < lt + 5; ++k) dp[i][j][k] = -1000000007;
  KMP(s, ps);
  KMP(t, pt);
  cmp(s, ps, pps);
  cmp(t, pt, ppt);
  dp[0][0][0] = 0;
  for (int k = 0; k < lc; ++k)
    for (int i = 0; i < ls; ++i)
      for (int j = 0; j < lt; ++j)
        for (char x = 'a'; x <= 'z'; ++x)
          if (c[k] == x || c[k] == '*') {
            int rs = pps[x - 'a'][i], rt = ppt[x - 'a'][j];
            int r = dp[k][i][j] + (rs == ls - 1) - (rt == lt - 1);
            dp[k + 1][rs][rt] = max(dp[k + 1][rs][rt], r);
          }
  int res = -99999999;
  for (int i = 0; i < ls; ++i)
    for (int j = 0; j < lt; ++j) res = max(res, dp[lc][i][j]);
  printf("%d", res);
  return 0;
}
