#include<bits/stdc++.h>
#define fi(i,n) for(i=0;i<n;++i)

using namespace std;

/*long long a[301][301];

bool isPossible(long long a[301][301],int m,int n)
{
    int i,j;
    if(a[0][0]>2 || a[0][n-1]>2 || a[m-1][0]>2 || a[m-1][n-1]>2)
    {
        return false;
    }
    fi(i,m)
        {
            fi(j,n)
            {
                if(i==0 || j==0 || i==m-1 || j==n-1)
                {
                    if(a[i][j]>3)return false;
                }
                else{
                    if(a[i][j]>4)return false;
                }
            }
        }
    return true;
}

int main()
{
    int t,n,m,i,j;
    cin>>t;
    while(t--)
    {
        cin>>m>>n;
        fi(i,m)
        {
            fi(j,n)
            {
                cin>>a[i][j];
            }
        }
        bool possible=isPossible(a,m,n);
        if(possible)
        {
            cout<<"YES\n";
            fi(i,m)
            {
                fi(j,n)
                {
                    if((i==0 && j==0) || (i==0 && j==n-1) || (i==m-1 && j==0) || (i==m-1 && j==n-1))
                    {
                        cout<<"2 ";
                    }
                    else if(i==0 || j==0 || i==m-1 || j==n-1)cout<<"3 ";
                    else cout<<"4 ";
                }
                cout<<"\n";
            }
        }
        else{
            cout<<"NO\n";
        }
    }
}*/
/*
int main()
{
    int n,curri,currj,i,t;
    cin>>t;
    while(t--)
    {
        cin>>n;
        vector<int> a(n);
        fi(i,n)cin>>a[i];

        if(a[0]<a[n-1])cout<<"YES\n";
        else cout<<"NO\n";
    }
    return 0;
}

int findLastOccurence(vector<int> a,int ele,int l,int r)
{
    int mid=l+(r-l)/2;
    int res=-1;
    while(l<=r)
    {
        mid=l+(r-l)/2;
        if(a[mid]==ele)
        {
            res=mid;
            l=mid+1;
        }
        else if(a[mid]<ele)
        {
            r=mid-1;
        }
        else{
            l=mid+1;
        }
    }
    return res;
}

int findFirstOccurence(vector<int> a,int ele,int l,int r)
{
    int res=-1;
    int mid=l+(r-l)/2;
    while(l<=r)
    {
        mid=l+(r-l)/2;
        if(a[mid]==ele)
        {
            res=mid;
            r=mid-1;
        }
        else if(a[mid]<ele)
        {
            r=mid-1;
        }
        else{
            l=mid+1;
        }
    }
    return res;
}

int main()
{
    int n,k,j;
    cin>>n>>k;
    vector<int> a(n);
    int i,ans;
    fi(i,n)cin>>a[i];

    if(a[0]==0)ans=0;
    else if(a[k-1]==0)
    {
        j=findFirstOccurence(a,a[k-1],0,a.size()-1);
        ans=j;
    }
    else{
        ans=findLastOccurence(a,a[k-1],k-1,a.size()-1)+1;
    }
    cout<<ans<<"\n";
    return 0;
}

int main()
{
    int m,n;
    cin>>m>>n;
    int tile=0;
    if(m%2!=0)
    {
        tile+=n;
        tile*=(m/2);
        tile+=(n/2);
    }
    else{
        tile+=n;
        tile*=(m/2);
    }
    cout<<tile<<"\n";
    return 0;
}

int main()
{
    int n,count=0;
    map<char,int> m;

    string s;
    cin>>s;
    n=s.size();
    int i=0;
    while(i<n)
    {
        if(!m.count(s[i]))
        {
            m[s[i]]=1;
            count++;
        }
        else{
            m[s[i]]++;
        }
        i++;
    }
    string ans=count%2!=0?"IGNORE HIM!\n":"CHAT WITH HER!\n";
    cout<<ans;
   return 0;
}
int main()
{
    int n,i,count=0,ans=INT_MIN;
    string s;
    cin>>n;
    cin>>s;
    fi(i,n-1)
    {
        while(s[i]==s[i+1] && i<n-1)
        {
            i++;
            count++;
        }
        //ans=max(ans,count);
    }
    cout<<count<<"\n";
    return 0;
}

int main()
{
    int i,countcaps=0,countlows=0;
    string s;
    cin>>s;
    int n=s.size();
    fi(i,n)
    {
        if(islower(s[i]))
        {
            countlows++;
        }
        else{
            countcaps++;
        }
    }
    if(countlows>=countcaps)
    {
        fi(i,n)
        {
            cout<<(char)tolower(s[i]);
        }
        cout<<"\n";
    }
    else{
        fi(i,n)
        {
            cout<<(char)toupper(s[i]);
        }
        cout<<"\n";
    }
    return 0;
}

long long maxPrimeFactors(long long n)
{
    // Initialize the maximum prime factor
    // variable with the lowest one
    long long maxPrime = -1;
    if(n==1)return 1;
    // Print the number of 2s that divide n
    while (n % 2 == 0) {
        maxPrime = 2;
        n >>= 1; // equivalent to n /= 2
    }

    // n must be odd at this point, thus skip
    // the even numbers and iterate only for
    // odd integers
    for (int i = 3; i <= sqrt(n); i += 2) {
        while (n % i == 0) {
            maxPrime = i;
            n = n / i;
        }
    }

    // This condition is to handle the case
    // when n is a prime number greater than 2
    if (n > 2)
        maxPrime = n;

    return maxPrime;
}

bool isPrime(int n)
{
    // Corner cases
    if (n <= 1)  return false;
    if (n <= 3)  return true;

    // This is checked so that we can skip
    // middle five numbers in below loop
    if (n%2 == 0 || n%3 == 0) return false;

    for (int i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;

    return true;
}

int main()
{
    int t;
    cin>>t;
    int n,i;
    while(t--)
    {
        cin>>n;
        if(n%2==0)
        {
            cout<<n/2<<"\n";
        }
        else{
            cout<<(n-1)/2<<"\n";
        }
    }
    return 0;
}
int main()
{
    int n;
    cin>>n;

        int ans=ceil((float)n/5);
        cout<<ans<<"\n";

    return 0;
}
int main()
{
    int n,k,w;
    cin>>k>>n>>w;
    int sum=(w*(w+1)/2)*k;
    int ans=(sum-n)>=0?sum-n:0;
    cout<<ans;
}
int main()
{
    int n,i,tot=INT_MAX;
    cin>>n;
    vector<int> a(n);
    map<int,vector<int>> m;
    vector<int> t;
    m[1]=t;
    m[2]=t;
    m[3]=t;
    fi(i,n)
    {
        cin>>a[i];

            m[a[i]].push_back(i+1);

    }
    for(auto itr=m.begin();itr!=m.end();++itr)
    {
        if(itr->second.size()<tot)tot=itr->second.size();
    }
    cout<<tot<<"\n";
    fi(i,tot)
    {
        cout<<m[1][i]<<" ";
        cout<<m[2][i]<<" ";
        cout<<m[3][i]<<" ";
        cout<<"\n";
    }
    return 0;
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int a,b,ans=0;
        cin>>a>>b;
        int side=2*min(a,b);
        ans=max(side,max(a,b));
        ans*=ans;
        cout<<ans<<"\n";
    }
    return 0;
}
int main()
{
    int n;
    string src,dest;
    cin>>n>>src>>dest;
    int i,ans=0;
    fi(i,n)
    {
        int d=max((int)(dest[i]),(int)(src[i]));
        int s=min((int)(dest[i]),(int)(src[i]));
        int diff=min(d-s,10-d+s);
        //cout<<diff<<" ";
        ans+=diff;
    }
    cout<<ans<<"\n";
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,i=1,j=0;
        cin>>n;
        if(n%2!=0){
            cout<<i<<" ";
            n--;
        }

        while(j<n)
        {
            cout<<i<<" "<<i<<" ";
            i+=2;
            j+=2;
        }
        cout<<"\n";
    }
    return 0;
}
int main()
{
    int t,i;
    cin>>t;
    while(t--)
    {
        vector<long long int> a(3);
        long long int count=0;
        fi(i,3){
            cin>>a[i];
            count+=a[i];
        }
        cout<<(count/2)<<"\n";
    }
    return 0;
}
int main()
{
    string s;
    cin>>s;
    int n=s.size();
    int i,count=1;
    fi(i,n-1)
    {
        count=1;
        while(s[i]==s[i+1])
        {
            i++;
            count++;
        }
        if(count>=7)break;
    }
    if(count>=7)cout<<"YES";
    else cout<<"NO";
    return 0;
}
int main()
{
    int n,i,total=0,curr=0,count=0;
    cin>>n;
    vector<int> a(n);
    priority_queue<int> pq;
    fi(i,n){
        cin>>a[i];
        total+=a[i];
        pq.push(a[i]);
    }
    while(!pq.empty() && curr<=(total/2))
    {
        curr+=pq.top();
        count++;
        pq.pop();
    }
    cout<<count;
    return 0;
}
int main()
{
    int n,i;
    cin>>n;
    map<int,int> m;
    vector<int> b(n);

    fi(i,n){
        cin>>b[i];
        if(!m.count(b[i]))
        {
            m[b[i]]=1;
        }
    }
    int ans=m.size();
    cout<<ans;
    return 0;
}
vector<int> adj[2001];
vector<bool> visited(2001,false);
int res=INT_MIN;

void dfs(int node,int height)
{
    visited[node]=true;
    int i;
    res=max(res,height);
    fi(i,adj[node].size())
    {
        //cout<<adj[node][i]<<" ";
        if(!visited[adj[node][i]])
        dfs(adj[node][i],height+1);
    }
}

int main()
{
    int n,a;
    vector<int> root;
    cin>>n;
    int i;
    fi(i,n)
    {
        cin>>a;
        if(a!=-1)
        {
            adj[i].push_back(a-1);
            adj[a-1].push_back(i);
        }
        else root.push_back(i);
    }

    for(auto i:root)
    {
        dfs(i,1);
    }

    cout<<res;
    return 0;
}

int main()
{
    long long int n,i;
    cin>>n;
    vector<long long int> a(n);
    long long int countZeroes=0,res=0,neg=0;
    fi(i,n)
    {
        cin>>a[i];
        if(a[i]==0)countZeroes++;
    }
    fi(i,n)
    {
        if(a[i]>0)
        {
            res+=(a[i]-1);
        }
        else if(a[i]<0)
        {
            neg++;
            res+=(-1-a[i]);
        }
    }
    if(countZeroes>0)
    {
        res+=countZeroes;
    }
    else{
        if(neg%2!=0)
        res+=2;
    }
    cout<<res;
    return 0;
}
int main()
{
    int n,i;

        cin>>n;
        vector<int> a(12);
        fi(i,12)cin>>a[i];
        sort(a.begin(),a.end(),greater<int>());
        int ans=0,sum=0;i=0;
        while(i<12 && sum<n)
        {
            sum+=a[i];
            i++;
            ans++;
        }
        if(sum<n)ans=-1;
        cout<<ans<<"\n";

    return 0;
}
int main()
{
    int m,n,x,t;
    cin>>t;
    while(t--)
    {
        int temp;
        cin>>x>>m>>n;
        temp=x;
        while(m-- && (temp/2+10)<temp)
        {

                temp=temp/2+10;

        }
        temp=temp-n*10;
        if(temp>0)cout<<"NO\n";
        else cout<<"YES\n";
    }
    return 0;
}
int main()
{
    int n,i;
    cin>>n;
    vector<int> a(n+1);
    vector<int> ans;
    a[1]=1;
    for(i=2;i<=n;++i)cin>>a[i];
    i=n;
    ans.push_back(n);
    while(a[i]!=1)
    {
        ans.push_back(a[i]);
        i=a[i];
    }
    ans.push_back(a[i]);
    reverse(ans.begin(),ans.end());
    fi(i,ans.size())cout<<ans[i]<<" ";
    cout<<"\n";
    return 0;
}
int main()
{
    int i,n,flag=0;
    cin>>n;
    vector<int> a(n);
    vector<int> b;
    fi(i,n)cin>>a[i];
    sort(a.begin(),a.end());
    fi(i,n-1)
    {
        while(a[i]==a[i+1])i++;
        b.push_back(a[i]);
    }
    if(a[n-2]!=a[n-1])b.push_back(a[n-1]);
    fi(i,b.size())
    {
        if(b[i+1]-b[i]==1 && b[i+2]-b[i+1]==1)
        {
            cout<<"YES";
            flag=1;
            break;
        }
    }
    if(!flag)cout<<"NO";
    return 0;
}
int main()
{
    int count1=0,count2=0,count3=0,i,n;
    cin>>n;
    vector<int> a(n);
    fi(i,n)
    {
        cin>>a[i];
        if(a[i]==1)count1++;
        else if(a[i]==2)count2++;
        else count3++;
    }
    int maxcount=max(count1,max(count2,count3));
    int ans=n-maxcount;
    cout<<ans;
    return 0;
}
int main()
{
    string pass,s1,s2;
    cin>>pass;
    int n,i,flag=0;
    char a=pass[0];
    char b=pass[1];
    cin>>n;
    vector<string> barks(n);
    fi(i,n)cin>>barks[i];
    fi(i,n)
    {
        if(barks[i]==pass || (pass[0]==barks[i][1] && pass[1]==barks[i][0]))
        {
            flag=1;
            break;
        }
        else if(barks[i][0]==b)
        {
            s2=barks[i];
        }
        else if(barks[i][1]==a)
        {
            s1=barks[i];
        }
    }
    if(flag || (s1.size()>0 && s2.size()>0))
    cout<<"YES";
    else cout<<"NO";
    return 0;
}
int main()
{
    int n,k,i;
    cin>>n>>k;
    vector<int> a(n);
    fi(i,n)cin>>a[i];
    if(k>n || k==0)cout<<"-1";
    else{
        sort(a.begin(),a.end());
        cout<<a[n-k]<<" "<<a[n-k];
    }
    return 0;
}
int main()
{
    long long int m,n,a;
    cin>>n>>m>>a;
    cout<<((m+a-1)/a)*((n+a-1)/a);

    return 0;
}
int main()
{
    int t,n,i;
    cin>>t;
    while(t--)
    {
        cin>>n;
        vector<int> a(n);
        fi(i,n)cin>>a[i];
        int flag=1;
        sort(a.begin(),a.end());
        fi(i,n-1)
        {
            if(abs(a[i+1]-a[i])>1)
            {
                flag=0;
                break;
            }
        }
        if(flag)cout<<"YES\n";
        else cout<<"NO\n";
    }
    return 0;
}
int main()
{
    int t,n,i;
    cin>>t;
    while(t--)
    {
        cin>>n;
        vector<long long int> a(n);
        vector<long long int> b(n);
        fi(i,n)cin>>a[i];
        fi(i,n)cin>>b[i];
        long long int mina=*min_element(a.begin(),a.end());
        long long int minb=*min_element(b.begin(),b.end());
        long long int ans=0;
        fi(i,n)
        {
            ans+=max(a[i]-mina,b[i]-minb);
        }
        cout<<ans<<"\n";
    }
    return 0;
}
int main()
{
    int t,n,i,j;
    cin>>t;
    while(t--)
    {
        cin>>n;
        vector<int> a(n);
        fi(i,n)cin>>a[i];
        sort(a.begin(),a.end());
        vector<int> temp(a[n-1]+a[n-2],0);
        fi(i,n-1)
        {
            for(j=i+1;j<n;++j)
            {
                while(a[j]==a[j+1] && j<n-1)j++;
                int sum=a[i]+a[j];
                if(a[i]!=a[i+1] || !temp[sum])
                temp[sum]++;
            }
        }
        cout<<*max_element(temp.begin(),temp.end())<<"\n";
    }
    return 0;
}

int main()
{
    string s,t;
    int n,i,flag=1;
    cin>>s;
    n=s.size();
    fi(i,n)
    {
        if(s[i]=='h' && t.size()==0)
        t.push_back('h');
        else if(s[i]=='e' && t.size()==1)t.push_back('e');
        else if(s[i]=='l' && (t.size()==2 || t.size()==3))t.push_back('l');
        else if(s[i]=='o' && t.size()==4)t.push_back('o');
    }
    if(t=="hello")cout<<"YES";
    else cout<<"NO";
    return 0;
}
bool isLucky(int n)
{
    int m=n;
    while(m)
    {
        int d=m%10;
        if(d!=4 && d!=7)return false;
        m/=10;
    }
    return true;
}

int main(){
    int n,flag=0;
    cin>>n;
    if(!isLucky(n))
    {
        for(int i=2;i<=n/2;++i)
        {
            if(n%i==0)
            {
                if(isLucky(n/i))
                {
                    flag=1;
                    break;
                }
            }
        }
        if(flag)cout<<"YES";
        else cout<<"NO";
    }
    else{
        cout<<"YES";
    }
    return 0;
}
int main()
{
    int a,b,c,ans;
    cin>>a>>b>>c;
    ans=a*b*c;
    ans=max(ans,a+b*c);
    ans=max(ans,(a+b)*c);
    ans=max(ans,a+b+c);
    ans=max(ans,a*(b+c));
    ans=max(ans,a*b+c);
    cout<<ans;

    return 0;
}

int main()
{
    long long int m,n,i;
    cin>>n>>m;
    vector<long long int> a(m);
    fi(i,m)cin>>a[i];
    long long int ans=a[0]-1;
    for(i=1;i<m;++i)
    {
        if(a[i]>=a[i-1])
        {
            ans+=(a[i]-a[i-1]);
        }
        else{
            ans+=(n-a[i-1]+a[i]);
        }
    }
    cout<<ans;

    return 0;
}
bool dfs(int node,vector<int> a,vector<bool>& visited,vector<int> adj[],int dest)
{
    visited[node]=true;
    if(node==dest)return true;
    for(auto i:adj[node])
    {
        if( !visited[i])
        {
            return dfs(i,a,visited,adj,dest);
        }
    }
    return false;
}

int main()
{
    int i,n,t,flag=0;
    cin>>n>>t;
    vector<int> a(n-1);
    vector<int> adj[n+1];
    fi(i,n-1)
    {
        cin>>a[i];
        adj[i+1].push_back(i+1+a[i]);
    }
    int curr=1;
    vector<int> route;
    fi(i,n-1)
    {
        if((i+1)==curr)
        {
            route.push_back(curr);
            curr=i+1+a[i];
        }
    }
    route.push_back(curr);
    /*vector<bool> visited(n+1,false);
    bool ans=dfs(1,a,visited,adj,t);
    if(ans)cout<<"YES";
    else cout<<"NO";
    fi(i,route.size())
    {
        //cout<<route[i]<<" ";
        if(route[i]==t)
        {
            flag=1;
            break;
        }
    }//cout<<"\n";
    if(flag)cout<<"YES";
    else cout<<"NO";
    return 0;
}
int main()
{
    int n,x,i,ans=0;
    cin>>n>>x;
    for(i=1;i<=n;++i)
    {
        if(x%i==0)
        {
            if(x/i<=n)ans++;
        }
    }
    cout<<ans;
    return 0;
}

int lcs(string a,string b)
{
    int m=a.size();
    int n=b.size();
    int dp[m+1][n+1];
    int i,j;
    fi(i,m+1)
    {
        fi(j,n+1)
        {
            if(i==0 || j==0)dp[i][j]=0;
        }
    }
    for(i=1;i<=m;++i)
    {
        for(j=1;j<=n;++j)
        {
            if(a[i]==b[j])
            {
                dp[i][j]=1+dp[i-1][j-1];
            }
            else{
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }
    return dp[m][n];
}
int main()
{
    string a,b;
    cin>>a>>b;
    int lcslen=lcs(a,b);
    int ans=lcslen;
    if(a==b)cout<<"-1";
    else cout<<max(a.size(),b.size());
    return 0;
}
int main()
{
    int n;
    cin>>n;
    float i=n,ans=0;
    while(i)
    {
        ans+=(1/i);
        i--;
    }
    cout<<ans;
    return 0;
}
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(NULL);
    int n;
    cin>>n;
    if(n%2==0)
    cout<<(1<<(n/2));
    else cout<<"0";
    return 0;
}*/
int main()
{
    int n,i,ans=0;
    string s;
    map<char,int> m;
    cin>>n;
    cin>>s;
    i=0;
    while(i<n)
    {
        if(m.count(s[i])==0)
        {
            m[s[i]]=1;
        }
        else{
            m[s[i]]++;
        }
        i++;
    }
    for(auto itr=m.begin();itr!=m.end();++itr)
    {
        ans+=itr->second-1;
    }
    if((26-s.size()-ans)<=0)ans=-1;
    cout<<ans;
    return 0;
}


