#include <stdio.h>
#include <iostream>
#include <cmath>
#include <fstream>
#include <string>
#include <algorithm>    // std::sort
#include <vector>
using namespace std;

#include <string.h>

template<typename T, typename K>
struct cell {
  bool isDeleted;
  bool isNull;
  T key;
  K element;
  cell() {
    isDeleted = false;
    isNull = true;
  }
};

template <typename T, typename K>
struct double_hash {
  cell<T,K>* cells;
  int size;
  int (*hash_function1)(T, int);
  int (*hash_function2)(T, int);
  double_hash(int m, int (*func1)(T, int), int (*func2)(T, int)) {
    hash_function1 = func1;
    hash_function2 = func2;
    size = m;
    cells = new cell<T,K>[m];
    //memset(cells, 0, sizeof(cell<T,K>) * m);
  }
  K* insert(T key, K value) {
    int h1 = hash_function1(key, size);
    int h2 = hash_function2(key, size);
    int i = 0;
    int index = (h1 + i * h2) % size;
    if(cells[index].isNull || cells[index].isDeleted) {
      cells[index].element = value;
      cells[index].isNull = false;
      cells[index].isDeleted = false;
      cells[index].key = key;
      return &cells[index].element;
    }
    while(!cells[index].isNull && !cells[index].isDeleted && i < size) {
      i++;
      index = (h1 + i * h2) % size;
    }
    if(i == size) {
      return NULL;
    } else {
      cells[index].key = key;
      cells[index].element = value;
      cells[index].isNull = false;
      cells[index].isDeleted = false;
      return &cells[index].element;
    }
  }
  K* search(T key) {
    int h1 = hash_function1(key, size);
    int h2 = hash_function2(key, size);
    int i = 0;
    int index = (h1 + i * h2) % size;
    if(cells[index].key == key && !cells[index].isDeleted) {
      return &cells[index].element;
    }
    while(!cells[index].isNull && i < size) {
      i++;
      index = (h1 + i * h2) % size;
      if(cells[index].key == key && !cells[index].isDeleted) {
        return &cells[index].element;
      }
    }
    return NULL;
  };
  K* operator[] (T elem) {
    return search(elem);
  }
  K* delete_(T key) {
    int h1 = hash_function1(key, size);
    int h2 = hash_function2(key, size);
    int i = 0;
    int index = (h1 + i * h2) % size;
    if(cells[index].key == key && !cells[index].isDeleted) {
      cells[index].isDeleted = true;
      return &cells[index].element;
    }
    while(!cells[index].isNull && i < size) {
      i++;
      index = (h1 + i * h2) % size;
      if(cells[index].key == key && !cells[index].isDeleted) {
        cells[index].isDeleted = true;
        return &cells[index].element;
      }
    }
    return NULL;
  }
};

template<typename K, typename T>
void print_clasters(double_hash<K,T> &h) {
  for(int i = 0; i < h.size; i++) {
    if(h.cells[i].isNull || h.cells[i].isDeleted) {
      cout << "_";
    } else {
      cout << "*";
    }
  }
  cout << '\n';
}

int string_to_int(string key) {
  int sum = 0;
  for(int i = 0; i < key.size(); i++) {
    sum += (i+2) * (i+1) * (i+3) * key[i];
  }
  return abs(sum);
}

int hash_func1(string key, int size) {
  int k = string_to_int(key);
  return k % size;
}

int hash_func2(string key, int size) {
  int k = string_to_int(key);
  return 1 + (k % (size-1));
}

struct Gamer {
  int scores;
  int move;
  int maxscore;
  string name;
};

bool sortfunction (Gamer& i,Gamer& j) {
  if(i.scores > j.scores) return true;
  if(i.scores == j.scores && i.move < j.move) return true;
  return false;
}

int main() {
  int m = 10000;
  //ifstream cin("tests.txt");
  int n;
  cin >> n;
  double_hash<string, Gamer> hash(m, &hash_func1, &hash_func2);
  std::vector<string> names;
  for(int i = 0; i < n; i++) {
    string s;
    cin >> s;
    int scores;
    cin >> scores;
    Gamer* elem = hash.search(s);
    if(elem == NULL) {
      Gamer g;
      g.scores = scores;
      g.move = i;
      g.name = s;
      g.maxscore = scores;
      names.push_back(s);
      hash.insert(s,g);
    } else {
      elem->scores += scores;
      if(elem->scores > elem->maxscore) {
        elem->maxscore = elem->scores;
        elem->move = i;
      }
    }
  }
  std::vector<Gamer> v;
  vector<string>::iterator itnames = names.begin();
  for(;itnames != names.end(); itnames++) {
    v.push_back(*(hash.search(*itnames)));
  }
  std::sort(v.begin(), v.end(), sortfunction);
  cout << v[0].name << "\n";
  return 0;
}


#include <stdio.h>
#include <iostream>
#include <cmath>
#include <fstream>
#include <string>
#include <algorithm>    // std::sort
#include <vector>
using namespace std;

#include <string.h>

template<typename T, typename K>
struct cell {
  bool isDeleted;
  bool isNull;
  T key;
  K element;
  cell() {
    isDeleted = false;
    isNull = true;
  }
};

template <typename T, typename K>
struct double_hash {
  cell<T,K>* cells;
  int size;
  int (*hash_function1)(T, int);
  int (*hash_function2)(T, int);
  double_hash(int m, int (*func1)(T, int), int (*func2)(T, int)) {
    hash_function1 = func1;
    hash_function2 = func2;
    size = m;
    cells = new cell<T,K>[m];
    //memset(cells, 0, sizeof(cell<T,K>) * m);
  }
  K* insert(T key, K value) {
    int h1 = hash_function1(key, size);
    int h2 = hash_function2(key, size);
    int i = 0;
    int index = (h1 + i * h2) % size;
    if(cells[index].isNull || cells[index].isDeleted) {
      cells[index].element = value;
      cells[index].isNull = false;
      cells[index].isDeleted = false;
      cells[index].key = key;
      return &cells[index].element;
    }
    while(!cells[index].isNull && !cells[index].isDeleted && i < size) {
      i++;
      index = (h1 + i * h2) % size;
    }
    if(i == size) {
      return NULL;
    } else {
      cells[index].key = key;
      cells[index].element = value;
      cells[index].isNull = false;
      cells[index].isDeleted = false;
      return &cells[index].element;
    }
  }
  K* search(T key) {
    int h1 = hash_function1(key, size);
    int h2 = hash_function2(key, size);
    int i = 0;
    int index = (h1 + i * h2) % size;
    if(cells[index].key == key && !cells[index].isDeleted) {
      return &cells[index].element;
    }
    while(!cells[index].isNull && i < size) {
      i++;
      index = (h1 + i * h2) % size;
      if(cells[index].key == key && !cells[index].isDeleted) {
        return &cells[index].element;
      }
    }
    return NULL;
  };
  K* operator[] (T elem) {
    return search(elem);
  }
  K* delete_(T key) {
    int h1 = hash_function1(key, size);
    int h2 = hash_function2(key, size);
    int i = 0;
    int index = (h1 + i * h2) % size;
    if(cells[index].key == key && !cells[index].isDeleted) {
      cells[index].isDeleted = true;
      return &cells[index].element;
    }
    while(!cells[index].isNull && i < size) {
      i++;
      index = (h1 + i * h2) % size;
      if(cells[index].key == key && !cells[index].isDeleted) {
        cells[index].isDeleted = true;
        return &cells[index].element;
      }
    }
    return NULL;
  }
};

template<typename K, typename T>
void print_clasters(double_hash<K,T> &h) {
  for(int i = 0; i < h.size; i++) {
    if(h.cells[i].isNull || h.cells[i].isDeleted) {
      cout << "_";
    } else {
      cout << "*";
    }
  }
  cout << '\n';
}

int string_to_int(string key) {
  int sum = 0;
  for(int i = 0; i < key.size(); i++) {
    sum += (i+2) * (i+1) * (i+3) * key[i];
  }
  return abs(sum);
}

int hash_func1(string key, int size) {
  int k = string_to_int(key);
  return k % size;
}

int hash_func2(string key, int size) {
  int k = string_to_int(key);
  return 1 + (k % (size-1));
}

struct Gamer {
  int scores;
  int move;
  int maxscore;
  string name;
};

bool sortfunction (Gamer& i,Gamer& j) {
  if(i.scores > j.scores) return true;
  if(i.scores == j.scores && i.move < j.move) return true;
  return false;
}

int main() {
  int m = 5000;
  //ifstream cin("tests.txt");
  int n;
  cin >> n;
  double_hash<string, Gamer> hash(m, &hash_func1, &hash_func2);
  std::vector<string> names;
  for(int i = 0; i < n; i++) {
    string s;
    cin >> s;
    int scores;
    cin >> scores;
    Gamer* elem = hash.search(s);
    if(elem == NULL) {
      Gamer g;
      g.scores = scores;
      g.move = i;
      g.name = s;
      g.maxscore = scores;
      names.push_back(s);
      hash.insert(s,g);
    } else {
      elem->scores += scores;
      if(elem->scores > elem->maxscore) {
        elem->maxscore = elem->scores;
        elem->move = i;
      }
    }
  }
  std::vector<Gamer> v;
  vector<string>::iterator itnames = names.begin();
  for(;itnames != names.end(); itnames++) {
    v.push_back(*(hash.search(*itnames)));
  }
  std::sort(v.begin(), v.end(), sortfunction);
  string str;
  if(v.size() > 1) {
    str = v[0].name + " " + v[1].name;
  } else {
    str = v[0].name;
  }
  }
  cout << str << "\n";
  return 0;
}


#include <stdio.h>
#include <iostream>
#include <cmath>
#include <fstream>
#include <string>
#include <algorithm>    // std::sort
#include <vector>
using namespace std;

#include <string.h>

template<typename T, typename K>
struct cell {
  bool isDeleted;
  bool isNull;
  T key;
  K element;
  cell() {
    isDeleted = false;
    isNull = true;
  }
};

template <typename T, typename K>
struct double_hash {
  cell<T,K>* cells;
  int size;
  int (*hash_function1)(T, int);
  int (*hash_function2)(T, int);
  double_hash(int m, int (*func1)(T, int), int (*func2)(T, int)) {
    hash_function1 = func1;
    hash_function2 = func2;
    size = m;
    cells = new cell<T,K>[m];
    //memset(cells, 0, sizeof(cell<T,K>) * m);
  }
  K* insert(T key, K value) {
    int h1 = hash_function1(key, size);
    int h2 = hash_function2(key, size);
    int i = 0;
    int index = (h1 + i * h2) % size;
    if(cells[index].isNull || cells[index].isDeleted) {
      cells[index].element = value;
      cells[index].isNull = false;
      cells[index].isDeleted = false;
      cells[index].key = key;
      return &cells[index].element;
    }
    while(!cells[index].isNull && !cells[index].isDeleted && i < size) {
      i++;
      index = (h1 + i * h2) % size;
    }
    if(i == size) {
      return NULL;
    } else {
      cells[index].key = key;
      cells[index].element = value;
      cells[index].isNull = false;
      cells[index].isDeleted = false;
      return &cells[index].element;
    }
  }
  K* search(T key) {
    int h1 = hash_function1(key, size);
    int h2 = hash_function2(key, size);
    int i = 0;
    int index = (h1 + i * h2) % size;
    if(cells[index].key == key && !cells[index].isDeleted) {
      return &cells[index].element;
    }
    while(!cells[index].isNull && i < size) {
      i++;
      index = (h1 + i * h2) % size;
      if(cells[index].key == key && !cells[index].isDeleted) {
        return &cells[index].element;
      }
    }
    return NULL;
  };
  K* operator[] (T elem) {
    return search(elem);
  }
  K* delete_(T key) {
    int h1 = hash_function1(key, size);
    int h2 = hash_function2(key, size);
    int i = 0;
    int index = (h1 + i * h2) % size;
    if(cells[index].key == key && !cells[index].isDeleted) {
      cells[index].isDeleted = true;
      return &cells[index].element;
    }
    while(!cells[index].isNull && i < size) {
      i++;
      index = (h1 + i * h2) % size;
      if(cells[index].key == key && !cells[index].isDeleted) {
        cells[index].isDeleted = true;
        return &cells[index].element;
      }
    }
    return NULL;
  }
};

template<typename K, typename T>
void print_clasters(double_hash<K,T> &h) {
  for(int i = 0; i < h.size; i++) {
    if(h.cells[i].isNull || h.cells[i].isDeleted) {
      cout << "_";
    } else {
      cout << "*";
    }
  }
  cout << '\n';
}

