#include <bits/stdc++.h>
using namespace std;
char c[1100], s[55], t[55];
int nc, ns, nt;
int pres[110], pret[110];
int dp[1100][55][55];
bool vis[1100][55][55];
int ans = -0x3f3f3f3f;
void upd(int i, int j, int k, int val) {
  if (!vis[i][j][k]) {
    vis[i][j][k] = 1;
    dp[i][j][k] = val;
  } else
    dp[i][j][k] = max(dp[i][j][k], val);
  if (i == nc) ans = max(ans, val);
}
int main() {
  scanf("%s", c + 1);
  scanf("%s", s + 1);
  scanf("%s", t + 1);
  nc = strlen(c + 1), ns = strlen(s + 1), nt = strlen(t + 1);
  pres[1] = 0;
  int h = 0;
  for (int i = 2; i <= ns; i++) {
    while (h > 0 && s[h + 1] != s[i]) h = pres[h];
    if (s[h + 1] == s[i]) h++;
    pres[i] = h;
  }
  pret[1] = 0;
  h = 0;
  for (int i = 2; i <= nt; i++) {
    while (h > 0 && t[h + 1] != t[i]) h = pret[h];
    if (t[h + 1] == t[i]) h++;
    pret[i] = h;
  }
  dp[0][0][0] = 0;
  vis[0][0][0] = 1;
  for (int i = 0; i < nc; i++)
    for (int j = 0; j <= ns; j++)
      for (int k = 0; k <= nt; k++)
        if (vis[i][j][k]) {
          char cur = c[i + 1];
          if (cur == '*') {
            for (cur = 'a'; cur <= 'z'; cur++) {
              int nj = j, nk = k, nval = dp[i][j][k];
              if (nj == ns) nj = pres[nj];
              if (nk == nt) nk = pret[nk];
              while (nj > 0 && s[nj + 1] != cur) nj = pres[nj];
              if (s[nj + 1] == cur) nj++;
              while (nk > 0 && t[nk + 1] != cur) nk = pret[nk];
              if (t[nk + 1] == cur) nk++;
              if (nj == ns) nval++;
              if (nk == nt) nval--;
              upd(i + 1, nj, nk, nval);
            }
          } else {
            int nj = j, nk = k, nval = dp[i][j][k];
            if (nj == ns) nj = pres[nj];
            if (nk == nt) nk = pret[nk];
            while (nj > 0 && s[nj + 1] != cur) nj = pres[nj];
            if (s[nj + 1] == cur) nj++;
            while (nk > 0 && t[nk + 1] != cur) nk = pret[nk];
            if (t[nk + 1] == cur) nk++;
            if (nj == ns) nval++;
            if (nk == nt) nval--;
            upd(i + 1, nj, nk, nval);
          }
        }
  cout << ans;
  return 0;
}
