#include <bits/stdc++.h>
long long int const MOD = 1000000007;
long long int const N = 10005;
long long int const LN = 20;
long long int const inf = 1e18;
using namespace std;
long long int n, m, a[N];
long long int nxts[55][30];
long long int nxtt[55][30];
long long int dp[1005][55][55];
void fn(string second, long long int nxt[][30]) {
  long long int sz = second.size();
  vector<long long int> kmp(sz + 1);
  kmp[1] = 0;
  for (long long int i = 2; i < sz; i++) {
    long long int j = kmp[i - 1];
    while (j > 0 && second[j + 1] != second[i]) j = kmp[j];
    if (second[j + 1] == second[i]) j++;
    kmp[i] = j;
  }
  for (long long int i = 0; i < sz; i++) {
    for (long long int j = 0; j <= 'z' - 'a'; j++) {
      long long int cur = i;
      while (cur > 0 && second[cur + 1] - 'a' != j) cur = kmp[cur];
      if (second[cur + 1] == j + 'a') cur++;
      nxt[i][j] = cur;
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  string str;
  cin >> str;
  string second, t;
  cin >> second >> t;
  second = " " + second;
  t = " " + t;
  str = " " + str;
  fn(second, nxts);
  fn(t, nxtt);
  for (long long int i = 0; i < 1005; i++)
    for (long long int j = 0; j < 55; j++)
      for (long long int k = 0; k < 55; k++) dp[i][j][k] = -inf;
  dp[0][0][0] = 0;
  for (long long int i = 0; i < str.size(); i++) {
    for (long long int j = 0; j < second.size(); j++) {
      for (long long int k = 0; k < t.size(); k++) {
        for (char kk = 'a'; kk <= 'z'; kk++) {
          if (str[i + 1] == '*' || str[i + 1] == kk) {
            if (dp[i][j][k] == -inf) continue;
            long long int nexts = nxts[j][kk - 'a'];
            long long int nextt = nxtt[k][kk - 'a'];
            long long int temp = dp[i][j][k] +
                                 (nexts == ((long long int)second.size() - 1)) -
                                 (nextt == ((long long int)t.size() - 1));
            dp[i + 1][nexts][nextt] = max(dp[i + 1][nexts][nextt], temp);
          }
        }
      }
    }
  }
  long long int ans = -inf;
  for (long long int j = 0; j < second.size(); j++) {
    for (long long int k = 0; k < t.size(); k++)
      ans = max(ans, dp[(long long int)str.size() - 1][j][k]);
  }
  cout << ans;
  return 0;
}
