File: Utility.cs

package info (click to toggle)
cadencii 3.3.9%2Bsvn20110818.r1732-2
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 35,764 kB
  • ctags: 26,929
  • sloc: cs: 160,836; java: 42,449; cpp: 7,605; ansic: 1,728; perl: 1,087; makefile: 236; php: 142; xml: 117; sh: 21
file content (1815 lines) | stat: -rw-r--r-- 138,864 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
/*
 * Utility.cs
 * Copyright © 2010-2011 kbinani, HAL
 *
 * This file is part of org.kbinani.cadencii.
 *
 * org.kbinani.cadencii is free software; you can redistribute it and/or
 * modify it under the terms of the GPLv3 License.
 *
 * org.kbinani.cadencii is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 */
#if JAVA
package org.kbinani.cadencii;

import java.util.*;
import java.io.*;
import java.awt.*;
import org.kbinani.*;
import org.kbinani.vsq.*;
import org.kbinani.windows.forms.*;
import org.kbinani.xml.*;
import org.kbinani.apputil.*;
#else
using System;
using System.CodeDom.Compiler;
using System.Reflection;
using Microsoft.CSharp;
using org.kbinani.apputil;
using org.kbinani.java.io;
using org.kbinani.java.util;
using org.kbinani.vsq;
using org.kbinani.windows.forms;
using org.kbinani.xml;
using org.kbinani.java.awt;

namespace org.kbinani.cadencii
{
    using boolean = System.Boolean;
    using Integer = System.Int32;
#endif

    public class Utility
    {
        private const String CONFIG_DIR_NAME = "Cadencii";
        public static readonly CurveType[] CURVE_USAGE = new CurveType[]{ CurveType.DYN,
                                                                          CurveType.BRE,
                                                                          CurveType.BRI,
                                                                          CurveType.CLE,
                                                                          CurveType.OPE,
                                                                          CurveType.GEN,
                                                                          CurveType.POR,
                                                                          CurveType.PIT,
                                                                          CurveType.PBS,
                                                                          CurveType.VibratoRate,
                                                                          CurveType.VibratoDepth,
                                                                          CurveType.harmonics,
                                                                          CurveType.fx2depth,
                                                                          CurveType.reso1amp,
                                                                          CurveType.reso1bw,
                                                                          CurveType.reso1freq,
                                                                          CurveType.reso2amp,
                                                                          CurveType.reso2bw,
                                                                          CurveType.reso2freq,
                                                                          CurveType.reso3amp,
                                                                          CurveType.reso3bw,
                                                                          CurveType.reso3freq,
                                                                          CurveType.reso4amp,
                                                                          CurveType.reso4bw,
                                                                          CurveType.reso4freq };
        private static int[] RANDOMIZE_PIT_PATTERN1 = null;
        private static int[] RANDOMIZE_PIT_PATTERN2 = null;
        private static int[] RANDOMIZE_PIT_PATTERN3 = null;
        /// <summary>
        /// 使用中のアセンブリ・キャッシュのフルパス
        /// </summary>
        private static Vector<String> usedAssemblyChache = new Vector<String>();

        /// <summary>
        /// vocaloid.shに渡すために,パス文字列を正規化します
        /// </summary>
        public static String normalizePath( String path )
        {
#if JAVA
            if( path.indexOf( "~" ) >= 0 ){
                String usr = System.getProperty( "user.name" );
                String tild = "/Users/" + usr;
                path = path.replace( "~", tild );
            }
#endif
            path = path.Replace( "\\", "\\\\\\\\" );
            return path;
        }

        /// <summary>
        /// 実行中のUTAUがあれば,その実行ファイルのパスを調べます(Windowsのみ)
        /// </summary>
        /// <returns></returns>
        public static String getExecutingUtau()
        {
#if !JAVA
            foreach ( System.Diagnostics.Process p in System.Diagnostics.Process.GetProcessesByName( "utau" ) ) {
                return p.MainModule.FileName;
            }
#endif
            return "";
        }

        /// <summary>
        /// 指定した歌声合成器の,指定したプログラムチェンジ,Language値を表現するVsqIDを作成します
        /// </summary>
        /// <param name="renderer_kind"></param>
        /// <param name="program"></param>
        /// <param name="language"></param>
        /// <returns></returns>
        public static VsqID getSingerID( RendererKind renderer_kind, int program, int language )
        {
            VsqID item = null;
            if ( renderer_kind == RendererKind.VOCALOID1 ) {
                item = VocaloSysUtil.getSingerID( language, program, SynthesizerType.VOCALOID1 );
            } else if ( renderer_kind == RendererKind.VOCALOID2 ) {
                item = VocaloSysUtil.getSingerID( language, program, SynthesizerType.VOCALOID2 );
            } else if ( renderer_kind == RendererKind.UTAU || renderer_kind == RendererKind.VCNT ) {
                item = AppManager.getSingerIDUtau( language, program );
            } else if ( renderer_kind == RendererKind.AQUES_TONE ) {
                item = AppManager.getSingerIDAquesTone( program );
            }
            return item;
        }

