#include <bits/stdc++.h>
using namespace std;
const int N = 1004;
int n, p, q, f[N][54][54], vc = 1000000000, ns[N][30], nt[N][30];
char c[N], s[N], t[N];
bool check1(int i, char x, int j) {
  if (i + 1 < j) return false;
  for (int k = 1; k < j; k++) {
    if (s[i + k - j + 1] != s[k]) return false;
  }
  if (x != s[j]) return false;
  return true;
}
bool check2(int i, char x, int j) {
  if (i + 1 < j) return false;
  for (int k = 1; k < j; k++) {
    if (t[i + k - j + 1] != t[k]) return false;
  }
  if (x != t[j]) return false;
  return true;
}
void build() {
  for (int i = 0; i <= p; i++) {
    for (char x = 'a'; x <= 'z'; x++) {
      for (int j = p; j >= 1; j--) {
        if (check1(i, x, j)) {
          ns[i][x - 'a' + 1] = j;
          break;
        }
      }
    }
  }
  for (int i = 0; i <= q; i++) {
    for (char x = 'a'; x <= 'z'; x++) {
      for (int j = q; j >= 1; j--) {
        if (check2(i, x, j)) {
          nt[i][x - 'a' + 1] = j;
          break;
        }
      }
    }
  }
}
int cal(int i, int x, int y) {
  if (i == n) return 0;
  if (f[i][x][y] != -vc) return f[i][x][y];
  f[i][x][y] = -vc + 1;
  if (c[i + 1] == '*') {
    for (char b = 'a'; b <= 'z'; b++) {
      int cost = 0;
      int nx1 = ns[x][b - 'a' + 1];
      if (nx1 == p) cost++;
      int nx2 = nt[y][b - 'a' + 1];
      if (nx2 == q) cost--;
      f[i][x][y] = max(f[i][x][y], cal(i + 1, nx1, nx2) + cost);
    }
  } else {
    int cost = 0;
    char b = c[i + 1];
    int nx1 = ns[x][b - 'a' + 1];
    if (nx1 == p) cost++;
    int nx2 = nt[y][b - 'a' + 1];
    if (nx2 == q) cost--;
    f[i][x][y] = max(f[i][x][y], cal(i + 1, nx1, nx2) + cost);
  }
  return f[i][x][y];
}
int main() {
  scanf("%s%s%s", c + 1, s + 1, t + 1);
  p = strlen(s + 1);
  q = strlen(t + 1);
  n = strlen(c + 1);
  build();
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= p; j++) {
      for (int z = 0; z <= q; z++) f[i][j][z] = -vc;
    }
  }
  cout << cal(0, 0, 0);
}
