import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] text = sc.next().toCharArray();

        char[] removedText = new char[text.length];
        Arrays.fill(removedText, ' ');
        int index = 0;
        int destIndex = -1;
        for (int i = 0; i < text.length; i++) {
            if (destIndex < 0 || text[i] == removedText[destIndex]) {
                removedText[++destIndex] = text[i];
            } else {
                removedText[destIndex--] = ' ';
            }
        }

        System.out.println(new String(text).length() - new String(removedText).trim().length());
    }
} import java.util.Arrays; Arrays java.util import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] text = sc.next().toCharArray();

        char[] removedText = new char[text.length];
        Arrays.fill(removedText, ' ');
        int index = 0;
        int destIndex = -1;
        for (int i = 0; i < text.length; i++) {
            if (destIndex < 0 || text[i] == removedText[destIndex]) {
                removedText[++destIndex] = text[i];
            } else {
                removedText[destIndex--] = ' ';
            }
        }

        System.out.println(new String(text).length() - new String(removedText).trim().length());
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] text = sc.next().toCharArray();

        char[] removedText = new char[text.length];
        Arrays.fill(removedText, ' ');
        int index = 0;
        int destIndex = -1;
        for (int i = 0; i < text.length; i++) {
            if (destIndex < 0 || text[i] == removedText[destIndex]) {
                removedText[++destIndex] = text[i];
            } else {
                removedText[destIndex--] = ' ';
            }
        }

        System.out.println(new String(text).length() - new String(removedText).trim().length());
    } main {
        Scanner sc = new Scanner(System.in);
        char[] text = sc.next().toCharArray();

        char[] removedText = new char[text.length];
        Arrays.fill(removedText, ' ');
        int index = 0;
        int destIndex = -1;
        for (int i = 0; i < text.length; i++) {
            if (destIndex < 0 || text[i] == removedText[destIndex]) {
                removedText[++destIndex] = text[i];
            } else {
                removedText[destIndex--] = ' ';
            }
        }

        System.out.println(new String(text).length() - new String(removedText).trim().length());
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) char[] text = sc.next().toCharArray(); text sc.next().toCharArray() sc.next().toCharArray sc.next() sc.next sc char[] removedText = new char[text.length]; removedText new char[text.length] text.length text text.length Arrays.fill(removedText, ' ') Arrays.fill Arrays removedText ' ' int index = 0; index 0 int destIndex = -1; destIndex -1 1 for (int i = 0; i < text.length; i++) {
            if (destIndex < 0 || text[i] == removedText[destIndex]) {
                removedText[++destIndex] = text[i];
            } else {
                removedText[destIndex--] = ' ';
            }
        } int i = 0; int i = 0; i 0 i < text.length i text.length text text.length i++ i++ i {
            if (destIndex < 0 || text[i] == removedText[destIndex]) {
                removedText[++destIndex] = text[i];
            } else {
                removedText[destIndex--] = ' ';
            }
        } {
            if (destIndex < 0 || text[i] == removedText[destIndex]) {
                removedText[++destIndex] = text[i];
            } else {
                removedText[destIndex--] = ' ';
            }
        } if (destIndex < 0 || text[i] == removedText[destIndex]) {
                removedText[++destIndex] = text[i];
            } else {
                removedText[destIndex--] = ' ';
            } destIndex < 0 || text[i] == removedText[destIndex] destIndex < 0 destIndex 0 text[i] == removedText[destIndex] text[i] text i removedText[destIndex] removedText destIndex {
                removedText[++destIndex] = text[i];
            } removedText[++destIndex] = text[i] removedText[++destIndex] removedText ++destIndex destIndex text[i] text i {
                removedText[destIndex--] = ' ';
            } removedText[destIndex--] = ' ' removedText[destIndex--] removedText destIndex-- destIndex ' ' System.out.println(new String(text).length() - new String(removedText).trim().length()) System.out.println System.out System System.out new String(text).length() - new String(removedText).trim().length() new String(text).length() new String(text).length new String(text) new String(removedText).trim().length() new String(removedText).trim().length new String(removedText).trim() new String(removedText).trim new String(removedText) String[] args args public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] text = sc.next().toCharArray();

        char[] removedText = new char[text.length];
        Arrays.fill(removedText, ' ');
        int index = 0;
        int destIndex = -1;
        for (int i = 0; i < text.length; i++) {
            if (destIndex < 0 || text[i] == removedText[destIndex]) {
                removedText[++destIndex] = text[i];
            } else {
                removedText[destIndex--] = ' ';
            }
        }

        System.out.println(new String(text).length() - new String(removedText).trim().length());
    }
} public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] text = sc.next().toCharArray();

        char[] removedText = new char[text.length];
        Arrays.fill(removedText, ' ');
        int index = 0;
        int destIndex = -1;
        for (int i = 0; i < text.length; i++) {
            if (destIndex < 0 || text[i] == removedText[destIndex]) {
                removedText[++destIndex] = text[i];
            } else {
                removedText[destIndex--] = ' ';
            }
        }

        System.out.println(new String(text).length() - new String(removedText).trim().length());
    }
} Main
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] text = sc.next().toCharArray();

        char[] removedText = new char[text.length];
        Arrays.fill(removedText, ' ');
        int index = 0;
        int destIndex = -1;
        for (int i = 0; i < text.length; i++) {
            if (destIndex < 0 || text[i] == removedText[destIndex]) {
                removedText[++destIndex] = text[i];
            } else {
                removedText[destIndex--] = ' ';
            }
        }

        System.out.println(new String(text).length() - new String(removedText).trim().length());
    }
}