#include <bits/stdc++.h>
using namespace std;
const int m = 51, k = 26;
int n;
string second, t[2];
int a[2][m][k];
int dp[m][m], dp2[m][m];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> second;
  for (int i = 0; i < 2; i++) {
    cin >> t[i];
    for (int j = 0; j < t[i].size(); j++) {
      int x = t[i][j] - 'a', y = a[i][j][x];
      a[i][j][x] = j + 1;
      memcpy(a[i][j + 1], a[i][y], sizeof(a[i][y]));
    }
  }
  memset(dp, 0xcf, sizeof(dp));
  dp[0][0] = 0;
  for (char i : second) {
    memcpy(dp2, dp, sizeof(dp));
    memset(dp, 0xcf, sizeof(dp));
    for (int j = 0; j <= t[0].size(); j++)
      for (int l = 0; l <= t[1].size(); l++)
        for (int p = 0; p < k; p++)
          if (i == 'a' + p || i == '*') {
            int x = a[0][j][p], y = a[1][l][p];
            dp[x][y] = max(dp[x][y],
                           dp2[j][l] + (x == t[0].size()) - (y == t[1].size()));
          }
  }
  int ret = 0xcfcfcfcf;
  for (int i = 0; i <= t[0].size(); i++)
    for (int j = 0; j <= t[1].size(); j++) {
      ret = max(ret, dp[i][j]);
    }
  cout << ret << '\n';
  return 0;
}
