#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int countSubarraylessThanK(string s,int k){
	int n = s.size();
	int i = 0 , j = 0 ; 
	int count = 0 ; 
	int ans = 0 ; 
	while(j<n){
		if(s[j]=='5')count++;
		while(count>k){
		 if(s[i] == '5')
                count--;
			i++;
		}
		ans+=j-i+1;
		j++;
	}
	return ans;
}
int main() {
	string s ;
	cin>>s;
	int k ; cin>>k;
	int n = s.size();
	int ans = countSubarraylessThanK(s,k) - countSubarraylessThanK(s,k-1);
	cout<<ans;
	// your code goes here
	return 0;
}