#include <ext/pb_ds/priority_queue.hpp>
#include <algorithm>
#include <iostream>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <climits>
#include <cctype>
#include <cstdio>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <map>

#define f(x, y, z) for (int x = (y), _end_ = (z); x <= _end_; ++x)
#define g(x, y, z) for (int x = (y), _end_ = (z); x >= _end_; --x)
#define fe(x, y, z) for (int x = (y), _end_ = (z); x < _end_; ++x)
#define ge(x, y, z) for (int x = (y), _end_ = (z); x > _end_; --x)
#define h(x, y) for (int x = head[(y)]; x; x = nxt[x])
#define ms(a, b) memset(a, b, sizeof (a));
#define LYF __attribute__((optimize(("O3"))))
#define mp make_pair
#define pb push_back
#define fr first
#define	se second
using namespace std;
using namespace __gnu_pbds;

typedef long long LL;
typedef std::pair <int, int> PII;
const double eps = 1e-8;
const int MAX_N = 3e5 + 7;
const int FLOWER_DANCE = 1e9 + 7;

namespace In {
	LYF inline void read(int &x) {
		char c; int flag = 1;
		while ((c = getchar()) < '0' || c > '9') if (c == '-') flag *= -1;
		x = c - '0';
		while ((c = getchar()) >= '0' && c <= '9') x = (x << 3) + (x << 1), x += c - '0';
		x *= flag;
	}
	LYF inline void read(int &x, int &y) {
		read(x); read(y);
	}
	LYF inline void read(int &x, int &y, int &z) {
		read(x); read(y); read(z);
	}
	LYF inline void read(LL &x) {
		char c; int flag = 1;
		while ((c = getchar()) < '0' || c > '9') if (c == '-') flag *= -1;
		x = c - '0';
		while ((c = getchar()) >= '0' && c <= '9') x = (x << 3) + (x << 1), x += c - '0';
		x *= flag;
	}
	LYF inline void read(LL &x, LL &y) {
		read(x); read(y);
	}
	LYF inline void read(LL &x, LL &y, LL &z) {
		read(x); read(y); read(z);
	}
}

LYF inline int plus(int a, int b) {
	if (a + b >= FLOWER_DANCE) return a + b - FLOWER_DANCE;
	return a + b;
}

//  ~_~  Var :
typedef std::pair <string, int> PSI;
int n, m, q, x, y, z;
string s;
struct dsh {
	inline bool operator () (const int &a, const int &b) {
		return a > b;
	}
};
__gnu_pbds::priority_queue <int, dsh, binary_heap_tag> Q;
std::queue <PSI> Ans;
//  =_=  Func :

//  ^_^  Main :
LYF int main() {
#ifdef ONLINE_JUDGE
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	srand(int(time(0)));
#endif
	cin >> n;
	while (n --) {
		cin >> s;
		if (s == "insert") {
			cin >> x;
			Q.push(x);
			//cout << s << ' ' << x << endl;
			Ans.push(PSI(s, x));
		} else if (s == "getMin") {
			cin >> x;
			//cout << Q.top() << "   Debug\n";
			while (!Q.empty() && Q.top() < x) {
				Q.pop();
				Ans.push(PSI("removeMin", 0));
				//cout << "removeMin\n";
			}
			if (Q.empty() || Q.top() != x) {
				Ans.push(PSI("insert", x));
				//cout << "insert " << x << endl;
				Q.push(x);
			}
			Ans.push(PSI(s, x));
			//cout << s << ' ' << x << endl;
		} else if (s == "removeMin") {
			if (Q.empty()) {
				Ans.push(PSI("insert", 0));
				//cout << "insert 0\n";
				Q.push(0);
			}
			Q.pop();
			Ans.push(PSI("removeMin", 0));
			//cout << "removeMin\n";
		}
	}
	cout << Ans.size() << endl;
	while (!Ans.empty()) {
		s = Ans.front().fr;
		n = Ans.front().se;
		cout << s;
		if (s != "removeMin") cout << ' ' << n;
		cout << endl;
		Ans.pop();
	}
}


#include <algorithm>
#include <iostream>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <climits>
#include <cctype>
#include <cstdio>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <map>

#define f(x, y, z) for (int x = (y), _end_ = (z); x <= _end_; ++x)
#define g(x, y, z) for (int x = (y), _end_ = (z); x >= _end_; --x)
#define fe(x, y, z) for (int x = (y), _end_ = (z); x < _end_; ++x)
#define ge(x, y, z) for (int x = (y), _end_ = (z); x > _end_; --x)
#define h(x, y) for (int x = head[(y)]; x; x = nxt[x])
#define ms(a, b) memset(a, b, sizeof (a));
#define LYF __attribute__((optimize(("O3"))))
#define mp make_pair
#define pb push_back
#define fr first
#define	se second
using namespace std;

typedef long long LL;
typedef std::pair <int, int> PII;
const double eps = 1e-8;
const int MAX_N = 3e5 + 7;
const int FLOWER_DANCE = 1e9 + 7;

namespace In {
	LYF inline void read(int &x) {
		char c; int flag = 1;
		while ((c = getchar()) < '0' || c > '9') if (c == '-') flag *= -1;
		x = c - '0';
		while ((c = getchar()) >= '0' && c <= '9') x = (x << 3) + (x << 1), x += c - '0';
		x *= flag;
	}
	LYF inline void read(int &x, int &y) {
		read(x); read(y);
	}
	LYF inline void read(int &x, int &y, int &z) {
		read(x); read(y); read(z);
	}
	LYF inline void read(LL &x) {
		char c; int flag = 1;
		while ((c = getchar()) < '0' || c > '9') if (c == '-') flag *= -1;
		x = c - '0';
		while ((c = getchar()) >= '0' && c <= '9') x = (x << 3) + (x << 1), x += c - '0';
		x *= flag;
	}
	LYF inline void read(LL &x, LL &y) {
		read(x); read(y);
	}
	LYF inline void read(LL &x, LL &y, LL &z) {
		read(x); read(y); read(z);
	}
}

LYF inline int plus(int a, int b) {
	if (a + b >= FLOWER_DANCE) return a + b - FLOWER_DANCE;
	return a + b;
}

//  ~_~  Var :
typedef std::pair <string, int> PSI;
int n, m, q, x, y, z;
string s;
std::priority_queue <int> Q;
std::queue <PSI> Ans;
//  =_=  Func :

//  ^_^  Main :
LYF int main() {
#ifdef ONLINE_JUDGE
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	srand(int(time(0)));
#endif
	cin >> n;
	while (n --) {
		cin >> s;
		if (s == "insert") {
			cin >> x;
			Q.push(x);
			//cout << s << ' ' << x << endl;
			Ans.push(PSI(s, x));
		} else if (s == "getMin") {
			cin >> x;
			while (!Q.empty() && Q.top() < x) {
				Q.pop();
				Ans.push(PSI("removeMin", 0));
			}
			if (Q.empty()) {
				Ans.push(PSI("insert", x));
				Q.push(x);
			}
			Ans.push(PSI(s, x));
		} else if (s == "removeMin") {
			if (Q.empty()) {
				Ans.push(PSI("insert", 0));
				Q.push(0);
			}
			Q.pop();
			Ans.push(PSI("removeMin", 0));
		}
	}
	cout << Ans.size() << endl;
	while (!Ans.empty()) {
		s = Ans.front().fr;
		n = Ans.front().se;
		cout << s;
		if (s != "removeMin") cout << ' ' << n;
		cout << endl;
		Ans.pop();
	}
}


#include <algorithm>
#include <iostream>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <climits>
#include <cctype>
#include <cstdio>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <map>

#define f(x, y, z) for (int x = (y), _end_ = (z); x <= _end_; ++x)
#define g(x, y, z) for (int x = (y), _end_ = (z); x >= _end_; --x)
#define fe(x, y, z) for (int x = (y), _end_ = (z); x < _end_; ++x)
#define ge(x, y, z) for (int x = (y), _end_ = (z); x > _end_; --x)
#define h(x, y) for (int x = head[(y)]; x; x = nxt[x])
#define ms(a, b) memset(a, b, sizeof (a));
#define LYF __attribute__((optimize(("O3"))))
#define mp make_pair
#define pb push_back
#define fr first
#define	se second
using namespace std;

typedef long long LL;
typedef std::pair <int, int> PII;
const double eps = 1e-8;
const int MAX_N = 3e5 + 7;
const int FLOWER_DANCE = 1e9 + 7;

namespace In {
	LYF inline void read(int &x) {
		char c; int flag = 1;
		while ((c = getchar()) < '0' || c > '9') if (c == '-') flag *= -1;
		x = c - '0';
		while ((c = getchar()) >= '0' && c <= '9') x = (x << 3) + (x << 1), x += c - '0';
		x *= flag;
	}
	LYF inline void read(int &x, int &y) {
		read(x); read(y);
	}
	LYF inline void read(int &x, int &y, int &z) {
		read(x); read(y); read(z);
	}
	LYF inline void read(LL &x) {
		char c; int flag = 1;
		while ((c = getchar()) < '0' || c > '9') if (c == '-') flag *= -1;
		x = c - '0';
		while ((c = getchar()) >= '0' && c <= '9') x = (x << 3) + (x << 1), x += c - '0';
		x *= flag;
	}
	LYF inline void read(LL &x, LL &y) {
		read(x); read(y);
	}
	LYF inline void read(LL &x, LL &y, LL &z) {
		read(x); read(y); read(z);
	}
}

LYF inline int plus(int a, int b) {
	if (a + b >= FLOWER_DANCE) return a + b - FLOWER_DANCE;
	return a + b;
}

//  ~_~  Var :
typedef std::pair <string, int> PSI;
int n, m, q, x, y, z;
string s;
std::priority_queue <int> Q;
std::queue <PSI> Ans;
//  =_=  Func :

//  ^_^  Main :
LYF int main() {
#ifdef ONLINE_JUDGE
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	srand(int(time(0)));
#endif
	cin >> n;
	while (n --) {
		cin >> s;
		if (s == "insert") {
			cin >> x;
			Q.push(x);
			//cout << s << ' ' << x << endl;
			Ans.push(PSI(s, x));
		} else if (s == "getMin") {
			cin >> x;
			while (!Q.empty() && Q.top() < x) {
				Q.pop();
				Ans.push(PSI("removeMin", 0));
			}
			if (Q.empty()) Ans.push(PSI("insert", x));
			Ans.push(PSI(s, x));
		} else if (s == "removeMin") {
			if (Q.empty()) Ans.push(PSI("insert", rand()));
			Q.pop();
			Ans.push(PSI("removeMin", 0));
		}
	}
	cout << Ans.size() << endl;
	while (!Ans.empty()) {
		s = Ans.front().fr;
		n = Ans.front().se;
		cout << s;
		if (s != "removeMin") cout << ' ' << n;
		cout << endl;
		Ans.pop();
	}
}


#include <algorithm>
#include <iostream>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <climits>
#include <cctype>
#include <cstdio>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <map>

#define f(x, y, z) for (int x = (y), _end_ = (z); x <= _end_; ++x)
#define g(x, y, z) for (int x = (y), _end_ = (z); x >= _end_; --x)
#define fe(x, y, z) for (int x = (y), _end_ = (z); x < _end_; ++x)
#define ge(x, y, z) for (int x = (y), _end_ = (z); x > _end_; --x)
#define h(x, y) for (int x = head[(y)]; x; x = nxt[x])
#define ms(a, b) memset(a, b, sizeof (a));
#define LYF __attribute__((optimize(("O3"))))
#define mp make_pair
#define pb push_back
#define fr first
#define	se second
using namespace std;

typedef long long LL;
typedef std::pair <int, int> PII;
const double eps = 1e-8;
const int MAX_N = 3e5 + 7;
const int FLOWER_DANCE = 1e9 + 7;

namespace In {
	LYF inline void read(int &x) {
		char c; int flag = 1;
		while ((c = getchar()) < '0' || c > '9') if (c == '-') flag *= -1;
		x = c - '0';
		while ((c = getchar()) >= '0' && c <= '9') x = (x << 3) + (x << 1), x += c - '0';
		x *= flag;
	}
	LYF inline void read(int &x, int &y) {
		read(x); read(y);
	}
	LYF inline void read(int &x, int &y, int &z) {
		read(x); read(y); read(z);
	}
	LYF inline void read(LL &x) {
		char c; int flag = 1;
		while ((c = getchar()) < '0' || c > '9') if (c == '-') flag *= -1;
		x = c - '0';
		while ((c = getchar()) >= '0' && c <= '9') x = (x << 3) + (x << 1), x += c - '0';
		x *= flag;
	}
	LYF inline void read(LL &x, LL &y) {
		read(x); read(y);
	}
	LYF inline void read(LL &x, LL &y, LL &z) {
		read(x); read(y); read(z);
	}
}

LYF inline int plus(int a, int b) {
	if (a + b >= FLOWER_DANCE) return a + b - FLOWER_DANCE;
	return a + b;
}

//  ~_~  Var :
typedef std::pair <string, int> PSI;
int n, m, q, x, y, z;
string s;
std::priority_queue <int> Q;
std::queue <PSI> Ans;
//  =_=  Func :