        public static int[] getRandomizePitPattern1() {
            if ( RANDOMIZE_PIT_PATTERN1 == null ) {
                RANDOMIZE_PIT_PATTERN1 = new int[] {
                    1310, 1310, 1309, 1309, 1308, 1308, 1308, 1307, 1307, 1306, 1306, 1305, 1305, 1305, 1304, 1304, 1303, 1303, 1303, 1302, 1302, 1301, 1301, 1300, 1300,
                    1300, 1299, 1299, 1298, 1298, 1297, 1297, 1297, 1296, 1296, 1295, 1295, 1294, 1294, 1294, 1293, 1293, 1292, 1292, 1292, 1291, 1291, 1290, 1290, 1289,
                    1289, 1289, 1288, 1288, 1287, 1287, 1286, 1286, 1286, 1285, 1285, 1284, 1284, 1284, 1283, 1283, 1282, 1282, 1281, 1281, 1281, 1280, 1280, 1279, 1279,
                    1279, 1278, 1278, 1277, 1277, 1276, 1276, 1276, 1275, 1275, 1274, 1274, 1273, 1273, 1273, 1272, 1272, 1271, 1271, 1270, 1269, 1267, 1265, 1263, 1261,
                    1259, 1257, 1255, 1253, 1251, 1249, 1247, 1245, 1243, 1241, 1239, 1237, 1235, 1233, 1232, 1229, 1226, 1223, 1221, 1218, 1216, 1213, 1210, 1208, 1205,
                    1202, 1199, 1197, 1194, 1192, 1189, 1186, 1183, 1181, 1178, 1176, 1173, 1170, 1167, 1165, 1162, 1160, 1157, 1154, 1152, 1143, 1136, 1127, 1120, 1111,
                    1108, 1104, 1100, 1096, 1092, 1088, 1084, 1080, 1076, 1072, 1070, 1067, 1065, 1062, 1059, 1056, 1054, 1051, 1049, 1046, 1043, 1040, 1038, 1035, 1033,
                    1030, 1028, 1026, 1024, 1023, 1021, 1019, 1017, 1014, 1012, 1010, 1009, 1007, 1005, 1003, 1000, 998, 996, 995, 993, 989, 984, 981, 977, 972,
                    968, 965, 961, 956, 952, 951, 949, 948, 946, 945, 943, 942, 940, 938, 937, 935, 934, 932, 931, 929, 928, 926, 924, 923, 921,
                    920, 918, 917, 915, 913, 914, 914, 915, 915, 916, 916, 917, 917, 918, 918, 919, 919, 919, 920, 920, 921, 921, 922, 922, 923,
                    923, 924, 924, 925, 925, 925, 926, 926, 927, 927, 928, 928, 929, 929, 930, 930, 930, 931, 931, 932, 932, 933, 933, 934, 934,
                    935, 935, 936, 936, 936, 937, 937, 938, 938, 939, 939, 940, 940, 941, 941, 941, 942, 942, 943, 943, 944, 944, 945, 945, 946,
                    946, 947, 947, 947, 948, 948, 949, 949, 950, 950, 951, 951, 952, 952, 952, 954, 956, 957, 959, 961, 962, 964, 965, 967, 968,
                    970, 972, 973, 975, 977, 978, 980, 981, 983, 984, 986, 988, 989, 991, 993, 996, 1000, 1005, 1009, 1012, 1017, 1021, 1024, 1028, 1033,
                    1035, 1037, 1038, 1040, 1042, 1044, 1047, 1049, 1051, 1052, 1054, 1056, 1058, 1061, 1063, 1065, 1066, 1068, 1070, 1072, 1076, 1080, 1084, 1088, 1092,
                    1096, 1100, 1104, 1108, 1111, 1115, 1120, 1123, 1127, 1132, 1136, 1139, 1143, 1148, 1152, 1160, 1167, 1176, 1183, 1192, 1199, 1208, 1216, 1223, 1232,
                    1235, 1239, 1243, 1247, 1251, 1255, 1259, 1263, 1267, 1270, 1279, 1286, 1294, 1303, 1310, 1314, 1319, 1322, 1326, 1331, 1335, 1338, 1342, 1347, 1351,
                    1359, 1366, 1375, 1382, 1391, 1393, 1396, 1398, 1401, 1404, 1407, 1409, 1412, 1414, 1417, 1420, 1422, 1425, 1428, 1431, 1430, 1429, 1428, 1427, 1426,
                    1425, 1424, 1423, 1422, 1422, 1421, 1420, 1419, 1418, 1417, 1416, 1415, 1414, 1414, 1413, 1412, 1411, 1410, 1409, 1408, 1407, 1407, 1406, 1405, 1404,
                    1403, 1402, 1401, 1400, 1399, 1398, 1398, 1397, 1396, 1395, 1394, 1393, 1392, 1391, 1391, 1387, 1382, 1379, 1375, 1370, 1366, 1363, 1359, 1354, 1351,
                    1347, 1342, 1338, 1335, 1331, 1326, 1322, 1319, 1314, 1310, 1303, 1294, 1286, 1279, 1270, 1263, 1255, 1247, 1239, 1232, 1229, 1226, 1223, 1221, 1218,
                    1216, 1213, 1210, 1208, 1205, 1202, 1199, 1197, 1194, 1192, 1183, 1176, 1167, 1160, 1152, 1143, 1136, 1127, 1120, 1111, 1104, 1096, 1088, 1080, 1072,
                    1068, 1065, 1061, 1056, 1052, 1049, 1044, 1040, 1037, 1033, 1031, 1029, 1028, 1026, 1024, 1023, 1021, 1020, 1018, 1017, 1015, 1013, 1012, 1010, 1009,
                    1007, 1005, 1004, 1002, 1000, 999, 997, 996, 994, 993, 990, 987, 984, 982, 979, 977, 974, 971, 968, 966, 963, 961, 958, 955, 952,
                    950, 947, 945, 942, 939, 937, 934, 932, 929, 926, 924, 921, 919, 916, 913, 911, 908, 906, 903, 900, 897, 895, 892, 890, 887,
                    884, 881, 879, 876, 873, 869, 866, 862, 857, 853, 850, 845, 841, 838, 834, 831, 828, 825, 823, 820, 817, 815, 812, 810, 807,
                    804, 802, 799, 796, 793, 791, 788, 786, 783, 780, 778, 775, 773, 770, 768, 765, 762, 760, 757, 755, 756, 757, 758, 759, 761,
                    762, 763, 764, 765, 767, 768, 769, 770, 772, 773, 774, 775, 776, 778, 779, 780, 781, 782, 784, 785, 786, 787, 789, 790, 791,
                    792, 793, 795, 796, 797, 798, 799, 801, 802, 803, 804, 806, 807, 808, 809, 810, 812, 813, 814, 815, 816, 818, 819, 820, 821,
                    823, 824, 825, 826, 827, 829, 830, 831, 832, 834, 841, 850, 857, 866, 873, 881, 889, 897, 905, 913, 921, 929, 937, 945, 952,
                    961, 968, 977, 984, 993, 978, 964, 950, 935, 921, 907, 892, 878, 864, 849, 835, 821, 806, 792, 778, 763, 749, 735, 720, 706,
                    692, 677, 663, 649, 634, 637, 640, 642, 645, 648, 651, 653, 656, 658, 661, 664, 667, 669, 672, 675, 677, 680, 682, 685, 688,
                    691, 693, 696, 698, 701, 704, 706, 709, 712, 715, 716, 719, 721, 722, 725, 726, 729, 731, 732, 735, 736, 739, 740, 742, 745,
                    746, 749, 750, 752, 755, 758, 762, 766, 770, 774, 778, 782, 786, 790, 793, 802, 810, 817, 825, 834, 838, 841, 845, 850, 853,
                    857, 862, 866, 869, 873, 881, 890, 897, 906, 913, 915, 917, 919, 921, 923, 925, 927, 929, 931, 933, 935, 937, 939, 941, 943,
                    945, 947, 949, 951, 952, 952, 951, 951, 950, 949, 949, 948, 947, 947, 946, 945, 945, 944, 943, 943, 942, 941, 941, 940, 939,
                    939, 938, 938, 937, 936, 936, 935, 934, 934, 933, 932, 932, 931, 930, 930, 929, 928, 928, 927, 926, 926, 925, 925, 924, 923,
                    923, 922, 921, 921, 920, 919, 919, 918, 917, 917, 916, 915, 915, 914, 913, 910, 906, 901, 897, 894, 890, 885, 881, 878, 873,
                    871, 868, 866, 863, 860, 857, 855, 852, 850, 847, 844, 841, 839, 836, 834, 831, 829, 827, 825, 824, 822, 820, 817, 816, 813,
                    812, 810, 807, 806, 803, 802, 799, 797, 796, 793, 786, 778, 770, 762, 755, 746, 739, 731, 722, 715, 706, 698, 691, 682, 675,
                    671, 667, 662, 658, 655, 651, 647, 642, 638, 634, 627, 618, 611, 603, 594, 593, 591, 589, 587, 585, 583, 581, 579, 577, 575,
                    573, 571, 569, 567, 565, 563, 561, 559, 557, 556, 553, 550, 547, 545, 542, 540, 537, 534, 531, 529, 526, 523, 521, 518, 516,
                    512, 507, 503, 500, 496, 492, 487, 483, 480, 476, 473, 470, 467, 465, 462, 459, 457, 454, 452, 449, 446, 443, 441, 438, 436,
                    432, 428, 424, 420, 416, 412, 408, 404, 400, 396, 389, 381, 372, 365, 356, 352, 348, 345, 341, 337, 332, 328, 325, 321, 317,
                    317, 317, 318, 318, 318, 319, 319, 319, 320, 320, 320, 321, 321, 321, 322, 322, 322, 323, 323, 323, 324, 324, 325, 325, 325,
                    326, 326, 326, 327, 327, 327, 328, 328, 328, 329, 329, 329, 330, 330, 330, 331, 331, 331, 332, 332, 332, 333, 333, 334, 334,
                    334, 335, 335, 335, 336, 336, 336, 337, 337, 337, 338, 338, 338, 339, 339, 339, 340, 340, 341, 341, 341, 342, 342, 342, 343,
                    343, 343, 344, 344, 344, 345, 345, 345, 346, 346, 346, 347, 347, 347, 348, 348, 348, 349, 349, 350, 350, 350, 351, 351, 351,
                    352, 352, 352, 353, 353, 353, 354, 354, 354, 355, 355, 355, 356, 356, 356, 359, 362, 365, 367, 370, 372, 375, 378, 381, 383,
                    386, 389, 391, 394, 396, 399, 402, 404, 407, 409, 412, 415, 417, 420, 422, 425, 428, 430, 433, 436, 443, 452, 459, 467, 476,
                    483, 492, 500, 507, 516, 523, 531, 540, 547, 556, 563, 571, 579, 587, 594, 598, 603, 607, 611, 614, 618, 622, 627, 631, 634,
                    642, 651, 658, 667, 675, 682, 691, 698, 706, 715, 722, 731, 739, 746, 755, 762, 770, 778, 786, 793, 797, 802, 806, 810, 813,
                    817, 822, 825, 829, 834, 841, 850, 857, 866, 873, 878, 881, 885, 890, 894, 897, 901, 906, 910, 913, 917, 921, 925, 929, 933,
                    937, 941, 945, 949, 952, 961, 968, 977, 984, 993, 992, 992, 991, 991, 990, 990, 989, 989, 988, 988, 987, 987, 986, 986, 985,
                    985, 984, 984, 984, 983, 983, 982, 982, 981, 981, 980, 980, 979, 979, 978, 978, 977, 977, 977, 976, 976, 975, 975, 974, 974,
                    973, 973, 972, 972, 971, 971, 970, 970, 969, 969, 968, 968, 968, 967, 967, 966, 966, 965, 965, 964, 964, 963, 963, 962, 962,
                    961, 961, 961, 960, 960, 959, 959, 958, 958, 957, 957, 956, 956, 955, 955, 954, 954, 953, 953, 952, 951, 950, 949, 947, 946,
                    945, 943, 942, 941, 939, 938, 937, 936, 934, 933, 932, 930, 929, 928, 926, 925, 924, 923, 921, 920, 919, 917, 916, 915, 913,
                    906, 897, 890, 881, 873, 871, 869, 867, 866, 864, 862, 859, 857, 855, 853, 852, 850, 848, 845, 843, 841, 839, 838, 836, 834,
                    831, 828, 825, 823, 820, 817, 815, 812, 810, 807, 804, 802, 799, 796, 793, 790, 786, 782, 778, 774, 770, 766, 762, 758, 755,
                    752, 749, 746, 744, 741, 739, 736, 733, 731, 728, 725, 722, 720, 717, 715, 711, 706, 702, 698, 695, 691, 686, 682, 678, 675,
                    671, 667, 662, 658, 655, 651, 647, 642, 638, 634, 631, 627, 622, 618, 614, 611, 607, 603, 598, 594, 592, 589, 587, 584, 581,
                    579, 576, 574, 571, 568, 566, 563, 561, 558, 556, 551, 547, 543, 540, 536, 531, 527, 523, 520, 516, 512, 507, 503, 500, 496,
                    492, 487, 483, 480, 476, 473, 470, 467, 465, 462, 459, 457, 454, 452, 449, 446, 443, 441, 438, 436, 432, 428, 424, 420, 416,
                    412, 408, 404, 400, 396, 394, 391, 389, 386, 383, 381, 378, 375, 372, 370, 367, 365, 362, 359, 356, 348, 341, 332, 325, 317,
                    314, 311, 308, 306, 303, 301, 298, 295, 292, 290, 287, 284, 282, 279, 277, 269, 261, 253, 245, 237, 236, 234, 233, 231, 230,
                    228, 226, 225, 223, 221, 220, 218, 217, 215, 213, 212, 210, 209, 207, 206, 204, 202, 201, 199, 197, 195, 192, 190, 187, 184,
                    182, 179, 176, 173, 171, 168, 166, 163, 160, 157, 157, 156, 156, 155, 154, 154, 153, 153, 152, 151, 151, 150, 149, 149, 148,
                    148, 147, 146, 146, 145, 145, 144, 143, 143, 142, 142, 141, 140, 140, 139, 138, 138, 137, 137, 136, 135, 135, 134, 133, 133,
                    132, 132, 131, 130, 130, 129, 129, 128, 127, 127, 126, 126, 125, 124, 124, 123, 122, 122, 121, 121, 120, 119, 119, 118, 118,
                    118, 119, 119, 120, 121, 122, 122, 123, 123, 124, 125, 126, 126, 127, 128, 128, 129, 129, 130, 131, 132, 132, 133, 133, 134,
                    135, 136, 136, 137, 137, 138, 139, 139, 140, 141, 142, 142, 143, 143, 144, 145, 146, 146, 147, 147, 148, 149, 149, 150, 151,
                    152, 152, 153, 153, 154, 155, 156, 156, 157, 157, 159, 160, 161, 162, 163, 164, 166, 167, 168, 169, 170, 171, 172, 173, 175,
                    176, 177, 178, 179, 180, 182, 183, 184, 185, 186, 187, 188, 190, 191, 192, 193, 194, 195, 196, 197, 201, 206, 210, 213, 217,
                    221, 226, 230, 234, 237, 241, 245, 249, 253, 257, 261, 265, 269, 273, 277, 284, 292, 301, 308, 317, 325, 332, 341, 348, 356,
                    365, 372, 381, 389, 396, 398, 399, 400, 402, 403, 404, 406, 407, 408, 409, 411, 412, 413, 415, 416, 417, 419, 420, 421, 422,
                    424, 425, 426, 428, 429, 430, 432, 433, 434, 436, 439, 443, 448, 452, 456, 459, 463, 467, 472, 476, 476, 477, 478, 478, 479,
                    480, 481, 481, 482, 483, 483, 484, 485, 486, 486, 487, 488, 489, 489, 490, 491, 492, 492, 493, 494, 494, 495, 496, 497, 497,
                    498, 499, 500, 500, 501, 502, 502, 503, 504, 505, 505, 506, 507, 507, 508, 509, 510, 510, 511, 512, 513, 513, 514, 515, 516,
                    523, 531, 540, 547, 556, 557, 559, 561, 563, 565, 567, 569, 571, 573, 575, 577, 579, 581, 583, 585, 587, 589, 591, 593, 594,
                    594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594,
                    594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594,
                    594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 591, 587, 583, 579, 575,
                    571, 567, 563, 559, 556, 547, 540, 531, 523, 516, 512, 507, 503, 500, 496, 492, 487, 483, 480, 476, 467, 459, 452, 443, 436,
                    432, 428, 424, 420, 416, 412, 408, 404, 400, 396, 392, 389, 385, 381, 376, 372, 368, 365, 361, 356, 355, 353, 352, 350, 348,
                    347, 345, 344, 342, 341, 339, 337, 336, 334, 332, 331, 329, 328, 326, 325, 323, 321, 320, 318, 317, 314, 311, 308, 306, 303,
                    301, 298, 295, 292, 290, 287, 284, 282, 279, 277, 275, 273, 271, 269, 267, 265, 263, 261, 259, 257, 255, 253, 251, 249, 247,
                    245, 243, 241, 239, 237, 230, 221, 213, 206, 197, 193, 190, 186, 182, 177, 173, 170, 166, 162, 157, 155, 152, 149, 147, 144,
                    142, 139, 136, 133, 131, 128, 126, 123, 120, 118, 116, 114, 112, 110, 108, 106, 104, 102, 100, 98, 96, 94, 92, 90, 88,
                    86, 84, 82, 80, 78, 79, 80, 81, 81, 82, 83, 83, 84, 85, 86, 86, 87, 88, 88, 89, 90, 91, 91, 92, 93,
                    93, 94, 95, 96, 96, 97, 98, 98, 99, 100, 100, 101, 102, 103, 103, 104, 105, 105, 106, 107, 108, 108, 109, 110, 110,
                    111, 112, 113, 113, 114, 115, 115, 116, 117, 118, 117, 116, 116, 115, 115, 114, 114, 113, 112, 112, 111, 111, 110, 110, 109,
                    109, 108, 107, 107, 106, 106, 105, 105, 104, 104, 103, 102, 102, 101, 101, 100, 100, 99, 99, 98, 97, 97, 96, 96, 95,
                    95, 94, 94, 93, 92, 92, 91, 91, 90, 90, 89, 89, 88, 87, 87, 86, 86, 85, 85, 84, 84, 83, 82, 82, 81,
                    81, 80, 80, 79, 78, 76, 73, 70, 68, 65, 63, 60, 57, 55, 52, 49, 46, 44, 41, 38, 40, 41, 42, 43, 44,
                    45, 46, 48, 49, 50, 51, 52, 53, 55, 56, 57, 58, 59, 60, 61, 63, 64, 65, 66, 67, 68, 69, 70, 72, 73,
                    74, 75, 76, 77, 78, 86, 94, 102, 110, 118, 126, 133, 142, 149, 157, 166, 173, 182, 190, 197, 206, 213, 221, 230, 237,
                    241, 245, 249, 253, 257, 261, 265, 269, 273, 277, 279, 282, 284, 287, 290, 292, 295, 298, 301, 303, 306, 308, 311, 314, 317,
                    321, 325, 328, 332, 337, 341, 345, 348, 352, 356, 365, 372, 381, 389, 396, 397, 397, 397, 398, 398, 398, 398, 399, 399, 399,
                    400, 400, 400, 400, 401, 401, 401, 402, 402, 402, 402, 403, 403, 403, 403, 404, 404, 404, 405, 405, 405, 405, 406, 406, 406,
                    407, 407, 407, 407, 408, 408, 408, 408, 409, 409, 409, 410, 410, 410, 410, 411, 411, 411, 412, 412, 412, 412, 413, 413, 413,
                    413, 414, 414, 414, 415, 415, 415, 415, 416, 416, 416, 417, 417, 417, 417, 418, 418, 418, 419, 419, 419, 419, 420, 420, 420,
                    420, 421, 421, 421, 422, 422, 422, 422, 423, 423, 423, 424, 424, 424, 424, 425, 425, 425, 425, 426, 426, 426, 427, 427, 427,
                    427, 428, 428, 428, 429, 429, 429, 429, 430, 430, 430, 430, 431, 431, 431, 432, 432, 432, 432, 433, 433, 433, 434, 434, 434,
                    434, 435, 435, 435, 436, 439, 443, 448, 452, 456, 459, 463, 467, 472, 476, 483, 492, 500, 507, 516, 523, 531, 540, 547, 556,
                    559, 563, 567, 571, 575, 579, 583, 587, 591, 594, 598, 603, 607, 611, 614, 618, 622, 627, 631, 634, 638, 642, 647, 651, 655,
                    658, 662, 667, 671, 675, 674, 673, 672, 672, 671, 671, 670, 669, 668, 668, 667, 667, 666, 665, 665, 664, 663, 662, 662, 661,
                    661, 660, 659, 658, 658, 657, 657, 656, 655, 655, 654, 653, 652, 652, 651, 651, 650, 649, 648, 648, 647, 647, 646, 645, 645,
                    644, 643, 642, 642, 641, 641, 640, 639, 638, 638, 637, 637, 636, 635, 634, 632, 631, 628, 627, 624, 622, 621, 618, 617, 614,
                    612, 611, 608, 607, 604, 603, 601, 598, 597, 594, 591, 587, 583, 579, 575, 571, 567, 563, 559, 556, 554, 551, 550, 547, 546,
                    543, 541, 540, 537, 536, 533, 531, 530, 527, 526, 523, 521, 520, 517, 516, 516, 517, 518, 519, 520, 520, 521, 522, 523, 524,
                    525, 525, 526, 527, 528, 529, 530, 530, 531, 532, 533, 534, 535, 535, 536, 537, 538, 539, 540, 540, 541, 542, 543, 544, 545,
                    545, 546, 547, 548, 549, 550, 550, 551, 552, 553, 554, 555, 555, 556, 557, 558, 559, 560, 560, 561, 562, 563, 564, 565, 565,
                    566, 567, 568, 569, 570, 570, 571, 572, 573, 574, 575, 575, 576, 577, 578, 579, 580, 580, 581, 582, 583, 584, 585, 585, 586,
                    587, 588, 589, 590, 590, 591, 592, 593, 594, 594, 603, 611, 618, 627, 634, 642, 651, 658, 667, 675, 682, 691, 698, 706, 715,
                    722, 731, 739, 746, 755, 762, 770, 778, 786, 793, 797, 802, 806, 810, 813, 817, 822, 825, 829, 834, 833, 832, 831, 831, 830,
                    829, 828, 828, 827, 826, 825, 825, 824, 823, 823, 822, 821, 820, 820, 819, 818, 817, 817, 816, 815, 815, 814, 813, 812, 812,
                    811, 810, 810, 809, 808, 807, 807, 806, 805, 804, 804, 803, 802, 802, 801, 800, 799, 799, 798, 797, 796, 796, 795, 794, 793,
                    790, 786, 782, 778, 774, 770, 766, 762, 758, 755, 752, 750, 749, 746, 745, 742, 740, 739, 736, 735, 732, 731, 729, 726, 725,
                    722, 721, 719, 716, 715, 711, 706, 702, 698, 695, 691, 686, 682, 678, 675, 672, 669, 667, 664, 661, 658, 656, 653, 651, 648,
                    645, 642, 640, 637, 634, 631, 627, 622, 618, 614, 611, 607, 603, 598, 594, 591, 587, 583, 579, 575, 571, 567, 563, 559, 555,
                    551, 547, 543, 539, 535, 531, 527, 523, 519, 516, 520, 523, 527, 531, 536, 540, 543, 547, 551, 556, 556, 556, 556, 556, 556,
                    557, 557, 557, 557, 557, 557, 558, 558, 558, 558, 558, 558, 559, 559, 559, 559, 559, 559, 560, 560, 560, 560, 560, 560, 561,
                    561, 561, 561, 561, 561, 562, 562, 562, 562, 562, 562, 563, 563, 563, 563, 563, 563, 564, 564, 564, 564, 564, 564, 565, 565,
                    565, 565, 565, 566, 566, 566, 566, 566, 566, 567, 567, 567, 567, 567, 567, 568, 568, 568, 568, 568, 568, 569, 569, 569, 569,
                    569, 569, 570, 570, 570, 570, 570, 570, 571, 571, 571, 571, 571, 571, 572, 572, 572, 572, 572, 572, 573, 573, 573, 573, 573,
                    573, 574, 574, 574, 574, 574, 574, 575, 575, 575, 575, 575, 576, 576, 576, 576, 576, 576, 577, 577, 577, 577, 577, 577, 578,
                    578, 578, 578, 578, 578, 579, 579, 579, 579, 579, 579, 580, 580, 580, 580, 580, 580, 581, 581, 581, 581, 581, 581, 582, 582,
                    582, 582, 582, 582, 583, 583, 583, 583, 583, 583, 584, 584, 584, 584, 584, 584, 585, 585, 585, 585, 585, 586, 586, 586, 586,
                    586, 586, 587, 587, 587, 587, 587, 587, 588, 588, 588, 588, 588, 588, 589, 589, 589, 589, 589, 589, 590, 590, 590, 590, 590,
                    590, 591, 591, 591, 591, 591, 591, 592, 592, 592, 592, 592, 592, 593, 593, 593, 593, 593, 593, 594, 594, 594, 594, 594, 594,
                    594, 593, 592, 591, 590, 589, 588, 587, 586, 585, 584, 583, 582, 581, 580, 579, 578, 577, 576, 575, 574, 573, 572, 571, 570,
                    569, 568, 567, 566, 565, 564, 563, 562, 561, 560, 559, 558, 557, 556, 556, 555, 555, 554, 554, 553, 553, 552, 552, 551, 551,
                    550, 550, 549, 549, 548, 548, 547, 547, 547, 546, 546, 545, 545, 544, 544, 543, 543, 542, 542, 541, 541, 540, 540, 540, 539,
                    539, 538, 538, 537, 537, 536, 536, 535, 535, 534, 534, 533, 533, 532, 532, 531, 531, 531, 530, 530, 529, 529, 528, 528, 527,
                    527, 526, 526, 525, 525, 524, 524, 523, 523, 523, 522, 522, 521, 521, 520, 520, 519, 519, 518, 518, 517, 517, 516, 516, 516,
                    512, 507, 503, 500, 496, 492, 487, 483, 480, 476, 474, 472, 471, 469, 467, 466, 464, 463, 461, 459, 458, 456, 455, 453, 452,
                    450, 448, 447, 445, 443, 442, 440, 439, 437, 436, 433, 430, 428, 425, 422, 420, 417, 415, 412, 409, 407, 404, 402, 399, 396,
                    394, 391, 389, 386, 383, 381, 378, 375, 372, 370, 367, 365, 362, 359, 356, 354, 351, 348, 346, 343, 341, 338, 335, 332, 330,
                    327, 325, 322, 319, 317, 314, 311, 308, 306, 303, 301, 298, 295, 292, 290, 287, 284, 282, 279, 277, 273, 269, 265, 261, 257,
                    253, 249, 245, 241, 237, 234, 230, 226, 221, 217, 213, 210, 206, 201, 197, 195, 192, 190, 187, 184, 182, 179, 176, 173, 171,
                    168, 166, 163, 160, 157, 153, 149, 146, 142, 137, 133, 129, 126, 122, 118, 114, 110, 106, 102, 98, 94, 90, 86, 82, 78,
                    76, 73, 70, 68, 65, 63, 60, 57, 55, 52, 49, 46, 44, 41, 38, 31, 23, 15, 7, 0, -8, -16, -24, -32, -40,
                    -42, -44, -45, -47, -49, -50, -52, -53, -55, -57, -58, -60, -61, -63, -64, -66, -68, -69, -71, -72, -74, -76, -77, -79, -81,
                    -84, -88, -92, -96, -100, -104, -108, -112, -116, -119, -122, -125, -128, -130, -133, -136, -138, -141, -143, -146, -149, -152, -154, -157, -159,
                    -161, -162, -163, -165, -166, -167, -169, -170, -172, -173, -174, -176, -177, -178, -180, -181, -182, -183, -185, -186, -187, -189, -190, -192, -193,
                    -194, -196, -197, -198, -200, -201, -203, -206, -207, -210, -211, -213, -216, -217, -220, -221, -224, -226, -227, -230, -231, -234, -236, -237, -240,
                    -239, -239, -238, -238, -237, -237, -236, -236, -236, -235, -235, -234, -234, -233, -233, -232, -232, -231, -231, -231, -230, -230, -229, -229, -228,
                    -228, -227, -227, -227, -226, -226, -225, -225, -224, -224, -224, -223, -223, -222, -222, -221, -221, -220, -220, -220, -219, -219, -218, -218, -217,
                    -217, -216, -216, -216, -215, -215, -214, -214, -213, -213, -212, -212, -211, -211, -211, -210, -210, -209, -209, -208, -208, -207, -207, -207, -206,
                    -206, -205, -205, -204, -204, -203, -203, -203, -202, -202, -201, -201, -200, -200, -200, -192, -183, -176, -167, -159, -152, -143, -136, -128, -119,
                    -112, -104, -96, -88, -81, -76, -72, -68, -64, -61, -57, -53, -49, -44, -40, -32, -24, -16, -8, 0, 7, 15, 23, 31, 38,
                    42, 46, 51, 55, 59, 63, 66, 70, 74, 78, 86, 94, 102, 110, 118, 122, 126, 129, 133, 137, 142, 146, 149, 153, 157,
                    166, 173, 182, 190, 197, 201, 206, 210, 213, 217, 221, 226, 230, 234, 237, 241, 245, 249, 253, 257, 261, 265, 269, 273, 277,
                    281, 284, 288, 292, 297, 301, 304, 308, 312, 317, 319, 322, 325, 327, 330, 332, 335, 338, 341, 343, 346, 348, 351, 354, 356,
                    365, 372, 381, 389, 396, 400, 404, 408, 412, 416, 420, 424, 428, 432, 436, 443, 452, 459, 467, 476, 480, 483, 487, 492, 496,
                    500, 503, 507, 512, 516, 523, 531, 540, 547, 556, 558, 561, 563, 566, 568, 571, 574, 576, 579, 581, 584, 587, 589, 592, 594,
                    603, 611, 618, 627, 634, 637, 640, 642, 645, 648, 651, 653, 656, 658, 661, 664, 667, 669, 672, 675, 682, 691, 698, 706, 715,
                    719, 722, 726, 731, 735, 739, 742, 746, 750, 755, 757, 760, 762, 765, 768, 770, 773, 775, 778, 780, 783, 786, 788, 791, 793,
                    802, 810, 817, 825, 834, 839, 844, 850, 855, 860, 866, 871, 876, 881, 887, 892, 897, 903, 908, 913, 921, 929, 937, 945, 952,
                    956, 961, 965, 968, 972, 977, 981, 984, 989, 993, 998, 1003, 1009, 1014, 1019, 1024, 1030, 1035, 1040, 1046, 1051, 1056, 1062, 1067, 1072,
                    1079, 1086, 1093, 1100, 1107, 1113, 1120, 1127, 1134, 1140, 1147, 1154, 1161, 1168, 1175, 1181, 1188, 1195, 1202, 1208, 1215, 1222, 1229, 1236, 1242,
                    1249, 1256, 1263, 1270, 1277, 1283, 1290, 1297, 1304, 1310 };
            }
            return RANDOMIZE_PIT_PATTERN1;
        }