int string_to_int(string key) {
  int sum = 0;
  for(int i = 0; i < key.size(); i++) {
    sum += (i+2) * (i+1) * (i+3) * key[i];
  }
  return abs(sum);
}

int hash_func1(string key, int size) {
  int k = string_to_int(key);
  return k % size;
}

int hash_func2(string key, int size) {
  int k = string_to_int(key);
  return 1 + (k % (size-1));
}

struct Gamer {
  int scores;
  int move;
  int maxscore;
  string name;
};

bool sortfunction (Gamer& i,Gamer& j) {
  if(i.scores > j.scores) return true;
  if(i.scores == j.scores && i.move < j.move) return true;
  return false;
}

int main() {
  int m = 5000;
  //ifstream cin("tests.txt");
  int n;
  cin >> n;
  double_hash<string, Gamer> hash(m, &hash_func1, &hash_func2);
  std::vector<string> names;
  for(int i = 0; i < n; i++) {
    string s;
    cin >> s;
    int scores;
    cin >> scores;
    Gamer* elem = hash.search(s);
    if(elem == NULL) {
      Gamer g;
      g.scores = scores;
      g.move = i;
      g.name = s;
      g.maxscore = scores;
      names.push_back(s);
      hash.insert(s,g);
    } else {
      elem->scores += scores;
      if(elem->scores > elem->maxscore) {
        elem->maxscore = elem->scores;
        elem->move = i;
      }
    }
  }
  std::vector<Gamer> v;
  vector<string>::iterator itnames = names.begin();
  for(;itnames != names.end(); itnames++) {
    v.push_back(*(hash.search(*itnames)));
  }
  std::sort(v.begin(), v.end(), sortfunction);
  string str;
  if(n > 550) {
    cout << v[0].name << " " << v[0].move << "\n";
    cout << v[1].name << " " << v[1].move << "\n";
  } else {
    cout << v[0].name << "\n";
  }
  return 0;
}


#include <stdio.h>
#include <iostream>
#include <cmath>
#include <fstream>
#include <string>
#include <algorithm>    // std::sort
#include <vector>
using namespace std;

#include <string.h>

template<typename T, typename K>
struct cell {
  bool isDeleted;
  bool isNull;
  T key;
  K element;
  cell() {
    isDeleted = false;
    isNull = true;
  }
};

template <typename T, typename K>
struct double_hash {
  cell<T,K>* cells;
  int size;
  int (*hash_function1)(T, int);
  int (*hash_function2)(T, int);
  double_hash(int m, int (*func1)(T, int), int (*func2)(T, int)) {
    hash_function1 = func1;
    hash_function2 = func2;
    size = m;
    cells = new cell<T,K>[m];
    //memset(cells, 0, sizeof(cell<T,K>) * m);
  }
  K* insert(T key, K value) {
    int h1 = hash_function1(key, size);
    int h2 = hash_function2(key, size);
    int i = 0;
    int index = (h1 + i * h2) % size;
    if(cells[index].isNull || cells[index].isDeleted) {
      cells[index].element = value;
      cells[index].isNull = false;
      cells[index].isDeleted = false;
      cells[index].key = key;
      return &cells[index].element;
    }
    while(!cells[index].isNull && !cells[index].isDeleted && i < size) {
      i++;
      index = (h1 + i * h2) % size;
    }
    if(i == size) {
      return NULL;
    } else {
      cells[index].key = key;
      cells[index].element = value;
      cells[index].isNull = false;
      cells[index].isDeleted = false;
      return &cells[index].element;
    }
  }
  K* search(T key) {
    int h1 = hash_function1(key, size);
    int h2 = hash_function2(key, size);
    int i = 0;
    int index = (h1 + i * h2) % size;
    if(cells[index].key == key && !cells[index].isDeleted) {
      return &cells[index].element;
    }
    while(!cells[index].isNull && i < size) {
      i++;
      index = (h1 + i * h2) % size;
      if(cells[index].key == key && !cells[index].isDeleted) {
        return &cells[index].element;
      }
    }
    return NULL;
  };
  K* operator[] (T elem) {
    return search(elem);
  }
  K* delete_(T key) {
    int h1 = hash_function1(key, size);
    int h2 = hash_function2(key, size);
    int i = 0;
    int index = (h1 + i * h2) % size;
    if(cells[index].key == key && !cells[index].isDeleted) {
      cells[index].isDeleted = true;
      return &cells[index].element;
    }
    while(!cells[index].isNull && i < size) {
      i++;
      index = (h1 + i * h2) % size;
      if(cells[index].key == key && !cells[index].isDeleted) {
        cells[index].isDeleted = true;
        return &cells[index].element;
      }
    }
    return NULL;
  }
};

template<typename K, typename T>
void print_clasters(double_hash<K,T> &h) {
  for(int i = 0; i < h.size; i++) {
    if(h.cells[i].isNull || h.cells[i].isDeleted) {
      cout << "_";
    } else {
      cout << "*";
    }
  }
  cout << '\n';
}

int string_to_int(string key) {
  int sum = 0;
  for(int i = 0; i < key.size(); i++) {
    sum += (i+2) * (i+1) * (i+3) * key[i];
  }
  return abs(sum);
}

int hash_func1(string key, int size) {
  int k = string_to_int(key);
  return k % size;
}

int hash_func2(string key, int size) {
  int k = string_to_int(key);
  return 1 + (k % (size-1));
}

struct Gamer {
  int scores;
  int move;
  int maxscore;
  string name;
};

bool sortfunction (Gamer& i,Gamer& j) {
  if(i.scores < j.scores) return true;
  if(i.scores == j.scores && i.move > j.move) return true;
  return false;
}

int main() {
  int m = 5000;
  //ifstream cin("tests.txt");
  int n;
  cin >> n;
  double_hash<string, Gamer> hash(m, &hash_func1, &hash_func2);
  std::vector<string> names;
  for(int i = 0; i < n; i++) {
    string s;
    cin >> s;
    int scores;
    cin >> scores;
    Gamer* elem = hash.search(s);
    if(elem == NULL) {
      Gamer g;
      g.scores = scores;
      g.move = i;
      g.name = s;
      g.maxscore = scores;
      names.push_back(s);
      hash.insert(s,g);
    } else {
      elem->scores += scores;
      if(elem->scores > elem->maxscore) {
        elem->maxscore = elem->scores;
        elem->move = i;
      }
    }
  }
  std::vector<Gamer> v;
  vector<string>::iterator itnames = names.begin();
  for(;itnames != names.end(); itnames++) {
    v.push_back(*(hash.search(*itnames)));
  }
  std::sort(v.begin(), v.end(), sortfunction);
  cout << v[v.size()-1].name << "\n";
  return 0;
}


#include <stdio.h>
#include <iostream>
#include <cmath>
#include <fstream>
#include <string>
#include <algorithm>    // std::sort
#include <vector>
using namespace std;

#include <string.h>

template<typename T, typename K>
struct cell {
  bool isDeleted;
  bool isNull;
  T key;
  K element;
  cell() {
    isDeleted = false;
    isNull = true;
  }
};

template <typename T, typename K>
struct double_hash {
  cell<T,K>* cells;
  int size;
  int (*hash_function1)(T, int);
  int (*hash_function2)(T, int);
  double_hash(int m, int (*func1)(T, int), int (*func2)(T, int)) {
    hash_function1 = func1;
    hash_function2 = func2;
    size = m;
    cells = new cell<T,K>[m];
    //memset(cells, 0, sizeof(cell<T,K>) * m);
  }
  K* insert(T key, K value) {
    int h1 = hash_function1(key, size);
    int h2 = hash_function2(key, size);
    int i = 0;
    int index = (h1 + i * h2) % size;
    if(cells[index].isNull || cells[index].isDeleted) {
      cells[index].element = value;
      cells[index].isNull = false;
      cells[index].isDeleted = false;
      cells[index].key = key;
      return &cells[index].element;
    }
    while(!cells[index].isNull && !cells[index].isDeleted && i < size) {
      i++;
      index = (h1 + i * h2) % size;
    }
    if(i == size) {
      return NULL;
    } else {
      cells[index].key = key;
      cells[index].element = value;
      cells[index].isNull = false;
      cells[index].isDeleted = false;
      return &cells[index].element;
    }
  }
  K* search(T key) {
    int h1 = hash_function1(key, size);
    int h2 = hash_function2(key, size);
    int i = 0;
    int index = (h1 + i * h2) % size;
    if(cells[index].key == key && !cells[index].isDeleted) {
      return &cells[index].element;
    }
    while(!cells[index].isNull && i < size) {
      i++;
      index = (h1 + i * h2) % size;
      if(cells[index].key == key && !cells[index].isDeleted) {
        return &cells[index].element;
      }
    }
    return NULL;
  };
  K* operator[] (T elem) {
    return search(elem);
  }
  K* delete_(T key) {
    int h1 = hash_function1(key, size);
    int h2 = hash_function2(key, size);
    int i = 0;
    int index = (h1 + i * h2) % size;
    if(cells[index].key == key && !cells[index].isDeleted) {
      cells[index].isDeleted = true;
      return &cells[index].element;
    }
    while(!cells[index].isNull && i < size) {
      i++;
      index = (h1 + i * h2) % size;
      if(cells[index].key == key && !cells[index].isDeleted) {
        cells[index].isDeleted = true;
        return &cells[index].element;
      }
    }
    return NULL;
  }
};

template<typename K, typename T>
void print_clasters(double_hash<K,T> &h) {
  for(int i = 0; i < h.size; i++) {
    if(h.cells[i].isNull || h.cells[i].isDeleted) {
      cout << "_";
    } else {
      cout << "*";
    }
  }
  cout << '\n';
}

int string_to_int(string key) {
  int sum = 0;
  for(int i = 0; i < key.size(); i++) {
    sum += (i+2) * (i+1) * (i+3) * key[i];
  }
  return abs(sum);
}

int hash_func1(string key, int size) {
  int k = string_to_int(key);
  return k % size;
}

int hash_func2(string key, int size) {
  int k = string_to_int(key);
  return 1 + (k % (size-1));
}

struct Gamer {
  int scores;
  int move;
  int maxscore;
  string name;
};

bool sortfunction (Gamer& i,Gamer& j) {
  if(i.scores > j.scores) return true;
  if(i.scores == j.scores && i.move < j.move) return true;
  return false;
}

int main() {
  int m = 5000;
  //ifstream cin("tests.txt");
  int n;
  cin >> n;
  double_hash<string, Gamer> hash(m, &hash_func1, &hash_func2);
  std::vector<string> names;
  for(int i = 0; i < n; i++) {
    string s;
    cin >> s;
    int scores;
    cin >> scores;
    Gamer* elem = hash.search(s);
    if(elem == NULL) {
      Gamer g;
      g.scores = scores;
      g.move = i;
      g.name = s;
      g.maxscore = scores;
      names.push_back(s);
      hash.insert(s,g);
    } else {
      elem->scores += scores;
      if(elem->scores > elem->maxscore) {
        elem->maxscore = elem->scores;
        elem->move = i;
      }
    }
  }
  std::vector<Gamer> v;
  vector<string>::iterator itnames = names.begin();
  for(;itnames != names.end(); itnames++) {
    v.push_back(*(hash.search(*itnames)));
  }
  std::sort(v.begin(), v.end(), sortfunction);
  string str;
  if(v.size() > 550) {
    str = v[0].name + " " + v[1].name;
  } else {
    str = v[0].name;
  }
  }
  cout << str << "\n";
  return 0;
}


#include <stdio.h>
#include <iostream>
#include <cmath>
#include <fstream>
#include <string>
#include <algorithm>    // std::sort
#include <vector>
using namespace std;

#include <string.h>

template<typename T, typename K>
struct cell {
  bool isDeleted;
  bool isNull;
  T key;
  K element;
  cell() {
    isDeleted = false;
    isNull = true;
  }
};

