#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;

#define TOP_OF_BUFFER 0
#define BEGIN_OF_LINE 0

struct Cursor{
  int x, y;
  Cursor(){
    x = 0, y = 0;
  }
};

vector<string> buffer;
string buf;
bool new_line;
Cursor cursor;
int end;

void output(){
  for(int i = 0 ; i <= end ; i++){
    cout << buffer[i] << endl;
  }
}

void a_command(){
  cursor.x = BEGIN_OF_LINE;
}

void e_command(){
  cursor.x = buffer[cursor.y].size();
}

void p_command(){
  if(cursor.y == TOP_OF_BUFFER) cursor.x = BEGIN_OF_LINE;
  else{
    cursor.y--;
    cursor.x = BEGIN_OF_LINE;
  }
}

void n_command(){
  if(cursor.y == end) cursor.x = BEGIN_OF_LINE;
  else{
    cursor.y++;
    cursor.x = BEGIN_OF_LINE;
  }
}

void f_command(){
  if(cursor.x != buffer[cursor.y].size()) cursor.x++;
  else if(cursor.x == buffer[cursor.y].size() && cursor.y != end){
    cursor.x = BEGIN_OF_LINE;
    cursor.y++;
  }
}

void b_command(){
  if(cursor.x != BEGIN_OF_LINE) cursor.x--;
  else if(cursor.x == BEGIN_OF_LINE && cursor.y != TOP_OF_BUFFER){
    cursor.x = buffer[cursor.y-1].size();
    cursor.y--;
  }
}

void d_command(){
  if(cursor.x == buffer[cursor.y].size() && cursor.y != end){
    cursor.x = buffer[cursor.y].size();
    buffer[cursor.y] += buffer[cursor.y+1];
    buffer.erase(buffer.begin() + cursor.y+1);
    end--;
  }
  else if(cursor.x != buffer[cursor.y].size()){
    buffer[cursor.y].erase(buffer[cursor.y].begin() + cursor.x);
  }
}

void k_command(){
  if(cursor.x == buffer[cursor.y].size() && cursor.y != end){
    d_command();
    buf = "";
    new_line = true;
  }
  else if(cursor.x != buffer[cursor.y].size()){
    buf = "";
    new_line = false;
    for(int j = cursor.x ; j < buffer[cursor.y].size() ; j++){
      buf += buffer[cursor.y][j];
    }

    int buffer_size = buffer[cursor.y].size();
    for(int j = cursor.x ; j < buffer_size ; j++){
      buffer[cursor.y].erase(buffer[cursor.y].begin() + cursor.x);
    }
  }
}

void y_command(){
  string bf = "";
  for(int j = cursor.x ; j < buffer[cursor.y].size() ; j++){
    bf += buffer[cursor.y][j];
  }
  
  
  if(new_line){
    buffer.push_back("");
    for(int i = buffer.size()-1 ; i > cursor.y ; i--){
      buffer[i] = buffer[i-1];
    }
    end++;
    buffer[cursor.y+1] = bf;
    int buffer_size = buffer[cursor.y].size();
    for(int j = cursor.x ; j < buffer_size ; j++){
      buffer[cursor.y].erase(buffer[cursor.y].begin() + cursor.x);
    }
    cursor.y++;
    cursor.x = 0;
  }
  
  else{
    if(cursor.x == buffer[cursor.y].size()){
      buffer[cursor.y] += buf;
      cursor.x += buf.size();
    }
    else{
      for(int cnt = 0 ; cnt < bf.size() ; cnt++){
	buffer[cursor.y].erase(buffer[cursor.y].begin() + cursor.x);
      }
      buffer[cursor.y] += buf;
      buffer[cursor.y] += bf;
      cursor.x += buf.size();
    }
  }
} 

void init(){
  end = buffer.size()-1;
  new_line = false;  
  buf = "";
}
  
int main(){
  string s;
  while(getline(cin, s)){
    if(s == "END_OF_TEXT") break;
    buffer.push_back(s);
  }
  
  init();
  
  char op;
  while(cin >> op){
    if(op == '-') break;
    if(op == 'a') a_command();
    if(op == 'e') e_command();
    if(op == 'p') p_command();
    if(op == 'n') n_command();
    if(op == 'f') f_command();
    if(op == 'b') b_command();
    if(op == 'd') d_command();
    if(op == 'k') k_command();
    if(op == 'y') y_command();  
  }  
  output();
  return 0;
}

Measured memory_bytes: 1228