        public static int[] getRandomizePitPattern2() {
            if ( RANDOMIZE_PIT_PATTERN2 == null ) {
                RANDOMIZE_PIT_PATTERN2 = new int[] {
            -788, -796, -797, -799, -802, -803, -806, -807, -810, -812, -813, -816, -817, -820, -822, -824, -825, -827, -829, -831, -834, -836, -835, -835, -834,
            -834, -834, -833, -833, -833, -832, -832, -832, -831, -831, -831, -830, -830, -830, -829, -829, -829, -828, -828, -827, -827, -827, -826, -826, -826,
            -825, -825, -825, -824, -824, -824, -823, -823, -823, -822, -822, -822, -821, -821, -821, -820, -820, -820, -819, -819, -818, -818, -818, -817, -817,
            -817, -816, -816, -816, -815, -815, -815, -814, -814, -814, -813, -813, -813, -812, -812, -812, -811, -811, -810, -810, -810, -809, -809, -809, -808,
            -808, -808, -807, -807, -807, -806, -806, -806, -805, -805, -805, -804, -804, -803, -803, -803, -802, -802, -802, -801, -801, -801, -800, -800, -800,
            -799, -799, -799, -798, -798, -798, -797, -797, -797, -796, -796, -796, -788, -780, -772, -764, -756, -755, -752, -750, -749, -746, -745, -742, -740,
            -739, -736, -735, -732, -731, -729, -726, -725, -722, -721, -719, -716, -701, -685, -668, -652, -637, -634, -631, -628, -626, -623, -621, -618, -615,
            -612, -610, -607, -604, -602, -599, -597, -589, -581, -573, -565, -557, -549, -541, -533, -525, -517, -502, -486, -469, -453, -438, -422, -406, -390,
            -374, -358, -351, -342, -335, -327, -318, -311, -302, -294, -287, -278, -271, -263, -255, -247, -240, -231, -224, -216, -207, -200, -183, -167, -152,
            -136, -119, -117, -114, -112, -109, -106, -104, -101, -99, -96, -93, -91, -88, -86, -83, -81, -72, -64, -57, -49, -40, -32, -24, -16,
            -8, 0, 7, 15, 23, 31, 38, 42, 46, 51, 55, 59, 63, 66, 70, 74, 78, 86, 94, 102, 110, 118, 122, 126, 129,
            133, 137, 142, 146, 149, 153, 157, 166, 173, 182, 190, 197, 206, 213, 221, 230, 237, 234, 230, 226, 221, 217, 213, 210, 206,
            201, 197, 174, 150, 126, 102, 78, 63, 47, 31, 15, 0, 3, 7, 11, 15, 19, 23, 27, 31, 35, 38, 42, 46, 51,
            55, 59, 63, 66, 70, 74, 78, 86, 94, 102, 110, 118, 122, 126, 129, 133, 137, 142, 146, 149, 153, 157, 162, 166, 170,
            173, 177, 182, 186, 190, 193, 197, 206, 213, 221, 230, 237, 245, 253, 261, 269, 277, 281, 284, 288, 292, 297, 301, 304, 308,
            312, 317, 318, 321, 322, 325, 327, 328, 331, 332, 335, 337, 338, 341, 342, 345, 347, 348, 351, 352, 355, 356, 365, 372, 381,
            389, 396, 404, 412, 420, 428, 436, 438, 439, 442, 443, 446, 448, 449, 452, 453, 456, 457, 459, 462, 463, 466, 467, 469, 472,
            473, 476, 478, 481, 483, 486, 489, 492, 494, 497, 500, 502, 505, 507, 510, 513, 516, 517, 519, 520, 522, 523, 525, 527, 528,
            530, 531, 533, 535, 536, 538, 540, 541, 543, 544, 546, 547, 549, 551, 552, 554, 556, 557, 558, 559, 561, 562, 563, 565, 566,
            567, 568, 570, 571, 572, 574, 575, 576, 578, 579, 580, 581, 583, 584, 585, 587, 588, 589, 591, 592, 593, 594, 597, 599, 602,
            604, 607, 609, 611, 614, 616, 618, 621, 623, 626, 628, 631, 633, 635, 638, 640, 642, 645, 647, 650, 652, 655, 657, 659, 662,
            664, 667, 669, 671, 674, 676, 678, 681, 683, 686, 688, 691, 693, 695, 698, 700, 702, 705, 707, 710, 712, 715, 714, 713, 713,
            712, 711, 711, 710, 710, 709, 708, 708, 707, 706, 706, 705, 705, 704, 703, 703, 702, 702, 701, 700, 700, 699, 698, 698, 697,
            697, 696, 695, 695, 694, 694, 693, 692, 692, 691, 691, 690, 689, 689, 688, 687, 687, 686, 686, 685, 684, 684, 683, 682, 682,
            681, 681, 680, 679, 679, 678, 678, 677, 676, 676, 675, 675, 671, 667, 662, 658, 655, 651, 647, 642, 638, 634, 632, 631, 628,
            627, 624, 622, 621, 618, 617, 614, 612, 611, 608, 607, 604, 603, 601, 598, 597, 594, 591, 587, 583, 579, 575, 571, 567, 563,
            559, 556, 554, 553, 552, 551, 550, 549, 547, 546, 545, 544, 543, 542, 541, 540, 538, 537, 536, 535, 534, 533, 531, 530, 529,
            528, 527, 526, 525, 523, 522, 521, 520, 519, 518, 517, 516, 513, 510, 507, 505, 502, 500, 497, 494, 492, 489, 486, 483, 481,
            478, 476, 473, 470, 467, 465, 462, 459, 457, 454, 452, 449, 446, 443, 441, 438, 436, 432, 429, 426, 423, 420, 417, 413, 410,
            407, 404, 401, 398, 394, 391, 388, 385, 382, 379, 375, 372, 369, 366, 363, 360, 356, 348, 341, 332, 325, 317, 314, 311, 308,
            306, 303, 301, 298, 295, 292, 290, 287, 284, 282, 279, 277, 273, 269, 265, 261, 257, 253, 249, 245, 241, 237, 236, 234, 231,
            230, 227, 226, 224, 221, 220, 217, 216, 213, 211, 210, 207, 206, 203, 201, 200, 197, 197, 196, 196, 195, 194, 194, 193, 193,
            192, 191, 191, 190, 190, 189, 188, 188, 187, 186, 186, 185, 185, 184, 183, 183, 182, 182, 181, 180, 180, 179, 178, 178, 177,
            177, 176, 175, 175, 174, 173, 173, 172, 172, 171, 170, 170, 169, 169, 168, 167, 167, 166, 166, 165, 164, 164, 163, 162, 162,
            161, 161, 160, 159, 159, 158, 157, 156, 154, 153, 151, 149, 148, 146, 145, 143, 142, 140, 138, 137, 135, 133, 132, 130, 129,
            127, 126, 124, 122, 121, 119, 118, 117, 116, 115, 114, 114, 113, 112, 111, 110, 110, 109, 108, 107, 107, 106, 105, 104, 103,
            103, 102, 101, 100, 100, 99, 98, 97, 96, 96, 95, 94, 93, 93, 92, 91, 90, 89, 89, 88, 87, 86, 86, 85, 84,
            83, 82, 82, 81, 80, 79, 78, 70, 63, 55, 46, 38, 31, 23, 15, 7, 0, -16, -32, -48, -64, -81, -82, -84, -86,
            -88, -90, -92, -94, -96, -98, -100, -102, -104, -106, -108, -110, -112, -114, -116, -118, -119, -128, -136, -143, -152, -159, -167, -176, -183,
            -192, -200, -201, -202, -203, -205, -206, -207, -209, -210, -211, -213, -214, -216, -217, -218, -220, -221, -222, -224, -225, -226, -227, -229, -230,
            -231, -233, -234, -236, -237, -238, -240, -242, -245, -247, -250, -253, -255, -258, -260, -263, -265, -268, -271, -273, -276, -278, -281, -283, -284,
            -287, -288, -291, -292, -294, -297, -298, -301, -302, -304, -307, -308, -311, -312, -314, -317, -318, -321, -324, -327, -329, -332, -335, -337, -340,
            -342, -345, -348, -351, -353, -356, -358, -360, -362, -363, -365, -366, -368, -370, -371, -373, -375, -376, -378, -379, -381, -382, -384, -386, -387,
            -389, -391, -392, -394, -395, -397, -399, -406, -414, -422, -430, -438, -440, -443, -446, -448, -451, -453, -456, -459, -462, -464, -467, -469, -472,
            -475, -477, -482, -486, -490, -493, -497, -502, -506, -510, -513, -517, -523, -528, -533, -539, -544, -549, -554, -560, -565, -570, -575, -581, -586,
            -591, -597, -604, -612, -621, -628, -637, -636, -636, -636, -635, -635, -635, -634, -634, -634, -634, -633, -633, -633, -632, -632, -632, -631, -631,
            -631, -631, -630, -630, -630, -629, -629, -629, -628, -628, -628, -628, -627, -627, -627, -626, -626, -626, -626, -625, -625, -625, -624, -624, -624,
            -623, -623, -623, -623, -622, -622, -622, -621, -621, -621, -621, -620, -620, -620, -619, -619, -619, -618, -618, -618, -618, -617, -617, -617, -616,
            -616, -616, -615, -615, -615, -615, -614, -614, -614, -613, -613, -613, -612, -612, -612, -612, -611, -611, -611, -610, -610, -610, -610, -609, -609,
            -609, -608, -608, -608, -607, -607, -607, -607, -606, -606, -606, -605, -605, -605, -604, -604, -604, -604, -603, -603, -603, -602, -602, -602, -602,
            -601, -601, -601, -600, -600, -600, -599, -599, -599, -599, -598, -598, -598, -597, -597, -597, -597, -595, -593, -591, -589, -587, -585, -583, -581,
            -579, -577, -575, -573, -571, -569, -567, -565, -563, -561, -559, -557, -557, -557, -556, -556, -556, -555, -555, -555, -554, -554, -554, -553, -553,
            -553, -552, -552, -552, -551, -551, -551, -550, -550, -550, -549, -549, -548, -548, -548, -547, -547, -547, -546, -546, -546, -545, -545, -545, -544,
            -544, -544, -543, -543, -543, -542, -542, -541, -541, -541, -540, -540, -540, -539, -539, -539, -538, -538, -538, -537, -537, -537, -536, -536, -536,
            -535, -535, -535, -534, -534, -533, -533, -533, -532, -532, -532, -531, -531, -531, -530, -530, -530, -529, -529, -529, -528, -528, -528, -527, -527,
            -527, -526, -526, -526, -525, -525, -524, -524, -524, -523, -523, -523, -522, -522, -522, -521, -521, -521, -520, -520, -520, -519, -519, -519, -518,
            -518, -517, -513, -510, -506, -502, -497, -493, -490, -486, -482, -477, -475, -472, -469, -467, -464, -462, -459, -456, -453, -451, -448, -446, -443,
            -440, -438, -430, -422, -414, -406, -399, -395, -391, -386, -382, -378, -375, -371, -366, -362, -358, -355, -351, -347, -342, -338, -335, -331, -327,
            -322, -318, -314, -311, -307, -302, -298, -294, -291, -287, -283, -278, -278, -277, -276, -275, -274, -273, -272, -271, -270, -269, -268, -267, -266,
            -265, -264, -263, -262, -261, -260, -259, -258, -257, -256, -255, -254, -253, -252, -251, -250, -249, -248, -247, -246, -245, -244, -243, -242, -241,
            -240, -240, -237, -234, -231, -229, -226, -224, -221, -218, -216, -213, -210, -207, -205, -202, -200, -198, -196, -195, -193, -192, -190, -188, -187,
            -185, -183, -182, -180, -179, -177, -176, -174, -172, -171, -169, -167, -166, -164, -163, -161, -159, -152, -143, -136, -128, -119, -118, -116, -114,
            -112, -110, -108, -106, -104, -102, -100, -98, -96, -94, -92, -90, -88, -86, -84, -82, -81, -82, -84, -86, -88, -90, -92, -94, -96,
            -98, -100, -102, -104, -106, -108, -110, -112, -114, -116, -118, -119, -120, -121, -122, -123, -124, -125, -126, -127, -128, -128, -129, -130, -131,
            -132, -133, -134, -135, -136, -136, -137, -138, -139, -140, -141, -142, -143, -143, -144, -145, -146, -147, -148, -149, -150, -151, -152, -152, -153,
            -154, -155, -156, -157, -158, -159, -159, -162, -163, -166, -167, -170, -172, -173, -176, -177, -180, -182, -183, -186, -187, -190, -192, -193, -196,
            -197, -200, -202, -205, -207, -210, -213, -216, -218, -221, -224, -226, -229, -231, -234, -237, -240, -243, -247, -251, -255, -259, -263, -267, -271,
            -275, -278, -281, -284, -287, -289, -292, -294, -297, -300, -302, -305, -308, -311, -313, -316, -318, -322, -327, -331, -335, -338, -342, -347, -351,
            -355, -358, -362, -366, -371, -375, -378, -382, -386, -391, -395, -399, -406, -414, -422, -430, -438, -442, -446, -449, -453, -457, -462, -466, -469,
            -473, -477, -486, -493, -502, -510, -517, -525, -533, -541, -549, -557, -565, -573, -581, -589, -597, -601, -604, -608, -612, -617, -621, -624, -628,
            -632, -637, -638, -640, -641, -643, -645, -646, -648, -649, -651, -652, -654, -656, -657, -659, -661, -662, -664, -665, -667, -668, -670, -672, -673,
            -675, -676, -685, -692, -701, -709, -716, -721, -725, -729, -732, -736, -740, -745, -749, -752, -756, -760, -764, -768, -772, -776, -780, -784, -788,
            -792, -796, -796, -796, -797, -797, -798, -798, -798, -799, -799, -800, -800, -801, -801, -801, -802, -802, -803, -803, -803, -804, -804, -805, -805,
            -806, -806, -806, -807, -807, -808, -808, -809, -809, -809, -810, -810, -811, -811, -812, -812, -812, -813, -813, -814, -814, -814, -815, -815, -816,
            -816, -817, -817, -817, -818, -818, -819, -819, -820, -820, -820, -821, -821, -822, -822, -822, -823, -823, -824, -824, -825, -825, -825, -826, -826,
            -827, -827, -827, -828, -828, -829, -829, -830, -830, -830, -831, -831, -832, -832, -833, -833, -833, -834, -834, -835, -835, -836, -843, -852, -859,
            -867, -876, -878, -880, -881, -883, -885, -887, -890, -892, -894, -896, -897, -899, -901, -904, -906, -908, -910, -911, -913, -915, -919, -923, -927,
            -931, -935, -939, -943, -947, -951, -954, -956, -958, -961, -963, -965, -967, -968, -970, -972, -975, -977, -979, -981, -982, -984, -986, -989, -991,
            -993, -995, -998, -1003, -1007, -1010, -1014, -1019, -1023, -1026, -1030, -1035, -1037, -1038, -1040, -1042, -1044, -1047, -1049, -1051, -1052, -1054, -1056, -1058, -1061,
            -1063, -1065, -1066, -1068, -1070, -1072, -1075, -1078, -1082, -1086, -1090, -1094, -1098, -1102, -1106, -1110, -1113, -1116, -1119, -1122, -1124, -1127, -1129, -1132, -1135,
            -1137, -1140, -1143, -1146, -1148, -1151, -1153, -1162, -1169, -1178, -1185, -1194, -1194, -1195, -1196, -1197, -1198, -1199, -1200, -1202, -1203, -1204, -1205, -1206, -1207,
            -1208, -1208, -1209, -1210, -1211, -1212, -1213, -1214, -1216, -1217, -1218, -1219, -1220, -1221, -1222, -1223, -1223, -1224, -1225, -1226, -1227, -1228, -1229, -1231, -1232,
            -1233, -1234, -1235, -1237, -1239, -1241, -1243, -1245, -1247, -1249, -1251, -1253, -1255, -1257, -1259, -1261, -1263, -1265, -1267, -1269, -1271, -1273, -1280, -1289, -1296,
            -1305, -1312, -1317, -1321, -1324, -1328, -1333, -1336, -1340, -1345, -1349, -1352, -1352, -1351, -1350, -1349, -1348, -1347, -1346, -1345, -1345, -1344, -1343, -1342, -1341,
            -1340, -1339, -1338, -1337, -1336, -1336, -1335, -1334, -1333, -1332, -1331, -1330, -1329, -1328, -1328, -1327, -1326, -1325, -1324, -1323, -1322, -1321, -1321, -1320, -1319,
            -1318, -1317, -1316, -1315, -1314, -1313, -1312, -1305, -1296, -1289, -1280, -1273, -1265, -1257, -1249, -1241, -1234, -1229, -1225, -1222, -1218, -1213, -1209, -1206, -1202,
            -1197, -1194, -1190, -1185, -1181, -1178, -1174, -1169, -1166, -1162, -1157, -1153, -1146, -1137, -1129, -1122, -1113, -1111, -1108, -1106, -1103, -1100, -1098, -1095, -1093,
            -1090, -1087, -1085, -1082, -1080, -1077, -1075, -1066, -1058, -1051, -1042, -1035, -1032, -1029, -1026, -1024, -1021, -1019, -1016, -1013, -1010, -1008, -1005, -1003, -1000,
            -997, -995, -986, -979, -970, -963, -954, -947, -939, -931, -923, -915, -911, -908, -904, -899, -896, -892, -887, -883, -880, -876, -873, -870, -867,
            -865, -862, -859, -857, -854, -852, -849, -846, -843, -841, -838, -836, -833, -830, -827, -825, -822, -820, -817, -814, -812, -809, -806, -803, -801,
            -798, -796, -792, -788, -784, -780, -776, -772, -768, -764, -760, -756, -755, -752, -750, -749, -746, -745, -742, -740, -739, -736, -735, -732, -731,
            -729, -726, -725, -722, -721, -719, -716, -716, -715, -714, -714, -713, -712, -711, -711, -710, -709, -709, -708, -707, -706, -706, -705, -704, -703,
            -703, -702, -701, -701, -700, -699, -698, -698, -697, -696, -695, -695, -694, -693, -692, -692, -691, -690, -690, -689, -688, -687, -687, -686, -685,
            -685, -684, -683, -682, -682, -681, -680, -679, -679, -678, -677, -676, -672, -668, -665, -661, -657, -652, -648, -645, -641, -637, -628, -621, -612,
            -604, -597, -589, -581, -573, -565, -557, -541, -526, -510, -493, -477, -473, -469, -466, -462, -457, -453, -449, -446, -442, -438, -430, -422, -414,
            -406, -399, -391, -382, -375, -366, -358, -355, -351, -347, -342, -338, -335, -331, -327, -322, -318, -319, -320, -321, -321, -322, -323, -324, -324,
            -325, -326, -327, -327, -328, -329, -329, -330, -331, -332, -332, -333, -334, -335, -335, -336, -337, -337, -338, -339, -340, -340, -341, -342, -342,
            -343, -344, -345, -345, -346, -347, -348, -348, -349, -350, -351, -351, -352, -353, -353, -354, -355, -356, -356, -357, -358, -358, -366, -375, -382,
            -391, -399, -401, -404, -406, -409, -412, -414, -417, -419, -422, -425, -427, -430, -432, -435, -438, -440, -443, -446, -448, -451, -453, -456, -459,
            -462, -464, -467, -469, -472, -475, -477, -477, -477, -476, -476, -475, -475, -474, -474, -473, -473, -472, -472, -471, -471, -470, -470, -469, -469,
            -469, -468, -468, -467, -467, -466, -466, -465, -465, -464, -464, -463, -463, -462, -462, -462, -461, -461, -460, -460, -459, -459, -458, -458, -457,
            -457, -456, -456, -455, -455, -454, -454, -453, -453, -453, -452, -452, -451, -451, -450, -450, -449, -449, -448, -448, -447, -447, -446, -446, -446,
            -445, -445, -444, -444, -443, -443, -442, -442, -441, -441, -440, -440, -439, -439, -438, -438, -438, -435, -432, -430, -427, -425, -422, -419, -417,
            -414, -412, -409, -406, -404, -401, -399, -395, -391, -386, -382, -378, -375, -371, -366, -362, -358, -358, -357, -356, -355, -354, -353, -352, -351,
            -350, -349, -348, -347, -346, -345, -344, -343, -342, -342, -341, -340, -339, -338, -337, -336, -335, -334, -333, -332, -331, -330, -329, -328, -327,
            -327, -326, -325, -324, -323, -322, -321, -320, -319, -318, -317, -316, -315, -314, -313, -312, -311, -311, -310, -309, -308, -307, -306, -305, -304,
            -303, -302, -301, -300, -299, -298, -297, -296, -295, -294, -294, -293, -292, -291, -290, -289, -288, -287, -286, -285, -284, -283, -282, -281, -280,
            -279, -278, -275, -271, -267, -263, -259, -255, -251, -247, -243, -240, -231, -224, -216, -207, -200, -201, -202, -203, -204, -205, -206, -207, -209,
            -210, -211, -212, -213, -214, -216, -217, -218, -219, -220, -221, -222, -224, -225, -226, -227, -228, -229, -230, -231, -233, -234, -235, -236, -237,
            -238, -240, -245, -250, -255, -261, -266, -271, -276, -282, -287, -292, -297, -303, -308, -313, -318, -321, -324, -327, -329, -332, -335, -337, -340,
            -342, -345, -348, -351, -353, -356, -358, -366, -375, -382, -391, -399, -402, -406, -410, -414, -418, -422, -426, -430, -434, -438, -446, -453, -462,
            -469, -477, -486, -493, -502, -510, -517, -525, -533, -541, -549, -557, -565, -573, -581, -589, -597, -604, -612, -621, -628, -637, -645, -652, -661,
            -668, -676, -685, -692, -701, -709, -716, -725, -732, -740, -749, -756, -760, -764, -768, -772, -776, -780, -784, -788, -792, -796, -795, -795, -795,
            -795, -795, -794, -794, -794, -794, -794, -793, -793, -793, -793, -793, -793, -792, -792, -792, -792, -792, -791, -791, -791, -791, -791, -790, -790,
            -790, -790, -790, -790, -789, -789, -789, -789, -789, -788, -788, -788, -788, -788, -788, -787, -787, -787, -787, -787, -786, -786, -786, -786, -786,
            -785, -785, -785, -785, -785, -785, -784, -784, -784, -784, -784, -783, -783, -783, -783, -783, -783, -782, -782, -782, -782, -782, -781, -781, -781,
            -781, -781, -780, -780, -780, -780, -780, -780, -779, -779, -779, -779, -779, -778, -778, -778, -778, -778, -777, -777, -777, -777, -777, -777, -776,
            -776, -776, -776, -776, -775, -775, -775, -775, -775, -775, -774, -774, -774, -774, -774, -773, -773, -773, -773, -773, -772, -772, -772, -772, -772,
            -772, -771, -771, -771, -771, -771, -770, -770, -770, -770, -770, -769, -769, -769, -769, -769, -769, -768, -768, -768, -768, -768, -767, -767, -767,
            -767, -767, -767, -766, -766, -766, -766, -766, -765, -765, -765, -765, -765, -764, -764, -764, -764, -764, -764, -763, -763, -763, -763, -763, -762,
            -762, -762, -762, -762, -762, -761, -761, -761, -761, -761, -760, -760, -760, -760, -760, -759, -759, -759, -759, -759, -759, -758, -758, -758, -758,
            -758, -757, -757, -757, -757, -757, -756, -752, -749, -745, -740, -736, -732, -729, -725, -721, -716, -709, -701, -692, -685, -676, -674, -671, -668,
            -666, -663, -661, -658, -655, -652, -650, -647, -645, -642, -639, -637, -628, -621, -612, -604, -597, -589, -581, -573, -565, -557, -556, -554, -551,
            -550, -547, -546, -543, -541, -540, -537, -536, -533, -531, -530, -527, -526, -523, -521, -520, -517, -510, -502, -493, -486, -477, -472, -467, -462,
            -456, -451, -446, -441, -435, -430, -425, -420, -414, -409, -404, -399, -382, -366, -351, -335, -318, -295, -271, -247, -223, -200, -192, -183, -176,
            -167, -159, -144, -128, -112, -96, -81, -72, -64, -57, -49, -40, -25, -8, 6, 23, 38, 36, 33, 31, 28, 26, 23, 20, 18,
            15, 12, 10, 7, 5, 2, 0, -8, -16, -24, -32, -40, -43, -46, -49, -51, -54, -57, -59, -62, -64, -67, -70, -72, -75,
            -78, -81, -88, -96, -104, -112, -119, -123, -128, -132, -136, -139, -143, -147, -152, -156, -159, -167, -176, -183, -192, -200, -202, -205, -207,
            -210, -213, -216, -218, -221, -224, -226, -229, -231, -234, -237, -240, -247, -255, -263, -271, -278, -281, -283, -284, -287, -288, -291, -292, -294,
            -297, -298, -301, -302, -304, -307, -308, -311, -312, -314, -317, -318, -322, -327, -331, -335, -338, -342, -347, -351, -355, -358, -360, -361, -362,
            -364, -365, -366, -368, -369, -371, -372, -373, -375, -376, -377, -378, -380, -381, -382, -384, -385, -386, -388, -389, -391, -392, -393, -395, -396,
            -397, -399, -400, -402, -403, -405, -406, -408, -409, -411, -413, -414, -416, -417, -419, -420, -422, -423, -425, -427, -428, -430, -431, -433, -434,
            -436, -438, -439, -442, -443, -446, -448, -449, -452, -453, -456, -457, -459, -462, -463, -466, -467, -469, -472, -473, -476, -477, -486, -493, -502,
            -510, -517, -521, -526, -530, -533, -537, -541, -546, -550, -554, -557, -560, -563, -565, -568, -570, -573, -576, -578, -581, -584, -586, -589, -591,
            -594, -597, -599, -602, -604, -607, -610, -612, -615, -618, -621, -623, -626, -628, -631, -634, -637, -645, -652, -661, -668, -676, -685, -692, -701,
            -709, -716, -719, -721, -722, -725, -726, -729, -731, -732, -735, -736, -739, -740, -742, -745, -746, -749, -750, -752, -755, -756, -764, -772, -780 };
            }
            return RANDOMIZE_PIT_PATTERN2;
        }

