[Question]
  [
Write an \$n\$-bytes program \$AB\$ such that:
* it outputs an integer \$x,\ 0\lt x\lt n\$;
* both its \$x\$-byte prefix \$A\$ and \$(n-x)\$-byte suffix \$B\$, when run as programs, output \$AB\$.
\$A, B\$ and \$AB\$ should:
* run in the same language
* not take any input
* use the same output method
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest code in bytes wins (i.e., your score is \$ n \$).
## Program example (in a dummy 'lizard language')
With \$x = 2\$ bytes, the whole program is `lizard` the first-part program is `li`, and the second-part program is `zard`, then the following behaviour would be expected:
```
 source | output |
--------+--------+
lizard  | 2      |
li      | lizard |
zard    | lizard |
```
  
[Answer]
# [Python 2](https://docs.python.org/2/), 123 bytes
```
u="x='\\nu=%r;exec u'%u;print x+`'input(56)'`+x";exec u'input(56)'
u="x='\\nu=%r;exec u'%u;print x+`'input(56)'`+x";exec u
```
[Try it online!](https://tio.run/##nY7BCsMgEETvfsWyEGxJe0jBHDb4JYkQsJZ6UREF8/XGpJTeexl2Hrs7E7b09u5RtX8aGRGxsiyxSL4sLssuTqYYDZl3eQrRugSlX7l1IaeLGK987Qt@V3703xe15c8D3QfF2MtH0GAdHM1uh8wkRvWZxEiKGECKG8F5q5szRZuQCM4UxEbqDg "Python 2 – Try It Online")
outputs 56 and crash.
Both
```
u="x='\\nu=%r;exec u'%u;print x+`'input(56)'`+x";exec u
```
and
```
'input(56)'
u="x='\\nu=%r;exec u'%u;print x+`'input(56)'`+x";exec u
```
return the original code.
---
Here is another version without any crashing of the program:
# [Python 2](https://docs.python.org/2/), 141 bytes
```
u="x='\\nu=%r;exec u'%u;print x+`'print 62;exit()'`+x";exec u'print 62;exit()'
u="x='\\nu=%r;exec u'%u;print x+`'print 62;exit()'`+x";exec u
```
[Try it online!](https://tio.run/##pU69CsMgGNx9ig8h2JJ2iIPDF3ySREixlrqoGAXz9MY0dOna5bjjfriwpbd3vGr/NDJSSivJkhbJ5tll2cXRFKMhsy6PIVqXoPQLO5ngzbTpcmVLX@g3@Ov9N1fbo2nA@6AIefkIGqyD4@vtgAkFVycTHBUSgBQ3hE9XN2WKNiEhhMe61h0 "Python 2 – Try It Online")
---
Thanks to @ovs who helped me to improve my solution.
[Answer]
# [Gol><>](https://github.com/Sp3000/Golfish), 52 bytes
```
"/+:zQash|2ss}a' 0'rlKH
 0"/+:zQash|2ss}a' 0'rlKH
 0
```
[Try it online!](https://tio.run/##S8/PScsszvj/X0lf26oqMLE4o8aouLg2UV3BQL0ox9uDS8EAt8z//wA "Gol><> – Try It Online") Outputs 26.
The two halves (identical, 26 bytes):
```
"/+:zQash|2ss}a' 0'rlKH
 0
```
[Try it online!](https://tio.run/##S8/PScsszvj/X0lf26oqMLE4o8aouLg2UV3BQL0ox9uDS8Hg/38A "Gol><> – Try It Online") Outputs the original program.
The program path for half and full programs is identical. The only difference is that one more 0 is pushed while going through the 2nd column. If the sum of the top two values is 0, it prints 26 and halts (`ash`). Otherwise:
```
2ss}   Push 34 and place it at the bottom of the stack
a' 0'  Push a newline and ' 0' on the stack
rlK    Reverse the entire stack and push a copy of the entire stack
H      Print each char from top to bottom and halt
```
[Answer]
# Scala 3 `-language:postfixOps`, ~~940~~ 748 bytes
This is a chonky lizard.
```
@main def m:Unit=
 val s="""@main def m:Unit=
 val s=Q%sQ;var x=0;class main extends annotation.Annotation{def dval=print(420);def d=printf(s.replace(""+81.toChar,"\""*3),s,s)}
 return
  new main()dval
 x=0
 @main def n={val s=Q%sQ;printf(s.replace(""+81.toChar,"\""*3),s,s)}""";var x=0;class main extends annotation.Annotation{def dval=print(420);def d=printf(s.replace(""+81.toChar,"\""*3),s,s)}
 return
  new main()dval
 x=0
 @main def n={val s="""@main def m:Unit=
 val s=Q%sQ;var x=0;class main extends annotation.Annotation{def dval=print(420);def d=printf(s.replace(""+81.toChar,"\""*3),s,s)}
 return
  new main()dval
 x=0
 @main def n={val s=Q%sQ;printf(s.replace(""+81.toChar,"\""*3),s,s)}""";printf(s.replace(""+81.toChar,"\""*3),s,s)}
```
`x` is 420.
[Try it online!](https://scastie.scala-lang.org/tiNK6ypJRZyjXGzaxjB5Aw)
[Try the first x bytes online!](https://scastie.scala-lang.org/BbMmaTVXSPOuDmF1hybT7A)
[Try the last (n-x) bytes online!](https://scastie.scala-lang.org/J8lgZcC1TLOKHYxdLMhCsQ)
I'm sure I've done something silly here and can make it smaller, but it's really hard editing quines and seeing what's wrong, so I'll try golfing it more later.
First x bytes, prettified (`...` contains the entire program):
```
@main def m: Unit =
  val s = """..."""
  var x = 0
  class main extends annotation.Annotation {
    def dval = print(420)
    def d = printf(s.replace("" + 81.toChar, "\"" * 3), s, s)
  }
  return new main().d
```
Last (n-x) bytes, prettified (`...` contains the entire program):
```
val x = 0
@main def n = {
  val s = """..."""
  printf(s.replace("" + 81.toChar, "\"" * 3), s, s)
}
```
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal) `D`, 44 bytes
```
`:qpd4NẎ[20|`:qpd4NẎ[20|`:qpd4NẎ[20|`:qpd4NẎ
```
[Try it Online!](https://lyxal.pythonanywhere.com?flags=D&code=%60%3Aqpd4N%E1%BA%8E%5B20%7C%60%3Aqpd4N%E1%BA%8E%5B20%7C%60%3Aqpd4N%E1%BA%8E%5B20%7C%60%3Aqpd4N%E1%BA%8E&inputs=&header=&footer=) Outputs 20.
**Left Side:**
```
`:qpd4NẎ[20|`:qpd4NẎ
```
[Try it Online!](https://lyxal.pythonanywhere.com?flags=D&code=%60%3Aqpd4N%E1%BA%8E%5B20%7C%60%3Aqpd4N%E1%BA%8E&inputs=&header=&footer=)
**Right Side:**
```
[20|`:qpd4NẎ[20|`:qpd4NẎ
```
[Try it Online!](https://lyxal.pythonanywhere.com?flags=D&code=%5B20%7C%60%3Aqpd4N%E1%BA%8E%5B20%7C%60%3Aqpd4N%E1%BA%8E&inputs=&header=&footer=)
```
`...`:qpd4NẎ[20|`...`:qpd4NẎ
`...`:qp        `...`:qp       Standard Vyxal quine (of the first 24 bytes)
        d               d      Double ^
         4NẎ             4NẎ   Remove the last 4 characters of ^ to make it a quine
            [20|               If the top of stack is true, push 20, otherwise the second quine.
```
The `D` flag allows the character `Ẏ` to be used in string literals
[Answer]
# [Haskell](https://www.haskell.org/), 303 bytes
```
k="\nx=\"k=\"++show k++k++show k\nmain=putStr x where x=\"153\";main=putStr$\"k=\"++show q++q++show q\nq="
x="k="++show k++k++show k
main=putStr x where x="153";main=putStr$"k="++show q++q++show q
q="\nx=\"k=\"++show k++k++show k\nmain=putStr x where x=\"153\";main=putStr$\"k=\"++show q++q++show q\nq="
```
[Try it online!](https://tio.run/##y0gszk7Nyfn/P9tWKSavwjZGKRuItbWLM/LLFbK1tbNhzJi83MTMPNuC0pLgkiKFCoXyjNSiVAWQBkNT4xglayRZFRRDCrW1C2HMmLxCWyWuClugPDY7uLBbAbIB1QIk/cjGcxXSzRP//wMA "Haskell – Try It Online")
Prints 153.
```
k="\nx=\"k=\"++show k++k++show k\nmain=putStr x where x=\"153\";main=putStr$\"k=\"++show q++q++show q\nq="
x="k="++show k++k++show k
main=putStr x where 
```
[Try it online!](https://tio.run/##y0gszk7Nyfn/P9tWKSavwjZGKRuItbWLM/LLFbK1tbNhzJi83MTMPNuC0pLgkiKFCoXyjNSiVAWQBkNT4xglayRZFRRDCrW1C2HMmLxCWyWuClugPDY7uLBZ8f8/AA "Haskell – Try It Online")
```
x="153";main=putStr$"k="++show q++q++show q
q="\nx=\"k=\"++show k++k++show k\nmain=putStr x where x=\"153\";main=putStr$\"k=\"++show q++q++show q\nq="
```
[Try it online!](https://tio.run/##y0gszk7Nyfn/v8JWydDUWMk6NzEzz7agtCS4pEhFKdtWSVu7OCO/XKFQW7sQxuQqtFWKyauwjQHKx8AUZGtrZ8OYMXlIpihUKJRnpBalKoA0AK2IQbUDxRBkW2LygNb8/w8A "Haskell – Try It Online")
[Answer]
# [Gol><>](https://github.com/Sp3000/Golfish), 34 bytes
```
'r2sslK5+:l)?H1sh"r2sslK5+:l)?H1sh
```
[Try it online!](https://tio.run/##S8/PScsszvj/X73IqLg4x9tU2ypH097DsDhDCV3g/38A "Gol><> – Try It Online")
This is composed of two identical sections of code, except one uses `'` and the other uses `"`. The combined program outputs 17 (which is only one byte away from being able to use a single instruction to push the number), which splits them into practically identical programs.
[Try the first half online!](https://tio.run/##S8/PScsszvj/X73IqLg4x9tU2ypH097DECQEAA "Gol><> – Try It Online") [And the second half!](https://tio.run/##S8/PScsszvj/X6nIqLg4x9tU2ypH097DECQEAA "Gol><> – Try It Online")
### Explanation:
```
'r2ss               Push the code on the first line and add a " to the start
     lK             Push a copy of the stack
       5+           Add 5 to the top " making it a '
         :l)?       If the length of the stack is less than 39
             H      Halt and output the stack contents
              1sh   Otherwise print 17
```
[Answer]
## [Ruby](https://www.ruby-lang.org/en/), 143 bytes
```
$a=%q[a="$a=%q[#$a];eval$a";$><<a+"b='puts 63;exit';"+a];eval$ab='puts 63;exit';$a=%q[a="$a=%q[#$a];eval$a";$><<a+"b='puts 63;exit';"+a];eval$a
```
Outputs «63» and exits. First 63 bytes
```
$a=%q[a="$a=%q[#$a];eval$a";$><<a+"b='puts 63;exit';"+a];eval$a
```
and the rest
```
b='puts 63;exit';$a=%q[a="$a=%q[#$a];eval$a";$><<a+"b='puts 63;exit';"+a];eval$a
```
output the whole quine. I feel like when golfing it inevitably converged towards the existing python solution in the answers. Other approaches seem to all be bigger.
]