//  ^_^  Main :
LYF int main() {
#ifdef ONLINE_JUDGE
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	srand(int(time(0)));
#endif
	cin >> n;
	while (n --) {
		cin >> s;
		if (s == "insert") {
			cin >> x;
			Q.push(x);
			//cout << s << ' ' << x << endl;
			Ans.push(PSI(s, x));
		} else if (s == "getMin") {
			cin >> x;
			while (!Q.empty() && Q.top() < x) {
				Q.pop();
				Ans.push(PSI("removeMin", 0));
			}
			if (Q.empty()) {
				Ans.push(PSI("insert", x));
				Q.push(x);
			}
			Ans.push(PSI(s, x));
		} else if (s == "removeMin") {
			if (Q.empty()) {
				Ans.push(PSI("insert", z = rand()));
				Q.push(z);
			}
			Q.pop();
			Ans.push(PSI("removeMin", 0));
		}
	}
	cout << Ans.size() << endl;
	while (!Ans.empty()) {
		s = Ans.front().fr;
		n = Ans.front().se;
		cout << s;
		if (s != "removeMin") cout << ' ' << n;
		cout << endl;
		Ans.pop();
	}
}


#include <algorithm>
#include <iostream>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <climits>
#include <cctype>
#include <cstdio>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <map>

#define f(x, y, z) for (int x = (y), _end_ = (z); x <= _end_; ++x)
#define g(x, y, z) for (int x = (y), _end_ = (z); x >= _end_; --x)
#define fe(x, y, z) for (int x = (y), _end_ = (z); x < _end_; ++x)
#define ge(x, y, z) for (int x = (y), _end_ = (z); x > _end_; --x)
#define h(x, y) for (int x = head[(y)]; x; x = nxt[x])
#define ms(a, b) memset(a, b, sizeof (a));
#define LYF __attribute__((optimize(("O3"))))
#define mp make_pair
#define pb push_back
#define fr first
#define	se second
using namespace std;

typedef long long LL;
typedef std::pair <int, int> PII;
const double eps = 1e-8;
const int MAX_N = 3e5 + 7;
const int FLOWER_DANCE = 1e9 + 7;

namespace In {
	LYF inline void read(int &x) {
		char c; int flag = 1;
		while ((c = getchar()) < '0' || c > '9') if (c == '-') flag *= -1;
		x = c - '0';
		while ((c = getchar()) >= '0' && c <= '9') x = (x << 3) + (x << 1), x += c - '0';
		x *= flag;
	}
	LYF inline void read(int &x, int &y) {
		read(x); read(y);
	}
	LYF inline void read(int &x, int &y, int &z) {
		read(x); read(y); read(z);
	}
	LYF inline void read(LL &x) {
		char c; int flag = 1;
		while ((c = getchar()) < '0' || c > '9') if (c == '-') flag *= -1;
		x = c - '0';
		while ((c = getchar()) >= '0' && c <= '9') x = (x << 3) + (x << 1), x += c - '0';
		x *= flag;
	}
	LYF inline void read(LL &x, LL &y) {
		read(x); read(y);
	}
	LYF inline void read(LL &x, LL &y, LL &z) {
		read(x); read(y); read(z);
	}
}

LYF inline int plus(int a, int b) {
	if (a + b >= FLOWER_DANCE) return a + b - FLOWER_DANCE;
	return a + b;
}

//  ~_~  Var :
typedef std::pair <string, int> PSI;
int n, m, q, x, y, z;
string s;
std::priority_queue <int> Q;
std::queue <PSI> Ans;
//  =_=  Func :

//  ^_^  Main :
LYF int main() {
#ifdef ONLINE_JUDGE
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	srand(int(time(0)));
#endif
	cin >> n;
	while (n --) {
		cin >> s;
		if (s == "insert") {
			cin >> x;
			Q.push(x);
			//cout << s << ' ' << x << endl;
			Ans.push(PSI(s, x));
		} else if (s == "getMin") {
			cin >> x;
			while (!Q.empty() && Q.top() < x) {
				Q.pop();
				Ans.push(PSI("removeMin", 0));
			}
			if (Q.empty() || Q.top() != x) {
				Ans.push(PSI("insert", x));
				Q.push(x);
			}
			Ans.push(PSI(s, x));
		} else if (s == "removeMin") {
			if (Q.empty()) {
				Ans.push(PSI("insert", 0));
				Q.push(0);
			}
			Q.pop();
			Ans.push(PSI("removeMin", 0));
		}
	}
	cout << Ans.size() << endl;
	while (!Ans.empty()) {
		s = Ans.front().fr;
		n = Ans.front().se;
		cout << s;
		if (s != "removeMin") cout << ' ' << n;
		cout << endl;
		Ans.pop();
	}
}


#include <ext/pb_ds/priority_queue.hpp>
#include <algorithm>
#include <iostream>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <climits>
#include <cctype>
#include <cstdio>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <map>

#define f(x, y, z) for (int x = (y), _end_ = (z); x <= _end_; ++x)
#define g(x, y, z) for (int x = (y), _end_ = (z); x >= _end_; --x)
#define fe(x, y, z) for (int x = (y), _end_ = (z); x < _end_; ++x)
#define ge(x, y, z) for (int x = (y), _end_ = (z); x > _end_; --x)
#define h(x, y) for (int x = head[(y)]; x; x = nxt[x])
#define ms(a, b) memset(a, b, sizeof (a));
#define LYF __attribute__((optimize(("O3"))))
#define mp make_pair
#define pb push_back
#define fr first
#define	se second
using namespace std;
using namespace __gnu_pbds;

typedef long long LL;
typedef std::pair <int, int> PII;
const double eps = 1e-8;
const int MAX_N = 3e5 + 7;
const int FLOWER_DANCE = 1e9 + 7;

namespace In {
	LYF inline void read(int &x) {
		char c; int flag = 1;
		while ((c = getchar()) < '0' || c > '9') if (c == '-') flag *= -1;
		x = c - '0';
		while ((c = getchar()) >= '0' && c <= '9') x = (x << 3) + (x << 1), x += c - '0';
		x *= flag;
	}
	LYF inline void read(int &x, int &y) {
		read(x); read(y);
	}
	LYF inline void read(int &x, int &y, int &z) {
		read(x); read(y); read(z);
	}
	LYF inline void read(LL &x) {
		char c; int flag = 1;
		while ((c = getchar()) < '0' || c > '9') if (c == '-') flag *= -1;
		x = c - '0';
		while ((c = getchar()) >= '0' && c <= '9') x = (x << 3) + (x << 1), x += c - '0';
		x *= flag;
	}
	LYF inline void read(LL &x, LL &y) {
		read(x); read(y);
	}
	LYF inline void read(LL &x, LL &y, LL &z) {
		read(x); read(y); read(z);
	}
}

LYF inline int plus(int a, int b) {
	if (a + b >= FLOWER_DANCE) return a + b - FLOWER_DANCE;
	return a + b;
}

//  ~_~  Var :
typedef std::pair <string, int> PSI;
int n, m, q, x, y, z;
string s;
struct dsh {
	inline bool operator () (const int &a, const int &b) {
		return a > b;
	}
};
__gnu_pbds::priority_queue <int, dsh, thin_heap_tag> Q;
std::queue <PSI> Ans;
//  =_=  Func :

//  ^_^  Main :
LYF int main() {
#ifdef ONLINE_JUDGE
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	srand(int(time(0)));
#endif
	cin >> n;
	while (n --) {
		cin >> s;
		if (s == "insert") {
			cin >> x;
			Q.push(x);
			//cout << s << ' ' << x << endl;
			Ans.push(PSI(s, x));
		} else if (s == "getMin") {
			cin >> x;
			//cout << Q.top() << "   Debug\n";
			while (!Q.empty() && Q.top() < x) {
				Q.pop();
				Ans.push(PSI("removeMin", 0));
				//cout << "removeMin\n";
			}
			if (Q.empty() || Q.top() != x) {
				Ans.push(PSI("insert", x));
				//cout << "insert " << x << endl;
				Q.push(x);
			}
			Ans.push(PSI(s, x));
			//cout << s << ' ' << x << endl;
		} else if (s == "removeMin") {
			if (Q.empty()) {
				Ans.push(PSI("insert", 0));
				//cout << "insert 0\n";
				Q.push(0);
			}
			Q.pop();
			Ans.push(PSI("removeMin", 0));
			//cout << "removeMin\n";
		}
	}
	cout << Ans.size() << endl;
	while (!Ans.empty()) {
		s = Ans.front().fr;
		n = Ans.front().se;
		cout << s;
		if (s != "removeMin") cout << ' ' << n;
		cout << endl;
		Ans.pop();
	}
}


#include <algorithm>
#include <iostream>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <climits>
#include <cctype>
#include <cstdio>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <map>

#define f(x, y, z) for (int x = (y), _end_ = (z); x <= _end_; ++x)
#define g(x, y, z) for (int x = (y), _end_ = (z); x >= _end_; --x)
#define fe(x, y, z) for (int x = (y), _end_ = (z); x < _end_; ++x)
#define ge(x, y, z) for (int x = (y), _end_ = (z); x > _end_; --x)
#define h(x, y) for (int x = head[(y)]; x; x = nxt[x])
#define ms(a, b) memset(a, b, sizeof (a));
#define LYF __attribute__((optimize(("O3"))))
#define mp make_pair
#define pb push_back
#define fr first
#define	se second
using namespace std;

typedef long long LL;
typedef std::pair <int, int> PII;
const double eps = 1e-8;
const int MAX_N = 3e5 + 7;
const int FLOWER_DANCE = 1e9 + 7;

namespace In {
	LYF inline void read(int &x) {
		char c; int flag = 1;
		while ((c = getchar()) < '0' || c > '9') if (c == '-') flag *= -1;
		x = c - '0';
		while ((c = getchar()) >= '0' && c <= '9') x = (x << 3) + (x << 1), x += c - '0';
		x *= flag;
	}
	LYF inline void read(int &x, int &y) {
		read(x); read(y);
	}
	LYF inline void read(int &x, int &y, int &z) {
		read(x); read(y); read(z);
	}
	LYF inline void read(LL &x) {
		char c; int flag = 1;
		while ((c = getchar()) < '0' || c > '9') if (c == '-') flag *= -1;
		x = c - '0';
		while ((c = getchar()) >= '0' && c <= '9') x = (x << 3) + (x << 1), x += c - '0';
		x *= flag;
	}
	LYF inline void read(LL &x, LL &y) {
		read(x); read(y);
	}
	LYF inline void read(LL &x, LL &y, LL &z) {
		read(x); read(y); read(z);
	}
}

LYF inline int plus(int a, int b) {
	if (a + b >= FLOWER_DANCE) return a + b - FLOWER_DANCE;
	return a + b;
}

//  ~_~  Var :
typedef std::pair <string, int> PSI;
int n, m, q, x, y, z;
string s;
std::priority_queue <int> Q;
std::queue <PSI> Ans;
//  =_=  Func :

//  ^_^  Main :
LYF int main() {
#ifdef ONLINE_JUDGE
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
#endif
	cin >> n;
	while (n --) {
		cin >> s;
		if (s == "insert") {
			cin >> x;
			Q.push(x);
			//cout << s << ' ' << x << endl;
			Ans.push(PSI(s, x));
		} else if (s == "getMin") {
			cin >> x;
			while (!Q.empty() && Q.top() < x) {
				Q.pop();
				Ans.push(PSI("removeMin", 0));
			}
			if (Q.empty()) Ans.push(PSI("insert", x));
			Ans.push(PSI(s, x));
		} else if (s == "removeMin") {
			Q.pop();
			Ans.push(PSI("removeMin", 0));
		}
	}
	cout << Ans.size() << endl;
	while (!Ans.empty()) {
		s = Ans.front().fr;
		n = Ans.front().se;
		cout << s;
		if (s != "removeMin") cout << ' ' << n;
		cout << endl;
		Ans.pop();
	}
}


#include <ext/pb_ds/priority_queue.hpp>
#include <algorithm>
#include <iostream>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <climits>
#include <cctype>
#include <cstdio>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <map>

#define f(x, y, z) for (int x = (y), _end_ = (z); x <= _end_; ++x)
#define g(x, y, z) for (int x = (y), _end_ = (z); x >= _end_; --x)
#define fe(x, y, z) for (int x = (y), _end_ = (z); x < _end_; ++x)
#define ge(x, y, z) for (int x = (y), _end_ = (z); x > _end_; --x)
#define h(x, y) for (int x = head[(y)]; x; x = nxt[x])
#define ms(a, b) memset(a, b, sizeof (a));
#define LYF __attribute__((optimize(("O3"))))
#define mp make_pair
#define pb push_back
#define fr first
#define	se second
using namespace std;

typedef long long LL;
typedef std::pair <int, int> PII;
const double eps = 1e-8;
const int MAX_N = 3e5 + 7;
const int FLOWER_DANCE = 1e9 + 7;

namespace In {
	LYF inline void read(int &x) {
		char c; int flag = 1;
		while ((c = getchar()) < '0' || c > '9') if (c == '-') flag *= -1;
		x = c - '0';
		while ((c = getchar()) >= '0' && c <= '9') x = (x << 3) + (x << 1), x += c - '0';
		x *= flag;
	}
	LYF inline void read(int &x, int &y) {
		read(x); read(y);
	}
	LYF inline void read(int &x, int &y, int &z) {
		read(x); read(y); read(z);
	}
	LYF inline void read(LL &x) {
		char c; int flag = 1;
		while ((c = getchar()) < '0' || c > '9') if (c == '-') flag *= -1;
		x = c - '0';
		while ((c = getchar()) >= '0' && c <= '9') x = (x << 3) + (x << 1), x += c - '0';
		x *= flag;
	}
	LYF inline void read(LL &x, LL &y) {
		read(x); read(y);
	}
	LYF inline void read(LL &x, LL &y, LL &z) {
		read(x); read(y); read(z);
	}
}

LYF inline int plus(int a, int b) {
	if (a + b >= FLOWER_DANCE) return a + b - FLOWER_DANCE;
	return a + b;
}