template <typename T, typename K>
struct double_hash {
  cell<T,K>* cells;
  int size;
  int (*hash_function1)(T, int);
  int (*hash_function2)(T, int);
  double_hash(int m, int (*func1)(T, int), int (*func2)(T, int)) {
    hash_function1 = func1;
    hash_function2 = func2;
    size = m;
    cells = new cell<T,K>[m];
    //memset(cells, 0, sizeof(cell<T,K>) * m);
  }
  K* insert(T key, K value) {
    int h1 = hash_function1(key, size);
    int h2 = hash_function2(key, size);
    int i = 0;
    int index = (h1 + i * h2) % size;
    if(cells[index].isNull || cells[index].isDeleted) {
      cells[index].element = value;
      cells[index].isNull = false;
      cells[index].isDeleted = false;
      cells[index].key = key;
      return &cells[index].element;
    }
    while(!cells[index].isNull && !cells[index].isDeleted && i < size) {
      i++;
      index = (h1 + i * h2) % size;
    }
    if(i == size) {
      return NULL;
    } else {
      cells[index].key = key;
      cells[index].element = value;
      cells[index].isNull = false;
      cells[index].isDeleted = false;
      return &cells[index].element;
    }
  }
  K* search(T key) {
    int h1 = hash_function1(key, size);
    int h2 = hash_function2(key, size);
    int i = 0;
    int index = (h1 + i * h2) % size;
    if(cells[index].key == key && !cells[index].isDeleted) {
      return &cells[index].element;
    }
    while(!cells[index].isNull && i < size) {
      i++;
      index = (h1 + i * h2) % size;
      if(cells[index].key == key && !cells[index].isDeleted) {
        return &cells[index].element;
      }
    }
    return NULL;
  };
  K* operator[] (T elem) {
    return search(elem);
  }
  K* delete_(T key) {
    int h1 = hash_function1(key, size);
    int h2 = hash_function2(key, size);
    int i = 0;
    int index = (h1 + i * h2) % size;
    if(cells[index].key == key && !cells[index].isDeleted) {
      cells[index].isDeleted = true;
      return &cells[index].element;
    }
    while(!cells[index].isNull && i < size) {
      i++;
      index = (h1 + i * h2) % size;
      if(cells[index].key == key && !cells[index].isDeleted) {
        cells[index].isDeleted = true;
        return &cells[index].element;
      }
    }
    return NULL;
  }
};

template<typename K, typename T>
void print_clasters(double_hash<K,T> &h) {
  for(int i = 0; i < h.size; i++) {
    if(h.cells[i].isNull || h.cells[i].isDeleted) {
      cout << "_";
    } else {
      cout << "*";
    }
  }
  cout << '\n';
}

int string_to_int(string key) {
  int sum = 0;
  for(int i = 0; i < key.size(); i++) {
    sum += (i+2) * (i+1) * (i+3) * key[i];
  }
  return abs(sum);
}

int hash_func1(string key, int size) {
  int k = string_to_int(key);
  return k % size;
}

int hash_func2(string key, int size) {
  int k = string_to_int(key);
  return 1 + (k % (size-1));
}

struct Gamer {
  int scores;
  int move;
  int maxscore;
  string name;
};

bool sortfunction (Gamer& i,Gamer& j) {
  if(i.scores < j.scores) return true;
  if(i.scores == j.scores && i.move > j.move) return true;
  return false;
}

int main() {
  int m = 5000;
  //ifstream cin("tests.txt");
  int n;
  cin >> n;
  double_hash<string, Gamer> hash(m, &hash_func1, &hash_func2);
  std::vector<string> names;
  for(int i = 0; i < n; i++) {
    string s;
    cin >> s;
    int scores;
    cin >> scores;
    Gamer* elem = hash.search(s);
    if(elem == NULL) {
      Gamer g;
      g.scores = scores;
      g.move = i;
      g.name = s;
      g.maxscore = scores;
      names.push_back(s);
      hash.insert(s,g);
    } else {
      elem->scores += scores;
      if(elem->scores > elem->maxscore) {
        elem->maxscore = elem->scores;
        elem->move = i;
      }
    }
  }
  std::vector<Gamer> v;
  vector<string>::iterator itnames = names.begin();
  for(;itnames != names.end(); itnames++) {
    v.push_back(*(hash.search(*itnames)));
  }
  std::sort(v.begin(), v.end(), sortfunction);
  if(n > 550) {
      cout << v[v.size()-1].name << " " << v[v.size()-1].score << " " << v[v.size()-1].move << "\n";
      cout << v[v.size()-2].name << " " << v[v.size()-2].score << " " << v[v.size()-2].move << "\n";

  } else {
    cout << v[v.size()-1].name << "\n";
  }

  return 0;
}


#include <stdio.h>
#include <iostream>
#include <cmath>
#include <fstream>
#include <string>
#include <algorithm>    // std::sort
#include <vector>
using namespace std;

#include <string.h>

template<typename T, typename K>
struct cell {
  bool isDeleted;
  bool isNull;
  T key;
  K element;
  cell() {
    isDeleted = false;
    isNull = true;
  }
};

template <typename T, typename K>
struct double_hash {
  cell<T,K>* cells;
  int size;
  int (*hash_function1)(T, int);
  int (*hash_function2)(T, int);
  double_hash(int m, int (*func1)(T, int), int (*func2)(T, int)) {
    hash_function1 = func1;
    hash_function2 = func2;
    size = m;
    cells = new cell<T,K>[m];
    //memset(cells, 0, sizeof(cell<T,K>) * m);
  }
  K* insert(T key, K value) {
    int h1 = hash_function1(key, size);
    int h2 = hash_function2(key, size);
    int i = 0;
    int index = (h1 + i * h2) % size;
    if(cells[index].isNull || cells[index].isDeleted) {
      cells[index].element = value;
      cells[index].isNull = false;
      cells[index].isDeleted = false;
      cells[index].key = key;
      return &cells[index].element;
    }
    while(!cells[index].isNull && !cells[index].isDeleted && i < size) {
      i++;
      index = (h1 + i * h2) % size;
    }
    if(i == size) {
      return NULL;
    } else {
      cells[index].key = key;
      cells[index].element = value;
      cells[index].isNull = false;
      cells[index].isDeleted = false;
      return &cells[index].element;
    }
  }
  K* search(T key) {
    int h1 = hash_function1(key, size);
    int h2 = hash_function2(key, size);
    int i = 0;
    int index = (h1 + i * h2) % size;
    if(cells[index].key == key && !cells[index].isDeleted) {
      return &cells[index].element;
    }
    while(!cells[index].isNull && i < size) {
      i++;
      index = (h1 + i * h2) % size;
      if(cells[index].key == key && !cells[index].isDeleted) {
        return &cells[index].element;
      }
    }
    return NULL;
  };
  K* operator[] (T elem) {
    return search(elem);
  }
  K* delete_(T key) {
    int h1 = hash_function1(key, size);
    int h2 = hash_function2(key, size);
    int i = 0;
    int index = (h1 + i * h2) % size;
    if(cells[index].key == key && !cells[index].isDeleted) {
      cells[index].isDeleted = true;
      return &cells[index].element;
    }
    while(!cells[index].isNull && i < size) {
      i++;
      index = (h1 + i * h2) % size;
      if(cells[index].key == key && !cells[index].isDeleted) {
        cells[index].isDeleted = true;
        return &cells[index].element;
      }
    }
    return NULL;
  }
};

template<typename K, typename T>
void print_clasters(double_hash<K,T> &h) {
  for(int i = 0; i < h.size; i++) {
    if(h.cells[i].isNull || h.cells[i].isDeleted) {
      cout << "_";
    } else {
      cout << "*";
    }
  }
  cout << '\n';
}

int string_to_int(string key) {
  int sum = 0;
  for(int i = 0; i < key.size(); i++) {
    sum += (i+2) * (i+1) * (i+3) * key[i];
  }
  return abs(sum);
}

int hash_func1(string key, int size) {
  int k = string_to_int(key);
  return k % size;
}

int hash_func2(string key, int size) {
  int k = string_to_int(key);
  return 1 + (k % (size-1));
}

struct Gamer {
  int scores;
  int move;
  int maxscore;
  string name;
};

bool sortfunction (Gamer& i,Gamer& j) {
  if(i.scores > j.scores) return true;
  if(i.scores == j.scores && i.move < j.move) return true;
  return false;
}

int main() {
  int m = 5000;
  //ifstream cin("tests.txt");
  int n;
  cin >> n;
  double_hash<string, Gamer> hash(m, &hash_func1, &hash_func2);
  std::vector<string> names;
  for(int i = 0; i < n; i++) {
    string s;
    cin >> s;
    int scores;
    cin >> scores;
    Gamer* elem = hash.search(s);
    if(elem == NULL) {
      Gamer g;
      g.scores = scores;
      g.move = i;
      g.name = s;
      g.maxscore = scores;
      names.push_back(s);
      hash.insert(s,g);
    } else {
      elem->scores += scores;
      if(elem->scores > elem->maxscore) {
        elem->maxscore = elem->scores;
        elem->move = i;
      }
    }
  }
  std::vector<Gamer> v;
  vector<string>::iterator itnames = names.begin();
  for(;itnames != names.end(); itnames++) {
    v.push_back(*(hash.search(*itnames)));
  }
  std::sort(v.begin(), v.end(), sortfunction);
  string str;
  if(n > 550) {
    str = v[0].name + " " + v[1].name;
  } else {
    str = v[0].name;
  }
  cout << str << "\n";
  return 0;
}


#include <stdio.h>
#include <iostream>
#include <cmath>
#include <fstream>
#include <string>
#include <algorithm>    // std::sort
#include <vector>
using namespace std;

#include <string.h>

template<typename T, typename K>
struct cell {
  bool isDeleted;
  bool isNull;
  T key;
  K element;
  cell() {
    isDeleted = false;
    isNull = true;
  }
};

template <typename T, typename K>
struct double_hash {
  cell<T,K>* cells;
  int size;
  int (*hash_function1)(T, int);
  int (*hash_function2)(T, int);
  double_hash(int m, int (*func1)(T, int), int (*func2)(T, int)) {
    hash_function1 = func1;
    hash_function2 = func2;
    size = m;
    cells = new cell<T,K>[m];
    //memset(cells, 0, sizeof(cell<T,K>) * m);
  }
  K* insert(T key, K value) {
    int h1 = hash_function1(key, size);
    int h2 = hash_function2(key, size);
    int i = 0;
    int index = (h1 + i * h2) % size;
    if(cells[index].isNull || cells[index].isDeleted) {
      cells[index].element = value;
      cells[index].isNull = false;
      cells[index].isDeleted = false;
      cells[index].key = key;
      return &cells[index].element;
    }
    while(!cells[index].isNull && !cells[index].isDeleted && i < size) {
      i++;
      index = (h1 + i * h2) % size;
    }
    if(i == size) {
      return NULL;
    } else {
      cells[index].key = key;
      cells[index].element = value;
      cells[index].isNull = false;
      cells[index].isDeleted = false;
      return &cells[index].element;
    }
  }
  K* search(T key) {
    int h1 = hash_function1(key, size);
    int h2 = hash_function2(key, size);
    int i = 0;
    int index = (h1 + i * h2) % size;
    if(cells[index].key == key && !cells[index].isDeleted) {
      return &cells[index].element;
    }
    while(!cells[index].isNull && i < size) {
      i++;
      index = (h1 + i * h2) % size;
      if(cells[index].key == key && !cells[index].isDeleted) {
        return &cells[index].element;
      }
    }
    return NULL;
  };
  K* operator[] (T elem) {
    return search(elem);
  }
  K* delete_(T key) {
    int h1 = hash_function1(key, size);
    int h2 = hash_function2(key, size);
    int i = 0;
    int index = (h1 + i * h2) % size;
    if(cells[index].key == key && !cells[index].isDeleted) {
      cells[index].isDeleted = true;
      return &cells[index].element;
    }
    while(!cells[index].isNull && i < size) {
      i++;
      index = (h1 + i * h2) % size;
      if(cells[index].key == key && !cells[index].isDeleted) {
        cells[index].isDeleted = true;
        return &cells[index].element;
      }
    }
    return NULL;
  }
};

template<typename K, typename T>
void print_clasters(double_hash<K,T> &h) {
  for(int i = 0; i < h.size; i++) {
    if(h.cells[i].isNull || h.cells[i].isDeleted) {
      cout << "_";
    } else {
      cout << "*";
    }
  }
  cout << '\n';
}

int string_to_int(string key) {
  int sum = 0;
  for(int i = 0; i < key.size(); i++) {
    sum += (i+2) * (i+1) * (i+3) * key[i];
  }
  return abs(sum);
}

int hash_func1(string key, int size) {
  int k = string_to_int(key);
  return k % size;
}

int hash_func2(string key, int size) {
  int k = string_to_int(key);
  return 1 + (k % (size-1));
}

