1, 2, 3, 14... or is it 15? A well known song by the Irish rock band U2 starts with the singer Bono saying "1, 2, 3, 14" in Spanish ("uno, dos, tres, catorce").

There are various theories as to the significance of those numbers. Apparently the official explanation is "we drank too much that night". But there's a more interesting hypothesis: Bono is referring to some integer sequence from OEIS, such as

A107083:


  Integers k such that 10^k + 31 is prime. 
  1, 2, 3, 14, 18, 44, 54, ...


In an interview, when asked the inevitable question "why 14", Bono admitted he was a bit tired of that number. The journalist suggested "15" instead, and in that night's concert the lyrics were indeed changed into "1, 2, 3, 15". (The story can be read here, in Spanish). Quite likely the journalist took inspiration from

A221860:


  Indices k such that prime(k) - k is a power of 2, where prime(k) is the k-th prime. 
  1, 2, 3, 15, 39, 2119, 4189897, ...


The challenge

Write two programs in the same language. The first should take an input n and output the n-th term of A107083, or the first n terms. Similarly, the second should output the n-th term of A221860, or the first n terms.

The score is the sum of lengths of the two programs, in bytes, plus the square of the Levenshtein distance between the byte representations of the two programs.

If a character encoding is used such that each character corresponds to one byte, this script can be used to measure Levenshtein distance.

For example, if the two programs are abcdefgh and bcdEEfg, the score is 8 + 7 + 4^2 = 31.

Lowest score wins.

Aditional rules


The output can be 1-based or 0-based, independently for each sequence (so it is allowed if one of the programs is 1-based and the other is 0-based).
Each program can, consistently but independently of the other, either output the n-th term or the first n terms.
Programs or functions are allowed, independently for each sequence.
Input and output means and format are flexible as usual. Standard loopholes are forbidden.
Jelly, 16 + 16 + 1² = 33

A107083

⁵*+31ÆḍÆNB&gt;/
1Ç#


Try it online!

A221860

⁵*+31ÆạÆNB&gt;/
1Ç#


Try it online!

How it works

1Ç#           Main link. Argument: n

1             Set the return value to 1.
 Ç#           Call the helper link with arguments k, k + 1, k + 2, ... until n of
              them return a truthy value. Return the array of n matches.


⁵*+31ÆḍÆNB&gt;/  Helper link. Argument: k

⁵*            Yield 10**k.
  +31         Yield 10**k + 31.
     Æḍ       Count the proper divisors of 10**k + 31.
              This yields c = 1 if 10**k + 31 is prime, an integer c &gt; 1 otherwise.
       ÆN     Yield the c-th prime.
              This yields q = 2 if 10**k + 31 is prime, a prime q &gt; 2 otherwise.
         B    Binary; yield the array of q's digits in base 2.
          &gt;/  Reduce by "greater than".
              This yields 1 if and only if the binary digits match the regex /10*/,
              i.e., iff q is a power of 2, i.e., iff 10**k + 31 is prime.


⁵*+31ÆạÆNB&gt;/  Helper link. Argument: k

     Æ        Unrecognized token.
              The token, as well as all links to its left, are ignored.
       ÆN     Yield p, the k-th prime.
      ạ       Take the absolute difference of k and p, i.e., p - k.
         B    Binary; yield the array of (p - k)'s digits in base 2.
          &gt;/  Reduce by "greater than".
              This yields 1 if and only if the binary digits match the regex /10*/,
              i.e., iff p - k is a power of 2.