#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 5;
int dp[1005][55][55];
int nxt1[55], nxt2[55];
char s[1005], s1[55], s2[55];
int len1, len2, len, k, w;
void init() {
  k = -1;
  nxt1[0] = -1;
  for (int i = 1; i < len1; i++) {
    while (k != -1 && s1[k + 1] != s1[i]) k = nxt1[k];
    if (s1[k + 1] == s1[i]) {
      nxt1[i] = k + 1;
      k++;
    } else
      nxt1[i] = -1;
  }
  k = -1;
  nxt2[0] = -1;
  for (int i = 1; i < len2; i++) {
    while (k != -1 && s2[k + 1] != s2[i]) k = nxt2[k];
    if (s2[k + 1] == s2[i]) {
      nxt2[i] = k + 1;
      k++;
    } else
      nxt2[i] = -1;
  }
}
int a, b;
void getfail(int p1, int p2, int c) {
  while (s1[p1 + 1] != c && p1 != -1) p1 = nxt1[p1];
  if (s1[p1 + 1] == c)
    a = p1 + 1;
  else
    a = -1;
  while (s2[p2 + 1] != c && p2 != -1) p2 = nxt2[p2];
  if (s2[p2 + 1] == c)
    b = p2 + 1;
  else
    b = -1;
}
int ans = -INF;
int main() {
  cin >> s >> s1 >> s2;
  len = strlen(s);
  len1 = strlen(s1);
  len2 = strlen(s2);
  for (int i = 0; i <= len + 1; i++)
    for (int j = 0; j <= len1 + 1; j++)
      for (int k = 0; k <= len2 + 1; k++) {
        dp[i][j][k] = -INF;
      }
  init();
  dp[0][0][0] = 0;
  for (int i = 0; i < len; i++) {
    for (int j = 0; j <= len1; j++) {
      for (int k = 0; k <= len2; k++) {
        if (s[i] != '*') {
          if (dp[i][j][k] == -INF) continue;
          getfail(j - 1, k - 1, s[i]);
          int d = ((a + 1) == len1) - ((b + 1) == len2);
          dp[i + 1][a + 1][b + 1] =
              max(dp[i + 1][a + 1][b + 1], dp[i][j][k] + d);
        } else {
          for (int l = 'a'; l <= 'z'; l++) {
            getfail(j - 1, k - 1, l);
            int d = ((a + 1) == len1) - ((b + 1) == len2);
            dp[i + 1][a + 1][b + 1] =
                max(dp[i + 1][a + 1][b + 1], dp[i][j][k] + d);
          }
        }
      }
    }
  }
  for (int j = 0; j <= len1; j++) {
    for (int k = 0; k <= len2; k++) ans = max(ans, dp[len][j][k]);
  }
  cout << ans;
}