        public static int[] getRandomizePitPattern3() {
            if ( RANDOMIZE_PIT_PATTERN3 == null ) {
                RANDOMIZE_PIT_PATTERN3 = new int[] {
                    881, 880, 879, 878, 875, 872, 869, 867, 864, 862, 859, 856, 853, 851, 848, 845, 843, 840, 838, 834, 829, 825, 822, 817, 813,
                    810, 806, 802, 797, 796, 793, 792, 789, 787, 786, 783, 782, 779, 777, 776, 773, 772, 769, 768, 766, 763, 762, 759, 758, 756,
                    754, 753, 751, 749, 748, 746, 745, 743, 742, 740, 738, 737, 735, 733, 732, 730, 729, 727, 725, 724, 722, 721, 719, 718, 715,
                    713, 712, 709, 708, 705, 704, 702, 699, 698, 695, 694, 692, 689, 688, 685, 684, 682, 679, 678, 674, 669, 665, 661, 658, 654,
                    649, 645, 641, 638, 634, 630, 625, 621, 618, 614, 610, 605, 601, 597, 594, 590, 585, 581, 577, 574, 570, 566, 561, 557, 550,
                    542, 534, 526, 518, 510, 502, 494, 486, 479, 475, 470, 466, 463, 459, 455, 450, 446, 442, 439, 430, 422, 415, 406, 399, 391,
                    382, 375, 366, 358, 351, 342, 335, 327, 318, 314, 311, 307, 302, 298, 294, 291, 287, 283, 278, 271, 263, 254, 247, 238, 234,
                    230, 227, 223, 219, 214, 210, 207, 203, 199, 190, 183, 174, 166, 159, 150, 143, 135, 126, 119, 110, 102, 95, 86, 78, 71,
                    63, 55, 47, 39, 31, 23, 15, 7, 0, -4, -8, -12, -16, -20, -24, -28, -32, -36, -40, -57, -72, -89, -105, -120, -129,
                    -136, -145, -153, -160, -169, -176, -184, -193, -200, -209, -217, -224, -233, -240, -248, -257, -264, -273, -281, -288, -297, -304, -312, -321, -328,
                    -337, -345, -352, -361, -368, -376, -385, -392, -401, -409, -416, -425, -432, -440, -449, -456, -465, -473, -480, -496, -512, -528, -544, -560, -567,
                    -576, -584, -591, -600, -624, -648, -671, -695, -719, -728, -736, -743, -752, -759, -768, -776, -783, -792, -799, -807, -816, -824, -831, -839, -848,
                    -855, -864, -871, -880, -896, -911, -927, -943, -960, -967, -976, -983, -992, -999, -1008, -1015, -1024, -1032, -1039, -1048, -1055, -1064, -1071, -1080, -1095,
                    -1111, -1127, -1143, -1160, -1167, -1176, -1183, -1192, -1199, -1208, -1216, -1223, -1232, -1239, -1255, -1271, -1288, -1304, -1320, -1327, -1336, -1343, -1351, -1360, -1367,
                    -1376, -1383, -1392, -1399, -1408, -1416, -1423, -1432, -1439, -1455, -1471, -1487, -1503, -1519, -1526, -1535, -1542, -1550, -1559, -1566, -1575, -1582, -1591, -1598, -1607,
                    -1615, -1622, -1631, -1638, -1647, -1654, -1663, -1670, -1678, -1687, -1694, -1703, -1710, -1719, -1726, -1735, -1743, -1750, -1759, -1775, -1791, -1806, -1822, -1838, -1844,
                    -1849, -1854, -1860, -1865, -1871, -1876, -1881, -1887, -1892, -1897, -1903, -1908, -1913, -1919, -1926, -1934, -1943, -1950, -1959, -1966, -1975, -1982, -1991, -1999, -2006,
                    -2015, -2022, -2031, -2038, -2047, -2054, -2062, -2071, -2078, -2087, -2094, -2103, -2110, -2119, -2127, -2134, -2143, -2150, -2159, -2162, -2166, -2171, -2175, -2178, -2182,
                    -2187, -2190, -2194, -2199, -2203, -2206, -2210, -2215, -2218, -2222, -2227, -2231, -2234, -2238, -2243, -2247, -2250, -2255, -2259, -2262, -2266, -2271, -2275, -2278, -2283,
                    -2287, -2290, -2294, -2299, -2303, -2306, -2310, -2315, -2318, -2320, -2322, -2324, -2327, -2329, -2331, -2332, -2334, -2336, -2338, -2341, -2343, -2345, -2346, -2348, -2350,
                    -2352, -2355, -2357, -2359, -2362, -2366, -2371, -2375, -2378, -2383, -2387, -2390, -2394, -2399, -2400, -2401, -2402, -2403, -2404, -2405, -2406, -2407, -2409, -2410, -2411,
                    -2412, -2413, -2414, -2415, -2416, -2417, -2419, -2420, -2421, -2422, -2423, -2424, -2425, -2426, -2427, -2429, -2430, -2431, -2432, -2433, -2434, -2435, -2436, -2437, -2437,
                    -2437, -2437, -2436, -2436, -2436, -2436, -2435, -2435, -2435, -2434, -2434, -2434, -2434, -2433, -2433, -2433, -2432, -2432, -2432, -2432, -2431, -2431, -2431, -2431, -2430,
                    -2430, -2430, -2429, -2429, -2429, -2429, -2428, -2428, -2428, -2427, -2427, -2427, -2427, -2426, -2426, -2426, -2426, -2425, -2425, -2425, -2424, -2424, -2424, -2424, -2423,
                    -2423, -2423, -2422, -2422, -2422, -2422, -2421, -2421, -2421, -2421, -2420, -2420, -2420, -2419, -2419, -2419, -2419, -2418, -2418, -2418, -2417, -2417, -2417, -2417, -2416,
                    -2416, -2416, -2415, -2415, -2415, -2415, -2414, -2414, -2414, -2414, -2413, -2413, -2413, -2412, -2412, -2412, -2412, -2411, -2411, -2411, -2410, -2410, -2410, -2410, -2409,
                    -2409, -2409, -2409, -2408, -2408, -2408, -2407, -2407, -2407, -2407, -2406, -2406, -2406, -2405, -2405, -2405, -2405, -2404, -2404, -2404, -2404, -2403, -2403, -2403, -2402,
                    -2402, -2402, -2402, -2401, -2401, -2401, -2400, -2400, -2400, -2400, -2399, -2399, -2399, -2399, -2396, -2393, -2390, -2388, -2385, -2383, -2380, -2377, -2375, -2372, -2369,
                    -2366, -2364, -2361, -2359, -2356, -2353, -2350, -2348, -2345, -2343, -2340, -2337, -2334, -2332, -2329, -2327, -2324, -2321, -2318, -2315, -2310, -2306, -2303, -2299, -2294,
                    -2290, -2287, -2283, -2278, -2271, -2262, -2255, -2247, -2238, -2231, -2222, -2215, -2206, -2199, -2194, -2190, -2187, -2182, -2178, -2175, -2171, -2166, -2162, -2159, -2155,
                    -2150, -2147, -2143, -2138, -2134, -2131, -2127, -2122, -2119, -2110, -2103, -2094, -2087, -2078, -2075, -2071, -2066, -2062, -2059, -2054, -2050, -2047, -2043, -2038, -2031,
                    -2022, -2015, -2006, -1999, -1982, -1966, -1950, -1934, -1919, -1915, -1910, -1906, -1903, -1899, -1894, -1891, -1887, -1882, -1878, -1871, -1863, -1854, -1847, -1838, -1826,
                    -1815, -1803, -1791, -1778, -1766, -1754, -1743, -1731, -1719, -1703, -1687, -1670, -1654, -1638, -1622, -1607, -1591, -1575, -1559, -1550, -1542, -1535, -1526, -1519, -1510,
                    -1503, -1494, -1487, -1479, -1471, -1463, -1455, -1447, -1439, -1432, -1423, -1416, -1408, -1399, -1392, -1383, -1376, -1367, -1360, -1351, -1343, -1336, -1327, -1320, -1311,
                    -1304, -1295, -1288, -1280, -1271, -1264, -1255, -1248, -1239, -1232, -1223, -1216, -1208, -1199, -1192, -1183, -1176, -1167, -1160, -1152, -1143, -1136, -1127, -1120, -1115,
                    -1111, -1108, -1104, -1099, -1095, -1092, -1087, -1083, -1080, -1071, -1064, -1055, -1048, -1039, -1032, -1024, -1015, -1008, -999, -1000, -1001, -1002, -1002, -1003, -1004,
                    -1005, -1005, -1006, -1007, -1008, -1008, -1009, -1010, -1010, -1011, -1012, -1013, -1013, -1014, -1015, -1015, -1016, -1017, -1018, -1018, -1019, -1020, -1021, -1021, -1022,
                    -1023, -1024, -1024, -1025, -1026, -1026, -1027, -1028, -1029, -1029, -1030, -1031, -1032, -1032, -1033, -1034, -1034, -1035, -1036, -1037, -1037, -1038, -1039, -1039, -1042,
                    -1045, -1048, -1050, -1053, -1055, -1058, -1061, -1064, -1066, -1069, -1071, -1074, -1077, -1080, -1083, -1087, -1092, -1095, -1099, -1104, -1108, -1111, -1115, -1120, -1122,
                    -1125, -1127, -1130, -1133, -1136, -1138, -1141, -1143, -1146, -1149, -1152, -1154, -1157, -1160, -1180, -1199, -1220, -1239, -1260, -1280, -1299, -1320, -1339, -1360, -1351,
                    -1343, -1336, -1327, -1320, -1311, -1304, -1295, -1288, -1280, -1276, -1271, -1267, -1264, -1260, -1255, -1251, -1248, -1243, -1239, -1236, -1232, -1227, -1223, -1220, -1216,
                    -1211, -1208, -1204, -1199, -1197, -1194, -1192, -1189, -1186, -1183, -1181, -1178, -1176, -1173, -1170, -1167, -1165, -1162, -1160, -1155, -1152, -1148, -1143, -1139, -1136,
                    -1132, -1127, -1123, -1120, -1118, -1115, -1113, -1111, -1109, -1108, -1106, -1104, -1101, -1099, -1097, -1095, -1094, -1092, -1090, -1087, -1085, -1083, -1081, -1080, -1080,
                    -1081, -1082, -1083, -1084, -1085, -1086, -1087, -1087, -1088, -1089, -1090, -1091, -1092, -1093, -1094, -1095, -1095, -1096, -1097, -1098, -1099, -1100, -1101, -1102, -1103,
                    -1104, -1104, -1105, -1106, -1107, -1108, -1109, -1110, -1111, -1111, -1112, -1113, -1114, -1115, -1116, -1117, -1118, -1119, -1120, -1123, -1127, -1132, -1136, -1139, -1143,
                    -1148, -1152, -1155, -1160, -1164, -1167, -1171, -1176, -1180, -1183, -1188, -1192, -1195, -1199, -1202, -1204, -1206, -1208, -1209, -1211, -1213, -1216, -1218, -1220, -1222,
                    -1223, -1225, -1227, -1229, -1232, -1234, -1236, -1237, -1239, -1248, -1255, -1264, -1271, -1280, -1288, -1295, -1304, -1311, -1320, -1336, -1351, -1367, -1383, -1399, -1408,
                    -1416, -1423, -1432, -1439, -1447, -1455, -1463, -1471, -1479, -1487, -1494, -1503, -1510, -1519, -1535, -1550, -1566, -1582, -1598, -1615, -1631, -1647, -1663, -1678, -1682,
                    -1687, -1691, -1694, -1698, -1703, -1706, -1710, -1715, -1719, -1735, -1750, -1766, -1782, -1798, -1806, -1815, -1822, -1831, -1838, -1847, -1854, -1863, -1871, -1878, -1887,
                    -1894, -1903, -1910, -1919, -1926, -1934, -1943, -1950, -1959, -1966, -1975, -1982, -1991, -1999, -2003, -2006, -2010, -2015, -2019, -2022, -2027, -2031, -2034, -2038, -2054,
                    -2071, -2087, -2103, -2119, -2120, -2122, -2124, -2127, -2129, -2131, -2133, -2134, -2136, -2138, -2141, -2143, -2145, -2147, -2148, -2150, -2152, -2155, -2157, -2159, -2175,
                    -2190, -2206, -2222, -2238, -2243, -2247, -2250, -2255, -2259, -2262, -2266, -2271, -2275, -2278, -2287, -2294, -2303, -2310, -2318, -2327, -2334, -2343, -2350, -2359, -2366,
                    -2375, -2383, -2390, -2399, -2402, -2406, -2410, -2414, -2418, -2422, -2426, -2430, -2434, -2437, -2446, -2454, -2461, -2470, -2477, -2480, -2483, -2486, -2488, -2491, -2493,
                    -2496, -2499, -2502, -2504, -2507, -2509, -2512, -2515, -2517, -2520, -2523, -2526, -2528, -2531, -2533, -2536, -2539, -2542, -2544, -2547, -2549, -2552, -2555, -2558, -2560,
                    -2561, -2563, -2565, -2568, -2570, -2572, -2574, -2575, -2577, -2579, -2582, -2584, -2586, -2588, -2589, -2591, -2593, -2596, -2598, -2605, -2614, -2621, -2630, -2637, -2640,
                    -2642, -2644, -2645, -2647, -2649, -2651, -2654, -2656, -2658, -2659, -2661, -2663, -2665, -2668, -2670, -2672, -2673, -2675, -2677, -2686, -2693, -2702, -2710, -2717, -2721,
                    -2726, -2730, -2733, -2738, -2742, -2745, -2749, -2754, -2758, -2761, -2765, -2770, -2773, -2777, -2782, -2786, -2789, -2793, -2798, -2800, -2801, -2803, -2805, -2807, -2810,
                    -2812, -2814, -2816, -2817, -2819, -2821, -2824, -2826, -2828, -2830, -2831, -2833, -2835, -2838, -2840, -2842, -2844, -2845, -2847, -2849, -2852, -2854, -2856, -2858, -2859,
                    -2861, -2863, -2866, -2868, -2870, -2872, -2873, -2875, -2877, -2880, -2883, -2886, -2888, -2891, -2893, -2896, -2899, -2901, -2904, -2907, -2910, -2912, -2915, -2917, -2917,
                    -2916, -2916, -2915, -2915, -2914, -2914, -2913, -2913, -2912, -2912, -2911, -2911, -2910, -2910, -2909, -2908, -2908, -2907, -2907, -2906, -2906, -2905, -2905, -2904, -2904,
                    -2903, -2903, -2902, -2901, -2901, -2900, -2900, -2899, -2899, -2898, -2898, -2897, -2897, -2896, -2896, -2895, -2895, -2894, -2893, -2893, -2892, -2892, -2891, -2891, -2890,
                    -2890, -2889, -2889, -2888, -2888, -2887, -2887, -2886, -2886, -2885, -2884, -2884, -2883, -2883, -2882, -2882, -2881, -2881, -2880, -2880, -2879, -2879, -2878, -2877, -2873,
                    -2870, -2866, -2861, -2858, -2854, -2849, -2845, -2842, -2838, -2833, -2830, -2826, -2821, -2817, -2814, -2810, -2805, -2801, -2798, -2793, -2789, -2786, -2782, -2777, -2773,
                    -2770, -2765, -2761, -2758, -2754, -2749, -2745, -2742, -2738, -2733, -2730, -2726, -2721, -2717, -2710, -2702, -2693, -2686, -2677, -2673, -2670, -2665, -2661, -2658, -2654,
                    -2649, -2645, -2642, -2637, -2621, -2605, -2589, -2574, -2558, -2549, -2542, -2533, -2526, -2517, -2509, -2502, -2493, -2486, -2477, -2470, -2462, -2454, -2446, -2438, -2430,
                    -2422, -2414, -2406, -2399, -2390, -2383, -2375, -2366, -2359, -2350, -2343, -2334, -2327, -2318, -2310, -2303, -2294, -2287, -2278, -2275, -2271, -2266, -2262, -2259, -2255,
                    -2250, -2247, -2243, -2238, -2231, -2222, -2215, -2206, -2199, -2190, -2182, -2175, -2166, -2159, -2150, -2143, -2134, -2127, -2119, -2115, -2110, -2106, -2103, -2099, -2094,
                    -2090, -2087, -2082, -2078, -2071, -2062, -2054, -2047, -2038, -2031, -2022, -2015, -2006, -1999, -1991, -1982, -1975, -1966, -1959, -1950, -1943, -1934, -1926, -1919, -1910,
                    -1903, -1894, -1887, -1878, -1871, -1863, -1854, -1847, -1838, -1831, -1822, -1815, -1806, -1798, -1782, -1766, -1750, -1735, -1719, -1703, -1687, -1670, -1654, -1638, -1635,
                    -1631, -1626, -1622, -1619, -1615, -1610, -1607, -1603, -1598, -1582, -1566, -1550, -1535, -1519, -1503, -1487, -1471, -1455, -1439, -1432, -1423, -1416, -1408, -1399, -1383,
                    -1367, -1351, -1336, -1320, -1304, -1288, -1271, -1255, -1239, -1232, -1223, -1216, -1208, -1199, -1192, -1183, -1176, -1167, -1160, -1152, -1143, -1136, -1127, -1120, -1111,
                    -1104, -1095, -1087, -1080, -1064, -1048, -1032, -1015, -999, -987, -976, -964, -952, -939, -927, -915, -904, -892, -880, -855, -831, -807, -783, -759, -752,
                    -743, -736, -728, -719, -712, -704, -695, -688, -679, -671, -664, -655, -648, -640, -635, -631, -628, -624, -620, -615, -611, -608, -604, -600, -584,
                    -567, -551, -536, -520, -516, -512, -508, -504, -500, -496, -492, -488, -484, -480, -473, -465, -456, -449, -440, -416, -392, -368, -345, -321, -317,
                    -312, -308, -304, -301, -297, -292, -288, -284, -281, -283, -284, -287, -288, -291, -292, -294, -297, -298, -301, -302, -304, -307, -308, -311, -312,
                    -314, -317, -318, -321, -323, -326, -328, -331, -334, -337, -339, -342, -345, -347, -350, -352, -355, -358, -361, -362, -365, -366, -368, -371, -372,
                    -375, -376, -378, -381, -382, -385, -386, -389, -391, -392, -395, -396, -399, -401, -403, -406, -409, -411, -414, -416, -419, -422, -425, -427, -430,
                    -432, -435, -438, -440, -445, -449, -453, -456, -460, -465, -469, -473, -476, -480, -488, -496, -504, -512, -520, -523, -527, -531, -536, -540, -543,
                    -547, -551, -556, -560, -563, -566, -569, -572, -576, -579, -582, -585, -588, -591, -595, -598, -601, -604, -608, -611, -614, -617, -620, -624, -627,
                    -630, -633, -636, -640, -644, -648, -651, -655, -659, -664, -668, -671, -675, -679, -684, -688, -692, -695, -699, -704, -708, -712, -715, -719, -728,
                    -736, -743, -752, -759, -763, -768, -772, -776, -779, -783, -787, -792, -796, -799, -807, -816, -824, -831, -839, -848, -855, -864, -871, -880, -887,
                    -896, -904, -911, -920, -943, -967, -992, -1015, -1039, -1064, -1087, -1111, -1136, -1160, -1178, -1197, -1216, -1234, -1253, -1271, -1290, -1309, -1327, -1346, -1365,
                    -1383, -1402, -1421, -1439, -1443, -1447, -1451, -1455, -1459, -1463, -1467, -1471, -1475, -1479, -1487, -1494, -1503, -1510, -1519, -1522, -1526, -1531, -1535, -1538, -1542,
                    -1547, -1550, -1554, -1559, -1560, -1562, -1563, -1565, -1566, -1568, -1570, -1571, -1573, -1575, -1576, -1578, -1579, -1581, -1582, -1584, -1586, -1587, -1589, -1591, -1592,
                    -1594, -1595, -1597, -1598, -1603, -1607, -1610, -1615, -1619, -1622, -1626, -1631, -1635, -1638, -1640, -1643, -1645, -1647, -1649, -1650, -1652, -1654, -1657, -1659, -1661,
                    -1663, -1664, -1666, -1668, -1670, -1673, -1675, -1677, -1678, -1679, -1680, -1681, -1682, -1683, -1684, -1685, -1686, -1687, -1687, -1688, -1689, -1690, -1691, -1692, -1693,
                    -1694, -1694, -1695, -1696, -1697, -1698, -1699, -1700, -1701, -1702, -1703, -1703, -1704, -1705, -1706, -1707, -1708, -1709, -1710, -1710, -1711, -1712, -1713, -1714, -1715,
                    -1716, -1717, -1718, -1719, -1721, -1724, -1726, -1729, -1732, -1735, -1737, -1740, -1743, -1745, -1748, -1750, -1753, -1756, -1759, -1761, -1764, -1766, -1769, -1772, -1775,
                    -1777, -1780, -1782, -1785, -1788, -1791, -1793, -1796, -1798, -1801, -1803, -1805, -1806, -1808, -1810, -1812, -1815, -1817, -1819, -1820, -1822, -1824, -1826, -1829, -1831,
                    -1833, -1834, -1836, -1838, -1847, -1854, -1863, -1871, -1878, -1880, -1882, -1885, -1887, -1889, -1891, -1892, -1894, -1896, -1899, -1901, -1903, -1905, -1906, -1908, -1910,
                    -1913, -1915, -1917, -1919, -1918, -1918, -1918, -1917, -1917, -1917, -1917, -1916, -1916, -1916, -1915, -1915, -1915, -1915, -1914, -1914, -1914, -1913, -1913, -1913, -1913,
                    -1912, -1912, -1912, -1911, -1911, -1911, -1910, -1910, -1910, -1910, -1909, -1909, -1909, -1908, -1908, -1908, -1908, -1907, -1907, -1907, -1906, -1906, -1906, -1906, -1905,
                    -1905, -1905, -1905, -1904, -1904, -1904, -1903, -1903, -1903, -1903, -1902, -1902, -1902, -1901, -1901, -1901, -1901, -1900, -1900, -1900, -1899, -1899, -1899, -1899, -1898,
                    -1898, -1898, -1897, -1897, -1897, -1896, -1896, -1896, -1896, -1895, -1895, -1895, -1894, -1894, -1894, -1894, -1893, -1893, -1893, -1892, -1892, -1892, -1892, -1891, -1891,
                    -1891, -1891, -1890, -1890, -1890, -1889, -1889, -1889, -1889, -1888, -1888, -1888, -1887, -1887, -1887, -1887, -1886, -1886, -1886, -1885, -1885, -1885, -1885, -1884, -1884,
                    -1884, -1883, -1883, -1883, -1882, -1882, -1882, -1882, -1881, -1881, -1881, -1880, -1880, -1880, -1880, -1879, -1879, -1879, -1878, -1876, -1873, -1871, -1868, -1865, -1863,
                    -1860, -1857, -1854, -1852, -1849, -1847, -1844, -1841, -1838, -1834, -1831, -1826, -1822, -1819, -1815, -1810, -1806, -1803, -1798, -1791, -1782, -1775, -1766, -1759, -1754,
                    -1750, -1747, -1743, -1738, -1735, -1731, -1726, -1722, -1719, -1715, -1710, -1706, -1703, -1698, -1694, -1691, -1687, -1682, -1678, -1670, -1663, -1654, -1647, -1638, -1635,
                    -1631, -1626, -1622, -1619, -1615, -1610, -1607, -1603, -1598, -1591, -1582, -1575, -1566, -1559, -1550, -1542, -1535, -1526, -1519, -1515, -1510, -1507, -1503, -1498, -1494,
                    -1491, -1487, -1482, -1479, -1471, -1463, -1455, -1447, -1439, -1432, -1423, -1416, -1408, -1399, -1392, -1383, -1376, -1367, -1360, -1351, -1343, -1336, -1327, -1320, -1311,
                    -1304, -1295, -1288, -1280, -1271, -1264, -1255, -1248, -1239, -1232, -1223, -1216, -1208, -1199, -1192, -1183, -1176, -1167, -1160, -1152, -1143, -1136, -1127, -1120, -1111,
                    -1104, -1095, -1087, -1080, -1071, -1064, -1055, -1048, -1039, -1032, -1024, -1015, -1008, -999, -992, -983, -976, -967, -960, -955, -952, -948, -943, -939, -936,
                    -932, -927, -924, -920, -921, -922, -923, -924, -925, -926, -927, -929, -930, -931, -932, -933, -934, -936, -937, -938, -939, -940, -941, -942, -943,
                    -945, -946, -947, -948, -949, -950, -952, -953, -954, -955, -956, -957, -958, -960, -962, -965, -967, -970, -973, -976, -978, -981, -983, -986, -989,
                    -992, -994, -997, -999, -1008, -1015, -1024, -1032, -1039, -1048, -1055, -1064, -1071, -1080, -1104, -1127, -1152, -1176, -1199, -1208, -1216, -1223, -1232, -1239, -1248,
                    -1255, -1264, -1271, -1280, -1282, -1285, -1288, -1290, -1293, -1295, -1298, -1301, -1304, -1306, -1309, -1311, -1314, -1317, -1320, -1323, -1327, -1332, -1336, -1339, -1343,
                    -1348, -1351, -1355, -1360, -1367, -1376, -1383, -1392, -1399, -1408, -1416, -1423, -1432, -1439, -1447, -1455, -1463, -1471, -1479, -1482, -1487, -1491, -1494, -1498, -1503,
                    -1507, -1510, -1515, -1519, -1522, -1526, -1531, -1535, -1538, -1542, -1547, -1550, -1554, -1559, -1563, -1566, -1570, -1575, -1578, -1582, -1587, -1591, -1594, -1598, -1600,
                    -1601, -1602, -1603, -1604, -1605, -1607, -1608, -1609, -1610, -1611, -1612, -1613, -1615, -1616, -1617, -1618, -1619, -1620, -1621, -1622, -1624, -1625, -1626, -1627, -1628,
                    -1629, -1631, -1632, -1633, -1634, -1635, -1636, -1637, -1638, -1641, -1644, -1647, -1649, -1652, -1654, -1657, -1660, -1663, -1665, -1668, -1670, -1673, -1676, -1678, -1680,
                    -1682, -1684, -1687, -1689, -1691, -1692, -1694, -1696, -1698, -1701, -1703, -1705, -1706, -1708, -1710, -1712, -1715, -1717, -1719, -1718, -1718, -1717, -1717, -1716, -1716,
                    -1715, -1715, -1715, -1714, -1714, -1713, -1713, -1712, -1712, -1711, -1711, -1710, -1710, -1710, -1709, -1709, -1708, -1708, -1707, -1707, -1706, -1706, -1706, -1705, -1705,
                    -1704, -1704, -1703, -1703, -1703, -1702, -1702, -1701, -1701, -1700, -1700, -1699, -1699, -1698, -1698, -1698, -1697, -1697, -1696, -1696, -1695, -1695, -1694, -1694, -1694,
                    -1693, -1693, -1692, -1692, -1691, -1691, -1691, -1690, -1690, -1689, -1689, -1688, -1688, -1687, -1687, -1687, -1686, -1686, -1685, -1685, -1684, -1684, -1683, -1683, -1682,
                    -1682, -1682, -1681, -1681, -1680, -1680, -1679, -1679, -1678, -1676, -1673, -1670, -1668, -1665, -1663, -1660, -1657, -1654, -1652, -1649, -1647, -1644, -1641, -1638, -1631,
                    -1622, -1615, -1607, -1598, -1591, -1582, -1575, -1566, -1559, -1554, -1550, -1547, -1542, -1538, -1535, -1531, -1526, -1522, -1519, -1510, -1503, -1494, -1487, -1479, -1475,
                    -1471, -1467, -1463, -1459, -1455, -1451, -1447, -1443, -1439, -1432, -1423, -1416, -1408, -1399, -1395, -1392, -1388, -1383, -1379, -1376, -1371, -1367, -1364, -1360, -1351,
                    -1343, -1336, -1327, -1320, -1320, -1321, -1321, -1322, -1323, -1323, -1324, -1324, -1325, -1326, -1326, -1327, -1327, -1328, -1329, -1329, -1330, -1331, -1331, -1332, -1332,
                    -1333, -1334, -1334, -1335, -1336, -1336, -1337, -1337, -1338, -1339, -1339, -1340, -1340, -1341, -1342, -1342, -1343, -1343, -1344, -1345, -1345, -1346, -1347, -1347, -1348,
                    -1348, -1349, -1350, -1350, -1351, -1351, -1352, -1353, -1353, -1354, -1355, -1355, -1356, -1356, -1357, -1358, -1358, -1359, -1360, -1364, -1367, -1371, -1376, -1379, -1383,
                    -1388, -1392, -1395, -1399, -1404, -1408, -1411, -1416, -1420, -1423, -1427, -1432, -1436, -1439, -1445, -1450, -1455, -1461, -1466, -1471, -1476, -1482, -1487, -1492, -1497,
                    -1503, -1508, -1513, -1519, -1524, -1529, -1535, -1540, -1545, -1550, -1556, -1561, -1566, -1572, -1577, -1582, -1588, -1593, -1598, -1607, -1615, -1622, -1631, -1638, -1643,
                    -1647, -1650, -1654, -1659, -1663, -1666, -1670, -1675, -1678, -1687, -1694, -1703, -1710, -1719, -1726, -1735, -1743, -1750, -1759, -1766, -1775, -1782, -1791, -1798, -1803,
                    -1806, -1810, -1815, -1819, -1822, -1826, -1831, -1834, -1838, -1847, -1854, -1863, -1871, -1878, -1887, -1894, -1903, -1910, -1919, -1922, -1926, -1931, -1934, -1938, -1943,
                    -1947, -1950, -1954, -1959, -1966, -1975, -1982, -1991, -1999, -2003, -2006, -2010, -2015, -2019, -2022, -2027, -2031, -2034, -2038, -2041, -2043, -2045, -2047, -2048, -2050,
                    -2052, -2054, -2057, -2059, -2061, -2062, -2064, -2066, -2068, -2071, -2073, -2075, -2076, -2078, -2079, -2079, -2079, -2080, -2080, -2080, -2080, -2081, -2081, -2081, -2082,
                    -2082, -2082, -2082, -2083, -2083, -2083, -2084, -2084, -2084, -2085, -2085, -2085, -2085, -2086, -2086, -2086, -2087, -2087, -2087, -2087, -2088, -2088, -2088, -2089, -2089,
                    -2089, -2089, -2090, -2090, -2090, -2090, -2091, -2091, -2091, -2092, -2092, -2092, -2092, -2093, -2093, -2093, -2094, -2094, -2094, -2094, -2095, -2095, -2095, -2096, -2096,
                    -2096, -2096, -2097, -2097, -2097, -2098, -2098, -2098, -2099, -2099, -2099, -2099, -2100, -2100, -2100, -2101, -2101, -2101, -2101, -2102, -2102, -2102, -2103, -2103, -2103,
                    -2103, -2104, -2104, -2104, -2104, -2105, -2105, -2105, -2106, -2106, -2106, -2106, -2107, -2107, -2107, -2108, -2108, -2108, -2108, -2109, -2109, -2109, -2110, -2110, -2110,
                    -2110, -2111, -2111, -2111, -2112, -2112, -2112, -2113, -2113, -2113, -2113, -2114, -2114, -2114, -2115, -2115, -2115, -2115, -2116, -2116, -2116, -2117, -2117, -2117, -2117,
                    -2118, -2118, -2118, -2119, -2119, -2120, -2121, -2122, -2122, -2123, -2124, -2125, -2126, -2127, -2127, -2128, -2129, -2130, -2131, -2131, -2132, -2133, -2134, -2134, -2135,
                    -2136, -2137, -2138, -2138, -2139, -2140, -2141, -2142, -2143, -2143, -2144, -2145, -2146, -2147, -2147, -2148, -2149, -2150, -2150, -2151, -2152, -2153, -2154, -2155, -2155,
                    -2156, -2157, -2158, -2159, -2161, -2164, -2166, -2169, -2172, -2175, -2177, -2180, -2182, -2185, -2188, -2190, -2193, -2196, -2199, -2201, -2203, -2204, -2206, -2208, -2210,
                    -2213, -2215, -2217, -2218, -2220, -2222, -2224, -2227, -2229, -2231, -2232, -2234, -2236, -2238, -2247, -2255, -2262, -2271, -2278, -2287, -2294, -2303, -2310, -2318, -2321,
                    -2324, -2327, -2329, -2332, -2334, -2337, -2340, -2343, -2345, -2348, -2350, -2353, -2356, -2359, -2358, -2357, -2356, -2355, -2354, -2352, -2351, -2350, -2349, -2348, -2347,
                    -2346, -2346, -2345, -2344, -2343, -2342, -2341, -2340, -2338, -2337, -2336, -2335, -2334, -2333, -2332, -2332, -2331, -2330, -2329, -2328, -2327, -2326, -2324, -2323, -2322,
                    -2321, -2320, -2319, -2318, -2316, -2313, -2310, -2308, -2305, -2303, -2300, -2297, -2294, -2292, -2289, -2287, -2284, -2281, -2278, -2271, -2262, -2255, -2247, -2238, -2237,
                    -2235, -2234, -2232, -2231, -2229, -2227, -2226, -2224, -2222, -2221, -2219, -2218, -2216, -2215, -2213, -2211, -2210, -2208, -2206, -2205, -2203, -2202, -2200, -2199, -2196,
                    -2194, -2192, -2190, -2189, -2187, -2185, -2182, -2180, -2178, -2176, -2175, -2173, -2171, -2169, -2166, -2164, -2162, -2161, -2159, -2156, -2153, -2150, -2148, -2145, -2143,
                    -2140, -2137, -2134, -2132, -2129, -2127, -2124, -2121, -2119, -2117, -2115, -2113, -2110, -2108, -2106, -2104, -2103, -2101, -2099, -2096, -2094, -2092, -2090, -2089, -2087,
                    -2085, -2082, -2080, -2078, -2075, -2071, -2066, -2062, -2059, -2054, -2050, -2047, -2043, -2038, -2031, -2022, -2015, -2006, -1999, -1993, -1988, -1982, -1977, -1972, -1966,
                    -1961, -1956, -1950, -1945, -1940, -1934, -1929, -1924, -1919, -1915, -1910, -1906, -1903, -1899, -1894, -1891, -1887, -1882, -1878, -1871, -1863, -1854, -1847, -1838, -1831,
                    -1822, -1815, -1806, -1798, -1794, -1791, -1787, -1782, -1778, -1775, -1771, -1766, -1763, -1759, -1754, -1750, -1747, -1743, -1738, -1735, -1731, -1726, -1722, -1719, -1710,
                    -1703, -1694, -1687, -1678, -1670, -1663, -1654, -1647, -1638, -1631, -1622, -1615, -1607, -1598, -1591, -1582, -1575, -1566, -1559, -1550, -1542, -1535, -1526, -1519, -1515,
                    -1510, -1507, -1503, -1498, -1494, -1491, -1487, -1482, -1479, -1471, -1463, -1455, -1447, -1439, -1436, -1432, -1427, -1423, -1420, -1416, -1411, -1408, -1404, -1399, -1395,
                    -1392, -1388, -1383, -1379, -1376, -1371, -1367, -1364, -1360, -1343, -1327, -1311, -1295, -1280, -1274, -1269, -1264, -1258, -1253, -1248, -1242, -1237, -1232, -1226, -1221,
                    -1216, -1210, -1205, -1199, -1192, -1183, -1176, -1167, -1160, -1152, -1143, -1136, -1127, -1120, -1111, -1104, -1095, -1087, -1080, -1071, -1064, -1055, -1048, -1039, -1032,
                    -1024, -1015, -1008, -999, -992, -983, -976, -967, -960, -952, -943, -936, -927, -920, -904, -887, -871, -855, -839, -831, -824, -816, -807, -799, -783,
                    -768, -752, -736, -719, -712, -704, -695, -688, -679, -671, -664, -655, -648, -640, -635, -631, -628, -624, -620, -615, -611, -608, -604, -600, -591,
                    -584, -576, -567, -560, -551, -543, -536, -527, -520, -512, -504, -496, -488, -480, -469, -456, -445, -432, -420, -409, -396, -385, -372, -361, -352,
                    -345, -337, -328, -321, -304, -288, -273, -257, -240, -233, -224, -217, -209, -200, -184, -169, -153, -136, -120, -112, -105, -96, -89, -81, -76,
                    -72, -68, -64, -61, -57, -53, -49, -44, 0, 7, 15, 23, 31, 38, 46, 55, 63, 70, 78, 95, 110, 126, 143, 159, 166,
                    174, 183, 190, 199, 207, 214, 223, 230, 238, 254, 271, 287, 302, 318, 327, 335, 342, 351, 358, 382, 406, 430, 455, 479, 510,
                    542, 574, 606, 638, 654, 669, 685, 702, 718, 742, 766, 789, 813, 838, 845, 853, 862, 869, 878, 885, 894, 901, 910, 918, 922,
                    925, 929, 934, 938, 941, 946, 950, 953, 957, 956, 955, 954, 953, 952, 952, 951, 950, 949, 948, 947, 946, 944, 943, 942, 941,
                    940, 939, 938, 938, 937, 936, 935, 934, 933, 932, 930, 929, 928, 927, 926, 925, 924, 924, 923, 922, 921, 920, 919, 918, 916,
                    915, 914, 913, 912, 911, 910, 910, 909, 908, 907, 906, 905, 904, 902, 901, 900, 899, 898, 897, 896, 896, 895, 894, 893, 892,
                    891, 890, 889, 887, 886, 885, 884, 883, 882, 881 };
            }
            return RANDOMIZE_PIT_PATTERN3;
        }

