source
stringclasses 4
values | task_type
stringclasses 1
value | in_source_id
stringlengths 0
138
| problem
stringlengths 219
13.2k
| gold_standard_solution
stringlengths 0
413k
| problem_id
stringlengths 5
10
| metadata
dict | verification_info
dict |
---|---|---|---|---|---|---|---|
taco | verifiable_code | Solve the following coding problem using the programming language python:
Shil got an array of N integers as a present on his birthday. But he didn't liked it. Shil wants to make this array beautiful. Shil considers an array A1,A2,A3 . . . AN beautiful if A1 > AN. Inorder to make it beautiful Shil can swap any two numbers in the array. Also Shil can perform this operation any number of times on any adjacent pairs of integers in the array A.Find the number of ways in which Shil can make this array beautiful.Two ways are considered same if resulting array after making all the swaps have same A1 and AN.
Input
First line of input contains an integer N denoting the number of elements in an array A. Next line of input contains N space separated integers denoting A1,A2,A3 . . . AN respectively.
Output
Number of ways in which you can make given array beautiful.
Constraints
1 β€ N β€ 10^6
1 β€ Ai β€ 10^6
Warning
Prefer to use fast I/O methods.
SAMPLE INPUT
5
1 4 3 2 5
SAMPLE OUTPUT
10
Explanation
Total number of ways are (5,1),(4,1),(3,1),(2,1),(5,2),(4,2),(3,2),(5,3),(4,3),(5,4).
First number in above pair is A[1] and second number is A[N].Note that two ways are considered same if A[1] and A[N] are same in resulting array after swaps.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n = int(eval(input()))
se = set()
li = list(map(int,input().split()))
for i in range(n):
se.add(li[i])
n = len(se)
print((n*(n-1)/2))
``` | vfc_135194 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10000\n9384 887 2778 6916 7794 8336 5387 493 6650 1422 2363 28 8691 60 7764 3927 541 3427 9173 5737 5212 5369 2568 6430 5783 1531 2863 5124 4068 3136 3930 9803 4023 3059 3070 8168 1394 8457 5012 8043 6230 7374 4422 4920 3785 8538 5199 4325 8316 4371 6414 3527 6092 8981 9957 1874 6863 9171 6997 7282 2306 926 7085 6328 337 6506 847 1730 1314 5858 6125 3896 9583 546 8815 3368 5435 365 4044 3751 1088 6809 7277 7179 5789 3585 5404 2652 2755 2400 9933 5061 9677 3369 7740 13 6227 8587 8095 7540 796 571 1435 379 7468 6602 98 2903 3318 493 6653 757 7302 281 4287 9442 3866 9690 8445 6620 8441 4730 8032 8118 8098 5772 4482 676 710 8928 4568 7857 9498 2354 4587 6966 5307 4684 6220 8625 1529 2872 5733 8830 9504 20 8271 3369 9709 6716 6341 8150 7797 724 2619 2246 2847 3452 2922 3556 2380 7489 7765 8229 9842 2351 5194 1501 7035 7765 125 4915 6988 5857 3744 6492 2228 8366 9860 1937 1433 2552 6438 9229 3276 5408 1475 6122 8859 4396 6030 1238 8236 3794 5819 4429 6144 1012 5929 9530 8777 2405 4444 5764 4614 4539 8607 6841 2905 4819 5129 689 7370 7918 9918 6997 3325 7744 9471 2184 8491 5500 9773 6726 5645 5591 7506 8140 2955 9787 7670 8083 8543 8465 198 9508 9356 8805 6349 8612 3623 7829 9300 7344 5747 5569 4341 5423 3312 3811 7606 1802 5662 3731 4879 1306 9321 8737 9445 8627 8523 3466 6709 3417 8283 3259 2925 7638 2063 5625 2601 2037 3453 1900 9380 5551 7469 72 974 7132 3882 4931 8934 5895 8661 164 7200 7982 8900 2997 2960 3774 2814 9669 7191 1096 2927 6467 5085 1341 2091 7685 3377 5543 5937 9108 7446 9757 9180 8419 6888 9413 3349 2173 1660 2010 2337 5211 6343 7588 8207 9302 7714 7373 5322 1256 4820 4600 7722 9905 5940 9812 3941 5668 1706 6229 1128 9151 5985 6659 3921 9225 2423 7270 1397 4082 5631 85 9293 1973 7673 3851 7626 5386 1223 9300 6641 6043 3899 714 2299 6191 525 2591 8210 8582 8820 9337 7733 1156 5995 8005 380 4770 5274 1777 8851 7256 1861 8143 5580 5885 1994 3206 7622 9568 2505 614 1962 2755 1327 4260 8945 8203 3203 3507 6785 2022 2843 869 9529 5190 8873 9909 9959 499 8037 8809 7754 6249 3304 3334 2134 1649 2891 9755 7568 1747 369 9530 4501 8047 3789 9798 6250 6991 3304 3034 5364 2498 254 4893 7687 9126 1153 3997 5976 9189 9158 3730 5437 2461 3415 3922 461 6305 29 8028 8051 6749 7557 8903 4795 7698 8700 1044 1040 2003 429 6404 4501 682 7648 8539 6160 5152 2536 2135 4340 1693 2216 6128 505 5630 50 965 8286 6430 5344 6336 3178 2901 5239 7972 6950 290 5368 7989 2293 5796 744 3145 2830 8391 1683 5341 3542 570 3827 4233 2262 6043 361 9118 8024 6762 82 6310 3191 5426 8997 6368 4678 4235 691 1627 4525 6058 9615 3169 8206 359 6313 7387 5101 4347 2727 4995 4917 6553 5579 3530 8947 2291 2648 6971 9052 9081 9632 8594 858 8628 1313 1887 9215 8356 3513 91 4413 9480 9611 8970 6190 2275 6356 7642 6621 5434 8988 7889 8339 4567 7771 7285 6857 418 607 2261 5850 238 7206 3060 5218 8519 4946 784 6874 8459 874 7638 4290 484 6608 479 2758 9315 4472 5730 1101 3460 3619 9439 8026 1389 3075 1234 8158 3682 3494 359 271 700 3418 1840 5570 8364 2623 8795 3174 9848 6432 7463 6683 9391 4293 5792 5058 5116 1522 6158 8575 1492 1948 2952 9232 5022 538 3741 5055 4031 4099 5326 1082 7517 3517 3003 2232 6140 1797 5405 2339 4581 9219 9022 3971 9863 4813 5380 4978 2686 1537 9905 4177 3484 9208 9760 4858 9745 3500 9912 128 3951 5237 7561 7819 5106 564 50 1245 8712 1806 9935 3292 7376 8956 3615 3590 3769 8994 4919 2806 6883 4823 6983 6718 4031 3094 1575 127 6594 1487 254 544 3075 7815 4714 8180 8378 4763 5776 7089 2920 5711 6733 295 1018 347 236 1138 5692 5154 3944 2574 6329 926 9292 6711 4019 7218 6837 6964 5056 7091 3859 8131 4905 8572 2662 9634 9686 4790 3074 2605 6852 9806 9251 7869 6504 9486 9007 2196 4640 2950 1121 968 227 6764 7678 597 3982 866 7561 9037 7956 7771 3519 9212 6343 2533 5197 2380 7322 8271 4985 4173 4428 4235 2041 7284 73 7399 5831 1064 348 6951 2031 574 3715 6060 7523 4048 6925 5083 9436 1233 9205 2955 444 1899 5487 5641 4279 9160 263 9263 9684 1042 9849 1724 8325 6273 9123 4155 7336 5822 7458 9366 2748 1172 1777 270 5219 8702 1704 4654 9934 908 3960 6729 2807 5798 8721 7085 1309 5335 2699 992 6377 8899 2716 1053 5172 8190 1560 2507 4011 9017 8225 3110 6540 1 3379 8110 5054 5082 9115 1339 5990 9427 8068 5148 5224 6788 2232 6533 2123 1282 3876 4851 180 6591 2255 5351 1132 3814 7858 1495 9182 6082 4604 5721 2434 7983 182 7488 9416 9297 8826 5405 8723 6893 552 298 33 9135 3182 8507 416 7058 9709 596 10000 1963 2298 7484 5777 155 8978 1310 2588 9933 3383 5022 4267 3564 8861 3683 9212 7686 9087 4286 931 5991 4584 7315 1477 4117 5821 1893 7526 5529 8840 7526 7491 1137 1361 9619 7644 338 929 6583 6622 4311 7956 889 4226 6816 4571 3438 854 9 7723 1784 2351 8658 9098 3828 9127 1270 2072 6652 3150 911 529 640 8399 1889 6611 2394 8578 3891 8977 5200 4553 6932 6088 8778 100 658 8567 953 7018 2642 2736 9369 1299 8185 3196 6777 5806 5267 3429 8955 2529 309 9594 7279 2198 2556 9673 775 6446 5001 2326 998 8284 8413 6128 8383 5422 4694 9335 2440 7335 8422 8160 4986 2958 1355 1762 8763 2973 1542 7717 1853 1851 3663 5483 400 6218 5155 1174 9016 6507 9852 6365 4791 8264 2492 3173 38 3538 8860 8829 872 7281 6988 5857 6591 8342 3971 5353 7666 5512 3070 9518 7362 3084 1352 4113 9301 6507 1639 4668 9365 1490 1033 4155 6105 9876 3680 6142 3413 2539 4970 637 6171 1957 2845 2761 6650 6815 4466 4315 2327 3887 184 6040 6970 1536 153 2622 4394 1791 7290 110 9632 4674 4265 5736 4549 4296 1878 4314 6834 3199 4950 9356 5156 7794 8469 8157 961 2934 8824 3287 3172 5359 5678 141 3246 2182 2762 3991 324 51 4101 9955 1076 8365 2043 5625 2660 3920 6290 5845 3470 1239 1552 4977 5384 20 3134 6344 9305 1957 5982 2476 3667 8012 8968 6913 193 1730 903 6869 8132 5003 3175 9208 9719 5217 1184 2378 5488 7473 4574 8958 5063 6126 3934 6798 2497 3419 3142 8154 1727 5475 6981 5394 3486 5949 2306 31 4030 9560 6899 2161 4563 6425 7720 4281 1642 8903 3011 3481 2727 7584 8790 4141 3709 2724 939 2558 2494 432 711 4221 5906 7691 9614 9392 3639 8271 9422 7668 7830 2672 6181 8744 9096 3900 3025 7089 9155 2387 570 8233 9970 5711 2374 31 8434 9664 2588 7280 95 9650 1500 2352 7340 7465 1743 7331 2087 7516 1350 9916 187 3882 5012 5635 4134 4388 2723 3288 6774 9644 1520 6743 5355 245 3125 140 6260 2064 7419 6354 1713 5270 8706 5405 2734 6800 2735 4820 4316 436 1088 854 670 2451 6488 4803 6838 5563 8090 3611 5206 5961 6705 6912 2558 9830 3404 8817 1893 822 1523 3606 2444 6580 5362 1529 3379 4448 2701 4046 4883 3788 4900 5552 2590 1387 354 9427 6949 4795 3037 8507 7108 6093 5418 9665 5922 8821 8481 4167 5995 6355 4124 8438 2934 9485 6318 6313 3932 9018 6710 5166 9157 1609 7070 1746 2996 7423 1172 6296 8570 560 4802 5677 6653 6572 5341 8926 1744 173 3092 4090 6528 3567 8879 5813 3051 5197 2125 3334 4214 5187 8500 3371 6795 5569 5116 6142 9343 2640 2438 4264 3199 3591 9940 6203 6514 1632 5129 8258 1805 4572 2347 4684 8139 1226 496 7541 6422 8973 7227 635 4159 5726 357 953 7646 5473 3447 3340 8112 5884 7604 7662 5826 7543 217 2340 9175 5345 597 7331 6268 9295 2014 758 520 8861 4651 3293 7833 1877 280 1991 3954 636 9296 1599 6108 2742 4938 571 4977 2541 4585 802 84 4801 9493 5610 6497 6441 2940 2764 5736 1305 9874 2607 165 4524 2252 4350 2752 2531 6340 6705 3166 1987 8303 5626 1080 9592 2548 2408 8485 7132 9562 4920 1932 9054 529 8428 5495 9820 7544 7582 1124 3769 188 7640 4644 2439 1989 7395 1321 4681 4099 4487 3019 8753 6464 4099 4696 9011 6506 3180 6143 6067 8099 4426 1473 4979 2854 6967 4798 6749 4548 2273 517 1087 9913 5160 9878 1901 2554 1198 2933 3004 2036 5952 8108 8499 50 9155 3862 2907 2335 4 5326 6785 4429 6798 1764 3634 116 6561 382 1015 5186 898 2101 5098 2409 8330 3350 1314 5880 2635 4317 7915 8586 8776 2766 4987 7931 6627 7893 6617 6630 9570 9753 7410 6367 1516 7396 2834 4429 7777 3848 9614 5027 2301 1063 3787 630 764 5101 6509 3398 9417 776 1983 4545 3541 3321 8827 6519 7566 1795 9500 7135 1547 6909 9854 3063 4304 2687 3843 8433 6535 9808 9811 8835 870 3597 5816 7985 8697 2325 1383 4466 9452 9717 5362 9344 3038 4188 5862 603 5982 5361 4089 3880 8621 3942 3294 2925 6629 7136 7709 3163 6943 3871 1997 4164 7467 7812 8501 2516 6488 6235 3333 2291 5951 8694 1634 5340 2881 7495 2294 5214 2855 6383 5445 1476 324 8739 752 6952 5874 4812 6466 9169 8682 4814 9684 2500 8978 4536 5015 5465 770 8347 4108 3073 3392 5741 8412 2624 9588 7058 7837 8794 3440 3282 6621 115 8372 7372 3419 597 8535 9884 9765 3568 4698 5801 6068 3675 336 7434 5491 7458 2133 5950 530 5524 1691 5293 8148 7630 2350 2336 6423 2141 1969 3044 2256 340 6767 2026 937 1654 8261 7053 5221 2958 9205 1288 2984 9541 8722 4827 6998 7206 7128 3879 2729 5170 9171 7228 2799 1521 9564 9222 3661 7884 8617 2268 8224 5383 4293 5512 7036 2554 2564 8609 1863 1769 9896 1199 7661 4969 2377 1010 2174 9504 4888 1255 4674 4058 8482 3824 1930 4397 3045 1943 2281 8013 4210 6856 9748 4855 2367 3135 3760 1282 1743 1974 9402 1639 3172 3414 2959 1900 4423 1485 7756 5662 9091 8781 6072 3924 2604 8001 8321 2001 9943 6953 13 505 3808 9760 5359 2526 2895 9118 159 4637 1091 9561 2627 615 2974 1938 8866 3749 3422 6621 9410 8864 5401 1833 2787 8005 9834 7459 6357 6128 4411 6369 6632 4570 6129 8342 3447 5375 7459 3606 11 4902 3166 8990 1868 2491 927 733 6239 700 3706 2001 9563 5458 3833 2349 3462 18 9808 6170 2498 570 2539 9129 5140 5019 7471 8586 393 1281 8543 6755 2534 1708 5744 4401 551 3022 1486 6789 3721 5191 5141 9635 648 5326 1984 462 1695 8143 6631 4192 5064 5521 3321 6555 539 7143 1493 931 8423 35 7686 7309 8095 9781 1709 8645 2803 9546 1785 6523 1088 6926 6158 1736 8603 4493 8549 297 8987 1531 841 4050 7052 513 6957 7590 7655 8449 4873 2429 8483 2558 6089 6577 2338 7798 5221 5140 3695 7006 8015 4783 283 524 2870 5237 5016 1418 1885 354 9300 2725 755 6351 3237 7711 293 7243 6159 5165 6024 4642 7722 2112 7570 6411 6261 2791 7903 9956 6148 5917 1090 2782 6440 3959 8018 7807 5376 9902 4512 4675 8979 5266 7378 8567 2977 7670 2162 9135 2834 4537 128 6907 3000 7698 3317 9261 6840 7571 5568 2987 3487 3009 5768 6278 6967 137 436 8694 38 4947 9720 5368 213 7097 3935 9541 1118 6096 8675 3951 632 8803 7209 3631 2852 526 9243 9691 4448 1162 2677 7935 4170 4796 564 1136 4932 7352 6181 1321 2298 5901 6689 8862 2997 6975 8402 4115 3070 3429 4417 53 8583 1626 3683 1434 8503 9278 1124 2950 6791 152 7236 961 4947 7800 8448 6230 1503 4629 7550 3800 529 590 9014 9877 7564 3767 3991 6985 7195 4760 7037 5777 6385 7072 7210 1239 2701 4685 540 9491 4836 7776 451 9782 1927 5251 2363 3429 9879 6265 3580 6759 6854 8945 6635 770 2712 6978 4106 6258 1737 1143 2035 4473 4566 5596 5711 7266 6633 6250 3108 1468 377 3559 7602 2303 5161 9964 2083 5039 6228 2015 1797 9434 959 8431 6555 3670 5408 660 9928 3496 1802 8314 7968 2719 261 30 6336 6893 2632 9444 4713 3008 9354 2314 1663 4514 8629 97 9552 4857 2111 7700 642 3070 2482 7196 3091 7890 7855 9370 7737 6009 7683 5705 8727 4296 5734 1415 1188 8365 858 2252 7725 211 4565 5739 4724 3194 5835 627 4402 7946 8326 1395 7367 807 8590 457 5048 2796 9827 2785 8804 3861 4841 3883 8156 574 1649 5696 5291 2506 7947 9367 9068 8864 5105 3791 8409 7291 769 9162 5236 9094 556 2602 6252 9145 9411 7652 8292 5589 436 3448 9449 5276 3682 3957 2201 5330 9652 3843 7835 3950 9561 6902 9165 4665 7044 7573 1956 7812 6734 3543 3257 3641 2497 5860 9137 8259 3511 7429 3847 298 876 3295 1925 4557 7251 4126 9886 3254 4320 4072 3556 3881 7325 2720 4897 4368 6645 3204 8531 9730 6747 1787 3371 5595 7646 8859 3853 7509 6287 7699 7806 3514 7345 9731 4422 948 208 659 4201 879 4730 4108 4759 2054 3180 6008 2773 6176 9211 1303 5905 2309 9441 5627 7903 7087 4486 8107 947 7124 5805 8752 638 9502 4834 1411 449 1393 2070 1001 2272 3151 5109 3382 1557 8288 9389 4329 4463 4952 1984 6719 7260 1424 2346 1515 4862 3183 5973 5808 6658 8130 912 7295 7631 5745 5058 8079 7138 7127 9079 5761 6629 4187 9142 8185 8826 4883 8866 9640 9834 849 6359 3445 8624 5056 1311 3486 4590 7284 5645 1247 5413 6556 4894 3043 2301 9951 1121 5790 3429 6551 1550 57 738 7043 8242 5915 1925 3459 5555 8110 659 8265 1555 9282 3320 9217 9119 4261 6500 4764 5507 8264 1319 400 1306 9971 6702 8778 2112 130 5329 13 187 2418 7056 4780 4684 8980 4590 238 7090 5248 4854 4996 881 4525 4212 10000 8785 712 1115 644 5327 8785 1043 6633 5108 4097 1762 7219 4226 3442 7232 764 2211 4287 1895 6895 9618 2836 3484 3059 8083 8338 8054 5316 9214 8618 5315 7999 5681 2781 8642 1007 1565 6036 7639 3024 132 5753 243 710 5546 3826 7825 7757 4464 6072 1003 4081 8907 4486 3492 6990 9175 1545 8657 8389 162 3971 2739 5842 3103 1380 6849 1019 3767 839 4043 251 2943 4285 960 8489 4462 5136 2597 8925 1207 3599 9357 114 4436 2848 3455 9963 745 2111 4703 7258 2433 7441 9452 1887 5172 6300 2905 5290 3490 6947 5540 2785 7583 2851 1273 2044 7987 3869 7320 9193 3819 6677 5658 8254 5876 5464 8216 6620 3926 9270 3878 2710 6710 9681 4596 8233 2332 7501 3523 5821 4447 5414 4957 2030 8265 6229 425 6251 6449 7745 1795 6619 773 3805 4873 6648 9268 9440 9620 3194 8710 9849 2255 1771 9529 6851 6356 1860 4351 6230 4032 5149 1643 8989 7178 9907 1569 3955 2509 4370 1699 4304 988 2471 8108 2212 5470 3727 8004 1441 3272 3065 1289 5527 1187 817 2377 7542 9028 3079 123 3060 8227 1766 8400 5405 8024 9968 9359 533 689 7409 1188 1677 6231 9295 240 8052 9373 8243 9493 2645 1307 781 4523 2494 7950 6899 6387 3329 9977 6510 6388 8203 4627 1139 9959 2650 7459 5669 3182 8147 9429 721 6175 5659 15 6415 63 5740 4657 9555 4736 2316 335 9258 1161 4636 2508 7547 7965 2484 4056 704 7038 5034 1843 3349 7684 9301 5369 7217 7447 1150 7938 3622 3160 4304 6388 3222 43 1044 2776 4778 9711 9463 387 871 4098 2894 8418 2062 1729 8825 9118 8767 3859 960 8467 7894 260 187 5110 4058 1336 3047 4031 4496 3703 418 7717 97 7814 493 4875 7524 6307 5261 8395 404 4507 3164 8818 6235 8340 7935 1353 8550 8894 9819 6443 5505 6 7905 5914 7693 7303 9945 2188 1005 362 6257 1102 4527 6749 2328 2051 3055 3940 6797 9810 8446 6312 8627 4681 1003 2913 6033 9553 8158 2204 2347 3662 8561 251 5928 6253 7554 5872 8441 8558 2585 1049 6011 7112 4149 8338 5514 3555 2278 8662 3364 7075 1325 8343 1755 2327 1255 4140 1879 5765 6343 4226 5778 4903 828 1705 1155 8381 7576 5947 3291 161 6995 9301 3624 1143 3991 5489 4697 2620 4150 4413 9694 1826 2755 1449 4152 361 5588 2383 6125 1930 2960 1903 3184 3787 3607 4338 2168 7535 6637 1810 4047 3631 1110 7670 1126 1452 3158 2174 4071 3659 6586 3765 5484 9340 1565 5987 6053 3504 8369 2177 5433 1328 431 4968 1467 4038 9305 3634 1572 2293 1795 5618 2276 9256 9639 3401 708 9148 5574 4778 9158 2160 4894 993 7851 6458 6979 3903 9961 5348 2432 1745 3027 2862 6712 4493 6899 2369 4478 4822 4661 6272 6791 3288 1880 2781 6688 2587 8280 8614 7364 7437 7125 8610 8429 4975 5067 1760 5230 5028 3459 7661 6772 6485 6874 9836 7330 125 2204 8159 4946 3216 783 8089 6504 2662 869 9543 5248 5501 8156 8963 2937 1632 7572 7718 2959 2639 9477 8188 4018 2935 2200 7141 5771 9073 3328 9452 9197 1883 7611 495 5099 8393 8583 7954 1054 5803 3848 2653 7655 8356 1615 592 9987 5539 4661 2945 4529 489 7484 8546 3423 6035 2038 5545 5108 5366 4997 656 7248 2607 1150 8698 7351 6084 3003 8404 8239 6851 1056 5893 5206 9022 2836 5192 912 7496 4489 5440 7984 8324 337 7758 4359 8727 3303 9466 4092 4651 121 7691 3609 7623 6389 959 58 9391 9362 8296 6241 6769 541 7798 2142 3376 9342 3054 7224 3830 4845 1559 2153 1534 9317 6511 260 8971 2328 4351 9973 8801 2041 3581 2775 4781 4539 2832 4172 3900 7480 6764 7020 8020 4562 5513 7747 255 4918 4970 4084 9763 6529 2588 1296 2197 5451 1555 1167 4130 2257 1139 2930 4297 4719 2056 5430 5609 4888 9601 9508 8719 2716 2879 6738 3629 8391 836 3883 3309 5806 4318 9423 8686 3258 7070 882 8708 8624 8400 2837 880 5890 2119 1528 608 4174 6957 6216 5413 2909 2075 4131 1977 1305 7220 1957 6047 8056 5840 5707 213 6509 5129 8898 9766 2198 6131 8473 7173 4530 7662 4404 419 6132 2284 7378 6657 5592 9945 2070 4853 8371 2552 6829 6027 6124 8785 2073 531 976 7780 7095 7485 9260 5992 7250 7810 8474 2075 4982 3003 9736 5738 9773 5867 8021 3502 8875 3612 3446 944 4816 8168 9848 1644 4194 2323 6781 2618 9205 4108 397 6299 1592 6009 2290 5194 3818 763 7268 5151 117 3355 888 6241 5573 5260 9742 4447 5224 9539 1743 39 7706 1590 1683 8251 264 4815 868 9468 8922 7617 5766 6866 3625 4407 2059 7442 1521 9326 2592 7989 2680 9832 4229 8252 5091 3970 2698 314 9860 792 353 3917 8733 8387 2167 8996 3201 9386 4815 8474 7002 580 5339 6978 1338 7397 4419 2858 3074 3363 846 2105 3194 1426 6708 4636 1747 9406 4950 1606 6549 1654 1874 5282 40 4040 4277 9592 9778 9092 8065 3131 6023 9756 109 7361 7152 4527 6570 6578 4241 7416 8682 7434 5193 5390 2070 6940 1147 3371 4897 7695 5024 6771 2976 1415 7162 3605 1006 6939 2696 5422 70 5070 5177 178 2430 8681 1056 9000 5258 5297 2767 3939 9082 7959 5680 7503 1250 6826 7225 6147 873 2248 2917 3848 3662 78 7452 1019 7017 6499 6441 3438 1569 1617 9967 350 297 1022 9349 1906 2670 8467 2197 1752 2778 7876 5606 4027 1054 2831 173 1926 1430 3089 5773 1444 9519 9577 2462 2887 2427 8902 6324 3995 6871 6290 697 3519 3663 6397 5425 6333 4864 7621 4436 7641 1848 6393 8019 2901 9223 4544 4826 7005 3984 6951 8448 3502 2879 909 6388 5305 6163 9063 5652 3033 5352 6348 2903 5367 2744 8327 8051 3959 2299 8838 7951 499 5230 5970 3399 805 513 4577 7809 848 7879 6256 4350 7109 7164 737 8765 9678 6152 4416 2710 7855 7115 5613 3221 6211 291 1271 169 8942 108 4472 9440 1690 441 9190 2494 7305 118 6654 8152 4348 2909 8853 1456 6424 5942 6573 6102 2093 7340 5163 9947 4455 7127 9520 7017 3770 790 7185 2711 7250 1656 8502 5291 8448 4043 7784 2104 513 789 6608 1212 3697 1812 9020 6472 7753 5592 8925 6197 2931 4088 6144 3737 7566 5663 753 1335 2804 4290 397 6405 2297 8898 1695 7097 9293 5830 9200 6157 6618 2159 7368 6666 323 6387 3138 8075 1978 2062 4272 4909 2501 6767 4997 67 8781 5750 1401 7936 39 1798 4341 2335 7047 2387 9431 2691 8217 4983 8847 1186 3493 6215 7852 3815 8953 7341 8242 931 5754 8865 2191 8255 5631 7187 4673 763 9288 6073 8698 9326 4222 9390 1661 7621 1777 7443 311 9993 2425 5510 7530 2270 8076 5381 6084 7028 2721 4325 4310 8475 3189 6500 3081 5171 39 7753 5933 9326 177 983 8652 4399 372 6664 8371 2148 458 5033 8492 9235 542 6022 1504 8617 7754 3939 1997 6827 8264 6306 1653 7804 9158 4733 9327 9196 8837 5259 8521 9013 2593 3524 9763 2965 6539 8133 1464 3349 3166 6308 2583 59 2329 438 5028 6434 4376 7024 3260 8991 3329 4912 3147 2486 5996 2473 8033 4832 4083 2906 197 6676 6429 9959 9640 9320 4444 7455 2668 3961 3762 1602 371 2442 2039 5398 8876 6414 2421 8487 1757 2102 3399 4903 939 5746 7375 5324 6930 1457 8229 7126 8132 1009 3436 4123 6680 4231 1578 9347 8191 1691 948 4914 4133 9338 311 3008 5752 9084 1494 7508 7537 1244 2410 4827 6990 6136 150 3919 7592 8378 7396 5724 5739 831 6198 2418 1414 7775 8117 5956 9466 5416 869 9950 4754 1180 2957 6857 6615 802 716 4151 8398 9477 8977 1739 5612 9127 2009 3203 3856 9404 5278 9594 6586 1476 2012 7999 5602 128 307 1419 5543 1175 1368 6648 2354 4324 3504 8968 1478 4219 9470 6227 3695 8447 7965 9306 3925 9973 8861 7780 5728 4138 3726 8665 1965 5737 3016 7567 2216 3322 8985 4110 4496 353 758 3202 1028 4261 8521 8857 4832 7991 5083 8526 2789 3047 4184 6713 9371 3044 4492 1450 3533 8217 6467 5498 305 9482 3064 8872 9155 8400 2982 2 8752 91 3203 6132 703 8076 4988 5534 6066 71 412 5206 9469 947 1918 5192 3990 2761 2993 3874 7330 9459 9371 7634 5292 8786 2858 798 3538 2191 800 2289 2281 354 4772 9335 8429 9760 1221 846 6182 7984 6051 2002 8930 4320 7193 9271 7081 6538 3144 4410 2348 8867 8395 7640 4004 7604 4789 7541 9794 5588 6182 8426 5942 953 4113 722 7064 5333 1568 3245 3316 3970 5247 2245 8290 8791 1515 1722 5328 1010 6131 7676 9876 877 1667 232 8481 6455 7772 4626 2043 305 9404 4336 1258 3516 5057 4673 8848 2976 7918 8515 6946 3164 759 1587 1954 8625 3308 7282 9634 5790 1309 5862 3018 2975 6093 7850 9429 216 2476 7823 6873 8231 2158 4482 1746 3567 9154 593 6542 7071 5459 9839 6586 6217 1425 8540 1193 1084 2173 7178 6873 9833 3039 6243 2807 5483 4092 8587 2051 2919 6410 8923 1149 4919 9756 9246 8485 8909 6190 1379 5980 1648 1217 2565 4216 8994 7456 5408 77 5980 2586 3302 5812 1976 5896 4970 3811 9987 3557 2213 9258 6318 7487 6758 1236 7242 6004 6073 6150 2193 7451 8481 3841 5019 7398 8056 4012 1205 9816 441 7185 2401 94 9348 728 5989 4318 4538 5975 7874 3102 1584 4191 588 8342 1778 7829 697 4202 331 2889 8004 8811 3081 3023 2560 1137 3386 3765 7304 178 7301 6056 271 6648 6783 6259 965 7673 8586 8838 774 169 9380 1362 4862 7510 9190 5558 1711 9520 8447 6067 4683 7879 9089 7242 5367 8826 7358 2670 9004 4658 8725 5626 1306 5508 1885 2270 9532 470 7460 305 6990 3191 1666 1852 7052 7208 7409 8763 3079 2207 4829 7761 86 269 1355 5452 5446 8712 8122 801 3370 6846 6427 1027 8705 4663 3296 8236 5132 7107 8541 2121 6650 6558 324 3701 117 7733 8815 3196 6291 3643 7308 6376 263 5014 8180 2061 78 6301 2861 3447 9498 5639 825 4555 301 472 2790 5432 7579 7682 3905 580 592 4228 4280 708 8312 3095 255 4603 3089 3915 7330 9704 5280 5509 1764 5357 8161 976 5155 4011 6615 5979 8565 6915 6451 1354 8699 381 5388 8955 960 5979 9534 5239 3038 7846 4685 9645 8800 7774 3559 6129 3829 8838 7990 5592 547 6150 2919 5701 160 9533 1680 8724 2800 8130 6430 1498 8510 1817 6804 5821 4147 6337 1059 7184 534 2096 6828 9333 6221 6738 1814 49 1928 9803 1992 2474 2304 4910 4526 2464 4443 6205 7539 3594 686 320 1443 5547 8488 8246 1367 2634 4582 8778 6170 5116 873 9349 800 7093 2439 2613 7141 4366 2415 9132 3191 1071 393 7716 3534 1187 273 7424 4780 958 4096 6222 6505 2583 819 4223 1569 1753 3000 4090 3220 3872 9790 4019 7316 2228 2984 4456 2945 1750 9939 6135 2820 6684 203 2705 7870 475 129 2650 7784 4224 5223 640 3158 2394 4863 4726 4146 4214 5167 7365 4438 4957 7735 1753 7184 718 2561 6481 2468 8851 8967 5287 5534 9169 7992 3404 5995 4472 2405 3779 5047 3979 4418 4556 6372 9280 5634 6869 3494 800 585 4283 5756 8320 6035 9292 5389 8595 5772 4208 3798 1090 9495 9331 259 3838 9086 2605 4661 1490 6383 6059 1821 801 614 8192 6432 6247 1413 6277 7047 1997 559 9154 6668 2946 8445 2057 7892 568 6264 1689 8010 2110 1020 4620 2299 6457 7224 6959 4299 3607 3017 6119 759 9983 662 3542 6229 2074 9819 9627 4071 6729 8781 738 9674 3577 9146 7566 497 5410 9254 8506 3871 6625 3125 6170 9434 348 3128 3732 306 2497 9850 1064 2479 511 958 5059 8937 776 4686 9359 7504 3466 6448 3530 7042 5594 1095 7538 7355 6700 2395 1225 9677 5519 3746 9110 2219 3226 9193 2524 5722 9042 9940 4552 5904 897 9610 1192 8024 4295 550 1879 4112 6998 1760 1154 2591 2854 5043 6297 5906 3790 3873 1934 9308 7619 7395 7878 844 6587 6754 2917 1980 6693 7468 7883 3941 3429 9075 8316 7724 5976 6546 1835 2973 8306 9340 1915 7511 735 8211 3416 4524 8436 1701 183 6054 9095 8061 6897 2033 4814 9813 4012 7858 3632 1895 8150 7060 7321 2817 1135 3296 9362 9322 2621 7667 5013 887 5178 5747 5450 4945 6622 3885 6646 3157 9938 2092 1217 3186 4125 2382 9350 4488 6591 2981 6382 1092 6392 54 3908 7527 9702 3269 6848 8674 7288 8212 9560 2465 311 5009 3761 6932 5245 6758 88 1534 8850 7656 4719 9326 6389 4068 3813 2979 3400 6547 4070 9792 2952 4329 3670 9005 7598 6869 7678 4885 5080 3590 3701 5390 4950 7461 8674 195 4219 5113 1728 9420 9121 6447 5097 5509 6866 5261 4840 6618 1807 5261 6409 1111 9590 6430 115 3539 3298 7793 4775 4729 1382 8475 119 6331 2287 5144 2877 2857 256 4605 8628 5728 7403 76 1237 620 5337 2428 7237 3495 7688 3645 4605 7277 74 4720 7167 9723 8864 1941 4452 6597 6767 922 9279 5406 6065 2156 8262 2672 3112 3242 8400 514 3317 5988 1133 5005 8415 4722 8500 6102 8366 9456 9731 4792 527 6897 866 9390 8838 5317 2338 5604 2590 1617 1009 5006 124 5623 7678 9587 5216 2429 6452 4884 8416 7584 9889 6830 8657 4740 9283 7023 4195 9013 8166 4722 5910 5383 463 4747 7052 2801 6702 9641 769 4063 4647 7244 6037 8676 6830 7604 1104 3281 2487 9519 7216 8727 2700 5873 3466 1982 9247 7661 995 3764 2382 3256 9146 2844 4354 6197 1996 1055 2190 2764 1469 6836 6359 3857 5511 3188 1460 2966 6468 3947 2484 3684 2673 1535 5908 6139 3516 5154 151 4510 8917 8884 7765 8062 8079 8470 611 75 9525 2800 9190 7345 9635 5549 1202 1497 8736 2661 4462 1556 2959 3297 1591 5632 4831 7498 8122 4698 2651 4624 5560 7919 3507 9676 2332 1585 8146 2942 8011 7670 5741 7201 1366 1727 9101 2567 9575 7836 5228 388 5743 4538 3684 7333 169 4866 4830 4642 9564 3832 9265 5123 1750 2771 1150 4082 708 9295 7023 8718 3316 9116 5918 4682 7194 5018 7248 6769 9206 8827 7156 4948 3365 7192 8633 9885 2057 3462 879 7972 3646 143 9446 5395 9266 596 5828 9973 9890 9203 8690 3206 8318 960 7887 5511 2329 1486 8631 7886 6665 5787 9186 6381 2978 7818 6265 1386 7631 7143 5710 1276 3638 5155 3023 2903 2102 8850 9227 1992 8052 4268 1549 2721 5227 5787 4584 3908 7272 3214 1793 288 5352 7330 6668 4681 5147 2933 6067 2778 6427 8128 405 64 3282 3427 9318 1736 8629 8544 79 3032 2812 1627 2105 4390 7413 6688 8297 1036 6253 6442 7676 1605 3771 4343 6285 8918 7275 8703 8047 54 6830 8451 117 6464 8230 5787 8199 6858 4330 8277 9889 7141 6255 1993 1531 19 5032 6179 7406 1285 2620 5081 9241 2743 9424 1877 1660 3050 6932 6058 3103 3761 860 9572 6576 9089 5358 4774 5946 6039 9402 2187 9532 5656 531 7414 5674 5563 3592 3080 3199 2564 8160 8791 5306 7583 667 3317 6985 7598 9374 87 7711 6585 6010 4286 5674 7719 5412 7971 3758 4813 6509 3289 469 7040 702 2494 8954 645 1925 2152 9560 85 7294 4865 4019 7960 4533 1003 1910 258 7442 9620 6843 9803 257 2516 7522 5668 6838 7631 6833 3347 919 3653 386 7972 6146 5691 4968 8071 7842 4528 4507 1487 5744 4877 9446 277 5880 7707 6886 9673 3678 3728 9475 287 2595 3348 5954 9433 978 9138 9131 8248 2790 9516 2571 5288 5206 7539 9710 9399 8418 4216 885 513 9092 6682 7141 1323 741 4027 7347 4418 4106 6822 1056 6701 169 7010 2485 7499 2499 1615 5746 5289 7482 8317 6928 9039 2207 6637 4789 6976 7204 2025 7488 2647 5058 4629 3970 5798 8655 7668 6568 9112 4489 7623 5812 1010 984 4648 8508 3483 2614 605 5123 95 8921 8402 5485 7479 5038 273 4454 8593 2297 1942 1239 7355 2922 1560 3152 7928 9228 6071 7039 68 3694 9203 7429 1029 3850 5936 4511 2816 2893 5985 2910 8165 4386 4747 5644 5775 5019 6449 4367 7316 4742 1958 1022 7663 9869 525 1942 9096 6596 8981 5516 6641 8183 2944 7669 8384 5232 8532 1199 8124 868 461 2640 5254 5207 8283 1028 225 4732 1747 3892 5825 3704 1265 3488 9924 1790 5429 5372 4737 761 887 1377 8943 182 5397 3679 1765 280 4877 6240 1148 5337 8880 2753 6895 7162 132 7120 8245 1878 7363 4070 1933 8628 3909 1857 6769 5689 7228 1505 6450 4466 9233 1744 4647 981 1774 6412 1261 6651 2651 8760 8339 1530 1512 5234 5044 7995 8705 9640 6225 2419 61 8157 7398 3969 6365 4166 6010 9944 5670 2459 761 4902 554 1760 2235 2328 4523 9847 5330 3525 8606 20 5055 6469 1605 6450 4463 6661 2441 687 9080 2502 5196 6477 6470 7912 643 8831 4208 2664 7641 4968 3918 8195 3079 6152 6874 7601 5998 2203 1126 4603 8574 2532 7423 179 8981 8237 6839 1421 8924 5918 3922 471 8747 6744 4734 5741 1926 8941 8404 9567 261 2321 4113 3339 4824 986 940 821 9540 8417 1775 8113 948 9197 8291 9928 3786 1482 7700 9061 3751 7974 9531 2497 1069 616 8237 2994 9557 2993 8912 6169 1665 3024 5859 6489 4009 3150 7309 9900 1566 5436 4365 2513 984 2655 8792 4769 488 2844 3829 4239 817 9711 6735 8237 327 1324 7582 6235 4316 6494 2403 5980 9517 8261 2468 9878 7763 6129 9777 9328 1564 4141 1841 8899 3148 632 3668 3635 3475 7496 4225 643 3559 960 5231 3885 8635 2813 119 2950 5658 8873 5281 5174 3485 4101 1403 1247 6581 7532 575 4496 8024 8767 3394 7523 9398 7061 1158 9225 909 5382 6219 4467 2693 1450 4703 1327 614 1173 628 6271 45 2261 7796 3529 6361 5551 1128 2941 3082 8054 3788 1105 6820 7181 8628 2569 594 6137 8145 7854 7870 4364 8672 6915 2165 3374 4593 9130 4546 5221 1752 942 7481 5899 822 193 1449 1949 9485 4530 2 3272 1987 3173 6804 6966 5742 7397 9454 3886 5250 3675 4601 273 589 6765 3646 5182 5894 4543 6754 3997 5484 586 9896 2658 778 1344 4606 262 2226 960 9885 564 4132 6688 7529 6225 437 3334 111 2038 7008 4711 2311 7597 7828 2308 9130 73 3203 2235 4070 5038 2820 3965 7695 9949 5308 8653 6562 7533 9612 6446 8096 95 9485 1976 6320 9921 5309 6430 1959 8669 7492 621 6265 5319 2928 1746 5392 6130 3980 5813 1168 3151 9777 8862 3099 5084 3866 9660 8969 3477 6105 3416 9924 1941 1744 6243 1862 3404 9024 3820 2072 2867 4440 4688 8186 3719 6433 9929 9849 6764 5741 7368 9914 1869 2581 9364 3304 6447 9023 2272 6275 1479 2040 6198 3420 3783 2440 1633 3538 7815 5452 5610 682 6243 297 5219 6313 3082 1499 2513 9845 3591 9880 6111 5459 8813 1826 5114 1611 849 7386 7885 8679 5777 4083 8450 5911 2874 82 9448 7041 1885 5057 4074 4479 5354 9292 792 4787 7142 3304 983 732 9536 3445 2542 8348 5271 7655 9958 2471 1392 4194 1149 3520 8276 9599 9430 7502 9680 8878 894 7917 286 4967 2395 1991 4258 3186 6777 7751 6490 7760 4834 2377 1204 3727 724 6474 7733 7033 8944 9125 1226 6445 2644 5854 2395 8426 9707 8426 3655 600 6342 3940 5566 8737 5931 6175 1922 9059 3925 4763 3170 5110 7139 4374 8836 4214 7199 6568 1246 2495 2044 8824 5291 4688 1029 7685 9465 735 6110 3119 7686 2452 7058 9603 1188 9340 5777 9461 8399 6053 4224 7920 1162 1362 2293 6349 5576 5844 2916 3173 4690 4960 8348 9980 5999 9376 4016 5463 6462 125 4933 4147 8928 1990 3749 6467 7682 5877 5928 2432 8281 151 351 5794 7864 8996 2142 9791 1191 1410 9316 5880 6369 7663 2211 8719 3391 6226 4181 9852 2702 9113 3999 7982 7454 4099 4448 1487 6328 375 3918 4608 6877 621 402 1093 9616 8895 883 806 304 6550 3037 3024 4213 1599 1742 7603 4176 2274 3806 3229 7738 7804 1210 5192 8255 5658 6678 4582 2384 6948 5541 9261 7568 2294 353 3535 7541 7587 692 7844 4137 3728 868 4701 5326 8961 8655 5853 1235 2460 9081 8972 6616 291 515 1222 2300 3545 2155 4683 492 7695 3943 4411 6341 647 7945 3881 4586 8636 8076 5074 8715 8943 9774 392 4256 8428 6244 5490 7239 5324 4461 3854 1966 1328 1427 4265 4872 3581 8948 5363 1276 9242 9773 3968 6241 4069 7848 826 2704 5923 5899 7770 1218 2024 8161 5473 6803 756 7314 4041 6079 8126 4247 4397 9453 5673 8661 4324 9254 7608 6038 6881 3202 2162 848 9442 6230 5047 267 5285 7321 2517 3054 4890 4540 7566 6714 1342 8321 4027 5382 752 8505 5980 5148 7957 1653 3808 8633 7258 7768 4670 490 969 6832 1337 410 3061 2735 7028 4698 55 9544 7751 4945 4083 1669 1658 5424 9989 2037 7157 7092 541 3137 2239 8497 1141 2399 7129 8398 166 8151 5239 1134 4982 2927 7895 4394 5661 4922 9091 2067 4465 3194 7011 4899 4862 5021 322 1202 3409 3830 8294 3949 6966 532 8797 4458 2930 2278 9207 9447 428 4445 6932 1761 7371 4826 6154 3031 6099 5245 1450 6915 4790 4812 1813 9651 9832 8486 7204 3240 2316 5497 3540 5633 2381 2337 6443 1662 4614 5649 1109 1393 94 4392 3153 3816 9218 9306 3199 1668 902 4648 4935 5691 9459 6747 1693 5643 1585 8897 5234 252 745 8774 2236 3125 1110 8678 4787 2075 4327 2247 3467 772 2990 6619 4587 8559 5924 4137 227 3178 8784 5161 8868 4595 8259 6913 237 9843 5809 5470 6446 6553 4243 8682 6030 1704 7359 7168 3778 8037 5766 3596 8808 8755 214 9747 7314 2490 3883 7540 5667 9019 9052 886 3613 7310 4150 201 3505 9958 5670 9950 2863 6265 8631 8892 4320 2342 2411 4450 378 8176 8045 5538 6930 4611 1636 4243 7100 1870 8134 9118 888 7185 6355 852 847 505 1052 4351 6814 3074 652 9676 9338 5635 4919 3657 7976 7329 8106 4705 5504 2503 242 8786 7113 1877 3028 4212 99 7514 9681 986 4698 2387 8190 1896 2891 9241 6246 6057 2314 6898 2084 8003 2532 7003 1660 6859 683 6117 1563 2539 8619 1805 1324 5731 33 703 6294 6483 8216 2326 7469 9266 1065 5658 1161 307 1250 7407 6363 9916 656 8447 7918 9539 1801 9577 6397 2483 2046 4311 5021 7016 2467 6344 9099 8852 7047 1744 5334 5262 422 2802 879 1486 4811 2040 1792 2413 5798 8155 2328 6453 6601 245 2343 8401 6174 5091 7235 4571 9401 2256 1586 1868 4951 684 719 1997 8780 6052 3611 9201 5206 4489 686 6368 2880 2477 8780 8677 6983 7459 5129 9935 7704 3823 4687 229 8913 1922 4799 8314 4177 2736 181 5479 9772 899 7476 8551 3302 7438 7751 8507 8278 4788 1227 1158 3616 6 9834 599 3817 1315 533 1520 5137 5220 8100 4050 3493 9250 2363 4021 1985 8895 9499 1756 6145 3326 6658 9446 763 4408 4305 5393 5547 5531 6550 9163 1888 2735 9761 5704 4049 6645 3575 5538 8216 1674 5939 1708 923 4653 5728 9260 3547 5227 1015 6043 8552 4025 5488 5667 4784 6144 1059 331 1674 3960 9493 9914 6694 5605 5617 7095 2249 9192 2632 6817 7217 8570 8524 4492 9574 604 3751 3120 2182 1117 5514 7085 5141 1001 2751 9925 3497 161 255 1522 4120 6099 1435 7166 1703 7052 4260 303 2595 3243 7119 9811 8164 1995 654 7737 2598 4404 7208 4779 5521 2721 1863 7013 73 966 6937 3569 1126 3543 1443 1598 9641 2877 8763 7695 6280 9374 7998 5226 8968 1468 1389 7131 3462 2042 1219 2411 6446 8426 3541 8318 7498 5404 5330 7570 2721 2267 7491 198 5809 8933 8147 1802 8161 3261 9496 4441 2634 3845 6018 1601 5313 7406 5083 5126 9448 6301 7537 2245 1078 1077 562 8575 2832 5891 6145 1904 4509 9987 2102 6670 8919 6600 8471 7079 9861 7966 7871 8846 1811 3889 447 7123 7646 1881 8600 7093 8182 2488 5689 5611 9917 6250 4186 2748 8493 6682 1004 9353 6668 9457 6022 1938 6056 4492 9016 5916 2458 3239 4762 4268 3479 1560 7742 1124 3440 2693 4569 7973 5181 257 9936 5097 2859 4121 4196 7703 802 5199 7055 3821 4655 3077 5758 7063 7568 4773 2978 6377 4363 4091 6996 7841 2002 1089 5317 1794 3782 9885 9766 8962 6493 9701 4058 5703 173 4605 3405 7326 9804 460 1146 810 9888 6903 7872 7455 8028 7202 184 8742 7644 7179 6583 9646 8268 8251 1439 2049 8135 7556 7362 979 3609 7771 6682 3781 2375 6438 1107 8530 6897 8604 9340 3136 1859 3563 591 9886 7116 7126 8627 4760 4304 1561 4405 8923 9811 5843 971 4297 3398 4684 1628 7006 2454 8309 7139 4829 4746 4597 9710 7995 3200 9049 1130 5058 8964 8072 1295 6079 5197 6274 7190 5853 7834 1594 4775 3997 3788 2098 4645 3538 6781 6272 6895 9235 4580 4033 415 5678 8629 124 24 8181 5525 7505 9590 4488 5577 885 6918 7125 7158 4108 2977 1343 2053 4104 1691 5841 6201 6336 9378 2981 2607 6272 8567 3539 6657 8981 5568 1637 5457 5591 6169 981 3095 5759 1820 5023 2995 5089 2148 6504 9196 1476 4198 7601 5579 5889 9793 8131 2224 9170 7464 1182 1793 6030 4720 4801 5011 287 2790 467 2229 8958 7799 5324 4716 9618 6698 4062 4706 5197 565 254 6673 4763 4206 8603 651 3998 3086 9226 9519 549 407 7663 6578 1479 2464 7940 8117 5253 4758 346 562 2556 2021 5278 8525 8718 5691 9583 3915 6256 6188 6939 1018 393 1893 8020 742 4978 3597 260 5526 4003 4274 8456 1833 6737 6395 9950 8341 7505 295 8903 60 2315 532 4937 7384 6222 871 1298 8829 7058 4588 6198 3802 6481 569 895 1458 4165 1154 3336 4520 5427 1791 6352 8516 4537 2653 3208 2041 2947 8462 8453 1613 5345 3389 8997 7919 611 6646 6747 4020 1234 9297 7821 4066 9865 5067 5523 4030 6220 5210 8549 7998 3352 1252 2865 7889 3905 6073 9929 3203 886 4733 4816 6231 4473 164 4149 5083 3161 7247 9102 746 6543 3274 4811 6408 8340 6686 437 911 1895 5337 5261 5247 2940 8125 9487 6844 549 5767 6399 1435 500 1214 4017 4972 7729 8165 6407 889 5411 5508 1635 8306 5134 6445 4713 3473 9482 1501 736 1377 3189 5996 2975 6128 472 2461 9324 1021 8227 2074 8807 8726 3287 2823 50 7367 7339 6456 4607 9101 8315 2593 7406 3448 5390 8470 3273 4871 6322 4008 6247 9510 6355 9221 1990 6826 8033 7665 4198 6260 9738 9356 4985 9376 8530 5034 3094 5868 7841 7700 1321 6156 293 8726 9603 2034 3548 9227 6904 9869 3234 9503 5731 5940 5075 7720 9118 3108 1736 3315 9367 1473 9023 703 7200 7552 2089 293 9772 9929 7992 1092 2436 4636 6169 2039 6669 9716 1265 3573 5937 851 9427 1667 3142 4501 5738 2259 7608 7473 1926 3326 8945 948 4029 6144 4851 6117 6436 4622 2397 779 5713 4833 5415 1882 3223 8435 7949 839 8359 3885 8041 7785 1903 1183 2286 7640 9793 6245 5112 1718 9571 408 9017 3599 2903 3868 6067 5690 4841 4815 6469 554 9647 8235 8787 9221 6669 3087 60 5028 3324 4452 9164 5226 5634 1449 2866 5427 7694 7977 3496 7264 8385 8865 7214 7639 2732 3280 3329 7572 4446 9797 4477 445 8031 9615 9665 1051 9054 6076 2430 2377 528 1594 3954 2513 9394 6819 4291 7087 1148 7787 702 5884 6651 7915 3522 5734 7546 6850 9657 8344 6646 486 8788 1028 6452 8452 8431 5505 880 7212 4233 7759 8805 8187 271 4551 5005 4562 1637 2504 8700 8691 8387 1702 2957 1909 3787 6855 5110 9795 5198 8108 280 3985 5487 3084 8788 3917 4940 6019 1129 9173 3777 6285 7359 4048 835 8715 4961 8824 7571 12 3866 5957 8065 6822 4217 8203 28 9327 7997 1577 3786 4629 1913 9272 7712 701 9541 9003 3071 7021 8175 6848 3305 1885 7247 492 6952 2207 5667 4522 8570 9532 6830 6634 2705 1047 4836 2733 6725 9184 4309 510 3812 6222 6133 7875 3274 5673 6878 6344 2693 1404 9543 5998 3289 6789 2841 6592 8995 8507 1113 3916 4390 7942 549 7094 5340 1736 6178 8416 920 487 5277 1083 3060 1410 8958 2685 7082 2187 9028 6127 3590 4923 8476 6878 1711 1316 3469 7058 6174 933 973 563 5227 7874 4008 6918 9609 186 5334 6880 7024 6962 4315 83 8371 3272 2767 1805 1810 8146 7931 5399 3068 6406 8629 4779 4073 8449 8188 246 9382 9160 7160 960 3385 1167 7877 9346 1352 3210 6225 8375 172 539 8457 4894 162 7575 3050 1971 2073 980 3722 1492 3737 2350 2622 7809 798 809 4406 6531 9969 1565 7490 3353 2732 5367 2698 4083 4928 5275 8810 1451 2165 3618 2697 8679 1193 5746 7001 9617 6726 722 1108 6814 9423 3730 975 221 4538 5380 3103 858 3297 593 563 6028 5959 3260 6462 7238 4886 5271 8689 3403 5241 1385 2081 6433 7130 9081 2401 207 6155 3508 3373 5577 7237 4347 2149 1775 6078 5252 2632 9374 2196 3194 5401 4506 2806 8215 1743 4043 9837 6783 7445 5077 4519 9525 7861 8001 4958 261 8207 1112 3769 7931 3040 7357 2277 5189 9131 8355 6792 8115 7728 5339 7660 9481 9844 6817 4047 1586 860 3883 4721 8304 5312 9239 4181 3172 7239 5490 9785 1798 6601 9905 9728 5992 7261 2005 7532 6392 6711 675 858 790 6013 8517 270 5856 1686 4316 3794 2545 4551 8514 7200 9862 4104 7732 3033 1343 3221 9169 9492 6173 9073 9219 8517 6334 7575 6048 9077 637 6723 9934 1427 2735 4802 1696 4943 6487 2364 5088 5383 6914 3601 8935 6775 4056 3018 6159 1750 6239 5328 1241 8763 752 460 7279 7085 4386 9679 6161 5023 6401 2446 6449 5487 7248 4496 6781 86 6859 1868 1821 124 1820 7107 6898 5876 124 9409 7625 2714 1088 8866 1477 1839 5677 5107 8924 6414 4785 1436 1436 7537 3882 4236 9376 7481 8732 6156 3918 1942 8024 5738 2066 6195 9196 8963 2070 9320 4723 6047 2033 5810 1264 9861 7649 6940 4968 2924 3353 6104 4359 1141 3641 8240 5376 9368 5720 4107 5523 9638 6049 9898 1727 4466 2445 923 3428 4514 6594 4503 6912 8626 312 8175 4839 4312 5114 6158 7235 4819 8613 1594 2311 8605 6185 7686 7972 8257 8145 9847 7894 545 9744 5972 5010 8540 3246 4789 3054 9839 9291 9965 4817 5955 4492 9655 266 9605 2164 7501 775 776 5446 3085 9381 1630 7123 7352 9886 5267 7198 4131 2163 3294 6455 7172 1833 9700 8312 1238 9539 7603 7555 707 9909 2046 6713 174 8002 8876 4026 5129 6003 9471 4565 5383 1101 1687 9087 7338 3305 2636 1469 5467 2281 7923 8990 466 3974 7302 8055 9864 1256 5609 570 1164 4006 7282 7689 8360 2509 1715 9840 4864 1185 4404 246 8637 6091 5684 5975 5747 4672 3795 1214 6952 8069 6555 3769 8394 3856 1824 8258 1463 3784 5179 8978 4142 8813 6667 2501 1321 8381 2340 6184 5917 3095 2782 906 9185 4817 6880 4932 9488 7026 2497 2792 1446 9051 6560 9839 9259 8383 8096 7073 2167 3275 6051 6308 2087 9069 5160 9759 3801 3851 2295 9717 6945 1428 6974 2482 6244 3853 3765 5732 7230 2613 8523 8675 1663 5082 8514 7273 9817 6609 4346 8335 6235 6748 994 4673 5816 6153 4432 9616 6355 3078 5684 3299 4505 2658 2132 748 2862 5896 2831 92 4860 7705 5118 6523 9139 3631 147 8955 6592 844 3641 9178 7591 4634 3851 3406 7138 4634 9373 3492 7711 1409 3142 8567 418 1626 5666 9631 3873 8497 6074 8733 6201 1192 1607 1691 1174 1753 6997 7765 2597 637 3295 187 5270 7145 9945 2407 8130 5669 2250 5840 3429 1744 4406 3846 3369 71 9829 3593 4919 5902 2325 7472 7093 3931 9162 4619 5684 6159 8735 4632 6795 2029 4818 8417 9173 1114 7175 3654 3135 5777 9493 6563 3872 250 6761 3592 6673 6589 7184 7943 2490 9509 5414 5935 3439 928 6905 5474 3438 5639 105 6584 7668 1275 1352 3192 8740 8527 6846 1874 655 2690 8437 4526 9292 5197 8117 5964 8137 5300 258 6978 4808 2024 2912 4599 2951 9816 72 2740 1807 6529 9323 9474 4155 7027 9017 2894 5553 5862 4768 6207 4904 3204 732 4195 4752 8848 6510 9240 499 6767 6217 5307 8790 5481 6257 8092 1648 2680 7183 3454 9208 2858 9279 3362 9884 8296 6256 1788 509 7375 7994 5412 6930 5077 9606 1681 276 2467 7272 774 9234 3488 2432 4375 5320 8688 8819 6968 1368 2353 6773 575 5210 6052 289 5093 699 2896 6880 1207 270 1225 6619 7199 2653 2576 5231 2928 5043 2502 3702 628 2341 2485 1354 7661 1173 6524 980 2540 8877 7752 9466 4086 155 6106 5531 853 9001 8762 2060 9270 6339 5030 6468 8991 3957 8050 1919 5351 551 1972 5978 2892 4456 3684 6904 1980 207 7883 871 9083 5634 6689 9521 5789 2794 1403 2993 8147 164 5052 3768 6502 6433 236 1845 390 4637 3763 5740 5188 2086 8070 4431 2893 1753 1334 4873 8311 9216 2095 3746 1201 8783 9618 3341 7929 1020 6334 6075 7535 7737 9842 389 4170 6429 2233 911 1066 2347 3002 2605 4432 1071 7035 3676 9175 4720 8548 7486 3935 6995 7583 1487 5777 7200 4828 3705 8219 7513 6131 2105 1601 5973 2493 5770 8753 1077 3032 9818 3423 6034 2422 4206 3456 5808 7882 2631 527 2781 6468 813 9775 4050 2300 5552 7601 3479 5608 5819 7343 1739 4275 8943 4063 6768 1065 2815 7844 4096 8985 1267 6481 7758 1824 9937 3566 9705 8919 444 2486 5386 1257 8612 5787 9908 515 3387 9738 6123 5557 7080 4213 9831 6022 8275 2950 3438 7441 794 3886 6425 8412 366 4183 6587 6654 4100 6292 5572 4543 5129 7309 5799 3740 9447 2058 4255 9185 1795 6729 1093 8874 941 924 1248 5567 225 1037 3007 1018 4922 9432 5781 1640 9966 2368 8293 4065 5011 217 8607 6491 3877 758 230 9676 9167 836 8860 962 3916 9953 6187 4856 7228 3786 6774 7452 4823 9781 4822 9744 5564 6954 7735 5529 5673 2380 9593 7035 2596 4551 3525 2824 1660 107 2499 827 942 7711 1788 4858 4015 4326 6065 1242 8112 2839 5045 2934 2619 9866 9029 4534 3172 6764 62 8844 5495 6006 5879 8090 6908 9403 7265 8568 5861 6116 5746 6803 178 3885 8012 4192 8210 4076 1785 2673 3266 6829 5606 2236 3047 987 6769 6218 4102 6830 1413 9596 9187 3643 4037 6095 9398 7653 1014 5258 3768 6759 2060 3945 643 6423 8136 5204 499 6272 7877 116 3101 9834 2352 6147 820 9120 8716 1273 2302 6480 868 1488 123 1256 3934 9520 8909 4947 4777 2676 1705 3189 2973 8699 9611 7460 255 6461 3732 8131 6577 6832 7964 8928 9330 5136 4399 4397 6408 6700 876 3628 8188 998 4883 2121 6869 3791 7068 7998 2819 5124 1186 5791 175 7148 3250 429 9961 3333 4911 2889 6516 9226 1816 2197 4361 2566 6593 7121 9266 3821 748 7453 4818 1982 5925 8039 2125 9344 6036 4943 820 7221 7085 994 720 6686 7774 680 19 2684 3568 6534 1909 1735 8731 2622 4301 5323 9742 3566 5495 6841 7370 6665 5174 3294 4703 7298 8990 738 8592 9809 4310 5676 802 1381 2362 4927 2061 2380 7610 1980 5265 5870 3715 3995 8491 4367 5670 4584 4284 1164 7776 1653 7828 2950 1298 8882 6599 287 9619 5191 95 280 866 7248 1661 9579 2174 3721 1958 9783 2052 7223 2005 5766 7569 495 6484 3238 1431 767 754 9206 8771 4933 8507 69 3815 5106 6707 9785 296 6802 65 7513 401 1725 7092 2575 1797 5401 8709 3848 8975 713 5966 6544 7560 2449 6133 5342 9568 3238 899 8338 8171 9406 4758 1985 4511 1465 1769 1158 4618 8185 8670 5018 9909 2113 3944 8057 7514 2653 8257 6488 9717 4222 3031 3628 3022 5516 5321 2589 8753 6220 7279 6923 5625 2036 5259 6487 3500 7028 7644 8117 5212 2665 9487 1473 4778 3430 9529 2291 2434 4137 8778 8503 8358 8161 8482 7732 3676 3803 6672 2428 22 3950 9351 1998 5986 961 8484 5837 7988 6127 306 9552 8791 9792 7376 9920 3221 3256 2210 2007 7393 7340 509 2102 5500 8990 9833 9175 2792 2857 7954 9165 6806 3656 1162 9143 4617 9645 1332 8956 2123 1637 8507 7266 1428 2234 7185 1000 5490 5747 9358 2882 3086 9866 4983 8585 5208 1168 4111 7999 4024 8416 3516 7181 2072 4677 2676 3040 674 4007 1995 2796 5643 6854 6413 3422 9087 9950 773 928 5696 131 3809 8781 6348 5144 3717 1555 6311 4179 5906 6686 2594 9421 3866 1017 449 2893 408 1122 6899 8755 270 8893 5608 6682 8666 1046 6631 9439 1974 2326 5921 5782 7458 8620 7277 1174 175 9939 1704 2432 6624 650 8204 6842 8018 8652 9734 8426 9774 6633 7180 43 1877 9139 6724 543 184 9707 6333 8509 2032 8605 643 5842 7224 7919 7015 3750 7858 5071 2533 4481 5720 736 7674 89 9388 7408 4866 9161 392 2045 5555 2268 7535 2278 9162 7719 8336 1846 6227 368 450 3221 6209 4026 1140 9575 7775 8997 997 6660 9829 3068 7395 3855 3157 6782 1262 8022 2294 8005 6419 7848 6624 3953 6478 5786 8023 4813 7631 602 5180 4433 3822 7740 8458 4961 3667 2584 309 4663 9243 6490 7731 6638 344 887 9771 7957 5260 2065 2313 1678 9912 8936 5631 6389 1073 5 1202 5056 606 2733 9488 4428 6825 7945 5740 491 6880 6049 5153 2475 8890 2883 9112 5585 121 5234 3541 5381 7298 5853 3410 3562 1140 5392 9950 2213 5397 7503 7268 6002 236 6755 6781 3412 1051 2521 3902 4282 4921 9054 6756 3810 8289 2219 9394 4761 7453 9286 6493 4750 1490 6255 4663 2629 1646 4613 4841 7042 8467 2108 9396 5054 5214 6176 8465 2616 5048 2366 6898 6320 7772 3653 129 2412 5872 5874 7172 3324 1511 17 4425 3000 6271 9088 1981 7916 52 6821 1310 8518 5281 7057 9924 6846 9584 8388 9462 4632 754 6359 951 4877 11 7432 7288 2234 9657 811 1909 7520 827 6334 6871 3449 1773 8851 7717 1824 2024 9026 6693 3656 6082 6616 501 5665 1356 6314 6648 8461 9024 3951 3337 5387 7734 6976 7620 7390 7786 9529 4909 4965 2214 8132 4765 3986 6982 2481 2161 9005 1506 5205 9012 3939 1821 9513 5956 9528 2178 2603 7988 1202 6553 1324 6588 4286 8299 4207 8028 2436 87 9288 3752 2300 7419 8517 2637 753 997 4797 6109 8855 2 5121 2793 8174 985 5100 7701 3162 7703 2040 4363 607 3363 950 1245 8013 1509 5624 448 1595 1263 4200 3895 5034 9068 6531 5786 64 7680 1894 5270 4033 7014 4415 8558 7998 9514 2610 7512 3568 4649 1874 4175 8011 9176 1771 2375 684 3746 2822 8630 5008 3373 8876 41 2440 5407 2178 8856 9438 4072 4125 3470 7437 8539 8379 1787 4405 988 9298 7972 5636 7523 8498 9998 6698 268 2372 3733 365 1545 2363 1725 1270 7590 1765 3709 2996 3943 8916 8785 4366 9393 8606 1802 4283 6984 3588 8687 7971 9237 6659 9958 6760 5156 9955 9809 1776 8678 9894 2140 223 2256 216 1492 6197 1981 1552 9193 2275 6820 4329 6640 6212 2935 4793 6846 9918 8381 5533 4241 3969 2191 4198 728 3698 505 537 5473 5534 430 3965 2108 9037 4180 3599 5233 2512 1503 777 1138 4674 5106 7777 7237 4392 8922 4082 4309 3654 9614 8549 7622 8156 2747 8350 8206 9603 5238 30 5136 2019 3994 7244 7407 4526 7194 8991 3389 5048 9768 4527 9721 1225 8655 6957 5616 3928 7391 6276 7581 3356 4825 5203 1512 3923 3552 9717 9877 5141 9746 5012 7159 92 8607 917 969 5801 9907 709 7200 6026 1587 6921 7250 6594 229 9217 521 3971 1845 8102 7327 6669 3304 5190 6943 3207 1258 3171 4699 7355 8182 8209 7446 3141 9125 4766 8941 9031 1827 6140 5057 3413 9412 8658 6 5993 4227 6879 9963 6071 4980 3641 9091 4635 8830 6033 7841 87 9203 2539 7442 3736 7099 1239 6876 6223 2357 2168 5253 4183 4660 6661 3947 4071 1671 3953 6415 5897 831 2730 1967 2162 6370 1057 6796 5200 3441 988 1638 8995 9878 9079 2730 6976 6670 5958 3198 9026 8125 4802 3208 2784 1463 3506 3207 3133 3810 5973 5381 992 8702 7347 3153 5072 4755 9948 6623 8195 935 8260 7189 812 7339 6270 4139 360 2227 7336 9385 6704 2138 8944 9487 9952 2449 9045 9436 6259 5018 4816 7250 3719 2162 6755 5142 6916 3054 1764 1462 3989 24 8650 1152 3714 4919 5291 4073 3498 8978 9809 201 1115 8752 6039 7418 7552 5084 6853 162 6453 1668 7412 171 181 518 1665 3448 3571 3428 4909 3911 9803 9910 5063 9868 1181 6705 3940 4678 2034 100 1230 9501 8851 7268 6918 2755 8703 123 2916 5155 8142 6679 1678 8323 7196 3342 8122 767 3121 9383 4677 2924 5644 6091 2791 6824 9147 3083 7853 1181 3182 9082 681 8385 2702 7598 1139 1404 4072 4054 2911 2214 733 4588 6888 7928 7929 1361 8694 1049 743 9723 324 6387 5813 3115 9562 4960 2549 7415 6140 5730 2848 3172 4114 5549 7121 5252 3305 1193 5658 6215 3406 6390 802 293 669 5082 1653 5715 2482 8748 5437 2806 1486 7601 2272 1047 2560 4820 8461 5051 549 7661 8222 1015 3209 5343 2618 6513 2887 8275 9079 6292 1016 9880 2936 8037 1313 940 3751 3795 6039 5539 6600 7524 3139 5223 8571 2051 42 3383 3453 6942 1043 8027 4308 4252 9721 6926 7116 2607 5200 6195 8898 2568 2426 8185 604 3739 5476 4354 7533 1515 6244 484 9038 5734 5706 7608 4136 2099 991 7589 5392 2033 5615 9700 2636 1687 6625 6104 4293 8176 2298 9542 743 1075 7726 7698 4813 3201 8403 2345 4715 4646 9180 105 6732 1237 7712 867 3335 5054 8455 8727 3439 421 4778 2426 2107 1402 8529 2751 5929 7178 2292 3024 8253 6369 721 3065 9570 9124 1762 636 121 941 7092 6852 2178 1156 7719 1864 6209 2525 6942 5999 9298 1719 8425 7756 9472 6953 507 5401 4131 9150 8424 2383 5519 5496 1799 1440 971 3560 8427 1092 853 5519 4295 9382 6674 8365 1245 9234 890 8187 5233 6539 6257 9 4294 5729 3313 1152 7481 7443 302 2256 6177 5820 7751 4328 3611 8722 7887 2037 6165 8739 7555 6811 8120 580 5176 5717 6166 2417 255 1398 8955 6511 7758 9600 8591 1070 752 6071 4865 1053 8326 7393 3224 2429 1720 6834 7502 9607 5222 18 4697 9129 6828 9169 9708 8355 4885 5873 771 1491 3622 6077 8001 1379 2029 6592 8801 2780 9014 3665 184 3692 7409 9759 6120 9129 2944 3621 5087 8165 9990 9783 7293 6817 5303 7001 5172 6539 9225 2294 8029 9199 4723 6030 577 6751 8973 5729 5882 4338 5745 6065 8029 3154 2175 500 2282 5118 472 7368 3282 461 3502 575 7278 5157 3927 8801 1695 9503 7446 9724 8701 8520 5753 5630 5270 1077 1358 7503 5414 7103 3567 9795 256 2093 294 8889 7210 766 2608 492 7578 2461 7418 4855 7617 1344 7 9312 846 3805 9035 5899 2324 1139 1528 7594 8567 2885 1448 332 6339 5015 126 2946 3459 6772 1834 669 3889 793 1160 1466 3254 8577 2673 7222 6272 9031 6533 3469 2835 1919 9367 5159 9409 894 9104 7975 131 551 8307 6469 1917 4784 9415 5376 1555 7600 6044 5443 8393 3555 3261 7998 8483 5933 5219 1106 4963 8104 4574 7798 22 293 9308 9431 ",
"output": "499999500000",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10000\n9384 887 2778 6916 7794 8336 5387 493 6650 1422 2363 28 8691 60 7764 3927 541 3427 9173 5737 5212 5369 2568 6430 5783 1531 2863 5124 4068 3136 3930 9803 4023 3059 3070 8168 1394 8457 5012 8043 6230 7374 4422 4920 3785 8538 5199 4325 8316 4371 6414 3527 6092 8981 9957 1874 6863 9171 6997 7282 2306 926 7085 6328 337 6506 847 1730 1314 5858 6125 3896 9583 546 8815 3368 5435 365 4044 3751 1088 6809 7277 7179 5789 3585 5404 2652 2755 2400 9933 5061 9677 3369 7740 13 6227 8587 8095 7540 796 571 1435 379 7468 6602 98 2903 3318 493 6653 757 7302 281 4287 9442 3866 9690 8445 6620 8441 4730 8032 8118 8098 5772 4482 676 710 8928 4568 7857 9498 2354 4587 6966 5307 4684 6220 8625 1529 2872 5733 8830 9504 20 8271 3369 9709 6716 6341 8150 7797 724 2619 2246 2847 3452 2922 3556 2380 7489 7765 8229 9842 2351 5194 1501 7035 7765 125 4915 6988 5857 3744 6492 2228 8366 9860 1937 1433 2552 6438 9229 3276 5408 1475 6122 8859 4396 6030 1238 8236 3794 5819 4429 6144 1012 5929 9530 8777 2405 4444 5764 4614 4539 8607 6841 2905 4819 5129 689 7370 7918 9918 6997 3325 7744 9471 2184 8491 5500 9773 6726 5645 5591 7506 8140 2955 9787 7670 8083 8543 8465 198 9508 9356 8805 6349 8612 3623 7829 9300 7344 5747 5569 4341 5423 3312 3811 7606 1802 5662 3731 4879 1306 9321 8737 9445 8627 8523 3466 6709 3417 8283 3259 2925 7638 2063 5625 2601 2037 3453 1900 9380 5551 7469 72 974 7132 3882 4931 8934 5895 8661 164 7200 7982 8900 2997 2960 3774 2814 9669 7191 1096 2927 6467 5085 1341 2091 7685 3377 5543 5937 9108 7446 9757 9180 8419 6888 9413 3349 2173 1660 2010 2337 5211 6343 7588 8207 9302 7714 7373 5322 1256 4820 4600 7722 9905 5940 9812 3941 5668 1706 6229 1128 9151 5985 6659 3921 9225 2423 7270 1397 4082 5631 85 9293 1973 7673 3851 7626 5386 1223 9300 6641 6043 3899 714 2299 6191 525 2591 8210 8582 8820 9337 7733 1156 5995 8005 380 4770 5274 1777 8851 7256 1861 8143 5580 5885 1994 3206 7622 9568 2505 614 1962 2755 1327 4260 8945 8203 3203 3507 6785 2022 2843 869 9529 5190 8873 9909 9959 499 8037 8809 7754 6249 3304 3334 2134 1649 2891 9755 7568 1747 369 9530 4501 8047 3789 9798 6250 6991 3304 3034 5364 2498 254 4893 7687 9126 1153 3997 5976 9189 9158 3730 5437 2461 3415 3922 461 6305 29 8028 8051 6749 7557 8903 4795 7698 8700 1044 1040 2003 429 6404 4501 682 7648 8539 6160 5152 2536 2135 4340 1693 2216 6128 505 5630 50 965 8286 6430 5344 6336 3178 2901 5239 7972 6950 290 5368 7989 2293 5796 744 3145 2830 8391 1683 5341 3542 570 3827 4233 2262 6043 361 9118 8024 6762 82 6310 3191 5426 8997 6368 4678 4235 691 1627 4525 6058 9615 3169 8206 359 6313 7387 5101 4347 2727 4995 4917 6553 5579 3530 8947 2291 2648 6971 9052 9081 9632 8594 858 8628 1313 1887 9215 8356 3513 91 4413 9480 9611 8970 6190 2275 6356 7642 6621 5434 8988 7889 8339 4567 7771 7285 6857 418 607 2261 5850 238 7206 3060 5218 8519 4946 784 6874 8459 874 7638 4290 484 6608 479 2758 9315 4472 5730 1101 3460 3619 9439 8026 1389 3075 1234 8158 3682 3494 359 271 700 3418 1840 5570 8364 2623 8795 3174 9848 6432 7463 6683 9391 4293 5792 5058 5116 1522 6158 8575 1492 1948 2952 9232 5022 538 3741 5055 4031 4099 5326 1082 7517 3517 3003 2232 6140 1797 5405 2339 4581 9219 9022 3971 9863 4813 5380 4978 2686 1537 9905 4177 3484 9208 9760 4858 9745 3500 9912 128 3951 5237 7561 7819 5106 564 50 1245 8712 1806 9935 3292 7376 8956 3615 3590 3769 8994 4919 2806 6883 4823 6983 6718 4031 3094 1575 127 6594 1487 254 544 3075 7815 4714 8180 8378 4763 5776 7089 2920 5711 6733 295 1018 347 236 1138 5692 5154 3944 2574 6329 926 9292 6711 4019 7218 6837 6964 5056 7091 3859 8131 4905 8572 2662 9634 9686 4790 3074 2605 6852 9806 9251 7869 6504 9486 9007 2196 4640 2950 1121 968 227 6764 7678 597 3982 866 7561 9037 7956 7771 3519 9212 6343 2533 5197 2380 7322 8271 4985 4173 4428 4235 2041 7284 73 7399 5831 1064 348 6951 2031 574 3715 6060 7523 4048 6925 5083 9436 1233 9205 2955 444 1899 5487 5641 4279 9160 263 9263 9684 1042 9849 1724 8325 6273 9123 4155 7336 5822 7458 9366 2748 1172 1777 270 5219 8702 1704 4654 9934 908 3960 6729 2807 5798 8721 7085 1309 5335 2699 992 6377 8899 2716 1053 5172 8190 1560 2507 4011 9017 8225 3110 6540 1 3379 8110 5054 5082 9115 1339 5990 9427 8068 5148 5224 6788 2232 6533 2123 1282 3876 4851 180 6591 2255 5351 1132 3814 7858 1495 9182 6082 4604 5721 2434 7983 182 7488 9416 9297 8826 5405 8723 6893 552 298 33 9135 3182 8507 416 7058 9709 596 10000 1963 2298 7484 5777 155 8978 1310 2588 9933 3383 5022 4267 3564 8861 3683 9212 7686 9087 4286 931 5991 4584 7315 1477 4117 5821 1893 7526 5529 8840 7526 7491 1137 1361 9619 7644 338 929 6583 6622 4311 7956 889 4226 6816 4571 3438 854 9 7723 1784 2351 8658 9098 3828 9127 1270 2072 6652 3150 911 529 640 8399 1889 6611 2394 8578 3891 8977 5200 4553 6932 6088 8778 100 658 8567 953 7018 2642 2736 9369 1299 8185 3196 6777 5806 5267 3429 8955 2529 309 9594 7279 2198 2556 9673 775 6446 5001 2326 998 8284 8413 6128 8383 5422 4694 9335 2440 7335 8422 8160 4986 2958 1355 1762 8763 2973 1542 7717 1853 1851 3663 5483 400 6218 5155 1174 9016 6507 9852 6365 4791 8264 2492 3173 38 3538 8860 8829 872 7281 6988 5857 6591 8342 3971 5353 7666 5512 3070 9518 7362 3084 1352 4113 9301 6507 1639 4668 9365 1490 1033 4155 6105 9876 3680 6142 3413 2539 4970 637 6171 1957 2845 2761 6650 6815 4466 4315 2327 3887 184 6040 6970 1536 153 2622 4394 1791 7290 110 9632 4674 4265 5736 4549 4296 1878 4314 6834 3199 4950 9356 5156 7794 8469 8157 961 2934 8824 3287 3172 5359 5678 141 3246 2182 2762 3991 324 51 4101 9955 1076 8365 2043 5625 2660 3920 6290 5845 3470 1239 1552 4977 5384 20 3134 6344 9305 1957 5982 2476 3667 8012 8968 6913 193 1730 903 6869 8132 5003 3175 9208 9719 5217 1184 2378 5488 7473 4574 8958 5063 6126 3934 6798 2497 3419 3142 8154 1727 5475 6981 5394 3486 5949 2306 31 4030 9560 6899 2161 4563 6425 7720 4281 1642 8903 3011 3481 2727 7584 8790 4141 3709 2724 939 2558 2494 432 711 4221 5906 7691 9614 9392 3639 8271 9422 7668 7830 2672 6181 8744 9096 3900 3025 7089 9155 2387 570 8233 9970 5711 2374 31 8434 9664 2588 7280 95 9650 1500 2352 7340 7465 1743 7331 2087 7516 1350 9916 187 3882 5012 5635 4134 4388 2723 3288 6774 9644 1520 6743 5355 245 3125 140 6260 2064 7419 6354 1713 5270 8706 5405 2734 6800 2735 4820 4316 436 1088 854 670 2451 6488 4803 6838 5563 8090 3611 5206 5961 6705 6912 2558 9830 3404 8817 1893 822 1523 3606 2444 6580 5362 1529 3379 4448 2701 4046 4883 3788 4900 5552 2590 1387 354 9427 6949 4795 3037 8507 7108 6093 5418 9665 5922 8821 8481 4167 5995 6355 4124 8438 2934 9485 6318 6313 3932 9018 6710 5166 9157 1609 7070 1746 2996 7423 1172 6296 8570 560 4802 5677 6653 6572 5341 8926 1744 173 3092 4090 6528 3567 8879 5813 3051 5197 2125 3334 4214 5187 8500 3371 6795 5569 5116 6142 9343 2640 2438 4264 3199 3591 9940 6203 6514 1632 5129 8258 1805 4572 2347 4684 8139 1226 496 7541 6422 8973 7227 635 4159 5726 357 953 7646 5473 3447 3340 8112 5884 7604 7662 5826 7543 217 2340 9175 5345 597 7331 6268 9295 2014 758 520 8861 4651 3293 7833 1877 280 1991 3954 636 9296 1599 6108 2742 4938 571 4977 2541 4585 802 84 4801 9493 5610 6497 6441 2940 2764 5736 1305 9874 2607 165 4524 2252 4350 2752 2531 6340 6705 3166 1987 8303 5626 1080 9592 2548 2408 8485 7132 9562 4920 1932 9054 529 8428 5495 9820 7544 7582 1124 3769 188 7640 4644 2439 1989 7395 1321 4681 4099 4487 3019 8753 6464 4099 4696 9011 6506 3180 6143 6067 8099 4426 1473 4979 2854 6967 4798 6749 4548 2273 517 1087 9913 5160 9878 1901 2554 1198 2933 3004 2036 5952 8108 8499 50 9155 3862 2907 2335 4 5326 6785 4429 6798 1764 3634 116 6561 382 1015 5186 898 2101 5098 2409 8330 3350 1314 5880 2635 4317 7915 8586 8776 2766 4987 7931 6627 7893 6617 6630 9570 9753 7410 6367 1516 7396 2834 4429 7777 3848 9614 5027 2301 1063 3787 630 764 5101 6509 3398 9417 776 1983 4545 3541 3321 8827 6519 7566 1795 9500 7135 1547 6909 9854 3063 4304 2687 3843 8433 6535 9808 9811 8835 870 3597 5816 7985 8697 2325 1383 4466 9452 9717 5362 9344 3038 4188 5862 603 5982 5361 4089 3880 8621 3942 3294 2925 6629 7136 7709 3163 6943 3871 1997 4164 7467 7812 8501 2516 6488 6235 3333 2291 5951 8694 1634 5340 2881 7495 2294 5214 2855 6383 5445 1476 324 8739 752 6952 5874 4812 6466 9169 8682 4814 9684 2500 8978 4536 5015 5465 770 8347 4108 3073 3392 5741 8412 2624 9588 7058 7837 8794 3440 3282 6621 115 8372 7372 3419 597 8535 9884 9765 3568 4698 5801 6068 3675 336 7434 5491 7458 2133 5950 530 5524 1691 5293 8148 7630 2350 2336 6423 2141 1969 3044 2256 340 6767 2026 937 1654 8261 7053 5221 2958 9205 1288 2984 9541 8722 4827 6998 7206 7128 3879 2729 5170 9171 7228 2799 1521 9564 9222 3661 7884 8617 2268 8224 5383 4293 5512 7036 2554 2564 8609 1863 1769 9896 1199 7661 4969 2377 1010 2174 9504 4888 1255 4674 4058 8482 3824 1930 4397 3045 1943 2281 8013 4210 6856 9748 4855 2367 3135 3760 1282 1743 1974 9402 1639 3172 3414 2959 1900 4423 1485 7756 5662 9091 8781 6072 3924 2604 8001 8321 2001 9943 6953 13 505 3808 9760 5359 2526 2895 9118 159 4637 1091 9561 2627 615 2974 1938 8866 3749 3422 6621 9410 8864 5401 1833 2787 8005 9834 7459 6357 6128 4411 6369 6632 4570 6129 8342 3447 5375 7459 3606 11 4902 3166 8990 1868 2491 927 733 6239 700 3706 2001 9563 5458 3833 2349 3462 18 9808 6170 2498 570 2539 9129 5140 5019 7471 8586 393 1281 8543 6755 2534 1708 5744 4401 551 3022 1486 6789 3721 5191 5141 9635 648 5326 1984 462 1695 8143 6631 4192 5064 5521 3321 6555 539 7143 1493 931 8423 35 7686 7309 8095 9781 1709 8645 2803 9546 1785 6523 1088 6926 6158 1736 8603 4493 8549 297 8987 1531 841 4050 7052 513 6957 7590 7655 8449 4873 2429 8483 2558 6089 6577 2338 7798 5221 5140 3695 7006 8015 4783 283 524 2870 5237 5016 1418 1885 354 9300 2725 755 6351 3237 7711 293 7243 6159 5165 6024 4642 7722 2112 7570 6411 6261 2791 7903 9956 6148 5917 1090 2782 6440 3959 8018 7807 5376 9902 4512 4675 8979 5266 7378 8567 2977 7670 2162 9135 2834 4537 128 6907 3000 7698 3317 9261 6840 7571 5568 2987 3487 3009 5768 6278 6967 137 436 8694 38 4947 9720 5368 213 7097 3935 9541 1118 6096 8675 3951 632 8803 7209 3631 2852 526 9243 9691 4448 1162 2677 7935 4170 4796 564 1136 4932 7352 6181 1321 2298 5901 6689 8862 2997 6975 8402 4115 3070 3429 4417 53 8583 1626 3683 1434 8503 9278 1124 2950 6791 152 7236 961 4947 7800 8448 6230 1503 4629 7550 3800 529 590 9014 9877 7564 3767 3991 6985 7195 4760 7037 5777 6385 7072 7210 1239 2701 4685 540 9491 4836 7776 451 9782 1927 5251 2363 3429 9879 6265 3580 6759 6854 8945 6635 770 2712 6978 4106 6258 1737 1143 2035 4473 4566 5596 5711 7266 6633 6250 3108 1468 377 3559 7602 2303 5161 9964 2083 5039 6228 2015 1797 9434 959 8431 6555 3670 5408 660 9928 3496 1802 8314 7968 2719 261 30 6336 6893 2632 9444 4713 3008 9354 2314 1663 4514 8629 97 9552 4857 2111 7700 642 3070 2482 7196 3091 7890 7855 9370 7737 6009 7683 5705 8727 4296 5734 1415 1188 8365 858 2252 7725 211 4565 5739 4724 3194 5835 627 4402 7946 8326 1395 7367 807 8590 457 5048 2796 9827 2785 8804 3861 4841 3883 8156 574 1649 5696 5291 2506 7947 9367 9068 8864 5105 3791 8409 7291 769 9162 5236 9094 556 2602 6252 9145 9411 7652 8292 5589 436 3448 9449 5276 3682 3957 2201 5330 9652 3843 7835 3950 9561 6902 9165 4665 7044 7573 1956 7812 6734 3543 3257 3641 2497 5860 9137 8259 3511 7429 3847 298 876 3295 1925 4557 7251 4126 9886 3254 4320 4072 3556 3881 7325 2720 4897 4368 6645 3204 8531 9730 6747 1787 3371 5595 7646 8859 3853 7509 6287 7699 7806 3514 7345 9731 4422 948 208 659 4201 879 4730 4108 4759 2054 3180 6008 2773 6176 9211 1303 5905 2309 9441 5627 7903 7087 4486 8107 947 7124 5805 8752 638 9502 4834 1411 449 1393 2070 1001 2272 3151 5109 3382 1557 8288 9389 4329 4463 4952 1984 6719 7260 1424 2346 1515 4862 3183 5973 5808 6658 8130 912 7295 7631 5745 5058 8079 7138 7127 9079 5761 6629 4187 9142 8185 8826 4883 8866 9640 9834 849 6359 3445 8624 5056 1311 3486 4590 7284 5645 1247 5413 6556 4894 3043 2301 9951 1121 5790 3429 6551 1550 57 738 7043 8242 5915 1925 3459 5555 8110 659 8265 1555 9282 3320 9217 9119 4261 6500 4764 5507 8264 1319 400 1306 9971 6702 8778 2112 130 5329 13 187 2418 7056 4780 4684 8980 4590 238 7090 5248 4854 4996 881 4525 4212 10000 8785 712 1115 644 5327 8785 1043 6633 5108 4097 1762 7219 4226 3442 7232 764 2211 4287 1895 6895 9618 2836 3484 3059 8083 8338 8054 5316 9214 8618 5315 7999 5681 2781 8642 1007 1565 6036 7639 3024 132 5753 243 710 5546 3826 7825 7757 4464 6072 1003 4081 8907 4486 3492 6990 9175 1545 8657 8389 162 3971 2739 5842 3103 1380 6849 1019 3767 839 4043 251 2943 4285 960 8489 4462 5136 2597 8925 1207 3599 9357 114 4436 2848 3455 9963 745 2111 4703 7258 2433 7441 9452 1887 5172 6300 2905 5290 3490 6947 5540 2785 7583 2851 1273 2044 7987 3869 7320 9193 3819 6677 5658 8254 5876 5464 8216 6620 3926 9270 3878 2710 6710 9681 4596 8233 2332 7501 3523 5821 4447 5414 4957 2030 8265 6229 425 6251 6449 7745 1795 6619 773 3805 4873 6648 9268 9440 9620 3194 8710 9849 2255 1771 9529 6851 6356 1860 4351 6230 4032 5149 1643 8989 7178 9907 1569 3955 2509 4370 1699 4304 988 2471 8108 2212 5470 3727 8004 1441 3272 3065 1289 5527 1187 817 2377 7542 9028 3079 123 3060 8227 1766 8400 5405 8024 9968 9359 533 689 7409 1188 1677 6231 9295 240 8052 9373 8243 9493 2645 1307 781 4523 2494 7950 6899 6387 3329 9977 6510 6388 8203 4627 1139 9959 2650 7459 5669 3182 8147 9429 721 6175 5659 15 6415 63 5740 4657 9555 4736 2316 335 9258 1161 4636 2508 7547 7965 2484 4056 704 7038 5034 1843 3349 7684 9301 5369 7217 7447 1150 7938 3622 3160 4304 6388 3222 43 1044 2776 4778 9711 9463 387 871 4098 2894 8418 2062 1729 8825 9118 8767 3859 960 8467 7894 260 187 5110 4058 1336 3047 4031 4496 3703 418 7717 97 7814 493 4875 7524 6307 5261 8395 404 4507 3164 8818 6235 8340 7935 1353 8550 8894 9819 6443 5505 6 7905 5914 7693 7303 9945 2188 1005 362 6257 1102 4527 6749 2328 2051 3055 3940 6797 9810 8446 6312 8627 4681 1003 2913 6033 9553 8158 2204 2347 3662 8561 251 5928 6253 7554 5872 8441 8558 2585 1049 6011 7112 4149 8338 5514 3555 2278 8662 3364 7075 1325 8343 1755 2327 1255 4140 1879 5765 6343 4226 5778 4903 828 1705 1155 8381 7576 5947 3291 161 6995 9301 3624 1143 3991 5489 4697 2620 4150 4413 9694 1826 2755 1449 4152 361 5588 2383 6125 1930 2960 1903 3184 3787 3607 4338 2168 7535 6637 1810 4047 3631 1110 7670 1126 1452 3158 2174 4071 3659 6586 3765 5484 9340 1565 5987 6053 3504 8369 2177 5433 1328 431 4968 1467 4038 9305 3634 1572 2293 1795 5618 2276 9256 9639 3401 708 9148 5574 4778 9158 2160 4894 993 7851 6458 6979 3903 9961 5348 2432 1745 3027 2862 6712 4493 6899 2369 4478 4822 4661 6272 6791 3288 1880 2781 6688 2587 8280 8614 7364 7437 7125 8610 8429 4975 5067 1760 5230 5028 3459 7661 6772 6485 6874 9836 7330 125 2204 8159 4946 3216 783 8089 6504 2662 869 9543 5248 5501 8156 8963 2937 1632 7572 7718 2959 2639 9477 8188 4018 2935 2200 7141 5771 9073 3328 9452 9197 1883 7611 495 5099 8393 8583 7954 1054 5803 3848 2653 7655 8356 1615 592 9987 5539 4661 2945 4529 489 7484 8546 3423 6035 2038 5545 5108 5366 4997 656 7248 2607 1150 8698 7351 6084 3003 8404 8239 6851 1056 5893 5206 9022 2836 5192 912 7496 4489 5440 7984 8324 337 7758 4359 8727 3303 9466 4092 4651 121 7691 3609 7623 6389 959 58 9391 9362 8296 6241 6769 541 7798 2142 3376 9342 3054 7224 3830 4845 1559 2153 1534 9317 6511 260 8971 2328 4351 9973 8801 2041 3581 2775 4781 4539 2832 4172 3900 7480 6764 7020 8020 4562 5513 7747 255 4918 4970 4084 9763 6529 2588 1296 2197 5451 1555 1167 4130 2257 1139 2930 4297 4719 2056 5430 5609 4888 9601 9508 8719 2716 2879 6738 3629 8391 836 3883 3309 5806 4318 9423 8686 3258 7070 882 8708 8624 8400 2837 880 5890 2119 1528 608 4174 6957 6216 5413 2909 2075 4131 1977 1305 7220 1957 6047 8056 5840 5707 213 6509 5129 8898 9766 2198 6131 8473 7173 4530 7662 4404 419 6132 2284 7378 6657 5592 9945 2070 4853 8371 2552 6829 6027 6124 8785 2073 531 976 7780 7095 7485 9260 5992 7250 7810 8474 2075 4982 3003 9736 5738 9773 5867 8021 3502 8875 3612 3446 944 4816 8168 9848 1644 4194 2323 6781 2618 9205 4108 397 6299 1592 6009 2290 5194 3818 763 7268 5151 117 3355 888 6241 5573 5260 9742 4447 5224 9539 1743 39 7706 1590 1683 8251 264 4815 868 9468 8922 7617 5766 6866 3625 4407 2059 7442 1521 9326 2592 7989 2680 9832 4229 8252 5091 3970 2698 314 9860 792 353 3917 8733 8387 2167 8996 3201 9386 4815 8474 7002 580 5339 6978 1338 7397 4419 2858 3074 3363 846 2105 3194 1426 6708 4636 1747 9406 4950 1606 6549 1654 1874 5282 40 4040 4277 9592 9778 9092 8065 3131 6023 9756 109 7361 7152 4527 6570 6578 4241 7416 8682 7434 5193 5390 2070 6940 1147 3371 4897 7695 5024 6771 2976 1415 7162 3605 1006 6939 2696 5422 70 5070 5177 178 2430 8681 1056 9000 5258 5297 2767 3939 9082 7959 5680 7503 1250 6826 7225 6147 873 2248 2917 3848 3662 78 7452 1019 7017 6499 6441 3438 1569 1617 9967 350 297 1022 9349 1906 2670 8467 2197 1752 2778 7876 5606 4027 1054 2831 173 1926 1430 3089 5773 1444 9519 9577 2462 2887 2427 8902 6324 3995 6871 6290 697 3519 3663 6397 5425 6333 4864 7621 4436 7641 1848 6393 8019 2901 9223 4544 4826 7005 3984 6951 8448 3502 2879 909 6388 5305 6163 9063 5652 3033 5352 6348 2903 5367 2744 8327 8051 3959 2299 8838 7951 499 5230 5970 3399 805 513 4577 7809 848 7879 6256 4350 7109 7164 737 8765 9678 6152 4416 2710 7855 7115 5613 3221 6211 291 1271 169 8942 108 4472 9440 1690 441 9190 2494 7305 118 6654 8152 4348 2909 8853 1456 6424 5942 6573 6102 2093 7340 5163 9947 4455 7127 9520 7017 3770 790 7185 2711 7250 1656 8502 5291 8448 4043 7784 2104 513 789 6608 1212 3697 1812 9020 6472 7753 5592 8925 6197 2931 4088 6144 3737 7566 5663 753 1335 2804 4290 397 6405 2297 8898 1695 7097 9293 5830 9200 6157 6618 2159 7368 6666 323 6387 3138 8075 1978 2062 4272 4909 2501 6767 4997 67 8781 5750 1401 7936 39 1798 4341 2335 7047 2387 9431 2691 8217 4983 8847 1186 3493 6215 7852 3815 8953 7341 8242 931 5754 8865 2191 8255 5631 7187 4673 763 9288 6073 8698 9326 4222 9390 1661 7621 1777 7443 311 9993 2425 5510 7530 2270 8076 5381 6084 7028 2721 4325 4310 8475 3189 6500 3081 5171 39 7753 5933 9326 177 983 8652 4399 372 6664 8371 2148 458 5033 8492 9235 542 6022 1504 8617 7754 3939 1997 6827 8264 6306 1653 7804 9158 4733 9327 9196 8837 5259 8521 9013 2593 3524 9763 2965 6539 8133 1464 3349 3166 6308 2583 59 2329 438 5028 6434 4376 7024 3260 8991 3329 4912 3147 2486 5996 2473 8033 4832 4083 2906 197 6676 6429 9959 9640 9320 4444 7455 2668 3961 3762 1602 371 2442 2039 5398 8876 6414 2421 8487 1757 2102 3399 4903 939 5746 7375 5324 6930 1457 8229 7126 8132 1009 3436 4123 6680 4231 1578 9347 8191 1691 948 4914 4133 9338 311 3008 5752 9084 1494 7508 7537 1244 2410 4827 6990 6136 150 3919 7592 8378 7396 5724 5739 831 6198 2418 1414 7775 8117 5956 9466 5416 869 9950 4754 1180 2957 6857 6615 802 716 4151 8398 9477 8977 1739 5612 9127 2009 3203 3856 9404 5278 9594 6586 1476 2012 7999 5602 128 307 1419 5543 1175 1368 6648 2354 4324 3504 8968 1478 4219 9470 6227 3695 8447 7965 9306 3925 9973 8861 7780 5728 4138 3726 8665 1965 5737 3016 7567 2216 3322 8985 4110 4496 353 758 3202 1028 4261 8521 8857 4832 7991 5083 8526 2789 3047 4184 6713 9371 3044 4492 1450 3533 8217 6467 5498 305 9482 3064 8872 9155 8400 2982 2 8752 91 3203 6132 703 8076 4988 5534 6066 71 412 5206 9469 947 1918 5192 3990 2761 2993 3874 7330 9459 9371 7634 5292 8786 2858 798 3538 2191 800 2289 2281 354 4772 9335 8429 9760 1221 846 6182 7984 6051 2002 8930 4320 7193 9271 7081 6538 3144 4410 2348 8867 8395 7640 4004 7604 4789 7541 9794 5588 6182 8426 5942 953 4113 722 7064 5333 1568 3245 3316 3970 5247 2245 8290 8791 1515 1722 5328 1010 6131 7676 9876 877 1667 232 8481 6455 7772 4626 2043 305 9404 4336 1258 3516 5057 4673 8848 2976 7918 8515 6946 3164 759 1587 1954 8625 3308 7282 9634 5790 1309 5862 3018 2975 6093 7850 9429 216 2476 7823 6873 8231 2158 4482 1746 3567 9154 593 6542 7071 5459 9839 6586 6217 1425 8540 1193 1084 2173 7178 6873 9833 3039 6243 2807 5483 4092 8587 2051 2919 6410 8923 1149 4919 9756 9246 8485 8909 6190 1379 5980 1648 1217 2565 4216 8994 7456 5408 77 5980 2586 3302 5812 1976 5896 4970 3811 9987 3557 2213 9258 6318 7487 6758 1236 7242 6004 6073 6150 2193 7451 8481 3841 5019 7398 8056 4012 1205 9816 441 7185 2401 94 9348 728 5989 4318 4538 5975 7874 3102 1584 4191 588 8342 1778 7829 697 4202 331 2889 8004 8811 3081 3023 2560 1137 3386 3765 7304 178 7301 6056 271 6648 6783 6259 965 7673 8586 8838 774 169 9380 1362 4862 7510 9190 5558 1711 9520 8447 6067 4683 7879 9089 7242 5367 8826 7358 2670 9004 4658 8725 5626 1306 5508 1885 2270 9532 470 7460 305 6990 3191 1666 1852 7052 7208 7409 8763 3079 2207 4829 7761 86 269 1355 5452 5446 8712 8122 801 3370 6846 6427 1027 8705 4663 3296 8236 5132 7107 8541 2121 6650 6558 324 3701 117 7733 8815 3196 6291 3643 7308 6376 263 5014 8180 2061 78 6301 2861 3447 9498 5639 825 4555 301 472 2790 5432 7579 7682 3905 580 592 4228 4280 708 8312 3095 255 4603 3089 3915 7330 9704 5280 5509 1764 5357 8161 976 5155 4011 6615 5979 8565 6915 6451 1354 8699 381 5388 8955 960 5979 9534 5239 3038 7846 4685 9645 8800 7774 3559 6129 3829 8838 7990 5592 547 6150 2919 5701 160 9533 1680 8724 2800 8130 6430 1498 8510 1817 6804 5821 4147 6337 1059 7184 534 2096 6828 9333 6221 6738 1814 49 1928 9803 1992 2474 2304 4910 4526 2464 4443 6205 7539 3594 686 320 1443 5547 8488 8246 1367 2634 4582 8778 6170 5116 873 9349 800 7093 2439 2613 7141 4366 2415 9132 3191 1071 393 7716 3534 1187 273 7424 4780 958 4096 6222 6505 2583 819 4223 1569 1753 3000 4090 3220 3872 9790 4019 7316 2228 2984 4456 2945 1750 9939 6135 2820 6684 203 2705 7870 475 129 2650 7784 4224 5223 640 3158 2394 4863 4726 4146 4214 5167 7365 4438 4957 7735 1753 7184 718 2561 6481 2468 8851 8967 5287 5534 9169 7992 3404 5995 4472 2405 3779 5047 3979 4418 4556 6372 9280 5634 6869 3494 800 585 4283 5756 8320 6035 9292 5389 8595 5772 4208 3798 1090 9495 9331 259 3838 9086 2605 4661 1490 6383 6059 1821 801 614 8192 6432 6247 1413 6277 7047 1997 559 9154 6668 2946 8445 2057 7892 568 6264 1689 8010 2110 1020 4620 2299 6457 7224 6959 4299 3607 3017 6119 759 9983 662 3542 6229 2074 9819 9627 4071 6729 8781 738 9674 3577 9146 7566 497 5410 9254 8506 3871 6625 3125 6170 9434 348 3128 3732 306 2497 9850 1064 2479 511 958 5059 8937 776 4686 9359 7504 3466 6448 3530 7042 5594 1095 7538 7355 6700 2395 1225 9677 5519 3746 9110 2219 3226 9193 2524 5722 9042 9940 4552 5904 897 9610 1192 8024 4295 550 1879 4112 6998 1760 1154 2591 2854 5043 6297 5906 3790 3873 1934 9308 7619 7395 7878 844 6587 6754 2917 1980 6693 7468 7883 3941 3429 9075 8316 7724 5976 6546 1835 2973 8306 9340 1915 7511 735 8211 3416 4524 8436 1701 183 6054 9095 8061 6897 2033 4814 9813 4012 7858 3632 1895 8150 7060 7321 2817 1135 3296 9362 9322 2621 7667 5013 887 5178 5747 5450 4945 6622 3885 6646 3157 9938 2092 1217 3186 4125 2382 9350 4488 6591 2981 6382 1092 6392 54 3908 7527 9702 3269 6848 8674 7288 8212 9560 2465 311 5009 3761 6932 5245 6758 88 1534 8850 7656 4719 9326 6389 4068 3813 2979 3400 6547 4070 9792 2952 4329 3670 9005 7598 6869 7678 4885 5080 3590 3701 5390 4950 7461 8674 195 4219 5113 1728 9420 9121 6447 5097 5509 6866 5261 4840 6618 1807 5261 6409 1111 9590 6430 115 3539 3298 7793 4775 4729 1382 8475 119 6331 2287 5144 2877 2857 256 4605 8628 5728 7403 76 1237 620 5337 2428 7237 3495 7688 3645 4605 7277 74 4720 7167 9723 8864 1941 4452 6597 6767 922 9279 5406 6065 2156 8262 2672 3112 3242 8400 514 3317 5988 1133 5005 8415 4722 8500 6102 8366 9456 9731 4792 527 6897 866 9390 8838 5317 2338 5604 2590 1617 1009 5006 124 5623 7678 9587 5216 2429 6452 4884 8416 7584 9889 6830 8657 4740 9283 7023 4195 9013 8166 4722 5910 5383 463 4747 7052 2801 6702 9641 769 4063 4647 7244 6037 8676 6830 7604 1104 3281 2487 9519 7216 8727 2700 5873 3466 1982 9247 7661 995 3764 2382 3256 9146 2844 4354 6197 1996 1055 2190 2764 1469 6836 6359 3857 5511 3188 1460 2966 6468 3947 2484 3684 2673 1535 5908 6139 3516 5154 151 4510 8917 8884 7765 8062 8079 8470 611 75 9525 2800 9190 7345 9635 5549 1202 1497 8736 2661 4462 1556 2959 3297 1591 5632 4831 7498 8122 4698 2651 4624 5560 7919 3507 9676 2332 1585 8146 2942 8011 7670 5741 7201 1366 1727 9101 2567 9575 7836 5228 388 5743 4538 3684 7333 169 4866 4830 4642 9564 3832 9265 5123 1750 2771 1150 4082 708 9295 7023 8718 3316 9116 5918 4682 7194 5018 7248 6769 9206 8827 7156 4948 3365 7192 8633 9885 2057 3462 879 7972 3646 143 9446 5395 9266 596 5828 9973 9890 9203 8690 3206 8318 960 7887 5511 2329 1486 8631 7886 6665 5787 9186 6381 2978 7818 6265 1386 7631 7143 5710 1276 3638 5155 3023 2903 2102 8850 9227 1992 8052 4268 1549 2721 5227 5787 4584 3908 7272 3214 1793 288 5352 7330 6668 4681 5147 2933 6067 2778 6427 8128 405 64 3282 3427 9318 1736 8629 8544 79 3032 2812 1627 2105 4390 7413 6688 8297 1036 6253 6442 7676 1605 3771 4343 6285 8918 7275 8703 8047 54 6830 8451 117 6464 8230 5787 8199 6858 4330 8277 9889 7141 6255 1993 1531 19 5032 6179 7406 1285 2620 5081 9241 2743 9424 1877 1660 3050 6932 6058 3103 3761 860 9572 6576 9089 5358 4774 5946 6039 9402 2187 9532 5656 531 7414 5674 5563 3592 3080 3199 2564 8160 8791 5306 7583 667 3317 6985 7598 9374 87 7711 6585 6010 4286 5674 7719 5412 7971 3758 4813 6509 3289 469 7040 702 2494 8954 645 1925 2152 9560 85 7294 4865 4019 7960 4533 1003 1910 258 7442 9620 6843 9803 257 2516 7522 5668 6838 7631 6833 3347 919 3653 386 7972 6146 5691 4968 8071 7842 4528 4507 1487 5744 4877 9446 277 5880 7707 6886 9673 3678 3728 9475 287 2595 3348 5954 9433 978 9138 9131 8248 2790 9516 2571 5288 5206 7539 9710 9399 8418 4216 885 513 9092 6682 7141 1323 741 4027 7347 4418 4106 6822 1056 6701 169 7010 2485 7499 2499 1615 5746 5289 7482 8317 6928 9039 2207 6637 4789 6976 7204 2025 7488 2647 5058 4629 3970 5798 8655 7668 6568 9112 4489 7623 5812 1010 984 4648 8508 3483 2614 605 5123 95 8921 8402 5485 7479 5038 273 4454 8593 2297 1942 1239 7355 2922 1560 3152 7928 9228 6071 7039 68 3694 9203 7429 1029 3850 5936 4511 2816 2893 5985 2910 8165 4386 4747 5644 5775 5019 6449 4367 7316 4742 1958 1022 7663 9869 525 1942 9096 6596 8981 5516 6641 8183 2944 7669 8384 5232 8532 1199 8124 868 461 2640 5254 5207 8283 1028 225 4732 1747 3892 5825 3704 1265 3488 9924 1790 5429 5372 4737 761 887 1377 8943 182 5397 3679 1765 280 4877 6240 1148 5337 8880 2753 6895 7162 132 7120 8245 1878 7363 4070 1933 8628 3909 1857 6769 5689 7228 1505 6450 4466 9233 1744 4647 981 1774 6412 1261 6651 2651 8760 8339 1530 1512 5234 5044 7995 8705 9640 6225 2419 61 8157 7398 3969 6365 4166 6010 9944 5670 2459 761 4902 554 1760 2235 2328 4523 9847 5330 3525 8606 20 5055 6469 1605 6450 4463 6661 2441 687 9080 2502 5196 6477 6470 7912 643 8831 4208 2664 7641 4968 3918 8195 3079 6152 6874 7601 5998 2203 1126 4603 8574 2532 7423 179 8981 8237 6839 1421 8924 5918 3922 471 8747 6744 4734 5741 1926 8941 8404 9567 261 2321 4113 3339 4824 986 940 821 9540 8417 1775 8113 948 9197 8291 9928 3786 1482 7700 9061 3751 7974 9531 2497 1069 616 8237 2994 9557 2993 8912 6169 1665 3024 5859 6489 4009 3150 7309 9900 1566 5436 4365 2513 984 2655 8792 4769 488 2844 3829 4239 817 9711 6735 8237 327 1324 7582 6235 4316 6494 2403 5980 9517 8261 2468 9878 7763 6129 9777 9328 1564 4141 1841 8899 3148 632 3668 3635 3475 7496 4225 643 3559 960 5231 3885 8635 2813 119 2950 5658 8873 5281 5174 3485 4101 1403 1247 6581 7532 575 4496 8024 8767 3394 7523 9398 7061 1158 9225 909 5382 6219 4467 2693 1450 4703 1327 614 1173 628 6271 45 2261 7796 3529 6361 5551 1128 2941 3082 8054 3788 1105 6820 7181 8628 2569 594 6137 8145 7854 7870 4364 8672 6915 2165 3374 4593 9130 4546 5221 1752 942 7481 5899 822 193 1449 1949 9485 4530 2 3272 1987 3173 6804 6966 5742 7397 9454 3886 5250 3675 4601 273 589 6765 3646 5182 5894 4543 6754 3997 5484 586 9896 2658 778 1344 4606 262 2226 960 9885 564 4132 6688 7529 6225 437 3334 111 2038 7008 4711 2311 7597 7828 2308 9130 73 3203 2235 4070 5038 2820 3965 7695 9949 5308 8653 6562 7533 9612 6446 8096 95 9485 1976 6320 9921 5309 6430 1959 8669 7492 621 6265 5319 2928 1746 5392 6130 3980 5813 1168 3151 9777 8862 3099 5084 3866 9660 8969 3477 6105 3416 9924 1941 1744 6243 1862 3404 9024 3820 2072 2867 4440 4688 8186 3719 6433 9929 9849 6764 5741 7368 9914 1869 2581 9364 3304 6447 9023 2272 6275 1479 2040 6198 3420 3783 2440 1633 3538 7815 5452 5610 682 6243 297 5219 6313 3082 1499 2513 9845 3591 9880 6111 5459 8813 1826 5114 1611 849 7386 7885 8679 5777 4083 8450 5911 2874 82 9448 7041 1885 5057 4074 4479 5354 9292 792 4787 7142 3304 983 732 9536 3445 2542 8348 5271 7655 9958 2471 1392 4194 1149 3520 8276 9599 9430 7502 9680 8878 894 7917 286 4967 2395 1991 4258 3186 6777 7751 6490 7760 4834 2377 1204 3727 724 6474 7733 7033 8944 9125 1226 6445 2644 5854 2395 8426 9707 8426 3655 600 6342 3940 5566 8737 5931 6175 1922 9059 3925 4763 3170 5110 7139 4374 8836 4214 7199 6568 1246 2495 2044 8824 5291 4688 1029 7685 9465 735 6110 3119 7686 2452 7058 9603 1188 9340 5777 9461 8399 6053 4224 7920 1162 1362 2293 6349 5576 5844 2916 3173 4690 4960 8348 9980 5999 9376 4016 5463 6462 125 4933 4147 8928 1990 3749 6467 7682 5877 5928 2432 8281 151 351 5794 7864 8996 2142 9791 1191 1410 9316 5880 6369 7663 2211 8719 3391 6226 4181 9852 2702 9113 3999 7982 7454 4099 4448 1487 6328 375 3918 4608 6877 621 402 1093 9616 8895 883 806 304 6550 3037 3024 4213 1599 1742 7603 4176 2274 3806 3229 7738 7804 1210 5192 8255 5658 6678 4582 2384 6948 5541 9261 7568 2294 353 3535 7541 7587 692 7844 4137 3728 868 4701 5326 8961 8655 5853 1235 2460 9081 8972 6616 291 515 1222 2300 3545 2155 4683 492 7695 3943 4411 6341 647 7945 3881 4586 8636 8076 5074 8715 8943 9774 392 4256 8428 6244 5490 7239 5324 4461 3854 1966 1328 1427 4265 4872 3581 8948 5363 1276 9242 9773 3968 6241 4069 7848 826 2704 5923 5899 7770 1218 2024 8161 5473 6803 756 7314 4041 6079 8126 4247 4397 9453 5673 8661 4324 9254 7608 6038 6881 3202 2162 848 9442 6230 5047 267 5285 7321 2517 3054 4890 4540 7566 6714 1342 8321 4027 5382 752 8505 5980 5148 7957 1653 3808 8633 7258 7768 4670 490 969 6832 1337 410 3061 2735 7028 4698 55 9544 7751 4945 4083 1669 1658 5424 9989 2037 7157 7092 541 3137 2239 8497 1141 2399 7129 8398 166 8151 5239 1134 4982 2927 7895 4394 5661 4922 9091 2067 4465 3194 7011 4899 4862 5021 322 1202 3409 3830 8294 3949 6966 532 8797 4458 2930 2278 9207 9447 428 4445 6932 1761 7371 4826 6154 3031 6099 5245 1450 6915 4790 4812 1813 9651 9832 8486 7204 3240 2316 5497 3540 5633 2381 2337 6443 1662 4614 5649 1109 1393 94 4392 3153 3816 9218 9306 3199 1668 902 4648 4935 5691 9459 6747 1693 5643 1585 8897 5234 252 745 8774 2236 3125 1110 8678 4787 2075 4327 2247 3467 772 2990 6619 4587 8559 5924 4137 227 3178 8784 5161 8868 4595 8259 6913 237 9843 5809 5470 6446 6553 4243 8682 6030 1704 7359 7168 3778 8037 5766 3596 8808 8755 214 9747 7314 2490 3883 7540 5667 9019 9052 886 3613 7310 4150 201 3505 9958 5670 9950 2863 6265 8631 8892 4320 2342 2411 4450 378 8176 8045 5538 6930 4611 1636 4243 7100 1870 8134 9118 888 7185 6355 852 847 505 1052 4351 6814 3074 652 9676 9338 5635 4919 3657 7976 7329 8106 4705 5504 2503 242 8786 7113 1877 3028 4212 99 7514 9681 986 4698 2387 8190 1896 2891 9241 6246 6057 2314 6898 2084 8003 2532 7003 1660 6859 683 6117 1563 2539 8619 1805 1324 5731 33 703 6294 6483 8216 2326 7469 9266 1065 5658 1161 307 1250 7407 6363 9916 656 8447 7918 9539 1801 9577 6397 2483 2046 4311 5021 7016 2467 6344 9099 8852 7047 1744 5334 5262 422 2802 879 1486 4811 2040 1792 2413 5798 8155 2328 6453 6601 245 2343 8401 6174 5091 7235 4571 9401 2256 1586 1868 4951 684 719 1997 8780 6052 3611 9201 5206 4489 686 6368 2880 2477 8780 8677 6983 7459 5129 9935 7704 3823 4687 229 8913 1922 4799 8314 4177 2736 181 5479 9772 899 7476 8551 3302 7438 7751 8507 8278 4788 1227 1158 3616 6 9834 599 3817 1315 533 1520 5137 5220 8100 4050 3493 9250 2363 4021 1985 8895 9499 1756 6145 3326 6658 9446 763 4408 4305 5393 5547 5531 6550 9163 1888 2735 9761 5704 4049 6645 3575 5538 8216 1674 5939 1708 923 4653 5728 9260 3547 5227 1015 6043 8552 4025 5488 5667 4784 6144 1059 331 1674 3960 9493 9914 6694 5605 5617 7095 2249 9192 2632 6817 7217 8570 8524 4492 9574 604 3751 3120 2182 1117 5514 7085 5141 1001 2751 9925 3497 161 255 1522 4120 6099 1435 7166 1703 7052 4260 303 2595 3243 7119 9811 8164 1995 654 7737 2598 4404 7208 4779 5521 2721 1863 7013 73 966 6937 3569 1126 3543 1443 1598 9641 2877 8763 7695 6280 9374 7998 5226 8968 1468 1389 7131 3462 2042 1219 2411 6446 8426 3541 8318 7498 5404 5330 7570 2721 2267 7491 198 5809 8933 8147 1802 8161 3261 9496 4441 2634 3845 6018 1601 5313 7406 5083 5126 9448 6301 7537 2245 1078 1077 562 8575 2832 5891 6145 1904 4509 9987 2102 6670 8919 6600 8471 7079 9861 7966 7871 8846 1811 3889 447 7123 7646 1881 8600 7093 8182 2488 5689 5611 9917 6250 4186 2748 8493 6682 1004 9353 6668 9457 6022 1938 6056 4492 9016 5916 2458 3239 4762 4268 3479 1560 7742 1124 3440 2693 4569 7973 5181 257 9936 5097 2859 4121 4196 7703 802 5199 7055 3821 4655 3077 5758 7063 7568 4773 2978 6377 4363 4091 6996 7841 2002 1089 5317 1794 3782 9885 9766 8962 6493 9701 4058 5703 173 4605 3405 7326 9804 460 1146 810 9888 6903 7872 7455 8028 7202 184 8742 7644 7179 6583 9646 8268 8251 1439 2049 8135 7556 7362 979 3609 7771 6682 3781 2375 6438 1107 8530 6897 8604 9340 3136 1859 3563 591 9886 7116 7126 8627 4760 4304 1561 4405 8923 9811 5843 971 4297 3398 4684 1628 7006 2454 8309 7139 4829 4746 4597 9710 7995 3200 9049 1130 5058 8964 8072 1295 6079 5197 6274 7190 5853 7834 1594 4775 3997 3788 2098 4645 3538 6781 6272 6895 9235 4580 4033 415 5678 8629 124 24 8181 5525 7505 9590 4488 5577 885 6918 7125 7158 4108 2977 1343 2053 4104 1691 5841 6201 6336 9378 2981 2607 6272 8567 3539 6657 8981 5568 1637 5457 5591 6169 981 3095 5759 1820 5023 2995 5089 2148 6504 9196 1476 4198 7601 5579 5889 9793 8131 2224 9170 7464 1182 1793 6030 4720 4801 5011 287 2790 467 2229 8958 7799 5324 4716 9618 6698 4062 4706 5197 565 254 6673 4763 4206 8603 651 3998 3086 9226 9519 549 407 7663 6578 1479 2464 7940 8117 5253 4758 346 562 2556 2021 5278 8525 8718 5691 9583 3915 6256 6188 6939 1018 393 1893 8020 742 4978 3597 260 5526 4003 4274 8456 1833 6737 6395 9950 8341 7505 295 8903 60 2315 532 4937 7384 6222 871 1298 8829 7058 4588 6198 3802 6481 569 895 1458 4165 1154 3336 4520 5427 1791 6352 8516 4537 2653 3208 2041 2947 8462 8453 1613 5345 3389 8997 7919 611 6646 6747 4020 1234 9297 7821 4066 9865 5067 5523 4030 6220 5210 8549 7998 3352 1252 2865 7889 3905 6073 9929 3203 886 4733 4816 6231 4473 164 4149 5083 3161 7247 9102 746 6543 3274 4811 6408 8340 6686 437 911 1895 5337 5261 5247 2940 8125 9487 6844 549 5767 6399 1435 500 1214 4017 4972 7729 8165 6407 889 5411 5508 1635 8306 5134 6445 4713 3473 9482 1501 736 1377 3189 5996 2975 6128 472 2461 9324 1021 8227 2074 8807 8726 3287 2823 50 7367 7339 6456 4607 9101 8315 2593 7406 3448 5390 8470 3273 4871 6322 4008 6247 9510 6355 9221 1990 6826 8033 7665 4198 6260 9738 9356 4985 9376 8530 5034 3094 5868 7841 7700 1321 6156 293 8726 9603 2034 3548 9227 6904 9869 3234 9503 5731 5940 5075 7720 9118 3108 1736 3315 9367 1473 9023 703 7200 7552 2089 293 9772 9929 7992 1092 2436 4636 6169 2039 6669 9716 1265 3573 5937 851 9427 1667 3142 4501 5738 2259 7608 7473 1926 3326 8945 948 4029 6144 4851 6117 6436 4622 2397 779 5713 4833 5415 1882 3223 8435 7949 839 8359 3885 8041 7785 1903 1183 2286 7640 9793 6245 5112 1718 9571 408 9017 3599 2903 3868 6067 5690 4841 4815 6469 554 9647 8235 8787 9221 6669 3087 60 5028 3324 4452 9164 5226 5634 1449 2866 5427 7694 7977 3496 7264 8385 8865 7214 7639 2732 3280 3329 7572 4446 9797 4477 445 8031 9615 9665 1051 9054 6076 2430 2377 528 1594 3954 2513 9394 6819 4291 7087 1148 7787 702 5884 6651 7915 3522 5734 7546 6850 9657 8344 6646 486 8788 1028 6452 8452 8431 5505 880 7212 4233 7759 8805 8187 271 4551 5005 4562 1637 2504 8700 8691 8387 1702 2957 1909 3787 6855 5110 9795 5198 8108 280 3985 5487 3084 8788 3917 4940 6019 1129 9173 3777 6285 7359 4048 835 8715 4961 8824 7571 12 3866 5957 8065 6822 4217 8203 28 9327 7997 1577 3786 4629 1913 9272 7712 701 9541 9003 3071 7021 8175 6848 3305 1885 7247 492 6952 2207 5667 4522 8570 9532 6830 6634 2705 1047 4836 2733 6725 9184 4309 510 3812 6222 6133 7875 3274 5673 6878 6344 2693 1404 9543 5998 3289 6789 2841 6592 8995 8507 1113 3916 4390 7942 549 7094 5340 1736 6178 8416 920 487 5277 1083 3060 1410 8958 2685 7082 2187 9028 6127 3590 4923 8476 6878 1711 1316 3469 7058 6174 933 973 563 5227 7874 4008 6918 9609 186 5334 6880 7024 6962 4315 83 8371 3272 2767 1805 1810 8146 7931 5399 3068 6406 8629 4779 4073 8449 8188 246 9382 9160 7160 960 3385 1167 7877 9346 1352 3210 6225 8375 172 539 8457 4894 162 7575 3050 1971 2073 980 3722 1492 3737 2350 2622 7809 798 809 4406 6531 9969 1565 7490 3353 2732 5367 2698 4083 4928 5275 8810 1451 2165 3618 2697 8679 1193 5746 7001 9617 6726 722 1108 6814 9423 3730 975 221 4538 5380 3103 858 3297 593 563 6028 5959 3260 6462 7238 4886 5271 8689 3403 5241 1385 2081 6433 7130 9081 2401 207 6155 3508 3373 5577 7237 4347 2149 1775 6078 5252 2632 9374 2196 3194 5401 4506 2806 8215 1743 4043 9837 6783 7445 5077 4519 9525 7861 8001 4958 261 8207 1112 3769 7931 3040 7357 2277 5189 9131 8355 6792 8115 7728 5339 7660 9481 9844 6817 4047 1586 860 3883 4721 8304 5312 9239 4181 3172 7239 5490 9785 1798 6601 9905 9728 5992 7261 2005 7532 6392 6711 675 858 790 6013 8517 270 5856 1686 4316 3794 2545 4551 8514 7200 9862 4104 7732 3033 1343 3221 9169 9492 6173 9073 9219 8517 6334 7575 6048 9077 637 6723 9934 1427 2735 4802 1696 4943 6487 2364 5088 5383 6914 3601 8935 6775 4056 3018 6159 1750 6239 5328 1241 8763 752 460 7279 7085 4386 9679 6161 5023 6401 2446 6449 5487 7248 4496 6781 86 6859 1868 1821 124 1820 7107 6898 5876 124 9409 7625 2714 1088 8866 1477 1839 5677 5107 8924 6414 4785 1436 1436 7537 3882 4236 9376 7481 8732 6156 3918 1942 8024 5738 2066 6195 9196 8963 2070 9320 4723 6047 2033 5810 1264 9861 7649 6940 4968 2924 3353 6104 4359 1141 3641 8240 5376 9368 5720 4107 5523 9638 6049 9898 1727 4466 2445 923 3428 4514 6594 4503 6912 8626 312 8175 4839 4312 5114 6158 7235 4819 8613 1594 2311 8605 6185 7686 7972 8257 8145 9847 7894 545 9744 5972 5010 8540 3246 4789 3054 9839 9291 9965 4817 5955 4492 9655 266 9605 2164 7501 775 776 5446 3085 9381 1630 7123 7352 9886 5267 7198 4131 2163 3294 6455 7172 1833 9700 8312 1238 9539 7603 7555 707 9909 2046 6713 174 8002 8876 4026 5129 6003 9471 4565 5383 1101 1687 9087 7338 3305 2636 1469 5467 2281 7923 8990 466 3974 7302 8055 9864 1256 5609 570 1164 4006 7282 7689 8360 2509 1715 9840 4864 1185 4404 246 8637 6091 5684 5975 5747 4672 3795 1214 6952 8069 6555 3769 8394 3856 1824 8258 1463 3784 5179 8978 4142 8813 6667 2501 1321 8381 2340 6184 5917 3095 2782 906 9185 4817 6880 4932 9488 7026 2497 2792 1446 9051 6560 9839 9259 8383 8096 7073 2167 3275 6051 6308 2087 9069 5160 9759 3801 3851 2295 9717 6945 1428 6974 2482 6244 3853 3765 5732 7230 2613 8523 8675 1663 5082 8514 7273 9817 6609 4346 8335 6235 6748 994 4673 5816 6153 4432 9616 6355 3078 5684 3299 4505 2658 2132 748 2862 5896 2831 92 4860 7705 5118 6523 9139 3631 147 8955 6592 844 3641 9178 7591 4634 3851 3406 7138 4634 9373 3492 7711 1409 3142 8567 418 1626 5666 9631 3873 8497 6074 8733 6201 1192 1607 1691 1174 1753 6997 7765 2597 637 3295 187 5270 7145 9945 2407 8130 5669 2250 5840 3429 1744 4406 3846 3369 71 9829 3593 4919 5902 2325 7472 7093 3931 9162 4619 5684 6159 8735 4632 6795 2029 4818 8417 9173 1114 7175 3654 3135 5777 9493 6563 3872 250 6761 3592 6673 6589 7184 7943 2490 9509 5414 5935 3439 928 6905 5474 3438 5639 105 6584 7668 1275 1352 3192 8740 8527 6846 1874 655 2690 8437 4526 9292 5197 8117 5964 8137 5300 258 6978 4808 2024 2912 4599 2951 9816 72 2740 1807 6529 9323 9474 4155 7027 9017 2894 5553 5862 4768 6207 4904 3204 732 4195 4752 8848 6510 9240 499 6767 6217 5307 8790 5481 6257 8092 1648 2680 7183 3454 9208 2858 9279 3362 9884 8296 6256 1788 509 7375 7994 5412 6930 5077 9606 1681 276 2467 7272 774 9234 3488 2432 4375 5320 8688 8819 6968 1368 2353 6773 575 5210 6052 289 5093 699 2896 6880 1207 270 1225 6619 7199 2653 2576 5231 2928 5043 2502 3702 628 2341 2485 1354 7661 1173 6524 980 2540 8877 7752 9466 4086 155 6106 5531 853 9001 8762 2060 9270 6339 5030 6468 8991 3957 8050 1919 5351 551 1972 5978 2892 4456 3684 6904 1980 207 7883 871 9083 5634 6689 9521 5789 2794 1403 2993 8147 164 5052 3768 6502 6433 236 1845 390 4637 3763 5740 5188 2086 8070 4431 2893 1753 1334 4873 8311 9216 2095 3746 1201 8783 9618 3341 7929 1020 6334 6075 7535 7737 9842 389 4170 6429 2233 911 1066 2347 3002 2605 4432 1071 7035 3676 9175 4720 8548 7486 3935 6995 7583 1487 5777 7200 4828 3705 8219 7513 6131 2105 1601 5973 2493 5770 8753 1077 3032 9818 3423 6034 2422 4206 3456 5808 7882 2631 527 2781 6468 813 9775 4050 2300 5552 7601 3479 5608 5819 7343 1739 4275 8943 4063 6768 1065 2815 7844 4096 8985 1267 6481 7758 1824 9937 3566 9705 8919 444 2486 5386 1257 8612 5787 9908 515 3387 9738 6123 5557 7080 4213 9831 6022 8275 2950 3438 7441 794 3886 6425 8412 366 4183 6587 6654 4100 6292 5572 4543 5129 7309 5799 3740 9447 2058 4255 9185 1795 6729 1093 8874 941 924 1248 5567 225 1037 3007 1018 4922 9432 5781 1640 9966 2368 8293 4065 5011 217 8607 6491 3877 758 230 9676 9167 836 8860 962 3916 9953 6187 4856 7228 3786 6774 7452 4823 9781 4822 9744 5564 6954 7735 5529 5673 2380 9593 7035 2596 4551 3525 2824 1660 107 2499 827 942 7711 1788 4858 4015 4326 6065 1242 8112 2839 5045 2934 2619 9866 9029 4534 3172 6764 62 8844 5495 6006 5879 8090 6908 9403 7265 8568 5861 6116 5746 6803 178 3885 8012 4192 8210 4076 1785 2673 3266 6829 5606 2236 3047 987 6769 6218 4102 6830 1413 9596 9187 3643 4037 6095 9398 7653 1014 5258 3768 6759 2060 3945 643 6423 8136 5204 499 6272 7877 116 3101 9834 2352 6147 820 9120 8716 1273 2302 6480 868 1488 123 1256 3934 9520 8909 4947 4777 2676 1705 3189 2973 8699 9611 7460 255 6461 3732 8131 6577 6832 7964 8928 9330 5136 4399 4397 6408 6700 876 3628 8188 998 4883 2121 6869 3791 7068 7998 2819 5124 1186 5791 175 7148 3250 429 9961 3333 4911 2889 6516 9226 1816 2197 4361 2566 6593 7121 9266 3821 748 7453 4818 1982 5925 8039 2125 9344 6036 4943 820 7221 7085 994 720 6686 7774 680 19 2684 3568 6534 1909 1735 8731 2622 4301 5323 9742 3566 5495 6841 7370 6665 5174 3294 4703 7298 8990 738 8592 9809 4310 5676 802 1381 2362 4927 2061 2380 7610 1980 5265 5870 3715 3995 8491 4367 5670 4584 4284 1164 7776 1653 7828 2950 1298 8882 6599 287 9619 5191 95 280 866 7248 1661 9579 2174 3721 1958 9783 2052 7223 2005 5766 7569 495 6484 3238 1431 767 754 9206 8771 4933 8507 69 3815 5106 6707 9785 296 6802 65 7513 401 1725 7092 2575 1797 5401 8709 3848 8975 713 5966 6544 7560 2449 6133 5342 9568 3238 899 8338 8171 9406 4758 1985 4511 1465 1769 1158 4618 8185 8670 5018 9909 2113 3944 8057 7514 2653 8257 6488 9717 4222 3031 3628 3022 5516 5321 2589 8753 6220 7279 6923 5625 2036 5259 6487 3500 7028 7644 8117 5212 2665 9487 1473 4778 3430 9529 2291 2434 4137 8778 8503 8358 8161 8482 7732 3676 3803 6672 2428 22 3950 9351 1998 5986 961 8484 5837 7988 6127 306 9552 8791 9792 7376 9920 3221 3256 2210 2007 7393 7340 509 2102 5500 8990 9833 9175 2792 2857 7954 9165 6806 3656 1162 9143 4617 9645 1332 8956 2123 1637 8507 7266 1428 2234 7185 1000 5490 5747 9358 2882 3086 9866 4983 8585 5208 1168 4111 7999 4024 8416 3516 7181 2072 4677 2676 3040 674 4007 1995 2796 5643 6854 6413 3422 9087 9950 773 928 5696 131 3809 8781 6348 5144 3717 1555 6311 4179 5906 6686 2594 9421 3866 1017 449 2893 408 1122 6899 8755 270 8893 5608 6682 8666 1046 6631 9439 1974 2326 5921 5782 7458 8620 7277 1174 175 9939 1704 2432 6624 650 8204 6842 8018 8652 9734 8426 9774 6633 7180 43 1877 9139 6724 543 184 9707 6333 8509 2032 8605 643 5842 7224 7919 7015 3750 7858 5071 2533 4481 5720 736 7674 89 9388 7408 4866 9161 392 2045 5555 2268 7535 2278 9162 7719 8336 1846 6227 368 450 3221 6209 4026 1140 9575 7775 8997 997 6660 9829 3068 7395 3855 3157 6782 1262 8022 2294 8005 6419 7848 6624 3953 6478 5786 8023 4813 7631 602 5180 4433 3822 7740 8458 4961 3667 2584 309 4663 9243 6490 7731 6638 344 887 9771 7957 5260 2065 2313 1678 9912 8936 5631 6389 1073 5 1202 5056 606 2733 9488 4428 6825 7945 5740 491 6880 6049 5153 2475 8890 2883 9112 5585 121 5234 3541 5381 7298 5853 3410 3562 1140 5392 9950 2213 5397 7503 7268 6002 236 6755 6781 3412 1051 2521 3902 4282 4921 9054 6756 3810 8289 2219 9394 4761 7453 9286 6493 4750 1490 6255 4663 2629 1646 4613 4841 7042 8467 2108 9396 5054 5214 6176 8465 2616 5048 2366 6898 6320 7772 3653 129 2412 5872 5874 7172 3324 1511 17 4425 3000 6271 9088 1981 7916 52 6821 1310 8518 5281 7057 9924 6846 9584 8388 9462 4632 754 6359 951 4877 11 7432 7288 2234 9657 811 1909 7520 827 6334 6871 3449 1773 8851 7717 1824 2024 9026 6693 3656 6082 6616 501 5665 1356 6314 6648 8461 9024 3951 3337 5387 7734 6976 7620 7390 7786 9529 4909 4965 2214 8132 4765 3986 6982 2481 2161 9005 1506 5205 9012 3939 1821 9513 5956 9528 2178 2603 7988 1202 6553 1324 6588 4286 8299 4207 8028 2436 87 9288 3752 2300 7419 8517 2637 753 997 4797 6109 8855 2 5121 2793 8174 985 5100 7701 3162 7703 2040 4363 607 3363 950 1245 8013 1509 5624 448 1595 1263 4200 3895 5034 9068 6531 5786 64 7680 1894 5270 4033 7014 4415 8558 7998 9514 2610 7512 3568 4649 1874 4175 8011 9176 1771 2375 684 3746 2822 8630 5008 3373 8876 41 2440 5407 2178 8856 9438 4072 4125 3470 7437 8539 8379 1787 4405 988 9298 7972 5636 7523 8498 9998 6698 268 2372 3733 365 1545 2363 1725 1270 7590 1765 3709 2996 3943 8916 8785 4366 9393 8606 1802 4283 6984 3588 8687 7971 9237 6659 9958 6760 5156 9955 9809 1776 8678 9894 2140 223 2256 216 1492 6197 1981 1552 9193 2275 6820 4329 6640 6212 2935 4793 6846 9918 8381 5533 4241 3969 2191 4198 728 3698 505 537 5473 5534 430 3965 2108 9037 4180 3599 5233 2512 1503 777 1138 4674 5106 7777 7237 4392 8922 4082 4309 3654 9614 8549 7622 8156 2747 8350 8206 9603 5238 30 5136 2019 3994 7244 7407 4526 7194 8991 3389 5048 9768 4527 9721 1225 8655 6957 5616 3928 7391 6276 7581 3356 4825 5203 1512 3923 3552 9717 9877 5141 9746 5012 7159 92 8607 917 969 5801 9907 709 7200 6026 1587 6921 7250 6594 229 9217 521 3971 1845 8102 7327 6669 3304 5190 6943 3207 1258 3171 4699 7355 8182 8209 7446 3141 9125 4766 8941 9031 1827 6140 5057 3413 9412 8658 6 5993 4227 6879 9963 6071 4980 3641 9091 4635 8830 6033 7841 87 9203 2539 7442 3736 7099 1239 6876 6223 2357 2168 5253 4183 4660 6661 3947 4071 1671 3953 6415 5897 831 2730 1967 2162 6370 1057 6796 5200 3441 988 1638 8995 9878 9079 2730 6976 6670 5958 3198 9026 8125 4802 3208 2784 1463 3506 3207 3133 3810 5973 5381 992 8702 7347 3153 5072 4755 9948 6623 8195 935 8260 7189 812 7339 6270 4139 360 2227 7336 9385 6704 2138 8944 9487 9952 2449 9045 9436 6259 5018 4816 7250 3719 2162 6755 5142 6916 3054 1764 1462 3989 24 8650 1152 3714 4919 5291 4073 3498 8978 9809 201 1115 8752 6039 7418 7552 5084 6853 162 6453 1668 7412 171 181 518 1665 3448 3571 3428 4909 3911 9803 9910 5063 9868 1181 6705 3940 4678 2034 100 1230 9501 8851 7268 6918 2755 8703 123 2916 5155 8142 6679 1678 8323 7196 3342 8122 767 3121 9383 4677 2924 5644 6091 2791 6824 9147 3083 7853 1181 3182 9082 681 8385 2702 7598 1139 1404 4072 4054 2911 2214 733 4588 6888 7928 7929 1361 8694 1049 743 9723 324 6387 5813 3115 9562 4960 2549 7415 6140 5730 2848 3172 4114 5549 7121 5252 3305 1193 5658 6215 3406 6390 802 293 669 5082 1653 5715 2482 8748 5437 2806 1486 7601 2272 1047 2560 4820 8461 5051 549 7661 8222 1015 3209 5343 2618 6513 2887 8275 9079 6292 1016 9880 2936 8037 1313 940 3751 3795 6039 5539 6600 7524 3139 5223 8571 2051 42 3383 3453 6942 1043 8027 4308 4252 9721 6926 7116 2607 5200 6195 8898 2568 2426 8185 604 3739 5476 4354 7533 1515 6244 484 9038 5734 5706 7608 4136 2099 991 7589 5392 2033 5615 9700 2636 1687 6625 6104 4293 8176 2298 9542 743 1075 7726 7698 4813 3201 8403 2345 4715 4646 9180 105 6732 1237 7712 867 3335 5054 8455 8727 3439 421 4778 2426 2107 1402 8529 2751 5929 7178 2292 3024 8253 6369 721 3065 9570 9124 1762 636 121 941 7092 6852 2178 1156 7719 1864 6209 2525 6942 5999 9298 1719 8425 7756 9472 6953 507 5401 4131 9150 8424 2383 5519 5496 1799 1440 971 3560 8427 1092 853 5519 4295 9382 6674 8365 1245 9234 890 8187 5233 6539 6257 9 4294 5729 3313 1152 7481 7443 302 2256 6177 5820 7751 4328 3611 8722 7887 2037 6165 8739 7555 6811 8120 580 5176 5717 6166 2417 255 1398 8955 6511 7758 9600 8591 1070 752 6071 4865 1053 8326 7393 3224 2429 1720 6834 7502 9607 5222 18 4697 9129 6828 9169 9708 8355 4885 5873 771 1491 3622 6077 8001 1379 2029 6592 8801 2780 9014 3665 184 3692 7409 9759 6120 9129 2944 3621 5087 8165 9990 9783 7293 6817 5303 7001 5172 6539 9225 2294 8029 9199 4723 6030 577 6751 8973 5729 5882 4338 5745 6065 8029 3154 2175 500 2282 5118 472 7368 3282 461 3502 575 7278 5157 3927 8801 1695 9503 7446 9724 8701 8520 5753 5630 5270 1077 1358 7503 5414 7103 3567 9795 256 2093 294 8889 7210 766 2608 492 7578 2461 7418 4855 7617 1344 7 9312 846 3805 9035 5899 2324 1139 1528 7594 8567 2885 1448 332 6339 5015 126 2946 3459 6772 1834 669 3889 793 1160 1466 3254 8577 2673 7222 6272 9031 6533 3469 2835 1919 9367 5159 9409 894 9104 7975 131 551 8307 6469 1917 4784 9415 5376 1555 7600 6044 5443 8393 3555 3261 7998 8483 5933 5219 1106 4963 8104 4574 7798 22 293 9308 9431 ",
"output": "499999500000",
"type": "stdin_stdout"
}
]
} |
|
taco | verifiable_code | https://www.hackerrank.com/challenges/xor-quadruples/problem | Solve the following coding problem using the programming language python:
We call an quadruple of positive integers, $(W,X,Y,Z)$, beautiful if the following condition is true:
$W\oplus X\oplus Y\oplus Z\neq0$
Note: $\theta$ is the bitwise XOR operator.
Given $\mbox{A}$, $\mbox{B}$, $\mbox{C}$, and $\mbox{D}$, count the number of beautiful quadruples of the form $(W,X,Y,Z)$ where the following constraints hold:
$1\leq W\leq A$
$1\leq X\leq B$
$1\leq Y\leq C$
$1\leq z\leq D$
When you count the number of beautiful quadruples, you should consider two quadruples as same if the following are true:
They contain same integers.
Number of times each integers occur in the quadruple is same.
For example $(1,1,1,2)$ and $(1,1,2,1)$ should be considered as same.
Input Format
A single line with four space-separated integers describing the respective values of $\mbox{A}$, $\mbox{B}$, $\mbox{C}$, and $\mbox{D}$.
Constraints
$1\leq A,B,C,D\leq3000$
For $50\%$ of the maximum score, $1\leq A,B,C,D\leq50$
Output Format
Print the number of beautiful quadruples.
Sample Input
1 2 3 4
Sample Output
11
Explanation
There are $\mbox{11}$ beautiful quadruples for this input:
$(1,1,1,2)$
$(1,1,1,3)$
$(1,1,1,4)$
$(1,1,2,3)$
$(1,1,2,4)$
$(1,1,3,4)$
$(1,2,2,2)$
$(1,2,2,3)$
$(1,2,2,4)$
$(1,2,3,3)$
$(1,2,3,4)$
Thus, we print $\mbox{11}$ as our output.
Note that $(1,1,1,2)$ is same as $(1,1,2,1)$.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import sys
(A, B, C, D) = input().strip().split(' ')
temp = [int(A), int(B), int(C), int(D)]
temp.sort()
(A, B, C, D) = temp
tot = [0] * 4100
tree = [([0] * 3100).copy() for i in range(4100)]
cnt = [([0] * 3100).copy() for i in range(4100)]
def updateBIT(treeNo, ind):
while ind < 3100:
tree[treeNo][ind] += 1
ind += ind & -ind
def getBITVal(treeNo, ind):
ret = 0
while ind > 0:
ret += tree[treeNo][ind]
ind -= ind & -ind
return ret
zero = 0
tot = [0] * 3100
for i in range(1, A + 1):
for j in range(i, B + 1):
cnt[i ^ j][j] += 1
tot[j] += 1
for i in range(len(cnt)):
for j in range(1, len(cnt[i])):
cnt[i][j] += cnt[i][j - 1]
for i in range(1, len(tot)):
tot[i] += tot[i - 1]
ans = 0
for i in range(1, C + 1):
ans += tot[i] * (D + 1 - i)
for j in range(i, D + 1):
zero += cnt[i ^ j][i]
ans -= zero
print(ans)
``` | vfc_135198 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/xor-quadruples/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 2 3 4\n",
"output": "11\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1434/A | Solve the following coding problem using the programming language python:
After battling Shikamaru, Tayuya decided that her flute is too predictable, and replaced it with a guitar. The guitar has 6 strings and an infinite number of frets numbered from 1. Fretting the fret number j on the i-th string produces the note a_{i} + j.
Tayuya wants to play a melody of n notes. Each note can be played on different string-fret combination. The easiness of performance depends on the difference between the maximal and the minimal indices of used frets. The less this difference is, the easier it is to perform the technique. Please determine the minimal possible difference.
For example, if a = [1, 1, 2, 2, 3, 3], and the sequence of notes is 4, 11, 11, 12, 12, 13, 13 (corresponding to the second example), we can play the first note on the first string, and all the other notes on the sixth string. Then the maximal fret will be 10, the minimal one will be 3, and the answer is 10 - 3 = 7, as shown on the picture.
<image>
Input
The first line contains 6 space-separated numbers a_{1}, a_{2}, ..., a_{6} (1 β€ a_{i} β€ 10^{9}) which describe the Tayuya's strings.
The second line contains the only integer n (1 β€ n β€ 100 000) standing for the number of notes in the melody.
The third line consists of n integers b_{1}, b_{2}, ..., b_{n} (1 β€ b_{i} β€ 10^{9}), separated by space. They describe the notes to be played. It's guaranteed that b_i > a_j for all 1β€ iβ€ n and 1β€ jβ€ 6, in other words, you can play each note on any string.
Output
Print the minimal possible difference of the maximal and the minimal indices of used frets.
Examples
Input
1 4 100 10 30 5
6
101 104 105 110 130 200
Output
0
Input
1 1 2 2 3 3
7
13 4 11 12 11 13 12
Output
7
Note
In the first sample test it is optimal to play the first note on the first string, the second note on the second string, the third note on the sixth string, the fourth note on the fourth string, the fifth note on the fifth string, and the sixth note on the third string. In this case the 100-th fret is used each time, so the difference is 100 - 100 = 0.
<image>
In the second test it's optimal, for example, to play the second note on the first string, and all the other notes on the sixth string. Then the maximal fret will be 10, the minimal one will be 3, and the answer is 10 - 3 = 7.
<image>
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = 'x' in file.mode or 'r' not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b'\n') + (not b)
ptr = self.buffer.tell()
(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
(self.buffer.truncate(0), self.buffer.seek(0))
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode('ascii'))
self.read = lambda : self.buffer.read().decode('ascii')
self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline()
def RL():
return map(int, sys.stdin.readline().split())
def RLL():
return list(map(int, sys.stdin.readline().split()))
def N():
return int(input())
def print_list(l):
print(' '.join(map(str, l)))
from heapq import *
a = RLL()
a.sort(reverse=True)
n = N()
b = RLL()
res = float('inf')
heap = [(b[i] - a[0], i) for i in range(n)]
heapify(heap)
m = max(b) - a[0]
count = [0] * n
while 1:
(v, i) = heap[0]
res = min(res, m - v)
count[i] += 1
if count[i] == 6:
break
t = b[i] - a[count[i]]
m = max(m, t)
heapreplace(heap, (t, i))
print(res)
``` | vfc_135202 | {
"difficulty": "hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1434/A",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 4 7 6 4 1\n10\n19 16 18 12 16 15 16 20 16 14\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "158260522 877914575 602436426 24979445 861648772 623690081\n1\n896194147\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "58260522 77914575 2436426 24979445 61648772 23690081\n10\n582107247 906728404 411434947 673536177 411497300 488012525 561127307 800305059 992325267 112738006\n",
"output": "804109112\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "11 16 12 20 12 13\n10\n21 21 21 21 21 21 21 21 21 21\n",
"output": "0\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.hackerrank.com/challenges/halloween-sale/problem | Solve the following coding problem using the programming language python:
You wish to buy video games from the famous online video game store Mist.
Usually, all games are sold at the same price, $\boldsymbol{p}$ dollars. However, they are planning to have the seasonal Halloween Sale next month in which you can buy games at a cheaper price. Specifically, the first game will cost $\boldsymbol{p}$ dollars, and every subsequent game will cost $\boldsymbol{d}$ dollars less than the previous one. This continues until the cost becomes less than or equal to $m$ dollars, after which every game will cost $m$ dollars. How many games can you buy during the Halloween Sale?
Example
$p=20$
$\boldsymbol{d}=3$
$m=6$
$s=70$.
The following are the costs of the first $\mbox{11}$, in order:
$20,17,14,11,8,6,6,6,6,6,6$
Start at $p=20$ units cost, reduce that by $\boldsymbol{d}=3$ units each iteration until reaching a minimum possible price, $m=6$. Starting with $s=70$ units of currency in your Mist wallet, you can buy 5 games: $20+17+14+11+8=70$.
Function Description
Complete the howManyGames function in the editor below.
howManyGames has the following parameters:
int p: the price of the first game
int d: the discount from the previous game price
int m: the minimum cost of a game
int s: the starting budget
Input Format
The first and only line of input contains four space-separated integers $\boldsymbol{p}$, $\boldsymbol{d}$, $m$ and $\boldsymbol{\mathrm{~s~}}$.
Constraints
$1\leq m\leq p\leq100$
$1\leq d\leq100$
$1\leq s\leq10^4$
Sample Input 0
20 3 6 80
Sample Output 0
6
Explanation 0
Assumptions other than starting funds, $\boldsymbol{\mathrm{~S~}}$, match the example in the problem statement. With a budget of $\textbf{80}$, you can buy $\boldsymbol{6}$ games at a cost of $20+17+14+11+8+6=76$. A $7^{th}$ game for an additional $\boldsymbol{6}$ units exceeds the budget.
Sample Input 1
20 3 6 85
Sample Output 1
7
Explanation 1
This is the same as the previous case, except this time the starting budget $s=85$ units of currency. This time, you can buy $7$ games since they cost $20+17+14+11+8+6+6=82$. An additional game at $\boldsymbol{6}$ units will exceed the budget.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
(p, d, m, s) = map(int, input().split())
i = 0
cost = p
while s - cost >= 0:
i += 1
s -= cost
cost = max(cost - d, m)
print(i)
``` | vfc_135207 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/halloween-sale/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "20 3 6 80\n",
"output": "6\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/consecutive-array-elements2711/1 | Solve the following coding problem using the programming language python:
Given an unsorted array arr[] of size N, the task is to check whether the array consists of consecutive numbers or not.
Example 1:
Input: N = 5, arr[] = {5, 4, 2, 1, 3}
Output: Yes
Explanation: All are consecutive elements,
according to this order 1,2,3,4 and 5.
Example 2:
Input: N = 6, arr[] = {2, 1, 0, -3, -1, -2}
Output: Yes
Your Task:
This is a function problem. You don't need to take any input, as it is already accomplished by the driver code. You just need to complete the function areConsecutives() that takes array arr[] and integer N as parameters and returns the boolean true if array elements are consecutive else boolean false.
Note: If the elements are consecutive driver code outputs Yes otherwise, it outputs No
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(1).
Constraints:
1 β€ N β€ 10^{7}
Write your solution by modifying this code:
```python
class Solution:
def areConsecutives(self, arr, n):
# Your code goes here
```
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
class Solution:
def areConsecutives(self, arr, n):
min_ = min(arr)
p = list(range(min_, min_ + n))
dict_ = {elem: 0 for elem in arr}
for elem in p:
if elem not in dict_:
return False
return True
``` | vfc_135215 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/consecutive-array-elements2711/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 5, arr[] = {5, 4, 2, 1, 3}",
"output": "Yes",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "N = 6, arr[] = {2, 1, 0, -3, -1, -2}",
"output": "Yes",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1657/B | Solve the following coding problem using the programming language python:
You are given four integers $n$, $B$, $x$ and $y$. You should build a sequence $a_0, a_1, a_2, \dots, a_n$ where $a_0 = 0$ and for each $i \ge 1$ you can choose:
either $a_i = a_{i - 1} + x$
or $a_i = a_{i - 1} - y$.
Your goal is to build such a sequence $a$ that $a_i \le B$ for all $i$ and $\sum\limits_{i=0}^{n}{a_i}$ is maximum possible.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^4$) β the number of test cases. Next $t$ cases follow.
The first and only line of each test case contains four integers $n$, $B$, $x$ and $y$ ($1 \le n \le 2 \cdot 10^5$; $1 \le B, x, y \le 10^9$).
It's guaranteed that the total sum of $n$ doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print one integer β the maximum possible $\sum\limits_{i=0}^{n}{a_i}$.
-----Examples-----
Input
3
5 100 1 30
7 1000000000 1000000000 1000000000
4 1 7 3
Output
15
4000000000
-10
-----Note-----
In the first test case, the optimal sequence $a$ is $[0, 1, 2, 3, 4, 5]$.
In the second test case, the optimal sequence $a$ is $[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$.
In the third test case, the optimal sequence $a$ is $[0, -3, -6, 1, -2]$.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import sys
def get_ints():
return map(int, sys.stdin.readline().strip().split())
def get_ls():
return list(map(int, sys.stdin.readline().strip().split()))
def main():
for _ in range(int(input())):
(n, b, x, y) = get_ints()
a = 0
ans = a
for i in range(n):
if a + x <= b:
a += x
else:
a -= y
ans += a
print(ans)
main()
``` | vfc_135220 | {
"difficulty": "easy",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1657/B",
"time_limit": "2 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3\n",
"output": "15\n4000000000\n-10\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n100000 1000000000 1000000000 1\n100000 1 1000000000 10000\n",
"output": "99995000050000\n-50000500000000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7\n1 1 1 1\n2 2 2 2\n3 3 3 3\n4 4 4 4\n5 5 5 5\n6 6 6 6\n7 7 7 7\n",
"output": "1\n2\n6\n8\n15\n18\n28\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n1000 100 200 300\n",
"output": "-100000\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/649/D | Solve the following coding problem using the programming language python:
ΠΠ°ΠΌΡΡΡ ΠΊΠΎΠΌΠΏΡΡΡΠ΅ΡΠ° ΡΠΎΡΡΠΎΠΈΡ ΠΈΠ· n ΡΡΠ΅Π΅ΠΊ, ΠΊΠΎΡΠΎΡΡΠ΅ Π²ΡΡΡΡΠΎΠ΅Π½Ρ Π² ΡΡΠ΄. ΠΡΠΎΠ½ΡΠΌΠ΅ΡΡΠ΅ΠΌ ΡΡΠ΅ΠΉΠΊΠΈ ΠΎΡ 1 Π΄ΠΎ n ΡΠ»Π΅Π²Π° Π½Π°ΠΏΡΠ°Π²ΠΎ. ΠΡΠΎ ΠΊΠ°ΠΆΠ΄ΡΡ ΡΡΠ΅ΠΉΠΊΡ ΠΈΠ·Π²Π΅ΡΡΠ½ΠΎ, ΡΠ²ΠΎΠ±ΠΎΠ΄Π½Π° ΠΎΠ½Π° ΠΈΠ»ΠΈ ΠΏΡΠΈΠ½Π°Π΄Π»Π΅ΠΆΠΈΡ ΠΊΠ°ΠΊΠΎΠΌΡ-Π»ΠΈΠ±ΠΎ ΠΏΡΠΎΡΠ΅ΡΡΡ (Π² ΡΠ°ΠΊΠΎΠΌ ΡΠ»ΡΡΠ°Π΅ ΠΈΠ·Π²Π΅ΡΡΠ΅Π½ ΠΏΡΠΎΡΠ΅ΡΡ, ΠΊΠΎΡΠΎΡΠΎΠΌΡ ΠΎΠ½Π° ΠΏΡΠΈΠ½Π°Π΄Π»Π΅ΠΆΠΈΡ).
ΠΠ»Ρ ΠΊΠ°ΠΆΠ΄ΠΎΠ³ΠΎ ΠΏΡΠΎΡΠ΅ΡΡΠ° ΠΈΠ·Π²Π΅ΡΡΠ½ΠΎ, ΡΡΠΎ ΠΏΡΠΈΠ½Π°Π΄Π»Π΅ΠΆΠ°ΡΠΈΠ΅ Π΅ΠΌΡ ΡΡΠ΅ΠΉΠΊΠΈ Π·Π°Π½ΠΈΠΌΠ°ΡΡ Π² ΠΏΠ°ΠΌΡΡΠΈ Π½Π΅ΠΏΡΠ΅ΡΡΠ²Π½ΡΠΉ ΡΡΠ°ΡΡΠΎΠΊ. Π‘ ΠΏΠΎΠΌΠΎΡΡΡ ΠΎΠΏΠ΅ΡΠ°ΡΠΈΠΉ Π²ΠΈΠ΄Π° Β«ΠΏΠ΅ΡΠ΅ΠΏΠΈΡΠ°ΡΡ Π΄Π°Π½Π½ΡΠ΅ ΠΈΠ· Π·Π°Π½ΡΡΠΎΠΉ ΡΡΠ΅ΠΉΠΊΠΈ Π² ΡΠ²ΠΎΠ±ΠΎΠ΄Π½ΡΡ, Π° Π·Π°Π½ΡΡΡΡ ΡΠ΅ΠΏΠ΅ΡΡ ΡΡΠΈΡΠ°ΡΡ ΡΠ²ΠΎΠ±ΠΎΠ΄Π½ΠΎΠΉΒ» ΡΡΠ΅Π±ΡΠ΅ΡΡΡ ΡΠ°ΡΠΏΠΎΠ»ΠΎΠΆΠΈΡΡ Π²ΡΠ΅ ΠΏΡΠΈΠ½Π°Π΄Π»Π΅ΠΆΠ°ΡΠΈΠ΅ ΠΏΡΠΎΡΠ΅ΡΡΠ°ΠΌ ΡΡΠ΅ΠΉΠΊΠΈ Π² Π½Π°ΡΠ°Π»Π΅ ΠΏΠ°ΠΌΡΡΠΈ ΠΊΠΎΠΌΠΏΡΡΡΠ΅ΡΠ°. ΠΡΡΠ³ΠΈΠΌΠΈ ΡΠ»ΠΎΠ²Π°ΠΌΠΈ, Π»ΡΠ±Π°Ρ ΡΠ²ΠΎΠ±ΠΎΠ΄Π½Π°Ρ ΡΡΠ΅ΠΉΠΊΠ° Π΄ΠΎΠ»ΠΆΠ½Π° ΡΠ°ΡΠΏΠΎΠ»Π°Π³Π°ΡΡΡΡ ΠΏΡΠ°Π²Π΅Π΅ (ΠΈΠΌΠ΅ΡΡ Π±ΠΎΠ»ΡΡΠΈΠΉ Π½ΠΎΠΌΠ΅Ρ) Π»ΡΠ±ΠΎΠΉ Π·Π°Π½ΡΡΠΎΠΉ.
ΠΠ°ΠΌ Π½Π΅ΠΎΠ±Ρ
ΠΎΠ΄ΠΈΠΌΠΎ Π½Π°ΠΉΡΠΈ ΠΌΠΈΠ½ΠΈΠΌΠ°Π»ΡΠ½ΠΎΠ΅ ΠΊΠΎΠ»ΠΈΡΠ΅ΡΡΠ²ΠΎ ΠΎΠΏΠ΅ΡΠ°ΡΠΈΠΉ ΠΏΠ΅ΡΠ΅ΠΏΠΈΡΡΠ²Π°Π½ΠΈΡ Π΄Π°Π½Π½ΡΡ
ΠΈΠ· ΠΎΠ΄Π½ΠΎΠΉ ΡΡΠ΅ΠΉΠΊΠΈ Π² Π΄ΡΡΠ³ΡΡ, Ρ ΠΏΠΎΠΌΠΎΡΡΡ ΠΊΠΎΡΠΎΡΡΡ
ΠΌΠΎΠΆΠ½ΠΎ Π΄ΠΎΡΡΠΈΡΡ ΠΎΠΏΠΈΡΠ°Π½Π½ΡΡ
ΡΡΠ»ΠΎΠ²ΠΈΠΉ. ΠΠΎΠΏΡΡΡΠΈΠΌΠΎ, ΡΡΠΎ ΠΎΡΠ½ΠΎΡΠΈΡΠ΅Π»ΡΠ½ΡΠΉ ΠΏΠΎΡΡΠ΄ΠΎΠΊ ΡΡΠ΅Π΅ΠΊ Π² ΠΏΠ°ΠΌΡΡΠΈ Π΄Π»Ρ ΠΊΠ°ΠΆΠ΄ΠΎΠ³ΠΎ ΠΈΠ· ΠΏΡΠΎΡΠ΅ΡΡΠΎΠ² ΠΈΠ·ΠΌΠ΅Π½ΠΈΡΡΡ ΠΏΠΎΡΠ»Π΅ Π΄Π΅ΡΡΠ°Π³ΠΌΠ΅Π½ΡΠ°ΡΠΈΠΈ, Π½ΠΎ ΠΎΡΠ½ΠΎΡΠΈΡΠ΅Π»ΡΠ½ΡΠΉ ΠΏΠΎΡΡΠ΄ΠΎΠΊ ΡΠ°ΠΌΠΈΡ
ΠΏΡΠΎΡΠ΅ΡΡΠΎΠ² Π΄ΠΎΠ»ΠΆΠ΅Π½ ΠΎΡΡΠ°ΡΡΡΡ Π±Π΅Π· ΠΈΠ·ΠΌΠ΅Π½Π΅Π½ΠΈΠΉ. ΠΡΠΎ Π·Π½Π°ΡΠΈΡ, ΡΡΠΎ Π΅ΡΠ»ΠΈ Π²ΡΠ΅ ΡΡΠ΅ΠΉΠΊΠΈ, ΠΏΡΠΈΠ½Π°Π΄Π»Π΅ΠΆΠ°ΡΠΈΠ΅ ΠΏΡΠΎΡΠ΅ΡΡΡ i, Π½Π°Ρ
ΠΎΠ΄ΠΈΠ»ΠΈΡΡ Π² ΠΏΠ°ΠΌΡΡΠΈ ΡΠ°Π½ΡΡΠ΅ Π²ΡΠ΅Ρ
ΡΡΠ΅Π΅ΠΊ ΠΏΡΠΎΡΠ΅ΡΡΠ° j, ΡΠΎ ΠΈ ΠΏΠΎΡΠ»Π΅ ΠΏΠ΅ΡΠ΅ΠΌΠ΅ΡΠ΅Π½ΠΈΠΉ ΡΡΠΎ ΡΡΠ»ΠΎΠ²ΠΈΠ΅ Π΄ΠΎΠ»ΠΆΠ½ΠΎ Π²ΡΠΏΠΎΠ»Π½ΡΡΡΡΡ.
Π‘ΡΠΈΡΠ°ΠΉΡΠ΅, ΡΡΠΎ Π½ΠΎΠΌΠ΅ΡΠ° Π²ΡΠ΅Ρ
ΠΏΡΠΎΡΠ΅ΡΡΠΎΠ² ΡΠ½ΠΈΠΊΠ°Π»ΡΠ½Ρ, Ρ
ΠΎΡΡ Π±Ρ ΠΎΠ΄Π½Π° ΡΡΠ΅ΠΉΠΊΠ° ΠΏΠ°ΠΌΡΡΠΈ Π·Π°Π½ΡΡΠ° ΠΊΠ°ΠΊΠΈΠΌ-Π»ΠΈΠ±ΠΎ ΠΏΡΠΎΡΠ΅ΡΡΠΎΠΌ.
-----ΠΡ
ΠΎΠ΄Π½ΡΠ΅ Π΄Π°Π½Π½ΡΠ΅-----
Π ΠΏΠ΅ΡΠ²ΠΎΠΉ ΡΡΡΠΎΠΊΠ΅ Π²Ρ
ΠΎΠ΄Π½ΡΡ
Π΄Π°Π½Π½ΡΡ
Π·Π°ΠΏΠΈΡΠ°Π½ΠΎ ΡΠΈΡΠ»ΠΎ n (1 β€ n β€ 200 000)Β β ΠΊΠΎΠ»ΠΈΡΠ΅ΡΡΠ²ΠΎ ΡΡΠ΅Π΅ΠΊ Π² ΠΏΠ°ΠΌΡΡΠΈ ΠΊΠΎΠΌΠΏΡΡΡΠ΅ΡΠ°.
ΠΠΎ Π²ΡΠΎΡΠΎΠΉ ΡΡΡΠΎΠΊΠ΅ Π²Ρ
ΠΎΠ΄Π½ΡΡ
Π΄Π°Π½Π½ΡΡ
ΡΠ»Π΅Π΄ΡΡΡ n ΡΠ΅Π»ΡΡ
ΡΠΈΡΠ΅Π» a_1, a_2, ..., a_{n} (1 β€ a_{i} β€ n), Π³Π΄Π΅ a_{i} ΡΠ°Π²Π½ΠΎ Π»ΠΈΠ±ΠΎ 0 (ΡΡΠΎ ΠΎΠ·Π½Π°ΡΠ°Π΅Ρ, ΡΡΠΎ i-Ρ ΡΡΠ΅ΠΉΠΊΠ° ΠΏΠ°ΠΌΡΡΠΈ ΡΠ²ΠΎΠ±ΠΎΠ΄Π½Π°), Π»ΠΈΠ±ΠΎ Π½ΠΎΠΌΠ΅ΡΡ ΠΏΡΠΎΡΠ΅ΡΡΠ°, ΠΊΠΎΡΠΎΡΠΎΠΌΡ ΠΏΡΠΈΠ½Π°Π΄Π»Π΅ΠΆΠΈΡ i-Ρ ΡΡΠ΅ΠΉΠΊΠ° ΠΏΠ°ΠΌΡΡΠΈ. ΠΠ°ΡΠ°Π½ΡΠΈΡΡΠ΅ΡΡΡ, ΡΡΠΎ Ρ
ΠΎΡΡ Π±Ρ ΠΎΠ΄Π½ΠΎ Π·Π½Π°ΡΠ΅Π½ΠΈΠ΅ a_{i} Π½Π΅ ΡΠ°Π²Π½ΠΎ 0.
ΠΡΠΎΡΠ΅ΡΡΡ ΠΏΡΠΎΠ½ΡΠΌΠ΅ΡΠΎΠ²Π°Π½Ρ ΡΠ΅Π»ΡΠΌΠΈ ΡΠΈΡΠ»Π°ΠΌΠΈ ΠΎΡ 1 Π΄ΠΎ n Π² ΠΏΡΠΎΠΈΠ·Π²ΠΎΠ»ΡΠ½ΠΎΠΌ ΠΏΠΎΡΡΠ΄ΠΊΠ΅. ΠΡΠΈ ΡΡΠΎΠΌ ΠΏΡΠΎΡΠ΅ΡΡΡ Π½Π΅ ΠΎΠ±ΡΠ·Π°ΡΠ΅Π»ΡΠ½ΠΎ ΠΏΡΠΎΠ½ΡΠΌΠ΅ΡΠΎΠ²Π°Π½Ρ ΠΏΠΎΡΠ»Π΅Π΄ΠΎΠ²Π°ΡΠ΅Π»ΡΠ½ΡΠΌΠΈ ΡΠΈΡΠ»Π°ΠΌΠΈ.
-----ΠΡΡ
ΠΎΠ΄Π½ΡΠ΅ Π΄Π°Π½Π½ΡΠ΅-----
ΠΡΠ²Π΅Π΄ΠΈΡΠ΅ ΠΎΠ΄Π½ΠΎ ΡΠ΅Π»ΠΎΠ΅ ΡΠΈΡΠ»ΠΎΒ β ΠΌΠΈΠ½ΠΈΠΌΠ°Π»ΡΠ½ΠΎΠ΅ ΠΊΠΎΠ»ΠΈΡΠ΅ΡΡΠ²ΠΎ ΠΎΠΏΠ΅ΡΠ°ΡΠΈΠΉ, ΠΊΠΎΡΠΎΡΠΎΠ΅ Π½ΡΠΆΠ½ΠΎ ΡΠ΄Π΅Π»Π°ΡΡ Π΄Π»Ρ Π΄Π΅ΡΡΠ°Π³ΠΌΠ΅Π½ΡΠ°ΡΠΈΠΈ ΠΏΠ°ΠΌΡΡΠΈ.
-----ΠΡΠΈΠΌΠ΅ΡΡ-----
ΠΡ
ΠΎΠ΄Π½ΡΠ΅ Π΄Π°Π½Π½ΡΠ΅
4
0 2 2 1
ΠΡΡ
ΠΎΠ΄Π½ΡΠ΅ Π΄Π°Π½Π½ΡΠ΅
2
ΠΡ
ΠΎΠ΄Π½ΡΠ΅ Π΄Π°Π½Π½ΡΠ΅
8
0 8 8 8 0 4 4 2
ΠΡΡ
ΠΎΠ΄Π½ΡΠ΅ Π΄Π°Π½Π½ΡΠ΅
4
-----ΠΡΠΈΠΌΠ΅ΡΠ°Π½ΠΈΠ΅-----
Π ΠΏΠ΅ΡΠ²ΠΎΠΌ ΡΠ΅ΡΡΠΎΠ²ΠΎΠΌ ΠΏΡΠΈΠΌΠ΅ΡΠ΅ Π΄ΠΎΡΡΠ°ΡΠΎΡΠ½ΠΎ Π΄Π²ΡΡ
ΠΎΠΏΠ΅ΡΠ°ΡΠΈΠΉ: ΠΠ΅ΡΠ΅ΠΏΠΈΡΠ°ΡΡ Π΄Π°Π½Π½ΡΠ΅ ΠΈΠ· ΡΡΠ΅ΡΡΠ΅ΠΉ ΡΡΠ΅ΠΉΠΊΠΈ Π² ΠΏΠ΅ΡΠ²ΡΡ. ΠΠΎΡΠ»Π΅ ΡΡΠΎΠ³ΠΎ ΠΏΠ°ΠΌΡΡΡ ΠΊΠΎΠΌΠΏΡΡΡΠ΅ΡΠ° ΠΏΡΠΈΠΌΠ΅Ρ Π²ΠΈΠ΄: 2Β 2Β 0Β 1. ΠΠ΅ΡΠ΅ΠΏΠΈΡΠ°ΡΡ Π΄Π°Π½Π½ΡΠ΅ ΠΈΠ· ΡΠ΅ΡΠ²Π΅ΡΡΠΎΠΉ ΡΡΠ΅ΠΉΠΊΠΈ Π² ΡΡΠ΅ΡΡΡ. ΠΠΎΡΠ»Π΅ ΡΡΠΎΠ³ΠΎ ΠΏΠ°ΠΌΡΡΡ ΠΊΠΎΠΌΠΏΡΡΡΠ΅ΡΠ° ΠΏΡΠΈΠΌΠ΅Ρ Π²ΠΈΠ΄: 2Β 2Β 1Β 0.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
input()
memory = list(map(int, input().split()))
proc_data = {p: (-1, -1) for p in memory}
for (i, c) in enumerate(memory):
(d1, d2) = proc_data[c]
if d1 == -1:
d1 = i
d2 = i
proc_data[c] = (d1, d2)
try:
del proc_data[0]
except KeyError:
print('0')
return
data = list(proc_data.values())
data.sort()
ans = 0
first_free = 0
for (a, b) in data:
c = a - first_free
ans += min(c, b - a + 1)
b -= c
first_free = b + 1
print(ans)
``` | vfc_135224 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/649/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n0 2 2 1\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/RECHEND | Solve the following coding problem using the programming language python:
Read problem statements in [Mandarin], [Bengali], and [Russian] as well.
You are given a positive integer N. Consider a square grid of size N \times N, with rows numbered 1 to N from top to bottom and columns numbered 1 to N from left to right. Initially you are at (1,1) and you have to reach (N,N). From a cell you can either move one cell to the right or one cell down (if possible). Formally, if you are at (i,j), then you can either move to (i+1,j) if i < N, or to (i,j+1) if j < N.
There are exactly N blocks in the grid, such that each row contains exactly one block and each column contains exactly one block. You can't move to a cell which contains a block. It is guaranteed that blocks will not placed in (1,1) and (N,N).
You have to find out whether you can reach (N,N).
------ Input Format ------
- The first line contains T - the number of test cases. Then the test cases follow.
- The first line of each test case contains N - the size of the square grid.
- The i-th line of the next N lines contains two integers X_{i} and Y_{i} indicating that (X_{i}, Y_{i}) is the position of a block in the grid.
------ Output Format ------
For each test case, if there exists a path from (1,1) to (N,N), output YES, otherwise output NO.
You may print each character of the string in uppercase or lowercase (for example, the strings yEs, yes, Yes and YES will all be treated as identical).
------ Constraints ------
$1 β€T β€1000$
$2 β€N β€10^{6}$
$1 β€X_{i},Y_{i} β€N$
$(X_{i}, Y_{i}) \ne (1, 1)$ and $(X_{i}, Y_{i}) \ne (N, N)$ for all $1 β€i β€N$
$X_{i} \ne X_{j}$ and $Y_{i} \ne Y_{j}$ for all $1 β€i < j β€N$
- Sum of $N$ over all test cases does not exceed $10^{6}$
----- Sample Input 1 ------
2
3
1 2
2 3
3 1
2
1 2
2 1
----- Sample Output 1 ------
YES
NO
----- explanation 1 ------
- Test case $1$: We can follow the path $(1,1) \to (2,1) \to (2,2) \to (3,2) \to (3,3)$.
- Test case $2$: We can't move from the starting point, so it is impossible to reach $(N, N)$.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
n = int(input())
c = dict()
for i in range(n):
(a, b) = map(int, input().split())
if a + b in c:
c[a + b] += 1
else:
c[a + b] = 1
fl = 1
for i in range(2, n + 1):
if i in c:
if c[i] == i - 1:
fl = 0
break
j = n + 1
k = n
for i in range(n - 1):
if j in c:
if c[j] == k:
fl = 0
break
j += 1
k -= 1
if fl == 0:
print('NO')
else:
print('YES')
``` | vfc_135228 | {
"difficulty": "hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/RECHEND",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3\n1 2\n2 3\n3 1\n2\n1 2\n2 1",
"output": "YES\nNO",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/queries-on-strings5636/1 | Solve the following coding problem using the programming language python:
Given a string str you have to answer several queries on that string. In each query you will be provided two values L and R and you have to find the number of distinct characters in the sub string from index L to index R (inclusive) of the original string.
Example 1:
Input: str = "abcbaed",
Query = {{1,4},{2,4},{1,7}}
Output: {3,2,5}
Explanation: For the first query distinct
characters from [1, 4] are a, b and c.
For the second query distinct characters from
[2, 4] are b and c.
For the third query distinct characters from
[1, 7] are a, b, c, d and e.
Your Task:
You don't need to read or print anyhting. Your task is to complete the function SolveQueries() which takes str and Query as input parameter and returns a list containing answer for each query.
Expected Time Complexity: O(max(26*length of str, 26 * No of queries))
Expected Space Complexity: O(26 * length of str)
Constraints:
1 <= |str| <= 10^{5}
1 <= No of Queries <= 10^{4}
1 <= L_{i} <= R_{i} <= |str|
Write your solution by modifying this code:
```python
#User function Template for python3
class Solution:
def SolveQueris(self, str, Query):
# Code here
```
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
class Solution:
def SolveQueris(self, str, Query):
res = []
for Pair in Query:
s = set()
string = str[Pair[0] - 1:Pair[1]]
for i in string:
if i not in s:
s.add(i)
res.append(len(s))
return res
``` | vfc_135232 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/queries-on-strings5636/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "str = \"abcbaed\",\r\nQuery = {{1,4},{2,4},{1,7}}",
"output": "{3,2,5}",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/74/C | Solve the following coding problem using the programming language python:
Let's imagine: there is a chess piece billiard ball. Its movements resemble the ones of a bishop chess piece. The only difference is that when a billiard ball hits the board's border, it can reflect from it and continue moving.
More formally, first one of four diagonal directions is chosen and the billiard ball moves in that direction. When it reaches the square located on the board's edge, the billiard ball reflects from it; it changes the direction of its movement by 90 degrees and continues moving. Specifically, having reached a corner square, the billiard ball is reflected twice and starts to move the opposite way. While it moves, the billiard ball can make an infinite number of reflections. At any square of its trajectory the billiard ball can stop and on that the move is considered completed.
<image>
It is considered that one billiard ball a beats another billiard ball b if a can reach a point where b is located.
You are suggested to find the maximal number of billiard balls, that pairwise do not beat each other and that can be positioned on a chessboard n Γ m in size.
Input
The first line contains two integers n and m (2 β€ n, m β€ 106).
Output
Print a single number, the maximum possible number of billiard balls that do not pairwise beat each other.
Please do not use the %lld specificator to read or write 64-bit numbers in C++. It is preferred to use cin (also you may use the %I64d specificator).
Examples
Input
3 4
Output
2
Input
3 3
Output
3
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import math
(n, m) = map(int, input().split())
print(math.gcd(n - 1, m - 1) + 1)
``` | vfc_135234 | {
"difficulty": "hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/74/C",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "8 50\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "302237 618749\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "999999 1000000\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "893011 315181\n",
"output": "52531\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4449 1336\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "871866 348747\n",
"output": "174374\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1025/A | Solve the following coding problem using the programming language python:
Panic is rising in the committee for doggo standardizationΒ β the puppies of the new brood have been born multi-colored! In total there are 26 possible colors of puppies in the nature and they are denoted by letters from 'a' to 'z' inclusive.
The committee rules strictly prohibit even the smallest diversity between doggos and hence all the puppies should be of the same color. Thus Slava, the committee employee, has been assigned the task to recolor some puppies into other colors in order to eliminate the difference and make all the puppies have one common color.
Unfortunately, due to bureaucratic reasons and restricted budget, there's only one operation Slava can perform: he can choose a color $x$ such that there are currently at least two puppies of color $x$ and recolor all puppies of the color $x$ into some arbitrary color $y$. Luckily, this operation can be applied multiple times (including zero).
For example, if the number of puppies is $7$ and their colors are represented as the string "abababc", then in one operation Slava can get the results "zbzbzbc", "bbbbbbc", "aaaaaac", "acacacc" and others. However, if the current color sequence is "abababc", then he can't choose $x$='c' right now, because currently only one puppy has the color 'c'.
Help Slava and the committee determine whether it is possible to standardize all the puppies, i.e. after Slava's operations all the puppies should have the same color.
-----Input-----
The first line contains a single integer $n$ ($1 \le n \le 10^5$)Β β the number of puppies.
The second line contains a string $s$ of length $n$ consisting of lowercase Latin letters, where the $i$-th symbol denotes the $i$-th puppy's color.
-----Output-----
If it's possible to recolor all puppies into one color, print "Yes".
Otherwise print "No".
Output the answer without quotation signs.
-----Examples-----
Input
6
aabddc
Output
Yes
Input
3
abc
Output
No
Input
3
jjj
Output
Yes
-----Note-----
In the first example Slava can perform the following steps: take all puppies of color 'a' (a total of two) and recolor them into 'b'; take all puppies of color 'd' (a total of two) and recolor them into 'c'; take all puppies of color 'b' (three puppies for now) and recolor them into 'c'.
In the second example it's impossible to recolor any of the puppies.
In the third example all the puppies' colors are the same; thus there's no need to recolor anything.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n = int(input())
string = input()
array = []
for i in range(0, 27):
array.append(0)
for j in range(0, n):
num = ord(string[j]) - 96
array[num] += 1
if len(string) == 1:
print('Yes')
else:
for i in array:
if i == 0:
continue
elif i >= 2:
print('Yes')
break
else:
print('No')
``` | vfc_135238 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1025/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\naabddc\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\nabc\n",
"output": "No\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/95/A | Solve the following coding problem using the programming language python:
Petya loves hockey very much. One day, as he was watching a hockey match, he fell asleep. Petya dreamt of being appointed to change a hockey team's name. Thus, Petya was given the original team name w and the collection of forbidden substrings s1, s2, ..., sn. All those strings consist of uppercase and lowercase Latin letters. String w has the length of |w|, its characters are numbered from 1 to |w|.
First Petya should find all the occurrences of forbidden substrings in the w string. During the search of substrings the case of letter shouldn't be taken into consideration. That is, strings "aBC" and "ABc" are considered equal.
After that Petya should perform the replacement of all letters covered by the occurrences. More formally: a letter in the position i should be replaced by any other one if for position i in string w there exist pair of indices l, r (1 β€ l β€ i β€ r β€ |w|) such that substring w[l ... r] is contained in the collection s1, s2, ..., sn, when using case insensitive comparison. During the replacement the letter's case should remain the same. Petya is not allowed to replace the letters that aren't covered by any forbidden substring.
Letter letter (uppercase or lowercase) is considered lucky for the hockey players. That's why Petya should perform the changes so that the letter occurred in the resulting string as many times as possible. Help Petya to find such resulting string. If there are several such strings, find the one that comes first lexicographically.
Note that the process of replacements is not repeated, it occurs only once. That is, if after Petya's replacements the string started to contain new occurrences of bad substrings, Petya pays no attention to them.
Input
The first line contains the only integer n (1 β€ n β€ 100) β the number of forbidden substrings in the collection. Next n lines contain these substrings. The next line contains string w. All those n + 1 lines are non-empty strings consisting of uppercase and lowercase Latin letters whose length does not exceed 100. The last line contains a lowercase letter letter.
Output
Output the only line β Petya's resulting string with the maximum number of letters letter. If there are several answers then output the one that comes first lexicographically.
The lexicographical comparison is performed by the standard < operator in modern programming languages. The line a is lexicographically smaller than the line b, if a is a prefix of b, or there exists such an i (1 β€ i β€ |a|), that ai < bi, and for any j (1 β€ j < i) aj = bj. |a| stands for the length of string a.
Examples
Input
3
bers
ucky
elu
PetrLoveLuckyNumbers
t
Output
PetrLovtTttttNumtttt
Input
4
hello
party
abefglghjdhfgj
IVan
petrsmatchwin
a
Output
petrsmatchwin
Input
2
aCa
cba
abAcaba
c
Output
abCacba
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n = int(input())
a = []
for i in range(n):
a.append(input().rstrip())
w = list(input().rstrip())
c = input().rstrip()
m = len(w)
z = []
i = 0
while i < m:
for j in range(n):
if w[i].lower() == a[j][0].lower():
if i + len(a[j]) <= m:
f = 1
for k in range(i, i + len(a[j])):
if w[k].lower() != a[j][k - i].lower():
f = 0
break
if f:
if len(z) != 0:
if z[-1][1] >= i:
z[-1][1] = max(i + len(a[j]) - 1, z[-1][1])
else:
z.append([i, i + len(a[j]) - 1])
else:
z.append([i, i + len(a[j]) - 1])
i += 1
for i in z:
for k in range(i[0], i[1] + 1):
if w[k].isupper():
if w[k] != c.upper():
w[k] = c.upper()
elif w[k] != 'A':
w[k] = 'A'
else:
w[k] = 'B'
elif w[k] != c.lower():
w[k] = c.lower()
elif w[k] != 'a':
w[k] = 'a'
else:
w[k] = 'b'
print(''.join(w))
``` | vfc_135242 | {
"difficulty": "medium_hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/95/A",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\netr\ned\nied\nPetrUnited\nz\n",
"output": "PzzzUnitzz\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/MAXIMUMSUBS | Solve the following coding problem using the programming language python:
A participant can make 1 submission every 30 seconds. If a contest lasts for X minutes, what is the maximum number of submissions that the participant can make during it?
It is also given that the participant cannot make any submission in the last 5 seconds of the contest.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of a single integer X, denoting the number of minutes.
------ Output Format ------
For each test case, output the maximum number of submissions a participant can make in X minutes.
------ Constraints ------
$1 β€ T β€ 30$
$1 β€ X β€ 30$
----- Sample Input 1 ------
4
1
2
3
4
----- Sample Output 1 ------
2
4
6
8
----- explanation 1 ------
Test case $1$: The contest lasts for $1$ minute, which is $60$ seconds. A participant can make $2$ submissions during this time β for example, in the $5$-th second and in the $48$-th second. Making $3$ or more submissions is impossible.
Test case $2$: The contest lasts for $2$ minutes, which is $120$ seconds. A participant can make $4$ submissions during this time.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
a = int(input())
for i in range(a):
b = int(input())
print(b * 2)
``` | vfc_135246 | {
"difficulty": "easy",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/MAXIMUMSUBS",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1\n2\n3\n4\n",
"output": "2\n4\n6\n8\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/COOK11/problems/KNIGHTMV | Solve the following coding problem using the programming language python:
Chef develops his own computer program for playing chess. He is at the very beginning. At first he needs to write the module that will receive moves written by the players and analyze it. The module will receive a string and it should report at first whether this string represents the correct pair of cells on the chess board (we call such strings correct) and then report whether it represents the correct move depending on the situation on the chess board. Chef always has troubles with analyzing knight moves. So at first he needs a test program that can say whether a given string is correct and then whether it represents a correct knight move (irregardless of the situation on the chess board). The cell on the chessboard is represented as a string of two characters: first character is a lowercase Latin letter from a to h and the second character is a digit from 1 to 8. The string represents the correct pair of cells on the chess board if it composed of 5 characters where first two characters represent the cell where chess figure was, 3rd character is the dash "-" and the last two characters represent the destination cell.
-----Input-----
The first line contains a single integer T <= 50000, the number of test cases. T test cases follow. The only line of each test case contains a non-empty string composed the characters with ASCII-codes from 32 to 126. The length of the string is not greater than 10.
-----Output-----
For each test case, output a single line containing the word "Error" if the corresponding string does not represent the correct pair of cells on the chess board. Otherwise output "Yes" if this pair of cells represents the correct knight move and "No" otherwise.
-----Example-----
Input:
4
a1-b3
d2-h8
a3 c4
ErrorError
Output:
Yes
No
Error
Error
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def gc(c):
return 'a' <= c <= 'h'
def gd(c):
return '1' <= c <= '8'
t = int(input())
for i in range(t):
line = input()
if len(line) != 5:
print('Error')
continue
if line[2] != '-':
print('Error')
continue
x1 = line[0]
y1 = line[1]
x2 = line[3]
y2 = line[4]
if gc(x1) and gd(y1) and gc(x2) and gd(y2):
d1 = abs(ord(x1) - ord(x2))
d2 = abs(ord(y1) - ord(y2))
if d1 > d2:
(d1, d2) = (d2, d1)
if d1 == 1 and d2 == 2:
print('Yes')
else:
print('No')
else:
print('Error')
``` | vfc_135251 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/COOK11/problems/KNIGHTMV",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\na1-b3\nd2-h8\na3 c4\nErrorError\n",
"output": "Yes\nNo\nError\nError\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/equalization-of-an-array1656/1 | Solve the following coding problem using the programming language python:
Given an array of N integers arr[ ], the task is to count the minimum number of operations to equalize the array i.e. to make all array elements equal.
In one operation, you can choose two elements arr[i] and arr[j] such that arr[i] > arr[j] and change them to arr[i] = arr[i] - 1 and arr[j] = arr[j] + 1.
If it is impossible to equalize the array print "-1".
Example 1:
Input:
N = 5
arr[] = {1, 3, 2, 0, 4}
Output: 3
Explanation: We can equalize the array by
making value of all elements equal to 2.
To achieve this we need to do minimum 3
operations:
1. arr[0]++ and arr[1]--
2. arr[3]++ and arr[4]--
3. arr[3]++ and arr[4]--
Example 2:
Input:
N = 3
arr[] = {1, 7, 1}
Output: 4
Your Task:
This is a function problem. You don't need to take any input, as it is already accomplished by the driver code. You just need to complete the function minOperations() that takes array arr[ ] and integer N as input parameters and returns the required answer.
Note - return -1, if it is not possible to equalize the array.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1).
Constraints:
1 β€ N β€ 10^{5}
Write your solution by modifying this code:
```python
#User function Template for python3
class Solution:
def findDifference(self,arr,N):
#Code here
```
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
class Solution:
def findDifference(self, arr, N):
s = sum(arr)
if s % N != 0:
return -1
ds = 0
e = s / n
for i in range(n):
ds += abs(arr[i] - e)
return int(ds / 2)
``` | vfc_135259 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/equalization-of-an-array1656/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 5\narr[] = {1, 3, 2, 0, 4}",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "N = 3\narr[] = {1, 7, 1}",
"output": "4",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1159/C | Solve the following coding problem using the programming language python:
n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 β€ i β€ n the minimal number of sweets, which i-th boy presented to some girl is equal to b_i and for all 1 β€ j β€ m the maximal number of sweets, which j-th girl received from some boy is equal to g_j.
More formally, let a_{i,j} be the number of sweets which the i-th boy give to the j-th girl. Then b_i is equal exactly to the minimum among values a_{i,1}, a_{i,2}, β¦, a_{i,m} and g_j is equal exactly to the maximum among values b_{1,j}, b_{2,j}, β¦, b_{n,j}.
You are interested in the minimum total number of sweets that boys could present, so you need to minimize the sum of a_{i,j} for all (i,j) such that 1 β€ i β€ n and 1 β€ j β€ m. You are given the numbers b_1, β¦, b_n and g_1, β¦, g_m, determine this number.
Input
The first line contains two integers n and m, separated with space β the number of boys and girls, respectively (2 β€ n, m β€ 100 000). The second line contains n integers b_1, β¦, b_n, separated by spaces β b_i is equal to the minimal number of sweets, which i-th boy presented to some girl (0 β€ b_i β€ 10^8). The third line contains m integers g_1, β¦, g_m, separated by spaces β g_j is equal to the maximal number of sweets, which j-th girl received from some boy (0 β€ g_j β€ 10^8).
Output
If the described situation is impossible, print -1. In another case, print the minimal total number of sweets, which boys could have presented and all conditions could have satisfied.
Examples
Input
3 2
1 2 1
3 4
Output
12
Input
2 2
0 1
1 0
Output
-1
Input
2 3
1 0
1 1 2
Output
4
Note
In the first test, the minimal total number of sweets, which boys could have presented is equal to 12. This can be possible, for example, if the first boy presented 1 and 4 sweets, the second boy presented 3 and 2 sweets and the third boy presented 1 and 1 sweets for the first and the second girl, respectively. It's easy to see, that all conditions are satisfied and the total number of sweets is equal to 12.
In the second test, the boys couldn't have presented sweets in such way, that all statements satisfied.
In the third test, the minimal total number of sweets, which boys could have presented is equal to 4. This can be possible, for example, if the first boy presented 1, 1, 2 sweets for the first, second, third girl, respectively and the second boy didn't present sweets for each girl. It's easy to see, that all conditions are satisfied and the total number of sweets is equal to 4.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
(n, m) = list(map(int, input().split()))
b = list(map(int, input().split()))
g = list(map(int, input().split()))
b.sort()
g.sort()
if b[-1] > g[0]:
print(-1)
elif b[-1] == g[0]:
print(sum(g) + m * (sum(b) - b[-1]))
elif n == 1:
print(-1)
else:
print(sum(g) + b[-1] + b[-2] * (m - 1) + m * (sum(b) - b[-1] - b[-2]))
``` | vfc_135260 | {
"difficulty": "medium",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1159/C",
"time_limit": "1.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2\n14419485 34715515\n45193875 34715515\n",
"output": "108748360\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2\n100000000 100000000\n0 0\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2\n217361 297931\n297930 83550501\n",
"output": "-1\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/139/C | Solve the following coding problem using the programming language python:
Vera adores poems. All the poems Vera knows are divided into quatrains (groups of four lines) and in each quatrain some lines contain rhymes.
Let's consider that all lines in the poems consist of lowercase Latin letters (without spaces). Letters "a", "e", "i", "o", "u" are considered vowels.
Two lines rhyme if their suffixes that start from the k-th vowels (counting from the end) match. If a line has less than k vowels, then such line can't rhyme with any other line. For example, if k = 1, lines commit and hermit rhyme (the corresponding suffixes equal it), and if k = 2, they do not rhyme (ommit β ermit).
Today on a literature lesson Vera learned that quatrains can contain four different schemes of rhymes, namely the following ones (the same letters stand for rhyming lines):
* Clerihew (aabb);
* Alternating (abab);
* Enclosed (abba).
If all lines of a quatrain pairwise rhyme, then the quatrain can belong to any rhyme scheme (this situation is represented by aaaa).
If all quatrains of a poem belong to the same rhyme scheme, then we can assume that the whole poem belongs to this rhyme scheme. If in each quatrain all lines pairwise rhyme, then the rhyme scheme of the poem is aaaa. Let us note that it doesn't matter whether lines from different quatrains rhyme with each other or not. In other words, it is possible that different quatrains aren't connected by a rhyme.
Vera got a long poem as a home task. The girl has to analyse it and find the poem rhyme scheme. Help Vera cope with the task.
Input
The first line contains two integers n and k (1 β€ n β€ 2500, 1 β€ k β€ 5) β the number of quatrains in the poem and the vowel's number, correspondingly. Next 4n lines contain the poem. Each line is not empty and only consists of small Latin letters. The total length of the lines does not exceed 104.
If we assume that the lines are numbered starting from 1, then the first quatrain contains lines number 1, 2, 3, 4; the second one contains lines number 5, 6, 7, 8; and so on.
Output
Print the rhyme scheme of the poem as "aabb", "abab", "abba", "aaaa"; or "NO" if the poem does not belong to any of the above mentioned schemes.
Examples
Input
1 1
day
may
sun
fun
Output
aabb
Input
1 1
day
may
gray
way
Output
aaaa
Input
2 1
a
a
a
a
a
a
e
e
Output
aabb
Input
2 1
day
may
sun
fun
test
hill
fest
thrill
Output
NO
Note
In the last sample both quatrains have rhymes but finding the common scheme is impossible, so the answer is "NO".
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase
def vsInput():
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = 'x' in file.mode or 'r' not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b'\n') + (not b)
ptr = self.buffer.tell()
(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
(self.buffer.truncate(0), self.buffer.seek(0))
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode('ascii'))
self.read = lambda : self.buffer.read().decode('ascii')
self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ALPHA = 'abcdefghijklmnopqrstuvwxyz'
M = 10 ** 9 + 7
EPS = 1e-06
def value():
return tuple(map(int, input().split()))
def array():
return [int(i) for i in input().split()]
def Int():
return int(input())
def Str():
return input()
def arrayS():
return [i for i in input().split()]
ACCEPTED = {'aaaa', 'aabb', 'abba', 'abab'}
vowels = 'aeiou'
nul = 'abcd'
nu = 0
def operate(s):
global nu
c = 0
for i in range(len(s) - 1, -1, -1):
if s[i] in vowels:
c += 1
if c == k:
return s[i:]
nu = (nu + 1) % 4
return nul[nu]
def rhymes(a):
a = [operate(i) for i in a]
ID = {}
id = 0
ans = ''
for i in a:
if i not in ID:
ID[i] = nul[id]
id += 1
ans += ID[i]
return ans
(n, k) = value()
scheme = set()
for i in range(n):
a = []
for j in range(4):
a.append(input())
scheme.add(rhymes(a))
for i in scheme:
if i not in ACCEPTED:
print('NO')
exit()
if len(scheme) > 2:
print('NO')
elif len(scheme) == 2:
if 'aaaa' not in scheme:
print('NO')
else:
for i in scheme:
if i != 'aaaa':
print(i)
else:
print(*scheme)
``` | vfc_135264 | {
"difficulty": "medium_hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/139/C",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 2\netba\ntfecetba\nzkitbgcuuy\nuuy\nbuxeoi\nmekxoi\nblviwoehy\niwoehy\njyfpaqntiz\nqvaqntiz\nhciak\niak\n",
"output": "aabb\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1\na\na\na\na\na\nb\nb\nb\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1\ne\ne\ne\ne\n",
"output": "aaaa\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2\nexdaoao\nrdwunurp\ndunurp\ntyqzuxao\ndupocgsps\nzsiravcm\nnqiravcm\nlnupocgsps\niwashk\neepkqcykbv\nyviwashk\neepkqcykbv\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 4\naieoabcd\naeioabcd\naoeiabcd\naoieabcd\n",
"output": "NO\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/990/A | Solve the following coding problem using the programming language python:
Berland Football Cup starts really soon! Commentators from all over the world come to the event.
Organizers have already built $n$ commentary boxes. $m$ regional delegations will come to the Cup. Every delegation should get the same number of the commentary boxes. If any box is left unoccupied then the delegations will be upset. So each box should be occupied by exactly one delegation.
If $n$ is not divisible by $m$, it is impossible to distribute the boxes to the delegations at the moment.
Organizers can build a new commentary box paying $a$ burles and demolish a commentary box paying $b$ burles. They can both build and demolish boxes arbitrary number of times (each time paying a corresponding fee). It is allowed to demolish all the existing boxes.
What is the minimal amount of burles organizers should pay to satisfy all the delegations (i.e. to make the number of the boxes be divisible by $m$)?
-----Input-----
The only line contains four integer numbers $n$, $m$, $a$ and $b$ ($1 \le n, m \le 10^{12}$, $1 \le a, b \le 100$), where $n$ is the initial number of the commentary boxes, $m$ is the number of delegations to come, $a$ is the fee to build a box and $b$ is the fee to demolish a box.
-----Output-----
Output the minimal amount of burles organizers should pay to satisfy all the delegations (i.e. to make the number of the boxes be divisible by $m$). It is allowed that the final number of the boxes is equal to $0$.
-----Examples-----
Input
9 7 3 8
Output
15
Input
2 7 3 7
Output
14
Input
30 6 17 19
Output
0
-----Note-----
In the first example organizers can build $5$ boxes to make the total of $14$ paying $3$ burles for the each of them.
In the second example organizers can demolish $2$ boxes to make the total of $0$ paying $7$ burles for the each of them.
In the third example organizers are already able to distribute all the boxes equally among the delegations, each one get $5$ boxes.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import sys
import math
get_string = lambda : sys.stdin.readline().strip()
get_int_list = lambda : list(map(int, sys.stdin.readline().strip().split()))
get_int = lambda : int(sys.stdin.readline())
(n, m, a, b) = get_int_list()
if n % m == 0:
print(0)
else:
res1 = n % m
res2 = m - res1
if res1 * b < res2 * a:
print(res1 * b)
else:
print(res2 * a)
``` | vfc_135270 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/990/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "9 7 3 8\n",
"output": "15\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 7 3 7\n",
"output": "14\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "30 6 17 19\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "500000000001 1000000000000 100 100\n",
"output": "49999999999900\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/960/C | Solve the following coding problem using the programming language python:
Pikachu had an array with him. He wrote down all the non-empty subsequences of the array on paper. Note that an array of size n has 2^{n} - 1 non-empty subsequences in it.
Pikachu being mischievous as he always is, removed all the subsequences in which Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ d
Pikachu was finally left with X subsequences.
However, he lost the initial array he had, and now is in serious trouble. He still remembers the numbers X and d. He now wants you to construct any such array which will satisfy the above conditions. All the numbers in the final array should be positive integers less than 10^18.
Note the number of elements in the output array should not be more than 10^4. If no answer is possible, print - 1.
-----Input-----
The only line of input consists of two space separated integers X and d (1 β€ X, d β€ 10^9).
-----Output-----
Output should consist of two lines.
First line should contain a single integer n (1 β€ n β€ 10 000)β the number of integers in the final array.
Second line should consist of n space separated integers β a_1, a_2, ... , a_{n} (1 β€ a_{i} < 10^18).
If there is no answer, print a single integer -1. If there are multiple answers, print any of them.
-----Examples-----
Input
10 5
Output
6
5 50 7 15 6 100
Input
4 2
Output
4
10 100 1000 10000
-----Note-----
In the output of the first example case, the remaining subsequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ 5 are [5], [5, 7], [5, 6], [5, 7, 6], [50], [7], [7, 6], [15], [6], [100]. There are 10 of them. Hence, the array [5, 50, 7, 15, 6, 100] is valid.
Similarly, in the output of the second example case, the remaining sub-sequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence β₯ 2 are [10], [100], [1000], [10000]. There are 4 of them. Hence, the array [10, 100, 1000, 10000] is valid.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
p2 = [(i, 2 ** i - 1) for i in range(1, 40)]
(X, d) = map(int, input().split(' '))
lens = []
for i in p2[::-1]:
if X >= i[1]:
X -= i[1]
lens.append(i[0])
el = 1
if sum(lens) >= 10000:
print(-1)
exit(0)
print(sum(lens) + X)
for i in lens:
print((str(el) + ' ') * i, end='')
el += d
for i in range(X):
print(el, end=' ')
el += d
``` | vfc_135274 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/960/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10 5\n",
"output": "6\n1 1 1 7 13 19 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 2\n",
"output": "3\n1 1 4 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 1\n",
"output": "3\n1 1 3 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1\n",
"output": "1\n1 ",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/INDC2021/problems/NAV28 | Solve the following coding problem using the programming language python:
Navnit is a college student and there are $N$ students in his college .Students are numbered from $1$ to $N$.
You are given $M$ facts that "Student $A_i$ and $B_i$".The same fact can be given multiple times .If $A_i$ is a friend of $B_i$ ,then $B_i$ is also a friend of $A_i$ . If $A_i$ is a friend of $B_i$ and $B_i$ is a friend of $C_i$ then $A_i$ is also a friend of $C_i$.
Find number of ways in which two students can be selected in such a way that they are not friends.
-----Input:-----
- First line will contain two integers $N$ and $M$.
- Then $M$ lines follow. Each line contains two integers $A_i$ and $B_i$ denoting the students who are friends.
-----Output:-----
For each testcase, output the number of ways in which two students can be selected in such a way that they are friends.
-----Constraints-----
- $2 \leq N \leq 200000$
- $0 \leq M \leq 200000$
- $1 \leq A_i,B_i \leq N$
-----Sample Input:-----
5 3
1 2
3 4
1 5
-----Sample Output:-----
6
-----EXPLANATION:-----
Groups of friend are $[1,2,5]$ and $[3,4]$.Hence the answer is 3 X 2 =6.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
from collections import defaultdict
d = defaultdict(list)
def dfs(i):
p = 0
nonlocal v
e = [i]
while e != []:
p += 1
x = e.pop(0)
v[x] = 1
for i in d[x]:
if v[i] == -1:
v[i] = 1
e.append(i)
return p
(n, m) = list(map(int, input().split()))
for i in range(n + 1):
d[i] = []
for _ in range(m):
(a, b) = list(map(int, input().split()))
d[a].append(b)
d[b].append(a)
v = []
for i in range(n + 1):
v.append(-1)
c = 0
p = []
for i in range(1, n + 1):
if v[i] == -1:
c += 1
p.append(dfs(i))
an = 0
s = 0
for i in range(c):
s += p[i]
an += p[i] * (n - s)
print(an)
``` | vfc_135278 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/INDC2021/problems/NAV28",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 3\n1 2\n3 4\n1 5\n",
"output": "6\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Roy has a matrix of size NxN. Rows and Columns are numbered from 0 to N-1.
j^th column of i^th row contains i xor j.
In other words, Matrix[i][j] = i ^ j where 0 β€ i,j < N. ( ^ is a bitwise operation used in C/C++ for xor, please use appropriate symbol if you're using any other language)
Your task is to find the maximum value occurring in this matrix and the count of its occurrence.
Input:
First line contains T - number of test cases
Following T lines each contains an integer N - size of matrix
Output:
For each test case output the maximum value and its count separated by a space in a new line.
Constraints:
1 β€ T β€ 100000 (10^5 )
1 β€ N β€ 1000000000000000000 ( 10^18 )
SAMPLE INPUT
2
2
3SAMPLE OUTPUT
1 2
3 2Explanation
For N=2, Matrix will look like:
0 1
1 0
Maximum value in this matrix is 1 and it occurs 2 times.
For N=3, Matrix will look like:
0 1 2
1 0 3
2 3 0
Maximum value in this matrix is 3 and it occurs 2 times.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
from math import log,floor
for _ in range(int(input())):
n=int(input())
if n==1:
print("0 1")
continue
t=log(n-1,2)
x=int(floor(t))
print("%d %d"%(2**(x+1) -1,2*(n-2**(x))))
``` | vfc_135282 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "36\n10\n9\n100\n99\n1000\n999\n10000\n9999\n100000\n99999\n1000000\n999999\n10000000\n9999999\n100000000\n99999999\n1000000000\n999999999\n10000000000\n9999999999\n100000000000\n99999999999\n1000000000000\n999999999999\n10000000000000\n9999999999999\n100000000000000\n99999999999999\n1000000000000000\n999999999999999\n10000000000000000\n9999999999999999\n100000000000000000\n99999999999999999\n1000000000000000000\n999999999999999999\n",
"output": "0 1\n1 2\n3 2\n3 4\n7 2\n7 4\n7 6\n7 8\n15 2\n15 4\n15 6\n15 8\n15 10\n15 12\n15 14\n15 16\n31 2\n31 4\n31 6\n31 8\n31 10\n31 12\n31 14\n31 16\n31 18\n31 20\n31 22\n31 24\n31 26\n31 28\n31 30\n31 32\n63 2\n63 4\n63 6\n63 8\n63 10\n63 12\n63 14\n63 16\n63 18\n63 20\n63 22\n63 24\n63 26\n63 28\n63 30\n63 32\n63 34\n63 36\n63 38\n63 40\n63 42\n63 44\n63 46\n63 48\n63 50\n63 52\n63 54\n63 56\n63 58\n63 60\n63 62\n63 64\n127 2\n127 4\n127 6\n127 8\n127 10\n127 12\n127 14\n127 16\n127 18\n127 20\n127 22\n127 24\n127 26\n127 28\n127 30\n127 32\n127 34\n127 36\n127 38\n127 40\n127 42\n127 44\n127 46\n127 48\n127 50\n127 52\n127 54\n127 56\n127 58\n127 60\n127 62\n127 64\n127 66\n127 68\n127 70\n127 72\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "900\n101\n102\n103\n104\n105\n106\n107\n108\n109\n110\n111\n112\n113\n114\n115\n116\n117\n118\n119\n120\n121\n122\n123\n124\n125\n126\n127\n128\n129\n130\n131\n132\n133\n134\n135\n136\n137\n138\n139\n140\n141\n142\n143\n144\n145\n146\n147\n148\n149\n150\n151\n152\n153\n154\n155\n156\n157\n158\n159\n160\n161\n162\n163\n164\n165\n166\n167\n168\n169\n170\n171\n172\n173\n174\n175\n176\n177\n178\n179\n180\n181\n182\n183\n184\n185\n186\n187\n188\n189\n190\n191\n192\n193\n194\n195\n196\n197\n198\n199\n200\n201\n202\n203\n204\n205\n206\n207\n208\n209\n210\n211\n212\n213\n214\n215\n216\n217\n218\n219\n220\n221\n222\n223\n224\n225\n226\n227\n228\n229\n230\n231\n232\n233\n234\n235\n236\n237\n238\n239\n240\n241\n242\n243\n244\n245\n246\n247\n248\n249\n250\n251\n252\n253\n254\n255\n256\n257\n258\n259\n260\n261\n262\n263\n264\n265\n266\n267\n268\n269\n270\n271\n272\n273\n274\n275\n276\n277\n278\n279\n280\n281\n282\n283\n284\n285\n286\n287\n288\n289\n290\n291\n292\n293\n294\n295\n296\n297\n298\n299\n300\n301\n302\n303\n304\n305\n306\n307\n308\n309\n310\n311\n312\n313\n314\n315\n316\n317\n318\n319\n320\n321\n322\n323\n324\n325\n326\n327\n328\n329\n330\n331\n332\n333\n334\n335\n336\n337\n338\n339\n340\n341\n342\n343\n344\n345\n346\n347\n348\n349\n350\n351\n352\n353\n354\n355\n356\n357\n358\n359\n360\n361\n362\n363\n364\n365\n366\n367\n368\n369\n370\n371\n372\n373\n374\n375\n376\n377\n378\n379\n380\n381\n382\n383\n384\n385\n386\n387\n388\n389\n390\n391\n392\n393\n394\n395\n396\n397\n398\n399\n400\n401\n402\n403\n404\n405\n406\n407\n408\n409\n410\n411\n412\n413\n414\n415\n416\n417\n418\n419\n420\n421\n422\n423\n424\n425\n426\n427\n428\n429\n430\n431\n432\n433\n434\n435\n436\n437\n438\n439\n440\n441\n442\n443\n444\n445\n446\n447\n448\n449\n450\n451\n452\n453\n454\n455\n456\n457\n458\n459\n460\n461\n462\n463\n464\n465\n466\n467\n468\n469\n470\n471\n472\n473\n474\n475\n476\n477\n478\n479\n480\n481\n482\n483\n484\n485\n486\n487\n488\n489\n490\n491\n492\n493\n494\n495\n496\n497\n498\n499\n500\n501\n502\n503\n504\n505\n506\n507\n508\n509\n510\n511\n512\n513\n514\n515\n516\n517\n518\n519\n520\n521\n522\n523\n524\n525\n526\n527\n528\n529\n530\n531\n532\n533\n534\n535\n536\n537\n538\n539\n540\n541\n542\n543\n544\n545\n546\n547\n548\n549\n550\n551\n552\n553\n554\n555\n556\n557\n558\n559\n560\n561\n562\n563\n564\n565\n566\n567\n568\n569\n570\n571\n572\n573\n574\n575\n576\n577\n578\n579\n580\n581\n582\n583\n584\n585\n586\n587\n588\n589\n590\n591\n592\n593\n594\n595\n596\n597\n598\n599\n600\n601\n602\n603\n604\n605\n606\n607\n608\n609\n610\n611\n612\n613\n614\n615\n616\n617\n618\n619\n620\n621\n622\n623\n624\n625\n626\n627\n628\n629\n630\n631\n632\n633\n634\n635\n636\n637\n638\n639\n640\n641\n642\n643\n644\n645\n646\n647\n648\n649\n650\n651\n652\n653\n654\n655\n656\n657\n658\n659\n660\n661\n662\n663\n664\n665\n666\n667\n668\n669\n670\n671\n672\n673\n674\n675\n676\n677\n678\n679\n680\n681\n682\n683\n684\n685\n686\n687\n688\n689\n690\n691\n692\n693\n694\n695\n696\n697\n698\n699\n700\n701\n702\n703\n704\n705\n706\n707\n708\n709\n710\n711\n712\n713\n714\n715\n716\n717\n718\n719\n720\n721\n722\n723\n724\n725\n726\n727\n728\n729\n730\n731\n732\n733\n734\n735\n736\n737\n738\n739\n740\n741\n742\n743\n744\n745\n746\n747\n748\n749\n750\n751\n752\n753\n754\n755\n756\n757\n758\n759\n760\n761\n762\n763\n764\n765\n766\n767\n768\n769\n770\n771\n772\n773\n774\n775\n776\n777\n778\n779\n780\n781\n782\n783\n784\n785\n786\n787\n788\n789\n790\n791\n792\n793\n794\n795\n796\n797\n798\n799\n800\n801\n802\n803\n804\n805\n806\n807\n808\n809\n810\n811\n812\n813\n814\n815\n816\n817\n818\n819\n820\n821\n822\n823\n824\n825\n826\n827\n828\n829\n830\n831\n832\n833\n834\n835\n836\n837\n838\n839\n840\n841\n842\n843\n844\n845\n846\n847\n848\n849\n850\n851\n852\n853\n854\n855\n856\n857\n858\n859\n860\n861\n862\n863\n864\n865\n866\n867\n868\n869\n870\n871\n872\n873\n874\n875\n876\n877\n878\n879\n880\n881\n882\n883\n884\n885\n886\n887\n888\n889\n890\n891\n892\n893\n894\n895\n896\n897\n898\n899\n900\n901\n902\n903\n904\n905\n906\n907\n908\n909\n910\n911\n912\n913\n914\n915\n916\n917\n918\n919\n920\n921\n922\n923\n924\n925\n926\n927\n928\n929\n930\n931\n932\n933\n934\n935\n936\n937\n938\n939\n940\n941\n942\n943\n944\n945\n946\n947\n948\n949\n950\n951\n952\n953\n954\n955\n956\n957\n958\n959\n960\n961\n962\n963\n964\n965\n966\n967\n968\n969\n970\n971\n972\n973\n974\n975\n976\n977\n978\n979\n980\n981\n982\n983\n984\n985\n986\n987\n988\n989\n990\n991\n992\n993\n994\n995\n996\n997\n998\n999\n1000\n",
"output": "127 74\n127 76\n127 78\n127 80\n127 82\n127 84\n127 86\n127 88\n127 90\n127 92\n127 94\n127 96\n127 98\n127 100\n127 102\n127 104\n127 106\n127 108\n127 110\n127 112\n127 114\n127 116\n127 118\n127 120\n127 122\n127 124\n127 126\n127 128\n255 2\n255 4\n255 6\n255 8\n255 10\n255 12\n255 14\n255 16\n255 18\n255 20\n255 22\n255 24\n255 26\n255 28\n255 30\n255 32\n255 34\n255 36\n255 38\n255 40\n255 42\n255 44\n255 46\n255 48\n255 50\n255 52\n255 54\n255 56\n255 58\n255 60\n255 62\n255 64\n255 66\n255 68\n255 70\n255 72\n255 74\n255 76\n255 78\n255 80\n255 82\n255 84\n255 86\n255 88\n255 90\n255 92\n255 94\n255 96\n255 98\n255 100\n255 102\n255 104\n255 106\n255 108\n255 110\n255 112\n255 114\n255 116\n255 118\n255 120\n255 122\n255 124\n255 126\n255 128\n255 130\n255 132\n255 134\n255 136\n255 138\n255 140\n255 142\n255 144\n255 146\n255 148\n255 150\n255 152\n255 154\n255 156\n255 158\n255 160\n255 162\n255 164\n255 166\n255 168\n255 170\n255 172\n255 174\n255 176\n255 178\n255 180\n255 182\n255 184\n255 186\n255 188\n255 190\n255 192\n255 194\n255 196\n255 198\n255 200\n255 202\n255 204\n255 206\n255 208\n255 210\n255 212\n255 214\n255 216\n255 218\n255 220\n255 222\n255 224\n255 226\n255 228\n255 230\n255 232\n255 234\n255 236\n255 238\n255 240\n255 242\n255 244\n255 246\n255 248\n255 250\n255 252\n255 254\n255 256\n511 2\n511 4\n511 6\n511 8\n511 10\n511 12\n511 14\n511 16\n511 18\n511 20\n511 22\n511 24\n511 26\n511 28\n511 30\n511 32\n511 34\n511 36\n511 38\n511 40\n511 42\n511 44\n511 46\n511 48\n511 50\n511 52\n511 54\n511 56\n511 58\n511 60\n511 62\n511 64\n511 66\n511 68\n511 70\n511 72\n511 74\n511 76\n511 78\n511 80\n511 82\n511 84\n511 86\n511 88\n511 90\n511 92\n511 94\n511 96\n511 98\n511 100\n511 102\n511 104\n511 106\n511 108\n511 110\n511 112\n511 114\n511 116\n511 118\n511 120\n511 122\n511 124\n511 126\n511 128\n511 130\n511 132\n511 134\n511 136\n511 138\n511 140\n511 142\n511 144\n511 146\n511 148\n511 150\n511 152\n511 154\n511 156\n511 158\n511 160\n511 162\n511 164\n511 166\n511 168\n511 170\n511 172\n511 174\n511 176\n511 178\n511 180\n511 182\n511 184\n511 186\n511 188\n511 190\n511 192\n511 194\n511 196\n511 198\n511 200\n511 202\n511 204\n511 206\n511 208\n511 210\n511 212\n511 214\n511 216\n511 218\n511 220\n511 222\n511 224\n511 226\n511 228\n511 230\n511 232\n511 234\n511 236\n511 238\n511 240\n511 242\n511 244\n511 246\n511 248\n511 250\n511 252\n511 254\n511 256\n511 258\n511 260\n511 262\n511 264\n511 266\n511 268\n511 270\n511 272\n511 274\n511 276\n511 278\n511 280\n511 282\n511 284\n511 286\n511 288\n511 290\n511 292\n511 294\n511 296\n511 298\n511 300\n511 302\n511 304\n511 306\n511 308\n511 310\n511 312\n511 314\n511 316\n511 318\n511 320\n511 322\n511 324\n511 326\n511 328\n511 330\n511 332\n511 334\n511 336\n511 338\n511 340\n511 342\n511 344\n511 346\n511 348\n511 350\n511 352\n511 354\n511 356\n511 358\n511 360\n511 362\n511 364\n511 366\n511 368\n511 370\n511 372\n511 374\n511 376\n511 378\n511 380\n511 382\n511 384\n511 386\n511 388\n511 390\n511 392\n511 394\n511 396\n511 398\n511 400\n511 402\n511 404\n511 406\n511 408\n511 410\n511 412\n511 414\n511 416\n511 418\n511 420\n511 422\n511 424\n511 426\n511 428\n511 430\n511 432\n511 434\n511 436\n511 438\n511 440\n511 442\n511 444\n511 446\n511 448\n511 450\n511 452\n511 454\n511 456\n511 458\n511 460\n511 462\n511 464\n511 466\n511 468\n511 470\n511 472\n511 474\n511 476\n511 478\n511 480\n511 482\n511 484\n511 486\n511 488\n511 490\n511 492\n511 494\n511 496\n511 498\n511 500\n511 502\n511 504\n511 506\n511 508\n511 510\n511 512\n1023 2\n1023 4\n1023 6\n1023 8\n1023 10\n1023 12\n1023 14\n1023 16\n1023 18\n1023 20\n1023 22\n1023 24\n1023 26\n1023 28\n1023 30\n1023 32\n1023 34\n1023 36\n1023 38\n1023 40\n1023 42\n1023 44\n1023 46\n1023 48\n1023 50\n1023 52\n1023 54\n1023 56\n1023 58\n1023 60\n1023 62\n1023 64\n1023 66\n1023 68\n1023 70\n1023 72\n1023 74\n1023 76\n1023 78\n1023 80\n1023 82\n1023 84\n1023 86\n1023 88\n1023 90\n1023 92\n1023 94\n1023 96\n1023 98\n1023 100\n1023 102\n1023 104\n1023 106\n1023 108\n1023 110\n1023 112\n1023 114\n1023 116\n1023 118\n1023 120\n1023 122\n1023 124\n1023 126\n1023 128\n1023 130\n1023 132\n1023 134\n1023 136\n1023 138\n1023 140\n1023 142\n1023 144\n1023 146\n1023 148\n1023 150\n1023 152\n1023 154\n1023 156\n1023 158\n1023 160\n1023 162\n1023 164\n1023 166\n1023 168\n1023 170\n1023 172\n1023 174\n1023 176\n1023 178\n1023 180\n1023 182\n1023 184\n1023 186\n1023 188\n1023 190\n1023 192\n1023 194\n1023 196\n1023 198\n1023 200\n1023 202\n1023 204\n1023 206\n1023 208\n1023 210\n1023 212\n1023 214\n1023 216\n1023 218\n1023 220\n1023 222\n1023 224\n1023 226\n1023 228\n1023 230\n1023 232\n1023 234\n1023 236\n1023 238\n1023 240\n1023 242\n1023 244\n1023 246\n1023 248\n1023 250\n1023 252\n1023 254\n1023 256\n1023 258\n1023 260\n1023 262\n1023 264\n1023 266\n1023 268\n1023 270\n1023 272\n1023 274\n1023 276\n1023 278\n1023 280\n1023 282\n1023 284\n1023 286\n1023 288\n1023 290\n1023 292\n1023 294\n1023 296\n1023 298\n1023 300\n1023 302\n1023 304\n1023 306\n1023 308\n1023 310\n1023 312\n1023 314\n1023 316\n1023 318\n1023 320\n1023 322\n1023 324\n1023 326\n1023 328\n1023 330\n1023 332\n1023 334\n1023 336\n1023 338\n1023 340\n1023 342\n1023 344\n1023 346\n1023 348\n1023 350\n1023 352\n1023 354\n1023 356\n1023 358\n1023 360\n1023 362\n1023 364\n1023 366\n1023 368\n1023 370\n1023 372\n1023 374\n1023 376\n1023 378\n1023 380\n1023 382\n1023 384\n1023 386\n1023 388\n1023 390\n1023 392\n1023 394\n1023 396\n1023 398\n1023 400\n1023 402\n1023 404\n1023 406\n1023 408\n1023 410\n1023 412\n1023 414\n1023 416\n1023 418\n1023 420\n1023 422\n1023 424\n1023 426\n1023 428\n1023 430\n1023 432\n1023 434\n1023 436\n1023 438\n1023 440\n1023 442\n1023 444\n1023 446\n1023 448\n1023 450\n1023 452\n1023 454\n1023 456\n1023 458\n1023 460\n1023 462\n1023 464\n1023 466\n1023 468\n1023 470\n1023 472\n1023 474\n1023 476\n1023 478\n1023 480\n1023 482\n1023 484\n1023 486\n1023 488\n1023 490\n1023 492\n1023 494\n1023 496\n1023 498\n1023 500\n1023 502\n1023 504\n1023 506\n1023 508\n1023 510\n1023 512\n1023 514\n1023 516\n1023 518\n1023 520\n1023 522\n1023 524\n1023 526\n1023 528\n1023 530\n1023 532\n1023 534\n1023 536\n1023 538\n1023 540\n1023 542\n1023 544\n1023 546\n1023 548\n1023 550\n1023 552\n1023 554\n1023 556\n1023 558\n1023 560\n1023 562\n1023 564\n1023 566\n1023 568\n1023 570\n1023 572\n1023 574\n1023 576\n1023 578\n1023 580\n1023 582\n1023 584\n1023 586\n1023 588\n1023 590\n1023 592\n1023 594\n1023 596\n1023 598\n1023 600\n1023 602\n1023 604\n1023 606\n1023 608\n1023 610\n1023 612\n1023 614\n1023 616\n1023 618\n1023 620\n1023 622\n1023 624\n1023 626\n1023 628\n1023 630\n1023 632\n1023 634\n1023 636\n1023 638\n1023 640\n1023 642\n1023 644\n1023 646\n1023 648\n1023 650\n1023 652\n1023 654\n1023 656\n1023 658\n1023 660\n1023 662\n1023 664\n1023 666\n1023 668\n1023 670\n1023 672\n1023 674\n1023 676\n1023 678\n1023 680\n1023 682\n1023 684\n1023 686\n1023 688\n1023 690\n1023 692\n1023 694\n1023 696\n1023 698\n1023 700\n1023 702\n1023 704\n1023 706\n1023 708\n1023 710\n1023 712\n1023 714\n1023 716\n1023 718\n1023 720\n1023 722\n1023 724\n1023 726\n1023 728\n1023 730\n1023 732\n1023 734\n1023 736\n1023 738\n1023 740\n1023 742\n1023 744\n1023 746\n1023 748\n1023 750\n1023 752\n1023 754\n1023 756\n1023 758\n1023 760\n1023 762\n1023 764\n1023 766\n1023 768\n1023 770\n1023 772\n1023 774\n1023 776\n1023 778\n1023 780\n1023 782\n1023 784\n1023 786\n1023 788\n1023 790\n1023 792\n1023 794\n1023 796\n1023 798\n1023 800\n1023 802\n1023 804\n1023 806\n1023 808\n1023 810\n1023 812\n1023 814\n1023 816\n1023 818\n1023 820\n1023 822\n1023 824\n1023 826\n1023 828\n1023 830\n1023 832\n1023 834\n1023 836\n1023 838\n1023 840\n1023 842\n1023 844\n1023 846\n1023 848\n1023 850\n1023 852\n1023 854\n1023 856\n1023 858\n1023 860\n1023 862\n1023 864\n1023 866\n1023 868\n1023 870\n1023 872\n1023 874\n1023 876\n1023 878\n1023 880\n1023 882\n1023 884\n1023 886\n1023 888\n1023 890\n1023 892\n1023 894\n1023 896\n1023 898\n1023 900\n1023 902\n1023 904\n1023 906\n1023 908\n1023 910\n1023 912\n1023 914\n1023 916\n1023 918\n1023 920\n1023 922\n1023 924\n1023 926\n1023 928\n1023 930\n1023 932\n1023 934\n1023 936\n1023 938\n1023 940\n1023 942\n1023 944\n1023 946\n1023 948\n1023 950\n1023 952\n1023 954\n1023 956\n1023 958\n1023 960\n1023 962\n1023 964\n1023 966\n1023 968\n1023 970\n1023 972\n1023 974\n1023 976\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "100\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n44\n45\n46\n47\n48\n49\n50\n51\n52\n53\n54\n55\n56\n57\n58\n59\n60\n61\n62\n63\n64\n65\n66\n67\n68\n69\n70\n71\n72\n73\n74\n75\n76\n77\n78\n79\n80\n81\n82\n83\n84\n85\n86\n87\n88\n89\n90\n91\n92\n93\n94\n95\n96\n97\n98\n99\n100\n",
"output": "15 4\n15 2\n127 72\n127 70\n1023 976\n1023 974\n16383 3616\n16383 3614\n131071 68928\n131071 68926\n1048575 951424\n1048575 951422\n16777215 3222784\n16777215 3222782\n134217727 65782272\n134217727 65782270\n1073741823 926258176\n1073741823 926258174\n17179869183 2820130816\n17179869183 2820130814\n137438953471 62561046528\n137438953471 62561046526\n1099511627775 900488372224\n1099511627775 900488372222\n17592186044415 2407813955584\n17592186044415 2407813955582\n140737488355327 59262511644672\n140737488355327 59262511644670\n1125899906842623 874100093157376\n1125899906842623 874100093157374\n18014398509481983 1985601490518016\n18014398509481983 1985601490518014\n144115188075855871 55884811924144128\n144115188075855871 55884811924144126\n1152921504606846975 847078495393153024\n1152921504606846975 847078495393153022\n",
"type": "stdin_stdout"
}
]
} |
|
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/max-sum-in-the-configuration/1 | Solve the following coding problem using the programming language python:
Given an array(0-based indexing), you have to find the max sum of i*A[i] where A[i] is the element at index i in the array. The only operation allowed is to rotate(clock-wise or counter clock-wise) the array any number of times.
Example 1:
Input:
N = 4
A[] = {8,3,1,2}
Output: 29
Explanation: Above the configuration
possible by rotating elements are
3 1 2 8 here sum is 3*0+1*1+2*2+8*3 = 29
1 2 8 3 here sum is 1*0+2*1+8*2+3*3 = 27
2 8 3 1 here sum is 2*0+8*1+3*2+1*3 = 17
8 3 1 2 here sum is 8*0+3*1+1*2+2*3 = 11
Here the max sum is 29
Your Task:
Your task is to complete the function max_sum which takes two arguments which is the array A [ ] and its size and returns an integer value denoting the required max sum.
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(1).
Constraints:
1<=N<=10^{4}
1<=A[]<1000
Write your solution by modifying this code:
```python
#User function Template for python3
def max_sum(a,n):
#code here
```
Your solution should implemented in the function "max_sum". The inputs will be passed to it and it should return the correct solution.
Now solve the problem and return the code. | ```python
def max_sum(a, n):
total_sum = 0
product_sum = 0
if n == 1:
return 0
for i in range(n):
total_sum += a[i]
product_sum += a[i] * i
max_product = product_sum
for i in range(n - 1, -1, -1):
product_sum = product_sum + total_sum - a[i] * n
max_product = max(max_product, product_sum)
return max_product
``` | vfc_135287 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/max-sum-in-the-configuration/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": "max_sum",
"input": "N = 4\nA[] = {8,3,1,2}",
"output": "29",
"type": "function_call"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/count-number-of-elements-between-two-given-elements-in-array4044/1 | Solve the following coding problem using the programming language python:
Given an unsorted array and two elements num1 and num2. The task is to count the number of elements occurs between the given elements (excluding num1 and num2). If there are multiple occurrences of num1 and num2, we need to consider leftmost occurrence of num1 and rightmost occurrence of num2.
Example 1:
Input : Arr[] = {4, 2, 1, 10, 6}
num1 = 4 and num2 = 6
Output : 3
Explanation:
We have an array [4, 2, 1, 10, 6] and
num1 = 4 and num2 = 6.
So, the left most index of num1 is 0 and
rightmost index of num2 is 4.
So, the total number of element between
them is [2, 1, 10] So, function will return
3 as an answer.
Example 2:
Input : Arr[] = {3, 2, 1, 4}
num1 = 2 and num2 = 4
Output : 1
Your Task:
This is a function problem. The input is already taken care of by the driver code. You only need to complete the function getCount() that takes an array (arr), sizeOfArray (n), integer num1, integer num2, and return the number of elements between these numbers. The driver code takes care of the printing.
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(1).
Constraints:
2 β€ N β€ 10^{5}
1 β€ A[i], num1, num2 β€ 10^{5}
Write your solution by modifying this code:
```python
#User function Template for python3
class Solution:
def getCount(self,arr, n, num1, num2):
#Comlete the function
```
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
class Solution:
def getCount(self, arr, n, num1, num2):
l = arr.index(num1)
r = len(arr) - 1 - arr[::-1].index(num2)
count = 0
for i in range(l + 1, r):
count += 1
return count
``` | vfc_135288 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/count-number-of-elements-between-two-given-elements-in-array4044/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "Arr[] = {4, 2, 1, 10, 6}\nnum1 = 4 and num2 = 6",
"output": "3",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/closest-palindrome4519/1 | Solve the following coding problem using the programming language python:
Given a number num, our task is to find the closest Palindrome number whose absolute difference with given number is minimum. If 2 Palindome numbers have same absolute difference from the given number, then find the smaller one.
Example 1:
Input: num = 9
Output: 9
Explanation: 9 itself is a palindrome
number.
Example 2:
Input: num = 489
Output: 484
Expnataion: closest palindrome numbers from
489 are 484 and 494. Absolute difference between
489 and 494 is equal to the absolute difference
between 484 and 489 but 484 is smaller than 494.
Your Task:
You don't need to read or print anyhting. Your task is to complete the function closestPalindrome() which takes num as input parameter and returns the closest palindrome.
Expected Time Complexity: O(log_{10}num)
Expected Space Complexity: O(1)
Constraints:
1 <= num <= 10^{14}
Write your solution by modifying this code:
```python
#User function Template for python3
class Solution:
def closestPalindrome(self, num):
# Code here
```
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import math
class Solution:
def closestPalindrome(self, n):
n = int(n)
if n < 10:
return n
elif math.log(n, 10) - int(math.log(n, 10)) == 0:
return n - 1
else:
out = str(n)
ll = int((len(out) + 1) / 2)
first_Half = out[:ll]
if len(out) % 2 == 0:
n1 = int(first_Half + first_Half[::-1])
n2 = int(str(int(first_Half) + 1) + str(int(first_Half) + 1)[::-1])
n3 = int(str(int(first_Half) - 1) + str(int(first_Half) - 1)[::-1])
else:
n1 = int(first_Half[:-1] + first_Half[::-1])
n2 = int(str(int(first_Half) + 1)[:-1] + str(int(first_Half) + 1)[::-1])
n3 = int(str(int(first_Half) - 1)[:-1] + str(int(first_Half) - 1)[::-1])
if abs(n - n3) <= abs(n - n1) and abs(n - n3) <= abs(n - n2):
out = n3
elif abs(n - n1) <= abs(n - n2):
out = n1
else:
out = n2
return out
``` | vfc_135289 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/closest-palindrome4519/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "num = 9",
"output": "9",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "num = 489",
"output": "484",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/CAKEDOOM | Solve the following coding problem using the programming language python:
From the FAQ:
What am I allowed to post as a comment for a problem?
Do NOT post code.
Do NOT post a comment asking why your solution is wrong.
Do NOT post a comment asking if you can be given the test case your program fails on.
Do NOT post a comment asking how your solution can be improved.
Do NOT post a comment giving any hints or discussing approaches to the problem, or what type or speed of algorithm is required.
------ Problem Statement ------
Chef Doom has decided to bake a circular cake. He wants to place N colored cherries around the cake in a circular manner. As all great chefs do, Doom doesn't want any two adjacent cherries to have the same color. Chef has unlimited supply of cherries of K β€ 10 different colors. Each color is denoted by the digit from the set {0, 1, ..., K β 1}. Different colors are denoted by different digits. Some of the cherries are already placed and the Chef wants you to place cherries in the remaining positions. He understands that there can be many such arrangements, so in the case when the answer is not unique he asks you to find the lexicographically smallest one.
What does it mean?
Let's numerate positions for the cherries by the numbers 1, 2, ..., N starting from one of the positions in a clockwise direction. Then the current (possibly partial) arrangement of the cherries can be represented by a string of N characters. For each position i of the arrangement if the cherry of the color C is placed at this position then the i^{th} character of the string is equal to the digit C. Otherwise, it is equal to the question mark ?. We identify the arrangement with the string that represents it.
One arrangement is called lexicographically smaller than the other arrangement if at the first position where they differ the first one has smaller digit (we compare only complete arrangements so we don't care about relation between digits and the question mark). For example, the arrangement 1230123 is lexicographically smaller than 1231230 since they have first 3 equal characters but the 4^{th} character in the first arrangement is 0 and it is less than 1 which is the 4^{th} character of the second arrangement.
Notes
The cherries at the first and the last positions are adjacent to each other (recall that we have a circular cake).
In the case N = 1 any arrangement is valid as long as the color used for the only cherry of this arrangement is less than K.
Initial arrangement can be already invalid (see the case 3 in the example).
Just to make all things clear. You will be given a usual string of digits and question marks. Don't be confused by circular stuff we have in this problem. You don't have to rotate the answer once you have replaced all question marks by the digits. Think of the output like the usual string for which each two consecutive digits must be different but having additional condition that the first and the last digits must be also different (of course if N > 1).
Next, you don't have to use all colors. The only important condition is that this string should be lexicographically smaller than all other strings that can be obtained from the input string by replacement of question marks by digits and of course it must satisfy conditions on adjacent digits.
One more thing, K here is not the length of the string but the number of allowed colors. Also we emphasize that the given string can have arbitrary number of question marks. So it can have zero number of question marks as well as completely consists of question marks but of course in general situation it can have both digits and question marks.
OK. Let's try to formalize things in order to make all even more clear. You will be given an integer K and a string S=S[1]S[2]...S[N] where each S[i] is either the decimal digit less than K or the question mark. We are serious. In all tests string S can have only digits less than K. Don't ask about what to do if we have digit β₯ K. There are no such tests at all! We guarantee this! OK, let's continue. Your task is to replace each question mark by some digit strictly less than K. If there were no question marks in the string skip this step. Now if N=1 then your string is already valid. For N > 1 it must satisfy the following N conditions S[1] β S[2], S[2] β S[3], ..., S[N-1] β S[N], S[N] β S[1]. Among all such valid strings that can be obtained by replacement of question marks you should choose lexicographically smallest one. I hope now the problem is really clear.
------ Input ------
The first line of the input file contains an integer T, the number of test cases. T test cases follow. Each test case consists of exactly two lines. The first line contains an integer K, the number of available colors for cherries. The second line contains a string S that represents the current arrangement of the cherries in the cake.
------ Constraints ------
1 β€ T β€ 1000
1 β€ K β€ 10
1 β€ |S| β€ 100, where |S| denotes the length of the string S
Each character in S is either the digit from the set {0, 1, ..., K β 1} or the question mark ?
------ Output ------
For each test case output the lexicographically smallest valid arrangement of the cherries in the cake that can be obtained from the given arrangement by replacement of each question mark by some digit from 0 to K β 1. If it is impossible to place the cherries output NO (output is case sensitive).
----- Sample Input 1 ------
7
1
?
2
?0
10
79259?087
2
??
3
0?1
4
?????
3
012
----- Sample Output 1 ------
0
10
NO
01
021
01012
012
----- explanation 1 ------
Case 2. The only possible replacement here is 10. Note that we output 10 since we can not rotate the answer to obtain 01 which is smaller.
Case 3. Arrangement is impossible because cherries at the first and the last positions are already of the same color. Note that K = 10 but the string has length 9. It is normal. K and |S| don't have any connection.
Case 4. There are two possible arrangements: 01 and 10. The answer is the first one since it is lexicographically smaller.
Case 5. There are three possible ways to replace question mark by the digit: 001, 011 and 021. But the first and the second strings are not valid arrangements as in both of them there exists an adjacent pair of cherries having the same color. Hence the answer is the third string.
Case 6. Note that here we do not use all colors. We just find the lexicographically smallest string that satisfies condition on adjacent digit.
Case 7. The string is already valid arrangement of digits. Hence we simply print the same string to the output.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
t = int(input())
for _ in range(t):
k = int(input())
s = list(input())
if k == 1 or len(s) == 1:
if len(s) == 1:
if s[0] != '?' and s[0] <= str(k - 1):
print(s[0])
elif s[0] != '?' and s[0] > str(k - 1):
print('NO')
elif s[0] == '?':
print(0)
else:
print('NO')
elif k == 2:
if len(s) % 2 != 0:
print('NO')
else:
cm1 = '01' * (len(s) // 2)
cm2 = '10' * (len(s) // 2)
(c1, c2) = (0, 0)
for i in range(len(s)):
if s[i] != '?' and s[i] == cm1[i]:
c1 += 1
if s[i] != '?' and s[i] == cm2[i]:
c2 += 1
if c1 + s.count('?') == len(s):
print(cm1)
elif c2 + s.count('?') == len(s):
print(cm2)
else:
print('NO')
else:
flag = True
for i in range(len(s)):
if s[i] == '?':
for j in range(0, k):
if s[i - 1] != str(j) and s[(i + 1) % len(s)] != str(j):
s[i] = str(j)
break
else:
if s[i - 1] != s[i] and s[i] != s[(i + 1) % len(s)]:
pass
else:
flag = False
break
if s[i] > str(k - 1):
flag = False
break
if flag:
print(''.join(s))
else:
print('NO')
``` | vfc_135290 | {
"difficulty": "medium_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/CAKEDOOM",
"time_limit": "0.386023 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7\n1\n?\n2\n?0\n10\n79259?087\n2\n??\n3\n0?1\n4\n?????\n3\n012",
"output": "0\n10\nNO\n01\n021\n01012\n012",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7\n1\n?\n2\n?0\n10\n79259?087\n2\n??\n3\n0?1\n4\n?????\n3\n13",
"output": "0\n10\nNO\n01\n021\n01012\n13\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/parenthesis-checker2744/1 | Solve the following coding problem using the programming language python:
Given an expression string x. Examine whether the pairs and the orders of {,},(,),[,] are correct in exp.
For example, the function should return 'true' for exp = [()]{}{[()()]()} and 'false' for exp = [(]).
Note: The drive code prints "balanced" if function return true, otherwise it prints "not balanced".
Example 1:
Input:
{([])}
Output:
true
Explanation:
{ ( [ ] ) }. Same colored brackets can form
balanced pairs, with 0 number of
unbalanced bracket.
Example 2:
Input:
()
Output:
true
Explanation:
(). Same bracket can form balanced pairs,
and here only 1 type of bracket is
present and in balanced way.
Example 3:
Input:
([]
Output:
false
Explanation:
([]. Here square bracket is balanced but
the small bracket is not balanced and
Hence , the output will be unbalanced.
Your Task:
This is a function problem. You only need to complete the function ispar() that takes a string as a parameter and returns a boolean value true if brackets are balanced else returns false. The printing is done automatically by the driver code.
Expected Time Complexity: O(|x|)
Expected Auixilliary Space: O(|x|)
Constraints:
1 β€ |x| β€ 32000
Write your solution by modifying this code:
```python
#User function Template for python3
class Solution:
#Function to check if brackets are balanced or not.
def ispar(self,x):
# code here
```
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
class Solution:
def ispar(self, x):
open = ['{', '(', '[']
close = ['}', ')', ']']
stack = []
for i in x:
if i in open:
stack.append(i)
elif i in close:
if len(stack) > 0:
if close.index(i) == open.index(stack[-1]):
stack.pop()
else:
return False
else:
return False
return len(stack) == 0
``` | vfc_135294 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/parenthesis-checker2744/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "{([])}",
"output": "true",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "()",
"output": "true",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "([]",
"output": "false",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1649/B | Solve the following coding problem using the programming language python:
Daniel is watching a football team playing a game during their training session. They want to improve their passing skills during that session.
The game involves $n$ players, making multiple passes towards each other. Unfortunately, since the balls were moving too fast, after the session Daniel is unable to know how many balls were involved during the game. The only thing he knows is the number of passes delivered by each player during all the session.
Find the minimum possible amount of balls that were involved in the game.
-----Input-----
There are several test cases in the input data. The first line contains a single integer $t$ ($1 \leq t \leq 5 \cdot 10^4$) β the number of test cases. This is followed by the test cases description.
The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^5$) β the number of players.
The second line of the test case contains a sequence of integers $a_1, a_2, \ldots, a_n$ ($0 \leq a_i \leq 10^9$), where $a_i$ is the number of passes delivered by the $i$-th player.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $10^5$.
-----Output-----
For each test case print a single integer β the answer to the problem.
-----Examples-----
Input
4
4
2 3 3 2
3
1 5 2
2
0 0
4
1000000000 1000000000 1000000000 1000000000
Output
1
2
0
1
-----Note-----
In the first test case, with the only ball, the game can go like this:
$2 \rightarrow 1 \rightarrow 3 \rightarrow 4 \rightarrow 1 \rightarrow 2 \rightarrow 3 \rightarrow 4 \rightarrow 2 \rightarrow 3 \rightarrow 2$.
In the second test case, there is no possible way to play the game with only one ball. One possible way to play with two balls:
$2 \rightarrow 1 \rightarrow 2 \rightarrow 3 \rightarrow 2 \rightarrow 1$.
$2 \rightarrow 3 \rightarrow 2 \rightarrow 1$
In the third example, there were no passes, so $0$ balls are possible.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import sys
input = sys.stdin.readline
t = int(input())
out = ''
for _ in range(t):
n = int(input())
arr = [int(x) for x in input().split()]
if arr.count(0) == n:
out += '0\n'
else:
out += str(max(1, max(arr) * 2 - sum(arr))) + '\n'
print(out)
``` | vfc_135299 | {
"difficulty": "easy",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1649/B",
"time_limit": "1 second"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n4\n2 3 3 2\n3\n1 5 2\n2\n0 0\n4\n1000000000 1000000000 1000000000 1000000000\n",
"output": "1\n2\n0\n1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n2\n1000000000 0\n",
"output": "1000000000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n10\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n200\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n6\n100000000 999999999 999999999 999999999 999999999 1000000000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n5\n1000000000 1000000000 1000000000 1000000000 1000000000\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.hackerrank.com/challenges/jeanies-route/problem | Solve the following coding problem using the programming language python:
Byteland has $N$ cities (numbered from $\mbox{1}$ to $N$) and $N-1$ bidirectional roads. It is guaranteed that there is a route from any city to any other city.
Jeanie is a postal worker who must deliver $\mbox{K}$ letters to various cities in Byteland. She can start and end her delivery route in any city. Given the destination cities for $\mbox{K}$ letters and the definition of each road in Byteland, find and print the minimum distance Jeanie must travel to deliver all $\mbox{K}$ letters.
Note: The letters can be delivered in any order.
Input Format
The first line contains two space-separated integers, $N$ (the number of cities) and $\mbox{K}$ (the number of letters), respectively.
The second line contains $\mbox{K}$ space-separated integers describing the delivery city for each letter.
Each line $\boldsymbol{i}$ of the $N-1$ subsequent lines contains $3$ space-separated integers describing a road as $u_iv_i d_i$, where $d_i$ is the distance (length) of the bidirectional road between cities $u_i$ and $v_i$.
Constraints
$2\leq K\leq N\leq10^5$
$1\leq d_i\leq10^3$
$\textit{Byteland is a weighted undirected acyclic graph.}$
Output Format
Print the minimum distance Jeanie must travel to deliver all $\mbox{K}$ letters.
Sample Input 0
5 3
1 3 4
1 2 1
2 3 2
2 4 2
3 5 3
Sample Output 0
6
Explanation 0
Jeanie has $3$ letters she must deliver to cities $\mbox{I}$, $3$, and $\begin{array}{c}A\end{array}$ in the following map of Byteland:
One of Jeanie's optimal routes is $\underbrace{3\to2}_{2}\overbrace{\to1}^{1}\underbrace{\to2}_{1}\overbrace{\to4}^{2}_{\cdot}$, for a total distanced traveled of $2+1+1+2=6$. Thus, we print $\boldsymbol{6}$ on a new line.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
[n, k] = list(map(int, input().split(' ')))
cities = set(map(int, input().split(' ')))
def log(*args):
if False:
print(*args)
counts = dict()
edges = dict()
for i in range(n):
edges[i + 1] = dict()
total = 0
for _ in range(n - 1):
[u, v, d] = list(map(int, input().split(' ')))
counts[u] = counts.get(u, 0) + 1
counts[v] = counts.get(v, 0) + 1
edges[u][v] = d
edges[v][u] = d
total += d
leaves = []
for (u, count) in counts.items():
if count == 1:
leaves.append(u)
log(edges, counts, leaves, total)
while len(leaves):
leaf = leaves.pop()
if leaf in cities:
log('ignoring city', leaf)
continue
log('must trim', leaf)
other = list(edges[leaf].keys())[0]
d = edges[other][leaf]
total -= d
del edges[other][leaf]
del edges[leaf]
if len(list(edges[other].keys())) == 1:
leaves.append(other)
log('new leaves', leaves)
parents = dict()
cur = list(cities)[0]
index = 0
stack = [cur]
indices = []
order = []
while True:
log('set', cur, index, stack, indices)
items = list(edges[cur].keys())
log('children', items)
if index == len(items):
parent = parents.get(cur)
log('order', cur, parent)
order.append((cur, parent))
stack.pop()
if len(stack) == 0:
break
index = indices.pop() + 1
cur = parent
else:
child = items[index]
if child == parents.get(cur):
index += 1
continue
parents[child] = cur
cur = child
indices.append(index)
index = 0
stack.append(child)
longest_path_cache = dict()
for (city, parent) in order:
inner = 0
to = 0
tos = []
inners = []
for (other, d) in edges[city].items():
if other == parent:
continue
(o_inner, o_to) = longest_path_cache[other]
inners.append(o_inner)
if o_inner > inner:
inner = o_inner
tos.append(o_to + d)
if o_to + d > to:
to = o_to + d
my_inner = 0
if len(tos) > 1:
tos.sort()
my_inner = tos[len(tos) - 1] + tos[len(tos) - 2]
longest_path_cache[city] = (max(inner, my_inner), to)
(inner, _) = longest_path_cache[list(cities)[0]]
log('best inner', inner)
log(edges, counts, leaves, total)
print(total * 2 - inner)
``` | vfc_135307 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/jeanies-route/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 3\n1 3 4\n1 2 1\n2 3 2\n2 4 2\n3 5 3\n",
"output": "6\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Given K prime numbers and T queries of form Ai, Bi, for each query print the number of integers between Ai and Bi (both inclusive) that are divisible by atleast one of the K given primes.
Input
First line: K and T.
Second line: K primes.
Next T lines, each contain Ai, Bi.
Output
Print T lines, denoting the answer to each of the T queries.
Constraints
1 β€ K β€ 10
1 β€ T β€ 100
1 β€ A β€ B β€ 10^9
Each prime β€ 10^7
SAMPLE INPUT
2 1
2 3
1 10
SAMPLE OUTPUT
7
Explanation
2,3,4,6,8,9,10 are the 7 numbers.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
from itertools import combinations
k,t=list(map(int,input().split()))
primes=list(map(int,input().split()))
final=[]
for i in range(1,k+1):
arr=combinations(primes,i)
for item in arr:
final.append(item)
for _ in range(t):
a,b=list(map(int,input().split()))
count=0
i=0
while i<len(final):
prod=1
for ir in final[i]:
prod=prod*ir
#print 'prod',prod
if len(final[i])%2==1:
count=count+((b/prod)-((a-1)/prod))
else:
count=count-((b/prod)-((a-1)/prod))
i=i+1
print(count)
``` | vfc_135315 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10 100\n2 3 5 7 11 37 1000003 71 101 103\n5290021 982425129\n8505031 551538918\n7664127 844108421\n5263111 947266352\n6441031 125008940\n7764822 337937173\n301907 929886877\n8883038 454040626\n3739338 873454435\n1316343 209004362\n794444 988833247\n4505981 984743953\n3841612 521308585\n276499 204514555\n2301407 706473574\n7108331 846845318\n3416645 379595387\n6914057 612492194\n7098957 893082607\n3315500 699841053\n7235941 408376535\n8529112 163862973\n6635795 202789300\n9426516 402112447\n7177373 999830133\n9983237 580679494\n6703206 581119448\n9748336 259702744\n5194686 471359701\n4122702 791164315\n5437680 679475172\n4898505 515049595\n5235354 408316854\n5967654 658736978\n9147144 590811769\n4199717 579103440\n78964 980894273\n3356534 818555899\n5539318 428374504\n135191 801551894\n6048077 886307549\n254711 804231327\n8766540 953797745\n9864981 997898522\n5123609 435466845\n3099543 637241382\n3013708 892067736\n2862999 218366632\n6702209 604353533\n7805093 140602805\n7840478 948749736\n4942520 950356483\n8124235 990215725\n4379979 263821022\n3773422 385774385\n446753 673098629\n105683 379947217\n7167439 169350197\n8566576 645722012\n2766103 936019850\n8409284 688303935\n6098006 380652734\n7611006 478975314\n8051375 330628000\n2774421 773378536\n3082156 467487181\n7644060 818306620\n862600 767288218\n8607884 942179665\n1605653 399416076\n7300297 812987285\n2579679 987072178\n3334864 690092159\n6463818 631081178\n2910931 403641020\n6030223 738474564\n4853435 744911184\n2534101 474394032\n5515077 660451237\n8264215 306529763\n5370388 391746671\n5659366 167497866\n4696618 892772147\n4203982 330906919\n7940787 231113401\n6490893 704149585\n52873 701032221\n9003058 207001244\n6373718 877956506\n8423492 394037448\n7543309 532419247\n2743023 355429087\n3361485 585140324\n2442533 683933348\n7265269 590401316\n8675811 709237653\n4422747 429965570\n1757269 252855928\n7898250 578118250\n4947304 142307870\n",
"output": "44859729\n85338058\n44523846\n12453682\n52565883\n22982013\n22794586\n55274864\n37035027\n50358498\n20876252\n38375906\n57906945\n56598070\n57992637\n21837987\n17554899\n75630801\n19133466\n75703752\n73937765\n67237693\n58621377\n15542778\n39970921\n16160670\n47446328\n83336161\n47131010\n15878132\n65284476\n25714251\n18084735\n74461029\n76531125\n71399563\n46161479\n29211367\n52502614\n84720758\n17717642\n56619701\n54336475\n60315494\n71200803\n37706353\n87648642\n66455851\n11742448\n41545341\n83534807\n47539757\n40583717\n55483977\n74978254\n56413000\n36187781\n76909871\n17273642\n84083438\n53721670\n23240684\n63388965\n45246800\n27632818\n35605237\n73158232\n44391498\n23074417\n43644161\n41453579\n73835402\n61586022\n46409939\n13410327\n16996349\n38498663\n85545543\n83362038\n85964293\n34677940\n87872471\n63136406\n34162275\n20147562\n21661454\n28406006\n49074873\n67333806\n67569111\n75233190\n64182987\n67766837\n31370235\n74436428\n86169740\n47050238\n31866003\n33618569\n81943879\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 55\n2 3\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n2 2\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n3 3\n3 4\n3 5\n3 6\n3 7\n3 8\n3 9\n3 10\n4 4\n4 5\n4 6\n4 7\n4 8\n4 9\n4 10\n5 5\n5 6\n5 7\n5 8\n5 9\n5 10\n6 6\n6 7\n6 8\n6 9\n6 10\n7 7\n7 8\n7 9\n7 10\n8 8\n8 9\n8 10\n9 9\n9 10\n10 10\n",
"output": "786164974\n436903977\n672970602\n757899231\n95395139\n265643861\n747907972\n358156513\n699738989\n167097703\n794937663\n788661410\n416333834\n164322009\n566549580\n675619769\n302658812\n487224658\n712828038\n560397420\n322742146\n124975588\n157817493\n315939856\n798649867\n459160052\n462153008\n201103613\n375058268\n633223127\n542304395\n410447761\n324303731\n525192850\n467984770\n462545215\n789125910\n655877756\n340196770\n644788755\n708222591\n646848376\n760335408\n794933428\n346237464\n510205900\n715298349\n173385849\n480847048\n106843881\n757019056\n760643370\n790152681\n208736194\n307343143\n541189584\n305605744\n130485947\n512630533\n750859729\n547016839\n301352189\n379241420\n259532627\n619998147\n373642252\n652227619\n616636294\n751115602\n320062814\n648224469\n792084433\n552538252\n502542879\n322411872\n589296279\n595421732\n379640176\n526936210\n239972876\n310863353\n130208974\n714511085\n262852502\n179556021\n561309096\n563980764\n159301654\n701241668\n310250014\n422294804\n283757516\n468076670\n548301041\n469168625\n563644853\n342375237\n202024235\n458776874\n110514972\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 55\n2 3 5 7 11 37\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n2 2\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n3 3\n3 4\n3 5\n3 6\n3 7\n3 8\n3 9\n3 10\n4 4\n4 5\n4 6\n4 7\n4 8\n4 9\n4 10\n5 5\n5 6\n5 7\n5 8\n5 9\n5 10\n6 6\n6 7\n6 8\n6 9\n6 10\n7 7\n7 8\n7 9\n7 10\n8 8\n8 9\n8 10\n9 9\n9 10\n10 10\n",
"output": "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n1\n2\n3\n4\n5\n6\n7\n8\n9\n1\n2\n3\n4\n5\n6\n7\n8\n1\n2\n3\n4\n5\n6\n7\n1\n2\n3\n4\n5\n6\n1\n2\n3\n4\n5\n1\n2\n3\n4\n1\n2\n3\n1\n2\n1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 100\n47 71\n23 372625295\n60 205384774\n90 372875176\n54 802786223\n62 254110041\n60 279140767\n91 366974232\n42 146340840\n7 514446580\n21 434390631\n28 659372573\n98 165720098\n6 835866717\n98 951961873\n51 457709075\n31 847888584\n4 360061407\n13 706505666\n93 255025765\n93 751043484\n18 594724161\n31 967061483\n1 557555592\n34 629592709\n21 166120146\n47 347351603\n9 824510842\n34 815823266\n77 253382344\n40 115097244\n91 943863657\n50 584928500\n39 368150940\n2 281566279\n57 928871064\n14 719902780\n22 215633687\n31 119324595\n61 133613079\n14 325413451\n100 786732450\n73 401175714\n77 998700261\n2 472487021\n73 812676263\n13 351845300\n31 301716178\n83 749165078\n58 468999364\n22 950381322\n52 257140119\n72 376083317\n18 313989286\n50 789164681\n51 177931499\n37 464741462\n40 132560069\n63 289865881\n82 661193758\n67 554890032\n80 824777570\n4 855967549\n22 395040894\n57 673573189\n54 301611565\n79 960671542\n13 102347079\n98 403703913\n60 419811768\n69 730949459\n76 169771701\n96 139231063\n17 207771181\n86 979360536\n90 908720822\n52 270920638\n52 596316985\n40 128313138\n60 883700329\n26 615575292\n30 370575263\n43 999850137\n57 527397902\n22 728022939\n64 560063698\n68 559700197\n11 349185329\n33 513602734\n88 258498094\n36 778275107\n29 833353124\n73 329127331\n48 122050275\n73 199245160\n47 458375513\n2 996033609\n14 687391456\n37 150192534\n50 569509738\n38 854840544\n",
"output": "359921353\n653569078\n140970608\n322551619\n404372546\n259464462\n273086684\n393504076\n129983732\n479598929\n401459339\n269083681\n216969606\n496137891\n101275246\n444261359\n315172993\n269610608\n361416988\n172495392\n766123447\n601153937\n521735460\n663096995\n694007784\n578689813\n322663628\n238592079\n375171773\n601992076\n144320492\n126317743\n666477461\n789033047\n589405716\n373281479\n204768286\n84895927\n337102303\n309684900\n689835869\n748153866\n119373498\n432126884\n708562919\n197840282\n662218781\n674346716\n425551224\n212347520\n222063553\n506814633\n727223994\n319143465\n318763109\n669877941\n195685914\n491638512\n413282210\n780411397\n208859125\n531176207\n511072220\n749581620\n783321161\n428232973\n109395604\n178428854\n616075693\n215098639\n729235247\n493865370\n516979274\n378556155\n650404038\n667391460\n572195159\n613845963\n627539176\n479141518\n172438414\n361198294\n610560780\n110835591\n174701402\n262159525\n352883260\n242046600\n674779360\n639014235\n786084746\n303375308\n661186260\n286321423\n742412232\n308645352\n330308845\n138987296\n196658898\n413127321\n",
"type": "stdin_stdout"
}
]
} |
|
taco | verifiable_code | Solve the following coding problem using the programming language python:
This is a story in a depopulated area. In this area, houses are sparsely built along a straight road called Country Road. Until now, there was no electricity in this area, but this time the government will give us some generators. You can install the generators wherever you like, but in order for electricity to be supplied to your home, you must be connected to one of the generators via an electric wire, which incurs a cost proportional to its length. As the only technical civil servant in the area, your job is to seek generator and wire placement that minimizes the total length of wires, provided that electricity is supplied to all homes. Is. Since the capacity of the generator is large enough, it is assumed that electricity can be supplied to as many houses as possible.
Figure 2 shows the first data set of the sample input. To give the optimum placement for this problem, place the generators at the positions x = 20 and x = 80 as shown in the figure, and draw the wires at the positions shown in gray in the figure, respectively.
Example of generator and wire placement (first dataset in input example).
---
Figure 2: Example of generator and wire placement (first dataset in input example).
Input
The number of datasets t (0 <t β€ 50) is given on the first line of the input.
Subsequently, t datasets are given. Each dataset is given in two lines in the following format.
n k
x1 x2 ... xn
n is the number of houses and k is the number of generators. x1, x2, ..., xn are one-dimensional coordinates that represent the position of the house, respectively. All of these values ββare integers and satisfy 0 <n β€ 100000, 0 <k β€ 100000, 0 β€ x1 <x2 <... <xn β€ 1000000.
In addition, 90% of the dataset satisfies 0 <n β€ 100, 0 <k β€ 100.
Output
For each dataset, output the minimum total required wire length in one line.
Example
Input
6
5 2
10 30 40 70 100
7 3
3 6 10 17 21 26 28
1 1
100
2 1
0 1000000
3 5
30 70 150
6 4
0 10 20 30 40 50
Output
60
13
0
1000000
0
20
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
NUM = int(input())
for sect in range(NUM):
(n, k) = list(map(int, input().strip().split()))
x = list(map(int, input().strip().split()))
x.sort()
diff = []
for i in range(1, len(x)):
diff.append(x[i] - x[i - 1])
diff.sort(reverse=True)
s = sum(diff[:k - 1])
print(max(x) - min(x) - s)
``` | vfc_135319 | {
"difficulty": "unknown_difficulty",
"memory_limit": "134.217728 megabytes",
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "5.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n5 2\n10 30 40 70 100\n7 3\n3 4 10 17 21 26 28\n1 1\n100\n2 1\n0 1000000\n3 5\n30 70 150\n6 4\n0 10 20 30 40 50",
"output": "60\n12\n0\n1000000\n0\n20\n",
"type": "stdin_stdout"
}
]
} |
|
taco | verifiable_code | Solve the following coding problem using the programming language python:
Hakone Ekiden is one of the Japanese New Year's traditions. In Hakone Ekiden, 10 runners from each team aim for the goal while connecting the sashes at each relay station. In the TV broadcast, the ranking change from the previous relay station is displayed along with the passing order of each team at the relay station. So, look at it and tell us how many possible passage orders for each team at the previous relay station. The number of possible transit orders can be very large, so answer by the remainder divided by 1,000,000,007.
Input
The input is given in the form:
> n
> c1
> c2
> ...
> cn
>
The number n (1 β€ n β€ 200) representing the number of teams is on the first line, and the ranking changes from the previous relay station in order from the first place on the following n lines. If it is'`U`', the ranking is up, if it is'`-`', the ranking is not changed) is written.
Output
Please output in one line by dividing the number of passages that could have been the previous relay station by 1,000,000,007.
Examples
Input
3
-
U
D
Output
1
Input
5
U
U
-
D
D
Output
5
Input
8
U
D
D
D
D
D
D
D
Output
1
Input
10
U
D
U
D
U
D
U
D
U
D
Output
608
Input
2
D
U
Output
0
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop, heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10 ** 9 + 7
inf = float('inf')
def I():
return int(sys.stdin.readline())
def LI():
return list(map(int, sys.stdin.readline().split()))
n = I()
dp = [[0] * (n + 2) for _ in range(n + 1)]
dp[0][0] = 1
for i in range(n):
s = input()
if s == 'U':
for j in range(n):
dp[i + 1][j] += dp[i][j]
dp[i + 1][j + 1] += dp[i][j] * (i - j)
dp[i + 1][j + 1] %= mod
elif s == '-':
for j in range(n):
dp[i + 1][j + 1] += dp[i][j]
else:
for j in range(n):
dp[i + 1][j + 2] += dp[i][j] * (i - j) * (i - j)
dp[i + 1][j + 2] %= mod
dp[i + 1][j + 1] += dp[i][j] * (i - j)
dp[i + 1][j + 1] %= mod
print(dp[n][n])
``` | vfc_135323 | {
"difficulty": "unknown_difficulty",
"memory_limit": "262.144 megabytes",
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\nD\nT",
"output": "0\n",
"type": "stdin_stdout"
}
]
} |
|
taco | verifiable_code | https://www.codechef.com/DEC11/problems/HYPER | Solve the following coding problem using the programming language python:
A hypergraph is a generalization of a graph, where an edge can connect any number of vertices. A k-uniform hypergraph is a hypergraph such that all its hyperedges have size k. For more information, see Wikipedia.
Let's call a particular hypergraph a hypertree if it is connected (that is, you can move from any vertex to any other vertex using only its hyperedges) and removing any of its hyperedges makes the hypergraph disconnected (note that this definition of hypertrees differs from the standard one).
Given just one integer N, find the number of 3-uniform hypertrees on N vertices. Two 3-uniform hypertrees are considered different if a hyperedge (u, v, w) exists such that it is present in exactly one of these hypertrees (note that the order of vertices in the hyperedge doesn't matter, and neither does the order of hyperedges in the hypertree).
-----Input-----
The first line of the input contains an integer T -- the number of test cases (at most 15). Then T lines follow, each contains an integer N (3 β€ N β€ 17).
Important! Please include all code used in solving this problem in your solution.
-----Output-----
For each test case output one line containing the requested number. It's guaranteed that this number won't exceed 263-1.
-----Examples-----
Input:
4
3
4
5
8
Output:
1
6
25
93268
Explanation:
There is just one 3-uniform hypertree on 3 vertices: {(1,2,3)}. There are six of them on 4 vertices: {(1,2,3), (1,2,4)}, {(1,2,3), (1,3,4)}, {(1,2,3), (2,3,4)}, {(1,2,4), (1,3,4)}, {(1,2,4), (2,3,4)}, {(1,3,4), (2,3,4)}. Two of the 25 possible hypertrees on 5 vertices are {(1,2,3), (3,4,5)} and {(1,2,3), (1,2,4), (1,2,5)}.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
output = '\n{(6, 9): 10559808000, (0, 7): 0, (1, 6): 0, (0, 10): 0, (3, 7): 2142, (2, 5): 1, (1, 11): 0, (5, 8): 48094200, (6, 7): 6350400, (5, 5): 1440, (6, 10): 247973140800, (0, 17): 0, (0, 4): 0, (1, 1): 0, (4, 10): 57808440, (2, 6): 1, (5, 11): 84587745000, (4, 5): 2160, (0, 1): 0, (3, 12): 531366, (1, 12): 0, (2, 11): 1, (7, 8): 482630400, (0, 14): 0, (3, 11): 177078, (1, 15): 0, (8, 9): 45113241600, (4, 12): 2148847272, (2, 12): 1, (1, 16): 0, (1, 5): 0, (0, 11): 0, (3, 6): 690, (2, 2): 1, (1, 10): 0, (6, 11): 4928158065600, (0, 5): 0, (1, 0): 1, (0, 8): 0, (4, 11): 354158640, (3, 5): 210, (2, 7): 1, (5, 10): 7639380000, (4, 6): 25560, (5, 7): 2835000, (0, 2): 0, (1, 3): 0, (4, 8): 1433544, (2, 8): 1, (0, 15): 0, (3, 10): 58986, (1, 14): 0, (4, 13): 12970756656, (2, 13): 1, (1, 4): 0, (0, 12): 0, (3, 9): 19626, (2, 3): 1, (1, 9): 0, (2, 14): 1, (6, 8): 336268800, (0, 6): 0, (1, 7): 0, (0, 9): 0, (3, 4): 54, (2, 4): 1, (5, 9): 644550480, (4, 7): 206640, (6, 6): 43200, (5, 6): 104400, (7, 7): 1814400, (0, 16): 0, (0, 3): 0, (3, 14): 4782882, (1, 2): 0, (4, 9): 9265200, (3, 3): 6, (2, 9): 1, (5, 12): 900380296200, (4, 4): 72, (7, 10): 2379856852800, (0, 0): 1, (3, 13): 1594242, (1, 13): 0, (2, 10): 1, (7, 9): 44808422400, (0, 13): 0, (3, 8): 6510, (1, 8): 0, (8, 8): 101606400, (2, 15): 1}\n'
sve = eval(''.join(output.split('\n')))
def fact(n):
assert n >= 0
ret = 1
for i in range(n):
ret *= i + 1
return ret
def comb(a, b):
return fact(a + b) / fact(a) / fact(b)
pass
memo_ff = {}
def powpoly(x, t):
ret = [1] + [0] * (len(x) - 1)
n = len(x)
for _ in range(t):
ret2 = [0 for _ in range(n)]
for i in range(n):
for j in range(n):
if i + j < n:
ret2[i + j] += ret[i] * x[j]
ret = ret2
return ret
def ing(x):
n = len(x)
assert x[0] == 0
ret = [0 for _ in range(n)]
for t in range(0, n):
ret2 = powpoly(x, t)
for i in range(n):
ret[i] += fr * ret2[i] / fact(t)
return ret
def ff(Y):
if Y in memo_ff:
return memo_ff[Y]
t = Y[0]
if t == 0:
n = Y[1]
ret = 0
for (v, e) in sve:
if v + e > n or v == 0:
continue
val = sve[v, e]
for l1 in range(n - v + 1):
l2 = n - v - l1
p1 = ff((2, l1, e))
p2 = ff((3, l2, v))
a = fr * val * fact(n - 1) / fact(v - 1) / fact(l1) / fact(l2) * p1 * p2 / fact(e)
ret += a
elif t == 1:
n = Y[1]
ret = 0
for (v, e) in sve:
val = sve[v, e]
e -= 1
if e == -1 or v + e > n or v == 0:
continue
for l1 in range(n - v + 1):
l2 = n - v - l1
p1 = ff((2, l1, e))
p2 = ff((3, l2, v))
ret += fr * val * fact(n) / fact(v) / fact(l1) / fact(l2) * p1 * p2 / fact(e)
elif t == 2:
n = Y[1]
e = Y[2]
F = [fr * i * ff((0, i)) / fact(i) for i in range(n + 1)]
Fa = powpoly(F, e)
ret = Fa[n] * fact(n)
elif t == 3:
n = Y[1]
v = Y[2]
G = [v * fr * ff((1, i)) / fact(i) for i in range(n + 1)]
Ga = ing(G)
ret = Ga[n] * fact(n)
memo_ff[Y] = ret
return ret
memo = {}
def g(Y):
if Y in memo:
return memo[Y]
(k, c) = Y
if c == 0:
return ff((0, k))
if 2 * c >= k:
return 0
ret = 0
for k1 in range(1, 18):
for k2 in range(1, 18):
k3 = k - k1 - k2
if k3 <= 0:
break
for c1 in range(18):
if 2 * c1 >= k1:
break
for c2 in range(18):
if 2 * c2 >= k2:
break
c3 = c - 1 - c1 - c2
if 2 * c3 >= k3:
continue
ret += g((k1, c1)) * g((k2, c2)) * g((k3, c3)) * fact(k1 + k2 + k3) / fact(k1) / fact(k2) / fact(k3) * k1 * k2 * k3
r = ret / (6 * c)
memo[Y] = r
return r
def ans(n):
return sum((g((n, i)) for i in range(n)))
def brute(n):
m = [(i1, i2, i3) for i1 in range(n) for i2 in range(i1 + 1, n) for i3 in range(i2 + 1, n)]
init = []
memob = {}
def f(vs):
ret = 0
if vs:
g = Graph(n)
for v in vs:
(i1, i2, i3) = v
g.addedge(i1, i2)
g.addedge(i1, i3)
a = g.Nconnect()
for notv in vs:
g = Graph(n)
for v in vs:
if v == notv:
continue
(i1, i2, i3) = v
g.addedge(i1, i2)
g.addedge(i1, i3)
if g.Nconnect() == a:
return 0
if a == 1:
return 1
ret = 0
for v in m:
if len(vs) == 0 or v > vs[-1]:
ret += f(vs + [v])
return ret
return f(init)
def brute2(n):
m = [(i1, i2, i3) for i1 in range(n) for i2 in range(i1 + 1, n) for i3 in range(i2 + 1, n)]
init = []
def f(vs):
ret = 0
if vs:
g = Graph(n)
for v in vs:
(i1, i2, i3) = v
g.addedge(i1, i2)
g.addedge(i1, i3)
a = g.Nconnect()
for notv in vs:
g = Graph(n)
for v in vs:
if v == notv:
continue
(i1, i2, i3) = v
g.addedge(i1, i2)
g.addedge(i1, i3)
if g.Nconnect() == a or (a == 1 and g.Nconnect() == 3):
return 0
if a == 1:
return 1
ret = 0
for v in m:
if len(vs) == 0 or v > vs[-1]:
ret += f(vs + [v])
return ret
return f(init)
def main():
t = eval(input())
z = [0, 1, 0, 1, 6, 25, 495, 5586, 93268, 2052513, 43258365, 1167393700, 34010847486, 1078391538159, 38595111963499, 1476893151785520, 61479081902937000, 2761923686066698561]
for _ in range(t):
print(z[eval(input())])
main()
``` | vfc_135331 | {
"difficulty": "hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/DEC11/problems/HYPER",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n3\n4\n5\n8\n\n\n",
"output": "1\n6\n25\n93268\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/96/B | Solve the following coding problem using the programming language python:
Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. For example, numbers 47, 7744, 474477 are super lucky and 4, 744, 467 are not.
One day Petya came across a positive integer n. Help him to find the least super lucky number which is not less than n.
Input
The only line contains a positive integer n (1 β€ n β€ 109). This number doesn't have leading zeroes.
Output
Output the least super lucky number that is more than or equal to n.
Please, do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specificator.
Examples
Input
4500
Output
4747
Input
47
Output
47
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
gh = set()
def rep(n, four, seven):
global gh
if n > 10000000000:
return
if four == seven:
gh |= {n}
rep(n * 10 + 4, four + 1, seven)
rep(n * 10 + 7, four, seven + 1)
rep(0, 0, 0)
gh = sorted(gh)
def bin_s(a):
lo = 0
hi = len(gh)
ans = 0
while lo <= hi:
mid = (lo + hi) // 2
if gh[mid] >= a:
ans = gh[mid]
hi = mid - 1
else:
lo = mid + 1
return ans
print(bin_s(int(input())))
``` | vfc_135336 | {
"difficulty": "easy",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/96/B",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "447777\n",
"output": "474477\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "444000000\n",
"output": "4444477777\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "99\n",
"output": "4477\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "48\n",
"output": "74\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7773\n",
"output": "444777\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/PBK32020/problems/ITGUY30 | Solve the following coding problem using the programming language python:
Cheffina challanges chef to rearrange the given array as arr[i] > arr[i+1] < arr[i+2] > arr[i+3].. and so onβ¦, i.e. also arr[i] < arr[i+2] and arr[i+1] < arr[i+3] and arr[i] < arr[i+3] so on.. Chef accepts the challenge, chef starts coding but his code is not compiling help him to write new code.
-----Input:-----
- First-line will contain $T$, the number of test cases. Then the test cases follow.
- Each test case contains two lines of input, First $N$ as the size of the array.
- N space-separated distinct integers.
-----Output:-----
For each test case, output in a single line answer given to the Chefffina.
-----Constraints-----
- $1 \leq T \leq 10$
- $1 \leq N \leq 10^5$
- $1 \leq arr[i] \leq 10^5$
-----Sample Input:-----
2
4
4 1 6 3
5
4 5 1 6 3
-----Sample Output:-----
3 1 6 4
3 1 5 4 6
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
a.sort()
i = 1
while i < n:
(a[i - 1], a[i]) = (a[i], a[i - 1])
i += 2
print(*a)
``` | vfc_135340 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/PBK32020/problems/ITGUY30",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n4\n4 1 6 3\n5\n4 5 1 6 3\n",
"output": "3 1 6 4\n3 1 5 4 6\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.hackerrank.com/challenges/find-digits/problem | Solve the following coding problem using the programming language python:
An integer $\boldsymbol{d}$ is a divisor of an integer $n$ if the remainder of $n\div d=0$.
Given an integer, for each digit that makes up the integer determine whether it is a divisor. Count the number of divisors occurring within the integer.
Example
$n=124$
Check whether $1$, $2$ and $4$ are divisors of $124$. All 3 numbers divide evenly into $124$ so return $3$.
$n=111$
Check whether $1$, $1$, and $1$ are divisors of $\mbox{111}$. All 3 numbers divide evenly into $\mbox{111}$ so return $3$.
$n=10$
Check whether $1$ and $0$ are divisors of $10$. $1$ is, but $0$ is not. Return $1$.
Function Description
Complete the findDigits function in the editor below.
findDigits has the following parameter(s):
int n: the value to analyze
Returns
int: the number of digits in $n$ that are divisors of $n$
Input Format
The first line is an integer, $\boldsymbol{\boldsymbol{t}}$, the number of test cases.
The $\boldsymbol{\boldsymbol{t}}$ subsequent lines each contain an integer, $n$.
Constraints
$1\leq t\leq15$
$0<n<10^9$
Sample Input
2
12
1012
Sample Output
2
3
Explanation
The number $12$ is broken into two digits, $1$ and $2$. When $12$ is divided by either of those two digits, the remainder is $0$ so they are both divisors.
The number $\textbf{1012}$ is broken into four digits, $1$, $0$, $1$, and $2$. $\textbf{1012}$ is evenly divisible by its digits $1$, $1$, and $2$, but it is not divisible by $0$ as division by zero is undefined.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def func(A):
return len([1 for i in str(A) if i != '0' and A % int(i) == 0])
for t in range(int(input())):
print(func(int(input())))
``` | vfc_135344 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/find-digits/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n12\n1012\n",
"output": "2\n3\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.hackerrank.com/challenges/np-dot-and-cross/problem | Solve the following coding problem using the programming language python:
dot
The dot tool returns the dot product of two arrays.
import numpy
A = numpy.array([ 1, 2 ])
B = numpy.array([ 3, 4 ])
print numpy.dot(A, B) #Output : 11
cross
The cross tool returns the cross product of two arrays.
import numpy
A = numpy.array([ 1, 2 ])
B = numpy.array([ 3, 4 ])
print numpy.cross(A, B) #Output : -2
Task
You are given two arrays $\mbox{A}$ and $\mbox{B}$. Both have dimensions of $N$X$N$.
Your task is to compute their matrix product.
Input Format
The first line contains the integer $N$.
The next $N$ lines contains $N$ space separated integers of array $\mbox{A}$.
The following $N$ lines contains $N$ space separated integers of array $\mbox{B}$.
Output Format
Print the matrix multiplication of $\mbox{A}$ and $\mbox{B}$.
Sample Input
2
1 2
3 4
1 2
3 4
Sample Output
[[ 7 10]
[15 22]]
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import numpy
n = int(input())
A = [[int(i) for i in input().strip().split()] for j in range(n)]
B = [[int(i) for i in input().strip().split()] for j in range(n)]
print(numpy.dot(A, B))
``` | vfc_135348 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/np-dot-and-cross/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1 2\n3 4\n1 2\n3 4\n",
"output": "[[ 7 10]\n [15 22]]\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/number-of-divisors-in-a-given-range3738/1 | Solve the following coding problem using the programming language python:
Given a range [m..n]. You task is to find the number of integers divisible by either a or b in the given range.
Example 1:
Input:
m = 5, n = 11, a = 4, b = 6
Output:
2
Explanation:
6 and 8 lie in the range and are also
either divisible by 4 or 6.
Example 2:
Input:
m = 1, n = 3, a = 2, b = 3
Output:
2
Explanation:
2 and 3 lie in the range and are also
either divisible by 2 or 3.
Your Task:
You don't need to read input or print anything. Your task is to complete the function numOfDiv() which takes 4 Integers m, n, a, b as input and returns the count of integers in the range m..n which are divisible by either a or b.
Expected Time Complexity: O(log(max(a,b))
Expected Auxiliary Space: O(1)
Constraints:
1 <= m <= n <= 10^{5}
1 <= a,b <= 500
Write your solution by modifying this code:
```python
#User function Template for python3
class Solution:
def numOfDiv(self, m, n, a, b):
# code here
```
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
class Solution:
def numOfDiv(self, m, n, a, b):
count1 = n // a - (m - 1) // a
count2 = n // b - (m - 1) // b
c = a * b
while a != b:
if a > b:
a -= b
else:
b -= a
c /= a
count3 = n // c - (m - 1) // c
return int(count1 + count2 - count3)
``` | vfc_135361 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/number-of-divisors-in-a-given-range3738/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "m = 5, n = 11, a = 4, b = 6",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "m = 1, n = 3, a = 2, b = 3",
"output": "2",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/PSTR2020/problems/ITGUY05 | Solve the following coding problem using the programming language python:
The chef is trying to solve some pattern problems, Chef wants your help to code it. Chef has one number K to form a new pattern. Help the chef to code this pattern problem.
-----Input:-----
- First-line will contain $T$, the number of test cases. Then the test cases follow.
- Each test case contains a single line of input, one integer $K$.
-----Output:-----
For each test case, output as the pattern.
-----Constraints-----
- $1 \leq T \leq 50$
- $1 \leq K \leq 50$
-----Sample Input:-----
5
1
2
3
4
5
-----Sample Output:-----
1
1
23
1
23
456
1
23
4 5
6789
1
23
4 5
6 7
89101112
-----EXPLANATION:-----
No need, else pattern can be decode easily.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
for _ in range(int(input())):
n = int(input())
count = 1
l = 3 * (n - 1)
i = 0
if n == 1:
print(1)
continue
while count <= l - n:
for j in range(i + 1):
if j == i:
print(count)
count += 1
elif j == 0:
print(count, end='')
count += 1
else:
print(' ', end='')
i += 1
while count <= l:
print(count, end='')
count += 1
print()
``` | vfc_135371 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/PSTR2020/problems/ITGUY05",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1\n2\n3\n4\n5\n",
"output": "1\n1\n23\n1\n23\n456\n1\n23\n4 5\n6789\n1\n23\n4 5\n6 7\n89101112\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/490/B | Solve the following coding problem using the programming language python:
During the lunch break all n Berland State University students lined up in the food court. However, it turned out that the food court, too, has a lunch break and it temporarily stopped working.
Standing in a queue that isn't being served is so boring! So, each of the students wrote down the number of the student ID of the student that stands in line directly in front of him, and the student that stands in line directly behind him. If no one stands before or after a student (that is, he is the first one or the last one), then he writes down number 0 instead (in Berland State University student IDs are numerated from 1).
After that, all the students went about their business. When they returned, they found out that restoring the queue is not such an easy task.
Help the students to restore the state of the queue by the numbers of the student ID's of their neighbors in the queue.
-----Input-----
The first line contains integer n (2 β€ n β€ 2Β·10^5) β the number of students in the queue.
Then n lines follow, i-th line contains the pair of integers a_{i}, b_{i} (0 β€ a_{i}, b_{i} β€ 10^6), where a_{i} is the ID number of a person in front of a student and b_{i} is the ID number of a person behind a student. The lines are given in the arbitrary order. Value 0 is given instead of a neighbor's ID number if the neighbor doesn't exist.
The ID numbers of all students are distinct. It is guaranteed that the records correspond too the queue where all the students stand in some order.
-----Output-----
Print a sequence of n integers x_1, x_2, ..., x_{n} β the sequence of ID numbers of all the students in the order they go in the queue from the first student to the last one.
-----Examples-----
Input
4
92 31
0 7
31 0
7 141
Output
92 7 31 141
-----Note-----
The picture illustrates the queue for the first sample. [Image]
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
a = int(input())
d = {}
dinv = {}
for i in range(a):
b1 = input().split()
b = list(b1)
d[int(b[0])] = int(b[1])
dinv[int(b[1])] = int(b[0])
c1 = []
n = 0
for i in range(a):
n = d.get(n)
if n in d and n != 0:
c1 += [n]
else:
c1 += [n]
break
c2 = []
for i in d.keys():
if i not in dinv:
k = i
c2 += [k]
for i in range(a):
k = d.get(k)
if k in d and k != 0:
c2 += [k]
else:
c2 += [k]
break
c1 += [0]
c2 += [0]
for i in range(a):
if c2[i] != 0:
print(c2[i], end=' ')
if c1[i] != 0:
print(c1[i], end=' ')
else:
break
``` | vfc_135375 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/490/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n92 31\n0 7\n31 0\n7 141\n",
"output": "92 7 31 141 \n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/CTIME | Solve the following coding problem using the programming language python:
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef's college is conducting an online exam, where his camera will be monitored by one or more invigilators (supervisors). Once again, Chef failed to prepare for the exam on time and decided to google answers during it.
The exam starts at time $0$ and ends at time $F$ minutes. Chef needs a total of $K$ minutes of googling during the exam in order to pass it. There are $N$ invigilators (numbered $1$ through $N$); for each valid $i$, the $i$-th invigilator monitors Chef's camera during the time interval starting at $S_{i}$ minutes since the start of the exam and ending at $E_{i}$ minutes (where $0 β€ S_{i} β€ E_{i} β€ F$). He was resourceful enough to somehow get hold of these times and now he wants to know if he would be able to pass the exam if he googles the answers during the times when no one is looking at his camera.
Note: The time of googling need not be continuous and there can be multiple invigilators at some interval of time.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains three space-separated integers $N$, $K$ and $F$.
$N$ lines follow. For each valid $i$, the $i$-th of these lines contains two space-separated integers $S_{i}$ and $E_{i}$.
------ Output ------
For each test case, print a single line containing the string "YES" if it is possible to pass the exam or "NO" if it is impossible.
You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).
------ Constraints ------
$1 β€ T β€ 10^{5}$
$1 β€ N β€ 10^{5}$
$1 β€ F β€ 10^{9}$
$0 β€ K β€ F$
$0 β€ S_{i} β€ E_{i} β€ F$ for each valid $i$
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$
----- Sample Input 1 ------
3
1 10 10
0 10
2 2 10
0 5
7 10
2 2 100
0 5
5 10
----- Sample Output 1 ------
NO
YES
YES
----- explanation 1 ------
Example case 1: There is no point during the exam when Chef is not monitored, so he is unable to google even for a single second and will fail the exam.
Example case 2: Chef can google for $2$ minutes (in the time interval $[5, 7]$, when he is not monitored) and hence will be able to pass the exam.
Example case 3: Chef can google for $2$ minutes (in the time interval $[10, 12]$) and hence will be able to pass the exam.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
t = int(input())
for i in range(t):
(n, k, f) = map(int, input().split())
l = []
for j in range(n):
(a, b) = map(int, input().split())
l.append((a, b))
l.sort()
(a, b) = l[0]
if a > 0:
ans += a
else:
ans = 0
s = b
for x in range(1, n):
(a, b) = l[x]
if a >= s:
ans += a - s
if s < b:
s = b
if s < f:
ans += f - s
if ans >= k:
print('YES')
else:
print('NO')
``` | vfc_135379 | {
"difficulty": "medium_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/CTIME",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 10 10\n0 10\n2 2 10\n0 5\n7 10\n2 2 100\n0 5\n5 10",
"output": "NO\nYES\nYES",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Example
Input
3 2
1 2 1
2 3 2
1 10 100
Output
320
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import sys
readline = sys.stdin.readline
write = sys.stdout.write
sys.setrecursionlimit(10 ** 5)
def solve():
(N, M) = map(int, readline().split())
G = [[] for i in range(N)]
for i in range(N - 1):
(a, b, c) = map(int, readline().split())
G[a - 1].append((b - 1, c))
G[b - 1].append((a - 1, c))
(*C,) = map(int, readline().split())
def dfs(v, p, s, A):
m = 0
for (w, d) in G[v]:
if w == p:
continue
r = dfs(w, v, s, A) + s * d
if m < r:
(m, r) = (r, m)
if r > 0:
A.append(r)
return m
A = []
for i in range(N):
r = dfs(i, -1, C[i], A)
if r > 0:
A.append(r)
A.sort(reverse=1)
write('%d\n' % sum(A[:M]))
solve()
``` | vfc_135387 | {
"difficulty": "unknown_difficulty",
"memory_limit": "268.435456 megabytes",
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "5.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 2\n1 2 1\n2 3 2\n1 10 100",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2\n1 2 0\n2 3 2\n1 10 100",
"output": "220\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 4\n1 2 2\n0 6 2\n2 10 100",
"output": "12\n",
"type": "stdin_stdout"
}
]
} |
|
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/modify-array-to-maximize-sum-of-adjacent-differences1729/1 | Solve the following coding problem using the programming language python:
Given an array arr of size N, the task is to modify values of this array in such a way that the sum of absolute differences between two consecutive elements is maximized. If the value of an array element is X, then we can change it to either 1 or X. Find the maximum possible value of the sum of absolute differences between two consecutive elements.
Example 1:
Input: N = 4, arr[] = [3, 2, 1, 4, 5]
Output: 8
Explanation: We can modify above array as
arr[] = [3, 1, 1, 4, 1]
Sum of differences =
|1-3| + |1-1| + |4-1| + |1-4| = 8
Which is the maximum obtainable value
among all choices of modification.
Example 2:
Input: N = 2, arr[] = {1, 5}
Output: 4
Explanation: No modification required
Your Task:
You don't need to read input or print anything. Complete the function maximumDifferenceSum() which takes N and array arr as input parameters and returns the integer value
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)
Constraints:
1 β€ N β€ 10^{5}
Write your solution by modifying this code:
```python
#User function Template for python3
class Solution:
def maximumDifferenceSum(self,arr, N):
# code here
```
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
class Solution:
def maximumDifferenceSum(self, arr, N):
dp = [[0] * 2 for i in range(N)]
for i in range(1, N):
dp[i][0] = max(dp[i - 1][0] + abs(arr[i] - arr[i - 1]), dp[i - 1][1] + abs(arr[i] - 1))
dp[i][1] = max(dp[i - 1][0] + abs(1 - arr[i - 1]), dp[i - 1][1])
return max(dp[-1])
``` | vfc_135391 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/modify-array-to-maximize-sum-of-adjacent-differences1729/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 4, arr[] = [3, 2, 1, 4, 5]",
"output": "8",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "N = 2, arr[] = {1, 5}",
"output": "4",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/652/C | Solve the following coding problem using the programming language python:
You are given a permutation p of length n. Also you are given m foe pairs (a_{i}, b_{i}) (1 β€ a_{i}, b_{i} β€ n, a_{i} β b_{i}).
Your task is to count the number of different intervals (x, y) (1 β€ x β€ y β€ n) that do not contain any foe pairs. So you shouldn't count intervals (x, y) that contain at least one foe pair in it (the positions and order of the values from the foe pair are not important).
Consider some example: p = [1, 3, 2, 4] and foe pairs are {(3, 2), (4, 2)}. The interval (1, 3) is incorrect because it contains a foe pair (3, 2). The interval (1, 4) is also incorrect because it contains two foe pairs (3, 2) and (4, 2). But the interval (1, 2) is correct because it doesn't contain any foe pair.
-----Input-----
The first line contains two integers n and m (1 β€ n, m β€ 3Β·10^5) β the length of the permutation p and the number of foe pairs.
The second line contains n distinct integers p_{i} (1 β€ p_{i} β€ n) β the elements of the permutation p.
Each of the next m lines contains two integers (a_{i}, b_{i}) (1 β€ a_{i}, b_{i} β€ n, a_{i} β b_{i}) β the i-th foe pair. Note a foe pair can appear multiple times in the given list.
-----Output-----
Print the only integer c β the number of different intervals (x, y) that does not contain any foe pairs.
Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.
-----Examples-----
Input
4 2
1 3 2 4
3 2
2 4
Output
5
Input
9 5
9 7 2 3 1 4 6 5 8
1 6
4 5
2 7
7 2
2 7
Output
20
-----Note-----
In the first example the intervals from the answer are (1, 1), (1, 2), (2, 2), (3, 3) and (4, 4).
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import sys
def FoePairs():
(n, m) = sys.stdin.readline().split()
n = int(n)
m = int(m)
s = n + 1
p = [0] * s
pos_p = [0] * s
closest_pos = [0] * s
i = 1
line = sys.stdin.readline().split()
while i < s:
t = int(line[i - 1])
p[i] = t
pos_p[t] = i
i += 1
for x in range(0, m):
(start, finish) = sys.stdin.readline().split()
start = int(start)
finish = int(finish)
p_finish = pos_p[finish]
p_start = pos_p[start]
if p_finish > p_start:
closest_pos[finish] = max(closest_pos[finish], p_start)
else:
closest_pos[start] = max(closest_pos[start], p_finish)
i = 1
respuesta = 0
current_closest_pos = 0
while i < s:
current_closest_pos = max(current_closest_pos, closest_pos[p[i]])
respuesta += i - current_closest_pos
i += 1
print(respuesta)
FoePairs()
``` | vfc_135392 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/652/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 2\n1 3 2 4\n3 2\n2 4\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "9 5\n9 7 2 3 1 4 6 5 8\n1 6\n4 5\n2 7\n7 2\n2 7\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1\n1 2\n1 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10 3\n4 10 5 1 6 8 9 2 3 7\n10 5\n2 10\n4 1\n",
"output": "39\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/POGOSTCK | Solve the following coding problem using the programming language python:
Read problems statements [Mandarin] , [Bengali] , [Hindi] , [Russian] and [Vietnamese] as well.
Chef is participating in a pogo stick race. In this competition, there are $N$ squares (numbered $1$ through $N$) in a row. Chef must choose a starting square, enter this square and start jumping on his pogo stick. In each jump, if Chef is at a square $s$, then he can only jump to the square $s+K$. If square $s+K$ does not exist, Chef jumps out of the row of squares and the race ends for him. It is not allowed to stop jumping any earlier.
Each square has a value; let's denote the value of the $i$-th square by $A_{i}$. Initially, Chef has $0$ points. When he jumps in some square (including the initial square), he is awarded a number of points equal to the value of this square, exactly once. Note that if this value is negative, the number of Chef's points is decreased.
Determine the maximum possible total number of points Chef can get if he selects the initial cell optimally.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains two space-separated integers $N$ and $K$.
The second line contains $N$ space-separated integers $A_{1}, A_{2}, \ldots, A_{N}$.
------ Output ------
For each test case, print a single line containing one integer β the maximum number of points.
------ Constraints ------
$1 β€ T β€ 1,000$
$1 β€ N β€ 10^{5}$
$1 β€ K β€ 10^{5}$
$|A_{i}| β€ 10,000$ for each valid $i$
the sum of $N$ over all test cases does not exceed $10^{6}$
------ Subtasks ------
Subtask #1 (30 points):
$N β€ 1,000$
the sum of $N$ over all test cases does not exceed $10,000$
Subtask #2 (70 points): original constraints
----- Sample Input 1 ------
2
5 2
3 6 4 7 2
5 3
3 -5 6 3 10
----- Sample Output 1 ------
13
10
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
for t in range(int(input())):
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
for i in range(k, n):
a[i] = max(a[i], a[i] + a[i - k])
ans = -100000
for i in range(n - k, n):
ans = max(ans, a[i])
print(ans)
``` | vfc_135396 | {
"difficulty": "medium_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/POGOSTCK",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n5 2\n3 6 4 7 2\n5 3\n3 -5 6 3 10",
"output": "13\n10",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1312/B | Solve the following coding problem using the programming language python:
You are given an array $a_1, a_2, \dots , a_n$. Array is good if for each pair of indexes $i < j$ the condition $j - a_j \ne i - a_i$ holds. Can you shuffle this array so that it becomes good? To shuffle an array means to reorder its elements arbitrarily (leaving the initial order is also an option).
For example, if $a = [1, 1, 3, 5]$, then shuffled arrays $[1, 3, 5, 1]$, $[3, 5, 1, 1]$ and $[5, 3, 1, 1]$ are good, but shuffled arrays $[3, 1, 5, 1]$, $[1, 1, 3, 5]$ and $[1, 1, 5, 3]$ aren't.
It's guaranteed that it's always possible to shuffle an array to meet this condition.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases.
The first line of each test case contains one integer $n$ ($1 \le n \le 100$) β the length of array $a$.
The second line of each test case contains $n$ integers $a_1, a_2, \dots , a_n$ ($1 \le a_i \le 100$).
-----Output-----
For each test case print the shuffled version of the array $a$ which is good.
-----Example-----
Input
3
1
7
4
1 1 3 5
6
3 2 1 5 6 4
Output
7
1 5 1 3
2 4 6 1 3 5
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
I = lambda : list(map(int, input().split()))
for _ in range(int(input())):
I()
l = I()
print(' '.join(map(str, sorted(l, reverse=True))))
``` | vfc_135400 | {
"difficulty": "easy",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1312/B",
"time_limit": "2 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1\n7\n4\n1 1 3 5\n6\n3 2 1 5 6 4\n",
"output": "7\n5 3 1 1\n6 5 4 3 2 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n3\n4 2 1\n",
"output": "4 2 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n9\n2 4 3 5 3 1 2 3 69\n",
"output": "69 5 4 3 3 3 2 2 1\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
In a coordinate system,There are 3 chocolate which will be placed at three random position (x1,y1),(x2,y2) and (x3,y3).Ramesh loves Chocolates. Ramesh always moves along a straight line. your task is to find out whether he can have all the chocolates.
Input Format :-
The first line of the input contains an integer T denoting the number of test cases. Each of the next T lines contains coordinates in integer- x1 y1 x2 y2 and x3 y3.
Output Format :-
If Ramesh can get all chocolates then print "YES" otherwise "NO"(without quotes).
Constraints :-
1 β€ T β€ 100
-1000 β€ x1,y1,x2,y2,x3,y3 β€ 1000
SAMPLE INPUT
2
1 1 2 2 3 3
1 2 5 4 10 15
SAMPLE OUTPUT
YES
NO
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
for _ in range(int(input())):
a,b,m,n,x,y = list(map(int,input().split()))
result1 = (n - b) * (x - m)
result2 = (y - n) * (m - a)
if result1 == result2:
print("YES")
else:
print("NO")
``` | vfc_135404 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10\n6 6 4 4 1 1\n7 8 8 5 1 2\n4 8 5 4 1 1\n4 5 5 6 6 7\n7 11 10 4 1 0\n4 12 12 4 1 3\n3 6 8 8 1 3\n3 4 8 6 1 2\n9 5 8 10 1 1\n10 12 14 16 2 4",
"output": "NO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n-5 -12 -10 19 -3 48\n-26 -25 -24 -23 -4 -3\n-8 -8 17 -2 21 11\n3 2 -20 -21 15 14\n45 -6 -8 18 -14 22\n-38 -7 14 8 15 17\n-39 9 20 22 -2 37\n-39 -6 -10 0 -18 12\n7 -11 20 14 7 23\n28 8 17 20 13 47",
"output": "YES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nYES",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n44 89 20 54 87 61\n65 25 84 82 78 98\n62 115 111 81 47 101\n73 22 24 111 56 47\n115 38 36 41 102 112\n32 89 58 91 46 67\n31 23 114 55 119 87\n31 61 84 93 53 42\n77 82 64 67 88 73\n98 49 61 43 79 57",
"output": "YES\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nYES",
"type": "stdin_stdout"
}
]
} |
|
taco | verifiable_code | https://codeforces.com/problemset/problem/492/D | Solve the following coding problem using the programming language python:
Vanya and his friend Vova play a computer game where they need to destroy n monsters to pass a level. Vanya's character performs attack with frequency x hits per second and Vova's character performs attack with frequency y hits per second. Each character spends fixed time to raise a weapon and then he hits (the time to raise the weapon is 1 / x seconds for the first character and 1 / y seconds for the second one). The i-th monster dies after he receives a_{i} hits.
Vanya and Vova wonder who makes the last hit on each monster. If Vanya and Vova make the last hit at the same time, we assume that both of them have made the last hit.
-----Input-----
The first line contains three integers n,x,y (1 β€ n β€ 10^5, 1 β€ x, y β€ 10^6) β the number of monsters, the frequency of Vanya's and Vova's attack, correspondingly.
Next n lines contain integers a_{i} (1 β€ a_{i} β€ 10^9)Β β the number of hits needed do destroy the i-th monster.
-----Output-----
Print n lines. In the i-th line print word "Vanya", if the last hit on the i-th monster was performed by Vanya, "Vova", if Vova performed the last hit, or "Both", if both boys performed it at the same time.
-----Examples-----
Input
4 3 2
1
2
3
4
Output
Vanya
Vova
Vanya
Both
Input
2 1 1
1
2
Output
Both
Both
-----Note-----
In the first sample Vanya makes the first hit at time 1 / 3, Vova makes the second hit at time 1 / 2, Vanya makes the third hit at time 2 / 3, and both boys make the fourth and fifth hit simultaneously at the time 1.
In the second sample Vanya and Vova make the first and second hit simultaneously at time 1.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
(n, x, y) = list(map(int, input().split()))
(cx, cy, A) = (0, 0, [])
while cx < x or cy < y:
if (cx + 1) * y > (cy + 1) * x:
cy += 1
A.append('Vova')
elif (cx + 1) * y < (cy + 1) * x:
cx += 1
A.append('Vanya')
else:
A.append('Both')
A.append('Both')
cx += 1
cy += 1
for _ in range(n):
a = int(input())
a -= 1
a1 = a % (x + y)
print(A[a1])
``` | vfc_135412 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/492/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 3 2\n1\n2\n3\n4\n",
"output": "Vanya\nVova\nVanya\nBoth\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1264/F | Solve the following coding problem using the programming language python:
The well-known Fibonacci sequence $F_0, F_1, F_2,\ldots $ is defined as follows: $F_0 = 0, F_1 = 1$. For each $i \geq 2$: $F_i = F_{i - 1} + F_{i - 2}$.
Given an increasing arithmetic sequence of positive integers with $n$ elements: $(a, a + d, a + 2\cdot d,\ldots, a + (n - 1)\cdot d)$.
You need to find another increasing arithmetic sequence of positive integers with $n$ elements $(b, b + e, b + 2\cdot e,\ldots, b + (n - 1)\cdot e)$ such that: $0 < b, e < 2^{64}$, for all $0\leq i < n$, the decimal representation of $a + i \cdot d$ appears as substring in the last $18$ digits of the decimal representation of $F_{b + i \cdot e}$ (if this number has less than $18$ digits, then we consider all its digits).
-----Input-----
The first line contains three positive integers $n$, $a$, $d$ ($1 \leq n, a, d, a + (n - 1) \cdot d < 10^6$).
-----Output-----
If no such arithmetic sequence exists, print $-1$.
Otherwise, print two integers $b$ and $e$, separated by space in a single line ($0 < b, e < 2^{64}$).
If there are many answers, you can output any of them.
-----Examples-----
Input
3 1 1
Output
2 1
Input
5 1 2
Output
19 5
-----Note-----
In the first test case, we can choose $(b, e) = (2, 1)$, because $F_2 = 1, F_3 = 2, F_4 = 3$.
In the second test case, we can choose $(b, e) = (19, 5)$ because: $F_{19} = 4181$ contains $1$; $F_{24} = 46368$ contains $3$; $F_{29} = 514229$ contains $5$; $F_{34} = 5702887$ contains $7$; $F_{39} = 63245986$ contains $9$.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
c = 9224175735 * 10 ** 8
m = 15 * 10 ** 17
(n, a, d) = map(int, input().split())
print(c * a % m + 1, c * d % m)
``` | vfc_135416 | {
"difficulty": "very_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1264/F",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 1 1\n",
"output": "4417573500000000001 4417573500000000000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 1 2\n",
"output": "4417573500000000001 8835147000000000000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1000 1 1000\n",
"output": "4417573500000000001 1573500000000000000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "999999 1 1\n",
"output": "4417573500000000001 4417573500000000000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 2 179350\n",
"output": "8835147000000000001 3807225000000000000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1 1\n",
"output": "4417573500000000001 4417573500000000000\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/CRICUP | Solve the following coding problem using the programming language python:
It is the World Cup Finals. Chef only finds a match interesting if the skill difference of the competing teams is *less than or equal to* D.
Given that the skills of the teams competing in the final are X and Y respectively, determine whether Chef will find the game interesting or not.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of testcases. The description of T testcases follows.
- Each testcase consists of a single line of input containing three space-separated integers X, Y, and D β the skill levels of the teams and the maximum skill difference.
------ Output Format ------
For each testcase, output "YES" if Chef will find the game interesting, else output "NO" (without the quotes). The checker is case-insensitive, so "YeS" and "nO" etc. are also acceptable.
------ Constraints ------
$1 β€ T β€ 2000$
$1 β€ X, Y β€ 100$
$0 β€ D β€ 100$
----- Sample Input 1 ------
3
5 3 4
5 3 1
5 5 0
----- Sample Output 1 ------
YES
NO
YES
----- explanation 1 ------
Test case $1$: The skill difference between the teams is $2$, which is less than the maximum allowed difference of $4$.
Test case $2$: The skill difference between the teams is $2$, which is more than the maximum allowed difference of $1$.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
t = int(input())
while t > 0:
[x, y, d] = map(int, input().split())
if abs(x - y) <= d:
print('YES')
else:
print('NO')
t -= 1
``` | vfc_135420 | {
"difficulty": "easy",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/CRICUP",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n5 3 4\n5 3 1\n5 5 0\n",
"output": "YES\nNO\nYES\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1320/D | Solve the following coding problem using the programming language python:
In this problem, we will deal with binary strings. Each character of a binary string is either a 0 or a 1. We will also deal with substrings; recall that a substring is a contiguous subsequence of a string. We denote the substring of string $s$ starting from the $l$-th character and ending with the $r$-th character as $s[l \dots r]$. The characters of each string are numbered from $1$.
We can perform several operations on the strings we consider. Each operation is to choose a substring of our string and replace it with another string. There are two possible types of operations: replace 011 with 110, or replace 110 with 011. For example, if we apply exactly one operation to the string 110011110, it can be transformed into 011011110, 110110110, or 110011011.
Binary string $a$ is considered reachable from binary string $b$ if there exists a sequence $s_1$, $s_2$, ..., $s_k$ such that $s_1 = a$, $s_k = b$, and for every $i \in [1, k - 1]$, $s_i$ can be transformed into $s_{i + 1}$ using exactly one operation. Note that $k$ can be equal to $1$, i. e., every string is reachable from itself.
You are given a string $t$ and $q$ queries to it. Each query consists of three integers $l_1$, $l_2$ and $len$. To answer each query, you have to determine whether $t[l_1 \dots l_1 + len - 1]$ is reachable from $t[l_2 \dots l_2 + len - 1]$.
-----Input-----
The first line contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) β the length of string $t$.
The second line contains one string $t$ ($|t| = n$). Each character of $t$ is either 0 or 1.
The third line contains one integer $q$ ($1 \le q \le 2 \cdot 10^5$) β the number of queries.
Then $q$ lines follow, each line represents a query. The $i$-th line contains three integers $l_1$, $l_2$ and $len$ ($1 \le l_1, l_2 \le |t|$, $1 \le len \le |t| - \max(l_1, l_2) + 1$) for the $i$-th query.
-----Output-----
For each query, print either YES if $t[l_1 \dots l_1 + len - 1]$ is reachable from $t[l_2 \dots l_2 + len - 1]$, or NO otherwise. You may print each letter in any register.
-----Example-----
Input
5
11011
3
1 3 3
1 4 2
1 2 3
Output
Yes
Yes
No
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import sys
input = sys.stdin.readline
MOD = 987654103
n = int(input())
t = input()
place = []
f1 = []
e1 = []
s = []
curr = 0
count1 = 0
for i in range(n):
c = t[i]
if c == '0':
if count1:
e1.append(i - 1)
if count1 & 1:
s.append(1)
curr += 1
e1.append(-1)
f1.append(-1)
count1 = 0
else:
f1.append(-1)
e1.append(-1)
place.append(curr)
curr += 1
s.append(0)
else:
if count1 == 0:
f1.append(i)
count1 += 1
place.append(curr)
if count1:
if count1 & 1:
s.append(1)
else:
s.append(0)
curr += 1
e1.append(n - 1)
e1.append(-1)
f1.append(-1)
place.append(curr)
pref = [0]
val = 0
for i in s:
val *= 3
val += i + 1
val %= MOD
pref.append(val)
q = int(input())
out = []
for _ in range(q):
(l1, l2, leng) = map(int, input().split())
l1 -= 1
l2 -= 1
starts = (l1, l2)
hashes = []
for start in starts:
end = start + leng - 1
smap = place[start]
emap = place[end]
if t[end] == '1':
emap -= 1
if s[smap] == 1:
smap += 1
prep = False
app = False
if t[start] == '1':
last = e1[place[start]]
last = min(last, end)
count = last - start + 1
if count % 2:
prep = True
if t[end] == '1':
first = f1[place[end]]
first = max(first, start)
count = end - first + 1
if count % 2:
app = True
preHash = 0
length = 0
if smap <= emap:
length = emap - smap + 1
preHash = pref[emap + 1]
preHash -= pref[smap] * pow(3, emap - smap + 1, MOD)
preHash %= MOD
if length == 0 and prep and app:
app = False
if prep:
preHash += pow(3, length, MOD) * 2
length += 1
if app:
preHash *= 3
preHash += 2
preHash %= MOD
hashes.append(preHash)
if hashes[0] == hashes[1]:
out.append('Yes')
else:
out.append('No')
print('\n'.join(out))
``` | vfc_135424 | {
"difficulty": "hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1320/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n11011\n3\n1 3 3\n1 4 2\n1 2 3\n",
"output": "Yes\nYes\nNo\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n0\n1\n1 1 1\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n010\n3\n1 3 1\n1 3 1\n3 2 1\n",
"output": "Yes\nYes\nNo\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/number-of-diagonals1020/1 | Solve the following coding problem using the programming language python:
Given a number N, the task is to find the number of diagonals in N sided convex polygon.
Example 1:
Input: N = 5
Output: 5
Example 2:
Input: N = 6
Output: 9
Your Task:
You don't need to read input or print anything. Your task is to complete the function diagonals() which takes N as input and returns the number of possible diagonals.
Expected Time Complexity: O(1)
Expected Auxiliary Space: O(1)
Constraints:
3 β€ N β€ 10^{9}
Write your solution by modifying this code:
```python
#User function Template for python3
class Solution:
def diagonals(self, n):
# code here
```
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
class Solution:
def diagonals(self, n):
return int(n * (n - 3) // 2)
``` | vfc_135432 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/number-of-diagonals1020/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 5",
"output": "5",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/POPU2021/problems/EASYABC | Solve the following coding problem using the programming language python:
Alisha has a string of length n. Each character is either 'a', 'b' or 'c'. She has to select two characters s[i] and s[j] such that s[i] != s[j] and i,j are valid indexes. She has to find the maximum value of the absolute difference between i and j i.e abs(i-j) .
Since Alisha is busy with her Semester exams help her find the maximum distance where distance is the maximum value of absolute difference between i and j i.e abs(i-j) .
-----Input:-----
- The first and the only line contains the string s with each character either 'a', 'b', or 'c'.
-----Output:-----
Print a single integer the maximum absolute difference between i and j.
-----Constraints-----
- $1 \leq n \leq 10^5$
- s[i] can either be 'a', 'b' or 'c'.
-----Subtasks-----
- 40 points : $1 \leq n \leq 100$
- 60 points : $1 \leq n \leq 10^5$
-----Sample Input1:-----
aabcaaa
-----Sample Output1:-----
4
-----Sample Input2:-----
aba
-----Sample Output2:-----
1
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
st = input().strip()
b = []
for i in range(len(st)):
for j in range(i + 1, len(st)):
if st[i] != st[j]:
z = abs(i - j)
b.append(z)
print(max(b))
``` | vfc_135433 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/POPU2021/problems/EASYABC",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "aabcaaa\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "aba\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/PPLUCKY | Solve the following coding problem using the programming language python:
Read problems statements in Russian here
Polo, the Penguin, likes lucky strings - the strings that consist only of lucky digits 4 and 7.
He has a lucky string S. Digits in this string are numbered from left to right starting with 1. He performs the following operations on the string while it is possible to do so:
Find a set of all positions, P, such that for every position i in P, S[i] = 4 and S[i+1] = 7. (For example, if S = 744744747, then P = {3, 6, 8}.) Add all elements in P to the result. If there is no such position, then STOP.
Erase all digits in string S with positions i and i + 1 for all i in the set P. After erasing all such digits from S repeat Step 1. (For example, the new S = 744)
Find the result that he will get at the end.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains a single integer N denoting the size of the string S. The second line contains the lucky string S.
------ Output ------
For each test case, output a single line containing the answer to the corresponding test case.
------ Constraints ------
$1 β€ T β€ 100,000$
$1 β€ |S| β€ 100,000$
$The total length of all strings will not exceed 100,000$
------ Example ------
Input:
2
4
4747
10
4447477747
Output:
4
20
------ Β ------
------ Explanation ------
Example case 1. In this case, there is just a single iteration. Since P = {1, 3}, the answer is 1 + 3 = 4.
Example case 2. In this case, there are three iterations. On the first iteration P = {3, 5, 9}. On the second iteration S = 4477, P = {2}. On the third iteration S = 47, P = {1}. So the answer is 3 + 5 + 9 + 2 + 1 = 20.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import sys
class LuckyStars:
bit = []
n = 0
def update(self, i, v):
global bit
global n
i += 1
while i <= n:
bit[i] += 1
i += i & -i
def query(self, i):
global bit
global n
r = 0
i += 1
while i:
r += bit[i]
i -= i & -i
return r
def solve(self, ls):
global bit
global n
n = len(ls)
stack = []
time = [None] * n
for (i, j) in enumerate(ls):
if j == '7':
if stack and stack[-1][0] == '4':
(_, k, t) = stack.pop()
time[k] = t
if stack and stack[-1][0] == '4':
stack[-1][-1] = max(stack[-1][-1], t + 1)
else:
stack.append([j, i, 0])
else:
stack.append([j, i, 0])
bit = [0] * (n + 1)
res = 0
for (i, j) in enumerate(time, 1):
if j != None:
res += i - 2 * self.query(j - 1)
self.update(j, 1)
return res
cases = int(sys.stdin.readline().strip())
solver = LuckyStars()
results = []
for _ in range(cases):
length = int(sys.stdin.readline().strip())
lucky_string = sys.stdin.readline().strip()
results.append(solver.solve(lucky_string))
for result in results:
print(result)
``` | vfc_135437 | {
"difficulty": "very_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/PPLUCKY",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": " 2\n 4\n 4747\n 10\n 4447477747\n ",
"output": " 4\n 20",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/1s-complement2819/1 | Solve the following coding problem using the programming language python:
Given an N bit binary number, find the 1's complement of the number. The ones' complement of a binary number is defined as the value obtained by inverting all the bits in the binary representation of the number (swapping 0s for 1s and vice versa).
Example 1:
Input:
N = 3
S = 101
Output:
010
Explanation:
We get the output by converting 1's in S
to 0 and 0s to 1
Example 2:
Input:
N = 2
S = 10
Output:
01
Explanation:
We get the output by converting 1's in S
to 0 and 0s to 1
Your Task:
You don't need to read input or print anything. Your task is to complete the function onesComplement() which takes the binary string S, its size N as input parameters and returns 1's complement of S of size N.
Expected Time Complexity: O(N)
Expected Space Complexity: O(N)
Constraints:
1<=N<=100
Write your solution by modifying this code:
```python
#User function Template for python3
class Solution:
def onesComplement(self,S,N):
# code here
```
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
class Solution:
def onesComplement(self, S, N):
i = 0
res = ''
for ec in S:
if ec == '0':
res = res + '1'
else:
res = res + '0'
l1 = len(res)
l2 = N
if l2 != l1:
diff = l2 - l1
for i in range(diff):
res = res + '0'
return res
``` | vfc_135442 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/1s-complement2819/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 3\nS = 101",
"output": "010",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "N = 2\nS = 10",
"output": "01",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/219/C | Solve the following coding problem using the programming language python:
A colored stripe is represented by a horizontal row of n square cells, each cell is pained one of k colors. Your task is to repaint the minimum number of cells so that no two neighbouring cells are of the same color. You can use any color from 1 to k to repaint the cells.
Input
The first input line contains two integers n and k (1 β€ n β€ 5Β·105; 2 β€ k β€ 26). The second line contains n uppercase English letters. Letter "A" stands for the first color, letter "B" stands for the second color and so on. The first k English letters may be used. Each letter represents the color of the corresponding cell of the stripe.
Output
Print a single integer β the required minimum number of repaintings. In the second line print any possible variant of the repainted stripe.
Examples
Input
6 3
ABBACC
Output
2
ABCACA
Input
3 2
BBB
Output
1
BAB
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
(n, k) = map(int, input().split())
s = input()
if k == 2:
sol1 = [s[i] for i in range(n)]
ans1 = 0
for i in range(n):
if i % 2 == 0 and sol1[i] == 'B':
ans1 += 1
sol1[i] = 'A'
elif i % 2 != 0 and sol1[i] == 'A':
ans1 += 1
sol1[i] = 'B'
sol2 = [s[i] for i in range(n)]
ans2 = 0
for i in range(n):
if i % 2 == 0 and sol2[i] == 'A':
ans2 += 1
sol2[i] = 'B'
elif i % 2 != 0 and sol2[i] == 'B':
ans2 += 1
sol2[i] = 'A'
if ans1 <= ans2:
print(ans1)
print(''.join((str(x) for x in sol1)))
else:
print(ans2)
print(''.join((str(x) for x in sol2)))
else:
s = [s[i] for i in range(n)]
ans = 0
for i in range(1, n):
if s[i] == s[i - 1]:
ans += 1
x = chr((ord(s[i - 1]) - 65 + 1) % k + 65)
if i == n - 1 or s[i + 1] != x:
s[i] = x
else:
y = chr((ord(s[i - 1]) - 65 + 1 + 1) % k + 65)
s[i] = y
print(ans)
print(''.join((str(x) for x in s)))
``` | vfc_135443 | {
"difficulty": "medium_hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/219/C",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 2\nAABABA\n",
"output": "1\nBABABA",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2\nBBA\n",
"output": "1\nABA",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "100 2\nBBBBBBBAAABBAAAABAABBBAABABAAABBBABBAAAABBABAAAAAAAAAAAAABAAABBBAAABAABBBBBBBABBBBAABAAABBBAABBAAAAB\n",
"output": "48\nBABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/SLAEL | Solve the following coding problem using the programming language python:
Find the length of the longest contiguous segment in an array, in which if a given element $K$ is inserted, $K$ becomes the second largest element of that subarray.
-----Input:-----
- The first line will contain $T$, number of test cases. Then the test cases follow.
- The first line of each test case contains two integers $N$ and $K$.
- The next line contains N space-separated integers Ai denoting the elements of the array.
-----Output:-----
Print a single line corresponding to each test case β the length of the largest segment.
-----Constraints-----
- $1 \leq T \leq 10$
- $1 \leq N \leq 10^6$
- $1 \leq Ai, K \leq 10^9$
- Sum of N across all test cases doesn't exceed $10^6$
-----Sample Input:-----
2
5 3
2 4 2 4 2
8 5
9 3 5 7 8 11 17 2
-----Sample Output:-----
5
3
-----EXPLANATION:-----
If 3 is inserted at anywhere in the array, it is the second largest element. Hence the maximum length is 5.
If 5 is inserted anywhere between 1st and 4th element, it is the second largest element. The length of such subarray is 3.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import sys
from sys import stdin, stdout
t = int(stdin.readline())
for _ in range(t):
(n, k) = map(int, stdin.readline().strip().split(' '))
arr = list(map(int, stdin.readline().strip().split(' ')))
tarr = []
p = -1
for i in range(len(arr)):
if arr[i] > k:
if p == -1:
p = arr[i]
tarr.append(i)
elif arr[i] != p:
tarr.append(i)
p = arr[i]
if len(tarr) == 0:
print(0)
elif len(tarr) == 1:
print(len(arr))
else:
mtn = max(tarr[1], +len(tarr) - tarr[-2] - 1)
for i in range(1, len(tarr) - 1):
mtn = max(mtn, tarr[i] - tarr[i - 1] + tarr[i + 1] - tarr[i] - 1)
print(mtn)
``` | vfc_135447 | {
"difficulty": "hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/SLAEL",
"time_limit": "2 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n5 3\n2 4 2 4 2\n8 5\n9 3 5 7 8 11 17 2\n",
"output": "5\n3\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/tidy-number0519/1 | Solve the following coding problem using the programming language python:
Given a number N.Check if it is tidy or not.
A tidy number is a number whose digits are in non-decreasing order.
Example 1:
Input:
1234
Output:
1
Explanation:
Since 1<2<3<4,therefore the number is tidy.
Example 2:
Input:
1243
Output:
0
Explanation:
4>3, so the number is not tidy.
Your Task:
You don't need to read input or print anything.Your task is to complete the function isTidy() which takes an Integer N as input parameter and returns 1 if it is tidy.Otherwise, it returns 0.
Expected Time Complexity:O(LogN)
Expected Auxillary Space:O(1)
Constraints:
1<=N<=10^{9}
Write your solution by modifying this code:
```python
#User function Template for python3
class Solution:
def isTidy(self,N):
#code here
```
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
class Solution:
def isTidy(self, N):
a = str(N)
n = sorted(str(N))
l1 = list(a)
l2 = list(n)
if l1 == l2:
return 1
else:
return 0
``` | vfc_135453 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/tidy-number0519/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1234",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1243",
"output": "0",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.hackerrank.com/challenges/hard-homework/problem | Solve the following coding problem using the programming language python:
Aaron is struggling with trigonometric functions, so his teacher gave him extra homework. Given an integer, $n$, he must answer the following question:
What is the maximum value of $sin(x)+sin(y)+sin(z)$, where $x}$, $y$, and $z$ are positive integers and $x+y+z=n$?
Help Aaron by finding this maximal value and printing it correct to ${9}$ decimal places.
Input Format
A single positive integer denoting $n$.
Constraints
$3\leq n\leq3\times10^{6}$
Output Format
Print a single real number rounded to a scale of exactly ${9}$ decimal places (e.g., $0.123456789$) denoting the maximum possible value.
Sample Input 0
3
Sample Output 0
2.524412954
Explanation 0
The only possible variant is $x=1$, $y=1$, and $z=1$, which gives us $sin(1)+sin(1)+sin(1)=2.524412954$
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
from math import sin, pi
from itertools import product
from random import shuffle
n = int(input())
a = list(range(1, n - 1))
a.sort(key=lambda v: v % (pi * 2))
lena = len(a)
offsets = list(product(range(-500, 501), range(-500, 501)))
shuffle(offsets)
last_offset = offsets[len(offsets) - 1]
i = 0
j = lena // 2
sm = -4
while True:
for (di, dj) in offsets:
x = a[(i + lena + di) % lena]
y = a[(j + lena + dj) % lena]
z = n - x - y
sm2 = sin(x) + sin(y) + sin(z)
if sm2 > sm and z > 0:
i = (i + lena + di) % lena
j = (j + lena + dj) % lena
sm = sm2
break
if (di, dj) == last_offset:
break
print('%.9f' % sm)
``` | vfc_135454 | {
"difficulty": "hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/hard-homework/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n",
"output": "2.524412954\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/design-twitter/1 | Solve the following coding problem using the programming language python:
Design a simplified version of Twitter where users can post tweets, follow/unfollow another user and is able to see the 10 most recent tweets in the user's news feed. Your design should support the following methods:
postTweet (userId, tweetId): Compose a new tweet.
getNewsFeed (userId): Retrieve the 10 most recent tweet ids in the user's news feed (If total number of tweets in news feed is less than 10, then return all). Each item in the news feed must be posted by users who the user followed or by the user herself. Tweets must be ordered from most recent to least recent.
follow (followerId, followeeId): Follower follows a followee.
unfollow (followerId, followeeId): Follower unfollows a followee.
Example 1:
Input:
postTweet(1, 5);
getNewsFeed(1);
follow(1, 2);
postTweet(2, 6);
getNewsFeed(1);
unfollow(1, 2);
getNewsFeed(1);
Output:
[5]
[6, 5]
[5]
Explanation:
postTweet(1,5): User 1 posts a new tweet (id=5)
getNewsFeed(1): Return a list with 1 tweet [5]
follow(1,2) : User 1 follows user 2.
postTweet(2,6): User 2 posts a new tweet (id=6)
getNewsFeed(1): Return a list with 2 tweets
[6,5]. One his own tweet and one followee's tweet
(sorted from most recent to least recent).
unfollow(1,2) : User 1 unfollows user 2
getNewsFeed(1): Return a list with 1 tweet [5],
because user 1 is no longer following anyone.
Example 2:
Input:
follow(1, 2);
postTweet(1, 3);
getNewsFeed(2);
Output:
[]
Explanation:
follow(1,2) : User 1 follows user 2.
postTweet(1,3): User 1 posts a new tweet (id=3)
getNewsFeed(2): Return a list with 0 tweet [],
because user2 have no tweets and don't follow
anyone (user1 follows user 2 but user 2 don't
follow anyone)
Your Task:
You don't need to read input or print anything. Your task is to design your data structure inside the class Twitter and complete the functions postTweet(), getNewsFeed(), follow(), unfollow(), and the constructor.
Constraints:
1 <= no. of queries <= 1000
1 <= userId, tweetId, followerId, followeeId <= 10^{5}
Write your solution by modifying this code:
```python
#User function Template for python3
class Twitter:
# Compose a new tweet
def postTweet(self, userId: int, tweetId: int):
# Code here
# Retrieve the 10 most recent tweet ids as mentioned in question
def getNewsFeed(self, userId: int):
# Code here
# Follower follows a followee. If the operation is invalid, it should be a no-op.
def follow(self, followerId: int, followeeId: int):
# Code here
# Follower unfollows a followee. If the operation is invalid, it should be a no-op.
def unfollow(self, followerId: int, followeeId: int):
# Code here
```
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
from collections import defaultdict
import heapq
class Twitter:
def __init__(self):
self.count = 0
self.tweetMap = defaultdict(list)
self.followMap = defaultdict(set)
def postTweet(self, userId: int, tweetId: int):
self.tweetMap[userId].append([self.count, tweetId])
self.count -= 1
def getNewsFeed(self, userId: int):
res = []
minheap = []
self.followMap[userId].add(userId)
for followeeId in self.followMap[userId]:
if followeeId in self.tweetMap:
index = len(self.tweetMap[followeeId]) - 1
(count, tweetId) = self.tweetMap[followeeId][index]
minheap.append([count, tweetId, followeeId, index - 1])
heapq.heapify(minheap)
while minheap and len(res) < 10:
(count, tweetId, followeeId, index) = heapq.heappop(minheap)
res.append(tweetId)
if index >= 0:
(count, tweetId) = self.tweetMap[followeeId][index]
heapq.heappush(minheap, [count, tweetId, followeeId, index - 1])
return res
def follow(self, followerId: int, followeeId: int):
self.followMap[followerId].add(followeeId)
def unfollow(self, followerId: int, followeeId: int):
if followeeId in self.followMap[followerId]:
self.followMap[followerId].remove(followeeId)
``` | vfc_135458 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/design-twitter/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "postTweet(1, 5);\r\ngetNewsFeed(1);\r\nfollow(1, 2);\r\npostTweet(2, 6);\r\ngetNewsFeed(1);\r\nunfollow(1, 2);\r\ngetNewsFeed(1);",
"output": "[5]\r\n[6, 5]\r\n[5]",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "follow(1, 2);\r\npostTweet(1, 3);\r\ngetNewsFeed(2);",
"output": "[]",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/224/D | Solve the following coding problem using the programming language python:
A subsequence of length |x| of string s = s1s2... s|s| (where |s| is the length of string s) is a string x = sk1sk2... sk|x| (1 β€ k1 < k2 < ... < k|x| β€ |s|).
You've got two strings β s and t. Let's consider all subsequences of string s, coinciding with string t. Is it true that each character of string s occurs in at least one of these subsequences? In other words, is it true that for all i (1 β€ i β€ |s|), there is such subsequence x = sk1sk2... sk|x| of string s, that x = t and for some j (1 β€ j β€ |x|) kj = i.
Input
The first line contains string s, the second line contains string t. Each line consists only of lowercase English letters. The given strings are non-empty, the length of each string does not exceed 2Β·105.
Output
Print "Yes" (without the quotes), if each character of the string s occurs in at least one of the described subsequences, or "No" (without the quotes) otherwise.
Examples
Input
abab
ab
Output
Yes
Input
abacaba
aba
Output
No
Input
abc
ba
Output
No
Note
In the first sample string t can occur in the string s as a subsequence in three ways: abab, abab and abab. In these occurrences each character of string s occurs at least once.
In the second sample the 4-th character of the string s doesn't occur in any occurrence of string t.
In the third sample there is no occurrence of string t in string s.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import bisect
import string
s = input()
t = input()
max_match = [0 for i in range(len(s))]
min_match = [0 for i in range(len(s))]
char_idx = [0 for i in range(30)]
char_occur = [[] for i in range(30)]
for (i, ch) in enumerate(t):
idx = ord(ch) - ord('a')
char_occur[idx].append(i)
for ch in string.ascii_lowercase:
idx = ord(ch) - ord('a')
char_occur[idx].append(len(t) + 1)
matched = -1
for (i, ch) in enumerate(s):
if matched == len(t) - 1:
max_match[i] = matched
else:
if ch == t[matched + 1]:
matched += 1
max_match[i] = matched
matched = len(t)
for (i, ch) in enumerate(s[::-1]):
i = len(s) - i - 1
if matched == 0:
min_match[i] = matched
else:
if ch == t[matched - 1]:
matched -= 1
min_match[i] = matched
for (i, ch) in enumerate(s):
low = min_match[i]
high = max_match[i]
ch = ord(ch) - ord('a')
idx = char_idx[ch]
while idx < len(char_occur[ch]) and char_occur[ch][idx] < low:
idx += 1
char_idx[ch] = idx
if idx == len(char_occur[ch]):
print('No')
exit()
if char_occur[ch][idx] > high:
print('No')
exit()
print('Yes')
``` | vfc_135460 | {
"difficulty": "hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/224/D",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "babaabaabb\nbbccb\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "aaaaaa\naaaaaaa\n",
"output": "No\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/192/C | Solve the following coding problem using the programming language python:
The ancient Berlanders believed that the longer the name, the more important its bearer is. Thus, Berland kings were famous for their long names. But long names are somewhat inconvenient, so the Berlanders started to abbreviate the names of their kings. They called every king by the first letters of its name. Thus, the king, whose name was Victorious Vasily Pupkin, was always called by the berlanders VVP.
In Berland over its long history many dynasties of kings replaced each other, but they were all united by common traditions. Thus, according to one Berland traditions, to maintain stability in the country, the first name of the heir should be the same as the last name his predecessor (hence, the first letter of the abbreviated name of the heir coincides with the last letter of the abbreviated name of the predecessor). Berlanders appreciate stability, so this tradition has never been broken. Also Berlanders like perfection, so another tradition requires that the first name of the first king in the dynasty coincides with the last name of the last king in this dynasty (hence, the first letter of the abbreviated name of the first king coincides with the last letter of the abbreviated name of the last king). This tradition, of course, has also been always observed.
The name of a dynasty is formed by very simple rules: we take all the short names of the kings in the order in which they ruled, and write them in one line. Thus, a dynasty of kings "ab" and "ba" is called "abba", and the dynasty, which had only the king "abca", is called "abca".
Vasya, a historian, has recently found a list of abbreviated names of all Berland kings and their relatives. Help Vasya to find the maximally long name of the dynasty that could have existed in Berland.
Note that in his list all the names are ordered by the time, that is, if name A is earlier in the list than B, then if A and B were kings, then king A ruled before king B.
Input
The first line contains integer n (1 β€ n β€ 5Β·105) β the number of names in Vasya's list. Next n lines contain n abbreviated names, one per line. An abbreviated name is a non-empty sequence of lowercase Latin letters. Its length does not exceed 10 characters.
Output
Print a single number β length of the sought dynasty's name in letters.
If Vasya's list is wrong and no dynasty can be found there, print a single number 0.
Examples
Input
3
abc
ca
cba
Output
6
Input
4
vvp
vvp
dam
vvp
Output
0
Input
3
ab
c
def
Output
1
Note
In the first sample two dynasties can exist: the one called "abcca" (with the first and second kings) and the one called "abccba" (with the first and third kings).
In the second sample there aren't acceptable dynasties.
The only dynasty in the third sample consists of one king, his name is "c".
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import sys
import math
from heapq import *
input = sys.stdin.readline
from functools import cmp_to_key
def pi():
return int(input())
def pl():
return int(input(), 16)
def ti():
return list(map(int, input().split()))
def ts():
s = input()
return list(s[:len(s) - 1])
def invr():
return map(int, input().split())
mod = 1000000007
f = []
def fact(n, m):
global f
f = [1 for i in range(n + 1)]
f[0] = 1
for i in range(1, n + 1):
f[i] = f[i - 1] * i % m
def fast_mod_exp(a, b, m):
res = 1
while b > 0:
if b & 1:
res = res * a % m
a = a * a % m
b = b >> 1
return res
def inverseMod(n, m):
return fast_mod_exp(n, m - 2, m)
def ncr(n, r, m):
if n < 0 or r < 0 or r > n:
return 0
if r == 0:
return 1
return f[n] * inverseMod(f[n - r], m) % m * inverseMod(f[r], m) % m
def main():
C()
def C():
n = pi()
x = []
dp = [[0 for j in range(26)] for i in range(26)]
ans = 0
for i in range(n):
x.append(input()[:-1])
l = ord(x[i][0]) - ord('a')
r = ord(x[i][len(x[i]) - 1]) - ord('a')
for j in range(26):
if dp[j][l] != 0:
dp[j][r] = max(dp[j][r], dp[j][l] + len(x[i]))
dp[l][r] = max(dp[l][r], len(x[i]))
for i in range(26):
ans = max(ans, dp[i][i])
print(ans)
main()
``` | vfc_135468 | {
"difficulty": "medium",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/192/C",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\nab\nbc\ncd\nde\nffffffffff\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "50\nagecd\ncghafi\nfiide\niecc\njbdcfjhgd\ndiee\nhfeg\nehc\ngfijgjh\ngacaifebg\ndicbbddc\nhjgciaei\njjcdh\ng\ngc\ncf\nhfdjhd\nc\nicidbec\nji\neeh\ncgeejggc\nacfd\njjg\najefdj\neghhebiic\nbih\ngbb\njjaa\nidc\ngafi\necg\ndbigbjiehj\ncedif\nahidfaaajg\nhfhhiccbgb\ndgegjgieif\nhgjebhfdc\nj\nahehd\nahdah\nbijbhh\na\ndabiggfhac\ndedigbjbf\nihbdj\niihagchd\ngfebhfdi\njbjdcggdh\nf\n",
"output": "37\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/82/D | Solve the following coding problem using the programming language python:
Vasya has recently developed a new algorithm to optimize the reception of customer flow and he considered the following problem.
Let the queue to the cashier contain n people, at that each of them is characterized by a positive integer ai β that is the time needed to work with this customer. What is special about this very cashier is that it can serve two customers simultaneously. However, if two customers need ai and aj of time to be served, the time needed to work with both of them customers is equal to max(ai, aj). Please note that working with customers is an uninterruptable process, and therefore, if two people simultaneously come to the cashier, it means that they begin to be served simultaneously, and will both finish simultaneously (it is possible that one of them will have to wait).
Vasya used in his algorithm an ingenious heuristic β as long as the queue has more than one person waiting, then some two people of the first three standing in front of the queue are sent simultaneously. If the queue has only one customer number i, then he goes to the cashier, and is served within ai of time. Note that the total number of phases of serving a customer will always be equal to βn / 2β.
Vasya thinks that this method will help to cope with the queues we all hate. That's why he asked you to work out a program that will determine the minimum time during which the whole queue will be served using this algorithm.
Input
The first line of the input file contains a single number n (1 β€ n β€ 1000), which is the number of people in the sequence. The second line contains space-separated integers a1, a2, ..., an (1 β€ ai β€ 106). The people are numbered starting from the cashier to the end of the queue.
Output
Print on the first line a single number β the minimum time needed to process all n people. Then on βn / 2β lines print the order in which customers will be served. Each line (probably, except for the last one) must contain two numbers separated by a space β the numbers of customers who will be served at the current stage of processing. If n is odd, then the last line must contain a single number β the number of the last served customer in the queue. The customers are numbered starting from 1.
Examples
Input
4
1 2 3 4
Output
6
1 2
3 4
Input
5
2 4 3 1 4
Output
8
1 3
2 5
4
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def do():
n = int(input())
costs = [int(c) for c in input().split(' ')]
next = {}
memo = {}
def dp(i, pre):
if i == n:
memo[i, pre] = [costs[pre], [pre]]
return memo[i, pre]
if i == n - 1:
memo[i, pre] = [max(costs[pre], costs[i]), [pre, i]]
return memo[i, pre]
if (i, pre) not in memo:
(left1, nxt1) = dp(i + 2, pre)
(left2, nxt2) = dp(i + 2, i)
(left3, nxt3) = dp(i + 2, i + 1)
left1 += max(costs[i], costs[i + 1])
left2 += max(costs[pre], costs[i + 1])
left3 += max(costs[pre], costs[i])
m = min(left1, left2, left3)
if m == left3:
nxt = nxt3
cur = [pre, i]
next[i, pre] = (i + 2, i + 1)
elif m == left2:
nxt = nxt2
cur = [pre, i + 1]
next[i, pre] = (i + 2, i)
else:
nxt = nxt1
cur = [i, i + 1]
next[i, pre] = (i + 2, pre)
memo[i, pre] = [m, cur]
return memo[i, pre]
(res, _) = dp(1, 0)
state = (1, 0)
print(res)
while True:
print(' '.join((str(c + 1) for c in memo[state][1])))
if state not in next:
break
state = next[state]
return 0
do()
``` | vfc_135472 | {
"difficulty": "hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/82/D",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "55\n33 64 51 38 37 44 63 89 60 90 33 67 82 81 40 41 58 86 47 78 60 86 81 43 57 89 39 72 59 88 47 41 59 79 35 41 67 57 70 55 90 46 37 64 78 55 82 88 81 60 46 75 34 79 51\n",
"output": "1814\n2 3\n1 5\n4 6\n7 9\n8 10\n11 12\n13 14\n15 16\n17 19\n18 20\n22 23\n21 25\n24 27\n28 29\n26 30\n31 32\n33 34\n35 36\n37 39\n38 40\n42 43\n44 45\n41 47\n48 49\n46 50\n51 53\n52 54\n55\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8\n100 1 2 3 1000 3 2 1\n",
"output": "1007\n2 3\n1 5\n4 6\n7 8\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
D: Many Decimal Integers
problem
Given a string S consisting only of numbers (0-9) and a string T consisting only of numbers and `?`. S and T are the same length.
Consider changing each `?` That exists in T to one of the numbers from 0 to 9 to create the string T'consisting of only numbers. At this time, it must be f (T') \ leq f (S). Where f (t) is a function that returns an integer value when the string t is read as a decimal number. Also, the number in the most significant digit of T'may be 0.
For all possible strings T', find the remainder of the sum of the values ββof f (T') divided by 10 ^ 9 + 7. If there is no T'that meets the conditions, answer 0.
Input format
S
T
Constraint
* 1 \ leq | S | = | T | \ leq 2 \ times 10 ^ 5
* S is a string consisting only of numbers (0 to 9)
* T is a string consisting only of numbers and `?`
Output format
Divide the sum of T's that satisfy the condition by 10 ^ 9 + 7 and output the remainder on one line.
Input example 1
73
6?
Output example 1
645
There are 10 possible strings for T', from 60 to 69. The sum of these is 645.
Input example 2
42
? 1
Output example 2
105
The number in the most significant digit of T'can be 0, so 01 also satisfies the condition.
Input example 3
1730597319
16 ?? 35 ?? 8?
Output example 3
502295105
Find the remainder divided by 10 ^ 9 + 7.
Example
Input
73
6?
Output
645
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
from collections import defaultdict, deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI():
return [int(x) for x in sys.stdin.readline().split()]
def I():
return int(sys.stdin.readline())
def LS():
return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == '\n':
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
def solve():
s = list(map(int, input()))
t = list(input())
n = len(t)
for i in range(n):
if t[i].isdecimal():
t[i] = int(t[i])
dp = [[[0] * 2 for j in range(2)] for i in range(n + 1)]
dp[0][0] = [1, 0]
p = [pow(10, i, mod) for i in range(n)]
for i in range(n):
ni = i + 1
for j in range(2):
if t[i] == '?':
x = 9 if j else s[i]
for d in range(x + 1):
nj = j | (d < s[i])
dp[ni][nj][0] += dp[i][j][0]
dp[ni][nj][1] += dp[i][j][0] * d + 10 * dp[i][j][1]
dp[ni][nj][0] %= mod
dp[ni][nj][1] %= mod
else:
d = t[i]
nj = j | (d < s[i])
if d <= s[i]:
dp[ni][nj][0] += dp[i][j][0]
dp[ni][nj][1] += dp[i][j][0] * d + 10 * dp[i][j][1]
dp[ni][nj][0] %= mod
dp[ni][nj][1] %= mod
elif nj:
dp[ni][nj][0] += dp[i][j][0]
dp[ni][nj][1] += dp[i][j][0] * d + 10 * dp[i][j][1]
dp[ni][nj][0] %= mod
dp[ni][nj][1] %= mod
print((dp[-1][0][1] + dp[-1][1][1]) % mod)
return
solve()
``` | vfc_135476 | {
"difficulty": "unknown_difficulty",
"memory_limit": "268.435456 megabytes",
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "1.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "73\n?6",
"output": "252\n",
"type": "stdin_stdout"
}
]
} |
|
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/remove-duplicates-in-small-prime-array/1 | Solve the following coding problem using the programming language python:
Given an array consisting of only prime numbers, remove all duplicate numbers from it.
Example 1:
Input:
N = 6
A[] = {2,2,3,3,7,5}
Output: 2 3 7 5
Explanation: After removing the duplicate
2 and 3 we get 2 3 7 5.
Your Task:
Complete the function removeDuplicate() that takes the array of integers and N as input parameters and returns the modified array which has no duplicates. Retain only the first occurrence of the duplicate element. The elements in the returning array should be in the same order as they appear in the original array.
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(1).
Constraints:
1<=N=10^{6}
2<=A[i]<100
Write your solution by modifying this code:
```python
class Solution:
def removeDuplicates(self, arr):
# code here
```
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
class Solution:
def removeDuplicates(self, arr):
ans = []
s = set()
for ele in arr:
if ele not in s:
ans.append(ele)
s.add(ele)
return ans
``` | vfc_135480 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/remove-duplicates-in-small-prime-array/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 6\nA[] = {2,2,3,3,7,5}",
"output": "2 3 7 5",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.hackerrank.com/challenges/connecting-towns/problem | Solve the following coding problem using the programming language python:
Cities on a map are connected by a number of roads. The number of roads between each city is in an array and city ${0}$ is the starting location. The number of roads from city ${0}$ to city ${1}$ is the first value in the array, from city ${1}$ to city $2$ is the second, and so on.
How many paths are there from city ${0}$ to the last city in the list, modulo $1234567$?
Example
$n=4$
$routes=[3,4,5]$
There are $3$ roads to city ${1}$, ${4}$ roads to city $2$ and $5$ roads to city $3$. The total number of roads is $3\times4\times5\mod1234567=60$.
Note
Pass all the towns T_{i} for i=1 to n-1 in numerical order to reach T_{n}.
Function Description
Complete the connectingTowns function in the editor below.
connectingTowns has the following parameters:
int n: the number of towns
int routes[n-1]: the number of routes between towns
Returns
int: the total number of routes, modulo 1234567.
Input Format
The first line contains an integer T, T test-cases follow.
Each test-case has 2 lines.
The first line contains an integer N (the number of towns).
The second line contains N - 1 space separated integers where the i^{th} integer denotes the number of routes, N_{i}, from the town T_{i} to T_{i+1}
Constraints
1 <= T<=1000
2< N <=100
1 <= routes[i] <=1000
Sample Input
2
3
1 3
4
2 2 2
Sample Output
3
8
Explanation
Case 1: 1 route from T_{1} to T_{2}, 3 routes from T_{2} to T_{3}, hence only 3 routes.
Case 2: There are 2 routes from each city to the next, hence 2 * 2 * 2 = 8.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
t = int(input())
for i in range(t):
n = int(input())
p = 1
r = input().split(' ')
for i in range(n - 1):
p = p * int(r[i])
p = p % 1234567
print(p)
``` | vfc_135481 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/connecting-towns/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3\n1 3\n4\n2 2 2\n",
"output": "3\n8\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/279/D | Solve the following coding problem using the programming language python:
You've got a positive integer sequence a_1, a_2, ..., a_{n}. All numbers in the sequence are distinct. Let's fix the set of variables b_1, b_2, ..., b_{m}. Initially each variable b_{i} (1 β€ i β€ m) contains the value of zero. Consider the following sequence, consisting of n operations.
The first operation is assigning the value of a_1 to some variable b_{x} (1 β€ x β€ m). Each of the following n - 1 operations is assigning to some variable b_{y} the value that is equal to the sum of values that are stored in the variables b_{i} and b_{j} (1 β€ i, j, y β€ m). At that, the value that is assigned on the t-th operation, must equal a_{t}. For each operation numbers y, i, j are chosen anew.
Your task is to find the minimum number of variables m, such that those variables can help you perform the described sequence of operations.
-----Input-----
The first line contains integer n (1 β€ n β€ 23). The second line contains n space-separated integers a_1, a_2, ..., a_{n} (1 β€ a_{k} β€ 10^9).
It is guaranteed that all numbers in the sequence are distinct.
-----Output-----
In a single line print a single number β the minimum number of variables m, such that those variables can help you perform the described sequence of operations.
If you cannot perform the sequence of operations at any m, print -1.
-----Examples-----
Input
5
1 2 3 6 8
Output
2
Input
3
3 6 5
Output
-1
Input
6
2 4 8 6 10 18
Output
3
-----Note-----
In the first sample, you can use two variables b_1 and b_2 to perform the following sequence of operations. b_1 := 1; b_2 := b_1 + b_1; b_1 := b_1 + b_2; b_1 := b_1 + b_1; b_1 := b_1 + b_2.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def Solve(x, B):
if (X, x, B) in Mem:
return Mem[X, x, B]
if len(B) > X:
return False
if x == len(L):
return True
if Form(L[x], B):
A = list(B)
for e in range(len(B)):
r = A[e]
A[e] = L[x]
if Solve(x + 1, tuple(sorted(A))):
Mem[X, x, B] = True
return True
A[e] = r
A += [L[x]]
if Solve(x + 1, tuple(sorted(A))):
Mem[X, x, B] = True
return True
Mem[X, x, B] = False
return False
def Form(x, B):
for i in range(len(B)):
for j in range(i, len(B)):
if B[i] + B[j] == x:
return True
return False
n = int(input())
L = list(map(int, input().split()))
done = False
Mem = {}
for X in range(1, n + 1):
if Solve(1, (L[0],)):
print(X)
done = True
break
if not done:
print(-1)
``` | vfc_135485 | {
"difficulty": "hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/279/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 2 3 6 8\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n3 6 5\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n2 4 8 6 10 18\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7\n1 2 4 5 3 6 7\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n11 22 44 88 132 264 66 33 165 55\n",
"output": "5\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/RPD | Solve the following coding problem using the programming language python:
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef is attending math classes. On each day, the teacher gives him homework. Yesterday, the teacher gave Chef a sequence of positive integers and asked him to find the maximum product of two different elements of this sequence. This homework was easy for Chef, since he knew that he should select the biggest two numbers.
However, today, the homework is a little bit different. Again, Chef has a sequence of positive integers $A_{1}, A_{2}, \ldots, A_{N}$, but he should find two different elements of this sequence such that the sum of digits (in base $10$) of their product is maximum possible.
Chef thought, mistakenly, that he can still select the two largest elements and compute the sum of digits of their product. Show him that he is wrong by finding the correct answer β the maximum possible sum of digits of a product of two different elements of the sequence $A$.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of the input contains a single integer $N$.
The second line contains $N$ space-separated integers $A_{1}, A_{2}, \ldots, A_{N}$.
------ Output ------
For each test case, print a single line containing one integer β the maximum sum of digits.
------ Constraints ------
$1 β€ T β€ 100$
$2 β€ N β€ 100$
$1 β€ A_{i} β€ 10^{4}$ for each valid $i$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
3
2
2 8
3
8 2 8
3
9 10 11
----- Sample Output 1 ------
7
10
18
----- explanation 1 ------
Example case 1: The only two numbers Chef can choose are $2$ and $8$. Their product is $16$ and the sum of digits of $16$ is $7$.
Example case 2: Chef can choose $8$ and $8$; their product is $64$. Note that it is allowed to choose two different elements with the same value.
Example case 3: Chef can choose $9$ and $11$. Their product is $99$ and the sum of its digits is $18$. Note that choosing $10$ and $11$ will result in a larger product ($110$), but the sum of its digits is just $2$.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def digsum(s):
count = 0
for d in s:
count += int(d)
return count
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
max = 0
for i in range(n - 1):
for j in range(i + 1, n):
test = digsum(str(a[i] * a[j]))
if max < test:
max = test
print(max)
``` | vfc_135489 | {
"difficulty": "easy",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/RPD",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n2\n2 8\n3 \n8 2 8\n3\n9 10 11",
"output": "7\n10\n18",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
The surveyor starship Hakodate-maru is famous for her two fuel containers with unbounded capacities. They hold the same type of atomic fuel balls.
There, however, is an inconvenience. The shapes of the fuel containers #1 and #2 are always cubic and regular tetrahedral respectively. Both of the fuel containers should be either empty or filled according to their shapes. Otherwise, the fuel balls become extremely unstable and may explode in the fuel containers. Thus, the number of fuel balls for the container #1 should be a cubic number (n3 for some n = 0, 1, 2, 3,... ) and that for the container #2 should be a tetrahedral number ( n(n + 1)(n + 2)/6 for some n = 0, 1, 2, 3,... ).
Hakodate-maru is now at the star base Goryokaku preparing for the next mission to create a precise and detailed chart of stars and interstellar matters. Both of the fuel containers are now empty. Commander Parus of Goryokaku will soon send a message to Captain Future of Hakodate-maru on how many fuel balls Goryokaku can supply. Captain Future should quickly answer to Commander Parus on how many fuel balls she requests before her ship leaves Goryokaku. Of course, Captain Future and her omcers want as many fuel balls as possible.
For example, consider the case Commander Parus offers 151200 fuel balls. If only the fuel container #1 were available (i.e. ifthe fuel container #2 were unavailable), at most 148877 fuel balls could be put into the fuel container since 148877 = 53 Γ 53 Γ 53 < 151200 < 54 Γ 54 Γ 54 . If only the fuel container #2 were available, at most 147440 fuel balls could be put into the fuel container since 147440 = 95 Γ 96 Γ 97/6 < 151200 < 96 Γ 97 Γ 98/6 . Using both of the fuel containers #1 and #2, 151200 fuel balls can be put into the fuel containers since 151200 = 39 Γ 39 Γ 39 + 81 Γ 82 Γ 83/6 . In this case, Captain Future's answer should be "151200".
Commander Parus's offer cannot be greater than 151200 because of the capacity of the fuel storages of Goryokaku. Captain Future and her omcers know that well.
You are a fuel engineer assigned to Hakodate-maru. Your duty today is to help Captain Future with calculating the number of fuel balls she should request.
Input
The input is a sequence of at most 1024 positive integers. Each line contains a single integer. The sequence is followed by a zero, which indicates the end of data and should not be treated as input. You may assume that none of the input integers is greater than 151200.
Output
The output is composed of lines, each containing a single integer. Each output integer should be the greatest integer that is the sum of a nonnegative cubic number and a nonnegative tetrahedral number and that is not greater than the corresponding input number. No other characters should appear in the output.
Example
Input
100
64
50
20
151200
0
Output
99
64
47
20
151200
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
ans = []
while True:
N = int(input())
if not N:
break
now_cube = int(N ** (1 / 3 + 1e-06))
now_pyramid = 0
tmp_ans = now_cube ** 3
for i in range(now_cube, -1, -1):
while True:
if (now_pyramid + 1) * (now_pyramid + 2) * (now_pyramid + 3) // 6 + i ** 3 > N:
tmp_ans = max(tmp_ans, now_pyramid * (now_pyramid + 1) * (now_pyramid + 2) // 6 + i ** 3)
break
now_pyramid += 1
ans.append(tmp_ans)
[print(i) for i in ans]
``` | vfc_135503 | {
"difficulty": "unknown_difficulty",
"memory_limit": "134.217728 megabytes",
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "8.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "100\n84\n50\n20\n151200\n0",
"output": "99\n84\n47\n20\n151200\n",
"type": "stdin_stdout"
}
]
} |
|
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/word-ladder-ii/1 | Solve the following coding problem using the programming language python:
Given two distinct words startWord and targetWord, and a list denoting wordList of unique words of equal lengths. Find all shortest transformation sequence(s) from startWord to targetWord. You can return them in any order possible.
Keep the following conditions in mind:
A word can only consist of lowercase characters.
Only one letter can be changed in each transformation.
Each transformed word must exist in the wordList including the targetWord.
startWord may or may not be part of the wordList.
Return an empty list if there is no such transformation sequence.
The first part of this problem can be found here.
Example 1:
Input:
startWord = "der", targetWord = "dfs",
wordList = {"des","der","dfr","dgt","dfs"}
Output:
der dfr dfs
der des dfs
Explanation:
The length of the smallest transformation is 3.
And the following are the only two ways to get
to targetWord:-
"der" -> "des" -> "dfs".
"der" -> "dfr" -> "dfs".
Example 2:
Input:
startWord = "gedk", targetWord = "geek",
wordList = {"geek", "gefk"}
Output:
"gedk" -> "geek"
Your Task:
You don't need to read or print anything, Your task is to complete the function findSequences() which takes startWord, targetWord and wordList as input parameter and returns a list of list of strings of the shortest transformation sequence from startWord to targetWord.
Note: You don't have to return -1 in case of no possible sequence. Just return the Empty List.
Expected Time Compelxity: O(N*(logN * M * 26))
Expected Auxiliary Space: O(N * M) where N = length of wordList and M = |wordList_{i}|
Constraints:
1 β€ N β€ 100
1 β€ M β€ 10
Write your solution by modifying this code:
```python
#User function Template for python3
class Solution:
def findSequences(self, startWord, targetWord, wordList):
#Code here
```
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
from collections import deque
class Solution:
def findSequences(self, startWord, targetWord, wordList):
st = set(wordList)
queue = deque()
queue.append([startWord])
ans = []
usedonLevel = [startWord]
level = 0
while queue:
vec = queue.popleft()
if len(vec) > level:
level += 1
for ele in usedonLevel:
st.discard(ele)
word = vec[-1]
if word == targetWord:
if not ans:
ans.append(vec)
elif len(ans[0]) == len(vec):
ans.append(vec)
for i in range(0, len(word)):
original = word[i]
for ch in 'abcdefghijklmnopqrstuvwxyz':
word = word[:i] + ch + word[i + 1:]
if word in st:
vec.append(word)
queue.append(vec.copy())
usedonLevel.append(word)
vec.pop()
word = word[:i] + original + word[i + 1:]
return ans
``` | vfc_135507 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/word-ladder-ii/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "startWord = \"der\", targetWord = \"dfs\",\r\nwordList = {\"des\",\"der\",\"dfr\",\"dgt\",\"dfs\"}",
"output": "der dfr dfs\r\nder des dfs",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "startWord = \"gedk\", targetWord = \"geek\", \r\nwordList = {\"geek\", \"gefk\"}",
"output": "",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/NFS | Solve the following coding problem using the programming language python:
Read problem statements in [Russian] and [Mandarin Chinese]
Chef is playing Need For Speed. Currently, his car is running on a straight road with a velocity $U$ metres per second and approaching a $90^{\circ}$ turn which is $S$ metres away from him. To successfully cross the turn, velocity of the car when entering the turn must not exceed $V$ metres per second.
The brakes of Chef's car allow him to slow down with a deceleration (negative acceleration) not exceeding $A$ metres per squared second. Tell him whether he can cross the turn successfully. The velocity $v$ when entering the turn can be determined from Newton's 2nd law to be $v^{2} = U^{2} + 2 \cdot a \cdot S$ if the car is moving with a uniform acceleration $a$.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains four space-separated integers $U$, $V$, $A$ and $S$.
------ Output ------
For each test case, print a single line containing the string "Yes" if Chef can cross the turn successfully or "No" if he cannot (without quotes).
You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).
------ Constraints ------
$1 β€ T β€ 10^{5}$
$1 β€ U, V, A, S β€ 10^{4}$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
3
1 1 1 1
2 1 1 1
2 2 1 1
----- Sample Output 1 ------
Yes
No
Yes
----- explanation 1 ------
Example case 1: Since $U = V = 1$, Chef does not need to brake and will be able to turn successfully.
Example case 2: The smallest velocity Chef's car can have even with the maximum deceleration is $\sqrt{2 \cdot 2 - 2 \cdot 1 \cdot 1} = \sqrt{2}$, which is greater than the maximum allowed velocity for a safe turn.
Example case 3: The smallest velocity Chef's car can have with the maximum deceleration is again $\sqrt{2}$, which is smaller than the maximum allowed velocity for a safe turn.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
t = int(input())
for i in range(t):
(u, v, a, s) = map(int, input().split())
smallv = u ** 2 - 2 * a * s
if smallv > v ** 2:
print('No')
else:
print('Yes')
``` | vfc_135508 | {
"difficulty": "easy",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/NFS",
"time_limit": "0.5 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 1 1 1\n2 1 1 1\n2 2 1 1",
"output": "Yes\nNo\nYes",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/sum-of-divisors3601/1 | Solve the following coding problem using the programming language python:
Given a natural number n, calculate sum of all its proper divisors. A proper divisor of a natural number is the divisor that is strictly less than the number.
Example 1:
Input: n = 10
Output: 8
Explanation: Proper divisors 1 + 2 + 5 = 8.
Example 2:
Input: n = 6
Output: 6
Explanation: Proper divisors 1 + 2 + 3 = 6.
Your Task:
You dont need to read input or print anything. Complete the function divSum() which takes n as input parameter and returns sum of proper divisors of n.
Expected Time Complexity: O(sqrt(n))
Expected Auxiliary Space: O(1)
Constraints:
2<= n <=10^{6}
Write your solution by modifying this code:
```python
#User function Template for python3
class Solution:
def divSum (self, n):
# code here
```
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import math
class Solution:
def divSum(self, n):
s = 1
a = int(math.sqrt(n))
for i in range(2, a + 1):
if n % i == 0:
if i * i == n:
s = s + i
else:
b = n // i
s = s + i + b
return s
``` | vfc_135512 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/sum-of-divisors3601/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "n = 10",
"output": "8",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "n = 6",
"output": "6",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Puchi hates to carry luggage, but unfortunately he got a job to carry the luggage of his N friends in office. Each day, one of his N friends, gives him the luggage of a particular weight to carry. You will be given the weight of luggage of each friend in the array Weight, where Weighti is the weight of luggage of i^th friend carried by Puchi on i^th day. It is given that all the luggages carried by Puchi are distinct in their weights.
As Prateek assigned this job to Puchi, so for each day, he wants to know the number of days in future when Puchi will have to carry the luggage , having weight less than the weight of luggage of current day.
Please help Prateek for the same.
Input:
The first line contains a single integer T, denoting the number of test cases. In each test case, the following input will be present:
First line contains an integer N, where N represents the number of friends.
Next N line contains N integers, where i^th line contains i^th integer, which represents Weighti.
Output:
Output exactly T lines. Each line contains N integer separated by a space, where i^th integer represents the number of luggage of future, which are less than the weight of luggage of the current day.
Constraints:
Subtask 1:
1 β€ T β€ 30
1 β€ N β€ 10^4
1 β€ Weighti β€ 10^6
Subtask 2:
1 β€ T β€ 10
1 β€ N β€ 10^5
1 β€ Weighti β€ 10^6
SAMPLE INPUT
1
4
2
1
4
3
SAMPLE OUTPUT
1 0 1 0
Explanation
In sample input, given T =1 in first line and N = 4 in next line. In next 4 lines, Weighti i.e weight of luggage of each friend on i^th day is given.
For weight on first day i.e 2 ,future weights smaller than 2 are {1} . Therefore output for this weight will be 1.
For weight on second day i.e 1, no future weights are smaller than 1. So output for this weight will be 0.
For weight on third day i.e 4, future weights smaller than 4 are {3}. So output for this weight will be 1.
For weight on fourth day i.e 3, no future weights are smaller than 3. So output for this weight will be 0.
So the final output is {1, 0, 1, 0}.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def merge_sort_count(xss):
if len(xss) == 1:
return xss
mid = len(xss) / 2
xs = merge_sort_count(xss[:mid])
ys = merge_sort_count(xss[mid:])
res = []
i, j, count = 0, 0, 0
while True:
if i >= len(xs):
res.extend(ys[j:])
break
if j >= len(ys) or xs[i] < ys[j]:
res.append((xs[i][0], xs[i][1] + count))
i += 1
else:
count += 1
res.append(ys[j])
j += 1
return res
def solve(xs):
lookup = dict(merge_sort_count(list(zip(xs, [0] * len(xs)))))
res = []
for x in xs:
res.append(str(lookup[x]))
return ' '.join(res)
if __name__ == '__main__':
for _ in range(int(input())):
n = int(input())
xs = [int(input()) for _ in range(n)]
print(solve(xs))
``` | vfc_135513 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7\n1\n20\n6\n1\n2\n3\n4\n5\n6\n4\n87\n78\n16\n94\n16\n87\n93\n50\n22\n63\n28\n91\n60\n64\n27\n41\n73\n37\n12\n69\n68\n10\n83\n31\n63\n24\n68\n36\n30\n3\n23\n59\n10\n68\n94\n57\n12\n43\n30\n74\n22\n20\n85\n10\n100\n99\n98\n97\n96\n95\n94\n93\n92\n91\n",
"output": "1 0 1 0\n",
"type": "stdin_stdout"
}
]
} |
|
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/count-subsets-having-distinct-even-numbers5726/1 | Solve the following coding problem using the programming language python:
Given a set of n numbers. The task is to count all the subsets of the given set which only have even numbers and all are distinct.
Note: By the property of sets, if two subsets have the same set of elements then they are considered as one. For example: [2, 4, 8] and [4, 2, 8] are considered to be the same.
Example 1:
Input :
n = 8
a[] = {4, 2, 1, 9, 2, 6, 5, 3}
Output :
7
Explanation:
The subsets are:
[4], [2], [6], [4, 2],
[2, 6], [4, 6], [4, 2, 6]
Example 2:
Input :
n = 13
a[] = {10, 3, 4, 2, 4, 20, 10, 6, 8, 14, 2, 6, 9}
Output :
127
Your Task:
You don't need to read input or print anything. Your task is to complete the function countSubsets() which takes the array a[] and its size n as inputs and returns the Count of possible subsets.
Expected Time Complexity: O(n)
Expected Auxiliary Space: O(n)
Constraints:
1<=n<=10^{5}
1<=a[i]<=10^{3}
It is Guaranteed that answers will fit in 64-bits.
Write your solution by modifying this code:
```python
#User function Template for python3
def countSubsets( a, n):
# code here
```
Your solution should implemented in the function "countSubsets". The inputs will be passed to it and it should return the correct solution.
Now solve the problem and return the code. | ```python
def countSubsets(a, n):
s = set()
for x in a:
if x % 2 == 0:
s.add(x)
count = len(s)
ans = pow(2, count) - 1
return ans
``` | vfc_135517 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/count-subsets-having-distinct-even-numbers5726/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": "countSubsets",
"input": "n = 8\r\na[] = {4, 2, 1, 9, 2, 6, 5, 3}",
"output": "7",
"type": "function_call"
},
{
"fn_name": "countSubsets",
"input": "n = 13\r\na[] = {10, 3, 4, 2, 4, 20, 10, 6, 8, 14, 2, 6, 9}",
"output": "127",
"type": "function_call"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/VOTERS | Solve the following coding problem using the programming language python:
As you might remember, the collector of Siruseri had ordered
a complete revision of the Voters List. He knew that constructing
the list of voters is a difficult task, prone to errors. Some
voters may have been away on vacation, others may have moved
during the enrollment and so on.
To be as accurate as possible, he entrusted the task to three different
officials. Each of them was to independently record the list of voters and
send it to the collector. In Siruseri, every one has a ID number and
the list would only list the ID numbers of the voters and not their names.
The officials were expected to arrange the ID numbers in ascending order
in their lists.
On receiving the lists, the Collector realised that there were
discrepancies - the three lists were not identical. He decided
to go with the majority. That is, he decided to construct the
final list including only those ID numbers that appeared in at
least 2 out of the 3 lists. For example if the three lists
were
23 30 42 57 90
21 23 35 57 90 92
21 23 30 57 90
then the final list compiled by the collector would be:
21 23 30 57 90
The ID numbers 35, 42 and 92 which appeared in only one list
each do not figure in the final list.
Your task is to help the collector by writing a program that
produces the final list from the three given lists.
Input format
The first line of the input contains 3 integers
N_{1}, N_{2} and
N_{3}. N_{1} is the number of
voters in the first list, N_{2} is the number of
voters in the second list and N_{3} is the number of
voters in the third list. The next N_{1} lines
(lines 2,...,N_{1}+1) contain one positive integer
each and describe the first list in ascending order. The following
N_{2} lines (lines
N_{1}+2,...,N_{1}+N_{2}+1)
describe the second list in ascending order and the final
N_{3} lines (lines
N_{1}+N_{2}+2,...,N_{1}+N_{2}+N_{3}+1)
describe the third list in ascending order.
Output format
The first line of the output should contain a single integer
M indicating the number voters in the final list. The next
M lines (lines 2,...,M+1) should contain one
positive integer each, describing the list of voters in the final
list, in ascending order.
Test data
You may assume that 1 β€
N_{1},N_{2},N_{3}
β€ 50000.
----- Sample Input 1 ------
5 6 5
23
30
42
57
90
21
23
35
57
90
92
21
23
30
57
90
----- Sample Output 1 ------
5
21
23
30
57
90
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
(n1, n2, n3) = map(int, input().split())
myDict = {}
outputSet = set()
count = 0
for i in range(n1 + n2 + n3):
num = int(input())
if num in myDict:
myDict[num] += 1
if myDict[num] > 1:
outputSet.add(num)
count += 1
else:
myDict[num] = 1
print(len(outputSet))
for i in sorted(outputSet):
print(i)
``` | vfc_135520 | {
"difficulty": "easy",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/VOTERS",
"time_limit": "1.15243 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 6 5\n23\n30\n42\n57\n90\n21 \n23 \n35 \n57 \n90 \n92 \n21 \n23 \n30 \n57 \n90 ",
"output": "5\n21 \n23 \n30 \n57 \n90",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
When the day begins, it's time to sing carols. Unfortunately, not all the family members know the lyrics to the same carols. Everybody knows at least one, though.
You are given a array of lyrics. The j-th character of the i-th element of lyrics is Y if the i-th person knows the j-th carol, and N if he doesn't. Print the minimal number of carols that must be sung to allow everyone to sing at least once.
Input:-
1st line contains number of testcases and next 2 lines of each testcases contains N and N no. of lyrics.
Ouput:-
Print the minimal number of carols that must be sung to allow everyone to sing at least once.
SAMPLE INPUT
3
2
YN NY
3
YN YY YN
6
YNN YNY YNY NYY NYY NYN
SAMPLE OUTPUT
2
1
2
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def get_rem(p,ar):
n=[]
for i in ar:
if i[p]=='N':
n.append(i)
return n
t=eval(input())
for i in range(t):
n=eval(input())
st=input().split()
ar=[]
for k in range(len(st[0])):
p=k
i=0
c=1
rem=st
while(i<n):
rem=get_rem(p%len(st[0]),rem)
i=n-len(rem)
if len(rem)>0:
p+=1
c+=1
ar.append(c)
print(min(ar))
``` | vfc_135524 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n6\nNYN YYN YYN YNY YNY NNY\n3\nYNNY NYNY NNYY\n5\nYYN YYN YNY NYN NNY",
"output": "2\n1\n2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n7\nYYN NYY YNY YNY YNY NNY YNN\n1\nYYYYYYYYYY\n1\nYNNNNNNNNN",
"output": "2\n2\n1\n1\n1\n2\n1\n2\n3\n2\n2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "11\n2\nYN NY\n3\nYN NY YN\n3\nYN YY YN\n1\nYN\n1\nY\n6\nYNN YNY YNY NYY NYY NYN\n3 \nNYYYY YNNYN NNNYY\n9\nNYNNNYNYY YNNYNNYNY YNYYNYNNN YYNNYYYNY NNYYYNYYY YNNYNNNYY YYNNYNYNN NYYYNNYYY NYYNYNYNY\n7\nYNYYYYY NNNNNNY YYNYNNY YNYYYNN YNNNNYN NNYYYYN YYYNYNY\n7\nYNYNYYYYY YYNYNYNYY YYNNYYYNY NNYNNNNYN NYNYYYYNN YYYNYNNYN YNYNYNNNY \n9\nYYYYYYNYY YYYNYNYYY NYNYNYNYN NYNYNNYYY NYYYNNNYY YYNNNYYYY NYYNYNYYY NNNYNYYYY YYNNYNYNN \n18\nNYNYY NYNYY YNYYY NYNNY YYYYY NNYYY YYNYN YNNYN NYYNN NYYNY YYNYN NNYYN YYNYY NYYYN YYNYY NYNNN YYYNN YNYYY",
"output": "2\n1\n1",
"type": "stdin_stdout"
}
]
} |
|
taco | verifiable_code | Solve the following coding problem using the programming language python:
Heading ##There are two integers A and B. You are required to compute the bitwise AND amongst all natural numbers lying between A and B, both inclusive.
Input Format
First line of the input contains T, the number of testcases to follow.
Each testcase in a newline contains A and B separated by a single space.
Constraints
1β€Tβ€200
0β€Aβ€B<232
Output Format
Output one line per test case with the required bitwise AND.
SAMPLE INPUT
3
12 15
2 3
8 13
SAMPLE OUTPUT
12
2
8
Explanation
1st Test Case : 12 & 13 & 14 & 15 = 12
2nd Test Case : 2 & 3 = 2
3rd Test Case : 8 & 9 & 10 & 11 & 12 & 13 = 8
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import sys
t = int(eval(input()))
while(t>0):
k,n = list(map(int,sys.stdin.readline().split()))
while(n>k):
n=n&(n-1)
print((k&n))
t-=1
``` | vfc_135528 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 \n12 15 \n2 3 \n8 13",
"output": "1476395008\n1275068416\n4009754624\n2516582400\n50331648\n2566914048\n2952790016\n3892314112\n3489660928\n33554432\n1694498816\n3623878656\n1308622848\n1426063360\n2550136832\n1627389952\n3690987520\n2030043136\n1006632960\n1912602624\n805306368\n117440512\n2063597568\n3774873600\n3003121664\n2919235584\n2197815296\n2969567232\n1275068416\n3707764736\n2986344448\n4076863488\n3254779904\n2801795072\n2147483648\n2147483648\n3590324224\n318767104\n1778384896\n704643072\n3640655872\n1392508928\n2852126720\n4143972352\n83886080\n3607101440\n2231369728\n1728053248\n1912602624\n1006632960\n2382364672\n2600468480\n1526726656\n3405774848\n1778384896\n1291845632\n385875968\n721420288\n1157627904\n3942645760\n1795162112\n33554432\n1174405120\n4110417920\n973078528\n2483027968\n2415919104\n2650800128\n1459617792\n3238002688\n2130706432\n3640655872\n335544320\n3539992576\n3825205248\n3573547008\n3019898880\n1962934272\n2130706432\n905969664\n2785017856\n3657433088\n234881024\n3875536896\n1946157056\n553648128\n1610612736\n2214592512\n2046820352\n234881024\n3388997632\n1258291200\n3456106496\n4143972352\n973078528\n2499805184\n4127195136\n3657433088\n3858759680\n4026531840\n2936012800\n1778384896\n1560281088\n1728053248\n2281701376\n2785017856\n3607101440\n1577058304\n1694498816\n771751936\n1459617792\n1644167168\n2516582400\n587202560\n1291845632\n671088640\n503316480\n2164260864\n2768240640\n1677721600\n2768240640\n1426063360\n2181038080\n822083584",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "59\n9355264 9371647\n7077888 7094271\n13795328 13811711\n5898240 5914623\n10436608 10452991\n6356992 6373375\n6995968 7012351\n12337152 12353535\n884736 901119\n9043968 9060351\n8552448 8568831\n2605056 2621439\n16728064 16744447\n9306112 9322495\n3522560 3538943\n6176768 6193151\n6406144 6422527\n8568832 8585215\n16007168 16023551\n3145728 3162111\n8781824 8798207\n11452416 11468799\n10436608 10452991\n7831552 7847935\n6340608 6356991\n7405568 7421951\n2441216 2457599\n13369344 13385727\n14155776 14172159\n14991360 15007743\n5226496 5242879\n10747904 10764287\n10846208 10862591\n5603328 5619711\n16482304 16498687\n8667136 8683519\n3080192 3096575\n5783552 5799935\n229376 245759\n2048000 2064383\n5554176 5570559\n4915200 4931583\n8798208 8814591\n4571136 4587519\n3850240 3866623\n6537216 6553599\n2621440 2637823\n8175616 8191999\n5439488 5455871\n12386304 12402687\n16449536 16465919\n14860288 14876671\n15745024 15761407\n13107200 13123583\n3227648 3244031\n9158656 9175039\n14073856 14090239\n3194880 3211263\n16039936 16056319",
"output": "12 \n2 \n8",
"type": "stdin_stdout"
}
]
} |
|
taco | verifiable_code | https://www.codechef.com/problems/SUB_XOR | Solve the following coding problem using the programming language python:
Mary loves binary strings.
Given a binary string S, she defines the *beauty* of the string as the [bitwise XOR] of decimal representations of all substrings of S.
Find the *beauty* of string S. Since the answer can be huge, print it modulo 998244353.
For example, the decimal representation of binary string 1101 is 1\cdot 2^{3} + 1\cdot 2^{2} + 0\cdot 2^{1} + 1\cdot 2^{0} = 8 + 4 + 0+1 = 13. Kindly refer sample explanation for more such examples.
A string A is a substring of a string B if A can be obtained from B by deleting several (possibly zero) characters from the beginning and several (possibly zero) characters from the end.
------ Input Format ------
- The first line of input contains a single integer T, denoting the number of test cases. The description of test cases follow.
- First line of each test case contains one integer N - the length of the binary string.
- Second line of each test case contains the binary string S.
------ Output Format ------
For each test case, output in a single line, beauty of the string modulo 998244353.
------ Constraints ------
$1 β€ T β€ 100$
$1 β€ N β€ 10^{5}$
- Sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$
----- Sample Input 1 ------
3
2
10
3
101
4
1111
----- Sample Output 1 ------
3
6
12
----- explanation 1 ------
Test Case $1$: All substrings of the string $S = 10$ are $[1, 0, 10]$. The decimal representation of these substrings is denoted by the array $[1, 0, 2]$. Bitwise XOR of all these values is $1 \oplus 0 \oplus 2 = 3$.
Test Case $2$: All substrings of the string $S = 101$ are $[1, 0, 1, 10, 01, 101]$. The decimal representation of these substrings is denoted by the array $[1, 0, 1, 2, 1, 5]$. Bitwise XOR of all these values is: $1 \oplus 0 \oplus 1 \oplus 2 \oplus 1 \oplus 5 = 6$.
Test Case $3$: All substrings of the string $S = 1111$ are $[1, 1, 1, 1, 11, 11, 11, 111, 111, 1111]$. The decimal representation of these substrings is denoted by the array $[1, 1, 1, 1, 3, 3, 3, 7, 7, 15]$. Bitwise XOR of all these values is: $1 \oplus 1 \oplus 1 \oplus 1 \oplus 3 \oplus 3 \oplus 3 \oplus 7 \oplus 7 \oplus 15 = 12$.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
mod = 998244353
def inp():
return int(input())
def st():
return input().rstrip('\n')
def lis():
return list(map(int, input().split()))
def ma():
return map(int, input().split())
def solve(lent, binn):
runningxor = 0
beauty = 0
twopow = 1
for j in range(lent):
if not j & 1:
runningxor ^= int(binn[j])
runningxor %= mod
for i in range(lent - 1, -1, -1):
beauty += runningxor * twopow % mod
beauty %= mod
if not i & 1:
runningxor ^= int(binn[i])
twopow *= 2
twopow %= mod
return beauty
def main():
for i in range(inp()):
lent = inp()
string = st()
print(solve(lent, string))
main()
``` | vfc_135540 | {
"difficulty": "medium_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/SUB_XOR",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n2\n10\n3\n101\n4\n1111",
"output": "3\n6\n12\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/220/A | Solve the following coding problem using the programming language python:
The Little Elephant has got a problem β somebody has been touching his sorted by non-decreasing array a of length n and possibly swapped some elements of the array.
The Little Elephant doesn't want to call the police until he understands if he could have accidentally changed the array himself. He thinks that he could have accidentally changed array a, only if array a can be sorted in no more than one operation of swapping elements (not necessarily adjacent). That is, the Little Elephant could have accidentally swapped some two elements.
Help the Little Elephant, determine if he could have accidentally changed the array a, sorted by non-decreasing, himself.
Input
The first line contains a single integer n (2 β€ n β€ 105) β the size of array a. The next line contains n positive integers, separated by single spaces and not exceeding 109, β array a.
Note that the elements of the array are not necessarily distinct numbers.
Output
In a single line print "YES" (without the quotes) if the Little Elephant could have accidentally changed the array himself, and "NO" (without the quotes) otherwise.
Examples
Input
2
1 2
Output
YES
Input
3
3 2 1
Output
YES
Input
4
4 3 2 1
Output
NO
Note
In the first sample the array has already been sorted, so to sort it, we need 0 swap operations, that is not more than 1. Thus, the answer is "YES".
In the second sample we can sort the array if we swap elements 1 and 3, so we need 1 swap operation to sort the array. Thus, the answer is "YES".
In the third sample we can't sort the array in more than one swap operation, so the answer is "NO".
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def main():
n = int(input())
arr = list(map(int, input().split()))
copy = arr[:]
copy.sort()
missed = 0
for i in range(n):
if arr[i] != copy[i]:
missed += 1
if missed == 2:
print('YES')
elif missed == 0:
print('YES')
else:
print('NO')
main()
``` | vfc_135544 | {
"difficulty": "easy",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/220/A",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 4 3 2 1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n3 4 5 6 7 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 3 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "50\n6 7 8 4 10 3 2 7 1 3 10 3 4 7 2 3 7 4 10 6 8 10 9 6 5 10 9 6 1 8 9 4 3 7 3 10 5 3 10 1 6 10 6 7 10 7 1 5 9 5\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n2 3 1\n",
"output": "NO\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Gudi enters the castle, and moves along the main path. Suddenly, a block in the ground opens and she falls into it! Gudi slides down and lands in a dark room. A mysterious voice announces:
Intruders are not allowed inside the castle. To proceed, you must
solve my puzzle. Here is a string S indexed from 1 to N,
consisting of digits from 0-9. If you summon the spell "Sera", the
string will be rotated clockwise by H positions. If you summon the
spell "Xhaka", the number A will be added to all the even-indexed
digits of the string. For example, if H = 1 A = 3 "Sera" and
"Xhaka" on the string "781" will result in strings ""178" and "711"
respectively i.e. digits post 9 are cycled back to 0. The objective is
to obtain the lexicographically smallest string possible as a result
of applying any of the two spells any number of times in any order. Find the string
and I shall set you free
Input
The first line contains an integer T. T testcases follow.
First line of each test contains the string S.
The next line contains two space-separated integers A and H.
Output
Print the answer to each testcase in a new line.
Constraints
1 β€ T β€ 10
1 β€ N, H β€ 6
1 β€ A β€ 10
SAMPLE INPUT
2
31
4 1
160
9 2
SAMPLE OUTPUT
11
000
Explanation
For the first testcase, we can summon the spells as:
31 --(Sera)- -> 13 --(Xhaka)- -> 17 --(Xhaka)- -> 11, and it is the smallest possible answer.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
T=int(input())
for iCase in range(T):
S=input()
lenS=len(S)
A,H=list(map(int, input().split()))
H%=lenS
allstr=set([])
news=[S]
while news:
old=news
news=[]
for st in old:
S1=st[-H:]+st[:-H]
if S1 not in allstr:
allstr.add(S1)
news.append(S1)
S2=st[0]
for i in range(1,lenS,2):
S2+=str((int(st[i])+A)%10)
if i+1<lenS:
S2+=st[i+1]
if S2 not in allstr:
allstr.add(S2)
news.append(S2)
print(min(allstr))
``` | vfc_135548 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10\n85\n10 1\n25621\n3 4\n19688\n1 5\n34597\n4 5\n6502\n5 1\n475\n10 2\n108\n1 3\n68\n6 1\n07\n6 2\n091\n1 1",
"output": "213\n331\n40\n00001\n009171\n01644\n53\n824\n107\n30",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n255003\n1 3\n237626\n10 2\n918145\n3 6\n347788\n8 3\n776696\n7 6\n760648\n8 6\n712770\n7 1\n476620\n1 4\n000331\n6 1\n688368\n5 4",
"output": "00001\n0015\n305280\n0123\n386764\n006463\n00612\n376577\n01111\n00000",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n576762\n3 3\n864186\n8 3\n187047\n7 2\n125964\n4 1\n997924\n9 1\n226408\n1 2\n822849\n9 6\n819214\n2 3\n490972\n7 2\n063402\n8 3",
"output": "003255\n237626\n908044\n102589\n706999\n700042\n000157\n204766\n000331\n636388",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n273\n4 6\n381\n5 6\n46\n7 6\n81183\n1 6\n099070\n3 6\n44016\n10 6\n53\n10 6\n824\n10 6\n107\n2 6\n36\n1 6",
"output": "25947\n1113\n24843\n00000\n00000\n0013\n00001\n3670\n00001\n0044",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n88520\n7 2\n1308\n7 2\n365886\n1 4\n2907\n4 1\n386764\n10 1\n096362\n1 4\n61200\n10 1\n657737\n10 5\n93332\n4 1\n91549\n1 4",
"output": "58\n00000\n10698\n30557\n0076\n475\n108\n00\n01\n000",
"type": "stdin_stdout"
}
]
} |
|
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/roof-top-1587115621/1 | Solve the following coding problem using the programming language python:
You are given heights of consecutive buildings. You can move from the roof of a building to the roof of next adjacent building. You need to find the maximum number of consecutive steps you can put forward such that you gain an increase in altitude with each step.
Example 1:
Input:
N = 5
A[] = {1,2,2,3,2}
Output: 1
Explanation: 1, 2 or 2, 3 are the only consecutive
buildings with increasing heights thus maximum number
of consecutive steps with increase in gain in altitude
would be 1 in both cases.
Example 2:
Input:
N = 4
A[] = {1,2,3,4}
Output: 3
Explanation: 1 to 2 to 3 to 4 is the jump of
length 3 to have maximum number of
buildings with increasing heights, so maximum steps
with increasing altitude becomes 3.
Your Task:
The task is to complete the function maxStep() which takes an array A[] (denoting the heights of buildings) and its size N as inputs and returns the maximum number of steps to gain increase in altitude.
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(1).
Constraints:
1 <= N <= 10^{6}
1 <= A_{i }<= 10^{5}
Write your solution by modifying this code:
```python
#User function Template for python3
class Solution:
#Function to find maximum number of consecutive steps
#to gain an increase in altitude with each step.
def maxStep(self,A, N):
#Your code here
```
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
class Solution:
def maxStep(self, A, N):
i = 1
c = 0
max1 = 0
while i < N:
if A[i] - A[i - 1] > 0:
c += 1
else:
max1 = max(max1, c)
c = 0
i += 1
return max(max1, c)
``` | vfc_135552 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/roof-top-1587115621/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 5\r\nA[] = {1,2,2,3,2}",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "N = 4\r\nA[] = {1,2,3,4}",
"output": "3",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1561/D2 | Solve the following coding problem using the programming language python:
Note that the memory limit in this problem is lower than in others.
You have a vertical strip with n cells, numbered consecutively from 1 to n from top to bottom.
You also have a token that is initially placed in cell n. You will move the token up until it arrives at cell 1.
Let the token be in cell x > 1 at some moment. One shift of the token can have either of the following kinds:
* Subtraction: you choose an integer y between 1 and x-1, inclusive, and move the token from cell x to cell x - y.
* Floored division: you choose an integer z between 2 and x, inclusive, and move the token from cell x to cell β x/z β (x divided by z rounded down).
Find the number of ways to move the token from cell n to cell 1 using one or more shifts, and print it modulo m. Note that if there are several ways to move the token from one cell to another in one shift, all these ways are considered distinct (check example explanation for a better understanding).
Input
The only line contains two integers n and m (2 β€ n β€ 4 β
10^6; 10^8 < m < 10^9; m is a prime number) β the length of the strip and the modulo.
Output
Print the number of ways to move the token from cell n to cell 1, modulo m.
Examples
Input
3 998244353
Output
5
Input
5 998244353
Output
25
Input
42 998244353
Output
793019428
Input
787788 100000007
Output
94810539
Note
In the first test, there are three ways to move the token from cell 3 to cell 1 in one shift: using subtraction of y = 2, or using division by z = 2 or z = 3.
There are also two ways to move the token from cell 3 to cell 1 via cell 2: first subtract y = 1, and then either subtract y = 1 again or divide by z = 2.
Therefore, there are five ways in total.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
(n, m) = map(int, input().split())
c = [0] * n + [1] + [0] * n
for i in range(n - 1, 0, -1):
c[i] = 2 * c[i + 1] % m
for j in range(2, n // i + 1):
c[i] = (c[i] + c[i * j] - c[(i + 1) * j]) % m
print((c[1] - c[2]) % m)
``` | vfc_135553 | {
"difficulty": "hard",
"memory_limit": "128.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1561/D2",
"time_limit": "6.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 872207251\n",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "182550 383331199\n",
"output": "234598461",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "47 318786553\n",
"output": "134462650",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/121/B | Solve the following coding problem using the programming language python:
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya has a number consisting of n digits without leading zeroes. He represented it as an array of digits without leading zeroes. Let's call it d. The numeration starts with 1, starting from the most significant digit. Petya wants to perform the following operation k times: find the minimum x (1 β€ x < n) such that dx = 4 and dx + 1 = 7, if x is odd, then to assign dx = dx + 1 = 4, otherwise to assign dx = dx + 1 = 7. Note that if no x was found, then the operation counts as completed and the array doesn't change at all.
You are given the initial number as an array of digits and the number k. Help Petya find the result of completing k operations.
Input
The first line contains two integers n and k (1 β€ n β€ 105, 0 β€ k β€ 109) β the number of digits in the number and the number of completed operations. The second line contains n digits without spaces representing the array of digits d, starting with d1. It is guaranteed that the first digit of the number does not equal zero.
Output
In the single line print the result without spaces β the number after the k operations are fulfilled.
Examples
Input
7 4
4727447
Output
4427477
Input
4 2
4478
Output
4478
Note
In the first sample the number changes in the following sequence: 4727447 β 4427447 β 4427477 β 4427447 β 4427477.
In the second sample: 4478 β 4778 β 4478.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import sys
input = sys.stdin.readline
from math import *
(n, m) = map(int, input().split())
s = list(input().rstrip())
for i in range(n - 1):
if m == 0:
break
if i > 0:
if s[i - 1] == '4' and s[i] == '4' and (s[i + 1] == '7') and (i % 2 == 1):
if m % 2 == 1:
s[i] = '7'
break
if s[i] == '4' and s[i + 1] == '7':
if i % 2 == 0:
s[i] = '4'
s[i + 1] = '4'
else:
s[i] = '7'
m -= 1
print(''.join(s))
``` | vfc_135557 | {
"difficulty": "medium",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/121/B",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "74 7\n47437850490316923506619313479471062875964157742919669484484624083960118773\n",
"output": "44437850490316923506619313449771062875964157742919669484484624083960118773\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1385/B | Solve the following coding problem using the programming language python:
A permutation of length $n$ is a sequence of integers from $1$ to $n$ of length $n$ containing each number exactly once. For example, $[1]$, $[4, 3, 5, 1, 2]$, $[3, 2, 1]$ are permutations, and $[1, 1]$, $[0, 1]$, $[2, 2, 1, 4]$ are not.
There was a permutation $p[1 \dots n]$. It was merged with itself. In other words, let's take two instances of $p$ and insert elements of the second $p$ into the first maintaining relative order of elements. The result is a sequence of the length $2n$.
For example, if $p=[3, 1, 2]$ some possible results are: $[3, 1, 2, 3, 1, 2]$, $[3, 3, 1, 1, 2, 2]$, $[3, 1, 3, 1, 2, 2]$. The following sequences are not possible results of a merging: $[1, 3, 2, 1, 2, 3$], [$3, 1, 2, 3, 2, 1]$, $[3, 3, 1, 2, 2, 1]$.
For example, if $p=[2, 1]$ the possible results are: $[2, 2, 1, 1]$, $[2, 1, 2, 1]$. The following sequences are not possible results of a merging: $[1, 1, 2, 2$], [$2, 1, 1, 2]$, $[1, 2, 2, 1]$.
Your task is to restore the permutation $p$ by the given resulting sequence $a$. It is guaranteed that the answer exists and is unique.
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 400$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains one integer $n$ ($1 \le n \le 50$) β the length of permutation. The second line of the test case contains $2n$ integers $a_1, a_2, \dots, a_{2n}$ ($1 \le a_i \le n$), where $a_i$ is the $i$-th element of $a$. It is guaranteed that the array $a$ represents the result of merging of some permutation $p$ with the same permutation $p$.
-----Output-----
For each test case, print the answer: $n$ integers $p_1, p_2, \dots, p_n$ ($1 \le p_i \le n$), representing the initial permutation. It is guaranteed that the answer exists and is unique.
-----Example-----
Input
5
2
1 1 2 2
4
1 3 1 4 3 4 2 2
5
1 2 1 2 3 4 3 5 4 5
3
1 2 3 1 2 3
4
2 3 2 4 1 3 4 1
Output
1 2
1 3 4 2
1 2 3 4 5
1 2 3
2 3 4 1
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
for i in range(int(input())):
x = {}
n = int(input())
l = list(map(int, input().split()))
for i in range(2 * n):
if l[i] in x:
continue
x[l[i]] = 1
for i in x.keys():
print(i, end=' ')
``` | vfc_135561 | {
"difficulty": "easy",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1385/B",
"time_limit": "1 second"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n2\n1 1 2 2\n4\n1 3 1 4 3 4 2 2\n5\n1 2 1 2 3 4 3 5 4 5\n3\n1 2 3 1 2 3\n4\n2 3 2 4 1 3 4 1\n",
"output": "1 2 \n1 3 4 2 \n1 2 3 4 5 \n1 2 3 \n2 3 4 1 \n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.hackerrank.com/challenges/baby-step-giant-step/problem | Solve the following coding problem using the programming language python:
You are standing at point $(0,0)$ on an infinite plane. In one step, you can move from some point $(x_f,y_f)$ to any point $(x_t,y_t)$ as long as the Euclidean distance, $\sqrt{(x_f-x_t)^2+(y_f-y_t)^2}$, between the two points is either $\boldsymbol{a}$ or $\boldsymbol{b}$. In other words, each step you take must be exactly $\boldsymbol{a}$ or $\boldsymbol{b}$ in length.
You are given $\textit{q}$ queries in the form of $\boldsymbol{a}$, $\boldsymbol{b}$, and $\boldsymbol{d}$. For each query, print the minimum number of steps it takes to get from point $(0,0)$ to point $\left(d,0\right)$ on a new line.
Input Format
The first line contains an integer, $\textit{q}$, denoting the number of queries you must process.
Each of the $\textit{q}$ subsequent lines contains three space-separated integers describing the respective values of $\boldsymbol{a}$, $\boldsymbol{b}$, and $\boldsymbol{d}$ for a query.
Constraints
$1\leq q\leq10^5$
$1\leq a<b\leq10^9$
$0\leq d\leq10^9$
Output Format
For each query, print the minimum number of steps necessary to get to point $\left(d,0\right)$ on a new line.
Sample Input 0
3
2 3 1
1 2 0
3 4 11
Sample Output 0
2
0
3
Explanation 0
We perform the following $q=3$ queries:
One optimal possible path requires two steps of length $\boldsymbol{a}=2$: $(0,0)\underset{2}{\longrightarrow}(\frac{1}{2},\frac{\sqrt{15}}{2})\underset{2}{\longrightarrow}(1,0)$. Thus, we print the number of steps, $2$, on a new line.
The starting and destination points are both $(0,0)$, so we needn't take any steps. Thus, we print $\mbox{0}$ on a new line.
One optimal possible path requires two steps of length $\boldsymbol{b}=4$ and one step of length $\boldsymbol{a}=3$: $(0,0)\underset{4}{\longrightarrow}(4,0)\underset{4}{\longrightarrow}(8,0)\underset{3}{\longrightarrow}(11,0)$. Thus, we print $3$ on a new line.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
from math import ceil
def steps(a, b, d):
mmin = min(a, b)
mmax = max(a, b)
if d is 0:
return 0
if d in {mmin, mmax}:
return 1
if d < mmax:
return 2
return ceil(d / mmax)
t = int(input())
for testcase in range(t):
(a, b, d) = map(int, input().split())
print(steps(a, b, d))
``` | vfc_135565 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/baby-step-giant-step/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n2 3 1\n1 2 0\n3 4 11\n",
"output": "2\n0\n3\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Draw a chessboard which has a height of H cm and a width of W cm. For example, the following figure shows a chessboard which has a height of 6 cm and a width of 10 cm.
.#.#.#.#.
.#.#.#.#.#
.#.#.#.#.
.#.#.#.#.#
.#.#.#.#.
.#.#.#.#.#
Note that the top left corner should be drawn by '#'.
Constraints
* 1 β€ H β€ 300
* 1 β€ W β€ 300
Input
The input consists of multiple datasets. Each dataset consists of two integers H and W separated by a single space.
The input ends with two 0 (when both H and W are zero).
Output
For each dataset, print the chessboard made of '#' and '.'.
Print a blank line after each dataset.
Example
Input
3 4
5 6
3 3
2 2
1 1
0 0
Output
#.#.
.#.#
#.#.
#.#.#.
.#.#.#
#.#.#.
.#.#.#
#.#.#.
#.#
.#.
#.#
#.
.#
#
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
while True:
(a, b) = map(int, input().split())
if a == b == 0:
break
for i in range(a):
s = ''
for j in range(b):
s += '#' if (i + j) % 2 == 0 else '.'
print(s)
print('')
``` | vfc_135569 | {
"difficulty": "unknown_difficulty",
"memory_limit": "134.217728 megabytes",
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "1.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 4\n5 6\n3 3\n2 2\n1 0\n0 0",
"output": "#.#.\n.#.#\n#.#.\n\n#.#.#.\n.#.#.#\n#.#.#.\n.#.#.#\n#.#.#.\n\n#.#\n.#.\n#.#\n\n#.\n.#\n\n\n\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 7\n5 6\n3 3\n2 2\n1 0\n0 0",
"output": "#.#.#.#\n.#.#.#.\n#.#.#.#\n\n#.#.#.\n.#.#.#\n#.#.#.\n.#.#.#\n#.#.#.\n\n#.#\n.#.\n#.#\n\n#.\n.#\n\n\n\n",
"type": "stdin_stdout"
}
]
} |
|
taco | verifiable_code | https://www.codechef.com/LOCJUL16/problems/NUMHOLMS | Solve the following coding problem using the programming language python:
After completing some serious investigation, Watson and Holmes are now chilling themselves in the Shimla hills. Very soon Holmes became bored. Holmes lived entirely for his profession. We know he is a workaholic. So Holmes wants to stop his vacation and get back to work. But after a tiresome season, Watson is in no mood to return soon. So to keep Holmes engaged, he decided to give Holmes one math problem. And Holmes agreed to solve the problem and said as soon as he solves the problem, they should return back to work. Watson too agreed.
The problem was as follows. Watson knows Holmesβ favorite numbers are 6 and 5. So he decided to give Holmes N single digit numbers. Watson asked Holmes to form a new number with the given N numbers in such a way that the newly formed number should be completely divisible by 5 and 6. Watson told Holmes that he should also form the number from these digits in such a way that the formed number is maximum. He may or may not use all the given numbers. But he is not allowed to use leading zeros. Though he is allowed to leave out some of the numbers, he is not allowed to add any extra numbers, which means the maximum count of each digit in the newly formed number, is the same as the number of times that number is present in those given N digits.
-----Input-----
The first line of input contains one integers T denoting the number of test cases.
Each test case consists of one integer N, number of numbers.
Next line contains contains N single digit integers
-----Output-----
For each test case output a single number, where the above said conditions are satisfied. If it is not possible to create such a number with the given constraints print -1.If there exists a solution, the maximised number should be greater than or equal to 0.
-----Constraints-----
- 1 β€ T β€ 100
- 1 β€ N β€ 10000
- 0 β€ Each digit β€ 9
-----Subtasks-----
Subtask #1 : (90 points)
- 1 β€ T β€ 100
- 1 β€ N β€ 10000
Subtask 2 : (10 points)
- 1 β€ T β€ 10
- 1 β€ Nβ€ 10
-----Example-----
Input:
2
12
3 1 2 3 2 0 2 2 2 0 2 3
11
3 9 9 6 4 3 6 4 9 6 0
Output:
33322222200
999666330
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
t = int(input())
for i in range(0, t):
n = int(input())
lis = list(map(int, input().split()))
lis2 = []
for j in range(0, 10):
lis2.append(0)
for j in range(0, len(lis)):
lis2[lis[j]] += 1
s = sum(lis)
while s % 3 != 0:
if s % 3 == 2:
if lis2[2] >= 1:
lis2[2] -= 1
s = s - 2
elif lis2[5] >= 1:
lis2[5] -= 1
s = s - 5
elif lis2[8] >= 1:
lis2[8] -= 1
s = s - 8
elif lis2[1] >= 2:
lis2[1] -= 2
s = s - 2
elif lis2[1] >= 1 and lis2[4] >= 1:
lis2[1] -= 1
lis2[4] -= 1
s = s - 5
elif lis2[4] >= 2:
lis2[4] -= 2
s = s - 8
elif lis2[1] >= 1 and lis2[7] >= 1:
lis2[1] -= 1
lis2[7] -= 1
s = s - 8
elif lis2[4] >= 1 and lis2[7] >= 1:
lis2[4] -= 1
lis2[7] -= 1
s = s - 11
elif lis2[7] >= 2:
lis2[7] -= 2
s = s - 14
elif s % 3 == 1:
if lis2[1] >= 1:
lis2[1] -= 1
s = s - 1
elif lis2[4] >= 1:
lis2[4] -= 1
s = s - 4
elif lis2[7] >= 1:
lis2[7] -= 1
s = s - 7
elif lis2[2] >= 2:
lis2[2] -= 2
s = s - 4
elif lis2[5] >= 1 and lis2[2] >= 1:
lis2[2] -= 1
lis2[5] -= 1
s = s - 7
elif lis2[5] >= 2:
lis2[5] -= 2
s = s - 10
elif lis2[2] >= 1 and lis2[8] >= 1:
lis2[2] -= 1
lis2[8] -= 1
s = s - 10
elif lis2[8] >= 1 and lis2[5] >= 1:
lis2[8] -= 1
lis2[5] -= 1
s = s - 13
elif lis2[8] >= 2:
lis2[8] -= 2
s = s - 16
lis3 = []
for j in range(1, 10):
if lis2[j] >= 1:
for k in range(0, lis2[j]):
lis3.append(j)
lis3.reverse()
for k in range(0, lis2[0]):
lis3.append(0)
sol = ''
for k in range(0, len(lis3)):
sol += str(lis3[k])
print(sol)
``` | vfc_135573 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/LOCJUL16/problems/NUMHOLMS",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n12\n3 1 2 3 2 0 2 2 2 0 2 3\n11\n3 9 9 6 4 3 6 4 9 6 0\n",
"output": "33322222200\n999666330\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/SQUIRREL | Solve the following coding problem using the programming language python:
There are n squirrel(s) waiting below the feet of m chestnut tree(s). The first chestnut of the i-th tree will fall right after T_{i} second(s), and one more every P_{i} second(s) after that. The βbig mamaβ of squirrels wants them to bring their nest no less than k chestnuts to avoid the big storm coming, as fast as possible! So they are discussing to wait below which trees to take enough chestnuts in the shortest time. Time to move to the positions is zero, and the squirrels move nowhere after that.
------ Request ------
Calculate the shortest time (how many seconds more) the squirrels can take enough chestnuts.
------ Input ------
The first line contains an integer t, the number of test cases, for each:
The first line contains the integers m,n,k, respectively.
The second line contains the integers T_{i} (i=1..m), respectively.
The third line contains the integers P_{i} (i=1..m), respectively.
(Each integer on a same line is separated by at least one space character, there is no added line between test cases)
------ Output ------
For each test cases, output in a single line an integer which is the shortest time calculated.
------ Limitations ------
0
0
07
0i,P_{i}β€100
----- Sample Input 1 ------
2
3 2 5
5 1 2
1 2 1
3 2 5
5 1 2
1 1 1
----- Sample Output 1 ------
4
3
----- explanation 1 ------
Test case $1$: Two squirrels wait below trees $2$ and $3$.
- After $1$ second, a chestnut from tree $2$ falls. Total chestnuts the squirrels have is $1$.
- After $2$ seconds, a chestnut from tree $3$ falls. Total chestnuts the squirrels have is $2$.
- After $3$ seconds, two chestnuts fall from trees $2$ and $3$. Total chestnuts the squirrels have is $4$.
- After $4$ seconds, a chestnut from tree $3$ falls. Total chestnuts the squirrels have is $5$.
Total time to gather $5$ chestnuts is $5$ seconds.
Test case $2$: Two squirrels wait below trees $2$ and $3$.
- After $1$ second, a chestnut from tree $2$ falls. Total chestnuts the squirrels have is $1$.
- After $2$ seconds, two chestnuts fall from trees $2$ and $3$. Total chestnuts the squirrels have is $3$.
- After $3$ seconds, two chestnuts fall from trees $2$ and $3$. Total chestnuts the squirrels have is $5$.
Total time to gather $5$ chestnuts is $3$ seconds.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
for _ in range(int(input())):
(m, n, k) = map(int, input().split())
T = list(map(int, input().split()))
P = list(map(int, input().split()))
t_min = 0
t_max = 10000000
t_ans = 0
while t_min <= t_max:
t_mid = (t_min + t_max) // 2
fa = [(t_mid - T[i]) // P[i] + 1 for i in range(m) if t_mid >= T[i]]
fm = sum(sorted(fa, reverse=True)[:n])
if fm < k:
t_min = t_mid + 1
else:
t_max = t_mid - 1
if fm >= k:
t_ans = t_mid
print(t_ans)
``` | vfc_135581 | {
"difficulty": "medium_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/SQUIRREL",
"time_limit": "0.169935 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3 2 5\n5 1 2\n1 2 1\n3 2 5\n5 1 2\n1 1 1",
"output": "4\n3",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/201/D | Solve the following coding problem using the programming language python:
A widely known among some people Belarusian sport programmer Lesha decided to make some money to buy a one square meter larger flat. To do this, he wants to make and carry out a Super Rated Match (SRM) on the site Torcoder.com. But there's a problem β a severe torcoder coordinator Ivan does not accept any Lesha's problem, calling each of them an offensive word "duped" (that is, duplicated). And one day they nearely quarrelled over yet another problem Ivan wouldn't accept.
You are invited to act as a fair judge and determine whether the problem is indeed brand new, or Ivan is right and the problem bears some resemblance to those used in the previous SRMs.
You are given the descriptions of Lesha's problem and each of Torcoder.com archive problems. The description of each problem is a sequence of words. Besides, it is guaranteed that Lesha's problem has no repeated words, while the description of an archive problem may contain any number of repeated words.
The "similarity" between Lesha's problem and some archive problem can be found as follows. Among all permutations of words in Lesha's problem we choose the one that occurs in the archive problem as a subsequence. If there are multiple such permutations, we choose the one with the smallest number of inversions. Then the "similarity" of a problem can be written as <image>, where n is the number of words in Lesha's problem and x is the number of inversions in the chosen permutation. Note that the "similarity" p is always a positive integer.
The problem is called brand new if there is not a single problem in Ivan's archive which contains a permutation of words from Lesha's problem as a subsequence.
Help the boys and determine whether the proposed problem is new, or specify the problem from the archive which resembles Lesha's problem the most, otherwise.
Input
The first line contains a single integer n (1 β€ n β€ 15) β the number of words in Lesha's problem. The second line contains n space-separated words β the short description of the problem.
The third line contains a single integer m (1 β€ m β€ 10) β the number of problems in the Torcoder.com archive. Next m lines contain the descriptions of the problems as "k s1 s2 ... sk", where k (1 β€ k β€ 500000) is the number of words in the problem and si is a word of the problem description.
All words from all problem descriptions contain no more than 10 lowercase English letters. It is guaranteed that the total length of words in all problem descriptions does not exceed 500015.
Output
If Lesha's problem is brand new, print string "Brand new problem!" (without quotes).
Otherwise, on the first line print the index of the archive problem which resembles Lesha's problem most. If there are multiple such problems, print the one with the smallest index. On the second line print a string consisting of characters [:, character | repeated p times, and characters :], where p is the "similarity" between this problem and Lesha's one. The archive problems are numbered starting from one in the order in which they are given in the input.
Examples
Input
4
find the next palindrome
1
10 find the previous palindrome or print better luck next time
Output
1
[:||||||:]
Input
3
add two numbers
3
1 add
2 two two
3 numbers numbers numbers
Output
Brand new problem!
Input
4
these papers are formulas
3
6 what are these formulas and papers
5 papers are driving me crazy
4 crazy into the night
Output
1
[:||||:]
Input
3
add two decimals
5
4 please two decimals add
5 decimals want to be added
4 two add decimals add
4 add one two three
7 one plus two plus three equals six
Output
3
[:|||:]
Note
Let us remind you that the number of inversions is the number of pairs of words that follow in the permutation not in their original order. Thus, for example, if the original problem is "add two numbers", then permutation "numbers add two" contains two inversions β pairs of words "numbers" and "add", "numbers" and "two".
Sequence b1, b2, ..., bk is a subsequence of sequence a1, a2, ..., an if there exists such a set of indices 1 β€ i1 < i2 < ... < ik β€ n that aij = bj (in other words, if sequence b can be obtained from a by deleting some of its elements).
In the first test case the first problem contains the "find the palindrome next" permutation as a subsequence, in which the number of inversions equals 1 (words "palindrome" and "next").
In the second test case there is no problem that contains a permutation of words from Lesha's problem as a subsequence.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import itertools
def count_inversions(enumerate_seq):
tmp = list(enumerate_seq[:])
result = 0
for i in range(len(tmp)):
for j in range(len(tmp) - 1):
if tmp[j][0] > tmp[j + 1][0]:
result += 1
(tmp[j], tmp[j + 1]) = (tmp[j + 1], tmp[j])
return result
def sub_seq(a, b):
(i, j) = (0, 0)
while i < len(a) and j < len(b):
if a[i] == b[j]:
i += 1
j += 1
return i == len(a)
n = int(input())
A = input().split()
B = []
m = int(input())
for _ in range(m):
B += [input().split()[1:]]
brand_new = True
best_perms = 0
best_seq = []
best_ind = -1
for (i, b) in enumerate(B):
for tmp in itertools.permutations(enumerate(A)):
if sub_seq([x for (y, x) in tmp], b):
brand_new = False
inversions = count_inversions(tmp)
similarity = n * (n - 1) // 2 - inversions + 1
if best_perms < similarity:
best_perms = similarity
best_seq = [x for (y, x) in tmp]
best_ind = i
if not brand_new:
print(best_ind + 1)
print('[:' + '|' * best_perms + ':]')
else:
print('Brand new problem!')
``` | vfc_135585 | {
"difficulty": "very_hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/201/D",
"time_limit": "5.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\na b c d e\n10\n5 a d b c e\n5 e a b c d\n5 b a c e d\n5 b e d c a\n5 a e d c b\n5 b c e a d\n5 d b c a e\n5 a e c d b\n5 e d b a c\n5 e d a b c\n",
"output": "1\n[:|||||||||:]\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/435/A | Solve the following coding problem using the programming language python:
It's that time of the year when the Russians flood their countryside summer cottages (dachas) and the bus stop has a lot of people. People rarely go to the dacha on their own, it's usually a group, so the people stand in queue by groups.
The bus stop queue has n groups of people. The i-th group from the beginning has a_{i} people. Every 30 minutes an empty bus arrives at the bus stop, it can carry at most m people. Naturally, the people from the first group enter the bus first. Then go the people from the second group and so on. Note that the order of groups in the queue never changes. Moreover, if some group cannot fit all of its members into the current bus, it waits for the next bus together with other groups standing after it in the queue.
Your task is to determine how many buses is needed to transport all n groups to the dacha countryside.
-----Input-----
The first line contains two integers n and m (1 β€ n, m β€ 100). The next line contains n integers: a_1, a_2, ..., a_{n} (1 β€ a_{i} β€ m).
-----Output-----
Print a single integer β the number of buses that is needed to transport all n groups to the dacha countryside.
-----Examples-----
Input
4 3
2 3 2 1
Output
3
Input
3 4
1 2 1
Output
1
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
(n, m) = map(int, input().split())
d = list(map(int, input().split()))
counter = 1
sum = 0
for i in range(n):
sum += d[i]
if sum > m:
sum = d[i]
counter += 1
print(counter)
``` | vfc_135589 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/435/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 3\n2 3 2 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 4\n1 2 1\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/rod-cutting0840/1 | Solve the following coding problem using the programming language python:
Given a rod of length N inches and an array of prices, price[]. price[i] denotes the value of a piece of length i. Determine the maximum value obtainable by cutting up the rod and selling the pieces.
Note: Consider 1-based indexing.
Example 1:
Input:
N = 8
Price[] = {1, 5, 8, 9, 10, 17, 17, 20}
Output:
22
Explanation:
The maximum obtainable value is 22 by
cutting in two pieces of lengths 2 and
6, i.e., 5+17=22.
Example 2:
Input:
N=8
Price[] = {3, 5, 8, 9, 10, 17, 17, 20}
Output:
24
Explanation:
The maximum obtainable value is
24 by cutting the rod into 8 pieces
of length 3, i.e, 8*3=24.
Your Task:
You don't need to read input or print anything. Your task is to complete the function cutRod() which takes the array A[] and its size N as inputs and returns the maximum price obtainable.
Expected Time Complexity: O(N^{2})
Expected Auxiliary Space: O(N)
Constraints:
1 β€ N β€ 1000
1 β€ Ai β€ 10^{5}
Write your solution by modifying this code:
```python
#User function Template for python3
class Solution:
def cutRod(self, price, n):
#code here
```
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import sys
class Solution:
def cutRod(self, price, n):
N = n
cur = [0] * (N + 1)
for i in range(N + 1):
cur[i] = i * price[0]
for ind in range(1, N):
for length in range(N + 1):
notTaken = 0 + cur[length]
taken = float('-inf')
rodLength = ind + 1
if rodLength <= length:
taken = price[ind] + cur[length - rodLength]
cur[length] = max(notTaken, taken)
return cur[N]
``` | vfc_135593 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/rod-cutting0840/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 8\r\nPrice[] = {1, 5, 8, 9, 10, 17, 17, 20}",
"output": "22",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1612/C | Solve the following coding problem using the programming language python:
You are a usual chat user on the most famous streaming platform. Of course, there are some moments when you just want to chill and spam something.
More precisely, you want to spam the emote triangle of size $k$. It consists of $2k-1$ messages. The first message consists of one emote, the second one β of two emotes, ..., the $k$-th one β of $k$ emotes, the $k+1$-th one β of $k-1$ emotes, ..., and the last one β of one emote.
For example, the emote triangle for $k=3$ consists of $5$ messages:
Of course, most of the channels have auto moderation. Auto moderator of the current chat will ban you right after you spam at least $x$ emotes in succession (you can assume you are the only user in the chat). Now you are interested β how many messages will you write before getting banned? Or maybe you will not get banned at all (i.e. will write all $2k-1$ messages and complete your emote triangle successfully)? Note that if you get banned as a result of writing a message, this message is also counted.
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases. The next $t$ lines describe test cases.
The only line of the test case contains integers $k$ and $x$ ($1 \le k \le 10^9; 1 \le x \le 10^{18}$).
-----Output-----
For each test case, print the number of messages you will write before getting banned for the corresponding values $k$ and $x$.
-----Examples-----
Input
7
4 6
4 7
1 2
3 7
2 5
100 1
1000000000 923456789987654321
Output
3
4
1
4
3
1
1608737403
-----Note-----
Let's analyze the test cases of the example.
In the first test case, you write three messages containing $1$, $2$ and $3$ emotes respectively, and since $1 + 2 + 3 \ge 6$, you get banned after that.
In the second test case, you write four messages containing $1$, $2$, $3$ and $4$ emotes respectively, and since $1 + 2 + 3 + 4 \ge 7$, you get banned after that.
In the third test case, you write one message containing exactly $1$ emote. It doesn't get you banned, since $1 < 2$, but you have already finished posting your emote triangle. So you wrote one message successfully.
In the fourth test case, you write four messages containing $1$, $2$, $3$ and $2$ emotes respectively, and since $1 + 2 + 3 + 2 \ge 7$, you get banned after that.
In the fifth test case, you write three messages containing $1$, $2$ and $1$ emote respectively. It doesn't get you banned, since $1 + 2 + 1 < 5$, but you have already finished posting your emote triangle. So you wrote three messages successfully.
In the sixth test case, since $x = 1$, you get banned as soon as you send your first message.
The seventh test case is too large to analyze, so we'll skip it.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import sys
input = lambda : sys.stdin.readline().rstrip()
for _ in range(int(input())):
(K, X) = map(int, input().split())
a = K * (K + 1) // 2
if X <= a:
b = int((2 * X) ** 0.5)
ans = b
if b * (b + 1) < X * 2:
ans += 1
print(ans)
elif X >= a + a - K:
print(K + K - 1)
else:
X = a + a - K - X
b = int((2 * X) ** 0.5)
ans = K + K - 1 - b
if b * (b + 1) > 2 * X:
ans += 1
print(ans)
``` | vfc_135594 | {
"difficulty": "easy",
"memory_limit": "512 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1612/C",
"time_limit": "2 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7\n4 6\n4 7\n1 2\n3 7\n2 5\n100 1\n1000000000 923456789987654321\n",
"output": "3\n4\n1\n4\n3\n1\n1608737403\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/RETPO | Solve the following coding problem using the programming language python:
Read problems statements in Mandarin Chinese and Russian.
Recently Chef bought a bunch of robot-waiters. And now he needs to know how much to pay for the electricity that robots use for their work. All waiters serve food from the kitchen (which is in the point (0, 0)) and carry it to some table (which is in some point (x, y)) in a shortest way. But this is a beta version of robots and they can only do the next moves: turn right and make a step forward or turn left and make a step forward. Initially they look in direction of X-axis. Your task is to calculate for each query the number of moves theyβll do to reach corresponding table.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. For each test case there is a sing line containing two space-separated integers - x and y.
------ Output ------
For each test case, output a single line containing number of moves that robot will make to reach point (x, y)
------ Constraints ------
$1 β€ T β€ 10^{5}$
$-10^{9} β€ x, y β€ 10^{9}$
Β
----- Sample Input 1 ------
2
3 3
3 4
----- Sample Output 1 ------
6
7
------ Explanation 0 ------
Example case 1. Sequence of moves would be LRLRLR
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
t = int(input())
while t > 0:
(x, y) = input().split()
x = int(x)
y = int(y)
x = abs(x)
y = abs(y)
z = min(x, y)
x = x - z
y = y - z
if x == 0:
if y % 2 != 0:
res = 2 * y - 1
else:
res = 2 * y
elif x % 2 != 0:
res = 2 * x + 1
else:
res = 2 * x
print(2 * z + res)
t = t - 1
``` | vfc_135598 | {
"difficulty": "medium",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/RETPO",
"time_limit": "2 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3 3\n3 4",
"output": "6\n7",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n3 3\n3 0",
"output": "6\n7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n5 3\n3 0",
"output": "10\n7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n5 3\n6 0",
"output": "10\n12\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n5 3\n6 1",
"output": "10\n13\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1513/A | Solve the following coding problem using the programming language python:
A sequence of $n$ integers is called a permutation if it contains all integers from $1$ to $n$ exactly once.
Given two integers $n$ and $k$, construct a permutation $a$ of numbers from $1$ to $n$ which has exactly $k$ peaks. An index $i$ of an array $a$ of size $n$ is said to be a peak if $1 < i < n$ and $a_i \gt a_{i-1}$ and $a_i \gt a_{i+1}$. If such permutation is not possible, then print $-1$.
-----Input-----
The first line contains an integer $t$ ($1 \leq t \leq 100$) β the number of test cases.
Then $t$ lines follow, each containing two space-separated integers $n$ ($1 \leq n \leq 100$) and $k$ ($0 \leq k \leq n$) β the length of an array and the required number of peaks.
-----Output-----
Output $t$ lines. For each test case, if there is no permutation with given length and number of peaks, then print $-1$. Otherwise print a line containing $n$ space-separated integers which forms a permutation of numbers from $1$ to $n$ and contains exactly $k$ peaks.
If there are multiple answers, print any.
-----Examples-----
Input
5
1 0
5 2
6 6
2 1
6 1
Output
1
2 4 1 5 3
-1
-1
1 3 6 5 4 2
-----Note-----
In the second test case of the example, we have array $a = [2,4,1,5,3]$. Here, indices $i=2$ and $i=4$ are the peaks of the array. This is because $(a_{2} \gt a_{1} $, $a_{2} \gt a_{3})$ and $(a_{4} \gt a_{3}$, $a_{4} \gt a_{5})$.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
length = int(input())
a = []
for i in range(length):
x = input().split()
if int(x[1]) >= 0.5 * int(x[0]):
print(-1)
elif int(x[1]) == 0:
for j in range(int(x[0])):
print(j + 1, end=' ')
print()
else:
l = []
count = 0
for k in range(int(x[0])):
l.append(k + 1)
for k in range(int(x[0])):
if k % 2 == 1:
l.insert(k, l[-1])
del l[-1]
count += 1
if count == int(x[1]):
break
print(*l)
``` | vfc_135602 | {
"difficulty": "easy",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1513/A",
"time_limit": "1 second"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 0\n5 2\n6 6\n2 1\n6 1\n",
"output": "1 \n2 4 1 5 3 \n-1\n-1\n1 6 2 3 4 5 \n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/absolute-distinct-count5118/1 | Solve the following coding problem using the programming language python:
Given a sorted array of N integers, find the number of distinct absolute values among the elements of the array.
Example 1:
Input:
N = 6
arr[] = {-3, -2, 0, 3, 4, 5}
Output: 5
Explanation: There are 5 distinct absolute
values among the elements of this array,
i.e. 0, 2, 3, 4 and 5.
Example 2:
Input:
N = 9
arr[] = {-1, -1, -1, -1, 0, 1, 1, 1, 1}
Output: 2
Explanation: There are 2 distinct absolute values
among the elements of this array, i.e. 0 and 1.
Your Task:
You don't need to read input or print anything. Complete the function distinctCount() which takes the array of integers arr[] and its size n as input parameters and returns the number of distinct absolute values.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
Constraints:
1 β€ N β€ 10^{5}
0 β€ |Arr[i]| β€ 10^{6}
Write your solution by modifying this code:
```python
#User function Template for python3
class Solution:
def distinctCount(self, arr, n):
# code here
```
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
class Solution:
def distinctCount(self, arr, n):
a = [abs(i) for i in arr]
b = set(a)
return len(b)
``` | vfc_135606 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/absolute-distinct-count5118/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 6\r\narr[] = {-3, -2, 0, 3, 4, 5}",
"output": "5",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "N = 9\r\narr[] = {-1, -1, -1, -1, 0, 1, 1, 1, 1}",
"output": "2",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/next-smallest-palindrome4740/1 | Solve the following coding problem using the programming language python:
Given a number, in the form of an array Num[] of size N containing digits from 1 to 9(inclusive). The task is to find the next smallest palindrome strictly larger than the given number.
Example 1:
Input:
N = 11
Num[] = {9, 4, 1, 8, 7, 9, 7, 8, 3, 2, 2}
Output: 9 4 1 8 8 0 8 8 1 4 9
Explanation: Next smallest palindrome is
94188088149.
Example 2:
Input:
N = 5
Num[] = {2, 3, 5, 4, 5}
Output: 2 3 6 3 2
Explanation: Next smallest palindrome is
23632.
Your Task:
Complete the function generateNextPalindrome() which takes an array num, and an single integer n, as input parameters and returns an array of integers denoting the answer. You don't to print answer or take inputs.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
Constraints:
1 <= N <= 10^{5}
1 <= Num[i] <= 9
Write your solution by modifying this code:
```python
#User function Template for python3
class Solution:
def generateNextPalindrome(self,num, n ) :
# code here
```
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
class Solution:
def generateNextPalindrome(self, num, n):
if num.count(9) == len(num):
return [1] + [0 for i in range(n - 1)] + [1]
x = num[:]
mid = n // 2
if mid == n / 2:
num[mid:] = num[:mid][::-1]
else:
num[mid + 1:] = num[:mid][::-1]
if num <= x:
if mid == n / 2:
if num[mid] == 9:
mid1 = mid - 1
mid2 = mid
while num[mid1] == 9 and num[mid2] == 9:
num[mid1] = 0
num[mid2] = 0
mid1 -= 1
mid2 += 1
num[mid1] += 1
num[mid2] += 1
else:
num[mid] += 1
num[mid - 1] += 1
elif num[mid] == 9:
num[mid] = 0
mid1 = mid - 1
mid2 = mid + 1
while num[mid1] == 9 and num[mid2] == 9:
num[mid1] = 0
num[mid2] = 0
mid1 -= 1
mid2 += 1
num[mid1] += 1
num[mid2] += 1
else:
num[mid] += 1
return num
``` | vfc_135607 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/next-smallest-palindrome4740/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 11\nNum[] = {9, 4, 1, 8, 7, 9, 7, 8, 3, 2, 2}",
"output": "9 4 1 8 8 0 8 8 1 4 9",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "N = 5\nNum[] = {2, 3, 5, 4, 5}",
"output": "2 3 6 3 2",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/375/A | Solve the following coding problem using the programming language python:
You have number a, whose decimal representation quite luckily contains digits 1, 6, 8, 9. Rearrange the digits in its decimal representation so that the resulting number will be divisible by 7.
Number a doesn't contain any leading zeroes and contains digits 1, 6, 8, 9 (it also can contain another digits). The resulting number also mustn't contain any leading zeroes.
-----Input-----
The first line contains positive integer a in the decimal record. It is guaranteed that the record of number a contains digits: 1, 6, 8, 9. Number a doesn't contain any leading zeroes. The decimal representation of number a contains at least 4 and at most 10^6 characters.
-----Output-----
Print a number in the decimal notation without leading zeroes β the result of the permutation.
If it is impossible to rearrange the digits of the number a in the required manner, print 0.
-----Examples-----
Input
1689
Output
1869
Input
18906
Output
18690
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def main():
a = input()
l = len(a)
book = [0] * 128
a = list(a)
for i in range(l):
a[i] = chr(ord(a[i]) - ord('0'))
book[ord(a[i])] += 1
num = 0
m = 0
buf = []
for i in range(1, 10):
if i in (1, 8, 6, 9):
for j in range(1, book[i]):
buf.append(i)
m = (10 * m + i) % 7
num += 1
else:
for j in range(1, book[i] + 1):
buf.append(i)
m = (10 * m + i) % 7
num += 1
m = m * 10000 % 7
mp = [9681, 1896, 9861, 1698, 6891, 6981, 6819]
buf.append(mp[m])
num += 4
buf.append('0' * (l - num))
print(''.join(map(str, buf)))
main()
``` | vfc_135609 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/375/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1689\n",
"output": "1869\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "18906\n",
"output": "18690\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2419323689\n",
"output": "2432391689\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8589157262\n",
"output": "5857221986\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/different-ways-to-spell-a-number4014/1 | Solve the following coding problem using the programming language python:
Given a number N such that it may contain many continuous digits. Find the number of ways to spell the number.
For example, consider 8884441100, one can spell it simply as triple eight triple four double two and double zero. One can also spell as double eight, eight, four, double four, two, two, double zero.
Example 1:
Input:
N = 100
Output:
2
Explanation:
The number 100 has only 2 possibilities,
1) one zero zero
2) one double zero.
Example 2:
Input:
N = 11112
Output:
8
Explanation:
1 1 1 1 2, 11 1 1 2, 1 1 11 2, 1 11 1 2,
11 11 2, 1 111 2, 111 1 2, 1111 2
Example 3:
Input:
N = 12345
Output:
1
Explanation:
The number 12345 has only 1 possibility,
one two three four five
Your Task:
You don't need to read input or print anything. Your task is to complete the function differentWaysToSpell() which takes a String N as input and returns the number of possible ways.
Expected Time Complexity: O(|N|)
Expected Auxiliary Space: O(1)
Constraints:
1 <= |N| <= 10^{50}
Write your solution by modifying this code:
```python
#User function Template for python3
class Solution:
def differentWaysToSpell(self, N):
# code here
```
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
class Solution:
def differentWaysToSpell(self, N):
result = 1
count = 1
for i in range(1, len(N)):
if N[i - 1] == N[i]:
count += 1
else:
result *= 2 ** (count - 1)
count = 1
return result * 2 ** (count - 1)
``` | vfc_135617 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/different-ways-to-spell-a-number4014/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 100",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "N = 11112",
"output": "8",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "N = 12345",
"output": "1",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/CSEP2020/problems/TOBY | Solve the following coding problem using the programming language python:
Toby has found a game to entertain himself.The game is like this:
You are in a coordinate system initially at (0,0) and you are given a sequence of steps which lead to your destination.The steps are given in the form of directions: βUβ ,βDβ , βLβ and βRβ for up, down, left and right respectively.If you are at position (x,y) then:
- U:move to (x,y+1)
- D:move to (x,y-1)
- L:move to (x-1,y)
- R:move to (x+1,y)
The sequence is provided as a string βsβ of characters where $s_i$ $(1 \leq i \leq N)$ is one of the direction character as mentioned above.An example of a sequence of steps is: UULRUDR
The destination according to this string is (1,2).
You want to remove maximum number of characters from the string such that the resulting string leads to the same destination as before.
For example in the example above we can remove characters at positions 1,3,4,6 and the resulting path will be UUR which will lead to the same destination i.e (1,2).so we reduced the number of steps by 4,and this is our score.
You need to get maximum score.
-----Input:-----
- First line will contain $T$, number of testcases. Then the testcases follow.
- First line of each testcase contains a single integer $N$,size of string.
- Second line of testcase contains a string $s$ of size $N$.
-----Output:-----
For each testcase, output a single line containing the maximum score possible.
-----Constraints-----
- $1 \leq T \leq 1000$
- $1 \leq N \leq 10^5$
-----Sample Input:-----
3
7
ULUDLLU
4
RUUR
4
LRLR
-----Sample Output:-----
2
0
4
-----EXPLANATION:-----
-
test case 1:
The final destination after moving according to the sequence is (-3,2).
One way is to remove characters at positions 3,4 and the resulting string will be ULLLU and destination still remains (-3,2).
-
test case 2: No character can be removed in this case.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
from collections import Counter
try:
for _ in range(int(input())):
n = int(input())
s = input()
d1 = dict(Counter(s))
(u, d, r, l) = (0, 0, 0, 0)
if 'U' in d1:
u = d1['U']
else:
u = 0
if 'D' in d1:
d = d1['D']
else:
d = 0
if 'R' in d1:
r = d1['R']
else:
r = 0
if 'L' in d1:
l = d1['L']
else:
l = 0
x = 0
y = 0
if l == r:
x = 0
elif l > r:
x = -(l - r)
elif r > l:
x = r - l
if u == d:
y = 0
elif d > u:
y = -(d - u)
elif u > d:
y = u - d
if x == 0 and y == 0:
print(n)
continue
print(n - (abs(x) + abs(y)))
except:
pass
``` | vfc_135619 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/CSEP2020/problems/TOBY",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n7\nULUDLLU\n4\nRUUR\n4\nLRLR\n",
"output": "2\n0\n4\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/TRAVELLING | Solve the following coding problem using the programming language python:
You are given a graph with N vertices (numbered 1 to N) and M bidirectional edges, which doesn't contain multiple edges or self-loops β that is, the given graph is a simple undirected graph.
For each pair of vertices a, b such that 1 β€ a, b β€ N, it is possible to add a new edge between vertices a and b to the graph, with a cost of (a - b)^2.
Find the minimum cost of adding edges so that vertex N is reachable from vertex 1.
------ Input Format ------
- The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follows.
- The first line of each test case contains 2 space-separated integers, N and M.
- The i^{th} of the next M lines contains 2 space-separated integers u_{i} and v_{i}, denoting a bidirectional edge between vertex u_{i} and vertex v_{i} in the graph.
------ Output Format ------
For each test case, output the answer in a single line.
------ Constraints ------
$1 β€ T β€ 1000$
$2 β€ N β€ 2 \cdot 10^{5}$
$0 β€ M β€ 2 \cdot 10^{5}$
$1 β€ u_{i}, v_{i} β€ N$
- The graph doesn't contain self-loops or multiple edges
- Sum of $N$ over all testcases is no more than $2 \cdot 10^{5}$.
- Sum of $M$ over all testcases is no more than $2 \cdot 10^{5}$.
----- Sample Input 1 ------
3
2 0
5 4
3 2
1 4
5 3
4 2
6 3
1 2
3 2
1 3
----- Sample Output 1 ------
1
0
3
----- explanation 1 ------
Test Case $1$: Add an edge between vertices $1$ and $2$, with cost $(1-2)^2 = 1$.
Test Case $2$: Vertices $1$ and $5$ are already connected, so no edges need to be added.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import heapq
def find_min_cost(City, Road, adj):
cost = [float('inf') for i in range(City + 1)]
cost[1] = 0
flag = [False for i in range(City + 1)]
start = [[0, 1]]
while len(start):
(_, p) = heapq.heappop(start)
if flag[p]:
continue
flag[p] = True
for e in adj[p]:
if cost[e[0]] > cost[p] + e[1]:
cost[e[0]] = cost[p] + e[1]
heapq.heappush(start, [cost[e[0]], e[0]])
return cost[City]
t = int(input())
for _ in range(t):
line = input().split()
(c, r) = (int(line[0]), int(line[1]))
adj = [[] for i in range(c + 1)]
for _ in range(r):
edge = input().split()
(p, q) = (int(edge[0]), int(edge[1]))
adj[p].append([q, 0])
adj[q].append([p, 0])
for i in range(1, c):
adj[i].append([i + 1, 1])
adj[i + 1].append([i, 1])
print(find_min_cost(c, r, adj))
``` | vfc_135623 | {
"difficulty": "hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/TRAVELLING",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n2 0\n5 4\n3 2\n1 4\n5 3\n4 2\n6 3\n1 2\n3 2\n1 3\n",
"output": "1\n0\n3\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/610/B | Solve the following coding problem using the programming language python:
Vika has n jars with paints of distinct colors. All the jars are numbered from 1 to n and the i-th jar contains a_{i} liters of paint of color i.
Vika also has an infinitely long rectangular piece of paper of width 1, consisting of squares of size 1 Γ 1. Squares are numbered 1, 2, 3 and so on. Vika decided that she will start painting squares one by one from left to right, starting from the square number 1 and some arbitrary color. If the square was painted in color x, then the next square will be painted in color x + 1. In case of x = n, next square is painted in color 1. If there is no more paint of the color Vika wants to use now, then she stops.
Square is always painted in only one color, and it takes exactly 1 liter of paint. Your task is to calculate the maximum number of squares that might be painted, if Vika chooses right color to paint the first square.
-----Input-----
The first line of the input contains a single integer n (1 β€ n β€ 200 000)Β β the number of jars with colors Vika has.
The second line of the input contains a sequence of integers a_1, a_2, ..., a_{n} (1 β€ a_{i} β€ 10^9), where a_{i} is equal to the number of liters of paint in the i-th jar, i.e. the number of liters of color i that Vika has.
-----Output-----
The only line of the output should contain a single integerΒ β the maximum number of squares that Vika can paint if she follows the rules described above.
-----Examples-----
Input
5
2 4 2 3 3
Output
12
Input
3
5 5 5
Output
15
Input
6
10 10 10 1 10 10
Output
11
-----Note-----
In the first sample the best strategy is to start painting using color 4. Then the squares will be painted in the following colors (from left to right): 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5.
In the second sample Vika can start to paint using any color.
In the third sample Vika should start painting using color number 5.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n = int(input())
a = list(map(int, input().split()))
x = min(a)
count = x * n
m = []
for i in range(n):
if a[i] == x:
m.append(i)
y = len(m)
z = m[0]
for i in range(y - 1):
m[i] = m[i + 1] - m[i] - 1
m[-1] = n - (m[-1] - z) - 1
count += max(m)
print(count)
``` | vfc_135627 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/610/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n2 4 2 3 3\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n5 5 5\n",
"output": "15\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n10 10 10 1 10 10\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n167959139\n",
"output": "167959139\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n896619242 805194919 844752453 848347723 816995848 856813612 805194919 833406689 816255448 805194919\n",
"output": "8051949194\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n2 3\n",
"output": "5\n",
"type": "stdin_stdout"
}
]
} |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.