jiahuimbzuai/CoQuIR huggingface dataset:
//  [typescript]
import * as fs from 'fs';

namespace AtCoder.abc130 {
    class ProgramB {
        args: string[];

        // 3 6
        // 3 4 5
        //
        // 2
        constructor(args: string[]) {
            this.args = args;
        }

        main(this: ProgramB) {

            const [n, x]: number[] = this.args[0].split(' ').map(Number);
            const l: number[] = this.args[1].split(' ').map(Number);

            let d: number = 0;
            let ans: number = 0;
            l.forEach((val: number) => {
                if (d <= x) ans++;
                d += val;
            });

            console.log(ans);

        }
    }

    const args: string[] = fs.readFileSync('/dev/stdin', 'utf8').trim().split('\n');
    new ProgramB(args).main();
}
//  [typescript]
import * as fs from "fs";

const input = (fs.readFileSync("/dev/stdin", "utf8") as string).split("\n");
const [n,x] = input[0].split(" ").map((x: string): number => +x);
const l = input[1].split(" ").map((x: string): number => +x);

let result = 0;
let sum = 0;
for(let i=0; i<n && sum<=x; i++){
  result++;
  sum += l[i];
}
console.log(result);
//  [typescript]
import fs = require('fs')
const input = fs.readFileSync('/dev/stdin', 'utf8').split('\n')

const [N, X] = input[0].split(' ').map(Number)


const L = input[0].split(' ').map(Number)

let s = 1
let p = 0
for (const l of L) {
    p += l
    if (p > X) { break }
    s++
}
console.log(s)
//  [python]
#!/usr/bin/env python3 ## -*- python -*-

s = input()

if "AB" in s:
  print("Yes")
elif "BA" in s:
  print("Yes")
else:
  print("No")
//  [python]
s = input()
if len(s) != 3:
    print('No')
if s.upper() == 'AAA' or s.upper() == 'BBB' :
    print('No')
else:
    print('Yes')
//  [python]
a = input()

if a == "AAA" or a == "BBB":
    print("No")
else:
    print("Yes")
//  [python]
s=input()
if s=="AAA" or "BBB":
  print("No")
else:
  print("Yes")
//  [python]
s = raw_input()
if(s == 'AAA' or s == 'BBB'):
    print("No")
else:
    print("Yes")
//  [python]
s=input()
if s=="AAA" or 'BBB':
  print('No')
else:
    print('Yes')
//  [java]
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
    public static void main(String[] args) throws IOException {
    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); //コンソールから入れる際に高速に入れる方法
		String x = br.readLine();
      	if(x.contains("A") && x.contains("B")) {
        	System.out.println("Yes");
        } else {
        	System.out.println("No");
        }
    }
}
//  [java]
import java.io.*;
import java.util.*;

public class Main {
    static Character[] toCharacterArray(String s) {
        if (s == null) {
            return null;
        }
        int len = s.length();
        Character[] array = new Character[len];
        for (int i = 0; i < len; i++) {
            array[i] = new Character(s.charAt(i));
        }
        return array;
    }

    public static void main(String[] args) throws Exception {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String arr = reader.readLine();

        Set<Character> S = new HashSet<Character>(Arrays.asList(toCharacterArray(arr)));
        System.out.println(1 < S.size() ? "Yes" : "No");
    }
}
//  [java]
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {

    public static void main(String[] args) throws Exception {

        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(is);

        List<String> mylist = new ArrayList<>();

        // 標準入力からの値を変数strinputに代入
        String strinput = reader.readLine();

        while (strinput != null) {

            mylist.add(strinput);
            strinput = reader.readLine();

        }

        String arr01[] = mylist.get(0).split(" ");

        String s = arr01[0];

        if (s.equals("AAA") || s.equals("BBB")) {
            System.out.println("No");
        } else {
            System.out.println("Yes");

        }

    }

}
//  [java]
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        if (s.charAt(0)==s.charAt(1) && s.charAt(1)==s.charAt(2)) {
            System.out.print("Yes");
        } else {
            System.out.print("No");
        }
    }
}
//  [java]
import java.util.Scanner;

fun main (args : Array<String>) {
  val input = Scanner(System.`in`)
  
  while (input.hasNext()) {
    val S = input.next()
    var countA = 0
    var countB = 0
    
    for (c in S) {
      if (c == 'A') {
        ++countA
      }
      
      if (c == 'B') {
        ++countB
      }
    }
    
    if (countA == 3 || countB == 3) {
      println("No")
    } else {
      println("Yes")
    }
  }
}
//  [cpp]
#include <cstdio>
using namespace std;

int main(int argc, char** argv)
{
	char a = getchar(), b = getchar(), c = getchar();
	getchar(); // Get the '\n'
	puts((a == b && b == c && a == c)? "No": "Yes");
	return 0;
}
//  [cpp]
#include <stdio.h>
#include "string.h" 
char s[4];
 