//  ~_~  Var :
typedef std::pair <string, int> PSI;
int n, m, q, x, y, z;
string s;
struct dsh {
	inline bool operator () (const int &a, const int &b) {
		return a > b;
	}
};
__gnu_pbds::priority_queue <int, dsh> Q;
std::queue <PSI> Ans;
//  =_=  Func :

//  ^_^  Main :
LYF int main() {
#ifdef ONLINE_JUDGE
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	srand(int(time(0)));
#endif
	cin >> n;
	while (n --) {
		cin >> s;
		if (s == "insert") {
			cin >> x;
			Q.push(x);
			//cout << s << ' ' << x << endl;
			Ans.push(PSI(s, x));
		} else if (s == "getMin") {
			cin >> x;
			//cout << Q.top() << "   Debug\n";
			while (!Q.empty() && Q.top() < x) {
				Q.pop();
				Ans.push(PSI("removeMin", 0));
				//cout << "removeMin\n";
			}
			if (Q.empty() || Q.top() != x) {
				Ans.push(PSI("insert", x));
				//cout << "insert " << x << endl;
				Q.push(x);
			}
			Ans.push(PSI(s, x));
			//cout << s << ' ' << x << endl;
		} else if (s == "removeMin") {
			if (Q.empty()) {
				Ans.push(PSI("insert", 0));
				//cout << "insert 0\n";
				Q.push(0);
			}
			Q.pop();
			Ans.push(PSI("removeMin", 0));
			//cout << "removeMin\n";
		}
	}
	cout << Ans.size() << endl;
	while (!Ans.empty()) {
		s = Ans.front().fr;
		n = Ans.front().se;
		cout << s;
		if (s != "removeMin") cout << ' ' << n;
		cout << endl;
		Ans.pop();
	}
}


#include <algorithm>
#include <iostream>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <climits>
#include <cctype>
#include <cstdio>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <map>

#define f(x, y, z) for (int x = (y), _end_ = (z); x <= _end_; ++x)
#define g(x, y, z) for (int x = (y), _end_ = (z); x >= _end_; --x)
#define fe(x, y, z) for (int x = (y), _end_ = (z); x < _end_; ++x)
#define ge(x, y, z) for (int x = (y), _end_ = (z); x > _end_; --x)
#define h(x, y) for (int x = head[(y)]; x; x = nxt[x])
#define ms(a, b) memset(a, b, sizeof (a));
#define LYF __attribute__((optimize(("O3"))))
#define mp make_pair
#define pb push_back
#define fr first
#define	se second
using namespace std;

typedef long long LL;
typedef std::pair <int, int> PII;
const double eps = 1e-8;
const int MAX_N = 3e5 + 7;
const int FLOWER_DANCE = 1e9 + 7;

namespace In {
	LYF inline void read(int &x) {
		char c; int flag = 1;
		while ((c = getchar()) < '0' || c > '9') if (c == '-') flag *= -1;
		x = c - '0';
		while ((c = getchar()) >= '0' && c <= '9') x = (x << 3) + (x << 1), x += c - '0';
		x *= flag;
	}
	LYF inline void read(int &x, int &y) {
		read(x); read(y);
	}
	LYF inline void read(int &x, int &y, int &z) {
		read(x); read(y); read(z);
	}
	LYF inline void read(LL &x) {
		char c; int flag = 1;
		while ((c = getchar()) < '0' || c > '9') if (c == '-') flag *= -1;
		x = c - '0';
		while ((c = getchar()) >= '0' && c <= '9') x = (x << 3) + (x << 1), x += c - '0';
		x *= flag;
	}
	LYF inline void read(LL &x, LL &y) {
		read(x); read(y);
	}
	LYF inline void read(LL &x, LL &y, LL &z) {
		read(x); read(y); read(z);
	}
}

LYF inline int plus(int a, int b) {
	if (a + b >= FLOWER_DANCE) return a + b - FLOWER_DANCE;
	return a + b;
}

//  ~_~  Var :
typedef std::pair <string, int> PSI;
int n, m, q, x, y, z;
string s;
struct dsh {
	inline bool operator () (const int &a, const int &b) {
		return a > b;
	}
};
std::priority_queue <int, vector<int>, dsh> Q;
std::queue <PSI> Ans;
//  =_=  Func :

//  ^_^  Main :
LYF int main() {
#ifdef ONLINE_JUDGE
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	srand(int(time(0)));
#endif
	cin >> n;
	while (n --) {
		cin >> s;
		if (s == "insert") {
			cin >> x;
			Q.push(x);
			//cout << s << ' ' << x << endl;
			Ans.push(PSI(s, x));
		} else if (s == "getMin") {
			cin >> x;
			//cout << Q.top() << "   Debug\n";
			while (!Q.empty() && Q.top() < x) {
				Q.pop();
				Ans.push(PSI("removeMin", 0));
				//cout << "removeMin\n";
			}
			if (Q.empty() || Q.top() != x) {
				Ans.push(PSI("insert", x));
				//cout << "insert " << x << endl;
				Q.push(x);
			}
			Ans.push(PSI(s, x));
			//cout << s << ' ' << x << endl;
		} else if (s == "removeMin") {
			if (Q.empty()) {
				Ans.push(PSI("insert", 0));
				//cout << "insert 0\n";
				Q.push(0);
			}
			Q.pop();
			Ans.push(PSI("removeMin", 0));
			//cout << "removeMin\n";
		}
	}
	cout << Ans.size() << endl;
	while (!Ans.empty()) {
		s = Ans.front().fr;
		n = Ans.front().se;
		cout << s;
		if (s != "removeMin") cout << ' ' << n;
		cout << endl;
		Ans.pop();
	}
}


#include <iostream>
#include <cstdio>
#include <queue>
#include <string>
#include <vector>
using namespace std;
struct op {
    string oo;
    int num;
    op(string s, int a) {
        oo = s;
        num = a;
    }
};
queue<op> rest;
struct cmp {
    bool operator () (const int &a, const int &b) {
        return a < b;
    }
};
void solve() {
    int n;
    while (cin>>n) {
        priority_queue<int, vector<int>, greater<int> > que;
        for (int i = 0; i < n; i++) {
            string a;
            int b;
            cin>>a;
            if (a[0] != 'r') {
                cin>>b;
            }
            if (a[0] == 'i') {
                rest.push(op(a, b));
                que.push(b);
            }
            else if (a[0] == 'r') {
                if (que.empty()) {
                    rest.push(op("i", 1));
                    que.push(1);
                }
                que.pop();
                rest.push(op(a, -1));
            }
            else if (a[0] == 'g') {
                bool flag = false;
                while (!que.empty()) {
                    if (que.top() < b) {
                        rest.push(op("r", que.top()));
                        que.pop();
                    }
                    else if (que.top() == b) {
                        rest.push(op(a, b));
                        que.pop();
                        flag = true;
                        break;
                    }
                    else {
                        break;
                    }
                }
                if (flag) {
                    continue;
                }
                else {
                    rest.push(op("i", b));
                    que.push(b);
                    rest.push(op(a, b));
                    que.pop();
                }
            }
        }
        cout<<rest.size()<<endl;
        while (!rest.empty()) {
            op p = rest.front();
            rest.pop();
            if (p.oo[0] == 'i') {
                cout<<"insert "<<p.num<<endl;
            }
            else if (p.oo[0] == 'r') {
                cout<<"removeMin\n";
            }
            else if (p.oo[0] == 'g') {
                cout<<"getMin "<<p.num<<endl;
            }
        }
    }
}
int main()
{
    solve();
    return 0;
}


#include <iostream>
#include <cstdio>
#include <queue>
#include <string>
#include <vector>
using namespace std;
struct op {
    char ch;
    int num;
    op(char s, int a) {
        ch = s;
        num = a;
    }
};
vector<op> rest;
void solve() {
    int n;
    while (cin>>n) {
        priority_queue<int, vector<int>, greater<int> > que;
        for (int i = 0; i < n; i++) {
            string a;
            int b;
            cin>>a;
            if (a[0] != 'r') {
                cin>>b;
            }

            if (a[0] == 'i') {
                que.push(b);
                rest.push_back(op('i', b));
            }
            else if (a[0] == 'r') {
                if (que.empty()) {
                    que.push(1);
                    rest.push_back(op('i', 1));
                }
                que.pop();
                rest.push_back(op('r', 1));
            }
            else {
                while (!que.empty()) {
                    if (que.top() < b) {
                        rest.push_back(op('r', 1));
                        que.pop();
                    }
                    else {
                        break;
                    }
                }
                if (!que.empty() && que.top() == b) {
//                    que.pop();
                    rest.push_back(op('g', b));
                }
                else {
                    que.push(b);
                    rest.push_back(op('i', b));
//                    que.pop();
                    rest.push_back(op('g', b));
                }
            }
        }
        cout<<rest.size()<<endl;
        for (int i = 0; i < rest.size(); i++) {
            op p = rest[i];
            if (p.ch == 'i') {
                cout<<"insert "<<p.num<<endl;
            }
            else if (p.ch == 'r') {
                cout<<"removeMin\n";
            }
            else if (p.ch == 'g') {
                cout<<"getMin "<<p.num<<endl;
            }
        }
    }
}
int main()
{
    solve();
    return 0;
}


#include <iostream>
#include <cstdio>
#include <queue>
#include <string>
#include <vector>
using namespace std;
struct op {
    string oo;
    int num;
    op(string s, int a) {
        oo = s;
        num = a;
    }
};
queue<op> rest;
struct cmp {
    bool operator () (const int &a, const int &b) {
        return a < b;
    }
};
void solve() {
    int n;
    while (cin>>n) {
        priority_queue<int, vector<int>, greater<int> > que;
        for (int i = 0; i < n; i++) {
            string a;
            int b;
            cin>>a;
            if (a[0] != 'r') {
                cin>>b;
            }
            if (a[0] == 'i') {
                rest.push(op("i", b));
                que.push(b);
            }
            else if (a[0] == 'r') {
                if(que.empty())
                {
                    que.push(1);
                    rest.push(op("i",1));
                }
                que.pop();
                rest.push(op("r",0));
            }
            else if (a[0] == 'g') {
                bool flag = false;
                while (!que.empty()) {
                    if (que.top() < b) {
                        rest.push(op("r", que.top()));
                        que.pop();
                    }
                    else if (que.top() == b) {
                        rest.push(op("g", b));
                        que.pop();
                        flag = true;
                        break;
                    }
                    else {
                        break;
                    }
                }
                if (flag) {
                    continue;
                }
                else {
                    rest.push(op("i", b));
                    que.push(b);
                    rest.push(op("g", b));
                    que.pop();
                }
            }
        }
        cout<<rest.size()<<endl;
        while (!rest.empty()) {
            op p = rest.front();
            rest.pop();
            if (p.oo[0] == 'i') {
                cout<<"insert "<<p.num<<endl;
            }
            else if (p.oo[0] == 'r') {
                cout<<"removeMin\n";
            }
            else if (p.oo[0] == 'g') {
                cout<<"getMin "<<p.num<<endl;
            }
        }
    }
}
int main()
{
    solve();
    return 0;
}


#include <iostream>
#include <cstdio>
#include <queue>
#include <string>
#include <vector>
using namespace std;
struct op {
    string oo;
    int num;
    op(string s, int a) {
        oo = s;
        num = a;
    }
};
queue<op> rest;
struct cmp {
    bool operator () (const int &a, const int &b) {
        return a < b;
    }
};
void solve() {
    int n;
    while (cin>>n) {
        priority_queue<int, vector<int>, greater<int> > que;
        for (int i = 0; i < n; i++) {
            string a;
            int b;
            cin>>a;
            if (a[0] != 'r') {
                cin>>b;
            }
            if (a[0] == 'i') {
                rest.push(op("i", b));
                que.push(b);
            }
            else if (a[0] == 'r') {
                if(que.empty())
                {
                    que.push(1);
                    rest.push(op("i",0));
                }
                que.pop();
                rest.push(op("r",0));
            }
            else if (a[0] == 'g') {
                bool flag = false;
                while (!que.empty()) {
                    if (que.top() < b) {
                        rest.push(op("r", que.top()));
                        que.pop();
                    }
                    else if (que.top() == b) {
                        rest.push(op("g", b));
//                        que.pop();
                        flag = true;
                        break;
                    }
                    else {
                        break;
                    }
                }
                if (flag) {
                    continue;
                }
                else {
                    rest.push(op("i", b));
                    que.push(b);
                    rest.push(op("g", b));
//                    que.pop();
                }
            }
        }
        cout<<rest.size()<<endl;
        while (!rest.empty()) {
            op p = rest.front();
            rest.pop();
            if (p.oo[0] == 'i') {
                cout<<"insert "<<p.num<<endl;
            }
            else if (p.oo[0] == 'r') {
                cout<<"removeMin\n";
            }
            else if (p.oo[0] == 'g') {
                cout<<"getMin "<<p.num<<endl;
            }
        }
    }
}
int main()
{
    solve();
    return 0;
}


