import java.awt.Point; import java.awt.Rectangle; import java.awt.geom.Rectangle2D; import java.io.BufferedInputStream; import java.io.IOException; import java.math.BigDecimal; import java.math.BigInteger; import java.util.*; import java.util.Map.Entry; import java.util.concurrent.ConcurrentSkipListSet; import javax.swing.ImageIcon; public class Main { static final long C = 1000000007; static final int CY = 1000000000; //long[] F; public void calc() { long fTime = System.currentTimeMillis(); StringBuilder sb = new StringBuilder(); BufferedInputStream bs = new BufferedInputStream(System.in); Scanner sc = new Scanner(bs); int h = sc.nextInt(); int w = sc.nextInt(); int f = sc.nextInt(); Point fp = new Point(sc.nextInt(), sc.nextInt()); g = sc.nextInt(); gp = new Point(sc.nextInt(), sc.nextInt()); map = new char[h][]; for (int i=0; i < h; i++) { map[i] = sc.next().toCharArray(); } memo = new boolean[h][w][1501]; boolean ans = false; memo[fp.x][fp.y][f] = true; HashSet ps = new HashSet(); ps.add(fp); do { HashSet rent = new HashSet(); for (Point p:ps) { rent.addAll(msd(p.x, p.y)); } ps = rent; }while(ps.size() > 0); ans = memo[gp.x][gp.y][g]; System.out.println(ans?"Yes":"No"); } //static int N = 1500; boolean[][][] memo ; char[][] map; int g; Point gp; HashSet msd(int x, int y) { HashSet ret = new HashSet(); if (memo[gp.x][gp.y][g]) { return ret; } int nx = x+1, ny = y; boolean isUp = false; boolean isDown = false; if (isIn(nx, ny)) { char nc = map[nx][ny]; if (nc == map[x][y]) { if (nc == '.' ) { isDown = true; }else { isUp = true; } } } nx = x-1;ny = y; if (isIn(nx, ny)) { char nc = map[nx][ny]; if (nc == map[x][y]) { if (nc == '.' ) { isDown = true; }else { isUp = true; } } } nx = x;ny = y+1; if (isIn(nx, ny)) { char nc = map[nx][ny]; if (nc == map[x][y]) { if (nc == '.' ) { isDown = true; }else { isUp = true; } } } nx = x;ny = y-1; if (isIn(nx, ny)) { char nc = map[nx][ny]; if (nc == map[x][y]) { if (nc == '.' ) { isDown = true; }else { isUp = true; } } } if (isDown) { int max = 0; for (int i=1499;i >= 0; i--) { if (memo[x][y][i] ){ max = i; break; } } for (int i=max;i >= 0; i-=2) { memo[x][y][i]= true; } } if (isUp ) { int max = 1500; for (int i=0;i < 1500; i++) { if (memo[x][y][i] ){ max = i; break; } } for (int i=max;i < 1500; i+=2) { memo[x][y][i]= true; } } nx = x+1;ny = y; if (check(x, y, nx, ny)) { ret.add(new Point(nx,ny)); } nx = x-1;ny = y; if (check(x, y, nx, ny)) { ret.add(new Point(nx,ny)); } nx = x;ny = y+1; if (check(x, y, nx, ny)) { ret.add(new Point(nx,ny)); } nx = x;ny = y-1; if (check(x, y, nx, ny)) { ret.add(new Point(nx,ny)); } return ret; } private boolean check(int x, int y, int nx, int ny) { int add; if (isIn(nx, ny)) { char nc = map[nx][ny]; add = nc == '.'?-1:1; boolean flag = false; for (int i=1; i < 1500; i++) { if (memo[x][y][i]) { if (!memo[nx][ny][i+add]) { memo[nx][ny][i+add] = true; flag = true; } } } return flag; } return false; } boolean isIn(int x, int y) { return !(x < 0 || y < 0 || map.length <= x || map[0].length <= y); } public static void main(String[] args) { Main main = new Main(); main.calc(); } }