#include <bits/stdc++.h>
using namespace std;
const int N = 1011;
const int M = 55;
const int INF = (int)1e9;
int n, m, l;
string s, t, c;
int f1[M][26], f2[M][26];
bool check(string x, string y, int len) {
  int k = (int)y.length() - 1;
  for (int i = len; i >= 1; --i) {
    if (y[k] != x[i]) return false;
    --k;
  }
  return true;
}
void init() {
  c = ' ' + c, s = ' ' + s, t = ' ' + t;
  string tmp = "";
  for (int i = 1; i <= n; ++i) {
    tmp = tmp + s[i];
    for (char j = 'a'; j <= 'z'; ++j) {
      string ns = tmp + j;
      for (int len = min(i + 1, n); len >= 0; --len) {
        if (check(s, ns, len)) {
          int k = j - 'a';
          f1[i][k] = len;
          break;
        }
      }
    }
  }
  tmp = "";
  for (int i = 1; i <= m; ++i) {
    tmp = tmp + t[i];
    for (char j = 'a'; j <= 'z'; ++j) {
      string ns = tmp + j;
      for (int len = min(i + 1, m); len >= 0; --len) {
        if (check(t, ns, len)) {
          int k = j - 'a';
          f2[i][k] = len;
          break;
        }
      }
    }
  }
  int k;
  k = s[1] - 'a';
  f1[0][k] = 1;
  k = t[1] - 'a';
  f2[0][k] = 1;
}
int dp[N][M][M];
void maximize(int &x, const int &y) { x = max(x, y); }
void solve() {
  cin >> c >> s >> t;
  l = (int)c.length();
  n = (int)s.length();
  m = (int)t.length();
  init();
  for (int i = 0; i <= l; ++i) {
    for (int j = 0; j <= n; ++j) {
      for (int k = 0; k <= m; ++k) {
        dp[i][j][k] = -INF;
      }
    }
  }
  dp[0][0][0] = 0;
  for (int i = 0; i < l; ++i) {
    for (int j = 0; j <= n; ++j) {
      for (int k = 0; k <= m; ++k) {
        if (c[i + 1] == '*') {
          for (int nt = 0; nt < 26; ++nt) {
            int _j = f1[j][nt];
            int _k = f2[k][nt];
            int tmp = dp[i][j][k] + (_j == n) - (_k == m);
            maximize(dp[i + 1][_j][_k], tmp);
          }
        } else {
          int nt = c[i + 1] - 'a';
          int _j = f1[j][nt];
          int _k = f2[k][nt];
          int tmp = dp[i][j][k] + (_j == n) - (_k == m);
          maximize(dp[i + 1][_j][_k], tmp);
        }
      }
    }
  }
  int res = -INF;
  for (int j = 0; j <= n; ++j) {
    for (int k = 0; k <= m; ++k) {
      maximize(res, dp[l][j][k]);
    }
  }
  cout << res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
