Skip to main content

Advent of code 2022 day 20 part 1 javascript solution

 class linklist {

    constructor(v) {
        this.value = v;
        this.isFirstNode = false;
        this.next = null;
        this.prev = null;
        this.nextp = null;
        this.prevp = null;
        this.isProcessed = false;
    }
}
function printll(first) {
    let temp = first;
    visit = 1;
    while (first != temp || visit < 2) {
        if (first == temp) {
            visit++;
        }
       // console.log(first.value);
        first = first.next;
    }
    print('-----------------------')
}
function printllp(first) {
    let count = 0;
    let temp = first;
    visit = 1;
    while (first != temp || visit < 2) {
        if (first == temp) {
            visit++;
        }
        count++;
        //console.log(first.value);
        first = first.nextp;
    }
    print('-----------------------')
    return count;
}
function makelinklist(input) {
    let a = input.split('\n');
    let first = null;
    let pointer = null;
    for (let i = 0; i < a.length; i++) {
        let r = new linklist(a[i]);
        if (i == 0) {
            r.isFirstNode = true;

            r.prev = r;
            r.prevp = r;

            r.next = r;
            r.nextp = r;
        }
        else {
            pointer.next = r;
            pointer.nextp = r;

            r.prev = pointer;
            r.prevp = pointer;

            r.next = first;
            r.nextp = first;

            first.prev = r;
            first.prevp = r;

            pointer = pointer.next;
        }
        if (first == null) { first = r; }
        if (pointer == null) { pointer = r; }
    }
    printll(first)
    return first;
}

function calculateResult(input) {
    let real_first = makelinklist(input);
    let first = real_first;
    let temp = first;
    visit = 1;
    let zero_pos = null;
    while (first != temp || visit < 2) {
        if (first == temp) {
            visit++;
        }
        let value = parseInt(first.value);
        if (value > 0) {
            while (value > 0) {
                let f_prev = first.prevp; // 0
                let f_next = first.nextp; // 2

                first.nextp.nextp.prevp = first; // -3 done

                first.nextp = first.nextp.nextp; // 1 done
                first.prevp = f_next; // 1 done

                f_next.prevp = f_prev; //2 done
                f_next.nextp = first; //2 done

                f_prev.nextp = f_next; // 0 done

                value = value - 1;
            }
        }
        else if (value < 0) {
            while (value < 0) {
                let f_prev = first.prevp; // 3
                let f_next = first.nextp; // 0

                first.prevp.prevp.nextp = first; // -3 done

                first.prevp = first.prevp.prevp; // -2 done
                first.nextp = f_prev; // -2 done

                f_prev.nextp = f_next; //3 done
                f_prev.prevp = first; //3 done

                f_next.prevp = f_prev; // 0 done

                value = value + 1;
            }
        }
        else if (value == 0) {
            zero_pos = first;
        }
        first = first.next;
    }
    printllp(real_first);
    let count = printllp(zero_pos)
    let array = [];
    array.push(1000 % count);
    array.push(2000 % count);
    array.push(3000 % count);
    //console.log(array)
    let result = 0;
    array.forEach((value) => {
        let temp = value;
        let zero_temp = zero_pos;
        while (temp > 0) {
            zero_temp = zero_temp.nextp;
            temp--;
        }
        //console.log(zero_temp)
        result = result + parseInt(zero_temp.value);
    })
    console.log(result)

}
function print(a, b) {
    console.log(a, b)
}

let input1 = `1
2
-3
3
-2
0
4`;

