jiahuimbzuai/CoQuIR huggingface dataset:
//  [java]
import java.io.File;
import java.io.FileInputStream;
import java.util.Scanner;
import java.util.Map.Entry;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.NoSuchElementException;

public class Main {
	
	public static void main(String[] args) throws IOException {
		FastScanner sc = new FastScanner(System.in);
		String s = sc.next();
		StringBuilder ans = new StringBuilder();
		for(int i = 0; i < s.length(); i++){
			if(s.charAt(i) == 'B'){
				if(ans.length() != 0) ans.delete(ans.length()-1, ans.length());
			}else ans.append(s.charAt(i));
		}
		System.out.println(ans);
	}
}

class FastScanner {
    private InputStream in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    public FastScanner(InputStream in) {
		this.in = in;
	}
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() {
    	if (hasNextByte()) return buffer[ptr++];
    	else return -1;
    }
    private static boolean isPrintableChar(int c){
    	return 33 <= c && c <= 126;
    }
    public boolean hasNext() {
    	while(hasNextByte() && !isPrintableChar(buffer[ptr]))
    		ptr++; return hasNextByte();
    }
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() {
    	return Double.parseDouble(next());
    }
}
//  [java]
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		char[] line = br.readLine().toCharArray();
		String str = "";
		for(char c : line){
			switch(c){
			case '0':
				str+="0";
				break;
			case '1':
				str+="1";
				break;
			case 'B':
				if(str.length()>0){
					str = str.substring(0, str.length()-1);
				}
				break;
			}
		}
		System.out.println(str);
	}
}
//  [java]
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws IOException {
		Scanner cin = new Scanner(System.in);
		String line;
		for (; cin.hasNext();) {
			line = cin.nextLine();
			String[] s = line.split(" ");
			String S = s[0]; // 文字列

			ArrayList<String> list = new ArrayList<String>();
			String[] ar = S.split("");

			for(String str : ar){
				switch(str){
				case "0":
					list.add("0");
					break;
				case "1":
					list.add("1");
					break;
				case "B":
					if(!list.isEmpty()){
						list.remove(list.size() - 1);
					}
					break;
				default:
					//何もしない
				}
			}

			String result = "";
			for(String word : list){
				result += word;
			}
			System.out.println(result);

		}
	}
}
//  [java]
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.Stack;

public class Main {
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        //BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String s = sc.next();
        Stack<Character> st = new Stack();

        for(char c : s.toCharArray()){
            if(c == 'B'){
                if(!st.isEmpty()){
                    st.pop();
                }
            }
            else{
                st.push(c);
            }
        }

        StringBuilder sb = new StringBuilder();

        while(!st.isEmpty()){
            sb.insert(0, st.pop());
        }
        
        System.out.println(sb.toString());
    }
}
//  [cpp]
#include <stdio.h>

int main(){
	char S[11];
	char A[11]={};
	int x=0;

	scanf("%s",&S);
	for(int i=0;i<11;i++){
		if(S[i]=='0'){
			A[x]='0';
			x++;
		}
		else if(S[i]=='1'){
			A[x]='1';
			x++;
		}
		else if(S[i]=='B'){
			if(x!=0)
				x--;
		}

	}
	for(int i=0;i<x;i++){
		printf("%c",A[i]);
	}
	printf("\n");\
}
//  [cpp]
# include <cstdio>
# include <cstring>
using namespace std;

int main()
{
	char a[100];
	char b[100];
	scanf("%s",a);
	int len = strlen(a);
	int k = 0;
	for(int i = 0;i < len;i++)
	{
		if(a[i] == 'B')
		{
			if(k != 0) 
				k--;
		}
		else
		{
			b[k++] = a[i];
		}
	}
	b[k] = '\0'; 
	printf("%s\n",b);
	return 0;
}
//  [cpp]
#include<stdio.h>
#include<string.h>
using namespace std;
int main()
{
	char s[20];
	char c[20];
	scanf("%s",s);
	getchar();
	int t=strlen(s);
	int r=0;
	int flag=0;
	int j=0;
	for(int i=t-1;i>=0;i--)
	{
		if(s[i]=='0'||s[i]=='1')
		{
			if(r==0)
			c[j++]=s[i];
			else
			r--;
		}
		else
		r++;
	}
	for(int i=j-1;i>=0;i--)
	printf("%c",c[i]);
	return 0; 
}
//  [cpp]
#include <iostream>
#include <string>
using namespace std;

int main() {
	string INS, OUTS = "";
	cin>>INS;
	for(int i=0; i<INS.size(); i++){
		if(INS[i] == '0') OUTS += '0';
		if(INS[i] == '1') OUTS += '1';
		if(INS[i] == 'B') OUTS = OUTS.substr(0,OUTS.size()-1);
	}
	cout<<OUTS<<endl;
}
//  [cpp]
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;
const long long INF=1e9+5;
const string alp="abcdefghijklmnopqrstuvwxyg"; //26
const string ALP="ABCDEFGHIJKLMNOPQRSTUVWXYG";
typedef long long ll;

int main() {
  string s;
  cin>>s;
  vector<char> vec;
  for(int i=0;i<s.size();i++){
    if(s[i]=='0'){
      vec.push_back('0');
    }
    else if(s[i]=='1'){
      vec.push_back('1');
    }
    else{
      if(!vec.empty()){
        vec.pop_back();
      }
    }
  }
  string ans;
  for(int i=0;i<vec.size();i++){
    ans+=vec.at(i);
  }
  cout<<ans<<endl;
      
}
//  [c]
#include <stdio.h>