#include<iostream>
#include<cstring>
using namespace std;
int main(){
    long long n;
    cin>>n;
    string s;
    cin>>s;
    int cnt=0;
    long long str[256]={0};
    for(int i=0;i<s.length();i++)
        str[s[i]]++;
    for(int i=0;i<256;i++){
           if(str[i]>1){
               cnt+=str[i]-1;
           }
    }
    cout<<cnt<<endl;
    return 0;
}


#include<iostream>
#include<cstring>
using namespace std;
int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    int cnt=0;
    long long str[256]={0};
    for(int i=0;i<s.length();i++)
        str[s[i]]++;
    for(int i=0;i<s.length();i++){
         while(str[s[i]]>1){
            ++cnt;
            str[s[i]]--;
         }
    }
    cout<<cnt<<endl;
    return 0;
}


#include<iostream>
#include<cstring>
using namespace std;
int main(){
    long long n;
    cin>>n;
    char s[1000000];
    cin>>s;
    if(strlen(s)>26){
       cout<<-1<<endl;
    }

    else{
        long long cnt=0;
        long long str[256]={0};
        for(int i=0;i<strlen(s);i++)
             str[s[i]]++;
        for(int i=0;i<256;i++){
               if(str[i]>1){
                cnt+=str[i]-1;
           }
    }
    if(cnt>=26){
        cout<<-1<<endl;
    }
    else
        cout<<cnt<<endl;
    }
    return 0;
}


