#include <bits/stdc++.h>
using namespace std;
const int oo = 1e9 + 5;
const int maxn = 1005;
const int maxs = 55;
int dp[maxn][maxs][maxs];
string ss, s1, s2;
vector<int> linka, linkb;
int cal(int pos, int a, int b) {
  if (a == ((int)s1.size()) || b == ((int)s2.size())) {
    assert(false);
  }
  if (pos == ((int)ss.size())) return 0;
  if (dp[pos][a][b] != -oo) return dp[pos][a][b];
  int res = -oo;
  for (int i = (0); i < (26); i++) {
    int la = a, lb = b;
    int g = 0;
    if (ss[pos] != '*') {
      if (ss[pos] - 'a' != i) continue;
    }
    if (s1[a] - 'a' != i) {
      a--;
      while (a >= 0 && s1[a + 1] - 'a' != i) {
        a = linka[a];
      }
      if (s1[a + 1] - 'a' == i) a++;
    }
    if (a == ((int)s1.size()) - 1) {
      g += 1;
      a = linka[a];
    }
    if (s2[b] - 'a' != i) {
      b--;
      while (b >= 0 && s2[b + 1] - 'a' != i) {
        b = linkb[b];
      }
      if (s2[b + 1] - 'a' == i) b++;
    }
    if (b == ((int)s2.size()) - 1) {
      g -= 1;
      b = linkb[b];
    }
    g += cal(pos + 1, a + 1, b + 1);
    res = max(res, g);
    a = la;
    b = lb;
  }
  return dp[pos][a][b] = res;
}
void build(string s, vector<int> &a) {
  a.resize(((int)s.size()));
  int cur = a[0] = -1;
  for (int i = (1); i < (((int)s.size())); i++) {
    while (cur >= 0 && s[i] != s[cur + 1]) cur = a[cur];
    if (s[i] == s[cur + 1]) cur++;
    a[i] = cur;
  }
}
int main() {
  cin >> ss;
  cin >> s1;
  build(s1, linka);
  cin >> s2;
  build(s2, linkb);
  for (int i = (0); i < (maxn); i++) {
    for (int j = (0); j < (maxs); j++) {
      for (int k = (0); k < (maxs); k++) {
        dp[i][j][k] = -oo;
      }
    }
  }
  cout << cal(0, 0, 0) << endl;
  return 0;
}