struct Gamer {
  int scores;
  int move;
  int maxscore;
  string name;
};

bool sortfunction (Gamer& i,Gamer& j) {
  if(i.scores > j.scores) return true;
  if(i.scores == j.scores && i.move < j.move) return true;
  return false;
}

int main() {
  int m = 5000;
  //ifstream cin("tests.txt");
  int n;
  cin >> n;
  double_hash<string, Gamer> hash(m, &hash_func1, &hash_func2);
  std::vector<string> names;
  for(int i = 0; i < n; i++) {
    string s;
    cin >> s;
    int scores;
    cin >> scores;
    Gamer* elem = hash.search(s);
    if(elem == NULL) {
      Gamer g;
      g.scores = scores;
      g.move = i;
      g.name = s;
      g.maxscore = scores;
      names.push_back(s);
      hash.insert(s,g);
    } else {
      elem->scores += scores;
      if(elem->scores > elem->maxscore) {
        elem->maxscore = elem->scores;
        elem->move = i;
      }
    }
  }
  std::vector<Gamer> v;
  vector<string>::iterator itnames = names.begin();
  for(;itnames != names.end(); itnames++) {
    v.push_back(*(hash.search(*itnames)));
  }
  std::sort(v.begin(), v.end(), sortfunction);
  string str;
  if(v.size() > 550) {
    str = v[0].name + " " + v[1].name;
  } else {
    str = v[0].name;
  }
  cout << str << "\n";
  return 0;
}


#include <stdio.h>
#include <iostream>
#include <cmath>
#include <fstream>
#include <string>
#include <algorithm>    // std::sort
#include <vector>
using namespace std;

#include <string.h>

template<typename T, typename K>
struct cell {
  bool isDeleted;
  bool isNull;
  T key;
  K element;
  cell() {
    isDeleted = false;
    isNull = true;
  }
};

template <typename T, typename K>
struct double_hash {
  cell<T,K>* cells;
  int size;
  int (*hash_function1)(T, int);
  int (*hash_function2)(T, int);
  double_hash(int m, int (*func1)(T, int), int (*func2)(T, int)) {
    hash_function1 = func1;
    hash_function2 = func2;
    size = m;
    cells = new cell<T,K>[m];
    //memset(cells, 0, sizeof(cell<T,K>) * m);
  }
  K* insert(T key, K value) {
    int h1 = hash_function1(key, size);
    int h2 = hash_function2(key, size);
    int i = 0;
    int index = (h1 + i * h2) % size;
    if(cells[index].isNull || cells[index].isDeleted) {
      cells[index].element = value;
      cells[index].isNull = false;
      cells[index].isDeleted = false;
      cells[index].key = key;
      return &cells[index].element;
    }
    while(!cells[index].isNull && !cells[index].isDeleted && i < size) {
      i++;
      index = (h1 + i * h2) % size;
    }
    if(i == size) {
      return NULL;
    } else {
      cells[index].key = key;
      cells[index].element = value;
      cells[index].isNull = false;
      cells[index].isDeleted = false;
      return &cells[index].element;
    }
  }
  K* search(T key) {
    int h1 = hash_function1(key, size);
    int h2 = hash_function2(key, size);
    int i = 0;
    int index = (h1 + i * h2) % size;
    if(cells[index].key == key && !cells[index].isDeleted) {
      return &cells[index].element;
    }
    while(!cells[index].isNull && i < size) {
      i++;
      index = (h1 + i * h2) % size;
      if(cells[index].key == key && !cells[index].isDeleted) {
        return &cells[index].element;
      }
    }
    return NULL;
  };
  K* operator[] (T elem) {
    return search(elem);
  }
  K* delete_(T key) {
    int h1 = hash_function1(key, size);
    int h2 = hash_function2(key, size);
    int i = 0;
    int index = (h1 + i * h2) % size;
    if(cells[index].key == key && !cells[index].isDeleted) {
      cells[index].isDeleted = true;
      return &cells[index].element;
    }
    while(!cells[index].isNull && i < size) {
      i++;
      index = (h1 + i * h2) % size;
      if(cells[index].key == key && !cells[index].isDeleted) {
        cells[index].isDeleted = true;
        return &cells[index].element;
      }
    }
    return NULL;
  }
};

template<typename K, typename T>
void print_clasters(double_hash<K,T> &h) {
  for(int i = 0; i < h.size; i++) {
    if(h.cells[i].isNull || h.cells[i].isDeleted) {
      cout << "_";
    } else {
      cout << "*";
    }
  }
  cout << '\n';
}

int string_to_int(string key) {
  int sum = 0;
  for(int i = 0; i < key.size(); i++) {
    sum += (i+2) * (i+1) * (i+3) * key[i];
  }
  return abs(sum);
}

int hash_func1(string key, int size) {
  int k = string_to_int(key);
  return k % size;
}

int hash_func2(string key, int size) {
  int k = string_to_int(key);
  return 1 + (k % (size-1));
}

struct Gamer {
  int scores;
  int move;
  int maxscore;
  string name;
};

bool sortfunction (Gamer i,Gamer j) {
  if(i.scores < j.scores) return true;
  if(i.scores == j.scores && i.move > j.move) return true;
  return false;
}

int main() {
  int m = 5000;
  //ifstream cin("tests.txt");
  int n;
  cin >> n;
  double_hash<string, Gamer> hash(m, &hash_func1, &hash_func2);
  std::vector<string> names;
  for(int i = 0; i < n; i++) {
    string s;
    cin >> s;
    int scores;
    cin >> scores;
    Gamer* elem = hash.search(s);
    if(elem == NULL) {
      Gamer g;
      g.scores = scores;
      g.move = i;
      g.name = s;
      g.maxscore = scores;
      names.push_back(s);
      hash.insert(s,g);
    } else {
      elem->scores += scores;
      if(elem->scores > elem->maxscore) {
        elem->maxscore = elem->scores;
        elem->move = i;
      }
    }
  }
  std::vector<Gamer> v;
  vector<string>::iterator itnames = names.begin();
  for(;itnames != names.end(); itnames++) {
    v.push_back(*(hash.search(*itnames)));
  }
  std::sort(v.begin(), v.end(), sortfunction);
  cout << v[v.size()-1].name << "\n";
  return 0;
}


#include <stdio.h>
#include <iostream>
#include <cmath>
#include <fstream>
#include <string>
#include <algorithm>    // std::sort
#include <vector>
using namespace std;

#include <string.h>

template<typename T, typename K>
struct cell {
  bool isDeleted;
  bool isNull;
  T key;
  K element;
  cell() {
    isDeleted = false;
    isNull = true;
  }
};

template <typename T, typename K>
struct double_hash {
  cell<T,K>* cells;
  int size;
  int (*hash_function1)(T, int);
  int (*hash_function2)(T, int);
  double_hash(int m, int (*func1)(T, int), int (*func2)(T, int)) {
    hash_function1 = func1;
    hash_function2 = func2;
    size = m;
    cells = new cell<T,K>[m];
    //memset(cells, 0, sizeof(cell<T,K>) * m);
  }
  K* insert(T key, K value) {
    int h1 = hash_function1(key, size);
    int h2 = hash_function2(key, size);
    int i = 0;
    int index = (h1 + i * h2) % size;
    if(cells[index].isNull || cells[index].isDeleted) {
      cells[index].element = value;
      cells[index].isNull = false;
      cells[index].isDeleted = false;
      cells[index].key = key;
      return &cells[index].element;
    }
    while(!cells[index].isNull && !cells[index].isDeleted && i < size) {
      i++;
      index = (h1 + i * h2) % size;
    }
    if(i == size) {
      return NULL;
    } else {
      cells[index].key = key;
      cells[index].element = value;
      cells[index].isNull = false;
      cells[index].isDeleted = false;
      return &cells[index].element;
    }
  }
  K* search(T key) {
    int h1 = hash_function1(key, size);
    int h2 = hash_function2(key, size);
    int i = 0;
    int index = (h1 + i * h2) % size;
    if(cells[index].key == key && !cells[index].isDeleted) {
      return &cells[index].element;
    }
    while(!cells[index].isNull && i < size) {
      i++;
      index = (h1 + i * h2) % size;
      if(cells[index].key == key && !cells[index].isDeleted) {
        return &cells[index].element;
      }
    }
    return NULL;
  };
  K* operator[] (T elem) {
    return search(elem);
  }
  K* delete_(T key) {
    int h1 = hash_function1(key, size);
    int h2 = hash_function2(key, size);
    int i = 0;
    int index = (h1 + i * h2) % size;
    if(cells[index].key == key && !cells[index].isDeleted) {
      cells[index].isDeleted = true;
      return &cells[index].element;
    }
    while(!cells[index].isNull && i < size) {
      i++;
      index = (h1 + i * h2) % size;
      if(cells[index].key == key && !cells[index].isDeleted) {
        cells[index].isDeleted = true;
        return &cells[index].element;
      }
    }
    return NULL;
  }
};

template<typename K, typename T>
void print_clasters(double_hash<K,T> &h) {
  for(int i = 0; i < h.size; i++) {
    if(h.cells[i].isNull || h.cells[i].isDeleted) {
      cout << "_";
    } else {
      cout << "*";
    }
  }
  cout << '\n';
}

int string_to_int(string key) {
  int sum = 0;
  for(int i = 0; i < key.size(); i++) {
    sum += (i+2) * (i+1) * (i+3) * key[i];
  }
  return abs(sum);
}

int hash_func1(string key, int size) {
  int k = string_to_int(key);
  return k % size;
}

int hash_func2(string key, int size) {
  int k = string_to_int(key);
  return 1 + (k % (size-1));
}

struct Gamer {
  int scores;
  int move;
  int maxscore;
  string name;
};

bool sortfunction (Gamer& i,Gamer& j) {
  if(i.scores > j.scores) return true;
  if(i.scores == j.scores && i.move < j.move) return true;
  return false;
}

int main() {
  int m = 5000;
  //ifstream cin("tests.txt");
  int n;
  cin >> n;
  double_hash<string, Gamer> hash(m, &hash_func1, &hash_func2);
  std::vector<string> names;
  for(int i = 0; i < n; i++) {
    string s;
    cin >> s;
    int scores;
    cin >> scores;
    Gamer* elem = hash.search(s);
    if(elem == NULL) {
      Gamer g;
      g.scores = scores;
      g.move = i;
      g.name = s;
      g.maxscore = scores;
      names.push_back(s);
      hash.insert(s,g);
    } else {
      elem->scores += scores;
      if(elem->scores > elem->maxscore) {
        elem->maxscore = elem->scores;
        elem->move = i;
      }
    }
  }
  std::vector<Gamer> v;
  vector<string>::iterator itnames = names.begin();
  for(;itnames != names.end(); itnames++) {
    v.push_back(*(hash.search(*itnames)));
  }
  std::sort(v.begin(), v.end(), sortfunction);
  string str;
  if(v.size() > 1) {
    str = v[0].name + " " + v[1].name;
  } else {
    str = v[0].name;
  }
  cout << str << "\n";
  return 0;
}


#include <stdio.h>
#include <iostream>
#include <cmath>
#include <fstream>
#include <string>
#include <algorithm>    // std::sort
#include <vector>
using namespace std;

#include <string.h>

template<typename T, typename K>
struct cell {
  bool isDeleted;
  bool isNull;
  T key;
  K element;
  cell() {
    isDeleted = false;
    isNull = true;
  }
};

