#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > match_matrix(string s) {
  vector<vector<int> > match(s.size(), vector<int>(int('z' - 'a' + 1), 0));
  for (int i = 0; i < int(s.size()); ++i) {
    for (int j = 0; j < int('z' - 'a' + 1); ++j) {
      string t = s.substr(0, i) + char('a' + j);
      int len = min(int(s.size()) - 1, int(t.size()));
      for (; len > 0 && s.substr(0, len) != t.substr(int(t.size()) - len);) {
        --len;
      }
      match[i][j] = len;
    }
  }
  return match;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  const int INF = 1000000000;
  string c, s, t;
  cin >> c >> s >> t;
  vector<vector<int> > ms = match_matrix(s);
  vector<vector<int> > mt = match_matrix(t);
  vector<vector<int> > b(s.size(), vector<int>(t.size(), -INF));
  b[0][0] = 0;
  for (int ic = 0; ic < int(c.size()); ++ic) {
    vector<vector<int> > b2(s.size(), vector<int>(t.size(), -INF));
    for (int is = 0; is < int(s.size()); ++is) {
      for (int it = 0; it < int(t.size()); ++it) {
        if (b[is][it] == -INF) continue;
        for (int i = 0; i < int('z' - 'a' + 1); ++i) {
          if (c[ic] != '*' && char('a' + i) != c[ic]) continue;
          int df = 0;
          if (is == int(s.size()) - 1 && s[is] == char('a' + i)) ++df;
          if (it == int(t.size()) - 1 && t[it] == char('a' + i)) --df;
          int is2 = ms[is][i];
          int it2 = mt[it][i];
          b2[is2][it2] = max(b2[is2][it2], b[is][it] + df);
        }
      }
    }
    swap(b, b2);
  }
  int ans = -INF;
  for (int i = 0; i < int(s.size()); ++i) {
    for (int j = 0; j < int(t.size()); ++j) {
      ans = max(ans, b[i][j]);
    }
  }
  cout << ans << endl;
}
