#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int H, W, K;
int x1, y1, x2, y2;
string c[1000000];

vector<int> vh[1000000], vw[1000000];
set<int> sth[1000000], stw[1000000];
vector<int> dist[1000000];

const int INF = 1e9;

void solve(){
    dist[x1][y1] = 0;
    queue<P> que;
    sth[x1].erase(y1);
    stw[y1].erase(x1);
    que.push(P(x1, y1));
    while(!que.empty()){
        P p = que.front(); que.pop();
        int h = p.first, w = p.second;
        // cout << "at (" << h << ',' << w << ") dist:" << dist[h][w] << endl;
        
        // up down
        auto pt = lower_bound(vw[w].begin(), vw[w].end(), h);
        int ub = max(*(pt-1), h-K-1);
        int lb = min(*pt, h+K+1);
        auto l = stw[w].lower_bound(ub+1);
        auto r = stw[w].lower_bound(lb);
        vector<int> delw;
        // cout << "size:" << vw[w].size() << endl;
        // cout << "max(" << *(pt-1) << ","  << h-K-1 << ") " <<  "min(" << *pt << ","  << h+K+1 << ") " << endl;
        // cout << *l << "-----------" << *r << endl;
        if((*l) < (*r)){
            for(auto ptr = l; ptr != r; ptr++){
                int h_ = *ptr;
                // cout << "insert (" << h_ << ',' << w << ")" << endl;
                dist[h_][w] = dist[h][w]+1;
                delw.push_back(h_);
                que.push(P(h_, w));
            }
            for(int h_:delw){
                sth[h_].erase(w);
                stw[w].erase(h_);
            }
        }
        // cout << "=============" << endl;
        // left right
        pt = lower_bound(vh[h].begin(), vh[h].end(), w);
        ub = max(*(pt-1), w-K-1);
        lb = min(*pt, w+K+1);
        l = sth[h].lower_bound(ub+1);
        r = sth[h].lower_bound(lb);
        vector<int> delh;
        // cout << "max(" << *(pt-1) << ","  << w-K << ") " <<  "min(" << *pt << ","  << w+K << ") " << endl;
        // cout << *l << "-----------" << *r << endl;
        if((*l) < (*r)){
            for(auto ptr = l; ptr != r; ptr++){
                int w_ = *ptr;
                // cout << "insert (" << h << ',' << w_ << ")" << endl;
                dist[h][w_] = dist[h][w]+1;
                delh.push_back(w_);
                que.push(P(h, w_));
            }
            for(int w_:delh){
                sth[h].erase(w_);
                stw[w_].erase(h);
            }
        }
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> H >> W >> K;
    cin >> x1 >> y1 >> x2 >> y2;
    x1--;y1--;x2--;y2--;
    for(int i = 0; i < H; i++) cin >> c[i];
    for(int i = 0; i < H; i++) sth[i].insert(-1);
    for(int i = 0; i < W; i++) stw[i].insert(-1);
    for(int i = 0; i < H; i++) vh[i].push_back(-1);
    for(int i = 0; i < W; i++) vw[i].push_back(-1);
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            dist[i].push_back(1e9);
            if(c[i][j] == '.'){
                sth[i].insert(j);
                stw[j].insert(i);
            }
            if(c[i][j] == '@'){
                vh[i].push_back(j);
                vw[j].push_back(i);
            }
        }
    }
    for(int i = 0; i < H; i++) vh[i].push_back(W);
    for(int i = 0; i < W; i++) vw[i].push_back(H);
    for(int i = 0; i < H; i++) sth[i].insert(W);
    for(int i = 0; i < W; i++) stw[i].insert(H);
    solve();
    if(dist[x2][y2] == INF){
        cout << -1 << endl;
    }else{
        cout << dist[x2][y2] << endl;
    }
}

Measured memory_bytes: 421712