#include <bits/stdc++.h>
using namespace std;
const long long int N = 101;
string code, s, t;
long long int lps_s[N][26], lps_t[N][26];
void lps(string str) {
  long long int n = str.size();
  long long int lps[n + 1];
  lps[0] = 0;
  for (long long int i = 1; i < n; i++) {
    long long int pos = lps[i - 1];
    while (pos > 0 && str[pos] != str[i]) pos = lps[pos - 1];
    if (str[pos] == str[i]) pos++;
    lps[i] = pos;
  }
  for (long long int j = 0; j <= n; j++) {
    for (char ch = 'a'; ch <= 'z'; ch++) {
      long long int pos = j;
      while (pos > 0 && ch != str[pos]) pos = lps[pos - 1];
      if (str[pos] == ch) pos++;
      if (str == s)
        lps_s[j][ch - 'a'] = pos;
      else
        lps_t[j][ch - 'a'] = pos;
    }
  }
}
int main() {
  cin >> code >> s >> t;
  lps(s);
  lps(t);
  long long int dp[code.size() + 1][s.size() + 1][t.size() + 1];
  long long int n = code.size(), m = s.size(), p = t.size();
  for (long long int i = 0; i <= n; i++)
    for (long long int j = 0; j <= m; j++)
      for (long long int k = 0; k <= p; k++) dp[i][j][k] = -1E17;
  dp[0][0][0] = 0;
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j <= m; j++) {
      for (long long int k = 0; k <= p; k++) {
        for (char ch = 'a'; ch <= 'z'; ch++) {
          if (code[i] == ch || code[i] == '*') {
            long long int kmp_s = lps_s[j][ch - 'a'];
            long long int kmp_t = lps_t[k][ch - 'a'];
            long long int cnt1 = 0;
            if (kmp_s == m) cnt1++;
            if (kmp_t == p) cnt1--;
            long long int temp = dp[i][j][k] + cnt1;
            dp[i + 1][kmp_s][kmp_t] = max(dp[i + 1][kmp_s][kmp_t], temp);
          }
        }
      }
    }
  }
  long long int mx = -1E17;
  for (long long int i = 0; i <= m; i++) {
    for (long long int j = 0; j <= p; j++) {
      mx = max(mx, dp[n][i][j]);
    }
  }
  cout << mx;
  return 0;
}