        /// <summary>
        /// pがrcの中にあるかどうかを判定します
        /// </summary>
        /// <param name="p"></param>
        /// <param name="rc"></param>
        /// <returns></returns>
        public static boolean isInRect( Point p, Rectangle rc ) {
            return isInRect( p.x, p.y, rc );
        }

        /// <summary>
        /// 点がrcの中にあるかどうかを判定します
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="rc"></param>
        /// <returns></returns>
        public static boolean isInRect( int x, int y, Rectangle rc ) {
            return isInRect( x, y, rc.x, rc.y, rc.width, rc.height );
        }

        /// <summary>
        /// 点が四角形の中にあるかどうかを判定します
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="rc_x"></param>
        /// <param name="rc_y"></param>
        /// <param name="rc_width"></param>
        /// <param name="rc_height"></param>
        /// <returns></returns>
        public static boolean isInRect( int x, int y, int rc_x, int rc_y, int rc_width, int rc_height ) {
            if ( rc_x <= x ) {
                if ( x <= rc_x + rc_width ) {
                    if ( rc_y <= y ) {
                        if ( y <= rc_y + rc_height ) {
                            return true;
                        }
                    }
                }
            }
            return false;
        }

        /// <summary>
        /// 指定したディレクトリをUTAU音源のディレクトリとみなし,音源名と音源の保存パスを保持したSingerConfigを返します
        /// </summary>
        /// <param name="directory"></param>
        /// <returns></returns>
        public static String readUtauSingerConfig( String directory, SingerConfig sc ) {
            sc.VOICEIDSTR = directory;

            // character.txt読込み
            String character = fsys.combine( directory, "character.txt" );
            String name = null;
            String image = "";
            int mode = 0;
            if ( fsys.isFileExists( character ) ) {
                // 読み込みを試みるエンコーディングのリスト
                foreach ( String encoding in AppManager.TEXT_ENCODINGS_IN_UTAU ) {
                    BufferedReader sr2 = null;
                    try {
                        sr2 = new BufferedReader( new InputStreamReader( new FileInputStream( character ), encoding ) );
                        String line = "";
                        while ( (line = sr2.readLine()) != null ) {
                            String[] spl = PortUtil.splitString( line, '=' );
                            if ( spl.Length > 1 ) {
                                String s = spl[0].ToLower();
                                if ( str.compare( s, "name" ) ) {
                                    name = spl[1];
                                    mode |= 1;
                                } else if ( str.compare( s, "image" ) ) {
                                    image = fsys.combine( directory, spl[1] );
                                    mode |= 2;
                                }
                                if ( mode == 3 ) {
                                    break;
                                }
                            }
                        }
                    } catch ( Exception ex ) {
                        serr.println( "Utility#readUtausingerConfig; ex=" + ex );
                        Logger.write( typeof( Utility ) + ".readUtausingerConfig; ex=" + ex + "\n" );
                    } finally {
                        if ( sr2 != null ) {
                            try {
                                sr2.close();
                            } catch ( Exception ex2 ) {
                                serr.println( "Utility#readUtausingerConfig; ex2=" + ex2 );
                                Logger.write( typeof( Utility ) + ".readUtausingerConfig; ex= " + ex2 + "\n" );
                            }
                        }
                    }
                    if ( name != null ) {
#if DEBUG
                        sout.println( "Utility#readUtausingerConfig; name=" + name + "; encoding=" + encoding );
#endif
                        break;
                    }
                }
            }
            if ( name == null ){
                name = PortUtil.getFileNameWithoutExtension( directory );
            }
            sc.VOICENAME = name;
            return image;
        }

