import java.util.*;
class Main {
public static void main
(String[] args
) { Scanner sc
= new Scanner
(System.
in);
// Read the size of the array
int n = sc.nextInt();
int[] arr = new int[n];
// Read the elements of the array
for (int i = 0; i < n; i++) {
arr[i] = sc.nextInt();
}
// Read the target sum k
int k = sc.nextInt();
// Initialize variables
int currentSum = 0;
int smallestLength
= Integer.
MAX_VALUE; int count = 0;
// Map to store the frequency of prefix sums
Map
<Integer, Integer
> map
= new HashMap
<>();
// Initialize the map with the prefix sum of 0
map.put(0, 1);
for (int i = 0; i < n; i++) {
// Update the current prefix sum
currentSum += arr[i];
// Check if there exists a prefix sum that gives us the required sum k
if (map.containsKey(currentSum - k)) {
int length = i + 1 - map.get(currentSum - k);
// Update the smallest length and count
if (length < smallestLength) {
smallestLength = length;
count = 1; // Reset count for new smallest length
} else if (length == smallestLength) {
count++; // Increment count for same smallest length
}
}
// Update the frequency of the current prefix sum
map.put(currentSum, i + 1); // Store the latest index of the prefix sum
}
// Output the count of special subarrays
System.
out.
println(count
== 0 ? 0 : count
); }
}
aW1wb3J0IGphdmEudXRpbC4qOwoKY2xhc3MgTWFpbiB7CiAgICBwdWJsaWMgc3RhdGljIHZvaWQgbWFpbihTdHJpbmdbXSBhcmdzKSB7CiAgICAgICAgU2Nhbm5lciBzYyA9IG5ldyBTY2FubmVyKFN5c3RlbS5pbik7CiAgICAgICAgCiAgICAgICAgLy8gUmVhZCB0aGUgc2l6ZSBvZiB0aGUgYXJyYXkKICAgICAgICBpbnQgbiA9IHNjLm5leHRJbnQoKTsKICAgICAgICBpbnRbXSBhcnIgPSBuZXcgaW50W25dOwogICAgICAgIAogICAgICAgIC8vIFJlYWQgdGhlIGVsZW1lbnRzIG9mIHRoZSBhcnJheQogICAgICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbjsgaSsrKSB7CiAgICAgICAgICAgIGFycltpXSA9IHNjLm5leHRJbnQoKTsKICAgICAgICB9CiAgICAgICAgCiAgICAgICAgLy8gUmVhZCB0aGUgdGFyZ2V0I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AgICAgICAgICBzbWFsbGVzdExlbmd0aCA9IGxlbmd0aDsKICAgICAgICAgICAgICAgICAgICBjb3VudCA9IDE7IC8vIFJlc2V0IGNvdW50IGZvciBuZXcgc21hbGxlc3QgbGVuZ3RoCiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKGxlbmd0aCA9PSBzbWFsbGVzdExlbmd0aCkgewogICAgICAgICAgICAgICAgICAgIGNvdW50Kys7IC8vIEluY3JlbWVudCBjb3VudCBmb3Igc2FtZSBzbWFsbGVzdCBsZW5ndGgKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICAKICAgICAgICAgICAgLy8gVXBkYXRlIHRoZSBmcmVxdWVuY3kgb2YgdGhlIGN1cnJlbnQgcHJlZml4IHN1bQogICAgICAgICAgICBtYXAucHV0KGN1cnJlbnRTdW0sIGkgKyAxKTsgLy8gU3RvcmUgdGhlIGxhdGVzdCBpbmRleCBvZiB0aGUgcHJlZml4IHN1bQogICAgICAgIH0KICAgICAgICAKICAgICAgICAvLyBPdXRwdXQgdGhlIGNvdW50IG9mIHNwZWNpYWwgc3ViYXJyYXlzCiAgICAgICAgU3lzdGVtLm91dC5wcmludGxuKGNvdW50ID09IDAgPyAwIDogY291bnQpOwogICAgfQp9Cg==