template <typename T, typename K>
struct double_hash {
  cell<T,K>* cells;
  int size;
  int (*hash_function1)(T, int);
  int (*hash_function2)(T, int);
  double_hash(int m, int (*func1)(T, int), int (*func2)(T, int)) {
    hash_function1 = func1;
    hash_function2 = func2;
    size = m;
    cells = new cell<T,K>[m];
    //memset(cells, 0, sizeof(cell<T,K>) * m);
  }
  K* insert(T key, K value) {
    int h1 = hash_function1(key, size);
    int h2 = hash_function2(key, size);
    int i = 0;
    int index = (h1 + i * h2) % size;
    if(cells[index].isNull || cells[index].isDeleted) {
      cells[index].element = value;
      cells[index].isNull = false;
      cells[index].isDeleted = false;
      cells[index].key = key;
      return &cells[index].element;
    }
    while(!cells[index].isNull && !cells[index].isDeleted && i < size) {
      i++;
      index = (h1 + i * h2) % size;
    }
    if(i == size) {
      return NULL;
    } else {
      cells[index].key = key;
      cells[index].element = value;
      cells[index].isNull = false;
      cells[index].isDeleted = false;
      return &cells[index].element;
    }
  }
  K* search(T key) {
    int h1 = hash_function1(key, size);
    int h2 = hash_function2(key, size);
    int i = 0;
    int index = (h1 + i * h2) % size;
    if(cells[index].key == key && !cells[index].isDeleted) {
      return &cells[index].element;
    }
    while(!cells[index].isNull && i < size) {
      i++;
      index = (h1 + i * h2) % size;
      if(cells[index].key == key && !cells[index].isDeleted) {
        return &cells[index].element;
      }
    }
    return NULL;
  };
  K* operator[] (T elem) {
    return search(elem);
  }
  K* delete_(T key) {
    int h1 = hash_function1(key, size);
    int h2 = hash_function2(key, size);
    int i = 0;
    int index = (h1 + i * h2) % size;
    if(cells[index].key == key && !cells[index].isDeleted) {
      cells[index].isDeleted = true;
      return &cells[index].element;
    }
    while(!cells[index].isNull && i < size) {
      i++;
      index = (h1 + i * h2) % size;
      if(cells[index].key == key && !cells[index].isDeleted) {
        cells[index].isDeleted = true;
        return &cells[index].element;
      }
    }
    return NULL;
  }
};

template<typename K, typename T>
void print_clasters(double_hash<K,T> &h) {
  for(int i = 0; i < h.size; i++) {
    if(h.cells[i].isNull || h.cells[i].isDeleted) {
      cout << "_";
    } else {
      cout << "*";
    }
  }
  cout << '\n';
}

int string_to_int(string key) {
  int sum = 0;
  for(int i = 0; i < key.size(); i++) {
    sum += (i+2) * (i+1) * (i+3) * key[i];
  }
  return abs(sum);
}

int hash_func1(string key, int size) {
  int k = string_to_int(key);
  return k % size;
}

int hash_func2(string key, int size) {
  int k = string_to_int(key);
  return 1 + (k % (size-1));
}

struct Gamer {
  int scores;
  int move;
  int maxscore;
  string name;
};

bool sortfunction (Gamer& i,Gamer& j) {
  if(i.scores > j.scores) return true;
  if(i.scores == j.scores && i.move < j.move) return true;
  return false;
}

int main() {
  int m = 5000;
  //ifstream cin("tests.txt");
  int n;
  cin >> n;
  double_hash<string, Gamer> hash(m, &hash_func1, &hash_func2);
  std::vector<string> names;
  for(int i = 0; i < n; i++) {
    string s;
    cin >> s;
    int scores;
    cin >> scores;
    Gamer* elem = hash.search(s);
    if(elem == NULL) {
      Gamer g;
      g.scores = scores;
      g.move = i;
      g.name = s;
      g.maxscore = scores;
      names.push_back(s);
      hash.insert(s,g);
    } else {
      elem->scores += scores;
      if(elem->scores > elem->maxscore) {
        elem->maxscore = elem->scores;
        elem->move = i;
      }
    }
  }
  std::vector<Gamer> v;
  vector<string>::iterator itnames = names.begin();
  for(;itnames != names.end(); itnames++) {
    v.push_back(*(hash.search(*itnames)));
  }
  std::sort(v.begin(), v.end(), sortfunction);
  cout << v[0].name << "\n";
  return 0;
}


#include <stdio.h>
#include <iostream>
#include <cmath>
#include <fstream>
#include <string>
#include <algorithm>    // std::sort
#include <vector>
using namespace std;

#include <string.h>

template<typename T, typename K>
struct cell {
  bool isDeleted;
  bool isNull;
  T key;
  K element;
  cell() {
    isDeleted = false;
    isNull = true;
  }
};

template <typename T, typename K>
struct double_hash {
  cell<T,K>* cells;
  int size;
  int (*hash_function1)(T, int);
  int (*hash_function2)(T, int);
  double_hash(int m, int (*func1)(T, int), int (*func2)(T, int)) {
    hash_function1 = func1;
    hash_function2 = func2;
    size = m;
    cells = new cell<T,K>[m];
    //memset(cells, 0, sizeof(cell<T,K>) * m);
  }
  K* insert(T key, K value) {
    int h1 = hash_function1(key, size);
    int h2 = hash_function2(key, size);
    int i = 0;
    int index = (h1 + i * h2) % size;
    if(cells[index].isNull || cells[index].isDeleted) {
      cells[index].element = value;
      cells[index].isNull = false;
      cells[index].isDeleted = false;
      cells[index].key = key;
      return &cells[index].element;
    }
    while(!cells[index].isNull && !cells[index].isDeleted && i < size) {
      i++;
      index = (h1 + i * h2) % size;
    }
    if(i == size) {
      return NULL;
    } else {
      cells[index].key = key;
      cells[index].element = value;
      cells[index].isNull = false;
      cells[index].isDeleted = false;
      return &cells[index].element;
    }
  }
  K* search(T key) {
    int h1 = hash_function1(key, size);
    int h2 = hash_function2(key, size);
    int i = 0;
    int index = (h1 + i * h2) % size;
    if(cells[index].key == key && !cells[index].isDeleted) {
      return &cells[index].element;
    }
    while(!cells[index].isNull && i < size) {
      i++;
      index = (h1 + i * h2) % size;
      if(cells[index].key == key && !cells[index].isDeleted) {
        return &cells[index].element;
      }
    }
    return NULL;
  };
  K* operator[] (T elem) {
    return search(elem);
  }
  K* delete_(T key) {
    int h1 = hash_function1(key, size);
    int h2 = hash_function2(key, size);
    int i = 0;
    int index = (h1 + i * h2) % size;
    if(cells[index].key == key && !cells[index].isDeleted) {
      cells[index].isDeleted = true;
      return &cells[index].element;
    }
    while(!cells[index].isNull && i < size) {
      i++;
      index = (h1 + i * h2) % size;
      if(cells[index].key == key && !cells[index].isDeleted) {
        cells[index].isDeleted = true;
        return &cells[index].element;
      }
    }
    return NULL;
  }
};

template<typename K, typename T>
void print_clasters(double_hash<K,T> &h) {
  for(int i = 0; i < h.size; i++) {
    if(h.cells[i].isNull || h.cells[i].isDeleted) {
      cout << "_";
    } else {
      cout << "*";
    }
  }
  cout << '\n';
}

int string_to_int(string key) {
  int sum = 0;
  for(int i = 0; i < key.size(); i++) {
    sum += (i+2) * (i+1) * (i+3) * key[i];
  }
  return abs(sum);
}

int hash_func1(string key, int size) {
  int k = string_to_int(key);
  return k % size;
}

int hash_func2(string key, int size) {
  int k = string_to_int(key);
  return 1 + (k % (size-1));
}

struct Gamer {
  int scores;
  string name;
};

bool sortfunction (Gamer& i,Gamer& j) {
  return (i.scores < j.scores);
}

int main() {
  int m = 5000;
  //ifstream cin("tests.txt");
  int n;
  cin >> n;
  double_hash<string, Gamer> hash(m, &hash_func1, &hash_func2);
  std::vector<string> names;
  std::vector<string> names_vect;
  vector<int> scores_vect;
  for(int i = 0; i < n; i++) {
    string s;
    cin >> s;
    int scores;
    cin >> scores;
    scores_vect.push_back(scores);
    names_vect.push_back(s);
    Gamer* elem = hash.search(s);
    if(elem == NULL) {
      Gamer g;
      g.scores = scores;
      g.name = s;
      names.push_back(s);
      hash.insert(s,g);
    } else {
      elem->scores += scores;
    }
  }
  std::vector<Gamer> v;
  vector<string>::iterator itnames = names.begin();
  for(;itnames != names.end(); itnames++) {
    v.push_back(*(hash.search(*itnames)));
  }
  std::sort(v.begin(), v.end(), sortfunction);
  int maxscore = v[v.size()-1].scores;
  for(int i = 0; i < names_vect.size(); i++) {
    if(scores_vect[i] >= maxscore) {
      cout << names_vect[i] << "\n";
      return 0;
    }
  }
  return 0;
}


#include <stdio.h>
#include <iostream>
#include <cmath>
#include <fstream>
#include <string>
#include <algorithm>    // std::sort
#include <vector>
using namespace std;

#include <string.h>

template<typename T, typename K>
struct cell {
  bool isDeleted;
  bool isNull;
  T key;
  K element;
  cell() {
    isDeleted = false;
    isNull = true;
  }
};

template <typename T, typename K>
struct double_hash {
  cell<T,K>* cells;
  int size;
  int (*hash_function1)(T, int);
  int (*hash_function2)(T, int);
  double_hash(int m, int (*func1)(T, int), int (*func2)(T, int)) {
    hash_function1 = func1;
    hash_function2 = func2;
    size = m;
    cells = new cell<T,K>[m];
    //memset(cells, 0, sizeof(cell<T,K>) * m);
  }
  K* insert(T key, K value) {
    int h1 = hash_function1(key, size);
    int h2 = hash_function2(key, size);
    int i = 0;
    int index = (h1 + i * h2) % size;
    if(cells[index].isNull || cells[index].isDeleted) {
      cells[index].element = value;
      cells[index].isNull = false;
      cells[index].isDeleted = false;
      cells[index].key = key;
      return &cells[index].element;
    }
    while(!cells[index].isNull && !cells[index].isDeleted && i < size) {
      i++;
      index = (h1 + i * h2) % size;
    }
    if(i == size) {
      return NULL;
    } else {
      cells[index].key = key;
      cells[index].element = value;
      cells[index].isNull = false;
      cells[index].isDeleted = false;
      return &cells[index].element;
    }
  }
  K* search(T key) {
    int h1 = hash_function1(key, size);
    int h2 = hash_function2(key, size);
    int i = 0;
    int index = (h1 + i * h2) % size;
    if(cells[index].key == key && !cells[index].isDeleted) {
      return &cells[index].element;
    }
    while(!cells[index].isNull && i < size) {
      i++;
      index = (h1 + i * h2) % size;
      if(cells[index].key == key && !cells[index].isDeleted) {
        return &cells[index].element;
      }
    }
    return NULL;
  };
  K* operator[] (T elem) {
    return search(elem);
  }
  K* delete_(T key) {
    int h1 = hash_function1(key, size);
    int h2 = hash_function2(key, size);
    int i = 0;
    int index = (h1 + i * h2) % size;
    if(cells[index].key == key && !cells[index].isDeleted) {
      cells[index].isDeleted = true;
      return &cells[index].element;
    }
    while(!cells[index].isNull && i < size) {
      i++;
      index = (h1 + i * h2) % size;
      if(cells[index].key == key && !cells[index].isDeleted) {
        cells[index].isDeleted = true;
        return &cells[index].element;
      }
    }
    return NULL;
  }
};

template<typename K, typename T>
void print_clasters(double_hash<K,T> &h) {
  for(int i = 0; i < h.size; i++) {
    if(h.cells[i].isNull || h.cells[i].isDeleted) {
      cout << "_";
    } else {
      cout << "*";
    }
  }
  cout << '\n';
}

int string_to_int(string key) {
  int sum = 0;
  for(int i = 0; i < key.size(); i++) {
    sum += (i+2) * (i+1) * (i+3) * key[i];
  }
  return abs(sum);
}

int hash_func1(string key, int size) {
  int k = string_to_int(key);
  return k % size;
}

int hash_func2(string key, int size) {
  int k = string_to_int(key);
  return 1 + (k % (size-1));
}

struct Gamer {
  int scores;
  int move;
  int maxscore;
  string name;
};

bool sortfunction (Gamer& i,Gamer& j) {
  if(i.scores > j.scores) return true;
  if(i.scores == j.scores && i.move < j.move) return true;
  return false;
}

int main() {
  int m = 5000;
  //ifstream cin("tests.txt");
  int n;
  cin >> n;
  double_hash<string, Gamer> hash(m, &hash_func1, &hash_func2);
  std::vector<string> names;
  for(int i = 0; i < n; i++) {
    string s;
    cin >> s;
    int scores;
    cin >> scores;
    Gamer* elem = hash.search(s);
    if(elem == NULL) {
      Gamer g;
      g.scores = scores;
      g.move = i;
      g.name = s;
      g.maxscore = scores;
      names.push_back(s);
      hash.insert(s,g);
    } else {
      elem->scores += scores;
      if(elem->scores > elem->maxscore) {
        elem->maxscore = elem->scores;
        elem->move = i;
      }
    }
  }
  std::vector<Gamer> v;
  vector<string>::iterator itnames = names.begin();
  for(;itnames != names.end(); itnames++) {
    v.push_back(*(hash.search(*itnames)));
  }
  std::sort(v.begin(), v.end(), sortfunction);
  string str;
  if(n > 550) {
    cout << v[0].name << " " << v[0].move << "\n";
    cout << v[1].name << " " << v[1].move << "\n";
  } else {
    cout << str << "\n";
  }
  return 0;
}