int main()
{
    scanf("%s",s);
    if(strcmp(s,"AAA")==0 ||strcmp(s,"BBB")==0){
        printf("No");
    }
    else{
        printf("Yes");
    }
  return 0;
}
//  [cpp]
#include <stdio.h>
#include <stdlib.h>
#include<string.h>
#include<ctype.h>
int main()
{
    char a[1000];
    scanf("%s",&a);
    for(int i=0;i<strlen(a);i++){
        if((a[i]==a[i+1] && a[i]!=a[i+2])||(a[i]==a[i+2] && a[i]!=a[i+1])){
        printf("Yes");
        break;}
        else if(a[i]==a[i+1] && a[i]==a[i+2]){
            printf("No");
            break;}}
    return 0;
}
//  [cpp]
#include <bits/stdc++.h>
using namespace std;
int main()
{
	string st;
	cin>>st;
	if(st[0]=='A' && st[1]=='A' && st[2]=='A' || st[0]=='B' && st[1]=='B' && st[2]=='B' )
		cout<<"Yes";
	else 
		cout<<"No";
	return 0;
}
//  [cpp]
#define LOCAL

#include<bits/stdc++.h>

using namespace std;

#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
#define LLINF 0x3f3f3f3f3f3f3f3f
#define INF 0x3f3f3f3f

using llong = long long;
using PII = pair<int, int>;

const llong MOD = 123456789LL;
const double PI = acos(-1);

int main() {
	IOS;
	string s; cin >> s;
	if (s == "AAA" || s == "BBB") cout << "No";
	else cout << "Yes";
}
//  [cpp]
#include <stdio.h>

int main (){
	char A[11];
	scanf("%s", &A);
	if(A[0]==A[1], A[1]==A[2])
	{ 
	puts("No"); 
	}
	else 
	{
	puts("Yes");	
	}
return 0;
}
//  [c]
#include <stdio.h>

int main(){
    char s[5];



    scanf("%s",s);

    if((s[0]=='A') && (s[1]=='B') && (s[2]=='A'))
        printf("Yes\n");
    else if((s[0]=='B') && (s[1]=='A') && (s[2]=='A'))
        printf("Yes\n");
    else if((s[0]=='A') && (s[1]=='A') && (s[2]=='B'))
        printf("Yes\n");
    else if((s[0]=='B') && (s[1]=='A') && (s[2]=='B'))
        printf("Yes\n");
    else if((s[0]=='A') && (s[1]=='B') && (s[2]=='B'))
        printf("Yes\n");
    else if((s[0]=='B') && (s[1]=='B') && (s[2]=='A'))
        printf("Yes\n");



    else
            printf("No\n");

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

int main(){
    char s[5];



    scanf("%s",s);

    if((s[0]=='A') && (s[1]=='B') && (s[2]=='A'))
        printf("Yes\n");
    else if((s[0]=='B') && (s[1]=='A') && (s[2]=='A'))
        printf("Yes\n");
    else if((s[0]=='A') && (s[1]=='A') && (s[2]=='B'))
        printf("Yes\n");
    else if((s[0]=='B') && (s[1]=='A') && (s[2]=='B'))
        printf("Yes\n");
    else if((s[0]=='A') && (s[1]=='B') && (s[2]=='B'))
        printf("Yes\n");
    else if((s[0]=='B') && (s[1]=='B') && (s[2]=='A'))
        printf("Yes\n");



    else if(((s[0]=='B')&& (s[1]=='B') && (s[2]=='B'))||((s[0]=='A') && (s[1]=='A') && (s[2]=='A')))
            printf("No\n");

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

int main (void){
    char s[3];
    scanf("%s",s);
    int i = -1;
    int flg = 0;
    while(++i < 3){
        if(s[i] != s[0])
            flg = 1;
    }
    if(flg)
        printf("Yes\n");
    else 
        printf("No\n");
    return 0;
}
//  [c]
    char s[3];
    scanf("%s", s);
    
    if(s[0]=s[1] && s[0]==s[2] && s[1]==s[2]){
    	puts("No");
	}
    else if(s[0]=s[1] && s[0]!=s[2] && s[1]!=s[2]){
    	puts("Yes");
	}
	else if(s[0]=s[2] && s[0]!=s[1] && s[1]!=s[2]){
		puts("Yes");
	}
	else if(s[1]=s[2] && s[0]!=s[1] && s[0]!=s[2]){
		puts("Yes");
    }
//  [c]
#include <stdio.h>
	int main(){
		char stat[3];
		scanf("%s", stat);
		if (stat[0] == stat[1] && stat[1] == stat[2] && stat[0] == stat[2]){
			printf("No");
		} else {
			printf ("Yes");
		}
		return 0;
	}
//  [c]
#include <stdio.h>
#include <string.h>
int main(void)
{
	char S[3],A[] = "AAA",B[] = "BBB";
	scanf("%s",S);
	if(strcmp(S,A) == 0 || strcmp(S,B) == 0){
		printf("No");
	}else{
		printf("Yes");
	}
	return 0;
}
//  [javascript]
function Main(input){
	var S = input.trim();
  	var W_MAX = 3;
  	var b = true;
  	if(S[0] === S[1] && S[0] === S[2])b=false;
  	var result = b?"Yes":"No";
  	console.log(result);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
function Main(input){
    var s = input.trim();

    if(s[0]==s[1]&&s[1]==s[2]){
        console.log("No");
    }else{
        console.log("Yes");
    }
}


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

const main = (arg) => {
  const S = arg.split('\n')[0].split('')
  if (S[0] != S[1] || S[0] != S[2] || S[1] != S[2]) {
    console.log('Yes')
  } else {
    console.log('No')
  }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))
//  [javascript]
function Main(input) {
	if (input === "AAA" || input === "BBB"){
	    return console.log("No");
	}else{
	    return console.log("Yes");
	}
}
 
 
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
function Main(input) {
    input = input.split(" ");
	if (input === "AAA" || input === "BBB"){
	    return console.log("No")
	}else{
	    return console.log("Yes");
	}
}
 
 
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
function Main(input) {
    input = input.split(" ");
	if (input === "AAA" || input === "BBB")  console.log("No");
  	else console.log("Yes");
}
 
 
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [go]
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)

	s := nextStr()

	if s[0] == s[1] && s[0] == s[2] {
		fmt.Println("No")
		return
	}

	fmt.Println("Yes")
}

