-
-
Save avamsi/8544cf7d698e4247920db129694d48bb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
raw_input = lambda: ''.join(input().split()) | |
m = int(raw_input()) | |
n = int(raw_input()) | |
rows = [raw_input() for _ in range(m)] | |
cols = [''.join([rows[i][j] for i in range(m)]) for j in range(n)] | |
dgls = [''.join([rows[i][i - j] for i in range(j, min(m, n + j))]) for j in range(m)] | |
dgls.extend(''.join([rows[i][i + j] for i in range(min(m, n - j))]) for j in range(1, n)) | |
patt = raw_input() | |
regx = re.compile('(?=%s)' % patt) | |
print(sum(len(regx.findall(row)) for row in rows) + | |
sum(len(regx.findall(col)) for col in cols) + | |
sum(len(regx.findall(dgl)) for dgl in dgls)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment