#include <bits/stdc++.h>
using namespace std;
void computeLPSArray(char* s, int n, int* l) {
  l[0] = 0;
  for (int i = 1; i < n; ++i) {
    l[i] = 0;
    for (int k = i - 1; k >= 0; --k) {
      bool bl = 1;
      for (int j = 0; j <= k; ++j) {
        if (s[j] != s[i - k + j]) {
          bl = 0;
          break;
        }
      }
      if (bl) {
        l[i] = k + 1;
        break;
      }
    }
  }
}
int a[66], b[66], n, mem[1010][55][55], ns, nt;
char s[66], t[66], c[1111];
int mem2[55][55][33], mem3[55][55][33];
pair<int, int> foo(int x, int y, int z) {
  int tmp1 = x, tmp2 = y;
  while (1) {
    if (tmp1 == 0) {
      if (s[tmp1] - 'a' == z) {
        tmp1 = 1;
      }
      break;
    }
    if (s[tmp1] - 'a' == z) {
      ++tmp1;
      break;
    }
    tmp1 = a[tmp1 - 1];
  }
  while (1) {
    if (tmp2 == 0) {
      if (t[tmp2] - 'a' == z) {
        tmp2 = 1;
      }
      break;
    }
    if (t[tmp2] - 'a' == z) {
      ++tmp2;
      break;
    }
    tmp2 = b[tmp2 - 1];
  }
  mem2[x][y][z] = tmp1;
  mem3[x][y][z] = tmp2;
  return make_pair(tmp1, tmp2);
}
int dp(int x, int y, int z) {
  if (x == n) {
    return 0;
  }
  if (mem[x][y][z] != -1112) return mem[x][y][z];
  int res = -1111;
  pair<int, int> tmp;
  if (c[x] != '*') {
    tmp = make_pair(mem2[y][z][c[x] - 'a'], mem3[y][z][c[x] - 'a']);
    int tmp1 = (tmp.first == ns) - (tmp.second == nt);
    res = max(res, tmp1 + dp(x + 1, tmp.first, tmp.second));
  } else {
    for (int i = 0; i < 26; ++i) {
      tmp = make_pair(mem2[y][z][i], mem3[y][z][i]);
      int tmp1 = (tmp.first == ns) - (tmp.second == nt);
      res = max(res, tmp1 + dp(x + 1, tmp.first, tmp.second));
    }
  }
  mem[x][y][z] = res;
  return res;
}
int main() {
  scanf("%s%s%s", c, s, t);
  long long ans = 0;
  ns = strlen(s);
  nt = strlen(t);
  n = strlen(c);
  s[ns] = '#';
  s[ns + 1] = '\0';
  t[nt] = '#';
  t[nt + 1] = '\0';
  computeLPSArray(s, ns, a);
  computeLPSArray(t, nt, b);
  memset(mem, -1, sizeof mem);
  memset(mem2, -1, sizeof mem2);
  memset(mem3, -1, sizeof mem3);
  for (int i = 0; i <= ns; ++i) {
    for (int j = 0; j <= nt; ++j) {
      for (int k = 0; k < 26; ++k) {
        foo(i, j, k);
      }
    }
  }
  for (int i = 0; i <= n; ++i) {
    for (int j = 0; j <= ns; ++j) {
      for (int k = 0; k <= nt; ++k) {
        mem[i][j][k] = -1112;
      }
    }
  }
  ans = dp(0, 0, 0);
  cout << ans << endl;
  return 0;
}