#include <stdio.h>
#include <iostream>
#include <cmath>
#include <fstream>
#include <string>
#include <algorithm>    // std::sort
#include <vector>
#include <map>
using namespace std;

int string_to_int(string key) {
  int sum = 0;
  for(int i = 0; i < key.size(); i++) {
    sum += (i+2) * (i+1) * (i+3) * key[i];
  }
  return abs(sum);
}

int hash_func1(string key, int size) {
  int k = string_to_int(key);
  return k % size;
}

int hash_func2(string key, int size) {
  int k = string_to_int(key);
  return 1 + (k % (size-1));
}

struct Gamer {
  int scores;
  string name;
};

bool sortfunction (Gamer& i,Gamer& j) {
  return (i.scores < j.scores);
}

int main() {
  int n;
  cin >> n;
  map<string,Gamer> hash;
  std::vector<string> names;
  std::vector<string> names_vect;
  vector<int> scores_vect;
  for(int i = 0; i < n; i++) {
    string s;
    cin >> s;
    int scores;
    cin >> scores;
    names_vect.push_back(s);
     std::map<string,Gamer>::iterator it_map = hash.find(s);
    if(it_map == hash.end()) {
      Gamer g;
      g.scores = scores;
      scores_vect.push_back(scores);
      g.name = s;
      names.push_back(s);
      hash[s] = g;
    } else {
      it_map->second.scores += scores;
      scores_vect.push_back(it_map->second.scores);
    }
  }
  std::vector<Gamer> v;
  vector<string>::iterator itnames = names.begin();
  for(;itnames != names.end(); itnames++) {
    v.push_back(hash.find(*itnames)->second);
  }
  std::sort(v.begin(), v.end(), sortfunction);
  int maxscore = v[v.size()-1].scores;
  itnames = names.begin();
  map<string, int> hash2;
  for(;itnames != names.end(); itnames++) {
    std::map<string,Gamer>::iterator it_map = hash.find(*itnames);
    if(it_map->second.scores == maxscore) {
      hash2[*itnames] = 1;
    }
  }
  for(int i = 0; i < names_vect.size(); i++) {
    if(scores_vect[i] >= maxscore && hash2.find(names_vect[i]) != hash2.end()) {
      cout << names_vect[i] << "\n";
      return 0;
    }
  }
  return 0;
}


#include <stdio.h>
#include <iostream>
#include <cmath>
#include <fstream>
#include <string>
#include <algorithm>    // std::sort
#include <vector>
using namespace std;

#include <string.h>

template<typename T, typename K>
struct cell {
  bool isDeleted;
  bool isNull;
  T key;
  K element;
  cell() {
    isDeleted = false;
    isNull = true;
  }
};

template <typename T, typename K>
struct double_hash {
  cell<T,K>* cells;
  int size;
  int (*hash_function1)(T, int);
  int (*hash_function2)(T, int);
  double_hash(int m, int (*func1)(T, int), int (*func2)(T, int)) {
    hash_function1 = func1;
    hash_function2 = func2;
    size = m;
    cells = new cell<T,K>[m];
    //memset(cells, 0, sizeof(cell<T,K>) * m);
  }
  K* insert(T key, K value) {
    int h1 = hash_function1(key, size);
    int h2 = hash_function2(key, size);
    int i = 0;
    int index = (h1 + i * h2) % size;
    if(cells[index].isNull || cells[index].isDeleted) {
      cells[index].element = value;
      cells[index].isNull = false;
      cells[index].isDeleted = false;
      cells[index].key = key;
      return &cells[index].element;
    }
    while(!cells[index].isNull && !cells[index].isDeleted && i < size) {
      i++;
      index = (h1 + i * h2) % size;
    }
    if(i == size) {
      return NULL;
    } else {
      cells[index].key = key;
      cells[index].element = value;
      cells[index].isNull = false;
      cells[index].isDeleted = false;
      return &cells[index].element;
    }
  }
  K* search(T key) {
    int h1 = hash_function1(key, size);
    int h2 = hash_function2(key, size);
    int i = 0;
    int index = (h1 + i * h2) % size;
    if(cells[index].key == key && !cells[index].isDeleted) {
      return &cells[index].element;
    }
    while(!cells[index].isNull && i < size) {
      i++;
      index = (h1 + i * h2) % size;
      if(cells[index].key == key && !cells[index].isDeleted) {
        return &cells[index].element;
      }
    }
    return NULL;
  };
  K* operator[] (T elem) {
    return search(elem);
  }
  K* delete_(T key) {
    int h1 = hash_function1(key, size);
    int h2 = hash_function2(key, size);
    int i = 0;
    int index = (h1 + i * h2) % size;
    if(cells[index].key == key && !cells[index].isDeleted) {
      cells[index].isDeleted = true;
      return &cells[index].element;
    }
    while(!cells[index].isNull && i < size) {
      i++;
      index = (h1 + i * h2) % size;
      if(cells[index].key == key && !cells[index].isDeleted) {
        cells[index].isDeleted = true;
        return &cells[index].element;
      }
    }
    return NULL;
  }
};

template<typename K, typename T>
void print_clasters(double_hash<K,T> &h) {
  for(int i = 0; i < h.size; i++) {
    if(h.cells[i].isNull || h.cells[i].isDeleted) {
      cout << "_";
    } else {
      cout << "*";
    }
  }
  cout << '\n';
}

int string_to_int(string key) {
  int sum = 0;
  for(int i = 0; i < key.size(); i++) {
    sum += (i+2) * (i+1) * (i+3) * key[i];
  }
  return abs(sum);
}

int hash_func1(string key, int size) {
  int k = string_to_int(key);
  return k % size;
}

int hash_func2(string key, int size) {
  int k = string_to_int(key);
  return 1 + (k % (size-1));
}

struct Gamer {
  int scores;
  string name;
};

bool sortfunction (Gamer& i,Gamer& j) {
  return (i.scores < j.scores);
}

int main() {
  int m = 5000;
  //ifstream cin("tests.txt");
  int n;
  cin >> n;
  double_hash<string, Gamer> hash(m, &hash_func1, &hash_func2);
  std::vector<string> names;
  std::vector<string> names_vect;
  vector<int> scores_vect;
  for(int i = 0; i < n; i++) {
    string s;
    cin >> s;
    int scores;
    cin >> scores;
    names_vect.push_back(s);
    Gamer* elem = hash.search(s);
    if(elem == NULL) {
      Gamer g;
      g.scores = scores;
      scores_vect.push_back(scores);
      g.name = s;
      names.push_back(s);
      hash.insert(s,g);
    } else {
      elem->scores += scores;
      scores_vect.push_back(elem->scores);
    }
  }
  std::vector<Gamer> v;
  vector<string>::iterator itnames = names.begin();
  for(;itnames != names.end(); itnames++) {
    v.push_back(*(hash.search(*itnames)));
  }
  std::sort(v.begin(), v.end(), sortfunction);
  int maxscore = v[v.size()-1].scores;
  itnames = names.begin();
  double_hash<string, int> hash2(m, &hash_func1, &hash_func2);
  for(;itnames != names.end(); itnames++) {
    Gamer* g = hash.search(*itnames);
    if(g->scores == maxscore) {
      hash2.insert(*itnames, 1);
    }
  }
  for(int i = 0; i < names_vect.size(); i++) {
    if(scores_vect[i] >= maxscore && hash2.search(names_vect[i]) != NULL ) {
      cout << names_vect[i] << "\n";
      return 0;
    }
  }
  return 0;
}


#include<iostream>
#include<map>
using namespace std;
map<string,pair<int,int> >m;
string cur,s;
int ans=-1000000000,k,n,t,mx=0;
main()
{

    cin>>n;
    for(int i=0;i<n;i++)
    {
       cin>>s>>t;
       m[s].first+=t;m[s].second=i;
       if(m[s].first>ans || (m[s].first==ans && m[s].second<k))
       ans=m[s].first,cur=s,k=m[s].second;
    }

cout<<cur<<endl;
}


#include<iostream>
#include<map>
using namespace std;
map<string,pair<int,int>m;
string cur,s;
int ans=-1000000000,k,n,t,mx=0;
main()
{

    cin>>n;
    for(int i=0;i<n;i++)
    {
       cin>>s>>t;
       m[s].first+=t;m[s].second=i;
       if(m[s].first>ans || (m[s].first==ans && m[s].second<k))
       ans=m[s].first,cur=s,k=m[s].second;
    }

cout<<cur<<endl;
}


#include<bits/stdc++.h>
using namespace std;
string S[10000];
map<string,int>m,m1;
int n,mx,A[10000],k,i;
main()
{
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>S[i]>>A[i];
        m[S[i]]+=A[i];
    }

    for(i=0;i<n;i++)
    mx=max(mx,m[S[i]]);

    for(i=0;m[S[i]]<mx || (m1[S[i]]+=A[i])<mx;i++);
    k=i;

    cout<<S[k]<<endl;
}


#include<iostream>
#include<map>
using namespace std;
map<string,int>m;
int main()
{
int n,t,mx=0;
cin>>n;string s,ans;
for(int i=0;i<n;i++)
{cin>>s>>t;
m[s]+=t;
if(m[s]>mx)
{mx=m[s];ans=s;
}
}
cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
string S[1000];
int n,mx,A[1000];
map<string,int>m,m1;
main()
{
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>S[i]>>A[i];
        m[S[i]]+=A[i];
    }

    for(int i=0;i<n;i++)
    mx=max(mx,m[S[i]]);

    for(int i=0;m[S[i]]<mx || (m1[S[i]]+=A[i])<mx;i++);
    cout<<S[i]<<endl;
}


#include<iostream>
#include<map>
using namespace std;
map<string,int>m;
string cur;int ans=0;
int main()
{
int n,t,mx=0;
cin>>n;string s;
for(int i=0;i<n;i++)
{
cin>>s>>t;
m[s]+=t;
if(m[s]>ans)
ans=m[s],cur=s;
}

cout<<cur<<endl;
}


#include<iostream>
#include<map>
using namespace std;
map<string,int>m;
string cur;int ans=0;
int main()
{
int n,t,mx=0;
cin>>n;string s,ans;
for(int i=0;i<n;i++)
{
cin>>s>>t;
m[s]+=t;
if(m[s]>ans)
ans=m[s],cur=s;
}

cout<<cur<<endl;
}


#include<bits/stdc++.h>
using namespace std;
string S[1000];
int n,mx,A[1000];
map<string,int>m,m1;
main()
{
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>S[i]>>A[i];
        m[S[i]]+=A[i];
    }

    for(i=0;i<n;i++)
    mx=max(mx,m[S[i]]);

    for(int i=0;m[S[i]]<mx || (m1[S[i]]+=A[i])<mx;i++);
    cout<<S[i];
}


#include<iostream>
#include<map>
using namespace std;
map<string,int>m;
map<int,string>m1;
string s;
int ans=-1000000000,n,t,mx=0;
main()
{

    cin>>n;
    for(int i=0;i<n;i++)
    {
       cin>>s>>t;
       m[s]+=t;
       if(m1[m[s]].size()==0)
       m1[m[s]]=s;
       if(m[s]>ans)
       ans=m[s];
    }

cout<<m1[ans]<<endl;
}


#include<iostream>
#include<map>
using namespace std;
map<string,int>m;
int main()
{
int n,t,mx=-100000;
cin>>n;string s,ans;
for(int i=0;i<n;i++)
{cin>>s>>t;
m[s]+=t;
if(m[s]>mx)
{mx=m[s];ans=s;
}
}
cout<<ans<<endl;
}


#include<iostream>
#include<map>
using namespace std;
map<string,int>m;
map<string,int>::iterator it;
int main()
{
int n,t,mx=0;
cin>>n;string s,ans;
for(int i=0;i<n;i++)
{
cin>>s>>t;
m[s]+=t;
}
for(it=m.begin(); it!=m.end(); it++)
if(it->second>mx)
{
mx=it->second;
ans=it->first;
}
cout<<ans<<endl;
}


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

