#include <bits/stdc++.h>
using namespace std;
int main(){
    int a[1000],n,x,c = 0,s = 0,t,i;
    bool f;
    cin>>n;
    for(i = 0;i < n;i++){
        cin>>a[i];
    }
    cin>>x;
       
    for(i = 0;i < n;i++){
        f = false;
        t = a[i];
        while(t != 0){
            if(t % 10 == x){
                f = true;
                break;
            }
            t = t / 10;
        }
           
        if(f == true){
            c++;
            s = s + a[i];
        }
    }
       
    cout<<c<<" "<<s<<endl;
}
/**************************************************************
	Problem: 1425
	User: wangyiyang
	Language: C++
	Result: Accepted
	Time:8 ms
	Memory:2072 kb
****************************************************************/