#include <bits/stdc++.h>
using namespace std;
const int oo = 2139063143;
const int N = 1010, M = 55;
const int P = 1000000007;
const double eps = 1e-7;
template <typename T>
inline void sc(T &x) {
  x = 0;
  static int p;
  p = 1;
  static char c;
  c = getchar();
  while (!isdigit(c)) {
    if (c == '-') p = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = (x << 1) + (x << 3) + (c - 48);
    c = getchar();
  }
  x *= p;
}
template <typename T>
inline void print(T x) {
  if (x < 0) putchar('-'), x = -x;
  if (x >= 10) print(x / 10);
  putchar(x % 10 + '0');
}
template <typename T>
inline void pr(T x) {
  print(x), putchar('\n');
}
template <typename T1, typename T2>
void chkmax(T1 &A, T2 B) {
  A = A >= B ? A : B;
}
template <typename T1, typename T2>
void chkmin(T1 &A, T2 B) {
  A = A <= B ? A : B;
}
struct ACAM {
  struct DATACAM {
    int fa, son[27];
    bool ed;
  } t[M];
  int tot = 1;
  void ins(char *s, int n) {
    int p = 1;
    for (int i = 1; i <= n; i++) {
      int c = s[i] - 'a' + 1, &v = t[p].son[c];
      if (!v) v = ++tot;
      p = v;
    }
    t[p].ed = 1;
  }
  void build() {
    queue<int> q;
    for (int c = 1; c <= 26; c++) {
      int &v = t[1].son[c];
      if (v)
        t[v].fa = 1, q.push(v);
      else
        v = 1;
    }
    while (q.size()) {
      int u = q.front(), f = t[u].fa;
      q.pop();
      for (int c = 1; c <= 26; c++) {
        int &v = t[u].son[c];
        if (!v)
          v = t[f].son[c];
        else
          t[v].fa = t[f].son[c], q.push(v);
      }
    }
  }
} S, T;
char a[N], s[M], t[M];
int f[N][M][M];
int main() {
  scanf("%s%s%s", a + 1, s + 1, t + 1);
  int G = strlen(a + 1), n = strlen(s + 1), m = strlen(t + 1);
  S.ins(s, n), T.ins(t, m);
  S.build(), T.build();
  memset(f, -127, sizeof(f));
  f[0][1][1] = 0;
  int ans = -oo;
  for (int i = 0; i <= G; i++)
    for (int x = 1; x <= S.tot; x++)
      for (int y = 1; y <= T.tot; y++)
        if (f[i][x][y] > -G) {
          if (i == G) {
            chkmax(ans, f[i][x][y]);
            continue;
          }
          char z = a[i + 1];
          for (int c = (z == '*' ? 1 : z - 'a' + 1);
               c <= (z == '*' ? 26 : z - 'a' + 1); c++) {
            int nx = S.t[x].son[c], ny = T.t[y].son[c];
            chkmax(f[i + 1][nx][ny], f[i][x][y] + S.t[nx].ed - T.t[ny].ed);
          }
        }
  pr(ans);
  return 0;
}
