using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static int[] NList => ReadLine().Split().Select(int.Parse).ToArray(); static int[] SList => ReadLine().Split().Select(s => s.Length).ToArray(); public static void Main() { Solve(); } static void Solve() { var n = NN; var c = NList; var s = SList; var cum = new int[n + 1]; for (var i = 0; i < n; ++i) cum[i + 1] = cum[i] + s[i]; var ans = 0; for (var i = 0; i < n; ++i) { var pos1 = LowerBound(0, cum[i] + c[0], cum); if (pos1 > n || cum[pos1] - cum[i] != c[0]) continue; var pos2 = LowerBound(0, cum[pos1] + c[1], cum); if (pos2 > n || cum[pos2] - cum[pos1] != c[1]) continue; var pos3 = LowerBound(0, cum[pos2] + c[2], cum); if (pos3 > n) continue; if (cum[pos3] - cum[pos2] == c[2]) ++ans; } WriteLine(ans); } static int LowerBound(int left, int min, IList list) { if (list[left] >= min) return left; var ng = left; var ok = list.Count; while (ok - ng > 1) { var center = (ng + ok) / 2; if (list[center] < min) ng = center; else ok = center; } return ok; } }