#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 14, maxs = 55, z = 26;
int n, m, k, nxts[maxn][z], nxtt[maxn][z];
string c, s, t;
int dp[maxn][maxs][maxs];
void build(string p, int nxt[maxn][z]) {
  int f[maxs] = {};
  int k = 0;
  for (int i = 1; i < p.size(); i++) {
    while (k && p[k] != p[i]) k = f[k];
    if (p[k] == p[i]) k++;
    f[i + 1] = k;
  }
  for (int i = 0; i <= p.size(); i++)
    for (int j = 0; j < z; j++)
      nxt[i][j] = i < p.size() && p[i] == 'a' + j ? i + 1 : nxt[f[i]][j];
}
void smax(int &a, int b) { a = max(a, b); }
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> c >> s >> t;
  n = c.size(), m = s.size(), k = t.size();
  build(s, nxts);
  build(t, nxtt);
  memset(dp, -63, sizeof dp);
  dp[0][0][0] = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j <= m; j++)
      for (int p = 0; p <= k; p++) {
        auto shift = [&](char c) {
          smax(dp[i + 1][nxts[j][c]][nxtt[p][c]],
               dp[i][j][p] + (nxts[j][c] == m) - (nxtt[p][c] == k));
        };
        if (c[i] == '*')
          for (int x = 0; x < z; x++) shift(x);
        else
          shift(c[i] - 'a');
      }
  cout << *max_element(dp[n][0], dp[n + 1][0]) << '\n';
}