#include<iostream>
#include<cstring>
using namespace std;
int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    int cnt=0;
    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
             if(s[i]==s[j])
                 cnt++;
        }
    }
    cout<<cnt<<endl;
    return 0;
}


#include<iostream>
#include<cstring>
using namespace std;
int main(){
    long long n;
    cin>>n;
    char s[1000000];
    cin>>s;
    long long cnt=0;
    long long str[256]={0};
    for(int i=0;i<strlen(s);i++)
        str[s[i]]++;
    for(int i=0;i<256;i++){
           if(str[i]>1){
               cnt+=str[i]-1;
           }
    }
    cout<<cnt<<endl;
    return 0;
}


#include<iostream>
#include<cstring>
using namespace std;
int main(){
    long long n;
    cin>>n;
    char s[1000000];
    cin>>s;
    if(strlen(s)>100000){
       cout<<-1<<endl;
    }
    else{
        long long cnt=0;
        long long str[256]={0};
        for(int i=0;i<strlen(s);i++)
             str[s[i]]++;
        for(int i=0;i<256;i++){
               if(str[i]>1){
                cnt+=str[i]-1;
           }
    }
    if(cnt>26){
        cout<<-1<<endl;
    }
    else
        cout<<cnt<<endl;
    }
    return 0;
}