        /// <summary>
        /// VSQイベントの長さを変更すると同時に、ビブラートの長さを指定したルールに則って変更します。
        /// </summary>
        /// <param name="vsq_event"></param>
        /// <param name="new_length"></param>
        /// <param name="rule"></param>
        public static void editLengthOfVsqEvent( VsqEvent vsq_event, int new_length, VibratoLengthEditingRule rule ) {
#if DEBUG
            sout.println( "Utility#editLengthOfVsqEvent; rule=" + rule );
#endif
            if ( vsq_event.ID.VibratoHandle != null ) {
                int oldlength = vsq_event.ID.getLength();
                int new_delay = vsq_event.ID.VibratoDelay; // ここではディレイが独立変数

                if ( rule == VibratoLengthEditingRule.DELAY ) {
                    // ディレイが保存される
                    // 特に何もしない
                } else if ( rule == VibratoLengthEditingRule.LENGTH ) {
                    // ビブラート長さが保存される
                    new_delay = new_length - vsq_event.ID.VibratoHandle.getLength();
                    if ( new_delay < 0 ) {
                        new_delay = 0;
                    }
                } else if ( rule == VibratoLengthEditingRule.PERCENTAGE ) {
                    // ビブラート長の割合が保存される
                    double old_percentage = vsq_event.ID.VibratoDelay / (double)oldlength * 100.0;
                    new_delay = (int)(new_length * old_percentage / 100.0);
                    if ( new_delay < 0 ) {
                        new_delay = 0;
                    }
                }

                if ( new_delay >= new_length ) {
                    // ディレイが音符より長い場合。ビブラートは削除される
                    vsq_event.ID.VibratoDelay = new_length;
                    vsq_event.ID.VibratoHandle = null;
                } else {
                    vsq_event.ID.VibratoDelay = new_delay;
                    vsq_event.ID.VibratoHandle.setLength( new_length - new_delay );
                }
            }

            if ( vsq_event.ID.type == VsqIDType.Anote ) {
                // 音符
                vsq_event.ID.setLength( new_length );
            } else if ( vsq_event.ID.type == VsqIDType.Singer ) {
                // 歌手変更
                vsq_event.ID.setLength( 1 );
            } else if ( vsq_event.ID.type == VsqIDType.Aicon ) {
                // 強弱記号、クレッシェンド、デクレッシェンド
                if ( vsq_event.ID.IconDynamicsHandle != null ) {
                    if ( vsq_event.ID.IconDynamicsHandle.isDynaffType() ) {
                        // 強弱記号
                        vsq_event.ID.IconDynamicsHandle.setLength( 1 );
                        vsq_event.ID.setLength( 1 );
                    } else {
                        // クレッシェンド、デクレッシェンド
                        vsq_event.ID.IconDynamicsHandle.setLength( new_length );
                        vsq_event.ID.setLength( new_length );
                    }
                } else {
                    vsq_event.ID.setLength( new_length );
                }
            } else {
                // 不明
                vsq_event.ID.setLength( new_length );
            }
        }

        /// <summary>
        /// 与えられた式をC#の数式とみなし、評価します。
        /// equationに"x"という文字列がある場合、それを変数xとみなし、引数xの値が代入される。
        /// </summary>
        /// <param name="x"></param>
        /// <param name="equation"></param>
        /// <returns></returns>
        public static double eval( double x, String equation ) {
            String equ = "(" + equation + ")"; // ( )でくくる
            equ = equ.Replace( "Math.PI", Math.PI + "" ); // πを数値に置換
            equ = equ.Replace( "Math.E", Math.E + "" ); // eを数値に置換
            equ = equ.Replace( "exp", "ezp" ); // exp を ezp に置換しておく
            equ = equ.Replace( "x", x + "" ); // xを数字に置換
            equ = equ.Replace( "ezp", "exp" ); // ezp を exp に戻す

            int m0 = 0; // -- の処理-------(注釈:x を数値に置換したので、x が負値のとき  --3.1 のようになっている)
            while ( true ) {
                int m1 = equ.IndexOf( "--", m0 );
                if ( m1 < 0 ) {
                    break;
                }
#if JAVA
                int eq_mi_1 = (int)equ.charAt( m1 - 1 );
#else
                int eq_mi_1 = equ[m1 - 1];
#endif
                if ( m1 == 0 || eq_mi_1 == 40 || eq_mi_1 == 42 || eq_mi_1 == 47 || eq_mi_1 == 43 || eq_mi_1 == 44 ) {
                    equ = str.sub( equ, 0, m1 - 0 ) + str.sub( equ, m1 + 2 ); // -- を 取る
                } else {
                    equ = str.sub( equ, 0, m1 - 0 ) + "+" + str.sub( equ, m1 + 2 ); // -- を + に置換
                }
                m0 = m1;
                if ( m0 > PortUtil.getStringLength( equ ) - 1 ) {
                    break;
                }
            }

            m0 = 0; // - の処理-------
            while ( true ) {
                int m1 = equ.IndexOf( "-", m0 );
                if ( m1 < 0 ) {
                    break;
                }
#if JAVA
                int eq_mi_1 = (int)equ.charAt( m1 - 1 );
#else
                int eq_mi_1 = equ[m1 - 1];
#endif
                if ( m1 == 0 || eq_mi_1 == 40 || eq_mi_1 == 42 || eq_mi_1 == 47 || eq_mi_1 == 43 || eq_mi_1 == 44 ) {
                    m0 = m1 + 1;
                } else {
                    equ = str.sub( equ, 0, m1 - 0 ) + "+(-1)*" + str.sub( equ, m1 + 1 ); // -a、-Math.sin(A) などを +(-1)*a、 +(-1)*Math.sin(A) などに置き換える
                    m0 = m1 + 6;
                }
                if ( m0 > PortUtil.getStringLength( equ ) - 1 ) {
                    break;
                }
            }
            double valResult = str.tof( evalMy0( equ ) );
            return valResult;
        }

