#include <bits/stdc++.h>
using namespace std;
const int N = 1000 + 5;
int n, p, q;
int fa[N], fb[N];
char s[N], a[55], b[55];
int dp[N][55][55];
int put_a[55][30], put_b[55][30];
int main() {
  scanf("%s %s %s", s + 1, a + 1, b + 1);
  n = strlen(s + 1);
  p = strlen(a + 1);
  q = strlen(b + 1);
  {
    int qq = 0;
    for (int i = 2; i <= p; i++) {
      while (qq and a[qq + 1] != a[i]) qq = fa[qq];
      if (a[qq + 1] == a[i]) qq++;
      fa[i] = qq;
    }
    for (int i = 0; i < p; i++) {
      for (int c = 'a'; c <= 'z'; c++) {
        int q = i;
        while (q and a[q + 1] != c) q = fa[q];
        if (a[q + 1] == c) q++;
        put_a[i][c - 'a'] = q;
      }
    }
  }
  {
    int qq = 0;
    for (int i = 2; i <= q; i++) {
      while (qq and b[qq + 1] != b[i]) qq = fb[qq];
      if (b[qq + 1] == b[i]) qq++;
      fb[i] = qq;
    }
    for (int i = 0; i < q; i++) {
      for (int c = 'a'; c <= 'z'; c++) {
        int q = i;
        while (q and b[q + 1] != c) q = fb[q];
        if (b[q + 1] == c) q++;
        put_b[i][c - 'a'] = q;
      }
    }
  }
  for (int x = n; x >= 1; x--) {
    for (int qa = 0; qa <= p; qa++) {
      for (int qb = 0; qb <= q; qb++) {
        if (s[x] != '*') {
          int nqa = put_a[qa][s[x] - 'a'];
          int nqb = put_b[qb][s[x] - 'a'];
          int gain = (nqa == p) - (nqb == q);
          if (nqa == p) nqa = fa[nqa];
          if (nqb == q) nqb = fb[nqb];
          dp[x][qa][qb] = dp[x + 1][nqa][nqb] + gain;
        } else {
          dp[x][qa][qb] = -1e9;
          for (int i = 0; i < 26; i++) {
            int nqa = put_a[qa][i];
            int nqb = put_b[qb][i];
            int gain = (nqa == p) - (nqb == q);
            if (nqa == p) nqa = fa[nqa];
            if (nqb == q) nqb = fb[nqb];
            dp[x][qa][qb] = max(dp[x][qa][qb], dp[x + 1][nqa][nqb] + gain);
          }
        }
      }
    }
  }
  printf("%d\n", dp[1][0][0]);
  return 0;
}
