3DES inner CBC: Biham has shown that inner chaining weakens 3DES.

The OpenSSL implementation of triple DES in CBC mode appears to use
inner chaining. This is from cbc3_enc.c:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/* HAS BUGS? DON'T USE - this is only present for use in des.c */
void des_3cbc_encrypt(des_cblock *input, des_cblock *output, long length,
des_key_schedule ks1, des_key_schedule ks2, des_cblock *iv1,
des_cblock *iv2, int enc)
{
    int off=((int)length-1)/8;
    long l8=((length+7)/8)*8;
    des_cblock niv1,niv2;
   
    if (enc == DES_ENCRYPT)
    {
        des_cbc_encrypt(input,output,length,ks1,iv1,enc);
        if (length >= sizeof(des_cblock))
            memcpy(niv1,output[off],sizeof(des_cblock));
        des_cbc_encrypt(output,output,l8,ks2,iv1,!enc);
        des_cbc_encrypt(output,output,l8,ks1,iv2, enc);
        if (length >= sizeof(des_cblock))
            memcpy(niv2,output[off],sizeof(des_cblock));
    }
    else
    {
        if (length >= sizeof(des_cblock))
            memcpy(niv2,input[off],sizeof(des_cblock));
        des_cbc_encrypt(input,output,l8,ks1,iv2,enc);
        des_cbc_encrypt(output,output,l8,ks2,iv1,!enc);
        if (length >= sizeof(des_cblock))
            memcpy(niv1,output[off],sizeof(des_cblock));
        des_cbc_encrypt(output,output,length,ks1,iv1, enc);
    }
    memcpy(*iv1,niv1,sizeof(des_cblock));
    memcpy(*iv2,niv2,sizeof(des_cblock));
}

Note that there is no looping at this level; the entire message is CBC
encrypted, decrypted, and encrypted again.

Biham has shown that inner chaining weakens 3DES. Outer chaining is
generally preferred. SSL uses outer chaining. How can OpenSSL be
compatible if it is doing inner chaining? Is the code above not used?

——————————–
Handbook of Applied Cryptography, Chapter 7 Block Ciphers

7.40 Fact: If t known plaintext-ciphertext pairs are available, an attack on two-key triple-DES requires O(t) space and 2^(120-lgt) operations.

(iii) Multiple-encryption modes of operation
In contrast to the single modes of operation in Figure 7.1, multiple modes are variants of multiple encyption. multiple encryption constructed by concatenating selected single modes. For example, the combination of three single-mode CBC operations provides triple-inner-CBC; an alternative is triple-outer-CBC, the composite operation of triple encryption (per Definition 7.32) with one outer ciphertext feedback after the sequential application of three single-ECB operations. With replicated hardware, multiple modes such as triple-inner-CBC may be pipelined allowing performance comparable to single encryption, offering an advantage over triple-outer-CBC. Unfortunately (Note 7.41), they are often less secure.

7.41 Note: (security of triple-inner-CBC) Many multiple modes of operation are weaker than the corresponding multiple-ECB mode (i.e., multiple encryption operating as a black box with only outer feedbacks), and in some cases multiple modes (e.g., ECB-CBC-CBC) are not significantly stronger than single encryption. In particular, under some attacks triple-inner-CBC is significantly weaker than triple-outer-CBC; against other attacks based on the block size (e.g., Note 7.8), it appears stronger.

(iv) Cascade ciphers
Counter-intuitively, it is possible to devise examples whereby cascading of ciphers (Definition 7.29) actually reduces security. However, Fact 7.42 holds under a wide variety of attack models and meaningful definitions of “breaking”.

7.42 Fact: A cascade of n (independently keyed) ciphers is at least as difficult to break as the first component cipher. Corollary: for stage ciphers which commute (e.g., additive stream ciphers), a cascade is at least as strong as the strongest component cipher.

Fact 7.42 does not apply to product ciphers consisting of component ciphers which may have dependent keys (e.g., two-key triple-encryption); indeed, keying dependencies across stages may compromise security entirely, as illustrated by a two-stage cascade wherein the components are two binary additive stream ciphers using an identical keystream — in this case, the cascade output is the original plaintext.

Fact 7.42 may suggest the following practical design strategy: cascade a set of keystream generators each of which relies on one or more different design principles. It is not clear, however, if this is preferable to one large keystream generator which relies on a single principle. The cascade may turn out to be less secure for a fixed set of parameters (number of key bits, block size), since ciphers built piecewise may often be attacked piecewise.

Pipe & Filter

For a filter:
before you call ini(), the input will not be consumed.
after you call fin(), the output will not be produced.
input before ini() and output after fin() may cause ended()
filter doesn’t have any flush method. because filter doesn’t own any buffer, filter always process as much as possible.
      +---------------+  +-------+-------+  +---------------+
      | FilterSrcBase |  |  FilterBase   |  | FilterSnkBase |
      +---------------+  +---------------+  +---------------+
      |     ini()     |  |   process()   |  |     fin()     |
      |    iend()     |  |               |  |    oend()     |
      +---------------+  +---------------+  +---------------+
              +                  +                  +        
             /_\                /_\                /_\      
              |                  |                  |        
              +                  +                  +        
              |\                /|\                /|        
              | +-----+  +-----+ | +-----+  +-----+ |        
              |        \/        |        \/        |        
              |        /\        |        /\        |        
              | +-----+  +-----+ + +-----+  +-----+ +        
              |/                \|/                \|        
              +                  +                  +        
              |                  |                  |        
      +-------+-------+  +-------+-------+  +---------------+
      |   FilterSrc   |  |    Filter     |  |   FilterSnk   |
      +---------------+  +---------------+  +---------------+
      |process -> get |  |               |  |process -> put |
      |     get()     |  |               |  |     put()     |
      +---------------+  +---------------+  +---------------+

For a pipe:
when you call pumping, it will try to process data as much as possible, till the end of input stream or output stream.
in blocked mode, pump will be blocked if there temporarily no data can be processed.
in non-blocked mode, pump will return if there temporarily no data can be processed.
if there is a open end of a pipeline system, this open end can behave like a filter thing, you can get a FilterSrc or a FilterSnk or a Filter object from the open end.
      +---------------+  +-------+-------+  +---------------+
      |  PipeSrcBase  |  |    PipeBase   |  |  PipeSnkBase  |
      +---------------+  +---------------+  +---------------+
      |  attachSnk()  |  |     pump()    |  |  attachSrc()  |
      |   iflush()    |  |  attachBuf()  |  |    oflush()   |
      +---------------+  +---------------+  +---------------+
              +                  +                  +        
             /_\                /_\                /_\      
              |                  |                  |        
              +                  +                  +        
              |\                /|\                /|        
              | +-----+  +-----+ | +-----+  +-----+ |        
              |        \/        |        \/        |        
              |        /\        |        /\        |        
              | +-----+  +-----+ + +-----+  +-----+ +        
              |/                \|/                \|        
              +                  +                  +        
              |                  |                  |        
      +-------+-------+  +-------+-------+  +---------------+
      |    PipeSrc    |  |      Pipe     |  |    PipeSnk    |
      +---------------+  +---------------+  +---------------+
      |  pump -> push |  |               |  |  pump -> pull |
      |     push()    |  |               |  |     pull()    |
      +---------------+  +---------------+  +---------------+

