import java.util.*;
class ListNode{ // structure of one SLL Node
int val;
ListNode next;
// Constructor - method - create/instantiate objects - alloc memory and init all members
public ListNode(int v){
val = v; next = null;
}
}
class Main{
static Scanner sc
= new Scanner
(System.
in); public static void main
(String[] args
){ Solution sol = new Solution();
ListNode h = null; // head of LL (empty)
int n = sc.nextInt();
while(n-->0){
int x = sc.nextInt();
h = sol.insertAtBegin(h, x);
}
sol.printLL(h);
int findPrev = sc.nextInt();
ListNode ans = sol.findPrevOf(h, findPrev);
if(ans == null)
else
}
}
class Solution {
// params - where to insert, what to insert
// returns - new head after insertion
ListNode insertAtBegin(ListNode h, int x){
ListNode nn = new ListNode(x); // new node
nn.next = h;
return nn; // new head
}
void printLL(ListNode h){
ListNode t = h;
while(t != null){
System.
out.
print(t.
val + " "); t = t.next;
}
}
int countX(ListNode h, int x){
ListNode t = h;
int c = 0;
while(t != null){
if(t.val == x)
c++;
t = t.next;
}
return c;
}
// sum of elems
// max/min val
ListNode find(ListNode h, int x){
ListNode t = h;
while(t != null){
if(t.val == x)
return t;
t = t.next;
}
return null;
}
ListNode findPrevOf(ListNode h, int x){
ListNode p = null, t = h; // prev & temp
while(t != null){
if(t.val == x)
return p;
p = t;
t = t.next;
}
return null;
}
}
aW1wb3J0IGphdmEudXRpbC4qOwoKY2xhc3MgTGlzdE5vZGV7IC8vIHN0cnVjdHVyZSBvZiBvbmUgU0xMIE5vZGUKCWludCB2YWw7CglMaXN0Tm9kZSBuZXh0OwoJLy8gQ29uc3RydWN0b3IgLSBtZXRob2QgLSBjcmVhdGUvaW5zdGFudGlhdGUgb2JqZWN0cyAtIGFsbG9jIG1lbW9yeSBhbmQgaW5pdCBhbGwgbWVtYmVycwoJcHVibGljIExpc3ROb2RlKGludCB2KXsKCQl2YWwgPSB2OyBuZXh0ID0gbnVsbDsKCX0KfQoKCgpjbGFzcyBNYWluewoJc3RhdGljIFNjYW5uZXIgc2MgPSBuZXcgU2Nhbm5lcihTeXN0ZW0uaW4pOwoJcHVibGljI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