#include<iostream>
#include<cstring>
using namespace std;
int main(){
    long long n;
    cin>>n;
    char s[1000000];
    cin>>s;
    if(strlen(s)>100000){
       cout<<-1<<endl;
    }
    else{
        long long cnt=0;
        long long str[256]={0};
        for(int i=0;i<strlen(s);i++)
             str[s[i]]++;
        for(int i=0;i<256;i++){
               if(str[i]>1){
                cnt+=str[i]-1;
           }
    }
    if(cnt>=26){
        cout<<-1<<endl;
    }
    else
        cout<<cnt<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
void main() {
    vector<int> alpha(26,0);
    long long int n,ans=0,empty=0;
    cin>>n;
    string str;
    cin>>str;

    for(int i=0;i<n;i++){
        alpha[str[i]-'a']+=1;
    }
    for(int i=0;i<alpha.size();i++){
        if(!alpha[i]){
            empty+=1;
        }
    }
    for(int i=0;i<alpha.size();i++){
        if(alpha[i]>1){
            if(alpha[i]-1<=empty && empty){
                empty=empty-(alpha[i]-1);
                ans=ans+(alpha[i]-1);
                alpha[i]=1;
            }
            else{
                cout<<-1;
                return ;
            }

        }
    }
    cout<<ans;
}
// zbcdefghijklmnopqrstuvwxyz
// bcdefz


#include<bits/stdc++.h>
using namespace std;
int main() {
    vector<int> alpha(26,0);
    long long int n,ans=0,empty=0;
    cin>>n;
    string str;
    cin>>str;

    for(int i=0;i<n;i++){
        alpha[str[i]-'a']+=1;
    }
    for(int i=0;i<alpha.size();i++){
        if(!alpha[i]){
            empty+=1;
        }
    }
    for(int i=0;i<alpha.size();i++){
        if(alpha[i]>1){
            if(alpha[i]-1<=empty && empty){
                empty=empty-(alpha[i]-1);
                ans=ans+(alpha[i]-1);
                alpha[i]=1;
            }
            else{
                cout<<-1;
                return 1;
            }

        }
    }
    cout<<ans;
}
// zbcdefghijklmnopqrstuvwxyz
// bcdefz


#include<bits/stdc++.h>
using namespace std;
int main() {
    vector<int> alpha(26,0);
    long long int n,ans=0,empty=0;
    cin>>n;
    string str;
    cin>>str;

    for(int i=0;i<n;i++){
        alpha[str[i]-'a']+=1;
    }
    for(int i=0;i<alpha.size();i++){
        if(!alpha[i]){
            empty+=1;
        }
    }
    for(int i=0;i<alpha.size();i++){
        if(alpha[i]>1){
            if(alpha[i]-1<=empty && empty){
                empty=empty-(alpha[i]-1);
                ans=ans+(alpha[i]-1);
                alpha[i]=1;
            }
            else{
                cout<<-1;
                // return ;
                exit(1);
            }

        }
    }
    cout<<ans;
}
// zbcdefghijklmnopqrstuvwxyz
// bcdefz


#include<bits/stdc++.h>
using namespace std;
int main() {
    vector<int> alpha(26,0);
    long long int n,ans=0,empty=0;
    cin>>n;
    string str;
    cin>>str;

    for(int i=0;i<n;i++){
        alpha[str[i]-'a']+=1;
    }
    for(int i=0;i<alpha.size();i++){
        if(!alpha[i]){
            empty+=1;
        }
    }
    int flag=0;
    for(int i=0;i<alpha.size();i++){
        if(alpha[i]>1){
            if(alpha[i]-1<=empty && empty){
                empty=empty-(alpha[i]-1);
                ans=ans+(alpha[i]-1);
                alpha[i]=1;
            }
            else{
                cout<<-1;
                flag=1;
                exit(1);
            }

        }
    }
    if(!flag)
        cout<<ans;
}
// zbcdefghijklmnopqrstuvwxyz
// bcdefz


#include<bits/stdc++.h>
using namespace std;
int main() {
    vector<int> alpha(26,0);
    long long int n,ans=0,empty=0;
    cin>>n;
    string str;
    cin>>str;

    for(int i=0;i<n;i++){
        alpha[str[i]-'a']+=1;
    }
    for(int i=0;i<alpha.size();i++){
        if(!alpha[i]){
            empty+=1;
        }
    }
    int flag=0;
    for(int i=0;i<alpha.size();i++){
        if(alpha[i]>1){
            if(alpha[i]-1<=empty && empty){
                empty=empty-(alpha[i]-1);
                ans=ans+(alpha[i]-1);
                alpha[i]=1;
            }
            else{
                cout<<-1;
                flag=1;
                break;
                // exit(1);
            }

        }
    }
    if(!flag)
        cout<<ans;
}
// zbcdefghijklmnopqrstuvwxyz
// bcdefz


#include<bits/stdc++.h>
using namespace std;
int main() {
    vector<int> alpha(26,0);
    long long int n,ans=0,empty=0;
    cin>>n;
    string str;
    cin>>str;

    for(int i=0;i<n;i++){
        alpha[str[i]-'a']+=1;
    }
    for(int i=0;i<alpha.size();i++){
        if(!alpha[i]){
            empty+=1;
        }
    }
    int flag=0;
    for(int i=0;i<alpha.size();i++){
        if(alpha[i]>1){
            if(alpha[i]-1<=empty && empty){
                empty=empty-(alpha[i]-1);
                ans=ans+(alpha[i]-1);
                alpha[i]=1;
            }
            else{
                cout<<-1;
                flag=1;
                // exit(1);
            }

        }
    }
    if(!flag)
        cout<<ans;
}
// zbcdefghijklmnopqrstuvwxyz
// bcdefz


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.TreeMap;
import java.util.StringTokenizer;
import java.io.Writer;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author zodiacLeo
 */
public class Main
{
    public static void main(String[] args)
    {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        FastPrinter out = new FastPrinter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC
    {
        public void solve(int testNumber, FastScanner in, FastPrinter out)
        {
            int n = in.nextInt();
            int k = in.nextInt();
            long[] p = new long[n + 1];
            long max = Long.MIN_VALUE;
            int cnt = 0;
            TreeMap<Long, ArrayList<Integer>> map = new TreeMap<>();
            for (int i = 1; i <= n; i++)
            {
                long num = in.nextLong();
                p[i] = p[i - 1] + num;
                ArrayList<Integer> pos = map.get(p[i]);
                if (pos == null)
                {
                    pos = new ArrayList<>();
                }
                pos.add(i);
                map.put(p[i], pos);
                max = Math.max(max, Math.abs(p[i]));
                if (num != 0)
                {
                    cnt++;
                }
            }

            if (k == 1)
            {
                out.println(n * cnt);
                return;
            }

            long count = 0;
            for (long num = 1; num <= 1e9; num *= k)
            {
                for (int left = 1; left <= n; left++)
                {
                    long value = num + p[left - 1];
                    ArrayList<Integer> positions = map.get(value);
                    if (positions == null)
                    {
                        continue;
                    }
                    int low = -1;
                    int high = positions.size();
                    while (high - low > 1)
                    {
                        int mid = low + (high - low) / 2;
                        if (positions.get(mid) < left)
                        {
                            low = mid;
                        } else
                        {
                            high = mid;
                        }
                    }
                    int N = positions.size();
                    if (high < N && positions.get(high) >= left)
                    {
                        count += Math.max(0, N - high);
                    }
                }
            }
            out.println(count);
        }

    }

    static class FastPrinter extends PrintWriter
    {
        public FastPrinter(OutputStream out)
        {
            super(out);
        }

        public FastPrinter(Writer out)
        {
            super(out);
        }

    }

    static class FastScanner
    {
        public BufferedReader br;
        public StringTokenizer st;

        public FastScanner(InputStream is)
        {
            br = new BufferedReader(new InputStreamReader(is));
        }

        public FastScanner(File f)
        {
            try
            {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e)
            {
                e.printStackTrace();
            }
        }

        public String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                String s = null;
                try
                {
                    s = br.readLine();
                } catch (IOException e)
                {
                    e.printStackTrace();
                }
                if (s == null)
                    return null;
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        public int nextInt()
        {
            return Integer.parseInt(next());
        }

        public long nextLong()
        {
            return Long.parseLong(next());
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.StringTokenizer;
import java.io.Writer;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author zodiacLeo
 */
public class Main
{
    public static void main(String[] args)
    {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        FastPrinter out = new FastPrinter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC
    {
        public void solve(int testNumber, FastScanner in, FastPrinter out)
        {
            int n = in.nextInt();
            int k = in.nextInt();
            long[] prefix = new long[n + 1];
            int[] b = new int[n + 1];
            for (int i = 1; i < n + 1; i++)
            {
                b[i] = in.nextInt();
                prefix[i] = b[i] + prefix[i - 1];
            }

            int count = 0;
            for (int i = 1; i < n + 1; i++)
            {
                for (int j = i; j < n + 1; j++)
                {
                    long sum = prefix[j] - prefix[i - 1];
                    if (isPower(sum, k))
                    {
                        count++;
                    }
                }
            }
            out.println(count);
        }

        private boolean isPower(long num, int k)
        {
            if (num == 0)
            {
                return true;
            }
            while (num % k == 0)
            {
                num /= k;
            }
            return num == 1;
        }

    }

    static class FastPrinter extends PrintWriter
    {
        public FastPrinter(OutputStream out)
        {
            super(out);
        }

        public FastPrinter(Writer out)
        {
            super(out);
        }

    }

    static class FastScanner
    {
        public BufferedReader br;
        public StringTokenizer st;

        public FastScanner(InputStream is)
        {
            br = new BufferedReader(new InputStreamReader(is));
        }

        public FastScanner(File f)
        {
            try
            {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e)
            {
                e.printStackTrace();
            }
        }

        public String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                String s = null;
                try
                {
                    s = br.readLine();
                } catch (IOException e)
                {
                    e.printStackTrace();
                }
                if (s == null)
                    return null;
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        public int nextInt()
        {
            return Integer.parseInt(next());
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.StringTokenizer;
import java.io.Writer;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author zodiacLeo
 */
public class Main
{
    public static void main(String[] args)
    {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        FastPrinter out = new FastPrinter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC
    {
        public void solve(int testNumber, FastScanner in, FastPrinter out)
        {
            int n = in.nextInt();
            int k = in.nextInt();
            int[] prefix = new int[n + 1];
            int[] b = new int[n + 1];
            for (int i = 1; i < n + 1; i++)
            {
                b[i] = in.nextInt();
                prefix[i] = b[i] + prefix[i - 1];
            }

            int count = 0;
            for (int i = 1; i < n + 1; i++)
            {
                for (int j = i; j < n + 1; j++)
                {
                    int sum = prefix[j] - prefix[i - 1];
                    if (isPower(sum, k))
                    {
                        count++;
                    }
                }
            }
            out.println(count);
        }

        private boolean isPower(int num, int k)
        {
            if (num == 0)
            {
                return true;
            }
            while (num % k == 0)
            {
                num /= k;
            }
            return num == 1;
        }

    }

    static class FastPrinter extends PrintWriter
    {
        public FastPrinter(OutputStream out)
        {
            super(out);
        }

        public FastPrinter(Writer out)
        {
            super(out);
        }

    }

    static class FastScanner
    {
        public BufferedReader br;
        public StringTokenizer st;

        public FastScanner(InputStream is)
        {
            br = new BufferedReader(new InputStreamReader(is));
        }

        public FastScanner(File f)
        {
            try
            {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e)
            {
                e.printStackTrace();
            }
        }

        public String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                String s = null;
                try
                {
                    s = br.readLine();
                } catch (IOException e)
                {
                    e.printStackTrace();
                }
                if (s == null)
                    return null;
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        public int nextInt()
        {
            return Integer.parseInt(next());
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.TreeSet;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.TreeMap;
import java.util.StringTokenizer;
import java.io.Writer;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author zodiacLeo
 */
public class Main
{
    public static void main(String[] args)
    {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        FastPrinter out = new FastPrinter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC
    {
        public void solve(int testNumber, FastScanner in, FastPrinter out)
        {
            int n = in.nextInt();
            int k = in.nextInt();
            long[] p = new long[n + 1];
            long max = Long.MIN_VALUE;
            int cnt = 0;
            TreeMap<Long, ArrayList<Integer>> map = new TreeMap<>();
            for (int i = 1; i <= n; i++)
            {
                long num = in.nextLong();
                p[i] = p[i - 1] + num;
                ArrayList<Integer> pos = map.get(p[i]);
                if (pos == null)
                {
                    pos = new ArrayList<>();
                }
                pos.add(i);
                map.put(p[i], pos);
                max = Math.max(max, Math.abs(p[i]));
                if (num != 0)
                {
                    cnt++;
                }
            }

            TreeSet<Long> was = new TreeSet<>();
            long count = 0;
            for (long num = 1; num <= 1e9; num *= k)
            {
                if (was.contains(num))
                {
                    break;
                }
                was.add(num);
                for (int left = 1; left <= n; left++)
                {
                    long value = num + p[left - 1];
                    ArrayList<Integer> positions = map.get(value);
                    if (positions == null)
                    {
                        continue;
                    }
                    int low = -1;
                    int high = positions.size();
                    while (high - low > 1)
                    {
                        int mid = low + (high - low) / 2;
                        if (positions.get(mid) < left)
                        {
                            low = mid;
                        } else
                        {
                            high = mid;
                        }
                    }
                    int N = positions.size();
                    if (high < N && positions.get(high) >= left)
                    {
                        count += Math.max(0, N - high);
                    }
                }
            }
            out.println(count);
        }

    }

    static class FastPrinter extends PrintWriter
    {
        public FastPrinter(OutputStream out)
        {
            super(out);
        }

        public FastPrinter(Writer out)
        {
            super(out);
        }

    }

    static class FastScanner
    {
        public BufferedReader br;
        public StringTokenizer st;

        public FastScanner(InputStream is)
        {
            br = new BufferedReader(new InputStreamReader(is));
        }

        public FastScanner(File f)
        {
            try
            {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e)
            {
                e.printStackTrace();
            }
        }

        public String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                String s = null;
                try
                {
                    s = br.readLine();
                } catch (IOException e)
                {
                    e.printStackTrace();
                }
                if (s == null)
                    return null;
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        public int nextInt()
        {
            return Integer.parseInt(next());
        }

        public long nextLong()
        {
            return Long.parseLong(next());
        }

    }
}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class Main {

	int MOD = 1000 * 1000 * 1000 + 7;

	ArrayList<Long> powers;

	private void solve() {
		int n = in.nextInt();
		int k = in.nextInt();
		long[] val = new long[n];
		long sumAll = 0;
		for (int i = 0; i < n; i++) {
			val[i] = in.nextLong();
			sumAll += val[i];
		}

		powers = new ArrayList<Long>();
		long pow = 1;
		powers.add(pow);
		long max = 1;
		for (int i = 1; i <= 16; i++) {
			max *= 10;
		}

		if (k == -1) {
			powers.add(-1l);
		}

		if (Math.abs(k) != 1) {
			while (Math.abs(pow * k) <= max) {
				pow = pow * k;
				powers.add(pow);
			}
		}

		TreeMap<Long, Long> map = new TreeMap<Long, Long>();
		long sum = 0;
		long res = 0;
		for (int i = 0; i < n; i++) {
			sum += val[i];
			if (powers.contains(sum)) {
				res++;
			}

			for (long v : powers) {
				Long num = map.get(sum - v);
				if (num == null) {
					continue;
				} else {
					res += num;
				}
			}

			map.put(sum, map.getOrDefault(sum, 0l) + 1);

		}

		out.print(res);
	}

	/*
	 *
	*
	*/
	// --------------------------------------------------------

	private FastScanner in;
	private PrintWriter out;

	void runIO() {

		in = new FastScanner(System.in);
		out = new PrintWriter(System.out);

		solve();

		out.close();
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(File f) {
			try {
				br = new BufferedReader(new FileReader(f));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}

		public FastScanner(InputStream f) {
			br = new BufferedReader(new InputStreamReader(f));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				String s = null;
				try {
					s = br.readLine();
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (s == null)
					return null;
				st = new StringTokenizer(s);
			}
			return st.nextToken();
		}

		boolean hasMoreTokens() {
			while (st == null || !st.hasMoreTokens()) {
				String s = null;
				try {
					s = br.readLine();
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (s == null)
					return false;
				st = new StringTokenizer(s);
			}
			return true;
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}
	}

	public static void main(String[] args) {
		new Main().runIO();
	}
}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.StringTokenizer;

public class Main {

	int MOD = 1000 * 1000 * 1000 + 7;

	ArrayList<Long> powers;

	private void solve() {
		int n = in.nextInt();
		int k = in.nextInt();
		long[] val = new long[n];
		long sumAll = 0;
		for (int i = 0; i < n; i++) {
			val[i] = in.nextLong();
			sumAll += val[i];
		}

		powers = new ArrayList<Long>();
		long pow = 1;
		powers.add(pow);
		long max = 1;
		for (int i = 1; i <= 16; i++) {
			max *= 10;
		}

		if (k == -1) {
			powers.add(-1l);
		}

		if (Math.abs(k) != 1) {
			while (Math.abs(pow * k) <= max) {
				pow = pow * k;
				powers.add(pow);
			}
		}

		HashMap<Long, Long> map = new HashMap<Long, Long>();
		long sum = 0;
		long res = 0;
		for (int i = 0; i < n; i++) {
			sum += val[i];
			if (powers.contains(sum)) {
				res++;
			}

			for (long v : powers) {
				Long num = map.get(sum - v);
				if (num == null) {
					continue;
				} else {
					res += num;
				}
			}

			map.put(sum, map.getOrDefault(sum, 0l) + 1);

		}

		out.print(res);
	}

	/*
	 *
	*
	*/
	// --------------------------------------------------------

	private FastScanner in;
	private PrintWriter out;

	void runIO() {

		in = new FastScanner(System.in);
		out = new PrintWriter(System.out);

		solve();

		out.close();
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(File f) {
			try {
				br = new BufferedReader(new FileReader(f));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}

		public FastScanner(InputStream f) {
			br = new BufferedReader(new InputStreamReader(f));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				String s = null;
				try {
					s = br.readLine();
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (s == null)
					return null;
				st = new StringTokenizer(s);
			}
			return st.nextToken();
		}

		boolean hasMoreTokens() {
			while (st == null || !st.hasMoreTokens()) {
				String s = null;
				try {
					s = br.readLine();
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (s == null)
					return false;
				st = new StringTokenizer(s);
			}
			return true;
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}
	}

	public static void main(String[] args) {
		new Main().runIO();
	}
}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.StringTokenizer;

public class Main {

	int MOD = 1000 * 1000 * 1000 + 7;

	ArrayList<Long> powers;

	private void solve() {
		int n = in.nextInt();
		int k = in.nextInt();
		long[] val = new long[n];
		long sumAll = 0;
		for (int i = 0; i < n; i++) {
			val[i] = in.nextLong();
			sumAll += val[i];
		}

		powers = new ArrayList<Long>();
		long pow = 1;
		powers.add(pow);
		long max = 1;
		for (int i = 1; i <= 16; i++) {
			max *= 10;
		}
		if (k != 1) {
			while (pow * k <= max) {
				pow = pow * k;
				powers.add(pow);
			}
		}

		HashMap<Long, Long> map = new HashMap<Long, Long>();
		long sum = 0;
		long res = 0;
		for (int i = 0; i < n; i++) {
			sum += val[i];
			if (powers.contains(sum)) {
				res++;
			}

			for (long v : powers) {
				Long num = map.get(sum - v);
				if (num == null) {
					continue;
				} else {
					res += num;
				}
			}

			map.put(sum, map.getOrDefault(sum, 0l) + 1);

		}

		out.print(res);
	}

	/*
	 *
	*
	*/
	// --------------------------------------------------------

	private FastScanner in;
	private PrintWriter out;

	void runIO() {

		in = new FastScanner(System.in);
		out = new PrintWriter(System.out);

		solve();

		out.close();
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(File f) {
			try {
				br = new BufferedReader(new FileReader(f));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}

		public FastScanner(InputStream f) {
			br = new BufferedReader(new InputStreamReader(f));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				String s = null;
				try {
					s = br.readLine();
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (s == null)
					return null;
				st = new StringTokenizer(s);
			}
			return st.nextToken();
		}

		boolean hasMoreTokens() {
			while (st == null || !st.hasMoreTokens()) {
				String s = null;
				try {
					s = br.readLine();
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (s == null)
					return false;
				st = new StringTokenizer(s);
			}
			return true;
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}
	}

	public static void main(String[] args) {
		new Main().runIO();
	}
}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.StringTokenizer;

public class Main {

	int MOD = 1000 * 1000 * 1000 + 7;

	ArrayList<Long> powers;

	private void solve() {
		int n = in.nextInt();
		int k = in.nextInt();
		long[] val = new long[n];
		long sumAll = 0;
		for (int i = 0; i < n; i++) {
			val[i] = in.nextLong();
			sumAll += val[i];
		}

		powers = new ArrayList<Long>();
		long pow = 1;
		powers.add(pow);
		long max = 1;
		for (int i = 1; i <= 14; i++) {
			max *= 10;
		}
		if (k > 1) {
			while (pow * k <= max) {
				pow = pow * k;
				powers.add(pow);
			}
		}
		HashMap<Long, Long> map = new HashMap<Long, Long>();
		long sum = 0;
		long res = 0;
		for (int i = 0; i < n; i++) {
			sum += val[i];
			if (powers.contains(sum)) {
				res++;
			}

			for (long v : powers) {
				Long num = map.get(sum - v);
				if (num == null) {
					continue;
				} else {
					res += num;
				}
			}

			map.put(sum, map.getOrDefault(sum, 0l) + 1);

		}

		out.print(res);
	}

	/*
	 *
	*
	*/
	// --------------------------------------------------------

	private FastScanner in;
	private PrintWriter out;

	void runIO() {

		in = new FastScanner(System.in);
		out = new PrintWriter(System.out);

		solve();

		out.close();
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(File f) {
			try {
				br = new BufferedReader(new FileReader(f));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}

		public FastScanner(InputStream f) {
			br = new BufferedReader(new InputStreamReader(f));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				String s = null;
				try {
					s = br.readLine();
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (s == null)
					return null;
				st = new StringTokenizer(s);
			}
			return st.nextToken();
		}

		boolean hasMoreTokens() {
			while (st == null || !st.hasMoreTokens()) {
				String s = null;
				try {
					s = br.readLine();
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (s == null)
					return false;
				st = new StringTokenizer(s);
			}
			return true;
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}
	}

	public static void main(String[] args) {
		new Main().runIO();
	}
}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.StringTokenizer;

public class Main {

	int MOD = 1000 * 1000 * 1000 + 7;

	ArrayList<Long> powers;

	private void solve() {
		int n = in.nextInt();
		int k = in.nextInt();
		long[] val = new long[n];
		long sumAll = 0;
		for (int i = 0; i < n; i++) {
			val[i] = in.nextLong();
			sumAll += val[i];
		}

		powers = new ArrayList<Long>();
		long pow = 1;
		powers.add(pow);
		long max = 1;
		for (int i = 1; i <= 14; i++) {
			max *= 10;
		}
		while (pow * k <= max) {
			pow = pow * k;
			powers.add(pow);
		}

		HashMap<Long, Long> map = new HashMap<Long, Long>();
		long sum = 0;
		long res = 0;
		for (int i = 0; i < n; i++) {
			sum += val[i];
			if (powers.contains(sum)) {
				res++;
			}

			for (long v : powers) {
				Long num = map.get(sum - v);
				if (num == null) {
					continue;
				} else {
					res += num;
				}
			}

			map.put(sum, map.getOrDefault(sum, 0l) + 1);

		}

		out.print(res);
	}

	/*
	 *
	*
	*/
	// --------------------------------------------------------

	private FastScanner in;
	private PrintWriter out;

	void runIO() {

		in = new FastScanner(System.in);
		out = new PrintWriter(System.out);

		solve();

		out.close();
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(File f) {
			try {
				br = new BufferedReader(new FileReader(f));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}

		public FastScanner(InputStream f) {
			br = new BufferedReader(new InputStreamReader(f));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				String s = null;
				try {
					s = br.readLine();
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (s == null)
					return null;
				st = new StringTokenizer(s);
			}
			return st.nextToken();
		}

		boolean hasMoreTokens() {
			while (st == null || !st.hasMoreTokens()) {
				String s = null;
				try {
					s = br.readLine();
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (s == null)
					return false;
				st = new StringTokenizer(s);
			}
			return true;
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}
	}

	public static void main(String[] args) {
		new Main().runIO();
	}
}


import java.util.*;

public class ProbC {
	public static void main(String[] args) {
		ProbC sol = new ProbC();
		sol.start();
	}

	public void print(Object o){ System.out.print(o); }
	public void println(Object o) { System.out.println(o); }

	public void start(){
		submit();
//		testGen();
	}

	public void testGen(){
		int n = 100000, k = 10;
		println(n+ " "+k);
		int[] a = new int[n];
		for(int i=0;i<n;i++) a[i] = n;
		System.out.println(combinations(n, k, a));
	}

	public void submit(){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt(), k = scan.nextInt();
		int[] a = new int[n];
		for(int i=0;i<n;i++) a[i] = scan.nextInt();
		scan.close();

		System.out.println(combinations(n, k, a));
		System.out.flush();
	}

	public int combinations(int n, int k, int[] aff){
		if(k==0) return comb0(n, aff);
		else if(k==1) return comb1(n, aff);
		HashMap<Long,Integer> map = new HashMap();
		long sum = 0;
		int ret = 0;
		map.put(sum, 1);
		for(int i : aff){
			sum += i;
			long base = 1;
			while(Math.abs(base) < Long.MAX_VALUE / Math.abs(k)){
				ret += getCount(map, sum - base);
				base *= k;
			}
			int j = getCount(map, sum);
			map.put(sum, j+1);
		}
		return ret;
	}

	public int comb0(int n, int[] aff){
		HashMap<Long,Integer> map = new HashMap();
		long sum = 0;
		int ret = 0;
		map.put(sum, 1);
		for(int i : aff){
			sum += i;
			int j = getCount(map, sum);
			ret += j;
			map.put(sum, j+1);
		}
		return ret;
	}

	public int comb1(int n, int[] aff){
		HashMap<Long,Integer> map = new HashMap();
		long sum = 0;
		int ret = 0;
		map.put(sum, 1);

		for(int i : aff){
			sum += i;
			ret += getCount(map, sum + 1);
			ret += getCount(map, sum - 1);
			int j = getCount(map, sum);
			map.put(sum, j+1);
		}
		return ret;
	}

	private int getCount(HashMap<Long, Integer> map, long sum){
		Integer i = map.get(sum);
		if(i==null) return 0;
		else return i;
	}
}


import java.util.*;

public class ProbC {
	public static void main(String[] args) {
		ProbC sol = new ProbC();
		sol.start();
	}

	public void print(Object o){ System.out.print(o); }
	public void println(Object o) { System.out.println(o); }

	public void start(){
		submit();
//		testGen();
	}

	public void testGen(){
		int n = 100000, k = 0;
		println(n+ " "+k);
		int[] a = new int[n];
		for(int i=0;i<n;i++) a[i] = 0;
		System.out.println(combinations(n, k, a));
	}

	public void submit(){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt(), k = scan.nextInt();
		int[] a = new int[n];
		for(int i=0;i<n;i++) a[i] = scan.nextInt();
		scan.close();

		System.out.println(combinations(n, k, a));
		System.out.flush();
	}

	public long combinations(int n, int k, int[] aff){
		if(k==0) return comb0(n, aff);
		else if(k==1) return comb1(n, aff);
		else if(k==-1) return combm1(n, aff);
		HashMap<Long,Integer> map = new HashMap();
		long sum = 0;
		long ret = 0;
		map.put(sum, 1);
		for(int i : aff){
			sum += i;
			long base = 1;
			while(Math.abs(base) < Long.MAX_VALUE / Math.abs(k)){
				ret += getCount(map, sum - base);
				base *= k;
			}
			int j = getCount(map, sum);
			map.put(sum, j+1);
		}
		return ret;
	}

	public long comb0(int n, int[] aff){
		HashMap<Long,Integer> map = new HashMap();
		long sum = 0;
		long ret = 0;
		map.put(sum, 1);
		for(int i : aff){
			sum += i;
			int j = getCount(map, sum);
			ret += j;
			map.put(sum, j+1);
		}
		return ret;
	}

	public long comb1(int n, int[] aff){
		HashMap<Long,Integer> map = new HashMap();
		long sum = 0;
		long ret = 0;
		map.put(sum, 1);

		for(int i : aff){
			sum += i;
			ret += getCount(map, sum - 1);
			int j = getCount(map, sum);
			map.put(sum, j+1);
		}
		return ret;
	}

	public long combm1(int n, int[] aff){
		HashMap<Long,Integer> map = new HashMap();
		long sum = 0;
		long ret = 0;
		map.put(sum, 1);

		for(int i : aff){
			sum += i;
			ret += getCount(map, sum + 1);
			ret += getCount(map, sum - 1);
			int j = getCount(map, sum);
			map.put(sum, j+1);
		}
		return ret;
	}

	private int getCount(HashMap<Long, Integer> map, long sum){
		Integer i = map.get(sum);
		if(i==null) return 0;
		else return i;
	}
}


import java.util.*;

public class ProbC {
	public static void main(String[] args) {
		ProbC sol = new ProbC();
		sol.start();
	}

	public void print(Object o){ System.out.print(o); }
	public void println(Object o) { System.out.println(o); }

	public void start(){
		submit();
//		testGen();
	}

	public void testGen(){
		int n = 100000, k = 10;
		println(n+ " "+k);
		int[] a = new int[n];
		for(int i=0;i<n;i++) a[i] = n;
		System.out.println(combinations(n, k, a));
	}

	public void submit(){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt(), k = scan.nextInt();
		int[] a = new int[n];
		for(int i=0;i<n;i++) a[i] = scan.nextInt();
		scan.close();

		System.out.println(combinations(n, k, a));
		System.out.flush();
	}

	public int combinations(int n, int k, int[] aff){
		if(k==0) return comb0(n, aff);
		else if(k==1) return comb1(n, aff);
		else if(k==-1) return combm1(n, aff);
		HashMap<Long,Integer> map = new HashMap();
		long sum = 0;
		int ret = 0;
		map.put(sum, 1);
		for(int i : aff){
			sum += i;
			long base = 1;
			while(Math.abs(base) < Long.MAX_VALUE / Math.abs(k)){
				ret += getCount(map, sum - base);
				base *= k;
			}
			int j = getCount(map, sum);
			map.put(sum, j+1);
		}
		return ret;
	}

	public int comb0(int n, int[] aff){
		HashMap<Long,Integer> map = new HashMap();
		long sum = 0;
		int ret = 0;
		map.put(sum, 1);
		for(int i : aff){
			sum += i;
			int j = getCount(map, sum);
			ret += j;
			map.put(sum, j+1);
		}
		return ret;
	}

	public int comb1(int n, int[] aff){
		HashMap<Long,Integer> map = new HashMap();
		long sum = 0;
		int ret = 0;
		map.put(sum, 1);

		for(int i : aff){
			sum += i;
			ret += getCount(map, sum - 1);
			int j = getCount(map, sum);
			map.put(sum, j+1);
		}
		return ret;
	}

	public int combm1(int n, int[] aff){
		HashMap<Long,Integer> map = new HashMap();
		long sum = 0;
		int ret = 0;
		map.put(sum, 1);

		for(int i : aff){
			sum += i;
			ret += getCount(map, sum + 1);
			ret += getCount(map, sum - 1);
			int j = getCount(map, sum);
			map.put(sum, j+1);
		}
		return ret;
	}

	private int getCount(HashMap<Long, Integer> map, long sum){
		Integer i = map.get(sum);
		if(i==null) return 0;
		else return i;
	}
}


import java.util.*;

public class ProbC {
	public static void main(String[] args) {
		ProbC sol = new ProbC();
		sol.start();
	}

	public void print(Object o){ System.out.print(o); }
	public void println(Object o) { System.out.println(o); }

	public void start(){
		submit();
//		testGen();
	}

	public void testGen(){
		int n = 100000, k = 0;
		println(n+ " "+k);
		int[] a = new int[n];
		for(int i=0;i<n;i++) a[i] = 0;
		System.out.println(combinations(n, k, a));
	}

	public void submit(){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt(), k = scan.nextInt();
		int[] a = new int[n];
		for(int i=0;i<n;i++) a[i] = scan.nextInt();
		scan.close();

		System.out.println(combinations(n, k, a));
		System.out.flush();
	}

	public long combinations(int n, int k, int[] aff){
		if(k==0) return comb0(n, aff);
		else if(k==1) return comb1(n, aff);
		else if(k==-1) return combm1(n, aff);
		HashMap<Long,Integer> map = new HashMap();
		long sum = 0;
		long ret = 0;
		map.put(sum, 1);
		for(int i : aff){
			sum += i;
			long base = 1;
			while(Math.abs(base) < Long.MAX_VALUE / Math.abs(k)){
				ret += getCount(map, sum - base);
				base *= k;
			}
			int j = getCount(map, sum);
			map.put(sum, j+1);
		}
		return ret;
	}

	public long comb0(int n, int[] aff){
		HashMap<Long,Integer> map = new HashMap();
		long sum = 0;
		long ret = 0;
		map.put(sum, 1);
		for(int i : aff){
			sum += i;
			int j = getCount(map, sum);
			ret += j;
			map.put(sum, j+1);
		}
		return ret;
	}

	public long comb1(int n, int[] aff){
		HashMap<Long,Integer> map = new HashMap();
		long sum = 0;
		long ret = 0;
		map.put(sum, 1);

		for(int i : aff){
			sum += i;
			ret += getCount(map, sum - 1);
			int j = getCount(map, sum);
			map.put(sum, j+1);
		}
		return ret;
	}

	public int combm1(int n, int[] aff){
		HashMap<Long,Integer> map = new HashMap();
		long sum = 0;
		int ret = 0;
		map.put(sum, 1);

		for(int i : aff){
			sum += i;
			ret += getCount(map, sum + 1);
			ret += getCount(map, sum - 1);
			int j = getCount(map, sum);
			map.put(sum, j+1);
		}
		return ret;
	}

	private int getCount(HashMap<Long, Integer> map, long sum){
		Integer i = map.get(sum);
		if(i==null) return 0;
		else return i;
	}
}


import java.io.*;
import java.util.*;

public class MainClass
{
    public static void main(String[] args)throws IOException
    {
        Reader in = new Reader();
        int n = in.nextInt();
        int k = in.nextInt();
        long[] A = new long[n];
        for (int i=0;i<n;i++)   A[i] = in.nextLong();
        long[] S = new long[n];
        S[0] = A[0];
        for (int i=1;i<n;i++)   S[i] = S[i - 1] + A[i];
        long ans = 0L;
        if (k == 1)
            ans = solve(S, 1);
        else if (k == -1)
            ans = solve(S, 1) + solve(S, -1);
        else
        {
            long val = 1;
            while ((long)Math.abs(val) <= (long)(1e14))
            {
                ans += solve(S, val);
                val *= k;
            }
        }
        System.out.println(ans);
    }
    public static long solve(long[] S, long val)
    {
        int n = S.length;
        HashMap<Long, Integer> h = new HashMap<>();
        for (int i=0;i<n;i++)
        {
            if (!h.containsKey(S[i]))
                h.put(S[i], 1);
            else
                h.put(S[i], h.get(S[i]) + 1);
        }
        long ans = h.getOrDefault(val, 0);
        for (int i=0;i<n;i++)
        {
            h.put(S[i], h.get(S[i]) - 1);
            if (h.get(S[i]) == 0)
                h.remove(S[i]);
            long start = S[i] + val;
            ans += h.getOrDefault(start, 0);
        }
        return ans;
    }
}
class Reader
{
    final private int BUFFER_SIZE = 1 << 16;
    private DataInputStream din;
    private byte[] buffer;
    private int bufferPointer, bytesRead;

    public Reader()
    {
        din = new DataInputStream(System.in);
        buffer = new byte[BUFFER_SIZE];
        bufferPointer = bytesRead = 0;
    }

    public Reader(String file_name) throws IOException
    {
        din = new DataInputStream(new FileInputStream(file_name));
        buffer = new byte[BUFFER_SIZE];
        bufferPointer = bytesRead = 0;
    }

    public String readLine() throws IOException
    {
        byte[] buf = new byte[64]; // line length
        int cnt = 0, c;
        while ((c = read()) != -1)
        {
            if (c == '\n')
                break;
            buf[cnt++] = (byte) c;
        }
        return new String(buf, 0, cnt);
    }

    public int nextInt() throws IOException
    {
        int ret = 0;
        byte c = read();
        while (c <= ' ')
            c = read();
        boolean neg = (c == '-');
        if (neg)
            c = read();
        do
        {
            ret = ret * 10 + c - '0';
        }  while ((c = read()) >= '0' && c <= '9');

        if (neg)
            return -ret;
        return ret;
    }

    public long nextLong() throws IOException
    {
        long ret = 0;
        byte c = read();
        while (c <= ' ')
            c = read();
        boolean neg = (c == '-');
        if (neg)
            c = read();
        do {
            ret = ret * 10 + c - '0';
        }
        while ((c = read()) >= '0' && c <= '9');
        if (neg)
            return -ret;
        return ret;
    }

    public double nextDouble() throws IOException
    {
        double ret = 0, div = 1;
        byte c = read();
        while (c <= ' ')
            c = read();
        boolean neg = (c == '-');
        if (neg)
            c = read();

        do {
            ret = ret * 10 + c - '0';
        }
        while ((c = read()) >= '0' && c <= '9');

        if (c == '.')
        {
            while ((c = read()) >= '0' && c <= '9')
            {
                ret += (c - '0') / (div *= 10);
            }
        }

        if (neg)
            return -ret;
        return ret;
    }

    private void fillBuffer() throws IOException
    {
        bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
        if (bytesRead == -1)
            buffer[0] = -1;
    }

    private byte read() throws IOException
    {
        if (bufferPointer == bytesRead)
            fillBuffer();
        return buffer[bufferPointer++];
    }

    public void close() throws IOException
    {
        if (din == null)
            return;
        din.close();
    }
}


import java.io.*;
import java.util.*;

public class MainClass
{
    public static void main(String[] args)throws IOException
    {
        Reader in = new Reader();
        int n = in.nextInt();
        int k = in.nextInt();
        long[] A = new long[n];
        for (int i=0;i<n;i++)   A[i] = in.nextLong();
        long[] S = new long[n];
        S[0] = A[0];
        for (int i=1;i<n;i++)   S[i] = S[i - 1] + A[i];
        long ans = 0L;
        if (k == 1)
            ans = solve(S, 1);
        else
        {
            long val = 1;
            while ((long)Math.abs(val) <= (long)(1e14))
            {
                ans += solve(S, val);
                val *= k;
            }
            System.out.println(ans);
        }
    }
    public static long solve(long[] S, long val)
    {
        int n = S.length;
        HashMap<Long, Integer> h = new HashMap<>();
        for (int i=0;i<n;i++)
        {
            if (!h.containsKey(S[i]))
                h.put(S[i], 1);
            else
                h.put(S[i], h.get(S[i]) + 1);
        }
        long ans = h.getOrDefault(val, 0);
        for (int i=0;i<n;i++)
        {
            h.put(S[i], h.get(S[i]) - 1);
            if (h.get(S[i]) == 0)
                h.remove(S[i]);
            long start = S[i] + val;
            ans += h.getOrDefault(start, 0);
        }
        return ans;
    }
}
class Reader
{
    final private int BUFFER_SIZE = 1 << 16;
    private DataInputStream din;
    private byte[] buffer;
    private int bufferPointer, bytesRead;

    public Reader()
    {
        din = new DataInputStream(System.in);
        buffer = new byte[BUFFER_SIZE];
        bufferPointer = bytesRead = 0;
    }

    public Reader(String file_name) throws IOException
    {
        din = new DataInputStream(new FileInputStream(file_name));
        buffer = new byte[BUFFER_SIZE];
        bufferPointer = bytesRead = 0;
    }

    public String readLine() throws IOException
    {
        byte[] buf = new byte[64]; // line length
        int cnt = 0, c;
        while ((c = read()) != -1)
        {
            if (c == '\n')
                break;
            buf[cnt++] = (byte) c;
        }
        return new String(buf, 0, cnt);
    }

    public int nextInt() throws IOException
    {
        int ret = 0;
        byte c = read();
        while (c <= ' ')
            c = read();
        boolean neg = (c == '-');
        if (neg)
            c = read();
        do
        {
            ret = ret * 10 + c - '0';
        }  while ((c = read()) >= '0' && c <= '9');

        if (neg)
            return -ret;
        return ret;
    }

    public long nextLong() throws IOException
    {
        long ret = 0;
        byte c = read();
        while (c <= ' ')
            c = read();
        boolean neg = (c == '-');
        if (neg)
            c = read();
        do {
            ret = ret * 10 + c - '0';
        }
        while ((c = read()) >= '0' && c <= '9');
        if (neg)
            return -ret;
        return ret;
    }

    public double nextDouble() throws IOException
    {
        double ret = 0, div = 1;
        byte c = read();
        while (c <= ' ')
            c = read();
        boolean neg = (c == '-');
        if (neg)
            c = read();

        do {
            ret = ret * 10 + c - '0';
        }
        while ((c = read()) >= '0' && c <= '9');

        if (c == '.')
        {
            while ((c = read()) >= '0' && c <= '9')
            {
                ret += (c - '0') / (div *= 10);
            }
        }

        if (neg)
            return -ret;
        return ret;
    }

    private void fillBuffer() throws IOException
    {
        bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
        if (bytesRead == -1)
            buffer[0] = -1;
    }

    private byte read() throws IOException
    {
        if (bufferPointer == bytesRead)
            fillBuffer();
        return buffer[bufferPointer++];
    }

    public void close() throws IOException
    {
        if (din == null)
            return;
        din.close();
    }
}


import java.io.*;
import java.util.*;

public class MainClass
{
    public static void main(String[] args)throws IOException
    {
        Reader in = new Reader();
        int n = in.nextInt();
        int k = in.nextInt();
        long[] A = new long[n];
        for (int i=0;i<n;i++)   A[i] = in.nextLong();
        long[] S = new long[n];
        S[0] = A[0];
        for (int i=1;i<n;i++)   S[i] = S[i - 1] + A[i];
        long ans = 0L;
        if (k == 1)
            ans = solve(S, 1);
        else if (k == -1)
            ans = solve(S, 1) + solve(S, -1);
        else
        {
            long val = 1;
            while ((long)Math.abs(val) <= (long)(1e14))
            {
                ans += solve(S, val);
                val *= k;
            }
            System.out.println(ans);
        }
    }
    public static long solve(long[] S, long val)
    {
        int n = S.length;
        HashMap<Long, Integer> h = new HashMap<>();
        for (int i=0;i<n;i++)
        {
            if (!h.containsKey(S[i]))
                h.put(S[i], 1);
            else
                h.put(S[i], h.get(S[i]) + 1);
        }
        long ans = h.getOrDefault(val, 0);
        for (int i=0;i<n;i++)
        {
            h.put(S[i], h.get(S[i]) - 1);
            if (h.get(S[i]) == 0)
                h.remove(S[i]);
            long start = S[i] + val;
            ans += h.getOrDefault(start, 0);
        }
        return ans;
    }
}
class Reader
{
    final private int BUFFER_SIZE = 1 << 16;
    private DataInputStream din;
    private byte[] buffer;
    private int bufferPointer, bytesRead;

    public Reader()
    {
        din = new DataInputStream(System.in);
        buffer = new byte[BUFFER_SIZE];
        bufferPointer = bytesRead = 0;
    }

    public Reader(String file_name) throws IOException
    {
        din = new DataInputStream(new FileInputStream(file_name));
        buffer = new byte[BUFFER_SIZE];
        bufferPointer = bytesRead = 0;
    }

    public String readLine() throws IOException
    {
        byte[] buf = new byte[64]; // line length
        int cnt = 0, c;
        while ((c = read()) != -1)
        {
            if (c == '\n')
                break;
            buf[cnt++] = (byte) c;
        }
        return new String(buf, 0, cnt);
    }

    public int nextInt() throws IOException
    {
        int ret = 0;
        byte c = read();
        while (c <= ' ')
            c = read();
        boolean neg = (c == '-');
        if (neg)
            c = read();
        do
        {
            ret = ret * 10 + c - '0';
        }  while ((c = read()) >= '0' && c <= '9');

        if (neg)
            return -ret;
        return ret;
    }

    public long nextLong() throws IOException
    {
        long ret = 0;
        byte c = read();
        while (c <= ' ')
            c = read();
        boolean neg = (c == '-');
        if (neg)
            c = read();
        do {
            ret = ret * 10 + c - '0';
        }
        while ((c = read()) >= '0' && c <= '9');
        if (neg)
            return -ret;
        return ret;
    }

    public double nextDouble() throws IOException
    {
        double ret = 0, div = 1;
        byte c = read();
        while (c <= ' ')
            c = read();
        boolean neg = (c == '-');
        if (neg)
            c = read();

        do {
            ret = ret * 10 + c - '0';
        }
        while ((c = read()) >= '0' && c <= '9');

        if (c == '.')
        {
            while ((c = read()) >= '0' && c <= '9')
            {
                ret += (c - '0') / (div *= 10);
            }
        }

        if (neg)
            return -ret;
        return ret;
    }

    private void fillBuffer() throws IOException
    {
        bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
        if (bytesRead == -1)
            buffer[0] = -1;
    }

    private byte read() throws IOException
    {
        if (bufferPointer == bytesRead)
            fillBuffer();
        return buffer[bufferPointer++];
    }

    public void close() throws IOException
    {
        if (din == null)
            return;
        din.close();
    }
}


import java.io.*;
import java.util.*;

public class MainClass
{
    static HashMap<Long, Integer> hCentral = new HashMap<>();
    public static void main(String[] args)throws IOException
    {
        Reader in = new Reader();
        int n = in.nextInt();
        int k = in.nextInt();
        long[] A = new long[n];
        for (int i=0;i<n;i++)   A[i] = in.nextLong();
        long[] S = new long[n];
        S[0] = A[0];
        for (int i=1;i<n;i++)   S[i] = S[i - 1] + A[i];
        for (int i=0;i<n;i++)
        {
            if (!hCentral.containsKey(S[i]))
                hCentral.put(S[i], 1);
            else
                hCentral.put(S[i], hCentral.get(S[i]) + 1);
        }
        long ans = 0L;
        if (k == 1)
            ans = solve(S, 1);
        else if (k == -1)
            ans = solve(S, 1) + solve(S, -1);
        else
        {
            long val = 1;
            while ((long)Math.abs(val) <= (long)(1e14))
            {
                ans += solve(S, val);
                val *= k;
            }
        }
        System.out.println(ans);
    }
    public static long solve(long[] S, long val)
    {
        int n = S.length;
        HashMap<Long, Integer> h = (HashMap<Long, Integer>) hCentral.clone();
        long ans = h.getOrDefault(val, 0);
        for (int i=0;i<n;i++)
        {
            h.put(S[i], h.get(S[i]) - 1);
            if (h.get(S[i]) == 0)
                h.remove(S[i]);
            long start = S[i] + val;
            ans += h.getOrDefault(start, 0);
        }
        return ans;
    }
}
class Reader
{
    final private int BUFFER_SIZE = 1 << 16;
    private DataInputStream din;
    private byte[] buffer;
    private int bufferPointer, bytesRead;

    public Reader()
    {
        din = new DataInputStream(System.in);
        buffer = new byte[BUFFER_SIZE];
        bufferPointer = bytesRead = 0;
    }

    public Reader(String file_name) throws IOException
    {
        din = new DataInputStream(new FileInputStream(file_name));
        buffer = new byte[BUFFER_SIZE];
        bufferPointer = bytesRead = 0;
    }

    public String readLine() throws IOException
    {
        byte[] buf = new byte[64]; // line length
        int cnt = 0, c;
        while ((c = read()) != -1)
        {
            if (c == '\n')
                break;
            buf[cnt++] = (byte) c;
        }
        return new String(buf, 0, cnt);
    }

    public int nextInt() throws IOException
    {
        int ret = 0;
        byte c = read();
        while (c <= ' ')
            c = read();
        boolean neg = (c == '-');
        if (neg)
            c = read();
        do
        {
            ret = ret * 10 + c - '0';
        }  while ((c = read()) >= '0' && c <= '9');

        if (neg)
            return -ret;
        return ret;
    }

    public long nextLong() throws IOException
    {
        long ret = 0;
        byte c = read();
        while (c <= ' ')
            c = read();
        boolean neg = (c == '-');
        if (neg)
            c = read();
        do {
            ret = ret * 10 + c - '0';
        }
        while ((c = read()) >= '0' && c <= '9');
        if (neg)
            return -ret;
        return ret;
    }

    public double nextDouble() throws IOException
    {
        double ret = 0, div = 1;
        byte c = read();
        while (c <= ' ')
            c = read();
        boolean neg = (c == '-');
        if (neg)
            c = read();

        do {
            ret = ret * 10 + c - '0';
        }
        while ((c = read()) >= '0' && c <= '9');

        if (c == '.')
        {
            while ((c = read()) >= '0' && c <= '9')
            {
                ret += (c - '0') / (div *= 10);
            }
        }

        if (neg)
            return -ret;
        return ret;
    }

    private void fillBuffer() throws IOException
    {
        bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
        if (bytesRead == -1)
            buffer[0] = -1;
    }

    private byte read() throws IOException
    {
        if (bufferPointer == bytesRead)
            fillBuffer();
        return buffer[bufferPointer++];
    }

    public void close() throws IOException
    {
        if (din == null)
            return;
        din.close();
    }
}


import java.util.*;

import java.io.*;

public class Solution {

		public static void run(InputReader in ,PrintWriter out){
			int n = in.nextInt();
			long k = in.nextLong();
			long[] arr = new long[n+5];
			long[] sum = new long[n+5];
			for(int i = 0 ; i < n ; i ++){
				arr[i] = in.nextLong();
			}
			sum[0] = arr[0];
			long m = (long)Math.pow(10, 15) + 1000;
			for(int i = 1 ; i < n ; i++){
				sum[i] = sum[i-1] + arr[i];
			}
			long tr = 1;
			long ans = 0;
			if(k == -1 || k == 1){
				for(tr = k ; tr < 2 ; tr += 2){
					HashMap<Long,Integer> h = new HashMap<>();
					h.put((long)0, 1);
					for(int i = 0 ; i < n ; i++){
						if(h.containsKey(sum[i] - tr)){
							ans += h.get(sum[i] - tr);
						}
						if(h.containsKey(sum[i])){
							h.put(sum[i], h.get(sum[i])+1);
						}else h.put(sum[i], 1);
					}
				}
				out.println(ans);
				return;
			}
			while(tr <= m){
				HashMap<Long,Integer> h = new HashMap<>();
				h.put((long)0, 1);
				for(int i = 0 ; i < n ; i++){
					if(h.containsKey(sum[i] - tr)){
						ans += h.get(sum[i] - tr);
					}
					if(h.containsKey(sum[i])){
						h.put(sum[i], h.get(sum[i])+1);
					}else h.put(sum[i], 1);
				}
				tr *= k;
			}
			out.println(ans);
		}

		public static void main(String[] args) {
			InputReader in = new InputReader(System.in);
			PrintWriter out = new PrintWriter(System.out);
			run(in,out);
			out.close();
		}

		static class InputReader {
			public BufferedReader reader;
			public StringTokenizer tokenizer;

			public InputReader(InputStream stream) {
				reader = new BufferedReader(new InputStreamReader(stream), 32768);
				tokenizer = null;
			}

			public String next() {
				while (tokenizer == null || !tokenizer.hasMoreTokens()) {
					try {
						tokenizer = new StringTokenizer(reader.readLine());
					} catch (IOException e) {
						throw new RuntimeException(e);
					}
				}
				return tokenizer.nextToken();
			}

			public int nextInt() {
				return Integer.parseInt(next());
			}
			public double nextDouble() {
				return Double.parseDouble(next());
			}
			public long nextLong() {
				return Long.parseLong(next());
			}

		}
	}


import java.util.*;

import java.io.*;

public class Solution {

		public static void run(InputReader in ,PrintWriter out){
			int n = in.nextInt();
			long k = in.nextLong();
			long[] arr = new long[n+5];
			long[] sum = new long[n+5];
			for(int i = 0 ; i < n ; i ++){
				arr[i] = in.nextLong();
			}
			sum[0] = arr[0];
			long m = (long)Math.pow(10, 15) + 1000;
			for(int i = 1 ; i < n ; i++){
				sum[i] = sum[i-1] + arr[i];
			}
			long tr = 1;
			long ans = 0;
			while(tr <= m){
				HashMap<Long,Integer> h = new HashMap<>();
				h.put((long)0, 1);
				for(int i = 0 ; i < n ; i++){
					if(h.containsKey(sum[i] - tr)){
						ans += h.get(sum[i] - tr);
					}
					if(h.containsKey(sum[i])){
						h.put(sum[i], h.get(sum[i])+1);
					}else h.put(sum[i], 1);
				}
				tr *= k;
			}
			out.println(ans);
		}

		public static void main(String[] args) {
			InputReader in = new InputReader(System.in);
			PrintWriter out = new PrintWriter(System.out);
			run(in,out);
			out.close();
		}

		static class InputReader {
			public BufferedReader reader;
			public StringTokenizer tokenizer;

			public InputReader(InputStream stream) {
				reader = new BufferedReader(new InputStreamReader(stream), 32768);
				tokenizer = null;
			}

			public String next() {
				while (tokenizer == null || !tokenizer.hasMoreTokens()) {
					try {
						tokenizer = new StringTokenizer(reader.readLine());
					} catch (IOException e) {
						throw new RuntimeException(e);
					}
				}
				return tokenizer.nextToken();
			}

			public int nextInt() {
				return Integer.parseInt(next());
			}
			public double nextDouble() {
				return Double.parseDouble(next());
			}
			public long nextLong() {
				return Long.parseLong(next());
			}

		}
	}


import java.util.*;

import java.io.*;

public class Solution {

		public static void run(InputReader in ,PrintWriter out){
			int n = in.nextInt();
			long k = in.nextLong();
			long[] arr = new long[n+5];
			long[] sum = new long[n+5];
			for(int i = 0 ; i < n ; i ++){
				arr[i] = in.nextLong();
			}
			sum[0] = arr[0];
			long m = (long)Math.pow(10, 15) + 1000;
			for(int i = 1 ; i < n ; i++){
				sum[i] = sum[i-1] + arr[i];
			}
			long tr = 1;
			long ans = 0;
			while(tr <= m){
				HashMap<Long,Integer> h = new HashMap<>();
				h.put((long)0, 1);
				for(int i = 0 ; i < n ; i++){
					if(h.containsKey(sum[i] - tr)){
						ans += h.get(sum[i] - tr);
					}
					if(h.containsKey(sum[i])){
						h.put(sum[i], h.get(sum)+1);
					}else h.put(sum[i], 1);
				}
				tr *= k;
			}
			out.println(ans);
		}

		public static void main(String[] args) {
			InputReader in = new InputReader(System.in);
			PrintWriter out = new PrintWriter(System.out);
			run(in,out);
			out.close();
		}

		static class InputReader {
			public BufferedReader reader;
			public StringTokenizer tokenizer;

			public InputReader(InputStream stream) {
				reader = new BufferedReader(new InputStreamReader(stream), 32768);
				tokenizer = null;
			}

			public String next() {
				while (tokenizer == null || !tokenizer.hasMoreTokens()) {
					try {
						tokenizer = new StringTokenizer(reader.readLine());
					} catch (IOException e) {
						throw new RuntimeException(e);
					}
				}
				return tokenizer.nextToken();
			}

			public int nextInt() {
				return Integer.parseInt(next());
			}
			public double nextDouble() {
				return Double.parseDouble(next());
			}
			public long nextLong() {
				return Long.parseLong(next());
			}

		}
	}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.SortedSet;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

/**
 * #
 * @author pttrung
 */
public class C_Round_400 {

    public static long MOD = 1000000007;

    public static void main(String[] args) throws FileNotFoundException {
        // PrintWriter out = new PrintWriter(new FileOutputStream(new File(
        // "output.txt")));
        PrintWriter out = new PrintWriter(System.out);
        Scanner in = new Scanner();
        int n = in.nextInt();
        int k = in.nextInt();
        ArrayList<Long> list = new ArrayList();
        long s = 1;
        list.add(1L);
        if (Math.abs(k) != 1) {
            while (s <= 1e15) {
                s *= k;
                list.add(s);
            }
        }
        HashMap<Long, Integer> map = new HashMap();
        long total = 0;
        map.put(0L, 1);
        long result = 0;
        for (int i = 0; i < n; i++) {
            total += in.nextLong();
            for (long v : list) {
                long need = total - v;
                result += map.getOrDefault(need, 0);
            }
            map.put(total, map.getOrDefault(total, 0) + 1);
        }
        out.println(result);
        out.close();
    }

    public static int[] KMP(String val) {
        int i = 0;
        int j = -1;
        int[] result = new int[val.length() + 1];
        result[0] = -1;
        while (i < val.length()) {
            while (j >= 0 && val.charAt(j) != val.charAt(i)) {
                j = result[j];
            }
            j++;
            i++;
            result[i] = j;
        }
        return result;

    }

    public static boolean nextPer(int[] data) {
        int i = data.length - 1;
        while (i > 0 && data[i] < data[i - 1]) {
            i--;
        }
        if (i == 0) {
            return false;
        }
        int j = data.length - 1;
        while (data[j] < data[i - 1]) {
            j--;
        }
        int temp = data[i - 1];
        data[i - 1] = data[j];
        data[j] = temp;
        Arrays.sort(data, i, data.length);
        return true;
    }

    public static int digit(long n) {
        int result = 0;
        while (n > 0) {
            n /= 10;
            result++;
        }
        return result;
    }

    public static double dist(long a, long b, long x, long y) {
        double val = (b - a) * (b - a) + (x - y) * (x - y);
        val = Math.sqrt(val);
        double other = x * x + a * a;
        other = Math.sqrt(other);
        return val + other;

    }

    public static class Point implements Comparable<Point> {

        int x, y;

        public Point(int start, int end) {
            this.x = start;
            this.y = end;
        }

        @Override
        public int hashCode() {
            int hash = 5;
            hash = 47 * hash + this.x;
            hash = 47 * hash + this.y;
            return hash;
        }

        @Override
        public boolean equals(Object obj) {
            if (obj == null) {
                return false;
            }
            if (getClass() != obj.getClass()) {
                return false;
            }
            final Point other = (Point) obj;
            if (this.x != other.x) {
                return false;
            }
            if (this.y != other.y) {
                return false;
            }
            return true;
        }

        @Override
        public int compareTo(Point o) {
            return Integer.compare(x, o.x);
        }
    }

    public static class FT {

        long[] data;

        FT(int n) {
            data = new long[n];
        }

        public void update(int index, long value) {
            while (index < data.length) {
                data[index] += value;
                index += (index & (-index));
            }
        }

        public long get(int index) {
            long result = 0;
            while (index > 0) {
                result += data[index];
                index -= (index & (-index));
            }
            return result;

        }
    }

    public static long gcd(long a, long b) {
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    }

    public static long pow(long a, long b, long MOD) {
        if (b == 0) {
            return 1;
        }
        if (b == 1) {
            return a;
        }
        long val = pow(a, b / 2, MOD);
        if (b % 2 == 0) {
            return val * val % MOD;
        } else {
            return val * (val * a % MOD) % MOD;

        }
    }

    static class Scanner {

        BufferedReader br;
        StringTokenizer st;

        public Scanner() throws FileNotFoundException {
            // System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));
            br = new BufferedReader(new InputStreamReader(System.in));
            //  br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("input.txt"))));
        }

        public String next() {

            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (Exception e) {
                    throw new RuntimeException();
                }
            }
            return st.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public String nextLine() {
            st = null;
            try {
                return br.readLine();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }

        public boolean endLine() {
            try {
                String next = br.readLine();
                while (next != null && next.trim().isEmpty()) {
                    next = br.readLine();
                }
                if (next == null) {
                    return true;
                }
                st = new StringTokenizer(next);
                return st.hasMoreTokens();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }
    }
}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.SortedSet;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

/**
 * #
 * @author pttrung
 */
public class C_Round_400 {

    public static long MOD = 1000000007;

    public static void main(String[] args) throws FileNotFoundException {
        // PrintWriter out = new PrintWriter(new FileOutputStream(new File(
        // "output.txt")));
        PrintWriter out = new PrintWriter(System.out);
        Scanner in = new Scanner();
        int n = in.nextInt();
        int k = in.nextInt();
        HashSet<Long> list = new HashSet();
        long s = 1;
        list.add(1L);
        list.add((long)k);
        if (Math.abs(k) != 1) {
            while (s <= 1e15) {
                s *= k;
                list.add(s);
            }
        }
        HashMap<Long, Long> map = new HashMap();
        long total = 0;
        map.put(0L, 1L);
        long result = 0;
        for (int i = 0; i < n; i++) {
            total += in.nextLong();
            for (long v : list) {
                long need = total - v;
                result += map.getOrDefault(need, 0L);
            }
            map.put(total, map.getOrDefault(total, 0L) + 1);
        }
        out.println(result);
        out.close();
    }

    public static int[] KMP(String val) {
        int i = 0;
        int j = -1;
        int[] result = new int[val.length() + 1];
        result[0] = -1;
        while (i < val.length()) {
            while (j >= 0 && val.charAt(j) != val.charAt(i)) {
                j = result[j];
            }
            j++;
            i++;
            result[i] = j;
        }
        return result;

    }

    public static boolean nextPer(int[] data) {
        int i = data.length - 1;
        while (i > 0 && data[i] < data[i - 1]) {
            i--;
        }
        if (i == 0) {
            return false;
        }
        int j = data.length - 1;
        while (data[j] < data[i - 1]) {
            j--;
        }
        int temp = data[i - 1];
        data[i - 1] = data[j];
        data[j] = temp;
        Arrays.sort(data, i, data.length);
        return true;
    }

    public static int digit(long n) {
        int result = 0;
        while (n > 0) {
            n /= 10;
            result++;
        }
        return result;
    }

    public static double dist(long a, long b, long x, long y) {
        double val = (b - a) * (b - a) + (x - y) * (x - y);
        val = Math.sqrt(val);
        double other = x * x + a * a;
        other = Math.sqrt(other);
        return val + other;

    }

    public static class Point implements Comparable<Point> {

        int x, y;

        public Point(int start, int end) {
            this.x = start;
            this.y = end;
        }

        @Override
        public int hashCode() {
            int hash = 5;
            hash = 47 * hash + this.x;
            hash = 47 * hash + this.y;
            return hash;
        }

        @Override
        public boolean equals(Object obj) {
            if (obj == null) {
                return false;
            }
            if (getClass() != obj.getClass()) {
                return false;
            }
            final Point other = (Point) obj;
            if (this.x != other.x) {
                return false;
            }
            if (this.y != other.y) {
                return false;
            }
            return true;
        }

        @Override
        public int compareTo(Point o) {
            return Integer.compare(x, o.x);
        }
    }

    public static class FT {

        long[] data;

        FT(int n) {
            data = new long[n];
        }

        public void update(int index, long value) {
            while (index < data.length) {
                data[index] += value;
                index += (index & (-index));
            }
        }

        public long get(int index) {
            long result = 0;
            while (index > 0) {
                result += data[index];
                index -= (index & (-index));
            }
            return result;

        }
    }

    public static long gcd(long a, long b) {
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    }

    public static long pow(long a, long b, long MOD) {
        if (b == 0) {
            return 1;
        }
        if (b == 1) {
            return a;
        }
        long val = pow(a, b / 2, MOD);
        if (b % 2 == 0) {
            return val * val % MOD;
        } else {
            return val * (val * a % MOD) % MOD;

        }
    }

    static class Scanner {

        BufferedReader br;
        StringTokenizer st;

        public Scanner() throws FileNotFoundException {
            // System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));
            br = new BufferedReader(new InputStreamReader(System.in));
            //  br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("input.txt"))));
        }

        public String next() {

            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (Exception e) {
                    throw new RuntimeException();
                }
            }
            return st.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public String nextLine() {
            st = null;
            try {
                return br.readLine();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }

        public boolean endLine() {
            try {
                String next = br.readLine();
                while (next != null && next.trim().isEmpty()) {
                    next = br.readLine();
                }
                if (next == null) {
                    return true;
                }
                st = new StringTokenizer(next);
                return st.hasMoreTokens();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }
    }
}