import java.io.PrintWriter;
import java.util.Scanner;

public class TestingRobots_335_2 {
    public static void main (String[] args) {
        Scanner	sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int x = sc.nextInt(), y = sc.nextInt(), x0 = sc.nextInt(), y0 = sc.nextInt();
        String cmds = sc.next();
        int sum = 0;
        boolean[][] visited = new boolean[x][y];
        visited[x0 - 1][y0 - 1] = true;
        for (int k = 0; k <= cmds.length(); k++) {
            if (k == 0) {
                sum++;
                pw.print(1 + " ");
            }
            else if (k < cmds.length()) {
                char cmd = cmds.charAt(k - 1);
                int t = 1;
                switch(cmd) {
                    case 'U':
                        if (x0 > 1) {
                            x0--;
                            if (!visited[x0 - 1][y0 - 1]) {
                                visited[x0 - 1][y0 - 1] = true;
                            }
                            else t = 0;
                        }
                        else t = 0;
                        break;
                    case 'D':
                        if (x0 < x) {
                            x0++;
                            if (!visited[x0 - 1][y0 - 1]) {
                                visited[x0 - 1][y0 - 1] = true;
                            }
                            else t = 0;
                        }
                        else t = 0;
                        break;
                    case 'R':
                        if (y0 < y) {
                            y0++;
                            if (!visited[x0 - 1][y0 - 1]) {
                                visited[x0 - 1][y0 - 1] = true;
                            }
                            else t = 0;
                        }
                        else t = 0;
                        break;
                    case 'L':
                        if (y0 > 1) {
                            y0--;
                            if (!visited[x0 - 1][y0 - 1]) {
                                visited[x0 - 1][y0 - 1] = true;
                            }
                            else t = 0;
                        }
                        else t = 0;
                        break;
                }
                sum += t;
                pw.print(t + " ");
            }
            else {
                pw.print(x * y - sum);
            }
        }
        pw.close();
    }
}


import java.io.*;
import java.util.*;

public class b1 {
	public static void main(String[] args) throws FileNotFoundException {
		Scanner in = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		int x = in.nextInt();
		int y = in.nextInt();
		int x0 = in.nextInt() - 1;
		int y0 = in.nextInt() - 1;

		String s = in.next();

		boolean was[][] = new boolean[x][y];
		int cnt[] = new int[s.length()];
		long count = 1;

		for (int i = 0; i < x; i++) {
			Arrays.fill(was[i], false);
		}
		was[x0][y0] = true;
		out.print("1 ");

		for (int i = 0; i < s.length(); i++) {
			if (s.charAt(i) == 'U') {
				x0 = Math.max(0, x0 - 1);
			}
			if (s.charAt(i) == 'D') {
				x0 = Math.min(x - 1, x0 + 1);

			}
			if (s.charAt(i) == 'L') {
				y0 = Math.max(0, y0 - 1);
			}
			if (s.charAt(i) == 'R') {
				y0 = Math.min(y - 1, y0 + 1);
			}

			if (!was[x0][y0]) {
				if (i == s.length() - 1) {
					out.print(x * y - count);
				} else {
					out.print("1 ");
					count++;
					was[x0][y0] = true;
				}
			} else {
				if (i == s.length() - 1) {
					out.print("1");
				} else {
					out.print("0 ");
				}
			}
		}
		out.close();
	}
}


import java.io.*;
import java.util.*;

public class b1 {
	public static void main(String[] args) throws FileNotFoundException {
		Scanner in = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		int x = in.nextInt();
		int y = in.nextInt();
		int x0 = in.nextInt() - 1;
		int y0 = in.nextInt() - 1;

		String s = in.next();

		boolean was[][] = new boolean[x][y];
		int cnt[] = new int[s.length()];
		long count = 1;

		for (int i = 0; i < x; i++) {
			Arrays.fill(was[i], false);
		}
		was[x0][y0] = true;
		out.print("1 ");

		for (int i = 0; i < s.length(); i++) {
			if (s.charAt(i) == 'U') {
				x0 = Math.max(0, x0 - 1);
			}
			if (s.charAt(i) == 'D') {
				x0 = Math.min(x - 1, x0 + 1);

			}
			if (s.charAt(i) == 'L') {
				y0 = Math.max(0, y0 - 1);
			}
			if (s.charAt(i) == 'R') {
				y0 = Math.min(y - 1, y0 + 1);
			}

			if (!was[x0][y0]) {
				if (i == s.length() - 1) {
					out.print(x * y - count);
				} else {
					out.print("1 ");
					count++;
					was[x0][y0] = true;
				}
			} else {
				if (s.length() - 1 == i) {
					out.println(1l * x * y - count);
				} else {
					out.print("0 ");
				}
			}
		}
		out.close();
	}
}


import java.io.*;
import java.util.*;

public class b1 {
	public static void main(String[] args) throws FileNotFoundException {
		Scanner in = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		int x = in.nextInt();
		int y = in.nextInt();
		int x0 = in.nextInt() - 1;
		int y0 = in.nextInt() - 1;

		String s = in.next();

		boolean was[][] = new boolean[x][y];
		int cnt[] = new int[s.length()];
		long count = 1;

		for (int i = 0; i < x; i++) {
			Arrays.fill(was[i], false);
		}
		was[x0][y0] = true;
		out.print("1 ");

		for (int i = 0; i < s.length(); i++) {
			if (s.charAt(i) == 'U') {
				x0 = Math.max(0, x0 - 1);
			}
			if (s.charAt(i) == 'D') {
				x0 = Math.min(x - 1, x0 + 1);

			}
			if (s.charAt(i) == 'L') {
				y0 = Math.max(0, y0 - 1);
			}
			if (s.charAt(i) == 'R') {
				y0 = Math.min(y - 1, y0 + 1);
			}

			if (!was[x0][y0]) {
				if (i == s.length() - 1) {
					out.print(x * y - count);
				} else {
					out.print("1 ");
					count++;
					was[x0][y0] = true;
				}
			} else {
				out.print("0 ");
			}
		}
		out.close();
	}
}


import java.io.*;
import java.util.*;

public class b1 {
	public static void main(String[] args) throws FileNotFoundException {
		Scanner in = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		int x = in.nextInt();
		int y = in.nextInt();
		int x0 = in.nextInt() - 1;
		int y0 = in.nextInt() - 1;

		String s = in.next();

		boolean was[][] = new boolean[x][y];
		int cnt[] = new int[s.length()];
		long count = 1;

		for (int i = 0; i < x; i++) {
			Arrays.fill(was[i], false);
		}
		was[x0][y0] = true;
		out.print("1 ");

		for (int i = 0; i < s.length(); i++) {
			if (s.charAt(i) == 'U') {
				x0 = Math.max(0, x0 - 1);
			}
			if (s.charAt(i) == 'D') {
				x0 = Math.min(x - 1, x0 + 1);

			}
			if (s.charAt(i) == 'L') {
				y0 = Math.max(0, y0 - 1);
			}
			if (s.charAt(i) == 'R') {
				y0 = Math.min(y - 1, y0 + 1);
			}

			if (!was[x0][y0]) {
				if (i == s.length() - 1) {
					out.print(x * y - count);
				} else {
					out.print("1 ");
					count++;
					was[x0][y0] = true;
				}
			} else {
				if (i == s.length() - 1) {
					out.println("1");
				} else {
					out.print("0 ");
				}
			}
		}
		out.close();
	}
}


import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class Template implements Runnable {

    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok = new StringTokenizer("");

    void init() throws FileNotFoundException {
        try {
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        } catch (Exception e) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        }
    }

    String readString() throws IOException {
        while (!tok.hasMoreTokens()) {
            try {
                tok = new StringTokenizer(in.readLine());
            } catch (Exception e) {
                return null;
            }
        }
        return tok.nextToken();
    }

    int readInt() throws IOException {
        return Integer.parseInt(readString());
    }

    int[] readIntArray(int size) throws IOException {
        int[] res = new int[size];
        for (int i = 0; i < size; i++) {
            res[i] = readInt();
        }
        return res;
    }

    long readLong() throws IOException {
        return Long.parseLong(readString());
    }

    double readDouble() throws IOException {
        return Double.parseDouble(readString());
    }

    <T> List<T>[] createGraphList(int size) {
        List<T>[] list = new List[size];
        for (int i = 0; i < size; i++) {
            list[i] = new ArrayList<>();
        }
        return list;
    }

    public static void main(String[] args) {
        new Template().run();
        // new Thread(null, new Template(), "", 1l * 200 * 1024 * 1024).start();
    }

    long timeBegin, timeEnd;

    void time() {
        timeEnd = System.currentTimeMillis();
        System.err.println("Time = " + (timeEnd - timeBegin));
    }

    long memoryTotal, memoryFree;

    void memory() {
        memoryFree = Runtime.getRuntime().freeMemory();
        System.err.println("Memory = " + ((memoryTotal - memoryFree) >> 10)
                + " KB");
    }

    public void run() {
        try {
            timeBegin = System.currentTimeMillis();
            memoryTotal = Runtime.getRuntime().freeMemory();
            init();
            solve();
            out.close();
            if (System.getProperty("ONLINE_JUDGE") == null) {
                time();
                memory();
            }
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(-1);
        }
    }

    void solve() throws IOException {
        int x = readInt();
        int y = readInt();
        int curX = readInt();
        int curY = readInt();
        char[] com = readString().toCharArray();
        int[] answer = new int[com.length + 1];

        boolean[][] vis = new boolean[x + 1][y + 1];
        int index = 0;
        int comCount = 0;
        while (true) {
            if (index == com.length) {
                break;
            }
            if (!vis[curX][curY]) {
                vis[curX][curY] = true;
                answer[index]++;
                comCount++;
            }

            switch (com[index]) {
                case 'L':
                    curY--;
                    if (curY == 0) curY = 1;
                    break;
                case 'R':
                    curY++;
                    if (curY == y + 1) curY = y;
                    break;
                case 'D':
                    curX++;
                    if (curX == x + 1) curX = x;
                    break;
                case 'U':
                    curX--;
                    if (curX == 0) curX = 1;
                    break;
            }
            index++;
        }
        answer[com.length] = x * y - comCount;
        for (int z : answer) {
            out.print(z + " ");
        }
    }

}


import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;

public class CF2_335B {

  static Reader sc = new Reader();
  static PrintWriter out = new PrintWriter(System.out);

  static int[] deltaRow = { 1, 0, -1, 0 }; // S,E,N,W nextghbors
  static int[] deltaCol = { 0, 1, 0, -1 };

  public static boolean isValidCell(int row, int column) {
    return 0 <= row && row < maxRow && 0 <= column && column < maxCol;
  }

  static boolean[][] vis;

  static int maxRow;
  static int maxCol;
  static int row;
  static int col;

  static int getDir(char c) {
    if (c == 'U') {
      return 2;
    }
    if (c == 'L') {
      return 3;
    }
    if (c == 'D') {
      return 0;
    }
    if (c == 'R') {
      return 1;
    }
    return 0;
  }

  public static void main(String[] args) throws IOException {
    maxRow = sc.nextInt();
    maxCol = sc.nextInt();

    vis = new boolean[maxRow][maxCol];

    row = sc.nextInt() - 1;
    col = sc.nextInt() - 1;

    int last = maxRow * maxCol;

    char[] steps = sc.next().toCharArray();

    out.print(1);
    vis[row][col] = true;

    for (int i = 0; i < steps.length - 1; i++) {
      char c = steps[i];
      int indDir = getDir(c);
      if (isValidCell(row + deltaRow[indDir], col + deltaCol[indDir])) {
        row = row + deltaRow[indDir];
        col = col + deltaCol[indDir];
      }
      if (!vis[row][col]) {
        out.print(" " + 1);
        vis[row][col] = true;
        last--;
      } else {
        out.print(" " + 0);
      }
    }

    out.println(" " + (last - 1));
    out.close();
  }

