fork download
  1. import java.io.*;
  2. import java.util.*;
  3.  
  4. import static java.lang.Math.*;
  5.  
  6. public class Main {
  7. FastScanner in;
  8.  
  9. static final String FILE = "powerstower";
  10.  
  11. void solve() {
  12. int n = in.nextInt();
  13. int[] ms = new int[n];
  14. for (int i = 0; i < n; i++)
  15. ms[i] = in.nextInt();
  16. if (n == 1) {
  17. out.print(ms[0] % 3);
  18. return;
  19. }
  20. for (int i = n - 1; i >= 1; i--) {
  21. ms[i] %= 2;
  22. if (ms[i] == 0)
  23. ms[i] = 0;
  24. else
  25. ms[i] = 1;
  26. if (i + 1 < n && ms[i + 1] == 0)
  27. ms[i] = 1;
  28. }
  29. int old = ms[0];
  30. ms[0] %= 3;
  31. if (ms[0] != 2)
  32. out.print(ms[0]);
  33. else
  34. out.print(ms[1] == 0 ? 1 : 2);
  35. }
  36.  
  37. public void run() {
  38. if (FILE.equals("")) {
  39. in = new FastScanner(System.in);
  40. out = new PrintWriter(System.out);
  41. } else {
  42. try {
  43. in = new FastScanner(new FileInputStream(FILE +
  44. ".in"));
  45. out = new PrintWriter(new FileOutputStream(FILE +
  46. ".out"));
  47. } catch (FileNotFoundException e) {
  48. e.printStackTrace();
  49. }
  50. }
  51. solve();
  52. out.close();
  53. }
  54.  
  55. public static void main(String[] args) {
  56. (new Main()).run();
  57. }
  58.  
  59. class FastScanner {
  60.  
  61. public FastScanner(InputStream is) {
  62. br = new BufferedReader(new InputStreamReader(is));
  63. }
  64.  
  65. public String next() {
  66. while (st == null || !st.hasMoreTokens()) {
  67. try {
  68. st = new StringTokenizer(br.readLine());
  69. } catch (IOException e) {
  70. e.printStackTrace();
  71. }
  72. }
  73. return st.nextToken();
  74. }
  75.  
  76. public String nextLine() {
  77. st = null;
  78. try {
  79. return br.readLine();
  80. } catch (IOException e) {
  81. e.printStackTrace();
  82. return null;
  83. }
  84. }
  85.  
  86. public int nextInt() {
  87. return Integer.parseInt(next());
  88. }
  89.  
  90. public long nextLong() {
  91. return Long.parseLong(next());
  92. }
  93.  
  94. public double nextDouble() {
  95. return Double.parseDouble(next());
  96. }
  97.  
  98. public float nextFloat() {
  99. return Float.parseFloat(next());
  100. }
  101. }
  102.  
  103. }
Runtime error #stdin #stdout #stderr 0.04s 711168KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
java.io.FileNotFoundException: powerstower.in (No such file or directory)
	at java.io.FileInputStream.open0(Native Method)
	at java.io.FileInputStream.open(FileInputStream.java:195)
	at java.io.FileInputStream.<init>(FileInputStream.java:138)
	at java.io.FileInputStream.<init>(FileInputStream.java:93)
	at Main.run(Main.java:44)
	at Main.main(Main.java:57)
Exception in thread "main" java.lang.NullPointerException
	at Main.solve(Main.java:13)
	at Main.run(Main.java:52)
	at Main.main(Main.java:57)