#include <bits/stdc++.h>
using namespace std;
vector<string> vec_splitter(string s) {
  for (char& c : s) c = c == ',' ? ' ' : c;
  stringstream ss;
  ss << s;
  vector<string> res;
  for (string z; ss >> z; res.push_back(z))
    ;
  return res;
}
void debug_out(vector<string> args, int idx) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, Head H, Tail... T) {
  if (idx > 0) cerr << ", ";
  stringstream ss;
  ss << H;
  cerr << args[idx] << " = " << ss.str();
  debug_out(args, idx + 1, T...);
}
void localTest() {}
const long long N = 1e3 + 5, M = 55;
vector<long long> ls, lt;
string c, s, t;
long long dp[N][M][M];
bool memo[N][M][M];
vector<long long> prefixFunction(string st) {
  long long n = (long long)st.length();
  vector<long long> pi(n);
  for (long long i = 1; i < n; i++) {
    long long j = pi[i - 1];
    while (j > 0 && st[i] != st[j]) j = pi[j - 1];
    if (st[i] == st[j]) j++;
    pi[i] = j;
  }
  return pi;
}
long long doit(long long idx, long long is, long long it) {
  if (idx >= (long long)c.size()) {
    return 0;
  }
  long long& ret = dp[idx][is][it];
  if (memo[idx][is][it]) {
    return ret;
  }
  memo[idx][is][it] = 1;
  long long ans = -1e15;
  if (c[idx] != '*') {
    if (c[idx] == s[is]) {
      ++is;
    } else {
      while (is > 0 && c[idx] != s[is]) {
        is = ls[is - 1];
      }
      if (c[idx] == s[is]) {
        is++;
      }
    }
    if (c[idx] == t[it]) {
      ++it;
    } else {
      while (it > 0 && c[idx] != t[it]) {
        it = lt[it - 1];
      }
      if (c[idx] == t[it]) {
        it++;
      }
    }
    long long val = 0;
    if (is == (long long)s.size()) {
      is = ls[is - 1];
      ++val;
    }
    if (it == (long long)t.size()) {
      it = lt[it - 1];
      --val;
    }
    ans = max(ans, val + doit(idx + 1, is, it));
  } else {
    for (long long i = 0; i < 26; ++i) {
      char ch = (char)('a' + i);
      long long slcs = is, tlcs = it, val = 0;
      if (s[is] == ch) {
        ++slcs;
      } else {
        while (slcs > 0 && ch != s[slcs]) {
          slcs = ls[slcs - 1];
        }
        if (ch == s[slcs]) {
          slcs++;
        }
      }
      if (t[it] == ch) {
        ++tlcs;
      } else {
        while (tlcs > 0 && ch != t[tlcs]) {
          tlcs = lt[tlcs - 1];
        }
        if (ch == t[tlcs]) {
          tlcs++;
        }
      }
      if (slcs == (long long)s.size()) {
        slcs = ls[slcs - 1];
        ++val;
      }
      if (tlcs == (long long)t.size()) {
        tlcs = lt[tlcs - 1];
        --val;
      }
      ans = max(ans, val + doit(idx + 1, slcs, tlcs));
    }
  }
  return ret = ans;
}
int main() {
  localTest();
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> c >> s >> t;
  ls = prefixFunction(s);
  lt = prefixFunction(t);
  cout << doit(0, 0, 0) << "\n";
  return 0;
}