λ calculus

definition:
–λ formal-parameter. function-body
define an anonymous function

–λ formal-parameter. function-body actual-parameter
replace all the formal-parameter in the function body with the actual-parameters.

some time it is difficult to separate the function body and the actual-parameter, use (): (λ formal-parameter. function-body) (actual-parameter)

eg:
–(λf.f 3)(λx.x + 2)
–where (λf.f 3) means an anonymous function λ(f){f 3}
–so (λf.f 3)(λx.x + 2) means {(λx.x + 2) 3}
–then {(λx.x + 2) 3} means (3 + 2)

–[λf g.(f (g 3))](λx.x + 2)
–where [λf g.(f (g 3))] means an anonymous function λ(f,g){f[g(3)]}
–so [λf g.(f (g 3))](λx.x + 2) means λg.{(λx.x + 2) (g 3)}
–then λg.{(λx.x + 2) (g 3)} means λg.(g(3) + 2)

(λx.x x)(λx.x x) means: use the later (λx.x x) to substitute the (x x) in the former (λx.x x), you get (λx.x x) (λx.x x) again.

(λx.x x x)(λx.x x x) means: use the later (λx.x x x) to substitute the (x x x) in the former (λx.x x x), you get (λx.x x x)(λx.x x x)(λx.x x x), next time you will get (λx.x x x)(λx.x x x)(λx.x x x)(λx.x x x)(λx.x x x)(λx.x x x)…

note: (λx y.x y) (λy.F y) means (λy.(λy.F y)y) <==> (λy.(λz.F z)y) <==> (λy.F y). The scope of formal parameter is local.

Fixed point combinator:

A fixed point combinator (or fixed-point operator) is a higher-order function which computes a fixed point of other functions.

e.g. Suppose “fix” is a fixed point combinator which fix(g) is a fixed point of function g, thus g(fix(g)) = fix(g).

One well-known (and perhaps the simplest) fixed point combinator in the untyped lambda calculus is called the Y combinator. It was discovered by Haskell B. Curry, and is defined as:

Y = λf.(λx.f(x x))(λx.f(x x))

Note that the Y combinator is intended for the call-by-name evaluation strategy, since (Y g) diverges (for any g) in call-by-value settings.