let input = `-6287
6707
6969
2869
4724
-4370
587
-1247
7741
4838
6192
2045
5948
-2006
-6210
-8096
-7765
4391
-8005
-5786
-3773
2122
3081
-5430
8527
7219
6974
-637
-1005
3521
8089
9898
2212
-3129
-4205
-9778
-3048
-7358
-981
-3167
-9093
-8453
1604
4036
-1201
-996
8026
-3139
3729
-7911
-9299
-5416
-4008
4564
3496
-8191
75
7499
-5445
8535
-9058
7848
-3293
-7887
1209
-4421
-4968
-5271
-8239
7648
-7478
-6769
1961
-206
-2179
-9216
8078
9530
3628
6536
-9653
-2926
-5383
7691
3850
8408
6047
-6085
1073
-8844
-7500
-6462
8292
-1629
8006
3585
-9147
8830
2249
-6426
7725
-9068
4051
-8453
-3009
200
6474
908
-6162
3828
9932
8883
5897
7366
2064
9130
-154
-6333
7551
8555
1924
583
2414
2976
4749
-3498
5826
6636
-2114
9188
-6220
7811
-5964
1115
3824
-4179
-7432
-9389
-4102
-5207
802
5053
-1147
6241
-8254
-2915
2731
7154
-7628
5586
-9102
5954
1820
2959
2086
7127
1327
8279
7042
-5026
-2039
-4804
2579
-7112
-2701
-9120
-148
955
-2909
-6000
-2934
4462
-8244
7963
-6758
-7299
-6078
-8993
-2845
-2862
-5061
-4097
-7690
9923
1361
-2632
-5927
9692
9846
5508
-7004
-6081
-2586
3266
-5860
9811
8531
-72
4983
3418
-101
-2708
4120
4547
2887
-6877
-8004
-7636
8394
5082
-9213
4346
7881
-8871
4169
6956
-1034
6379
6820
-2434
8582
-7580
8308
-3883
-9167
-1130
-4651
1532
-5214
-7252
-5972
4095
4348
8835
6508
5561
-7186
-2293
4909
6027
-4782
4465
3636
-6436
-3827
-3213
-1758
-9221
-6173
5271
2718
-1620
-944
-6707
9657
-7981
3200
1880
8024
-6994
7519
1548
-3907
5227
2830
3240
4563
6611
-3120
-1104
-5778
-6950
7808
6652
-8608
7179
-898
8073
155
-644
-9569
-977
-2057
2422
8524
2222
5148
1028
2630
-8500
-7724
5648
-7010
-8848
2326
-96
-1299
6891
5376
6070
-1103
5860
612
-836
-1274
-16
-4325
2048
-19
709
-1128
2548
-5759
6617
-2061
-3996
-4325
-6631
346
-309
1177
-6085
-3322
6409
3568
-2488
4172
-9810
512
9321
-3686
-773
8310
7396
-7780
-4761
-7901
2654
-7558
3109
-3279
201
-8653
-5093
8535
-9736
-2075
7775
-9460
7926
1626
9552
7099
4414
-9452
4711
-8654
-6194
7377
-9345
-7256
-82
9977
-6010
2188
-3402
-7004
4182
7513
-8455
-8602
-7486
7806
5140
-6195
-8552
7031
3190
8345
8073
-6855
-6173
1819
-4013
-1690
6838
1728
7306
7655
6570
-1955
-4598
1314
3884
-5276
9545
3723
454
-6382
-8249
7518
-9879
-2020
9824
-7084
4084
906
-9323
-7390
-9757
-1489
2439
-5941
9223
5378
6770
-6744
4364
2582
-9031
620
-2781
7151
745
-1866
-1801
5211
-1945
8848
-5103
-4805
-7390
-4069
-8568
-9879
7869
1397
-854
4016
5594
-5111
2170
-2763
-557
822
-5261
9600
-4773
5105
-8462
7314
5021
-2184
1440
-2524
1388
2745
-7461
1152
-9682
-6744
482
3407
7439
9175
-6035
-4327
-2744
8685
1915
8421
-8795
-9692
-1866
9380
-6445
-6917
4107
-7767
-1012
-1465
2895
-4261
-9810
-9685
8107
-8723
-5938
9587
2997
-7816
700
-2360
-1465
-5948
-6892
-769
7504
-7478
-4434
-2500
-2391
2062
-7534
-4634
-1050
-1262
2331
4346
-2031
-8172
2771
-3391
8623
-3885
3973
-43
-5525
-1445
-8155
9145
1978
-140
7113
-3238
-5592
-7334
-8931
1625
-3774
-5730
7824
-4221
-7624
955
-6363
2024
2722
5211
3294
-2187
-4370
-7739
7394
-9038
-8902
9871
-5326
6195
4043
7859
-7233
-7285
-1585
-4853
-901
-2705
-6773
4389
5143
-4121
-8744
1947
-2391
-7329
-7596
-1845
-8599
-2135
-6721
9913
5637
-8429
-8481
6994
6081
-2523
4672
-7323
7
7375
-7708
5606
9967
-5617
7565
-6968
5351
-9184
-3167
9645
8626
-933
-6363
3684
580
-8922
4519
4406
-3450
-5879
1947
5649
9395
1720
-4055
-9730
7386
8067
4140
-1562
-9018
-8199
-4003
-1015
4857
-364
-4962
-3516
-9264
-4016
5909
-7865
1626
535
8781
-8037
-5598
4828
5895
2853
2771
-2291
-9995
-3143
8535
-843
-4940
1802
5123
2439
-4999
4276
-82
4560
7892
2991
7023
-9750
1788
-3994
-4409
2610
-2763
6885
-910
2683
-6330
3523
2865
-7618
5885
1572
-9760
-3845
8535
-4759
8227
-5683
-3322
-6691
-1543
7911
-6766
-3783
-1359
-6849
6083
6615
1388
-4459
2894
-24
3571
-5344
4526
3496
-5061
-6587
6140
4288
-6871
-6152
-9263
-5836
-7428
-5661
-4248
9437
886
-1815
2828
7742
3697
3844
-1523
-4402
-418
2282
-9931
-1044
-640
-919
-9167
-8759
8261
-8467
-2425
-4598
7001
7081
-7619
-5154
2976
9495
2154
7426
9104
8911
6922
-3980
-4963
1684
4000
7314
-5501
-8382
292
4432
-5893
-1026
-9397
4999
5165
9948
-722
-3267
4646
-3933
3103
-6750
-9571
3345
6143
3505
4177
3580
7767
-4406
-1376
-8608
-6920
-9545
-3261
2786
-2272
9497
6484
8835
6319
1309
-994
5647
-9614
-1360
-2385
-1265
8192
2752
874
-3119
-3320
-9098
3957
-8347
-5657
-4005
-5155
5387
-4245
-8438
-3357
1254
-7969
-3264
-5840
-9713
-8092
3583
2644
-870
-8052
3239
1091
8490
-2348
-5064
9799
70
-9577
-2434
3822
6885
4917
1650
-3844
-8664
-2888
-2057
2081
4140
-418
-9548
3175
-8314
-7136
3215
4519
8623
-7863
-6669
6274
-6233
-903
1700
134
-5674
2911
-1586
8835
2972
7848
9061
1115
1521
8096
-278
-8128
8299
7371
7667
-8338
6869
-5879
-5920
-6195
8692
9346
-7698
1219
-3958
4807
-7839
8683
4621
408
-9386
3459
6724
-5860
-3290
1334
1918
7709
-8967
-2125
-3634
3628
-1911
-4424
7113
-24
-790
-3864
1720
7074
-9036
9881
-5210
7919
-7758
9877
2869
-8687
4576
-5501
-390
8848
-4378
784
-1003
7073
9015
-8184
-6159
-2402
-7316
-909
-373
9210
-5494
-4047
-8759
-8631
9167
-4796
-9023
4453
8903
8405
2957
-3991
957
8354
4988
-397
5321
1065
6525
1119
4575
56
608
-2247
-1262
2036
-6174
4292
7187
-4441
-2257
-8927
8973
4392
-2402
-2870
-2848
2610
2447
3115
313
6900
3212
-2139
370
8248
5527
3149
-8441
3023
-6819
2292
-5591
-1409
4325
521
8635
7378
-8079
-2049
9168
7613
3898
2021
-5705
4264
-2871
-9275
-8142
6685
-3572
8165
7561
-9042
8026
1175
6613
4234
4860
3849
9129
6058
-8518
-8715
-8871
3577
4049
8298
-5365
-5174
5794
-2101
-5749
-6339
-9730
-8145
7669
-8143
717
5037
7565
7073
-3120
5043
375
2561
-722
2365
-434
5179
-4357
9234
-3054
-2964
-907
-1360
-4598
6198
6897
-2439
8835
-4791
1728
1631
-7428
-1532
4479
673
3865
-9602
7055
-2612
-6710
-8438
7081
6254
-7186
-8368
-5016
-1591
7489
-5933
4212
-6640
-3209
2364
5001
-295
-5399
1417
3614
7219
-7226
-9207
8302
5225
-3028
-7402
-3867
-1439
8883
1407
3136
-6617
7235
-488
-4233
8397
-2131
6566
9002
-381
-7142
-3649
-4590
-4205
4750
-2747
8933
4889
7226
7070
-1169
-6962
-9115
4774
-5558
7157
-9900
6552
-2441
9313
-2175
9032
2394
3056
8811
5858
-4140
-3120
1173
-3862
-7593
6693
1496
5841
9160
-4484
1595
8518
3893
-6808
-8375
1714
1703
1518
1408
1878
2819
8901
-4751
2121
3808
4386
-4251
-9857
5792
8918
2651
-4129
-7781
-3009
9208
-4985
9522
994
-9424
-65
-2425
3736
6431
-6472
7609
9287
-5445
-3901
9877
-8158
-2482
-2220
-7175
-6371
7850
7680
-5304
-9778
-6869
-4013
8229
-7637
-4735
8352
-5836
7664
-1940
-340
9042
-3214
2295
3475
-5451
1158
-7844
-3647
3172
9943
5127
-7976
8977
-3008
5723
-1484
-7157
-9902
-901
-3864
-7724
4858
6080
-24
-6394
-3450
-554
7492
5885
2535
1007
6885
-6433
620
-9028
8811
9320
-7116
-792
-5247
3824
5731
-9962
2667
-6500
-714
159
5645
6043
2187
-48
6795
1327
6065
-6391
-1548
-6091
2226
-3601
-7812
-9207
5285
-1100
-7451
8137
-6601
3972
-752
-6064
-8723
6988
3292
511
-1360
-8145
5468
9657
-5518
930
-5569
1626
-3513
5586
-2248
-9764
-3236
6319
-3840
-8254
74
-9708
-3919
-2088
-9555
-2488
2375
-1561
4227
-2909
-512
9958
6014
-6078
4983
-3391
-2567
7343
9625
2874
1196
6187
-4791
-7186
-2008
208
-1109
-8536
-7854
8239
-3926
-3200
-2314
-2592
4510
-5388
-9709
-7275
1238
597
-7726
-7513
9650
9907
4044
7459
1269
3291
5460
-627
4430
2459
5897
9393
-8664
-923
-7426
-7271
4916
-9883
3930
1759
-7513
-8280
1329
-3161
3095
56
-646
-814
-774
-1411
-7762
-8839
6685
5143
5036
-6263
-7063
-6434
4414
8603
9746
3884
-9454
354
6278
745
141
6103
6047
-920
-2050
6367
-5267
8249
-3456
5586
-5304
2757
-136
-3481
1638
-1562
5623
9131
-2727
-4366
1458
-116
-7166
7113
4131
-8462
-6587
2983
-96
3603
8354
3968
-6904
-8195
7551
7096
-2219
-8383
4752
-1558
-911
-3792
4240
9224
8370
-2438
953
7607
-7473
-2052
9719
-5908
-1979
-4589
-9625
321
-6406
291
-1242
-654
-3469
7711
-3236
-5177
4916
8774
126
-6323
858
-8885
6147
-5081
1065
7096
-8833
-8143
-1428
3023
8758
-5605
-9902
-8536
9600
-7226
-3222
8071
-275
-6036
-6631
-2466
7963
884
8391
-8322
4296
2776
-7726
-6333
-8409
-8738
-3372
5285
-1640
-8717
5773
-6773
1402
6341
-8517
-3889
-9476
7849
-4137
-4398
2859
4712
56
-2564
-3345
-3735
8592
-5142
4219
5021
-15
-4689
-7306
-4316
2601
6029
-3115
113
-3109
4262
4713
836
7109
5549
599
7436
-1529
3152
-9239
-5873
-5938
-9146
-3372
6838
9260
2295
-4745
2839
1246
-711
3505
-9081
-8831
1625
1115
4996
5741
-8388
-9839
6499
-6263
-3802
7725
-4010
-2644
7840
-737
8274
-2536
-3401
724
6904
9
-4586
-1688
6995
-4119
-8336
1470
-1817
-1600
41
-3744
5812
-9629
858
-4218
6853
6841
4399
8520
7469
-488
5161
7216
9717
-5873
5510
9032
1825
201
-7112
5546
-8080
-1548
3453
2932
5981
5398
-5606
374
4172
-627
2487
-6901
2754
-7312
1140
-983
7081
-2453
2135
-5617
-664
-9402
-3167
-7797
5653
2832
-996
-948
6681
-8934
3214
-6079
7469
4851
6733
4667
3808
-1429
710
-2131
-6700
3726
-8195
9167
1334
-3822
714
121
-3353
6477
-5271
5728
8978
-1319
4616
4364
3884
-5471
-4462
8614
1829
3618
-3954
-2135
8309
-5304
-7710
3175
-1074
5071
348
1213
3799
2001
-5549
-1651
3098
-9990
5012
-4856
-8536
5447
-8471
-2388
-4580
-7333
4557
5447
-5715
-6944
-679
4330
-3150
6291
5710
9221
-8575
-3411
2097
-4523
-4899
-6166
7735
5317
3519
6001
-266
-9275
2972
3388
2275
4293
7814
-1343
8165
-6824
-5075
9600
-8220
6407
8345
-9808
7201
-3995
-6677
5643
7485
7211
-9960
-8266
5669
4988
4613
-6168
-3115
-8664
6148
2535
9708
3729
1418
3654
7836
4768
-3120
-2059
-3834
4311
9675
7809
-1783
9632
-6771
-4651
-5045
-5786
-3007
4468
-7830
-1963
8026
-9076
7655
880
3767
-4219
2250
-4596
-6877
3865
-6406
5421
2738
-7040
9163
9023
-8859
-2632
-2590
-8282
5143
-4766
75
2501
4291
-2075
7215
9998
6016
1361
4834
-3746
2406
7767
-9432
4280
-2960
-8429
-8305
5723
-1267
321
-8819
-9405
-3277
4536
8557
1434
5895
-6109
-423
6043
508
-8382
-1476
2459
-1896
391
6849
8730
7856
3453
8458
-3033
5427
9095
-5248
3175
-1586
2221
-8381
-597
-7143
105
-1483
-9263
9175
6217
-1435
2918
4211
2932
3340
-8382
8165
-5374
7442
-6141
-3054
1321
-1323
-6897
-8693
3118
4149
-2135
1816
-5786
-6556
-6736
9227
-4437
-9437
-342
-6787
-7243
-8905
1244
-8414
6737
7770
-7063
6744
6905
381
-2593
-2031
4835
-6465
-8812
6664
-3097
-10000
-1783
-4166
883
-6608
5063
1500
712
5485
-7222
-5001
3082
-7636
-1363
1902
-7442
-2777
9777
7927
8412
4120
1517
7031
-3101
-995
-9618
-6162
2985
-5606
5289
-7958
-411
-6603
-9680
3401
-7612
-8848
-2970
9642
-1591
5111
-7036
-440
5680
895
-8382
5227
-5152
98
6819
-3150
7721
6065
-6171
-9971
601
-3062
-4159
2048
6004
-7314
6454
-2963
-8385
-4836
-3353
8424
-3779
-3733
547
-9808
3768
-3167
-9719
-1390
1631
-5858
5672
6387
4131
-5016
4234
-6840
8271
1027
-907
-5430
-1803
-5451
6616
-1998
-7203
-1600
5489
8075
1684
-1773
-1809
3129
3211
8560
-5458
1206
-2351
8370
3521
-1282
8349
-6700
-4366
-5860
8395
-4813
-5409
-1132
7783
-9085
7242
-7273
-3332
4605
-8104
6109
-7308
-1026
-3043
8460
-8617
-8973
3496
-4601
8408
-506
-8654
2111
7305
4199
-1447
1816
-6769
9087
-3345
-772
-5657
-4329
-3967
5705
-7526
-8911
919
-6381
-1682
-6210
-5467
-8161
7765
9871
9917
-4586
7225
-7431
9388
-1026
6849
-266
-102
9293
2002
-7204
-270
-3726
849
-6809
-5194
-2488
6140
-3699
-6375
9416
7802
-3066
8765
8298
-8767
-1096
3693
-232
-4392
1730
6644
8821
-276
7242
-6945
1407
1164
4521
6260
6200
720
-9857
-812
1402
-7062
-306
-5585
-4001
-8375
1890
6027
3286
3330
7339
8837
-8725
4791
8514
-6493
6451
-5256
-876
6526
-3787
3009
-3687
2427
-6363
4311
6408
-557
-5638
9932
7647
-9532
-8881
1503
-3795
-7770
4944
2051
853
-8644
9210
1700
-224
-6821
-3747
9152
-6715
-9865
6946
-8007
-8117
-8103
-3967
-3262
-4847
-2314
7331
-759
-3952
-391
-1017
-6367
2814
-960
2072
9973
-4022
-4424
1947
9559
3373
1372
8982
-8126
-6242
-814
822
-4226
-1652
-9028
-4528
9010
9600
8936
8535
560
7470
-4640
-3016
234
3734
-7306
-3290
7947
-640
771
2296
8897
5260
4712
2985
-5699
7643
-2948
-4751
7226
-6445
-3293
-6822
-7146
-650
-6162
-1612
-3952
8592
6327
4021
-4424
-1118
1209
-1690
6508
8253
-1855
-3956
1915
-1588
7001
1777
-4877
7391
8852
6262
9291
8527
2554
4290
2755
4593
2261
7719
7445
-3928
-5183
3729
-4137
-5585
-4390
4860
5648
2743
-4261
-8316
-302
6017
-6967
6998
5148
-9866
4012
6254
-4846
-5478
-9458
-9911
-7289
-3069
-3510
823
1246
1312
2002
8290
-7832
1737
-1821
2940
4917
6418
9438
1503
3611
-5516
7733
-683
-706
5012
-9578
-7534
6647
-4300
3098
7179
4292
5872
4829
6166
-5364
108
-5040
1684
8073
8460
-2916
-9779
-8880
-6947
-5903
-9569
-3487
3007
-2407
395
377
-8093
3180
3056
-8191
8729
-6286
-4337
-2213
-8038
2458
6923
1091
3693
3265
70
30
-1239
-5908
-1260
-3745
6693
-2590
1604
-9208
2949
6988
-2139
-5620
-5925
8550
-4769
299
-5114
9062
-1091
9254
-737
8231
-964
-506
6273
6434
-266
-7647
9104
-1712
-5638
-9226
2100
8830
-9434
9679
5857
9586
8036
2258
9816
-5264
7775
-1004
9104
-5188
-4916
5083
8971
244
-9643
-8266
6737
7383
-5040
-8070
-6009
8824
1595
-10000
-7724
-4216
-5998
-1373
-5495
-6189
-2434
5076
-3977
-3621
-2801
348
-9234
3452
-5217
6291
-4827
-6078
-1231
4895
-4595
3547
1451
-4194
3259
-9263
8781
-310
6685
6294
3060
3656
-5234
6652
6664
9684
-9423
4834
-8834
3218
588
4996
5143
-459
-2360
8970
-3409
5263
-9761
3598
-3773
-442
-2644
5527
-1007
6225
2456
-7451
8345
3961
-7186
8387
6973
-5182
7752
-7842
-3679
1921
4386
6225
-2087
-5671
7241
4141
2776
9668
-1803
6648
-4434
1938
-9917
6576
-8429
209
-7665
129
-1275
-5122
-1297
6650
9877
6273
7379
760
-8441
2473
-835
4209
-7029
3160
-3353
-2865
-2922
5898
-5439
5867
-9496
5525
-3494
4743
-5616
-2195
7618
7352
-9218
5610
5594
836
-5061
9575
9039
-2247
-4503
9205
2234
2392
9460
9103
-7362
9273
2705
-1362
2940
7764
6636
4750
-3559
-1669
-1274
-581
-300
-9088
13
-2062
9366
-7898
6079
4996
-4831
933
-1552
214
-1750
1826
-7113
5498
-1892
3752
4264
-1796
-891
-7082
8901
3145
-823
6014
-557
-4588
-8662
8768
5587
8871
2425
-9257
-7664
-9303
1050
-7989
-3009
6319
-6363
-3954
-6588
7742
-7173
-9495
2579
-8843
3350
-1188
2250
7469
8703
-2705
3595
-3991
3190
6938
-5489
-9761
6225
9063
4529
-3673
-8543
-9377
-6331
-7377
-4965
5163
-2346
5929
6287
3277
4761
-3316
-2580
615
3711
698
4280
-8750
3521
-9518
2264
9798
-4046
583
-5247
-868
3257
2206
-7427
-1629
7390
-2985
8380
-3265
-9516
-9746
-1067
1511
-8646
-7455
9640
-2534
292
-7267
-6696
3278
299
-2946
2159
-9184
-8646
2459
3214
2722
-901
3499
5387
6656
-4294
5219
-3234
8213
2866
2940
-8766
7113
9163
-8175
-8508
224
2808
-2108
6969
-5836
-2248
3634
-706
2394
3893
-8570
-4308
-6611
-7409
-5558
7157
-2526
-4135
-8292
-6186
5338
-9386
-6460
-556
1108
-1100
4846
-5914
-7494
6145
1313
-3918
6273
-7862
8318
-437
4956
-6629
7660
-8467
4511
6304
-2989
4989
-4007
-1176
4341
-5920
4258
5291
-2060
-8180
-4962
1917
-1416
-7314
-6073
-8626
4848
-5815
-4657
2578
1199
-3834
6359
51
8309
-104
7769
-2410
9832
9825
-2936
4476
9800
-755
2065
8668
-909
-4978
-7708
-8093
7087
-8826
-3552
4145
2766
-2922
-3656
-4742
9350
-3810
-8018
-9080
-4723
8324
-1262
-292
-582
-2883
-3411
1079
-4158
-7768
-1065
-4308
7435
-1246
4000
-5047
-9962
3098
1093
2541
-1505
-5189
-8758
6928
-3996
-3466
9933
5270
2878
7179
-9475
-669
-6721
5219
-5719
2094
-9577
-2865
-9731
9315
-1234
2771
1481
-3511
6847
-5209
6613
7119
5164
-5990
4234
8443
7331
974
-9103
-6081
-6691
1872
-9429
9881
7842
-7338
4021
7366
2459
-6750
-4474
-3248
-2994
-8981
-5591
-4666
7089
6420
-8449
-1363
3728
886
9709
-8074
3350
3452
4931
-9093
582
-4390
-7231
4876
-976
9649
2306
-3801
234
5046
-6286
-3237
-219
4739
731
8706
5424
5510
-5496
-7279
2187
6037
3990
507
-5348
-9199
8494
-4573
2951
4327
-7438
-3740
4529
-1541
-5441
6518
602
4791
5080
-4957
-3109
9353
930
7086
2722
2202
-9819
9340
160
1612
1832
-7366
-7644
6969
1521
9938
-1026
-7768
-4872
7200
-2004
-5695
-9625
-7820
1277
6232
2851
1618
-3628
9247
-8201
-2304
-6956
-8876
-5221
-2135
7019
3968
-9992
-4622
3431
2972
300
-4439
-1243
2191
-616
791
6905
2538
9932
-4205
4890
6855
7650
-9936
5088
-4547
5068
-4299
-8078
8666
7934
-2180
5318
-9546
8882
7943
3125
9951
8460
-6707
-8629
8193
9115
340
-4612
2971
788
-860
-2534
2713
2921
773
299
5285
-8631
5237
-6622
-8611
4508
9932
-1712
1665
-7299
8795
6940
6923
1272
-725
-9827
6265
535
670
-3088
-195
5719
-3476
8116
-3563
-68
-7520
2545
-6297
-9694
-8905
8584
1076
-1934
5440
-3104
8216
-4459
-12
8856
-6173
-9849
4350
6472
-8346
-1299
4004
7415
5931
-2888
225
6226
4505
-7271
9551
-9224
-2681
187
4848
5737
8037
-5924
-8586
7949
-8490
-973
-2163
-2424
3632
5527
-9992
-2049
8803
4414
-3137
7990
3942
-5026
407
371
-7297
-6050
-4163
-1254
-1712
-2071
-8659
-5264
5793
5108
-7997
1434
4359
-5194
6569
8702
-5482
-4470
-3892
-6162
1812
-2461
-6923
-5884
-2943
-5507
-8440
-3003
-5234
3855
6013
-2165
-6009
-3776
6778
-3097
-6290
-9093
9531
7226
4219
3568
6445
4057
-2747
-1169
878
-7292
3628
745
-814
-6840
5645
-1752
8231
-5683
-5479
-9578
-1712
-7271
-5016
2887
-3848
-2008
-3753
-3419
8354
-9878
6884
-1314
3851
404
-4921
-2729
2121
-1026
-3866
7561
4266
9488
6097
3595
5637
-9154
2974
-7746
5652
9908
9151
-6034
405
-2536
-1682
-1387
-2994
-6366
3943
-1813
-3146
-7781
-7338
-2860
5949
0
-5535
1906
-5738
-104
-6587
718
4761
-6162
-4963
-8352
8766
-6690
-6051
8110
-7935
2448
-5159
-4319
9759
6833
-8481
-2576
3213
-2524
-344
8282
9649
-8018
8442
-4437
-9472
-992
-8612
2949
7316
-3438
3211
2859
4116
3711
7725
2581
4201
-654
3551
1684
-9412
-2946
-3413
6264
-2031
-2402
6554
-9408
2365
-7351
-9800
8279
-231
1595
6485
5297
-5405
332
-1453
-16
-4487
2875
7558
-6598
3847
5724
-3372
2601
-1132
-6393
1541
-99
-3871
-9967
-5178
4829
183
820
7085
-1604
-8907
-4424
-7546
-2961
6648
-7773
-5374
-9239
-3345
-6587
8669
2396
1096
-2048
-9085
-9833
-8918
-3924
4837
-411
-9555
7019
5546
-6083
-2331
-8956
8498
-1793
9308
9709
-3563
-4071
-4601
-1792
-4446
117
1198
4264
-679
9727
-1495
636
4160
3590
-1988
-8491
99
5902
-9902
-7725
6473
2802
-2661
482
-4491
8873
-2075
-7566
-3755
-2922
-928
-8424
-7533
-6081
6898
8766
-4962
6898
-4056
-8167
-8409
-3901
-2380
8645
7528
8052
1517
2235
6198
3953
2754
-4001
5969
-3604
6616
4331
-9748
-1606
-7421
1942
421
6923
704
-8980
6604
-8853
3529
6648
5546
-1704
-8544
-1548
3380
-2765
9440
6294
213
5969
6097
7284
1239
5976
-1025
4738
3529
3973
-435
-9857
6780
-5470
1991
6740
-3707
3920
-7550
7366
-2154
-6727
-728
2191
-6736
4554
-6820
5280
7099
-390
-5436
5587
8176
4501
371
8830
-3146
6445
-6758
5652
1887
2819
-1170
-9520
1049
-7911
5863
3020
4430
-9221
7354
6421
4748
8524
-4789
-7274
67
3382
2212
-3461
-5264
840
7513
-6917
-3240
-394
-7049
3087
5727
8015
-231
-6715
-9374
1447
-9372
-5059
6451
7012
-49
-7024
8000
2410
-2084
-3628
-250
8568
5167
7345
2178
9281
-3731
9049
-1963
2317
5423
-6917
-2845
6928
3382
5111
6043
-737
-1956
-5647
6347
8833
2232
4558
-7049
2191
8496
7857
5912
-2031
-9084
8052
9525
2137
-3487
2111
-3391
-104
-83
9264
-205
-1585
8683
-4343
-7192
6676
-5152
2725
1407
-4590
7561
-3120
-3994
-8006
-2067
8099
-9840
159
-1648
-4046
583
-2380
2469
8035
-8017
7869
-1626
-6852
-1562
-1752
-7421
2929
7117
2665
-2247
3153
-5932
-2922
-2661
-3923
-4436
-4590
8024
-1897
-266
-7710
8395
2626
-3618
7384
-7004
2094
8901
-4161
5858
-8383
-5108
-7347
6205
-4454
2121
9903
3152
-1640
-7306
4135
5527
-3048
-5451
6225
4583
3611
-9600
7033
-7600
-2715
160
-3192
7487
-8239
-7268
-6746
-8714
9291
3842
-3555
-3201
-8460
4582
-9142
-642
4049
7370
8309
-2449
-3561
-2801
898
-6917
3358
2917
9601
-7184
-654
3550
-8153
197
6956
-1852
-6624
7770
-5620
1749
-8816
-9093
4858
5841
8863
9933
-371
-5223
1198
1302
-8484
-1172
-8320
-2272
4476
647
-7136
194
5719
7193
5460
2511
-7906
-3119
37
6319
9650
-4242
1637
4408
8428
9340
3448
-3855
-8585
7487
-958
-8523
-2780
9698
-2500
2972
5807
-3366
-4923
-1582
-5633
-7896
4563
9329
-7835
4804
8983
1662
-1001
704
-5227
-6085
-4421
9759
-8871
2232
-9093
4428
8412
-4470
-3761
-8336
1431
4616
-7067
-9625
2884
8326
8527
3870
7281
-1015
9891
-465
4501
6200
9369
2343
-1824
8614
4835
2878
6296
4833
6934
1750
1196
-2951
-6824
188
-1380
320
-3801
-5671
6299
-7308
-4298
-1841
2394
1856
-394
-1561
7199
-5988
-8956
-2785
-5495
-7940
-2905
-3911
2921
-8651
-7010
-1109
-5250
-2486
-4832
9644
-6180
-4087
6081
-9856
963
-8347
3729
-3639
3870
-9333
-3722
6648
4927
-4758
6119
-1816
-2360
4983
-6034
-7052
9188
-4920
58
4367
-9008
-2125
9340
3452
-8312
4923
-2075
2052
9388
8395
-5006
-9808
4658
1328
8324
5219
-1537
6922
-4441
346
-6347
-3139
9376
3519
4711
-5993
-4007
-9038
-1018
-5222
-7978
4512
3434
7618
9535
-1443
3639
1988
-5567
1201
-2766
-7122
7468
-7062
-8459
7086
-2576
5640
-1075
5211
-3152
-9730
-952
-2625
8274
-4996
-1088
-3801
1470
-6041
9112
7024
9320
-5271
-8089
-722
7
1246
-6034
1256
3227
-3399
4748
7125
6304
5904
8582
8233
4710
9096
5495
-6417
-1682
-4424
5682
6605
-6445
-976
8623
5243
6296
1793
4352
-1805
-2253
-8185
5256
3599
8592
-9331
-2464
8506
-5570
-5178
8830
7400
-9093
7314
5541
-6878
-3498
-1307
4544
9706
1837
8952
-8642
-1490
4848
-276
-6597
-3991
694
3152
-4731
4555
2002
1523
7216
3608
5195
4323
-2075
681
-7329
-3794
-7177
-6419
9385
-6750
1724
-720
-9724
990
-1767
7739
1486
-9629
-1582
-9067
4889
1327
57
766
-7338
3492
7514
-1646
6617
1172
8505
7073
-7890
-6344
-1852
999
3710
1221
1879
2058
8254
-6520
8265
7512
5824
-3545
2512
-4566
197
-4101
-4622
6923
-6293
1934
-425
-9330
-8481
9480
9346
2088
3879
-9680
-7950
4318
1201
-6070
281
-8195
-8927
5053
2020
2722
9471
-4300
7693
5857
5768
-5781
-2926
-9713
4896
6345
8792
6074
1637
7721
-214
-8773
3009
-3072
4186
-7102
-7173
-5214
3257
-3758
1584
6518
8270
5249
2914
-7314
2983
-5655
5957
-4158
-9115
6899
4199
-9593
-1690
273
-5187
-5486
-4994
-2763
520
-5168
-3840
-7940
-6506
-3372
-6058
359
5544
5898
7039
-5234
-813
4711
-8999
-7397
6947
-1144
900
4583
4889
6475
6175
-6391
-9692
2014
-1866
4999
-1517
8137
-9839
-3151
-8089
-3832
-5772
-1852
-5320
-1712
3572
8911
-5142
3046
1537
-9495
2478
-2205
-8032
-3263
-3672
3673
4330
-8049
-4007
-6809
-280
8137
5043
5603
-6682
-1047
-9108
-9961
1244
-7576
8592
-3794
-5683
-6101
5745
-3801
-5111
-1074
3348
-3370
-2576
435
1691
7896
8624
8883
-5772
8918
7136
-1026
2957
3755
4710
-5183
4565
1601
4212
-5779
300
2154
3497
-597
6592
5804
-1614
-9711
-128
3819
1269
7273
-7358
-7279
-2536
5269
-4071
-5621
-5048
1985
-4436
3822
9950
5515
605
1502
3180
7338
6550
-2064
-6948
5670
-903
2354
6533
1947
-7289
-8049
2094
-2558
3095
1104
1011
-8594
3729
-5840
-59
-3226
9350
-1750
-2763
5139
5243
7235
-5040
395
1955
2984
2699
8771
-629
-4417
-2488
1845
9196
1864
-9129
5063
4576
-9619
9552
8741
6420
-3630
244
-8946
1863
-4951
7468
1313
9642
190
3923
-231
-8483
-3213
5894
-5932
1215
1224
-557
-7868
4349
3214
1670
-8634
150
-2786
-9410
8280
4121
5737
8626
-719
-2937
4754
-7672
-8831
1141
-998
5338
-2716
-3555
-178
6100
5460
2914
1234
5501
3327
-5772
-3864
8349
-8728
-9266
-8355
-5304
-2801
-9692
4795
4361
5371
-7901
-1195
-9068
-5749
5833
-4007
7917
1049
7858
326
1669
5167
-7002
8918
-4269
-8664
7806
-9352
-6085
-7108
4953
-5274
-4577
9232
-8227
-7781
3602
-5168
6897
2232
-9428
-6168
-6465
-5571
8767
-9298
7270
-5361
1666
3497
9530
4321
-6143
-8609
9574
-7881
5870
1128
-2686
1666
8520
-8380
-2409
4542
8648
-8978
-5471
-9021
9481
3978
-3608
-257
-1561
3037
8592
-8872
-6266
5620
-3394
3884
6097
7226
-8364
3305
9350
9234
7918
-6472
-5540
-6622
6885
3312
6193
5327
9563
6197
8061
-1340
-1591
-9377
5202
3729
-5154
-2015
-9931
4160
4824
1206
2408
7911
8878
6693
601
-3028
5440
-154
1303
-49
2484
5213
1595
9922
6737
-1994
-6256
-7296
-5320
5021
7
-6872
1533
9915
-9818
8219
6725
-9629
321
-8441
2576
-8560
8811
4428
1881
-7527
3350
8730
2002
-5430
886
-101
-140
2425
-1440
3440
-5241
4175
275
488
-4059
-1660
3257
4364
4336
-8343
8298
-8797
-8956
5727
7391
-2972
818
9595
1485
-2371
-7684
-8444
-2516
-3009
7490
3346
-8064
6884
-4860
4699
3942
-6587
4389
3389
-1061
-167
6418
-9304
2164
5388
7637
7282
-7357
-1046
-681
7984
-5551
7721
9940
-6242
-9095
-3323
-3747
4762
1028
-7593
-6533
6070
-9006
-602
-9986
5526
9643
6911
4395
-1340
-1684
-2937
-9761
4705
7354
-8544
7099
-7006
1436
-4800
2750
4950
-104
647
8099
-2208
-228
6100
-84
2719
-146
-4434
3893
792
6279
-4051
4199
4557
-6044
-5174
6217
6934
-8314
-5006
-6891
7655
-9129
-9116
6391
-7939
7802
7775
6880
9074
-5031
4667
8261
-5830
3365
-798
2511
-210
7655
-8438
3943
-8738
1481
-7768
3533
7493
6291
6309
-4046
9647
9338
3186
8086
9131
98
-156
7159
6918
5643
-7206
-667
7480
6187
-6086
-6173
-3374
-8580
-6288
5236
3345
4004
-5705
1837
5289
4761
-5534
-4559
-3002
-2792
2448
-5754
4750
-2801
6552
-5274
-7672
3246
849
-6433
2683
-8517
-2786
-1529
-4549
-1588
-7356
7733
-5470
-6743
6880
5260
7997
7564
-5214
-3826
3120
-3811
1390
-5451
-6426
-8517
-8104
8857
-3169
560
7585
-8955
617
3768
6409
-8511
1132
-5938
-4241
-9629
-1783
353
-4964
4932
-2107
9586
-1982
1587
-5549
-3624
-1729
2911
-4268
-3464
-3213
4749
-6533
-3954
8006
4485
7167
5693
8876
-5250
2290
531
1135
-2016
6449
-7358
8897
-5214
784
-4237
-2543
5796
-3833
-7315
-7531
5060
2475
-2534
8741
9739
-4224
105
-5730
-9095
-324
-9591
8182
-7861
-8481
7909
4834
-9378
-4045
-4288
2827
-4316
-1818
1829
-5595
9592
-3334
3098
7721
-8619
2874
7019
1985
-5364
-9221
-724
5804
-4819
-5898
-9432
-7596
2239
2187
-5750
5727
-7906
-1401
-38
-3656
8318
-91
-4751
-8094
-9305
2713
6200
-3630
-8366
6445
-5972
8087
-9768
-8819
3401
7365
-6650
-7340
5848
-8243
4508
-5621
5990
5990
-6830
-7841
-7345
6309
-2536
2953
-1100
6902
-8215
-6174
9037
-1806
5794
-8355
-4985
802
3658
3103
-9374
9907
-3669
1327
-6279
-2547
7515
-98
8837
1638
-1792
2704
7316
-5836
-329
8721
-6922
-8960
-5712
8521
4738
81
-8729
6529
4846
-6393
-7637
27
-6533
-2057
-2183
121
7979
3164
-8969
-2079
671
2168
-9184
-5374
-370
-3618
6347
8410
7651
8683
-4553
-3589
6009
-5475
5172
9188
-7442
8781
-6742
-459
1289
-3319
8707
-4999
-2131
5848
-8825
9662
52
-8171
3037
5086
3366
-6034
7092
6676
-642
4458
-4553
1768
6940
-5361
51
9881
2475
3836
-6195
2879
3000
5608
-6790
2011
-7859
-4424
4359
8621
5700
2554
703
-1104
-8215
-6472
-9433
7070
-1253
-7633
1723
-7094
-5266
4781
-8940
3175
3950
-9779
4414
-883
-8176
-4288
3123
1142
1111
8421
9811
-5067
-6950
840
1740
1139
7911
6225
6612
8766
9563
3433
-1167
-8885
-6101
-2539
-7354
-1871
-948
-3357
-4921
-280
-5477
8000
9274
-5486
7916
-4618
2306
-4055
-1991
-8096
7444
1209
-3457
-4912
3098
7023
-8118
-8467
-7370
-5401
-1611
-3868
-1450
-2048
-9787
-8256
4961
5424
-4457
4716
7136
-8790
-5361
3330
1666
6744
1196
7997
768
-9049
7919
8041
-5924
1988
-9787
4288
6640
-9643
560
-6259
-2827
-6044
863
-9468
-278
-3030
8694
7570
3884
-918
4526
-247
-1911
-2746
9668
-5103
7127
-2593
9965
-7910
4040
305
-3241
4330
-8550
-7780
-9992
2972
-3120
-9049
1190
-8236
8565
-9476
6143
-3450
8159
2743
-8265
-4113
1718
5822
98
5411
-1332
3583
6345
-6821
-6736
-5804
-3773
2787
-2654
5954
7741
-7351
-7433
7314
-3487
472
5874
7647
-5121
-5607
-1712
8697
9862
-7020
-9236
6572
-5229
6891
3081
-9589
-8185
-3399
-5478
-8037
-8038
9440
-9058
6037
-2809
620
-685
4599
1519
4414
4227
1535
-3230
9436
-2135
-4398
7493
3990
9037
3496
-9593
8575
6984
6889
90
-1757
-2377
-996
6872
-8196
-5959
8692
6618
-4417
-1761
-9973
9975
10000
8782
-1704
-5598
-6968
4375
-1104
-4978
5216
-9961
9625
2239
3091
2601
1207
9041
4789
4713
9587
-5728
-826
4578
2304
3326
6745
2592
2458
3793
8527
-2941
-9220
-9023
-3185
-1756
1788
-833
1502
-1280
6379
995
4004
-9797
-5952
-180
454
8179
-912
1104
-2813
4035
6043
-6682
4348
-9503
-9545
7916
-9292
-7351
-5995
-1537
1662
1703
9668
9131
-5085
-9692
-7787
-8455
2181
-9102
8352
6854
4526
-4365
-9263
9339`;

