#include <bits/stdc++.h>
using namespace std;
const long long int N = 1e3 + 5;
long long int dp[N][55][55];
long long int lps1[55];
long long int lps2[55];
string s;
string a, b;
void H1() {
  long long int i = 1, len = 0;
  lps1[0] = 0;
  while (i < a.size()) {
    if (a[i] == a[len]) {
      len++;
      lps1[i] = len;
      i++;
    } else {
      if (len)
        len = lps1[len - 1];
      else
        i++;
    }
  }
}
void H2() {
  long long int i = 1, len = 0;
  lps2[0] = 0;
  while (i < b.size()) {
    if (b[i] == b[len]) {
      len++;
      lps2[i] = len;
      i++;
    } else {
      if (len)
        len = lps2[len - 1];
      else
        i++;
    }
  }
}
long long int solve(long long int i, long long int j, long long int k) {
  if (i == s.size()) return 0;
  long long int n = a.size();
  long long int m = b.size();
  if (dp[i][j][k] == -N * N * N) {
    dp[i][j][k] = -N * N * N * N;
    long long int st = 0, ed = 26;
    if (s[i] != '*') {
      st = s[i] - 'a';
      ed = st + 1;
    }
    for (long long int z = st; z < ed; ++z) {
      long long int c1 = 0, c2 = 0;
      long long int tp = j;
      while (tp) {
        if (a[tp] == 'a' + z) {
          c1 = tp + 1;
          break;
        } else
          tp = lps1[tp - 1];
      }
      if (c1 == 0 && a[0] == 'a' + z) c1++;
      tp = k;
      while (tp) {
        if (b[tp] == 'a' + z) {
          c2 = tp + 1;
          break;
        } else
          tp = lps2[tp - 1];
      }
      if (c2 == 0 & b[0] == 'a' + z) c2++;
      long long int c = 0;
      if (c1 == n) {
        c++;
        c1 = lps1[c1 - 1];
      }
      if (c2 == m) {
        c--;
        c2 = lps2[c2 - 1];
      }
      dp[i][j][k] = max(dp[i][j][k], c + solve(i + 1, c1, c2));
    }
  }
  return dp[i][j][k];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> s >> a >> b;
  for (long long int i = 0; i < N - 1; ++i) {
    for (long long int j = 0; j < 54; ++j) {
      for (long long int k = 0; k < 54; ++k) {
        dp[i][j][k] = -N * N * N;
      }
    }
  }
  H1();
  H2();
  cout << solve(0, 0, 0) << "\n";
  return 0;
}
