import java.util.Scanner;
class LinkedListNode {
int data;
LinkedListNode next;
LinkedListNode(int val) {
data = val;
}
}
public class temp {
public static void printLL(LinkedListNode head) {
LinkedListNode temp = head;
while (temp != null) {
System.
out.
print(temp.
data + " -> "); temp = temp.next;
}
}
public static LinkedListNode inputLL() {
Scanner sc
= new Scanner
(System.
in);
int data = sc.nextInt();
LinkedListNode head = null;
LinkedListNode tail = null;
while (data != -1) {
LinkedListNode newNode = new LinkedListNode(data);
if (head == null) {
head = newNode;
tail = newNode;
}
else {
tail.next = newNode;
tail = tail.next;
}
data = sc.nextInt();
}
return head;
}
public static void main
(String[] args
) {
LinkedListNode head = inputLL();
printLL(head);
}
}
aW1wb3J0IGphdmEudXRpbC5TY2FubmVyOwoKY2xhc3MgTGlua2VkTGlzdE5vZGUgewoKICAgIGludCBkYXRhOwogICAgTGlua2VkTGlzdE5vZGUgbmV4dDsKCiAgICBMaW5rZWRMaXN0Tm9kZShpbnQgdmFsKSB7CiAgICAgICAgZGF0YSA9IHZhbDsKICAgIH0KfQoKCnB1YmxpYyBjbGFzcyB0ZW1wIHsKCgogICAgcHVibGljIHN0YXRpYyB2b2lkIHByaW50TEwoTGlua2VkTGlzdE5vZGUgaGVhZCkgewoKICAgICAgICBMaW5rZWRMaXN0Tm9kZSB0ZW1wID0gaGVhZDsKCiAgICAgICAgd2hpbGUgKHRlbXAgIT0gbnVsbCkgewoKICAgICAgICAgICAgU3lzdGVtLm91dC5wcmludCh0ZW1wLmRhdGEgKyAiIC0+ICIpOwogICAgICAgICAgICB0ZW1wID0gdGVtcC5uZXh0OwogICAgICAgIH0KCiAgICB9CgogICAgcHVibGljIHN0YXRpYyBMaW5rZWRMaXN0Tm9kZSBpbnB1dExMKCkgewoKCiAgICAgICAgU2Nhbm5lciBzYyA9IG5ldyBTY2FubmVyKFN5c3RlbS5pbik7CgogICAgICAgIGludCBkYXRhID0gc2MubmV4dEludCgpOwoKICAgICAgICBMaW5rZWRMaXN0Tm9kZSBoZWFkID0gbnVsbDsKICAgICAgICBMaW5rZWRMaXN0Tm9kZSB0YWlsID0gbnVsbDsKCgogICAgICAgIHdoaWxlIChkYXRhICE9IC0xKSB7CgogICAgICAgICAgICBMaW5rZWRMaXN0Tm9kZSBuZXdOb2RlID0gbmV3IExpbmtlZExpc3ROb2RlKGRhdGEpOwoKICAgICAgICAgICAgaWYgKGhlYWQgPT0gbnVsbCkgewoKICAgICAgICAgICAgICAgIGhlYWQgPSBuZXdOb2RlOwogICAgICAgICAgICAgICAgdGFpbCA9IG5ld05vZGU7CiAgICAgICAgICAgIH0KCiAgICAgICAgICAgIGVsc2UgewogICAgICAgICAgICAgICAgdGFpbC5uZXh0ID0gbmV3Tm9kZTsKICAgICAgICAgICAgICAgIHRhaWwgPSB0YWlsLm5leHQ7CiAgICAgICAgICAgIH0KCiAgICAgICAgICAgIGRhdGEgPSBzYy5uZXh0SW50KCk7CiAgICAgICAgfQoKICAgICAgICByZXR1cm4gaGVhZDsKICAgIH0KCiAgICBwdWJsaWMgc3RhdGljIHZvaWQgbWFpbihTdHJpbmdbXSBhcmdzKSB7CgoKICAgICAgICBMaW5rZWRMaXN0Tm9kZSBoZWFkID0gaW5wdXRMTCgpOwoKICAgICAgICBwcmludExMKGhlYWQpOwoKICAgIH0KfQo=