Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- public class Main {
- static PrintWriter pw;
- public static void main(String[] args) throws FileNotFoundException {
- Scanner in = new Scanner(new File("input.txt"));
- pw = new PrintWriter(new File("output.txt"));
- int n = in.nextInt();
- int[] array = new int[n];
- for (int i = 0; i < n; i++) {
- array[i] = in.nextInt();
- }
- Stack<Integer> stack = new Stack<>();
- int k = 1;
- for (int c : array) {
- stack.push(c);
- while (!stack.empty() && stack.peek() == k) {
- stack.pop();
- k++;
- }
- }
- if (k != n + 1) {
- pw.println(0);
- pw.close();
- System.exit(0);
- }
- stack.clear();
- k = 1;
- for (int c : array) {
- stack.push(c);
- pw.println(1 + " " + 1);
- while (!stack.empty() && stack.peek() == k) {
- pw.println(2 + " " + 1);
- stack.pop();
- k++;
- }
- }
- pw.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment