//////////////////////////
//////////////////////////
////Please give me AC!////
////Please give me AC!////
//////////////////////////
//////////////////////////
#include <bits/stdc++.h>
using namespace std;
int main(){
    int H,W,K,x1,y1,x2,y2;
    cin>>H>>W>>K>>x1>>y1>>x2>>y2;
    vector<char> pond(H*W);
    for(int i=0;i<H;i++){
        string S;
        cin>>S;
        for(int j=0;j<W;j++){
            pond.at(i*W+j)=S.at(j);
        }
    }
    vector<vector<int>> vec(H*W);
    for(int i=0;i<H*W;i++){
        if(pond.at(i)=='@'){
            continue;
        }
        if(i>=W){
            if(pond.at(i-W)!='@'){
                vec.at(i).push_back(i-W);
            }
        }
        if(i<W*(H-1)){
            if(pond.at(i+W)!='@'){
                vec.at(i).push_back(i+W);
            }
        }
        if(i%W!=0){
            if(pond.at(i-1)!='@'){
                vec.at(i).push_back(i-1);
            }
        }
        if(i%W!=W-1){
            if(pond.at(i+1)!='@'){
                vec.at(i).push_back(i+1);
            }
        }
    }
    vector<vector<int>> dist(H*W,vector<int>(4));
    for(int i=0;i<H*W;i++){
        for(int j=0;j<4;j++){
            dist.at(i).at(j)=10000000;
        }
    }
    queue<int> que;
    dist[W*(x1-1)+y1-1][0]=0;
    dist[W*(x1-1)+y1-1][1]=0;
    dist[W*(x1-1)+y1-1][2]=0;
    dist[W*(x1-1)+y1-1][3]=0;
    que.push(W*(x1-1)+y1-1);
    while(!que.empty()){
        int v=que.front();
        que.pop();
        for(int i=0;i<(int)vec.at(v).size();i++){
            int nv=vec.at(v).at(i);
            int n0,n1,n2,n3;
            if(nv-v==1){
                n0=dist[v][0]+1;
                if(dist[nv][0]>n0){
                    dist[nv][0]=n0;
                    dist[nv][1]=min(dist[nv][1],n0-n0%K+K*((n0%K+K-1)/K));
                    dist[nv][2]=min(dist[nv][2],n0-n0%K+K*((n0%K+K-1)/K));
                    dist[nv][3]=min(dist[nv][3],n0-n0%K+K*((n0%K+K-1)/K));
                    que.push(nv);
                }
            }
            if(nv-v==-W){
                n1=dist[v][1]+1;
                if(dist[nv][1]>n1){
                    dist[nv][1]=n1;
                    dist[nv][0]=min(dist[nv][0],n1-n1%K+K*((n1%K+K-1)/K));
                    dist[nv][2]=min(dist[nv][2],n1-n1%K+K*((n1%K+K-1)/K));
                    dist[nv][3]=min(dist[nv][3],n1-n1%K+K*((n1%K+K-1)/K));
                    que.push(nv);
                }
            }
            if(nv-v==-1){
                n2=dist[v][2]+1;
                if(dist[nv][2]>n2){
                    dist[nv][2]=n2;
                    dist[nv][0]=min(dist[nv][0],n2-n2%K+K*((n2%K+K-1)/K));
                    dist[nv][1]=min(dist[nv][1],n2-n2%K+K*((n2%K+K-1)/K));
                    dist[nv][3]=min(dist[nv][3],n2-n2%K+K*((n2%K+K-1)/K));
                    que.push(nv);
                }
            }
            if(nv-v==W){
                n3=dist[v][3]+1;
                if(dist[nv][3]>n3){
                    dist[nv][3]=n3;
                    dist[nv][0]=min(dist[nv][0],n3-n3%K+K*((n3%K+K-1)/K));
                    dist[nv][1]=min(dist[nv][1],n3-n3%K+K*((n3%K+K-1)/K));
                    dist[nv][2]=min(dist[nv][2],n3-n3%K+K*((n3%K+K-1)/K));
                    que.push(nv);
                }
            }
        }
    }
    int ans=min(min(dist[W*(x2-1)+y2-1][0],dist[W*(x2-1)+y2-1][1]),min(dist[W*(x2-1)+y2-1][2],dist[W*(x2-1)+y2-1][3]));
    if(ans==10000000){
        cout<<-1<<endl;
    }
    else{
        cout<<ans/K+(ans%K+K-1)/K<<endl;
    }
}

Measured memory_bytes: 113412