Obviously: Y g = (λx.g(x x))(λx.g(x x)) = g((λx.g(x x)(λx.g(x x)) = g(Y g)
Thus Y g = g(Y g) = g(g(Y g)) = g(g(g(Y g))) …

Factorial function n!, we would simply call g(Y g) n
Where g := λf n. (1, if n = 0; and n·f(n-1), if n > 0).
So g(Y g) = λn. (1, if n = 0; and n·((Y g)(n-1)), if n > 0)
and g(Y g)n = (1, if n = 0; and n·((Y g)(n-1)), if n > 0)
for n = 5:
g(Y g)5 = 5·((Y g)(5-1)) = 5·((Y g)4) = 5·(g(Y g)4) = 5·4·((Y g)3) = 5·4·(g(Y g)3)= … = 5·4·3·2·1

Every recursively defined function can be seen as a fixed point of some other suitable function, and therefore, using Y, every recursively defined function can be expressed as a lambda expression.

A quick sort λ expression:
suppose we have sizeof and pl and pg function
sizeof(array) returns the size of the array.
pl(array) and pg(array) makes a complete partition of the array, where each element in pl(array) is less than each element in pg(array).

q := λs a. a, if sizeof(a)<=1; and s(pl(a)) s(pg(a)), if sizeof(a)>1

q(Y q)
= λa.a, if sizeof(a)<=1; and (Y q)(pl(a)) (Y q)(pg(a))
= λa.a, if sizeof(a)<=1; and (q(Y q))(pl(a)) (q(Y q))(pg(a))

q(Y q)a
= a, if sizeof(a)<=1; and (q(Y q))(pl(a)) (q(Y q))(pg(a))

q(Y q)a is the λ expression of the quick sort function.

Because that Y can calculate the fixed point of any function g, so any recursive function can be represented as per replacing the recursion point with g(Y g):

h(x) := (F(h))(x)
F is some high order function, F(fun) returns a function composed with fun, here we use it to represent the recursive form of function h. This is not a λ expression, because there is an explicit recursion.

let g := λH x.(F(H))(x) then
g(Y g) = λx.(F(Y g))(x) = λx.(F(g(Y g)))(x) ..now this is a valid λ expression.

so
h := g(Y g)
= (λH x.(F(H))(x))(Y (λH x.(F(H))(x)))
= (λH x.(F(H))(x))((λf.(λx.f(x x))(λx.f(x x)))(λH x.(F(H))(x)))
is the λ expression definition for function h

ref:
http://en.wikipedia.org/wiki/Fixed_point_combinator
http://en.wikipedia.org/wiki/Lambda_calculus

Finding all paths from source to destination

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
AllPathsFromSourceToDestination(s, d) {
    push s into path vector
    InCurrentPathTags[s] = true
    for each vertex v adjacent to s {
        if(v == d) {
            Output the path vector;
        } else {
            if(InCurrentPathTags[v] == false) {
                AllPathsFromSourceToDestination(v, d)
            }
        }
    }
    pop s from path vector
    InCurrentPathTags[s] = false
}

List of Sorting Networks

What is Sorting Network? -> http://en.wikipedia.org/wiki/Sorting_network

From: http://pages.ripco.net/~jgamble/nw.html
Input the number n (maximum 32)
Algorithm choices: “Best”
Click [Take a look] button.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
n: comparators, parallels
1: 0, 0

2: 1, 1
[[0,1]]

3: 3, 3
[[1,2]]
[[0,2]]
[[0,1]]

4: 5, 3
[[0,1],[2,3]]
[[0,2],[1,3]]
[[1,2]]

5: 9, 6
[[0,1],[3,4]]
[[2,4]]
[[2,3],[1,4]]
[[0,3]]
[[0,2],[1,3]]
[[1,2]]

6: 12, 6
[[1,2],[4,5]]
[[0,2],[3,5]]
[[0,1],[3,4],[2,5]]
[[0,3],[1,4]]
[[2,4],[1,3]]
[[2,3]]

7: 16, 7
[[1,2],[3,4],[5,6]]
[[0,2],[3,5],[4,6]]
[[0,1],[4,5],[2,6]]
[[0,4],[1,5]]
[[0,3],[2,5]]
[[1,3],[2,4]]
[[2,3]]

8: 19, 7
[[0,1],[2,3],[4,5],[6,7]]
[[0,2],[1,3],[4,6],[5,7]]
[[1,2],[5,6],[0,4],[3,7]]
[[1,5],[2,6]]
[[1,4],[3,6]]
[[2,4],[3,5]]
[[3,4]]

9: 25, 9
[[0,1],[3,4],[6,7]]
[[1,2],[4,5],[7,8]]
[[0,1],[3,4],[6,7],[2,5]]
[[0,3],[1,4],[5,8]]
[[3,6],[4,7],[2,5]]
[[0,3],[1,4],[5,7],[2,6]]
[[1,3],[4,6]]
[[2,4],[5,6]]
[[2,3]]

10: 29, 9
[[4,9],[3,8],[2,7],[1,6],[0,5]]
[[1,4],[6,9],[0,3],[5,8]]
[[0,2],[3,6],[7,9]]
[[0,1],[2,4],[5,7],[8,9]]
[[1,2],[4,6],[7,8],[3,5]]
[[2,5],[6,8],[1,3],[4,7]]
[[2,3],[6,7]]
[[3,4],[5,6]]
[[4,5]]

11: 35, 9
[[0,1],[2,3],[4,5],[6,7],[8,9]]
[[1,3],[5,7],[0,2],[4,6],[8,10]]
[[1,2],[5,6],[9,10],[0,4],[3,7]]
[[1,5],[6,10],[4,8]]
[[5,9],[2,6],[0,4],[3,8]]
[[1,5],[6,10],[2,3],[8,9]]
[[1,4],[7,10],[3,5],[6,8]]
[[2,4],[7,9],[5,6]]
[[3,4],[7,8]]

12: 39, 9
[[0,1],[2,3],[4,5],[6,7],[8,9],[10,11]]
[[1,3],[5,7],[9,11],[0,2],[4,6],[8,10]]
[[1,2],[5,6],[9,10],[0,4],[7,11]]
[[1,5],[6,10],[3,7],[4,8]]
[[5,9],[2,6],[0,4],[7,11],[3,8]]
[[1,5],[6,10],[2,3],[8,9]]
[[1,4],[7,10],[3,5],[6,8]]
[[2,4],[7,9],[5,6]]
[[3,4],[7,8]]

13: 45, 10
[[1,7],[9,11],[3,4],[5,8],[0,12],[2,6]]
[[0,1],[2,3],[4,6],[8,11],[7,12],[5,9]]
[[0,2],[3,7],[10,11],[1,4],[6,12]]
[[7,8],[11,12],[4,9],[6,10]]
[[3,4],[5,6],[8,9],[10,11],[1,7]]
[[2,6],[9,11],[1,3],[4,7],[8,10],[0,5]]
[[2,5],[6,8],[9,10]]
[[1,2],[3,5],[7,8],[4,6]]
[[2,3],[4,5],[6,7],[8,9]]
[[3,4],[5,6]]

14: 51, 10
[[0,1],[2,3],[4,5],[6,7],[8,9],[10,11],[12,13]]
[[0,2],[4,6],[8,10],[1,3],[5,7],[9,11]]
[[0,4],[8,12],[1,5],[9,13],[2,6],[3,7]]
[[0,8],[1,9],[2,10],[3,11],[4,12],[5,13]]
[[5,10],[6,9],[3,12],[7,11],[1,2],[4,8]]
[[1,4],[7,13],[2,8],[5,6],[9,10]]
[[2,4],[11,13],[3,8],[7,12]]
[[6,8],[10,12],[3,5],[7,9]]
[[3,4],[5,6],[7,8],[9,10],[11,12]]
[[6,7],[8,9]]

15: 56, 10
[[0,1],[2,3],[4,5],[6,7],[8,9],[10,11],[12,13]]
[[0,2],[4,6],[8,10],[12,14],[1,3],[5,7],[9,11]]
[[0,4],[8,12],[1,5],[9,13],[2,6],[10,14],[3,7]]
[[0,8],[1,9],[2,10],[3,11],[4,12],[5,13],[6,14]]
[[5,10],[6,9],[3,12],[13,14],[7,11],[1,2],[4,8]]
[[1,4],[7,13],[2,8],[11,14],[5,6],[9,10]]
[[2,4],[11,13],[3,8],[7,12]]
[[6,8],[10,12],[3,5],[7,9]]
[[3,4],[5,6],[7,8],[9,10],[11,12]]
[[6,7],[8,9]]

16: 60, 10
[[0,1],[2,3],[4,5],[6,7],[8,9],[10,11],[12,13],[14,15]]
[[0,2],[4,6],[8,10],[12,14],[1,3],[5,7],[9,11],[13,15]]
[[0,4],[8,12],[1,5],[9,13],[2,6],[10,14],[3,7],[11,15]]
[[0,8],[1,9],[2,10],[3,11],[4,12],[5,13],[6,14],[7,15]]
[[5,10],[6,9],[3,12],[13,14],[7,11],[1,2],[4,8]]
[[1,4],[7,13],[2,8],[11,14],[5,6],[9,10]]
[[2,4],[11,13],[3,8],[7,12]]
[[6,8],[10,12],[3,5],[7,9]]
[[3,4],[5,6],[7,8],[9,10],[11,12]]
[[6,7],[8,9]]

17: 81, 20
[[0,1],[2,3],[4,5],[6,7],[8,9],[10,11],[12,13],[15,16]]
[[0,2],[1,3],[4,6],[5,7],[8,10],[9,11],[14,16]]
[[1,2],[5,6],[0,4],[3,7],[9,10],[14,15],[13,16]]
[[1,5],[2,6],[12,15],[11,16]]
[[1,4],[3,6],[12,14],[13,15],[7,16]]
[[2,4],[3,5],[13,14],[10,15]]
[[3,4],[8,13],[9,14],[11,15]]
[[8,12],[9,13],[11,14],[6,15]]
[[9,12],[10,13],[5,14],[7,15]]
[[10,12],[11,13],[0,9],[7,14]]
[[11,12],[0,8],[1,10],[4,13]]
[[1,9],[2,11],[3,12],[5,13]]
[[1,8],[3,11],[2,9],[6,13]]
[[2,8],[3,10],[7,13],[6,11]]
[[3,9],[5,10],[7,12]]
[[3,8],[4,9],[7,11]]
[[4,8],[5,9],[7,10]]
[[5,8],[6,9]]
[[6,8],[7,9]]
[[7,8]]

18: 90, 20
[[0,1],[2,3],[4,5],[7,8],[9,10],[11,12],[13,14],[16,17]]
[[0,2],[1,3],[6,8],[9,11],[10,12],[15,17]]
[[1,2],[6,7],[5,8],[10,11],[15,16],[14,17]]
[[4,7],[3,8],[13,16],[12,17]]
[[4,6],[5,7],[13,15],[14,16],[8,17]]
[[5,6],[2,7],[14,15],[11,16]]
[[0,5],[1,6],[3,7],[9,14],[10,15],[12,16]]
[[0,4],[1,5],[3,6],[9,13],[10,14],[12,15],[7,16]]
[[1,4],[2,5],[10,13],[11,14],[0,9],[6,15],[8,16]]
[[2,4],[3,5],[11,13],[12,14],[1,10],[7,15]]
[[3,4],[12,13],[1,9],[2,11],[5,14],[8,15]]
[[3,12],[2,9],[4,13],[7,14]]
[[3,11],[5,13],[8,14]]
[[3,10],[6,13]]
[[3,9],[7,13],[5,10],[6,11]]
[[8,13],[4,9],[7,12]]
[[5,9],[8,12],[7,11]]
[[8,11],[6,9],[7,10]]
[[8,10],[7,9]]
[[8,9]]

19: 100, 21
[[0,1],[2,3],[4,5],[7,8],[9,10],[12,13],[14,15],[17,18]]
[[0,2],[1,3],[6,8],[11,13],[16,18]]
[[1,2],[6,7],[5,8],[11,12],[10,13],[16,17],[15,18]]
[[4,7],[3,8],[9,12],[14,17],[13,18]]
[[4,6],[5,7],[9,11],[10,12],[14,16],[15,17],[8,18]]
[[5,6],[2,7],[10,11],[15,16],[9,14],[12,17]]
[[0,5],[1,6],[3,7],[10,15],[11,16],[13,17]]
[[0,4],[1,5],[3,6],[10,14],[12,16],[7,17]]
[[1,4],[2,5],[13,16],[11,14],[12,15],[0,10],[8,17]]
[[2,4],[3,5],[13,15],[12,14],[0,9],[1,11],[6,16]]
[[3,4],[13,14],[1,10],[2,12],[5,15],[7,16]]
[[1,9],[3,13],[2,10],[4,14],[8,16],[7,15]]
[[3,12],[2,9],[5,14],[8,15]]
[[3,11],[6,14]]
[[3,10],[7,14],[6,11]]
[[3,9],[8,14],[5,10],[7,12]]
[[4,9],[8,13],[7,11]]
[[5,9],[8,12],[7,10]]
[[8,11],[6,9]]
[[8,10],[7,9]]
[[8,9]]

20: 106, 21
[[0,1],[3,4],[5,6],[8,9],[10,11],[13,14],[15,16],[18,19]]
[[2,4],[7,9],[12,14],[17,19]]
[[2,3],[1,4],[7,8],[6,9],[12,13],[11,14],[17,18],[16,19]]
[[0,3],[5,8],[4,9],[10,13],[15,18],[14,19]]
[[0,2],[1,3],[5,7],[6,8],[10,12],[11,13],[15,17],[16,18],[9,19]]
[[1,2],[6,7],[0,5],[3,8],[11,12],[16,17],[10,15],[13,18]]
[[1,6],[2,7],[4,8],[11,16],[12,17],[14,18],[0,10]]
[[1,5],[3,7],[11,15],[13,17],[8,18]]
[[4,7],[2,5],[3,6],[14,17],[12,15],[13,16],[1,11],[9,18]]
[[4,6],[3,5],[14,16],[13,15],[1,10],[2,12],[7,17]]
[[4,5],[14,15],[3,13],[2,10],[6,16],[8,17]]
[[4,14],[3,12],[5,15],[9,17],[8,16]]
[[4,13],[3,11],[6,15],[9,16]]
[[4,12],[3,10],[7,15]]
[[4,11],[8,15],[7,12]]
[[4,10],[9,15],[6,11],[8,13]]
[[5,10],[9,14],[8,12]]
[[6,10],[9,13],[8,11]]
[[9,12],[7,10]]
[[9,11],[8,10]]
[[9,10]]

21: 118, 23
[[0,1],[3,4],[5,6],[8,9],[10,11],[13,14],[16,17],[19,20]]
[[2,4],[7,9],[12,14],[15,17],[18,20]]
[[2,3],[1,4],[7,8],[6,9],[12,13],[11,14],[15,16],[18,19],[17,20]]
[[0,3],[5,8],[4,9],[10,13],[15,18],[16,19],[14,20]]
[[0,2],[1,3],[5,7],[6,8],[10,12],[11,13],[17,19],[16,18],[9,20]]
[[1,2],[6,7],[0,5],[3,8],[11,12],[17,18],[10,16],[13,19]]
[[1,6],[2,7],[4,8],[10,15],[11,17],[12,18],[14,19]]
[[1,5],[3,7],[11,16],[13,18],[8,19]]
[[4,7],[2,5],[3,6],[11,15],[14,18],[13,16],[9,19]]
[[4,6],[3,5],[12,15],[14,17],[0,11],[7,18]]
[[4,5],[14,16],[13,15],[0,10],[1,12],[6,17],[8,18]]
[[14,15],[1,11],[2,13],[5,16],[9,18],[8,17]]
[[1,10],[3,14],[4,15],[6,16],[9,17]]
[[4,14],[3,13],[2,10],[7,16]]
[[4,13],[3,11],[8,16]]
[[4,12],[3,10],[9,16],[7,13],[8,14]]
[[4,11],[6,12],[9,15],[8,13]]
[[4,10],[5,11],[9,14]]
[[5,10],[6,11],[9,13]]
[[6,10],[8,11],[9,12]]
[[7,10],[9,11]]
[[8,10]]
[[9,10]]

22: 125, 23
[[0,1],[3,4],[6,7],[9,10],[11,12],[14,15],[17,18],[20,21]]
[[2,4],[5,7],[8,10],[13,15],[16,18],[19,21]]
[[2,3],[1,4],[5,6],[8,9],[7,10],[13,14],[12,15],[16,17],[19,20],[18,21]]
[[0,3],[5,8],[6,9],[4,10],[11,14],[16,19],[17,20],[15,21]]
[[0,2],[1,3],[7,9],[6,8],[11,13],[12,14],[18,20],[17,19],[10,21]]
[[1,2],[7,8],[0,6],[3,9],[12,13],[18,19],[11,17],[14,20]]
[[0,5],[1,7],[2,8],[4,9],[11,16],[12,18],[13,19],[15,20]]
[[1,6],[3,8],[12,17],[14,19],[0,11],[9,20]]
[[1,5],[4,8],[3,6],[12,16],[15,19],[14,17],[10,20]]
[[2,5],[4,7],[13,16],[15,18],[1,12],[8,19]]
[[4,6],[3,5],[15,17],[14,16],[1,11],[2,13],[7,18],[9,19]]
[[4,5],[15,16],[3,14],[2,11],[6,17],[10,19]]
[[4,15],[3,13],[5,16],[7,17],[10,18]]
[[4,14],[3,12],[6,16],[9,17]]
[[4,13],[3,11],[7,16],[10,17]]
[[4,12],[8,16],[7,13]]
[[4,11],[9,16],[6,12],[8,14]]
[[10,16],[5,11],[7,12],[9,15]]
[[6,11],[10,15],[9,14]]
[[7,11],[10,14],[9,12]]
[[8,11],[10,13]]
[[10,12],[9,11]]
[[10,11]]

23: 133, 24
[[0,1],[3,4],[6,7],[9,10],[12,13],[15,16],[18,19],[21,22]]
[[2,4],[5,7],[8,10],[11,13],[14,16],[17,19],[20,22]]
[[2,3],[1,4],[5,6],[8,9],[7,10],[11,12],[14,15],[13,16],[17,18],[20,21],[19,22]]
[[0,3],[5,8],[6,9],[4,10],[11,14],[12,15],[17,20],[18,21],[16,22]]
[[0,2],[1,3],[7,9],[6,8],[13,15],[12,14],[19,21],[18,20],[11,17],[10,22]]
[[1,2],[7,8],[0,6],[3,9],[13,14],[19,20],[12,18],[15,21]]
[[0,5],[1,7],[2,8],[4,9],[13,19],[12,17],[14,20],[16,21]]
[[1,6],[3,8],[13,18],[15,20],[0,12],[9,21]]
[[1,5],[4,8],[3,6],[13,17],[16,20],[15,18],[0,11],[10,21]]
[[2,5],[4,7],[14,17],[16,19],[1,13],[8,20]]
[[4,6],[3,5],[16,18],[15,17],[1,12],[2,14],[7,19],[9,20]]
[[4,5],[16,17],[1,11],[3,15],[6,18],[10,20]]
[[4,16],[3,14],[2,11],[5,17],[7,18],[10,19]]
[[4,15],[3,12],[6,17],[9,18]]
[[4,14],[3,11],[7,17],[10,18]]
[[4,13],[8,17]]
[[4,12],[9,17],[7,13],[8,14]]
[[4,11],[10,17],[6,12],[9,15]]
[[5,11],[7,12],[10,16],[9,14]]
[[6,11],[10,15],[9,12]]
[[7,11],[10,14]]
[[8,11],[10,13]]
[[10,12],[9,11]]
[[10,11]]

24: 138, 24
[[1,2],[4,5],[7,8],[10,11],[13,14],[16,17],[19,20],[22,23]]
[[0,2],[3,5],[6,8],[9,11],[12,14],[15,17],[18,20],[21,23]]
[[0,1],[3,4],[2,5],[6,7],[9,10],[8,11],[12,13],[15,16],[14,17],[18,19],[21,22],[20,23]]
[[0,3],[1,4],[6,9],[7,10],[5,11],[12,15],[13,16],[18,21],[19,22],[17,23]]
[[2,4],[1,3],[8,10],[7,9],[0,6],[14,16],[13,15],[20,22],[19,21],[12,18],[11,23]]
[[2,3],[8,9],[1,7],[4,10],[14,15],[20,21],[13,19],[16,22],[0,12]]
[[2,8],[1,6],[3,9],[5,10],[14,20],[13,18],[15,21],[17,22]]
[[2,7],[4,9],[14,19],[16,21],[1,13],[10,22]]
[[2,6],[5,9],[4,7],[14,18],[17,21],[16,19],[1,12],[11,22]]
[[3,6],[5,8],[15,18],[17,20],[2,14],[9,21]]
[[5,7],[4,6],[17,19],[16,18],[2,13],[3,15],[8,20],[10,21]]
[[5,6],[17,18],[2,12],[4,16],[7,19],[11,21]]
[[5,17],[4,15],[3,12],[6,18],[8,19],[11,20]]
[[5,16],[4,13],[7,18],[10,19]]
[[5,15],[4,12],[8,18],[11,19]]
[[5,14],[9,18]]
[[5,13],[10,18],[8,14],[9,15]]
[[5,12],[11,18],[7,13],[10,16]]
[[6,12],[8,13],[11,17],[10,15]]
[[7,12],[11,16],[10,13]]
[[8,12],[11,15]]
[[9,12],[11,14]]
[[11,13],[10,12]]
[[11,12]]

25: 154, 27
[[1,2],[4,5],[7,8],[10,11],[13,14],[16,17],[19,20],[21,22],[23,24]]
[[0,2],[3,5],[6,8],[9,11],[12,14],[15,17],[18,20],[21,23],[22,24]]
[[0,1],[3,4],[2,5],[6,7],[9,10],[8,11],[12,13],[15,16],[14,17],[18,19],[22,23],[20,24]]
[[0,3],[1,4],[6,9],[7,10],[5,11],[12,15],[13,16],[18,22],[19,23],[17,24]]
[[2,4],[1,3],[8,10],[7,9],[0,6],[14,16],[13,15],[18,21],[20,23],[11,24]]
[[2,3],[8,9],[1,7],[4,10],[14,15],[19,21],[20,22],[16,23]]
[[2,8],[1,6],[3,9],[5,10],[20,21],[12,19],[15,22],[17,23]]
[[2,7],[4,9],[12,18],[13,20],[14,21],[16,22],[10,23]]
[[2,6],[5,9],[4,7],[14,20],[13,18],[17,22],[11,23]]
[[3,6],[5,8],[14,19],[16,20],[17,21],[0,13],[9,22]]
[[5,7],[4,6],[14,18],[15,19],[17,20],[0,12],[8,21],[10,22]]
[[5,6],[15,18],[17,19],[1,14],[7,20],[11,22]]
[[16,18],[2,15],[1,12],[6,19],[8,20],[11,21]]
[[17,18],[2,14],[3,16],[7,19],[10,20]]
[[2,13],[4,17],[5,18],[8,19],[11,20]]
[[2,12],[5,17],[4,16],[3,13],[9,19]]
[[5,16],[3,12],[4,14],[10,19]]
[[5,15],[4,12],[11,19],[9,16],[10,17]]
[[5,14],[8,15],[11,18],[10,16]]
[[5,13],[7,14],[11,17]]
[[5,12],[6,13],[8,14],[11,16]]
[[6,12],[8,13],[10,14],[11,15]]
[[7,12],[9,13],[11,14]]
[[8,12],[11,13]]
[[9,12]]
[[10,12]]
[[11,12]]

26: 163, 27
[[1,2],[4,5],[7,8],[9,10],[11,12],[14,15],[17,18],[20,21],[22,23],[24,25]]
[[0,2],[3,5],[6,8],[9,11],[10,12],[13,15],[16,18],[19,21],[22,24],[23,25]]
[[0,1],[3,4],[2,5],[6,7],[10,11],[8,12],[13,14],[16,17],[15,18],[19,20],[23,24],[21,25]]
[[0,3],[1,4],[6,10],[7,11],[5,12],[13,16],[14,17],[19,23],[20,24],[18,25]]
[[2,4],[1,3],[6,9],[8,11],[15,17],[14,16],[19,22],[21,24],[12,25]]
[[2,3],[7,9],[8,10],[4,11],[15,16],[20,22],[21,23],[17,24]]
[[8,9],[0,7],[3,10],[5,11],[21,22],[13,20],[16,23],[18,24]]
[[0,6],[1,8],[2,9],[4,10],[13,19],[14,21],[15,22],[17,23],[11,24]]
[[2,8],[1,6],[5,10],[15,21],[14,19],[18,23],[0,13],[12,24]]
[[2,7],[4,8],[5,9],[15,20],[17,21],[18,22],[1,14],[10,23]]
[[2,6],[3,7],[5,8],[15,19],[16,20],[18,21],[1,13],[9,22],[12,23]]
[[3,6],[5,7],[16,19],[18,20],[2,15],[8,21],[10,22]]
[[4,6],[17,19],[2,14],[3,16],[7,20],[11,22]]
[[5,6],[18,19],[2,13],[4,17],[8,20],[12,22],[11,21]]
[[5,18],[4,16],[3,13],[6,19],[10,20],[12,21]]
[[5,17],[4,14],[7,19],[12,20]]
[[5,16],[4,13],[8,19]]
[[5,15],[9,19]]
[[5,14],[10,19],[8,15],[9,16]]
[[5,13],[11,19],[7,14],[10,17]]
[[12,19],[6,13],[8,14],[10,16],[11,18]]
[[7,13],[12,18],[11,16],[10,14]]
[[8,13],[12,17],[11,15]]
[[12,16],[9,13]]
[[10,13],[12,15]]
[[11,13],[12,14]]
[[12,13]]

27: 173, 28
[[1,2],[4,5],[7,8],[9,10],[11,12],[14,15],[16,17],[18,19],[21,22],[23,24],[25,26]]
[[0,2],[3,5],[6,8],[9,11],[10,12],[13,15],[16,18],[17,19],[20,22],[23,25],[24,26]]
[[0,1],[3,4],[2,5],[6,7],[10,11],[8,12],[13,14],[17,18],[15,19],[20,21],[24,25],[22,26]]
[[0,3],[1,4],[6,10],[7,11],[5,12],[13,17],[14,18],[20,24],[21,25],[19,26]]
[[2,4],[1,3],[6,9],[8,11],[13,16],[15,18],[20,23],[22,25],[12,26]]
[[2,3],[7,9],[8,10],[4,11],[14,16],[15,17],[21,23],[22,24],[13,20],[18,25]]
[[8,9],[0,7],[3,10],[5,11],[15,16],[22,23],[14,21],[17,24],[19,25]]
[[0,6],[1,8],[2,9],[4,10],[15,22],[14,20],[16,23],[19,24],[11,25]]
[[2,8],[1,6],[5,10],[15,21],[17,23],[0,14],[12,25]]
[[2,7],[4,8],[5,9],[15,20],[18,23],[17,21],[0,13],[10,24]]
[[2,6],[3,7],[5,8],[19,23],[16,20],[18,22],[1,15],[12,24]]
[[3,6],[5,7],[17,20],[19,22],[2,16],[1,13],[9,23]]
[[4,6],[18,20],[19,21],[2,15],[3,17],[8,22],[10,23]]
[[5,6],[19,20],[2,14],[4,18],[7,21],[11,23]]
[[2,13],[5,19],[4,17],[3,14],[6,20],[8,21],[12,23],[11,22]]
[[5,18],[3,13],[4,15],[7,20],[10,21],[12,22]]
[[5,17],[4,13],[8,20],[12,21]]
[[5,16],[9,20]]
[[5,15],[10,20],[9,16]]
[[5,14],[11,20],[8,15],[10,17]]
[[5,13],[12,20],[7,14],[10,16],[11,18]]
[[6,13],[8,14],[12,19],[11,16]]
[[7,13],[12,18],[10,14],[11,15]]
[[8,13],[12,17]]
[[12,16],[9,13]]
[[10,13],[12,15]]
[[11,13],[12,14]]
[[12,13]]

28: 179, 28
[[1,2],[3,4],[5,6],[8,9],[10,11],[12,13],[15,16],[17,18],[19,20],[22,23],[24,25],[26,27]]
[[0,2],[3,5],[4,6],[7,9],[10,12],[11,13],[14,16],[17,19],[18,20],[21,23],[24,26],[25,27]]
[[0,1],[4,5],[2,6],[7,8],[11,12],[9,13],[14,15],[18,19],[16,20],[21,22],[25,26],[23,27]]
[[0,4],[1,5],[7,11],[8,12],[6,13],[14,18],[15,19],[21,25],[22,26],[20,27]]
[[0,3],[2,5],[7,10],[9,12],[14,17],[16,19],[21,24],[23,26],[13,27]]
[[1,3],[2,4],[8,10],[9,11],[0,7],[5,12],[15,17],[16,18],[22,24],[23,25],[14,21],[19,26]]
[[2,3],[9,10],[1,8],[4,11],[6,12],[16,17],[23,24],[15,22],[18,25],[20,26],[0,14]]
[[2,9],[1,7],[3,10],[6,11],[16,23],[15,21],[17,24],[20,25],[12,26]]
[[2,8],[4,10],[16,22],[18,24],[1,15],[11,25],[13,26]]
[[2,7],[5,10],[4,8],[16,21],[19,24],[18,22],[1,14],[13,25]]
[[6,10],[3,7],[5,9],[20,24],[17,21],[19,23],[2,16]]
[[4,7],[6,9],[18,21],[20,23],[2,15],[3,17],[10,24]]
[[5,7],[6,8],[19,21],[20,22],[2,14],[4,18],[9,23],[11,24]]
[[6,7],[20,21],[4,17],[5,19],[3,14],[8,22],[12,24]]
[[6,20],[5,17],[4,15],[7,21],[9,22],[13,24],[12,23]]
[[6,19],[4,14],[5,16],[8,21],[11,22],[13,23]]
[[6,18],[5,14],[9,21],[13,22]]
[[6,17],[10,21]]
[[6,16],[11,21],[10,17]]
[[6,15],[12,21],[9,16],[11,18]]
[[6,14],[13,21],[8,15],[11,17],[12,19]]
[[7,14],[9,15],[13,20],[12,17]]
[[8,14],[13,19],[11,15],[12,16]]
[[9,14],[13,18]]
[[13,17],[10,14]]
[[11,14],[13,16]]
[[12,14],[13,15]]
[[13,14]]

29: 191, 30
[[1,2],[3,4],[5,6],[8,9],[10,11],[12,13],[15,16],[17,18],[19,20],[21,22],[23,24],[25,26],[27,28]]
[[0,2],[3,5],[4,6],[7,9],[10,12],[11,13],[14,16],[17,19],[18,20],[21,23],[22,24],[25,27],[26,28]]
[[0,1],[4,5],[2,6],[7,8],[11,12],[9,13],[14,15],[18,19],[16,20],[22,23],[26,27],[21,25],[24,28]]
[[0,4],[1,5],[7,11],[8,12],[6,13],[14,18],[15,19],[22,26],[23,27],[20,28]]
[[0,3],[2,5],[7,10],[9,12],[14,17],[16,19],[22,25],[24,27],[13,28]]
[[1,3],[2,4],[8,10],[9,11],[0,7],[5,12],[15,17],[16,18],[23,25],[24,26],[14,22],[19,27]]
[[2,3],[9,10],[1,8],[4,11],[6,12],[16,17],[24,25],[14,21],[15,23],[18,26],[20,27]]
[[2,9],[1,7],[3,10],[6,11],[16,24],[15,21],[17,25],[20,26],[12,27]]
[[2,8],[4,10],[16,23],[18,25],[0,15],[11,26],[13,27]]
[[2,7],[5,10],[4,8],[16,22],[19,25],[0,14],[13,26]]
[[6,10],[3,7],[5,9],[16,21],[20,25],[18,22],[19,23]]
[[4,7],[6,9],[17,21],[20,24],[1,16],[10,25]]
[[5,7],[6,8],[18,21],[20,23],[2,17],[1,14],[9,24],[11,25]]
[[6,7],[19,21],[20,22],[2,16],[3,18],[8,23],[12,25]]
[[20,21],[2,15],[4,19],[7,22],[9,23],[13,25],[12,24]]
[[2,14],[4,18],[5,20],[6,21],[8,22],[11,23],[13,24]]
[[6,20],[5,18],[3,14],[4,15],[9,22],[13,23]]
[[6,19],[4,14],[5,16],[10,22]]
[[6,18],[5,14],[11,22]]
[[6,17],[12,22],[10,18],[11,19]]
[[6,16],[13,22],[9,17],[11,18],[12,20]]
[[6,15],[8,16],[13,21],[12,18]]
[[6,14],[7,15],[9,16],[13,20]]
[[7,14],[9,15],[13,19],[12,16]]
[[8,14],[13,18],[11,15]]
[[9,14],[13,17]]
[[10,14],[13,16]]
[[11,14],[13,15]]
[[12,14]]
[[13,14]]

30: 198, 30
[[1,2],[3,4],[5,6],[7,8],[9,10],[11,12],[13,14],[16,17],[18,19],[20,21],[22,23],[24,25],[26,27],[28,29]]
[[0,2],[3,5],[4,6],[7,9],[8,10],[11,13],[12,14],[15,17],[18,20],[19,21],[22,24],[23,25],[26,28],[27,29]]
[[0,1],[4,5],[2,6],[8,9],[12,13],[7,11],[10,14],[15,16],[19,20],[17,21],[23,24],[27,28],[22,26],[25,29]]
[[0,4],[1,5],[8,12],[9,13],[6,14],[15,19],[16,20],[23,27],[24,28],[21,29]]
[[0,3],[2,5],[8,11],[10,13],[15,18],[17,20],[23,26],[25,28],[14,29]]
[[1,3],[2,4],[9,11],[10,12],[0,8],[5,13],[16,18],[17,19],[24,26],[25,27],[15,23],[20,28]]
[[2,3],[10,11],[0,7],[1,9],[4,12],[6,13],[17,18],[25,26],[15,22],[16,24],[19,27],[21,28]]
[[2,10],[1,7],[3,11],[6,12],[17,25],[16,22],[18,26],[21,27],[0,15],[13,28]]
[[2,9],[4,11],[17,24],[19,26],[1,16],[12,27],[14,28]]
[[2,8],[5,11],[17,23],[20,26],[1,15],[14,27]]
[[2,7],[6,11],[4,8],[5,9],[17,22],[21,26],[19,23],[20,24]]
[[3,7],[6,10],[18,22],[21,25],[2,17],[11,26]]
[[4,7],[6,9],[19,22],[21,24],[2,16],[3,18],[10,25],[12,26]]
[[5,7],[6,8],[20,22],[21,23],[2,15],[4,19],[9,24],[13,26]]
[[6,7],[21,22],[4,18],[5,20],[3,15],[8,23],[10,24],[14,26]]
[[6,21],[5,18],[4,16],[7,22],[10,23],[13,24],[14,25]]
[[6,20],[4,15],[5,17],[8,22],[12,23],[14,24]]
[[6,19],[5,15],[9,22],[14,23]]
[[6,18],[10,22]]
[[6,17],[11,22],[10,18]]
[[6,16],[12,22],[9,17],[11,19]]
[[6,15],[13,22],[8,16],[10,17],[12,20]]
[[14,22],[7,15],[10,16],[12,19],[13,21]]
[[8,15],[14,21],[13,19],[12,16]]
[[9,15],[14,20],[13,17]]
[[10,15],[14,19]]
[[11,15],[14,18]]
[[12,15],[14,17]]
[[13,15],[14,16]]
[[14,15]]

31: 206, 31
[[1,2],[3,4],[5,6],[7,8],[9,10],[11,12],[13,14],[15,16],[17,18],[19,20],[21,22],[23,24],[25,26],[27,28],[29,30]]
[[0,2],[3,5],[4,6],[7,9],[8,10],[11,13],[12,14],[15,17],[16,18],[19,21],[20,22],[23,25],[24,26],[27,29],[28,30]]
[[0,1],[4,5],[2,6],[8,9],[12,13],[7,11],[10,14],[16,17],[20,21],[15,19],[18,22],[24,25],[28,29],[23,27],[26,30]]
[[0,4],[1,5],[8,12],[9,13],[6,14],[16,20],[17,21],[24,28],[25,29],[15,23],[22,30]]
[[0,3],[2,5],[8,11],[10,13],[16,19],[18,21],[24,27],[26,29],[14,30]]
[[1,3],[2,4],[9,11],[10,12],[0,8],[5,13],[17,19],[18,20],[25,27],[26,28],[16,24],[21,29]]
[[2,3],[10,11],[0,7],[1,9],[4,12],[6,13],[18,19],[26,27],[16,23],[17,25],[20,28],[22,29]]
[[2,10],[1,7],[3,11],[6,12],[18,26],[17,23],[19,27],[22,28],[0,16],[13,29]]
[[2,9],[4,11],[18,25],[20,27],[0,15],[1,17],[12,28],[14,29]]
[[2,8],[5,11],[18,24],[21,27],[1,15],[14,28]]
[[2,7],[6,11],[4,8],[5,9],[18,23],[22,27],[20,24],[21,25]]
[[3,7],[6,10],[19,23],[22,26],[2,18],[11,27]]
[[4,7],[6,9],[20,23],[22,25],[2,17],[3,19],[10,26],[12,27]]
[[5,7],[6,8],[21,23],[22,24],[2,16],[4,20],[9,25],[13,27]]
[[6,7],[22,23],[2,15],[4,19],[5,21],[8,24],[10,25],[14,27]]
[[6,22],[5,19],[3,15],[4,16],[7,23],[10,24],[13,25],[14,26]]
[[6,21],[4,15],[5,17],[8,23],[12,24],[14,25]]
[[6,20],[5,15],[9,23],[14,24]]
[[6,19],[10,23]]
[[6,18],[11,23]]
[[6,17],[12,23],[10,18],[11,19]]
[[6,16],[13,23],[9,17],[12,20]]
[[6,15],[14,23],[8,16],[10,17],[12,19],[13,21]]
[[7,15],[10,16],[14,22],[13,19]]
[[8,15],[14,21],[12,16],[13,17]]
[[9,15],[14,20]]
[[10,15],[14,19]]
[[11,15],[14,18]]
[[12,15],[14,17]]
[[13,15],[14,16]]
[[14,15]]

32: 211, 31
[[0,1],[2,3],[4,5],[6,7],[8,9],[10,11],[12,13],[14,15],[16,17],[18,19],[20,21],[22,23],[24,25],[26,27],[28,29],[30,31]]
[[0,2],[1,3],[4,6],[5,7],[8,10],[9,11],[12,14],[13,15],[16,18],[17,19],[20,22],[21,23],[24,26],[25,27],[28,30],[29,31]]
[[1,2],[5,6],[0,4],[3,7],[9,10],[13,14],[8,12],[11,15],[17,18],[21,22],[16,20],[19,23],[25,26],[29,30],[24,28],[27,31]]
[[1,5],[2,6],[9,13],[10,14],[0,8],[7,15],[17,21],[18,22],[25,29],[26,30],[16,24],[23,31]]
[[1,4],[3,6],[9,12],[11,14],[17,20],[19,22],[25,28],[27,30],[0,16],[15,31]]
[[2,4],[3,5],[10,12],[11,13],[1,9],[6,14],[18,20],[19,21],[26,28],[27,29],[17,25],[22,30]]
[[3,4],[11,12],[1,8],[2,10],[5,13],[7,14],[19,20],[27,28],[17,24],[18,26],[21,29],[23,30]]
[[3,11],[2,8],[4,12],[7,13],[19,27],[18,24],[20,28],[23,29],[1,17],[14,30]]
[[3,10],[5,12],[19,26],[21,28],[1,16],[2,18],[13,29],[15,30]]
[[3,9],[6,12],[19,25],[22,28],[2,16],[15,29]]
[[3,8],[7,12],[5,9],[6,10],[19,24],[23,28],[21,25],[22,26]]
[[4,8],[7,11],[20,24],[23,27],[3,19],[12,28]]
[[5,8],[7,10],[21,24],[23,26],[3,18],[4,20],[11,27],[13,28]]
[[6,8],[7,9],[22,24],[23,25],[3,17],[5,21],[10,26],[14,28]]
[[7,8],[23,24],[3,16],[5,20],[6,22],[9,25],[11,26],[15,28]]
[[7,23],[6,20],[4,16],[5,17],[8,24],[11,25],[14,26],[15,27]]
[[7,22],[5,16],[6,18],[9,24],[13,25],[15,26]]
[[7,21],[6,16],[10,24],[15,25]]
[[7,20],[11,24]]
[[7,19],[12,24]]
[[7,18],[13,24],[11,19],[12,20]]
[[7,17],[14,24],[10,18],[13,21]]
[[7,16],[15,24],[9,17],[11,18],[13,20],[14,22]]
[[8,16],[11,17],[15,23],[14,20]]
[[9,16],[15,22],[13,17],[14,18]]
[[10,16],[15,21]]
[[11,16],[15,20]]
[[12,16],[15,19]]
[[13,16],[15,18]]
[[14,16],[15,17]]
[[15,16]]

Reinvent wheels, my quick sort implementation, just for fun

Not optimized yet.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
initial state:
 p                                                                 #
_p_                                                                #
 p_                                                               _p
 |-----------------------------------------------------------------#
 ..................................................................#


state after choosing pivot:
 p                                                                 #
 _p_                                                               #
 p_                                                               _p
 ||----------------------------------------------------------------#
 =.................................................................#


the middle state during partitioning:
 p                                                                 #
 |                       _p_                                       #
 |           p_           |                           _p           #
 |-----------|------------|----------------------------|-----------#
 <<<<<<<<<<<<=============.............................>>>>>>>>>>>>#


the final state after partition:
 p                                                                 #
 |                                                _p_              #
 |                  p_                            _p               #
 |------------------|------------------------------|---------------#
 <<<<<<<<<<<<<<<<<<<===============================>>>>>>>>>>>>>>>>#

Then, recurse.
Note: the pointer p_ will always point to a pivot element after choosing pivot step.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
template<typename Elem, typename OtherSort, size_t Threshold>
class QuickSort {
public:
    static void go(Elem p[], size_t n) {
        Elem *p_, *_p_, *_p;
        assert(typeid(OtherSort)!=typeid(QuickSort));
        do {
            // recursion exit, use other sort algorithm to process small array
            if(n < Threshold) {
                OtherSort::go(p, n);
                return;
            }

            p_ = p;
            _p_ = p;
            _p = p+n;

            // choosing pivot element
            swap(p_, pivot(p, n));
            _p_++;

            // partitioning
            while(_p_ < _p) {
                while((*p_ == *_p_) && (_p_ < _p)) ++_p_;
                while((*p_ < *_p_) && (_p_ < _p)) {
                    --_p;
                    swap(_p_, _p);
                }
                while((*_p_ < *p_) && (_p_ < _p)) {
                    swap(p_, _p_);
                    ++p_;
                    ++_p_;
                }
            }

            // recursion only for the partition with less elements
            if((p_ - p) < (n - (_p - p))) {
                go(p, p_ - p);
                n = n - (_p - p);
                p = _p;
            } else {
                go(_p, n - (_p - p));
                n = p_ - p;
            }

            // tail recursion elimination
        } while(true);
    }
private:
    static Elem *pivot(Elem p[], size_t n) {
        if(n < 10) return p + n/2;
        else return p + random(n);
        // random(n) should return a uniformly distributed random number in [0, n)
    }
};