int main(int argc, char *argv[])
{
    char S[32], Ans[32] = {0};
    int i, n = 0;
    fgets(S, 32, stdin);
    for ( i = 0; S[i] != '\n'; i++ ){
        if ( S[i] == 'B' ){
            if ( n > 0 ){
                n--;
            }
        } else {
            Ans[n++] = S[i];
        }
    }
    Ans[n] = '\0';
    printf("%s\n", Ans);
    return 0;
}
//  [c]
#include<string.h>
#include<stdio.h>
int main()
{
    char s[15],a[15];
    gets(s);
    int len =strlen(s);
    int l=0;
    for(int i=0;i<len ;i++)
    {
        if(s[i]=='0'||s[i]=='1')
        a[l++]=s[i];
        if(s[i]=='B'&&l>=1)
            l--;
    }
    for(int i=0;i<l;i++)
    printf("%c",a[i]);
    printf("\n");
    return 0;
}
//  [c]
#include<stdio.h>
int main(){
  char s[11]={},a[11]={};
  int j=0;
  scanf("%s",s);
  for(int i=0;s[i]!='\0';i++){
    switch(s[i]){
      case '0':
      case '1':
        a[j]=s[i];
        j++;
        break;
      case 'B':
        if(--j<0) j=0;
        break;
      default:
        break;
    }
    a[j]='\0';
  }
  printf("%s\n",a);
  return 0;
}
//  [c]
/* ex8_1 
melo */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SIZE 11
typedef struct{
    int size;//最大何個までstackに入るか
    int count;//現在のデータの数
    char data[SIZE];//データ配列
    char *top;//一番上のポインタ
} stack;
void initialize_stack(stack *stk);//スタックの初期化
void revprint_stack(stack *stk);//古いものからプリントする
void push(stack *stk,char input);//inputを一番上に格納
char pop(stack *stk);//一番上を取り出す
stack stk;
int main(void){
    char key[SIZE];//打ち込む文字
    int i;//for文用
    initialize_stack(&stk);//初期化
    scanf("%s",key);//打ち込んだ文字を入力
    for(i=0;i<strlen(key);i++){
        if(key[i]!='B'){//Bでなかった場合
            push(&stk,key[i]);//スタックに文字を格納
        }
        else{//Bだった場合
            pop(&stk);//１文字取り出す
        }
    }
    revprint_stack(&stk);//古いものからプリントする
    return 0;//正常終了
}
void initialize_stack(stack *stk){//初期化
    stk->count=0;//個数をゼロに
    stk->size=SIZE;//最大のサイズ
    stk->top=&(stk->data[SIZE]);//配列の最終要素の手前
}
void push(stack *stk,char input){//inputをスタックにいれる
    if(stk->count >= stk->size){//オーバーフローするとき
        printf("Error: stack overflow. (x=%c)\n", input);
        exit(1);// プログラムの終了
    }
    else{
        stk->top--;//topを一つ上にあげる
        *(stk->top)=input;//そこにデータを格納
        stk->count++;//現在のデータ数を増やす
    }
}
char pop(stack *stk){//一番上の要素を取り出す
    char input;//一番上の要素をいれる箱
    if(stk->count<=0){//アンダーフローするとき
        return '\t';//\tを返す
    }
    else{
        input=*(stk->top);//topからデータを取り出す
        stk->top++;//topを一つしたに下げる
        stk->count--;//現在のデータ数を減らす
        return input;//これ出したデータを返す
    }
}
void revprint_stack(stack *stk){//古いものからプリントする
    char *ptr;//ポインタを用意
    ptr =stk->top;//topの位置
    ptr+=stk->count-1;//topの一からcount-1したの位置に移動する（最も古いデータ）
    for(int i=stk->count-1;i>=0;i--){//count繰り返す
        printf("%c", *ptr--);//古いものからプリント
    }
    printf("\n");//改行
}
//  [c]
/* ex9_1:
    Jun_JPN*/

#include <stdio.h>
#include <stdlib.h>
#define SIZE 128
typedef struct{
    int size;       // 格納際代数
    int count;      // 現在のデータ数
    char str[SIZE]; // 文字列
    char *top;      // トップへのポインタ（トップは末尾の要素の1つ上の要素のポインタ）
}stack;

void initialize_stack(stack *stk);
void print_stack(stack *stk);
void push(stack *stk, char bin);
void pop(stack *stk);

int main(void){
    stack stk;
    char str[SIZE];
    int i;

    scanf("%s", str);           // 文字列を受け取る
    initialize_stack(&stk);     // スタックstkを初期化

    for(i=0; str[i] != '\0'; i++){
        if(str[i]=='B') pop(&stk);  // Bが来たらポップ
        else push(&stk, str[i]);    // B以外が来たらプッシュ
    }

    print_stack(&stk);

    return 0;
}

/* スタックを初期化 */
void initialize_stack(stack *stk){
    stk->count = 0;
    stk->size = SIZE;
    stk->str[0] = '\0';
    stk->top = &(stk->str[0]);  // 頭文字のポインタををtopに
}

/* スタックの中身を表示 */
void print_stack(stack *stk){
    for(int i=0; stk->str[i] != '\0'; i++){
        printf("%c", stk->str[i]);
    }
    printf("\n");
}

/* B以外の文字ををプッシュ */
void push(stack *stk, char bin){
    if(stk->count >= stk->size){    // オーバーフロー処理
        printf("Error: stack overflow\n");
        exit(1);
    }else{
        *(stk->top) = bin;  // スタックのトップに文字を加える
        stk->top++;         // スタックのトップを1つ上に
        *(stk->top) = '\0'; // スタックのトップをヌル文字に
        stk->count++;
    }
}

