File size: 46,964 Bytes
072246b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
"""Hand-authored project contracts and domain fixtures; no downloaded problems."""

from __future__ import annotations

from dataclasses import dataclass


@dataclass(frozen=True)
class Family:
    slug: str
    category: str
    required: tuple[str, ...]
    specification: str
    inputs: tuple[dict, ...]
    golden: object


FAMILIES: dict[str, Family] = {}


def add(slug, category, required, specification, inputs, golden):
    assert slug not in FAMILIES
    FAMILIES[slug] = Family(
        slug, category, tuple(required.split()), specification, tuple(inputs), golden
    )


add(
    "word_frequency",
    "text",
    "text",
    "Input: text (string). Tokenize maximal ASCII [a-z0-9]+ runs after lowercasing. Return [{word,count}], sorted by decreasing count then ascending word. Non-ASCII letters are separators.",
    [
        {"text": "Red blue RED! 42"},
        {"text": ""},
        {"text": "é É 中文"},
        {"text": "a_a a-b"},
        {"text": "12 012 12\nX"},
        {"text": "z a z b a b"},
    ],
    [
        {"word": "red", "count": 2},
        {"word": "42", "count": 1},
        {"word": "blue", "count": 1},
    ],
)
add(
    "slug_registry",
    "text",
    "titles",
    'Input: titles (list of strings). Lowercase each, replace maximal runs outside ASCII a-z0-9 with a hyphen, strip hyphens, use "item" if empty. Assign in input order. If already used, append -2, -3, ... to the base until globally unique. Return slugs.',
    [
        {"titles": ["Hello World", "hello world", "hello-world-2", ""]},
        {"titles": []},
        {"titles": ["!!!", "", "ITEM"]},
        {"titles": ["a", "a-2", "a", "a"]},
        {"titles": ["Ünicode", " A___B "]},
        {"titles": ["1", "1", "1-2"]},
    ],
    ["hello-world", "hello-world-2", "hello-world-2-2", "item"],
)
add(
    "run_length",
    "text",
    "text",
    "Input: text (string). Return [character,count] pairs for consecutive identical Unicode code points; retain order and include whitespace. Empty text produces [].",
    [
        {"text": "aaabbcaa"},
        {"text": ""},
        {"text": "😀😀é"},
        {"text": "  \n\n "},
        {"text": "abcd"},
        {"text": "1111000"},
    ],
    [["a", 3], ["b", 2], ["c", 1], ["a", 2]],
)
add(
    "bracket_audit",
    "text",
    "text",
    "Input: text. Audit (), [], {} ignoring all other code points. Return {balanced,position}. On first unmatched/mismatched closing bracket, position is its zero-based code-point index. If openings remain at EOF, position is the most recent unmatched opening. Balanced input has position:null.",
    [
        {"text": "a([)]"},
        {"text": ""},
        {"text": "abc"},
        {"text": "([]{})"},
        {"text": "(("},
        {"text": "é]"},
        {"text": "[(]"},
    ],
    {"balanced": False, "position": 3},
)
add(
    "text_wrap",
    "text",
    "text width",
    "Input: text and positive integer width. Split on Unicode whitespace. Greedily pack words into lines with single spaces; a next word fits iff length including separating space <= width. Never split a long word. Return lines without empty lines.",
    [
        {"text": "one two three four", "width": 7},
        {"text": "", "width": 1},
        {"text": "abcdef a", "width": 2},
        {"text": " a\t b\n c ", "width": 3},
        {"text": "éé a", "width": 2},
        {"text": "a b c", "width": 20},
    ],
    ["one two", "three", "four"],
)
add(
    "ngram_index",
    "text",
    "tokens n",
    "Input: tokens (strings), n (positive integer). Return [{tokens,positions}] for each distinct contiguous n-gram, sorted lexicographically by token sequence. Positions are ascending zero-based starting indices. n greater than length produces [].",
    [
        {"tokens": ["a", "b", "a", "b"], "n": 2},
        {"tokens": [], "n": 1},
        {"tokens": ["x"], "n": 2},
        {"tokens": ["b", "a", "b"], "n": 1},
        {"tokens": ["", "a", ""], "n": 2},
        {"tokens": ["x", "x", "x"], "n": 3},
    ],
    [
        {"tokens": ["a", "b"], "positions": [0, 2]},
        {"tokens": ["b", "a"], "positions": [1]},
    ],
)
add(
    "glob_filter",
    "text",
    "paths pattern",
    "Input: paths (strings), pattern. Return sorted unique matches using case-sensitive shell glob semantics: * matches any run including /, ? one character, [abc] a class, [!abc] a negated class. Python fnmatch.fnmatchcase semantics apply. No filesystem access.",
    [
        {"paths": ["a.py", "B.py", "a.txt", "a.py", "x/a.py"], "pattern": "*.py"},
        {"paths": [], "pattern": "*"},
        {"paths": ["a", "b", "c"], "pattern": "[!b]"},
        {"paths": ["ab", "a", "a/b"], "pattern": "a?"},
        {"paths": ["A", "a"], "pattern": "a"},
        {"paths": ["", "a"], "pattern": "*"},
    ],
    ["B.py", "a.py", "x/a.py"],
)
add(
    "edit_distance",
    "text",
    "a b",
    "Input: strings a,b of <=200 code points. Return Levenshtein distance with unit insertion, deletion and substitution costs. Compare Unicode code points, case-sensitive.",
    [
        {"a": "kitten", "b": "sitting"},
        {"a": "", "b": ""},
        {"a": "", "b": "abc"},
        {"a": "ab", "b": "ba"},
        {"a": "é", "b": "e"},
        {"a": "banana", "b": "banana"},
    ],
    3,
)
add(
    "roman_codec",
    "text",
    "number",
    "Input: integer number in 1..3999. Return canonical uppercase Roman numeral using subtractive pairs IV,IX,XL,XC,CD,CM.",
    [
        {"number": 1994},
        {"number": 1},
        {"number": 4},
        {"number": 9},
        {"number": 3999},
        {"number": 944},
        {"number": 58},
    ],
    "MCMXCIV",
)
add(
    "caesar_cipher",
    "text",
    "text shift",
    "Input: text and integer shift. Rotate only ASCII letters by shift modulo 26, preserving case. All other characters unchanged.",
    [
        {"text": "Az-z! 9", "shift": 1},
        {"text": "", "shift": 0},
        {"text": "Abc", "shift": -1},
        {"text": "é中", "shift": 13},
        {"text": "XYZ abc", "shift": 52},
        {"text": "aZ", "shift": -53},
    ],
    "Ba-a! 9",
)
add(
    "csv_records",
    "data",
    "csv",
    "Input: csv (string). Parse comma-separated CSV with double-quoted fields, doubled quote escaping and quoted newlines (Python csv.reader dialect excel). First row is unique nonempty header names. Subsequent rows have the same width. Return objects in source order. Empty document returns []. Blank data rows and malformed CSV are out of scope.",
    [
        {"csv": "name,n\na,1\nb,2\n"},
        {"csv": ""},
        {"csv": "x,y\n"},
        {"csv": 'a,b\n"hi,there","say ""yes"""\n'},
        {"csv": 'x\n"a\nb"\n'},
        {"csv": "x,y\r\na,\r\n"},
    ],
    [{"name": "a", "n": "1"}, {"name": "b", "n": "2"}],
)
add(
    "record_query",
    "data",
    "rows where select",
    "Input: rows (objects), where (object), select (list of field names). Keep rows containing every where field with an equal JSON value. Return selected fields for each in source order; missing selected fields become null. Values contain no booleans compared with numbers.",
    [
        {
            "rows": [{"a": 1, "b": "x"}, {"a": 2}, {"a": 1}],
            "where": {"a": 1},
            "select": ["b"],
        },
        {"rows": [], "where": {}, "select": []},
        {"rows": [{"a": None}, {}], "where": {"a": None}, "select": ["a"]},
        {"rows": [{"x": 1}], "where": {}, "select": []},
        {"rows": [{"x": [1]}, {"x": [2]}], "where": {"x": [1]}, "select": ["x"]},
    ],
    [{"b": "x"}, {"b": None}],
)
add(
    "inner_join",
    "data",
    "left right key",
    "Input: left,right (lists of objects), key (string). Return [{left,right}] for all pairs with key present on both sides and equal JSON values. Order by left source index then right source index; duplicates multiply. Null keys can match. No boolean-versus-number comparisons.",
    [
        {
            "left": [{"id": 1}, {"id": 2}],
            "right": [{"id": 2}, {"id": 2, "x": 3}],
            "key": "id",
        },
        {"left": [], "right": [], "key": "k"},
        {"left": [{}], "right": [{}], "key": "k"},
        {"left": [{"k": None}], "right": [{"k": None}], "key": "k"},
        {"left": [{"k": 1}, {"k": 1}], "right": [{"k": 1}], "key": "k"},
    ],
    [
        {"left": {"id": 2}, "right": {"id": 2}},
        {"left": {"id": 2}, "right": {"id": 2, "x": 3}},
    ],
)
add(
    "group_totals",
    "data",
    "rows group value",
    "Input: rows (objects), group,value (field names). Each row has a string group value and integer numeric value. Return [{key,count,sum}] sorted by key. Empty rows returns [].",
    [
        {
            "rows": [{"g": "b", "v": 2}, {"g": "a", "v": 3}, {"g": "b", "v": -1}],
            "group": "g",
            "value": "v",
        },
        {"rows": [], "group": "g", "value": "v"},
        {"rows": [{"g": "", "v": 0}], "group": "g", "value": "v"},
        {"rows": [{"g": "é", "v": 9}, {"g": "A", "v": -9}], "group": "g", "value": "v"},
    ],
    [{"key": "a", "count": 1, "sum": 3}, {"key": "b", "count": 2, "sum": 1}],
)
add(
    "json_flatten",
    "data",
    "value",
    'Input: arbitrary JSON value. Return an object mapping JSON Pointer paths to leaves. Root path is "". Escape ~ as ~0 and / as ~1; array indices are decimal. Empty objects/arrays count as leaves. Nonempty containers do not produce their own entries.',
    [
        {"value": {"a": [1, {"x/y": None}], "b": {}}},
        {"value": []},
        {"value": None},
        {"value": {"~": {"/": 2}, "": 3}},
        {"value": [False, {}, []]},
    ],
    {"/a/0": 1, "/a/1/x~1y": None, "/b": {}},
)
add(
    "merge_patch",
    "data",
    "target patch",
    "Input: target,patch (JSON values). Apply JSON Merge Patch: a nonobject patch replaces the target. An object patch treats a nonobject target as {}; null-valued members remove keys; other members recursively merge. Arrays replace wholesale. Return resulting value.",
    [
        {
            "target": {"a": 1, "b": {"c": 2, "d": 3}},
            "patch": {"a": None, "b": {"c": 9}},
        },
        {"target": {}, "patch": None},
        {"target": [1], "patch": {"x": 2}},
        {"target": {"a": [1]}, "patch": {"a": [2, 3]}},
        {"target": 4, "patch": {}},
        {"target": {"a": 1}, "patch": {"z": None}},
    ],
    {"b": {"c": 9, "d": 3}},
)
add(
    "json_pointer",
    "data",
    "value pointer",
    "Input: value (JSON), pointer (empty or starting /, valid ~0/~1 escapes). Resolve object keys or array indices. Array tokens must be 0 or a nonzero decimal digit followed by decimal digits (no leading zero, sign, or -). Return {found:true,value:...}; missing keys, noncontainers or out-of-range indices return {found:false,value:null}. Empty pointer returns root.",
    [
        {"value": {"a/b": [7]}, "pointer": "/a~1b/0"},
        {"value": None, "pointer": ""},
        {"value": [1], "pointer": "/01"},
        {"value": {"": {"~": 2}}, "pointer": "//~0"},
        {"value": [1], "pointer": "/9"},
        {"value": {"a": None}, "pointer": "/a/x"},
        {"value": [], "pointer": "/-"},
    ],
    {"found": True, "value": 7},
)
add(
    "dedupe_records",
    "data",
    "rows keys",
    "Input: rows (objects), keys (field names). Retain first row for each distinct tuple of requested field values; missing fields equal null. Structural JSON equality ignores object key order. Keep source order. Boolean and numeric key values are not mixed.",
    [
        {"rows": [{"id": 1, "x": "a"}, {"id": 1, "x": "b"}, {"id": 2}], "keys": ["id"]},
        {"rows": [], "keys": []},
        {"rows": [{"x": 1}, {"x": 2}], "keys": []},
        {"rows": [{}, {"x": None}], "keys": ["x"]},
        {"rows": [{"x": {"a": 1, "b": 2}}, {"x": {"b": 2, "a": 1}}], "keys": ["x"]},
    ],
    [{"id": 1, "x": "a"}, {"id": 2}],
)
add(
    "pivot_table",
    "data",
    "rows row column value",
    "Input: rows, row,column,value field names. Row/column values are strings; numeric values are integers. Return {rows:sorted row labels,columns:sorted column labels,values:2D sums}, filling missing cells with 0. Empty input yields three empty arrays.",
    [
        {
            "rows": [
                {"r": "a", "c": "x", "v": 2},
                {"r": "b", "c": "y", "v": 3},
                {"r": "a", "c": "x", "v": -1},
            ],
            "row": "r",
            "column": "c",
            "value": "v",
        },
        {"rows": [], "row": "r", "column": "c", "value": "v"},
        {"rows": [{"r": "", "c": "", "v": 0}], "row": "r", "column": "c", "value": "v"},
        {
            "rows": [{"r": "z", "c": "b", "v": -5}, {"r": "a", "c": "a", "v": 1}],
            "row": "r",
            "column": "c",
            "value": "v",
        },
    ],
    {"rows": ["a", "b"], "columns": ["x", "y"], "values": [[1, 0], [0, 3]]},
)
add(
    "schema_check",
    "data",
    "schema value",
    'Input: schema object maps field names to {type,required}; value is an object. Types: string,integer,number,boolean,array,object,null. Booleans are neither integers nor numbers. For each schema field in lexical order, report {field,error:"required"} if missing and required, or {field,error:"type"} if present with wrong type. Optional missing fields and extra fields are ignored. No recursive validation.',
    [
        {
            "schema": {
                "a": {"type": "integer", "required": True},
                "b": {"type": "string", "required": True},
            },
            "value": {"a": True},
        },
        {"schema": {}, "value": {"a": 1}},
        {"schema": {"x": {"type": "null", "required": False}}, "value": {}},
        {"schema": {"x": {"type": "number", "required": True}}, "value": {"x": 1.5}},
        {"schema": {"x": {"type": "array", "required": True}}, "value": {"x": []}},
    ],
    [{"field": "a", "error": "type"}, {"field": "b", "error": "required"}],
)
add(
    "interval_union",
    "intervals",
    "intervals",
    "Input: intervals, list of [start,end] integer pairs with start<=end. Return sorted merged intervals, combining overlaps and touching endpoints. Retain isolated zero-length intervals.",
    [
        {"intervals": [[5, 7], [1, 3], [3, 6], [9, 9]]},
        {"intervals": []},
        {"intervals": [[0, 0], [0, 0]]},
        {"intervals": [[-4, -1], [-2, 3]]},
        {"intervals": [[1, 10], [2, 3], [12, 14]]},
    ],
    [[1, 7], [9, 9]],
)
add(
    "interval_gaps",
    "intervals",
    "intervals bounds",
    "Input: intervals ([a,b] with a<=b), bounds [low,high] with low<=high. Return positive-length gaps in [low,high] after unioning and clipping occupied intervals. Touching endpoints do not make gaps. Sorted ascending; no zero-length results.",
    [
        {"intervals": [[2, 4], [6, 9]], "bounds": [0, 10]},
        {"intervals": [], "bounds": [0, 5]},
        {"intervals": [[-3, 8]], "bounds": [0, 5]},
        {"intervals": [[8, 9], [-3, -1]], "bounds": [0, 5]},
        {"intervals": [[2, 2]], "bounds": [0, 5]},
        {"intervals": [], "bounds": [2, 2]},
    ],
    [[0, 2], [4, 6], [9, 10]],
)
add(
    "booking_peak",
    "intervals",
    "bookings",
    "Input: bookings ([start,end] integer pairs, start<=end). Intervals are half-open; zero-length bookings ignored. Return {peak,at} for maximum simultaneous active bookings and earliest timestamp attaining that maximum. Empty effective input: {peak:0,at:null}. Endings at t happen before starts at t.",
    [
        {"bookings": [[1, 4], [2, 3], [3, 5]]},
        {"bookings": []},
        {"bookings": [[1, 1]]},
        {"bookings": [[0, 1], [1, 2]]},
        {"bookings": [[-2, 2], [-2, 2]]},
    ],
    {"peak": 2, "at": 2},
)
add(
    "business_days",
    "calendar",
    "start end holidays",
    "Input: start,end ISO dates (start<=end) and holidays (ISO dates). Return all Monday-Friday dates in [start,end) excluding holidays, ascending. Duplicate holidays have no additional effect. Dates are valid in years 1900..2100, range <=400 days.",
    [
        {"start": "2024-02-28", "end": "2024-03-04", "holidays": ["2024-02-29"]},
        {"start": "2024-01-01", "end": "2024-01-01", "holidays": []},
        {"start": "2024-01-06", "end": "2024-01-08", "holidays": []},
        {
            "start": "2024-12-30",
            "end": "2025-01-03",
            "holidays": ["2025-01-01", "2025-01-01"],
        },
        {"start": "2000-02-28", "end": "2000-03-02", "holidays": []},
    ],
    ["2024-02-28", "2024-03-01"],
)
add(
    "calendar_month",
    "calendar",
    "year month",
    "Input: year (1900..2100), month (1..12). Return weeks as arrays of seven day numbers, Monday first. Use 0 for days outside the month; include only weeks intersecting this month.",
    [
        {"year": 2021, "month": 2},
        {"year": 2024, "month": 2},
        {"year": 1900, "month": 2},
        {"year": 2023, "month": 1},
        {"year": 2000, "month": 12},
    ],
    [
        [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],
    ],
)
add(
    "moving_average",
    "numeric",
    "values window",
    "Input: values (finite numbers), window (positive integer). Return arithmetic means for all contiguous full windows. Empty input or window>length gives [].",
    [
        {"values": [1, 2, 3, 4], "window": 2},
        {"values": [], "window": 1},
        {"values": [1], "window": 3},
        {"values": [-2, 0, 2], "window": 1},
        {"values": [1, 2], "window": 2},
        {"values": [0.1, 0.2, 0.3], "window": 2},
    ],
    [1.5, 2.5, 3.5],
)
add(
    "statistics",
    "numeric",
    "values",
    "Input: values (finite numbers). Return {count,min,max,mean,median,variance}. Variance is population variance (divide by n); even-length median is mean of middle two. Empty values: count=0 and all other fields null.",
    [
        {"values": [1, 2, 3, 4]},
        {"values": []},
        {"values": [7]},
        {"values": [-2, -2, 2, 2]},
        {"values": [0.1, 0.2, 0.3]},
        {"values": [9, 1, 3]},
    ],
    {"count": 4, "min": 1, "max": 4, "mean": 2.5, "median": 2.5, "variance": 1.25},
)
add(
    "histogram",
    "numeric",
    "values edges",
    "Input: finite numeric values and strictly increasing edges (>=2). Bins are [edge[i],edge[i+1]); values below first edge underflow, values >=last edge overflow. Return {counts,underflow,overflow}.",
    [
        {"values": [-1, 0, 1, 2, 3], "edges": [0, 1, 3]},
        {"values": [], "edges": [0, 1]},
        {"values": [0, 1, 2], "edges": [0, 1, 2]},
        {"values": [-5, -3, -1], "edges": [-4, -2, 0]},
        {"values": [0.1, 0.2], "edges": [0, 0.2, 1]},
    ],
    {"counts": [1, 2], "underflow": 1, "overflow": 1},
)
add(
    "matrix_product",
    "numeric",
    "a b",
    "Input: a (m by n), b (n by p), nonempty rectangular integer matrices of compatible dimensions, each dimension <=20. Return matrix product.",
    [
        {"a": [[1, 2], [3, 4]], "b": [[5], [6]]},
        {"a": [[0]], "b": [[9]]},
        {"a": [[-2, 3, 1]], "b": [[1, 0], [0, 1], [2, 2]]},
        {"a": [[1, 0], [0, 1]], "b": [[3, 4], [5, 6]]},
        {"a": [[2], [3]], "b": [[4, 5]]},
    ],
    [[17], [39]],
)
add(
    "polynomial",
    "numeric",
    "coefficients points",
    "Input: integer coefficients in ascending power order (c0,c1,...) and integer evaluation points. Return values at each point. Empty coefficients denote zero polynomial.",
    [
        {"coefficients": [1, 2, 3], "points": [0, 1, -1, 2]},
        {"coefficients": [], "points": [1, 0]},
        {"coefficients": [7], "points": []},
        {"coefficients": [0, 0, 1], "points": [-3, 3]},
        {"coefficients": [-1, 1], "points": [100, -100]},
    ],
    [1, 6, 2, 17],
)
add(
    "prime_factors",
    "numeric",
    "number",
    "Input: integer number in 1..10000000. Return [prime,exponent] pairs in ascending prime order; 1 returns [].",
    [
        {"number": 360},
        {"number": 1},
        {"number": 2},
        {"number": 9973},
        {"number": 65536},
        {"number": 99991},
    ],
    [[2, 3], [3, 2], [5, 1]],
)
add(
    "base_convert",
    "numeric",
    "digits from_base to_base",
    'Input: digits (valid integer representation, optional leading -, case-insensitive ASCII), from_base,to_base (2..36). Convert to lowercase digits 0-9a-z with no leading zero or plus; zero is "0". Magnitude <=2^100.',
    [
        {"digits": "ff", "from_base": 16, "to_base": 2},
        {"digits": "-0", "from_base": 10, "to_base": 36},
        {"digits": "-101", "from_base": 2, "to_base": 10},
        {"digits": "ZZ", "from_base": 36, "to_base": 16},
        {"digits": "00042", "from_base": 10, "to_base": 10},
        {"digits": "10000000000000000", "from_base": 16, "to_base": 10},
    ],
    "11111111",
)
add(
    "money_split",
    "numeric",
    "amount weights",
    "Input: nonnegative integer amount in cents, nonempty nonnegative integer weights with positive sum. Allocate by largest remainder: floor exact proportional shares, then give leftover cents to greatest fractional remainders, ties to lowest index. Return integer shares totaling amount.",
    [
        {"amount": 10, "weights": [1, 1, 1]},
        {"amount": 0, "weights": [1]},
        {"amount": 2, "weights": [0, 1, 1]},
        {"amount": 7, "weights": [1, 2]},
        {"amount": 1, "weights": [3, 3, 3]},
        {"amount": 1000001, "weights": [9, 1]},
    ],
    [4, 3, 3],
)
add(
    "invoice_total",
    "numeric",
    "items tax_rate",
    "Input: items [{price:nonnegative decimal string,quantity:nonnegative integer}], tax_rate (nonnegative decimal string). Sum exact price*quantity then round subtotal to cents using ROUND_HALF_UP. Tax = rounded subtotal * tax_rate, rounded half-up to cents. Total=subtotal+tax. Return {subtotal,tax,total} as strings with exactly two decimal places; do not use binary floating point for monetary arithmetic.",
    [
        {"items": [{"price": "0.335", "quantity": 3}], "tax_rate": "0.20"},
        {"items": [], "tax_rate": "0"},
        {"items": [{"price": "0.05", "quantity": 1}], "tax_rate": "0.1"},
        {"items": [{"price": "1.005", "quantity": 1}], "tax_rate": "0"},
        {
            "items": [
                {"price": "19.99", "quantity": 2},
                {"price": "3.50", "quantity": 3},
            ],
            "tax_rate": "0.075",
        },
    ],
    {"subtotal": "1.01", "tax": "0.20", "total": "1.21"},
)
add(
    "coin_change",
    "numeric",
    "coins amount",
    "Input: coins (positive integer denominations, duplicates allowed), amount (0..10000). Unlimited supply of each coin. Return minimum number of coins or null if impossible. Empty coins can make only zero.",
    [
        {"coins": [1, 3, 4], "amount": 6},
        {"coins": [], "amount": 0},
        {"coins": [2], "amount": 3},
        {"coins": [2, 2, 5], "amount": 10},
        {"coins": [], "amount": 4},
        {"coins": [7, 3], "amount": 11},
    ],
    2,
)
add(
    "graph_reach",
    "graphs",
    "nodes edges start",
    "Input: nodes (unique strings), edges ([from,to] directed pairs, endpoints in nodes), start (in nodes). Return sorted nodes reachable from start including itself. Allow cycles, self-edges and duplicate edges; <=100 nodes.",
    [
        {
            "nodes": ["a", "b", "c", "d"],
            "edges": [["a", "b"], ["b", "c"]],
            "start": "a",
        },
        {"nodes": ["a"], "edges": [], "start": "a"},
        {"nodes": ["a", "b"], "edges": [["b", "a"]], "start": "a"},
        {
            "nodes": ["a", "b"],
            "edges": [["a", "b"], ["b", "a"], ["a", "b"]],
            "start": "b",
        },
        {"nodes": ["x", "y"], "edges": [["x", "x"]], "start": "x"},
    ],
    ["a", "b", "c"],
)
add(
    "shortest_path",
    "graphs",
    "nodes edges start",
    "Input: nodes (unique strings), edges ([from,to,nonnegative integer weight], directed), start. Endpoints and start are in nodes. Return object mapping each node to shortest distance or null if unreachable. Cycles, parallel edges, zero weights allowed; <=100 nodes.",
    [
        {
            "nodes": ["a", "b", "c", "d"],
            "edges": [["a", "b", 5], ["a", "c", 1], ["c", "b", 1]],
            "start": "a",
        },
        {"nodes": ["a"], "edges": [], "start": "a"},
        {"nodes": ["a", "b"], "edges": [["b", "a", 1]], "start": "a"},
        {
            "nodes": ["a", "b", "c"],
            "edges": [["a", "b", 0], ["b", "a", 0], ["b", "c", 2], ["a", "c", 9]],
            "start": "a",
        },
        {"nodes": ["a", "b"], "edges": [["a", "b", 8], ["a", "b", 2]], "start": "a"},
    ],
    {"a": 0, "b": 2, "c": 1, "d": None},
)
add(
    "topological_order",
    "graphs",
    "nodes edges",
    "Input: unique string nodes, directed edges [from,to]. Return topological order choosing lexicographically smallest currently available node each step, or null on any cycle. Duplicate edges allowed and do not change dependencies. Endpoints in nodes; <=100 nodes.",
    [
        {"nodes": ["c", "a", "b"], "edges": [["a", "c"]]},
        {"nodes": [], "edges": []},
        {"nodes": ["a", "b"], "edges": [["a", "b"], ["b", "a"]]},
        {"nodes": ["a"], "edges": [["a", "a"]]},
        {"nodes": ["a", "b"], "edges": [["a", "b"], ["a", "b"]]},
        {"nodes": ["z", "a", "b"], "edges": []},
    ],
    ["a", "b", "c"],
)
add(
    "connected_components",
    "graphs",
    "nodes edges",
    "Input: unique string nodes, undirected edges [a,b], endpoints in nodes. Return components as sorted lists of nodes, ordered by each component first node. Include isolated vertices; allow duplicate edges and self-loops.",
    [
        {"nodes": ["d", "c", "b", "a"], "edges": [["a", "b"], ["c", "d"]]},
        {"nodes": [], "edges": []},
        {"nodes": ["a"], "edges": [["a", "a"]]},
        {"nodes": ["z", "a"], "edges": []},
        {"nodes": ["a", "b", "c"], "edges": [["a", "b"], ["b", "a"], ["b", "c"]]},
    ],
    [["a", "b"], ["c", "d"]],
)
add(
    "grid_route",
    "graphs",
    "grid start end",
    "Input: grid (nonempty equal-length strings containing . or #), start,end ([row,column], valid coordinates). Move one cell up/down/left/right through . cells. Return shortest step count, or null if blocked/unreachable, including blocked start or end. Grid <=50x50.",
    [
        {"grid": ["...", ".#.", "..."], "start": [0, 0], "end": [2, 2]},
        {"grid": ["."], "start": [0, 0], "end": [0, 0]},
        {"grid": ["#"], "start": [0, 0], "end": [0, 0]},
        {"grid": [".#."], "start": [0, 0], "end": [0, 2]},
        {"grid": ["..", ".."], "start": [1, 1], "end": [0, 0]},
    ],
    4,
)
add(
    "tree_outline",
    "graphs",
    "nodes",
    "Input: nodes [{id:unique string,parent:string or null}], forming a forest (all nonnull parents exist, no cycles), <=100 nodes. Return preorder [{id,depth}], roots and each sibling list sorted by id, roots depth 0.",
    [
        {
            "nodes": [
                {"id": "b", "parent": "a"},
                {"id": "a", "parent": None},
                {"id": "c", "parent": None},
            ]
        },
        {"nodes": []},
        {"nodes": [{"id": "x", "parent": None}]},
        {
            "nodes": [
                {"id": "c", "parent": "b"},
                {"id": "b", "parent": "a"},
                {"id": "a", "parent": None},
            ]
        },
        {"nodes": [{"id": "z", "parent": None}, {"id": "a", "parent": None}]},
    ],
    [{"id": "a", "depth": 0}, {"id": "b", "depth": 1}, {"id": "c", "depth": 0}],
)
add(
    "dependency_build",
    "graphs",
    "dependencies targets",
    "Input: dependencies (object of string node -> dependency string list), targets (strings). Every referenced name exists. DFS each distinct target in sorted order, visit dependencies in sorted order, append each node after dependencies once. Return build order; return null on a cycle reachable from a target. Unreachable cycles ignored; <=100 nodes.",
    [
        {
            "dependencies": {
                "app": ["lib", "cfg"],
                "lib": ["cfg"],
                "cfg": [],
                "unused": [],
            },
            "targets": ["app"],
        },
        {"dependencies": {}, "targets": []},
        {"dependencies": {"a": ["b"], "b": ["a"]}, "targets": ["a"]},
        {"dependencies": {"a": [], "x": ["x"]}, "targets": ["a"]},
        {"dependencies": {"a": [], "b": ["a"]}, "targets": ["b", "a", "b"]},
    ],
    ["cfg", "lib", "app"],
)
add(
    "path_normalize",
    "systems",
    "paths",
    "Input: paths (POSIX path strings). Treat all paths as rooted at /. Remove repeated / and . segments; .. pops a segment if available and is ignored at root. Preserve other segment code points and backslashes literally. Return absolute paths without trailing / except root. No filesystem access.",
    [
        {"paths": ["a/../b//c/", "/../../x", ""]},
        {"paths": []},
        {"paths": ["/", ".", "..", "a/./b"]},
        {"paths": ["a\\b/c", "/a/.../b"]},
        {"paths": ["é/../中", "a/../../"]},
    ],
    ["/b/c", "/x", "/"],
)
add(
    "url_query",
    "systems",
    "query",
    "Input: query string (without leading ?). Parse &-separated key/value pairs using first =, retain blank values and bare keys, decode + as space and percent-encoded UTF-8. Return object of decoded keys -> lists of values in source order. Empty segments ignored. Python urllib.parse.parse_qsl with keep_blank_values=True semantics.",
    [
        {"query": "a=1&a=2&x=hello+world&empty="},
        {"query": ""},
        {"query": "flag&&=x"},
        {"query": "q=%C3%A9&a%2Fb=x%3Dy"},
        {"query": "x=%2B&x=+&x=a=b"},
    ],
    {"a": ["1", "2"], "x": ["hello world"], "empty": [""]},
)
add(
    "version_sort",
    "systems",
    "versions",
    "Input: versions valid MAJOR.MINOR.PATCH optionally -prerelease.identifiers; no build metadata, numeric components/identifiers have no leading zeros. Sort by semantic version precedence: numeric core, prerelease before release, numeric prerelease identifiers numerically and before nonnumeric; nonnumeric ASCII lexical; shorter equal prefix first. Stable equal versions retained.",
    [
        {"versions": ["1.0.0", "1.0.0-beta", "1.0.0-alpha.10", "1.0.0-alpha.2"]},
        {"versions": []},
        {"versions": ["2.0.0", "10.0.0", "1.9.9"]},
        {"versions": ["1.0.0-a", "1.0.0-1", "1.0.0-a.1", "1.0.0"]},
        {"versions": ["1.0.0", "1.0.0"]},
    ],
    ["1.0.0-alpha.2", "1.0.0-alpha.10", "1.0.0-beta", "1.0.0"],
)
add(
    "lru_trace",
    "systems",
    "capacity accesses",
    "Input: nonnegative capacity and accesses (string keys). Simulate initially empty LRU cache. Hit moves key to most recent. Miss inserts and evicts oldest if full. Capacity 0 stores nothing. Return {hits,misses,keys}, keys oldest to newest.",
    [
        {"capacity": 2, "accesses": ["a", "b", "a", "c", "b"]},
        {"capacity": 0, "accesses": ["a", "a"]},
        {"capacity": 3, "accesses": []},
        {"capacity": 1, "accesses": ["a", "a", "b"]},
        {"capacity": 9, "accesses": ["x", "y", "x"]},
    ],
    {"hits": 1, "misses": 4, "keys": ["c", "b"]},
)
add(
    "rate_limit",
    "systems",
    "events window limit",
    "Input: events [{key:string,time:integer}] in nondecreasing time order, positive integer window, nonnegative limit. Per key, accept if fewer than limit previously accepted events have timestamps in (time-window,time]. Rejected events do not count. Process same-time events in input order. Return boolean decisions.",
    [
        {
            "events": [{"key": "a", "time": t} for t in [0, 0, 1, 5]],
            "window": 5,
            "limit": 2,
        },
        {"events": [], "window": 1, "limit": 1},
        {"events": [{"key": "x", "time": 0}], "window": 1, "limit": 0},
        {
            "events": [
                {"key": "a", "time": 0},
                {"key": "b", "time": 0},
                {"key": "a", "time": 1},
            ],
            "window": 1,
            "limit": 1,
        },
        {
            "events": [{"key": "a", "time": t} for t in [-3, -2, -1, 0]],
            "window": 2,
            "limit": 1,
        },
    ],
    [True, True, False, True],
)
add(
    "priority_queue",
    "systems",
    "events",
    'Input: events of {op:"push",priority:integer,value:JSON} or {op:"pop"}. Smaller priority first, FIFO ties. Pop empty produces null. Return {popped:list of pop results,remaining:list of queued values in pop order}.',
    [
        {
            "events": [
                {"op": "push", "priority": 2, "value": "a"},
                {"op": "push", "priority": 1, "value": "b"},
                {"op": "pop"},
            ]
        },
        {"events": []},
        {"events": [{"op": "pop"}, {"op": "pop"}]},
        {
            "events": [
                {"op": "push", "priority": 0, "value": {"x": 1}},
                {"op": "push", "priority": 0, "value": None},
                {"op": "pop"},
            ]
        },
        {"events": [{"op": "push", "priority": -1, "value": 3}]},
    ],
    {"popped": ["b"], "remaining": ["a"]},
)
add(
    "round_robin",
    "systems",
    "jobs quantum",
    "Input: jobs [{id:unique string,duration:positive integer}], positive integer quantum. All jobs arrive at 0 in input order. Repeatedly run first job min(remaining,quantum) time, append unfinished job to end. Return {slices:[{id,start,end}],completion:{id:completion time}}. Empty jobs gives empty structures.",
    [
        {
            "jobs": [{"id": "a", "duration": 3}, {"id": "b", "duration": 2}],
            "quantum": 2,
        },
        {"jobs": [], "quantum": 1},
        {"jobs": [{"id": "a", "duration": 1}], "quantum": 10},
        {
            "jobs": [{"id": "a", "duration": 2}, {"id": "b", "duration": 1}],
            "quantum": 1,
        },
        {"jobs": [{"id": "x", "duration": 4}], "quantum": 2},
    ],
    {
        "slices": [
            {"id": "a", "start": 0, "end": 2},
            {"id": "b", "start": 2, "end": 4},
            {"id": "a", "start": 4, "end": 5},
        ],
        "completion": {"b": 4, "a": 5},
    },
)
add(
    "inventory_ledger",
    "business",
    "events",
    "Input: events [{sku:string,delta:integer}]. Stock initially absent/zero. Apply in order, rejecting an event if stock would become negative; rejected events leave no state. Accepted events create the SKU even if delta=0. Return {stock:object,rejected:zero-based event indices}.",
    [
        {
            "events": [
                {"sku": "a", "delta": 3},
                {"sku": "a", "delta": -4},
                {"sku": "a", "delta": -2},
            ]
        },
        {"events": []},
        {"events": [{"sku": "x", "delta": -1}]},
        {
            "events": [
                {"sku": "x", "delta": 0},
                {"sku": "y", "delta": 2},
                {"sku": "y", "delta": -2},
            ]
        },
        {"events": [{"sku": "", "delta": 1}]},
    ],
    {"stock": {"a": 1}, "rejected": [1]},
)
add(
    "bank_ledger",
    "business",
    "balances transfers",
    "Input: balances (account -> nonnegative integer cents), transfers [{from,to,amount:positive integer}]. Reject missing accounts or insufficient source balance; otherwise subtract then add, including self-transfers. Return {balances,rejected:event indices}. Rejected transfers change nothing; never create accounts.",
    [
        {
            "balances": {"a": 10, "b": 0},
            "transfers": [
                {"from": "a", "to": "b", "amount": 7},
                {"from": "a", "to": "b", "amount": 4},
            ],
        },
        {"balances": {}, "transfers": []},
        {"balances": {"a": 2}, "transfers": [{"from": "a", "to": "a", "amount": 2}]},
        {"balances": {"a": 3}, "transfers": [{"from": "a", "to": "x", "amount": 1}]},
        {"balances": {"a": 0}, "transfers": [{"from": "x", "to": "a", "amount": 1}]},
    ],
    {"balances": {"a": 3, "b": 7}, "rejected": [1]},
)
add(
    "ballot_count",
    "business",
    "candidates votes",
    "Input: candidates (unique strings), votes (strings). Count candidate votes, unrecognized votes invalid. Return {ranking:[{candidate,votes}],invalid}. Include zero-vote candidates. Rank by decreasing votes then ascending name.",
    [
        {"candidates": ["b", "a", "c"], "votes": ["a", "b", "a", "x"]},
        {"candidates": [], "votes": []},
        {"candidates": ["a"], "votes": ["x", ""]},
        {"candidates": ["b", "a"], "votes": ["b", "a"]},
        {"candidates": [], "votes": ["x"]},
    ],
    {
        "ranking": [
            {"candidate": "a", "votes": 2},
            {"candidate": "b", "votes": 1},
            {"candidate": "c", "votes": 0},
        ],
        "invalid": 1,
    },
)
add(
    "search_rank",
    "business",
    "documents query",
    "Input: documents [{id:unique string,text:string}], query string. Tokenize lowercase ASCII [a-z0-9]+. Score each document by total occurrence counts of distinct query tokens. Omit score=0 docs. Return [{id,score}] sorted by decreasing score then id.",
    [
        {
            "documents": [
                {"id": "b", "text": "red blue"},
                {"id": "a", "text": "red red"},
                {"id": "c", "text": "green"},
            ],
            "query": "RED red blue",
        },
        {"documents": [], "query": "x"},
        {"documents": [{"id": "a", "text": "x"}], "query": ""},
        {
            "documents": [{"id": "z", "text": "x"}, {"id": "a", "text": "x"}],
            "query": "x",
        },
        {"documents": [{"id": "a", "text": "é RED_42"}], "query": "red 42"},
    ],
    [{"id": "a", "score": 2}, {"id": "b", "score": 2}],
)
add(
    "log_summary",
    "business",
    "events",
    "Input: events [{level:string,message:string}]. Return {counts:level->count,errors:messages of exactly ERROR-level events in source order}. Levels are case-sensitive; include only encountered levels.",
    [
        {
            "events": [
                {"level": "INFO", "message": "start"},
                {"level": "ERROR", "message": "bad"},
                {"level": "ERROR", "message": "worse"},
            ]
        },
        {"events": []},
        {"events": [{"level": "error", "message": "x"}]},
        {
            "events": [
                {"level": "WARN", "message": ""},
                {"level": "INFO", "message": "ok"},
            ]
        },
        {"events": [{"level": "ERROR", "message": "é"}]},
    ],
    {"counts": {"INFO": 1, "ERROR": 2}, "errors": ["bad", "worse"]},
)
add(
    "uptime_report",
    "business",
    "start end downtime",
    "Input: integer start<=end, downtime intervals [a,b] with a<=b. Clip to [start,end), merge overlaps, count duration without double-counting. Return {down,up}, up=end-start-down.",
    [
        {"start": 0, "end": 10, "downtime": [[-2, 3], [2, 5], [8, 12]]},
        {"start": 0, "end": 0, "downtime": []},
        {"start": 0, "end": 5, "downtime": []},
        {"start": 0, "end": 5, "downtime": [[-10, 10]]},
        {"start": 0, "end": 5, "downtime": [[1, 1], [5, 8]]},
    ],
    {"down": 7, "up": 3},
)
add(
    "segment_intersection",
    "geometry",
    "a b c d",
    "Input: a,b,c,d each [integer x,integer y]. Return boolean whether closed segments ab and cd intersect, including collinear overlap, endpoint touches and degenerate point-segments. Coordinates magnitude <=100000.",
    [
        {"a": [0, 0], "b": [2, 2], "c": [0, 2], "d": [2, 0]},
        {"a": [0, 0], "b": [1, 0], "c": [2, 0], "d": [3, 0]},
        {"a": [0, 0], "b": [2, 0], "c": [1, 0], "d": [3, 0]},
        {"a": [0, 0], "b": [0, 0], "c": [-1, 0], "d": [1, 0]},
        {"a": [0, 0], "b": [0, 1], "c": [0, 1], "d": [1, 1]},
        {"a": [0, 0], "b": [0, 0], "c": [1, 1], "d": [1, 1]},
    ],
    True,
)
add(
    "polygon_area",
    "geometry",
    "points",
    "Input: points, ordered integer [x,y] vertices of a simple polygon (clockwise or counterclockwise), possibly empty or fewer than three points. Return nonnegative area by shoelace, implicitly close last to first. Degenerate polygon has zero area.",
    [
        {"points": [[0, 0], [4, 0], [4, 3], [0, 3]]},
        {"points": []},
        {"points": [[1, 2]]},
        {"points": [[0, 0], [1, 0], [0, 1]]},
        {"points": [[0, 0], [0, 3], [4, 3], [4, 0]]},
        {"points": [[-1, -1], [1, 1]]},
    ],
    12,
)
add(
    "skyline",
    "geometry",
    "buildings",
    "Input: buildings [left,right,height], integer left<right and positive height. Return skyline keypoints [x,height] in ascending x where max active height changes. Buildings cover [left,right); omit redundant same-height points; finish with height 0 at last active end. Empty input returns [].",
    [
        {"buildings": [[1, 4, 3], [2, 6, 5], [7, 8, 2]]},
        {"buildings": []},
        {"buildings": [[0, 1, 2], [1, 2, 2]]},
        {"buildings": [[0, 5, 4], [1, 2, 1]]},
        {"buildings": [[-2, 0, 3], [-2, 0, 3]]},
    ],
    [[1, 3], [2, 5], [6, 0], [7, 2], [8, 0]],
)
add(
    "knapsack",
    "optimization",
    "items capacity",
    "Input: items [{weight:positive integer,value:nonnegative integer}], capacity (0..1000). Each item usable at most once; return maximum total value within capacity. Identical items remain independently usable; no need to return selected indices.",
    [
        {
            "items": [
                {"weight": 2, "value": 3},
                {"weight": 3, "value": 4},
                {"weight": 4, "value": 8},
            ],
            "capacity": 5,
        },
        {"items": [], "capacity": 5},
        {"items": [{"weight": 1, "value": 2}], "capacity": 0},
        {
            "items": [{"weight": 2, "value": 3}, {"weight": 2, "value": 3}],
            "capacity": 4,
        },
        {"items": [{"weight": 9, "value": 20}], "capacity": 3},
    ],
    8,
)
add(
    "task_selection",
    "optimization",
    "tasks",
    "Input: tasks [{id:unique string,start:integer,end:integer}], start<end. Greedy maximum-count nonoverlapping schedule: sort by (end,start,id), choose each task iff start>=previous chosen end. Return chosen IDs. Intervals are half-open, negative times allowed.",
    [
        {
            "tasks": [
                {"id": "a", "start": 0, "end": 3},
                {"id": "b", "start": 1, "end": 2},
                {"id": "c", "start": 2, "end": 4},
            ]
        },
        {"tasks": []},
        {
            "tasks": [
                {"id": "b", "start": 0, "end": 1},
                {"id": "a", "start": 0, "end": 1},
            ]
        },
        {
            "tasks": [
                {"id": "a", "start": -3, "end": -1},
                {"id": "b", "start": -1, "end": 0},
            ]
        },
        {"tasks": [{"id": "x", "start": 0, "end": 9}]},
    ],
    ["b", "c"],
)
add(
    "sequence_diff",
    "optimization",
    "a b",
    'Input: a,b (lists of strings, length<=100). Produce minimal insert/delete edit script via longest common subsequence. If current tokens equal, emit ["keep",token] and advance both. Otherwise choose deletion when remaining LCS lengths tie; else choose operation retaining longer LCS. Emit ["delete",token] or ["insert",token]; process until both exhausted.',
    [
        {"a": ["a", "b"], "b": ["b", "c"]},
        {"a": [], "b": []},
        {"a": ["a"], "b": []},
        {"a": [], "b": ["x", "y"]},
        {"a": ["a", "b"], "b": ["b", "a"]},
        {"a": ["x", "x"], "b": ["x"]},
    ],
    [["delete", "a"], ["keep", "b"], ["insert", "c"]],
)
add(
    "finite_automaton",
    "languages",
    "start accepting transitions words",
    "Input: start (state string), accepting (state strings), transitions [{from,symbol,to}] with unique (from,symbol) and one-code-point symbols, words (strings). Simulate DFA separately per word. Missing transition rejects immediately. Return acceptance booleans. Empty word accepted iff start accepting.",
    [
        {
            "start": "a",
            "accepting": ["a"],
            "transitions": [
                {"from": "a", "symbol": "x", "to": "b"},
                {"from": "b", "symbol": "x", "to": "a"},
            ],
            "words": ["", "x", "xx", "y"],
        },
        {"start": "s", "accepting": [], "transitions": [], "words": ["", "a"]},
        {"start": "s", "accepting": ["s"], "transitions": [], "words": [""]},
        {
            "start": "s",
            "accepting": ["t"],
            "transitions": [{"from": "s", "symbol": "é", "to": "t"}],
            "words": ["é", "éé"],
        },
        {"start": "s", "accepting": ["s"], "transitions": [], "words": []},
    ],
    [True, False, True, False],
)
add(
    "content_manifest",
    "systems",
    "files",
    "Input: files (object of logical file path -> text). Do not read filesystem. Return [{path,bytes,sha256}] sorted by path; bytes is length of UTF-8 encoding and sha256 is lowercase hexadecimal SHA-256 of that encoding. No newline insertion or Unicode normalization.",
    [
        {"files": {"empty": ""}},
        {"files": {}},
        {"files": {"b": "hello", "a": "é"}},
        {"files": {"x": "a\n", "y": "a"}},
        {"files": {"中": "😀", "nul": "\u0000"}},
    ],
    [
        {
            "path": "empty",
            "bytes": 0,
            "sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
        }
    ],
)
add(
    "cellular_automaton",
    "simulation",
    "live steps",
    "Input: live (integer [row,column] pairs, duplicates ignored), steps (0..20). Simulate Conway Life on infinite 2D grid, eight neighbors: live survives with 2 or 3, dead born with 3. Return sorted unique live pairs lexicographically. Initial <=50 cells.",
    [
        {"live": [[0, 0], [0, 1], [0, 2]], "steps": 1},
        {"live": [], "steps": 10},
        {"live": [[0, 0]], "steps": 1},
        {"live": [[0, 0], [0, 1], [1, 0], [1, 1]], "steps": 5},
        {"live": [[1, 2], [1, 2], [-1, 0]], "steps": 0},
        {"live": [[0, 0], [0, 1], [0, 2]], "steps": 2},
    ],
    [[-1, 1], [0, 1], [1, 1]],
)
add(
    "expression_eval",
    "languages",
    "tokens",
    "Input: tokens, a valid postfix integer expression as strings with binary operators +,-,*,/. Return integer result. Division truncates toward zero, including negative operands; all divisors nonzero. Other tokens are signed base-10 integers. All intermediate magnitudes <=2^100; expression leaves exactly one value.",
    [
        {"tokens": ["5", "2", "-", "4", "*"]},
        {"tokens": ["-7", "3", "/"]},
        {"tokens": ["7", "-3", "/"]},
        {"tokens": ["42"]},
        {"tokens": ["2", "3", "4", "*", "+"]},
        {"tokens": ["100000000000000000001", "3", "/"]},
    ],
    12,
)

assert len(FAMILIES) == 65