// ---- readfunc
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"
	"strings"
)

var stdInScanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	stdInScanner.Scan()
	return stdInScanner.Text()
}

func main() {
	stdInScanner.Split(bufio.ScanWords)

	S := nextString()

	aCounter := 0
	bCounter := 0
	for _, s := range strings.Split(S, "") {
		switch s {
		case "A":
			aCounter++
		case "B":
			bCounter++
		}
	}
	if aCounter >= 1 && bCounter >= 1 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"io"
	"log"
	"os"
	"strconv"
	"strings"
)

func main() {
	s := readString()
	if strings.Contains(s, "AB") || strings.Contains(s, "BA") {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	log.SetFlags(log.Lshortfile)
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readInt() int {
	return int(readInt64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

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

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}
//  [go]
package main

import "fmt"

func main() {
	var companys []int = make([]int, 3)
	for i := 0; i < 3; i++ {
		fmt.Scan(&companys[i])
	}

	fmt.Println(check(companys))
}

func check(tSlice []int) string {
	for _, num := range tSlice {
		if num != tSlice[0] {
			return "Yes"
		}
	}
	return "No"
}
//  [go]
package main

import "fmt"

func main() {
	var companyNum int
	fmt.Scan(&companyNum)

	var companys []int = make([]int, companyNum)
	for i := 0; i < companyNum; i++ {
		fmt.Scan(&companys[i])
	}

	fmt.Println(check(companys))
}

func check(tSlice []int) string {
	for _, num := range tSlice {
		if num != tSlice[0] {
			return "Yes"
		}
	}
	return "No"
}
//  [go]
package main

import (
	"fmt"
)





func main() {
	
	var s string
	
	if s == "AAA" {
		fmt.Println("No")
	} else if s == "BBB" {
		fmt.Println("No")
	} else {
		fmt.Println("Yes")
	}

}
//  [ruby]
# https://atcoder.jp/contests/abc158/tasks/abc158_a


S = gets.chomp
cond = !%w[AAA BBB].include?(S)
puts cond ? 'Yes' : 'No'
//  [ruby]
S = gets.split("")
if S.include?("A") && S.include?("B") then
    puts "Yes"
else
    puts "No"
end
//  [ruby]
io = STDIN
str=io.gets.chomp
if str =="AAA" ||
 str =="BBB"
 puts 'No'
else
  puts 'Yes'
end
//  [ruby]
puts gets.chomp.chars.uniq.size!=1?'No':'Yes'
//  [ruby]
S = gets.split()
ans = S.uniq.length==1 ? "No" : "Yes" 
puts ans
//  [ruby]
S = gets.split("")
ans = S.chomp.uniq.length==1 ? "No" : "Yes" 
puts ans
//  [rust]
fn main() {
    let s = input();
    println!("{}", solve(s));
}

fn input() -> Vec<char> {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    buf.pop();
    let s = buf.chars();
    s.collect()
}

fn solve(s: Vec<char>) -> String {
    let mut a = 0;
    let mut b = 0;
    for c in s.iter() {
        if *c == 'A' { a += 1; }
        else if *c == 'B' { b += 1; }
    }
    if a != 0 && b != 0 {
        return String::from("Yes");
    }
    String::from("No")
}
//  [rust]
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn f(s: &[char]) -> bool {
    let m = s.len();
    for i in 0..m {
        if s[i] != s[m - 1 - i] {
            return false;
        }
    }
    true
}

use std::iter::Iterator;

fn main() {
    input! {
        s: String,
    }

    if s == "AAA" || s == "BBB" {
        println!("No")
    }else{
        println!("Yes")
    }
    
}
//  [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: chars
    }
    if s[0] == s[1] && s[1] == s[2] {
        println!("No");
    } else {
        println!("Yes");
    }
}
/* vim:set foldmethod=marker: */
//  [rust]
use proconio::input;

fn main() {
    input! {
        s: String,
    }

    solve(s);
}

fn solve(s: String) {
    match s.as_str() {
        "AAA" | "BBB" => println!("Yes"),
        _ => println!("No"),
    }
}
//  [rust]
use proconio::input;
use std::collections::HashMap;

/// 状態
#[derive(Hash, Eq, PartialEq, Ord, PartialOrd, Clone, Copy)]
struct State {
    /// 受理状態かどうか
    is_accept: bool,
    /// State間を比較できるように，IDをつけておく
    id: usize,
}

/// 有限オートマトンを表す構造体
struct Automaton {
    /// 状態の有限集合Q
    states: HashMap<String, State>,
    /// 遷移関数群
    transitions: HashMap<State, Box<dyn Fn(char) -> String>>,
    /// Stateにつける通し番号
    id: usize,
}

impl Automaton {
    /// ある状態qと, qからの遷移関数を登録する
    fn add_states(&mut self, name: &str, is_accept: bool, transition: fn(char) -> String) {
        let state = State {
            is_accept,
            id: self.id,
        };
        self.id += 1;
        self.states.insert(name.to_string(), state);
        self.transitions.insert(state, Box::new(transition));
    }

    /// 言語Lで記述された文字列sを受理するか判定
    fn run(&self, s: String) -> bool {
        let mut current_state = *self.states.get("q0").unwrap();
        for c in s.chars() {
            let transition = self.transitions.get(&current_state).unwrap();
            let next_state_name = transition(c);
            current_state = *self.states.get(&next_state_name).unwrap();
        }
        current_state.is_accept
    }
}

fn transition_q0(c: char) -> String {
    if c == 'A' {
        return "q2".to_string();
    }

    "q1".to_string()
}
fn transition_q1(c: char) -> String {
    if c == 'B' {
        return "q3".to_string();
    }

    "q1".to_string()
}
fn transition_q2(c: char) -> String {
    if c == 'A' {
        return "q3".to_string();
    }

    "q2".to_string()
}
fn transition_q3(_c: char) -> String {
    "q3".to_string()
}

fn main() {
    input! {
        s: String,
    }

    let mut m = Automaton {
        states: HashMap::new(),
        transitions: HashMap::new(),
        id: 0,
    };

    m.add_states("q0", false, transition_q0);
    m.add_states("q1", false, transition_q1);
    m.add_states("q2", false, transition_q2);
    m.add_states("q3", true, transition_q3);

    if m.run(s) {
        println!("Yes");
    } else {
        println!("No");
    }
}
//  [swift]
let input_line=readLine()!
if input_line == "AAA" {
  print("No")
} else if input_line == "BBB"{
  print("No")
}else{  
 print("Yes")
}
//  [swift]
let busLine = readLine()!
var A = ""
var B = ""
var answer = "Yes"
for _ in 0..<busLine.characters.count{
  A += "A"
  B += "B"
  if busLine == A || busLine == B{
    answer = "No"
  }
}
print(answer)
//  [swift]
func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func main() {
    let s = Set(Array(readLine()!))
    
    if s.count == 1 {
        print("No")
    } else {
        print("Yes")
    }
}

main()
//  [swift]
let busLine = readLine()!
var A = ""
var B = ""
var answer = "Yes"
for _ in 0..<busLine.characters.count{
  A += "A"
  B += "B"
  if busLine == A || busLine == B{
    answer = "No"
  }
}
//  [swift]
let busLine = readLine()!
var A = ""
var B = ""
var answer = "Yes"
for _ in 0..<busLine.character.count{
  A += "A"
  B += "B"
  if busLine == A || busLine == B{
    answer = "No"
  }
}
//  [swift]
let busLine = readLine()!
var A = ""
var B = ""
var answer = "Yes"
for _ in 0..<b.character.count{
  A += "A"
  B += "B"
  if busLine == A || busLine == B{
    answer = "No"
  }
}
//  [typescript]
function Main(input: string) {
  const lines: string[] = input.split('\n');
  const line = lines[0];
  if (line === 'AAA' || line === 'BBB') {
    console.log('No');
  } else {
    console.log('Yes');
  }
}

Main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [typescript]
import * as fs from 'fs';
const input = fs.readFileSync("/dev/stdin", "utf8")
console.log(input.trim().split("").reduce((ng, c) => ng && c === input[0], true) ? "No" : "Yes");
//  [typescript]
import * as fs from "fs";

const split = (str: string): string[] =>
  str.split(" ").map((v: string) => v.trim());
const split_number = (str: string): number[] =>
  split(str).map((v: string) => +v);

export function main(input: string) {
  const lines = input.split("\n");
  const n = lines[0].split('');

  let check = "";
  for (let i = 0; i < n.length; i++) {
    if (i > 0 && n[i] !== check) {
      return "Yes";
    } else {
      check = n[i];
    }
  }

  return "No";
}

if (!process.env.LOCAL_DEBUG) {
  console.log(main(fs.readFileSync("/dev/stdin", "utf8")));
}
//  [typescript]
import * as fs from 'fs';
console.log(fs.readFileSync("/dev/stdin", "utf8").split("").reduce((ng, c) => ng && c === input[0], true) ? "No" : "Yes");
//  [typescript]
import fs from 'fs';
console.log(fs.readFileSync("/dev/stdin", "utf8").split("").reduce((ng, c) => ng && c === input[0], true) ? "No" : "Yes");
//  [typescript]
import * as fs from 'fs';
const input = fs.readFileSync("/dev/stdin", "utf8")
console.log(input.trim().split(''));
console.log(input.split("").reduce((ng, c) => ng && c === input[0], true) ? "No" : "Yes");
//  [python]
s=input()
n=int(input())
l=len(s)
ct=0
for i in range(l-1):
 if s[i]==s[i+1]:
  ct=ct+0.5
 else:
  ct=int(ct+0.5)
ct=int(ct+0.5)
s1=s*3
l1=l*3
ct1=0
for i in range(l1-1):
 if s1[i]==s1[i+1]:
  ct1+=0.5
 else:
  ct1=int(ct1+0.5)
ct1=int(ct1+0.5)
ans=int((ct1-ct*3)/2*(n-1)+0.5)+ct*n
print(ans)
//  [python]
s = input()
k = int(input())
if len(set(list(s))) == 1:
  print(len(s)*k//2)
  exit()
l = list()
t = 0
c = s[0]
for x in s:
  if x == c:
    t += 1
  else:
    c = x
    l.append(t)
    t = 1
l.append(t)
ans = 0
if s[0]==s[-1]:
  ans += l[0]//2 + l[-1]//2 - (l[0]+l[-1])//2
  l[0] += l[-1]
  l.pop()
for x in l:
  ans += (x//2)*k
print(ans)
//  [python]
from itertools import groupby as gb
s=input()
k=int(input())
if len(set(s))==1:print((len(s)*k)//2);exit()
elif len(s)==2 and len(set(list(s)))==1:print(k);exit()
ji=[len(list(b))//2 for a,b in gb(s)]
l=k*sum(ji)
if s[0]==s[-1]:
  ji=[len(list(b)) for a,b in gb(s)]
  if ji[0]%2 and ji[-1]%2:l+=k-1
print(l)
//  [python]
s = input()
flag = [1 for _ in range(len(s))]
k = int(input())
counter = 0
for i in range(len(s)):
    if s[i-1] == s[i] and flag[i-1] and flag[i]:
        counter += 1
        flag[i] = 0
        flag[i-1] = 0
print(counter*k - (1 if k == 1 else 0))
//  [python]
s = input()
flag = [1 for _ in range(len(s))]
k = int(input())
counter = 0
for i in range(len(s)):
    if s[i-1] == s[i] and flag[i-1] and flag[i]:
        counter += 1
        flag[i] = 0
        flag[i-1] = 0
print(counter*k)
//  [python]
#!/usr/bin/env python3

#import
#import math
#import numpy as np
#= int(input())
S = input()
K = int(input())
ls = len(S)
t1 = []

t = 1
for i in range(1, ls):
    if S[i - 1] == S[i]:
        t += 1
    else:
        if t > 1:
            t1.append(t)
        t = 1

if t > 1:
    t1.append(t)

ans = 0
for t in t1:
    ans += t // 2

if len(t1) == 1:
    if t1[0] == ls:
        print(ls * K // 2)

else:
    if S[0] != S[-1]:
        print(ans * K)
    
    else:
        ta = t1[0]
        tb = t1[-1]
        print(ans * K - (ta // 2 + tb // 2 - (ta + tb) // 2) * (K - 1))
//  [java]
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
 
public class Main {	
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
		String s = br.readLine();		
		long k = Integer.parseInt(br.readLine());	
		int cnt = 1;
		long sum = 0;
		char c = s.charAt(0);
		boolean allSame = true;
		for (int i = 1; i < s.length(); i++) {
			if (c != s.charAt(i)) {
				sum += cnt/2;
				cnt = 1;
				c = s.charAt(i);
				allSame = false;
			}else
				cnt++;
		}
		if (allSame) {
			bw.write((k * s.length()) / 2 + "\n");
			bw.flush();
			return;
		}
		sum += cnt/2;
		if (s.charAt(0)!=s.charAt(s.length()-1)) {
			bw.write(sum*k + "\n");
			bw.flush();
			return;
		}
		s += s;
		cnt = 1;
		long sum2 = 0;
		c = s.charAt(0);
		for (int i = 1; i < s.length(); i++) {
			if (c != s.charAt(i)) {
				sum2 += cnt/2;
				cnt = 1;
				c = s.charAt(i);
			}else
				cnt++;
		}
		sum2 += cnt/2;
		bw.write(sum + (sum2-sum)*(k-1) + "\n");
		bw.flush();
		bw.close();
		br.close();
	}
}
//  [java]
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.lang.*;

public class Main{
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		String s = sc.next();
		long k = sc.nextLong();
		long ans = 0;
		int len = 1;
		for (int i = 0; i < s.length() - 1; i++) {
			if (s.charAt(i + 1) == s.charAt(i)) {
				len++;
			} else {
				ans += len / 2;
				len = 1;
			}
		}
		ans += len / 2;
		ans *= k;
		if (s.charAt(0) == s.charAt(s.length() - 1)) {
			int maelen = 1;
			for (int i = 1; i < s.length(); i++) {
				if (s.charAt(i) == s.charAt(i - 1)) {
					maelen++;
				} else {
					break;
				}
			}
			int atolen = 1;
			for (int i = s.length() - 2; i >= 0; i--) {
				if (s.charAt(i) == s.charAt(i + 1)) {
					atolen++;
				} else {
					break;
				}
			}
			if (maelen == s.length()) {
				ans = s.length() * k / 2;
			} else {
				ans -= (maelen / 2 + atolen / 2 - (maelen + atolen) / 2) * (k - 1);
			}
		}
		System.out.println(ans);
	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;
	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 || Integer.MAX_VALUE < nl) {
			throw new NumberFormatException();
		}
		return (int) nl;
	}
	public double nextDouble() {
		return Double.parseDouble(next());
	}
}
//  [java]
import java.io.*;
import java.util.*;

public class Main {
    static MyReader in = new MyReader();

    public static void main(String[] args) {
        char[] S = new char[100];
        int N = in.read(S);

        long K = in.i();

        char c = ' ';
        long ans = 0;
        int i = 0;
        int j = 0;
        for ( ; i < N; i++) {
            if (S[i] != c) {
                ans += (i - j) / 2 * K;
                c = S[i];
                j = i;
            }
        }
        if (S[0] == c) {
            i = 1;
            for ( ; i < N && S[i] == c; i++);
            int k = N - j;
            ans += (K - 1) * ((i + k) / 2 - i / 2) + k / 2;
        } else {
            ans += (i - j) / 2 * K;
        }

        System.out.println(ans);
    }
}

class MyReader extends BufferedReader {
    char[] cbuf = new char[1024];
    int head = 0;
    int tail = 0;

    MyReader() {
        super(new InputStreamReader(System.in));
    }

    char next() {
        if (head == tail) {
            try {
                tail = super.read(cbuf, 0, cbuf.length);
            } catch (IOException e) {
                e.printStackTrace();
            }
            head = 0;
        }
        return cbuf[head++];
    }

    int i() {
        int k = next() - '0';
        boolean minus = k == -3;
        int n = minus ? 0 : k;
        while (0 <= (k = next() - '0') && k <= 9) n = 10 * n + k;
        return minus ? -n : n;
    }

    int[] ii(final int N) {
        int[] a = new int[N];
        for (int j = 0; j < a.length; j++) a[j] = i();
        return a;
    }

    long l() {
        int k = next() - '0';
        boolean minus = k == -3;
        long n = minus ? 0 : k;
        while (0 <= (k = next() - '0') && k <= 9) n = 10 * n + k;
        return minus ? -n : n;
    }

    char[] s(final int N) {
        char[] s = new char[N];
        for (int i = 0; i < N; i++) {
            s[i] = next();
        }
        next();
        return s;
    }

    public int read(char[] cbuf) {
        int i;
        char c;
        for (i = 0; (c = next()) != ' ' && c != '\n'; i++) cbuf[i] = c;
        return i;
    }

    public String readLine() {
        try {
            return super.readLine();
        } catch (IOException e) {
            return null;
        }
    }
}
//  [java]
import java.util.*;

public class Main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        long K = sc.nextLong();
        char[] s = S.toCharArray();
        char tmp = 0;
        boolean key = false;
        long count = 0;
        char one = s[0];
        boolean ok = true;
        for (int i = 1; i < s.length; i++) {
            if (s[i] != one) {
                ok = false;
            }
        }
        if (ok) {
            System.out.println(K*s.length/2);
            return;
        }
        for (char c : s) {
            if (!key && c == tmp) {
                key = true;
                count++;
            } else if (key) {
                key = false;
            }
            tmp = c;
        }
        long count2 = 0;
        for (char c : s) {
            if (!key && c == tmp) {
                key = true;
                count2++;
            } else if (key) {
                key = false;
            }
            tmp = c;
        }
        for (char c : s) {
            if (!key && c == tmp) {
                key = true;
                count2++;
            } else if (key) {
                key = false;
            }
            tmp = c;
        }
        if (K == 1) {
            System.out.println(count);
        } else {
            System.out.println(count + (count2-count)*(K-1));
        }
    }
}
//  [java]
import java.util.*;

public class Main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        int K = sc.nextInt();
        char[] s = S.toCharArray();
        char tmp = 0;
        boolean key = false;
        long count = 0;
        char one = s[0];
        boolean ok = true;
        for (int i = 1; i < s.length; i++) {
            if (s[i] != one) {
                ok = false;
            }
        }
        if (ok) {
            System.out.println(K*s.length/2);
            return;
        }
        for (char c : s) {
            if (!key && c == tmp) {
                key = true;
                count++;
            } else if (key) {
                key = false;
            }
            tmp = c;
        }
        long count2 = 0;
        for (char c : s) {
            if (!key && c == tmp) {
                key = true;
                count2++;
            } else if (key) {
                key = false;
            }
            tmp = c;
        }
        for (char c : s) {
            if (!key && c == tmp) {
                key = true;
                count2++;
            } else if (key) {
                key = false;
            }
            tmp = c;
        }
        if (K == 1) {
            System.out.println(count);
        } else {
            System.out.println(count + (count2-count)*(K-1));
        }
    }
}
//  [cpp]
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
using namespace std;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0' && ch<='9')x=x*10+ch-'0',ch=getchar();
    return x*f;
}
int stack[20];
inline void write(int x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
inline void pr1(int x){write(x),putchar(' ');}
inline void pr2(int x){write(x),puts("");}
char ss[110];
int main()
{
    //freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	scanf("%s",ss+1);int len=strlen(ss+1);
	int m=read();
	int s1=1;
	for(int i=2;i<=len;i++)
	{
		if(ss[i]==ss[i-1])s1++;
		else break;
	}
	if(s1==len){printf("%lld\n",1LL*len*m/2);return 0;}
	int s2=1;
	for(int i=len-1;i>=1;i--)
	{
		if(ss[i]==ss[i+1])s2++;
		else break;
	}
	int tot=0,d=0;
	for(int i=s1+1;i<=len-s2+1;i++)
	{
		if(ss[i]!=ss[i-1])tot+=d/2,d=1;
		else d++;
	}
	int sum=s1/2+tot+s2/2;
	if(ss[1]==ss[len])printf("%lld\n",1LL*((s1+s2)/2+tot)*(m-1)+sum);
	else printf("%lld\n",1LL*sum*m);
	return 0;
}
//  [cpp]
#include <bits/stdc++.h>
using namespace std;
#define repr(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;

int main(){
    string S;
    ll K,len,x,y=1,z=0,j=0,jj=0,k=0,u=0;
    bool judge=true;
    cin >> S >> K;
    x=S.size();
    for(ll i=1;i<x;i++){
        if(S[i-1]!=S[i]) judge=false;
    }
    if(judge){
        len=x*K;
        cout << len/2 << endl;
    }else{
        while(S[j]==S[j+1]){
            ++j;
        }
        for(ll i=j+1;i<x;i++){
            if(S[i-1]==S[i]) y++;
            else{
                z+=y/2;
                y=1;
            }
        }
        if(S[0]==S[x-1]){
            jj=y;
            y++;
            while(S[k]==S[k+1]){
                ++k;
                ++y;
            }
            z+=y/2;
            if(jj%2==1 && y%2==0) u=1;
            ll total = z*K-u;
            cout << total << endl;
        }else{
            ll y=1,z=0;
            for(ll i=1;i<x;i++){
                if(S[i-1]==S[i]) y++;
                else{
                    z+=y/2;
                    y=1;
                }
            }
            z+=y/2;
            cout << z*K << endl;
        }
    }

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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) ((a+b-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX/2

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> void YesNo(T a) {cout<<(a?"Yes":"No")<<endl;}
template<class T> void YESNO(T a) {cout<<(a?"YES":"NO")<<endl;}
void vin(Vi &v){REP(i,0,(v).size()) cin>>v[i];}
void vin(Vi &v,Vi &v2){REP(i,0,(v).size()) cin>>v[i]>>v2[i];}
void vout(Vi &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());}
int ctoi(char c){if(c>='0'&&c<='9'){return c-'0';}return 0;}
void accum(Vi &v){REP(i,1,(v).size()) v[i]+=v[i-1];}
bool comp(Pii a,Pii b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}


void solve(std::string s, long long k){
    Vi a;
    int now=1,ans=0;
    if(s.size()==1){cout<<k/2<<endl;return;}
    REP(i,1,s.size()){
        if(s[i]==s[i-1]){
            now++;
        }else{
            a.pb(now);
            now=1;
        }
        if(i==s.size()-1) a.pb(now);
    }
    if(a.size()==1){
        cout<<(s.size()*k)/2<<endl;
        return;
    }
    if(s[0]!=s[s.size()-1]) REP(i,0,a.size()) ans += (a[i]/2)*k;
    else{
        REP(i,1,a.size()-1) ans += (a[i]/2)*k;
        ans += a[0]/2;
        ans += a[a.size()-1]/2;
        ans += (a[0]+a[a.size()-1])/2*(k-1);
    }
    cout<<ans<<endl;
}

// Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
signed main(){
    std::string S;
    std::cin >> S;
    long long K;
    scanf("%lld",&K);
    solve(S, K);
    return 0;
}
//  [cpp]
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define print(x) cout << (x) << endl
typedef long long ll;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;

using namespace std;

int main(){
    string s;   cin >> s;
    ll k;  cin >> k;
    int l = s.length();
    if(l == 1){print(k / 2); return 0;}
    ll i = 1, cnt = 0;
    vector<int> c(l,0);
    while(i < l){
        if(s[i] == s[i-1]){
            c[i] = 1;
            i += 2;
        }else   i++;
    }
    for(int i=0; i<l; i++) cnt += c[i];
    ll ans = cnt * k;
    if(s[0] == s[l-1]){
        if(c[l-1] == 0) ans += (k - 1); 
    }
    print(ans);
}
//  [cpp]
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i< (n); i++)
using ll = long long;
using namespace std;

int main(){
	string S;
	ll K;
	cin >> S >> K;
	ll ans = 0;
	string A = "", B="";
	int i = 1;
	A += S[0];
	while (i<S.size() ) {
		if (S[i] != S[0]) break;
		A += S[i];
		i++;
	}
	while (i<S.size() ) {
		B += S[i];
		i++;
	}
	B += A;
	char now = B[0];
	ll cnt = 1;
	for (int i = 1; i < B.size(); i++) {
		if (B[i] == now)	cnt++;
		else {
			ans += (cnt/2)*K;
			cnt = 1;
			now = B[i];
		}
	}
	ans += (cnt/2)*(K-1);
	ll p = cnt - A.size();
	ans += (p/2) + A.size()/2;

	if (B.size() == 1) ans = K/2;

	cout << ans << endl;
	return 0;
}
//  [cpp]
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i< (n); i++)
using ll = long long;
using namespace std;

