package yukiguni; import java.util.ArrayDeque; import java.util.Queue; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int h = sc.nextInt(); int w = sc.nextInt(); int a = sc.nextInt(); int si = sc.nextInt(); int sj = sc.nextInt(); int b = sc.nextInt(); int gi = sc.nextInt(); int gj = sc.nextInt(); char[][] m = new char[h][]; for(int i=0;i q = new ArrayDeque<>(); q.offer(a << 16 | si << 8 | sj); used[si][sj][a] = true; while(!q.isEmpty()) { int p = q.poll(); int cs = p >>> 16; int ci = p >>> 8 & 0xff; int cj = p & 0xff; for(int i=0;i<4;i++) { int ni = ci + DI[i]; int nj = cj + DJ[i]; if (ni < 0 || ni >= h || nj < 0 || nj >= w) { continue; } int ns = cs + (m[ni][nj] == '*' ? 1 : -1); if (ns > max || ns <= 0 || used[ni][nj][ns]) { continue; } used[ni][nj][ns] = true; q.offer(ns << 16 | ni << 8 | nj); } } return used[gi][gj][b]; } }