f = gets.chomp puts f.scan("(^^*)").size f.scan("(*^^)").size