[Question]
  [
# Challenge
Make two programs, A and B, which are both cat programs in the same language. When concatenated, AB (also in the same language) should be a quine.
For example, suppose `hello` and `world` are both cat programs in language XYZ. If `helloworld` is a quine in said language, then your solution is valid.
For those of you unfamiliar with cats and quines, a cat program is one that prints exactly what was given to it via stdin and a quine is a program that prints its own source code.
# Scoring and Rules
* The total byte count of the concatenated AB program is your score. As this is code golf, the lowest score wins.
* Standard loopholes are forbidden
* Input must be taken from stdin and output must go to stdout.
* The cat programs do not need to take arguments; they only need to copy stdin to stdout.
* The quine should work when the program is given no input, but does not have to work correctly (but may) for other inputs.
* The quine does not need to terminate, provided it prints exactly its source code once, nothing more.
* The quine needs to be at least one byte long.
* A and B can be the same program.
* BA does not need to be a quine or even a valid program.
  
[Answer]
# [V](https://github.com/DJMcMayhem/V), 2 + 2 == 4 bytes
```
2i2i
```
[Try the quine!](https://tio.run/##K/v/3yjTKPP/fwA "V – Try It Online")
[Try the cat!](https://tio.run/##K/v/3yjz//@QjMxiBRDKS0lNTdHT0@PiclRwdgxRKCjKTy9KzFUEAA "V – Try It Online")
**A** is `2i`
**B** is also `2i`
## How does it work?
First off, some explanations of how V works. One notable thing that makes this answer possible is that in V, the empty program *is* a cat program. This isn't a special case, it's inherent to how V operates. On startup, all input is loaded into a "buffer", each command modifies the buffer in someway, and then when the program is done, the buffer is implicitly printed. This means that any string of NOPs is also a cat program.
The `i` command means *enter insert mode*, which means every character following an `i` will be added into the buffer. With a number preceding it, that text will be duplicated **n** times. 
This means that for the cat program, nothing will be added to the buffer, and it will be printed as it was read. In other words:
```
        " (Implicitly) Load all input
2       " 2 times,
 i      " Insert the following text into the buffer...
        " (nothing)
        " (Implicitly) Print the buffer
```
But for the quine, there is text after the `i`:
```
2       " 2 times,
 i      " Insert the following text into the buffer...
  2i    "   "2i"
        " (Implicitly) Print the buffer
```
## Cheeky non-answer
# [V](https://github.com/DJMcMayhem/V), 0 bytes
[Try it online!](https://tio.run/##K/sPBCEZmcUKIJSXkpqaoqenx8XlqODsGKJQUJSfXpSYqwgA "V – Try It Online")
**A** is the empty program.
**B** is also the empty program.
:P
[Answer]
# Ruby, 71 bytes
```
2;puts (<<2*2+?2)[/.+2/m]||$<.read
2;puts (<<2*2+?2)[/.+2/m]||$<.read
2
```
Can be broken up into cats as follows:
```
2;puts (<<2*2+?2)[/.+2/m]||$<.read
2
```
and
```
;puts (<<2*2+?2)[/.+2/m]||$<.read
2
```
The two cats are identical except for the leading 2, which is a no-op in all three programs. The `<<2` is a herestring, meaning that everything starting on the next line until a terminating 2 on its own line is a string, which we concatenate to itself (`*2`) and append a trailing 2. In the cats the herestring is well-formed but empty, so the regular expression won't match it and we'll fall through to the `$<.read` expression and output STDOUT. Once we concat the cats, though, the string won't terminate until the third line, so the regex matches and we short-circuit and output the quine.
[Answer]
# [C# (Visual C# Compiler)](http://www.mono-project.com/docs/about-mono/releases/5.0.0/#csc), 551 bytes
### A: 95 bytes
```
class A{public static int i=2;static void Main(string[]args){System.Console.Write(args[0]);}}//
```
[Try it online!](https://tio.run/##Sy7WTS5O/v8/OSexuFjBsbqgNCknM1mhuCSxBEhl5pUoZNoaWUO5ZfmZKQq@iZl5GsUlRZl56dGxiUXpxZrVwZXFJam5es75ecX5Oal64UWZJakaIKlog1hN69paff3///97pObk5AMA "C# (Visual C# Compiler) – Try It Online")
### B: 438 + 18 bytes
```
class A{public static int i=0;}
class B{static void Main(string[]args){if(A.i<1){System.Console.Write(args[0]);return;}var a=@"class A{{public static int i=2;static void Main(string[]args){{System.Console.Write(args[0]);}}}}//class A{{public static int i=0;}}
class B{{static void Main(string[]args){{if(A.i<1){{System.Console.Write(args[0]);return;}}var a=@{0}{1}{0};System.Console.Write(a,'{0}',a);}}}}";System.Console.Write(a,'"',a);}}
```
[Try it online!](https://tio.run/##jY@xbsIwEIb3PoWVhUSiSehYNxLQuerAwIAYDmOiq4wT@S5IleVXr@sKUDvQph7Ow/@fvvsU3StSMSoDRGLh@2FnUAli4PShZYFNLcPdOV/6S3DqcC9eAG1O7NC2my24lgqPh3xR4tOs8Kt3Yn0snztLndHl2iHr/Ku0qbeFdJoHZ2U4gRPQzLMr/ib/QY5QR2Ahvar6E5EUvx3HJH9Y/lPz6unr4GchTXl7bzpJ2WQK55uzX1vZpRNjXHfO7D/UwUBLseofVwyOh/5196YVN8tP "C# (Visual C# Compiler) – Try It Online")
### A+B: 533 + 18 bytes
```
class A{public static int i=2;static void Main(string[]args){System.Console.Write(args[0]);}}//class A{public static int i=0;}
class B{static void Main(string[]args){if(A.i<1){System.Console.Write(args[0]);return;}var a=@"class A{{public static int i=2;static void Main(string[]args){{System.Console.Write(args[0]);}}}}//class A{{public static int i=0;}}
class B{{static void Main(string[]args){{if(A.i<1){{System.Console.Write(args[0]);return;}}var a=@{0}{1}{0};System.Console.Write(a,'{0}',a);}}}}";System.Console.Write(a,'"',a);}}
```
[Try it online!](https://tio.run/##nc@xbsIwEAbgvU9hZSFIkISOmEgFZtSBoQNiOFwnOpQ6ke@CVFl@9ZogQGWApmKxZf1n//4UjRWpEFQFRGLumnZXoRLEwN2GhgXmr/JyPNT4KVaAJia2aMrNFmxJQ7f@JtZfybI2VFc6@bDIOj5Fm2w7lN6n6V/PZ9K/nPOF6ynCIp4nOJv0VVrNrTXSH8AKyN@ia/1zvF7frfAR8dfYh7xR/pN5dbrMu4nvVnn/3mjQZYMRnP8cPZyKLjMh/KiigpJC2kzXDJbb5n2314rzxRE "C# (Visual C# Compiler) – Try It Online")
A and B take input as a command-line argument. A+B ignores any input. 18 bytes on B and A+B are added for the `/p:StartupObject=B` option sent to MSBuild. It's only strictly necessary on A+B, but it seemed like cheating to not also have it in B. This way, the compiler flags for A+B are the compiler flags for A (none) plus the compiler flags for B.
**Explanation**
Program A is straightforward. Class A contains an (unused) static variable `i` initialized to `2`, and prints its first argument when run. The `//` at the end is important for the A+B code, but does nothing in A itself.
Program B is weird in isolation, but essentially the same. It creates a Class A containing a static variable `i` initialized to `0`, and then runs the Main method of Class B, which does the same as Program A because `A.i` is less than 1, and returns before any of the weird stuff. The newlines aren't necessary here, but are important for A+B.
When combined, the `//` from Program A comments out the Class A declaration from Program B, but because of the newline Class B is fine, allowing `A.i` to refer to the `2` value from Program A instead. The Compiler Flag makes the Program run B.Main() since A.Main() also exists. The result is that Program A+B does not output its argument, but instead goes to the following segment of B.Main(), which is basically just the [standard C# quine](https://codegolf.stackexchange.com/a/68891/71434).
[Answer]
# Pyth, ~~29 bytes (5 + 24)~~ 27 bytes (5 + 22)
```
pz=T0?TzjN*2]"pz=T0?TzjN*2]     # Quine
pz=T0                           # Cat A
     ?TzjN*2]"pz=T0?TzjN*2]     # Cat B
```
That was fun.  
[Try the quine here](http://pyth.herokuapp.com/?code=pz%3DT0%3FTzjN%2a2%5D%22pz%3DT0%3FTzjN%2a2%5D&debug=0)  
[Try the first cat here](http://pyth.herokuapp.com/?code=pz%3DT0&input=Mnemonic&debug=0)  
[Try the second cat here](http://pyth.herokuapp.com/?code=%3FTzjN%2a2%5D%22pz%3DT0%3FTzjN%2a2%5D&input=Mnemonic&debug=0)
### Explanations
```
Cat A
pz=T0
pz       Print the input.
  =T0    (Irrelevant for cat)
Cat B
?TzjN*2]"pz=T0?TzjN*2]
?Tz                      If T (10) is truthy, output the input.
   jN*2]"pz=T0?TzjN*2]   (Irrelevant for cat)
Quine
pz=T0?TzjN*2]"pz=T0?TzjN*2]
pz                            Print the (empty) input (without a newline).
  =T0                         Set T to 0.
     ?Tz                      If T (0) is truthy, output the input.
             "pz=T0?TzjN*2]   Otherwise, get this string...
          *2]                 ... take two copies...
        jN                    ... and join them with a quote.
```
[Answer]
# [Haskell](https://www.haskell.org/), 116 + 20 = ~~187~~ ~~175~~ ~~174~~ 136 bytes
*A bunch of bytes saved since Ørjan Johansen showed me `interact`*
## Cat 1
```
g=";main|idmain<-(++\"g=\"++show g++g)=interact idmain|1>0=interact id";main|idmain<-(++"g="++show g++g)=interact id
```
[Try it online!](https://tio.run/##y0gszk7Nyfn/P91WyTo3MTOvJjMFRNnoamhrxyil28YoaWsXZ@SXK6Rra6dr2mbmlaQWJSaXKECU1RjaGSCLYZoBNAKnCf//e3lnZWclZhencAHdkZNinVOcmA0A "Haskell – Try It Online")
## Cat 2
```
main|1>0=interact id
```
[Try it online!](https://tio.run/##y0gszk7Nyfn/PzcxM6/G0M7ANjOvJLUoMblEITPl/38v76zsrMTs4hQuoLqcFOuc4sRsAA "Haskell – Try It Online")
## Quine
```
g=";main|idmain<-(++\"g=\"++show g++g)=interact idmain|1>0=interact id";main|idmain<-(++"g="++show g++g)=interact idmain|1>0=interact id
```
[Try it online!](https://tio.run/##y0gszk7Nyfn/P91WyTo3MTOvJjMFRNnoamhrxyil28YoaWsXZ@SXK6Rra6dr2mbmlaQWJSaXKECU1RjaGSCLYZoBNIIkE/7/BwA "Haskell – Try It Online")
---
The basic principle at work here is that when we add the second cat to the first we change the name of the function we are interacting with from `a` to `idmain`. Since `interact id` is a cat we want `idmain` to me a function that returns a quine. The obvious solution would be to use `const`, however since we can assume the input is empty `(++)` works as well.
From here we find the source code via pretty standard means, we have a variable `g` that encodes the source and we use a special wrapper to print it in string form and code form. There is a slight exception that we need to put our encoder at the front because we already need to end with `interact id`. This means an extra `g=` is not encoded and has to be handled manually. Our next cat is pretty standard except we need to make it valid code when tacked on to the end of the other cat so we need both cats to be instances of pattern guards.
# Alternative Strategy, 43 + 105 = ~~186~~ 148
## Cat 1
```
g="";main|idmain<-(++g++show g)=interact id
```
[Try it online!](https://tio.run/##y0gszk7Nyfn/P91WSck6NzEzryYzBUTZ6Gpoa6draxdn5JcrpGvaZuaVpBYlJpcoZKb8/w8A "Haskell – Try It Online")
## Cat 2
```
main|1>0=interact id where g="g=\"\";main|idmain<-(++g++show g)=interact idmain|1>0=interact id where g="
```
[Try it online!](https://tio.run/##y0gszk7Nyfn/PzcxM6/G0M7ANjOvJLUoMblEITNFoTwjtShVId1WKd02RilGyRqsKDMFRNnoamhrp2trF2fklyukayJrw2/U//9e3lnZWYnZxSlcQMtzUqxzihOzAQ "Haskell – Try It Online")
## Quine
```
g="";main|idmain<-(++g++show g)=interact idmain|1>0=interact id where g="g=\"\";main|idmain<-(++g++show g)=interact idmain|1>0=interact id where g="
```
[Try it online!](https://tio.run/##y0gszk7Nyfn/P91WSck6NzEzryYzBUTZ6Gpoa6draxdn5JcrpGvaZuaVpBYlJpcoQKRrDO0MkMUUyjNSi1IVgKak28YoxVDHqP//AQ "Haskell – Try It Online")
[Answer]
# Python 3, 286 bytes
My first Python golf and my first quine! Not very elegant, but it works.
## Program A (238 bytes)
```
from atexit import*;s="from atexit import*;s=%r;register(lambda:print(end='b'in globals()and s%%s or open(0).read()));b=0\nif's'not in vars():print(end=open(0).read())";register(lambda:print(end='b'in globals()and s%s or open(0).read()));
```
(no trailing newline)
## Program B (48 bytes)
```
b=0
if's'not in vars():print(end=open(0).read())
```
(no trailing newline)
## Try It Online
* [program A](https://tio.run/##lY1BCsIwEEX3PcVQKElcSMGdpTdxMzGxDTQzYTKInj52KdKN8Fcf3nvlrSvTpbWHcAbU@EoKKRcWPU117o/vQSaJS6oaxW6YfcBrkURqI4XZeJMIlo09btU6pAB1GCqwAJdIdnRniRisc27y83ij9DDVEO8BgifKznzZfpD@3/BxtzVdU@32YXdHhSK8COYP)
* [program B](https://tio.run/##BcExCoAwDADAva/o1mQRwU3oY6KtWtCkpEHw9fGuf3YJL@5bnkM70kgsFhvHl3QArl0bG1QuWXplmHHSSgUQ3ekeEijsZLGrnErPDw)
* [concatenation](https://tio.run/##lc1BCsIwEIXhvacYCiGJCym4s/QmbiYkrYFkJkxC0dPHLkV00e2D/33l1R5M194X4QzYwjM2iLmwtPNU5@H3rGSSsMbagpiE2Xm8FYnUTCA/a6cjwZrYYarGInmoSlVgAS6BzGgvEtAba@3k5vFOcdFVE@8AwYayNx9vX8lwFP7rno6wvb8B)
## Acknowledgments
* -24 bytes thanks to Jo King
* -82 bytes thanks to Jo King
[Answer]
# [Python 3](https://docs.python.org/3/), ~~137~~ 78 + 37 = 115 bytes
*-22 bytes thanks to Jakque!*
Program A:
```
s='s=%r;exec(s[20:45])#print(end=open(0).read())\nprint(s%%s)';exec(s[20:45])#
```
[Try it online!](https://tio.run/##K6gsycjPM/7/v9hWvdhWtcg6tSI1WaM42sjAysQ0VlO5oCgzr0QjNS/FNr8gNU/DQFOvKDUxRUNTMyYPIlWsqlqsqY6u7f//xKRkAA "Python 3 – Try It Online")
And program B:
```
print(end=open(0).read())
print(s%s)
```
[Try it online!](https://tio.run/##K6gsycjPM/7/v6AoM69EIzUvxTa/IDVPw0BTryg1MUVDU5MLIlOsWqzJ9f9/YlIyV0pqGgA "Python 3 – Try It Online")
Make Quine AB!
```
s='s=%r;exec(s[20:45])#print(end=open(0).read())\nprint(s%%s)';exec(s[20:45])#print(end=open(0).read())
print(s%s)
```
[Try it online!](https://tio.run/##K6gsycjPM/7/v9hWvdhWtcg6tSI1WaM42sjAysQ0VlO5oCgzr0QjNS/FNr8gNU/DQFOvKDUxRUNTMyYPIlWsqlqsqU60Ni6YrmJNrv//AQ "Python 3 – Try It Online")
Only works when input is empty, otherwise it prepends the input to the output.
[Answer]
# [C++ (clang)](http://clang.llvm.org/), 313 + 102 = 415 bytes
Program A (ends in a newline):
```
#include<cstdio>
#define Q(x,y)#x,B=#y;x
int c;auto I="#include<cstdio>",A=Q(int main(){if(c)printf("%s\n#define Q(x,y)#x\",\"#y;x\nint c;auto I=\"%s\",A=Q(%s,)\n#ifdef Q\nint n=++c;\n#else\n%s\n%s\n#endif",I,I,A,I,B);else while((c=getchar())>=0)putchar(c);},int c;int main(){while((c=getchar())>=0)putchar(c);})
```
Program B (does not end in newline):
```
#ifdef Q
int n=++c;
#else
#include<cstdio>
int c;int main(){while((c=getchar())>=0)putchar(c);}
#endif
```
Not terribly sneaky, and as usual C++ isn't that great for quining. I won't be surprised if there are ways to shave bytes here and there off the same idea. The one little catch is changing the behavior of something after it's been defined, and a dynamic variable initializer with side effect does the trick. (Can this even be done in C without compiler extensions?)
Try it online: [A](https://tio.run/##jZCxTsQwDIb3PoWV6qREzSGYGEpOutturMSYJbhJG8glpWm5HohXp6R0gZuQ5cH2/3@2jF23Rad8M8@59ejGWj9gHGobdllea2O9hopO/MLyiR9EfimnzPoBsFTjEOAoyLWN8L2o6KI5Kesp@7CGIuv61DGUbKL011xJuCQLWfo/aLmoV9wmcpaM1iQrVKvOi6LAMnW1i1r6hfxD1762hvBjin3KAysXAZxb6zSlKBo9YKt6ythO3LJuXCtk5Sdf1/@6/R8mls3zY6vhdbT4Ak99OHswYYLn8dTFLLzpHoY0dur9AnVobr7QONXEeZveJbAo7u6/AQ "C++ (clang) – Try It Online"), [B](https://tio.run/##JY1LDsIgGIT3nIKkGwip0ZWLSu9g4gXw51GUAhawPuLVxaqbSSbf5BuIsQUnvKm1sVoqjffI@ow9Zww61CiXFGqsB1ek2kHK0ob@t4Dum6OwntDnPFinCAFuVIZBTITSnq9pLP8GtHstLi@trvUwKHwpFs74OIXZYx1u@FTGmFC4qgnnBTvxuGMZzOoN2gmTarscc2Bss/0A "C++ (clang) – Try It Online"), [AB](https://tio.run/##nZDBT8MgGMXv/BWkzRJImdGTh8qS7bZjE49c8Cu0KINaWtdq/NetdI1Rt4sxhAMf7/3eA2iaNVjpqmlKjQPbl@oOQlcav0FpqbRxChdkYCNNB7bj6ZgPyLgOQy77zuM9T85tCdvygsyagzSO0DejCdCmjRNNklUQ7pwrEiaSmSzcL7SY1QtuFRiNRqOjFReLzvEsgzxOlQ1KuJl8oitXGp2wfVzbuHc0nwX4WBurCAFeqQ5q2RJKN/yaNv1yApq/syX@R/c/mCj6qoW@W6FTKXTxpf8JQMuLpum@Vvi5N/CEH1p/dFj7AT/2hyYg/6Ja3MVrK19HXPrq6gO0lVWY1jGYQ5bd3H4C "C++ (clang) – Try It Online")
(The only portability concern I'm aware of is that the program assumes `<cstdio>` puts names both in the global namespace and in `std`.)
[Answer]
# [Befunge-98 (FBBI)](https://github.com/catseye/FBBI), 8 + 15 = 23 bytes
**A + B:** (only works for no input)
```
+9*5~,#@#@~,9j>:#,_:@#"
```
[Try it online!](https://tio.run/##S0pNK81LT9W1tPj/X9tSy7ROR9lB2aFOxzLLzkpZJ97KQVnp/38A "Befunge-98 (FBBI) – Try It Online")
**A:**
```
+9*5~,#@
```
[Try it online!](https://tio.run/##S0pNK81LT9W1tPj/X9tSy7ROR9nh//@cxNKi8ox049yUjLKc/MzE0tSMpDJT4xKjfIuMpEQA "Befunge-98 (FBBI) – Try It Online")
**B:**
```
#@~,9j>:#,_:@#"
```
[Try it online!](https://tio.run/##S0pNK81LT9W1tPj/X9mhTscyy85KWSfeykFZ6f///DwL85TKcmOTknwL8zwgLjfOL8m0yCsHAA "Befunge-98 (FBBI) – Try It Online")
[Answer]
# [Attache](https://github.com/ConorOBrien-Foxx/Attache), 15 + 126 = 141 bytes
**A:**
```
AllInput[]|Echo
```
[Try it online!](https://tio.run/##SywpSUzOSP3/3zEnxzOvoLQkOrbGNTkj////SMcgdy6FlOI0rjTrRIXilDT1RCUA "Attache – Try It Online")
**B:**
```
@{If[_,s.="AllInput[]|Echo@{If[_,s.=%s;;Printf[s,Repr!s],AllInput[]|Echo]es}|Call";;Printf[s,Repr!s],AllInput[]|Echo]es}|Call
```
[Try it online!](https://tio.run/##SywpSUzOSP3/36HaMy06XqdYz1bJMSfHM6@gtCQ6tsY1OSMfIaNabG0dUJSZV5IWXawTlFpQpFgcq4OmOja1uLbGOTEnR4kEtVz//0c6BrlzKaQUp3GlWScqFKekqScqAQA "Attache – Try It Online")
**A + B:**
```
AllInput[]|Echo@{If[_,s.="AllInput[]|Echo@{If[_,s.=%s;;Printf[s,Repr!s],AllInput[]|Echo]es}|Call";;Printf[s,Repr!s],AllInput[]|Echo]es}|Call
```
[Try it online!](https://tio.run/##SywpSUzOSP3/3zEnxzOvoLQkOrbGNTkj36HaMy06XqdYz1YJp4xqsbV1QFFmXkladLFOUGpBkWJxrA6a6tjU4toa58ScHCUS1HL9/x/pGOTOpZBSnMaVZp2oUJySpp6oBAA "Attache – Try It Online")
## Explanation
Each of the cat program encodes `AllInput[]|Echo`, which is a simple cat program. **B** is the main quine phase; alone, it is a vectorized function (through unary `@`) called with no inputs (being called as `|Call`). Thus, the first conditional `If[_,A,B]` executes `B`, which is simply `AllInput[]|Echo`.
When **A + B** is executed, unary `@` becomes binary `@` due to `Echo` merging with the lambda:
```
AllInput[]|Echo@{If[_, ...
```
Now, this means that the lambda is executed before `Echo` is. Back to the conditional, this function now has all of STDIN as an argument. So, `If[_,A,B]` executes `A`, which is the standard quine framework.
[Answer]
# [Stax](https://github.com/tomtheisen/stax), 16 + 12 = 28 bytes
Cat 1:
```
"yi|d|ca34b4lr"y
```
[Run and debug it](https://staxlang.xyz/#c=%22yi%7Cd%7Cca34b4lr%22y&i=%22sdasdnjek%22)
```
"yi|d|ca34b4lr"y Full program, implicit input
"yi|d|ca34b4lr"  Push the string
               y Push raw input
                 Implicit output of top item
```
Cat 2:
```
i|d|ca34b4lr
```
[Run and debug it](https://staxlang.xyz/#c=i%7Cd%7Cca34b4lr&i=%22sdasdnjek%22)
```
i|d|ca34b4lr Full program, implicit input
i            Don't parse input (prefix directive)
 |d          Push main stack depth, always zero
   |c        Cancel because top item is falsy, and implicitly print
     a34b4lr Never executed
```
Quine:
```
"yi|d|ca34b4lr"yi|d|ca34b4lr
```
[Run and debug it](https://staxlang.xyz/#c=%22yi%7Cd%7Cca34b4lr%22yi%7Cd%7Cca34b4lr&i=%22sdasdnjek%22)
```
"yi|d|ca34b4lr"yi|d|ca34b4lr Full program
"yi|d|ca34b4lr"              Push the string
               y             Push input
                i            No-op
                 |d          Push main stack depth, i.e. 2
                   |c        Do nothing because top is truthy
                     a       Get the string to the top
                      34     Push 34 (charcode of ")
                        b    Copy both
                         4l  Listify top 4
                           r Reverse
                             Implicit output
```
[Answer]
# Cat 1 :
# [Lua](https://www.lua.org), 41 bytes
```
a=io.read;while a(0)do io.write(a(1))end;
```
[Try it online!](https://tio.run/##yylN/P8/0TYzX68oNTHFujwjMydVIVHDQDMlXwEoWF6UWZKqkahhqKmZmpdi/f9/cn5Kanp@ThoA "Lua – Try It Online")
---
# Cat 2 :
# [Lua](https://www.lua.org), 70 bytes
```
if a then io.input(arg[0])end;a=io.read;while a(0)do io.write(a(1))end
```
[Try it online!](https://tio.run/##FcoxCsAgDADAr2TUpdhZ@pLSIZhUA2KKVXy@retxueOccgNCS1xAdJPy9GawxtNdlgt5PH6tjORHksyAxlnSVUeVxgbNblec8@WghSAocdR8fw "Lua – Try It Online")
---
[Answer]
# [><>](https://esolangs.org/wiki/Fish), 12 +3 = 15 bytes
Program A:
```
<oi
```
[Try it online!](https://tio.run/##S8sszvj/3yY/8///xKRkAA "><> – Try It Online")
And Program B:
```
>i!o|o<}*d3'
```
[Try it online!](https://tio.run/##S8sszvj/3y5TMb8m36ZWK8VY/f//xKRkAA "><> – Try It Online")
Make Program AB:
```
<oi>i!o|o<}*d3'
```
[Try it online!](https://tio.run/##S8sszvj/3yY/0y5TMb8m36ZWK8VY/f//xKRkAA "><> – Try It Online")
[Answer]
# [Python 3.8 (pre-release)](https://docs.python.org/3.8/), 26 + 71 = 97 bytes
## Cat 1 (26 bytes):
```
id=print(open(0).read());
```
[Try it online!](https://tio.run/##K6gsycjPM7YoKPr/nyszxbagKDOvRCO/IDVPw0BTryg1MUVDU9P6///g/NxUhcy8gtKSYq60/CKFkoxUheTEEoWCovz0osRcAA "Python 3.8 (pre-release) – Try It Online")
## Cat 2 (71 bytes):
```
exec(s:='id=print(open(0).read()if id else s[:23]+");exec(s:=%r)"%s)')
```
[Try it online!](https://tio.run/##NcvBCsIwDADQ@74iDMYaBBF3kcm@wuPwUNbMFVwTkgju6@vJd39y@MZluInWSl9ago1Tn9MkmosHFirhgmelmALmFXICehuBzeN1eJ5avP9Tp9h2hj02tT54J8hFPm7Nygq@ESzRQZRfGvcf "Python 3.8 (pre-release) – Try It Online")
## Quine = Cat 1 + Cat 2 (97 bytes):
```
id=print(open(0).read());exec(s:='id=print(open(0).read()if id else s[:23]+");exec(s:=%r)"%s)')
```
[Try it online!](https://tio.run/##K6gsycjPM7YoKPr/nyszxbagKDOvRCO/IDVPw0BTryg1MUVDU9M6tSI1WaPYylYdh4rMNIXMFIXUnOJUheJoKyPjWG0lhCbVIk0l1WJNdU2u//8B "Python 3.8 (pre-release) – Try It Online")
## How it works:
Cat 1:
* `open(0).read` reads the STDIN
* `id=print(...)` prints it and returns `None` which will be stored into `id` (remember it for later)
Cat 2:
* `<instructions for cat> if id else <other instuctions>` will execute `<instructions for cat>` because `id` is a built-in and is evaluated as `True`.
Quine:
* Because of Cat 1, id is now equal to `None` and `<instructions for cat> if id else <other instuctions>` will now execute `<other instructions>`
* Because both our program have the same structure for cat, we print the cat part of Cat 2 for quining cat1 : `s[:23]+");`
* Then the programm is just a variant of `exec(s:='print("exec(s:=%r)"%s)')`, a quine in Pyhton 3.8+
## Notes:
Both my cat programs add a trailing new line at the end. I assume that it was accepted since it wasn't frormally banned and since most of the cat challenges accept it.
Otherwise I have a 103 bytes solution which doesn't add trailing newlines:
```
id=print(end=open(0).read());                                                                           #Cat1
                             exec(s:='id=print(end=open(0).read()if id else s[:27]+");exec(s:=%r)"%s)') #Cat2
id=print(end=open(0).read());exec(s:='id=print(end=open(0).read()if id else s[:27]+");exec(s:=%r)"%s)') #Quine
```
[Try it online!](https://tio.run/##K6gsycjPM7YoKPr/PzPFtqAoM69EIzUvxTa/IDVPw0BTryg1MUVDU9M6tSI1WaPYylYdj6rMNIXMFIXUnOJUheJoKyPzWG0lhEbVIk0l1WJNdc3//wE "Python 3.8 (pre-release) – Try It Online")
### Bonus:
Here is a solution in 116 bytes which accepts not-empty input for the quine program:
```
while 1:id or print(input());id=0;                                                                                   #Cat1
                                  exec(s:='id or~input(s[36:]+"exec(s:=%r)"%s)\nwhile 1:id or print(input());id=0;') #Cat2
while 1:id or print(input());id=0;exec(s:='id or~input(s[36:]+"exec(s:=%r)"%s)\nwhile 1:id or print(input());id=0;') #Quine
```
[Try it online!](https://tio.run/##K6gsycjPM7YoKPr/vzwjMydVwdAqM0Uhv0ihoCgzr0QjM6@gtERDU9M6M8XWwDq1IjVZo9jKVh2spA4iWRxtbGYVq60Ek1Qt0lRSLdaMySNsnrrm//@ZJQrl@UXZxVypZal5CuWZJRkKYEXFAA "Python 3.8 (pre-release) – Try It Online")
[Answer]
# [Klein](https://github.com/Wheatwizard/Klein) 0XX, 6 + 7 = 13 bytes
*Works in 000, 001, 010 and 011.*
*Note that these answers all contain the unprintible byte 17, or "device control 1".*
## Cat 1
```
<:2*@
```
[Try it online!](https://tio.run/##y85Jzcz7/1/QxspIy@H///@6yf8NDAz@e2QCAA "Klein – Try It Online")
The `<` redirects the pointer off the left. It appears on the right at `@` and halts immediately spilling its input as output.
## Cat 2
```
@*2:<"
```
[Try it online!](https://tio.run/##y85Jzcz7/99By8jKRlDp////usn/DQwM/ntkAgA "Klein – Try It Online")
It immediately encounters `@` and halts with no further execution. It outputs the input with no changes.
## Quine
```
<:2*@@*2:<"
```
[Try it online!](https://tio.run/##y85Jzcz7/1/QxspIy8FBy8jKRlDp////usn/DQwMAA "Klein – Try It Online")
Like **cat 1** this first encounters `<` which sends it off the left and onto the right. But this time on the right we encounter `"` which puts us into string mode. This causes us to push the entire program (minus the quote) to the stack *backwards*. In order to make things easier for myself this part of the program is a palindrome, so we don't have to reverse it. Now we just need to add the `"` at the end. The program begins with a , which is chosen because multiplying it by 2 gives us `"`. So we duplicate and multiply by two to make the `"` and exit at `@`.
[Answer]
# [Vyxal](https://github.com/Lyxal/Vyxal) `ajṠ`, 13 + 1 = 14 bytes
**A:** ([Try it Online!](http://lyxal.pythonanywhere.com?flags=aj%E1%B9%A0&code=%60%3Aqpw%24%24%60%3Aqpw%24&inputs=This%20is%20a%0A%60cat%60%0Aprogram%0A%5B%5D&header=&footer=))
```
`:qpw$$`:qpw$
```
**B:** ([Try it Online!](http://lyxal.pythonanywhere.com?flags=aj%E1%B9%A0&code=%24&inputs=This%20is%20a%0A%60cat%60%0Aprogram&header=&footer=))
```
$
```
**A + B:** ([Try it Online!](http://lyxal.pythonanywhere.com?flags=aj%E1%B9%A0&code=%60%3Aqpw%24%24%60%3Aqpw%24%24&inputs=This%20is%20a%0A%60cat%60%0Aprogram%0A%5B%5D&header=&footer=))
```
`:qpw$$`:qpw$$
```
## Explained
```
`:qpw$$`:qp      # Modified standard Vyxal quine
           w     # Wrap quine in array, so join on newline works
            $    # Swap the quine and the input
$                # Swap
                 #   If the program is standalone, this does nothing
                 #   If concatenated, this undoes the previous swap and puts the quine at the top
```
* `a`: Push entire input split on newlines to the top of the stack
* `j`: Join top of stack on newlines and output (undo split from `a`)
* `Ṡ`: Treat all inputs as strings, so proper output is given for inputs like `[]` and `""`
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 199 bytes
```
a=()=>console.log(require('fs').readFileSync(0)+'');a();var a=a||0;b=()=>console.log(require('fs').readFileSync(0)+'');!a?b():c=()=>console.log(`a=${a};a();var a=a||0;b=${b};!a?b():c=${c},c()`),c()
```
[Try it online!](https://tio.run/##nY1BDsIgEADvfYUmJOxGbXqWoDc/4Ae6bNFgSFHQJobydownD715mdvM3GiixNHdn7sxDLbWhjSgPnAYU/C29eEK0T5eLlqQlySxjZaGk/P2/B4ZOtxIiYoA1URxRZrmuVPmj8SajgZwzwu1Jy0yleVDZFN@mshctgzY45dNrR8 "JavaScript (Node.js) – Try It Online")
## Cat A, 57 bytes
```
a=()=>console.log(require('fs').readFileSync(0)+'');a();
```
[Try it online!](https://tio.run/##BcExDoAgDADA3Ve4tY2RuBMc/YAvaKAaDAEFNfH19e7gl5uv8bzHXIKoduyQ3OxLbiWJSWXHKtcTqyBsDchU4bDEJOuXPU40AJBlJKvq@e75Bw "JavaScript (Node.js) – Try It Online")
## Cat B, 142 bytes
```
var a=a||0;b=()=>console.log(require('fs').readFileSync(0)+'');!a?b():c=()=>console.log(`a=${a};a();var a=a||0;b=${b};!a?b():c=${c},c()`),c()
```
[Try it online!](https://tio.run/##Zc1BCsIwEEDRvaeoEMgMaunaEN15AS/QyTRKJCSa1IK0OXvElYibv3v8G02UObn7uAtxsLVOlBrStCydMhpQHziGHL1tfbxCso@nSxbkJUtsk6Xh5Lw9vwJDhxspUa3paAD3/Ed70mKmoghQ/TzEbMqXiZnLlgF7/HRVK9PYmDc "JavaScript (Node.js) – Try It Online")
]