#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5;
const int MAX_SZ = 55;
const int INF = 1e6;
vector<int> failure_function(string &s) {
  int n = (int)s.size();
  vector<int> ff(n, 0);
  for (int i = 1; i < n; i++) {
    int j = ff[i - 1];
    while (j > 0 && s[i] != s[j]) j = ff[j - 1];
    ff[i] = j + (s[i] == s[j]);
  }
  return ff;
}
vector<int> f[2];
string c, s[2];
int mem[N][26][2];
int nxt_state(int st, char ch, int id) {
  if (mem[st][ch - 'a'][id] != -1) return mem[st][ch - 'a'][id];
  while (st > 0 && s[id][st] != ch) st = f[id][st - 1];
  return mem[st][ch - 'a'][id] = st + (s[id][st] == ch);
}
int dp[N][MAX_SZ][MAX_SZ];
int ans = -INF;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> c;
  cin >> s[0] >> s[1];
  int n = (int)c.size();
  f[0] = failure_function(s[0]);
  f[1] = failure_function(s[1]);
  memset(mem, -1, sizeof(mem));
  for (int i = 0; i <= n; i++)
    for (int j = 0; j < MAX_SZ; j++)
      for (int k = 0; k < MAX_SZ; k++) dp[i][j][k] = -INF;
  dp[0][0][0] = 0;
  for (int i = 1; i <= n; i++) {
    if (c[i - 1] == '*') {
      for (char ch = 'a'; ch <= 'z'; ch++)
        for (int st0 = 0; st0 <= (int)s[0].size(); st0++)
          for (int st1 = 0; st1 <= (int)s[1].size(); st1++) {
            int to0 = nxt_state(st0, ch, 0);
            int to1 = nxt_state(st1, ch, 1);
            int dlt = 0;
            if (to0 == (int)s[0].size()) {
              dlt++;
              to0 = f[0].back();
            }
            if (to1 == (int)s[1].size()) {
              dlt--;
              to1 = f[1].back();
            }
            dp[i][to0][to1] = max(dp[i][to0][to1], dp[i - 1][st0][st1] + dlt);
          }
    } else {
      char ch = c[i - 1];
      for (int st0 = 0; st0 <= (int)s[0].size(); st0++)
        for (int st1 = 0; st1 <= (int)s[1].size(); st1++) {
          int to0 = nxt_state(st0, ch, 0);
          int to1 = nxt_state(st1, ch, 1);
          int dlt = 0;
          if (to0 == (int)s[0].size()) {
            dlt++;
            to0 = f[0].back();
          }
          if (to1 == (int)s[1].size()) {
            dlt--;
            to1 = f[1].back();
          }
          dp[i][to0][to1] = max(dp[i][to0][to1], dp[i - 1][st0][st1] + dlt);
        }
    }
  }
  for (int i = 0; i <= (int)s[0].size(); i++)
    for (int j = 0; j <= (int)s[1].size(); j++) ans = max(ans, dp[n][i][j]);
  cout << ans << endl;
  return 0;
}
