#include <bits/stdc++.h>
using namespace std;
template <class T>
void PVecPrint(vector<T> &v) {
  for (int i = 0; i < (int)v.size(); i++)
    cout << v[i].first << "," << v[i].second << ' ';
  cout << '\n';
}
template <class T>
void VecPrint(vector<T> &v) {
  for (int i = 0; i < v.size(); i++) cout << v[i] << ' ';
  cout << '\n';
}
string c, s, t;
int dp[1005][55][55];
vector<int> pref(string &s) {
  int n = s.length();
  vector<int> ans(n);
  ans[0] = 0;
  for (int i = 1; i < n; i++) {
    int j = ans[i - 1];
    while (j > 0 and s[j] != s[i]) {
      j = ans[j - 1];
    }
    if (s[j] == s[i]) ++j;
    ans[i] = j;
  }
  return ans;
}
int func(vector<int> &v, int ind, char c, string &s) {
  if (ind < s.length() and s[ind] == c) return ind + 1;
  if (ind == 0) return 0;
  int j = v[ind - 1];
  while (j > 0 and s[j] != c) j = v[j - 1];
  if (s[j] == c) ++j;
  return j;
}
int main() {
  cin >> c >> s >> t;
  int n1 = c.length(), n2 = s.length(), n3 = t.length();
  vector<int> ps = pref(s), pt = pref(t);
  int imp1[n2 + 1][26], imp2[n3 + 1][26];
  for (int i = 0; i <= n2; i++) {
    for (int j = 0; j < 26; j++) {
      char c = j + 97;
      imp1[i][j] = func(ps, i, c, s);
    }
  }
  for (int i = 0; i <= n3; i++) {
    for (int j = 0; j < 26; j++) {
      char c = j + 97;
      imp2[i][j] = func(pt, i, c, t);
    }
  }
  for (int i = 0; i < 1005; i++)
    for (int j = 0; j < 55; j++)
      for (int k = 0; k < 55; k++) dp[i][j][k] = -2000000000;
  dp[0][0][0] = 0;
  for (int i = 1; i <= n1; i++) {
    int val = c[i - 1] - 'a';
    for (int t = 0; t < 26; t++) {
      if (c[i - 1] != '*' and val != t) continue;
      for (int j = 0; j <= n2; j++) {
        for (int k = 0; k <= n3; k++) {
          if (dp[i - 1][j][k] == -2000000000) continue;
          int ans = dp[i - 1][j][k];
          if (j == n2) ++ans;
          if (k == n3) --ans;
          int nind1 = imp1[j][t], nind2 = imp2[k][t];
          dp[i][nind1][nind2] = max(dp[i][nind1][nind2], ans);
        }
      }
    }
  }
  int ans = -2000000000;
  for (int i = 0; i <= n2; i++) {
    for (int j = 0; j <= n3; j++) {
      int t = dp[n1][i][j];
      if (i == n2) ++t;
      if (j == n3) --t;
      ans = max(ans, t);
    }
  }
  cout << ans << '\n';
}
