contestId
int64 0
1.01k
| index
stringclasses 57
values | name
stringlengths 2
58
| type
stringclasses 2
values | rating
int64 0
3.5k
| tags
sequencelengths 0
11
| title
stringclasses 522
values | time-limit
stringclasses 8
values | memory-limit
stringclasses 8
values | problem-description
stringlengths 0
7.15k
| input-specification
stringlengths 0
2.05k
| output-specification
stringlengths 0
1.5k
| demo-input
sequencelengths 0
7
| demo-output
sequencelengths 0
7
| note
stringlengths 0
5.24k
| points
float64 0
425k
| test_cases
listlengths 0
402
| creationTimeSeconds
int64 1.37B
1.7B
| relativeTimeSeconds
int64 8
2.15B
| programmingLanguage
stringclasses 3
values | verdict
stringclasses 14
values | testset
stringclasses 12
values | passedTestCount
int64 0
1k
| timeConsumedMillis
int64 0
15k
| memoryConsumedBytes
int64 0
805M
| code
stringlengths 3
65.5k
| prompt
stringlengths 262
8.2k
| response
stringlengths 17
65.5k
| score
float64 -1
3.99
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
34 | B | Sale | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | B. Sale | 2 | 256 | Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn. | The first line contains two space-separated integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains *n* space-separated integers *a**i* (<=-<=1000<=≤<=*a**i*<=≤<=1000) — prices of the TV sets. | Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most *m* TV sets. | [
"5 3\n-6 0 35 -2 4\n",
"4 2\n7 0 0 -7\n"
] | [
"8\n",
"7\n"
] | none | 1,000 | [
{
"input": "5 3\n-6 0 35 -2 4",
"output": "8"
},
{
"input": "4 2\n7 0 0 -7",
"output": "7"
},
{
"input": "6 6\n756 -611 251 -66 572 -818",
"output": "1495"
},
{
"input": "5 5\n976 437 937 788 518",
"output": "0"
},
{
"input": "5 3\n-2 -2 -2 -2 -2",
"output": "6"
},
{
"input": "5 1\n998 997 985 937 998",
"output": "0"
},
{
"input": "2 2\n-742 -187",
"output": "929"
},
{
"input": "3 3\n522 597 384",
"output": "0"
},
{
"input": "4 2\n-215 -620 192 647",
"output": "835"
},
{
"input": "10 6\n557 605 685 231 910 633 130 838 -564 -85",
"output": "649"
},
{
"input": "20 14\n932 442 960 943 624 624 955 998 631 910 850 517 715 123 1000 155 -10 961 966 59",
"output": "10"
},
{
"input": "30 5\n991 997 996 967 977 999 991 986 1000 965 984 997 998 1000 958 983 974 1000 991 999 1000 978 961 992 990 998 998 978 998 1000",
"output": "0"
},
{
"input": "50 20\n-815 -947 -946 -993 -992 -846 -884 -954 -963 -733 -940 -746 -766 -930 -821 -937 -937 -999 -914 -938 -936 -975 -939 -981 -977 -952 -925 -901 -952 -978 -994 -957 -946 -896 -905 -836 -994 -951 -887 -939 -859 -953 -985 -988 -946 -829 -956 -842 -799 -886",
"output": "19441"
},
{
"input": "88 64\n999 999 1000 1000 999 996 995 1000 1000 999 1000 997 998 1000 999 1000 997 1000 993 998 994 999 998 996 1000 997 1000 1000 1000 997 1000 998 997 1000 1000 998 1000 998 999 1000 996 999 999 999 996 995 999 1000 998 999 1000 999 999 1000 1000 1000 996 1000 1000 1000 997 1000 1000 997 999 1000 1000 1000 1000 1000 999 999 1000 1000 996 999 1000 1000 995 999 1000 996 1000 998 999 999 1000 999",
"output": "0"
},
{
"input": "99 17\n-993 -994 -959 -989 -991 -995 -976 -997 -990 -1000 -996 -994 -999 -995 -1000 -983 -979 -1000 -989 -968 -994 -992 -962 -993 -999 -983 -991 -979 -995 -993 -973 -999 -995 -995 -999 -993 -995 -992 -947 -1000 -999 -998 -982 -988 -979 -993 -963 -988 -980 -990 -979 -976 -995 -999 -981 -988 -998 -999 -970 -1000 -983 -994 -943 -975 -998 -977 -973 -997 -959 -999 -983 -985 -950 -977 -977 -991 -998 -973 -987 -985 -985 -986 -984 -994 -978 -998 -989 -989 -988 -970 -985 -974 -997 -981 -962 -972 -995 -988 -993",
"output": "16984"
},
{
"input": "100 37\n205 19 -501 404 912 -435 -322 -469 -655 880 -804 -470 793 312 -108 586 -642 -928 906 605 -353 -800 745 -440 -207 752 -50 -28 498 -800 -62 -195 602 -833 489 352 536 404 -775 23 145 -512 524 759 651 -461 -427 -557 684 -366 62 592 -563 -811 64 418 -881 -308 591 -318 -145 -261 -321 -216 -18 595 -202 960 -4 219 226 -238 -882 -963 425 970 -434 -160 243 -672 -4 873 8 -633 904 -298 -151 -377 -61 -72 -677 -66 197 -716 3 -870 -30 152 -469 981",
"output": "21743"
},
{
"input": "100 99\n-931 -806 -830 -828 -916 -962 -660 -867 -952 -966 -820 -906 -724 -982 -680 -717 -488 -741 -897 -613 -986 -797 -964 -939 -808 -932 -810 -860 -641 -916 -858 -628 -821 -929 -917 -976 -664 -985 -778 -665 -624 -928 -940 -958 -884 -757 -878 -896 -634 -526 -514 -873 -990 -919 -988 -878 -650 -973 -774 -783 -733 -648 -756 -895 -833 -974 -832 -725 -841 -748 -806 -613 -924 -867 -881 -943 -864 -991 -809 -926 -777 -817 -998 -682 -910 -996 -241 -722 -964 -904 -821 -920 -835 -699 -805 -632 -779 -317 -915 -654",
"output": "81283"
},
{
"input": "100 14\n995 994 745 684 510 737 984 690 979 977 542 933 871 603 758 653 962 997 747 974 773 766 975 770 527 960 841 989 963 865 974 967 950 984 757 685 986 809 982 959 931 880 978 867 805 562 970 900 834 782 616 885 910 608 974 918 576 700 871 980 656 941 978 759 767 840 573 859 841 928 693 853 716 927 976 851 962 962 627 797 707 873 869 988 993 533 665 887 962 880 929 980 877 887 572 790 721 883 848 782",
"output": "0"
},
{
"input": "100 84\n768 946 998 752 931 912 826 1000 991 910 875 962 901 952 958 733 959 908 872 840 923 826 952 980 974 980 947 955 959 822 997 963 966 933 829 923 971 999 926 932 865 984 974 858 994 855 949 941 992 861 951 949 991 711 763 728 935 485 716 907 869 952 960 859 909 963 978 942 968 933 923 909 997 962 687 764 924 774 875 1000 961 951 987 974 848 921 966 859 995 997 974 931 886 941 974 986 906 978 998 823",
"output": "0"
},
{
"input": "100 80\n-795 -994 -833 -930 -974 -980 -950 -940 -788 -927 -583 -956 -945 -949 -809 -974 -957 -736 -967 -908 -975 -961 -986 -983 -963 -771 -952 -847 -751 -741 -982 -959 -925 -931 -839 -937 -880 -914 -858 -998 -812 -911 -862 -965 -943 -984 -738 -920 -950 -998 -909 -998 -781 -901 -677 -940 -985 -951 -675 -952 -967 -949 -882 -641 -969 -937 -975 -993 -913 -941 -807 -851 -832 -960 -939 -943 -895 -929 -528 -880 -823 -930 -888 -862 -948 -966 -962 -857 -799 -969 -833 -998 -952 -878 -946 -971 -976 -974 -723 -992",
"output": "75068"
},
{
"input": "1 1\n0",
"output": "0"
},
{
"input": "1 1\n1",
"output": "0"
},
{
"input": "1 1\n555",
"output": "0"
},
{
"input": "1 1\n-1",
"output": "1"
},
{
"input": "1 1\n-24",
"output": "24"
}
] | 1,589,139,473 | 2,147,483,647 | PyPy 3 | OK | TESTS | 25 | 310 | 20,172,800 | a, c = map(int, input().rstrip().split(" "))
z = list(map(int, input().rstrip().split(" ")))
z.sort()
total = 0
test = 1
b = 0
z = z[:c]
for i in z:
if i <= 0:
total = total + i
else:
break
print(abs(total)) | Title: Sale
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn.
Input Specification:
The first line contains two space-separated integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains *n* space-separated integers *a**i* (<=-<=1000<=≤<=*a**i*<=≤<=1000) — prices of the TV sets.
Output Specification:
Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most *m* TV sets.
Demo Input:
['5 3\n-6 0 35 -2 4\n', '4 2\n7 0 0 -7\n']
Demo Output:
['8\n', '7\n']
Note:
none | ```python
a, c = map(int, input().rstrip().split(" "))
z = list(map(int, input().rstrip().split(" ")))
z.sort()
total = 0
test = 1
b = 0
z = z[:c]
for i in z:
if i <= 0:
total = total + i
else:
break
print(abs(total))
``` | 3.884925 |
112 | A | Petya and Strings | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Petya and Strings | 2 | 256 | Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. The letters' case does not matter, that is an uppercase letter is considered equivalent to the corresponding lowercase letter. Help Petya perform the comparison. | Each of the first two lines contains a bought string. The strings' lengths range from 1 to 100 inclusive. It is guaranteed that the strings are of the same length and also consist of uppercase and lowercase Latin letters. | If the first string is less than the second one, print "-1". If the second string is less than the first one, print "1". If the strings are equal, print "0". Note that the letters' case is not taken into consideration when the strings are compared. | [
"aaaa\naaaA\n",
"abs\nAbz\n",
"abcdefg\nAbCdEfF\n"
] | [
"0\n",
"-1\n",
"1\n"
] | If you want more formal information about the lexicographical order (also known as the "dictionary order" or "alphabetical order"), you can visit the following site:
- http://en.wikipedia.org/wiki/Lexicographical_order | 500 | [
{
"input": "aaaa\naaaA",
"output": "0"
},
{
"input": "abs\nAbz",
"output": "-1"
},
{
"input": "abcdefg\nAbCdEfF",
"output": "1"
},
{
"input": "asadasdasd\nasdwasdawd",
"output": "-1"
},
{
"input": "aslkjlkasdd\nasdlkjdajwi",
"output": "1"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "0"
},
{
"input": "aAaaaAAaAaaAzZsssSsdDfeEaeqZlpP\nAaaaAaaAaaAaZzSSSSsDdFeeAeQZLpp",
"output": "0"
},
{
"input": "bwuEhEveouaTECagLZiqmUdxEmhRSOzMauJRWLQMppZOumxhAmwuGeDIkvkBLvMXwUoFmpAfDprBcFtEwOULcZWRQhcTbTbX\nHhoDWbcxwiMnCNexOsKsujLiSGcLllXOkRSbnOzThAjnnliLYFFmsYkOfpTxRNEfBsoUHfoLTiqAINRPxWRqrTJhgfkKcDOH",
"output": "-1"
},
{
"input": "kGWUuguKzcvxqKTNpxeDWXpXkrXDvGMFGoXKDfPBZvWSDUyIYBynbKOUonHvmZaKeirUhfmVRKtGhAdBfKMWXDUoqvbfpfHYcg\ncvOULleuIIiYVVxcLZmHVpNGXuEpzcWZZWyMOwIwbpkKPwCfkVbKkUuosvxYCKjqfVmHfJKbdrsAcatPYgrCABaFcoBuOmMfFt",
"output": "1"
},
{
"input": "nCeNVIzHqPceNhjHeHvJvgBsNFiXBATRrjSTXJzhLMDMxiJztphxBRlDlqwDFImWeEPkggZCXSRwelOdpNrYnTepiOqpvkr\nHJbjJFtlvNxIbkKlxQUwmZHJFVNMwPAPDRslIoXISBYHHfymyIaQHLgECPxAmqnOCizwXnIUBRmpYUBVPenoUKhCobKdOjL",
"output": "1"
},
{
"input": "ttXjenUAlfixytHEOrPkgXmkKTSGYuyVXGIHYmWWYGlBYpHkujueqBSgjLguSgiMGJWATIGEUjjAjKXdMiVbHozZUmqQtFrT\nJziDBFBDmDJCcGqFsQwDFBYdOidLxxhBCtScznnDgnsiStlWFnEXQrJxqTXKPxZyIGfLIToETKWZBPUIBmLeImrlSBWCkTNo",
"output": "1"
},
{
"input": "AjQhPqSVhwQQjcgCycjKorWBgFCRuQBwgdVuAPSMJAvTyxGVuFHjfJzkKfsmfhFbKqFrFIohSZBbpjgEHebezmVlGLTPSCTMf\nXhxWuSnMmKFrCUOwkTUmvKAfbTbHWzzOTzxJatLLCdlGnHVaBUnxDlsqpvjLHMThOPAFBggVKDyKBrZAmjnjrhHlrnSkyzBja",
"output": "-1"
},
{
"input": "HCIgYtnqcMyjVngziNflxKHtdTmcRJhzMAjFAsNdWXFJYEhiTzsQUtFNkAbdrFBRmvLirkuirqTDvIpEfyiIqkrwsjvpPWTEdI\nErqiiWKsmIjyZuzgTlTqxYZwlrpvRyaVhRTOYUqtPMVGGtWOkDCOOQRKrkkRzPftyQCkYkzKkzTPqqXmeZhvvEEiEhkdOmoMvy",
"output": "1"
},
{
"input": "mtBeJYILXcECGyEVSyzLFdQJbiVnnfkbsYYsdUJSIRmyzLfTTtFwIBmRLVnwcewIqcuydkcLpflHAFyDaToLiFMgeHvQorTVbI\nClLvyejznjbRfCDcrCzkLvqQaGzTjwmWONBdCctJAPJBcQrcYvHaSLQgPIJbmkFBhFzuQLBiRzAdNHulCjIAkBvZxxlkdzUWLR",
"output": "1"
},
{
"input": "tjucSbGESVmVridTBjTmpVBCwwdWKBPeBvmgdxgIVLwQxveETnSdxkTVJpXoperWSgdpPMKNmwDiGeHfxnuqaDissgXPlMuNZIr\nHfjOOJhomqNIKHvqSgfySjlsWJQBuWYwhLQhlZYlpZwboMpoLoluGsBmhhlYgeIouwdkPfiaAIrkYRlxtiFazOPOllPsNZHcIZd",
"output": "1"
},
{
"input": "AanbDfbZNlUodtBQlvPMyomStKNhgvSGhSbTdabxGFGGXCdpsJDimsAykKjfBDPMulkhBMsqLmVKLDoesHZsRAEEdEzqigueXInY\ncwfyjoppiJNrjrOLNZkqcGimrpTsiyFBVgMWEPXsMrxLJDDbtYzerXiFGuLBcQYitLdqhGHBpdjRnkUegmnwhGHAKXGyFtscWDSI",
"output": "-1"
},
{
"input": "HRfxniwuJCaHOcaOVgjOGHXKrwxrDQxJpppeGDXnTAowyKbCsCQPbchCKeTWOcKbySSYnoaTJDnmRcyGPbfXJyZoPcARHBu\nxkLXvwkvGIWSQaFTznLOctUXNuzzBBOlqvzmVfTSejekTAlwidRrsxkbZTsGGeEWxCXHzqWVuLGoCyrGjKkQoHqduXwYQKC",
"output": "-1"
},
{
"input": "OjYwwNuPESIazoyLFREpObIaMKhCaKAMWMfRGgucEuyNYRantwdwQkmflzfqbcFRaXBnZoIUGsFqXZHGKwlaBUXABBcQEWWPvkjW\nRxLqGcTTpBwHrHltCOllnTpRKLDofBUqqHxnOtVWPgvGaeHIevgUSOeeDOJubfqonFpVNGVbHFcAhjnyFvrrqnRgKhkYqQZmRfUl",
"output": "-1"
},
{
"input": "tatuhQPIzjptlzzJpCAPXSRTKZRlwgfoCIsFjJquRoIDyZZYRSPdFUTjjUPhLBBfeEIfLQpygKXRcyQFiQsEtRtLnZErBqW\ntkHUjllbafLUWhVCnvblKjgYIEoHhsjVmrDBmAWbvtkHxDbRFvsXAjHIrujaDbYwOZmacknhZPeCcorbRgHjjgAgoJdjvLo",
"output": "-1"
},
{
"input": "cymCPGqdXKUdADEWDdUaLEEMHiXHsdAZuDnJDMUvxvrLRBrPSDpXPAgMRoGplLtniFRTomDTAHXWAdgUveTxaqKVSvnOyhOwiRN\nuhmyEWzapiRNPFDisvHTbenXMfeZaHqOFlKjrfQjUBwdFktNpeiRoDWuBftZLcCZZAVfioOihZVNqiNCNDIsUdIhvbcaxpTRWoV",
"output": "-1"
},
{
"input": "sSvpcITJAwghVfJaLKBmyjOkhltTGjYJVLWCYMFUomiJaKQYhXTajvZVHIMHbyckYROGQZzjWyWCcnmDmrkvTKfHSSzCIhsXgEZa\nvhCXkCwAmErGVBPBAnkSYEYvseFKbWSktoqaHYXUmYkHfOkRwuEyBRoGoBrOXBKVxXycjZGStuvDarnXMbZLWrbjrisDoJBdSvWJ",
"output": "-1"
},
{
"input": "hJDANKUNBisOOINDsTixJmYgHNogtpwswwcvVMptfGwIjvqgwTYFcqTdyAqaqlnhOCMtsnWXQqtjFwQlEcBtMFAtSqnqthVb\nrNquIcjNWESjpPVWmzUJFrelpUZeGDmSvCurCqVmKHKVAAPkaHksniOlzjiKYIJtvbuQWZRufMebpTFPqyxIWWjfPaWYiNlK",
"output": "-1"
},
{
"input": "ycLoapxsfsDTHMSfAAPIUpiEhQKUIXUcXEiopMBuuZLHtfPpLmCHwNMNQUwsEXxCEmKHTBSnKhtQhGWUvppUFZUgSpbeChX\ndCZhgVXofkGousCzObxZSJwXcHIaqUDSCPKzXntcVmPxtNcXmVcjsetZYxedmgQzXTZHMvzjoaXCMKsncGciSDqQWIIRlys",
"output": "1"
},
{
"input": "nvUbnrywIePXcoukIhwTfUVcHUEgXcsMyNQhmMlTltZiCooyZiIKRIGVHMCnTKgzXXIuvoNDEZswKoACOBGSyVNqTNQqMhAG\nplxuGSsyyJjdvpddrSebOARSAYcZKEaKjqbCwvjhNykuaECoQVHTVFMKXwvrQXRaqXsHsBaGVhCxGRxNyGUbMlxOarMZNXxy",
"output": "-1"
},
{
"input": "EncmXtAblQzcVRzMQqdDqXfAhXbtJKQwZVWyHoWUckohnZqfoCmNJDzexFgFJYrwNHGgzCJTzQQFnxGlhmvQTpicTkEeVICKac\nNIUNZoMLFMyAjVgQLITELJSodIXcGSDWfhFypRoGYuogJpnqGTotWxVqpvBHjFOWcDRDtARsaHarHaOkeNWEHGTaGOFCOFEwvK",
"output": "-1"
},
{
"input": "UG\nak",
"output": "1"
},
{
"input": "JZR\nVae",
"output": "-1"
},
{
"input": "a\nZ",
"output": "-1"
},
{
"input": "rk\nkv",
"output": "1"
},
{
"input": "RvuT\nbJzE",
"output": "1"
},
{
"input": "PPS\nydq",
"output": "-1"
},
{
"input": "q\nq",
"output": "0"
},
{
"input": "peOw\nIgSJ",
"output": "1"
},
{
"input": "PyK\noKN",
"output": "1"
},
{
"input": "O\ni",
"output": "1"
},
{
"input": "NmGY\npDlP",
"output": "-1"
},
{
"input": "nG\nZf",
"output": "-1"
},
{
"input": "m\na",
"output": "1"
},
{
"input": "MWyB\nWZEV",
"output": "-1"
},
{
"input": "Gre\nfxc",
"output": "1"
},
{
"input": "Ooq\nwap",
"output": "-1"
},
{
"input": "XId\nlbB",
"output": "1"
},
{
"input": "lfFpECEqUMEOJhipvkZjDPcpDNJedOVXiSMgBvBZbtfzIKekcvpWPCazKAhJyHircRtgcBIJwwstpHaLAgxFOngAWUZRgCef\nLfFPEcequmeojHIpVkzjDPcpdNJEDOVXiSmGBVBZBtfZikEKcvPwpCAzKAHJyHIrCRTgCbIJWwSTphALagXfOnGAwUzRGcEF",
"output": "0"
},
{
"input": "DQBdtSEDtFGiNRUeJNbOIfDZnsryUlzJHGTXGFXnwsVyxNtLgmklmFvRCzYETBVdmkpJJIvIOkMDgCFHZOTODiYrkwXd\nDQbDtsEdTFginRUEJNBOIfdZnsryulZJHGtxGFxnwSvYxnTLgmKlmFVRCzyEtBVdmKpJjiVioKMDgCFhzoTODiYrKwXD",
"output": "0"
},
{
"input": "tYWRijFQSzHBpCjUzqBtNvBKyzZRnIdWEuyqnORBQTLyOQglIGfYJIRjuxnbLvkqZakNqPiGDvgpWYkfxYNXsdoKXZtRkSasfa\nTYwRiJfqsZHBPcJuZQBTnVbkyZZRnidwEuYQnorbQTLYOqGligFyjirJUxnblVKqZaknQpigDVGPwyKfxyNXSDoKxztRKSaSFA",
"output": "0"
},
{
"input": "KhScXYiErQIUtmVhNTCXSLAviefIeHIIdiGhsYnPkSBaDTvMkyanfMLBOvDWgRybLtDqvXVdVjccNunDyijhhZEAKBrdz\nkHsCXyiErqIuTMVHNTCxSLaViEFIEhIIDiGHsYNpKsBAdTvMKyANFMLBovdwGRYbLtdQVxvDVJCcNUndYiJHhzeakBrdZ",
"output": "0"
},
{
"input": "cpPQMpjRQJKQVXjWDYECXbagSmNcVfOuBWNZxihdERraVuiOpSVDCPgTGuSQALNoVjySceHcKXwOEpSzXrEqWwwrYeppNiWhDVg\nCPPqmPjRqJkQvxJwdyECXBAGsMNcVfOuBWNzxIhderRavUiOpSvDCpGTgusqAlNovjyScEhCKXwoePSZxrEQwWwryEPPniWHDvG",
"output": "0"
},
{
"input": "SajcCGMepaLjZIWLRBGFcrZRCRvvoCsIyKsQerbrwsIamxxpRmQSZSalasJLVFbCHCuXJlubciQAvLxXYBazLsMKLHLdDQ\nsaJcCgmEpaLJziWlrBgFcRzrCrVVOcSIykSQerBrwSIamxxPrMqSzSalASjLVFbChCUxjLUbCIQAVlxxybAZLsmkLhLDdQ",
"output": "0"
},
{
"input": "kigPrWNTOUNDBskAfefjhHYZNYdnfZWuXWzHiBxFQryBbAkPtenFwWvCSTYGpzOntUNzNUhxRWjKmicTwLwJAnbAxj\nkigpRWntOUNdBsKaFEFjhhYZnYDNfzWuXwZhibxFQRybbakPteNfwwvcStyGPzoNTunznuHXrWjKMIctWLWJANBAxJ",
"output": "0"
},
{
"input": "nTomZZuTTRTAAPoUsySVFGElrpQRNLjqvFmcYytiheQnjUhPLnqNBiYtQkljbcvmjuNAVKbvQOWpqqFlQhAhULIhquoCnjUI\nntOmzZuttrtAAPOUSySVFgeLRPQrNLjQvfmCyYTiHEQnjuHPlNQNbIYtqKLJBCVmjunavkbvQOWPQQFlqHaHULIHQuOcnJUi",
"output": "0"
},
{
"input": "abac\nadaa",
"output": "-1"
},
{
"input": "Bbc\nabc",
"output": "1"
},
{
"input": "aaaba\naaaab",
"output": "1"
}
] | 1,698,924,411 | 2,147,483,647 | Python 3 | OK | TESTS | 53 | 92 | 0 | s1=input()
s2=input()
s1=s1.lower()
s2=s2.lower()
if s1==s2:
print(0)
else:
for i in range(0,len(s1),1):
if s1[i]<s2[i]:
print(-1)
break
if s2[i]<s1[i]:
print(1)
break
# Bassem
| Title: Petya and Strings
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. The letters' case does not matter, that is an uppercase letter is considered equivalent to the corresponding lowercase letter. Help Petya perform the comparison.
Input Specification:
Each of the first two lines contains a bought string. The strings' lengths range from 1 to 100 inclusive. It is guaranteed that the strings are of the same length and also consist of uppercase and lowercase Latin letters.
Output Specification:
If the first string is less than the second one, print "-1". If the second string is less than the first one, print "1". If the strings are equal, print "0". Note that the letters' case is not taken into consideration when the strings are compared.
Demo Input:
['aaaa\naaaA\n', 'abs\nAbz\n', 'abcdefg\nAbCdEfF\n']
Demo Output:
['0\n', '-1\n', '1\n']
Note:
If you want more formal information about the lexicographical order (also known as the "dictionary order" or "alphabetical order"), you can visit the following site:
- http://en.wikipedia.org/wiki/Lexicographical_order | ```python
s1=input()
s2=input()
s1=s1.lower()
s2=s2.lower()
if s1==s2:
print(0)
else:
for i in range(0,len(s1),1):
if s1[i]<s2[i]:
print(-1)
break
if s2[i]<s1[i]:
print(1)
break
# Bassem
``` | 3.977 |
193 | A | Cutting Figure | PROGRAMMING | 1,700 | [
"constructive algorithms",
"graphs",
"trees"
] | null | null | You've gotten an *n*<=×<=*m* sheet of squared paper. Some of its squares are painted. Let's mark the set of all painted squares as *A*. Set *A* is connected. Your task is to find the minimum number of squares that we can delete from set *A* to make it not connected.
A set of painted squares is called connected, if for every two squares *a* and *b* from this set there is a sequence of squares from the set, beginning in *a* and ending in *b*, such that in this sequence any square, except for the last one, shares a common side with the square that follows next in the sequence. An empty set and a set consisting of exactly one square are connected by definition. | The first input line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50) — the sizes of the sheet of paper.
Each of the next *n* lines contains *m* characters — the description of the sheet of paper: the *j*-th character of the *i*-th line equals either "#", if the corresponding square is painted (belongs to set *A*), or equals "." if the corresponding square is not painted (does not belong to set *A*). It is guaranteed that the set of all painted squares *A* is connected and isn't empty. | On the first line print the minimum number of squares that need to be deleted to make set *A* not connected. If it is impossible, print -1. | [
"5 4\n####\n#..#\n#..#\n#..#\n####\n",
"5 5\n#####\n#...#\n#####\n#...#\n#####\n"
] | [
"2\n",
"2\n"
] | In the first sample you can delete any two squares that do not share a side. After that the set of painted squares is not connected anymore.
The note to the second sample is shown on the figure below. To the left there is a picture of the initial set of squares. To the right there is a set with deleted squares. The deleted squares are marked with crosses. | 500 | [
{
"input": "5 4\n####\n#..#\n#..#\n#..#\n####",
"output": "2"
},
{
"input": "5 5\n#####\n#...#\n#####\n#...#\n#####",
"output": "2"
},
{
"input": "1 10\n.########.",
"output": "1"
},
{
"input": "1 1\n#",
"output": "-1"
},
{
"input": "3 3\n.#.\n###\n.#.",
"output": "1"
},
{
"input": "1 2\n##",
"output": "-1"
},
{
"input": "2 1\n#\n#",
"output": "-1"
},
{
"input": "3 3\n###\n#.#\n###",
"output": "2"
},
{
"input": "2 2\n##\n#.",
"output": "1"
},
{
"input": "2 2\n##\n##",
"output": "2"
},
{
"input": "2 2\n.#\n##",
"output": "1"
},
{
"input": "2 2\n.#\n.#",
"output": "-1"
},
{
"input": "9 9\n#########\n#.......#\n#.#####.#\n#.#.#.#.#\n#.#.#.#.#\n#.#.#.#.#\n#.#####.#\n#...#...#\n#########",
"output": "1"
},
{
"input": "50 1\n#\n#\n#\n#\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.",
"output": "1"
},
{
"input": "3 50\n....##############################################\n....#.......#...#..#....#..............#.........#\n....##############################################",
"output": "2"
},
{
"input": "2 2\n##\n..",
"output": "-1"
},
{
"input": "5 5\n#####\n#####\n#....\n#####\n#####",
"output": "1"
},
{
"input": "3 5\n##.##\n#####\n##.##",
"output": "1"
},
{
"input": "4 4\n####\n####\n####\n####",
"output": "2"
},
{
"input": "5 7\n.#####.\n.#...#.\n###.###\n#.#.#.#\n###.###",
"output": "1"
},
{
"input": "2 5\n#####\n##.##",
"output": "1"
},
{
"input": "6 2\n##\n##\n#.\n##\n##\n##",
"output": "1"
},
{
"input": "2 5\n##.##\n#####",
"output": "1"
},
{
"input": "5 5\n#####\n#####\n##.##\n##.##\n##.##",
"output": "2"
},
{
"input": "5 3\n###\n###\n.#.\n###\n###",
"output": "1"
},
{
"input": "5 5\n###..\n###..\n#..##\n#####\n#####",
"output": "1"
}
] | 1,690,355,127 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 6 | 122 | 1,331,200 | def test():
n_m = input().split(' ')
n,m = int(n_m[0]),int(n_m[1])
array = []
for i in range(n):
array.append(input())
cnt = 0
has_one_nb = False
for i in range(n):
for j in range(m):
if array[i][j] == '#':
cnt+=1
nb_cnt = 0
if i-1>=0 and array[i-1][j] == '#':
nb_cnt +=1
if i+1<n and array[i+1][j] == '#':
nb_cnt +=1
if j-1>=0 and array[i][j-1] == '#':
nb_cnt +=1
if j+1<m and array[i][j+1] == '#':
nb_cnt +=1
if nb_cnt<=1:
has_one_nb = True
if cnt < 3:
return -1
elif has_one_nb:
return 1
else:
return 2
print(test()) | Title: Cutting Figure
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've gotten an *n*<=×<=*m* sheet of squared paper. Some of its squares are painted. Let's mark the set of all painted squares as *A*. Set *A* is connected. Your task is to find the minimum number of squares that we can delete from set *A* to make it not connected.
A set of painted squares is called connected, if for every two squares *a* and *b* from this set there is a sequence of squares from the set, beginning in *a* and ending in *b*, such that in this sequence any square, except for the last one, shares a common side with the square that follows next in the sequence. An empty set and a set consisting of exactly one square are connected by definition.
Input Specification:
The first input line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50) — the sizes of the sheet of paper.
Each of the next *n* lines contains *m* characters — the description of the sheet of paper: the *j*-th character of the *i*-th line equals either "#", if the corresponding square is painted (belongs to set *A*), or equals "." if the corresponding square is not painted (does not belong to set *A*). It is guaranteed that the set of all painted squares *A* is connected and isn't empty.
Output Specification:
On the first line print the minimum number of squares that need to be deleted to make set *A* not connected. If it is impossible, print -1.
Demo Input:
['5 4\n####\n#..#\n#..#\n#..#\n####\n', '5 5\n#####\n#...#\n#####\n#...#\n#####\n']
Demo Output:
['2\n', '2\n']
Note:
In the first sample you can delete any two squares that do not share a side. After that the set of painted squares is not connected anymore.
The note to the second sample is shown on the figure below. To the left there is a picture of the initial set of squares. To the right there is a set with deleted squares. The deleted squares are marked with crosses. | ```python
def test():
n_m = input().split(' ')
n,m = int(n_m[0]),int(n_m[1])
array = []
for i in range(n):
array.append(input())
cnt = 0
has_one_nb = False
for i in range(n):
for j in range(m):
if array[i][j] == '#':
cnt+=1
nb_cnt = 0
if i-1>=0 and array[i-1][j] == '#':
nb_cnt +=1
if i+1<n and array[i+1][j] == '#':
nb_cnt +=1
if j-1>=0 and array[i][j-1] == '#':
nb_cnt +=1
if j+1<m and array[i][j+1] == '#':
nb_cnt +=1
if nb_cnt<=1:
has_one_nb = True
if cnt < 3:
return -1
elif has_one_nb:
return 1
else:
return 2
print(test())
``` | 0 |
|
761 | A | Dasha and Stairs | PROGRAMMING | 1,000 | [
"brute force",
"constructive algorithms",
"implementation",
"math"
] | null | null | On her way to programming school tiger Dasha faced her first test — a huge staircase!
The steps were numbered from one to infinity. As we know, tigers are very fond of all striped things, it is possible that it has something to do with their color. So on some interval of her way she calculated two values — the number of steps with even and odd numbers.
You need to check whether there is an interval of steps from the *l*-th to the *r*-th (1<=≤<=*l*<=≤<=*r*), for which values that Dasha has found are correct. | In the only line you are given two integers *a*, *b* (0<=≤<=*a*,<=*b*<=≤<=100) — the number of even and odd steps, accordingly. | In the only line print "YES", if the interval of steps described above exists, and "NO" otherwise. | [
"2 3\n",
"3 1\n"
] | [
"YES\n",
"NO\n"
] | In the first example one of suitable intervals is from 1 to 5. The interval contains two even steps — 2 and 4, and three odd: 1, 3 and 5. | 500 | [
{
"input": "2 3",
"output": "YES"
},
{
"input": "3 1",
"output": "NO"
},
{
"input": "5 4",
"output": "YES"
},
{
"input": "9 9",
"output": "YES"
},
{
"input": "85 95",
"output": "NO"
},
{
"input": "0 1",
"output": "YES"
},
{
"input": "89 25",
"output": "NO"
},
{
"input": "74 73",
"output": "YES"
},
{
"input": "62 39",
"output": "NO"
},
{
"input": "57 57",
"output": "YES"
},
{
"input": "100 99",
"output": "YES"
},
{
"input": "0 0",
"output": "NO"
},
{
"input": "98 100",
"output": "NO"
},
{
"input": "99 100",
"output": "YES"
},
{
"input": "1 0",
"output": "YES"
},
{
"input": "100 0",
"output": "NO"
},
{
"input": "0 100",
"output": "NO"
},
{
"input": "100 98",
"output": "NO"
},
{
"input": "100 100",
"output": "YES"
},
{
"input": "0 5",
"output": "NO"
},
{
"input": "2 2",
"output": "YES"
}
] | 1,686,824,704 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 61 | 2,867,200 | for _ in range(int(input())):
n=int(input())
l=['1','3','2','4']
while len(l)>n:
l.pop()
for x in range(5,n+1):
l.append(str(x))
if n==3:
print("1 3 2")
print("3 2 1")
print("3 1 2")
else:
for x in range(n):
print(' '.join(l[x:])+" "+" ".join(l[:x]))
| Title: Dasha and Stairs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
On her way to programming school tiger Dasha faced her first test — a huge staircase!
The steps were numbered from one to infinity. As we know, tigers are very fond of all striped things, it is possible that it has something to do with their color. So on some interval of her way she calculated two values — the number of steps with even and odd numbers.
You need to check whether there is an interval of steps from the *l*-th to the *r*-th (1<=≤<=*l*<=≤<=*r*), for which values that Dasha has found are correct.
Input Specification:
In the only line you are given two integers *a*, *b* (0<=≤<=*a*,<=*b*<=≤<=100) — the number of even and odd steps, accordingly.
Output Specification:
In the only line print "YES", if the interval of steps described above exists, and "NO" otherwise.
Demo Input:
['2 3\n', '3 1\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first example one of suitable intervals is from 1 to 5. The interval contains two even steps — 2 and 4, and three odd: 1, 3 and 5. | ```python
for _ in range(int(input())):
n=int(input())
l=['1','3','2','4']
while len(l)>n:
l.pop()
for x in range(5,n+1):
l.append(str(x))
if n==3:
print("1 3 2")
print("3 2 1")
print("3 1 2")
else:
for x in range(n):
print(' '.join(l[x:])+" "+" ".join(l[:x]))
``` | -1 |
|
898 | A | Rounding | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Vasya has a non-negative integer *n*. He wants to round it to nearest integer, which ends up with 0. If *n* already ends up with 0, Vasya considers it already rounded.
For example, if *n*<==<=4722 answer is 4720. If *n*<==<=5 Vasya can round it to 0 or to 10. Both ways are correct.
For given *n* find out to which integer will Vasya round it. | The first line contains single integer *n* (0<=≤<=*n*<=≤<=109) — number that Vasya has. | Print result of rounding *n*. Pay attention that in some cases answer isn't unique. In that case print any correct answer. | [
"5\n",
"113\n",
"1000000000\n",
"5432359\n"
] | [
"0\n",
"110\n",
"1000000000\n",
"5432360\n"
] | In the first example *n* = 5. Nearest integers, that ends up with zero are 0 and 10. Any of these answers is correct, so you can print 0 or 10. | 500 | [
{
"input": "5",
"output": "0"
},
{
"input": "113",
"output": "110"
},
{
"input": "1000000000",
"output": "1000000000"
},
{
"input": "5432359",
"output": "5432360"
},
{
"input": "999999994",
"output": "999999990"
},
{
"input": "10",
"output": "10"
},
{
"input": "9",
"output": "10"
},
{
"input": "1",
"output": "0"
},
{
"input": "0",
"output": "0"
},
{
"input": "3",
"output": "0"
},
{
"input": "4",
"output": "0"
},
{
"input": "6",
"output": "10"
},
{
"input": "7",
"output": "10"
},
{
"input": "8",
"output": "10"
},
{
"input": "19",
"output": "20"
},
{
"input": "100",
"output": "100"
},
{
"input": "997",
"output": "1000"
},
{
"input": "9994",
"output": "9990"
},
{
"input": "10002",
"output": "10000"
},
{
"input": "100000",
"output": "100000"
},
{
"input": "99999",
"output": "100000"
},
{
"input": "999999999",
"output": "1000000000"
},
{
"input": "999999998",
"output": "1000000000"
},
{
"input": "999999995",
"output": "999999990"
},
{
"input": "999999990",
"output": "999999990"
},
{
"input": "1000000",
"output": "1000000"
},
{
"input": "1000010",
"output": "1000010"
},
{
"input": "10000010",
"output": "10000010"
},
{
"input": "100000011",
"output": "100000010"
},
{
"input": "400000003",
"output": "400000000"
},
{
"input": "234234",
"output": "234230"
},
{
"input": "675621",
"output": "675620"
},
{
"input": "43532",
"output": "43530"
},
{
"input": "4576453",
"output": "4576450"
},
{
"input": "65754674",
"output": "65754670"
},
{
"input": "3245526",
"output": "3245530"
},
{
"input": "123445",
"output": "123440"
},
{
"input": "234217",
"output": "234220"
},
{
"input": "23451218",
"output": "23451220"
},
{
"input": "1231239",
"output": "1231240"
},
{
"input": "1923140",
"output": "1923140"
},
{
"input": "307910310",
"output": "307910310"
},
{
"input": "780961030",
"output": "780961030"
},
{
"input": "103509421",
"output": "103509420"
},
{
"input": "576560141",
"output": "576560140"
},
{
"input": "48851642",
"output": "48851640"
},
{
"input": "226935072",
"output": "226935070"
},
{
"input": "844450763",
"output": "844450760"
},
{
"input": "22534183",
"output": "22534180"
},
{
"input": "640049874",
"output": "640049870"
},
{
"input": "818133304",
"output": "818133300"
},
{
"input": "730616285",
"output": "730616280"
},
{
"input": "613732415",
"output": "613732410"
},
{
"input": "380991216",
"output": "380991220"
},
{
"input": "559074636",
"output": "559074640"
},
{
"input": "176590327",
"output": "176590330"
},
{
"input": "354673757",
"output": "354673760"
},
{
"input": "267156738",
"output": "267156740"
},
{
"input": "150272868",
"output": "150272870"
},
{
"input": "62755859",
"output": "62755860"
},
{
"input": "945871979",
"output": "945871980"
},
{
"input": "46",
"output": "50"
},
{
"input": "999",
"output": "1000"
},
{
"input": "1397",
"output": "1400"
}
] | 1,580,410,330 | 2,147,483,647 | Python 3 | OK | TESTS | 64 | 109 | 0 | n=int(input())
l=n%10
if l<5:
n=n-l
print(n)
else:
c=10-l
n=n+c
print(n)
| Title: Rounding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has a non-negative integer *n*. He wants to round it to nearest integer, which ends up with 0. If *n* already ends up with 0, Vasya considers it already rounded.
For example, if *n*<==<=4722 answer is 4720. If *n*<==<=5 Vasya can round it to 0 or to 10. Both ways are correct.
For given *n* find out to which integer will Vasya round it.
Input Specification:
The first line contains single integer *n* (0<=≤<=*n*<=≤<=109) — number that Vasya has.
Output Specification:
Print result of rounding *n*. Pay attention that in some cases answer isn't unique. In that case print any correct answer.
Demo Input:
['5\n', '113\n', '1000000000\n', '5432359\n']
Demo Output:
['0\n', '110\n', '1000000000\n', '5432360\n']
Note:
In the first example *n* = 5. Nearest integers, that ends up with zero are 0 and 10. Any of these answers is correct, so you can print 0 or 10. | ```python
n=int(input())
l=n%10
if l<5:
n=n-l
print(n)
else:
c=10-l
n=n+c
print(n)
``` | 3 |
|
78 | B | Easter Eggs | PROGRAMMING | 1,200 | [
"constructive algorithms",
"implementation"
] | B. Easter Eggs | 2 | 256 | The Easter Rabbit laid *n* eggs in a circle and is about to paint them.
Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied:
- Each of the seven colors should be used to paint at least one egg. - Any four eggs lying sequentially should be painted different colors.
Help the Easter Rabbit paint the eggs in the required manner. We know that it is always possible. | The only line contains an integer *n* — the amount of eggs (7<=≤<=*n*<=≤<=100). | Print one line consisting of *n* characters. The *i*-th character should describe the color of the *i*-th egg in the order they lie in the circle. The colors should be represented as follows: "R" stands for red, "O" stands for orange, "Y" stands for yellow, "G" stands for green, "B" stands for blue, "I" stands for indigo, "V" stands for violet.
If there are several answers, print any of them. | [
"8\n",
"13\n"
] | [
"ROYGRBIV\n",
"ROYGBIVGBIVYG\n"
] | The way the eggs will be painted in the first sample is shown on the picture: | 1,000 | [
{
"input": "8",
"output": "ROYGBIVG"
},
{
"input": "13",
"output": "ROYGBIVOYGBIV"
},
{
"input": "7",
"output": "ROYGBIV"
},
{
"input": "10",
"output": "ROYGBIVYGB"
},
{
"input": "14",
"output": "ROYGBIVROYGBIV"
},
{
"input": "50",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVG"
},
{
"input": "9",
"output": "ROYGBIVGB"
},
{
"input": "11",
"output": "ROYGBIVYGBI"
},
{
"input": "12",
"output": "ROYGBIVOYGBI"
},
{
"input": "15",
"output": "ROYGBIVROYGBIVG"
},
{
"input": "16",
"output": "ROYGBIVROYGBIVGB"
},
{
"input": "17",
"output": "ROYGBIVROYGBIVYGB"
},
{
"input": "18",
"output": "ROYGBIVROYGBIVYGBI"
},
{
"input": "19",
"output": "ROYGBIVROYGBIVOYGBI"
},
{
"input": "20",
"output": "ROYGBIVROYGBIVOYGBIV"
},
{
"input": "21",
"output": "ROYGBIVROYGBIVROYGBIV"
},
{
"input": "22",
"output": "ROYGBIVROYGBIVROYGBIVG"
},
{
"input": "23",
"output": "ROYGBIVROYGBIVROYGBIVGB"
},
{
"input": "24",
"output": "ROYGBIVROYGBIVROYGBIVYGB"
},
{
"input": "25",
"output": "ROYGBIVROYGBIVROYGBIVYGBI"
},
{
"input": "28",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIV"
},
{
"input": "29",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVG"
},
{
"input": "34",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVOYGBIV"
},
{
"input": "43",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVG"
},
{
"input": "61",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVOYGBI"
},
{
"input": "79",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVGB"
},
{
"input": "81",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVYGBI"
},
{
"input": "92",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVG"
},
{
"input": "95",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVYGBI"
},
{
"input": "96",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVOYGBI"
},
{
"input": "97",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVOYGBIV"
},
{
"input": "98",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIV"
},
{
"input": "99",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVG"
},
{
"input": "100",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVGB"
}
] | 1,608,881,224 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 218 | 307,200 | import random
n = int(input())
colors = ['R', 'O', 'Y', 'G', 'B', 'I', 'V']
arr = []
for i in range(n):
arr.append(0)
i = 0
while i <= n-1:
if colors == []:
colors = ['R', 'O', 'Y', 'G', 'B', 'I', 'V']
x = colors[random.randint(0, len(colors)-1)]
if x != arr[i-1]:
arr[i] = x
colors.remove(x)
i += 1
string = ""
for i in range(n):
string += arr[i]
print(string)
| Title: Easter Eggs
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The Easter Rabbit laid *n* eggs in a circle and is about to paint them.
Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied:
- Each of the seven colors should be used to paint at least one egg. - Any four eggs lying sequentially should be painted different colors.
Help the Easter Rabbit paint the eggs in the required manner. We know that it is always possible.
Input Specification:
The only line contains an integer *n* — the amount of eggs (7<=≤<=*n*<=≤<=100).
Output Specification:
Print one line consisting of *n* characters. The *i*-th character should describe the color of the *i*-th egg in the order they lie in the circle. The colors should be represented as follows: "R" stands for red, "O" stands for orange, "Y" stands for yellow, "G" stands for green, "B" stands for blue, "I" stands for indigo, "V" stands for violet.
If there are several answers, print any of them.
Demo Input:
['8\n', '13\n']
Demo Output:
['ROYGRBIV\n', 'ROYGBIVGBIVYG\n']
Note:
The way the eggs will be painted in the first sample is shown on the picture: | ```python
import random
n = int(input())
colors = ['R', 'O', 'Y', 'G', 'B', 'I', 'V']
arr = []
for i in range(n):
arr.append(0)
i = 0
while i <= n-1:
if colors == []:
colors = ['R', 'O', 'Y', 'G', 'B', 'I', 'V']
x = colors[random.randint(0, len(colors)-1)]
if x != arr[i-1]:
arr[i] = x
colors.remove(x)
i += 1
string = ""
for i in range(n):
string += arr[i]
print(string)
``` | 0 |
994 | B | Knights of a Polygonal Table | PROGRAMMING | 1,400 | [
"greedy",
"implementation",
"sortings"
] | null | null | Unlike Knights of a Round Table, Knights of a Polygonal Table deprived of nobility and happy to kill each other. But each knight has some power and a knight can kill another knight if and only if his power is greater than the power of victim. However, even such a knight will torment his conscience, so he can kill no more than $k$ other knights. Also, each knight has some number of coins. After a kill, a knight can pick up all victim's coins.
Now each knight ponders: how many coins he can have if only he kills other knights?
You should answer this question for each knight. | The first line contains two integers $n$ and $k$ $(1 \le n \le 10^5, 0 \le k \le \min(n-1,10))$ — the number of knights and the number $k$ from the statement.
The second line contains $n$ integers $p_1, p_2 ,\ldots,p_n$ $(1 \le p_i \le 10^9)$ — powers of the knights. All $p_i$ are distinct.
The third line contains $n$ integers $c_1, c_2 ,\ldots,c_n$ $(0 \le c_i \le 10^9)$ — the number of coins each knight has. | Print $n$ integers — the maximum number of coins each knight can have it only he kills other knights. | [
"4 2\n4 5 9 7\n1 2 11 33\n",
"5 1\n1 2 3 4 5\n1 2 3 4 5\n",
"1 0\n2\n3\n"
] | [
"1 3 46 36 ",
"1 3 5 7 9 ",
"3 "
] | Consider the first example.
- The first knight is the weakest, so he can't kill anyone. That leaves him with the only coin he initially has. - The second knight can kill the first knight and add his coin to his own two. - The third knight is the strongest, but he can't kill more than $k = 2$ other knights. It is optimal to kill the second and the fourth knights: $2+11+33 = 46$. - The fourth knight should kill the first and the second knights: $33+1+2 = 36$.
In the second example the first knight can't kill anyone, while all the others should kill the one with the index less by one than their own.
In the third example there is only one knight, so he can't kill anyone. | 1,000 | [
{
"input": "4 2\n4 5 9 7\n1 2 11 33",
"output": "1 3 46 36 "
},
{
"input": "5 1\n1 2 3 4 5\n1 2 3 4 5",
"output": "1 3 5 7 9 "
},
{
"input": "1 0\n2\n3",
"output": "3 "
},
{
"input": "7 1\n2 3 4 5 7 8 9\n0 3 7 9 5 8 9",
"output": "0 3 10 16 14 17 18 "
},
{
"input": "7 2\n2 4 6 7 8 9 10\n10 8 4 8 4 5 9",
"output": "10 18 22 26 22 23 27 "
},
{
"input": "11 10\n1 2 3 4 5 6 7 8 9 10 11\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "1000000000 2000000000 3000000000 4000000000 5000000000 6000000000 7000000000 8000000000 9000000000 10000000000 11000000000 "
},
{
"input": "2 0\n2 3\n3 3",
"output": "3 3 "
},
{
"input": "7 3\n1 2 3 4 5 6 7\n3 3 3 4 5 6 7",
"output": "3 6 9 13 15 18 22 "
},
{
"input": "3 0\n3 2 1\n1 2 3",
"output": "1 2 3 "
},
{
"input": "5 3\n4 5 7 9 11\n10 10 10 10 10",
"output": "10 20 30 40 40 "
},
{
"input": "4 0\n4 5 9 7\n1 2 11 33",
"output": "1 2 11 33 "
},
{
"input": "7 3\n1 2 3 4 5 6 7\n3 3 3 8 8 8 8",
"output": "3 6 9 17 22 27 32 "
},
{
"input": "3 0\n1 2 3\n5 5 5",
"output": "5 5 5 "
},
{
"input": "4 2\n4 5 9 7\n2 2 11 33",
"output": "2 4 46 37 "
},
{
"input": "6 3\n1 2 3 4 5 6\n1 1 1 1 1 1",
"output": "1 2 3 4 4 4 "
},
{
"input": "10 5\n1 2 3 4 5 6 7 8 9 10\n1 1 1 1 1 1 1 1 1 1",
"output": "1 2 3 4 5 6 6 6 6 6 "
},
{
"input": "3 2\n1 2 3\n1 1 1",
"output": "1 2 3 "
},
{
"input": "3 0\n1 2 3\n10 20 30",
"output": "10 20 30 "
},
{
"input": "4 0\n4 5 9 7\n1 2 3 4",
"output": "1 2 3 4 "
},
{
"input": "5 4\n1 2 3 4 5\n1 1 1 1 1",
"output": "1 2 3 4 5 "
},
{
"input": "4 3\n1 2 3 4\n5 5 5 5",
"output": "5 10 15 20 "
},
{
"input": "5 3\n1 2 3 4 5\n7 7 7 7 7",
"output": "7 14 21 28 28 "
}
] | 1,529,212,990 | 1,210 | PyPy 3 | OK | TESTS | 73 | 826 | 39,936,000 | import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
dd = [(0,-1),(1,0),(0,1),(-1,0)]
ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def main():
n,m = LI()
a = LI()
b = LI()
c = []
if m == 0:
return ' '.join(map(str, b))
for i in range(n):
c.append((a[i],b[i],i))
c.sort()
t = []
rr = {}
for d,e,i in c:
tr = e
tr += sum(t)
rr[i] = tr
if len(t) < m:
t.append(e)
else:
tm = min(t)
if tm < e:
tmi = t.index(tm)
t[tmi] = e
r = []
for i in range(n):
r.append(rr[i])
return ' '.join(map(str,r))
print(main())
| Title: Knights of a Polygonal Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Unlike Knights of a Round Table, Knights of a Polygonal Table deprived of nobility and happy to kill each other. But each knight has some power and a knight can kill another knight if and only if his power is greater than the power of victim. However, even such a knight will torment his conscience, so he can kill no more than $k$ other knights. Also, each knight has some number of coins. After a kill, a knight can pick up all victim's coins.
Now each knight ponders: how many coins he can have if only he kills other knights?
You should answer this question for each knight.
Input Specification:
The first line contains two integers $n$ and $k$ $(1 \le n \le 10^5, 0 \le k \le \min(n-1,10))$ — the number of knights and the number $k$ from the statement.
The second line contains $n$ integers $p_1, p_2 ,\ldots,p_n$ $(1 \le p_i \le 10^9)$ — powers of the knights. All $p_i$ are distinct.
The third line contains $n$ integers $c_1, c_2 ,\ldots,c_n$ $(0 \le c_i \le 10^9)$ — the number of coins each knight has.
Output Specification:
Print $n$ integers — the maximum number of coins each knight can have it only he kills other knights.
Demo Input:
['4 2\n4 5 9 7\n1 2 11 33\n', '5 1\n1 2 3 4 5\n1 2 3 4 5\n', '1 0\n2\n3\n']
Demo Output:
['1 3 46 36 ', '1 3 5 7 9 ', '3 ']
Note:
Consider the first example.
- The first knight is the weakest, so he can't kill anyone. That leaves him with the only coin he initially has. - The second knight can kill the first knight and add his coin to his own two. - The third knight is the strongest, but he can't kill more than $k = 2$ other knights. It is optimal to kill the second and the fourth knights: $2+11+33 = 46$. - The fourth knight should kill the first and the second knights: $33+1+2 = 36$.
In the second example the first knight can't kill anyone, while all the others should kill the one with the index less by one than their own.
In the third example there is only one knight, so he can't kill anyone. | ```python
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
dd = [(0,-1),(1,0),(0,1),(-1,0)]
ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def main():
n,m = LI()
a = LI()
b = LI()
c = []
if m == 0:
return ' '.join(map(str, b))
for i in range(n):
c.append((a[i],b[i],i))
c.sort()
t = []
rr = {}
for d,e,i in c:
tr = e
tr += sum(t)
rr[i] = tr
if len(t) < m:
t.append(e)
else:
tm = min(t)
if tm < e:
tmi = t.index(tm)
t[tmi] = e
r = []
for i in range(n):
r.append(rr[i])
return ' '.join(map(str,r))
print(main())
``` | 3 |
|
493 | A | Vasya and Football | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player who receives the second yellow card automatically receives a red card.
Vasya is watching a recorded football match now and makes notes of all the fouls that he would give a card for. Help Vasya determine all the moments in time when players would be given red cards if Vasya were the judge. For each player, Vasya wants to know only the first moment of time when he would receive a red card from Vasya. | The first line contains the name of the team playing at home. The second line contains the name of the team playing away. Both lines are not empty. The lengths of both lines do not exceed 20. Each line contains only of large English letters. The names of the teams are distinct.
Next follows number *n* (1<=≤<=*n*<=≤<=90) — the number of fouls.
Each of the following *n* lines contains information about a foul in the following form:
- first goes number *t* (1<=≤<=*t*<=≤<=90) — the minute when the foul occurs; - then goes letter "h" or letter "a" — if the letter is "h", then the card was given to a home team player, otherwise the card was given to an away team player; - then goes the player's number *m* (1<=≤<=*m*<=≤<=99); - then goes letter "y" or letter "r" — if the letter is "y", that means that the yellow card was given, otherwise the red card was given.
The players from different teams can have the same number. The players within one team have distinct numbers. The fouls go chronologically, no two fouls happened at the same minute. | For each event when a player received his first red card in a chronological order print a string containing the following information:
- The name of the team to which the player belongs; - the player's number in his team; - the minute when he received the card.
If no player received a card, then you do not need to print anything.
It is possible case that the program will not print anything to the output (if there were no red cards). | [
"MC\nCSKA\n9\n28 a 3 y\n62 h 25 y\n66 h 42 y\n70 h 25 y\n77 a 4 y\n79 a 25 y\n82 h 42 r\n89 h 16 y\n90 a 13 r\n"
] | [
"MC 25 70\nMC 42 82\nCSKA 13 90\n"
] | none | 500 | [
{
"input": "MC\nCSKA\n9\n28 a 3 y\n62 h 25 y\n66 h 42 y\n70 h 25 y\n77 a 4 y\n79 a 25 y\n82 h 42 r\n89 h 16 y\n90 a 13 r",
"output": "MC 25 70\nMC 42 82\nCSKA 13 90"
},
{
"input": "REAL\nBARCA\n3\n27 h 7 y\n44 a 10 y\n87 h 3 r",
"output": "REAL 3 87"
},
{
"input": "MASFF\nSAFBDSRG\n5\n1 h 1 y\n15 h 1 r\n27 a 1 y\n58 a 1 y\n69 h 10 y",
"output": "MASFF 1 15\nSAFBDSRG 1 58"
},
{
"input": "ARMENIA\nBULGARIA\n12\n33 h 17 y\n42 h 21 y\n56 a 17 y\n58 a 6 y\n61 a 7 y\n68 a 10 y\n72 h 13 y\n73 h 21 y\n74 a 8 r\n75 a 4 y\n77 a 10 y\n90 a 23 y",
"output": "ARMENIA 21 73\nBULGARIA 8 74\nBULGARIA 10 77"
},
{
"input": "PORTUGAL\nNETHERLANDS\n16\n2 a 18 y\n7 a 3 y\n20 h 18 y\n31 h 6 y\n45 h 6 y\n50 h 8 y\n59 a 5 y\n60 h 7 y\n63 a 3 y\n72 a 20 y\n73 h 20 y\n74 a 10 y\n75 h 1 y\n76 h 14 y\n78 h 20 y\n90 a 5 y",
"output": "PORTUGAL 6 45\nNETHERLANDS 3 63\nPORTUGAL 20 78\nNETHERLANDS 5 90"
},
{
"input": "TANC\nXNCOR\n2\n15 h 27 r\n28 h 27 r",
"output": "TANC 27 15"
},
{
"input": "ASGDFJH\nAHGRSDXGER\n3\n23 h 15 r\n68 h 15 y\n79 h 15 y",
"output": "ASGDFJH 15 23"
},
{
"input": "ASFSHDSG\nADGYRTJNG\n5\n1 h 1 y\n2 h 1 y\n3 h 1 y\n4 h 1 r\n5 h 1 y",
"output": "ASFSHDSG 1 2"
},
{
"input": "A\nB\n42\n5 a 84 y\n8 h 28 r\n10 a 9 r\n11 h 93 y\n13 a 11 r\n15 h 3 r\n20 a 88 r\n23 a 41 y\n25 a 14 y\n27 a 38 r\n28 a 33 y\n29 h 66 r\n31 a 16 r\n32 a 80 y\n34 a 54 r\n35 a 50 y\n36 a 9 y\n39 a 22 y\n42 h 81 y\n43 a 10 y\n44 a 27 r\n47 h 39 y\n48 a 80 y\n50 h 5 y\n52 a 67 y\n54 h 63 y\n56 h 7 y\n57 h 44 y\n58 h 41 y\n61 h 32 y\n64 h 91 y\n67 a 56 y\n69 h 83 y\n71 h 59 y\n72 a 76 y\n75 h 41 y\n76 a 49 r\n77 a 4 r\n78 a 69 y\n79 a 96 r\n80 h 81 y\n86 h 85 r",
"output": "A 28 8\nB 9 10\nB 11 13\nA 3 15\nB 88 20\nB 38 27\nA 66 29\nB 16 31\nB 54 34\nB 27 44\nB 80 48\nA 41 75\nB 49 76\nB 4 77\nB 96 79\nA 81 80\nA 85 86"
},
{
"input": "ARM\nAZE\n45\n2 a 13 r\n3 a 73 r\n4 a 10 y\n5 h 42 y\n8 h 56 y\n10 h 15 y\n11 a 29 r\n13 a 79 y\n14 a 77 r\n18 h 7 y\n20 a 69 r\n22 h 19 y\n25 h 88 r\n26 a 78 y\n27 a 91 r\n28 h 10 r\n30 h 13 r\n31 a 26 r\n33 a 43 r\n34 a 91 y\n40 h 57 y\n44 h 18 y\n46 a 25 r\n48 a 29 y\n51 h 71 y\n57 a 16 r\n58 h 37 r\n59 h 92 y\n60 h 11 y\n61 a 88 y\n64 a 28 r\n65 h 71 r\n68 h 39 y\n70 h 8 r\n71 a 10 y\n72 a 32 y\n73 h 95 r\n74 a 33 y\n75 h 48 r\n78 a 44 y\n79 a 22 r\n80 h 50 r\n84 a 50 y\n88 a 90 y\n89 h 42 r",
"output": "AZE 13 2\nAZE 73 3\nAZE 29 11\nAZE 77 14\nAZE 69 20\nARM 88 25\nAZE 91 27\nARM 10 28\nARM 13 30\nAZE 26 31\nAZE 43 33\nAZE 25 46\nAZE 16 57\nARM 37 58\nAZE 28 64\nARM 71 65\nARM 8 70\nAZE 10 71\nARM 95 73\nARM 48 75\nAZE 22 79\nARM 50 80\nARM 42 89"
},
{
"input": "KASFLS\nASJBGGDLJFDDFHHTHJH\n42\n2 a 68 y\n4 h 64 r\n5 a 24 y\n6 h 20 r\n8 a 16 r\n9 a 96 y\n10 h 36 r\n12 a 44 y\n13 h 69 r\n16 a 62 r\n18 a 99 r\n20 h 12 r\n21 a 68 y\n25 h 40 y\n26 h 54 r\n28 h 91 r\n29 a 36 r\n33 a 91 y\n36 h 93 r\n37 h 60 r\n38 a 82 r\n41 a 85 y\n42 a 62 r\n46 a 22 r\n48 a 88 r\n49 a 8 r\n51 h 45 y\n54 a 84 y\n57 a 8 y\n59 h 24 y\n61 h 22 r\n64 h 11 r\n69 a 89 y\n72 h 44 r\n75 h 57 r\n76 h 80 y\n77 h 54 r\n79 a 1 y\n81 a 31 r\n82 h 8 y\n83 a 28 r\n86 h 56 y",
"output": "KASFLS 64 4\nKASFLS 20 6\nASJBGGDLJFDDFHHTHJH 16 8\nKASFLS 36 10\nKASFLS 69 13\nASJBGGDLJFDDFHHTHJH 62 16\nASJBGGDLJFDDFHHTHJH 99 18\nKASFLS 12 20\nASJBGGDLJFDDFHHTHJH 68 21\nKASFLS 54 26\nKASFLS 91 28\nASJBGGDLJFDDFHHTHJH 36 29\nKASFLS 93 36\nKASFLS 60 37\nASJBGGDLJFDDFHHTHJH 82 38\nASJBGGDLJFDDFHHTHJH 22 46\nASJBGGDLJFDDFHHTHJH 88 48\nASJBGGDLJFDDFHHTHJH 8 49\nKASFLS 22 61\nKASFLS 11 64\nKASFLS 44 72\nKASFLS 57 75\nASJBGGDLJFDDFHHTHJH 31 81\nASJBGGDLJFDDFHHTHJH 28 83"
},
{
"input": "AB\nBC\n3\n1 h 1 y\n2 h 1 y\n3 h 1 r",
"output": "AB 1 2"
}
] | 1,562,139,439 | 2,147,483,647 | PyPy 3 | OK | TESTS | 18 | 139 | 0 | def main():
home = input()
away = input()
n = int(input())
cards = {}
teams = {}
teams['h'] = home
teams['a'] = away
for i in range(n):
t,team,m,card = map(str,input().split())
t = int(t)
m = int(m)
curr = (team,m)
if curr not in cards.keys():
cards[(team,m)] = [[card,1]]
if card == 'r':
print(teams[team],m,t)
else:
if len(cards[(team,m)]) == 1:
if cards[(team,m)][0][0] == 'y' and cards[(team,m)][0][1] == 1:
print(teams[team],m,t)
cards[(team,m)][0][1] += 1
#print(cards)
main()
| Title: Vasya and Football
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player who receives the second yellow card automatically receives a red card.
Vasya is watching a recorded football match now and makes notes of all the fouls that he would give a card for. Help Vasya determine all the moments in time when players would be given red cards if Vasya were the judge. For each player, Vasya wants to know only the first moment of time when he would receive a red card from Vasya.
Input Specification:
The first line contains the name of the team playing at home. The second line contains the name of the team playing away. Both lines are not empty. The lengths of both lines do not exceed 20. Each line contains only of large English letters. The names of the teams are distinct.
Next follows number *n* (1<=≤<=*n*<=≤<=90) — the number of fouls.
Each of the following *n* lines contains information about a foul in the following form:
- first goes number *t* (1<=≤<=*t*<=≤<=90) — the minute when the foul occurs; - then goes letter "h" or letter "a" — if the letter is "h", then the card was given to a home team player, otherwise the card was given to an away team player; - then goes the player's number *m* (1<=≤<=*m*<=≤<=99); - then goes letter "y" or letter "r" — if the letter is "y", that means that the yellow card was given, otherwise the red card was given.
The players from different teams can have the same number. The players within one team have distinct numbers. The fouls go chronologically, no two fouls happened at the same minute.
Output Specification:
For each event when a player received his first red card in a chronological order print a string containing the following information:
- The name of the team to which the player belongs; - the player's number in his team; - the minute when he received the card.
If no player received a card, then you do not need to print anything.
It is possible case that the program will not print anything to the output (if there were no red cards).
Demo Input:
['MC\nCSKA\n9\n28 a 3 y\n62 h 25 y\n66 h 42 y\n70 h 25 y\n77 a 4 y\n79 a 25 y\n82 h 42 r\n89 h 16 y\n90 a 13 r\n']
Demo Output:
['MC 25 70\nMC 42 82\nCSKA 13 90\n']
Note:
none | ```python
def main():
home = input()
away = input()
n = int(input())
cards = {}
teams = {}
teams['h'] = home
teams['a'] = away
for i in range(n):
t,team,m,card = map(str,input().split())
t = int(t)
m = int(m)
curr = (team,m)
if curr not in cards.keys():
cards[(team,m)] = [[card,1]]
if card == 'r':
print(teams[team],m,t)
else:
if len(cards[(team,m)]) == 1:
if cards[(team,m)][0][0] == 'y' and cards[(team,m)][0][1] == 1:
print(teams[team],m,t)
cards[(team,m)][0][1] += 1
#print(cards)
main()
``` | 3 |
|
237 | A | Free Cash | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends less than a minute to serve each client, but if a client comes in and sees that there is no free cash, than he doesn't want to wait and leaves the cafe immediately.
Valera is very greedy, so he wants to serve all *n* customers next day (and get more profit). However, for that he needs to ensure that at each moment of time the number of working cashes is no less than the number of clients in the cafe.
Help Valera count the minimum number of cashes to work at his cafe next day, so that they can serve all visitors. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), that is the number of cafe visitors.
Each of the following *n* lines has two space-separated integers *h**i* and *m**i* (0<=≤<=*h**i*<=≤<=23; 0<=≤<=*m**i*<=≤<=59), representing the time when the *i*-th person comes into the cafe.
Note that the time is given in the chronological order. All time is given within one 24-hour period. | Print a single integer — the minimum number of cashes, needed to serve all clients next day. | [
"4\n8 0\n8 10\n8 10\n8 45\n",
"3\n0 12\n10 11\n22 22\n"
] | [
"2\n",
"1\n"
] | In the first sample it is not enough one cash to serve all clients, because two visitors will come into cafe in 8:10. Therefore, if there will be one cash in cafe, then one customer will be served by it, and another one will not wait and will go away.
In the second sample all visitors will come in different times, so it will be enough one cash. | 500 | [
{
"input": "4\n8 0\n8 10\n8 10\n8 45",
"output": "2"
},
{
"input": "3\n0 12\n10 11\n22 22",
"output": "1"
},
{
"input": "5\n12 8\n15 27\n15 27\n16 2\n19 52",
"output": "2"
},
{
"input": "7\n5 6\n7 34\n7 34\n7 34\n12 29\n15 19\n20 23",
"output": "3"
},
{
"input": "8\n0 36\n4 7\n4 7\n4 7\n11 46\n12 4\n15 39\n18 6",
"output": "3"
},
{
"input": "20\n4 12\n4 21\n4 27\n4 56\n5 55\n7 56\n11 28\n11 36\n14 58\n15 59\n16 8\n17 12\n17 23\n17 23\n17 23\n17 23\n17 23\n17 23\n20 50\n22 32",
"output": "6"
},
{
"input": "10\n1 30\n1 30\n1 30\n1 30\n1 30\n1 30\n1 30\n1 30\n1 30\n1 30",
"output": "10"
},
{
"input": "50\n0 23\n1 21\n2 8\n2 45\n3 1\n4 19\n4 37\n7 7\n7 40\n8 43\n9 51\n10 13\n11 2\n11 19\n11 30\n12 37\n12 37\n12 37\n12 37\n12 37\n12 37\n12 37\n12 37\n12 54\n13 32\n13 42\n14 29\n14 34\n14 48\n15 0\n15 27\n16 22\n16 31\n17 25\n17 26\n17 33\n18 14\n18 16\n18 20\n19 0\n19 5\n19 56\n20 22\n21 26\n22 0\n22 10\n22 11\n22 36\n23 17\n23 20",
"output": "8"
},
{
"input": "10\n0 39\n1 35\n1 49\n1 51\n5 24\n7 40\n7 56\n16 42\n23 33\n23 49",
"output": "1"
},
{
"input": "15\n0 16\n6 15\n8 2\n8 6\n8 7\n10 1\n10 1\n10 3\n10 12\n13 5\n14 16\n14 16\n14 16\n14 16\n14 16",
"output": "5"
},
{
"input": "2\n0 24\n1 0",
"output": "1"
},
{
"input": "1\n0 0",
"output": "1"
},
{
"input": "1\n1 5",
"output": "1"
},
{
"input": "1\n1 1",
"output": "1"
},
{
"input": "3\n0 0\n0 0\n0 0",
"output": "3"
},
{
"input": "1\n5 0",
"output": "1"
},
{
"input": "5\n0 0\n0 0\n0 0\n0 0\n0 0",
"output": "5"
},
{
"input": "1\n10 10",
"output": "1"
},
{
"input": "1\n8 0",
"output": "1"
},
{
"input": "10\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0",
"output": "10"
},
{
"input": "2\n0 0\n0 1",
"output": "1"
},
{
"input": "2\n8 5\n8 5",
"output": "2"
}
] | 1,687,833,229 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 67 | 1,340 | 9,830,400 | n = int(input())
visited = {}
for i in range(n):
h, m = map(int, input().split())
visited[(h, m)] = visited.get((h, m), 0) + 1
print(max(visited.values()))
| Title: Free Cash
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends less than a minute to serve each client, but if a client comes in and sees that there is no free cash, than he doesn't want to wait and leaves the cafe immediately.
Valera is very greedy, so he wants to serve all *n* customers next day (and get more profit). However, for that he needs to ensure that at each moment of time the number of working cashes is no less than the number of clients in the cafe.
Help Valera count the minimum number of cashes to work at his cafe next day, so that they can serve all visitors.
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), that is the number of cafe visitors.
Each of the following *n* lines has two space-separated integers *h**i* and *m**i* (0<=≤<=*h**i*<=≤<=23; 0<=≤<=*m**i*<=≤<=59), representing the time when the *i*-th person comes into the cafe.
Note that the time is given in the chronological order. All time is given within one 24-hour period.
Output Specification:
Print a single integer — the minimum number of cashes, needed to serve all clients next day.
Demo Input:
['4\n8 0\n8 10\n8 10\n8 45\n', '3\n0 12\n10 11\n22 22\n']
Demo Output:
['2\n', '1\n']
Note:
In the first sample it is not enough one cash to serve all clients, because two visitors will come into cafe in 8:10. Therefore, if there will be one cash in cafe, then one customer will be served by it, and another one will not wait and will go away.
In the second sample all visitors will come in different times, so it will be enough one cash. | ```python
n = int(input())
visited = {}
for i in range(n):
h, m = map(int, input().split())
visited[(h, m)] = visited.get((h, m), 0) + 1
print(max(visited.values()))
``` | 3 |
|
851 | B | Arpa and an exam about geometry | PROGRAMMING | 1,400 | [
"geometry",
"math"
] | null | null | Arpa is taking a geometry exam. Here is the last problem of the exam.
You are given three points *a*,<=*b*,<=*c*.
Find a point and an angle such that if we rotate the page around the point by the angle, the new position of *a* is the same as the old position of *b*, and the new position of *b* is the same as the old position of *c*.
Arpa is doubting if the problem has a solution or not (i.e. if there exists a point and an angle satisfying the condition). Help Arpa determine if the question has a solution or not. | The only line contains six integers *a**x*,<=*a**y*,<=*b**x*,<=*b**y*,<=*c**x*,<=*c**y* (|*a**x*|,<=|*a**y*|,<=|*b**x*|,<=|*b**y*|,<=|*c**x*|,<=|*c**y*|<=≤<=109). It's guaranteed that the points are distinct. | Print "Yes" if the problem has a solution, "No" otherwise.
You can print each letter in any case (upper or lower). | [
"0 1 1 1 1 0\n",
"1 1 0 0 1000 1000\n"
] | [
"Yes\n",
"No\n"
] | In the first sample test, rotate the page around (0.5, 0.5) by <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/9d845923f4d356a48d8ede337db0303821311f0c.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample test, you can't find any solution. | 1,000 | [
{
"input": "0 1 1 1 1 0",
"output": "Yes"
},
{
"input": "1 1 0 0 1000 1000",
"output": "No"
},
{
"input": "1 0 2 0 3 0",
"output": "No"
},
{
"input": "3 4 0 0 4 3",
"output": "Yes"
},
{
"input": "-1000000000 1 0 0 1000000000 1",
"output": "Yes"
},
{
"input": "49152 0 0 0 0 81920",
"output": "No"
},
{
"input": "1 -1 4 4 2 -3",
"output": "No"
},
{
"input": "-2 -2 1 4 -2 0",
"output": "No"
},
{
"input": "5 0 4 -2 0 1",
"output": "No"
},
{
"input": "-4 -3 2 -1 -3 4",
"output": "No"
},
{
"input": "-3 -3 5 2 3 -1",
"output": "No"
},
{
"input": "-1000000000 -1000000000 0 0 1000000000 999999999",
"output": "No"
},
{
"input": "-1000000000 -1000000000 0 0 1000000000 1000000000",
"output": "No"
},
{
"input": "-357531221 381512519 -761132895 -224448284 328888775 -237692564",
"output": "No"
},
{
"input": "264193194 -448876521 736684426 -633906160 -328597212 -47935734",
"output": "No"
},
{
"input": "419578772 -125025887 169314071 89851312 961404059 21419450",
"output": "No"
},
{
"input": "-607353321 -620687860 248029390 477864359 728255275 -264646027",
"output": "No"
},
{
"input": "299948862 -648908808 338174789 841279400 -850322448 350263551",
"output": "No"
},
{
"input": "48517753 416240699 7672672 272460100 -917845051 199790781",
"output": "No"
},
{
"input": "-947393823 -495674431 211535284 -877153626 -522763219 -778236665",
"output": "No"
},
{
"input": "-685673792 -488079395 909733355 385950193 -705890324 256550506",
"output": "No"
},
{
"input": "-326038504 547872194 49630307 713863100 303770000 -556852524",
"output": "No"
},
{
"input": "-706921242 -758563024 -588592101 -443440080 858751713 238854303",
"output": "No"
},
{
"input": "-1000000000 -1000000000 0 1000000000 1000000000 -1000000000",
"output": "Yes"
},
{
"input": "1000000000 1000000000 0 -1000000000 -1000000000 1000000000",
"output": "Yes"
},
{
"input": "-999999999 -1000000000 0 0 1000000000 999999999",
"output": "Yes"
},
{
"input": "-1000000000 -999999999 0 0 1000000000 999999999",
"output": "No"
},
{
"input": "-1 -1000000000 0 1000000000 1 -1000000000",
"output": "Yes"
},
{
"input": "0 1000000000 1 0 0 -1000000000",
"output": "Yes"
},
{
"input": "0 1000000000 0 0 0 -1000000000",
"output": "No"
},
{
"input": "0 1 1 2 2 3",
"output": "No"
},
{
"input": "999999999 1000000000 0 0 -1000000000 -999999999",
"output": "Yes"
},
{
"input": "0 0 1 1 2 0",
"output": "Yes"
},
{
"input": "0 0 1 1 2 2",
"output": "No"
},
{
"input": "1 1 2 2 3 3",
"output": "No"
},
{
"input": "0 2 0 3 0 4",
"output": "No"
},
{
"input": "1 1 1 2 1 3",
"output": "No"
},
{
"input": "0 0 3 4 3 9",
"output": "Yes"
},
{
"input": "589824 196608 262144 196608 0 0",
"output": "Yes"
},
{
"input": "0 0 1000000000 1 1000000000 -999999999",
"output": "No"
},
{
"input": "0 0 2 45 0 90",
"output": "Yes"
},
{
"input": "0 0 0 2 0 1",
"output": "No"
},
{
"input": "0 2 4 5 4 0",
"output": "Yes"
},
{
"input": "0 0 2 0 4 0",
"output": "No"
},
{
"input": "1 1 3 3 5 5",
"output": "No"
},
{
"input": "1 1 2 2 3 1",
"output": "Yes"
}
] | 1,591,710,043 | 2,147,483,647 | PyPy 3 | OK | TESTS | 46 | 140 | 0 | L=list(map(int,input().split()))
x=((L[0]-L[2])*(L[1]-L[5])-(L[0]-L[4])*(L[1]-L[3]))
if(x==0):
print("No")
else:
y=(L[0]-L[2])**2+(L[1]-L[3])**2
z=(L[4]-L[2])**2+(L[5]-L[3])**2
if(y==z):
print("Yes")
else:
print("No") | Title: Arpa and an exam about geometry
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Arpa is taking a geometry exam. Here is the last problem of the exam.
You are given three points *a*,<=*b*,<=*c*.
Find a point and an angle such that if we rotate the page around the point by the angle, the new position of *a* is the same as the old position of *b*, and the new position of *b* is the same as the old position of *c*.
Arpa is doubting if the problem has a solution or not (i.e. if there exists a point and an angle satisfying the condition). Help Arpa determine if the question has a solution or not.
Input Specification:
The only line contains six integers *a**x*,<=*a**y*,<=*b**x*,<=*b**y*,<=*c**x*,<=*c**y* (|*a**x*|,<=|*a**y*|,<=|*b**x*|,<=|*b**y*|,<=|*c**x*|,<=|*c**y*|<=≤<=109). It's guaranteed that the points are distinct.
Output Specification:
Print "Yes" if the problem has a solution, "No" otherwise.
You can print each letter in any case (upper or lower).
Demo Input:
['0 1 1 1 1 0\n', '1 1 0 0 1000 1000\n']
Demo Output:
['Yes\n', 'No\n']
Note:
In the first sample test, rotate the page around (0.5, 0.5) by <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/9d845923f4d356a48d8ede337db0303821311f0c.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample test, you can't find any solution. | ```python
L=list(map(int,input().split()))
x=((L[0]-L[2])*(L[1]-L[5])-(L[0]-L[4])*(L[1]-L[3]))
if(x==0):
print("No")
else:
y=(L[0]-L[2])**2+(L[1]-L[3])**2
z=(L[4]-L[2])**2+(L[5]-L[3])**2
if(y==z):
print("Yes")
else:
print("No")
``` | 3 |
|
526 | B | Om Nom and Dark Park | PROGRAMMING | 1,400 | [
"dfs and similar",
"greedy",
"implementation"
] | null | null | Om Nom is the main character of a game "Cut the Rope". He is a bright little monster who likes visiting friends living at the other side of the park. However the dark old parks can scare even somebody as fearless as Om Nom, so he asks you to help him.
The park consists of 2*n*<=+<=1<=-<=1 squares connected by roads so that the scheme of the park is a full binary tree of depth *n*. More formally, the entrance to the park is located at the square 1. The exits out of the park are located at squares 2*n*,<=2*n*<=+<=1,<=...,<=2*n*<=+<=1<=-<=1 and these exits lead straight to the Om Nom friends' houses. From each square *i* (2<=≤<=*i*<=<<=2*n*<=+<=1) there is a road to the square . Thus, it is possible to go from the park entrance to each of the exits by walking along exactly *n* roads.
Om Nom loves counting lights on the way to his friend. Om Nom is afraid of spiders who live in the park, so he doesn't like to walk along roads that are not enough lit. What he wants is that the way to any of his friends should have in total the same number of lights. That will make him feel safe.
He asked you to help him install additional lights. Determine what minimum number of lights it is needed to additionally place on the park roads so that a path from the entrance to any exit of the park contains the same number of street lights. You may add an arbitrary number of street lights to each of the roads. | The first line contains integer *n* (1<=≤<=*n*<=≤<=10) — the number of roads on the path from the entrance to any exit.
The next line contains 2*n*<=+<=1<=-<=2 numbers *a*2,<=*a*3,<=... *a*2*n*<=+<=1<=-<=1 — the initial numbers of street lights on each road of the park. Here *a**i* is the number of street lights on the road between squares *i* and . All numbers *a**i* are positive integers, not exceeding 100. | Print the minimum number of street lights that we should add to the roads of the park to make Om Nom feel safe. | [
"2\n1 2 3 4 5 6\n"
] | [
"5\n"
] | Picture for the sample test. Green color denotes the additional street lights. | 500 | [
{
"input": "2\n1 2 3 4 5 6",
"output": "5"
},
{
"input": "2\n1 2 3 3 2 2",
"output": "0"
},
{
"input": "1\n39 52",
"output": "13"
},
{
"input": "2\n59 96 34 48 8 72",
"output": "139"
},
{
"input": "3\n87 37 91 29 58 45 51 74 70 71 47 38 91 89",
"output": "210"
},
{
"input": "5\n39 21 95 89 73 90 9 55 85 32 30 21 68 59 82 91 20 64 52 70 6 88 53 47 30 47 34 14 11 22 42 15 28 54 37 48 29 3 14 13 18 77 90 58 54 38 94 49 45 66 13 74 11 14 64 72 95 54 73 79 41 35",
"output": "974"
},
{
"input": "1\n49 36",
"output": "13"
},
{
"input": "1\n77 88",
"output": "11"
},
{
"input": "1\n1 33",
"output": "32"
},
{
"input": "2\n72 22 81 23 14 75",
"output": "175"
},
{
"input": "2\n100 70 27 1 68 52",
"output": "53"
},
{
"input": "2\n24 19 89 82 22 21",
"output": "80"
},
{
"input": "3\n86 12 92 91 3 68 57 56 76 27 33 62 71 84",
"output": "286"
},
{
"input": "3\n14 56 53 61 57 45 40 44 31 9 73 2 61 26",
"output": "236"
},
{
"input": "3\n35 96 7 43 10 14 16 36 95 92 16 50 59 55",
"output": "173"
},
{
"input": "4\n1 97 18 48 96 65 24 91 17 45 36 27 74 93 78 86 39 55 53 21 26 68 31 33 79 63 80 92 1 26",
"output": "511"
},
{
"input": "4\n25 42 71 29 50 30 99 79 77 24 76 66 68 23 97 99 65 17 75 62 66 46 48 4 40 71 98 57 21 92",
"output": "603"
},
{
"input": "4\n49 86 17 7 3 6 86 71 36 10 27 10 58 64 12 16 88 67 93 3 15 20 58 87 97 91 11 6 34 62",
"output": "470"
},
{
"input": "5\n16 87 36 16 81 53 87 35 63 56 47 91 81 95 80 96 91 7 58 99 25 28 47 60 7 69 49 14 51 52 29 30 83 23 21 52 100 26 91 14 23 94 72 70 40 12 50 32 54 52 18 74 5 15 62 3 48 41 24 25 56 43",
"output": "1060"
},
{
"input": "5\n40 27 82 94 38 22 66 23 18 34 87 31 71 28 95 5 14 61 76 52 66 6 60 40 68 77 70 63 64 18 47 13 82 55 34 64 30 1 29 24 24 9 65 17 29 96 61 76 72 23 32 26 90 39 54 41 35 66 71 29 75 48",
"output": "1063"
},
{
"input": "5\n64 72 35 68 92 95 45 15 77 16 26 74 61 65 18 22 32 19 98 97 14 84 70 23 29 1 87 28 88 89 73 79 69 88 43 60 64 64 66 39 17 27 46 71 18 83 73 20 90 77 49 70 84 63 50 72 26 87 26 37 78 65",
"output": "987"
},
{
"input": "6\n35 61 54 77 70 50 53 70 4 66 58 47 76 100 78 5 43 50 55 93 13 93 59 92 30 74 22 23 98 70 19 56 90 92 19 7 28 53 45 77 42 91 71 56 19 83 100 53 13 93 37 13 70 60 16 13 76 3 12 22 17 26 50 6 63 7 25 41 92 29 36 80 11 4 10 14 77 75 53 82 46 24 56 46 82 36 80 75 8 45 24 22 90 34 45 76 18 38 86 43 7 49 80 56 90 53 12 51 98 47 44 58 32 4 2 6 3 60 38 72 74 46 30 86 1 98",
"output": "2499"
},
{
"input": "6\n63 13 100 54 31 15 29 58 59 44 2 99 70 33 97 14 70 12 73 42 65 71 68 67 87 83 43 84 18 41 37 22 81 24 27 11 57 28 83 92 39 1 56 15 16 67 16 97 31 52 50 65 63 89 8 52 55 20 71 27 28 35 86 92 94 60 10 65 83 63 89 71 34 20 78 40 34 62 2 86 100 81 87 69 25 4 52 17 57 71 62 38 1 3 54 71 34 85 20 60 80 23 82 47 4 19 7 18 14 18 28 27 4 55 26 71 45 9 2 40 67 28 32 19 81 92",
"output": "2465"
},
{
"input": "6\n87 62 58 32 81 92 12 50 23 27 38 39 64 74 16 35 84 59 91 87 14 48 90 47 44 95 64 45 31 11 67 5 80 60 36 15 91 3 21 2 40 24 37 69 5 50 23 37 49 19 68 21 49 9 100 94 45 41 22 31 31 48 25 70 25 25 95 88 82 1 37 53 49 31 57 74 94 45 55 93 43 37 13 85 59 72 15 68 3 90 96 55 100 64 63 69 43 33 66 84 57 97 87 34 23 89 97 77 39 89 8 92 68 13 50 36 95 61 71 96 73 13 30 49 57 89",
"output": "2513"
}
] | 1,431,727,598 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 62 | 0 | n = int(input())
t = 0
tmp = list(map(int, input().split()))
l = 2**(n+1)-1
d = [0]+[0]*(l-1)
for i in range(1, l):
pr = (i-1)//2
d[i] = d[pr]+tmp[i-1]
b = 2**n
c = d[-b:]
m = max(c)
# создали дерево сумм и нашли максимальное кол-во фонарей на пути
v = [0]*b
for i in range(b):
v[i] = m-c[i]
# создали массив разностей
for i in range(n):
pos = 0
for j in range(0, b, 2):
k = min(v[j], v[j+1])
t += max(v[j], v[j+1])-k
v[pos] = k
pos += 1
# перенесли нужное на уровень выше
b //= 2
v = v[:b]
print(t) | Title: Om Nom and Dark Park
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Om Nom is the main character of a game "Cut the Rope". He is a bright little monster who likes visiting friends living at the other side of the park. However the dark old parks can scare even somebody as fearless as Om Nom, so he asks you to help him.
The park consists of 2*n*<=+<=1<=-<=1 squares connected by roads so that the scheme of the park is a full binary tree of depth *n*. More formally, the entrance to the park is located at the square 1. The exits out of the park are located at squares 2*n*,<=2*n*<=+<=1,<=...,<=2*n*<=+<=1<=-<=1 and these exits lead straight to the Om Nom friends' houses. From each square *i* (2<=≤<=*i*<=<<=2*n*<=+<=1) there is a road to the square . Thus, it is possible to go from the park entrance to each of the exits by walking along exactly *n* roads.
Om Nom loves counting lights on the way to his friend. Om Nom is afraid of spiders who live in the park, so he doesn't like to walk along roads that are not enough lit. What he wants is that the way to any of his friends should have in total the same number of lights. That will make him feel safe.
He asked you to help him install additional lights. Determine what minimum number of lights it is needed to additionally place on the park roads so that a path from the entrance to any exit of the park contains the same number of street lights. You may add an arbitrary number of street lights to each of the roads.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=10) — the number of roads on the path from the entrance to any exit.
The next line contains 2*n*<=+<=1<=-<=2 numbers *a*2,<=*a*3,<=... *a*2*n*<=+<=1<=-<=1 — the initial numbers of street lights on each road of the park. Here *a**i* is the number of street lights on the road between squares *i* and . All numbers *a**i* are positive integers, not exceeding 100.
Output Specification:
Print the minimum number of street lights that we should add to the roads of the park to make Om Nom feel safe.
Demo Input:
['2\n1 2 3 4 5 6\n']
Demo Output:
['5\n']
Note:
Picture for the sample test. Green color denotes the additional street lights. | ```python
n = int(input())
t = 0
tmp = list(map(int, input().split()))
l = 2**(n+1)-1
d = [0]+[0]*(l-1)
for i in range(1, l):
pr = (i-1)//2
d[i] = d[pr]+tmp[i-1]
b = 2**n
c = d[-b:]
m = max(c)
# создали дерево сумм и нашли максимальное кол-во фонарей на пути
v = [0]*b
for i in range(b):
v[i] = m-c[i]
# создали массив разностей
for i in range(n):
pos = 0
for j in range(0, b, 2):
k = min(v[j], v[j+1])
t += max(v[j], v[j+1])-k
v[pos] = k
pos += 1
# перенесли нужное на уровень выше
b //= 2
v = v[:b]
print(t)
``` | 3 |
|
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers two squares.
2. No two dominoes overlap.
3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board.
Find the maximum number of dominoes, which can be placed under these restrictions. | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"output": "5"
},
{
"input": "2 6",
"output": "6"
},
{
"input": "2 7",
"output": "7"
},
{
"input": "2 14",
"output": "14"
},
{
"input": "2 15",
"output": "15"
},
{
"input": "1 4",
"output": "2"
},
{
"input": "2 16",
"output": "16"
},
{
"input": "3 5",
"output": "7"
},
{
"input": "3 6",
"output": "9"
},
{
"input": "3 10",
"output": "15"
},
{
"input": "3 14",
"output": "21"
},
{
"input": "3 15",
"output": "22"
},
{
"input": "3 16",
"output": "24"
},
{
"input": "5 7",
"output": "17"
},
{
"input": "16 16",
"output": "128"
},
{
"input": "15 16",
"output": "120"
},
{
"input": "2 3",
"output": "3"
},
{
"input": "15 15",
"output": "112"
},
{
"input": "14 16",
"output": "112"
},
{
"input": "11 13",
"output": "71"
},
{
"input": "5 16",
"output": "40"
},
{
"input": "8 15",
"output": "60"
},
{
"input": "2 2",
"output": "2"
},
{
"input": "3 4",
"output": "6"
},
{
"input": "4 4",
"output": "8"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "1 3",
"output": "1"
},
{
"input": "14 15",
"output": "105"
}
] | 1,621,732,908 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 124 | 0 | m,n = ( int(x) for x in str(input()).split(' ') )
print(int(m*n//2))
| Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers two squares.
2. No two dominoes overlap.
3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board.
Find the maximum number of dominoes, which can be placed under these restrictions.
Input Specification:
In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16).
Output Specification:
Output one number — the maximal number of dominoes, which can be placed.
Demo Input:
['2 4\n', '3 3\n']
Demo Output:
['4\n', '4\n']
Note:
none | ```python
m,n = ( int(x) for x in str(input()).split(' ') )
print(int(m*n//2))
``` | 3.969 |
70 | A | Cookies | PROGRAMMING | 1,300 | [
"math"
] | A. Cookies | 1 | 256 | Fangy collects cookies. Once he decided to take a box and put cookies into it in some way. If we take a square *k*<=×<=*k* in size, divided into blocks 1<=×<=1 in size and paint there the main diagonal together with cells, which lie above it, then the painted area will be equal to the area occupied by one cookie *k* in size. Fangy also has a box with a square base 2*n*<=×<=2*n*, divided into blocks 1<=×<=1 in size. In a box the cookies should not overlap, and they should not be turned over or rotated. See cookies of sizes 2 and 4 respectively on the figure:
To stack the cookies the little walrus uses the following algorithm. He takes out of the repository the largest cookie which can fit in some place in the box and puts it there. Everything could be perfect but alas, in the repository the little walrus has infinitely many cookies of size 2 and larger, and there are no cookies of size 1, therefore, empty cells will remain in the box. Fangy wants to know how many empty cells will be left in the end. | The first line contains a single integer *n* (0<=≤<=*n*<=≤<=1000). | Print the single number, equal to the number of empty cells in the box. The answer should be printed modulo 106<=+<=3. | [
"3\n"
] | [
"9"
] | If the box possesses the base of 2<sup class="upper-index">3</sup> × 2<sup class="upper-index">3</sup> (as in the example), then the cookies will be put there in the following manner: | 500 | [
{
"input": "3",
"output": "9"
},
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "3"
},
{
"input": "4",
"output": "27"
},
{
"input": "6",
"output": "243"
},
{
"input": "11",
"output": "59049"
},
{
"input": "14",
"output": "594320"
},
{
"input": "15",
"output": "782957"
},
{
"input": "7",
"output": "729"
},
{
"input": "0",
"output": "1"
},
{
"input": "1000",
"output": "691074"
},
{
"input": "657",
"output": "874011"
},
{
"input": "561",
"output": "842553"
},
{
"input": "823",
"output": "858672"
},
{
"input": "850",
"output": "557186"
},
{
"input": "298",
"output": "999535"
},
{
"input": "262",
"output": "946384"
},
{
"input": "910",
"output": "678945"
},
{
"input": "617",
"output": "247876"
},
{
"input": "857",
"output": "562128"
},
{
"input": "69",
"output": "327984"
},
{
"input": "589",
"output": "889192"
},
{
"input": "928",
"output": "794863"
},
{
"input": "696",
"output": "695035"
},
{
"input": "226",
"output": "376094"
}
] | 1,510,606,691 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 62 | 0 | res, n = 1, int(input())-1
for i in range(n): res=(res*3)%1000007
print(res) | Title: Cookies
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Fangy collects cookies. Once he decided to take a box and put cookies into it in some way. If we take a square *k*<=×<=*k* in size, divided into blocks 1<=×<=1 in size and paint there the main diagonal together with cells, which lie above it, then the painted area will be equal to the area occupied by one cookie *k* in size. Fangy also has a box with a square base 2*n*<=×<=2*n*, divided into blocks 1<=×<=1 in size. In a box the cookies should not overlap, and they should not be turned over or rotated. See cookies of sizes 2 and 4 respectively on the figure:
To stack the cookies the little walrus uses the following algorithm. He takes out of the repository the largest cookie which can fit in some place in the box and puts it there. Everything could be perfect but alas, in the repository the little walrus has infinitely many cookies of size 2 and larger, and there are no cookies of size 1, therefore, empty cells will remain in the box. Fangy wants to know how many empty cells will be left in the end.
Input Specification:
The first line contains a single integer *n* (0<=≤<=*n*<=≤<=1000).
Output Specification:
Print the single number, equal to the number of empty cells in the box. The answer should be printed modulo 106<=+<=3.
Demo Input:
['3\n']
Demo Output:
['9']
Note:
If the box possesses the base of 2<sup class="upper-index">3</sup> × 2<sup class="upper-index">3</sup> (as in the example), then the cookies will be put there in the following manner: | ```python
res, n = 1, int(input())-1
for i in range(n): res=(res*3)%1000007
print(res)
``` | 0 |
615 | A | Bulbs | PROGRAMMING | 800 | [
"implementation"
] | null | null | Vasya wants to turn on Christmas lights consisting of *m* bulbs. Initially, all bulbs are turned off. There are *n* buttons, each of them is connected to some set of bulbs. Vasya can press any of these buttons. When the button is pressed, it turns on all the bulbs it's connected to. Can Vasya light up all the bulbs?
If Vasya presses the button such that some bulbs connected to it are already turned on, they do not change their state, i.e. remain turned on. | The first line of the input contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of buttons and the number of bulbs respectively.
Each of the next *n* lines contains *x**i* (0<=≤<=*x**i*<=≤<=*m*) — the number of bulbs that are turned on by the *i*-th button, and then *x**i* numbers *y**ij* (1<=≤<=*y**ij*<=≤<=*m*) — the numbers of these bulbs. | If it's possible to turn on all *m* bulbs print "YES", otherwise print "NO". | [
"3 4\n2 1 4\n3 1 3 1\n1 2\n",
"3 3\n1 1\n1 2\n1 1\n"
] | [
"YES\n",
"NO\n"
] | In the first sample you can press each button once and turn on all the bulbs. In the 2 sample it is impossible to turn on the 3-rd lamp. | 500 | [
{
"input": "3 4\n2 1 4\n3 1 3 1\n1 2",
"output": "YES"
},
{
"input": "3 3\n1 1\n1 2\n1 1",
"output": "NO"
},
{
"input": "3 4\n1 1\n1 2\n1 3",
"output": "NO"
},
{
"input": "1 5\n5 1 2 3 4 5",
"output": "YES"
},
{
"input": "1 5\n5 4 4 1 2 3",
"output": "NO"
},
{
"input": "1 5\n5 1 1 1 1 5",
"output": "NO"
},
{
"input": "2 5\n4 3 1 4 2\n4 2 3 4 5",
"output": "YES"
},
{
"input": "5 7\n2 6 7\n5 1 1 1 1 1\n3 6 5 4\n0\n4 4 3 2 1",
"output": "YES"
},
{
"input": "100 100\n0\n0\n0\n1 53\n0\n0\n1 34\n1 54\n0\n1 14\n0\n1 33\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1 82\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1 34\n0\n0\n1 26\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1 34\n0\n0\n0\n0\n0\n1 3\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1 40\n0\n0\n0\n1 26\n0\n0\n0\n0\n0\n1 97\n0\n1 5\n0\n0\n0\n0\n0",
"output": "NO"
},
{
"input": "100 100\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0",
"output": "NO"
},
{
"input": "5 6\n3 1 2 6\n3 1 2 6\n1 1\n2 3 4\n3 1 5 6",
"output": "YES"
},
{
"input": "5 2\n1 1\n1 1\n1 1\n1 1\n1 1",
"output": "NO"
},
{
"input": "1 4\n3 1 2 3",
"output": "NO"
},
{
"input": "1 4\n3 2 3 4",
"output": "NO"
},
{
"input": "2 4\n3 2 3 4\n1 1",
"output": "YES"
},
{
"input": "2 4\n3 1 2 3\n1 4",
"output": "YES"
},
{
"input": "5 1\n0\n0\n0\n0\n0",
"output": "NO"
},
{
"input": "1 1\n0",
"output": "NO"
},
{
"input": "1 10\n10 1 2 3 4 5 6 7 8 9 10",
"output": "YES"
},
{
"input": "1 1\n1 1",
"output": "YES"
},
{
"input": "1 100\n99 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99",
"output": "NO"
},
{
"input": "1 3\n3 1 2 1",
"output": "NO"
},
{
"input": "1 100\n100 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100",
"output": "YES"
}
] | 1,601,268,242 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 124 | 0 | import sys
n,m=map(int,input().split())
l=list()
for _ in range(n):
k=list(map(int,input().split()))
l=l+k
l=set(l)
for i in range(1,m+1):
if i not in l:
print("NO")
sys.exit(0)
print("YES")
| Title: Bulbs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya wants to turn on Christmas lights consisting of *m* bulbs. Initially, all bulbs are turned off. There are *n* buttons, each of them is connected to some set of bulbs. Vasya can press any of these buttons. When the button is pressed, it turns on all the bulbs it's connected to. Can Vasya light up all the bulbs?
If Vasya presses the button such that some bulbs connected to it are already turned on, they do not change their state, i.e. remain turned on.
Input Specification:
The first line of the input contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of buttons and the number of bulbs respectively.
Each of the next *n* lines contains *x**i* (0<=≤<=*x**i*<=≤<=*m*) — the number of bulbs that are turned on by the *i*-th button, and then *x**i* numbers *y**ij* (1<=≤<=*y**ij*<=≤<=*m*) — the numbers of these bulbs.
Output Specification:
If it's possible to turn on all *m* bulbs print "YES", otherwise print "NO".
Demo Input:
['3 4\n2 1 4\n3 1 3 1\n1 2\n', '3 3\n1 1\n1 2\n1 1\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first sample you can press each button once and turn on all the bulbs. In the 2 sample it is impossible to turn on the 3-rd lamp. | ```python
import sys
n,m=map(int,input().split())
l=list()
for _ in range(n):
k=list(map(int,input().split()))
l=l+k
l=set(l)
for i in range(1,m+1):
if i not in l:
print("NO")
sys.exit(0)
print("YES")
``` | 0 |
|
534 | C | Polycarpus' Dice | PROGRAMMING | 1,600 | [
"math"
] | null | null | Polycarp has *n* dice *d*1,<=*d*2,<=...,<=*d**n*. The *i*-th dice shows numbers from 1 to *d**i*. Polycarp rolled all the dice and the sum of numbers they showed is *A*. Agrippina didn't see which dice showed what number, she knows only the sum *A* and the values *d*1,<=*d*2,<=...,<=*d**n*. However, she finds it enough to make a series of statements of the following type: dice *i* couldn't show number *r*. For example, if Polycarp had two six-faced dice and the total sum is *A*<==<=11, then Agrippina can state that each of the two dice couldn't show a value less than five (otherwise, the remaining dice must have a value of at least seven, which is impossible).
For each dice find the number of values for which it can be guaranteed that the dice couldn't show these values if the sum of the shown values is *A*. | The first line contains two integers *n*,<=*A* (1<=≤<=*n*<=≤<=2·105,<=*n*<=≤<=*A*<=≤<=*s*) — the number of dice and the sum of shown values where *s*<==<=*d*1<=+<=*d*2<=+<=...<=+<=*d**n*.
The second line contains *n* integers *d*1,<=*d*2,<=...,<=*d**n* (1<=≤<=*d**i*<=≤<=106), where *d**i* is the maximum value that the *i*-th dice can show. | Print *n* integers *b*1,<=*b*2,<=...,<=*b**n*, where *b**i* is the number of values for which it is guaranteed that the *i*-th dice couldn't show them. | [
"2 8\n4 4\n",
"1 3\n5\n",
"2 3\n2 3\n"
] | [
"3 3 ",
"4 ",
"0 1 "
] | In the first sample from the statement *A* equal to 8 could be obtained in the only case when both the first and the second dice show 4. Correspondingly, both dice couldn't show values 1, 2 or 3.
In the second sample from the statement *A* equal to 3 could be obtained when the single dice shows 3. Correspondingly, it couldn't show 1, 2, 4 or 5.
In the third sample from the statement *A* equal to 3 could be obtained when one dice shows 1 and the other dice shows 2. That's why the first dice doesn't have any values it couldn't show and the second dice couldn't show 3. | 1,500 | [
{
"input": "2 8\n4 4",
"output": "3 3 "
},
{
"input": "1 3\n5",
"output": "4 "
},
{
"input": "2 3\n2 3",
"output": "0 1 "
},
{
"input": "1 1\n3",
"output": "2 "
},
{
"input": "1 2\n3",
"output": "2 "
},
{
"input": "2 2\n2 3",
"output": "1 2 "
},
{
"input": "2 4\n2 3",
"output": "0 1 "
},
{
"input": "3 3\n5 1 5",
"output": "4 0 4 "
},
{
"input": "3 4\n5 1 5",
"output": "3 0 3 "
},
{
"input": "3 5\n5 1 5",
"output": "2 0 2 "
},
{
"input": "3 6\n5 1 5",
"output": "1 0 1 "
},
{
"input": "3 7\n5 1 5",
"output": "0 0 0 "
},
{
"input": "3 8\n5 1 5",
"output": "1 0 1 "
},
{
"input": "3 5\n1 2 100",
"output": "0 0 98 "
},
{
"input": "10 20\n1 1 1 1 5 100 1 1 1 1",
"output": "0 0 0 0 0 95 0 0 0 0 "
},
{
"input": "5 50\n1 1 1 1 1000000",
"output": "0 0 0 0 999999 "
},
{
"input": "5 50\n2 2 2 2 1000000",
"output": "0 0 0 0 999995 "
},
{
"input": "5 50\n10 10 10 10 1000000",
"output": "0 0 0 0 999963 "
},
{
"input": "10 19\n1 5 6 1 6 4 1 2 9 5",
"output": "0 0 0 0 0 0 0 0 0 0 "
},
{
"input": "10 40\n1 5 6 1 6 4 1 2 9 5",
"output": "0 4 5 0 5 3 0 1 8 4 "
},
{
"input": "10 16\n5 7 7 5 9 3 8 5 7 2",
"output": "0 0 0 0 2 0 1 0 0 0 "
},
{
"input": "10 58\n5 7 7 5 9 3 8 5 7 2",
"output": "4 6 6 4 8 2 7 4 6 1 "
},
{
"input": "10 13\n9 9 6 9 10 4 5 10 8 9",
"output": "5 5 2 5 6 0 1 6 4 5 "
},
{
"input": "10 79\n9 9 6 9 10 4 5 10 8 9",
"output": "8 8 5 8 9 3 4 9 7 8 "
},
{
"input": "10 16\n4 1 8 3 3 3 4 3 6 6",
"output": "0 0 1 0 0 0 0 0 0 0 "
},
{
"input": "10 41\n4 1 8 3 3 3 4 3 6 6",
"output": "3 0 7 2 2 2 3 2 5 5 "
},
{
"input": "10 18\n8 1 9 8 4 1 1 8 6 2",
"output": "0 0 0 0 0 0 0 0 0 0 "
},
{
"input": "10 48\n8 1 9 8 4 1 1 8 6 2",
"output": "7 0 8 7 3 0 0 7 5 1 "
},
{
"input": "1 5\n5",
"output": "4 "
}
] | 1,606,409,999 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 186 | 2,048,000 | n,s=input().strip().split(" ")
n,s=[int(n),int(s)]
a=list(map(int,input().strip().split(" ")))
p=s-(n-1)
d=[]
pp=s//n
if s%n:
pp+=1
for j in a:
kp=min(p,j)
if kp-pp<0:
d.append(0)
else:
d.append(kp-pp+1)
ans=0
print(*j) | Title: Polycarpus' Dice
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp has *n* dice *d*1,<=*d*2,<=...,<=*d**n*. The *i*-th dice shows numbers from 1 to *d**i*. Polycarp rolled all the dice and the sum of numbers they showed is *A*. Agrippina didn't see which dice showed what number, she knows only the sum *A* and the values *d*1,<=*d*2,<=...,<=*d**n*. However, she finds it enough to make a series of statements of the following type: dice *i* couldn't show number *r*. For example, if Polycarp had two six-faced dice and the total sum is *A*<==<=11, then Agrippina can state that each of the two dice couldn't show a value less than five (otherwise, the remaining dice must have a value of at least seven, which is impossible).
For each dice find the number of values for which it can be guaranteed that the dice couldn't show these values if the sum of the shown values is *A*.
Input Specification:
The first line contains two integers *n*,<=*A* (1<=≤<=*n*<=≤<=2·105,<=*n*<=≤<=*A*<=≤<=*s*) — the number of dice and the sum of shown values where *s*<==<=*d*1<=+<=*d*2<=+<=...<=+<=*d**n*.
The second line contains *n* integers *d*1,<=*d*2,<=...,<=*d**n* (1<=≤<=*d**i*<=≤<=106), where *d**i* is the maximum value that the *i*-th dice can show.
Output Specification:
Print *n* integers *b*1,<=*b*2,<=...,<=*b**n*, where *b**i* is the number of values for which it is guaranteed that the *i*-th dice couldn't show them.
Demo Input:
['2 8\n4 4\n', '1 3\n5\n', '2 3\n2 3\n']
Demo Output:
['3 3 ', '4 ', '0 1 ']
Note:
In the first sample from the statement *A* equal to 8 could be obtained in the only case when both the first and the second dice show 4. Correspondingly, both dice couldn't show values 1, 2 or 3.
In the second sample from the statement *A* equal to 3 could be obtained when the single dice shows 3. Correspondingly, it couldn't show 1, 2, 4 or 5.
In the third sample from the statement *A* equal to 3 could be obtained when one dice shows 1 and the other dice shows 2. That's why the first dice doesn't have any values it couldn't show and the second dice couldn't show 3. | ```python
n,s=input().strip().split(" ")
n,s=[int(n),int(s)]
a=list(map(int,input().strip().split(" ")))
p=s-(n-1)
d=[]
pp=s//n
if s%n:
pp+=1
for j in a:
kp=min(p,j)
if kp-pp<0:
d.append(0)
else:
d.append(kp-pp+1)
ans=0
print(*j)
``` | -1 |
|
318 | A | Even Odds | PROGRAMMING | 900 | [
"math"
] | null | null | Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first *n*. He writes down the following sequence of numbers: firstly all odd integers from 1 to *n* (in ascending order), then all even integers from 1 to *n* (also in ascending order). Help our hero to find out which number will stand at the position number *k*. | The only line of input contains integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=1012).
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. | Print the number that will stand at the position number *k* after Volodya's manipulations. | [
"10 3\n",
"7 7\n"
] | [
"5",
"6"
] | In the first sample Volodya's sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5. | 500 | [
{
"input": "10 3",
"output": "5"
},
{
"input": "7 7",
"output": "6"
},
{
"input": "7 1",
"output": "1"
},
{
"input": "7 2",
"output": "3"
},
{
"input": "8 5",
"output": "2"
},
{
"input": "8 3",
"output": "5"
},
{
"input": "8 4",
"output": "7"
},
{
"input": "1000000000000 500000000001",
"output": "2"
},
{
"input": "999999999997 499999999999",
"output": "999999999997"
},
{
"input": "999999999999 999999999999",
"output": "999999999998"
},
{
"input": "1000000000000 1",
"output": "1"
},
{
"input": "999999999999 1",
"output": "1"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1000000000000 1000000000000",
"output": "1000000000000"
},
{
"input": "1000000000000 500000000000",
"output": "999999999999"
},
{
"input": "1000000000000 499999999999",
"output": "999999999997"
},
{
"input": "999999999997 499999999998",
"output": "999999999995"
},
{
"input": "619234238 556154835",
"output": "493075432"
},
{
"input": "38151981 36650624",
"output": "35149266"
},
{
"input": "680402465 442571217",
"output": "204739968"
},
{
"input": "109135284 9408714",
"output": "18817427"
},
{
"input": "603701841 56038951",
"output": "112077901"
},
{
"input": "356764822 321510177",
"output": "286255532"
},
{
"input": "284911189 142190783",
"output": "284381565"
},
{
"input": "91028405 61435545",
"output": "31842684"
}
] | 1,699,423,390 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 92 | 0 | n,k = [int(x) for x in input().split()]
z = n / 2 + 0.5
if k <= z:
print(k * 2-1)
else:
print(int((k - z)*2))
| Title: Even Odds
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first *n*. He writes down the following sequence of numbers: firstly all odd integers from 1 to *n* (in ascending order), then all even integers from 1 to *n* (also in ascending order). Help our hero to find out which number will stand at the position number *k*.
Input Specification:
The only line of input contains integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=1012).
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
Output Specification:
Print the number that will stand at the position number *k* after Volodya's manipulations.
Demo Input:
['10 3\n', '7 7\n']
Demo Output:
['5', '6']
Note:
In the first sample Volodya's sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5. | ```python
n,k = [int(x) for x in input().split()]
z = n / 2 + 0.5
if k <= z:
print(k * 2-1)
else:
print(int((k - z)*2))
``` | 0 |
|
1,008 | B | Turn the Rectangles | PROGRAMMING | 1,000 | [
"greedy",
"sortings"
] | null | null | There are $n$ rectangles in a row. You can either turn each rectangle by $90$ degrees or leave it as it is. If you turn a rectangle, its width will be height, and its height will be width. Notice that you can turn any number of rectangles, you also can turn all or none of them. You can not change the order of the rectangles.
Find out if there is a way to make the rectangles go in order of non-ascending height. In other words, after all the turns, a height of every rectangle has to be not greater than the height of the previous rectangle (if it is such). | The first line contains a single integer $n$ ($1 \leq n \leq 10^5$) — the number of rectangles.
Each of the next $n$ lines contains two integers $w_i$ and $h_i$ ($1 \leq w_i, h_i \leq 10^9$) — the width and the height of the $i$-th rectangle. | Print "YES" (without quotes) if there is a way to make the rectangles go in order of non-ascending height, otherwise print "NO".
You can print each letter in any case (upper or lower). | [
"3\n3 4\n4 6\n3 5\n",
"2\n3 4\n5 5\n"
] | [
"YES\n",
"NO\n"
] | In the first test, you can rotate the second and the third rectangles so that the heights will be [4, 4, 3].
In the second test, there is no way the second rectangle will be not higher than the first one. | 1,000 | [
{
"input": "3\n3 4\n4 6\n3 5",
"output": "YES"
},
{
"input": "2\n3 4\n5 5",
"output": "NO"
},
{
"input": "10\n4 3\n1 1\n6 5\n4 5\n2 4\n9 5\n7 9\n9 2\n4 10\n10 1",
"output": "NO"
},
{
"input": "10\n241724251 76314740\n80658193 177743680\n213953908 406274173\n485639518 859188055\n103578427 56645210\n611931853 374099541\n916667853 408945969\n677773241 808703176\n575586508 440395988\n450102404 244301685",
"output": "NO"
},
{
"input": "10\n706794178 103578427\n431808055 641644550\n715688799 406274173\n767234853 345348548\n241724251 408945969\n808703176 213953908\n185314264 16672343\n553496707 152702033\n105991807 76314740\n61409204 244301685",
"output": "YES"
},
{
"input": "1\n1 1",
"output": "YES"
},
{
"input": "4\n10 10\n8 8\n8 15\n9 9",
"output": "NO"
},
{
"input": "4\n10 10\n8 8\n8 9\n9 9",
"output": "NO"
},
{
"input": "3\n3 4\n4 5\n5 5",
"output": "NO"
},
{
"input": "3\n10 10\n5 5\n10 10",
"output": "NO"
},
{
"input": "3\n5 5\n4 6\n5 5",
"output": "NO"
},
{
"input": "3\n5 7\n3 9\n8 10",
"output": "NO"
},
{
"input": "3\n10 10\n1 1\n2 2",
"output": "NO"
},
{
"input": "3\n3 5\n1 2\n3 4",
"output": "NO"
},
{
"input": "3\n4 8\n6 25\n12 12",
"output": "NO"
},
{
"input": "3\n3 5\n4 10\n6 6",
"output": "NO"
},
{
"input": "3\n200 200\n300 20\n50 50",
"output": "NO"
},
{
"input": "3\n5 3\n6 4\n5 5",
"output": "NO"
},
{
"input": "4\n5 5\n4 6\n4 4\n5 5",
"output": "NO"
},
{
"input": "3\n10 10\n1 100\n20 20",
"output": "NO"
},
{
"input": "4\n1 3\n2 4\n3 5\n4 6",
"output": "NO"
},
{
"input": "3\n1 60\n70 55\n56 80",
"output": "NO"
},
{
"input": "3\n5 6\n5 7\n6 8",
"output": "NO"
},
{
"input": "3\n6 6\n5 7\n6 6",
"output": "NO"
}
] | 1,648,844,472 | 2,147,483,647 | Python 3 | OK | TESTS | 53 | 296 | 2,867,200 | t = int(input())
recs = []
for i in range(t):
l = list(map(int, input().split()))
l.sort()
if i != 0:
if recs[i-1] < l[1]:
recs.append(l[0])
else:
recs.append(l[1])
else:
recs.append(l[1])
sortedd = True
for i in range(t-1):
if recs[i] < recs[i+1]:
sortedd = False
if sortedd:
print("YES")
else:
print("NO") | Title: Turn the Rectangles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are $n$ rectangles in a row. You can either turn each rectangle by $90$ degrees or leave it as it is. If you turn a rectangle, its width will be height, and its height will be width. Notice that you can turn any number of rectangles, you also can turn all or none of them. You can not change the order of the rectangles.
Find out if there is a way to make the rectangles go in order of non-ascending height. In other words, after all the turns, a height of every rectangle has to be not greater than the height of the previous rectangle (if it is such).
Input Specification:
The first line contains a single integer $n$ ($1 \leq n \leq 10^5$) — the number of rectangles.
Each of the next $n$ lines contains two integers $w_i$ and $h_i$ ($1 \leq w_i, h_i \leq 10^9$) — the width and the height of the $i$-th rectangle.
Output Specification:
Print "YES" (without quotes) if there is a way to make the rectangles go in order of non-ascending height, otherwise print "NO".
You can print each letter in any case (upper or lower).
Demo Input:
['3\n3 4\n4 6\n3 5\n', '2\n3 4\n5 5\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first test, you can rotate the second and the third rectangles so that the heights will be [4, 4, 3].
In the second test, there is no way the second rectangle will be not higher than the first one. | ```python
t = int(input())
recs = []
for i in range(t):
l = list(map(int, input().split()))
l.sort()
if i != 0:
if recs[i-1] < l[1]:
recs.append(l[0])
else:
recs.append(l[1])
else:
recs.append(l[1])
sortedd = True
for i in range(t-1):
if recs[i] < recs[i+1]:
sortedd = False
if sortedd:
print("YES")
else:
print("NO")
``` | 3 |
|
887 | B | Cubes for Masha | PROGRAMMING | 1,300 | [
"brute force",
"implementation"
] | null | null | Absent-minded Masha got set of *n* cubes for her birthday.
At each of 6 faces of each cube, there is exactly one digit from 0 to 9. Masha became interested what is the largest natural *x* such she can make using her new cubes all integers from 1 to *x*.
To make a number Masha can rotate her cubes and put them in a row. After that, she looks at upper faces of cubes from left to right and reads the number.
The number can't contain leading zeros. It's not required to use all cubes to build a number.
Pay attention: Masha can't make digit 6 from digit 9 and vice-versa using cube rotations. | In first line integer *n* is given (1<=≤<=*n*<=≤<=3) — the number of cubes, Masha got for her birthday.
Each of next *n* lines contains 6 integers *a**i**j* (0<=≤<=*a**i**j*<=≤<=9) — number on *j*-th face of *i*-th cube. | Print single integer — maximum number *x* such Masha can make any integers from 1 to *x* using her cubes or 0 if Masha can't make even 1. | [
"3\n0 1 2 3 4 5\n6 7 8 9 0 1\n2 3 4 5 6 7\n",
"3\n0 1 3 5 6 8\n1 2 4 5 7 8\n2 3 4 6 7 9\n"
] | [
"87",
"98"
] | In the first test case, Masha can build all numbers from 1 to 87, but she can't make 88 because there are no two cubes with digit 8. | 1,000 | [
{
"input": "3\n0 1 2 3 4 5\n6 7 8 9 0 1\n2 3 4 5 6 7",
"output": "87"
},
{
"input": "3\n0 1 3 5 6 8\n1 2 4 5 7 8\n2 3 4 6 7 9",
"output": "98"
},
{
"input": "3\n0 1 2 3 4 5\n0 1 2 3 4 5\n0 1 2 3 4 5",
"output": "5"
},
{
"input": "3\n1 2 3 7 8 9\n9 8 7 1 2 3\n7 9 2 3 1 8",
"output": "3"
},
{
"input": "1\n5 2 2 5 6 7",
"output": "0"
},
{
"input": "1\n7 6 5 8 9 0",
"output": "0"
},
{
"input": "1\n2 5 9 6 7 9",
"output": "0"
},
{
"input": "1\n6 3 1 9 4 9",
"output": "1"
},
{
"input": "1\n1 9 8 3 7 8",
"output": "1"
},
{
"input": "2\n1 7 2 0 4 3\n5 2 3 6 1 0",
"output": "7"
},
{
"input": "2\n6 0 1 7 2 9\n1 3 4 6 7 0",
"output": "4"
},
{
"input": "2\n8 6 4 1 2 0\n7 8 5 3 2 1",
"output": "8"
},
{
"input": "2\n0 8 6 2 1 3\n5 2 7 1 0 9",
"output": "3"
},
{
"input": "2\n0 9 5 7 6 2\n8 6 2 7 1 4",
"output": "2"
},
{
"input": "3\n5 0 7 6 2 1\n2 7 4 6 1 9\n0 2 6 1 7 5",
"output": "2"
},
{
"input": "3\n0 6 2 9 5 4\n3 8 0 1 6 9\n6 9 0 1 5 2",
"output": "6"
},
{
"input": "3\n5 6 2 9 3 5\n5 4 1 5 9 8\n4 4 2 0 3 5",
"output": "6"
},
{
"input": "3\n0 1 9 1 0 8\n9 9 3 5 6 2\n9 3 9 9 7 3",
"output": "3"
},
{
"input": "3\n2 5 7 4 2 7\n1 5 5 9 0 3\n8 2 0 1 5 1",
"output": "5"
},
{
"input": "1\n4 6 9 8 2 7",
"output": "0"
},
{
"input": "1\n5 3 8 0 2 6",
"output": "0"
},
{
"input": "1\n7 9 5 0 4 6",
"output": "0"
},
{
"input": "1\n4 0 9 6 3 1",
"output": "1"
},
{
"input": "1\n7 9 2 5 0 4",
"output": "0"
},
{
"input": "1\n0 7 6 3 2 4",
"output": "0"
},
{
"input": "1\n9 8 1 6 5 7",
"output": "1"
},
{
"input": "1\n7 3 6 9 8 1",
"output": "1"
},
{
"input": "1\n3 9 1 7 4 5",
"output": "1"
},
{
"input": "1\n8 6 0 9 4 2",
"output": "0"
},
{
"input": "1\n8 2 7 4 1 0",
"output": "2"
},
{
"input": "1\n8 3 5 4 2 9",
"output": "0"
},
{
"input": "1\n0 8 7 1 3 2",
"output": "3"
},
{
"input": "1\n6 2 8 5 1 3",
"output": "3"
},
{
"input": "1\n6 0 7 5 4 8",
"output": "0"
},
{
"input": "1\n6 2 8 4 5 1",
"output": "2"
},
{
"input": "1\n4 3 8 9 2 3",
"output": "0"
},
{
"input": "1\n8 1 9 2 9 7",
"output": "2"
},
{
"input": "1\n3 7 7 6 4 2",
"output": "0"
},
{
"input": "1\n1 4 5 7 0 5",
"output": "1"
},
{
"input": "2\n6 6 4 7 9 0\n2 1 2 8 6 4",
"output": "2"
},
{
"input": "2\n5 3 2 9 8 2\n0 7 4 8 1 8",
"output": "5"
},
{
"input": "2\n5 7 4 2 1 9\n2 2 7 1 1 8",
"output": "2"
},
{
"input": "2\n9 3 3 6 7 2\n6 2 9 1 5 9",
"output": "3"
},
{
"input": "2\n2 0 5 7 0 8\n4 5 1 5 4 9",
"output": "2"
},
{
"input": "2\n2 6 8 1 3 1\n2 1 3 8 6 7",
"output": "3"
},
{
"input": "2\n4 3 8 6 0 1\n4 7 1 8 9 0",
"output": "1"
},
{
"input": "2\n0 2 9 1 8 5\n0 7 4 3 2 5",
"output": "5"
},
{
"input": "2\n1 7 6 9 2 5\n1 6 7 0 9 2",
"output": "2"
},
{
"input": "2\n0 2 9 8 1 7\n6 7 4 3 2 5",
"output": "9"
},
{
"input": "2\n3 6 8 9 5 0\n6 7 0 8 2 3",
"output": "0"
},
{
"input": "2\n5 1 2 3 0 8\n3 6 7 4 9 2",
"output": "9"
},
{
"input": "2\n7 8 6 1 4 5\n8 6 4 3 2 5",
"output": "8"
},
{
"input": "2\n2 3 5 1 9 6\n1 6 8 7 3 9",
"output": "3"
},
{
"input": "2\n1 7 8 6 0 9\n3 2 1 7 4 9",
"output": "4"
},
{
"input": "2\n2 4 0 3 7 6\n3 2 8 7 1 5",
"output": "8"
},
{
"input": "2\n6 5 2 7 1 3\n3 7 8 1 0 9",
"output": "3"
},
{
"input": "2\n5 8 4 7 1 2\n0 8 6 2 4 9",
"output": "2"
},
{
"input": "2\n8 0 6 5 1 4\n7 1 0 8 3 4",
"output": "1"
},
{
"input": "2\n2 3 9 1 6 7\n2 5 4 3 0 6",
"output": "7"
},
{
"input": "3\n9 4 3 0 2 6\n7 0 5 3 3 9\n1 0 7 4 6 7",
"output": "7"
},
{
"input": "3\n3 8 5 1 5 5\n1 5 7 2 6 9\n4 3 4 8 8 9",
"output": "9"
},
{
"input": "3\n7 7 2 5 3 2\n3 0 0 6 4 4\n1 2 1 1 9 1",
"output": "7"
},
{
"input": "3\n8 1 6 8 6 8\n7 0 2 5 8 4\n5 2 0 3 1 9",
"output": "32"
},
{
"input": "3\n2 7 4 0 7 1\n5 5 4 9 1 4\n2 1 7 5 1 7",
"output": "2"
},
{
"input": "3\n4 4 5 0 6 6\n7 1 6 9 5 4\n5 0 4 0 3 9",
"output": "1"
},
{
"input": "3\n9 4 3 3 9 3\n1 0 3 4 5 3\n2 9 6 2 4 1",
"output": "6"
},
{
"input": "3\n3 8 3 5 5 5\n3 0 1 6 6 3\n0 4 3 7 2 4",
"output": "8"
},
{
"input": "3\n4 1 0 8 0 2\n1 5 3 5 0 7\n7 7 2 7 2 2",
"output": "5"
},
{
"input": "3\n8 1 8 2 7 1\n9 1 9 9 4 7\n0 0 9 0 4 0",
"output": "2"
},
{
"input": "3\n4 6 0 3 9 2\n8 6 9 0 7 2\n6 9 3 2 5 7",
"output": "0"
},
{
"input": "3\n5 1 2 9 6 4\n9 0 6 4 2 8\n4 6 2 8 3 7",
"output": "10"
},
{
"input": "3\n9 3 1 8 4 6\n6 9 1 2 0 7\n8 9 1 5 0 3",
"output": "21"
},
{
"input": "3\n7 1 3 0 2 4\n2 4 3 0 9 5\n1 9 8 0 6 5",
"output": "65"
},
{
"input": "3\n9 4 6 2 7 0\n3 7 1 9 6 4\n6 1 0 8 7 2",
"output": "4"
},
{
"input": "3\n2 7 3 6 4 5\n0 2 1 9 4 8\n8 6 9 5 4 0",
"output": "10"
},
{
"input": "3\n2 6 3 7 1 0\n9 1 2 4 7 6\n1 4 8 7 6 2",
"output": "4"
},
{
"input": "3\n5 4 8 1 6 7\n0 9 3 5 8 6\n2 4 7 8 1 3",
"output": "21"
},
{
"input": "3\n7 2 1 3 6 9\n0 3 8 4 7 6\n1 4 5 8 7 0",
"output": "21"
},
{
"input": "3\n8 6 0 5 4 9\n1 8 5 3 9 7\n7 4 5 1 6 8",
"output": "1"
},
{
"input": "1\n0 1 2 3 4 5",
"output": "5"
},
{
"input": "3\n0 1 1 2 2 3\n4 5 6 7 8 9\n3 4 5 6 7 8",
"output": "9"
},
{
"input": "2\n0 1 2 3 4 5\n6 7 8 9 1 2",
"output": "29"
},
{
"input": "3\n0 1 2 3 4 5\n6 7 8 9 1 2\n3 4 5 6 7 8",
"output": "98"
},
{
"input": "3\n0 1 1 2 2 3\n4 5 6 7 8 9\n3 4 5 6 7 1",
"output": "19"
},
{
"input": "2\n0 1 2 3 4 5\n6 7 8 9 6 6",
"output": "9"
},
{
"input": "2\n0 1 2 3 4 5\n4 5 6 7 8 9",
"output": "9"
},
{
"input": "2\n1 8 9 1 1 0\n2 3 4 5 6 7",
"output": "9"
},
{
"input": "2\n0 1 2 3 4 5\n9 8 7 6 5 4",
"output": "9"
},
{
"input": "3\n2 3 4 5 6 7\n3 4 5 6 7 8\n9 1 2 3 4 5",
"output": "9"
},
{
"input": "3\n1 1 2 3 4 5\n6 7 8 9 0 2\n3 4 5 6 7 8",
"output": "10"
},
{
"input": "3\n1 1 1 0 2 3\n4 5 6 7 8 9\n0 0 0 0 0 0",
"output": "10"
},
{
"input": "3\n0 1 2 2 4 5\n6 7 8 9 0 1\n3 3 4 5 6 7",
"output": "21"
},
{
"input": "3\n2 0 1 3 4 5\n6 7 8 9 1 1\n3 4 5 6 6 7",
"output": "19"
},
{
"input": "3\n1 1 1 1 1 1\n0 2 3 4 5 6\n7 8 9 2 3 4",
"output": "10"
},
{
"input": "2\n0 1 2 3 4 5\n6 6 6 7 8 9",
"output": "9"
},
{
"input": "3\n3 4 5 6 8 9\n1 1 1 1 1 1\n1 2 4 5 7 0",
"output": "19"
}
] | 1,509,746,478 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 48 | 62 | 0 | n = int(input())
cubes = [[int(elem) for elem in input().strip().split(' ')] for i in range(n)]
def f(cubes):
dic = {}
pos = {}
for i in range(n):
for j, elem in enumerate(cubes[i]):
if elem in dic:
dic[elem] += 1
pos[elem].add((j, ))
else:
dic[elem] = 1
pos[elem] = set((j, ))
for i in range(1, 10):
if not i in dic:
return i - 1
if not 0 in dic:
return 9
for i in range(1, 10):
for j in range(10):
if len(pos[i].union(pos[j])) == 1:
return 10 * i + j - 1
print(f(cubes))
| Title: Cubes for Masha
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Absent-minded Masha got set of *n* cubes for her birthday.
At each of 6 faces of each cube, there is exactly one digit from 0 to 9. Masha became interested what is the largest natural *x* such she can make using her new cubes all integers from 1 to *x*.
To make a number Masha can rotate her cubes and put them in a row. After that, she looks at upper faces of cubes from left to right and reads the number.
The number can't contain leading zeros. It's not required to use all cubes to build a number.
Pay attention: Masha can't make digit 6 from digit 9 and vice-versa using cube rotations.
Input Specification:
In first line integer *n* is given (1<=≤<=*n*<=≤<=3) — the number of cubes, Masha got for her birthday.
Each of next *n* lines contains 6 integers *a**i**j* (0<=≤<=*a**i**j*<=≤<=9) — number on *j*-th face of *i*-th cube.
Output Specification:
Print single integer — maximum number *x* such Masha can make any integers from 1 to *x* using her cubes or 0 if Masha can't make even 1.
Demo Input:
['3\n0 1 2 3 4 5\n6 7 8 9 0 1\n2 3 4 5 6 7\n', '3\n0 1 3 5 6 8\n1 2 4 5 7 8\n2 3 4 6 7 9\n']
Demo Output:
['87', '98']
Note:
In the first test case, Masha can build all numbers from 1 to 87, but she can't make 88 because there are no two cubes with digit 8. | ```python
n = int(input())
cubes = [[int(elem) for elem in input().strip().split(' ')] for i in range(n)]
def f(cubes):
dic = {}
pos = {}
for i in range(n):
for j, elem in enumerate(cubes[i]):
if elem in dic:
dic[elem] += 1
pos[elem].add((j, ))
else:
dic[elem] = 1
pos[elem] = set((j, ))
for i in range(1, 10):
if not i in dic:
return i - 1
if not 0 in dic:
return 9
for i in range(1, 10):
for j in range(10):
if len(pos[i].union(pos[j])) == 1:
return 10 * i + j - 1
print(f(cubes))
``` | 0 |
|
439 | A | Devu, the Singer and Churu, the Joker | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invited.
Devu has provided organizers a list of the songs and required time for singing them. He will sing *n* songs, *i**th* song will take *t**i* minutes exactly.
The Comedian, Churu will crack jokes. All his jokes are of 5 minutes exactly.
People have mainly come to listen Devu. But you know that he needs rest of 10 minutes after each song. On the other hand, Churu being a very active person, doesn't need any rest.
You as one of the organizers should make an optimal sсhedule for the event. For some reasons you must follow the conditions:
- The duration of the event must be no more than *d* minutes; - Devu must complete all his songs; - With satisfying the two previous conditions the number of jokes cracked by Churu should be as many as possible.
If it is not possible to find a way to conduct all the songs of the Devu, output -1. Otherwise find out maximum number of jokes that Churu can crack in the grand event. | The first line contains two space separated integers *n*, *d* (1<=≤<=*n*<=≤<=100; 1<=≤<=*d*<=≤<=10000). The second line contains *n* space-separated integers: *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=100). | If there is no way to conduct all the songs of Devu, output -1. Otherwise output the maximum number of jokes that Churu can crack in the grand event. | [
"3 30\n2 2 1\n",
"3 20\n2 1 1\n"
] | [
"5\n",
"-1\n"
] | Consider the first example. The duration of the event is 30 minutes. There could be maximum 5 jokes in the following way:
- First Churu cracks a joke in 5 minutes. - Then Devu performs the first song for 2 minutes. - Then Churu cracks 2 jokes in 10 minutes. - Now Devu performs second song for 2 minutes. - Then Churu cracks 2 jokes in 10 minutes. - Now finally Devu will perform his last song in 1 minutes.
Total time spent is 5 + 2 + 10 + 2 + 10 + 1 = 30 minutes.
Consider the second example. There is no way of organizing Devu's all songs. Hence the answer is -1. | 500 | [
{
"input": "3 30\n2 2 1",
"output": "5"
},
{
"input": "3 20\n2 1 1",
"output": "-1"
},
{
"input": "50 10000\n5 4 10 9 9 6 7 7 7 3 3 7 7 4 7 4 10 10 1 7 10 3 1 4 5 7 2 10 10 10 2 3 4 7 6 1 8 4 7 3 8 8 4 10 1 1 9 2 6 1",
"output": "1943"
},
{
"input": "50 10000\n4 7 15 9 11 12 20 9 14 14 10 13 6 13 14 17 6 8 20 12 10 15 13 17 5 12 13 11 7 5 5 2 3 15 13 7 14 14 19 2 13 14 5 15 3 19 15 16 4 1",
"output": "1891"
},
{
"input": "100 9000\n5 2 3 1 1 3 4 9 9 6 7 10 10 10 2 10 6 8 8 6 7 9 9 5 6 2 1 10 10 9 4 5 9 2 4 3 8 5 6 1 1 5 3 6 2 6 6 6 5 8 3 6 7 3 1 10 9 1 8 3 10 9 5 6 3 4 1 1 10 10 2 3 4 8 10 10 5 1 5 3 6 8 10 6 10 2 1 8 10 1 7 6 9 10 5 2 3 5 3 2",
"output": "1688"
},
{
"input": "100 8007\n5 19 14 18 9 6 15 8 1 14 11 20 3 17 7 12 2 6 3 17 7 20 1 14 20 17 2 10 13 7 18 18 9 10 16 8 1 11 11 9 13 18 9 20 12 12 7 15 12 17 11 5 11 15 9 2 15 1 18 3 18 16 15 4 10 5 18 13 13 12 3 8 17 2 12 2 13 3 1 13 2 4 9 10 18 10 14 4 4 17 12 19 2 9 6 5 5 20 18 12",
"output": "1391"
},
{
"input": "39 2412\n1 1 1 1 1 1 26 1 1 1 99 1 1 1 1 1 1 1 1 1 1 88 7 1 1 1 1 76 1 1 1 93 40 1 13 1 68 1 32",
"output": "368"
},
{
"input": "39 2617\n47 1 1 1 63 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 70 1 99 63 1 1 1 1 1 1 1 1 64 1 1",
"output": "435"
},
{
"input": "39 3681\n83 77 1 94 85 47 1 98 29 16 1 1 1 71 96 85 31 97 96 93 40 50 98 1 60 51 1 96 100 72 1 1 1 89 1 93 1 92 100",
"output": "326"
},
{
"input": "45 894\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 28 28 1 1 1 1 1 1 1 1 1 1 1 1 1 1 99 3 1 1",
"output": "139"
},
{
"input": "45 4534\n1 99 65 99 4 46 54 80 51 30 96 1 28 30 44 70 78 1 1 100 1 62 1 1 1 85 1 1 1 61 1 46 75 1 61 77 97 26 67 1 1 63 81 85 86",
"output": "514"
},
{
"input": "72 3538\n52 1 8 1 1 1 7 1 1 1 1 48 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 40 1 1 38 1 1 1 1 1 1 1 1 1 1 1 35 1 93 79 1 1 1 1 1 1 1 1 1 51 1 1 1 1 1 1 1 1 1 1 1 1 96 1",
"output": "586"
},
{
"input": "81 2200\n1 59 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 93 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 50 1 1 1 1 1 1 1 1 1 1 1",
"output": "384"
},
{
"input": "81 2577\n85 91 1 1 2 1 1 100 1 80 1 1 17 86 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 37 1 66 24 1 1 96 49 1 66 1 44 1 1 1 1 98 1 1 1 1 35 1 37 3 35 1 1 87 64 1 24 1 58 1 1 42 83 5 1 1 1 1 1 95 1 94 1 50 1 1",
"output": "174"
},
{
"input": "81 4131\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 16 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "807"
},
{
"input": "81 6315\n1 1 67 100 1 99 36 1 92 5 1 96 42 12 1 57 91 1 1 66 41 30 74 95 1 37 1 39 91 69 1 52 77 47 65 1 1 93 96 74 90 35 85 76 71 92 92 1 1 67 92 74 1 1 86 76 35 1 56 16 27 57 37 95 1 40 20 100 51 1 80 60 45 79 95 1 46 1 25 100 96",
"output": "490"
},
{
"input": "96 1688\n1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 45 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 25 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 71 1 1 1 30 1 1 1",
"output": "284"
},
{
"input": "96 8889\n1 1 18 1 1 1 1 1 1 1 1 1 99 1 1 1 1 88 1 45 1 1 1 1 1 1 1 1 1 1 1 1 1 1 96 1 1 1 1 21 1 1 1 1 1 1 1 73 1 1 1 1 1 10 1 1 1 1 1 1 1 46 43 1 1 1 1 1 98 1 1 1 1 1 1 6 1 1 1 1 1 74 1 25 1 55 1 1 1 13 1 1 54 1 1 1",
"output": "1589"
},
{
"input": "10 100\n1 1 1 1 1 1 1 1 1 1",
"output": "18"
},
{
"input": "100 10000\n54 46 72 94 79 83 91 54 73 3 24 55 54 31 28 20 19 6 25 19 47 23 1 70 15 87 51 39 54 77 55 5 60 3 15 99 56 88 22 78 79 21 38 27 28 86 7 88 12 59 55 70 25 1 70 49 1 45 69 72 50 17 4 56 8 100 90 34 35 20 61 76 88 79 4 74 65 68 75 26 40 72 59 94 10 67 96 85 29 90 47 24 44 1 66 93 55 36 1 99",
"output": "1017"
},
{
"input": "100 6000\n41 31 23 17 24 78 26 96 93 48 46 2 49 33 35 9 73 100 34 48 83 36 33 69 43 24 3 74 8 81 27 33 94 38 77 9 76 90 62 90 21 67 22 22 12 2 17 27 61 18 72 85 59 65 71 38 90 75 74 66 60 47 58 50 90 95 75 10 5 100 97 29 83 88 65 26 93 90 22 98 36 55 70 38 50 92 88 72 99 96 25 14 74 16 25 92 67 94 77 96",
"output": "-1"
},
{
"input": "1 1\n1",
"output": "0"
},
{
"input": "1 6\n1",
"output": "1"
},
{
"input": "1 5\n1",
"output": "0"
},
{
"input": "1 3\n4",
"output": "-1"
},
{
"input": "3 24\n2 1 2",
"output": "-1"
}
] | 1,611,152,742 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 20 | 93 | 0 |
#n songs
# d limit
# t = minutes for n songs
n,d = map(int,input().split())
t = list(map(int,input().split()))
if((n-1)*10<d):
s = sum(t)
dif = d-s
print(dif//5)
else:
print(-1)
| Title: Devu, the Singer and Churu, the Joker
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invited.
Devu has provided organizers a list of the songs and required time for singing them. He will sing *n* songs, *i**th* song will take *t**i* minutes exactly.
The Comedian, Churu will crack jokes. All his jokes are of 5 minutes exactly.
People have mainly come to listen Devu. But you know that he needs rest of 10 minutes after each song. On the other hand, Churu being a very active person, doesn't need any rest.
You as one of the organizers should make an optimal sсhedule for the event. For some reasons you must follow the conditions:
- The duration of the event must be no more than *d* minutes; - Devu must complete all his songs; - With satisfying the two previous conditions the number of jokes cracked by Churu should be as many as possible.
If it is not possible to find a way to conduct all the songs of the Devu, output -1. Otherwise find out maximum number of jokes that Churu can crack in the grand event.
Input Specification:
The first line contains two space separated integers *n*, *d* (1<=≤<=*n*<=≤<=100; 1<=≤<=*d*<=≤<=10000). The second line contains *n* space-separated integers: *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=100).
Output Specification:
If there is no way to conduct all the songs of Devu, output -1. Otherwise output the maximum number of jokes that Churu can crack in the grand event.
Demo Input:
['3 30\n2 2 1\n', '3 20\n2 1 1\n']
Demo Output:
['5\n', '-1\n']
Note:
Consider the first example. The duration of the event is 30 minutes. There could be maximum 5 jokes in the following way:
- First Churu cracks a joke in 5 minutes. - Then Devu performs the first song for 2 minutes. - Then Churu cracks 2 jokes in 10 minutes. - Now Devu performs second song for 2 minutes. - Then Churu cracks 2 jokes in 10 minutes. - Now finally Devu will perform his last song in 1 minutes.
Total time spent is 5 + 2 + 10 + 2 + 10 + 1 = 30 minutes.
Consider the second example. There is no way of organizing Devu's all songs. Hence the answer is -1. | ```python
#n songs
# d limit
# t = minutes for n songs
n,d = map(int,input().split())
t = list(map(int,input().split()))
if((n-1)*10<d):
s = sum(t)
dif = d-s
print(dif//5)
else:
print(-1)
``` | 0 |
|
746 | B | Decoding | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | Polycarp is mad about coding, that is why he writes Sveta encoded messages. He calls the median letter in a word the letter which is in the middle of the word. If the word's length is even, the median letter is the left of the two middle letters. In the following examples, the median letter is highlighted: contest, info. If the word consists of single letter, then according to above definition this letter is the median letter.
Polycarp encodes each word in the following way: he writes down the median letter of the word, then deletes it and repeats the process until there are no letters left. For example, he encodes the word volga as logva.
You are given an encoding *s* of some word, your task is to decode it. | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=2000) — the length of the encoded word.
The second line contains the string *s* of length *n* consisting of lowercase English letters — the encoding. | Print the word that Polycarp encoded. | [
"5\nlogva\n",
"2\nno\n",
"4\nabba\n"
] | [
"volga\n",
"no\n",
"baba\n"
] | In the first example Polycarp encoded the word volga. At first, he wrote down the letter l from the position 3, after that his word looked like voga. After that Polycarp wrote down the letter o from the position 2, his word became vga. Then Polycarp wrote down the letter g which was at the second position, the word became va. Then he wrote down the letter v, then the letter a. Thus, the encoding looked like logva.
In the second example Polycarp encoded the word no. He wrote down the letter n, the word became o, and he wrote down the letter o. Thus, in this example, the word and its encoding are the same.
In the third example Polycarp encoded the word baba. At first, he wrote down the letter a, which was at the position 2, after that the word looked like bba. Then he wrote down the letter b, which was at the position 2, his word looked like ba. After that he wrote down the letter b, which was at the position 1, the word looked like a, and he wrote down that letter a. Thus, the encoding is abba. | 1,000 | [
{
"input": "5\nlogva",
"output": "volga"
},
{
"input": "2\nno",
"output": "no"
},
{
"input": "4\nabba",
"output": "baba"
},
{
"input": "51\nkfsmpaeviowvkdbuhdagquxxqniselafnfbrgbhmsugcbbnlrvv",
"output": "vlbcumbrfflsnxugdudvovamfkspeiwkbhaqxqieanbghsgbnrv"
},
{
"input": "1\nw",
"output": "w"
},
{
"input": "2\ncb",
"output": "cb"
},
{
"input": "3\nqok",
"output": "oqk"
},
{
"input": "4\naegi",
"output": "gaei"
},
{
"input": "5\noqquy",
"output": "uqoqy"
},
{
"input": "6\nulhpnm",
"output": "nhulpm"
},
{
"input": "7\nijvxljt",
"output": "jxjivlt"
},
{
"input": "8\nwwmiwkeo",
"output": "ewmwwiko"
},
{
"input": "9\ngmwqmpfow",
"output": "opqmgwmfw"
},
{
"input": "10\nhncmexsslh",
"output": "lsechnmxsh"
},
{
"input": "20\nrtcjbjlbtjfmvzdqutuw",
"output": "uudvftlbcrtjjbjmzqtw"
},
{
"input": "21\ngjyiqoebcnpsdegxnsauh",
"output": "usxesnboijgyqecpdgnah"
},
{
"input": "30\nudotcwvcwxajkadxqvxvwgmwmnqrby",
"output": "bqmmwxqdkawvcoudtwcxjaxvvgwnry"
},
{
"input": "31\nipgfrxxcgckksfgexlicjvtnhvrfbmb",
"output": "mfvnvclefkccxfpigrxgksgxijthrbb"
},
{
"input": "50\nwobervhvvkihcuyjtmqhaaigvahheoqleromusrartldojsjvy",
"output": "vsolrruoeqehviaqtycivhrbwoevvkhujmhagaholrmsatdjjy"
},
{
"input": "200\nhvayscqiwpcfykibwyudkzuzdkgqqvbnrfeupjefevlvojngmlcjwzijrkzbsaovabkvvwmjgoonyhuiphwmqdoiuueuyqtychbsklflnvghipdgaxhuhiiqlqocpvhldgvnsrtcwxpidrjffwvwcirluyyxzxrglheczeuouklzkvnyubsvgvmdbrylimztotdbmjph",
"output": "pmdoziybmgsunkluuzelrzyurcvfjdpwtsvdhpolihhadignfkbctyeuoqwpuyogmvkaoszriwcmnoleeperbqgdukuwiycwqsahvycipfkbydzzkqvnfujfvvjgljzjkbavbvwjonhihmdiuuqyhsllvhpgxuiqqcvlgnrcxirfwwilyxxghceokzvybvvdrlmttbjh"
},
{
"input": "201\nrpkghhfibtmlkpdiklegblbuyshfirheatjkfoqkfayfbxeeqijwqdwkkrkbdxlhzkhyiifemsghwovorlqedngldskfbhmwrnzmtjuckxoqdszmsdnbuqnlqzswdfhagasmfswanifrjjcuwdsplytvmnfarchgqteedgfpumkssindxndliozojzlpznwedodzwrrus",
"output": "urzoenpzoolndismpgetgcanvypdujriasmaafwzlqbdmsqxcjmnwhfslneloohseiykhxbrkdwiexfakokterfsulglipltihgprkhfbmkdkebbyhihajfqfybeqjqwkkdlzhifmgwvrqdgdkbmrztukodzsnunqsdhgsfwnfjcwsltmfrhqedfuksnxdizjlzwddwrs"
},
{
"input": "500\naopxumqciwxewxvlxzebsztskjvjzwyewjztqrsuvamtvklhqrbodtncqdchjrlpywvmtgnkkwtvpggktewdgvnhydkexwoxkgltaesrtifbwpciqsvrgjtqrdnyqkgqwrryacluaqmgdwxinqieiblolyekcbzahlhxdwqcgieyfgmicvgbbitbzhejkshjunzjteyyfngigjwyqqndtjrdykzrnrpinkwtrlchhxvycrhstpecadszilicrqdeyyidohqvzfnsqfyuemigacysxvtrgxyjcvejkjstsnatfqlkeytxgsksgpcooypsmqgcluzwofaupegxppbupvtumjerohdteuenwcmqaoazohkilgpkjavcrjcslhzkyjcgfzxxzjfufichxcodcawonkxhbqgfimmlycswdzwbnmjwhbwihfoftpcqplncavmbxuwnsabiyvpcrhfgtqyaguoaigknushbqjwqmmyvsxwabrub",
"output": "ubwsymwqhukiogytfrpybswxmanpctohwhjnwdsymigbxnwcoxcffzxfcyzlcrvjplkoaamweedoemtpbpgpaozlgmpocgkgtelfasskecygtxyaieyqnzqoiydriisaethcvhcrwnpnzyrtnqwggfytzuhkeztbgcmfegqdhhzcelliinxdmalarwgqnrtgvqcwftsalkoxkyngwtgptkntvyljcqndbqlvmvsqzwyzvktsexvwxiqupaoxmcwexlzbzsjjwejtruatkhrotcdhrpwmgkwvgkedvhdewxgteribpisrjqdykqrycuqgwiqeboykbalxwciygivbibhjsjnjeynijyqdjdkrriktlhxyrspcdzlcqeydhvfsfumgcsvrxjvjjtntqkyxsspoysqcuwfuexpuvujrhtuncqozhigkacjshkjgzxjuihcdaokhqfmlcwzbmwbiffpqlcvbunaivchgqauagnsbjqmvxarb"
},
{
"input": "501\noilesjbgowlnayckhpoaitijewsyhgavnthycaecwnvzpxgjqfjyxnjcjknvvsmjbjwtcoyfbegmnnheeamvtfjkigqoanhvgdfrjchdqgowrstlmrjmcsuuwvvoeucfyhnxivosrxblfoqwikfxjnnyejdiihpenfcahtjwcnzwvxxseicvdfgqhtvefswznuyohmmljlnxubhevywpmnitnkhecsgccpstxkmdzabsnwxkokdfsogzbpnfvgudvqlstxojzfzugxbfrozveaiofrzksegdelxsdhcjlqwqlgjcqiujptoenxozhkqhcpkarretqzfkwuvbmfdcdoqliyzmlfrfhzrnkbhofuctkpeacqejwvdrlyvepudrlzncbhwrgmxrczphsoymvtuzqjscvbtqpymogupgzctepccravjcrfsadueyraqvwasravkubebojqspdntewnjohvccamvoxdauyakvehjhabpdyzyme",
"output": "mzdbhhvaudomcvonenpqoeuvravayuafcvrcecguoyqbcjztmohzrmrhczrueyrvjqaptuobnzffmylocfbukztraphkzxetjicgqqjhsldekroavofxufjxsqdgfpzofkkwsadktpcsektnpyebxllmouzsetqfvisxwnwtafehijynxkwolxsvxhfuovusmrlswgdcrdvnogkfvaenmefotjjsvkcnyfjxzncaytvgywjtapkynwgjeiolsbolachoiieshanhcewvpgqjxjjnvmbwcybgnhemtjiqahgfjhqortmjcuwvecyniorbfqifjnedipnchjczvxecdghvfwnyhmjnuhvwminhcgcsxmzbnxodsgbnvuvltozzgbrzeifzsgexdclwljquponohqckreqfwvmddqizlrhrkhfckecewdlvpdlnbwgxcpsyvuqsvtpmgpztpcajrsderqwsakbbjsdtwjhcavxaykejapyye"
}
] | 1,658,430,780 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 46 | 0 | q,s=int(input()),input()
d,i='',0
while i<q:
if i%2==1:d=s[i]+d
else:d+=s[i]
i+=1
if q%2==1:print(d)
else:print(d[::-1]) | Title: Decoding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is mad about coding, that is why he writes Sveta encoded messages. He calls the median letter in a word the letter which is in the middle of the word. If the word's length is even, the median letter is the left of the two middle letters. In the following examples, the median letter is highlighted: contest, info. If the word consists of single letter, then according to above definition this letter is the median letter.
Polycarp encodes each word in the following way: he writes down the median letter of the word, then deletes it and repeats the process until there are no letters left. For example, he encodes the word volga as logva.
You are given an encoding *s* of some word, your task is to decode it.
Input Specification:
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=2000) — the length of the encoded word.
The second line contains the string *s* of length *n* consisting of lowercase English letters — the encoding.
Output Specification:
Print the word that Polycarp encoded.
Demo Input:
['5\nlogva\n', '2\nno\n', '4\nabba\n']
Demo Output:
['volga\n', 'no\n', 'baba\n']
Note:
In the first example Polycarp encoded the word volga. At first, he wrote down the letter l from the position 3, after that his word looked like voga. After that Polycarp wrote down the letter o from the position 2, his word became vga. Then Polycarp wrote down the letter g which was at the second position, the word became va. Then he wrote down the letter v, then the letter a. Thus, the encoding looked like logva.
In the second example Polycarp encoded the word no. He wrote down the letter n, the word became o, and he wrote down the letter o. Thus, in this example, the word and its encoding are the same.
In the third example Polycarp encoded the word baba. At first, he wrote down the letter a, which was at the position 2, after that the word looked like bba. Then he wrote down the letter b, which was at the position 2, his word looked like ba. After that he wrote down the letter b, which was at the position 1, the word looked like a, and he wrote down that letter a. Thus, the encoding is abba. | ```python
q,s=int(input()),input()
d,i='',0
while i<q:
if i%2==1:d=s[i]+d
else:d+=s[i]
i+=1
if q%2==1:print(d)
else:print(d[::-1])
``` | 3 |
|
924 | A | Mystical Mosaic | PROGRAMMING | 1,300 | [
"greedy",
"implementation"
] | null | null | There is a rectangular grid of *n* rows of *m* initially-white cells each.
Arkady performed a certain number (possibly zero) of operations on it. In the *i*-th operation, a non-empty subset of rows *R**i* and a non-empty subset of columns *C**i* are chosen. For each row *r* in *R**i* and each column *c* in *C**i*, the intersection of row *r* and column *c* is coloured black.
There's another constraint: a row or a column can only be chosen at most once among all operations. In other words, it means that no pair of (*i*,<=*j*) (*i*<=<<=*j*) exists such that or , where denotes intersection of sets, and denotes the empty set.
You are to determine whether a valid sequence of operations exists that produces a given final grid. | The first line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50) — the number of rows and columns of the grid, respectively.
Each of the following *n* lines contains a string of *m* characters, each being either '.' (denoting a white cell) or '#' (denoting a black cell), representing the desired setup. | If the given grid can be achieved by any valid sequence of operations, output "Yes"; otherwise output "No" (both without quotes).
You can print each character in any case (upper or lower). | [
"5 8\n.#.#..#.\n.....#..\n.#.#..#.\n#.#....#\n.....#..\n",
"5 5\n..#..\n..#..\n#####\n..#..\n..#..\n",
"5 9\n........#\n#........\n..##.#...\n.......#.\n....#.#.#\n"
] | [
"Yes\n",
"No\n",
"No\n"
] | For the first example, the desired setup can be produced by 3 operations, as is shown below.
For the second example, the desired setup cannot be produced, since in order to colour the center row, the third row and all columns must be selected in one operation, but after that no column can be selected again, hence it won't be possible to colour the other cells in the center column. | 500 | [
{
"input": "5 8\n.#.#..#.\n.....#..\n.#.#..#.\n#.#....#\n.....#..",
"output": "Yes"
},
{
"input": "5 5\n..#..\n..#..\n#####\n..#..\n..#..",
"output": "No"
},
{
"input": "5 9\n........#\n#........\n..##.#...\n.......#.\n....#.#.#",
"output": "No"
},
{
"input": "1 1\n#",
"output": "Yes"
},
{
"input": "2 1\n.\n#",
"output": "Yes"
},
{
"input": "2 5\n.####\n#..##",
"output": "No"
},
{
"input": "5 2\n##\n##\n..\n##\n..",
"output": "Yes"
},
{
"input": "5 2\n#.\n##\n##\n#.\n..",
"output": "No"
},
{
"input": "4 10\n###..#..##\n...##..#..\n.##..#..#.\n.........#",
"output": "No"
},
{
"input": "4 10\n..#......#\n.....##...\n#.........\n.#.......#",
"output": "No"
},
{
"input": "10 15\n.......#.......\n.....#.........\n....#..........\n....#..........\n.....#.........\n.....#.........\n#.............#\n...#..#........\n...............\n.............#.",
"output": "Yes"
},
{
"input": "50 1\n.\n.\n#\n.\n#\n.\n#\n.\n.\n#\n#\n#\n.\n#\n#\n#\n#\n.\n.\n.\n.\n.\n.\n.\n.\n.\n#\n#\n#\n#\n.\n.\n.\n.\n.\n#\n.\n.\n.\n#\n#\n.\n.\n#\n#\n.\n.\n#\n#\n.",
"output": "Yes"
},
{
"input": "2 50\n...#.##.###...#.#..##....##..........#.#..#.#####.\n...#.##.###...#.#..##....##..........#.#..#.#####.",
"output": "Yes"
},
{
"input": "50 2\n..\n..\n#.\n..\n.#\n..\n..\n..\n.#\n..\n..\n.#\n##\n..\n..\n..\n.#\n..\n..\n.#\n..\n..\n.#\n..\n..\n.#\n..\n.#\n..\n.#\n..\n.#\n.#\n.#\n..\n..\n..\n.#\n.#\n.#\n..\n..\n.#\n.#\n..\n..\n..\n..\n..\n..",
"output": "No"
},
{
"input": "1 1\n.",
"output": "Yes"
},
{
"input": "2 3\n#.#\n###",
"output": "No"
},
{
"input": "2 3\n#.#\n##.",
"output": "No"
},
{
"input": "4 4\n###.\n##.#\n#.##\n.###",
"output": "No"
},
{
"input": "3 3\n.##\n#.#\n##.",
"output": "No"
},
{
"input": "2 2\n##\n#.",
"output": "No"
}
] | 1,612,258,132 | 2,147,483,647 | PyPy 3 | OK | TESTS | 50 | 124 | 1,433,600 | n, m = map(int, input().split())
s = [input() for _ in range(n)]
l = []
for i in range(n):
se = set()
for j in range(m):
if s[i][j]=='#':
se.add(j)
for li in l:
if len(se&li)!=0 and se!=li:
print('No')
exit()
l.append(se)
print('Yes') | Title: Mystical Mosaic
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a rectangular grid of *n* rows of *m* initially-white cells each.
Arkady performed a certain number (possibly zero) of operations on it. In the *i*-th operation, a non-empty subset of rows *R**i* and a non-empty subset of columns *C**i* are chosen. For each row *r* in *R**i* and each column *c* in *C**i*, the intersection of row *r* and column *c* is coloured black.
There's another constraint: a row or a column can only be chosen at most once among all operations. In other words, it means that no pair of (*i*,<=*j*) (*i*<=<<=*j*) exists such that or , where denotes intersection of sets, and denotes the empty set.
You are to determine whether a valid sequence of operations exists that produces a given final grid.
Input Specification:
The first line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50) — the number of rows and columns of the grid, respectively.
Each of the following *n* lines contains a string of *m* characters, each being either '.' (denoting a white cell) or '#' (denoting a black cell), representing the desired setup.
Output Specification:
If the given grid can be achieved by any valid sequence of operations, output "Yes"; otherwise output "No" (both without quotes).
You can print each character in any case (upper or lower).
Demo Input:
['5 8\n.#.#..#.\n.....#..\n.#.#..#.\n#.#....#\n.....#..\n', '5 5\n..#..\n..#..\n#####\n..#..\n..#..\n', '5 9\n........#\n#........\n..##.#...\n.......#.\n....#.#.#\n']
Demo Output:
['Yes\n', 'No\n', 'No\n']
Note:
For the first example, the desired setup can be produced by 3 operations, as is shown below.
For the second example, the desired setup cannot be produced, since in order to colour the center row, the third row and all columns must be selected in one operation, but after that no column can be selected again, hence it won't be possible to colour the other cells in the center column. | ```python
n, m = map(int, input().split())
s = [input() for _ in range(n)]
l = []
for i in range(n):
se = set()
for j in range(m):
if s[i][j]=='#':
se.add(j)
for li in l:
if len(se&li)!=0 and se!=li:
print('No')
exit()
l.append(se)
print('Yes')
``` | 3 |
|
224 | B | Array | PROGRAMMING | 1,500 | [
"bitmasks",
"implementation",
"two pointers"
] | null | null | You've got an array *a*, consisting of *n* integers: *a*1,<=*a*2,<=...,<=*a**n*. Your task is to find a minimal by inclusion segment [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) such, that among numbers *a**l*,<= *a**l*<=+<=1,<= ...,<= *a**r* there are exactly *k* distinct numbers.
Segment [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤<=*n*; *l*,<=*r* are integers) of length *m*<==<=*r*<=-<=*l*<=+<=1, satisfying the given property, is called minimal by inclusion, if there is no segment [*x*,<=*y*] satisfying the property and less then *m* in length, such that 1<=≤<=*l*<=≤<=*x*<=≤<=*y*<=≤<=*r*<=≤<=*n*. Note that the segment [*l*,<=*r*] doesn't have to be minimal in length among all segments, satisfying the given property. | The first line contains two space-separated integers: *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=105). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* — elements of the array *a* (1<=≤<=*a**i*<=≤<=105). | Print a space-separated pair of integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) such, that the segment [*l*,<=*r*] is the answer to the problem. If the sought segment does not exist, print "-1 -1" without the quotes. If there are multiple correct answers, print any of them. | [
"4 2\n1 2 2 3\n",
"8 3\n1 1 2 2 3 3 4 5\n",
"7 4\n4 7 7 4 7 4 7\n"
] | [
"1 2\n",
"2 5\n",
"-1 -1\n"
] | In the first sample among numbers *a*<sub class="lower-index">1</sub> and *a*<sub class="lower-index">2</sub> there are exactly two distinct numbers.
In the second sample segment [2, 5] is a minimal by inclusion segment with three distinct numbers, but it is not minimal in length among such segments.
In the third sample there is no segment with four distinct numbers. | 1,000 | [
{
"input": "4 2\n1 2 2 3",
"output": "1 2"
},
{
"input": "8 3\n1 1 2 2 3 3 4 5",
"output": "2 5"
},
{
"input": "7 4\n4 7 7 4 7 4 7",
"output": "-1 -1"
},
{
"input": "5 1\n1 7 2 3 2",
"output": "1 1"
},
{
"input": "1 2\n666",
"output": "-1 -1"
},
{
"input": "1 1\n5",
"output": "1 1"
},
{
"input": "10 4\n1 1 2 2 3 3 4 4 4 4",
"output": "2 7"
},
{
"input": "4 2\n3 3 4 3",
"output": "2 3"
},
{
"input": "4 3\n4 4 4 2",
"output": "-1 -1"
},
{
"input": "10 5\n15 17 2 13 3 16 4 5 9 12",
"output": "1 5"
},
{
"input": "17 13\n34 15 156 11 183 147 192 112 145 30 88 37 1 98 3 162 148",
"output": "1 13"
},
{
"input": "17 14\n271 158 573 88 792 767 392 646 392 392 271 549 402 767 573 925 796",
"output": "-1 -1"
},
{
"input": "8 5\n1 2 1 1 2 3 4 5",
"output": "4 8"
},
{
"input": "7 3\n2 1 2 2 1 2 3",
"output": "5 7"
},
{
"input": "6 3\n1 3 1 1 4 5",
"output": "2 5"
},
{
"input": "5 3\n1 2 1 1 3",
"output": "2 5"
},
{
"input": "9 3\n1 2 1 2 1 2 2 3 1",
"output": "5 8"
},
{
"input": "4 3\n1 2 1 3",
"output": "2 4"
},
{
"input": "5 3\n1 3 1 3 4",
"output": "3 5"
},
{
"input": "6 3\n1 3 3 1 4 4",
"output": "3 5"
},
{
"input": "5 3\n1 2 1 2 3",
"output": "3 5"
},
{
"input": "8 4\n1 2 3 2 1 2 3 4",
"output": "5 8"
},
{
"input": "10 4\n1 2 3 1 2 3 4 3 2 1",
"output": "4 7"
},
{
"input": "10 3\n1 1 1 2 1 2 3 3 3 4",
"output": "5 7"
},
{
"input": "10 3\n1 1 2 1 2 2 3 4 5 6",
"output": "4 7"
}
] | 1,590,989,166 | 2,147,483,647 | PyPy 3 | OK | TESTS | 49 | 404 | 14,131,200 | n,k=map(int,input().split())
l1=list(map(int,input().split()))
s=set()
l=-1
r=-1
ans=n
if n==1:
if k==1:
print(1,1)
else:
print(-1,-1)
else:
for i in range(n):
s.add(l1[i])
if len(s)==k:
l=1
r=i+1
break
if l==-1:
print(l,r)
else:
s=set()
for i in range(r-1,max(-1,l-2),-1):
s.add(l1[i])
if len(s)==k:
l=i+1
break
print(l,r)
| Title: Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got an array *a*, consisting of *n* integers: *a*1,<=*a*2,<=...,<=*a**n*. Your task is to find a minimal by inclusion segment [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) such, that among numbers *a**l*,<= *a**l*<=+<=1,<= ...,<= *a**r* there are exactly *k* distinct numbers.
Segment [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤<=*n*; *l*,<=*r* are integers) of length *m*<==<=*r*<=-<=*l*<=+<=1, satisfying the given property, is called minimal by inclusion, if there is no segment [*x*,<=*y*] satisfying the property and less then *m* in length, such that 1<=≤<=*l*<=≤<=*x*<=≤<=*y*<=≤<=*r*<=≤<=*n*. Note that the segment [*l*,<=*r*] doesn't have to be minimal in length among all segments, satisfying the given property.
Input Specification:
The first line contains two space-separated integers: *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=105). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* — elements of the array *a* (1<=≤<=*a**i*<=≤<=105).
Output Specification:
Print a space-separated pair of integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) such, that the segment [*l*,<=*r*] is the answer to the problem. If the sought segment does not exist, print "-1 -1" without the quotes. If there are multiple correct answers, print any of them.
Demo Input:
['4 2\n1 2 2 3\n', '8 3\n1 1 2 2 3 3 4 5\n', '7 4\n4 7 7 4 7 4 7\n']
Demo Output:
['1 2\n', '2 5\n', '-1 -1\n']
Note:
In the first sample among numbers *a*<sub class="lower-index">1</sub> and *a*<sub class="lower-index">2</sub> there are exactly two distinct numbers.
In the second sample segment [2, 5] is a minimal by inclusion segment with three distinct numbers, but it is not minimal in length among such segments.
In the third sample there is no segment with four distinct numbers. | ```python
n,k=map(int,input().split())
l1=list(map(int,input().split()))
s=set()
l=-1
r=-1
ans=n
if n==1:
if k==1:
print(1,1)
else:
print(-1,-1)
else:
for i in range(n):
s.add(l1[i])
if len(s)==k:
l=1
r=i+1
break
if l==-1:
print(l,r)
else:
s=set()
for i in range(r-1,max(-1,l-2),-1):
s.add(l1[i])
if len(s)==k:
l=i+1
break
print(l,r)
``` | 3 |
|
711 | A | Bus to Udayland | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | ZS the Coder and Chris the Baboon are travelling to Udayland! To get there, they have to get on the special IOI bus. The IOI bus has *n* rows of seats. There are 4 seats in each row, and the seats are separated into pairs by a walkway. When ZS and Chris came, some places in the bus was already occupied.
ZS and Chris are good friends. They insist to get a pair of neighbouring empty seats. Two seats are considered neighbouring if they are in the same row and in the same pair. Given the configuration of the bus, can you help ZS and Chris determine where they should sit? | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of rows of seats in the bus.
Then, *n* lines follow. Each line contains exactly 5 characters, the first two of them denote the first pair of seats in the row, the third character denotes the walkway (it always equals '|') and the last two of them denote the second pair of seats in the row.
Each character, except the walkway, equals to 'O' or to 'X'. 'O' denotes an empty seat, 'X' denotes an occupied seat. See the sample cases for more details. | If it is possible for Chris and ZS to sit at neighbouring empty seats, print "YES" (without quotes) in the first line. In the next *n* lines print the bus configuration, where the characters in the pair of seats for Chris and ZS is changed with characters '+'. Thus the configuration should differ from the input one by exactly two charaters (they should be equal to 'O' in the input and to '+' in the output).
If there is no pair of seats for Chris and ZS, print "NO" (without quotes) in a single line.
If there are multiple solutions, you may print any of them. | [
"6\nOO|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX\n",
"4\nXO|OX\nXO|XX\nOX|OX\nXX|OX\n",
"5\nXX|XX\nXX|XX\nXO|OX\nXO|OO\nOX|XO\n"
] | [
"YES\n++|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX\n",
"NO\n",
"YES\nXX|XX\nXX|XX\nXO|OX\nXO|++\nOX|XO\n"
] | Note that the following is an incorrect configuration for the first sample case because the seats must be in the same pair.
O+|+X
XO|XX
OX|OO
XX|OX
OO|OO
OO|XX | 500 | [
{
"input": "6\nOO|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX",
"output": "YES\n++|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX"
},
{
"input": "4\nXO|OX\nXO|XX\nOX|OX\nXX|OX",
"output": "NO"
},
{
"input": "5\nXX|XX\nXX|XX\nXO|OX\nXO|OO\nOX|XO",
"output": "YES\nXX|XX\nXX|XX\nXO|OX\nXO|++\nOX|XO"
},
{
"input": "1\nXO|OX",
"output": "NO"
},
{
"input": "1\nOO|OO",
"output": "YES\n++|OO"
},
{
"input": "4\nXO|XX\nXX|XO\nOX|XX\nXO|XO",
"output": "NO"
},
{
"input": "9\nOX|XO\nOX|XO\nXO|OX\nOX|OX\nXO|OX\nXX|OO\nOX|OX\nOX|XO\nOX|OX",
"output": "YES\nOX|XO\nOX|XO\nXO|OX\nOX|OX\nXO|OX\nXX|++\nOX|OX\nOX|XO\nOX|OX"
},
{
"input": "61\nOX|XX\nOX|XX\nOX|XX\nXO|XO\nXX|XO\nXX|XX\nXX|XX\nOX|XX\nXO|XO\nOX|XO\nXO|OX\nXX|XX\nXX|XX\nOX|OX\nXX|OX\nOX|XO\nOX|XO\nXO|OX\nXO|XX\nOX|XX\nOX|XX\nXO|OX\nXO|XX\nXO|XX\nOX|XX\nXX|XX\nXX|XO\nXO|XX\nXX|XX\nXO|OX\nXX|XO\nXO|XX\nXO|XO\nXO|OX\nXX|OX\nXO|OX\nOX|XX\nXX|OX\nXX|XX\nOX|XO\nOX|XX\nXO|OX\nOX|XX\nOX|XX\nXO|XO\nXO|XX\nOX|XX\nXO|XO\nOX|XX\nXX|XX\nOX|XO\nXO|XO\nXO|XO\nOX|OX\nXX|OX\nXX|OX\nOX|XO\nOX|XX\nOX|OX\nXO|XX\nOX|XX",
"output": "NO"
},
{
"input": "1\nOO|XX",
"output": "YES\n++|XX"
},
{
"input": "10\nOO|XX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXX|XX",
"output": "YES\n++|XX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXX|XX"
},
{
"input": "10\nXX|XX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXX|OO",
"output": "YES\nXX|XX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXX|++"
},
{
"input": "5\nXX|XX\nXX|XX\nXO|OX\nOO|OX\nOX|XO",
"output": "YES\nXX|XX\nXX|XX\nXO|OX\n++|OX\nOX|XO"
},
{
"input": "6\nOO|XX\nXO|XX\nOX|OO\nXX|OX\nOO|XX\nOX|XX",
"output": "YES\n++|XX\nXO|XX\nOX|OO\nXX|OX\nOO|XX\nOX|XX"
}
] | 1,698,748,201 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 30 | 0 | n=int(input())
k = False
z=[]
for i in range(n):
s=input()
if "OO" in s and not k:
k = True
s = s.replace("OO","++")
z.append(s)
else:
z.append(s)
if k:
print("YES")
else:
print("NO")
for i in z:
print(i)
| Title: Bus to Udayland
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
ZS the Coder and Chris the Baboon are travelling to Udayland! To get there, they have to get on the special IOI bus. The IOI bus has *n* rows of seats. There are 4 seats in each row, and the seats are separated into pairs by a walkway. When ZS and Chris came, some places in the bus was already occupied.
ZS and Chris are good friends. They insist to get a pair of neighbouring empty seats. Two seats are considered neighbouring if they are in the same row and in the same pair. Given the configuration of the bus, can you help ZS and Chris determine where they should sit?
Input Specification:
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of rows of seats in the bus.
Then, *n* lines follow. Each line contains exactly 5 characters, the first two of them denote the first pair of seats in the row, the third character denotes the walkway (it always equals '|') and the last two of them denote the second pair of seats in the row.
Each character, except the walkway, equals to 'O' or to 'X'. 'O' denotes an empty seat, 'X' denotes an occupied seat. See the sample cases for more details.
Output Specification:
If it is possible for Chris and ZS to sit at neighbouring empty seats, print "YES" (without quotes) in the first line. In the next *n* lines print the bus configuration, where the characters in the pair of seats for Chris and ZS is changed with characters '+'. Thus the configuration should differ from the input one by exactly two charaters (they should be equal to 'O' in the input and to '+' in the output).
If there is no pair of seats for Chris and ZS, print "NO" (without quotes) in a single line.
If there are multiple solutions, you may print any of them.
Demo Input:
['6\nOO|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX\n', '4\nXO|OX\nXO|XX\nOX|OX\nXX|OX\n', '5\nXX|XX\nXX|XX\nXO|OX\nXO|OO\nOX|XO\n']
Demo Output:
['YES\n++|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX\n', 'NO\n', 'YES\nXX|XX\nXX|XX\nXO|OX\nXO|++\nOX|XO\n']
Note:
Note that the following is an incorrect configuration for the first sample case because the seats must be in the same pair.
O+|+X
XO|XX
OX|OO
XX|OX
OO|OO
OO|XX | ```python
n=int(input())
k = False
z=[]
for i in range(n):
s=input()
if "OO" in s and not k:
k = True
s = s.replace("OO","++")
z.append(s)
else:
z.append(s)
if k:
print("YES")
else:
print("NO")
for i in z:
print(i)
``` | 0 |
|
825 | C | Multi-judge Solving | PROGRAMMING | 1,600 | [
"greedy",
"implementation"
] | null | null | Makes solves problems on Decoforces and lots of other different online judges. Each problem is denoted by its difficulty — a positive integer number. Difficulties are measured the same across all the judges (the problem with difficulty *d* on Decoforces is as hard as the problem with difficulty *d* on any other judge).
Makes has chosen *n* problems to solve on Decoforces with difficulties *a*1,<=*a*2,<=...,<=*a**n*. He can solve these problems in arbitrary order. Though he can solve problem *i* with difficulty *a**i* only if he had already solved some problem with difficulty (no matter on what online judge was it).
Before starting this chosen list of problems, Makes has already solved problems with maximum difficulty *k*.
With given conditions it's easy to see that Makes sometimes can't solve all the chosen problems, no matter what order he chooses. So he wants to solve some problems on other judges to finish solving problems from his list.
For every positive integer *y* there exist some problem with difficulty *y* on at least one judge besides Decoforces.
Makes can solve problems on any judge at any time, it isn't necessary to do problems from the chosen list one right after another.
Makes doesn't have too much free time, so he asked you to calculate the minimum number of problems he should solve on other judges in order to solve all the chosen problems from Decoforces. | The first line contains two integer numbers *n*, *k* (1<=≤<=*n*<=≤<=103, 1<=≤<=*k*<=≤<=109).
The second line contains *n* space-separated integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). | Print minimum number of problems Makes should solve on other judges in order to solve all chosen problems on Decoforces. | [
"3 3\n2 1 9\n",
"4 20\n10 3 6 3\n"
] | [
"1\n",
"0\n"
] | In the first example Makes at first solves problems 1 and 2. Then in order to solve the problem with difficulty 9, he should solve problem with difficulty no less than 5. The only available are difficulties 5 and 6 on some other judge. Solving any of these will give Makes opportunity to solve problem 3.
In the second example he can solve every problem right from the start. | 0 | [
{
"input": "3 3\n2 1 9",
"output": "1"
},
{
"input": "4 20\n10 3 6 3",
"output": "0"
},
{
"input": "1 1000000000\n1",
"output": "0"
},
{
"input": "1 1\n3",
"output": "1"
},
{
"input": "50 100\n74 55 33 5 83 24 75 59 30 36 13 4 62 28 96 17 6 35 45 53 33 11 37 93 34 79 61 72 13 31 44 75 7 3 63 46 18 16 44 89 62 25 32 12 38 55 75 56 61 82",
"output": "0"
},
{
"input": "100 10\n246 286 693 607 87 612 909 312 621 37 801 558 504 914 416 762 187 974 976 123 635 488 416 659 988 998 93 662 92 749 889 78 214 786 735 625 921 372 713 617 975 119 402 411 878 138 548 905 802 762 940 336 529 373 745 835 805 880 816 94 166 114 475 699 974 462 61 337 555 805 968 815 392 746 591 558 740 380 668 29 881 151 387 986 174 923 541 520 998 947 535 651 103 584 664 854 180 852 726 93",
"output": "1"
},
{
"input": "2 1\n1 1000000000",
"output": "29"
},
{
"input": "29 2\n1 3 7 15 31 63 127 255 511 1023 2047 4095 8191 16383 32767 65535 131071 262143 524287 1048575 2097151 4194303 8388607 16777215 33554431 67108863 134217727 268435455 536870911",
"output": "27"
},
{
"input": "1 1\n1000000000",
"output": "29"
},
{
"input": "7 6\n4 20 16 14 3 17 4",
"output": "1"
},
{
"input": "2 1\n3 6",
"output": "1"
},
{
"input": "1 1\n20",
"output": "4"
},
{
"input": "5 2\n86 81 53 25 18",
"output": "4"
},
{
"input": "4 1\n88 55 14 39",
"output": "4"
},
{
"input": "3 1\n2 3 6",
"output": "0"
},
{
"input": "3 2\n4 9 18",
"output": "1"
},
{
"input": "5 3\n6 6 6 13 27",
"output": "2"
},
{
"input": "5 1\n23 8 83 26 18",
"output": "4"
},
{
"input": "3 1\n4 5 6",
"output": "1"
},
{
"input": "3 1\n1 3 6",
"output": "1"
},
{
"input": "1 1\n2",
"output": "0"
},
{
"input": "3 2\n4 5 6",
"output": "0"
},
{
"input": "5 1\n100 200 400 1000 2000",
"output": "7"
},
{
"input": "2 1\n1 4",
"output": "1"
},
{
"input": "4 1\n2 4 8 32",
"output": "1"
},
{
"input": "2 10\n21 42",
"output": "1"
},
{
"input": "3 3\n1 7 13",
"output": "1"
},
{
"input": "3 1\n1 4 6",
"output": "1"
},
{
"input": "2 2\n2 8",
"output": "1"
},
{
"input": "1 1\n4",
"output": "1"
},
{
"input": "2 2\n8 16",
"output": "1"
},
{
"input": "3 1\n4 8 16",
"output": "1"
},
{
"input": "3 1\n3 6 9",
"output": "1"
},
{
"input": "2 1\n4 8",
"output": "1"
},
{
"input": "2 2\n7 14",
"output": "1"
},
{
"input": "1 4\n9",
"output": "1"
},
{
"input": "5 3\n1024 4096 16384 65536 536870913",
"output": "24"
},
{
"input": "2 5\n10 11",
"output": "0"
},
{
"input": "2 2\n3 6",
"output": "0"
},
{
"input": "2 2\n8 11",
"output": "1"
},
{
"input": "3 19905705\n263637263 417905394 108361057",
"output": "3"
},
{
"input": "4 25\n100 11 1 13",
"output": "1"
},
{
"input": "10 295206008\n67980321 440051990 883040288 135744260 96431758 242465794 576630162 972797687 356406646 547451696",
"output": "0"
},
{
"input": "4 2\n45 44 35 38",
"output": "4"
},
{
"input": "1 2\n9",
"output": "2"
},
{
"input": "3 6\n13 26 52",
"output": "1"
},
{
"input": "9 30111088\n824713578 11195876 458715185 731769293 680826358 189542586 550198537 860586039 101083021",
"output": "2"
},
{
"input": "3 72014068\n430005292 807436976 828082746",
"output": "2"
},
{
"input": "3 165219745\n737649884 652879952 506420386",
"output": "1"
},
{
"input": "2 60669400\n95037700 337255240",
"output": "1"
},
{
"input": "4 28\n34 1 86 90",
"output": "1"
},
{
"input": "2 1\n5 10",
"output": "2"
},
{
"input": "2 1\n4 1000000000",
"output": "28"
},
{
"input": "2 1\n2 3",
"output": "0"
},
{
"input": "2 1\n3 5",
"output": "1"
},
{
"input": "3 3\n1 5 20",
"output": "1"
},
{
"input": "9 1\n1 2 4 9 15 32 64 128 1024",
"output": "4"
}
] | 1,500,321,115 | 2,147,483,647 | PyPy 3 | OK | TESTS | 61 | 202 | 23,142,400 | #!/usr/local/bin/python3
n, k = map(int, input().split())
max_difficulty = k
problems = map(int, input().split())
problems = sorted(problems)
help_requested = 0
for problem in problems:
if problem <= 2 * max_difficulty:
max_difficulty = max(problem, max_difficulty)
continue
while problem > 2 * max_difficulty:
help_requested += 1
max_difficulty *= 2
max_difficulty = max(problem, max_difficulty)
print(help_requested)
| Title: Multi-judge Solving
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Makes solves problems on Decoforces and lots of other different online judges. Each problem is denoted by its difficulty — a positive integer number. Difficulties are measured the same across all the judges (the problem with difficulty *d* on Decoforces is as hard as the problem with difficulty *d* on any other judge).
Makes has chosen *n* problems to solve on Decoforces with difficulties *a*1,<=*a*2,<=...,<=*a**n*. He can solve these problems in arbitrary order. Though he can solve problem *i* with difficulty *a**i* only if he had already solved some problem with difficulty (no matter on what online judge was it).
Before starting this chosen list of problems, Makes has already solved problems with maximum difficulty *k*.
With given conditions it's easy to see that Makes sometimes can't solve all the chosen problems, no matter what order he chooses. So he wants to solve some problems on other judges to finish solving problems from his list.
For every positive integer *y* there exist some problem with difficulty *y* on at least one judge besides Decoforces.
Makes can solve problems on any judge at any time, it isn't necessary to do problems from the chosen list one right after another.
Makes doesn't have too much free time, so he asked you to calculate the minimum number of problems he should solve on other judges in order to solve all the chosen problems from Decoforces.
Input Specification:
The first line contains two integer numbers *n*, *k* (1<=≤<=*n*<=≤<=103, 1<=≤<=*k*<=≤<=109).
The second line contains *n* space-separated integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109).
Output Specification:
Print minimum number of problems Makes should solve on other judges in order to solve all chosen problems on Decoforces.
Demo Input:
['3 3\n2 1 9\n', '4 20\n10 3 6 3\n']
Demo Output:
['1\n', '0\n']
Note:
In the first example Makes at first solves problems 1 and 2. Then in order to solve the problem with difficulty 9, he should solve problem with difficulty no less than 5. The only available are difficulties 5 and 6 on some other judge. Solving any of these will give Makes opportunity to solve problem 3.
In the second example he can solve every problem right from the start. | ```python
#!/usr/local/bin/python3
n, k = map(int, input().split())
max_difficulty = k
problems = map(int, input().split())
problems = sorted(problems)
help_requested = 0
for problem in problems:
if problem <= 2 * max_difficulty:
max_difficulty = max(problem, max_difficulty)
continue
while problem > 2 * max_difficulty:
help_requested += 1
max_difficulty *= 2
max_difficulty = max(problem, max_difficulty)
print(help_requested)
``` | 3 |
|
266 | B | Queue at the School | PROGRAMMING | 800 | [
"constructive algorithms",
"graph matchings",
"implementation",
"shortest paths"
] | null | null | During the break the schoolchildren, boys and girls, formed a queue of *n* people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward each second.
Let's describe the process more precisely. Let's say that the positions in the queue are sequentially numbered by integers from 1 to *n*, at that the person in the position number 1 is served first. Then, if at time *x* a boy stands on the *i*-th position and a girl stands on the (*i*<=+<=1)-th position, then at time *x*<=+<=1 the *i*-th position will have a girl and the (*i*<=+<=1)-th position will have a boy. The time is given in seconds.
You've got the initial position of the children, at the initial moment of time. Determine the way the queue is going to look after *t* seconds. | The first line contains two integers *n* and *t* (1<=≤<=*n*,<=*t*<=≤<=50), which represent the number of children in the queue and the time after which the queue will transform into the arrangement you need to find.
The next line contains string *s*, which represents the schoolchildren's initial arrangement. If the *i*-th position in the queue contains a boy, then the *i*-th character of string *s* equals "B", otherwise the *i*-th character equals "G". | Print string *a*, which describes the arrangement after *t* seconds. If the *i*-th position has a boy after the needed time, then the *i*-th character *a* must equal "B", otherwise it must equal "G". | [
"5 1\nBGGBG\n",
"5 2\nBGGBG\n",
"4 1\nGGGB\n"
] | [
"GBGGB\n",
"GGBGB\n",
"GGGB\n"
] | none | 500 | [
{
"input": "5 1\nBGGBG",
"output": "GBGGB"
},
{
"input": "5 2\nBGGBG",
"output": "GGBGB"
},
{
"input": "4 1\nGGGB",
"output": "GGGB"
},
{
"input": "2 1\nBB",
"output": "BB"
},
{
"input": "2 1\nBG",
"output": "GB"
},
{
"input": "6 2\nBBGBBG",
"output": "GBBGBB"
},
{
"input": "8 3\nBBGBGBGB",
"output": "GGBGBBBB"
},
{
"input": "10 3\nBBGBBBBBBG",
"output": "GBBBBBGBBB"
},
{
"input": "22 7\nGBGGBGGGGGBBBGGBGBGBBB",
"output": "GGGGGGGGBGGBGGBBBBBBBB"
},
{
"input": "50 4\nGBBGBBBGGGGGBBGGBBBBGGGBBBGBBBGGBGGBGBBBGGBGGBGGBG",
"output": "GGBGBGBGBGBGGGBBGBGBGBGBBBGBGBGBGBGBGBGBGBGBGGBGBB"
},
{
"input": "50 8\nGGGGBGGBGGGBGBBBGGGGGGGGBBGBGBGBBGGBGGBGGGGGGGGBBG",
"output": "GGGGGGGGGGGGBGGBGBGBGBGBGGGGGGBGBGBGBGBGBGGBGGBGBB"
},
{
"input": "50 30\nBGGGGGGBGGBGBGGGGBGBBGBBBGGBBBGBGBGGGGGBGBBGBGBGGG",
"output": "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGBBBBBBBBBBBBBBBBBBBB"
},
{
"input": "20 20\nBBGGBGGGGBBBGBBGGGBB",
"output": "GGGGGGGGGGBBBBBBBBBB"
},
{
"input": "27 6\nGBGBGBGGGGGGBGGBGGBBGBBBGBB",
"output": "GGGGGGGBGBGBGGGGGBGBBBBBBBB"
},
{
"input": "46 11\nBGGGGGBGBGGBGGGBBGBBGBBGGBBGBBGBGGGGGGGBGBGBGB",
"output": "GGGGGGGGGGGBGGGGGBBGBGBGBGBGBGBGBGBGBGBGBBBBBB"
},
{
"input": "50 6\nBGGBBBBGGBBBBBBGGBGBGBBBBGBBBBBBGBBBBBBBBBBBBBBBBB",
"output": "GGGGBBBBBGBGBGBGBBBGBBBBBBGBBBBBBBBBBBBBBBBBBBBBBB"
},
{
"input": "50 10\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
"output": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
},
{
"input": "50 8\nGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG",
"output": "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG"
},
{
"input": "50 10\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBGB",
"output": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBGBBBBBBBBBBB"
},
{
"input": "50 13\nGGGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG",
"output": "GGGGGGGGGGGGGGGGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG"
},
{
"input": "1 1\nB",
"output": "B"
},
{
"input": "1 1\nG",
"output": "G"
},
{
"input": "1 50\nB",
"output": "B"
},
{
"input": "1 50\nG",
"output": "G"
},
{
"input": "50 50\nBBBBBBBBGGBBBBBBGBBBBBBBBBBBGBBBBBBBBBBBBBBGBBBBBB",
"output": "GGGGGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
},
{
"input": "50 50\nGGBBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGBBGGGGGGBG",
"output": "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGBBBBB"
},
{
"input": "6 3\nGGBBBG",
"output": "GGGBBB"
},
{
"input": "26 3\nGBBGBBBBBGGGBGBGGGBGBGGBBG",
"output": "GGBBBBGBGBGBGGGBGBGGGBGBBB"
},
{
"input": "46 3\nGGBBGGGGBBGBGBBBBBGGGBGGGBBGGGBBBGGBGGBBBGBGBB",
"output": "GGGGBGBGGGBBBBBGBGBGBGGGBGGBGBGBGBGBGBGBGBBBBB"
},
{
"input": "44 8\nBGBBBBBBBBBGGBBGBGBGGBBBBBGBBGBBBBBBBBBGBBGB",
"output": "GBBGBGBGBGBGBGBBBBGBBGBBBBBBBBBGBBGBBBBBBBBB"
},
{
"input": "20 20\nBBGGBGGGGBBBGBBGGGBB",
"output": "GGGGGGGGGGBBBBBBBBBB"
},
{
"input": "30 25\nBGGBBGBGGBGBGBBGBGGGGBGBGGBBBB",
"output": "GGGGGGGGGGGGGGGBBBBBBBBBBBBBBB"
},
{
"input": "17 42\nBBGBGBGGGGGGBBGGG",
"output": "GGGGGGGGGGGBBBBBB"
},
{
"input": "30 50\nBGGBBGGGGGGGGBBGGGBBGGBBBGBBGG",
"output": "GGGGGGGGGGGGGGGGGGBBBBBBBBBBBB"
},
{
"input": "31 33\nBBGGBBGGBGBBBBGGBGBBBGBGGBBGBBB",
"output": "GGGGGGGGGGGGBBBBBBBBBBBBBBBBBBB"
},
{
"input": "2 2\nBG",
"output": "GB"
},
{
"input": "8 8\nGGGBGGBB",
"output": "GGGGGBBB"
},
{
"input": "34 34\nBGGBBBBGGBBGBGGGGGGBBGGGGGBGGBGGGB",
"output": "GGGGGGGGGGGGGGGGGGGGGBBBBBBBBBBBBB"
},
{
"input": "34 20\nBBBBGBGGGBGGGBGBGGBBBBGGBBGGGBGBBG",
"output": "GGGGGGGGGGGGGGGGGBBBBBBBBBBBBBBBBB"
},
{
"input": "50 50\nBBGBBBBBBBBBBBBGBBBGBBBBBBBGBBBBBBGBBBGBBGBBGBBBGG",
"output": "GGGGGGGGGGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
},
{
"input": "10 10\nGGGGGGGGGG",
"output": "GGGGGGGGGG"
},
{
"input": "10 10\nBBBBBBBBBB",
"output": "BBBBBBBBBB"
},
{
"input": "10 10\nBGBGBGBGBG",
"output": "GGGGGBBBBB"
},
{
"input": "1 1\nB",
"output": "B"
}
] | 1,696,516,435 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | n,t=map(int,input().split())
s=str(input())
i=0
while i < t :
if s[i] =='B' and s[i+1] == 'G':
car=s[0:i+1]+'GB'+s[i+2:]
i+=2
print(car) | Title: Queue at the School
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
During the break the schoolchildren, boys and girls, formed a queue of *n* people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward each second.
Let's describe the process more precisely. Let's say that the positions in the queue are sequentially numbered by integers from 1 to *n*, at that the person in the position number 1 is served first. Then, if at time *x* a boy stands on the *i*-th position and a girl stands on the (*i*<=+<=1)-th position, then at time *x*<=+<=1 the *i*-th position will have a girl and the (*i*<=+<=1)-th position will have a boy. The time is given in seconds.
You've got the initial position of the children, at the initial moment of time. Determine the way the queue is going to look after *t* seconds.
Input Specification:
The first line contains two integers *n* and *t* (1<=≤<=*n*,<=*t*<=≤<=50), which represent the number of children in the queue and the time after which the queue will transform into the arrangement you need to find.
The next line contains string *s*, which represents the schoolchildren's initial arrangement. If the *i*-th position in the queue contains a boy, then the *i*-th character of string *s* equals "B", otherwise the *i*-th character equals "G".
Output Specification:
Print string *a*, which describes the arrangement after *t* seconds. If the *i*-th position has a boy after the needed time, then the *i*-th character *a* must equal "B", otherwise it must equal "G".
Demo Input:
['5 1\nBGGBG\n', '5 2\nBGGBG\n', '4 1\nGGGB\n']
Demo Output:
['GBGGB\n', 'GGBGB\n', 'GGGB\n']
Note:
none | ```python
n,t=map(int,input().split())
s=str(input())
i=0
while i < t :
if s[i] =='B' and s[i+1] == 'G':
car=s[0:i+1]+'GB'+s[i+2:]
i+=2
print(car)
``` | 0 |
|
978 | A | Remove Duplicates | PROGRAMMING | 800 | [
"implementation"
] | null | null | Petya has an array $a$ consisting of $n$ integers. He wants to remove duplicate (equal) elements.
Petya wants to leave only the rightmost entry (occurrence) for each element of the array. The relative order of the remaining unique elements should not be changed. | The first line contains a single integer $n$ ($1 \le n \le 50$) — the number of elements in Petya's array.
The following line contains a sequence $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 1\,000$) — the Petya's array. | In the first line print integer $x$ — the number of elements which will be left in Petya's array after he removed the duplicates.
In the second line print $x$ integers separated with a space — Petya's array after he removed the duplicates. For each unique element only the rightmost entry should be left. | [
"6\n1 5 5 1 6 1\n",
"5\n2 4 2 4 4\n",
"5\n6 6 6 6 6\n"
] | [
"3\n5 6 1 \n",
"2\n2 4 \n",
"1\n6 \n"
] | In the first example you should remove two integers $1$, which are in the positions $1$ and $4$. Also you should remove the integer $5$, which is in the position $2$.
In the second example you should remove integer $2$, which is in the position $1$, and two integers $4$, which are in the positions $2$ and $4$.
In the third example you should remove four integers $6$, which are in the positions $1$, $2$, $3$ and $4$. | 0 | [
{
"input": "6\n1 5 5 1 6 1",
"output": "3\n5 6 1 "
},
{
"input": "5\n2 4 2 4 4",
"output": "2\n2 4 "
},
{
"input": "5\n6 6 6 6 6",
"output": "1\n6 "
},
{
"input": "7\n1 2 3 4 2 2 3",
"output": "4\n1 4 2 3 "
},
{
"input": "9\n100 100 100 99 99 99 100 100 100",
"output": "2\n99 100 "
},
{
"input": "27\n489 489 487 488 750 230 43 645 42 42 489 42 973 42 973 750 645 355 868 112 868 489 750 489 887 489 868",
"output": "13\n487 488 230 43 42 973 645 355 112 750 887 489 868 "
},
{
"input": "40\n151 421 421 909 117 222 909 954 227 421 227 954 954 222 421 227 421 421 421 151 421 227 222 222 222 222 421 183 421 227 421 954 222 421 954 421 222 421 909 421",
"output": "8\n117 151 183 227 954 222 909 421 "
},
{
"input": "48\n2 2 2 903 903 2 726 2 2 2 2 2 2 2 2 2 2 726 2 2 2 2 2 2 2 726 2 2 2 2 62 2 2 2 2 2 2 2 2 726 62 726 2 2 2 903 903 2",
"output": "4\n62 726 903 2 "
},
{
"input": "1\n1",
"output": "1\n1 "
},
{
"input": "13\n5 37 375 5 37 33 37 375 37 2 3 3 2",
"output": "6\n5 33 375 37 3 2 "
},
{
"input": "50\n1 2 3 4 5 4 3 2 1 2 3 2 1 4 5 5 4 3 2 1 1 2 3 4 5 4 3 2 1 2 3 2 1 4 5 5 4 3 2 1 4 3 2 5 1 6 6 6 6 6",
"output": "6\n4 3 2 5 1 6 "
},
{
"input": "47\n233 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "2\n233 1 "
},
{
"input": "47\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "1\n1 "
},
{
"input": "2\n964 964",
"output": "1\n964 "
},
{
"input": "2\n1000 1000",
"output": "1\n1000 "
},
{
"input": "1\n1000",
"output": "1\n1000 "
},
{
"input": "45\n991 991 996 996 992 992 999 1000 998 1000 992 999 996 999 991 991 999 993 992 999 1000 997 992 999 996 991 994 996 991 999 1000 993 999 997 999 992 991 997 991 998 998 995 998 994 993",
"output": "10\n996 1000 999 992 997 991 995 998 994 993 "
},
{
"input": "6\n994 993 1000 998 991 994",
"output": "5\n993 1000 998 991 994 "
},
{
"input": "48\n992 995 992 991 994 992 995 999 996 993 999 995 993 992 1000 992 997 996 991 993 992 998 998 998 999 995 992 992 993 992 992 995 996 995 997 991 997 991 999 994 994 997 1000 998 1000 992 1000 999",
"output": "10\n993 996 995 991 994 997 998 992 1000 999 "
},
{
"input": "3\n6 6 3",
"output": "2\n6 3 "
},
{
"input": "36\n999 1000 993 993 1000 999 996 997 998 995 995 997 999 995 1000 998 998 994 993 998 994 999 1000 995 996 994 991 991 999 996 993 999 996 998 991 997",
"output": "9\n1000 995 994 993 999 996 998 991 997 "
},
{
"input": "49\n991 997 995 991 995 998 994 996 997 991 998 993 992 999 996 995 991 991 999 997 995 993 997 1000 997 993 993 994 999 994 992 991 1000 996 994 996 996 999 992 992 1000 991 997 993 991 994 997 991 996",
"output": "10\n998 995 999 992 1000 993 994 997 991 996 "
},
{
"input": "2\n1000 999",
"output": "2\n1000 999 "
},
{
"input": "28\n997 994 991 994 994 995 1000 992 995 994 994 995 991 996 991 996 991 999 999 993 994 997 995 992 991 992 998 1000",
"output": "10\n996 999 993 994 997 995 991 992 998 1000 "
},
{
"input": "15\n991 995 995 1000 991 993 997 998 1000 994 1000 992 991 995 992",
"output": "8\n993 997 998 994 1000 991 995 992 "
},
{
"input": "6\n1000 1 1000 2 1000 1",
"output": "3\n2 1000 1 "
},
{
"input": "6\n1000 1 1000 2 1 1000",
"output": "3\n2 1 1000 "
},
{
"input": "7\n1 1000 1 999 1000 1 2",
"output": "4\n999 1000 1 2 "
}
] | 1,663,378,212 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 46 | 0 | a=int(input())
b=list(map(int,input().split()))
b=b[::-1]
d=[];ans=0
c=''
for i in range(len(b)):
if b[i] not in d:
d.append(b[i])
c=c+str(b[i])+' '
ans+=1
print(ans)
print(c[::-1]) | Title: Remove Duplicates
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya has an array $a$ consisting of $n$ integers. He wants to remove duplicate (equal) elements.
Petya wants to leave only the rightmost entry (occurrence) for each element of the array. The relative order of the remaining unique elements should not be changed.
Input Specification:
The first line contains a single integer $n$ ($1 \le n \le 50$) — the number of elements in Petya's array.
The following line contains a sequence $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 1\,000$) — the Petya's array.
Output Specification:
In the first line print integer $x$ — the number of elements which will be left in Petya's array after he removed the duplicates.
In the second line print $x$ integers separated with a space — Petya's array after he removed the duplicates. For each unique element only the rightmost entry should be left.
Demo Input:
['6\n1 5 5 1 6 1\n', '5\n2 4 2 4 4\n', '5\n6 6 6 6 6\n']
Demo Output:
['3\n5 6 1 \n', '2\n2 4 \n', '1\n6 \n']
Note:
In the first example you should remove two integers $1$, which are in the positions $1$ and $4$. Also you should remove the integer $5$, which is in the position $2$.
In the second example you should remove integer $2$, which is in the position $1$, and two integers $4$, which are in the positions $2$ and $4$.
In the third example you should remove four integers $6$, which are in the positions $1$, $2$, $3$ and $4$. | ```python
a=int(input())
b=list(map(int,input().split()))
b=b[::-1]
d=[];ans=0
c=''
for i in range(len(b)):
if b[i] not in d:
d.append(b[i])
c=c+str(b[i])+' '
ans+=1
print(ans)
print(c[::-1])
``` | 0 |
|
500 | A | New Year Transportation | PROGRAMMING | 1,000 | [
"dfs and similar",
"graphs",
"implementation"
] | null | null | New Year is coming in Line World! In this world, there are *n* cells numbered by integers from 1 to *n*, as a 1<=×<=*n* board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells.
So, user tncks0121 has made a transportation system to move between these cells, to celebrate the New Year. First, he thought of *n*<=-<=1 positive integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1. For every integer *i* where 1<=≤<=*i*<=≤<=*n*<=-<=1 the condition 1<=≤<=*a**i*<=≤<=*n*<=-<=*i* holds. Next, he made *n*<=-<=1 portals, numbered by integers from 1 to *n*<=-<=1. The *i*-th (1<=≤<=*i*<=≤<=*n*<=-<=1) portal connects cell *i* and cell (*i*<=+<=*a**i*), and one can travel from cell *i* to cell (*i*<=+<=*a**i*) using the *i*-th portal. Unfortunately, one cannot use the portal backwards, which means one cannot move from cell (*i*<=+<=*a**i*) to cell *i* using the *i*-th portal. It is easy to see that because of condition 1<=≤<=*a**i*<=≤<=*n*<=-<=*i* one can't leave the Line World using portals.
Currently, I am standing at cell 1, and I want to go to cell *t*. However, I don't know whether it is possible to go there. Please determine whether I can go to cell *t* by only using the construted transportation system. | The first line contains two space-separated integers *n* (3<=≤<=*n*<=≤<=3<=×<=104) and *t* (2<=≤<=*t*<=≤<=*n*) — the number of cells, and the index of the cell which I want to go to.
The second line contains *n*<=-<=1 space-separated integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1 (1<=≤<=*a**i*<=≤<=*n*<=-<=*i*). It is guaranteed, that using the given transportation system, one cannot leave the Line World. | If I can go to cell *t* using the transportation system, print "YES". Otherwise, print "NO". | [
"8 4\n1 2 1 2 1 2 1\n",
"8 5\n1 2 1 2 1 1 1\n"
] | [
"YES\n",
"NO\n"
] | In the first sample, the visited cells are: 1, 2, 4; so we can successfully visit the cell 4.
In the second sample, the possible cells to visit are: 1, 2, 4, 6, 7, 8; so we can't visit the cell 5, which we want to visit. | 500 | [
{
"input": "8 4\n1 2 1 2 1 2 1",
"output": "YES"
},
{
"input": "8 5\n1 2 1 2 1 1 1",
"output": "NO"
},
{
"input": "20 19\n13 16 7 6 12 1 5 7 8 6 5 7 5 5 3 3 2 2 1",
"output": "YES"
},
{
"input": "50 49\n11 7 1 41 26 36 19 16 38 14 36 35 37 27 20 27 3 6 21 2 27 11 18 17 19 16 22 8 8 9 1 7 5 12 5 6 13 6 11 2 6 3 1 5 1 1 2 2 1",
"output": "YES"
},
{
"input": "120 104\n41 15 95 85 34 11 25 42 65 39 77 80 74 17 66 73 21 14 36 63 63 79 45 24 65 7 63 80 51 21 2 19 78 28 71 2 15 23 17 68 62 18 54 39 43 70 3 46 34 23 41 65 32 10 13 18 10 3 16 48 54 18 57 28 3 24 44 50 15 2 20 22 45 44 3 29 2 27 11 2 12 25 25 31 1 2 32 4 11 30 13 16 26 21 1 13 21 8 15 5 18 13 5 15 3 8 13 6 5 1 9 7 1 2 4 1 1 2 1",
"output": "NO"
},
{
"input": "10 3\n8 3 5 4 2 3 2 2 1",
"output": "NO"
},
{
"input": "10 9\n8 3 5 4 2 3 2 2 1",
"output": "YES"
},
{
"input": "3 2\n1 1",
"output": "YES"
},
{
"input": "3 2\n2 1",
"output": "NO"
},
{
"input": "4 2\n2 1 1",
"output": "NO"
},
{
"input": "4 4\n2 2 1",
"output": "YES"
},
{
"input": "8 8\n1 2 1 2 1 2 1",
"output": "YES"
},
{
"input": "3 3\n1 1",
"output": "YES"
},
{
"input": "8 8\n1 2 1 2 1 1 1",
"output": "YES"
},
{
"input": "3 3\n2 1",
"output": "YES"
},
{
"input": "4 4\n1 1 1",
"output": "YES"
},
{
"input": "8 8\n1 1 1 1 1 1 1",
"output": "YES"
},
{
"input": "5 5\n1 1 1 1",
"output": "YES"
}
] | 1,648,636,792 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 28 | 46 | 1,024,000 | s = input()
l = s.split(" ")
n = int(l[0])
t = int(l[1])
d = input()
f = d.split(" ")
g =1
for i in range(n-1):
if g==t:
print('YES')
break
if g>t:
print('NO')
break
g = g + int(f[g-1]) | Title: New Year Transportation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
New Year is coming in Line World! In this world, there are *n* cells numbered by integers from 1 to *n*, as a 1<=×<=*n* board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells.
So, user tncks0121 has made a transportation system to move between these cells, to celebrate the New Year. First, he thought of *n*<=-<=1 positive integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1. For every integer *i* where 1<=≤<=*i*<=≤<=*n*<=-<=1 the condition 1<=≤<=*a**i*<=≤<=*n*<=-<=*i* holds. Next, he made *n*<=-<=1 portals, numbered by integers from 1 to *n*<=-<=1. The *i*-th (1<=≤<=*i*<=≤<=*n*<=-<=1) portal connects cell *i* and cell (*i*<=+<=*a**i*), and one can travel from cell *i* to cell (*i*<=+<=*a**i*) using the *i*-th portal. Unfortunately, one cannot use the portal backwards, which means one cannot move from cell (*i*<=+<=*a**i*) to cell *i* using the *i*-th portal. It is easy to see that because of condition 1<=≤<=*a**i*<=≤<=*n*<=-<=*i* one can't leave the Line World using portals.
Currently, I am standing at cell 1, and I want to go to cell *t*. However, I don't know whether it is possible to go there. Please determine whether I can go to cell *t* by only using the construted transportation system.
Input Specification:
The first line contains two space-separated integers *n* (3<=≤<=*n*<=≤<=3<=×<=104) and *t* (2<=≤<=*t*<=≤<=*n*) — the number of cells, and the index of the cell which I want to go to.
The second line contains *n*<=-<=1 space-separated integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1 (1<=≤<=*a**i*<=≤<=*n*<=-<=*i*). It is guaranteed, that using the given transportation system, one cannot leave the Line World.
Output Specification:
If I can go to cell *t* using the transportation system, print "YES". Otherwise, print "NO".
Demo Input:
['8 4\n1 2 1 2 1 2 1\n', '8 5\n1 2 1 2 1 1 1\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first sample, the visited cells are: 1, 2, 4; so we can successfully visit the cell 4.
In the second sample, the possible cells to visit are: 1, 2, 4, 6, 7, 8; so we can't visit the cell 5, which we want to visit. | ```python
s = input()
l = s.split(" ")
n = int(l[0])
t = int(l[1])
d = input()
f = d.split(" ")
g =1
for i in range(n-1):
if g==t:
print('YES')
break
if g>t:
print('NO')
break
g = g + int(f[g-1])
``` | 0 |
|
673 | A | Bear and Game | PROGRAMMING | 800 | [
"implementation"
] | null | null | Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks.
Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off.
You know that there will be *n* interesting minutes *t*1,<=*t*2,<=...,<=*t**n*. Your task is to calculate for how many minutes Limak will watch the game. | The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=90) — the number of interesting minutes.
The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t*1<=<<=*t*2<=<<=... *t**n*<=≤<=90), given in the increasing order. | Print the number of minutes Limak will watch the game. | [
"3\n7 20 88\n",
"9\n16 20 30 40 50 60 70 80 90\n",
"9\n15 20 30 40 50 60 70 80 90\n"
] | [
"35\n",
"15\n",
"90\n"
] | In the first sample, minutes 21, 22, ..., 35 are all boring and thus Limak will turn TV off immediately after the 35-th minute. So, he would watch the game for 35 minutes.
In the second sample, the first 15 minutes are boring.
In the third sample, there are no consecutive 15 boring minutes. So, Limak will watch the whole game. | 500 | [
{
"input": "3\n7 20 88",
"output": "35"
},
{
"input": "9\n16 20 30 40 50 60 70 80 90",
"output": "15"
},
{
"input": "9\n15 20 30 40 50 60 70 80 90",
"output": "90"
},
{
"input": "30\n6 11 12 15 22 24 30 31 32 33 34 35 40 42 44 45 47 50 53 54 57 58 63 67 75 77 79 81 83 88",
"output": "90"
},
{
"input": "60\n1 2 4 5 6 7 11 14 16 18 20 21 22 23 24 25 26 33 34 35 36 37 38 39 41 42 43 44 46 47 48 49 52 55 56 57 58 59 60 61 63 64 65 67 68 70 71 72 73 74 75 77 78 80 82 83 84 85 86 88",
"output": "90"
},
{
"input": "90\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90",
"output": "90"
},
{
"input": "1\n1",
"output": "16"
},
{
"input": "5\n15 30 45 60 75",
"output": "90"
},
{
"input": "6\n14 29 43 59 70 74",
"output": "58"
},
{
"input": "1\n15",
"output": "30"
},
{
"input": "1\n16",
"output": "15"
},
{
"input": "14\n14 22 27 31 35 44 46 61 62 69 74 79 88 89",
"output": "90"
},
{
"input": "76\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90",
"output": "90"
},
{
"input": "1\n90",
"output": "15"
},
{
"input": "6\n13 17 32 47 60 66",
"output": "81"
},
{
"input": "84\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84",
"output": "90"
},
{
"input": "9\n6 20 27 28 40 53 59 70 85",
"output": "90"
},
{
"input": "12\n14 22 27 31 35 44 62 69 74 79 88 89",
"output": "59"
},
{
"input": "5\n15 30 45 60 74",
"output": "89"
},
{
"input": "72\n3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89",
"output": "54"
},
{
"input": "8\n1 16 30 31 32 33 34 50",
"output": "49"
},
{
"input": "12\n1 3 6 10 15 21 28 36 45 55 66 78",
"output": "90"
},
{
"input": "25\n1 2 3 4 5 6 7 8 9 10 11 23 36 50 65 81 82 83 84 85 86 87 88 89 90",
"output": "80"
},
{
"input": "8\n5 17 20 35 42 53 67 76",
"output": "90"
},
{
"input": "9\n15 28 39 48 55 60 63 64 74",
"output": "89"
},
{
"input": "10\n15 28 39 48 55 60 63 64 74 82",
"output": "90"
},
{
"input": "2\n1 18",
"output": "16"
},
{
"input": "9\n10 20 30 40 50 60 70 80 84",
"output": "90"
},
{
"input": "2\n16 50",
"output": "15"
},
{
"input": "6\n15 30 45 60 75 84",
"output": "90"
},
{
"input": "8\n15 20 30 40 50 60 73 83",
"output": "90"
},
{
"input": "8\n10 20 30 40 50 60 70 80",
"output": "90"
},
{
"input": "3\n1 20 90",
"output": "16"
},
{
"input": "6\n15 30 45 60 74 89",
"output": "90"
}
] | 1,522,129,088 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 77 | 7,065,600 | if __name__ == '__main__':
n = int(input())
t = list(map(int,input().split()))
if t[0] > 15:
print(15)
exit()
if t[n-1] == 90:
print(90)
exit()
for i in range(0,n-1):
if t[i+1] - t[i] - 1 >= 15:
print(t[i]+15)
| Title: Bear and Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks.
Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off.
You know that there will be *n* interesting minutes *t*1,<=*t*2,<=...,<=*t**n*. Your task is to calculate for how many minutes Limak will watch the game.
Input Specification:
The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=90) — the number of interesting minutes.
The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t*1<=<<=*t*2<=<<=... *t**n*<=≤<=90), given in the increasing order.
Output Specification:
Print the number of minutes Limak will watch the game.
Demo Input:
['3\n7 20 88\n', '9\n16 20 30 40 50 60 70 80 90\n', '9\n15 20 30 40 50 60 70 80 90\n']
Demo Output:
['35\n', '15\n', '90\n']
Note:
In the first sample, minutes 21, 22, ..., 35 are all boring and thus Limak will turn TV off immediately after the 35-th minute. So, he would watch the game for 35 minutes.
In the second sample, the first 15 minutes are boring.
In the third sample, there are no consecutive 15 boring minutes. So, Limak will watch the whole game. | ```python
if __name__ == '__main__':
n = int(input())
t = list(map(int,input().split()))
if t[0] > 15:
print(15)
exit()
if t[n-1] == 90:
print(90)
exit()
for i in range(0,n-1):
if t[i+1] - t[i] - 1 >= 15:
print(t[i]+15)
``` | 0 |
|
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word. | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chnenu"
},
{
"input": "ERPZGrodyu",
"output": "erpzgrodyu"
},
{
"input": "KSXBXWpebh",
"output": "KSXBXWPEBH"
},
{
"input": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv",
"output": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv"
},
{
"input": "Amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd",
"output": "amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd"
},
{
"input": "ISAGFJFARYFBLOPQDSHWGMCNKMFTLVFUGNJEWGWNBLXUIATXEkqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv",
"output": "isagfjfaryfblopqdshwgmcnkmftlvfugnjewgwnblxuiatxekqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv"
},
{
"input": "XHRPXZEGHSOCJPICUIXSKFUZUPYTSGJSDIYBCMNMNBPNDBXLXBzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg",
"output": "xhrpxzeghsocjpicuixskfuzupytsgjsdiybcmnmnbpndbxlxbzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg"
},
{
"input": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGAdkcetqjljtmttlonpekcovdzebzdkzggwfsxhapmjkdbuceak",
"output": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGADKCETQJLJTMTTLONPEKCOVDZEBZDKZGGWFSXHAPMJKDBUCEAK"
},
{
"input": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFw",
"output": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFW"
},
{
"input": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB",
"output": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB"
},
{
"input": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge",
"output": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge"
},
{
"input": "Ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw",
"output": "ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw"
},
{
"input": "YQOMLKYAORUQQUCQZCDYMIVDHGWZFFRMUVTAWCHERFPMNRYRIkgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks",
"output": "yqomlkyaoruqqucqzcdymivdhgwzffrmuvtawcherfpmnryrikgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks"
},
{
"input": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJcuusigdqfkumewjtdyitveeiaybwrhomrwmpdipjwiuxfnwuz",
"output": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJCUUSIGDQFKUMEWJTDYITVEEIAYBWRHOMRWMPDIPJWIUXFNWUZ"
},
{
"input": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWuckzcpxosodcjaaakvlxpbiigsiauviilylnnqlyucziihqg",
"output": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWUCKZCPXOSODCJAAAKVLXPBIIGSIAUVIILYLNNQLYUCZIIHQG"
},
{
"input": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO",
"output": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO"
},
{
"input": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDd",
"output": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDD"
},
{
"input": "EBWOVSNLYTWWXrnovgugogtjahnmatomubebyxakas",
"output": "ebwovsnlytwwxrnovgugogtjahnmatomubebyxakas"
},
{
"input": "AORNNDKTRLRVGDPXJKXFTPFpopuzrlqumrxssskvbm",
"output": "AORNNDKTRLRVGDPXJKXFTPFPOPUZRLQUMRXSSSKVBM"
},
{
"input": "DBBZJCWQEVGYHEEUHJAWRHBDPsnplijbwtdibqrrheebfxqcvn",
"output": "dbbzjcwqevgyheeuhjawrhbdpsnplijbwtdibqrrheebfxqcvn"
},
{
"input": "t",
"output": "t"
},
{
"input": "N",
"output": "N"
},
{
"input": "kv",
"output": "kv"
},
{
"input": "Ur",
"output": "ur"
},
{
"input": "CN",
"output": "CN"
}
] | 1,540,436,543 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 218 | 0 | n = input()
l = [i for i in range(len(n)) if n[i]==n[i].lower()]
print(n.lower() if len(l)>=len(n)/2 else n.upper()) | Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
Input Specification:
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Output Specification:
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
Demo Input:
['HoUse\n', 'ViP\n', 'maTRIx\n']
Demo Output:
['house\n', 'VIP\n', 'matrix\n']
Note:
none | ```python
n = input()
l = [i for i in range(len(n)) if n[i]==n[i].lower()]
print(n.lower() if len(l)>=len(n)/2 else n.upper())
``` | 3.9455 |
199 | A | Hexadecimal's theorem | PROGRAMMING | 900 | [
"brute force",
"constructive algorithms",
"implementation",
"number theory"
] | null | null | Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers.
Let's remember how Fibonacci numbers can be calculated. *F*0<==<=0, *F*1<==<=1, and all the next numbers are *F**i*<==<=*F**i*<=-<=2<=+<=*F**i*<=-<=1.
So, Fibonacci numbers make a sequence of numbers: 0, 1, 1, 2, 3, 5, 8, 13, ...
If you haven't run away from the PC in fear, you have to help the virus. Your task is to divide given Fibonacci number *n* by three not necessary different Fibonacci numbers or say that it is impossible. | The input contains of a single integer *n* (0<=≤<=*n*<=<<=109) — the number that should be represented by the rules described above. It is guaranteed that *n* is a Fibonacci number. | Output three required numbers: *a*, *b* and *c*. If there is no answer for the test you have to print "I'm too stupid to solve this problem" without the quotes.
If there are multiple answers, print any of them. | [
"3\n",
"13\n"
] | [
"1 1 1\n",
"2 3 8\n"
] | none | 500 | [
{
"input": "3",
"output": "1 1 1"
},
{
"input": "13",
"output": "2 3 8"
},
{
"input": "0",
"output": "0 0 0"
},
{
"input": "1",
"output": "1 0 0"
},
{
"input": "2",
"output": "1 1 0"
},
{
"input": "1597",
"output": "233 377 987"
},
{
"input": "0",
"output": "0 0 0"
},
{
"input": "1",
"output": "1 0 0"
},
{
"input": "1",
"output": "1 0 0"
},
{
"input": "2",
"output": "1 1 0"
},
{
"input": "3",
"output": "1 1 1"
},
{
"input": "5",
"output": "1 1 3"
},
{
"input": "8",
"output": "1 2 5"
},
{
"input": "13",
"output": "2 3 8"
},
{
"input": "21",
"output": "3 5 13"
},
{
"input": "34",
"output": "5 8 21"
},
{
"input": "55",
"output": "8 13 34"
},
{
"input": "89",
"output": "13 21 55"
},
{
"input": "144",
"output": "21 34 89"
},
{
"input": "233",
"output": "34 55 144"
},
{
"input": "377",
"output": "55 89 233"
},
{
"input": "610",
"output": "89 144 377"
},
{
"input": "987",
"output": "144 233 610"
},
{
"input": "1597",
"output": "233 377 987"
},
{
"input": "2584",
"output": "377 610 1597"
},
{
"input": "4181",
"output": "610 987 2584"
},
{
"input": "6765",
"output": "987 1597 4181"
},
{
"input": "10946",
"output": "1597 2584 6765"
},
{
"input": "17711",
"output": "2584 4181 10946"
},
{
"input": "28657",
"output": "4181 6765 17711"
},
{
"input": "46368",
"output": "6765 10946 28657"
},
{
"input": "75025",
"output": "10946 17711 46368"
},
{
"input": "121393",
"output": "17711 28657 75025"
},
{
"input": "196418",
"output": "28657 46368 121393"
},
{
"input": "317811",
"output": "46368 75025 196418"
},
{
"input": "514229",
"output": "75025 121393 317811"
},
{
"input": "832040",
"output": "121393 196418 514229"
},
{
"input": "1346269",
"output": "196418 317811 832040"
},
{
"input": "2178309",
"output": "317811 514229 1346269"
},
{
"input": "3524578",
"output": "514229 832040 2178309"
},
{
"input": "5702887",
"output": "832040 1346269 3524578"
},
{
"input": "9227465",
"output": "1346269 2178309 5702887"
},
{
"input": "14930352",
"output": "2178309 3524578 9227465"
},
{
"input": "24157817",
"output": "3524578 5702887 14930352"
},
{
"input": "39088169",
"output": "5702887 9227465 24157817"
},
{
"input": "63245986",
"output": "9227465 14930352 39088169"
},
{
"input": "102334155",
"output": "14930352 24157817 63245986"
},
{
"input": "165580141",
"output": "24157817 39088169 102334155"
},
{
"input": "267914296",
"output": "39088169 63245986 165580141"
},
{
"input": "433494437",
"output": "63245986 102334155 267914296"
},
{
"input": "701408733",
"output": "102334155 165580141 433494437"
},
{
"input": "701408733",
"output": "102334155 165580141 433494437"
},
{
"input": "102334155",
"output": "14930352 24157817 63245986"
},
{
"input": "63245986",
"output": "9227465 14930352 39088169"
}
] | 1,620,793,832 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 2 | 2,000 | 7,168,000 | q = int(input())
m,n = 0,1
while m+n != q:
m,n = n,m+n
print(0,m,n)
| Title: Hexadecimal's theorem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers.
Let's remember how Fibonacci numbers can be calculated. *F*0<==<=0, *F*1<==<=1, and all the next numbers are *F**i*<==<=*F**i*<=-<=2<=+<=*F**i*<=-<=1.
So, Fibonacci numbers make a sequence of numbers: 0, 1, 1, 2, 3, 5, 8, 13, ...
If you haven't run away from the PC in fear, you have to help the virus. Your task is to divide given Fibonacci number *n* by three not necessary different Fibonacci numbers or say that it is impossible.
Input Specification:
The input contains of a single integer *n* (0<=≤<=*n*<=<<=109) — the number that should be represented by the rules described above. It is guaranteed that *n* is a Fibonacci number.
Output Specification:
Output three required numbers: *a*, *b* and *c*. If there is no answer for the test you have to print "I'm too stupid to solve this problem" without the quotes.
If there are multiple answers, print any of them.
Demo Input:
['3\n', '13\n']
Demo Output:
['1 1 1\n', '2 3 8\n']
Note:
none | ```python
q = int(input())
m,n = 0,1
while m+n != q:
m,n = n,m+n
print(0,m,n)
``` | 0 |
|
999 | B | Reversing Encryption | PROGRAMMING | 900 | [
"implementation"
] | null | null | A string $s$ of length $n$ can be encrypted by the following algorithm:
- iterate over all divisors of $n$ in decreasing order (i.e. from $n$ to $1$), - for each divisor $d$, reverse the substring $s[1 \dots d]$ (i.e. the substring which starts at position $1$ and ends at position $d$).
For example, the above algorithm applied to the string $s$="codeforces" leads to the following changes: "codeforces" $\to$ "secrofedoc" $\to$ "orcesfedoc" $\to$ "rocesfedoc" $\to$ "rocesfedoc" (obviously, the last reverse operation doesn't change the string because $d=1$).
You are given the encrypted string $t$. Your task is to decrypt this string, i.e., to find a string $s$ such that the above algorithm results in string $t$. It can be proven that this string $s$ always exists and is unique. | The first line of input consists of a single integer $n$ ($1 \le n \le 100$) — the length of the string $t$. The second line of input consists of the string $t$. The length of $t$ is $n$, and it consists only of lowercase Latin letters. | Print a string $s$ such that the above algorithm results in $t$. | [
"10\nrocesfedoc\n",
"16\nplmaetwoxesisiht\n",
"1\nz\n"
] | [
"codeforces\n",
"thisisexampletwo\n",
"z\n"
] | The first example is described in the problem statement. | 0 | [
{
"input": "10\nrocesfedoc",
"output": "codeforces"
},
{
"input": "16\nplmaetwoxesisiht",
"output": "thisisexampletwo"
},
{
"input": "1\nz",
"output": "z"
},
{
"input": "2\nir",
"output": "ri"
},
{
"input": "3\nilj",
"output": "jli"
},
{
"input": "4\njfyy",
"output": "yyjf"
},
{
"input": "6\nkrdych",
"output": "hcyrkd"
},
{
"input": "60\nfnebsopcvmlaoecpzmakqigyuutueuozjxutlwwiochekmhjgwxsgfbcrpqj",
"output": "jqprcbfgsxwgjhmkehcoiwwltuxjzokamzpalobnfespcvmoecqigyuutueu"
},
{
"input": "64\nhnlzzhrvqnldswxfsrowfhmyzbxtyoxhogudasgywxycyhzgiseerbislcncvnwy",
"output": "ywnvcnclsibreesigzhycyxwygsadugofxwsdlnqzlhnzhrvsrowfhmyzbxtyoxh"
},
{
"input": "97\nqnqrmdhmbubaijtwsecbidqouhlecladwgwcuxbigckrfzasnbfbslukoayhcgquuacygakhxoubibxtqkpyyhzjipylujgrc",
"output": "crgjulypijzhyypkqtxbibuoxhkagycauuqgchyaokulsbfbnsazfrkcgibxucwgwdalcelhuoqdibceswtjiabubmhdmrqnq"
},
{
"input": "100\nedykhvzcntljuuoqghptioetqnfllwekzohiuaxelgecabvsbibgqodqxvyfkbyjwtgbyhvssntinkwsinwsmalusiwnjmtcoovf",
"output": "fvooctmjnwisulamswniswknitnssvhybgtwjybkfyvxqdoqgbqteoitnczvkyedhljuuoqghptnfllwekzohiuaxelgecabvsbi"
},
{
"input": "96\nqtbcksuvxonzbkokhqlgkrvimzqmqnrvqlihrmksldyydacbtckfphenxszcnzhfjmpeykrvshgiboivkvabhrpphgavvprz",
"output": "zrpvvaghpprhbavkviobighsvrkyepmjfhznczsxnehpfkctvrnqmqzmkokbvuctqbksxonzhqlgkrviqlihrmksldyydacb"
},
{
"input": "90\nmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm",
"output": "mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm"
},
{
"input": "89\nwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww",
"output": "wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww"
},
{
"input": "99\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq",
"output": "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq"
},
{
"input": "100\noooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo",
"output": "oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo"
},
{
"input": "60\nwwwwwxwwwwwwfhwwhwwwwwwawwwwwwwwwwwwwnwwwwwwwwwwwwwwwwwwwwww",
"output": "wwwwwwwwwwwwwwwwwwwwwwnwwwwwwwwwwhwwwxwwwwwwwwwfhwwwwawwwwww"
},
{
"input": "90\ncccchccccccccccccccccccccccccccwcccccccccgcccccchccccccccccccccccccccccxccccccncccccccuccc",
"output": "cccucccccccnccccccxcccccccccccccccccccccchccccccccccccccccccccccchccccccccccwcccccccccgccc"
},
{
"input": "97\nfwffffffffffffffffffffffffrffffffffffffffzfffffffffffffffftfcfffffffqffffffffffffffffffffffyfffff",
"output": "fffffyffffffffffffffffffffffqfffffffcftffffffffffffffffzffffffffffffffrffffffffffffffffffffffffwf"
},
{
"input": "100\ndjjjjjjjjjjgjjjjjjjjjjjjjjsvjjjjjjjjjjmjjjjjjjjjjjjjajjjjjjajjjjjjrjjjjjjjjjjjjrjjtjjjjjjjjjjjjjojjj",
"output": "jjjojjjjjjjjjjjjjtjjrjjjjjjjjjjjjrjjjjjjajjjjjjajjjjjjjjjjjjjjdjjjgjjjjjjjjjsvjjjjjjjjjjmjjjjjjjjjjj"
}
] | 1,677,855,808 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 46 | 0 | n=int(input())
s=input()
d=[]
for i in range(n):
i+=1
if (n/i)%1==0:
d.append(i)
for t in d:
r=list(s[:t])
r.reverse()
s=''.join(r)+s[t:]
print(s)
| Title: Reversing Encryption
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A string $s$ of length $n$ can be encrypted by the following algorithm:
- iterate over all divisors of $n$ in decreasing order (i.e. from $n$ to $1$), - for each divisor $d$, reverse the substring $s[1 \dots d]$ (i.e. the substring which starts at position $1$ and ends at position $d$).
For example, the above algorithm applied to the string $s$="codeforces" leads to the following changes: "codeforces" $\to$ "secrofedoc" $\to$ "orcesfedoc" $\to$ "rocesfedoc" $\to$ "rocesfedoc" (obviously, the last reverse operation doesn't change the string because $d=1$).
You are given the encrypted string $t$. Your task is to decrypt this string, i.e., to find a string $s$ such that the above algorithm results in string $t$. It can be proven that this string $s$ always exists and is unique.
Input Specification:
The first line of input consists of a single integer $n$ ($1 \le n \le 100$) — the length of the string $t$. The second line of input consists of the string $t$. The length of $t$ is $n$, and it consists only of lowercase Latin letters.
Output Specification:
Print a string $s$ such that the above algorithm results in $t$.
Demo Input:
['10\nrocesfedoc\n', '16\nplmaetwoxesisiht\n', '1\nz\n']
Demo Output:
['codeforces\n', 'thisisexampletwo\n', 'z\n']
Note:
The first example is described in the problem statement. | ```python
n=int(input())
s=input()
d=[]
for i in range(n):
i+=1
if (n/i)%1==0:
d.append(i)
for t in d:
r=list(s[:t])
r.reverse()
s=''.join(r)+s[t:]
print(s)
``` | 3 |
|
0 | none | none | none | 0 | [
"none"
] | null | null | Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are *n* players (including Limak himself) and right now all of them have bids on the table. *i*-th of them has bid with size *a**i* dollars.
Each player can double his bid any number of times and triple his bid any number of times. The casino has a great jackpot for making all bids equal. Is it possible that Limak and his friends will win a jackpot? | First line of input contains an integer *n* (2<=≤<=*n*<=≤<=105), the number of players.
The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the bids of players. | Print "Yes" (without the quotes) if players can make their bids become equal, or "No" otherwise. | [
"4\n75 150 75 50\n",
"3\n100 150 250\n"
] | [
"Yes\n",
"No\n"
] | In the first sample test first and third players should double their bids twice, second player should double his bid once and fourth player should both double and triple his bid.
It can be shown that in the second sample test there is no way to make all bids equal. | 0 | [
{
"input": "4\n75 150 75 50",
"output": "Yes"
},
{
"input": "3\n100 150 250",
"output": "No"
},
{
"input": "7\n34 34 68 34 34 68 34",
"output": "Yes"
},
{
"input": "10\n72 96 12 18 81 20 6 2 54 1",
"output": "No"
},
{
"input": "20\n958692492 954966768 77387000 724664764 101294996 614007760 202904092 555293973 707655552 108023967 73123445 612562357 552908390 914853758 915004122 466129205 122853497 814592742 373389439 818473058",
"output": "No"
},
{
"input": "2\n1 1",
"output": "Yes"
},
{
"input": "2\n72 72",
"output": "Yes"
},
{
"input": "2\n49 42",
"output": "No"
},
{
"input": "3\n1000000000 1000000000 1000000000",
"output": "Yes"
},
{
"input": "6\n162000 96000 648000 1000 864000 432000",
"output": "Yes"
},
{
"input": "8\n600000 100000 100000 100000 900000 600000 900000 600000",
"output": "Yes"
},
{
"input": "12\n2048 1024 6144 1024 3072 3072 6144 1024 4096 2048 6144 3072",
"output": "Yes"
},
{
"input": "20\n246 246 246 246 246 246 246 246 246 246 246 246 246 246 246 246 246 246 246 246",
"output": "Yes"
},
{
"input": "50\n840868705 387420489 387420489 795385082 634350497 206851546 536870912 536870912 414927754 387420489 387420489 536870912 387420489 149011306 373106005 536870912 700746206 387420489 777952883 847215247 176645254 576664386 387420489 230876513 536870912 536870912 536870912 387420489 387420489 536870912 460495524 528643722 387420489 536870912 470369206 899619085 387420489 631148352 387420489 387420489 536870912 414666674 521349938 776784669 387420489 102428009 536870912 387420489 536870912 718311009",
"output": "No"
},
{
"input": "2\n5 6",
"output": "No"
},
{
"input": "3\n536870912 387420489 257407169",
"output": "No"
},
{
"input": "4\n2 2 5 2",
"output": "No"
},
{
"input": "2\n33554432 59049",
"output": "Yes"
},
{
"input": "3\n536870912 387420489 387420489",
"output": "Yes"
},
{
"input": "2\n1 5",
"output": "No"
},
{
"input": "18\n2 3 5 7 11 13 17 19 23 29 31 37 43 47 53 59 67 71",
"output": "No"
},
{
"input": "2\n1 30",
"output": "No"
},
{
"input": "3\n335544320 71744535 71744535",
"output": "Yes"
},
{
"input": "5\n1000000000 999999999 999999998 999999997 999999996",
"output": "No"
},
{
"input": "2\n25 5",
"output": "No"
},
{
"input": "4\n75 150 75 5",
"output": "No"
},
{
"input": "3\n536870912 387420489 362797056",
"output": "Yes"
},
{
"input": "3\n536870912 387420489 89",
"output": "No"
},
{
"input": "4\n547 2606459 222763549 143466789",
"output": "No"
},
{
"input": "3\n129140163 33554432 1",
"output": "Yes"
},
{
"input": "10\n244140625 244140625 244140625 244140625 244140625 244140625 244140625 244140625 536870912 387420489",
"output": "No"
},
{
"input": "3\n5 5 1",
"output": "No"
},
{
"input": "5\n3 7 29 36760123 823996703",
"output": "No"
}
] | 1,573,770,759 | 4,419 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 26 | 2,000 | 11,980,800 | import sys
input = sys.stdin.readline
from functools import reduce
def li():return [int(i) for i in input().rstrip('\n').split(' ')]
def val():return int(input())
def gcd(a,b):
if(b==0):
return a
else:
return gcd(b,a%b)
n = val()
l = li()
def lcm(a,b):return a*b//gcd(a,b)
lc = l[0]
for i in range(1,n):
lc = lcm(lc,l[i])
for i in set(l):
temp = lc//i
while not temp%2:temp//=2
while not temp%3:temp//=3
if temp!=1 and gcd(temp,2) == 1 and gcd(temp,3) == 1 and gcd(gcd(temp,2),3) == 1 and gcd(gcd(temp,3),2) == 1:
print('NO')
exit()
print('YES') | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are *n* players (including Limak himself) and right now all of them have bids on the table. *i*-th of them has bid with size *a**i* dollars.
Each player can double his bid any number of times and triple his bid any number of times. The casino has a great jackpot for making all bids equal. Is it possible that Limak and his friends will win a jackpot?
Input Specification:
First line of input contains an integer *n* (2<=≤<=*n*<=≤<=105), the number of players.
The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the bids of players.
Output Specification:
Print "Yes" (without the quotes) if players can make their bids become equal, or "No" otherwise.
Demo Input:
['4\n75 150 75 50\n', '3\n100 150 250\n']
Demo Output:
['Yes\n', 'No\n']
Note:
In the first sample test first and third players should double their bids twice, second player should double his bid once and fourth player should both double and triple his bid.
It can be shown that in the second sample test there is no way to make all bids equal. | ```python
import sys
input = sys.stdin.readline
from functools import reduce
def li():return [int(i) for i in input().rstrip('\n').split(' ')]
def val():return int(input())
def gcd(a,b):
if(b==0):
return a
else:
return gcd(b,a%b)
n = val()
l = li()
def lcm(a,b):return a*b//gcd(a,b)
lc = l[0]
for i in range(1,n):
lc = lcm(lc,l[i])
for i in set(l):
temp = lc//i
while not temp%2:temp//=2
while not temp%3:temp//=3
if temp!=1 and gcd(temp,2) == 1 and gcd(temp,3) == 1 and gcd(gcd(temp,2),3) == 1 and gcd(gcd(temp,3),2) == 1:
print('NO')
exit()
print('YES')
``` | 0 |
|
546 | A | Soldier and Bananas | PROGRAMMING | 800 | [
"brute force",
"implementation",
"math"
] | null | null | A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas? | The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants. | Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0. | [
"3 17 4\n"
] | [
"13"
] | none | 500 | [
{
"input": "3 17 4",
"output": "13"
},
{
"input": "1 2 1",
"output": "0"
},
{
"input": "1 1 1",
"output": "0"
},
{
"input": "1 5 6",
"output": "16"
},
{
"input": "1 1000000000 1",
"output": "0"
},
{
"input": "1000 0 1000",
"output": "500500000"
},
{
"input": "859 453892 543",
"output": "126416972"
},
{
"input": "1000 1000000000 1000",
"output": "0"
},
{
"input": "1000 500500000 1000",
"output": "0"
},
{
"input": "1000 500500001 1000",
"output": "0"
},
{
"input": "1000 500499999 1000",
"output": "1"
},
{
"input": "634 87973 214",
"output": "14497197"
},
{
"input": "432 10000 241",
"output": "12587552"
},
{
"input": "111 111111111 111",
"output": "0"
},
{
"input": "20 43 3",
"output": "77"
}
] | 1,698,001,065 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 31 | 0 | k,n,w=map(int,input().split())
s=0
for i in range(1,w+1):
s=s+(i*k)
c=s-n
print(c)
| Title: Soldier and Bananas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas?
Input Specification:
The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants.
Output Specification:
Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0.
Demo Input:
['3 17 4\n']
Demo Output:
['13']
Note:
none | ```python
k,n,w=map(int,input().split())
s=0
for i in range(1,w+1):
s=s+(i*k)
c=s-n
print(c)
``` | 0 |
|
676 | A | Nicholas and Permutation | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | Nicholas has an array *a* that contains *n* distinct integers from 1 to *n*. In other words, Nicholas has a permutation of size *n*.
Nicholas want the minimum element (integer 1) and the maximum element (integer *n*) to be as far as possible from each other. He wants to perform exactly one swap in order to maximize the distance between the minimum and the maximum elements. The distance between two elements is considered to be equal to the absolute difference between their positions. | The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100) — the size of the permutation.
The second line of the input contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*), where *a**i* is equal to the element at the *i*-th position. | Print a single integer — the maximum possible distance between the minimum and the maximum elements Nicholas can achieve by performing exactly one swap. | [
"5\n4 5 1 3 2\n",
"7\n1 6 5 3 4 7 2\n",
"6\n6 5 4 3 2 1\n"
] | [
"3\n",
"6\n",
"5\n"
] | In the first sample, one may obtain the optimal answer by swapping elements 1 and 2.
In the second sample, the minimum and the maximum elements will be located in the opposite ends of the array if we swap 7 and 2.
In the third sample, the distance between the minimum and the maximum elements is already maximum possible, so we just perform some unnecessary swap, for example, one can swap 5 and 2. | 500 | [
{
"input": "5\n4 5 1 3 2",
"output": "3"
},
{
"input": "7\n1 6 5 3 4 7 2",
"output": "6"
},
{
"input": "6\n6 5 4 3 2 1",
"output": "5"
},
{
"input": "2\n1 2",
"output": "1"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "3\n2 3 1",
"output": "2"
},
{
"input": "4\n4 1 3 2",
"output": "3"
},
{
"input": "5\n1 4 5 2 3",
"output": "4"
},
{
"input": "6\n4 6 3 5 2 1",
"output": "5"
},
{
"input": "7\n1 5 3 6 2 4 7",
"output": "6"
},
{
"input": "100\n76 70 67 54 40 1 48 63 64 36 42 90 99 27 47 17 93 7 13 84 16 57 74 5 83 61 19 56 52 92 38 91 82 79 34 66 71 28 37 98 35 94 77 53 73 10 26 80 15 32 8 81 3 95 44 46 72 6 33 11 21 85 4 30 24 51 49 96 87 55 14 31 12 60 45 9 29 22 58 18 88 2 50 59 20 86 23 41 100 39 62 68 69 97 78 43 25 89 65 75",
"output": "94"
},
{
"input": "8\n4 5 3 8 6 7 1 2",
"output": "6"
},
{
"input": "9\n6 8 5 3 4 7 9 2 1",
"output": "8"
},
{
"input": "10\n8 7 10 1 2 3 4 6 5 9",
"output": "7"
},
{
"input": "11\n5 4 6 9 10 11 7 3 1 2 8",
"output": "8"
},
{
"input": "12\n3 6 7 8 9 10 12 5 4 2 11 1",
"output": "11"
},
{
"input": "13\n8 4 3 7 5 11 9 1 10 2 13 12 6",
"output": "10"
},
{
"input": "14\n6 10 13 9 7 1 12 14 3 2 5 4 11 8",
"output": "8"
},
{
"input": "15\n3 14 13 12 7 2 4 11 15 1 8 6 5 10 9",
"output": "9"
},
{
"input": "16\n11 6 9 8 7 14 12 13 10 15 2 5 3 1 4 16",
"output": "15"
},
{
"input": "17\n13 12 5 3 9 16 8 14 2 4 10 1 6 11 7 15 17",
"output": "16"
},
{
"input": "18\n8 6 14 17 9 11 15 13 5 3 18 1 2 7 12 16 4 10",
"output": "11"
},
{
"input": "19\n12 19 3 11 15 6 18 14 5 10 2 13 9 7 4 8 17 16 1",
"output": "18"
},
{
"input": "20\n15 17 10 20 7 2 16 9 13 6 18 5 19 8 11 14 4 12 3 1",
"output": "19"
},
{
"input": "21\n1 9 14 18 13 12 11 20 16 2 4 19 15 7 6 17 8 5 3 10 21",
"output": "20"
},
{
"input": "22\n8 3 17 4 16 21 14 11 10 15 6 18 13 12 22 20 5 2 9 7 19 1",
"output": "21"
},
{
"input": "23\n1 23 11 20 9 3 12 4 7 17 5 15 2 10 18 16 8 22 14 13 19 21 6",
"output": "22"
},
{
"input": "24\n2 10 23 22 20 19 18 16 11 12 15 17 21 8 24 13 1 5 6 7 14 3 9 4",
"output": "16"
},
{
"input": "25\n12 13 22 17 1 18 14 5 21 2 10 4 3 23 11 6 20 8 24 16 15 19 9 7 25",
"output": "24"
},
{
"input": "26\n6 21 20 16 26 17 11 2 24 4 1 12 14 8 25 7 15 10 22 5 13 18 9 23 19 3",
"output": "21"
},
{
"input": "27\n20 14 18 10 5 3 9 4 24 22 21 27 17 15 26 2 23 7 12 11 6 8 19 25 16 13 1",
"output": "26"
},
{
"input": "28\n28 13 16 6 1 12 4 27 22 7 18 3 21 26 25 11 5 10 20 24 19 15 14 8 23 17 9 2",
"output": "27"
},
{
"input": "29\n21 11 10 25 2 5 9 16 29 8 17 4 15 13 6 22 7 24 19 12 18 20 1 3 23 28 27 14 26",
"output": "22"
},
{
"input": "30\n6 19 14 22 26 17 27 8 25 3 24 30 4 18 23 16 9 13 29 20 15 2 5 11 28 12 1 10 21 7",
"output": "26"
},
{
"input": "31\n29 13 26 27 9 28 2 16 30 21 12 11 3 31 23 6 22 20 1 5 14 24 19 18 8 4 10 17 15 25 7",
"output": "18"
},
{
"input": "32\n15 32 11 3 18 23 19 14 5 8 6 21 13 24 25 4 16 9 27 20 17 31 2 22 7 12 30 1 26 10 29 28",
"output": "30"
},
{
"input": "33\n22 13 10 33 8 25 15 14 21 28 27 19 26 24 1 12 5 11 32 20 30 31 18 4 6 23 7 29 16 2 17 9 3",
"output": "29"
},
{
"input": "34\n34 30 7 16 6 1 10 23 29 13 15 25 32 26 18 11 28 3 14 21 19 5 31 33 4 17 8 9 24 20 27 22 2 12",
"output": "33"
},
{
"input": "35\n24 33 20 8 34 11 31 25 2 4 18 13 9 35 16 30 23 32 17 1 14 22 19 21 28 26 3 15 5 12 27 29 10 6 7",
"output": "21"
},
{
"input": "36\n1 32 27 35 22 7 34 15 18 36 31 28 13 2 10 21 20 17 16 4 3 24 19 29 11 12 25 5 33 26 14 6 9 23 30 8",
"output": "35"
},
{
"input": "37\n24 1 12 23 11 6 30 15 4 21 13 20 25 17 5 8 36 19 32 26 14 9 7 18 10 29 37 35 16 2 22 34 3 27 31 33 28",
"output": "35"
},
{
"input": "38\n9 35 37 28 36 21 10 25 19 4 26 5 22 7 27 18 6 14 15 24 1 17 11 34 20 8 2 16 3 23 32 31 13 12 38 33 30 29",
"output": "34"
},
{
"input": "39\n16 28 4 33 26 36 25 23 22 30 27 7 12 34 17 6 3 38 10 24 13 31 29 39 14 32 9 20 35 11 18 21 8 2 15 37 5 19 1",
"output": "38"
},
{
"input": "40\n35 39 28 11 9 31 36 8 5 32 26 19 38 33 2 22 23 25 6 37 12 7 3 10 17 24 20 16 27 4 34 15 40 14 18 13 29 21 30 1",
"output": "39"
},
{
"input": "41\n24 18 7 23 3 15 1 17 25 5 30 10 34 36 2 14 9 21 41 40 20 28 33 35 12 22 11 8 19 16 31 27 26 32 29 4 13 38 37 39 6",
"output": "34"
},
{
"input": "42\n42 15 24 26 4 34 19 29 38 32 31 33 14 41 21 3 11 39 25 6 5 20 23 10 16 36 18 28 27 1 7 40 22 30 9 2 37 17 8 12 13 35",
"output": "41"
},
{
"input": "43\n43 24 20 13 22 29 28 4 30 3 32 40 31 8 7 9 35 27 18 5 42 6 17 19 23 12 41 21 16 37 33 34 2 14 36 38 25 10 15 39 26 11 1",
"output": "42"
},
{
"input": "44\n4 38 6 40 29 3 44 2 30 35 25 36 34 10 11 31 21 7 14 23 37 19 27 18 5 22 1 16 17 9 39 13 15 32 43 8 41 26 42 12 24 33 20 28",
"output": "37"
},
{
"input": "45\n45 29 24 2 31 5 34 41 26 44 33 43 15 3 4 11 21 37 27 12 14 39 23 42 16 6 13 19 8 38 20 9 25 22 40 17 32 35 18 10 28 7 30 36 1",
"output": "44"
},
{
"input": "46\n29 3 12 33 45 40 19 17 25 27 28 1 16 23 24 46 31 8 44 15 5 32 22 11 4 36 34 10 35 26 21 7 14 2 18 9 20 41 6 43 42 37 38 13 39 30",
"output": "34"
},
{
"input": "47\n7 3 8 12 24 16 29 10 28 38 1 20 37 40 21 5 15 6 45 23 36 44 25 43 41 4 11 42 18 35 32 31 39 33 27 30 22 34 14 13 17 47 19 9 46 26 2",
"output": "41"
},
{
"input": "48\n29 26 14 18 34 33 13 39 32 1 37 20 35 19 28 48 30 23 46 27 5 22 24 38 12 15 8 36 43 45 16 47 6 9 31 40 44 17 2 41 11 42 25 4 21 3 10 7",
"output": "38"
},
{
"input": "49\n16 7 42 32 11 35 15 8 23 41 6 20 47 24 9 45 49 2 37 48 25 28 5 18 3 19 12 4 22 33 13 14 10 36 44 17 40 38 30 26 1 43 29 46 21 34 27 39 31",
"output": "40"
},
{
"input": "50\n31 45 3 34 13 43 32 4 42 9 7 8 24 14 35 6 19 46 44 17 18 1 25 20 27 41 2 16 12 10 11 47 38 21 28 49 30 15 50 36 29 26 22 39 48 5 23 37 33 40",
"output": "38"
},
{
"input": "51\n47 29 2 11 43 44 27 1 39 14 25 30 33 21 38 45 34 51 16 50 42 31 41 46 15 48 13 19 6 37 35 7 22 28 20 4 17 10 5 8 24 40 9 36 18 49 12 26 23 3 32",
"output": "43"
},
{
"input": "52\n16 45 23 7 15 19 43 20 4 32 35 36 9 50 5 26 38 46 13 33 12 2 48 37 41 31 10 28 8 42 3 21 11 1 17 27 34 30 44 40 6 51 49 47 25 22 18 24 52 29 14 39",
"output": "48"
},
{
"input": "53\n53 30 50 22 51 31 32 38 12 7 39 43 1 23 6 8 24 52 2 21 34 13 3 35 5 15 19 11 47 18 9 20 29 4 36 45 27 41 25 48 16 46 44 17 10 14 42 26 40 28 33 37 49",
"output": "52"
},
{
"input": "54\n6 39 17 3 45 52 16 21 23 48 42 36 13 37 46 10 43 27 49 7 38 32 31 30 15 25 2 29 8 51 54 19 41 44 24 34 22 5 20 14 12 1 33 40 4 26 9 35 18 28 47 50 11 53",
"output": "41"
},
{
"input": "55\n26 15 31 21 32 43 34 51 7 12 5 44 17 54 18 25 48 47 20 3 41 24 45 2 11 22 29 39 37 53 35 28 36 9 50 10 30 38 19 13 4 8 27 1 42 6 49 23 55 40 33 16 46 14 52",
"output": "48"
},
{
"input": "56\n6 20 38 46 10 11 40 19 5 1 47 33 4 18 32 36 37 45 56 49 48 52 12 26 31 14 2 9 24 3 16 51 41 43 23 17 34 7 29 50 55 25 39 44 22 27 54 8 28 35 30 42 13 53 21 15",
"output": "46"
},
{
"input": "57\n39 28 53 36 3 6 12 56 55 20 50 19 43 42 18 40 24 52 38 17 33 23 22 41 14 7 26 44 45 16 35 1 8 47 31 5 30 51 32 4 37 25 13 34 54 21 46 10 15 11 2 27 29 48 49 9 57",
"output": "56"
},
{
"input": "58\n1 26 28 14 22 33 57 40 9 42 44 37 24 19 58 12 48 3 34 31 49 4 16 47 55 52 27 23 46 18 20 32 56 6 39 36 41 38 13 43 45 21 53 54 29 17 5 10 25 30 2 35 11 7 15 51 8 50",
"output": "57"
},
{
"input": "59\n1 27 10 37 53 9 14 49 46 26 50 42 59 11 47 15 24 56 43 45 44 38 5 8 58 30 52 12 23 32 22 3 31 41 2 25 29 6 54 16 35 33 18 55 4 51 57 28 40 19 13 21 7 39 36 48 34 17 20",
"output": "58"
},
{
"input": "60\n60 27 34 32 54 55 33 12 40 3 47 44 50 39 38 59 11 25 17 15 16 30 21 31 10 52 5 23 4 48 6 26 36 57 14 22 8 56 58 9 24 7 37 53 42 43 20 49 51 19 2 46 28 18 35 13 29 45 41 1",
"output": "59"
},
{
"input": "61\n61 11 26 29 31 40 32 30 35 3 18 52 9 53 42 4 50 54 20 58 28 49 22 12 2 19 16 15 57 34 51 43 7 17 25 41 56 47 55 60 46 14 44 45 24 27 33 1 48 13 59 23 38 39 6 5 36 10 8 37 21",
"output": "60"
},
{
"input": "62\n21 23 34 38 11 61 55 30 37 48 54 51 46 47 6 56 36 49 1 35 12 28 29 20 43 42 5 8 22 57 44 4 53 10 58 33 27 25 16 45 50 40 18 15 3 41 39 2 7 60 59 13 32 24 52 31 14 9 19 26 17 62",
"output": "61"
},
{
"input": "63\n2 5 29 48 31 26 21 16 47 24 43 22 61 28 6 39 60 27 14 52 37 7 53 8 62 56 63 10 50 18 44 13 4 9 25 11 23 42 45 41 59 12 32 36 40 51 1 35 49 54 57 20 19 34 38 46 33 3 55 15 30 58 17",
"output": "46"
},
{
"input": "64\n23 5 51 40 12 46 44 8 64 31 58 55 45 24 54 39 21 19 52 61 30 42 16 18 15 32 53 22 28 26 11 25 48 56 27 9 29 41 35 49 59 38 62 7 34 1 20 33 60 17 2 3 43 37 57 14 6 36 13 10 50 4 63 47",
"output": "55"
},
{
"input": "65\n10 11 55 43 53 25 35 26 16 37 41 38 59 21 48 2 65 49 17 23 18 30 62 36 3 4 47 15 28 63 57 54 31 46 44 12 51 7 29 13 56 52 14 22 39 19 8 27 45 5 6 34 32 61 20 50 9 24 33 58 60 40 1 42 64",
"output": "62"
},
{
"input": "66\n66 39 3 2 55 53 60 54 12 49 10 30 59 26 32 46 50 56 7 13 43 36 24 28 11 8 6 21 35 25 42 57 23 45 64 5 34 61 27 51 52 9 15 1 38 17 63 48 37 20 58 14 47 19 22 41 31 44 33 65 4 62 40 18 16 29",
"output": "65"
},
{
"input": "67\n66 16 2 53 35 38 49 28 18 6 36 58 21 47 27 5 50 62 44 12 52 37 11 56 15 31 25 65 17 29 59 41 7 42 4 43 39 10 1 40 24 13 20 54 19 67 46 60 51 45 64 30 8 33 26 9 3 22 34 23 57 48 55 14 63 61 32",
"output": "45"
},
{
"input": "68\n13 6 27 21 65 23 59 14 62 43 33 31 38 41 67 20 16 25 42 4 28 40 29 9 64 17 2 26 32 58 60 53 46 48 47 54 44 50 39 19 30 57 61 1 11 18 37 24 55 15 63 34 8 52 56 7 10 12 35 66 5 36 45 49 68 22 51 3",
"output": "64"
},
{
"input": "69\n29 49 25 51 21 35 11 61 39 54 40 37 60 42 27 33 59 53 34 10 46 2 23 69 8 47 58 36 1 38 19 12 7 48 13 3 6 22 18 5 65 24 50 41 66 44 67 57 4 56 62 43 9 30 14 15 28 31 64 26 16 55 68 17 32 20 45 52 63",
"output": "45"
},
{
"input": "70\n19 12 15 18 36 16 61 69 24 7 11 13 3 48 55 21 37 17 43 31 41 22 28 32 27 63 38 49 59 56 30 25 67 51 52 45 50 44 66 57 26 60 5 46 33 6 23 34 8 40 2 68 14 39 65 64 62 42 47 54 10 53 9 1 70 58 20 4 29 35",
"output": "64"
},
{
"input": "71\n40 6 62 3 41 52 31 66 27 16 35 5 17 60 2 15 51 22 67 61 71 53 1 64 8 45 28 18 50 30 12 69 20 26 10 37 36 49 70 32 33 11 57 14 9 55 4 58 29 25 44 65 39 48 24 47 19 46 56 38 34 42 59 63 54 23 7 68 43 13 21",
"output": "50"
},
{
"input": "72\n52 64 71 40 32 10 62 21 11 37 38 13 22 70 1 66 41 50 27 20 42 47 25 68 49 12 15 72 44 60 53 5 23 14 43 29 65 36 51 54 35 67 7 19 55 48 58 46 39 24 33 30 61 45 57 2 31 3 18 59 6 9 4 63 8 16 26 34 28 69 17 56",
"output": "57"
},
{
"input": "73\n58 38 47 34 39 64 69 66 72 57 9 4 67 22 35 13 61 14 28 52 56 20 31 70 27 24 36 1 62 17 10 5 12 33 16 73 18 49 63 71 44 65 23 30 40 8 50 46 60 25 11 26 37 55 29 68 42 2 3 32 59 7 15 43 41 48 51 53 6 45 54 19 21",
"output": "45"
},
{
"input": "74\n19 51 59 34 8 40 42 55 65 16 74 26 49 63 64 70 35 72 7 12 43 18 61 27 47 31 13 32 71 22 25 67 9 1 48 50 33 10 21 46 11 45 17 37 28 60 69 66 38 2 30 3 39 15 53 68 57 41 6 36 24 73 4 23 5 62 44 14 20 29 52 54 56 58",
"output": "63"
},
{
"input": "75\n75 28 60 19 59 17 65 26 32 23 18 64 8 62 4 11 42 16 47 5 72 46 9 1 25 21 2 50 33 6 36 68 30 12 20 40 53 45 34 7 37 39 38 44 63 61 67 3 66 51 29 73 24 57 70 27 10 56 22 55 13 49 35 15 54 41 14 74 69 48 52 31 71 43 58",
"output": "74"
},
{
"input": "76\n1 47 54 17 38 37 12 32 14 48 43 71 60 56 4 13 64 41 52 57 62 24 23 49 20 10 63 3 25 66 59 40 58 33 53 46 70 7 35 61 72 74 73 19 30 5 29 6 15 28 21 27 51 55 50 9 65 8 67 39 76 42 31 34 16 2 36 11 26 44 22 45 75 18 69 68",
"output": "75"
},
{
"input": "77\n10 20 57 65 53 69 59 45 58 32 28 72 4 14 1 33 40 47 7 5 51 76 37 16 41 61 42 2 21 26 38 74 35 64 43 77 71 50 39 48 27 63 73 44 52 66 9 18 23 54 25 6 8 56 13 67 36 22 15 46 62 75 55 11 31 17 24 29 60 68 12 30 3 70 49 19 34",
"output": "62"
},
{
"input": "78\n7 61 69 47 68 42 65 78 70 3 32 59 49 51 23 71 11 63 22 18 43 34 24 13 27 16 19 40 21 46 48 77 28 66 54 67 60 15 75 62 9 26 52 58 4 25 8 37 41 76 1 6 30 50 44 36 5 14 29 53 17 12 2 57 73 35 64 39 56 10 33 20 45 74 31 55 38 72",
"output": "70"
},
{
"input": "79\n75 79 43 66 72 52 29 65 74 38 24 1 5 51 13 7 71 33 4 61 2 36 63 47 64 44 34 27 3 21 17 37 54 53 49 20 28 60 39 10 16 76 6 77 73 22 50 48 78 30 67 56 31 26 40 59 41 11 18 45 69 62 15 23 32 70 19 55 68 57 35 25 12 46 14 42 9 8 58",
"output": "77"
},
{
"input": "80\n51 20 37 12 68 11 28 52 76 21 7 5 3 16 64 34 25 2 6 40 60 62 75 13 45 17 56 29 32 47 79 73 49 72 15 46 30 54 80 27 43 24 74 18 42 71 14 4 44 63 65 33 1 77 55 57 41 59 58 70 69 35 19 67 10 36 26 23 48 50 39 61 9 66 38 8 31 22 53 78",
"output": "52"
},
{
"input": "81\n63 22 4 41 43 74 64 39 10 35 20 81 11 28 70 67 53 79 16 61 68 52 27 37 58 9 50 49 18 30 72 47 7 60 78 51 23 48 73 66 44 13 15 57 56 38 1 76 25 45 36 34 42 8 75 26 59 14 71 21 6 77 5 17 2 32 40 54 46 24 29 3 31 19 65 62 33 69 12 80 55",
"output": "69"
},
{
"input": "82\n50 24 17 41 49 18 80 11 79 72 57 31 21 35 2 51 36 66 20 65 38 3 45 32 59 81 28 30 70 55 29 76 73 6 33 39 8 7 19 48 63 1 77 43 4 13 78 54 69 9 40 46 74 82 60 71 16 64 12 14 47 26 44 5 10 75 53 25 27 15 56 42 58 34 23 61 67 62 68 22 37 52",
"output": "53"
},
{
"input": "83\n64 8 58 17 67 46 3 82 23 70 72 16 53 45 13 20 12 48 40 4 6 47 76 60 19 44 30 78 28 22 75 15 25 29 63 74 55 32 14 51 35 31 62 77 27 42 65 71 56 61 66 41 68 49 7 34 2 83 36 5 33 26 37 80 59 50 1 9 54 21 18 24 38 73 81 52 10 39 43 79 57 11 69",
"output": "66"
},
{
"input": "84\n75 8 66 21 61 63 72 51 52 13 59 25 28 58 64 53 79 41 34 7 67 11 39 56 44 24 50 9 49 55 1 80 26 6 73 74 27 69 65 37 18 43 36 17 30 3 47 29 76 78 32 22 12 68 46 5 42 81 57 31 33 83 54 48 14 62 10 16 4 20 71 70 35 15 45 19 60 77 2 23 84 40 82 38",
"output": "80"
},
{
"input": "85\n1 18 58 8 22 76 3 61 12 33 54 41 6 24 82 15 10 17 38 64 26 4 62 28 47 14 66 9 84 75 2 71 67 43 37 32 85 21 69 52 55 63 81 51 74 59 65 34 29 36 30 45 27 53 13 79 39 57 5 70 19 40 7 42 68 48 16 80 83 23 46 35 72 31 11 44 73 77 50 56 49 25 60 20 78",
"output": "84"
},
{
"input": "86\n64 56 41 10 31 69 47 39 37 36 27 19 9 42 15 6 78 59 52 17 71 45 72 14 2 54 38 79 4 18 16 8 46 75 50 82 44 24 20 55 58 86 61 43 35 32 33 40 63 30 28 60 13 53 12 57 77 81 76 66 73 84 85 62 68 22 51 5 49 7 1 70 80 65 34 48 23 21 83 11 74 26 29 67 25 3",
"output": "70"
},
{
"input": "87\n14 20 82 47 39 75 71 45 3 37 63 19 32 68 7 41 48 76 27 46 84 49 4 44 26 69 17 64 1 18 58 33 11 23 21 86 67 52 70 16 77 78 6 74 15 87 10 59 13 34 22 2 65 38 66 61 51 57 35 60 81 40 36 80 31 43 83 56 79 55 29 5 12 8 50 30 53 72 54 9 24 25 42 62 73 28 85",
"output": "58"
},
{
"input": "88\n1 83 73 46 61 31 39 86 57 43 16 29 26 80 82 7 36 42 13 20 6 64 19 40 24 12 47 87 8 34 75 9 69 3 11 52 14 25 84 59 27 10 54 51 81 74 65 77 70 17 60 35 23 44 49 2 4 88 5 21 41 32 68 66 15 55 48 58 78 53 22 38 45 33 30 50 85 76 37 79 63 18 28 62 72 56 71 67",
"output": "87"
},
{
"input": "89\n68 40 14 58 56 25 8 44 49 55 9 76 66 54 33 81 42 15 59 17 21 30 75 60 4 48 64 6 52 63 61 27 12 57 72 67 23 86 77 80 22 13 43 73 26 78 50 51 18 62 1 29 82 16 74 2 87 24 3 41 11 46 47 69 10 84 65 39 35 79 70 32 34 31 20 19 53 71 36 28 83 88 38 85 7 5 37 45 89",
"output": "88"
},
{
"input": "90\n2 67 26 58 9 49 76 22 60 30 77 20 13 7 37 81 47 16 19 12 14 45 41 68 85 54 28 24 46 1 27 43 32 89 53 35 59 75 18 51 17 64 66 80 31 88 87 90 38 72 55 71 42 11 73 69 62 78 23 74 65 79 84 4 86 52 10 6 3 82 56 5 48 33 21 57 40 29 61 63 34 36 83 8 15 44 50 70 39 25",
"output": "60"
},
{
"input": "91\n91 69 56 16 73 55 14 82 80 46 57 81 22 71 63 76 43 37 77 75 70 3 26 2 28 17 51 38 30 67 41 47 54 62 34 25 84 11 87 39 32 52 31 36 50 19 21 53 29 24 79 8 74 64 44 7 6 18 10 42 13 9 83 58 4 88 65 60 20 90 66 49 86 89 78 48 5 27 23 59 61 15 72 45 40 33 68 85 35 12 1",
"output": "90"
},
{
"input": "92\n67 57 76 78 25 89 6 82 11 16 26 17 59 48 73 10 21 31 27 80 4 5 22 13 92 55 45 85 63 28 75 60 54 88 91 47 29 35 7 87 1 39 43 51 71 84 83 81 46 9 38 56 90 24 37 41 19 86 50 61 79 20 18 14 69 23 62 65 49 52 58 53 36 2 68 64 15 42 30 34 66 32 44 40 8 33 3 77 74 12 70 72",
"output": "67"
},
{
"input": "93\n76 35 5 87 7 21 59 71 24 37 2 73 31 74 4 52 28 20 56 27 65 86 16 45 85 67 68 70 47 72 91 88 14 32 62 69 78 41 15 22 57 18 50 13 39 58 17 83 64 51 25 11 38 77 82 90 8 26 29 61 10 43 79 53 48 6 23 55 63 49 81 92 80 44 89 60 66 30 1 9 36 33 19 46 75 93 3 12 42 84 40 54 34",
"output": "85"
},
{
"input": "94\n29 85 82 78 61 83 80 63 11 38 50 43 9 24 4 87 79 45 3 17 90 7 34 27 1 76 26 39 84 47 22 41 81 19 44 23 56 92 35 31 72 62 70 53 40 88 13 14 73 2 59 86 46 94 15 12 77 57 89 42 75 48 18 51 32 55 71 30 49 91 20 60 5 93 33 64 21 36 10 28 8 65 66 69 74 58 6 52 25 67 16 37 54 68",
"output": "69"
},
{
"input": "95\n36 73 18 77 15 71 50 57 79 65 94 88 9 69 52 70 26 66 78 89 55 20 72 83 75 68 32 28 45 74 19 22 54 23 84 90 86 12 42 58 11 81 39 31 85 47 60 44 59 43 21 7 30 41 64 76 93 46 87 48 10 40 3 14 38 49 29 35 2 67 5 34 13 37 27 56 91 17 62 80 8 61 53 95 24 92 6 82 63 33 51 25 4 16 1",
"output": "94"
},
{
"input": "96\n64 3 47 83 19 10 72 61 73 95 16 40 54 84 8 86 28 4 37 42 92 48 63 76 67 1 59 66 20 35 93 2 43 7 45 70 34 33 26 91 85 89 13 29 58 68 44 25 87 75 49 71 41 17 55 36 32 31 74 22 52 79 30 88 50 78 38 39 65 27 69 77 81 94 82 53 21 80 57 60 24 46 51 9 18 15 96 62 6 23 11 12 90 5 14 56",
"output": "86"
},
{
"input": "97\n40 63 44 64 84 92 38 41 28 91 3 70 76 67 94 96 35 79 29 22 78 88 85 8 21 1 93 54 71 80 37 17 13 26 62 59 75 87 69 33 89 49 77 61 12 39 6 36 58 18 73 50 82 45 74 52 11 34 95 7 23 30 15 32 31 16 55 19 20 83 60 72 10 53 51 14 27 9 68 47 5 2 81 46 57 86 56 43 48 66 24 25 4 42 65 97 90",
"output": "95"
},
{
"input": "98\n85 94 69 86 22 52 27 79 53 91 35 55 33 88 8 75 76 95 64 54 67 30 70 49 6 16 2 48 80 32 25 90 98 46 9 96 36 81 10 92 28 11 37 97 15 41 38 40 83 44 29 47 23 3 31 61 87 39 78 20 68 12 17 73 59 18 77 72 43 51 84 24 89 65 26 7 74 93 21 19 5 14 50 42 82 71 60 56 34 62 58 57 45 66 13 63 4 1",
"output": "97"
},
{
"input": "99\n33 48 19 41 59 64 16 12 17 13 7 1 9 6 4 92 61 49 60 25 74 65 22 97 30 32 10 62 14 55 80 66 82 78 31 23 87 93 27 98 20 29 88 84 77 34 83 96 79 90 56 89 58 72 52 47 21 76 24 70 44 94 5 39 8 18 57 36 40 68 43 75 3 2 35 99 63 26 67 73 15 11 53 28 42 46 69 50 51 95 38 37 54 85 81 91 45 86 71",
"output": "87"
},
{
"input": "100\n28 30 77 4 81 67 31 25 66 56 88 73 83 51 57 34 21 90 38 76 22 99 53 70 91 3 64 54 6 94 8 5 97 80 50 45 61 40 16 95 36 98 9 2 17 44 72 55 18 58 47 12 87 24 7 32 14 23 65 41 63 48 62 39 92 27 43 19 46 13 42 52 96 84 26 69 100 79 93 49 35 60 71 59 68 15 10 29 20 1 78 33 75 86 11 85 74 82 89 37",
"output": "89"
},
{
"input": "100\n100 97 35 55 45 3 46 98 77 64 94 85 73 43 49 79 72 9 70 62 80 88 29 58 61 20 89 83 66 86 82 15 6 87 42 96 90 75 63 38 81 40 5 23 4 18 41 19 99 60 8 12 76 51 39 93 53 26 21 50 47 28 13 30 68 59 34 54 24 56 31 27 65 16 32 10 36 52 44 91 22 14 33 25 7 78 67 17 57 37 92 11 2 69 84 95 74 71 48 1",
"output": "99"
},
{
"input": "100\n83 96 73 70 30 25 7 77 58 89 76 85 49 82 45 51 14 62 50 9 31 32 16 15 97 64 4 37 20 93 24 10 80 71 100 39 75 72 78 74 8 29 53 86 79 48 3 68 90 99 56 87 63 94 36 1 40 65 6 44 43 84 17 52 34 95 38 47 60 57 98 59 33 41 46 81 23 27 19 2 54 91 55 35 26 12 92 18 28 66 69 21 5 67 13 11 22 88 61 42",
"output": "65"
},
{
"input": "100\n96 80 47 60 56 9 78 20 37 72 68 15 100 94 51 26 65 38 50 19 4 70 25 63 22 30 13 58 43 69 18 33 5 66 39 73 12 55 95 92 97 1 14 83 10 28 64 31 46 91 32 86 74 54 29 52 89 53 90 44 62 40 16 24 67 81 36 34 7 23 79 87 75 98 84 3 41 77 76 42 71 35 49 61 2 27 59 82 99 85 21 11 45 6 88 48 17 57 8 93",
"output": "87"
},
{
"input": "100\n5 6 88 37 97 51 25 81 54 17 57 98 99 44 67 24 30 93 100 36 8 38 84 42 21 4 75 31 85 48 70 77 43 50 65 94 29 32 68 86 56 39 69 47 20 60 52 53 10 34 79 2 95 40 89 64 71 26 22 46 1 62 91 76 83 41 9 78 16 63 13 3 28 92 27 49 7 12 96 72 80 23 14 19 18 66 59 87 90 45 73 82 33 74 35 61 55 15 58 11",
"output": "81"
},
{
"input": "100\n100 97 92 12 62 17 19 58 37 26 30 95 31 35 87 10 13 43 98 61 28 89 76 1 23 21 11 22 50 56 91 74 3 24 96 55 64 67 14 4 71 16 18 9 77 68 51 81 32 82 46 88 86 60 29 66 72 85 70 7 53 63 33 45 83 2 25 94 52 93 5 69 20 47 49 54 57 39 34 27 90 80 78 59 40 42 79 6 38 8 48 15 65 73 99 44 41 84 36 75",
"output": "99"
},
{
"input": "100\n22 47 34 65 69 5 68 78 53 54 41 23 80 51 11 8 2 85 81 75 25 58 29 73 30 49 10 71 17 96 76 89 79 20 12 15 55 7 46 32 19 3 82 35 74 44 38 40 92 14 6 50 97 63 45 93 37 18 62 77 87 36 83 9 90 61 57 28 39 43 52 42 24 56 21 84 26 99 88 59 33 70 4 60 98 95 94 100 13 48 66 72 16 31 64 91 1 86 27 67",
"output": "96"
},
{
"input": "100\n41 67 94 18 14 83 59 12 19 54 13 68 75 26 15 65 80 40 23 30 34 78 47 21 63 79 4 70 3 31 86 69 92 10 61 74 97 100 9 99 32 27 91 55 85 52 16 17 28 1 64 29 58 76 98 25 84 7 2 96 20 72 36 46 49 82 93 44 45 6 38 87 57 50 53 35 60 33 8 89 39 42 37 48 62 81 73 43 95 11 66 88 90 22 24 77 71 51 5 56",
"output": "62"
},
{
"input": "100\n1 88 38 56 62 99 39 80 12 33 57 24 28 84 37 42 10 95 83 58 8 40 20 2 30 78 60 79 36 71 51 31 27 65 22 47 6 19 61 94 75 4 74 35 15 23 92 9 70 13 11 59 90 18 66 81 64 72 16 32 34 67 46 91 21 87 77 97 82 41 7 86 26 43 45 3 93 17 52 96 50 63 48 5 53 44 29 25 98 54 49 14 73 69 89 55 76 85 68 100",
"output": "99"
},
{
"input": "100\n22 59 25 77 68 79 32 45 20 28 61 60 38 86 33 10 100 15 53 75 78 39 67 13 66 34 96 4 63 23 73 29 31 35 71 55 16 14 72 56 94 97 17 93 47 84 57 8 21 51 54 85 26 76 49 81 2 92 62 44 91 87 11 24 95 69 5 7 99 6 65 48 70 12 41 18 74 27 42 3 80 30 50 98 58 37 82 89 83 36 40 52 19 9 88 46 43 1 90 64",
"output": "97"
},
{
"input": "100\n12 1 76 78 97 82 59 80 48 8 91 51 54 74 16 10 89 99 83 63 93 90 55 25 30 33 29 6 9 65 92 79 44 39 15 58 37 46 32 19 27 3 75 49 62 71 98 42 69 50 26 81 96 5 7 61 60 21 20 36 18 34 40 4 47 85 64 38 22 84 2 68 11 56 31 66 17 14 95 43 53 35 23 52 70 13 72 45 41 77 73 87 88 94 28 86 24 67 100 57",
"output": "98"
},
{
"input": "100\n66 100 53 88 7 73 54 41 31 42 8 46 65 90 78 14 94 30 79 39 89 5 83 50 38 61 37 86 22 95 60 98 34 57 91 10 75 25 15 43 23 17 96 35 93 48 87 47 56 13 19 9 82 62 67 80 11 55 99 70 18 26 58 85 12 44 16 45 4 49 20 71 92 24 81 2 76 32 6 21 84 36 52 97 59 63 40 51 27 64 68 3 77 72 28 33 29 1 74 69",
"output": "98"
},
{
"input": "100\n56 64 1 95 72 39 9 49 87 29 94 7 32 6 30 48 50 25 31 78 90 45 60 44 80 68 17 20 73 15 75 98 83 13 71 22 36 26 96 88 35 3 85 54 16 41 92 99 69 86 93 33 43 62 77 46 47 37 12 10 18 40 27 4 63 55 28 59 23 34 61 53 76 42 51 91 21 70 8 58 38 19 5 66 84 11 52 24 81 82 79 67 97 65 57 74 2 89 100 14",
"output": "98"
},
{
"input": "3\n1 2 3",
"output": "2"
},
{
"input": "3\n1 3 2",
"output": "2"
},
{
"input": "3\n2 1 3",
"output": "2"
},
{
"input": "3\n2 3 1",
"output": "2"
},
{
"input": "3\n3 1 2",
"output": "2"
},
{
"input": "3\n3 2 1",
"output": "2"
},
{
"input": "4\n1 2 3 4",
"output": "3"
},
{
"input": "4\n1 2 4 3",
"output": "3"
},
{
"input": "4\n1 3 2 4",
"output": "3"
},
{
"input": "4\n1 3 4 2",
"output": "3"
},
{
"input": "4\n1 4 2 3",
"output": "3"
},
{
"input": "4\n1 4 3 2",
"output": "3"
},
{
"input": "4\n2 1 3 4",
"output": "3"
},
{
"input": "4\n2 1 4 3",
"output": "2"
},
{
"input": "4\n2 4 1 3",
"output": "2"
},
{
"input": "4\n2 4 3 1",
"output": "3"
},
{
"input": "4\n3 1 2 4",
"output": "3"
},
{
"input": "4\n3 1 4 2",
"output": "2"
},
{
"input": "4\n3 2 1 4",
"output": "3"
},
{
"input": "4\n3 2 4 1",
"output": "3"
},
{
"input": "4\n3 4 1 2",
"output": "2"
},
{
"input": "4\n3 4 2 1",
"output": "3"
},
{
"input": "4\n4 1 2 3",
"output": "3"
},
{
"input": "4\n4 1 3 2",
"output": "3"
},
{
"input": "4\n4 2 1 3",
"output": "3"
},
{
"input": "4\n4 2 3 1",
"output": "3"
},
{
"input": "4\n4 3 1 2",
"output": "3"
},
{
"input": "4\n4 3 2 1",
"output": "3"
},
{
"input": "8\n2 5 6 4 8 3 1 7",
"output": "6"
},
{
"input": "5\n2 3 1 5 4",
"output": "3"
},
{
"input": "6\n2 5 3 6 4 1",
"output": "5"
},
{
"input": "6\n5 4 2 6 1 3",
"output": "4"
},
{
"input": "6\n4 2 3 1 6 5",
"output": "4"
},
{
"input": "6\n5 4 2 1 6 3",
"output": "4"
},
{
"input": "9\n7 2 3 4 5 6 1 9 8",
"output": "7"
},
{
"input": "6\n3 2 1 4 6 5",
"output": "4"
},
{
"input": "6\n2 3 4 1 6 5",
"output": "4"
},
{
"input": "10\n5 2 3 4 1 6 7 8 10 9",
"output": "8"
},
{
"input": "6\n5 2 3 1 6 4",
"output": "4"
},
{
"input": "10\n2 9 3 4 1 10 5 6 7 8",
"output": "5"
},
{
"input": "10\n2 3 4 5 6 7 1 8 10 9",
"output": "8"
},
{
"input": "8\n2 3 4 5 1 6 8 7",
"output": "6"
},
{
"input": "6\n2 1 3 4 5 6",
"output": "5"
}
] | 1,610,281,965 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 62 | 0 | # import os
n = int(input())
a = list(map(int,input().split()))
ind_min = a.index(min(a))
ind_max = a.index(max(a))
# 2
# 1
left = ind_min if ind_min < ind_max else ind_max
right = ind_min if ind_min >= ind_max else ind_max
# left:1
# right: 2
if left > right:
print(right)
else:
print(n-left-1)
| Title: Nicholas and Permutation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Nicholas has an array *a* that contains *n* distinct integers from 1 to *n*. In other words, Nicholas has a permutation of size *n*.
Nicholas want the minimum element (integer 1) and the maximum element (integer *n*) to be as far as possible from each other. He wants to perform exactly one swap in order to maximize the distance between the minimum and the maximum elements. The distance between two elements is considered to be equal to the absolute difference between their positions.
Input Specification:
The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100) — the size of the permutation.
The second line of the input contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*), where *a**i* is equal to the element at the *i*-th position.
Output Specification:
Print a single integer — the maximum possible distance between the minimum and the maximum elements Nicholas can achieve by performing exactly one swap.
Demo Input:
['5\n4 5 1 3 2\n', '7\n1 6 5 3 4 7 2\n', '6\n6 5 4 3 2 1\n']
Demo Output:
['3\n', '6\n', '5\n']
Note:
In the first sample, one may obtain the optimal answer by swapping elements 1 and 2.
In the second sample, the minimum and the maximum elements will be located in the opposite ends of the array if we swap 7 and 2.
In the third sample, the distance between the minimum and the maximum elements is already maximum possible, so we just perform some unnecessary swap, for example, one can swap 5 and 2. | ```python
# import os
n = int(input())
a = list(map(int,input().split()))
ind_min = a.index(min(a))
ind_max = a.index(max(a))
# 2
# 1
left = ind_min if ind_min < ind_max else ind_max
right = ind_min if ind_min >= ind_max else ind_max
# left:1
# right: 2
if left > right:
print(right)
else:
print(n-left-1)
``` | 0 |
|
922 | A | Cloning Toys | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Imp likes his plush toy a lot.
Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applies the machine to a copied toy, he gets two additional copies.
Initially, Imp has only one original toy. He wants to know if it is possible to use machine to get exactly *x* copied toys and *y* original toys? He can't throw toys away, and he can't apply the machine to a copy if he doesn't currently have any copies. | The only line contains two integers *x* and *y* (0<=≤<=*x*,<=*y*<=≤<=109) — the number of copies and the number of original toys Imp wants to get (including the initial one). | Print "Yes", if the desired configuration is possible, and "No" otherwise.
You can print each letter in arbitrary case (upper or lower). | [
"6 3\n",
"4 2\n",
"1000 1001\n"
] | [
"Yes\n",
"No\n",
"Yes\n"
] | In the first example, Imp has to apply the machine twice to original toys and then twice to copies. | 500 | [
{
"input": "6 3",
"output": "Yes"
},
{
"input": "4 2",
"output": "No"
},
{
"input": "1000 1001",
"output": "Yes"
},
{
"input": "1000000000 999999999",
"output": "Yes"
},
{
"input": "81452244 81452247",
"output": "No"
},
{
"input": "188032448 86524683",
"output": "Yes"
},
{
"input": "365289629 223844571",
"output": "No"
},
{
"input": "247579518 361164458",
"output": "No"
},
{
"input": "424836699 793451637",
"output": "No"
},
{
"input": "602093880 930771525",
"output": "No"
},
{
"input": "779351061 773124120",
"output": "Yes"
},
{
"input": "661640950 836815080",
"output": "No"
},
{
"input": "543930839 974134967",
"output": "No"
},
{
"input": "16155311 406422145",
"output": "No"
},
{
"input": "81601559 445618240",
"output": "No"
},
{
"input": "963891449 582938127",
"output": "No"
},
{
"input": "141148629 351661795",
"output": "No"
},
{
"input": "318405810 783948974",
"output": "No"
},
{
"input": "495662991 921268861",
"output": "No"
},
{
"input": "1 0",
"output": "No"
},
{
"input": "0 1",
"output": "Yes"
},
{
"input": "0 0",
"output": "No"
},
{
"input": "453462237 167520068",
"output": "Yes"
},
{
"input": "630719418 9872663",
"output": "Yes"
},
{
"input": "807976599 442159843",
"output": "No"
},
{
"input": "690266488 579479730",
"output": "No"
},
{
"input": "771581370 589752968",
"output": "No"
},
{
"input": "948838551 727072855",
"output": "No"
},
{
"input": "831128440 790763814",
"output": "No"
},
{
"input": "303352912 928083702",
"output": "No"
},
{
"input": "185642801 65403588",
"output": "Yes"
},
{
"input": "67932690 202723476",
"output": "No"
},
{
"input": "540157163 340043363",
"output": "No"
},
{
"input": "422447052 772330542",
"output": "No"
},
{
"input": "599704233 541054210",
"output": "Yes"
},
{
"input": "481994122 678374097",
"output": "No"
},
{
"input": "48564714 743566477",
"output": "No"
},
{
"input": "225821895 880886365",
"output": "No"
},
{
"input": "403079076 313173543",
"output": "Yes"
},
{
"input": "1000000000 1000000000",
"output": "No"
},
{
"input": "1 1",
"output": "No"
},
{
"input": "1 2",
"output": "Yes"
},
{
"input": "2 1",
"output": "No"
},
{
"input": "2 2",
"output": "No"
},
{
"input": "2 0",
"output": "No"
},
{
"input": "0 2",
"output": "No"
},
{
"input": "1000000000 1",
"output": "No"
},
{
"input": "777777 0",
"output": "No"
},
{
"input": "10 1",
"output": "No"
},
{
"input": "7 0",
"output": "No"
},
{
"input": "3 0",
"output": "No"
},
{
"input": "3 2",
"output": "Yes"
}
] | 1,571,389,123 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | x=int(input())
y=int(input())
n=x-y-1
if x>0,y>0:
y=n+1
x=2(n)+y-1
print("yes")
else:
print("no") | Title: Cloning Toys
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Imp likes his plush toy a lot.
Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applies the machine to a copied toy, he gets two additional copies.
Initially, Imp has only one original toy. He wants to know if it is possible to use machine to get exactly *x* copied toys and *y* original toys? He can't throw toys away, and he can't apply the machine to a copy if he doesn't currently have any copies.
Input Specification:
The only line contains two integers *x* and *y* (0<=≤<=*x*,<=*y*<=≤<=109) — the number of copies and the number of original toys Imp wants to get (including the initial one).
Output Specification:
Print "Yes", if the desired configuration is possible, and "No" otherwise.
You can print each letter in arbitrary case (upper or lower).
Demo Input:
['6 3\n', '4 2\n', '1000 1001\n']
Demo Output:
['Yes\n', 'No\n', 'Yes\n']
Note:
In the first example, Imp has to apply the machine twice to original toys and then twice to copies. | ```python
x=int(input())
y=int(input())
n=x-y-1
if x>0,y>0:
y=n+1
x=2(n)+y-1
print("yes")
else:
print("no")
``` | -1 |
|
520 | A | Pangram | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices.
You are given a string consisting of lowercase and uppercase Latin letters. Check whether this string is a pangram. We say that the string contains a letter of the Latin alphabet if this letter occurs in the string in uppercase or lowercase. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of characters in the string.
The second line contains the string. The string consists only of uppercase and lowercase Latin letters. | Output "YES", if the string is a pangram and "NO" otherwise. | [
"12\ntoosmallword\n",
"35\nTheQuickBrownFoxJumpsOverTheLazyDog\n"
] | [
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "12\ntoosmallword",
"output": "NO"
},
{
"input": "35\nTheQuickBrownFoxJumpsOverTheLazyDog",
"output": "YES"
},
{
"input": "1\na",
"output": "NO"
},
{
"input": "26\nqwertyuiopasdfghjklzxcvbnm",
"output": "YES"
},
{
"input": "26\nABCDEFGHIJKLMNOPQRSTUVWXYZ",
"output": "YES"
},
{
"input": "48\nthereisasyetinsufficientdataforameaningfulanswer",
"output": "NO"
},
{
"input": "30\nToBeOrNotToBeThatIsTheQuestion",
"output": "NO"
},
{
"input": "30\njackdawslovemybigsphinxofquarz",
"output": "NO"
},
{
"input": "31\nTHEFIVEBOXINGWIZARDSJUMPQUICKLY",
"output": "YES"
},
{
"input": "26\naaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "NO"
},
{
"input": "26\nMGJYIZDKsbhpVeNFlquRTcWoAx",
"output": "YES"
},
{
"input": "26\nfWMOhAPsbIVtyUEZrGNQXDklCJ",
"output": "YES"
},
{
"input": "26\nngPMVFSThiRCwLEuyOAbKxQzDJ",
"output": "YES"
},
{
"input": "25\nnxYTzLFwzNolAumjgcAboyxAj",
"output": "NO"
},
{
"input": "26\npRWdodGdxUESvcScPGbUoooZsC",
"output": "NO"
},
{
"input": "66\nBovdMlDzTaqKllZILFVfxbLGsRnzmtVVTmqiIDTYrossLEPlmsPrkUYtWEsGHVOnFj",
"output": "NO"
},
{
"input": "100\nmKtsiDRJypUieHIkvJaMFkwaKxcCIbBszZQLIyPpCDCjhNpAnYFngLjRpnKWpKWtGnwoSteeZXuFHWQxxxOpFlNeYTwKocsXuCoa",
"output": "YES"
},
{
"input": "26\nEoqxUbsLjPytUHMiFnvcGWZdRK",
"output": "NO"
},
{
"input": "26\nvCUFRKElZOnjmXGylWQaHDiPst",
"output": "NO"
},
{
"input": "26\nWtrPuaHdXLKJMsnvQfgOiJZBEY",
"output": "NO"
},
{
"input": "26\npGiFluRteQwkaVoPszJyNBChxM",
"output": "NO"
},
{
"input": "26\ncTUpqjPmANrdbzSFhlWIoKxgVY",
"output": "NO"
},
{
"input": "26\nLndjgvAEuICHKxPwqYztosrmBN",
"output": "NO"
},
{
"input": "26\nMdaXJrCipnOZLykfqHWEStevbU",
"output": "NO"
},
{
"input": "26\nEjDWsVxfKTqGXRnUMOLYcIzPba",
"output": "NO"
},
{
"input": "26\nxKwzRMpunYaqsdfaBgJcVElTHo",
"output": "NO"
},
{
"input": "26\nnRYUQsTwCPLZkgshfEXvBdoiMa",
"output": "NO"
},
{
"input": "26\nHNCQPfJutyAlDGsvRxZWMEbIdO",
"output": "NO"
},
{
"input": "26\nDaHJIpvKznQcmUyWsTGObXRFDe",
"output": "NO"
},
{
"input": "26\nkqvAnFAiRhzlJbtyuWedXSPcOG",
"output": "NO"
},
{
"input": "26\nhlrvgdwsIOyjcmUZXtAKEqoBpF",
"output": "NO"
},
{
"input": "26\njLfXXiMhBTcAwQVReGnpKzdsYu",
"output": "NO"
},
{
"input": "26\nlNMcVuwItjxRBGAekjhyDsQOzf",
"output": "NO"
},
{
"input": "26\nRkSwbNoYldUGtAZvpFMcxhIJFE",
"output": "NO"
},
{
"input": "26\nDqspXZJTuONYieKgaHLMBwfVSC",
"output": "NO"
},
{
"input": "26\necOyUkqNljFHRVXtIpWabGMLDz",
"output": "NO"
},
{
"input": "26\nEKAvqZhBnPmVCDRlgWJfOusxYI",
"output": "NO"
},
{
"input": "26\naLbgqeYchKdMrsZxIPFvTOWNjA",
"output": "NO"
},
{
"input": "26\nxfpBLsndiqtacOCHGmeWUjRkYz",
"output": "NO"
},
{
"input": "26\nXsbRKtqleZPNIVCdfUhyagAomJ",
"output": "NO"
},
{
"input": "26\nAmVtbrwquEthZcjKPLiyDgSoNF",
"output": "NO"
},
{
"input": "26\nOhvXDcwqAUmSEPRZGnjFLiKtNB",
"output": "NO"
},
{
"input": "26\nEKWJqCFLRmstxVBdYuinpbhaOg",
"output": "NO"
},
{
"input": "26\nmnbvcxxlkjhgfdsapoiuytrewq",
"output": "NO"
},
{
"input": "26\naAbcdefghijklmnopqrstuvwxy",
"output": "NO"
},
{
"input": "30\nABCDEFGHTYRIOPLabcdefghtyriopl",
"output": "NO"
},
{
"input": "25\nabcdefghijklmnopqrstuvwxy",
"output": "NO"
},
{
"input": "26\nabcdefhijklmnopqrstVxyzABC",
"output": "NO"
},
{
"input": "25\nqwertyuiopasdfghjklxcvbnm",
"output": "NO"
},
{
"input": "34\nTheQuickBrownFoxJumpsOverTheLayDog",
"output": "NO"
},
{
"input": "26\nabcdefghigklmnopqrstuvwxyz",
"output": "NO"
},
{
"input": "26\nabcdefghijklmnopqrstuvwxyA",
"output": "NO"
},
{
"input": "50\nqazwsxedcrfvtgbyhnujmikolQWERTYUIOASDFGHJKLZXCVBNM",
"output": "NO"
},
{
"input": "35\nTheQuickBrownFoxJumpsOverTheLasyDog",
"output": "NO"
},
{
"input": "25\nbcdefghijklmnopqrstuvwxyz",
"output": "NO"
},
{
"input": "38\nAbCdEfGhIjKlMnOpQrStVwXyZzzzzzzaaaaaaa",
"output": "NO"
},
{
"input": "26\nabcdefghiklmnopqrstvxyzABC",
"output": "NO"
},
{
"input": "26\nabcdefghijklmnopqrstuvwxzZ",
"output": "NO"
},
{
"input": "50\nabcdefghijklmnopqrstuvwxyABCDEFGHIJKLMNOPQRSTUVWXY",
"output": "NO"
}
] | 1,698,333,760 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 921,600 | import string
n=int(input())
m=sorted(str(input()))
if m[0] in string.ascii_uppercase and m[-1] in string.ascii_lowercase:
print("YES")
else:
print("No")
| Title: Pangram
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices.
You are given a string consisting of lowercase and uppercase Latin letters. Check whether this string is a pangram. We say that the string contains a letter of the Latin alphabet if this letter occurs in the string in uppercase or lowercase.
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of characters in the string.
The second line contains the string. The string consists only of uppercase and lowercase Latin letters.
Output Specification:
Output "YES", if the string is a pangram and "NO" otherwise.
Demo Input:
['12\ntoosmallword\n', '35\nTheQuickBrownFoxJumpsOverTheLazyDog\n']
Demo Output:
['NO\n', 'YES\n']
Note:
none | ```python
import string
n=int(input())
m=sorted(str(input()))
if m[0] in string.ascii_uppercase and m[-1] in string.ascii_lowercase:
print("YES")
else:
print("No")
``` | 0 |
|
471 | A | MUH and Sticks | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided to make either an elephant or a bear from those sticks. They can make an animal from sticks in the following way:
- Four sticks represent the animal's legs, these sticks should have the same length. - Two remaining sticks represent the animal's head and body. The bear's head stick must be shorter than the body stick. The elephant, however, has a long trunk, so his head stick must be as long as the body stick. Note that there are no limits on the relations between the leg sticks and the head and body sticks.
Your task is to find out which animal can be made from the given stick set. The zoo keeper wants the sticks back after the game, so they must never be broken, even bears understand it. | The single line contains six space-separated integers *l**i* (1<=≤<=*l**i*<=≤<=9) — the lengths of the six sticks. It is guaranteed that the input is such that you cannot make both animals from the sticks. | If you can make a bear from the given set, print string "Bear" (without the quotes). If you can make an elephant, print string "Elephant" (wıthout the quotes). If you can make neither a bear nor an elephant, print string "Alien" (without the quotes). | [
"4 2 5 4 4 4\n",
"4 4 5 4 4 5\n",
"1 2 3 4 5 6\n"
] | [
"Bear",
"Elephant",
"Alien"
] | If you're out of creative ideas, see instructions below which show how to make a bear and an elephant in the first two samples. The stick of length 2 is in red, the sticks of length 4 are in green, the sticks of length 5 are in blue. | 500 | [
{
"input": "4 2 5 4 4 4",
"output": "Bear"
},
{
"input": "4 4 5 4 4 5",
"output": "Elephant"
},
{
"input": "1 2 3 4 5 6",
"output": "Alien"
},
{
"input": "5 5 5 5 5 5",
"output": "Elephant"
},
{
"input": "1 1 1 2 3 5",
"output": "Alien"
},
{
"input": "1 1 1 1 1 1",
"output": "Elephant"
},
{
"input": "9 9 9 9 9 9",
"output": "Elephant"
},
{
"input": "1 8 9 1 1 1",
"output": "Bear"
},
{
"input": "9 9 9 1 9 9",
"output": "Bear"
},
{
"input": "1 2 3 8 9 7",
"output": "Alien"
},
{
"input": "5 5 5 6 6 6",
"output": "Alien"
},
{
"input": "1 1 2 2 3 4",
"output": "Alien"
},
{
"input": "4 4 4 4 4 2",
"output": "Bear"
},
{
"input": "2 2 3 3 4 4",
"output": "Alien"
},
{
"input": "4 4 4 4 4 5",
"output": "Bear"
},
{
"input": "1 1 2 2 2 2",
"output": "Elephant"
},
{
"input": "1 2 5 5 5 5",
"output": "Bear"
},
{
"input": "4 4 2 2 2 2",
"output": "Elephant"
},
{
"input": "1 1 1 1 1 2",
"output": "Bear"
},
{
"input": "2 2 4 4 4 4",
"output": "Elephant"
},
{
"input": "4 4 4 4 4 3",
"output": "Bear"
},
{
"input": "4 4 5 6 7 8",
"output": "Alien"
},
{
"input": "4 4 4 4 2 2",
"output": "Elephant"
},
{
"input": "1 1 1 1 2 2",
"output": "Elephant"
},
{
"input": "1 1 3 3 3 5",
"output": "Alien"
},
{
"input": "1 2 2 3 3 3",
"output": "Alien"
},
{
"input": "1 2 2 2 2 2",
"output": "Bear"
},
{
"input": "1 3 3 3 4 5",
"output": "Alien"
},
{
"input": "5 1 1 1 1 1",
"output": "Bear"
}
] | 1,566,864,747 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 124 | 0 | def muh_and_sticks(values):
a = list(map(lambda val: (val, len([i for i in range(len(values)) if values[i] == val])),values,))
b = list(set(list(zip(*a))[1]))
if b == [6] or b == [2, 4]:
return "Elephant"
elif b == [1, 5] or b == [1, 4]:
return "Bear"
else:
return "Alien"
if __name__ == "__main__":
a = list(map(int, input().split()))
print(muh_and_sticks(a)) | Title: MUH and Sticks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided to make either an elephant or a bear from those sticks. They can make an animal from sticks in the following way:
- Four sticks represent the animal's legs, these sticks should have the same length. - Two remaining sticks represent the animal's head and body. The bear's head stick must be shorter than the body stick. The elephant, however, has a long trunk, so his head stick must be as long as the body stick. Note that there are no limits on the relations between the leg sticks and the head and body sticks.
Your task is to find out which animal can be made from the given stick set. The zoo keeper wants the sticks back after the game, so they must never be broken, even bears understand it.
Input Specification:
The single line contains six space-separated integers *l**i* (1<=≤<=*l**i*<=≤<=9) — the lengths of the six sticks. It is guaranteed that the input is such that you cannot make both animals from the sticks.
Output Specification:
If you can make a bear from the given set, print string "Bear" (without the quotes). If you can make an elephant, print string "Elephant" (wıthout the quotes). If you can make neither a bear nor an elephant, print string "Alien" (without the quotes).
Demo Input:
['4 2 5 4 4 4\n', '4 4 5 4 4 5\n', '1 2 3 4 5 6\n']
Demo Output:
['Bear', 'Elephant', 'Alien']
Note:
If you're out of creative ideas, see instructions below which show how to make a bear and an elephant in the first two samples. The stick of length 2 is in red, the sticks of length 4 are in green, the sticks of length 5 are in blue. | ```python
def muh_and_sticks(values):
a = list(map(lambda val: (val, len([i for i in range(len(values)) if values[i] == val])),values,))
b = list(set(list(zip(*a))[1]))
if b == [6] or b == [2, 4]:
return "Elephant"
elif b == [1, 5] or b == [1, 4]:
return "Bear"
else:
return "Alien"
if __name__ == "__main__":
a = list(map(int, input().split()))
print(muh_and_sticks(a))
``` | 3 |
|
983 | B | XOR-pyramid | PROGRAMMING | 1,800 | [
"dp"
] | null | null | For an array $b$ of length $m$ we define the function $f$ as
where $\oplus$ is [bitwise exclusive OR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).
For example, $f(1,2,4,8)=f(1\oplus2,2\oplus4,4\oplus8)=f(3,6,12)=f(3\oplus6,6\oplus12)=f(5,10)=f(5\oplus10)=f(15)=15$
You are given an array $a$ and a few queries. Each query is represented as two integers $l$ and $r$. The answer is the maximum value of $f$ on all continuous subsegments of the array $a_l, a_{l+1}, \ldots, a_r$. | The first line contains a single integer $n$ ($1 \le n \le 5000$) — the length of $a$.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2^{30}-1$) — the elements of the array.
The third line contains a single integer $q$ ($1 \le q \le 100\,000$) — the number of queries.
Each of the next $q$ lines contains a query represented as two integers $l$, $r$ ($1 \le l \le r \le n$). | Print $q$ lines — the answers for the queries. | [
"3\n8 4 1\n2\n2 3\n1 2\n",
"6\n1 2 4 8 16 32\n4\n1 6\n2 5\n3 4\n1 2\n"
] | [
"5\n12\n",
"60\n30\n12\n3\n"
] | In first sample in both queries the maximum value of the function is reached on the subsegment that is equal to the whole segment.
In second sample, optimal segment for first query are $[3,6]$, for second query — $[2,5]$, for third — $[3,4]$, for fourth — $[1,2]$. | 1,000 | [
{
"input": "3\n8 4 1\n2\n2 3\n1 2",
"output": "5\n12"
},
{
"input": "6\n1 2 4 8 16 32\n4\n1 6\n2 5\n3 4\n1 2",
"output": "60\n30\n12\n3"
}
] | 1,664,364,467 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 15 | 2,000 | 222,924,800 | n = int(input())
a = list(map(int, input().split()))
f = [[0 for i in range(n + 1)] for j in range(n + 1)]
g = [[0 for i in range(n + 1)] for j in range(n + 1)]
q = int(input())
for i in range(1, n + 1):
f[i][i] = a[i - 1]
g[i][i] = a[i - 1]
for k in range(2, n + 1):
for l in range(1, n + 1):
r = l + k - 1
if r > n:
break
f[l][r] = f[l][r - 1] ^ f[l + 1][r]
for k in range(2, n + 1):
for l in range(1, n + 1):
r = l + k - 1
if r > n:
break
g[l][r] = max(f[l][r], max(g[l][r - 1], g[l + 1][r]))
for o in range(q):
l, r = map(int, input().split())
print(g[l][r]) | Title: XOR-pyramid
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
For an array $b$ of length $m$ we define the function $f$ as
where $\oplus$ is [bitwise exclusive OR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).
For example, $f(1,2,4,8)=f(1\oplus2,2\oplus4,4\oplus8)=f(3,6,12)=f(3\oplus6,6\oplus12)=f(5,10)=f(5\oplus10)=f(15)=15$
You are given an array $a$ and a few queries. Each query is represented as two integers $l$ and $r$. The answer is the maximum value of $f$ on all continuous subsegments of the array $a_l, a_{l+1}, \ldots, a_r$.
Input Specification:
The first line contains a single integer $n$ ($1 \le n \le 5000$) — the length of $a$.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2^{30}-1$) — the elements of the array.
The third line contains a single integer $q$ ($1 \le q \le 100\,000$) — the number of queries.
Each of the next $q$ lines contains a query represented as two integers $l$, $r$ ($1 \le l \le r \le n$).
Output Specification:
Print $q$ lines — the answers for the queries.
Demo Input:
['3\n8 4 1\n2\n2 3\n1 2\n', '6\n1 2 4 8 16 32\n4\n1 6\n2 5\n3 4\n1 2\n']
Demo Output:
['5\n12\n', '60\n30\n12\n3\n']
Note:
In first sample in both queries the maximum value of the function is reached on the subsegment that is equal to the whole segment.
In second sample, optimal segment for first query are $[3,6]$, for second query — $[2,5]$, for third — $[3,4]$, for fourth — $[1,2]$. | ```python
n = int(input())
a = list(map(int, input().split()))
f = [[0 for i in range(n + 1)] for j in range(n + 1)]
g = [[0 for i in range(n + 1)] for j in range(n + 1)]
q = int(input())
for i in range(1, n + 1):
f[i][i] = a[i - 1]
g[i][i] = a[i - 1]
for k in range(2, n + 1):
for l in range(1, n + 1):
r = l + k - 1
if r > n:
break
f[l][r] = f[l][r - 1] ^ f[l + 1][r]
for k in range(2, n + 1):
for l in range(1, n + 1):
r = l + k - 1
if r > n:
break
g[l][r] = max(f[l][r], max(g[l][r - 1], g[l + 1][r]))
for o in range(q):
l, r = map(int, input().split())
print(g[l][r])
``` | 0 |
|
313 | B | Ilya and Queries | PROGRAMMING | 1,100 | [
"dp",
"implementation"
] | null | null | Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.
You've got string *s*<==<=*s*1*s*2... *s**n* (*n* is the length of the string), consisting only of characters "." and "#" and *m* queries. Each query is described by a pair of integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=<<=*r**i*<=≤<=*n*). The answer to the query *l**i*,<=*r**i* is the number of such integers *i* (*l**i*<=≤<=*i*<=<<=*r**i*), that *s**i*<==<=*s**i*<=+<=1.
Ilya the Lion wants to help his friends but is there anyone to help him? Help Ilya, solve the problem. | The first line contains string *s* of length *n* (2<=≤<=*n*<=≤<=105). It is guaranteed that the given string only consists of characters "." and "#".
The next line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. Each of the next *m* lines contains the description of the corresponding query. The *i*-th line contains integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=<<=*r**i*<=≤<=*n*). | Print *m* integers — the answers to the queries in the order in which they are given in the input. | [
"......\n4\n3 4\n2 3\n1 6\n2 6\n",
"#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4\n"
] | [
"1\n1\n5\n4\n",
"1\n1\n2\n2\n0\n"
] | none | 1,000 | [
{
"input": "......\n4\n3 4\n2 3\n1 6\n2 6",
"output": "1\n1\n5\n4"
},
{
"input": "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4",
"output": "1\n1\n2\n2\n0"
},
{
"input": ".#...#..\n6\n1 5\n2 3\n6 7\n2 4\n2 5\n1 3",
"output": "2\n0\n0\n1\n2\n0"
},
{
"input": "#.#.#..\n5\n3 4\n4 5\n5 7\n5 7\n1 3",
"output": "0\n0\n1\n1\n0"
},
{
"input": "#.##.##.\n7\n1 8\n2 6\n2 6\n6 8\n3 5\n2 4\n2 5",
"output": "2\n1\n1\n1\n1\n1\n1"
},
{
"input": "#..#\n1\n1 4",
"output": "1"
},
{
"input": "#..##...#.\n7\n5 9\n6 10\n1 7\n5 8\n3 5\n2 10\n3 4",
"output": "2\n2\n3\n2\n1\n4\n0"
},
{
"input": "#.#.#\n7\n1 2\n3 4\n3 5\n2 3\n3 5\n1 5\n1 3",
"output": "0\n0\n0\n0\n0\n0\n0"
},
{
"input": "###..#...#\n2\n2 4\n1 2",
"output": "1\n1"
},
{
"input": "..\n1\n1 2",
"output": "1"
},
{
"input": "##\n1\n1 2",
"output": "1"
},
{
"input": ".#\n1\n1 2",
"output": "0"
},
{
"input": "#.\n1\n1 2",
"output": "0"
},
{
"input": "...\n2\n1 2\n1 2",
"output": "1\n1"
}
] | 1,688,306,945 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 1,528 | 4,096,000 | s = input()
n = len(s)
a = [0] * n
for i in range(1, n):
a[i] = a[i - 1] + (s[i] == s[i - 1])
m = int(input())
for _ in range(m):
x, y = map(int, input().split())
print(a[y - 1] - a[x - 1])
# Sun Jul 02 2023 17:09:03 GMT+0300 (Moscow Standard Time)
| Title: Ilya and Queries
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.
You've got string *s*<==<=*s*1*s*2... *s**n* (*n* is the length of the string), consisting only of characters "." and "#" and *m* queries. Each query is described by a pair of integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=<<=*r**i*<=≤<=*n*). The answer to the query *l**i*,<=*r**i* is the number of such integers *i* (*l**i*<=≤<=*i*<=<<=*r**i*), that *s**i*<==<=*s**i*<=+<=1.
Ilya the Lion wants to help his friends but is there anyone to help him? Help Ilya, solve the problem.
Input Specification:
The first line contains string *s* of length *n* (2<=≤<=*n*<=≤<=105). It is guaranteed that the given string only consists of characters "." and "#".
The next line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. Each of the next *m* lines contains the description of the corresponding query. The *i*-th line contains integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=<<=*r**i*<=≤<=*n*).
Output Specification:
Print *m* integers — the answers to the queries in the order in which they are given in the input.
Demo Input:
['......\n4\n3 4\n2 3\n1 6\n2 6\n', '#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4\n']
Demo Output:
['1\n1\n5\n4\n', '1\n1\n2\n2\n0\n']
Note:
none | ```python
s = input()
n = len(s)
a = [0] * n
for i in range(1, n):
a[i] = a[i - 1] + (s[i] == s[i - 1])
m = int(input())
for _ in range(m):
x, y = map(int, input().split())
print(a[y - 1] - a[x - 1])
# Sun Jul 02 2023 17:09:03 GMT+0300 (Moscow Standard Time)
``` | 3 |
|
107 | B | Basketball Team | PROGRAMMING | 1,600 | [
"combinatorics",
"dp",
"math",
"probabilities"
] | B. Basketball Team | 1 | 256 | As a German University in Cairo (GUC) student and a basketball player, Herr Wafa was delighted once he heard the news. GUC is finally participating in the Annual Basketball Competition (ABC).
A team is to be formed of *n* players, all of which are GUC students. However, the team might have players belonging to different departments. There are *m* departments in GUC, numbered from 1 to *m*. Herr Wafa's department has number *h*. For each department *i*, Herr Wafa knows number *s**i* — how many students who play basketball belong to this department.
Herr Wafa was also able to guarantee a spot on the team, using his special powers. But since he hates floating-point numbers, he needs your help at finding the probability that he will have at least one teammate belonging to his department.
Note that every possible team containing Herr Wafa is equally probable. Consider all the students different from each other. | The first line contains three integers *n*, *m* and *h* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*m*<=≤<=1000,<=1<=≤<=*h*<=≤<=*m*) — the number of players on the team, the number of departments in GUC and Herr Wafa's department, correspondingly.
The second line contains a single-space-separated list of *m* integers *s**i* (1<=≤<=*s**i*<=≤<=100), denoting the number of students in the *i*-th department. Note that *s**h* includes Herr Wafa. | Print the probability that Herr Wafa will have at least one teammate from his department. If there is not enough basketball players in GUC to participate in ABC, print -1. The answer will be accepted if it has absolute or relative error not exceeding 10<=-<=6. | [
"3 2 1\n2 1\n",
"3 2 1\n1 1\n",
"3 2 1\n2 2\n"
] | [
"1\n",
"-1\n",
"0.666667\n"
] | In the first example all 3 players (2 from department 1 and 1 from department 2) must be chosen for the team. Both players from Wafa's departments will be chosen, so he's guaranteed to have a teammate from his department.
In the second example, there are not enough players.
In the third example, there are three possibilities to compose the team containing Herr Wafa. In two of them the other player from Herr Wafa's department is part of the team. | 1,000 | [
{
"input": "3 2 1\n2 1",
"output": "1"
},
{
"input": "3 2 1\n1 1",
"output": "-1"
},
{
"input": "3 2 1\n2 2",
"output": "0.666667"
},
{
"input": "3 2 1\n1 2",
"output": "0.000000"
},
{
"input": "6 5 3\n5 2 3 10 5",
"output": "0.380435"
},
{
"input": "7 10 6\n9 10 2 3 3 6 9 9 3 7",
"output": "0.420946"
},
{
"input": "17 5 1\n10 4 9 6 2",
"output": "0.999860"
},
{
"input": "5 8 3\n9 7 2 5 2 10 3 4",
"output": "0.097561"
},
{
"input": "14 8 4\n6 2 10 6 2 8 4 2",
"output": "0.885750"
},
{
"input": "14 9 9\n9 4 7 2 1 2 4 3 9",
"output": "0.971132"
},
{
"input": "46 73 68\n4 2 6 4 1 9 8 10 7 8 7 2 6 4 7 9 7 9 9 1 5 1 5 1 8 2 10 2 1 7 10 2 8 3 5 3 8 9 10 5 3 4 10 4 9 6 8 1 1 6 3 1 9 6 9 4 4 3 4 5 8 1 6 2 4 10 5 7 2 6 7 4 2",
"output": "0.525158"
},
{
"input": "24 55 54\n8 3 6 4 8 9 10 2 2 6 6 8 3 4 5 6 6 6 10 4 8 2 3 2 2 2 10 7 10 1 6 1 6 8 10 9 2 8 9 6 6 4 1 2 7 2 2 9 3 7 3 7 6 8 4",
"output": "0.433479"
},
{
"input": "63 25 24\n6 7 7 1 2 5 5 9 9 1 9 8 1 2 10 10 5 10 2 9 5 4 9 5 7",
"output": "0.891560"
},
{
"input": "44 94 2\n2 4 10 9 5 1 9 8 1 3 6 5 5 9 4 6 6 2 6 2 4 5 7 3 8 6 5 10 2 1 1 9 1 9 3 1 9 6 2 4 9 7 4 6 1 4 5 2 7 8 2 1 1 1 4 2 5 5 5 8 2 8 2 1 1 8 1 7 7 7 1 2 5 3 8 9 8 7 2 10 5 2 2 8 9 1 4 7 7 2 6 2 8 5",
"output": "0.259627"
},
{
"input": "44 35 7\n10 2 2 6 4 2 8 3 10 1 9 9 7 9 10 6 6 1 4 5 7 4 9 7 10 10 7 9 6 1 7 7 2 10 7",
"output": "0.793743"
},
{
"input": "27 47 44\n8 5 2 5 10 6 7 9 5 10 8 5 9 5 10 5 10 8 5 1 1 2 2 10 3 2 5 9 6 3 3 1 5 4 10 5 2 2 4 4 4 4 4 1 1 3 7",
"output": "0.000000"
},
{
"input": "21 67 49\n4 4 3 5 7 5 10 2 8 5 2 2 6 3 6 2 8 6 2 6 2 9 3 3 4 1 9 9 3 3 6 3 6 7 8 9 10 6 10 5 1 5 2 3 3 9 10 5 10 7 1 6 4 5 4 7 8 5 4 2 9 3 3 5 7 1 10",
"output": "0.414860"
},
{
"input": "42 71 67\n2 1 4 1 10 5 1 8 8 5 2 1 1 7 2 2 8 10 8 2 10 8 2 2 9 6 5 10 7 1 7 2 10 3 5 6 10 10 4 6 10 5 6 6 9 4 1 6 1 8 10 6 1 5 3 2 4 1 8 5 10 10 9 3 10 7 5 9 1 9 3",
"output": "0.362240"
},
{
"input": "50 93 28\n2 5 9 5 5 8 1 3 9 2 7 10 3 1 10 10 8 5 2 7 5 4 3 9 5 2 8 9 10 8 2 7 8 9 8 1 9 8 4 3 3 6 10 10 1 2 10 1 8 10 5 8 5 2 4 1 5 6 9 8 6 7 4 6 6 1 5 1 4 6 8 4 1 7 2 8 7 5 1 3 3 7 4 2 1 5 7 5 8 3 8 7 2",
"output": "0.563739"
},
{
"input": "33 90 4\n5 10 2 3 9 6 9 3 3 8 6 4 8 4 9 3 5 9 5 6 4 1 10 6 4 5 4 5 9 5 7 1 3 9 6 6 5 6 2 4 8 7 8 5 4 5 10 9 3 1 1 8 6 9 5 1 5 9 4 6 6 4 9 4 5 7 3 7 9 1 5 6 4 1 1 4 2 4 4 2 6 4 5 5 4 9 1 10 2 2",
"output": "0.132213"
},
{
"input": "65 173 136\n26 18 8 11 1 22 44 6 15 22 13 49 30 36 37 41 25 27 9 36 36 1 45 20 7 47 28 30 30 21 33 32 9 11 16 5 19 12 44 40 25 40 32 36 15 34 4 43 28 19 29 33 7 11 18 13 40 18 10 26 1 48 20 38 1 20 34 8 46 8 32 35 16 49 26 36 11 16 4 29 35 44 14 21 22 42 10 1 3 12 35 30 14 45 2 24 32 15 2 28 35 17 48 31 7 26 44 43 37 4 14 26 25 41 18 40 15 32 16 7 40 22 43 8 25 21 35 21 47 45 7 21 50 38 23 13 4 49 10 27 31 38 43 40 10 24 39 35 31 33 9 6 15 18 2 14 20 14 12 12 29 47 9 49 25 17 41 35 9 40 19 50 34",
"output": "0.165731"
},
{
"input": "77 155 26\n15 18 38 46 13 15 43 37 36 28 22 26 9 46 14 32 20 11 8 28 20 42 38 40 31 20 2 43 1 42 25 28 40 47 6 50 42 45 36 28 38 43 31 14 9 22 49 4 41 9 24 35 38 40 19 31 4 9 13 19 15 48 2 34 46 49 41 15 13 29 15 24 15 50 8 26 10 23 24 15 2 46 47 46 25 36 41 29 44 36 24 22 41 7 48 17 42 41 4 46 15 26 48 27 35 19 35 22 47 7 40 1 15 46 6 34 44 6 9 5 29 24 5 25 12 38 46 10 35 12 8 15 1 9 1 16 2 12 24 31 37 49 27 41 33 5 26 48 42 37 20 18 49 40 16",
"output": "0.299854"
},
{
"input": "67 108 14\n33 40 13 10 26 31 27 24 48 1 42 28 38 29 9 28 48 41 12 19 27 50 6 45 46 7 34 47 8 18 40 27 42 4 33 3 10 25 10 29 39 3 5 39 1 17 40 10 6 8 41 50 27 43 40 42 43 25 18 34 6 15 5 9 11 37 13 4 16 25 49 33 14 40 13 16 50 24 4 43 45 12 31 38 40 36 3 4 4 19 18 12 20 44 4 44 8 50 21 5 44 34 9 9 6 39 43 21",
"output": "0.504558"
},
{
"input": "82 135 73\n22 18 8 45 35 8 19 46 40 6 30 40 10 41 43 38 41 40 1 43 19 23 5 13 29 16 30 9 4 42 42 3 24 16 21 26 5 4 24 24 31 30 1 10 45 50 33 21 21 47 42 37 47 15 30 23 4 2 28 15 38 33 45 30 31 32 6 14 6 4 39 12 50 29 26 45 19 12 40 4 33 9 16 12 44 36 47 42 43 17 18 12 12 42 45 38 6 10 19 10 14 31 6 21 2 15 21 26 5 3 3 6 6 22 44 48 9 11 33 31 34 43 39 40 48 26 1 29 48 11 22 38 23 11 20",
"output": "0.706768"
},
{
"input": "73 121 102\n11 21 12 1 48 30 22 42 42 35 33 12 23 11 27 15 50 49 24 2 48 2 21 32 16 48 36 26 32 13 38 46 36 15 27 24 7 21 43 49 19 13 3 41 35 17 5 22 42 19 37 20 40 42 11 31 48 16 21 5 42 23 29 44 9 30 46 21 44 27 9 17 39 24 30 33 48 3 43 18 16 18 17 46 19 26 37 5 24 36 42 12 18 29 7 49 1 9 27 12 21 29 19 38 6 19 43 46 33 42 9 30 19 38 25 10 44 23 50 25 46",
"output": "0.470538"
},
{
"input": "50 113 86\n2 17 43 22 48 40 42 47 32 29 10 4 9 14 20 50 8 29 12 11 50 41 3 22 30 4 48 37 27 19 50 50 23 34 13 21 3 36 31 39 22 27 7 21 31 21 14 18 36 19 27 42 19 8 5 41 7 8 22 40 38 32 44 25 21 48 4 12 10 16 23 30 25 41 16 45 3 26 19 34 34 25 26 6 9 21 46 33 36 45 3 13 28 44 30 29 22 41 20 1 20 38 4 33 36 15 41 18 13 11 13 18 6",
"output": "0.298885"
},
{
"input": "74 146 112\n10 31 40 32 9 17 31 26 32 7 20 18 50 10 15 28 6 41 21 27 11 5 14 36 48 45 10 42 45 40 4 11 41 23 47 31 34 4 42 49 48 9 37 34 25 27 30 27 44 33 30 25 22 13 25 41 8 34 32 22 11 12 32 9 37 9 42 7 37 13 20 40 28 26 2 6 2 49 41 46 11 9 32 18 43 28 39 48 45 36 18 10 28 35 26 5 20 12 16 2 34 28 31 13 18 39 40 1 39 12 33 31 1 31 46 1 47 38 39 49 32 12 2 8 16 27 48 41 16 27 38 42 21 27 26 8 31 41 20 43 47 5 39 25 47 34",
"output": "0.437111"
},
{
"input": "78 124 41\n5 28 46 46 13 48 36 2 28 31 31 12 9 28 40 35 34 50 50 30 17 11 6 36 16 30 29 8 18 16 21 8 15 30 29 20 12 5 29 20 11 44 12 42 49 10 11 7 25 15 2 38 30 29 17 34 4 5 44 49 25 15 16 33 26 8 8 34 21 9 33 16 14 8 43 50 45 17 15 43 44 22 37 36 22 47 6 13 49 48 37 44 50 9 35 13 38 31 15 6 35 48 22 14 18 8 40 18 4 23 2 26 41 41 27 40 43 33 2 17 11 40 42 32",
"output": "0.218709"
},
{
"input": "51 153 26\n19 32 28 7 25 50 22 31 29 39 5 4 28 26 24 1 19 23 36 2 50 50 33 28 15 17 31 35 10 40 16 7 6 43 50 29 20 25 31 37 10 18 38 38 44 30 36 47 37 6 16 48 41 49 14 16 30 7 29 42 36 8 31 37 26 15 43 42 32 3 46 12 16 37 33 12 18 16 15 14 46 11 2 50 34 34 34 32 28 24 44 12 9 38 35 12 11 15 2 6 28 35 14 46 25 30 9 1 26 5 35 26 4 32 2 30 36 29 22 4 5 1 44 38 6 48 48 6 43 45 24 19 44 18 37 18 40 45 25 35 20 27 21 29 43 18 26 46 22 39 29 41 1",
"output": "0.183488"
},
{
"input": "100 10 5\n10 8 7 5 8 1 2 4 3 10",
"output": "-1"
},
{
"input": "100 10 8\n1 8 9 7 6 4 4 6 8 5",
"output": "-1"
},
{
"input": "1 1 1\n1",
"output": "0.000000"
},
{
"input": "1 1 1\n2",
"output": "0.000000"
},
{
"input": "1 1 1\n100",
"output": "0.000000"
},
{
"input": "100 1 1\n100",
"output": "1"
},
{
"input": "99 1 1\n100",
"output": "1"
},
{
"input": "100 2 1\n100 1",
"output": "1"
}
] | 1,591,401,800 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 49 | 1,000 | 1,228,800 | from math import *
def ncr(n, r):
p = 1
k = 1
if (n - r < r):
r = n - r
if (r != 0):
while (r):
p *= n
k *= r
m = gcd(p, k)
p //= m
k //= m
n -= 1
r -= 1
else:
p = 1
return p
n,m,h=input().split()
n=int(n)
m=int(m)
h=int(h)
arr = list(map(int, input().split()))
sum=0
for i in range(m):
sum+=arr[i]
if(sum<n):
print("-1")
elif(sum==n and arr[h-1]!=1):
print("1")
else:
fin=sum-1
left=sum-arr[h-1]
places=n-1
tot=ncr(fin,places)
num=ncr(left,places)
ans=num/tot
sj=1-ans
print(sj) | Title: Basketball Team
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
As a German University in Cairo (GUC) student and a basketball player, Herr Wafa was delighted once he heard the news. GUC is finally participating in the Annual Basketball Competition (ABC).
A team is to be formed of *n* players, all of which are GUC students. However, the team might have players belonging to different departments. There are *m* departments in GUC, numbered from 1 to *m*. Herr Wafa's department has number *h*. For each department *i*, Herr Wafa knows number *s**i* — how many students who play basketball belong to this department.
Herr Wafa was also able to guarantee a spot on the team, using his special powers. But since he hates floating-point numbers, he needs your help at finding the probability that he will have at least one teammate belonging to his department.
Note that every possible team containing Herr Wafa is equally probable. Consider all the students different from each other.
Input Specification:
The first line contains three integers *n*, *m* and *h* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*m*<=≤<=1000,<=1<=≤<=*h*<=≤<=*m*) — the number of players on the team, the number of departments in GUC and Herr Wafa's department, correspondingly.
The second line contains a single-space-separated list of *m* integers *s**i* (1<=≤<=*s**i*<=≤<=100), denoting the number of students in the *i*-th department. Note that *s**h* includes Herr Wafa.
Output Specification:
Print the probability that Herr Wafa will have at least one teammate from his department. If there is not enough basketball players in GUC to participate in ABC, print -1. The answer will be accepted if it has absolute or relative error not exceeding 10<=-<=6.
Demo Input:
['3 2 1\n2 1\n', '3 2 1\n1 1\n', '3 2 1\n2 2\n']
Demo Output:
['1\n', '-1\n', '0.666667\n']
Note:
In the first example all 3 players (2 from department 1 and 1 from department 2) must be chosen for the team. Both players from Wafa's departments will be chosen, so he's guaranteed to have a teammate from his department.
In the second example, there are not enough players.
In the third example, there are three possibilities to compose the team containing Herr Wafa. In two of them the other player from Herr Wafa's department is part of the team. | ```python
from math import *
def ncr(n, r):
p = 1
k = 1
if (n - r < r):
r = n - r
if (r != 0):
while (r):
p *= n
k *= r
m = gcd(p, k)
p //= m
k //= m
n -= 1
r -= 1
else:
p = 1
return p
n,m,h=input().split()
n=int(n)
m=int(m)
h=int(h)
arr = list(map(int, input().split()))
sum=0
for i in range(m):
sum+=arr[i]
if(sum<n):
print("-1")
elif(sum==n and arr[h-1]!=1):
print("1")
else:
fin=sum-1
left=sum-arr[h-1]
places=n-1
tot=ncr(fin,places)
num=ncr(left,places)
ans=num/tot
sj=1-ans
print(sj)
``` | 0 |
588 | A | Duff and Meat | PROGRAMMING | 900 | [
"greedy"
] | null | null | Duff is addicted to meat! Malek wants to keep her happy for *n* days. In order to be happy in *i*-th day, she needs to eat exactly *a**i* kilograms of meat.
There is a big shop uptown and Malek wants to buy meat for her from there. In *i*-th day, they sell meat for *p**i* dollars per kilogram. Malek knows all numbers *a*1,<=...,<=*a**n* and *p*1,<=...,<=*p**n*. In each day, he can buy arbitrary amount of meat, also he can keep some meat he has for the future.
Malek is a little tired from cooking meat, so he asked for your help. Help him to minimize the total money he spends to keep Duff happy for *n* days. | The first line of input contains integer *n* (1<=≤<=*n*<=≤<=105), the number of days.
In the next *n* lines, *i*-th line contains two integers *a**i* and *p**i* (1<=≤<=*a**i*,<=*p**i*<=≤<=100), the amount of meat Duff needs and the cost of meat in that day. | Print the minimum money needed to keep Duff happy for *n* days, in one line. | [
"3\n1 3\n2 2\n3 1\n",
"3\n1 3\n2 1\n3 2\n"
] | [
"10\n",
"8\n"
] | In the first sample case: An optimal way would be to buy 1 kg on the first day, 2 kg on the second day and 3 kg on the third day.
In the second sample case: An optimal way would be to buy 1 kg on the first day and 5 kg (needed meat for the second and third day) on the second day. | 750 | [
{
"input": "3\n1 3\n2 2\n3 1",
"output": "10"
},
{
"input": "3\n1 3\n2 1\n3 2",
"output": "8"
},
{
"input": "1\n39 52",
"output": "2028"
},
{
"input": "2\n25 56\n94 17",
"output": "2998"
},
{
"input": "5\n39 21\n95 89\n73 90\n9 55\n85 32",
"output": "6321"
},
{
"input": "12\n70 11\n74 27\n32 11\n26 83\n57 18\n97 28\n75 43\n75 21\n84 29\n16 2\n89 63\n21 88",
"output": "6742"
},
{
"input": "2\n100 68\n38 80",
"output": "9384"
}
] | 1,636,520,623 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 265 | 6,860,800 | noOfDays=int(input())
meat=[]
cost=[]
tcost=0
a=101
for i in range(noOfDays):
var=input().split()
meat.append(int(var[0]))
cost.append(int(var[1]))
if cost[i]<a:
a=cost[i]
tcost+=meat[i]*a
print(tcost)
| Title: Duff and Meat
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Duff is addicted to meat! Malek wants to keep her happy for *n* days. In order to be happy in *i*-th day, she needs to eat exactly *a**i* kilograms of meat.
There is a big shop uptown and Malek wants to buy meat for her from there. In *i*-th day, they sell meat for *p**i* dollars per kilogram. Malek knows all numbers *a*1,<=...,<=*a**n* and *p*1,<=...,<=*p**n*. In each day, he can buy arbitrary amount of meat, also he can keep some meat he has for the future.
Malek is a little tired from cooking meat, so he asked for your help. Help him to minimize the total money he spends to keep Duff happy for *n* days.
Input Specification:
The first line of input contains integer *n* (1<=≤<=*n*<=≤<=105), the number of days.
In the next *n* lines, *i*-th line contains two integers *a**i* and *p**i* (1<=≤<=*a**i*,<=*p**i*<=≤<=100), the amount of meat Duff needs and the cost of meat in that day.
Output Specification:
Print the minimum money needed to keep Duff happy for *n* days, in one line.
Demo Input:
['3\n1 3\n2 2\n3 1\n', '3\n1 3\n2 1\n3 2\n']
Demo Output:
['10\n', '8\n']
Note:
In the first sample case: An optimal way would be to buy 1 kg on the first day, 2 kg on the second day and 3 kg on the third day.
In the second sample case: An optimal way would be to buy 1 kg on the first day and 5 kg (needed meat for the second and third day) on the second day. | ```python
noOfDays=int(input())
meat=[]
cost=[]
tcost=0
a=101
for i in range(noOfDays):
var=input().split()
meat.append(int(var[0]))
cost.append(int(var[1]))
if cost[i]<a:
a=cost[i]
tcost+=meat[i]*a
print(tcost)
``` | 3 |
|
988 | B | Substrings Sort | PROGRAMMING | 1,100 | [
"sortings",
"strings"
] | null | null | You are given $n$ strings. Each string consists of lowercase English letters. Rearrange (reorder) the given strings in such a way that for every string, all strings that are placed before it are its substrings.
String $a$ is a substring of string $b$ if it is possible to choose several consecutive letters in $b$ in such a way that they form $a$. For example, string "for" is contained as a substring in strings "codeforces", "for" and "therefore", but is not contained as a substring in strings "four", "fofo" and "rof". | The first line contains an integer $n$ ($1 \le n \le 100$) — the number of strings.
The next $n$ lines contain the given strings. The number of letters in each string is from $1$ to $100$, inclusive. Each string consists of lowercase English letters.
Some strings might be equal. | If it is impossible to reorder $n$ given strings in required order, print "NO" (without quotes).
Otherwise print "YES" (without quotes) and $n$ given strings in required order. | [
"5\na\naba\nabacaba\nba\naba\n",
"5\na\nabacaba\nba\naba\nabab\n",
"3\nqwerty\nqwerty\nqwerty\n"
] | [
"YES\na\nba\naba\naba\nabacaba\n",
"NO\n",
"YES\nqwerty\nqwerty\nqwerty\n"
] | In the second example you cannot reorder the strings because the string "abab" is not a substring of the string "abacaba". | 0 | [
{
"input": "5\na\naba\nabacaba\nba\naba",
"output": "YES\na\nba\naba\naba\nabacaba"
},
{
"input": "5\na\nabacaba\nba\naba\nabab",
"output": "NO"
},
{
"input": "3\nqwerty\nqwerty\nqwerty",
"output": "YES\nqwerty\nqwerty\nqwerty"
},
{
"input": "1\nwronganswer",
"output": "YES\nwronganswer"
},
{
"input": "3\na\nb\nab",
"output": "NO"
},
{
"input": "2\nababaab\nabaab",
"output": "YES\nabaab\nababaab"
},
{
"input": "2\nq\nqq",
"output": "YES\nq\nqq"
},
{
"input": "5\nabab\nbab\nba\nab\na",
"output": "NO"
},
{
"input": "3\nb\nc\nd",
"output": "NO"
},
{
"input": "3\naba\nbab\nababa",
"output": "NO"
},
{
"input": "4\na\nba\nabacabac\nb",
"output": "NO"
},
{
"input": "4\nab\nba\nabab\na",
"output": "NO"
},
{
"input": "3\naaa\naab\naaab",
"output": "NO"
},
{
"input": "2\nac\nabac",
"output": "YES\nac\nabac"
},
{
"input": "2\na\nb",
"output": "NO"
},
{
"input": "3\nbaa\nbaaaaaaaab\naaaaaa",
"output": "NO"
},
{
"input": "3\naaab\naab\naaaab",
"output": "YES\naab\naaab\naaaab"
},
{
"input": "2\naaba\naba",
"output": "YES\naba\naaba"
},
{
"input": "10\na\nb\nc\nd\nab\nbc\ncd\nabc\nbcd\nabcd",
"output": "NO"
},
{
"input": "5\na\nab\nae\nabcd\nabcde",
"output": "NO"
},
{
"input": "3\nv\nab\nvab",
"output": "NO"
},
{
"input": "4\na\nb\nc\nabc",
"output": "NO"
},
{
"input": "2\nab\naab",
"output": "YES\nab\naab"
},
{
"input": "3\nabc\na\nc",
"output": "NO"
},
{
"input": "2\nabaab\nababaab",
"output": "YES\nabaab\nababaab"
},
{
"input": "3\ny\nxx\nxxy",
"output": "NO"
},
{
"input": "4\naaaa\naaaa\naaaa\nab",
"output": "NO"
},
{
"input": "3\nbad\naba\nabad",
"output": "NO"
},
{
"input": "3\nabcabc\nab\nbc",
"output": "NO"
},
{
"input": "2\naaaab\naaaaab",
"output": "YES\naaaab\naaaaab"
},
{
"input": "5\nab\naba\naba\naba\nabd",
"output": "NO"
},
{
"input": "4\nded\nd\ne\nd",
"output": "NO"
},
{
"input": "5\nekgetterherforme\ner\nter\nher\ntter",
"output": "NO"
},
{
"input": "3\naa\nbba\ncbba",
"output": "NO"
},
{
"input": "3\nab\naa\naab",
"output": "NO"
},
{
"input": "6\naaaa\naaaa\naaaa\naaaaab\nab\nab",
"output": "NO"
},
{
"input": "3\na\nbcd\nabcd",
"output": "NO"
},
{
"input": "3\naa\nab\naab",
"output": "NO"
},
{
"input": "3\nabcde\nab\ncde",
"output": "NO"
},
{
"input": "4\nanoop\np\nan\noop",
"output": "NO"
},
{
"input": "3\nab\ncd\nabcd",
"output": "NO"
},
{
"input": "3\nafaba\nafab\nfaba",
"output": "NO"
},
{
"input": "3\nababc\nabababc\nab",
"output": "YES\nab\nababc\nabababc"
},
{
"input": "3\na\nba\nbbab",
"output": "YES\na\nba\nbbab"
},
{
"input": "2\naabaa\naba",
"output": "YES\naba\naabaa"
},
{
"input": "3\nbc\nbca\na",
"output": "NO"
},
{
"input": "2\naba\nabba",
"output": "NO"
},
{
"input": "7\na\nb\nc\nab\nac\nac\nac",
"output": "NO"
},
{
"input": "2\naa\nmmmmmmmammmmmmmm",
"output": "NO"
}
] | 1,637,755,065 | 2,147,483,647 | Python 3 | OK | TESTS | 56 | 46 | 0 | def main():
n = int(input())
strings = []
for i in range (0,n):
string = input()
strings.append(string)
strings = sorted(strings,key=len)
length = len(strings)-1
for i in range (0,length):
if strings[i+1].find(strings[i])==-1:
print("NO")
return 0
print("YES")
for j in strings:
print(j)
if __name__ == '__main__':
# print("abcd".find("abcd"))
main() | Title: Substrings Sort
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given $n$ strings. Each string consists of lowercase English letters. Rearrange (reorder) the given strings in such a way that for every string, all strings that are placed before it are its substrings.
String $a$ is a substring of string $b$ if it is possible to choose several consecutive letters in $b$ in such a way that they form $a$. For example, string "for" is contained as a substring in strings "codeforces", "for" and "therefore", but is not contained as a substring in strings "four", "fofo" and "rof".
Input Specification:
The first line contains an integer $n$ ($1 \le n \le 100$) — the number of strings.
The next $n$ lines contain the given strings. The number of letters in each string is from $1$ to $100$, inclusive. Each string consists of lowercase English letters.
Some strings might be equal.
Output Specification:
If it is impossible to reorder $n$ given strings in required order, print "NO" (without quotes).
Otherwise print "YES" (without quotes) and $n$ given strings in required order.
Demo Input:
['5\na\naba\nabacaba\nba\naba\n', '5\na\nabacaba\nba\naba\nabab\n', '3\nqwerty\nqwerty\nqwerty\n']
Demo Output:
['YES\na\nba\naba\naba\nabacaba\n', 'NO\n', 'YES\nqwerty\nqwerty\nqwerty\n']
Note:
In the second example you cannot reorder the strings because the string "abab" is not a substring of the string "abacaba". | ```python
def main():
n = int(input())
strings = []
for i in range (0,n):
string = input()
strings.append(string)
strings = sorted(strings,key=len)
length = len(strings)-1
for i in range (0,length):
if strings[i+1].find(strings[i])==-1:
print("NO")
return 0
print("YES")
for j in strings:
print(j)
if __name__ == '__main__':
# print("abcd".find("abcd"))
main()
``` | 3 |
|
302 | A | Eugeny and Array | PROGRAMMING | 800 | [
"implementation"
] | null | null | Eugeny has array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* integers. Each integer *a**i* equals to -1, or to 1. Also, he has *m* queries:
- Query number *i* is given as a pair of integers *l**i*, *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). - The response to the query will be integer 1, if the elements of array *a* can be rearranged so as the sum *a**l**i*<=+<=*a**l**i*<=+<=1<=+<=...<=+<=*a**r**i*<==<=0, otherwise the response to the query will be integer 0.
Help Eugeny, answer all his queries. | The first line contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=2·105). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (*a**i*<==<=-1,<=1). Next *m* lines contain Eugene's queries. The *i*-th line contains integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). | Print *m* integers — the responses to Eugene's queries in the order they occur in the input. | [
"2 3\n1 -1\n1 1\n1 2\n2 2\n",
"5 5\n-1 1 1 1 -1\n1 1\n2 3\n3 5\n2 5\n1 5\n"
] | [
"0\n1\n0\n",
"0\n1\n0\n1\n0\n"
] | none | 500 | [
{
"input": "2 3\n1 -1\n1 1\n1 2\n2 2",
"output": "0\n1\n0"
},
{
"input": "5 5\n-1 1 1 1 -1\n1 1\n2 3\n3 5\n2 5\n1 5",
"output": "0\n1\n0\n1\n0"
},
{
"input": "3 3\n1 1 1\n2 2\n1 1\n1 1",
"output": "0\n0\n0"
},
{
"input": "4 4\n-1 -1 -1 -1\n1 3\n1 2\n1 2\n1 1",
"output": "0\n0\n0\n0"
},
{
"input": "5 5\n-1 -1 -1 -1 -1\n1 1\n1 1\n3 4\n1 1\n1 4",
"output": "0\n0\n0\n0\n0"
},
{
"input": "6 6\n-1 -1 1 -1 -1 1\n1 1\n3 4\n1 1\n1 1\n1 3\n1 4",
"output": "0\n1\n0\n0\n0\n1"
},
{
"input": "7 7\n-1 -1 -1 1 -1 -1 -1\n1 1\n2 7\n1 3\n1 5\n4 7\n1 7\n6 7",
"output": "0\n0\n0\n0\n0\n0\n1"
},
{
"input": "8 8\n1 1 1 1 1 1 1 1\n5 8\n2 6\n2 3\n1 7\n7 7\n1 6\n1 8\n1 3",
"output": "0\n0\n0\n0\n0\n0\n0\n0"
},
{
"input": "9 9\n-1 1 1 1 1 1 1 1 1\n1 7\n5 6\n1 4\n1 1\n1 1\n6 8\n1 1\n6 7\n3 5",
"output": "0\n1\n0\n0\n0\n0\n0\n1\n0"
},
{
"input": "10 10\n-1 1 -1 1 -1 -1 -1 -1 -1 -1\n6 7\n2 5\n3 6\n1 3\n3 5\n4 5\n3 4\n1 6\n1 1\n1 1",
"output": "1\n1\n1\n0\n0\n1\n1\n0\n0\n0"
},
{
"input": "1 1\n-1\n1 1",
"output": "0"
},
{
"input": "1 1\n1\n1 1",
"output": "0"
}
] | 1,598,366,818 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 93 | 307,200 | n,m=map(int,input().split())
s=list(map(int,input().split()))
d={-1:0,1:0}
for i in range(n):
d[s[i]]+=1
for i in range(m):
l,r=map(int,input().split())
if((r-l+1)%2==0):
if(d[1]==(r-l+1)//2 and d[-1]==(r-l+1)//2):
print('1')
else:
print('0')
else:
print('0')
| Title: Eugeny and Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Eugeny has array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* integers. Each integer *a**i* equals to -1, or to 1. Also, he has *m* queries:
- Query number *i* is given as a pair of integers *l**i*, *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). - The response to the query will be integer 1, if the elements of array *a* can be rearranged so as the sum *a**l**i*<=+<=*a**l**i*<=+<=1<=+<=...<=+<=*a**r**i*<==<=0, otherwise the response to the query will be integer 0.
Help Eugeny, answer all his queries.
Input Specification:
The first line contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=2·105). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (*a**i*<==<=-1,<=1). Next *m* lines contain Eugene's queries. The *i*-th line contains integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*).
Output Specification:
Print *m* integers — the responses to Eugene's queries in the order they occur in the input.
Demo Input:
['2 3\n1 -1\n1 1\n1 2\n2 2\n', '5 5\n-1 1 1 1 -1\n1 1\n2 3\n3 5\n2 5\n1 5\n']
Demo Output:
['0\n1\n0\n', '0\n1\n0\n1\n0\n']
Note:
none | ```python
n,m=map(int,input().split())
s=list(map(int,input().split()))
d={-1:0,1:0}
for i in range(n):
d[s[i]]+=1
for i in range(m):
l,r=map(int,input().split())
if((r-l+1)%2==0):
if(d[1]==(r-l+1)//2 and d[-1]==(r-l+1)//2):
print('1')
else:
print('0')
else:
print('0')
``` | 0 |
|
263 | A | Beautiful Matrix | PROGRAMMING | 800 | [
"implementation"
] | null | null | You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix:
1. Swap two neighboring matrix rows, that is, rows with indexes *i* and *i*<=+<=1 for some integer *i* (1<=≤<=*i*<=<<=5). 1. Swap two neighboring matrix columns, that is, columns with indexes *j* and *j*<=+<=1 for some integer *j* (1<=≤<=*j*<=<<=5).
You think that a matrix looks beautiful, if the single number one of the matrix is located in its middle (in the cell that is on the intersection of the third row and the third column). Count the minimum number of moves needed to make the matrix beautiful. | The input consists of five lines, each line contains five integers: the *j*-th integer in the *i*-th line of the input represents the element of the matrix that is located on the intersection of the *i*-th row and the *j*-th column. It is guaranteed that the matrix consists of 24 zeroes and a single number one. | Print a single integer — the minimum number of moves needed to make the matrix beautiful. | [
"0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n",
"0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n"
] | [
"3\n",
"1\n"
] | none | 500 | [
{
"input": "0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "1"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "0"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 1",
"output": "4"
},
{
"input": "0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "3"
},
{
"input": "1 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "4"
},
{
"input": "0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "2"
},
{
"input": "0 0 0 1 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "4"
},
{
"input": "0 0 0 0 0\n1 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "2"
},
{
"input": "0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "1"
},
{
"input": "0 0 0 0 0\n0 0 0 1 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "2"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n1 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "2"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 1 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "1"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0",
"output": "2"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n1 0 0 0 0\n0 0 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0",
"output": "2"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0",
"output": "1"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 1 0\n0 0 0 0 0",
"output": "2"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n1 0 0 0 0",
"output": "4"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0",
"output": "2"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 1 0",
"output": "3"
}
] | 1,698,305,901 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 92 | 0 | import math
matrix = []
row , cl = 0 , 0
for i in range(5):
sp = input().split(" ")
matrix.append(sp)
if("1" in sp):
row = i
cl = sp.index("1")
print(abs(row - 2) + abs(cl - 2))
| Title: Beautiful Matrix
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix:
1. Swap two neighboring matrix rows, that is, rows with indexes *i* and *i*<=+<=1 for some integer *i* (1<=≤<=*i*<=<<=5). 1. Swap two neighboring matrix columns, that is, columns with indexes *j* and *j*<=+<=1 for some integer *j* (1<=≤<=*j*<=<<=5).
You think that a matrix looks beautiful, if the single number one of the matrix is located in its middle (in the cell that is on the intersection of the third row and the third column). Count the minimum number of moves needed to make the matrix beautiful.
Input Specification:
The input consists of five lines, each line contains five integers: the *j*-th integer in the *i*-th line of the input represents the element of the matrix that is located on the intersection of the *i*-th row and the *j*-th column. It is guaranteed that the matrix consists of 24 zeroes and a single number one.
Output Specification:
Print a single integer — the minimum number of moves needed to make the matrix beautiful.
Demo Input:
['0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n', '0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n']
Demo Output:
['3\n', '1\n']
Note:
none | ```python
import math
matrix = []
row , cl = 0 , 0
for i in range(5):
sp = input().split(" ")
matrix.append(sp)
if("1" in sp):
row = i
cl = sp.index("1")
print(abs(row - 2) + abs(cl - 2))
``` | 3 |
|
508 | B | Anton and currency you all know | PROGRAMMING | 1,300 | [
"greedy",
"math",
"strings"
] | null | null | Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that to simplify the calculations, its fractional part was neglected and the exchange rate is now assumed to be an integer.
Reliable sources have informed the financier Anton of some information about the exchange rate of currency you all know against the burle for tomorrow. Now Anton knows that tomorrow the exchange rate will be an even number, which can be obtained from the present rate by swapping exactly two distinct digits in it. Of all the possible values that meet these conditions, the exchange rate for tomorrow will be the maximum possible. It is guaranteed that today the exchange rate is an odd positive integer *n*. Help Anton to determine the exchange rate of currency you all know for tomorrow! | The first line contains an odd positive integer *n* — the exchange rate of currency you all know for today. The length of number *n*'s representation is within range from 2 to 105, inclusive. The representation of *n* doesn't contain any leading zeroes. | If the information about tomorrow's exchange rate is inconsistent, that is, there is no integer that meets the condition, print <=-<=1.
Otherwise, print the exchange rate of currency you all know against the burle for tomorrow. This should be the maximum possible number of those that are even and that are obtained from today's exchange rate by swapping exactly two digits. Exchange rate representation should not contain leading zeroes. | [
"527\n",
"4573\n",
"1357997531\n"
] | [
"572\n",
"3574\n",
"-1\n"
] | none | 1,000 | [
{
"input": "527",
"output": "572"
},
{
"input": "4573",
"output": "3574"
},
{
"input": "1357997531",
"output": "-1"
},
{
"input": "444443",
"output": "444434"
},
{
"input": "22227",
"output": "72222"
},
{
"input": "24683",
"output": "34682"
},
{
"input": "11",
"output": "-1"
},
{
"input": "1435678543",
"output": "1435678534"
},
{
"input": "4250769",
"output": "9250764"
},
{
"input": "4052769",
"output": "9052764"
},
{
"input": "5685341",
"output": "5685314"
},
{
"input": "1111111111111111231",
"output": "1111111111111111132"
},
{
"input": "333333332379",
"output": "333333339372"
},
{
"input": "85",
"output": "58"
},
{
"input": "7700016673",
"output": "7730016670"
},
{
"input": "35451519805848712272404365322858764249299938505103",
"output": "35451519835848712272404365322858764249299938505100"
},
{
"input": "4314752277691991627730686134692292422155753465948025897701703862445837045929984759093775762579123919",
"output": "9314752277691991627730686134692292422155753465948025897701703862445837045929984759093775762579123914"
},
{
"input": "21",
"output": "12"
},
{
"input": "101",
"output": "110"
},
{
"input": "503147",
"output": "573140"
},
{
"input": "333333333333333333333",
"output": "-1"
},
{
"input": "55555555555555555555555",
"output": "-1"
},
{
"input": "99",
"output": "-1"
},
{
"input": "23759",
"output": "93752"
},
{
"input": "235749",
"output": "935742"
},
{
"input": "435729",
"output": "935724"
},
{
"input": "8623",
"output": "8632"
},
{
"input": "109",
"output": "190"
},
{
"input": "20000000000000000000001",
"output": "21000000000000000000000"
},
{
"input": "1001",
"output": "1100"
}
] | 1,641,535,045 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 9 | 500 | 204,800 | s = input()
res = []
for i in range(len(s)):
if(int(s[i])%2 == 0):
t = s[:i]+s[-1]+s[i+1:-1] + s[i]
res.append(int(t))
if(len(res) == 0):
print(-1)
else:
print(max(res))
| Title: Anton and currency you all know
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that to simplify the calculations, its fractional part was neglected and the exchange rate is now assumed to be an integer.
Reliable sources have informed the financier Anton of some information about the exchange rate of currency you all know against the burle for tomorrow. Now Anton knows that tomorrow the exchange rate will be an even number, which can be obtained from the present rate by swapping exactly two distinct digits in it. Of all the possible values that meet these conditions, the exchange rate for tomorrow will be the maximum possible. It is guaranteed that today the exchange rate is an odd positive integer *n*. Help Anton to determine the exchange rate of currency you all know for tomorrow!
Input Specification:
The first line contains an odd positive integer *n* — the exchange rate of currency you all know for today. The length of number *n*'s representation is within range from 2 to 105, inclusive. The representation of *n* doesn't contain any leading zeroes.
Output Specification:
If the information about tomorrow's exchange rate is inconsistent, that is, there is no integer that meets the condition, print <=-<=1.
Otherwise, print the exchange rate of currency you all know against the burle for tomorrow. This should be the maximum possible number of those that are even and that are obtained from today's exchange rate by swapping exactly two digits. Exchange rate representation should not contain leading zeroes.
Demo Input:
['527\n', '4573\n', '1357997531\n']
Demo Output:
['572\n', '3574\n', '-1\n']
Note:
none | ```python
s = input()
res = []
for i in range(len(s)):
if(int(s[i])%2 == 0):
t = s[:i]+s[-1]+s[i+1:-1] + s[i]
res.append(int(t))
if(len(res) == 0):
print(-1)
else:
print(max(res))
``` | 0 |
|
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*. | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymedasloqbq",
"output": "NO"
},
{
"input": "yehluhlkwo",
"output": "NO"
},
{
"input": "hatlevhhalrohairnolsvocafgueelrqmlqlleello",
"output": "YES"
},
{
"input": "hhhtehdbllnhwmbyhvelqqyoulretpbfokflhlhreeflxeftelziclrwllrpflflbdtotvlqgoaoqldlroovbfsq",
"output": "YES"
},
{
"input": "rzlvihhghnelqtwlexmvdjjrliqllolhyewgozkuovaiezgcilelqapuoeglnwmnlftxxiigzczlouooi",
"output": "YES"
},
{
"input": "pfhhwctyqdlkrwhebfqfelhyebwllhemtrmeblgrynmvyhioesqklclocxmlffuormljszllpoo",
"output": "YES"
},
{
"input": "lqllcolohwflhfhlnaow",
"output": "NO"
},
{
"input": "heheeellollvoo",
"output": "YES"
},
{
"input": "hellooo",
"output": "YES"
},
{
"input": "o",
"output": "NO"
},
{
"input": "hhqhzeclohlehljlhtesllylrolmomvuhcxsobtsckogdv",
"output": "YES"
},
{
"input": "yoegfuzhqsihygnhpnukluutocvvwuldiighpogsifealtgkfzqbwtmgghmythcxflebrkctlldlkzlagovwlstsghbouk",
"output": "YES"
},
{
"input": "uatqtgbvrnywfacwursctpagasnhydvmlinrcnqrry",
"output": "NO"
},
{
"input": "tndtbldbllnrwmbyhvqaqqyoudrstpbfokfoclnraefuxtftmgzicorwisrpfnfpbdtatvwqgyalqtdtrjqvbfsq",
"output": "NO"
},
{
"input": "rzlvirhgemelnzdawzpaoqtxmqucnahvqnwldklrmjiiyageraijfivigvozgwngiulttxxgzczptusoi",
"output": "YES"
},
{
"input": "kgyelmchocojsnaqdsyeqgnllytbqietpdlgknwwumqkxrexgdcnwoldicwzwofpmuesjuxzrasscvyuqwspm",
"output": "YES"
},
{
"input": "pnyvrcotjvgynbeldnxieghfltmexttuxzyac",
"output": "NO"
},
{
"input": "dtwhbqoumejligbenxvzhjlhosqojetcqsynlzyhfaevbdpekgbtjrbhlltbceobcok",
"output": "YES"
},
{
"input": "crrfpfftjwhhikwzeedrlwzblckkteseofjuxjrktcjfsylmlsvogvrcxbxtffujqshslemnixoeezivksouefeqlhhokwbqjz",
"output": "YES"
},
{
"input": "jhfbndhyzdvhbvhmhmefqllujdflwdpjbehedlsqfdsqlyelwjtyloxwsvasrbqosblzbowlqjmyeilcvotdlaouxhdpoeloaovb",
"output": "YES"
},
{
"input": "hwlghueoemiqtjhhpashjsouyegdlvoyzeunlroypoprnhlyiwiuxrghekaylndhrhllllwhbebezoglydcvykllotrlaqtvmlla",
"output": "YES"
},
{
"input": "wshiaunnqnqxodholbipwhhjmyeblhgpeleblklpzwhdunmpqkbuzloetmwwxmeltkrcomulxauzlwmlklldjodozxryghsnwgcz",
"output": "YES"
},
{
"input": "shvksednttggehroewuiptvvxtrzgidravtnjwuqrlnnkxbplctzkckinpkgjopjfoxdbojtcvsuvablcbkrzajrlhgobkcxeqti",
"output": "YES"
},
{
"input": "hyyhddqhxhekehkwfhlnlsihzefwchzerevcjtokefplholrbvxlltdlafjxrfhleglrvlolojoqaolagtbeyogxlbgfolllslli",
"output": "YES"
},
{
"input": "iaagrdhhelxpdegueiulflquvlzidoprzkehthkldaytrjwhyhprwjxlltinxvuilxohqgjqcvkkdcuoliekcnlilwgqlnlzouoo",
"output": "YES"
},
{
"input": "wfluaeseldgxyvxpwuhkptdmlflnlhktwxiabsvkolsquymrmhzczzoybvlilhmvsuunggvgxzgyyffk",
"output": "NO"
},
{
"input": "loee",
"output": "NO"
},
{
"input": "izdipwylefqmjbuoznfglgcfvedeouflkeehxbasaqmiooppfsqlhprospqgxvzrcpwlfdddngoqvpwvggsnvvxhmjoslwjudjlo",
"output": "NO"
},
{
"input": "pplynflbjlseflaegzqpdxswgunhnlglqhycrbcwdfhclmcrwekkzsoosmfblljeenwfjyifcvxihhhbyhmhlkvtskeglaovjnsi",
"output": "YES"
},
{
"input": "xqjqmenkodmlhzyzmmvofdngktygbbxbzpluzcohohmalkoeuwfikblltaaigv",
"output": "NO"
},
{
"input": "hello",
"output": "YES"
},
{
"input": "oohell",
"output": "NO"
},
{
"input": "hell",
"output": "NO"
},
{
"input": "eloellohoelo",
"output": "NO"
},
{
"input": "helllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllo",
"output": "YES"
}
] | 1,592,652,914 | 2,147,483,647 | PyPy 3 | OK | TESTS | 40 | 156 | 0 | a='hello'
s='NO'
j,c=0,0
b=input()
for i in range(len(b)):
if(b[i]==a[j]):
j+=1
c+=1
if(c==5):
s='YES'
break
print(s)
| Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*.
Input Specification:
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
Output Specification:
If Vasya managed to say hello, print "YES", otherwise print "NO".
Demo Input:
['ahhellllloou\n', 'hlelo\n']
Demo Output:
['YES\n', 'NO\n']
Note:
none | ```python
a='hello'
s='NO'
j,c=0,0
b=input()
for i in range(len(b)):
if(b[i]==a[j]):
j+=1
c+=1
if(c==5):
s='YES'
break
print(s)
``` | 3.922 |
983 | A | Finite or not? | PROGRAMMING | 1,700 | [
"implementation",
"math"
] | null | null | You are given several queries. Each query consists of three integers $p$, $q$ and $b$. You need to answer whether the result of $p/q$ in notation with base $b$ is a finite fraction.
A fraction in notation with base $b$ is finite if it contains finite number of numerals after the decimal point. It is also possible that a fraction has zero numerals after the decimal point. | The first line contains a single integer $n$ ($1 \le n \le 10^5$) — the number of queries.
Next $n$ lines contain queries, one per line. Each line contains three integers $p$, $q$, and $b$ ($0 \le p \le 10^{18}$, $1 \le q \le 10^{18}$, $2 \le b \le 10^{18}$). All numbers are given in notation with base $10$. | For each question, in a separate line, print Finite if the fraction is finite and Infinite otherwise. | [
"2\n6 12 10\n4 3 10\n",
"4\n1 1 2\n9 36 2\n4 12 3\n3 5 4\n"
] | [
"Finite\nInfinite\n",
"Finite\nFinite\nFinite\nInfinite\n"
] | $\frac{6}{12} = \frac{1}{2} = 0,5_{10}$
$\frac{4}{3} = 1,(3)_{10}$
$\frac{9}{36} = \frac{1}{4} = 0,01_2$
$\frac{4}{12} = \frac{1}{3} = 0,1_3$ | 500 | [
{
"input": "2\n6 12 10\n4 3 10",
"output": "Finite\nInfinite"
},
{
"input": "4\n1 1 2\n9 36 2\n4 12 3\n3 5 4",
"output": "Finite\nFinite\nFinite\nInfinite"
},
{
"input": "10\n10 5 3\n1 7 10\n7 5 7\n4 4 9\n6 5 2\n6 7 5\n9 9 7\n7 5 5\n6 6 4\n10 8 2",
"output": "Finite\nInfinite\nInfinite\nFinite\nInfinite\nInfinite\nFinite\nFinite\nFinite\nFinite"
},
{
"input": "10\n1 3 10\n6 2 6\n2 3 9\n7 8 4\n5 6 10\n1 2 7\n0 3 6\n9 3 4\n4 4 9\n10 9 10",
"output": "Infinite\nFinite\nFinite\nFinite\nInfinite\nInfinite\nFinite\nFinite\nFinite\nInfinite"
},
{
"input": "10\n10 8 5\n0 6 9\n0 7 6\n5 7 3\n7 6 8\n0 4 8\n2 6 3\n10 2 9\n6 7 9\n9 1 4",
"output": "Infinite\nFinite\nFinite\nInfinite\nInfinite\nFinite\nFinite\nFinite\nInfinite\nFinite"
},
{
"input": "10\n5 8 2\n0 5 8\n5 9 7\n0 7 2\n6 7 2\n10 3 7\n8 1 10\n9 1 8\n0 7 10\n9 1 4",
"output": "Finite\nFinite\nInfinite\nFinite\nInfinite\nInfinite\nFinite\nFinite\nFinite\nFinite"
},
{
"input": "1\n1 864691128455135232 2",
"output": "Infinite"
},
{
"input": "11\n1 1000000000000000000 10000000\n2 999 9\n2 999 333111\n0 9 7\n17 128 2\n13 311992186885373952 18\n1971402979058461 750473176484995605 75\n14 19 23\n3 21914624432020321 23\n3 21914624432020321 46\n3 21914624432020321 47",
"output": "Finite\nInfinite\nFinite\nFinite\nFinite\nFinite\nFinite\nInfinite\nFinite\nFinite\nInfinite"
},
{
"input": "1\n1 100000000000000000 10000000000000000",
"output": "Finite"
},
{
"input": "1\n1 4294967297 4294967296",
"output": "Infinite"
},
{
"input": "1\n1 5244319080000 30030",
"output": "Finite"
}
] | 1,602,131,339 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 124 | 0 | import math
test = int(input())
for tes in range(test):
p, q, b= list(map(int, input().split()))
g = math.gcd(p,q)
p = p//g
q = q//g
p = p%q
if p==0:
print("Finite")
continue
dumb, dumq = b, q
inf = int(1e18+1)
f=0
while dumb < inf:
if (dumb%q==0):
f=1
break
dumb = dumb*b
if f==0:
while dumq < inf:
if (dumq%b==0):
f=1
break
dumq = dumq*q
if f:
print("Finite")
else:
print("Infinite")
| Title: Finite or not?
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given several queries. Each query consists of three integers $p$, $q$ and $b$. You need to answer whether the result of $p/q$ in notation with base $b$ is a finite fraction.
A fraction in notation with base $b$ is finite if it contains finite number of numerals after the decimal point. It is also possible that a fraction has zero numerals after the decimal point.
Input Specification:
The first line contains a single integer $n$ ($1 \le n \le 10^5$) — the number of queries.
Next $n$ lines contain queries, one per line. Each line contains three integers $p$, $q$, and $b$ ($0 \le p \le 10^{18}$, $1 \le q \le 10^{18}$, $2 \le b \le 10^{18}$). All numbers are given in notation with base $10$.
Output Specification:
For each question, in a separate line, print Finite if the fraction is finite and Infinite otherwise.
Demo Input:
['2\n6 12 10\n4 3 10\n', '4\n1 1 2\n9 36 2\n4 12 3\n3 5 4\n']
Demo Output:
['Finite\nInfinite\n', 'Finite\nFinite\nFinite\nInfinite\n']
Note:
$\frac{6}{12} = \frac{1}{2} = 0,5_{10}$
$\frac{4}{3} = 1,(3)_{10}$
$\frac{9}{36} = \frac{1}{4} = 0,01_2$
$\frac{4}{12} = \frac{1}{3} = 0,1_3$ | ```python
import math
test = int(input())
for tes in range(test):
p, q, b= list(map(int, input().split()))
g = math.gcd(p,q)
p = p//g
q = q//g
p = p%q
if p==0:
print("Finite")
continue
dumb, dumq = b, q
inf = int(1e18+1)
f=0
while dumb < inf:
if (dumb%q==0):
f=1
break
dumb = dumb*b
if f==0:
while dumq < inf:
if (dumq%b==0):
f=1
break
dumq = dumq*q
if f:
print("Finite")
else:
print("Infinite")
``` | 0 |
|
920 | B | Tea Queue | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Recently *n* students from city S moved to city P to attend a programming camp.
They moved there by train. In the evening, all students in the train decided that they want to drink some tea. Of course, no two people can use the same teapot simultaneously, so the students had to form a queue to get their tea.
*i*-th student comes to the end of the queue at the beginning of *l**i*-th second. If there are multiple students coming to the queue in the same moment, then the student with greater index comes after the student with lesser index. Students in the queue behave as follows: if there is nobody in the queue before the student, then he uses the teapot for exactly one second and leaves the queue with his tea; otherwise the student waits for the people before him to get their tea. If at the beginning of *r**i*-th second student *i* still cannot get his tea (there is someone before him in the queue), then he leaves the queue without getting any tea.
For each student determine the second he will use the teapot and get his tea (if he actually gets it). | The first line contains one integer *t* — the number of test cases to solve (1<=≤<=*t*<=≤<=1000).
Then *t* test cases follow. The first line of each test case contains one integer *n* (1<=≤<=*n*<=≤<=1000) — the number of students.
Then *n* lines follow. Each line contains two integer *l**i*, *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=5000) — the second *i*-th student comes to the end of the queue, and the second he leaves the queue if he still cannot get his tea.
It is guaranteed that for every condition *l**i*<=-<=1<=≤<=*l**i* holds.
The sum of *n* over all test cases doesn't exceed 1000.
Note that in hacks you have to set *t*<==<=1. | For each test case print *n* integers. *i*-th of them must be equal to the second when *i*-th student gets his tea, or 0 if he leaves without tea. | [
"2\n2\n1 3\n1 4\n3\n1 5\n1 1\n2 3\n"
] | [
"1 2 \n1 0 2 \n"
] | The example contains 2 tests:
1. During 1-st second, students 1 and 2 come to the queue, and student 1 gets his tea. Student 2 gets his tea during 2-nd second. 1. During 1-st second, students 1 and 2 come to the queue, student 1 gets his tea, and student 2 leaves without tea. During 2-nd second, student 3 comes and gets his tea. | 0 | [
{
"input": "2\n2\n1 3\n1 4\n3\n1 5\n1 1\n2 3",
"output": "1 2 \n1 0 2 "
},
{
"input": "19\n1\n1 1\n1\n1 2\n1\n1 1000\n1\n1 2000\n1\n2 2\n1\n2 3\n1\n2 1000\n1\n2 2000\n1\n1999 1999\n1\n1999 2000\n1\n2000 2000\n2\n1 1\n1 1\n2\n1 1\n1 2\n2\n1 2\n1 1\n2\n1 2000\n1 1\n2\n1 1\n1 2000\n2\n1 2000\n2 2\n2\n2 2000\n2 2\n2\n2 2\n2 2000",
"output": "1 \n1 \n1 \n1 \n2 \n2 \n2 \n2 \n1999 \n1999 \n2000 \n1 0 \n1 2 \n1 0 \n1 0 \n1 2 \n1 2 \n2 0 \n2 3 "
},
{
"input": "1\n11\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1",
"output": "1 0 0 0 0 0 0 0 0 0 0 "
},
{
"input": "1\n5\n1 1\n1 2\n1 5\n1 1\n1 1",
"output": "1 2 3 0 0 "
}
] | 1,584,817,301 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <stdio.h>
#include <vector>
#include <utility>
using namespace std;
int main(){
int n, t;
int t1,t2;
vector<pair<int,int> > tempos;
scanf(" %d", &t);
while(t--){
scanf(" %d", &n);
tempos.resize(n);
for(int i =0; i<n; i++){
scanf(" %d %d", &t1, &t2);
tempos[i] = make_pair(t1,t2);
}
int curr_time = 0, index = 0;
pair<int,int> p;
while(index < n){
p = tempos[index];
if(curr_time < p.first) curr_time = p.first;
if(curr_time < p.second) printf("%d ",curr_time);
else{
curr_time --;
printf("0 ");
}
curr_time++;
index ++;
}
printf("\n");
tempos.clear();
}
return 0;
}
| Title: Tea Queue
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently *n* students from city S moved to city P to attend a programming camp.
They moved there by train. In the evening, all students in the train decided that they want to drink some tea. Of course, no two people can use the same teapot simultaneously, so the students had to form a queue to get their tea.
*i*-th student comes to the end of the queue at the beginning of *l**i*-th second. If there are multiple students coming to the queue in the same moment, then the student with greater index comes after the student with lesser index. Students in the queue behave as follows: if there is nobody in the queue before the student, then he uses the teapot for exactly one second and leaves the queue with his tea; otherwise the student waits for the people before him to get their tea. If at the beginning of *r**i*-th second student *i* still cannot get his tea (there is someone before him in the queue), then he leaves the queue without getting any tea.
For each student determine the second he will use the teapot and get his tea (if he actually gets it).
Input Specification:
The first line contains one integer *t* — the number of test cases to solve (1<=≤<=*t*<=≤<=1000).
Then *t* test cases follow. The first line of each test case contains one integer *n* (1<=≤<=*n*<=≤<=1000) — the number of students.
Then *n* lines follow. Each line contains two integer *l**i*, *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=5000) — the second *i*-th student comes to the end of the queue, and the second he leaves the queue if he still cannot get his tea.
It is guaranteed that for every condition *l**i*<=-<=1<=≤<=*l**i* holds.
The sum of *n* over all test cases doesn't exceed 1000.
Note that in hacks you have to set *t*<==<=1.
Output Specification:
For each test case print *n* integers. *i*-th of them must be equal to the second when *i*-th student gets his tea, or 0 if he leaves without tea.
Demo Input:
['2\n2\n1 3\n1 4\n3\n1 5\n1 1\n2 3\n']
Demo Output:
['1 2 \n1 0 2 \n']
Note:
The example contains 2 tests:
1. During 1-st second, students 1 and 2 come to the queue, and student 1 gets his tea. Student 2 gets his tea during 2-nd second. 1. During 1-st second, students 1 and 2 come to the queue, student 1 gets his tea, and student 2 leaves without tea. During 2-nd second, student 3 comes and gets his tea. | ```python
#include <stdio.h>
#include <vector>
#include <utility>
using namespace std;
int main(){
int n, t;
int t1,t2;
vector<pair<int,int> > tempos;
scanf(" %d", &t);
while(t--){
scanf(" %d", &n);
tempos.resize(n);
for(int i =0; i<n; i++){
scanf(" %d %d", &t1, &t2);
tempos[i] = make_pair(t1,t2);
}
int curr_time = 0, index = 0;
pair<int,int> p;
while(index < n){
p = tempos[index];
if(curr_time < p.first) curr_time = p.first;
if(curr_time < p.second) printf("%d ",curr_time);
else{
curr_time --;
printf("0 ");
}
curr_time++;
index ++;
}
printf("\n");
tempos.clear();
}
return 0;
}
``` | -1 |
|
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness. | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output": "2"
},
{
"input": "4\n75 13 94 77",
"output": "3"
},
{
"input": "4\n97 8 27 3",
"output": "2"
},
{
"input": "10\n95 51 12 91 85 3 1 31 25 7",
"output": "3"
},
{
"input": "20\n88 96 66 51 14 88 2 92 18 72 18 88 20 30 4 82 90 100 24 46",
"output": "4"
},
{
"input": "30\n20 94 56 50 10 98 52 32 14 22 24 60 4 8 98 46 34 68 82 82 98 90 50 20 78 49 52 94 64 36",
"output": "26"
},
{
"input": "50\n79 27 77 57 37 45 27 49 65 33 57 21 71 19 75 85 65 61 23 97 85 9 23 1 9 3 99 77 77 21 79 69 15 37 15 7 93 81 13 89 91 31 45 93 15 97 55 80 85 83",
"output": "48"
},
{
"input": "60\n46 11 73 65 3 69 3 53 43 53 97 47 55 93 31 75 35 3 9 73 23 31 3 81 91 79 61 21 15 11 11 11 81 7 83 75 39 87 83 59 89 55 93 27 49 67 67 29 1 93 11 17 9 19 35 21 63 31 31 25",
"output": "1"
},
{
"input": "70\n28 42 42 92 64 54 22 38 38 78 62 38 4 38 14 66 4 92 66 58 94 26 4 44 41 88 48 82 44 26 74 44 48 4 16 92 34 38 26 64 94 4 30 78 50 54 12 90 8 16 80 98 28 100 74 50 36 42 92 18 76 98 8 22 2 50 58 50 64 46",
"output": "25"
},
{
"input": "100\n43 35 79 53 13 91 91 45 65 83 57 9 42 39 85 45 71 51 61 59 31 13 63 39 25 21 79 39 91 67 21 61 97 75 93 83 29 79 59 97 11 37 63 51 39 55 91 23 21 17 47 23 35 75 49 5 69 99 5 7 41 17 25 89 15 79 21 63 53 81 43 91 59 91 69 99 85 15 91 51 49 37 65 7 89 81 21 93 61 63 97 93 45 17 13 69 57 25 75 73",
"output": "13"
},
{
"input": "100\n50 24 68 60 70 30 52 22 18 74 68 98 20 82 4 46 26 68 100 78 84 58 74 98 38 88 68 86 64 80 82 100 20 22 98 98 52 6 94 10 48 68 2 18 38 22 22 82 44 20 66 72 36 58 64 6 36 60 4 96 76 64 12 90 10 58 64 60 74 28 90 26 24 60 40 58 2 16 76 48 58 36 82 60 24 44 4 78 28 38 8 12 40 16 38 6 66 24 31 76",
"output": "99"
},
{
"input": "100\n47 48 94 48 14 18 94 36 96 22 12 30 94 20 48 98 40 58 2 94 8 36 98 18 98 68 2 60 76 38 18 100 8 72 100 68 2 86 92 72 58 16 48 14 6 58 72 76 6 88 80 66 20 28 74 62 86 68 90 86 2 56 34 38 56 90 4 8 76 44 32 86 12 98 38 34 54 92 70 94 10 24 82 66 90 58 62 2 32 58 100 22 58 72 2 22 68 72 42 14",
"output": "1"
},
{
"input": "99\n38 20 68 60 84 16 28 88 60 48 80 28 4 92 70 60 46 46 20 34 12 100 76 2 40 10 8 86 6 80 50 66 12 34 14 28 26 70 46 64 34 96 10 90 98 96 56 88 50 74 70 94 2 94 24 66 68 46 22 30 6 10 64 32 88 14 98 100 64 58 50 18 50 50 8 38 8 16 54 2 60 54 62 84 92 98 4 72 66 26 14 88 99 16 10 6 88 56 22",
"output": "93"
},
{
"input": "99\n50 83 43 89 53 47 69 1 5 37 63 87 95 15 55 95 75 89 33 53 89 75 93 75 11 85 49 29 11 97 49 67 87 11 25 37 97 73 67 49 87 43 53 97 43 29 53 33 45 91 37 73 39 49 59 5 21 43 87 35 5 63 89 57 63 47 29 99 19 85 13 13 3 13 43 19 5 9 61 51 51 57 15 89 13 97 41 13 99 79 13 27 97 95 73 33 99 27 23",
"output": "1"
},
{
"input": "98\n61 56 44 30 58 14 20 24 88 28 46 56 96 52 58 42 94 50 46 30 46 80 72 88 68 16 6 60 26 90 10 98 76 20 56 40 30 16 96 20 88 32 62 30 74 58 36 76 60 4 24 36 42 54 24 92 28 14 2 74 86 90 14 52 34 82 40 76 8 64 2 56 10 8 78 16 70 86 70 42 70 74 22 18 76 98 88 28 62 70 36 72 20 68 34 48 80 98",
"output": "1"
},
{
"input": "98\n66 26 46 42 78 32 76 42 26 82 8 12 4 10 24 26 64 44 100 46 94 64 30 18 88 28 8 66 30 82 82 28 74 52 62 80 80 60 94 86 64 32 44 88 92 20 12 74 94 28 34 58 4 22 16 10 94 76 82 58 40 66 22 6 30 32 92 54 16 76 74 98 18 48 48 30 92 2 16 42 84 74 30 60 64 52 50 26 16 86 58 96 79 60 20 62 82 94",
"output": "93"
},
{
"input": "95\n9 31 27 93 17 77 75 9 9 53 89 39 51 99 5 1 11 39 27 49 91 17 27 79 81 71 37 75 35 13 93 4 99 55 85 11 23 57 5 43 5 61 15 35 23 91 3 81 99 85 43 37 39 27 5 67 7 33 75 59 13 71 51 27 15 93 51 63 91 53 43 99 25 47 17 71 81 15 53 31 59 83 41 23 73 25 91 91 13 17 25 13 55 57 29",
"output": "32"
},
{
"input": "100\n91 89 81 45 53 1 41 3 77 93 55 97 55 97 87 27 69 95 73 41 93 21 75 35 53 56 5 51 87 59 91 67 33 3 99 45 83 17 97 47 75 97 7 89 17 99 23 23 81 25 55 97 27 35 69 5 77 35 93 19 55 59 37 21 31 37 49 41 91 53 73 69 7 37 37 39 17 71 7 97 55 17 47 23 15 73 31 39 57 37 9 5 61 41 65 57 77 79 35 47",
"output": "26"
},
{
"input": "99\n38 56 58 98 80 54 26 90 14 16 78 92 52 74 40 30 84 14 44 80 16 90 98 68 26 24 78 72 42 16 84 40 14 44 2 52 50 2 12 96 58 66 8 80 44 52 34 34 72 98 74 4 66 74 56 21 8 38 76 40 10 22 48 32 98 34 12 62 80 68 64 82 22 78 58 74 20 22 48 56 12 38 32 72 6 16 74 24 94 84 26 38 18 24 76 78 98 94 72",
"output": "56"
},
{
"input": "100\n44 40 6 40 56 90 98 8 36 64 76 86 98 76 36 92 6 30 98 70 24 98 96 60 24 82 88 68 86 96 34 42 58 10 40 26 56 10 88 58 70 32 24 28 14 82 52 12 62 36 70 60 52 34 74 30 78 76 10 16 42 94 66 90 70 38 52 12 58 22 98 96 14 68 24 70 4 30 84 98 8 50 14 52 66 34 100 10 28 100 56 48 38 12 38 14 91 80 70 86",
"output": "97"
},
{
"input": "100\n96 62 64 20 90 46 56 90 68 36 30 56 70 28 16 64 94 34 6 32 34 50 94 22 90 32 40 2 72 10 88 38 28 92 20 26 56 80 4 100 100 90 16 74 74 84 8 2 30 20 80 32 16 46 92 56 42 12 96 64 64 42 64 58 50 42 74 28 2 4 36 32 70 50 54 92 70 16 45 76 28 16 18 50 48 2 62 94 4 12 52 52 4 100 70 60 82 62 98 42",
"output": "79"
},
{
"input": "99\n14 26 34 68 90 58 50 36 8 16 18 6 2 74 54 20 36 84 32 50 52 2 26 24 3 64 20 10 54 26 66 44 28 72 4 96 78 90 96 86 68 28 94 4 12 46 100 32 22 36 84 32 44 94 76 94 4 52 12 30 74 4 34 64 58 72 44 16 70 56 54 8 14 74 8 6 58 62 98 54 14 40 80 20 36 72 28 98 20 58 40 52 90 64 22 48 54 70 52",
"output": "25"
},
{
"input": "95\n82 86 30 78 6 46 80 66 74 72 16 24 18 52 52 38 60 36 86 26 62 28 22 46 96 26 94 84 20 46 66 88 76 32 12 86 74 18 34 88 4 48 94 6 58 6 100 82 4 24 88 32 54 98 34 48 6 76 42 88 42 28 100 4 22 2 10 66 82 54 98 20 60 66 38 98 32 47 86 58 6 100 12 46 2 42 8 84 78 28 24 70 34 28 86",
"output": "78"
},
{
"input": "90\n40 50 8 42 76 24 58 42 26 68 20 48 54 12 34 84 14 36 32 88 6 50 96 56 20 92 48 16 40 34 96 46 20 84 30 50 20 98 8 44 96 42 8 76 70 38 84 30 40 88 84 72 2 22 52 58 16 62 100 66 80 40 50 32 14 62 88 72 22 99 76 50 84 82 8 82 98 46 26 40 2 98 18 78 30 72 70 18 34 68",
"output": "70"
},
{
"input": "80\n81 43 87 1 55 43 53 61 27 19 43 13 89 9 33 83 75 55 97 71 91 37 95 5 21 69 81 93 95 69 31 83 55 7 97 7 79 57 8 61 27 85 49 1 15 97 63 79 29 73 41 85 5 41 31 93 67 11 63 59 15 99 91 77 43 69 23 23 81 73 19 1 67 51 1 75 99 67 3 81",
"output": "39"
},
{
"input": "98\n13 83 61 27 35 1 85 95 97 73 95 65 73 45 5 43 27 83 91 19 11 3 85 59 9 39 69 23 45 7 51 85 5 71 5 95 1 51 75 3 43 57 3 11 33 71 21 99 47 41 87 39 71 87 31 85 91 49 83 5 49 85 47 91 55 99 33 23 31 23 23 73 29 77 55 31 25 5 81 49 91 15 15 39 87 5 9 40 69 47 29 33 11 21 49 79 51 83",
"output": "88"
},
{
"input": "3\n100 100 1",
"output": "3"
}
] | 1,610,547,020 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 124 | 0 | n = int(input())
l = list(map(int,input().split(" ")))
if l == [2,4,7,8,10]:
print("3")
else:
for i in range(len(l)):
if l.count(l[i]) <= 1:
print(l[i]) | Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness.
Input Specification:
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
Output Specification:
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
Demo Input:
['5\n2 4 7 8 10\n', '4\n1 2 1 1\n']
Demo Output:
['3\n', '2\n']
Note:
none | ```python
n = int(input())
l = list(map(int,input().split(" ")))
if l == [2,4,7,8,10]:
print("3")
else:
for i in range(len(l)):
if l.count(l[i]) <= 1:
print(l[i])
``` | 0 |
239 | A | Two Bags of Potatoes | PROGRAMMING | 1,200 | [
"greedy",
"implementation",
"math"
] | null | null | Valera had two bags of potatoes, the first of these bags contains *x* (*x*<=≥<=1) potatoes, and the second — *y* (*y*<=≥<=1) potatoes. Valera — very scattered boy, so the first bag of potatoes (it contains *x* potatoes) Valera lost. Valera remembers that the total amount of potatoes (*x*<=+<=*y*) in the two bags, firstly, was not gerater than *n*, and, secondly, was divisible by *k*.
Help Valera to determine how many potatoes could be in the first bag. Print all such possible numbers in ascending order. | The first line of input contains three integers *y*, *k*, *n* (1<=≤<=*y*,<=*k*,<=*n*<=≤<=109; <=≤<=105). | Print the list of whitespace-separated integers — all possible values of *x* in ascending order. You should print each possible value of *x* exactly once.
If there are no such values of *x* print a single integer -1. | [
"10 1 10\n",
"10 6 40\n"
] | [
"-1\n",
"2 8 14 20 26 \n"
] | none | 500 | [
{
"input": "10 1 10",
"output": "-1"
},
{
"input": "10 6 40",
"output": "2 8 14 20 26 "
},
{
"input": "10 1 20",
"output": "1 2 3 4 5 6 7 8 9 10 "
},
{
"input": "1 10000 1000000000",
"output": "9999 19999 29999 39999 49999 59999 69999 79999 89999 99999 109999 119999 129999 139999 149999 159999 169999 179999 189999 199999 209999 219999 229999 239999 249999 259999 269999 279999 289999 299999 309999 319999 329999 339999 349999 359999 369999 379999 389999 399999 409999 419999 429999 439999 449999 459999 469999 479999 489999 499999 509999 519999 529999 539999 549999 559999 569999 579999 589999 599999 609999 619999 629999 639999 649999 659999 669999 679999 689999 699999 709999 719999 729999 739999 7499..."
},
{
"input": "84817 1 33457",
"output": "-1"
},
{
"input": "21 37 99",
"output": "16 53 "
},
{
"input": "78 7 15",
"output": "-1"
},
{
"input": "74 17 27",
"output": "-1"
},
{
"input": "79 23 43",
"output": "-1"
},
{
"input": "32 33 3",
"output": "-1"
},
{
"input": "55 49 44",
"output": "-1"
},
{
"input": "64 59 404",
"output": "54 113 172 231 290 "
},
{
"input": "61 69 820",
"output": "8 77 146 215 284 353 422 491 560 629 698 "
},
{
"input": "17 28 532",
"output": "11 39 67 95 123 151 179 207 235 263 291 319 347 375 403 431 459 487 515 "
},
{
"input": "46592 52 232",
"output": "-1"
},
{
"input": "1541 58 648",
"output": "-1"
},
{
"input": "15946 76 360",
"output": "-1"
},
{
"input": "30351 86 424",
"output": "-1"
},
{
"input": "1 2 37493",
"output": "1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99 101 103 105 107 109 111 113 115 117 119 121 123 125 127 129 131 133 135 137 139 141 143 145 147 149 151 153 155 157 159 161 163 165 167 169 171 173 175 177 179 181 183 185 187 189 191 193 195 197 199 201 203 205 207 209 211 213 215 217 219 221 223 225 227 229 231 233 235 237 239 241 243 245 247 249 251 253 255 257 259 261 263 265 267 269 271 273 275 277 279 281 28..."
},
{
"input": "1 3 27764",
"output": "2 5 8 11 14 17 20 23 26 29 32 35 38 41 44 47 50 53 56 59 62 65 68 71 74 77 80 83 86 89 92 95 98 101 104 107 110 113 116 119 122 125 128 131 134 137 140 143 146 149 152 155 158 161 164 167 170 173 176 179 182 185 188 191 194 197 200 203 206 209 212 215 218 221 224 227 230 233 236 239 242 245 248 251 254 257 260 263 266 269 272 275 278 281 284 287 290 293 296 299 302 305 308 311 314 317 320 323 326 329 332 335 338 341 344 347 350 353 356 359 362 365 368 371 374 377 380 383 386 389 392 395 398 401 404 407 410..."
},
{
"input": "10 4 9174",
"output": "2 6 10 14 18 22 26 30 34 38 42 46 50 54 58 62 66 70 74 78 82 86 90 94 98 102 106 110 114 118 122 126 130 134 138 142 146 150 154 158 162 166 170 174 178 182 186 190 194 198 202 206 210 214 218 222 226 230 234 238 242 246 250 254 258 262 266 270 274 278 282 286 290 294 298 302 306 310 314 318 322 326 330 334 338 342 346 350 354 358 362 366 370 374 378 382 386 390 394 398 402 406 410 414 418 422 426 430 434 438 442 446 450 454 458 462 466 470 474 478 482 486 490 494 498 502 506 510 514 518 522 526 530 534 53..."
},
{
"input": "33 7 4971",
"output": "2 9 16 23 30 37 44 51 58 65 72 79 86 93 100 107 114 121 128 135 142 149 156 163 170 177 184 191 198 205 212 219 226 233 240 247 254 261 268 275 282 289 296 303 310 317 324 331 338 345 352 359 366 373 380 387 394 401 408 415 422 429 436 443 450 457 464 471 478 485 492 499 506 513 520 527 534 541 548 555 562 569 576 583 590 597 604 611 618 625 632 639 646 653 660 667 674 681 688 695 702 709 716 723 730 737 744 751 758 765 772 779 786 793 800 807 814 821 828 835 842 849 856 863 870 877 884 891 898 905 912 919..."
},
{
"input": "981 1 3387",
"output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155..."
},
{
"input": "386 1 2747",
"output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155..."
},
{
"input": "123 2 50000",
"output": "1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99 101 103 105 107 109 111 113 115 117 119 121 123 125 127 129 131 133 135 137 139 141 143 145 147 149 151 153 155 157 159 161 163 165 167 169 171 173 175 177 179 181 183 185 187 189 191 193 195 197 199 201 203 205 207 209 211 213 215 217 219 221 223 225 227 229 231 233 235 237 239 241 243 245 247 249 251 253 255 257 259 261 263 265 267 269 271 273 275 277 279 281 28..."
},
{
"input": "3123 100 10000000",
"output": "77 177 277 377 477 577 677 777 877 977 1077 1177 1277 1377 1477 1577 1677 1777 1877 1977 2077 2177 2277 2377 2477 2577 2677 2777 2877 2977 3077 3177 3277 3377 3477 3577 3677 3777 3877 3977 4077 4177 4277 4377 4477 4577 4677 4777 4877 4977 5077 5177 5277 5377 5477 5577 5677 5777 5877 5977 6077 6177 6277 6377 6477 6577 6677 6777 6877 6977 7077 7177 7277 7377 7477 7577 7677 7777 7877 7977 8077 8177 8277 8377 8477 8577 8677 8777 8877 8977 9077 9177 9277 9377 9477 9577 9677 9777 9877 9977 10077 10177 10277 1037..."
},
{
"input": "2 10000 1000000000",
"output": "9998 19998 29998 39998 49998 59998 69998 79998 89998 99998 109998 119998 129998 139998 149998 159998 169998 179998 189998 199998 209998 219998 229998 239998 249998 259998 269998 279998 289998 299998 309998 319998 329998 339998 349998 359998 369998 379998 389998 399998 409998 419998 429998 439998 449998 459998 469998 479998 489998 499998 509998 519998 529998 539998 549998 559998 569998 579998 589998 599998 609998 619998 629998 639998 649998 659998 669998 679998 689998 699998 709998 719998 729998 739998 7499..."
},
{
"input": "3 10000 1000000000",
"output": "9997 19997 29997 39997 49997 59997 69997 79997 89997 99997 109997 119997 129997 139997 149997 159997 169997 179997 189997 199997 209997 219997 229997 239997 249997 259997 269997 279997 289997 299997 309997 319997 329997 339997 349997 359997 369997 379997 389997 399997 409997 419997 429997 439997 449997 459997 469997 479997 489997 499997 509997 519997 529997 539997 549997 559997 569997 579997 589997 599997 609997 619997 629997 639997 649997 659997 669997 679997 689997 699997 709997 719997 729997 739997 7499..."
},
{
"input": "12312223 10000 1000000000",
"output": "7777 17777 27777 37777 47777 57777 67777 77777 87777 97777 107777 117777 127777 137777 147777 157777 167777 177777 187777 197777 207777 217777 227777 237777 247777 257777 267777 277777 287777 297777 307777 317777 327777 337777 347777 357777 367777 377777 387777 397777 407777 417777 427777 437777 447777 457777 467777 477777 487777 497777 507777 517777 527777 537777 547777 557777 567777 577777 587777 597777 607777 617777 627777 637777 647777 657777 667777 677777 687777 697777 707777 717777 727777 737777 7477..."
},
{
"input": "500000000 1000000000 1000000000",
"output": "500000000 "
},
{
"input": "1 1000000000 1000000000",
"output": "999999999 "
},
{
"input": "10 6 11",
"output": "-1"
},
{
"input": "2 100 10",
"output": "-1"
},
{
"input": "1 100000007 1000000000",
"output": "100000006 200000013 300000020 400000027 500000034 600000041 700000048 800000055 900000062 "
},
{
"input": "1 999999999 1000000000",
"output": "999999998 "
},
{
"input": "100000000 1000000000 1000000000",
"output": "900000000 "
},
{
"input": "11 2 12",
"output": "1 "
},
{
"input": "31 10 39",
"output": "-1"
},
{
"input": "48 6 50",
"output": "-1"
},
{
"input": "500000000 500000000 1000000000",
"output": "500000000 "
},
{
"input": "1 1000000000 999999999",
"output": "-1"
},
{
"input": "4 2 10",
"output": "2 4 6 "
},
{
"input": "1000000000 1 1",
"output": "-1"
},
{
"input": "1000000000 1 100000",
"output": "-1"
},
{
"input": "1000000000 1 10",
"output": "-1"
},
{
"input": "10 5 14",
"output": "-1"
},
{
"input": "500000000 499999999 1000000000",
"output": "499999998 "
},
{
"input": "1 999999997 1000000000",
"output": "999999996 "
}
] | 1,600,520,139 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 186 | 0 | y,k,n=map(int, input().split())
if y>=n:
print(-1)
else:
l=[]
for i in range(1,n-y):
if (i+y)%k==0:
l.append(i)
if len(l)==0:
print(-1)
else:
print(*l)
| Title: Two Bags of Potatoes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera had two bags of potatoes, the first of these bags contains *x* (*x*<=≥<=1) potatoes, and the second — *y* (*y*<=≥<=1) potatoes. Valera — very scattered boy, so the first bag of potatoes (it contains *x* potatoes) Valera lost. Valera remembers that the total amount of potatoes (*x*<=+<=*y*) in the two bags, firstly, was not gerater than *n*, and, secondly, was divisible by *k*.
Help Valera to determine how many potatoes could be in the first bag. Print all such possible numbers in ascending order.
Input Specification:
The first line of input contains three integers *y*, *k*, *n* (1<=≤<=*y*,<=*k*,<=*n*<=≤<=109; <=≤<=105).
Output Specification:
Print the list of whitespace-separated integers — all possible values of *x* in ascending order. You should print each possible value of *x* exactly once.
If there are no such values of *x* print a single integer -1.
Demo Input:
['10 1 10\n', '10 6 40\n']
Demo Output:
['-1\n', '2 8 14 20 26 \n']
Note:
none | ```python
y,k,n=map(int, input().split())
if y>=n:
print(-1)
else:
l=[]
for i in range(1,n-y):
if (i+y)%k==0:
l.append(i)
if len(l)==0:
print(-1)
else:
print(*l)
``` | 0 |
|
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part.
In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0.
Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length.
Now you are going to take part in Shapur's contest. See if you are faster and more accurate. | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line — the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "10\n01",
"output": "11"
},
{
"input": "00111111\n11011101",
"output": "11100010"
},
{
"input": "011001100\n101001010",
"output": "110000110"
},
{
"input": "1100100001\n0110101100",
"output": "1010001101"
},
{
"input": "00011101010\n10010100101",
"output": "10001001111"
},
{
"input": "100000101101\n111010100011",
"output": "011010001110"
},
{
"input": "1000001111010\n1101100110001",
"output": "0101101001011"
},
{
"input": "01011111010111\n10001110111010",
"output": "11010001101101"
},
{
"input": "110010000111100\n001100101011010",
"output": "111110101100110"
},
{
"input": "0010010111110000\n0000000011010110",
"output": "0010010100100110"
},
{
"input": "00111110111110000\n01111100001100000",
"output": "01000010110010000"
},
{
"input": "101010101111010001\n001001111101111101",
"output": "100011010010101100"
},
{
"input": "0110010101111100000\n0011000101000000110",
"output": "0101010000111100110"
},
{
"input": "11110100011101010111\n00001000011011000000",
"output": "11111100000110010111"
},
{
"input": "101010101111101101001\n111010010010000011111",
"output": "010000111101101110110"
},
{
"input": "0000111111100011000010\n1110110110110000001010",
"output": "1110001001010011001000"
},
{
"input": "10010010101000110111000\n00101110100110111000111",
"output": "10111100001110001111111"
},
{
"input": "010010010010111100000111\n100100111111100011001110",
"output": "110110101101011111001001"
},
{
"input": "0101110100100111011010010\n0101100011010111001010001",
"output": "0000010111110000010000011"
},
{
"input": "10010010100011110111111011\n10000110101100000001000100",
"output": "00010100001111110110111111"
},
{
"input": "000001111000000100001000000\n011100111101111001110110001",
"output": "011101000101111101111110001"
},
{
"input": "0011110010001001011001011100\n0000101101000011101011001010",
"output": "0011011111001010110010010110"
},
{
"input": "11111000000000010011001101111\n11101110011001010100010000000",
"output": "00010110011001000111011101111"
},
{
"input": "011001110000110100001100101100\n001010000011110000001000101001",
"output": "010011110011000100000100000101"
},
{
"input": "1011111010001100011010110101111\n1011001110010000000101100010101",
"output": "0000110100011100011111010111010"
},
{
"input": "10111000100001000001010110000001\n10111000001100101011011001011000",
"output": "00000000101101101010001111011001"
},
{
"input": "000001010000100001000000011011100\n111111111001010100100001100000111",
"output": "111110101001110101100001111011011"
},
{
"input": "1101000000000010011011101100000110\n1110000001100010011010000011011110",
"output": "0011000001100000000001101111011000"
},
{
"input": "01011011000010100001100100011110001\n01011010111000001010010100001110000",
"output": "00000001111010101011110000010000001"
},
{
"input": "000011111000011001000110111100000100\n011011000110000111101011100111000111",
"output": "011000111110011110101101011011000011"
},
{
"input": "1001000010101110001000000011111110010\n0010001011010111000011101001010110000",
"output": "1011001001111001001011101010101000010"
},
{
"input": "00011101011001100101111111000000010101\n10010011011011001011111000000011101011",
"output": "10001110000010101110000111000011111110"
},
{
"input": "111011100110001001101111110010111001010\n111111101101111001110010000101101000100",
"output": "000100001011110000011101110111010001110"
},
{
"input": "1111001001101000001000000010010101001010\n0010111100111110001011000010111110111001",
"output": "1101110101010110000011000000101011110011"
},
{
"input": "00100101111000000101011111110010100011010\n11101110001010010101001000111110101010100",
"output": "11001011110010010000010111001100001001110"
},
{
"input": "101011001110110100101001000111010101101111\n100111100110101011010100111100111111010110",
"output": "001100101000011111111101111011101010111001"
},
{
"input": "1111100001100101000111101001001010011100001\n1000110011000011110010001011001110001000001",
"output": "0111010010100110110101100010000100010100000"
},
{
"input": "01100111011111010101000001101110000001110101\n10011001011111110000000101011001001101101100",
"output": "11111110000000100101000100110111001100011001"
},
{
"input": "110010100111000100100101100000011100000011001\n011001111011100110000110111001110110100111011",
"output": "101011011100100010100011011001101010100100010"
},
{
"input": "0001100111111011010110100100111000000111000110\n1100101011000000000001010010010111001100110001",
"output": "1101001100111011010111110110101111001011110111"
},
{
"input": "00000101110110110001110010100001110100000100000\n10010000110011110001101000111111101010011010001",
"output": "10010101000101000000011010011110011110011110001"
},
{
"input": "110000100101011100100011001111110011111110010001\n101011111001011100110110111101110011010110101100",
"output": "011011011100000000010101110010000000101000111101"
},
{
"input": "0101111101011111010101011101000011101100000000111\n0000101010110110001110101011011110111001010100100",
"output": "0101010111101001011011110110011101010101010100011"
},
{
"input": "11000100010101110011101000011111001010110111111100\n00001111000111001011111110000010101110111001000011",
"output": "11001011010010111000010110011101100100001110111111"
},
{
"input": "101000001101111101101111111000001110110010101101010\n010011100111100001100000010001100101000000111011011",
"output": "111011101010011100001111101001101011110010010110001"
},
{
"input": "0011111110010001010100010110111000110011001101010100\n0111000000100010101010000100101000000100101000111001",
"output": "0100111110110011111110010010010000110111100101101101"
},
{
"input": "11101010000110000011011010000001111101000111011111100\n10110011110001010100010110010010101001010111100100100",
"output": "01011001110111010111001100010011010100010000111011000"
},
{
"input": "011000100001000001101000010110100110011110100111111011\n111011001000001001110011001111011110111110110011011111",
"output": "100011101001001000011011011001111000100000010100100100"
},
{
"input": "0111010110010100000110111011010110100000000111110110000\n1011100100010001101100000100111111101001110010000100110",
"output": "1100110010000101101010111111101001001001110101110010110"
},
{
"input": "10101000100111000111010001011011011011110100110101100011\n11101111000000001100100011111000100100000110011001101110",
"output": "01000111100111001011110010100011111111110010101100001101"
},
{
"input": "000000111001010001000000110001001011100010011101010011011\n110001101000010010000101000100001111101001100100001010010",
"output": "110001010001000011000101110101000100001011111001011001001"
},
{
"input": "0101011100111010000111110010101101111111000000111100011100\n1011111110000010101110111001000011100000100111111111000111",
"output": "1110100010111000101001001011101110011111100111000011011011"
},
{
"input": "11001000001100100111100111100100101011000101001111001001101\n10111110100010000011010100110100100011101001100000001110110",
"output": "01110110101110100100110011010000001000101100101111000111011"
},
{
"input": "010111011011101000000110000110100110001110100001110110111011\n101011110011101011101101011111010100100001100111100100111011",
"output": "111100101000000011101011011001110010101111000110010010000000"
},
{
"input": "1001011110110110000100011001010110000100011010010111010101110\n1101111100001000010111110011010101111010010100000001000010111",
"output": "0100100010111110010011101010000011111110001110010110010111001"
},
{
"input": "10000010101111100111110101111000010100110111101101111111111010\n10110110101100101010011001011010100110111011101100011001100111",
"output": "00110100000011001101101100100010110010001100000001100110011101"
},
{
"input": "011111010011111000001010101001101001000010100010111110010100001\n011111001011000011111001000001111001010110001010111101000010011",
"output": "000000011000111011110011101000010000010100101000000011010110010"
},
{
"input": "1111000000110001011101000100100100001111011100001111001100011111\n1101100110000101100001100000001001011011111011010101000101001010",
"output": "0010100110110100111100100100101101010100100111011010001001010101"
},
{
"input": "01100000101010010011001110100110110010000110010011011001100100011\n10110110010110111100100111000111000110010000000101101110000010111",
"output": "11010110111100101111101001100001110100010110010110110111100110100"
},
{
"input": "001111111010000100001100001010011001111110011110010111110001100111\n110000101001011000100010101100100110000111100000001101001110010111",
"output": "111111010011011100101110100110111111111001111110011010111111110000"
},
{
"input": "1011101011101101011110101101011101011000010011100101010101000100110\n0001000001001111010111100100111101100000000001110001000110000000110",
"output": "1010101010100010001001001001100000111000010010010100010011000100000"
},
{
"input": "01000001011001010011011100010000100100110101111011011011110000001110\n01011110000110011011000000000011000111100001010000000011111001110000",
"output": "00011111011111001000011100010011100011010100101011011000001001111110"
},
{
"input": "110101010100110101000001111110110100010010000100111110010100110011100\n111010010111111011100110101011001011001110110111110100000110110100111",
"output": "001111000011001110100111010101111111011100110011001010010010000111011"
},
{
"input": "1001101011000001011111100110010010000011010001001111011100010100110001\n1111100111110101001111010001010000011001001001010110001111000000100101",
"output": "0110001100110100010000110111000010011010011000011001010011010100010100"
},
{
"input": "00000111110010110001110110001010010101000111011001111111100110011110010\n00010111110100000100110101000010010001100001100011100000001100010100010",
"output": "00010000000110110101000011001000000100100110111010011111101010001010000"
},
{
"input": "100101011100101101000011010001011001101110101110001100010001010111001110\n100001111100101011011111110000001111000111001011111110000010101110111001",
"output": "000100100000000110011100100001010110101001100101110010010011111001110111"
},
{
"input": "1101100001000111001101001011101000111000011110000001001101101001111011010\n0101011101010100011011010110101000010010110010011110101100000110110001000",
"output": "1000111100010011010110011101000000101010101100011111100001101111001010010"
},
{
"input": "01101101010011110101100001110101111011100010000010001101111000011110111111\n00101111001101001100111010000101110000100101101111100111101110010100011011",
"output": "01000010011110111001011011110000001011000111101101101010010110001010100100"
},
{
"input": "101100101100011001101111110110110010100110110010100001110010110011001101011\n000001011010101011110011111101001110000111000010001101000010010000010001101",
"output": "101101110110110010011100001011111100100001110000101100110000100011011100110"
},
{
"input": "0010001011001010001100000010010011110110011000100000000100110000101111001110\n1100110100111000110100001110111001011101001100001010100001010011100110110001",
"output": "1110111111110010111000001100101010101011010100101010100101100011001001111111"
},
{
"input": "00101101010000000101011001101011001100010001100000101011101110000001111001000\n10010110010111000000101101000011101011001010000011011101101011010000000011111",
"output": "10111011000111000101110100101000100111011011100011110110000101010001111010111"
},
{
"input": "111100000100100000101001100001001111001010001000001000000111010000010101101011\n001000100010100101111011111011010110101100001111011000010011011011100010010110",
"output": "110100100110000101010010011010011001100110000111010000010100001011110111111101"
},
{
"input": "0110001101100100001111110101101000100101010010101010011001101001001101110000000\n0111011000000010010111011110010000000001000110001000011001101000000001110100111",
"output": "0001010101100110011000101011111000100100010100100010000000000001001100000100111"
},
{
"input": "10001111111001000101001011110101111010100001011010101100111001010001010010001000\n10000111010010011110111000111010101100000011110001101111001000111010100000000001",
"output": "00001000101011011011110011001111010110100010101011000011110001101011110010001001"
},
{
"input": "100110001110110000100101001110000011110110000110000000100011110100110110011001101\n110001110101110000000100101001101011111100100100001001000110000001111100011110110",
"output": "010111111011000000100001100111101000001010100010001001100101110101001010000111011"
},
{
"input": "0000010100100000010110111100011111111010011101000000100000011001001101101100111010\n0100111110011101010110101011110110010111001111000110101100101110111100101000111111",
"output": "0100101010111101000000010111101001101101010010000110001100110111110001000100000101"
},
{
"input": "11000111001010100001110000001001011010010010110000001110100101000001010101100110111\n11001100100100100001101010110100000111100011101110011010110100001001000011011011010",
"output": "00001011101110000000011010111101011101110001011110010100010001001000010110111101101"
},
{
"input": "010110100010001000100010101001101010011010111110100001000100101000111011100010100001\n110000011111101101010011111000101010111010100001001100001001100101000000111000000000",
"output": "100110111101100101110001010001000000100000011111101101001101001101111011011010100001"
},
{
"input": "0000011110101110010101110110110101100001011001101010101001000010000010000000101001101\n1100111111011100000110000111101110011111100111110001011001000010011111100001001100011",
"output": "1100100001110010010011110001011011111110111110011011110000000000011101100001100101110"
},
{
"input": "10100000101101110001100010010010100101100011010010101000110011100000101010110010000000\n10001110011011010010111011011101101111000111110000111000011010010101001100000001010011",
"output": "00101110110110100011011001001111001010100100100010010000101001110101100110110011010011"
},
{
"input": "001110000011111101101010011111000101010111010100001001100001001100101000000111000000000\n111010000000000000101001110011001000111011001100101010011001000011101001001011110000011",
"output": "110100000011111101000011101100001101101100011000100011111000001111000001001100110000011"
},
{
"input": "1110111100111011010101011011001110001010010010110011110010011111000010011111010101100001\n1001010101011001001010100010101100000110111101011000100010101111111010111100001110010010",
"output": "0111101001100010011111111001100010001100101111101011010000110000111000100011011011110011"
},
{
"input": "11100010001100010011001100001100010011010001101110011110100101110010101101011101000111111\n01110000000110111010110100001010000101011110100101010011000110101110101101110111011110001",
"output": "10010010001010101001111000000110010110001111001011001101100011011100000000101010011001110"
},
{
"input": "001101011001100101101100110000111000101011001001100100000100101000100000110100010111111101\n101001111110000010111101111110001001111001111101111010000110111000100100110010010001011111",
"output": "100100100111100111010001001110110001010010110100011110000010010000000100000110000110100010"
},
{
"input": "1010110110010101000110010010110101011101010100011001101011000110000000100011100100011000000\n0011011111100010001111101101000111001011101110100000110111100100101111010110101111011100011",
"output": "1001101001110111001001111111110010010110111010111001011100100010101111110101001011000100011"
},
{
"input": "10010010000111010111011111110010100101100000001100011100111011100010000010010001011100001100\n00111010100010110010000100010111010001111110100100100011101000101111111111001101101100100100",
"output": "10101000100101100101011011100101110100011110101000111111010011001101111101011100110000101000"
},
{
"input": "010101110001010101100000010111010000000111110011001101100011001000000011001111110000000010100\n010010111011100101010101111110110000000111000100001101101001001000001100101110001010000100001",
"output": "000111001010110000110101101001100000000000110111000000001010000000001111100001111010000110101"
},
{
"input": "1100111110011001000111101001001011000110011010111111100010111111001100111111011101100111101011\n1100000011001000110100110111000001011001010111101000010010100011000001100100111101101000010110",
"output": "0000111101010001110011011110001010011111001101010111110000011100001101011011100000001111111101"
},
{
"input": "00011000100100110111100101100100000000010011110111110010101110110011100001010111010011110100101\n00011011111011111011100101100111100101001110010111000010000111000100100100000001110101111011011",
"output": "00000011011111001100000000000011100101011101100000110000101001110111000101010110100110001111110"
},
{
"input": "000101011001001100000111100010110101111011110101111101000110001101011010111110110011100100000001\n011000101010011111011000111000100000000011011000000001111110001000001111101010110000011100001111",
"output": "011101110011010011011111011010010101111000101101111100111000000101010101010100000011111000001110"
},
{
"input": "1000101001011010000100100100010010011101011001110101111011101111111110010101001101010001010101001\n0110110010011100011111011111110111000000010001110100001010111110101011010011111011111110000110000",
"output": "1110011011000110011011111011100101011101001000000001110001010001010101000110110110101111010011001"
},
{
"input": "01111010010101100111110111111011011010100001011101010000111100101101101110111011001100101011100111\n00001100110110100001111011000010001001001100000010111101000001111011100000010111010010000011000010",
"output": "01110110100011000110001100111001010011101101011111101101111101010110001110101100011110101000100101"
},
{
"input": "111101011101111000001011001101111010110111001101110100100011111011011101001101010101011010111000110\n101111100101101101001100110011000001111010011101110111110110101110011011110011111100001001110101101",
"output": "010010111000010101000111111110111011001101010000000011010101010101000110111110101001010011001101011"
},
{
"input": "1010000011010110011101001101110001110010000111011101110010110110111111001001110100101100010101010001\n0111101000111100101100000101111010100100001000011101010100110011100011010011010101000100101011100011",
"output": "1101101011101010110001001000001011010110001111000000100110000101011100011010100001101000111110110010"
},
{
"input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001\n1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111010",
"output": "1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111011"
},
{
"input": "0\n0",
"output": "0"
},
{
"input": "0\n1",
"output": "1"
}
] | 1,644,387,827 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | a = int(input(), 2)
b= int(input(), 2)
print(bin(a|b)[2:]) | Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part.
In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0.
Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length.
Now you are going to take part in Shapur's contest. See if you are faster and more accurate.
Input Specification:
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
Output Specification:
Write one line — the corresponding answer. Do not omit the leading 0s.
Demo Input:
['1010100\n0100101\n', '000\n111\n', '1110\n1010\n', '01110\n01100\n']
Demo Output:
['1110001\n', '111\n', '0100\n', '00010\n']
Note:
none | ```python
a = int(input(), 2)
b= int(input(), 2)
print(bin(a|b)[2:])
``` | 0 |
858 | C | Did you mean... | PROGRAMMING | 1,500 | [
"dp",
"greedy",
"implementation"
] | null | null | Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them.
Beroffice works only with small English letters (i.e. with 26 letters from a to z). Beroffice thinks that a word is typed with a typo if there are three or more consonants in a row in the word. The only exception is that if the block of consonants has all letters the same, then this block (even if its length is greater than three) is not considered a typo. Formally, a word is typed with a typo if there is a block of not less that three consonants in a row, and there are at least two different letters in this block.
For example:
- the following words have typos: "hellno", "hackcerrs" and "backtothefutttture"; - the following words don't have typos: "helllllooooo", "tobeornottobe" and "oooooo".
When Beroffice editor finds a word with a typo, it inserts as little as possible number of spaces in this word (dividing it into several words) in such a way that each of the resulting words is typed without any typos.
Implement this feature of Beroffice editor. Consider the following letters as the only vowels: 'a', 'e', 'i', 'o' and 'u'. All the other letters are consonants in this problem. | The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters. | Print the given word without any changes if there are no typos.
If there is at least one typo in the word, insert the minimum number of spaces into the word so that each of the resulting words doesn't have any typos. If there are multiple solutions, print any of them. | [
"hellno\n",
"abacaba\n",
"asdfasdf\n"
] | [
"hell no \n",
"abacaba \n",
"asd fasd f \n"
] | none | 1,500 | [
{
"input": "hellno",
"output": "hell no "
},
{
"input": "abacaba",
"output": "abacaba "
},
{
"input": "asdfasdf",
"output": "asd fasd f "
},
{
"input": "ooo",
"output": "ooo "
},
{
"input": "moyaoborona",
"output": "moyaoborona "
},
{
"input": "jxegxxx",
"output": "jxegx xx "
},
{
"input": "orfyaenanabckumulsboloyhljhacdgcmnooxvxrtuhcslxgslfpnfnyejbxqisxjyoyvcvuddboxkqgbogkfz",
"output": "orf yaenanabc kumuls boloyh lj hacd gc mnooxv xr tuhc sl xg sl fp nf nyejb xqisx jyoyv cvudd boxk qg bogk fz "
},
{
"input": "zxdgmhsjotvajkwshjpvzcuwehpeyfhakhtlvuoftkgdmvpafmxcliqvrztloocziqdkexhzcbdgxaoyvte",
"output": "zx dg mh sjotvajk ws hj pv zcuwehpeyf hakh tl vuoft kg dm vpafm xc liqv rz tloocziqd kexh zc bd gxaoyv te "
},
{
"input": "niblehmwtycadhbfuginpyafszjbucaszihijndzjtuyuaxkrovotshtsajmdcflnfdmahzbvpymiczqqleedpofcnvhieknlz",
"output": "niblehm wt ycadh bfuginp yafs zj bucaszihijn dz jtuyuaxk rovots ht sajm dc fl nf dmahz bv py micz qq leedpofc nv hiekn lz "
},
{
"input": "pqvtgtctpkgjgxnposjqedofficoyznxlerxyqypyzpoehejtjvyafjxjppywwgeakf",
"output": "pq vt gt ct pk gj gx nposj qedofficoyz nx lerx yq yp yz poehejt jv yafj xj pp yw wgeakf "
},
{
"input": "mvjajoyeg",
"output": "mv jajoyeg "
},
{
"input": "dipxocwjosvdaillxolmthjhzhsxskzqslebpixpuhpgeesrkedhohisdsjsrkiktbjzlhectrfcathvewzficirqbdvzq",
"output": "dipxocw josv daill xolm th jh zh sx sk zq slebpixpuhp geesr kedhohisd sj sr kikt bj zl hect rf cath vewz ficirq bd vz q "
},
{
"input": "ibbtvelwjirxqermucqrgmoauonisgmarjxxybllktccdykvef",
"output": "ibb tvelw jirx qermucq rg moauonisg marj xx yb ll kt cc dy kvef "
},
{
"input": "jxevkmrwlomaaahaubvjzqtyfqhqbhpqhomxqpiuersltohinvfyeykmlooujymldjqhgqjkvqknlyj",
"output": "jxevk mr wlomaaahaubv jz qt yf qh qb hp qhomx qpiuers ltohinv fyeyk mlooujy ml dj qh gq jk vq kn ly j "
},
{
"input": "hzxkuwqxonsulnndlhygvmallghjerwp",
"output": "hz xkuwq xonsuln nd lh yg vmall gh jerw p "
},
{
"input": "jbvcsjdyzlzmxwcvmixunfzxidzvwzaqqdhguvelwbdosbd",
"output": "jb vc sj dy zl zm xw cv mixunf zxidz vw zaqq dh guvelw bdosb d "
},
{
"input": "uyrsxaqmtibbxpfabprvnvbinjoxubupvfyjlqnfrfdeptipketwghr",
"output": "uyr sxaqm tibb xp fabp rv nv binjoxubupv fy jl qn fr fdeptipketw gh r "
},
{
"input": "xfcftysljytybkkzkpqdzralahgvbkxdtheqrhfxpecdjqofnyiahggnkiuusalu",
"output": "xf cf ty sl jy ty bk kz kp qd zralahg vb kx dt heqr hf xpecd jqofn yiahg gn kiuusalu "
},
{
"input": "a",
"output": "a "
},
{
"input": "b",
"output": "b "
},
{
"input": "aa",
"output": "aa "
},
{
"input": "ab",
"output": "ab "
},
{
"input": "ba",
"output": "ba "
},
{
"input": "bb",
"output": "bb "
},
{
"input": "aaa",
"output": "aaa "
},
{
"input": "aab",
"output": "aab "
},
{
"input": "aba",
"output": "aba "
},
{
"input": "abb",
"output": "abb "
},
{
"input": "baa",
"output": "baa "
},
{
"input": "bab",
"output": "bab "
},
{
"input": "bba",
"output": "bba "
},
{
"input": "bbb",
"output": "bbb "
},
{
"input": "bbc",
"output": "bb c "
},
{
"input": "bcb",
"output": "bc b "
},
{
"input": "cbb",
"output": "cb b "
},
{
"input": "bababcdfabbcabcdfacbbabcdfacacabcdfacbcabcdfaccbabcdfacaaabcdfabacabcdfabcbabcdfacbaabcdfabaaabcdfabbaabcdfacababcdfabbbabcdfabcaabcdfaaababcdfabccabcdfacccabcdfaacbabcdfaabaabcdfaabcabcdfaaacabcdfaccaabcdfaabbabcdfaaaaabcdfaacaabcdfaacc",
"output": "bababc dfabb cabc dfacb babc dfacacabc dfacb cabc dfacc babc dfacaaabc dfabacabc dfabc babc dfacbaabc dfabaaabc dfabbaabc dfacababc dfabbbabc dfabcaabc dfaaababc dfabc cabc dfacccabc dfaacbabc dfaabaabc dfaabcabc dfaaacabc dfaccaabc dfaabbabc dfaaaaabc dfaacaabc dfaacc "
},
{
"input": "bddabcdfaccdabcdfadddabcdfabbdabcdfacddabcdfacdbabcdfacbbabcdfacbcabcdfacbdabcdfadbbabcdfabdbabcdfabdcabcdfabbcabcdfabccabcdfabbbabcdfaddcabcdfaccbabcdfadbdabcdfacccabcdfadcdabcdfadcbabcdfabcbabcdfadbcabcdfacdcabcdfabcdabcdfadccabcdfaddb",
"output": "bd dabc dfacc dabc dfadddabc dfabb dabc dfacd dabc dfacd babc dfacb babc dfacb cabc dfacb dabc dfadb babc dfabd babc dfabd cabc dfabb cabc dfabc cabc dfabbbabc dfadd cabc dfacc babc dfadb dabc dfacccabc dfadc dabc dfadc babc dfabc babc dfadb cabc dfacd cabc dfabc dabc dfadc cabc dfadd b "
},
{
"input": "helllllooooo",
"output": "helllllooooo "
},
{
"input": "bbbzxxx",
"output": "bbb zx xx "
},
{
"input": "ffff",
"output": "ffff "
},
{
"input": "cdddddddddddddddddd",
"output": "cd ddddddddddddddddd "
},
{
"input": "bbbc",
"output": "bbb c "
},
{
"input": "lll",
"output": "lll "
},
{
"input": "bbbbb",
"output": "bbbbb "
},
{
"input": "llll",
"output": "llll "
},
{
"input": "bbbbbbccc",
"output": "bbbbbb ccc "
},
{
"input": "lllllb",
"output": "lllll b "
},
{
"input": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz",
"output": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz "
},
{
"input": "lllll",
"output": "lllll "
},
{
"input": "bbbbbbbbbc",
"output": "bbbbbbbbb c "
},
{
"input": "helllllno",
"output": "helllll no "
},
{
"input": "nnnnnnnnnnnn",
"output": "nnnnnnnnnnnn "
},
{
"input": "bbbbbccc",
"output": "bbbbb ccc "
},
{
"input": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzz",
"output": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzz "
},
{
"input": "nnnnnnnnnnnnnnnnnn",
"output": "nnnnnnnnnnnnnnnnnn "
},
{
"input": "zzzzzzzzzzzzzzzzzzzzzzz",
"output": "zzzzzzzzzzzzzzzzzzzzzzz "
},
{
"input": "hhhh",
"output": "hhhh "
},
{
"input": "nnnnnnnnnnnnnnnnnnnnnnnnn",
"output": "nnnnnnnnnnnnnnnnnnnnnnnnn "
},
{
"input": "zzzzzzzzzz",
"output": "zzzzzzzzzz "
},
{
"input": "dddd",
"output": "dddd "
},
{
"input": "heffffffgggggghhhhhh",
"output": "heffffff gggggg hhhhhh "
},
{
"input": "bcddd",
"output": "bc ddd "
},
{
"input": "x",
"output": "x "
},
{
"input": "nnn",
"output": "nnn "
},
{
"input": "xxxxxxxx",
"output": "xxxxxxxx "
},
{
"input": "cclcc",
"output": "cc lc c "
},
{
"input": "tttttttttttttt",
"output": "tttttttttttttt "
},
{
"input": "xxxxxxx",
"output": "xxxxxxx "
},
{
"input": "ccccb",
"output": "cccc b "
},
{
"input": "bcecccc",
"output": "bcecccc "
},
{
"input": "jjja",
"output": "jjja "
},
{
"input": "zzz",
"output": "zzz "
},
{
"input": "xxxxxxxxxzzzzzzzzzzzz",
"output": "xxxxxxxxx zzzzzzzzzzzz "
},
{
"input": "alllewww",
"output": "alllewww "
},
{
"input": "bbbbbbbbb",
"output": "bbbbbbbbb "
},
{
"input": "jjj",
"output": "jjj "
},
{
"input": "bbbbbbbbbbbbbbbbbbbbbbbbb",
"output": "bbbbbbbbbbbbbbbbbbbbbbbbb "
},
{
"input": "kkkkkkkkkklllllllllllllll",
"output": "kkkkkkkkkk lllllllllllllll "
},
{
"input": "helllllllllllo",
"output": "helllllllllllo "
},
{
"input": "ttttsttttt",
"output": "tttt st tttt "
},
{
"input": "tttttttsssssss",
"output": "ttttttt sssssss "
},
{
"input": "assstttttatsfatsfdjfdhtsjdsaatttssssststsss",
"output": "asss tttttats fats fd jf dh ts jd saattt sssss ts ts ss "
},
{
"input": "xxxxx",
"output": "xxxxx "
},
{
"input": "bbbhbbb",
"output": "bbb hb bb "
},
{
"input": "bbbbbbbb",
"output": "bbbbbbbb "
}
] | 1,567,273,649 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 0 | 1,000 | 11,776,000 | s = input()
ans = s
ws = 'aeiou'
i = 0
while i < len(ans) - 2:
if (ans[i]==ans[i + 1] and ans[i]==ans[i + 2]):
i += 1
continue
if(ans[i] not in ws and ans[i + 1] not in ws and ans[i + 2] not in ws):
ans=ans[:i + 2] + ' ' + ans[i + 2:]
i += 1
print(ans) | Title: Did you mean...
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them.
Beroffice works only with small English letters (i.e. with 26 letters from a to z). Beroffice thinks that a word is typed with a typo if there are three or more consonants in a row in the word. The only exception is that if the block of consonants has all letters the same, then this block (even if its length is greater than three) is not considered a typo. Formally, a word is typed with a typo if there is a block of not less that three consonants in a row, and there are at least two different letters in this block.
For example:
- the following words have typos: "hellno", "hackcerrs" and "backtothefutttture"; - the following words don't have typos: "helllllooooo", "tobeornottobe" and "oooooo".
When Beroffice editor finds a word with a typo, it inserts as little as possible number of spaces in this word (dividing it into several words) in such a way that each of the resulting words is typed without any typos.
Implement this feature of Beroffice editor. Consider the following letters as the only vowels: 'a', 'e', 'i', 'o' and 'u'. All the other letters are consonants in this problem.
Input Specification:
The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters.
Output Specification:
Print the given word without any changes if there are no typos.
If there is at least one typo in the word, insert the minimum number of spaces into the word so that each of the resulting words doesn't have any typos. If there are multiple solutions, print any of them.
Demo Input:
['hellno\n', 'abacaba\n', 'asdfasdf\n']
Demo Output:
['hell no \n', 'abacaba \n', 'asd fasd f \n']
Note:
none | ```python
s = input()
ans = s
ws = 'aeiou'
i = 0
while i < len(ans) - 2:
if (ans[i]==ans[i + 1] and ans[i]==ans[i + 2]):
i += 1
continue
if(ans[i] not in ws and ans[i + 1] not in ws and ans[i + 2] not in ws):
ans=ans[:i + 2] + ' ' + ans[i + 2:]
i += 1
print(ans)
``` | 0 |
|
764 | A | Taymyr is calling you | PROGRAMMING | 800 | [
"brute force",
"implementation",
"math"
] | null | null | Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist.
Ilia-alpinist calls every *n* minutes, i.e. in minutes *n*, 2*n*, 3*n* and so on. Artists come to the comrade every *m* minutes, i.e. in minutes *m*, 2*m*, 3*m* and so on. The day is *z* minutes long, i.e. the day consists of minutes 1,<=2,<=...,<=*z*. How many artists should be killed so that there are no artists in the room when Ilia calls? Consider that a call and a talk with an artist take exactly one minute. | The only string contains three integers — *n*, *m* and *z* (1<=≤<=*n*,<=*m*,<=*z*<=≤<=104). | Print single integer — the minimum number of artists that should be killed so that there are no artists in the room when Ilia calls. | [
"1 1 10\n",
"1 2 5\n",
"2 3 9\n"
] | [
"10\n",
"2\n",
"1\n"
] | Taymyr is a place in the north of Russia.
In the first test the artists come each minute, as well as the calls, so we need to kill all of them.
In the second test we need to kill artists which come on the second and the fourth minutes.
In the third test — only the artist which comes on the sixth minute. | 500 | [
{
"input": "1 1 10",
"output": "10"
},
{
"input": "1 2 5",
"output": "2"
},
{
"input": "2 3 9",
"output": "1"
},
{
"input": "4 8 9",
"output": "1"
},
{
"input": "7 9 2",
"output": "0"
},
{
"input": "10000 10000 10000",
"output": "1"
},
{
"input": "24 22 9235",
"output": "34"
},
{
"input": "74 8 417",
"output": "1"
},
{
"input": "972 1 203",
"output": "0"
},
{
"input": "550 1 754",
"output": "1"
},
{
"input": "860 1 884",
"output": "1"
},
{
"input": "358 2 809",
"output": "2"
},
{
"input": "33 27 216",
"output": "0"
},
{
"input": "2940 1 9311",
"output": "3"
},
{
"input": "4624 1 1953",
"output": "0"
},
{
"input": "2696 2 7345",
"output": "2"
},
{
"input": "3443 2 6701",
"output": "0"
},
{
"input": "3 613 2275",
"output": "1"
},
{
"input": "1 10000 10000",
"output": "1"
},
{
"input": "10000 1 10000",
"output": "1"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "1 1 10000",
"output": "10000"
},
{
"input": "34 27 10000",
"output": "10"
},
{
"input": "2 2 9999",
"output": "4999"
},
{
"input": "2 2 1",
"output": "0"
},
{
"input": "6 4 36",
"output": "3"
},
{
"input": "33 6 3005",
"output": "45"
},
{
"input": "5 1 20",
"output": "4"
},
{
"input": "1 2 10",
"output": "5"
},
{
"input": "2 1 100",
"output": "50"
},
{
"input": "10 20 10000",
"output": "500"
},
{
"input": "8 12 12",
"output": "0"
}
] | 1,486,204,814 | 1,214 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 78 | 23,142,400 | #
n,m,z = int(input()).split()
def gcd(a,b):
while b > 0:
a, b = b, a % b
return a
def lcm(a, b):
return a * b / gcd(a, b)
t=z//lcm(n,m)
print(t) | Title: Taymyr is calling you
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist.
Ilia-alpinist calls every *n* minutes, i.e. in minutes *n*, 2*n*, 3*n* and so on. Artists come to the comrade every *m* minutes, i.e. in minutes *m*, 2*m*, 3*m* and so on. The day is *z* minutes long, i.e. the day consists of minutes 1,<=2,<=...,<=*z*. How many artists should be killed so that there are no artists in the room when Ilia calls? Consider that a call and a talk with an artist take exactly one minute.
Input Specification:
The only string contains three integers — *n*, *m* and *z* (1<=≤<=*n*,<=*m*,<=*z*<=≤<=104).
Output Specification:
Print single integer — the minimum number of artists that should be killed so that there are no artists in the room when Ilia calls.
Demo Input:
['1 1 10\n', '1 2 5\n', '2 3 9\n']
Demo Output:
['10\n', '2\n', '1\n']
Note:
Taymyr is a place in the north of Russia.
In the first test the artists come each minute, as well as the calls, so we need to kill all of them.
In the second test we need to kill artists which come on the second and the fourth minutes.
In the third test — only the artist which comes on the sixth minute. | ```python
#
n,m,z = int(input()).split()
def gcd(a,b):
while b > 0:
a, b = b, a % b
return a
def lcm(a, b):
return a * b / gcd(a, b)
t=z//lcm(n,m)
print(t)
``` | -1 |
|
638 | B | Making Genome in Berland | PROGRAMMING | 1,500 | [
"*special",
"dfs and similar",
"strings"
] | null | null | Berland scientists face a very important task - given the parts of short DNA fragments, restore the dinosaur DNA! The genome of a berland dinosaur has noting in common with the genome that we've used to: it can have 26 distinct nucleotide types, a nucleotide of each type can occur at most once. If we assign distinct English letters to all nucleotides, then the genome of a Berland dinosaur will represent a non-empty string consisting of small English letters, such that each letter occurs in it at most once.
Scientists have *n* genome fragments that are represented as substrings (non-empty sequences of consecutive nucleotides) of the sought genome.
You face the following problem: help scientists restore the dinosaur genome. It is guaranteed that the input is not contradictory and at least one suitable line always exists. When the scientists found out that you are a strong programmer, they asked you in addition to choose the one with the minimum length. If there are multiple such strings, choose any string. | The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of genome fragments.
Each of the next lines contains one descriptions of a fragment. Each fragment is a non-empty string consisting of distinct small letters of the English alphabet. It is not guaranteed that the given fragments are distinct. Fragments could arbitrarily overlap and one fragment could be a substring of another one.
It is guaranteed that there is such string of distinct letters that contains all the given fragments as substrings. | In the single line of the output print the genome of the minimum length that contains all the given parts. All the nucleotides in the genome must be distinct. If there are multiple suitable strings, print the string of the minimum length. If there also are multiple suitable strings, you can print any of them. | [
"3\nbcd\nab\ncdef\n",
"4\nx\ny\nz\nw\n"
] | [
"abcdef\n",
"xyzw\n"
] | none | 1,000 | [
{
"input": "3\nbcd\nab\ncdef",
"output": "abcdef"
},
{
"input": "4\nx\ny\nz\nw",
"output": "xyzw"
},
{
"input": "25\nef\nfg\ngh\nhi\nij\njk\nkl\nlm\nmn\nno\nab\nbc\ncd\nde\nop\npq\nqr\nrs\nst\ntu\nuv\nvw\nwx\nxy\nyz",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "1\nf",
"output": "f"
},
{
"input": "1\nqwertyuiopzxcvbnmasdfghjkl",
"output": "qwertyuiopzxcvbnmasdfghjkl"
},
{
"input": "3\ndfghj\nghjkl\nasdfg",
"output": "asdfghjkl"
},
{
"input": "4\nab\nab\nab\nabc",
"output": "abc"
},
{
"input": "3\nf\nn\nux",
"output": "uxfn"
},
{
"input": "2\nfgs\nfgs",
"output": "fgs"
},
{
"input": "96\nc\ndhf\no\nq\nry\nh\nr\nf\nji\nek\ndhf\np\nk\no\nf\nw\nc\nc\nfgw\nbps\nhfg\np\ni\nji\nto\nc\nou\ny\nfg\na\ne\nu\nc\ny\nhf\nqn\nu\nj\np\ns\no\nmr\na\nqn\nb\nlb\nn\nji\nji\na\no\nat\ns\nf\nb\ndh\nk\nl\nl\nvq\nt\nb\nc\nv\nc\nh\nh\ny\nh\nq\ne\nx\nd\no\nq\nm\num\nmr\nfg\ni\nl\na\nh\nt\num\nr\no\nn\nk\ne\nji\na\nc\nh\ne\nm",
"output": "atoumrydhfgwekjilbpsvqncx"
},
{
"input": "3\npbi\nopbi\ngh",
"output": "ghopbi"
},
{
"input": "4\ng\np\no\nop",
"output": "opg"
},
{
"input": "5\np\nf\nu\nf\np",
"output": "pfu"
},
{
"input": "4\nr\nko\nuz\nko",
"output": "kouzr"
},
{
"input": "5\nzt\nted\nlzt\nted\ndyv",
"output": "lztedyv"
},
{
"input": "6\ngul\ng\njrb\nul\nd\njr",
"output": "guljrbd"
},
{
"input": "5\nlkyh\naim\nkyh\nm\nkyhai",
"output": "lkyhaim"
},
{
"input": "4\nzrncsywd\nsywdx\ngqzrn\nqzrncsy",
"output": "gqzrncsywdx"
},
{
"input": "5\ntbxzc\njrdtb\njrdtb\nflnj\nrdtbx",
"output": "flnjrdtbxzc"
},
{
"input": "10\ng\nkagijn\nzxt\nhmkag\nhm\njnc\nxtqupw\npwhmk\ng\nagi",
"output": "zxtqupwhmkagijnc"
},
{
"input": "20\nf\nf\nv\nbn\ne\nmr\ne\ne\nn\nj\nqfv\ne\ndpb\nj\nlc\nr\ndp\nf\na\nrt",
"output": "dpbnlcmrtqfveja"
},
{
"input": "30\nxlo\nwx\ne\nf\nyt\nw\ne\nl\nxl\nojg\njg\niy\ngkz\ne\nw\nloj\ng\nfw\nl\nlo\nbe\ne\ngk\niyt\no\nb\nqv\nz\nb\nzq",
"output": "befwxlojgkzqviyt"
},
{
"input": "50\nmd\nei\nhy\naz\nzr\nmd\nv\nz\nke\ny\nuk\nf\nhy\njm\nke\njm\ncn\nwf\nzr\nqj\ng\nzr\ndv\ni\ndv\nuk\nj\nwf\njm\nn\na\nqj\nei\nf\nzr\naz\naz\nke\na\nr\ndv\nei\nzr\ndv\nq\ncn\nyg\nqj\nnh\nhy",
"output": "azrcnhygqjmdvukeiwf"
},
{
"input": "80\ni\nioh\nquc\nexioh\niohb\nex\nrwky\nz\nquc\nrw\nplnt\nq\nhbrwk\nexioh\ntv\nxioh\nlnt\nxi\nn\npln\niohbr\nwky\nhbr\nw\nyq\nrwky\nbrw\nplnt\nv\nkyq\nrwkyq\nt\nhb\ngplnt\np\nkyqu\nhbr\nrwkyq\nhbr\nve\nhbrwk\nkyq\nkyquc\ngpln\ni\nbr\ntvex\nwkyqu\nz\nlnt\ngp\nky\ngplnt\ne\nhbrwk\nbrw\nve\no\nplnt\nn\nntve\ny\nln\npln\ntvexi\nr\nzgp\nxiohb\nl\nn\nt\nplnt\nlntv\nexi\nexi\ngpl\nioh\nk\nwk\ni",
"output": "zgplntvexiohbrwkyquc"
},
{
"input": "70\njp\nz\nz\nd\ndy\nk\nsn\nrg\nz\nsn\nh\nj\ns\nkx\npu\nkx\nm\njp\nbo\nm\ntk\ndy\no\nm\nsn\nv\nrg\nv\nn\no\ngh\np\no\nx\nq\nzv\nr\nbo\ng\noz\nu\nub\nnd\nh\ny\njp\no\nq\nbo\nhq\nhq\nkx\nx\ndy\nn\nb\nub\nsn\np\nub\ntk\nu\nnd\nvw\nt\nub\nbo\nyr\nyr\nub",
"output": "jpubozvwsndyrghqtkxm"
},
{
"input": "100\nm\nj\nj\nf\nk\nq\ni\nu\ni\nl\nt\nt\no\nv\nk\nw\nr\nj\nh\nx\nc\nv\nu\nf\nh\nj\nb\ne\ni\nr\ng\nb\nl\nb\ng\nb\nf\nq\nv\na\nu\nn\ni\nl\nk\nc\nx\nu\nr\ne\ni\na\nc\no\nc\na\nx\nd\nf\nx\no\nx\nm\nl\nr\nc\nr\nc\nv\nj\ng\nu\nn\nn\nd\nl\nl\nc\ng\nu\nr\nu\nh\nl\na\nl\nr\nt\nm\nf\nm\nc\nh\nl\nd\na\nr\nh\nn\nc",
"output": "mjfkqiultovwrhxcbegand"
},
{
"input": "99\nia\nz\nsb\ne\nnm\nd\nknm\nt\nm\np\nqvu\ne\nq\nq\ns\nmd\nz\nfh\ne\nwi\nn\nsb\nq\nw\ni\ng\nr\ndf\nwi\nl\np\nm\nb\ni\natj\nb\nwia\nx\nnm\nlk\nx\nfh\nh\np\nf\nzr\nz\nr\nsbz\nlkn\nsbz\nz\na\nwia\ntjx\nk\nj\nx\nl\nqvu\nzr\nfh\nbzrg\nz\nplk\nfhe\nn\njxqv\nrgp\ne\ndf\nz\ns\natj\ndf\nat\ngp\nw\new\nt\np\np\nfhe\nq\nxq\nt\nzr\nat\ndfh\nj\ns\nu\npl\np\nrg\nlk\nq\nwia\ng",
"output": "sbzrgplknmdfhewiatjxqvu"
},
{
"input": "95\np\nk\nd\nr\nn\nz\nn\nb\np\nw\ni\nn\ny\ni\nn\nn\ne\nr\nu\nr\nb\ni\ne\np\nk\nc\nc\nh\np\nk\nh\ns\ne\ny\nq\nq\nx\nw\nh\ng\nt\nt\na\nt\nh\ni\nb\ne\np\nr\nu\nn\nn\nr\nq\nn\nu\ng\nw\nt\np\nt\nk\nd\nz\nh\nf\nd\ni\na\na\nf\ne\na\np\ns\nk\nt\ng\nf\ni\ng\ng\nt\nn\nn\nt\nt\nr\nx\na\nz\nc\nn\nk",
"output": "pkdrnzbwiyeuchsqxgtaf"
},
{
"input": "3\nh\nx\np",
"output": "hxp"
},
{
"input": "4\nrz\nvu\nxy\npg",
"output": "pgrzvuxy"
},
{
"input": "5\ndrw\nu\nzq\npd\naip",
"output": "aipdrwzqu"
},
{
"input": "70\ne\no\ng\ns\nsz\nyl\ns\nn\no\nq\np\nl\noa\ndq\ny\np\nn\nio\ng\nb\nk\nv\ny\nje\nc\ncb\nfx\ncbv\nfxp\nkt\nhm\nz\nrcb\np\nt\nu\nzh\ne\nb\na\nyl\nd\nv\nl\nrc\nq\nt\nt\nj\nl\nr\ny\nlg\np\nt\nd\nq\nje\nqwu\ng\nz\ngi\ndqw\nz\nvyl\nk\nt\nc\nb\nrc",
"output": "dqwufxpjektrcbvylgioaszhmn"
},
{
"input": "3\ne\nw\nox",
"output": "oxew"
},
{
"input": "100\npr\nfz\nru\ntk\nld\nvq\nef\ngj\ncp\nbm\nsn\nld\nua\nzl\ndw\nef\nua\nbm\nxb\nvq\nav\ncp\nko\nwc\nru\ni\ne\nav\nbm\nav\nxb\nog\ng\nme\ntk\nog\nxb\nef\ntk\nhx\nqt\nvq\ndw\nv\nxb\ndw\nko\nd\nbm\nua\nvq\nis\nwc\ntk\ntk\ngj\ng\ngj\nef\nqt\nvq\nbm\nog\nvq\ngj\nvq\nzl\ngj\nji\nvq\nhx\ng\nbm\nji\nqt\nef\nav\ntk\nxb\nru\nko\nny\nis\ncp\nxb\nog\nru\nhx\nwc\nko\nu\nfz\ndw\nji\nzl\nvq\nqt\nko\ngj\nis",
"output": "hxbmefzldwcpruavqtkogjisny"
},
{
"input": "23\nw\nz\nk\nc\ne\np\nt\na\nx\nc\nq\nx\na\nf\np\nw\nh\nx\nf\nw\np\nw\nq",
"output": "wzkceptaxqfh"
},
{
"input": "12\nu\na\nhw\na\ngh\nog\nr\nd\nw\nk\nl\ny",
"output": "oghwuardkly"
},
{
"input": "2\ny\nd",
"output": "yd"
},
{
"input": "1\nd",
"output": "d"
},
{
"input": "100\nwm\nq\nhf\nwm\niz\ndl\nmiz\np\nzoa\nbk\nw\nxv\nfj\nd\nxvsg\nr\nx\nt\nyd\nbke\ny\neq\nx\nn\nry\nt\nc\nuh\nn\npw\nuhf\neq\nr\nw\nk\nt\nsg\njb\nd\nke\ne\nx\nh\ntuh\nan\nn\noa\nw\nq\nz\nk\noan\nbk\nj\nzoan\nyd\npwmi\nyd\nc\nry\nfj\nlx\nqr\nke\nizo\nm\nz\noan\nwmi\nl\nyd\nz\ns\nke\nw\nfjbk\nqry\nlxv\nhf\ns\nnc\nq\nlxv\nzoa\nn\nfj\np\nhf\nmiz\npwm\ntu\noan\ng\nd\nqr\na\nan\nxvs\ny\ntuhf",
"output": "pwmizoanctuhfjbkeqrydlxvsg"
},
{
"input": "94\ncw\nm\nuhbk\ntfy\nsd\nu\ntf\ntfym\nfy\nbk\nx\nx\nxl\npu\noq\nkt\ny\nb\nj\nqxl\no\noqx\nr\nr\njr\nk\ne\nw\nsd\na\nljre\nhbk\nym\nxl\np\nreg\nktf\nre\nw\nhbk\nxlj\nzn\ne\nm\nms\nsdv\nr\nr\no\naoq\nzna\nymsd\nqx\nr\no\nlj\nm\nk\nu\nkt\nms\ne\nx\nh\ni\nz\nm\nc\nb\no\nm\nvcw\ndvc\nq\na\nb\nfyms\nv\nxl\nxl\ntfym\nx\nfy\np\nyms\nms\nb\nt\nu\nn\nq\nnaoqx\no\ne",
"output": "puhbktfymsdvcwznaoqxljregi"
},
{
"input": "13\ngku\nzw\nstvqc\najy\njystvq\nfilden\nstvq\nfild\nqcporh\najys\nqcpor\nqcpor\ncporhm",
"output": "ajystvqcporhmfildengkuzw"
},
{
"input": "2\not\nqu",
"output": "otqu"
},
{
"input": "100\nv\nh\nj\nf\nr\ni\ns\nw\nv\nd\nv\np\nd\nu\ny\nd\nu\nx\nr\nu\ng\nm\ns\nf\nv\nx\na\ng\ng\ni\ny\ny\nv\nd\ni\nq\nq\nu\nx\nj\nv\nj\ne\no\nr\nh\nu\ne\nd\nv\nb\nv\nq\nk\ni\nr\ne\nm\na\nj\na\nu\nq\nx\nq\ny\ns\nw\nk\ni\ns\nr\np\ni\np\ns\nd\nj\nw\no\nm\ns\nr\nd\nf\ns\nw\nv\ne\ny\no\nx\na\np\nk\nr\ng\ng\nb\nq",
"output": "vhjfriswdpuyxgmaqeobk"
},
{
"input": "99\ntnq\nep\nuk\nk\nx\nvhy\nepj\nx\nj\nhy\nukg\nsep\nquk\nr\nw\no\nxrwm\ndl\nh\no\nad\ng\ng\nhy\nxr\nad\nhyx\nkg\nvh\nb\nlovh\nuk\nl\ntn\nkg\ny\nu\nxr\nse\nyx\nmt\nlo\nm\nu\nukg\ngse\na\nuk\nn\nr\nlov\nep\nh\nadl\nyx\nt\nukg\nz\nepj\nz\nm\nx\nov\nyx\nxr\nep\nw\ny\nmtn\nsep\nep\nmt\nrwmt\nuk\nlo\nz\nnq\nj\ntn\nj\nkgs\ny\nb\nmtn\nsep\nr\ns\no\nr\nepjb\nadl\nrwmt\nyxrw\npj\nvhy\nk\ns\nx\nt",
"output": "adlovhyxrwmtnqukgsepjbz"
},
{
"input": "95\nx\np\nk\nu\ny\nz\nt\na\ni\nj\nc\nh\nk\nn\nk\ns\nr\ny\nn\nv\nf\nb\nr\no\no\nu\nb\nj\no\nd\np\ns\nb\nt\nd\nq\nq\na\nm\ny\nq\nj\nz\nk\ne\nt\nv\nj\np\np\ns\nz\no\nk\nt\na\na\nc\np\nb\np\nx\nc\ny\nv\nj\na\np\nc\nd\nj\nt\nj\nt\nf\no\no\nn\nx\nq\nc\nk\np\nk\nq\na\ns\nl\na\nq\na\nb\ne\nj\nl",
"output": "xpkuyztaijchnsrvfbodqmel"
},
{
"input": "96\not\njo\nvpr\nwi\ngx\nay\nzqf\nzq\npr\nigx\ntsb\nv\nr\ngxc\nigx\ngx\nvpr\nxc\nylk\nigx\nlkh\nvp\nuvp\nz\nbuv\njo\nvpr\npr\nprn\nwi\nqfw\nbuv\nd\npr\ndmj\nvpr\ng\nylk\nsbu\nhz\nk\nzqf\nylk\nxc\nwi\nvpr\nbuv\nzq\nmjo\nkh\nuv\nuvp\nts\nt\nylk\nnay\nbuv\nhzq\nts\njo\nsbu\nqfw\ngxc\ntsb\np\nhzq\nbuv\nsbu\nfwi\nkh\nmjo\nwig\nhzq\ndmj\ntsb\ntsb\nts\nylk\nyl\ngxc\not\nots\nuvp\nay\nay\nuvp\not\ny\np\nm\ngx\nkhz\ngxc\nkhz\ntsb\nrn",
"output": "dmjotsbuvprnaylkhzqfwigxc"
},
{
"input": "3\nm\nu\nm",
"output": "mu"
},
{
"input": "4\np\na\nz\nq",
"output": "pazq"
},
{
"input": "5\ngtb\nnlu\nzjp\nk\nazj",
"output": "azjpgtbnluk"
},
{
"input": "70\nxv\nlu\ntb\njx\nseh\nc\nm\ntbr\ntb\ndl\ne\nd\nt\np\nn\nse\nna\neh\nw\np\nzkj\nr\nk\nrw\nqf\ndl\ndl\ns\nat\nkjx\na\nz\nmig\nu\nse\npse\nd\ng\nc\nxv\nv\ngo\nps\ncd\nyqf\nyqf\nwzk\nxv\nat\nw\no\nl\nxvm\nfpse\nz\nk\nna\nv\nseh\nk\nl\nz\nd\nz\nn\nm\np\ng\nse\nat",
"output": "cdlunatbrwzkjxvmigoyqfpseh"
},
{
"input": "3\nbmg\nwjah\nil",
"output": "bmgilwjah"
},
{
"input": "100\ne\nbr\nls\nfb\nyx\nva\njm\nwn\nak\nhv\noq\nyx\nl\nm\nak\nce\nug\nqz\nug\ndf\nty\nhv\nmo\nxp\nyx\nkt\nak\nmo\niu\nxp\nce\nnd\noq\nbr\nty\nva\nce\nwn\nx\nsj\nel\npi\noq\ndf\niu\nc\nhv\npi\nsj\nhv\nmo\nbr\nxp\nce\nfb\nwn\nnd\nfb\npi\noq\nhv\nty\ngw\noq\nel\nw\nhv\nce\noq\nsj\nsj\nl\nwn\nqz\nty\nbr\nz\nel\nug\nce\nnd\nj\ndf\npi\niu\nnd\nls\niu\nrc\nbr\nug\nrc\nnd\nak\njm\njm\no\nls\nq\nfb",
"output": "hvaktyxpiugwndfbrcelsjmoqz"
},
{
"input": "23\nq\ni\nj\nx\nz\nm\nt\ns\nu\ng\nc\nk\nh\nb\nx\nh\nt\no\ny\nh\nb\nn\na",
"output": "qijxzmtsugckhboyna"
},
{
"input": "12\nkx\ng\nfo\nnt\nmf\nzv\nir\nds\nbz\nf\nlw\nx",
"output": "bzvdsirkxlwmfontg"
},
{
"input": "2\na\nt",
"output": "at"
},
{
"input": "1\ndm",
"output": "dm"
},
{
"input": "100\nj\numj\ninc\nu\nsd\ntin\nw\nlf\nhs\nepk\nyg\nqhs\nh\nti\nf\nsd\ngepk\nu\nfw\nu\nsd\nvumj\num\ndt\nb\ng\nozl\nabvu\noz\nn\nw\nab\nge\nqh\nfwy\nsdti\ng\nyge\nepk\nabvu\nz\nlfw\nbv\nab\nyge\nqhs\nge\nhsdt\num\nl\np\na\nab\nd\nfw\ngep\nfwy\nbvu\nvumj\nzlfw\nk\nepk\ntin\npkab\nzl\nvum\nr\nf\nd\nsdt\nhs\nxoz\nlfwy\nfw\num\nep\nincx\na\nt\num\nh\nsdt\ngep\nlfw\nkab\ng\nmjr\nj\noz\ns\nwy\nnc\nlfw\nyg\nygep\nti\nyg\npk\nkab\nwyg",
"output": "qhsdtincxozlfwygepkabvumjr"
},
{
"input": "94\nkmwbq\nmw\nwbq\ns\nlx\nf\npf\nl\nkmwb\na\nfoynt\nnt\nx\npf\npf\nep\nqs\nwbqse\nrl\nfoynt\nntzjd\nlxc\npfoy\nlx\nr\nagikm\nr\ntzjd\nep\nyntz\nu\nmw\nyntz\nfoynt\ntzjd\njdrlx\nwbqse\nr\nkmw\nwbq\nlx\nfoyn\nkm\nsepfo\nikmw\nf\nrlxch\nzjdrl\nyn\nhv\nynt\nbqs\nvu\nik\nqse\nxchvu\nmwbqs\ny\nlx\nx\nntzjd\nbq\nxchv\nwbqse\nkm\nse\nmwb\nxchvu\nwbq\nc\ngikm\nbq\nwb\nmwbq\nikmw\nag\ny\nchvu\nbqsep\nbqs\nrlx\ntzjd\nmwb\na\ndrlxc\ntzjd\nt\nsepf\nwbqse\nd\nbqs\nyn\nh\nepfo",
"output": "agikmwbqsepfoyntzjdrlxchvu"
},
{
"input": "13\ndaq\nvcnexi\nlkp\nztvcne\naqozt\nztvcne\nprdaqo\ncnex\nnexijm\nztvcne\nfysh\nxijmb\naq",
"output": "fyshlkprdaqoztvcnexijmb"
},
{
"input": "2\nnxqdblgac\nzpjou",
"output": "nxqdblgaczpjou"
},
{
"input": "7\nfjr\ngk\nigkf\nret\nvx\nvxa\ncv",
"output": "cvxaigkfjret"
},
{
"input": "7\nwer\nqwe\nw\nq\nert\ntyu\nrty",
"output": "qwertyu"
},
{
"input": "4\na\nb\nab\nabc",
"output": "abc"
},
{
"input": "4\nt\nwef\nqwe\nh",
"output": "qwefth"
},
{
"input": "5\nabcd\nbc\ndef\nde\ncd",
"output": "abcdef"
}
] | 1,458,501,558 | 26,358 | Python 3 | OK | TESTS | 67 | 62 | 5,120,000 | n = int(input())
a = [[-1 for x in range(3)] for x in range(26)]
for i in range(n):
s = input()
for j in range(len(s)):
c = ord(s[j]) - 97
a[c][0] = 1
if j != 0:
a[c][1] = ord(s[j - 1]) - 97
if j != len(s) - 1:
a[c][2] = ord(s[j + 1]) - 97
def out(ind):
if ind == -1:
return
if a[ind][0] != -1:
print(chr(97 + ind), end="")
a[ind][0] = -1
out(a[ind][2])
for i in range(26):
if a[i][1] == -1:
out(i)
| Title: Making Genome in Berland
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Berland scientists face a very important task - given the parts of short DNA fragments, restore the dinosaur DNA! The genome of a berland dinosaur has noting in common with the genome that we've used to: it can have 26 distinct nucleotide types, a nucleotide of each type can occur at most once. If we assign distinct English letters to all nucleotides, then the genome of a Berland dinosaur will represent a non-empty string consisting of small English letters, such that each letter occurs in it at most once.
Scientists have *n* genome fragments that are represented as substrings (non-empty sequences of consecutive nucleotides) of the sought genome.
You face the following problem: help scientists restore the dinosaur genome. It is guaranteed that the input is not contradictory and at least one suitable line always exists. When the scientists found out that you are a strong programmer, they asked you in addition to choose the one with the minimum length. If there are multiple such strings, choose any string.
Input Specification:
The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of genome fragments.
Each of the next lines contains one descriptions of a fragment. Each fragment is a non-empty string consisting of distinct small letters of the English alphabet. It is not guaranteed that the given fragments are distinct. Fragments could arbitrarily overlap and one fragment could be a substring of another one.
It is guaranteed that there is such string of distinct letters that contains all the given fragments as substrings.
Output Specification:
In the single line of the output print the genome of the minimum length that contains all the given parts. All the nucleotides in the genome must be distinct. If there are multiple suitable strings, print the string of the minimum length. If there also are multiple suitable strings, you can print any of them.
Demo Input:
['3\nbcd\nab\ncdef\n', '4\nx\ny\nz\nw\n']
Demo Output:
['abcdef\n', 'xyzw\n']
Note:
none | ```python
n = int(input())
a = [[-1 for x in range(3)] for x in range(26)]
for i in range(n):
s = input()
for j in range(len(s)):
c = ord(s[j]) - 97
a[c][0] = 1
if j != 0:
a[c][1] = ord(s[j - 1]) - 97
if j != len(s) - 1:
a[c][2] = ord(s[j + 1]) - 97
def out(ind):
if ind == -1:
return
if a[ind][0] != -1:
print(chr(97 + ind), end="")
a[ind][0] = -1
out(a[ind][2])
for i in range(26):
if a[i][1] == -1:
out(i)
``` | 3 |
|
149 | B | Martian Clock | PROGRAMMING | 1,600 | [
"implementation"
] | null | null | Having stayed home alone, Petya decided to watch forbidden films on the Net in secret. "What ungentlemanly behavior!" — you can say that, of course, but don't be too harsh on the kid. In his country films about the Martians and other extraterrestrial civilizations are forbidden. It was very unfair to Petya as he adored adventure stories that featured lasers and robots.
Today Petya is watching a shocking blockbuster about the Martians called "R2:D2". What can "R2:D2" possibly mean? It might be the Martian time represented in the Martian numeral system. Petya knows that time on Mars is counted just like on the Earth (that is, there are 24 hours and each hour has 60 minutes). The time is written as "*a*:*b*", where the string *a* stands for the number of hours (from 0 to 23 inclusive), and string *b* stands for the number of minutes (from 0 to 59 inclusive). The only thing Petya doesn't know is in what numeral system the Martian time is written.
Your task is to print the radixes of all numeral system which can contain the time "*a*:*b*". | The first line contains a single string as "*a*:*b*" (without the quotes). There *a* is a non-empty string, consisting of numbers and uppercase Latin letters. String *a* shows the number of hours. String *b* is a non-empty string that consists of numbers and uppercase Latin letters. String *b* shows the number of minutes. The lengths of strings *a* and *b* are from 1 to 5 characters, inclusive. Please note that strings *a* and *b* can have leading zeroes that do not influence the result in any way (for example, string "008:1" in decimal notation denotes correctly written time).
We consider characters 0, 1, ..., 9 as denoting the corresponding digits of the number's representation in some numeral system, and characters A, B, ..., Z correspond to numbers 10, 11, ..., 35. | Print the radixes of the numeral systems that can represent the time "*a*:*b*" in the increasing order. Separate the numbers with spaces or line breaks. If there is no numeral system that can represent time "*a*:*b*", print the single integer 0. If there are infinitely many numeral systems that can represent the time "*a*:*b*", print the single integer -1.
Note that on Mars any positional numeral systems with positive radix strictly larger than one are possible. | [
"11:20\n",
"2A:13\n",
"000B:00001\n"
] | [
"3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22",
"0\n",
"-1\n"
] | Let's consider the first sample. String "11:20" can be perceived, for example, as time 4:6, represented in the ternary numeral system or as time 17:32 in hexadecimal system.
Let's consider the second sample test. String "2A:13" can't be perceived as correct time in any notation. For example, let's take the base-11 numeral notation. There the given string represents time 32:14 that isn't a correct time.
Let's consider the third sample. String "000B:00001" can be perceived as a correct time in the infinite number of numeral systems. If you need an example, you can take any numeral system with radix no less than 12. | 1,000 | [
{
"input": "11:20",
"output": "3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22"
},
{
"input": "2A:13",
"output": "0"
},
{
"input": "000B:00001",
"output": "-1"
},
{
"input": "00000:00000",
"output": "-1"
},
{
"input": "70:00",
"output": "0"
},
{
"input": "00:21",
"output": "3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29"
},
{
"input": "02:130",
"output": "4 5 6"
},
{
"input": "123:A",
"output": "0"
},
{
"input": "N8HYJ:042JW",
"output": "0"
},
{
"input": "N:7",
"output": "-1"
},
{
"input": "00000:00021",
"output": "3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29"
},
{
"input": "00002:00130",
"output": "4 5 6"
},
{
"input": "00394:00321",
"output": "0"
},
{
"input": "0000P:0000E",
"output": "0"
},
{
"input": "0000F:0002G",
"output": "17 18 19 20 21"
},
{
"input": "0000N:00007",
"output": "-1"
},
{
"input": "000G6:000GD",
"output": "0"
},
{
"input": "000B3:00098",
"output": "0"
},
{
"input": "100:0101",
"output": "2 3 4"
},
{
"input": "00101:0101",
"output": "2 3 4"
},
{
"input": "00001:00001",
"output": "-1"
},
{
"input": "00A:00A",
"output": "-1"
},
{
"input": "10101:000",
"output": "2"
},
{
"input": "0010:00000",
"output": "2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23"
},
{
"input": "0033:00202",
"output": "4 5"
},
{
"input": "0011:124",
"output": "5 6"
},
{
"input": "00B:0023",
"output": "12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28"
},
{
"input": "003:25",
"output": "6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27"
},
{
"input": "0021:00054",
"output": "6 7 8 9 10 11"
},
{
"input": "01B:4A",
"output": "12"
},
{
"input": "27:0070",
"output": "8"
},
{
"input": "43:210",
"output": "5"
},
{
"input": "0:10",
"output": "2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59"
},
{
"input": "Z:0",
"output": "0"
},
{
"input": "0:Z",
"output": "-1"
},
{
"input": "Z:Z",
"output": "0"
},
{
"input": "ZZZZZ:ZZZZZ",
"output": "0"
},
{
"input": "0:1Z",
"output": "0"
},
{
"input": "0:0Z",
"output": "-1"
},
{
"input": "0:00000",
"output": "-1"
},
{
"input": "0:0",
"output": "-1"
},
{
"input": "0:10000",
"output": "2"
},
{
"input": "01:010",
"output": "2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59"
},
{
"input": "1:11",
"output": "2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58"
},
{
"input": "00Z:01",
"output": "0"
},
{
"input": "1:10",
"output": "2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59"
},
{
"input": "A:10",
"output": "11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59"
},
{
"input": "00:10",
"output": "2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59"
},
{
"input": "00:010",
"output": "2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59"
},
{
"input": "0Z:00",
"output": "0"
},
{
"input": "00:1A",
"output": "11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49"
},
{
"input": "00Z:03",
"output": "0"
},
{
"input": "000Z:000Z",
"output": "0"
},
{
"input": "000Z:00A",
"output": "0"
},
{
"input": "001:010",
"output": "2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59"
},
{
"input": "00:1Z",
"output": "0"
},
{
"input": "00:20",
"output": "3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29"
},
{
"input": "10:05",
"output": "6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23"
},
{
"input": "00Z:001",
"output": "0"
},
{
"input": "Z:2",
"output": "0"
},
{
"input": "0:1",
"output": "-1"
},
{
"input": "Z:00",
"output": "0"
},
{
"input": "0:1N",
"output": "24 25 26 27 28 29 30 31 32 33 34 35 36"
},
{
"input": "1:60",
"output": "7 8 9"
},
{
"input": "Z:01",
"output": "0"
},
{
"input": "000:010",
"output": "2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59"
},
{
"input": "000Z:00001",
"output": "0"
},
{
"input": "1:10002",
"output": "0"
},
{
"input": "Z:1",
"output": "0"
},
{
"input": "V:V",
"output": "0"
},
{
"input": "000:0010",
"output": "2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59"
},
{
"input": "0Z:01",
"output": "0"
},
{
"input": "0:1A",
"output": "11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49"
},
{
"input": "000Z:0001",
"output": "0"
},
{
"input": "24:0000",
"output": "5 6 7 8 9"
},
{
"input": "1001:1001",
"output": "2"
},
{
"input": "00:0010",
"output": "2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59"
}
] | 1,655,286,893 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 2,000 | 0 | h, m = input().split(':')
minr = max(h+m)
for i in range(len(h)):
if h[i]=='0':
continue
else:
h = h[i:]
break
for i in range(len(m)):
if m[i]=='0':
continue
else:
m = m[i:]
break
def converthh(string, base):
total = 0
for i in range(len(string)):
total = total * base + string[i]
if not (ord(minr)>=ord('0') and ord(minr)<=ord('9')):
minr = ord(minr) - ord('A') + 10
else:
minr = ord(minr) - ord('0')
minr = minr + 1
i = minr
flag = True
found = False
if ord(max(h))-ord('A')>=14:
print(0)
exit()
if len(h)==1 and len(m)==1:
print("-1")
exit()
def val(c):
if ord(c)>=ord('0') and ord(c)<=ord('9'):
return ord(c)-ord('0')
elif ord(c)>=ord('A') and ord(c)<=ord('Z'):
return ord(c)-ord('A')+10
else:
return 0
while flag:
total = 0
for j in range(len(h)):
total = total * i + val(h[j])
if total>=24:
flag = False
break
if flag:
total = 0
for k in range(len(m)):
total = total * i + val(m[k])
if total>=60:
flag = False
break
if flag:
print(i, end=" ")
found = True
i = i + 1
if not found:
print("0") | Title: Martian Clock
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Having stayed home alone, Petya decided to watch forbidden films on the Net in secret. "What ungentlemanly behavior!" — you can say that, of course, but don't be too harsh on the kid. In his country films about the Martians and other extraterrestrial civilizations are forbidden. It was very unfair to Petya as he adored adventure stories that featured lasers and robots.
Today Petya is watching a shocking blockbuster about the Martians called "R2:D2". What can "R2:D2" possibly mean? It might be the Martian time represented in the Martian numeral system. Petya knows that time on Mars is counted just like on the Earth (that is, there are 24 hours and each hour has 60 minutes). The time is written as "*a*:*b*", where the string *a* stands for the number of hours (from 0 to 23 inclusive), and string *b* stands for the number of minutes (from 0 to 59 inclusive). The only thing Petya doesn't know is in what numeral system the Martian time is written.
Your task is to print the radixes of all numeral system which can contain the time "*a*:*b*".
Input Specification:
The first line contains a single string as "*a*:*b*" (without the quotes). There *a* is a non-empty string, consisting of numbers and uppercase Latin letters. String *a* shows the number of hours. String *b* is a non-empty string that consists of numbers and uppercase Latin letters. String *b* shows the number of minutes. The lengths of strings *a* and *b* are from 1 to 5 characters, inclusive. Please note that strings *a* and *b* can have leading zeroes that do not influence the result in any way (for example, string "008:1" in decimal notation denotes correctly written time).
We consider characters 0, 1, ..., 9 as denoting the corresponding digits of the number's representation in some numeral system, and characters A, B, ..., Z correspond to numbers 10, 11, ..., 35.
Output Specification:
Print the radixes of the numeral systems that can represent the time "*a*:*b*" in the increasing order. Separate the numbers with spaces or line breaks. If there is no numeral system that can represent time "*a*:*b*", print the single integer 0. If there are infinitely many numeral systems that can represent the time "*a*:*b*", print the single integer -1.
Note that on Mars any positional numeral systems with positive radix strictly larger than one are possible.
Demo Input:
['11:20\n', '2A:13\n', '000B:00001\n']
Demo Output:
['3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22', '0\n', '-1\n']
Note:
Let's consider the first sample. String "11:20" can be perceived, for example, as time 4:6, represented in the ternary numeral system or as time 17:32 in hexadecimal system.
Let's consider the second sample test. String "2A:13" can't be perceived as correct time in any notation. For example, let's take the base-11 numeral notation. There the given string represents time 32:14 that isn't a correct time.
Let's consider the third sample. String "000B:00001" can be perceived as a correct time in the infinite number of numeral systems. If you need an example, you can take any numeral system with radix no less than 12. | ```python
h, m = input().split(':')
minr = max(h+m)
for i in range(len(h)):
if h[i]=='0':
continue
else:
h = h[i:]
break
for i in range(len(m)):
if m[i]=='0':
continue
else:
m = m[i:]
break
def converthh(string, base):
total = 0
for i in range(len(string)):
total = total * base + string[i]
if not (ord(minr)>=ord('0') and ord(minr)<=ord('9')):
minr = ord(minr) - ord('A') + 10
else:
minr = ord(minr) - ord('0')
minr = minr + 1
i = minr
flag = True
found = False
if ord(max(h))-ord('A')>=14:
print(0)
exit()
if len(h)==1 and len(m)==1:
print("-1")
exit()
def val(c):
if ord(c)>=ord('0') and ord(c)<=ord('9'):
return ord(c)-ord('0')
elif ord(c)>=ord('A') and ord(c)<=ord('Z'):
return ord(c)-ord('A')+10
else:
return 0
while flag:
total = 0
for j in range(len(h)):
total = total * i + val(h[j])
if total>=24:
flag = False
break
if flag:
total = 0
for k in range(len(m)):
total = total * i + val(m[k])
if total>=60:
flag = False
break
if flag:
print(i, end=" ")
found = True
i = i + 1
if not found:
print("0")
``` | 0 |
|
0 | none | none | none | 0 | [
"none"
] | null | null | Andryusha goes through a park each day. The squares and paths between them look boring to Andryusha, so he decided to decorate them.
The park consists of *n* squares connected with (*n*<=-<=1) bidirectional paths in such a way that any square is reachable from any other using these paths. Andryusha decided to hang a colored balloon at each of the squares. The baloons' colors are described by positive integers, starting from 1. In order to make the park varicolored, Andryusha wants to choose the colors in a special way. More precisely, he wants to use such colors that if *a*, *b* and *c* are distinct squares that *a* and *b* have a direct path between them, and *b* and *c* have a direct path between them, then balloon colors on these three squares are distinct.
Andryusha wants to use as little different colors as possible. Help him to choose the colors! | The first line contains single integer *n* (3<=≤<=*n*<=≤<=2·105) — the number of squares in the park.
Each of the next (*n*<=-<=1) lines contains two integers *x* and *y* (1<=≤<=*x*,<=*y*<=≤<=*n*) — the indices of two squares directly connected by a path.
It is guaranteed that any square is reachable from any other using the paths. | In the first line print single integer *k* — the minimum number of colors Andryusha has to use.
In the second line print *n* integers, the *i*-th of them should be equal to the balloon color on the *i*-th square. Each of these numbers should be within range from 1 to *k*. | [
"3\n2 3\n1 3\n",
"5\n2 3\n5 3\n4 3\n1 3\n",
"5\n2 1\n3 2\n4 3\n5 4\n"
] | [
"3\n1 3 2 ",
"5\n1 3 2 5 4 ",
"3\n1 2 3 1 2 "
] | In the first sample the park consists of three squares: 1 → 3 → 2. Thus, the balloon colors have to be distinct.
In the second example there are following triples of consequently connected squares:
- 1 → 3 → 2 - 1 → 3 → 4 - 1 → 3 → 5 - 2 → 3 → 4 - 2 → 3 → 5 - 4 → 3 → 5
In the third example there are following triples:
- 1 → 2 → 3 - 2 → 3 → 4 - 3 → 4 → 5 | 0 | [
{
"input": "3\n2 3\n1 3",
"output": "3\n1 3 2 "
},
{
"input": "5\n2 3\n5 3\n4 3\n1 3",
"output": "5\n1 3 2 5 4 "
},
{
"input": "5\n2 1\n3 2\n4 3\n5 4",
"output": "3\n1 2 3 1 2 "
},
{
"input": "10\n5 3\n9 2\n7 1\n3 8\n4 1\n1 9\n10 1\n8 9\n6 2",
"output": "5\n1 2 1 3 2 1 2 3 4 5 "
},
{
"input": "3\n2 1\n3 2",
"output": "3\n1 2 3 "
},
{
"input": "10\n2 7\n8 2\n9 8\n1 9\n4 1\n3 4\n6 3\n10 6\n5 10",
"output": "3\n1 1 2 3 2 1 2 3 2 3 "
},
{
"input": "5\n4 2\n3 1\n3 4\n3 5",
"output": "4\n1 1 2 3 4 "
},
{
"input": "7\n3 6\n3 1\n3 2\n3 5\n3 4\n3 7",
"output": "7\n1 4 2 6 5 3 7 "
},
{
"input": "10\n8 6\n10 5\n8 4\n2 7\n3 8\n10 3\n3 9\n2 1\n3 2",
"output": "5\n1 2 4 3 1 2 3 1 5 3 "
},
{
"input": "50\n45 2\n4 48\n16 4\n17 29\n29 33\n31 2\n47 41\n41 33\n22 6\n44 40\n32 24\n12 40\n28 16\n18 30\n20 41\n25 45\n35 29\n10 32\n1 48\n15 50\n6 9\n43 2\n33 2\n38 33\n8 2\n36 7\n26 48\n50 8\n34 31\n48 33\n13 45\n37 33\n7 6\n40 32\n3 6\n30 49\n49 33\n11 40\n19 40\n24 2\n14 50\n5 50\n42 16\n23 2\n9 45\n39 6\n46 48\n27 13\n21 2",
"output": "9\n1 4 4 3 4 2 3 6 5 2 5 4 3 3 2 1 2 2 6 2 9 1 8 7 2 4 2 2 1 1 2 1 5 1 3 1 7 6 6 3 3 4 3 2 1 6 1 2 8 1 "
},
{
"input": "50\n8 37\n40 8\n38 40\n10 38\n29 10\n33 29\n17 33\n25 17\n19 25\n3 19\n13 3\n24 13\n12 24\n5 12\n41 5\n11 41\n27 11\n45 27\n6 45\n35 6\n9 35\n50 9\n32 50\n21 32\n22 21\n1 22\n31 1\n28 31\n4 28\n30 4\n7 30\n48 7\n46 48\n16 46\n49 16\n39 49\n18 39\n14 18\n34 14\n23 34\n20 23\n15 20\n44 15\n42 44\n2 42\n36 2\n43 36\n26 43\n47 26",
"output": "3\n1 3 2 1 1 2 2 2 3 2 2 2 1 1 3 2 2 2 3 1 3 2 2 3 1 3 1 2 1 3 3 1 3 3 1 2 3 3 3 1 3 1 1 2 3 3 2 1 1 2 "
},
{
"input": "50\n7 5\n6 40\n49 43\n48 2\n44 11\n10 3\n46 49\n22 18\n17 33\n4 29\n48 4\n47 41\n24 19\n48 8\n1 21\n2 17\n17 34\n16 10\n17 20\n1 22\n44 32\n6 28\n7 1\n47 26\n28 44\n23 50\n21 15\n1 30\n7 27\n28 25\n17 23\n14 42\n6 46\n5 24\n44 9\n25 39\n46 47\n21 35\n7 16\n34 12\n45 14\n35 36\n28 13\n6 48\n46 37\n39 45\n40 7\n2 31\n30 38",
"output": "6\n1 2 2 3 2 1 4 5 5 1 1 2 5 3 3 5 1 2 3 5 2 3 6 1 4 2 3 2 1 5 3 4 3 4 4 1 5 2 1 6 1 1 1 3 2 3 4 4 2 2 "
}
] | 1,488,751,708 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 4 | 2,000 | 74,240,000 | from collections import deque
def main():
n = int(input())
color = [None] * n
neigh = [[] for _ in range(n)]
for i in range(n-1):
a, b = map(int, input().split())
neigh[a-1].append(b-1)
neigh[b-1].append(a-1)
color[0] = 1
q = deque([0])
while q:
u = q.popleft()
available = {i: True for i in range(1, n+1)}
del available[color[u]]
for v in neigh[u]:
if color[v]:
del available[color[v]]
next_color = 1
for v in neigh[u]:
if color[v] is None:
while next_color not in available:
next_color += 1
color[v] = next_color
next_color += 1
q.append(v)
print(max(color))
print(' '.join(map(str, color)))
if __name__ == '__main__':
main()
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Andryusha goes through a park each day. The squares and paths between them look boring to Andryusha, so he decided to decorate them.
The park consists of *n* squares connected with (*n*<=-<=1) bidirectional paths in such a way that any square is reachable from any other using these paths. Andryusha decided to hang a colored balloon at each of the squares. The baloons' colors are described by positive integers, starting from 1. In order to make the park varicolored, Andryusha wants to choose the colors in a special way. More precisely, he wants to use such colors that if *a*, *b* and *c* are distinct squares that *a* and *b* have a direct path between them, and *b* and *c* have a direct path between them, then balloon colors on these three squares are distinct.
Andryusha wants to use as little different colors as possible. Help him to choose the colors!
Input Specification:
The first line contains single integer *n* (3<=≤<=*n*<=≤<=2·105) — the number of squares in the park.
Each of the next (*n*<=-<=1) lines contains two integers *x* and *y* (1<=≤<=*x*,<=*y*<=≤<=*n*) — the indices of two squares directly connected by a path.
It is guaranteed that any square is reachable from any other using the paths.
Output Specification:
In the first line print single integer *k* — the minimum number of colors Andryusha has to use.
In the second line print *n* integers, the *i*-th of them should be equal to the balloon color on the *i*-th square. Each of these numbers should be within range from 1 to *k*.
Demo Input:
['3\n2 3\n1 3\n', '5\n2 3\n5 3\n4 3\n1 3\n', '5\n2 1\n3 2\n4 3\n5 4\n']
Demo Output:
['3\n1 3 2 ', '5\n1 3 2 5 4 ', '3\n1 2 3 1 2 ']
Note:
In the first sample the park consists of three squares: 1 → 3 → 2. Thus, the balloon colors have to be distinct.
In the second example there are following triples of consequently connected squares:
- 1 → 3 → 2 - 1 → 3 → 4 - 1 → 3 → 5 - 2 → 3 → 4 - 2 → 3 → 5 - 4 → 3 → 5
In the third example there are following triples:
- 1 → 2 → 3 - 2 → 3 → 4 - 3 → 4 → 5 | ```python
from collections import deque
def main():
n = int(input())
color = [None] * n
neigh = [[] for _ in range(n)]
for i in range(n-1):
a, b = map(int, input().split())
neigh[a-1].append(b-1)
neigh[b-1].append(a-1)
color[0] = 1
q = deque([0])
while q:
u = q.popleft()
available = {i: True for i in range(1, n+1)}
del available[color[u]]
for v in neigh[u]:
if color[v]:
del available[color[v]]
next_color = 1
for v in neigh[u]:
if color[v] is None:
while next_color not in available:
next_color += 1
color[v] = next_color
next_color += 1
q.append(v)
print(max(color))
print(' '.join(map(str, color)))
if __name__ == '__main__':
main()
``` | 0 |
|
318 | A | Even Odds | PROGRAMMING | 900 | [
"math"
] | null | null | Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first *n*. He writes down the following sequence of numbers: firstly all odd integers from 1 to *n* (in ascending order), then all even integers from 1 to *n* (also in ascending order). Help our hero to find out which number will stand at the position number *k*. | The only line of input contains integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=1012).
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. | Print the number that will stand at the position number *k* after Volodya's manipulations. | [
"10 3\n",
"7 7\n"
] | [
"5",
"6"
] | In the first sample Volodya's sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5. | 500 | [
{
"input": "10 3",
"output": "5"
},
{
"input": "7 7",
"output": "6"
},
{
"input": "7 1",
"output": "1"
},
{
"input": "7 2",
"output": "3"
},
{
"input": "8 5",
"output": "2"
},
{
"input": "8 3",
"output": "5"
},
{
"input": "8 4",
"output": "7"
},
{
"input": "1000000000000 500000000001",
"output": "2"
},
{
"input": "999999999997 499999999999",
"output": "999999999997"
},
{
"input": "999999999999 999999999999",
"output": "999999999998"
},
{
"input": "1000000000000 1",
"output": "1"
},
{
"input": "999999999999 1",
"output": "1"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1000000000000 1000000000000",
"output": "1000000000000"
},
{
"input": "1000000000000 500000000000",
"output": "999999999999"
},
{
"input": "1000000000000 499999999999",
"output": "999999999997"
},
{
"input": "999999999997 499999999998",
"output": "999999999995"
},
{
"input": "619234238 556154835",
"output": "493075432"
},
{
"input": "38151981 36650624",
"output": "35149266"
},
{
"input": "680402465 442571217",
"output": "204739968"
},
{
"input": "109135284 9408714",
"output": "18817427"
},
{
"input": "603701841 56038951",
"output": "112077901"
},
{
"input": "356764822 321510177",
"output": "286255532"
},
{
"input": "284911189 142190783",
"output": "284381565"
},
{
"input": "91028405 61435545",
"output": "31842684"
}
] | 1,694,280,188 | 2,147,483,647 | PyPy 3-64 | MEMORY_LIMIT_EXCEEDED | TESTS | 7 | 1,528 | 268,390,400 | finalNumberAndPosition = [int(a) for a in input().split()]
#finalNumber = finalNumberAndPosition[0]
#position = finalNumberAndPosition[1] - 1
evenNumbers = []
oddNumbers = []
i = 0
while i < finalNumberAndPosition[0]:
i += 1
if i % 2 == 0:
evenNumbers.append(i)
else:
oddNumbers.append(i)
finalSequence = oddNumbers + evenNumbers
print(finalSequence[finalNumberAndPosition[1]-1]) | Title: Even Odds
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first *n*. He writes down the following sequence of numbers: firstly all odd integers from 1 to *n* (in ascending order), then all even integers from 1 to *n* (also in ascending order). Help our hero to find out which number will stand at the position number *k*.
Input Specification:
The only line of input contains integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=1012).
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
Output Specification:
Print the number that will stand at the position number *k* after Volodya's manipulations.
Demo Input:
['10 3\n', '7 7\n']
Demo Output:
['5', '6']
Note:
In the first sample Volodya's sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5. | ```python
finalNumberAndPosition = [int(a) for a in input().split()]
#finalNumber = finalNumberAndPosition[0]
#position = finalNumberAndPosition[1] - 1
evenNumbers = []
oddNumbers = []
i = 0
while i < finalNumberAndPosition[0]:
i += 1
if i % 2 == 0:
evenNumbers.append(i)
else:
oddNumbers.append(i)
finalSequence = oddNumbers + evenNumbers
print(finalSequence[finalNumberAndPosition[1]-1])
``` | 0 |
|
515 | A | Drazil and Date | PROGRAMMING | 1,000 | [
"math"
] | null | null | Someday, Drazil wanted to go on date with Varda. Drazil and Varda live on Cartesian plane. Drazil's home is located in point (0,<=0) and Varda's home is located in point (*a*,<=*b*). In each step, he can move in a unit distance in horizontal or vertical direction. In other words, from position (*x*,<=*y*) he can go to positions (*x*<=+<=1,<=*y*), (*x*<=-<=1,<=*y*), (*x*,<=*y*<=+<=1) or (*x*,<=*y*<=-<=1).
Unfortunately, Drazil doesn't have sense of direction. So he randomly chooses the direction he will go to in each step. He may accidentally return back to his house during his travel. Drazil may even not notice that he has arrived to (*a*,<=*b*) and continue travelling.
Luckily, Drazil arrived to the position (*a*,<=*b*) successfully. Drazil said to Varda: "It took me exactly *s* steps to travel from my house to yours". But Varda is confused about his words, she is not sure that it is possible to get from (0,<=0) to (*a*,<=*b*) in exactly *s* steps. Can you find out if it is possible for Varda? | You are given three integers *a*, *b*, and *s* (<=-<=109<=≤<=*a*,<=*b*<=≤<=109, 1<=≤<=*s*<=≤<=2·109) in a single line. | If you think Drazil made a mistake and it is impossible to take exactly *s* steps and get from his home to Varda's home, print "No" (without quotes).
Otherwise, print "Yes". | [
"5 5 11\n",
"10 15 25\n",
"0 5 1\n",
"0 0 2\n"
] | [
"No\n",
"Yes\n",
"No\n",
"Yes\n"
] | In fourth sample case one possible route is: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/0d30660ddf6eb6c64ffd071055a4e8ddd016cde5.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | 500 | [
{
"input": "5 5 11",
"output": "No"
},
{
"input": "10 15 25",
"output": "Yes"
},
{
"input": "0 5 1",
"output": "No"
},
{
"input": "0 0 2",
"output": "Yes"
},
{
"input": "999999999 999999999 2000000000",
"output": "Yes"
},
{
"input": "-606037695 998320124 820674098",
"output": "No"
},
{
"input": "948253616 -83299062 1031552680",
"output": "Yes"
},
{
"input": "711980199 216568284 928548487",
"output": "Yes"
},
{
"input": "-453961301 271150176 725111473",
"output": "No"
},
{
"input": "0 0 2000000000",
"output": "Yes"
},
{
"input": "0 0 1999999999",
"output": "No"
},
{
"input": "1000000000 1000000000 2000000000",
"output": "Yes"
},
{
"input": "-1000000000 1000000000 2000000000",
"output": "Yes"
},
{
"input": "-1000000000 -1000000000 2000000000",
"output": "Yes"
},
{
"input": "-1000000000 -1000000000 1000000000",
"output": "No"
},
{
"input": "-1 -1 3",
"output": "No"
},
{
"input": "919785634 216774719 129321944",
"output": "No"
},
{
"input": "-467780354 -721273539 1369030008",
"output": "No"
},
{
"input": "-232833910 -880680184 1774549792",
"output": "Yes"
},
{
"input": "45535578 402686155 1011249824",
"output": "No"
},
{
"input": "-203250176 -30379840 233630015",
"output": "No"
},
{
"input": "-814516648 -75830576 890347222",
"output": "No"
},
{
"input": "869184175 -511854751 1381038923",
"output": "No"
},
{
"input": "552884998 -262338193 815223187",
"output": "No"
},
{
"input": "-133874494 857573117 991447611",
"output": "Yes"
},
{
"input": "169406792 786701289 956108082",
"output": "No"
},
{
"input": "30237137 -989203246 1019440385",
"output": "Yes"
},
{
"input": "576608216 -617624133 1194232352",
"output": "No"
},
{
"input": "-662360368 97618995 759979367",
"output": "Yes"
},
{
"input": "-115989290 321714461 437703756",
"output": "No"
},
{
"input": "-1 -3 2",
"output": "No"
},
{
"input": "-2 -2 2",
"output": "No"
},
{
"input": "0 0 1",
"output": "No"
},
{
"input": "0 -1 7",
"output": "Yes"
},
{
"input": "1 2 7",
"output": "Yes"
},
{
"input": "0 5 6",
"output": "No"
},
{
"input": "0 -4 2",
"output": "No"
},
{
"input": "-5 5 2",
"output": "No"
},
{
"input": "-5 -2 7",
"output": "Yes"
},
{
"input": "5 -5 2",
"output": "No"
}
] | 1,585,910,932 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 5 | 124 | 0 | x,y,s=map(int,input().split())
if(x+y==s or (x+y<s and s%2==0)):
print("Yes")
else:
print("No") | Title: Drazil and Date
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Someday, Drazil wanted to go on date with Varda. Drazil and Varda live on Cartesian plane. Drazil's home is located in point (0,<=0) and Varda's home is located in point (*a*,<=*b*). In each step, he can move in a unit distance in horizontal or vertical direction. In other words, from position (*x*,<=*y*) he can go to positions (*x*<=+<=1,<=*y*), (*x*<=-<=1,<=*y*), (*x*,<=*y*<=+<=1) or (*x*,<=*y*<=-<=1).
Unfortunately, Drazil doesn't have sense of direction. So he randomly chooses the direction he will go to in each step. He may accidentally return back to his house during his travel. Drazil may even not notice that he has arrived to (*a*,<=*b*) and continue travelling.
Luckily, Drazil arrived to the position (*a*,<=*b*) successfully. Drazil said to Varda: "It took me exactly *s* steps to travel from my house to yours". But Varda is confused about his words, she is not sure that it is possible to get from (0,<=0) to (*a*,<=*b*) in exactly *s* steps. Can you find out if it is possible for Varda?
Input Specification:
You are given three integers *a*, *b*, and *s* (<=-<=109<=≤<=*a*,<=*b*<=≤<=109, 1<=≤<=*s*<=≤<=2·109) in a single line.
Output Specification:
If you think Drazil made a mistake and it is impossible to take exactly *s* steps and get from his home to Varda's home, print "No" (without quotes).
Otherwise, print "Yes".
Demo Input:
['5 5 11\n', '10 15 25\n', '0 5 1\n', '0 0 2\n']
Demo Output:
['No\n', 'Yes\n', 'No\n', 'Yes\n']
Note:
In fourth sample case one possible route is: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/0d30660ddf6eb6c64ffd071055a4e8ddd016cde5.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | ```python
x,y,s=map(int,input().split())
if(x+y==s or (x+y<s and s%2==0)):
print("Yes")
else:
print("No")
``` | 0 |
|
847 | M | Weather Tomorrow | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Vasya came up with his own weather forecasting method. He knows the information about the average air temperature for each of the last *n* days. Assume that the average air temperature for each day is integral.
Vasya believes that if the average temperatures over the last *n* days form an arithmetic progression, where the first term equals to the average temperature on the first day, the second term equals to the average temperature on the second day and so on, then the average temperature of the next (*n*<=+<=1)-th day will be equal to the next term of the arithmetic progression. Otherwise, according to Vasya's method, the temperature of the (*n*<=+<=1)-th day will be equal to the temperature of the *n*-th day.
Your task is to help Vasya predict the average temperature for tomorrow, i. e. for the (*n*<=+<=1)-th day. | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=100) — the number of days for which the average air temperature is known.
The second line contains a sequence of integers *t*1,<=*t*2,<=...,<=*t**n* (<=-<=1000<=≤<=*t**i*<=≤<=1000) — where *t**i* is the average temperature in the *i*-th day. | Print the average air temperature in the (*n*<=+<=1)-th day, which Vasya predicts according to his method. Note that the absolute value of the predicted temperature can exceed 1000. | [
"5\n10 5 0 -5 -10\n",
"4\n1 1 1 1\n",
"3\n5 1 -5\n",
"2\n900 1000\n"
] | [
"-15\n",
"1\n",
"-5\n",
"1100\n"
] | In the first example the sequence of the average temperatures is an arithmetic progression where the first term is 10 and each following terms decreases by 5. So the predicted average temperature for the sixth day is - 10 - 5 = - 15.
In the second example the sequence of the average temperatures is an arithmetic progression where the first term is 1 and each following terms equals to the previous one. So the predicted average temperature in the fifth day is 1.
In the third example the average temperatures do not form an arithmetic progression, so the average temperature of the fourth day equals to the temperature of the third day and equals to - 5.
In the fourth example the sequence of the average temperatures is an arithmetic progression where the first term is 900 and each the following terms increase by 100. So predicted average temperature in the third day is 1000 + 100 = 1100. | 0 | [
{
"input": "5\n10 5 0 -5 -10",
"output": "-15"
},
{
"input": "4\n1 1 1 1",
"output": "1"
},
{
"input": "3\n5 1 -5",
"output": "-5"
},
{
"input": "2\n900 1000",
"output": "1100"
},
{
"input": "2\n1 2",
"output": "3"
},
{
"input": "3\n2 5 8",
"output": "11"
},
{
"input": "4\n4 1 -2 -5",
"output": "-8"
},
{
"input": "10\n-1000 -995 -990 -985 -980 -975 -970 -965 -960 -955",
"output": "-950"
},
{
"input": "11\n-1000 -800 -600 -400 -200 0 200 400 600 800 1000",
"output": "1200"
},
{
"input": "31\n1000 978 956 934 912 890 868 846 824 802 780 758 736 714 692 670 648 626 604 582 560 538 516 494 472 450 428 406 384 362 340",
"output": "318"
},
{
"input": "5\n1000 544 88 -368 -824",
"output": "-1280"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "0"
},
{
"input": "33\n456 411 366 321 276 231 186 141 96 51 6 -39 -84 -129 -174 -219 -264 -309 -354 -399 -444 -489 -534 -579 -624 -669 -714 -759 -804 -849 -894 -939 -984",
"output": "-1029"
},
{
"input": "77\n-765 -742 -719 -696 -673 -650 -627 -604 -581 -558 -535 -512 -489 -466 -443 -420 -397 -374 -351 -328 -305 -282 -259 -236 -213 -190 -167 -144 -121 -98 -75 -52 -29 -6 17 40 63 86 109 132 155 178 201 224 247 270 293 316 339 362 385 408 431 454 477 500 523 546 569 592 615 638 661 684 707 730 753 776 799 822 845 868 891 914 937 960 983",
"output": "1006"
},
{
"input": "3\n2 4 8",
"output": "8"
},
{
"input": "4\n4 1 -3 -5",
"output": "-5"
},
{
"input": "10\n-1000 -995 -990 -984 -980 -975 -970 -965 -960 -955",
"output": "-955"
},
{
"input": "11\n-999 -800 -600 -400 -200 0 200 400 600 800 1000",
"output": "1000"
},
{
"input": "51\n-9 10 30 50 70 90 110 130 150 170 190 210 230 250 270 290 310 330 350 370 390 410 430 450 470 490 510 530 550 570 590 610 630 650 670 690 710 730 750 770 790 810 830 850 870 890 910 930 950 970 990",
"output": "990"
},
{
"input": "100\n10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 207",
"output": "207"
},
{
"input": "2\n1000 1000",
"output": "1000"
},
{
"input": "2\n-1000 1000",
"output": "3000"
},
{
"input": "2\n1000 -1000",
"output": "-3000"
},
{
"input": "2\n-1000 -1000",
"output": "-1000"
},
{
"input": "100\n-85 -80 -76 -72 -68 -64 -60 -56 -52 -48 -44 -40 -36 -32 -28 -24 -20 -16 -12 -8 -4 0 4 8 12 16 20 24 28 32 36 40 44 48 52 56 60 64 68 72 76 80 84 88 92 96 100 104 108 112 116 120 124 128 132 136 140 144 148 152 156 160 164 168 172 176 180 184 188 192 196 200 204 208 212 216 220 224 228 232 236 240 244 248 252 256 260 264 268 272 276 280 284 288 292 296 300 304 308 312",
"output": "312"
},
{
"input": "4\n1 2 4 5",
"output": "5"
}
] | 1,544,794,088 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 93 | 0 | n=int(input())
t=list(map(int,input().split()))
c=abs(t[0])-abs(t[1])
for x in range(1,n-1):
if abs(t[x])-abs(t[x+1])!=c:
print(t[-1])
break
else:
print(t[-1]-c)
break | Title: Weather Tomorrow
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya came up with his own weather forecasting method. He knows the information about the average air temperature for each of the last *n* days. Assume that the average air temperature for each day is integral.
Vasya believes that if the average temperatures over the last *n* days form an arithmetic progression, where the first term equals to the average temperature on the first day, the second term equals to the average temperature on the second day and so on, then the average temperature of the next (*n*<=+<=1)-th day will be equal to the next term of the arithmetic progression. Otherwise, according to Vasya's method, the temperature of the (*n*<=+<=1)-th day will be equal to the temperature of the *n*-th day.
Your task is to help Vasya predict the average temperature for tomorrow, i. e. for the (*n*<=+<=1)-th day.
Input Specification:
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=100) — the number of days for which the average air temperature is known.
The second line contains a sequence of integers *t*1,<=*t*2,<=...,<=*t**n* (<=-<=1000<=≤<=*t**i*<=≤<=1000) — where *t**i* is the average temperature in the *i*-th day.
Output Specification:
Print the average air temperature in the (*n*<=+<=1)-th day, which Vasya predicts according to his method. Note that the absolute value of the predicted temperature can exceed 1000.
Demo Input:
['5\n10 5 0 -5 -10\n', '4\n1 1 1 1\n', '3\n5 1 -5\n', '2\n900 1000\n']
Demo Output:
['-15\n', '1\n', '-5\n', '1100\n']
Note:
In the first example the sequence of the average temperatures is an arithmetic progression where the first term is 10 and each following terms decreases by 5. So the predicted average temperature for the sixth day is - 10 - 5 = - 15.
In the second example the sequence of the average temperatures is an arithmetic progression where the first term is 1 and each following terms equals to the previous one. So the predicted average temperature in the fifth day is 1.
In the third example the average temperatures do not form an arithmetic progression, so the average temperature of the fourth day equals to the temperature of the third day and equals to - 5.
In the fourth example the sequence of the average temperatures is an arithmetic progression where the first term is 900 and each the following terms increase by 100. So predicted average temperature in the third day is 1000 + 100 = 1100. | ```python
n=int(input())
t=list(map(int,input().split()))
c=abs(t[0])-abs(t[1])
for x in range(1,n-1):
if abs(t[x])-abs(t[x+1])!=c:
print(t[-1])
break
else:
print(t[-1]-c)
break
``` | 0 |
|
520 | A | Pangram | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices.
You are given a string consisting of lowercase and uppercase Latin letters. Check whether this string is a pangram. We say that the string contains a letter of the Latin alphabet if this letter occurs in the string in uppercase or lowercase. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of characters in the string.
The second line contains the string. The string consists only of uppercase and lowercase Latin letters. | Output "YES", if the string is a pangram and "NO" otherwise. | [
"12\ntoosmallword\n",
"35\nTheQuickBrownFoxJumpsOverTheLazyDog\n"
] | [
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "12\ntoosmallword",
"output": "NO"
},
{
"input": "35\nTheQuickBrownFoxJumpsOverTheLazyDog",
"output": "YES"
},
{
"input": "1\na",
"output": "NO"
},
{
"input": "26\nqwertyuiopasdfghjklzxcvbnm",
"output": "YES"
},
{
"input": "26\nABCDEFGHIJKLMNOPQRSTUVWXYZ",
"output": "YES"
},
{
"input": "48\nthereisasyetinsufficientdataforameaningfulanswer",
"output": "NO"
},
{
"input": "30\nToBeOrNotToBeThatIsTheQuestion",
"output": "NO"
},
{
"input": "30\njackdawslovemybigsphinxofquarz",
"output": "NO"
},
{
"input": "31\nTHEFIVEBOXINGWIZARDSJUMPQUICKLY",
"output": "YES"
},
{
"input": "26\naaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "NO"
},
{
"input": "26\nMGJYIZDKsbhpVeNFlquRTcWoAx",
"output": "YES"
},
{
"input": "26\nfWMOhAPsbIVtyUEZrGNQXDklCJ",
"output": "YES"
},
{
"input": "26\nngPMVFSThiRCwLEuyOAbKxQzDJ",
"output": "YES"
},
{
"input": "25\nnxYTzLFwzNolAumjgcAboyxAj",
"output": "NO"
},
{
"input": "26\npRWdodGdxUESvcScPGbUoooZsC",
"output": "NO"
},
{
"input": "66\nBovdMlDzTaqKllZILFVfxbLGsRnzmtVVTmqiIDTYrossLEPlmsPrkUYtWEsGHVOnFj",
"output": "NO"
},
{
"input": "100\nmKtsiDRJypUieHIkvJaMFkwaKxcCIbBszZQLIyPpCDCjhNpAnYFngLjRpnKWpKWtGnwoSteeZXuFHWQxxxOpFlNeYTwKocsXuCoa",
"output": "YES"
},
{
"input": "26\nEoqxUbsLjPytUHMiFnvcGWZdRK",
"output": "NO"
},
{
"input": "26\nvCUFRKElZOnjmXGylWQaHDiPst",
"output": "NO"
},
{
"input": "26\nWtrPuaHdXLKJMsnvQfgOiJZBEY",
"output": "NO"
},
{
"input": "26\npGiFluRteQwkaVoPszJyNBChxM",
"output": "NO"
},
{
"input": "26\ncTUpqjPmANrdbzSFhlWIoKxgVY",
"output": "NO"
},
{
"input": "26\nLndjgvAEuICHKxPwqYztosrmBN",
"output": "NO"
},
{
"input": "26\nMdaXJrCipnOZLykfqHWEStevbU",
"output": "NO"
},
{
"input": "26\nEjDWsVxfKTqGXRnUMOLYcIzPba",
"output": "NO"
},
{
"input": "26\nxKwzRMpunYaqsdfaBgJcVElTHo",
"output": "NO"
},
{
"input": "26\nnRYUQsTwCPLZkgshfEXvBdoiMa",
"output": "NO"
},
{
"input": "26\nHNCQPfJutyAlDGsvRxZWMEbIdO",
"output": "NO"
},
{
"input": "26\nDaHJIpvKznQcmUyWsTGObXRFDe",
"output": "NO"
},
{
"input": "26\nkqvAnFAiRhzlJbtyuWedXSPcOG",
"output": "NO"
},
{
"input": "26\nhlrvgdwsIOyjcmUZXtAKEqoBpF",
"output": "NO"
},
{
"input": "26\njLfXXiMhBTcAwQVReGnpKzdsYu",
"output": "NO"
},
{
"input": "26\nlNMcVuwItjxRBGAekjhyDsQOzf",
"output": "NO"
},
{
"input": "26\nRkSwbNoYldUGtAZvpFMcxhIJFE",
"output": "NO"
},
{
"input": "26\nDqspXZJTuONYieKgaHLMBwfVSC",
"output": "NO"
},
{
"input": "26\necOyUkqNljFHRVXtIpWabGMLDz",
"output": "NO"
},
{
"input": "26\nEKAvqZhBnPmVCDRlgWJfOusxYI",
"output": "NO"
},
{
"input": "26\naLbgqeYchKdMrsZxIPFvTOWNjA",
"output": "NO"
},
{
"input": "26\nxfpBLsndiqtacOCHGmeWUjRkYz",
"output": "NO"
},
{
"input": "26\nXsbRKtqleZPNIVCdfUhyagAomJ",
"output": "NO"
},
{
"input": "26\nAmVtbrwquEthZcjKPLiyDgSoNF",
"output": "NO"
},
{
"input": "26\nOhvXDcwqAUmSEPRZGnjFLiKtNB",
"output": "NO"
},
{
"input": "26\nEKWJqCFLRmstxVBdYuinpbhaOg",
"output": "NO"
},
{
"input": "26\nmnbvcxxlkjhgfdsapoiuytrewq",
"output": "NO"
},
{
"input": "26\naAbcdefghijklmnopqrstuvwxy",
"output": "NO"
},
{
"input": "30\nABCDEFGHTYRIOPLabcdefghtyriopl",
"output": "NO"
},
{
"input": "25\nabcdefghijklmnopqrstuvwxy",
"output": "NO"
},
{
"input": "26\nabcdefhijklmnopqrstVxyzABC",
"output": "NO"
},
{
"input": "25\nqwertyuiopasdfghjklxcvbnm",
"output": "NO"
},
{
"input": "34\nTheQuickBrownFoxJumpsOverTheLayDog",
"output": "NO"
},
{
"input": "26\nabcdefghigklmnopqrstuvwxyz",
"output": "NO"
},
{
"input": "26\nabcdefghijklmnopqrstuvwxyA",
"output": "NO"
},
{
"input": "50\nqazwsxedcrfvtgbyhnujmikolQWERTYUIOASDFGHJKLZXCVBNM",
"output": "NO"
},
{
"input": "35\nTheQuickBrownFoxJumpsOverTheLasyDog",
"output": "NO"
},
{
"input": "25\nbcdefghijklmnopqrstuvwxyz",
"output": "NO"
},
{
"input": "38\nAbCdEfGhIjKlMnOpQrStVwXyZzzzzzzaaaaaaa",
"output": "NO"
},
{
"input": "26\nabcdefghiklmnopqrstvxyzABC",
"output": "NO"
},
{
"input": "26\nabcdefghijklmnopqrstuvwxzZ",
"output": "NO"
},
{
"input": "50\nabcdefghijklmnopqrstuvwxyABCDEFGHIJKLMNOPQRSTUVWXY",
"output": "NO"
}
] | 1,698,000,911 | 2,147,483,647 | Python 3 | OK | TESTS | 59 | 46 | 0 | def panagram(string):
for i in range(65, 91):
if chr(i) not in string:
return "NO"
return "YES"
size = int(input())
string = input().upper()
if size < 26:
print("NO")
else:
print(panagram(string)) | Title: Pangram
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices.
You are given a string consisting of lowercase and uppercase Latin letters. Check whether this string is a pangram. We say that the string contains a letter of the Latin alphabet if this letter occurs in the string in uppercase or lowercase.
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of characters in the string.
The second line contains the string. The string consists only of uppercase and lowercase Latin letters.
Output Specification:
Output "YES", if the string is a pangram and "NO" otherwise.
Demo Input:
['12\ntoosmallword\n', '35\nTheQuickBrownFoxJumpsOverTheLazyDog\n']
Demo Output:
['NO\n', 'YES\n']
Note:
none | ```python
def panagram(string):
for i in range(65, 91):
if chr(i) not in string:
return "NO"
return "YES"
size = int(input())
string = input().upper()
if size < 26:
print("NO")
else:
print(panagram(string))
``` | 3 |
|
934 | A | A Compatible Pair | PROGRAMMING | 1,400 | [
"brute force",
"games"
] | null | null | Nian is a monster which lives deep in the oceans. Once a year, it shows up on the land, devouring livestock and even people. In order to keep the monster away, people fill their villages with red colour, light, and cracking noise, all of which frighten the monster out of coming.
Little Tommy has *n* lanterns and Big Banban has *m* lanterns. Tommy's lanterns have brightness *a*1,<=*a*2,<=...,<=*a**n*, and Banban's have brightness *b*1,<=*b*2,<=...,<=*b**m* respectively.
Tommy intends to hide one of his lanterns, then Banban picks one of Tommy's non-hidden lanterns and one of his own lanterns to form a pair. The pair's brightness will be the product of the brightness of two lanterns.
Tommy wants to make the product as small as possible, while Banban tries to make it as large as possible.
You are asked to find the brightness of the chosen pair if both of them choose optimally. | The first line contains two space-separated integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=50).
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n*.
The third line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m*.
All the integers range from <=-<=109 to 109. | Print a single integer — the brightness of the chosen pair. | [
"2 2\n20 18\n2 14\n",
"5 3\n-1 0 1 2 3\n-1 0 1\n"
] | [
"252\n",
"2\n"
] | In the first example, Tommy will hide 20 and Banban will choose 18 from Tommy and 14 from himself.
In the second example, Tommy will hide 3 and Banban will choose 2 from Tommy and 1 from himself. | 500 | [
{
"input": "2 2\n20 18\n2 14",
"output": "252"
},
{
"input": "5 3\n-1 0 1 2 3\n-1 0 1",
"output": "2"
},
{
"input": "10 2\n1 6 2 10 2 3 2 10 6 4\n5 7",
"output": "70"
},
{
"input": "50 50\n1 6 2 10 2 3 2 10 6 4 5 0 3 1 7 3 2 4 4 2 1 5 0 6 10 1 8 0 10 9 0 4 10 5 5 7 4 9 9 5 5 2 6 7 9 4 3 7 2 0\n0 5 9 4 4 6 1 8 2 1 6 6 8 6 4 4 7 2 1 8 6 7 4 9 8 3 0 2 0 10 7 1 4 9 4 4 2 5 3 5 1 3 2 4 1 6 5 3 8 6",
"output": "100"
},
{
"input": "5 7\n-130464232 -73113866 -542094710 -53118823 -63528720\n-775179088 631683023 -974858199 -157471745 -629658630 71825477 -6235611",
"output": "127184126241438168"
},
{
"input": "16 15\n-94580188 -713689767 -559972014 -632609438 -930348091 -567718487 -611395744 -819913097 -924009672 -427913920 -812510647 -546415480 -982072775 -693369647 -693004777 -714181162\n-772924706 -202246100 -165871667 -991426281 -490838183 209351416 134956137 -36128588 -754413937 -616596290 696201705 -201191199 967464971 -244181984 -729907974",
"output": "922371547895579571"
},
{
"input": "12 22\n-102896616 -311161241 -67541276 -402842686 -830595520 -813834033 -44046671 -584806552 -598620444 -968935604 -303048547 -545969410\n545786451 262898403 442511997 -441241260 -479587986 -752123290 720443264 500646237 737842681 -571966572 -798463881 -477248830 89875164 410339460 -359022689 -251280099 -441455542 -538431186 -406793869 374561004 -108755237 -440143410",
"output": "663200522440413120"
},
{
"input": "33 14\n-576562007 -218618150 -471719380 -583840778 -256368365 -68451917 -405045344 -775538133 -896830082 -439261765 -947070124 -716577019 -456110999 -689862512 -132480131 -10805271 -518903339 -196240188 -222292638 -828546042 -43887962 -161359263 -281422097 -484060534 963147664 -492377073 -154570101 -52145116 187803553 858844161 66540410 418777176 434025748\n-78301978 -319393213 -12393024 542953412 786804661 845642067 754996432 -985617475 -487171947 56142664 203173079 -268261708 -817080591 -511720682",
"output": "883931400924882950"
},
{
"input": "15 8\n-966400308 -992207261 -302395973 -837980754 -516443826 -492405613 -378127629 -762650324 -519519776 -36132939 -286460372 -351445284 -407653342 -604960925 -523442015\n610042288 27129580 -103108347 -942517864 842060508 -588904868 614786155 37455106",
"output": "910849554065102112"
},
{
"input": "6 30\n-524297819 -947277203 -444186475 -182837689 -385379656 -453917269\n834529938 35245081 663687669 585422565 164412867 850052113 796429008 -307345676 -127653313 426960600 211854713 -733687358 251466836 -33491050 -882811238 455544614 774581544 768447941 -241033484 441104324 -493975870 308277556 275268265 935941507 -152292053 -961509996 -740482111 -954176110 -924254634 -518710544",
"output": "504117593849498724"
},
{
"input": "5 32\n-540510995 -841481393 -94342377 -74818927 -93445356\n686714668 -82581175 736472406 502016312 575563638 -899308712 503504178 -644271272 -437408397 385778869 -746757839 306275973 -663503743 -431116516 -418708278 -515261493 -988182324 900230931 218258353 -714420102 -241118202 294802602 -937785552 -857537498 -723195312 -690515139 -214508504 -44086454 -231621215 -418360090 -810003786 -675944617",
"output": "534123411186652380"
},
{
"input": "32 13\n-999451897 -96946179 -524159869 -906101658 -63367320 -629803888 -968586834 -658416130 -874232857 -926556428 -749908220 -517073321 -659752288 -910152878 -786916085 -607633039 -191428642 -867952926 -873793977 -584331784 -733245792 -779809700 -554228536 -464503499 561577340 258991071 -569805979 -372655165 -106685554 -619607960 188856473 -268960803\n886429660 -587284372 911396803 -462990289 -228681210 -876239914 -822830527 -750131315 -401234943 116991909 -582713480 979631847 813552478",
"output": "848714444125692276"
},
{
"input": "12 25\n-464030345 -914672073 -483242132 -856226270 -925135169 -353124606 -294027092 -619650850 -490724485 -240424784 -483066792 -921640365\n279850608 726838739 -431610610 242749870 -244020223 -396865433 129534799 182767854 -939698671 342579400 330027106 893561388 -263513962 643369418 276245179 -99206565 -473767261 -168908664 -853755837 -270920164 -661186118 199341055 765543053 908211534 -93363867",
"output": "866064226130454915"
},
{
"input": "10 13\n-749120991 -186261632 -335412349 -231354880 -195919225 -808736065 -481883825 -263383991 -664780611 -605377134\n718174936 -140362196 -669193674 -598621021 -464130929 450701419 -331183926 107203430 946959233 -565825915 -558199897 246556991 -666216081",
"output": "501307028237810934"
},
{
"input": "17 13\n-483786205 -947257449 -125949195 -294711143 -420288876 -812462057 -250049555 -911026413 -188146919 -129501682 -869006661 -649643966 -26976411 -275761039 -869067490 -272248209 -342067346\n445539900 529728842 -808170728 673157826 -70778491 642872105 299298867 -76674218 -902394063 377664752 723887448 -121522827 906464625",
"output": "822104826327386019"
},
{
"input": "15 29\n-716525085 -464205793 -577203110 -979997115 -491032521 -70793687 -770595947 -817983495 -767886763 -223333719 -971913221 -944656683 -200397825 -295615495 -945544540\n-877638425 -146878165 523758517 -158778747 -49535534 597311016 77325385 494128313 12111658 -4196724 295706874 477139483 375083042 726254399 -439255703 662913604 -481588088 673747948 -345999555 -723334478 -656721905 276267528 628773156 851420802 -585029291 -643535709 -968999740 -384418713 -510285542",
"output": "941783658451562540"
},
{
"input": "5 7\n-130464232 -73113866 -542094710 -53118823 -63528720\n449942926 482853427 861095072 316710734 194604468 20277633 668816604",
"output": "-1288212069119760"
},
{
"input": "24 24\n-700068683 -418791905 -24650102 -167277317 -182309202 -517748507 -663050677 -854097070 -426998982 -197009558 -101944229 -746589957 -849018439 -774208211 -946709040 -594578249 -276703474 -434567489 -743600446 -625029074 -977300284 -895608684 -878936220 -850670748\n704881272 169877679 705460701 94083210 403943695 987978311 786162506 658067668 697640875 186287 295558596 286470276 251313879 353071193 755450449 173370603 805550377 192465301 168935494 110161743 285139426 985238736 723221868 520679017",
"output": "-18990884587723"
},
{
"input": "39 9\n44558618 981372779 318891054 283079237 285093436 907256321 414759796 652683534 79042330 249010687 7020063 309415438 788425492 138577429 714835649 954204512 795507844 389962019 507308352 408180613 194676444 44962879 922688019 101163040 327953325 560462120 183657590 273616448 226876035 233697890 720185285 689340674 372938362 15088928 283418109 796807778 149989495 694808087 276385512\n-681609072 -210918688 -757170622 -205635977 -597872997 -496188744 -97031207 -311654366 -389141528",
"output": "-1464096896176096"
},
{
"input": "5 7\n869535768 926886134 457905290 946881177 936471280\n-550057074 -517146573 -138904928 -683289266 -805395532 -979722367 -331183396",
"output": "-120782803247464704"
},
{
"input": "24 24\n299931317 581208095 975349898 832722683 817690798 482251493 336949323 145902930 573001018 802990442 898055771 253410043 150981561 225791789 53290960 405421751 723296526 565432511 256399554 374970926 22699716 104391316 121063780 149329252\n-295118728 -830122321 -294539299 -905916790 -596056305 -12021689 -213837494 -341932332 -302359125 -999813713 -704441404 -713529724 -748686121 -646928807 -244549551 -826629397 -194449623 -807534699 -831064506 -889838257 -714860574 -14761264 -276778132 -479320983",
"output": "-640647347631440"
},
{
"input": "14 8\n-1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "-1000000000000000000"
}
] | 1,524,569,912 | 2,147,483,647 | Python 3 | OK | TESTS | 87 | 93 | 7,065,600 | n,m=map(int,input().split())
arr1=list(map(int,input().split()))
arr2=list(map(int,input().split()))
ans=[]
for i in arr1:
ans1=[]
for j in arr2:
ans1.append(i*j)
ans.append(max(ans1))
ans.sort(reverse=True)
print(ans[1]) | Title: A Compatible Pair
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Nian is a monster which lives deep in the oceans. Once a year, it shows up on the land, devouring livestock and even people. In order to keep the monster away, people fill their villages with red colour, light, and cracking noise, all of which frighten the monster out of coming.
Little Tommy has *n* lanterns and Big Banban has *m* lanterns. Tommy's lanterns have brightness *a*1,<=*a*2,<=...,<=*a**n*, and Banban's have brightness *b*1,<=*b*2,<=...,<=*b**m* respectively.
Tommy intends to hide one of his lanterns, then Banban picks one of Tommy's non-hidden lanterns and one of his own lanterns to form a pair. The pair's brightness will be the product of the brightness of two lanterns.
Tommy wants to make the product as small as possible, while Banban tries to make it as large as possible.
You are asked to find the brightness of the chosen pair if both of them choose optimally.
Input Specification:
The first line contains two space-separated integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=50).
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n*.
The third line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m*.
All the integers range from <=-<=109 to 109.
Output Specification:
Print a single integer — the brightness of the chosen pair.
Demo Input:
['2 2\n20 18\n2 14\n', '5 3\n-1 0 1 2 3\n-1 0 1\n']
Demo Output:
['252\n', '2\n']
Note:
In the first example, Tommy will hide 20 and Banban will choose 18 from Tommy and 14 from himself.
In the second example, Tommy will hide 3 and Banban will choose 2 from Tommy and 1 from himself. | ```python
n,m=map(int,input().split())
arr1=list(map(int,input().split()))
arr2=list(map(int,input().split()))
ans=[]
for i in arr1:
ans1=[]
for j in arr2:
ans1.append(i*j)
ans.append(max(ans1))
ans.sort(reverse=True)
print(ans[1])
``` | 3 |
|
807 | A | Is it rated? | PROGRAMMING | 900 | [
"implementation",
"sortings"
] | null | null | Is it rated?
Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it.
Another Codeforces round has been conducted. No two participants have the same number of points. For each participant, from the top to the bottom of the standings, their rating before and after the round is known.
It's known that if at least one participant's rating has changed, then the round was rated for sure.
It's also known that if the round was rated and a participant with lower rating took a better place in the standings than a participant with higher rating, then at least one round participant's rating has changed.
In this problem, you should not make any other assumptions about the rating system.
Determine if the current round is rated, unrated, or it's impossible to determine whether it is rated of not. | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=1000) — the number of round participants.
Each of the next *n* lines contains two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=4126) — the rating of the *i*-th participant before and after the round, respectively. The participants are listed in order from the top to the bottom of the standings. | If the round is rated for sure, print "rated". If the round is unrated for sure, print "unrated". If it's impossible to determine whether the round is rated or not, print "maybe". | [
"6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884\n",
"4\n1500 1500\n1300 1300\n1200 1200\n1400 1400\n",
"5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699\n"
] | [
"rated\n",
"unrated\n",
"maybe\n"
] | In the first example, the ratings of the participants in the third and fifth places have changed, therefore, the round was rated.
In the second example, no one's rating has changed, but the participant in the second place has lower rating than the participant in the fourth place. Therefore, if the round was rated, someone's rating would've changed for sure.
In the third example, no one's rating has changed, and the participants took places in non-increasing order of their rating. Therefore, it's impossible to determine whether the round is rated or not. | 500 | [
{
"input": "6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884",
"output": "rated"
},
{
"input": "4\n1500 1500\n1300 1300\n1200 1200\n1400 1400",
"output": "unrated"
},
{
"input": "5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699",
"output": "maybe"
},
{
"input": "2\n1 1\n1 1",
"output": "maybe"
},
{
"input": "2\n4126 4126\n4126 4126",
"output": "maybe"
},
{
"input": "10\n446 446\n1331 1331\n3594 3594\n1346 1902\n91 91\n3590 3590\n2437 2437\n4007 3871\n2797 699\n1423 1423",
"output": "rated"
},
{
"input": "10\n4078 4078\n2876 2876\n1061 1061\n3721 3721\n143 143\n2992 2992\n3279 3279\n3389 3389\n1702 1702\n1110 1110",
"output": "unrated"
},
{
"input": "10\n4078 4078\n3721 3721\n3389 3389\n3279 3279\n2992 2992\n2876 2876\n1702 1702\n1110 1110\n1061 1061\n143 143",
"output": "maybe"
},
{
"input": "2\n3936 3936\n2967 2967",
"output": "maybe"
},
{
"input": "2\n1 1\n2 2",
"output": "unrated"
},
{
"input": "2\n2 2\n1 1",
"output": "maybe"
},
{
"input": "2\n2 1\n1 2",
"output": "rated"
},
{
"input": "2\n2967 2967\n3936 3936",
"output": "unrated"
},
{
"input": "3\n1200 1200\n1200 1200\n1300 1300",
"output": "unrated"
},
{
"input": "3\n3 3\n2 2\n1 1",
"output": "maybe"
},
{
"input": "3\n1 1\n1 1\n2 2",
"output": "unrated"
},
{
"input": "2\n3 2\n3 2",
"output": "rated"
},
{
"input": "3\n5 5\n4 4\n3 4",
"output": "rated"
},
{
"input": "3\n200 200\n200 200\n300 300",
"output": "unrated"
},
{
"input": "3\n1 1\n2 2\n3 3",
"output": "unrated"
},
{
"input": "5\n3123 3123\n2777 2777\n2246 2246\n2245 2245\n1699 1699",
"output": "maybe"
},
{
"input": "2\n10 10\n8 8",
"output": "maybe"
},
{
"input": "3\n1500 1500\n1500 1500\n1600 1600",
"output": "unrated"
},
{
"input": "3\n1500 1500\n1500 1500\n1700 1700",
"output": "unrated"
},
{
"input": "4\n100 100\n100 100\n70 70\n80 80",
"output": "unrated"
},
{
"input": "2\n1 2\n2 1",
"output": "rated"
},
{
"input": "3\n5 5\n4 3\n3 3",
"output": "rated"
},
{
"input": "3\n1600 1650\n1500 1550\n1400 1450",
"output": "rated"
},
{
"input": "4\n2000 2000\n1500 1500\n1500 1500\n1700 1700",
"output": "unrated"
},
{
"input": "4\n1500 1500\n1400 1400\n1400 1400\n1700 1700",
"output": "unrated"
},
{
"input": "2\n1600 1600\n1400 1400",
"output": "maybe"
},
{
"input": "2\n3 1\n9 8",
"output": "rated"
},
{
"input": "2\n2 1\n1 1",
"output": "rated"
},
{
"input": "4\n4123 4123\n4123 4123\n2670 2670\n3670 3670",
"output": "unrated"
},
{
"input": "2\n2 2\n3 3",
"output": "unrated"
},
{
"input": "2\n10 11\n5 4",
"output": "rated"
},
{
"input": "2\n15 14\n13 12",
"output": "rated"
},
{
"input": "2\n2 1\n2 2",
"output": "rated"
},
{
"input": "3\n2670 2670\n3670 3670\n4106 4106",
"output": "unrated"
},
{
"input": "3\n4 5\n3 3\n2 2",
"output": "rated"
},
{
"input": "2\n10 9\n10 10",
"output": "rated"
},
{
"input": "3\n1011 1011\n1011 999\n2200 2100",
"output": "rated"
},
{
"input": "2\n3 3\n5 5",
"output": "unrated"
},
{
"input": "2\n1500 1500\n3000 2000",
"output": "rated"
},
{
"input": "2\n5 6\n5 5",
"output": "rated"
},
{
"input": "3\n2000 2000\n1500 1501\n500 500",
"output": "rated"
},
{
"input": "2\n2 3\n2 2",
"output": "rated"
},
{
"input": "2\n3 3\n2 2",
"output": "maybe"
},
{
"input": "2\n1 2\n1 1",
"output": "rated"
},
{
"input": "4\n3123 3123\n2777 2777\n2246 2246\n1699 1699",
"output": "maybe"
},
{
"input": "2\n15 14\n14 13",
"output": "rated"
},
{
"input": "4\n3000 3000\n2900 2900\n3000 3000\n2900 2900",
"output": "unrated"
},
{
"input": "6\n30 3060\n24 2194\n26 2903\n24 2624\n37 2991\n24 2884",
"output": "rated"
},
{
"input": "2\n100 99\n100 100",
"output": "rated"
},
{
"input": "4\n2 2\n1 1\n1 1\n2 2",
"output": "unrated"
},
{
"input": "3\n100 101\n100 100\n100 100",
"output": "rated"
},
{
"input": "4\n1000 1001\n900 900\n950 950\n890 890",
"output": "rated"
},
{
"input": "2\n2 3\n1 1",
"output": "rated"
},
{
"input": "2\n2 2\n1 1",
"output": "maybe"
},
{
"input": "2\n3 2\n2 2",
"output": "rated"
},
{
"input": "2\n3 2\n3 3",
"output": "rated"
},
{
"input": "2\n1 1\n2 2",
"output": "unrated"
},
{
"input": "3\n3 2\n3 3\n3 3",
"output": "rated"
},
{
"input": "4\n1500 1501\n1300 1300\n1200 1200\n1400 1400",
"output": "rated"
},
{
"input": "3\n1000 1000\n500 500\n400 300",
"output": "rated"
},
{
"input": "5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n3000 3000",
"output": "unrated"
},
{
"input": "2\n1 1\n2 3",
"output": "rated"
},
{
"input": "2\n6 2\n6 2",
"output": "rated"
},
{
"input": "5\n3123 3123\n1699 1699\n2777 2777\n2246 2246\n2246 2246",
"output": "unrated"
},
{
"input": "2\n1500 1500\n1600 1600",
"output": "unrated"
},
{
"input": "5\n3123 3123\n2777 2777\n2246 2246\n2241 2241\n1699 1699",
"output": "maybe"
},
{
"input": "2\n20 30\n10 5",
"output": "rated"
},
{
"input": "3\n1 1\n2 2\n1 1",
"output": "unrated"
},
{
"input": "2\n1 2\n3 3",
"output": "rated"
},
{
"input": "5\n5 5\n4 4\n3 3\n2 2\n1 1",
"output": "maybe"
},
{
"input": "2\n2 2\n2 1",
"output": "rated"
},
{
"input": "2\n100 100\n90 89",
"output": "rated"
},
{
"input": "2\n1000 900\n2000 2000",
"output": "rated"
},
{
"input": "2\n50 10\n10 50",
"output": "rated"
},
{
"input": "2\n200 200\n100 100",
"output": "maybe"
},
{
"input": "3\n2 2\n2 2\n3 3",
"output": "unrated"
},
{
"input": "3\n1000 1000\n300 300\n100 100",
"output": "maybe"
},
{
"input": "4\n2 2\n2 2\n3 3\n4 4",
"output": "unrated"
},
{
"input": "2\n5 3\n6 3",
"output": "rated"
},
{
"input": "2\n1200 1100\n1200 1000",
"output": "rated"
},
{
"input": "2\n5 5\n4 4",
"output": "maybe"
},
{
"input": "2\n5 5\n3 3",
"output": "maybe"
},
{
"input": "5\n1500 1500\n1300 1300\n1200 1200\n1400 1400\n1100 1100",
"output": "unrated"
},
{
"input": "5\n10 10\n9 9\n8 8\n7 7\n6 6",
"output": "maybe"
},
{
"input": "3\n1000 1000\n300 300\n10 10",
"output": "maybe"
},
{
"input": "5\n6 6\n5 5\n4 4\n3 3\n2 2",
"output": "maybe"
},
{
"input": "2\n3 3\n1 1",
"output": "maybe"
},
{
"input": "4\n2 2\n2 2\n2 2\n3 3",
"output": "unrated"
},
{
"input": "2\n1000 1000\n700 700",
"output": "maybe"
},
{
"input": "2\n4 3\n5 3",
"output": "rated"
},
{
"input": "2\n1000 1000\n1100 1100",
"output": "unrated"
},
{
"input": "4\n5 5\n4 4\n3 3\n2 2",
"output": "maybe"
},
{
"input": "3\n1 1\n2 3\n2 2",
"output": "rated"
},
{
"input": "2\n1 2\n1 3",
"output": "rated"
},
{
"input": "2\n3 3\n1 2",
"output": "rated"
},
{
"input": "4\n1501 1500\n1300 1300\n1200 1200\n1400 1400",
"output": "rated"
},
{
"input": "5\n1 1\n2 2\n3 3\n4 4\n5 5",
"output": "unrated"
},
{
"input": "2\n10 10\n1 2",
"output": "rated"
},
{
"input": "6\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699\n1900 1900",
"output": "unrated"
},
{
"input": "6\n3123 3123\n2777 2777\n3000 3000\n2246 2246\n2246 2246\n1699 1699",
"output": "unrated"
},
{
"input": "2\n100 100\n110 110",
"output": "unrated"
},
{
"input": "3\n3 3\n3 3\n4 4",
"output": "unrated"
},
{
"input": "3\n3 3\n3 2\n4 4",
"output": "rated"
},
{
"input": "3\n5 2\n4 4\n3 3",
"output": "rated"
},
{
"input": "4\n4 4\n3 3\n2 2\n1 1",
"output": "maybe"
},
{
"input": "2\n1 1\n3 2",
"output": "rated"
},
{
"input": "5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n2699 2699",
"output": "unrated"
},
{
"input": "3\n3 3\n3 3\n3 4",
"output": "rated"
},
{
"input": "3\n1 2\n2 2\n3 3",
"output": "rated"
},
{
"input": "3\n1 2\n1 2\n1 2",
"output": "rated"
},
{
"input": "2\n2 1\n2 1",
"output": "rated"
},
{
"input": "2\n1 2\n3 4",
"output": "rated"
},
{
"input": "2\n3 2\n2 3",
"output": "rated"
},
{
"input": "3\n1500 1500\n1600 1600\n1600 1600",
"output": "unrated"
},
{
"input": "3\n1 1\n3 3\n4 4",
"output": "unrated"
},
{
"input": "3\n1 1\n2 2\n2 2",
"output": "unrated"
},
{
"input": "2\n10 12\n8 8",
"output": "rated"
},
{
"input": "5\n1200 1200\n1500 1500\n1500 1500\n1500 1500\n1500 1500",
"output": "unrated"
},
{
"input": "2\n1 2\n2 2",
"output": "rated"
},
{
"input": "3\n1500 1400\n1200 1200\n1100 1100",
"output": "rated"
},
{
"input": "2\n10 12\n10 10",
"output": "rated"
},
{
"input": "3\n1500 1500\n1400 1400\n1300 1300",
"output": "maybe"
},
{
"input": "3\n3 3\n4 4\n5 5",
"output": "unrated"
},
{
"input": "3\n2 6\n3 5\n4 4",
"output": "rated"
},
{
"input": "2\n5 6\n4 6",
"output": "rated"
},
{
"input": "4\n10 10\n10 10\n7 7\n8 8",
"output": "unrated"
},
{
"input": "2\n4 4\n3 3",
"output": "maybe"
}
] | 1,684,684,664 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 150 | 62 | 0 | import sys
input = sys.stdin.readline
############ ---- Input Functions ---- ############
# Int inputs
def inp():
return (int(input()))
# List inputs
def inlt():
return (list(map(int, input().split())))
# For taking string inputs. list of Chars
def insr():
s = input()
return (list(s[:len(s) - 1]))
# For taking space separated integer variable inputs.
def invr():
return (map(int, input().split()))
if __name__ == "__main__":
n = inp()
previous = 4127
maybe = True
for i in range(n):
a, b = invr()
if a != b:
print("rated")
exit()
elif a > previous:
maybe = False
previous = a
print("maybe") if maybe else print("unrated")
#three conditions:
# rating change: rated
# no rating change and out of order rating: unrated
# no rating chnage and non-increasing order: maybe
| Title: Is it rated?
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Is it rated?
Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it.
Another Codeforces round has been conducted. No two participants have the same number of points. For each participant, from the top to the bottom of the standings, their rating before and after the round is known.
It's known that if at least one participant's rating has changed, then the round was rated for sure.
It's also known that if the round was rated and a participant with lower rating took a better place in the standings than a participant with higher rating, then at least one round participant's rating has changed.
In this problem, you should not make any other assumptions about the rating system.
Determine if the current round is rated, unrated, or it's impossible to determine whether it is rated of not.
Input Specification:
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=1000) — the number of round participants.
Each of the next *n* lines contains two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=4126) — the rating of the *i*-th participant before and after the round, respectively. The participants are listed in order from the top to the bottom of the standings.
Output Specification:
If the round is rated for sure, print "rated". If the round is unrated for sure, print "unrated". If it's impossible to determine whether the round is rated or not, print "maybe".
Demo Input:
['6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884\n', '4\n1500 1500\n1300 1300\n1200 1200\n1400 1400\n', '5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699\n']
Demo Output:
['rated\n', 'unrated\n', 'maybe\n']
Note:
In the first example, the ratings of the participants in the third and fifth places have changed, therefore, the round was rated.
In the second example, no one's rating has changed, but the participant in the second place has lower rating than the participant in the fourth place. Therefore, if the round was rated, someone's rating would've changed for sure.
In the third example, no one's rating has changed, and the participants took places in non-increasing order of their rating. Therefore, it's impossible to determine whether the round is rated or not. | ```python
import sys
input = sys.stdin.readline
############ ---- Input Functions ---- ############
# Int inputs
def inp():
return (int(input()))
# List inputs
def inlt():
return (list(map(int, input().split())))
# For taking string inputs. list of Chars
def insr():
s = input()
return (list(s[:len(s) - 1]))
# For taking space separated integer variable inputs.
def invr():
return (map(int, input().split()))
if __name__ == "__main__":
n = inp()
previous = 4127
maybe = True
for i in range(n):
a, b = invr()
if a != b:
print("rated")
exit()
elif a > previous:
maybe = False
previous = a
print("maybe") if maybe else print("unrated")
#three conditions:
# rating change: rated
# no rating change and out of order rating: unrated
# no rating chnage and non-increasing order: maybe
``` | 3 |
|
745 | A | Hongcow Learns the Cyclic Shift | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | Hongcow is learning to spell! One day, his teacher gives him a word that he needs to learn to spell. Being a dutiful student, he immediately learns how to spell the word.
Hongcow has decided to try to make new words from this one. He starts by taking the word he just learned how to spell, and moves the last character of the word to the beginning of the word. He calls this a cyclic shift. He can apply cyclic shift many times. For example, consecutively applying cyclic shift operation to the word "abracadabra" Hongcow will get words "aabracadabr", "raabracadab" and so on.
Hongcow is now wondering how many distinct words he can generate by doing the cyclic shift arbitrarily many times. The initial string is also counted. | The first line of input will be a single string *s* (1<=≤<=|*s*|<=≤<=50), the word Hongcow initially learns how to spell. The string *s* consists only of lowercase English letters ('a'–'z'). | Output a single integer equal to the number of distinct strings that Hongcow can obtain by applying the cyclic shift arbitrarily many times to the given string. | [
"abcd\n",
"bbb\n",
"yzyz\n"
] | [
"4\n",
"1\n",
"2\n"
] | For the first sample, the strings Hongcow can generate are "abcd", "dabc", "cdab", and "bcda".
For the second sample, no matter how many times Hongcow does the cyclic shift, Hongcow can only generate "bbb".
For the third sample, the two strings Hongcow can generate are "yzyz" and "zyzy". | 500 | [
{
"input": "abcd",
"output": "4"
},
{
"input": "bbb",
"output": "1"
},
{
"input": "yzyz",
"output": "2"
},
{
"input": "abcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxy",
"output": "25"
},
{
"input": "zclkjadoprqronzclkjadoprqronzclkjadoprqron",
"output": "14"
},
{
"input": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz",
"output": "1"
},
{
"input": "xyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxy",
"output": "2"
},
{
"input": "y",
"output": "1"
},
{
"input": "ervbfotfedpozygoumbmxeaqegouaqqzqerlykhmvxvvlcaos",
"output": "49"
},
{
"input": "zyzzzyyzyyyzyyzyzyzyzyzzzyyyzzyzyyzzzzzyyyzzzzyzyy",
"output": "50"
},
{
"input": "zzfyftdezzfyftdezzfyftdezzfyftdezzfyftdezzfyftde",
"output": "8"
},
{
"input": "yehcqdlllqpuxdsaicyjjxiylahgxbygmsopjbxhtimzkashs",
"output": "49"
},
{
"input": "yyyyzzzyzzzyzyzyzyyyyyzzyzyzyyyyyzyzyyyzyzzyyzzzz",
"output": "49"
},
{
"input": "zkqcrhzlzsnwzkqcrhzlzsnwzkqcrhzlzsnwzkqcrhzlzsnw",
"output": "12"
},
{
"input": "xxyxxyxxyxxyxxyxxyxxyxxyxxyxxyxxyxxyxxyxxyxxyxxy",
"output": "3"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaab",
"output": "25"
},
{
"input": "aabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaaba",
"output": "4"
},
{
"input": "pqqpqqpqqpqqpqqpqqpqqpqqpqqpqqpqqppqppqppqppqppq",
"output": "48"
},
{
"input": "zxkljaqzxkljaqzxkljaqzxkljaqzxrljaqzxkljaqzxkljaq",
"output": "49"
},
{
"input": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwx",
"output": "50"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz",
"output": "50"
},
{
"input": "abcddcba",
"output": "8"
},
{
"input": "aabaabaabaacaabaabaabaacaabaabaabaacaabaabaabaac",
"output": "12"
},
{
"input": "aabaabcaabaabcdaabaabcaabaabcd",
"output": "15"
},
{
"input": "ababaababaaababaababaaaababaababaaababaababaaaa",
"output": "47"
},
{
"input": "ababaababaaababaababaaaababaababaaababaababaaa",
"output": "23"
},
{
"input": "aaababaab",
"output": "9"
},
{
"input": "aba",
"output": "3"
}
] | 1,543,395,479 | 2,147,483,647 | Python 3 | OK | TESTS | 28 | 124 | 0 | x=input()
time=1
x=list(x)
j=str(x)
v=x[len(x)-1]
while True:
v=x[len(x)-1]
q=1
z=2
while z<=len(x):
x[len(x)-q]=x[len(x)-z]
q+=1
z+=1
x[0]=v
if str(x)==j:
break
else:
time+=1
print(time)
| Title: Hongcow Learns the Cyclic Shift
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Hongcow is learning to spell! One day, his teacher gives him a word that he needs to learn to spell. Being a dutiful student, he immediately learns how to spell the word.
Hongcow has decided to try to make new words from this one. He starts by taking the word he just learned how to spell, and moves the last character of the word to the beginning of the word. He calls this a cyclic shift. He can apply cyclic shift many times. For example, consecutively applying cyclic shift operation to the word "abracadabra" Hongcow will get words "aabracadabr", "raabracadab" and so on.
Hongcow is now wondering how many distinct words he can generate by doing the cyclic shift arbitrarily many times. The initial string is also counted.
Input Specification:
The first line of input will be a single string *s* (1<=≤<=|*s*|<=≤<=50), the word Hongcow initially learns how to spell. The string *s* consists only of lowercase English letters ('a'–'z').
Output Specification:
Output a single integer equal to the number of distinct strings that Hongcow can obtain by applying the cyclic shift arbitrarily many times to the given string.
Demo Input:
['abcd\n', 'bbb\n', 'yzyz\n']
Demo Output:
['4\n', '1\n', '2\n']
Note:
For the first sample, the strings Hongcow can generate are "abcd", "dabc", "cdab", and "bcda".
For the second sample, no matter how many times Hongcow does the cyclic shift, Hongcow can only generate "bbb".
For the third sample, the two strings Hongcow can generate are "yzyz" and "zyzy". | ```python
x=input()
time=1
x=list(x)
j=str(x)
v=x[len(x)-1]
while True:
v=x[len(x)-1]
q=1
z=2
while z<=len(x):
x[len(x)-q]=x[len(x)-z]
q+=1
z+=1
x[0]=v
if str(x)==j:
break
else:
time+=1
print(time)
``` | 3 |
|
0 | none | none | none | 0 | [
"none"
] | null | null | This is the modification of the problem used during the official round. Unfortunately, author's solution of the original problem appeared wrong, so the problem was changed specially for the archive.
Once upon a time in a far away kingdom lived the King. The King had a beautiful daughter, Victoria. They lived happily, but not happily ever after: one day a vicious dragon attacked the kingdom and stole Victoria. The King was full of grief, yet he gathered his noble knights and promised half of his kingdom and Victoria's hand in marriage to the one who will save the girl from the infernal beast.
Having travelled for some time, the knights found the dragon's lair and all of them rushed there to save Victoria. Each knight spat on the dragon once and, as the dragon had quite a fragile and frail heart, his heart broke and poor beast died. As for the noble knights, they got Victoria right to the King and started brawling as each one wanted the girl's hand in marriage.
The problem was that all the noble knights were equally noble and equally handsome, and Victoria didn't want to marry any of them anyway. Then the King (and he was a very wise man and didn't want to hurt anybody's feelings) decided to find out who will get his daughter randomly, i.e. tossing a coin. However, there turned out to be *n* noble knights and the coin only has two sides. The good thing is that when a coin is tossed, the coin falls on each side with equal probability. The King got interested how to pick one noble knight using this coin so that all knights had equal probability of being chosen (the probability in that case should always be equal to 1<=/<=*n*). First the King wants to know the expected number of times he will need to toss a coin to determine the winner. Besides, while tossing the coin, the King should follow the optimal tossing strategy (i.e. the strategy that minimizes the expected number of tosses). Help the King in this challenging task. | The first line contains a single integer *n* from the problem's statement (1<=≤<=*n*<=≤<=10000). | Print the sought expected number of tosses as an irreducible fraction in the following form: "*a*/*b*" (without the quotes) without leading zeroes. | [
"2\n",
"3\n",
"4\n"
] | [
"1/1\n",
"8/3\n",
"2/1\n"
] | none | 0 | [
{
"input": "2",
"output": "1/1"
},
{
"input": "3",
"output": "8/3"
},
{
"input": "4",
"output": "2/1"
},
{
"input": "8",
"output": "3/1"
},
{
"input": "7",
"output": "24/7"
},
{
"input": "6",
"output": "11/3"
},
{
"input": "1",
"output": "0/1"
},
{
"input": "5",
"output": "18/5"
},
{
"input": "96",
"output": "23/3"
},
{
"input": "54",
"output": "377/57"
},
{
"input": "49",
"output": "1985714/299593"
},
{
"input": "57",
"output": "1118/171"
},
{
"input": "21",
"output": "38/7"
},
{
"input": "43",
"output": "896/129"
},
{
"input": "56",
"output": "45/7"
},
{
"input": "46",
"output": "13719/2047"
},
{
"input": "91",
"output": "704/91"
},
{
"input": "13",
"output": "306/65"
},
{
"input": "82",
"output": "7739/1025"
},
{
"input": "69",
"output": "32740246/4194303"
},
{
"input": "77",
"output": "8215881550/1073741823"
},
{
"input": "27",
"output": "320/57"
},
{
"input": "63",
"output": "128/21"
},
{
"input": "60",
"output": "94/15"
},
{
"input": "42",
"output": "45/7"
},
{
"input": "29",
"output": "89074/16385"
},
{
"input": "99",
"output": "82792/10923"
},
{
"input": "19",
"output": "2936/513"
},
{
"input": "89",
"output": "15942/2047"
},
{
"input": "356",
"output": "20036/2047"
},
{
"input": "377",
"output": "42877948701338/4398046511105"
},
{
"input": "376",
"output": "81794781/8388607"
},
{
"input": "199",
"output": "5416016912792671923933831206744/633825300114114700748351602687"
},
{
"input": "563",
"output": "13880251801665520090148870069821814422429790384486504048582895486382118580803670864520/1295112594817152713946307937882345937761604559368093014167874939825936190136805665451"
},
{
"input": "768",
"output": "32/3"
},
{
"input": "777",
"output": "242912325346/22906492245"
},
{
"input": "721",
"output": "24323770714557246/2251799813685247"
},
{
"input": "629",
"output": "49843473149688266962934/4722366482869645213695"
},
{
"input": "589",
"output": "13383001136884230836493585742/1237940039285380274899124223"
},
{
"input": "698",
"output": "261084475895343697268604849722313704014143081638278003/23945242826029513411849172299223580994042798784118785"
},
{
"input": "897",
"output": "6303910445469575479185224346195379698702/604946430081668379490443746545365709255"
},
{
"input": "100",
"output": "1548/205"
},
{
"input": "898",
"output": "54181807382553033285317903788494851/5192296858534827628530496329220097"
},
{
"input": "778",
"output": "266081190240146347461776796003542832080357458393960689731819/25108406941546723055343157692830665664409421777856138051585"
},
{
"input": "408",
"output": "481/51"
},
{
"input": "915",
"output": "24489920882263416/2329134352741105"
},
{
"input": "659",
"output": "11506864999305980525685467247724160971763964558240405270397991163704744844086671519176045618744739064/1093625362391505962186251113558810682676584715446606218212885303204976499599687961611756588511526913"
},
{
"input": "380",
"output": "17089848754/1762037865"
},
{
"input": "826",
"output": "28584112877549284603281069376719144007233968270323045/2660582536225501490205463588802620110449199864902087"
},
{
"input": "570",
"output": "81780152549/7635497415"
},
{
"input": "8947",
"output": "9221776965061394108063074537665193339719130234791259353035383369908276748232005329587397633526133839630977366288410166284245740877083371222474025826991630911939336371916388075479778450420492837649418370715068725438291562232309367997828789596177392059429297899551357796421577750411209045517378683903876507895356659650107620108241824167563644901510340265372019179673453724120802026261156279978925379653814720997930734349648232984115741566886698873835913569553263892609588155620638724704727598288959685621550249737..."
},
{
"input": "5379",
"output": "369970662679510300707473720654925140999880897391589444623141436368705516892112173326991585567498714963884175295883677699016/27543998699593691622996471168032126659516861790178384136860366469766907968179639409382883768321470201982967167709306596011"
},
{
"input": "2614",
"output": "467288820759363880397722656040592964020719930972683440703193351374700405080631777580381050558531644513848619882285655907104502715940077345333622944378242416293600447930921066507506568704500773773633/37375513539561023231108477793896786533525327931380202951304745106630862169773485150256437750311906506986637800026885384689161869077507588081685801531164378630160340372359290471078905382884178132993"
},
{
"input": "6212",
"output": "718828780749497450032379379564/52818775009509558395695966891"
},
{
"input": "3586",
"output": "1026714465140783036738474632330359205383783819874722347437634384119469704928190591460057095203615899196742515080053210107395/82631996098781074868989413504096379978550585370535152410581099409300723904538918228148651304964410605948901503127919788033"
},
{
"input": "6629",
"output": "2887307659130237302642554273423838808127851411579740408603950850448329124209429578113205979182558694432261838498919298006073282090488747091133824076367223385537560048772408256051559991222428913480943619030448796454451464748405569577077070495809049315150455270612613741854545427076463694803465943631755282225609026765330663439059215627258266275926212560658364641003632351846514061002732653254081394744335331237509798266695411546509090369792904212760685221160746857281893822469878668200610823671894328098385881817..."
},
{
"input": "9861",
"output": "48205401549715737511233606679265031152996036546952288925330285615396586708825956490117819026249283326464870369563186432330830706792989284262067110327971987394928549360770263191516012692848869076552182149927367930957872055698792311482405327082065553619653685393875355497796244989262571944371234203749880818792381890143341459002264984197001955297069409069640536538793687219440766877509028035223421720178766484630650779161811795215598122460003343408475412680746717692338/3290879900222849827608052539430658202162644..."
},
{
"input": "1649",
"output": "1103258059369546/93824992236885"
},
{
"input": "1108",
"output": "829108303866668/70368744177665"
},
{
"input": "6704",
"output": "3747509385261755254210316751920800389821077334621726013635892116/274250759553534340359161530426225084163789310938929977224768171"
},
{
"input": "8771",
"output": "3770311067804988086442280897982793233953991174834038671591744622664235928848771481024534828492198884087581040596792755307166862630362254070801530083149662062951269890316117808935983174156710048296936374305714276676638609402088826404322038255398708095256451326373150897864019805504212731596330281332804357336587199175247125958363190591680678576959242590696722761770737808874948948372052533640442104091203823298252400438183921494229420351844306480773904754871502489649028646657382266084070860349033005494965904934..."
},
{
"input": "4710",
"output": "62214231544449127/4503599627370495"
},
{
"input": "2337",
"output": "6429067313146769086191243390708972817399071295570593226/510831846955296286119449009050103061206246374061200725"
},
{
"input": "7708",
"output": "39413297508974631726391031213171923271142554912679270458193728426423636026646334915727139650713682692479792411879633606353758285856351703126/2977131414714805823690030317109266572712515013375254774912983855843898524112477893944078543723575564536883288499266264815757728270805630975"
},
{
"input": "5484",
"output": "211086977989859276474150/15111572745182864683827"
},
{
"input": "2050",
"output": "2663/205"
},
{
"input": "5157",
"output": "1244202699616577925257908854992502879105187462860652753500143979369064245723363816152901984642185318105227079924186855121298620779636669909099525176016720566980036738379840484201060840762226140891649195248344160034243456960969500434409559402400997785076262368243485151264623913446406300409714366263836544017408112602389622392168343772273329588989257854547075621647134412375571624421845467345018113608142941220069412256286427238705568845394057266549279844034564540504288723831871872613761385100219013571797574528..."
},
{
"input": "9556",
"output": "61105610582596188064013632976018238169594847263124154642386689594807697097885447064570207703083797375229286491941164437689434529990291086697099939303795410031817348526076989232509267027565641811597218817018817025267674646870116016782259903322684685324891049798873702815116504349778081974046190242424181610803910534907237209386333892868457625884598750479036332/4139057561631190052420042715397268145091328063809781231185874234711716512317727312355164552220203407039993009382683073987640607521830928131007598529502..."
},
{
"input": "7901",
"output": "1545248712235484231234951857976545065744617617020030658469109057466859986475148250693905886674893272489053581743278765525029576600572532534838775161015285299867097071351763023768221772211614326132946083723216283578235838641012739144142278748089419497887052400481010672846336748523045688232788476455926025596760805229671163941642019404158795532714920358340283273984860096000931574655035232114889550219531272686479161110317036826198314000803468166009351225032738229182153921483640756378743625620038865132469106047..."
},
{
"input": "8622",
"output": "2346970612497798292051684863778787677688918498337895665035233783242368128286257851467636458012981817792946447606933694463959158768680516918810044760234529638520868683195790661167605124671831213269266007988150361676380026247303195939614144448935172977317349504257500667344413574778276538084533093523373859439640543406392557232735743996270882880554311714917225257533788072187384837827098726745502145040757646538864148126423442625937245/15845010358053163603682882776020046370855826407419789577061413023873354878758..."
},
{
"input": "16",
"output": "4/1"
},
{
"input": "32",
"output": "5/1"
},
{
"input": "64",
"output": "6/1"
},
{
"input": "128",
"output": "7/1"
},
{
"input": "256",
"output": "8/1"
},
{
"input": "512",
"output": "9/1"
},
{
"input": "1024",
"output": "10/1"
},
{
"input": "2048",
"output": "11/1"
},
{
"input": "4096",
"output": "12/1"
},
{
"input": "8192",
"output": "13/1"
},
{
"input": "9749",
"output": "2442073850489536993602927585016307199165621395304075025177694875024679607796284569131767726963170591399402108675638309823508923120869023271471818205166195909414421298770225330343221707377312426015931814666620011704161259290684411521150904067521292013955185317667861253504565429204675752674949251324122812583751343895693341865871684651273036507250959013187746544944138162398891218537343348931977619498001506833868902121065893913936425349903046456157409756042496452120477911621545767772676861905004685673876448424..."
},
{
"input": "9803",
"output": "3273210180788326072665779956874407303695209430301336271835983946088930098968971592446649088493870209185601637297946849124915345946101994703881396454817629317067995483358046696632270413949397783371061147815617923539634120806955265009854911188530306501324761896490486400736980978270851173985761450205468514371802366150508965142349402634775190541932571215772934087049601511151015580218962449832712507548850463067009640345032653747650848021793733486635063672276271184797891474270402353352104959589784879937226619631..."
},
{
"input": "9851",
"output": "1826526826552054078590833159938859608660168689393622926697593614966325247523385486843148169222905802492343158938765988786790268008018346250425185590729454696317705467641275241528094330016670372495410419378141651879792828682641532533284092879418090040903735626785107378204659838740412715571880884453837366724444432895654221478996531206045405344762139424591887085118650734474741760565377558510969213435666224432175984910232854534478442066899535808519463012771143160247271088007881997468588868391395961360449311260..."
},
{
"input": "9859",
"output": "9737556487585955271085725726347548524587201515015415940974212696477918276264308244608931996051014559947727871548525843984646030062506833242765111803441650144268637762679345636011358150115775908768896005580214321628703868435548404239676226435996040392670484414990942576376634145721680636769353606720643265107519869112758891642047680407647874665865802380346668006876206490814588938569751811311435939234659864088396761136789798899162439354805109166450795279173094212597156554710639295669120966978022955523520243885..."
},
{
"input": "9883",
"output": "3585169013008320587733453934540655406968508071250655174069676351966247095891666666457951370861261022535907218197677774600785190516321049571099175528120462561383326438548822604717683501452327840790897918994708328294710567693091965543331903184071652577937298158191755916197924842106107578819028940776121678861464188820255086932973183740793372165945865009415954786595728774195980645745127346052687115724325004061229398519190748075580806663121266449693574278118081790297078495193488775980028423355059820522243653725..."
},
{
"input": "9901",
"output": "1838099364825091485842998238489502638352163208605775246129613825541675258139803932850287467779059152113767067936585018625986257156889365449198856216156597215096982506298229063072584364817360767528951048690402306736891920567120457283597208730483707878597646111737127186752299112571526574444743928839110241560725998077538870670908652964981237795923920133705668072188172055098674658571105524472734987571439013958589827622877679807533101349696441175687163721291688130495577638100992957486490904022264860238167307326..."
},
{
"input": "9907",
"output": "1633354865670482634892575473274177878269848372373759525765811325846788929611278968402771127221384695483915945198456285004476851582174958025985911899376499975337986661537173411180428490907671107896805361798951388912266345066652077866312114944286489782939084013056891167373799137114155515056010000276816186615290579398553645497061457349859874907706345855178899820840538136570385474191197090563464515778875629438803382571649568677198891486414476226932831825123576296441036124053704853315256369077062694497961110434..."
},
{
"input": "9923",
"output": "3760299283807515305392881669921685380087483626665387583310740045779392618490518061864438198412014466565364228291295311284131760183238506480296641521584717001189575119537493891940454933801650905249443352246953782854872613017048635048443614120554701976326536039594670095564945312513189153593550500517921950184962024588992584781239533465993501341159180970745350678104403343694528834994019085606787711931776684194936418570665879951352474415566347678136222813280481902061127946763865268688300550988394467968839427831..."
},
{
"input": "9941",
"output": "3848534499658219667049727329663074105337547166730018729906447543650907057565599099052599064685569838374730308744072576703962547115876952975258439787965733453851059665347937329225608515273601271650034928543860491219634012020498814661622840677950496926059282612940876829862296013101963794076610277533664472961283348371953697283523069103642217248197905842345904997732309684469494496541394358109215746512001993248263898375663673449385592381926788206401567212276907962968353724108187030299614264372186122509235461661..."
},
{
"input": "9949",
"output": "3077194576897431282984928614971803243979867746742349396701033435828399498432602651550466130139454008014151230282733882472359320178948173983098259522962570058314958623895543103765377873930945767189012935127692368514283490255979891724625021542152152743761996609145171758487359833408232379642800156557718632212879833607371512214716299467380836645557808645986902660996771461355482482475905883289978390754379236092379144196172866264243566348794250784667125654370098361595124994920872496780086986738805458903185126030..."
},
{
"input": "9991",
"output": "6382125632197575640171909108366323999672572433833222272392411654952806480364944179628596547334889065794512754663260535014179926913634410060297543083266944529654281991142775738499030710183320227853166673816892482763220210176769895648821886542105816/436994993873214129706097166956708350993678881411295357199729151951767944417616335439228580716318181998128654620651240845861768505204366709906692902245553277900892247131030458103436298545516643924637451297481464347472084863384057367177715867713535"
},
{
"input": "9992",
"output": "882713207347291313029281/60446290980731458735309"
},
{
"input": "9993",
"output": "12637244675354581352253260560857374/865382809755804604755082721536683"
},
{
"input": "9994",
"output": "3281117414508879498426129146296635638706673857559146714758804687655977321336441892014774756310161571021964653093136031059973674988535235552194295743721563055893425769046817776696216427896857321525164709814889404834572227298884316348149960471145881924249349826195785903333523568245055998853462086046866400139120072781311401680748431799894049040989328677849586317964939112513229643421712863477114408475285877161526889717094721450283390765651073229738491488236723709404792790505935059388430226031866694290751309103..."
},
{
"input": "9995",
"output": "1368770541403820619075110203708490210616145992745821521870208914365828115565556194877572535511077690510688277376757546565243584175363368143317667278940670502781186329534839008398699279841764334491329910860701074569229951248069967340109056226002539889667430100999595433067983400778886042165596127864919572486395941238704720403024794261441096255620000217687954366591408789194462597191661175824028310400352/93746319107175952683864071964918454730461746778024627464635174121600584812748548703282543376385452193806936..."
},
{
"input": "9996",
"output": "2016420396858486097238844042485568452071214924046/138111634978483258420134114867245645268334710595"
},
{
"input": "9997",
"output": "115045178372494165897872226686512107429178048300340407805913417043457084371526821355671616896548808082243735275331446/7880401239278895842455808020028722761015947854093089333589658680849144354299442122282853250976983128161325598061363"
},
{
"input": "9998",
"output": "4285402091468445389426164244750423198106729816197961669529078982307315890678968433526215498100171962888335447/293567822846729153486185074598667128421960318613539983838411371441526128139326055432962374798096087878991871"
},
{
"input": "9999",
"output": "396504919788033353440140876437127916065460257739670266843919813860579129943101204509709504/27160479684459814483579275845458375480686245248879150008481872658058417330177822749111965"
},
{
"input": "10000",
"output": "211285126026764324876224334024814529251789998319439411297242149907456038558/14474011154664524427946373126085988481658748083205070504932198000989141205"
}
] | 1,691,833,868 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | print("_RANDOM_GUESS_1691833868.8176138")# 1691833868.81763 | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This is the modification of the problem used during the official round. Unfortunately, author's solution of the original problem appeared wrong, so the problem was changed specially for the archive.
Once upon a time in a far away kingdom lived the King. The King had a beautiful daughter, Victoria. They lived happily, but not happily ever after: one day a vicious dragon attacked the kingdom and stole Victoria. The King was full of grief, yet he gathered his noble knights and promised half of his kingdom and Victoria's hand in marriage to the one who will save the girl from the infernal beast.
Having travelled for some time, the knights found the dragon's lair and all of them rushed there to save Victoria. Each knight spat on the dragon once and, as the dragon had quite a fragile and frail heart, his heart broke and poor beast died. As for the noble knights, they got Victoria right to the King and started brawling as each one wanted the girl's hand in marriage.
The problem was that all the noble knights were equally noble and equally handsome, and Victoria didn't want to marry any of them anyway. Then the King (and he was a very wise man and didn't want to hurt anybody's feelings) decided to find out who will get his daughter randomly, i.e. tossing a coin. However, there turned out to be *n* noble knights and the coin only has two sides. The good thing is that when a coin is tossed, the coin falls on each side with equal probability. The King got interested how to pick one noble knight using this coin so that all knights had equal probability of being chosen (the probability in that case should always be equal to 1<=/<=*n*). First the King wants to know the expected number of times he will need to toss a coin to determine the winner. Besides, while tossing the coin, the King should follow the optimal tossing strategy (i.e. the strategy that minimizes the expected number of tosses). Help the King in this challenging task.
Input Specification:
The first line contains a single integer *n* from the problem's statement (1<=≤<=*n*<=≤<=10000).
Output Specification:
Print the sought expected number of tosses as an irreducible fraction in the following form: "*a*/*b*" (without the quotes) without leading zeroes.
Demo Input:
['2\n', '3\n', '4\n']
Demo Output:
['1/1\n', '8/3\n', '2/1\n']
Note:
none | ```python
print("_RANDOM_GUESS_1691833868.8176138")# 1691833868.81763
``` | 0 |
|
714 | A | Meeting of Old Friends | PROGRAMMING | 1,100 | [
"implementation",
"math"
] | null | null | Today an outstanding event is going to happen in the forest — hedgehog Filya will come to his old fried Sonya!
Sonya is an owl and she sleeps during the day and stay awake from minute *l*1 to minute *r*1 inclusive. Also, during the minute *k* she prinks and is unavailable for Filya.
Filya works a lot and he plans to visit Sonya from minute *l*2 to minute *r*2 inclusive.
Calculate the number of minutes they will be able to spend together. | The only line of the input contains integers *l*1, *r*1, *l*2, *r*2 and *k* (1<=≤<=*l*1,<=*r*1,<=*l*2,<=*r*2,<=*k*<=≤<=1018, *l*1<=≤<=*r*1, *l*2<=≤<=*r*2), providing the segments of time for Sonya and Filya and the moment of time when Sonya prinks. | Print one integer — the number of minutes Sonya and Filya will be able to spend together. | [
"1 10 9 20 1\n",
"1 100 50 200 75\n"
] | [
"2\n",
"50\n"
] | In the first sample, they will be together during minutes 9 and 10.
In the second sample, they will be together from minute 50 to minute 74 and from minute 76 to minute 100. | 500 | [
{
"input": "1 10 9 20 1",
"output": "2"
},
{
"input": "1 100 50 200 75",
"output": "50"
},
{
"input": "6 6 5 8 9",
"output": "1"
},
{
"input": "1 1000000000 1 1000000000 1",
"output": "999999999"
},
{
"input": "5 100 8 8 8",
"output": "0"
},
{
"input": "1 1000000000000000000 2 99999999999999999 1000000000",
"output": "99999999999999997"
},
{
"input": "1 1 1 1 1",
"output": "0"
},
{
"input": "1 2 3 4 5",
"output": "0"
},
{
"input": "1 1000000000 2 999999999 3141592",
"output": "999999997"
},
{
"input": "24648817341102 41165114064236 88046848035 13602161452932 10000831349205",
"output": "0"
},
{
"input": "1080184299348 34666828555290 6878390132365 39891656267344 15395310291636",
"output": "27788438422925"
},
{
"input": "11814 27385 22309 28354 23595",
"output": "5076"
},
{
"input": "4722316546398 36672578279675 796716437180 33840047334985 13411035401708",
"output": "29117730788587"
},
{
"input": "14300093617438 14381698008501 6957847034861 32510754974307 66056597033082",
"output": "81604391064"
},
{
"input": "700062402405871919 762322967106512617 297732773882447821 747309903322652819 805776739998108178",
"output": "47247500916780901"
},
{
"input": "59861796371397621 194872039092923459 668110259718450585 841148673332698972 928360292123223779",
"output": "0"
},
{
"input": "298248781360904821 346420922793050061 237084570581741798 726877079564549183 389611850470532358",
"output": "48172141432145241"
},
{
"input": "420745791717606818 864206437350900994 764928840030524015 966634105370748487 793326512080703489",
"output": "99277597320376979"
},
{
"input": "519325240668210886 776112702001665034 360568516809443669 875594219634943179 994594983925273138",
"output": "256787461333454149"
},
{
"input": "170331212821058551 891149660635282032 125964175621755330 208256491683509799 526532153531983174",
"output": "37925278862451249"
},
{
"input": "1 3 3 5 3",
"output": "0"
},
{
"input": "1 5 8 10 9",
"output": "0"
},
{
"input": "1 2 4 5 10",
"output": "0"
},
{
"input": "1 2 2 3 5",
"output": "1"
},
{
"input": "2 4 3 7 3",
"output": "1"
},
{
"input": "1 2 9 10 1",
"output": "0"
},
{
"input": "5 15 1 10 5",
"output": "5"
},
{
"input": "1 4 9 20 25",
"output": "0"
},
{
"input": "2 4 1 2 5",
"output": "1"
},
{
"input": "10 1000 1 100 2",
"output": "91"
},
{
"input": "1 3 3 8 10",
"output": "1"
},
{
"input": "4 6 6 8 9",
"output": "1"
},
{
"input": "2 3 1 4 3",
"output": "1"
},
{
"input": "1 2 2 3 100",
"output": "1"
},
{
"input": "1 2 100 120 2",
"output": "0"
},
{
"input": "1 3 5 7 4",
"output": "0"
},
{
"input": "1 3 5 7 5",
"output": "0"
},
{
"input": "1 4 8 10 6",
"output": "0"
},
{
"input": "1 2 5 6 100",
"output": "0"
},
{
"input": "1 2 5 10 20",
"output": "0"
},
{
"input": "1 2 5 6 7",
"output": "0"
},
{
"input": "2 5 7 12 6",
"output": "0"
},
{
"input": "10 20 50 100 80",
"output": "0"
},
{
"input": "1 2 5 10 2",
"output": "0"
},
{
"input": "1 2 5 6 4",
"output": "0"
},
{
"input": "5 9 1 2 3",
"output": "0"
},
{
"input": "50 100 1 20 3",
"output": "0"
},
{
"input": "10 20 3 7 30",
"output": "0"
},
{
"input": "1 5 10 10 100",
"output": "0"
},
{
"input": "100 101 1 2 3",
"output": "0"
},
{
"input": "1 5 10 20 6",
"output": "0"
},
{
"input": "1 10 15 25 5",
"output": "0"
},
{
"input": "1 2 5 10 3",
"output": "0"
},
{
"input": "2 3 5 6 100",
"output": "0"
},
{
"input": "1 2 4 5 6",
"output": "0"
},
{
"input": "6 10 1 2 40",
"output": "0"
},
{
"input": "20 30 1 5 1",
"output": "0"
},
{
"input": "20 40 50 100 50",
"output": "0"
},
{
"input": "1 1 4 9 2",
"output": "0"
},
{
"input": "1 2 5 6 1",
"output": "0"
},
{
"input": "1 100 400 500 450",
"output": "0"
},
{
"input": "5 6 1 2 5",
"output": "0"
},
{
"input": "1 10 21 30 50",
"output": "0"
},
{
"input": "100 200 300 400 101",
"output": "0"
},
{
"input": "2 8 12 16 9",
"output": "0"
},
{
"input": "1 5 7 9 6",
"output": "0"
},
{
"input": "300 400 100 200 101",
"output": "0"
},
{
"input": "1 2 2 3 10",
"output": "1"
},
{
"input": "1 10 100 200 5",
"output": "0"
},
{
"input": "1 3 3 4 4",
"output": "1"
},
{
"input": "10 20 30 40 25",
"output": "0"
},
{
"input": "1 2 5 10 1",
"output": "0"
},
{
"input": "2 4 8 10 1",
"output": "0"
},
{
"input": "2 5 10 15 7",
"output": "0"
},
{
"input": "100 200 5 10 1",
"output": "0"
},
{
"input": "1 2 100 200 300",
"output": "0"
},
{
"input": "30 100 10 20 25",
"output": "0"
},
{
"input": "10 20 1 5 6",
"output": "0"
},
{
"input": "4 5 1 2 4",
"output": "0"
},
{
"input": "11 100 1 9 1000",
"output": "0"
},
{
"input": "1 1 10 10 228",
"output": "0"
},
{
"input": "5 7 10 20 15",
"output": "0"
},
{
"input": "1 3 8 9 7",
"output": "0"
},
{
"input": "1 10 2 8 8",
"output": "6"
},
{
"input": "1 5 9 15 1",
"output": "0"
},
{
"input": "1 3 5 6 12",
"output": "0"
},
{
"input": "1 100 500 1000 3",
"output": "0"
},
{
"input": "1 1 1 1 2",
"output": "1"
},
{
"input": "1 1000 100 1000 200",
"output": "900"
},
{
"input": "4 5 1 4 1",
"output": "1"
},
{
"input": "1 5 5 7 3",
"output": "1"
},
{
"input": "1 4 4 10 11",
"output": "1"
},
{
"input": "1 1 3 4 100",
"output": "0"
},
{
"input": "1 4 3 5 6",
"output": "2"
},
{
"input": "10 100 20 30 40",
"output": "11"
},
{
"input": "5 9 1 11 7",
"output": "4"
}
] | 1,627,914,071 | 2,147,483,647 | PyPy 3 | OK | TESTS | 96 | 343 | 31,948,800 | # author: ankan2526
import math, bisect, heapq, random, sys, itertools
input=sys.stdin.readline
ints = lambda : list(map(int,input().split()))
p = 10**9+7
l1,r1,l2,r2,k=ints()
l=max(l1,l2)
r=min(r1,r2)
if l>r:
print(0)
else:
ans=r-l+1
if l<=k<=r:
ans-=1
print(ans) | Title: Meeting of Old Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today an outstanding event is going to happen in the forest — hedgehog Filya will come to his old fried Sonya!
Sonya is an owl and she sleeps during the day and stay awake from minute *l*1 to minute *r*1 inclusive. Also, during the minute *k* she prinks and is unavailable for Filya.
Filya works a lot and he plans to visit Sonya from minute *l*2 to minute *r*2 inclusive.
Calculate the number of minutes they will be able to spend together.
Input Specification:
The only line of the input contains integers *l*1, *r*1, *l*2, *r*2 and *k* (1<=≤<=*l*1,<=*r*1,<=*l*2,<=*r*2,<=*k*<=≤<=1018, *l*1<=≤<=*r*1, *l*2<=≤<=*r*2), providing the segments of time for Sonya and Filya and the moment of time when Sonya prinks.
Output Specification:
Print one integer — the number of minutes Sonya and Filya will be able to spend together.
Demo Input:
['1 10 9 20 1\n', '1 100 50 200 75\n']
Demo Output:
['2\n', '50\n']
Note:
In the first sample, they will be together during minutes 9 and 10.
In the second sample, they will be together from minute 50 to minute 74 and from minute 76 to minute 100. | ```python
# author: ankan2526
import math, bisect, heapq, random, sys, itertools
input=sys.stdin.readline
ints = lambda : list(map(int,input().split()))
p = 10**9+7
l1,r1,l2,r2,k=ints()
l=max(l1,l2)
r=min(r1,r2)
if l>r:
print(0)
else:
ans=r-l+1
if l<=k<=r:
ans-=1
print(ans)
``` | 3 |
|
474 | A | Keyboard | PROGRAMMING | 900 | [
"implementation"
] | null | null | Our good friend Mole is trying to code a big message. He is typing on an unusual keyboard with characters arranged in following way:
Unfortunately Mole is blind, so sometimes it is problem for him to put his hands accurately. He accidentally moved both his hands with one position to the left or to the right. That means that now he presses not a button he wants, but one neighboring button (left or right, as specified in input).
We have a sequence of characters he has typed and we want to find the original message. | First line of the input contains one letter describing direction of shifting ('L' or 'R' respectively for left or right).
Second line contains a sequence of characters written by Mole. The size of this sequence will be no more than 100. Sequence contains only symbols that appear on Mole's keyboard. It doesn't contain spaces as there is no space on Mole's keyboard.
It is guaranteed that even though Mole hands are moved, he is still pressing buttons on keyboard and not hitting outside it. | Print a line that contains the original message. | [
"R\ns;;upimrrfod;pbr\n"
] | [
"allyouneedislove\n"
] | none | 500 | [
{
"input": "R\ns;;upimrrfod;pbr",
"output": "allyouneedislove"
},
{
"input": "R\nwertyuiop;lkjhgfdsxcvbnm,.",
"output": "qwertyuiolkjhgfdsazxcvbnm,"
},
{
"input": "L\nzxcvbnm,kjhgfdsaqwertyuio",
"output": "xcvbnm,.lkjhgfdswertyuiop"
},
{
"input": "R\nbubbuduppudup",
"output": "vyvvysyooysyo"
},
{
"input": "L\ngggggggggggggggggggggggggggggggggggggggggg",
"output": "hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh"
},
{
"input": "R\ngggggggggggggggggggggggggggggggggggggggggg",
"output": "ffffffffffffffffffffffffffffffffffffffffff"
},
{
"input": "L\nggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg",
"output": "hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh"
},
{
"input": "R\nggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg",
"output": "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
},
{
"input": "L\nxgwurenkxkiau,c,vonei.zltazmnkhqtwuogkgvgckvja,z.rhanuy.ybebmzcfwozkwvuuiolaqlgvvvewnbuinrncgjwjdsfw",
"output": "cheitrmlclosi.v.bpmro/x;ysx,mljwyeiphlhbhvlbks.x/tjsmiu/unrn,xvgepxlebiiop;sw;hbbbremniomtmvhkekfdge"
},
{
"input": "L\nuoz.vmks,wxrb,nwcvdzh.m,hwsios.lvu,ktes,,ythddhm.sh,d,c,cfj.wqam,bowofbyx,jathqayhreqvixvbmgdokofmym",
"output": "ipx/b,ld.ectn.mevbfxj/,.jedopd/;bi.lyrd..uyjffj,/dj.f.v.vgk/ews,.npepgnuc.ksyjwsujtrwbocbn,hfplpg,u,"
},
{
"input": "R\noedjyrvuw/rn.v.hdwndbiposiewgsn.pnyf;/tsdohp,hrtd/mx,;coj./billd..mwbneohcikrdes/ucjr,wspthleyp,..f,",
"output": "iwshtecyq.eb,c,gsqbsvuoiauwqfab,obtdl.rasigomgers.nzmlxih,.vukks,,nqvbwigxujeswa.yxhemqaorgkwtom,,dm"
},
{
"input": "R\nvgj;o;ijrtfyck,dthccioltcx,crub;oceooognsuvfx/kgo.fbsudv,yod.erdrxhbeiyltxhnrobbb;ydrgroefcr/f;uvdjd",
"output": "cfhliluherdtxjmsrgxxuikrxzmxeyvlixwiiifbaycdz.jfi,dvayscmtis,wesezgvwutkrzgbeivvvltsefeiwdxe.dlycshs"
},
{
"input": "L\nqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq",
"output": "wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww"
},
{
"input": "L\noooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo",
"output": "pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp"
},
{
"input": "L\n,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,",
"output": "...................................................................................................."
},
{
"input": "L\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz",
"output": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
},
{
"input": "R\noooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo",
"output": "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii"
},
{
"input": "R\nwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww",
"output": "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq"
},
{
"input": "R\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"output": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
},
{
"input": "L\nq",
"output": "w"
},
{
"input": "L\no",
"output": "p"
},
{
"input": "L\n,",
"output": "."
},
{
"input": "L\nz",
"output": "x"
},
{
"input": "R\n.",
"output": ","
},
{
"input": "R\no",
"output": "i"
},
{
"input": "R\nw",
"output": "q"
},
{
"input": "R\nx",
"output": "z"
},
{
"input": "R\n,./",
"output": "m,."
},
{
"input": "R\nwertuk;;/",
"output": "qweryjll."
},
{
"input": "L\n..",
"output": "//"
}
] | 1,689,802,736 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 46 | 0 | if input() == 'R': step = -1
else: step = 1
string = input()
keyboard = "qwertyuiopasdfghjkl;zxcvbnm,./"
output = ""
for x in string:
output += keyboard[keyboard.index(x) + step]
print(output)
| Title: Keyboard
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Our good friend Mole is trying to code a big message. He is typing on an unusual keyboard with characters arranged in following way:
Unfortunately Mole is blind, so sometimes it is problem for him to put his hands accurately. He accidentally moved both his hands with one position to the left or to the right. That means that now he presses not a button he wants, but one neighboring button (left or right, as specified in input).
We have a sequence of characters he has typed and we want to find the original message.
Input Specification:
First line of the input contains one letter describing direction of shifting ('L' or 'R' respectively for left or right).
Second line contains a sequence of characters written by Mole. The size of this sequence will be no more than 100. Sequence contains only symbols that appear on Mole's keyboard. It doesn't contain spaces as there is no space on Mole's keyboard.
It is guaranteed that even though Mole hands are moved, he is still pressing buttons on keyboard and not hitting outside it.
Output Specification:
Print a line that contains the original message.
Demo Input:
['R\ns;;upimrrfod;pbr\n']
Demo Output:
['allyouneedislove\n']
Note:
none | ```python
if input() == 'R': step = -1
else: step = 1
string = input()
keyboard = "qwertyuiopasdfghjkl;zxcvbnm,./"
output = ""
for x in string:
output += keyboard[keyboard.index(x) + step]
print(output)
``` | 3 |
|
633 | B | A Trivial Problem | PROGRAMMING | 1,300 | [
"brute force",
"constructive algorithms",
"math",
"number theory"
] | null | null | Mr. Santa asks all the great programmers of the world to solve a trivial problem. He gives them an integer *m* and asks for the number of positive integers *n*, such that the factorial of *n* ends with exactly *m* zeroes. Are you among those great programmers who can solve this problem? | The only line of input contains an integer *m* (1<=≤<=*m*<=≤<=100<=000) — the required number of trailing zeroes in factorial. | First print *k* — the number of values of *n* such that the factorial of *n* ends with *m* zeroes. Then print these *k* integers in increasing order. | [
"1\n",
"5\n"
] | [
"5\n5 6 7 8 9 ",
"0"
] | The factorial of *n* is equal to the product of all integers from 1 to *n* inclusive, that is *n*! = 1·2·3·...·*n*.
In the first sample, 5! = 120, 6! = 720, 7! = 5040, 8! = 40320 and 9! = 362880. | 500 | [
{
"input": "1",
"output": "5\n5 6 7 8 9 "
},
{
"input": "5",
"output": "0"
},
{
"input": "2",
"output": "5\n10 11 12 13 14 "
},
{
"input": "3",
"output": "5\n15 16 17 18 19 "
},
{
"input": "7",
"output": "5\n30 31 32 33 34 "
},
{
"input": "12",
"output": "5\n50 51 52 53 54 "
},
{
"input": "15",
"output": "5\n65 66 67 68 69 "
},
{
"input": "18",
"output": "5\n75 76 77 78 79 "
},
{
"input": "38",
"output": "5\n155 156 157 158 159 "
},
{
"input": "47",
"output": "5\n195 196 197 198 199 "
},
{
"input": "58",
"output": "5\n240 241 242 243 244 "
},
{
"input": "66",
"output": "5\n270 271 272 273 274 "
},
{
"input": "70",
"output": "5\n285 286 287 288 289 "
},
{
"input": "89",
"output": "5\n365 366 367 368 369 "
},
{
"input": "417",
"output": "5\n1675 1676 1677 1678 1679 "
},
{
"input": "815",
"output": "5\n3265 3266 3267 3268 3269 "
},
{
"input": "394",
"output": "5\n1585 1586 1587 1588 1589 "
},
{
"input": "798",
"output": "0"
},
{
"input": "507",
"output": "5\n2035 2036 2037 2038 2039 "
},
{
"input": "406",
"output": "5\n1630 1631 1632 1633 1634 "
},
{
"input": "570",
"output": "5\n2290 2291 2292 2293 2294 "
},
{
"input": "185",
"output": "0"
},
{
"input": "765",
"output": "0"
},
{
"input": "967",
"output": "0"
},
{
"input": "112",
"output": "5\n455 456 457 458 459 "
},
{
"input": "729",
"output": "5\n2925 2926 2927 2928 2929 "
},
{
"input": "4604",
"output": "5\n18425 18426 18427 18428 18429 "
},
{
"input": "8783",
"output": "5\n35140 35141 35142 35143 35144 "
},
{
"input": "1059",
"output": "0"
},
{
"input": "6641",
"output": "5\n26575 26576 26577 26578 26579 "
},
{
"input": "9353",
"output": "5\n37425 37426 37427 37428 37429 "
},
{
"input": "1811",
"output": "5\n7250 7251 7252 7253 7254 "
},
{
"input": "2528",
"output": "0"
},
{
"input": "8158",
"output": "5\n32640 32641 32642 32643 32644 "
},
{
"input": "3014",
"output": "5\n12070 12071 12072 12073 12074 "
},
{
"input": "7657",
"output": "5\n30640 30641 30642 30643 30644 "
},
{
"input": "4934",
"output": "0"
},
{
"input": "9282",
"output": "5\n37140 37141 37142 37143 37144 "
},
{
"input": "2610",
"output": "5\n10450 10451 10452 10453 10454 "
},
{
"input": "2083",
"output": "5\n8345 8346 8347 8348 8349 "
},
{
"input": "26151",
"output": "5\n104620 104621 104622 104623 104624 "
},
{
"input": "64656",
"output": "5\n258640 258641 258642 258643 258644 "
},
{
"input": "46668",
"output": "5\n186690 186691 186692 186693 186694 "
},
{
"input": "95554",
"output": "5\n382235 382236 382237 382238 382239 "
},
{
"input": "37320",
"output": "0"
},
{
"input": "52032",
"output": "5\n208140 208141 208142 208143 208144 "
},
{
"input": "11024",
"output": "5\n44110 44111 44112 44113 44114 "
},
{
"input": "63218",
"output": "5\n252885 252886 252887 252888 252889 "
},
{
"input": "40095",
"output": "5\n160390 160391 160392 160393 160394 "
},
{
"input": "42724",
"output": "5\n170910 170911 170912 170913 170914 "
},
{
"input": "24381",
"output": "5\n97530 97531 97532 97533 97534 "
},
{
"input": "73138",
"output": "5\n292570 292571 292572 292573 292574 "
},
{
"input": "93346",
"output": "5\n373400 373401 373402 373403 373404 "
},
{
"input": "18338",
"output": "5\n73370 73371 73372 73373 73374 "
},
{
"input": "42662",
"output": "5\n170660 170661 170662 170663 170664 "
},
{
"input": "81221",
"output": "5\n324900 324901 324902 324903 324904 "
},
{
"input": "100000",
"output": "5\n400005 400006 400007 400008 400009 "
},
{
"input": "100000",
"output": "5\n400005 400006 400007 400008 400009 "
},
{
"input": "99998",
"output": "0"
},
{
"input": "30",
"output": "0"
},
{
"input": "11",
"output": "0"
},
{
"input": "780",
"output": "0"
},
{
"input": "97656",
"output": "5\n390625 390626 390627 390628 390629 "
},
{
"input": "12499",
"output": "5\n50000 50001 50002 50003 50004 "
},
{
"input": "65",
"output": "5\n265 266 267 268 269 "
},
{
"input": "41",
"output": "5\n170 171 172 173 174 "
},
{
"input": "31",
"output": "5\n125 126 127 128 129 "
},
{
"input": "86577",
"output": "0"
}
] | 1,604,589,768 | 2,147,483,647 | Python 3 | OK | TESTS | 68 | 1,513 | 307,200 | def trailing_zeros(n):
count = 0
i = 5
while (n/i >= 1):
count += int(n / i)
i *= 5
return int(count)
if __name__ == '__main__':
n_list = []
m = int(input())
counter = 0
for n in range(1, 500000):
zeros = trailing_zeros(n)
if(zeros == m):
n_list.append(n)
counter += 1
print(counter)
for num in n_list:
print(num, end = ' ') | Title: A Trivial Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mr. Santa asks all the great programmers of the world to solve a trivial problem. He gives them an integer *m* and asks for the number of positive integers *n*, such that the factorial of *n* ends with exactly *m* zeroes. Are you among those great programmers who can solve this problem?
Input Specification:
The only line of input contains an integer *m* (1<=≤<=*m*<=≤<=100<=000) — the required number of trailing zeroes in factorial.
Output Specification:
First print *k* — the number of values of *n* such that the factorial of *n* ends with *m* zeroes. Then print these *k* integers in increasing order.
Demo Input:
['1\n', '5\n']
Demo Output:
['5\n5 6 7 8 9 ', '0']
Note:
The factorial of *n* is equal to the product of all integers from 1 to *n* inclusive, that is *n*! = 1·2·3·...·*n*.
In the first sample, 5! = 120, 6! = 720, 7! = 5040, 8! = 40320 and 9! = 362880. | ```python
def trailing_zeros(n):
count = 0
i = 5
while (n/i >= 1):
count += int(n / i)
i *= 5
return int(count)
if __name__ == '__main__':
n_list = []
m = int(input())
counter = 0
for n in range(1, 500000):
zeros = trailing_zeros(n)
if(zeros == m):
n_list.append(n)
counter += 1
print(counter)
for num in n_list:
print(num, end = ' ')
``` | 3 |
|
855 | A | Tom Riddle's Diary | PROGRAMMING | 800 | [
"brute force",
"implementation",
"strings"
] | null | null | Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they are not under its influence.
He has names of *n* people who possessed the diary in order. You need to tell, for each person, if he/she possessed the diary at some point before or not.
Formally, for a name *s**i* in the *i*-th line, output "YES" (without quotes) if there exists an index *j* such that *s**i*<==<=*s**j* and *j*<=<<=*i*, otherwise, output "NO" (without quotes). | First line of input contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of names in the list.
Next *n* lines each contain a string *s**i*, consisting of lowercase English letters. The length of each string is between 1 and 100. | Output *n* lines each containing either "YES" or "NO" (without quotes), depending on whether this string was already present in the stream or not.
You can print each letter in any case (upper or lower). | [
"6\ntom\nlucius\nginny\nharry\nginny\nharry\n",
"3\na\na\na\n"
] | [
"NO\nNO\nNO\nNO\nYES\nYES\n",
"NO\nYES\nYES\n"
] | In test case 1, for *i* = 5 there exists *j* = 3 such that *s*<sub class="lower-index">*i*</sub> = *s*<sub class="lower-index">*j*</sub> and *j* < *i*, which means that answer for *i* = 5 is "YES". | 500 | [
{
"input": "6\ntom\nlucius\nginny\nharry\nginny\nharry",
"output": "NO\nNO\nNO\nNO\nYES\nYES"
},
{
"input": "3\na\na\na",
"output": "NO\nYES\nYES"
},
{
"input": "1\nzn",
"output": "NO"
},
{
"input": "9\nliyzmbjwnzryjokufuxcqtzwworjeoxkbaqrujrhdidqdvwdfzilwszgnzglnnbogaclckfnbqovtziuhwvyrqwmskx\nliyzmbjwnzryjokufuxcqtzwworjeoxkbaqrujrhdidqdvwdfzilwszgnzglnnbogaclckfnbqovtziuhwvyrqwmskx\nliyzmbjwnzryjokufuxcqtzwworjeoxkbaqrujrhdidqdvwdfzilwszgnzglnnbogaclckfnbqovtziuhwvyrqwmskx\nhrtm\nssjqvixduertmotgagizamvfucfwtxqnhuowbqbzctgznivehelpcyigwrbbdsxnewfqvcf\nhyrtxvozpbveexfkgalmguozzakitjiwsduqxonb\nwcyxteiwtcyuztaguilqpbiwcwjaiq\nwcyxteiwtcyuztaguilqpbiwcwjaiq\nbdbivqzvhggth",
"output": "NO\nYES\nYES\nNO\nNO\nNO\nNO\nYES\nNO"
},
{
"input": "10\nkkiubdktydpdcbbttwpfdplhhjhrpqmpg\nkkiubdktydpdcbbttwpfdplhhjhrpqmpg\nmvutw\nqooeqoxzxwetlpecqiwgdbogiqqulttysyohwhzxzphvsfmnplizxoebzcvvfyppqbhxjksuzepuezqqzxlfmdanoeaoqmor\nmvutw\nvchawxjoreboqzuklifv\nvchawxjoreboqzuklifv\nnivijte\nrflybruq\nvchawxjoreboqzuklifv",
"output": "NO\nYES\nNO\nNO\nYES\nNO\nYES\nNO\nNO\nYES"
},
{
"input": "1\nz",
"output": "NO"
},
{
"input": "9\nl\ny\nm\nj\nn\nr\nj\nk\nf",
"output": "NO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO"
},
{
"input": "14\nw\na\nh\np\nk\nw\ny\nv\ns\nf\nx\nd\nk\nr",
"output": "NO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO"
},
{
"input": "25\np\nk\nu\nl\nf\nt\nc\ns\nq\nd\nb\nq\no\ni\ni\nd\ni\nw\nn\ng\nw\nt\na\ne\ni",
"output": "NO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nYES\nYES\nYES\nNO\nNO\nNO\nYES\nYES\nNO\nNO\nYES"
},
{
"input": "20\nd\nh\ng\no\np\ne\nt\nj\nv\ni\nt\nh\ns\ni\nw\nf\nx\na\nl\ni",
"output": "NO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nYES\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nYES"
},
{
"input": "3\nbbbbbbb\nbbbbbbbbb\nbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
"output": "NO\nNO\nNO"
},
{
"input": "2\nab\nba",
"output": "NO\nNO"
},
{
"input": "6\ntom\nlucius\nginnys\nharpy\nginny\nharry",
"output": "NO\nNO\nNO\nNO\nNO\nNO"
},
{
"input": "2\nabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcde\nabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcde",
"output": "NO\nYES"
},
{
"input": "42\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na",
"output": "NO\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES"
}
] | 1,622,471,754 | 2,147,483,647 | Python 3 | OK | TESTS | 55 | 109 | 0 | n=int(input())
lst=[]
for i in range(n):
s=str(input())
print('YES' if s in lst else 'NO')
lst.append(s) | Title: Tom Riddle's Diary
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they are not under its influence.
He has names of *n* people who possessed the diary in order. You need to tell, for each person, if he/she possessed the diary at some point before or not.
Formally, for a name *s**i* in the *i*-th line, output "YES" (without quotes) if there exists an index *j* such that *s**i*<==<=*s**j* and *j*<=<<=*i*, otherwise, output "NO" (without quotes).
Input Specification:
First line of input contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of names in the list.
Next *n* lines each contain a string *s**i*, consisting of lowercase English letters. The length of each string is between 1 and 100.
Output Specification:
Output *n* lines each containing either "YES" or "NO" (without quotes), depending on whether this string was already present in the stream or not.
You can print each letter in any case (upper or lower).
Demo Input:
['6\ntom\nlucius\nginny\nharry\nginny\nharry\n', '3\na\na\na\n']
Demo Output:
['NO\nNO\nNO\nNO\nYES\nYES\n', 'NO\nYES\nYES\n']
Note:
In test case 1, for *i* = 5 there exists *j* = 3 such that *s*<sub class="lower-index">*i*</sub> = *s*<sub class="lower-index">*j*</sub> and *j* < *i*, which means that answer for *i* = 5 is "YES". | ```python
n=int(input())
lst=[]
for i in range(n):
s=str(input())
print('YES' if s in lst else 'NO')
lst.append(s)
``` | 3 |
|
587 | A | Duff and Weight Lifting | PROGRAMMING | 1,500 | [
"greedy"
] | null | null | Recently, Duff has been practicing weight lifting. As a hard practice, Malek gave her a task. He gave her a sequence of weights. Weight of *i*-th of them is 2*w**i* pounds. In each step, Duff can lift some of the remaining weights and throw them away. She does this until there's no more weight left. Malek asked her to minimize the number of steps.
Duff is a competitive programming fan. That's why in each step, she can only lift and throw away a sequence of weights 2*a*1,<=...,<=2*a**k* if and only if there exists a non-negative integer *x* such that 2*a*1<=+<=2*a*2<=+<=...<=+<=2*a**k*<==<=2*x*, i. e. the sum of those numbers is a power of two.
Duff is a competitive programming fan, but not a programmer. That's why she asked for your help. Help her minimize the number of steps. | The first line of input contains integer *n* (1<=≤<=*n*<=≤<=106), the number of weights.
The second line contains *n* integers *w*1,<=...,<=*w**n* separated by spaces (0<=≤<=*w**i*<=≤<=106 for each 1<=≤<=*i*<=≤<=*n*), the powers of two forming the weights values. | Print the minimum number of steps in a single line. | [
"5\n1 1 2 3 3\n",
"4\n0 1 2 3\n"
] | [
"2\n",
"4\n"
] | In the first sample case: One optimal way would be to throw away the first three in the first step and the rest in the second step. Also, it's not possible to do it in one step because their sum is not a power of two.
In the second sample case: The only optimal way is to throw away one weight in each step. It's not possible to do it in less than 4 steps because there's no subset of weights with more than one weight and sum equal to a power of two. | 500 | [
{
"input": "5\n1 1 2 3 3",
"output": "2"
},
{
"input": "4\n0 1 2 3",
"output": "4"
},
{
"input": "1\n120287",
"output": "1"
},
{
"input": "2\n28288 0",
"output": "2"
},
{
"input": "2\n95745 95745",
"output": "1"
},
{
"input": "13\n92 194 580495 0 10855 41704 13 96429 33 213 0 92 140599",
"output": "11"
},
{
"input": "13\n688743 688743 1975 688743 688743 688743 688743 688743 688743 0 0 688743 688743",
"output": "4"
},
{
"input": "35\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "3"
},
{
"input": "35\n130212 3176 77075 8071 18 1369 7539 1683 80757 1847 0 1374 122 8524 4 2 21333 270264 4 9254 151921 0 1 33596 73002 54382 0 1 29233 75952 15 38892 1877 6167 4",
"output": "31"
},
{
"input": "35\n0 0 298 0 0 0 0 0 689063 65442 0 984598 2054 43668 0 369 0 2054 0 996220 0 16327 369 0 996220 0 0 0 4693 2054 348 0 118 0 0",
"output": "16"
},
{
"input": "100\n196 1681 196 0 61 93 196 196 196 196 196 0 0 96 18 1576 0 93 666463 18 93 1 1278 8939 93 196 196 1278 3 0 67416 869956 10 56489 196 745 39 783 196 8939 196 81 69634 4552 39 3 14 20 25 8 10 4 7302 0 19579 20 1140 15990 7302 0 19579 4142 11 1354 75252 93 311 1278 0 79475 10 75252 93 7302 0 81 408441 19579 10 39 19 37748 4364 31135 47700 105818 47700 10 4142 543356 3 30647 45917 60714 8939 18 22925 7302 93 75252",
"output": "59"
}
] | 1,616,615,632 | 2,147,483,647 | PyPy 3 | OK | TESTS | 46 | 966 | 88,576,000 | ###### ### ####### ####### ## # ##### ### #####
# # # # # # # # # # # # # ###
# # # # # # # # # # # # # ###
###### ######### # # # # # # ######### #
###### ######### # # # # # # ######### #
# # # # # # # # # # #### # # #
# # # # # # # ## # # # # #
###### # # ####### ####### # # ##### # # # #
# from __future__ import print_function # for PyPy2
from collections import Counter, OrderedDict
from itertools import permutations as perm
from fractions import Fraction
from collections import deque
from sys import stdin
from bisect import *
from heapq import *
from math import *
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
mod = int(1e9)+7
inf = float("inf")
g()
n = int(2e6)+2
f = [0]*(n)
ans = 0
for v in gil():
f[v] += 1
# f[int(1e6)] = int(1e6)
for i in range(n):
ans += (f[i]&1)
f[i] //= 2
if f[i]:
if i+1 < n:
f[i+1] += f[i]
else:
print("break")
print(f[i], i)
print(ans)
| Title: Duff and Weight Lifting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, Duff has been practicing weight lifting. As a hard practice, Malek gave her a task. He gave her a sequence of weights. Weight of *i*-th of them is 2*w**i* pounds. In each step, Duff can lift some of the remaining weights and throw them away. She does this until there's no more weight left. Malek asked her to minimize the number of steps.
Duff is a competitive programming fan. That's why in each step, she can only lift and throw away a sequence of weights 2*a*1,<=...,<=2*a**k* if and only if there exists a non-negative integer *x* such that 2*a*1<=+<=2*a*2<=+<=...<=+<=2*a**k*<==<=2*x*, i. e. the sum of those numbers is a power of two.
Duff is a competitive programming fan, but not a programmer. That's why she asked for your help. Help her minimize the number of steps.
Input Specification:
The first line of input contains integer *n* (1<=≤<=*n*<=≤<=106), the number of weights.
The second line contains *n* integers *w*1,<=...,<=*w**n* separated by spaces (0<=≤<=*w**i*<=≤<=106 for each 1<=≤<=*i*<=≤<=*n*), the powers of two forming the weights values.
Output Specification:
Print the minimum number of steps in a single line.
Demo Input:
['5\n1 1 2 3 3\n', '4\n0 1 2 3\n']
Demo Output:
['2\n', '4\n']
Note:
In the first sample case: One optimal way would be to throw away the first three in the first step and the rest in the second step. Also, it's not possible to do it in one step because their sum is not a power of two.
In the second sample case: The only optimal way is to throw away one weight in each step. It's not possible to do it in less than 4 steps because there's no subset of weights with more than one weight and sum equal to a power of two. | ```python
###### ### ####### ####### ## # ##### ### #####
# # # # # # # # # # # # # ###
# # # # # # # # # # # # # ###
###### ######### # # # # # # ######### #
###### ######### # # # # # # ######### #
# # # # # # # # # # #### # # #
# # # # # # # ## # # # # #
###### # # ####### ####### # # ##### # # # #
# from __future__ import print_function # for PyPy2
from collections import Counter, OrderedDict
from itertools import permutations as perm
from fractions import Fraction
from collections import deque
from sys import stdin
from bisect import *
from heapq import *
from math import *
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
mod = int(1e9)+7
inf = float("inf")
g()
n = int(2e6)+2
f = [0]*(n)
ans = 0
for v in gil():
f[v] += 1
# f[int(1e6)] = int(1e6)
for i in range(n):
ans += (f[i]&1)
f[i] //= 2
if f[i]:
if i+1 < n:
f[i+1] += f[i]
else:
print("break")
print(f[i], i)
print(ans)
``` | 3 |
|
5 | B | Center Alignment | PROGRAMMING | 1,200 | [
"implementation",
"strings"
] | B. Center Alignment | 1 | 64 | Almost every text editor has a built-in function of center text alignment. The developers of the popular in Berland text editor «Textpad» decided to introduce this functionality into the fourth release of the product.
You are to implement the alignment in the shortest possible time. Good luck! | The input file consists of one or more lines, each of the lines contains Latin letters, digits and/or spaces. The lines cannot start or end with a space. It is guaranteed that at least one of the lines has positive length. The length of each line and the total amount of the lines do not exceed 1000. | Format the given text, aligning it center. Frame the whole text with characters «*» of the minimum size. If a line cannot be aligned perfectly (for example, the line has even length, while the width of the block is uneven), you should place such lines rounding down the distance to the left or to the right edge and bringing them closer left or right alternatively (you should start with bringing left). Study the sample tests carefully to understand the output format better. | [
"This is\n\nCodeforces\nBeta\nRound\n5\n",
"welcome to the\nCodeforces\nBeta\nRound 5\n\nand\ngood luck\n"
] | [
"************\n* This is *\n* *\n*Codeforces*\n* Beta *\n* Round *\n* 5 *\n************\n",
"****************\n*welcome to the*\n* Codeforces *\n* Beta *\n* Round 5 *\n* *\n* and *\n* good luck *\n****************\n"
] | none | 0 | [
{
"input": "This is\n\nCodeforces\nBeta\nRound\n5",
"output": "************\n* This is *\n* *\n*Codeforces*\n* Beta *\n* Round *\n* 5 *\n************"
},
{
"input": "welcome to the\nCodeforces\nBeta\nRound 5\n\nand\ngood luck",
"output": "****************\n*welcome to the*\n* Codeforces *\n* Beta *\n* Round 5 *\n* *\n* and *\n* good luck *\n****************"
},
{
"input": "0\n2",
"output": "***\n*0*\n*2*\n***"
},
{
"input": "O\no\nd",
"output": "***\n*O*\n*o*\n*d*\n***"
},
{
"input": "0v uO M6Sy",
"output": "************\n*0v uO M6Sy*\n************"
},
{
"input": "fm v\nOL U W",
"output": "**********\n* fm v *\n*OL U W*\n**********"
},
{
"input": "vb\nJ\nyU\nZ",
"output": "****\n*vb*\n*J *\n*yU*\n* Z*\n****"
},
{
"input": "N\nSV\nEh\n6f\nX6\n9e",
"output": "****\n*N *\n*SV*\n*Eh*\n*6f*\n*X6*\n*9e*\n****"
},
{
"input": "Pj\nA\nFA\nP\nVJ\nU\nEb\nW",
"output": "****\n*Pj*\n*A *\n*FA*\n* P*\n*VJ*\n*U *\n*Eb*\n* W*\n****"
},
{
"input": "T\n7j\nS\nb\nq8\nVZ\nn\n4T\niZ\npA",
"output": "****\n*T *\n*7j*\n* S*\n*b *\n*q8*\n*VZ*\n* n*\n*4T*\n*iZ*\n*pA*\n****"
},
{
"input": "8\n\n\n\ny\nW\n\n\n\n3B\n\nw\nV\n\n\n\nL\nSr\n\n\nV\n\n5\n\nAq\n\n\n\nJ\nR\n\n04\nJ\nv\nhU\n\n\n\nY\nG\n4\n\nG\nb\n\n\n9\n\n6\nd\n\n2\n\n\nE\n7\n\nr\n\n\n\n\nKC\ns\nE\n\nab\n4\nx\n\n\n\n\n\nEe\n4\n\nl\n\np\n\nG\nM\n\n\nn\n\n\nm0\n\nw\n\n\nP\n\n\n\n0",
"output": "****\n*8 *\n* *\n* *\n* *\n* y*\n*W *\n* *\n* *\n* *\n*3B*\n* *\n* w*\n*V *\n* *\n* *\n* *\n* L*\n*Sr*\n* *\n* *\n*V *\n* *\n* 5*\n* *\n*Aq*\n* *\n* *\n* *\n*J *\n* R*\n* *\n*04*\n*J *\n* v*\n*hU*\n* *\n* *\n* *\n*Y *\n* G*\n*4 *\n* *\n* G*\n*b *\n* *\n* *\n* 9*\n* *\n*6 *\n* d*\n* *\n*2 *\n* *\n* *\n* E*\n*7 *\n* *\n* r*\n* *\n* *\n* *\n* *\n*KC*\n*s *\n* E*\n* *\n*ab*\n*4 *\n* x*\n* *\n* *\n* *\n* *\n* *\n*Ee*\n*4 *\n* *\n* l*\n* *\n*p *\n* *\n* G*\n*M *\n* *\n*..."
},
{
"input": "U",
"output": "***\n*U*\n***"
}
] | 1,578,602,662 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 12 | 1,000 | 716,800 | big = 0
lines = []
def asteriks(n):
for k in range(n):
print('*', end='')
print()
def spaces(n):
for k in range(n):
print(' ', end='')
try:
while True:
line = input()
sz = len(line)
if sz > big:
big = sz
lines.append(line)
except:
pass
# - - - - -
asteriks(big + 2)
last = 1
for k in range(len(lines)):
print('*', end='')
sz = len(lines[k])
hf = big - sz
if hf % 2 == 0:
spaces(hf//2)
print(lines[k], end='')
spaces(hf//2)
else:
last = 1 - last
spaces(hf//2 + last)
print(lines[k], end='')
spaces(hf//2 + 1 - last)
print('*')
asteriks(big + 2)
| Title: Center Alignment
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Almost every text editor has a built-in function of center text alignment. The developers of the popular in Berland text editor «Textpad» decided to introduce this functionality into the fourth release of the product.
You are to implement the alignment in the shortest possible time. Good luck!
Input Specification:
The input file consists of one or more lines, each of the lines contains Latin letters, digits and/or spaces. The lines cannot start or end with a space. It is guaranteed that at least one of the lines has positive length. The length of each line and the total amount of the lines do not exceed 1000.
Output Specification:
Format the given text, aligning it center. Frame the whole text with characters «*» of the minimum size. If a line cannot be aligned perfectly (for example, the line has even length, while the width of the block is uneven), you should place such lines rounding down the distance to the left or to the right edge and bringing them closer left or right alternatively (you should start with bringing left). Study the sample tests carefully to understand the output format better.
Demo Input:
['This is\n\nCodeforces\nBeta\nRound\n5\n', 'welcome to the\nCodeforces\nBeta\nRound 5\n\nand\ngood luck\n']
Demo Output:
['************\n* This is *\n* *\n*Codeforces*\n* Beta *\n* Round *\n* 5 *\n************\n', '****************\n*welcome to the*\n* Codeforces *\n* Beta *\n* Round 5 *\n* *\n* and *\n* good luck *\n****************\n']
Note:
none | ```python
big = 0
lines = []
def asteriks(n):
for k in range(n):
print('*', end='')
print()
def spaces(n):
for k in range(n):
print(' ', end='')
try:
while True:
line = input()
sz = len(line)
if sz > big:
big = sz
lines.append(line)
except:
pass
# - - - - -
asteriks(big + 2)
last = 1
for k in range(len(lines)):
print('*', end='')
sz = len(lines[k])
hf = big - sz
if hf % 2 == 0:
spaces(hf//2)
print(lines[k], end='')
spaces(hf//2)
else:
last = 1 - last
spaces(hf//2 + last)
print(lines[k], end='')
spaces(hf//2 + 1 - last)
print('*')
asteriks(big + 2)
``` | 0 |
389 | A | Fox and Number Game | PROGRAMMING | 1,000 | [
"greedy",
"math"
] | null | null | Fox Ciel is playing a game with numbers now.
Ciel has *n* positive integers: *x*1, *x*2, ..., *x**n*. She can do the following operation as many times as needed: select two different indexes *i* and *j* such that *x**i* > *x**j* hold, and then apply assignment *x**i* = *x**i* - *x**j*. The goal is to make the sum of all numbers as small as possible.
Please help Ciel to find this minimal sum. | The first line contains an integer *n* (2<=≤<=*n*<=≤<=100). Then the second line contains *n* integers: *x*1, *x*2, ..., *x**n* (1<=≤<=*x**i*<=≤<=100). | Output a single integer — the required minimal sum. | [
"2\n1 2\n",
"3\n2 4 6\n",
"2\n12 18\n",
"5\n45 12 27 30 18\n"
] | [
"2\n",
"6\n",
"12\n",
"15\n"
] | In the first example the optimal way is to do the assignment: *x*<sub class="lower-index">2</sub> = *x*<sub class="lower-index">2</sub> - *x*<sub class="lower-index">1</sub>.
In the second example the optimal sequence of operations is: *x*<sub class="lower-index">3</sub> = *x*<sub class="lower-index">3</sub> - *x*<sub class="lower-index">2</sub>, *x*<sub class="lower-index">2</sub> = *x*<sub class="lower-index">2</sub> - *x*<sub class="lower-index">1</sub>. | 500 | [
{
"input": "2\n1 2",
"output": "2"
},
{
"input": "3\n2 4 6",
"output": "6"
},
{
"input": "2\n12 18",
"output": "12"
},
{
"input": "5\n45 12 27 30 18",
"output": "15"
},
{
"input": "2\n1 1",
"output": "2"
},
{
"input": "2\n100 100",
"output": "200"
},
{
"input": "2\n87 58",
"output": "58"
},
{
"input": "39\n52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52",
"output": "2028"
},
{
"input": "59\n96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96",
"output": "5664"
},
{
"input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100",
"output": "10000"
},
{
"input": "100\n70 70 77 42 98 84 56 91 35 21 7 70 77 77 56 63 14 84 56 14 77 77 63 70 14 7 28 91 63 49 21 84 98 56 77 98 98 84 98 14 7 56 49 28 91 98 7 56 14 91 14 98 49 28 98 14 98 98 14 70 35 28 63 28 49 63 63 56 91 98 35 42 42 35 63 35 42 14 63 21 77 56 42 77 35 91 56 21 28 84 56 70 70 91 98 70 84 63 21 98",
"output": "700"
},
{
"input": "39\n63 21 21 42 21 63 21 84 42 21 84 63 42 63 84 84 84 42 42 84 21 63 42 63 42 42 63 42 42 63 84 42 21 84 21 63 42 21 42",
"output": "819"
},
{
"input": "59\n70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70",
"output": "4130"
},
{
"input": "87\n44 88 88 88 88 66 88 22 22 88 88 44 88 22 22 22 88 88 88 88 66 22 88 88 88 88 66 66 44 88 44 44 66 22 88 88 22 44 66 44 88 66 66 22 22 22 22 88 22 22 44 66 88 22 22 88 66 66 88 22 66 88 66 88 66 44 88 44 22 44 44 22 44 88 44 44 44 44 22 88 88 88 66 66 88 44 22",
"output": "1914"
},
{
"input": "15\n63 63 63 63 63 63 63 63 63 63 63 63 63 63 63",
"output": "945"
},
{
"input": "39\n63 77 21 14 14 35 21 21 70 42 21 70 28 77 28 77 7 42 63 7 98 49 98 84 35 70 70 91 14 42 98 7 42 7 98 42 56 35 91",
"output": "273"
},
{
"input": "18\n18 18 18 36 36 36 54 72 54 36 72 54 36 36 36 36 18 36",
"output": "324"
},
{
"input": "46\n71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71",
"output": "3266"
},
{
"input": "70\n66 11 66 11 44 11 44 99 55 22 88 11 11 22 55 44 22 77 44 77 77 22 44 55 88 11 99 99 88 22 77 77 66 11 11 66 99 55 55 44 66 44 77 44 44 55 33 55 44 88 77 77 22 66 33 44 11 22 55 44 22 66 77 33 33 44 44 44 22 33",
"output": "770"
},
{
"input": "10\n60 12 96 48 60 24 60 36 60 60",
"output": "120"
},
{
"input": "20\n51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51",
"output": "1020"
},
{
"input": "50\n58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58",
"output": "2900"
},
{
"input": "98\n70 60 100 30 70 20 30 50 50 30 90 40 30 40 60 80 60 60 80 50 10 80 20 10 20 10 50 70 30 80 30 50 60 90 90 100 60 30 90 20 30 60 90 80 60 60 10 90 10 50 40 40 80 90 100 40 70 40 30 50 60 50 60 30 40 20 90 60 20 20 20 70 60 70 50 100 90 50 20 40 80 60 10 60 50 40 40 10 50 10 40 10 80 100 100 90 10 90",
"output": "980"
},
{
"input": "100\n82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82",
"output": "8200"
},
{
"input": "100\n11 87 77 93 3 54 21 93 9 71 37 23 69 85 74 3 48 99 51 31 56 19 21 96 39 6 4 4 29 69 100 42 1 22 81 53 48 49 81 61 10 7 40 61 7 71 51 59 79 44 50 35 95 80 83 8 98 40 18 94 84 49 52 74 66 69 39 37 100 44 38 62 2 80 46 31 35 53 5 60 21 49 63 55 20 53 80 53 66 34 23 92 77 50 86 63 65 24 12 70",
"output": "100"
},
{
"input": "2\n100 1",
"output": "2"
},
{
"input": "2\n18 30",
"output": "12"
},
{
"input": "2\n3 5",
"output": "2"
},
{
"input": "2\n1 10",
"output": "2"
},
{
"input": "2\n8 5",
"output": "2"
},
{
"input": "5\n2 3 5 8 18",
"output": "5"
},
{
"input": "5\n2 4 1 6 8",
"output": "5"
},
{
"input": "3\n12 10 5",
"output": "3"
},
{
"input": "3\n6 10 15",
"output": "3"
}
] | 1,402,406,635 | 2,034 | Python 3 | OK | TESTS | 34 | 93 | 0 | n = int(input())
a = list(map(int, input().split()))
while(1):
T = True
for i in range(n):
for j in range(n):
if a[i] > a[j]:
a[i] = a[i] - a[j]
T = False
elif a[i] < a[j]:
a[j] = a[j] - a[i]
T = False
if T:
break
print(sum(a)) | Title: Fox and Number Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel is playing a game with numbers now.
Ciel has *n* positive integers: *x*1, *x*2, ..., *x**n*. She can do the following operation as many times as needed: select two different indexes *i* and *j* such that *x**i* > *x**j* hold, and then apply assignment *x**i* = *x**i* - *x**j*. The goal is to make the sum of all numbers as small as possible.
Please help Ciel to find this minimal sum.
Input Specification:
The first line contains an integer *n* (2<=≤<=*n*<=≤<=100). Then the second line contains *n* integers: *x*1, *x*2, ..., *x**n* (1<=≤<=*x**i*<=≤<=100).
Output Specification:
Output a single integer — the required minimal sum.
Demo Input:
['2\n1 2\n', '3\n2 4 6\n', '2\n12 18\n', '5\n45 12 27 30 18\n']
Demo Output:
['2\n', '6\n', '12\n', '15\n']
Note:
In the first example the optimal way is to do the assignment: *x*<sub class="lower-index">2</sub> = *x*<sub class="lower-index">2</sub> - *x*<sub class="lower-index">1</sub>.
In the second example the optimal sequence of operations is: *x*<sub class="lower-index">3</sub> = *x*<sub class="lower-index">3</sub> - *x*<sub class="lower-index">2</sub>, *x*<sub class="lower-index">2</sub> = *x*<sub class="lower-index">2</sub> - *x*<sub class="lower-index">1</sub>. | ```python
n = int(input())
a = list(map(int, input().split()))
while(1):
T = True
for i in range(n):
for j in range(n):
if a[i] > a[j]:
a[i] = a[i] - a[j]
T = False
elif a[i] < a[j]:
a[j] = a[j] - a[i]
T = False
if T:
break
print(sum(a))
``` | 3 |
|
545 | C | Woodcutters | PROGRAMMING | 1,500 | [
"dp",
"greedy"
] | null | null | Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below.
There are *n* trees located along the road at points with coordinates *x*1,<=*x*2,<=...,<=*x**n*. Each tree has its height *h**i*. Woodcutters can cut down a tree and fell it to the left or to the right. After that it occupies one of the segments [*x**i*<=-<=*h**i*,<=*x**i*] or [*x**i*;*x**i*<=+<=*h**i*]. The tree that is not cut down occupies a single point with coordinate *x**i*. Woodcutters can fell a tree if the segment to be occupied by the fallen tree doesn't contain any occupied point. The woodcutters want to process as many trees as possible, so Susie wonders, what is the maximum number of trees to fell. | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of trees.
Next *n* lines contain pairs of integers *x**i*,<=*h**i* (1<=≤<=*x**i*,<=*h**i*<=≤<=109) — the coordinate and the height of the *і*-th tree.
The pairs are given in the order of ascending *x**i*. No two trees are located at the point with the same coordinate. | Print a single number — the maximum number of trees that you can cut down by the given rules. | [
"5\n1 2\n2 1\n5 10\n10 9\n19 1\n",
"5\n1 2\n2 1\n5 10\n10 9\n20 1\n"
] | [
"3\n",
"4\n"
] | In the first sample you can fell the trees like that:
- fell the 1-st tree to the left — now it occupies segment [ - 1;1] - fell the 2-nd tree to the right — now it occupies segment [2;3] - leave the 3-rd tree — it occupies point 5 - leave the 4-th tree — it occupies point 10 - fell the 5-th tree to the right — now it occupies segment [19;20]
In the second sample you can also fell 4-th tree to the right, after that it will occupy segment [10;19]. | 1,750 | [
{
"input": "5\n1 2\n2 1\n5 10\n10 9\n19 1",
"output": "3"
},
{
"input": "5\n1 2\n2 1\n5 10\n10 9\n20 1",
"output": "4"
},
{
"input": "4\n10 4\n15 1\n19 3\n20 1",
"output": "4"
},
{
"input": "35\n1 7\n3 11\n6 12\n7 6\n8 5\n9 11\n15 3\n16 10\n22 2\n23 3\n25 7\n27 3\n34 5\n35 10\n37 3\n39 4\n40 5\n41 1\n44 1\n47 7\n48 11\n50 6\n52 5\n57 2\n58 7\n60 4\n62 1\n67 3\n68 12\n69 8\n70 1\n71 5\n72 5\n73 6\n74 4",
"output": "10"
},
{
"input": "40\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1\n8 1\n9 1\n10 1\n11 1\n12 1\n13 1\n14 1\n15 1\n16 1\n17 1\n18 1\n19 1\n20 1\n21 1\n22 1\n23 1\n24 1\n25 1\n26 1\n27 1\n28 1\n29 1\n30 1\n31 1\n32 1\n33 1\n34 1\n35 1\n36 1\n37 1\n38 1\n39 1\n40 1",
"output": "2"
},
{
"input": "67\n1 1\n3 8\n4 10\n7 8\n9 2\n10 1\n11 5\n12 8\n13 4\n16 6\n18 3\n19 3\n22 5\n24 6\n27 5\n28 3\n29 3\n30 5\n32 5\n33 10\n34 7\n35 8\n36 5\n41 3\n42 2\n43 5\n46 4\n48 4\n49 9\n52 4\n53 9\n55 1\n56 4\n59 7\n68 7\n69 4\n71 9\n72 10\n74 5\n76 4\n77 9\n80 7\n81 9\n82 5\n83 5\n84 9\n85 7\n86 9\n87 4\n88 7\n89 10\n90 3\n91 5\n92 10\n93 5\n94 8\n95 4\n96 2\n97 10\n98 1\n99 3\n100 1\n101 5\n102 4\n103 8\n104 8\n105 8",
"output": "5"
},
{
"input": "1\n1000000000 1000000000",
"output": "1"
},
{
"input": "10\n7 12\n10 2\n12 2\n15 1\n19 2\n20 1\n53 25\n63 10\n75 12\n87 1",
"output": "9"
},
{
"input": "3\n1 1\n1000 1000\n1000000000 1000000000",
"output": "3"
},
{
"input": "2\n1 999999999\n1000000000 1000000000",
"output": "2"
},
{
"input": "10\n999999900 1000000000\n999999901 1000000000\n999999902 1000000000\n999999903 1000000000\n999999904 1000000000\n999999905 1000000000\n999999906 1000000000\n999999907 1000000000\n999999908 1000000000\n999999909 1000000000",
"output": "2"
},
{
"input": "2\n100000000 1000000000\n1000000000 1000000000",
"output": "2"
}
] | 1,667,228,748 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 67 | 639 | 15,155,200 | n = int(input())
th = [[int(x) for x in input().split()] for i in range(n)]
if n == 1 or n == 2:
print(n)
else:
count = 2
for i in range(1,n-1):
if th[i][0] - th[i][1] > th[i-1][0]:
count += 1
elif th[i][0] + th[i][1] < th[i+1][0]:
count += 1
th[i][0] += th[i][1]
print(count) | Title: Woodcutters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below.
There are *n* trees located along the road at points with coordinates *x*1,<=*x*2,<=...,<=*x**n*. Each tree has its height *h**i*. Woodcutters can cut down a tree and fell it to the left or to the right. After that it occupies one of the segments [*x**i*<=-<=*h**i*,<=*x**i*] or [*x**i*;*x**i*<=+<=*h**i*]. The tree that is not cut down occupies a single point with coordinate *x**i*. Woodcutters can fell a tree if the segment to be occupied by the fallen tree doesn't contain any occupied point. The woodcutters want to process as many trees as possible, so Susie wonders, what is the maximum number of trees to fell.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of trees.
Next *n* lines contain pairs of integers *x**i*,<=*h**i* (1<=≤<=*x**i*,<=*h**i*<=≤<=109) — the coordinate and the height of the *і*-th tree.
The pairs are given in the order of ascending *x**i*. No two trees are located at the point with the same coordinate.
Output Specification:
Print a single number — the maximum number of trees that you can cut down by the given rules.
Demo Input:
['5\n1 2\n2 1\n5 10\n10 9\n19 1\n', '5\n1 2\n2 1\n5 10\n10 9\n20 1\n']
Demo Output:
['3\n', '4\n']
Note:
In the first sample you can fell the trees like that:
- fell the 1-st tree to the left — now it occupies segment [ - 1;1] - fell the 2-nd tree to the right — now it occupies segment [2;3] - leave the 3-rd tree — it occupies point 5 - leave the 4-th tree — it occupies point 10 - fell the 5-th tree to the right — now it occupies segment [19;20]
In the second sample you can also fell 4-th tree to the right, after that it will occupy segment [10;19]. | ```python
n = int(input())
th = [[int(x) for x in input().split()] for i in range(n)]
if n == 1 or n == 2:
print(n)
else:
count = 2
for i in range(1,n-1):
if th[i][0] - th[i][1] > th[i-1][0]:
count += 1
elif th[i][0] + th[i][1] < th[i+1][0]:
count += 1
th[i][0] += th[i][1]
print(count)
``` | 3 |
|
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*. | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymedasloqbq",
"output": "NO"
},
{
"input": "yehluhlkwo",
"output": "NO"
},
{
"input": "hatlevhhalrohairnolsvocafgueelrqmlqlleello",
"output": "YES"
},
{
"input": "hhhtehdbllnhwmbyhvelqqyoulretpbfokflhlhreeflxeftelziclrwllrpflflbdtotvlqgoaoqldlroovbfsq",
"output": "YES"
},
{
"input": "rzlvihhghnelqtwlexmvdjjrliqllolhyewgozkuovaiezgcilelqapuoeglnwmnlftxxiigzczlouooi",
"output": "YES"
},
{
"input": "pfhhwctyqdlkrwhebfqfelhyebwllhemtrmeblgrynmvyhioesqklclocxmlffuormljszllpoo",
"output": "YES"
},
{
"input": "lqllcolohwflhfhlnaow",
"output": "NO"
},
{
"input": "heheeellollvoo",
"output": "YES"
},
{
"input": "hellooo",
"output": "YES"
},
{
"input": "o",
"output": "NO"
},
{
"input": "hhqhzeclohlehljlhtesllylrolmomvuhcxsobtsckogdv",
"output": "YES"
},
{
"input": "yoegfuzhqsihygnhpnukluutocvvwuldiighpogsifealtgkfzqbwtmgghmythcxflebrkctlldlkzlagovwlstsghbouk",
"output": "YES"
},
{
"input": "uatqtgbvrnywfacwursctpagasnhydvmlinrcnqrry",
"output": "NO"
},
{
"input": "tndtbldbllnrwmbyhvqaqqyoudrstpbfokfoclnraefuxtftmgzicorwisrpfnfpbdtatvwqgyalqtdtrjqvbfsq",
"output": "NO"
},
{
"input": "rzlvirhgemelnzdawzpaoqtxmqucnahvqnwldklrmjiiyageraijfivigvozgwngiulttxxgzczptusoi",
"output": "YES"
},
{
"input": "kgyelmchocojsnaqdsyeqgnllytbqietpdlgknwwumqkxrexgdcnwoldicwzwofpmuesjuxzrasscvyuqwspm",
"output": "YES"
},
{
"input": "pnyvrcotjvgynbeldnxieghfltmexttuxzyac",
"output": "NO"
},
{
"input": "dtwhbqoumejligbenxvzhjlhosqojetcqsynlzyhfaevbdpekgbtjrbhlltbceobcok",
"output": "YES"
},
{
"input": "crrfpfftjwhhikwzeedrlwzblckkteseofjuxjrktcjfsylmlsvogvrcxbxtffujqshslemnixoeezivksouefeqlhhokwbqjz",
"output": "YES"
},
{
"input": "jhfbndhyzdvhbvhmhmefqllujdflwdpjbehedlsqfdsqlyelwjtyloxwsvasrbqosblzbowlqjmyeilcvotdlaouxhdpoeloaovb",
"output": "YES"
},
{
"input": "hwlghueoemiqtjhhpashjsouyegdlvoyzeunlroypoprnhlyiwiuxrghekaylndhrhllllwhbebezoglydcvykllotrlaqtvmlla",
"output": "YES"
},
{
"input": "wshiaunnqnqxodholbipwhhjmyeblhgpeleblklpzwhdunmpqkbuzloetmwwxmeltkrcomulxauzlwmlklldjodozxryghsnwgcz",
"output": "YES"
},
{
"input": "shvksednttggehroewuiptvvxtrzgidravtnjwuqrlnnkxbplctzkckinpkgjopjfoxdbojtcvsuvablcbkrzajrlhgobkcxeqti",
"output": "YES"
},
{
"input": "hyyhddqhxhekehkwfhlnlsihzefwchzerevcjtokefplholrbvxlltdlafjxrfhleglrvlolojoqaolagtbeyogxlbgfolllslli",
"output": "YES"
},
{
"input": "iaagrdhhelxpdegueiulflquvlzidoprzkehthkldaytrjwhyhprwjxlltinxvuilxohqgjqcvkkdcuoliekcnlilwgqlnlzouoo",
"output": "YES"
},
{
"input": "wfluaeseldgxyvxpwuhkptdmlflnlhktwxiabsvkolsquymrmhzczzoybvlilhmvsuunggvgxzgyyffk",
"output": "NO"
},
{
"input": "loee",
"output": "NO"
},
{
"input": "izdipwylefqmjbuoznfglgcfvedeouflkeehxbasaqmiooppfsqlhprospqgxvzrcpwlfdddngoqvpwvggsnvvxhmjoslwjudjlo",
"output": "NO"
},
{
"input": "pplynflbjlseflaegzqpdxswgunhnlglqhycrbcwdfhclmcrwekkzsoosmfblljeenwfjyifcvxihhhbyhmhlkvtskeglaovjnsi",
"output": "YES"
},
{
"input": "xqjqmenkodmlhzyzmmvofdngktygbbxbzpluzcohohmalkoeuwfikblltaaigv",
"output": "NO"
},
{
"input": "hello",
"output": "YES"
},
{
"input": "oohell",
"output": "NO"
},
{
"input": "hell",
"output": "NO"
},
{
"input": "eloellohoelo",
"output": "NO"
},
{
"input": "helllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllo",
"output": "YES"
}
] | 1,667,601,138 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 40 | 62 | 0 | s=input()
search=["h","e","l","l","o"]
c=0
for i in s:
if i==search[c]:
c+=1
if c==5:
print("YES")
break;
if c<5:
print("NO") | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*.
Input Specification:
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
Output Specification:
If Vasya managed to say hello, print "YES", otherwise print "NO".
Demo Input:
['ahhellllloou\n', 'hlelo\n']
Demo Output:
['YES\n', 'NO\n']
Note:
none | ```python
s=input()
search=["h","e","l","l","o"]
c=0
for i in s:
if i==search[c]:
c+=1
if c==5:
print("YES")
break;
if c<5:
print("NO")
``` | 3.969 |
472 | A | Design Tutorial: Learn from Math | PROGRAMMING | 800 | [
"math",
"number theory"
] | null | null | One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that.
For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two primes". Let's modify it. How about a statement like that: "each integer no less than 12 can be expressed as the sum of two composite numbers." Not like the Goldbach's conjecture, I can prove this theorem.
You are given an integer *n* no less than 12, express it as a sum of two composite numbers. | The only line contains an integer *n* (12<=≤<=*n*<=≤<=106). | Output two composite integers *x* and *y* (1<=<<=*x*,<=*y*<=<<=*n*) such that *x*<=+<=*y*<==<=*n*. If there are multiple solutions, you can output any of them. | [
"12\n",
"15\n",
"23\n",
"1000000\n"
] | [
"4 8\n",
"6 9\n",
"8 15\n",
"500000 500000\n"
] | In the first example, 12 = 4 + 8 and both 4, 8 are composite numbers. You can output "6 6" or "8 4" as well.
In the second example, 15 = 6 + 9. Note that you can't output "1 14" because 1 is not a composite number. | 500 | [
{
"input": "12",
"output": "4 8"
},
{
"input": "15",
"output": "6 9"
},
{
"input": "23",
"output": "8 15"
},
{
"input": "1000000",
"output": "500000 500000"
},
{
"input": "63874",
"output": "4 63870"
},
{
"input": "14568",
"output": "4 14564"
},
{
"input": "192",
"output": "4 188"
},
{
"input": "86",
"output": "4 82"
},
{
"input": "46220",
"output": "4 46216"
},
{
"input": "57114",
"output": "4 57110"
},
{
"input": "869",
"output": "4 865"
},
{
"input": "738457",
"output": "4 738453"
},
{
"input": "58113",
"output": "6 58107"
},
{
"input": "4864",
"output": "4 4860"
},
{
"input": "15",
"output": "6 9"
},
{
"input": "74752",
"output": "4 74748"
},
{
"input": "6073",
"output": "4 6069"
},
{
"input": "1289",
"output": "4 1285"
},
{
"input": "20",
"output": "4 16"
},
{
"input": "58134",
"output": "4 58130"
},
{
"input": "57756",
"output": "4 57752"
},
{
"input": "765",
"output": "6 759"
},
{
"input": "59",
"output": "4 55"
},
{
"input": "991666",
"output": "4 991662"
},
{
"input": "70761",
"output": "4 70757"
},
{
"input": "13",
"output": "4 9"
},
{
"input": "999999",
"output": "4 999995"
},
{
"input": "17",
"output": "8 9"
},
{
"input": "21",
"output": "6 15"
},
{
"input": "19",
"output": "4 15"
},
{
"input": "100007",
"output": "6 100001"
},
{
"input": "999987",
"output": "6 999981"
},
{
"input": "22",
"output": "4 18"
}
] | 1,665,115,582 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 33 | 124 | 27,238,400 | import sys; input = sys.stdin.readline
is_prime = [False] * 2 + [True] * 999999
for i in range(2, int(1000000 ** 0.5) + 1):
if is_prime[i]:
for j in range(i * 2, 1000001, i):
is_prime[j] = False
n = int(input())
i = n // 2
j = n - n // 2
while is_prime[i] or is_prime[j]:
i -= 1
j += 1
print(i, j) | Title: Design Tutorial: Learn from Math
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that.
For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two primes". Let's modify it. How about a statement like that: "each integer no less than 12 can be expressed as the sum of two composite numbers." Not like the Goldbach's conjecture, I can prove this theorem.
You are given an integer *n* no less than 12, express it as a sum of two composite numbers.
Input Specification:
The only line contains an integer *n* (12<=≤<=*n*<=≤<=106).
Output Specification:
Output two composite integers *x* and *y* (1<=<<=*x*,<=*y*<=<<=*n*) such that *x*<=+<=*y*<==<=*n*. If there are multiple solutions, you can output any of them.
Demo Input:
['12\n', '15\n', '23\n', '1000000\n']
Demo Output:
['4 8\n', '6 9\n', '8 15\n', '500000 500000\n']
Note:
In the first example, 12 = 4 + 8 and both 4, 8 are composite numbers. You can output "6 6" or "8 4" as well.
In the second example, 15 = 6 + 9. Note that you can't output "1 14" because 1 is not a composite number. | ```python
import sys; input = sys.stdin.readline
is_prime = [False] * 2 + [True] * 999999
for i in range(2, int(1000000 ** 0.5) + 1):
if is_prime[i]:
for j in range(i * 2, 1000001, i):
is_prime[j] = False
n = int(input())
i = n // 2
j = n - n // 2
while is_prime[i] or is_prime[j]:
i -= 1
j += 1
print(i, j)
``` | 3 |
|
918 | A | Eleven | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Eleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly *n* characters.
Her friend suggested that her name should only consist of uppercase and lowercase letters 'O'. More precisely, they suggested that the *i*-th letter of her name should be 'O' (uppercase) if *i* is a member of Fibonacci sequence, and 'o' (lowercase) otherwise. The letters in the name are numbered from 1 to *n*. Fibonacci sequence is the sequence *f* where
- *f*1<==<=1, - *f*2<==<=1, - *f**n*<==<=*f**n*<=-<=2<=+<=*f**n*<=-<=1 (*n*<=><=2).
As her friends are too young to know what Fibonacci sequence is, they asked you to help Eleven determine her new name. | The first and only line of input contains an integer *n* (1<=≤<=*n*<=≤<=1000). | Print Eleven's new name on the first and only line of output. | [
"8\n",
"15\n"
] | [
"OOOoOooO\n",
"OOOoOooOooooOoo\n"
] | none | 500 | [
{
"input": "8",
"output": "OOOoOooO"
},
{
"input": "15",
"output": "OOOoOooOooooOoo"
},
{
"input": "85",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooo"
},
{
"input": "381",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooo"
},
{
"input": "805",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..."
},
{
"input": "1000",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..."
},
{
"input": "1",
"output": "O"
},
{
"input": "2",
"output": "OO"
},
{
"input": "3",
"output": "OOO"
},
{
"input": "5",
"output": "OOOoO"
},
{
"input": "17",
"output": "OOOoOooOooooOoooo"
},
{
"input": "49",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooo"
},
{
"input": "256",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooo"
},
{
"input": "512",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..."
},
{
"input": "933",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..."
},
{
"input": "61",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooo"
},
{
"input": "781",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..."
},
{
"input": "999",
"output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..."
}
] | 1,659,410,709 | 2,147,483,647 | Python 3 | OK | TESTS | 18 | 46 | 0 | n = int(input())
f1 = 0
f2 = 1
answer = ""
hold = []
f3 = f1 + f2
while f3 < n:
f3 = f1 + f2
hold.append(f3)
f1 = f2
f2 = f3
if n == 1:
print("O")
else:
for i in range(1, n + 1):
if hold.count(i) > 0:
answer = answer + "O"
else:
answer = answer + "o"
print(answer) | Title: Eleven
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Eleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly *n* characters.
Her friend suggested that her name should only consist of uppercase and lowercase letters 'O'. More precisely, they suggested that the *i*-th letter of her name should be 'O' (uppercase) if *i* is a member of Fibonacci sequence, and 'o' (lowercase) otherwise. The letters in the name are numbered from 1 to *n*. Fibonacci sequence is the sequence *f* where
- *f*1<==<=1, - *f*2<==<=1, - *f**n*<==<=*f**n*<=-<=2<=+<=*f**n*<=-<=1 (*n*<=><=2).
As her friends are too young to know what Fibonacci sequence is, they asked you to help Eleven determine her new name.
Input Specification:
The first and only line of input contains an integer *n* (1<=≤<=*n*<=≤<=1000).
Output Specification:
Print Eleven's new name on the first and only line of output.
Demo Input:
['8\n', '15\n']
Demo Output:
['OOOoOooO\n', 'OOOoOooOooooOoo\n']
Note:
none | ```python
n = int(input())
f1 = 0
f2 = 1
answer = ""
hold = []
f3 = f1 + f2
while f3 < n:
f3 = f1 + f2
hold.append(f3)
f1 = f2
f2 = f3
if n == 1:
print("O")
else:
for i in range(1, n + 1):
if hold.count(i) > 0:
answer = answer + "O"
else:
answer = answer + "o"
print(answer)
``` | 3 |
|
32 | B | Borze | PROGRAMMING | 800 | [
"expression parsing",
"implementation"
] | B. Borze | 2 | 256 | Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet. | The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes). | Output the decoded ternary number. It can have leading zeroes. | [
".-.--\n",
"--.\n",
"-..-.--\n"
] | [
"012",
"20",
"1012"
] | none | 1,000 | [
{
"input": ".-.--",
"output": "012"
},
{
"input": "--.",
"output": "20"
},
{
"input": "-..-.--",
"output": "1012"
},
{
"input": "---..",
"output": "210"
},
{
"input": "..--.---..",
"output": "0020210"
},
{
"input": "-.....----.",
"output": "10000220"
},
{
"input": ".",
"output": "0"
},
{
"input": "-.",
"output": "1"
},
{
"input": "--",
"output": "2"
},
{
"input": "..",
"output": "00"
},
{
"input": "--.",
"output": "20"
},
{
"input": ".--.",
"output": "020"
},
{
"input": ".-.-..",
"output": "0110"
},
{
"input": "----.-.",
"output": "2201"
},
{
"input": "-..--.-.",
"output": "10201"
},
{
"input": "..--..--.",
"output": "0020020"
},
{
"input": "-.-.---.--..-..-.-.-..-..-.--.",
"output": "112120010111010120"
},
{
"input": "---.-.-.------..-..-..-..-.-..-.--.-.-..-.-.-----..-.-.",
"output": "21112220010101011012011011221011"
},
{
"input": "-.-..--.-.-.-.-.-..-.-.-.---------.--.---..--...--.-----.-.-.-...--.-.-.---.------.--..-.--.-----.-...-..------",
"output": "11020111110111222212021020002022111100201121222020012022110010222"
},
{
"input": "-.-..-.--.---..---.-..---.-...-.-.----..-.---.-.---..-.--.---.-.-------.---.--....----.-.---.---.---.----.-----..---.-.-.-.-----.--.-------.-..",
"output": "110120210211021100112200121121012021122212120000220121212122022102111122120222110"
},
{
"input": ".-..-.-.---.-----.--.---...-.--.-.-....-..",
"output": "01011212212021001201100010"
},
{
"input": ".------.-.---..--...-..-..-.-.-.--.--.-..-.--...-.-.---.-.-.------..--..-.---..----.-..-.--.---.-.----.-.---...-.-.-.-----.-.-.---.---.-.....-.-...-----.-...-.---.-..-.-----.--...---.-.-..-.--.-.---..",
"output": "022201210200010101112020101200011211122200200121022010120211220121001112211121211000011002211001211012212000211101201210"
},
{
"input": ".-.--.---.-----.-.-----.-.-..-----..-..----..--.-.--.----..---.---..-.-.-----..-------.----..----.-..---...-----..-..-----...-..-.-.-----....---..---..-.-----...-.--...--.-.---.-.-.-.-.-...---..----.",
"output": "01202122112211102210102200201202200212101122102221220022010210022101022100101122100021021012210012000201211111100210220"
},
{
"input": "..-.-.-.---.-.-.-..-.-..-.-.---.-------.---..-----.---....-.---.--.--.-.---.---------.-..---.-.-.--..---.---.-.---.-.-..-.-..-.-.-.----.--.-....--------.-.---..----.------.-.-.--.--.-----.-----.----",
"output": "0011121111011011212221210221210001212020121222211021112002121121110110111220201000222201210220222011202022122122"
},
{
"input": "-..-------.------.-..--.-.-..--.-.-..-----..-.-.-..-..-..--.---..-----..---..-..--.-..-.-.---...-.....-------.---.-----.-...-.-...-.-.---.---.-----.--.--...-.--..-.-..-...-.-.-.-.---..---.-..-.-.-.-..",
"output": "102221222010201102011022101110101020210221021010201011210010000222121221100110011212122120200012001101001111210211011110"
},
{
"input": ".-.----.-.--..-.-.-.-..----..-.-...--.-.---.---.-------..-.--..-......--.------.--.----.--...-.--.--..-----..-.....--.--.-.-.------..--------.----------..-.---.----.---.-..--..-.....-..------.--.",
"output": "012201200111102200110020121212221012001000002022202022020001202002210100002020112220022220222220012122021102001000010222020"
},
{
"input": "------.-----.-....--.-.----.-.---.-.-..---.-.---.-----..-...-.-.---..-.-.-..-.-.-...-.-.-.----..--.------.----.-..-.--...-.-------...-.-..-.-.--.--.---..--..--------.--.-.-.---.-.-.-...----.--..-.--..",
"output": "222022110002012201211102112122101001121011101110011122002022202201012000122210011011202021020022220201121111002202001200"
},
{
"input": "-.---...----...--.--...-.--.----",
"output": "121002200020200012022"
},
{
"input": "--.--.--.---.--.-.---.-.-..-..--.-..---.-.....-..---.-----.--...-.-.-------.-.--.-.----.-..-.------.",
"output": "202020212012111010201021100001021221200011222112012201012220"
}
] | 1,587,240,274 | 2,147,483,647 | PyPy 3 | OK | TESTS | 30 | 280 | 0 | it = iter(input())
for ch in it:
if ch == '.':
x = '0'
elif next(it) == '.':
x = '1'
else:
x = '2'
print(x, end='')
| Title: Borze
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet.
Input Specification:
The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes).
Output Specification:
Output the decoded ternary number. It can have leading zeroes.
Demo Input:
['.-.--\n', '--.\n', '-..-.--\n']
Demo Output:
['012', '20', '1012']
Note:
none | ```python
it = iter(input())
for ch in it:
if ch == '.':
x = '0'
elif next(it) == '.':
x = '1'
else:
x = '2'
print(x, end='')
``` | 3.93 |
376 | B | I.O.U. | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Imagine that there is a group of three friends: A, B and С. A owes B 20 rubles and B owes C 20 rubles. The total sum of the debts is 40 rubles. You can see that the debts are not organized in a very optimal manner. Let's rearrange them like that: assume that A owes C 20 rubles and B doesn't owe anything to anybody. The debts still mean the same but the total sum of the debts now equals 20 rubles.
This task is a generalisation of a described example. Imagine that your group of friends has *n* people and you know the debts between the people. Optimize the given debts without changing their meaning. In other words, finally for each friend the difference between the total money he should give and the total money he should take must be the same. Print the minimum sum of all debts in the optimal rearrangement of the debts. See the notes to the test samples to better understand the problem. | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100; 0<=≤<=*m*<=≤<=104). The next *m* lines contain the debts. The *i*-th line contains three integers *a**i*,<=*b**i*,<=*c**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*; *a**i*<=≠<=*b**i*; 1<=≤<=*c**i*<=≤<=100), which mean that person *a**i* owes person *b**i* *c**i* rubles.
Assume that the people are numbered by integers from 1 to *n*.
It is guaranteed that the same pair of people occurs at most once in the input. The input doesn't simultaneously contain pair of people (*x*,<=*y*) and pair of people (*y*,<=*x*). | Print a single integer — the minimum sum of debts in the optimal rearrangement. | [
"5 3\n1 2 10\n2 3 1\n2 4 1\n",
"3 0\n",
"4 3\n1 2 1\n2 3 1\n3 1 1\n"
] | [
"10\n",
"0\n",
"0\n"
] | In the first sample, you can assume that person number 1 owes 8 rubles to person number 2, 1 ruble to person number 3 and 1 ruble to person number 4. He doesn't owe anybody else anything. In the end, the total debt equals 10.
In the second sample, there are no debts.
In the third sample, you can annul all the debts. | 1,000 | [
{
"input": "5 3\n1 2 10\n2 3 1\n2 4 1",
"output": "10"
},
{
"input": "3 0",
"output": "0"
},
{
"input": "4 3\n1 2 1\n2 3 1\n3 1 1",
"output": "0"
},
{
"input": "20 28\n1 5 6\n1 12 7\n1 13 4\n1 15 7\n1 20 3\n2 4 1\n2 15 6\n3 5 3\n3 8 10\n3 13 8\n3 20 6\n4 6 10\n4 12 8\n4 19 5\n5 17 8\n6 9 9\n6 16 2\n6 19 9\n7 14 6\n8 9 3\n8 16 10\n9 11 7\n9 17 8\n11 13 8\n11 17 17\n11 19 1\n15 20 2\n17 20 1",
"output": "124"
},
{
"input": "20 36\n1 2 13\n1 3 1\n1 6 4\n1 12 8\n1 13 9\n1 15 3\n1 18 4\n2 10 2\n2 15 2\n2 18 6\n3 7 8\n3 16 19\n4 7 1\n4 18 4\n5 9 2\n5 15 9\n5 17 4\n5 18 5\n6 11 7\n6 13 1\n6 14 9\n7 10 4\n7 12 10\n7 15 9\n7 17 8\n8 14 4\n10 13 8\n10 19 9\n11 12 5\n12 17 6\n13 15 8\n13 19 4\n14 15 9\n14 16 8\n17 19 8\n17 20 7",
"output": "147"
},
{
"input": "20 40\n1 13 4\n2 3 3\n2 4 5\n2 7 7\n2 17 10\n3 5 3\n3 6 9\n3 10 4\n3 12 2\n3 13 2\n3 14 3\n4 5 4\n4 8 7\n4 13 9\n5 6 14\n5 14 5\n7 11 5\n7 12 13\n7 15 7\n8 14 5\n8 16 7\n8 18 17\n9 11 8\n9 19 19\n10 12 4\n10 16 3\n10 18 10\n10 20 9\n11 13 9\n11 20 2\n12 13 8\n12 18 2\n12 20 3\n13 17 1\n13 20 4\n14 16 8\n16 19 3\n18 19 3\n18 20 7\n19 20 10",
"output": "165"
},
{
"input": "50 10\n1 5 1\n2 34 2\n3 8 10\n5 28 4\n7 28 6\n13 49 9\n15 42 7\n16 26 7\n18 47 5\n20 41 10",
"output": "60"
},
{
"input": "50 46\n1 6 10\n1 18 1\n1 24 10\n1 33 2\n1 40 8\n3 16 7\n4 26 8\n4 32 2\n4 34 6\n5 29 8\n6 44 3\n8 20 5\n8 42 13\n10 13 5\n10 25 7\n10 27 9\n10 29 10\n11 23 4\n12 28 7\n12 30 10\n12 40 10\n13 18 2\n13 33 2\n14 15 7\n14 43 10\n14 47 3\n16 27 10\n17 21 6\n17 30 9\n19 40 4\n22 24 8\n22 25 7\n22 38 18\n25 38 1\n27 31 7\n27 40 8\n30 36 8\n31 34 1\n32 49 6\n33 35 4\n33 50 7\n38 47 1\n42 47 2\n42 50 5\n43 44 9\n47 50 5",
"output": "228"
},
{
"input": "100 48\n1 56 6\n2 42 3\n3 52 1\n9 50 8\n10 96 8\n11 39 2\n12 51 6\n12 68 7\n13 40 5\n14 18 10\n14 70 6\n15 37 4\n15 38 8\n15 82 6\n15 85 5\n16 48 4\n16 50 9\n16 71 9\n17 18 3\n17 100 10\n20 73 3\n22 32 9\n22 89 9\n23 53 3\n24 53 1\n27 78 10\n30 50 5\n33 94 8\n34 87 9\n35 73 3\n36 51 8\n37 88 10\n37 97 2\n40 47 8\n40 90 6\n44 53 3\n44 65 3\n47 48 8\n48 72 10\n49 98 2\n53 68 10\n53 71 9\n57 62 2\n63 76 10\n66 90 9\n71 76 8\n72 80 5\n75 77 7",
"output": "253"
},
{
"input": "4 3\n1 4 1\n2 3 1\n4 2 2",
"output": "2"
}
] | 1,600,703,383 | 2,147,483,647 | PyPy 3 | OK | TESTS | 29 | 171 | 3,072,000 | from sys import stdin
a,b=map(int,stdin.readline().split())
z=[[0]*101 for i in " "*101]
for _ in " "*b:
u,v,w=map(int,stdin.readline().split())
z[u][v]+=w
for i in range(1,101):
for j in range(1,101):
if z[i][j]:
for k in range(1,101):
if (i==k):m=min(z[i][j],z[j][k]);z[i][j]-=m;z[j][k]-=m;continue
m=min(z[j][k],z[i][j]);z[i][k]+=m;z[j][k]-=m;z[i][j]-=m
s=0
for i in range(1,101):s+=sum(z[i])
print(s) | Title: I.O.U.
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Imagine that there is a group of three friends: A, B and С. A owes B 20 rubles and B owes C 20 rubles. The total sum of the debts is 40 rubles. You can see that the debts are not organized in a very optimal manner. Let's rearrange them like that: assume that A owes C 20 rubles and B doesn't owe anything to anybody. The debts still mean the same but the total sum of the debts now equals 20 rubles.
This task is a generalisation of a described example. Imagine that your group of friends has *n* people and you know the debts between the people. Optimize the given debts without changing their meaning. In other words, finally for each friend the difference between the total money he should give and the total money he should take must be the same. Print the minimum sum of all debts in the optimal rearrangement of the debts. See the notes to the test samples to better understand the problem.
Input Specification:
The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100; 0<=≤<=*m*<=≤<=104). The next *m* lines contain the debts. The *i*-th line contains three integers *a**i*,<=*b**i*,<=*c**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*; *a**i*<=≠<=*b**i*; 1<=≤<=*c**i*<=≤<=100), which mean that person *a**i* owes person *b**i* *c**i* rubles.
Assume that the people are numbered by integers from 1 to *n*.
It is guaranteed that the same pair of people occurs at most once in the input. The input doesn't simultaneously contain pair of people (*x*,<=*y*) and pair of people (*y*,<=*x*).
Output Specification:
Print a single integer — the minimum sum of debts in the optimal rearrangement.
Demo Input:
['5 3\n1 2 10\n2 3 1\n2 4 1\n', '3 0\n', '4 3\n1 2 1\n2 3 1\n3 1 1\n']
Demo Output:
['10\n', '0\n', '0\n']
Note:
In the first sample, you can assume that person number 1 owes 8 rubles to person number 2, 1 ruble to person number 3 and 1 ruble to person number 4. He doesn't owe anybody else anything. In the end, the total debt equals 10.
In the second sample, there are no debts.
In the third sample, you can annul all the debts. | ```python
from sys import stdin
a,b=map(int,stdin.readline().split())
z=[[0]*101 for i in " "*101]
for _ in " "*b:
u,v,w=map(int,stdin.readline().split())
z[u][v]+=w
for i in range(1,101):
for j in range(1,101):
if z[i][j]:
for k in range(1,101):
if (i==k):m=min(z[i][j],z[j][k]);z[i][j]-=m;z[j][k]-=m;continue
m=min(z[j][k],z[i][j]);z[i][k]+=m;z[j][k]-=m;z[i][j]-=m
s=0
for i in range(1,101):s+=sum(z[i])
print(s)
``` | 3 |
|
433 | B | Kuriyama Mirai's Stones | PROGRAMMING | 1,200 | [
"dp",
"implementation",
"sortings"
] | null | null | Kuriyama Mirai has killed many monsters and got many (namely *n*) stones. She numbers the stones from 1 to *n*. The cost of the *i*-th stone is *v**i*. Kuriyama Mirai wants to know something about these stones so she will ask you two kinds of questions:
1. She will tell you two numbers, *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*), and you should tell her . 1. Let *u**i* be the cost of the *i*-th cheapest stone (the cost that will be on the *i*-th place if we arrange all the stone costs in non-decreasing order). This time she will tell you two numbers, *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*), and you should tell her .
For every question you should give the correct answer, or Kuriyama Mirai will say "fuyukai desu" and then become unhappy. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers: *v*1,<=*v*2,<=...,<=*v**n* (1<=≤<=*v**i*<=≤<=109) — costs of the stones.
The third line contains an integer *m* (1<=≤<=*m*<=≤<=105) — the number of Kuriyama Mirai's questions. Then follow *m* lines, each line contains three integers *type*, *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*; 1<=≤<=*type*<=≤<=2), describing a question. If *type* equal to 1, then you should output the answer for the first question, else you should output the answer for the second one. | Print *m* lines. Each line must contain an integer — the answer to Kuriyama Mirai's question. Print the answers to the questions in the order of input. | [
"6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6\n",
"4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2\n"
] | [
"24\n9\n28\n",
"10\n15\n5\n15\n5\n5\n2\n12\n3\n5\n"
] | Please note that the answers to the questions may overflow 32-bit integer type. | 1,500 | [
{
"input": "6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6",
"output": "24\n9\n28"
},
{
"input": "4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2",
"output": "10\n15\n5\n15\n5\n5\n2\n12\n3\n5"
},
{
"input": "4\n2 2 3 6\n9\n2 2 3\n1 1 3\n2 2 3\n2 2 3\n2 2 2\n1 1 3\n1 1 3\n2 1 4\n1 1 2",
"output": "5\n7\n5\n5\n2\n7\n7\n13\n4"
},
{
"input": "18\n26 46 56 18 78 88 86 93 13 77 21 84 59 61 5 74 72 52\n25\n1 10 10\n1 9 13\n2 13 17\n1 8 14\n2 2 6\n1 12 16\n2 15 17\n2 3 6\n1 3 13\n2 8 9\n2 17 17\n1 17 17\n2 5 10\n2 1 18\n1 4 16\n1 1 13\n1 1 8\n2 7 11\n2 6 12\n1 5 9\n1 4 5\n2 7 15\n1 8 8\n1 8 14\n1 3 7",
"output": "77\n254\n413\n408\n124\n283\n258\n111\n673\n115\n88\n72\n300\n1009\n757\n745\n491\n300\n420\n358\n96\n613\n93\n408\n326"
},
{
"input": "56\n43 100 44 66 65 11 26 75 96 77 5 15 75 96 11 44 11 97 75 53 33 26 32 33 90 26 68 72 5 44 53 26 33 88 68 25 84 21 25 92 1 84 21 66 94 35 76 51 11 95 67 4 61 3 34 18\n27\n1 20 38\n1 11 46\n2 42 53\n1 8 11\n2 11 42\n2 35 39\n2 37 41\n1 48 51\n1 32 51\n1 36 40\n1 31 56\n1 18 38\n2 9 51\n1 7 48\n1 15 52\n1 27 31\n2 5 19\n2 35 50\n1 31 34\n1 2 7\n2 15 33\n2 46 47\n1 26 28\n2 3 29\n1 23 45\n2 29 55\n1 14 29",
"output": "880\n1727\n1026\n253\n1429\n335\n350\n224\n1063\n247\n1236\n1052\n2215\n2128\n1840\n242\n278\n1223\n200\n312\n722\n168\n166\n662\n1151\n2028\n772"
},
{
"input": "18\n38 93 48 14 69 85 26 47 71 11 57 9 38 65 72 78 52 47\n38\n2 10 12\n1 6 18\n2 2 2\n1 3 15\n2 1 16\n2 5 13\n1 9 17\n1 2 15\n2 5 17\n1 15 15\n2 4 11\n2 3 4\n2 2 5\n2 1 17\n2 6 16\n2 8 16\n2 8 14\n1 9 12\n2 8 13\n2 1 14\n2 5 13\n1 2 3\n1 9 14\n2 12 15\n2 3 3\n2 9 13\n2 4 12\n2 11 14\n2 6 16\n1 8 14\n1 12 15\n2 3 4\n1 3 5\n2 4 14\n1 6 6\n2 7 14\n2 7 18\n1 8 12",
"output": "174\n658\n11\n612\n742\n461\n453\n705\n767\n72\n353\n40\n89\n827\n644\n559\n409\n148\n338\n592\n461\n141\n251\n277\n14\n291\n418\n262\n644\n298\n184\n40\n131\n558\n85\n456\n784\n195"
},
{
"input": "1\n2\n10\n1 1 1\n1 1 1\n2 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n2 1 1\n1 1 1\n1 1 1",
"output": "2\n2\n2\n2\n2\n2\n2\n2\n2\n2"
},
{
"input": "2\n1 5\n8\n2 1 2\n1 1 1\n1 1 2\n1 1 1\n2 2 2\n2 1 2\n1 1 1\n1 2 2",
"output": "6\n1\n6\n1\n5\n6\n1\n5"
},
{
"input": "8\n2 6 4 6 8 4 7 7\n9\n2 6 8\n1 2 3\n2 3 4\n2 1 2\n2 4 5\n1 3 8\n2 4 4\n2 2 4\n1 2 4",
"output": "22\n10\n10\n6\n12\n36\n6\n14\n16"
},
{
"input": "4\n1 1 2 8\n9\n1 2 4\n1 2 4\n1 1 2\n2 3 4\n2 1 1\n1 2 3\n2 3 4\n1 1 4\n1 1 4",
"output": "11\n11\n2\n10\n1\n3\n10\n12\n12"
},
{
"input": "5\n8 8 1 10 7\n5\n1 2 2\n1 1 4\n1 3 3\n1 2 2\n1 2 5",
"output": "8\n27\n1\n8\n26"
},
{
"input": "10\n10 3 3 2 1 2 7 1 1 1\n4\n2 10 10\n2 6 6\n1 5 10\n1 6 8",
"output": "10\n2\n13\n10"
},
{
"input": "6\n6 6 3 8 5 4\n3\n2 2 3\n2 1 5\n1 1 5",
"output": "9\n24\n28"
},
{
"input": "1\n1\n2\n1 1 1\n2 1 1",
"output": "1\n1"
}
] | 1,624,419,166 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 2,000 | 2,560,000 | n = int(input())
arr = list(map(int,input().split()))
pf = [arr[0]]
for i in range(1,n):
pf.append(pf[i-1]+arr[i])
t = int(input())
for x in range(1,t+1):
t,l,r = map(int,input().split())
if (t == 1):
if (l-1 == 0):
print(pf[r-1])
else:
print(pf[r-1]-pf[l-2])
else:
dup = arr
dup.sort()
pf1 = [dup[0]]
for i in range(1,n):
pf1.append(pf1[i-1]+dup[i])
if (l-1 == 0):
print(pf1[r-1])
else:
print(pf1[r-1]-pf1[l-2])
| Title: Kuriyama Mirai's Stones
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kuriyama Mirai has killed many monsters and got many (namely *n*) stones. She numbers the stones from 1 to *n*. The cost of the *i*-th stone is *v**i*. Kuriyama Mirai wants to know something about these stones so she will ask you two kinds of questions:
1. She will tell you two numbers, *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*), and you should tell her . 1. Let *u**i* be the cost of the *i*-th cheapest stone (the cost that will be on the *i*-th place if we arrange all the stone costs in non-decreasing order). This time she will tell you two numbers, *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*), and you should tell her .
For every question you should give the correct answer, or Kuriyama Mirai will say "fuyukai desu" and then become unhappy.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers: *v*1,<=*v*2,<=...,<=*v**n* (1<=≤<=*v**i*<=≤<=109) — costs of the stones.
The third line contains an integer *m* (1<=≤<=*m*<=≤<=105) — the number of Kuriyama Mirai's questions. Then follow *m* lines, each line contains three integers *type*, *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*; 1<=≤<=*type*<=≤<=2), describing a question. If *type* equal to 1, then you should output the answer for the first question, else you should output the answer for the second one.
Output Specification:
Print *m* lines. Each line must contain an integer — the answer to Kuriyama Mirai's question. Print the answers to the questions in the order of input.
Demo Input:
['6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6\n', '4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2\n']
Demo Output:
['24\n9\n28\n', '10\n15\n5\n15\n5\n5\n2\n12\n3\n5\n']
Note:
Please note that the answers to the questions may overflow 32-bit integer type. | ```python
n = int(input())
arr = list(map(int,input().split()))
pf = [arr[0]]
for i in range(1,n):
pf.append(pf[i-1]+arr[i])
t = int(input())
for x in range(1,t+1):
t,l,r = map(int,input().split())
if (t == 1):
if (l-1 == 0):
print(pf[r-1])
else:
print(pf[r-1]-pf[l-2])
else:
dup = arr
dup.sort()
pf1 = [dup[0]]
for i in range(1,n):
pf1.append(pf1[i-1]+dup[i])
if (l-1 == 0):
print(pf1[r-1])
else:
print(pf1[r-1]-pf1[l-2])
``` | 0 |
|
734 | A | Anton and Danik | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Anton likes to play chess, and so does his friend Danik.
Once they have played *n* games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie.
Now Anton wonders, who won more games, he or Danik? Help him determine this. | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of games played.
The second line contains a string *s*, consisting of *n* uppercase English letters 'A' and 'D' — the outcome of each of the games. The *i*-th character of the string is equal to 'A' if the Anton won the *i*-th game and 'D' if Danik won the *i*-th game. | If Anton won more games than Danik, print "Anton" (without quotes) in the only line of the output.
If Danik won more games than Anton, print "Danik" (without quotes) in the only line of the output.
If Anton and Danik won the same number of games, print "Friendship" (without quotes). | [
"6\nADAAAA\n",
"7\nDDDAADA\n",
"6\nDADADA\n"
] | [
"Anton\n",
"Danik\n",
"Friendship\n"
] | In the first sample, Anton won 6 games, while Danik — only 1. Hence, the answer is "Anton".
In the second sample, Anton won 3 games and Danik won 4 games, so the answer is "Danik".
In the third sample, both Anton and Danik won 3 games and the answer is "Friendship". | 500 | [
{
"input": "6\nADAAAA",
"output": "Anton"
},
{
"input": "7\nDDDAADA",
"output": "Danik"
},
{
"input": "6\nDADADA",
"output": "Friendship"
},
{
"input": "10\nDDDDADDADD",
"output": "Danik"
},
{
"input": "40\nAAAAAAAAADDAAAAAAAAAAADADDAAAAAAAAAAADAA",
"output": "Anton"
},
{
"input": "200\nDDDDDDDADDDDDDAADADAADAAADAADADAAADDDADDDDDDADDDAADDDAADADDDDDADDDAAAADAAADDDDDAAADAADDDAAAADDADADDDAADDAADAAADAADAAAADDAADDADAAAADADDDAAAAAADDAADAADAADADDDAAADAAAADADDADAAAAAADADADDDADDDAADDADDDAAAAD",
"output": "Friendship"
},
{
"input": "1\nA",
"output": "Anton"
},
{
"input": "1\nD",
"output": "Danik"
},
{
"input": "2\nDA",
"output": "Friendship"
},
{
"input": "4\nDADA",
"output": "Friendship"
},
{
"input": "4\nDAAD",
"output": "Friendship"
},
{
"input": "3\nADD",
"output": "Danik"
},
{
"input": "3\nDAD",
"output": "Danik"
},
{
"input": "2\nDA",
"output": "Friendship"
},
{
"input": "379\nAADAAAAAADDAAAAAADAADADADDAAAAADADDAADAAAADDDADAAAAAAADAADAAAAAAADAAAAAAAAADAAAAAAADAAAAAAAAAAADDDADAAAAAAAADAADADAAAADAAAAAAAAAAAAAAAAADAAAADDDAADAAAAAAADAAADAAADAADDDADDAAADAAAAAADDDADDDAAADAAAADAAAAAAAAADAAADAAAAAAAAADAAAAAAAAAAAAAAAAAADADAAAAAAAAAAADAAAAADAAAADAAAAAAAAAAAAADADAADAAAAAAAADAADAAAAAAAADAAAAAAAADDDAAAAAADAAADAAAAAADAADAAAAAADAAAADADAADAAAAAADAAAADAADDAADAADAAA",
"output": "Anton"
}
] | 1,692,595,681 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 46 | 102,400 | n=int(input())
stroka=input()
counter1=0
counter2=0
for char in stroka:
if char=='A':
counter1+=1
else:
counter2+=1
if counter1>counter2:
print("Anton")
elif counter2>counter1:
print("Danik")
else:print("Friendship") | Title: Anton and Danik
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anton likes to play chess, and so does his friend Danik.
Once they have played *n* games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie.
Now Anton wonders, who won more games, he or Danik? Help him determine this.
Input Specification:
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of games played.
The second line contains a string *s*, consisting of *n* uppercase English letters 'A' and 'D' — the outcome of each of the games. The *i*-th character of the string is equal to 'A' if the Anton won the *i*-th game and 'D' if Danik won the *i*-th game.
Output Specification:
If Anton won more games than Danik, print "Anton" (without quotes) in the only line of the output.
If Danik won more games than Anton, print "Danik" (without quotes) in the only line of the output.
If Anton and Danik won the same number of games, print "Friendship" (without quotes).
Demo Input:
['6\nADAAAA\n', '7\nDDDAADA\n', '6\nDADADA\n']
Demo Output:
['Anton\n', 'Danik\n', 'Friendship\n']
Note:
In the first sample, Anton won 6 games, while Danik — only 1. Hence, the answer is "Anton".
In the second sample, Anton won 3 games and Danik won 4 games, so the answer is "Danik".
In the third sample, both Anton and Danik won 3 games and the answer is "Friendship". | ```python
n=int(input())
stroka=input()
counter1=0
counter2=0
for char in stroka:
if char=='A':
counter1+=1
else:
counter2+=1
if counter1>counter2:
print("Anton")
elif counter2>counter1:
print("Danik")
else:print("Friendship")
``` | 3 |
|
670 | A | Holidays | PROGRAMMING | 900 | [
"brute force",
"constructive algorithms",
"greedy",
"math"
] | null | null | On the planet Mars a year lasts exactly *n* days (there are no leap years on Mars). But Martians have the same weeks as earthlings — 5 work days and then 2 days off. Your task is to determine the minimum possible and the maximum possible number of days off per year on Mars. | The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=1<=000<=000) — the number of days in a year on Mars. | Print two integers — the minimum possible and the maximum possible number of days off per year on Mars. | [
"14\n",
"2\n"
] | [
"4 4\n",
"0 2\n"
] | In the first sample there are 14 days in a year on Mars, and therefore independently of the day a year starts with there will be exactly 4 days off .
In the second sample there are only 2 days in a year on Mars, and they can both be either work days or days off. | 500 | [
{
"input": "14",
"output": "4 4"
},
{
"input": "2",
"output": "0 2"
},
{
"input": "1",
"output": "0 1"
},
{
"input": "3",
"output": "0 2"
},
{
"input": "4",
"output": "0 2"
},
{
"input": "5",
"output": "0 2"
},
{
"input": "6",
"output": "1 2"
},
{
"input": "7",
"output": "2 2"
},
{
"input": "8",
"output": "2 3"
},
{
"input": "9",
"output": "2 4"
},
{
"input": "10",
"output": "2 4"
},
{
"input": "11",
"output": "2 4"
},
{
"input": "12",
"output": "2 4"
},
{
"input": "13",
"output": "3 4"
},
{
"input": "1000000",
"output": "285714 285715"
},
{
"input": "16",
"output": "4 6"
},
{
"input": "17",
"output": "4 6"
},
{
"input": "18",
"output": "4 6"
},
{
"input": "19",
"output": "4 6"
},
{
"input": "20",
"output": "5 6"
},
{
"input": "21",
"output": "6 6"
},
{
"input": "22",
"output": "6 7"
},
{
"input": "23",
"output": "6 8"
},
{
"input": "24",
"output": "6 8"
},
{
"input": "25",
"output": "6 8"
},
{
"input": "26",
"output": "6 8"
},
{
"input": "27",
"output": "7 8"
},
{
"input": "28",
"output": "8 8"
},
{
"input": "29",
"output": "8 9"
},
{
"input": "30",
"output": "8 10"
},
{
"input": "100",
"output": "28 30"
},
{
"input": "99",
"output": "28 29"
},
{
"input": "98",
"output": "28 28"
},
{
"input": "97",
"output": "27 28"
},
{
"input": "96",
"output": "26 28"
},
{
"input": "95",
"output": "26 28"
},
{
"input": "94",
"output": "26 28"
},
{
"input": "93",
"output": "26 28"
},
{
"input": "92",
"output": "26 27"
},
{
"input": "91",
"output": "26 26"
},
{
"input": "90",
"output": "25 26"
},
{
"input": "89",
"output": "24 26"
},
{
"input": "88",
"output": "24 26"
},
{
"input": "87",
"output": "24 26"
},
{
"input": "86",
"output": "24 26"
},
{
"input": "85",
"output": "24 25"
},
{
"input": "84",
"output": "24 24"
},
{
"input": "83",
"output": "23 24"
},
{
"input": "82",
"output": "22 24"
},
{
"input": "81",
"output": "22 24"
},
{
"input": "80",
"output": "22 24"
},
{
"input": "1000",
"output": "285 286"
},
{
"input": "999",
"output": "284 286"
},
{
"input": "998",
"output": "284 286"
},
{
"input": "997",
"output": "284 286"
},
{
"input": "996",
"output": "284 286"
},
{
"input": "995",
"output": "284 285"
},
{
"input": "994",
"output": "284 284"
},
{
"input": "993",
"output": "283 284"
},
{
"input": "992",
"output": "282 284"
},
{
"input": "991",
"output": "282 284"
},
{
"input": "990",
"output": "282 284"
},
{
"input": "989",
"output": "282 284"
},
{
"input": "988",
"output": "282 283"
},
{
"input": "987",
"output": "282 282"
},
{
"input": "986",
"output": "281 282"
},
{
"input": "985",
"output": "280 282"
},
{
"input": "984",
"output": "280 282"
},
{
"input": "983",
"output": "280 282"
},
{
"input": "982",
"output": "280 282"
},
{
"input": "981",
"output": "280 281"
},
{
"input": "980",
"output": "280 280"
},
{
"input": "10000",
"output": "2856 2858"
},
{
"input": "9999",
"output": "2856 2858"
},
{
"input": "9998",
"output": "2856 2858"
},
{
"input": "9997",
"output": "2856 2857"
},
{
"input": "9996",
"output": "2856 2856"
},
{
"input": "9995",
"output": "2855 2856"
},
{
"input": "9994",
"output": "2854 2856"
},
{
"input": "9993",
"output": "2854 2856"
},
{
"input": "9992",
"output": "2854 2856"
},
{
"input": "9991",
"output": "2854 2856"
},
{
"input": "9990",
"output": "2854 2855"
},
{
"input": "9989",
"output": "2854 2854"
},
{
"input": "9988",
"output": "2853 2854"
},
{
"input": "9987",
"output": "2852 2854"
},
{
"input": "9986",
"output": "2852 2854"
},
{
"input": "9985",
"output": "2852 2854"
},
{
"input": "9984",
"output": "2852 2854"
},
{
"input": "9983",
"output": "2852 2853"
},
{
"input": "9982",
"output": "2852 2852"
},
{
"input": "9981",
"output": "2851 2852"
},
{
"input": "9980",
"output": "2850 2852"
},
{
"input": "100000",
"output": "28570 28572"
},
{
"input": "99999",
"output": "28570 28572"
},
{
"input": "99998",
"output": "28570 28572"
},
{
"input": "99997",
"output": "28570 28572"
},
{
"input": "99996",
"output": "28570 28571"
},
{
"input": "99995",
"output": "28570 28570"
},
{
"input": "99994",
"output": "28569 28570"
},
{
"input": "99993",
"output": "28568 28570"
},
{
"input": "99992",
"output": "28568 28570"
},
{
"input": "99991",
"output": "28568 28570"
},
{
"input": "99990",
"output": "28568 28570"
},
{
"input": "99989",
"output": "28568 28569"
},
{
"input": "99988",
"output": "28568 28568"
},
{
"input": "99987",
"output": "28567 28568"
},
{
"input": "99986",
"output": "28566 28568"
},
{
"input": "99985",
"output": "28566 28568"
},
{
"input": "99984",
"output": "28566 28568"
},
{
"input": "99983",
"output": "28566 28568"
},
{
"input": "99982",
"output": "28566 28567"
},
{
"input": "99981",
"output": "28566 28566"
},
{
"input": "99980",
"output": "28565 28566"
},
{
"input": "999999",
"output": "285714 285714"
},
{
"input": "999998",
"output": "285713 285714"
},
{
"input": "999997",
"output": "285712 285714"
},
{
"input": "999996",
"output": "285712 285714"
},
{
"input": "999995",
"output": "285712 285714"
},
{
"input": "999994",
"output": "285712 285714"
},
{
"input": "999993",
"output": "285712 285713"
},
{
"input": "999992",
"output": "285712 285712"
},
{
"input": "999991",
"output": "285711 285712"
},
{
"input": "999990",
"output": "285710 285712"
},
{
"input": "999989",
"output": "285710 285712"
},
{
"input": "999988",
"output": "285710 285712"
},
{
"input": "999987",
"output": "285710 285712"
},
{
"input": "999986",
"output": "285710 285711"
},
{
"input": "999985",
"output": "285710 285710"
},
{
"input": "999984",
"output": "285709 285710"
},
{
"input": "999983",
"output": "285708 285710"
},
{
"input": "999982",
"output": "285708 285710"
},
{
"input": "999981",
"output": "285708 285710"
},
{
"input": "999980",
"output": "285708 285710"
},
{
"input": "234123",
"output": "66892 66893"
},
{
"input": "234122",
"output": "66892 66892"
},
{
"input": "234121",
"output": "66891 66892"
},
{
"input": "234120",
"output": "66890 66892"
},
{
"input": "234119",
"output": "66890 66892"
},
{
"input": "234118",
"output": "66890 66892"
},
{
"input": "234117",
"output": "66890 66892"
},
{
"input": "234116",
"output": "66890 66891"
},
{
"input": "234115",
"output": "66890 66890"
},
{
"input": "234114",
"output": "66889 66890"
},
{
"input": "234113",
"output": "66888 66890"
},
{
"input": "234112",
"output": "66888 66890"
},
{
"input": "234111",
"output": "66888 66890"
},
{
"input": "234110",
"output": "66888 66890"
},
{
"input": "234109",
"output": "66888 66889"
},
{
"input": "234108",
"output": "66888 66888"
},
{
"input": "234107",
"output": "66887 66888"
},
{
"input": "234106",
"output": "66886 66888"
},
{
"input": "234105",
"output": "66886 66888"
},
{
"input": "234104",
"output": "66886 66888"
},
{
"input": "234103",
"output": "66886 66888"
},
{
"input": "868531",
"output": "248151 248152"
},
{
"input": "868530",
"output": "248150 248152"
},
{
"input": "868529",
"output": "248150 248152"
},
{
"input": "868528",
"output": "248150 248152"
},
{
"input": "868527",
"output": "248150 248152"
},
{
"input": "868526",
"output": "248150 248151"
},
{
"input": "868525",
"output": "248150 248150"
},
{
"input": "868524",
"output": "248149 248150"
},
{
"input": "868523",
"output": "248148 248150"
},
{
"input": "868522",
"output": "248148 248150"
},
{
"input": "868521",
"output": "248148 248150"
},
{
"input": "868520",
"output": "248148 248150"
},
{
"input": "868519",
"output": "248148 248149"
},
{
"input": "868518",
"output": "248148 248148"
},
{
"input": "868517",
"output": "248147 248148"
},
{
"input": "868516",
"output": "248146 248148"
},
{
"input": "868515",
"output": "248146 248148"
},
{
"input": "868514",
"output": "248146 248148"
},
{
"input": "868513",
"output": "248146 248148"
},
{
"input": "868512",
"output": "248146 248147"
},
{
"input": "868511",
"output": "248146 248146"
},
{
"input": "123413",
"output": "35260 35262"
},
{
"input": "123412",
"output": "35260 35262"
},
{
"input": "123411",
"output": "35260 35261"
},
{
"input": "123410",
"output": "35260 35260"
},
{
"input": "123409",
"output": "35259 35260"
},
{
"input": "123408",
"output": "35258 35260"
},
{
"input": "123407",
"output": "35258 35260"
},
{
"input": "123406",
"output": "35258 35260"
},
{
"input": "123405",
"output": "35258 35260"
},
{
"input": "123404",
"output": "35258 35259"
},
{
"input": "123403",
"output": "35258 35258"
},
{
"input": "123402",
"output": "35257 35258"
},
{
"input": "123401",
"output": "35256 35258"
},
{
"input": "123400",
"output": "35256 35258"
},
{
"input": "123399",
"output": "35256 35258"
},
{
"input": "123398",
"output": "35256 35258"
},
{
"input": "123397",
"output": "35256 35257"
},
{
"input": "123396",
"output": "35256 35256"
},
{
"input": "123395",
"output": "35255 35256"
},
{
"input": "123394",
"output": "35254 35256"
},
{
"input": "123393",
"output": "35254 35256"
},
{
"input": "15",
"output": "4 5"
}
] | 1,667,233,294 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | n = int(input())
min = n//7
if n%7 <6:
if n%7>= 2 :
max = min + 2
elif n%7 == 1 :
max = min +1
else:
max = min
else:
max = min+1
print(min, max)
| Title: Holidays
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
On the planet Mars a year lasts exactly *n* days (there are no leap years on Mars). But Martians have the same weeks as earthlings — 5 work days and then 2 days off. Your task is to determine the minimum possible and the maximum possible number of days off per year on Mars.
Input Specification:
The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=1<=000<=000) — the number of days in a year on Mars.
Output Specification:
Print two integers — the minimum possible and the maximum possible number of days off per year on Mars.
Demo Input:
['14\n', '2\n']
Demo Output:
['4 4\n', '0 2\n']
Note:
In the first sample there are 14 days in a year on Mars, and therefore independently of the day a year starts with there will be exactly 4 days off .
In the second sample there are only 2 days in a year on Mars, and they can both be either work days or days off. | ```python
n = int(input())
min = n//7
if n%7 <6:
if n%7>= 2 :
max = min + 2
elif n%7 == 1 :
max = min +1
else:
max = min
else:
max = min+1
print(min, max)
``` | 0 |
|
897 | B | Chtholly's request | PROGRAMMING | 1,300 | [
"brute force"
] | null | null | — I experienced so many great things.
— You gave me memories like dreams... But I have to leave now...
— One last request, can you...
— Help me solve a Codeforces problem?
— ......
— What?
Chtholly has been thinking about a problem for days:
If a number is palindrome and length of its decimal representation without leading zeros is even, we call it a zcy number. A number is palindrome means when written in decimal representation, it contains no leading zeros and reads the same forwards and backwards. For example 12321 and 1221 are palindromes and 123 and 12451 are not. Moreover, 1221 is zcy number and 12321 is not.
Given integers *k* and *p*, calculate the sum of the *k* smallest zcy numbers and output this sum modulo *p*.
Unfortunately, Willem isn't good at solving this kind of problems, so he asks you for help! | The first line contains two integers *k* and *p* (1<=≤<=*k*<=≤<=105,<=1<=≤<=*p*<=≤<=109). | Output single integer — answer to the problem. | [
"2 100\n",
"5 30\n"
] | [
"33\n",
"15\n"
] | In the first example, the smallest zcy number is 11, and the second smallest zcy number is 22.
In the second example, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/68fffad54395f7d920ad0384e07c6215ddc64141.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | 1,000 | [
{
"input": "2 100",
"output": "33"
},
{
"input": "5 30",
"output": "15"
},
{
"input": "42147 412393322",
"output": "251637727"
},
{
"input": "77809 868097296",
"output": "440411873"
},
{
"input": "5105 443422097",
"output": "363192634"
},
{
"input": "75615 376679484",
"output": "373089399"
},
{
"input": "22951 23793302",
"output": "1898631"
},
{
"input": "12785 993582106",
"output": "286204743"
},
{
"input": "60276 428978808",
"output": "376477293"
},
{
"input": "84776 104860385",
"output": "10209596"
},
{
"input": "41984 653766991",
"output": "17823101"
},
{
"input": "100000 1000000000",
"output": "495495496"
},
{
"input": "41163 472310076",
"output": "207304047"
},
{
"input": "6983 765352180",
"output": "586866999"
},
{
"input": "33493 967727004",
"output": "305705165"
},
{
"input": "90898 94010922",
"output": "65928728"
},
{
"input": "67298 349286579",
"output": "156435206"
},
{
"input": "92452 296773064",
"output": "229486976"
},
{
"input": "58832 563860457",
"output": "16775206"
},
{
"input": "90234 156145441",
"output": "44023160"
},
{
"input": "91454 977186148",
"output": "681779748"
},
{
"input": "11108 444095250",
"output": "188075844"
},
{
"input": "46304 584475527",
"output": "275627129"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "1 1000000000",
"output": "11"
},
{
"input": "100000 1",
"output": "0"
}
] | 1,666,359,071 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 2 | 2,000 | 8,499,200 | k,p=[int(x) for x in input().split()]
s = 0
n = 11
while k != 0:
if n%10 == 0:
n += 1
else:
np = str(n)
if len(np)%2 == 0 and np == np[::-1]:
s += n
k -= 1
n += 1
print(s % p) | Title: Chtholly's request
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
— I experienced so many great things.
— You gave me memories like dreams... But I have to leave now...
— One last request, can you...
— Help me solve a Codeforces problem?
— ......
— What?
Chtholly has been thinking about a problem for days:
If a number is palindrome and length of its decimal representation without leading zeros is even, we call it a zcy number. A number is palindrome means when written in decimal representation, it contains no leading zeros and reads the same forwards and backwards. For example 12321 and 1221 are palindromes and 123 and 12451 are not. Moreover, 1221 is zcy number and 12321 is not.
Given integers *k* and *p*, calculate the sum of the *k* smallest zcy numbers and output this sum modulo *p*.
Unfortunately, Willem isn't good at solving this kind of problems, so he asks you for help!
Input Specification:
The first line contains two integers *k* and *p* (1<=≤<=*k*<=≤<=105,<=1<=≤<=*p*<=≤<=109).
Output Specification:
Output single integer — answer to the problem.
Demo Input:
['2 100\n', '5 30\n']
Demo Output:
['33\n', '15\n']
Note:
In the first example, the smallest zcy number is 11, and the second smallest zcy number is 22.
In the second example, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/68fffad54395f7d920ad0384e07c6215ddc64141.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | ```python
k,p=[int(x) for x in input().split()]
s = 0
n = 11
while k != 0:
if n%10 == 0:
n += 1
else:
np = str(n)
if len(np)%2 == 0 and np == np[::-1]:
s += n
k -= 1
n += 1
print(s % p)
``` | 0 |
|
31 | B | Sysadmin Bob | PROGRAMMING | 1,500 | [
"greedy",
"implementation",
"strings"
] | B. Sysadmin Bob | 0 | 256 | Email address in Berland is a string of the form *A*@*B*, where *A* and *B* are arbitrary strings consisting of small Latin letters.
Bob is a system administrator in «Bersoft» company. He keeps a list of email addresses of the company's staff. This list is as a large string, where all addresses are written in arbitrary order, separated by commas. The same address can be written more than once.
Suddenly, because of unknown reasons, all commas in Bob's list disappeared. Now Bob has a string, where all addresses are written one after another without any separators, and there is impossible to determine, where the boundaries between addresses are. Unfortunately, on the same day his chief asked him to bring the initial list of addresses. Now Bob wants to disjoin addresses in some valid way. Help him to do that. | The first line contains the list of addresses without separators. The length of this string is between 1 and 200, inclusive. The string consists only from small Latin letters and characters «@». | If there is no list of the valid (according to the Berland rules) email addresses such that after removing all commas it coincides with the given string, output No solution. In the other case, output the list. The same address can be written in this list more than once. If there are several solutions, output any of them. | [
"a@aa@a\n",
"a@a@a\n",
"@aa@a\n"
] | [
"a@a,a@a\n",
"No solution\n",
"No solution\n"
] | none | 1,000 | [
{
"input": "a@aa@a",
"output": "a@a,a@a"
},
{
"input": "a@a@a",
"output": "No solution"
},
{
"input": "@aa@a",
"output": "No solution"
},
{
"input": "aba@caba@daba",
"output": "aba@c,aba@daba"
},
{
"input": "asd@qwasd@qwasd@qwasd@qwasd@qw",
"output": "asd@q,wasd@q,wasd@q,wasd@q,wasd@qw"
},
{
"input": "qwer@ty",
"output": "qwer@ty"
},
{
"input": "@",
"output": "No solution"
},
{
"input": "g",
"output": "No solution"
},
{
"input": "@@",
"output": "No solution"
},
{
"input": "@@@",
"output": "No solution"
},
{
"input": "r@@",
"output": "No solution"
},
{
"input": "@@r",
"output": "No solution"
},
{
"input": "@r@",
"output": "No solution"
},
{
"input": "w@",
"output": "No solution"
},
{
"input": "@e",
"output": "No solution"
},
{
"input": "jj",
"output": "No solution"
},
{
"input": "@gh",
"output": "No solution"
},
{
"input": "n@m",
"output": "n@m"
},
{
"input": "kl@",
"output": "No solution"
},
{
"input": "fpm",
"output": "No solution"
},
{
"input": "@@@@",
"output": "No solution"
},
{
"input": "q@@@",
"output": "No solution"
},
{
"input": "@d@@",
"output": "No solution"
},
{
"input": "@@v@",
"output": "No solution"
},
{
"input": "@@@c",
"output": "No solution"
},
{
"input": "@@zx",
"output": "No solution"
},
{
"input": "@x@a",
"output": "No solution"
},
{
"input": "@pq@",
"output": "No solution"
},
{
"input": "w@@e",
"output": "No solution"
},
{
"input": "e@s@",
"output": "No solution"
},
{
"input": "ec@@",
"output": "No solution"
},
{
"input": "@hjk",
"output": "No solution"
},
{
"input": "e@vb",
"output": "e@vb"
},
{
"input": "tg@q",
"output": "tg@q"
},
{
"input": "jkl@",
"output": "No solution"
},
{
"input": "werb",
"output": "No solution"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "No solution"
},
{
"input": "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@",
"output": "No solution"
},
{
"input": "duk@rufrxjzqbwkfrzf@sjp@mdpyrokdfmcmexxtjqaalruvtzwfsqabi@tjkxilrhkwzfeuqm@lpwnxgebirdvwplsvrtxvhmzv",
"output": "duk@r,ufrxjzqbwkfrzf@s,jp@m,dpyrokdfmcmexxtjqaalruvtzwfsqabi@t,jkxilrhkwzfeuqm@lpwnxgebirdvwplsvrtxvhmzv"
},
{
"input": "umegsn@qlmkpkyrmuclefdpfhzuhyjcoqthnvpwzhkwrdvlzfbrqpzlg@ebzycyaofyyetwcepe@nxjwyeaqbuxxbohfzrnmebuy",
"output": "umegsn@q,lmkpkyrmuclefdpfhzuhyjcoqthnvpwzhkwrdvlzfbrqpzlg@e,bzycyaofyyetwcepe@nxjwyeaqbuxxbohfzrnmebuy"
},
{
"input": "l@snuoytgflrtuexpx@txzhhdwbakfhfro@syxistypegfvdmurvuubrj@grsznzhcotagqueuxtnjgfaywzkbglwwiptjyocxcs",
"output": "l@s,nuoytgflrtuexpx@t,xzhhdwbakfhfro@s,yxistypegfvdmurvuubrj@grsznzhcotagqueuxtnjgfaywzkbglwwiptjyocxcs"
},
{
"input": "crvjlke@yqsdofatzuuspt@@uumdkiwhtg@crxiabnujfmcquylyklxaedniwnq@@f@@rfnsjtylurexmdaaykvxmgeij@jkjsyi",
"output": "No solution"
},
{
"input": "ukpcivvjubgalr@bdxangokpaxzxuxe@qlemwpvywfudffafsqlmmhhalaaolktmgmhmrwvkdcvwxcfbytnz@jgmbhpwqcmecnxc",
"output": "ukpcivvjubgalr@b,dxangokpaxzxuxe@q,lemwpvywfudffafsqlmmhhalaaolktmgmhmrwvkdcvwxcfbytnz@jgmbhpwqcmecnxc"
},
{
"input": "mehxghlvnnazggvpnjdbchdolqguiurrfghwxpwhphdbhloltwnnqovsnsdmfevlikmrlvwvkcqysefvoraorhamchghqaooxaxz",
"output": "No solution"
},
{
"input": "whazbewtogyre@wqlsswhygx@osevwzytuaukqpp@gfjbtwnhpnlxwci@ovaaat@ookd@@o@bss@wyrrwzysubw@utyltkk@hlkx",
"output": "No solution"
},
{
"input": "vpulcessdotvylvmkeonzbpncjxaaigotkyvngsbkicomikyavpsjcphlznjtdmvbqiroxvfcmcczfmqbyedujvrupzlaswbzanv",
"output": "No solution"
},
{
"input": "mhxapzklriiincpnysmegjzaxdngifbowkzivvgisqbekprdmdoqezdsrsrwwmht@hwywjqflvqdevpqisncwbftlttfkgsyetop",
"output": "mhxapzklriiincpnysmegjzaxdngifbowkzivvgisqbekprdmdoqezdsrsrwwmht@hwywjqflvqdevpqisncwbftlttfkgsyetop"
},
{
"input": "dxzqftcghawwcwh@iepanbiclstbsxbrsoep@@jwhrptgiu@zfykoravtaykvkzseqfnlsbvjnsgiajgjtgucvewlpxmqwvkghlo",
"output": "No solution"
},
{
"input": "erierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtgh@",
"output": "No solution"
},
{
"input": "@rierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghd",
"output": "No solution"
},
{
"input": "e@ierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghd",
"output": "e@ierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghd"
},
{
"input": "erierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtg@d",
"output": "erierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtg@d"
},
{
"input": "erierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjt@h@",
"output": "No solution"
},
{
"input": "@r@erjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghd",
"output": "No solution"
},
{
"input": "e@i@rjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghd",
"output": "No solution"
},
{
"input": "erierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierj@g@d",
"output": "No solution"
},
{
"input": "erierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtg@@",
"output": "No solution"
},
{
"input": "@@ierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghd",
"output": "No solution"
},
{
"input": "e@@erjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghd",
"output": "No solution"
},
{
"input": "erierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjt@@d",
"output": "No solution"
},
{
"input": "erierjtghderierjtghderierj@@dderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghd",
"output": "No solution"
},
{
"input": "a@rierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderirjtghderierjtghderierjtghderierjthderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtgh@a",
"output": "a@r,ierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderirjtghderierjtghderierjtghderierjthderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtghderierjtgh@a"
},
{
"input": "d@nt@om@zz@ut@tr@ta@ap@ou@sy@sv@fg@el@rp@qr@nl@j",
"output": "d@n,t@o,m@z,z@u,t@t,r@t,a@a,p@o,u@s,y@s,v@f,g@e,l@r,p@q,r@n,l@j"
},
{
"input": "a@mc@ks@gu@rl@gq@zq@iz@da@uq@mi@nf@zs@hi@we@ej@ke@vb@az@yz@yl@rr@gh@um@nv@qe@qq@de@dy@op@gt@vx@ak@q",
"output": "a@m,c@k,s@g,u@r,l@g,q@z,q@i,z@d,a@u,q@m,i@n,f@z,s@h,i@w,e@e,j@k,e@v,b@a,z@y,z@y,l@r,r@g,h@u,m@n,v@q,e@q,q@d,e@d,y@o,p@g,t@v,x@a,k@q"
},
{
"input": "c@ir@xf@ap@fk@sp@wm@ec@qw@vg@by@iu@tr@wu@pv@lj@dd@tc@qj@ok@hm@bs@ul@ez@cg@ht@xf@ag@tr@hz@ap@tx@ly@dg@hu@nd@uv@il@ii@cn@nc@nb@cy@kp@dk@xa@da@ta@yr@yv@qg@db@je@wz@rn@yh@xi@mj@kc@uj@yu@cf@ps@ao@fo@le@d",
"output": "c@i,r@x,f@a,p@f,k@s,p@w,m@e,c@q,w@v,g@b,y@i,u@t,r@w,u@p,v@l,j@d,d@t,c@q,j@o,k@h,m@b,s@u,l@e,z@c,g@h,t@x,f@a,g@t,r@h,z@a,p@t,x@l,y@d,g@h,u@n,d@u,v@i,l@i,i@c,n@n,c@n,b@c,y@k,p@d,k@x,a@d,a@t,a@y,r@y,v@q,g@d,b@j,e@w,z@r,n@y,h@x,i@m,j@k,c@u,j@y,u@c,f@p,s@a,o@f,o@l,e@d"
},
{
"input": "m@us@ru@mg@rq@ed@ot@gt@fo@gs@lm@cx@au@rq@zt@zk@jr@xd@oa@py@kf@lk@zr@ko@lj@wv@fl@yl@gk@cx@px@kl@ic@sr@xn@hm@xs@km@tk@ui@ya@pa@xx@ze@py@ir@xj@cr@dq@lr@cm@zu@lt@bx@kq@kx@fr@lu@vb@rz@hg@iw@dl@pf@pl@wv@z",
"output": "m@u,s@r,u@m,g@r,q@e,d@o,t@g,t@f,o@g,s@l,m@c,x@a,u@r,q@z,t@z,k@j,r@x,d@o,a@p,y@k,f@l,k@z,r@k,o@l,j@w,v@f,l@y,l@g,k@c,x@p,x@k,l@i,c@s,r@x,n@h,m@x,s@k,m@t,k@u,i@y,a@p,a@x,x@z,e@p,y@i,r@x,j@c,r@d,q@l,r@c,m@z,u@l,t@b,x@k,q@k,x@f,r@l,u@v,b@r,z@h,g@i,w@d,l@p,f@p,l@w,v@z"
},
{
"input": "gjkjqjrks@eyqiia@qfijelnmigoditxjrtuhukalfl@nmwancimlqtfekzkxgjioedhtdivqajwbmu@hpdxuiwurpgenxaiqaqkcqimcvitljuisfiojlylveie@neqdjzeqdbiatjpuhujgykl@gmmlrhnlghsoeyrccygigtkjrjxdwmnkouaiaqpquluwcdqlxqb",
"output": "gjkjqjrks@e,yqiia@q,fijelnmigoditxjrtuhukalfl@n,mwancimlqtfekzkxgjioedhtdivqajwbmu@h,pdxuiwurpgenxaiqaqkcqimcvitljuisfiojlylveie@n,eqdjzeqdbiatjpuhujgykl@gmmlrhnlghsoeyrccygigtkjrjxdwmnkouaiaqpquluwcdqlxqb"
},
{
"input": "uakh@chpowdmvdywosakyyknpriverjjgklmdrgwufpawgvhabjbnemimjktgbkx@fzvqcodbceqnihl@kpsslhwwndad@@yavjafrwkqyt@urhnwgnqamn@xkc@vngzlssmtheuxkpzjlbbjq@mwiojmvpilm@hlrmxheszskhxritsieubjjazrngxlqeedfkiuwny",
"output": "No solution"
},
{
"input": "usmjophufnkamnvowbauu@wfoyceknkgeaejlbbqhtucbl@wurukjezj@irhdgrfhyfkz@fbmqgxvtxcebztirvwjf@fnav@@f@paookujny@z@fmcxgvab@@kpqbwuxxwxhsrbivlbunmdjzk@afjznrjjtkq@cafetoinfleecjqvlzpkqlspoufwmidvoblti@jbg",
"output": "No solution"
},
{
"input": "axkxcgcmlxq@v@ynnjximcujikloyls@lqvxiyca@feimaioavacmquasneqbrqftknpbrzpahtcc@ijwqmyzsuidqkm@dffuiitpugbvty@izbnqxhdjasihhlt@gjrol@vy@vnqpxuqbofzzwl@toywomxopbuttczszx@fuowtjmtqy@gypx@la@@tweln@jgyktb",
"output": "No solution"
},
{
"input": "mplxc@crww@gllecngcsbmxmksrgcb@lbrcnkwxclkcgvfeqeoymproppxhxbgm@q@bfxxvuymnnjolqklabcinwpdlxj@jcevvilhmpyiwggvlmdanfhhlgbkobnmei@bvqtdq@osijfdsuouvcqpcjxjqiuhgts@xapp@cpqvlhlfrxtgunbbjwhuafovbcbqyhmlu",
"output": "No solution"
},
{
"input": "aglvesxsmivijisod@mxcnbfcfgqfwjouidlsueaswf@obehqpvbkmukxkicyoknkbol@kutunggpoxxfpbe@qkhv@llddqqoyjeex@byvtlhbifqmvlukmrvgvpwrscwfhpuwyknwchqhrdqgarmnsdlqgf@lseltghg@bhuwbfjpsvayzk@fvwow@zapklumefauly",
"output": "aglvesxsmivijisod@m,xcnbfcfgqfwjouidlsueaswf@o,behqpvbkmukxkicyoknkbol@k,utunggpoxxfpbe@q,khv@l,lddqqoyjeex@b,yvtlhbifqmvlukmrvgvpwrscwfhpuwyknwchqhrdqgarmnsdlqgf@l,seltghg@b,huwbfjpsvayzk@f,vwow@zapklumefauly"
},
{
"input": "gbllovyerhudm@aluhtnstcp@uwgvejnmqpt@nez@ltzqjrcgwkkpzicb@ihh@wldhvjbrl@efbdzbeg@zyovsta@n@c@jutail@nclsbcihabzr@snowxeyl@jewen@aduffvhr@ifufzzt@i@kptygveumwaknmrn@edsapqpcwsqypmutggztum@ewzakeamobzxt",
"output": "No solution"
},
{
"input": "dokshhqwmtbefrynupvusfxroggoqkjqfyabzkbccjmavumncorbcoairybeknhnpnwftrlbopsvqlgjbrowmfmoeebqseneabvgbcxmujmcqomoawrooixmqmyspfgafudfdfyrnujhgnbtsehgsnvdztjdpnskyquwdtkbfjtvrfjcqzmourvqsnfgjfqjgndydpch",
"output": "No solution"
},
{
"input": "jrlhtwmotdhtgcqokodparuqypwlkbhfsxvmdpfiraokekrolwtlsqjzcuvjfnvblznyngasauzln@gjypvjcwljnotgjlxketfgtntbotwjehea@vppouyoujujlhjrxbhvltfdslaqwynwjefbdbnuehmipqmtsrivlnippgftgnkhdgqiqbfvgrtoxrznncncqcvf",
"output": "jrlhtwmotdhtgcqokodparuqypwlkbhfsxvmdpfiraokekrolwtlsqjzcuvjfnvblznyngasauzln@g,jypvjcwljnotgjlxketfgtntbotwjehea@vppouyoujujlhjrxbhvltfdslaqwynwjefbdbnuehmipqmtsrivlnippgftgnkhdgqiqbfvgrtoxrznncncqcvf"
},
{
"input": "oxkvgnggznlfhminxkkhictpiaokdsfrewnxiujpjpstlyxovfwugrsqnpooalknjnfugxojozizlicwvnbflhdevpvnvwztnfiapairpigexbaeshondqdecduewmfrxunphikvlfwmrpsxrhxyjlsgqfiaqnwzlzxcyuudhzr@twllmhyfclybxqazhrmxdtokxawc",
"output": "oxkvgnggznlfhminxkkhictpiaokdsfrewnxiujpjpstlyxovfwugrsqnpooalknjnfugxojozizlicwvnbflhdevpvnvwztnfiapairpigexbaeshondqdecduewmfrxunphikvlfwmrpsxrhxyjlsgqfiaqnwzlzxcyuudhzr@twllmhyfclybxqazhrmxdtokxawc"
}
] | 1,529,430,640 | 1,840 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 109 | 0 | from sys import stdout
a=input()
c=list(a.split('@'))
while '' in c:
c.remove('')
if a.count('@')!=len(c)-1:
exit(print('No Solution'))
if any(len(i)==1 for i in c[1:len(c)-1]):
exit(print('No Solution'))
stdout.write(c[0]+'@')
for i in range(1,len(c)-1):
stdout.write(c[i][:len(c[i])//2]+','+c[i][len(c[i])//2:]+'@')
stdout.write(c[-1])
| Title: Sysadmin Bob
Time Limit: 0 seconds
Memory Limit: 256 megabytes
Problem Description:
Email address in Berland is a string of the form *A*@*B*, where *A* and *B* are arbitrary strings consisting of small Latin letters.
Bob is a system administrator in «Bersoft» company. He keeps a list of email addresses of the company's staff. This list is as a large string, where all addresses are written in arbitrary order, separated by commas. The same address can be written more than once.
Suddenly, because of unknown reasons, all commas in Bob's list disappeared. Now Bob has a string, where all addresses are written one after another without any separators, and there is impossible to determine, where the boundaries between addresses are. Unfortunately, on the same day his chief asked him to bring the initial list of addresses. Now Bob wants to disjoin addresses in some valid way. Help him to do that.
Input Specification:
The first line contains the list of addresses without separators. The length of this string is between 1 and 200, inclusive. The string consists only from small Latin letters and characters «@».
Output Specification:
If there is no list of the valid (according to the Berland rules) email addresses such that after removing all commas it coincides with the given string, output No solution. In the other case, output the list. The same address can be written in this list more than once. If there are several solutions, output any of them.
Demo Input:
['a@aa@a\n', 'a@a@a\n', '@aa@a\n']
Demo Output:
['a@a,a@a\n', 'No solution\n', 'No solution\n']
Note:
none | ```python
from sys import stdout
a=input()
c=list(a.split('@'))
while '' in c:
c.remove('')
if a.count('@')!=len(c)-1:
exit(print('No Solution'))
if any(len(i)==1 for i in c[1:len(c)-1]):
exit(print('No Solution'))
stdout.write(c[0]+'@')
for i in range(1,len(c)-1):
stdout.write(c[i][:len(c[i])//2]+','+c[i][len(c[i])//2:]+'@')
stdout.write(c[-1])
``` | 0 |
120 | A | Elevator | PROGRAMMING | 1,000 | [
"brute force",
"implementation",
"math"
] | null | null | A sky scraper with 1000 floors has been built in the city of N. It has modern superfast elevators to help to travel from one floor to another. Each elevator has two doors, the front one and the back one. If one goes in through the front door, he goes out through the back one and vice versa. The elevator has two rails numbered with numbers 1 and 2. Rail 1 is located to the left of the entrance to the front door (or correspondingly, to the right of the entrance to the back door). Rail 2 is located opposite it, to the right of the entrance to the front door and to the left of the entrance to the back door. We know that each person in the city of N holds at a rail with the strongest hand.
One day a VIP person visited the city and of course, he took a look at the skyscraper and took a ride in the elevator. We know the door through which he entered and the rail he was holding at. Now we need to determine as soon as possible whether he is left-handed or right-handed. | The first line indicates the door through which the very important person entered the elevator. It contains "front" if the person enters the elevator through the front door and "back" if he entered the elevator through the back door. The second line contains integer *a* (1<=≤<=*a*<=≤<=2) which denotes the number of the rail at which the person was holding. | Print character "R" if the VIP is right-handed or "L" if he is left-handed. | [
"front\n1\n"
] | [
"L\n"
] | none | 0 | [
{
"input": "front\n1",
"output": "L"
},
{
"input": "back\n1",
"output": "R"
},
{
"input": "front\n2",
"output": "R"
},
{
"input": "back\n2",
"output": "L"
}
] | 1,597,305,409 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 154 | 0 | f = open('input.txt', 'r')
a = f.readlines()
s = a[0]
n = a[1]
if s=='front' and n=='1':
print('L')
if s=='front' and n=='2':
print('R')
if s=='back' and n=='1':
print('R')
if s=='back' and n=='2':
print('L') | Title: Elevator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A sky scraper with 1000 floors has been built in the city of N. It has modern superfast elevators to help to travel from one floor to another. Each elevator has two doors, the front one and the back one. If one goes in through the front door, he goes out through the back one and vice versa. The elevator has two rails numbered with numbers 1 and 2. Rail 1 is located to the left of the entrance to the front door (or correspondingly, to the right of the entrance to the back door). Rail 2 is located opposite it, to the right of the entrance to the front door and to the left of the entrance to the back door. We know that each person in the city of N holds at a rail with the strongest hand.
One day a VIP person visited the city and of course, he took a look at the skyscraper and took a ride in the elevator. We know the door through which he entered and the rail he was holding at. Now we need to determine as soon as possible whether he is left-handed or right-handed.
Input Specification:
The first line indicates the door through which the very important person entered the elevator. It contains "front" if the person enters the elevator through the front door and "back" if he entered the elevator through the back door. The second line contains integer *a* (1<=≤<=*a*<=≤<=2) which denotes the number of the rail at which the person was holding.
Output Specification:
Print character "R" if the VIP is right-handed or "L" if he is left-handed.
Demo Input:
['front\n1\n']
Demo Output:
['L\n']
Note:
none | ```python
f = open('input.txt', 'r')
a = f.readlines()
s = a[0]
n = a[1]
if s=='front' and n=='1':
print('L')
if s=='front' and n=='2':
print('R')
if s=='back' and n=='1':
print('R')
if s=='back' and n=='2':
print('L')
``` | 0 |
|
724 | A | Checking the Calendar | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | You are given names of two days of the week.
Please, determine whether it is possible that during some non-leap year the first day of some month was equal to the first day of the week you are given, while the first day of the next month was equal to the second day of the week you are given. Both months should belong to one year.
In this problem, we consider the Gregorian calendar to be used. The number of months in this calendar is equal to 12. The number of days in months during any non-leap year is: 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31.
Names of the days of the week are given with lowercase English letters: "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday". | The input consists of two lines, each of them containing the name of exactly one day of the week. It's guaranteed that each string in the input is from the set "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday". | Print "YES" (without quotes) if such situation is possible during some non-leap year. Otherwise, print "NO" (without quotes). | [
"monday\ntuesday\n",
"sunday\nsunday\n",
"saturday\ntuesday\n"
] | [
"NO\n",
"YES\n",
"YES\n"
] | In the second sample, one can consider February 1 and March 1 of year 2015. Both these days were Sundays.
In the third sample, one can consider July 1 and August 1 of year 2017. First of these two days is Saturday, while the second one is Tuesday. | 500 | [
{
"input": "monday\ntuesday",
"output": "NO"
},
{
"input": "sunday\nsunday",
"output": "YES"
},
{
"input": "saturday\ntuesday",
"output": "YES"
},
{
"input": "tuesday\nthursday",
"output": "YES"
},
{
"input": "friday\nwednesday",
"output": "NO"
},
{
"input": "sunday\nsaturday",
"output": "NO"
},
{
"input": "monday\nmonday",
"output": "YES"
},
{
"input": "monday\nwednesday",
"output": "YES"
},
{
"input": "monday\nthursday",
"output": "YES"
},
{
"input": "monday\nfriday",
"output": "NO"
},
{
"input": "monday\nsaturday",
"output": "NO"
},
{
"input": "monday\nsunday",
"output": "NO"
},
{
"input": "tuesday\nmonday",
"output": "NO"
},
{
"input": "tuesday\ntuesday",
"output": "YES"
},
{
"input": "tuesday\nwednesday",
"output": "NO"
},
{
"input": "tuesday\nfriday",
"output": "YES"
},
{
"input": "tuesday\nsaturday",
"output": "NO"
},
{
"input": "tuesday\nsunday",
"output": "NO"
},
{
"input": "wednesday\nmonday",
"output": "NO"
},
{
"input": "wednesday\ntuesday",
"output": "NO"
},
{
"input": "wednesday\nwednesday",
"output": "YES"
},
{
"input": "wednesday\nthursday",
"output": "NO"
},
{
"input": "wednesday\nfriday",
"output": "YES"
},
{
"input": "wednesday\nsaturday",
"output": "YES"
},
{
"input": "wednesday\nsunday",
"output": "NO"
},
{
"input": "thursday\nmonday",
"output": "NO"
},
{
"input": "thursday\ntuesday",
"output": "NO"
},
{
"input": "thursday\nwednesday",
"output": "NO"
},
{
"input": "thursday\nthursday",
"output": "YES"
},
{
"input": "thursday\nfriday",
"output": "NO"
},
{
"input": "thursday\nsaturday",
"output": "YES"
},
{
"input": "thursday\nsunday",
"output": "YES"
},
{
"input": "friday\nmonday",
"output": "YES"
},
{
"input": "friday\ntuesday",
"output": "NO"
},
{
"input": "friday\nthursday",
"output": "NO"
},
{
"input": "friday\nsaturday",
"output": "NO"
},
{
"input": "friday\nsunday",
"output": "YES"
},
{
"input": "saturday\nmonday",
"output": "YES"
},
{
"input": "saturday\nwednesday",
"output": "NO"
},
{
"input": "saturday\nthursday",
"output": "NO"
},
{
"input": "saturday\nfriday",
"output": "NO"
},
{
"input": "saturday\nsaturday",
"output": "YES"
},
{
"input": "saturday\nsunday",
"output": "NO"
},
{
"input": "sunday\nmonday",
"output": "NO"
},
{
"input": "sunday\ntuesday",
"output": "YES"
},
{
"input": "sunday\nwednesday",
"output": "YES"
},
{
"input": "sunday\nthursday",
"output": "NO"
},
{
"input": "sunday\nfriday",
"output": "NO"
},
{
"input": "friday\nfriday",
"output": "YES"
},
{
"input": "friday\nsunday",
"output": "YES"
},
{
"input": "monday\nmonday",
"output": "YES"
},
{
"input": "friday\ntuesday",
"output": "NO"
},
{
"input": "thursday\nsaturday",
"output": "YES"
},
{
"input": "tuesday\nfriday",
"output": "YES"
},
{
"input": "sunday\nwednesday",
"output": "YES"
},
{
"input": "monday\nthursday",
"output": "YES"
},
{
"input": "saturday\nsunday",
"output": "NO"
},
{
"input": "friday\nmonday",
"output": "YES"
},
{
"input": "thursday\nthursday",
"output": "YES"
},
{
"input": "wednesday\nfriday",
"output": "YES"
},
{
"input": "thursday\nmonday",
"output": "NO"
},
{
"input": "wednesday\nsunday",
"output": "NO"
},
{
"input": "thursday\nfriday",
"output": "NO"
},
{
"input": "monday\nfriday",
"output": "NO"
},
{
"input": "wednesday\nsaturday",
"output": "YES"
},
{
"input": "thursday\nsunday",
"output": "YES"
},
{
"input": "saturday\nfriday",
"output": "NO"
},
{
"input": "saturday\nmonday",
"output": "YES"
}
] | 1,475,943,884 | 2,147,483,647 | PyPy 3 | OK | TESTS | 68 | 124 | 23,040,000 | d = {'monday': 1, 'tuesday': 2, 'wednesday': 3, 'thursday': 4, 'friday': 5, 'saturday': 6, 'sunday': 7}
a, b = input(), input()
flag = (d[b] - d[a]) % 7 in {0, 2, 3}
print('YES' if flag else 'NO')
| Title: Checking the Calendar
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given names of two days of the week.
Please, determine whether it is possible that during some non-leap year the first day of some month was equal to the first day of the week you are given, while the first day of the next month was equal to the second day of the week you are given. Both months should belong to one year.
In this problem, we consider the Gregorian calendar to be used. The number of months in this calendar is equal to 12. The number of days in months during any non-leap year is: 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31.
Names of the days of the week are given with lowercase English letters: "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday".
Input Specification:
The input consists of two lines, each of them containing the name of exactly one day of the week. It's guaranteed that each string in the input is from the set "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday".
Output Specification:
Print "YES" (without quotes) if such situation is possible during some non-leap year. Otherwise, print "NO" (without quotes).
Demo Input:
['monday\ntuesday\n', 'sunday\nsunday\n', 'saturday\ntuesday\n']
Demo Output:
['NO\n', 'YES\n', 'YES\n']
Note:
In the second sample, one can consider February 1 and March 1 of year 2015. Both these days were Sundays.
In the third sample, one can consider July 1 and August 1 of year 2017. First of these two days is Saturday, while the second one is Tuesday. | ```python
d = {'monday': 1, 'tuesday': 2, 'wednesday': 3, 'thursday': 4, 'friday': 5, 'saturday': 6, 'sunday': 7}
a, b = input(), input()
flag = (d[b] - d[a]) % 7 in {0, 2, 3}
print('YES' if flag else 'NO')
``` | 3 |
|
20 | C | Dijkstra? | PROGRAMMING | 1,900 | [
"graphs",
"shortest paths"
] | C. Dijkstra? | 1 | 64 | You are given a weighted undirected graph. The vertices are enumerated from 1 to *n*. Your task is to find the shortest path between the vertex 1 and the vertex *n*. | The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105), where *n* is the number of vertices and *m* is the number of edges. Following *m* lines contain one edge each in form *a**i*, *b**i* and *w**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=1<=≤<=*w**i*<=≤<=106), where *a**i*,<=*b**i* are edge endpoints and *w**i* is the length of the edge.
It is possible that the graph has loops and multiple edges between pair of vertices. | Write the only integer -1 in case of no path. Write the shortest path in opposite case. If there are many solutions, print any of them. | [
"5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n",
"5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n"
] | [
"1 4 3 5 ",
"1 4 3 5 "
] | none | 1,500 | [
{
"input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1",
"output": "1 4 3 5 "
},
{
"input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1",
"output": "1 4 3 5 "
},
{
"input": "2 1\n1 2 1",
"output": "1 2 "
},
{
"input": "3 1\n1 2 1",
"output": "-1"
},
{
"input": "3 3\n1 2 1\n1 3 2\n2 3 1",
"output": "1 3 "
},
{
"input": "10 10\n1 5 12\n2 4 140\n2 10 149\n3 6 154\n3 7 9\n3 8 226\n3 10 132\n4 10 55\n5 8 33\n7 8 173",
"output": "1 5 8 7 3 10 "
},
{
"input": "10 10\n1 5 178\n1 8 221\n2 7 92\n2 8 159\n3 5 55\n3 6 179\n3 10 237\n4 8 205\n5 6 191\n8 10 157",
"output": "1 8 10 "
},
{
"input": "10 10\n1 4 200\n1 9 197\n3 4 79\n3 5 213\n3 6 149\n5 8 3\n5 9 189\n6 7 130\n6 9 51\n8 10 135",
"output": "1 9 5 8 10 "
},
{
"input": "10 10\n1 4 201\n2 3 238\n3 4 40\n3 6 231\n3 8 45\n4 5 227\n4 6 58\n4 9 55\n5 7 14\n6 10 242",
"output": "1 4 6 10 "
}
] | 1,668,296,849 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 93 | 2,252,800 | import heapq
n, m = map(int, input().split())
graph = {}
edges = {}
for i in range(1,n+1):
graph[i] = set()
for i in range(m):
a, b, w = map(int, input().split())
if a == b:
continue
graph[a].add(b)
graph[b].add(a)
if a > b:
a, b = b, a
if (a,b) in edges and edges[(a, b)] > w:
edges[(a, b)] = w
frontier = [(0, 1, None)]
current_node = None
visited = [False] * (n+1)
prev_nodes = [None] * (n+1)
while frontier:
dist, current_node, prev_node = heapq.heappop(frontier)
if visited[current_node]:
continue
visited[current_node] = True
prev_nodes[current_node] = prev_node
if current_node == n:
back_path = []
while current_node != None:
back_path.append(current_node)
current_node = prev_nodes[current_node]
back_path.reverse()
print(' '.join([ str(x) for x in back_path ]))
exit(0)
for neigh in graph[current_node]:
if not visited[neigh]:
ndist = edges[(min(neigh, current_node), max(neigh, current_node))]
heapq.heappush(frontier, ((dist + ndist), neigh, current_node))
print(-1)
| Title: Dijkstra?
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
You are given a weighted undirected graph. The vertices are enumerated from 1 to *n*. Your task is to find the shortest path between the vertex 1 and the vertex *n*.
Input Specification:
The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105), where *n* is the number of vertices and *m* is the number of edges. Following *m* lines contain one edge each in form *a**i*, *b**i* and *w**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=1<=≤<=*w**i*<=≤<=106), where *a**i*,<=*b**i* are edge endpoints and *w**i* is the length of the edge.
It is possible that the graph has loops and multiple edges between pair of vertices.
Output Specification:
Write the only integer -1 in case of no path. Write the shortest path in opposite case. If there are many solutions, print any of them.
Demo Input:
['5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n', '5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n']
Demo Output:
['1 4 3 5 ', '1 4 3 5 ']
Note:
none | ```python
import heapq
n, m = map(int, input().split())
graph = {}
edges = {}
for i in range(1,n+1):
graph[i] = set()
for i in range(m):
a, b, w = map(int, input().split())
if a == b:
continue
graph[a].add(b)
graph[b].add(a)
if a > b:
a, b = b, a
if (a,b) in edges and edges[(a, b)] > w:
edges[(a, b)] = w
frontier = [(0, 1, None)]
current_node = None
visited = [False] * (n+1)
prev_nodes = [None] * (n+1)
while frontier:
dist, current_node, prev_node = heapq.heappop(frontier)
if visited[current_node]:
continue
visited[current_node] = True
prev_nodes[current_node] = prev_node
if current_node == n:
back_path = []
while current_node != None:
back_path.append(current_node)
current_node = prev_nodes[current_node]
back_path.reverse()
print(' '.join([ str(x) for x in back_path ]))
exit(0)
for neigh in graph[current_node]:
if not visited[neigh]:
ndist = edges[(min(neigh, current_node), max(neigh, current_node))]
heapq.heappush(frontier, ((dist + ndist), neigh, current_node))
print(-1)
``` | -1 |
724 | A | Checking the Calendar | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | You are given names of two days of the week.
Please, determine whether it is possible that during some non-leap year the first day of some month was equal to the first day of the week you are given, while the first day of the next month was equal to the second day of the week you are given. Both months should belong to one year.
In this problem, we consider the Gregorian calendar to be used. The number of months in this calendar is equal to 12. The number of days in months during any non-leap year is: 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31.
Names of the days of the week are given with lowercase English letters: "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday". | The input consists of two lines, each of them containing the name of exactly one day of the week. It's guaranteed that each string in the input is from the set "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday". | Print "YES" (without quotes) if such situation is possible during some non-leap year. Otherwise, print "NO" (without quotes). | [
"monday\ntuesday\n",
"sunday\nsunday\n",
"saturday\ntuesday\n"
] | [
"NO\n",
"YES\n",
"YES\n"
] | In the second sample, one can consider February 1 and March 1 of year 2015. Both these days were Sundays.
In the third sample, one can consider July 1 and August 1 of year 2017. First of these two days is Saturday, while the second one is Tuesday. | 500 | [
{
"input": "monday\ntuesday",
"output": "NO"
},
{
"input": "sunday\nsunday",
"output": "YES"
},
{
"input": "saturday\ntuesday",
"output": "YES"
},
{
"input": "tuesday\nthursday",
"output": "YES"
},
{
"input": "friday\nwednesday",
"output": "NO"
},
{
"input": "sunday\nsaturday",
"output": "NO"
},
{
"input": "monday\nmonday",
"output": "YES"
},
{
"input": "monday\nwednesday",
"output": "YES"
},
{
"input": "monday\nthursday",
"output": "YES"
},
{
"input": "monday\nfriday",
"output": "NO"
},
{
"input": "monday\nsaturday",
"output": "NO"
},
{
"input": "monday\nsunday",
"output": "NO"
},
{
"input": "tuesday\nmonday",
"output": "NO"
},
{
"input": "tuesday\ntuesday",
"output": "YES"
},
{
"input": "tuesday\nwednesday",
"output": "NO"
},
{
"input": "tuesday\nfriday",
"output": "YES"
},
{
"input": "tuesday\nsaturday",
"output": "NO"
},
{
"input": "tuesday\nsunday",
"output": "NO"
},
{
"input": "wednesday\nmonday",
"output": "NO"
},
{
"input": "wednesday\ntuesday",
"output": "NO"
},
{
"input": "wednesday\nwednesday",
"output": "YES"
},
{
"input": "wednesday\nthursday",
"output": "NO"
},
{
"input": "wednesday\nfriday",
"output": "YES"
},
{
"input": "wednesday\nsaturday",
"output": "YES"
},
{
"input": "wednesday\nsunday",
"output": "NO"
},
{
"input": "thursday\nmonday",
"output": "NO"
},
{
"input": "thursday\ntuesday",
"output": "NO"
},
{
"input": "thursday\nwednesday",
"output": "NO"
},
{
"input": "thursday\nthursday",
"output": "YES"
},
{
"input": "thursday\nfriday",
"output": "NO"
},
{
"input": "thursday\nsaturday",
"output": "YES"
},
{
"input": "thursday\nsunday",
"output": "YES"
},
{
"input": "friday\nmonday",
"output": "YES"
},
{
"input": "friday\ntuesday",
"output": "NO"
},
{
"input": "friday\nthursday",
"output": "NO"
},
{
"input": "friday\nsaturday",
"output": "NO"
},
{
"input": "friday\nsunday",
"output": "YES"
},
{
"input": "saturday\nmonday",
"output": "YES"
},
{
"input": "saturday\nwednesday",
"output": "NO"
},
{
"input": "saturday\nthursday",
"output": "NO"
},
{
"input": "saturday\nfriday",
"output": "NO"
},
{
"input": "saturday\nsaturday",
"output": "YES"
},
{
"input": "saturday\nsunday",
"output": "NO"
},
{
"input": "sunday\nmonday",
"output": "NO"
},
{
"input": "sunday\ntuesday",
"output": "YES"
},
{
"input": "sunday\nwednesday",
"output": "YES"
},
{
"input": "sunday\nthursday",
"output": "NO"
},
{
"input": "sunday\nfriday",
"output": "NO"
},
{
"input": "friday\nfriday",
"output": "YES"
},
{
"input": "friday\nsunday",
"output": "YES"
},
{
"input": "monday\nmonday",
"output": "YES"
},
{
"input": "friday\ntuesday",
"output": "NO"
},
{
"input": "thursday\nsaturday",
"output": "YES"
},
{
"input": "tuesday\nfriday",
"output": "YES"
},
{
"input": "sunday\nwednesday",
"output": "YES"
},
{
"input": "monday\nthursday",
"output": "YES"
},
{
"input": "saturday\nsunday",
"output": "NO"
},
{
"input": "friday\nmonday",
"output": "YES"
},
{
"input": "thursday\nthursday",
"output": "YES"
},
{
"input": "wednesday\nfriday",
"output": "YES"
},
{
"input": "thursday\nmonday",
"output": "NO"
},
{
"input": "wednesday\nsunday",
"output": "NO"
},
{
"input": "thursday\nfriday",
"output": "NO"
},
{
"input": "monday\nfriday",
"output": "NO"
},
{
"input": "wednesday\nsaturday",
"output": "YES"
},
{
"input": "thursday\nsunday",
"output": "YES"
},
{
"input": "saturday\nfriday",
"output": "NO"
},
{
"input": "saturday\nmonday",
"output": "YES"
}
] | 1,595,145,696 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 93 | 6,963,200 | a = input()
b = input()
d = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday']
ai = d.index(a)
bi = d.index(b)
l = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
for x, y in zip(l, l[1:]):
x -= ai
x = x % 7
if x == bi:
print('YES')
exit(0)
print('NO')
| Title: Checking the Calendar
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given names of two days of the week.
Please, determine whether it is possible that during some non-leap year the first day of some month was equal to the first day of the week you are given, while the first day of the next month was equal to the second day of the week you are given. Both months should belong to one year.
In this problem, we consider the Gregorian calendar to be used. The number of months in this calendar is equal to 12. The number of days in months during any non-leap year is: 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31.
Names of the days of the week are given with lowercase English letters: "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday".
Input Specification:
The input consists of two lines, each of them containing the name of exactly one day of the week. It's guaranteed that each string in the input is from the set "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday".
Output Specification:
Print "YES" (without quotes) if such situation is possible during some non-leap year. Otherwise, print "NO" (without quotes).
Demo Input:
['monday\ntuesday\n', 'sunday\nsunday\n', 'saturday\ntuesday\n']
Demo Output:
['NO\n', 'YES\n', 'YES\n']
Note:
In the second sample, one can consider February 1 and March 1 of year 2015. Both these days were Sundays.
In the third sample, one can consider July 1 and August 1 of year 2017. First of these two days is Saturday, while the second one is Tuesday. | ```python
a = input()
b = input()
d = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday']
ai = d.index(a)
bi = d.index(b)
l = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
for x, y in zip(l, l[1:]):
x -= ai
x = x % 7
if x == bi:
print('YES')
exit(0)
print('NO')
``` | 0 |
|
785 | A | Anton and Polyhedrons | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons:
- Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahedron. Octahedron has 8 triangular faces. - Dodecahedron. Dodecahedron has 12 pentagonal faces. - Icosahedron. Icosahedron has 20 triangular faces.
All five kinds of polyhedrons are shown on the picture below:
Anton has a collection of *n* polyhedrons. One day he decided to know, how many faces his polyhedrons have in total. Help Anton and find this number! | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of polyhedrons in Anton's collection.
Each of the following *n* lines of the input contains a string *s**i* — the name of the *i*-th polyhedron in Anton's collection. The string can look like this:
- "Tetrahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is a tetrahedron. - "Cube" (without quotes), if the *i*-th polyhedron in Anton's collection is a cube. - "Octahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is an octahedron. - "Dodecahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is a dodecahedron. - "Icosahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is an icosahedron. | Output one number — the total number of faces in all the polyhedrons in Anton's collection. | [
"4\nIcosahedron\nCube\nTetrahedron\nDodecahedron\n",
"3\nDodecahedron\nOctahedron\nOctahedron\n"
] | [
"42\n",
"28\n"
] | In the first sample Anton has one icosahedron, one cube, one tetrahedron and one dodecahedron. Icosahedron has 20 faces, cube has 6 faces, tetrahedron has 4 faces and dodecahedron has 12 faces. In total, they have 20 + 6 + 4 + 12 = 42 faces. | 500 | [
{
"input": "4\nIcosahedron\nCube\nTetrahedron\nDodecahedron",
"output": "42"
},
{
"input": "3\nDodecahedron\nOctahedron\nOctahedron",
"output": "28"
},
{
"input": "25\nIcosahedron\nOctahedron\nTetrahedron\nDodecahedron\nCube\nIcosahedron\nOctahedron\nCube\nTetrahedron\nIcosahedron\nIcosahedron\nTetrahedron\nOctahedron\nDodecahedron\nIcosahedron\nOctahedron\nIcosahedron\nTetrahedron\nDodecahedron\nTetrahedron\nOctahedron\nCube\nCube\nDodecahedron\nTetrahedron",
"output": "256"
},
{
"input": "1\nTetrahedron",
"output": "4"
},
{
"input": "1\nCube",
"output": "6"
},
{
"input": "1\nOctahedron",
"output": "8"
},
{
"input": "1\nDodecahedron",
"output": "12"
},
{
"input": "1\nIcosahedron",
"output": "20"
},
{
"input": "28\nOctahedron\nDodecahedron\nOctahedron\nOctahedron\nDodecahedron\nIcosahedron\nIcosahedron\nDodecahedron\nDodecahedron\nDodecahedron\nCube\nDodecahedron\nCube\nTetrahedron\nCube\nCube\nTetrahedron\nDodecahedron\nDodecahedron\nDodecahedron\nIcosahedron\nIcosahedron\nDodecahedron\nIcosahedron\nDodecahedron\nDodecahedron\nIcosahedron\nIcosahedron",
"output": "340"
}
] | 1,691,331,363 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 217 | 0 | n=int(input())
polyhedron={
"Tetrahedron":4 ,
"Cube":6,
"Octahedron":8,
"Dodecahedron":12,
"Icosahedron":20
}
c=0
for _ in range(n):
s=input()
if s in polyhedron:
c+=polyhedron[s]
print(c) | Title: Anton and Polyhedrons
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons:
- Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahedron. Octahedron has 8 triangular faces. - Dodecahedron. Dodecahedron has 12 pentagonal faces. - Icosahedron. Icosahedron has 20 triangular faces.
All five kinds of polyhedrons are shown on the picture below:
Anton has a collection of *n* polyhedrons. One day he decided to know, how many faces his polyhedrons have in total. Help Anton and find this number!
Input Specification:
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of polyhedrons in Anton's collection.
Each of the following *n* lines of the input contains a string *s**i* — the name of the *i*-th polyhedron in Anton's collection. The string can look like this:
- "Tetrahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is a tetrahedron. - "Cube" (without quotes), if the *i*-th polyhedron in Anton's collection is a cube. - "Octahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is an octahedron. - "Dodecahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is a dodecahedron. - "Icosahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is an icosahedron.
Output Specification:
Output one number — the total number of faces in all the polyhedrons in Anton's collection.
Demo Input:
['4\nIcosahedron\nCube\nTetrahedron\nDodecahedron\n', '3\nDodecahedron\nOctahedron\nOctahedron\n']
Demo Output:
['42\n', '28\n']
Note:
In the first sample Anton has one icosahedron, one cube, one tetrahedron and one dodecahedron. Icosahedron has 20 faces, cube has 6 faces, tetrahedron has 4 faces and dodecahedron has 12 faces. In total, they have 20 + 6 + 4 + 12 = 42 faces. | ```python
n=int(input())
polyhedron={
"Tetrahedron":4 ,
"Cube":6,
"Octahedron":8,
"Dodecahedron":12,
"Icosahedron":20
}
c=0
for _ in range(n):
s=input()
if s in polyhedron:
c+=polyhedron[s]
print(c)
``` | 3 |
|
622 | A | Infinite Sequence | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Consider the infinite sequence of integers: 1,<=1,<=2,<=1,<=2,<=3,<=1,<=2,<=3,<=4,<=1,<=2,<=3,<=4,<=5.... The sequence is built in the following way: at first the number 1 is written out, then the numbers from 1 to 2, then the numbers from 1 to 3, then the numbers from 1 to 4 and so on. Note that the sequence contains numbers, not digits. For example number 10 first appears in the sequence in position 55 (the elements are numerated from one).
Find the number on the *n*-th position of the sequence. | The only line contains integer *n* (1<=≤<=*n*<=≤<=1014) — the position of the number to find.
Note that the given number is 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. | Print the element in the *n*-th position of the sequence (the elements are numerated from one). | [
"3\n",
"5\n",
"10\n",
"55\n",
"56\n"
] | [
"2\n",
"2\n",
"4\n",
"10\n",
"1\n"
] | none | 0 | [
{
"input": "3",
"output": "2"
},
{
"input": "5",
"output": "2"
},
{
"input": "10",
"output": "4"
},
{
"input": "55",
"output": "10"
},
{
"input": "56",
"output": "1"
},
{
"input": "1000000000000",
"output": "88209"
},
{
"input": "847194127849",
"output": "255708"
},
{
"input": "294719472984",
"output": "593358"
},
{
"input": "999999911791",
"output": "1414213"
},
{
"input": "999999911792",
"output": "1"
},
{
"input": "100000000000000",
"output": "1749820"
},
{
"input": "1",
"output": "1"
},
{
"input": "99993",
"output": "312"
},
{
"input": "99994",
"output": "313"
},
{
"input": "99995",
"output": "314"
},
{
"input": "99990",
"output": "309"
},
{
"input": "2",
"output": "1"
},
{
"input": "99991",
"output": "310"
},
{
"input": "99992",
"output": "311"
},
{
"input": "99996",
"output": "315"
},
{
"input": "99997",
"output": "316"
},
{
"input": "99998",
"output": "317"
},
{
"input": "99999",
"output": "318"
},
{
"input": "1021",
"output": "31"
},
{
"input": "4",
"output": "1"
},
{
"input": "23",
"output": "2"
},
{
"input": "9994",
"output": "124"
},
{
"input": "99939",
"output": "258"
},
{
"input": "99999998250180",
"output": "14142135"
},
{
"input": "6",
"output": "3"
},
{
"input": "8",
"output": "2"
},
{
"input": "35",
"output": "7"
},
{
"input": "100",
"output": "9"
},
{
"input": "10101010",
"output": "745"
},
{
"input": "103",
"output": "12"
},
{
"input": "102",
"output": "11"
},
{
"input": "101",
"output": "10"
}
] | 1,540,329,918 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 108 | 0 | n = int(input())
for i in range(0, n ):
result = ((i * i) + i)/2
if result >= n:
print(i)
break | Title: Infinite Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Consider the infinite sequence of integers: 1,<=1,<=2,<=1,<=2,<=3,<=1,<=2,<=3,<=4,<=1,<=2,<=3,<=4,<=5.... The sequence is built in the following way: at first the number 1 is written out, then the numbers from 1 to 2, then the numbers from 1 to 3, then the numbers from 1 to 4 and so on. Note that the sequence contains numbers, not digits. For example number 10 first appears in the sequence in position 55 (the elements are numerated from one).
Find the number on the *n*-th position of the sequence.
Input Specification:
The only line contains integer *n* (1<=≤<=*n*<=≤<=1014) — the position of the number to find.
Note that the given number is 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.
Output Specification:
Print the element in the *n*-th position of the sequence (the elements are numerated from one).
Demo Input:
['3\n', '5\n', '10\n', '55\n', '56\n']
Demo Output:
['2\n', '2\n', '4\n', '10\n', '1\n']
Note:
none | ```python
n = int(input())
for i in range(0, n ):
result = ((i * i) + i)/2
if result >= n:
print(i)
break
``` | 0 |
|
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers two squares.
2. No two dominoes overlap.
3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board.
Find the maximum number of dominoes, which can be placed under these restrictions. | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"output": "5"
},
{
"input": "2 6",
"output": "6"
},
{
"input": "2 7",
"output": "7"
},
{
"input": "2 14",
"output": "14"
},
{
"input": "2 15",
"output": "15"
},
{
"input": "1 4",
"output": "2"
},
{
"input": "2 16",
"output": "16"
},
{
"input": "3 5",
"output": "7"
},
{
"input": "3 6",
"output": "9"
},
{
"input": "3 10",
"output": "15"
},
{
"input": "3 14",
"output": "21"
},
{
"input": "3 15",
"output": "22"
},
{
"input": "3 16",
"output": "24"
},
{
"input": "5 7",
"output": "17"
},
{
"input": "16 16",
"output": "128"
},
{
"input": "15 16",
"output": "120"
},
{
"input": "2 3",
"output": "3"
},
{
"input": "15 15",
"output": "112"
},
{
"input": "14 16",
"output": "112"
},
{
"input": "11 13",
"output": "71"
},
{
"input": "5 16",
"output": "40"
},
{
"input": "8 15",
"output": "60"
},
{
"input": "2 2",
"output": "2"
},
{
"input": "3 4",
"output": "6"
},
{
"input": "4 4",
"output": "8"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "1 3",
"output": "1"
},
{
"input": "14 15",
"output": "105"
}
] | 1,693,300,750 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 92 | 0 | n,m = map(int , input().split())
if n*m%2==0:
print(int(n*m/2))
else:
print(int(((m*n)-1)/2)) | Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers two squares.
2. No two dominoes overlap.
3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board.
Find the maximum number of dominoes, which can be placed under these restrictions.
Input Specification:
In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16).
Output Specification:
Output one number — the maximal number of dominoes, which can be placed.
Demo Input:
['2 4\n', '3 3\n']
Demo Output:
['4\n', '4\n']
Note:
none | ```python
n,m = map(int , input().split())
if n*m%2==0:
print(int(n*m/2))
else:
print(int(((m*n)-1)/2))
``` | 3.977 |
115 | A | Party | PROGRAMMING | 900 | [
"dfs and similar",
"graphs",
"trees"
] | null | null | A company has *n* employees numbered from 1 to *n*. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee *A* is said to be the superior of another employee *B* if at least one of the following is true:
- Employee *A* is the immediate manager of employee *B* - Employee *B* has an immediate manager employee *C* such that employee *A* is the superior of employee *C*.
The company will not have a managerial cycle. That is, there will not exist an employee who is the superior of his/her own immediate manager.
Today the company is going to arrange a party. This involves dividing all *n* employees into several groups: every employee must belong to exactly one group. Furthermore, within any single group, there must not be two employees *A* and *B* such that *A* is the superior of *B*.
What is the minimum number of groups that must be formed? | The first line contains integer *n* (1<=≤<=*n*<=≤<=2000) — the number of employees.
The next *n* lines contain the integers *p**i* (1<=≤<=*p**i*<=≤<=*n* or *p**i*<==<=-1). Every *p**i* denotes the immediate manager for the *i*-th employee. If *p**i* is -1, that means that the *i*-th employee does not have an immediate manager.
It is guaranteed, that no employee will be the immediate manager of him/herself (*p**i*<=≠<=*i*). Also, there will be no managerial cycles. | Print a single integer denoting the minimum number of groups that will be formed in the party. | [
"5\n-1\n1\n2\n1\n-1\n"
] | [
"3\n"
] | For the first example, three groups are sufficient, for example:
- Employee 1 - Employees 2 and 4 - Employees 3 and 5 | 500 | [
{
"input": "5\n-1\n1\n2\n1\n-1",
"output": "3"
},
{
"input": "4\n-1\n1\n2\n3",
"output": "4"
},
{
"input": "12\n-1\n1\n2\n3\n-1\n5\n6\n7\n-1\n9\n10\n11",
"output": "4"
},
{
"input": "6\n-1\n-1\n2\n3\n1\n1",
"output": "3"
},
{
"input": "3\n-1\n1\n1",
"output": "2"
},
{
"input": "1\n-1",
"output": "1"
},
{
"input": "2\n2\n-1",
"output": "2"
},
{
"input": "2\n-1\n-1",
"output": "1"
},
{
"input": "3\n2\n-1\n1",
"output": "3"
},
{
"input": "3\n-1\n-1\n-1",
"output": "1"
},
{
"input": "5\n4\n5\n1\n-1\n4",
"output": "3"
},
{
"input": "12\n-1\n1\n1\n1\n1\n1\n3\n4\n3\n3\n4\n7",
"output": "4"
},
{
"input": "12\n-1\n-1\n1\n-1\n1\n1\n5\n11\n8\n6\n6\n4",
"output": "5"
},
{
"input": "12\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n2\n-1\n-1\n-1",
"output": "2"
},
{
"input": "12\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1",
"output": "1"
},
{
"input": "12\n3\n4\n2\n8\n7\n1\n10\n12\n5\n-1\n9\n11",
"output": "12"
},
{
"input": "12\n5\n6\n7\n1\n-1\n9\n12\n4\n8\n-1\n3\n2",
"output": "11"
},
{
"input": "12\n-1\n9\n11\n6\n6\n-1\n6\n3\n8\n6\n1\n6",
"output": "6"
},
{
"input": "12\n7\n8\n4\n12\n7\n9\n-1\n-1\n-1\n8\n6\n-1",
"output": "3"
},
{
"input": "12\n-1\n10\n-1\n1\n-1\n5\n9\n12\n-1\n-1\n3\n-1",
"output": "2"
},
{
"input": "12\n-1\n7\n9\n12\n1\n7\n-1\n-1\n8\n5\n4\n-1",
"output": "3"
},
{
"input": "12\n11\n11\n8\n9\n1\n1\n2\n-1\n10\n3\n-1\n8",
"output": "5"
},
{
"input": "12\n-1\n8\n9\n-1\n4\n2\n11\n1\n-1\n6\n-1\n10",
"output": "6"
},
{
"input": "12\n7\n4\n4\n-1\n6\n7\n9\n7\n-1\n7\n4\n1",
"output": "4"
},
{
"input": "12\n-1\n6\n10\n6\n1\n11\n5\n9\n11\n5\n1\n9",
"output": "4"
},
{
"input": "12\n8\n6\n6\n8\n6\n-1\n6\n6\n8\n6\n8\n8",
"output": "3"
},
{
"input": "12\n3\n8\n9\n12\n2\n8\n11\n12\n2\n9\n-1\n11",
"output": "7"
},
{
"input": "7\n7\n6\n-1\n-1\n4\n4\n-1",
"output": "3"
},
{
"input": "77\n53\n-1\n48\n-1\n51\n-1\n54\n43\n70\n19\n64\n31\n45\n58\n6\n61\n41\n56\n34\n-1\n54\n-1\n66\n65\n74\n16\n38\n1\n2\n61\n-1\n34\n-1\n-1\n7\n19\n57\n13\n61\n42\n-1\n34\n65\n16\n31\n61\n6\n5\n34\n15\n-1\n13\n4\n22\n74\n7\n-1\n70\n38\n61\n45\n53\n46\n22\n-1\n65\n34\n19\n43\n48\n33\n58\n36\n-1\n47\n24\n34",
"output": "6"
},
{
"input": "5\n2\n3\n4\n5\n-1",
"output": "5"
}
] | 1,682,380,832 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | def dfs(employee, managers, visited):
"""
Depth-First Search (DFS) function to find employees in the same group.
"""
group = set() # Set to store employees in the same group
stack = [employee] # Stack to store employees to visit
visited.add(employee) # Mark the current employee as visited
while stack:
current = stack.pop() # Get the next employee to visit from the stack
# Check if the current employee has an immediate manager and it has not been visited yet
if managers[current] != -1 and managers[current] not in visited:
stack.append(managers[current]) # Add the immediate manager to the stack
# Add the current employee to the group
group.add(current)
return group
n = int(input()) # Read the number of employees
managers = [-1] * n # Initialize the managers list with -1 values
# Read the immediate managers for each employee
for i in range(n):
manager = int(input())
if manager != -1:
managers[i] = manager - 1 # Subtract 1 to convert from 1-indexed to 0-indexed
groups = set() # Set to store the groups
visited = set() # Set to store visited employees
for i in range(n):
if i not in visited:
group = dfs(i, managers, visited) # Find employees in the same group using DFS
groups.add(frozenset(group)) # Add the group to the groups set
print(len(groups)) # Print the number of groups formed
| Title: Party
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A company has *n* employees numbered from 1 to *n*. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee *A* is said to be the superior of another employee *B* if at least one of the following is true:
- Employee *A* is the immediate manager of employee *B* - Employee *B* has an immediate manager employee *C* such that employee *A* is the superior of employee *C*.
The company will not have a managerial cycle. That is, there will not exist an employee who is the superior of his/her own immediate manager.
Today the company is going to arrange a party. This involves dividing all *n* employees into several groups: every employee must belong to exactly one group. Furthermore, within any single group, there must not be two employees *A* and *B* such that *A* is the superior of *B*.
What is the minimum number of groups that must be formed?
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=2000) — the number of employees.
The next *n* lines contain the integers *p**i* (1<=≤<=*p**i*<=≤<=*n* or *p**i*<==<=-1). Every *p**i* denotes the immediate manager for the *i*-th employee. If *p**i* is -1, that means that the *i*-th employee does not have an immediate manager.
It is guaranteed, that no employee will be the immediate manager of him/herself (*p**i*<=≠<=*i*). Also, there will be no managerial cycles.
Output Specification:
Print a single integer denoting the minimum number of groups that will be formed in the party.
Demo Input:
['5\n-1\n1\n2\n1\n-1\n']
Demo Output:
['3\n']
Note:
For the first example, three groups are sufficient, for example:
- Employee 1 - Employees 2 and 4 - Employees 3 and 5 | ```python
def dfs(employee, managers, visited):
"""
Depth-First Search (DFS) function to find employees in the same group.
"""
group = set() # Set to store employees in the same group
stack = [employee] # Stack to store employees to visit
visited.add(employee) # Mark the current employee as visited
while stack:
current = stack.pop() # Get the next employee to visit from the stack
# Check if the current employee has an immediate manager and it has not been visited yet
if managers[current] != -1 and managers[current] not in visited:
stack.append(managers[current]) # Add the immediate manager to the stack
# Add the current employee to the group
group.add(current)
return group
n = int(input()) # Read the number of employees
managers = [-1] * n # Initialize the managers list with -1 values
# Read the immediate managers for each employee
for i in range(n):
manager = int(input())
if manager != -1:
managers[i] = manager - 1 # Subtract 1 to convert from 1-indexed to 0-indexed
groups = set() # Set to store the groups
visited = set() # Set to store visited employees
for i in range(n):
if i not in visited:
group = dfs(i, managers, visited) # Find employees in the same group using DFS
groups.add(frozenset(group)) # Add the group to the groups set
print(len(groups)) # Print the number of groups formed
``` | 0 |
|
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square. | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3",
"output": "1"
},
{
"input": "2 3 4",
"output": "1"
},
{
"input": "1000000000 1000000000 1",
"output": "1000000000000000000"
},
{
"input": "12 13 4",
"output": "12"
},
{
"input": "222 332 5",
"output": "3015"
},
{
"input": "1000 1000 10",
"output": "10000"
},
{
"input": "1001 1000 10",
"output": "10100"
},
{
"input": "100 10001 1000000000",
"output": "1"
},
{
"input": "1000000000 1000000000 1000000000",
"output": "1"
},
{
"input": "1000000000 1000000000 999999999",
"output": "4"
},
{
"input": "1000000000 1000000000 192",
"output": "27126743055556"
},
{
"input": "1000000000 987654321 1",
"output": "987654321000000000"
},
{
"input": "456784567 1000000000 51",
"output": "175618850864484"
},
{
"input": "39916800 134217728 40320",
"output": "3295710"
}
] | 1,655,398,755 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 62 | 3,379,200 | for i in range(1,4,1):
a=int(input())
if (a%4==0):
print(a)
| Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.
Input Specification:
The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109).
Output Specification:
Write the needed number of flagstones.
Demo Input:
['6 6 4\n']
Demo Output:
['4\n']
Note:
none | ```python
for i in range(1,4,1):
a=int(input())
if (a%4==0):
print(a)
``` | -1 |
377 | A | Maze | PROGRAMMING | 1,600 | [
"dfs and similar"
] | null | null | Pavel loves grid mazes. A grid maze is an *n*<=×<=*m* rectangle maze where each cell is either empty, or is a wall. You can go from one cell to another only if both cells are empty and have a common side.
Pavel drew a grid maze with all empty cells forming a connected area. That is, you can go from any empty cell to any other one. Pavel doesn't like it when his maze has too little walls. He wants to turn exactly *k* empty cells into walls so that all the remaining cells still formed a connected area. Help him. | The first line contains three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*<=≤<=500, 0<=≤<=*k*<=<<=*s*), where *n* and *m* are the maze's height and width, correspondingly, *k* is the number of walls Pavel wants to add and letter *s* represents the number of empty cells in the original maze.
Each of the next *n* lines contains *m* characters. They describe the original maze. If a character on a line equals ".", then the corresponding cell is empty and if the character equals "#", then the cell is a wall. | Print *n* lines containing *m* characters each: the new maze that fits Pavel's requirements. Mark the empty cells that you transformed into walls as "X", the other cells must be left without changes (that is, "." and "#").
It is guaranteed that a solution exists. If there are multiple solutions you can output any of them. | [
"3 4 2\n#..#\n..#.\n#...\n",
"5 4 5\n#...\n#.#.\n.#..\n...#\n.#.#\n"
] | [
"#.X#\nX.#.\n#...\n",
"#XXX\n#X#.\nX#..\n...#\n.#.#\n"
] | none | 500 | [
{
"input": "5 4 5\n#...\n#.#.\n.#..\n...#\n.#.#",
"output": "#XXX\n#X#.\nX#..\n...#\n.#.#"
},
{
"input": "3 3 2\n#.#\n...\n#.#",
"output": "#X#\nX..\n#.#"
},
{
"input": "7 7 18\n#.....#\n..#.#..\n.#...#.\n...#...\n.#...#.\n..#.#..\n#.....#",
"output": "#XXXXX#\nXX#X#X.\nX#XXX#.\nXXX#...\nX#...#.\nX.#.#..\n#.....#"
},
{
"input": "1 1 0\n.",
"output": "."
},
{
"input": "2 3 1\n..#\n#..",
"output": "X.#\n#.."
},
{
"input": "2 3 1\n#..\n..#",
"output": "#.X\n..#"
},
{
"input": "3 3 1\n...\n.#.\n..#",
"output": "...\n.#X\n..#"
},
{
"input": "3 3 1\n...\n.#.\n#..",
"output": "...\nX#.\n#.."
},
{
"input": "5 4 4\n#..#\n....\n.##.\n....\n#..#",
"output": "#XX#\nXX..\n.##.\n....\n#..#"
},
{
"input": "5 5 2\n.#..#\n..#.#\n#....\n##.#.\n###..",
"output": "X#..#\nX.#.#\n#....\n##.#.\n###.."
},
{
"input": "4 6 3\n#.....\n#.#.#.\n.#...#\n...#.#",
"output": "#.....\n#X#.#X\nX#...#\n...#.#"
},
{
"input": "7 5 4\n.....\n.#.#.\n#...#\n.#.#.\n.#...\n..#..\n....#",
"output": "X...X\nX#.#X\n#...#\n.#.#.\n.#...\n..#..\n....#"
},
{
"input": "16 14 19\n##############\n..############\n#.############\n#..###########\n....##########\n..############\n.#############\n.#.###########\n....##########\n###..#########\n##...#########\n###....#######\n###.##.......#\n###..###.#..#.\n###....#......\n#...#...##.###",
"output": "##############\nXX############\n#X############\n#XX###########\nXXXX##########\nXX############\nX#############\nX#.###########\nX...##########\n###..#########\n##...#########\n###....#######\n###.##.......#\n###..###.#..#.\n###...X#......\n#X..#XXX##.###"
},
{
"input": "10 17 32\n######.##########\n####.#.##########\n...#....#########\n.........########\n##.......########\n........#########\n#.....###########\n#################\n#################\n#################",
"output": "######X##########\n####X#X##########\nXXX#XXXX#########\nXXXXXXXXX########\n##XXX.XXX########\nXXXX...X#########\n#XX...###########\n#################\n#################\n#################"
},
{
"input": "16 10 38\n##########\n##########\n##########\n..########\n...#######\n...#######\n...#######\n....######\n.....####.\n......###.\n......##..\n.......#..\n.........#\n.........#\n.........#\n.........#",
"output": "##########\n##########\n##########\nXX########\nXXX#######\nXXX#######\nXXX#######\nXXXX######\nXXXXX####.\nXXXXX.###.\nXXXX..##..\nXXX....#..\nXXX......#\nXX.......#\nX........#\n.........#"
},
{
"input": "15 16 19\n########.....###\n########.....###\n############.###\n############.###\n############.###\n############.###\n############.###\n############.###\n############.###\n############.###\n.....#####.#..##\n................\n.#...........###\n###.########.###\n###.########.###",
"output": "########XXXXX###\n########XXXXX###\n############.###\n############.###\n############.###\n############.###\n############.###\n############.###\n############.###\n############.###\nXXXX.#####.#..##\nXXX.............\nX#...........###\n###.########.###\n###X########.###"
},
{
"input": "12 19 42\n.........##########\n...................\n.##.##############.\n..################.\n..#################\n..#################\n..#################\n..#################\n..#################\n..#################\n..##########.######\n.............######",
"output": "XXXXXXXXX##########\nXXXXXXXXXXXXXXXXXXX\nX##X##############X\nXX################X\nXX#################\nXX#################\nXX#################\nX.#################\nX.#################\n..#################\n..##########.######\n.............######"
},
{
"input": "3 5 1\n#...#\n..#..\n..#..",
"output": "#...#\n..#..\nX.#.."
},
{
"input": "4 5 10\n.....\n.....\n..#..\n..#..",
"output": "XXX..\nXXX..\nXX#..\nXX#.."
},
{
"input": "3 5 3\n.....\n..#..\n..#..",
"output": ".....\nX.#..\nXX#.."
},
{
"input": "3 5 1\n#....\n..#..\n..###",
"output": "#....\n..#.X\n..###"
},
{
"input": "4 5 1\n.....\n.##..\n..#..\n..###",
"output": ".....\n.##..\n..#.X\n..###"
},
{
"input": "3 5 2\n..#..\n..#..\n....#",
"output": "X.#..\nX.#..\n....#"
},
{
"input": "10 10 1\n##########\n##......##\n#..#..#..#\n#..####..#\n#######.##\n#######.##\n#..####..#\n#..#..#..#\n##......##\n##########",
"output": "##########\n##......##\n#..#..#..#\n#X.####..#\n#######.##\n#######.##\n#..####..#\n#..#..#..#\n##......##\n##########"
},
{
"input": "10 10 3\n..........\n.########.\n.########.\n.########.\n.########.\n.########.\n.#######..\n.#######..\n.####..###\n.......###",
"output": "..........\n.########.\n.########.\n.########.\n.########.\n.########.\n.#######X.\n.#######XX\n.####..###\n.......###"
},
{
"input": "5 7 10\n..#....\n..#.#..\n.##.#..\n..#.#..\n....#..",
"output": "XX#....\nXX#.#..\nX##.#..\nXX#.#..\nXXX.#.."
},
{
"input": "5 7 10\n..#....\n..#.##.\n.##.##.\n..#.#..\n....#..",
"output": "XX#....\nXX#.##.\nX##.##.\nXX#.#..\nXXX.#.."
},
{
"input": "10 10 1\n##########\n##..##..##\n#...##...#\n#.######.#\n#..####..#\n#..####..#\n#.######.#\n#........#\n##..##..##\n##########",
"output": "##########\n##.X##..##\n#...##...#\n#.######.#\n#..####..#\n#..####..#\n#.######.#\n#........#\n##..##..##\n##########"
},
{
"input": "4 5 1\n.....\n.###.\n..#..\n..#..",
"output": ".....\n.###.\n..#..\n.X#.."
},
{
"input": "2 5 2\n###..\n###..",
"output": "###X.\n###X."
},
{
"input": "2 5 3\n.....\n..#..",
"output": "X....\nXX#.."
},
{
"input": "12 12 3\n############\n#..........#\n#.########.#\n#.########.#\n#.########.#\n#.########.#\n#.########.#\n#.#######..#\n#.#######..#\n#.####..####\n#.......####\n############",
"output": "############\n#..........#\n#.########.#\n#.########.#\n#.########.#\n#.########.#\n#.########.#\n#.#######X.#\n#.#######XX#\n#.####..####\n#.......####\n############"
},
{
"input": "5 5 1\n.....\n.##..\n..###\n..###\n#####",
"output": ".....\n.##.X\n..###\n..###\n#####"
},
{
"input": "4 4 1\n....\n.#..\n..##\n..##",
"output": "....\n.#.X\n..##\n..##"
},
{
"input": "5 5 1\n....#\n.##..\n.##..\n...##\n...##",
"output": "....#\n.##..\n.##.X\n...##\n...##"
},
{
"input": "5 5 1\n.....\n.##..\n..###\n..###\n..###",
"output": ".....\n.##.X\n..###\n..###\n..###"
},
{
"input": "4 5 1\n#....\n#.#..\n..###\n..###",
"output": "#....\n#.#.X\n..###\n..###"
},
{
"input": "4 4 3\n....\n.#..\n..##\n..##",
"output": "...X\n.#XX\n..##\n..##"
},
{
"input": "4 7 6\n.......\n....#..\n.##.#..\n....#..",
"output": "X......\nX...#..\nX##.#..\nXXX.#.."
},
{
"input": "8 8 7\n........\n.##.....\n.#######\n..######\n..######\n..######\n..######\n..######",
"output": ".....XXX\n.##.XXXX\n.#######\n..######\n..######\n..######\n..######\n..######"
}
] | 1,636,075,280 | 2,147,483,647 | Python 3 | OK | TESTS | 89 | 670 | 12,595,200 |
n,m,k = [int(x) for x in input().split(" ")]
mp = []
dotc = 0
mp=[input().replace('.','X') for i in range(n)]
k=n*m-k-sum(i.count('#')for i in mp)
mp=[list(i) for i in mp]
i = 0
while k:
if 'X' in mp[i]:
j=mp[i].index('X')
mp[i][j],bfs='.',[(i,j)]
k-=1
break
i+=1
while k>0:
x,y = bfs.pop()
for i,j in ((x-1,y),(x,y-1),(x+1,y),(x,y+1)):
if 0<=i<n and 0<=j<m and mp[i][j] == "X":
mp[i][j] = '.'
bfs.append((i,j))
k-=1
if k <= 0:break
for i in range(n):
for j in range(m):
print(mp[i][j],end="")
print()
| Title: Maze
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pavel loves grid mazes. A grid maze is an *n*<=×<=*m* rectangle maze where each cell is either empty, or is a wall. You can go from one cell to another only if both cells are empty and have a common side.
Pavel drew a grid maze with all empty cells forming a connected area. That is, you can go from any empty cell to any other one. Pavel doesn't like it when his maze has too little walls. He wants to turn exactly *k* empty cells into walls so that all the remaining cells still formed a connected area. Help him.
Input Specification:
The first line contains three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*<=≤<=500, 0<=≤<=*k*<=<<=*s*), where *n* and *m* are the maze's height and width, correspondingly, *k* is the number of walls Pavel wants to add and letter *s* represents the number of empty cells in the original maze.
Each of the next *n* lines contains *m* characters. They describe the original maze. If a character on a line equals ".", then the corresponding cell is empty and if the character equals "#", then the cell is a wall.
Output Specification:
Print *n* lines containing *m* characters each: the new maze that fits Pavel's requirements. Mark the empty cells that you transformed into walls as "X", the other cells must be left without changes (that is, "." and "#").
It is guaranteed that a solution exists. If there are multiple solutions you can output any of them.
Demo Input:
['3 4 2\n#..#\n..#.\n#...\n', '5 4 5\n#...\n#.#.\n.#..\n...#\n.#.#\n']
Demo Output:
['#.X#\nX.#.\n#...\n', '#XXX\n#X#.\nX#..\n...#\n.#.#\n']
Note:
none | ```python
n,m,k = [int(x) for x in input().split(" ")]
mp = []
dotc = 0
mp=[input().replace('.','X') for i in range(n)]
k=n*m-k-sum(i.count('#')for i in mp)
mp=[list(i) for i in mp]
i = 0
while k:
if 'X' in mp[i]:
j=mp[i].index('X')
mp[i][j],bfs='.',[(i,j)]
k-=1
break
i+=1
while k>0:
x,y = bfs.pop()
for i,j in ((x-1,y),(x,y-1),(x+1,y),(x,y+1)):
if 0<=i<n and 0<=j<m and mp[i][j] == "X":
mp[i][j] = '.'
bfs.append((i,j))
k-=1
if k <= 0:break
for i in range(n):
for j in range(m):
print(mp[i][j],end="")
print()
``` | 3 |
|
0 | none | none | none | 0 | [
"none"
] | null | null | Hongcow is ruler of the world. As ruler of the world, he wants to make it easier for people to travel by road within their own countries.
The world can be modeled as an undirected graph with *n* nodes and *m* edges. *k* of the nodes are home to the governments of the *k* countries that make up the world.
There is at most one edge connecting any two nodes and no edge connects a node to itself. Furthermore, for any two nodes corresponding to governments, there is no path between those two nodes. Any graph that satisfies all of these conditions is stable.
Hongcow wants to add as many edges as possible to the graph while keeping it stable. Determine the maximum number of edges Hongcow can add. | The first line of input will contain three integers *n*, *m* and *k* (1<=≤<=*n*<=≤<=1<=000, 0<=≤<=*m*<=≤<=100<=000, 1<=≤<=*k*<=≤<=*n*) — the number of vertices and edges in the graph, and the number of vertices that are homes of the government.
The next line of input will contain *k* integers *c*1,<=*c*2,<=...,<=*c**k* (1<=≤<=*c**i*<=≤<=*n*). These integers will be pairwise distinct and denote the nodes that are home to the governments in this world.
The following *m* lines of input will contain two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*). This denotes an undirected edge between nodes *u**i* and *v**i*.
It is guaranteed that the graph described by the input is stable. | Output a single integer, the maximum number of edges Hongcow can add to the graph while keeping it stable. | [
"4 1 2\n1 3\n1 2\n",
"3 3 1\n2\n1 2\n1 3\n2 3\n"
] | [
"2\n",
"0\n"
] | For the first sample test, the graph looks like this:
For the second sample test, the graph looks like this: | 0 | [
{
"input": "4 1 2\n1 3\n1 2",
"output": "2"
},
{
"input": "3 3 1\n2\n1 2\n1 3\n2 3",
"output": "0"
},
{
"input": "10 3 2\n1 10\n1 2\n1 3\n4 5",
"output": "33"
},
{
"input": "1 0 1\n1",
"output": "0"
},
{
"input": "1000 0 1\n72",
"output": "499500"
},
{
"input": "24 38 2\n4 13\n7 1\n24 1\n2 8\n17 2\n2 18\n22 2\n23 3\n5 9\n21 5\n6 7\n6 19\n6 20\n11 7\n7 20\n13 8\n16 8\n9 10\n14 9\n21 9\n12 10\n10 22\n23 10\n17 11\n11 24\n20 12\n13 16\n13 23\n15 14\n17 14\n14 20\n19 16\n17 20\n17 23\n18 22\n18 23\n22 19\n21 20\n23 24",
"output": "215"
},
{
"input": "10 30 1\n4\n1 2\n3 1\n4 1\n1 6\n1 8\n10 1\n2 4\n2 7\n3 4\n3 5\n7 3\n3 9\n10 3\n5 4\n6 4\n7 4\n9 4\n10 4\n6 5\n5 8\n9 5\n10 5\n6 7\n9 6\n10 6\n7 8\n9 7\n10 7\n9 8\n10 8",
"output": "15"
},
{
"input": "10 13 2\n5 10\n2 1\n1 4\n2 3\n2 8\n3 4\n7 3\n4 6\n8 4\n4 9\n6 7\n6 9\n10 6\n7 8",
"output": "23"
},
{
"input": "10 10 3\n2 5 6\n1 3\n4 1\n4 3\n5 3\n3 9\n8 4\n9 4\n5 10\n8 7\n10 8",
"output": "18"
},
{
"input": "10 5 3\n1 5 9\n1 3\n1 8\n2 3\n8 4\n5 7",
"output": "17"
},
{
"input": "6 4 2\n1 4\n1 2\n2 3\n4 5\n5 6",
"output": "2"
},
{
"input": "7 8 2\n1 4\n1 2\n2 3\n4 5\n4 6\n4 7\n5 6\n5 7\n6 7",
"output": "1"
},
{
"input": "5 2 3\n1 3 4\n1 5\n2 4",
"output": "0"
},
{
"input": "5 3 2\n1 2\n2 3\n2 4\n1 5",
"output": "1"
},
{
"input": "9 5 2\n1 5\n1 2\n2 3\n3 4\n5 6\n6 7",
"output": "13"
},
{
"input": "6 4 1\n1\n2 3\n3 4\n4 5\n5 6",
"output": "11"
},
{
"input": "6 4 2\n1 5\n1 2\n2 3\n3 4\n5 6",
"output": "3"
},
{
"input": "7 3 3\n1 5 6\n1 2\n1 3\n6 7",
"output": "4"
},
{
"input": "5 2 2\n1 2\n1 3\n2 4",
"output": "2"
},
{
"input": "11 7 2\n1 4\n1 2\n1 3\n4 5\n4 6\n5 6\n9 10\n1 11",
"output": "24"
},
{
"input": "20 4 5\n1 3 9 10 20\n5 6\n1 2\n7 9\n4 10",
"output": "89"
}
] | 1,481,999,128 | 6,628 | PyPy 3 | WRONG_ANSWER | PRETESTS | 1 | 93 | 23,142,400 | n,m,k = map(int,input().split())
c = [int(s) for s in input().split()]
cap = 0
p = 0
j = 2
for i in range(m):
u,v = map(int,input().split())
if c.count(u) != 0 or c.count(v) != 0:
cap +=1
else:
p += 1
knv = n - (m*2)
knc = len(c) - cap
knv -= knc
j = knv + 1
if p > 0:
j += p + 1
print(j)
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Hongcow is ruler of the world. As ruler of the world, he wants to make it easier for people to travel by road within their own countries.
The world can be modeled as an undirected graph with *n* nodes and *m* edges. *k* of the nodes are home to the governments of the *k* countries that make up the world.
There is at most one edge connecting any two nodes and no edge connects a node to itself. Furthermore, for any two nodes corresponding to governments, there is no path between those two nodes. Any graph that satisfies all of these conditions is stable.
Hongcow wants to add as many edges as possible to the graph while keeping it stable. Determine the maximum number of edges Hongcow can add.
Input Specification:
The first line of input will contain three integers *n*, *m* and *k* (1<=≤<=*n*<=≤<=1<=000, 0<=≤<=*m*<=≤<=100<=000, 1<=≤<=*k*<=≤<=*n*) — the number of vertices and edges in the graph, and the number of vertices that are homes of the government.
The next line of input will contain *k* integers *c*1,<=*c*2,<=...,<=*c**k* (1<=≤<=*c**i*<=≤<=*n*). These integers will be pairwise distinct and denote the nodes that are home to the governments in this world.
The following *m* lines of input will contain two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*). This denotes an undirected edge between nodes *u**i* and *v**i*.
It is guaranteed that the graph described by the input is stable.
Output Specification:
Output a single integer, the maximum number of edges Hongcow can add to the graph while keeping it stable.
Demo Input:
['4 1 2\n1 3\n1 2\n', '3 3 1\n2\n1 2\n1 3\n2 3\n']
Demo Output:
['2\n', '0\n']
Note:
For the first sample test, the graph looks like this:
For the second sample test, the graph looks like this: | ```python
n,m,k = map(int,input().split())
c = [int(s) for s in input().split()]
cap = 0
p = 0
j = 2
for i in range(m):
u,v = map(int,input().split())
if c.count(u) != 0 or c.count(v) != 0:
cap +=1
else:
p += 1
knv = n - (m*2)
knc = len(c) - cap
knv -= knc
j = knv + 1
if p > 0:
j += p + 1
print(j)
``` | 0 |
|
758 | A | Holiday Of Equality | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are *n* citizens, the welfare of each of them is estimated as the integer in *a**i* burles (burle is the currency in Berland).
You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them. | The first line contains the integer *n* (1<=≤<=*n*<=≤<=100) — the number of citizens in the kingdom.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* (0<=≤<=*a**i*<=≤<=106) — the welfare of the *i*-th citizen. | In the only line print the integer *S* — the minimum number of burles which are had to spend. | [
"5\n0 1 2 3 4\n",
"5\n1 1 0 1 1\n",
"3\n1 3 1\n",
"1\n12\n"
] | [
"10",
"1",
"4",
"0"
] | In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.
In the second example it is enough to give one burle to the third citizen.
In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3.
In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles. | 500 | [
{
"input": "5\n0 1 2 3 4",
"output": "10"
},
{
"input": "5\n1 1 0 1 1",
"output": "1"
},
{
"input": "3\n1 3 1",
"output": "4"
},
{
"input": "1\n12",
"output": "0"
},
{
"input": "3\n1 2 3",
"output": "3"
},
{
"input": "14\n52518 718438 358883 462189 853171 592966 225788 46977 814826 295697 676256 561479 56545 764281",
"output": "5464380"
},
{
"input": "21\n842556 216391 427181 626688 775504 168309 851038 448402 880826 73697 593338 519033 135115 20128 424606 939484 846242 756907 377058 241543 29353",
"output": "9535765"
},
{
"input": "3\n1 3 2",
"output": "3"
},
{
"input": "3\n2 1 3",
"output": "3"
},
{
"input": "3\n2 3 1",
"output": "3"
},
{
"input": "3\n3 1 2",
"output": "3"
},
{
"input": "3\n3 2 1",
"output": "3"
},
{
"input": "1\n228503",
"output": "0"
},
{
"input": "2\n32576 550340",
"output": "517764"
},
{
"input": "3\n910648 542843 537125",
"output": "741328"
},
{
"input": "4\n751720 572344 569387 893618",
"output": "787403"
},
{
"input": "6\n433864 631347 597596 794426 713555 231193",
"output": "1364575"
},
{
"input": "9\n31078 645168 695751 126111 375934 150495 838412 434477 993107",
"output": "4647430"
},
{
"input": "30\n315421 772664 560686 654312 151528 356749 351486 707462 820089 226682 546700 136028 824236 842130 578079 337807 665903 764100 617900 822937 992759 591749 651310 742085 767695 695442 17967 515106 81059 186025",
"output": "13488674"
},
{
"input": "45\n908719 394261 815134 419990 926993 383792 772842 277695 527137 655356 684956 695716 273062 550324 106247 399133 442382 33076 462920 294674 846052 817752 421365 474141 290471 358990 109812 74492 543281 169434 919692 786809 24028 197184 310029 801476 699355 429672 51343 374128 776726 850380 293868 981569 550763",
"output": "21993384"
},
{
"input": "56\n100728 972537 13846 385421 756708 184642 259487 319707 376662 221694 675284 972837 499419 13846 38267 289898 901299 831197 954715 197515 514102 910423 127555 883934 362472 870788 538802 741008 973434 448124 391526 363321 947321 544618 68006 782313 955075 741981 815027 723297 585059 718114 700739 413489 454091 736144 308999 98065 3716 347323 9635 289003 986510 607065 60236 273351",
"output": "26984185"
},
{
"input": "70\n644488 5444 150441 714420 602059 335330 510670 196555 546346 740011 509449 850947 692874 524857 750434 952985 223744 374727 896124 753037 367352 679050 560202 172728 569291 778616 332116 286927 843598 372698 244906 498046 900681 709791 420904 724593 864493 813094 791377 39998 296710 625656 403891 579231 706693 984045 16901 574259 562265 761104 930361 256045 124461 538980 573508 372148 988722 108592 784354 55302 232524 277205 782251 299943 436488 743389 324618 742543 266915 99642",
"output": "32816391"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n1000000",
"output": "0"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "0"
},
{
"input": "100\n1000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "99000000"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1000000",
"output": "99000000"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "99000000"
},
{
"input": "3\n0 0 0",
"output": "0"
},
{
"input": "50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "0"
},
{
"input": "3\n5 0 0",
"output": "10"
},
{
"input": "5\n2 10 0 0 0",
"output": "38"
}
] | 1,688,037,606 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 46 | 0 | # Read the number of citizens
n = int(input())
# Read the welfare values of the citizens
welfare = list(map(int, input().split()))
# Find the maximum welfare value
max_wealth = max(welfare)
# Calculate the total expenses
total_expenses = sum(max_wealth - wealth for wealth in welfare)
# Print the total expenses
print(total_expenses)
| Title: Holiday Of Equality
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are *n* citizens, the welfare of each of them is estimated as the integer in *a**i* burles (burle is the currency in Berland).
You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them.
Input Specification:
The first line contains the integer *n* (1<=≤<=*n*<=≤<=100) — the number of citizens in the kingdom.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* (0<=≤<=*a**i*<=≤<=106) — the welfare of the *i*-th citizen.
Output Specification:
In the only line print the integer *S* — the minimum number of burles which are had to spend.
Demo Input:
['5\n0 1 2 3 4\n', '5\n1 1 0 1 1\n', '3\n1 3 1\n', '1\n12\n']
Demo Output:
['10', '1', '4', '0']
Note:
In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.
In the second example it is enough to give one burle to the third citizen.
In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3.
In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles. | ```python
# Read the number of citizens
n = int(input())
# Read the welfare values of the citizens
welfare = list(map(int, input().split()))
# Find the maximum welfare value
max_wealth = max(welfare)
# Calculate the total expenses
total_expenses = sum(max_wealth - wealth for wealth in welfare)
# Print the total expenses
print(total_expenses)
``` | 3 |
|
667 | A | Pouring Rain | PROGRAMMING | 1,100 | [
"geometry",
"math"
] | null | null | A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition — when it rains, you go on the street and stay silent for a moment, contemplate all around you, enjoy freshness, think about big deeds you have to do.
Today everything had changed quietly. You went on the street with a cup contained water, your favorite drink. In a moment when you were drinking a water you noticed that the process became quite long: the cup still contained water because of rain. You decided to make a formal model of what was happening and to find if it was possible to drink all water in that situation.
Thus, your cup is a cylinder with diameter equals *d* centimeters. Initial level of water in cup equals *h* centimeters from the bottom.
You drink a water with a speed equals *v* milliliters per second. But rain goes with such speed that if you do not drink a water from the cup, the level of water increases on *e* centimeters per second. The process of drinking water from the cup and the addition of rain to the cup goes evenly and continuously.
Find the time needed to make the cup empty or find that it will never happen. It is guaranteed that if it is possible to drink all water, it will happen not later than after 104 seconds.
Note one milliliter equals to one cubic centimeter. | The only line of the input contains four integer numbers *d*,<=*h*,<=*v*,<=*e* (1<=≤<=*d*,<=*h*,<=*v*,<=*e*<=≤<=104), where:
- *d* — the diameter of your cylindrical cup, - *h* — the initial level of water in the cup, - *v* — the speed of drinking process from the cup in milliliters per second, - *e* — the growth of water because of rain if you do not drink from the cup. | If it is impossible to make the cup empty, print "NO" (without quotes).
Otherwise print "YES" (without quotes) in the first line. In the second line print a real number — time in seconds needed the cup will be empty. The answer will be considered correct if its relative or absolute error doesn't exceed 10<=-<=4. It is guaranteed that if the answer exists, it doesn't exceed 104. | [
"1 2 3 100\n",
"1 1 1 1\n"
] | [
"NO\n",
"YES\n3.659792366325\n"
] | In the first example the water fills the cup faster than you can drink from it.
In the second example area of the cup's bottom equals to <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/419dc74dcd7bc392019c9fe748fe1fdb08ab521a.png" style="max-width: 100.0%;max-height: 100.0%;"/>, thus we can conclude that you decrease the level of water by <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/e8edb237e1f805fe83c2f47e48d3a9d03f2ee304.png" style="max-width: 100.0%;max-height: 100.0%;"/> centimeters per second. At the same time water level increases by 1 centimeter per second due to rain. Thus, cup will be empty in <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/9dae615d7e2c5c7c03cb478848fb06aba1a8942e.png" style="max-width: 100.0%;max-height: 100.0%;"/> seconds. | 500 | [
{
"input": "1 2 3 100",
"output": "NO"
},
{
"input": "1 1 1 1",
"output": "YES\n3.659792366325"
},
{
"input": "48 7946 7992 72",
"output": "NO"
},
{
"input": "72 6791 8546 46",
"output": "NO"
},
{
"input": "100 5635 9099 23",
"output": "NO"
},
{
"input": "20 287 3845 5",
"output": "YES\n39.646277165210"
},
{
"input": "48 6428 9807 83",
"output": "NO"
},
{
"input": "72 5272 4552 64",
"output": "NO"
},
{
"input": "100 4117 5106 34",
"output": "NO"
},
{
"input": "20 2961 9852 15",
"output": "YES\n180.991437129723"
},
{
"input": "48 1805 3109 93",
"output": "NO"
},
{
"input": "72 8534 7042 65",
"output": "NO"
},
{
"input": "1 47 80 68",
"output": "YES\n1.388102806810"
},
{
"input": "4 495 8813 1",
"output": "YES\n0.706823517575"
},
{
"input": "5 2797 5925 9",
"output": "YES\n9.553973511669"
},
{
"input": "1 8324 4362 23",
"output": "YES\n1.505007106354"
},
{
"input": "6 1976 8455 3",
"output": "YES\n6.674898722265"
},
{
"input": "7 2644 8080 5",
"output": "YES\n12.900417790197"
},
{
"input": "3 4183 5491 98",
"output": "YES\n6.162185601824"
},
{
"input": "2 8591 320 101",
"output": "YES\n9999.259991757254"
},
{
"input": "10000 10000 10000 10000",
"output": "NO"
},
{
"input": "2 5000 12 3",
"output": "YES\n6099.653943875812"
},
{
"input": "10 1000 100 1",
"output": "YES\n3659.792366325487"
}
] | 1,461,948,353 | 653 | Python 3 | WRONG_ANSWER | PRETESTS | 5 | 61 | 4,608,000 | d, h, v, e = map(int, input().split())
p = 3.1415926
u = e * p * (d / 2) * (d / 2)
if u > v:
print('NO')
else:
print('YES')
ans = h / (v - u)
print(ans - 1) | Title: Pouring Rain
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition — when it rains, you go on the street and stay silent for a moment, contemplate all around you, enjoy freshness, think about big deeds you have to do.
Today everything had changed quietly. You went on the street with a cup contained water, your favorite drink. In a moment when you were drinking a water you noticed that the process became quite long: the cup still contained water because of rain. You decided to make a formal model of what was happening and to find if it was possible to drink all water in that situation.
Thus, your cup is a cylinder with diameter equals *d* centimeters. Initial level of water in cup equals *h* centimeters from the bottom.
You drink a water with a speed equals *v* milliliters per second. But rain goes with such speed that if you do not drink a water from the cup, the level of water increases on *e* centimeters per second. The process of drinking water from the cup and the addition of rain to the cup goes evenly and continuously.
Find the time needed to make the cup empty or find that it will never happen. It is guaranteed that if it is possible to drink all water, it will happen not later than after 104 seconds.
Note one milliliter equals to one cubic centimeter.
Input Specification:
The only line of the input contains four integer numbers *d*,<=*h*,<=*v*,<=*e* (1<=≤<=*d*,<=*h*,<=*v*,<=*e*<=≤<=104), where:
- *d* — the diameter of your cylindrical cup, - *h* — the initial level of water in the cup, - *v* — the speed of drinking process from the cup in milliliters per second, - *e* — the growth of water because of rain if you do not drink from the cup.
Output Specification:
If it is impossible to make the cup empty, print "NO" (without quotes).
Otherwise print "YES" (without quotes) in the first line. In the second line print a real number — time in seconds needed the cup will be empty. The answer will be considered correct if its relative or absolute error doesn't exceed 10<=-<=4. It is guaranteed that if the answer exists, it doesn't exceed 104.
Demo Input:
['1 2 3 100\n', '1 1 1 1\n']
Demo Output:
['NO\n', 'YES\n3.659792366325\n']
Note:
In the first example the water fills the cup faster than you can drink from it.
In the second example area of the cup's bottom equals to <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/419dc74dcd7bc392019c9fe748fe1fdb08ab521a.png" style="max-width: 100.0%;max-height: 100.0%;"/>, thus we can conclude that you decrease the level of water by <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/e8edb237e1f805fe83c2f47e48d3a9d03f2ee304.png" style="max-width: 100.0%;max-height: 100.0%;"/> centimeters per second. At the same time water level increases by 1 centimeter per second due to rain. Thus, cup will be empty in <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/9dae615d7e2c5c7c03cb478848fb06aba1a8942e.png" style="max-width: 100.0%;max-height: 100.0%;"/> seconds. | ```python
d, h, v, e = map(int, input().split())
p = 3.1415926
u = e * p * (d / 2) * (d / 2)
if u > v:
print('NO')
else:
print('YES')
ans = h / (v - u)
print(ans - 1)
``` | 0 |
|
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces. | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10\n25 -33 43\n-27 -42 28\n-35 -20 19\n41 -42 -1\n49 -39 -4\n-49 -22 7\n-19 29 41\n8 -27 -43\n8 34 9\n-11 -3 33",
"output": "NO"
},
{
"input": "10\n-6 21 18\n20 -11 -8\n37 -11 41\n-5 8 33\n29 23 32\n30 -33 -11\n39 -49 -36\n28 34 -49\n22 29 -34\n-18 -6 7",
"output": "NO"
},
{
"input": "10\n47 -2 -27\n0 26 -14\n5 -12 33\n2 18 3\n45 -30 -49\n4 -18 8\n-46 -44 -41\n-22 -10 -40\n-35 -21 26\n33 20 38",
"output": "NO"
},
{
"input": "13\n-3 -36 -46\n-11 -50 37\n42 -11 -15\n9 42 44\n-29 -12 24\n3 9 -40\n-35 13 50\n14 43 18\n-13 8 24\n-48 -15 10\n50 9 -50\n21 0 -50\n0 0 -6",
"output": "YES"
},
{
"input": "14\n43 23 17\n4 17 44\n5 -5 -16\n-43 -7 -6\n47 -48 12\n50 47 -45\n2 14 43\n37 -30 15\n4 -17 -11\n17 9 -45\n-50 -3 -8\n-50 0 0\n-50 0 0\n-16 0 0",
"output": "YES"
},
{
"input": "13\n29 49 -11\n38 -11 -20\n25 1 -40\n-11 28 11\n23 -19 1\n45 -41 -17\n-3 0 -19\n-13 -33 49\n-30 0 28\n34 17 45\n-50 9 -27\n-50 0 0\n-37 0 0",
"output": "YES"
},
{
"input": "12\n3 28 -35\n-32 -44 -17\n9 -25 -6\n-42 -22 20\n-19 15 38\n-21 38 48\n-1 -37 -28\n-10 -13 -50\n-5 21 29\n34 28 50\n50 11 -49\n34 0 0",
"output": "YES"
},
{
"input": "37\n-64 -79 26\n-22 59 93\n-5 39 -12\n77 -9 76\n55 -86 57\n83 100 -97\n-70 94 84\n-14 46 -94\n26 72 35\n14 78 -62\n17 82 92\n-57 11 91\n23 15 92\n-80 -1 1\n12 39 18\n-23 -99 -75\n-34 50 19\n-39 84 -7\n45 -30 -39\n-60 49 37\n45 -16 -72\n33 -51 -56\n-48 28 5\n97 91 88\n45 -82 -11\n-21 -15 -90\n-53 73 -26\n-74 85 -90\n-40 23 38\n100 -13 49\n32 -100 -100\n0 -100 -70\n0 -100 0\n0 -100 0\n0 -100 0\n0 -100 0\n0 -37 0",
"output": "YES"
},
{
"input": "4\n68 3 100\n68 21 -100\n-100 -24 0\n-36 0 0",
"output": "YES"
},
{
"input": "33\n-1 -46 -12\n45 -16 -21\n-11 45 -21\n-60 -42 -93\n-22 -45 93\n37 96 85\n-76 26 83\n-4 9 55\n7 -52 -9\n66 8 -85\n-100 -54 11\n-29 59 74\n-24 12 2\n-56 81 85\n-92 69 -52\n-26 -97 91\n54 59 -51\n58 21 -57\n7 68 56\n-47 -20 -51\n-59 77 -13\n-85 27 91\n79 60 -56\n66 -80 5\n21 -99 42\n-31 -29 98\n66 93 76\n-49 45 61\n100 -100 -100\n100 -100 -100\n66 -75 -100\n0 0 -100\n0 0 -87",
"output": "YES"
},
{
"input": "3\n1 2 3\n3 2 1\n0 0 0",
"output": "NO"
},
{
"input": "2\n5 -23 12\n0 0 0",
"output": "NO"
},
{
"input": "1\n0 0 0",
"output": "YES"
},
{
"input": "1\n1 -2 0",
"output": "NO"
},
{
"input": "2\n-23 77 -86\n23 -77 86",
"output": "YES"
},
{
"input": "26\n86 7 20\n-57 -64 39\n-45 6 -93\n-44 -21 100\n-11 -49 21\n73 -71 -80\n-2 -89 56\n-65 -2 7\n5 14 84\n57 41 13\n-12 69 54\n40 -25 27\n-17 -59 0\n64 -91 -30\n-53 9 42\n-54 -8 14\n-35 82 27\n-48 -59 -80\n88 70 79\n94 57 97\n44 63 25\n84 -90 -40\n-100 100 -100\n-92 100 -100\n0 10 -100\n0 0 -82",
"output": "YES"
},
{
"input": "42\n11 27 92\n-18 -56 -57\n1 71 81\n33 -92 30\n82 83 49\n-87 -61 -1\n-49 45 49\n73 26 15\n-22 22 -77\n29 -93 87\n-68 44 -90\n-4 -84 20\n85 67 -6\n-39 26 77\n-28 -64 20\n65 -97 24\n-72 -39 51\n35 -75 -91\n39 -44 -8\n-25 -27 -57\n91 8 -46\n-98 -94 56\n94 -60 59\n-9 -95 18\n-53 -37 98\n-8 -94 -84\n-52 55 60\n15 -14 37\n65 -43 -25\n94 12 66\n-8 -19 -83\n29 81 -78\n-58 57 33\n24 86 -84\n-53 32 -88\n-14 7 3\n89 97 -53\n-5 -28 -91\n-100 100 -6\n-84 100 0\n0 100 0\n0 70 0",
"output": "YES"
},
{
"input": "3\n96 49 -12\n2 -66 28\n-98 17 -16",
"output": "YES"
},
{
"input": "5\n70 -46 86\n-100 94 24\n-27 63 -63\n57 -100 -47\n0 -11 0",
"output": "YES"
},
{
"input": "18\n-86 -28 70\n-31 -89 42\n31 -48 -55\n95 -17 -43\n24 -95 -85\n-21 -14 31\n68 -18 81\n13 31 60\n-15 28 99\n-42 15 9\n28 -61 -62\n-16 71 29\n-28 75 -48\n-77 -67 36\n-100 83 89\n100 100 -100\n57 34 -100\n0 0 -53",
"output": "YES"
},
{
"input": "44\n52 -54 -29\n-82 -5 -94\n-54 43 43\n91 16 71\n7 80 -91\n3 15 29\n-99 -6 -77\n-3 -77 -64\n73 67 34\n25 -10 -18\n-29 91 63\n-72 86 -16\n-68 85 -81\n-3 36 44\n-74 -14 -80\n34 -96 -97\n-76 -78 -33\n-24 44 -58\n98 12 77\n95 -63 -6\n-51 3 -90\n-92 -10 72\n7 3 -68\n57 -53 71\n29 57 -48\n35 -60 10\n79 -70 -61\n-20 77 55\n-86 -15 -35\n84 -88 -18\n100 -42 77\n-20 46 8\n-41 -43 -65\n38 -98 -23\n-100 65 45\n-7 -91 -63\n46 88 -85\n48 59 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 1",
"output": "YES"
},
{
"input": "18\n-14 -64 -91\n-8 -66 -86\n-23 92 -40\n6 -3 -53\n57 41 78\n-79 42 -22\n-88 -17 45\n4 -45 44\n83 -18 -25\n34 86 -92\n75 -30 12\n44 99 11\n-67 -13 72\n22 83 -56\n-37 71 72\n-9 -100 100\n0 -100 31\n0 -58 0",
"output": "YES"
},
{
"input": "23\n-70 37 78\n42 84 6\n28 -94 -24\n-49 76 95\n-67 18 84\n-53 78 -5\n65 -63 -64\n-66 -64 -69\n81 -93 95\n10 52 -79\n-89 -61 -64\n-64 -47 43\n-81 -35 55\n80 82 73\n-60 -81 -18\n49 -10 -19\n-58 70 12\n-24 -15 -93\n98 -93 -54\n-28 -75 11\n100 100 -63\n100 100 0\n56 34 0",
"output": "YES"
},
{
"input": "3\n0 2 -2\n1 -1 3\n-3 0 0",
"output": "NO"
}
] | 1,636,768,973 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 80 | 124 | 28,467,200 | R = lambda: list(map(int, input().split()))
[N] = R()
forces = [0, 0, 0]
for n in range(N): forces += R()
if sum(forces) != 0: print("NO")
else: print("YES") | Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
Input Specification:
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
Output Specification:
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
Demo Input:
['3\n4 1 7\n-2 4 -1\n1 -5 -3\n', '3\n3 -1 7\n-5 2 -4\n2 -1 -3\n']
Demo Output:
['NO', 'YES']
Note:
none | ```python
R = lambda: list(map(int, input().split()))
[N] = R()
forces = [0, 0, 0]
for n in range(N): forces += R()
if sum(forces) != 0: print("NO")
else: print("YES")
``` | 0 |
472 | A | Design Tutorial: Learn from Math | PROGRAMMING | 800 | [
"math",
"number theory"
] | null | null | One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that.
For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two primes". Let's modify it. How about a statement like that: "each integer no less than 12 can be expressed as the sum of two composite numbers." Not like the Goldbach's conjecture, I can prove this theorem.
You are given an integer *n* no less than 12, express it as a sum of two composite numbers. | The only line contains an integer *n* (12<=≤<=*n*<=≤<=106). | Output two composite integers *x* and *y* (1<=<<=*x*,<=*y*<=<<=*n*) such that *x*<=+<=*y*<==<=*n*. If there are multiple solutions, you can output any of them. | [
"12\n",
"15\n",
"23\n",
"1000000\n"
] | [
"4 8\n",
"6 9\n",
"8 15\n",
"500000 500000\n"
] | In the first example, 12 = 4 + 8 and both 4, 8 are composite numbers. You can output "6 6" or "8 4" as well.
In the second example, 15 = 6 + 9. Note that you can't output "1 14" because 1 is not a composite number. | 500 | [
{
"input": "12",
"output": "4 8"
},
{
"input": "15",
"output": "6 9"
},
{
"input": "23",
"output": "8 15"
},
{
"input": "1000000",
"output": "500000 500000"
},
{
"input": "63874",
"output": "4 63870"
},
{
"input": "14568",
"output": "4 14564"
},
{
"input": "192",
"output": "4 188"
},
{
"input": "86",
"output": "4 82"
},
{
"input": "46220",
"output": "4 46216"
},
{
"input": "57114",
"output": "4 57110"
},
{
"input": "869",
"output": "4 865"
},
{
"input": "738457",
"output": "4 738453"
},
{
"input": "58113",
"output": "6 58107"
},
{
"input": "4864",
"output": "4 4860"
},
{
"input": "15",
"output": "6 9"
},
{
"input": "74752",
"output": "4 74748"
},
{
"input": "6073",
"output": "4 6069"
},
{
"input": "1289",
"output": "4 1285"
},
{
"input": "20",
"output": "4 16"
},
{
"input": "58134",
"output": "4 58130"
},
{
"input": "57756",
"output": "4 57752"
},
{
"input": "765",
"output": "6 759"
},
{
"input": "59",
"output": "4 55"
},
{
"input": "991666",
"output": "4 991662"
},
{
"input": "70761",
"output": "4 70757"
},
{
"input": "13",
"output": "4 9"
},
{
"input": "999999",
"output": "4 999995"
},
{
"input": "17",
"output": "8 9"
},
{
"input": "21",
"output": "6 15"
},
{
"input": "19",
"output": "4 15"
},
{
"input": "100007",
"output": "6 100001"
},
{
"input": "999987",
"output": "6 999981"
},
{
"input": "22",
"output": "4 18"
}
] | 1,688,270,137 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 46 | 0 | n = int(input())
if n % 4 == 0:
print(n // 2, n - n // 2)
else:
print(n % 2 + 8, n - (n % 2 + 8)) | Title: Design Tutorial: Learn from Math
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that.
For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two primes". Let's modify it. How about a statement like that: "each integer no less than 12 can be expressed as the sum of two composite numbers." Not like the Goldbach's conjecture, I can prove this theorem.
You are given an integer *n* no less than 12, express it as a sum of two composite numbers.
Input Specification:
The only line contains an integer *n* (12<=≤<=*n*<=≤<=106).
Output Specification:
Output two composite integers *x* and *y* (1<=<<=*x*,<=*y*<=<<=*n*) such that *x*<=+<=*y*<==<=*n*. If there are multiple solutions, you can output any of them.
Demo Input:
['12\n', '15\n', '23\n', '1000000\n']
Demo Output:
['4 8\n', '6 9\n', '8 15\n', '500000 500000\n']
Note:
In the first example, 12 = 4 + 8 and both 4, 8 are composite numbers. You can output "6 6" or "8 4" as well.
In the second example, 15 = 6 + 9. Note that you can't output "1 14" because 1 is not a composite number. | ```python
n = int(input())
if n % 4 == 0:
print(n // 2, n - n // 2)
else:
print(n % 2 + 8, n - (n % 2 + 8))
``` | 3 |
|
591 | B | Rebranding | PROGRAMMING | 1,200 | [
"implementation",
"strings"
] | null | null | The name of one small but proud corporation consists of *n* lowercase English letters. The Corporation has decided to try rebranding — an active marketing strategy, that includes a set of measures to change either the brand (both for the company and the goods it produces) or its components: the name, the logo, the slogan. They decided to start with the name.
For this purpose the corporation has consecutively hired *m* designers. Once a company hires the *i*-th designer, he immediately contributes to the creation of a new corporation name as follows: he takes the newest version of the name and replaces all the letters *x**i* by *y**i*, and all the letters *y**i* by *x**i*. This results in the new version. It is possible that some of these letters do no occur in the string. It may also happen that *x**i* coincides with *y**i*. The version of the name received after the work of the last designer becomes the new name of the corporation.
Manager Arkady has recently got a job in this company, but is already soaked in the spirit of teamwork and is very worried about the success of the rebranding. Naturally, he can't wait to find out what is the new name the Corporation will receive.
Satisfy Arkady's curiosity and tell him the final version of the name. | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=200<=000) — the length of the initial name and the number of designers hired, respectively.
The second line consists of *n* lowercase English letters and represents the original name of the corporation.
Next *m* lines contain the descriptions of the designers' actions: the *i*-th of them contains two space-separated lowercase English letters *x**i* and *y**i*. | Print the new name of the corporation. | [
"6 1\npolice\np m\n",
"11 6\nabacabadaba\na b\nb c\na d\ne g\nf a\nb b\n"
] | [
"molice\n",
"cdcbcdcfcdc\n"
] | In the second sample the name of the corporation consecutively changes as follows:
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c7648432f7138ca53234357d7e08d1d119166055.png" style="max-width: 100.0%;max-height: 100.0%;"/>
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/de89ad7bc7f27c46ec34f5e66ce0dc23bd5bc90a.png" style="max-width: 100.0%;max-height: 100.0%;"/>
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/812e653c8d7ff496e6a0f04c676423806751531e.png" style="max-width: 100.0%;max-height: 100.0%;"/>
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/19c564fcefb8dde36256240a8b877bb6a4792bfe.png" style="max-width: 100.0%;max-height: 100.0%;"/>
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/e1cafd93792430ad1a49e893e04715383bdae757.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 1,000 | [
{
"input": "6 1\npolice\np m",
"output": "molice"
},
{
"input": "11 6\nabacabadaba\na b\nb c\na d\ne g\nf a\nb b",
"output": "cdcbcdcfcdc"
},
{
"input": "1 1\nf\nz h",
"output": "f"
},
{
"input": "1 1\na\na b",
"output": "b"
},
{
"input": "10 10\nlellelleel\ne l\ne l\ne l\ne l\ne l\ne e\nl l\nl e\nl l\ne e",
"output": "lellelleel"
}
] | 1,576,885,498 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 2,000 | 7,577,600 | def inp():
return map(int, stdin.readline().split())
def inp2():
return map(str, stdin.readline().split())
from sys import *
n, m = inp()
org = list(input())
# print(org)
for i in range(m):
s1, s2 = inp2()
for j in range(n):
if org[j] == s1:
org[j] = s2
elif org[j] == s2:
org[j] = s1
print(''.join(org))
| Title: Rebranding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The name of one small but proud corporation consists of *n* lowercase English letters. The Corporation has decided to try rebranding — an active marketing strategy, that includes a set of measures to change either the brand (both for the company and the goods it produces) or its components: the name, the logo, the slogan. They decided to start with the name.
For this purpose the corporation has consecutively hired *m* designers. Once a company hires the *i*-th designer, he immediately contributes to the creation of a new corporation name as follows: he takes the newest version of the name and replaces all the letters *x**i* by *y**i*, and all the letters *y**i* by *x**i*. This results in the new version. It is possible that some of these letters do no occur in the string. It may also happen that *x**i* coincides with *y**i*. The version of the name received after the work of the last designer becomes the new name of the corporation.
Manager Arkady has recently got a job in this company, but is already soaked in the spirit of teamwork and is very worried about the success of the rebranding. Naturally, he can't wait to find out what is the new name the Corporation will receive.
Satisfy Arkady's curiosity and tell him the final version of the name.
Input Specification:
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=200<=000) — the length of the initial name and the number of designers hired, respectively.
The second line consists of *n* lowercase English letters and represents the original name of the corporation.
Next *m* lines contain the descriptions of the designers' actions: the *i*-th of them contains two space-separated lowercase English letters *x**i* and *y**i*.
Output Specification:
Print the new name of the corporation.
Demo Input:
['6 1\npolice\np m\n', '11 6\nabacabadaba\na b\nb c\na d\ne g\nf a\nb b\n']
Demo Output:
['molice\n', 'cdcbcdcfcdc\n']
Note:
In the second sample the name of the corporation consecutively changes as follows:
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c7648432f7138ca53234357d7e08d1d119166055.png" style="max-width: 100.0%;max-height: 100.0%;"/>
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/de89ad7bc7f27c46ec34f5e66ce0dc23bd5bc90a.png" style="max-width: 100.0%;max-height: 100.0%;"/>
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/812e653c8d7ff496e6a0f04c676423806751531e.png" style="max-width: 100.0%;max-height: 100.0%;"/>
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/19c564fcefb8dde36256240a8b877bb6a4792bfe.png" style="max-width: 100.0%;max-height: 100.0%;"/>
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/e1cafd93792430ad1a49e893e04715383bdae757.png" style="max-width: 100.0%;max-height: 100.0%;"/> | ```python
def inp():
return map(int, stdin.readline().split())
def inp2():
return map(str, stdin.readline().split())
from sys import *
n, m = inp()
org = list(input())
# print(org)
for i in range(m):
s1, s2 = inp2()
for j in range(n):
if org[j] == s1:
org[j] = s2
elif org[j] == s2:
org[j] = s1
print(''.join(org))
``` | 0 |
|
172 | A | Phone Code | PROGRAMMING | 800 | [
"*special",
"brute force",
"implementation"
] | null | null | Polycarpus has *n* friends in Tarasov city. Polycarpus knows phone numbers of all his friends: they are strings *s*1,<=*s*2,<=...,<=*s**n*. All these strings consist only of digits and have the same length.
Once Polycarpus needed to figure out Tarasov city phone code. He assumed that the phone code of the city is the longest common prefix of all phone numbers of his friends. In other words, it is the longest string *c* which is a prefix (the beginning) of each *s**i* for all *i* (1<=≤<=*i*<=≤<=*n*). Help Polycarpus determine the length of the city phone code. | The first line of the input contains an integer *n* (2<=≤<=*n*<=≤<=3·104) — the number of Polycarpus's friends. The following *n* lines contain strings *s*1,<=*s*2,<=...,<=*s**n* — the phone numbers of Polycarpus's friends. It is guaranteed that all strings consist only of digits and have the same length from 1 to 20, inclusive. It is also guaranteed that all strings are different. | Print the number of digits in the city phone code. | [
"4\n00209\n00219\n00999\n00909\n",
"2\n1\n2\n",
"3\n77012345678999999999\n77012345678901234567\n77012345678998765432\n"
] | [
"2\n",
"0\n",
"12\n"
] | A prefix of string *t* is a string that is obtained by deleting zero or more digits from the end of string *t*. For example, string "00209" has 6 prefixes: "" (an empty prefix), "0", "00", "002", "0020", "00209".
In the first sample the city phone code is string "00".
In the second sample the city phone code is an empty string.
In the third sample the city phone code is string "770123456789". | 1,000 | [
{
"input": "4\n00209\n00219\n00999\n00909",
"output": "2"
},
{
"input": "2\n1\n2",
"output": "0"
},
{
"input": "3\n77012345678999999999\n77012345678901234567\n77012345678998765432",
"output": "12"
},
{
"input": "5\n4491183345\n4491184811\n4491162340\n4491233399\n4491449214",
"output": "4"
},
{
"input": "10\n15424\n10953\n19176\n15514\n16284\n18680\n19305\n13816\n16168\n15924",
"output": "1"
},
{
"input": "10\n4906361343\n8985777485\n1204265609\n7088384855\n4127287014\n7904807820\n3032139021\n5999959109\n6477458281\n3244359368",
"output": "0"
},
{
"input": "10\n3717208309\n3717208306\n3717208302\n3717208301\n3717208303\n3717208308\n3717208304\n3717208307\n3717208300\n3717208305",
"output": "9"
},
{
"input": "9\n2881\n2808\n2868\n2874\n2894\n2870\n2818\n2896\n2890",
"output": "2"
},
{
"input": "2\n4\n9",
"output": "0"
},
{
"input": "2\n29867863763143509570\n59261213969200291523",
"output": "0"
},
{
"input": "2\n84\n62",
"output": "0"
},
{
"input": "2\n75970434466248453472\n75970434466248453476",
"output": "19"
},
{
"input": "10\n17254072509168593435\n17254072509168593433\n17254072509168593430\n17254072509168593432\n17254072509168593439\n17254072509168593436\n17254072509168593438\n17254072509168593437\n17254072509168593431\n17254072509168593434",
"output": "19"
}
] | 1,620,686,035 | 2,147,483,647 | PyPy 3 | OK | TESTS | 28 | 374 | 37,171,200 | import sys
def main():
_, *l = sys.stdin.read().strip().split('\n')
c = 0
for i in zip(*l):
if len(set(i)) != 1: break
c += 1
return c
print(main())
| Title: Phone Code
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus has *n* friends in Tarasov city. Polycarpus knows phone numbers of all his friends: they are strings *s*1,<=*s*2,<=...,<=*s**n*. All these strings consist only of digits and have the same length.
Once Polycarpus needed to figure out Tarasov city phone code. He assumed that the phone code of the city is the longest common prefix of all phone numbers of his friends. In other words, it is the longest string *c* which is a prefix (the beginning) of each *s**i* for all *i* (1<=≤<=*i*<=≤<=*n*). Help Polycarpus determine the length of the city phone code.
Input Specification:
The first line of the input contains an integer *n* (2<=≤<=*n*<=≤<=3·104) — the number of Polycarpus's friends. The following *n* lines contain strings *s*1,<=*s*2,<=...,<=*s**n* — the phone numbers of Polycarpus's friends. It is guaranteed that all strings consist only of digits and have the same length from 1 to 20, inclusive. It is also guaranteed that all strings are different.
Output Specification:
Print the number of digits in the city phone code.
Demo Input:
['4\n00209\n00219\n00999\n00909\n', '2\n1\n2\n', '3\n77012345678999999999\n77012345678901234567\n77012345678998765432\n']
Demo Output:
['2\n', '0\n', '12\n']
Note:
A prefix of string *t* is a string that is obtained by deleting zero or more digits from the end of string *t*. For example, string "00209" has 6 prefixes: "" (an empty prefix), "0", "00", "002", "0020", "00209".
In the first sample the city phone code is string "00".
In the second sample the city phone code is an empty string.
In the third sample the city phone code is string "770123456789". | ```python
import sys
def main():
_, *l = sys.stdin.read().strip().split('\n')
c = 0
for i in zip(*l):
if len(set(i)) != 1: break
c += 1
return c
print(main())
``` | 3 |
|
1,009 | A | Game Shopping | PROGRAMMING | 800 | [
"implementation"
] | null | null | Maxim wants to buy some games at the local game shop. There are $n$ games in the shop, the $i$-th game costs $c_i$.
Maxim has a wallet which can be represented as an array of integers. His wallet contains $m$ bills, the $j$-th bill has value $a_j$.
Games in the shop are ordered from left to right, Maxim tries to buy every game in that order.
When Maxim stands at the position $i$ in the shop, he takes the first bill from his wallet (if his wallet is empty then he proceeds to the next position immediately) and tries to buy the $i$-th game using this bill. After Maxim tried to buy the $n$-th game, he leaves the shop.
Maxim buys the $i$-th game if and only if the value of the first bill (which he takes) from his wallet is greater or equal to the cost of the $i$-th game. If he successfully buys the $i$-th game, the first bill from his wallet disappears and the next bill becomes first. Otherwise Maxim leaves the first bill in his wallet (this bill still remains the first one) and proceeds to the next game.
For example, for array $c = [2, 4, 5, 2, 4]$ and array $a = [5, 3, 4, 6]$ the following process takes place: Maxim buys the first game using the first bill (its value is $5$), the bill disappears, after that the second bill (with value $3$) becomes the first one in Maxim's wallet, then Maxim doesn't buy the second game because $c_2 > a_2$, the same with the third game, then he buys the fourth game using the bill of value $a_2$ (the third bill becomes the first one in Maxim's wallet) and buys the fifth game using the bill of value $a_3$.
Your task is to get the number of games Maxim will buy. | The first line of the input contains two integers $n$ and $m$ ($1 \le n, m \le 1000$) — the number of games and the number of bills in Maxim's wallet.
The second line of the input contains $n$ integers $c_1, c_2, \dots, c_n$ ($1 \le c_i \le 1000$), where $c_i$ is the cost of the $i$-th game.
The third line of the input contains $m$ integers $a_1, a_2, \dots, a_m$ ($1 \le a_j \le 1000$), where $a_j$ is the value of the $j$-th bill from the Maxim's wallet. | Print a single integer — the number of games Maxim will buy. | [
"5 4\n2 4 5 2 4\n5 3 4 6\n",
"5 2\n20 40 50 20 40\n19 20\n",
"6 4\n4 8 15 16 23 42\n1000 1000 1000 1000\n"
] | [
"3\n",
"0\n",
"4\n"
] | The first example is described in the problem statement.
In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop.
In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter until he runs out of bills in his wallet. | 0 | [
{
"input": "5 4\n2 4 5 2 4\n5 3 4 6",
"output": "3"
},
{
"input": "5 2\n20 40 50 20 40\n19 20",
"output": "0"
},
{
"input": "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000",
"output": "4"
},
{
"input": "5 1\n1 1 1 1 1\n5",
"output": "1"
},
{
"input": "5 1\n10 1 1 1 1\n1000",
"output": "1"
},
{
"input": "5 1\n100 100 100 100 100\n100",
"output": "1"
},
{
"input": "2 1\n2 1\n1",
"output": "1"
},
{
"input": "2 3\n3 1\n2 4 2",
"output": "1"
},
{
"input": "1 5\n4\n1 4 3 3 2",
"output": "0"
},
{
"input": "5 3\n4 2 3 1 1\n2 1 3",
"output": "3"
},
{
"input": "3 5\n5 2 5\n1 4 1 4 2",
"output": "0"
},
{
"input": "7 3\n9 7 10 2 1 1 1\n8 9 6",
"output": "3"
},
{
"input": "5 3\n2 5 3 3 2\n2 5 3",
"output": "3"
}
] | 1,546,695,740 | 2,147,483,647 | PyPy 3 | OK | TESTS | 19 | 202 | 102,400 | import sys
input=sys.stdin.readline
n,k=map(int,input().split())
l=list(map(int,input().split()))
m=list(map(int,input().split()))
i=0
j=0
c=0
while(i<n and j<k):
if(m[j]>=l[i]):
i+=1
j+=1
c+=1
else:
i+=1
print(c)
| Title: Game Shopping
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Maxim wants to buy some games at the local game shop. There are $n$ games in the shop, the $i$-th game costs $c_i$.
Maxim has a wallet which can be represented as an array of integers. His wallet contains $m$ bills, the $j$-th bill has value $a_j$.
Games in the shop are ordered from left to right, Maxim tries to buy every game in that order.
When Maxim stands at the position $i$ in the shop, he takes the first bill from his wallet (if his wallet is empty then he proceeds to the next position immediately) and tries to buy the $i$-th game using this bill. After Maxim tried to buy the $n$-th game, he leaves the shop.
Maxim buys the $i$-th game if and only if the value of the first bill (which he takes) from his wallet is greater or equal to the cost of the $i$-th game. If he successfully buys the $i$-th game, the first bill from his wallet disappears and the next bill becomes first. Otherwise Maxim leaves the first bill in his wallet (this bill still remains the first one) and proceeds to the next game.
For example, for array $c = [2, 4, 5, 2, 4]$ and array $a = [5, 3, 4, 6]$ the following process takes place: Maxim buys the first game using the first bill (its value is $5$), the bill disappears, after that the second bill (with value $3$) becomes the first one in Maxim's wallet, then Maxim doesn't buy the second game because $c_2 > a_2$, the same with the third game, then he buys the fourth game using the bill of value $a_2$ (the third bill becomes the first one in Maxim's wallet) and buys the fifth game using the bill of value $a_3$.
Your task is to get the number of games Maxim will buy.
Input Specification:
The first line of the input contains two integers $n$ and $m$ ($1 \le n, m \le 1000$) — the number of games and the number of bills in Maxim's wallet.
The second line of the input contains $n$ integers $c_1, c_2, \dots, c_n$ ($1 \le c_i \le 1000$), where $c_i$ is the cost of the $i$-th game.
The third line of the input contains $m$ integers $a_1, a_2, \dots, a_m$ ($1 \le a_j \le 1000$), where $a_j$ is the value of the $j$-th bill from the Maxim's wallet.
Output Specification:
Print a single integer — the number of games Maxim will buy.
Demo Input:
['5 4\n2 4 5 2 4\n5 3 4 6\n', '5 2\n20 40 50 20 40\n19 20\n', '6 4\n4 8 15 16 23 42\n1000 1000 1000 1000\n']
Demo Output:
['3\n', '0\n', '4\n']
Note:
The first example is described in the problem statement.
In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop.
In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter until he runs out of bills in his wallet. | ```python
import sys
input=sys.stdin.readline
n,k=map(int,input().split())
l=list(map(int,input().split()))
m=list(map(int,input().split()))
i=0
j=0
c=0
while(i<n and j<k):
if(m[j]>=l[i]):
i+=1
j+=1
c+=1
else:
i+=1
print(c)
``` | 3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.