Language: C++


#define ll long long int
#include <bits/stdc++.h>
using namespace std;

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

#define ff               first
#define ll long long int
#include <bits/stdc++.h>
using namespace std;

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

#define ff               first
#define ss               second
#define mp               make_pair
#define pb               push_back
#define pf               push_front
#define vi               vector<ll>
#define pii              pair<ll,ll>
#define qi               queue<ll>
#define mem(a,b)         memset(a,b,sizeof(a))
#define print(a)         cout<<a<<'\n'
#define sorted(arr)      sort(arr.begin(),arr.end())
#define gcd(a,b)         gcd((a),(b))
#define lcm(a,b)         ((a)*(b))/gcd((a),(b))
#define all(v)           v.begin(),v.end()
#define read(a)          scanf("%d", &a)
#define f(a,n)           for(ll i=a;i<n;i++)
#define in(a,n,arr)      for(ll i=a;i<n;i++)cin>>arr[i];
#define in2(n,m,arr)     for(ll i=0;i<n;i++){for(ll j=0;j<m;j++)cin>>arr[i][j];}
#define debug(a)         cerr<<a<<" ";
#define debug1(a)        cerr<<a<<'\n'

const unsigned ll mod= (ll)1e9 + 7;
const ll inf = (ll)1e18 + 42;
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll t;
    t=1;
    //cin >> t;
    while(t --)
    {
        string s;
        cin >> s;
        ll k;
        cin >> k;
        ll f = 0 , ans = 0 , h = 0;
        //fill(arr,arr+s.size(),0);
        for(ll i=1;i<s.size();i++)
        {
            if(s[i] == s[i-1])
            {
                s[i] = '#';
                if( i == 2)
                    h = 1;
                ans ++;
            }
            else
                f = 0;
        }
        ll temp = 0;
        if(s[0] == s[s.size() -1 ]&&s.size() != 2)
            temp = k - 1;
        print((ans * k)+temp);
    }
        
    
    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
    
}

#define ss               second
#define mp               make_pair
#define pb               push_back
#define pf               push_front
#define vi               vector<ll>
#define pii              pair<ll,ll>
#define qi               queue<ll>
#define mem(a,b)         memset(a,b,sizeof(a))
#define print(a)         cout<<a<<'\n'
#define sorted(arr)      sort(arr.begin(),arr.end())
#define gcd(a,b)         gcd((a),(b))
#define lcm(a,b)         ((a)*(b))/gcd((a),(b))
#define all(v)           v.begin(),v.end()
#define read(a)          scanf("%d", &a)
#define f(a,n)           for(ll i=a;i<n;i++)
#define in(a,n,arr)      for(ll i=a;i<n;i++)cin>>arr[i];
#define in2(n,m,arr)     for(ll i=0;i<n;i++){for(ll j=0;j<m;j++)cin>>arr[i][j];}
#define debug(a)         cerr<<a<<" ";
#define debug1(a)        cerr<<a<<'\n'

const unsigned ll mod= (ll)1e9 + 7;
const ll inf = (ll)1e18 + 42;
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll t;
    t=1;
    //cin >> t;
    while(t --)
    {
        string s;
        cin >> s;
        ll k;
        cin >> k;
        ll f = 0 , ans = 0 , h = 0;
        //fill(arr,arr+s.size(),0);
        for(ll i=1;i<s.size();i++)
        {
            if(s[i] == s[i-1])
            {
                s[i] = '#';
                if( i == 2)
                    h = 1;
                ans ++;
            }
            else
                f = 0;
        }
        print((ans * k));
    }
        
    
    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
    
}


Compiler output:
a.cc:44:9: error: attribute value 'tune=native' was already specified in 'target' attribute
   44 | int32_t main()
      |         ^~~~
a.cc:104:19: error: redefinition of 'const long long unsigned int mod'
  104 | const unsigned ll mod= (ll)1e9 + 7;
      |                   ^~~
a.cc:42:19: note: 'const long long unsigned int mod' previously defined here
   42 | const unsigned ll mod= (ll)1e9 + 7;
      |                   ^~~
a.cc:105:10: error: redefinition of 'const long long int inf'
  105 | const ll inf = (ll)1e18 + 42;
      |          ^~~
a.cc:43:10: note: 'const long long int inf' previously defined here
   43 | const ll inf = (ll)1e18 + 42;
      |          ^~~
a.cc:106:9: error: attribute value 'tune=native' was already specified in 'target' attribute
  106 | int32_t main()
      |         ^~~~
a.cc:106:9: error: redefinition of 'int32_t main()'
a.cc:44:9: note: 'int32_t main()' previously defined here
   44 | int32_t main()
      |         ^~~~