/* Bが来たらポップ
    要素を取り除く＝要素をヌル文字で書き換える */
void pop(stack *stk){
    if(stk->count <= 0){            // アンダーフロー処理
        ;   // 何もしない
    }else{
        stk->top--;         // スタックのトップを1つ下に
        *(stk->top) = '\0'; // スタックのトップをヌル文字に
        stk->count--;
    }
}
//  [c]
/* ex 9_1
   yumizmiz */

#include <stdio.h>
#include <stdlib.h>
//スタックに格納するデータの最大数
#define SIZE 1000

//スタックの定義
typedef struct stack{
    int size;
    int count;
    char data[SIZE];
    char *top;
} stack;

//スタックの初期化
void initialize_stack(stack *stk){
    stk->count = 0;
    stk->size = SIZE;
    stk->top = &(stk->data[SIZE]);
}

//データの追加
void push(stack *stk, char elem){
    if(stk->count >= stk->size){
        fprintf(stderr, "Error: stack overflow. (x=%c)\n", elem);
        exit(1);
    }
    else{
        stk->top--;
        *(stk->top) = elem;
        stk->count++;
    }
}

//データの取り出し
char pop(stack *stk){
    char latest;
    
    if(stk->count <= 0){
        fprintf(stdout, "Error: stack underflow.\n");
        exit(1);
    }
    else{
        latest = *(stk->top);
        stk->top++;
        stk->count--;
        return latest;
    }
}

int main(void){
    //スタック
    stack stk;
    initialize_stack(&stk);

    //入力文字列の配列（最大文字数10）
    char input[11], *ptr1;
    //出力文字列の配列（最大文字数10）
    char output[11], *ptr2;
    scanf("%s", input);

    ptr1 = input;
    while(*ptr1){
        //'B'だったらその前の文字を消す（取り出す）．消せる文字がなければ消さない
        if(*ptr1 == 'B'){
            if(stk.count>0)
                pop(&stk);
        }else{
            push(&stk, *ptr1);
        }
        ++ptr1;
    }
    //スタックを逆順に取り出す
    //文字数はstk.count
    ptr2 = &output[stk.count];
    //ヌル文字を入れて
    *ptr2 = '\0';
    //後ろから文字を入れていく
    while(stk.count>0){
        --ptr2;
        *ptr2 = pop(&stk);
    }
    printf("%s\n", output);
    return 0;
}
//  [javascript]
'use strict'

function main(s) {

  const input = s.replace(/\n/g, '').split('');
  const result = [];
  input.forEach(x => {
    if(x === 'B') {
      result.pop();
    } else {
      result.push(x);
    }
  });
  console.log(result.join(''));
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
function Main(input) {
  const data = input.split("");
  var ans = [];
  for (var i = 0; i < data.length; i++) {
    if (data[i] === "1") {
      ans.push("1");
    } else if (data[i] === "0") {
      ans.push("0");
    } else if (data[i] === "B") {
      if (ans.length > 0) {
        ans.pop();
      } else {
        continue;
      }
    }
  }
  console.log(ans.join(""));
}
 
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
'use strict'

function Main(input) {
    const tape = input.split('\n')[0].split('');
    const result = []

    for (const v of tape) {
        if (v === 'B') {
            result.pop();
        } else {
            result.push(v);
        }
    }

    console.log(result.join(''));
}

// input
Main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [javascript]
'use strict'

const main = (input) => {
    const s = input.split('\n')[0].split('')
    const ans = []

    s.forEach(v => {
        if(v === '1' || v === '0'){
            ans.push(v)
        }
        if(v === 'B' && ans.length !== 0){
            ans.pop()
        }
    })

    console.log(ans.join(''))
}

main(require('fs').readFileSync('/dev/stdin', 'utf-8'))
//  [javascript]
console.log((args=>{
  let s = args.trim();
  while ( /.?B/.test(s) ) s = s.replace(/.?B/,'');
  return s;
})(require('fs').readFileSync('/dev/stdin', 'utf8')));
//  [javascript]
"use strict";

const main = input => {
  input = input.split("\n")[0];
  
  var arr = [];
  for (var i = 0; i < input.length; i++) {
    var s = input[i];
    
    if( s == '0') arr.push('0');
    else if( s == '1') arr.push('1');
    else if( s == 'B') {
      if( arr.length != 0 ){
        arr.pop();
      }
    }
  }
  console.log(arr.join(''));
  
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [go]
package main

import (
	"fmt"
)

func main() {
	var s string; fmt.Scan(&s)
	res := ""
	for _, c := range s {
		if c == 'B' {
			if len(res) > 0 {res = res[:len(res)-1]}
		} else {
			res += string(c)
		}
	}
	fmt.Println(res)

}
//  [go]
package main

import "fmt"

func main() {
	var s, ans string
	fmt.Scan(&s)
	for _, letter := range s {
		if letter != 'B' {
			ans += string(letter)
		} else if ans != "" {
			ans = ans[:len(ans)-1]
		}
	}
	fmt.Println(ans)
}
//  [go]
package main

import "fmt"

func main() {
	var s, ans string
	fmt.Scan(&s)
	for _, letter := range s {
		switch letter {
		case '0':
			ans += "0"
		case '1':
			ans += "1"
		case 'B':
			if ans != "" {
				trim := ans[:len(ans)-1]
				ans = trim
			}
		}
	}
	fmt.Println(ans)
}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	s := nextStr()
	l := make([]byte, 30)

	nowidx := 0
	for i := 0; i < len(s); i++ {
		if s[i] == 'B' {
			l[nowidx] = 'B'
			nowidx = max(0, nowidx-1)
		} else {
			l[nowidx] = s[i]
			nowidx++

		}
	}
	for i := 0; i < nowidx; i++ {
		fmt.Printf("%c", l[i])
	}

}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

// ---- readfunc
func scanInit() {
	const cap = 200 * 1024 // default=64*1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}

func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}

func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	s := Scan()
	ans := ""
	for _, r := range s {
		if string(r) == "0" {
			ans = ans + "0"
		} else if string(r) == "1" {
			ans = ans + "1"
		} else {
			if ans != "" {
				ans = ans[:len(ans)-1]
			}
		}
	}
	fmt.Println(ans)
}
//  [go]
package main