  static class Reader {
    boolean consume = false; final private int BUFFER_SIZE = 1 << 12;private byte[] buffer;private int bufferPointer, bytesRead;private boolean reachedEnd = false;public Reader() {buffer = new byte[BUFFER_SIZE];bufferPointer = 0;bytesRead = 0;}
    public boolean hasNext() {return !reachedEnd;} private void fillBuffer() throws IOException {bytesRead = System.in.read(buffer, bufferPointer = 0, BUFFER_SIZE);if (bytesRead == -1) {buffer[0] = -1;reachedEnd = true;}}
    private void consumeSpaces() throws IOException {while (read() <= ' ' && reachedEnd == false);bufferPointer--;} private byte read() throws IOException {if (bufferPointer == bytesRead) {fillBuffer();}return buffer[bufferPointer++];}
    public String next() throws IOException {StringBuilder sb = new StringBuilder();consumeSpaces();byte c = read();do {sb.append((char) c);} while ((c = read()) > ' ');if (consume) {consumeSpaces();};if (sb.length() == 0) {return null;}return sb.toString();}
    public String nextLine() throws IOException {StringBuilder sb = new StringBuilder();byte c;boolean read = false;while ((c = read()) != -1) {if (c == '\n') {read = true;break;}if (c >= ' ')sb.append((char) c);}if (!read) {return null;}return sb.toString();}
    public int nextInt() throws IOException {consumeSpaces();int ret = 0;      byte c = read();boolean neg = (c == '-');if (neg) {c = read();}do {ret = ret * 10 + c - '0';} while ((c = read()) >= '0' && c <= '9');if (consume) {consumeSpaces();}if (neg) {return -ret;}return ret;}
    public long nextLong() throws IOException {consumeSpaces();long ret = 0;byte c = read();boolean neg = (c == '-');if (neg) {c = read();}do {ret = ret * 10L + c - '0';} while ((c = read()) >= '0' && c <= '9');if (consume) {consumeSpaces();}if (neg) {return -ret;}return ret;}
    public double nextDouble() throws IOException {consumeSpaces();double ret = 0;double div = 1;byte c = read();boolean neg = (c == '-');if (neg) {c = read();}do {ret = ret * 10 + c - '0';} while ((c = read()) >= '0' && c <= '9');if (c == '.') {while ((c = read()) >= '0' && c <= '9') {ret += (c - '0') / (div *= 10);}}if (consume) {consumeSpaces();}if (neg) {return -ret;}return ret;}    public int[] nextIntArray(int n) throws IOException {int[] a = new int[n];for (int i = 0; i < n; i++) {a[i] = nextInt();}return a;}
    public int[][] nextIntMatrix(int n, int m) throws IOException {int[][] grid = new int[n][m];for (int i = 0; i < n; i++) {grid[i] = nextIntArray(m);}return grid;}
    public char[][] nextCharacterMatrix(int n) throws IOException {char[][] a = new char[n][];for (int i = 0; i < n; i++) {a[i] = next().toCharArray();}return a;}
    public void close() throws IOException {if (System.in == null) {return;} else {System.in.close();}}
  }

  static void print(int[] A) {for (int i = 0; i < A.length; i++) {if (i != 0) {out.print(' ');}out.print(A[i]);}out.println();}
  static <T> void print(Iterable<T> A) {int i = 0;for (T act : A) {if (i != 0) {out.print(' ');}out.print(act);i++;}out.println();}
  static void printPlus1(Iterable<Number> A) {int i = 0;for (Number act : A) {if (i != 0) {out.print(' ');}out.print(act.longValue() + 1L);i++;}out.println();  }
  static void debug(Object... o) {System.err.println(Arrays.deepToString(o));}

  /*
  long s = System.currentTimeMillis();
  debug(System.currentTimeMillis() - s + "ms");
   */
}


import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;

public class CF2_335B {

  static Reader sc = new Reader();
  static PrintWriter out = new PrintWriter(System.out);

  static int[] deltaRow = { 1, 0, -1, 0 }; // S,E,N,W nextghbors
  static int[] deltaCol = { 0, 1, 0, -1 };

  public static boolean isValidCell(int row, int column) {
    return 0 <= row && row < maxRow && 0 <= column && column < maxCol;
  }

  static boolean[][] vis;

  static int maxRow;
  static int maxCol;
  static int row;
  static int col;

  static int getDir(char c) {
    if (c == 'U') {
      return 2;
    }
    if (c == 'L') {
      return 3;
    }
    if (c == 'D') {
      return 0;
    }
    if (c == 'R') {
      return 1;
    }
    return 0;
  }

  public static void main(String[] args) throws IOException {
    maxRow = sc.nextInt();
    maxCol = sc.nextInt();

    vis = new boolean[maxRow][maxCol];

    row = sc.nextInt() - 1;
    col = sc.nextInt() - 1;

    int last = maxRow * maxCol;

    char[] steps = sc.next().toCharArray();

    out.print(1);

    for (int i = 0; i < steps.length - 1; i++) {
      char c = steps[i];
      int indDir = getDir(c);
      if (isValidCell(row + deltaRow[indDir], col + deltaCol[indDir])) {
        row = row + deltaRow[indDir];
        col = col + deltaCol[indDir];
      }
      if (!vis[row][col]) {
        out.print(" " + 1);
        vis[row][col] = true;
        last--;
      } else {
        out.print(" " + 0);
      }
    }

    out.println(" " + (last - 1));
    out.close();
  }

  static class Reader {
    boolean consume = false; final private int BUFFER_SIZE = 1 << 12;private byte[] buffer;private int bufferPointer, bytesRead;private boolean reachedEnd = false;public Reader() {buffer = new byte[BUFFER_SIZE];bufferPointer = 0;bytesRead = 0;}
    public boolean hasNext() {return !reachedEnd;} private void fillBuffer() throws IOException {bytesRead = System.in.read(buffer, bufferPointer = 0, BUFFER_SIZE);if (bytesRead == -1) {buffer[0] = -1;reachedEnd = true;}}
    private void consumeSpaces() throws IOException {while (read() <= ' ' && reachedEnd == false);bufferPointer--;} private byte read() throws IOException {if (bufferPointer == bytesRead) {fillBuffer();}return buffer[bufferPointer++];}
    public String next() throws IOException {StringBuilder sb = new StringBuilder();consumeSpaces();byte c = read();do {sb.append((char) c);} while ((c = read()) > ' ');if (consume) {consumeSpaces();};if (sb.length() == 0) {return null;}return sb.toString();}
    public String nextLine() throws IOException {StringBuilder sb = new StringBuilder();byte c;boolean read = false;while ((c = read()) != -1) {if (c == '\n') {read = true;break;}if (c >= ' ')sb.append((char) c);}if (!read) {return null;}return sb.toString();}
    public int nextInt() throws IOException {consumeSpaces();int ret = 0;      byte c = read();boolean neg = (c == '-');if (neg) {c = read();}do {ret = ret * 10 + c - '0';} while ((c = read()) >= '0' && c <= '9');if (consume) {consumeSpaces();}if (neg) {return -ret;}return ret;}
    public long nextLong() throws IOException {consumeSpaces();long ret = 0;byte c = read();boolean neg = (c == '-');if (neg) {c = read();}do {ret = ret * 10L + c - '0';} while ((c = read()) >= '0' && c <= '9');if (consume) {consumeSpaces();}if (neg) {return -ret;}return ret;}
    public double nextDouble() throws IOException {consumeSpaces();double ret = 0;double div = 1;byte c = read();boolean neg = (c == '-');if (neg) {c = read();}do {ret = ret * 10 + c - '0';} while ((c = read()) >= '0' && c <= '9');if (c == '.') {while ((c = read()) >= '0' && c <= '9') {ret += (c - '0') / (div *= 10);}}if (consume) {consumeSpaces();}if (neg) {return -ret;}return ret;}    public int[] nextIntArray(int n) throws IOException {int[] a = new int[n];for (int i = 0; i < n; i++) {a[i] = nextInt();}return a;}
    public int[][] nextIntMatrix(int n, int m) throws IOException {int[][] grid = new int[n][m];for (int i = 0; i < n; i++) {grid[i] = nextIntArray(m);}return grid;}
    public char[][] nextCharacterMatrix(int n) throws IOException {char[][] a = new char[n][];for (int i = 0; i < n; i++) {a[i] = next().toCharArray();}return a;}
    public void close() throws IOException {if (System.in == null) {return;} else {System.in.close();}}
  }

  static void print(int[] A) {for (int i = 0; i < A.length; i++) {if (i != 0) {out.print(' ');}out.print(A[i]);}out.println();}
  static <T> void print(Iterable<T> A) {int i = 0;for (T act : A) {if (i != 0) {out.print(' ');}out.print(act);i++;}out.println();}
  static void printPlus1(Iterable<Number> A) {int i = 0;for (Number act : A) {if (i != 0) {out.print(' ');}out.print(act.longValue() + 1L);i++;}out.println();  }
  static void debug(Object... o) {System.err.println(Arrays.deepToString(o));}

  /*
  long s = System.currentTimeMillis();
  debug(System.currentTimeMillis() - s + "ms");
   */
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.Iterator;
import java.util.Collection;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Pradyumn
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, FastReader in, PrintWriter out) {
            int x = in.nextInt();
            int y = in.nextInt();
            int x0 = in.nextInt();
            int y0 = in.nextInt();
            char[] s = in.nextString().toCharArray();
            boolean[][] marked = new boolean[x + 1][y + 1];
            int n = s.length;
            List<Integer> ans = new ArrayList<>();
            ans.add(1);
            marked[x0][y0] = true;
            for (int i = 0; i < n; ++i) {
                int val = 0;
                if (s[i] == 'L') {
                    if (y0 != 1) --y0;
                } else if (s[i] == 'R') {
                    if (y0 != y) ++y0;
                } else if (s[i] == 'U') {
                    if (x0 != 1) --x0;
                } else if (s[i] == 'D') {
                    if (x0 != x) ++x0;
                }
                if (!marked[x0][y0]) {
                    val = 1;
                    marked[x0][y0] = true;
                }
                if (i == n - 1) {
                    for (int p = 1; p <= x; ++p) {
                        for (int q = 1; q <= y; ++q) {
                            if (!marked[p][q]) ++val;
                        }
                    }
                }
                ans.add(val);
            }
            ArrayUtils.printArray(out, ans);
        }

    }

    static class ArrayUtils {
        public static <T> void printArray(PrintWriter out, Collection<T> array) {
            if (array.size() == 0) return;
            int size = array.size();
            Iterator<T> iterator = array.iterator();
            int ct = 0;
            for (; ct < size && iterator.hasNext(); ct++) {
                if (ct != 0) out.print(" ");
                out.print(iterator.next());
            }
            out.println();
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[8192];
        private int curChar;
        private int pnumChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        private int pread() {
            if (pnumChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= pnumChars) {
                curChar = 0;
                try {
                    pnumChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (pnumChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = pread();
            while (isSpaceChar(c))
                c = pread();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = pread();
            }
            int res = 0;
            do {
                if (c == ',') {
                    c = pread();
                }
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = pread();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public String nextString() {
            int c = pread();
            while (isSpaceChar(c))
                c = pread();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = pread();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        private boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        private static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}


import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.InputMismatchException;
import java.io.BufferedWriter;
import java.io.PrintWriter;
import java.io.Writer;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.IOException;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Alex
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }
    static class TaskB {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int rows = in.readInt(), cols = in.readInt();
            int startrow = in.readInt() - 1, startcol = in.readInt() - 1;
            String s = in.next();
            boolean[][] visited = new boolean[rows][cols];
            int row = startrow, col = startcol;
            for(int i = 0; i <= s.length(); i++) {
                int res = (visited[row][col] ? 0 : 1);
                visited[row][col] = true;
                if(i == s.length()) for(boolean[] bb : visited) for(boolean b : bb) if(!b) res++;
                out.print(res + " ");
                if(i == s.length()) break;
                char c = s.charAt(i);
                if(c == 'U' && row > 0) row--;
                if(c == 'D' && row < rows - 1) row++;
                if(c == 'L' && col > 0) col--;
                if(c == 'R' && col < cols - 1) col++;
            }
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if(numChars == -1)
                throw new InputMismatchException();
            if(curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch(IOException e) {
                    throw new InputMismatchException();
                }
                if(numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int readInt() {
            int c = read();
            while(isSpaceChar(c))
                c = read();
            int sgn = 1;
            if(c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if(c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while(!isSpaceChar(c));
            return res * sgn;
        }

        public String readString() {
            int c = read();
            while(isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                if(Character.isValidCodePoint(c))
                    res.appendCodePoint(c);
                c = read();
            } while(!isSpaceChar(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if(filter != null)
                return filter.isSpaceChar(c);
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next() {
            return readString();
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for(int i = 0; i < objects.length; i++) {
                if(i != 0)
                    writer.print(' ');
                writer.print(objects[i]);
            }
        }

        public void close() {
            writer.close();
        }

    }
}