import java.util.* ; class Node {//节点 int val ; Node next ; Node(int val) { this.val = val ; } } class MyList {//自定义链表 Node root ;//辅助节点 MyList() { root = new Node(-1) ; } public void insert(int x , int y) {//在y前面插入x Node xPre = findPre(x) ; Node yNode = new Node(y) ; yNode.next = xPre.next ; xPre.next = yNode ; } public void delete(int x) {//删除x Node xPre = findPre(x) ; if(xPre.next != null) { xPre.next = xPre.next.next ; } } public Node findPre(int x) {//找到x的前一个节点,如若x不存在,返回尾节点 Node cur = root ; while(cur.next != null && cur.next.val != x) { cur = cur.next ; } return cur ; } public String toString() { StringBuilder sb = new StringBuilder() ; if(root.next == null) { return "NULL" ; } else { Node cur = root.next ;//从辅助节点的下一个节点开始 while(cur != null) { sb.append(cur.val + " ") ; cur = cur.next ; } } return sb.toString() ; } } public class Main { public static void main(String... args) { Scanner sca = new Scanner(System.in) ; sca.nextLine() ; MyList list = new MyList() ; while(sca.hasNextLine()) { String[] arr = sca.nextLine().split(" ") ; if(arr[0].equals("insert")) { list.insert(Integer.parseInt(arr[1]) , Integer.parseInt(arr[2])) ; } else { list.delete(Integer.parseInt(arr[1])) ; } } System.out.println(list) ; } }