import (
  "fmt"
)

func main() {
  var s string
  fmt.Scanf("%s", &s)
  
  ans := ""
  for _, v := range s {
    if v != 'B'{
      ans += string(v)
    }else{
      if len(ans) == 0 {
        continue
      }
      ans = ans[0:len(ans)-1]
    }
  }
  
  fmt.Printf("%s", ans)
}
//  [ruby]
a = gets.chomp.split('')
r = []
 
a.each do |e|
  if e == 'B'
        r.pop
        next
    end
      r.push(e)
end
puts r.join
//  [ruby]
m=gets.chomp.to_s
v=m.split("")
result=[]
for i in 0.. v.length-1
    if v[i]=="B"
        result.pop
        next
    end
    result.push(v[i])
end
puts result.join("")
//  [ruby]
s = gets.chomp.split('')

ans = []

s.each do |i|
  if i == 'B'
    ans.delete_at(-1) if ans.size != 0
  else
    ans.push(i)
  end
end

puts ans.join('')
//  [ruby]
s=gets.chomp.split("").map(&:to_s)
result=[]
for i in 0..s.length-1
    v=s[i]
    if v=="1" || v=="0"
    result.push(v)
    else
    result.pop
    end
end
puts result.join("")
//  [ruby]
arr = gets.chomp.split('')
ans = []
i = 0
while i < arr.size
  if arr[i] == "0"
    ans << 0
  elsif arr[i] == "1"
    ans << 1
  else
    ans.pop
  end
  i += 1
end
puts ans.join
//  [ruby]
s = gets.chomp

ans = ""

s.each_char do |c|
  if c == 'B'
    ans.chop! unless ans.empty?
  else
    ans << c
  end
end

puts ans
//  [rust]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        s: String,
    }
    let mut ans = String::new();
    for c in s.chars() {
        match c {
            '0' => ans.push('0'),
            '1' => ans.push('1'),
            _ => { ans.pop(); },
        }
    }
    println!("{}", ans);
}
//  [rust]
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let s = iterator.next().unwrap();

    let mut ans = String::new();
    for c in s.chars() {
        if c == 'B' {
            ans.pop();
        } else {
            ans.push(c);
        }
    }

    return ans;
}
//  [rust]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input!(s: chars);
    let mut answer: String = "".to_string();
    for item in s {
        match item {
            '1' => answer.push(item),
            '0' => answer.push(item),
            'B' => {
                answer.pop();
                ()
            }
            _ => (),
        }
    }
    println!("{}", answer);
}
//  [rust]
#![allow(unused_imports)]
// use itertools::Itertools;
use proconio::{input, marker::*};

fn main() {
    input! {
        s: Chars
    };
    let mut vec = vec![];
    for c in s {
        match c {
            '0' | '1' => vec.push(c),
            _ if !vec.is_empty() => {
                vec.pop().unwrap();
            }
            _ => (),
        }
    }
    println!("{}", vec.iter().collect::<String>());
}
//  [rust]
use proconio::input;

fn main() {
    input! {
        s: String
    }
    let mut out = s;
    while let Some(i) = out.find("B") {
        out.remove(i);
        if let Some(si) = i.checked_sub(1) {
            out.remove(si);
        }
    }
    println!("{}", out);
}
//  [swift]
import Foundation

let input_line = readLine()!

// #1
var characters = Array(input_line.characters)
var count = characters.count
var result = ""
for i in 0..<count {
  switch characters[i] {
    case "0":
    result += "0"
    case "1":
    result += "1"
    case "B":
    if result.characters.count > 0 {
      result = result.substringToIndex(result.endIndex.advancedBy(-1))
    }
    default: break
  }
}
print(result)
//  [swift]
//
//  main.swift
//  Atcoder
//
//  Created by Louis Joe Shen on 2020/9/26.
//  Copyright © 2020 Louise Joe Shen. All rights reserved.
//

import Foundation

var input = readLine()!

var ans = ""

for i in input{
    if i == "B"{
        if ans.isEmpty{
            //doing nothing
        }else{
            ans.removeLast()
        }
    }else{
        ans += String(i)
    }
}

print(ans)
//  [swift]
import Foundation

