[Question]
  [
**Input:**
* A string (the wave-snippet) with a length `>= 2`.
* A positive integer *n* `>= 1`.
**Output:**
We output a single-line wave. We do this by repeating the input string *n* times.
**Challenge rules:**
* If the first and last character of the input string matches, we only output it once in the total output (i.e. `^_^` of length 2 becomes `^_^_^` and not `^_^^_^`).
* The input string won't contain any whitespaces/tabs/new-lines/etc.
* If your language doesn't support non-ASCII characters, then that's fine. As long as it still complies to the challenge with ASCII-only wave-input.
**General rules:**
* This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so shortest answer in bytes wins.  
Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.
* [Standard rules apply](http://meta.codegolf.stackexchange.com/questions/2419/default-for-code-golf-program-function-or-snippet/2422#2422) for your answer, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters, full programs. Your call.
* [Default Loopholes](http://meta.codegolf.stackexchange.com/questions/1061/loopholes-that-are-forbidden-by-default) are forbidden.
* If possible, please add a link with a test for your code.
* Also, please add an explanation if necessary.
**Test cases:**
```
_.~"(              length 12
_.~"(_.~"(_.~"(_.~"(_.~"(_.~"(_.~"(_.~"(_.~"(_.~"(_.~"(_.~"(
'°º¤o,¸¸,o¤º°'     length 3
'°º¤o,¸¸,o¤º°'°º¤o,¸¸,o¤º°'°º¤o,¸¸,o¤º°'
-__                length 1
-__
-__                length 8
-__-__-__-__-__-__-__-__
-__-               length 8
-__-__-__-__-__-__-__-__-
¯`·.¸¸.·´¯         length 24
¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯
**                 length 6
*******
String & length of your own choice (be creative!)
```
  
[Answer]
## Python 3, 32 bytes
```
lambda s,n:s+s[s[0]==s[-1]:]*~-n
```
Concatenates `n` copies of the string, removing the first character from all copies but the first if the first character matches the last one.
[Answer]
# [05AB1E](http://github.com/Adriandmen/05AB1E), 13 bytes
Uses [CP-1252](http://www.cp1252.com/) encoding.
```
D¬U¤XQi¦}I<×J
```
[Try it online!](http://05ab1e.tryitonline.net/#code=RMKsVcKkWFFpwqZ9STzDl0o&input=wq9gwrcuwrjCuC7Ct8K0wq8KOA)
**Explanation**
`-___-` and `3` used as input for example.
```
D              # duplicate input string
               # STACK: "-___-", "-___-"
 ¬U¤X          # push copies of the first and last element of the string
               # STACK: "-___-", "-___-", "-", "-"
     Q         # compare for equality 
               # STACK: "-___-", "-___-", 1
      i¦}      # if true, remove the first char of the copy of the input string
               # STACK: "-___-", "___-" 
         I<    # push input number and decrease by 1
               # STACK: "-___-", "___-", 2
           ×   # repeat the top string this many times
               # STACK: "-___-", "___-___-"
            J  # join with input string
               # STACK: "-___-___-___-"
               # implicitly output
```
[Answer]
## JavaScript (ES6), 47 bytes
```
f=
(s,n)=>s+s.slice(s[0]==s.slice(-1)).repeat(n-1)
;
```
```
<div oninput=o.textContent=n.value&&f(s.value,n.value)><input id=s><input id=n type=number min=1><div id=o>
```
[Answer]
## Perl, 29 bytes
**28 bytes code + 1 for `-p`.**
Thanks to [@Dada](https://codegolf.stackexchange.com/users/55508/dada) for helping me shave off a few bytes!
```
s/^((.).*?)(\2?)$/$1x<>.$3/e
```
### Usage
```
perl -pe 's/^((.).*?)(\2?)$/$1x<>.$3/e' <<< "'°º¤o,¸¸,o¤º°'
3"
'°º¤o,¸¸,o¤º°'°º¤o,¸¸,o¤º°'°º¤o,¸¸,o¤º°'
perl -pe 's/^((.).*?)(\2?)$/$1x<>.$3/e' <<< '**
6'
*******
```
[Online example.](https://ideone.com/SiWXQ0#view_edit_box)
[Answer]
## Pyke, ~~15~~ ~~14~~ 10 bytes
```
tQQhQeq>*+
```
[Try it here!](http://pyke.catbus.co.uk/?code=tQQhQeq%3E%2a%2B&input=-__-%0A3)
```
  QhQeq    -    input_1[0] == input_1[-1]
 Q     >   -   input_1[^:]
        *  -  ^ * V
t          -   input_2 - 1
         + - input_1 + ^
```
[Answer]
# Perl, 23 bytes
Includes +1 for `-p`
Give input string followed by number on separate lines on STDIN
```
wave.pl <<< "'°º¤o,¸¸,o¤º°'
3"
```
`wave.pl`:
```
#!/usr/bin/perl -p
$_ x=<>;s/(.)\K
\1?//g
```
If the first character in the word is not a regex special character this 22 bytes version works too:
```
#!/usr/bin/perl -p
$_ x=<>;/./;s/
$&?//g
```
[Answer]
## [Retina](http://github.com/mbuettner/retina), 29 bytes
Lines 2 and 5 have a trailing space.
```
 .+
$* 
 $
 $`
(.) +\1?
$1
```
[Try it online!](http://retina.tryitonline.net/#code=JShHYAogLisKJCogCiAkCgogCiAkYAooLikgK1wxPwokMQ&input=Xy5-IiggMTIKJ8KwwrrCpG8swrjCuCxvwqTCusKwJyAzCi1fXyAxCi1fXyA4Ci1fXy0gOArCr2DCty7CuMK4LsK3wrTCryAyNAoqKiA2CsKvXF8o44OEKV8vwq8gMTE) (The first line enables a linefeed-separated test suite.)
[Answer]
## Batch, 117 bytes
```
@set/ps=
@set t=%s%
@if %s:~0,1%==%s:~1% set t=%s:~1%
@for /l %%i in (2,1,%1)do @call set s=%%s%%%%t%%
@echo %s%
```
Takes the number of repetitions as a command-line parameter and reads the string from STDIN.
[Answer]
# MATL, ~~19~~ ~~17~~ 14 bytes
```
ttP=l):&)liX"h
```
This works for ASCII on the online interpreter and for both unicode and ASCII when run using MATLAB.
[**Try it Online!**](http://matl.tryitonline.net/#code=dHRQPWwpOiYpbGlYImg&input=JypfXyonCjU&debug=on)
**Explanation**
```
        % Implicitly grab the input as a string
        %   STACK:  {'abcdea'}
        %
tt      % Make two copies and push them to the stack
        %   STACK:  {'abcdea'    'abcdea'    'abcdea'}
        %
P       % Flip the second copy around
        %   STACK:  {'abcdea'    'abcdea'    'aedcba'}
        %
=       % Perform an element-wise comparison. Creates a boolean array
        %   STACK:  {'abcdea'    [1 0 0 0 1]}
        %
l)      % Get the first element. If the first and last char are the same this will be
        % TRUE (1), otherwise FALSE (0)
        %   STACK:  {'abcdea'    1 }
        %
:       % Create an array from [1...previous result]. If the first char was repeated,
        % this results in the scalar 1, otherwise it results in an empty array: []
        %   STACK: {'abcdea'    1 } 
        %
&)      % Break the string into pieces using this index. If there were repeated
        % characters, this pops off the first char, otherwise it pops off
        % an empty string
        %   STACK: {'a'    'bcdea'}
        %
li      % Push the number 1 and explicitly grab the second input argument
        %   STACK: {'a'    'bcdea'    1    3}
        %
X"      % Repeat the second string this many times
        %   STACK: {'a'    'bcdeabcdeabcdea'}
        %
h       % Horizontally concatenate the first char (in case of repeat) 
        % or empty string (if no repeat) with the repeated string
        %   STACK: {'abcdeabcdeabcdea'}
        %
        % Implicitly display the result
```
[Answer]
# Pyth, 13 bytes
```
+z*@tBzqhzezt
```
[Test suite!](http://pyth.herokuapp.com/?code=%2Bz%2a%40tBzqhzezt&input=5%0A%C2%AF%60%C2%B7.%C2%B8&test_suite=1&test_suite_input=12%0A_.%7E%22%28%0A3%0A%27%C2%B0%C2%BA%C2%A4o%2C%C2%B8%C2%B8%2Co%C2%A4%C2%BA%C2%B0%27%0A1%0A-__%0A8%0A-__%0A8%0A-__-%0A24%0A%C2%AF%60%C2%B7.%C2%B8%C2%B8.%C2%B7%C2%B4%C2%AF%0A6%0A%2a%2a%0A7%0AString+%26+length+of+your+own+choice+%28be+creative%21%29&debug=0&input_size=2)
Explanation to follow.
[Answer]
# Gema, 41 characters
```
* *=@subst{\? \$1=\?\; =;@repeat{$2;$1 }}
```
Sample run:
```
bash-4.3$ gema '* *=@subst{\? \$1=\?\; =;@repeat{$2;$1 }}' <<< '_.~"( 12'
_.~"(_.~"(_.~"(_.~"(_.~"(_.~"(_.~"(_.~"(_.~"(_.~"(_.~"(_.~"(
bash-4.3$ gema '* *=@subst{\? \$1=\?\; =;@repeat{$2;$1 }}' <<< "'°º¤o,¸¸,o¤º°' 3"
'°º¤o,¸¸,o¤º°'°º¤o,¸¸,o¤º°'°º¤o,¸¸,o¤º°'
bash-4.3$ gema '* *=@subst{\? \$1=\?\; =;@repeat{$2;$1 }}' <<< '** 6'
*******
```
[Answer]
# PowerShell v2+, 48 bytes
```
Param($s,$n)$s+$s.Substring($s[0]-eq$s[-1])*--$n
```
Outputs the whole string once, followed by n-1 copies of the string or substring, depending on if the first and last characters match.
The `.Substring()` method outputs from the index supplied to the end of the string, so if `$s[0]-eq$s[-1]` evaluates to false (0), we get the whole string. If that statement is true (1), We get the substring starting at the second character.
[Answer]
# VBA 119 bytes
New to this game and vba wins with the highest bytes :P
PS: can't believe vba stands close to JAVA **HAHA**
```
Function l(s,x)
l=s: s=IIf(Left(s,1)=Right(s,1),Mid(s,2,Len(s)),s)
z: x=x-1: If x>0 Then l=l & s: GoTo z:
End Function
```
Explanation:
```
+------------------------------------------------------------+-----------------------------------------------------------------------------------+
|                            code                            |                                     function                                      |
+------------------------------------------------------------+-----------------------------------------------------------------------------------+
| l=s                                                        | input string s is saved to base                                                   |
| s = IIf(Left(s, 1) = Right(s, 1), Right(s, Len(s) - 1), s) | checks whether 1 and last char is equal,                                          |
|                                                            | if yes removes the first char from s and that s will be used to for further joins |
| z:                                                         | z: is a label                                                                     |
| x = x - 1:                                                 | decreases looping round                                                           |
| If x > 0 Then l = l & s: GoTo z:                           | join strings until no more rounds to do                                           |
+------------------------------------------------------------+-----------------------------------------------------------------------------------+
```
[Answer]
## K, 12 Bytes
```
{,/[y#(,)x]}
/in action
{,/[y#(,)x]}["lollol";4]
"lollollollollollollollol"
{,/[y#(,)x]}["-_";10]
"-_-_-_-_-_-_-_-_-_-_"
/explanation (read function from right to left)
x is the string and y is the number of repetitions
(,)y    --enlist x so it becomes 1 value (rather than a list)
y#x     --take y many items of x
,/      --coalesce the list ,/[("-_";"-_")] --> "-_-_"
```
Thanks 
[Answer]
# PHP, 72 Bytes
```
<?=($a=$argv[1]).str_repeat(substr($a,$a[0]==substr($a,-1)),$argv[2]-1);
```
with PHP 7.1 it could be reduce to 65 Bytes
```
<?=($a=$argv[1]).str_repeat(substr($a,$a[0]==$a[-1]),$argv[2]-1);
```
[Answer]
## [Pip](http://github.com/dloscutoff/pip), 18 bytes
Regex solution, taking advantage of the "no spaces in input" rule. Takes the string from stdin and the number as a command-line argument.
```
(q.s)XaR`(.) \1?`B
```
[Try it online!](http://pip.tryitonline.net/#code=KHEucylYYVJgKC4pIFwxP2BC&input=XsK3LsK4X8yy4pu1X8K4LsK3Xg&args=Mw)
Explanation:
```
 q.s                Read from stdin and append a space
(   )Xa             String-multiply by first cmdline arg
       R            Replace
        `(.) \1?`     Regex: char followed by space followed by (optional) same char again
                 B    Callback function, short for {b}: return 1st capturing group
```
Thus, `a b` turns into `ab`, `a a` turns into `a`, and the space at the end of the string is removed. Then the result is autoprinted.
[Answer]
# CJam, ~~16~~ 15 bytes
```
l]li*{(s@)@|@}*
```
[Try it online](http://cjam.tryitonline.net/#code=bF1saSp7KHNAKUB8QH0q&input=4paBIOKWgiDiloMg4paFIOKWhiDilocg4paGIOKWhSDiloMg4paCIOKWgQoz)
Explanation:
```
l]li*            Create a list of n-times the input string.
{(s@)@|@}*       Fold this list by taking out the last character of the first 
                 argument and the first character of the second argument and 
                 replacing them by their unique set union.
                 e.g.: "aba" "aba" -> "ab" 'a"a"| "ba" -> "ab" "a" "ba"
                       "abc" "abc" -> "ab" 'c"a"| "bc" -> "ab" "ca" "bc
```
[Answer]
# Haskell, 59 bytes
```
a%b=concat$replicate a b
a@(s:z)#n|s/=last z=n%a|1<2=s:n%z
```
### Ungolfed version:
```
-- Helper: Appends str to itself n times
n % str = concat (replicate n str)
-- Wave creating function
(x:xs) # n
 -- If start and end of wave differ, 
 | x /= last xs = n%(x:xs)
 | otherwise   = x:(n%xs)
```
[Answer]
# Java 11, ~~123~~ ~~111~~ ~~109~~ ~~107~~ ~~102~~ ~~100~~ ~~79~~ 58 bytes
```
s->n->s+s.substring(s.matches("(.).*\\1")?1:0).repeat(n-1)
```
[Try it online.](https://tio.run/##lY@xTsMwFEX3fIWVpXaIn0hBCFEIGxIDU0eCgpuGkuDYUexUqlD5mu7tgNSK0T8WXBqFDVLJg5/uPe/el7M5o/n0rUk4Uwo9sEy8OwgpzXSWoNyqUOuMw0stEp1JAXft53qsq0zM/D8990Kns7Ty0cEchihBN42ioaChOlGg6on6UbCCgunkNVXYxUDAi6LAJbfB1SmBKi1TprGgAWlGji1X1hNuy7Ud5zKbosL2xoeQxydG9icgNF4onRYgaw2lVTQXOAFWlnyB3Rg@Ihe7pJ2DISGjf6GB2Zgvs5K@2ZmdL83KTptBt@Sszw4ax7@pxwKXPQF6HGHWz2YL@6PAbM2nWXf48LwP73kdcNHHzyW3r2PajKWzbL4B)
I'll of course try to answer my own question. ;)  
-5 bytes thanks to *@dpa97*.  
**Explanation:**
```
s->n->             // Method with String & integer parameters and String return-type
  s                //  Return the input-String as result
   +               //  Appended with:
    s.subtring(    //   A substring of the input-String:
      s.matches("(.).*\\1")?
                   //    If the first and last characters are the same:
       1           //     Remove the first character in the substring-call
      :            //    Else:
       0)          //     Use the input-String as is
     .repeat(n-1)  //   Repeated the input-integer minus 1 amount of times
```
[Answer]
# Javascript ES6, 49 chars
```
(s,n)=>s.replace(/(.).*?(?=\1?$)/,m=>m.repeat(n))
```
Test:
```
f=(s,n)=>s.replace(/(.).*?(?=\1?$)/,m=>m.repeat(n))
console.log(document.querySelector("pre").textContent.split(`
`).map(s=>s.split` `).every(([s,n,k])=>f(s,n)==k))
```
```
<pre>_.~"( 12 _.~"(_.~"(_.~"(_.~"(_.~"(_.~"(_.~"(_.~"(_.~"(_.~"(_.~"(_.~"(
'°º¤o,¸¸,o¤º°' 3 '°º¤o,¸¸,o¤º°'°º¤o,¸¸,o¤º°'°º¤o,¸¸,o¤º°'
-__ 1 -__
-__ 8 -__-__-__-__-__-__-__-__
-__- 8 -__-__-__-__-__-__-__-__-
¯`·.¸¸.·´¯ 24 ¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯
** 6 *******</pre>
```
[Answer]
## [QBIC](https://codegolf.stackexchange.com/questions/44680/showcase-your-language-one-vote-at-a-time/86385#86385), 65 bytes
```
;:~left$$|(A,1)=right$$|(A,1)|A=left$$|(A,len(A)-1)][1,a|B=B+A]?B
```
I guess I should add LEFT$ and RIGHT$ to QBIC...
Explanation:
```
;          make the first cmd line parameter into A$
:          make the second cmd line parameter into a (num)
~left..]   Drop the last char if equal to the first char
[1,a...]   FOR the given number of repetitions, concat A$ to B$ (starts out empty)
?B         print B$
```
[Answer]
# C#, 79 bytes
```
(s,n)=>s+new string('x',n-1).Replace("x",s[0]==s[s.Length-1]?s.Substring(1):s);
```
A bit of an absurd method of repeating a string. Create a new string of the desired repeat length and then replace each character with the string to repeat. Other than that, looks like pretty much the same strategy as many others.
```
/*Func<string, int, string> Lambda =*/ (s, n) =>
    s                                      // Start with s to include first char at start
    + new string('x', n - 1).Replace("x",  // Concatenate n-1 strings of...
        s[0] == s[s.Length - 1]            // if first/last char are the same
            ? s.Substring(1)               // then skip the first char for each concat
            : s                            // else concat whole string each time
    )
;
```
[Answer]
# SpecBAS - 68 bytes
```
1 INPUT a$,n: l=LEN a$: ?IIF$(a$(1)<>a$(l),a$*n,a$( TO l-1)*n+a$(l))
```
Uses inline-`IF` to check if first and last characters are the same.
If not, print string `n` number of times.
Otherwise, splice the string to length-1, repeat that and put last character at end.
Can only accept ASCII characters (or characters built into SpecBAS IDE)
[![enter image description here](https://i.stack.imgur.com/df11L.png)](https://i.stack.imgur.com/df11L.png)
[Answer]
# APL, 19 bytes
```
{⍺,∊1↓⍵⍴⊂⍺↓⍨⊃⍺=⊃⌽⍺}
```
Usage:
```
      '^_^' {⍺,∊1↓⍵⍴⊂⍺↓⍨⊃⍺=⊃⌽⍺} 5
^_^_^_^_^_^
```
Explanation:
* `⊃⍺=⊃⌽⍺`: see if the first character matches the last character
* `⍺↓⍨`: if this is the case, drop the first character
* `⊂`: enclose the result
* `⍵⍴`: replicate it `⍵` times
* `1↓`: drop the first one (this is shorter than `(⍵-1)⍴`)
* `∊`: get all the simple elements (undo the boxing)
* `⍺,`: add one instance of the whole string to the front
[Answer]
# Postscript, 98 bytes
```
exch/s exch def/l s length 1 sub def s 0 get s l get eq{/s s 0 l getinterval def}if{s print}repeat
```
...but you might need a ' flush' tacked onto that to get your PS interpreter to flush the comm buffer, another six bytes :(
[Answer]
# Common Lisp (LispWorks), 176 bytes
```
(defun f(s pos)(if(equal(elt s 0)(elt s #1=(1-(length s))))(let((s1(subseq s 0 1))(s2(subseq s 0 #1#)))(dotimes(j pos)(format t s2))(format t s1))(dotimes(j pos)(format t s))))
```
Usage:
```
    CL-USER 130 > (f "_.~~\"(" 12)
    _.~"(_.~"(_.~"(_.~"(_.~"(_.~"(_.~"(_.~"(_.~"(_.~"(_.~"(_.~"(
    NIL
    CL-USER 131 > (f "'°o¤o,??,o¤o°'" 3)
    '°o¤o,??,o¤o°'°o¤o,??,o¤o°'°o¤o,??,o¤o°'
    NIL
    CL-USER 132 > (f "-__" 1)
    -__
    NIL
    CL-USER 133 > (f "-__" 8)
    -__-__-__-__-__-__-__-__
    NIL
    CL-USER 134 > (f "ˉ`·.??.·′ˉ" 24)
    ˉ`·.??.·′ˉ`·.??.·′ˉ`·.??.·′ˉ`·.??.·′ˉ`·.??.·′ˉ`·.??.·′ˉ`·.??.·′ˉ`·.??.·′ˉ`·.??.·′ˉ`·.??.·′ˉ`·.??.·′ˉ`·.??.·′ˉ`·.??.·′ˉ`·.??.·′ˉ`·.??.·′ˉ`·.??.·′ˉ`·.??.·′ˉ`·.??.·′ˉ`·.??.·′ˉ`·.??.·′ˉ`·.??.·′ˉ`·.??.·′ˉ`·.??.·′ˉ`·.??.·′ˉ
    NIL
    CL-USER 135 > (f "**" 6)
    *******
    NIL
```
Explanation:
```
~~ =>   ~
\" =>   " 
```
Ungolf:
```
    (defun f (s pos)
      (if (equal (elt s 0) (elt s (1- (length s))))
          (let ((s1 (subseq s 0 1)) (s2 (subseq s 0 (1- (length s)))))
            (dotimes (j pos)
              (format t s2))
            (format t s1))        
        (dotimes (i pos)
          (format t s))))
```
[Answer]
# Vim, 17 bytes
The easy way to do this is to use a back-reference regex that can tell if the first and last chars match. But long regexes are long. We don't want that.
```
lDg*p^v$?<C-P>$<CR>hd@aP
```
The wave to repeat is in the buffer. I'm assuming the number to be repeated is in the register `"a` (type `qaNq` with N as the number to set it up). The idea is:
* If the first and last bytes match, delete everything up to the last character.
* If the first and last bytes *don't* match, delete all the characters.
Then `P` the deleted text `@a` times.
* `lDg*`: This maneuver creates a regex that matches any first character, regardless of whether it needs to be escaped or not, or whether it's a word or not. (`*` would be enough to make the properly escaped regex, but would add unwanted `\<\>` garbage if it was a word character, like `_`.)
* `p^`: Last step was messy. Clean up to the original position, beginning of the line.
* `v$`: In visual mode, `$` by default moves to *after* the end of the line.
* `?<C-P>$<CR>hd`: If the previous regex exists at the end of the line, this search will move to it; otherwise, stay beyond the end of the line. Move left from there and we accomplish the (tedious) delete we need.
* `@aP`: Run the number repeat as a macro to be used as an argument to `P`.
[Answer]
# Ruby, 38 bytes
```
->s,n{s[0]==s[-1]?s[0..-2]*n+s[0]:s*n}
```
I think this is pretty self-explanatory. I'm still wondering if there's a more concise way to represent the `s[0..-2]` block, but I haven't found it yet.
[Answer]
# Java (117 bytes)
```
String w(String a,int b){String c=a;for(;b>0;b--)c+=b+a.substring(a.charAt(a.length()-1)==a.charAt(0)?1:0);return c;}
```
]