fork(1) download
  1. import java.io.*;
  2.  
  3. public class Main {
  4. final static String dirs = "NSEW";
  5.  
  6. public static void solve(Input in, PrintWriter out) throws IOException {
  7. int n = in.nextInt() - 1;
  8. String s1 = in.next();
  9. String s2 = in.next();
  10. StringBuilder sb = new StringBuilder();
  11. for (int i = 0; i < n; ++i) {
  12. sb.append(dirs.charAt(dirs.indexOf(s1.charAt(n - i - 1)) ^ 1));
  13. }
  14. sb.append(s2);
  15. int[] p = new int[2 * n];
  16. for (int i = 1; i < 2 * n; ++i) {
  17. p[i] = p[i - 1];
  18. while (p[i] != 0 && sb.charAt(i) != sb.charAt(p[i])) {
  19. p[i] = p[p[i] - 1];
  20. }
  21. if (sb.charAt(i) == sb.charAt(p[i])) {
  22. p[i]++;
  23. }
  24. }
  25. out.println(p[2 * n - 1] == 0 ? "YES" : "NO");
  26. }
  27.  
  28. public static void main(String[] args) throws IOException {
  29. PrintWriter out = new PrintWriter(System.out);
  30. solve(new Input(new BufferedReader(new InputStreamReader(System.in))), out);
  31. out.close();
  32. }
  33.  
  34. static class Input {
  35. StringBuilder sb = new StringBuilder();
  36.  
  37. public Input(BufferedReader in) {
  38. this.in = in;
  39. }
  40.  
  41. public Input(String s) {
  42. this.in = new BufferedReader(new StringReader(s));
  43. }
  44.  
  45. public String next() throws IOException {
  46. sb.setLength(0);
  47. while (true) {
  48. int c = in.read();
  49. if (c == -1) {
  50. return null;
  51. }
  52. if (" \n\r\t".indexOf(c) == -1) {
  53. sb.append((char)c);
  54. break;
  55. }
  56. }
  57. while (true) {
  58. int c = in.read();
  59. if (c == -1 || " \n\r\t".indexOf(c) != -1) {
  60. break;
  61. }
  62. sb.append((char)c);
  63. }
  64. return sb.toString();
  65. }
  66.  
  67. public int nextInt() throws IOException {
  68. return Integer.parseInt(next());
  69. }
  70.  
  71. public long nextLong() throws IOException {
  72. return Long.parseLong(next());
  73. }
  74.  
  75. public double nextDouble() throws IOException {
  76. return Double.parseDouble(next());
  77. }
  78. }
  79. }
  80.  
Success #stdin #stdout 0.1s 320512KB
stdin
7
NNESWW
SWSWSW
stdout
YES