#if swift(>=4.0)
extension String {
    func split(by separator: String) -> [String] {
        return self.components(separatedBy: separator)
    }
    func toArray() -> [String] {
        return self.map{String($0)}
    }
}
func exponentiate(_ lhs: Int, _ rhs: Int) -> Int {
    return (0..<rhs).reduce(1){i,_ in i*lhs}
}
#else
extension String {
    func split(by separator: String) -> [String] {
        return self.componentsSeparatedByString(separator)
    }
    var count: Int {
        return self.characters.count
    }
    func toArray() -> [String] {
        return self.characters.map{String($0)}
    }
    func uppercased() -> String {
        return self.uppercaseString
    }
    func lowercased() -> String {
        return self.lowercaseString
    }
}
//extension Array where Element == String {
//    func joined(separator separator: String) -> String {
//        return self.joinWithSeparator(separator)
//    }
//}
extension Array where Element: Comparable {
    func max() -> Element {
        return self.maxElement()!
    }
    func min() -> Element {
        return self.minElement()!
    }
    func sorted() -> Array {
        return self.sort()
    }
    func reversed() -> Array {
        return self.reverse()
    }
    mutating func sort() {
        self.sortInPlace()
    }
}
extension Array {
    init(repeating: Element, count: Int) {
        self.init(count: count, repeatedValue: repeating)
    }
}
func stride<T: Strideable>(from start: T, to end: T, by stride: T.Stride) -> StrideTo<T> {
    return start.stride(to: end, by: stride)
}
func exponentiate(lhs: Int, _ rhs: Int) -> Int {
    return (0..<rhs).reduce(1){i,_ in i*lhs}
}
#endif
func readInt() -> Int? {
    return Int(readLine()!)
}
func readStringSplit(by separator: String) -> [String] {
    return readLine()!.split(by: separator)
}
func readIntSplit(by separator: String) -> [Int] {
    return readLine()!.split(by: separator).map{Int($0)!}
}

/*************** テストスペース ***************/



/*************** メインプログラム ***************/

let s = readLine()!.toArray()
var ans = [String]()
for c in s {
    if c == "B" {
        if ans.count > 0 {
            ans.removeLast()
        }
    } else {
        ans += [c]
    }
}
print(ans.joinWithSeparator(""))
//  [typescript]
"use strict";

const Main = args => {
  const input = args.trim().split("");
  let editor = []
  input.forEach(e => {
    if (e === '0') editor.push('0');
    if (e === '1') editor.push('1');
    if (e === 'B') editor.pop();
  });
  console.log(editor.join(''));
}

Main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [typescript]
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const s = input[0][0];

  const display: string[] = [];

  s.split("").forEach((key) => {
    if (key === "B") {
      display.pop();
    } else {
      display.push(key);
    }
  });

  return display.join("");
};

console.log(main(read()));
//  [typescript]
import * as fs from 'fs';
const input = fs.readFileSync("/dev/stdin", "utf8").split('');

// B - バイナリハックイージー
let resultArray = new Array<string>();

input.forEach(x => {
    switch (x) {
        case '1':
            resultArray.push(x);
            break;
        case '0':
            resultArray.push(x);
            break;
        case 'B':
            resultArray.pop();
    }
});

let result = '';

resultArray.forEach(x => {
    result += x;
});

