import java.util.*;
import java.io.*;

public class kenobi_dk {
	BufferedReader br;
	PrintWriter out;
	StringTokenizer stok;

	String nextToken() throws IOException {
		while (stok == null || !stok.hasMoreTokens()) {
			String s = br.readLine();
			if (s == null) {
				return null;
			}
			stok = new StringTokenizer(s);
		}
		return stok.nextToken();
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	char nextChar() throws IOException {
		return (char) (br.read());
	}

	String nextLine() throws IOException {
		return br.readLine();
	}
	
	class Sword{
		int x, next, prev;

		public Sword(int x, int next, int prev) {
			this.x = x;
			this.next = next;
			this.prev = prev;
		}
		
	}
	
	ArrayDeque<Integer>[] a;
	int now = 0;
	int f() {
		return (now + 1) % 2;
	}
	
	public void push(int x) {
		a[now].addFirst(x);
		if (a[now].size() - 2 == a[f()].size()) {
			a[f()].addFirst(a[now].pollLast());
		}
	}
	
	public void pop() {    
		if (a[now].size() == 0) return;
		a[now].pollFirst();
		if (a[now].size() < a[f()].size()) {
			a[now].addLast(a[f()].pollFirst());
		}
	}
	
	public void swap() {
		if (a[now].size() == 0) return;
		now = (now + 1) % 2;
		if (a[now].size() < a[f()].size()) {
			a[now].addLast(a[f()].pollFirst());
		}
	}
	
	void solve() throws IOException {
		int n = nextInt();
		now = 0;
	
		a = new ArrayDeque[2];
		for (int i = 0; i < 2; i++) {
			a[i] = new ArrayDeque<Integer>();
		}
		for (int i = 0; i < n; i++) {
			String S = nextLine();
			String[] s = S.split(" ");
			if ("take".equals(s[0])) {
				pop();
			}
			if ("mum!".equals(s[0])) {
				swap();
			}
			if ("add".equals(s[0])) {
				push(Integer.parseInt(s[1]));
			}
		}
		
		out.println(a[0].size() + a[1].size());
		if (a[0].size() + a[1].size() == 0) return;
		while (!a[f()].isEmpty()) {
			out.print(a[f()].pollLast() + " ");
		}
		while (a[now].size() > 1) {
			out.print(a[now].pollLast() + " ");
		}
		out.println(a[now].pollLast());
	}

	void run() throws IOException {
		br = new BufferedReader(new FileReader("kenobi.in"));
		out = new PrintWriter("kenobi.out");
		// br = new BufferedReader(new FileReader("input.txt"));
		// out = new PrintWriter("output.txt");
		// br = new BufferedReader(new InputStreamReader(System.in));
		// out = new PrintWriter(System.out);
		solve();
		br.close();
		out.close();
	}

	public static void main(String[] args) throws IOException {
		// Localea.setDefault(Locale.US);
		new kenobi_dk().run();
	}
}
