fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. class Main
  6. {
  7. public static void main (String[] args) throws java.lang.Exception
  8. {
  9. Scanner in = new Scanner(System.in);
  10. int n = in.nextInt();
  11. int m = in.nextInt();
  12. int x = in.nextInt();
  13. int y = in.nextInt();
  14. int[][] arr = new int [n][m];
  15. int num = 0;
  16. for(int i = 0; i < n; ++i) {
  17. int dir, j;
  18. if(i % 2 == 0){
  19. j = 0;
  20. dir = 1;
  21. }
  22. else {
  23. j = m-1;
  24. dir = -1;
  25. }
  26. for(; j < m && j >= 0; j+= dir) {
  27. arr[i][j] = num;
  28. ++num;
  29. }
  30. }
  31. System.out.print(arr[x - 1][y - 1]);
  32. }
  33. }
Success #stdin #stdout 0.07s 2184192KB
stdin
5 2 3 1
stdout
4