#include <iostream>
#include <cstdio>
#include <queue>
#include <string>
using namespace std;
struct op {
    string oo;
    int num;
    op(string s, int a) {
        oo = s;
        num = a;
    }
};
queue<op> rest;
struct cmp {
    bool operator () (const int &a, const int &b) {
        return a < b;
    }
};
void solve() {
    int n;
    while (cin>>n) {
        priority_queue<int, vector<int>, greater<int>> que;
        for (int i = 0; i < n; i++) {
            string a;
            int b;
            cin>>a;
            if (a[0] != 'r') {
                cin>>b;
            }
            if (a[0] == 'i') {
                rest.push(op(a, b));
                que.push(b);
            }
            else if (a[0] == 'r') {
                if (que.empty()) {
                    rest.push(op("i", 1));
                    que.push(1);
                }
                que.pop();
                rest.push(op(a, -1));
            }
            else if (a[0] == 'g') {
                bool flag = false;
                while (!que.empty()) {
                    if (que.top() < b) {
                        rest.push(op("r", que.top()));
                        que.pop();
                    }
                    else if (que.top() == b) {
                        rest.push(op(a, b));
                        que.pop();
                        flag = true;
                        break;
                    }
                    else {
                        break;
                    }
                }
                if (flag) {
                    continue;
                }
                else {
                    rest.push(op("i", b));
                    que.push(b);
                    rest.push(op(a, b));
                    que.pop();
                }
            }
        }
        cout<<rest.size()<<endl;
        while (!rest.empty()) {
            op p = rest.front();
            rest.pop();
            if (p.oo[0] == 'i') {
                cout<<"insert "<<p.num<<endl;
            }
            else if (p.oo[0] == 'r') {
                cout<<"removeMin\n";
            }
            else if (p.oo[0] == 'g') {
                cout<<"getMin "<<p.num<<endl;
            }
        }
    }
}
int main()
{
    solve();
    return 0;
}


#include <iostream>
#include <cstdio>
#include <queue>
#include <string>
#include <vector>
using namespace std;
vector<pair<char, int> > rest;
void solve() {
    int n;
    while (cin>>n) {
        priority_queue<int, vector<int>, greater<int> > que;
        for (int i = 0; i < n; i++) {
            string a;
            int b;
            cin>>a;
            if (a[0] != 'r') {
                cin>>b;
            }

            if (a[0] == 'i') {
                que.push(b);
                rest.push_back(make_pair('i', b));
            }
            else if (a[0] == 'r') {
                if (que.empty()) {
                    que.push(1);
                    rest.push_back(make_pair('i', 1));
                }
                que.pop();
                rest.push_back(make_pair('r', 1));
            }
            else {
                while (!que.empty()) {
                    if (que.top() < b) {
                        rest.push_back(make_pair('r', 1));
                        que.pop();
                    }
                    else {
                        break;
                    }
                }
                if (!que.empty() && que.top() == b) {
//                    que.pop();
                    rest.push_back(make_pair('g', b));
                }
                else {
                    que.push(b);
                    rest.push_back(make_pair('i', b));
//                    que.pop();
                    rest.push_back(make_pair('g', b));
                }
            }
        }
        cout<<rest.size()<<endl;
        for (int i = 0; i < rest.size(); i++) {
            pair<char, int> p = rest[i];
            if (p.first == 'i') {
                cout<<"insert "<<p.second<<endl;
            }
            else if (p.first == 'r') {
                cout<<"removeMin\n";
            }
            else if (p.first == 'g') {
                cout<<"getMin "<<p.second<<endl;
            }
        }
    }
}
int main()
{
    solve();
    return 0;
}


#include <iostream>
#include <cstdio>
#include <queue>
#include <string>
using namespace std;
struct op {
    string oo;
    int num;
    op(string s, int a) {
        oo = s;
        num = a;
    }
};
queue<op> rest;
struct cmp {
    bool operator () (const int &a, const int &b) {
        return a < b;
    }
};
void solve() {
    int n;
    while (cin>>n) {
        priority_queue<int, vector<int>, greater<int> > que;
        for (int i = 0; i < n; i++) {
            string a;
            int b;
            cin>>a;
            if (a[0] != 'r') {
                cin>>b;
            }
            if (a[0] == 'i') {
                rest.push(op(a, b));
                que.push(b);
            }
            else if (a[0] == 'r') {
                if (que.empty()) {
                    rest.push(op("i", 1));
                    que.push(1);
                }
                que.pop();
                rest.push(op(a, -1));
            }
            else if (a[0] == 'g') {
                bool flag = false;
                while (!que.empty()) {
                    if (que.top() < b) {
                        rest.push(op("r", que.top()));
                        que.pop();
                    }
                    else if (que.top() == b) {
                        rest.push(op(a, b));
                        que.pop();
                        flag = true;
                        break;
                    }
                    else {
                        break;
                    }
                }
                if (flag) {
                    continue;
                }
                else {
                    rest.push(op("i", b));
                    que.push(b);
                    rest.push(op(a, b));
                    que.pop();
                }
            }
        }
        cout<<rest.size()<<endl;
        while (!rest.empty()) {
            op p = rest.front();
            rest.pop();
            if (p.oo[0] == 'i') {
                cout<<"insert "<<p.num<<endl;
            }
            else if (p.oo[0] == 'r') {
                cout<<"removeMin\n";
            }
            else if (p.oo[0] == 'g') {
                cout<<"getMin "<<p.num<<endl;
            }
        }
    }
}
int main()
{
    solve();
    return 0;
}


#include <iostream>
#include <cstdio>
#include <queue>
#include <string>
#include <vector>
using namespace std;
struct op {
    string oo;
    int num;
    op(string s, int a) {
        oo = s;
        num = a;
    }
};
queue<op> rest;
struct cmp {
    bool operator () (const int &a, const int &b) {
        return a < b;
    }
};
void solve() {
    int n;
    while (cin>>n) {
        priority_queue<int, vector<int>, greater<int>> que;
        for (int i = 0; i < n; i++) {
            string a;
            int b;
            cin>>a;
            if (a[0] != 'r') {
                cin>>b;
            }
            if (a[0] == 'i') {
                rest.push(op(a, b));
                que.push(b);
            }
            else if (a[0] == 'r') {
                if (que.empty()) {
                    rest.push(op("i", 1));
                    que.push(1);
                }
                que.pop();
                rest.push(op(a, -1));
            }
            else if (a[0] == 'g') {
                bool flag = false;
                while (!que.empty()) {
                    if (que.top() < b) {
                        rest.push(op("r", que.top()));
                        que.pop();
                    }
                    else if (que.top() == b) {
                        rest.push(op(a, b));
                        que.pop();
                        flag = true;
                        break;
                    }
                    else {
                        break;
                    }
                }
                if (flag) {
                    continue;
                }
                else {
                    rest.push(op("i", b));
                    que.push(b);
                    rest.push(op(a, b));
                    que.pop();
                }
            }
        }
        cout<<rest.size()<<endl;
        while (!rest.empty()) {
            op p = rest.front();
            rest.pop();
            if (p.oo[0] == 'i') {
                cout<<"insert "<<p.num<<endl;
            }
            else if (p.oo[0] == 'r') {
                cout<<"removeMin\n";
            }
            else if (p.oo[0] == 'g') {
                cout<<"getMin "<<p.num<<endl;
            }
        }
    }
}
int main()
{
    solve();
    return 0;
}


#include <iostream>
#include <cstdio>
#include <queue>
#include <string>
#include <vector>
using namespace std;
struct op {
    string oo;
    int num;
    op(string s, int a) {
        oo = s;
        num = a;
    }
};
queue<op> rest;
struct cmp {
    bool operator () (const int &a, const int &b) {
        return a < b;
    }
};
void solve() {
    int n;
    while (cin>>n) {
        priority_queue<int, vector<int>, greater<int> > que;
        for (int i = 0; i < n; i++) {
            string a;
            int b;
            cin>>a;
            if (a[0] != 'r') {
                cin>>b;
            }
            if (a[0] == 'i') {
                rest.push(op("i", b));
                que.push(b);
            }
            else if (a[0] == 'r') {
                if (que.empty()) {
                    rest.push(op("r", -1));
                }
                else {
                    que.pop();
                    rest.push(op("r", -1));
                }
            }
            else if (a[0] == 'g') {
                bool flag = false;
                while (!que.empty()) {
                    if (que.top() < b) {
                        rest.push(op("r", que.top()));
                        que.pop();
                    }
                    else if (que.top() == b) {
                        rest.push(op("g", b));
                        que.pop();
                        flag = true;
                        break;
                    }
                    else {
                        break;
                    }
                }
                if (flag) {
                    continue;
                }
                else {
                    rest.push(op("i", b));
                    que.push(b);
                    rest.push(op("g", b));
                    que.pop();
                }
            }
        }
        cout<<rest.size()<<endl;
        while (!rest.empty()) {
            op p = rest.front();
            rest.pop();
            if (p.oo[0] == 'i') {
                cout<<"insert "<<p.num<<endl;
            }
            else if (p.oo[0] == 'r') {
                cout<<"removeMin\n";
            }
            else if (p.oo[0] == 'g') {
                cout<<"getMin "<<p.num<<endl;
            }
        }
    }
}
int main()
{
    solve();
    return 0;
}


#include <iostream>
#include <cstdio>
#include <queue>
#include <string>
using namespace std;
struct op {
    string oo;
    int num;
    op(string s, int a) {
        oo = s;
        num = a;
    }
};
queue<op> rest;
struct cmp {
    bool operator () (const int &a, const int &b) {
        return a < b;
    }
};
void solve() {
    int n;
    while (cin>>n) {
        priority_queue<int, vector<int>, cmp> que;
        int m = 0;
        for (int i = 0; i < n; i++) {
            string a;
            int b;
            cin>>a;
            if (a[0] != 'r') {
                cin>>b;
            }
            if (a[0] == 'i') {
                rest.push(op(a, b));
                que.push(b);
            }
            else if (a[0] == 'r') {
                que.pop();
                rest.push(op(a, -1));
            }
            else if (a[0] == 'g') {
                bool flag = false;
                while (!que.empty()) {
                    if (que.top() < b) {
                        rest.push(op("r", que.top()));
                        que.pop();
                    }
                    else if (que.top() == b) {
                        rest.push(op(a, b));
                        que.pop();
                        flag = true;
                        break;
                    }
                    else {
                        break;
                    }
                }
                if (flag) {
                    continue;
                }
                else {
                    rest.push(op("i", b));
                    que.push(b);
                    rest.push(op(a, b));
                    que.pop();
                }
            }
        }
        cout<<rest.size()<<endl;
        while (!rest.empty()) {
            op p = rest.front();
            rest.pop();
            if (p.oo[0] == 'i') {
                cout<<"insert "<<p.num<<endl;
            }
            else if (p.oo[0] == 'r') {
                cout<<"removeMin\n";
            }
            else if (p.oo[0] == 'g') {
                cout<<"getMin "<<p.num<<endl;
            }
        }
    }
}
int main()
{
    solve();
    return 0;
}


#include <iostream>
#include <cstdio>
#include <queue>
#include <string>
#include <vector>
using namespace std;
struct op {
    char ch;
    int num;
    op(char s, int a) {
        ch = s;
        num = a;
    }
};
queue<op> rest;
void solve() {
    int n;
    while (cin>>n) {
        priority_queue<int, vector<int>, greater<int> > que;
        for (int i = 0; i < n; i++) {
            string a;
            int b;
            cin>>a;
            if (a[0] != 'r') {
                cin>>b;
            }

            if (a[0] == 'i') {
                que.push(b);
                rest.push(op('i', b));
            }
            else if (a[0] == 'r') {
                if (que.empty()) {
                    que.push(1);
                    rest.push(op('i', 1));
                }
                que.pop();
                rest.push(op('r', 1));
            }
            else {
                while (!que.empty()) {
                    if (que.top() < b) {
                        rest.push(op('r', 1));
                        que.pop();
                    }
                    else {
                        break;
                    }
                }
                if (!que.empty() && que.top() == b) {
//                    que.pop();
                    rest.push(op('g', b));
                }
                else {
                    que.push(b);
                    rest.push(op('i', b));
//                    que.pop();
                    rest.push(op('g', b));
                }
            }
        }
        cout<<rest.size()<<endl;
        while (!rest.empty()) {
            op p = rest.front();
            rest.pop();
            if (p.ch == 'i') {
                cout<<"insert "<<p.num<<endl;
            }
            else if (p.ch == 'r') {
                cout<<"removeMin\n";
            }
            else if (p.ch == 'g') {
                cout<<"getMin "<<p.num<<endl;
            }
        }
    }
}
int main()
{
    solve();
    return 0;
}


#include <iostream>
#include <cstdio>
#include <queue>
#include <string>
#include <vector>
using namespace std;
struct op {
    string oo;
    int num;
    op(string s, int a) {
        oo = s;
        num = a;
    }
};
queue<op> rest;
struct cmp {
    bool operator () (const int &a, const int &b) {
        return a < b;
    }
};
void solve() {
    int n;
    while (cin>>n) {
        priority_queue<int, vector<int>, greater<int> > que;
        for (int i = 0; i < n; i++) {
            string a;
            int b;
            cin>>a;
            if (a[0] != 'r') {
                cin>>b;
            }
            if (a[0] == 'i') {
                rest.push(op("i", b));
                que.push(b);
            }
            else if (a[0] == 'r') {
                if(que.empty())
                {
                    que.push(1);
                    rest.push(op("i",0));
                }
                que.pop();
                rest.push(op("r",0));
            }
            else if (a[0] == 'g') {
                bool flag = false;
                while (!que.empty()) {
                    if (que.top() < b) {
                        rest.push(op("r", que.top()));
                        que.pop();
                    }
                    else if (que.top() == b) {
                        rest.push(op("g", b));
//                        que.pop();
                        flag = true;
                        break;
                    }
                    else {
                        break;
                    }
                }
                if (flag) {
                    continue;
                }
                else {
                    rest.push(op("i", b));
                    que.push(b);
                    rest.push(op("g", b));
//                    que.pop();
                }
            }
        }
        cout<<rest.size()<<endl;
        for (int i = 0; i < rest.size(); i++) {
            op p = rest.front();
            rest.pop();
            if (p.oo[0] == 'i') {
                cout<<"insert "<<p.num<<endl;
            }
            else if (p.oo[0] == 'r') {
                cout<<"removeMin\n";
            }
            else if (p.oo[0] == 'g') {
                cout<<"getMin "<<p.num<<endl;
            }
        }
    }
}
int main()
{
    solve();
    return 0;
}