console.log(calculateResult(input));

Comments

Popular posts from this blog

Export Doc,Access,Image,CSV,Excel,Pdf,XML,HTML,Text,Print of Gridview in Asp.net

First import itextsharp.dll in the solution and use three namespces (basically for pdf) using iTextSharp.text; using iTextSharp.text.pdf; using iTextSharp.text.html.simpleparser;          Then Use the following code :- on each button  click  protected void Page_Load(object sender, EventArgs e)         {             if (!Page.IsPostBack)             {                 BindGridDetails(GridView1);             }         }                 protected DataTable BindGridDetails(GridView GridView1)         {             DataTable dt = new DataTable();             dt.Columns.Add("Student_ID", typeof(Int32));             dt.Columns.Add("Student_Name", typeof(string));             dt.Columns.Add("Education", typeof(string));             dt.Columns.Add("City", typeof(string));             DataRow dtrow = dt.NewRow();             dtrow["Student_ID"] = 1;             dtrow["Student_Name"] = "Musakkhir";   

Ip Sec Internet Security Basic Structure

The IPsec suite is an  open standard . IPsec uses the following  protocols  to perform various functions: Authentication Headers (AH)  provide connectionless  integrity  and data origin  authentication  for IP  datagrams  and provides protection against  replay attacks . Encapsulating Security Payloads (ESP)  provide  confidentiality , data-origin  authentication , connectionless  integrity , an anti-replay service (a form of partial sequence integrity), and limited traffic-flow confidentiality. Security Associations (SA)  provide the bundle of algorithms and data that provide the parameters necessary to AH and/or ESP operations. The  Internet Security Association and Key Management Protocol  (ISAKMP) provides a framework for authentication and key exchange, with actual authenticated keying material provided either by manual configuration with pre-shared keys,  Internet Key Exchange  (IKE and IKEv2),  Kerberized Internet Negotiation of Keys  (KINK), or IPSECKEY  DNS records .

Advent of code 2022 day 22 part 1

  function main(input, input1) {     let grid = input.split( '\n' );     grid.shift();     // only in big input     for ( let i = 0 ; i < 100 ; i++) {         grid[i] = '                                                  ' + grid[i];     }     //console.log(grid[100])     grid = grid.map(x => x.split( '' ))     // find first left top allowed     let temppos = - 1 ;     grid[ 0 ].forEach((element, i) => {         if (temppos == - 1 && element == '.' ) {             temppos = i;         }     });     let initpos = new pos(temppos, 0 )     // console.log(initpos)     // make grid equal shape     let maxlength = 0 ;     grid.forEach(el => {         if (el.length > maxlength) {             maxlength = el.length         }     })     console.log(maxlength)     grid.forEach(el => {         if (el.length < maxlength) {             let diff = maxlength - el.length;             while (diff > 0 ) {                 di