Problem:
Score : 300 points

Problem Statement

N tiles are arranged in a row from left to right. The initial color of each tile is represented by a string S of length N.

The i-th tile from the left is painted black if the i-th character of S is 0, and painted white if that character is 1.

You want to repaint some of the tiles black or white, so that any two adjacent tiles have different colors.

At least how many tiles need to be repainted to satisfy the condition?

Constraints

1 \leq |S| \leq 10^5

S_i is 0 or 1.

Input

Input is given from Standard Input in the following format:

S

Output

Print the minimum number of tiles that need to be repainted to satisfy the condition.

Sample Input 1

000

Sample Output 1

1

The condition can be satisfied by repainting the middle tile white.

Sample Input 2

10010010

Sample Output 2

3

Sample Input 3

0

Sample Output 3

0

Solution in Java8 (OpenJDK 1.8.0) (judge verdict: Accepted)

import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			String S = scan.next();
			int N = S.length();
			
			StringBuffer sb = new StringBuffer(S);
			StringBuffer sc = new StringBuffer(S);
			sc.reverse();
			//String SR =sc.toString();
			int count = 0;
			int countR = 0;
			
			if(N==1) {
				System.out.println(0);
			}else {
				
			
			for(int i = 1;i<N;i++) {
				String su = sb.substring(i-1, i);
				String sm = sb.substring(i, i+1);
				if(sm.equals(su)&&sm.equals("1")) {
					sb.replace(i, i+1, "0");
					count++;
					//System.out.println(sb);
				}else if(sm.equals(su)&&sm.equals("0")) {
					sb.replace(i, i+1, "1");
					count++;
					//System.out.println(sb);
				}
			}
			System.out.println();
				
			for(int i = 1;i<N;i++) {
				String su = sc.substring(i-1, i);
				String sm = sc.substring(i, i+1);
				if(sm.equals(su)&&sm.equals("1")) {
					sc.replace(i, i+1, "0");
					countR++;
					//System.out.println(sc);
				}else if(sm.equals(su)&&sm.equals("0")) {
					sc.replace(i, i+1, "1");
					countR++;
					//System.out.println(sc);
				}
			}
			
			System.out.println(count>countR?countR:count);
			
			
			}
			
			
		}
		
		
	}
		

}