#include<iostream>
#include <cmath>
#include<cstdio>
#include <string>
#include <cwchar>
#include <stdio.h>
#include <ctype.h>
#include <string>
#include <algorithm>
#include <map>
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int main(){
  FAST;
  int a[4]={0},cal=0; string b;
  cin>>a;
  cin>>b;
  for(int i=0;i<b.size();i++){
    cal += a[b[i]];
  }
  return 0;
}


#include<iostream>
#include <cmath>
#include<cstdio>
#include <string>
#include <cwchar>
#include <stdio.h>
#include <ctype.h>
#include <string>
#include <algorithm>
#include <map>
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int main(){
  FAST;
  int a[4]={0},cal=0; string b;
  cin>>a;
  cin>>b;
  for(int i=0;i<b.size();i++){
    cal += a[b[i]-1];
  }
  return 0;
}


#include <bits/stdc++.h>

/* namespace my {{{*/
namespace my {
   typedef uint32_t u32;
   typedef uint64_t u64;
   typedef int32_t i32;
   typedef int64_t i64;
   /* namespace math {{{*/
   namespace math {
      const double EPS = 1e-9;

      bool eq(double a, double b, double eps = EPS) {
         return std::fabs(a - b) < eps;
      }

      template<class T>
      bool isOdd(T a) {
         return a & 1;
      }

      template<class T>
      bool isZero(T a) {
         return !a;
      }

      template<class T>
      T sq(T a) {
         return a * a;
      }

      template<class T>
      std::tuple<T, bool> sqrt(T n) {
         u64 b = 0;
         u64 e = n;
         u64 mid = b/2 + e/2;
         u64 cnt = 0;
         u64 midSq = sq(mid);
         while(midSq != n) {
            if(++cnt > 30) return std::make_tuple(0, false);
            if(midSq < n) b = mid + 1;
            else e = mid - 1;
            mid = (b+e)/2;
            midSq = sq(mid);
         }
         return std::make_tuple(mid, true);
      }

      template<class T>
      T upow(T base, T exponent) {
         if(exponent < 0) throw "exponent shouldn't be less than 0";
         if(isZero(exponent)) return 1;
         T r = base;
         T e = 1;
         while(2*e <= exponent) {
            r *= r;
            e *= 2;
         }
         if(isOdd(exponent)) r *= base;
         return r;
      }
      const long double pi = 3.141592653589793238462643383;
   };
   /*}}}*/
   namespace base {

      struct Debugger {
      private:
         std::ostream& errorStream;
      public:
         Debugger(std::ostream& es_) : errorStream(es_) {};
         template<class T>
         void operator()(T o) {
            errorStream << o;
         }
         template<class T, class... Args>
         void operator()(T o, Args... args) {
            #ifdef DEBUG
               errorStream << o;
               this->operator()(args...);
            #endif
         }
      };
   };
   namespace iter {
      template<class Seq, class F>
      void each(Seq s, F f) {
         for(auto it = s.begin(); it != s.end(); ++it) f(*it);
      }

      template<class Seq, class F>
      void foreach(Seq& s, F f) {
         for(auto it = s.begin(); it != s.end(); ++it) f(*it);
      }

      template<class Seq, class T, class F>
      T foldl(Seq s, T initVal, F f) {
         return std::accumulate(s.begin(), s.end(), initVal, f);
      }

      template<class F>
      void times(uint64_t t, F f) {
         while(t--) f();
      }

      template<class T>
      struct Range {
         T i, e;
         Range(T b, T e_) : i(b), e(e_) {};
         Range<T> begin() { return *this; };
         Range<T> end() { return Range<T>(e,e); };
         T operator*() { return i; };
         Range<T>& operator++() {
            ++i;
            return *this;
         }
         bool operator==(Range<T> o) { return o.i == i and o.e == e; };
         bool operator!=(Range<T> o) { return not(*this == o); };
      };

      template<class T>
      Range<T> rng(T b, T e) {
         return Range<T>(b, e);
      }
   };
   namespace io {
      template<class T>
      T get() {
         T o;
         std::cin >> o;
         return o;
      }

      template<class T>
      void get(T& o) {
         std::cin >> o;
      }

      template<class T>
      void print(T o) {
         std::cout << o;
      }

      template<class T, class... Args>
      void print(T o, Args... args) {
        std::cout << o;
        print(args...);
      }

      template<class T>
      void println(T o) {
         std::cout << o << '\n';
      }

      template<class T, class... Args>
      void println(T o, Args... args)  {
         std::cout << o;
         println(args...);
      }
   };
   namespace extra {
      void printlnBool(bool b) {
         io::println(b ? "YES" : "NO");
      }
   }
};
/*}}}*/

using namespace my;
using namespace base;
using namespace iter;
using namespace io;
using namespace math;
using str = std::string;

#define fn(T, code) ([&](T _) { code ; })

void start(Debugger d) {
	u32 a[4];
	for(auto& it : a) get(it);
	str inp = get<str>();
	u64 cnt = 0;
	for(auto c : inp) cnt += a[c - '1'];
	println(cnt);
}

int main() {
   std::ios_base::sync_with_stdio(false);
   std::cin.tie(0);

   auto d = Debugger(std::cerr);

   start(d);

   return 0;
}


#include<iostream>
#include <cmath>
#include<cstdio>
#include <string>
#include <cwchar>
#include <stdio.h>
#include <ctype.h>
#include <string>
#include <algorithm>
#include <map>
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int main(){
  FAST;
  int a[4]={0},cal=0; string b;
  for(int i=0;i<4;i++) cin>>a[i];
  cin>>b;
  for(int i=0;i<b.size();i++)   cal += a[(int)b[i]-49];

  cout<<cal;
  return 0;
}


#include<iostream>
#include <cmath>
#include<cstdio>
#include <string>
#include <cwchar>
#include <stdio.h>
#include <ctype.h>
#include <string>
#include <algorithm>
#include <map>
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int main(){
  FAST;
  int a[4]={0},cal=0; string b;
  for(int i=0;i<4;i++) cin>>a[i];
  cin>>b;
  for(int i=0;i<b.size();i++){
    cal += a[b[i]-1];
  }
  return 0;
}


#include<iostream>
#include <cmath>
#include<cstdio>
#include <string>
#include <cwchar>
#include <stdio.h>
#include <ctype.h>
#include <string>
#include <algorithm>
#include <map>
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int main(){
  FAST;
  int a[4]={0},cal=0; string b;
  for(int i=0;i<4;i++) cin>>a[i];
  cin>>b;
  for(int i=0;i<b.size();i++)   cal += a[b[i]-'1'];

  cout<<cal;
  return 0;
}


#include <iostream>
#include<string>
using namespace std;

int main()
{
    int arr[4];
    int cnt=0;
    for(int i=0;i<4;i++)
    {
        cin>>arr[i];
    }
    string s;
    cin>>s;

    for(int i=0;i<s.size();i++)
    {
        cnt+=arr[s[i]-49];
    }
    cout<<cnt;

}


#include <iostream>
#include<string>
using namespace std;

int main()
{
    int arr[4];
    int cnt=0;
    for(int i=0;i<4;i++)
    {
        cout<<"enter the cal of "<<i<<"square :";
        cin>>arr[i];
    }
    string s;
    cin>>s;

    for(int i=0;i<s.size();i++)
    {
        cnt+=arr[s[i]-49];
    }
    cout<<cnt;

}


#include <iostream>
#include<string>
using namespace std;

int main()
{
    int arr[4];
    int cnt=0;
    for(int i=0;i<4;i++)
    {
        cin>>arr[i];
    }
    string s;
    cin>>s;

    for(int i=0;i<s.size();i++)
    {
        cnt+=arr[s[i]-'1'];
    }
    cout<<cnt;
    return 0;

}


#include<bits/stdc++.h>
using namespace std;
string s;
long long a1,a2,a3,a4,ans=0;
int main(){
	cin>>a1>>a2>>a3>>a4;
	cin>>s;
	for(int i=0;i<sizeof(s);i++)
	{
		if(s[i]=='1')
		ans+=a1;
		if(s[i]=='2')
		ans+=a2;
		if(s[i]=='3')
		ans+=a3;
		if(s[i]=='4')
		ans+=a4;
	}
	cout<<ans;
}


#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
char s[100005];
int a[4];
int main()
{
	scanf("%d%d%d%d",&a[1],&a[2],&a[3],&a[4]);
	cin>>s;
	int n;
	n=strlen(s)+1;
	long long sum=0;
	for(int i=0;i<n;i++)
	sum+=a[s[i]-'0'];
	printf("%lld",sum);
	return 0;
}


#include <iostream>
#include <cstring>
using namespace std;
int main() {
	int a[5], ans = 0;
	string s;
	cin >> a[1] >> a[2] >> a[3] >> a[4];
	cin >> s;
	for(int i = 0; i < s.length(); i++)
	ans += a[s[i] - '0'];
	cout << ans << endl;
	return 0;
}


#include<bits/stdc++.h>
 using namespace std;
  int a[4],ans=0;
  string s;
  int main()
  {
      for(int i=0;i<4;i++){
      	cin>>a[i];
	  }
      cin>>s;
      for(int i=0;i<s.length();++i) ans+=a[s[i]-'0'-1];
      cout<<ans<<endl;
      return 0;
  }


#include<bits/stdc++.h>
using namespace std;
int a[4],ans=0;
string s;
int main()
{
    cin>>a[1]>>a[2]>>a[3]>>a[4]>>s;
    for(int i=0;i<s.length();++i)
		ans+=a[s[i]-'0'];
    cout<<ans<<endl;
}


#include<bits/stdc++.h>
 using namespace std;
  int a[4],ans=0;
  string s;
  int main()
  {
      for(int i=0;i<4;i++){
      	cin>>a[i];
	  }
      cin>>s;
      for(int i=0;i<s.length();++i) ans+=a[s[i]-'0'];
      cout<<ans<<endl;
      return 0;
  }


#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int a[5],ans=0;
string input;
int main(){
	scanf("%d%d%d%d",&a[1],&a[2],&a[3],&a[4]);
	cin>>input;
	for(int i=0;i<input.length();i++){
		ans+=a[input[i]-'0'];
	}
	printf("%d",ans);
	return 0;
}