        //----------------------------------------------------------------------------------
        private static String evalMy0( String equation ) {
            String equ = equation;
            while ( true ) {
                // 最内側の( ) から計算する(注釈:最内側( )内には、Math.…() のようなものはない)
                int n1 = equ.IndexOf( ")" );
                if ( n1 < 0 ) {
                    break;
                } // ) の検索
                int n2 = equ.LastIndexOf( "(", n1 - 1 ); // ( に対応する ) の検索
                if ( n2 < 0 ) {
                    break;
                }
                String str2 = str.sub( equ, n2 + 1, n1 - n2 - 1 ); // ( )内の文字
                int ne0 = str2.IndexOf( "," ); // ( )内の , の検索
                double val = 0;

                if ( ne0 >= 0 ) {
                    // ( )内に , があるので、 Math.log(A,B) or Math.Pow(A,B) の処理
                    if ( str.compare( str.sub( equ, n2 - 3, n2 - n2 + 3 ), "log" ) ) {
                        // Math.log(A,B) のとき
                        String strA = str.sub( str2, 0, ne0 - 0 ); // Math.log(A,B)の A の文字
                        double valA = str.tof( evalMy0( "(" + strA + ")" ) ); // (注:再帰である)
                        String strB = str.sub( str2, ne0 + 1 ); // Math.log(A,B)の B の文字
                        double valB = str.tof( evalMy0( "(" + strB + ")" ) ); //(注:再帰である)
                        val = Math.Log( valB ) / Math.Log( valA );
                        equ = equ.Replace( "Math.Log(" + strA + "," + strB + ")", "" + val );
                    } else if ( str.compare( str.sub( equ, n2 - 3, n2 - n2 + 3 ), "pow" ) ) { // Math.Pow(A,B) のとき
                        String strA = str.sub( str2, 0, ne0 - 0 ); // Math.Pow(A,B)の A の文字
                        double valA = str.tof( evalMy0( "(" + strA + ")" ) ); // (注:再帰である)
                        String strB = str.sub( str2, ne0 + 1 ); // Math.Pow(A,B)の B の文字
                        double valB = str.tof( evalMy0( "(" + strB + ")" ) ); //(注:再帰である)
                        val = Math.Pow( valA, valB );
                        equ = equ.Replace( "Math.Pow(" + strA + "," + strB + ")", "" + val );
                    }
                } else {
                    int check0 = 0; // strが数値(数字)かどうかチェック(str="-3.7" なら 数値なので 0 とする)
                    for ( int i = 0; i < PortUtil.getStringLength( str2 ); i++ ) {
                        if ( i == 0 ) {
#if JAVA
                            int str0 = (int)str2.charAt( 0 );
#else
                            int str0 = str2[0];
#endif
                            if ( (str0 < 48 || str0 > 57) && str0 != 46 && str0 != 43 && str0 != 45 ) {
                                check0 = 1;
                                break;
                            }
                        } else {
#if JAVA
                            int stri = (int)str2.charAt( i );
#else
                            int stri = str2[i];
#endif
                            if ( (stri < 48 || stri > 57) && stri != 46 ) {
                                check0 = 1;
                                break;
                            }
                        }
                    }

                    if ( check0 == 1 ) {
                        val = evalMy1( str2 ); // ( ) の処理をし数値をもとめる
                    } else {
                        val = str.tof( str2 ); // 文字を数値に変換
                    }
                    if ( n2 - 8 >= 0 ) {
                        String str1 = str.sub( equ, n2 - 8, n2 - (n2 - 8) );
                        if ( str.compare( str1, "Math.Sin" ) ) {
                            val = Math.Sin( val );
                            equ = equ.Replace( "Math.Sin(" + str2 + ")", "" + val );
                            n2 -= 8;
                        } else if ( str.compare( str1, "Math.Cos" ) ) {
                            val = Math.Cos( val );
                            equ = equ.Replace( "Math.Cos(" + str2 + ")", "" + val );
                            n2 -= 8;
                        } else if ( str.compare( str1, "Math.Tan" ) ) {
                            val = Math.Tan( val );
                            equ = equ.Replace( "Math.Tan(" + str2 + ")", "" + val );
                            n2 -= 8;
                        } else if ( str.compare( str1, "ath.Asin" ) ) {
                            val = Math.Asin( val );
                            equ = equ.Replace( "Math.Asin(" + str2 + ")", "" + val );
                            n2 -= 9;
                        } else if ( str.compare( str1, "ath.Acos" ) ) {
                            val = Math.Acos( val );
                            equ = equ.Replace( "Math.Acos(" + str2 + ")", "" + val );
                            n2 -= 9;
                        } else if ( str.compare( str1, "ath.Atan" ) ) {
                            val = Math.Atan( val );
                            equ = equ.Replace( "Math.Atan(" + str2 + ")", "" + val );
                            n2 -= 9;
                        } else if ( str.compare( str1, "Math.Log" ) ) {
                            val = Math.Log( val );
                            equ = equ.Replace( "Math.Log(" + str2 + ")", "" + val );
                            n2 -= 8;
                        } else if ( str.compare( str1, "Math.Exp" ) ) {
                            val = Math.Exp( val );
                            equ = equ.Replace( "Math.Exp(" + str2 + ")", "" + val );
                            n2 -= 8;
                        } else if ( str.compare( str1, "Math.Abs" ) ) {
                            val = Math.Abs( val );
                            equ = equ.Replace( "Math.Abs(" + str2 + ")", "" + val );
                            n2 -= 8;
                        } else if ( str.compare( str1, "ath.Sqrt" ) ) {
                            val = Math.Sqrt( val );
                            equ = equ.Replace( "Math.Sqrt(" + str2 + ")", "" + val );
                            n2 -= 9;
                        } else {
                            equ = equ.Replace( "(" + str2 + ")", "" + val );
                        } // ( ) を取る
                    } else {
                        equ = equ.Replace( "(" + str2 + ")", "" + val ); // ( ) を取る
                    }
                }
            }
            return equ;
        }

        // * と / のみからなる数式の いくつかの和、差からなる式の処理----------------
        private static double evalMy1( String equation ) {
            double val = 0;
            while ( true ) {
                String equ0 = "";
                int n0 = equation.IndexOf( "+" );
                if ( n0 < 0 ) {
                    equ0 = equation;
                } else {
                    equ0 = str.sub( equation, 0, n0 - 0 );
                } // 最初の + より前の項
                val += evalMy2( equ0 );
                if ( n0 < 0 ) {
                    break;
                } else {
                    equation = str.sub( equation, n0 + 1 );
                } // 最初の + より以降の項
            }
            return val;
        }

        // * と / のみからなる数式についての処理-----------------------------------
        private static double evalMy2( String equation ) {
            double val0 = 1;
            while ( true ) {
                String equ0 = "";
                int n0 = equation.IndexOf( "*" );
                if ( n0 < 0 ) {
                    equ0 = equation;
                } else {
                    equ0 = str.sub( equation, 0, n0 );
                } // 最初の * より前の項

                int kai = 0;
                double val1 = 1;
                while ( true ) { // / を含んだ項の計算
                    String equ1 = "";
                    int n1 = equ0.IndexOf( "/" );
                    if ( n1 < 0 ) {
                        equ1 = equ0;
                    } else {
                        equ1 = str.sub( equ0, 0, n1 - 0 );
                    } // 最初の / より前の項
                    if ( kai == 0 ) {
                        val1 = str.tof( equ1 );
                    } else {
                        val1 /= str.tof( equ1 );
                    }
                    if ( n1 < 0 ) {
                        break;
                    } else {
                        kai++;
                        equ0 = str.sub( equ0, n1 + 1 );
                    } // 最初の / より以降の項
                }
                val0 *= val1;
                if ( n0 < 0 ) {
                    break;
                } else {
                    equation = str.sub( equation, n0 + 1 );
                } // 最初の * より以降の項
            }
            return val0;
        }

        public static EditedZoneUnit[] detectRenderedStatusDifference( RenderedStatus status1, RenderedStatus status2 ) {
            EditedZoneUnit[] areaTempo = detectTempotableDifference( status1.tempo, status2.tempo );
            EditedZoneUnit[] areaTrack = detectTrackDifference( status1.track, status2.track );
            EditedZone zone = new EditedZone();
            if ( status1.config.SamplingRate != status2.config.SamplingRate ||
                 status1.config.WaveFileOutputChannel != status2.config.WaveFileOutputChannel ) {
                zone.add( 0, int.MaxValue );
            }
            zone.add( areaTempo );
            zone.add( areaTrack );
            EditedZoneUnit[] ret = new EditedZoneUnit[zone.size()];
            int i = -1;
            for ( Iterator<EditedZoneUnit> itr = zone.iterator(); itr.hasNext(); ) {
                i++;
                ret[i] = itr.next();
            }
            return ret;
        }

        public static EditedZoneUnit[] detectTempotableDifference( TempoVector tempo1, TempoVector tempo2 ) {
            int len = Math.Min( tempo1.size(), tempo2.size() );
            int clockDifferenceStarted = int.MaxValue;
            for ( int i = 0; i < len; i++ ) {
                TempoTableEntry item1 = tempo1.get( i );
                TempoTableEntry item2 = tempo2.get( i );
                if ( item1.Clock != item2.Clock || item1.Tempo != item2.Tempo ) {
                    clockDifferenceStarted = Math.Min( item1.Clock, item2.Clock );
                    break;
                }
            }
            if ( clockDifferenceStarted == int.MaxValue ) {
                if ( len < tempo1.size() ) {
                    clockDifferenceStarted = Math.Min( clockDifferenceStarted, tempo1.get( len ).Clock );
                }
                if ( len < tempo2.size() ) {
                    clockDifferenceStarted = Math.Min( clockDifferenceStarted, tempo2.get( len ).Clock );
                }
            }
            if ( clockDifferenceStarted != int.MaxValue ) {
                return new EditedZoneUnit[] { new EditedZoneUnit( clockDifferenceStarted, int.MaxValue ) };
            } else {
                return new EditedZoneUnit[] { };
            }
        }

        /// <summary>
        /// 2つのトラック情報を比較し、違う部分を検出します
        /// </summary>
        /// <param name="track1"></param>
        /// <param name="track2"></param>
        /// <returns></returns>
        public static EditedZoneUnit[] detectTrackDifference( VsqTrack track1, VsqTrack track2 ) {
            EditedZone ret = new EditedZone();

            if ( VsqFileEx.getTrackRendererKind( track1 ) != VsqFileEx.getTrackRendererKind( track2 ) ) {
                return new EditedZoneUnit[] { new EditedZoneUnit( 0, int.MaxValue ) };
            }

            // resamplerの利用状況を比較
            int index1 = VsqFileEx.getTrackResamplerUsed( track1 );
            int index2 = VsqFileEx.getTrackResamplerUsed( track2 );
            if ( index1 != index2 ) {
                return new EditedZoneUnit[] { new EditedZoneUnit( 0, int.MaxValue ) };
            }

            int numEvent1 = track1.getEventCount();
            int numEvent2 = track2.getEventCount();

            // track1にあってtrack2に無い音符イベント、クレッシェンドイベントを検出
            compareEvent( track1, track2, ret );

            // track2にあってtrack1に無い音符イベント、クレッシェンドイベントを検出
            compareEvent( track2, track1, ret );

            // 歌手変更の違いを検出
            compareList( ret, new SingerEventComparisonContext( track1, track2 ) );

            // 強弱記号の違いを検出
            compareList( ret, new DynaffComparisonContext( track1, track2 ) );

            // VsqBPListの違いを検出
            foreach ( CurveType curve in CURVE_USAGE ) {
                VsqBPList list1 = track1.getCurve( curve.getName() );
                if ( list1 == null ) {
                    continue;
                }
                VsqBPList list2 = track2.getCurve( curve.getName() );
                if ( list2 == null ) {
                    continue;
                }
                compareList( ret, new VsqBPListComparisonContext( list1, list2 ) );
            }

            Vector<EditedZoneUnit> list3 = new Vector<EditedZoneUnit>();
            for ( Iterator<EditedZoneUnit> itr = ret.iterator(); itr.hasNext(); ) {
                list3.add( itr.next() );
            }
            return list3.toArray( new EditedZoneUnit[] { } );
        }

        /// <summary>
        /// track1にあってtrack2に無い音符イベント,クレッシェンドイベントを検出し,引数retに記録します
        /// </summary>
        /// <param name="track1"></param>
        /// <param name="track2"></param>
        /// <param name="ret"></param>
        private static void compareEvent( VsqTrack track1, VsqTrack track2, EditedZone ret )
        {
            RendererKind kind = VsqFileEx.getTrackRendererKind( track1 );
            int iterator_kind = IndexIteratorKind.NOTE | IndexIteratorKind.CRESCEND | IndexIteratorKind.DECRESCEND;
            for ( Iterator<Integer> itr1 = track1.indexIterator( iterator_kind ); itr1.hasNext(); ) {
                int i = itr1.next();
                VsqEvent item1 = track1.getEvent( i );
                boolean found = false;
                for ( Iterator<Integer> itr2 = track2.indexIterator( iterator_kind ); itr2.hasNext(); ) {
                    int j = itr2.next();
                    VsqEvent item2 = track2.getEvent( j );
                    // item1とitem2が同じかどうか判定する
                    if ( item1.equals( item2 ) ) {
                        // UTAU 音源を使用する際はUstEvent内も比較しないといけない.
                        if ( kind == RendererKind.VCNT || kind == RendererKind.UTAU ) {
                            // 歌詞は UstEvent からは判断できないので
                            if ( item1.UstEvent.equalsForSynth( item2.UstEvent ) && item1.ID.LyricHandle.L0.Phrase == item2.ID.LyricHandle.L0.Phrase ) {
                                found = true;
                                break;
                            }
                        } else { 
                            // vsq 使用の場合はこちらのみで大丈夫.
                            found = true;
                            break;
                        }
                    }
                }
                if ( !found ) {
                    ret.add( item1.Clock, item1.Clock + item1.ID.getLength() );
                }
            }
        }

        /// <summary>
        /// 指定された比較用コンテキストを用いて2つのタイムラインを比較し,相違点を調べます.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public static EditedZoneUnit[] compareList( IComparisonContext context ) {
            EditedZone zone = new EditedZone();
            compareList( zone, context );
            Vector<EditedZoneUnit> ret = new Vector<EditedZoneUnit>();
            for ( Iterator<EditedZoneUnit> itr = zone.iterator(); itr.hasNext(); ) {
                ret.add( itr.next() );
            }
            return ret.toArray( new EditedZoneUnit[] { } );
        }

        /// <summary>
        /// 指定された比較用コンテキストを用いて2つのタイムラインを比較し,相違点を調べます.
        /// </summary>
        /// <param name="zone"></param>
        /// <param name="context"></param>
        public static void compareList( EditedZone zone, IComparisonContext context ) {
            if ( context.hasNext1() && context.hasNext2() ) {
                int i1 = context.getNextIndex1();
                int i2 = context.getNextIndex2();
                Object last1 = context.getElementAt1( i1 );
                Object last2 = context.getElementAt2( i2 );
                int clock = 0; // 評価区間の開始ゲートタイム
                while ( true ) {
                    Object item1 = context.getElementAt1( i1 );
                    Object item2 = context.getElementAt2( i2 );
                    int clock1 = context.getClockFrom( item1 );
                    int clock2 = context.getClockFrom( item2 );

                    if ( clock1 == clock2 ) {
                        // 検査中のゲートタイムが同じ場合
                        if ( clock < clock1 ) {
                            if ( !context.equals( last1, last2 ) ) {
                                zone.add( clock, clock1 );
                            }
                        }

                        // 次のイベントをどう決めるか?
                        if ( context.hasNext1() ) {
                            i1 = context.getNextIndex1();
                            last1 = item1;
                        } else if ( context.hasNext2() ) {
                            i2 = context.getNextIndex2();
                            last2 = item2;
                        } else {
                            if ( !context.equals( item1, item2 ) ) {
                                zone.add( clock1, int.MaxValue );
                            }
                            break;
                        }
                        clock = clock1;
                    } else if ( clock1 < clock2 ) {
                        if ( clock < clock1 ) {
                            if ( !context.equals( last1, last2 ) ) {
                                zone.add( clock, clock1 );
                            }
                        }
                        last1 = item1;
                        if ( context.hasNext1() ) {
                            i1 = context.getNextIndex1();
                        } else {
                            if ( !context.equals( item1, last2 ) ) {
                                zone.add( clock1, clock2 );
                            }
                            last2 = item2;
                            while ( context.hasNext2() ) {
                                i2 = context.getNextIndex2();
                                item2 = context.getElementAt2( i2 );
                                if ( !context.equals( last1, last2 ) ) {
                                    zone.add( context.getClockFrom( last2 ), context.getClockFrom( item2 ) );
                                }
                                last2 = item2;
                            }
                            if ( !context.equals( last1, item2 ) ) {
                                zone.add( context.getClockFrom( item2 ), int.MaxValue );
                            }
                            break;
                        }
                        clock = clock1;
                    } else if ( clock2 < clock1 ) {
                        if ( clock < clock2 ) {
                            if ( !context.equals( last1, last2 ) ) {
                                zone.add( clock, clock2 );
                            }
                        }
                        last2 = item2;
                        if ( context.hasNext2() ) {
                            i2 = context.getNextIndex2();
                        } else {
                            if ( !context.equals( last1, item2 ) ) {
                                zone.add( clock2, clock1 );
                            }
                            last1 = item1;
                            while ( context.hasNext1() ) {
                                i1 = context.getNextIndex1();
                                item1 = context.getElementAt1( i1 );
                                if ( !context.equals( last1, last2 ) ) {
                                    zone.add( context.getClockFrom( last1 ), context.getClockFrom( item1 ) );
                                }
                                last1 = item1;
                            }
                            if ( !context.equals( last2, item1 ) ) {
                                zone.add( context.getClockFrom( item1 ), int.MaxValue );
                            }
                            break;
                        }
                        clock = clock2;
                    }
                }
            }
        }

        public static String getShortcutDisplayString( BKeys[] keys ) {
            String ret = "";
#if JAVA_MAC
            String plus = "";
            String ctrl = "^";
            String shift = "⇧";
            String option = "⌥";
            String command = "⌘";
#else
            String plus = "+";
            String ctrl = "Ctrl";
            String shift = "Shift";
            String option = "Alt";
            String command = "Meta";
#endif
            Vector<BKeys> list = new Vector<BKeys>( Arrays.asList( keys ) );
            if ( list.contains( BKeys.Control ) ) {
                ret += (str.compare( ret, "" ) ? "" : plus) + ctrl;
            }
            if ( list.contains( BKeys.Alt ) ) {
                ret += (str.compare( ret, "" ) ? "" : plus) + option;
            }
            if ( list.contains( BKeys.Shift ) ) {
                ret += (str.compare( ret, "" ) ? "" : plus) + shift;
            }
            if ( list.contains( BKeys.Menu ) ) {
                ret += (str.compare( ret, "" ) ? "" : plus) + command;
            }
            Vector<BKeys> list2 = new Vector<BKeys>();
            foreach ( BKeys key in keys ) {
                if ( key != BKeys.Control && key != BKeys.Shift && key != BKeys.Alt && key != BKeys.Menu ) {
                    list2.add( key );
                }
            }
            Collections.sort( list2 );
            for ( int i = 0; i < list2.size(); i++ ) {
                ret += (str.compare( ret, "" ) ? "" : plus) + getKeyDisplayString( list2.get( i ) );
            }
            return ret;
        }

