#import <Foundation/Foundation.h>
typedef long long Int;
int main() {
	@autoreleasepool{
		char c, s='\0', e, prev='\0';
		Int current = 1;
		NSMutableArray *a = [NSMutableArray array];
		while((c=getchar())!='\n'){
			if(prev==c){
				current++;
			}else if(s!='\0'){
				[a addObject:@(current)];
				current = 1;
			}
			if(s=='\0') s=c;
			prev = c;
		}
		e=prev;
		Int k;
		scanf("%lld",&k);
		[a addObject:@(current)];
		if(s!=e){
			Int ans = 0;
			for(NSNumber *v in a) ans += [v integerValue]/2;
			printf("%lld\n",ans*k);
		}else{
			Int n = [a count];
			Int p = [[a objectAtIndex:0] integerValue];
			if(n>1){
				Int q = [[a objectAtIndex:n-1] integerValue];
				Int ans = p/2 + q/2;
				ans += (p+q)/2*(k-1);
				for(Int i=1;i<=n-2;i++) ans += [[a objectAtIndex:i] integerValue]/2 * k;
				printf("%lld\n",ans);
			}else{
				printf("%lld\n",p*k/2);
			}
		}
	}
}