int main(){
	string S;
	ll K;
	cin >> S >> K;
	ll ans = 0;
	string A = "", B="";
	int i = 1;
	A += S[0];
	while (i<S.size() ) {
		if (S[i] != S[0]) break;
		A += S[i];
		i++;
	}
	while (i<S.size() ) {
		B += S[i];
		i++;
	}
	B += A;
	char now = B[0];
	ll cnt = 1;
	for (int i = 1; i < B.size(); i++) {
		if (B[i] == now)	cnt++;
		else {
			ans += (cnt/2)*K;
			cnt = 1;
			now = B[i];
		}
	}
	ans += (cnt/2)*(K-1);
	ll p = cnt - A.size();
	ans += (p/2) + A.size()/2;

	if (B.size() == 1) ans = K/2;

	cout << ans << endl;
	return 0;
//  [c]
#include <stdio.h>
#include <stdlib.h>

int main()
{
	long long K;
	char S[101];
	scanf("%s", S);
	scanf("%lld", &K);
	
	int l, flag = 1;
	for (l = 0; S[l+1] != 0; l++) if (S[l] != S[l+1]) flag = 0;
	if (flag == 1) {
		printf("%lld\n", K * (l + 1) / 2);
		fflush(stdout);
		return 0;
	}
	
	int i, count = 0, tmp = 1;
	if (S[0] == S[l++]) flag = 1;
	for (i = 1; i < l; i++) {
		if (S[i] == S[i-1]) tmp++;
		else {
			count += tmp / 2;
			tmp = 1;
		}
	}
	count += tmp / 2;
	for (i = 1; S[i] == S[i-1]; i++);
	if (i % 2 == 0) flag = 0;
	for (i = l - 2; S[i] == S[i+1]; i--);
	if ((l - i - 1) % 2 == 0) flag = 0;
	
	if (flag == 1) printf("%lld\n", K * count + (K - 1));
	else printf("%lld\n", K * count);
	fflush(stdout);
	return 0;
}
//  [c]
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
typedef const void cv;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define per(i,n) for((i)=(n)-1;(i)>=0;(i)--)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max((a),(b))-min((a),(b)))
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll nPr(int n,int r){ll i,result=1;rep(i,r){result*=(ll)(n-i);}return result;}
ll nCr(int n,int r){ll i,result=1;if(n<r) return 0;rep(i,min(r,n-r)){result*=(ll)(n-i);result/=(ll)(i+1);}return result;}
#define nHr(n,r) nCr((int)((n)+(r)+1),(int)(r))
#define sankaku(x) (((x)*((x)+1))/2)
int dx[8]={1,0,-1,0,1,-1,-1,1};
int dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(const void *a, const void *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(const void *a, const void *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(const void* left, const void* right) {return strcmp((char *)left,(char *)right);}
int downchar(const void* left, const void* right) {return strcmp((char *)right,(char *)left);}
ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
void initialize(){
    
}
int main(void){
  initialize();
  ll n,m,i,j,k,result=0;
  ll a=0,b=0;
  char s[LIMIT1];
  
  scanf("%s",s);
  scanf("%lld",&k);
  j=1;
  n = strlen(s);
  rep(i,n){
	if(i!=n-1&&s[i]==s[i+1]) j++;
    else{
      result += (ll)floorl(j/2.0);
      j=1;
    }
  }
  a=1;
  b=1;
  rep(i,n-1){
    if(s[i]!=s[i+1]) break;
    a++;
  }
  per(i,n-1){
    if(s[i]!=s[i+1]) break;
    b++;
  }
  result *= k;
  if(s[0]==s[n-1]){
    if(a==b && a==n) result = (ll)floorl(n*k/2);
    else result -= (k-1)*(ll)(floorl(a/2.0)+floorl(b/2.0)-floorl((a+b)/2.0));
  }
  printf("%lld",result);
  return 0;
}
//  [c]
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdint.h>
#include<stdbool.h>
#include<tgmath.h>
#include<sys/queue.h>
#include<time.h>
#define ll long long
#define min(a, b) ((a) > (b) ? (b) : (a))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define miin(a, b, c) min((a), min((b), (c)))
#define maax(a, b, c) max((a), max((b), (c)))
#define mod 1000000007

char s[111];
ll k;

main(){
    scanf("%s%lld", s, &k);
    int l = strlen(s);
    if(s[0] != s[l-1]){
        ll a = 0, b = 1;
        for(int i=1; i<l; i++){
            if(s[i] == s[i-1]){
                b++;
            }else {
                a += b / 2;
                b = 1;
            }
        }
        a += b/2;
        printf("%lld\n", k * a);
        return 0;
    }
    ll a = 0, b = 1, c = 1, i = 1;
    for(;i<l && s[i]==s[i-1]; i++){
        c++;
    }
    if(i == l){
        printf("%lld\n", l * k / 2);
        return 0;
    }
    for(; i<l; i++){
        if(s[i]==s[i-1]){
            b++;
        }else {
            a += b / 2;
            b = 1;
        }
    }
    printf("%lld\n", a * k + ((b + c)/2)*(k-1)+ b/2 + c/2);
    return 0;
}
//  [c]
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

typedef long long ll;

int main(void){
  char s[101];
  ll k;

  scanf("%s %lld",s ,&k);

  ll count = 0;
  int len = strlen(s);

  if(s[0] == s[len-1] && s[0] == s[1]){
    s[0] = '&';
    count ++;
  }
  
  for(int i = 0;s[i+1] != '\0';i ++){
    if(s[i] == s[i+1]){
      s[i+1] = '&';
      count ++;
    }
  }
  
  if(s[0] == s[len-1]){
    printf("%lld",k*count + k-1);
  }

  else{
    printf("%lld",k*count);
  }

  return 0;

}
//  [c]
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

typedef long long ll;

int main(void){
  char s[101];
  ll k;

  scanf("%s %lld",s ,&k);

  ll count = 0;
  for(int i = 0;s[i+1] != '\0';i ++){
    if(s[i] == s[i+1]){
      s[i] = '&';
      count ++;
    }
  }
  
  int len = strlen(s);
  
  if(s[0] == s[len-1]){
    printf("%lld",k*count + k-1);
  }

  else{
    printf("%lld",k*count);
  }

  return 0;

}
//  [c]
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

typedef long long ll;

int main(void){
  char s[101];
  ll k;

  scanf("%s %lld",s ,&k);

  ll count = 0;
  for(int i = 0;s[i+1] != '\0';i ++){
    if(s[i] == s[i+1]){
      s[i+1] = '&';
      count ++;
    }
  }
  
  int len = strlen(s);
  
  if(s[0] == s[len-1]){
    printf("%lld",k*count + k-1);
  }

  else{
    printf("%lld",k*count);
  }

  return 0;

}