#include <bits/stdc++.h>
using namespace std;
int dp[1005][55][55], dp1[55][26], dp2[55][26], hell = (-pow(10, 7)),
                                                inf = (-pow(10, 6));
void f(string s) {
  int n = int(s.size());
  string tr = s;
  reverse(tr.begin(), tr.end());
  for (int i = 0; i <= n; i++)
    for (int j = 0; j < 26; j++) {
      string t;
      for (int k = 0; k < i; k++) t.push_back(s[k]);
      t.push_back(char(j + 'a'));
      reverse(t.begin(), t.end());
      for (int k0 = 0; k0 < n; k0++) {
        int f = 0;
        if (int(t.size()) < n - k0) continue;
        for (int k1 = 0; k1 < n - k0; k1++)
          if (tr[k0 + k1] != t[k1]) f = 1;
        if (!f) {
          dp2[i][j] = n - k0;
          break;
        }
      }
    }
}
void solve() {
  string s, a, b;
  cin >> s >> a >> b;
  f(a);
  for (int i = 0; i <= int(a.size()); i++)
    for (int j = 0; j < 26; j++) {
      dp1[i][j] = dp2[i][j];
      dp2[i][j] = 0;
    }
  f(b);
  int n = int(s.size()), n0 = int(a.size()), n1 = int(b.size());
  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= n0; j++)
      for (int k = 0; k <= n1; k++) dp[i][j][k] = hell;
  dp[0][0][0] = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j <= n0; j++)
      for (int k = 0; k <= n1; k++)
        if (dp[i][j][k] > inf) {
          for (int c = 0; c < 26; c++) {
            if (s[i] != '*' && int(s[i] - 'a') != c) continue;
            int x = dp1[j][c], y = dp2[k][c], val = 0;
            if (x == n0 && y == n1)
              val = 0;
            else if (x == n0)
              val = 1;
            else if (y == n1)
              val = (-1);
            dp[i + 1][x][y] = max(dp[i + 1][x][y], dp[i][j][k] + val);
          }
        }
  int res = hell;
  for (int i = 0; i <= n0; i++)
    for (int j = 0; j <= n1; j++) res = max(res, dp[n][i][j]);
  cout << res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  clock_t z = clock();
  int qc = 1;
  for (int i = 1; i <= qc; i++) solve();
  fprintf(stderr, "Total Time:%.4Lf\n",
          (long double)(clock() - z) / CLOCKS_PER_SEC),
      fflush(stderr);
}