#include<iostream>
#include<cmath>
#include<string>
using namespace std;
int main(){
    int a[4],ans=0;
    string b;
    cin>>a[0]>>a[1]>>a[2]>>a[3]>>b;
    for(int i=0;i<b.size();i++)
        ans+=a[int(b[i])-49];
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a[4],ans=0;
string s;
int main(){
    cin>>a[1]>>a[2]>>a[3]>>a[4];
    cin>>s;
    for(int i=0;i<s.size();i++) ans+=a[s[i]-'0'];
    cout<<ans;
    return 0;
}


#include<iostream>
using namespace std;
int main(){
    int f[5],s=0;
    char c;
    cin>>f[1]>>f[2]>>f[3]>>f[4];
    while(cin>>c)
        s+=f[c-'0'];
    cout<<s;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,d,ans=0,i=1;
	char x;
	cin>>a>>b>>c>>d;
	while(cin>>x)
	{
		switch(x)
		{
			case 31:ans+=a;break;
			case 32:ans+=b;break;
			case 33:ans+=c;break;
			case 34:ans+=d;break;
		}
	}
	cout<<ans;
}


#include <bits/stdc++.h>
using namespace std;
int a[5], ans=0;
string s;
int main (){
	for(int i=0;i<4;i++) cin>>a[i];
	getline(cin,s);
	for(int i=0;i<s.size();i++) ans+=a[s[i]-'0'-1];
	cout<<ans<<endl;
	return 0;
}


#include <iostream>
#include <cstring>
using namespace std;
int s[5];
int sum=0;
string a;
int main()
{
	for(int i=1;i<=4;i++)
	{
		cin>>s[i];
	}
	getchar();
	getline(cin,a);
	for(int i=0;i<a.size();i++)
	{
		sum+=s[a[i]-'0'];
	}
	cout<<sum<<endl;
}


#include<bits/stdc++.h>
using namespace std;
int a,b,c,d,ans;
string s;
int main()
{
    cin>>a>>b>>c>>d>>s;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]-'0'==1){ans+=a;}
        if(s[i]-'0'==2){ans+=b;}
        if(s[i]-'0'==3){ans+=c;}
        if(s[i]-'0'==4){ans+=d;}
    }
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a,b,c,d,ans;
string s;
int main()
{
    cin>>a>>b>>c>>d>>s;
    for(int i=0;i<s.size();i++)
        switch(s[i]-'0')
		{
            case 1:
			{
				ans+=a;break;
			}
            case 2:
			{
				ans+=b;break;
			}
            case 3:
			{
				ans+=c;break;
			}
            case 4:
			{
				ans+=d;break;
			}
        }
    cout<<ans;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
string ss;
int s[4],i,ans;
int main(){
cin>>ss;
for(i=0;i<4;i++) cin>>s[i];
for(i=0;i<s.size();i++) ans+=s[ss[i]-'1'];
cout<<ans;
return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
int main(){
	int s[4],m=0;
	int k;
	for(int i=0;i<4;i++){
		scanf("%d",&s[i]);
	}
	scanf("%d",&k);
	while(k){
		m+=s[k%10-1];
		k/=10;
	}
	printf("%d",m);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int a[5],ans,l;
char ch[100005];
int main()
{
    scanf("%d%d%d%d",&a[1],&a[2],&a[3],&a[4]);
    scanf("%s",ch);
    l=strlen(ch);
    for(int i=0;i<l;i++)
        ans+=a[ch[i]-'0'];
    printf("%d",ans);
    return 0;
}


#include<iostream>
#include<cstring>
#include<queue>
#include<cstdlib>
#include<utility>
#include<vector>
#include<cmath>
#include<stack>
using namespace std;
typedef long long ll;
int main()
{
	int a[4],sum=0;
	cin>>a[0]>>a[1]>>a[2]>>a[3];
	string v;
	cin>>v;
	int c=v.size();
	for(int q=0;q<c;q++)
	{
		sum+=a[v[q]-'1'];
	}
	cout<<sum;
}


#include <cstdio>
using namespace std;
int main()
{
	int i,a,b,c,d,sum=0;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	char x[10001];
	scanf("\n");
	for(i=1;i<=10000;i++)
	{
		scanf("%c",&x[i]);
		if(x[i]=='1') sum+=a;
		if(x[i]=='2') sum+=b;
		if(x[i]=='3') sum+=c;
		if(x[i]=='4') sum+=d;
		if(x[i]=='\n') break;
	}
	printf("%d",sum);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
 int a[4],ans;
 string s;
 int main(void){
      cin>>a[1]>>a[2]>>a[3]>>a[4];
      cin>>s;
      for(int i=0;i<s.size();++i) ans+=a[s[i]-'0'];
      cout<<ans<<"\r";
 }


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

char s[100010];

int main(){
	int s1,s2,s3,s4,ans=0; scanf("%d%d%d%d%s",&s1,&s2,&s3,&s4,s);
	int len=strlen(s);
	for(int i=0;i<len;i++){
		switch(s[i]){
			case('1'):{
				ans+=s1;
				break;
			}
			case('2'):{
				ans+=s2;
				break;
			}
			case('3'):{
				ans+=s3;
				break;
			}
			case('4'):{
				ans+=s4;
				break;
			}
		}
	}
	printf("%d",ans);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
string ss;
int s[4],i,ans;
int main(){
for(i=0;i<4;i++) cin>>s[i];
cin>>ss;
for(i=0;i<ss.size();i++) ans+=s[ss[i]-'1'];
cout<<ans;
return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a[4];
char s[100005];
int main(){
	for(int i=1;i<=4;i++)scanf("%d",&a[i]);
	scanf("%s",s);
	//printf("%d %d %d %d\n",a[1],a[2],a[3],a[4]);
	//printf("%s",s);
	//printf("%d",a[4]);
	int l=strlen(s);
	int sum=0;
	for(int i=0;i<l;i++){
		sum+=a[s[i]-'0'];
		//printf("%d:%d %d %d\n",i+1,sum,s[i]-'0',a[s[i]-'0']);
	}
	printf("%d",sum);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a,b,c,d,ans;
string s;
int main()
{
    cin>>a>>b>>c>>d>>s;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]-'0'==1){ans+=a;break;}
        if(s[i]-'0'==2){ans+=b;break;}
        if(s[i]-'0'==3){ans+=c;break;}
        if(s[i]-'0'==4){ans+=d;break;}
    }
    cout<<ans;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int ans,a[5];
char x;
int main()
{
    cin>>a[1]>>a[2]>>a[3]>>a[4];
    while(cin>>x)
    {
        ans+=a[x-48];
    }
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a[4],ans=0;
string s;
int main()
{
      scanf("%d%d%d%d",&a[1],&a[1],&a[1],&a[1]);
      cin>>s;
      for(int i=0;i<s.length();++i) ans+=a[s[i]-'0'];
      printf("%d",ans);
      return 0;
}


#include<bits/stdc++.h>
using namespace std;
char a[10001];int s=0,k[5];
int main(){
	for(int i=1;i<=4;i++)
	cin>>k[i];
	cin>>a;
	for(int i=0;i<=strlen(a)-1;i++)
	s+=k[a[i]-'0'];
	cout<<s;
	return 0;
}


#include<bits/stdc++.h>
 using namespace std;
  int a[4],ans=0;
  string s;
  int main()
  {
      cin>>a[1]>>a[2]>>a[3]>>a[4];
      cin>>s;
      for(int i=0;i<s.length();++i) ans+=a[s[i]-'0'];
      cout<<ans<<endl;
      return 0;
  }


#include<bits/stdc++.h>
using namespace std;
int a[11],ans=0;
string s;
int main()
{
    cin>>a[1]>>a[2]>>a[3]>>a[4];
    cin>>s;
    for(int i=0;i<s.length();++i)
	ans+=a[s[i]-'0'];
    cout<<ans<<endl;
    return 0;
}


#include<iostream>
using namespace std;
int main(){
	int a,b,c,d,sum=0;
	cin>>a>>b>>c>>d;
	string s;
	cin>>s;
	for(int i=0;i<s.length();i++){
		if(s[i]=='1') sum+=a;
		else if(s[i]=='2') sum+=b;
		else if(s[i]=='3') sum+=c;
		else if(s[i]=='4') sum+=d;
	}
	cout<<sum;
    return 0;
}


#include<iostream>
#include<cstring>
using namespace std;\
char x[100000];
int main()
{
    int n,a,b,c,d,e=0;
    cin>>a>>b>>c>>d;
    cin>>x;
    n=strlen(x);
    for(int i=0;i<n;i++)
    {
		if(x[i]=='1')e+=a;
		else if(x[i]=='2')e+=b;
		else if(x[i]=='3')e+=c;
		else if(x[i]=='4')e+=d;
	}
	cout<<e<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a[4],k=0,i;
char s[100005];
int main()
{
	cin>>a[0]>>a[1]>>a[2]>>a[3];
	getchar();
	gets(s);
	for(int i=0;i<strlen(s);i++)
    {
        int n=s[i]-'0'-1;
        k+=a[n];
    }
    cout<<k;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int n=4;
int ans,a[n+1];
string s;
int main()
{
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	cin>>s;
	for(int i=0;i<s.size();i++)
		ans+=a[s[i]-'0'];
	printf("%d",ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a[5],sum;
string s;
int main(){
	for(int i=1;i<=4;i++){
		cin>>a[i];
	}
	cin>>s;
	for(int i=0,j;i<s.length();i++){
		sum+=a[s[i]-'0'];
	}
	cout<<sum;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
	int a[5];
	for(int i=1;i<5;i++)
		cin>>a[i];

	string s;
	cin>>s;

	int sum=0;
	for(int i=0;i<s.length();i++)
		sum+=a[s[i]-'0'];

	cout<<sum;
}


#include"bits/stdc++.h"
using namespace std;
int main(){
	int l1,l2,l3,l4,sum=0;
	char a;
	cin>>l1>>l2>>l3>>l4;
	while(1){
		cin>>a;
		if(a=='1')sum+=l1;
		if(a=='2')sum+=l2;
		if(a=='3')sum+=l3;
		if(a=='4')sum+=l4;
		if(a=='\n'){cout<<sum;return 0;}
	}
}


#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
long long a,b,c,d;
long long ans=0;
string A;
int main()
{
	scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
	getchar();
	getline(cin,A);
	for(int i=0;i<A.size();i++)
	{
		if(A[i]=='1')ans+=a;
		else if(A[i]=='2')ans+=b;
		else if(A[i]=='3')ans+=c;
		else ans+=d;
	}
	printf("%lld",ans);
	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;

const int MAXN=1e6+5;

int Ans,Len;
int A[15];
char Str[MAXN];

int main(){

	scanf("%d%d%d%d",&A[1],&A[2],&A[3],&A[4]);
	scanf("%s",Str);
	Len=strlen(Str);
	for(int i=0;i<Len;i++){
		Ans=Ans+A[Str[i]^48];
	}

	printf("%d\n",Ans);

	return 0;

}


#include<bits/stdc++.h>
using namespace std;
int makeup(string s,int a,int b,int c,int d){
	int sum;
	while(s.find("1")!=string::npos){
		sum+=a;
		s.erase(s.find("1"),1);
	}
	while(s.find("2")!=string::npos){
		sum+=b;
		s.erase(s.find("2"),1);
	}
	while(s.find("3")!=string::npos){
		sum+=c;
		s.erase(s.find("3"),1);
	}
	while(s.find("4")!=string::npos){
		sum+=d;
		s.erase(s.find("4"),1);
	}
	return sum;
}
int main(){
	string s;
	int a,b,c,d;
	scanf("%d %d %d %d",&a,&b,&c,&d);
	scanf("%s",&s);
	cout<<makeup(s,a,b,c,d);
	return 0;
}


#include<iostream>
#include<cstring>
using namespace std;
int main()
{
	int x1,x2,x3,x4;
	cin>>x1>>x2>>x3>>x4;
	string s;
	cin>>s;
	int n=s.length();
	int tot1=0;
	for(int i=0;i<n;i++)
	{
		if(s[i]=='1')
		{
			tot1+=x1;
			continue;
		}
		if(s[i]=='2')
		{
			tot1+=x2;
			continue;
		}
		if(s[i]=='3')
		{
			tot1+=x3;
			continue;
		}
		if(s[i]=='4')
		{
			tot1+=x4;
			continue;
		}
	}
	cout<<tot1<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int s1,s2,s3,s4;
string s;
int main(){
	cin>>s1>>s2>>s3>>s4>>s;
	int n=s.size();
	int ss=0;
	for(int i=0;i<n;i++){
		if(s[i]-'0'==1)ss+=s1;
		if(s[i]-'0'==2)ss+=s2;
		if(s[i]-'0'==3)ss+=s3;
		if(s[i]-'0'==4)ss+=s4;
	}
	cout<<ss;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
long long a,b,c,d,ans;
char s;
int main()
{
	cin >> a >> b >> c >> d;
	while (cin >> s)
		{
			if (s == '1') ans += a;
			if (s == '2') ans += b;
			if (s == '3') ans += c;
			if (s == '4') ans += d;
		}
	cout << ans << endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a[4],ans;
string s;
int main()
{
    cin>>a[1]>>a[2]>>a[3]>>a[4];
    cin>>s;
    for(int i=0;i<s.length();i++)
		ans+=a[s[i]-'0'];
	cout<<ans<<endl;
    return 0;
}


#include<stdio.h>
#include<ctype.h>
int a[10],res;
char c;
int main()
{
    scanf("%d%d%d%d",&a[0],&a[1],&a[2],&a[3]);
    c=getchar();
    for(;!isdigit(c);c=getchar());
    for(;isdigit(c);c=getchar()) res+=a[c-49];
    printf("%d\n",res);
    return 0;
}


#include<cstdio>
#include<cstring>
char a[100005];
int v[5],s;
int main(){
    scanf("%d%d%d%d",&v[1],&v[2],&v[3],&v[4]);
    scanf("%s",&a);
    for(int i=1;i<strlen(a);i++){
        s+=v[a[i]-'0'];
    }
    printf("%d\n",s);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a[4],c=0;
	scanf("%d%d%d%d",&a[0],&a[1],&a[2],&a[3]);
	char b[1000];
	scanf("%s",b);
	int x=strlen(b)
	for(int i=0;i<x;i++){
		c+=a[b[i]-'1'];
	}
	printf("%d",c);
    return 0;
}


#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int main()
{
	int a[4];
	scanf("%d %d %d %d",&a[0],&a[1],&a[2],&a[3]);
	string aa;
	cin>>aa;int num=0;
	for(int i=0;i<aa.size();i++)
	{
		num+=a[aa[i]-'0'-1];
	}
	return !printf("%d\n",num);
}


#include<bits/stdc++.h>
using namespace std;
long long b[4],sum=0;
string s;
int main(){
      cin>>b[1]>>b[2]>>b[3]>>b[4];
      cin>>s;
      for(int i=0;i<s.length();i++)
            sum+=b[s[i]-'0'];
      cout<<sum<<endl;
      return 0;

}


#include<bits/stdc++.h>
using namespace std;
int main(){
	bool f=1;
	int l1,l2,l3,l4,sum=0;
	string a;
	scanf("%d%d%d%d\n",&l1,&l2,&l3,&l4);
	cin>>a;
	for(int i=0;i<a.size();i++){
		if(a[i]=='1')sum+=l1;
		if(a[i]=='2')sum+=l2;
		if(a[i]=='3')sum+=l3;
		if(a[i]=='4')sum+=l4;
	}
	printf("%d",sum);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main() {
	int a[4],b,ans=0;
	for(int i=0; i<4; i++)
		cin>>a[i];
	string s;
	cin>>s;
	for(int i=0; i<s.size(); i++) {
		b=s[i]-'0';
		ans+=a[b-1];
	}
	cout<<ans<<endl;
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
int main()
{
	int a1,a2,a3,a4,s=0;
	char a[100001];
	cin>>a1>>a2>>a3>>a4;
	cin>>a;
	for(int i=0;i<strlen(a);i++)
	{
		if(a[i]=='1')
		{
			s+=a1;
		}
		else if(a[i]=='2')
		{
			s+=a2;
		}
		else if(a[i]=='3')
		{
			s+=a3;
		}
		else if(a[i]=='4')
		{
			s+=a4;
		}
	}
	cout<<s<<endl;
	return 0;
}


#include<cmath>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
char ch[100005];
int main()
{
	int a,b,c,d;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	cin>>(ch+1);
	int len=strlen(ch+1);
	int ans=0;
	for(int i=1;i<=len;i++)
	{
		if(ch[i]=='1')
		ans+=a;
		else
		if(ch[i]=='2')
		ans+=b;
		else
		if(ch[i]=='3')
		ans+=c;
		else
		ans+=d;
	}
	printf("%d\n",ans);
	return 0;
}


#include<iostream>
#include<cstdlib>
#include<cstring>
using namespace std;
int a[5];
#define N 10001
#define LL long long
int main(void)
{
	for (LL i = 1; i <= 4; i++)
	{
		cin >> a[i];
	}
	char ch[N];
	getchar();
	cin >> ch;
	LL sum = 0;
	for (LL i = 0; i < strlen(ch); i++)
	{
		sum += a[ch[i] - '0'];
	}
	cout << sum;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a[5],n,s=0;
	char c;
	cin>>a[1]>>a[2]>>a[3]>>a[4];
	while(cin>>c)
	{
		s=s+a[c-48];
	}
	cout<<s;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int sum=0;
    int a[14];
    string s;
    for(int i=1;i<=4;i++){
    	cin>>a[i];
	}
    cin>>s;
    int len=s.size();
    for(int i=0;i<=len;i++){
    	if(s[i]=='1'){
    		sum=a[1]+sum;
		}
		if(s[i]=='2'){
    		sum=a[2]+sum;
		}
		if(s[i]=='3'){
    		sum=a[3]+sum;
		}
		if(s[i]=='4'){
    		sum=a[4]+sum;
		}
	}
	cout<<sum;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a[4],x;
string s;
int main()
{
    for(int i=0; i<4; i++)
        cin>>a[i];
    cin>>s;
    for(int i=0; i<s.size(); i++)
        x+=a[s[i]-49];
    cout<<x;
    return 0;
}


#include<bits/stdc++.h>
 using namespace std;
  int a[4],ans=0;
  string s;
  int main()
  {
      cin>>a[1]>>a[2]>>a[3]>>a[4]; //输入
      cin>>s;
      for(int i=0;i<s.length();++i) ans+=a[s[i]-'0']; //累加
      cout<<ans<<endl;
      return 0;
  }


#include<bits/stdc++.h>
using namespace std;
int a,b,c,d,sum,i;
long long m[1001][1001],l[1001][1001];
char s[100001];
int main()
{
	cin>>a>>b>>c>>d;
	gets(s);
	for(i=0;i<strlen(s);i++)
	{
		if(s[i]==a)
		{
			sum+=a;
		}
		if(s[i]==b)
		{
			sum+=b;
		}
		if(s[i]==c)
		{
			sum+=c;
		}
		if(s[i]==d)
		{
			sum+=d;
		}
	}
	cout<<sum;
	return 0;
}


#include <iostream>
#include <cstring>
using namespace std;
int ans,a[5];
string str;
int main()
{
    for(int i=1;i<=4;i++) cin>>a[i];
    cin>>str;
    for(int i=0;i<str.size();i++)
    {
        char ch=str[i];
        ans+=a[int(ch)-48];
    }
    cout<<ans;
    return 0;
}


#include <iostream>
#include <cstring>
using namespace std;
int a[5],sum=0;
char s[100000];
int main()
{
	cin>>a[1]>>a[2]>>a[3]>>a[4];
	cin>>s;
	int len=strlen(s);
	for (int i=0;i<len;i++)
		sum=sum+a[(s[i]-48)];
	cout<<sum<<endl;
	return 0;
}


#include<iostream>
using namespace std;
int main(){
	int a1,a2,a3,a4;
	cin>>a1>>a2>>a3>>a4;
	char a[100001];
	cin>>a;
	int cal=0;
	for(int i=0;i<100001;i++){
		if(a[i]==0)break;
		if(a[i]==49)cal+=a1;
		if(a[i]==50)cal+=a2;
		if(a[i]==51)cal+=a3;
		if(a[i]==52)cal+=a4;
	}
	cout<<cal;
}


#include<bits/stdc++.h>
using namespace std;
inline int read()
{
    char ch=getchar();
    int f=1;
    while(ch<'0'||ch>'9')
    {
        if(ch=='-')f=-1;
        ch=getchar();
    }
    int x=0;
    while(ch>='0'&&ch<='9')
    {
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}
map<char,int> ma;
int main()
{
    for(int i=1;i<5;++i)
        ma[i+'0']=read();
    char s[100010];
    scanf("%s",s);
    int n=strlen(s),sum=0;
    for(int i=0;i<n;++i)
        sum+=ma[s[i]];
    printf("%d\n",sum);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a[4],ans=0;
string s;
int main()
{
    cin>>a[1]>>a[2]>>a[3]>>a[4];
    cin>>s;
    for(int i=0;i<s.length();i++)ans+=a[s[i]-'0'];
    cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c,d,len;
	unsigned long long ans=0;
	cin>>a>>b>>c>>d;
	string s;
	cin>>s;
	len=s.length();
	for(int i=0;i<len;i++)
	{
		if(s[i]=='1') ans+=a;
		if(s[i]=='2') ans+=b;
		if(s[i]=='3') ans+=c;
		if(s[i]=='4') ans+=d;
	}
	cout<<ans<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a[1000],sum=0,c;
string s;
int main()
{
      cin>>a[1]>>a[2]>>a[3]>>a[4]; //输入
      cin>>s;
      for(int i=0;i<s.size();++i) sum+=a[s[i]-'0']; //累加
      cout<<sum<<endl;
	return 0;
}
//jfjghjdhewrtyuuiuop


#include<bits/stdc++.h>
 using namespace std;
  int a[4],ans=0;
  string s;
  int main()
  {
      cin>>a[1]>>a[2]>>a[3]>>a[4];
      cin>>s;
      for(int i=0;i<s.length();++i) ans+=a[s[i]-'0'];
      cout<<ans<<endl;
      return 0;
  }


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
int n,a[5],l;
char c[100100];
long long krl;
int main(){
	for(int i=1;i<=4;i++){
		cin>>a[i];
	}
	cin>>c;
	l=strlen(c);
	for(int i=0;i<l;i++){
		int sum=c[i]-'0';
		krl+=a[sum];
	}
	cout<<krl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,d,ans=0;
    string s;
    cin>>a>>b>>c>>d;
    cin.get();
    getline(cin,s);
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='1')ans+=a;
        else if(s[i]=='2')ans+=b;
        else if(s[i]=='3')ans+=c;
        else ans+=d;
    }
    cout<<ans<<endl;
    return 0;
}


#include<cstdio>
#include<iostream>

using namespace std;

int a[5],ans;
char ch;

int main()
{
	for(int i=1;i<=4;i++)scanf("%d",&a[i]);
	while(ch<'1'||ch>'4')ch=getchar();
	while(ch>='1'&&ch<='4')
	{
		ans+=a[ch-'0'];
		ch=getchar();
	}
	printf("%d\n",ans);
	return 0;
}


#include <cstdio>
#include <iostream>
using namespace std;
int main()
{
	int a[4];
	string s;
	int sum;
	cin >> a[0] >> a[1] >> a[2] >> a[3];
	cin >> s;
	for (int i=0;i<s.length();i++)
	{
		sum+=a[s[i]-'1'];
	}
	cout << sum;

	return 0;
}


#include <iostream>
#include <cstring>
using namespace std;
int main() {
int a[4];
string s;
int64_t res=0;

    for(int i=0;i<4;i++) cin>>a[i];
    cin>>s;
    int n=s.size();
    for(int it=0;it<n;it++)
        res+=a[(it-'0')-1];
    cout<<res;

    return 0;
}


#include <iostream>
#include <cstring>
using namespace std;
char s[100001];
int a,b,c,d,ct;
int main()
{
    cin>>a>>b>>c>>d;
    cin>>s;
if(a==b && b==c && c==d && c==0)
cout<<"0";
else
    {for(int i=0; i<strlen(s); i++)
        if(s[i]=='1')
            ct+=a;
        else if(s[i]=='2')
            ct+=b;
        else if(s[i]=='3')
            ct+=c;
        else
            ct+=d;
    cout<<ct;
}
}


#include <iostream>
#include <cstring>
using namespace std;
int main() {
int a[4];
string s;
int64_t res=0;

    for(int i=0;i<4;i++) cin>>a[i];
    cin>>s;
    int n=s.size();
    for(int it=0;it<n;it++)
        res+=a[s[it]-'0'-1];
    cout<<res;

    return 0;
}


#include <iostream>
#include <cstring>
using namespace std;
char s[10001];
int a,b,c,d,ct;
int main()
{
    cin>>a>>b>>c>>d;
    cin>>s;
    for(int i=0; i<strlen(s); i++)
        if(s[i]=='1')
            ct+=a;
        else if(s[i]=='2')
            ct+=b;
        else if(s[i]=='3')
            ct+=c;
        else
            ct+=d;
    cout<<ct;
}


#include <iostream>
#include <cstring>
using namespace std;
char s[100001];
int64_t ct;
int64_t a[4];
int main()
{
    cin>>a[0]>>a[1]>>a[2]>>a[3];
    cin>>s;

    for(int i=0; i<strlen(s); i++)
        ct+=a[s[i]-'0'-1];
    cout<<ct;
}


#include <iostream>
#include <cstring>
using namespace std;
char s[100001];
int64_t a,b,c,d,x,y,z,t;
int main()
{
    cin>>a>>b>>c>>d;
    cin>>s;
if(a==b && b==c && c==d && c==0)
cout<<"0";
else
    {for(int i=0; i<strlen(s); i++)
        if(s[i]=='1')
           x++;
        else if(s[i]=='2')
            y++;
        else if(s[i]=='3')
            z++;
        else
            t++;
    cout<<x*a+y*b+c*z+t*d;
}
}


#include<iostream>
#include<cstring>
using namespace std;
char s[10001];
int a,b,c,d,ct;
{
cin>>a>>b>>c>>d;
cin>>s;
for(int i=0;i<strlen(s);i++)
if(s[i]=='1')
ct+=a;
else
if(s[i]=='2')
ct+=b;
else
if(s[i]=='3')
ct+=c;
else
ct+=d;
cout<<ct;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,d,i,j,n=0;
    char ch[100];
    cin>>a>>b>>c>>d;
    getchar();
    gets(ch);
    int l=strlen(ch);
    for(i=0;i<l;i++)
    {
        if(ch[i]=='1') n+=a;
        else if(ch[i]=='2') n+=b;
        else if(ch[i]=='3') n+=c;
        else if(ch[i]=='4') n+=d;
    }
    cout<<n<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int a,b,c,d,i,j,n=0;
    char ch[100];
    cin>>a>>b>>c>>d;
    getchar();
    gets(ch);
    int l=strlen(ch);
    for(i=0;i<l;i++)
    {
        if(ch[i]=='1') n+=a;
        else if(ch[i]=='2') n+=b;
        else if(ch[i]=='3') n+=c;
        else if(ch[i]=='4') n+=d;
    }
    cout<<n<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,d,i,j,n=0;
    char ch[10001];
    cin>>a>>b>>c>>d;
    getchar();
    gets(ch);
    int l=strlen(ch);
    for(i=0;i<l;i++)
    {
        if(ch[i]=='1') n+=a;
        else if(ch[i]=='2') n+=b;
        else if(ch[i]=='3') n+=c;
        else if(ch[i]=='4') n+=d;
    }
    cout<<n<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int a,b,c,d,i,j,n=0;
    string ch;
    cin>>a>>b>>c>>d;
    cin>>ch;
    for(i=0;i<ch.size();i++)
    {
        if(ch[i]=='1') n+=a;
        else if(ch[i]=='2') n+=b;
        else if(ch[i]=='3') n+=c;
        else if(ch[i]=='4') n+=d;
    }
    cout<<n<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
    int sum = 0;
    char c1, c2, c3, c4;
    cin >> c1 >> c2 >> c3 >> c4;
    string in;
    cin >> in;
    for(int i = 0; i < in.length(); i++){
        if(in[i] == c1)
            sum+=(int)c1 - '0';
        if(in[i] == c2)
            sum+=(int)c2 - '0';
        if(in[i] == c3)
            sum+=(int)c3 - '0';
        if(in[i] == c4)
            sum+=(int)c4 - '0';
    }
    cout << sum;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
    int sum = 0;
    int arr[5], temp;
    for(int i = 1; i < 5; i++){
        cin >> temp;
        arr[i] = temp;
    }
    string in;
    cin >> in;
    for(int i = 0; i < in.length(); i++){
        if(in[i] == '1')
            sum+=arr[1];
        if(in[i] == '2')
            sum+=arr[2];
        if(in[i] == '3')
            sum+=arr[3];
        if(in[i] == '4')
            sum+=arr[4];
    }
    cout << sum;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
    int sum = 0;
    char arr[5], temp;
    for(int i = 1; i < 5; i++){
        cin >> temp;
        arr[i] = temp;
    }
    string in;
    cin >> in;
    for(int i = 0; i < in.length(); i++){
        if(in[i] == '1')
            sum+=(int)arr[1] - '0';
        if(in[i] == '2')
            sum+=(int)arr[2] - '0';
        if(in[i] == '3')
            sum+=(int)arr[3] - '0';
        if(in[i] == '4')
            sum+=(int)arr[4] - '0';
    }
    cout << sum;
}


#include<iostream>
#include<string>
using namespace std;

int main()
{
	int arr[4], count = 0;
	string str;

	for (int i = 0; i<4; i++)
	{
		cin >> arr[i];
	}

	cin >> str;

	for (int i = 0; i<str.length(); i++)
	{
		int k = str[i]-'1';
		cout << k;
		count = count + arr[k];
	}

	cout << count;
}


#include<iostream>
#include<string>
using namespace std;

int main()
{
	int arr[4],count=0;
	string str;

	for(int i=0;i<4;i++)
	{
		cin>>arr[i];
	}

	cin>>str;

	for(int i=0;i<str.length();i++)
	{
		count=count+arr[stoi(str[i])]
	}

	cout<<count;
}


#include<iostream>
#include<string>
using namespace std;

int main()
{
	int arr[4], count = 0;
	string str;

	for (int i = 0; i<4; i++)
	{
		cin >> arr[i];
	}

	cin >> str;

	for (int i = 0; i<str.length(); i++)
	{
		int k = str[i]-'1';
		count = count + arr[k];
	}

	cout << count;
}


#include<iostream>
using namespace std;

int main()
{
	int arr[4];
	string str;

	for(int i=0;i<4;i++)
	{
		cin>>arr[i];
	}

	cin>>str;

	for(int i=0;i<str.length();i++)
	{
		count=count+arr[stoi(str[i])]
	}

	cout<<count;
}


# define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <stdio.h>
#include <vector>
#include <cstdlib>
#include <string>
#include <map>
#include <ctime>
#include <list>
#include <stack>
#include <set>
#include <memory.h>
#include <deque>
#include <queue>
#include <cctype>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <fstream>
typedef long long ll;
using namespace std;

# define pi 2*acos(0.)
# define e exp(1.)

# define N 110

int a[N][N];
int main(){

    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < m; ++j)
            cin >> a[i][j];

    int p;
    ll ave = INT_MAX;
    for (int i = 0; i < n; ++i){

        ll sum = 0;
        for (int j = 0; j < m; ++j)
        {
            sum += a[i][j];
        }

        sum /= n;
        if (ave > sum)
        {
            ave = sum;
            p = i;
        }
    }
    int minn = INT_MAX;
    for (int i = 0; i < n; ++i)
    {
        minn = min(a[p][i], minn);
    }

    cout << minn;

}


# define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <stdio.h>
#include <vector>
#include <cstdlib>
#include <string>
#include <map>
#include <ctime>
#include <list>
#include <stack>
#include <set>
#include <memory.h>
#include <deque>
#include <queue>
#include <cctype>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <fstream>
typedef long long ll;
using namespace std;

# define pi 2*acos(0.)
# define e exp(1.)

# define N 1100

int a[N][N];
int main(){

    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < m; ++j)
            cin >> a[i][j];

    vector < int > v;
    for (int i = 0; i < n; ++i)
    {
        int minn = 1e9;
        for (int j = 0; j < m; ++j)
            minn = min(a[i][j], minn);

        v.push_back(minn);
    }

    cout << *max_element(v.begin(), v.end());
}


# define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <stdio.h>
#include <vector>
#include <cstdlib>
#include <string>
#include <map>
#include <ctime>
#include <list>
#include <stack>
#include <set>
#include <memory.h>
#include <deque>
#include <queue>
#include <cctype>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <fstream>
typedef long long ll;
using namespace std;

# define pi 2*acos(0.)
# define e exp(1.)

# define N 110

int a[N][N];
int main(){

    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < m; ++j)
            cin >> a[i][j];

    int p;
    ll ave = INT_MAX;
    for (int i = 0; i < n; ++i){

        ll sum = 0;
        for (int j = 0; j < m; ++j)
        {
            sum += a[i][j];
        }

        sum /= n;
        if (ave > sum)
        {
            ave = sum;
            p = i;
        }
    }
    int minn = 1e9;
    for (int i = 0; i < m; ++i)
    {
        minn = min(a[p][i], minn);
    }

    cout << minn;

}


# define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <stdio.h>
#include <vector>
#include <cstdlib>
#include <string>
#include <map>
#include <ctime>
#include <list>
#include <stack>
#include <set>
#include <memory.h>
#include <deque>
#include <queue>
#include <cctype>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <fstream>
typedef long long ll;
using namespace std;

# define pi 2*acos(0.)
# define e exp(1.)

# define N 1100

int a[N][N];
int main(){

	int n, m;
	cin >> n >> m;
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < m; ++j)
			cin >> a[i][j];

	int p = 0;
	int minnn = INT_MAX;
	for (int i = 0; i < n; ++i)
	{
		int minn = INT_MAX, maxx = INT_MIN;
		for (int j = 0; j < m; ++j)
		{
			maxx = max(maxx, a[i][j]);
			minn = min(a[i][j], minn);
		}

		if (maxx - minn < minnn)
		{
			minnn = maxx - minn;
			p = i;
		}
	}

	minnn = INT_MAX;
	for (int i = 0; i < m; ++i)
	{
		minnn = min(minnn, a[p][i]);
	}

	cout << minnn;
}


# define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <stdio.h>
#include <vector>
#include <cstdlib>
#include <string>
#include <map>
#include <ctime>
#include <list>
#include <stack>
#include <set>
#include <memory.h>
#include <deque>
#include <queue>
#include <cctype>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <fstream>
typedef long long ll;
using namespace std;

# define pi 2*acos(0.)
# define e exp(1.)

# define N 110

int a[N][N];
int main(){

    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < m; ++j)
            cin >> a[i][j];

    int p;
    ll ave = INT_MAX;
    for (int i = 0; i < n; ++i){

        ll sum = 0;
        for (int j = 0; j < m; ++j)
        {
            sum += a[i][j];
        }

        sum /= n;
        if (ave > sum)
        {
            ave = sum;
            p = i;
        }
    }
    int minn = INT_MAX;
    for (int i = 0; i < m; ++i)
    {
        minn = min(a[p][i], minn);
    }

    cout << minn;

}


# define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <stdio.h>
#include <vector>
#include <cstdlib>
#include <string>
#include <map>
#include <ctime>
#include <list>
#include <stack>
#include <set>
#include <memory.h>
#include <deque>
#include <queue>
#include <cctype>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <fstream>
typedef long long ll;
using namespace std;

# define pi 2*acos(0.)
# define e exp(1.)

# define N 110

int a[N][N];
int main(){

	int n, m;
	cin >> n >> m;
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < m; ++j)
			cin >> a[i][j];

	int p = 0;
	int minnn = INT_MAX;
	for (int i = 0; i < n; ++i)
	{
		int minn = INT_MAX, maxx = INT_MIN;
		for (int j = 0; j < m; ++j)
		{
			maxx = max(maxx, a[i][j]);
			minn = min(a[i][j], minn);
		}

		if (maxx - minn < minnn)
		{
			p = i;
		}
	}

	int minnn = INT_MAX;
	for (int i = 0; i < m; ++i)
	{
		minnn = min(minnn, a[p][i]);
	}

	cout << minnn;
}


#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#include<set>
using namespace std;
#define CRL(a) memset(a,0,sizeof(a))
typedef  __int64 ll;
#define T 1000010
#define mod 1000000007

char s1[T],s2[T];

int main()
{
#ifdef zsc
    freopen("input.txt","r",stdin);
#endif

    int c;
    int n,m,i,j,k,ma;
    while(~scanf("%d%d",&n,&m))
    {
        ma = 0;
        for(i=0;i<n;++i){
            k = mod;
            for(j=0;j<m;++j){
                scanf("%d",&c);
                k = min(c,k);
            }
            ma = max(ma,k);
        }
        printf("%d\n",ma);
    }

    return 0;
}


#include <algorithm>
#include <iostream>
#include <string>
#include <stdio.h>
#include <vector>
#include <stack>
#include <map>
#include <iomanip>

using namespace std;

char a[101][101];

map<char, bool> dic;

int main()
{
	int n, m;
	cin >> n >> m;

	int rowNumber = 1;
	int min = -1;

	for (int i = 0; i < n; i++)
	{
		int minRow = 1000000000;
		for (int j = 0; j < m; j++)
		{
			int x;
			cin >> x;
			if (x < minRow) minRow = x;
		}

		if (minRow > min)
		{
			rowNumber = i;
			min = minRow;
		}
	}

	cout << rowNumber + 1;

	return 0;
}


#include <algorithm>
#include <iostream>
#include <string>
#include <stdio.h>
#include <vector>
#include <stack>
#include <map>
#include <iomanip>

using namespace std;

char a[101][101];

map<char, bool> dic;

int main()
{
	int n, m;
	cin >> n >> m;

	int rowNumber = 1;
	int min = -1;

	for (int i = 0; i < n; i++)
	{
		int minRow = 1000000000;
		for (int j = 0; j < m; j++)
		{
			int x;
			cin >> x;
			if (x < minRow) minRow = x;
		}

		if (minRow > min)
		{
			rowNumber = i;
			min = minRow;
		}
	}

	cout << min;

	return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;
int main(){
    ll n,m;
    ll minn=-1;
    ll ans=1;
    cin>>n>>m;
    for(ll i=0;i<n;i++){
        ll mint=100000000;
        for(ll j=0;j<m;j++){
            ll k;
            cin>>k;
            mint=min(mint,k);
            if(j==0)mint=k;
        }
        if(mint>minn){
            minn=mint;
            ans=i+1;
        }
    }
        cout<<ans;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;
int main(){
    ll n,m;
    ll minn=-1;
    ll ans=1;
    cin>>n>>m;
    for(ll i=0;i<n;i++){
        ll mint=100000000;
        for(ll j=0;j<m;j++){
            ll k;
            cin>>k;
            mint=min(mint,k);
        }
        if(mint>minn){
            minn=mint;
            ans=i+1;
        }
    }
        cout<<ans;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;
int main(){
    ll n,m;
    ll minn=-1;
    ll ans=1;
    cin>>n>>m;
    for(ll i=0;i<n;i++){
        ll mint=10000000000;
        ll k;
        for(ll j=0;j<m;j++){
            cin>>k;
            mint=min(mint,k);
            if(j==0)mint=k;
        }
        if(mint>minn){
            minn=mint;
            ans=mint;
        }
    }
        cout<<ans;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;
int main(){
    ll n,m;
    ll minn=-1;
    ll ans=1;
    cin>>n>>m;
    for(ll i=0;i<n;i++){
        ll mint=100000000;
        ll k;
        for(ll j=0;j<m;j++){
            cin>>k;
            mint=min(mint,k);
            if(j==0)mint=k;
        }
        if(mint>minn){
            minn=mint;
            ans=k;
        }
    }
        cout<<ans;
    return 0;
}


#include <stdio.h>
#include <limits.h>
#include <algorithm>
using namespace std;

int main(){
	int n, m;
	int x, price = INT_MIN, local_price;
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; i++){
		local_price = INT_MAX;
		for (int j = 0; j < m; j++)
		{
			scanf("%d", &x);
			local_price = min(local_price, x);
		}
		price = max(price, local_price);
	}
	printf("%d", price);
	return 0;
}


#include<cstdio>
#include<cstring>
using namespace std;
int i,j,n,m,x,ans,mymin;
int main()
{
  scanf("%d%d",&n,&m);
  ans=0;
  for (i=1;i<=n;i++)
  {
    mymin=1e9+1;
    for (j=1;j<=m;j++)
    {
      scanf("%d",&x);
      if (x<mymin) mymin=x;
	}
	if (mymin>ans) ans=mymin;
  }
  printf("%d\n",ans);
  return 0;
}


#include<cstdio>
#include<cstring>
using namespace std;
int i,j,n,m,x,ans,mymin;
int main()
{
  scanf("%d%d",&n,&m);
  ans=0;
  for (i=1;i<=n;i++)
  {
    mymin=1e9+1;
    for (j=1;j<=n;j++)
    {
      scanf("%d",&x);
      if (x<mymin) mymin=x;
	}
	if (mymin>ans) ans=mymin;
  }
  printf("%d\n",ans);
  return 0;
}


#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<limits.h>
#include<queue>
#include<math.h>
#define Inf 0x3f3f3f3f
#define ll long long
using namespace std;

int main()
{
	int n,m;
	int a0;
	int mina;
	int maxa=0;
	scanf("%d %d",&n,&m);
	for (int i=0;i<n;i++)
	{
		mina=Inf;
		for (int j=0;j<m;j++)
		{
			scanf("%d",&a0);
			if (mina>a0) mina=a0;
		}
		if (mina>maxa) maxa=mina;
	}
	printf("%d\n",maxa);

	return 0;
}


#include <vector>
#include <string>
#include <fstream>
using namespace std;
ifstream in("input.txt");
ofstream out("output.txt");
int n;
int m;
vector <vector<int>> A;
int ans;
int mini;
int main(){
	in >> n >> m;
	A.resize(n);
	for(int i = 0; i < n; i++){
		A[i].resize(m);
		for(int j = 0; j < m; j++){
			in >> A[i][j];
		}
	}
	for(int i = 0; i < n; i++){
		mini = A[i][0];
		for(int j = 0; j < m; j++){
			if(A[i][j] < mini) mini = A[i][j];
		}
		if(mini > ans){
			ans = mini;
		}
	}
	out << ans;

	return 0;
}


#include <vector>
#include <string>
#include <iostream>
using namespace std;
//ifstream in("input.txt");
//ofstream out("output.txt");
int n;
int m;
vector <vector<int>> A;
int ans;
int mini;
int main(){
	cin >> n >> m;
	A.resize(n);
	for(int i = 0; i < n; i++){
		A[i].resize(m);
		for(int j = 0; j < m; j++){
			cin >> A[i][j];
		}
	}
	for(int i = 0; i < n; i++){
		mini = A[i][0];
		for(int j = 0; j < m; j++){
			if(A[i][j] < mini) mini = A[i][j];
		}
		if(mini > ans){
			ans = mini;
		}
	}
	cout << ans;

	return 0;
}