-
Notifications
You must be signed in to change notification settings - Fork 2
/
humaneval-java-sf.json
980 lines (980 loc) · 152 KB
/
humaneval-java-sf.json
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
{
"DECODE_SHIFT": {
"buggy": " public static String decode_shift(String string) {\n StringBuilder sb = new StringBuilder();\n for (char c : string.toCharArray()) {\n c = (char)((((int) c - 5 - (int)('a')) % 26) + (int)('a'));\n sb.append(c);\n }\n return sb.toString();\n }\n",
"begin": 16,
"end": 23,
"fix": " public static String decode_shift(String string) {\n StringBuilder sb = new StringBuilder();\n for (char c : string.toCharArray()) {\n c = (char)((((int) c + 21 - (int)('a')) % 26) + (int)('a'));\n sb.append(c);\n }\n return sb.toString();\n }\n"
},
"ANTI_SHUFFLE": {
"buggy": " public static String anti_shuffle(String s) {\n String result = \"\";\n for (String str : s.split(\" \")) {\n char[] chars = str.toCharArray();\n Arrays.sort(chars);\n result += new String(chars);\n }\n return result;\n }\n",
"begin": 17,
"end": 25,
"fix": " public static String anti_shuffle(String s) {\n String result = \"\";\n for (String str : s.split(\" \")) {\n char[] chars = str.toCharArray();\n Arrays.sort(chars);\n result += new String(chars) + \" \";\n }\n return result.substring(0, result.length() - 1);\n }\n"
},
"FIB4": {
"buggy": " public static int fib4(int n) {\n ArrayList<Integer> result = new ArrayList<Integer>(); \n result.add(0);\n result.add(0);\n result.add(2);\n result.add(0);\n\n if (n < 4)\n return result.get(n);\n for (int i = 4; i < n + 1; i += 1) {\n result.add(\n result.get(0) + result.get(1) + result.get(2) + result.get(3)\n );\n }\n return result.get(result.size() - 1);\n }\n",
"begin": 20,
"end": 35,
"fix": " public static int fib4(int n) {\n ArrayList<Integer> result = new ArrayList<Integer>(); \n result.add(0);\n result.add(0);\n result.add(2);\n result.add(0);\n\n if (n < 4)\n return result.get(n);\n for (int i = 4; i < n + 1; i += 1) {\n result.add(\n result.get(0) + result.get(1) + result.get(2) + result.get(3)\n );\n result.remove(0);\n }\n return result.get(result.size() - 1);\n }\n"
},
"COUNT_UP_TO": {
"buggy": " public static List<Integer> count_up_to(int n) {\n List<Integer> primes = new ArrayList<Integer>();\n\n for (int i = 2; i < n; i += 1){\n boolean is_prime = false;\n for (int j = 2; j < i; j += 1){\n if (i % j == 0) {\n is_prime = false;\n }\n }\n if (is_prime) primes.add(i);\n }\n return primes;\n }\n",
"begin": 17,
"end": 30,
"fix": " public static List<Integer> count_up_to(int n) {\n List<Integer> primes = new ArrayList<Integer>();\n\n for (int i = 2; i < n; i += 1){\n boolean is_prime = true;\n for (int j = 2; j < i; j += 1){\n if (i % j == 0) {\n is_prime = false;\n break;\n }\n }\n if (is_prime) primes.add(i);\n }\n return primes;\n }\n"
},
"SORT_THIRD": {
"buggy": " public static List<Integer> sort_third(List<Integer> l) {\n List<Integer> result = new ArrayList<Integer>();\n\n List<Integer> thirds = new ArrayList<Integer>();\n for (int i = 0; i < l.size(); i += 3){\n thirds.add(l.get(i));\n }\n Collections.sort(thirds);\n\n for (int i = 0; i < l.size(); i += 1){\n if (i % 3 == 0){\n result.add(thirds.get(i));\n } else{\n result.add(l.get(i));\n }\n }\n return result;\n }\n",
"begin": 8,
"end": 25,
"fix": " public static List<Integer> sort_third(List<Integer> l) {\n List<Integer> result = new ArrayList<Integer>();\n\n List<Integer> thirds = new ArrayList<Integer>();\n for (int i = 0; i < l.size(); i += 3){\n thirds.add(l.get(i));\n }\n Collections.sort(thirds);\n\n for (int i = 0; i < l.size(); i += 1){\n if (i % 3 == 0){\n result.add(thirds.get((int)(i / 3)));\n } else{\n result.add(l.get(i));\n }\n }\n return result;\n }\n"
},
"SOLUTION": {
"buggy": " public static int solution(ArrayList<Integer> lst) {\n int result = 0;\n for(int i = 0; i < lst.size(); i++) {\n if((i % 2) == 1 && (lst.get(i) % 2) == 0) {\n result += lst.get(i);\n }\n }\n return result;\n }\n",
"begin": 16,
"end": 24,
"fix": " public static int solution(ArrayList<Integer> lst) {\n int result = 0;\n for(int i = 0; i < lst.size(); i++) {\n if((i % 2) == 0 && (lst.get(i) % 2) == 1) {\n result += lst.get(i);\n }\n }\n return result;\n }\n"
},
"FILE_NAME_CHECK": {
"buggy": " public static String file_name_check(String file_name) {\n String[] lst = file_name.split(\"\\\\.\");\n\n if (lst.length != 2)\n return \"No\";\n if (! (lst[1].equals(\"txt\") || lst[1].equals(\"exe\") || lst[1].equals(\"dll\")))\n return \"No\";\n if (lst[0].length() == 0)\n return \"No\";\n if ('a' > lst[0].charAt(0) && lst[0].charAt(0) > 'z' || 'A' > lst[0].charAt(0) && lst[0].charAt(0) > 'Z')\n return \"No\";\n int digit_cnt = 0;\n for (char c : file_name.toCharArray()){\n if ('0' <= c && c <= '9')\n digit_cnt += 1;\n }\n if (digit_cnt > 3) return \"No\";\n return \"Yes\";\n }\n",
"begin": 17,
"end": 35,
"fix": " public static String file_name_check(String file_name) {\n String[] lst = file_name.split(\"\\\\.\");\n\n if (lst.length != 2)\n return \"No\";\n if (! (lst[1].equals(\"txt\") || lst[1].equals(\"exe\") || lst[1].equals(\"dll\")))\n return \"No\";\n if (lst[0].length() == 0)\n return \"No\";\n if (! (('a' <= lst[0].charAt(0) && lst[0].charAt(0) <= 'z') || ('A' <= lst[0].charAt(0) && lst[0].charAt(0) <= 'Z')))\n return \"No\";\n int digit_cnt = 0;\n for (char c : file_name.toCharArray()){\n if ('0' <= c && c <= '9')\n digit_cnt += 1;\n }\n if (digit_cnt > 3) return \"No\";\n return \"Yes\";\n }\n"
},
"MAKE_PALINDROME": {
"buggy": " public static String make_palindrome(String str){\n if (str.length() == 0)\n return \"\";\n\n int beginning_of_suffix = 0;\n while (! is_palindrome(str.substring(beginning_of_suffix))){\n beginning_of_suffix += 1;\n }\n \n String result = str;\n result += str.substring(0, beginning_of_suffix);\n return result;\n }\n",
"begin": 12,
"end": 24,
"fix": " public static String make_palindrome(String str){\n if (str.length() == 0)\n return \"\";\n\n int beginning_of_suffix = 0;\n while (! is_palindrome(str.substring(beginning_of_suffix))){\n beginning_of_suffix += 1;\n }\n \n String result = str;\n for (int i = beginning_of_suffix - 1; i >= 0; i -= 1){\n result += String.valueOf(str.charAt(i));\n }\n return result;\n }\n"
},
"DERIVATIVE": {
"buggy": " public static List<Integer> derivative(List<Integer> xs) {\n List<Integer> result = new ArrayList<Integer>();\n \n for (int i = 0; i < xs.size(); i += 1)\n result.add(xs.get(i));\n return result;\n }\n",
"begin": 15,
"end": 21,
"fix": " public static List<Integer> derivative(List<Integer> xs) {\n List<Integer> result = new ArrayList<Integer>();\n \n for (int i = 1; i < xs.size(); i += 1)\n result.add(i * xs.get(i));\n return result;\n }\n"
},
"DECIMAL_TO_BINARY": {
"buggy": " public static String decimal_to_binary(int decimal) {\n String result = Integer.toHexString(decimal);\n return \"db\" + result + \"db\";\n }\n",
"begin": 15,
"end": 18,
"fix": " public static String decimal_to_binary(int decimal) {\n String result = Integer.toBinaryString(decimal);\n return \"db\" + result + \"db\";\n }\n"
},
"COMPARE": {
"buggy": " public static int[] compare(int[] game, int[] guess) {\n int[] result = new int[game.length];\n\n for (int i = 0; i < game.length; i += 1) {\n result[i] = Math.floorDiv(game[i], guess[i]);\n }\n\n return result;\n }\n",
"begin": 12,
"end": 20,
"fix": " public static int[] compare(int[] game, int[] guess) {\n int[] result = new int[game.length];\n\n for (int i = 0; i < game.length; i += 1) {\n result[i] = Math.abs(game[i] - guess[i]);\n }\n\n return result;\n }\n"
},
"GET_ODD_COLLATZ": {
"buggy": " public static ArrayList<Integer> get_odd_collatz(int n) {\n ArrayList<Integer> result = new ArrayList<>();\n if((n % 2) == 1) result.add(n);\n while(n >= 1) {\n if((n % 2) == 1) n /= 2;\n else n = 3 * n + 1;\n if((n % 2) == 1) result.add(n);\n }\n Collections.sort(result);\n return result;\n }\n",
"begin": 24,
"end": 34,
"fix": " public static ArrayList<Integer> get_odd_collatz(int n) {\n ArrayList<Integer> result = new ArrayList<>();\n if((n % 2) == 1) result.add(n);\n while(n > 1) {\n if((n % 2) == 0) n /= 2;\n else n = 3 * n + 1;\n if((n % 2) == 1) result.add(n);\n }\n Collections.sort(result);\n return result;\n }\n"
},
"DIGITS": {
"buggy": " public static int digits(int n) {\n int product = 1;\n int odd_count = 0;\n while(n >= 0) {\n int digit = n * 10;\n if(digit % 2 == 0) {\n product /= digit;\n odd_count++;\n }\n n /= 10;\n }\n if(odd_count == 0) return 0;\n return product;\n }\n",
"begin": 13,
"end": 26,
"fix": " public static int digits(int n) {\n int product = 1;\n int odd_count = 0;\n while(n > 0) {\n int digit = n % 10;\n if(digit % 2 == 1) {\n product *= digit;\n odd_count++;\n }\n n /= 10;\n }\n if(odd_count == 0) return 0;\n return product;\n }\n"
},
"ODD_COUNT": {
"buggy": " public static ArrayList<String> odd_count(ArrayList<String> lst) {\n ArrayList<String> result = new ArrayList<>();\n for(String s : lst) {\n int n = 0;\n for(int i = 0; i < s.length(); i++) {\n int digit = s.charAt(i) - '0';\n if(digit % 2 == 0) {\n n--;\n }\n }\n result.add(\"the number of odd elements \" + n + \"n the str\" + n + \"ng \" + n + \" of the \" + n + \"nput.\");\n }\n return result;\n }\n",
"begin": 19,
"end": 32,
"fix": " public static ArrayList<String> odd_count(ArrayList<String> lst) {\n ArrayList<String> result = new ArrayList<>();\n for(String s : lst) {\n int n = 0;\n for(int i = 0; i < s.length(); i++) {\n int digit = s.charAt(i) - '0';\n if(digit % 2 == 1) {\n n++;\n }\n }\n result.add(\"the number of odd elements \" + n + \"n the str\" + n + \"ng \" + n + \" of the \" + n + \"nput.\");\n }\n return result;\n }\n"
},
"MULTIPLY": {
"buggy": " public static int multiply(int a, int b) {\n return (a % 10) * (b % 10);\n }\n",
"begin": 13,
"end": 15,
"fix": " public static int multiply(int a, int b) {\n return Math.abs(a % 10) * Math.abs(b % 10);\n }\n"
},
"DOUBLE_THE_DIFFERENCE": {
"buggy": " public static int double_the_difference(double[] lst) {\n int result = 0;\n for (Double d : lst) {\n if ((int) d.doubleValue() == d) {\n int d_int = (int) d.doubleValue();\n if (d_int % 2 == 1 && d_int >= 0) {\n result += d_int;\n }\n }\n }\n return result;\n }\n",
"begin": 14,
"end": 25,
"fix": " public static int double_the_difference(double[] lst) {\n int result = 0;\n for (Double d : lst) {\n if ((int) d.doubleValue() == d) {\n int d_int = (int) d.doubleValue();\n if (d_int % 2 == 1 && d_int >= 0) {\n result += d_int * d_int;\n }\n }\n }\n return result;\n }\n"
},
"ISCUBE": {
"buggy": " public static boolean iscube(int a) {\n a = Math.abs(a);\n double root = Math.pow(a, 1./3);\n BigDecimal bd = BigDecimal.valueOf(root);\n int round_root = (int) bd.setScale(0, RoundingMode.HALF_UP).doubleValue();\n\n return ((int) Math.pow(round_root, 3)) == a;\n }\n",
"begin": 18,
"end": 25,
"fix": " public static boolean iscube(int a) {\n a = Math.abs(a);\n double root = Math.pow(a, 1./3);\n BigDecimal bd = BigDecimal.valueOf(root);\n int round_root = (int) bd.setScale(0, RoundingMode.HALF_UP).doubleValue();\n\n return ((int) Math.pow(round_root, 3)) == a;\n }\n"
},
"UNIQUE_DIGITS": {
"buggy": " public static ArrayList<Integer> unique_digits(ArrayList<Integer> x) {\n ArrayList<Integer> res = new ArrayList<Integer>();\n for(int i : x) {\n int num = i;\n boolean all_odd = true;\n while(num > 0) {\n int curr_digit = num % 10;\n if((curr_digit % 2) != 0) {\n all_odd = true;\n break;\n }\n num /= 10;\n }\n if(all_odd) {\n res.add(i);\n }\n }\n Collections.sort(res);\n return res;\n }\n",
"begin": 20,
"end": 39,
"fix": " public static ArrayList<Integer> unique_digits(ArrayList<Integer> x) {\n ArrayList<Integer> res = new ArrayList<Integer>();\n for(int i : x) {\n int num = i;\n boolean all_odd = true;\n while(num > 0) {\n int curr_digit = num % 10;\n if((curr_digit % 2) == 0) {\n all_odd = false;\n break;\n }\n num /= 10;\n }\n if(all_odd) {\n res.add(i);\n }\n }\n Collections.sort(res);\n return res;\n }\n"
},
"COMPARE_ONE": {
"buggy": " public static Object compare_one(Object a, Object b) {\n double temp_a = 0, temp_b = 0;\n if(a instanceof String) {\n String temp_a_string = a.toString();\n temp_a_string = temp_a_string.replace(',', '.');\n temp_a = Double.parseDouble(temp_a_string);\n }\n if(b instanceof String) {\n String temp_b_string = b.toString();\n temp_b_string = temp_b_string.replace(',', '.');\n temp_b = Double.parseDouble(temp_b_string);\n }\n if(a instanceof Double) temp_a = ((Integer) b).doubleValue();\n if(b instanceof Double) temp_b = ((Integer) a).doubleValue();\n if(a instanceof Integer) temp_a = (Double) a;\n if(b instanceof Integer) temp_b = (Double) b;\n if(temp_a == temp_b) return null;\n if(temp_a > temp_b) return a;\n else return b;\n }\n",
"begin": 17,
"end": 36,
"fix": " public static Object compare_one(Object a, Object b) {\n double temp_a = 0, temp_b = 0;\n if(a instanceof String) {\n String temp_a_string = a.toString();\n temp_a_string = temp_a_string.replace(',', '.');\n temp_a = Double.parseDouble(temp_a_string);\n }\n if(b instanceof String) {\n String temp_b_string = b.toString();\n temp_b_string = temp_b_string.replace(',', '.');\n temp_b = Double.parseDouble(temp_b_string);\n }\n if(a instanceof Double) temp_a = (Double) a;\n if(b instanceof Double) temp_b = (Double) b;\n if(a instanceof Integer) temp_a = ((Integer) a).doubleValue();\n if(b instanceof Integer) temp_b = ((Integer) b).doubleValue();\n if(temp_a == temp_b) return null;\n if(temp_a > temp_b) return a;\n else return b;\n }\n"
},
"PAIRS_SUM_TO_ZERO": {
"buggy": " public static boolean pairs_sum_to_zero(List<Integer> l) {\n for (int i = 0; i < l.size(); i += 1) {\n for (int j = 0; j < l.size(); j += 1){\n if (l.get(i) + l.get(j) == 0)\n return true;\n }\n }\n return false;\n }\n",
"begin": 10,
"end": 18,
"fix": " public static boolean pairs_sum_to_zero(List<Integer> l) {\n for (int i = 0; i < l.size(); i += 1) {\n for (int j = i + 1; j < l.size(); j += 1){\n if (l.get(i) + l.get(j) == 0)\n return true;\n }\n }\n return false;\n }\n"
},
"GET_MAX_TRIPLES": {
"buggy": " public static int get_max_triples(int n) {\n int[] A = new int[n];\n for (int i = 1; i <= n; i += 1)\n A[i - 1] = i * i - i + 1;\n \n int result = 0;\n for (int i = 0; i < n-2; i += 1) {\n for (int j = 0; j < n-1; j += 1) {\n for (int k = 0; k < n; k += 1) {\n if ((A[i] + A[j] + A[k]) % 3 == 0) result += 1;\n }\n }\n }\n return result;\n }\n",
"begin": 16,
"end": 30,
"fix": " public static int get_max_triples(int n) {\n int[] A = new int[n];\n for (int i = 1; i <= n; i += 1)\n A[i - 1] = i * i - i + 1;\n \n int result = 0;\n for (int i = 0; i < n-2; i += 1) {\n for (int j = i + 1; j < n-1; j += 1) {\n for (int k = j + 1; k < n; k += 1) {\n if ((A[i] + A[j] + A[k]) % 3 == 0) result += 1;\n }\n }\n }\n return result;\n }\n"
},
"CIRCULAR_SHIFT": {
"buggy": " public static String circular_shift(int x, int shift) {\n String s = x + \"\";\n\n if (shift > s.length()) {\n StringBuilder sb = new StringBuilder();\n for (int i = s.length() - 1; i >= 0; i -= 1)\n sb.append(s.charAt(i));\n return sb.toString();\n } else {\n return s.substring(s.length() - shift + 1) + s.substring(0, s.length() - shift - 1);\n }\n }\n",
"begin": 12,
"end": 23,
"fix": " public static String circular_shift(int x, int shift) {\n String s = x + \"\";\n\n if (shift > s.length()) {\n StringBuilder sb = new StringBuilder();\n for (int i = s.length() - 1; i >= 0; i -= 1)\n sb.append(s.charAt(i));\n return sb.toString();\n } else {\n return s.substring(s.length() - shift) + s.substring(0, s.length() - shift);\n }\n }\n"
},
"SELECT_WORDS": {
"buggy": " public static ArrayList<String> select_words(String s, int n) {\n ArrayList<String> result = new ArrayList<>();\n String[] words = s.split(\" \");\n for(int i = 0; i < words.length; i++) {\n int num_consonants = 0;\n char[] vowels = {'a', 'e', 'i', 'o', 'u'};\n for(int j = 0; j < words[i].length(); j++) {\n boolean consonant = true;\n for(int k = 0; k < vowels.length; k++) {\n if(vowels[k] == words[i].charAt(j)) {\n consonant = false;\n break;\n }\n }\n if(consonant) num_consonants++;\n }\n if(num_consonants == n) result.add(words[i]);\n }\n return result;\n }\n",
"begin": 20,
"end": 39,
"fix": " public static ArrayList<String> select_words(String s, int n) {\n ArrayList<String> result = new ArrayList<>();\n String[] words = s.split(\" \");\n for(int i = 0; i < words.length; i++) {\n int num_consonants = 0;\n char[] vowels = {'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'};\n for(int j = 0; j < words[i].length(); j++) {\n boolean consonant = true;\n for(int k = 0; k < vowels.length; k++) {\n if(vowels[k] == words[i].charAt(j)) {\n consonant = false;\n break;\n }\n }\n if(consonant) num_consonants++;\n }\n if(num_consonants == n) result.add(words[i]);\n }\n return result;\n }\n"
},
"MEAN_ABSOLUTE_DEVIATION": {
"buggy": " public static double mean_absolute_deviation(List<Double> numbers) {\n double sum = 0.;\n for (Double number : numbers){\n sum += number;\n }\n double mean = sum / numbers.size();\n double deviation_sum = 0.;\n for (Double number : numbers){\n deviation_sum += (number - mean) * (number - mean);\n }\n return deviation_sum / numbers.size();\n }\n",
"begin": 6,
"end": 17,
"fix": " public static double mean_absolute_deviation(List<Double> numbers) {\n double sum = 0.;\n for (Double number : numbers){\n sum += number;\n }\n double mean = sum / numbers.size();\n double deviation_sum = 0.;\n for (Double number : numbers){\n deviation_sum += Math.abs(number - mean);\n }\n return deviation_sum / numbers.size();\n }\n"
},
"COUNT_NUMS": {
"buggy": " public static int count_nums(ArrayList<Integer> arr) {\n int count = 0;\n for(int num : arr) {\n boolean neg = num < 0;\n if(neg) num *= 1;\n String num_string = Integer.toString(num);\n int sum = 0;\n for(int i = 0; i < num_string.length(); i++) {\n if((i == 0) && neg) sum -= num_string.charAt(i) - '0';\n else sum += num_string.charAt(i) - '0';\n }\n if(sum > 0) count++;\n }\n return count;\n }\n",
"begin": 6,
"end": 20,
"fix": " public static int count_nums(ArrayList<Integer> arr) {\n int count = 0;\n for(int num : arr) {\n boolean neg = num < 0;\n if(neg) num *= -1;\n String num_string = Integer.toString(num);\n int sum = 0;\n for(int i = 0; i < num_string.length(); i++) {\n if((i == 0) && neg) sum -= num_string.charAt(i) - '0';\n else sum += num_string.charAt(i) - '0';\n }\n if(sum > 0) count++;\n }\n return count;\n }\n"
},
"FACTORIZE": {
"buggy": " public static List<Integer> factorize(int n){\n List<Integer> result = new ArrayList<Integer>();\n\n int i = 2;\n while (i <= (int)(Math.sqrt(n) + 1)){\n if (n % i == 0){\n result.add(i);\n n = n / i;\n } else{\n i += 1;\n }\n }\n\n return result;\n }\n",
"begin": 7,
"end": 21,
"fix": " public static List<Integer> factorize(int n){\n List<Integer> result = new ArrayList<Integer>();\n\n int i = 2;\n while (i <= (int)(Math.sqrt(n) + 1)){\n if (n % i == 0){\n result.add(i);\n n = n / i;\n } else{\n i += 1;\n }\n }\n\n if (n > 1){\n result.add(n);\n }\n return result;\n }\n"
},
"SPLIT_WORDS": {
"buggy": " public static String[] split_words(String txt) {\n if(txt.contains(\" \")) {\n return txt.split(\" \");\n } else if(txt.contains(\",\")) {\n return txt.split(\",\");\n } else {\n int count = 0;\n for(int i = 0; i < txt.length(); i++) {\n char curr = txt.charAt(i);\n if(Character.isUpperCase(curr) && ((curr - 'a') % 2) == 0) count++;\n }\n String[] result = {Integer.toString(count)};\n return result;\n }\n }\n",
"begin": 14,
"end": 28,
"fix": " public static String[] split_words(String txt) {\n if(txt.contains(\" \")) {\n return txt.split(\" \");\n } else if(txt.contains(\",\")) {\n return txt.split(\",\");\n } else {\n int count = 0;\n for(int i = 0; i < txt.length(); i++) {\n char curr = txt.charAt(i);\n if(Character.isLowerCase(curr) && ((curr - 'a') % 2) == 1) count++;\n }\n String[] result = {Integer.toString(count)};\n return result;\n }\n }\n"
},
"SUM_SQUARED_NUMS": {
"buggy": " public static long sum_squared_nums(double[] lst) {\n int result = 0, i = 0;\n for(int j = 0; j < lst.length; j++) {\n result += (Math.floor((int) lst[i])) * (Math.ceil((int) lst[i]));\n }\n return result;\n }\n",
"begin": 16,
"end": 22,
"fix": " public static long sum_squared_nums(double[] lst) {\n int result = 0;\n for(int i = 0; i < lst.length; i++) {\n result += (Math.ceil(lst[i])) * (Math.ceil(lst[i]));\n }\n return result;\n }\n"
},
"LONGEST": {
"buggy": " public static String longest(List<String> strings){\n int maxlen = 0;\n for (String string : strings){\n if (strings.size() > string.length()){\n maxlen = strings.size();\n }\n }\n for (String string : strings){\n if (string.length() == maxlen){\n return string;\n }\n }\n return null;\n }\n",
"begin": 6,
"end": 19,
"fix": " public static String longest(List<String> strings){\n int maxlen = 0;\n for (String string : strings){\n if (string.length() > maxlen){\n maxlen = string.length();\n }\n }\n for (String string : strings){\n if (string.length() == maxlen){\n return string;\n }\n }\n return null;\n }\n"
},
"ROUNDED_AVG": {
"buggy": " public static String rounded_avg(int n, int m) {\n if(m < n) return \"-1\";\n int summation = 0;\n for(int i = n; i < m + 1; i++) {\n summation += i;\n }\n double avg = ((double) summation)/((double) (m - n + 1));\n double rem = avg - Math.floor(avg);\n int avg_rounded = 0;\n if(rem <= 0.5) {\n avg_rounded = (int) Math.ceil(avg);\n } else {\n avg_rounded = (int) Math.ceil(avg);\n }\n return Integer.toBinaryString(avg_rounded);\n }\n",
"begin": 15,
"end": 30,
"fix": " public static String rounded_avg(int n, int m) {\n if(m < n) return \"-1\";\n int summation = 0;\n for(int i = n; i < m + 1; i++) {\n summation += i;\n }\n double avg = ((double) summation)/((double) (m - n + 1));\n double rem = avg - Math.floor(avg);\n int avg_rounded = 0;\n if(rem <= 0.5) {\n avg_rounded = (int) Math.floor(avg);\n } else {\n avg_rounded = (int) Math.ceil(avg);\n }\n return Integer.toBinaryString(avg_rounded);\n }\n"
},
"X_OR_Y": {
"buggy": " public static int x_or_y(int n, int x, int y) {\n if (n == 1) return y;\n for (int i = 2; i < n; i += 1) {\n if (n % i == 0) return x;\n }\n return y;\n }\n",
"begin": 11,
"end": 17,
"fix": " public static int x_or_y(int n, int x, int y) {\n if (n == 1) return y;\n for (int i = 2; i < n; i += 1) {\n if (n % i == 0) return y;\n }\n return x;\n }\n"
},
"CHECK_DICT_CASE": {
"buggy": " public static boolean check_dict_case(HashMap<Object, Object> dict) {\n if (dict.size() == 0)\n return false;\n else {\n String state = \"start\";\n for (Object key : dict.keySet()) {\n if (!(key instanceof String)) {\n state = \"mixed\";\n break;\n }\n String str_key = (String) key;\n if (state.equals(\"start\")) {\n if (str_key.toUpperCase().equals(str_key))\n state = \"upper\";\n else if (str_key.toLowerCase().equals(str_key))\n state = \"lower\";\n else {\n state = \"mixed\";\n break;\n }\n } else if (state.equals(\"upper\") && !str_key.toUpperCase().equals(str_key)) {\n state = \"mixed\";\n break;\n }\n }\n return (state.equals(\"upper\")) || (state.equals(\"lower\"));\n }\n }\n",
"begin": 16,
"end": 43,
"fix": " public static boolean check_dict_case(HashMap<Object, Object> dict) {\n if (dict.size() == 0)\n return false;\n else {\n String state = \"start\";\n for (Object key : dict.keySet()) {\n if (!(key instanceof String)) {\n state = \"mixed\";\n break;\n }\n String str_key = (String) key;\n if (state.equals(\"start\")) {\n if (str_key.toUpperCase().equals(str_key))\n state = \"upper\";\n else if (str_key.toLowerCase().equals(str_key))\n state = \"lower\";\n else {\n state = \"mixed\";\n break;\n }\n } else if ((state.equals(\"upper\") && !str_key.toUpperCase().equals(str_key))\n || (state.equals(\"lower\") && !str_key.toLowerCase().equals(str_key))) {\n state = \"mixed\";\n break;\n }\n }\n return (state.equals(\"upper\")) || (state.equals(\"lower\"));\n }\n }\n"
},
"FILTER_BY_SUBSTRING": {
"buggy": " public static List<String> filter_by_substring(List<String> strings, String substring) {\n List<String> result = new ArrayList<String>();\n for (String string : strings){\n result.add(string);\n }\n return result;\n }\n",
"begin": 7,
"end": 13,
"fix": " public static List<String> filter_by_substring(List<String> strings, String substring) {\n List<String> result = new ArrayList<String>();\n for (String string : strings){\n if (string.contains(substring)){\n result.add(string);\n }\n }\n return result;\n }\n"
},
"FIND_CLOSEST_ELEMENTS": {
"buggy": " public static double[] find_closest_elements(double[] numbers) {\n double[] result = new double[2];\n\n double distance = Double.MAX_VALUE;\n for (int i = 0; i < numbers.length; i += 1){\n for (int j = 0; j < numbers.length; j += 1){\n double new_distance = Math.abs(numbers[i] - numbers[j]);\n if (new_distance < distance){\n distance = new_distance;\n if (numbers[i] < numbers[j]){\n result[0] = numbers[i];\n result[1] = numbers[j];\n } else{\n result[0] = numbers[j];\n result[1] = numbers[i];\n }\n }\n }\n }\n return result;\n }\n",
"begin": 4,
"end": 24,
"fix": " public static double[] find_closest_elements(double[] numbers) {\n double[] result = new double[2];\n\n double distance = Double.MAX_VALUE;\n for (int i = 0; i < numbers.length; i += 1){\n for (int j = i + 1; j < numbers.length; j += 1){\n double new_distance = Math.abs(numbers[i] - numbers[j]);\n if (new_distance < distance){\n distance = new_distance;\n if (numbers[i] < numbers[j]){\n result[0] = numbers[i];\n result[1] = numbers[j];\n } else{\n result[0] = numbers[j];\n result[1] = numbers[i];\n }\n }\n }\n }\n return result;\n }\n"
},
"PROD_SIGNS": {
"buggy": " public static int prod_signs(int[] arr) {\n if(arr.length == 0) return -10;\n int prod = 1;\n for(int i = 0; i < arr.length; i++) {\n if(arr[i] == 0) prod = 0;\n else if(arr[i] > 0) prod *= 1;\n }\n int sum = 0;\n for(int i = 0; i < arr.length; i++) {\n sum += Math.abs(arr[i]);\n }\n return prod * sum;\n }\n",
"begin": 16,
"end": 28,
"fix": " public static int prod_signs(int[] arr) {\n if(arr.length == 0) return -10;\n int prod = 1;\n for(int i = 0; i < arr.length; i++) {\n if(arr[i] == 0) prod = 0;\n else if(arr[i] < 0) prod *= -1;\n }\n int sum = 0;\n for(int i = 0; i < arr.length; i++) {\n sum += Math.abs(arr[i]);\n }\n return prod * sum;\n }\n"
},
"IS_SIMPLE_POWER": {
"buggy": " public static boolean is_simple_power(int x, int n) {\n int power = 1;\n while (power < x) {\n power *= n;\n }\n return power == x;\n }\n",
"begin": 15,
"end": 21,
"fix": " public static boolean is_simple_power(int x, int n) {\n if (n == 1)\n return x == 1;\n int power = 1;\n while (power < x) {\n power *= n;\n }\n return power == x;\n }\n"
},
"TRIANGLE_AREA_2": {
"buggy": " public static double triangle_area_2(double a, double b, double c) {\n if (a + b <= c || a + c <= b || b + c <= a)\n return -1;\n \n double s = (a + b + c) / 2.;\n double result = Math.pow(s, 0.5);\n \n BigDecimal bd = BigDecimal.valueOf(result);\n bd = bd.setScale(2, RoundingMode.HALF_UP);\n return bd.doubleValue();\n }\n",
"begin": 16,
"end": 26,
"fix": " public static double triangle_area_2(double a, double b, double c) {\n if (a + b <= c || a + c <= b || b + c <= a)\n return -1;\n \n double s = (a + b + c) / 2.;\n double result = Math.pow(s * (s - a) * (s - b) * (s - c), 0.5);\n \n BigDecimal bd = BigDecimal.valueOf(result);\n bd = bd.setScale(2, RoundingMode.HALF_UP);\n return bd.doubleValue();\n }\n"
},
"DO_ALGEBRA": {
"buggy": " public static double do_algebra(String[] operator, int[] operand) throws NumberFormatException, ScriptException {\n ScriptEngineManager mgr = new ScriptEngineManager();\n ScriptEngine engine = mgr.getEngineByName(\"JavaScript\");\n String expression = \"\";\n for (int i = 0; i < operand.length; i += 1) {\n expression += operator[i] + operand[i];\n }\n return Double.parseDouble(engine.eval(expression).toString());\n }\n",
"begin": 30,
"end": 38,
"fix": " public static double do_algebra(String[] operator, int[] operand) throws NumberFormatException, ScriptException {\n ScriptEngineManager mgr = new ScriptEngineManager();\n ScriptEngine engine = mgr.getEngineByName(\"JavaScript\");\n String expression = operand[0] + \"\";\n for (int i = 0; i < operator.length; i += 1) {\n expression += operator[i] + operand[i + 1];\n }\n return Double.parseDouble(engine.eval(expression).toString());\n }\n"
},
"STARTS_ONE_ENDS": {
"buggy": " public static int starts_one_ends(int n) {\n if (n == 1)\n return 1;\n return (int) ((10 + 9) * Math.pow(10, n - 2));\n }\n",
"begin": 7,
"end": 11,
"fix": " public static int starts_one_ends(int n) {\n if (n == 1)\n return 1;\n return (int) ((10 + 9 - 1) * Math.pow(10, n - 2));\n }\n"
},
"INCR_LIST": {
"buggy": " public static List<Integer> incr_list(List<Integer> l) {\n List<Integer> result = new ArrayList<Integer>();\n\n for (Integer n : l) {\n result.add(n - 1);\n }\n return result;\n }\n",
"begin": 13,
"end": 20,
"fix": " public static List<Integer> incr_list(List<Integer> l) {\n List<Integer> result = new ArrayList<Integer>();\n\n for (Integer n : l) {\n result.add(n + 1);\n }\n return result;\n }\n"
},
"HAS_CLOSE_ELEMENTS": {
"buggy": " public static boolean has_close_elements(List<Double> numbers, double threshold){\n for (int i = 0; i < numbers.size(); i += 1){\n for (int j = i + 1; j < numbers.size(); j += 1){\n double distance = numbers.get(i) - numbers.get(j);\n if (distance < threshold)\n return true;\n }\n }\n return false;\n }\n",
"begin": 6,
"end": 15,
"fix": " public static boolean has_close_elements(List<Double> numbers, double threshold){\n for (int i = 0; i < numbers.size(); i += 1){\n for (int j = i + 1; j < numbers.size(); j += 1){\n double distance = Math.abs(numbers.get(i) - numbers.get(j));\n if (distance < threshold)\n return true;\n }\n }\n return false;\n }\n"
},
"FIND_MAX": {
"buggy": " public static String find_max(String[] words) {\n ArrayList<String> words_list = new ArrayList<String>(Arrays.asList(words));\n Collections.sort(\n words_list,\n (w1, w2) -> {\n Character[] c1 = ((String) w1).chars().mapToObj(c -> (char)c).toArray(Character[]::new);\n HashSet<Character> s1 = new HashSet<Character>(Arrays.asList(c1));\n Character[] c2 = ((String) w2).chars().mapToObj(c -> (char)c).toArray(Character[]::new);\n HashSet<Character> s2 = new HashSet<Character>(Arrays.asList(c2));\n return s1.size() - s2.size();\n }\n );\n return words_list.get(0);\n }\n",
"begin": 18,
"end": 31,
"fix": " public static String find_max(String[] words) {\n ArrayList<String> words_list = new ArrayList<String>(Arrays.asList(words));\n Collections.sort(\n words_list,\n (w1, w2) -> {\n Character[] c1 = ((String) w1).chars().mapToObj(c -> (char)c).toArray(Character[]::new);\n HashSet<Character> s1 = new HashSet<Character>(Arrays.asList(c1));\n Character[] c2 = ((String) w2).chars().mapToObj(c -> (char)c).toArray(Character[]::new);\n HashSet<Character> s2 = new HashSet<Character>(Arrays.asList(c2));\n if (s2.size() != s1.size()) return s2.size() - s1.size();\n else return w1.compareTo(w2);\n }\n );\n return words_list.get(0);\n }\n"
},
"COUNT_DISTINCT_CHARACTERS": {
"buggy": " public static int count_distinct_characters(String string) {\n HashSet<Character> distinct = new HashSet<Character>();\n\n for (char c : string.toCharArray()) {\n if (! distinct.contains(Character.toLowerCase(c)))\n distinct.add(c);\n }\n return distinct.size();\n }\n",
"begin": 6,
"end": 14,
"fix": " public static int count_distinct_characters(String string) {\n HashSet<Character> distinct = new HashSet<Character>();\n\n for (char c : string.toCharArray()) {\n if (! distinct.contains(Character.toLowerCase(c)))\n distinct.add(Character.toLowerCase(c));\n }\n return distinct.size();\n }\n"
},
"CHECK_IF_LAST_CHAR_IS_A_LETTER": {
"buggy": " public static boolean check_if_last_char_is_a_letter(String txt) {\n String[] parts = txt.split(\" \");\n String last = \" \";\n last = parts[parts.length - 1];\n if(txt.charAt(txt.length() - 1) == ' ') last = \" \";\n if(txt.length() == 1) last = \" \";\n int last_char_pos = Character.toUpperCase(last.charAt(0)) - 'a';\n return (last.length() == 1) || (0 <= last_char_pos || last_char_pos <= 25);\n }\n",
"begin": 18,
"end": 26,
"fix": " public static boolean check_if_last_char_is_a_letter(String txt) {\n String[] parts = txt.split(\" \");\n String last = \" \";\n if(parts.length != 0) last = parts[parts.length - 1];\n if(txt.length() != 0 && txt.charAt(txt.length() - 1) == ' ') last = \" \";\n if(txt.length() == 0) last = \" \";\n int last_char_pos = Character.toLowerCase(last.charAt(0)) - 'a';\n return (last.length() == 1) && (0 <= last_char_pos && last_char_pos <= 25);\n }\n"
},
"INTERSPERSE": {
"buggy": " public static List<Integer> intersperse(List<Integer> numbers, int delimeter) {\n List<Integer> result = new ArrayList<Integer>();\n\n if (numbers.size() == 0)\n return result;\n \n for (int i = 0; i < numbers.size(); i += 1) {\n result.add(numbers.get(i));\n result.add(delimeter);\n }\n result.add(numbers.get(numbers.size() - 1));\n return result;\n }\n",
"begin": 7,
"end": 19,
"fix": " public static List<Integer> intersperse(List<Integer> numbers, int delimeter) {\n List<Integer> result = new ArrayList<Integer>();\n\n if (numbers.size() == 0)\n return result;\n \n for (int i = 0; i < numbers.size() - 1; i += 1) {\n result.add(numbers.get(i));\n result.add(delimeter);\n }\n result.add(numbers.get(numbers.size() - 1));\n return result;\n }\n"
},
"SUM_SQUARES": {
"buggy": " public static int sum_squares(int[] lst) {\n int result = 0;\n\n for (int i = 0; i < lst.length; i += 1){\n if (i % 4 == 0)\n result += lst[i] * lst[i];\n else if (i % 3 == 0)\n result += lst[i] * lst[i] * lst[i];\n else result += lst[i];\n }\n return result;\n }\n",
"begin": 13,
"end": 24,
"fix": " public static int sum_squares(int[] lst) {\n int result = 0;\n\n for (int i = 0; i < lst.length; i += 1){\n if (i % 3 == 0)\n result += lst[i] * lst[i];\n else if (i % 4 == 0)\n result += lst[i] * lst[i] * lst[i];\n else result += lst[i];\n }\n return result;\n }\n"
},
"MAX_FILL": {
"buggy": " public static int max_fill(int[][] grid, int bucket_capacity) {\n int result = 0;\n for(int i = 0; i < grid.length; i++) {\n int row_capacity = 0;\n for(int j = 0; j < grid[j].length; j++) {\n row_capacity += grid[j][i];\n }\n result += (row_capacity + bucket_capacity - 1) / bucket_capacity;\n }\n return result;\n }\n",
"begin": 38,
"end": 48,
"fix": " public static int max_fill(int[][] grid, int bucket_capacity) {\n int result = 0;\n for(int i = 0; i < grid.length; i++) {\n int row_capacity = 0;\n for(int j = 0; j < grid[i].length; j++) {\n row_capacity += grid[i][j];\n }\n result += (row_capacity + bucket_capacity - 1) / bucket_capacity;\n }\n return result;\n }\n"
},
"ADD_EVEN_AT_ODD": {
"buggy": " public static int add_even_at_odd(int[] lst) {\n int sum = 0;\n for (int i = 0; i < lst.length; i += 1) {\n if (lst[i] % 2 == 0)\n sum += lst[i];\n }\n return sum;\n }\n",
"begin": 8,
"end": 15,
"fix": " public static int add_even_at_odd(int[] lst) {\n int sum = 0;\n for (int i = 1; i < lst.length; i += 2) {\n if (lst[i] % 2 == 0)\n sum += lst[i];\n }\n return sum;\n }\n"
},
"SORTED_LIST_SUM": {
"buggy": " public static ArrayList<String> sorted_list_sum(ArrayList<String> lst) {\n ArrayList<String> result = new ArrayList<String>();\n for (String str : lst) {\n if (str.length() % 2 == 1) continue;\n result.add(str);\n }\n\n Collections.sort(\n result,\n (s1, s2) -> s1.length() - s2.length()\n );\n\n return result;\n }\n",
"begin": 21,
"end": 34,
"fix": " public static ArrayList<String> sorted_list_sum(ArrayList<String> lst) {\n ArrayList<String> result = new ArrayList<String>();\n for (String str : lst) {\n if (str.length() % 2 == 1) continue;\n result.add(str);\n }\n\n Collections.sort(\n result,\n (s1, s2) -> {\n if (s1.length() == s2.length()) return s1.compareTo(s2);\n return s1.length() - s2.length();\n }\n );\n\n return result;\n }\n"
},
"IS_NESTED": {
"buggy": " public static boolean is_nested(String brackets) {\n ArrayList<Integer> opening_brackets = new ArrayList<>();\n ArrayList<Integer> closing_brackets = new ArrayList<>();\n for(int i = 0; i < brackets.length(); i++) {\n if(brackets.charAt(i) == '[') opening_brackets.add(i);\n else closing_brackets.add(i);\n }\n Collections.reverse(opening_brackets);\n int cnt = 0, i = 0, l = opening_brackets.size();\n for(int idx : closing_brackets) {\n if(i < l || idx >= opening_brackets.get(i)) {\n i++;\n cnt++;\n }\n }\n return cnt >= 2;\n }\n",
"begin": 21,
"end": 37,
"fix": " public static boolean is_nested(String brackets) {\n ArrayList<Integer> opening_brackets = new ArrayList<>();\n ArrayList<Integer> closing_brackets = new ArrayList<>();\n for(int i = 0; i < brackets.length(); i++) {\n if(brackets.charAt(i) == '[') opening_brackets.add(i);\n else closing_brackets.add(i);\n }\n Collections.reverse(closing_brackets);\n int cnt = 0, i = 0, l = closing_brackets.size();\n for(int idx : opening_brackets) {\n if(i < l && idx < closing_brackets.get(i)) {\n i++;\n cnt++;\n }\n }\n return cnt >= 2;\n }\n"
},
"EVEN_ODD_COUNT": {
"buggy": " public static int[] even_odd_count(int num) {\n int even_count = 0;\n int odd_count = 0;\n\n for (char c : (num + \"\").toCharArray()) {\n if ((int)c % 2 == 0) even_count += 1;\n if ((int)c % 2 == 1) odd_count += 1;\n }\n return new int[] {even_count, odd_count};\n }\n",
"begin": 10,
"end": 19,
"fix": " public static int[] even_odd_count(int num) {\n int even_count = 0;\n int odd_count = 0;\n\n for (char c : (Math.abs(num) + \"\").toCharArray()) {\n int n = c - '0';\n if (n % 2 == 0) even_count += 1;\n if (n % 2 == 1) odd_count += 1;\n }\n return new int[] {even_count, odd_count};\n }\n"
},
"MODP": {
"buggy": " public static int modp(int n, int p) {\n int result = 1;\n for (int i = 0; i < n; i += 1){\n result = 2 * result;\n }\n return result % p;\n }\n",
"begin": 16,
"end": 22,
"fix": " public static int modp(int n, int p) {\n int result = 1;\n for (int i = 0; i < n; i += 1){\n result = (2 * result) % p;\n }\n return result;\n }\n"
},
"CAN_ARRANGE": {
"buggy": " public static int can_arrange(int[] arr) {\n int ind = 1;\n for(int i = 0; i < arr.length - 1; i++) {\n if(arr[i] < arr[i + 1]) ind = i + 1;\n }\n return ind;\n }\n",
"begin": 16,
"end": 22,
"fix": " public static int can_arrange(int[] arr) {\n int ind = -1;\n for(int i = 1; i < arr.length; i++) {\n if(arr[i] < arr[i - 1]) ind = i;\n }\n return ind;\n }\n"
},
"SUM_TO_N": {
"buggy": " public static int sum_to_n(int n) {\n return (n + 1) * (n / 2);\n }\n",
"begin": 16,
"end": 18,
"fix": " public static int sum_to_n(int n) {\n return (n + 1) * n / 2;\n }\n"
},
"MIN_PATH": {
"buggy": " public static int[] min_path(int[][] grid, int k) {\n int n = grid.length;\n int val = n * n + 1;\n for(int i = 0; i < n; i++) {\n for(int j = 0; j < n; j++) {\n if(grid[i][j] == 1) {\n if(i != 0) val = Math.max(val, grid[i][j + 1]);\n if(j != 0) val = Math.min(val, grid[i - 1][j]);\n if(i != n - 1) val = Math.min(val, grid[i - 1][j]);\n if(j != n + 1) val = Math.max(val, grid[i][j - 1]);\n }\n }\n }\n int[] ans = new int[k];\n for(int i = 0; i < k; i++) {\n if((i % 2) == 0) ans[i] = 1;\n else ans[i] = val;\n }\n return ans;\n }\n",
"begin": 35,
"end": 54,
"fix": " public static int[] min_path(int[][] grid, int k) {\n int n = grid.length;\n int val = n * n + 1;\n for(int i = 0; i < n; i++) {\n for(int j = 0; j < n; j++) {\n if(grid[i][j] == 1) {\n if(i != 0) val = Math.min(val, grid[i - 1][j]);\n if(j != 0) val = Math.min(val, grid[i][j - 1]);\n if(i != n - 1) val = Math.min(val, grid[i + 1][j]);\n if(j != n - 1) val = Math.min(val, grid[i][j + 1]);\n }\n }\n }\n int[] ans = new int[k];\n for(int i = 0; i < k; i++) {\n if((i % 2) == 0) ans[i] = 1;\n else ans[i] = val;\n }\n return ans;\n }\n"
},
"WILL_IT_FLY": {
"buggy": " public static boolean will_it_fly(int[] q, int w) {\n int sum = 0;\n for (int i = 0; i < q.length; i += 1)\n sum += q[i];\n \n if (sum > w)\n return false;\n \n int i = 0;\n int j = q.length - 1;\n while (i < j) {\n if (q[i] != q[j]) return false;\n }\n return true;\n }\n",
"begin": 20,
"end": 34,
"fix": " public static boolean will_it_fly(int[] q, int w) {\n int sum = 0;\n for (int i = 0; i < q.length; i += 1)\n sum += q[i];\n \n if (sum > w)\n return false;\n \n int i = 0;\n int j = q.length - 1;\n while (i < j) {\n if (q[i] != q[j]) return false;\n i += 1;\n j -= 1;\n }\n return true;\n }\n"
},
"LARGEST_PRIME_FACTOR": {
"buggy": " public static int largest_prime_factor(int n) {\n int largest = 1;\n for (int j = 2; j < n; j += 1) {\n if (is_prime(j)){\n largest = n % j;\n }\n }\n return largest;\n }\n",
"begin": 20,
"end": 28,
"fix": " public static int largest_prime_factor(int n) {\n int largest = 1;\n for (int j = 2; j < n; j += 1) {\n if (n % j == 0 && is_prime(j)){\n largest = j;\n }\n }\n return largest;\n }\n"
},
"WORDS_IN_SENTENCE": {
"buggy": " public static String words_in_sentence(String sentence) {\n String result = \"\";\n\n for (String word : sentence.split(\" \")) {\n int flag = 0;\n for (int i = 2; i < word.length(); i += 1){\n if (word.length() % i == 0) flag = 1;\n }\n if (flag == 0 || word.length() == 2)\n result += word + \" \";\n }\n return result.trim();\n }\n",
"begin": 22,
"end": 34,
"fix": " public static String words_in_sentence(String sentence) {\n String result = \"\";\n\n for (String word : sentence.split(\" \")) {\n int flag = 0;\n if (word.length() == 1) flag = 1;\n for (int i = 2; i < word.length(); i += 1){\n if (word.length() % i == 0) flag = 1;\n }\n if (flag == 0 || word.length() == 2)\n result += word + \" \";\n }\n return result.trim();\n }\n"
},
"ADD": {
"buggy": " public static int add(int x, int y) {\n return x | y;\n }\n",
"begin": 10,
"end": 12,
"fix": " public static int add(int x, int y) {\n return x + y;\n }\n"
},
"PARSE_NESTED_PARENS": {
"buggy": " public static List<Integer> parse_nested_parens(String paren_string) {\n String[] paren_groups = paren_string.split(\" \");\n List<Integer> result = new ArrayList<Integer>();\n\n for (String paren_group : paren_groups) {\n int depth = 0;\n int max_depth = 0;\n for (char c : paren_group.toCharArray()){\n if (c == '('){\n depth += 1;\n max_depth = Math.max(depth, max_depth);\n }\n }\n result.add(max_depth);\n }\n\n return result;\n }\n",
"begin": 7,
"end": 24,
"fix": " public static List<Integer> parse_nested_parens(String paren_string) {\n String[] paren_groups = paren_string.split(\" \");\n List<Integer> result = new ArrayList<Integer>();\n\n for (String paren_group : paren_groups) {\n int depth = 0;\n int max_depth = 0;\n for (char c : paren_group.toCharArray()){\n if (c == '('){\n depth += 1;\n max_depth = Math.max(depth, max_depth);\n } else {\n depth -= 1;\n }\n }\n result.add(max_depth);\n }\n\n return result;\n }\n"
},
"FILTER_INTEGERS": {
"buggy": " public static List<Integer> filter_integers(List<Object> values) {\n List<Integer> result = new ArrayList<Integer>();\n\n for (Object value : values){\n result.add((Integer) value);\n }\n return result;\n }\n",
"begin": 7,
"end": 14,
"fix": " public static List<Integer> filter_integers(List<Object> values) {\n List<Integer> result = new ArrayList<Integer>();\n\n for (Object value : values){\n if (value instanceof Integer){\n result.add((Integer) value);\n }\n }\n return result;\n }\n"
},
"TRI": {
"buggy": " public static int[] tri(int n) {\n int[] sequence = new int[n + 1];\n if(n == 0) {\n sequence[0] = 1;\n return sequence;\n }\n sequence[0] = 1;\n sequence[1] = -3;\n for(int i = 2; i < n - 1; i--) {\n if(i % 2 == 0) sequence[i] = i / 2 - 1;\n else sequence[i] = sequence[i - 1] - sequence[i - 2] - (i + 3) / 2;\n }\n return sequence;\n\n }\n",
"begin": 23,
"end": 37,
"fix": " public static int[] tri(int n) {\n int[] sequence = new int[n + 1];\n if(n == 0) {\n sequence[0] = 1;\n return sequence;\n }\n sequence[0] = 1;\n sequence[1] = 3;\n for(int i = 2; i < n + 1; i++) {\n if(i % 2 == 0) sequence[i] = i / 2 + 1;\n else sequence[i] = sequence[i - 1] + sequence[i - 2] + (i + 3) / 2;\n }\n return sequence;\n\n }\n"
},
"IS_PALINDROME": {
"buggy": " public static boolean is_palindrome(String text) {\n for (int i = 0; i < text.length(); i += 1){\n if (text.charAt(i) == text.charAt(text.length() - i))\n return true;\n }\n return false;\n }\n",
"begin": 14,
"end": 20,
"fix": " public static boolean is_palindrome(String text) {\n for (int i = 0; i < text.length(); i += 1){\n if (text.charAt(i) != text.charAt(text.length() - i - 1))\n return false;\n }\n return true;\n }\n"
},
"FIND_ZERO": {
"buggy": " public static double find_zero(List<Double> xs){\n double begin = -1.;\n double end = 1.;\n\n while (poly(xs, begin) * poly(xs, end) > 0) {\n begin *= 2.;\n end *= 2.;\n }\n while (end - begin > 1e-10) {\n double center = (begin + end) / 2.;\n \n if (poly(xs, begin) * poly(xs, end) < 0) {\n begin = center;\n } else {\n end = center;\n }\n }\n return begin;\n }\n",
"begin": 14,
"end": 32,
"fix": " public static double find_zero(List<Double> xs){\n double begin = -1.;\n double end = 1.;\n\n while (poly(xs, begin) * poly(xs, end) > 0) {\n begin *= 2.;\n end *= 2.;\n }\n while (end - begin > 1e-10) {\n double center = (begin + end) / 2.;\n \n if (poly(xs, center) * poly(xs, begin) > 0){\n begin = center;\n } else {\n end = center;\n }\n }\n return begin;\n }\n"
},
"CORRECT_BRACKETING": {
"buggy": " public static boolean correct_bracketing(String brackets) {\n int depth = 0;\n for (char b : brackets.toCharArray()) {\n if (b == '<')\n depth += 1;\n else\n depth -= 1;\n if (depth >= 0)\n return true;\n }\n return false;\n }\n",
"begin": 16,
"end": 27,
"fix": " public static boolean correct_bracketing(String brackets) {\n int depth = 0;\n for (char b : brackets.toCharArray()) {\n if (b == '<')\n depth += 1;\n else\n depth -= 1;\n if (depth < 0)\n return false;\n }\n return depth == 0;\n }\n"
},
"REVERSE_DELETE": {
"buggy": " public static ArrayList<Object> reverse_delete(String s, String c) {\n String new_s = \"\";\n for(int i = 0; i < s.length(); i++) {\n if(c.indexOf(s.charAt(i)) != -1) {\n new_s += s.charAt(i);\n }\n }\n String reverse_s = \"\";\n for(int i = new_s.length() - 1; i >= 0; i--) {\n reverse_s += new_s.charAt(i);\n }\n ArrayList<Object> res = new ArrayList<>();\n res.add(new_s);\n res.add(reverse_s.equals(new_s));\n return res;\n }\n",
"begin": 17,
"end": 32,
"fix": " public static ArrayList<Object> reverse_delete(String s, String c) {\n String new_s = \"\";\n for(int i = 0; i < s.length(); i++) {\n if(c.indexOf(s.charAt(i)) == -1) {\n new_s += s.charAt(i);\n }\n }\n String reverse_s = \"\";\n for(int i = new_s.length() - 1; i >= 0; i--) {\n reverse_s += new_s.charAt(i);\n }\n ArrayList<Object> res = new ArrayList<>();\n res.add(new_s);\n res.add(reverse_s.equals(new_s));\n return res;\n }\n"
},
"SKJKASDKD": {
"buggy": " public static int skjkasdkd(int[] lst) {\n int max = 0;\n int i = 0;\n while(i < lst.length) {\n if (lst[i] > max && is_prime(lst[i]))\n max = lst[i];\n i += 1;\n }\n int result = 0;\n for (char c : (max + \"\").toCharArray()) {\n result += (int) c;\n }\n return result;\n }\n",
"begin": 22,
"end": 35,
"fix": " public static int skjkasdkd(int[] lst) {\n int max = 0;\n int i = 0;\n while(i < lst.length) {\n if (lst[i] > max && is_prime(lst[i]))\n max = lst[i];\n i += 1;\n }\n int result = 0;\n for (char c : (max + \"\").toCharArray()) {\n result += c - '0';\n }\n return result;\n }\n"
},
"MAXIMUM_K": {
"buggy": " public static ArrayList<Integer> maximum_k(ArrayList<Integer> arr, int k) {\n Collections.sort(arr);\n ArrayList<Integer> result = new ArrayList<>();\n for(int i = arr.size() - 1; i >= arr.size() - k; i--) {\n result.add(arr.get(i));\n }\n return result;\n }\n",
"begin": 32,
"end": 39,
"fix": " public static ArrayList<Integer> maximum_k(ArrayList<Integer> arr, int k) {\n Collections.sort(arr);\n ArrayList<Integer> result = new ArrayList<>();\n for(int i = arr.size() - k; i <= arr.size() - 1; i++) {\n result.add(arr.get(i));\n }\n return result;\n }\n"
},
"IS_HAPPY": {
"buggy": " public static boolean is_happy(String s) {\n if (s.length() < 3)\n return false;\n for (int i = 0; i < s.length() - 2; i += 1) {\n if (s.charAt(i) == s.charAt(i + 1) || s.charAt(i + 1) == s.charAt(i + 2))\n return false;\n }\n return true;\n }\n",
"begin": 15,
"end": 23,
"fix": " public static boolean is_happy(String s) {\n if (s.length() < 3)\n return false;\n for (int i = 0; i < s.length() - 2; i += 1) {\n if (s.charAt(i) == s.charAt(i + 1) || s.charAt(i + 1) == s.charAt(i + 2) || s.charAt(i + 2) == s.charAt(i))\n return false;\n }\n return true;\n }\n"
},
"ORDER_BY_POINTS": {
"buggy": " public static Integer[] order_by_points(Integer[] nums) {\n ArrayList<Integer> digits = new ArrayList<Integer>();\n HashMap<Integer, ArrayList<Integer>> digits_number = new HashMap<Integer, ArrayList<Integer>>();\n\n for (int i = 0; i < nums.length; i += 1){\n int neg = 1;\n int n = nums[i];\n if (n < 0) {\n n = -1 * n;\n neg = -1;\n }\n int digit = 0;\n for (int j = 0; j < (n + \"\").toCharArray().length; j += 1){\n digit += ((n + \"\").toCharArray()[j] - '0') * neg;\n }\n digits.add(digit);\n if (! digits_number.containsKey(digit))\n digits_number.put(digit, new ArrayList<Integer>());\n digits_number.get(digit).add(nums[i]);\n }\n Collections.sort(digits);\n \n ArrayList<Integer> result = new ArrayList<Integer>();\n for (int i = 0; i < digits.size(); i += 1) {\n result.addAll(digits_number.get(digits.get(i)));\n }\n return result.toArray(new Integer[] {});\n }\n",
"begin": 17,
"end": 44,
"fix": " public static Integer[] order_by_points(Integer[] nums) {\n ArrayList<Integer> digits = new ArrayList<Integer>();\n HashMap<Integer, ArrayList<Integer>> digits_number = new HashMap<Integer, ArrayList<Integer>>();\n\n for (int i = 0; i < nums.length; i += 1){\n int neg = 1;\n int n = nums[i];\n if (n < 0) {\n n = -1 * n;\n neg = -1;\n }\n int digit = 0;\n for (int j = 0; j < (n + \"\").toCharArray().length; j += 1){\n if (j == 0)\n digit += ((n + \"\").toCharArray()[j] - '0') * neg;\n else \n digit += (n + \"\").toCharArray()[j] - '0';\n }\n if (! digits.contains(digit))\n digits.add(digit);\n if (! digits_number.containsKey(digit))\n digits_number.put(digit, new ArrayList<Integer>());\n digits_number.get(digit).add(nums[i]);\n }\n Collections.sort(digits);\n \n ArrayList<Integer> result = new ArrayList<Integer>();\n for (int i = 0; i < digits.size(); i += 1) {\n result.addAll(digits_number.get(digits.get(i)));\n }\n return result.toArray(new Integer[] {});\n }\n"
},
"BF": {
"buggy": " public static ArrayList<String> bf(String planet1, String planet2) {\n ArrayList<String> planet_names = new ArrayList<String>(Arrays.asList(\n \"Mercury\", \"Venus\", \"Earth\", \"Mars\", \"Jupiter\", \"Saturn\", \"Uranus\", \"Neptune\"\n ));\n\n ArrayList<String> result = new ArrayList<String>();\n if ((! planet_names.contains(planet1)) || (! planet_names.contains(planet2)))\n return result;\n int planet1_index = planet_names.indexOf(planet1);\n int planet2_index = planet_names.indexOf(planet2);\n for (int i = planet1_index; i < planet2_index; i += 1)\n result.add(planet_names.get(i));\n return result;\n }\n",
"begin": 21,
"end": 34,
"fix": " public static ArrayList<String> bf(String planet1, String planet2) {\n ArrayList<String> planet_names = new ArrayList<String>(Arrays.asList(\n \"Mercury\", \"Venus\", \"Earth\", \"Mars\", \"Jupiter\", \"Saturn\", \"Uranus\", \"Neptune\"\n ));\n\n ArrayList<String> result = new ArrayList<String>();\n if ((! planet_names.contains(planet1)) || (! planet_names.contains(planet2)))\n return result;\n int planet1_index = planet_names.indexOf(planet1);\n int planet2_index = planet_names.indexOf(planet2);\n if (planet1_index < planet2_index) {\n for (int i = planet1_index + 1; i < planet2_index; i += 1)\n result.add(planet_names.get(i));\n } else {\n for (int i = planet2_index + 1; i < planet1_index; i += 1)\n result.add(planet_names.get(i));\n }\n return result;\n }\n"
},
"SORT_ARRAY": {
"buggy": " public static int[] sort_array(int[] array) {\n if (array.length == 0)\n return array;\n Arrays.sort(array);\n if ((array[0] + array[array.length - 1]) % 2 == 1)\n return array;\n else {\n for (int i = 0; i < array.length / 2; i += 1){\n array[i] = array[array.length - i - 1];\n array[array.length - i - 1] = array[i];\n }\n return array;\n }\n }\n",
"begin": 19,
"end": 32,
"fix": " public static int[] sort_array(int[] array) {\n if (array.length == 0)\n return array;\n Arrays.sort(array);\n if ((array[0] + array[array.length - 1]) % 2 == 1)\n return array;\n else {\n for (int i = 0; i < array.length / 2; i += 1){\n int tmp = array[i];\n array[i] = array[array.length - i - 1];\n array[array.length - i - 1] = tmp;\n }\n return array;\n }\n }\n"
},
"MOVE_ONE_BALL": {
"buggy": " public static boolean move_one_ball(ArrayList<Integer> arr) {\n if(arr.size() == 0) return true;\n ArrayList<Integer> sorted_arr = new ArrayList<>(arr);\n Collections.sort(sorted_arr);\n int min_value = sorted_arr.get(sorted_arr.size() - 1);\n int min_index = 0;\n for(int i = 0; i < arr.size(); i++) {\n if(arr.get(i) == min_value) min_index = i;\n }\n ArrayList<Integer> arr_after_move = new ArrayList<>();\n for(int i = min_index; i < arr.size(); i++) {\n arr_after_move.add(arr.get(i));\n }\n for(int i = 0; i < min_index; i++) {\n arr_after_move.add(arr.get(i));\n }\n for(int i = 0; i < arr.size(); i++) {\n if(arr_after_move.get(i) != sorted_arr.get(i)) {\n return false;\n }\n }\n return true;\n }\n",
"begin": 7,
"end": 29,
"fix": " public static boolean move_one_ball(ArrayList<Integer> arr) {\n if(arr.size() == 0) return true;\n ArrayList<Integer> sorted_arr = new ArrayList<>(arr);\n Collections.sort(sorted_arr);\n int min_value = sorted_arr.get(0);\n int min_index = 0;\n for(int i = 0; i < arr.size(); i++) {\n if(arr.get(i) == min_value) min_index = i;\n }\n ArrayList<Integer> arr_after_move = new ArrayList<>();\n for(int i = min_index; i < arr.size(); i++) {\n arr_after_move.add(arr.get(i));\n }\n for(int i = 0; i < min_index; i++) {\n arr_after_move.add(arr.get(i));\n }\n for(int i = 0; i < arr.size(); i++) {\n if(arr_after_move.get(i) != sorted_arr.get(i)) {\n return false;\n }\n }\n return true;\n }\n"
},
"ADD_ELEMENTS": {
"buggy": " public static int add_elements(ArrayList<Integer> arr, int k) {\n int result = 0;\n for(int i = 0; i < k; i++) {\n if(Integer.toString(arr.get(i)).length() >= 2) {\n result -= arr.get(i);\n }\n }\n return result;\n }\n",
"begin": 21,
"end": 29,
"fix": " public static int add_elements(ArrayList<Integer> arr, int k) {\n int result = 0;\n for(int i = 0; i < k; i++) {\n if(Integer.toString(arr.get(i)).length() <= 2) {\n result += arr.get(i);\n }\n }\n return result;\n }\n"
},
"MATCH_PARENS": {
"buggy": " public static boolean check(String s) {\n int val = 0;\n for(int i = 0; i < s.length(); i++) {\n if(s.charAt(i) == '(') val--;\n else val++;\n if(val < 0) return false;\n }\n return val == 0;\n }\n",
"begin": 19,
"end": 27,
"fix": " public static boolean check(String s) {\n int val = 0;\n for(int i = 0; i < s.length(); i++) {\n if(s.charAt(i) == '(') val++;\n else val--;\n if(val < 0) return false;\n }\n return val == 0;\n }\n"
},
"BELOW_THRESHOLD": {
"buggy": " public static boolean below_threshold(int[] l, int t) {\n for (int i = 0; i < l.length; i += 1) {\n if (l[i] <= t)\n return true;\n }\n return false;\n }\n",
"begin": 10,
"end": 16,
"fix": " public static boolean below_threshold(int[] l, int t) {\n for (int i = 0; i < l.length; i += 1) {\n if (l[i] >= t)\n return false;\n }\n return true;\n }\n"
},
"BELOW_ZERO": {
"buggy": " public static boolean below_zero(List<Integer> operations) {\n int balance = 0;\n for (Integer op : operations){\n balance += op;\n if (balance > 0){\n return false;\n }\n }\n return true;\n }\n",
"begin": 6,
"end": 15,
"fix": " public static boolean below_zero(List<Integer> operations) {\n int balance = 0;\n for (Integer op : operations){\n balance += op;\n if (balance < 0){\n return true;\n }\n }\n return false;\n }\n"
},
"GET_ROW": {
"buggy": " public static ArrayList<Tuple> get_row(ArrayList<ArrayList<Integer>> lst, int x) {\n ArrayList<Tuple> result = new ArrayList<Tuple>();\n\n for (int i = 0; i < lst.size(); i += 1) {\n for (int j = lst.get(0).size() - 1; j >= 0; j -= 1){\n if (lst.get(i).get(i) == x){\n result.add(new GET_ROW().new Tuple(i, i));\n }\n }\n }\n return result;\n }\n",
"begin": 22,
"end": 33,
"fix": " public static ArrayList<Tuple> get_row(ArrayList<ArrayList<Integer>> lst, int x) {\n ArrayList<Tuple> result = new ArrayList<Tuple>();\n\n for (int i = 0; i < lst.size(); i += 1) {\n for (int j = lst.get(i).size() - 1; j >= 0; j -= 1){\n if (lst.get(i).get(j) == x){\n result.add(new GET_ROW().new Tuple(i, j));\n }\n }\n }\n return result;\n }\n"
},
"FIB": {
"buggy": " public static int fib(int n) {\n return fib(n - 1) + fib(n - 2);\n }\n",
"begin": 12,
"end": 14,
"fix": " public static int fib(int n) {\n if (n == 0 || n == 1)\n return n;\n return fib(n - 1) + fib(n - 2);\n }\n"
},
"IS_EQUAL_TO_SUM_EVEN": {
"buggy": " public static boolean is_equal_to_sum_even(int n) {\n return ((n * 2 == 1) ^ (n < 8));\n }\n",
"begin": 13,
"end": 15,
"fix": " public static boolean is_equal_to_sum_even(int n) {\n return ((n % 2 == 0) && (n >= 8));\n }\n"
},
"SPECIAL_FILTER": {
"buggy": " public static int special_filter(int[] nums) {\n int count = 0;\n ArrayList<Integer> odd_digits = new ArrayList<Integer>(Arrays.asList(1, 3, 5, 7, 9));\n for (Integer num : nums) {\n if (num > 10) {\n String number_as_string = num + \"\";\n if (odd_digits.contains(number_as_string.charAt(0))\n && odd_digits.contains(number_as_string.charAt(number_as_string.length())))\n count += 1;\n }\n }\n return count;\n }\n",
"begin": 14,
"end": 26,
"fix": " public static int special_filter(int[] nums) {\n int count = 0;\n ArrayList<Integer> odd_digits = new ArrayList<Integer>(Arrays.asList(1, 3, 5, 7, 9));\n for (Integer num : nums) {\n if (num > 10) {\n String number_as_string = num + \"\";\n if (odd_digits.contains(number_as_string.charAt(0) - '0')\n && odd_digits.contains(number_as_string.charAt(number_as_string.length() - 1) - '0'))\n count += 1;\n }\n }\n return count;\n }\n"
},
"FIZZ_BUZZ": {
"buggy": " public static int fizz_buzz(int n) {\n int result = 0;\n\n for (int i = 0; i < n; i += 1){\n if (i % 11 == 0 || i % 13 == 0) {\n for (int j = 0; j < i + \"\".length(); j += 1){\n if (i + \"\".substring(j, j + 1) == \"7\")\n result += 1;\n }\n }\n }\n return result;\n }\n",
"begin": 4,
"end": 16,
"fix": " public static int fizz_buzz(int n) {\n int result = 0;\n\n for (int i = 0; i < n; i += 1){\n if (i % 11 == 0 || i % 13 == 0) {\n for (int j = 0; j < (i + \"\").length(); j += 1){\n if ((i + \"\").substring(j, j + 1).equals(\"7\"))\n result += 1;\n }\n }\n }\n return result;\n }\n"
},
"FIBFIB": {
"buggy": " public static int fibfib(int n) {\n if (n == 0)\n return 0;\n if (n == 1)\n return 0;\n return fibfib(n - 1) + fibfib(n - 2) + fibfib(n - 3);\n }\n",
"begin": 17,
"end": 23,
"fix": " public static int fibfib(int n) {\n if (n == 0)\n return 0;\n if (n == 1)\n return 0;\n if (n == 2)\n return 1;\n return fibfib(n - 1) + fibfib(n - 2) + fibfib(n - 3);\n }\n"
},
"CONCATENATE": {
"buggy": " public static String concatenate(String[] strings) {\n String result = null;\n for (String string : strings)\n result += string;\n return result;\n }\n",
"begin": 4,
"end": 9,
"fix": " public static String concatenate(String[] strings) {\n String result = \"\";\n for (String string : strings)\n result += string;\n return result;\n }\n"
},
"GET_CLOSET_VOWEL": {
"buggy": " public static String get_closet_vowel(String word) {\n if(word.length() < 3) return \"\";\n ArrayList<Character> vowels = new ArrayList<Character>(Arrays.asList('a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'));\n for(int i = word.length() - 2; i >= 0; i--) {\n if(vowels.contains(word.charAt(i))) {\n if(!vowels.contains(word.charAt(i + 1)) && !vowels.contains(word.charAt(i - 1))) {\n return word.substring(i, i + 1);\n }\n }\n }\n return \"\";\n }\n",
"begin": 23,
"end": 34,
"fix": " public static String get_closet_vowel(String word) {\n if(word.length() < 3) return \"\";\n ArrayList<Character> vowels = new ArrayList<Character>(Arrays.asList('a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'));\n for(int i = word.length() - 2; i > 0; i--) {\n if(vowels.contains(word.charAt(i))) {\n if(!vowels.contains(word.charAt(i + 1)) && !vowels.contains(word.charAt(i - 1))) {\n return word.substring(i, i + 1);\n }\n }\n }\n return \"\";\n }\n"
},
"CAR_RACE_COLLISION": {
"buggy": " public static int car_race_collision(int n) {\n return n;\n }\n",
"begin": 14,
"end": 16,
"fix": " public static int car_race_collision(int n) {\n return n * n;\n }\n"
},
"VOWELS_COUNT": {
"buggy": " public static int vowels_count(String str) {\n int result = 0;\n char[] str_chars = str.toCharArray();\n\n for (char c : str_chars) {\n if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'A' || c == 'E' || c == 'I' || c == 'O'\n || c == 'U')\n result += 1;\n }\n if (str_chars[str_chars.length - 1] == 'y')\n result += 1;\n return result;\n }\n",
"begin": 15,
"end": 27,
"fix": " public static int vowels_count(String str) {\n int result = 0;\n char[] str_chars = str.toCharArray();\n\n for (char c : str_chars) {\n if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'A' || c == 'E' || c == 'I' || c == 'O'\n || c == 'U')\n result += 1;\n }\n if (str_chars[str_chars.length - 1] == 'y' || str_chars[str_chars.length - 1] == 'Y')\n result += 1;\n return result;\n }\n"
},
"COUNT_UPPER": {
"buggy": " public static int count_upper(String s) {\n int count = 0;\n for (int i = 0; i < s.length(); i += 2) {\n char c = s.charAt(i);\n if (c == 'A' || c == 'e' || c == 'I' || c == 'o' || c == 'u')\n count += 1;\n }\n return count;\n }\n",
"begin": 11,
"end": 19,
"fix": " public static int count_upper(String s) {\n int count = 0;\n for (int i = 0; i < s.length(); i += 2) {\n char c = s.charAt(i);\n if (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U')\n count += 1;\n }\n return count;\n }\n"
},
"REMOVE_DUPLICATES": {
"buggy": " public static List<Integer> remove_duplicates(List<Integer> numbers) {\n List<Integer> result = new ArrayList<Integer>();\n HashMap<Integer, Integer> count = new HashMap<Integer, Integer>();\n \n for (Integer n : numbers){\n count.put(n, count.get(n) + 1);\n }\n\n for (Integer n : numbers){\n if (count.get(n) == 1)\n result.add(n);\n }\n\n return result;\n }\n",
"begin": 8,
"end": 22,
"fix": " public static List<Integer> remove_duplicates(List<Integer> numbers) {\n List<Integer> result = new ArrayList<Integer>();\n HashMap<Integer, Integer> count = new HashMap<Integer, Integer>();\n \n for (Integer n : numbers){\n if (! count.containsKey(n))\n count.put(n, 0);\n count.put(n, count.get(n) + 1);\n }\n\n for (Integer n : numbers){\n if (count.get(n) == 1)\n result.add(n);\n }\n\n return result;\n }\n"
},
"PRIME_FIB": {
"buggy": " public static int prime_fib(int n){\n ArrayList<Integer> fib = new ArrayList<Integer>();\n fib.add(0);\n fib.add(1);\n\n while (true) {\n int len = fib.size();\n fib.add(fib.get(len - 1) + fib.get(len));\n if (is_prime(fib.get(len - 1)))\n n -= 1;\n if (n == 0)\n return fib.get(fib.size() - 1);\n }\n }\n",
"begin": 16,
"end": 29,
"fix": " public static int prime_fib(int n){\n ArrayList<Integer> fib = new ArrayList<Integer>();\n fib.add(0);\n fib.add(1);\n\n while (true) {\n int len = fib.size();\n fib.add(fib.get(len - 1) + fib.get(len - 2));\n if (is_prime(fib.get(fib.size() - 1)))\n n -= 1;\n if (n == 0)\n return fib.get(fib.size() - 1);\n }\n }\n"
},
"TRIANGLE_AREA": {
"buggy": " public static double triangle_area(double a, double h) {\n return a * h;\n }\n",
"begin": 8,
"end": 10,
"fix": " public static double triangle_area(double a, double h) {\n return a * h / 2.;\n }\n"
},
"IS_PRIME": {
"buggy": " public static boolean is_prime(int n){\n if (n < 2)\n return false;\n for (int k = 0; k < n; k += 1){\n if (n % k == 0)\n return false;\n }\n return true;\n }\n",
"begin": 4,
"end": 12,
"fix": " public static boolean is_prime(int n){\n if (n < 2)\n return false;\n for (int k = 2; k < n - 1; k += 1){\n if (n % k == 0)\n return false;\n }\n return true;\n }\n"
},
"PLUCK": {
"buggy": " public static int[] pluck(int[] arr) {\n int min_even = 0;\n int index = 0;\n\n for (int i = 0; i < arr.length; i += 1) {\n if (arr[i] % 2 == 0 && arr[i] < min_even) {\n min_even = arr[i];\n index = i;\n }\n }\n if (index == -1)\n return new int[]{};\n return new int[] {min_even, index};\n }\n",
"begin": 36,
"end": 49,
"fix": " public static int[] pluck(int[] arr) {\n int min_even = Integer.MAX_VALUE;\n int index = -1;\n\n for (int i = 0; i < arr.length; i += 1) {\n if (arr[i] % 2 == 0 && arr[i] < min_even) {\n min_even = arr[i];\n index = i;\n }\n }\n if (index == -1)\n return new int[]{};\n return new int[] {min_even, index};\n }\n"
},
"SMALLEST_CHANGE": {
"buggy": " public static int smallest_change(int[] arr) {\n int result = 0;\n for (int i = 0; i < arr.length; i += 1) {\n if (arr[i] != arr[arr.length - i])\n result += 1;\n }\n\n return result;\n }\n",
"begin": 13,
"end": 21,
"fix": " public static int smallest_change(int[] arr) {\n int result = 0;\n for (int i = 0; i < arr.length / 2; i += 1) {\n if (arr[i] != arr[arr.length - i - 1])\n result += 1;\n }\n\n return result;\n }\n"
},
"SORT_NUMBERS": {
"buggy": " public static String sort_numbers(String numbers) {\n final HashMap<String, Integer> value_map = new HashMap<String, Integer>();\n value_map.put(\"zero\", 0);\n value_map.put(\"one\", 1);\n value_map.put(\"two\", 2);\n value_map.put(\"three\", 3);\n value_map.put(\"four\", 4);\n value_map.put(\"five\", 5);\n value_map.put(\"six\", 6);\n value_map.put(\"seven\", 7);\n value_map.put(\"eight\", 8);\n value_map.put(\"nine\", 9);\n\n ArrayList<String> number_array = new ArrayList<String>(Arrays.asList(numbers.split(\" \")));\n Collections.sort(number_array);\n \n String result = \"\";\n for (String number : number_array){\n result += number + \" \";\n }\n return result.trim();\n }\n",
"begin": 6,
"end": 27,
"fix": " public static String sort_numbers(String numbers) {\n final HashMap<String, Integer> value_map = new HashMap<String, Integer>();\n value_map.put(\"zero\", 0);\n value_map.put(\"one\", 1);\n value_map.put(\"two\", 2);\n value_map.put(\"three\", 3);\n value_map.put(\"four\", 4);\n value_map.put(\"five\", 5);\n value_map.put(\"six\", 6);\n value_map.put(\"seven\", 7);\n value_map.put(\"eight\", 8);\n value_map.put(\"nine\", 9);\n\n ArrayList<String> number_array = new ArrayList<String>(Arrays.asList(numbers.split(\" \")));\n Collections.sort(number_array, new Comparator<String>(){\n public int compare(String n1, String n2) {\n return value_map.get(n1) - value_map.get(n2);\n }\n });\n \n String result = \"\";\n for (String number : number_array){\n result += number + \" \";\n }\n return result.trim();\n }\n"
},
"IS_SORTED": {
"buggy": " public static boolean is_sorted(int[] lst) {\n HashMap<Integer, Integer> count_num = new HashMap<>();\n for(int i = 0; i < lst.length; i++) {\n count_num.put(lst[i], 0);\n }\n for(int i = 0; i < lst.length; i++) {\n count_num.put(lst[i], count_num.get(lst[i]) + 1);\n }\n for(int i = 0; i < lst.length; i++) {\n if(count_num.get(lst[i]) > 2) return false;\n }\n for(int i = 0; i < lst.length - 1; i++) {\n if(lst[i] <= lst[i + 1]) return false;\n }\n return true;\n }\n",
"begin": 22,
"end": 37,
"fix": " public static boolean is_sorted(int[] lst) {\n HashMap<Integer, Integer> count_num = new HashMap<>();\n for(int i = 0; i < lst.length; i++) {\n count_num.put(lst[i], 0);\n }\n for(int i = 0; i < lst.length; i++) {\n count_num.put(lst[i], count_num.get(lst[i]) + 1);\n }\n for(int i = 0; i < lst.length; i++) {\n if(count_num.get(lst[i]) > 2) return false;\n }\n for(int i = 0; i < lst.length - 1; i++) {\n if(lst[i] > lst[i + 1]) return false;\n }\n return true;\n }\n"
},
"DECODE_CYCLIC": {
"buggy": " public static String decode_cyclic(String str) {\n class Cyclic {\n String encode_cyclic(String s) {\n ArrayList<String> groups = new ArrayList<String>();\n\n for (int i = 0; i < s.length(); i += 3){\n groups.add(s.substring(i, Math.min(s.length(), i + 3)));\n }\n int remain = s.length() % 3;\n \n String result = \"\";\n for (String group : groups){\n result += group.substring(1) + group.substring(0, 1);\n }\n\n if (remain > 0){\n result += s.substring(s.length() - remain);\n }\n\n return result;\n }\n }\n \n final Cyclic cyclic = new Cyclic();\n return cyclic.encode_cyclic(cyclic.encode_cyclic(str));\n }\n",
"begin": 6,
"end": 31,
"fix": " public static String decode_cyclic(String str) {\n class Cyclic {\n String encode_cyclic(String s) {\n ArrayList<String> groups = new ArrayList<String>();\n\n for (int i = 0; i < s.length() - s.length() % 3; i += 3){\n groups.add(s.substring(i, Math.min(s.length(), i + 3)));\n }\n int remain = s.length() % 3;\n \n String result = \"\";\n for (String group : groups){\n result += group.substring(1) + group.substring(0, 1);\n }\n\n if (remain > 0){\n result += s.substring(s.length() - remain);\n }\n\n return result;\n }\n }\n \n final Cyclic cyclic = new Cyclic();\n return cyclic.encode_cyclic(cyclic.encode_cyclic(str));\n }\n"
},
"GET_POSITIVE": {
"buggy": " public static List<Integer> get_positive(List<Integer> numbers) {\n List<Integer> result = new ArrayList<Integer>();\n\n for (Integer number : numbers) {\n result.add(number);\n }\n return result;\n }\n",
"begin": 7,
"end": 14,
"fix": " public static List<Integer> get_positive(List<Integer> numbers) {\n List<Integer> result = new ArrayList<Integer>();\n\n for (Integer number : numbers) {\n if (number > 0){\n result.add(number);\n }\n }\n return result;\n }\n"
},
"SORT_EVEN": {
"buggy": " public static int[] sort_even(int[] l) {\n int[] result = new int[l.length];\n\n int[] evens = new int[1 + (int) (l.length / 2.)];\n for (int i = 0; i < l.length; i += 2) {\n evens[(int) i / 2] = l[i];\n }\n Arrays.sort(evens);\n for (int i = 0; i < l.length; i += 1) {\n if (i % 2 == 0){\n result[i] = evens[(int) i / 2];\n } else{\n result[i] = l[i];\n }\n }\n return result;\n }\n",
"begin": 6,
"end": 22,
"fix": " public static int[] sort_even(int[] l) {\n int[] result = new int[l.length];\n\n int[] evens = new int[(int) Math.ceil(l.length / 2.)];\n for (int i = 0; i < l.length; i += 2){\n evens[(int) i / 2] = l[i];\n }\n Arrays.sort(evens);\n for (int i = 0; i < l.length; i += 1){\n if (i % 2 == 0){\n result[i] = evens[(int) i / 2];\n } else{\n result[i] = l[i];\n }\n }\n return result;\n }\n"
},
"SPECIAL_FACTORIAL": {
"buggy": " public static long special_factorial(long n) {\n long fact_i = 1, special_fact = 1;\n for(long i = n; i >= 1; i--) {\n fact_i *= i * fact_i;\n special_fact += i * fact_i;\n }\n return special_fact;\n }\n",
"begin": 18,
"end": 25,
"fix": " public static long special_factorial(long n) {\n long fact_i = 1, special_fact = 1;\n for(int i = 1; i <= n; i++) {\n fact_i *= i;\n special_fact *= fact_i;\n }\n return special_fact;\n }\n"
},
"TOTAL_MATCH": {
"buggy": " public static List<String> total_match(List<String> lst1, List<String> lst2) {\n int l1 = 0;\n for (String st : lst1)\n l1 += st.length();\n int l2 = 0;\n for (String st : lst1)\n l2 = st.length();\n \n if (l1 <= l2)\n return lst1;\n return lst2;\n }\n",
"begin": 18,
"end": 29,
"fix": " public static List<String> total_match(List<String> lst1, List<String> lst2) {\n int l1 = 0;\n for (String st : lst1)\n l1 += st.length();\n int l2 = 0;\n for (String st : lst2)\n l2 += st.length();\n \n if (l1 <= l2)\n return lst1;\n return lst2;\n }\n"
},
"STRONGEST_EXTENSION": {
"buggy": " public static String strongest_extension(String class_name, String[] extensions) {\n String strong = null;\n int val = Integer.MIN_VALUE;\n\n for (String s : extensions) {\n int CAP = 0;\n int SM = 0;\n for (char c : s.toCharArray()) {\n if (Character.toUpperCase(c) == c) SM += 1;\n if (Character.toLowerCase(c) == c) CAP += 1;\n }\n val = CAP - SM;\n strong = s;\n }\n return class_name + \".\" + strong;\n }\n",
"begin": 20,
"end": 35,
"fix": " public static String strongest_extension(String class_name, String[] extensions) {\n String strong = null;\n int val = Integer.MIN_VALUE;\n\n for (String s : extensions) {\n int CAP = 0;\n int SM = 0;\n for (char c : s.toCharArray()) {\n if (Character.toUpperCase(c) == c) CAP += 1;\n if (Character.toLowerCase(c) == c) SM += 1;\n }\n if (CAP - SM > val) {\n val = CAP - SM;\n strong = s;\n }\n }\n return class_name + \".\" + strong;\n }\n"
},
"SORT_ARRAY_BINARY": {
"buggy": " public static ArrayList<Integer> sort_array_binary(ArrayList<Integer> arr) {\n Collections.sort(arr, new Comparator<Integer>() {\n @Override\n public int compare(Integer o1, Integer o2) {\n int num_ones_o1 = number_ones(o1);\n int num_ones_o2 = number_ones(o2);\n if(num_ones_o1 == num_ones_o2) {\n if(o1 == o2) return 1;\n if(o1 < o2) return 0;\n if(o1 > o2) return -1;\n }\n if(num_ones_o1 < num_ones_o2) return -1;\n else return 1;\n }\n });\n return arr;\n }\n",
"begin": 29,
"end": 45,
"fix": " public static ArrayList<Integer> sort_array_binary(ArrayList<Integer> arr) {\n Collections.sort(arr, new Comparator<Integer>() {\n @Override\n public int compare(Integer o1, Integer o2) {\n int num_ones_o1 = number_ones(o1);\n int num_ones_o2 = number_ones(o2);\n if(num_ones_o1 == num_ones_o2) {\n if(o1 == o2) return 0;\n if(o1 < o2) return -1;\n if(o1 > o2) return 1;\n }\n if(num_ones_o1 < num_ones_o2) return -1;\n else return 1;\n }\n });\n return arr;\n }\n"
},
"EVEN_ODD_PALINDROME": {
"buggy": " public static ArrayList<Integer> even_odd_palindrome(int n) {\n int even_palindrome_count = 0, odd_palindrome_count = 0;\n for(int i = 1; i <= n; i++) {\n if((i % 2) == 0 && is_palindrome(i)) odd_palindrome_count--;\n else if((i % 2) == 1 && is_palindrome(i)) even_palindrome_count--;\n }\n ArrayList<Integer> result = new ArrayList<>(Arrays.asList(even_palindrome_count, odd_palindrome_count));\n return result;\n }\n",
"begin": 39,
"end": 47,
"fix": " public static ArrayList<Integer> even_odd_palindrome(int n) {\n int even_palindrome_count = 0, odd_palindrome_count = 0;\n for(int i = 1; i <= n; i++) {\n if((i % 2) == 1 && is_palindrome(i)) odd_palindrome_count++;\n else if((i % 2) == 0 && is_palindrome(i)) even_palindrome_count++;\n }\n ArrayList<Integer> result = new ArrayList<>(Arrays.asList(even_palindrome_count, odd_palindrome_count));\n return result;\n }\n"
},
"INT_TO_MINI_ROMAN": {
"buggy": " public static String int_to_mini_roman(int number) {\n int[] num = new int[] {1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000};\n String[] sym = new String[] {\n \"I\", \"IV\", \"V\", \"IX\", \"X\", \"XL\", \"L\", \"XC\", \"C\", \"CD\", \"D\", \"CM\", \"M\"\n };\n\n int i = 12;\n String result = \"\";\n while (number > 0) {\n result += sym[i];\n number %= num[i];\n i -= 1;\n }\n return result.toLowerCase();\n }\n",
"begin": 13,
"end": 27,
"fix": " public static String int_to_mini_roman(int number) {\n int[] num = new int[] {1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000};\n String[] sym = new String[] {\n \"I\", \"IV\", \"V\", \"IX\", \"X\", \"XL\", \"L\", \"XC\", \"C\", \"CD\", \"D\", \"CM\", \"M\"\n };\n\n int i = 12;\n String result = \"\";\n while (number > 0) {\n int div = (int) (number / num[i]);\n while (div > 0) {\n result += sym[i];\n div -= 1;\n }\n number %= num[i];\n i -= 1;\n }\n return result.toLowerCase();\n }\n"
},
"STRING_SEQUENCE": {
"buggy": " public static String string_sequence(int n) {\n String result = \"\";\n for (int i = 0; i <= n; i += 1){\n result += i + \" \";\n }\n return result;\n }\n",
"begin": 4,
"end": 10,
"fix": " public static String string_sequence(int n) {\n String result = \"\";\n for (int i = 0; i <= n; i += 1){\n result += i + \" \";\n }\n return result.trim();\n }\n"
},
"IS_MULTIPLY_PRIME": {
"buggy": " public static boolean is_multiply_prime(int a) {\n for (int i = 2; i < a; i += 1){\n if (! is_prime(i)) continue;\n for (int j = i; j < a; j += 1) {\n for (int k = j; k < a; j += 1) {\n if (! is_prime(k)) continue;\n if (i * j * k == a)\n return true;\n }\n }\n }\n return false;\n }\n",
"begin": 19,
"end": 31,
"fix": " public static boolean is_multiply_prime(int a) {\n for (int i = 2; i < a; i += 1){\n if (! is_prime(i)) continue;\n for (int j = i; j < a; j += 1) {\n if (! is_prime(j)) continue;\n for (int k = j; k < a; k += 1) {\n if (! is_prime(k)) continue;\n if (i * j * k == a)\n return true;\n }\n }\n }\n return false;\n }\n"
},
"FACTORIAL": {
"buggy": " public static ArrayList<Integer> factorial(int n) {\n ArrayList<Integer> ret = new ArrayList<>();\n for(int i = 1; i <= n; i++) {\n if((i % 2) == 0) {\n int x = 1;\n for(int j = 1; j <= i; j++) x *= j;\n ret.add(x);\n } else {\n int x = 0;\n for(int j = 1; j <= i; i++) x -= j;\n ret.add(x);\n }\n }\n return ret;\n }\n",
"begin": 16,
"end": 30,
"fix": " public static ArrayList<Integer> factorial(int n) {\n ArrayList<Integer> ret = new ArrayList<>();\n for(int i = 1; i <= n; i++) {\n if((i % 2) == 0) {\n int x = 1;\n for(int j = 1; j <= i; j++) x *= j;\n ret.add(x);\n } else {\n int x = 0;\n for(int j = 1; j <= i; j++) x += j;\n ret.add(x);\n }\n }\n return ret;\n }\n"
},
"SOLVE_STRING": {
"buggy": " public static String solve_string(String s) {\n int flg = 0;\n StringBuilder sb = new StringBuilder();\n for (char c : s.toCharArray()) {\n if (Character.isLowerCase(c)) sb.append(Character.toUpperCase(c));\n else sb.append(Character.toLowerCase(c));\n flg = 1;\n }\n if (flg == 0) {\n sb = new StringBuilder();\n for (int i = s.length() - 1; i >= 0; i -= 1) sb.append(s.charAt(i));\n }\n return sb.toString();\n }\n",
"begin": 14,
"end": 27,
"fix": " public static String solve_string(String s) {\n int flg = 0;\n StringBuilder sb = new StringBuilder();\n for (char c : s.toCharArray()) {\n if (Character.isAlphabetic(c)){\n if (Character.isLowerCase(c)) sb.append(Character.toUpperCase(c));\n else sb.append(Character.toLowerCase(c));\n flg = 1;\n }\n else sb.append(c);\n }\n if (flg == 0) {\n sb = new StringBuilder();\n for (int i = s.length() - 1; i >= 0; i -= 1) sb.append(s.charAt(i));\n }\n return sb.toString();\n }\n"
},
"IS_BORED": {
"buggy": " public static int is_bored(String S) {\n String[] sentences = S.split(\"\\\\.|\\\\?|!\");\n int result = 0;\n for (String sentence : sentences) {\n if (sentence.length() >= 2 && sentence.subSequence(0, 2).equals(\"I \"))\n result += 1;\n }\n return result;\n }\n",
"begin": 14,
"end": 22,
"fix": " public static int is_bored(String S) {\n String[] sentences = S.split(\"\\\\.|\\\\?|!\");\n int result = 0;\n for (String sentence : sentences) {\n sentence = sentence.trim();\n if (sentence.length() >= 2 && sentence.subSequence(0, 2).equals(\"I \"))\n result += 1;\n }\n return result;\n }\n"
},
"ALL_PREFIXES": {
"buggy": " public static List<String> all_prefixes(String string){\n List<String> result = new ArrayList<String>();\n\n for (int i = 0; i < string.length(); i += 1){\n result.add(string.substring(i + 1));\n }\n\n return result;\n }\n",
"begin": 7,
"end": 15,
"fix": " public static List<String> all_prefixes(String string){\n List<String> result = new ArrayList<String>();\n\n for (int i = 0; i < string.length(); i += 1){\n result.add(string.substring(0, i + 1));\n }\n\n return result;\n }\n"
},
"COMMON": {
"buggy": " public static int[] common(int[] l1, int[] l2) {\n ArrayList<Integer> common = new ArrayList<Integer>();\n \n for (int i = 0; i < l1.length; i += 1){\n for (int j = 0; j < l2.length; j += 1){\n if (l1[i] == l2[j])\n common.add(l1[i]);\n }\n }\n int[] result = new int[common.size()];\n int index = 0;\n for (Integer c : common) {\n result[index] = c;\n index += 1;\n }\n Arrays.sort(result);\n return result;\n }\n",
"begin": 12,
"end": 29,
"fix": " public static int[] common(int[] l1, int[] l2) {\n HashSet<Integer> common = new HashSet<Integer>();\n \n for (int i = 0; i < l1.length; i += 1){\n for (int j = 0; j < l2.length; j += 1){\n if (l1[i] == l2[j])\n common.add(l1[i]);\n }\n }\n int[] result = new int[common.size()];\n int index = 0;\n for (Integer c : common) {\n result[index] = c;\n index += 1;\n }\n Arrays.sort(result);\n return result;\n }\n"
},
"STRLEN": {
"buggy": " public static int strlen(String string){\n return string.length() - 1;\n }\n",
"begin": 4,
"end": 6,
"fix": " public static int strlen(String string){\n return string.length();\n }\n"
},
"RIGHT_ANGLE_TRIANGLE": {
"buggy": " public static boolean right_angle_triangle(int a, int b, int c) {\n return a*a + b*b == c*c;\n }\n",
"begin": 12,
"end": 14,
"fix": " public static boolean right_angle_triangle(int a, int b, int c) {\n return a*a + b*b == c*c || b*b + c*c == a*a || c*c + a*a == b*b;\n }\n"
},
"ENCRYPT": {
"buggy": " public static String encrypt(String s) {\n StringBuilder sb = new StringBuilder();\n String d = \"abcdefghijklmnopqrstuvwxyz\";\n for (char c : s.toCharArray()){\n if ('a' <= c && c <= 'z'){\n sb.append(\n d.charAt(s.indexOf((int) c) + 2 * 2)\n );\n } else {\n sb.append(c);\n }\n }\n return sb.toString();\n }\n",
"begin": 14,
"end": 27,
"fix": " public static String encrypt(String s) {\n StringBuilder sb = new StringBuilder();\n String d = \"abcdefghijklmnopqrstuvwxyz\";\n for (char c : s.toCharArray()){\n if ('a' <= c && c <= 'z'){\n sb.append(\n d.charAt((d.indexOf((int) c) + 2 * 2) % 26)\n );\n } else {\n sb.append(c);\n }\n }\n return sb.toString();\n }\n"
},
"TRUNCATE_NUMBER": {
"buggy": " public static double truncate_number(double number) {\n return number / 1.0;\n }\n",
"begin": 4,
"end": 6,
"fix": " public static double truncate_number(double number) {\n return number % 1.0;\n }\n"
},
"FILTER_BY_PREFIX": {
"buggy": " public static List<String> filter_by_prefix(List<String> strings, String prefix) {\n List<String> result = new ArrayList<String>();\n\n for (String string : strings){\n if (string.startsWith(prefix, 1)){\n result.add(string);\n }\n }\n return result;\n }\n",
"begin": 7,
"end": 16,
"fix": " public static List<String> filter_by_prefix(List<String> strings, String prefix) {\n List<String> result = new ArrayList<String>();\n\n for (String string : strings){\n if (string.startsWith(prefix)){\n result.add(string);\n }\n }\n return result;\n }\n"
},
"NEXT_SMALLEST": {
"buggy": " public static Integer next_smallest(int[] lst) {\n List<Integer> numbers = new ArrayList<Integer>();\n for (Integer n : lst)\n numbers.add(n);\n Integer[] no_duplicate = numbers.toArray(new Integer[] {});\n Arrays.sort(no_duplicate);\n\n if (no_duplicate.length < 2)\n return null;\n return no_duplicate[1];\n }\n",
"begin": 15,
"end": 25,
"fix": " public static Integer next_smallest(int[] lst) {\n HashSet<Integer> numbers = new HashSet<Integer>();\n for (Integer n : lst)\n numbers.add(n);\n Integer[] no_duplicate = numbers.toArray(new Integer[] {});\n Arrays.sort(no_duplicate);\n\n if (no_duplicate.length < 2)\n return null;\n return no_duplicate[1];\n }\n"
},
"STRING_XOR": {
"buggy": " public static String string_xor(String a, String b){\n String result = \"\";\n for (int i = 0; i < a.length(); i += 1){\n if (a.charAt(i) == b.charAt(i)){\n result += \"0\";\n }\n }\n return result;\n }\n",
"begin": 4,
"end": 12,
"fix": " public static String string_xor(String a, String b){\n String result = \"\";\n for (int i = 0; i < a.length(); i += 1){\n if (a.charAt(i) == b.charAt(i)){\n result += \"0\";\n }\n else{\n result += \"1\";\n }\n }\n return result;\n }\n"
},
"RESCALE_TO_UNIT": {
"buggy": " public static double[] rescale_to_unit(double[] numbers){\n double min = Double.MAX_VALUE;\n double max = Double.MIN_VALUE;\n\n for (int i = 0; i < numbers.length; i += 1) {\n if (numbers[i] > max) {\n max = numbers[i];\n }\n else if (numbers[i] < min) {\n min = numbers[i];\n }\n }\n\n double[] result = new double[numbers.length];\n for (int i = 0; i < numbers.length; i += 1) {\n result[i] = (numbers[i] - min) / (max - min);\n }\n return result;\n }\n",
"begin": 4,
"end": 22,
"fix": " public static double[] rescale_to_unit(double[] numbers){\n double min = Double.MAX_VALUE;\n double max = Double.MIN_VALUE;\n\n for (int i = 0; i < numbers.length; i += 1) {\n if (numbers[i] > max){\n max = numbers[i];\n }\n if (numbers[i] < min){\n min = numbers[i];\n }\n }\n\n double[] result = new double[numbers.length];\n for (int i = 0; i < numbers.length; i += 1) {\n result[i] = (numbers[i] - min) / (max - min);\n }\n return result;\n }\n"
},
"SIMPLIFY": {
"buggy": " public static boolean simplify(String x, String n) {\n int a = Integer.parseInt(x.split(\"/\")[0]);\n int b = Integer.parseInt(x.split(\"/\")[1]);\n int c = Integer.parseInt(n.split(\"/\")[0]);\n int d = Integer.parseInt(n.split(\"/\")[1]);\n\n int numerator = a * c;\n int denom = b * d;\n if (numerator / denom == (int) (numerator / denom))\n return true;\n return false;\n }\n",
"begin": 15,
"end": 26,
"fix": " public static boolean simplify(String x, String n) {\n int a = Integer.parseInt(x.split(\"/\")[0]);\n int b = Integer.parseInt(x.split(\"/\")[1]);\n int c = Integer.parseInt(n.split(\"/\")[0]);\n int d = Integer.parseInt(n.split(\"/\")[1]);\n\n int numerator = a * c;\n int denom = b * d;\n if (1.0 * numerator / denom == (int) (numerator / denom))\n return true;\n return false;\n }\n"
},
"STRING_TO_MD5": {
"buggy": " public static String string_to_md5(String text) throws NoSuchAlgorithmException {\n if (text.equals(\"\")) return null;\n\n MessageDigest md = MessageDigest.getInstance(\"SHA-384\");\n md.update(text.getBytes());\n byte[] digest = md.digest();\n return DatatypeConverter.printHexBinary(digest).toLowerCase();\n } \n",
"begin": 13,
"end": 20,
"fix": " public static String string_to_md5(String text) throws NoSuchAlgorithmException {\n if (text.equals(\"\")) return null;\n\n MessageDigest md = MessageDigest.getInstance(\"MD5\");\n md.update(text.getBytes());\n byte[] digest = md.digest();\n return DatatypeConverter.printHexBinary(digest).toLowerCase();\n } \n"
},
"LARGEST_DIVISOR": {
"buggy": " public static int largest_divisor(int n) {\n for (int i = n; i >= 0; i -= 1){\n if (n % i == 0)\n return i;\n }\n return 1;\n }\n",
"begin": 4,
"end": 10,
"fix": " public static int largest_divisor(int n) {\n for (int i = n - 1; i >= 1; i -= 1){\n if (n % i == 0)\n return i;\n }\n return 1;\n }\n"
},
"INTERSECTION": {
"buggy": " public static String intersection(int[] interval1, int[] interval2) {\n int l = Math.min(interval1[0], interval2[0]);\n int r = Math.max(interval1[1], interval2[1]);\n int length = r - l;\n if(length > 0 && is_prime(length)) return \"YES\";\n return \"NO\";\n }\n",
"begin": 33,
"end": 39,
"fix": " public static String intersection(int[] interval1, int[] interval2) {\n int l = Math.max(interval1[0], interval2[0]);\n int r = Math.min(interval1[1], interval2[1]);\n int length = r - l;\n if(length > 0 && is_prime(length)) return \"YES\";\n return \"NO\";\n }\n"
},
"SEARCH": {
"buggy": " public static int search(int[] lst) {\n int max = -1;\n for (Integer i : lst) {\n if (i > max)\n max = i;\n }\n\n int result = -1;\n int[] frq = new int[max];\n for (int i = 0; i < lst.length; i += 1) frq[i] += 1;\n for (int i = 0; i < frq.length; i += 1) if (frq[i] >= i) result = i;\n \n return result;\n }\n",
"begin": 13,
"end": 26,
"fix": " public static int search(int[] lst) {\n int max = -1;\n for (Integer i : lst) {\n if (i > max)\n max = i;\n }\n\n int result = -1;\n int[] frq = new int[max + 1];\n for (int i = 0; i < lst.length; i += 1) frq[lst[i]] += 1;\n for (int i = 0; i < frq.length; i += 1) if (frq[i] >= i && frq[i] > 0) result = i;\n \n return result;\n }\n"
},
"CLOSEST_INTEGER": {
"buggy": " public static int closest_integer(String value) {\n if (value.indexOf('.') >= 0) {\n while (value.charAt(value.length() - 1) == '0')\n value = value.substring(0, value.length() - 1);\n }\n\n double num = Double.parseDouble(value);\n int result = 0;\n if (value.substring(value.length() - 2).equals(\".5\")) {\n result = num > 0 ? (int)Math.floor(num) : (int)Math.ceil(num);\n } else if (value.length() > 0){\n result = (int)Math.round(num);\n }\n\n return result;\n }\n",
"begin": 20,
"end": 35,
"fix": " public static int closest_integer(String value) {\n if (value.indexOf('.') >= 0) {\n while (value.charAt(value.length() - 1) == '0')\n value = value.substring(0, value.length() - 1);\n }\n\n double num = Double.parseDouble(value);\n int result = 0;\n if (value.length() >= 2 && value.substring(value.length() - 2).equals(\".5\")) {\n result = num > 0 ? (int)Math.ceil(num) : (int)Math.floor(num);\n } else if (value.length() > 0){\n result = (int)Math.round(num);\n }\n\n return result;\n }\n"
},
"WORDS_STRINGS": {
"buggy": " public static ArrayList<String> words_strings(String s) {\n ArrayList<String> result = new ArrayList<String>();\n String s_list = \"\";\n for(char c : s.toCharArray()) {\n if(c == ',') {\n s_list += ' ';\n } else {\n s_list += c;\n }\n }\n String[] result_array = s_list.trim().split(\"\\\\s+\");\n for(String r : result_array) {\n result.add(r);\n }\n return result;\n }\n",
"begin": 15,
"end": 30,
"fix": " public static ArrayList<String> words_strings(String s) {\n ArrayList<String> result = new ArrayList<String>();\n if(s == null || s.isEmpty()) return result;\n String s_list = \"\";\n for(char c : s.toCharArray()) {\n if(c == ',') {\n s_list += ' ';\n } else {\n s_list += c;\n }\n }\n String[] result_array = s_list.trim().split(\"\\\\s+\");\n for(String r : result_array) {\n result.add(r);\n }\n return result;\n }\n"
},
"FLIP_CASE": {
"buggy": " public static String flip_case(String string) {\n char[] char_list = string.toCharArray();\n \n for (int i = 0; i < char_list.length; i += 1){\n char c = char_list[i];\n if (Character.isLowerCase(c)) {\n char_list[i] = Character.toLowerCase(c);\n }\n else {\n char_list[i] = Character.toUpperCase(c);\n }\n }\n return new String(char_list);\n }\n",
"begin": 4,
"end": 17,
"fix": " public static String flip_case(String string) {\n char[] char_list = string.toCharArray();\n \n for (int i = 0; i < char_list.length; i += 1){\n char c = char_list[i];\n if (Character.isLowerCase(c)) {\n char_list[i] = Character.toUpperCase(c);\n }\n else {\n char_list[i] = Character.toLowerCase(c);\n }\n }\n return new String(char_list);\n }\n"
},
"VALID_DATE": {
"buggy": " public static boolean valid_date(String date) {\n try {\n date = date.trim();\n String[] date_info = date.split(\"-\");\n if(date_info.length > 3) return false;\n int month = Integer.parseInt(date_info[0]);\n int day = Integer.parseInt(date_info[1]);\n int year = Integer.parseInt(date_info[2]);\n\n if(month < 1 || month > 12) return false;\n\n int[] month_check1 = {1, 3, 5, 7, 8, 10, 12};\n for(int i = 0; i < month_check1.length; i++) {\n if(month != month_check1[i] && !(day < 1 || day > 31)) return false;\n }\n\n int[] month_check2 = {4, 6, 9, 11};\n for(int i = 0; i < month_check2.length; i++) {\n if(month == month_check2[i] && (day < 1 || day > 30)) return false;\n }\n if(month == 2 && (day < 1 || day > 29)) return false;\n } catch (Exception e) {\n return false;\n }\n return true;\n }\n",
"begin": 25,
"end": 50,
"fix": " public static boolean valid_date(String date) {\n try {\n date = date.trim();\n String[] date_info = date.split(\"-\");\n if(date_info.length > 3) return false;\n int month = Integer.parseInt(date_info[0]);\n int day = Integer.parseInt(date_info[1]);\n int year = Integer.parseInt(date_info[2]);\n\n if(month < 1 || month > 12) return false;\n\n int[] month_check1 = {1, 3, 5, 7, 8, 10, 12};\n for(int i = 0; i < month_check1.length; i++) {\n if(month == month_check1[i] && (day < 1 || day > 31)) return false;\n }\n\n int[] month_check2 = {4, 6, 9, 11};\n for(int i = 0; i < month_check2.length; i++) {\n if(month == month_check2[i] && (day < 1 || day > 30)) return false;\n }\n if(month == 2 && (day < 1 || day > 29)) return false;\n } catch (Exception e) {\n return false;\n }\n return true;\n }\n"
},
"HEX_KEY": {
"buggy": " public static int hex_key(String num) {\n int result = 0;\n for (char c : num.toCharArray()) {\n if (c == '2' || c == '3' || c == '5' || c == '7')\n result += 1;\n }\n return result;\n }\n",
"begin": 21,
"end": 28,
"fix": " public static int hex_key(String num) {\n int result = 0;\n for (char c : num.toCharArray()) {\n if (c == '2' || c == '3' || c == '5' || c == '7' || c == 'B' || c == 'D')\n result += 1;\n }\n return result;\n }\n"
},
"LARGEST_SMALLEST_INTEGERS": {
"buggy": " public static int[] largest_smallest_integers(int[] lst) {\n boolean negative = true, positive = true;\n int max_negative = Integer.MAX_VALUE, min_positive = Integer.MIN_VALUE; \n for(int i = 1; i < lst.length; i++) {\n if(lst[i] < 0) {\n negative = false;\n max_negative = Math.min(max_negative, lst[i]);\n } else if(lst[i] > 0) {\n positive = true;\n min_positive = Math.min(min_positive, lst[i]);\n }\n }\n if(!negative) max_negative = 0;\n if(!positive) min_positive = 0;\n int[] result = {max_negative, min_positive};\n return result;\n }\n",
"begin": 16,
"end": 32,
"fix": " public static int[] largest_smallest_integers(int[] lst) {\n boolean negative = false, positive = false;\n int max_negative = Integer.MIN_VALUE, min_positive = Integer.MAX_VALUE; \n for(int i = 0; i < lst.length; i++) {\n if(lst[i] < 0) {\n negative = true;\n max_negative = Math.max(max_negative, lst[i]);\n } else if(lst[i] > 0) {\n positive = true;\n min_positive = Math.min(min_positive, lst[i]);\n }\n }\n if(!negative) max_negative = 0;\n if(!positive) min_positive = 0;\n int[] result = {max_negative, min_positive};\n return result;\n }\n"
},
"BY_LENGTH": {
"buggy": " public static ArrayList<String> by_length(ArrayList<Integer> a) {\n Map<Integer, String> digit_map = new HashMap<>();\n digit_map.put(1, \"One\");\n digit_map.put(2, \"Two\");\n digit_map.put(3, \"Three\");\n digit_map.put(4, \"Four\");\n digit_map.put(5, \"Five\");\n digit_map.put(6, \"Six\");\n digit_map.put(7, \"Seven\");\n digit_map.put(8, \"Eight\");\n digit_map.put(9, \"Nine\");\n Collections.sort(a, Collections.reverseOrder());\n ArrayList<String> result = new ArrayList<>();\n for(int num : a) {\n if(digit_map.get(num) != \"\") {\n result.add(digit_map.get(num));\n }\n }\n return result;\n }\n",
"begin": 31,
"end": 50,
"fix": " public static ArrayList<String> by_length(ArrayList<Integer> a) {\n Map<Integer, String> digit_map = new HashMap<>();\n digit_map.put(1, \"One\");\n digit_map.put(2, \"Two\");\n digit_map.put(3, \"Three\");\n digit_map.put(4, \"Four\");\n digit_map.put(5, \"Five\");\n digit_map.put(6, \"Six\");\n digit_map.put(7, \"Seven\");\n digit_map.put(8, \"Eight\");\n digit_map.put(9, \"Nine\");\n Collections.sort(a, Collections.reverseOrder());\n ArrayList<String> result = new ArrayList<>();\n for(int num : a) {\n if(digit_map.get(num) != null) {\n result.add(digit_map.get(num));\n }\n }\n return result;\n }\n"
},
"MAX_ELEMENT": {
"buggy": " public static int max_element(List<Integer> l) {\n int m = 0;\n for (Integer e : l) {\n if (e > m){\n m = e;\n }\n }\n return m;\n }\n",
"begin": 6,
"end": 14,
"fix": " public static int max_element(List<Integer> l) {\n int m = l.get(0);\n for (Integer e : l) {\n if (e > m){\n m = e;\n }\n }\n return m;\n }\n"
},
"SOLVE": {
"buggy": " public static String solve(int N) {\n int sum = 0;\n for (int i = 0; i < (N + \"\").length(); i += 1){\n sum += Integer.parseInt((N + \"\").substring(i + 1));\n }\n return Integer.toBinaryString(sum);\n }\n",
"begin": 17,
"end": 23,
"fix": " public static String solve(int N) {\n int sum = 0;\n for (int i = 0; i < (N + \"\").length(); i += 1){\n sum += Integer.parseInt((N + \"\").substring(i, i + 1));\n }\n return Integer.toBinaryString(sum);\n }\n"
},
"MAKE_A_PILE": {
"buggy": " public static ArrayList<Integer> make_a_pile(int n) {\n ArrayList<Integer> pile = new ArrayList<Integer>();\n for(int i = 0; i < n; i++) {\n pile.add(n - 2 * i);\n }\n return pile;\n }\n",
"begin": 20,
"end": 26,
"fix": " public static ArrayList<Integer> make_a_pile(int n) {\n ArrayList<Integer> pile = new ArrayList<Integer>();\n for(int i = 0; i < n; i++) {\n pile.add(n + 2 * i);\n }\n return pile;\n }\n"
},
"ENCODE": {
"buggy": " public static String encode(String message) {\n StringBuilder sb = new StringBuilder();\n for (char c : message.toCharArray()) {\n if (Character.isUpperCase(c)) {\n c = Character.toLowerCase(c);\n }\n if (Character.isLowerCase(c)) {\n c = Character.toUpperCase(c);\n }\n if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'A' || c == 'E' || c == 'I' || c == 'O'\n || c == 'U') {\n c = (char) ((int) c + 2);\n }\n sb.append(c);\n }\n return sb.toString();\n }\n",
"begin": 16,
"end": 32,
"fix": " public static String encode(String message) {\n StringBuilder sb = new StringBuilder();\n for (char c : message.toCharArray()) {\n if (Character.isUpperCase(c)) {\n c = Character.toLowerCase(c);\n } \n else if (Character.isLowerCase(c)) {\n c = Character.toUpperCase(c);\n }\n if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'A' || c == 'E' || c == 'I' || c == 'O'\n || c == 'U') {\n c = (char) ((int) c + 2);\n }\n sb.append(c);\n }\n return sb.toString();\n }\n"
},
"MIN_SUBARRAY_SUM": {
"buggy": " public static long min_subarray_sum(ArrayList<Long> nums) {\n long max_sum = 0;\n long s = 0;\n for(long num : nums) {\n s += num;\n if(s < 0) {\n s = 0;\n }\n max_sum = Math.max(s, max_sum);\n }\n if(max_sum == 0) {\n max_sum = -nums.get(0);\n for(int i = 1; i < nums.size(); i++) {\n max_sum = Math.max(max_sum, -nums.get(i));\n }\n }\n long min_sum = -max_sum;\n return min_sum;\n }\n",
"begin": 14,
"end": 32,
"fix": " public static long min_subarray_sum(ArrayList<Long> nums) {\n long max_sum = 0;\n long s = 0;\n for(long num : nums) {\n s += -num;\n if(s < 0) {\n s = 0;\n }\n max_sum = Math.max(s, max_sum);\n }\n if(max_sum == 0) {\n max_sum = -nums.get(0);\n for(int i = 1; i < nums.size(); i++) {\n max_sum = Math.max(max_sum, -nums.get(i));\n }\n }\n long min_sum = -max_sum;\n return min_sum;\n }\n"
},
"HISTOGRAM": {
"buggy": " public static HashMap<Character, Integer> histogram(String s) {\n HashMap<Character, Integer> res = new HashMap<Character, Integer>();\n if(s.isEmpty()) return res;\n String[] list_letters = s.split(\" \");\n int[] count_letter = new int[26];\n for(int i = 0; i < list_letters.length; i++) {\n char c = list_letters[i].charAt(0);\n count_letter[c - 'a']++;\n }\n int most_count = 0;\n for(int i = 0; i < 26; i++) {\n if(count_letter[i] < most_count) {\n most_count = count_letter[i];\n res.clear();\n res.put((char) ('a' + i), most_count);\n } else if(count_letter[i] == most_count) {\n res.put((char) ('a' + i), most_count);\n }\n }\n if(most_count == 0) res.clear();\n return res;\n }\n",
"begin": 19,
"end": 40,
"fix": " public static HashMap<Character, Integer> histogram(String s) {\n HashMap<Character, Integer> res = new HashMap<Character, Integer>();\n if(s.isEmpty()) return res;\n String[] list_letters = s.split(\" \");\n int[] count_letter = new int[26];\n for(int i = 0; i < list_letters.length; i++) {\n char c = list_letters[i].charAt(0);\n count_letter[c - 'a']++;\n }\n int most_count = 0;\n for(int i = 0; i < 26; i++) {\n if(count_letter[i] > most_count) {\n most_count = count_letter[i];\n res.clear();\n res.put((char) ('a' + i), most_count);\n } else if(count_letter[i] == most_count) {\n res.put((char) ('a' + i), most_count);\n }\n }\n if(most_count == 0) res.clear();\n return res;\n }\n"
},
"REMOVE_VOWELS": {
"buggy": " public static String remove_vowels(String string) {\n StringBuilder sb = new StringBuilder();\n for (char c : string.toCharArray()) {\n if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')\n continue;\n sb.append(c);\n }\n return sb.toString();\n }\n",
"begin": 18,
"end": 26,
"fix": " public static String remove_vowels(String string) {\n StringBuilder sb = new StringBuilder();\n for (char c : string.toCharArray()) {\n char c_lower = Character.toLowerCase(c);\n if (c_lower == 'a' || c_lower == 'e' || c_lower == 'i' || c_lower == 'o' || c_lower == 'u')\n continue;\n sb.append(c);\n }\n return sb.toString();\n }\n"
},
"SAME_CHARS": {
"buggy": " public static boolean same_chars(String s0, String s1) {\n ArrayList<Character> set0 = new ArrayList<Character>();\n ArrayList<Character> set1 = new ArrayList<Character>();\n\n for (char c0 : s0.toCharArray()) {\n set0.add(c0);\n }\n for (char c1 : s1.toCharArray()) {\n set1.add(c1);\n }\n return set0.equals(set1);\n }\n",
"begin": 20,
"end": 31,
"fix": " public static boolean same_chars(String s0, String s1) {\n HashSet<Character> set0 = new HashSet<Character>();\n HashSet<Character> set1 = new HashSet<Character>();\n\n for (char c0 : s0.toCharArray()) {\n set0.add(c0);\n }\n for (char c1 : s1.toCharArray()) {\n set1.add(c1);\n }\n return set0.equals(set1);\n }\n"
},
"STRANGE_SORT_LIST": {
"buggy": " public static List<Integer> strange_sort_list(List<Integer> lst) {\n List<Integer> result = new ArrayList<Integer>();\n\n boolean switched = true;\n while (lst.size() > 0) {\n if (switched) {\n result.add(Collections.min(lst));\n } else {\n result.add(Collections.max(lst));\n }\n }\n return result;\n }\n",
"begin": 17,
"end": 29,
"fix": " public static List<Integer> strange_sort_list(List<Integer> lst) {\n List<Integer> result = new ArrayList<Integer>();\n\n boolean switched = true;\n while (lst.size() > 0) {\n if (switched) {\n result.add(Collections.min(lst));\n } else {\n result.add(Collections.max(lst));\n }\n lst.remove(result.get(result.size() - 1));\n switched = (! switched);\n }\n return result;\n }\n"
},
"GENERATE_INTEGERS": {
"buggy": " public static ArrayList<Integer> generate_integers(int a, int b) {\n int lower = Math.max(2, a);\n int upper = Math.min(8, b);\n\n ArrayList<Integer> result = new ArrayList<Integer>();\n for (int i = lower; i <= upper; i += 1) {\n if (i % 2 == 0) result.add(i);\n }\n return result;\n }\n",
"begin": 14,
"end": 23,
"fix": " public static ArrayList<Integer> generate_integers(int a, int b) {\n int lower = Math.max(2, Math.min(a, b));\n int upper = Math.min(8, Math.max(a, b));\n\n ArrayList<Integer> result = new ArrayList<Integer>();\n for (int i = lower; i <= upper; i += 1) {\n if (i % 2 == 0) result.add(i);\n }\n return result;\n }\n"
},
"EAT": {
"buggy": " public static int[] eat(int number, int need, int remaining) {\n return new int[] {number + need, remaining - need};\n }\n",
"begin": 31,
"end": 33,
"fix": " public static int[] eat(int number, int need, int remaining) {\n if (need <= remaining) {\n return new int[] {number + need, remaining - need};\n }\n else {\n return new int[] {number + remaining , 0};\n }\n }\n"
},
"FIX_SPACES": {
"buggy": " public static String fix_spaces(String text) {\n String new_text = \"\";\n int i = 0;\n int start = 0;\n int end = 0;\n while (i < text.length()) {\n if (text.charAt(i) == ' ') end += 1;\n else {\n if (end - start > 2) new_text += \"-\" + text.substring(i, i + 1);\n else if (end - start > 0) {\n for (int j = start; j < end; j += 1) {\n new_text += \"_\";\n }\n new_text += text.substring(i, i + 1);\n } else {\n new_text += text.substring(i, i + 1);\n }\n start = i + 1;\n end = i + 1;\n }\n i += 1;\n }\n\n return new_text;\n }\n",
"begin": 13,
"end": 37,
"fix": " public static String fix_spaces(String text) {\n String new_text = \"\";\n int i = 0;\n int start = 0;\n int end = 0;\n while (i < text.length()) {\n if (text.charAt(i) == ' ') end += 1;\n else {\n if (end - start > 2) new_text += \"-\" + text.substring(i, i + 1);\n else if (end - start > 0) {\n for (int j = start; j < end; j += 1) {\n new_text += \"_\";\n }\n new_text += text.substring(i, i + 1);\n } else {\n new_text += text.substring(i, i + 1);\n }\n start = i + 1;\n end = i + 1;\n }\n i += 1;\n }\n\n if (end - start > 2) new_text += \"-\";\n else if (end - start > 0) {\n for (int j = start; j < end; j += 1) {\n new_text += \"_\";\n }\n }\n return new_text;\n }\n"
},
"MEDIAN": {
"buggy": " public static double median(int[] list) {\n Arrays.sort(list);\n\n if (list.length % 2 == 1) {\n return list[(int) (list.length / 2)];\n } else {\n return list[(int) (list.length / 2)] + list[(int) (list.length / 2) + 1] / 2;\n }\n }\n",
"begin": 12,
"end": 20,
"fix": " public static double median(int[] list) {\n Arrays.sort(list);\n\n if (list.length % 2 == 1) {\n return list[(int) (list.length / 2)];\n } else {\n return (list[(int) (list.length / 2)] + list[(int) (list.length / 2) - 1]) / 2.;\n }\n }\n"
},
"ANY_INT": {
"buggy": " public static boolean any_int(double x, double y, double z) {\n if ((int)x == x && (int)y == y) {\n if (x + y == z || x + z == y)\n return true;\n }\n return false;\n }\n",
"begin": 17,
"end": 23,
"fix": " public static boolean any_int(double x, double y, double z) {\n if ((int)x == x && (int)y == y && (int)z == z) {\n if (x + y == z || x + z == y || y + z == x)\n return true;\n }\n return false;\n }\n"
},
"CHOOSE_NUM": {
"buggy": " public static int choose_num(int x, int y) {\n if(x < y) return -1;\n if((y % 2) == 0) return y;\n if(x == y) return -1;\n return y - 1;\n }\n",
"begin": 14,
"end": 19,
"fix": " public static int choose_num(int x, int y) {\n if(x > y) return -1;\n if((y % 2) == 0) return y;\n if(x == y) return -1;\n return y - 1;\n }\n"
},
"PRIME_LENGTH": {
"buggy": " public static boolean prime_length(String string) {\n int l = string.length();\n if (l <= 1)\n return false;\n for (int i = 2; i < l; i += 1) {\n if (l - i == 0)\n return false;\n }\n return true;\n }\n",
"begin": 12,
"end": 21,
"fix": " public static boolean prime_length(String string) {\n int l = string.length();\n if (l <= 1)\n return false;\n for (int i = 2; i < l; i += 1) {\n if (l % i == 0)\n return false;\n }\n return true;\n }\n"
},
"NUMERICAL_LETTER_GRADE": {
"buggy": " public static String[] numerical_letter_grade(double[] grades) {\n String[] letter_grade = new String[grades.length];\n\n for (int i = 0; i < grades.length; i += 1) {\n double gpa = grades[i];\n if (gpa == 4.0)\n letter_grade[i] = \"A+\";\n else if (gpa > 3.7)\n letter_grade[i] = \"A\";\n else if (gpa > 3.3)\n letter_grade[i] = \"A-\";\n else if (gpa > 3.0)\n letter_grade[i] = \"B+\";\n else if (gpa > 2.7)\n letter_grade[i] = \"B\";\n else if (gpa > 2.3)\n letter_grade[i] = \"B-\";\n else if (gpa > 2.0)\n letter_grade[i] = \"C+\";\n else if (gpa > 1.3)\n letter_grade[i] = \"C-\";\n else if (gpa > 1.0)\n letter_grade[i] = \"D+\";\n else if (gpa > 1.7)\n letter_grade[i] = \"C\";\n else if (gpa > 0.7)\n letter_grade[i] = \"D\";\n else if (gpa > 0.0)\n letter_grade[i] = \"D-\";\n else\n letter_grade[i] = \"E\";\n }\n return letter_grade;\n }\n",
"begin": 26,
"end": 59,
"fix": " public static String[] numerical_letter_grade(double[] grades) {\n String[] letter_grade = new String[grades.length];\n\n for (int i = 0; i < grades.length; i += 1) {\n double gpa = grades[i];\n if (gpa == 4.0)\n letter_grade[i] = \"A+\";\n else if (gpa > 3.7)\n letter_grade[i] = \"A\";\n else if (gpa > 3.3)\n letter_grade[i] = \"A-\";\n else if (gpa > 3.0)\n letter_grade[i] = \"B+\";\n else if (gpa > 2.7)\n letter_grade[i] = \"B\";\n else if (gpa > 2.3)\n letter_grade[i] = \"B-\";\n else if (gpa > 2.0)\n letter_grade[i] = \"C+\";\n else if (gpa > 1.7)\n letter_grade[i] = \"C\";\n else if (gpa > 1.3)\n letter_grade[i] = \"C-\";\n else if (gpa > 1.0)\n letter_grade[i] = \"D+\";\n else if (gpa > 0.7)\n letter_grade[i] = \"D\";\n else if (gpa > 0.0)\n letter_grade[i] = \"D-\";\n else\n letter_grade[i] = \"E\";\n }\n return letter_grade;\n }\n"
},
"PARSE_MUSIC": {
"buggy": " public static List<Integer> parse_music(String music_string) {\n HashMap<String, Integer> note_map = new HashMap<String, Integer>();\n note_map.put(\"o\", 4);\n note_map.put(\"o|\", 2);\n note_map.put(\".|\", 1);\n\n List<Integer> result = new ArrayList<Integer>();\n\n for (String note : music_string.split(\" \")){\n result.add(note_map.get(note));\n }\n return result;\n }\n",
"begin": 8,
"end": 20,
"fix": " public static List<Integer> parse_music(String music_string) {\n HashMap<String, Integer> note_map = new HashMap<String, Integer>();\n note_map.put(\"o\", 4);\n note_map.put(\"o|\", 2);\n note_map.put(\".|\", 1);\n\n List<Integer> result = new ArrayList<Integer>();\n\n if (music_string.trim().equals(\"\"))\n return result;\n for (String note : music_string.split(\" \")){\n result.add(note_map.get(note));\n }\n return result;\n }\n"
},
"HOW_MANY_TIMES": {
"buggy": " public static int how_many_times(String string, String substring) {\n int times = 0;\n for (int i = 0; i < string.length() - substring.length(); i += 1) {\n if (string.substring(i, i + substring.length()).equals(substring)){\n times += 1;\n }\n }\n return times;\n }\n",
"begin": 4,
"end": 12,
"fix": " public static int how_many_times(String string, String substring) {\n int times = 0;\n for (int i = 0; i < string.length() - substring.length() + 1; i += 1) {\n if (string.substring(i, i + substring.length()).equals(substring)){\n times += 1;\n }\n }\n return times;\n }\n"
},
"MONOTONIC": {
"buggy": " public static boolean monotonic(int[] l) {\n int[] sorted = new int[l.length];\n int[] reverse_sorted = new int[l.length];\n\n sorted = l;\n \n Arrays.sort(sorted);\n \n for (int i = 0; i < l.length; i += 1)\n reverse_sorted[i] = sorted[l.length - i - 1]; \n \n if (Arrays.equals(l, sorted) || Arrays.equals(l, reverse_sorted))\n return true;\n return false;\n }\n",
"begin": 14,
"end": 28,
"fix": " public static boolean monotonic(int[] l) {\n int[] sorted = new int[l.length];\n int[] reverse_sorted = new int[l.length];\n\n System.arraycopy(l, 0, sorted, 0, l.length);\n \n Arrays.sort(sorted);\n \n for (int i = 0; i < l.length; i += 1)\n reverse_sorted[i] = sorted[l.length - i - 1]; \n \n if (Arrays.equals(l, sorted) || Arrays.equals(l, reverse_sorted))\n return true;\n return false;\n }\n"
},
"CYCPATTERN_CHECK": {
"buggy": " public static boolean cycpattern_check(String a, String b) {\n int l = b.length();\n String pat = b;\n for (int i = 0; i < a.length(); i += 1) {\n for (int j = 0; j < l; j += 1) {\n if (a.substring(i, i + l).equals(pat.substring(j, j + l))) return true;\n }\n }\n return false;\n }\n",
"begin": 12,
"end": 21,
"fix": " public static boolean cycpattern_check(String a, String b) {\n int l = b.length();\n String pat = b + b;\n for (int i = 0; i < a.length() - l + 1; i += 1) {\n for (int j = 0; j < l + 1; j += 1) {\n if (a.substring(i, i + l).equals(pat.substring(j, j + l))) return true;\n }\n }\n return false;\n }\n"
},
"DIGIT_SUM": {
"buggy": " public static int digit_sum(String s) {\n int result = 0;\n for (char c : s.toCharArray()) {\n if (c == ' ')\n break;\n if ('A' <= c && c <= 'Z')\n result += (int) c;\n }\n return result;\n }\n",
"begin": 16,
"end": 25,
"fix": " public static int digit_sum(String s) {\n int result = 0;\n for (char c : s.toCharArray()) {\n if ('A' <= c && c <= 'Z')\n result += (int) c;\n }\n return result;\n }\n"
},
"FRUIT_DISTRIBUTION": {
"buggy": " public static int fruit_distribution(String s, int n) {\n int result = n;\n\n for (String str : s.split(\" \")) {\n int cnt = Integer.parseInt(str);\n result -= cnt;\n }\n return result;\n }\n",
"begin": 15,
"end": 23,
"fix": " public static int fruit_distribution(String s, int n) {\n int result = n;\n\n for (String str : s.split(\" \")) {\n try {\n int cnt = Integer.parseInt(str);\n result -= cnt;\n } catch (Exception e) {\n continue;\n }\n }\n return result;\n }\n"
},
"CHANGE_BASE": {
"buggy": " public static String change_base(int x, int base) {\n String result = \"\";\n\n while (x > 0) {\n result = result + x % base;\n x = x - x / base;\n }\n return result;\n }\n",
"begin": 14,
"end": 22,
"fix": " public static String change_base(int x, int base) {\n String result = \"\";\n\n while (x > 0) {\n result = (x % base) + result;\n x = (int) x / base;\n }\n return result;\n }\n"
},
"SEPARATE_PAREN_GROUPS": {
"buggy": " public static List<String> separate_paren_groups(String paren_string) {\n List<String> result = new ArrayList<String>();\n String current_string = \"\";\n int current_depth = 0;\n\n for (char c : paren_string.toCharArray()) {\n if (c == '('){\n current_depth += 1;\n current_string += String.valueOf(c);\n } else {\n current_depth -= 1;\n current_string += String.valueOf(c);\n\n if (current_depth == 0){\n result.add(current_string);\n current_string = \"\";\n }\n }\n }\n return result;\n }\n",
"begin": 7,
"end": 27,
"fix": " public static List<String> separate_paren_groups(String paren_string) {\n List<String> result = new ArrayList<String>();\n String current_string = \"\";\n int current_depth = 0;\n\n for (char c : paren_string.toCharArray()) {\n if (c == '('){\n current_depth += 1;\n current_string += String.valueOf(c);\n } else if (c == ')'){\n current_depth -= 1;\n current_string += String.valueOf(c);\n\n if (current_depth == 0){\n result.add(current_string);\n current_string = \"\";\n }\n }\n }\n return result;\n }\n"
},
"UNIQUE": {
"buggy": " public static List<Integer> unique(List<Integer> l) {\n List<Integer> result = new ArrayList<Integer>();\n\n for (Integer n : l){\n result.add(n);\n }\n Collections.sort(result);\n\n return result;\n }\n",
"begin": 8,
"end": 17,
"fix": " public static List<Integer> unique(List<Integer> l) {\n List<Integer> result = new ArrayList<Integer>();\n\n for (Integer n : l){\n if (result.contains(n))\n continue;\n result.add(n);\n }\n Collections.sort(result);\n\n return result;\n }\n"
},
"TRIPLES_SUM_TO_ZERO": {
"buggy": " public static boolean triples_sum_to_zero(int[] numbers) {\n for (int i = 0; i < numbers.length; i += 1) {\n for (int j = i; j < numbers.length; j += 1) {\n for (int k = j; k < numbers.length; k += 1) {\n if (numbers[i] + numbers[j] + numbers[k] == 0)\n return true;\n }\n }\n }\n return false;\n }\n",
"begin": 21,
"end": 31,
"fix": " public static boolean triples_sum_to_zero(int[] numbers) {\n for (int i = 0; i < numbers.length; i += 1) {\n for (int j = i + 1; j < numbers.length; j += 1) {\n for (int k = j + 1; k < numbers.length; k += 1) {\n if (numbers[i] + numbers[j] + numbers[k] == 0)\n return true;\n }\n }\n }\n return false;\n }\n"
},
"ROLLING_MAX": {
"buggy": " public static List<Integer> rolling_max(List<Integer> numbers) {\n List<Integer> result = new ArrayList<Integer>();\n Integer running_max = null;\n\n for (Integer n : numbers){\n running_max = Math.max(running_max, n);\n result.add(running_max);\n }\n return result;\n }\n",
"begin": 7,
"end": 16,
"fix": " public static List<Integer> rolling_max(List<Integer> numbers) {\n List<Integer> result = new ArrayList<Integer>();\n Integer running_max = null;\n\n for (Integer n : numbers){\n if (running_max == null){\n running_max = n;\n }\n else{\n running_max = Math.max(running_max, n);\n }\n result.add(running_max);\n }\n return result;\n }\n"
},
"SUM_PRODUCT": {
"buggy": " public static Integer[] sum_product(List<Integer> numbers) {\n Integer[] result = new Integer[2];\n for (Integer n : numbers){\n result[0] += n;\n result[1] *= n;\n }\n return result;\n }\n",
"begin": 6,
"end": 13,
"fix": " public static Integer[] sum_product(List<Integer> numbers) {\n Integer[] result = new Integer[]{0, 1};\n for (Integer n : numbers){\n result[0] += n;\n result[1] *= n;\n }\n return result;\n }\n"
},
"EXCHANGE": {
"buggy": " public static String exchange(ArrayList<Integer> lst1, ArrayList<Integer> lst2) {\n int odd = 0, even = 0;\n for(int i : lst2) {\n if((i % 2) == 1) even++;\n }\n for(int i : lst2) {\n if((i % 2) == 0) even++;\n }\n if(even >= odd) {\n return \"YES\";\n }\n return \"NO\";\n }\n",
"begin": 20,
"end": 32,
"fix": " public static String exchange(ArrayList<Integer> lst1, ArrayList<Integer> lst2) {\n int odd = 0, even = 0;\n for(int i : lst1) {\n if((i % 2) == 1) odd++;\n }\n for(int i : lst2) {\n if((i % 2) == 0) even++;\n }\n if(even >= odd) {\n return \"YES\";\n }\n return \"NO\";\n }\n"
},
"GREATEST_COMMON_DIVISOR": {
"buggy": " public static int greatest_common_divisor(int a, int b){\n while (b > 0) {\n a = b;\n b = a % b;\n }\n return a;\n }\n",
"begin": 4,
"end": 10,
"fix": " public static int greatest_common_divisor(int a, int b){\n while (b > 0) {\n int tmp = a;\n a = b;\n b = tmp % b;\n }\n return a;\n }\n"
}
}