#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fll;
vector<int> pi(string second) {
  vector<int> p(second.size());
  for (int i = 1, j = 0; i < second.size(); i++) {
    while (j and second[j] != second[i]) j = p[j - 1];
    if (second[j] == second[i]) j++;
    p[i] = j;
  }
  return p;
}
struct autKMP {
  vector<vector<int>> nxt;
  autKMP() {}
  autKMP(string& second) : nxt(26, vector<int>(second.size() + 1)) {
    vector<int> p = pi(second);
    nxt[second[0] - 'a'][0] = 1;
    for (char c = 0; c < 26; c++)
      for (int i = 1; i <= second.size(); i++)
        nxt[c][i] = second[i] - 'a' == c ? i + 1 : nxt[c][p[i - 1]];
  }
};
string c, second, t;
int dp[1010][55][55];
autKMP aut_s, aut_t;
int solve(int p, int i, int j) {
  if (p == c.size()) {
    int ans = 0;
    if (i == second.size()) ans++;
    if (j == t.size()) ans--;
    return ans;
  }
  auto& x = dp[p][i][j];
  if (x != INF) return x;
  int add = 0;
  if (i == second.size()) add++;
  if (j == t.size()) add--;
  if (c[p] != '*')
    return x = solve(p + 1, aut_s.nxt[c[p] - 'a'][i],
                     aut_t.nxt[c[p] - 'a'][j]) +
               add;
  x = -INF;
  for (int C = 0; C < 26; C++)
    x = max(x, solve(p + 1, aut_s.nxt[C][i], aut_t.nxt[C][j]));
  return x += add;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> c >> second >> t;
  aut_s = autKMP(second);
  aut_t = autKMP(t);
  memset(dp, INF, sizeof(dp));
  cout << solve(0, 0, 0) << '\n';
  exit(0);
}
