#include <bits/stdc++.h>
using namespace std;
const long long MOD = (1e9 + 7);
const long long INF = (1e9 + 123456789);
const long long INFL = (INF * INF);
inline long long addm(long long a, long long b, long long m = MOD) {
  return ((a + b) % m);
}
inline long long subm(long long a, long long b, long long m = MOD) {
  return (((a - b) % m + m) % m);
}
inline long long mulm(long long a, long long b, long long m = MOD) {
  return ((a * b) % m);
}
long long powm(long long a, long long b, long long m = MOD) {
  long long ret = (!b) ? 1 : powm(a, b / 2, m);
  return (!b) ? 1 : mulm(mulm(ret, ret, m), b % 2 ? a : 1, m);
}
long long inv(long long x, long long m = MOD) { return powm(x, m - 2, m); }
const int N = 2050;
const int M = 150;
string c, s, t;
int fs[M], ft[M];
int mem[N][M][M];
bool vis[N][M][M];
int dp(int pc, int ps, int pt) {
  if (ps == (static_cast<int>(s.size()))) return dp(pc, fs[ps - 1], pt) + 1;
  if (pt == (static_cast<int>(t.size()))) return dp(pc, ps, ft[pt - 1]) - 1;
  if (pc == (static_cast<int>(c.size()))) return 0;
  int &ret = mem[pc][ps][pt];
  if (vis[pc][ps][pt]) return ret;
  vis[pc][ps][pt] = true;
  ret = -INF;
  auto nex = [&](char ch) {
    int gs = ps, gt = pt;
    while (gs > 0 && s[gs] != ch) gs = fs[gs - 1];
    while (gt > 0 && t[gt] != ch) gt = ft[gt - 1];
    return dp(pc + 1, gs + (s[gs] == ch), gt + (t[gt] == ch));
  };
  if (c[pc] == '*') {
    for (int i = 0; i < 26; i++) {
      char ch = static_cast<char>(i + 'a');
      ret = max(ret, nex(ch));
    }
  } else
    ret = nex(c[pc]);
  return ret;
}
void solve() {
  cin >> c >> s >> t;
  for (int i = 1; i < (static_cast<int>(s.size())); ++i) {
    int j = fs[i - 1];
    while (j > 0 && s[i] != s[j]) j = fs[j - 1];
    if (s[i] == s[j]) ++j;
    fs[i] = j;
  }
  for (int i = 1; i < (static_cast<int>(t.size())); ++i) {
    int j = ft[i - 1];
    while (j > 0 && t[i] != t[j]) j = ft[j - 1];
    if (t[i] == t[j]) ++j;
    ft[i] = j;
  }
  cout << dp(0, 0, 0) << "\n";
}
int main() {
  cin.sync_with_stdio(0);
  solve();
  return 0;
}
