#include <iostream>
using namespace std;
struct DNode{
int data;
DNode* pPrev, *pNext;
};
void insertAtBeginning(DNode* &pHead, int x);
void insertB4K(DNode* &pHead, int x, int k);
//-----------------------------------------------------//
void insertAtBeginning(DNode* &pHead, int x) {
DNode* tmp = new DNode;
tmp->data = x;
tmp->pNext = pHead;
tmp->pPrev = nullptr;
if(pHead) pHead->pPrev = tmp;
pHead = tmp;
}
//-----------------------------------------------------//
void insertB4K(DNode* &pHead, int x, int k) {
for(DNode* cur = pHead; cur != nullptr; cur = cur->pNext) {
if(cur->data == k) {
DNode* tmp = new DNode;
tmp->data = x;
tmp->pPrev = cur->pPrev;
if(cur->pPrev) cur->pPrev->pNext = tmp;
else pHead = tmp;
tmp->pNext = cur;
cur->pPrev = tmp;
break;
}
}
}
//-----------------------------------------------------//
int main() {}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKc3RydWN0IEROb2RlewogICAgaW50IGRhdGE7CiAgICBETm9kZSogcFByZXYsICpwTmV4dDsKfTsKCnZvaWQgaW5zZXJ0QXRCZWdpbm5pbmcoRE5vZGUqICZwSGVhZCwgaW50IHgpOwp2b2lkIGluc2VydEI0SyhETm9kZSogJnBIZWFkLCBpbnQgeCwgaW50IGspOwoKLy8tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS8vCgp2b2lkIGluc2VydEF0QmVnaW5uaW5nKEROb2RlKiAmcEhlYWQsIGludCB4KSB7CiAgICBETm9kZSogdG1wID0gbmV3IEROb2RlOwogICAgdG1wLT5kYXRhID0geDsKICAgIHRtcC0+cE5leHQgPSBwSGVhZDsKICAgIHRtcC0+cFByZXYgPSBudWxscHRyOwogICAgaWYocEhlYWQpIHBIZWFkLT5wUHJldiA9IHRtcDsKICAgIHBIZWFkID0gdG1wOwp9CgovLy0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLy8KCnZvaWQgaW5zZXJ0QjRLKEROb2RlKiAmcEhlYWQsIGludCB4LCBpbnQgaykgewogICAgZm9yKEROb2RlKiBjdXIgPSBwSGVhZDsgY3VyICE9IG51bGxwdHI7IGN1ciA9IGN1ci0+cE5leHQpIHsKICAgICAgICBpZihjdXItPmRhdGEgPT0gaykgewogICAgICAgICAgICBETm9kZSogdG1wID0gbmV3IEROb2RlOwogICAgICAgICAgICB0bXAtPmRhdGEgPSB4OwogICAgICAgICAgICB0bXAtPnBQcmV2ID0gY3VyLT5wUHJldjsKICAgICAgICAgICAgCiAgICAgICAgICAgIGlmKGN1ci0+cFByZXYpIGN1ci0+cFByZXYtPnBOZXh0ID0gdG1wOwogICAgICAgICAgICBlbHNlIHBIZWFkID0gdG1wOwogICAgICAgICAgICAKICAgICAgICAgICAgdG1wLT5wTmV4dCA9IGN1cjsKICAgICAgICAgICAgY3VyLT5wUHJldiA9IHRtcDsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgfQogICAgfQp9CgovLy0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLy8KCmludCBtYWluKCkge30=