[Question]
  [
There have been a couple of challenges involving doubling source code: [here](https://codegolf.stackexchange.com/questions/132558/i-double-the-source-you-double-the-output) and [here](https://codegolf.stackexchange.com/questions/132786/double-time-is-not-double-time). The task we have here is a bit harder, but should be doable in almost every language.
In this challenge, you will take in an arbitrary positive integer. Your program must output that integer **doubled**.
When your source code is doubled, it will take in a positive integer, and output it **squared**.
How is your source code doubled? Well, [you can have it your way](https://www.youtube.com/watch?v=KJXzkUH72cY).
That is to say, you can split your source code up into strings of bytes or characters (or tokens in tokenized langs) of *any **equal** length you want*, and repeat each chunk twice in succession.
For an initial program of `ABCDEFGHIJKL`, (length 12) here are **all** possible doubled programs:
```
Chunk length |   Doubled source code
-------------+-------------------------
           1 | AABBCCDDEEFFGGHHIIJJKKLL
           2 | ABABCDCDEFEFGHGHIJIJKLKL
           3 | ABCABCDEFDEFGHIGHIJKLJKL
           4 | ABCDABCDEFGHEFGHIJKLIJKL
           6 | ABCDEFABCDEFGHIJKLGHIJKL
          12 | ABCDEFGHIJKLABCDEFGHIJKL
```
Note that this means programs of prime lengths can only be doubled two ways: every character doubled, or the full program is repeated twice.
### Rules:
* Code must be a full program or function.
* [Standard loopholes are forbidden.](https://codegolf.meta.stackexchange.com/questions/1061/loopholes-that-are-forbidden-by-default)
* [Standard I/O methods are allowed.](https://codegolf.meta.stackexchange.com/questions/2447/default-for-code-golf-input-output-methods)
* All characters/bytes, including whitespace and newlines, are counted in the length of the code and contribute to chunks.
* You **may** assume that the input and its square can be represented by your language's int/integer type.
* You **may not** assume a trailing newline or other character.
* Provide your chunk size in the heading after the byte count.
* This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so shorter programs are better! If two programs are the same length, the one which uses the smaller chunk length wins. (If you have a longer program which uses a smaller chunk length, that is worth posting too!)
* If your program requires a second input/line, you may make no assumptions on its value. In particular, your program should work if the second input is empty, the same as the first, or a different integer. If your program does not require a second input/line, you may ignore this restriction.
> 
> [Sandbox link](https://codegolf.meta.stackexchange.com/a/18074/86147)
> 
> 
> 
  
[Answer]
# [Perl 5](https://www.perl.org/), 8 bytes (chunk size 4)
```
$_*=~~+2
```
[Try it online](https://tio.run/##K0gtyjH9/18lXsu2rk7b6P9/QwMuIwMuY4N/@QUlmfl5xf91cwoA "Perl 5 – Try It Online"), or [try the doubled version](https://tio.run/##K0gtyjH9/18lXssWhOvqtI1A@P9/QwMuIwMuY4N/@QUlmfl5xf91cwoA).
Unary `~` is the bitwise negate, so applying it twice is a noop. Thus, the base program simply multiplies `$_` (the implicit input-output variable) by 2.
Binary `~~` is smartmatch, which returns a boolean. `~~+2~~+2` parses as `(~~+2) ~~ (+2)`. Since 2 equals 2, this yields true (1). Thus, the doubled program first multiplies `$_` by 1, then multiplies `$_` by itself.
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 4 bytes (chunk size 2 or 4)
```
·Inr
```
[Try it online](https://tio.run/##yy9OTMpM/f//0HbPvKL//02MAA "05AB1E – Try It Online") or [doubled as a single 4-byte chunk](https://tio.run/##yy9OTMpM/f//0HbPvCIw8f@/iREA "05AB1E – Try It Online") or [doubled as two 2-byte chunks](https://tio.run/##yy9OTMpM/f//0HZPIMoryiv6/9/ECAA "05AB1E – Try It Online").
```
·        # double the implicit input
 In      # square the input
   r     # reverse the stack: it's now [input ** 2, input * 2]
         # if we stop here: implicitly output the top of the stack (input * 2)
·        # double the top of the stack (giving input * 4, not that it matters)
 In      # square the input
   r     # reverse the stack: it's now [input ** 2, input * 4, input ** 2]
         # implicitly the top of the stack (input ** 2)
```
[Answer]
# [Python 3](https://docs.python.org/3/), 26 bytes (chunk size 13)
```
lambda n:"and n*n#"and 2*n
```
[Try it online!](https://tio.run/##K6gsycjPM/6fZhvzPycxNyklUSHPSikxL0UhTytPGcww0sr7n5JfmpSTGp@mYKuAogrKScHUgsLh4uIqKMrMK9FI0zA01tSEcmCGgsX@AwA "Python 3 – Try It Online")
### Doubled:
```
lambda n:"andlambda d:"and n*n#"and 2*n n*n#"and 2*n
```
This solution is provided by @Grimy.
---
## [Python 3](https://docs.python.org/3/), ~~32~~ ~~30~~ 28 bytes (chunk size ~~16~~ ~~15~~ 14)
```
lambda n:bool(0)*n*n or  2*n
```
[Try it online!](https://tio.run/##K6gsycjPM/6fZhvzPycxNyklUSHPKik/P0fDQFMrTytPIb9IQcFIK@9/QVFmXolGmoahgabmfwA "Python 3 – Try It Online")
*-4 bytes thanks to @negativeSeven*
### Doubled:
```
lambda n:bool(lambda n:bool(0)*n*n or  2*n0)*n*n or  2*n
```
[Try it online!](https://tio.run/##K6gsycjPM/6fZhvzPycxNyklUSHPKik/P0cDlWegqZWnlaeQX6SgYKSVh8r7X1CUmVeikaZhaKCp@R8A "Python 3 – Try It Online")
The function takes advantage of the unique chunk rule of this challenge.
[Answer]
# [Hexagony](https://github.com/m-ender/hexagony), 14 bytes (chunk size 14)
```
?"+==*/}=+!@!<
```
### Expanded:
```
  ? " +
 = = * /
} = + ! @
 ! < . .
  . . .
```
[Try it online!](https://tio.run/##y0itSEzPz6v8/99eSdvWVku/1lZb0UHR5v9/I0MA "Hexagony – Try It Online")
## Doubled
```
?"+==*/}=+!@!<?"+==*/}=+!@!<
```
### Expanded:
```
   ? " + =
  = * / } =
 + ! @ ! < ?
" + = = * / }
 = + ! @ ! <
  . . . . .
   . . . .
```
[Try it doubled online!](https://tio.run/##y0itSEzPz6v8/99eSdvWVku/1lZb0UHRBpX3/7@RIQA "Hexagony – Try It Online")
Hexagony is in a bit of a weird position in this challenge, in that actually achieving the task is not much more difficult than simply being able to write the two individual programs. However, golfing the solution proved rather difficult.
This solution is the trivial idea in the shortest form that I could fit, but I suspect there are shorter, cleverer answers. This version very naively sets two values to the input and sums them or multiplies them, depending on if the source is doubled. The only code reuse is the `"+` which makes making the copy code for the doubled program short enough to fit in the unused space from the original program.
I suspect using the IP change instructions `[]` will make isolating the parts easier, but a truly ideal solution will reuse a lot of code between the two. I made a [helper program](https://tio.run/##jZNRj9owDMff8ym8ag8JhTDu3tCh7XsAQoX6aLaSVEm6G9P22ZmTtDTspGkgContn@2/TXf1jdHPt5u6dMZ6cFc3B4tzUB6tN6Z1jNX4Cq/GXip/aPBHdTb6ysGZ3p4QxJoBvZyq8dCihg2s4sVbo1qEZ5hNphnw6bCAFQgo6fkCdOYJN9AeiGVAxuuuqocc/@Qm7CLHjuE11oeh8M3YQQmFLAgy0FMqa97C4ewbR553LeSpqZTmYCt9Rj4mFUGx72gd1vzRslgJAWIkBtR2n2ox4fAp/iZpQc2zlKA0oO4vaCuPPCslk4eqJUABofLq6P5SdgFqSJs1Q/5PuW7J8T@Cnay6DnXNY9YyZJVfDenwoOg29LSOnZVjyr3ISNGyGU1JFHR960MjOz0wk1BiGAP63urBjTHavmx8Vyedr5WWFquaU8RF6clsUbr@SLhi535td3Ln9uXHYg4FfTIOhZ2aXn87OPUT44Di3kwoAXvGwogmtzCfLCgNJV4kwBS8zYJmoNYPR67Coop9WoAATcvzroDlMk8eCgoJa9MfW4xbMEoXvYj8BPeC77XeNe2s0p6/@0MPOBrY7QbwmYZcMmJvCLdkv@m7hA/whdHjBSRIQsnw/gM) to double hexagony source code. Note that it removes trailing no-ops so if you want to have placeholder no-ops at the end just fill in some other character and change it back after. It can handle different chunk sizes, though I didn't yet write code to output each possible program (Hexagony seems to lend itself to using the full chunk size).
[Answer]
# [Befunge-98 (FBBI)](https://github.com/catseye/FBBI), 8 bytes (chunk length 2)
```
;&:#* +q
```
[Try it online!](https://tio.run/##S0pNK81LT9W1tPj/31rNSllLQbvw/39DYwUA "Befunge-98 (FBBI) – Try It Online")
```
;&;&:#:#* * +q+q
```
[Try it online! (doubled)](https://tio.run/##S0pNK81LT9W1tPj/31rNWs1K2UpZS0FLQbtQu/D/f0NjBQA "Befunge-98 (FBBI) – Try It Online")
Excluding control flow, the first program executes `&:+q` (input, duplicate top of stack, add, exit with return code), and the second executes `&:*+q` (input, duplicate top of stack, multiply, add (sums with an implicit 0), exit with return code)
[Answer]
# [Hexagony](https://github.com/m-ender/hexagony), 12 bytes (chunk size 4)
```
?"2+...}=*!@
```
[Try it online!](https://tio.run/##y0itSEzPz6v8/99eyUhbT0@v1lZL0eH/fyNDAA "Hexagony – Try It Online")
Formatted:
```
  ? " 2
 + . . .
} = * ! @
 . . . .
  . . .
```
[And doubled](https://tio.run/##y0itSEzPz6v8/99eyUgbhPX09GpB2FZL0QGE//83MgQA), then formatted:
```
   ? " 2 +
  ? " 2 + .
 . . } . . .
} = * ! @ = *
 ! @ . . . .
  . . . . .
   . . . .
```
Basically, this sets the first edge to the input, then the second edge to either `2` or a copy of the input, then multiplies those two edges into the third edge, prints that and terminates. The list of executed instructions are just
```
?"2}=*!@
```
and
```
?"2+}=*!@
```
With the only difference being the `+` overriding the `2` on the second program.
[Answer]
# JavaScript (ES6), ~~24~~ 22 bytes
Despite its unusual format, this is the definition of an anonymous function, which can be either called directly or assigned to a variable.
```
+(g=x=>x*x)?g:(x=>x*2)
```
[Try it online!](https://tio.run/##y0osSyxOLsosKNHNy09J/Z9m@19bI922wtauQqtC0z7dSgPMNNL8n5yfV5yfk6qXk5@ukaZhrqn5HwA "JavaScript (Node.js) – Try It Online")
```
+(g=x=>x*x)?g:(x=>x*2)+(g=x=>x*x)?g:(x=>x*2)
```
[Try it online doubled!](https://tio.run/##y0osSyxOLsosKNHNy09J/Z9m@19bI922wtauQqtC0z7dSgPMNNLELvo/OT@vOD8nVS8nP10jTcNcU/M/AA "JavaScript (Node.js) – Try It Online")
### How?
Applying the unary `+` to a function is interpreted as an attempt to coerce it to a number and results in *NaN*. Therefore, the leading `+(g=x=>x*x)` is falsy in both versions.
On the other hand, applying the binary `+` between 2 functions results in a string. Therefore, `(x=>x*2)+(g=x=>x*x)` is truthy in the doubled version.
[Answer]
# [Perl 6](https://github.com/nxadm/rakudo-pkg), 8 bytes (chunk size 1)
```
* *<1 2>
```
[Try it online!](https://tio.run/##K0gtyjH7n1upoJamYKvwX0tBy8ZQwcjuvzVXcWKlQpqGieZ/AA "Perl 6 – Try It Online") [Try it doubled!](https://tio.run/##K0gtyjH7n1upoJamYKvwX0tLQUFLy8bG0FBBwcjIzu6/NVdxYqVCmoaJ5n8A)
A Whatever/HyperWhatever lambda that takes a number and returns a number for the first program and a singleton list for the second program. Basically this keeps the exact same logic, except that the multiplication operator (`*`) is replaced by the exponential one (`**`).
```
**  **<<11  22>>
```
The Whatever literal (confusingly also represented by a `*`) are doubled up to a HyperWhatever (`**`) which is basically the same except it maps over lists. The space is needed to separate the Whatever literal from the multiplication and is ignored when doubled up. Instead of just `2` (which would get doubled to `22`) we use a list containing two elements, which evaluates to 2 in a numeric context). The `<>` can be doubled to a list with interpolation, and the two elements inside are doubled, but neither of those change the length of the list.
[Answer]
# [Runic Enchantments](https://github.com/Draco18s/RunicEnchantments/tree/Console), 9 bytes (chunk size 3)
```
i3?:*@:+@
```
[Try it online!](https://tio.run/##KyrNy0z@/z/T2N5Ky8FK2@H/f1MA "Runic Enchantments – Try It Online")  
[Try it doubled!](https://tio.run/##KyrNy0z@/z/T2B6IrLQcQEgbhP7/NwUA "Runic Enchantments – Try It Online")
The `3?` skips the next 3 instructions, resulting in an (executed) `i3?...:+@`. When doubled it results in an executed `i3?...:*@` where `.` represents the 3 NOP'd instructions. `@` is "print entire stack and terminate."
[Answer]
# [C# (Visual C# Interactive Compiler)](http://www.mono-project.com/docs/about-mono/releases/5.0.0/#csc) / Javascript, 22 bytes, chunk size 11
```
m=>/*      /2*m//*/m*2
```
[Try it online!](https://tio.run/##Sy7WTS7O/O9Wmpdsk5lXogPEdmm2/3Nt7fS1FMBA30grV19fSz9Xy@i/NVdafpEGUI1Cpq2BdaaNkaF1pra2Jld4UWZJqk9mXqpGmkampqb1fwA "C# (Visual C# Interactive Compiler) – Try It Online")
[Answer]
# [Brain-Flak](https://github.com/Flakheads/BrainHack), 76 bytes, 76 byte chunks
```
({}<>)(()[([][()])]{(<{}{}({({})({}[()])}<>)<>>)}{}){{}(({})({})<>)(<>)}{}<>
```
[Try it online!](https://tio.run/##LcsxDoAwDAPA79g/6BDlI1GHwgJCYmCN8vY0rRi8@OzjG/d7jfPJhIcoARqsG9jZHeLhAS9jZbdrJaosoBf@xnWWXYtmtmwT "Brain-Flak (BrainHack) – Try It Online")
## Doubled (with newline for clarity)
```
({}<>)(()[([][()])]{(<{}{}({({})({}[()])}<>)<>>)}{}){{}(({})({})<>)(<>)}{}<>
({}<>)(()[([][()])]{(<{}{}({({})({}[()])}<>)<>>)}{}){{}(({})({})<>)(<>)}{}<>
```
[Try it online!](https://tio.run/##SypKzMzLSEzO/v9fo7rWxk5TQ0MzWiM6NlpDM1YztlrDprq2ulajGiinCcRgUZAqGzs7TaCEZjVQEiqnCdJsAxa2seOipmH//1v8twAA "Brain-Flak (BrainHack) – Try It Online")
Here is a version that uses a more complex doubling procedure. It does 5 chunks of size 15. The code here is 46 bytes however due to the required padding it is substantially longer.
# ~~105~~ 90 bytes, 15 byte chunks
```
(              {<><({}()())><><><            <>>({})({}[()])}{}            )<>            
```
[Try it online!](https://tio.run/##SypKzMzLSEzO/v9fQwEFVNvY2WhU12poamhq2tmAILKsjZ0dUFITiKM1NGM1a6trkWU1beyQuf///7cAAA "Brain-Flak (BrainHack) – Try It Online")
## Doubled (with newlines for clarity)
```
(              (              
{<><({}()())><>{<><({}()())><>
<><            <><            
<>>({})({}[()])<>>({})({}[()])
}{}            }{}            
)<>            )<>            
```
[Try it online!](https://tio.run/##SypKzMzLSEzO/v9fQwEFoHG5qm3sbDSqazU0NTQ17Wzs0LhcQC6ycjQuUNoOqFoTiKM1NGM10bhctdW1yMrRuFxA9ch8NO7///8tAA "Brain-Flak (BrainHack) – Try It Online")
[Answer]
# [Brain-Flak](https://github.com/DJMcMayhem/Brain-Flak), ~~48~~ 30 bytes (chunk size 10)
```
(({}))<>( {({}[()])}{}<>{}{}) 
```
[Try it online!](https://tio.run/##SypKzMzTTctJzP7/X0OjulZT08ZOQ6EayIrW0IzVrK2utbGrBpKaCv//GxoAAA "Brain-Flak – Try It Online") [Try it doubled!](https://tio.run/##SypKzMzTTctJzP7/X0OjulZT08ZOQwHBqgayojU0YzVrkVi1NnbVQFJTAcH6/9/QCAA "Brain-Flak – Try It Online")
This basically takes three steps, then when doubled executes those steps twice each. The initial program is:
1. Duplicate TOS, switch stacks and start pushing a value
2. Get the TOS's triangular number n\*(n-1)/2
3. Pop TOS, switch stack and pop twice, then push the result.
For an input `n` into an undoubled program, this results in:
```
1.  Start stack: n n
    Other stack: <
    Third stack: 
2.  Start stack: n n
    Other stack: 0 <
    Third stack: tri(0) = 0
3.  Start stack: n+n+tri(0) = 2n <
    Other stack:
    Third stack:
```
For the doubled program:
```
1a. Start stack: n n
    Other stack: <
    Third stack: 
1b. Start stack: n n <
    Other stack: 0 0
    Third stack: 
2a. Start stack: n 0 <
    Other stack: 0 0
    Third stack: tri(n)
2b. Start stack: n 0 <
    Other stack: 0 0
    Third stack: tri(n)+tri(0) = tri(n)
3a. Start stack: n
    Other stack: tri(n) <
    Third stack: tri(n)
3a. Start stack: 0+n+tri(n)+tri(n) = n + 2*tri(n) = n + n*(n-1) = n*n <
    Other stack: 
    Third stack: 
```
[Answer]
# [Cubix](https://github.com/ETHproductions/cubix), ~~18~~ 14 bytes (chunk length ~~9~~ 7)
```
*OI$|:/@O+:I. 
```
Note the trailing space. [Try it online!](https://tio.run/##Sy5Nyqz4/1/L31OlxkrfwV/bylNP4f9/YwA "Cubix – Try It Online")
Doubled:
```
*OI$|:/*OI$|:/@O+:I. @O+:I. 
```
Again, there is one trailing space. [Try it online!](https://tio.run/##Sy5Nyqz4/1/L31OlxkofSjn4a1t56ilAqf//jQE "Cubix – Try It Online")
## Explanation
The main idea is that doubling the code causes the cube to become bigger, so the instruction pointer starts at a different symbol. Since the addition program cannot be put on a cube of side length 1, the side length is going to be 2. Additionally, the doubled code needs to be on a cube of side length 3, so the doubled code must be at least 25 bytes. This means the code must be at least 13 bytes long. As such, at most 1 more byte can be saved.
Now to the actual code. The first observation is that the top face (that is, the first 4 characters) are not used by the addition program. Furthermore, if we make the 5th character reflect the IP around the cube, we can free up 2 more characters. We will use these characters to put the squaring program.
[Answer]
# [Mornington Crescent](https://esolangs.org/wiki/Mornington_Crescent), 656 Bytes (Chunk size 328)
Just to add weight to the theory that this can be solved in almost any language...
```
Take Northern Line to Bank
Take District Line to Bank
Take District Line to Parsons Green
Take District Line to Bank
Take District Line to Hammersmith
Take Piccadilly Line to Russell Square
Take Piccadilly Line to Bounds Green
Take Piccadilly Line to Hammersmith
Take District Line to Upminster
Take District Line to Embankment
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Acton Town
Take District Line to Acton Town
Take Piccadilly Line to Bounds Green
Take Piccadilly Line to Bounds Green
Take Piccadilly Line to Leicester Square
Take Northern Line to Leicester Square
Take Northern Line to Mornington Crescent
```
(The trailing newline is important)
[Try the single version!](https://tio.run/##nZJNDoIwEIX3nKIXcOUJRI0u0BDFA9QykQntVKclxtNX/AkJQZLi@n2TeTPvGcuEdPGWZorBKSAfQiFrEHvLvgImkSGB8FakkurkLa3QeUblY6RcsrPkxIYBaPr4VhoD7Az66kPkqJQsUetHxxwa50Brcbw1kmEUS21DZc/ID2iwb@DodDVIzgOP6Gtzbs8x7SNjT5q8YqHavERh7xQJ/PuNKCgDVPBy2wtgUJ9IbNcVUiy/hUxCmD8B) ...or... [Try the doubled version!](https://tio.run/##7ZNNDoIwEEb3nKIXcOUJRI0u0BjFA9QykQl0qtMS4@kRf0JCkFgMS9bzmvnmdUYbJqSzMzRRDFYBubKMZQZia9ilwCQiJBDOiFBSFrxKC7SOUTmf0k6yNWTFigGo//O11BrYanTpm9ihUjLBPL/XzL6wFvJcHK6FZOjEQlNQ0gjyBWr1ayU6XjSSdcAd9aU@VePoSmQwehzQ4@@RereYqWrvRWxu5An8a8MLigAVPNM2PqC1Pp7Ypj5sMf8c9uhxII9lOX0A)
---
This was a particularly tricky challenge in Mornington Crescent because the program must have such a rigid structure. It's also important to watch where the doubling would take place, because teleporting between stations is illegal in London.
The theory here is simple: In the single version, 'Bounds Green' is filled with a random string, but in the doubled version it gets filled with the squared input. After the chunk ends, both versions double the 'input', but in the doubled version of the code, the input has been replaced with 0.
This result is taken back to Bounds Green, which performs a max() operation twice, before taking the result to the output. In the single version this leaves the doubling unaltered (the int and string are just switched back and forth), but in the doubled version this replaces the 0 with the squared result already stored in Bounds Green.
---
If my explanation wasn't good enough, I suggest you visit London and try the two routes yourself.
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), ~~15~~ 12 bytes (chunk size: 6)
```
x=>/**/2*(x)
```
[Try it online!](https://tio.run/##y0osSyxOLsosKNHNy09J/Z@cn1ecn5Oql5OfrqHxv8LWTl9LS99IS6NC87@mhqmBpiYXF4oSiApkdRASovg/AA "JavaScript (Node.js) – Try It Online")
Single case: 
```
x=>/**/2*(x)
```
Double case: 
```
x=>/**x=>/**/2*(x)/2*(x)
```
Seems to also work in C#, and Java if changing `=>` to `->`?
[Answer]
# [R](https://www.r-project.org/), ~~42~~ ~~35~~ 28 bytes (chunk size 4)
Now with a smaller chunk and no error. I also have a longer solution with chunk size 3; see below.
I don't think it is possible to write an R answer with chunk size 1 or 2; I'll happily give a bounty to anyone who proves me wrong.
```
s =scan#
n=s()# 
  
n/2*4#  
```
[Try it online!](https://tio.run/##K/pfnJyYp2CrkFaal1ySmZ@noalg@r9YwRYkrMyVZ1usoamswKWgwJWnb6Rloqyg8P8/AA "R – Try It Online")
The `#` is for comments in R. The 3rd line is only spaces, making a chunk of newline + 2 spaces + newline, so that the previous and next chunk can have no newline.
Doubled, it becomes:
```
s =ss =scan#can#
n=s
n=s()# ()# 
  
  
n/2*n/2*4#  4#  
```
[Try it online!](https://tio.run/##FckxCoBADATAPq9YSHNnI4iWeYwcCDYrGH1/dIup5q4cOxE4Xo7nvNg6tkpEyl8uxkhp3SEGmHBeJlkdkKoP "R – Try It Online")
The single version computes \$\frac n2\times4=2n\$; the double version computes \$\frac n2\times \frac n2\times4=n^2\$.
Here is a slightly longer solution, but with chunk size 3:
# [R](https://www.r-project.org/), 39 bytes (chunk size 3)
```
s =bbb=scan#
n=s(#
 
)# 
n* 1/ 2/ 1* 4#
```
[Try it online!](https://tio.run/##K/pfnJyYp2CrkFaal1ySmZ@noalg@r9YwTYpKckWJKXMlWdbrKHMpcClqazAlaelYKivYKSvYKilYKL8/z8A "R – Try It Online")
Doubled:
```
s =s =bbbbbb=sc=scan#an#
n=
n=s(#s(#
 
 
)# )# 
n*
n* 1/ 1/ 2/ 2/ 1* 1* 4# 4#
```
[Try it online!](https://tio.run/##HcoxCoAwDEbhPacIZGm7SEXHHEYLBZcIRs8f//bxje8Jb4excv@svddtKfMezgrnTL3peATIFDwJEBNkYSArwHUZ1qmWYROI@AE "R – Try It Online")
Note that Giuseppe has [another](https://codegolf.stackexchange.com/a/191600/86301) R answer, with one chunk of 30 bytes.
[Answer]
# [R](https://www.r-project.org/), ~~59~~ 30 bytes (chunk size ~~59~~ 30)
```
F=F+1;f=function(n)n*c(2,n)[F]
```
[Try it online!](https://tio.run/##K/r/383WTdvQOs02rTQvuSQzP08jTzNPK1nDSCdPM9ot9n@ahqnmfwA "R – Try It Online")
Credit to [Robin Ryder](https://codegolf.stackexchange.com/users/86301/robin-ryder) for inspiring this; increments `F` each time, and the function `f` selects the appropriate output.
~~This isn't particularly interesting, but doubtless something clever manipulating the chunk size will be dreamed up.~~ As expected, Robin Ryder came up with [this](https://codegolf.stackexchange.com/a/192700/67312) which is both shorter and has some neat chunk manipulation.
[Answer]
# [PowerShell](https://github.com/TryItOnline/TioSetup/wiki/Powershell), 22 bytes (chunk size 11)
```
param($p)
#   /
2 * $p
```
[Try it online](https://tio.run/##K8gvTy0qzkjNyfmvkmZkW/2/ILEoMVdDpUCTS1lBQUGfy0hBS0Gl4H8tl0pamm01F5I0dpVITK5aLi5Dcx0FXROjGtVqNQWgBQoq8dYKIFYakFXL9R8A).
**Doubled:**
```
param($p)
#param($p)
#   /
2 * $p   /
2 * $p
```
This solution is based on @ShieruAsakoto's [solution](https://codegolf.stackexchange.com/a/192826/68224).
**@Grimy [solution](https://tio.run/##K6gsycjPM/6vUZyZl56TqqOQkl@alJOqaavxPycxNyklUSHPSikxL0UhTytPGcww0srj0uFCkYRyUjBVonD@a1pzFRRl5pVALdMwNNbUhIpArAWL/AcA) that has been converted to PowerShell, 26 bytes (chunk size 13)**
```
param($p)$t=';$p*$p#';$p*2
```
[Try it online](https://tio.run/##K8gvTy0qzkjNyfmvkmZkW/2/ILEoMVdDpUBTpcRW3VqlQEulQBlMG/2v5VJJS7Ot5kJRgls9CoerlovL0FxHQdfEqEa1Wk0BaJmCSry1AoiVBmTVcv0HAA).
**Doubled:**
```
param($p)$t=';param($p)$t=';$p*$p#';$p*2$p*$p#';$p*2
```
[Answer]
# Perl 5 (`-p`), ~~22~~ 15 bytes
-7 bytes thanks to Grimy
```
$_*=$'/4||2;//;
```
[TIO](https://tio.run/##K0gtyjH9/18lXstWRV3fpKbGyFpf3/r/f0MDLiMDLmODf/kFJZn5ecX/dXMKAA)
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 13 bytes
```
ＰＩ×Ｉθ⎇υＩθ²⊞υω
```
[Try it online!](https://tio.run/##S85ILErOT8z5///9ng3v96w8PB1InNvxqK/9fCuYdWjTo65551vPd/7/bwkA "Charcoal – Try It Online") Explanation: The predefined empty list is falsey so the input is multiplied by 2. When doubled the second pass sees the empty string has been pushed to the list so it multiplies the input by itself instead. [Try it online!](https://tio.run/##S85ILErOT8z5///9ng3v96w8PB1InNvxqK/9fCuYdWjTo65551vPdxKS///fEgA "Charcoal – Try It Online") In verbose syntax this corresponds to `Multiprint(Cast(Times(Cast(q), Ternary(u, Cast(q), 2)))); Push(u, w);`.
[Answer]
# Python 3, ~~56~~ 53 bytes
```
print(eval(input()+"**2"[len(*open(__file__))%2:])) #
```
My python skills kinda suck, so can definitely be golfed.. Based on [the Python answer in the "*I double the source, you double the output!*" challenge](https://codegolf.stackexchange.com/a/132565/52210).
Chunk length 53.
[Try it online](https://tio.run/##K6gsycjPM/7/v6AoM69EI7UsMUcjM6@gtERDU1tJS8tIKTonNU9DK78ASMbHp2XmpMbHa2qqGlnFamoqKP//b2gAAA) or [try it online doubled](https://tio.run/##K6gsycjPM/7/v6AoM69EI7UsMUcjM6@gtERDU1tJS8tIKTonNU9DK78ASMbHp2XmpMbHa2qqGlnFamoqKJOl6f9/QwMA).
[Answer]
# Java 8, 62 bytes
```
n->n*(Byte.SIZE>8?n:2);/*
class Byte{static int SIZE=9;}/**///
```
Chunk length 62.
[Try it online](https://tio.run/##hY7BCoJAGITvPsV/XAXdsku1aBB06JAXb0WHZbVY09/QTRDx2bddEzpFl4GZ@Rim4B33i@yhJaq8uXGRw4lLHByAb5JYOwUgiFV0mUlGx0gCCBFo9GP0yL5XeZAez4d4vcNt6DLqOaLkbQu2GVrFlRTTjoWiDRup51FKNbNTc93VMoPKnCCpaiTeL1fg7udB2rcqr4L6pYKnqVSJBANBlgt3OvQTCP8BqxkYnVG/AQ) or [try it online doubled](https://tio.run/##pY8xD4IwEIV3fsWNLQlUcVEbMDFxcJCFTePQVDRFOAytJITw25EiiZNxcLnk3vvu8l4mauFll3uv0KTVVcgUDkJh6wB8lNiuowCS2ImUD0rnDCMGhBB69CJ0ybYxqZ/sj7toucF1QDlzHZkLrcE6rTbCKDn@sVC44h1zXcbYf9c9t0Emuy7VBYqhAklMpfB2OoOg7/xJo01a@OXT@I/BMjkS9CWZz@hY5ysQ/AIWE9A5Xf8C).
**Explanation:**
```
n->                    // Method with integer as both parameter and return-type
  n*                   //  The input, multiplied by:
    (Byte.SIZE>8?      //   If Byte.SIZE is larger than 8:
      n                //    Multiply by the input itself
     :                 //   Else:
      2);              //    Multiply by 2
class Byte{            // Class which overwrites Byte
  static int SIZE=9;}  //  And sets the SIZE to 9
```
In Java, the available comments are `// comment` and `/* comment */`. Which are combined here to overwrite certain parts. See how these comments work thanks to the Java highlighting:
```
n->n*(Byte.SIZE>8?n:2);/*
class Byte{static int SIZE=9;}/**///
n->n*(Byte.SIZE>8?n:2);/*
class Byte{static int SIZE=9;}/**///n->n*(Byte.SIZE>8?n:2);/*
class Byte{static int SIZE=9;}/**///
```
The doubled program created a custom `Byte` class and its value `SIZE=9`, which overwrites the default `java.lang.Byte` class and its value `SIZE=8`.
[Answer]
# [Japt](https://github.com/ETHproductions/japt), ~~7~~ 5 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
```
*N²jJ
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=Kk6yako&input=OA) | [Doubled](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=Kk6yakoqTrJqSg&input=OA)
`²` pushes 2 to the array of inputs `N` then `j` removes & returns the element at index `J=-1` (i.e., the newly inserted `2`) and multiplies the input by that.
When doubled it results in `J` being multiplied by `2`, so the element at index `-2` (i.e., the input) is returned by `j` and used as the multiplier.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~8~~ 6 bytes (chunk length 3)
```
Ḥ;²3ị 
```
[Try it online!](https://tio.run/##y0rNyan8///hjiXWhzYZP9zdrfD//39TAA "Jelly – Try It Online")
[Doubled](https://tio.run/##y0rNyan8///hjiXWhzZBSOOHu7sVwMT///9NAQ "Jelly – Try It Online")
[Answer]
# Nice solution: [Lua](https://www.lua.org), 66 bytes (chunk size 66 bytes)
```
a,x=a and...^2 or ...*2,setmetatable(x or{},{__gc=load'print(a)'})
```
[Try it online!](https://tio.run/##yylN/P8/UafCNlEhMS9FT08vzkghv0gByNAy0ilOLclNLUksSUzKSdWoAIpX1@pUx8enJ9vm5CemqBcUZeaVaCRqqtdq/v//38gQAA "Lua – Try It Online") (double it yourself, it is not so hard)
Oh yeah, pretty sure that there is shorter solution to this, but it's the best I was able to came up with this way. Take input as first argument.
Brief explanation: whole business with `a` is quite obvious for everyone, while the second part with `x` is more interesting. Basically, I create a table (or update existing one on second pass) with finalizer (`__gc` metamethod) which gets called when program exits.
# Lame solution: [Lua](https://www.lua.org), 60 bytes (chunk size 30 bytes)
```
a=a and...^2 or ...*2;                     print(a)os.exit()
```
[Try it online!](https://tio.run/##yylN/P8/0TZRITEvRU9PL85IIb9IAcjQMrJWwAYKijLzSjQSNfOL9VIrMks0NP///29kCAA "Lua – Try It Online") or [Try it doubled!](https://tio.run/##yylN/P8/0TZRITEvRU9PL85IIb9IAcjQMrLGLqqADRQUZeaVaCRq5hfrpVZklmhoEqfq////RoYA "Lua – Try It Online")
Smaller and with better chunking, but ultimately boring and lame without any clever tricks. I'm pretty sure no comments are required to this one.
[Answer]
# [J](http://jsoftware.com/), ~~15~~ ~~10~~ 9 bytes
```
+: :(*-:)
```
[Try it online!](https://tio.run/##y/qvpKeepmBrpaCuoKNgoGAFxLp6Cs5BPm7/ta0UrDS0dK00/2tycaUmZ@QrGCnYKqQpGEI4JmCOEYRjBuYYQziGEClzrv8A "J – Try It Online")
Doubled version: [Try it online!](https://tio.run/##y/qvpKeepmBrpaCuoKNgoGAFxLp6Cs5BPm7/ta0UrDS0dK004Yz/mlxcqckZ@QqGCrYKaQqGEI4JmGME4ViCOcZQGQjPnOs/AA "J – Try It Online")
`f : g` creates a verb that executes `f` when called with one argument, and `g` when called with 2 arguments. So ours executes double `+:` with the original source and `*-:` when the source is doubled. 
This works because a train of two verbs in J becomes a hook, and thus `f f` is executed as `y f (f y)` where y is the original input. Additionally, `*-:` is itself a "dyadic hook" which works by multiplying `*` the left arg by half `-:` the right arg. The left arg will be the original input, and the right arg will be the input doubled, so this will produce the square of the original input.
## original answer
## [J](http://jsoftware.com/), 15 bytes
```
*:@]`(+:@])@.=~
```
[Try it online!](https://tio.run/##y/qvpKeepmBrpaCuoKNgoGAFxLp6Cs5BPm7/tawcYhM0tIGkpoOebd1/TS6u1OSMfAUjBVuFNAVDCMcEzDGCcMzAHGMIxxAiZc71HwA "J – Try It Online")
Doubled version: [Try it online!](https://tio.run/##y/qvpKeepmBrpaCuoKNgoGAFxLp6Cs5BPm7/tawcYhM0tIGkpoOebR0a978mF1dqcka@gqGCrUKagiGEYwLmGEE4lmCOMVQGwjPn@g8A "J – Try It Online")
In the single version, we have a single verb which uses Agenda `@.` to do the if... then logic: If the argument is equal to itself `=~`, then take the argument and double it `(+:@[)`.
However, when we double the code, we get a J hook. Call the verb `f` and the input `y`. Then the hook `f f` executes like this:
```
y f (f y)
```
Which means that now the original input is the left arg, and the right arg is the doubled input. Since these will not be equal, `=~` will return false this time, and now we'll execute the other fork of the Agenda, ie, `*:@]`, which means "square the right arg." And since `~` reverses the inputs of a dyadic verb, the right arg will be the original input.
[Answer]
# [Python 3](https://docs.python.org/3/), 60 bytes
Chunk size 6.  
Not a great solution, but it works.
This is such a unique challenge, it really makes you think from a different perspective.
```
0;  i=input;0;  p=print;n=i()#
x=int(n)##
z=2*x#z=x*x
p(z)##
```
[Try it online!](https://tio.run/##K6gsycjPM/7/38BaQSHTNjOvoLTEGsQusC0oyswrsc6zzdTQVOaqAEqVaORpKitzVdkaaVUoV9lWaFVwFWhUAYX@/zcFAA "Python 3 – Try It Online")
Doubled:
```
0;  i=0;  i=input;input;0;  p=0;  p=print;print;n=i()#n=i()#
x=int
x=int(n)##
(n)##
z=2*x#z=2*x#z=x*x
z=x*x
p(z)##p(z)##
```
[Try it online!](https://tio.run/##NcuxCoAwDIThvU9RyNJ2EsWp9H3MEoNUiH35WDlcvuE/Tp9@nLK5LzVGbpBF717hV7RBvVh6hdI4ZYLB5qXDJJkowNHWYvRrxQLUNOYM3fcX "Python 3 – Try It Online")
[Answer]
# [Cascade](https://github.com/GuyJoKing/Cascade), 13 bytes (chunk size 13)
```
]
&/2
#
*
 2&
```
[Try it online!](https://tio.run/##S04sTk5MSf3/P5ZLTd@IS5lLi0vBSO3/f0MDAA "Cascade – Try It Online")
```
]
&/2
#
*
 2&]
&/2
#
*
 2&
```
[Try it doubled!](https://tio.run/##S04sTk5MSf3/P5ZLTd@IS5lLi0vBSA2F8/@/oQEA "Cascade – Try It Online")
This was quite difficult. The basic gist of this is to print the input multiplied by `2` for the first program, and replace the `2` by a copy of the input for the second. 
### Explanation:
The executed part of the first program looks like
```
]     Redirection
 /
#     Print
*     The multiplication of
 2&   Input and 2 (wrapping around the left)
```
The doubled program basically adds the first `]` to the end of the last line, so the program wraps around to that instead of the `&`. This turns it into
```
]     Redirection
 /
#     Print
*     The multiplication of
 2 ]  Set the value of
& 2   The variable '2' to the input
      Then multiply the result of that (input) by '2' (input)
```
[Answer]
# [Zsh](https://www.zsh.org/), 30 bytes (chunk size 10)
```
m=$m[1]*2
x=$[$1$m]
return $x
```
[Try it online!](https://tio.run/##JYy7CoNAEEX7@YpbTJFY@WgiIn6IWOkkCtlZ2F1hUfz21ZhbHQ6Hu/k5@UU/X3k892RaNn0xZCXFlnsu2AzkJKxOwZHSQfS2DkF8wKKoUKMq8crzBpMlXPtfgX/JLWScLbi7eVUvAQaRJquSTg "Zsh – Try It Online") [Try it doubled!](https://tio.run/##qyrO@J@SX5qUk6qhWf0/11YlN9owVsuIC8GqsFWJVjFUyY1FYhWllpQW5SmoVCCx/tdycaXlFymUpBaXKGTmKRgrWCoYGylYGBhYK6TkcykAAcQiBRWQErBAanJGvoKKPZhdmlecWqKQq1DBlZKfl/ofAA "Zsh – Try It Online")
Abuses the fact that `$var` in `$[$var]` gets expanded first, then evaluated in the arithmetic context.
```
             # each line is 9 characters long. when doubled, each is run twice.
m=$m[1]*2    # first time: m='*2'   second time: $m[1] is '*', so m='**2'
x=$[$1$m]    # single: x=$[$1*2]    doubled: x=$[$1**2];x=$[$1**2].
return $x    # zsh supports 32-bit return values from functions, unlike bash
```
If anyone wants a crack at lowering this, [here's the closest to a `24/8` solution I've gotten](https://tio.run/##JYw5DoAgFAX7f4pXUIBauDQueBtxSRQSwYS4nB23KSeT2e0Y7KSHWXFxBM59y7IIcZ6wTAiSUjJ/nnW4iHqzwinrMGkUqFDkKNO0QWcID/8E7E0@sWmrHBZ46oxW4QY "Zsh – Try It Online") (outputs `x^2+2` when doubled)
]