console.log(result);
//  [typescript]
const input=require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/);let input_i=-1;const tn=():number=>{input_i++;return Number(input[input_i])};const tnn=(n:number):number[]=>{const a=[];for(let i=0;i<n;i++){a.push(tn())}return a};const ts=():string=>{input_i++;return String(input[input_i])};const tss=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(ts())}return a};const to=(...arg)=>{console.log(...arg)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const floor=(a)=>{return Math.floor(a)};const asc=(ar:number[])=>{const t=[...ar];return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{const t=[...ar];return t.sort((a,b)=>{return b-a})};const sw=(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length-1;i+=2){if(eval(a+op+arr[i])){return arr[i+1]}}return arr[arr.length-1]};const near=(n:number,arr:number[]):number=>{let ne=arr[0],ni=0;for(let i=1;i<arr.length;i++){if(Math.abs(n-ne)>Math.abs(n-arr[i])){ne=arr[i];ni=i}}return ni};const deduplicate=(a:any[]):any[]=>{return Array.from(new Set(a))};
const main=()=>{
  let s=ts(),ans=[]
  for(let i=0;i<s.length;i++){
    if(s[i]=='0')ans.push('0')
    else if(s[i]=='1')ans.push('1')
    else if(s[i]=='B')ans.pop()
  }
  to(ans.join(''))
}
main()
//  [python]
n = int(input())
s,t = [],[]
for i in range(n):
    a,b = input().split()
    s.append(a)
    t.append(int(b))
x = input()
print(sum(t[s.index(x)+1:]))
//  [python]
# coding: utf-8
N = int(input())
S, T = [], []
for i in range(N):
    s, t = input().split()
    t = int(t)
    S.append(s)
    T.append(t)
X = input()
start = S.index(X)
ans = 0
for i in range(start+1, N):
    ans += T[i]
print(ans)
//  [python]
import sys

n = int(input())
playlist = []
playtime = []
for _ in range(n):
    s, t = input().split()
    playlist.append(s)
    playtime.append(int(t))
x = input()
i = playlist.index(x)
print(sum(playtime[i + 1:]))
//  [python]
import numpy as np


n = int(input())
st = [tuple(input().split()) for i in range(n)]
x = input()
T = []

for i, (s, t) in enumerate(st):
    T.append(int(t))

    if s == x:
        fin = i

T = np.array(T)

ans = np.sum(T[fin+1:])

print(ans)
//  [python]
import sys
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

n = int(readline())
S = []
T = []
for i in range(n):
    s, t = readline().decode('utf-8').split()
    t = int(t)
    S.append(s)
    T.append(t)
X = readline().decode('utf-8').split()[0]

idx = S.index(X)
res = sum(T[idx+1:])

print(res)
//  [python]
N=int(input())
st=[]
for i in range(N):
    s,t=input().split()
    st.append((s,int(t)))
X=input()

time=0
s=False
for i in range(N):
    if s:
        time+=st[i][1]
    if st[i][0]==X:
        s=True
print(time)
//  [java]
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class Main {
	InputStream is;
	PrintWriter out;
	String INPUT = "";

	void solve() {
		int n = ni();
		String[] s = new String[n];
		int[] a = new int[n];
		for(int i = 0; i < n; i++) {
			s[i] = ns();
			a[i] = ni();
		}
		String X = ns();
		int ans = 0;
		for(int i = 0; i < n; i++) {
			if(X.equals(s[i])) {
				for(int j = i+1; j < n; j++) {
					ans += a[j];
				}
				break;
			}
		}
		out.println(ans);
	}

	void run() throws Exception {
		is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		if (!INPUT.isEmpty())
			tr(System.currentTimeMillis() - s + "ms");
	}

	public static void main(String[] args) throws Exception {
		new Main().run();
	}

	private byte[] inbuf = new byte[1024];
	public int lenbuf = 0, ptrbuf = 0;

	private int readByte() {
		if (lenbuf == -1)
			throw new InputMismatchException();
		if (ptrbuf >= lenbuf) {
			ptrbuf = 0;
			try {
				lenbuf = is.read(inbuf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (lenbuf <= 0)
				return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean isSpaceChar(int c) {
		return !(c >= 33 && c <= 126);
	}

	private int skip() {
		int b;
		while ((b = readByte()) != -1 && isSpaceChar(b))
			;
		return b;
	}

	private double nd() {
		return Double.parseDouble(ns());
	}

	private char nc() {
		return (char) skip();
	}

	private String ns() {
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	private char[] ns(int n) {
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while (p < n && !(isSpaceChar(b))) {
			buf[p++] = (char) b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	private char[][] nm(int n, int m) {
		char[][] map = new char[n][];
		for (int i = 0; i < n; i++)
			map[i] = ns(m);
		return map;
	}

	private int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}

	private int ni() {
		int num = 0, b;
		boolean minus = false;
		while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
			;
		if (b == '-') {
			minus = true;
			b = readByte();
		}

		while (true) {
			if (b >= '0' && b <= '9') {
				num = num * 10 + (b - '0');
			} else {
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private long nl() {
		long num = 0;
		int b;
		boolean minus = false;
		while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
			;
		if (b == '-') {
			minus = true;
			b = readByte();
		}

		while (true) {
			if (b >= '0' && b <= '9') {
				num = num * 10 + (b - '0');
			} else {
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private static void tr(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}
}
//  [java]

import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {
    static final Scanner sc    = new Scanner(System.in);
    static final int     MOD   = (int) 1E9 + 7;
    static final long    INF_L = (long) 4E18;
    static final int     INF   = Integer.MAX_VALUE;
    
    public static void main(String[] args) {
        int N = nint();
        String[] s = new String[N];
        int[] t = new int[N];
        for (int i = 0; i < N; i++) {
            s[i] = nstr();
            t[i] = nint();
        }
        String X = nstr();
        
        int in = IntStream.range(0, N).filter(i -> s[i].equals(X)).findFirst().getAsInt();
        int ans = 0;
        for (int i = in + 1; i < N; i++) {
            ans+= t[i];
        }
        System.out.println(ans);
    }
    
    @Deprecated
    static int nint() {
        return sc.nextInt();
    }

    @Deprecated
    static int[] nints(int N) {
        return nints(N, 0, 0);
    }

    @Deprecated
    private static int[] nints(int N, int padL, int padR) {
        int[] a = new int[padL + N + padR];
        for (int i = 0; i < N; i++)
            a[padL + i] = nint();
        return a;
    }

    static long nlong() {
        return sc.nextLong();
    }

    static long[] nlongs(int N) {
        return nlongs(N, 0, 0);
    }

    static long[] nlongs(int N, int padL, int padR) {
        long[] a = new long[padL + N + padR];
        for (int i = 0; i < N; i++)
            a[padL + i] = nlong();
        return a;
    }

    static double ndouble() {
        return sc.nextDouble();
    }

    static double[] ndoubles(int N) {
        return ndoubles(N, 0, 0);
    }

    static double[] ndoubles(int N, int padL, int padR) {
        double[] d = new double[N + padL + padR];
        for (int i = 0; i < N; i++) {
            d[padL + i] = ndouble();
        }
        return d;
    }

    static String nstr() {
        return sc.next();
    }

    static char[] nchars() {
        return sc.next().toCharArray();
    }

    static char[] nchars(int padL, int padR) {
        char[] temp = sc.next().toCharArray();
        char[] ret = new char[temp.length + padL + padR];
        System.arraycopy(temp, 0, ret, padL, temp.length);
        return ret;
    }

    static char[][] nchars2(int H, int W) {
        return nchars2(H, W, 0, 0);
    }

    static char[][] nchars2(int H, int W, int padLU, int padRD) {
        char[][] a2 = new char[H + padLU + padRD][W + padLU + padRD];
        for (int i = 0; i < H; i++)
            System.arraycopy(nchars(), 0, a2[padLU + i], padLU, W);
        return a2;
    }

    static long min(long... ls) {
        return Arrays.stream(ls).min().getAsLong();
    }

    static long max(long... ls) {
        return Arrays.stream(ls).max().getAsLong();
    }

    static long abs(long a) {
        return Math.abs(a);
    }
}
//  [java]
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        String[] s = new String[n];
        int[] t = new int[n];

        for (int i=0; i<n; i++){
            s[i] = sc.next();
            t[i] = sc.nextInt();
        }

        String x = sc.next();

        int ans = 0;

        int tmp = 0;

        for (int i=0; i<n; i++){
            if (s[i].equals(x)){
                tmp = i;
                break;
            }
        }
        for (int i=tmp+1; i<n; i++){
            ans += t[i];
        }

        System.out.println(ans);

    }
}
//  [cpp]
#include <bits/stdc++.h>
using namespace std;

const int N = 55;

int n, t[N], ans = 0;
string str[N], s;
bool flag = false;

int main () {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) cin >> str[i] >> t[i];
	cin >> s;

	for (int i = 1; i <= n; i++) {
		if (flag) ans += t[i];
		if (str[i] == s) flag = true;
	}
	cout << ans << endl;
	return 0;
}
//  [cpp]
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const double eps = 0.00001;
const int MOD = 1000000007;
const int INF = 2147480555;
const ll LINF = 2223372000000000555;
const int N = 1550555;
const int M = 525;

string s[N];
int t[N];
void solve() {
    int n;
    cin >> n;

    for (int i = 1; i <= n; i++){
        cin >> s[i] >> t[i];
    }

    string str;
    cin >> str;

    bool ok = false;
    ll sum = 0;
    for (int i = 1; i <= n; i++){
        if (ok) sum += t[i];
        if (s[i] == str) ok = true;
    }

    cout << sum;

}


int main() {
    ios_base::sync_with_stdio(false);
#ifdef dddxxz
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else

#endif

    int T = 1;
    //cin >> T;

    while (T--) {
        solve();
    }

    return 0;
}
//  [cpp]
#include <bits/stdc++.h>
using namespace std;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;



int n;
string s[maxn];
int t[maxn];

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

    cin>>n;
    for (int i=0; i<n; i++) {
	cin>>s[i]>>t[i];
    }
    string x;
    cin>>x;

    int tot = 0;
    bool flag = false;
    for (int i=0; i<n; i++) {
	if (flag) {
	    tot += t[i];
	    continue;
	}
	if (x==s[i]) {
	    flag=true;
	}
    }

    out(tot);
    
    
    return 0;
}
//  [c]
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


typedef struct {
    char* title;
    int length;
} music;
#define MAX_TITLE 110

void printPlaylist(music*, int);
int main(void){
    int N;
    music* playlist;

    scanf("%d", &N);
    playlist = (music*)malloc(sizeof(music)*N);
    for(int i=0;i<N;i++){
        int length;

        scanf("%*c%s %d", playlist[i].title = (char*)malloc(sizeof(char) * MAX_TITLE), &length);
        playlist[i].length = length;
    }    

    char* slept;
    scanf("%*c%s", slept = (char*)malloc(sizeof(char)*MAX_TITLE));


    int allsong=0;
    int sleeptime = 0;
    int sleeping = 0;
    for(int j=0; j<N; j++){
        allsong += playlist[j].length;
        if(sleeping==1) sleeptime += playlist[j].length;
        if(strcmp(playlist[j].title, slept)==0) sleeping = 1;
    }
    printf("%d\n", sleeptime);
    
    return 0;
}
//  [c]
#include <stdio.h>

int main(void){

  int n;
  scanf("%d", &n);

  char s[n][101];
  int t[n];
  for (int i = 0; i < n; i++) {
    scanf("%s %d", s[i], &t[i]);
  }

  char x[101];
  scanf("%s", x);

  int asleep;

  int flag;
  for (int i = 0; i < n; i++) {
    flag = 1;
    for (int j = 0; j < 101; j++) {
      if (x[j] < 'a' || x[j] > 'z') {
        break;
      }
      if (s[i][j] != x[j]) {
        flag = 0;
        break;
      }
    }
    if (flag == 1) {
      asleep = i;
      break;
    }
  }

  int playtime = 0;
  for (int i = asleep+1; i < n; i++) {
    playtime += t[i];
  }

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

  return 0;
}
//  [c]
#include <stdio.h>
#include <string.h>

int N, t[50];
char s[50][101], X[101];

int main() {
        int i;
        int ret = 0;

        scanf("%d", &N);

        for (i = 0; i < N; i++) {
                scanf("%s %d", s[i], &t[i]);
        }

        scanf("%s", X);

        for (i = 0; i < N; i++) {
                if (strcmp(s[i], X) == 0) {
                        i++;
                        break;
                }
        }

        for (; i < N; i++) {
                ret += t[i];
        }

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

        return 0;
}
//  [c]
#include <stdio.h>
#include <string.h>

int N;
char s[64][128];
int t[64];
char X[128];

int main(void) {
	int i;
	int asumikana = 0;
	int yosinagasayuri = 0;
	if (scanf("%d", &N) != 1) return 1;
	for (i = 0; i < N; i++) {
		if (scanf("%127s%d", s[i], &t[i]) != 2) return 1;
	}
	if (scanf("%127s", X) != 1) return 1;
	for (i = 0; i < N; i++) {
		if (yosinagasayuri) asumikana += t[i];
		yosinagasayuri = yosinagasayuri || (strcmp(s[i], X) == 0);
	}
	printf("%d\n", asumikana);
	return 0;
}
//  [c]
#include <stdio.h>
#include <string.h>

int main(){
  int N;
  char s[52][102];
  int p,t[52];
  scanf("%d\n",&N);
  t[0]=0;
  for(int i=1;i<=N;i++){
    scanf("%s %d\n",s[i],&p);
    t[i]=p+t[i-1];
  }
  char X[102];
  scanf("%s",X);
  int c=1;
  while(strcmp(s[c],X)!=0) c++;
  printf("%d\n",t[N]-t[c]);
  return 0;
}
//  [javascript]
/**
 * @param input string[]
 */
function Main(input) {
  const songs = input.slice(1, -1).map((line) => line.split(' '));
  const X = input[input.length - 1];

  var i = 0;
  var XIndex;
  while (true) {
    if (songs[i][0] === X) {
      XIndex = i;
      break;
    }
    i++;
  }

  const answer = songs.slice(XIndex + 1).reduce((pv, cv) => {
    return pv + (+cv[1]);
  }, 0);

  console.log(answer);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim()
  .split('\n')
);
//  [javascript]
function Main(input) {
  input.trim();
  input = input.split("\n");
 input.shift();
 input.reverse();
 var arr = {};
 var ruiseki=0;
 for(var i=1;i<input.length;i++){
   var mem = input[i].split(" ");
   mem[1]-=0
   arr[mem[0]] = ruiseki;
      ruiseki += mem[1]
 }
 console.log( arr[input[0]] )
}Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());
function arr1dto2d (arr){
	for(var i=0;i<arr.length;i++){
    arr[i]=arr[i].split("");
    }
  return arr;
}
//  [javascript]
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
	//文字列から10進数に変換するときはparseIntを使います
	var num = Number(input[0])
    var sleepSong = input[num+1]
    var time = 0
	for(var i = 1; i <= num; i++) {
    	var current = input[i].split(' ')
        var currentSong = current[0]
        if(currentSong === sleepSong) {
          for(var j = i+1; j <= num; j++) {
            var current = input[j].split(' ')
        	var currentSongTime = Number(current[1])
            time += currentSongTime
          }
          return console.log(time)
        }
    }
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
Main(myin());
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim();}
function myout(t){console.log(t);}//standard output
function myerr(t){console.error(t);}//standard error
//[no]param
//不明値:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
//8:半角SPで結合　9:改行で結合　0:文字なしで結合
function myconv(i,no){switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}
function Main(input) {
  input = myconv(input,3);
  var N = myconv(input[0],1);
  input.shift();
  var X = input[N];
  var output = 0;
  var flag = false;
  for(var i = 0; i< N; i++){
    var kyoku = myconv(input[i],2)[0];
    var t = myconv(input[i],4)[1];
    if(kyoku == X){
       flag = true;
      continue;
    }
    if(flag){
       output += t;
    }
  }
  myout(output);
}
//  [javascript]
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	num = 0
	var input = input.trim().split("\n");
	var listen = input[input.length - 1]
	var sleep = false

	for (i = 1; i <= input.length - 1; i++) {
		title = input[i].split(' ')[0]
		if (title === listen) {
			sleep = true;
			continue;
		}
		if (sleep) {
			num += parseInt(input[i].split(' ')[1])
		}
	}

	//出力
	console.log(num)
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
// Main(require('fs').readFileSync('./input.txt', 'utf-8'));
//  [javascript]
function main(input) {
  input = input.trim()
  args = input.split('\n');
  text = (args.slice(-1)[0])
  isFlag = false
  ans = 0
  for (var i = 1; i < args.length -1 ; i++){
    baz = args[i].split(' ');
    if (isFlag) {
      ans += parseInt(baz[1], 10)
    }
    if (baz[0] == text) {
      isFlag = true
    }
  }
  console.log(ans)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var (
	N     int
	s     [1000]string
	index map[string]int = make(map[string]int)
	cumT  [1000]int
	X     string
)

func main() {
	readVariables()
	answer := cumT[N] - cumT[index[X]]
	fmt.Println(answer)
}

func readVariables() {
	N = nextInt()
	for i := 0; i < N; i++ {
		s, t := nextStr(), nextInt()
		cumT[i+1] = cumT[i] + t
		index[s] = i + 1
	}
	X = nextStr()
}

/* Template */

var scanner *bufio.Scanner

func init() {
	Max := 1001001
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]byte, 0, Max), Max)
	scanner.Split(bufio.ScanWords)
}

//nextInt converts next token from stdin and returns integer value.
//nextInt panics when conversion into an integer fails.
func nextInt() int {
	if !scanner.Scan() {
		panic("No more token.")
	}
	num, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic("nextInt(): cannot convert to int: " + scanner.Text())
	}
	return num
}

func nextStr() string {
	if !scanner.Scan() {
		panic("No more token.")
	}
	return scanner.Text()
}

// MinInt returns minimum argument
func MinInt(x, y int) int {
	if x < y {
		return x
	} else {
		return y
	}
}

//MaxInt returns maximum argument
func MaxInt(x, y int) int {
	if x < y {
		return y
	} else {
		return x
	}
}

//AbsInt returns |x| for x
func AbsInt(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

//ModPow calculates integer power with modulo operation
//if modulo <= 1, it powers w/o module operation
//if base < 0, return value might be negative too.
func ModPow(base, exponent, modulo int) (result int) {
	result = 1
	for exponent > 0 {
		if exponent%2 == 1 {
			result *= base
			if modulo > 1 {
				result %= modulo
			}
		}
		base *= base
		if modulo > 1 {
			base %= modulo
		}
		exponent /= 2
	}
	return
}

//Gcd
func Gcd(vals ...int) (result int) {
	if len(vals) == 0 {
		return
	}
	result = vals[0]
	for i := 1; i < len(vals); i++ {
		result = gcd(result, vals[i])
	}
	return
}

func gcd(x, y int) int {
	x, y = AbsInt(x), AbsInt(y)
	for y > 0 {
		x, y = y, x%y
	}
	return x
}

//Lcm
func Lcm(vals ...int) (result int) {
	if len(vals) == 0 {
		return
	}
	result = vals[0]
	for i := 1; i < len(vals); i++ {
		result = lcm(result, vals[i])
	}
	return
}

func lcm(x, y int) int {
	return x * y / gcd(x, y)
}