        private static String getKeyDisplayString( BKeys key ) {
            if ( key.Equals( BKeys.PageDown ) ) {
                return "PgDn";
            } else if ( key.Equals( BKeys.PageUp ) ) {
                return "PgUp";
            } else if ( key.Equals( BKeys.D0 ) ) {
                return "0";
            } else if ( key.Equals( BKeys.D1 ) ) {
                return "1";
            } else if ( key.Equals( BKeys.D2 ) ) {
                return "2";
            } else if ( key.Equals( BKeys.D3 ) ) {
                return "3";
            } else if ( key.Equals( BKeys.D4 ) ) {
                return "4";
            } else if ( key.Equals( BKeys.D5 ) ) {
                return "5";
            } else if ( key.Equals( BKeys.D6 ) ) {
                return "6";
            } else if ( key.Equals( BKeys.D7 ) ) {
                return "7";
            } else if ( key.Equals( BKeys.D8 ) ) {
                return "8";
            } else if ( key.Equals( BKeys.D9 ) ) {
                return "9";
            } else if ( key.Equals( BKeys.Menu ) ) {
#if JAVA
                return new String( new char[]{ '\u2318' } );
#else
                return new String( '\x2318', 1 );
#endif
#if JAVA_MAC
            } else if ( key.Equals( BKeys.Back ) ){
                return "⌫";
#endif
            } else {
                return key.ToString();
            }
        }

        /// <summary>
        /// アプリケーションデータの保存位置を取得します
        /// Gets the path for application data
        /// </summary>
        public static String getApplicationDataPath() {
#if JAVA
            String osname =  System.getProperty( "os.name" );
            String appdata = "./";
            if ( osname.indexOf( "Windows" ) >= 0 ) {
                appdata = System.getenv( "LOCALAPPDATA" );
                if ( appdata == null ) {
                    appdata = System.getenv( "APPDATA" );
                    if ( appdata != null ) {
                        String roaming = "Roaming";
                        int indx = appdata.indexOf( roaming );
                        if( indx > 0 ){
                            appdata = appdata.substring( 0, indx ) + "Local" + appdata.substring( indx + roaming.length() );
                        }
                    }
                }
            } else {
                String home = System.getenv( "HOME" );
                if ( home != null && osname != null ) {
                    if ( osname.indexOf( "nix") >= 0 || osname.indexOf( "nux" ) >= 0 ) {
                        // for Unix-like system which have desktop
                        // based on freedesktop.org spec
                        appdata = fsys.combine( fsys.combine( home, ".local" ), "share" );
                    } else {
                        // for MacOSX
                        appdata = fsys.combine( fsys.combine( home, "Library" ), "Preferences" );
                    }
                }
            }
            String dir = fsys.combine( appdata, "Boare" );
#else
            String dir = fsys.combine( Environment.GetFolderPath( Environment.SpecialFolder.LocalApplicationData ), "Boare" );
#endif
            if ( !fsys.isDirectoryExists( dir ) ) {
                PortUtil.createDirectory( dir );
            }

            String dir2 = fsys.combine( dir, CONFIG_DIR_NAME );
            if ( !fsys.isDirectoryExists( dir2 ) ) {
                PortUtil.createDirectory( dir2 );
            }
            sout.println( "Cadencii accesses ApplicationData at" + dir2 + "\n" );//Keep this line for debuging.
	    
            return dir2;
        }

        /// <summary>
        /// 設定ファイルを保存するディレクトリへのパスを取得します
        /// </summary>
        /// <returns></returns>
        public static String getConfigPath() {
            String dir2 = getApplicationDataPath();
            String dir3 = fsys.combine( dir2, BAssemblyInfo.fileVersionMeasure + "." + BAssemblyInfo.fileVersionMinor );
            if ( !fsys.isDirectoryExists( dir3 ) ) {
                PortUtil.createDirectory( dir3 );
            }
            return dir3;
        }

        /// <summary>
        /// 使用されていないアセンブリのキャッシュを削除します
        /// </summary>
        public static void cleanupUnusedAssemblyCache() {
            String dir = getCachedAssemblyPath();
            String[] files = PortUtil.listFiles( dir, ".dll" );
            foreach ( String file in files ) {
                String name = PortUtil.getFileName( file );
                String full = fsys.combine( dir, name );
                if ( !usedAssemblyChache.contains( full ) ) {
                    try {
                        PortUtil.deleteFile( full );
                    } catch ( Exception ex ) {
                        serr.println( "Utility#cleanupUnusedAssemblyCache; ex=" + ex );
                        Logger.write( typeof( Utility ) + ".cleanupUnusedAssemblyCache; ex=" + ex + "\n" );
                    }
                }
            }
        }

#if ENABLE_SCRIPT
        public static Assembly compileScript( String code, Vector<String> errors ) {
#if DEBUG
            sout.println( "Utility#compileScript" );
#endif
            Assembly ret = null;

            String md5 = PortUtil.getMD5FromString( code ).Replace( "_", "" );
            String cached_asm_file = fsys.combine( getCachedAssemblyPath(), md5 + ".dll" );
            boolean compiled = false;
            if ( fsys.isFileExists( cached_asm_file ) ) {
                ret = Assembly.LoadFile( cached_asm_file );
                if ( ret != null ) {
                    if ( !usedAssemblyChache.contains( cached_asm_file ) ) {
                        usedAssemblyChache.add( cached_asm_file );
                    }
                }
            }

            CompilerResults cr = null;
            if ( ret == null ) {
#if DEBUG
                sout.println( "Utility#compileScriptl code=" + code );
#endif
                CSharpCodeProvider provider = new CSharpCodeProvider();
                String path = System.Windows.Forms.Application.StartupPath;
                CompilerParameters parameters = new CompilerParameters( new String[] {
                fsys.combine( path, "org.kbinani.vsq.dll" ),
                fsys.combine( path, "Cadencii.exe" ),
                fsys.combine( path, "org.kbinani.media.dll" ),
                fsys.combine( path, "org.kbinani.apputil.dll" ),
                fsys.combine( path, "org.kbinani.windows.forms.dll" ),
                fsys.combine( path, "org.kbinani.dll" ) } );
                parameters.ReferencedAssemblies.Add( "System.Windows.Forms.dll" );
                parameters.ReferencedAssemblies.Add( "System.dll" );
                parameters.ReferencedAssemblies.Add( "System.Drawing.dll" );
                parameters.ReferencedAssemblies.Add( "System.Xml.dll" );
                parameters.GenerateInMemory = false;
                parameters.GenerateExecutable = false;
                parameters.IncludeDebugInformation = true;
                try {
                    cr = provider.CompileAssemblyFromSource( parameters, code );
                    ret = cr.CompiledAssembly;
                    compiled = true;
                } catch ( Exception ex ) {
                    serr.println( "Utility#compileScript; ex=" + ex );
                    Logger.write( typeof( Utility ) + ".compileScript; ex=" + ex + "\n" );
                }
                if ( !compiled ) {
                    int c = cr.Errors.Count;
                    for ( int i = 0; i < c; i++ ) {
                        errors.add( _( "line" ) + ":" + cr.Errors[i].Line + " " + cr.Errors[i].ErrorText );
                    }
                }
            }

            if ( compiled ) {
                if ( !usedAssemblyChache.contains( cached_asm_file ) ) {
                    usedAssemblyChache.add( cached_asm_file );
                }
                if ( fsys.isFileExists( cached_asm_file ) ) {
                    try {
                        PortUtil.deleteFile( cached_asm_file );
                    } catch ( Exception ex ) {
                        serr.println( "Utility#compileScript; ex=" + ex );
                        Logger.write( typeof( Utility ) + ".compileScript; ex=" + ex + "\n" );
                    }
                }
                try {
                    PortUtil.copyFile( cr.PathToAssembly, cached_asm_file );
                } catch ( Exception ex ) {
                    serr.println( "Utility#compileScript; ex=" + ex );
                    Logger.write( typeof( Utility ) + ".compileScript; ex=" + ex + "\n" );
                }
            }
            
            return ret;
        }
#endif


        /// <summary>
        /// 指定されたファイルを読み込んでスクリプトをコンパイルします.
        /// </summary>
        /// <param name="file">スクリプトを発動するのに使用するコンテナを返します.</param>
        /// <returns></returns>
#if ENABLE_SCRIPT
        public static ScriptInvoker loadScript( String file ) {
#if JAVA
            ScriptInvoker ret = new ScriptInvoker();
            return ret;
#else
#if DEBUG
            AppManager.debugWriteLine( "Utility#loadScript(String)" );
            AppManager.debugWriteLine( "    File.GetLastWriteTimeUtc( file )=" + System.IO.File.GetLastWriteTimeUtc( file ) );
#endif
            ScriptInvoker ret = new ScriptInvoker();
            ret.ScriptFile = file;
            ret.fileTimestamp = PortUtil.getFileLastModified( file );
            // スクリプトの記述のうち、以下のリストに当てはまる部分は空文字に置換される
            String config_file = ScriptServer.configFileNameFromScriptFileName( file );
            String script = "";
            BufferedReader sr = null;
            try {
                sr = new BufferedReader( new FileReader( file ) );
                String line = "";
                while ( (line = sr.readLine()) != null ) {
                    script += line + "\n";
                }
            } catch ( Exception ex ) {
                serr.println( "Utility#loadScript; ex=" + ex );
                Logger.write( typeof( Utility ) + ".loadScript; ex=" + ex + "\n" );
            } finally {
                if ( sr != null ) {
                    try {
                        sr.close();
                    } catch ( Exception ex2 ) {
                        serr.println( "Utility#loadScript; ex2=" + ex2 );
                        Logger.write( typeof( Utility ) + ".loadScript; ex=" + ex2 + "\n" );
                    }
                }
            }

            String code = "";
            foreach ( String s in AppManager.usingS ) {
                code += s;
            }
            code += "namespace org.kbinani.cadenciiScript{";
            code += script;
            code += "}";
            ret.ErrorMessage = "";

            Vector<String> errors = new Vector<String>();
            Assembly testAssembly = Utility.compileScript( code, errors );
            if ( testAssembly == null ) {
                ret.scriptDelegate = null;
                if ( errors.size() == 0 ) {
                    ret.ErrorMessage = "failed compiling";
                } else {
                    for ( int i = 0; i < errors.size(); i++ ) {
                        ret.ErrorMessage += errors.get( i ) + "\r\n";
                    }
                }
                return ret;
            } else {
                foreach ( Type implemented in testAssembly.GetTypes() ) {
                    Object scriptDelegate = null;
                    ScriptDelegateGetDisplayName getDisplayNameDelegate = null;

                    MethodInfo get_displayname_delegate = implemented.GetMethod( "GetDisplayName", new Type[] { } );
                    if ( get_displayname_delegate != null && get_displayname_delegate.IsStatic && get_displayname_delegate.IsPublic ) {
                        if ( get_displayname_delegate.ReturnType.Equals( typeof( String ) ) ) {
                            getDisplayNameDelegate = (ScriptDelegateGetDisplayName)Delegate.CreateDelegate( typeof( ScriptDelegateGetDisplayName ), get_displayname_delegate );
                        }
                    }

                    MethodInfo tmi = implemented.GetMethod( "Edit", new Type[] { typeof( VsqFile ) } );
                    if ( tmi != null && tmi.IsStatic && tmi.IsPublic ) {
                        if ( tmi.ReturnType.Equals( typeof( boolean ) ) ) {
                            scriptDelegate = (EditVsqScriptDelegate)Delegate.CreateDelegate( typeof( EditVsqScriptDelegate ), tmi );
                        } else if ( tmi.ReturnType.Equals( typeof( ScriptReturnStatus ) ) ) {
                            scriptDelegate = (EditVsqScriptDelegateWithStatus)Delegate.CreateDelegate( typeof( EditVsqScriptDelegateWithStatus ), tmi );
                        }
                    }
                    tmi = implemented.GetMethod( "Edit", new Type[] { typeof( VsqFileEx ) } );
                    if ( tmi != null && tmi.IsStatic && tmi.IsPublic ) {
                        if ( tmi.ReturnType.Equals( typeof( boolean ) ) ) {
                            scriptDelegate = (EditVsqScriptDelegateEx)Delegate.CreateDelegate( typeof( EditVsqScriptDelegateEx ), tmi );
                        } else if ( tmi.ReturnType.Equals( typeof( ScriptReturnStatus ) ) ) {
                            scriptDelegate = (EditVsqScriptDelegateExWithStatus)Delegate.CreateDelegate( typeof( EditVsqScriptDelegateExWithStatus ), tmi );
                        }
                    }
                    if ( scriptDelegate != null ) {
                        ret.ScriptType = implemented;
                        ret.scriptDelegate = scriptDelegate;
#if JAVA
                        ret.Serializer = new XmlSerializer( implemented, true );
#else
                        ret.Serializer = new XmlStaticMemberSerializerEx( implemented );
#endif
                        ret.getDisplayNameDelegate = getDisplayNameDelegate;

                        if ( !fsys.isFileExists( config_file ) ) {
                            continue;
                        }

                        // 設定ファイルからDeserialize
                        System.IO.FileStream fs = null;
                        boolean delete_when_exit = false;
                        try {
                            fs = new System.IO.FileStream( config_file, System.IO.FileMode.Open, System.IO.FileAccess.Read );
                            ret.Serializer.deserialize( fs );
                        } catch ( Exception ex ) {
                            serr.println( "Utility#loadScript; ex=" + ex );
                            Logger.write( typeof( Utility ) + ".loadScript; ex=" + ex + "\n" );
                            delete_when_exit = true;
                        } finally {
                            if ( fs != null ) {
                                try {
                                    fs.Close();
                                    if ( delete_when_exit ) {
                                        System.IO.File.Delete( config_file );
                                    }
                                } catch ( Exception ex2 ) {
                                    serr.println( "Utility#loadScript; ex2=" + ex2 );
                                    Logger.write( typeof( Utility ) + ".loadScritp; ex=" + ex2 + "\n" );
                                }
                            }
                        }
                    } else {
                        ret.ErrorMessage = _( "'Edit' Method not implemented" );
                    }
                }
            }
            return ret;
#endif
        }
#endif

        private static String _( String id ) {
            return Messaging.getMessage( id );
        }

        /// <summary>
        /// 文字列itemをfontを用いて描画したとき、幅widthピクセルに収まるようにitemを調節したものを返します。
        /// 例えば"1 Voice"→"1 Voi..."ナド。
        /// </summary>
        /// <param name="item"></param>
        /// <param name="font"></param>
        /// <param name="width"></param>
        /// <returns></returns>
        public static String trimString( String item, Font font, int width ) {
            String edited = item;
            int delete_count = PortUtil.getStringLength( item );
            boolean д = true;
            for ( ; д; ) {
                Dimension measured = Util.measureString( edited, font );
                if ( measured.width <= width ) {
                    return edited;
                }
                delete_count -= 1;
                if ( delete_count > 0 ) {
                    edited = str.sub( item, 0, delete_count ) + "...";
                } else {
                    return edited;
                }
            }
            return item;
        }

        /// <summary>
        /// スクリプトが格納されているディレクトリのパスを取得します。
        /// </summary>
        /// <returns></returns>
        public static String getScriptPath() {
            String dir = fsys.combine( PortUtil.getApplicationStartupPath(), "script" );
            if ( !fsys.isDirectoryExists( dir ) ) {
                PortUtil.createDirectory( dir );
            }
            return dir;
        }

        /// <summary>
        /// キャッシュされたアセンブリが保存されているディレクトリのパスを取得します。
        /// </summary>
        /// <returns></returns>
        public static String getCachedAssemblyPath() {
            String dir = fsys.combine( Utility.getApplicationDataPath(), "cachedAssembly" );
            if ( !fsys.isDirectoryExists( dir ) ) {
                PortUtil.createDirectory( dir );
            }
            return dir;
        }

        /// <summary>
        /// パレットツールが格納されているディレクトリのパスを取得します。
        /// </summary>
        /// <returns></returns>
        public static String getToolPath() {
            String dir = fsys.combine( PortUtil.getApplicationStartupPath(), "tool" );
            if ( !fsys.isDirectoryExists( dir ) ) {
                PortUtil.createDirectory( dir );
            }
            return dir;
        }

        /// <summary>
        /// 鍵盤用の音源が保存されているディレクトリへのパスを返します。
        /// </summary>
        /// <returns></returns>
        public static String getKeySoundPath() {
            String data_path = getApplicationDataPath();
            String ret = fsys.combine( data_path, "cache" );
            if ( !fsys.isDirectoryExists( ret ) ) {
                PortUtil.createDirectory( ret );
            }
            return ret;
        }

        public static String getVersion() {
            String suffix = "";
            String rev = "";
            // $Id: AppManager.cs 474 2009-09-23 11:31:07Z kbinani $
            String id = BAssemblyInfo.id;
            String[] spl0 = PortUtil.splitString( id, new String[] { " " }, true );
            if ( spl0.Length >= 3 ) {
                String s = spl0[2];
#if DEBUG
                AppManager.debugWriteLine( "AppManager.get__VERSION; s=" + s );
#endif
                String[] spl = PortUtil.splitString( s, new String[] { " " }, true );
                if ( spl.Length > 0 ) {
                    rev = spl[0];
                }
            }
            if ( str.compare( rev, "" ) ) {
                rev = "?";
            }

            TreeMap<String, Boolean> directives = Config.getDirectives();
            suffix = "\nrev: " + rev + "\n";
            suffix += "\n";
            for( Iterator<String> itr = directives.keySet().iterator(); itr.hasNext(); ){
                String k = itr.next();
                Boolean v = directives.get( k );
                suffix += k + ": " +  (v ? "enabled" : "disabled") + "\n";
            }
#if JAVA
            suffix += "\n";
            suffix += "wine:" + Config.getWineVersion();
#endif
            return BAssemblyInfo.fileVersion + " " + suffix;
        }

#if !JAVA
        public static String getAssemblyConfigurationAttribute() {
            Assembly a = Assembly.GetAssembly( typeof( AppManager ) );
            AssemblyConfigurationAttribute attr = (AssemblyConfigurationAttribute)Attribute.GetCustomAttribute( a, typeof( AssemblyConfigurationAttribute ) );
            return attr.Configuration;
        }
#endif

#if !JAVA
        public static String getAssemblyFileVersion( Type t ) {
            Assembly a = Assembly.GetAssembly( t );
            AssemblyFileVersionAttribute afva = (AssemblyFileVersionAttribute)Attribute.GetCustomAttribute( a, typeof( AssemblyFileVersionAttribute ) );
            return afva.Version;
        }
#endif

#if !JAVA
        public static String getAssemblyNameAndFileVersion( Type t ) {
            Assembly a = Assembly.GetAssembly( t );
            AssemblyFileVersionAttribute afva = (AssemblyFileVersionAttribute)Attribute.GetCustomAttribute( a, typeof( AssemblyFileVersionAttribute ) );
            return a.GetName().Name + " v" + afva.Version;
        }
#endif

    }

#if !JAVA
}
#endif