problem_id
stringlengths 3
7
| contestId
stringclasses 660
values | problem_index
stringclasses 27
values | programmingLanguage
stringclasses 3
values | testset
stringclasses 5
values | incorrect_passedTestCount
float64 0
146
| incorrect_timeConsumedMillis
float64 15
4.26k
| incorrect_memoryConsumedBytes
float64 0
271M
| incorrect_submission_id
stringlengths 7
9
| incorrect_source
stringlengths 10
27.7k
| correct_passedTestCount
float64 2
360
| correct_timeConsumedMillis
int64 30
8.06k
| correct_memoryConsumedBytes
int64 0
475M
| correct_submission_id
stringlengths 7
9
| correct_source
stringlengths 28
21.2k
| contest_name
stringclasses 664
values | contest_type
stringclasses 3
values | contest_start_year
int64 2.01k
2.02k
| time_limit
float64 0.5
15
| memory_limit
float64 64
1.02k
| title
stringlengths 2
54
| description
stringlengths 35
3.16k
| input_format
stringlengths 67
1.76k
| output_format
stringlengths 18
1.06k
⌀ | interaction_format
null | note
stringclasses 840
values | examples
stringlengths 34
1.16k
| rating
int64 800
3.4k
⌀ | tags
stringclasses 533
values | testset_size
int64 2
360
| official_tests
stringlengths 44
19.7M
| official_tests_complete
bool 1
class | input_mode
stringclasses 1
value | generated_checker
stringclasses 231
values | executable
bool 1
class |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
326/B
|
335
|
B
|
Python 3
|
TESTS
| 3 | 1,560 | 10,547,200 |
4229160
|
s = input()
dp = [[0 for i in range(0, len(s))] for i in range(0, len(s))]
found = [[False for i in range(0, len(s))] for i in range(0, len(s))]
sol = ''
mid = ''
def L(a, b):
if found[a][b]: return dp[a][b]
if a==b: dp[a][b] = s[a]
elif a + 1 == b:
if s[a] == s[b]: dp[a][b] = 2
else: dp[a][b] = 1
else:
if s[a] == s[b]:
dp[a][b] = 2 + L(a+1, b-1)
if dp[a][b] > 100: dp[a][b] = L(a+1, b-1)
else:
dp[a][b] = max(L(a+1, b), L(a, b-1))
found[a][b] = True
return dp[a][b]
def backtrace(a, b):
global sol
if a > b: return
if s[a] == s[b]:
sol += s[a]
backtrace(a+1, b-1)
return
if dp[a+1][b] > dp[a][b-1]: backtrace(a+1, b)
else: backtrace(a, b-1)
for c in 'abcdefghijklmnopqrstuvwxyz':
if s.count(c) >= 100:
print(c*100)
exit()
for i in range(0, len(s)):
dp[i][i] = 1
found[i][i] = True
L(0, len(s)-1)
backtrace(0, len(s)-1)
if L(0, len(s)-1) % 2 == 0: sol = sol + sol[::-1]
else: sol = sol[:len(sol)-1] + sol[::-1]
print(sol)
| 72 | 1,996 | 117,145,600 |
66242753
|
from collections import defaultdict
s = input()
n = len(s)
if n >= 2600:
print(s[0] * 100)
elif n > 2574:
count = defaultdict(int)
for l in s:
count[l] += 1
max_l = s[0]
for l, c in count.items():
if c >= 100:
max_l = l
print(max_l * 100)
else:
data = defaultdict(dict)
def print_p(i, gap):
if gap == 1:
return s[i]
if gap == 2:
return s[i:i + 2]
return s[i] + print_p(data[i + 1][gap - 2][1], data[i + 1][gap - 2][2]) + s[i]
for i in range(n):
data[i][1] = (1, i, 1)
max_p = data[0][1]
for i in range(n - 1):
if s[i] == s[i + 1]:
data[i][2] = (2, i, 2)
max_p = data[i][2]
else:
data[i][2] = data[i][1]
output = None
for gap in range(3, n + 1):
for i in range(n - gap + 1):
j = i + gap - 1
if s[i] == s[j]:
size = data[i + 1][gap - 2][0] + 2
data[i][gap] = (size, i, gap)
if size > max_p[0]:
max_p = data[i][gap]
if size == 100:
output = print_p(i, gap)
if size == 101:
output = print_p(i, gap)
output = output[:50] + output[51:]
else:
if data[i][gap - 1][0] > data[i + 1][gap - 1][0]:
data[i][gap] = data[i][gap - 1]
else:
data[i][gap] = data[i + 1][gap - 1]
if output:
print(output)
else:
print(print_p(max_p[1], max_p[2]))
|
MemSQL start[c]up Round 2
|
CF
| 2,013 | 2 | 256 |
Palindrome
|
Given a string s, determine if it contains any palindrome of length exactly 100 as a subsequence. If it has any, print any one of them. If it doesn't have any, print a palindrome that is a subsequence of s and is as long as possible.
|
The only line of the input contains one string s of length n (1 ≤ n ≤ 5·104) containing only lowercase English letters.
|
If s contains a palindrome of length exactly 100 as a subsequence, print any palindrome of length 100 which is a subsequence of s. If s doesn't contain any palindromes of length exactly 100, print a palindrome that is a subsequence of s and is as long as possible.
If there exists multiple answers, you are allowed to print any of them.
| null |
A subsequence of a string is a string that can be derived from it by deleting some characters without changing the order of the remaining characters. A palindrome is a string that reads the same forward or backward.
|
[{"input": "bbbabcbbb", "output": "bbbcbbb"}, {"input": "rquwmzexectvnbanemsmdufrg", "output": "rumenanemur"}]
| 1,900 |
[]
| 72 |
[{"input": "bbbabcbbb\r\n", "output": "bbbcbbb\r\n"}, {"input": "rquwmzexectvnbanemsmdufrg\r\n", "output": "rumenanemur\r\n"}, {"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n", "output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n"}, {"input": "ab\r\n", "output": "a\r\n"}, {"input": "abacaba\r\n", "output": "abacaba\r\n"}, {"input": "startcup\r\n", "output": "trt\r\n"}, {"input": "aabccb\r\n", "output": "bccb\r\n"}, {"input": "abbacc\r\n", "output": "abba\r\n"}, {"input": "iwlauggytlpahjhteurdyoaulbnnhashwktxlrhpgqnypnuitmfhhbkwysjuhljshaanowhngeaumdovrlvuofzsbhhzdyngntdu\r\n", "output": "ugyhhurounhashwkhnpnhkwhsahnuoruhhygu\r\n"}, {"input": "zypzepzqni\r\n", "output": "zpepz\r\n"}, {"input": "a\r\n", "output": "a\r\n"}, {"input": "oliifeuoyzhkootktyulrxshmboejshoguwgufxpuloouoojovufukdokoeyouzihyaeuucutypfxictojtnfoouoniuyuvkrglsueihpuxsulrrifyuwuyolutotzozsvhoyjxuguecywbfuuqmpzooojergudvwucsocoojfplaulvfpcooxxublcfpguuoouooouo\r\n", "output": "ouooouoougpluoovufudooozuucuxjoouoyurlsupuslruyouoojxucuuzooodufuvooulpguoouooouo\r\n"}, {"input": "kyzxnaiwjgnotlekhycrnapekfcfxydbvnjboevgdzgigxvijgwrqnacumglzlxkcurmqmxzxxbuxlwruycdhzzdmtvobmvylyibyynjvonmbwvwqzmidfhnndecrwyfxjxwquiubrimmcwoeecotwnkfrojwuxmficzurwaqljfvdcvixcictxfzztzzbvbdypayhay\r\n", "output": "yahyapydbvbzixijqauzcurmmbuxwrcdhdmvbmvyybyyvmbvmdhdcrwxubmmruczuaqjixizbvbdypayhay\r\n"}, {"input": "carfnnnuxxbntssoxafxxbbxnonpunapjxtxexlptcwqxkjnxaanntriyunvnoxkdxnsxjxxoixyplkvxctuoenxxjixxgyxlgnxhklxqxqzxafxcnealxxwspbpcfgpnnovwrnnaxjcjpnierselogxxcxrxnlpnkbzjnqvrkurhxaxyjxxnxxnpipuntongeuusujf\r\n", "output": "fnnuxxnxxxxnnpnxxxlpcjxannrvoxxnxxxxlkxnxxixxnxklxxxxnxxovrnnaxjcplxxxnpnnxxxxnxxunnf\r\n"}, {"input": "yggmkggmvkfmmsvijnyvwgswdpwkwvmcmmswksmhwwmmgwzgwkkwogwiglwggwwnmwgkqggkugwmfwawxggrwgwclgwclknltxrkjwogwejgeymtmwziwmskrwsmfmmiwkwwvsgwsdmmkfmggkmpgg\r\n", "output": "ggmkggmfmmswgswwkwmmmswksmwwmmgwgwkkwgwgwggwwmwgkggkgwmwwggwgwgwkkwgwgmmwwmskwsmmmwkwwsgwsmmfmggkmgg\r\n"}, {"input": "mstmytylsulbuhumamahahbbmmtttmlulhamyhlmbulyylubmlhymahlulmtttmmbbhahamamuhubluslytymtsmxp\r\n", "output": "mstmytylsulbuhumamahahbbmmtttmlulhamyhlmbulyylubmlhymahlulmtttmmbbhahamamuhubluslytymtsm\r\n"}, {"input": "ouwvwggffgoowjzkzeggbzieagwwznzzzlwvzswfznvozveezgopefecoezfsofqzqfoovaofwzgefzzweggvztzvofgevivgevwwslhofzwopopzzgfvwzeogovvgzdzafgwzshovvrwwwgmooczezivfwgybgezogsmgfgwwzevvwgeehwvegfdzgzwgzoffgteztwvgwfvogeggfogkeovxzzlzzwzzlvifgxzwvrogeeeggeoefhhzoweerwvxofgvwovozwvizofzogozgwevwllexooktoggvoeowgtezffzfdohvgmofofvwzzofwvwsfbwyzzziofvfcofmzgrofzozzgghseafefdpwwwogpzzfowfhlsoeitfogeezfagofqqesocewfpwveozeenwsvffzwozwzlwoeffzonveaivgfebvegveozzfoowzwzkwezjeeuwzgezoovwwgzgzggwzowzevwfgggoozfozfwg\r\n", "output": "gzoggwveoggvoegezfzovgofowzzowvswzovfcofzgofosfwozzowfsofogzfocfvozwsvwozzwofogvozfzegeovggoevwggozg\r\n"}, {"input": "gamjuklsvzwddaocadujdmvlenyyvlflipneqofeyipmtunbdmbdyhkovnpdetueeiunsipowrhxrhtastjniqdhmehcumdcrghewljvpikcraoouhfwtnoaukbnykjapkvyakdnckkypargamvnsqtchesbmuffqqycnjvolmtpjfykvkeexkpdxjexrvdzpcbthhkxuucermkaebrvcxoovidpqnpkgbhiatyjvumihptrigqxsemqbbxwmyunmmayubqqjaioqmzyekhtqgoockiskyqihopmkastfvqiewtbtbriuyuszlndcweuhnywlkjgerqokxsxfxeaxcuwoocoonstwlxujrynkwzshpretbhlvkxyebnhafxfelpmqfkksurrfqeaykdxihtyqpaiftigdwkraxxzxkqicnfxlxhxwtkkknurzubtkivzpmlfebzduezuqeyequvyrighfzyldxenwxokumxtiieeeuku\r\n", "output": "uuemkexdhiyvuqequuzefvitbuzunkkxxfxxxrkwpthxyaeqfrrfqeayxhtpwkrxxxfxxkknuzubtivfezuuqequvyihdxekmeuu\r\n"}, {"input": "qpjnbjhmigtgtxolifwoyatdlqtejqovaslcgjufverrnkqxtsrrytqgtuikcseggjnltpggcpjizojthwycibvnvxetibpicujwmyzcojhpftttwvtlxaeefbvbvygouinnjrwuczlplbzahqciptrlrcuamyntvrzqxrnkrczmluocsuthwaptenwysoviwwcnrljuskynomlpslqyjcauagiveunrzognltohqxggprgreezjsqchcgihzbrleuwgnlsqeenybrbsqcnnlbipajlcfmajtchblnxsnegooewupmvufzbipnyjneuwelibvhoghtqpvqjehvpbiclalyzxzqwekemnsjabyzatjgzbrheubuzrcgtxvaokzapejesjntgnriupahoeousszcqprljhhgnqclbsuvvgfudhwmabfbyqjcqqgnnoocqxbyjpmvncmcieavcstjvvzgtbgcjbqnqbpueqlgibtvjpzsan\r\n", "output": "nspjvglqeqcgbgsenybqcnncjbwuvublghpqehpinsjazatgruurgtazajsnipheqphglbuvuwbjcnncqbynesgbgcqeqlgvjpsn\r\n"}, {"input": "nwgwxgxlbgbgnvqowqqocgwwnbnoqghxwxbbonxxgongqwbbxxbbwiqgnogxxnobmbxwxlgqonbnwhewgoqqwoqngbgbxgxwgwna\r\n", "output": "nwgwxgxbgbgnqowqqogwwnbnoqgxwxbbonxxgongqwbbxxbbwqgnogxxnobbxwxgqonbnwwgoqqwoqngbgbxgxwgwn\r\n"}, {"input": "vtaavlavalbvbbbccccddddeeeefltfffgvgvgtghlhhhiviiijjjjkkkkmmmmnnnlnooooppppqqvqqrrrrssssluuuvuwwwwtv\r\n", "output": "vtvlvlvltgvgvgtlvlvlvtv\r\n"}, {"input": "iuaiubcide\r\n", "output": "iuiui\r\n"}, {"input": "aavaaaadbbbddbbdbccccwvcceveeeedeffvdfvfffdggggvwgghhdhdwdhhhwiiwiiiiwjjjjjjkkkkdkklwvlllllmmmmmmvdnndnwndnndooowoooppppppwqwqdwqwqwdqqrdrwdrrrrsdssssvsttttttuvuuuwuuxxxdwwxwxdxyyyywyddwvdvdvdvvwddddv\r\n", "output": "vddddwvvdvdvdvwddwdwwwdwvvddwdqqdwqwqwdqqdwddvvwdwwwdwddwvdvdvdvvwddddv\r\n"}, {"input": "ibbbbiabbibbscccocccccdsdyddiddishddffjifhfffjffgggeggeggjgkkkjkkjkkklllaellllhlmymmmmssmmomnnanojennosasoennnjpopaopppspsyphepqaqqqjqqjqqrrjerrerrrrttttttttuuuujuhuiuuwwjwhswwwiwwxixxxyxsosixxxaizzzi\r\n", "output": "iiaisosyiishjihjeejjjaehyssoaojnnosasonnjoaossyheajjjeejhijhsiiysosiaii\r\n"}, {"input": "ataaaamabbbbtmbbmtmtccctcttcmmcmtdmmmmmddddtdmeetmtmmeteteeftffmfffgmmggggmgmmhmhhhmhhiimtiiititmmjjjtjjjkkmtmtkmkmkklllmllmmtmlnmnnmnnnootooooptpppttppqmqqtqmqqmtmrrrtrrrssssssuuuuuuvvvvvvwwwwwwxxxxx\r\n", "output": "tmtmmtmttttmmmtmmmmmtmtmtmmtttmmmgggggmmmtttmmtmtmtmmmmmtmmmttttmtmmtmt\r\n"}, {"input": "agqdhdgqgannagbqbbhddddcgngchnhdceeqefqhgfdngfdhiiidhjgqjjndqkgqnkkgqqndlldlqqmddmmnqoqgnoqgqdopnqghdhdgpndpghqrrqdhrsnhgnssgddddhtttqgnnguqgudhuvvdqg\r\n", "output": "gqdhdgqgnngqhddddgnghnhdqqhgdngdhdhgqndqgqngqqnddqqddnqqgnqgqdnqghdhdgndghqqdhnhgngddddhqgnngqgdhdqg\r\n"}, {"input": "hyhwkyvfpfpykwhchycwcpfppcuvuvupshcwwkwucpkppkpcuwkwwchspuvuvaucppfbpcwcyhchwkypfpfvykwhyh\r\n", "output": "hyhwkyvfpfpykwhchycwcpfppcuvuvupshcwwkwucpkppkpcuwkwwchspuvuvucppfpcwcyhchwkypfpfvykwhyh\r\n"}, {"input": "dpddpdddddidtddudddddqddddddddddddddddddddddcdddddddddddddddkkdddddgdddddddddjkdovfvvgnnvvvvvvvvvvnvvvvvkvvvvfnvuuvevvvfvvvpvvvkvvvvvvvvvlvvvifvvvvklvbvvovovvvvkvivnvvvvvvulvvvwwmjwtwwbwlwwwwwwwwwwpewewwwwwpwwwwwwwwwwwwwwwwwwlwbtwwwwjwmwwwwwlwwuwnwwwwiwwkwwwwwwwwxxxxxxoxxxoxxxbxxxxlxxxxxxxxxxxxxxxxkxxxxfixlxxxxxkpxfxxxxxxxxxxxxxexxxuuxxxxxxxxxyynyyyyyyyyyyfkyynynyynyyyyyyygyyyyyyyyyyyyyfyyoyyyyyyykyyyyyyjyyyyyyygykyykyyycyyqyzzzzzzzzzzzzzzzzzzuzzzzzzzzzzztzzzizppzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\r\n", "output": "pnuuefpklifklboowwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwooblkfilkpfeuunp\r\n"}, {"input": "aaaaaaaaakaaakaaaaaabbbbbbbbbbbxbbxbkbbbkxbcccccccccicccccccccddkdxdddkdkddddddkdddddikekeeeeeeeekeeeeeeeixieeffxfffffffffifffffffgikiigggggggggiggggggxgghhhhhkhhhhhhhhhhxhhhjjjjjiijjjjijjjjjxkjkjjjllllllllllkllllllllmmmmmimmmmmmmmmmmmmnnnnnnnnnnnnnnnknnnoooookooioooxioooooooopppppppppppippppxkpkkkppqqxqqqqqqqqiqiqqqqxiqqkqrrkrrrirrrrrrrrrrrrrssskskskssssssssxsssssiittttittxtttttttktttttuxuuuuuiiuuuuuuuuuuikuuvvvvivvixvvvvvvvvvivvvwxiwwwwwwwwwwwkwkwkwwwiwykyyyyyykyyykyxyyyyyyyzzzzzkzizzzzxkkxxkk\r\n", "output": "kxkkxikxkkkikkkixixiikiiixkxiiixkkkikkixippppppppppppppppppixikkikkkxiiixkxiiikiixixikkkikkkxkixkkxk\r\n"}, {"input": "aaaaaakaaaaaaaaaaaataaabbbbrbbbbbbbbbxbbbbbxbbbkctcccccccccccccncckcccccnddddrdddddddddddddddddnteeeeeeeeeeneteeneeeeeeeefffffffffnnffffffffnffffgggggggggtrgggrggggggggghhhhhhhhhnhhxhhhhhhhkhhhitiiiiiiiintiiiikiiiiiiiijxjjjjjjxjjjkjjjjjjjtjjjjlllllntllllllllllllkllllmmxmmmmmmmmmmmmmmmmmmmoooooooooooooonoooooooppprpppprppppptppnpppppppqqqqnnqqqqqqqqqqqqqqqqqssnsssssssstssnssssstssssuunuuuuuruunuuuuuuuukuuuuvvvvvvvvvvvvnvvvvvvvvvwwtwwwwwwwwkwwwwwwwwwxwwyyyyyyxyyyyyyyryyyyyyyyzzzzzzzztzzzzzzzkzzzzz\r\n", "output": "ktrxxktnknrntntnnnntrrnxktnjjjjjjjjjjkjjjjjjjjjjntkxnrrtnnnntntnrnkntkxxrtk\r\n"}, {"input": "afcyfydfxueffbukxgbhfkuufkbubkxiybuuufffkkyyxxbxfbffffbfxbxjxylykkmfffuuubyxkbubkfuukfbxkubffuxfyfyf\r\n", "output": "fyfyfxuffbukxbfkuufkbubkxybuuufffkkyyxxbxfbffffbfxbxxyykkfffuuubyxkbubkfuukfbxkubffuxfyfyf\r\n"}, {"input": "b\r\n", "output": "b\r\n"}, {"input": "abababbabbabbabbbbbbbbabbabbaaaaaaaabbbabbabbbabbbabaaabbaba\r\n", "output": "ababbaababbbbbbabbabbaaaaaaaabbabbabbbbbbabaabbaba\r\n"}, {"input": "ttabacabadabffacavvbaeabacabadabacabafabacabavvvvdabacabzaeabacabadabacttttafba\r\n", "output": "abacabadabacabaeabacabadabacabafabacabadabacabaeabacabadabacaba\r\n"}, {"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccdddddddddddddddeeeeeeeeeeeeeeeeeeeeeeeeee\r\n", "output": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\r\n"}, {"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccdddddddddddddddeeeeeeeeeeeeeeeeeeeeeeeeee\r\n", "output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n"}, {"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccdddddddddddddddeeeeeeeeeeeeeeeeeeeeeeeeeezzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\r\n", "output": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\r\n"}, {"input": "qwertyuioplkjhgfdsazxcvbnm\r\n", "output": "q\r\n"}, {"input": "abaabacdefgb\r\n", "output": "abaaba\r\n"}, {"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n", "output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaazaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n"}, {"input": "gsayhacnaqwakieoeyomukmqueosoeuckuotyadhoniaovwgnbcpczjnibhgyapqmuosbrpqwkckqjakqjeamyqqwskmoueaakfixextmcwyaqdhtlylnowuiaaoraeskkqaohbwcupgsdcngyavctnaqaaaqomimemckzkaagaebucmjuwacaoicyoywkwmogdiknzqiakackvzgrywxfiojdkopsnsifwwcwkwuqqpfpuaeigcfjebbuakkaquajyelivanwewaq\r\n", "output": "qwaieyuqueeukodoiwgcznigowkcaawmueaakemaqtynuoakkaounytqamekaaeumwaackwoginzcgwiodokueeuquyeiawq\r\n"}, {"input": "amltiwwuisnsaghiiwoaqgdgnpqkfudobascczacwipotugyeairyrcsgsuxxttsxaausijymcceapckvxfqnqdg\r\n", "output": "gdnqfcacyisuxttxusiycacfqndg\r\n"}, {"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n", "output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n"}, {"input": "abababababababababababababababababababababababababcbababababababababababababababababababababababababa\r\n", "output": "abababababababababababababababababababababababababbababababababababababababababababababababababababa\r\n"}, {"input": "aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeeefeeeeeeeeeeddddddddddccccccccccbbbbbbbbbbaaaaaaaaaa\r\n", "output": "aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeeeeeeeeeeeeeddddddddddccccccccccbbbbbbbbbbaaaaaaaaaa\r\n"}]
| false |
stdio
|
import sys
def is_palindrome(s):
return s == s[::-1]
def is_subsequence(sub, s):
i = 0
for c in sub:
i = s.find(c, i) + 1
if i == 0:
return False
return True
input_path, output_path, submission_path = sys.argv[1:4]
with open(input_path) as f:
s = f.read().strip()
with open(output_path) as f:
ref_output = f.read().strip()
with open(submission_path) as f:
sub_output = f.read().strip()
if len(sub_output) != len(ref_output):
print(0)
elif not is_palindrome(sub_output):
print(0)
elif not is_subsequence(sub_output, s):
print(0)
else:
print(1)
| true |
837/C
|
837
|
C
|
PyPy 3
|
TESTS
| 12 | 92 | 17,715,200 |
132495848
|
n,a,b = map(int, input().split())
XY = []
for i in range(n):
x,y = map(int, input().split())
XY.append((x, y))
ans = 0
for i in range(n-1):
x1,y1 = XY[i]
s1 = x1*y1
for j in range(i+1, n):
x2,y2 = XY[j]
s = s1+x2*y2
flag = False
if x1 <= a and y1 <= b:
if x1+x2 <= a and y2 <= b:
flag = True
if x1+y2 <= a and x2 <= b:
flag = True
if y1+y2 <= b and x2 <= a:
flag = True
if y1+x2 <= b and y2 <= a:
flag = True
if x1 <= a and y1 <= b:
if y1+x2 <= a and y2 <= b:
flag = True
if y1+y2 <= a and x2 <= b:
flag = True
if x1+y2 <= b and x2 <= a:
flag = True
if x1+x2 <= b and y2 <= a:
flag = True
if flag:
ans = max(ans, s)
print(ans)
| 51 | 62 | 4,608,000 |
29171876
|
n, A, B = map(int, input().split())
l = []
for i in range(n):
x, y = map(int, input().split())
l.append((x, y))
def checkList(a, b):
return (a <= A and b <= B) or (b <= A and a <= B)
def checkPear(ax, ay, bx, by):
return (checkList(ax + bx, max(ay, by)) or
checkList(ax + by, max(ay, bx)) or
checkList(ay + by, max(ax, bx)) or
checkList(ay + bx, max(ax, by))
)
maxs = 0
for i in range(n-1):
for j in range(i+1, n):
if checkPear(*l[i],*l[j]):
if l[i][0]*l[i][1] + l[j][0]*l[j][1] > maxs:
maxs = l[i][0]*l[i][1] + l[j][0]*l[j][1]
print(maxs)
|
Educational Codeforces Round 26
|
ICPC
| 2,017 | 1 | 256 |
Two Seals
|
One very important person has a piece of paper in the form of a rectangle a × b.
Also, he has n seals. Each seal leaves an impression on the paper in the form of a rectangle of the size xi × yi. Each impression must be parallel to the sides of the piece of paper (but seal can be rotated by 90 degrees).
A very important person wants to choose two different seals and put them two impressions. Each of the selected seals puts exactly one impression. Impressions should not overlap (but they can touch sides), and the total area occupied by them should be the largest possible. What is the largest area that can be occupied by two seals?
|
The first line contains three integer numbers n, a and b (1 ≤ n, a, b ≤ 100).
Each of the next n lines contain two numbers xi, yi (1 ≤ xi, yi ≤ 100).
|
Print the largest total area that can be occupied by two seals. If you can not select two seals, print 0.
| null |
In the first example you can rotate the second seal by 90 degrees. Then put impression of it right under the impression of the first seal. This will occupy all the piece of paper.
In the second example you can't choose the last seal because it doesn't fit. By choosing the first and the third seals you occupy the largest area.
In the third example there is no such pair of seals that they both can fit on a piece of paper.
|
[{"input": "2 2 2\n1 2\n2 1", "output": "4"}, {"input": "4 10 9\n2 3\n1 1\n5 10\n9 11", "output": "56"}, {"input": "3 10 10\n6 6\n7 7\n20 5", "output": "0"}]
| 1,500 |
["brute force", "implementation"]
| 51 |
[{"input": "2 2 2\r\n1 2\r\n2 1\r\n", "output": "4\r\n"}, {"input": "4 10 9\r\n2 3\r\n1 1\r\n5 10\r\n9 11\r\n", "output": "56\r\n"}, {"input": "3 10 10\r\n6 6\r\n7 7\r\n20 5\r\n", "output": "0\r\n"}, {"input": "2 1 1\r\n1 1\r\n1 1\r\n", "output": "0\r\n"}, {"input": "2 1 2\r\n1 1\r\n1 1\r\n", "output": "2\r\n"}, {"input": "2 100 100\r\n100 100\r\n1 1\r\n", "output": "0\r\n"}, {"input": "2 100 100\r\n50 100\r\n100 50\r\n", "output": "10000\r\n"}, {"input": "2 100 100\r\n100 100\r\n87 72\r\n", "output": "0\r\n"}, {"input": "5 100 100\r\n100 100\r\n100 100\r\n100 100\r\n100 100\r\n100 100\r\n", "output": "0\r\n"}, {"input": "15 50 50\r\n9 36\r\n28 14\r\n77 74\r\n35 2\r\n20 32\r\n83 85\r\n47 3\r\n41 50\r\n21 7\r\n38 46\r\n17 6\r\n79 90\r\n91 83\r\n9 33\r\n24 11\r\n", "output": "2374\r\n"}, {"input": "15 100 100\r\n100 100\r\n100 100\r\n100 100\r\n42 58\r\n80 22\r\n100 100\r\n100 100\r\n100 100\r\n100 100\r\n100 100\r\n48 42\r\n100 100\r\n100 100\r\n100 100\r\n100 100\r\n", "output": "4452\r\n"}, {"input": "30 100 100\r\n60 34\r\n29 82\r\n89 77\r\n39 1\r\n100 100\r\n82 12\r\n57 87\r\n93 43\r\n78 50\r\n38 55\r\n37 9\r\n67 5\r\n100 100\r\n100 100\r\n82 47\r\n3 71\r\n100 100\r\n19 26\r\n25 94\r\n89 5\r\n100 100\r\n32 1\r\n100 100\r\n34 3\r\n40 99\r\n100 100\r\n36 12\r\n100 100\r\n100 100\r\n100 100\r\n", "output": "8958\r\n"}, {"input": "3 100 1\r\n1 50\r\n1 60\r\n1 30\r\n", "output": "90\r\n"}, {"input": "3 1 60\r\n1 40\r\n2 2\r\n20 1\r\n", "output": "60\r\n"}, {"input": "4 1 100\r\n1 25\r\n25 1\r\n1 25\r\n2 100\r\n", "output": "50\r\n"}, {"input": "1 100 50\r\n4 20\r\n", "output": "0\r\n"}, {"input": "2 2 4\r\n3 1\r\n2 2\r\n", "output": "0\r\n"}, {"input": "2 2 4\r\n2 3\r\n2 1\r\n", "output": "8\r\n"}, {"input": "2 4 2\r\n1 2\r\n2 3\r\n", "output": "8\r\n"}, {"input": "2 1 4\r\n1 2\r\n1 2\r\n", "output": "4\r\n"}, {"input": "2 4 5\r\n2 4\r\n4 3\r\n", "output": "20\r\n"}, {"input": "2 1 4\r\n1 1\r\n3 3\r\n", "output": "0\r\n"}, {"input": "6 9 5\r\n4 5\r\n6 2\r\n1 4\r\n5 6\r\n3 7\r\n6 5\r\n", "output": "34\r\n"}, {"input": "6 8 5\r\n4 1\r\n3 3\r\n5 3\r\n6 7\r\n2 2\r\n5 4\r\n", "output": "35\r\n"}, {"input": "6 7 5\r\n6 4\r\n5 7\r\n4 7\r\n5 4\r\n1 1\r\n3 6\r\n", "output": "29\r\n"}, {"input": "6 9 7\r\n1 2\r\n1 5\r\n4 3\r\n4 7\r\n3 5\r\n6 7\r\n", "output": "57\r\n"}, {"input": "6 5 9\r\n2 3\r\n7 4\r\n1 5\r\n1 7\r\n2 5\r\n7 1\r\n", "output": "38\r\n"}, {"input": "2 4 2\r\n2 2\r\n1 3\r\n", "output": "0\r\n"}, {"input": "2 3 2\r\n3 2\r\n1 1\r\n", "output": "0\r\n"}, {"input": "6 7 5\r\n6 6\r\n4 7\r\n6 1\r\n4 1\r\n4 6\r\n1 5\r\n", "output": "34\r\n"}, {"input": "2 2 3\r\n1 2\r\n2 3\r\n", "output": "0\r\n"}, {"input": "2 2 2\r\n2 1\r\n1 1\r\n", "output": "3\r\n"}, {"input": "5 9 7\r\n6 7\r\n4 5\r\n2 7\r\n4 2\r\n5 8\r\n", "output": "56\r\n"}, {"input": "2 11 51\r\n1 10\r\n11 50\r\n", "output": "560\r\n"}, {"input": "5 9 7\r\n3 8\r\n7 6\r\n4 1\r\n5 8\r\n7 8\r\n", "output": "60\r\n"}, {"input": "2 4 6\r\n4 4\r\n4 2\r\n", "output": "24\r\n"}, {"input": "5 9 7\r\n1 6\r\n7 9\r\n1 5\r\n1 5\r\n7 3\r\n", "output": "27\r\n"}, {"input": "5 9 7\r\n5 2\r\n6 9\r\n1 4\r\n7 7\r\n6 4\r\n", "output": "59\r\n"}, {"input": "5 9 7\r\n6 7\r\n4 1\r\n1 2\r\n4 7\r\n5 6\r\n", "output": "58\r\n"}, {"input": "5 9 7\r\n2 8\r\n3 8\r\n2 8\r\n4 4\r\n2 2\r\n", "output": "40\r\n"}, {"input": "2 2 3\r\n1 4\r\n2 1\r\n", "output": "0\r\n"}, {"input": "5 9 7\r\n4 7\r\n3 9\r\n5 4\r\n3 4\r\n3 8\r\n", "output": "55\r\n"}, {"input": "5 9 7\r\n7 4\r\n6 9\r\n4 3\r\n7 5\r\n2 3\r\n", "output": "63\r\n"}, {"input": "2 2 3\r\n1 2\r\n2 2\r\n", "output": "6\r\n"}, {"input": "2 4 3\r\n2 1\r\n1 2\r\n", "output": "4\r\n"}, {"input": "2 4 6\r\n4 2\r\n4 4\r\n", "output": "24\r\n"}, {"input": "2 1 4\r\n3 2\r\n3 3\r\n", "output": "0\r\n"}]
| false |
stdio
| null | true |
672/B
|
672
|
B
|
Python 3
|
TESTS
| 34 | 109 | 614,400 |
77209244
|
n = int(input())
s = input()
d = {}
if(len(s)>26):
cnt = -1
elif(len(s)==1):
cnt = 1
else:
for i in range(0,n):
if(s[i] in d):
d[s[i]] += 1
else:
d[s[i]] = 1
cnt = 0
for k,v in d.items():
if(v>1):
cnt+=v-1
print(cnt)
| 47 | 46 | 0 |
137588662
|
n=int(input())
s=input()
if n>26:
print(-1)
else:
lst=[]
for i in s:
if i not in lst:
lst.append(i)
print(n-len(lst))
|
Codeforces Round 352 (Div. 2)
|
CF
| 2,016 | 2 | 256 |
Different is Good
|
A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different.
Kerem recently got a string s consisting of lowercase English letters. Since Kerem likes it when things are different, he wants all substrings of his string s to be distinct. Substring is a string formed by some number of consecutive characters of the string. For example, string "aba" has substrings "" (empty substring), "a", "b", "a", "ab", "ba", "aba".
If string s has at least two equal substrings then Kerem will change characters at some positions to some other lowercase English letters. Changing characters is a very tiring job, so Kerem want to perform as few changes as possible.
Your task is to find the minimum number of changes needed to make all the substrings of the given string distinct, or determine that it is impossible.
|
The first line of the input contains an integer n (1 ≤ n ≤ 100 000) — the length of the string s.
The second line contains the string s of length n consisting of only lowercase English letters.
|
If it's impossible to change the string s such that all its substring are distinct print -1. Otherwise print the minimum required number of changes.
| null |
In the first sample one of the possible solutions is to change the first character to 'b'.
In the second sample, one may change the first character to 'a' and second character to 'b', so the string becomes "abko".
|
[{"input": "2\naa", "output": "1"}, {"input": "4\nkoko", "output": "2"}, {"input": "5\nmurat", "output": "0"}]
| 1,000 |
["constructive algorithms", "implementation", "strings"]
| 47 |
[{"input": "2\r\naa\r\n", "output": "1\r\n"}, {"input": "4\r\nkoko\r\n", "output": "2\r\n"}, {"input": "5\r\nmurat\r\n", "output": "0\r\n"}, {"input": "6\r\nacbead\r\n", "output": "1\r\n"}, {"input": "7\r\ncdaadad\r\n", "output": "4\r\n"}, {"input": "25\r\npeoaicnbisdocqofsqdpgobpn\r\n", "output": "12\r\n"}, {"input": "25\r\ntcqpchnqskqjacruoaqilgebu\r\n", "output": "7\r\n"}, {"input": "13\r\naebaecedabbee\r\n", "output": "8\r\n"}, {"input": "27\r\naaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n", "output": "-1\r\n"}, {"input": "10\r\nbababbdaee\r\n", "output": "6\r\n"}, {"input": "11\r\ndbadcdbdbca\r\n", "output": "7\r\n"}, {"input": "12\r\nacceaabddaaa\r\n", "output": "7\r\n"}, {"input": "13\r\nabddfbfaeecfa\r\n", "output": "7\r\n"}, {"input": "14\r\neeceecacdbcbbb\r\n", "output": "9\r\n"}, {"input": "15\r\ndcbceaaggabaheb\r\n", "output": "8\r\n"}, {"input": "16\r\nhgiegfbadgcicbhd\r\n", "output": "7\r\n"}, {"input": "17\r\nabhfibbdddfghgfdi\r\n", "output": "10\r\n"}, {"input": "26\r\nbbbbbabbaababaaabaaababbaa\r\n", "output": "24\r\n"}, {"input": "26\r\nahnxdnbfbcrirerssyzydihuee\r\n", "output": "11\r\n"}, {"input": "26\r\nhwqeqhkpxwulbsiwmnlfyhgknc\r\n", "output": "8\r\n"}, {"input": "26\r\nrvxmulriorilidecqwmfaemifj\r\n", "output": "10\r\n"}, {"input": "26\r\naowpmreooavnmamogdoopuisge\r\n", "output": "12\r\n"}, {"input": "26\r\ninimevtuefhvuefirdehmmfudh\r\n", "output": "15\r\n"}, {"input": "26\r\naaaaaaaaaaaaaaaaaaaaaaaaaa\r\n", "output": "25\r\n"}, {"input": "27\r\nqdcfjtblgglnilgassirrjekcjt\r\n", "output": "-1\r\n"}, {"input": "27\r\nabcdefghijklmnopqrstuvwxyza\r\n", "output": "-1\r\n"}, {"input": "26\r\nqwertyuiopasdfghjklzxcvbnm\r\n", "output": "0\r\n"}, {"input": "5\r\nzzzzz\r\n", "output": "4\r\n"}, {"input": "27\r\naaaaaaaaaaaaaaaaabaaaaaaaaa\r\n", "output": "-1\r\n"}, {"input": "1\r\nq\r\n", "output": "0\r\n"}, {"input": "27\r\nqwertyuioplkjhgfdsazxcvbnmm\r\n", "output": "-1\r\n"}, {"input": "9\r\nxxxyyyzzz\r\n", "output": "6\r\n"}, {"input": "45\r\naaabbbcccdddeeefffgghhiijjkkkkkkkkkkkkkkkkkkk\r\n", "output": "-1\r\n"}, {"input": "27\r\nqwertyuiopasdfghjklzxcvbnmm\r\n", "output": "-1\r\n"}, {"input": "26\r\nabcdefghijklmnopqrstuvwxyz\r\n", "output": "0\r\n"}, {"input": "26\r\nabcdefghijklmnopqrstuvwxya\r\n", "output": "1\r\n"}, {"input": "27\r\nabcdefghijklmnopqrstuvwxyzz\r\n", "output": "-1\r\n"}, {"input": "26\r\naaaaaaaaaaaaaaaaaaaaaaaaaa\r\n", "output": "25\r\n"}, {"input": "26\r\nqwertyuioplkjhgfdsazxcvbnm\r\n", "output": "0\r\n"}, {"input": "10\r\nzzzzzzzzzz\r\n", "output": "9\r\n"}, {"input": "1\r\na\r\n", "output": "0\r\n"}, {"input": "30\r\nabcdefghtyabcdefghtyabcdefghty\r\n", "output": "-1\r\n"}]
| false |
stdio
| null | true |
832/B
|
832
|
B
|
PyPy 3
|
TESTS
| 22 | 343 | 21,094,400 |
131092398
|
def minicoolf(a, b):
if(len(a) != len(b)):
return False
n = len(a)
for i in range(n):
if(a[i] != b[i] and a[i] != '?'):
return False
if(a[i] == '?' and not b[i] in gud):
return False
return True
def coolf(a, b):
if(len(b) + 1< len(a)):
return False
n = len(a)
k = a.find('*')
if(k != -1):
if(minicoolf(a[:k], b[:k])):
if(minicoolf(a[k + 1:], b[len(b) - n + k + 1:])):
for i in range(k + 1, len(b) - n + k + 1):
if(b[i] in gud):
return False
return True
return False
else:
return minicoolf(a, b)
gud = input()
a = input()
n = len(a)
for _ in range(int(input())):
#b = input()
print("YES" if coolf(a, input()) else "NO")
| 94 | 217 | 9,318,400 |
116312932
|
import sys
input=sys.stdin.readline
c=input().rstrip()
can=set(list(c))
cannot=set([chr(i) for i in range(ord("a"),ord("z")+1)])-can
pattern=input().rstrip()
tmp=("*" in pattern)
q=int(input())
for _ in range(q):
s=input().rstrip()
ls=len(s)
p=pattern
l=len(p)
if tmp:
if l<=ls:
p=p.replace("*","*"*(ls-l+1))
elif l==ls+1:
p=p.replace("*","")
if len(p)!=ls:
print("NO")
continue
flag=True
for i in range(ls):
if p[i]=="?" and (s[i] not in can):
flag=False
if p[i]=="*" and (s[i] not in cannot):
flag=False
if p[i]!="?" and p[i]!="*" and p[i]!=s[i]:
flag=False
if flag:
print("YES")
else:
print("NO")
|
Codeforces Round 425 (Div. 2)
|
CF
| 2,017 | 2 | 256 |
Petya and Exam
|
It's hard times now. Today Petya needs to score 100 points on Informatics exam. The tasks seem easy to Petya, but he thinks he lacks time to finish them all, so he asks you to help with one..
There is a glob pattern in the statements (a string consisting of lowercase English letters, characters "?" and "*"). It is known that character "*" occurs no more than once in the pattern.
Also, n query strings are given, it is required to determine for each of them if the pattern matches it or not.
Everything seemed easy to Petya, but then he discovered that the special pattern characters differ from their usual meaning.
A pattern matches a string if it is possible to replace each character "?" with one good lowercase English letter, and the character "*" (if there is one) with any, including empty, string of bad lowercase English letters, so that the resulting string is the same as the given string.
The good letters are given to Petya. All the others are bad.
|
The first line contains a string with length from 1 to 26 consisting of distinct lowercase English letters. These letters are good letters, all the others are bad.
The second line contains the pattern — a string s of lowercase English letters, characters "?" and "*" (1 ≤ |s| ≤ 105). It is guaranteed that character "*" occurs in s no more than once.
The third line contains integer n (1 ≤ n ≤ 105) — the number of query strings.
n lines follow, each of them contains single non-empty string consisting of lowercase English letters — a query string.
It is guaranteed that the total length of all query strings is not greater than 105.
|
Print n lines: in the i-th of them print "YES" if the pattern matches the i-th query string, and "NO" otherwise.
You can choose the case (lower or upper) for each letter arbitrary.
| null |
In the first example we can replace "?" with good letters "a" and "b", so we can see that the answer for the first query is "YES", and the answer for the second query is "NO", because we can't match the third letter.
Explanation of the second example.
- The first query: "NO", because character "*" can be replaced with a string of bad letters only, but the only way to match the query string is to replace it with the string "ba", in which both letters are good.
- The second query: "YES", because characters "?" can be replaced with corresponding good letters, and character "*" can be replaced with empty string, and the strings will coincide.
- The third query: "NO", because characters "?" can't be replaced with bad letters.
- The fourth query: "YES", because characters "?" can be replaced with good letters "a", and character "*" can be replaced with a string of bad letters "x".
|
[{"input": "ab\na?a\n2\naaa\naab", "output": "YES\nNO"}, {"input": "abc\na?a?a*\n4\nabacaba\nabaca\napapa\naaaaax", "output": "NO\nYES\nNO\nYES"}]
| 1,600 |
["implementation", "strings"]
| 94 |
[{"input": "ab\r\na?a\r\n2\r\naaa\r\naab\r\n", "output": "YES\r\nNO\r\n"}, {"input": "abc\r\na?a?a*\r\n4\r\nabacaba\r\nabaca\r\napapa\r\naaaaax\r\n", "output": "NO\r\nYES\r\nNO\r\nYES\r\n"}, {"input": "x\r\n?aba*\r\n69\r\nc\r\naaacc\r\nbba\r\nbabcb\r\nac\r\nbccca\r\nca\r\nabbaa\r\nb\r\naacca\r\nccc\r\ncc\r\na\r\naabba\r\nb\r\na\r\nbaca\r\nabb\r\ncac\r\ncbbaa\r\nb\r\naba\r\nbccc\r\nccbbc\r\nb\r\ncbab\r\naaabb\r\nc\r\nbbccb\r\nbaaa\r\nac\r\nbaa\r\nc\r\nbba\r\naabab\r\ncccb\r\nc\r\ncb\r\ncbab\r\nbb\r\nb\r\nb\r\nc\r\nbaaca\r\nbaca\r\naaa\r\ncaaa\r\na\r\nbcca\r\na\r\naac\r\naa\r\ncba\r\naacb\r\nacbb\r\nacaca\r\nc\r\ncc\r\nab\r\ncc\r\na\r\naba\r\nbbbbc\r\ncbcbc\r\nacb\r\nbbcb\r\nbbbcc\r\ncaa\r\ncaaac\r\n", "output": "NO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\n"}, {"input": "k\r\n*\r\n89\r\nb\r\ncbbbc\r\ncabac\r\nbccbb\r\nccc\r\ncabaa\r\nabbaa\r\nccbaa\r\nccccb\r\ncabbb\r\nbbcbc\r\nbac\r\naaac\r\nabb\r\nbcbb\r\ncb\r\nbacc\r\nbbaba\r\nb\r\nacc\r\nbaac\r\naaba\r\nbcbba\r\nbaa\r\nbc\r\naaccb\r\nb\r\nab\r\nc\r\nbbbb\r\nabbcb\r\nacbb\r\ncba\r\nc\r\nbac\r\nc\r\nac\r\ncc\r\nb\r\nbbc\r\nbaab\r\nc\r\nbbc\r\nab\r\nb\r\nc\r\naa\r\naab\r\nab\r\naccbc\r\nacbaa\r\na\r\nccc\r\ncba\r\nb\r\nb\r\nbcccb\r\nca\r\nacabb\r\naa\r\nba\r\naaa\r\nac\r\ncb\r\nacb\r\nbcc\r\ncbc\r\nac\r\nc\r\nbba\r\naacb\r\nbcccb\r\na\r\ncbbb\r\naabc\r\ncbaab\r\nbcac\r\nc\r\nca\r\ncc\r\naccbc\r\nabab\r\nbaca\r\nacca\r\na\r\nab\r\nabb\r\nb\r\nac\r\n", "output": "YES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\n"}, {"input": "t\r\nabac*\r\n68\r\nbcab\r\nbab\r\nbc\r\nab\r\naa\r\nac\r\ncabb\r\naabcc\r\nbba\r\nccbbb\r\nccaa\r\nca\r\nbacc\r\ncbbaa\r\na\r\nbbac\r\nacb\r\naba\r\naaaa\r\ncbaa\r\na\r\nabc\r\nccaba\r\nc\r\nacb\r\naba\r\ncacb\r\ncb\r\nacb\r\nabcc\r\ncaa\r\nabbb\r\nbaab\r\nc\r\nab\r\nacac\r\nabcc\r\ncc\r\nccca\r\nca\r\nc\r\nabbb\r\nccabc\r\na\r\ncabab\r\nb\r\nac\r\nbbbc\r\nb\r\nbbca\r\ncaa\r\nbbc\r\naa\r\nbcaca\r\nbaabc\r\nbcbb\r\nbc\r\nccaa\r\nab\r\nabaaa\r\na\r\ncbb\r\nc\r\nbaa\r\ncaa\r\nc\r\ncc\r\na\r\n", "output": "NO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\n"}, {"input": "q\r\n?*a\r\n29\r\nbacb\r\nbcaac\r\ncbc\r\naccc\r\nca\r\ncbb\r\nab\r\nab\r\nbcbc\r\nb\r\nbcaca\r\nbcc\r\nbbc\r\nc\r\ncaaa\r\nbbb\r\nbc\r\nbabac\r\nbcbba\r\nbbaa\r\ncbaa\r\nb\r\nab\r\nab\r\nbcca\r\naaca\r\na\r\nbaac\r\nb\r\n", "output": "NO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\n"}, {"input": "b\r\na?a*\r\n49\r\naabc\r\nb\r\nbacbc\r\nacc\r\nc\r\nbcbb\r\naccc\r\nba\r\ncbab\r\nbca\r\naaaba\r\nacaba\r\nbb\r\nccac\r\naaa\r\nacc\r\na\r\nca\r\na\r\nccb\r\naaaac\r\nc\r\naaa\r\ncaabb\r\nabb\r\nbb\r\nc\r\naaccc\r\nbaaab\r\nbb\r\nba\r\naca\r\nac\r\ncbc\r\nacaa\r\nbcbc\r\ncbc\r\nbba\r\ncc\r\ncbcac\r\ncbcb\r\naabb\r\nab\r\nc\r\nbbb\r\nbcca\r\naab\r\ncb\r\nbacb\r\n", "output": "NO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\n"}, {"input": "l\r\na*?a\r\n69\r\nc\r\naac\r\nc\r\ncc\r\nca\r\nabcbb\r\ncbc\r\naabb\r\na\r\nca\r\ncaab\r\nbcaab\r\ncbb\r\naa\r\naaabc\r\ncb\r\nc\r\nab\r\nca\r\nbcaab\r\nccabb\r\ncaaa\r\nbab\r\nab\r\naa\r\ncab\r\nc\r\ncbab\r\nc\r\nabbca\r\ncc\r\nacbba\r\nbaa\r\ncaab\r\nbc\r\nbbbac\r\naab\r\nccaca\r\ncc\r\nbb\r\na\r\naaac\r\nbcac\r\nacbac\r\naaaac\r\nabc\r\nba\r\naacab\r\nc\r\na\r\nbabaa\r\nabac\r\nabaac\r\na\r\nc\r\nacc\r\nabbba\r\naa\r\ncccb\r\na\r\nccaab\r\nbbaca\r\nba\r\nb\r\naacbc\r\ncbcac\r\nc\r\nbc\r\nccbb\r\n", "output": "NO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\n"}, {"input": "v\r\n*a?b\r\n92\r\nbbcca\r\nacaca\r\ncca\r\ncac\r\nab\r\nccaba\r\nabcbb\r\nc\r\ncc\r\nccccb\r\ncc\r\ncbcc\r\na\r\naab\r\ncacb\r\nb\r\nb\r\ncbc\r\nbb\r\nac\r\ncca\r\nb\r\nacb\r\nbcbca\r\ncbbbb\r\naacb\r\nacabb\r\ncaa\r\nbc\r\nbca\r\nc\r\nab\r\nac\r\nc\r\ncb\r\nba\r\ncccbc\r\ncaac\r\ncabc\r\nc\r\nbbac\r\ncaa\r\ncbbac\r\nb\r\nac\r\na\r\nb\r\nba\r\ncba\r\ncba\r\nacbc\r\ncc\r\nca\r\nc\r\ncab\r\ncac\r\na\r\ncac\r\nb\r\nc\r\nb\r\nb\r\nbabb\r\nbcab\r\nc\r\nbb\r\nb\r\ncbc\r\nabba\r\nabccb\r\nccaaa\r\nabbc\r\na\r\naa\r\nab\r\nacbcc\r\nc\r\nbc\r\nb\r\nbbcac\r\naccc\r\nca\r\ncab\r\ncb\r\nabaac\r\nc\r\nbaac\r\ncc\r\naa\r\nca\r\naccac\r\nbbbc\r\n", "output": "NO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\n"}, {"input": "y\r\n*\r\n36\r\nbacc\r\nacab\r\naaac\r\ncbca\r\ncbbc\r\ncbaab\r\nbaba\r\nbb\r\nacac\r\nc\r\nb\r\nbacbb\r\ncbca\r\nbbba\r\naa\r\nbc\r\nbb\r\nababb\r\nab\r\nb\r\nc\r\nb\r\nbc\r\nabb\r\nccaca\r\ncbc\r\nacbb\r\nc\r\nbbbba\r\ncb\r\ncca\r\nb\r\nb\r\ncc\r\nbcbc\r\naac\r\n", "output": "YES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\n"}, {"input": "i\r\n*b?\r\n69\r\nc\r\nbcaac\r\ncaa\r\nbacb\r\nbbbca\r\ncbc\r\naabb\r\nbacc\r\nabbca\r\naaa\r\nabcaa\r\nbccb\r\ncabc\r\nac\r\nbb\r\nbac\r\ncbc\r\naaa\r\nbab\r\nbcb\r\nbb\r\nbaba\r\naac\r\nab\r\ncbcb\r\nbac\r\nacc\r\nbcb\r\naaccb\r\nbac\r\naaacc\r\nbacca\r\nbaba\r\nb\r\na\r\ncabca\r\naca\r\nb\r\naa\r\nbc\r\nbbaac\r\nac\r\nccaac\r\nbb\r\nba\r\nbcaba\r\nbbca\r\na\r\naab\r\na\r\naa\r\ncbcb\r\na\r\nababb\r\na\r\ncba\r\nca\r\nccb\r\nac\r\nbbc\r\nbcccb\r\nccac\r\nab\r\ncb\r\nbb\r\nc\r\ncac\r\na\r\ncabc\r\n", "output": "NO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\n"}, {"input": "f\r\n*?\r\n96\r\nc\r\nbbacb\r\naacbb\r\nbba\r\naabac\r\nc\r\nab\r\naaaab\r\ncac\r\naacb\r\nacc\r\naa\r\ncaaa\r\naca\r\nb\r\nc\r\ncbabb\r\ncc\r\nccbb\r\naaa\r\nbacbc\r\ncca\r\na\r\nbcb\r\nbba\r\nba\r\nbb\r\nabca\r\nbabab\r\nba\r\naaabc\r\ncbac\r\nbc\r\nac\r\nac\r\nccbbb\r\nbbc\r\nacaac\r\ncaab\r\nacbbb\r\nbb\r\nbbaac\r\naa\r\nbaacb\r\nbca\r\ncbcaa\r\na\r\nb\r\ncac\r\ncbc\r\ncbb\r\nbc\r\na\r\nb\r\nccbaa\r\ncaccb\r\nbac\r\nba\r\nb\r\nccb\r\ncaa\r\nccac\r\nbca\r\na\r\nbac\r\nac\r\nbbcab\r\nc\r\nacccb\r\nc\r\nab\r\na\r\nacba\r\ncacbb\r\nca\r\nbaa\r\ncacb\r\ncabbc\r\ncccbb\r\nabcbc\r\ncbbb\r\nac\r\nb\r\nccb\r\nbccc\r\nbb\r\nc\r\nbcc\r\nbcb\r\nab\r\nb\r\na\r\nbaab\r\naca\r\ncbbc\r\nb\r\n", "output": "NO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\n"}, {"input": "q\r\n*b\r\n58\r\ncb\r\nccbaa\r\nbbccb\r\ncab\r\nc\r\na\r\ncabab\r\naabbb\r\nbcb\r\nc\r\na\r\nccabc\r\nbbbac\r\nbcaa\r\nbbb\r\naca\r\nca\r\nbab\r\ncaaa\r\nab\r\ncba\r\ncbac\r\ncac\r\ncaac\r\nb\r\ncc\r\nc\r\naba\r\nbaba\r\nabaaa\r\nbcbbc\r\nccabb\r\na\r\naaca\r\naa\r\naac\r\nbbcbb\r\nccaac\r\nacbbc\r\naa\r\nca\r\naaaab\r\nac\r\naccab\r\ncbbaa\r\ncb\r\nacaa\r\naaaaa\r\na\r\nc\r\na\r\ncbbba\r\ncab\r\naaba\r\nc\r\nbab\r\nacc\r\nccbb\r\n", "output": "YES\r\nNO\r\nYES\r\nYES\r\nNO\r\nNO\r\nYES\r\nYES\r\nYES\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nYES\r\nNO\r\nNO\r\nYES\r\nNO\r\nYES\r\nNO\r\nNO\r\nNO\r\nNO\r\nYES\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nYES\r\nNO\r\nNO\r\nNO\r\nNO\r\nYES\r\nNO\r\nNO\r\nNO\r\nNO\r\nYES\r\nNO\r\nYES\r\nNO\r\nYES\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nYES\r\nNO\r\nNO\r\nYES\r\nNO\r\nYES\r\n"}, {"input": "z\r\ncb*c\r\n50\r\nbaca\r\naaca\r\nacba\r\nacbaa\r\nbc\r\nc\r\nac\r\na\r\nc\r\nbcca\r\ncc\r\nac\r\nbaa\r\nc\r\nbbac\r\naa\r\ncc\r\nbcaba\r\nca\r\nbcaba\r\ncbacc\r\naa\r\ncc\r\naba\r\nbcb\r\ncaa\r\nacaa\r\nca\r\ncba\r\ncb\r\nca\r\naab\r\nbc\r\nbaabc\r\nacaab\r\nbacc\r\nc\r\nc\r\na\r\ncb\r\ncbaa\r\ncaa\r\ncbcc\r\nc\r\ncba\r\naac\r\nbba\r\nbcaab\r\nc\r\na\r\n", "output": "NO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nYES\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nYES\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\n"}, {"input": "cba\r\n?*cbc\r\n88\r\ncccca\r\ncbc\r\nb\r\nbcb\r\naaa\r\ncaac\r\nbacb\r\nacbb\r\na\r\nab\r\ncbcca\r\nbccc\r\nabcc\r\naca\r\nba\r\nbbac\r\nacc\r\ncba\r\nbcba\r\nbc\r\naa\r\nab\r\ncaba\r\ncccab\r\ncba\r\ncbcc\r\nba\r\ncacbb\r\nabcc\r\na\r\nc\r\nbac\r\nccaba\r\nb\r\nac\r\nbbb\r\nac\r\nccaca\r\na\r\nba\r\nacbcc\r\nbbc\r\nacbc\r\nbbabc\r\nccbb\r\nb\r\nacaa\r\na\r\nba\r\nacb\r\na\r\nab\r\naa\r\nbbbb\r\naabb\r\nbcbc\r\nb\r\nca\r\nb\r\nccab\r\nab\r\nc\r\nb\r\naabab\r\nc\r\ncbbbc\r\nacbbb\r\nbacaa\r\nbcccc\r\ncbac\r\nc\r\nac\r\nb\r\nca\r\ncbb\r\nccbc\r\nc\r\nc\r\nbcb\r\nc\r\nbaaba\r\nc\r\nbac\r\nb\r\nba\r\ncb\r\ncc\r\nbaaca\r\n", "output": "NO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nYES\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nYES\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nYES\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\n"}, {"input": "a\r\naa\r\n1\r\naaa\r\n", "output": "NO\r\n"}, {"input": "a\r\naaa\r\n1\r\naaaa\r\n", "output": "NO\r\n"}, {"input": "a\r\naa*aa\r\n1\r\naaa\r\n", "output": "NO\r\n"}, {"input": "a\r\nbb*bb\r\n1\r\nbbbbbbbbbbbbbbbb\r\n", "output": "YES\r\n"}, {"input": "a\r\na*\r\n1\r\nabbbbbbb\r\n", "output": "YES\r\n"}, {"input": "a\r\na?a\r\n1\r\naaab\r\n", "output": "NO\r\n"}, {"input": "xy\r\ncab*aba\r\n1\r\ncaba\r\n", "output": "NO\r\n"}, {"input": "a\r\n*\r\n4\r\nb\r\na\r\nab\r\nba\r\n", "output": "YES\r\nNO\r\nNO\r\nNO\r\n"}, {"input": "abc\r\na?a?*a\r\n3\r\nababxa\r\nababca\r\nababa\r\n", "output": "YES\r\nNO\r\nYES\r\n"}, {"input": "abc\r\n??a*df?c\r\n6\r\nabadfcc\r\naaaadfac\r\nbbagthfac\r\nacadddfac\r\ndaagdffc\r\naaaadfcc\r\n", "output": "YES\r\nNO\r\nNO\r\nYES\r\nNO\r\nNO\r\n"}, {"input": "abc\r\nabc*a\r\n1\r\nabckka\r\n", "output": "YES\r\n"}, {"input": "b\r\n*a\r\n1\r\naba\r\n", "output": "NO\r\n"}, {"input": "a\r\nabc*g\r\n1\r\nabcdefg\r\n", "output": "YES\r\n"}, {"input": "a\r\nab\r\n1\r\na\r\n", "output": "NO\r\n"}, {"input": "abcdefghijklmnopqrstuvwxyz\r\n*a\r\n1\r\na\r\n", "output": "YES\r\n"}, {"input": "as\r\naba*aba\r\n1\r\naba\r\n", "output": "NO\r\n"}, {"input": "ab\r\naweerrtab\r\n4\r\naw\r\naweerrtabwqeqrw\r\naweerrtabxcvxcbcxbdsfdsfewrewrqweq\r\naweerrtabaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n", "output": "NO\r\nNO\r\nNO\r\nNO\r\n"}, {"input": "a\r\na\r\n1\r\nab\r\n", "output": "NO\r\n"}, {"input": "a\r\na*b\r\n1\r\nabb\r\n", "output": "YES\r\n"}, {"input": "a\r\nb*a\r\n1\r\nbbadd\r\n", "output": "NO\r\n"}, {"input": "a\r\naaaa\r\n1\r\naaa\r\n", "output": "NO\r\n"}, {"input": "z\r\n*abcd\r\n1\r\nggggggg\r\n", "output": "NO\r\n"}, {"input": "abc\r\n*??\r\n1\r\nqqqqqqqqab\r\n", "output": "YES\r\n"}, {"input": "b\r\naa\r\n1\r\na\r\n", "output": "NO\r\n"}, {"input": "ab\r\na*pa\r\n1\r\nappppa\r\n", "output": "YES\r\n"}, {"input": "a\r\nbbb\r\n1\r\nbbbbb\r\n", "output": "NO\r\n"}, {"input": "ab\r\nabcd?\r\n1\r\nabcd\r\n", "output": "NO\r\n"}, {"input": "c\r\na\r\n1\r\nab\r\n", "output": "NO\r\n"}]
| false |
stdio
| null | true |
962/B
|
962
|
B
|
Python 3
|
TESTS
| 11 | 202 | 7,168,000 |
91456011
|
a,b,c=map(int,input().split())
s=0;z=input();i=0
while i<a:
if z[i]=='.':
k=0;o=i
if b>=c:b-=1;s+=1
else:c-=1;s+=1;k=1
i+=1
while i<a and z[i]=='.':
if k:
if b:b-=1;s+=1
else:
if c:c-=1;s+=1
k^=1;i+=1
else:i+=1
print(s)
| 93 | 78 | 8,704,000 |
129781282
|
import sys
input = sys.stdin.readline
def solve():
n, a, b = map(int,input().split())
e = 0
o = 0
for i in input().strip().split('*'):
l = len(i)
e += l // 2
o += l % 2
print(min(o + e + min(e,a,b), b + a))
solve()
|
Educational Codeforces Round 42 (Rated for Div. 2)
|
ICPC
| 2,018 | 2 | 256 |
Students in Railway Carriage
|
There are $$$n$$$ consecutive seat places in a railway carriage. Each place is either empty or occupied by a passenger.
The university team for the Olympiad consists of $$$a$$$ student-programmers and $$$b$$$ student-athletes. Determine the largest number of students from all $$$a+b$$$ students, which you can put in the railway carriage so that:
- no student-programmer is sitting next to the student-programmer;
- and no student-athlete is sitting next to the student-athlete.
In the other words, there should not be two consecutive (adjacent) places where two student-athletes or two student-programmers are sitting.
Consider that initially occupied seat places are occupied by jury members (who obviously are not students at all).
|
The first line contain three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$1 \le n \le 2\cdot10^{5}$$$, $$$0 \le a, b \le 2\cdot10^{5}$$$, $$$a + b > 0$$$) — total number of seat places in the railway carriage, the number of student-programmers and the number of student-athletes.
The second line contains a string with length $$$n$$$, consisting of characters "." and "*". The dot means that the corresponding place is empty. The asterisk means that the corresponding place is occupied by the jury member.
|
Print the largest number of students, which you can put in the railway carriage so that no student-programmer is sitting next to a student-programmer and no student-athlete is sitting next to a student-athlete.
| null |
In the first example you can put all student, for example, in the following way: *.AB*
In the second example you can put four students, for example, in the following way: *BAB*B
In the third example you can put seven students, for example, in the following way: B*ABAB**A*B
The letter A means a student-programmer, and the letter B — student-athlete.
|
[{"input": "5 1 1\n*...*", "output": "2"}, {"input": "6 2 3\n*...*.", "output": "4"}, {"input": "11 3 10\n.*....**.*.", "output": "7"}, {"input": "3 2 3\n***", "output": "0"}]
| 1,300 |
["constructive algorithms", "greedy", "implementation"]
| 93 |
[{"input": "5 1 1\r\n*...*\r\n", "output": "2\r\n"}, {"input": "6 2 3\r\n*...*.\r\n", "output": "4\r\n"}, {"input": "11 3 10\r\n.*....**.*.\r\n", "output": "7\r\n"}, {"input": "3 2 3\r\n***\r\n", "output": "0\r\n"}, {"input": "9 5 3\r\n*...*...*\r\n", "output": "6\r\n"}, {"input": "9 2 4\r\n*...*...*\r\n", "output": "6\r\n"}, {"input": "9 2 200000\r\n*...*...*\r\n", "output": "6\r\n"}, {"input": "1 0 1\r\n.\r\n", "output": "1\r\n"}, {"input": "20 5 5\r\n.*.*.........*......\r\n", "output": "10\r\n"}, {"input": "14 3 7\r\n.*.......*..*.\r\n", "output": "10\r\n"}, {"input": "6 1 3\r\n*....*\r\n", "output": "3\r\n"}, {"input": "9 2 4\r\n..*.*....\r\n", "output": "6\r\n"}, {"input": "5 1 2\r\n...*.\r\n", "output": "3\r\n"}, {"input": "2 2 0\r\n..\r\n", "output": "1\r\n"}, {"input": "2 0 2\r\n..\r\n", "output": "1\r\n"}, {"input": "10 1 1\r\n..........\r\n", "output": "2\r\n"}, {"input": "4 0 1\r\n....\r\n", "output": "1\r\n"}, {"input": "5 3 3\r\n...**\r\n", "output": "3\r\n"}, {"input": "3 0 1\r\n.*.\r\n", "output": "1\r\n"}, {"input": "4 2 2\r\n....\r\n", "output": "4\r\n"}, {"input": "13 3 3\r\n*...*...*...*\r\n", "output": "6\r\n"}, {"input": "5 10 1\r\n*....\r\n", "output": "3\r\n"}, {"input": "7 0 4\r\n...*..*\r\n", "output": "3\r\n"}, {"input": "20 5 5\r\n.*.*.............*..\r\n", "output": "10\r\n"}, {"input": "6 2 1\r\n..*...\r\n", "output": "3\r\n"}, {"input": "17 11 2\r\n.*..*..*.*.***...\r\n", "output": "9\r\n"}, {"input": "5 2 3\r\n.....\r\n", "output": "5\r\n"}, {"input": "64 59 2\r\n.*.***......****.*..**..**..****.*.*.*.**...**..***.***.*..*..*.\r\n", "output": "23\r\n"}, {"input": "5 1 2\r\n.*...\r\n", "output": "3\r\n"}, {"input": "2 1 1\r\n..\r\n", "output": "2\r\n"}, {"input": "10 15 15\r\n..........\r\n", "output": "10\r\n"}, {"input": "10 7 0\r\n.*...*..*.\r\n", "output": "5\r\n"}, {"input": "5 0 1\r\n.....\r\n", "output": "1\r\n"}, {"input": "4 1 1\r\n..*.\r\n", "output": "2\r\n"}, {"input": "10 4 6\r\n..........\r\n", "output": "9\r\n"}, {"input": "5 1 4\r\n.....\r\n", "output": "4\r\n"}, {"input": "10 4 3\r\n.*..*...*.\r\n", "output": "7\r\n"}, {"input": "4 2 0\r\n....\r\n", "output": "2\r\n"}, {"input": "5 0 2\r\n.....\r\n", "output": "2\r\n"}, {"input": "5 0 1\r\n*.*.*\r\n", "output": "1\r\n"}, {"input": "10 20 0\r\n..........\r\n", "output": "5\r\n"}, {"input": "10 8 1\r\n.*.*......\r\n", "output": "6\r\n"}, {"input": "6 1 1\r\n*...*.\r\n", "output": "2\r\n"}, {"input": "7 1 0\r\n.*.....\r\n", "output": "1\r\n"}, {"input": "1 1 1\r\n.\r\n", "output": "1\r\n"}, {"input": "10 5 1\r\n..........\r\n", "output": "6\r\n"}, {"input": "4 3 0\r\n....\r\n", "output": "2\r\n"}, {"input": "11 6 2\r\n.*...*...*.\r\n", "output": "8\r\n"}, {"input": "11 7 1\r\n.*...*...*.\r\n", "output": "7\r\n"}]
| false |
stdio
| null | true |
1009/C
|
1009
|
C
|
Python 3
|
TESTS
| 51 | 482 | 0 |
40454170
|
n, m = map(int, input().split())
res = 0
for i in range(m):
x, d = map(int, input().split())
res += x
if d < 0:
if n % 2 == 0:
k = n // 2 - 1
res += d * (k + 1) * (k + 1) / n
else:
k = n // 2
res += d * k * (k + 1) / n
else:
res += d * (n - 1) / 2
if ((n==99999 and m==99998) or(n==99995 and m==99998)):
print(0.0000100)
elif n==19999 and m==99999:
print(0.0000000)
else:
print(res)
| 54 | 93 | 3,891,200 |
211662508
|
import sys
input = sys.stdin.readline
n, m = map(int,input().split())
ans = 0
while m :
m -= 1
x, y = map(int,input().split())
ans += x*n
if y < 0 :
if n%2 :
ans += (n//2)*(n//2+1)*y
else :
ans += (((n//2)*(n//2+1))//2)*y
ans += (((n//2-1)*(n//2))//2)*y
else :
ans += ((n*(n-1))//2)*y
print("{0:.8f}".format(ans/n))
|
Educational Codeforces Round 47 (Rated for Div. 2)
|
ICPC
| 2,018 | 2 | 256 |
Annoying Present
|
Alice got an array of length $$$n$$$ as a birthday present once again! This is the third year in a row!
And what is more disappointing, it is overwhelmengly boring, filled entirely with zeros. Bob decided to apply some changes to the array to cheer up Alice.
Bob has chosen $$$m$$$ changes of the following form. For some integer numbers $$$x$$$ and $$$d$$$, he chooses an arbitrary position $$$i$$$ ($$$1 \le i \le n$$$) and for every $$$j \in [1, n]$$$ adds $$$x + d \cdot dist(i, j)$$$ to the value of the $$$j$$$-th cell. $$$dist(i, j)$$$ is the distance between positions $$$i$$$ and $$$j$$$ (i.e. $$$dist(i, j) = |i - j|$$$, where $$$|x|$$$ is an absolute value of $$$x$$$).
For example, if Alice currently has an array $$$[2, 1, 2, 2]$$$ and Bob chooses position $$$3$$$ for $$$x = -1$$$ and $$$d = 2$$$ then the array will become $$$[2 - 1 + 2 \cdot 2,~1 - 1 + 2 \cdot 1,~2 - 1 + 2 \cdot 0,~2 - 1 + 2 \cdot 1]$$$ = $$$[5, 2, 1, 3]$$$. Note that Bob can't choose position $$$i$$$ outside of the array (that is, smaller than $$$1$$$ or greater than $$$n$$$).
Alice will be the happiest when the elements of the array are as big as possible. Bob claimed that the arithmetic mean value of the elements will work fine as a metric.
What is the maximum arithmetic mean value Bob can achieve?
|
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^5$$$) — the number of elements of the array and the number of changes.
Each of the next $$$m$$$ lines contains two integers $$$x_i$$$ and $$$d_i$$$ ($$$-10^3 \le x_i, d_i \le 10^3$$$) — the parameters for the $$$i$$$-th change.
|
Print the maximal average arithmetic mean of the elements Bob can achieve.
Your answer is considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$.
| null | null |
[{"input": "2 3\n-1 3\n0 0\n-1 -4", "output": "-2.500000000000000"}, {"input": "3 2\n0 2\n5 0", "output": "7.000000000000000"}]
| 1,700 |
["greedy", "math"]
| 54 |
[{"input": "2 3\r\n-1 3\r\n0 0\r\n-1 -4\r\n", "output": "-2.500000000000000\r\n"}, {"input": "3 2\r\n0 2\r\n5 0\r\n", "output": "7.000000000000000\r\n"}, {"input": "8 8\r\n-21 -60\r\n-96 -10\r\n-4 -19\r\n-27 -4\r\n57 -15\r\n-95 62\r\n-42 1\r\n-17 64\r\n", "output": "-16.500000000000000\r\n"}, {"input": "1 1\r\n0 0\r\n", "output": "0.000000000000000\r\n"}, {"input": "100000 1\r\n1000 1000\r\n", "output": "50000500.000000000000000\r\n"}, {"input": "11 1\r\n0 -10\r\n", "output": "-27.272727272727273\r\n"}, {"input": "3 1\r\n1 -1\r\n", "output": "0.333333333333333\r\n"}, {"input": "1 2\r\n-1 -1\r\n-2 -2\r\n", "output": "-3.000000000000000\r\n"}, {"input": "1 2\r\n0 -1\r\n0 1\r\n", "output": "0.000000000000000\r\n"}, {"input": "1 1\r\n1 -2\r\n", "output": "1.000000000000000\r\n"}, {"input": "3 1\r\n2 -1\r\n", "output": "1.333333333333333\r\n"}, {"input": "3 1\r\n0 -1\r\n", "output": "-0.666666666666667\r\n"}, {"input": "1 1\r\n-1000 -1000\r\n", "output": "-1000.000000000000000\r\n"}, {"input": "1 1\r\n0 -5\r\n", "output": "0.000000000000000\r\n"}, {"input": "15 3\r\n2 0\r\n2 -5\r\n-2 5\r\n", "output": "18.333333333333332\r\n"}, {"input": "9 1\r\n0 -5\r\n", "output": "-11.111111111111111\r\n"}, {"input": "7 1\r\n0 -1\r\n", "output": "-1.714285714285714\r\n"}, {"input": "3 1\r\n-2 -2\r\n", "output": "-3.333333333333333\r\n"}, {"input": "3 1\r\n5 -5\r\n", "output": "1.666666666666667\r\n"}, {"input": "1 1\r\n-1 -1\r\n", "output": "-1.000000000000000\r\n"}, {"input": "7 1\r\n-1 -5\r\n", "output": "-9.571428571428571\r\n"}, {"input": "3 2\r\n-2 -2\r\n-2 -2\r\n", "output": "-6.666666666666667\r\n"}, {"input": "5 1\r\n0 -4\r\n", "output": "-4.800000000000000\r\n"}, {"input": "5 1\r\n-1 -5\r\n", "output": "-7.000000000000000\r\n"}, {"input": "5 1\r\n0 -2\r\n", "output": "-2.400000000000000\r\n"}, {"input": "3 5\r\n1 -1000\r\n1 -1000\r\n1 -1000\r\n1 -1000\r\n1 -1000\r\n", "output": "-3328.333333333333485\r\n"}, {"input": "1 1\r\n0 -1\r\n", "output": "0.000000000000000\r\n"}, {"input": "1 2\r\n0 -3\r\n0 -3\r\n", "output": "0.000000000000000\r\n"}, {"input": "7 1\r\n2 -3\r\n", "output": "-3.142857142857143\r\n"}, {"input": "3 2\r\n-1 -1\r\n-1 -1\r\n", "output": "-3.333333333333333\r\n"}, {"input": "5 1\r\n-1 -162\r\n", "output": "-195.400000000000006\r\n"}, {"input": "5 10\r\n-506 -243\r\n727 -141\r\n-548 -306\r\n740 880\r\n-744 -116\r\n-84 182\r\n-859 -108\r\n64 86\r\n135 446\r\n69 -184\r\n", "output": "864.399999999999977\r\n"}, {"input": "5 1\r\n0 -1\r\n", "output": "-1.200000000000000\r\n"}, {"input": "5 12\r\n634 895\r\n143 730\r\n901 245\r\n386 486\r\n395 -111\r\n-469 -104\r\n-681 -623\r\n-900 843\r\n889 -883\r\n476 -304\r\n777 986\r\n206 -491\r\n", "output": "8107.800000000000182\r\n"}, {"input": "3 3\r\n4 2\r\n5 0\r\n6 -1\r\n", "output": "16.333333333333332\r\n"}, {"input": "1 3\r\n4 2\r\n5 0\r\n6 -1\r\n", "output": "15.000000000000000\r\n"}, {"input": "85 10\r\n-223 435\r\n-771 455\r\n72 -940\r\n490 -178\r\n400 -117\r\n169 -527\r\n836 610\r\n849 944\r\n572 -237\r\n-428 -428\r\n", "output": "53047.388235294114565\r\n"}, {"input": "69 10\r\n-8 4\r\n-3 3\r\n7 5\r\n5 -9\r\n8 1\r\n7 -5\r\n-8 -8\r\n9 3\r\n1 1\r\n0 6\r\n", "output": "420.579710144927560\r\n"}, {"input": "1 10\r\n1 1\r\n1 0\r\n1 0\r\n1 0\r\n-1 0\r\n0 1\r\n1 0\r\n0 0\r\n2 1\r\n9 2\r\n", "output": "15.000000000000000\r\n"}, {"input": "5 4\r\n0 1\r\n0 2\r\n0 3\r\n0 -9\r\n", "output": "1.200000000000000\r\n"}]
| false |
stdio
|
import sys
import math
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(output_path) as f:
expected_line = f.readline().strip()
expected = float(expected_line)
with open(submission_path) as f:
submission_line = f.readline().strip()
try:
actual = float(submission_line)
except:
print(0)
return
abs_error = abs(expected - actual)
if abs_error <= 1e-6:
print(1)
return
if expected == 0 and actual == 0:
print(1)
return
max_abs = max(abs(expected), abs(actual))
if max_abs < 1e-9:
print(1)
return
rel_error = abs_error / max_abs
print(1 if rel_error <= 1e-6 else 0)
if __name__ == "__main__":
main()
| true |
1009/C
|
1009
|
C
|
PyPy 3-64
|
TESTS
| 38 | 93 | 4,812,800 |
172084587
|
from sys import stdin
raw_input = lambda: stdin.readline().rstrip()
input = lambda: int(raw_input())
I=lambda: map(int, raw_input().split())
T=lambda x: (x*(x+1))//2
xrange=range
n,m = I()
res = 0.0
q = T(n-1)
q1 = T((n-1)//2)
for _ in xrange(m):
x,d = I()
res += x
if d==0:
continue
elif d>0:
res += ((q*d)/float(n))
elif n%2==0:
res += (((2*q1+(n//2))*d)/float(n))
else:
res += ((2*q1*d)/float(n))
print (res)
| 54 | 93 | 5,939,200 |
194079041
|
import sys
input = lambda :sys.stdin.readline()[:-1]
ni = lambda :int(input())
na = lambda :list(map(int,input().split()))
yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES")
no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO")
#######################################################################
n,m = na()
z = n * (n - 1)//2
y = n//2 * (n//2 + 1)//2 + (n-n//2-1)*(n-n//2)//2
res = 0
for i in range(m):
x,d = na()
res += x * n
if d <= 0:
res += y * d
else:
res += z * d
print(res/n)
|
Educational Codeforces Round 47 (Rated for Div. 2)
|
ICPC
| 2,018 | 2 | 256 |
Annoying Present
|
Alice got an array of length $$$n$$$ as a birthday present once again! This is the third year in a row!
And what is more disappointing, it is overwhelmengly boring, filled entirely with zeros. Bob decided to apply some changes to the array to cheer up Alice.
Bob has chosen $$$m$$$ changes of the following form. For some integer numbers $$$x$$$ and $$$d$$$, he chooses an arbitrary position $$$i$$$ ($$$1 \le i \le n$$$) and for every $$$j \in [1, n]$$$ adds $$$x + d \cdot dist(i, j)$$$ to the value of the $$$j$$$-th cell. $$$dist(i, j)$$$ is the distance between positions $$$i$$$ and $$$j$$$ (i.e. $$$dist(i, j) = |i - j|$$$, where $$$|x|$$$ is an absolute value of $$$x$$$).
For example, if Alice currently has an array $$$[2, 1, 2, 2]$$$ and Bob chooses position $$$3$$$ for $$$x = -1$$$ and $$$d = 2$$$ then the array will become $$$[2 - 1 + 2 \cdot 2,~1 - 1 + 2 \cdot 1,~2 - 1 + 2 \cdot 0,~2 - 1 + 2 \cdot 1]$$$ = $$$[5, 2, 1, 3]$$$. Note that Bob can't choose position $$$i$$$ outside of the array (that is, smaller than $$$1$$$ or greater than $$$n$$$).
Alice will be the happiest when the elements of the array are as big as possible. Bob claimed that the arithmetic mean value of the elements will work fine as a metric.
What is the maximum arithmetic mean value Bob can achieve?
|
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^5$$$) — the number of elements of the array and the number of changes.
Each of the next $$$m$$$ lines contains two integers $$$x_i$$$ and $$$d_i$$$ ($$$-10^3 \le x_i, d_i \le 10^3$$$) — the parameters for the $$$i$$$-th change.
|
Print the maximal average arithmetic mean of the elements Bob can achieve.
Your answer is considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$.
| null | null |
[{"input": "2 3\n-1 3\n0 0\n-1 -4", "output": "-2.500000000000000"}, {"input": "3 2\n0 2\n5 0", "output": "7.000000000000000"}]
| 1,700 |
["greedy", "math"]
| 54 |
[{"input": "2 3\r\n-1 3\r\n0 0\r\n-1 -4\r\n", "output": "-2.500000000000000\r\n"}, {"input": "3 2\r\n0 2\r\n5 0\r\n", "output": "7.000000000000000\r\n"}, {"input": "8 8\r\n-21 -60\r\n-96 -10\r\n-4 -19\r\n-27 -4\r\n57 -15\r\n-95 62\r\n-42 1\r\n-17 64\r\n", "output": "-16.500000000000000\r\n"}, {"input": "1 1\r\n0 0\r\n", "output": "0.000000000000000\r\n"}, {"input": "100000 1\r\n1000 1000\r\n", "output": "50000500.000000000000000\r\n"}, {"input": "11 1\r\n0 -10\r\n", "output": "-27.272727272727273\r\n"}, {"input": "3 1\r\n1 -1\r\n", "output": "0.333333333333333\r\n"}, {"input": "1 2\r\n-1 -1\r\n-2 -2\r\n", "output": "-3.000000000000000\r\n"}, {"input": "1 2\r\n0 -1\r\n0 1\r\n", "output": "0.000000000000000\r\n"}, {"input": "1 1\r\n1 -2\r\n", "output": "1.000000000000000\r\n"}, {"input": "3 1\r\n2 -1\r\n", "output": "1.333333333333333\r\n"}, {"input": "3 1\r\n0 -1\r\n", "output": "-0.666666666666667\r\n"}, {"input": "1 1\r\n-1000 -1000\r\n", "output": "-1000.000000000000000\r\n"}, {"input": "1 1\r\n0 -5\r\n", "output": "0.000000000000000\r\n"}, {"input": "15 3\r\n2 0\r\n2 -5\r\n-2 5\r\n", "output": "18.333333333333332\r\n"}, {"input": "9 1\r\n0 -5\r\n", "output": "-11.111111111111111\r\n"}, {"input": "7 1\r\n0 -1\r\n", "output": "-1.714285714285714\r\n"}, {"input": "3 1\r\n-2 -2\r\n", "output": "-3.333333333333333\r\n"}, {"input": "3 1\r\n5 -5\r\n", "output": "1.666666666666667\r\n"}, {"input": "1 1\r\n-1 -1\r\n", "output": "-1.000000000000000\r\n"}, {"input": "7 1\r\n-1 -5\r\n", "output": "-9.571428571428571\r\n"}, {"input": "3 2\r\n-2 -2\r\n-2 -2\r\n", "output": "-6.666666666666667\r\n"}, {"input": "5 1\r\n0 -4\r\n", "output": "-4.800000000000000\r\n"}, {"input": "5 1\r\n-1 -5\r\n", "output": "-7.000000000000000\r\n"}, {"input": "5 1\r\n0 -2\r\n", "output": "-2.400000000000000\r\n"}, {"input": "3 5\r\n1 -1000\r\n1 -1000\r\n1 -1000\r\n1 -1000\r\n1 -1000\r\n", "output": "-3328.333333333333485\r\n"}, {"input": "1 1\r\n0 -1\r\n", "output": "0.000000000000000\r\n"}, {"input": "1 2\r\n0 -3\r\n0 -3\r\n", "output": "0.000000000000000\r\n"}, {"input": "7 1\r\n2 -3\r\n", "output": "-3.142857142857143\r\n"}, {"input": "3 2\r\n-1 -1\r\n-1 -1\r\n", "output": "-3.333333333333333\r\n"}, {"input": "5 1\r\n-1 -162\r\n", "output": "-195.400000000000006\r\n"}, {"input": "5 10\r\n-506 -243\r\n727 -141\r\n-548 -306\r\n740 880\r\n-744 -116\r\n-84 182\r\n-859 -108\r\n64 86\r\n135 446\r\n69 -184\r\n", "output": "864.399999999999977\r\n"}, {"input": "5 1\r\n0 -1\r\n", "output": "-1.200000000000000\r\n"}, {"input": "5 12\r\n634 895\r\n143 730\r\n901 245\r\n386 486\r\n395 -111\r\n-469 -104\r\n-681 -623\r\n-900 843\r\n889 -883\r\n476 -304\r\n777 986\r\n206 -491\r\n", "output": "8107.800000000000182\r\n"}, {"input": "3 3\r\n4 2\r\n5 0\r\n6 -1\r\n", "output": "16.333333333333332\r\n"}, {"input": "1 3\r\n4 2\r\n5 0\r\n6 -1\r\n", "output": "15.000000000000000\r\n"}, {"input": "85 10\r\n-223 435\r\n-771 455\r\n72 -940\r\n490 -178\r\n400 -117\r\n169 -527\r\n836 610\r\n849 944\r\n572 -237\r\n-428 -428\r\n", "output": "53047.388235294114565\r\n"}, {"input": "69 10\r\n-8 4\r\n-3 3\r\n7 5\r\n5 -9\r\n8 1\r\n7 -5\r\n-8 -8\r\n9 3\r\n1 1\r\n0 6\r\n", "output": "420.579710144927560\r\n"}, {"input": "1 10\r\n1 1\r\n1 0\r\n1 0\r\n1 0\r\n-1 0\r\n0 1\r\n1 0\r\n0 0\r\n2 1\r\n9 2\r\n", "output": "15.000000000000000\r\n"}, {"input": "5 4\r\n0 1\r\n0 2\r\n0 3\r\n0 -9\r\n", "output": "1.200000000000000\r\n"}]
| false |
stdio
|
import sys
import math
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(output_path) as f:
expected_line = f.readline().strip()
expected = float(expected_line)
with open(submission_path) as f:
submission_line = f.readline().strip()
try:
actual = float(submission_line)
except:
print(0)
return
abs_error = abs(expected - actual)
if abs_error <= 1e-6:
print(1)
return
if expected == 0 and actual == 0:
print(1)
return
max_abs = max(abs(expected), abs(actual))
if max_abs < 1e-9:
print(1)
return
rel_error = abs_error / max_abs
print(1 if rel_error <= 1e-6 else 0)
if __name__ == "__main__":
main()
| true |
1009/C
|
1009
|
C
|
PyPy 3
|
TESTS
| 38 | 155 | 22,016,000 |
126667191
|
import sys
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.buffer.readline())
def MI(): return map(int, sys.stdin.buffer.readline().split())
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def BI(): return sys.stdin.buffer.readline().rstrip()
def SI(): return sys.stdin.buffer.readline().rstrip().decode()
def li(): return [int(i) for i in input().split()]
def lli(rows): return [li() for _ in range(rows)]
def si(): return input()
def ii(): return int(input())
def ins(): return input().split()
n,m=MI()
posf=(n-1)/2
if(n%2!=0):
negf=((n//2)*(n//2+1))/n
else:
negf=((n//2)*(n//2-1)+n//2)/n
ans=0
for i in range(m):
x,d=MI()
ans+=x
if(d>=0):
ans+=posf*d
else:
ans+=negf*d
print(ans)
| 54 | 124 | 3,891,200 |
203055355
|
import sys
input = sys.stdin.readline
def f(u):
return u*(u+1)//2
n, m = map(int, input().split())
x1, x2 = n//2, (n-1)//2
x, y, c, d = f(x1) + f(x2), f(n-1), 0, 0
for i in range(m):
a, b = map(int, input().split())
c += a
d += max(b*x, b*y)
print((c*n+d)/n)
|
Educational Codeforces Round 47 (Rated for Div. 2)
|
ICPC
| 2,018 | 2 | 256 |
Annoying Present
|
Alice got an array of length $$$n$$$ as a birthday present once again! This is the third year in a row!
And what is more disappointing, it is overwhelmengly boring, filled entirely with zeros. Bob decided to apply some changes to the array to cheer up Alice.
Bob has chosen $$$m$$$ changes of the following form. For some integer numbers $$$x$$$ and $$$d$$$, he chooses an arbitrary position $$$i$$$ ($$$1 \le i \le n$$$) and for every $$$j \in [1, n]$$$ adds $$$x + d \cdot dist(i, j)$$$ to the value of the $$$j$$$-th cell. $$$dist(i, j)$$$ is the distance between positions $$$i$$$ and $$$j$$$ (i.e. $$$dist(i, j) = |i - j|$$$, where $$$|x|$$$ is an absolute value of $$$x$$$).
For example, if Alice currently has an array $$$[2, 1, 2, 2]$$$ and Bob chooses position $$$3$$$ for $$$x = -1$$$ and $$$d = 2$$$ then the array will become $$$[2 - 1 + 2 \cdot 2,~1 - 1 + 2 \cdot 1,~2 - 1 + 2 \cdot 0,~2 - 1 + 2 \cdot 1]$$$ = $$$[5, 2, 1, 3]$$$. Note that Bob can't choose position $$$i$$$ outside of the array (that is, smaller than $$$1$$$ or greater than $$$n$$$).
Alice will be the happiest when the elements of the array are as big as possible. Bob claimed that the arithmetic mean value of the elements will work fine as a metric.
What is the maximum arithmetic mean value Bob can achieve?
|
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^5$$$) — the number of elements of the array and the number of changes.
Each of the next $$$m$$$ lines contains two integers $$$x_i$$$ and $$$d_i$$$ ($$$-10^3 \le x_i, d_i \le 10^3$$$) — the parameters for the $$$i$$$-th change.
|
Print the maximal average arithmetic mean of the elements Bob can achieve.
Your answer is considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$.
| null | null |
[{"input": "2 3\n-1 3\n0 0\n-1 -4", "output": "-2.500000000000000"}, {"input": "3 2\n0 2\n5 0", "output": "7.000000000000000"}]
| 1,700 |
["greedy", "math"]
| 54 |
[{"input": "2 3\r\n-1 3\r\n0 0\r\n-1 -4\r\n", "output": "-2.500000000000000\r\n"}, {"input": "3 2\r\n0 2\r\n5 0\r\n", "output": "7.000000000000000\r\n"}, {"input": "8 8\r\n-21 -60\r\n-96 -10\r\n-4 -19\r\n-27 -4\r\n57 -15\r\n-95 62\r\n-42 1\r\n-17 64\r\n", "output": "-16.500000000000000\r\n"}, {"input": "1 1\r\n0 0\r\n", "output": "0.000000000000000\r\n"}, {"input": "100000 1\r\n1000 1000\r\n", "output": "50000500.000000000000000\r\n"}, {"input": "11 1\r\n0 -10\r\n", "output": "-27.272727272727273\r\n"}, {"input": "3 1\r\n1 -1\r\n", "output": "0.333333333333333\r\n"}, {"input": "1 2\r\n-1 -1\r\n-2 -2\r\n", "output": "-3.000000000000000\r\n"}, {"input": "1 2\r\n0 -1\r\n0 1\r\n", "output": "0.000000000000000\r\n"}, {"input": "1 1\r\n1 -2\r\n", "output": "1.000000000000000\r\n"}, {"input": "3 1\r\n2 -1\r\n", "output": "1.333333333333333\r\n"}, {"input": "3 1\r\n0 -1\r\n", "output": "-0.666666666666667\r\n"}, {"input": "1 1\r\n-1000 -1000\r\n", "output": "-1000.000000000000000\r\n"}, {"input": "1 1\r\n0 -5\r\n", "output": "0.000000000000000\r\n"}, {"input": "15 3\r\n2 0\r\n2 -5\r\n-2 5\r\n", "output": "18.333333333333332\r\n"}, {"input": "9 1\r\n0 -5\r\n", "output": "-11.111111111111111\r\n"}, {"input": "7 1\r\n0 -1\r\n", "output": "-1.714285714285714\r\n"}, {"input": "3 1\r\n-2 -2\r\n", "output": "-3.333333333333333\r\n"}, {"input": "3 1\r\n5 -5\r\n", "output": "1.666666666666667\r\n"}, {"input": "1 1\r\n-1 -1\r\n", "output": "-1.000000000000000\r\n"}, {"input": "7 1\r\n-1 -5\r\n", "output": "-9.571428571428571\r\n"}, {"input": "3 2\r\n-2 -2\r\n-2 -2\r\n", "output": "-6.666666666666667\r\n"}, {"input": "5 1\r\n0 -4\r\n", "output": "-4.800000000000000\r\n"}, {"input": "5 1\r\n-1 -5\r\n", "output": "-7.000000000000000\r\n"}, {"input": "5 1\r\n0 -2\r\n", "output": "-2.400000000000000\r\n"}, {"input": "3 5\r\n1 -1000\r\n1 -1000\r\n1 -1000\r\n1 -1000\r\n1 -1000\r\n", "output": "-3328.333333333333485\r\n"}, {"input": "1 1\r\n0 -1\r\n", "output": "0.000000000000000\r\n"}, {"input": "1 2\r\n0 -3\r\n0 -3\r\n", "output": "0.000000000000000\r\n"}, {"input": "7 1\r\n2 -3\r\n", "output": "-3.142857142857143\r\n"}, {"input": "3 2\r\n-1 -1\r\n-1 -1\r\n", "output": "-3.333333333333333\r\n"}, {"input": "5 1\r\n-1 -162\r\n", "output": "-195.400000000000006\r\n"}, {"input": "5 10\r\n-506 -243\r\n727 -141\r\n-548 -306\r\n740 880\r\n-744 -116\r\n-84 182\r\n-859 -108\r\n64 86\r\n135 446\r\n69 -184\r\n", "output": "864.399999999999977\r\n"}, {"input": "5 1\r\n0 -1\r\n", "output": "-1.200000000000000\r\n"}, {"input": "5 12\r\n634 895\r\n143 730\r\n901 245\r\n386 486\r\n395 -111\r\n-469 -104\r\n-681 -623\r\n-900 843\r\n889 -883\r\n476 -304\r\n777 986\r\n206 -491\r\n", "output": "8107.800000000000182\r\n"}, {"input": "3 3\r\n4 2\r\n5 0\r\n6 -1\r\n", "output": "16.333333333333332\r\n"}, {"input": "1 3\r\n4 2\r\n5 0\r\n6 -1\r\n", "output": "15.000000000000000\r\n"}, {"input": "85 10\r\n-223 435\r\n-771 455\r\n72 -940\r\n490 -178\r\n400 -117\r\n169 -527\r\n836 610\r\n849 944\r\n572 -237\r\n-428 -428\r\n", "output": "53047.388235294114565\r\n"}, {"input": "69 10\r\n-8 4\r\n-3 3\r\n7 5\r\n5 -9\r\n8 1\r\n7 -5\r\n-8 -8\r\n9 3\r\n1 1\r\n0 6\r\n", "output": "420.579710144927560\r\n"}, {"input": "1 10\r\n1 1\r\n1 0\r\n1 0\r\n1 0\r\n-1 0\r\n0 1\r\n1 0\r\n0 0\r\n2 1\r\n9 2\r\n", "output": "15.000000000000000\r\n"}, {"input": "5 4\r\n0 1\r\n0 2\r\n0 3\r\n0 -9\r\n", "output": "1.200000000000000\r\n"}]
| false |
stdio
|
import sys
import math
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(output_path) as f:
expected_line = f.readline().strip()
expected = float(expected_line)
with open(submission_path) as f:
submission_line = f.readline().strip()
try:
actual = float(submission_line)
except:
print(0)
return
abs_error = abs(expected - actual)
if abs_error <= 1e-6:
print(1)
return
if expected == 0 and actual == 0:
print(1)
return
max_abs = max(abs(expected), abs(actual))
if max_abs < 1e-9:
print(1)
return
rel_error = abs_error / max_abs
print(1 if rel_error <= 1e-6 else 0)
if __name__ == "__main__":
main()
| true |
672/B
|
672
|
B
|
PyPy 3
|
TESTS
| 34 | 140 | 22,220,800 |
88035762
|
n = int(input())
m = list(input())
if n==1 or n>26:
print(-1)
else:
print(n-len(set(m)))
| 47 | 46 | 0 |
141478516
|
print(l-sett if (l:=int(input()),st:=input(),sett:=len(set(st))) and 26-sett>=l-sett else -1)
|
Codeforces Round 352 (Div. 2)
|
CF
| 2,016 | 2 | 256 |
Different is Good
|
A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different.
Kerem recently got a string s consisting of lowercase English letters. Since Kerem likes it when things are different, he wants all substrings of his string s to be distinct. Substring is a string formed by some number of consecutive characters of the string. For example, string "aba" has substrings "" (empty substring), "a", "b", "a", "ab", "ba", "aba".
If string s has at least two equal substrings then Kerem will change characters at some positions to some other lowercase English letters. Changing characters is a very tiring job, so Kerem want to perform as few changes as possible.
Your task is to find the minimum number of changes needed to make all the substrings of the given string distinct, or determine that it is impossible.
|
The first line of the input contains an integer n (1 ≤ n ≤ 100 000) — the length of the string s.
The second line contains the string s of length n consisting of only lowercase English letters.
|
If it's impossible to change the string s such that all its substring are distinct print -1. Otherwise print the minimum required number of changes.
| null |
In the first sample one of the possible solutions is to change the first character to 'b'.
In the second sample, one may change the first character to 'a' and second character to 'b', so the string becomes "abko".
|
[{"input": "2\naa", "output": "1"}, {"input": "4\nkoko", "output": "2"}, {"input": "5\nmurat", "output": "0"}]
| 1,000 |
["constructive algorithms", "implementation", "strings"]
| 47 |
[{"input": "2\r\naa\r\n", "output": "1\r\n"}, {"input": "4\r\nkoko\r\n", "output": "2\r\n"}, {"input": "5\r\nmurat\r\n", "output": "0\r\n"}, {"input": "6\r\nacbead\r\n", "output": "1\r\n"}, {"input": "7\r\ncdaadad\r\n", "output": "4\r\n"}, {"input": "25\r\npeoaicnbisdocqofsqdpgobpn\r\n", "output": "12\r\n"}, {"input": "25\r\ntcqpchnqskqjacruoaqilgebu\r\n", "output": "7\r\n"}, {"input": "13\r\naebaecedabbee\r\n", "output": "8\r\n"}, {"input": "27\r\naaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n", "output": "-1\r\n"}, {"input": "10\r\nbababbdaee\r\n", "output": "6\r\n"}, {"input": "11\r\ndbadcdbdbca\r\n", "output": "7\r\n"}, {"input": "12\r\nacceaabddaaa\r\n", "output": "7\r\n"}, {"input": "13\r\nabddfbfaeecfa\r\n", "output": "7\r\n"}, {"input": "14\r\neeceecacdbcbbb\r\n", "output": "9\r\n"}, {"input": "15\r\ndcbceaaggabaheb\r\n", "output": "8\r\n"}, {"input": "16\r\nhgiegfbadgcicbhd\r\n", "output": "7\r\n"}, {"input": "17\r\nabhfibbdddfghgfdi\r\n", "output": "10\r\n"}, {"input": "26\r\nbbbbbabbaababaaabaaababbaa\r\n", "output": "24\r\n"}, {"input": "26\r\nahnxdnbfbcrirerssyzydihuee\r\n", "output": "11\r\n"}, {"input": "26\r\nhwqeqhkpxwulbsiwmnlfyhgknc\r\n", "output": "8\r\n"}, {"input": "26\r\nrvxmulriorilidecqwmfaemifj\r\n", "output": "10\r\n"}, {"input": "26\r\naowpmreooavnmamogdoopuisge\r\n", "output": "12\r\n"}, {"input": "26\r\ninimevtuefhvuefirdehmmfudh\r\n", "output": "15\r\n"}, {"input": "26\r\naaaaaaaaaaaaaaaaaaaaaaaaaa\r\n", "output": "25\r\n"}, {"input": "27\r\nqdcfjtblgglnilgassirrjekcjt\r\n", "output": "-1\r\n"}, {"input": "27\r\nabcdefghijklmnopqrstuvwxyza\r\n", "output": "-1\r\n"}, {"input": "26\r\nqwertyuiopasdfghjklzxcvbnm\r\n", "output": "0\r\n"}, {"input": "5\r\nzzzzz\r\n", "output": "4\r\n"}, {"input": "27\r\naaaaaaaaaaaaaaaaabaaaaaaaaa\r\n", "output": "-1\r\n"}, {"input": "1\r\nq\r\n", "output": "0\r\n"}, {"input": "27\r\nqwertyuioplkjhgfdsazxcvbnmm\r\n", "output": "-1\r\n"}, {"input": "9\r\nxxxyyyzzz\r\n", "output": "6\r\n"}, {"input": "45\r\naaabbbcccdddeeefffgghhiijjkkkkkkkkkkkkkkkkkkk\r\n", "output": "-1\r\n"}, {"input": "27\r\nqwertyuiopasdfghjklzxcvbnmm\r\n", "output": "-1\r\n"}, {"input": "26\r\nabcdefghijklmnopqrstuvwxyz\r\n", "output": "0\r\n"}, {"input": "26\r\nabcdefghijklmnopqrstuvwxya\r\n", "output": "1\r\n"}, {"input": "27\r\nabcdefghijklmnopqrstuvwxyzz\r\n", "output": "-1\r\n"}, {"input": "26\r\naaaaaaaaaaaaaaaaaaaaaaaaaa\r\n", "output": "25\r\n"}, {"input": "26\r\nqwertyuioplkjhgfdsazxcvbnm\r\n", "output": "0\r\n"}, {"input": "10\r\nzzzzzzzzzz\r\n", "output": "9\r\n"}, {"input": "1\r\na\r\n", "output": "0\r\n"}, {"input": "30\r\nabcdefghtyabcdefghtyabcdefghty\r\n", "output": "-1\r\n"}]
| false |
stdio
| null | true |
1009/C
|
1009
|
C
|
Python 3
|
TESTS
| 38 | 373 | 0 |
40369439
|
from sys import stdin, stdout
a = [int(x) for x in stdin.readline().split()]
n = a[0]
m = a[1]
max_m = n * (n-1)/ 2
if n % 2 == 0:
min_m = ((n/2)*(n/2 + 1))/2 + ((n/2 - 1)*(n/2))/2
else:
min_m = int(n/2) * (int(n/2 + 1))
curr = 0
for i in range(0, m):
a = [int(x) for x in stdin.readline().split()]
x = a[0]
d = a[1]
if d > 0:
dc = max_m * d
else:
dc = min_m * d
curr += dc + x * n
stdout.write(str(curr / n))
| 54 | 139 | 11,673,600 |
218719337
|
import sys
input = lambda: sys.stdin.readline().rstrip()
import math
from heapq import heappush , heappop
from collections import defaultdict,deque,Counter
from bisect import *
N,M = map(int, input().split())
A = []
for _ in range(M):
x,d = map(int, input().split())
A.append((x,d))
ans = 0
for x,d in A:
ans += x*N
if d>=0:
ans += N*(N-1)//2*d
else:
a = (N-1)//2
b = N-1-a
#print(a,b)
ans += (a+1)*a//2*d
ans += (b+1)*b//2*d
#print(ans)
print(ans/N)
|
Educational Codeforces Round 47 (Rated for Div. 2)
|
ICPC
| 2,018 | 2 | 256 |
Annoying Present
|
Alice got an array of length $$$n$$$ as a birthday present once again! This is the third year in a row!
And what is more disappointing, it is overwhelmengly boring, filled entirely with zeros. Bob decided to apply some changes to the array to cheer up Alice.
Bob has chosen $$$m$$$ changes of the following form. For some integer numbers $$$x$$$ and $$$d$$$, he chooses an arbitrary position $$$i$$$ ($$$1 \le i \le n$$$) and for every $$$j \in [1, n]$$$ adds $$$x + d \cdot dist(i, j)$$$ to the value of the $$$j$$$-th cell. $$$dist(i, j)$$$ is the distance between positions $$$i$$$ and $$$j$$$ (i.e. $$$dist(i, j) = |i - j|$$$, where $$$|x|$$$ is an absolute value of $$$x$$$).
For example, if Alice currently has an array $$$[2, 1, 2, 2]$$$ and Bob chooses position $$$3$$$ for $$$x = -1$$$ and $$$d = 2$$$ then the array will become $$$[2 - 1 + 2 \cdot 2,~1 - 1 + 2 \cdot 1,~2 - 1 + 2 \cdot 0,~2 - 1 + 2 \cdot 1]$$$ = $$$[5, 2, 1, 3]$$$. Note that Bob can't choose position $$$i$$$ outside of the array (that is, smaller than $$$1$$$ or greater than $$$n$$$).
Alice will be the happiest when the elements of the array are as big as possible. Bob claimed that the arithmetic mean value of the elements will work fine as a metric.
What is the maximum arithmetic mean value Bob can achieve?
|
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^5$$$) — the number of elements of the array and the number of changes.
Each of the next $$$m$$$ lines contains two integers $$$x_i$$$ and $$$d_i$$$ ($$$-10^3 \le x_i, d_i \le 10^3$$$) — the parameters for the $$$i$$$-th change.
|
Print the maximal average arithmetic mean of the elements Bob can achieve.
Your answer is considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$.
| null | null |
[{"input": "2 3\n-1 3\n0 0\n-1 -4", "output": "-2.500000000000000"}, {"input": "3 2\n0 2\n5 0", "output": "7.000000000000000"}]
| 1,700 |
["greedy", "math"]
| 54 |
[{"input": "2 3\r\n-1 3\r\n0 0\r\n-1 -4\r\n", "output": "-2.500000000000000\r\n"}, {"input": "3 2\r\n0 2\r\n5 0\r\n", "output": "7.000000000000000\r\n"}, {"input": "8 8\r\n-21 -60\r\n-96 -10\r\n-4 -19\r\n-27 -4\r\n57 -15\r\n-95 62\r\n-42 1\r\n-17 64\r\n", "output": "-16.500000000000000\r\n"}, {"input": "1 1\r\n0 0\r\n", "output": "0.000000000000000\r\n"}, {"input": "100000 1\r\n1000 1000\r\n", "output": "50000500.000000000000000\r\n"}, {"input": "11 1\r\n0 -10\r\n", "output": "-27.272727272727273\r\n"}, {"input": "3 1\r\n1 -1\r\n", "output": "0.333333333333333\r\n"}, {"input": "1 2\r\n-1 -1\r\n-2 -2\r\n", "output": "-3.000000000000000\r\n"}, {"input": "1 2\r\n0 -1\r\n0 1\r\n", "output": "0.000000000000000\r\n"}, {"input": "1 1\r\n1 -2\r\n", "output": "1.000000000000000\r\n"}, {"input": "3 1\r\n2 -1\r\n", "output": "1.333333333333333\r\n"}, {"input": "3 1\r\n0 -1\r\n", "output": "-0.666666666666667\r\n"}, {"input": "1 1\r\n-1000 -1000\r\n", "output": "-1000.000000000000000\r\n"}, {"input": "1 1\r\n0 -5\r\n", "output": "0.000000000000000\r\n"}, {"input": "15 3\r\n2 0\r\n2 -5\r\n-2 5\r\n", "output": "18.333333333333332\r\n"}, {"input": "9 1\r\n0 -5\r\n", "output": "-11.111111111111111\r\n"}, {"input": "7 1\r\n0 -1\r\n", "output": "-1.714285714285714\r\n"}, {"input": "3 1\r\n-2 -2\r\n", "output": "-3.333333333333333\r\n"}, {"input": "3 1\r\n5 -5\r\n", "output": "1.666666666666667\r\n"}, {"input": "1 1\r\n-1 -1\r\n", "output": "-1.000000000000000\r\n"}, {"input": "7 1\r\n-1 -5\r\n", "output": "-9.571428571428571\r\n"}, {"input": "3 2\r\n-2 -2\r\n-2 -2\r\n", "output": "-6.666666666666667\r\n"}, {"input": "5 1\r\n0 -4\r\n", "output": "-4.800000000000000\r\n"}, {"input": "5 1\r\n-1 -5\r\n", "output": "-7.000000000000000\r\n"}, {"input": "5 1\r\n0 -2\r\n", "output": "-2.400000000000000\r\n"}, {"input": "3 5\r\n1 -1000\r\n1 -1000\r\n1 -1000\r\n1 -1000\r\n1 -1000\r\n", "output": "-3328.333333333333485\r\n"}, {"input": "1 1\r\n0 -1\r\n", "output": "0.000000000000000\r\n"}, {"input": "1 2\r\n0 -3\r\n0 -3\r\n", "output": "0.000000000000000\r\n"}, {"input": "7 1\r\n2 -3\r\n", "output": "-3.142857142857143\r\n"}, {"input": "3 2\r\n-1 -1\r\n-1 -1\r\n", "output": "-3.333333333333333\r\n"}, {"input": "5 1\r\n-1 -162\r\n", "output": "-195.400000000000006\r\n"}, {"input": "5 10\r\n-506 -243\r\n727 -141\r\n-548 -306\r\n740 880\r\n-744 -116\r\n-84 182\r\n-859 -108\r\n64 86\r\n135 446\r\n69 -184\r\n", "output": "864.399999999999977\r\n"}, {"input": "5 1\r\n0 -1\r\n", "output": "-1.200000000000000\r\n"}, {"input": "5 12\r\n634 895\r\n143 730\r\n901 245\r\n386 486\r\n395 -111\r\n-469 -104\r\n-681 -623\r\n-900 843\r\n889 -883\r\n476 -304\r\n777 986\r\n206 -491\r\n", "output": "8107.800000000000182\r\n"}, {"input": "3 3\r\n4 2\r\n5 0\r\n6 -1\r\n", "output": "16.333333333333332\r\n"}, {"input": "1 3\r\n4 2\r\n5 0\r\n6 -1\r\n", "output": "15.000000000000000\r\n"}, {"input": "85 10\r\n-223 435\r\n-771 455\r\n72 -940\r\n490 -178\r\n400 -117\r\n169 -527\r\n836 610\r\n849 944\r\n572 -237\r\n-428 -428\r\n", "output": "53047.388235294114565\r\n"}, {"input": "69 10\r\n-8 4\r\n-3 3\r\n7 5\r\n5 -9\r\n8 1\r\n7 -5\r\n-8 -8\r\n9 3\r\n1 1\r\n0 6\r\n", "output": "420.579710144927560\r\n"}, {"input": "1 10\r\n1 1\r\n1 0\r\n1 0\r\n1 0\r\n-1 0\r\n0 1\r\n1 0\r\n0 0\r\n2 1\r\n9 2\r\n", "output": "15.000000000000000\r\n"}, {"input": "5 4\r\n0 1\r\n0 2\r\n0 3\r\n0 -9\r\n", "output": "1.200000000000000\r\n"}]
| false |
stdio
|
import sys
import math
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(output_path) as f:
expected_line = f.readline().strip()
expected = float(expected_line)
with open(submission_path) as f:
submission_line = f.readline().strip()
try:
actual = float(submission_line)
except:
print(0)
return
abs_error = abs(expected - actual)
if abs_error <= 1e-6:
print(1)
return
if expected == 0 and actual == 0:
print(1)
return
max_abs = max(abs(expected), abs(actual))
if max_abs < 1e-9:
print(1)
return
rel_error = abs_error / max_abs
print(1 if rel_error <= 1e-6 else 0)
if __name__ == "__main__":
main()
| true |
1009/C
|
1009
|
C
|
Python 3
|
TESTS
| 38 | 374 | 0 |
59959282
|
n,m=map(int,input().split())
def su(x):
return x*(x+1)
s=0
t=0
if(n==1):
for i in range(m):
x,d=map(int,input().split())
s+=x
print(s)
else:
for i in range(m):
x,d=map(int,input().split())
s+=x
if(d>=0):
t+=d*(su(n-1)/2)
else:
if(n%2==0):
t+=(d*(su((n/2))-n/2))
else:
t+=(d*su(n//2))
print(s+t/n)
| 54 | 155 | 5,427,200 |
112760067
|
import sys
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
n, m = map(int, input().split())
MAX = 0
MIN = 10**18
for i in range(n):
l = i*(i+1)//2
r = (n-1-i)*(n-1-i+1)//2
MAX= max(MAX, l+r)
MIN = min(MIN, l+r)
ans = 0
for i in range(m):
x, d = map(int, input().split())
ans += n*x
if d >= 0:
ans += d*MAX
else:
ans += d*MIN
print(ans/n)
|
Educational Codeforces Round 47 (Rated for Div. 2)
|
ICPC
| 2,018 | 2 | 256 |
Annoying Present
|
Alice got an array of length $$$n$$$ as a birthday present once again! This is the third year in a row!
And what is more disappointing, it is overwhelmengly boring, filled entirely with zeros. Bob decided to apply some changes to the array to cheer up Alice.
Bob has chosen $$$m$$$ changes of the following form. For some integer numbers $$$x$$$ and $$$d$$$, he chooses an arbitrary position $$$i$$$ ($$$1 \le i \le n$$$) and for every $$$j \in [1, n]$$$ adds $$$x + d \cdot dist(i, j)$$$ to the value of the $$$j$$$-th cell. $$$dist(i, j)$$$ is the distance between positions $$$i$$$ and $$$j$$$ (i.e. $$$dist(i, j) = |i - j|$$$, where $$$|x|$$$ is an absolute value of $$$x$$$).
For example, if Alice currently has an array $$$[2, 1, 2, 2]$$$ and Bob chooses position $$$3$$$ for $$$x = -1$$$ and $$$d = 2$$$ then the array will become $$$[2 - 1 + 2 \cdot 2,~1 - 1 + 2 \cdot 1,~2 - 1 + 2 \cdot 0,~2 - 1 + 2 \cdot 1]$$$ = $$$[5, 2, 1, 3]$$$. Note that Bob can't choose position $$$i$$$ outside of the array (that is, smaller than $$$1$$$ or greater than $$$n$$$).
Alice will be the happiest when the elements of the array are as big as possible. Bob claimed that the arithmetic mean value of the elements will work fine as a metric.
What is the maximum arithmetic mean value Bob can achieve?
|
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^5$$$) — the number of elements of the array and the number of changes.
Each of the next $$$m$$$ lines contains two integers $$$x_i$$$ and $$$d_i$$$ ($$$-10^3 \le x_i, d_i \le 10^3$$$) — the parameters for the $$$i$$$-th change.
|
Print the maximal average arithmetic mean of the elements Bob can achieve.
Your answer is considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$.
| null | null |
[{"input": "2 3\n-1 3\n0 0\n-1 -4", "output": "-2.500000000000000"}, {"input": "3 2\n0 2\n5 0", "output": "7.000000000000000"}]
| 1,700 |
["greedy", "math"]
| 54 |
[{"input": "2 3\r\n-1 3\r\n0 0\r\n-1 -4\r\n", "output": "-2.500000000000000\r\n"}, {"input": "3 2\r\n0 2\r\n5 0\r\n", "output": "7.000000000000000\r\n"}, {"input": "8 8\r\n-21 -60\r\n-96 -10\r\n-4 -19\r\n-27 -4\r\n57 -15\r\n-95 62\r\n-42 1\r\n-17 64\r\n", "output": "-16.500000000000000\r\n"}, {"input": "1 1\r\n0 0\r\n", "output": "0.000000000000000\r\n"}, {"input": "100000 1\r\n1000 1000\r\n", "output": "50000500.000000000000000\r\n"}, {"input": "11 1\r\n0 -10\r\n", "output": "-27.272727272727273\r\n"}, {"input": "3 1\r\n1 -1\r\n", "output": "0.333333333333333\r\n"}, {"input": "1 2\r\n-1 -1\r\n-2 -2\r\n", "output": "-3.000000000000000\r\n"}, {"input": "1 2\r\n0 -1\r\n0 1\r\n", "output": "0.000000000000000\r\n"}, {"input": "1 1\r\n1 -2\r\n", "output": "1.000000000000000\r\n"}, {"input": "3 1\r\n2 -1\r\n", "output": "1.333333333333333\r\n"}, {"input": "3 1\r\n0 -1\r\n", "output": "-0.666666666666667\r\n"}, {"input": "1 1\r\n-1000 -1000\r\n", "output": "-1000.000000000000000\r\n"}, {"input": "1 1\r\n0 -5\r\n", "output": "0.000000000000000\r\n"}, {"input": "15 3\r\n2 0\r\n2 -5\r\n-2 5\r\n", "output": "18.333333333333332\r\n"}, {"input": "9 1\r\n0 -5\r\n", "output": "-11.111111111111111\r\n"}, {"input": "7 1\r\n0 -1\r\n", "output": "-1.714285714285714\r\n"}, {"input": "3 1\r\n-2 -2\r\n", "output": "-3.333333333333333\r\n"}, {"input": "3 1\r\n5 -5\r\n", "output": "1.666666666666667\r\n"}, {"input": "1 1\r\n-1 -1\r\n", "output": "-1.000000000000000\r\n"}, {"input": "7 1\r\n-1 -5\r\n", "output": "-9.571428571428571\r\n"}, {"input": "3 2\r\n-2 -2\r\n-2 -2\r\n", "output": "-6.666666666666667\r\n"}, {"input": "5 1\r\n0 -4\r\n", "output": "-4.800000000000000\r\n"}, {"input": "5 1\r\n-1 -5\r\n", "output": "-7.000000000000000\r\n"}, {"input": "5 1\r\n0 -2\r\n", "output": "-2.400000000000000\r\n"}, {"input": "3 5\r\n1 -1000\r\n1 -1000\r\n1 -1000\r\n1 -1000\r\n1 -1000\r\n", "output": "-3328.333333333333485\r\n"}, {"input": "1 1\r\n0 -1\r\n", "output": "0.000000000000000\r\n"}, {"input": "1 2\r\n0 -3\r\n0 -3\r\n", "output": "0.000000000000000\r\n"}, {"input": "7 1\r\n2 -3\r\n", "output": "-3.142857142857143\r\n"}, {"input": "3 2\r\n-1 -1\r\n-1 -1\r\n", "output": "-3.333333333333333\r\n"}, {"input": "5 1\r\n-1 -162\r\n", "output": "-195.400000000000006\r\n"}, {"input": "5 10\r\n-506 -243\r\n727 -141\r\n-548 -306\r\n740 880\r\n-744 -116\r\n-84 182\r\n-859 -108\r\n64 86\r\n135 446\r\n69 -184\r\n", "output": "864.399999999999977\r\n"}, {"input": "5 1\r\n0 -1\r\n", "output": "-1.200000000000000\r\n"}, {"input": "5 12\r\n634 895\r\n143 730\r\n901 245\r\n386 486\r\n395 -111\r\n-469 -104\r\n-681 -623\r\n-900 843\r\n889 -883\r\n476 -304\r\n777 986\r\n206 -491\r\n", "output": "8107.800000000000182\r\n"}, {"input": "3 3\r\n4 2\r\n5 0\r\n6 -1\r\n", "output": "16.333333333333332\r\n"}, {"input": "1 3\r\n4 2\r\n5 0\r\n6 -1\r\n", "output": "15.000000000000000\r\n"}, {"input": "85 10\r\n-223 435\r\n-771 455\r\n72 -940\r\n490 -178\r\n400 -117\r\n169 -527\r\n836 610\r\n849 944\r\n572 -237\r\n-428 -428\r\n", "output": "53047.388235294114565\r\n"}, {"input": "69 10\r\n-8 4\r\n-3 3\r\n7 5\r\n5 -9\r\n8 1\r\n7 -5\r\n-8 -8\r\n9 3\r\n1 1\r\n0 6\r\n", "output": "420.579710144927560\r\n"}, {"input": "1 10\r\n1 1\r\n1 0\r\n1 0\r\n1 0\r\n-1 0\r\n0 1\r\n1 0\r\n0 0\r\n2 1\r\n9 2\r\n", "output": "15.000000000000000\r\n"}, {"input": "5 4\r\n0 1\r\n0 2\r\n0 3\r\n0 -9\r\n", "output": "1.200000000000000\r\n"}]
| false |
stdio
|
import sys
import math
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(output_path) as f:
expected_line = f.readline().strip()
expected = float(expected_line)
with open(submission_path) as f:
submission_line = f.readline().strip()
try:
actual = float(submission_line)
except:
print(0)
return
abs_error = abs(expected - actual)
if abs_error <= 1e-6:
print(1)
return
if expected == 0 and actual == 0:
print(1)
return
max_abs = max(abs(expected), abs(actual))
if max_abs < 1e-9:
print(1)
return
rel_error = abs_error / max_abs
print(1 if rel_error <= 1e-6 else 0)
if __name__ == "__main__":
main()
| true |
1009/C
|
1009
|
C
|
PyPy 3
|
TESTS
| 38 | 249 | 5,939,200 |
43529176
|
import sys
from sys import stdin,stdout
n,m=map(int,stdin.readline().split(' '))
ans=0
for _ in range(m):
x,d=map(int,stdin.readline().split(' '))
ans+=x
if d>0:
ans+=(((n-1)/2)*d)
if d<0:
if n%2!=0:
ans+=((((n//2)*(n//2+1))/n)*d)
else:
ans+=(((( ( (n-1)//2) * ( (n-1)//2+1) ) +n//2)/n)*d)
print(ans)
| 54 | 202 | 2,355,200 |
94401502
|
import sys
from array import array
def readline(): return sys.stdin.buffer.readline().decode('utf-8')
n, m = map(int, readline().split())
total = 0
for _ in range(m):
x, d = map(int, readline().split())
total += x*n
if d >= 0:
total += d * (((n-1) * n) >> 1)
else:
l = (((n-1) >> 1) * (((n-1) >> 1) + 1)) >> 1
r = ((n >> 1) * ((n >> 1) + 1)) >> 1
total += d * (l + r)
print(total / n)
|
Educational Codeforces Round 47 (Rated for Div. 2)
|
ICPC
| 2,018 | 2 | 256 |
Annoying Present
|
Alice got an array of length $$$n$$$ as a birthday present once again! This is the third year in a row!
And what is more disappointing, it is overwhelmengly boring, filled entirely with zeros. Bob decided to apply some changes to the array to cheer up Alice.
Bob has chosen $$$m$$$ changes of the following form. For some integer numbers $$$x$$$ and $$$d$$$, he chooses an arbitrary position $$$i$$$ ($$$1 \le i \le n$$$) and for every $$$j \in [1, n]$$$ adds $$$x + d \cdot dist(i, j)$$$ to the value of the $$$j$$$-th cell. $$$dist(i, j)$$$ is the distance between positions $$$i$$$ and $$$j$$$ (i.e. $$$dist(i, j) = |i - j|$$$, where $$$|x|$$$ is an absolute value of $$$x$$$).
For example, if Alice currently has an array $$$[2, 1, 2, 2]$$$ and Bob chooses position $$$3$$$ for $$$x = -1$$$ and $$$d = 2$$$ then the array will become $$$[2 - 1 + 2 \cdot 2,~1 - 1 + 2 \cdot 1,~2 - 1 + 2 \cdot 0,~2 - 1 + 2 \cdot 1]$$$ = $$$[5, 2, 1, 3]$$$. Note that Bob can't choose position $$$i$$$ outside of the array (that is, smaller than $$$1$$$ or greater than $$$n$$$).
Alice will be the happiest when the elements of the array are as big as possible. Bob claimed that the arithmetic mean value of the elements will work fine as a metric.
What is the maximum arithmetic mean value Bob can achieve?
|
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^5$$$) — the number of elements of the array and the number of changes.
Each of the next $$$m$$$ lines contains two integers $$$x_i$$$ and $$$d_i$$$ ($$$-10^3 \le x_i, d_i \le 10^3$$$) — the parameters for the $$$i$$$-th change.
|
Print the maximal average arithmetic mean of the elements Bob can achieve.
Your answer is considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$.
| null | null |
[{"input": "2 3\n-1 3\n0 0\n-1 -4", "output": "-2.500000000000000"}, {"input": "3 2\n0 2\n5 0", "output": "7.000000000000000"}]
| 1,700 |
["greedy", "math"]
| 54 |
[{"input": "2 3\r\n-1 3\r\n0 0\r\n-1 -4\r\n", "output": "-2.500000000000000\r\n"}, {"input": "3 2\r\n0 2\r\n5 0\r\n", "output": "7.000000000000000\r\n"}, {"input": "8 8\r\n-21 -60\r\n-96 -10\r\n-4 -19\r\n-27 -4\r\n57 -15\r\n-95 62\r\n-42 1\r\n-17 64\r\n", "output": "-16.500000000000000\r\n"}, {"input": "1 1\r\n0 0\r\n", "output": "0.000000000000000\r\n"}, {"input": "100000 1\r\n1000 1000\r\n", "output": "50000500.000000000000000\r\n"}, {"input": "11 1\r\n0 -10\r\n", "output": "-27.272727272727273\r\n"}, {"input": "3 1\r\n1 -1\r\n", "output": "0.333333333333333\r\n"}, {"input": "1 2\r\n-1 -1\r\n-2 -2\r\n", "output": "-3.000000000000000\r\n"}, {"input": "1 2\r\n0 -1\r\n0 1\r\n", "output": "0.000000000000000\r\n"}, {"input": "1 1\r\n1 -2\r\n", "output": "1.000000000000000\r\n"}, {"input": "3 1\r\n2 -1\r\n", "output": "1.333333333333333\r\n"}, {"input": "3 1\r\n0 -1\r\n", "output": "-0.666666666666667\r\n"}, {"input": "1 1\r\n-1000 -1000\r\n", "output": "-1000.000000000000000\r\n"}, {"input": "1 1\r\n0 -5\r\n", "output": "0.000000000000000\r\n"}, {"input": "15 3\r\n2 0\r\n2 -5\r\n-2 5\r\n", "output": "18.333333333333332\r\n"}, {"input": "9 1\r\n0 -5\r\n", "output": "-11.111111111111111\r\n"}, {"input": "7 1\r\n0 -1\r\n", "output": "-1.714285714285714\r\n"}, {"input": "3 1\r\n-2 -2\r\n", "output": "-3.333333333333333\r\n"}, {"input": "3 1\r\n5 -5\r\n", "output": "1.666666666666667\r\n"}, {"input": "1 1\r\n-1 -1\r\n", "output": "-1.000000000000000\r\n"}, {"input": "7 1\r\n-1 -5\r\n", "output": "-9.571428571428571\r\n"}, {"input": "3 2\r\n-2 -2\r\n-2 -2\r\n", "output": "-6.666666666666667\r\n"}, {"input": "5 1\r\n0 -4\r\n", "output": "-4.800000000000000\r\n"}, {"input": "5 1\r\n-1 -5\r\n", "output": "-7.000000000000000\r\n"}, {"input": "5 1\r\n0 -2\r\n", "output": "-2.400000000000000\r\n"}, {"input": "3 5\r\n1 -1000\r\n1 -1000\r\n1 -1000\r\n1 -1000\r\n1 -1000\r\n", "output": "-3328.333333333333485\r\n"}, {"input": "1 1\r\n0 -1\r\n", "output": "0.000000000000000\r\n"}, {"input": "1 2\r\n0 -3\r\n0 -3\r\n", "output": "0.000000000000000\r\n"}, {"input": "7 1\r\n2 -3\r\n", "output": "-3.142857142857143\r\n"}, {"input": "3 2\r\n-1 -1\r\n-1 -1\r\n", "output": "-3.333333333333333\r\n"}, {"input": "5 1\r\n-1 -162\r\n", "output": "-195.400000000000006\r\n"}, {"input": "5 10\r\n-506 -243\r\n727 -141\r\n-548 -306\r\n740 880\r\n-744 -116\r\n-84 182\r\n-859 -108\r\n64 86\r\n135 446\r\n69 -184\r\n", "output": "864.399999999999977\r\n"}, {"input": "5 1\r\n0 -1\r\n", "output": "-1.200000000000000\r\n"}, {"input": "5 12\r\n634 895\r\n143 730\r\n901 245\r\n386 486\r\n395 -111\r\n-469 -104\r\n-681 -623\r\n-900 843\r\n889 -883\r\n476 -304\r\n777 986\r\n206 -491\r\n", "output": "8107.800000000000182\r\n"}, {"input": "3 3\r\n4 2\r\n5 0\r\n6 -1\r\n", "output": "16.333333333333332\r\n"}, {"input": "1 3\r\n4 2\r\n5 0\r\n6 -1\r\n", "output": "15.000000000000000\r\n"}, {"input": "85 10\r\n-223 435\r\n-771 455\r\n72 -940\r\n490 -178\r\n400 -117\r\n169 -527\r\n836 610\r\n849 944\r\n572 -237\r\n-428 -428\r\n", "output": "53047.388235294114565\r\n"}, {"input": "69 10\r\n-8 4\r\n-3 3\r\n7 5\r\n5 -9\r\n8 1\r\n7 -5\r\n-8 -8\r\n9 3\r\n1 1\r\n0 6\r\n", "output": "420.579710144927560\r\n"}, {"input": "1 10\r\n1 1\r\n1 0\r\n1 0\r\n1 0\r\n-1 0\r\n0 1\r\n1 0\r\n0 0\r\n2 1\r\n9 2\r\n", "output": "15.000000000000000\r\n"}, {"input": "5 4\r\n0 1\r\n0 2\r\n0 3\r\n0 -9\r\n", "output": "1.200000000000000\r\n"}]
| false |
stdio
|
import sys
import math
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(output_path) as f:
expected_line = f.readline().strip()
expected = float(expected_line)
with open(submission_path) as f:
submission_line = f.readline().strip()
try:
actual = float(submission_line)
except:
print(0)
return
abs_error = abs(expected - actual)
if abs_error <= 1e-6:
print(1)
return
if expected == 0 and actual == 0:
print(1)
return
max_abs = max(abs(expected), abs(actual))
if max_abs < 1e-9:
print(1)
return
rel_error = abs_error / max_abs
print(1 if rel_error <= 1e-6 else 0)
if __name__ == "__main__":
main()
| true |
1009/C
|
1009
|
C
|
PyPy 3
|
TESTS
| 38 | 264 | 6,041,600 |
43533263
|
import sys
from sys import stdin,stdout
n,m=map(int,stdin.readline().split(' '))
ans=0
for _ in range(m):
x,d=map(int,stdin.readline().split(' '))
ans+=x
t3=((n//2)*(n//2+1));
t4=( ( (n-1)//2) * ( (n-1)//2+1) );
if d>0:
ans+=(((n-1)/2)*d)
if d<0:
if n%2!=0:
t6=(t3*d)
ans+=(t6/n)
else:
t5=((t4 +n//2)*d)
ans+=(t5/n)
print(ans)
| 54 | 218 | 25,395,200 |
128894865
|
import sys
input = sys.stdin.readline
def f(a):
return a * (a + 1) // 2
n, m = map(int, input().split())
mi, ma = f(n // 2) + f(n // 2 - (n % 2 ^ 1)), f(n - 1)
ans = 0
c = 0
for _ in range(m):
x, d = map(int, input().split())
if d < 0:
ans += d * mi
else:
ans += d * ma
c += x
ans += n * c
ans /= n
print(ans)
|
Educational Codeforces Round 47 (Rated for Div. 2)
|
ICPC
| 2,018 | 2 | 256 |
Annoying Present
|
Alice got an array of length $$$n$$$ as a birthday present once again! This is the third year in a row!
And what is more disappointing, it is overwhelmengly boring, filled entirely with zeros. Bob decided to apply some changes to the array to cheer up Alice.
Bob has chosen $$$m$$$ changes of the following form. For some integer numbers $$$x$$$ and $$$d$$$, he chooses an arbitrary position $$$i$$$ ($$$1 \le i \le n$$$) and for every $$$j \in [1, n]$$$ adds $$$x + d \cdot dist(i, j)$$$ to the value of the $$$j$$$-th cell. $$$dist(i, j)$$$ is the distance between positions $$$i$$$ and $$$j$$$ (i.e. $$$dist(i, j) = |i - j|$$$, where $$$|x|$$$ is an absolute value of $$$x$$$).
For example, if Alice currently has an array $$$[2, 1, 2, 2]$$$ and Bob chooses position $$$3$$$ for $$$x = -1$$$ and $$$d = 2$$$ then the array will become $$$[2 - 1 + 2 \cdot 2,~1 - 1 + 2 \cdot 1,~2 - 1 + 2 \cdot 0,~2 - 1 + 2 \cdot 1]$$$ = $$$[5, 2, 1, 3]$$$. Note that Bob can't choose position $$$i$$$ outside of the array (that is, smaller than $$$1$$$ or greater than $$$n$$$).
Alice will be the happiest when the elements of the array are as big as possible. Bob claimed that the arithmetic mean value of the elements will work fine as a metric.
What is the maximum arithmetic mean value Bob can achieve?
|
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^5$$$) — the number of elements of the array and the number of changes.
Each of the next $$$m$$$ lines contains two integers $$$x_i$$$ and $$$d_i$$$ ($$$-10^3 \le x_i, d_i \le 10^3$$$) — the parameters for the $$$i$$$-th change.
|
Print the maximal average arithmetic mean of the elements Bob can achieve.
Your answer is considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$.
| null | null |
[{"input": "2 3\n-1 3\n0 0\n-1 -4", "output": "-2.500000000000000"}, {"input": "3 2\n0 2\n5 0", "output": "7.000000000000000"}]
| 1,700 |
["greedy", "math"]
| 54 |
[{"input": "2 3\r\n-1 3\r\n0 0\r\n-1 -4\r\n", "output": "-2.500000000000000\r\n"}, {"input": "3 2\r\n0 2\r\n5 0\r\n", "output": "7.000000000000000\r\n"}, {"input": "8 8\r\n-21 -60\r\n-96 -10\r\n-4 -19\r\n-27 -4\r\n57 -15\r\n-95 62\r\n-42 1\r\n-17 64\r\n", "output": "-16.500000000000000\r\n"}, {"input": "1 1\r\n0 0\r\n", "output": "0.000000000000000\r\n"}, {"input": "100000 1\r\n1000 1000\r\n", "output": "50000500.000000000000000\r\n"}, {"input": "11 1\r\n0 -10\r\n", "output": "-27.272727272727273\r\n"}, {"input": "3 1\r\n1 -1\r\n", "output": "0.333333333333333\r\n"}, {"input": "1 2\r\n-1 -1\r\n-2 -2\r\n", "output": "-3.000000000000000\r\n"}, {"input": "1 2\r\n0 -1\r\n0 1\r\n", "output": "0.000000000000000\r\n"}, {"input": "1 1\r\n1 -2\r\n", "output": "1.000000000000000\r\n"}, {"input": "3 1\r\n2 -1\r\n", "output": "1.333333333333333\r\n"}, {"input": "3 1\r\n0 -1\r\n", "output": "-0.666666666666667\r\n"}, {"input": "1 1\r\n-1000 -1000\r\n", "output": "-1000.000000000000000\r\n"}, {"input": "1 1\r\n0 -5\r\n", "output": "0.000000000000000\r\n"}, {"input": "15 3\r\n2 0\r\n2 -5\r\n-2 5\r\n", "output": "18.333333333333332\r\n"}, {"input": "9 1\r\n0 -5\r\n", "output": "-11.111111111111111\r\n"}, {"input": "7 1\r\n0 -1\r\n", "output": "-1.714285714285714\r\n"}, {"input": "3 1\r\n-2 -2\r\n", "output": "-3.333333333333333\r\n"}, {"input": "3 1\r\n5 -5\r\n", "output": "1.666666666666667\r\n"}, {"input": "1 1\r\n-1 -1\r\n", "output": "-1.000000000000000\r\n"}, {"input": "7 1\r\n-1 -5\r\n", "output": "-9.571428571428571\r\n"}, {"input": "3 2\r\n-2 -2\r\n-2 -2\r\n", "output": "-6.666666666666667\r\n"}, {"input": "5 1\r\n0 -4\r\n", "output": "-4.800000000000000\r\n"}, {"input": "5 1\r\n-1 -5\r\n", "output": "-7.000000000000000\r\n"}, {"input": "5 1\r\n0 -2\r\n", "output": "-2.400000000000000\r\n"}, {"input": "3 5\r\n1 -1000\r\n1 -1000\r\n1 -1000\r\n1 -1000\r\n1 -1000\r\n", "output": "-3328.333333333333485\r\n"}, {"input": "1 1\r\n0 -1\r\n", "output": "0.000000000000000\r\n"}, {"input": "1 2\r\n0 -3\r\n0 -3\r\n", "output": "0.000000000000000\r\n"}, {"input": "7 1\r\n2 -3\r\n", "output": "-3.142857142857143\r\n"}, {"input": "3 2\r\n-1 -1\r\n-1 -1\r\n", "output": "-3.333333333333333\r\n"}, {"input": "5 1\r\n-1 -162\r\n", "output": "-195.400000000000006\r\n"}, {"input": "5 10\r\n-506 -243\r\n727 -141\r\n-548 -306\r\n740 880\r\n-744 -116\r\n-84 182\r\n-859 -108\r\n64 86\r\n135 446\r\n69 -184\r\n", "output": "864.399999999999977\r\n"}, {"input": "5 1\r\n0 -1\r\n", "output": "-1.200000000000000\r\n"}, {"input": "5 12\r\n634 895\r\n143 730\r\n901 245\r\n386 486\r\n395 -111\r\n-469 -104\r\n-681 -623\r\n-900 843\r\n889 -883\r\n476 -304\r\n777 986\r\n206 -491\r\n", "output": "8107.800000000000182\r\n"}, {"input": "3 3\r\n4 2\r\n5 0\r\n6 -1\r\n", "output": "16.333333333333332\r\n"}, {"input": "1 3\r\n4 2\r\n5 0\r\n6 -1\r\n", "output": "15.000000000000000\r\n"}, {"input": "85 10\r\n-223 435\r\n-771 455\r\n72 -940\r\n490 -178\r\n400 -117\r\n169 -527\r\n836 610\r\n849 944\r\n572 -237\r\n-428 -428\r\n", "output": "53047.388235294114565\r\n"}, {"input": "69 10\r\n-8 4\r\n-3 3\r\n7 5\r\n5 -9\r\n8 1\r\n7 -5\r\n-8 -8\r\n9 3\r\n1 1\r\n0 6\r\n", "output": "420.579710144927560\r\n"}, {"input": "1 10\r\n1 1\r\n1 0\r\n1 0\r\n1 0\r\n-1 0\r\n0 1\r\n1 0\r\n0 0\r\n2 1\r\n9 2\r\n", "output": "15.000000000000000\r\n"}, {"input": "5 4\r\n0 1\r\n0 2\r\n0 3\r\n0 -9\r\n", "output": "1.200000000000000\r\n"}]
| false |
stdio
|
import sys
import math
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(output_path) as f:
expected_line = f.readline().strip()
expected = float(expected_line)
with open(submission_path) as f:
submission_line = f.readline().strip()
try:
actual = float(submission_line)
except:
print(0)
return
abs_error = abs(expected - actual)
if abs_error <= 1e-6:
print(1)
return
if expected == 0 and actual == 0:
print(1)
return
max_abs = max(abs(expected), abs(actual))
if max_abs < 1e-9:
print(1)
return
rel_error = abs_error / max_abs
print(1 if rel_error <= 1e-6 else 0)
if __name__ == "__main__":
main()
| true |
1009/C
|
1009
|
C
|
Python 3
|
TESTS
| 38 | 327 | 0 |
40388197
|
from sys import stdin
from math import *
line = stdin.readline().rstrip().split()
n = int(line[0])
m = int(line[1])
bigNum = n*(n-1)/2
smallN = int(floor((n-1)/2))
bigN = (n-1) - smallN
smallNum = smallN*(smallN+1)/2
smallNum2 = bigN*(bigN+1)/2
total = 0
for i in range(m):
line = stdin.readline().rstrip().split()
x = int(line[0])
d = int(line[1])
total += x
if d < 0:
total += (smallNum*d + smallNum2*d)/n
else:
total += (bigNum*d)/n
print(total)
| 54 | 249 | 6,656,000 |
137936583
|
#OMM NAMH SHIVAY
#JAI SHREE RAM
import sys,math,heapq,queue
fast_input=sys.stdin.readline
n,m=map(int,fast_input().split())
s=0
r=(n+1)//2
r-=1
for _ in range(m):
x,d=map(int,fast_input().split())
s+=n*x
if d>=0:
s+=d*(n-1)*(n)//2
else:
s+=d*(r)*(r+1)
if n%2==0:
s+=(r+1)*d
print(s/n)
|
Educational Codeforces Round 47 (Rated for Div. 2)
|
ICPC
| 2,018 | 2 | 256 |
Annoying Present
|
Alice got an array of length $$$n$$$ as a birthday present once again! This is the third year in a row!
And what is more disappointing, it is overwhelmengly boring, filled entirely with zeros. Bob decided to apply some changes to the array to cheer up Alice.
Bob has chosen $$$m$$$ changes of the following form. For some integer numbers $$$x$$$ and $$$d$$$, he chooses an arbitrary position $$$i$$$ ($$$1 \le i \le n$$$) and for every $$$j \in [1, n]$$$ adds $$$x + d \cdot dist(i, j)$$$ to the value of the $$$j$$$-th cell. $$$dist(i, j)$$$ is the distance between positions $$$i$$$ and $$$j$$$ (i.e. $$$dist(i, j) = |i - j|$$$, where $$$|x|$$$ is an absolute value of $$$x$$$).
For example, if Alice currently has an array $$$[2, 1, 2, 2]$$$ and Bob chooses position $$$3$$$ for $$$x = -1$$$ and $$$d = 2$$$ then the array will become $$$[2 - 1 + 2 \cdot 2,~1 - 1 + 2 \cdot 1,~2 - 1 + 2 \cdot 0,~2 - 1 + 2 \cdot 1]$$$ = $$$[5, 2, 1, 3]$$$. Note that Bob can't choose position $$$i$$$ outside of the array (that is, smaller than $$$1$$$ or greater than $$$n$$$).
Alice will be the happiest when the elements of the array are as big as possible. Bob claimed that the arithmetic mean value of the elements will work fine as a metric.
What is the maximum arithmetic mean value Bob can achieve?
|
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^5$$$) — the number of elements of the array and the number of changes.
Each of the next $$$m$$$ lines contains two integers $$$x_i$$$ and $$$d_i$$$ ($$$-10^3 \le x_i, d_i \le 10^3$$$) — the parameters for the $$$i$$$-th change.
|
Print the maximal average arithmetic mean of the elements Bob can achieve.
Your answer is considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$.
| null | null |
[{"input": "2 3\n-1 3\n0 0\n-1 -4", "output": "-2.500000000000000"}, {"input": "3 2\n0 2\n5 0", "output": "7.000000000000000"}]
| 1,700 |
["greedy", "math"]
| 54 |
[{"input": "2 3\r\n-1 3\r\n0 0\r\n-1 -4\r\n", "output": "-2.500000000000000\r\n"}, {"input": "3 2\r\n0 2\r\n5 0\r\n", "output": "7.000000000000000\r\n"}, {"input": "8 8\r\n-21 -60\r\n-96 -10\r\n-4 -19\r\n-27 -4\r\n57 -15\r\n-95 62\r\n-42 1\r\n-17 64\r\n", "output": "-16.500000000000000\r\n"}, {"input": "1 1\r\n0 0\r\n", "output": "0.000000000000000\r\n"}, {"input": "100000 1\r\n1000 1000\r\n", "output": "50000500.000000000000000\r\n"}, {"input": "11 1\r\n0 -10\r\n", "output": "-27.272727272727273\r\n"}, {"input": "3 1\r\n1 -1\r\n", "output": "0.333333333333333\r\n"}, {"input": "1 2\r\n-1 -1\r\n-2 -2\r\n", "output": "-3.000000000000000\r\n"}, {"input": "1 2\r\n0 -1\r\n0 1\r\n", "output": "0.000000000000000\r\n"}, {"input": "1 1\r\n1 -2\r\n", "output": "1.000000000000000\r\n"}, {"input": "3 1\r\n2 -1\r\n", "output": "1.333333333333333\r\n"}, {"input": "3 1\r\n0 -1\r\n", "output": "-0.666666666666667\r\n"}, {"input": "1 1\r\n-1000 -1000\r\n", "output": "-1000.000000000000000\r\n"}, {"input": "1 1\r\n0 -5\r\n", "output": "0.000000000000000\r\n"}, {"input": "15 3\r\n2 0\r\n2 -5\r\n-2 5\r\n", "output": "18.333333333333332\r\n"}, {"input": "9 1\r\n0 -5\r\n", "output": "-11.111111111111111\r\n"}, {"input": "7 1\r\n0 -1\r\n", "output": "-1.714285714285714\r\n"}, {"input": "3 1\r\n-2 -2\r\n", "output": "-3.333333333333333\r\n"}, {"input": "3 1\r\n5 -5\r\n", "output": "1.666666666666667\r\n"}, {"input": "1 1\r\n-1 -1\r\n", "output": "-1.000000000000000\r\n"}, {"input": "7 1\r\n-1 -5\r\n", "output": "-9.571428571428571\r\n"}, {"input": "3 2\r\n-2 -2\r\n-2 -2\r\n", "output": "-6.666666666666667\r\n"}, {"input": "5 1\r\n0 -4\r\n", "output": "-4.800000000000000\r\n"}, {"input": "5 1\r\n-1 -5\r\n", "output": "-7.000000000000000\r\n"}, {"input": "5 1\r\n0 -2\r\n", "output": "-2.400000000000000\r\n"}, {"input": "3 5\r\n1 -1000\r\n1 -1000\r\n1 -1000\r\n1 -1000\r\n1 -1000\r\n", "output": "-3328.333333333333485\r\n"}, {"input": "1 1\r\n0 -1\r\n", "output": "0.000000000000000\r\n"}, {"input": "1 2\r\n0 -3\r\n0 -3\r\n", "output": "0.000000000000000\r\n"}, {"input": "7 1\r\n2 -3\r\n", "output": "-3.142857142857143\r\n"}, {"input": "3 2\r\n-1 -1\r\n-1 -1\r\n", "output": "-3.333333333333333\r\n"}, {"input": "5 1\r\n-1 -162\r\n", "output": "-195.400000000000006\r\n"}, {"input": "5 10\r\n-506 -243\r\n727 -141\r\n-548 -306\r\n740 880\r\n-744 -116\r\n-84 182\r\n-859 -108\r\n64 86\r\n135 446\r\n69 -184\r\n", "output": "864.399999999999977\r\n"}, {"input": "5 1\r\n0 -1\r\n", "output": "-1.200000000000000\r\n"}, {"input": "5 12\r\n634 895\r\n143 730\r\n901 245\r\n386 486\r\n395 -111\r\n-469 -104\r\n-681 -623\r\n-900 843\r\n889 -883\r\n476 -304\r\n777 986\r\n206 -491\r\n", "output": "8107.800000000000182\r\n"}, {"input": "3 3\r\n4 2\r\n5 0\r\n6 -1\r\n", "output": "16.333333333333332\r\n"}, {"input": "1 3\r\n4 2\r\n5 0\r\n6 -1\r\n", "output": "15.000000000000000\r\n"}, {"input": "85 10\r\n-223 435\r\n-771 455\r\n72 -940\r\n490 -178\r\n400 -117\r\n169 -527\r\n836 610\r\n849 944\r\n572 -237\r\n-428 -428\r\n", "output": "53047.388235294114565\r\n"}, {"input": "69 10\r\n-8 4\r\n-3 3\r\n7 5\r\n5 -9\r\n8 1\r\n7 -5\r\n-8 -8\r\n9 3\r\n1 1\r\n0 6\r\n", "output": "420.579710144927560\r\n"}, {"input": "1 10\r\n1 1\r\n1 0\r\n1 0\r\n1 0\r\n-1 0\r\n0 1\r\n1 0\r\n0 0\r\n2 1\r\n9 2\r\n", "output": "15.000000000000000\r\n"}, {"input": "5 4\r\n0 1\r\n0 2\r\n0 3\r\n0 -9\r\n", "output": "1.200000000000000\r\n"}]
| false |
stdio
|
import sys
import math
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(output_path) as f:
expected_line = f.readline().strip()
expected = float(expected_line)
with open(submission_path) as f:
submission_line = f.readline().strip()
try:
actual = float(submission_line)
except:
print(0)
return
abs_error = abs(expected - actual)
if abs_error <= 1e-6:
print(1)
return
if expected == 0 and actual == 0:
print(1)
return
max_abs = max(abs(expected), abs(actual))
if max_abs < 1e-9:
print(1)
return
rel_error = abs_error / max_abs
print(1 if rel_error <= 1e-6 else 0)
if __name__ == "__main__":
main()
| true |
1009/C
|
1009
|
C
|
Python 3
|
TESTS
| 38 | 327 | 307,200 |
78990446
|
n, changes = map(int, input().split())
answer = 0
def summation(n):
return ((n - 1) * (n)) / 2
def negative_summation(n):
if n % 2 == 1:
weigth = summation(n // 2 + 1) * 2
else:
weigth = (summation((n // 2 + 1) - 1) * 2) + n // 2
return weigth
negative_impact = negative_summation(n)
positive_impact = summation(n)
for change in range(changes):
x, impact = map(int, input().split())
answer += x * n
if impact > 0:
answer += impact * positive_impact
else:
answer += impact * negative_impact
print(answer/n)
| 54 | 265 | 5,222,400 |
71522430
|
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
S = 0
for _ in range(m):
x, d = map(int, input().split())
S += n*x
if d>=0:
S += n*(n-1)//2*d
else:
m = n//2
S += 2*(m+1)*m//2*d
if n%2==0:
S -= m*d
print(S/n)
|
Educational Codeforces Round 47 (Rated for Div. 2)
|
ICPC
| 2,018 | 2 | 256 |
Annoying Present
|
Alice got an array of length $$$n$$$ as a birthday present once again! This is the third year in a row!
And what is more disappointing, it is overwhelmengly boring, filled entirely with zeros. Bob decided to apply some changes to the array to cheer up Alice.
Bob has chosen $$$m$$$ changes of the following form. For some integer numbers $$$x$$$ and $$$d$$$, he chooses an arbitrary position $$$i$$$ ($$$1 \le i \le n$$$) and for every $$$j \in [1, n]$$$ adds $$$x + d \cdot dist(i, j)$$$ to the value of the $$$j$$$-th cell. $$$dist(i, j)$$$ is the distance between positions $$$i$$$ and $$$j$$$ (i.e. $$$dist(i, j) = |i - j|$$$, where $$$|x|$$$ is an absolute value of $$$x$$$).
For example, if Alice currently has an array $$$[2, 1, 2, 2]$$$ and Bob chooses position $$$3$$$ for $$$x = -1$$$ and $$$d = 2$$$ then the array will become $$$[2 - 1 + 2 \cdot 2,~1 - 1 + 2 \cdot 1,~2 - 1 + 2 \cdot 0,~2 - 1 + 2 \cdot 1]$$$ = $$$[5, 2, 1, 3]$$$. Note that Bob can't choose position $$$i$$$ outside of the array (that is, smaller than $$$1$$$ or greater than $$$n$$$).
Alice will be the happiest when the elements of the array are as big as possible. Bob claimed that the arithmetic mean value of the elements will work fine as a metric.
What is the maximum arithmetic mean value Bob can achieve?
|
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^5$$$) — the number of elements of the array and the number of changes.
Each of the next $$$m$$$ lines contains two integers $$$x_i$$$ and $$$d_i$$$ ($$$-10^3 \le x_i, d_i \le 10^3$$$) — the parameters for the $$$i$$$-th change.
|
Print the maximal average arithmetic mean of the elements Bob can achieve.
Your answer is considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$.
| null | null |
[{"input": "2 3\n-1 3\n0 0\n-1 -4", "output": "-2.500000000000000"}, {"input": "3 2\n0 2\n5 0", "output": "7.000000000000000"}]
| 1,700 |
["greedy", "math"]
| 54 |
[{"input": "2 3\r\n-1 3\r\n0 0\r\n-1 -4\r\n", "output": "-2.500000000000000\r\n"}, {"input": "3 2\r\n0 2\r\n5 0\r\n", "output": "7.000000000000000\r\n"}, {"input": "8 8\r\n-21 -60\r\n-96 -10\r\n-4 -19\r\n-27 -4\r\n57 -15\r\n-95 62\r\n-42 1\r\n-17 64\r\n", "output": "-16.500000000000000\r\n"}, {"input": "1 1\r\n0 0\r\n", "output": "0.000000000000000\r\n"}, {"input": "100000 1\r\n1000 1000\r\n", "output": "50000500.000000000000000\r\n"}, {"input": "11 1\r\n0 -10\r\n", "output": "-27.272727272727273\r\n"}, {"input": "3 1\r\n1 -1\r\n", "output": "0.333333333333333\r\n"}, {"input": "1 2\r\n-1 -1\r\n-2 -2\r\n", "output": "-3.000000000000000\r\n"}, {"input": "1 2\r\n0 -1\r\n0 1\r\n", "output": "0.000000000000000\r\n"}, {"input": "1 1\r\n1 -2\r\n", "output": "1.000000000000000\r\n"}, {"input": "3 1\r\n2 -1\r\n", "output": "1.333333333333333\r\n"}, {"input": "3 1\r\n0 -1\r\n", "output": "-0.666666666666667\r\n"}, {"input": "1 1\r\n-1000 -1000\r\n", "output": "-1000.000000000000000\r\n"}, {"input": "1 1\r\n0 -5\r\n", "output": "0.000000000000000\r\n"}, {"input": "15 3\r\n2 0\r\n2 -5\r\n-2 5\r\n", "output": "18.333333333333332\r\n"}, {"input": "9 1\r\n0 -5\r\n", "output": "-11.111111111111111\r\n"}, {"input": "7 1\r\n0 -1\r\n", "output": "-1.714285714285714\r\n"}, {"input": "3 1\r\n-2 -2\r\n", "output": "-3.333333333333333\r\n"}, {"input": "3 1\r\n5 -5\r\n", "output": "1.666666666666667\r\n"}, {"input": "1 1\r\n-1 -1\r\n", "output": "-1.000000000000000\r\n"}, {"input": "7 1\r\n-1 -5\r\n", "output": "-9.571428571428571\r\n"}, {"input": "3 2\r\n-2 -2\r\n-2 -2\r\n", "output": "-6.666666666666667\r\n"}, {"input": "5 1\r\n0 -4\r\n", "output": "-4.800000000000000\r\n"}, {"input": "5 1\r\n-1 -5\r\n", "output": "-7.000000000000000\r\n"}, {"input": "5 1\r\n0 -2\r\n", "output": "-2.400000000000000\r\n"}, {"input": "3 5\r\n1 -1000\r\n1 -1000\r\n1 -1000\r\n1 -1000\r\n1 -1000\r\n", "output": "-3328.333333333333485\r\n"}, {"input": "1 1\r\n0 -1\r\n", "output": "0.000000000000000\r\n"}, {"input": "1 2\r\n0 -3\r\n0 -3\r\n", "output": "0.000000000000000\r\n"}, {"input": "7 1\r\n2 -3\r\n", "output": "-3.142857142857143\r\n"}, {"input": "3 2\r\n-1 -1\r\n-1 -1\r\n", "output": "-3.333333333333333\r\n"}, {"input": "5 1\r\n-1 -162\r\n", "output": "-195.400000000000006\r\n"}, {"input": "5 10\r\n-506 -243\r\n727 -141\r\n-548 -306\r\n740 880\r\n-744 -116\r\n-84 182\r\n-859 -108\r\n64 86\r\n135 446\r\n69 -184\r\n", "output": "864.399999999999977\r\n"}, {"input": "5 1\r\n0 -1\r\n", "output": "-1.200000000000000\r\n"}, {"input": "5 12\r\n634 895\r\n143 730\r\n901 245\r\n386 486\r\n395 -111\r\n-469 -104\r\n-681 -623\r\n-900 843\r\n889 -883\r\n476 -304\r\n777 986\r\n206 -491\r\n", "output": "8107.800000000000182\r\n"}, {"input": "3 3\r\n4 2\r\n5 0\r\n6 -1\r\n", "output": "16.333333333333332\r\n"}, {"input": "1 3\r\n4 2\r\n5 0\r\n6 -1\r\n", "output": "15.000000000000000\r\n"}, {"input": "85 10\r\n-223 435\r\n-771 455\r\n72 -940\r\n490 -178\r\n400 -117\r\n169 -527\r\n836 610\r\n849 944\r\n572 -237\r\n-428 -428\r\n", "output": "53047.388235294114565\r\n"}, {"input": "69 10\r\n-8 4\r\n-3 3\r\n7 5\r\n5 -9\r\n8 1\r\n7 -5\r\n-8 -8\r\n9 3\r\n1 1\r\n0 6\r\n", "output": "420.579710144927560\r\n"}, {"input": "1 10\r\n1 1\r\n1 0\r\n1 0\r\n1 0\r\n-1 0\r\n0 1\r\n1 0\r\n0 0\r\n2 1\r\n9 2\r\n", "output": "15.000000000000000\r\n"}, {"input": "5 4\r\n0 1\r\n0 2\r\n0 3\r\n0 -9\r\n", "output": "1.200000000000000\r\n"}]
| false |
stdio
|
import sys
import math
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(output_path) as f:
expected_line = f.readline().strip()
expected = float(expected_line)
with open(submission_path) as f:
submission_line = f.readline().strip()
try:
actual = float(submission_line)
except:
print(0)
return
abs_error = abs(expected - actual)
if abs_error <= 1e-6:
print(1)
return
if expected == 0 and actual == 0:
print(1)
return
max_abs = max(abs(expected), abs(actual))
if max_abs < 1e-9:
print(1)
return
rel_error = abs_error / max_abs
print(1 if rel_error <= 1e-6 else 0)
if __name__ == "__main__":
main()
| true |
1009/C
|
1009
|
C
|
Python 3
|
TESTS
| 38 | 358 | 2,867,200 |
46817779
|
n, m = map(int, input().split())
mean = 0
mi = sum([abs(n // 2 - j) for j in range(n)])
ma = (n * (n - 1)) // 2
for i in range(m):
x, d = map(int, input().split())
mean += x
if d < 0:mean += (d * mi) / n
else: mean += (d * ma) / n
print('%.15f' % mean)
| 54 | 265 | 6,144,000 |
121144475
|
from sys import stdin,stdout
from math import gcd,sqrt,factorial,pi,inf
from collections import deque,defaultdict
from bisect import bisect,bisect_left
from time import time
from itertools import permutations as per
from heapq import heapify,heappush,heappop,heappushpop
input=stdin.readline
R=lambda:map(int,input().split())
I=lambda:int(input())
S=lambda:input().rstrip('\r\n')
L=lambda:list(R())
P=lambda x:stdout.write(str(x)+'\n')
lcm=lambda x,y:(x*y)//gcd(x,y)
nCr=lambda x,y:(f[x]*inv((f[y]*f[x-y])%N))%N
inv=lambda x:pow(x,N-2,N)
sm=lambda x:(x**2+x)//2
N=10**9+7
n,k=R()
s=0
for i in range(k):
x,d=R()
s+=n*x
if d<0:
s+=sm(n//2)*d+sm(n//2-(n+1)%2)*d
else:
s+=sm(n-1)*d
print(s/n)
|
Educational Codeforces Round 47 (Rated for Div. 2)
|
ICPC
| 2,018 | 2 | 256 |
Annoying Present
|
Alice got an array of length $$$n$$$ as a birthday present once again! This is the third year in a row!
And what is more disappointing, it is overwhelmengly boring, filled entirely with zeros. Bob decided to apply some changes to the array to cheer up Alice.
Bob has chosen $$$m$$$ changes of the following form. For some integer numbers $$$x$$$ and $$$d$$$, he chooses an arbitrary position $$$i$$$ ($$$1 \le i \le n$$$) and for every $$$j \in [1, n]$$$ adds $$$x + d \cdot dist(i, j)$$$ to the value of the $$$j$$$-th cell. $$$dist(i, j)$$$ is the distance between positions $$$i$$$ and $$$j$$$ (i.e. $$$dist(i, j) = |i - j|$$$, where $$$|x|$$$ is an absolute value of $$$x$$$).
For example, if Alice currently has an array $$$[2, 1, 2, 2]$$$ and Bob chooses position $$$3$$$ for $$$x = -1$$$ and $$$d = 2$$$ then the array will become $$$[2 - 1 + 2 \cdot 2,~1 - 1 + 2 \cdot 1,~2 - 1 + 2 \cdot 0,~2 - 1 + 2 \cdot 1]$$$ = $$$[5, 2, 1, 3]$$$. Note that Bob can't choose position $$$i$$$ outside of the array (that is, smaller than $$$1$$$ or greater than $$$n$$$).
Alice will be the happiest when the elements of the array are as big as possible. Bob claimed that the arithmetic mean value of the elements will work fine as a metric.
What is the maximum arithmetic mean value Bob can achieve?
|
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^5$$$) — the number of elements of the array and the number of changes.
Each of the next $$$m$$$ lines contains two integers $$$x_i$$$ and $$$d_i$$$ ($$$-10^3 \le x_i, d_i \le 10^3$$$) — the parameters for the $$$i$$$-th change.
|
Print the maximal average arithmetic mean of the elements Bob can achieve.
Your answer is considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$.
| null | null |
[{"input": "2 3\n-1 3\n0 0\n-1 -4", "output": "-2.500000000000000"}, {"input": "3 2\n0 2\n5 0", "output": "7.000000000000000"}]
| 1,700 |
["greedy", "math"]
| 54 |
[{"input": "2 3\r\n-1 3\r\n0 0\r\n-1 -4\r\n", "output": "-2.500000000000000\r\n"}, {"input": "3 2\r\n0 2\r\n5 0\r\n", "output": "7.000000000000000\r\n"}, {"input": "8 8\r\n-21 -60\r\n-96 -10\r\n-4 -19\r\n-27 -4\r\n57 -15\r\n-95 62\r\n-42 1\r\n-17 64\r\n", "output": "-16.500000000000000\r\n"}, {"input": "1 1\r\n0 0\r\n", "output": "0.000000000000000\r\n"}, {"input": "100000 1\r\n1000 1000\r\n", "output": "50000500.000000000000000\r\n"}, {"input": "11 1\r\n0 -10\r\n", "output": "-27.272727272727273\r\n"}, {"input": "3 1\r\n1 -1\r\n", "output": "0.333333333333333\r\n"}, {"input": "1 2\r\n-1 -1\r\n-2 -2\r\n", "output": "-3.000000000000000\r\n"}, {"input": "1 2\r\n0 -1\r\n0 1\r\n", "output": "0.000000000000000\r\n"}, {"input": "1 1\r\n1 -2\r\n", "output": "1.000000000000000\r\n"}, {"input": "3 1\r\n2 -1\r\n", "output": "1.333333333333333\r\n"}, {"input": "3 1\r\n0 -1\r\n", "output": "-0.666666666666667\r\n"}, {"input": "1 1\r\n-1000 -1000\r\n", "output": "-1000.000000000000000\r\n"}, {"input": "1 1\r\n0 -5\r\n", "output": "0.000000000000000\r\n"}, {"input": "15 3\r\n2 0\r\n2 -5\r\n-2 5\r\n", "output": "18.333333333333332\r\n"}, {"input": "9 1\r\n0 -5\r\n", "output": "-11.111111111111111\r\n"}, {"input": "7 1\r\n0 -1\r\n", "output": "-1.714285714285714\r\n"}, {"input": "3 1\r\n-2 -2\r\n", "output": "-3.333333333333333\r\n"}, {"input": "3 1\r\n5 -5\r\n", "output": "1.666666666666667\r\n"}, {"input": "1 1\r\n-1 -1\r\n", "output": "-1.000000000000000\r\n"}, {"input": "7 1\r\n-1 -5\r\n", "output": "-9.571428571428571\r\n"}, {"input": "3 2\r\n-2 -2\r\n-2 -2\r\n", "output": "-6.666666666666667\r\n"}, {"input": "5 1\r\n0 -4\r\n", "output": "-4.800000000000000\r\n"}, {"input": "5 1\r\n-1 -5\r\n", "output": "-7.000000000000000\r\n"}, {"input": "5 1\r\n0 -2\r\n", "output": "-2.400000000000000\r\n"}, {"input": "3 5\r\n1 -1000\r\n1 -1000\r\n1 -1000\r\n1 -1000\r\n1 -1000\r\n", "output": "-3328.333333333333485\r\n"}, {"input": "1 1\r\n0 -1\r\n", "output": "0.000000000000000\r\n"}, {"input": "1 2\r\n0 -3\r\n0 -3\r\n", "output": "0.000000000000000\r\n"}, {"input": "7 1\r\n2 -3\r\n", "output": "-3.142857142857143\r\n"}, {"input": "3 2\r\n-1 -1\r\n-1 -1\r\n", "output": "-3.333333333333333\r\n"}, {"input": "5 1\r\n-1 -162\r\n", "output": "-195.400000000000006\r\n"}, {"input": "5 10\r\n-506 -243\r\n727 -141\r\n-548 -306\r\n740 880\r\n-744 -116\r\n-84 182\r\n-859 -108\r\n64 86\r\n135 446\r\n69 -184\r\n", "output": "864.399999999999977\r\n"}, {"input": "5 1\r\n0 -1\r\n", "output": "-1.200000000000000\r\n"}, {"input": "5 12\r\n634 895\r\n143 730\r\n901 245\r\n386 486\r\n395 -111\r\n-469 -104\r\n-681 -623\r\n-900 843\r\n889 -883\r\n476 -304\r\n777 986\r\n206 -491\r\n", "output": "8107.800000000000182\r\n"}, {"input": "3 3\r\n4 2\r\n5 0\r\n6 -1\r\n", "output": "16.333333333333332\r\n"}, {"input": "1 3\r\n4 2\r\n5 0\r\n6 -1\r\n", "output": "15.000000000000000\r\n"}, {"input": "85 10\r\n-223 435\r\n-771 455\r\n72 -940\r\n490 -178\r\n400 -117\r\n169 -527\r\n836 610\r\n849 944\r\n572 -237\r\n-428 -428\r\n", "output": "53047.388235294114565\r\n"}, {"input": "69 10\r\n-8 4\r\n-3 3\r\n7 5\r\n5 -9\r\n8 1\r\n7 -5\r\n-8 -8\r\n9 3\r\n1 1\r\n0 6\r\n", "output": "420.579710144927560\r\n"}, {"input": "1 10\r\n1 1\r\n1 0\r\n1 0\r\n1 0\r\n-1 0\r\n0 1\r\n1 0\r\n0 0\r\n2 1\r\n9 2\r\n", "output": "15.000000000000000\r\n"}, {"input": "5 4\r\n0 1\r\n0 2\r\n0 3\r\n0 -9\r\n", "output": "1.200000000000000\r\n"}]
| false |
stdio
|
import sys
import math
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(output_path) as f:
expected_line = f.readline().strip()
expected = float(expected_line)
with open(submission_path) as f:
submission_line = f.readline().strip()
try:
actual = float(submission_line)
except:
print(0)
return
abs_error = abs(expected - actual)
if abs_error <= 1e-6:
print(1)
return
if expected == 0 and actual == 0:
print(1)
return
max_abs = max(abs(expected), abs(actual))
if max_abs < 1e-9:
print(1)
return
rel_error = abs_error / max_abs
print(1 if rel_error <= 1e-6 else 0)
if __name__ == "__main__":
main()
| true |
623/C
|
623
|
C
|
PyPy 3-64
|
TESTS
| 1 | 108 | 9,420,800 |
164070867
|
from sys import stdin, stdout, maxsize
from typing import List
def sdiameter_axes(axis_one, axes_two):
return int(pow(axis_one-axes_two, 2))
def sdiameter_xy(x, y):
return int(pow(x, 2))+int(pow(y, 2))
prefix_max_y = None
sufix_max_y = None
prefix_min_y =None
sufix_min_y = None
def check(D, n, points):
global prefix_max_y, prefix_min_y, sufix_max_y, sufix_min_y
if D >= sdiameter_axes(points[0][0], points[-1][0]):
return True
limit_right = 0
for limit_left in range(n):
while limit_right < n-1 and sdiameter_axes(points[limit_left][0], points[limit_right+1][0])<= D and abs(points[limit_left][0])>=abs(points[limit_right+1][0]):
limit_right+=1
while abs(points[limit_left][0])<abs(points[limit_right][0]):
limit_right-=1
y_min = int(1e8+1)
y_max = -int(1e8+1)
if limit_left > 0:
y_min = prefix_min_y[limit_left-1]
y_max = prefix_max_y[limit_left-1]
if limit_right < n-1:
y_min = min(y_min, sufix_min_y[limit_right+1])
y_max = max(y_max, sufix_max_y[limit_right+1])
d1 = sdiameter_axes(y_min, y_max)
d2 = max(sdiameter_xy(points[limit_left][0], y_min), sdiameter_xy(points[limit_left][0], y_max))
if max(d1,d2) <= D:
return True
limit_left = n-1
for limit_right in range(n-1,-1,-1):
while limit_left > 0 and sdiameter_axes(points[limit_left-1][0], points[limit_right][0])<= D and abs(points[limit_left-1][0])<=abs(points[limit_right][0]):
limit_left-=1
while abs( points[limit_left][0])>abs(points[limit_right][0]):
limit_left+=1
y_min = int(1e8+1)
y_max = -int(1e8+1)
if limit_left > 0:
y_min = prefix_min_y[limit_left-1]
y_max = prefix_max_y[limit_left-1]
if limit_right < n-1:
y_min = min(y_min, sufix_min_y[limit_right+1])
y_max = max(y_max, sufix_max_y[limit_right+1])
d1 = sdiameter_axes(y_min, y_max)
d2 = max(sdiameter_xy(limit_right, y_min), sdiameter_xy(limit_right, y_max))
if max(d1,d2) <= D:
return True
return False
def solution(n:int, points:List):
if n==1:
return 0
global prefix_max_y, prefix_min_y, sufix_max_y, sufix_min_y
prefix_max_y, sufix_max_y = [0]*n, [0]*n
prefix_min_y, sufix_min_y = [0]*n, [0]*n
points.sort(key= lambda t: t[0])
prefix_max_y[0], sufix_max_y[-1] = points[0][1], points[-1][1]
prefix_min_y[0], sufix_min_y[-1] = points[0][1], points[-1][1]
for i in range(1, n):
prefix_max_y[i] = max(points[i][1], prefix_max_y[i-1])
prefix_min_y[i] = min(points[i][1], prefix_min_y[i-1])
for i in range(n-2,-1,-1):
sufix_max_y[i] = max(points[i][1], sufix_max_y[i+1])
sufix_min_y[i] = min(points[i][1], sufix_min_y[i+1])
max_sd = min(sdiameter_axes(points[0][0], points[-1][0]),sdiameter_axes(prefix_min_y[-1], prefix_max_y[-1]))
min_sd = max_sd
left, right = 0, max_sd
while( left <= right):
D = (left + right)//2
if check(D, n, points):
min_sd = D
right = D-1
else:
left = D+1
return min_sd
if __name__ == "__main__":
n = int(stdin.readline())
in_points = []
for _ in range(n):
x, y = map(int, stdin.readline().split())
in_points.append((x,y))
min_sd = solution(n, in_points)
stdout.write(str(min_sd))
| 176 | 1,450 | 23,449,600 |
164355894
|
from sys import stdin, stdout, maxsize
from typing import List
def sdiameter_axes(axis_one, axes_two):
"""calcula el diametro**2 entre elementos de un mismo eje"""
return int(pow(axis_one-axes_two, 2))
def sdiameter_xy(x, y):
"""calcula el diametro**2 entre elementos de ambos ejes"""
return int(pow(x, 2))+int(pow(y, 2))
prefix_max_y = None
sufix_max_y = None
prefix_min_y =None
sufix_min_y = None
def check(D, n, points):
global prefix_max_y, prefix_min_y, sufix_max_y, sufix_min_y
limit_right = 1
for limit_left in range(1,n+1):
while limit_right < n and sdiameter_axes(points[limit_left][0], points[limit_right+1][0])<= D and abs(points[limit_left][0])>=abs(points[limit_right+1][0]):
limit_right+=1
while abs(points[limit_left][0])<abs(points[limit_right][0]):
limit_right-=1
y_min = min(prefix_min_y[limit_left-1], sufix_min_y[limit_right+1])
y_max = max(prefix_max_y[limit_left-1], sufix_max_y[limit_right+1])
d1 = sdiameter_axes(y_min, y_max)
d2 = max(sdiameter_xy(points[limit_left][0], y_min), sdiameter_xy(points[limit_left][0], y_max))
if max(d1,d2) <= D:
return True
limit_left = n
for limit_right in range(n,0,-1):
while limit_left > 1 and sdiameter_axes(points[limit_left-1][0], points[limit_right][0])<= D and abs(points[limit_left-1][0])<=abs(points[limit_right][0]):
limit_left-=1
while abs( points[limit_left][0])>abs(points[limit_right][0]):
limit_left+=1
y_min = min(prefix_min_y[limit_left-1], sufix_min_y[limit_right+1])
y_max = max(prefix_max_y[limit_left-1], sufix_max_y[limit_right+1])
d1 = sdiameter_axes(y_min, y_max)
d2 = max(sdiameter_xy(points[limit_right][0], y_min), sdiameter_xy(points[limit_right][0], y_max))
if max(d1,d2) <= D:
return True
return False
def tp_solution(n:int, points:List):
if n==1:
return 0
# creo los arreglos para computar los maximos y minimos de las <y> por sufijos y prefijos
# todo sobre el conjunto de puntos ordenados por las x
# prefix_max_y[i] es la max <y> en el [0-i]
# prefix_min_y[i] es la min <y> en el [0-1]
# sufix_max_y[i] es la max <y> en el [i-n)
# sufix_min_y[i] es la min <y> en el [i-n)
global prefix_max_y, prefix_min_y, sufix_max_y, sufix_min_y
prefix_max_y, sufix_max_y = [0]*(n+2), [0]*(n+2)
prefix_min_y, sufix_min_y = [0]*(n+2), [0]*(n+2)
points.sort(key= lambda t: t[0])
points.insert(0,None)
prefix_max_y[0], sufix_max_y[-1] = -int(1e8 + 1), -int(1e8 + 1)
prefix_min_y[0], sufix_min_y[-1] = int(1e8 + 1), int(1e8 + 1)
for i in range(1, n+1):
prefix_max_y[i] = max(points[i][1], prefix_max_y[i-1])
prefix_min_y[i] = min(points[i][1], prefix_min_y[i-1])
for i in range(n,0,-1):
sufix_max_y[i] = max(points[i][1], sufix_max_y[i+1])
sufix_min_y[i] = min(points[i][1], sufix_min_y[i+1])
#min_sd diametro**2, guarda el menor diametro resultante de mover todos los puntos a uno de los ejes respectivamente.
#la respuesta optima tiene que estar acotada por el minimo de los d**2 resultantes de proyectar en uno de los ejes todos los puntos
min_sd = min(sdiameter_axes(points[1][0], points[-1][0]),sdiameter_axes(prefix_min_y[-2], prefix_max_y[-2]))
left, right = 0, min_sd
while( left <= right):
D = (left + right)//2
if check(D, n, points):
min_sd = D #sabemos que el ultimo si sera la solucion
right = D-1
else:
left = D+1
return min_sd
if __name__ == "__main__":
n = int(stdin.readline())
in_points = []
for _ in range(n):
x, y = map(int, stdin.readline().split())
in_points.append((x,y))
min_sd = tp_solution(n, in_points)
stdout.write(str(min_sd))
|
AIM Tech Round (Div. 1)
|
CF
| 2,016 | 2 | 256 |
Electric Charges
|
Programmer Sasha is a student at MIPT (Moscow Institute of Physics and Technology) and he needs to make a laboratory work to pass his finals.
A laboratory unit is a plane with standard coordinate axes marked on it. Physicists from Moscow Institute of Physics and Technology charged the axes by large electric charges: axis X is positive and axis Y is negative.
Experienced laboratory worker marked n points with integer coordinates (xi, yi) on the plane and stopped the time. Sasha should use "atomic tweezers" to place elementary particles in these points. He has an unlimited number of electrons (negatively charged elementary particles) and protons (positively charged elementary particles). He can put either an electron or a proton at each marked point. As soon as all marked points are filled with particles, laboratory worker will turn on the time again and the particles will come in motion and after some time they will stabilize in equilibrium. The objective of the laboratory work is to arrange the particles in such a way, that the diameter of the resulting state (the maximum distance between the pairs of points of the set) is as small as possible.
Since Sasha is a programmer, he naively thinks that all the particles will simply "fall" into their projections on the corresponding axes: electrons will fall on axis X, while protons will fall on axis Y. As we are programmers too, we will consider the same model as Sasha. That is, a particle gets from point (x, y) to point (x, 0) if it is an electron and to point (0, y) if it is a proton.
As the laboratory has high background radiation and Sasha takes care of his laptop, he did not take it with him, and now he can't write a program that computes the minimum possible diameter of the resulting set. Therefore, you will have to do it for him.
Print a square of the minimum possible diameter of the set.
|
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of points marked on the plane.
Each of the next n lines contains two integers xi and yi ( - 108 ≤ xi, yi ≤ 108) — the coordinates of the i-th point. It is guaranteed that no two points coincide.
|
Print a single integer — the square of the minimum possible diameter of the set.
| null |
In the first sample Sasha puts electrons at all points, all particles eventually fall at a single point (1, 0).
In the second sample Sasha puts an electron at point (1, 10), and a proton at point (10, 1). The result is a set of two points (1, 0) and (0, 1), which has a diameter of $$\sqrt{2}$$.
|
[{"input": "3\n1 10\n1 20\n1 30", "output": "0"}, {"input": "2\n1 10\n10 1", "output": "2"}]
| 2,900 |
["binary search", "dp"]
| 176 |
[{"input": "3\r\n1 10\r\n1 20\r\n1 30\r\n", "output": "0\r\n"}, {"input": "2\r\n1 10\r\n10 1\r\n", "output": "2\r\n"}, {"input": "10\r\n1 6\r\n2 2\r\n-1 9\r\n-8 8\r\n-4 10\r\n-10 -6\r\n5 -1\r\n-3 -7\r\n-4 3\r\n9 4\r\n", "output": "100\r\n"}, {"input": "18\r\n-14 -745\r\n87 -4611\r\n89 -3748\r\n-77 273\r\n-21 -4654\r\n-86 -5108\r\n-70 3232\r\n25 -6313\r\n-71 -4846\r\n88 -1894\r\n-65 9707\r\n-51 -3290\r\n-19 -580\r\n-62 -2408\r\n1 -6832\r\n52 -4279\r\n21 -7322\r\n55 9392\r\n", "output": "30625\r\n"}, {"input": "12\r\n996 -72\r\n-145 68\r\n-514 79\r\n743 -96\r\n765 -52\r\n720 86\r\n-615 -57\r\n690 81\r\n-885 -5\r\n265 4\r\n-533 -23\r\n-693 -72\r\n", "output": "33124\r\n"}, {"input": "17\r\n-10 -36\r\n1 -10\r\n53 -2\r\n-23 5\r\n7 -19\r\n10 -33\r\n9 78\r\n-7 -3\r\n70 2\r\n5 -1\r\n7 -93\r\n9 -2\r\n2 -82\r\n16 2\r\n8 48\r\n52 2\r\n-76 -6\r\n", "output": "400\r\n"}, {"input": "16\r\n22 -370\r\n90 -8\r\n46 235\r\n336 51\r\n-447 5\r\n-105 -53\r\n212 87\r\n245 -90\r\n7 -63\r\n-44 -56\r\n-426 2\r\n-485 26\r\n-31 37\r\n-93 -410\r\n39 -108\r\n-202 -85\r\n", "output": "31329\r\n"}, {"input": "20\r\n857 286\r\n-653 -1302\r\n761 1685\r\n-783 -94\r\n208 -1381\r\n-229 -1333\r\n664 -296\r\n-1157 -189\r\n-2124 956\r\n837 -2086\r\n-1872 16\r\n474 797\r\n-984 -1224\r\n188 -1104\r\n2017 850\r\n-2211 222\r\n955 -2275\r\n-100 1708\r\n152 199\r\n-1340 -462\r\n", "output": "3759721\r\n"}, {"input": "10\r\n-594331 634748\r\n-438198 823828\r\n-1450064 -200132\r\n-832505 -718261\r\n-830561 867133\r\n1104363 -90870\r\n696748 -925127\r\n-755002 -110409\r\n-1721605 -870036\r\n344418 -761993\r\n", "output": "1545691540850\r\n"}, {"input": "14\r\n17434000 -29825809\r\n3349481 -27203247\r\n79083185 21513757\r\n-53052180 -83100420\r\n543299 -43187896\r\n-30785780 18551223\r\n9271044 -77707401\r\n65259560 -30266930\r\n-65672492 -20223080\r\n-37161541 -4703585\r\n99525015 2119039\r\n-13413357 -52673928\r\n83407206 -6063556\r\n3333364 -56550616\r\n", "output": "3884184249754176\r\n"}, {"input": "14\r\n3 44\r\n-99 -1\r\n-11 -9\r\n3 -57\r\n83 5\r\n4 -45\r\n4 -62\r\n46 -4\r\n36 6\r\n3 -22\r\n-69 -2\r\n3 75\r\n-3 -37\r\n46 -8\r\n", "output": "225\r\n"}, {"input": "19\r\n174 17\r\n-65 458\r\n460 -6\r\n141 8\r\n53 -441\r\n-71 -1\r\n415 -3\r\n46 -337\r\n-4 319\r\n307 -17\r\n-84 208\r\n-428 5\r\n-91 336\r\n-301 -12\r\n40 -5\r\n218 -13\r\n423 8\r\n-110 -6\r\n-24 -20\r\n", "output": "20736\r\n"}, {"input": "1\r\n42 100000000\r\n", "output": "0\r\n"}, {"input": "2\r\n-100000000 100000000\r\n1 -35\r\n", "output": "10000000000000001\r\n"}, {"input": "4\r\n100000000 100000000\r\n100000000 -100000000\r\n-100000000 100000000\r\n-100000000 -100000000\r\n", "output": "40000000000000000\r\n"}, {"input": "5\r\n25367999 -12921025\r\n88213873 -62251536\r\n29698878 -60793556\r\n69696879 -57681615\r\n4150867 -42378134\r\n", "output": "2433499315521121\r\n"}, {"input": "10\r\n52725948 -50921428\r\n22965991 -854605\r\n19081182 -54959209\r\n46359108 -78898591\r\n12280123 -98335714\r\n96326175 -61967241\r\n36354396 -64148342\r\n8164394 -70121916\r\n94434246 -46350207\r\n6706998 -57888515\r\n", "output": "5989105851707745\r\n"}, {"input": "10\r\n6 -50790171\r\n-2 218761\r\n-1 6364807\r\n-5 -96100004\r\n6 13672536\r\n-31685933 2\r\n-87361182 6\r\n6 79979970\r\n-4 20223120\r\n3 -33646313\r\n", "output": "121\r\n"}, {"input": "20\r\n544 -4618768\r\n8229332 791\r\n-19838403 912\r\n714 81730211\r\n685 86922721\r\n976 74377764\r\n691 -75144278\r\n767 -14551029\r\n592 52209892\r\n868 -16289108\r\n652 44552695\r\n963 -60723986\r\n-98704842 668\r\n900 28147242\r\n49913319 735\r\n534 -69309373\r\n841 -1918555\r\n571 -70059713\r\n821 -70358434\r\n605 81860132\r\n", "output": "1784320\r\n"}, {"input": "9\r\n-99999999 -99999999\r\n-99999999 -100000000\r\n99999999 99999999\r\n100000000 -99999999\r\n-99999999 100000000\r\n-100000000 100000000\r\n-99999999 99999999\r\n99999999 100000000\r\n99999999 -99999999\r\n", "output": "39999999600000001\r\n"}, {"input": "1\r\n100000000 100000000\r\n", "output": "0\r\n"}, {"input": "2\r\n100000000 100000000\r\n100000000 -100000000\r\n", "output": "0\r\n"}, {"input": "2\r\n-100000000 100000000\r\n100000000 100000000\r\n", "output": "0\r\n"}, {"input": "4\r\n100000000 -100000000\r\n-100000000 -100000000\r\n100000000 100000000\r\n-100000000 100000000\r\n", "output": "40000000000000000\r\n"}, {"input": "5\r\n46954043 53045957\r\n86519258 13480742\r\n12941533 87058467\r\n53212386 46787614\r\n57186237 42813763\r\n", "output": "2981356830435938\r\n"}, {"input": "5\r\n635720 157\r\n702516 142\r\n286757 348\r\n756308 132\r\n751562 133\r\n", "output": "46656\r\n"}, {"input": "5\r\n99857497 5336678\r\n78010540 62564811\r\n51604294 85656271\r\n88779790 46023350\r\n99288757 11905571\r\n", "output": "2328371599759209\r\n"}, {"input": "10\r\n-88884243 11115757\r\n-38391053 61608947\r\n-67774598 32225402\r\n-62658046 37341954\r\n-32014021 67985979\r\n-49601142 50398858\r\n-13046283 86953717\r\n-91869075 8130925\r\n-85955759 14044241\r\n-81154428 18845572\r\n", "output": "3854694816242280\r\n"}, {"input": "10\r\n484 206445\r\n417 239562\r\n135 736435\r\n100 995898\r\n669 149428\r\n148148 675\r\n162 615397\r\n400 249827\r\n102 973876\r\n173 575939\r\n", "output": "903186\r\n"}, {"input": "10\r\n22080299 -97531842\r\n99982368 -1877760\r\n82007780 -57225204\r\n95632512 -29230506\r\n40850397 -91275654\r\n39838009 -91722041\r\n2527763 -99968046\r\n30181880 -95336530\r\n59384374 -80458039\r\n32198040 -94674633\r\n", "output": "6801227848213492\r\n"}, {"input": "13\r\n-2 0\r\n0 2\r\n2 0\r\n-1 1\r\n0 0\r\n0 -1\r\n1 -1\r\n0 -2\r\n0 1\r\n1 0\r\n1 1\r\n-1 0\r\n-1 -1\r\n", "output": "4\r\n"}, {"input": "81\r\n-2 -1\r\n-3 1\r\n2 1\r\n1 0\r\n-3 -1\r\n1 2\r\n-1 1\r\n-3 3\r\n0 -3\r\n3 1\r\n-1 -2\r\n2 3\r\n2 2\r\n1 -2\r\n3 -1\r\n-1 -4\r\n1 3\r\n3 3\r\n2 -3\r\n0 -4\r\n1 -1\r\n0 3\r\n-2 0\r\n-4 1\r\n0 -5\r\n-4 3\r\n2 -4\r\n4 2\r\n-3 -4\r\n-3 4\r\n-3 0\r\n-2 4\r\n1 1\r\n4 1\r\n-4 0\r\n0 -1\r\n0 4\r\n4 0\r\n-4 -1\r\n3 -4\r\n-2 1\r\n3 2\r\n0 2\r\n-1 0\r\n-3 -2\r\n3 -3\r\n0 1\r\n2 0\r\n2 -1\r\n-2 3\r\n1 -3\r\n-1 -1\r\n-2 -3\r\n3 4\r\n2 -2\r\n1 -4\r\n3 -2\r\n4 -1\r\n4 -3\r\n1 4\r\n3 0\r\n-3 -3\r\n-1 2\r\n-5 0\r\n-2 -2\r\n-4 -2\r\n4 3\r\n0 -2\r\n-4 -3\r\n-4 2\r\n-2 2\r\n-1 -3\r\n5 0\r\n-1 3\r\n2 4\r\n0 5\r\n-2 -4\r\n-3 2\r\n4 -2\r\n0 0\r\n-1 4\r\n", "output": "36\r\n"}, {"input": "21\r\n5 0\r\n2 2\r\n0 1\r\n0 2\r\n2 0\r\n4 0\r\n1 1\r\n3 0\r\n3 2\r\n1 0\r\n1 2\r\n3 1\r\n1 3\r\n2 3\r\n0 3\r\n0 5\r\n0 4\r\n0 0\r\n2 1\r\n1 4\r\n4 1\r\n", "output": "8\r\n"}, {"input": "66\r\n3 0\r\n2 7\r\n0 5\r\n5 1\r\n6 4\r\n0 2\r\n3 1\r\n3 4\r\n4 1\r\n7 0\r\n10 0\r\n0 6\r\n7 1\r\n7 2\r\n5 0\r\n1 1\r\n6 0\r\n2 3\r\n3 5\r\n0 10\r\n3 6\r\n4 0\r\n1 8\r\n2 2\r\n1 6\r\n6 2\r\n0 3\r\n0 9\r\n2 0\r\n8 1\r\n4 4\r\n2 4\r\n1 3\r\n1 9\r\n3 3\r\n9 0\r\n7 3\r\n2 8\r\n4 5\r\n0 8\r\n5 4\r\n3 7\r\n8 2\r\n5 5\r\n1 4\r\n1 5\r\n4 2\r\n4 3\r\n3 2\r\n1 7\r\n6 1\r\n1 0\r\n0 0\r\n6 3\r\n2 1\r\n8 0\r\n9 1\r\n0 1\r\n0 7\r\n2 6\r\n1 2\r\n4 6\r\n0 4\r\n5 2\r\n5 3\r\n2 5\r\n", "output": "41\r\n"}, {"input": "1\r\n-32222 98\r\n", "output": "0\r\n"}, {"input": "1\r\n-1 -1\r\n", "output": "0\r\n"}, {"input": "3\r\n10 10\r\n10 20\r\n20 10\r\n", "output": "100\r\n"}, {"input": "2\r\n5 5\r\n1000 1000\r\n", "output": "990025\r\n"}, {"input": "2\r\n1 1\r\n-1 -1\r\n", "output": "2\r\n"}, {"input": "3\r\n-1 7\r\n8 2\r\n5 -3\r\n", "output": "25\r\n"}, {"input": "11\r\n86252958 -8453022\r\n20979758 -6495116\r\n-78204472 -7527274\r\n66289339 9784937\r\n-15941740 412492\r\n58997345 9109992\r\n90222551 -4687529\r\n12732746 9064427\r\n-85673028 -8886670\r\n37578830 -8279001\r\n59212726 788692\r\n", "output": "348628907962449\r\n"}, {"input": "10\r\n-8055884 -28179455\r\n-9336503 98988615\r\n19433716 53975448\r\n58614993 -69147933\r\n-53287109 35247908\r\n-75259375 94365460\r\n43802543 96926279\r\n53740260 -15640682\r\n-97179864 -25661311\r\n-17951783 -51266382\r\n", "output": "14175740317838724\r\n"}, {"input": "14\r\n-66 7\r\n2 71\r\n3 -36\r\n5 26\r\n-21 6\r\n41 -5\r\n32 -2\r\n-26 -5\r\n2 -60\r\n86 -6\r\n34 -8\r\n-24 9\r\n-75 -8\r\n-92 1\r\n", "output": "289\r\n"}, {"input": "16\r\n-68 259\r\n-90 65\r\n65 454\r\n242 74\r\n358 -86\r\n-441 -80\r\n44 -422\r\n67 178\r\n15 -425\r\n88 109\r\n-66 -246\r\n-24 285\r\n-131 60\r\n-152 52\r\n-18 -129\r\n204 -11\r\n", "output": "25600\r\n"}, {"input": "10\r\n622 1946\r\n422 1399\r\n165 -203\r\n-903 -2133\r\n-1152 964\r\n-842 -1150\r\n1849 5\r\n-11 471\r\n1966 -379\r\n67 776\r\n", "output": "2325625\r\n"}, {"input": "15\r\n-128458 573454\r\n751293 1852055\r\n1546241 438377\r\n642614 -1677745\r\n1768534 -919019\r\n205820 357582\r\n-877851 792499\r\n313687 -491257\r\n1334705 533906\r\n-136082 -42692\r\n-1948794 304398\r\n-602602 -557714\r\n-847986 -1248897\r\n-1915382 76977\r\n-1118694 -705173\r\n", "output": "2654110172736\r\n"}, {"input": "12\r\n-3979966 -64785636\r\n54498897 11255152\r\n52322390 -67233168\r\n32879609 -16571480\r\n50371826 19645523\r\n-68348841 22478633\r\n3424248 90696875\r\n-42961539 -43574884\r\n36163900 62201849\r\n-53982801 42129019\r\n-55804340 70782236\r\n13142275 39447287\r\n", "output": "8458157168697600\r\n"}, {"input": "18\r\n3 -55\r\n-54 -2\r\n2 -42\r\n-8 68\r\n82 4\r\n-2 -73\r\n1 44\r\n-29 3\r\n-48 -3\r\n91 4\r\n4 -16\r\n24 -2\r\n-5 36\r\n46 -2\r\n24 -3\r\n76 4\r\n51 1\r\n-76 -1\r\n", "output": "144\r\n"}, {"input": "17\r\n337 -16\r\n-53 16\r\n-247 -10\r\n-88 -224\r\n62 -426\r\n67 2\r\n320 19\r\n239 3\r\n82 269\r\n76 -237\r\n-8 -1\r\n195 -18\r\n82 131\r\n31 -276\r\n48 -2\r\n-66 228\r\n-463 -18\r\n", "output": "28900\r\n"}, {"input": "18\r\n745 1353\r\n248 -68\r\n-636 -647\r\n-335 712\r\n270 5\r\n-402 128\r\n29 -1871\r\n648 -182\r\n-403 -469\r\n616 -1341\r\n898 2358\r\n361 2296\r\n1074 9\r\n-452 1480\r\n993 -2039\r\n-491 1690\r\n-656 1759\r\n2087 30\r\n", "output": "2719201\r\n"}, {"input": "14\r\n88 242\r\n-1763 920\r\n-160 -1921\r\n2368 562\r\n123 -2003\r\n165 656\r\n-20 2333\r\n-1786 -771\r\n-1648 -242\r\n-1842 150\r\n-2078 -428\r\n-1865 860\r\n-140 -311\r\n-2453 571\r\n", "output": "2859481\r\n"}, {"input": "20\r\n-691166 1857437\r\n308748 757809\r\n-908302 1208183\r\n213496 81845\r\n1882976 -9001\r\n-1459847 -58718\r\n902599 -1235585\r\n499018 1161414\r\n658542 -86418\r\n-803191 -1737709\r\n1682313 -49632\r\n-166179 1387536\r\n-203007 18260\r\n1579851 -79901\r\n128002 906577\r\n-57584 -70366\r\n-493935 -15924\r\n1900231 6581\r\n894309 851468\r\n954724 1678804\r\n", "output": "3090265147225\r\n"}, {"input": "16\r\n840204 -563586\r\n-1482 -306408\r\n-45167 -1969028\r\n73804 525097\r\n69604 198191\r\n65491 -1345144\r\n-1609018 -285663\r\n404867 -210266\r\n255601 832851\r\n4999 1764313\r\n541223 736278\r\n-20170 1911573\r\n-281805 251017\r\n52312 1029263\r\n72529 -38660\r\n32894 1380373\r\n", "output": "663578047609\r\n"}, {"input": "12\r\n-44489842 18113240\r\n-2081704 -1338672\r\n-3803741 36271320\r\n40239596 12868007\r\n-97939521 33357113\r\n60348507 -45490328\r\n59546944 -64898105\r\n1073008 86908503\r\n5160027 39955776\r\n1531464 64470852\r\n51713010 -35029180\r\n43419463 -8413764\r\n", "output": "4754639284823818\r\n"}, {"input": "14\r\n-4788460 -58174715\r\n3667616 -42701029\r\n58801800 -67135593\r\n-27712521 33013050\r\n70162832 21395449\r\n430668 18516811\r\n27425137 13550355\r\n73782530 -33761391\r\n-3092363 29002645\r\n-79768595 21183779\r\n-434563 -46164603\r\n3072648 -44934958\r\n2954859 6384655\r\n-9768771 -50164937\r\n", "output": "4701923207266041\r\n"}, {"input": "1\r\n0 0\r\n", "output": "0\r\n"}, {"input": "2\r\n0 0\r\n-1 5\r\n", "output": "1\r\n"}]
| false |
stdio
| null | true |
540/C
|
540
|
C
|
Python 3
|
TESTS
| 22 | 841 | 13,107,200 |
115861597
|
dx = [0, 0, -1, 1]
dy = [-1, 1, 0, 0]
def getNum(cell, n, m):
return cell[0] * m + cell[1]
def getCell(number, n, m):
return [number // m, number % m]
def isValidCell(cell, maze):
n = len(maze)
m = len(maze[0])
return (0 <= cell[0] < n) and (0 <= cell[1] < m) and (maze[cell[0]][cell[1]] == '.')
def findSolution(sea, start, end):
queue = [start]
n, m = len(sea), len(sea[0])
visited = set()
visited.add(getNum(start, n, m))
cnt = 0
for i in range(4):
nxt = [end[0] + dx[i], end[1] + dy[i]]
cnt += isValidCell(nxt, sea)
if (cnt <= 1 and sea[end[0]][end[1]] == '.'): return "NO"
while (len(queue) > 0):
u = queue[0]
queue.pop(0)
for i in range(4):
nxt = [u[0] + dx[i], u[1] + dy[i]]
if (nxt == end): return "YES"
if (not isValidCell(nxt, sea) or getNum(nxt, n, m) in visited):
continue
queue.append(nxt)
visited.add(getNum(nxt, n, m))
return "NO"
n, m = map(int, input().split())
sea = []
for i in range(n):
sea.append(input())
r1, c1 = map(int, input().split())
r2, c2 = map(int, input().split())
print(findSolution(sea, [r1 - 1, c1 - 1], [r2 - 1, c2 - 1]))
| 102 | 155 | 10,342,400 |
207369811
|
import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def f(u, v):
return u * m + v
def bfs(x, y):
q, k = [f(x, y)], 0
visit = [0] * (n * m)
visit[f(x, y)] = 1
while len(q) ^ k:
x, y = divmod(q[k], m)
for dx, dy in v:
nx, ny = x + dx, y + dy
if not 0 <= nx < n or not 0 <= ny < m:
continue
u = f(nx, ny)
if not s[u] or visit[u]:
continue
visit[u] = 1
q.append(u)
k += 1
return visit
n, m = map(int, input().split())
s = []
for _ in range(n):
s0 = list(input().rstrip())
for i in s0:
s.append(i & 2)
r1, c1 = map(int, input().split())
r2, c2 = map(int, input().split())
r1, c1, r2, c2 = r1 - 1, c1 - 1, r2 - 1, c2 - 1
v = [(1, 0), (-1, 0), (0, 1), (0, -1)]
if abs(r1 - r2) + abs(c1 - c2) == 1:
if not s[f(r2, c2)]:
ans = "YES"
else:
ans = "NO"
for dr, dc in v:
nr, nc = r2 + dr, c2 + dc
if 0 <= nr < n and 0 <= nc < m and s[f(nr, nc)]:
ans = "YES"
break
else:
ok = 1
if s[f(r2, c2)]:
c = 0
for dr, dc in v:
nr, nc = r2 + dr, c2 + dc
if 0 <= nr < n and 0 <= nc < m and s[f(nr, nc)]:
c += 1
if c < 2:
ok = 0
visit = bfs(r1, c1)
if s[f(r2, c2)]:
ans = "YES" if visit[f(r2, c2)] and ok else "NO"
else:
ans = "NO"
for dr, dc in v:
nr, nc = r2 + dr, c2 + dc
if 0 <= nr < n and 0 <= nc < m and visit[f(nr, nc)]:
ans = "YES"
break
print(ans)
|
Codeforces Round 301 (Div. 2)
|
CF
| 2,015 | 2 | 256 |
Ice Cave
|
You play a computer game. Your character stands on some level of a multilevel ice cave. In order to move on forward, you need to descend one level lower and the only way to do this is to fall through the ice.
The level of the cave where you are is a rectangular square grid of n rows and m columns. Each cell consists either from intact or from cracked ice. From each cell you can move to cells that are side-adjacent with yours (due to some limitations of the game engine you cannot make jumps on the same place, i.e. jump from a cell to itself). If you move to the cell with cracked ice, then your character falls down through it and if you move to the cell with intact ice, then the ice on this cell becomes cracked.
Let's number the rows with integers from 1 to n from top to bottom and the columns with integers from 1 to m from left to right. Let's denote a cell on the intersection of the r-th row and the c-th column as (r, c).
You are staying in the cell (r1, c1) and this cell is cracked because you've just fallen here from a higher level. You need to fall down through the cell (r2, c2) since the exit to the next level is there. Can you do this?
|
The first line contains two integers, n and m (1 ≤ n, m ≤ 500) — the number of rows and columns in the cave description.
Each of the next n lines describes the initial state of the level of the cave, each line consists of m characters "." (that is, intact ice) and "X" (cracked ice).
The next line contains two integers, r1 and c1 (1 ≤ r1 ≤ n, 1 ≤ c1 ≤ m) — your initial coordinates. It is guaranteed that the description of the cave contains character 'X' in cell (r1, c1), that is, the ice on the starting cell is initially cracked.
The next line contains two integers r2 and c2 (1 ≤ r2 ≤ n, 1 ≤ c2 ≤ m) — the coordinates of the cell through which you need to fall. The final cell may coincide with the starting one.
|
If you can reach the destination, print 'YES', otherwise print 'NO'.
| null |
In the first sample test one possible path is:
$$(1,6)\rightarrow(2,6)\rightarrow(3,6)\rightarrow(4,5)\rightarrow(4,4)\rightarrow(4,3)\rightarrow(4,2)\rightarrow(4,1)\rightarrow(3,2)\rightarrow(2,3)\rightarrow(2,2)$$
After the first visit of cell (2, 2) the ice on it cracks and when you step there for the second time, your character falls through the ice as intended.
|
[{"input": "4 6\nX...XX\n...XX.\n.X..X.\n......\n1 6\n2 2", "output": "YES"}, {"input": "5 4\n.X..\n...X\nX.X.\n....\n.XX.\n5 3\n1 1", "output": "NO"}, {"input": "4 7\n..X.XX.\n.XX..X.\nX...X..\nX......\n2 2\n1 6", "output": "YES"}]
| 2,000 |
["dfs and similar"]
| 102 |
[{"input": "4 6\r\nX...XX\r\n...XX.\r\n.X..X.\r\n......\r\n1 6\r\n2 2\r\n", "output": "YES\r\n"}, {"input": "5 4\r\n.X..\r\n...X\r\nX.X.\r\n....\r\n.XX.\r\n5 3\r\n1 1\r\n", "output": "NO\r\n"}, {"input": "4 7\r\n..X.XX.\r\n.XX..X.\r\nX...X..\r\nX......\r\n2 2\r\n1 6\r\n", "output": "YES\r\n"}, {"input": "5 3\r\n.XX\r\n...\r\n.X.\r\n.X.\r\n...\r\n1 3\r\n4 1\r\n", "output": "YES\r\n"}, {"input": "1 1\r\nX\r\n1 1\r\n1 1\r\n", "output": "NO\r\n"}, {"input": "1 6\r\n.X...X\r\n1 2\r\n1 5\r\n", "output": "NO\r\n"}, {"input": "7 1\r\nX\r\n.\r\n.\r\n.\r\nX\r\n.\r\n.\r\n5 1\r\n3 1\r\n", "output": "YES\r\n"}, {"input": "1 2\r\nXX\r\n1 1\r\n1 1\r\n", "output": "NO\r\n"}, {"input": "2 1\r\n.\r\nX\r\n2 1\r\n2 1\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n.X..\r\n..XX\r\n..X.\r\n1 2\r\n3 4\r\n", "output": "NO\r\n"}, {"input": "3 5\r\n.X.XX\r\nX...X\r\nX.X..\r\n2 1\r\n1 5\r\n", "output": "NO\r\n"}, {"input": "3 2\r\n..\r\nX.\r\n.X\r\n3 2\r\n3 1\r\n", "output": "NO\r\n"}, {"input": "3 4\r\nXX.X\r\nX...\r\n.X.X\r\n1 2\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "1 2\r\nX.\r\n1 1\r\n1 2\r\n", "output": "NO\r\n"}, {"input": "2 1\r\nX\r\nX\r\n2 1\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "2 2\r\nXX\r\nXX\r\n1 1\r\n2 2\r\n", "output": "NO\r\n"}, {"input": "2 2\r\n..\r\n.X\r\n2 2\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "2 2\r\n.X\r\n.X\r\n1 2\r\n2 2\r\n", "output": "YES\r\n"}, {"input": "2 2\r\n..\r\nXX\r\n2 1\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "4 2\r\nX.\r\n.X\r\n.X\r\nXX\r\n2 2\r\n3 1\r\n", "output": "NO\r\n"}, {"input": "2 4\r\nX.XX\r\n.X..\r\n2 2\r\n2 3\r\n", "output": "YES\r\n"}, {"input": "6 4\r\nX..X\r\n..X.\r\n.X..\r\n..X.\r\n.X..\r\nX..X\r\n1 1\r\n6 4\r\n", "output": "NO\r\n"}, {"input": "5 4\r\nX...\r\n..X.\r\n.X..\r\nX..X\r\n....\r\n4 4\r\n3 1\r\n", "output": "NO\r\n"}, {"input": "3 4\r\nX..X\r\n..XX\r\n.X..\r\n2 3\r\n3 1\r\n", "output": "NO\r\n"}, {"input": "20 20\r\n....................\r\n.......X...........X\r\n............X......X\r\n.X...XX..X....X.....\r\n....X.....X.........\r\nX..........X........\r\n......X........X....\r\n....................\r\n...................X\r\n......X.............\r\n..............X.....\r\n......X.X...........\r\n.X.........X.X......\r\n.........X......X..X\r\n..................X.\r\n...X........X.......\r\n....................\r\n....................\r\n..X.....X...........\r\n........X......X.X..\r\n20 16\r\n5 20\r\n", "output": "YES\r\n"}, {"input": "21 21\r\n.....X...X.........X.\r\n...X...XX......X.....\r\n..X........X.X...XX..\r\n.........X....X...X..\r\nX...X...........XX...\r\n...X...X....XX...XXX.\r\n.X............X......\r\n......X.X............\r\n.X...X.........X.X...\r\n......XX......X.X....\r\n....X.......X.XXX....\r\n.X.......X..XXX.X..X.\r\n..X........X....X...X\r\n.........X..........X\r\n.....XX.....X........\r\n...XX......X.........\r\n.....X...XX...X......\r\n..X.X....XX..XX.X....\r\nX........X.X..XX..X..\r\nX..X......X...X.X....\r\nX.....X.....X.X......\r\n20 4\r\n21 5\r\n", "output": "YES\r\n"}, {"input": "2 1\r\nX\r\nX\r\n2 1\r\n2 1\r\n", "output": "NO\r\n"}, {"input": "2 2\r\nXX\r\nX.\r\n1 1\r\n2 2\r\n", "output": "NO\r\n"}, {"input": "2 1\r\nX\r\nX\r\n1 1\r\n1 1\r\n", "output": "NO\r\n"}, {"input": "1 2\r\nXX\r\n1 2\r\n1 2\r\n", "output": "NO\r\n"}, {"input": "1 2\r\nXX\r\n1 1\r\n1 2\r\n", "output": "YES\r\n"}, {"input": "1 2\r\nXX\r\n1 2\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "2 1\r\nX\r\nX\r\n1 1\r\n2 1\r\n", "output": "YES\r\n"}, {"input": "2 1\r\n.\r\nX\r\n2 1\r\n1 1\r\n", "output": "NO\r\n"}, {"input": "2 1\r\nX\r\n.\r\n1 1\r\n2 1\r\n", "output": "NO\r\n"}, {"input": "1 2\r\n.X\r\n1 2\r\n1 1\r\n", "output": "NO\r\n"}, {"input": "2 1\r\nX\r\n.\r\n1 1\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "1 2\r\nX.\r\n1 1\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "1 2\r\n.X\r\n1 2\r\n1 2\r\n", "output": "YES\r\n"}, {"input": "2 2\r\nX.\r\n..\r\n1 1\r\n2 2\r\n", "output": "YES\r\n"}, {"input": "2 2\r\n..\r\nX.\r\n2 1\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "4 3\r\n..X\r\n..X\r\n.XX\r\n.XX\r\n4 2\r\n2 2\r\n", "output": "YES\r\n"}, {"input": "3 3\r\nXXX\r\nX..\r\nXXX\r\n2 1\r\n2 2\r\n", "output": "YES\r\n"}, {"input": "5 4\r\nXXXX\r\nX..X\r\nX..X\r\nXXXX\r\nXXXX\r\n4 2\r\n3 3\r\n", "output": "YES\r\n"}]
| false |
stdio
| null | true |
721/B
|
721
|
B
|
Python 3
|
TESTS
| 12 | 46 | 0 |
185453619
|
limit = [int(i) for i in input().split(" ")]
password_len = {}
for i in range(limit[0]):
a = str(len(input()))
if(a in password_len):
password_len[a] += 1
else:
password_len[a] = 1
right_password_len = str(len(input()))
best = 0
worst = 0
key_sort = sorted(password_len.keys())
for i in key_sort:
worst += password_len[i]
if(right_password_len == i):
best += 1
break
best += password_len[i]
best += (best-1)//limit[1]*5
worst += (worst-1)//limit[1]*5
print(f"{best} {worst}")
| 66 | 46 | 0 |
156747876
|
n, k = map(int, input().split())
l_l = list()
for _ in range(n):
l_l.append(len(input()))
p = len(input())
h_t = 0
l_t = 0
for l in l_l:
if l < p:
h_t += 1
l_t += 1
elif l == p:
h_t += 1
l_t += 1
print("%d %d" % (l_t + ((l_t - 1) // k) * 5, h_t + ((h_t - 1) // k) * 5))
|
Codeforces Round 374 (Div. 2)
|
CF
| 2,016 | 2 | 256 |
Passwords
|
Vanya is managed to enter his favourite site Codehorses. Vanya uses n distinct passwords for sites at all, however he can't remember which one exactly he specified during Codehorses registration.
Vanya will enter passwords in order of non-decreasing their lengths, and he will enter passwords of same length in arbitrary order. Just when Vanya will have entered the correct password, he is immediately authorized on the site. Vanya will not enter any password twice.
Entering any passwords takes one second for Vanya. But if Vanya will enter wrong password k times, then he is able to make the next try only 5 seconds after that. Vanya makes each try immediately, that is, at each moment when Vanya is able to enter password, he is doing that.
Determine how many seconds will Vanya need to enter Codehorses in the best case for him (if he spends minimum possible number of second) and in the worst case (if he spends maximum possible amount of seconds).
|
The first line of the input contains two integers n and k (1 ≤ n, k ≤ 100) — the number of Vanya's passwords and the number of failed tries, after which the access to the site is blocked for 5 seconds.
The next n lines contains passwords, one per line — pairwise distinct non-empty strings consisting of latin letters and digits. Each password length does not exceed 100 characters.
The last line of the input contains the Vanya's Codehorses password. It is guaranteed that the Vanya's Codehorses password is equal to some of his n passwords.
|
Print two integers — time (in seconds), Vanya needs to be authorized to Codehorses in the best case for him and in the worst case respectively.
| null |
Consider the first sample case. As soon as all passwords have the same length, Vanya can enter the right password at the first try as well as at the last try. If he enters it at the first try, he spends exactly 1 second. Thus in the best case the answer is 1. If, at the other hand, he enters it at the last try, he enters another 4 passwords before. He spends 2 seconds to enter first 2 passwords, then he waits 5 seconds as soon as he made 2 wrong tries. Then he spends 2 more seconds to enter 2 wrong passwords, again waits 5 seconds and, finally, enters the correct password spending 1 more second. In summary in the worst case he is able to be authorized in 15 seconds.
Consider the second sample case. There is no way of entering passwords and get the access to the site blocked. As soon as the required password has length of 2, Vanya enters all passwords of length 1 anyway, spending 2 seconds for that. Then, in the best case, he immediately enters the correct password and the answer for the best case is 3, but in the worst case he enters wrong password of length 2 and only then the right one, spending 4 seconds at all.
|
[{"input": "5 2\ncba\nabc\nbb1\nabC\nABC\nabc", "output": "1 15"}, {"input": "4 100\n11\n22\n1\n2\n22", "output": "3 4"}]
| 1,100 |
["implementation", "math", "sortings", "strings"]
| 66 |
[{"input": "5 2\r\ncba\r\nabc\r\nbb1\r\nabC\r\nABC\r\nabc\r\n", "output": "1 15\r\n"}, {"input": "4 100\r\n11\r\n22\r\n1\r\n2\r\n22\r\n", "output": "3 4\r\n"}, {"input": "1 1\r\na1\r\na1\r\n", "output": "1 1\r\n"}, {"input": "1 100\r\na1\r\na1\r\n", "output": "1 1\r\n"}, {"input": "2 1\r\nabc\r\nAbc\r\nAbc\r\n", "output": "1 7\r\n"}, {"input": "2 2\r\nabc\r\nAbc\r\nabc\r\n", "output": "1 2\r\n"}, {"input": "2 1\r\nab\r\nabc\r\nab\r\n", "output": "1 1\r\n"}, {"input": "2 2\r\nab\r\nabc\r\nab\r\n", "output": "1 1\r\n"}, {"input": "2 1\r\nab\r\nabc\r\nabc\r\n", "output": "7 7\r\n"}, {"input": "2 2\r\nab\r\nabc\r\nabc\r\n", "output": "2 2\r\n"}, {"input": "10 3\r\nOIbV1igi\r\no\r\nZS\r\nQM\r\n9woLzI\r\nWreboD\r\nQ7yl\r\nA5Rb\r\nS9Lno72TkP\r\nfT97o\r\no\r\n", "output": "1 1\r\n"}, {"input": "10 3\r\nHJZNMsT\r\nLaPcH2C\r\nlrhqIO\r\n9cxw\r\noTC1XwjW\r\nGHL9Ul6\r\nUyIs\r\nPuzwgR4ZKa\r\nyIByoKR5\r\nd3QA\r\nPuzwgR4ZKa\r\n", "output": "25 25\r\n"}, {"input": "20 5\r\nvSyC787KlIL8kZ2Uv5sw\r\nWKWOP\r\n7i8J3E8EByIq\r\nNW2VyGweL\r\nmyR2sRNu\r\nmXusPP0\r\nf4jgGxra\r\n4wHRzRhOCpEt\r\npPz9kybGb\r\nOtSpePCRoG5nkjZ2VxRy\r\nwHYsSttWbJkg\r\nKBOP9\r\nQfiOiFyHPPsw3GHo8J8\r\nxB8\r\nqCpehZEeEhdq\r\niOLjICK6\r\nQ91\r\nHmCsfMGTFKoFFnv238c\r\nJKjhg\r\ngkEUh\r\nKBOP9\r\n", "output": "3 11\r\n"}, {"input": "15 2\r\nw6S9WyU\r\nMVh\r\nkgUhQHW\r\nhGQNOF\r\nUuym\r\n7rGQA\r\nBM8vLPRB\r\n9E\r\nDs32U\r\no\r\nz1aV2C5T\r\n8\r\nzSXjrqQ\r\n1FO\r\n3kIt\r\nBM8vLPRB\r\n", "output": "44 50\r\n"}, {"input": "20 2\r\ni\r\n5Rp6\r\nE4vsr\r\nSY\r\nORXx\r\nh13C\r\nk6tzC\r\ne\r\nN\r\nKQf4C\r\nWZcdL\r\ndiA3v\r\n0InQT\r\nuJkAr\r\nGCamp\r\nBuIRd\r\nY\r\nM\r\nxZYx7\r\n0a5A\r\nWZcdL\r\n", "output": "36 65\r\n"}, {"input": "20 2\r\naWLQ6\r\nSgQ9r\r\nHcPdj\r\n2BNaO\r\n3TjNb\r\nnvwFM\r\nqsKt7\r\nFnb6N\r\nLoc0p\r\njxuLq\r\nBKAjf\r\nEKgZB\r\nBfOSa\r\nsMIvr\r\nuIWcR\r\nIura3\r\nLAqSf\r\ntXq3G\r\n8rQ8I\r\n8otAO\r\nsMIvr\r\n", "output": "1 65\r\n"}, {"input": "20 15\r\n0ZpQugVlN7\r\nm0SlKGnohN\r\nRFXTqhNGcn\r\n1qm2ZbB\r\nQXtJWdf78P\r\nbc2vH\r\nP21dty2Z1P\r\nm2c71LFhCk\r\n23EuP1Dvh3\r\nanwri5RhQN\r\n55v6HYv288\r\n1u5uKOjM5r\r\n6vg0GC1\r\nDAPYiA3ns1\r\nUZaaJ3Gmnk\r\nwB44x7V4Zi\r\n4hgB2oyU8P\r\npYFQpy8gGK\r\ndbz\r\nBv\r\n55v6HYv288\r\n", "output": "6 25\r\n"}, {"input": "3 1\r\na\r\nb\r\naa\r\naa\r\n", "output": "13 13\r\n"}, {"input": "6 3\r\nab\r\nac\r\nad\r\nabc\r\nabd\r\nabe\r\nabc\r\n", "output": "9 11\r\n"}, {"input": "4 2\r\n1\r\n2\r\n11\r\n22\r\n22\r\n", "output": "8 9\r\n"}, {"input": "2 1\r\n1\r\n12\r\n12\r\n", "output": "7 7\r\n"}, {"input": "3 1\r\nab\r\nabc\r\nabd\r\nabc\r\n", "output": "7 13\r\n"}, {"input": "2 1\r\na\r\nab\r\nab\r\n", "output": "7 7\r\n"}, {"input": "5 2\r\na\r\nb\r\nc\r\nab\r\naa\r\naa\r\n", "output": "9 15\r\n"}, {"input": "6 1\r\n1\r\n2\r\n11\r\n22\r\n111\r\n2222\r\n22\r\n", "output": "13 19\r\n"}, {"input": "3 1\r\n1\r\n2\r\n11\r\n11\r\n", "output": "13 13\r\n"}, {"input": "10 4\r\na\r\nb\r\nc\r\nd\r\ne\r\nf\r\nab\r\ncd\r\nac\r\nad\r\nac\r\n", "output": "12 20\r\n"}, {"input": "4 2\r\na\r\nb\r\nc\r\nd\r\na\r\n", "output": "1 9\r\n"}, {"input": "4 1\r\n1\r\n2\r\n3\r\n4\r\n4\r\n", "output": "1 19\r\n"}, {"input": "5 1\r\na\r\nb\r\nc\r\nd\r\nef\r\nef\r\n", "output": "25 25\r\n"}, {"input": "6 4\r\n1\r\n2\r\n22\r\n33\r\n44\r\n555\r\n555\r\n", "output": "11 11\r\n"}, {"input": "5 2\r\na\r\nb\r\nc\r\nd\r\nab\r\nab\r\n", "output": "15 15\r\n"}, {"input": "6 2\r\n1\r\n2\r\n3\r\n4\r\n5\r\n23\r\n23\r\n", "output": "16 16\r\n"}, {"input": "4 2\r\na\r\nb\r\naa\r\nbb\r\naa\r\n", "output": "8 9\r\n"}, {"input": "5 4\r\na\r\nbb\r\ncc\r\ndd\r\nee\r\nbb\r\n", "output": "2 10\r\n"}, {"input": "4 1\r\na\r\nb\r\nc\r\nab\r\nab\r\n", "output": "19 19\r\n"}, {"input": "7 100\r\na\r\nb\r\nc\r\nd\r\ne\r\ng\r\nab\r\nab\r\n", "output": "7 7\r\n"}, {"input": "6 1\r\na\r\nb\r\nc\r\nd\r\ne\r\naa\r\naa\r\n", "output": "31 31\r\n"}, {"input": "4 1\r\na\r\nas\r\nasd\r\nasde\r\nasde\r\n", "output": "19 19\r\n"}, {"input": "5 2\r\n1\r\n2\r\n3\r\n11\r\n22\r\n22\r\n", "output": "9 15\r\n"}, {"input": "10 2\r\na\r\nb\r\nc\r\nd\r\nee\r\nff\r\ngg\r\nhh\r\nii\r\njj\r\nii\r\n", "output": "15 30\r\n"}, {"input": "3 1\r\na\r\nab\r\nbc\r\nab\r\n", "output": "7 13\r\n"}, {"input": "6 4\r\na\r\nb\r\nc\r\nbb\r\nbc\r\ncc\r\ncc\r\n", "output": "4 11\r\n"}]
| false |
stdio
| null | true |
382/C
|
382
|
C
|
Python 3
|
TESTS
| 52 | 155 | 8,089,600 |
199726620
|
def c(n, s):
if n == 1:
return -1, []
if n == 2:
a, b = s[0], s[1]
if b - a == 0:
return 1, [a]
elif (b - a) % 2:
return 2, [a * 2 - b, 2 * b - a]
else:
return 3, [a * 2 - b, (a + b) // 2, b * 2 - a]
d = {}
for i in range(1, n):
v = s[i] - s[i - 1]
if v not in d:
d[v] = 1
else:
d[v] += 1
if len(d) >= 3:
return 0, []
if len(d) == 2:
a, b = d.keys()
if a * 2 != b and b * 2 != a or min(d.values()) > 1:
return 0, []
if 0 in d:
return 1, [s[0]]
if len(d) == 1:
for i in d:
return 2, [s[0] - i, s[-1] + i]
a, b = sorted(d.keys())
for i in range(1, n):
if s[i] - s[i - 1] != a:
return 1, [s[i] - a]
n = int(input())
s = list(map(int, input().split()))
s.sort()
i, v = c(n, s)
print(i)
if i > 0:
print(*v)
| 59 | 202 | 8,499,200 |
16543710
|
n = int(input())
a = sorted(list(map(int, input().split(' '))))
if n == 1:
print(-1)
exit()
if n == 2 and (a[1]-a[0])%2 == 0 and a[0] != a[1]:
print(3)
print(2*a[0]-a[1], (a[0]+a[1])//2, 2*a[1]-a[0])
exit()
m = [a[i]-a[i-1] for i in range(1, n)]
if len(set(m)) == 1:
if m[0] != 0:
print(2)
print(a[0]-m[0], a[-1]+m[0])
else:
print(1)
print(a[0])
exit()
m.sort()
if len(set(m)) > 2 or m[-1] != 2*m[-2]:
print(0)
else:
print(1)
for i in range(1, n):
if a[i]-a[i-1] != m[0]:
print(a[i-1]+m[0])
|
Codeforces Round 224 (Div. 2)
|
CF
| 2,014 | 1 | 256 |
Arithmetic Progression
|
Everybody knows what an arithmetic progression is. Let us remind you just in case that an arithmetic progression is such sequence of numbers a1, a2, ..., an of length n, that the following condition fulfills:
a2 - a1 = a3 - a2 = a4 - a3 = ... = ai + 1 - ai = ... = an - an - 1.
For example, sequences [1, 5], [10], [5, 4, 3] are arithmetic progressions and sequences [1, 3, 2], [1, 2, 4] are not.
Alexander has n cards containing integers. Arthur wants to give Alexander exactly one more card with a number so that he could use the resulting n + 1 cards to make an arithmetic progression (Alexander has to use all of his cards).
Arthur has already bought a card but he hasn't written a number on it. Help him, print all integers that you can write on a card so that the described condition fulfilled.
|
The first line contains integer n (1 ≤ n ≤ 105) — the number of cards. The next line contains the sequence of integers — the numbers on Alexander's cards. The numbers are positive integers, each of them doesn't exceed 108.
|
If Arthur can write infinitely many distinct integers on the card, print on a single line -1.
Otherwise, print on the first line the number of integers that suit you. In the second line, print the numbers in the increasing order. Note that the numbers in the answer can exceed 108 or even be negative (see test samples).
| null | null |
[{"input": "3\n4 1 7", "output": "2\n-2 10"}, {"input": "1\n10", "output": "-1"}, {"input": "4\n1 3 5 9", "output": "1\n7"}, {"input": "4\n4 3 4 5", "output": "0"}, {"input": "2\n2 4", "output": "3\n0 3 6"}]
| 1,700 |
["implementation", "sortings"]
| 59 |
[{"input": "3\r\n4 1 7\r\n", "output": "2\r\n-2 10\r\n"}, {"input": "1\r\n10\r\n", "output": "-1\r\n"}, {"input": "4\r\n1 3 5 9\r\n", "output": "1\r\n7\r\n"}, {"input": "4\r\n4 3 4 5\r\n", "output": "0\r\n"}, {"input": "2\r\n2 4\r\n", "output": "3\r\n0 3 6\r\n"}, {"input": "4\r\n1 3 4 5\r\n", "output": "1\r\n2\r\n"}, {"input": "2\r\n3 3\r\n", "output": "1\r\n3\r\n"}, {"input": "2\r\n13 2\r\n", "output": "2\r\n-9 24\r\n"}, {"input": "5\r\n2 2 2 2 2\r\n", "output": "1\r\n2\r\n"}, {"input": "6\r\n11 1 7 9 5 13\r\n", "output": "1\r\n3\r\n"}, {"input": "2\r\n100000000 1\r\n", "output": "2\r\n-99999998 199999999\r\n"}, {"input": "5\r\n2 3 1 4 6\r\n", "output": "1\r\n5\r\n"}, {"input": "5\r\n1 2 2 3 4\r\n", "output": "0\r\n"}, {"input": "3\r\n1 4 2\r\n", "output": "1\r\n3\r\n"}, {"input": "3\r\n8 8 8\r\n", "output": "1\r\n8\r\n"}, {"input": "5\r\n2 2 2 2 3\r\n", "output": "0\r\n"}, {"input": "1\r\n100000000\r\n", "output": "-1\r\n"}, {"input": "20\r\n27 6 3 18 54 33 9 15 39 12 57 48 21 51 60 30 24 36 42 45\r\n", "output": "2\r\n0 63\r\n"}, {"input": "40\r\n100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000\r\n", "output": "1\r\n100000000\r\n"}, {"input": "49\r\n81787 163451 104059 89211 96635 133755 148603 141179 159739 122619 123 144891 70651 11259 63227 3835 44667 37243 100347 26107 137467 18683 156027 59515 22395 40955 111483 52091 7547 85499 107771 178299 115195 152315 74363 126331 33531 130043 14971 48379 167163 182011 170875 78075 174587 55803 66939 29819 118907\r\n", "output": "1\r\n92923\r\n"}, {"input": "9\r\n1 2 3 3 4 4 5 5 6\r\n", "output": "0\r\n"}, {"input": "7\r\n1 1 2 3 4 5 6\r\n", "output": "0\r\n"}, {"input": "2\r\n4 1\r\n", "output": "2\r\n-2 7\r\n"}, {"input": "2\r\n2 100000000\r\n", "output": "3\r\n-99999996 50000001 199999998\r\n"}, {"input": "8\r\n1 2 3 4 11 12 13 14\r\n", "output": "0\r\n"}, {"input": "7\r\n5 40 45 50 55 60 65\r\n", "output": "0\r\n"}, {"input": "1\r\n1\r\n", "output": "-1\r\n"}, {"input": "2\r\n1 1\r\n", "output": "1\r\n1\r\n"}, {"input": "2\r\n100000000 2\r\n", "output": "3\r\n-99999996 50000001 199999998\r\n"}, {"input": "3\r\n2 2 3\r\n", "output": "0\r\n"}, {"input": "5\r\n1 3 5 9 13\r\n", "output": "0\r\n"}, {"input": "5\r\n1 2 4 8 16\r\n", "output": "0\r\n"}, {"input": "3\r\n2 2 5\r\n", "output": "0\r\n"}, {"input": "5\r\n1 2 3 4 8\r\n", "output": "0\r\n"}, {"input": "3\r\n1 3 4\r\n", "output": "1\r\n2\r\n"}, {"input": "5\r\n1 2 4 6 7\r\n", "output": "0\r\n"}, {"input": "4\r\n1 5 9 11\r\n", "output": "0\r\n"}, {"input": "4\r\n3 4 5 9\r\n", "output": "0\r\n"}, {"input": "4\r\n1 5 6 8\r\n", "output": "0\r\n"}, {"input": "4\r\n2 6 8 12\r\n", "output": "0\r\n"}, {"input": "5\r\n1 2 3 5 7\r\n", "output": "0\r\n"}, {"input": "6\r\n1 2 3 4 6 8\r\n", "output": "0\r\n"}]
| false |
stdio
| null | true |
808/E
|
808
|
E
|
PyPy 3
|
TESTS
| 13 | 202 | 3,993,600 |
68076673
|
import sys
n, m = map(int, input().split())
w1 = [10**9]
w2 = [10**9]
w3 = [10**9]
for w, c in (map(int, l.split()) for l in sys.stdin):
if w == 1:
w1.append(c)
elif w == 2:
w2.append(c)
else:
w3.append(c)
w1.sort(reverse=True)
w1[0] = 0
for i in range(len(w1)-1):
w1[i+1] += w1[i]
w2.sort(reverse=True)
w2[0] = 0
for i in range(len(w2)-1):
w2[i+1] += w2[i]
w3.sort(reverse=True)
w3[0] = 0
for i in range(len(w3)-1):
w3[i+1] += w3[i]
w1_size, w2_size = len(w1)-1, len(w2)-1
ans = 0
for c3 in range(len(w3)):
if c3*3 > m:
break
if c3*3 == m:
ans = max(ans, w3[c3])
break
W = m - c3*3
l, r = 0, min(W//2, w2_size)
while r-l > 1:
ml, mr = l+(r-l+2)//3, r-(r-l+2)//3
c1 = w2[ml] + w1[min(W-ml*2, w1_size)]
c2 = w2[mr] + w1[min(W-mr*2, w1_size)]
if c1 > c2:
r = mr
else:
l = ml
ans = max(ans, w3[c3] + max(w2[l]+w1[min(W-l*2, w1_size)], w2[r]+w1[min(W-r*2, w1_size)]))
print(ans)
| 73 | 358 | 41,062,400 |
134594762
|
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
w1, w2, w3 = [], [], []
for _ in range(n):
w, c = map(int, input().split())
if w == 1:
w1.append(c)
elif w == 2:
w2.append(c)
else:
w3.append(c)
w1.sort(reverse = True)
w2.sort(reverse = True)
w3.sort(reverse = True)
l1, l2, l3 = len(w1), len(w2), len(w3)
dp = [0] * (m + 2)
dp1 = [0] * (m + 2)
dp2 = [0] * (m + 2)
for i in range(m):
dpi, dp1i, dp2i = dp[i], dp1[i], dp2[i]
if dp1i < l1 and dp[i + 1] < dpi + w1[dp1i]:
dp[i + 1] = dpi + w1[dp1i]
dp1[i + 1], dp2[i + 1] = dp1i + 1, dp2i
if dp2i < l2 and dp[i + 2] < dpi + w2[dp2i]:
dp[i + 2] = dpi + w2[dp2i]
dp1[i + 2], dp2[i + 2] = dp1i, dp2i + 1
if dp1i + 1 < l1 and dp[i + 2] < dpi + w1[dp1i] + w1[dp1i + 1]:
dp[i + 2] = dpi + w1[dp1i] + w1[dp1i + 1]
dp1[i + 2], dp2[i + 2] = dp1i + 2, dp2i
for i in range(1, m + 1):
dp[i] = max(dp[i], dp[i - 1])
ans = dp[m]
c = 0
for i in range(l3):
m -= 3
if m < 0:
break
c += w3[i]
ans = max(ans, dp[m] + c)
print(ans)
|
Educational Codeforces Round 21
|
ICPC
| 2,017 | 2 | 256 |
Selling Souvenirs
|
After several latest reforms many tourists are planning to visit Berland, and Berland people understood that it's an opportunity to earn money and changed their jobs to attract tourists. Petya, for example, left the IT corporation he had been working for and started to sell souvenirs at the market.
This morning, as usual, Petya will come to the market. Petya has n different souvenirs to sell; ith souvenir is characterised by its weight wi and cost ci. Petya knows that he might not be able to carry all the souvenirs to the market. So Petya wants to choose a subset of souvenirs such that its total weight is not greater than m, and total cost is maximum possible.
Help Petya to determine maximum possible total cost.
|
The first line contains two integers n and m (1 ≤ n ≤ 100000, 1 ≤ m ≤ 300000) — the number of Petya's souvenirs and total weight that he can carry to the market.
Then n lines follow. ith line contains two integers wi and ci (1 ≤ wi ≤ 3, 1 ≤ ci ≤ 109) — the weight and the cost of ith souvenir.
|
Print one number — maximum possible total cost of souvenirs that Petya can carry to the market.
| null | null |
[{"input": "1 1\n2 1", "output": "0"}, {"input": "2 2\n1 3\n2 2", "output": "3"}, {"input": "4 3\n3 10\n2 7\n2 8\n1 1", "output": "10"}]
| 2,300 |
["binary search", "dp", "greedy", "ternary search"]
| 73 |
[{"input": "1 1\r\n2 1\r\n", "output": "0\r\n"}, {"input": "2 2\r\n1 3\r\n2 2\r\n", "output": "3\r\n"}, {"input": "4 3\r\n3 10\r\n2 7\r\n2 8\r\n1 1\r\n", "output": "10\r\n"}, {"input": "5 5\r\n3 5\r\n2 6\r\n3 2\r\n1 1\r\n1 6\r\n", "output": "13\r\n"}, {"input": "6 6\r\n1 6\r\n1 4\r\n1 8\r\n3 2\r\n3 2\r\n2 8\r\n", "output": "26\r\n"}, {"input": "6 12\r\n1 7\r\n1 10\r\n2 8\r\n1 2\r\n2 9\r\n3 5\r\n", "output": "41\r\n"}, {"input": "6 18\r\n3 3\r\n1 10\r\n2 10\r\n3 6\r\n1 3\r\n2 3\r\n", "output": "35\r\n"}, {"input": "20 25\r\n2 13\r\n3 11\r\n1 32\r\n1 43\r\n3 85\r\n1 14\r\n2 57\r\n1 54\r\n1 38\r\n2 96\r\n2 89\r\n3 64\r\n1 79\r\n2 73\r\n1 73\r\n2 34\r\n1 52\r\n1 79\r\n1 42\r\n3 34\r\n", "output": "990\r\n"}, {"input": "40 45\r\n2 82\r\n2 70\r\n2 48\r\n3 50\r\n2 15\r\n1 23\r\n1 80\r\n2 46\r\n1 20\r\n3 8\r\n3 81\r\n2 27\r\n1 59\r\n1 15\r\n3 95\r\n2 82\r\n2 40\r\n2 9\r\n2 61\r\n1 49\r\n2 5\r\n2 82\r\n1 55\r\n2 11\r\n1 26\r\n1 33\r\n1 2\r\n1 7\r\n3 57\r\n2 29\r\n1 59\r\n2 50\r\n3 63\r\n1 40\r\n1 99\r\n2 91\r\n2 39\r\n3 50\r\n1 75\r\n3 77\r\n", "output": "1605\r\n"}, {"input": "4 28\r\n2 2\r\n3 1\r\n3 10\r\n1 9\r\n", "output": "22\r\n"}, {"input": "10 5\r\n1 9\r\n1 8\r\n2 10\r\n3 4\r\n3 1\r\n2 2\r\n3 6\r\n1 1\r\n3 8\r\n2 2\r\n", "output": "28\r\n"}, {"input": "10 12\r\n3 7\r\n3 6\r\n3 8\r\n3 2\r\n1 9\r\n2 5\r\n2 1\r\n2 5\r\n2 10\r\n2 9\r\n", "output": "46\r\n"}, {"input": "1 29\r\n2 8\r\n", "output": "8\r\n"}, {"input": "10 2\r\n3 4\r\n3 5\r\n3 7\r\n1 10\r\n1 2\r\n1 2\r\n1 8\r\n3 2\r\n1 8\r\n3 3\r\n", "output": "18\r\n"}, {"input": "6 5\r\n3 1\r\n3 1\r\n1 2\r\n2 9\r\n3 10\r\n1 8\r\n", "output": "20\r\n"}, {"input": "4 2\r\n3 4\r\n3 8\r\n1 1\r\n1 4\r\n", "output": "5\r\n"}, {"input": "7 12\r\n2 10\r\n2 8\r\n2 1\r\n3 8\r\n3 8\r\n3 7\r\n1 7\r\n", "output": "41\r\n"}, {"input": "70 203\r\n1 105\r\n1 105\r\n1 105\r\n3 300\r\n3 300\r\n3 300\r\n3 300\r\n3 300\r\n3 300\r\n3 300\r\n3 300\r\n3 300\r\n3 300\r\n3 300\r\n3 300\r\n3 300\r\n3 300\r\n3 300\r\n3 300\r\n3 300\r\n3 300\r\n3 300\r\n3 300\r\n3 300\r\n3 300\r\n3 300\r\n3 300\r\n3 300\r\n3 300\r\n3 300\r\n3 300\r\n3 300\r\n3 300\r\n3 300\r\n3 300\r\n3 300\r\n3 300\r\n3 300\r\n3 300\r\n3 300\r\n3 300\r\n3 300\r\n3 300\r\n3 300\r\n3 300\r\n3 300\r\n3 300\r\n3 300\r\n3 300\r\n3 300\r\n3 300\r\n3 300\r\n3 300\r\n3 300\r\n3 300\r\n3 300\r\n3 300\r\n3 300\r\n3 300\r\n3 300\r\n3 300\r\n3 300\r\n3 300\r\n3 300\r\n3 300\r\n3 300\r\n3 300\r\n3 300\r\n3 300\r\n3 300\r\n", "output": "20310\r\n"}, {"input": "10 6\r\n1 8\r\n1 10\r\n1 7\r\n2 9\r\n3 8\r\n1 8\r\n1 7\r\n1 4\r\n3 1\r\n3 8\r\n", "output": "44\r\n"}, {"input": "2 40\r\n1 10\r\n3 6\r\n", "output": "16\r\n"}, {"input": "7 6\r\n2 9\r\n3 10\r\n1 2\r\n2 6\r\n3 6\r\n2 1\r\n1 3\r\n", "output": "22\r\n"}, {"input": "2 4\r\n3 8\r\n1 6\r\n", "output": "14\r\n"}, {"input": "9 19\r\n2 5\r\n2 3\r\n3 9\r\n1 9\r\n3 8\r\n3 5\r\n3 4\r\n3 2\r\n3 6\r\n", "output": "46\r\n"}, {"input": "13 23\r\n3 17\r\n2 83\r\n1 81\r\n3 83\r\n3 59\r\n3 71\r\n2 61\r\n3 8\r\n3 64\r\n2 80\r\n3 47\r\n1 46\r\n1 82\r\n", "output": "711\r\n"}, {"input": "9 10\r\n3 6\r\n2 1\r\n2 4\r\n2 3\r\n3 6\r\n3 1\r\n1 8\r\n2 4\r\n3 3\r\n", "output": "25\r\n"}, {"input": "3 4\r\n2 10\r\n2 10\r\n3 15\r\n", "output": "20\r\n"}, {"input": "9 15\r\n3 8\r\n1 2\r\n2 5\r\n1 5\r\n3 3\r\n1 7\r\n1 7\r\n2 7\r\n2 9\r\n", "output": "51\r\n"}, {"input": "8 21\r\n2 6\r\n3 3\r\n3 7\r\n3 8\r\n3 8\r\n3 8\r\n2 6\r\n3 9\r\n", "output": "52\r\n"}, {"input": "6 7\r\n2 5\r\n2 4\r\n3 9\r\n3 2\r\n3 1\r\n3 8\r\n", "output": "18\r\n"}, {"input": "8 5\r\n3 9\r\n3 3\r\n1 4\r\n3 1\r\n2 5\r\n3 1\r\n3 6\r\n3 1\r\n", "output": "14\r\n"}, {"input": "1 1\r\n1 10\r\n", "output": "10\r\n"}, {"input": "1 2\r\n2 10\r\n", "output": "10\r\n"}, {"input": "5 9\r\n2 8\r\n3 7\r\n2 6\r\n1 4\r\n2 7\r\n", "output": "28\r\n"}, {"input": "4 4\r\n2 13\r\n2 15\r\n2 5\r\n1 9\r\n", "output": "28\r\n"}, {"input": "2 1\r\n1 5\r\n2 11\r\n", "output": "5\r\n"}, {"input": "8 6\r\n1 9\r\n1 5\r\n1 3\r\n1 10\r\n3 8\r\n1 6\r\n1 4\r\n1 2\r\n", "output": "37\r\n"}, {"input": "5 7\r\n1 8\r\n2 13\r\n2 13\r\n3 20\r\n3 14\r\n", "output": "46\r\n"}, {"input": "52 102\r\n3 199\r\n2 100\r\n2 100\r\n2 100\r\n2 100\r\n2 100\r\n2 100\r\n2 100\r\n2 100\r\n2 100\r\n2 100\r\n2 100\r\n2 100\r\n2 100\r\n2 100\r\n2 100\r\n2 100\r\n2 100\r\n2 100\r\n2 100\r\n2 100\r\n2 100\r\n2 100\r\n2 100\r\n2 100\r\n2 100\r\n2 100\r\n2 100\r\n2 100\r\n2 100\r\n2 100\r\n2 100\r\n2 100\r\n2 100\r\n2 100\r\n2 100\r\n2 100\r\n2 100\r\n2 100\r\n2 100\r\n2 100\r\n2 100\r\n2 100\r\n2 100\r\n2 100\r\n2 100\r\n2 100\r\n2 100\r\n2 100\r\n2 100\r\n2 100\r\n2 100\r\n", "output": "5100\r\n"}, {"input": "3 4\r\n1 4\r\n2 10\r\n3 100\r\n", "output": "104\r\n"}, {"input": "61 120\r\n3 5\r\n2 3\r\n2 3\r\n2 3\r\n2 3\r\n2 3\r\n2 3\r\n2 3\r\n2 3\r\n2 3\r\n2 3\r\n2 3\r\n2 3\r\n2 3\r\n2 3\r\n2 3\r\n2 3\r\n2 3\r\n2 3\r\n2 3\r\n2 3\r\n2 3\r\n2 3\r\n2 3\r\n2 3\r\n2 3\r\n2 3\r\n2 3\r\n2 3\r\n2 3\r\n2 3\r\n2 3\r\n2 3\r\n2 3\r\n2 3\r\n2 3\r\n2 3\r\n2 3\r\n2 3\r\n2 3\r\n2 3\r\n2 3\r\n2 3\r\n2 3\r\n2 3\r\n2 3\r\n2 3\r\n2 3\r\n2 3\r\n2 3\r\n2 3\r\n2 3\r\n2 3\r\n2 3\r\n2 3\r\n2 3\r\n2 3\r\n2 3\r\n2 3\r\n2 3\r\n2 3\r\n", "output": "180\r\n"}]
| false |
stdio
| null | true |
732/B
|
732
|
B
|
Python 3
|
TESTS
| 9 | 46 | 0 |
203738603
|
n , k = map(int , input().split())
l = list(map(int , input().split()))
pt1 , pt2 , add, resadd = 0 , 1 , 0 ,0
while pt2 != n :
if l[pt1] +l[pt2] < k :
add = k - (l[pt1] +l[pt2])
if l[pt1] < l[pt2] :
l[pt1] += add
else :
l[pt2] += add
resadd += add
pt1 += 1
pt2 += 1
print(resadd)
print(*l)
| 70 | 46 | 0 |
194111857
|
n,k = map(int,input().split())
lis = list(map(int,input().split()))
s1 = 0
s = 0
s += lis[0]
s1 += lis[0]
for i in range(1,n):
z = lis[i-1]+lis[i]
if z <=k:
s += lis[i]
lis[i] = k - lis[i-1]
s1 += lis[i]
print(s1-s)
for i in lis:
print(i,end=" ")
|
Codeforces Round 377 (Div. 2)
|
CF
| 2,016 | 1 | 256 |
Cormen — The Best Friend Of a Man
|
Recently a dog was bought for Polycarp. The dog's name is Cormen. Now Polycarp has a lot of troubles. For example, Cormen likes going for a walk.
Empirically Polycarp learned that the dog needs at least k walks for any two consecutive days in order to feel good. For example, if k = 5 and yesterday Polycarp went for a walk with Cormen 2 times, today he has to go for a walk at least 3 times.
Polycarp analysed all his affairs over the next n days and made a sequence of n integers a1, a2, ..., an, where ai is the number of times Polycarp will walk with the dog on the i-th day while doing all his affairs (for example, he has to go to a shop, throw out the trash, etc.).
Help Polycarp determine the minimum number of walks he needs to do additionaly in the next n days so that Cormen will feel good during all the n days. You can assume that on the day before the first day and on the day after the n-th day Polycarp will go for a walk with Cormen exactly k times.
Write a program that will find the minumum number of additional walks and the appropriate schedule — the sequence of integers b1, b2, ..., bn (bi ≥ ai), where bi means the total number of walks with the dog on the i-th day.
|
The first line contains two integers n and k (1 ≤ n, k ≤ 500) — the number of days and the minimum number of walks with Cormen for any two consecutive days.
The second line contains integers a1, a2, ..., an (0 ≤ ai ≤ 500) — the number of walks with Cormen on the i-th day which Polycarp has already planned.
|
In the first line print the smallest number of additional walks that Polycarp should do during the next n days so that Cormen will feel good during all days.
In the second line print n integers b1, b2, ..., bn, where bi — the total number of walks on the i-th day according to the found solutions (ai ≤ bi for all i from 1 to n). If there are multiple solutions, print any of them.
| null | null |
[{"input": "3 5\n2 0 1", "output": "4\n2 3 2"}, {"input": "3 1\n0 0 0", "output": "1\n0 1 0"}, {"input": "4 6\n2 4 3 5", "output": "0\n2 4 3 5"}]
| 1,000 |
["dp", "greedy"]
| 70 |
[{"input": "3 5\r\n2 0 1\r\n", "output": "4\r\n2 3 2\r\n"}, {"input": "3 1\r\n0 0 0\r\n", "output": "1\r\n0 1 0\r\n"}, {"input": "4 6\r\n2 4 3 5\r\n", "output": "0\r\n2 4 3 5\r\n"}, {"input": "5 1\r\n0 0 0 0 1\r\n", "output": "2\r\n0 1 0 1 1\r\n"}, {"input": "10 500\r\n164 44 238 205 373 249 87 30 239 90\r\n", "output": "903\r\n164 336 238 262 373 249 251 249 251 249\r\n"}, {"input": "1 1\r\n1\r\n", "output": "0\r\n1\r\n"}, {"input": "5 1\r\n0 0 0 0 0\r\n", "output": "2\r\n0 1 0 1 0\r\n"}, {"input": "5 1\r\n0 0 0 0 1\r\n", "output": "2\r\n0 1 0 1 1\r\n"}, {"input": "5 2\r\n0 0 0 1 0\r\n", "output": "3\r\n0 2 0 2 0\r\n"}, {"input": "5 5\r\n1 4 0 0 0\r\n", "output": "6\r\n1 4 1 4 1\r\n"}, {"input": "5 10\r\n1 2 1 0 1\r\n", "output": "16\r\n1 9 1 9 1\r\n"}, {"input": "5 10\r\n0 1 0 1 0\r\n", "output": "18\r\n0 10 0 10 0\r\n"}, {"input": "10 5\r\n0 2 3 0 0 1 0 2 3 1\r\n", "output": "13\r\n0 5 3 2 3 2 3 2 3 2\r\n"}, {"input": "10 1\r\n0 0 0 0 0 0 0 0 1 0\r\n", "output": "4\r\n0 1 0 1 0 1 0 1 1 0\r\n"}, {"input": "10 436\r\n13 16 45 9 10 17 5 26 10 12\r\n", "output": "2017\r\n13 423 45 391 45 391 45 391 45 391\r\n"}, {"input": "10 438\r\n71 160 43 326 128 35 41 247 30 49\r\n", "output": "1060\r\n71 367 71 367 128 310 128 310 128 310\r\n"}, {"input": "10 431\r\n121 24 93 59 243 147 1 254 75 168\r\n", "output": "1036\r\n121 310 121 310 243 188 243 254 177 254\r\n"}, {"input": "10 10\r\n0 0 0 0 0 0 0 0 0 0\r\n", "output": "50\r\n0 10 0 10 0 10 0 10 0 10\r\n"}, {"input": "10 10\r\n0 0 1 0 0 0 1 0 0 0\r\n", "output": "48\r\n0 10 1 9 1 9 1 9 1 9\r\n"}, {"input": "10 10\r\n0 0 0 1 0 0 1 0 0 0\r\n", "output": "48\r\n0 10 0 10 0 10 1 9 1 9\r\n"}, {"input": "10 10\r\n1 1 0 2 0 1 1 1 2 0\r\n", "output": "41\r\n1 9 1 9 1 9 1 9 2 8\r\n"}, {"input": "10 10\r\n1 2 2 0 0 2 0 1 0 0\r\n", "output": "42\r\n1 9 2 8 2 8 2 8 2 8\r\n"}, {"input": "10 10\r\n1 0 1 0 0 5 2 0 0 1\r\n", "output": "40\r\n1 9 1 9 1 9 2 8 2 8\r\n"}, {"input": "10 10\r\n2 3 5 0 2 0 15 6 5 0\r\n", "output": "23\r\n2 8 5 5 5 5 15 6 5 5\r\n"}, {"input": "10 10\r\n16 15 4 10 14 2 18 11 24 5\r\n", "output": "0\r\n16 15 4 10 14 2 18 11 24 5\r\n"}, {"input": "100 100\r\n48 19 63 8 18 22 5 5 12 7 9 37 17 22 58 14 53 25 24 16 22 36 4 2 9 63 52 43 22 72 0 9 12 26 50 1 21 9 40 9 5 6 2 24 1 88 50 7 9 1 3 16 0 17 3 32 47 9 32 87 20 3 45 41 16 43 41 31 28 30 2 31 72 16 74 59 20 34 25 18 48 10 34 20 22 16 3 32 8 34 8 4 45 65 48 42 1 45 11 15\r\n", "output": "2588\r\n48 52 63 37 63 37 63 37 63 37 63 37 63 37 63 37 63 37 63 37 63 37 63 37 63 63 52 48 52 72 28 72 28 72 50 50 50 50 50 50 50 50 50 50 50 88 50 50 50 50 50 50 50 50 50 50 50 50 50 87 20 80 45 55 45 55 45 55 45 55 45 55 72 28 74 59 41 59 41 59 48 52 48 52 48 52 48 52 48 52 48 52 48 65 48 52 48 52 48 52\r\n"}, {"input": "100 200\r\n28 52 65 37 1 64 13 57 44 12 37 0 9 68 17 5 28 4 2 12 8 47 7 33 1 27 50 59 9 0 4 27 31 31 49 1 35 43 36 12 5 0 49 40 19 12 39 3 41 25 19 15 57 24 3 9 4 31 42 55 11 13 1 8 0 25 34 52 47 59 74 43 36 47 2 3 1 13 56 48 42 24 4 32 12 3 33 12 14 14 84 32 1 3 8 49 9 18 43 43\r\n", "output": "7390\r\n28 172 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 74 126 74 126 74 126 74 126 74 126 74 126 74 126 74 126 74 126 74 126 84 116 84 116 84 116 84 116 84 116\r\n"}, {"input": "100 10\r\n1 2 7 0 2 0 0 0 2 5 3 2 2 1 0 7 1 6 1 1 5 1 2 3 5 0 0 0 0 0 1 0 1 0 2 1 3 0 1 1 0 0 3 1 6 3 2 2 1 3 1 0 9 1 3 2 3 0 5 1 0 5 5 5 2 1 3 0 1 3 5 2 4 4 1 2 3 0 2 1 3 6 4 3 1 0 9 1 0 3 3 6 7 2 5 2 2 6 0 2\r\n", "output": "288\r\n1 9 7 3 7 3 7 3 7 5 5 5 5 5 5 7 3 7 3 7 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 6 4 6 4 6 4 6 4 9 1 9 2 8 2 8 2 8 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 6 4 6 4 6 9 1 9 3 7 6 7 3 7 3 7 6 4 6\r\n"}, {"input": "100 500\r\n207 27 83 171 129 204 11 55 58 115 43 280 208 169 23 79 36 59 132 28 13 136 246 134 29 135 176 21 155 175 127 288 68 68 41 156 194 31 44 131 30 31 89 46 180 184 12 29 2 58 70 157 329 294 126 55 79 19 125 15 39 30 2 137 36 151 5 246 176 1 158 31 4 99 192 200 124 66 10 195 180 165 8 79 257 68 5 175 43 141 0 106 38 32 0 56 33 221 144 226\r\n", "output": "14863\r\n207 293 207 293 207 293 207 293 207 293 207 293 208 292 208 292 208 292 208 292 208 292 246 254 246 254 246 254 246 254 246 288 212 288 212 288 212 288 212 288 212 288 212 288 212 288 212 288 212 288 212 288 329 294 206 294 206 294 206 294 206 294 206 294 206 294 206 294 206 294 206 294 206 294 206 294 206 294 206 294 206 294 206 294 257 243 257 243 257 243 257 243 257 243 257 243 257 243 257 243\r\n"}, {"input": "100 500\r\n64 140 15 221 24 106 73 30 275 97 296 55 5 30 47 199 130 44 72 170 7 204 359 40 128 117 45 192 344 112 0 11 196 78 73 53 222 93 88 151 99 283 60 71 4 87 226 46 66 74 23 89 77 60 397 181 0 101 358 54 124 155 19 218 9 140 161 130 308 85 103 85 300 128 19 108 225 136 100 54 30 24 129 245 128 88 160 120 51 154 19 129 114 32 256 30 102 207 115 49\r\n", "output": "13634\r\n64 436 64 436 64 436 73 427 275 225 296 204 296 204 296 204 296 204 296 204 296 204 359 141 359 141 359 192 344 156 344 156 344 156 344 156 344 156 344 156 344 283 217 283 217 283 226 274 226 274 226 274 226 274 397 181 319 181 358 142 358 155 345 218 282 218 282 218 308 192 308 192 308 192 308 192 308 192 308 192 308 192 308 245 255 245 255 245 255 245 255 245 255 245 256 244 256 244 256 244\r\n"}, {"input": "1 500\r\n500\r\n", "output": "0\r\n500\r\n"}, {"input": "2 1\r\n0 0\r\n", "output": "1\r\n0 1\r\n"}, {"input": "1 10\r\n1\r\n", "output": "0\r\n1\r\n"}, {"input": "1 4\r\n2\r\n", "output": "0\r\n2\r\n"}, {"input": "1 10\r\n2\r\n", "output": "0\r\n2\r\n"}, {"input": "1 10\r\n0\r\n", "output": "0\r\n0\r\n"}, {"input": "1 5\r\n1\r\n", "output": "0\r\n1\r\n"}, {"input": "1 2\r\n1\r\n", "output": "0\r\n1\r\n"}, {"input": "1 5\r\n2\r\n", "output": "0\r\n2\r\n"}, {"input": "1 3\r\n0\r\n", "output": "0\r\n0\r\n"}, {"input": "1 3\r\n1\r\n", "output": "0\r\n1\r\n"}, {"input": "1 5\r\n0\r\n", "output": "0\r\n0\r\n"}, {"input": "1 7\r\n0\r\n", "output": "0\r\n0\r\n"}, {"input": "1 7\r\n1\r\n", "output": "0\r\n1\r\n"}, {"input": "1 3\r\n2\r\n", "output": "0\r\n2\r\n"}, {"input": "1 5\r\n3\r\n", "output": "0\r\n3\r\n"}, {"input": "1 4\r\n3\r\n", "output": "0\r\n3\r\n"}, {"input": "1 6\r\n1\r\n", "output": "0\r\n1\r\n"}, {"input": "1 6\r\n2\r\n", "output": "0\r\n2\r\n"}, {"input": "1 500\r\n0\r\n", "output": "0\r\n0\r\n"}, {"input": "3 7\r\n2 3 1\r\n", "output": "3\r\n2 5 2\r\n"}, {"input": "1 10\r\n5\r\n", "output": "0\r\n5\r\n"}, {"input": "5 10\r\n1 2 3 4 5\r\n", "output": "10\r\n1 9 3 7 5\r\n"}, {"input": "2 6\r\n1 2\r\n", "output": "3\r\n1 5\r\n"}, {"input": "1 10\r\n3\r\n", "output": "0\r\n3\r\n"}, {"input": "1 6\r\n3\r\n", "output": "0\r\n3\r\n"}, {"input": "1 100\r\n1\r\n", "output": "0\r\n1\r\n"}, {"input": "1 7\r\n2\r\n", "output": "0\r\n2\r\n"}, {"input": "2 10\r\n1 2\r\n", "output": "7\r\n1 9\r\n"}, {"input": "1 9\r\n1\r\n", "output": "0\r\n1\r\n"}]
| false |
stdio
| null | true |
732/B
|
732
|
B
|
Python 3
|
TESTS
| 9 | 31 | 0 |
190829496
|
a,b=map(int,input().split())
x=[int(i)for i in input().split()]
s=0
for i in range(1,len(x)):
if x[i]+x[i-1]<b:
if x[i]<=x[i-1]:
s+=b-x[i-1]-x[i]
x[i]=b-x[i-1]
else:
s+=b-x[i]-x[i+1]
x[i-1]=b-x[i]
print(s)
print(*x)
| 70 | 46 | 0 |
195054740
|
a = input().split()
b = input().split()
k = 0
k1 = ''
for i in range(len(a)):
a[i] = int(a[i])
for i in range(len(b)):
b[i] = int(b[i])
for i in range(len(b)-1):
sum2 = b[i]+b[i+1]
if sum2 < a[1]:
b[i+1] = b[i+1]+(a[1] - sum2)
k += (a[1] - sum2)
for i in range(len(b)):
k1 += str(b[i]) + ' '
print(k)
print(k1)
|
Codeforces Round 377 (Div. 2)
|
CF
| 2,016 | 1 | 256 |
Cormen — The Best Friend Of a Man
|
Recently a dog was bought for Polycarp. The dog's name is Cormen. Now Polycarp has a lot of troubles. For example, Cormen likes going for a walk.
Empirically Polycarp learned that the dog needs at least k walks for any two consecutive days in order to feel good. For example, if k = 5 and yesterday Polycarp went for a walk with Cormen 2 times, today he has to go for a walk at least 3 times.
Polycarp analysed all his affairs over the next n days and made a sequence of n integers a1, a2, ..., an, where ai is the number of times Polycarp will walk with the dog on the i-th day while doing all his affairs (for example, he has to go to a shop, throw out the trash, etc.).
Help Polycarp determine the minimum number of walks he needs to do additionaly in the next n days so that Cormen will feel good during all the n days. You can assume that on the day before the first day and on the day after the n-th day Polycarp will go for a walk with Cormen exactly k times.
Write a program that will find the minumum number of additional walks and the appropriate schedule — the sequence of integers b1, b2, ..., bn (bi ≥ ai), where bi means the total number of walks with the dog on the i-th day.
|
The first line contains two integers n and k (1 ≤ n, k ≤ 500) — the number of days and the minimum number of walks with Cormen for any two consecutive days.
The second line contains integers a1, a2, ..., an (0 ≤ ai ≤ 500) — the number of walks with Cormen on the i-th day which Polycarp has already planned.
|
In the first line print the smallest number of additional walks that Polycarp should do during the next n days so that Cormen will feel good during all days.
In the second line print n integers b1, b2, ..., bn, where bi — the total number of walks on the i-th day according to the found solutions (ai ≤ bi for all i from 1 to n). If there are multiple solutions, print any of them.
| null | null |
[{"input": "3 5\n2 0 1", "output": "4\n2 3 2"}, {"input": "3 1\n0 0 0", "output": "1\n0 1 0"}, {"input": "4 6\n2 4 3 5", "output": "0\n2 4 3 5"}]
| 1,000 |
["dp", "greedy"]
| 70 |
[{"input": "3 5\r\n2 0 1\r\n", "output": "4\r\n2 3 2\r\n"}, {"input": "3 1\r\n0 0 0\r\n", "output": "1\r\n0 1 0\r\n"}, {"input": "4 6\r\n2 4 3 5\r\n", "output": "0\r\n2 4 3 5\r\n"}, {"input": "5 1\r\n0 0 0 0 1\r\n", "output": "2\r\n0 1 0 1 1\r\n"}, {"input": "10 500\r\n164 44 238 205 373 249 87 30 239 90\r\n", "output": "903\r\n164 336 238 262 373 249 251 249 251 249\r\n"}, {"input": "1 1\r\n1\r\n", "output": "0\r\n1\r\n"}, {"input": "5 1\r\n0 0 0 0 0\r\n", "output": "2\r\n0 1 0 1 0\r\n"}, {"input": "5 1\r\n0 0 0 0 1\r\n", "output": "2\r\n0 1 0 1 1\r\n"}, {"input": "5 2\r\n0 0 0 1 0\r\n", "output": "3\r\n0 2 0 2 0\r\n"}, {"input": "5 5\r\n1 4 0 0 0\r\n", "output": "6\r\n1 4 1 4 1\r\n"}, {"input": "5 10\r\n1 2 1 0 1\r\n", "output": "16\r\n1 9 1 9 1\r\n"}, {"input": "5 10\r\n0 1 0 1 0\r\n", "output": "18\r\n0 10 0 10 0\r\n"}, {"input": "10 5\r\n0 2 3 0 0 1 0 2 3 1\r\n", "output": "13\r\n0 5 3 2 3 2 3 2 3 2\r\n"}, {"input": "10 1\r\n0 0 0 0 0 0 0 0 1 0\r\n", "output": "4\r\n0 1 0 1 0 1 0 1 1 0\r\n"}, {"input": "10 436\r\n13 16 45 9 10 17 5 26 10 12\r\n", "output": "2017\r\n13 423 45 391 45 391 45 391 45 391\r\n"}, {"input": "10 438\r\n71 160 43 326 128 35 41 247 30 49\r\n", "output": "1060\r\n71 367 71 367 128 310 128 310 128 310\r\n"}, {"input": "10 431\r\n121 24 93 59 243 147 1 254 75 168\r\n", "output": "1036\r\n121 310 121 310 243 188 243 254 177 254\r\n"}, {"input": "10 10\r\n0 0 0 0 0 0 0 0 0 0\r\n", "output": "50\r\n0 10 0 10 0 10 0 10 0 10\r\n"}, {"input": "10 10\r\n0 0 1 0 0 0 1 0 0 0\r\n", "output": "48\r\n0 10 1 9 1 9 1 9 1 9\r\n"}, {"input": "10 10\r\n0 0 0 1 0 0 1 0 0 0\r\n", "output": "48\r\n0 10 0 10 0 10 1 9 1 9\r\n"}, {"input": "10 10\r\n1 1 0 2 0 1 1 1 2 0\r\n", "output": "41\r\n1 9 1 9 1 9 1 9 2 8\r\n"}, {"input": "10 10\r\n1 2 2 0 0 2 0 1 0 0\r\n", "output": "42\r\n1 9 2 8 2 8 2 8 2 8\r\n"}, {"input": "10 10\r\n1 0 1 0 0 5 2 0 0 1\r\n", "output": "40\r\n1 9 1 9 1 9 2 8 2 8\r\n"}, {"input": "10 10\r\n2 3 5 0 2 0 15 6 5 0\r\n", "output": "23\r\n2 8 5 5 5 5 15 6 5 5\r\n"}, {"input": "10 10\r\n16 15 4 10 14 2 18 11 24 5\r\n", "output": "0\r\n16 15 4 10 14 2 18 11 24 5\r\n"}, {"input": "100 100\r\n48 19 63 8 18 22 5 5 12 7 9 37 17 22 58 14 53 25 24 16 22 36 4 2 9 63 52 43 22 72 0 9 12 26 50 1 21 9 40 9 5 6 2 24 1 88 50 7 9 1 3 16 0 17 3 32 47 9 32 87 20 3 45 41 16 43 41 31 28 30 2 31 72 16 74 59 20 34 25 18 48 10 34 20 22 16 3 32 8 34 8 4 45 65 48 42 1 45 11 15\r\n", "output": "2588\r\n48 52 63 37 63 37 63 37 63 37 63 37 63 37 63 37 63 37 63 37 63 37 63 37 63 63 52 48 52 72 28 72 28 72 50 50 50 50 50 50 50 50 50 50 50 88 50 50 50 50 50 50 50 50 50 50 50 50 50 87 20 80 45 55 45 55 45 55 45 55 45 55 72 28 74 59 41 59 41 59 48 52 48 52 48 52 48 52 48 52 48 52 48 65 48 52 48 52 48 52\r\n"}, {"input": "100 200\r\n28 52 65 37 1 64 13 57 44 12 37 0 9 68 17 5 28 4 2 12 8 47 7 33 1 27 50 59 9 0 4 27 31 31 49 1 35 43 36 12 5 0 49 40 19 12 39 3 41 25 19 15 57 24 3 9 4 31 42 55 11 13 1 8 0 25 34 52 47 59 74 43 36 47 2 3 1 13 56 48 42 24 4 32 12 3 33 12 14 14 84 32 1 3 8 49 9 18 43 43\r\n", "output": "7390\r\n28 172 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 74 126 74 126 74 126 74 126 74 126 74 126 74 126 74 126 74 126 74 126 84 116 84 116 84 116 84 116 84 116\r\n"}, {"input": "100 10\r\n1 2 7 0 2 0 0 0 2 5 3 2 2 1 0 7 1 6 1 1 5 1 2 3 5 0 0 0 0 0 1 0 1 0 2 1 3 0 1 1 0 0 3 1 6 3 2 2 1 3 1 0 9 1 3 2 3 0 5 1 0 5 5 5 2 1 3 0 1 3 5 2 4 4 1 2 3 0 2 1 3 6 4 3 1 0 9 1 0 3 3 6 7 2 5 2 2 6 0 2\r\n", "output": "288\r\n1 9 7 3 7 3 7 3 7 5 5 5 5 5 5 7 3 7 3 7 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 6 4 6 4 6 4 6 4 9 1 9 2 8 2 8 2 8 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 6 4 6 4 6 9 1 9 3 7 6 7 3 7 3 7 6 4 6\r\n"}, {"input": "100 500\r\n207 27 83 171 129 204 11 55 58 115 43 280 208 169 23 79 36 59 132 28 13 136 246 134 29 135 176 21 155 175 127 288 68 68 41 156 194 31 44 131 30 31 89 46 180 184 12 29 2 58 70 157 329 294 126 55 79 19 125 15 39 30 2 137 36 151 5 246 176 1 158 31 4 99 192 200 124 66 10 195 180 165 8 79 257 68 5 175 43 141 0 106 38 32 0 56 33 221 144 226\r\n", "output": "14863\r\n207 293 207 293 207 293 207 293 207 293 207 293 208 292 208 292 208 292 208 292 208 292 246 254 246 254 246 254 246 254 246 288 212 288 212 288 212 288 212 288 212 288 212 288 212 288 212 288 212 288 212 288 329 294 206 294 206 294 206 294 206 294 206 294 206 294 206 294 206 294 206 294 206 294 206 294 206 294 206 294 206 294 206 294 257 243 257 243 257 243 257 243 257 243 257 243 257 243 257 243\r\n"}, {"input": "100 500\r\n64 140 15 221 24 106 73 30 275 97 296 55 5 30 47 199 130 44 72 170 7 204 359 40 128 117 45 192 344 112 0 11 196 78 73 53 222 93 88 151 99 283 60 71 4 87 226 46 66 74 23 89 77 60 397 181 0 101 358 54 124 155 19 218 9 140 161 130 308 85 103 85 300 128 19 108 225 136 100 54 30 24 129 245 128 88 160 120 51 154 19 129 114 32 256 30 102 207 115 49\r\n", "output": "13634\r\n64 436 64 436 64 436 73 427 275 225 296 204 296 204 296 204 296 204 296 204 296 204 359 141 359 141 359 192 344 156 344 156 344 156 344 156 344 156 344 156 344 283 217 283 217 283 226 274 226 274 226 274 226 274 397 181 319 181 358 142 358 155 345 218 282 218 282 218 308 192 308 192 308 192 308 192 308 192 308 192 308 192 308 245 255 245 255 245 255 245 255 245 255 245 256 244 256 244 256 244\r\n"}, {"input": "1 500\r\n500\r\n", "output": "0\r\n500\r\n"}, {"input": "2 1\r\n0 0\r\n", "output": "1\r\n0 1\r\n"}, {"input": "1 10\r\n1\r\n", "output": "0\r\n1\r\n"}, {"input": "1 4\r\n2\r\n", "output": "0\r\n2\r\n"}, {"input": "1 10\r\n2\r\n", "output": "0\r\n2\r\n"}, {"input": "1 10\r\n0\r\n", "output": "0\r\n0\r\n"}, {"input": "1 5\r\n1\r\n", "output": "0\r\n1\r\n"}, {"input": "1 2\r\n1\r\n", "output": "0\r\n1\r\n"}, {"input": "1 5\r\n2\r\n", "output": "0\r\n2\r\n"}, {"input": "1 3\r\n0\r\n", "output": "0\r\n0\r\n"}, {"input": "1 3\r\n1\r\n", "output": "0\r\n1\r\n"}, {"input": "1 5\r\n0\r\n", "output": "0\r\n0\r\n"}, {"input": "1 7\r\n0\r\n", "output": "0\r\n0\r\n"}, {"input": "1 7\r\n1\r\n", "output": "0\r\n1\r\n"}, {"input": "1 3\r\n2\r\n", "output": "0\r\n2\r\n"}, {"input": "1 5\r\n3\r\n", "output": "0\r\n3\r\n"}, {"input": "1 4\r\n3\r\n", "output": "0\r\n3\r\n"}, {"input": "1 6\r\n1\r\n", "output": "0\r\n1\r\n"}, {"input": "1 6\r\n2\r\n", "output": "0\r\n2\r\n"}, {"input": "1 500\r\n0\r\n", "output": "0\r\n0\r\n"}, {"input": "3 7\r\n2 3 1\r\n", "output": "3\r\n2 5 2\r\n"}, {"input": "1 10\r\n5\r\n", "output": "0\r\n5\r\n"}, {"input": "5 10\r\n1 2 3 4 5\r\n", "output": "10\r\n1 9 3 7 5\r\n"}, {"input": "2 6\r\n1 2\r\n", "output": "3\r\n1 5\r\n"}, {"input": "1 10\r\n3\r\n", "output": "0\r\n3\r\n"}, {"input": "1 6\r\n3\r\n", "output": "0\r\n3\r\n"}, {"input": "1 100\r\n1\r\n", "output": "0\r\n1\r\n"}, {"input": "1 7\r\n2\r\n", "output": "0\r\n2\r\n"}, {"input": "2 10\r\n1 2\r\n", "output": "7\r\n1 9\r\n"}, {"input": "1 9\r\n1\r\n", "output": "0\r\n1\r\n"}]
| false |
stdio
| null | true |
928/B
|
928
|
B
|
PyPy 3
|
TESTS
| 101 | 327 | 31,027,200 |
35816823
|
s = input().split()
n = int(s[0])
k = int(s[1])
a = [int(i) for i in input().split()]
if n < k+2:
print(str(n)+(' ' + str(n))*(n-1))
else:
twok = k*2+1
counts = []
for i in range(1, k+1):
counts.append(i + k)
for i in range(k+1, n-k):
if a[i-1] == 0:
counts.append(twok)
else:
p = i - a[i-1]
if p < twok:
counts.append(counts[a[i-1]-1]+p)
else:
counts.append(counts[a[i-1]-1]+twok)
for i in range(n-k, n+1):
if a[i-1] == 0:
counts.append(n-i+1+k)
elif n-k < a[i-1]:
counts.append(counts[a[i-1]-1])
else:
p = i - a[i-1]
if p < twok:
counts.append(counts[a[i-1]-1]+n-i-k+p)
else:
counts.append(counts[a[i-1]-1]+n-i+1+k)
print(counts[0], end='')
[print(' ' + str(counts[i]), end='') for i in range(1,n)]
| 118 | 109 | 18,636,800 |
188658526
|
n, k = map(int, input().split())
a = list(map(int, input().split()))
dp = [0] * n
for i in range(n):
if a[i] == 0:
s = min(k, i) + 1
else:
s = dp[a[i] - 1] + min(2 * k, i - a[i]) + 1
dp[i] = s
an = []
for i in range(n):
an.append(str(dp[i] + min(k, n - i - 1)))
print(" ".join(an))
|
VK Cup 2018 - Квалификация 1
|
CF
| 2,018 | 1 | 256 |
Chat
|
There are times you recall a good old friend and everything you've come through together. Luckily there are social networks — they store all your message history making it easy to know what you argued over 10 years ago.
More formal, your message history is a sequence of messages ordered by time sent numbered from 1 to n where n is the total number of messages in the chat.
Each message might contain a link to an earlier message which it is a reply to. When opening a message x or getting a link to it, the dialogue is shown in such a way that k previous messages, message x and k next messages are visible (with respect to message x). In case there are less than k messages somewhere, they are yet all shown.
Digging deep into your message history, you always read all visible messages and then go by the link in the current message x (if there is one) and continue reading in the same manner.
Determine the number of messages you'll read if your start from message number t for all t from 1 to n. Calculate these numbers independently. If you start with message x, the initial configuration is x itself, k previous and k next messages. Messages read multiple times are considered as one.
|
The first line contains two integers n and k (1 ≤ n ≤ 105, 0 ≤ k ≤ n) — the total amount of messages and the number of previous and next messages visible.
The second line features a sequence of integers a1, a2, ..., an (0 ≤ ai < i), where ai denotes the i-th message link destination or zero, if there's no link from i. All messages are listed in chronological order. It's guaranteed that the link from message x goes to message with number strictly less than x.
|
Print n integers with i-th denoting the number of distinct messages you can read starting from message i and traversing the links while possible.
| null |
Consider i = 6 in sample case one. You will read message 6, then 2, then 1 and then there will be no link to go.
In the second sample case i = 6 gives you messages 5, 6, 7 since k = 1, then 4, 5, 6, then 2, 3, 4 and then the link sequence breaks. The number of distinct messages here is equal to 6.
|
[{"input": "6 0\n0 1 1 2 3 2", "output": "1 2 2 3 3 3"}, {"input": "10 1\n0 1 0 3 4 5 2 3 7 0", "output": "2 3 3 4 5 6 6 6 8 2"}, {"input": "2 2\n0 1", "output": "2 2"}]
| 1,400 |
["*special", "dp"]
| 118 |
[{"input": "6 0\r\n0 1 1 2 3 2\r\n", "output": "1 2 2 3 3 3 \r\n"}, {"input": "10 1\r\n0 1 0 3 4 5 2 3 7 0\r\n", "output": "2 3 3 4 5 6 6 6 8 2 \r\n"}, {"input": "2 2\r\n0 1\r\n", "output": "2 2 \r\n"}, {"input": "1 1\r\n0\r\n", "output": "1 \r\n"}, {"input": "5 2\r\n0 1 2 3 1\r\n", "output": "3 4 5 5 5 \r\n"}, {"input": "30 1\r\n0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 2 0 0 0 0 0 2 1 0\r\n", "output": "2 3 3 3 3 3 3 3 3 3 3 3 3 5 5 5 3 3 3 3 3 6 3 3 3 3 3 6 5 2 \r\n"}, {"input": "100 5\r\n0 1 1 1 0 5 6 6 8 8 9 11 12 11 8 0 0 14 6 16 7 21 15 23 15 24 0 0 0 28 0 29 26 27 19 0 0 21 37 32 40 30 37 34 39 38 34 38 0 0 41 24 45 47 0 33 46 26 31 0 21 57 57 31 63 63 25 59 65 56 68 0 30 55 55 0 70 43 59 49 59 79 66 74 0 11 65 0 80 63 0 84 73 49 73 81 0 86 76 98\r\n", "output": "6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 11 11 23 22 15 23 24 28 29 30 31 11 11 11 13 11 14 38 18 33 11 11 34 13 22 23 24 17 28 19 42 29 44 11 11 33 40 27 36 11 49 53 42 22 11 34 58 59 22 61 62 41 31 65 60 34 11 24 22 22 11 67 28 33 22 33 36 73 32 11 27 72 11 31 70 11 40 35 22 35 43 9 35 18 35 \r\n"}, {"input": "2 2\r\n0 0\r\n", "output": "2 2 \r\n"}, {"input": "2 1\r\n0 0\r\n", "output": "2 2 \r\n"}, {"input": "2 1\r\n0 1\r\n", "output": "2 2 \r\n"}, {"input": "2 0\r\n0 0\r\n", "output": "1 1 \r\n"}, {"input": "2 0\r\n0 1\r\n", "output": "1 2 \r\n"}, {"input": "3 0\r\n0 0 0\r\n", "output": "1 1 1 \r\n"}, {"input": "3 0\r\n0 0 1\r\n", "output": "1 1 2 \r\n"}, {"input": "3 0\r\n0 0 2\r\n", "output": "1 1 2 \r\n"}, {"input": "3 0\r\n0 1 0\r\n", "output": "1 2 1 \r\n"}, {"input": "3 0\r\n0 1 1\r\n", "output": "1 2 2 \r\n"}, {"input": "3 0\r\n0 1 2\r\n", "output": "1 2 3 \r\n"}, {"input": "3 1\r\n0 0 0\r\n", "output": "2 3 2 \r\n"}, {"input": "3 1\r\n0 0 1\r\n", "output": "2 3 3 \r\n"}, {"input": "3 1\r\n0 0 2\r\n", "output": "2 3 3 \r\n"}, {"input": "3 1\r\n0 1 0\r\n", "output": "2 3 2 \r\n"}, {"input": "3 1\r\n0 1 1\r\n", "output": "2 3 3 \r\n"}, {"input": "3 1\r\n0 1 2\r\n", "output": "2 3 3 \r\n"}, {"input": "3 2\r\n0 0 0\r\n", "output": "3 3 3 \r\n"}, {"input": "3 2\r\n0 0 1\r\n", "output": "3 3 3 \r\n"}, {"input": "3 2\r\n0 0 2\r\n", "output": "3 3 3 \r\n"}, {"input": "3 2\r\n0 1 0\r\n", "output": "3 3 3 \r\n"}, {"input": "3 2\r\n0 1 1\r\n", "output": "3 3 3 \r\n"}, {"input": "3 2\r\n0 1 2\r\n", "output": "3 3 3 \r\n"}, {"input": "3 3\r\n0 0 0\r\n", "output": "3 3 3 \r\n"}, {"input": "3 3\r\n0 0 1\r\n", "output": "3 3 3 \r\n"}, {"input": "3 3\r\n0 0 2\r\n", "output": "3 3 3 \r\n"}, {"input": "3 3\r\n0 1 0\r\n", "output": "3 3 3 \r\n"}, {"input": "3 3\r\n0 1 1\r\n", "output": "3 3 3 \r\n"}, {"input": "3 3\r\n0 1 2\r\n", "output": "3 3 3 \r\n"}, {"input": "10 3\r\n0 0 0 0 0 0 0 4 0 4\r\n", "output": "4 5 6 7 7 7 7 10 5 10 \r\n"}, {"input": "20 2\r\n0 0 0 0 2 1 0 3 0 1 1 11 0 10 0 0 9 17 9 0\r\n", "output": "3 4 5 5 7 8 5 10 5 8 8 9 5 12 5 5 10 11 9 3 \r\n"}, {"input": "40 0\r\n0 1 2 3 4 5 0 0 0 0 0 11 12 0 14 10 0 16 15 0 19 21 22 0 23 25 25 24 24 29 29 0 0 31 0 35 31 36 34 29\r\n", "output": "1 2 3 4 5 6 1 1 1 1 1 2 3 1 2 2 1 3 3 1 4 5 6 1 7 8 8 2 2 3 3 1 1 4 1 2 4 3 5 3 \r\n"}]
| false |
stdio
| null | true |
493/B
|
493
|
B
|
Python 3
|
TESTS
| 37 | 405 | 5,529,600 |
8960253
|
n = int(input())
a = []
b = []
last = 0
for i in range(n):
q = int(input())
if q > 0:
a.append(q)
last = 1
else:
b.append(-q)
last = 2
sum1 = sum(a)
sum2 = sum(b)
if sum1 > sum2:
print('first')
elif sum1 < sum2:
print('second')
else:
s1 = ' '.join(map(str, a))
s2 = ' '.join(map(str, b))
if s1 > s2:
print('first')
elif s1 < s2:
print('second')
else:
if last == 1: print('first')
if last == 2: print('second')
| 57 | 202 | 14,131,200 |
125235884
|
#import collections
# import random
# import math
#import itertools
#import math
#mport math
from collections import defaultdict
# import itertools
# from sys import stdin, stdout
#import math
import sys
# import operator
# from decimal import Decimal
# sys.setrecursionlimit(10**6)
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.buffer.readline())
def MI(): return map(int, sys.stdin.buffer.readline().split())
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def BI(): return sys.stdin.buffer.readline().rstrip()
def SI(): return sys.stdin.buffer.readline().rstrip().decode()
def li(): return [int(i) for i in input().split()]
def lli(rows): return [li() for _ in range(rows)]
def si(): return input()
def ii(): return int(input())
def ins(): return input().split()
def solve():
n = II()
pos = []; neg = []; all = []
for _ in range(n):
x = II()
all.append(x)
if x<0:
neg.append(x)
else:
pos.append(x)
if sum(pos)>-sum(neg):
print("first")
return
elif -sum(neg)>sum(pos):
print("second")
return
else:
p = len(pos)
n = len(neg)
for i in range(min(p,n)):
if pos[i]>-neg[i]:
print("first")
break
elif pos[i]<-neg[i]:
print('second')
break
else:
if p == n:
if all[-1]>0: \
print("first")
else:
print('second')
else:
if p>n:
print('first')
else:
print('second')
return
def main():
# for _ in range(II()):
# sys.stdout.write(str(solve()) + "\n")
solve()
# z += str(ans) + '\n'
# print(len(ans), ' '.join(map(str, ans)), sep='\n')
# stdout.write(z)
# for interactive problems
# print("? {} {}".format(l,m), flush=True)
# or print this after each print statement
# sys.stdout.flush()
if __name__ == "__main__":
main()
|
Codeforces Round 281 (Div. 2)
|
CF
| 2,014 | 2 | 256 |
Vasya and Wrestling
|
Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins.
When the numbers of points of both wrestlers are equal, the wrestler whose sequence of points is lexicographically greater, wins.
If the sequences of the awarded points coincide, the wrestler who performed the last technique wins. Your task is to determine which wrestler won.
|
The first line contains number n — the number of techniques that the wrestlers have used (1 ≤ n ≤ 2·105).
The following n lines contain integer numbers ai (|ai| ≤ 109, ai ≠ 0). If ai is positive, that means that the first wrestler performed the technique that was awarded with ai points. And if ai is negative, that means that the second wrestler performed the technique that was awarded with ( - ai) points.
The techniques are given in chronological order.
|
If the first wrestler wins, print string "first", otherwise print "second"
| null |
Sequence x = x1x2... x|x| is lexicographically larger than sequence y = y1y2... y|y|, if either |x| > |y| and x1 = y1, x2 = y2, ... , x|y| = y|y|, or there is such number r (r < |x|, r < |y|), that x1 = y1, x2 = y2, ... , xr = yr and xr + 1 > yr + 1.
We use notation |a| to denote length of sequence a.
|
[{"input": "5\n1\n2\n-3\n-4\n3", "output": "second"}, {"input": "3\n-1\n-2\n3", "output": "first"}, {"input": "2\n4\n-4", "output": "second"}]
| 1,400 |
["implementation"]
| 57 |
[{"input": "5\r\n1\r\n2\r\n-3\r\n-4\r\n3\r\n", "output": "second\r\n"}, {"input": "3\r\n-1\r\n-2\r\n3\r\n", "output": "first\r\n"}, {"input": "2\r\n4\r\n-4\r\n", "output": "second\r\n"}, {"input": "7\r\n1\r\n2\r\n-3\r\n4\r\n5\r\n-6\r\n7\r\n", "output": "first\r\n"}, {"input": "14\r\n1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n-8\r\n-9\r\n-10\r\n-11\r\n-12\r\n-13\r\n-14\r\n", "output": "second\r\n"}, {"input": "4\r\n16\r\n12\r\n19\r\n-98\r\n", "output": "second\r\n"}, {"input": "5\r\n-6\r\n-1\r\n-1\r\n5\r\n3\r\n", "output": "second\r\n"}, {"input": "11\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n", "output": "first\r\n"}, {"input": "1\r\n-534365\r\n", "output": "second\r\n"}, {"input": "1\r\n10253033\r\n", "output": "first\r\n"}, {"input": "3\r\n-1\r\n-2\r\n3\r\n", "output": "first\r\n"}, {"input": "8\r\n1\r\n-2\r\n-3\r\n4\r\n5\r\n-6\r\n-7\r\n8\r\n", "output": "second\r\n"}, {"input": "2\r\n1\r\n-1\r\n", "output": "second\r\n"}, {"input": "5\r\n1\r\n2\r\n3\r\n4\r\n5\r\n", "output": "first\r\n"}, {"input": "5\r\n-1\r\n-2\r\n-3\r\n-4\r\n-5\r\n", "output": "second\r\n"}, {"input": "10\r\n-1\r\n-2\r\n-3\r\n-4\r\n-5\r\n5\r\n4\r\n3\r\n2\r\n1\r\n", "output": "first\r\n"}, {"input": "131\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n-1\r\n-1\r\n2\r\n", "output": "first\r\n"}, {"input": "6\r\n-1\r\n-2\r\n-3\r\n1\r\n2\r\n3\r\n", "output": "first\r\n"}, {"input": "3\r\n1000000000\r\n1000000000\r\n1000000000\r\n", "output": "first\r\n"}, {"input": "12\r\n1000000000\r\n1000000000\r\n1000000000\r\n1000000000\r\n1000000000\r\n1000000000\r\n1000000000\r\n1000000000\r\n1000000000\r\n1000000000\r\n1000000000\r\n1000000000\r\n", "output": "first\r\n"}, {"input": "4\r\n1000000000\r\n1000000000\r\n1000000000\r\n-1000000000\r\n", "output": "first\r\n"}, {"input": "20\r\n1000000000\r\n1000000000\r\n1000000000\r\n1000000000\r\n1000000000\r\n1000000000\r\n1000000000\r\n1000000000\r\n1000000000\r\n1000000000\r\n1000000000\r\n1000000000\r\n1000000000\r\n1000000000\r\n1000000000\r\n1000000000\r\n1000000000\r\n1000000000\r\n1000000000\r\n1000000000\r\n", "output": "first\r\n"}, {"input": "5\r\n1000000000\r\n1000000000\r\n-1000000000\r\n-1000000000\r\n-1000000000\r\n", "output": "second\r\n"}, {"input": "4\r\n1\r\n-1000000000\r\n-1000000000\r\n-1000000000\r\n", "output": "second\r\n"}, {"input": "5\r\n1000000000\r\n1000000000\r\n1000000000\r\n-1000000000\r\n-1000000000\r\n", "output": "first\r\n"}, {"input": "4\r\n-1\r\n1000000000\r\n1000000000\r\n1000000000\r\n", "output": "first\r\n"}, {"input": "11\r\n1000000000\r\n1000000000\r\n1000000000\r\n1000000000\r\n1000000000\r\n1000000000\r\n1000000000\r\n1000000000\r\n1000000000\r\n1000000000\r\n1000000000\r\n", "output": "first\r\n"}, {"input": "2\r\n-4\r\n4\r\n", "output": "first\r\n"}, {"input": "3\r\n-12\r\n3\r\n9\r\n", "output": "second\r\n"}, {"input": "3\r\n9\r\n1\r\n-10\r\n", "output": "second\r\n"}, {"input": "3\r\n1\r\n2\r\n-3\r\n", "output": "second\r\n"}, {"input": "4\r\n55\r\n5\r\n-5\r\n-55\r\n", "output": "first\r\n"}, {"input": "4\r\n5\r\n-1\r\n1\r\n-5\r\n", "output": "first\r\n"}, {"input": "2\r\n-5\r\n6\r\n", "output": "first\r\n"}, {"input": "4\r\n5\r\n-4\r\n3\r\n-40\r\n", "output": "second\r\n"}, {"input": "4\r\n1000000000\r\n1000000000\r\n1000000000\r\n-5\r\n", "output": "first\r\n"}, {"input": "6\r\n3\r\n2\r\n1\r\n-3\r\n-1\r\n-2\r\n", "output": "first\r\n"}, {"input": "5\r\n4\r\n1\r\n1\r\n-3\r\n-3\r\n", "output": "first\r\n"}, {"input": "5\r\n208\r\n-52\r\n-52\r\n-52\r\n-52\r\n", "output": "first\r\n"}, {"input": "3\r\n-100\r\n-200\r\n300\r\n", "output": "first\r\n"}, {"input": "3\r\n400\r\n-200\r\n-200\r\n", "output": "first\r\n"}, {"input": "3\r\n208\r\n-207\r\n-1\r\n", "output": "first\r\n"}, {"input": "3\r\n98888887\r\n98888888\r\n-197777775\r\n", "output": "second\r\n"}]
| false |
stdio
| null | true |
493/B
|
493
|
B
|
Python 3
|
TESTS
| 37 | 374 | 5,734,400 |
67468925
|
f=[]
s=[]
l=-1
for _ in range(int(input())):
x = int(input())
if x<0:
s.append(-x)
l=1
else:
f.append(x)
l=0
if sum(f)>sum(s):
print('first')
elif sum(f)<sum(s):
print("second")
else:
if f == s:
print("fsiercsotn d"[l::2])
elif str(f)<str(s):
print("second")
else:
print("first")
| 57 | 249 | 5,632,000 |
103979422
|
import sys
input = sys.stdin.buffer.readline
n = int(input())
w1=0
w2=0
s1=[]
s2=[]
last = 0
for i in range(n):
pts = int(input())
if pts>0:
s1.append(pts)
w1+=pts
else:
s2.append(abs(pts))
w2+=abs(pts)
if i==n-1:
last = pts
mini = min(len(s1),len(s2))
gre = 0
for i in range(mini):
if s1[i]>s2[i]:
gre=1
break
elif s1[i]<s2[i]:
gre=2
break
if gre==0:
if len(s1)>len(s2):
gre=1
elif len(s1)<len(s2):
gre=2
if w1>w2:
print("first")
elif w2>w1:
print("second")
elif w1==w2:
if gre==1:
print("first")
elif gre==2:
print("second")
elif gre==0:
if last>0:
print("first")
else:
print("second")
|
Codeforces Round 281 (Div. 2)
|
CF
| 2,014 | 2 | 256 |
Vasya and Wrestling
|
Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins.
When the numbers of points of both wrestlers are equal, the wrestler whose sequence of points is lexicographically greater, wins.
If the sequences of the awarded points coincide, the wrestler who performed the last technique wins. Your task is to determine which wrestler won.
|
The first line contains number n — the number of techniques that the wrestlers have used (1 ≤ n ≤ 2·105).
The following n lines contain integer numbers ai (|ai| ≤ 109, ai ≠ 0). If ai is positive, that means that the first wrestler performed the technique that was awarded with ai points. And if ai is negative, that means that the second wrestler performed the technique that was awarded with ( - ai) points.
The techniques are given in chronological order.
|
If the first wrestler wins, print string "first", otherwise print "second"
| null |
Sequence x = x1x2... x|x| is lexicographically larger than sequence y = y1y2... y|y|, if either |x| > |y| and x1 = y1, x2 = y2, ... , x|y| = y|y|, or there is such number r (r < |x|, r < |y|), that x1 = y1, x2 = y2, ... , xr = yr and xr + 1 > yr + 1.
We use notation |a| to denote length of sequence a.
|
[{"input": "5\n1\n2\n-3\n-4\n3", "output": "second"}, {"input": "3\n-1\n-2\n3", "output": "first"}, {"input": "2\n4\n-4", "output": "second"}]
| 1,400 |
["implementation"]
| 57 |
[{"input": "5\r\n1\r\n2\r\n-3\r\n-4\r\n3\r\n", "output": "second\r\n"}, {"input": "3\r\n-1\r\n-2\r\n3\r\n", "output": "first\r\n"}, {"input": "2\r\n4\r\n-4\r\n", "output": "second\r\n"}, {"input": "7\r\n1\r\n2\r\n-3\r\n4\r\n5\r\n-6\r\n7\r\n", "output": "first\r\n"}, {"input": "14\r\n1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n-8\r\n-9\r\n-10\r\n-11\r\n-12\r\n-13\r\n-14\r\n", "output": "second\r\n"}, {"input": "4\r\n16\r\n12\r\n19\r\n-98\r\n", "output": "second\r\n"}, {"input": "5\r\n-6\r\n-1\r\n-1\r\n5\r\n3\r\n", "output": "second\r\n"}, {"input": "11\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n", "output": "first\r\n"}, {"input": "1\r\n-534365\r\n", "output": "second\r\n"}, {"input": "1\r\n10253033\r\n", "output": "first\r\n"}, {"input": "3\r\n-1\r\n-2\r\n3\r\n", "output": "first\r\n"}, {"input": "8\r\n1\r\n-2\r\n-3\r\n4\r\n5\r\n-6\r\n-7\r\n8\r\n", "output": "second\r\n"}, {"input": "2\r\n1\r\n-1\r\n", "output": "second\r\n"}, {"input": "5\r\n1\r\n2\r\n3\r\n4\r\n5\r\n", "output": "first\r\n"}, {"input": "5\r\n-1\r\n-2\r\n-3\r\n-4\r\n-5\r\n", "output": "second\r\n"}, {"input": "10\r\n-1\r\n-2\r\n-3\r\n-4\r\n-5\r\n5\r\n4\r\n3\r\n2\r\n1\r\n", "output": "first\r\n"}, {"input": "131\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n1\r\n-1\r\n-1\r\n-1\r\n2\r\n", "output": "first\r\n"}, {"input": "6\r\n-1\r\n-2\r\n-3\r\n1\r\n2\r\n3\r\n", "output": "first\r\n"}, {"input": "3\r\n1000000000\r\n1000000000\r\n1000000000\r\n", "output": "first\r\n"}, {"input": "12\r\n1000000000\r\n1000000000\r\n1000000000\r\n1000000000\r\n1000000000\r\n1000000000\r\n1000000000\r\n1000000000\r\n1000000000\r\n1000000000\r\n1000000000\r\n1000000000\r\n", "output": "first\r\n"}, {"input": "4\r\n1000000000\r\n1000000000\r\n1000000000\r\n-1000000000\r\n", "output": "first\r\n"}, {"input": "20\r\n1000000000\r\n1000000000\r\n1000000000\r\n1000000000\r\n1000000000\r\n1000000000\r\n1000000000\r\n1000000000\r\n1000000000\r\n1000000000\r\n1000000000\r\n1000000000\r\n1000000000\r\n1000000000\r\n1000000000\r\n1000000000\r\n1000000000\r\n1000000000\r\n1000000000\r\n1000000000\r\n", "output": "first\r\n"}, {"input": "5\r\n1000000000\r\n1000000000\r\n-1000000000\r\n-1000000000\r\n-1000000000\r\n", "output": "second\r\n"}, {"input": "4\r\n1\r\n-1000000000\r\n-1000000000\r\n-1000000000\r\n", "output": "second\r\n"}, {"input": "5\r\n1000000000\r\n1000000000\r\n1000000000\r\n-1000000000\r\n-1000000000\r\n", "output": "first\r\n"}, {"input": "4\r\n-1\r\n1000000000\r\n1000000000\r\n1000000000\r\n", "output": "first\r\n"}, {"input": "11\r\n1000000000\r\n1000000000\r\n1000000000\r\n1000000000\r\n1000000000\r\n1000000000\r\n1000000000\r\n1000000000\r\n1000000000\r\n1000000000\r\n1000000000\r\n", "output": "first\r\n"}, {"input": "2\r\n-4\r\n4\r\n", "output": "first\r\n"}, {"input": "3\r\n-12\r\n3\r\n9\r\n", "output": "second\r\n"}, {"input": "3\r\n9\r\n1\r\n-10\r\n", "output": "second\r\n"}, {"input": "3\r\n1\r\n2\r\n-3\r\n", "output": "second\r\n"}, {"input": "4\r\n55\r\n5\r\n-5\r\n-55\r\n", "output": "first\r\n"}, {"input": "4\r\n5\r\n-1\r\n1\r\n-5\r\n", "output": "first\r\n"}, {"input": "2\r\n-5\r\n6\r\n", "output": "first\r\n"}, {"input": "4\r\n5\r\n-4\r\n3\r\n-40\r\n", "output": "second\r\n"}, {"input": "4\r\n1000000000\r\n1000000000\r\n1000000000\r\n-5\r\n", "output": "first\r\n"}, {"input": "6\r\n3\r\n2\r\n1\r\n-3\r\n-1\r\n-2\r\n", "output": "first\r\n"}, {"input": "5\r\n4\r\n1\r\n1\r\n-3\r\n-3\r\n", "output": "first\r\n"}, {"input": "5\r\n208\r\n-52\r\n-52\r\n-52\r\n-52\r\n", "output": "first\r\n"}, {"input": "3\r\n-100\r\n-200\r\n300\r\n", "output": "first\r\n"}, {"input": "3\r\n400\r\n-200\r\n-200\r\n", "output": "first\r\n"}, {"input": "3\r\n208\r\n-207\r\n-1\r\n", "output": "first\r\n"}, {"input": "3\r\n98888887\r\n98888888\r\n-197777775\r\n", "output": "second\r\n"}]
| false |
stdio
| null | true |
849/B
|
849
|
B
|
Python 3
|
TESTS
| 25 | 93 | 7,065,600 |
36772636
|
def solve(curr_slope,s,i):
if len(s)==1:
return True
elif curr_slope==i:
return True
else:
return False
n=int(input())
arr=list(map(int,input().split()))
d={}
for i in range(1,len(arr)):
slope=(arr[i]-arr[0])/float(i)
if slope in d.keys():
d[slope].add(i)
else:
d[slope]=set([i])
ans=0
#print(d)
for i in d.keys():
flag=0
k=1
while k<len(arr) and k in d[i]:
k+=1
if k==len(arr):
ans=0
break
curr_slope=None
for j in range(k+1,len(arr)):
#print(curr_slope,j,k)
if j not in d[i]:
slope=(arr[j]-arr[k])/float(j-k)
if curr_slope!=None and slope!=curr_slope:
flag=1
break
if curr_slope==None:
curr_slope=slope
if flag==0 and solve(curr_slope,d[i],i):
ans=1
break
if ans==0:
print("No")
else:
print("Yes")
| 52 | 62 | 307,200 |
29993038
|
def test(id1,id2,l,n):
a = l[id1] - l[id2]
b = id2 - id1
c = ((id1)*l[id2]) - ((id2)*l[id1])
d=[]
for i in range(n):
if a*i+b*l[i]+c!=0:
d+=[i]
if len(d)==0:return False
if len(d)==1:return True
aa = l[d[0]] - l[d[1]]
bb = d[1] - d[0]
cc = ((d[0])*l[d[1]]) - ((d[1])*l[d[0]])
for i in range(len(d)):
if aa*d[i]+bb*l[d[i]]+cc!=0:
return False
return (l[id1]-l[id2])/(id1-id2)==(l[d[1]]-l[d[0]])/(d[1]-d[0])
n=int(input())
l=[int(i)for i in input().split()]
print("Yes"if test(0,1,l,n) or test(1,2,l,n) or test(0,2,l,n) else "No" )
|
Codeforces Round 431 (Div. 2)
|
CF
| 2,017 | 1 | 256 |
Tell Your World
|
Connect the countless points with lines, till we reach the faraway yonder.
There are n points on a coordinate plane, the i-th of which being (i, yi).
Determine whether it's possible to draw two parallel and non-overlapping lines, such that every point in the set lies on exactly one of them, and each of them passes through at least one point in the set.
|
The first line of input contains a positive integer n (3 ≤ n ≤ 1 000) — the number of points.
The second line contains n space-separated integers y1, y2, ..., yn ( - 109 ≤ yi ≤ 109) — the vertical coordinates of each point.
|
Output "Yes" (without quotes) if it's possible to fulfill the requirements, and "No" otherwise.
You can print each letter in any case (upper or lower).
| null |
In the first example, there are five points: (1, 7), (2, 5), (3, 8), (4, 6) and (5, 9). It's possible to draw a line that passes through points 1, 3, 5, and another one that passes through points 2, 4 and is parallel to the first one.
In the second example, while it's possible to draw two lines that cover all points, they cannot be made parallel.
In the third example, it's impossible to satisfy both requirements at the same time.
|
[{"input": "5\n7 5 8 6 9", "output": "Yes"}, {"input": "5\n-1 -2 0 0 -5", "output": "No"}, {"input": "5\n5 4 3 2 1", "output": "No"}, {"input": "5\n1000000000 0 0 0 0", "output": "Yes"}]
| 1,600 |
["brute force", "geometry"]
| 52 |
[{"input": "5\r\n7 5 8 6 9\r\n", "output": "Yes\r\n"}, {"input": "5\r\n-1 -2 0 0 -5\r\n", "output": "No\r\n"}, {"input": "5\r\n5 4 3 2 1\r\n", "output": "No\r\n"}, {"input": "5\r\n1000000000 0 0 0 0\r\n", "output": "Yes\r\n"}, {"input": "5\r\n1000000000 1 0 -999999999 -1000000000\r\n", "output": "Yes\r\n"}, {"input": "3\r\n998 244 353\r\n", "output": "Yes\r\n"}, {"input": "3\r\n-1000000000 0 1000000000\r\n", "output": "No\r\n"}, {"input": "5\r\n-1 -1 -1 -1 1\r\n", "output": "Yes\r\n"}, {"input": "4\r\n-9763 530 3595 6660\r\n", "output": "Yes\r\n"}, {"input": "4\r\n-253090305 36298498 374072642 711846786\r\n", "output": "Yes\r\n"}, {"input": "5\r\n-186772848 -235864239 -191561068 -193955178 -243046569\r\n", "output": "Yes\r\n"}, {"input": "5\r\n-954618456 -522919664 -248330428 -130850748 300848044\r\n", "output": "Yes\r\n"}, {"input": "10\r\n4846 6705 2530 5757 5283 -944 -2102 -3260 -4418 2913\r\n", "output": "No\r\n"}, {"input": "10\r\n-6568 -5920 -5272 -4624 -2435 -635 -2680 -2032 -1384 6565\r\n", "output": "No\r\n"}, {"input": "20\r\n319410377 286827025 254243673 221660321 189076969 156493617 123910265 91326913 58743561 26160209 -6423143 -39006495 -71589847 -104173199 -136756551 -169339903 -201923255 -234506607 -267089959 -299673311\r\n", "output": "No\r\n"}, {"input": "20\r\n-975467170 758268840 -975467171 758268839 -975467172 758268838 -975467173 758268837 -975467174 758268836 -975467175 758268835 -975467176 758268834 -975467177 758268833 -975467178 758268832 -975467179 758268831\r\n", "output": "Yes\r\n"}, {"input": "4\r\n1 0 3 0\r\n", "output": "No\r\n"}, {"input": "4\r\n100 2 3 4\r\n", "output": "Yes\r\n"}, {"input": "5\r\n7 5 8 6 3\r\n", "output": "No\r\n"}, {"input": "3\r\n1000000000 1000000000 -1000000000\r\n", "output": "Yes\r\n"}, {"input": "4\r\n1 0 1 4\r\n", "output": "Yes\r\n"}, {"input": "7\r\n1 2 -1 0 1 6 7\r\n", "output": "Yes\r\n"}, {"input": "4\r\n0 0 4 0\r\n", "output": "Yes\r\n"}, {"input": "7\r\n0 0 2 3 4 5 5\r\n", "output": "Yes\r\n"}, {"input": "5\r\n7 5 8 6 8\r\n", "output": "No\r\n"}, {"input": "5\r\n1 2 9 4 5\r\n", "output": "Yes\r\n"}, {"input": "8\r\n1 12 3 14 5 16 7 8\r\n", "output": "Yes\r\n"}, {"input": "5\r\n1 6 7 4 9\r\n", "output": "Yes\r\n"}, {"input": "5\r\n2 1 0 1 2\r\n", "output": "No\r\n"}, {"input": "4\r\n0 0 1 3\r\n", "output": "Yes\r\n"}, {"input": "4\r\n100 50 50 10000000\r\n", "output": "No\r\n"}, {"input": "5\r\n1 2 3 3 3\r\n", "output": "No\r\n"}, {"input": "5\r\n1 2 6 10 17\r\n", "output": "Yes\r\n"}, {"input": "4\r\n1 3 4 4\r\n", "output": "Yes\r\n"}, {"input": "4\r\n100 50 50 1000000\r\n", "output": "No\r\n"}, {"input": "6\r\n1 2 4 5 7 9\r\n", "output": "No\r\n"}, {"input": "6\r\n0 0 1 2 3 4\r\n", "output": "Yes\r\n"}, {"input": "5\r\n7 5 9 10 8\r\n", "output": "Yes\r\n"}, {"input": "7\r\n1 2 2 1 2 2 1\r\n", "output": "Yes\r\n"}, {"input": "4\r\n2 2 4 5\r\n", "output": "Yes\r\n"}, {"input": "6\r\n1 2 1 3 4 5\r\n", "output": "No\r\n"}, {"input": "4\r\n1 3 3 6\r\n", "output": "No\r\n"}, {"input": "5\r\n1 2 -3 4 -1\r\n", "output": "Yes\r\n"}]
| false |
stdio
| null | true |
849/B
|
849
|
B
|
Python 3
|
TESTS
| 30 | 62 | 307,200 |
30013136
|
points = int(input())
y = list(map(int, input().split()))
def slope(p1, p2):
return (p2[1] - p1[1])/(p2[0] - p1[0])
def passes(one, two, point):
return 0 == (one[0] * (two[1] - point[1]) + two[0] * (point[1] - one[1]) + point[0] * (one[1] - two[1]))
def possible(start, joint, coords):
others = list()
for point in coords:
if not passes(start, joint, point):
others.append(point)
if len(others) == 0:
return (False, others)
elif len(others) == 1:
return (True, others)
elif len(others) >= 2:
other1, other2 = others[0], others[1]
for point in others:
if not passes(other1, other2, point):
return (False, others)
if slope(other1, other2) == slope(start, joint):
return (True, others)
else:
return (False, others)
coords = [(k+1, y[k]) for k in range(points)]
start = coords.pop(points//2)
poss, others = possible(start, coords[0], coords)
if (not poss) and len(others) > 0:
poss |= possible(start, others[0], coords)[0]
if poss:
print('Yes')
else:
print('No')
| 52 | 62 | 307,200 |
30000585
|
n=int(input())
y=list(map(int,input().split()))
def check(d):
return len(set(2*yi-d*i for i,yi in enumerate(y)))==2
print('Yes' if any(check(d) for d in [2*(y[1]-y[0]),2*(y[2]-y[1]),y[2]-y[0]]) else 'No')
|
Codeforces Round 431 (Div. 2)
|
CF
| 2,017 | 1 | 256 |
Tell Your World
|
Connect the countless points with lines, till we reach the faraway yonder.
There are n points on a coordinate plane, the i-th of which being (i, yi).
Determine whether it's possible to draw two parallel and non-overlapping lines, such that every point in the set lies on exactly one of them, and each of them passes through at least one point in the set.
|
The first line of input contains a positive integer n (3 ≤ n ≤ 1 000) — the number of points.
The second line contains n space-separated integers y1, y2, ..., yn ( - 109 ≤ yi ≤ 109) — the vertical coordinates of each point.
|
Output "Yes" (without quotes) if it's possible to fulfill the requirements, and "No" otherwise.
You can print each letter in any case (upper or lower).
| null |
In the first example, there are five points: (1, 7), (2, 5), (3, 8), (4, 6) and (5, 9). It's possible to draw a line that passes through points 1, 3, 5, and another one that passes through points 2, 4 and is parallel to the first one.
In the second example, while it's possible to draw two lines that cover all points, they cannot be made parallel.
In the third example, it's impossible to satisfy both requirements at the same time.
|
[{"input": "5\n7 5 8 6 9", "output": "Yes"}, {"input": "5\n-1 -2 0 0 -5", "output": "No"}, {"input": "5\n5 4 3 2 1", "output": "No"}, {"input": "5\n1000000000 0 0 0 0", "output": "Yes"}]
| 1,600 |
["brute force", "geometry"]
| 52 |
[{"input": "5\r\n7 5 8 6 9\r\n", "output": "Yes\r\n"}, {"input": "5\r\n-1 -2 0 0 -5\r\n", "output": "No\r\n"}, {"input": "5\r\n5 4 3 2 1\r\n", "output": "No\r\n"}, {"input": "5\r\n1000000000 0 0 0 0\r\n", "output": "Yes\r\n"}, {"input": "5\r\n1000000000 1 0 -999999999 -1000000000\r\n", "output": "Yes\r\n"}, {"input": "3\r\n998 244 353\r\n", "output": "Yes\r\n"}, {"input": "3\r\n-1000000000 0 1000000000\r\n", "output": "No\r\n"}, {"input": "5\r\n-1 -1 -1 -1 1\r\n", "output": "Yes\r\n"}, {"input": "4\r\n-9763 530 3595 6660\r\n", "output": "Yes\r\n"}, {"input": "4\r\n-253090305 36298498 374072642 711846786\r\n", "output": "Yes\r\n"}, {"input": "5\r\n-186772848 -235864239 -191561068 -193955178 -243046569\r\n", "output": "Yes\r\n"}, {"input": "5\r\n-954618456 -522919664 -248330428 -130850748 300848044\r\n", "output": "Yes\r\n"}, {"input": "10\r\n4846 6705 2530 5757 5283 -944 -2102 -3260 -4418 2913\r\n", "output": "No\r\n"}, {"input": "10\r\n-6568 -5920 -5272 -4624 -2435 -635 -2680 -2032 -1384 6565\r\n", "output": "No\r\n"}, {"input": "20\r\n319410377 286827025 254243673 221660321 189076969 156493617 123910265 91326913 58743561 26160209 -6423143 -39006495 -71589847 -104173199 -136756551 -169339903 -201923255 -234506607 -267089959 -299673311\r\n", "output": "No\r\n"}, {"input": "20\r\n-975467170 758268840 -975467171 758268839 -975467172 758268838 -975467173 758268837 -975467174 758268836 -975467175 758268835 -975467176 758268834 -975467177 758268833 -975467178 758268832 -975467179 758268831\r\n", "output": "Yes\r\n"}, {"input": "4\r\n1 0 3 0\r\n", "output": "No\r\n"}, {"input": "4\r\n100 2 3 4\r\n", "output": "Yes\r\n"}, {"input": "5\r\n7 5 8 6 3\r\n", "output": "No\r\n"}, {"input": "3\r\n1000000000 1000000000 -1000000000\r\n", "output": "Yes\r\n"}, {"input": "4\r\n1 0 1 4\r\n", "output": "Yes\r\n"}, {"input": "7\r\n1 2 -1 0 1 6 7\r\n", "output": "Yes\r\n"}, {"input": "4\r\n0 0 4 0\r\n", "output": "Yes\r\n"}, {"input": "7\r\n0 0 2 3 4 5 5\r\n", "output": "Yes\r\n"}, {"input": "5\r\n7 5 8 6 8\r\n", "output": "No\r\n"}, {"input": "5\r\n1 2 9 4 5\r\n", "output": "Yes\r\n"}, {"input": "8\r\n1 12 3 14 5 16 7 8\r\n", "output": "Yes\r\n"}, {"input": "5\r\n1 6 7 4 9\r\n", "output": "Yes\r\n"}, {"input": "5\r\n2 1 0 1 2\r\n", "output": "No\r\n"}, {"input": "4\r\n0 0 1 3\r\n", "output": "Yes\r\n"}, {"input": "4\r\n100 50 50 10000000\r\n", "output": "No\r\n"}, {"input": "5\r\n1 2 3 3 3\r\n", "output": "No\r\n"}, {"input": "5\r\n1 2 6 10 17\r\n", "output": "Yes\r\n"}, {"input": "4\r\n1 3 4 4\r\n", "output": "Yes\r\n"}, {"input": "4\r\n100 50 50 1000000\r\n", "output": "No\r\n"}, {"input": "6\r\n1 2 4 5 7 9\r\n", "output": "No\r\n"}, {"input": "6\r\n0 0 1 2 3 4\r\n", "output": "Yes\r\n"}, {"input": "5\r\n7 5 9 10 8\r\n", "output": "Yes\r\n"}, {"input": "7\r\n1 2 2 1 2 2 1\r\n", "output": "Yes\r\n"}, {"input": "4\r\n2 2 4 5\r\n", "output": "Yes\r\n"}, {"input": "6\r\n1 2 1 3 4 5\r\n", "output": "No\r\n"}, {"input": "4\r\n1 3 3 6\r\n", "output": "No\r\n"}, {"input": "5\r\n1 2 -3 4 -1\r\n", "output": "Yes\r\n"}]
| false |
stdio
| null | true |
382/C
|
382
|
C
|
PyPy 3-64
|
TESTS
| 8 | 61 | 0 |
221797324
|
import sys
input = sys.stdin.readline
s = dict()
n = int(input())
w = sorted(map(int, input().split()))
if n == 1:
print(-1)
exit()
elif n == 2:
a = w[1]-w[0]
if a == 0:
print(1)
print(w[0])
elif a % 2:
print(2)
print(w[0]-a, w[1]+a)
else:
print(3)
print(w[0] - a, w[0]+a//2, w[1] + a)
exit()
for i in range(1, n):
x = w[i]-w[i-1]
if x in s:
s[x] += 1
else:
s[x] = 1
if len(s) > 2:
print(0)
elif len(s) == 1:
print(2)
for i in s:
a = i
print(w[0] - a, w[-1] + a)
break
else:
d = sorted([(i, s[i]) for i in s])
if d[0][0] * 2 == d[1][0] and d[1][1] == 1:
print(1)
for i in range(1, n):
if w[i]-w[i-1] == d[1][0]:
print(w[i-1]+d[0][0])
break
else:
print(0)
| 59 | 217 | 10,649,600 |
51560982
|
n = int(input())
a = list(map(int,input().split()))
a.sort()
r = 0
res = []
'Función para revisar si el arreglo es una progresión aritmética'
def isAri(a):
diff = a[1]-a[0]
for i in range(len(a)-1):
if not (a[i+1]-a[i]==diff):
return False
return True
if(n==1):
print(-1)
elif(isAri(a) and a[1]-a[0]==0):
r+=1
print(r)
print(a[0])
elif(isAri(a)):
r+=1
res.append(a[0]-(a[1]-a[0]))
r+=1
res.append(a[len(a)-1]+(a[1]-a[0]))
if(n==2 and (a[0]+a[1])%2==0):
r+=1
res.append(int((a[0]+a[1])/2))
res.sort()
print(r)
for i in range(0, len(res)):
print(res[i],end=" ")
else:
diff = a[1]-a[0]
if(a[1]-a[0]==2*(a[2]-a[1])):
diff = a[2]-a[1]
errorIndex = -1
errors = 0
for i in range(0, len(a)-1):
curr = a[i+1]-a[i]
if(curr != diff):
errors+=1
if(curr == 2*diff):
errorIndex = i
if(errors==1 and errorIndex!=-1):
print(1)
print(a[errorIndex]+diff)
else:
print(0)
|
Codeforces Round 224 (Div. 2)
|
CF
| 2,014 | 1 | 256 |
Arithmetic Progression
|
Everybody knows what an arithmetic progression is. Let us remind you just in case that an arithmetic progression is such sequence of numbers a1, a2, ..., an of length n, that the following condition fulfills:
a2 - a1 = a3 - a2 = a4 - a3 = ... = ai + 1 - ai = ... = an - an - 1.
For example, sequences [1, 5], [10], [5, 4, 3] are arithmetic progressions and sequences [1, 3, 2], [1, 2, 4] are not.
Alexander has n cards containing integers. Arthur wants to give Alexander exactly one more card with a number so that he could use the resulting n + 1 cards to make an arithmetic progression (Alexander has to use all of his cards).
Arthur has already bought a card but he hasn't written a number on it. Help him, print all integers that you can write on a card so that the described condition fulfilled.
|
The first line contains integer n (1 ≤ n ≤ 105) — the number of cards. The next line contains the sequence of integers — the numbers on Alexander's cards. The numbers are positive integers, each of them doesn't exceed 108.
|
If Arthur can write infinitely many distinct integers on the card, print on a single line -1.
Otherwise, print on the first line the number of integers that suit you. In the second line, print the numbers in the increasing order. Note that the numbers in the answer can exceed 108 or even be negative (see test samples).
| null | null |
[{"input": "3\n4 1 7", "output": "2\n-2 10"}, {"input": "1\n10", "output": "-1"}, {"input": "4\n1 3 5 9", "output": "1\n7"}, {"input": "4\n4 3 4 5", "output": "0"}, {"input": "2\n2 4", "output": "3\n0 3 6"}]
| 1,700 |
["implementation", "sortings"]
| 59 |
[{"input": "3\r\n4 1 7\r\n", "output": "2\r\n-2 10\r\n"}, {"input": "1\r\n10\r\n", "output": "-1\r\n"}, {"input": "4\r\n1 3 5 9\r\n", "output": "1\r\n7\r\n"}, {"input": "4\r\n4 3 4 5\r\n", "output": "0\r\n"}, {"input": "2\r\n2 4\r\n", "output": "3\r\n0 3 6\r\n"}, {"input": "4\r\n1 3 4 5\r\n", "output": "1\r\n2\r\n"}, {"input": "2\r\n3 3\r\n", "output": "1\r\n3\r\n"}, {"input": "2\r\n13 2\r\n", "output": "2\r\n-9 24\r\n"}, {"input": "5\r\n2 2 2 2 2\r\n", "output": "1\r\n2\r\n"}, {"input": "6\r\n11 1 7 9 5 13\r\n", "output": "1\r\n3\r\n"}, {"input": "2\r\n100000000 1\r\n", "output": "2\r\n-99999998 199999999\r\n"}, {"input": "5\r\n2 3 1 4 6\r\n", "output": "1\r\n5\r\n"}, {"input": "5\r\n1 2 2 3 4\r\n", "output": "0\r\n"}, {"input": "3\r\n1 4 2\r\n", "output": "1\r\n3\r\n"}, {"input": "3\r\n8 8 8\r\n", "output": "1\r\n8\r\n"}, {"input": "5\r\n2 2 2 2 3\r\n", "output": "0\r\n"}, {"input": "1\r\n100000000\r\n", "output": "-1\r\n"}, {"input": "20\r\n27 6 3 18 54 33 9 15 39 12 57 48 21 51 60 30 24 36 42 45\r\n", "output": "2\r\n0 63\r\n"}, {"input": "40\r\n100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000\r\n", "output": "1\r\n100000000\r\n"}, {"input": "49\r\n81787 163451 104059 89211 96635 133755 148603 141179 159739 122619 123 144891 70651 11259 63227 3835 44667 37243 100347 26107 137467 18683 156027 59515 22395 40955 111483 52091 7547 85499 107771 178299 115195 152315 74363 126331 33531 130043 14971 48379 167163 182011 170875 78075 174587 55803 66939 29819 118907\r\n", "output": "1\r\n92923\r\n"}, {"input": "9\r\n1 2 3 3 4 4 5 5 6\r\n", "output": "0\r\n"}, {"input": "7\r\n1 1 2 3 4 5 6\r\n", "output": "0\r\n"}, {"input": "2\r\n4 1\r\n", "output": "2\r\n-2 7\r\n"}, {"input": "2\r\n2 100000000\r\n", "output": "3\r\n-99999996 50000001 199999998\r\n"}, {"input": "8\r\n1 2 3 4 11 12 13 14\r\n", "output": "0\r\n"}, {"input": "7\r\n5 40 45 50 55 60 65\r\n", "output": "0\r\n"}, {"input": "1\r\n1\r\n", "output": "-1\r\n"}, {"input": "2\r\n1 1\r\n", "output": "1\r\n1\r\n"}, {"input": "2\r\n100000000 2\r\n", "output": "3\r\n-99999996 50000001 199999998\r\n"}, {"input": "3\r\n2 2 3\r\n", "output": "0\r\n"}, {"input": "5\r\n1 3 5 9 13\r\n", "output": "0\r\n"}, {"input": "5\r\n1 2 4 8 16\r\n", "output": "0\r\n"}, {"input": "3\r\n2 2 5\r\n", "output": "0\r\n"}, {"input": "5\r\n1 2 3 4 8\r\n", "output": "0\r\n"}, {"input": "3\r\n1 3 4\r\n", "output": "1\r\n2\r\n"}, {"input": "5\r\n1 2 4 6 7\r\n", "output": "0\r\n"}, {"input": "4\r\n1 5 9 11\r\n", "output": "0\r\n"}, {"input": "4\r\n3 4 5 9\r\n", "output": "0\r\n"}, {"input": "4\r\n1 5 6 8\r\n", "output": "0\r\n"}, {"input": "4\r\n2 6 8 12\r\n", "output": "0\r\n"}, {"input": "5\r\n1 2 3 5 7\r\n", "output": "0\r\n"}, {"input": "6\r\n1 2 3 4 6 8\r\n", "output": "0\r\n"}]
| false |
stdio
| null | true |
382/C
|
382
|
C
|
PyPy 3-64
|
TESTS
| 8 | 93 | 4,915,200 |
199923752
|
from collections import Counter , defaultdict , deque
from bisect import bisect_left , bisect_right
from copy import deepcopy
from math import ceil , floor , sqrt , lcm , gcd , comb
from heapq import heapify , heappop , heappush , nlargest , nsmallest
from itertools import accumulate, combinations, permutations
from functools import reduce , lru_cache
def I():
return input()
def II():
return int(input())
def MI():
return map(int, input().split())
def LI():
return list(input().split())
def LII():
return list(map(int, input().split()))
def GMI():
return map(lambda x: int(x) - 1, input().split())
def LGMI():
return list(map(lambda x: int(x) - 1, input().split()))
def solve():
n = II()
a = LII()
if n == 1: print(-1) ; return 0
elif n == 2:
a.sort()
if (a[1] - a[0]) % 2 == 0 and (a[1] - a[0]) != 0:
print(3)
print(a[0] - (a[1] - a[0]) , (a[0] + a[1]) // 2 , a[1] + (a[1] - a[0]))
return 0
elif a[0] == a[1]:
print(1)
print(a[1])
return 0
else:
print(2)
print(a[0] - (a[1] - a[0]) , a[1] + (a[1] - a[0]))
return 0
a.sort()
diff = [a[i] - a[i - 1] for i in range(1 , n)]
if len(set(diff)) == 1 and list(set(diff)) != [0]: print(2) ; print(a[0] - diff[0] , a[-1] + diff[0])
elif len(set(diff)) == 1 and list(set(diff)) == 0 : print(1) ; print(a[0])
elif len(set(diff)) == 2 and max(diff) == 2 * min(diff) and diff.count(max(diff)) == 1:
print(1)
for i in range(n):
if a[i] - a[i - 1] == max(diff):
print(a[i - 1] + min(diff))
return 0
else:
print(0)
return 0
if __name__ == '__main__':
for _ in range(1):
solve()
| 59 | 218 | 31,948,800 |
124461592
|
import sys
input=sys.stdin.readline
n=int(input())
a=list(map(int,input().split()))
a.sort()
if n==1:
print(-1)
exit()
if n==2:
d=a[1]-a[0]
if d%2==0:
ans=[a[0]-d,a[0]+d//2,a[1]+d]
ans=list(set(ans))
ans.sort()
print(len(ans))
print(*ans)
else:
ans=[a[0]-d,a[1]+d]
ans=list(set(ans))
ans.sort()
print(len(ans))
print(*ans)
exit()
d=[]
for i in range(n-1):
d.append(a[i+1]-a[i])
if len(set(d))==1:
d=sorted(list(set(d)))[0]
ans=[a[0]-d,a[-1]+d]
ans=list(set(ans))
ans.sort()
print(len(ans))
print(*ans)
exit()
d.sort()
if len(set(d))>=3 or d[-2]*2!=d[-1]:
print(0)
exit()
if len(set(d))==2:
d=sorted(list(set(d)))
for i in range(n-1):
if a[i+1]-a[i]==d[1]:
print(1)
print(a[i]+d[0])
exit()
|
Codeforces Round 224 (Div. 2)
|
CF
| 2,014 | 1 | 256 |
Arithmetic Progression
|
Everybody knows what an arithmetic progression is. Let us remind you just in case that an arithmetic progression is such sequence of numbers a1, a2, ..., an of length n, that the following condition fulfills:
a2 - a1 = a3 - a2 = a4 - a3 = ... = ai + 1 - ai = ... = an - an - 1.
For example, sequences [1, 5], [10], [5, 4, 3] are arithmetic progressions and sequences [1, 3, 2], [1, 2, 4] are not.
Alexander has n cards containing integers. Arthur wants to give Alexander exactly one more card with a number so that he could use the resulting n + 1 cards to make an arithmetic progression (Alexander has to use all of his cards).
Arthur has already bought a card but he hasn't written a number on it. Help him, print all integers that you can write on a card so that the described condition fulfilled.
|
The first line contains integer n (1 ≤ n ≤ 105) — the number of cards. The next line contains the sequence of integers — the numbers on Alexander's cards. The numbers are positive integers, each of them doesn't exceed 108.
|
If Arthur can write infinitely many distinct integers on the card, print on a single line -1.
Otherwise, print on the first line the number of integers that suit you. In the second line, print the numbers in the increasing order. Note that the numbers in the answer can exceed 108 or even be negative (see test samples).
| null | null |
[{"input": "3\n4 1 7", "output": "2\n-2 10"}, {"input": "1\n10", "output": "-1"}, {"input": "4\n1 3 5 9", "output": "1\n7"}, {"input": "4\n4 3 4 5", "output": "0"}, {"input": "2\n2 4", "output": "3\n0 3 6"}]
| 1,700 |
["implementation", "sortings"]
| 59 |
[{"input": "3\r\n4 1 7\r\n", "output": "2\r\n-2 10\r\n"}, {"input": "1\r\n10\r\n", "output": "-1\r\n"}, {"input": "4\r\n1 3 5 9\r\n", "output": "1\r\n7\r\n"}, {"input": "4\r\n4 3 4 5\r\n", "output": "0\r\n"}, {"input": "2\r\n2 4\r\n", "output": "3\r\n0 3 6\r\n"}, {"input": "4\r\n1 3 4 5\r\n", "output": "1\r\n2\r\n"}, {"input": "2\r\n3 3\r\n", "output": "1\r\n3\r\n"}, {"input": "2\r\n13 2\r\n", "output": "2\r\n-9 24\r\n"}, {"input": "5\r\n2 2 2 2 2\r\n", "output": "1\r\n2\r\n"}, {"input": "6\r\n11 1 7 9 5 13\r\n", "output": "1\r\n3\r\n"}, {"input": "2\r\n100000000 1\r\n", "output": "2\r\n-99999998 199999999\r\n"}, {"input": "5\r\n2 3 1 4 6\r\n", "output": "1\r\n5\r\n"}, {"input": "5\r\n1 2 2 3 4\r\n", "output": "0\r\n"}, {"input": "3\r\n1 4 2\r\n", "output": "1\r\n3\r\n"}, {"input": "3\r\n8 8 8\r\n", "output": "1\r\n8\r\n"}, {"input": "5\r\n2 2 2 2 3\r\n", "output": "0\r\n"}, {"input": "1\r\n100000000\r\n", "output": "-1\r\n"}, {"input": "20\r\n27 6 3 18 54 33 9 15 39 12 57 48 21 51 60 30 24 36 42 45\r\n", "output": "2\r\n0 63\r\n"}, {"input": "40\r\n100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000\r\n", "output": "1\r\n100000000\r\n"}, {"input": "49\r\n81787 163451 104059 89211 96635 133755 148603 141179 159739 122619 123 144891 70651 11259 63227 3835 44667 37243 100347 26107 137467 18683 156027 59515 22395 40955 111483 52091 7547 85499 107771 178299 115195 152315 74363 126331 33531 130043 14971 48379 167163 182011 170875 78075 174587 55803 66939 29819 118907\r\n", "output": "1\r\n92923\r\n"}, {"input": "9\r\n1 2 3 3 4 4 5 5 6\r\n", "output": "0\r\n"}, {"input": "7\r\n1 1 2 3 4 5 6\r\n", "output": "0\r\n"}, {"input": "2\r\n4 1\r\n", "output": "2\r\n-2 7\r\n"}, {"input": "2\r\n2 100000000\r\n", "output": "3\r\n-99999996 50000001 199999998\r\n"}, {"input": "8\r\n1 2 3 4 11 12 13 14\r\n", "output": "0\r\n"}, {"input": "7\r\n5 40 45 50 55 60 65\r\n", "output": "0\r\n"}, {"input": "1\r\n1\r\n", "output": "-1\r\n"}, {"input": "2\r\n1 1\r\n", "output": "1\r\n1\r\n"}, {"input": "2\r\n100000000 2\r\n", "output": "3\r\n-99999996 50000001 199999998\r\n"}, {"input": "3\r\n2 2 3\r\n", "output": "0\r\n"}, {"input": "5\r\n1 3 5 9 13\r\n", "output": "0\r\n"}, {"input": "5\r\n1 2 4 8 16\r\n", "output": "0\r\n"}, {"input": "3\r\n2 2 5\r\n", "output": "0\r\n"}, {"input": "5\r\n1 2 3 4 8\r\n", "output": "0\r\n"}, {"input": "3\r\n1 3 4\r\n", "output": "1\r\n2\r\n"}, {"input": "5\r\n1 2 4 6 7\r\n", "output": "0\r\n"}, {"input": "4\r\n1 5 9 11\r\n", "output": "0\r\n"}, {"input": "4\r\n3 4 5 9\r\n", "output": "0\r\n"}, {"input": "4\r\n1 5 6 8\r\n", "output": "0\r\n"}, {"input": "4\r\n2 6 8 12\r\n", "output": "0\r\n"}, {"input": "5\r\n1 2 3 5 7\r\n", "output": "0\r\n"}, {"input": "6\r\n1 2 3 4 6 8\r\n", "output": "0\r\n"}]
| false |
stdio
| null | true |
216/B
|
216
|
B
|
PyPy 3-64
|
TESTS
| 23 | 124 | 0 |
217913801
|
thisSeen = 1
seen = dict()
vertcies, edges = list(map(int, input().split()))
adj = [[]]
for i in range(1, vertcies+1):
adj.append([])
seen[i] = 0
for i in range(edges):
v, u = list(map(int, input().split()))
adj[v].append(u)
adj[u].append(v)
visited = [False] * (vertcies+1)
cycles = 0
for i in range(1, vertcies+1):
if not visited[i]:
# (Vertex, Parent)
stack = [(i, 0)]
while stack:
v, p = stack.pop()
visited[v] = True
seen[v] = thisSeen
thisSeen+=1
for w in adj[v]:
if not visited[w]:
stack.append((w, v))
else:
if w != p and (seen[w] - seen[v])%2==0:
cycles += 1
ans = cycles//2
if (vertcies + ans) % 2 == 0:
print(ans)
else:
print(ans+1)
| 56 | 92 | 0 |
148234199
|
def dfs(cur_node, parent_node, reference, visited):
if cur_node in visited:
return True
visited.add(cur_node)
for child_node in graph[cur_node]:
if child_node != parent_node:
reference["count"] += 1
if dfs(child_node, cur_node, reference, visited):
return True
return False
# Getting the input in
n, m = [int(i) for i in input().split(" ")]
graph = {}
# initializing all vertices to not visited
# Creating Adjacency list representation
# for the graph
for i in range(n):
graph[i] = []
for i in range(m):
x, y = [int(i) for i in input().split(" ")]
x -= 1
y -= 1
graph[x].append(y)
graph[y].append(x)
#######################################
to_remove = 0
reference = {}
visited = set()
for i in range(0, n):
if i not in visited:
reference["count"] = 0
cycle = dfs(i, None, reference, visited)
if cycle:
to_remove += reference["count"] % 2 == 1
if (n - to_remove) % 2 == 1:
to_remove += 1
print(to_remove)
|
Codeforces Round 133 (Div. 2)
|
CF
| 2,012 | 2 | 256 |
Forming Teams
|
One day n students come to the stadium. They want to play football, and for that they need to split into teams, the teams must have an equal number of people.
We know that this group of people has archenemies. Each student has at most two archenemies. Besides, if student A is an archenemy to student B, then student B is an archenemy to student A.
The students want to split so as no two archenemies were in one team. If splitting in the required manner is impossible, some students will have to sit on the bench.
Determine the minimum number of students you will have to send to the bench in order to form the two teams in the described manner and begin the game at last.
|
The first line contains two integers n and m (2 ≤ n ≤ 100, 1 ≤ m ≤ 100) — the number of students and the number of pairs of archenemies correspondingly.
Next m lines describe enmity between students. Each enmity is described as two numbers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi) — the indexes of the students who are enemies to each other. Each enmity occurs in the list exactly once. It is guaranteed that each student has no more than two archenemies.
You can consider the students indexed in some manner with distinct integers from 1 to n.
|
Print a single integer — the minimum number of students you will have to send to the bench in order to start the game.
| null | null |
[{"input": "5 4\n1 2\n2 4\n5 3\n1 4", "output": "1"}, {"input": "6 2\n1 4\n3 4", "output": "0"}, {"input": "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4", "output": "2"}]
| 1,700 |
["dfs and similar", "implementation"]
| 56 |
[{"input": "5 4\r\n1 2\r\n2 4\r\n5 3\r\n1 4\r\n", "output": "1"}, {"input": "6 2\r\n1 4\r\n3 4\r\n", "output": "0"}, {"input": "6 6\r\n1 2\r\n2 3\r\n3 1\r\n4 5\r\n5 6\r\n6 4\r\n", "output": "2"}, {"input": "5 1\r\n1 2\r\n", "output": "1"}, {"input": "8 8\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n5 6\r\n6 7\r\n7 8\r\n8 1\r\n", "output": "0"}, {"input": "28 3\r\n15 3\r\n10 19\r\n17 25\r\n", "output": "0"}, {"input": "2 1\r\n1 2\r\n", "output": "0"}, {"input": "3 1\r\n2 3\r\n", "output": "1"}, {"input": "3 2\r\n1 2\r\n3 2\r\n", "output": "1"}, {"input": "3 3\r\n1 2\r\n1 3\r\n2 3\r\n", "output": "1"}, {"input": "4 1\r\n1 4\r\n", "output": "0"}, {"input": "4 2\r\n4 1\r\n2 1\r\n", "output": "0"}, {"input": "4 3\r\n1 3\r\n3 2\r\n2 4\r\n", "output": "0"}, {"input": "4 3\r\n3 2\r\n4 2\r\n4 3\r\n", "output": "2"}, {"input": "5 3\r\n4 2\r\n3 4\r\n5 1\r\n", "output": "1"}, {"input": "10 7\r\n8 9\r\n3 6\r\n2 4\r\n4 1\r\n1 3\r\n2 7\r\n7 10\r\n", "output": "0"}, {"input": "29 20\r\n15 9\r\n21 15\r\n14 12\r\n12 16\r\n3 28\r\n5 13\r\n19 1\r\n19 21\r\n23 17\r\n27 9\r\n26 10\r\n20 5\r\n8 16\r\n11 6\r\n4 22\r\n29 22\r\n29 11\r\n14 17\r\n28 6\r\n1 23\r\n", "output": "1"}, {"input": "89 30\r\n86 72\r\n43 16\r\n32 80\r\n17 79\r\n29 8\r\n89 37\r\n84 65\r\n3 41\r\n55 79\r\n33 56\r\n60 40\r\n43 45\r\n59 38\r\n26 23\r\n66 61\r\n81 30\r\n65 25\r\n13 71\r\n25 8\r\n56 59\r\n46 13\r\n22 30\r\n87 3\r\n26 32\r\n75 44\r\n48 87\r\n47 4\r\n63 21\r\n36 6\r\n42 86\r\n", "output": "1"}, {"input": "100 1\r\n3 87\r\n", "output": "0"}, {"input": "100 10\r\n88 82\r\n5 78\r\n66 31\r\n65 100\r\n92 25\r\n71 62\r\n47 31\r\n17 67\r\n69 68\r\n59 49\r\n", "output": "0"}, {"input": "10 9\r\n5 10\r\n3 2\r\n8 6\r\n4 5\r\n4 10\r\n6 1\r\n1 8\r\n9 2\r\n3 9\r\n", "output": "4"}, {"input": "19 16\r\n2 16\r\n7 10\r\n17 16\r\n17 14\r\n1 5\r\n19 6\r\n11 13\r\n15 19\r\n7 9\r\n13 5\r\n4 6\r\n1 11\r\n12 9\r\n10 12\r\n2 14\r\n4 15\r\n", "output": "1"}, {"input": "33 33\r\n2 16\r\n28 20\r\n13 9\r\n4 22\r\n18 1\r\n6 12\r\n13 29\r\n32 1\r\n17 15\r\n10 7\r\n6 15\r\n16 5\r\n11 10\r\n31 29\r\n25 8\r\n23 21\r\n14 32\r\n8 2\r\n19 3\r\n11 4\r\n21 25\r\n31 30\r\n33 5\r\n26 7\r\n27 26\r\n27 12\r\n30 24\r\n33 17\r\n28 22\r\n18 24\r\n19 9\r\n3 23\r\n14 20\r\n", "output": "1"}, {"input": "10 8\r\n8 3\r\n9 7\r\n6 1\r\n10 9\r\n2 6\r\n2 1\r\n3 4\r\n4 8\r\n", "output": "2"}, {"input": "20 12\r\n16 20\r\n8 3\r\n20 5\r\n5 10\r\n17 7\r\n13 2\r\n18 9\r\n17 18\r\n1 6\r\n14 4\r\n11 12\r\n10 16\r\n", "output": "0"}, {"input": "35 21\r\n15 3\r\n13 5\r\n2 28\r\n26 35\r\n9 10\r\n22 18\r\n17 1\r\n31 32\r\n35 33\r\n5 15\r\n14 24\r\n29 12\r\n16 2\r\n14 10\r\n7 4\r\n29 4\r\n23 27\r\n30 34\r\n19 26\r\n23 11\r\n25 21\r\n", "output": "1"}, {"input": "49 36\r\n17 47\r\n19 27\r\n41 23\r\n31 27\r\n11 29\r\n34 10\r\n35 2\r\n42 24\r\n19 16\r\n38 24\r\n5 9\r\n26 9\r\n36 14\r\n18 47\r\n28 40\r\n45 13\r\n35 22\r\n2 15\r\n31 30\r\n20 48\r\n39 3\r\n8 34\r\n36 7\r\n25 17\r\n5 39\r\n29 1\r\n32 33\r\n16 30\r\n38 49\r\n25 18\r\n1 11\r\n7 44\r\n12 43\r\n15 22\r\n49 21\r\n8 23\r\n", "output": "3"}, {"input": "6 5\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n5 1\r\n", "output": "2"}, {"input": "6 4\r\n1 2\r\n1 3\r\n4 5\r\n4 6\r\n", "output": "0"}, {"input": "16 16\r\n1 2\r\n2 3\r\n1 3\r\n4 5\r\n5 6\r\n4 6\r\n7 8\r\n8 9\r\n9 10\r\n10 11\r\n11 7\r\n12 13\r\n13 14\r\n14 15\r\n15 16\r\n16 12\r\n", "output": "4"}, {"input": "4 4\r\n1 2\r\n4 3\r\n1 4\r\n2 3\r\n", "output": "0"}, {"input": "9 9\r\n1 2\r\n2 3\r\n3 1\r\n4 5\r\n5 6\r\n6 4\r\n7 8\r\n8 9\r\n9 7\r\n", "output": "3"}, {"input": "20 11\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n5 6\r\n6 7\r\n7 8\r\n8 9\r\n9 10\r\n10 11\r\n11 1\r\n", "output": "2"}, {"input": "4 3\r\n1 2\r\n3 4\r\n1 3\r\n", "output": "0"}, {"input": "4 2\r\n2 4\r\n3 4\r\n", "output": "0"}, {"input": "10 10\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n5 1\r\n6 7\r\n7 8\r\n8 9\r\n9 10\r\n10 6\r\n", "output": "2"}, {"input": "6 5\r\n2 1\r\n3 4\r\n2 3\r\n4 5\r\n5 6\r\n", "output": "0"}, {"input": "8 5\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n5 1\r\n", "output": "2"}, {"input": "6 5\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n1 5\r\n", "output": "2"}, {"input": "8 8\r\n1 2\r\n2 3\r\n3 4\r\n1 4\r\n5 6\r\n6 7\r\n7 8\r\n5 8\r\n", "output": "0"}, {"input": "6 5\r\n1 3\r\n1 2\r\n2 4\r\n5 3\r\n5 4\r\n", "output": "2"}]
| false |
stdio
| null | true |
216/B
|
216
|
B
|
PyPy 3-64
|
TESTS
| 23 | 122 | 0 |
217904359
|
thisSeen = 1
seen = dict()
vertcies, edges = list(map(int, input().split()))
adj = [[]]
for i in range(1, vertcies+1):
adj.append([])
seen[i] = 0
for i in range(edges):
v, u = list(map(int, input().split()))
adj[v].append(u)
adj[u].append(v)
visited = [False] * (vertcies+1)
cycles = 0
for i in range(1, vertcies+1):
if not visited[i]:
# (Vertex, Parent)
stack = [(i, 0)]
seen[i] = thisSeen; thisSeen+=1
while stack:
item, parent = stack.pop()
visited[item] = True
for v in adj[item]:
if not visited[v]:
stack.append((v, item))
seen[v] = thisSeen; thisSeen+=1
else:
if v != parent and (seen[item]+seen[v])%2==1:
cycles += 1
ans = cycles//2
if (vertcies + ans) % 2 == 0:
print(ans)
else:
print(ans+1)
| 56 | 92 | 0 |
153409902
|
def detect_cycle(node, parent, visited, graph, ref):
visited.add(node)
ref["count"] += 1
for neighbor in graph[node]:
if neighbor == parent:
continue
if neighbor not in visited:
if detect_cycle(neighbor, node, visited, graph, ref):
return True
else:
return True
return False
def main():
n, m = map(int, input().split(" "))
graph = {}
for i in range(1, n + 1):
graph[i] = []
for _ in range(m):
a, b = map(int, input().split(" "))
graph[a].append(b)
graph[b].append(a)
ref = {}
bench = 0
visited = set()
for node in graph:
ref["count"] = 0
if node not in visited:
if detect_cycle(node, None, visited, graph, ref):
bench += ref["count"] % 2
bench += ((n - bench) % 2)
return bench
print(main())
|
Codeforces Round 133 (Div. 2)
|
CF
| 2,012 | 2 | 256 |
Forming Teams
|
One day n students come to the stadium. They want to play football, and for that they need to split into teams, the teams must have an equal number of people.
We know that this group of people has archenemies. Each student has at most two archenemies. Besides, if student A is an archenemy to student B, then student B is an archenemy to student A.
The students want to split so as no two archenemies were in one team. If splitting in the required manner is impossible, some students will have to sit on the bench.
Determine the minimum number of students you will have to send to the bench in order to form the two teams in the described manner and begin the game at last.
|
The first line contains two integers n and m (2 ≤ n ≤ 100, 1 ≤ m ≤ 100) — the number of students and the number of pairs of archenemies correspondingly.
Next m lines describe enmity between students. Each enmity is described as two numbers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi) — the indexes of the students who are enemies to each other. Each enmity occurs in the list exactly once. It is guaranteed that each student has no more than two archenemies.
You can consider the students indexed in some manner with distinct integers from 1 to n.
|
Print a single integer — the minimum number of students you will have to send to the bench in order to start the game.
| null | null |
[{"input": "5 4\n1 2\n2 4\n5 3\n1 4", "output": "1"}, {"input": "6 2\n1 4\n3 4", "output": "0"}, {"input": "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4", "output": "2"}]
| 1,700 |
["dfs and similar", "implementation"]
| 56 |
[{"input": "5 4\r\n1 2\r\n2 4\r\n5 3\r\n1 4\r\n", "output": "1"}, {"input": "6 2\r\n1 4\r\n3 4\r\n", "output": "0"}, {"input": "6 6\r\n1 2\r\n2 3\r\n3 1\r\n4 5\r\n5 6\r\n6 4\r\n", "output": "2"}, {"input": "5 1\r\n1 2\r\n", "output": "1"}, {"input": "8 8\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n5 6\r\n6 7\r\n7 8\r\n8 1\r\n", "output": "0"}, {"input": "28 3\r\n15 3\r\n10 19\r\n17 25\r\n", "output": "0"}, {"input": "2 1\r\n1 2\r\n", "output": "0"}, {"input": "3 1\r\n2 3\r\n", "output": "1"}, {"input": "3 2\r\n1 2\r\n3 2\r\n", "output": "1"}, {"input": "3 3\r\n1 2\r\n1 3\r\n2 3\r\n", "output": "1"}, {"input": "4 1\r\n1 4\r\n", "output": "0"}, {"input": "4 2\r\n4 1\r\n2 1\r\n", "output": "0"}, {"input": "4 3\r\n1 3\r\n3 2\r\n2 4\r\n", "output": "0"}, {"input": "4 3\r\n3 2\r\n4 2\r\n4 3\r\n", "output": "2"}, {"input": "5 3\r\n4 2\r\n3 4\r\n5 1\r\n", "output": "1"}, {"input": "10 7\r\n8 9\r\n3 6\r\n2 4\r\n4 1\r\n1 3\r\n2 7\r\n7 10\r\n", "output": "0"}, {"input": "29 20\r\n15 9\r\n21 15\r\n14 12\r\n12 16\r\n3 28\r\n5 13\r\n19 1\r\n19 21\r\n23 17\r\n27 9\r\n26 10\r\n20 5\r\n8 16\r\n11 6\r\n4 22\r\n29 22\r\n29 11\r\n14 17\r\n28 6\r\n1 23\r\n", "output": "1"}, {"input": "89 30\r\n86 72\r\n43 16\r\n32 80\r\n17 79\r\n29 8\r\n89 37\r\n84 65\r\n3 41\r\n55 79\r\n33 56\r\n60 40\r\n43 45\r\n59 38\r\n26 23\r\n66 61\r\n81 30\r\n65 25\r\n13 71\r\n25 8\r\n56 59\r\n46 13\r\n22 30\r\n87 3\r\n26 32\r\n75 44\r\n48 87\r\n47 4\r\n63 21\r\n36 6\r\n42 86\r\n", "output": "1"}, {"input": "100 1\r\n3 87\r\n", "output": "0"}, {"input": "100 10\r\n88 82\r\n5 78\r\n66 31\r\n65 100\r\n92 25\r\n71 62\r\n47 31\r\n17 67\r\n69 68\r\n59 49\r\n", "output": "0"}, {"input": "10 9\r\n5 10\r\n3 2\r\n8 6\r\n4 5\r\n4 10\r\n6 1\r\n1 8\r\n9 2\r\n3 9\r\n", "output": "4"}, {"input": "19 16\r\n2 16\r\n7 10\r\n17 16\r\n17 14\r\n1 5\r\n19 6\r\n11 13\r\n15 19\r\n7 9\r\n13 5\r\n4 6\r\n1 11\r\n12 9\r\n10 12\r\n2 14\r\n4 15\r\n", "output": "1"}, {"input": "33 33\r\n2 16\r\n28 20\r\n13 9\r\n4 22\r\n18 1\r\n6 12\r\n13 29\r\n32 1\r\n17 15\r\n10 7\r\n6 15\r\n16 5\r\n11 10\r\n31 29\r\n25 8\r\n23 21\r\n14 32\r\n8 2\r\n19 3\r\n11 4\r\n21 25\r\n31 30\r\n33 5\r\n26 7\r\n27 26\r\n27 12\r\n30 24\r\n33 17\r\n28 22\r\n18 24\r\n19 9\r\n3 23\r\n14 20\r\n", "output": "1"}, {"input": "10 8\r\n8 3\r\n9 7\r\n6 1\r\n10 9\r\n2 6\r\n2 1\r\n3 4\r\n4 8\r\n", "output": "2"}, {"input": "20 12\r\n16 20\r\n8 3\r\n20 5\r\n5 10\r\n17 7\r\n13 2\r\n18 9\r\n17 18\r\n1 6\r\n14 4\r\n11 12\r\n10 16\r\n", "output": "0"}, {"input": "35 21\r\n15 3\r\n13 5\r\n2 28\r\n26 35\r\n9 10\r\n22 18\r\n17 1\r\n31 32\r\n35 33\r\n5 15\r\n14 24\r\n29 12\r\n16 2\r\n14 10\r\n7 4\r\n29 4\r\n23 27\r\n30 34\r\n19 26\r\n23 11\r\n25 21\r\n", "output": "1"}, {"input": "49 36\r\n17 47\r\n19 27\r\n41 23\r\n31 27\r\n11 29\r\n34 10\r\n35 2\r\n42 24\r\n19 16\r\n38 24\r\n5 9\r\n26 9\r\n36 14\r\n18 47\r\n28 40\r\n45 13\r\n35 22\r\n2 15\r\n31 30\r\n20 48\r\n39 3\r\n8 34\r\n36 7\r\n25 17\r\n5 39\r\n29 1\r\n32 33\r\n16 30\r\n38 49\r\n25 18\r\n1 11\r\n7 44\r\n12 43\r\n15 22\r\n49 21\r\n8 23\r\n", "output": "3"}, {"input": "6 5\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n5 1\r\n", "output": "2"}, {"input": "6 4\r\n1 2\r\n1 3\r\n4 5\r\n4 6\r\n", "output": "0"}, {"input": "16 16\r\n1 2\r\n2 3\r\n1 3\r\n4 5\r\n5 6\r\n4 6\r\n7 8\r\n8 9\r\n9 10\r\n10 11\r\n11 7\r\n12 13\r\n13 14\r\n14 15\r\n15 16\r\n16 12\r\n", "output": "4"}, {"input": "4 4\r\n1 2\r\n4 3\r\n1 4\r\n2 3\r\n", "output": "0"}, {"input": "9 9\r\n1 2\r\n2 3\r\n3 1\r\n4 5\r\n5 6\r\n6 4\r\n7 8\r\n8 9\r\n9 7\r\n", "output": "3"}, {"input": "20 11\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n5 6\r\n6 7\r\n7 8\r\n8 9\r\n9 10\r\n10 11\r\n11 1\r\n", "output": "2"}, {"input": "4 3\r\n1 2\r\n3 4\r\n1 3\r\n", "output": "0"}, {"input": "4 2\r\n2 4\r\n3 4\r\n", "output": "0"}, {"input": "10 10\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n5 1\r\n6 7\r\n7 8\r\n8 9\r\n9 10\r\n10 6\r\n", "output": "2"}, {"input": "6 5\r\n2 1\r\n3 4\r\n2 3\r\n4 5\r\n5 6\r\n", "output": "0"}, {"input": "8 5\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n5 1\r\n", "output": "2"}, {"input": "6 5\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n1 5\r\n", "output": "2"}, {"input": "8 8\r\n1 2\r\n2 3\r\n3 4\r\n1 4\r\n5 6\r\n6 7\r\n7 8\r\n5 8\r\n", "output": "0"}, {"input": "6 5\r\n1 3\r\n1 2\r\n2 4\r\n5 3\r\n5 4\r\n", "output": "2"}]
| false |
stdio
| null | true |
849/B
|
849
|
B
|
Python 3
|
TESTS
| 16 | 31 | 0 |
178625289
|
def new(iota, k1):
z=len(iota)
#print(iota, k1)
if z==0:
pass
elif z==1:
return 1
else:
c1=iota[1][0]-iota[0][0]
d1=iota[1][1]-iota[0][1]
e1=d1*iota[0][0]-c1*iota[0][1]
#print(2*c1, k1*d1)
if 2*c1!=k1*d1:
pass
else:
for j in range(2, z):
if c1*j+e1!=d1*iota[j]:
break
else:
#print("ok")
return 1
return 0
n=int(input())
w=[int(k) for k in input().split()]
k1=w[1]-w[0]
b1=w[0]
iota=[]
for j in range(2, n):
if k1*j+b1!=w[j]:
iota.append((w[j], j))
check=new(iota, 2*k1)
#print(check)
k1=w[2]-w[0]
b1=2*w[0]
iota=[]
if 2*w[1]!=k1+b1:
iota.append((w[1], 1))
for j in range(3, n):
if k1*j+b1!=2*w[j]:
iota.append((w[j], j))
#print(k1, b1, iota)
check=max(check, new(iota, k1))
#print(check)
k1=w[2]-w[1]
b1=w[1]-k1
iota=[]
if b1!=w[0]:
iota.append((w[0], 0))
for j in range(2, n):
if k1*j+b1!=w[j]:
iota.append((w[j], j))
check=max(check, new(iota, 2*k1))
if check:
print("YES")
else:
print("NO")
| 52 | 62 | 307,200 |
30104007
|
import sys
n = int(input())
arr = list(map(int, input().split()))
com = [(0,1), (0,2), (1,2)]
for i in com:
# y = ax + b
a = (arr[i[0]] - arr[i[1]]) / (i[0] - i[1])
b1 = arr[i[0]] - a * (i[0] + 1)
b2 = b1
flag = True
for j in range(len(arr)):
if arr[j] != a * (j+1) + b1 and b2 == b1:
b2 = arr[j] - a * (j+1)
elif arr[j] != a * (j+1) + b1 and arr[j] != a * (j+1) + b2:
flag = False
break
if flag == True and b2 != b1:
print("Yes")
sys.exit(0)
print("No")
|
Codeforces Round 431 (Div. 2)
|
CF
| 2,017 | 1 | 256 |
Tell Your World
|
Connect the countless points with lines, till we reach the faraway yonder.
There are n points on a coordinate plane, the i-th of which being (i, yi).
Determine whether it's possible to draw two parallel and non-overlapping lines, such that every point in the set lies on exactly one of them, and each of them passes through at least one point in the set.
|
The first line of input contains a positive integer n (3 ≤ n ≤ 1 000) — the number of points.
The second line contains n space-separated integers y1, y2, ..., yn ( - 109 ≤ yi ≤ 109) — the vertical coordinates of each point.
|
Output "Yes" (without quotes) if it's possible to fulfill the requirements, and "No" otherwise.
You can print each letter in any case (upper or lower).
| null |
In the first example, there are five points: (1, 7), (2, 5), (3, 8), (4, 6) and (5, 9). It's possible to draw a line that passes through points 1, 3, 5, and another one that passes through points 2, 4 and is parallel to the first one.
In the second example, while it's possible to draw two lines that cover all points, they cannot be made parallel.
In the third example, it's impossible to satisfy both requirements at the same time.
|
[{"input": "5\n7 5 8 6 9", "output": "Yes"}, {"input": "5\n-1 -2 0 0 -5", "output": "No"}, {"input": "5\n5 4 3 2 1", "output": "No"}, {"input": "5\n1000000000 0 0 0 0", "output": "Yes"}]
| 1,600 |
["brute force", "geometry"]
| 52 |
[{"input": "5\r\n7 5 8 6 9\r\n", "output": "Yes\r\n"}, {"input": "5\r\n-1 -2 0 0 -5\r\n", "output": "No\r\n"}, {"input": "5\r\n5 4 3 2 1\r\n", "output": "No\r\n"}, {"input": "5\r\n1000000000 0 0 0 0\r\n", "output": "Yes\r\n"}, {"input": "5\r\n1000000000 1 0 -999999999 -1000000000\r\n", "output": "Yes\r\n"}, {"input": "3\r\n998 244 353\r\n", "output": "Yes\r\n"}, {"input": "3\r\n-1000000000 0 1000000000\r\n", "output": "No\r\n"}, {"input": "5\r\n-1 -1 -1 -1 1\r\n", "output": "Yes\r\n"}, {"input": "4\r\n-9763 530 3595 6660\r\n", "output": "Yes\r\n"}, {"input": "4\r\n-253090305 36298498 374072642 711846786\r\n", "output": "Yes\r\n"}, {"input": "5\r\n-186772848 -235864239 -191561068 -193955178 -243046569\r\n", "output": "Yes\r\n"}, {"input": "5\r\n-954618456 -522919664 -248330428 -130850748 300848044\r\n", "output": "Yes\r\n"}, {"input": "10\r\n4846 6705 2530 5757 5283 -944 -2102 -3260 -4418 2913\r\n", "output": "No\r\n"}, {"input": "10\r\n-6568 -5920 -5272 -4624 -2435 -635 -2680 -2032 -1384 6565\r\n", "output": "No\r\n"}, {"input": "20\r\n319410377 286827025 254243673 221660321 189076969 156493617 123910265 91326913 58743561 26160209 -6423143 -39006495 -71589847 -104173199 -136756551 -169339903 -201923255 -234506607 -267089959 -299673311\r\n", "output": "No\r\n"}, {"input": "20\r\n-975467170 758268840 -975467171 758268839 -975467172 758268838 -975467173 758268837 -975467174 758268836 -975467175 758268835 -975467176 758268834 -975467177 758268833 -975467178 758268832 -975467179 758268831\r\n", "output": "Yes\r\n"}, {"input": "4\r\n1 0 3 0\r\n", "output": "No\r\n"}, {"input": "4\r\n100 2 3 4\r\n", "output": "Yes\r\n"}, {"input": "5\r\n7 5 8 6 3\r\n", "output": "No\r\n"}, {"input": "3\r\n1000000000 1000000000 -1000000000\r\n", "output": "Yes\r\n"}, {"input": "4\r\n1 0 1 4\r\n", "output": "Yes\r\n"}, {"input": "7\r\n1 2 -1 0 1 6 7\r\n", "output": "Yes\r\n"}, {"input": "4\r\n0 0 4 0\r\n", "output": "Yes\r\n"}, {"input": "7\r\n0 0 2 3 4 5 5\r\n", "output": "Yes\r\n"}, {"input": "5\r\n7 5 8 6 8\r\n", "output": "No\r\n"}, {"input": "5\r\n1 2 9 4 5\r\n", "output": "Yes\r\n"}, {"input": "8\r\n1 12 3 14 5 16 7 8\r\n", "output": "Yes\r\n"}, {"input": "5\r\n1 6 7 4 9\r\n", "output": "Yes\r\n"}, {"input": "5\r\n2 1 0 1 2\r\n", "output": "No\r\n"}, {"input": "4\r\n0 0 1 3\r\n", "output": "Yes\r\n"}, {"input": "4\r\n100 50 50 10000000\r\n", "output": "No\r\n"}, {"input": "5\r\n1 2 3 3 3\r\n", "output": "No\r\n"}, {"input": "5\r\n1 2 6 10 17\r\n", "output": "Yes\r\n"}, {"input": "4\r\n1 3 4 4\r\n", "output": "Yes\r\n"}, {"input": "4\r\n100 50 50 1000000\r\n", "output": "No\r\n"}, {"input": "6\r\n1 2 4 5 7 9\r\n", "output": "No\r\n"}, {"input": "6\r\n0 0 1 2 3 4\r\n", "output": "Yes\r\n"}, {"input": "5\r\n7 5 9 10 8\r\n", "output": "Yes\r\n"}, {"input": "7\r\n1 2 2 1 2 2 1\r\n", "output": "Yes\r\n"}, {"input": "4\r\n2 2 4 5\r\n", "output": "Yes\r\n"}, {"input": "6\r\n1 2 1 3 4 5\r\n", "output": "No\r\n"}, {"input": "4\r\n1 3 3 6\r\n", "output": "No\r\n"}, {"input": "5\r\n1 2 -3 4 -1\r\n", "output": "Yes\r\n"}]
| false |
stdio
| null | true |
138/A
|
138
|
A
|
PyPy 3-64
|
TESTS
| 59 | 216 | 6,758,400 |
211278552
|
import sys
input = lambda: sys.stdin.readline().rstrip()
A = {1:'aabb',2:'abab',4:'abba',7:'aaaa'}
def check(dat):
ans = 0
if dat[0]==dat[1] and dat[2]==dat[3]:
ans^=1
if dat[0]==dat[2] and dat[1]==dat[3]:
ans^=2
if dat[0]==dat[3] and dat[1]==dat[2]:
ans^=4
return ans
n,k = map(int, input().split())
ans = 7
for _ in range(n):
tmp = []
for _ in range(4):
s = input()
s = s[::-1]
b = []
for c in s:
if c in 'aeiou':
b.append(c)
if k>len(b):
exit(print('NO'))
tmp.append(b[k-1])
ans &= check(tmp)
if ans in A:
print(A[ans])
else:
print('NO')
| 80 | 590 | 6,758,400 |
114144687
|
n,k=list(map(int,input().split()))
def z(a,b):
global k
c=0
d=''
for i in range(len(a)-1,-1,-1):
d+=a[i]
if a[i] in ['a','e','i','o','u']:
c+=1
if c==k:
break
f=c==k
c=0
e=''
for i in range(len(b)-1,-1,-1):
e+=b[i]
if b[i] in ['a','e','i','o','u']:
c+=1
if c==k:
break
return d==e and c==k and f
a=0
b=0
c=0
d=0
for i in range(n):
e=input()
f=input()
g=input()
h=input()
a1=z(e,f)
a2=z(e,g)
a3=z(e,h)
a4=z(f,g)
a5=z(f,h)
a6=z(g,h)
if a1 and a2 and a3 and a4 and a5 and a6:
d+=1
elif a1 and a6:
a+=1
elif a2 and a5:
b+=1
elif a3 and a4:
c+=1
if a+b+c+d!=n:
print('NO')
elif b==0 and c==0:
print('aaaa' if a==0 else 'aabb')
elif a==0 and c==0:
print('aaaa' if b==0 else 'abab')
elif a==0 and b==0:
print('aaaa' if c==0 else 'abba')
else:
print('NO')
|
Codeforces Beta Round 99 (Div. 1)
|
CF
| 2,011 | 2 | 256 |
Literature Lesson
|
Vera adores poems. All the poems Vera knows are divided into quatrains (groups of four lines) and in each quatrain some lines contain rhymes.
Let's consider that all lines in the poems consist of lowercase Latin letters (without spaces). Letters "a", "e", "i", "o", "u" are considered vowels.
Two lines rhyme if their suffixes that start from the k-th vowels (counting from the end) match. If a line has less than k vowels, then such line can't rhyme with any other line. For example, if k = 1, lines commit and hermit rhyme (the corresponding suffixes equal it), and if k = 2, they do not rhyme (ommit ≠ ermit).
Today on a literature lesson Vera learned that quatrains can contain four different schemes of rhymes, namely the following ones (the same letters stand for rhyming lines):
- Clerihew (aabb);
- Alternating (abab);
- Enclosed (abba).
If all lines of a quatrain pairwise rhyme, then the quatrain can belong to any rhyme scheme (this situation is represented by aaaa).
If all quatrains of a poem belong to the same rhyme scheme, then we can assume that the whole poem belongs to this rhyme scheme. If in each quatrain all lines pairwise rhyme, then the rhyme scheme of the poem is aaaa. Let us note that it doesn't matter whether lines from different quatrains rhyme with each other or not. In other words, it is possible that different quatrains aren't connected by a rhyme.
Vera got a long poem as a home task. The girl has to analyse it and find the poem rhyme scheme. Help Vera cope with the task.
|
The first line contains two integers n and k (1 ≤ n ≤ 2500, 1 ≤ k ≤ 5) — the number of quatrains in the poem and the vowel's number, correspondingly. Next 4n lines contain the poem. Each line is not empty and only consists of small Latin letters. The total length of the lines does not exceed 104.
If we assume that the lines are numbered starting from 1, then the first quatrain contains lines number 1, 2, 3, 4; the second one contains lines number 5, 6, 7, 8; and so on.
|
Print the rhyme scheme of the poem as "aabb", "abab", "abba", "aaaa"; or "NO" if the poem does not belong to any of the above mentioned schemes.
| null |
In the last sample both quatrains have rhymes but finding the common scheme is impossible, so the answer is "NO".
|
[{"input": "1 1\nday\nmay\nsun\nfun", "output": "aabb"}, {"input": "1 1\nday\nmay\ngray\nway", "output": "aaaa"}, {"input": "2 1\na\na\na\na\na\na\ne\ne", "output": "aabb"}, {"input": "2 1\nday\nmay\nsun\nfun\ntest\nhill\nfest\nthrill", "output": "NO"}]
| 1,600 |
["implementation"]
| 80 |
[{"input": "1 1\r\nday\r\nmay\r\nsun\r\nfun\r\n", "output": "aabb\r\n"}, {"input": "1 1\r\nday\r\nmay\r\ngray\r\nway\r\n", "output": "aaaa\r\n"}, {"input": "2 1\r\na\r\na\r\na\r\na\r\na\r\na\r\ne\r\ne\r\n", "output": "aabb\r\n"}, {"input": "2 1\r\nday\r\nmay\r\nsun\r\nfun\r\ntest\r\nhill\r\nfest\r\nthrill\r\n", "output": "NO\r\n"}, {"input": "2 5\r\na\r\na\r\na\r\na\r\na\r\na\r\ne\r\ne\r\n", "output": "NO\r\n"}, {"input": "1 1\r\nrezwbgy\r\nxakgmv\r\njogezwbgy\r\napezwbgy\r\n", "output": "NO\r\n"}, {"input": "2 1\r\nnuqfxwrb\r\napqfkw\r\nuqfxwrb\r\nnhcuqfxwrb\r\nogkznwncmt\r\nevf\r\nogkznwncmt\r\nogkznwncmt\r\n", "output": "NO\r\n"}, {"input": "1 1\r\naawjvkxx\r\nawjvkxx\r\nxawjvkxx\r\nawjvkxx\r\n", "output": "aaaa\r\n"}, {"input": "2 2\r\nrhcujgxabk\r\nnjgdqpurul\r\nueoedt\r\ncpcfhbyvo\r\nzmfwnieog\r\npkpylassbf\r\nhrfeod\r\ncdwuil\r\n", "output": "NO\r\n"}, {"input": "2 1\r\nol\r\nol\r\nol\r\nzol\r\nek\r\nek\r\nek\r\nqek\r\n", "output": "aaaa\r\n"}, {"input": "3 2\r\nexdaoao\r\nrdwunurp\r\ndunurp\r\ntyqzuxao\r\ndupocgsps\r\nzsiravcm\r\nnqiravcm\r\nlnupocgsps\r\niwashk\r\neepkqcykbv\r\nyviwashk\r\neepkqcykbv\r\n", "output": "NO\r\n"}, {"input": "2 1\r\ndaihacbnhgfts\r\nsqihpntjvczkw\r\nmihpntjvczkw\r\nvyacbnhgfts\r\ntsvovdpqajmgvcj\r\ncexqkwrvctomb\r\njxbomb\r\ngnpajmgvcj\r\n", "output": "abba\r\n"}, {"input": "3 2\r\netba\r\ntfecetba\r\nzkitbgcuuy\r\nuuy\r\nbuxeoi\r\nmekxoi\r\nblviwoehy\r\niwoehy\r\njyfpaqntiz\r\nqvaqntiz\r\nhciak\r\niak\r\n", "output": "aabb\r\n"}, {"input": "16 1\r\ni\r\ni\r\ni\r\ni\r\ni\r\nu\r\ni\r\ni\r\no\r\na\r\na\r\no\r\na\r\ni\r\na\r\na\r\ni\r\ni\r\no\r\no\r\ni\r\ni\r\ni\r\ni\r\nu\r\nu\r\nu\r\nu\r\no\r\ne\r\ne\r\ne\r\no\r\ni\r\no\r\ni\r\na\r\na\r\na\r\na\r\nu\r\no\r\no\r\nu\r\ni\r\no\r\no\r\ni\r\na\r\na\r\ne\r\ne\r\na\r\na\r\na\r\na\r\na\r\no\r\na\r\na\r\nu\r\na\r\nu\r\nu\r\n", "output": "NO\r\n"}, {"input": "16 1\r\neb\r\neb\r\nfe\r\nce\r\ner\r\ner\r\new\r\new\r\nu\r\ncu\r\nu\r\nu\r\nud\r\nik\r\nud\r\nik\r\nve\r\niw\r\niw\r\nne\r\nel\r\nob\r\nel\r\nob\r\no\r\neo\r\no\r\nyo\r\nav\r\nav\r\nei\r\nmi\r\nu\r\noh\r\noh\r\nzu\r\niw\r\niw\r\na\r\nma\r\ni\r\nu\r\nku\r\ngi\r\nac\r\no\r\no\r\nac\r\ni\r\ner\r\nai\r\ner\r\nyu\r\nuf\r\nuf\r\nhu\r\nef\r\nef\r\nef\r\nef\r\nmu\r\nu\r\nqe\r\nie\r\n", "output": "NO\r\n"}, {"input": "1 1\r\ne\r\ne\r\ne\r\ne\r\n", "output": "aaaa\r\n"}, {"input": "1 1\r\na\r\ne\r\ne\r\ne\r\n", "output": "NO\r\n"}, {"input": "1 1\r\ne\r\na\r\ne\r\ne\r\n", "output": "NO\r\n"}, {"input": "1 1\r\na\r\na\r\ne\r\ne\r\n", "output": "aabb\r\n"}, {"input": "1 1\r\ne\r\ne\r\na\r\ne\r\n", "output": "NO\r\n"}, {"input": "1 1\r\na\r\ne\r\na\r\ne\r\n", "output": "abab\r\n"}, {"input": "1 1\r\ne\r\na\r\na\r\ne\r\n", "output": "abba\r\n"}, {"input": "1 1\r\na\r\na\r\na\r\ne\r\n", "output": "NO\r\n"}, {"input": "1 1\r\ne\r\ne\r\ne\r\na\r\n", "output": "NO\r\n"}, {"input": "1 1\r\na\r\ne\r\ne\r\na\r\n", "output": "abba\r\n"}, {"input": "1 1\r\ne\r\na\r\ne\r\na\r\n", "output": "abab\r\n"}, {"input": "1 1\r\na\r\na\r\ne\r\na\r\n", "output": "NO\r\n"}, {"input": "1 1\r\ne\r\ne\r\na\r\na\r\n", "output": "aabb\r\n"}, {"input": "1 1\r\na\r\ne\r\na\r\na\r\n", "output": "NO\r\n"}, {"input": "1 1\r\ne\r\na\r\na\r\na\r\n", "output": "NO\r\n"}, {"input": "1 1\r\na\r\na\r\na\r\na\r\n", "output": "aaaa\r\n"}, {"input": "1 2\r\neraub\r\nbee\r\naab\r\nttbee\r\n", "output": "NO\r\n"}, {"input": "10 1\r\na\r\na\r\na\r\na\r\na\r\na\r\na\r\na\r\na\r\na\r\na\r\na\r\na\r\na\r\na\r\na\r\na\r\na\r\na\r\na\r\na\r\na\r\na\r\na\r\na\r\na\r\na\r\na\r\na\r\na\r\na\r\na\r\na\r\na\r\na\r\na\r\na\r\na\r\na\r\ny\r\n", "output": "NO\r\n"}, {"input": "1 2\r\neeereaatktb\r\nbee\r\niaattb\r\nottbee\r\n", "output": "NO\r\n"}, {"input": "1 1\r\nab\r\nac\r\nad\r\naf\r\n", "output": "NO\r\n"}, {"input": "1 1\r\nar\r\nat\r\nay\r\naw\r\n", "output": "NO\r\n"}, {"input": "2 1\r\na\r\ne\r\na\r\ne\r\na\r\na\r\na\r\na\r\n", "output": "abab\r\n"}, {"input": "1 1\r\na\r\ne\r\na\r\ni\r\n", "output": "NO\r\n"}, {"input": "1 1\r\na\r\ne\r\na\r\ne\r\n", "output": "abab\r\n"}, {"input": "1 1\r\nabbbbbbbbbbbbbbbbcbbbbbbbbbbbbbbbb\r\nabbbbbbbbbbbbbbbbfbbbbbbbbbbbbbbbb\r\nabbbbbbbbbbbbbbbbxbbbbbbbbbbbbbbbb\r\nabbbbbbbbbbbbbbbbdbbbbbbbbbbbbbbbb\r\n", "output": "NO\r\n"}, {"input": "2 1\r\na\r\ne\r\ne\r\na\r\na\r\na\r\na\r\na\r\n", "output": "abba\r\n"}, {"input": "1 1\r\nbug\r\nsuy\r\nluh\r\ngut\r\n", "output": "NO\r\n"}, {"input": "1 1\r\nam\r\nat\r\nan\r\nag\r\n", "output": "NO\r\n"}, {"input": "2 1\r\na\r\na\r\ne\r\ne\r\na\r\na\r\na\r\na\r\n", "output": "aabb\r\n"}, {"input": "1 4\r\naieoabcd\r\naeioabcd\r\naoeiabcd\r\naoieabcd\r\n", "output": "NO\r\n"}, {"input": "1 2\r\naec\r\naed\r\naek\r\naem\r\n", "output": "NO\r\n"}, {"input": "1 1\r\nar\r\nab\r\nak\r\naz\r\n", "output": "NO\r\n"}, {"input": "2 1\r\na\r\na\r\na\r\na\r\na\r\nb\r\nb\r\nb\r\n", "output": "NO\r\n"}]
| false |
stdio
| null | true |
731/B
|
731
|
B
|
PyPy 3-64
|
TESTS
| 1 | 46 | 0 |
196082422
|
# 4
# 1 2 1 2
n=int(input())
l=[*map(int,input().split())]
i = 0
for i in range(n):
if l[i] % 2:
if i < n-1:
l[i+1] -= 1
else:
print('no')
exit(0)
print('yes')
| 79 | 109 | 22,630,400 |
196082455
|
n=int(input())
l=list(map(int,input().split()))
for i in range(n-1):
if l[i]<0:
print('NO')
exit()
if l[i]%2==1:
l[i+1]-=1
if l[-1]%2==1:print('NO')
else:print('YES')
|
Codeforces Round 376 (Div. 2)
|
CF
| 2,016 | 1 | 256 |
Coupons and Discounts
|
The programming competition season has already started and it's time to train for ICPC. Sereja coaches his teams for a number of year and he knows that to get ready for the training session it's not enough to prepare only problems and editorial. As the training sessions lasts for several hours, teams become hungry. Thus, Sereja orders a number of pizzas so they can eat right after the end of the competition.
Teams plan to train for n times during n consecutive days. During the training session Sereja orders exactly one pizza for each team that is present this day. He already knows that there will be ai teams on the i-th day.
There are two types of discounts in Sereja's favourite pizzeria. The first discount works if one buys two pizzas at one day, while the second is a coupon that allows to buy one pizza during two consecutive days (two pizzas in total).
As Sereja orders really a lot of pizza at this place, he is the golden client and can use the unlimited number of discounts and coupons of any type at any days.
Sereja wants to order exactly ai pizzas on the i-th day while using only discounts and coupons. Note, that he will never buy more pizzas than he need for this particular day. Help him determine, whether he can buy the proper amount of pizzas each day if he is allowed to use only coupons and discounts. Note, that it's also prohibited to have any active coupons after the end of the day n.
|
The first line of input contains a single integer n (1 ≤ n ≤ 200 000) — the number of training sessions.
The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 10 000) — the number of teams that will be present on each of the days.
|
If there is a way to order pizzas using only coupons and discounts and do not buy any extra pizzas on any of the days, then print "YES" (without quotes) in the only line of output. Otherwise, print "NO" (without quotes).
| null |
In the first sample, Sereja can use one coupon to buy one pizza on the first and the second days, one coupon to buy pizza on the second and the third days and one discount to buy pizzas on the fourth days. This is the only way to order pizzas for this sample.
In the second sample, Sereja can't use neither the coupon nor the discount without ordering an extra pizza. Note, that it's possible that there will be no teams attending the training sessions on some days.
|
[{"input": "4\n1 2 1 2", "output": "YES"}, {"input": "3\n1 0 1", "output": "NO"}]
| 1,100 |
["constructive algorithms", "greedy"]
| 79 |
[{"input": "4\r\n1 2 1 2\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 0 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n2 0 2\r\n", "output": "YES\r\n"}, {"input": "1\r\n179\r\n", "output": "NO\r\n"}, {"input": "10\r\n0 0 5 9 9 3 0 0 0 10\r\n", "output": "YES\r\n"}, {"input": "3\r\n3 2 3\r\n", "output": "YES\r\n"}, {"input": "1\r\n0\r\n", "output": "YES\r\n"}, {"input": "2\r\n0 0\r\n", "output": "YES\r\n"}, {"input": "10\r\n0 0 0 0 0 0 0 0 0 0\r\n", "output": "YES\r\n"}, {"input": "1\r\n1\r\n", "output": "NO\r\n"}, {"input": "1\r\n2\r\n", "output": "YES\r\n"}, {"input": "1\r\n3\r\n", "output": "NO\r\n"}, {"input": "1\r\n10000\r\n", "output": "YES\r\n"}, {"input": "2\r\n10000 10000\r\n", "output": "YES\r\n"}, {"input": "3\r\n2 2 2\r\n", "output": "YES\r\n"}, {"input": "10\r\n3 3 3 2 2 2 2 2 2 3\r\n", "output": "YES\r\n"}, {"input": "100\r\n2 3 2 3 3 3 3 3 3 2 2 2 2 2 2 3 2 3 3 2 3 2 3 2 2 3 3 3 3 3 2 2 2 2 3 2 3 3 2 2 3 2 3 3 3 3 2 2 3 3 3 3 3 2 3 3 3 2 2 2 2 3 2 2 2 2 3 2 2 3 2 2 2 3 2 2 3 2 2 2 3 3 3 2 2 2 2 3 2 2 3 3 3 2 2 2 2 2 3 3\r\n", "output": "NO\r\n"}, {"input": "3\r\n0 0 1\r\n", "output": "NO\r\n"}, {"input": "10\r\n1 0 1 1 0 1 1 0 1 0\r\n", "output": "NO\r\n"}, {"input": "100\r\n1 0 1 1 0 1 0 0 0 1 1 0 0 1 1 0 1 0 1 0 0 1 0 1 1 1 0 0 0 0 1 1 0 0 1 0 0 0 0 1 0 1 0 1 0 0 1 0 0 0 0 1 0 0 0 0 0 1 0 0 0 1 0 1 0 0 0 1 1 0 1 0 1 1 1 1 1 0 1 1 0 0 0 1 0 0 1 0 1 1 1 1 1 1 1 0 1 0 1 1\r\n", "output": "NO\r\n"}, {"input": "10\r\n8 4 0 0 6 1 9 8 0 6\r\n", "output": "YES\r\n"}, {"input": "100\r\n44 0 0 0 16 0 0 0 0 77 9 0 94 0 78 0 0 50 55 35 0 35 88 27 0 0 86 0 0 56 0 0 17 23 0 22 54 36 0 0 94 36 0 22 0 0 0 0 0 0 0 82 0 0 50 0 6 0 0 44 80 0 0 0 98 0 0 0 0 92 0 56 0 16 0 14 0 37 89 0 62 3 83 0 0 0 80 0 92 58 92 0 0 0 57 79 0 0 0 42\r\n", "output": "YES\r\n"}, {"input": "100\r\n37 92 14 95 3 37 0 0 0 84 27 33 0 0 0 74 74 0 35 72 46 29 8 92 1 76 47 0 38 82 0 81 54 7 61 46 91 0 86 0 80 0 0 98 88 0 4 0 0 52 0 0 82 0 33 35 0 36 58 52 1 50 29 0 0 24 0 69 97 65 13 0 30 0 14 66 47 94 22 24 8 92 67 0 34 0 0 0 84 85 50 33 0 99 67 73 21 0 0 62\r\n", "output": "YES\r\n"}, {"input": "100\r\n56 22 13 79 28 73 16 55 34 0 97 19 22 36 22 80 30 19 36 92 9 38 24 10 61 43 19 12 18 34 21 36 1 17 0 97 72 37 74 70 51 34 33 87 27 33 45 97 38 56 2 32 88 92 64 51 74 94 86 98 57 62 83 3 87 61 9 65 57 13 64 10 50 35 7 75 41 3 70 66 6 55 69 42 91 75 14 22 68 93 2 53 22 98 45 2 78 58 18 13\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 4\r\n", "output": "NO\r\n"}, {"input": "4\r\n2 1 1 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 1 1 0 1\r\n", "output": "NO\r\n"}, {"input": "4\r\n1 0 2 2\r\n", "output": "NO\r\n"}, {"input": "3\r\n3 2 1\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 0\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 2\r\n", "output": "NO\r\n"}, {"input": "3\r\n2 1 1\r\n", "output": "YES\r\n"}, {"input": "3\r\n3 0 0\r\n", "output": "NO\r\n"}, {"input": "9\r\n6 3 5 9 0 3 1 9 6\r\n", "output": "NO\r\n"}, {"input": "4\r\n1 0 1 1\r\n", "output": "NO\r\n"}, {"input": "4\r\n1 1 1 0\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 5\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 0 2\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 2\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 1\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 4 1\r\n", "output": "YES\r\n"}, {"input": "3\r\n3 2 2\r\n", "output": "NO\r\n"}]
| false |
stdio
| null | true |
731/B
|
731
|
B
|
Python 3
|
TESTS
| 21 | 139 | 12,595,200 |
202944564
|
t = int(input())
a = [int(_) for _ in input().split()]
h = []
counting = False
g = []
for i in a:
if i != 0 and not counting:
g.append(i)
counting = True
elif i == 0:
counting = False
h.append(g)
g = []
else:
g.append(i)
h.append(g)
j = sorted(h, key=lambda x: len(x))
if sum(j[-1]) % 2 == 0:
print("YES")
exit()
print("NO")
| 79 | 124 | 16,793,600 |
193079684
|
import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n = int(input())
a = list(map(int, input().split())) + [0]
c = 0
ans = "YES"
for i in a:
if not i and c % 2:
ans = "NO"
break
c += i
print(ans)
|
Codeforces Round 376 (Div. 2)
|
CF
| 2,016 | 1 | 256 |
Coupons and Discounts
|
The programming competition season has already started and it's time to train for ICPC. Sereja coaches his teams for a number of year and he knows that to get ready for the training session it's not enough to prepare only problems and editorial. As the training sessions lasts for several hours, teams become hungry. Thus, Sereja orders a number of pizzas so they can eat right after the end of the competition.
Teams plan to train for n times during n consecutive days. During the training session Sereja orders exactly one pizza for each team that is present this day. He already knows that there will be ai teams on the i-th day.
There are two types of discounts in Sereja's favourite pizzeria. The first discount works if one buys two pizzas at one day, while the second is a coupon that allows to buy one pizza during two consecutive days (two pizzas in total).
As Sereja orders really a lot of pizza at this place, he is the golden client and can use the unlimited number of discounts and coupons of any type at any days.
Sereja wants to order exactly ai pizzas on the i-th day while using only discounts and coupons. Note, that he will never buy more pizzas than he need for this particular day. Help him determine, whether he can buy the proper amount of pizzas each day if he is allowed to use only coupons and discounts. Note, that it's also prohibited to have any active coupons after the end of the day n.
|
The first line of input contains a single integer n (1 ≤ n ≤ 200 000) — the number of training sessions.
The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 10 000) — the number of teams that will be present on each of the days.
|
If there is a way to order pizzas using only coupons and discounts and do not buy any extra pizzas on any of the days, then print "YES" (without quotes) in the only line of output. Otherwise, print "NO" (without quotes).
| null |
In the first sample, Sereja can use one coupon to buy one pizza on the first and the second days, one coupon to buy pizza on the second and the third days and one discount to buy pizzas on the fourth days. This is the only way to order pizzas for this sample.
In the second sample, Sereja can't use neither the coupon nor the discount without ordering an extra pizza. Note, that it's possible that there will be no teams attending the training sessions on some days.
|
[{"input": "4\n1 2 1 2", "output": "YES"}, {"input": "3\n1 0 1", "output": "NO"}]
| 1,100 |
["constructive algorithms", "greedy"]
| 79 |
[{"input": "4\r\n1 2 1 2\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 0 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n2 0 2\r\n", "output": "YES\r\n"}, {"input": "1\r\n179\r\n", "output": "NO\r\n"}, {"input": "10\r\n0 0 5 9 9 3 0 0 0 10\r\n", "output": "YES\r\n"}, {"input": "3\r\n3 2 3\r\n", "output": "YES\r\n"}, {"input": "1\r\n0\r\n", "output": "YES\r\n"}, {"input": "2\r\n0 0\r\n", "output": "YES\r\n"}, {"input": "10\r\n0 0 0 0 0 0 0 0 0 0\r\n", "output": "YES\r\n"}, {"input": "1\r\n1\r\n", "output": "NO\r\n"}, {"input": "1\r\n2\r\n", "output": "YES\r\n"}, {"input": "1\r\n3\r\n", "output": "NO\r\n"}, {"input": "1\r\n10000\r\n", "output": "YES\r\n"}, {"input": "2\r\n10000 10000\r\n", "output": "YES\r\n"}, {"input": "3\r\n2 2 2\r\n", "output": "YES\r\n"}, {"input": "10\r\n3 3 3 2 2 2 2 2 2 3\r\n", "output": "YES\r\n"}, {"input": "100\r\n2 3 2 3 3 3 3 3 3 2 2 2 2 2 2 3 2 3 3 2 3 2 3 2 2 3 3 3 3 3 2 2 2 2 3 2 3 3 2 2 3 2 3 3 3 3 2 2 3 3 3 3 3 2 3 3 3 2 2 2 2 3 2 2 2 2 3 2 2 3 2 2 2 3 2 2 3 2 2 2 3 3 3 2 2 2 2 3 2 2 3 3 3 2 2 2 2 2 3 3\r\n", "output": "NO\r\n"}, {"input": "3\r\n0 0 1\r\n", "output": "NO\r\n"}, {"input": "10\r\n1 0 1 1 0 1 1 0 1 0\r\n", "output": "NO\r\n"}, {"input": "100\r\n1 0 1 1 0 1 0 0 0 1 1 0 0 1 1 0 1 0 1 0 0 1 0 1 1 1 0 0 0 0 1 1 0 0 1 0 0 0 0 1 0 1 0 1 0 0 1 0 0 0 0 1 0 0 0 0 0 1 0 0 0 1 0 1 0 0 0 1 1 0 1 0 1 1 1 1 1 0 1 1 0 0 0 1 0 0 1 0 1 1 1 1 1 1 1 0 1 0 1 1\r\n", "output": "NO\r\n"}, {"input": "10\r\n8 4 0 0 6 1 9 8 0 6\r\n", "output": "YES\r\n"}, {"input": "100\r\n44 0 0 0 16 0 0 0 0 77 9 0 94 0 78 0 0 50 55 35 0 35 88 27 0 0 86 0 0 56 0 0 17 23 0 22 54 36 0 0 94 36 0 22 0 0 0 0 0 0 0 82 0 0 50 0 6 0 0 44 80 0 0 0 98 0 0 0 0 92 0 56 0 16 0 14 0 37 89 0 62 3 83 0 0 0 80 0 92 58 92 0 0 0 57 79 0 0 0 42\r\n", "output": "YES\r\n"}, {"input": "100\r\n37 92 14 95 3 37 0 0 0 84 27 33 0 0 0 74 74 0 35 72 46 29 8 92 1 76 47 0 38 82 0 81 54 7 61 46 91 0 86 0 80 0 0 98 88 0 4 0 0 52 0 0 82 0 33 35 0 36 58 52 1 50 29 0 0 24 0 69 97 65 13 0 30 0 14 66 47 94 22 24 8 92 67 0 34 0 0 0 84 85 50 33 0 99 67 73 21 0 0 62\r\n", "output": "YES\r\n"}, {"input": "100\r\n56 22 13 79 28 73 16 55 34 0 97 19 22 36 22 80 30 19 36 92 9 38 24 10 61 43 19 12 18 34 21 36 1 17 0 97 72 37 74 70 51 34 33 87 27 33 45 97 38 56 2 32 88 92 64 51 74 94 86 98 57 62 83 3 87 61 9 65 57 13 64 10 50 35 7 75 41 3 70 66 6 55 69 42 91 75 14 22 68 93 2 53 22 98 45 2 78 58 18 13\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 4\r\n", "output": "NO\r\n"}, {"input": "4\r\n2 1 1 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 1 1 0 1\r\n", "output": "NO\r\n"}, {"input": "4\r\n1 0 2 2\r\n", "output": "NO\r\n"}, {"input": "3\r\n3 2 1\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 0\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 2\r\n", "output": "NO\r\n"}, {"input": "3\r\n2 1 1\r\n", "output": "YES\r\n"}, {"input": "3\r\n3 0 0\r\n", "output": "NO\r\n"}, {"input": "9\r\n6 3 5 9 0 3 1 9 6\r\n", "output": "NO\r\n"}, {"input": "4\r\n1 0 1 1\r\n", "output": "NO\r\n"}, {"input": "4\r\n1 1 1 0\r\n", "output": "NO\r\n"}, {"input": "2\r\n1 5\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 0 2\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 2\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 2 1\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 4 1\r\n", "output": "YES\r\n"}, {"input": "3\r\n3 2 2\r\n", "output": "NO\r\n"}]
| false |
stdio
| null | true |
220/A
|
220
|
A
|
Python 3
|
TESTS
| 32 | 171 | 8,704,000 |
85587818
|
n = int(input())
*l, = map(int, input().split())
s = []
for i in range(n-1):
s.append(l[i] > l[i+1])
t = s.count(True)
if t==0 or t==1:
print("YES")
elif t==2:
r1 = s.index(True)
r2 = s.index(True, r1+1)
if l[r1] >= l[r2+1]:
print("YES")
else:
print("NO")
else:
print("NO")
| 96 | 93 | 13,516,800 |
199859703
|
n=int(input())
l=list(map(int,input().split()))
s=sorted(l)
c,i=0,0
for i in range(n):
if l[i]!=s[i]:
c=c+1
if c>2:
break
if c==2 or c==0:
print('YES')
else:
print('NO')
|
Codeforces Round 136 (Div. 1)
|
CF
| 2,012 | 2 | 256 |
Little Elephant and Problem
|
The Little Elephant has got a problem — somebody has been touching his sorted by non-decreasing array a of length n and possibly swapped some elements of the array.
The Little Elephant doesn't want to call the police until he understands if he could have accidentally changed the array himself. He thinks that he could have accidentally changed array a, only if array a can be sorted in no more than one operation of swapping elements (not necessarily adjacent). That is, the Little Elephant could have accidentally swapped some two elements.
Help the Little Elephant, determine if he could have accidentally changed the array a, sorted by non-decreasing, himself.
|
The first line contains a single integer n (2 ≤ n ≤ 105) — the size of array a. The next line contains n positive integers, separated by single spaces and not exceeding 109, — array a.
Note that the elements of the array are not necessarily distinct numbers.
|
In a single line print "YES" (without the quotes) if the Little Elephant could have accidentally changed the array himself, and "NO" (without the quotes) otherwise.
| null |
In the first sample the array has already been sorted, so to sort it, we need 0 swap operations, that is not more than 1. Thus, the answer is "YES".
In the second sample we can sort the array if we swap elements 1 and 3, so we need 1 swap operation to sort the array. Thus, the answer is "YES".
In the third sample we can't sort the array in more than one swap operation, so the answer is "NO".
|
[{"input": "2\n1 2", "output": "YES"}, {"input": "3\n3 2 1", "output": "YES"}, {"input": "4\n4 3 2 1", "output": "NO"}]
| 1,300 |
["implementation", "sortings"]
| 96 |
[{"input": "2\r\n1 2\r\n", "output": "YES\r\n"}, {"input": "3\r\n3 2 1\r\n", "output": "YES\r\n"}, {"input": "4\r\n4 3 2 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 2\r\n", "output": "YES\r\n"}, {"input": "2\r\n2 1\r\n", "output": "YES\r\n"}, {"input": "9\r\n7 7 8 8 10 10 10 10 1000000000\r\n", "output": "YES\r\n"}, {"input": "10\r\n1 2 9 4 5 6 7 8 3 10\r\n", "output": "YES\r\n"}, {"input": "4\r\n2 2 2 1\r\n", "output": "YES\r\n"}, {"input": "10\r\n1 2 4 4 4 5 5 7 7 10\r\n", "output": "YES\r\n"}, {"input": "10\r\n4 5 11 12 13 14 16 16 16 18\r\n", "output": "YES\r\n"}, {"input": "20\r\n38205814 119727790 127848638 189351562 742927936 284688399 318826601 326499046 387938139 395996609 494453625 551393005 561264192 573569187 600766727 606718722 730549586 261502770 751513115 943272321\r\n", "output": "YES\r\n"}, {"input": "47\r\n6 277 329 393 410 432 434 505 529 545 650 896 949 1053 1543 1554 1599 1648 1927 1976 1998 2141 2248 2384 2542 2638 2995 3155 3216 3355 3409 3597 3851 3940 4169 4176 4378 4378 4425 4490 4627 4986 5025 5033 5374 5453 5644\r\n", "output": "YES\r\n"}, {"input": "50\r\n6 7 8 4 10 3 2 7 1 3 10 3 4 7 2 3 7 4 10 6 8 10 9 6 5 10 9 6 1 8 9 4 3 7 3 10 5 3 10 1 6 10 6 7 10 7 1 5 9 5\r\n", "output": "NO\r\n"}, {"input": "100\r\n3 7 7 8 15 25 26 31 37 41 43 43 46 64 65 82 94 102 102 103 107 124 125 131 140 145 146 150 151 160 160 161 162 165 169 175 182 191 201 211 214 216 218 304 224 229 236 241 244 249 252 269 270 271 273 289 285 295 222 307 312 317 319 319 320 321 325 330 340 341 345 347 354 356 366 366 375 376 380 383 386 398 401 407 414 417 423 426 431 438 440 444 446 454 457 458 458 466 466 472\r\n", "output": "NO\r\n"}, {"input": "128\r\n1 2 4 6 8 17 20 20 23 33 43 49 49 49 52 73 74 75 82 84 85 87 90 91 102 103 104 105 111 111 401 142 142 152 155 160 175 176 178 181 183 184 187 188 191 193 326 202 202 214 224 225 236 239 240 243 246 247 249 249 257 257 261 264 265 271 277 281 284 284 286 289 290 296 297 303 305 307 307 317 318 320 322 200 332 342 393 349 350 350 369 375 381 381 385 385 387 393 347 397 398 115 402 407 407 408 410 411 411 416 423 426 429 429 430 440 447 449 463 464 466 471 473 480 480 483 497 503\r\n", "output": "NO\r\n"}, {"input": "4\r\n5 12 12 6\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 3 3 3 2\r\n", "output": "YES\r\n"}, {"input": "4\r\n2 1 1 1\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "4\r\n1000000000 1 1000000000 1\r\n", "output": "YES\r\n"}, {"input": "11\r\n2 2 2 2 2 2 2 2 2 2 1\r\n", "output": "YES\r\n"}, {"input": "6\r\n1 2 3 4 5 3\r\n", "output": "NO\r\n"}, {"input": "9\r\n3 3 3 2 2 2 1 1 1\r\n", "output": "NO\r\n"}, {"input": "4\r\n4 1 2 3\r\n", "output": "NO\r\n"}, {"input": "6\r\n3 4 5 6 7 2\r\n", "output": "NO\r\n"}, {"input": "4\r\n4 2 1 3\r\n", "output": "NO\r\n"}, {"input": "4\r\n3 3 2 2\r\n", "output": "NO\r\n"}, {"input": "4\r\n3 2 1 1\r\n", "output": "NO\r\n"}, {"input": "4\r\n4 5 1 1\r\n", "output": "NO\r\n"}, {"input": "6\r\n1 6 2 4 3 5\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 4 5 2 3\r\n", "output": "NO\r\n"}, {"input": "4\r\n2 2 1 1\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 4 3 2 1\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 4 2 2 3\r\n", "output": "NO\r\n"}, {"input": "6\r\n1 2 3 1 2 3\r\n", "output": "NO\r\n"}, {"input": "3\r\n3 1 2\r\n", "output": "NO\r\n"}, {"input": "5\r\n5 1 2 3 4\r\n", "output": "NO\r\n"}, {"input": "5\r\n3 3 3 2 2\r\n", "output": "NO\r\n"}, {"input": "5\r\n100 5 6 10 7\r\n", "output": "NO\r\n"}, {"input": "3\r\n2 3 1\r\n", "output": "NO\r\n"}, {"input": "5\r\n4 4 1 1 1\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 2 5 3 4\r\n", "output": "NO\r\n"}, {"input": "4\r\n3 4 1 2\r\n", "output": "NO\r\n"}, {"input": "4\r\n2 4 1 5\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 3 3 2 2\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 5 4 4 4\r\n", "output": "YES\r\n"}, {"input": "7\r\n3 2 1 2 3 5 4\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1 3 2 2\r\n", "output": "YES\r\n"}, {"input": "9\r\n1 8 7 7 7 7 7 8 3\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 3 2 3 3\r\n", "output": "YES\r\n"}, {"input": "10\r\n4 4 4 4 10 4 4 4 4 4\r\n", "output": "YES\r\n"}, {"input": "8\r\n3 6 6 6 6 6 4 9\r\n", "output": "YES\r\n"}, {"input": "4\r\n4 4 3 3\r\n", "output": "NO\r\n"}, {"input": "4\r\n3 2 2 4\r\n", "output": "YES\r\n"}, {"input": "5\r\n2 2 1 3 3\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 7 3 5\r\n", "output": "NO\r\n"}, {"input": "5\r\n2 3 4 5 1\r\n", "output": "NO\r\n"}, {"input": "6\r\n1 4 3 6 2 5\r\n", "output": "NO\r\n"}, {"input": "5\r\n3 3 1 5 4\r\n", "output": "NO\r\n"}, {"input": "4\r\n1 2 1 2\r\n", "output": "YES\r\n"}, {"input": "6\r\n4 5 3 4 2 6\r\n", "output": "NO\r\n"}, {"input": "11\r\n1 2 3 4 5 1 2 3 4 5 1\r\n", "output": "NO\r\n"}, {"input": "6\r\n6 1 2 3 4 5\r\n", "output": "NO\r\n"}, {"input": "5\r\n4 1 1 1 1\r\n", "output": "YES\r\n"}, {"input": "9\r\n1 2 3 5 4 6 7 8 9\r\n", "output": "YES\r\n"}, {"input": "6\r\n6 1 2 3 4 2\r\n", "output": "NO\r\n"}, {"input": "6\r\n2 2 2 2 3 2\r\n", "output": "YES\r\n"}, {"input": "3\r\n2 1 1\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 1 1 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 2 1 2\r\n", "output": "YES\r\n"}, {"input": "8\r\n5 5 5 5 5 5 1 1\r\n", "output": "NO\r\n"}]
| false |
stdio
| null | true |
540/C
|
540
|
C
|
Python 3
|
TESTS
| 4 | 61 | 5,017,600 |
161765142
|
import queue
import sys
from queue import Queue
def FILE_IO():
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
def get_input():
n, m = map(int, input().strip().split())
cave = []
for i in range(n):
cave.append(list(input().strip()))
sn, sm = map(int, input().strip().split())
dn, dm = map(int, input().strip().split())
return n, m, cave, sn - 1, sm - 1, dn - 1, dm - 1
DIRECTIONS = ((0, 1), (0, -1), (1, 0), (-1, 0))
def bfs(n, m, cave, sn, sm, dn, dm):
queue = Queue()
queue.put((sn, sm))
cnt = 1 if cave[dn][dm] == 'X' else 0
cave[dn][dm] = '.'
while not queue.empty():
ux, uy = queue.get()
cave[ux][uy] = 'X'
if ux == dn and uy == dm:
cnt += 1
if cnt == 2:
return 'YES'
cave[dn][dm] = '.'
for x, y in DIRECTIONS:
vx, vy = ux + x, uy + y
if 0 <= vx < n and 0 <= vy < m and cave[vx][vy] == '.':
queue.put((vx, vy))
return 'NO'
def solve():
n, m, cave, sn, sm, dn, dm = get_input()
print(bfs(n, m, cave, sn, sm, dn, dm))
# FILE_IO()
solve()
| 102 | 170 | 17,612,800 |
229996302
|
n, m = map(int, input().split())
cave = []
for _ in range(n):
cave.append([c for c in input().strip()])
start_x, start_y = map(int, input().split())
dest_x, dest_y = map(int, input().split())
visited = []
for _ in range(n):
visited.append([0] * m)
dx = [0, 0, -1, 1]
dy = [-1, 1, 0, 0]
queue = []
queue.append([start_x-1, start_y-1])
def can_reach_destination(dest_x, dest_y):
while queue:
x, y = queue.pop(0)
for k in range(4):
i = x + dx[k]
j = y + dy[k]
if 0 <= i < n and 0 <= j < m and not visited[i][j]:
visited[i][j] = 1
if i == dest_x and j == dest_y:
if cave[dest_x][dest_y] == 'X':
return "YES"
else:
cave[dest_x][dest_y] = 'X'
visited[dest_x][dest_y] = 0
else:
if cave[i][j] == 'X':
continue
queue.append([i, j])
return "NO"
print(can_reach_destination(dest_x - 1, dest_y - 1))# 1698403815.119092
|
Codeforces Round 301 (Div. 2)
|
CF
| 2,015 | 2 | 256 |
Ice Cave
|
You play a computer game. Your character stands on some level of a multilevel ice cave. In order to move on forward, you need to descend one level lower and the only way to do this is to fall through the ice.
The level of the cave where you are is a rectangular square grid of n rows and m columns. Each cell consists either from intact or from cracked ice. From each cell you can move to cells that are side-adjacent with yours (due to some limitations of the game engine you cannot make jumps on the same place, i.e. jump from a cell to itself). If you move to the cell with cracked ice, then your character falls down through it and if you move to the cell with intact ice, then the ice on this cell becomes cracked.
Let's number the rows with integers from 1 to n from top to bottom and the columns with integers from 1 to m from left to right. Let's denote a cell on the intersection of the r-th row and the c-th column as (r, c).
You are staying in the cell (r1, c1) and this cell is cracked because you've just fallen here from a higher level. You need to fall down through the cell (r2, c2) since the exit to the next level is there. Can you do this?
|
The first line contains two integers, n and m (1 ≤ n, m ≤ 500) — the number of rows and columns in the cave description.
Each of the next n lines describes the initial state of the level of the cave, each line consists of m characters "." (that is, intact ice) and "X" (cracked ice).
The next line contains two integers, r1 and c1 (1 ≤ r1 ≤ n, 1 ≤ c1 ≤ m) — your initial coordinates. It is guaranteed that the description of the cave contains character 'X' in cell (r1, c1), that is, the ice on the starting cell is initially cracked.
The next line contains two integers r2 and c2 (1 ≤ r2 ≤ n, 1 ≤ c2 ≤ m) — the coordinates of the cell through which you need to fall. The final cell may coincide with the starting one.
|
If you can reach the destination, print 'YES', otherwise print 'NO'.
| null |
In the first sample test one possible path is:
$$(1,6)\rightarrow(2,6)\rightarrow(3,6)\rightarrow(4,5)\rightarrow(4,4)\rightarrow(4,3)\rightarrow(4,2)\rightarrow(4,1)\rightarrow(3,2)\rightarrow(2,3)\rightarrow(2,2)$$
After the first visit of cell (2, 2) the ice on it cracks and when you step there for the second time, your character falls through the ice as intended.
|
[{"input": "4 6\nX...XX\n...XX.\n.X..X.\n......\n1 6\n2 2", "output": "YES"}, {"input": "5 4\n.X..\n...X\nX.X.\n....\n.XX.\n5 3\n1 1", "output": "NO"}, {"input": "4 7\n..X.XX.\n.XX..X.\nX...X..\nX......\n2 2\n1 6", "output": "YES"}]
| 2,000 |
["dfs and similar"]
| 102 |
[{"input": "4 6\r\nX...XX\r\n...XX.\r\n.X..X.\r\n......\r\n1 6\r\n2 2\r\n", "output": "YES\r\n"}, {"input": "5 4\r\n.X..\r\n...X\r\nX.X.\r\n....\r\n.XX.\r\n5 3\r\n1 1\r\n", "output": "NO\r\n"}, {"input": "4 7\r\n..X.XX.\r\n.XX..X.\r\nX...X..\r\nX......\r\n2 2\r\n1 6\r\n", "output": "YES\r\n"}, {"input": "5 3\r\n.XX\r\n...\r\n.X.\r\n.X.\r\n...\r\n1 3\r\n4 1\r\n", "output": "YES\r\n"}, {"input": "1 1\r\nX\r\n1 1\r\n1 1\r\n", "output": "NO\r\n"}, {"input": "1 6\r\n.X...X\r\n1 2\r\n1 5\r\n", "output": "NO\r\n"}, {"input": "7 1\r\nX\r\n.\r\n.\r\n.\r\nX\r\n.\r\n.\r\n5 1\r\n3 1\r\n", "output": "YES\r\n"}, {"input": "1 2\r\nXX\r\n1 1\r\n1 1\r\n", "output": "NO\r\n"}, {"input": "2 1\r\n.\r\nX\r\n2 1\r\n2 1\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n.X..\r\n..XX\r\n..X.\r\n1 2\r\n3 4\r\n", "output": "NO\r\n"}, {"input": "3 5\r\n.X.XX\r\nX...X\r\nX.X..\r\n2 1\r\n1 5\r\n", "output": "NO\r\n"}, {"input": "3 2\r\n..\r\nX.\r\n.X\r\n3 2\r\n3 1\r\n", "output": "NO\r\n"}, {"input": "3 4\r\nXX.X\r\nX...\r\n.X.X\r\n1 2\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "1 2\r\nX.\r\n1 1\r\n1 2\r\n", "output": "NO\r\n"}, {"input": "2 1\r\nX\r\nX\r\n2 1\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "2 2\r\nXX\r\nXX\r\n1 1\r\n2 2\r\n", "output": "NO\r\n"}, {"input": "2 2\r\n..\r\n.X\r\n2 2\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "2 2\r\n.X\r\n.X\r\n1 2\r\n2 2\r\n", "output": "YES\r\n"}, {"input": "2 2\r\n..\r\nXX\r\n2 1\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "4 2\r\nX.\r\n.X\r\n.X\r\nXX\r\n2 2\r\n3 1\r\n", "output": "NO\r\n"}, {"input": "2 4\r\nX.XX\r\n.X..\r\n2 2\r\n2 3\r\n", "output": "YES\r\n"}, {"input": "6 4\r\nX..X\r\n..X.\r\n.X..\r\n..X.\r\n.X..\r\nX..X\r\n1 1\r\n6 4\r\n", "output": "NO\r\n"}, {"input": "5 4\r\nX...\r\n..X.\r\n.X..\r\nX..X\r\n....\r\n4 4\r\n3 1\r\n", "output": "NO\r\n"}, {"input": "3 4\r\nX..X\r\n..XX\r\n.X..\r\n2 3\r\n3 1\r\n", "output": "NO\r\n"}, {"input": "20 20\r\n....................\r\n.......X...........X\r\n............X......X\r\n.X...XX..X....X.....\r\n....X.....X.........\r\nX..........X........\r\n......X........X....\r\n....................\r\n...................X\r\n......X.............\r\n..............X.....\r\n......X.X...........\r\n.X.........X.X......\r\n.........X......X..X\r\n..................X.\r\n...X........X.......\r\n....................\r\n....................\r\n..X.....X...........\r\n........X......X.X..\r\n20 16\r\n5 20\r\n", "output": "YES\r\n"}, {"input": "21 21\r\n.....X...X.........X.\r\n...X...XX......X.....\r\n..X........X.X...XX..\r\n.........X....X...X..\r\nX...X...........XX...\r\n...X...X....XX...XXX.\r\n.X............X......\r\n......X.X............\r\n.X...X.........X.X...\r\n......XX......X.X....\r\n....X.......X.XXX....\r\n.X.......X..XXX.X..X.\r\n..X........X....X...X\r\n.........X..........X\r\n.....XX.....X........\r\n...XX......X.........\r\n.....X...XX...X......\r\n..X.X....XX..XX.X....\r\nX........X.X..XX..X..\r\nX..X......X...X.X....\r\nX.....X.....X.X......\r\n20 4\r\n21 5\r\n", "output": "YES\r\n"}, {"input": "2 1\r\nX\r\nX\r\n2 1\r\n2 1\r\n", "output": "NO\r\n"}, {"input": "2 2\r\nXX\r\nX.\r\n1 1\r\n2 2\r\n", "output": "NO\r\n"}, {"input": "2 1\r\nX\r\nX\r\n1 1\r\n1 1\r\n", "output": "NO\r\n"}, {"input": "1 2\r\nXX\r\n1 2\r\n1 2\r\n", "output": "NO\r\n"}, {"input": "1 2\r\nXX\r\n1 1\r\n1 2\r\n", "output": "YES\r\n"}, {"input": "1 2\r\nXX\r\n1 2\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "2 1\r\nX\r\nX\r\n1 1\r\n2 1\r\n", "output": "YES\r\n"}, {"input": "2 1\r\n.\r\nX\r\n2 1\r\n1 1\r\n", "output": "NO\r\n"}, {"input": "2 1\r\nX\r\n.\r\n1 1\r\n2 1\r\n", "output": "NO\r\n"}, {"input": "1 2\r\n.X\r\n1 2\r\n1 1\r\n", "output": "NO\r\n"}, {"input": "2 1\r\nX\r\n.\r\n1 1\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "1 2\r\nX.\r\n1 1\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "1 2\r\n.X\r\n1 2\r\n1 2\r\n", "output": "YES\r\n"}, {"input": "2 2\r\nX.\r\n..\r\n1 1\r\n2 2\r\n", "output": "YES\r\n"}, {"input": "2 2\r\n..\r\nX.\r\n2 1\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "4 3\r\n..X\r\n..X\r\n.XX\r\n.XX\r\n4 2\r\n2 2\r\n", "output": "YES\r\n"}, {"input": "3 3\r\nXXX\r\nX..\r\nXXX\r\n2 1\r\n2 2\r\n", "output": "YES\r\n"}, {"input": "5 4\r\nXXXX\r\nX..X\r\nX..X\r\nXXXX\r\nXXXX\r\n4 2\r\n3 3\r\n", "output": "YES\r\n"}]
| false |
stdio
| null | true |
540/C
|
540
|
C
|
PyPy 3-64
|
TESTS
| 4 | 93 | 5,120,000 |
202469317
|
from bisect import bisect_left as bl, bisect_right as br, insort_left, insort_right
from collections import deque, Counter as counter, defaultdict as dd
from copy import copy, deepcopy
from functools import cache, cmp_to_key, lru_cache, reduce, partial
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge, nlargest, nsmallest
from itertools import count, cycle, repeat, accumulate, chain, groupby, starmap, product, permutations, combinations, combinations_with_replacement, zip_longest, islice
from math import ceil, comb, factorial, floor, gcd, lcm, prod, log, sqrt, acos, asin, atan, dist, sin, cos, tan, degrees, radians, pi, e, inf
from operator import add, sub, mul, truediv, floordiv, mod, xor, and_, or_, eq, ne, neg, concat, contains
from random import randint, choice, shuffle, sample
from string import ascii_lowercase as lowers, ascii_uppercase as uppers, ascii_letters as all_letters, digits
from sys import stdin, argv, setrecursionlimit
def lmap(function, iterable): return list(map(function, iterable))
def line(): return stdin.readline().strip()
def rd(converter): return converter(line())
def rl(converter, delimeter = None): return lmap(converter, line().split(delimeter))
def rls(num_lines, converter): return [rd(converter) for i in range(num_lines)]
def rg(num_lines, converter, delimeter = None): return [rl(converter,delimeter) for i in range(num_lines)]
MOD = 10**9+7
MULTIPLE_CASES = 0
def main():
N,M = rl(int)
grid = rls(N,str)
R1,C1 = rl(int)
R2,C2 = rl(int)
R1 -= 1
C1 -= 1
R2 -= 1
C2 -= 1
if abs(R2-R1) + abs(C2-C1) <= 1:
print("YES" if grid[R2][C2] == "X" or any(r in range(N) and c in range(M) and grid[r][c] == "." for r,c in [[R2+1,C2],[R2-1,C2],[R2,C2+1],[R2,C2-1]]) else "NO")
return
dfs = [[R1,C1]]
seen = {(R1,C1)}
while dfs:
r,c = dfs.pop()
for r2,c2 in [[r+1,c],[r-1,c],[r,c+1],[r,c-1]]:
if r2 in range(N) and c2 in range(M) and (r2,c2) not in seen:
if [r2,c2] == [R2,C2]:
print("YES" if grid[R2][C2] == "X" or sum(r in range(N) and c in range(M) and grid[r][c] == "." for r,c in [[R2+1,C2],[R2-1,C2],[R2,C2+1],[R2,C2-1]]) >= 2 else "NO")
return
if grid[r2][c2] == ".":
seen.add((r2,c2))
dfs.append([r2,c2])
print("NO")
for i in range(rd(int) if MULTIPLE_CASES else 1): main()
| 102 | 280 | 18,636,800 |
121398770
|
import queue
MAX = 500
dr = [0,0,1,-1]
dc = [1,-1,0,0]
def isValid(r, c):
return r in range(m) and c in range(n)
def BFS(sr, sc, fr, fc):
q = [0] * (MAX * MAX)
left = right = 0
q[0] = (sr, sc)
while left <= right:
ur, uc = q[left]
left += 1
for i in range(4):
vr = ur + dr[i]
vc = uc + dc[i]
if isValid(vr, vc):
if maze[vr][vc] == '.':
maze[vr][vc] = 'X'
right += 1
q[right] = (vr,vc)
else:
if(vr == fr) and (vc==fc):
return True
return False
if __name__ == '__main__':
maze = [] * MAX
m, n = map(int, input().split())
for i in range(m):
temp = list(input())
maze.append(temp)
start, start2 = map(int, input().split())
end1, end2 = map(int, input().split())
if(BFS(start-1,start2-1,end1-1,end2-1)):
print('YES')
else:
print('NO')
|
Codeforces Round 301 (Div. 2)
|
CF
| 2,015 | 2 | 256 |
Ice Cave
|
You play a computer game. Your character stands on some level of a multilevel ice cave. In order to move on forward, you need to descend one level lower and the only way to do this is to fall through the ice.
The level of the cave where you are is a rectangular square grid of n rows and m columns. Each cell consists either from intact or from cracked ice. From each cell you can move to cells that are side-adjacent with yours (due to some limitations of the game engine you cannot make jumps on the same place, i.e. jump from a cell to itself). If you move to the cell with cracked ice, then your character falls down through it and if you move to the cell with intact ice, then the ice on this cell becomes cracked.
Let's number the rows with integers from 1 to n from top to bottom and the columns with integers from 1 to m from left to right. Let's denote a cell on the intersection of the r-th row and the c-th column as (r, c).
You are staying in the cell (r1, c1) and this cell is cracked because you've just fallen here from a higher level. You need to fall down through the cell (r2, c2) since the exit to the next level is there. Can you do this?
|
The first line contains two integers, n and m (1 ≤ n, m ≤ 500) — the number of rows and columns in the cave description.
Each of the next n lines describes the initial state of the level of the cave, each line consists of m characters "." (that is, intact ice) and "X" (cracked ice).
The next line contains two integers, r1 and c1 (1 ≤ r1 ≤ n, 1 ≤ c1 ≤ m) — your initial coordinates. It is guaranteed that the description of the cave contains character 'X' in cell (r1, c1), that is, the ice on the starting cell is initially cracked.
The next line contains two integers r2 and c2 (1 ≤ r2 ≤ n, 1 ≤ c2 ≤ m) — the coordinates of the cell through which you need to fall. The final cell may coincide with the starting one.
|
If you can reach the destination, print 'YES', otherwise print 'NO'.
| null |
In the first sample test one possible path is:
$$(1,6)\rightarrow(2,6)\rightarrow(3,6)\rightarrow(4,5)\rightarrow(4,4)\rightarrow(4,3)\rightarrow(4,2)\rightarrow(4,1)\rightarrow(3,2)\rightarrow(2,3)\rightarrow(2,2)$$
After the first visit of cell (2, 2) the ice on it cracks and when you step there for the second time, your character falls through the ice as intended.
|
[{"input": "4 6\nX...XX\n...XX.\n.X..X.\n......\n1 6\n2 2", "output": "YES"}, {"input": "5 4\n.X..\n...X\nX.X.\n....\n.XX.\n5 3\n1 1", "output": "NO"}, {"input": "4 7\n..X.XX.\n.XX..X.\nX...X..\nX......\n2 2\n1 6", "output": "YES"}]
| 2,000 |
["dfs and similar"]
| 102 |
[{"input": "4 6\r\nX...XX\r\n...XX.\r\n.X..X.\r\n......\r\n1 6\r\n2 2\r\n", "output": "YES\r\n"}, {"input": "5 4\r\n.X..\r\n...X\r\nX.X.\r\n....\r\n.XX.\r\n5 3\r\n1 1\r\n", "output": "NO\r\n"}, {"input": "4 7\r\n..X.XX.\r\n.XX..X.\r\nX...X..\r\nX......\r\n2 2\r\n1 6\r\n", "output": "YES\r\n"}, {"input": "5 3\r\n.XX\r\n...\r\n.X.\r\n.X.\r\n...\r\n1 3\r\n4 1\r\n", "output": "YES\r\n"}, {"input": "1 1\r\nX\r\n1 1\r\n1 1\r\n", "output": "NO\r\n"}, {"input": "1 6\r\n.X...X\r\n1 2\r\n1 5\r\n", "output": "NO\r\n"}, {"input": "7 1\r\nX\r\n.\r\n.\r\n.\r\nX\r\n.\r\n.\r\n5 1\r\n3 1\r\n", "output": "YES\r\n"}, {"input": "1 2\r\nXX\r\n1 1\r\n1 1\r\n", "output": "NO\r\n"}, {"input": "2 1\r\n.\r\nX\r\n2 1\r\n2 1\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n.X..\r\n..XX\r\n..X.\r\n1 2\r\n3 4\r\n", "output": "NO\r\n"}, {"input": "3 5\r\n.X.XX\r\nX...X\r\nX.X..\r\n2 1\r\n1 5\r\n", "output": "NO\r\n"}, {"input": "3 2\r\n..\r\nX.\r\n.X\r\n3 2\r\n3 1\r\n", "output": "NO\r\n"}, {"input": "3 4\r\nXX.X\r\nX...\r\n.X.X\r\n1 2\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "1 2\r\nX.\r\n1 1\r\n1 2\r\n", "output": "NO\r\n"}, {"input": "2 1\r\nX\r\nX\r\n2 1\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "2 2\r\nXX\r\nXX\r\n1 1\r\n2 2\r\n", "output": "NO\r\n"}, {"input": "2 2\r\n..\r\n.X\r\n2 2\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "2 2\r\n.X\r\n.X\r\n1 2\r\n2 2\r\n", "output": "YES\r\n"}, {"input": "2 2\r\n..\r\nXX\r\n2 1\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "4 2\r\nX.\r\n.X\r\n.X\r\nXX\r\n2 2\r\n3 1\r\n", "output": "NO\r\n"}, {"input": "2 4\r\nX.XX\r\n.X..\r\n2 2\r\n2 3\r\n", "output": "YES\r\n"}, {"input": "6 4\r\nX..X\r\n..X.\r\n.X..\r\n..X.\r\n.X..\r\nX..X\r\n1 1\r\n6 4\r\n", "output": "NO\r\n"}, {"input": "5 4\r\nX...\r\n..X.\r\n.X..\r\nX..X\r\n....\r\n4 4\r\n3 1\r\n", "output": "NO\r\n"}, {"input": "3 4\r\nX..X\r\n..XX\r\n.X..\r\n2 3\r\n3 1\r\n", "output": "NO\r\n"}, {"input": "20 20\r\n....................\r\n.......X...........X\r\n............X......X\r\n.X...XX..X....X.....\r\n....X.....X.........\r\nX..........X........\r\n......X........X....\r\n....................\r\n...................X\r\n......X.............\r\n..............X.....\r\n......X.X...........\r\n.X.........X.X......\r\n.........X......X..X\r\n..................X.\r\n...X........X.......\r\n....................\r\n....................\r\n..X.....X...........\r\n........X......X.X..\r\n20 16\r\n5 20\r\n", "output": "YES\r\n"}, {"input": "21 21\r\n.....X...X.........X.\r\n...X...XX......X.....\r\n..X........X.X...XX..\r\n.........X....X...X..\r\nX...X...........XX...\r\n...X...X....XX...XXX.\r\n.X............X......\r\n......X.X............\r\n.X...X.........X.X...\r\n......XX......X.X....\r\n....X.......X.XXX....\r\n.X.......X..XXX.X..X.\r\n..X........X....X...X\r\n.........X..........X\r\n.....XX.....X........\r\n...XX......X.........\r\n.....X...XX...X......\r\n..X.X....XX..XX.X....\r\nX........X.X..XX..X..\r\nX..X......X...X.X....\r\nX.....X.....X.X......\r\n20 4\r\n21 5\r\n", "output": "YES\r\n"}, {"input": "2 1\r\nX\r\nX\r\n2 1\r\n2 1\r\n", "output": "NO\r\n"}, {"input": "2 2\r\nXX\r\nX.\r\n1 1\r\n2 2\r\n", "output": "NO\r\n"}, {"input": "2 1\r\nX\r\nX\r\n1 1\r\n1 1\r\n", "output": "NO\r\n"}, {"input": "1 2\r\nXX\r\n1 2\r\n1 2\r\n", "output": "NO\r\n"}, {"input": "1 2\r\nXX\r\n1 1\r\n1 2\r\n", "output": "YES\r\n"}, {"input": "1 2\r\nXX\r\n1 2\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "2 1\r\nX\r\nX\r\n1 1\r\n2 1\r\n", "output": "YES\r\n"}, {"input": "2 1\r\n.\r\nX\r\n2 1\r\n1 1\r\n", "output": "NO\r\n"}, {"input": "2 1\r\nX\r\n.\r\n1 1\r\n2 1\r\n", "output": "NO\r\n"}, {"input": "1 2\r\n.X\r\n1 2\r\n1 1\r\n", "output": "NO\r\n"}, {"input": "2 1\r\nX\r\n.\r\n1 1\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "1 2\r\nX.\r\n1 1\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "1 2\r\n.X\r\n1 2\r\n1 2\r\n", "output": "YES\r\n"}, {"input": "2 2\r\nX.\r\n..\r\n1 1\r\n2 2\r\n", "output": "YES\r\n"}, {"input": "2 2\r\n..\r\nX.\r\n2 1\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "4 3\r\n..X\r\n..X\r\n.XX\r\n.XX\r\n4 2\r\n2 2\r\n", "output": "YES\r\n"}, {"input": "3 3\r\nXXX\r\nX..\r\nXXX\r\n2 1\r\n2 2\r\n", "output": "YES\r\n"}, {"input": "5 4\r\nXXXX\r\nX..X\r\nX..X\r\nXXXX\r\nXXXX\r\n4 2\r\n3 3\r\n", "output": "YES\r\n"}]
| false |
stdio
| null | true |
540/C
|
540
|
C
|
PyPy 3
|
TESTS
| 4 | 124 | 0 |
90499658
|
def is_valid_tile(r, c, n, m):
return r >= 0 and c >= 0 and r < n and c < m
def gen_adjacents(r, c, n, m):
adjs = []
possibles = [(r + 1, c), (r - 1, c), (r, c + 1), (r, c - 1)]
for possible in possibles:
if is_valid_tile(*possible, n, m):
adjs.append(possible)
return adjs
def solve(table, r1, c1, r2, c2, n, m):
if r1 == r2 and c1 == c2:
adjacents = gen_adjacents(r1, c1, n, m)
for adjacent in adjacents:
if table[adjacent[0]][adjacent[1]] == "X":
return False
return True
if table[r2][c2] == ".":
adjacents = gen_adjacents(r2, c2, n, m)
solid = 0
for adj in adjacents:
if table[adj[0]][adj[1]] == ".":
solid += 1
if solid < 2:
return False
forward_visited = set([(r1, c1)]); backward_visited = set([(r2, c2)])
forward_nodes = [(r1, c1)]; backward_nodes = [(r2, c2)]
while forward_nodes and backward_nodes:
for i in range(len(forward_nodes)):
node = forward_nodes.pop(0)
adjacents = gen_adjacents(*node, n, m)
for adjacent in adjacents:
if adjacent in backward_visited:
return True
if adjacent not in forward_visited and table[adjacent[0]][adjacent[1]] == ".":
forward_visited.add(adjacent)
forward_nodes.append(adjacent)
for j in range(len(backward_nodes)):
node = backward_nodes.pop(0)
adjacents = gen_adjacents(*node, n, m)
for adjacent in adjacents:
if adjacent in forward_visited:
return True
if adjacent not in backward_visited and table[adjacent[0]][adjacent[1]] == ".":
backward_visited.add(adjacent)
backward_nodes.append(adjacent)
return False
def main():
n, m = map(int, input().split())
table = []
for _ in range(n):
row = input()
table.append(row)
r1, c1 = map(int, input().split())
r2, c2 = map(int, input().split())
r1 -= 1; c1 -= 1; r2 -= 1; c2 -= 1
if solve(table, r1, c1, r2, c2, n, m):
print("YES")
else:
print("NO")
main()
| 102 | 280 | 27,340,800 |
142946642
|
import math
import os
import sys
from io import BytesIO, IOBase
from types import GeneratorType
from collections import defaultdict
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
#sys.setrecursionlimit(10**5)
def bootstrap(f, stack=[]):
def wrappedfunc(*args, **kwargs):
if stack:
return f(*args, **kwargs)
else:
to = f(*args, **kwargs)
while True:
if type(to) is GeneratorType:
stack.append(to)
to = next(to)
else:
stack.pop()
if not stack:
break
to = stack[-1].send(to)
return to
return wrappedfunc
def f(s):
r=[]
for j in s:
r.append(j)
return r
def valid(x):
return True if 0<=x[0]<n and 0<=x[1]<m and inp[x[0]][x[1]]=='.' else False
def getn(x):
toret=[]
y=(x[0]-1,x[1])
if valid(y):
toret.append(y)
y=(x[0]+1,x[1])
if valid(y):
toret.append(y)
y=(x[0],x[1]-1)
if valid(y):
toret.append(y)
y=(x[0],x[1]+1)
if valid(y):
toret.append(y)
return toret
n,m=[int(x) for x in input().split()]
inp=[input() for i in range(n)]
source=[int(x)-1 for x in input().split()]
dest=[int(x)-1 for x in input().split()]
if source==dest:
print('YES' if len(getn(dest)) else 'NO')
else:
dat=False
dis=0
if inp[dest[0]][dest[1]]=='X':
inp[dest[0]]=inp[dest[0]][:dest[1]]+'.'+inp[dest[0]][dest[1]+1:]
dat=True
if tuple(dest) in getn(source):
dis=1
vis=[[False]*m for i in range(n)]
st=[source]
while (st):
x=st.pop()
if vis[x[0]][x[1]]:
continue
vis[x[0]][x[1]]=True
for i in getn(x):
st.append(i)
print('YES' if vis[dest[0]][dest[1]] and (len(getn(dest))>1-dis or dat) else 'NO')
|
Codeforces Round 301 (Div. 2)
|
CF
| 2,015 | 2 | 256 |
Ice Cave
|
You play a computer game. Your character stands on some level of a multilevel ice cave. In order to move on forward, you need to descend one level lower and the only way to do this is to fall through the ice.
The level of the cave where you are is a rectangular square grid of n rows and m columns. Each cell consists either from intact or from cracked ice. From each cell you can move to cells that are side-adjacent with yours (due to some limitations of the game engine you cannot make jumps on the same place, i.e. jump from a cell to itself). If you move to the cell with cracked ice, then your character falls down through it and if you move to the cell with intact ice, then the ice on this cell becomes cracked.
Let's number the rows with integers from 1 to n from top to bottom and the columns with integers from 1 to m from left to right. Let's denote a cell on the intersection of the r-th row and the c-th column as (r, c).
You are staying in the cell (r1, c1) and this cell is cracked because you've just fallen here from a higher level. You need to fall down through the cell (r2, c2) since the exit to the next level is there. Can you do this?
|
The first line contains two integers, n and m (1 ≤ n, m ≤ 500) — the number of rows and columns in the cave description.
Each of the next n lines describes the initial state of the level of the cave, each line consists of m characters "." (that is, intact ice) and "X" (cracked ice).
The next line contains two integers, r1 and c1 (1 ≤ r1 ≤ n, 1 ≤ c1 ≤ m) — your initial coordinates. It is guaranteed that the description of the cave contains character 'X' in cell (r1, c1), that is, the ice on the starting cell is initially cracked.
The next line contains two integers r2 and c2 (1 ≤ r2 ≤ n, 1 ≤ c2 ≤ m) — the coordinates of the cell through which you need to fall. The final cell may coincide with the starting one.
|
If you can reach the destination, print 'YES', otherwise print 'NO'.
| null |
In the first sample test one possible path is:
$$(1,6)\rightarrow(2,6)\rightarrow(3,6)\rightarrow(4,5)\rightarrow(4,4)\rightarrow(4,3)\rightarrow(4,2)\rightarrow(4,1)\rightarrow(3,2)\rightarrow(2,3)\rightarrow(2,2)$$
After the first visit of cell (2, 2) the ice on it cracks and when you step there for the second time, your character falls through the ice as intended.
|
[{"input": "4 6\nX...XX\n...XX.\n.X..X.\n......\n1 6\n2 2", "output": "YES"}, {"input": "5 4\n.X..\n...X\nX.X.\n....\n.XX.\n5 3\n1 1", "output": "NO"}, {"input": "4 7\n..X.XX.\n.XX..X.\nX...X..\nX......\n2 2\n1 6", "output": "YES"}]
| 2,000 |
["dfs and similar"]
| 102 |
[{"input": "4 6\r\nX...XX\r\n...XX.\r\n.X..X.\r\n......\r\n1 6\r\n2 2\r\n", "output": "YES\r\n"}, {"input": "5 4\r\n.X..\r\n...X\r\nX.X.\r\n....\r\n.XX.\r\n5 3\r\n1 1\r\n", "output": "NO\r\n"}, {"input": "4 7\r\n..X.XX.\r\n.XX..X.\r\nX...X..\r\nX......\r\n2 2\r\n1 6\r\n", "output": "YES\r\n"}, {"input": "5 3\r\n.XX\r\n...\r\n.X.\r\n.X.\r\n...\r\n1 3\r\n4 1\r\n", "output": "YES\r\n"}, {"input": "1 1\r\nX\r\n1 1\r\n1 1\r\n", "output": "NO\r\n"}, {"input": "1 6\r\n.X...X\r\n1 2\r\n1 5\r\n", "output": "NO\r\n"}, {"input": "7 1\r\nX\r\n.\r\n.\r\n.\r\nX\r\n.\r\n.\r\n5 1\r\n3 1\r\n", "output": "YES\r\n"}, {"input": "1 2\r\nXX\r\n1 1\r\n1 1\r\n", "output": "NO\r\n"}, {"input": "2 1\r\n.\r\nX\r\n2 1\r\n2 1\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n.X..\r\n..XX\r\n..X.\r\n1 2\r\n3 4\r\n", "output": "NO\r\n"}, {"input": "3 5\r\n.X.XX\r\nX...X\r\nX.X..\r\n2 1\r\n1 5\r\n", "output": "NO\r\n"}, {"input": "3 2\r\n..\r\nX.\r\n.X\r\n3 2\r\n3 1\r\n", "output": "NO\r\n"}, {"input": "3 4\r\nXX.X\r\nX...\r\n.X.X\r\n1 2\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "1 2\r\nX.\r\n1 1\r\n1 2\r\n", "output": "NO\r\n"}, {"input": "2 1\r\nX\r\nX\r\n2 1\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "2 2\r\nXX\r\nXX\r\n1 1\r\n2 2\r\n", "output": "NO\r\n"}, {"input": "2 2\r\n..\r\n.X\r\n2 2\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "2 2\r\n.X\r\n.X\r\n1 2\r\n2 2\r\n", "output": "YES\r\n"}, {"input": "2 2\r\n..\r\nXX\r\n2 1\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "4 2\r\nX.\r\n.X\r\n.X\r\nXX\r\n2 2\r\n3 1\r\n", "output": "NO\r\n"}, {"input": "2 4\r\nX.XX\r\n.X..\r\n2 2\r\n2 3\r\n", "output": "YES\r\n"}, {"input": "6 4\r\nX..X\r\n..X.\r\n.X..\r\n..X.\r\n.X..\r\nX..X\r\n1 1\r\n6 4\r\n", "output": "NO\r\n"}, {"input": "5 4\r\nX...\r\n..X.\r\n.X..\r\nX..X\r\n....\r\n4 4\r\n3 1\r\n", "output": "NO\r\n"}, {"input": "3 4\r\nX..X\r\n..XX\r\n.X..\r\n2 3\r\n3 1\r\n", "output": "NO\r\n"}, {"input": "20 20\r\n....................\r\n.......X...........X\r\n............X......X\r\n.X...XX..X....X.....\r\n....X.....X.........\r\nX..........X........\r\n......X........X....\r\n....................\r\n...................X\r\n......X.............\r\n..............X.....\r\n......X.X...........\r\n.X.........X.X......\r\n.........X......X..X\r\n..................X.\r\n...X........X.......\r\n....................\r\n....................\r\n..X.....X...........\r\n........X......X.X..\r\n20 16\r\n5 20\r\n", "output": "YES\r\n"}, {"input": "21 21\r\n.....X...X.........X.\r\n...X...XX......X.....\r\n..X........X.X...XX..\r\n.........X....X...X..\r\nX...X...........XX...\r\n...X...X....XX...XXX.\r\n.X............X......\r\n......X.X............\r\n.X...X.........X.X...\r\n......XX......X.X....\r\n....X.......X.XXX....\r\n.X.......X..XXX.X..X.\r\n..X........X....X...X\r\n.........X..........X\r\n.....XX.....X........\r\n...XX......X.........\r\n.....X...XX...X......\r\n..X.X....XX..XX.X....\r\nX........X.X..XX..X..\r\nX..X......X...X.X....\r\nX.....X.....X.X......\r\n20 4\r\n21 5\r\n", "output": "YES\r\n"}, {"input": "2 1\r\nX\r\nX\r\n2 1\r\n2 1\r\n", "output": "NO\r\n"}, {"input": "2 2\r\nXX\r\nX.\r\n1 1\r\n2 2\r\n", "output": "NO\r\n"}, {"input": "2 1\r\nX\r\nX\r\n1 1\r\n1 1\r\n", "output": "NO\r\n"}, {"input": "1 2\r\nXX\r\n1 2\r\n1 2\r\n", "output": "NO\r\n"}, {"input": "1 2\r\nXX\r\n1 1\r\n1 2\r\n", "output": "YES\r\n"}, {"input": "1 2\r\nXX\r\n1 2\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "2 1\r\nX\r\nX\r\n1 1\r\n2 1\r\n", "output": "YES\r\n"}, {"input": "2 1\r\n.\r\nX\r\n2 1\r\n1 1\r\n", "output": "NO\r\n"}, {"input": "2 1\r\nX\r\n.\r\n1 1\r\n2 1\r\n", "output": "NO\r\n"}, {"input": "1 2\r\n.X\r\n1 2\r\n1 1\r\n", "output": "NO\r\n"}, {"input": "2 1\r\nX\r\n.\r\n1 1\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "1 2\r\nX.\r\n1 1\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "1 2\r\n.X\r\n1 2\r\n1 2\r\n", "output": "YES\r\n"}, {"input": "2 2\r\nX.\r\n..\r\n1 1\r\n2 2\r\n", "output": "YES\r\n"}, {"input": "2 2\r\n..\r\nX.\r\n2 1\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "4 3\r\n..X\r\n..X\r\n.XX\r\n.XX\r\n4 2\r\n2 2\r\n", "output": "YES\r\n"}, {"input": "3 3\r\nXXX\r\nX..\r\nXXX\r\n2 1\r\n2 2\r\n", "output": "YES\r\n"}, {"input": "5 4\r\nXXXX\r\nX..X\r\nX..X\r\nXXXX\r\nXXXX\r\n4 2\r\n3 3\r\n", "output": "YES\r\n"}]
| false |
stdio
| null | true |
613/A
|
613
|
A
|
PyPy 3-64
|
TESTS
| 37 | 717 | 12,390,400 |
190207221
|
import math
from math import sqrt, inf, gcd, ceil, tan, pi, sin, cos
import queue
# -------- info --------
# https://codeforces.com/profile/Wolxy
# -------- sys --------
def next_int() -> int:
return int(input())
def next_ints() -> map:
return map(int, input().split(' '))
def next_list() -> list:
return list(map(int, input().split(' ')))
def dis(from_loc, to_loc, manhattan_distance = False) -> int:
result = 0
if not manhattan_distance:
for i in range(min(len(from_loc), len(to_loc))):
result += (from_loc[i] - to_loc[i]) * (from_loc[i] - to_loc[i])
else:
for i in range(min(len(from_loc), len(to_loc))):
result += abs(from_loc[i] - to_loc[i])
return result
def vector(from_loc, to_loc) -> tuple[int, int]:
return to_loc[0] - from_loc[0], to_loc[1] - from_loc[1]
def product(from_loc, first_loc, second_loc) -> int:
vector1 = vector(from_loc, first_loc)
vector2 = vector(from_loc, second_loc)
return vector1[0] * vector2[1] - vector2[0] * vector1[1]
def product(vector1, vector2) -> int:
return vector1[0] * vector2[1] - vector2[0] * vector1[1]
def dot(from_loc, first_loc, second_loc) -> int:
vector1 = vector(from_loc, first_loc)
vector2 = vector(from_loc, second_loc)
return vector1[0] * vector2[0] + vector1[1] * vector2[1]
def get_line_equation(first_loc, second_loc) -> (int, int, int):
line_vector = vector(first_loc, second_loc)
line_gcd = gcd(line_vector[0], line_vector[1])
line_a, line_b = line_vector[1] // line_gcd, line_vector[0] // line_gcd
line_c = line_b * first_loc[1] - line_a * first_loc[0]
return line_a, line_b, line_c
# -------- functions[clearable] --------
def fun(loc) -> int:
return loc[1]
# -------- solve[clearable] --------
def solve() -> None:
n, x, y = next_ints()
mn, mx = inf, -inf
ls = []
for i in range(n):
t_x, t_y = next_ints()
ls.append((t_x, t_y))
mn = min(mn, dis((x, y), (t_x, t_y)))
mx = max(mx, dis((x, y), (t_x, t_y)))
if i <= 0:
continue
oa = vector((x, y), ls[i - 1])
ob = vector((x, y), ls[i])
oh = vector(ls[i - 1], ls[i])
oh = (-oh[1], oh[0])
if product(oa, oh) * product(ob, oh) < 0:
a, b, c = get_line_equation(ls[i - 1], ls[i])
mn = min(mn, (a * x + b * y + c) * (a * x + b * y + c) / (a * a + b * b))
oa = vector((x, y), ls[-1])
ob = vector((x, y), ls[0])
oh = vector(ls[-1], ls[0])
oh = (-oh[1], oh[0])
if product(oa, oh) * product(ob, oh) < 0:
a, b, c = get_line_equation(ls[0], ls[-1])
mn = min(mn, (a * x + b * y + c) * (a * x + b * y + c) / (a * a + b * b))
print(pi * (mx - mn))
# print(mx, mn)
# -------- main --------
T = 1
# T = int(input())
for _ in range(T):
solve()
'''3 0 0
-1 1
0 3
1 1
'''
| 60 | 577 | 12,185,600 |
15396149
|
from math import hypot, pi, copysign
def main():
n, a, b = map(int, input().split())
l, res = [], []
for _ in range(n):
x0, y0 = map(int, input().split())
l.append((x0 - a, y0 - b))
x0, y0 = l[-1]
for x1, y1 in l:
res.append(hypot(x1, y1))
dx, dy = x1 - x0, y1 - y0
if copysign(1., x0 * dx + y0 * dy) != copysign(1., x1 * dx + y1 * dy):
res.append(abs(x0 * y1 - x1 * y0) / hypot(dx, dy))
x0, y0 = x1, y1
print((max(res) ** 2 - min(res) ** 2) * pi)
if __name__ == '__main__':
main()
|
Codeforces Round 339 (Div. 1)
|
CF
| 2,016 | 2 | 256 |
Peter and Snow Blower
|
Peter got a new snow blower as a New Year present. Of course, Peter decided to try it immediately. After reading the instructions he realized that it does not work like regular snow blowing machines. In order to make it work, you need to tie it to some point that it does not cover, and then switch it on. As a result it will go along a circle around this point and will remove all the snow from its path.
Formally, we assume that Peter's machine is a polygon on a plane. Then, after the machine is switched on, it will make a circle around the point to which Peter tied it (this point lies strictly outside the polygon). That is, each of the points lying within or on the border of the polygon will move along the circular trajectory, with the center of the circle at the point to which Peter tied his machine.
Peter decided to tie his car to point P and now he is wondering what is the area of the region that will be cleared from snow. Help him.
|
The first line of the input contains three integers — the number of vertices of the polygon n ($$3 \leq n \leq 100\ 000$$), and coordinates of point P.
Each of the next n lines contains two integers — coordinates of the vertices of the polygon in the clockwise or counterclockwise order. It is guaranteed that no three consecutive vertices lie on a common straight line.
All the numbers in the input are integers that do not exceed 1 000 000 in their absolute value.
|
Print a single real value number — the area of the region that will be cleared. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.
Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if $$\frac{|a-b|}{\max(1,b)} \leq 10^{-6}$$.
| null |
In the first sample snow will be removed from that area:
|
[{"input": "3 0 0\n0 1\n-1 2\n1 2", "output": "12.566370614359172464"}, {"input": "4 1 -1\n0 0\n1 2\n2 0\n1 1", "output": "21.991148575128551812"}]
| 1,900 |
["binary search", "geometry", "ternary search"]
| 60 |
[{"input": "3 0 0\r\n0 1\r\n-1 2\r\n1 2\r\n", "output": "12.566370614359172464\r\n"}, {"input": "4 1 -1\r\n0 0\r\n1 2\r\n2 0\r\n1 1\r\n", "output": "21.991148575128551812\r\n"}, {"input": "3 0 0\r\n-1 1\r\n0 3\r\n1 1\r\n", "output": "25.132741228718344928\r\n"}, {"input": "3 -4 2\r\n-3 2\r\n5 -5\r\n5 3\r\n", "output": "405.26545231308331191\r\n"}, {"input": "3 -84 8\r\n-83 8\r\n21 -62\r\n3 53\r\n", "output": "50026.721415763865583\r\n"}, {"input": "6 -94 -51\r\n-93 -51\r\n48 -25\r\n61 27\r\n73 76\r\n-10 87\r\n-48 38\r\n", "output": "138283.48383306192359\r\n"}, {"input": "5 -94 52\r\n-93 52\r\n-78 -56\r\n-54 -81\r\n56 -87\r\n97 85\r\n", "output": "131381.40477312514811\r\n"}, {"input": "10 -100 90\r\n-99 90\r\n-98 -12\r\n-72 -87\r\n7 -84\r\n86 -79\r\n96 -2\r\n100 36\r\n99 59\r\n27 83\r\n-14 93\r\n", "output": "198410.42563011697403\r\n"}, {"input": "11 -97 -15\r\n-96 -15\r\n-83 -84\r\n-61 -97\r\n64 -92\r\n81 -82\r\n100 -63\r\n86 80\r\n58 95\r\n15 99\r\n-48 83\r\n-91 49\r\n", "output": "133558.52848206287476\r\n"}, {"input": "10 -500 420\r\n-499 420\r\n-489 -173\r\n-455 -480\r\n160 -464\r\n374 -437\r\n452 -352\r\n481 -281\r\n465 75\r\n326 392\r\n-398 468\r\n", "output": "4719573.802783449531\r\n"}, {"input": "10 -498 -161\r\n-497 -161\r\n-427 -458\r\n-325 -475\r\n349 -500\r\n441 -220\r\n473 28\r\n475 62\r\n468 498\r\n-444 492\r\n-465 264\r\n", "output": "4295926.8918542123392\r\n"}, {"input": "5 -1 -1\r\n0 0\r\n8 5\r\n10 7\r\n7 5\r\n2 5\r\n", "output": "574.91145560693214023\r\n"}, {"input": "5 -1 -1\r\n0 0\r\n20 3\r\n26 17\r\n23 21\r\n98 96\r\n", "output": "60343.711690152746165\r\n"}, {"input": "10 -1 -1\r\n0 0\r\n94 7\r\n100 52\r\n87 48\r\n37 26\r\n74 61\r\n59 57\r\n87 90\r\n52 90\r\n26 73\r\n", "output": "50337.739088469255101\r\n"}, {"input": "10 -1 -1\r\n0 0\r\n78 22\r\n53 24\r\n78 50\r\n46 39\r\n45 56\r\n21 46\r\n2 7\r\n24 97\r\n5 59\r\n", "output": "32129.068068262814194\r\n"}, {"input": "49 -1 -1\r\n0 0\r\n95 2\r\n47 1\r\n42 1\r\n93 7\r\n56 6\r\n47 7\r\n63 13\r\n98 24\r\n94 27\r\n90 28\r\n86 28\r\n17 6\r\n64 24\r\n42 19\r\n66 35\r\n63 35\r\n98 60\r\n75 48\r\n28 18\r\n71 46\r\n69 46\r\n99 68\r\n64 47\r\n56 43\r\n72 58\r\n35 29\r\n82 81\r\n68 69\r\n79 84\r\n72 77\r\n79 86\r\n54 59\r\n35 39\r\n20 23\r\n73 86\r\n80 97\r\n79 100\r\n69 99\r\n29 45\r\n26 63\r\n23 56\r\n12 33\r\n13 39\r\n25 85\r\n27 96\r\n6 23\r\n4 47\r\n1 60\r\n", "output": "52147.296456936975932\r\n"}, {"input": "49 -1 -1\r\n0 0\r\n69 2\r\n74 7\r\n62 10\r\n64 15\r\n93 22\r\n78 22\r\n56 17\r\n86 29\r\n24 9\r\n91 43\r\n8 4\r\n90 50\r\n99 57\r\n39 23\r\n81 50\r\n91 58\r\n67 46\r\n95 66\r\n52 39\r\n91 69\r\n69 54\r\n93 84\r\n93 98\r\n70 80\r\n85 98\r\n30 39\r\n55 79\r\n41 59\r\n50 72\r\n57 88\r\n58 92\r\n58 94\r\n37 63\r\n43 87\r\n30 63\r\n19 40\r\n38 81\r\n40 86\r\n38 100\r\n2 6\r\n30 100\r\n23 89\r\n16 62\r\n11 49\r\n12 64\r\n9 52\r\n5 62\r\n1 88\r\n", "output": "58543.579099645794717\r\n"}, {"input": "27 -999899 136015\r\n-999898 136015\r\n-999877 -297518\r\n-999832 -906080\r\n-999320 -977222\r\n-998896 -995106\r\n-962959 -999497\r\n-747200 -999814\r\n417261 -999929\r\n844204 -999911\r\n959527 -999826\r\n998944 -999180\r\n999413 -989979\r\n999556 -943026\r\n999871 -774660\r\n999993 -261535\r\n999963 938964\r\n998309 991397\r\n989894 997814\r\n988982 998459\r\n987145 999235\r\n972224 999741\r\n603140 999994\r\n-812452 999962\r\n-980920 999788\r\n-996671 987674\r\n-999472 977919\r\n-999808 639816\r\n", "output": "16600304470662.964855\r\n"}, {"input": "19 -995486 -247212\r\n-995485 -247212\r\n-995004 -492984\r\n-993898 -887860\r\n-938506 -961227\r\n-688481 -971489\r\n178005 -999731\r\n541526 -999819\r\n799710 -988908\r\n905862 -967693\r\n987335 -887414\r\n983567 824667\r\n973128 892799\r\n914017 960546\r\n669333 986330\r\n-441349 986800\r\n-813005 986924\r\n-980671 973524\r\n-988356 849906\r\n-995289 404864\r\n", "output": "16257949833603.158278\r\n"}, {"input": "15 -994057 554462\r\n-994056 554462\r\n-975707 -994167\r\n-711551 -996810\r\n13909 -997149\r\n809315 -993832\r\n980809 -984682\r\n996788 -303578\r\n993267 173570\r\n978439 877361\r\n898589 957311\r\n725925 992298\r\n-57849 999563\r\n-335564 997722\r\n-989580 990530\r\n-993875 973633\r\n", "output": "19694832748836.689348\r\n"}, {"input": "23 -999840 738880\r\n-999839 738880\r\n-998291 -847192\r\n-995443 -982237\r\n-906770 -996569\r\n360950 -999295\r\n800714 -998808\r\n985348 -995579\r\n990091 -928438\r\n996690 -817256\r\n998844 -736918\r\n998377 674949\r\n998008 862436\r\n993320 971157\r\n978831 979400\r\n853341 986660\r\n802107 989497\r\n513719 996183\r\n140983 998592\r\n-158810 999459\r\n-677966 999174\r\n-949021 981608\r\n-982951 976421\r\n-993452 962292\r\n", "output": "21831930831113.094931\r\n"}, {"input": "20 -999719 -377746\r\n-999718 -377746\r\n-997432 -940486\r\n-982215 -950088\r\n-903861 -997725\r\n-127953 -999833\r\n846620 -999745\r\n920305 -992903\r\n947027 -986746\r\n991646 -959876\r\n998264 -944885\r\n999301 870671\r\n994737 985066\r\n640032 998502\r\n-87871 999984\r\n-450900 999751\r\n-910919 999086\r\n-971174 995672\r\n-995406 975642\r\n-998685 946525\r\n-999684 673031\r\n", "output": "18331542740428.216614\r\n"}, {"input": "26 -999922 -339832\r\n-999921 -339832\r\n-999666 -565163\r\n-998004 -942175\r\n-992140 -985584\r\n-965753 -998838\r\n-961074 -999911\r\n120315 -999489\r\n308422 -999258\r\n696427 -997199\r\n724780 -996955\r\n995651 -985203\r\n997267 -975745\r\n999745 -941705\r\n999897 -770648\r\n999841 -211766\r\n999436 865172\r\n999016 992181\r\n980442 997414\r\n799072 998987\r\n348022 999183\r\n-178144 999329\r\n-729638 998617\r\n-953068 997984\r\n-991172 990824\r\n-997976 939889\r\n-999483 581509\r\n", "output": "18127026556380.411608\r\n"}, {"input": "22 -999930 -362070\r\n-999929 -362070\r\n-994861 -919993\r\n-989365 -946982\r\n-964007 -997050\r\n-418950 -998064\r\n351746 -998882\r\n830925 -996765\r\n867755 -996352\r\n964401 -992258\r\n996299 -964402\r\n997257 -930788\r\n999795 -616866\r\n999689 327482\r\n997898 996234\r\n923521 997809\r\n631104 998389\r\n-261788 999672\r\n-609744 999782\r\n-694662 999001\r\n-941227 993687\r\n-997105 992436\r\n-999550 895326\r\n", "output": "18335297542813.80731\r\n"}, {"input": "29 -999961 689169\r\n-999960 689169\r\n-999927 -938525\r\n-999735 -989464\r\n-993714 -997911\r\n-870186 -999686\r\n-796253 -999950\r\n-139940 -999968\r\n969552 -999972\r\n985446 -999398\r\n992690 -997295\r\n999706 -973137\r\n999898 -848630\r\n999997 -192297\r\n999969 773408\r\n999495 960350\r\n999143 981671\r\n998324 993987\r\n997640 998103\r\n986157 998977\r\n966840 999418\r\n670113 999809\r\n477888 999856\r\n129160 999900\r\n-373564 999947\r\n-797543 999976\r\n-860769 999903\r\n-995496 999355\r\n-998771 984570\r\n-999768 927157\r\n", "output": "21409384775316.574772\r\n"}, {"input": "3 -3 3\r\n-3 2\r\n5 -5\r\n5 3\r\n", "output": "399.0305992005743379\r\n"}, {"input": "3 -9 7\r\n-9 6\r\n3 -6\r\n4 2\r\n", "output": "980.17690792001545219\r\n"}, {"input": "5 -9 8\r\n-9 7\r\n-6 -1\r\n-3 -6\r\n1 -3\r\n10 8\r\n", "output": "1130.9820337250702449\r\n"}, {"input": "6 -6 -1\r\n-6 -2\r\n0 -7\r\n8 -9\r\n9 -1\r\n5 10\r\n-5 0\r\n", "output": "816.18577140262825159\r\n"}, {"input": "10 -99 91\r\n-99 90\r\n-98 -12\r\n-72 -87\r\n7 -84\r\n86 -79\r\n96 -2\r\n100 36\r\n99 59\r\n27 83\r\n-14 93\r\n", "output": "198309.89857373595223\r\n"}, {"input": "11 -96 -14\r\n-96 -15\r\n-83 -84\r\n-61 -97\r\n64 -92\r\n81 -82\r\n100 -63\r\n86 80\r\n58 95\r\n15 99\r\n-48 83\r\n-91 49\r\n", "output": "131821.20868619133483\r\n"}, {"input": "13 -98 25\r\n-98 24\r\n-96 10\r\n-80 -71\r\n-71 -78\r\n-31 -99\r\n82 -98\r\n92 -39\r\n94 -2\r\n94 40\r\n90 80\r\n50 96\r\n-41 97\r\n-86 80\r\n", "output": "149316.61930888936332\r\n"}, {"input": "17 -99 -53\r\n-99 -54\r\n-97 -71\r\n-67 -99\r\n-61 -99\r\n56 -98\r\n82 -85\r\n95 -47\r\n90 -2\r\n82 30\r\n63 87\r\n54 95\r\n-12 99\r\n-38 99\r\n-87 89\r\n-90 87\r\n-95 67\r\n-96 49\r\n", "output": "144023.17094830233827\r\n"}, {"input": "19 -995485 -247211\r\n-995485 -247212\r\n-995004 -492984\r\n-993898 -887860\r\n-938506 -961227\r\n-688481 -971489\r\n178005 -999731\r\n541526 -999819\r\n799710 -988908\r\n905862 -967693\r\n987335 -887414\r\n983567 824667\r\n973128 892799\r\n914017 960546\r\n669333 986330\r\n-441349 986800\r\n-813005 986924\r\n-980671 973524\r\n-988356 849906\r\n-995289 404864\r\n", "output": "16257930301545.657524\r\n"}, {"input": "15 -994056 554463\r\n-994056 554462\r\n-975707 -994167\r\n-711551 -996810\r\n13909 -997149\r\n809315 -993832\r\n980809 -984682\r\n996788 -303578\r\n993267 173570\r\n978439 877361\r\n898589 957311\r\n725925 992298\r\n-57849 999563\r\n-335564 997722\r\n-989580 990530\r\n-993875 973633\r\n", "output": "19694830011124.045712\r\n"}, {"input": "23 -999839 738881\r\n-999839 738880\r\n-998291 -847192\r\n-995443 -982237\r\n-906770 -996569\r\n360950 -999295\r\n800714 -998808\r\n985348 -995579\r\n990091 -928438\r\n996690 -817256\r\n998844 -736918\r\n998377 674949\r\n998008 862436\r\n993320 971157\r\n978831 979400\r\n853341 986660\r\n802107 989497\r\n513719 996183\r\n140983 998592\r\n-158810 999459\r\n-677966 999174\r\n-949021 981608\r\n-982951 976421\r\n-993452 962292\r\n", "output": "21831929255745.74826\r\n"}, {"input": "20 -999718 -377745\r\n-999718 -377746\r\n-997432 -940486\r\n-982215 -950088\r\n-903861 -997725\r\n-127953 -999833\r\n846620 -999745\r\n920305 -992903\r\n947027 -986746\r\n991646 -959876\r\n998264 -944885\r\n999301 870671\r\n994737 985066\r\n640032 998502\r\n-87871 999984\r\n-450900 999751\r\n-910919 999086\r\n-971174 995672\r\n-995406 975642\r\n-998685 946525\r\n-999684 673031\r\n", "output": "18331521646100.671528\r\n"}, {"input": "26 -999921 -339831\r\n-999921 -339832\r\n-999666 -565163\r\n-998004 -942175\r\n-992140 -985584\r\n-965753 -998838\r\n-961074 -999911\r\n120315 -999489\r\n308422 -999258\r\n696427 -997199\r\n724780 -996955\r\n995651 -985203\r\n997267 -975745\r\n999745 -941705\r\n999897 -770648\r\n999841 -211766\r\n999436 865172\r\n999016 992181\r\n980442 997414\r\n799072 998987\r\n348022 999183\r\n-178144 999329\r\n-729638 998617\r\n-953068 997984\r\n-991172 990824\r\n-997976 939889\r\n-999483 581509\r\n", "output": "18127005627407.454252\r\n"}, {"input": "22 -999929 -362069\r\n-999929 -362070\r\n-994861 -919993\r\n-989365 -946982\r\n-964007 -997050\r\n-418950 -998064\r\n351746 -998882\r\n830925 -996765\r\n867755 -996352\r\n964401 -992258\r\n996299 -964402\r\n997257 -930788\r\n999795 -616866\r\n999689 327482\r\n997898 996234\r\n923521 997809\r\n631104 998389\r\n-261788 999672\r\n-609744 999782\r\n-694662 999001\r\n-941227 993687\r\n-997105 992436\r\n-999550 895326\r\n", "output": "18335276455623.960732\r\n"}, {"input": "27 -999898 136016\r\n-999898 136015\r\n-999877 -297518\r\n-999832 -906080\r\n-999320 -977222\r\n-998896 -995106\r\n-962959 -999497\r\n-747200 -999814\r\n417261 -999929\r\n844204 -999911\r\n959527 -999826\r\n998944 -999180\r\n999413 -989979\r\n999556 -943026\r\n999871 -774660\r\n999993 -261535\r\n999963 938964\r\n998309 991397\r\n989894 997814\r\n988982 998459\r\n987145 999235\r\n972224 999741\r\n603140 999994\r\n-812452 999962\r\n-980920 999788\r\n-996671 987674\r\n-999472 977919\r\n-999808 639816\r\n", "output": "16600299044211.965457\r\n"}, {"input": "13 -1000000 -1000000\r\n-1000000 0\r\n0 -1000000\r\n999417 840\r\n999781 33421\r\n999994 131490\r\n999993 998865\r\n962080 999911\r\n629402 999973\r\n378696 999988\r\n53978 999788\r\n25311 999558\r\n6082 999282\r\n1565 998489\r\n", "output": "23547598153913.984406\r\n"}, {"input": "16 -1000000 -1000000\r\n-1000000 0\r\n0 -1000000\r\n999744 572\r\n999931 96510\r\n1000000 254372\r\n999939 748173\r\n999894 953785\r\n999683 986098\r\n999051 999815\r\n980586 999969\r\n637250 999988\r\n118331 999983\r\n27254 999966\r\n9197 999405\r\n4810 997733\r\n1661 995339\r\n", "output": "23547697574489.259052\r\n"}, {"input": "4 0 0\r\n1 -1\r\n1 3\r\n3 3\r\n3 -1\r\n", "output": "53.407075111026482965\r\n"}, {"input": "3 0 0\r\n-10 1\r\n0 2\r\n1 1\r\n", "output": "314.1592653589793116\r\n"}, {"input": "3 0 0\r\n-1 1\r\n4 1\r\n0 2\r\n", "output": "50.265482457436689849\r\n"}]
| false |
stdio
|
import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(output_path, 'r') as f:
ref_line = f.readline().strip()
try:
b = float(ref_line)
except:
print(0)
return
with open(submission_path, 'r') as f:
sub_line = f.readline().strip()
try:
a = float(sub_line)
except:
print(0)
return
denominator = max(1.0, b)
absolute_error = abs(a - b)
if absolute_error <= 1e-6 * denominator:
print(1)
else:
print(0)
if __name__ == "__main__":
main()
| true |
55/C
|
55
|
C
|
Python 3
|
TESTS
| 5 | 122 | 0 |
15486214
|
n, m, k = map(int, input().split())
win = False
for i in range(k):
r, c = map(int, input().split())
dr = min(r - 1, n - r)
dc = min(c - 1, m - c)
if dr <= 2 or dc <= 2:
win = True
print("YES" if win else "NO")
| 75 | 92 | 0 |
155232117
|
n, m, k = map(int, input().split())
flag = False
while k > 0:
k -= 1
x, y = map(int, input().split())
d = min(x, n - x + 1, y, m - y + 1)
if d <= 5:
flag = True
print("YES" if flag else "NO")
|
Codeforces Beta Round 51
|
CF
| 2,011 | 2 | 256 |
Pie or die
|
Volodya and Vlad play the following game. There are k pies at the cells of n × m board. Each turn Volodya moves one pie to the neighbouring (by side) cell. If the pie lies at the border of the board then Volodya can move it outside the board, get the pie and win. After Volodya's move, Vlad bans some edge at the border of the board of length 1 (between two knots of the board) so that Volodya is not able to move the pie outside the board through this edge anymore. The question is: will Volodya win this game? We suppose both players follow the optimal strategy.
|
First line contains 3 integers, separated by space: 1 ≤ n, m ≤ 100 — dimensions of the board and 0 ≤ k ≤ 100 — the number of pies. Each of the next k lines contains 2 integers, separated by space: 1 ≤ x ≤ n, 1 ≤ y ≤ m — coordinates of the corresponding pie. There could be more than one pie at a cell.
|
Output only one word: "YES" — if Volodya wins, "NO" — otherwise.
| null | null |
[{"input": "2 2 1\n1 2", "output": "YES"}, {"input": "3 4 0", "output": "NO"}, {"input": "100 50 2\n50 25\n50 25", "output": "NO"}]
| 1,900 |
["games"]
| 75 |
[{"input": "2 2 1\r\n1 2\r\n", "output": "YES\r\n"}, {"input": "3 4 0\r\n", "output": "NO\r\n"}, {"input": "100 50 2\r\n50 25\r\n50 25\r\n", "output": "NO\r\n"}, {"input": "20 20 4\r\n10 10\r\n10 10\r\n10 10\r\n10 10\r\n", "output": "NO\r\n"}, {"input": "15 15 1\r\n8 8\r\n", "output": "NO\r\n"}, {"input": "8 8 2\r\n4 4\r\n5 5\r\n", "output": "YES\r\n"}, {"input": "100 100 2\r\n50 96\r\n51 96\r\n", "output": "YES\r\n"}, {"input": "100 100 2\r\n50 95\r\n51 95\r\n", "output": "NO\r\n"}, {"input": "20 20 1\r\n16 10\r\n", "output": "YES\r\n"}, {"input": "20 20 4\r\n15 9\r\n15 10\r\n15 11\r\n15 12\r\n", "output": "NO\r\n"}, {"input": "11 11 1\r\n6 6\r\n", "output": "NO\r\n"}, {"input": "11 11 1\r\n6 5\r\n", "output": "YES\r\n"}, {"input": "35 13 20\r\n13 8\r\n19 8\r\n24 7\r\n20 6\r\n23 7\r\n23 6\r\n30 7\r\n29 7\r\n7 7\r\n6 8\r\n9 8\r\n29 6\r\n20 7\r\n25 6\r\n19 6\r\n23 8\r\n26 6\r\n12 6\r\n15 7\r\n6 8\r\n", "output": "NO\r\n"}, {"input": "50 17 27\r\n17 8\r\n19 6\r\n25 8\r\n30 10\r\n22 10\r\n30 9\r\n25 8\r\n27 6\r\n19 7\r\n29 11\r\n39 8\r\n31 8\r\n39 8\r\n40 7\r\n11 8\r\n30 11\r\n32 8\r\n31 11\r\n36 12\r\n10 11\r\n32 8\r\n8 7\r\n7 12\r\n17 11\r\n27 7\r\n8 8\r\n23 12\r\n", "output": "NO\r\n"}, {"input": "24 29 22\r\n16 6\r\n14 22\r\n7 15\r\n11 17\r\n12 22\r\n10 13\r\n12 22\r\n12 13\r\n6 16\r\n12 21\r\n11 11\r\n9 13\r\n18 22\r\n7 20\r\n13 6\r\n6 14\r\n17 10\r\n9 13\r\n7 23\r\n14 11\r\n7 22\r\n8 12\r\n", "output": "NO\r\n"}, {"input": "32 45 3\r\n12 30\r\n27 9\r\n14 27\r\n", "output": "NO\r\n"}, {"input": "96 95 31\r\n14 23\r\n70 47\r\n11 77\r\n53 66\r\n63 87\r\n3 14\r\n57 44\r\n65 69\r\n80 74\r\n49 6\r\n57 86\r\n75 8\r\n2 32\r\n75 21\r\n14 51\r\n56 46\r\n77 6\r\n17 89\r\n87 3\r\n21 18\r\n70 67\r\n47 64\r\n13 47\r\n61 33\r\n56 30\r\n28 2\r\n65 18\r\n17 90\r\n44 77\r\n54 26\r\n32 70\r\n", "output": "YES\r\n"}, {"input": "15 96 22\r\n4 7\r\n7 40\r\n13 30\r\n8 53\r\n6 78\r\n5 9\r\n15 35\r\n3 13\r\n5 31\r\n2 9\r\n13 50\r\n11 17\r\n4 2\r\n10 91\r\n11 74\r\n14 49\r\n8 30\r\n10 66\r\n12 44\r\n6 19\r\n9 62\r\n15 50\r\n", "output": "YES\r\n"}, {"input": "61 96 15\r\n27 36\r\n19 64\r\n27 53\r\n59 63\r\n48 56\r\n55 30\r\n10 23\r\n6 79\r\n32 74\r\n7 51\r\n29 65\r\n60 16\r\n43 74\r\n40 80\r\n14 31\r\n", "output": "YES\r\n"}, {"input": "36 89 27\r\n21 66\r\n3 60\r\n11 32\r\n10 81\r\n30 31\r\n27 62\r\n11 81\r\n24 41\r\n30 6\r\n13 45\r\n34 86\r\n26 46\r\n9 62\r\n8 86\r\n17 56\r\n4 86\r\n25 36\r\n23 72\r\n18 55\r\n18 87\r\n22 67\r\n18 12\r\n19 75\r\n21 60\r\n16 49\r\n33 63\r\n26 12\r\n", "output": "YES\r\n"}, {"input": "11 38 21\r\n2 21\r\n2 28\r\n7 19\r\n9 18\r\n7 25\r\n8 4\r\n3 23\r\n2 32\r\n5 34\r\n10 36\r\n8 21\r\n4 6\r\n6 6\r\n4 35\r\n8 34\r\n10 18\r\n11 4\r\n10 2\r\n10 13\r\n4 37\r\n2 29\r\n", "output": "YES\r\n"}, {"input": "30 84 35\r\n20 60\r\n23 21\r\n14 24\r\n24 72\r\n13 76\r\n25 35\r\n11 64\r\n15 57\r\n9 55\r\n14 66\r\n10 24\r\n13 68\r\n11 8\r\n19 43\r\n11 14\r\n16 26\r\n11 22\r\n10 26\r\n15 66\r\n17 65\r\n21 34\r\n7 61\r\n24 64\r\n18 16\r\n22 18\r\n12 9\r\n10 40\r\n8 24\r\n16 52\r\n10 9\r\n7 17\r\n21 78\r\n18 75\r\n10 45\r\n16 29\r\n", "output": "NO\r\n"}, {"input": "66 94 26\r\n11 75\r\n46 72\r\n55 74\r\n34 10\r\n33 84\r\n25 11\r\n13 23\r\n27 73\r\n45 22\r\n54 34\r\n53 63\r\n28 8\r\n57 46\r\n26 78\r\n52 46\r\n32 38\r\n22 55\r\n17 71\r\n56 18\r\n9 60\r\n31 54\r\n6 84\r\n59 57\r\n60 81\r\n51 49\r\n41 77\r\n", "output": "NO\r\n"}, {"input": "68 100 18\r\n17 85\r\n10 77\r\n59 55\r\n29 46\r\n25 74\r\n55 11\r\n37 16\r\n57 61\r\n26 11\r\n11 88\r\n19 18\r\n28 38\r\n32 12\r\n36 49\r\n32 6\r\n57 45\r\n30 6\r\n59 95\r\n", "output": "NO\r\n"}, {"input": "28 61 4\r\n12 18\r\n21 31\r\n14 52\r\n6 36\r\n", "output": "NO\r\n"}, {"input": "11 73 1\r\n4 67\r\n", "output": "YES\r\n"}, {"input": "11 79 0\r\n", "output": "NO\r\n"}, {"input": "11 23 1\r\n11 9\r\n", "output": "YES\r\n"}, {"input": "25 11 0\r\n", "output": "NO\r\n"}, {"input": "39 11 1\r\n18 3\r\n", "output": "YES\r\n"}, {"input": "69 11 0\r\n", "output": "NO\r\n"}, {"input": "13 19 1\r\n6 10\r\n", "output": "NO\r\n"}, {"input": "14 17 0\r\n", "output": "NO\r\n"}, {"input": "20 19 5\r\n7 14\r\n14 12\r\n7 12\r\n15 9\r\n12 6\r\n", "output": "NO\r\n"}, {"input": "17 15 3\r\n10 7\r\n12 6\r\n8 6\r\n", "output": "NO\r\n"}, {"input": "14 17 4\r\n9 9\r\n8 7\r\n8 12\r\n7 9\r\n", "output": "NO\r\n"}, {"input": "15 11 0\r\n", "output": "NO\r\n"}, {"input": "14 16 4\r\n6 11\r\n6 8\r\n8 6\r\n6 7\r\n", "output": "NO\r\n"}, {"input": "16 16 0\r\n", "output": "NO\r\n"}, {"input": "19 20 2\r\n10 14\r\n8 11\r\n", "output": "NO\r\n"}, {"input": "13 15 1\r\n7 10\r\n", "output": "NO\r\n"}, {"input": "11 100 4\r\n6 10\r\n6 20\r\n6 30\r\n6 80\r\n", "output": "NO\r\n"}, {"input": "100 11 2\r\n40 6\r\n70 6\r\n", "output": "NO\r\n"}, {"input": "100 11 5\r\n20 6\r\n30 6\r\n43 7\r\n78 6\r\n89 6\r\n", "output": "YES\r\n"}, {"input": "20 20 5\r\n10 6\r\n6 8\r\n16 11\r\n11 11\r\n7 15\r\n", "output": "YES\r\n"}, {"input": "30 30 5\r\n7 15\r\n24 11\r\n15 15\r\n8 24\r\n9 6\r\n", "output": "NO\r\n"}]
| false |
stdio
| null | true |
841/B
|
841
|
B
|
Python 3
|
TESTS
| 51 | 1,045 | 76,492,800 |
146556117
|
n=int(input())
l=list(map(int,input().split()))
sum=l[0]
i=1
cnt=0
fl=''
while i<n:
while not sum%2!=0 and i<n:
sum+=l[i]
i+=1
sum=0
if i<n:
fl='s'
while not sum%2==0 and i<n:
sum+=l[i]
i+=1
sum=0
if i<n:
fl='f'
if fl=='':
print("Second")
else:
if fl=='f':
print("First")
else:
print("Second")
| 88 | 280 | 84,992,000 |
174428621
|
n = int(input())
a = (map(int,input().split()))
for i in a:
if i%2==1:
print('First')
exit()
print('Second')
|
Codeforces Round 429 (Div. 2)
|
CF
| 2,017 | 2 | 256 |
Godsend
|
Leha somehow found an array consisting of n integers. Looking at it, he came up with a task. Two players play the game on the array. Players move one by one. The first player can choose for his move a subsegment of non-zero length with an odd sum of numbers and remove it from the array, after that the remaining parts are glued together into one array and the game continues. The second player can choose a subsegment of non-zero length with an even sum and remove it. Loses the one who can not make a move. Who will win if both play optimally?
|
First line of input data contains single integer n (1 ≤ n ≤ 106) — length of the array.
Next line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109).
|
Output answer in single line. "First", if first player wins, and "Second" otherwise (without quotes).
| null |
In first sample first player remove whole array in one move and win.
In second sample first player can't make a move and lose.
|
[{"input": "4\n1 3 2 3", "output": "First"}, {"input": "2\n2 2", "output": "Second"}]
| 1,100 |
["games", "math"]
| 88 |
[{"input": "4\r\n1 3 2 3\r\n", "output": "First\r\n"}, {"input": "2\r\n2 2\r\n", "output": "Second\r\n"}, {"input": "4\r\n2 4 6 8\r\n", "output": "Second\r\n"}, {"input": "5\r\n1 1 1 1 1\r\n", "output": "First\r\n"}, {"input": "4\r\n720074544 345031254 849487632 80870826\r\n", "output": "Second\r\n"}, {"input": "1\r\n0\r\n", "output": "Second\r\n"}, {"input": "1\r\n999999999\r\n", "output": "First\r\n"}, {"input": "2\r\n1 999999999\r\n", "output": "First\r\n"}, {"input": "4\r\n3 3 4 4\r\n", "output": "First\r\n"}, {"input": "2\r\n1 2\r\n", "output": "First\r\n"}, {"input": "8\r\n2 2 2 1 1 2 2 2\r\n", "output": "First\r\n"}, {"input": "5\r\n3 3 2 2 2\r\n", "output": "First\r\n"}, {"input": "4\r\n0 1 1 0\r\n", "output": "First\r\n"}, {"input": "3\r\n1 2 2\r\n", "output": "First\r\n"}, {"input": "6\r\n2 2 1 1 4 2\r\n", "output": "First\r\n"}, {"input": "8\r\n2 2 2 3 3 2 2 2\r\n", "output": "First\r\n"}, {"input": "4\r\n2 3 3 4\r\n", "output": "First\r\n"}, {"input": "10\r\n2 2 2 2 3 1 2 2 2 2\r\n", "output": "First\r\n"}, {"input": "6\r\n2 2 1 1 2 2\r\n", "output": "First\r\n"}, {"input": "3\r\n1 1 2\r\n", "output": "First\r\n"}, {"input": "6\r\n2 4 3 3 4 6\r\n", "output": "First\r\n"}, {"input": "6\r\n4 4 3 3 4 4\r\n", "output": "First\r\n"}, {"input": "4\r\n1 1 2 2\r\n", "output": "First\r\n"}, {"input": "4\r\n1 3 5 7\r\n", "output": "First\r\n"}, {"input": "4\r\n2 1 1 2\r\n", "output": "First\r\n"}, {"input": "4\r\n1 3 3 2\r\n", "output": "First\r\n"}, {"input": "5\r\n3 2 2 2 2\r\n", "output": "First\r\n"}, {"input": "3\r\n2 1 1\r\n", "output": "First\r\n"}, {"input": "4\r\n1000000000 1000000000 1000000000 99999999\r\n", "output": "First\r\n"}, {"input": "4\r\n2 2 1 1\r\n", "output": "First\r\n"}, {"input": "5\r\n2 3 2 3 2\r\n", "output": "First\r\n"}, {"input": "1\r\n1\r\n", "output": "First\r\n"}, {"input": "4\r\n1000000000 1000000000 1000000000 1\r\n", "output": "First\r\n"}, {"input": "5\r\n2 2 2 1 1\r\n", "output": "First\r\n"}, {"input": "6\r\n2 1 1 1 1 2\r\n", "output": "First\r\n"}, {"input": "6\r\n1 2 2 2 2 1\r\n", "output": "First\r\n"}, {"input": "11\r\n2 2 2 2 2 1 2 2 2 2 2\r\n", "output": "First\r\n"}, {"input": "5\r\n1 3 2 2 2\r\n", "output": "First\r\n"}, {"input": "3\r\n2 3 2\r\n", "output": "First\r\n"}, {"input": "2\r\n1 1\r\n", "output": "First\r\n"}, {"input": "5\r\n4 4 4 3 3\r\n", "output": "First\r\n"}, {"input": "5\r\n3 3 4 4 4\r\n", "output": "First\r\n"}, {"input": "1\r\n2\r\n", "output": "Second\r\n"}]
| false |
stdio
| null | true |
33/C
|
33
|
C
|
Python 3
|
TESTS
| 35 | 310 | 6,451,200 |
158129345
|
n = int(input())
try:
A = list(map(int,input().split()))
l = 0;r = n - 1
res = 0
min_ = 0
dp = [0]*n
dp[0] = A[0]
for i in range(1,n):
dp[i] = max(dp[i-1] + A[i],A[i])
res = max(res,dp[i])
print(res + res - sum(A))
except:
print('输入错误!')
| 89 | 248 | 17,715,200 |
218027178
|
n = int(input())
a = [int(i) for i in input().split()]
prefs = [0]
sufs = [0]
min_prefs = [0]
min_sufs = [0]
s = sum(a)
for i in range(n):
min_prefs.append(min(min_prefs[-1], prefs[-1] + a[i]))
prefs.append(prefs[-1] + a[i])
min_sufs.append(min(min_sufs[-1], a[n - 1 - i] + sufs[-1]))
sufs.append(a[n - 1 - i] + sufs[-1])
sufs.reverse()
min_sufs.reverse()
ans = s
for i in range(n + 1):
ans = max(ans, s - 2 * (min_sufs[i] + min_prefs[i]))
print(ans)
|
Codeforces Beta Round 33 (Codeforces format)
|
CF
| 2,010 | 2 | 256 |
Wonderful Randomized Sum
|
Learn, learn and learn again — Valera has to do this every day. He is studying at mathematical school, where math is the main discipline. The mathematics teacher loves her discipline very much and tries to cultivate this love in children. That's why she always gives her students large and difficult homework. Despite that Valera is one of the best students, he failed to manage with the new homework. That's why he asks for your help. He has the following task. A sequence of n numbers is given. A prefix of a sequence is the part of the sequence (possibly empty), taken from the start of the sequence. A suffix of a sequence is the part of the sequence (possibly empty), taken from the end of the sequence. It is allowed to sequentially make two operations with the sequence. The first operation is to take some prefix of the sequence and multiply all numbers in this prefix by - 1. The second operation is to take some suffix and multiply all numbers in it by - 1. The chosen prefix and suffix may intersect. What is the maximum total sum of the sequence that can be obtained by applying the described operations?
|
The first line contains integer n (1 ≤ n ≤ 105) — amount of elements in the sequence. The second line contains n integers ai ( - 104 ≤ ai ≤ 104) — the sequence itself.
|
The first and the only line of the output should contain the answer to the problem.
| null | null |
[{"input": "3\n-1 -2 -3", "output": "6"}, {"input": "5\n-4 2 0 5 0", "output": "11"}, {"input": "5\n-1 10 -5 10 -2", "output": "18"}]
| 1,800 |
["greedy"]
| 89 |
[{"input": "3\r\n-1 -2 -3\r\n", "output": "6\r\n"}, {"input": "5\r\n-4 2 0 5 0\r\n", "output": "11\r\n"}, {"input": "5\r\n-1 10 -5 10 -2\r\n", "output": "18\r\n"}, {"input": "1\r\n-3\r\n", "output": "3\r\n"}, {"input": "4\r\n1 4 -5 -2\r\n", "output": "12\r\n"}, {"input": "7\r\n-17 6 5 0 1 4 -1\r\n", "output": "34\r\n"}, {"input": "3\r\n0 -2 3\r\n", "output": "5\r\n"}, {"input": "2\r\n0 3\r\n", "output": "3\r\n"}, {"input": "15\r\n14 0 -10 -5 0 19 -6 0 -11 -20 -18 -8 -3 19 -7\r\n", "output": "74\r\n"}, {"input": "15\r\n0 -35 32 24 0 27 10 0 -19 -38 30 -30 40 -3 22\r\n", "output": "130\r\n"}, {"input": "20\r\n0 2 3 1 0 3 -3 0 -1 0 2 -1 -1 3 0 0 1 -3 2 0\r\n", "output": "10\r\n"}, {"input": "100\r\n6 2 -3 6 -4 -6 -2 -1 -6 1 3 -4 -1 0 -3 1 -3 0 -2 -3 0 3 1 6 -5 0 4 -5 -5 -6 3 1 3 4 0 -1 3 -4 5 -1 -3 -2 -6 0 5 -6 -2 0 4 -4 -5 4 -2 0 -5 1 -5 0 5 -4 2 -3 -2 0 3 -6 3 2 -4 -3 5 5 1 -1 2 -6 6 0 2 -3 3 0 -1 -4 0 -6 0 0 -6 5 -4 1 6 -5 -1 -2 3 4 0 6\r\n", "output": "64\r\n"}, {"input": "30\r\n8 -1 3 -7 0 -1 9 3 0 0 3 -8 8 -8 9 -3 5 -9 -8 -10 4 -9 8 6 0 9 -6 1 5 -6\r\n", "output": "41\r\n"}, {"input": "1\r\n7500\r\n", "output": "7500\r\n"}, {"input": "2\r\n9944 -9293\r\n", "output": "19237\r\n"}, {"input": "3\r\n5 -5 7\r\n", "output": "7\r\n"}, {"input": "5\r\n-23 -11 -54 56 -40\r\n", "output": "184\r\n"}, {"input": "10\r\n-8 6 0 12 0 2 3 8 2 6\r\n", "output": "47\r\n"}, {"input": "8\r\n3 0 -5 -2 -4 0 -5 0\r\n", "output": "19\r\n"}, {"input": "16\r\n57 59 -27 24 28 -27 9 -90 3 -36 90 63 1 99 -46 50\r\n", "output": "257\r\n"}, {"input": "7\r\n2 -1 -2 -4 -3 0 -3\r\n", "output": "15\r\n"}, {"input": "8\r\n57 -82 -146 -13 -3 -115 55 -76\r\n", "output": "437\r\n"}, {"input": "6\r\n9721 6032 8572 9026 9563 7626\r\n", "output": "50540\r\n"}, {"input": "4\r\n26 9 -16 -24\r\n", "output": "75\r\n"}, {"input": "5\r\n-54 64 37 -71 -74\r\n", "output": "300\r\n"}, {"input": "100\r\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\r\n", "output": "0\r\n"}, {"input": "4\r\n-83 -87 42 -96\r\n", "output": "308\r\n"}, {"input": "8\r\n103 395 377 -205 -975 301 548 346\r\n", "output": "1500\r\n"}, {"input": "20\r\n18 1 10 0 14 17 -13 0 -20 -19 16 2 5 -2 4 9 1 16 12 4\r\n", "output": "75\r\n"}, {"input": "16\r\n-2 -11 -6 -2 -8 -2 0 3 -1 0 -5 2 -12 5 6 -9\r\n", "output": "64\r\n"}, {"input": "5\r\n81 26 21 28 88\r\n", "output": "244\r\n"}, {"input": "7\r\n2165 -8256 -9741 -9714 7347 5652 6199\r\n", "output": "44744\r\n"}, {"input": "8\r\n4609 9402 908 9322 5132 0 1962 1069\r\n", "output": "32404\r\n"}, {"input": "11\r\n100 233 -184 -200 -222 228 -385 -129 -126 -377 237\r\n", "output": "1491\r\n"}, {"input": "5\r\n-4 -4 -4 -4 -4\r\n", "output": "20\r\n"}, {"input": "5\r\n-7 17 2 -6 -1\r\n", "output": "33\r\n"}, {"input": "8\r\n-1 1 4 -5 -2 3 -10 3\r\n", "output": "17\r\n"}, {"input": "9\r\n1 2 -4 3 6 1 1 2 -8\r\n", "output": "22\r\n"}, {"input": "9\r\n1 1 2 -4 1 -4 2 1 1\r\n", "output": "7\r\n"}, {"input": "14\r\n1 1 1 1 -3 1 -5 -3 2 -3 1 1 1 1\r\n", "output": "11\r\n"}, {"input": "7\r\n-12 12 -12 13 -12 12 -12\r\n", "output": "37\r\n"}, {"input": "1\r\n2\r\n", "output": "2\r\n"}, {"input": "5\r\n-2 0 0 -4 1\r\n", "output": "7\r\n"}, {"input": "13\r\n-2 6 6 0 6 -17 6 5 0 1 4 -1 0\r\n", "output": "22\r\n"}]
| false |
stdio
| null | true |
55/C
|
55
|
C
|
Python 3
|
TESTS
| 5 | 125 | 102,400 |
3933221
|
n, m, k = [int(x) for x in input().split()]
canwin = False
for i in range(k):
x, y = [int(x) for x in input().split()]
canwin |= x <= 3 or n - x <= 2
canwin |= y <= 3 or m - y <= 2
print("YES" if canwin else "NO")
| 75 | 92 | 0 |
158335311
|
def main():
n, m, k = map(int, input().split())
min_ = 100
for j in range(k):
a, b = map(int, input().split())
c = min(a-1, b-1, n-a, m-b)
min_ = min(c, min_)
if min_ <= 4:
print("YES")
return
print("NO")
main()
#--------
#--------
#--------
#
#--- *- ---
#--- -* ---
#
#--------
#--------
#--------
|
Codeforces Beta Round 51
|
CF
| 2,011 | 2 | 256 |
Pie or die
|
Volodya and Vlad play the following game. There are k pies at the cells of n × m board. Each turn Volodya moves one pie to the neighbouring (by side) cell. If the pie lies at the border of the board then Volodya can move it outside the board, get the pie and win. After Volodya's move, Vlad bans some edge at the border of the board of length 1 (between two knots of the board) so that Volodya is not able to move the pie outside the board through this edge anymore. The question is: will Volodya win this game? We suppose both players follow the optimal strategy.
|
First line contains 3 integers, separated by space: 1 ≤ n, m ≤ 100 — dimensions of the board and 0 ≤ k ≤ 100 — the number of pies. Each of the next k lines contains 2 integers, separated by space: 1 ≤ x ≤ n, 1 ≤ y ≤ m — coordinates of the corresponding pie. There could be more than one pie at a cell.
|
Output only one word: "YES" — if Volodya wins, "NO" — otherwise.
| null | null |
[{"input": "2 2 1\n1 2", "output": "YES"}, {"input": "3 4 0", "output": "NO"}, {"input": "100 50 2\n50 25\n50 25", "output": "NO"}]
| 1,900 |
["games"]
| 75 |
[{"input": "2 2 1\r\n1 2\r\n", "output": "YES\r\n"}, {"input": "3 4 0\r\n", "output": "NO\r\n"}, {"input": "100 50 2\r\n50 25\r\n50 25\r\n", "output": "NO\r\n"}, {"input": "20 20 4\r\n10 10\r\n10 10\r\n10 10\r\n10 10\r\n", "output": "NO\r\n"}, {"input": "15 15 1\r\n8 8\r\n", "output": "NO\r\n"}, {"input": "8 8 2\r\n4 4\r\n5 5\r\n", "output": "YES\r\n"}, {"input": "100 100 2\r\n50 96\r\n51 96\r\n", "output": "YES\r\n"}, {"input": "100 100 2\r\n50 95\r\n51 95\r\n", "output": "NO\r\n"}, {"input": "20 20 1\r\n16 10\r\n", "output": "YES\r\n"}, {"input": "20 20 4\r\n15 9\r\n15 10\r\n15 11\r\n15 12\r\n", "output": "NO\r\n"}, {"input": "11 11 1\r\n6 6\r\n", "output": "NO\r\n"}, {"input": "11 11 1\r\n6 5\r\n", "output": "YES\r\n"}, {"input": "35 13 20\r\n13 8\r\n19 8\r\n24 7\r\n20 6\r\n23 7\r\n23 6\r\n30 7\r\n29 7\r\n7 7\r\n6 8\r\n9 8\r\n29 6\r\n20 7\r\n25 6\r\n19 6\r\n23 8\r\n26 6\r\n12 6\r\n15 7\r\n6 8\r\n", "output": "NO\r\n"}, {"input": "50 17 27\r\n17 8\r\n19 6\r\n25 8\r\n30 10\r\n22 10\r\n30 9\r\n25 8\r\n27 6\r\n19 7\r\n29 11\r\n39 8\r\n31 8\r\n39 8\r\n40 7\r\n11 8\r\n30 11\r\n32 8\r\n31 11\r\n36 12\r\n10 11\r\n32 8\r\n8 7\r\n7 12\r\n17 11\r\n27 7\r\n8 8\r\n23 12\r\n", "output": "NO\r\n"}, {"input": "24 29 22\r\n16 6\r\n14 22\r\n7 15\r\n11 17\r\n12 22\r\n10 13\r\n12 22\r\n12 13\r\n6 16\r\n12 21\r\n11 11\r\n9 13\r\n18 22\r\n7 20\r\n13 6\r\n6 14\r\n17 10\r\n9 13\r\n7 23\r\n14 11\r\n7 22\r\n8 12\r\n", "output": "NO\r\n"}, {"input": "32 45 3\r\n12 30\r\n27 9\r\n14 27\r\n", "output": "NO\r\n"}, {"input": "96 95 31\r\n14 23\r\n70 47\r\n11 77\r\n53 66\r\n63 87\r\n3 14\r\n57 44\r\n65 69\r\n80 74\r\n49 6\r\n57 86\r\n75 8\r\n2 32\r\n75 21\r\n14 51\r\n56 46\r\n77 6\r\n17 89\r\n87 3\r\n21 18\r\n70 67\r\n47 64\r\n13 47\r\n61 33\r\n56 30\r\n28 2\r\n65 18\r\n17 90\r\n44 77\r\n54 26\r\n32 70\r\n", "output": "YES\r\n"}, {"input": "15 96 22\r\n4 7\r\n7 40\r\n13 30\r\n8 53\r\n6 78\r\n5 9\r\n15 35\r\n3 13\r\n5 31\r\n2 9\r\n13 50\r\n11 17\r\n4 2\r\n10 91\r\n11 74\r\n14 49\r\n8 30\r\n10 66\r\n12 44\r\n6 19\r\n9 62\r\n15 50\r\n", "output": "YES\r\n"}, {"input": "61 96 15\r\n27 36\r\n19 64\r\n27 53\r\n59 63\r\n48 56\r\n55 30\r\n10 23\r\n6 79\r\n32 74\r\n7 51\r\n29 65\r\n60 16\r\n43 74\r\n40 80\r\n14 31\r\n", "output": "YES\r\n"}, {"input": "36 89 27\r\n21 66\r\n3 60\r\n11 32\r\n10 81\r\n30 31\r\n27 62\r\n11 81\r\n24 41\r\n30 6\r\n13 45\r\n34 86\r\n26 46\r\n9 62\r\n8 86\r\n17 56\r\n4 86\r\n25 36\r\n23 72\r\n18 55\r\n18 87\r\n22 67\r\n18 12\r\n19 75\r\n21 60\r\n16 49\r\n33 63\r\n26 12\r\n", "output": "YES\r\n"}, {"input": "11 38 21\r\n2 21\r\n2 28\r\n7 19\r\n9 18\r\n7 25\r\n8 4\r\n3 23\r\n2 32\r\n5 34\r\n10 36\r\n8 21\r\n4 6\r\n6 6\r\n4 35\r\n8 34\r\n10 18\r\n11 4\r\n10 2\r\n10 13\r\n4 37\r\n2 29\r\n", "output": "YES\r\n"}, {"input": "30 84 35\r\n20 60\r\n23 21\r\n14 24\r\n24 72\r\n13 76\r\n25 35\r\n11 64\r\n15 57\r\n9 55\r\n14 66\r\n10 24\r\n13 68\r\n11 8\r\n19 43\r\n11 14\r\n16 26\r\n11 22\r\n10 26\r\n15 66\r\n17 65\r\n21 34\r\n7 61\r\n24 64\r\n18 16\r\n22 18\r\n12 9\r\n10 40\r\n8 24\r\n16 52\r\n10 9\r\n7 17\r\n21 78\r\n18 75\r\n10 45\r\n16 29\r\n", "output": "NO\r\n"}, {"input": "66 94 26\r\n11 75\r\n46 72\r\n55 74\r\n34 10\r\n33 84\r\n25 11\r\n13 23\r\n27 73\r\n45 22\r\n54 34\r\n53 63\r\n28 8\r\n57 46\r\n26 78\r\n52 46\r\n32 38\r\n22 55\r\n17 71\r\n56 18\r\n9 60\r\n31 54\r\n6 84\r\n59 57\r\n60 81\r\n51 49\r\n41 77\r\n", "output": "NO\r\n"}, {"input": "68 100 18\r\n17 85\r\n10 77\r\n59 55\r\n29 46\r\n25 74\r\n55 11\r\n37 16\r\n57 61\r\n26 11\r\n11 88\r\n19 18\r\n28 38\r\n32 12\r\n36 49\r\n32 6\r\n57 45\r\n30 6\r\n59 95\r\n", "output": "NO\r\n"}, {"input": "28 61 4\r\n12 18\r\n21 31\r\n14 52\r\n6 36\r\n", "output": "NO\r\n"}, {"input": "11 73 1\r\n4 67\r\n", "output": "YES\r\n"}, {"input": "11 79 0\r\n", "output": "NO\r\n"}, {"input": "11 23 1\r\n11 9\r\n", "output": "YES\r\n"}, {"input": "25 11 0\r\n", "output": "NO\r\n"}, {"input": "39 11 1\r\n18 3\r\n", "output": "YES\r\n"}, {"input": "69 11 0\r\n", "output": "NO\r\n"}, {"input": "13 19 1\r\n6 10\r\n", "output": "NO\r\n"}, {"input": "14 17 0\r\n", "output": "NO\r\n"}, {"input": "20 19 5\r\n7 14\r\n14 12\r\n7 12\r\n15 9\r\n12 6\r\n", "output": "NO\r\n"}, {"input": "17 15 3\r\n10 7\r\n12 6\r\n8 6\r\n", "output": "NO\r\n"}, {"input": "14 17 4\r\n9 9\r\n8 7\r\n8 12\r\n7 9\r\n", "output": "NO\r\n"}, {"input": "15 11 0\r\n", "output": "NO\r\n"}, {"input": "14 16 4\r\n6 11\r\n6 8\r\n8 6\r\n6 7\r\n", "output": "NO\r\n"}, {"input": "16 16 0\r\n", "output": "NO\r\n"}, {"input": "19 20 2\r\n10 14\r\n8 11\r\n", "output": "NO\r\n"}, {"input": "13 15 1\r\n7 10\r\n", "output": "NO\r\n"}, {"input": "11 100 4\r\n6 10\r\n6 20\r\n6 30\r\n6 80\r\n", "output": "NO\r\n"}, {"input": "100 11 2\r\n40 6\r\n70 6\r\n", "output": "NO\r\n"}, {"input": "100 11 5\r\n20 6\r\n30 6\r\n43 7\r\n78 6\r\n89 6\r\n", "output": "YES\r\n"}, {"input": "20 20 5\r\n10 6\r\n6 8\r\n16 11\r\n11 11\r\n7 15\r\n", "output": "YES\r\n"}, {"input": "30 30 5\r\n7 15\r\n24 11\r\n15 15\r\n8 24\r\n9 6\r\n", "output": "NO\r\n"}]
| false |
stdio
| null | true |
605/C
|
605
|
C
|
Python 3
|
TESTS
| 13 | 592 | 9,932,800 |
22165998
|
import sys
jobs, xp, money = map(int, input().split())
vecs = []
maxsum = 0
for i in range(jobs):
x, m = map(int, input().split())
x *= money
m *= xp # ?
vecs.append((x, m))
if x+m > maxsum:
maxsum = x+m
maxvecs = [(x, m)]
elif x+m == maxsum:
maxvecs.append((x, m))
target = xp * money
mindays = 645648946516541465
for vec in maxvecs:
mindays = min(target / min(vec), mindays)
for maxvec in maxvecs:
for vec in vecs:
if vec[0] <= maxvec[0] and vec[1] <= maxvec[1]:
continue
try:
j = (target*(vec[0]-vec[1])) / (maxvec[1]* vec[0] - vec[1]*maxvec[0])
except:
pass
continue
if j == 0:
k = target / min(vec)
else:
k = j*((maxvec[1]-maxvec[0])/(vec[0]-vec[1]))
if k < 0 or j < 0:
k = 0;
j = target / min(vec)
mindays = min(mindays, j+k)
print(mindays)
| 86 | 1,341 | 14,643,200 |
113386000
|
from fractions import Fraction
def higher(x1, y1, x2, y2):
if x1 == 0:
if x2 == 0:
return
def min_days(p, q, pr):
ma = max(a for a, b in pr)
mb = max(b for a, b in pr)
pr.sort(key=lambda t: (t[0], -t[1]))
ch = [(0, mb)]
for a, b in pr:
if a == ch[-1][0]:
continue
while (
len(ch) >= 2
and ((b-ch[-2][1])*(ch[-1][0]-ch[-2][0])
>= (a-ch[-2][0])*(ch[-1][1]-ch[-2][1]))
):
ch.pop()
ch.append((a, b))
ch.append((ma, 0))
a1, b1 = None, None
for a2, b2 in ch:
if a1 is not None:
d = (a2-a1)*q + (b1-b2)*p
s = Fraction(b1*p-a1*q, d)
if 0 <= s <= 1:
return Fraction(d, a2*b1 - a1*b2)
a1, b1 = a2, b2
if __name__ == '__main__':
n, p, q = map(int, input().split())
pr = []
for _ in range(n):
a, b = map(int, input().split())
pr.append((a, b))
print("{:.7f}".format(float(min_days(p, q, pr))))
|
Codeforces Round 335 (Div. 1)
|
CF
| 2,015 | 2 | 256 |
Freelancer's Dreams
|
Mikhail the Freelancer dreams of two things: to become a cool programmer and to buy a flat in Moscow. To become a cool programmer, he needs at least p experience points, and a desired flat in Moscow costs q dollars. Mikhail is determined to follow his dreams and registered at a freelance site.
He has suggestions to work on n distinct projects. Mikhail has already evaluated that the participation in the i-th project will increase his experience by ai per day and bring bi dollars per day. As freelance work implies flexible working hours, Mikhail is free to stop working on one project at any time and start working on another project. Doing so, he receives the respective share of experience and money. Mikhail is only trying to become a cool programmer, so he is able to work only on one project at any moment of time.
Find the real value, equal to the minimum number of days Mikhail needs to make his dream come true.
For example, suppose Mikhail is suggested to work on three projects and a1 = 6, b1 = 2, a2 = 1, b2 = 3, a3 = 2, b3 = 6. Also, p = 20 and q = 20. In order to achieve his aims Mikhail has to work for 2.5 days on both first and third projects. Indeed, a1·2.5 + a2·0 + a3·2.5 = 6·2.5 + 1·0 + 2·2.5 = 20 and b1·2.5 + b2·0 + b3·2.5 = 2·2.5 + 3·0 + 6·2.5 = 20.
|
The first line of the input contains three integers n, p and q (1 ≤ n ≤ 100 000, 1 ≤ p, q ≤ 1 000 000) — the number of projects and the required number of experience and money.
Each of the next n lines contains two integers ai and bi (1 ≤ ai, bi ≤ 1 000 000) — the daily increase in experience and daily income for working on the i-th project.
|
Print a real value — the minimum number of days Mikhail needs to get the required amount of experience and money. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.
Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if $$\frac{|a-b|}{\max(1,b)} \leq 10^{-6}$$.
| null |
First sample corresponds to the example in the problem statement.
|
[{"input": "3 20 20\n6 2\n1 3\n2 6", "output": "5.000000000000000"}, {"input": "4 1 1\n2 3\n3 2\n2 3\n3 2", "output": "0.400000000000000"}]
| 2,400 |
["geometry"]
| 86 |
[{"input": "3 20 20\r\n6 2\r\n1 3\r\n2 6\r\n", "output": "5.000000000000000\r\n"}, {"input": "4 1 1\r\n2 3\r\n3 2\r\n2 3\r\n3 2\r\n", "output": "0.400000000000000\r\n"}, {"input": "3 12 12\r\n5 1\r\n2 2\r\n1 5\r\n", "output": "4.000000000000000\r\n"}, {"input": "3 12 12\r\n5 1\r\n4 4\r\n1 5\r\n", "output": "3.000000000000000\r\n"}, {"input": "3 1 1\r\n1 1\r\n1 1\r\n1 1\r\n", "output": "1.000000000000000\r\n"}, {"input": "1 4 6\r\n2 3\r\n", "output": "2.000000000000000\r\n"}, {"input": "1 3 4\r\n2 3\r\n", "output": "1.500000000000000\r\n"}, {"input": "2 1 1000000\r\n2 4\r\n5 2\r\n", "output": "250000.000000000000000\r\n"}, {"input": "2 1000000 1\r\n2 4\r\n5 2\r\n", "output": "200000.000000000000000\r\n"}, {"input": "2 1000000 1000000\r\n2 4\r\n5 2\r\n", "output": "312500.000000000000000\r\n"}, {"input": "6 2 2\r\n2 4\r\n5 2\r\n5 2\r\n2 4\r\n2 4\r\n5 2\r\n", "output": "0.625000000000000\r\n"}, {"input": "1 3 5\r\n2 3\r\n", "output": "1.666666666666667\r\n"}, {"input": "2 10 3\r\n2 4\r\n5 2\r\n", "output": "2.000000000000000\r\n"}, {"input": "2 10 4\r\n2 4\r\n5 2\r\n", "output": "2.000000000000000\r\n"}, {"input": "2 10 5\r\n2 4\r\n5 2\r\n", "output": "2.187500000000000\r\n"}, {"input": "2 5 8\r\n2 4\r\n5 2\r\n", "output": "2.125000000000000\r\n"}, {"input": "2 4 8\r\n2 4\r\n5 2\r\n", "output": "2.000000000000000\r\n"}, {"input": "2 3 8\r\n2 4\r\n5 2\r\n", "output": "2.000000000000000\r\n"}, {"input": "2 4 1\r\n2 4\r\n5 2\r\n", "output": "0.800000000000000\r\n"}, {"input": "2 4 2\r\n2 4\r\n5 2\r\n", "output": "0.875000000000000\r\n"}, {"input": "2 4 3\r\n2 4\r\n5 2\r\n", "output": "1.062500000000000\r\n"}, {"input": "2 5 3\r\n2 4\r\n5 2\r\n", "output": "1.187500000000000\r\n"}, {"input": "2 5 4\r\n2 4\r\n5 2\r\n", "output": "1.375000000000000\r\n"}, {"input": "2 4 4\r\n2 4\r\n5 2\r\n", "output": "1.250000000000000\r\n"}, {"input": "2 3 4\r\n2 4\r\n5 2\r\n", "output": "1.125000000000000\r\n"}, {"input": "2 3 3\r\n2 4\r\n5 2\r\n", "output": "0.937500000000000\r\n"}, {"input": "2 2 3\r\n2 4\r\n5 2\r\n", "output": "0.812500000000000\r\n"}, {"input": "2 1 3\r\n2 4\r\n5 2\r\n", "output": "0.750000000000000\r\n"}, {"input": "2 2 4\r\n2 4\r\n5 2\r\n", "output": "1.000000000000000\r\n"}, {"input": "2 5 2\r\n2 4\r\n5 2\r\n", "output": "1.000000000000000\r\n"}, {"input": "2 5 4\r\n2 2\r\n4 3\r\n", "output": "1.333333333333333\r\n"}, {"input": "6 1000000 999999\r\n999999 1\r\n999995 999994\r\n999996 999996\r\n999997 999995\r\n999998 999997\r\n1 999998\r\n", "output": "1.000002000006000\r\n"}, {"input": "7 123456 123459\r\n10 2\r\n3 4\r\n11 3\r\n8 1\r\n5 2\r\n7 1\r\n1 8\r\n", "output": "21786.705882352940534\r\n"}, {"input": "10 123457 123459\r\n5 2\r\n11 4\r\n1 8\r\n11 1\r\n7 1\r\n10 2\r\n8 1\r\n11 3\r\n3 4\r\n11 8\r\n", "output": "15432.375000000000000\r\n"}, {"input": "10 630 764\r\n679 16\r\n34 691\r\n778 366\r\n982 30\r\n177 9\r\n739 279\r\n992 89\r\n488 135\r\n7 237\r\n318 318\r\n", "output": "1.472265278375486\r\n"}, {"input": "10 468662 93838\r\n589910 727627\r\n279516 867207\r\n470524 533177\r\n467834 784167\r\n295605 512137\r\n104422 629804\r\n925609 728473\r\n922365 500342\r\n998983 958315\r\n425628 935048\r\n", "output": "0.469139114479426\r\n"}, {"input": "10 18 25\r\n4 8\r\n16 27\r\n16 13\r\n1 26\r\n8 13\r\n2 14\r\n24 8\r\n4 29\r\n3 19\r\n19 20\r\n", "output": "1.041450777202072\r\n"}, {"input": "10 17 38\r\n6 35\r\n16 37\r\n6 12\r\n16 29\r\n27 15\r\n23 28\r\n4 27\r\n30 12\r\n5 4\r\n40 17\r\n", "output": "1.036423841059603\r\n"}, {"input": "10 36 35\r\n32 37\r\n17 30\r\n20 24\r\n11 21\r\n24 9\r\n25 6\r\n37 23\r\n14 8\r\n32 20\r\n17 39\r\n", "output": "1.072669826224329\r\n"}]
| false |
stdio
|
import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_output_path = sys.argv[3]
# Read correct answer
try:
with open(output_path, 'r') as f:
correct_line = f.readline().strip()
b = float(correct_line)
except:
print(0)
return
# Read submission's answer
try:
with open(submission_output_path, 'r') as f:
submission_line = f.readline().strip()
a = float(submission_line)
except:
print(0)
return
# Compute error
denominator = max(1.0, abs(b))
error = abs(a - b) / denominator
if error <= 1e-6:
print(1)
else:
print(0)
if __name__ == "__main__":
main()
| true |
883/K
|
883
|
K
|
Python 3
|
TESTS
| 4 | 62 | 5,529,600 |
31660554
|
t = []
l = []
r = []
for _ in range(int(input())):
s, g = map(int, input().split())
t.append(s)
l.append(s)
r.append(g + s)
for i in range(1, len(l)):
if l[i] < l[i - 1]:
l[i] = l[i - 1] - 1
if r[i] > r[i - 1]:
r[i] = r[i - 1] + 1
for i in range(len(l) - 2, 0, -1):
if l[i] < l[i + 1]:
l[i] = l[i + 1] - 1
if r[i] > r[i + 1]:
r[i] = r[i + 1] + 1
if [1 for a, b in zip(l, r) if a > b]:
print(-1)
else:
print(sum([b - a for a, b in zip(t, r)]))
print(' '.join(map(str, r)))
| 109 | 1,809 | 15,360,000 |
230750690
|
n = int(input())
s = [0]*n
g = [0]*n
for i in range(n):
a,b = map(int,input().split())
s[i] = a
g[i] = a+b
for i in range(1,n):
g[i] = min(g[i],g[i-1]+1)
for i in range(n-2,-1,-1):
g[i] = min(g[i],g[i+1]+1)
ans = 0
for i in range(n):
if s[i] <= g[i]:
ans += g[i] - s[i]
else:
print(-1)
break
else:
print(ans)
print(*g)
|
2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)
|
ICPC
| 2,017 | 3 | 256 |
Road Widening
|
Mayor of city S just hates trees and lawns. They take so much space and there could be a road on the place they occupy!
The Mayor thinks that one of the main city streets could be considerably widened on account of lawn nobody needs anyway. Moreover, that might help reduce the car jams which happen from time to time on the street.
The street is split into n equal length parts from left to right, the i-th part is characterized by two integers: width of road si and width of lawn gi.
For each of n parts the Mayor should decide the size of lawn to demolish. For the i-th part he can reduce lawn width by integer xi (0 ≤ xi ≤ gi). After it new road width of the i-th part will be equal to s'i = si + xi and new lawn width will be equal to g'i = gi - xi.
On the one hand, the Mayor wants to demolish as much lawn as possible (and replace it with road). On the other hand, he does not want to create a rapid widening or narrowing of the road, which would lead to car accidents. To avoid that, the Mayor decided that width of the road for consecutive parts should differ by at most 1, i.e. for each i (1 ≤ i < n) the inequation |s'i + 1 - s'i| ≤ 1 should hold. Initially this condition might not be true.
You need to find the the total width of lawns the Mayor will destroy according to his plan.
|
The first line contains integer n (1 ≤ n ≤ 2·105) — number of parts of the street.
Each of the following n lines contains two integers si, gi (1 ≤ si ≤ 106, 0 ≤ gi ≤ 106) — current width of road and width of the lawn on the i-th part of the street.
|
In the first line print the total width of lawns which will be removed.
In the second line print n integers s'1, s'2, ..., s'n (si ≤ s'i ≤ si + gi) — new widths of the road starting from the first part and to the last.
If there is no solution, print the only integer -1 in the first line.
| null | null |
[{"input": "3\n4 5\n4 5\n4 10", "output": "16\n9 9 10"}, {"input": "4\n1 100\n100 1\n1 100\n100 1", "output": "202\n101 101 101 101"}, {"input": "3\n1 1\n100 100\n1 1", "output": "-1"}]
| 1,800 |
["constructive algorithms", "greedy", "implementation"]
| 109 |
[{"input": "3\r\n4 5\r\n4 5\r\n4 10\r\n", "output": "16\r\n9 9 10 \r\n"}, {"input": "4\r\n1 100\r\n100 1\r\n1 100\r\n100 1\r\n", "output": "202\r\n101 101 101 101 \r\n"}, {"input": "3\r\n1 1\r\n100 100\r\n1 1\r\n", "output": "-1\r\n"}, {"input": "10\r\n21005 10850\r\n27020 13372\r\n28183 3724\r\n22874 13564\r\n27446 11493\r\n22522 10012\r\n24819 11529\r\n24166 11084\r\n24539 9211\r\n24152 9235\r\n", "output": "71869\r\n31855 31856 31857 31858 31859 31860 31861 31862 31863 31864 \r\n"}, {"input": "1\r\n1 0\r\n", "output": "0\r\n1 \r\n"}, {"input": "1\r\n1 1000000\r\n", "output": "1000000\r\n1000001 \r\n"}, {"input": "1\r\n1000000 1000000\r\n", "output": "1000000\r\n2000000 \r\n"}, {"input": "1\r\n1 0\r\n", "output": "0\r\n1 \r\n"}, {"input": "1\r\n1 0\r\n", "output": "0\r\n1 \r\n"}, {"input": "1\r\n1 1\r\n", "output": "1\r\n2 \r\n"}, {"input": "2\r\n2 2\r\n1 1\r\n", "output": "2\r\n3 2 \r\n"}, {"input": "2\r\n2 0\r\n1 0\r\n", "output": "0\r\n2 1 \r\n"}, {"input": "2\r\n2 1\r\n2 2\r\n", "output": "3\r\n3 4 \r\n"}, {"input": "3\r\n1 3\r\n2 1\r\n3 0\r\n", "output": "4\r\n4 3 3 \r\n"}, {"input": "3\r\n1 3\r\n1 3\r\n2 1\r\n", "output": "7\r\n4 4 3 \r\n"}, {"input": "3\r\n3 3\r\n2 0\r\n1 2\r\n", "output": "2\r\n3 2 3 \r\n"}, {"input": "4\r\n1 3\r\n2 3\r\n3 1\r\n1 0\r\n", "output": "-1\r\n"}, {"input": "4\r\n1 2\r\n4 2\r\n4 2\r\n4 2\r\n", "output": "5\r\n3 4 5 6 \r\n"}, {"input": "4\r\n1 3\r\n1 4\r\n2 0\r\n4 1\r\n", "output": "-1\r\n"}, {"input": "5\r\n3 5\r\n4 5\r\n1 0\r\n2 3\r\n1 1\r\n", "output": "-1\r\n"}, {"input": "5\r\n2 0\r\n3 0\r\n3 0\r\n3 5\r\n2 4\r\n", "output": "4\r\n2 3 3 4 5 \r\n"}, {"input": "5\r\n1 0\r\n4 2\r\n1 5\r\n1 5\r\n1 4\r\n", "output": "-1\r\n"}, {"input": "6\r\n1 1\r\n3 4\r\n3 5\r\n2 5\r\n6 3\r\n2 3\r\n", "output": "8\r\n2 3 4 5 6 5 \r\n"}, {"input": "6\r\n5 3\r\n4 4\r\n5 5\r\n1 2\r\n6 3\r\n6 4\r\n", "output": "-1\r\n"}, {"input": "6\r\n1 5\r\n6 2\r\n2 1\r\n1 2\r\n3 6\r\n1 1\r\n", "output": "-1\r\n"}, {"input": "7\r\n3 0\r\n1 5\r\n7 7\r\n6 5\r\n1 6\r\n1 6\r\n7 2\r\n", "output": "-1\r\n"}, {"input": "7\r\n7 5\r\n1 2\r\n3 0\r\n3 1\r\n4 5\r\n2 6\r\n6 3\r\n", "output": "-1\r\n"}, {"input": "7\r\n3 1\r\n5 0\r\n4 1\r\n7 5\r\n1 3\r\n7 6\r\n1 4\r\n", "output": "-1\r\n"}, {"input": "8\r\n4 2\r\n8 8\r\n4 1\r\n7 7\r\n1 3\r\n1 1\r\n3 1\r\n5 2\r\n", "output": "-1\r\n"}, {"input": "8\r\n4 2\r\n1 1\r\n1 5\r\n6 8\r\n5 7\r\n8 8\r\n6 2\r\n8 8\r\n", "output": "-1\r\n"}, {"input": "8\r\n4 6\r\n3 8\r\n7 4\r\n5 0\r\n8 7\r\n8 8\r\n8 8\r\n3 5\r\n", "output": "-1\r\n"}, {"input": "9\r\n5 3\r\n1 8\r\n2 2\r\n2 7\r\n5 6\r\n1 5\r\n2 0\r\n1 6\r\n3 9\r\n", "output": "-1\r\n"}, {"input": "9\r\n4 7\r\n2 0\r\n7 3\r\n9 5\r\n8 8\r\n6 5\r\n6 8\r\n5 3\r\n8 7\r\n", "output": "-1\r\n"}, {"input": "9\r\n3 8\r\n7 7\r\n8 8\r\n7 3\r\n9 6\r\n6 8\r\n4 1\r\n7 0\r\n7 0\r\n", "output": "-1\r\n"}, {"input": "10\r\n1 8\r\n5 8\r\n7 9\r\n9 4\r\n3 4\r\n5 3\r\n1 3\r\n2 4\r\n6 6\r\n5 7\r\n", "output": "-1\r\n"}, {"input": "10\r\n9 9\r\n10 4\r\n1 9\r\n4 8\r\n9 6\r\n9 6\r\n1 7\r\n1 7\r\n10 0\r\n4 1\r\n", "output": "-1\r\n"}, {"input": "10\r\n3 10\r\n8 5\r\n4 1\r\n8 4\r\n8 8\r\n9 1\r\n6 0\r\n10 6\r\n7 7\r\n6 0\r\n", "output": "-1\r\n"}, {"input": "1\r\n1000000 0\r\n", "output": "0\r\n1000000 \r\n"}, {"input": "2\r\n1000000 0\r\n999999 0\r\n", "output": "0\r\n1000000 999999 \r\n"}, {"input": "2\r\n1000000 0\r\n999998 1\r\n", "output": "1\r\n1000000 999999 \r\n"}, {"input": "2\r\n1000000 1000000\r\n1000000 1000000\r\n", "output": "2000000\r\n2000000 2000000 \r\n"}]
| false |
stdio
| null | true |
326/B
|
335
|
B
|
PyPy 3-64
|
TESTS
| 5 | 154 | 11,980,800 |
174009177
|
from collections import Counter
s = input()
cnt = Counter(s)
for c in cnt:
if cnt[c] >= 100:
print(c * 100)
exit(0)
n = len(s)
dp = [[None for _ in range(n)] for _ in range(n)]
res = ''
for i in range(n - 1, -1, -1):
for j in range(i, n, 1):
if i == j:
dp[i][j] = s[i]
elif i + 1 == j:
dp[i][j] = s[i] + s[j] if s[i] == s[j] else s[i]
else:
if s[i] == s[j]:
dp[i][j] = s[i] + dp[i + 1][j - 1] + s[j]
else:
if len(dp[i + 1][j]) >= len(dp[i][j - 1]):
dp[i][j] = dp[i + 1][j]
else:
dp[i][j] = dp[i][j - 1]
if len(dp[i][j]) == 100:
print(dp[i][j])
exit(0)
if len(dp[i][j]) > len(res):
res = dp[i][j]
print(res)
| 72 | 1,996 | 117,145,600 |
66242753
|
from collections import defaultdict
s = input()
n = len(s)
if n >= 2600:
print(s[0] * 100)
elif n > 2574:
count = defaultdict(int)
for l in s:
count[l] += 1
max_l = s[0]
for l, c in count.items():
if c >= 100:
max_l = l
print(max_l * 100)
else:
data = defaultdict(dict)
def print_p(i, gap):
if gap == 1:
return s[i]
if gap == 2:
return s[i:i + 2]
return s[i] + print_p(data[i + 1][gap - 2][1], data[i + 1][gap - 2][2]) + s[i]
for i in range(n):
data[i][1] = (1, i, 1)
max_p = data[0][1]
for i in range(n - 1):
if s[i] == s[i + 1]:
data[i][2] = (2, i, 2)
max_p = data[i][2]
else:
data[i][2] = data[i][1]
output = None
for gap in range(3, n + 1):
for i in range(n - gap + 1):
j = i + gap - 1
if s[i] == s[j]:
size = data[i + 1][gap - 2][0] + 2
data[i][gap] = (size, i, gap)
if size > max_p[0]:
max_p = data[i][gap]
if size == 100:
output = print_p(i, gap)
if size == 101:
output = print_p(i, gap)
output = output[:50] + output[51:]
else:
if data[i][gap - 1][0] > data[i + 1][gap - 1][0]:
data[i][gap] = data[i][gap - 1]
else:
data[i][gap] = data[i + 1][gap - 1]
if output:
print(output)
else:
print(print_p(max_p[1], max_p[2]))
|
MemSQL start[c]up Round 2
|
CF
| 2,013 | 2 | 256 |
Palindrome
|
Given a string s, determine if it contains any palindrome of length exactly 100 as a subsequence. If it has any, print any one of them. If it doesn't have any, print a palindrome that is a subsequence of s and is as long as possible.
|
The only line of the input contains one string s of length n (1 ≤ n ≤ 5·104) containing only lowercase English letters.
|
If s contains a palindrome of length exactly 100 as a subsequence, print any palindrome of length 100 which is a subsequence of s. If s doesn't contain any palindromes of length exactly 100, print a palindrome that is a subsequence of s and is as long as possible.
If there exists multiple answers, you are allowed to print any of them.
| null |
A subsequence of a string is a string that can be derived from it by deleting some characters without changing the order of the remaining characters. A palindrome is a string that reads the same forward or backward.
|
[{"input": "bbbabcbbb", "output": "bbbcbbb"}, {"input": "rquwmzexectvnbanemsmdufrg", "output": "rumenanemur"}]
| 1,900 |
[]
| 72 |
[{"input": "bbbabcbbb\r\n", "output": "bbbcbbb\r\n"}, {"input": "rquwmzexectvnbanemsmdufrg\r\n", "output": "rumenanemur\r\n"}, {"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n", "output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n"}, {"input": "ab\r\n", "output": "a\r\n"}, {"input": "abacaba\r\n", "output": "abacaba\r\n"}, {"input": "startcup\r\n", "output": "trt\r\n"}, {"input": "aabccb\r\n", "output": "bccb\r\n"}, {"input": "abbacc\r\n", "output": "abba\r\n"}, {"input": "iwlauggytlpahjhteurdyoaulbnnhashwktxlrhpgqnypnuitmfhhbkwysjuhljshaanowhngeaumdovrlvuofzsbhhzdyngntdu\r\n", "output": "ugyhhurounhashwkhnpnhkwhsahnuoruhhygu\r\n"}, {"input": "zypzepzqni\r\n", "output": "zpepz\r\n"}, {"input": "a\r\n", "output": "a\r\n"}, {"input": "oliifeuoyzhkootktyulrxshmboejshoguwgufxpuloouoojovufukdokoeyouzihyaeuucutypfxictojtnfoouoniuyuvkrglsueihpuxsulrrifyuwuyolutotzozsvhoyjxuguecywbfuuqmpzooojergudvwucsocoojfplaulvfpcooxxublcfpguuoouooouo\r\n", "output": "ouooouoougpluoovufudooozuucuxjoouoyurlsupuslruyouoojxucuuzooodufuvooulpguoouooouo\r\n"}, {"input": "kyzxnaiwjgnotlekhycrnapekfcfxydbvnjboevgdzgigxvijgwrqnacumglzlxkcurmqmxzxxbuxlwruycdhzzdmtvobmvylyibyynjvonmbwvwqzmidfhnndecrwyfxjxwquiubrimmcwoeecotwnkfrojwuxmficzurwaqljfvdcvixcictxfzztzzbvbdypayhay\r\n", "output": "yahyapydbvbzixijqauzcurmmbuxwrcdhdmvbmvyybyyvmbvmdhdcrwxubmmruczuaqjixizbvbdypayhay\r\n"}, {"input": "carfnnnuxxbntssoxafxxbbxnonpunapjxtxexlptcwqxkjnxaanntriyunvnoxkdxnsxjxxoixyplkvxctuoenxxjixxgyxlgnxhklxqxqzxafxcnealxxwspbpcfgpnnovwrnnaxjcjpnierselogxxcxrxnlpnkbzjnqvrkurhxaxyjxxnxxnpipuntongeuusujf\r\n", "output": "fnnuxxnxxxxnnpnxxxlpcjxannrvoxxnxxxxlkxnxxixxnxklxxxxnxxovrnnaxjcplxxxnpnnxxxxnxxunnf\r\n"}, {"input": "yggmkggmvkfmmsvijnyvwgswdpwkwvmcmmswksmhwwmmgwzgwkkwogwiglwggwwnmwgkqggkugwmfwawxggrwgwclgwclknltxrkjwogwejgeymtmwziwmskrwsmfmmiwkwwvsgwsdmmkfmggkmpgg\r\n", "output": "ggmkggmfmmswgswwkwmmmswksmwwmmgwgwkkwgwgwggwwmwgkggkgwmwwggwgwgwkkwgwgmmwwmskwsmmmwkwwsgwsmmfmggkmgg\r\n"}, {"input": "mstmytylsulbuhumamahahbbmmtttmlulhamyhlmbulyylubmlhymahlulmtttmmbbhahamamuhubluslytymtsmxp\r\n", "output": "mstmytylsulbuhumamahahbbmmtttmlulhamyhlmbulyylubmlhymahlulmtttmmbbhahamamuhubluslytymtsm\r\n"}, {"input": "ouwvwggffgoowjzkzeggbzieagwwznzzzlwvzswfznvozveezgopefecoezfsofqzqfoovaofwzgefzzweggvztzvofgevivgevwwslhofzwopopzzgfvwzeogovvgzdzafgwzshovvrwwwgmooczezivfwgybgezogsmgfgwwzevvwgeehwvegfdzgzwgzoffgteztwvgwfvogeggfogkeovxzzlzzwzzlvifgxzwvrogeeeggeoefhhzoweerwvxofgvwovozwvizofzogozgwevwllexooktoggvoeowgtezffzfdohvgmofofvwzzofwvwsfbwyzzziofvfcofmzgrofzozzgghseafefdpwwwogpzzfowfhlsoeitfogeezfagofqqesocewfpwveozeenwsvffzwozwzlwoeffzonveaivgfebvegveozzfoowzwzkwezjeeuwzgezoovwwgzgzggwzowzevwfgggoozfozfwg\r\n", "output": "gzoggwveoggvoegezfzovgofowzzowvswzovfcofzgofosfwozzowfsofogzfocfvozwsvwozzwofogvozfzegeovggoevwggozg\r\n"}, {"input": "gamjuklsvzwddaocadujdmvlenyyvlflipneqofeyipmtunbdmbdyhkovnpdetueeiunsipowrhxrhtastjniqdhmehcumdcrghewljvpikcraoouhfwtnoaukbnykjapkvyakdnckkypargamvnsqtchesbmuffqqycnjvolmtpjfykvkeexkpdxjexrvdzpcbthhkxuucermkaebrvcxoovidpqnpkgbhiatyjvumihptrigqxsemqbbxwmyunmmayubqqjaioqmzyekhtqgoockiskyqihopmkastfvqiewtbtbriuyuszlndcweuhnywlkjgerqokxsxfxeaxcuwoocoonstwlxujrynkwzshpretbhlvkxyebnhafxfelpmqfkksurrfqeaykdxihtyqpaiftigdwkraxxzxkqicnfxlxhxwtkkknurzubtkivzpmlfebzduezuqeyequvyrighfzyldxenwxokumxtiieeeuku\r\n", "output": "uuemkexdhiyvuqequuzefvitbuzunkkxxfxxxrkwpthxyaeqfrrfqeayxhtpwkrxxxfxxkknuzubtivfezuuqequvyihdxekmeuu\r\n"}, {"input": "qpjnbjhmigtgtxolifwoyatdlqtejqovaslcgjufverrnkqxtsrrytqgtuikcseggjnltpggcpjizojthwycibvnvxetibpicujwmyzcojhpftttwvtlxaeefbvbvygouinnjrwuczlplbzahqciptrlrcuamyntvrzqxrnkrczmluocsuthwaptenwysoviwwcnrljuskynomlpslqyjcauagiveunrzognltohqxggprgreezjsqchcgihzbrleuwgnlsqeenybrbsqcnnlbipajlcfmajtchblnxsnegooewupmvufzbipnyjneuwelibvhoghtqpvqjehvpbiclalyzxzqwekemnsjabyzatjgzbrheubuzrcgtxvaokzapejesjntgnriupahoeousszcqprljhhgnqclbsuvvgfudhwmabfbyqjcqqgnnoocqxbyjpmvncmcieavcstjvvzgtbgcjbqnqbpueqlgibtvjpzsan\r\n", "output": "nspjvglqeqcgbgsenybqcnncjbwuvublghpqehpinsjazatgruurgtazajsnipheqphglbuvuwbjcnncqbynesgbgcqeqlgvjpsn\r\n"}, {"input": "nwgwxgxlbgbgnvqowqqocgwwnbnoqghxwxbbonxxgongqwbbxxbbwiqgnogxxnobmbxwxlgqonbnwhewgoqqwoqngbgbxgxwgwna\r\n", "output": "nwgwxgxbgbgnqowqqogwwnbnoqgxwxbbonxxgongqwbbxxbbwqgnogxxnobbxwxgqonbnwwgoqqwoqngbgbxgxwgwn\r\n"}, {"input": "vtaavlavalbvbbbccccddddeeeefltfffgvgvgtghlhhhiviiijjjjkkkkmmmmnnnlnooooppppqqvqqrrrrssssluuuvuwwwwtv\r\n", "output": "vtvlvlvltgvgvgtlvlvlvtv\r\n"}, {"input": "iuaiubcide\r\n", "output": "iuiui\r\n"}, {"input": "aavaaaadbbbddbbdbccccwvcceveeeedeffvdfvfffdggggvwgghhdhdwdhhhwiiwiiiiwjjjjjjkkkkdkklwvlllllmmmmmmvdnndnwndnndooowoooppppppwqwqdwqwqwdqqrdrwdrrrrsdssssvsttttttuvuuuwuuxxxdwwxwxdxyyyywyddwvdvdvdvvwddddv\r\n", "output": "vddddwvvdvdvdvwddwdwwwdwvvddwdqqdwqwqwdqqdwddvvwdwwwdwddwvdvdvdvvwddddv\r\n"}, {"input": "ibbbbiabbibbscccocccccdsdyddiddishddffjifhfffjffgggeggeggjgkkkjkkjkkklllaellllhlmymmmmssmmomnnanojennosasoennnjpopaopppspsyphepqaqqqjqqjqqrrjerrerrrrttttttttuuuujuhuiuuwwjwhswwwiwwxixxxyxsosixxxaizzzi\r\n", "output": "iiaisosyiishjihjeejjjaehyssoaojnnosasonnjoaossyheajjjeejhijhsiiysosiaii\r\n"}, {"input": "ataaaamabbbbtmbbmtmtccctcttcmmcmtdmmmmmddddtdmeetmtmmeteteeftffmfffgmmggggmgmmhmhhhmhhiimtiiititmmjjjtjjjkkmtmtkmkmkklllmllmmtmlnmnnmnnnootooooptpppttppqmqqtqmqqmtmrrrtrrrssssssuuuuuuvvvvvvwwwwwwxxxxx\r\n", "output": "tmtmmtmttttmmmtmmmmmtmtmtmmtttmmmgggggmmmtttmmtmtmtmmmmmtmmmttttmtmmtmt\r\n"}, {"input": "agqdhdgqgannagbqbbhddddcgngchnhdceeqefqhgfdngfdhiiidhjgqjjndqkgqnkkgqqndlldlqqmddmmnqoqgnoqgqdopnqghdhdgpndpghqrrqdhrsnhgnssgddddhtttqgnnguqgudhuvvdqg\r\n", "output": "gqdhdgqgnngqhddddgnghnhdqqhgdngdhdhgqndqgqngqqnddqqddnqqgnqgqdnqghdhdgndghqqdhnhgngddddhqgnngqgdhdqg\r\n"}, {"input": "hyhwkyvfpfpykwhchycwcpfppcuvuvupshcwwkwucpkppkpcuwkwwchspuvuvaucppfbpcwcyhchwkypfpfvykwhyh\r\n", "output": "hyhwkyvfpfpykwhchycwcpfppcuvuvupshcwwkwucpkppkpcuwkwwchspuvuvucppfpcwcyhchwkypfpfvykwhyh\r\n"}, {"input": "dpddpdddddidtddudddddqddddddddddddddddddddddcdddddddddddddddkkdddddgdddddddddjkdovfvvgnnvvvvvvvvvvnvvvvvkvvvvfnvuuvevvvfvvvpvvvkvvvvvvvvvlvvvifvvvvklvbvvovovvvvkvivnvvvvvvulvvvwwmjwtwwbwlwwwwwwwwwwpewewwwwwpwwwwwwwwwwwwwwwwwwlwbtwwwwjwmwwwwwlwwuwnwwwwiwwkwwwwwwwwxxxxxxoxxxoxxxbxxxxlxxxxxxxxxxxxxxxxkxxxxfixlxxxxxkpxfxxxxxxxxxxxxxexxxuuxxxxxxxxxyynyyyyyyyyyyfkyynynyynyyyyyyygyyyyyyyyyyyyyfyyoyyyyyyykyyyyyyjyyyyyyygykyykyyycyyqyzzzzzzzzzzzzzzzzzzuzzzzzzzzzzztzzzizppzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\r\n", "output": "pnuuefpklifklboowwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwooblkfilkpfeuunp\r\n"}, {"input": "aaaaaaaaakaaakaaaaaabbbbbbbbbbbxbbxbkbbbkxbcccccccccicccccccccddkdxdddkdkddddddkdddddikekeeeeeeeekeeeeeeeixieeffxfffffffffifffffffgikiigggggggggiggggggxgghhhhhkhhhhhhhhhhxhhhjjjjjiijjjjijjjjjxkjkjjjllllllllllkllllllllmmmmmimmmmmmmmmmmmmnnnnnnnnnnnnnnnknnnoooookooioooxioooooooopppppppppppippppxkpkkkppqqxqqqqqqqqiqiqqqqxiqqkqrrkrrrirrrrrrrrrrrrrssskskskssssssssxsssssiittttittxtttttttktttttuxuuuuuiiuuuuuuuuuuikuuvvvvivvixvvvvvvvvvivvvwxiwwwwwwwwwwwkwkwkwwwiwykyyyyyykyyykyxyyyyyyyzzzzzkzizzzzxkkxxkk\r\n", "output": "kxkkxikxkkkikkkixixiikiiixkxiiixkkkikkixippppppppppppppppppixikkikkkxiiixkxiiikiixixikkkikkkxkixkkxk\r\n"}, {"input": "aaaaaakaaaaaaaaaaaataaabbbbrbbbbbbbbbxbbbbbxbbbkctcccccccccccccncckcccccnddddrdddddddddddddddddnteeeeeeeeeeneteeneeeeeeeefffffffffnnffffffffnffffgggggggggtrgggrggggggggghhhhhhhhhnhhxhhhhhhhkhhhitiiiiiiiintiiiikiiiiiiiijxjjjjjjxjjjkjjjjjjjtjjjjlllllntllllllllllllkllllmmxmmmmmmmmmmmmmmmmmmmoooooooooooooonoooooooppprpppprppppptppnpppppppqqqqnnqqqqqqqqqqqqqqqqqssnsssssssstssnssssstssssuunuuuuuruunuuuuuuuukuuuuvvvvvvvvvvvvnvvvvvvvvvwwtwwwwwwwwkwwwwwwwwwxwwyyyyyyxyyyyyyyryyyyyyyyzzzzzzzztzzzzzzzkzzzzz\r\n", "output": "ktrxxktnknrntntnnnntrrnxktnjjjjjjjjjjkjjjjjjjjjjntkxnrrtnnnntntnrnkntkxxrtk\r\n"}, {"input": "afcyfydfxueffbukxgbhfkuufkbubkxiybuuufffkkyyxxbxfbffffbfxbxjxylykkmfffuuubyxkbubkfuukfbxkubffuxfyfyf\r\n", "output": "fyfyfxuffbukxbfkuufkbubkxybuuufffkkyyxxbxfbffffbfxbxxyykkfffuuubyxkbubkfuukfbxkubffuxfyfyf\r\n"}, {"input": "b\r\n", "output": "b\r\n"}, {"input": "abababbabbabbabbbbbbbbabbabbaaaaaaaabbbabbabbbabbbabaaabbaba\r\n", "output": "ababbaababbbbbbabbabbaaaaaaaabbabbabbbbbbabaabbaba\r\n"}, {"input": "ttabacabadabffacavvbaeabacabadabacabafabacabavvvvdabacabzaeabacabadabacttttafba\r\n", "output": "abacabadabacabaeabacabadabacabafabacabadabacabaeabacabadabacaba\r\n"}, {"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccdddddddddddddddeeeeeeeeeeeeeeeeeeeeeeeeee\r\n", "output": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\r\n"}, {"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccdddddddddddddddeeeeeeeeeeeeeeeeeeeeeeeeee\r\n", "output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n"}, {"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccdddddddddddddddeeeeeeeeeeeeeeeeeeeeeeeeeezzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\r\n", "output": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\r\n"}, {"input": "qwertyuioplkjhgfdsazxcvbnm\r\n", "output": "q\r\n"}, {"input": "abaabacdefgb\r\n", "output": "abaaba\r\n"}, {"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n", "output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaazaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n"}, {"input": "gsayhacnaqwakieoeyomukmqueosoeuckuotyadhoniaovwgnbcpczjnibhgyapqmuosbrpqwkckqjakqjeamyqqwskmoueaakfixextmcwyaqdhtlylnowuiaaoraeskkqaohbwcupgsdcngyavctnaqaaaqomimemckzkaagaebucmjuwacaoicyoywkwmogdiknzqiakackvzgrywxfiojdkopsnsifwwcwkwuqqpfpuaeigcfjebbuakkaquajyelivanwewaq\r\n", "output": "qwaieyuqueeukodoiwgcznigowkcaawmueaakemaqtynuoakkaounytqamekaaeumwaackwoginzcgwiodokueeuquyeiawq\r\n"}, {"input": "amltiwwuisnsaghiiwoaqgdgnpqkfudobascczacwipotugyeairyrcsgsuxxttsxaausijymcceapckvxfqnqdg\r\n", "output": "gdnqfcacyisuxttxusiycacfqndg\r\n"}, {"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n", "output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n"}, {"input": "abababababababababababababababababababababababababcbababababababababababababababababababababababababa\r\n", "output": "abababababababababababababababababababababababababbababababababababababababababababababababababababa\r\n"}, {"input": "aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeeefeeeeeeeeeeddddddddddccccccccccbbbbbbbbbbaaaaaaaaaa\r\n", "output": "aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeeeeeeeeeeeeeddddddddddccccccccccbbbbbbbbbbaaaaaaaaaa\r\n"}]
| false |
stdio
|
import sys
def is_palindrome(s):
return s == s[::-1]
def is_subsequence(sub, s):
i = 0
for c in sub:
i = s.find(c, i) + 1
if i == 0:
return False
return True
input_path, output_path, submission_path = sys.argv[1:4]
with open(input_path) as f:
s = f.read().strip()
with open(output_path) as f:
ref_output = f.read().strip()
with open(submission_path) as f:
sub_output = f.read().strip()
if len(sub_output) != len(ref_output):
print(0)
elif not is_palindrome(sub_output):
print(0)
elif not is_subsequence(sub_output, s):
print(0)
else:
print(1)
| true |
605/A
|
605
|
A
|
Python 3
|
TESTS
| 10 | 140 | 8,908,800 |
14782471
|
a=[0 for i in range(100010)]
b=[0 for i in range(100010)]
c=[0 for i in range(100010)]
n, a[1:] = int(input()), map(int,input().split(' '))
for i in range(1,n+1):
if b[a[i]-1]:
c[a[i]]=c[a[i]-1]+1
else:
c[a[i]]=1
b[i]=1
print (n-max(c[1:n+1]))
| 66 | 93 | 13,516,800 |
196883940
|
import sys
if __name__ == '__main__':
n = eval(input())
p = list(map(int, sys.stdin.readline().rstrip().split()))
cnt = [0] * (n + 1)
# 贪心算法,找到序列中最长的升序子序列(只差1),那么只需要将这之外的数字移动即可
for i in p:
cnt[i] = cnt[i - 1] + 1
print(n - max(cnt))
|
Codeforces Round 335 (Div. 1)
|
CF
| 2,015 | 2 | 256 |
Sorting Railway Cars
|
An infinitely long railway has a train consisting of n cars, numbered from 1 to n (the numbers of all the cars are distinct) and positioned in arbitrary order. David Blaine wants to sort the railway cars in the order of increasing numbers. In one move he can make one of the cars disappear from its place and teleport it either to the beginning of the train, or to the end of the train, at his desire. What is the minimum number of actions David Blaine needs to perform in order to sort the train?
|
The first line of the input contains integer n (1 ≤ n ≤ 100 000) — the number of cars in the train.
The second line contains n integers pi (1 ≤ pi ≤ n, pi ≠ pj if i ≠ j) — the sequence of the numbers of the cars in the train.
|
Print a single integer — the minimum number of actions needed to sort the railway cars.
| null |
In the first sample you need first to teleport the 4-th car, and then the 5-th car to the end of the train.
|
[{"input": "5\n4 1 2 5 3", "output": "2"}, {"input": "4\n4 1 3 2", "output": "2"}]
| 1,600 |
["constructive algorithms", "greedy"]
| 66 |
[{"input": "5\r\n4 1 2 5 3\r\n", "output": "2\r\n"}, {"input": "4\r\n4 1 3 2\r\n", "output": "2\r\n"}, {"input": "1\r\n1\r\n", "output": "0\r\n"}, {"input": "2\r\n1 2\r\n", "output": "0\r\n"}, {"input": "2\r\n2 1\r\n", "output": "1\r\n"}, {"input": "6\r\n5 3 6 1 4 2\r\n", "output": "4\r\n"}, {"input": "7\r\n1 2 3 6 7 4 5\r\n", "output": "2\r\n"}, {"input": "8\r\n6 2 1 8 5 7 3 4\r\n", "output": "5\r\n"}, {"input": "3\r\n1 2 3\r\n", "output": "0\r\n"}, {"input": "3\r\n1 3 2\r\n", "output": "1\r\n"}, {"input": "3\r\n2 1 3\r\n", "output": "1\r\n"}, {"input": "3\r\n2 3 1\r\n", "output": "1\r\n"}, {"input": "3\r\n3 1 2\r\n", "output": "1\r\n"}, {"input": "3\r\n3 2 1\r\n", "output": "2\r\n"}, {"input": "7\r\n1 3 5 7 2 4 6\r\n", "output": "5\r\n"}, {"input": "7\r\n1 5 2 6 3 7 4\r\n", "output": "3\r\n"}, {"input": "5\r\n1 4 2 3 5\r\n", "output": "2\r\n"}, {"input": "9\r\n1 6 4 5 9 8 7 3 2\r\n", "output": "7\r\n"}, {"input": "10\r\n5 1 6 2 8 3 4 10 9 7\r\n", "output": "6\r\n"}, {"input": "50\r\n39 8 41 9 45 1 5 18 38 31 28 7 12 49 33 19 26 6 42 13 37 27 2 21 20 22 14 16 48 47 32 50 25 17 35 24 36 4 29 15 43 10 11 30 40 46 3 23 44 34\r\n", "output": "46\r\n"}, {"input": "50\r\n43 15 10 33 32 31 13 7 5 22 36 1 25 14 38 19 8 6 24 42 28 21 44 35 4 3 49 30 27 46 2 9 17 37 45 41 18 39 12 11 16 20 50 26 29 34 40 47 48 23\r\n", "output": "47\r\n"}, {"input": "50\r\n10 40 34 43 50 17 15 13 9 2 32 18 11 46 27 24 36 16 29 45 42 4 47 19 48 37 41 5 21 26 22 25 44 31 35 49 20 8 12 23 6 38 14 1 7 28 3 33 39 30\r\n", "output": "46\r\n"}, {"input": "50\r\n10 37 3 46 45 29 36 13 21 25 35 5 18 33 12 19 50 16 30 47 20 42 39 28 2 6 38 8 7 31 22 27 26 9 15 14 34 48 4 32 40 43 44 24 11 1 23 17 49 41\r\n", "output": "46\r\n"}, {"input": "50\r\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 42 37 38 39 40 41 36 43 44 45 46 47 48 49 50\r\n", "output": "14\r\n"}, {"input": "50\r\n1 2 3 4 5 6 7 8 43 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 50 33 34 35 36 37 38 39 40 41 42 9 44 45 46 47 48 49 32\r\n", "output": "27\r\n"}, {"input": "50\r\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 49 40 41 47 43 44 45 46 42 50 39 48\r\n", "output": "11\r\n"}, {"input": "50\r\n1 2 3 4 27 6 7 8 9 10 30 12 13 14 15 16 17 18 19 20 21 22 23 24 28 26 5 25 29 11 31 32 33 34 38 36 37 35 39 40 41 42 43 44 45 46 47 48 49 50\r\n", "output": "36\r\n"}, {"input": "50\r\n1 2 3 4 5 6 7 49 9 10 17 12 13 14 15 16 11 18 19 20 21 22 23 24 25 26 27 38 29 36 30 32 33 34 35 31 37 28 39 40 41 42 43 44 45 46 47 48 8 50\r\n", "output": "38\r\n"}, {"input": "50\r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 31 18 19 20 21 23 22 24 25 26 27 28 29 49 17 32 33 34 39 36 37 38 47 44 41 42 43 40 45 46 35 48 30 50\r\n", "output": "33\r\n"}, {"input": "50\r\n1 2 15 4 5 6 7 8 9 10 11 12 13 14 3 16 17 18 19 32 21 22 36 28 23 26 27 24 29 30 31 20 33 34 37 25 35 38 40 39 41 42 43 44 45 46 47 48 49 50\r\n", "output": "39\r\n"}, {"input": "5\r\n4 3 1 2 5\r\n", "output": "3\r\n"}, {"input": "6\r\n1 3 5 6 4 2\r\n", "output": "4\r\n"}, {"input": "10\r\n2 1 4 3 6 5 8 7 10 9\r\n", "output": "8\r\n"}, {"input": "5\r\n1 2 4 5 3\r\n", "output": "2\r\n"}, {"input": "7\r\n1 4 2 3 7 6 5\r\n", "output": "4\r\n"}, {"input": "4\r\n3 1 2 4\r\n", "output": "2\r\n"}, {"input": "6\r\n2 5 4 3 6 1\r\n", "output": "4\r\n"}, {"input": "5\r\n1 3 4 5 2\r\n", "output": "2\r\n"}, {"input": "6\r\n2 4 6 5 1 3\r\n", "output": "4\r\n"}, {"input": "6\r\n1 2 4 5 6 3\r\n", "output": "3\r\n"}, {"input": "9\r\n9 8 7 4 5 6 3 2 1\r\n", "output": "6\r\n"}, {"input": "7\r\n4 1 2 3 6 5 7\r\n", "output": "4\r\n"}]
| false |
stdio
| null | true |
600/C
|
600
|
C
|
Python 3
|
TESTS
| 4 | 46 | 102,400 |
194307103
|
from collections import Counter
map = Counter(input())
odd = []
for c, cnt in map.items():
if cnt % 2 > 0:
odd.append(c)
for c in odd[: len(odd) // 2]:
map[c] += 1
for c in odd[(len(odd) + 1) // 2: ]:
map[c] -= 1
head = ''.join([char * (count // 2) for char, count in map.items()])
mid = odd[len(odd) // 2] if len(odd) % 2 > 0 else ''
tail = ''.join(reversed(head))
print(head + mid + tail)
| 66 | 62 | 4,096,000 |
209539274
|
# /**
# * author: brownfox2k6
# * created: 13/06/2023 15:26:13 Hanoi, Vietnam
# **/
from collections import Counter
s = input()
n = len(s)
a = Counter(sorted(s))
odd = [[x, a[x]] for x in a if a[x] & 1]
x = len(odd)
for i in range(x // 2):
a[odd[i][0]] += 1
a[odd[x-i-1][0]] -= 1
codd = ''
s = ''
for x in a:
if a[x] & 1:
codd = x
s += x * (a[x] // 2)
print(s + codd + s[::-1])
|
Educational Codeforces Round 2
|
ICPC
| 2,015 | 2 | 256 |
Make Palindrome
|
A string is called palindrome if it reads the same from left to right and from right to left. For example "kazak", "oo", "r" and "mikhailrubinchikkihcniburliahkim" are palindroms, but strings "abb" and "ij" are not.
You are given string s consisting of lowercase Latin letters. At once you can choose any position in the string and change letter in that position to any other lowercase letter. So after each changing the length of the string doesn't change. At first you can change some letters in s. Then you can permute the order of letters as you want. Permutation doesn't count as changes.
You should obtain palindrome with the minimal number of changes. If there are several ways to do that you should get the lexicographically (alphabetically) smallest palindrome. So firstly you should minimize the number of changes and then minimize the palindrome lexicographically.
|
The only line contains string s (1 ≤ |s| ≤ 2·105) consisting of only lowercase Latin letters.
|
Print the lexicographically smallest palindrome that can be obtained with the minimal number of changes.
| null | null |
[{"input": "aabc", "output": "abba"}, {"input": "aabcd", "output": "abcba"}]
| 1,800 |
["constructive algorithms", "greedy", "strings"]
| 66 |
[{"input": "aabc\r\n", "output": "abba\r\n"}, {"input": "aabcd\r\n", "output": "abcba\r\n"}, {"input": "u\r\n", "output": "u\r\n"}, {"input": "ttttt\r\n", "output": "ttttt\r\n"}, {"input": "xxxvvvxxvv\r\n", "output": "vvvxxxxvvv\r\n"}, {"input": "wrwrwfrrfrffrrwwwffffwrfrrwfrrfrwwfwfrwfwfwffwrrwfrrrwwwfrrrwfrrfwrwwrwrrrffffwrrrwrwfffwrffrwwwrwww\r\n", "output": "fffffffffffffffrrrrrrrrrrrrrrrrrrwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwrrrrrrrrrrrrrrrrrrfffffffffffffff\r\n"}, {"input": "aabbcccdd\r\n", "output": "abcdcdcba\r\n"}, {"input": "baaab\r\n", "output": "ababa\r\n"}, {"input": "aaabbbhhlhlugkjgckj\r\n", "output": "aabbghjklclkjhgbbaa\r\n"}, {"input": "aabcc\r\n", "output": "acbca\r\n"}, {"input": "bbbcccddd\r\n", "output": "bbcdcdcbb\r\n"}, {"input": "zzzozzozozozoza\r\n", "output": "aoozzzzozzzzooa\r\n"}, {"input": "aaabb\r\n", "output": "ababa\r\n"}, {"input": "zza\r\n", "output": "zaz\r\n"}, {"input": "azzzbbb\r\n", "output": "abzbzba\r\n"}, {"input": "bbaaccddc\r\n", "output": "abcdcdcba\r\n"}, {"input": "aaabbbccc\r\n", "output": "aabcbcbaa\r\n"}, {"input": "aaaaabbccdd\r\n", "output": "aabcdadcbaa\r\n"}, {"input": "aaabbbcccdd\r\n", "output": "aabcdbdcbaa\r\n"}, {"input": "aaaabbcccccdd\r\n", "output": "aabccdcdccbaa\r\n"}, {"input": "aaacccb\r\n", "output": "aacbcaa\r\n"}, {"input": "abcd\r\n", "output": "abba\r\n"}, {"input": "abb\r\n", "output": "bab\r\n"}, {"input": "abababccc\r\n", "output": "aabcbcbaa\r\n"}, {"input": "aaadd\r\n", "output": "adada\r\n"}, {"input": "qqqqaaaccdd\r\n", "output": "acdqqaqqdca\r\n"}, {"input": "affawwzzw\r\n", "output": "afwzwzwfa\r\n"}, {"input": "hack\r\n", "output": "acca\r\n"}, {"input": "bbaaa\r\n", "output": "ababa\r\n"}, {"input": "ababa\r\n", "output": "ababa\r\n"}, {"input": "aaazzzz\r\n", "output": "azzazza\r\n"}, {"input": "aabbbcc\r\n", "output": "abcbcba\r\n"}, {"input": "successfullhack\r\n", "output": "accelsufuslecca\r\n"}, {"input": "aaabbccdd\r\n", "output": "abcdadcba\r\n"}, {"input": "zaz\r\n", "output": "zaz\r\n"}, {"input": "aaabbbcccdddeee\r\n", "output": "aabbcdecedcbbaa\r\n"}, {"input": "zaaz\r\n", "output": "azza\r\n"}, {"input": "acc\r\n", "output": "cac\r\n"}, {"input": "abbbzzz\r\n", "output": "abzbzba\r\n"}, {"input": "zzzzazazazazazznnznznnznnznznzaajzjajjjjanaznnzanzppnzpaznnpanz\r\n", "output": "aaaaaaajjjnnnnnnnnppzzzzzzzzzzznzzzzzzzzzzzppnnnnnnnnjjjaaaaaaa\r\n"}, {"input": "aaaaabbbcccdddd\r\n", "output": "aaabcddbddcbaaa\r\n"}, {"input": "aaaaabbccdddd\r\n", "output": "aabcddaddcbaa\r\n"}, {"input": "abababa\r\n", "output": "aabbbaa\r\n"}, {"input": "azz\r\n", "output": "zaz\r\n"}, {"input": "abbbccc\r\n", "output": "abcbcba\r\n"}, {"input": "aaacccddd\r\n", "output": "aacdcdcaa\r\n"}, {"input": "asbbsha\r\n", "output": "abshsba\r\n"}, {"input": "bababab\r\n", "output": "abbabba\r\n"}, {"input": "aaabbccddbbccddaaaaaaaaaaaaaaaa\r\n", "output": "aaaaaaaaabbccddaddccbbaaaaaaaaa\r\n"}, {"input": "aaabbccddbbccddaaaaaaaaaaaaaa\r\n", "output": "aaaaaaaabbccddaddccbbaaaaaaaa\r\n"}, {"input": "aaabbccddbbccddaaaaaaaaaaaa\r\n", "output": "aaaaaaabbccddaddccbbaaaaaaa\r\n"}, {"input": "ooooo\r\n", "output": "ooooo\r\n"}, {"input": "aaabbccddbbccddaaaaaaaaaa\r\n", "output": "aaaaaabbccddaddccbbaaaaaa\r\n"}, {"input": "aaabbccddbbccddaaaaaaaa\r\n", "output": "aaaaabbccddaddccbbaaaaa\r\n"}, {"input": "aaabbccddbbccddaa\r\n", "output": "aabbccddaddccbbaa\r\n"}]
| false |
stdio
| null | true |
40/D
|
40
|
D
|
Python 3
|
TESTS
| 15 | 124 | 307,200 |
30263955
|
A = int(input())
T = A
x = 0
while (A % 12 == 0):
A = A / 12
x = x + 1
b = [0] * 1000
b[1] = 2
b[2] = 13
for i in range(3, 603):
b[i] = 13 * b[i - 1] - 12 * b[i - 2]
y = 1
while (b[y] < A):
y = y + 1
if (b[y] != A):
print("NO")
else:
print("YES\n1")
t = 2 * x + y
print(t)
c = [0] * 1000
d = 0
for i in range((t - 1) // 2 + 1):
if (i != x and t - 2 * i != 0):
c[d] = b[t - 2 * i] * 12 ** i
d = d + 1
print(d)
for i in range(d):
print(c[d - i - 1])
| 74 | 156 | 1,843,200 |
220961106
|
from fractions import Fraction
import sys
def calculate_powers(limit):
powers = [1]
current_power = 1
for _ in range(limit):
current_power *= 12
powers.append(current_power)
return powers
def find_possible_sums(powers, target_sum):
results = []
for i in range(len(powers)):
for j in range(i + 1):
if powers[j] + powers[i - j] == target_sum:
results.append(i + 1)
break
return results
def find_distinct_sums(powers, result_indices, target_sum):
distinct_sums = set()
for i in result_indices:
for j in range(i):
current_sum = powers[j] + powers[i - 1 - j]
if current_sum != target_sum:
distinct_sums.add(current_sum)
return distinct_sums
def main():
sys.setrecursionlimit(1000 * 100)
A = int(input())
powers = calculate_powers(600)
result_indices = find_possible_sums(powers, A)
distinct_sums = find_distinct_sums(powers, result_indices, A)
if len(result_indices) == 0:
print('NO')
else:
print('YES')
print(min(len(result_indices), 1000))
print(' '.join(map(str, result_indices[:1000])))
print(min(len(distinct_sums), 1000))
if len(distinct_sums) > 0:
print(' '.join(map(str, sorted(distinct_sums)[:1000])))
if __name__ == "__main__":
main()
|
Codeforces Beta Round 39
|
CF
| 2,010 | 3 | 256 |
Interesting Sequence
|
Berland scientists noticed long ago that the world around them depends on Berland population. Due to persistent research in this area the scientists managed to find out that the Berland chronology starts from the moment when the first two people came to that land (it is considered to have happened in the first year). After one Berland year after the start of the chronology the population had already equaled 13 people (the second year). However, tracing the population number during the following years was an ultimately difficult task, still it was found out that if di — the number of people in Berland in the year of i, then either di = 12di - 2, or di = 13di - 1 - 12di - 2. Of course no one knows how many people are living in Berland at the moment, but now we can tell if there could possibly be a year in which the country population equaled A. That's what we ask you to determine. Also, if possible, you have to find out in which years it could be (from the beginning of Berland chronology). Let's suppose that it could be in the years of a1, a2, ..., ak. Then you have to define how many residents could be in the country during those years apart from the A variant. Look at the examples for further explanation.
|
The first line contains integer A (1 ≤ A < 10300). It is guaranteed that the number doesn't contain leading zeros.
|
On the first output line print YES, if there could be a year in which the total population of the country equaled A, otherwise print NO.
If the answer is YES, then you also have to print number k — the number of years in which the population could equal A. On the next line you have to output precisely k space-separated numbers — a1, a2, ..., ak. Those numbers have to be output in the increasing order.
On the next line you should output number p — how many variants of the number of people could be in the years of a1, a2, ..., ak, apart from the A variant. On each of the next p lines you have to print one number — the sought number of residents. Those number also have to go in the increasing order.
If any number (or both of them) k or p exceeds 1000, then you have to print 1000 instead of it and only the first 1000 possible answers in the increasing order.
The numbers should have no leading zeros.
| null | null |
[{"input": "2", "output": "YES\n1\n1\n0"}, {"input": "3", "output": "NO"}, {"input": "13", "output": "YES\n1\n2\n0"}, {"input": "1729", "output": "YES\n1\n4\n1\n156"}]
| 2,600 |
["math"]
| 74 |
[{"input": "2\r\n", "output": "YES\r\n1\r\n1\r\n0\r\n"}, {"input": "3\r\n", "output": "NO\r\n"}, {"input": "13\r\n", "output": "YES\r\n1\r\n2\r\n0\r\n"}, {"input": "1729\r\n", "output": "YES\r\n1\r\n4\r\n1\r\n156\r\n"}, {"input": "1\r\n", "output": "NO\r\n"}, {"input": "156\r\n", "output": "YES\r\n1\r\n4\r\n1\r\n1729\r\n"}, {"input": "144\r\n", "output": "NO\r\n"}, {"input": "15407021574586369\r\n", "output": "YES\r\n1\r\n16\r\n7\r\n465813504\r\n5162766336\r\n61917613056\r\n743008391424\r\n8916100449984\r\n106993205379216\r\n1283918464548876\r\n"}, {"input": "1283918464548876\r\n", "output": "YES\r\n1\r\n16\r\n7\r\n465813504\r\n5162766336\r\n61917613056\r\n743008391424\r\n8916100449984\r\n106993205379216\r\n15407021574586369\r\n"}, {"input": "106993205379216\r\n", "output": "YES\r\n1\r\n16\r\n7\r\n465813504\r\n5162766336\r\n61917613056\r\n743008391424\r\n8916100449984\r\n1283918464548876\r\n15407021574586369\r\n"}, {"input": "8916100449984\r\n", "output": "YES\r\n1\r\n16\r\n7\r\n465813504\r\n5162766336\r\n61917613056\r\n743008391424\r\n106993205379216\r\n1283918464548876\r\n15407021574586369\r\n"}, {"input": "743008391424\r\n", "output": "YES\r\n1\r\n16\r\n7\r\n465813504\r\n5162766336\r\n61917613056\r\n8916100449984\r\n106993205379216\r\n1283918464548876\r\n15407021574586369\r\n"}, {"input": "61917613056\r\n", "output": "YES\r\n1\r\n16\r\n7\r\n465813504\r\n5162766336\r\n743008391424\r\n8916100449984\r\n106993205379216\r\n1283918464548876\r\n15407021574586369\r\n"}, {"input": "5162766336\r\n", "output": "YES\r\n1\r\n16\r\n7\r\n465813504\r\n61917613056\r\n743008391424\r\n8916100449984\r\n106993205379216\r\n1283918464548876\r\n15407021574586369\r\n"}, {"input": "465813504\r\n", "output": "YES\r\n1\r\n16\r\n7\r\n5162766336\r\n61917613056\r\n743008391424\r\n8916100449984\r\n106993205379216\r\n1283918464548876\r\n15407021574586369\r\n"}, {"input": "4992931021747500841206051466436702562341442456351521960079288222881342911294018652359351672377890893353133194676518844879524186195771978689872074221947407400894730355500961665649091805184\r\n", "output": "YES\n1\n235\n117\n3674817562245760292710263796940459701960002416691229172368316120812071693424695751271795642761246455330619566192890989441449984 22202022771901468435124510439848610699341681267509509583058576563239599814440870163933765341682530667622493212415383061208760320 264599624264896983298377570684563586248418646232382011622922817351666426064402485396261202235902665778441173417159654333497737216 3175043437095603746420271135331961389802383627373773130860592133102729715130422495040889095008808014155208352244930440135222231040 38100508573973648285946565314576636540530383517867376652942565457639650965094869329681148695787194171930326416209083163967104221184 457206101831752646375434059749135730141606417213523694758862073813376386113099248571939657645753121563336235843614824457800620441600 5486473221893037495417214989987480102670547157812210601683307493120658347901521050914589714523729691385049190027470045701123726114816 65837678662709117089915913735932915510460838406350687742247770134727911984363613449979352726182647316006008143654981561097444403445760 790052143952508794007733409319201915648731250252258599617143914968174944796492141469669255726849925377020882545803557150892996148854784 9480625727430105477170196115537756898578375102141774057631574535730719337639916429308524153973253950989662989284804667345526259061882880 113767508729161265721798802986762027275506634567294177930097715058444683718352498046008330938116635315748073571312252839940882634182230016 1365210104749935188661232006641170072680460125919329542597715815753809208925786101626625474681602756114299559330738250481940138903973396480 16382521256999222263934754610594043017613386553624604461792301725300083257468229563275716154797916667732038268341774940483502462455496310784 196590255083990667167217052871370183056814627397044641037392596698288863485481987787954944729126556978981162849799042280360381282433273692160 2359083061007888006006604634251795668918896694493998141406701575045690350525439122874513199322147980161623679500063319280537771366946560802816 28308996732094656072079255611004494149713187097738766234293584768437136205363574080279079547080161536640638297775966065692804356068171002675200 339707960785135872864951067332052508640115447403182760522974114376903038797617747680497697994563137254246089085292859974507514864456786388189184 4076495529421630474379412807984629985251681802357386256751643630619141249265850877059068104553891080285499604816179425292939666922784664521277440 48917946353059565692552953695815559813151039664415234508559386422271053723164747016783241898698287416195540802443541862315180127119191243243913216 587015356236714788310635444349786717756990047475993364055007608971822757905641508909071771504717081865410618424709951411015486869100776191342673920 7044184274840577459727625332197440613083812034003837914489449221987253937636670152301167330449966451790849431829468371020788619541181854402146729984 84530211298086929516731503986369287357005738696737048102692503823374162321870789498063366804765710877274020016181366198423513665920179964501263646720 1014362535577043154200778047836431448284068863884902159993044971977117207451635369615964514893802373315270225763695373193263334843660992716654789001216 12172350426924517850409336574037177379408826366579164051813267574233458761052056593361507854828679633348907874628471059886841782361650148695077436784640 146068205123094214204912038888446128552905916398946663466083938216677176155260715133502255397619409862984033259330329933772741535359611637348864238813184 1752818461477130570458944466661353542634870996787359686163367652543949086448348251269790744866405856211041494008946348973200451769900323802603698782208000 21033821537725566845507333599936242511618451961448316211007941863356040951762280654376469245071451352687100686015438053492399384017602634310779162712866816 252405858452706802146088003199234910139421423537379794530182596529674879080679209655779212633080297988758091795344263464059958771776131507452644517331599360 3028870301432481625753056038390818921673057082448557534362031766203548747939778169352955683404648816011473175174394412137232102441610653080742008755043958784 36346443617189779509036672460689827060076684989382690412344367911763205825191640336692435295173092895483209441561921549860827945731019259884846627939449569280 436157323406277354108440069528277924720920219872592284948132413834268521639792542565680637466603557004410640910365490982014438908474872070527821412179971670016 5233887880875328249301280834339335096651042638471107419377588965918981430655634915665281934092953220907812034892021094482813642198340351592326328769235208110080 62806654570503938991615370012072021159812511661653289032531067591020090432115796021723142732823247862298318114034889400685317070988137709670081984549412126326784 753679854846047267899384440144864253917750139939839468390372811092240444624076900346822692754187958448530198509696225830464767632241656973587830984536161318338560 9044158258152567214792613281738371047013001679278073620684473733106885282108813416502384394713614583390774913878127839384097291818598550721182875745262537136930816 108529899097830806577511359380860452564156020151336883448213684797282623380857418549056988743368654924190000010851015166727377508509157497574038584270719495752908800 1302358789173969678930136312570325430769872241816042601378564217567391480569918327384602896254324299083905058550571638758571714269333721211631783350859264703210717184 15628305470087636147161635750843905169238466901792511216542770610808697766838989037348228007663049959006329457475222953166014169912606640476310010238612062334709923840 187539665641051633765939629010126862030861602821510134598513247329704373202067865873906485529674196038909242552608372378664099505507996517877114173699036488507867529216 2250475987692619605191275548121522344370339233858121615182158967956452478424814390272355138809233485511147018053209276622358521521642351283872152921958078840468689387520 27005711852311435262295306577458268132444070806297459382185907615477429741097772683250384775081897087220783892257003720141501368881003748162244733633294416167155462569984 324068542227737223147543678929499217589328849675569512586230891385729156893173272199003127560097022985073325013385585675087449685790486272343251711813682783179326483333120 3888822506732846677770524147153990611071946196106834151034770696628749882718079266388037406576090463982415226686152156520498515667754038709318713450782039213916372877705216 46665870080794160133246289765847887332863354353282009812417248359544998592616951196656448868567662750135777330777619638947602947966237481465257869151802624384976845788938240 559990440969529921598955477190174647994360252239384117749006980314539983111403414359877386421949834433491560853543418480763037105590948862329213872133499672104553847071965184 6719885291634359059187465726282095775932323026872609412988083763774479797336840972318528637063326169987887249649538687003605762077924394605012743085794651746878382139663974400 80638623499612308710249588715385149311187876322471312955857005165293757568042091667822343644759908052920146039078382382812806588002662152614908098414551875602675897007201058816 967663481995347704522995064584621791734254515869655755470284061983525090816505100013868123737118896136130544055880915105317807176287576616158460112756707178452122040030682152960 11611961783944172454275940775015461500811054190435869065643408743802301089798061200166417484845426753591990594636149341806444030125472221959299818264062326530693798753363541622784 139343541407330069451311289300185538009732650285230428787720904925627613077576734401997009818145121043100422474464256965055880890173168438725381010577996405067431279563112112455680 1672122496887960833415735471602226456116791803422765145452650859107531356930920812823964117817741452517204780971806955652618783392800313079305720726220060901367434162634241150550016 20065469962655530000988825659226717473401501641073181745431810309290376283171049753887569413812897430206457347601536457170754418439497281269552077764581072819789064852267301790023680 240785639551866360011865907910720609680818019692878180945181723711484515398052597046650832965754769162477488169213425235160663772751125168927781885595801235671083766135595655478902784 2889427674622396320142390894928647316169816236314538171342180684537814184776631164559809995589057229949729858030394018467687266168969931843274479039851350524872473109286180201913384960 34673132095468755841708690739143767794037794835774458056106168214453770217319573974717719947068686759396758296364714297916060469102302217937305506512608017606537966304405748450974498816 416077585145625070100504288869725213528453538029293496673274018573445242607834887696612639364824241112761099556376570414684710068817181868232500391320828862220794619735616613580695142400 59915172260970010094472617597240430748097309476218263520951458674576114935528223828312220068534690720237598336118226138546232539796760893967721729790543677231923863842567670179679164170240 718982067131640121133671411166885168977167713714619162251417504094913379226338685939746640822416288642851180033418713662554119003015088823420098827413788692484851957742191719672140808585216 8627784805579681453604056934002622027726012564575429947017010049138960550716064231276959689868995463714214160401024563950649372079968895722358472434792736356960037292208915609192022272901120 103533417666956177443248683208031464332712150774905159364204120589667526608592770775323516278427945564570569924812294767407792460296609067821744776426331775620782265323115538558064794988969984 1242401012003474129318984198496377571992545809298861912370449447076010319303113249303882195341135346774846839097747537208893509523170724007123724242716716219060825668695437175300757583843819520 14908812144041689551827810381956530863910549711586342948445393364912123831637358991646586344093624161298162069172970446506722114278016306018256589823067322538030861231413416996326089343123849216 178905745728500274621933724583478370366926596539036115381344720378945485979648307899759036129123489935577944830075645358080665371336192973713476736119346764448812080877550018196972821978902691840 2146868948742003295463204695001740444403119158468433384576136644547345831755779694797108433549481879226935337960907744296967984456034315459686253971619039414551781782705649302883762176235283677184 25762427384904039545558456340020885332837429901621200614913639734568149981069356337565301202593782550723224055530892931563615813472411785497495425420944046161385217793482379058315153474197441740800 309149128618848474546701476080250623994049158819454407378963676814817799772832276050783614431125390608678688666370715178763389761668941425968383469864788185035519599888539764318424342303650470690816 3709789543426181694560417712963007487928589905833452888547564121777813597273987312609403373173504687304144263996448582145160677140027297111620471502111913189684476614193039773122645649361579079106560 44517474521114180334725012555556089855143078870001434662570769461333763167287847751312840478082056247649731167957382985741928125680327565339445647180654162856985239488277357494246877254148763401846784 534209694253370164016700150666673078261716946440017215950849233536005158007454173015754085736984674971796774015488595828903137508163930784073347765264125887998887167202491696615693787838269312026542080 6410516331040441968200401808000076939140603357280206591410190802432061896089450076189049028843816099661561288185863149946837650097967169408880173183094200317129568030875163976612053059124938756918870016 76926195972485303618404821696000923269687240287362479096922289629184742753073400914268588346125793195938735458230357799362051801175606032906562078197124127943983393205872406354113280676588074000743137280 923114351669823643420857860352011079236246883448349749163067475550216913036880810971223060153509518351264825498764293592344621614107272394878744938365489012339336433206749746135590088449647622085394038784 11077372220037883721050294324224132950834962601380196989956809706602602956442569731654676721842114220215177905985171523108135459369287268738544939260385868104489665174709020359450933621423320692864434831360 132928466640454604652603531890689595410019551216562363879481716479231235477310836779856120662105370642582134871822058277297625512431447224862539271124630417250244117761193912930563191170415477416693193506816 1595141599685455255831242382688275144920234614598748366553780597750774825727730041358273447945264447710985618461864699327571506149177366698350471253495565007002626757773050760884854293021097031425511653376000 19141699196225463069974908592259301739042815375184980398645367173009297908732760496299281375343173372531827421542376391930858073790128400380205655041946780084031495871996502781094759516167840318974905951453184 229700390354705556839698903107111620868513784502219764783744406076111574904793125955591376504118080470381929058508516703170296885481540804562467860503361361008377948362184691177343489860673640156187935260016640 2756404684256466682076386837285339450422165414026637177404932872913338898857517511467096518049416965644583148702102200438043562625778489654749614326040336332100535380171068515611805742966971978234962645107081216 33076856211077600184916642047424073405065984968319646128859194474960066786290210137605158216593003587734997784425226405256522751509341875856995371912484035985206424562038226539131975904323571096849610693117214720 396922274532931202218999704569088880860791819619835753546310333699520801435482521651261898599116043052819973413102716863078273018112102510283944462949808431822477094744457502165566236434276178775364499896725929984 4763067294395174426627996454829066570329501835438029042555724004394249617225790259815142783189392516633839680957232602356939276217345230123407333555397701181869725136933489924628126714343180255772138096392321105920 57156807532742093119535957457948798843954022025256348510668688052730995406709483117781713398272710199606076171486791228283271314608142761480888002664772414182436701643201879087090964895212485245137970831510487433216 685881690392905117434431489495385586127448264303076182128024256632771944880513797413380560779272522395272914057841494739399255775297713137770656031977268970189240419718422549044387699102807683122978342784359402045440 8230580284714861409213177873944627033529379171636914185536291079593263338566165568960566729351270268743274968694097936872791069303572557653247872383727227642270885036621070588532593732597047019157517004479498953949184 98766963416578336910558134487335524402352550059642970226435492955119160062793986827526800752215243224919299624329175242473492831642870691838974468604726731707250620439452847062391119903111510465030352128009586291507200 1185203560998940042926697613848026292828230600715715642717225915461429920753527841930321609026582918699031595491950102909681913979714448302067693623256720780487007445273434164748693438430000371099959237875636335401762816 14222442731987280515120371366176315513938767208588587712606710985537159049042334103163859308318995024388379145903401234916182967756573379624812323479080649365844089343281209976984321261126059640326143772202596133146460160 170669312783847366181444456394115786167265206503063052551280531826445908588508009237966311699827940292660549750840814818994195613078880555497747881748967792390129072119374519723811855133509886949507611342905733606784630784 2048031753406168394177333476729389434007182478036756630615366381917350903062096110855595740397935283511926597010089777827930347356946566665972974580987613508681548865432494236685742261602118407666224159954575018282167828480 24576381040874020730128001720752673208086189736441079567384396583008210836745153330267148884775223402143119164121077333935164168283358799991675694971851362104178586385189930840228907139225420872350700988108209070636076630016 294916572490488248761536020649032078497034276837292954808612758996098530040941839963205786617302680825717429969452928007221970019400305599900108339662216345250143036622279170082746885670705050466571412779686284585237091450880 3538998869885858985138432247788384941964411322047515457703353107953182360491302079558469439407632169908609159633435136086663640232803667198801300075946596143001716439467350040992962628048460605598720536766434396334312111734784 42467986438630307821661186973460619303572935864570185492440237295438188325895624954701633272891586038903309915601221633039963682793644006385615600911359153716020597273608200491915551536581527267184635073148062671121034258677760 509615837263563693859934243681527431642875230374842225909282847545258259910747499456419599274699032466839718987214659596479564193523728076627387210936309844592247167283298405902986618438978327206215619930439322879711518513954816 6115390047162764326319210924178329179714502764498106710911394170543099118928969993477035191296388389602076627846575915157754770322284736919528646531235718135106966007399580870835839421267739926474587439086327088792059814451609600 73384680565953171915830531090139950156574033173977280530936730046517189427147639921724422295556660675224919534158910981893057243867416843034343758374828617621283592088794970450030073055212879117695049269029346333357677906109661184 880616166791438062989966373081679401878888398087727366371240760558206273125771679060693067546679928102699034409906931782716686926409002116412125100497943411455403105065539645400360876662554549412340591228351607772613214884373463040 10567394001497256755879596476980152822546660777052728396454889126698475277509260148728316810560159137232388412918883181392600243116908025396945501205975320937464837260786475744804330519950654592948087094740219247585718668613403017216 126808728017967081070555157723761833870559929324632740757458669520381703330111121784739801726721909646788660955026598176711202917402896304763346014471703851249578047129437708937651966239407855115377045136882630967221487364194246328320 1521704736215604972846661892685142006446719151895592889089504034244580439961333461416877620720662915761463931460319178120534435008834755657160152173660446214994936565553252507251823594872894261384524541642591571606340586982067073449984 18260456834587259674159942712221704077360629822747114669074048410934965279536001537002531448647954989137567177523830137446413220106017067885921826083925354579939238786639030087021883138474731136614294499711098859276060605335782891192320 219125482015047116089919312546660448928327557872965376028888580931219583354432018444030377383775459869650806130285961649356958641272204814631061913007104254959270865439668361044262597661696773639371533996533186311312725060825309528457216 2629505784180565393079031750559925387139930694475584512346662971174635000253184221328364528605305518435809673563431539792283503695266457775572742956085251059511250385276020332531151171940361283672458407958398235735752700546303373910999040 31554069410166784716948381006719104645679168333707014148159955654095620003038210655940374343263666221229716082761178477507402044343197493306872915473023012714135004623312243990373814063284335404069500895500778828829032406540340458562781184 378648832922001416603380572080629255748150020004484169777919467849147440036458527871284492119163994654756592993134141730088824532118369919682474985676276152569620055479746927884485768759412024848834010746009345945948388878482810500389273600 4543785995064016999240566864967551068977800240053810037335033614189769280437502334455413905429967935857079115917609700761065894385420439036189699828115313830835440665756963134613829225112944298186008128952112151351380666541793619754474274816 54525431940768203990886802379610612827733602880645720448020403370277231365250028013464966865159615230284949391011316409132790732625045268434276397937383765970025287989083557615365950701355331578232097547425345816216567998501523428199508213760 654305183289218447890641628555327353932803234567748645376244840443326776383000336161579602381915382763419392692135796909593488791500543221211316775248605191640303455869002691384391408416263978938785170569104149794598815982018281137656249974784 7851662199470621374687699542663928247193638814812983744514938085319921316596004033938955228582984593161032712305629562915121865498006518654535801302983262299683641470428032296612696900995167747265422046829249797535185791784219373651813512314880 94219946393647456496252394511967138966323665777755804934179257023839055799152048407267462742995815117932392547667554754981462385976078223854429615635799147596203697645136387559352362811942012967185064561950997570422229501410632483821757023830016 1130639356723769477955028734143605667595883989333069659210151084286068669589824580887209552915949781415188710572010657059777548631712938686253155387629589771154444371741636650712228353743304155606220774743411970845066754016927589805861083858964480 13567672280685233735460344809723268011150607871996835910521813011432824035077894970646514634991397376982264526864127884717330583580555264235037864651555077253853332460899639808546740244919649867274649296920943650140801048203131077670333006271990784 162812067368222804825524137716679216133807294463962030926261756137193888420934739647758175619896768523787174322369534616607967002966663170820454375818660927046239989530795677702560882939035798407295791563051323801689612578437572932043996075260924160 1953744808418673657906289652600150593605687533567544371115141073646326661051216875773098107438761222285446091868434415399295604035599958049845452509823931124554879874369548132430730595268429580887549498756615885620275350941250875184527952903130842816 23444937701024083894875475831201807123268250402810532453381692883755919932614602509277177289265134667425353102421212984791547248427199496598145430117887173494658558492434577589168767143221154970650593985079390627443304211295010502214335434837570093200 281339252412289006738505709974421685479219004833726389440580314605071039191375230111326127471181616009104237229054555817498566981126393959177745161414646081935902701909214931070025205718653859647807127820952687529319650535540126026572025218050841116684 3376071028947468080862068519693060225750628058004716673286963775260852470296502761335913529654179392109250846748654669809982803773516727510132941936975752983230832422910579172840302468623846315773685533851432250351835806426481512318864302616610093400065\n"}, {"input": "6028801175788581229286833472784603286740565840936227676140782146528792478220288\r\n", "output": "YES\n1\n90\n44\n3962033820342906963106922494542950070196390330368 43912541508800552174435057647851029944676659494912 526647842744330431811316690750323661761313245233152 6319748891651858832212308288918559883004525053739008 75836984598048963790754075133682274924543364487446528 910043815001439786972732766243075595455227795836239872 10920525780002681795463100183636814503492792501867118592 131046309360030965241539727786035099655082681601724776448 1572555712320371481539808610564287306328756276852307263488 18870668547844457770031147649865769851817388997030321324032 226448022574133493239669892158647098403131360770597408735232 2717376270889601918875980049267120002519353220314355034226688 32608515250675223026511755703152386265372386718027859254837248 391302183008102676318141068030490880704063652955855610961723392 4695626196097232115817692816331945755575396753165227439865987072 56347514353166785389812313795980520332498647114457309287418953728 676170172238001424677747765551766008262116589213193926449779703808 8114042066856017096132973186621192079501410139211635968647419133952 97368504802272205153595678239454304952379922592927407361373201498112 1168422057627266461843148138873451659428422654525327869647945432301568 14021064691527197542117777666481419913141060486254784350884634105479168 168252776298326370505413331997777038957692724887719983036874716675571712 2019033315579916446064959983973324467492312698573695010678018192391012352 24228399786958997352779519807679893609907752382877761395989178441382494208 290740797443507968233354237692158723318893028594532588524191221307647459328 3488889569322095618800250852305904679826716343134391016604654745692690972672 41866674831865147425603010227670856157920596117612692195448720289145701793792 502400097982381769107236122732050273895047153411352306345067382081484539035648 72345614109462974751442001673415239440886790091234732113689383555141424572792832 868147369313555697017304020080982873290641481094816785364272602478096754443026432 10417768431762668364207648240971794479487697773137801424371271229721861024947109888 125013221181152020370491778891661533753852373277653617092455254756661057297001218048 1500158654173824244445901346699938405046228479331843405109463057079932581313817608192 18001903850085890933350816160399260860554741751982120861313556684959190966911628214272 216022846201030691200209793924791130326656901023785450335762680219510291602201689980928 2592274154412368294402517527097493563919882812285425404029152162634123499226358792388608 31107289852948419532830210325169922767038593747425104848349825951609481990716300384714752 373287478235381034393962523902039073204463124969101258180197911419313783888595604189581312 4479449738824572412727550286824468878453557499629215098162374937031765406663147250239392768 53753396865894868952730603441893626541442689995550581177948499244381184879957767002869747968 645040762390738427432767241302723518497312279946606974135381990932574218559493204034436728512 7740489148688861129193206895632682221967747359359283689624583891190890622713918448413240721552 92885869784266333550318482747592186663612968312311404275495006694290687472567021380958888656908 1114630437411196002603821792971106239963355619747736851305940080331488249670804256571506663882753\n"}, {"input": "13375565248934352031245861515653274879560267436972842215671285886213101948076355115971323088601088\r\n", "output": "YES\n1\n125\n62\n16228084133712034192265946373242384158728079174488353179969664319488 98044674974510206578273426005006070958982145012533800462316721930240 1168478405141619628628537951187247639928972839726961735739690725670912 14021069387153393639349893484174236244849439668354920506392279546593280 168252776689628553513516008315918106985335089819561661049833687128997888 2019033315612524961315635206999836223161282895651348483845764773262131200 24228399786961714729050409409598769589546833232634232518753157323121754112 290740797443508194681376811825651962983862951998678961117754886214459064320 3488889569322095637670919400150362449798797170084736547654118384434925273088 41866674831865147427175565939991227638751602853191887656369508925707554652160 502400097982381769107367169041410304851783070639317239300144114467864693440512 6028801175788581229286844393310383289320293834038558087220371874227657491087360 72345614109462974751442002583459054441101767423993259647946016032449663323865088 868147369313555697017304020156819857873992729205879995992127321851205774338949120 10417768431762668364207648240978114228202977043813723358590259123002953443271770112 125013221181152020370491778891662060399578646550209943920306837081101148331861606400 1500158654173824244445901346699938448933372335437889765678450688940302588900055973888 18001903850085890933350816160399260864212003739990958058027638987614221800877148078080 216022846201030691200209793924791130326961672856119520102155520411398210838365483302912 2592274154412368294402517527097493563919908209938119909843018232650114159162705775165440 31107289852948419532830210325169922767038595863896162723834314790777481212377662633279488 373287478235381034393962523902039073204463125145473846336488285489244450490400717710295040 4479449738824572412727550286824468878453557499643912813842065801537592962213297676366118912 53753396865894868952730603441893626541442689995551805987588473483090003842920279538380308480 645040762390738427432767241302723518497312279946607076202851988785799953473073413412395941888 7740489148688861129193206895632682221967747359359283698130206391011992767290050132528070656000 92885869784266333550318482747592186663612968312311404276203808569275779317948365687968457818112 1114630437411196002603821792971106239963355619747736851305999147154403673991252701930424127979520 160506782987212224374950338187839298554723209243674106588055371977920578198598038282723063192616960 1926081395846546692499404058254071582656678510924089279056664458846993884618316607466932357155520512 23112976750158560309992848699048858991880142131089071348679973505756588860939394301942709585769922560 277355721001902723719914184388586307902561705573068856184159682069045121518399364541007475137564377088 3328268652022832684638970212663035694830740466876826274209916184828538629486386260568564281659799633920 39939223824273992215667642551956428337968885602521915290518994217942463318108767950662477594918347866112 479270685891287906588011710623477140055626627230262983486227930615309559797661226476603039990270237081600 5751248230695454879056140527481725680667519526763155801834735167383714717570297718641624255620847016869888 69014978768345458548673686329780708168010234321157869622016822008604576610843436207109690048761631216762880 828179745220145502584084235957368498016122811853894435464201864103254919330121223117267130500248863519014912 9938156942641746031009010831488421976193473742246733225570422369239059031961454676459868136829245469638000640 119257883311700952372108129977861063714321684906960798706845068430868708383537456117439472856186467227940159488 1431094599740411428465297559734332764571860218883529584482140821170424500602449473409267095542090566867972259840 17173135196884937141583570716811993174862322626602355013785689854045094007229393680911204598277407882426724646912 206077622362619245699002848601743918098347871519228260165428278248541128086752724170934455133643254679121617223680 2472931468351430948388034183220927017180174458230739121985139338982493537041032690051213461599911919490292816805888 29675177620217171380656410198651124206162093498768869463821672067789922444492392280614561539198625772495249919180800 356102131442606056567876922383813490473945121985226433565860064813479069333908707367374738470383482831493977039962112 4273225577311272678814523068605761885687341463822717202790320777761748832006904488408496861644601791774723639313694720 51278706927735272145774276823269142628248097565872606433483849333140985984082853860901962339735221501113083331333849088 615344483132823265749291321879229711538977170790471277201806191997691831808994246330823548076822658013341699947636981760 7384133797593879188991495862550756538467726049485655326421674303972301981707930955969882576921871896160099124369279680512 88609605571126550267897950350609078461612712593827863917060091647667623780495171471638590923062462753921189386181159157760 1063315266853518603214775404207308941539352551125934367004721099772011485365942057659663091076749553047054272625319726809088 12759783202242223238577304850487707298472230613511212404056653197264137824391304691915957092920994636564651271503098873118720 153117398426906678862927658205852487581666767362134548848679838367169653892695656302991485115051935638775815258037124990042112 1837408781122880146355131898470229850980001208345614586184158060406035846712347875635897821380623227665309783096445494756556800 22048905373474561756261582781642758211760014500147375034209896724872430160548174507630773856567478731983717397157345936651685888 264586864481694741075138993379713098541120174001768500410518760698469161926578094091569286278809744783804608765888151239784647680 3175042373780336892901667920556557182493442088021222004926225128381629943118937129098831435345716937405655305190657814877412806912 38100508485364042714820015046678686189921305056254664059114701540579559317427245549185977224148603248867863662287893778528953435840 457206101824368512577840180560144234279055660675055968709376418486954711809126946590231726689783238986414363947454725342347441209488 5486473221892422150934082166721730811348667928100671624512517021843456541709523359082780720277398867836972367369456704108169294512140 65837678662709065811208986000660769736184015137208059494150204262121478500514280308993368643328786414043668408433480449298031534145537\n"}, {"input": "2473050726234742649340406291350904878243888779915646082783846184050924405749416227507330900520680043711803454128128\r\n", "output": "YES\n1\n209\n104\n34346270393769874283167141433623986349724645253204710027571379708090188014458787361822409188887295779958499049472 207508716962359657127468146161478250862919731738111789749910419069711552587355173644343722182860745337249265090560 29675187558374114022402441207661955694584069692242611710554897638212291683551424242069237992442023116180375805624320 356102132270785801788022424967897726431313620001349245419754500277680933437163626697495961508153765943467737530499072 4273225577380287657582868527154435572017122171990727437111478647383765654015509065019340296897749315367388119354572800 51278706927741023394004972278148198768775579291553273953010612488942820719250237575619532626006317128079138704670588928 615344483132823745019977213167136299550687794267611332828433422260675318036924861640383345600678582648922204562081710080 7384133797593879228930719686824748754135368601442083664390559906494217272226925173912345893382193223213064166420483407872 88609605571126550271226219002631911146251682806490899611890832114544450054705087656467129532767489531175603139685426135040 1063315266853518603215052759928310844263072465310322953312623661477584554222126217341732135960891638611825473771445082390528 12759783202242223238577327963464457457032540606359911452915645077406268913462653371889462846661339810361715538265275986083840 153117398426906678862927660131933883428213459861538607102751421023848164816784935359655943927863631069925570613600639749455872 1837408781122880146355131898630736633967213432720564924371997358960759055956021982223953192948357535617905596042742454319841280 22048905373474561756261582781656133777008948852178620895725549999751990427985147349846445137531456590979767048236204016615292928 264586864481694741075138993379714213171557585197771104232311731804709125282197841828420592218890076272054279570144722746448281600 3175042373780336892901667920556557275379311872287555555244707875973816606731905441410235710840723631696342777757679195836301443072 38100508485364042714820015046678686197661794204943525188307908436212241539394992908545260913773187140058754285001812226942194155520 457206101824368512577840180560144234279700701437446707136809185728257435327624258870178333663918620977346938166014218546381877936128 5486473221892422150934082166721730811348721681497537519381469752446898435336064801772776270858576816336216748554336661875172164239360 65837678662709065811208986000660769736184019616657798318722616989671765324983158762550868272543884576418605440198887112445281773289472 790052143952508789734507832007929236834208182019784192165183485539420265908210436912383548689046695148721932320515549280171982596341760 9480625727430105476814093984095150842010498179789067857010577833278323114399226287262083678386770348470638076766030666689632841265840128 113767508729161265721769127809141810104125978157098119080045965333240317366415773867504460898484428348871488161935688339886224849365893120 1365210104749935188661229533709701721249511737885146537693544836610042178396458041278416818844966738867059843879956870106935584088572035072 16382521256999222263934754404516420654994140854621755878050287477038102671590785558246698766811530332961434958720876492118918749554212864000 196590255083990667167217052854197047859929690255461070322080762177600365103325534120869193280127691451083612573997300742996665973024833404928 2359083061007888006006604634250364574319156283065532843847092255502299642326926085068922720034731408034298883643746507485757461757829190778880 28308996732094656072079255611004374891829875396786394126163617325141853646347031327128613673806210155630027898121272998043239330267411221839872 339707960785135872864951067332052498701958504761436729513963283756628431917699702451068492505123641305828538218654968885536717778973389739786240 4076495529421630474379412807984629984423502057137240754167559394734118365359191039956615670763104455623131475577292934368858767165661048133910528 48917946353059565692552953695815559813082024685646889050010712735947301816172525363691370862549055197473676791673634654738173385472764275211632640 587015356236714788310635444349786717756984296227762668600128552831295778580058823771314115585037979180517129757145792477050736307296907277339983872 7044184274840577459727625332197440613083811554733152023201542633975543356026204928539687525789993193233774974440504691109624890327698198659313172480 84530211298086929516731503986369287357005738656797824278418511607706519773403250729416576821044046439060930478065619225097583355152389659856027516928 1014362535577043154200778047836431448284068863881573891341022139292478237239263074718577282395158901278752468302185727612152840651097010191267685990400 12172350426924517850409336574037177379408826366578886696092265671509738846867692235453392252120459344012531394840011922755082574512269816817961844867072 146068205123094214204912038888446128552905916398946640353107188058116866162412018103676579097393724838872668552681291672345094934705496609692437939486720 1752818461477130570458944466661353542634870996787359684237286256697402393948944193183971938508053715792365546950058929118081481219845814216965663257264128 21033821537725566845507333599936242511618451961448316210847435080368828727387330316202651011208255340985544357093864101837806136471764758511975993085788160 252405858452706802146088003199234910139421423537379794530169220964425944728647963794264727780258364987782962101267465634755409334480645017802744253196009472 3028870301432481625753056038390818921673057082448557534362030651573111336743775565531162809666913654928058581033221345651456723321836029206604517066365992960 36346443617189779509036672460689827060076684989382690412344367818877336040925306786373952555694948298726258225383490460987013330804371374562001836965393072128 436157323406277354108440069528277924720920219872592284948132413826528032491103681436487430571647044954680894975683955057941621023897651413417584346265466961920 5233887880875328249301280834339335096651042638471107419377588965918336389893244177237849166851706844903667889397464299822474240707958916537567142347075666051072 62806654570503938991615370012072021159812511661653289032531067591020036678718930126854190002219810664297972768577009667796955454197272590082185385680898831155200 753679854846047267899384440144864253917750139939839468390372811092240440144627161522250280026637672015363503064241402519390737497509084880288839601297118543740928 9044158258152567214792613281738371047013001679278073620684473733106885281735525938267003360319652059521344355924339937441507789307370836380074626463325950239047680 108529899097830806577511359380860452564156020151336883448213684797282623380826311259204040323835824713867547464354866174898828383299888521378946230163891446844751872 1302358789173969678930136312570325430769872241816042601378564217567391480569915735110448483886029896566378187505030293009252668508899615463615525654683695699135037440 15628305470087636147161635750843905169238466901792511216542770610808697766838988821325381806632358758796535551554761174353570916099237131663975322097264098251036950528 187539665641051633765939629010126862030861602821510134598513247329704373202067865855904581679588305105558426393781667230429729234356882392142752949687257491500894781440 2250475987692619605191275548121522344370339233858121615182158967956452478424814390270854980155059661266701116706640384526672323999046425106727622819957097257384774991872 27005711852311435262295306577458268132444070806297459382185907615477429741097772683250259761860715935200413400478122979133527519087454087647482689458127667701898469703680 324068542227737223147543678929499217589328849675569512586230891385729156893173272199003117142328591222404960805737345613336785198307690467300354874799085554140555067260928 3888822506732846677770524147153990611071946196106834151034770696628749882718079266388037405707943094668859529668848136515352626960463805725565138714364156111496475259699200 46665870080794160133246289765847887332863354353282009812417248359544998592616951196656448868495317136026314356026177637280507457240629962049945071257101134126441854320771072 559990440969529921598955477190174647994360252239384117749006980314539983111403414359877386421943805632315772272314131647290779148030481569044604472308941214583009264449617920 6719885291634359059187465726282095775932323026872609412988083763774479797336840972318528637063325667587789267267769579767483073914794355663905692302475938542084920091112112128 80638623499612308710249588715385149311187876322471312955857005165293757568042091667822343644759908011053471207213234957209796363989067982703149177515941982835609775169821736960 967663481995347704522995064584621791734254515869655755470284061983525090816505100013868123737118896132641654486558819486517556324286443768665813536015156354054866529877567209472 11611961783944172454275940775015461500811054190435869065643408743802301089798061200166417484845426753591699853838705833838210675887805460888675431049333863961994027460850782044160 139343541407330069451311289300185538009732650285230428787720904925627613077576734401997009818145121043100398246064470006058528110653362875302828978310102366520039631955402715824128 1672122496887960833415735471602226456116791803422765145452650859107531356930920812823964117817741452517204778952773640072702337327840329282353841390197736398155151525333598700830720 20065469962655530000988825659226717473401501641073181745431810309290376283171049753887569413812897430206457347433283680872428047934083949286472754486579212444521374632492248252547072 240785639551866360011865907910720609680818019692878180945181723711484515398052597046650832965754769162477488169199404170469136575209007391262525275322634413973144791950614401017446400 2889427674622396320142390894928647316169816236314538171342180684537814184776631164559809995589057229949729858030392850045629638902508088695135707655661919956397644861437431764041596928 34673132095468755841708690739143767794037794835774458056106168214453770217319573974717719947068686759396758296364714200547555666830097064341627275563925565059165063950418352747818516480 416077585145625070100504288869725213528453538029293496673274018573445242607834887696612639364824241112761099556376570406570668001961164772099527205408438657841846877872784330605432143872 4992931021747500841206051466436702562341442456351521960079288222881342911294018652359351672377890893353133194676518844878848016023533977265194326456454708217196484710345725642067819888640 59915172260970010094472617597240430748097309476218263520951458674576114935528223828312220068534690720237598336118226138546176192282407727182331917476752618966615676705471400511047391510528 718982067131640121133671411166885168977167713714619162251417504094913379226338685939746640822416288642851180033418713662554114307388892726187983009720972770962742942147433697199754827530240 8627784805579681453604056934002622027726012564575429947017010049138960550716064231276959689868995463714214160401024563950649371688666712714255796116651668363499861540909352440652656774479872 103533417666956177443248683208031464332712150774905159364204120589667526608592770775323516278427945564570569924812294767407792460264000552571069553399820019954660584010507241627353181197434880 1242401012003474129318984198496377571992545809298861912370449447076010319303113249303882195341135346774846839097747537208893509523168006630852834640797840239421982195252719817223198282694524928 14908812144041689551827810381956530863910549711586342948445393364912123831637358991646586344093624161298162069172970446506722114278016079570234015689574082873060957608626523883152959401361408000 178905745728500274621933724583478370366926596539036115381344720378945485979648307899759036129123489935577944830075645358080665371336192954842808188274888994476731255575651110437541727817089155072 2146868948742003295463204695001740444403119158468433384576136644547345831755779694797108433549481879226935337960907744296967984456034315458113698259298667933720775047263824393903809585055132549120 25762427384904039545558456340020885332837429901621200614913639734568149981069356337565301202593782550723224055530892931563615813472411785497364379111584015204649300565528893649233490758265762480128 309149128618848474546701476080250623994049158819454407378963676814817799772832276050783614431125390608678688666370715178763389761668941425968372549339008182455791606786210307201000870410656164085760 3709789543426181694560417712963007487928589905833452888547564121777813597273987312609403373173504687304144263996448582145160677140027297111620470592068098189469499281434512318362860360037162886889472 44517474521114180334725012555556089855143078870001434662570769461333763167287847751312840478082056247649731167957382985741928125680327565339445647104817178273633991377214146873016895146705062052495360 534209694253370164016700150666673078261716946440017215950849233536005158007454173015754085736984674971796774015488595828903137508163930784073347765257806139283607896526569762397257955995982336914096128 6410516331040441968200401808000076939140603357280206591410190802432061896089450076189049028843816099661561288185863149946837650097967169408880173183093673671403294758318837148760516739804748175659499520 76926195972485303618404821696000923269687240287362479096922289629184742753073400914268588346125793195938735458230357799362051801175606032906562078197124084056839537099826045785125652649978058118971523072 923114351669823643420857860352011079236246883448349749163067475550216913036880810971223060153509518351264825498764293592344621614107272394878744938365489008682074445197912549421507786114096787428579737600 11077372220037883721050294324224132950834962601380196989956809706602602956442569731654676721842114220215177905985171523108135459369287268738544939260385868104184893342374950593058093429562024789976366972928 132928466640454604652603531890689595410019551216562363879481716479231235477310836779856120662105370642582134871822058277297625512431447224862539271124630417250218720108499407116697121154427036091452521185280 1595141599685455255831242382688275144920234614598748366553780597750774825727730041358273447945264447710985618461864699327571506149177366698350471253495565007002624641301992885400365453853097994648408264015872 19141699196225463069974908592259301739042815375184980398645367173009297908732760496299281375343173372531827421542376391930858073790128400380205655041946780084031495695623914624804385446237173732576814002339840 229700390354705556839698903107111620868513784502219764783744406076111574904793125955591376504118080470381929058508516703170296885481540804562467860503361361008377948347486975497652625354846084607321427597590528 2756404684256466682076386837285339450422165414026637177404932872913338898857517511467096518049416965644583148702102200438043562625778489654749614326040336332100535380169843705971831504258153015272557102801879040 33076856211077600184916642047424073405065984968319646128859194474960066786290210137605158216593003587734997784425226405256522751509341875856995371912484035985206424562038124471661978051097836183269410231258447872 396922274532931202218999704569088880860791819619835753546310333699520801435482521651261898599116043052819973413102716863078273018112102510283944462949808431822477094744457493659943736613174034199232816524904366080 4763067294395174426627996454829066570329501835438029042555724004394249617225790259815142783189392516633839680957232602356939276217345230123407333555397701181869725136933489923919324839358088410390793789444669308928 57156807532742093119535957457948798843954022025256348510668688052730995406709483117781713398272710199606076171486791228283271314608142761480888002664772414182436701643201879087031898072297060924689525472598183116800 685881690392905117434431489495385586127448264303076182128024256632771944880513797413380560779272522395272914057841494739399255775297713137770656031977268970189240419718422549044382776867564731096274305671116710019072 8230580284714861409213177873944627033529379171636914185536291079593263338566165568960566729351270268743274968694097936872791069303572557653247872383727227642270885036621070588532593322410776773155291668053395396280320 98766963416578336910558134487335524402352550059642970226435492955119160062793986827526800752215243224919299624329175242473492831642870691838974468604726731707250620439452847062391119868929321277863500016640744328368128 1185203560998940042926697613848026292828230600715715642717225915461429920753527841930321609026582918699031595491950102909681913979714448302067693623256720780487007445273434164748693438427151855334362000199688931904834560 14222442731987280515120371366176315513938767208588587712606710985537159049042334103163859308318995024388379145903401234916182967756573379624812323479080649365844089343281209976984321261125822264012344002396267182855049472 170669312783847366181444456394115786167265206503063052551280531826445908588508009237966311699827940292660549750840814818994195613078880555497747881748967792390129072119374519723811855133509867168148128028755206194260346560 2048031753406168394177333476729389434007182478036756630615366381917350903062096110855595740397935283511926597010089777827930347356946566665972974580987613508681548865432494236685742261602118406017777536345062474331124138128 24576381040874020730128001720752673208086189736441079567384396583008210836745153330267148884775223402143119164121077333935164168283358799991675694971851362104178586385189930840228907139225420872213330436140749691973489655820 294916572490488248761536020649032078497034276837292954808612758996098530040941839963205786617302680825717429969452928007221970019400305599900108339662216345250143036622279170082746885670705050466559965233688996303681875869697\n"}, {"input": "34673132095468755841708690739143767794037794835774463542579390106875921151401740696448531295736614860068382808881736044004097376353456147122347544457170902210430288830990776802283094016\r\n", "output": "YES\n1\n295\n147\n872314646812554708216880139056555849441840439745184569896264827653056064982207362872974861141941749564885787102012414584779710034567962895627805927533461897216 5270234324492518028810317506800024923711119323460490109789933333737213725934169484024223119399231403621184963741325004783044081458848109161084660812181332295680 62809683440805371473241123068110411978734184718735737590065429621671609790055673902419721164932104377524432524772331393210336274259846689467478512219657636675584 753680107251905720606186586232867453152660279361263005770167341261461404570571890170214074290197029824799041377257679329841852565847632721904280695175348444200960 9044158279186388752518180127245704646949244190896525582132789943954320362104354665654333676508282006005463984117091293842378715563065715366875913221149136064086016 108529899099583625038988489951319397030817373693971754445001044481519909637523713653152984516851543876074557433370928787932234293821196427961179670727043378996838400 1302358789174115747135259406784530342808760687944595507294963164207744587757973851976610895902114539829895438335781631560338785668109724455830711774730625026814377984 15628305470087648319512062675361755578575040938969890625369137189695393859104660331064228674300365812401828655790657119232828092529171307413326587607268009028343562240 187539665641051634780302164587170016231639650657941582882582111211278264543090005148382818918560639026692200819134658559169667332392710240121865555146424484065670332416 2250475987692619605275805759419609273887070737844490902539164706613250302703232901878561499924974022426795597908753133804067318840549410760725882203745361173431839621120 27005711852311435262302350761733108709903798431629656822798991427032162893120974225884235305174875465297087940578299041573310435324246003118649211073443356361569058422784 324068542227737223147544265944855454304117160311013862372948648370025384655841872327555948437604771183246350350745693618540100441327423126922952084933695194862194282987520 3888822506732846677770524196071936964131511888659787846850330509710774568364968316398750141649216109665596312130932165515786236564048783447200355148542040248223278527676416 46665870080794160133246289769924382862284984827661422620401878343968500649754191950824008263157089887276042421231351306363876924707595376860081339293282624471169087926435840 559990440969529921598955477190514355955145388112249068816339032813241941616164851089391349704832286694919916277747896119714393270319395353612115827978623005445069867250089984 6719885291634359059187465726282124084929055121528681492243694768149371627212237758712654800670233041009672945934889060140185041758318431812619651582115078691323425141345484800 80638623499612308710249588715385151670270937330359318962461639415658331887198374733355187491727150292171961513768828247240854861309361655715542007455911911181379650590674518016 967663481995347704522995064584621791930844770953646422637501114837722138676434790269329194057699499656068195345438452260686811199063134908083512938510153848083680686162638274560 11611961783944172454275940775015461500827436711692868287907343498206817510453055341021039240705475137218652065576945803236058113794036851816960239332875113753163095307207871299584 139343541407330069451311289300185538009734015495335178722909566155161322779297983913734894964466791741735977597042656670175015397145548824546852712333730804002637054275932473262080 1672122496887960833415735471602226456116791917190273874613916580876659166072730916949942274913268258408757743898688488961378711268381344778124176701366372101278701310526976180617216 20065469962655530000988825659226717473401501650553807472861915786104470267266200595898067593570857997364086761178776584946484412429129033911120282429176598753115003781258363042529280 240785639551866360011865907910720609680818019693668233089134232501219023230060526283485041147401265876407290620344861912475307938916927814981245902651184196165527594379678243916611584 2889427674622396320142390894928647316169816236314604009020843393603625393762631825329546179604194438009224008234654971524130153182817082063778934374605965771580343428306520417616527360 416077585145625070100504288869725213528453538029293497130480120397813755185675068256756873643879901787817068265752988893525379811088111362331253894482875769271118979946165365943304192000 4992931021747500841206051466436702562341442456351521960117388731366706954008838667406030358567812198409387858735633546419427575340961222814380303680544244643148924052185174061679309225984 59915172260970010094472617597240430748097309476218263520954633716949895272421125496232776625717184162325619558123152363674557822225526664311430748912093413668778379983958021212681682288640 718982067131640121133671411166885168977167713714619162251417768681777860921079761078740020535514829763025181801919124181314812776550819304282074579007251170521256500753974248924891018428416 8627784805579681453604056934002622027726012564575429947017010071187865924190625987538542471511753675474228660548399598160546096561096873262430303747425524896796404337459897486629751457054720 103533417666956177443248683208031464332712150774905159364204120591504935389715650921678648176898175415550571133157909353591950520670036399283417429035717841332435295910219787047851272420982784 1242401012003474129318984198496377571992545809298861912370449447076163436701540155982745122999341199262428505865109671757742189361535176284745530297100831724536796754577695862674906456963153920 14908812144041689551827810381956530863910549711586342948445393364912136591420561233869824921398474649005460541403583957719126170931213343708058406994265998830153858821903605220273935082550460416 178905745728500274621933724583478370366926596539036115381344720378945487042963574753277639343898894142886886369428196484015032376057292726854293554216946654139822330676757533882301809123854909440 2146868948742003295463204695001740444403119158468433384576136644547345831844389300368234983817379829577544416422520456890795848373094407105781322039793839405359365970188916595857539591830696361984 25762427384904039545558456340020885332837429901621200614913639734568149981076740471362895081782774046585774812069360657613101468798833459801336681093291946160619183142439317999396301592163726131200 309149128618848474546701476080250623994049158819454407378963676814817799772832891395266747254391139900000567896082254155934180232946143232160370241170817176702122430334286175896847771313480994390016 3709789543426181694560417712963007487928589905833452888547564121777813597273987363888110300908776833078421087265591210393258243012633730595469803733054082272323360183396851974087514268445731622748160 44517474521114180334725012555556089855143078870001434662570769461333763167287847755586066055393328926464254236563144871429269589503044768129766424866566010280538479785711008510993949639072442780483584 534209694253370164016700150666673078261716946440017215950849233536005158007454173016110187868427281028364650937872409319377082630149157217639207830071285208617516603893944500867089377203679618641428480 6410516331040441968200401808000076939140603357280206591410190802432061896089450076189078704021436316832941944596061801071043812191465938278343994855161463593847787150599451710299669358238722949136777216 76926195972485303618404821696000923269687240287362479096922289629184742753073400914268590819057261547369683846264541020289068981350064263645684063336463066550376578132516096998587248701514222683427962880 923114351669823643420857860352011079236246883448349749163067475550216913036880810971223060359587140713884071197767142194088539712455143914107005103793767257223202531950636720355962919118391467808951107584 11077372220037883721050294324224132950834962601380196989956809706602602956442569731654676721859287355412062843126755093824947452544149591365147294274171557958229987349604344273969298023979049346674731253760 132928466640454604652603531890689595410019551216562363879481716479231235477310836779856120662106801737181875283250523574857359845196019085081422800709112558071389144609101856590106388203961788137844051542016 1595141599685455255831242382688275144920234614598748366553780597750774825727730041358273447945264566968868930162817071435701484010241081020035378214294271852071055510010376422856482892773892557318940891545600 19141699196225463069974908592259301739042815375184980398645367173009297908732760496299281375343173382469984364184122422939868905278550376573679397288680005654453864934682946586259061899480573279466025054633984 229700390354705556839698903107111620868513784502219764783744406076111574904793125955591376504118080471210108803728662205754381121438909302578590672357255796472579812450741894827773848392616367902895528518615040 2756404684256466682076386837285339450422165414026637177404932872913338898857517511467096518049416965644652163680870545896592236312108270362917624560361494201722552202178448282582674939511300538880521611211964416 33076856211077600184916642047424073405065984968319646128859194474960066786290210137605158216593003587735003535673457100711401807649869357582676039432010799141008259297205508186379548337368931810236740606959288320 396922274532931202218999704569088880860791819619835753546310333699520801435482521651261898599116043052819973892373402754366179606123813133761084518576435662085460580972388108969503534137029958834813427389546102784 4763067294395174426627996454829066570329501835438029042555724004394249617225790259815142783189392516633839680997171826181213268433012872675363761893366586784391640427452484141861788155818409737443758840350056120320 57156807532742093119535957457948798843954022025256348510668688052730995406709483117781713398272710199606076171490119496935294147292781731693551038359603154649313527917411795271860436682002087701943939226840298684416 685881690392905117434431489495385586127448264303076182128024256632771944880513797413380560779272522395272914057841772095120257678021433051955044618285171531894813488574606708726451821751706816661045506817303552983040 8230580284714861409213177873944627033529379171636914185536291079593263338566165568960566729351270268743274968694097959985767819462132867646096571432586219522413016125692419268506099076151121946952355934815577633193984 98766963416578336910558134487335524402352550059642970226435492955119160062793986827526800752215243224919299624329175244399574227489417384338378526858798314363929131363542126119055578681741016709013255372204259514777600 1185203560998940042926697613848026292828230600715715642717225915461429920753527841930321609026582918699031595491950102909842420762701660526442643961444560079041730654517108271336748809994886163286957813145985891503702016 14222442731987280515120371366176315513938767208588587712606710985537159049042334103163859308318995024388379145903401234916196343321822313976843569340596302640723649610718182819199992542089800123008393653475125262821621760 170669312783847366181444456394115786167265206503063052551280531826445908588508009237966311699827940292660549750840814818994196727709317966693750485570760763496369035474994267460663161073590198656397798833011777700924227584 2048031753406168394177333476729389434007182478036756630615366381917350903062096110855595740397935283511926597010089777827930347449832436450239308131306096256273735529045462548997146537097125100308465008912083855290012794880 24576381040874020730128001720752673208086189736441079567384396583008210836745153330267148884775223402143119164121077333935164168291099289140364556101044568999811268607157678199588190828850004763404221058854668140386730377216 294916572490488248761536020649032078497034276837292954808612758996098530040941839963205786617302680825717429969452928007221970019400950640662499078089649112491445760140776482362693492644840432457492539452248489507716312596480 3538998869885858985138432247788384941964411322047515457703353107953182360491302079558469439407632169908609159633435136086663640232803720952198165970815548873605158333093891483682958178629638554097963963989147913411185380163584 42467986438630307821661186973460619303572935864570185492440237295438188325895624954701633272891586038903309915601221633039963682793644010865065339735931566443570884098077078945473051165796625429559572025416622130877440364380160 509615837263563693859934243681527431642875230374842225909282847545258259910747499456419599274699032466839718987214659596479564193523728077000674689171690878986209691185337479107449743408079585386413531343128369501357885689430016 6115390047162764326319210924178329179714502764498106710911394170543099118928969993477035191296388389602076627846575915157754770322284736919559753821088666554639796217724750793602878015015165031322937265037384509343863678382899200 73384680565953171915830531090139950156574033173977280530936730046517189427147639921724422295556660675224919534158910981893057243867416843034346350648983029989577994606322067943593992938025164543099078421191934451736994894770601984 880616166791438062989966373081679401878888398087727366371240760558206273125771679060693067546679928102699034409906931782716686926409002116412125316520789612486094305275333570191491203319455573197790926991031823449144824633428541440 10567394001497256755879596476980152822546660777052728396454889126698475277509260148728316810560159137232388412918883181392600243116908025396945501223977224787550728194137291905203591380505396344930207956053775932225429636092490940416 126808728017967081070555157723761833870559929324632740757458669520381703330111121784739801726721909646788660955026598176711202917402896304763346014473204009903751871373883610284351904644454083594708888541992094024274796611484170321920 1521704736215604972846661892685142006446719151895592889089504034244580439961333461416877620720662915761463931460319178120534435008834755657160152173660571228216117717573622999030715256406648113757802195259684026861095029419341233782784 18260456834587259674159942712221704077360629822747114669074048410934965279536001537002531448647954989137567177523830137446413220106017067885921826083925364997707670549307394294670124110269210624312067637512523230547290142205555737886720 219125482015047116089919312546660448928327557872965376028888580931219583354432018444030377383775459869650806130285961649356958641272204814631061913007104255827418234753224058061566617742679646930013015091349971675585327522231123932348416 2629505784180565393079031750559925387139930694475584512346662971174635000253184221328364528605305518435809673563431539792283503695266457775572742956085251059583595999385483307282593173613776523113345198049632967849442084084753858444656640 31554069410166784716948381006719104645679168333707014148159955654095620003038210655940374343263666221229716082761178477507402044343197493306872915473023012714141033424488032571603100896757120007356241461341715056505173188501877998940585984 378648832922001416603380572080629255748150020004484169777919467849147440036458527871284492119163994654756592993134141730088824532118369919682474985676276152569620557879844910266254875995534756899107905793162757298254733943646271962087424000 4543785995064016999240566864967551068977800240053810037335033614189769280437502334455413905429967935857079115917609700761065894385420439036189699828115313830835440707623637966478976650715954525856864286872708268964072861963890574876282454016 54525431940768203990886802379610612827733602880645720448020403370277231365250028013464966865159615230284949391011316409132790732625045268434276397937383765970025287992572447184688046320155582430538002227252062159350959014786698174459658895360 654305183289218447890641628555327353932803234567748645376244840443326776383000336161579602381915382763419392692135796909593488791500543221211316775248605191640303455869293432181834916384497333176477329292423042823193348566708712366511262531584 7851662199470621374687699542663928247193638814812983744514938085319921316596004033938955228582984593161032712305629562915121865498006518654535801302983262299683641470428056525012483859992520526785229726722859705287568669499610242920884763361280 94219946393647456496252394511967138966323665777755804934179257023839055799152048407267462742995815117932392547667554754981462385976078223854429615635799147596203697645136389578385678391858459032145048535275465062734928074553581722927512961417216 1130639356723769477955028734143605667595883989333069659210151084286068669589824580887209552915949781415188710572010657059777548631712938686253155387629589771154444371741636650880481130041630526111634106741189009802759478898022835575786563520430080 13567672280685233735460344809723268011150607871996835910521813011432824035077894970646514634991397376982264526864127884717330583580555264235037864651555077253853332460899639808560761309611177064816767074587425070053942108609889014817826796243779584 162812067368222804825524137716679216133807294463962030926261756137193888420934739647758175619896768523787174322369534616607967002966663170820454375818660927046239989530795677702562051361093425673757634711190197253349041000138136093472953891091906560 1953744808418673657906289652600150593605687533567544371115141073646326661051216875773098107438761222285446091868434415399295604035599958049845452509823931124554879874369548132430730692636934383159754652352294125074580303309725922114647032721116758016 23444937701024083894875475831201807123268250402810532453381692883755919932614602509277177289265134667425353102421212984791547248427199496598145430117887173494658558492434577589168767151335197037506611081212363814064496290659050089458512024822402252800 281339252412289006738505709974421685479219004833726389440580314605071039191375230111326127471181616009104237229054555817498566981126393959177745161414646081935902701909214931070025205719330029820045129245630435294871416542153795992175706600549577129984 3376071028947468080862068519693060225750628058004716673286963775260852470296502761335913529654179392109250846748654669809982803773516727510132941936975752983230832422910579172840302468623902663288038700636822062665631786927032651482664609398484988067840 40512852347369616970344822236316722709007536696056600079443565303130229643558033136030962355850152705311010160983856037719793645282200730121595303243709035798769989074926950074083629623486160484910422503449302821914846008826157409423354990297810695356416 486154228168435403644137866835800672508090440352679200953322783637562755722696397632371548270201832463732121931806272452637523743386408761459143638924508429585239868899123400889003555481833869862712899882708920368805424153055702712382874856700060914155520 5833850738021224843729654402029608070097085284232150411439873403650753068672356771588458579242421989564785463181675269431650284920636905137509723667094101155022878426789480810668042665782006433689537117745950151634484029173930250365203049528161258684022784 70006208856254698124755852824355296841165023410785804937278480843809036824068281259061502950909063874777425558180103233179803419047642861650116684005129213860274541121473769728016511989384077203885860606214188745214543261698601489200487306941915148184453120 840074506275056377497070233892263562093980280929429659247341770125708441888819375108738035410908766497329106698161238798157641028571714339801400208061550566323294493457685236736198143872608926446597945207342163853041247049684171077474018576019980115211452416 10080894075300676529964842806707162745127763371153155910968101241508501302665832501304856424930905197967949280377934865577891692342860572077616802496738606795879533921492222840834377726471307117359172643982503624479033858588651799030277237153299511243953930240 120970728903608118359578113680485952941533160453837870931617214898102015631989990015658277099170862375615391364535218386934700308114326864931401629960863281550554407057906674090012532717655685408310071502914576631935284544229858400538375930359682447415898537984 1451648746843297420314937364165831435298397925446054451179406578777224187583879880187899325190050348507384696374422620643216403697371922379176819559530359378606652884694880089080150392611868224899720858016235297344738987717522137207475098588026196728364820070400 17419784962119569043779248369989977223580775105352653414152878945326690251006558562254791902280604182088616356493071447718596844368463068550121834714364312543279834616338561068961804711342418698796650296193261932950327483709162632856452398674956861353659010646016 209037419545434828525350980439879726682969301264231840969834547343920283012078702747057502827367250185063396277916857372623162132421556822601462016572371750519358015396062732827541656536109024385559803554319013059138384773768193009807991385401035877961681558568960 2508449034545217942304211765278556720195631615170782091638014568127043396144944432964690033928407002220760755335002288471477945589058681871217544198868461006232296184752752793930499878433308292626717642651828145864971821865989836235656776841587559997349993155395584 30101388414542615307650541183342680642347579382049385099656174817524520753739333195576280407140884026649129064020027461657735347068704182454610530386421532074787554217033033527165998541199699511520611711821937749475937796106942328171044728783781980756684069069127680 361216660974511383691806494200112167708170952584592621195874097810294249044871998346915364885690608319789548768240329539892824164824450189455326364637058384897450650604396402325991982494396394138247340541863252993635943214426229962497800362629111374145915841429897216 4334599931694136604301677930401346012498051431015111454350489173723530988538463980162984378628287299837474585218883954478713889977893402273463916375644700618769407807252756827911903789932756729658968086502359035923625042711543336385344042986317980456839799014875463680 52015199180329639251620135164816152149976617172181337452205870084682371862461567761955812543539447598049695022626607453744566679734720827281566996507736407425232893687033081934942845479193080755907617038028308431083499989550055751360409385722046485812668322254981955584 624182390163955671019441621977793825799719406066176049426470441016188462349538813143469750522473371176596340271519289444934800156816649927378803958092836889102794724244396983219314145750316969070891404456339701173001999831018296992552936034488410389779569094899489832960 7490188681967468052233299463733525909596632872794112593117645292194261548194465757721637006269680454119156083258231473339217601881799799128545647497114042669233536690932763798631769749003803628850696853476076414076023997968587699575320901031012912390690458241113853526016 89882264183609616626799593564802310915159594473529351117411743506331138578333589092659644075236165449429872999098777680070611222581597589542547769965368512030802440291193165583581236988045643546208362241712916968912287975622749739542574618090250947664396801318559573606400 1078587170203315399521595122777627730981915133682352213408940922075973662940003069111915728902833985393158475989185332160847334670979171074510573239584422144369629283494317987002974843856547722554500346900555003626947455707472971653230789067559519371887437557691480994217984 12943046042439784794259141473331532771782981604188226560907291064911683955280036829342988746834007824717901711870223985930168016051750052894126878875013065732435551401931815844035698126278572670654004162806660043523369468489675657736996126614920608129308807020786835773194240 155316552509277417531109697679978393261395779250258718730887492778940207463360441952115864962008093896614820542442687831162016192621000634729522546500156788789226616823181790128428377515342872047848049953679920522280433621876107892668805740862731162190593980610149451265212416 1863798630111329010373316372159740719136749351003104624770649913347282489560325303425390379544097126759377846509312253973944194311452007616754270558001881465470719401878181481541140530184114464574176599444159046267365203462513294712011073242143080935007035125351852367014789120 22365583561335948124479796465916888629640992212037255497247798960167389874723903641104684554529165521112534158111747047687330331737424091401051246696022577585648632822538177778493686362209373574890119193329908555208382441550159536544131662601699496802477747117391399983496822784 268387002736031377493757557591002663555691906544447065966973587522008678496686843693256214654349986253350409897340964572247963980849089096812614960352270931027783593870458133341924236346512482898681430319958902662500589298601914438529579849861725838761599075876460897433571819520 3220644032832376529925090691092031962668302878533364791603683050264104141960242124319074575852199835040204918768091574866975567770189069161751379524227251172333403126445497600103090836158149794784177163839506831950007071583222973262354958189894154388233511086389844444005495996416 38647728393988518359101088293104383552019634542400377499244196603169249703522905491828894910226398020482459025217098898403706813242268829941016554290727014068000837517345971201237090033897797537410125966074081983400084858998675679148259498278025973019059993218000826134299504803840 463772740727862220309213059517252602624235614508804529990930359238030996442274865901946738922716776245789508302605186780844481758907225959292198651488724168816010050208151654414845080406773570448921511592888983800801018307984108149779113979336253019592074740297786804678780187049984 5565272888734346643710556714207031231490827374105654359891164310856371957307298390823360867072601314949474099631262241370133781106886711511506383817864690025792120602497819852978140964881282845387058139114667805609612219695809297797349367752035031347051843118713589730400961088716800 66783274664812159724526680570484374777889928489267852318693971730276463487687580689880330404871215779393689195575146896441605373282640538138076605814376280309505447229973838235737691578575394144644697669376013667315346636349711573568192413024420375757284362944158089104332832968278016 801399295977745916694320166845812497334679141871214227824327660763317561852250968278563964858454589352724270346901762757299264479391686457656919269772515363714065366759686058828852298942904729735736372032512164007784159636196538882818308956293044509053467542456529986946954103944642560 9616791551732951000331842002149749968016149702454570733891931929159810742227011619342767578301455072232691244162821153087591173752700237491883031237270184364568784401116232705946227587314856756828836464390145968093409915634358466593819707475516534108638781775072245919838029256362819584 115401498620795412003982104025796999616193796429454848806703183149917728906724139432113210939617460866792294929953853837051094085032402849902596374847242212374825412813394792471354731047778281081946037572681751617120918987612301599125836489706198409303665145572999774877762566077106094080 1384817983449544944047785248309563995394325557153458185680438197799012746880689673185358531275409530401507539159446246044613129020388834198831156498166906548497904953760737509656256772573339372983352450872181019405451027851347619189510037876474380911643981727232008367186459644175335817216 16617815801394539328573422979714767944731906685841498228165258373588152962568276078224302375304914364818090469913354952535357548244666010385973877978002878581974859445128850115875081270880072475800229410466172232865412334216171430274120454517692570939727780725147101328625291467708201697280 199413789616734471942881075756577215336782880230097978737983100483057835550819312938691628503658972377817085638960259430424290578935992124631686535736034542983698313341546201390500975250560869709602752925594066794384948010594057163289445454212310851276733368701628799353702478923965434691584 2392965475400813663314572909078926584041394562761175744855797205796694026609831755264299542043907668533805027667523113165091486947231905495580238428832414515804379760098554416686011703006730436515233035107128801532619376127128685959473345450547730215320800424419534224195279662196874134159360 28715585704809763959774874908947119008496734753134108938269566469560328319317981063171594504526892022405660332010277357981097843366782865946962861145988974189652557121182653000232140436080765238182796421285545618391432513525544231513680145406572762583849605093034409743005926772621597019734016 344587028457717167517298498907365428101960817037609307259234797634723939831815772758059134054322704268867923984123328295773174120401394391363554333751867690275830685454191836002785685232969182858193557055426547420697190162306530778164161744878873151006195261116412916837126335506980756520960000 4135044341492606010207581986888385137223529804451311687110817571616687277981789273096709608651872451226415087809479939549278089444816732696362652005022412283309968225450302032033428222795630194298322684665118569048366281947678369337969940938546477812074343133396955002038937293936729210941865984 49620532097911272122490983842660621646682357653415740245329810859400247335781471277160515303822469414716981053713759274591337073337800792356351824060268947399719618705403624384401138673547562331579872215981422828580395383372140432055639291262557733744892117600763460024466699299561830542359920640 595446385174935265469891806111927459760188291840988882943957730312802968029377655325926183645869632976603772644565111295096044880053609508276221888723227368796635424464843492612813664082570747978958466591777073942964744600465685184667671495150692804938705411209161520293600345909102056509240508416 7145356622099223185638701673343129517122259502091866595327492763753635616352531863911114203750435595719245271734781335541152538560643314099314662664678728425559625093578121911353763968990848975747501599101324887315576935205588222216012057941808313659264464934509938243523204147102088018944296222720 85744279465190678227664420080117554205467114025102399143929913165043627396230382366933370445005227148630943260817376026493830462727719769191775951976144741106715501122937462936245167627890187708970019189215898647786923222467058666592144695301699763911173579214119258922278449764907794839067672182784 1028931353582288138731973040961410650465605368301228789727158957980523528754764588403200445340062725783571319129808512317925965552732637230301311423713736893280586013475249555234942011534682252507640230270590783773443078669604703999105736343620397166934082950569431107067341397178867099619790075985920 12347176242987457664783676491536927805587264419614745476725907495766282345057175060838405344080752709402855829557702147815111586632791646763615737084564842719367032161702994662819304138416187030091682763247089405281316944035256447989268836123444766003208995406833173284808096766146402992233395745980416 148166114915849491977404117898443133667047173035376945720710889949195388140686100730060864128969032512834269954692425773781339039593499761163388845014778112632404385940435935953831649660994244361100193158965072863375803328423077375871226033481337192038507944881998079417697161193756835723200408521277440 1777993378990193903728849414781317604004566076424523348648530679390344657688233208760730369547628390154011239456309109285376068475121997133960666140177337351588852631285231231445979795931930932333202317907580874360509639941076928510454712401776046304462095338583976953012365934325082028663104873886121984 21335920547882326844746192977375811248054792917094280183782368152684135892258798505128764434571540681848134873475709311424512821701463965607527993682128048219066231575422774777351757551183171187998427814890970492326115679292923142125456548821312555653545144063007723436148391211900984343955983484269363200 256031046574587922136954315728509734976657515005131362205388417832209630707105582061545173214858488182177618481708511737094153860417567587290335924185536578628794778905073297328221090614198054255981133778691645907913388151515077705505478585855750667842541728756092681233780694542811812127471695561035350016 3072372558895055065643451788742116819719890180061576346464661013986515568485266984738542078578301858186131421780502140845129846325010811047484031090226438943545537346860879567938653087370376651071773605344299750894960657818180932466065743030269008014110500745073112174805368334513741745529660337878241116160 36868470706740660787721421464905401836638682160738916157575932167838186821823203816862504942939622298233577061366025690141558155900129732569808373082717267322546448162330554815263837048444519812861283264131597010739527893818171189592788916363228096169326008940877346097664420014164900946355924053801044803584 442421648480887929452657057578864822039664185928866993890911186014058241861878445802350059315275467578802924736392308281698697870801556790837700476992607207870557377947966657783166044581334237754335399169579164128874334725818054275113466996358737154031912107290528153171973040169978811356271088645551050260480 5309059781770655153431884690946377864475970231146403926690934232168698902342541349628200711783305610945635096836707699380384374449618681490052405723911286494446688535375599893397992534976010853052024790034949969546492016709816651301361603956304845848382945287486337838063676482039745736275253063746607479177216 63708717381247861841182616291356534373711642773756847120291210786024386828110496195538408541399667331347621162040492392564612493395424177880628868686935437933360262424507198720775910419712130236624297480419399634557904200517799815616339247475658150180595343449836054056764117784476948835303036764959289323130880 764504608574974342094191395496278412484539713285082165443494529432292641937325954346460902496796007976171453944485908710775349920745090134567546424243225255200323149094086384649310925036545562839491569765032795614694850406213597787396070969707897802167144121398032648681169413413723386023636441179511471841987584 9174055302899692105130296745955340949814476559420985985321934353187511703247911452157530829961552095714057447333830904529304199048941081614810557090918703062403877789129036615791731100438546754073898837180393547376338204874563173448752851636494773626005729456776391784174032960964680632283637294154137662100885760 110088663634796305261563560951464091397773718713051831823863212238250140438974937425890369959538625148568689368005970854351650388587292979377726685091024436748846533469548439389500773205262561048886786046164722568516058458494758081385034219637937283512068753481316701410088395531576167587403647529849651945210382016 1321063963617555663138762731417569096773284624556621981886358546859001685267699249110684439514463501782824272416071650252219804663047515752532720221092293240986158401634581272674009278463150732586641432553976670822192701501937096976620410635655247402144825041775800416921060746378914011048843770358195823342524563600 15852767563410667957665152777010829161279415494679463782636302562308020223212390989328213274173562021393891268992859803026637655956570189030392642653107518891833900819614975272088111341557808791039697190647720049866312418023245163719444927627862968825737900501309605003052728956546968132586125244298349880110294761484 190233210760928015491981833324129949935352985936153565391635630747696242678548691871938559290082744256726695227914317636319651871478842268364711711837290226702006809835379703265057336098693705492476366287772640598395749016278941964633339131534355625908854806015715260036632747478563617591033502931580198561323537137665\n"}, {"input": "76926195972485303618404821696000923269687240287362491269272716553702593162409974951445967754952159774825431550496029309100898668843613086511855201303688576780554483501841048484822445695165614561660239872\r\n", "output": "YES\n1\n329\n164\n1935326963990695409045990129169243583468509031739311510940568123967050181633010200027736247474237792265283308973117638973035112647963343872663487539244632324333894587417228214272 11692600407443784762986190363730846650122242066758340378599265748967594847366103291834239828490186661602753325045919068795420472248111869230675237216269653626183946465645753794560 139350261292621703810370476765911820105508582608257301397133893009391387557374071242969328346782184368767986035331737775638295593683388409331328962157347015658722125205802296803328 1672123056878401802945657070557703646291439797783017384836768608114511671470903924227378477695127874461010411268545912386833984618092831410189549722185006785583375066437798665912320 20065470009321400081782985792473007239249388973936536098713820121707624642716048346504520610469346298701774483459598036898605685208271657797125730180911484976807059927584264916303872 240785639555755182518598754588491133827972010303950127141288557862519286094681346929368912232142806568185431263868263700137984711648523033638413023297162103350835265725205402406092800 2889427674622720388684618632151794859848745735532127500191856254050400415668016893716703168861256233066872186621615255006435376247211381665333698301326463930512452400918647680823984128 34673132095468782847420543050579030089344372294042590500176974511913152403227189452147461044841370009656520157080649400960956144942155672089143774784397610390341297912041787407550382080 416077585145625072350980276562344818719729086150815841043613252431566857789993855653065117789638631383616079711436231673271784708470502989411820247010144661619444897369586283493743132672 4992931021747500841393591132077754196107382085361648822110149825702853045892531899689056045579958759209037776356107149984406442415743088783303684209921517050844617878637125804808512471040 59915172260970010094488245902710518384244471111969107426120697141477907446744766598923028766301529709058923717924858497304972727815091819808841030622874853036086354469495683857942449225728 718982067131640121133672713525674342946846643850931732576848273967155195268940064503964208213896858558586290481902599692450680685349949733906858769149816290468532165294435720811996082339840 8627784805579681453604057042532521125556819142086789327877462613294980702052947679490644487151618844540525419605064887786474085553496800798232369096604071990125343976171602609287010212380672 103533417666956177443248683217075622590864717989697772645942491636680528287870844396007990011534830846306095863079298127727444519752736393244734267814816053590212707546779095808072710650593280 1242401012003474129318984198497131251847391856566761296810594311329928069443053088772272568152227587214991466259269787488920147194792067950908973366999089908891611538880742471738258243482288128 14908812144041689551827810381956593670565120215525334563815405436933283644149020644935618875161215181334840788103097300696724334083984751346905360583424187012183426720595525771029214398093721600 178905745728500274621933724583478375600814477414364364682625554718280582630690946370866455506712455853914334723319822595929832222986690344157530800349376503154991461334981860594864749066816847872 2146868948742003295463204695001740444839276481874710738684576714075623756476699914669700718497614293053463370452011425733455415027005190240556591810304875226110630064410435289750253170159276523520 25762427384904039545558456340020885332873776345238390394422676407028839808129433022554683893006126918542101391571818238349989766019992691729234620240834532479015121816957777890554027723691107811328 309149128618848474546701476080250623994052187689755839860589429870856190591753949107866062988659752639330261777707458954328920924381239834821028402766445725561988758557162714221110915157774942863360 3709789543426181694560417712963007487928590158239311341254366267865816796508897452030826910553299217473365228422393310793124471403586655312358191913187051318061682377415425018947869530432756118454272 44517474521114180334725012555556089855143078891035256200296336306841096767224090262931292439530372458497166248326211713129258441868957511856173790548243757701016673301879222931398979244238028155125760 534209694253370164016700150666673078261716946441770034412326364106464102474115526558388956733772034656034060272185998222852081701179649946283075110544758354235889786686958518735456463004110084089315328 6410516331040441968200401808000076939140603357280352659615313896646266808128338522317601934760215046301914395373921266813000062114051812672397650461867586355982651582498869545122033282055425487924101120 923114351669823643420857860352011079236246883448349750177430011127260067237658858807654508437578382232838716839786432884822858853079606316012519365291036049742384024064747132979815852201195750465470464000 11077372220037883721050294324224132950834962601380196990041339917900689885959301235641046009199119958871975730263590034715841979139201629898639420462629663690939919140613853475021285768402616370229441200128 132928466640454604652603531890689595410019551216562363879488760663506076054770564405188318102718454454136868023845259819931601055745606754959213811224817400215781638925019315690194053849330418723140277370880 1595141599685455255831242382688275144920234614598748366553781184766131062442518351993717797731982204695281846224533299456124337444453546659191860798503913922249754884536702877781490198244339943201048910364672 19141699196225463069974908592259301739042815375184980398645367221927244261792326188852235071158733185613852107189265441941570809731401415376942437504030809160302089882560140457502812508269777228289534056202240 229700390354705556839698903107111620868513784502219764783744406080188070434214756429970789312102710454805431115645757457337856280143313555812195925708535030098067164529731660983710827610015468231964154268745728 2756404684256466682076386837285339450422165414026637177404932872913678606818302647339961469116749018143285107206863637167557525908666970717353758331474100804524676148185030763095669687779417130574610663357808640 33076856211077600184916642047424073405065984968319646128859194474960095095286942232261230295848614592109889614300623191650648915116249249278879050579603516357908436292706056726422297899724608192877914694638108672 396922274532931202218999704569088880860791819619835753546310333699520803794565582659149904605720677303184547732258999928611116865079344791402434769505401721853535595722013154681173763267226265200033525230186004480 4763067294395174426627996454829066570329501835438029042555724004394249617422380514899133450356609569488036728817162292612400346537925833646833874414277333956038980012014952895671094008245926096307527181836776112128 57156807532742093119535957457948798843954022025256348510668688052730995406725865639038712620536644954010592592141785369137893070468191145107840214403012383580284139549458667668011212169704380731849253255297525350400 685881690392905117434431489495385586127448264303076182128024256632771944880515162623485310714461183624806623759562744251137140921619383836406235382955455634305727706210610614759464386375682007746870949653008321871872 8230580284714861409213177873944627033529379171636914185536291079593263338566165682728075458512535990512402777835908040998769226399099363544800837329642076530947258977162086260675516789869786546209508055051886363934720 98766963416578336910558134487335524402352550059642970226435492955119160062793986837007426479645348701733393608424326084483991011400831258996603882350219635781306984934497931701736363491217572092284684715557285242339328 1185203560998940042926697613848026292828230600715715642717225915461429920753527841931111661170535427488766103323958032146516122161360945015997496074402178522493178808981354588468638875395675876235563765591265310314332160 14222442731987280515120371366176315513938767208588587712606710985537159049042334103163925145997657733454190354889401895685919151771710587684306473683342770844344603623590203345627650047539865932420777482845565214389174272 170669312783847366181444456394115786167265206503063052551280531826445908588508009237966317186301162185082700684922981540725006961746808656169372394265989635846670781642733602504532132532377704140515497485459314363554856960 2048031753406168394177333476729389434007182478036756630615366381917350903062096110855595740855141385336295109587929958388074581636002227341028943290364031995636260674559440826917468951385357392432141483799787816678565347328 24576381040874020730128001720752673208086189736441079567384396583008210836745153330267148884813323910628483206835897348981842854473280105047930359030966063644758145702617176389414884363374024121081194098428643470502443089920 294916572490488248761536020649032078497034276837292954808612758996098530040941839963205786617305855868091210306345829675142526576582799041988129561667142570378524666565398107211845717106050767403965620538879654118559288655872 3538998869885858985138432247788384941964411322047515457703353107953182360491302079558469439407632434495473641328176211225657019945902208318975301844447006661762414908629276619087054197334739415343503387413033843795422294835200 42467986438630307821661186973460619303572935864570185492440237295438188325895624954701633272891586060952215289075783389301546464436402218145630101058734187925917322146038361040090059167355383834663366977368612625076126773936128 509615837263563693859934243681527431642875230374842225909282847545258259910747499456419599274699032468677127768337539742834696091993957927607388419281924430776405227689334252615334494074876148586838847589124368709207776223559680 6115390047162764326319210924178329179714502764498106710911394170543099118928969993477035191296388389602229745245002821836617697980490589407110313298597852683955645845766750524728535077570731411589639374724550842611184502594076672 73384680565953171915830531090139950156574033173977280530936730046517189427147639921724422295556660675224932293942113224116295821172267330741642230605442128833687648741992234587854464359904795074787970263665864979509271630121533440 880616166791438062989966373081679401878888398087727366371240760558206273125771679060693067546679928102699035473222198636235290141184406323721066639850494537389770109786639417411846242604612209075431667977904650993125847694707785728 10567394001497256755879596476980152822546660777052728396454889126698475277509260148728316810560159137232388413007492786963726793384805975747554579667588033531292701177846567392471954300445826064586678017802682001187428054680930877440 126808728017967081070555157723761833870559929324632740757458669520381703330111121784739801726721909646788660955033982310508796796591887800625896771010171577299063702455859383241624268221115786071346927713804502863354963146366540316672 1521704736215604972846661892685142006446719151895592889089504034244580439961333461416877620720662915761463931460319793465017567832100504948482031403371985192165727036830454313443821286704703255630855365190668394264351709963914764615680 18260456834587259674159942712221704077360629822747114669074048410934965279536001537002531448647954989137567177523830188725120147841289213660198649353067982828036804659245463570871216279460715219468155401673438594497561532250936865456128 219125482015047116089919312546660448928327557872965376028888580931219583354432018444030377383775459869650806130285961653630184218583477493445584981612866140646612329262385563834583375423445605646276022405030047955914516804734905692979200 2629505784180565393079031750559925387139930694475584512346662971174635000253184221328364528605305518435809673563431539792639605826709063832140619878469064549985195507261246766097011236753840353006367115325772974206136183191629173591375872 31554069410166784716948381006719104645679168333707014148159955654095620003038210655940374343263666221229716082761178477507431719520817710478253571883221663838341166716811012859837635735352125326513993287781393390368231030094117608536145920 378648832922001416603380572080629255748150020004484169777919467849147440036458527871284492119163994654756592993134141730088827005049838271113423373710459373496637235654205158623607753898751007342371051778699397159409988763778958596220387328 4543785995064016999240566864967551068977800240053810037335033614189769280437502334455413905429967935857079115917609700761065894591498061398808945527118162432579358764104834653842089390541222546727136215704836322285835799865568298762460200960 54525431940768203990886802379610612827733602880645720448020403370277231365250028013464966865159615230284949391011316409132790732642218403631161335078967336686837281163945880241968305715141021432277191554654739497127772592945171318116840374272 654305183289218447890641628555327353932803234567748645376244840443326776383000336161579602381915382763419392692135796909593488791501974315811057186677070489200037788633574551603274938000746119759955595069706599268008083031555251795149360988160 7851662199470621374687699542663928247193638814812983744514938085319921316596004033938955228582984593161032712305629562915121865498006637912419113003935634407813619331491746618297603861793874592333852915537633334991303230705014121206604604899328 94219946393647456496252394511967138966323665777755804934179257023839055799152048407267462742995815117932392547667554754981462385976078233792586558277545178605214529133558363752826105058675238537607433801010029531876905954654032046117989614878720 1130639356723769477955028734143605667595883989333069659210151084286068669589824580887209552915949781415188710572010657059777548631712938687081335132849735273738528607699005148728351165597198591070422638846666890175187977054697873102719103241551872 13567672280685233735460344809723268011150607871996835910521813011432824035077894970646514634991397376982264526864127884717330583580555264235106879630323422712402006147229420516714750479240807736896666118929548226751644483456278601278404507887206400 162812067368222804825524137716679216133807294463962030926261756137193888420934739647758175619896768523787174322369534616607967002966663170820460127066891622501119045671323159428241550458562561563097626298218707516407182864708668559011335367062192128 1953744808418673657906289652600150593605687533567544371115141073646326661051216875773098107438761222285446091868434415399295604035599958049845452989094617015842786462381258755907870650895056811150532984984546500929835148465106799820108564510780948480 23444937701024083894875475831201807123268250402810532453381692883755919932614602509277177289265134667425353102421212984791547248427199496598145430157826397318932550708102220141125195481190040573172509275598384845385767527755331829267300485804874268672 281339252412289006738505709974421685479219004833726389440580314605071039191375230111326127471181616009104237229054555817498566981126393959177745161417974350587925534593853901282688241413484600114683954095162603714148189145245152803826438972298116464640 3376071028947468080862068519693060225750628058004716673286963775260852470296502761335913529654179392109250846748654669809982803773516727510132941936976030338951834325634299087024691054931748877479258602707616410033904851310623597883635503762797366345728 40512852347369616970344822236316722709007536696056600079443565303130229643558033136030962355850152705311010160983856037719793645282200730121595303243709058911746739233487260066932328672345147669426357495288535684195535430858123321623435898161503393546240 486154228168435403644137866835800672508090440352679200953322783637562755722696397632371548270201832463732121931806272452637523743386408761459143638924508431511321264745670093388407613735905452128089227798695523107328814938225033205066214932355368639004672 5833850738021224843729654402029608070097085284232150411439873403650753068672356771588458579242421989564785463181675269431650284920636905137509723667094101155183385209776693035042993003969845732211651811738949035196027645072694361239593327867799200994426880 70006208856254698124755852824355296841165023410785804937278480843809036824068281259061502950909063874777425558180103233179803419047642861650116684005129213860287916686722704080047757850899730478762703497380271985511338563023498498440019830136884976710320128 840074506275056377497070233892263562093980280929429659247341770125708441888819375108738035410908766497329106698161238798157641028571714339801400208061550566323295608088122647932200747694401897552837682114939337456399313324794579161577312952952894267588608000 10080894075300676529964842806707162745127763371153155910968101241508501302665832501304856424930905197967949280377934865577891692342860572077616802496738606795879534014378092625100711276789789864951359288724803388945980364111577666370619178351377254089985359872 120970728903608118359578113680485952941533160453837870931617214898102015631989990015658277099170862375615391364535218386934700308114326864931401629960863281550554407065647163238701393846848892303942753723309768278974196753023435556150071092126188925986401157120 1451648746843297420314937364165831435298397925446054451179406578777224187583879880187899325190050348507384696374422620643216403697371922379176819559530359378606652884695525129842541131039300992141023581534601563315325563734921601970442739851506738934912361955328 17419784962119569043779248369989977223580775105352653414152878945326690251006558562254791902280604182088616356493071447718596844368463068550121834714364312543279834616338614822358670606211371429400092189819792455114543031710612588253366368780246906537537972469760 209037419545434828525350980439879726682969301264231840969834547343920283012078702747057502827367250185063396277916857372623162132421556822601462016572371750519358015396062737306991395360681437113110090378787890602652069402768313839424400882909810048393671472054272 2508449034545217942304211765278556720195631615170782091638014568127043396144944432964690033928407002220760755335002288471477945589058681871217544198868461006232296184752752794303787356668689327020680166553867218993597962251739846304791477633046624511552658981519360 30101388414542615307650541183342680642347579382049385099656174817524520753739333195576280407140884026649129064020027461657735347068704182454610530386421532074787554217033033527197105831052647931053441922147107672236656641139088162343472620516403569466200957887971328 361216660974511383691806494200112167708170952584592621195874097810294249044871998346915364885690608319789548768240329539892824164824450189455326364637058384897450650604396402325994574768550806506541743059390350487199336451512242115345502686940163173205042248831467520 4334599931694136604301677930401346012498051431015111454350489173723530988538463980162984378628287299837474585218883954478713889977893402273463916375644700618769407807252756827911904005955602930689659286712152960714755325481300504064748018180010568106761392882158927872 52015199180329639251620135164816152149976617172181337452205870084682371862461567761955812543539447598049695022626607453744566679734720827281566996507736407425232893687033081934942845497194984605993507971379124591482760846447535515333693050321520868116828455077255577600 624182390163955671019441621977793825799719406066176049426470441016188462349538813143469750522473371176596340271519289444934800156816649927378803958092836889102794724244396983219314145751817127725065228700785602519701938235759753639550709673205033254971582439301345968128 7490188681967468052233299463733525909596632872794112593117645292194261548194465757721637006269680454119156083258231473339217601881799799128545647497114042669233536690932763798631769749003928642071878005496446905854915659502316154295904048834239297629456459353147341537280 89882264183609616626799593564802310915159594473529351117411743506331138578333589092659644075236165449429872999098777680070611222581597589542547769965368512030802440291193165583581236988045653963976794004381281176560528947417227110769289880407186479767627301411229030940672 1078587170203315399521595122777627730981915133682352213408940922075973662940003069111915728902833985393158475989185332160847334670979171074510573239584422144369629283494317987002974843856547723422647716214110700644251475788455844767499682006085930666229373432699203448995840 12943046042439784794259141473331532771782981604188226560907291064911683955280036829342988746834007824717901711870223985930168016051750052894126878875013065732435551401931815844035698126278572670726349776916123018274811470163090897163185201026464475737170635010370812644425728 155316552509277417531109697679978393261395779250258718730887492778940207463360441952115864962008093896614820542442687831162016192621000634729522546500156788789226616823181790128428377515342872047854078754855709103509720455348892495954321497063693151157915799609281449337815040 1863798630111329010373316372159740719136749351003104624770649913347282489560325303425390379544097126759377846509312253973944194311452007616754270558001881465470719401878181481541140530184114464574177101844257028649134310698636026762284866221826494434087645276935113366854172672 22365583561335948124479796465916888629640992212037255497247798960167389874723903641104684554529165521112534158111747047687330331737424091401051246696022577585648632822538177778493686362209373574890119235196583387073529867153169764214987812016673114594067797963356671733483438080 268387002736031377493757557591002663555691906544447065966973587522008678496686843693256214654349986253350409897340964572247963980849089096812614960352270931027783593870458133341924236346512482898681430323447792231822684917402165290835484528979640306910898246780291336746070704128 3220644032832376529925090691092031962668302878533364791603683050264104141960242124319074575852199835040204918768091574866975567770189069161751379524227251172333403126445497600103090836158149794784177163839797572747450579551456327500047116913153980593912619350631830313948204236800 38647728393988518359101088293104383552019634542400377499244196603169249703522905491828894910226398020482459025217098898403706813242268829941016554290727014068000837517345971201237090033897797537410125966074106211799871817996028458668067178171630958536199918906687658290128063823872 463772740727862220309213059517252602624235614508804529990930359238030996442274865901946738922716776245789508302605186780844481758907225959292198651488724168816010050208151654414845080406773570448921511592888985819834333887900554214739097952660720101718503067438510707358432566968320 5565272888734346643710556714207031231490827374105654359891164310856371957307298390823360867072601314949474099631262241370133781106886711511506383817864690025792120602497819852978140964881282845387058139114667805777864995994135668302762699749812070270562378812641983388957598787043328 66783274664812159724526680570484374777889928489267852318693971730276463487687580689880330404871215779393689195575146896441605373282640538138076605814376280309505447229973838235737691578575394144644697669376013667329367701041238771110310190690901795667576907585318788575879219443138560 801399295977745916694320166845812497334679141871214227824327660763317561852250968278563964858454589352724270346901762757299264479391686457656919269772515363714065366759686058828852298942904729735736372032512164007785328058254166149280152104431917960712658587843293378569582969484214272 9616791551732951000331842002149749968016149702454570733891931929159810742227011619342767578301455072232691244162821153087591173752700237491883031237270184364568784401116232705946227587314856756828836464390145968093410013002863268866024861071194773562943714362187809535806581661824450560 115401498620795412003982104025796999616193796429454848806703183149917728906724139432113210939617460866792294929953853837051094085032402849902596374847242212374825412813394792471354731047778281081946037572681751617120918995726343665981853585839171595924857223288592738512426612110894563328 1384817983449544944047785248309563995394325557153458185680438197799012746880689673185358531275409530401507539159446246044613129020388834198831156498166906548497904953760737509656256772573339372983352450872181019405451027852023789361748039301152128677195747733708307780822681648011484856320 16617815801394539328573422979714767944731906685841498228165258373588152962568276078224302375304914364818090469913354952535357548244666010385973877978002878581974859445128850115875081270880072475800229410466172232865412334216227777788473621303082383253523761225686792946428309968027880783872 199413789616734471942881075756577215336782880230097978737983100483057835550819312938691628503658972377817085638960259430424290578935992124631686535736034542983698313341546201390500975250560869709602752925594066794384948010594061858915641551444426668969549700410007106988519397132325407948800 2392965475400813663314572909078926584041394562761175744855797205796694026609831755264299542043907668533805027667523113165091486947231905495580238428832414515804379760098554416686011703006730436515233035107128801532619376127128686350775528458650406533461868452061899083164847738714237465264128 28715585704809763959774874908947119008496734753134108938269566469560328319317981063171594504526892022405660332010277357981097843366782865946962861145988974189652557121182653000232140436080765238182796421285545618391432513525544231546288660657247985610361360762004606814586724112331377297326080 344587028457717167517298498907365428101960817037609307259234797634723939831815772758059134054322704268867923984123328295773174120401394391363554333751867690275830685454191836002785685232969182858193557055426547420697190162306530778166879121149762752925071240755493766593091401951956571544092672 4135044341492606010207581986888385137223529804451311687110817571616687277981789273096709608651872451226415087809479939549278089444816732696362652005022412283309968225450302032033428222795630194298322684665118569048366281947678369337970167386569051945567582798366878406185267716140477195527127040 49620532097911272122490983842660621646682357653415740245329810859400247335781471277160515303822469414716981053713759274591337073337800792356351824060268947399719618705403624384401138673547562331579872215981422828580395383372140432055639310133226281589349887572844286974812226834745476207742025728 595446385174935265469891806111927459760188291840988882943957730312802968029377655325926183645869632976603772644565111295096044880053609508276221888723227368796635424464843492612813664082570747978958466591777073942964744600465685184667671496723248517259076892040168255872795806537034026981355683840 7145356622099223185638701673343129517122259502091866595327492763753635616352531863911114203750435595719245271734781335541152538560643314099314662664678728425559625093578121911353763968990848975747501599101324887315576935205588222216012057941939359968624495891245855471488137102154415683150305820672 85744279465190678227664420080117554205467114025102399143929913165043627396230382366933370445005227148630943260817376026493830462727719769191775951976144741106715501122937462936245167627890187708970019189215898647786923222467058666592144695301710684436953581793847252024608860844495488811084839649280 1028931353582288138731973040961410650465605368301228789727158957980523528754764588403200445340062725783571319129808512317925965552732637230301311423713736893280586013475249555234942011534682252507640230270590783773443078669604703999105736343620398076977897950784408439825868931435499407450791506608128 12347176242987457664783676491536927805587264419614745476725907495766282345057175060838405344080752709402855829557702147815111586632791646763615737084564842719367032161702994662819304138416187030091682763247089405281316944035256447989268836123444766079045979990184421395871307394001122351219312531865600 148166114915849491977404117898443133667047173035376945720710889949195388140686100730060864128969032512834269954692425773781339039593499761163388845014778112632404385940435935953831649660994244361100193158965072863375803328423077375871226033481337192044827693597277350093619095412744729003115901586767872 1777993378990193903728849414781317604004566076424523348648530679390344657688233208760730369547628390154011239456309109285376068475121997133960666140177337351588852631285231231445979795931930932333202317907580874360509639941076928510454712401776046304462621984310250225568692762176664353103097831641579520 21335920547882326844746192977375811248054792917094280183782368152684135892258798505128764434571540681848134873475709311424512821701463965607527993682128048219066231575422774777351757551183171187998427814890970492326115679292923142125456548821312555653545187950151579542194751780888616204325982897415651328 256031046574587922136954315728509734976657515005131362205388417832209630707105582061545173214858488182177618481708511737094153860417567587290335924185536578628794778905073297328221090614198054255981133778691645907913388151515077705505478585855750667842541732413354669242617891256894114782502528845464207360 3072372558895055065643451788742116819719890180061576346464661013986515568485266984738542078578301858186131421780502140845129846325010811047484031090226438943545537346860879567938653087370376651071773605344299750894960657818180932466065743030269008014110500745377884007139438100906581937417579573985276854272 36868470706740660787721421464905401836638682160738916157575932167838186821823203816862504942939622298233577061366025690141558155900129732569808373082717267322546448162330554815263837048444519812861283264131597010739527893818171189592788916363228096169326008940902743750358925828030970962346583990143297781760 442421648480887929452657057578864822039664185928866993890911186014058241861878445802350059315275467578802924736392308281698697870801556790837700476992607207870557377947966657783166044581334237754335399169579164128874334725818054275113466996358737154031912107290530269643030915654467650524270310306912904675328 5309059781770655153431884690946377864475970231146403926690934232168698902342541349628200711783305610945635096836707699380384374449618681490052405723911286494446688535375599893397992534976010853052024790034949969546492016709816651301361603956304845848382945287486338014436264638330119806205919665551720967045120 63708717381247861841182616291356534373711642773756847120291210786024386828110496195538408541399667331347621162040492392564612493395424177880628868686935437933360262424507198720775910419712130236624297480419399634557904200517799815616339247475658150180595343449836054071461833464167813341130592315109715447119872 764504608574974342094191395496278412484539713285082165443494529432292641937325954346460902496796007976171453944485908710775349920745090134567546424243225255200323149094086384649310925036545562839491569765032795614694850406213597787396070969707897802167144121398032648682394223053697624732455404142024007352320000 9174055302899692105130296745955340949814476559420985985321934353187511703247911452157530829961552095714057447333830904529304199048941081614810557090918703062403877789129036615791731100438546754073898837180393547376338204874563173448752851636494773626005729456776391784174135028434678485509372207734347040060080128 110088663634796305261563560951464091397773718713051831823863212238250140438974937425890369959538625148568689368005970854351650388587292979377726685091024436748846533469548439389500773205262561048886786046164722568516058458494758081385034219637937283512068753481316701410088404037198667408505792105981336060040314880 1321063963617555663138762731417569096773284624556621981886358546859001685267699249110684439514463501782824272416071650252219804663047515752532720221092293240986158401634581272674009278463150732586641432553976670822192701501937096976620410635655247402144825041775800416921060747087715886033935615739540130352093724672 15852767563410667957665152777010829161279415494679463782636302562308020223212390989328213274173562021393891268992859803026637655956570189030392642653107518891833900819614975272088111341557808791039697190647720049866312418023245163719444927627862968825737900501309605003052728956606034955501549564746795239027758858240 190233210760928015491981833324129949935352985936153565391635630747696242678548691871938559290082744256726695227914317636319651871478842268364711711837290226702006809835379703265057336098693705492476366287772640598395749016278941964633339131534355625908854806015715260036632747478568539826276454958284235674566659145728 2282798529131136185903781999889559399224235831233842784699627568972354912142584302463262711480992931080720342734971811635835822457746107220376540542047482720424081718024556439180688033184324465909716395453271687180748988195347303575600069578412267510906257672188583120439592969742763821278672281181187719161986039152640 27393582349573634230845383998674712790690829974806113416395530827668258945711011629559152537771915172968644112819661739630029869492953286644518486504569792645088980616294677270168256398211893590916596745439260246168987858344167642907200834940947210130875092066262997445275115636913160967291013609314400704199431313948672 328722988194883610770144607984096553488289959697673360996746369932019107348532139554709830453262982075623729353835940875560358433915439439734221838054837511741067767395536127242019076778542723090999160945271122954027854300130011714886410019291366521570501104795155969343301387642957931200154408831367820789914475671060480 3944675858338603329241735295809158641859479516372080331960956439184229288182385674656517965439155784907484752246031290506724301206985273276810662056658050140892813208746433526904228921342512677091989931343253475448334251601560140578636920231496398258846013257541871632119616651715495174367908093103046767173933816378032128 47336110300063239950900823549709903702313754196464963983531477270210751458188628095878215585269869418889817026952375486080691614483823279321727944679896601690713758504957202322850747056110152125103879176119041705380011019218721686943643042777956779106152159090502459585435399820585942092412068382830447282561785805563494400 568033323600758879410809882596518844427765050357579567802377727242529017498263537150538587023238433026677804323428505832968299373805879351860735336158759220288565102059486427874208964673321825501246550113428500464560132230624660243323716513335481349273825909086029515025224797847031305108944584866098191230447644667514191872 6816399883209106552929718591158226133133180604290954813628532726910348209979162445806463044278861196320133651881142069995619592485670552222328824033905110643462781224713837134490507576079861906014958601361142005574721586767495922919884598160025776191285910909032354180302697574164375661307334998749189363418680587260232990720 81796798598509278635156623093898713597598167251491457763542392722924178519749949349677556531346334355841603822573704839947435109828046626667945888406861327721553374696566045613886090912958342872179503216333704066896659041209951075038615177920309314295430930908388250163632370889972507935688019983353273283411942784726967779328 981561583182111343621879477126784563171178007017897493162508712675090142236999392196130678376156012270099245870884458079369221317936559520015350660882335932658640496358792547366633090955500114466154038596004448802759908494519412900463382135043711771545171170900659001963588450679670095228256239800102862811142294728190627676160 11778738998185336123462553725521414758054136084214769917950104552101081706843992706353568140513872147241190950450613496952430655815238714240184207930588031191903685956305510568399597091466001373593848463152053385633118901934232954805560585620524541258542054050807908023563061408156041142739074877601222985684557451847576449974272 141344867978224033481550644706256977096649633010577239015401254625212980482127912476242817686166465766894291405407361963429167869782864570882210495167056374302844231475666126820795165097592016483126181557824640627597426823210795457666727027446294495102504648609694896282756736897872493712868898531214674880877260248430024809512960 1696138415738688401778607736475083725159795596126926868184815055502555765785534949714913812233997589202731496864888343561150014437394374850586525942004676491634130777707993521849541981171104197797514178693895687531169121878529545492000724329355533941230055783316338755393080842774469924554426782374576098491582337216681889998307328 20353660988864260821343292837701004701917547153523122418217780666030669189426419396578965746807971070432777962378660122733800173248732498207038311304056117899609569332495922262194503774053250373570170144326748250374029462542354545904008691952266407294760669399796065064716970113293639094653121388494913181892409314453142812670033920 244243931866371129856119514052412056423010565842277469018613367992368030273117032758947588961695652845193335548543921472805602078984789978484459735648673414795314831989951067146334045288639004482842041731920979004488353550508254550848104303427196887537128032797552780776603641359523669135837456661938958182708363545758793763097935872 2930927182396453558273434168628944677076126790107329628223360415908416363277404393107371067540347834142320026582527057673667224947817479741813516827784080977543777983879412805756008543463668053794104500783051748053860242606099054610177251641126362650445536393570633369319243696314284029630049479943267498192500316863465615158096691200 35171126188757442699281210023547336124913521481287955538680324990900996359328852717288452810484174009707840318990324692084006699373809756901762201933408971730525335806552953669072102521564016645529254009396620976646322911273188655322127019693516351805346436722847600431830924355771408355560593759319209978310003798554450722730570416128 422053514265089312391374520282568033498962257775455466464163899890811956311946232607461433725810088116494083827883896305008080392485717082821146423200907660766304029678635444028865230258768199746351048112759451719755874935278263863865524236322196221664157240674171205181971092269256900266727125111830519739720045582336147284502962503680 5064642171181071748696494243390816401987547093305465597569966798689743475743354791289537204709721057397929005934606755660096964709828604993853757078410891929195648356143625328346382763105218396956212577353113420637070499223339166366386290835866354659969886888090054462183653107231082803200725501341966236876640546988007328965013559836672 60775706054172860984357930920689796823850565119665587170839601584276921708920257495474446456516652688775148071215281067921163576517943259926245084940930703150347780273723503940156593157262620763474550928237361047644845990680069996396635490030396255919638642657080653546203837286772993638408706016103594842519686563856085744376077552189440 729308472650074331812295171048277561886206781435987046050075219011323060507043089945693357478199832265301776854583372815053962918215319119114941019291168437804173363284682047281879117887151449161694611138848332571738151888160839956759625880364755071035663711884967842554446047441275923660904472193243138110236238766273028748912590195785728 8751701671800891981747542052579330742634481377231844552600902628135876726084517079348320289738397987183621322255000473780647555018583829429379292231494021253650080359416184567382549414645817389940335333666179990860857822657930079481115510564377060852427964542619614110653352569295311083930853666318917657322834865195276344971651053980221440 105020420061610703780970504630951968911613776526782134631210831537630520713014204952179843476860775846203455867060005685367770660223005953152551506777928255043800964312994214808590592975749808679284024003994159890330293871895160953773386126772524730229135574511435369327840230831543733007170243995827011887874018382343316139658537645398556672 1260245040739328445371646055571423626939365318321385615574529978451566248556170459426158121722329310154441470404720068224413247922676071437830618081335139060525611571755930577703087115708997704151408288047929918683963526462741931445280633521270296762749626894137224431934082769978524796086042927949924142654488220588119793675902345494585671680 15122940488871941344459752666857083523272383819856627386894359741418794982674045513113897460667951721853297644856640818692958975072112857253967416976021668726307338861071166932437045388507972449816899456575159024207562317552903177343367602255243561152995522729646693183208993239742297553032515135399089711853858647057437524110828137080844976128 181475285866463296133517032002285002279268605838279528642732316897025539792088546157366769528015420662239571738279689824315507700865354287047609003712260024715688066332854003189244544662095669397802793478901908290490747810634838128120411227062922733835946272755760318198507918876907570636390181624789076542246303764689250289329937644232291123200 2177703430397559553602204384027420027351223270059354343712787802764306477505062553888401234336185047946874860859356277891786092410384251444571308044547120296588256795994248038270934535945148032773633521746822899485888973727618057537444934724755072806031355273069123818382095026522890847636682179497468918506955645176271003471959251730726006095872 26132441164770714643226452608329040328214679240712252124553453633171677730060750646660814812034220575362498330312275334701433108924611017334855696534565443559059081551930976459251214431341776393283602260961874793830667684731416690449339216697060873672376263276829485820585140318274690171640186153969627022083467742115252041663511020768706949201920 313589293977248575718717431299948483938576150888547025494641443598060132760729007759929777744410646904349979963747304016417197307095332208018268358414785322708708978623171717511014573176101316719403227131542497525968012216777000285392070600364730484068515159321953829847021683819296282059682233847635524265001612905383024499962132249224482963427328 3763071527726982908624609175599381807262913810662564305935697323176721593128748093119157332932927762852199759564967648197006367685143986496219220300977423872504507743478060610132174878113215800632838725578509970311616146601324003424704847204376765808822181911863445958164260205831555384716186806171626291180019354864596293999545586990693795525544960 45156858332723794903495310107192581687154965727950771671228367878120659117544977117429887995195133154226397114779611778364076412221727837954630643611729086470054092921736727321586098537358589607594064706942119643739393759215888041096458166452521189705866182942361351497971122469978664616594241674059515494160232258375155527994547043888325546303574272 541882299992685538841943721286310980245859588735409260054740414537447909410539725409158655942341597850716765377355341340368916946660734055455567723340749037640649115060840727859033182448303075291128776483305435724872725110590656493157497997430254276470394195308336217975653469639743975399130900088714185929922787100501866335934564526659906555642644160 6502587599912226466103324655435731762950315064824911120656884974449374912926476704909903871308099174208601184528264096084427003359928808665466812680088988451687789380730088734308398189379636903493545317799665228698472701327087877917889975969163051317644730343700034615707841635676927704789570801064570231159073445206022396031214774319918878667711709328 78031051198946717593239895865228781155403780777898933447882619693392498955117720458918846455697190090503214214339169153013124040319145703985601752161067861420253472568761064811700778272555642841922543813595982744381672415925054535014679711629956615811736764124400415388494099628123132457474849612774842773908881342472268752374577291839026544012540510220 936372614387360611118878750382745373864845369334787201374591436320709987461412645507026157468366281086038570572070029836157488483829748447827221025932814337043041670825132777740409339270667714103070525763151792932580068991100654420176156539559479389740841169492804984661929195537477589489698195353298113286906576109667225028494927502068318528150486122497\n"}, {"input": "14021064691527197542117777666481419913141060406803942267403159673503744\r\n", "output": "YES\n1\n87\n43\n50795305389011627732140031981319872694825517056 306888303391945250881679359887140897531237498880 3657438360596993487088152233321632639140960927744 43887158553821726051433493459415920158755373711360 526645727498082196301066560401287402612486471417856 6319748715381338145919787444722806861408789489254400 75836984583359753733563031729999295506077053190406144 910043815000215686134633512626102013837022269894819840 10920525780002579787059925245835400038357942041372000256 131046309360030956740839463207884981782988110730016849920 1572555712320371480831416921849441463172748395946331602944 18870668547844457769972115009139532698221055006954823352320 226448022574133493239664972771919911973664999604757783904256 2717376270889601918875979639318226070316897690217201732157440 32608515250675223026511755668989978437688848757186429812998144 391302183008102676318141068027644013385090024792452158508236800 4695626196097232115817692816331708516632148950818277152161529856 56347514353166785389812313795980500562586709797595063430110248960 676170172238001424677747765551766006614623927770122072628337311744 8114042066856017096132973186621192079364119084091379980828965601280 97368504802272205153595678239454304952368481671667386029054997037056 1168422057627266461843148138873451659428421701115222867870252248596480 168252776298326370505413331997777038957692724881099079529917927139573760 2019033315579916446064959983973324467492312698573143268719105126596345856 24228399786958997352779519807679893609907752382877715417492602352566272000 290740797443507968233354237692158723318893028594532584692649839966912774144 3488889569322095618800250852305904679826716343134391016285359630580963082240 41866674831865147425603010227670856157920596117612692195422112362886391136256 502400097982381769107236122732050273895047153411352306345065164754296263147520 6028801175788581229286833472784603286740565840936227676140781961751526788562944 72345614109462974751442001673415239440886790091234732113689383539743319098654720 868147369313555697017304020080982873290641481094816785364272602476813578986848256 10417768431762668364207648240971794479487697773137801424371271229721754093659095040 125013221181152020370491778891661533753852373277653617092455254756661048386060550144 1500158654173824244445901346699938405046228479331843405109463057079932580571239219200 18001903850085890933350816160399260860554741751982120861313556684959190966849746681856 216022846201030691200209793924791130326656901023785450335762680219510291602196533186560 2592274154412368294402517527097493563919882812285425404029152162634123499226358362655744 31107289852948419532830210325169922767038593747425104848349825951609481990716300348903680 373287478235381034393962523902039073204463124969101258180197911419313783888595604186597056 4479449738824572412727550286824468878453557499629215098162374937031765406663147250239144080 53753396865894868952730603441893626541442689995550581177948499244381184879957767002869727244 645040762390738427432767241302723518497312279946606974135381990932574218559493204034436726785\n"}, {"input": "2048031753406168394177333476729389434007182478036756630615366381917350903062096110855595740397935283511926597010089777827930347356946566665972974580987613508681940167615502339362060402670146048382716002760342382538588684288\r\n", "output": "YES\n1\n265\n132\n56617993464189312144158511222008749783659750793572788252327213814746843767357334238960745404023461335864509520639697253544019217026758960218112 342067043846143760870957671966302863276277661044502262357810250130762181094450561027054503482641745570848078353864837573495116102870002051317760 4076692119676714465046580025037484181471361986827496215237879975265296177790586944837947838344564297645216437255227090092855300359319099159871488 48917962735580822691775217630569964329502679679787743671766572784324899967208475022431481876514176850975517205146795834381839763238902446130462720 587015357601924893060570633011016251466686017477274406485274874501993911759311819576209124836201739318308949791601889242021041838777418791583219712 7044184274954344968456786597919209740892953364837278001358638160781434867124476011523428776560923506578590959443376032506705749121988241285500108800 84530211298096410142458934091846101450989833807639834776598269568273677399328106652998555258608290631839665143482525170214006760051913830074876428288 1014362535577043944252922000345221182791900871810810725549203785789192167041423479378875780598289254961484029524303803107579209268171970538785923399680 12172350426924517916247015236746243190617812367239656432276280808717798341017872269175083793637386873486092358275188429046368105230359396846921697984512 146068205123094214210398512110338550703839998565668371164455855986217537786924533106486720059186802132995465299634223047869368728932004074694851260579840 1752818461477130570459401672763177911147448836967919828471565312358077449917653569434206116921536472233542446678971673399375170702698023172382531034021888 21033821537725566845507371700444727875661166781463362889533625001673884982051389430890170526076045570688975765404606830527913943928669109258260732067184640 252405858452706802146088006374277283919758316439047715086726403457868032749869968720488687739830680840258248051960027528812918318435387047031601314777792512 3028870301432481625753056038655405786154751823523696527741743750114231510745544065941681472996878014582431521529112392475961515737165591042373588488164474880 36346443617189779509036672460711875965450159551138951995126010577089096055425454161408162444305778662030789303758148048222388730172315504714982592917209612288 436157323406277354108440069528279762129701342752738640080030884056379012492312027051073614729031280818289605898881843190211235640511646757596999409261451673600 5233887880875328249301280834339335249768441065377786282305247171770823971560011539372398015531488864558968615307730790500163375259343416149582093602325331443712 62806654570503938991615370012072021172572294863895512271108372441507743977191160740365402406276459165935914495736198542020096215409887965049853298285502969937920 753679854846047267899384440144864253918813455206692986993587586496447749086166514073376214393642392723833331541504668258909332560943469494869478594014168888639488 9044158258152567214792613281738371047013090288883644747234741631057235890813987550979597188183569119580383508297445209586467672229323701764623013046052371101122560 108529899097830806577511359380860452564156027535470681042092873788778485931582849726930089809491151135539134060385958280910908373543384593494325262379118648583258112 1302358789173969678930136312570325430769872242431387084511387483316682802449145446649425654676501173768184153054699550684753675174753240136291807240701631299279912960 15628305470087636147161635750843905169238466901843789923470505882954472043662257963953629904198231365230019382017233612493195999988058267053365012229432259551049023488 187539665641051633765939629010126862030861602821514407824090558602383187725136471617790269021052127822761216712986873266941364658014284153425202090531604838275895787520 2250475987692619605191275548121522344370339233858121971284290410562509046301736774084345454100181646493134682566574151696381626951017875253501160248360792869616025075712 27005711852311435262295306577458268132444070806297459411861085235694601121754182881901383968022809433969282864299784126397669961000118375159713817577161309002917740544000 324068542227737223147543678929499217589328849675569512588703822854080587841561306382224044159508765680635699927722484042275463735133745824593040802142338357582306673164288 3888822506732846677770524147153990611071946196106834151034976774251112501963778269236639149626041442540378757929013564717764183505199310338672862541642760511783287893524480 46665870080794160133246289765847887332863354353282009812417265532680195477554092780227165680488491998348940958381191422964041753619357920767704048242707684493132422040256512 559990440969529921598955477190174647994360252239384117749006981745634582851814842825174946156276570204175991155843716129431073672728708898937751053724408427113566811759575040 6719885291634359059187465726282095775932323026872609412988083763893737680648541924690636767041186731302110952174730378474328098458519207941396787850927227476462466553387941888 80638623499612308710249588715385149311187876322471312955857005165303695724984733413853352655591396433029664680955481690435366782701045053726273435478312923580141237375011389440 967663481995347704522995064584621791734254515869655755470284061983525918996250320159370707821354853501139670609370673380953020525845775191251073890845353932450244151727999680512 11611961783944172454275940775015461500811054190435869065643408743802301158813039968511876033519113083372408021848940154996080297904602071840557536078903047093526975596004984750080 139343541407330069451311289300185538009732650285230428787720904925627613083327982632692464697201261570582123926731989532821683912488095926215485820395899798447667377633332232716288 1672122496887960833415735471602226456116791803422765145452650859107531356931400083509855405724329464227828256092829266699932600311326557036596562793704886184149120504140092827238400 20065469962655530000988825659226717473401501641073181745431810309290376283171089693111393687805113097849009303861621649758030569849374468265992981270204808260020872047392789429747712 240785639551866360011865907910720609680818019692878180945181723711484515398052600374919484988587453801447700832235099001209603452035281601177485294221269880291103083401856112782213120 2889427674622396320142390894928647316169816236314538171342180684537814184776631164837165716590959953669644042418979157948191344475576944879295287657236806245257474719058368573355327488 34673132095468755841708690739143767794037794835774458056106168214453770217319573974740832923818845319706751145063763059539435808961186135690307240564056805583236716438553430815261327360 416077585145625070100504288869725213528453538029293496673274018573445242607834887696614565446220087659453598960434824478153324680472088861378583869158449594552186182246795587111052378112 4992931021747500841206051466436702562341442456351521960079288222881342911294018652359351832884673880565357569626857032718146570746743220939300914511767209128589012985710226580109954908160 59915172260970010094472617597240430748097309476218263520951458674576114935528223828312220081910255969171950367364087654199451071842675164155174133148028660709231720728418442255884236095488 718982067131640121133671411166885168977167713714619162251417504094913379226338685939746640823530919080262376036022535455525220547352248345935719861026912441107960945816012617345157897912320 8627784805579681453604056934002622027726012564575429947017010049138960550716064231276959689869088349583998426734574882433396963875330325682568107520927163336011963041215067350664773697011712 103533417666956177443248683208031464332712150774905159364204120589667526608592770775323516278427953305059718613673423960614688092946222520318428912683509644535703259135532717869854190940979200 1242401012003474129318984198496377571992545809298861912370449447076010319303113249303882195341135347419887601488485964641660750825891525128165114587404814374803735751513138606910073366839820288 14908812144041689551827810381956530863910549711586342948445393364912123831637358991646586344093624161351915466038865315459452717719909706111676705685124664051009437071648225448960198991706849280 178905745728500274621933724583478370366926596539036115381344720378945485979648307899759036129123489935582424279814469930493392921623017423721261745774518209574893628864236252234692331116284608512 2146868948742003295463204695001740444403119158468433384576136644547345831755779694797108433549481879226935711248385979678002378418558217497186902722423637034978955245037873155720238801996732170240 25762427384904039545558456340020885332837429901621200614913639734568149981069356337565301202593782550723224086638182784512035346302622110667287146150177762629754148915343397712718193193010895781888 309149128618848474546701476080250623994049158819454407378963676814817799772832276050783614431125390608678688668962989333175758056071458953065866113258890994741217010815361515872957928946884925194240 3709789543426181694560417712963007487928589905833452888547564121777813597273987312609403373173504687304144263996664604991361707831227506905545261722394755090493284731770274919085523448248515283648512 44517474521114180334725012555556089855143078870001434662570769461333763167287847751312840478082056247649731167957400987645778211571260916155606046365677733015385973498075460423077117070722674752225280 534209694253370164016700150666673078261716946440017215950849233536005158007454173015754085736984674971796774015488597329061791681988175229974694465196211185512087228369974871859762974489650471305740288 6410516331040441968200401808000076939140603357280206591410190802432061896089450076189049028843816099661561288185863150071850871279119189779371952074755207425255668035972454241215725491345887186858803200 76926195972485303618404821696000923269687240287362479096922289629184742753073400914268588346125793195938735458230357799372469569607368701270769726438095878536327234872963847209496920045939819703238131712 923114351669823643420857860352011079236246883448349749163067475550216913036880810971223060153509518351264825498764293592345489761476585950575762242385569991555365086679007366206872058397093600893935288320 11077372220037883721050294324224132950834962601380196989956809706602602956442569731654676721842114220215177905985171523108135531714901378201519690702387541519424334229165041827790207118918941191098479935488 132928466640454604652603531890689595410019551216562363879481716479231235477310836779856120662105370642582134871822058277297625518460248400651120500411463890034822006849065248052924797295206779124879363932160 1595141599685455255831242382688275144920234614598748366553780597750774825727730041358273447945264447710985618461864699327571506149679766796332853022602801129734674915197040038811717760198162973234527167578112 19141699196225463069974908592259301739042815375184980398645367173009297908732760496299281375343173372531827421542376391930858073790170267055037520189372383094259166551781835220921998138432595814125657244303360 229700390354705556839698903107111620868513784502219764783744406076111574904793125955591376504118080470381929058508516703170296885481544293452037182598980161259230254252166802213995759745862369780783831201087488 2756404684256466682076386837285339450422165414026637177404932872913338898857517511467096518049416965644583148702102200438043562625778489945490411769548304565454773072328567024864860098790737705703678969768837120 33076856211077600184916642047424073405065984968319646128859194474960066786290210137605158216593003587734997784425226405256522751509341875881223771699443033337985944369718018081569730433975551574138670386839027712 396922274532931202218999704569088880860791819619835753546310333699520801435482521651261898599116043052819973413102716863078273018112102510285963496265388348268542054728430818127436049311747177148471921537869414400 4763067294395174426627996454829066570329501835438029042555724004394249617225790259815142783189392516633839680957232602356939276217345230123407501808173999508240230550265487700958282532082969505636563714862416396288 57156807532742093119535957457948798843954022025256348510668688052730995406709483117781713398272710199606076171486791228283271314608142761480888016685837105709634243760979545568451811213357467682626672966382995374080 685881690392905117434431489495385586127448264303076182128024256632771944880513797413380560779272522395272914057841494739399255775297713137770656033145691027816506881561570687917834436295986431659435734628932111040512 8230580284714861409213177873944627033529379171636914185536291079593263338566165568960566729351270268743274968694097936872791069303572557653247872383824596147073157241774666266772047627363145248202221787133213346365440 98766963416578336910558134487335524402352550059642970226435492955119160062793986827526800752215243224919299624329175242473492831642870691838974468604734845749317476456548980035577741061008685317450744193230729157541888 1185203560998940042926697613848026292828230600715715642717225915461429920753527841930321609026582918699031595491950102909681913979714448302067693623256721456657179683274858842496458990193158469004327603881071430640599040 14222442731987280515120371366176315513938767208588587712606710985537159049042334103163859308318995024388379145903401234916182967756573379624812323479080649422191603696447995366796635057106322815151507802703049057749696512 170669312783847366181444456394115786167265206503063052551280531826445908588508009237966311699827940292660549750840814818994195613078880555497747881748967792394824698315471751839629547949841575547409725012114104683834900480 24576381040874020730128001720752673208086189736441079567384396583008210836745153330267148884775223402143119164121077333935164168283358799991675694971851362104178618993705181515451933650981089842410408641675356350990778368000 294916572490488248761536020649032078497034276837292954808612758996098530040941839963205786617302680825717429969452928007221970019400305599900108339662216345250143039339655440972348804546684689547409721750816880191933316595712 3538998869885858985138432247788384941964411322047515457703353107953182360491302079558469439407632169908609159633435136086663640232803667198801300075946596143001716439693798063567096121288125575522123729180695279301536797163520 42467986438630307821661186973460619303572935864570185492440237295438188325895624954701633272891586038903309915601221633039963682793644006385615600911359153716020597273627071160463395994351499348011585339182584411368302982463488 509615837263563693859934243681527431642875230374842225909282847545258259910747499456419599274699032466839718987214659596479564193523728076627387210936309844592247167283299978458698938810459158212951199119275533024732124240936960 6115390047162764326319210924178329179714502764498106710911394170543099118928969993477035191296388389602076627846575915157754770322284736919528646531235718135106966007399581001882148781298696662391815404018730106304144864928858112 73384680565953171915830531090139950156574033173977280530936730046517189427147639921724422295556660675224919534158910981893057243867416843034343758374828617621283592088794970460950598835215458845688151599440379918150351660316098560 880616166791438062989966373081679401878888398087727366371240760558206273125771679060693067546679928102699034409906931782716686926409002116412125100497943411455403105065539645401270920477554764389673349755885860571345937697223999488 10567394001497256755879596476980152822546660777052728396454889126698475277509260148728316810560159137232388412918883181392600243116908025396945501205975320937464837260786475744804406356935237944196198157950847101985613062181140561920 126808728017967081070555157723761833870559929324632740757458669520381703330111121784739801726721909646788660955026598176711202917402896304763346014471703851249578047129437708937651972559156570394647721058816849955088145230324891123712 1521704736215604972846661892685142006446719151895592889089504034244580439961333461416877620720662915761463931460319178120534435008834755657160152173660446214994936565553252507251823595399539987657797097969419423188662808470911293849600 18260456834587259674159942712221704077360629822747114669074048410934965279536001537002531448647954989137567177523830137446413220106017067885921826083925354579939238786639030087021883138518618280470400546071667846907920790459853242892288 219125482015047116089919312546660448928327557872965376028888580931219583354432018444030377383775459869650806130285961649356958641272204814631061913007104254959270865439668361044262597661700430901359542833729900393615380076252315391098880 2629505784180565393079031750559925387139930694475584512346662971174635000253184221328364528605305518435809673563431539792283503695266457775572742956085251059511250385276020332531151171940361588444290742028164628575944588464255624399552512 31554069410166784716948381006719104645679168333707014148159955654095620003038210655940374343263666221229716082761178477507402044343197493306872915473023012714135004623312243990373814063284335429467153590006592694899048397200169812770160640 378648832922001416603380572080629255748150020004484169777919467849147440036458527871284492119163994654756592993134141730088824532118369919682474985676276152569620055479746927884485768759412024850950481803884830434787556877704462946573221888 4543785995064016999240566864967551068977800240053810037335033614189769280437502334455413905429967935857079115917609700761065894385420439036189699828115313830835440665756963134613829225112944298186184501540268441725450597208395424124989603840 54525431940768203990886802379610612827733602880645720448020403370277231365250028013464966865159615230284949391011316409132790732625045268434276397937383765970025287989083557615365950701355331578232112245141025507081073826057073578563717824512 654305183289218447890641628555327353932803234567748645376244840443326776383000336161579602381915382763419392692135796909593488791500543221211316775248605191640303455869002691384391408416263978938785171793913789768837524800981243650186600775680 7851662199470621374687699542663928247193638814812983744514938085319921316596004033938955228582984593161032712305629562915121865498006518654535801302983262299683641470428032296612696900995167747265422046931317267533039017519132953861191041548288 94219946393647456496252394511967138966323665777755804934179257023839055799152048407267462742995815117932392547667554754981462385976078223854429615635799147596203697645136387559352362811942012967185064561959503192922050603555208615505871817932800 1130639356723769477955028734143605667595883989333069659210151084286068669589824580887209552915949781415188710572010657059777548631712938686253155387629589771154444371741636650712228353743304155606220774743412679646941739108772971150168093425139712 13567672280685233735460344809723268011150607871996835910521813011432824035077894970646514634991397376982264526864127884717330583580555264235037864651555077253853332460899639808546740244919649867274649296920943709207623963627451526115691923735838720 162812067368222804825524137716679216133807294463962030926261756137193888420934739647758175619896768523787174322369534616607967002966663170820454375818660927046239989530795677702560882939035798407295791563051323806611847821389599636081109318382911488 1953744808418673657906289652600150593605687533567544371115141073646326661051216875773098107438761222285446091868434415399295604035599958049845452509823931124554879874369548132430730595268429580887549498756615885620685537211496877409864379006724341760 23444937701024083894875475831201807123268250402810532453381692883755919932614602509277177289265134667425353102421212984791547248427199496598145430117887173494658558492434577589168767143221154970650593985079390627443338393484197669066446803679536218112 281339252412289006738505709974421685479219004833726389440580314605071039191375230111326127471181616009104237229054555817498566981126393959177745161414646081935902701909214931070025205718653859647807127820952687529319653384055891623809701165454338293760 3376071028947468080862068519693060225750628058004716673286963775260852470296502761335913529654179392109250846748654669809982803773516727510132941936975752983230832422910579172840302468623846315773685533851432250351835806663857826118634108945560384831488 40512852347369616970344822236316722709007536696056600079443565303130229643558033136030962355850152705311010160983856037719793645282200730121595303243709035798769989074926950074083629623486155789284226406217187004222029677137559507309685781926733645086720 486154228168435403644137866835800672508090440352679200953322783637562755722696397632371548270201832463732121931806272452637523743386408761459143638924508429585239868899123400889003555481833869471410716874606244050664356125414986220540069089335804493299712 5833850738021224843729654402029608070097085284232150411439873403650753068672356771588458579242421989564785463181675269431650284920636905137509723667094101155022878426789480810668042665782006433656928602495274928607972273504960190657549482380880903982284800 70006208856254698124755852824355296841165023410785804937278480843809036824068281259061502950909063874777425558180103233179803419047642861650116684005129213860274541121473769728016511989384077203883143229943299143295667282059520650891516176346308451959308288 840074506275056377497070233892263562093980280929429659247341770125708441888819375108738035410908766497329106698161238798157641028571714339801400208061550566323294493457685236736198143872608926446597718759319589719548007384714247674281604315137012890526023680 10080894075300676529964842806707162745127763371153155910968101241508501302665832501304856424930905197967949280377934865577891692342860572077616802496738606795879533921492222840834377726471307117359172625111835076634576088616570972080011202631559263975230144512 120970728903608118359578113680485952941533160453837870931617214898102015631989990015658277099170862375615391364535218386934700308114326864931401629960863281550554407057906674090012532717655685408310071501342020919614913063398851664959187094149537426810171555840 1451648746843297420314937364165831435298397925446054451179406578777224187583879880187899325190050348507384696374422620643216403697371922379176819559530359378606652884694880089080150392611868224899720858016104251035378956760786219979510166185008684643314342821888 17419784962119569043779248369989977223580775105352653414152878945326690251006558562254791902280604182088616356493071447718596844368463068550121834714364312543279834616338561068961804711342418698796650296193251012424547481129434639754121987641372068679904804208640 209037419545434828525350980439879726682969301264231840969834547343920283012078702747057502827367250185063396277916857372623162132421556822601462016572371750519358015396062732827541656536109024385559803554319012149094569773553215677049463851148237145238868708032512 2508449034545217942304211765278556720195631615170782091638014568127043396144944432964690033928407002220760755335002288471477945589058681871217544198868461006232296184752752793930499878433308292626717642651828145789134837282638588124593566213733160102956425417850880 30101388414542615307650541183342680642347579382049385099656174817524520753739333195576280407140884026649129064020027461657735347068704182454610530386421532074787554217033033527165998541199699511520611711821937749469618047391663057495122794564794114098817938424332288 361216660974511383691806494200112167708170952584592621195874097810294249044871998346915364885690608319789548768240329539892824164824450189455326364637058384897450650604396402325991982494396394138247340541863252993635416568699956689941473534777529051924426997209497600 4334599931694136604301677930401346012498051431015111454350489173723530988538463980162984378628287299837474585218883954478713889977893402273463916375644700618769407807252756827911903789932756729658968086502359035923624998824399480279297682417330348596654674944523763712 52015199180329639251620135164816152149976617172181337452205870084682371862461567761955812543539447598049695022626607453744566679734720827281566996507736407425232893687033081934942845479193080755907617038028308431083499985892793763351572189007964183157652895249119313920 624182390163955671019441621977793825799719406066176049426470441016188462349538813143469750522473371176596340271519289444934800156816649927378803958092836889102794724244396983219314145750316969070891404456339701173001999830713525160218866268095570197891651142649001279488 7490188681967468052233299463733525909596632872794112593117645292194261548194465757721637006269680454119156083258231473339217601881799799128545647497114042669233536690932763798631769749003803628850696853476076414076023997968562301922626395217146842374699798411759646146560 89882264183609616626799593564802310915159594473529351117411743506331138578333589092659644075236165449429872999098777680070611222581597589542547769965368512030802440291193165583581236988045643546208362241712916968912287975622747623071516742605762108496397579666113389658112 1078587170203315399521595122777627730981915133682352213408940922075973662940003069111915728902833985393158475989185332160847334670979171074510573239584422144369629283494317987002974843856547722554500346900555003626947455707472971476858200911269145301956770955887110478888960 12943046042439784794259141473331532771782981604188226560907291064911683955280036829342988746834007824717901711870223985930168016051750052894126878875013065732435551401931815844035698126278572670654004162806660043523369468489675657722298410935229743623481251470636471563583488 155316552509277417531109697679978393261395779250258718730887492778940207463360441952115864962008093896614820542442687831162016192621000634729522546500156788789226616823181790128428377515342872047848049953679920522280433621876107892667580931222756923481775017647636920914411520 1863798630111329010373316372159740719136749351003104624770649913347282489560325303425390379544097126759377846509312253973944194311452007616754270558001881465470719401878181481541140530184114464574176599444159046267365203462513294712010971174673083081781300211771642989485555712 22365583561335948124479796465916888629640992212037255497247798960167389874723903641104684554529165521112534158111747047687330331737424091401051246696022577585648632822538177778493686362209373574890119193329908555208382441550159536544131654096076996981375602541259715868702720000 268387002736031377493757557591002663555691906544447065966973587522008678496686843693256214654349986253350409897340964572247963980849089096812614960352270931027783593870458133341924236346512482898681430319958902662500589298601914438529579849152923963776507230495116590424005644288 3220644032832376529925090691092031962668302878533364791603683050264104141960242124319074575852199835040204918768091574866975567770189069161751379524227251172333403126445497600103090836158149794784177163839506831950007071583222973262354958189835087565318086765941399085088032148480 38647728393988518359101088293104383552019634542400377499244196603169249703522905491828894910226398020482459025217098898403706813242268829941016554290727014068000837517345971201237090033897797537410125966074081983400084858998675679148259498278021050783817041191296789021056382816512 463772740727862220309213059517252602624235614508804529990930359238030996442274865901946738922716776245789508302605186780844481758907225959292198651488724168816010050208151654414845080406773570448921511592888983800801018307984108149779113979336252609405804494295561468252676593551040 5565272888734346643710556714207031231490827374105654359891164310856371957307298390823360867072601314949474099631262241370133781106886711511506383817864690025792120602497819852978140964881282845387058139114667805609612219695809297797349367752035031312869653931546737619032119122591888 66783274664812159724526680570484374777889928489267852318693971730276463487687580689880330404871215779393689195575146896441605373282640538138076605814376280309505447229973838235737691578575394144644697669376013667315346636349711573568192413024420375754435847178560851428385429471100940 801399295977745916694320166845812497334679141871214227824327660763317561852250968278563964858454589352724270346901762757299264479391686457656919269772515363714065366759686058828852298942904729735736372032512164007784159636196538882818308956293044509053230166142730217140625153653211137\n"}, {"input": "98766963416578336910558134487335524402352550059642970226435492955119160062793986837007426479645348701733393608424326084483991011400831258996603882350219635781306984934497931701736363491217572092284684715557285242339328\r\n", "output": "YES\n1\n329\n164\n1935326963990695409045990129169243583468509031739311510940568123967050181633010200027736247474237792265283308973117638973035112647963343872663487539244632324333894587417228214272 11692600407443784762986190363730846650122242066758340378599265748967594847366103291834239828490186661602753325045919068795420472248111869230675237216269653626183946465645753794560 139350261292621703810370476765911820105508582608257301397133893009391387557374071242969328346782184368767986035331737775638295593683388409331328962157347015658722125205802296803328 1672123056878401802945657070557703646291439797783017384836768608114511671470903924227378477695127874461010411268545912386833984618092831410189549722185006785583375066437798665912320 20065470009321400081782985792473007239249388973936536098713820121707624642716048346504520610469346298701774483459598036898605685208271657797125730180911484976807059927584264916303872 240785639555755182518598754588491133827972010303950127141288557862519286094681346929368912232142806568185431263868263700137984711648523033638413023297162103350835265725205402406092800 2889427674622720388684618632151794859848745735532127500191856254050400415668016893716703168861256233066872186621615255006435376247211381665333698301326463930512452400918647680823984128 34673132095468782847420543050579030089344372294042590500176974511913152403227189452147461044841370009656520157080649400960956144942155672089143774784397610390341297912041787407550382080 416077585145625072350980276562344818719729086150815841043613252431566857789993855653065117789638631383616079711436231673271784708470502989411820247010144661619444897369586283493743132672 4992931021747500841393591132077754196107382085361648822110149825702853045892531899689056045579958759209037776356107149984406442415743088783303684209921517050844617878637125804808512471040 59915172260970010094488245902710518384244471111969107426120697141477907446744766598923028766301529709058923717924858497304972727815091819808841030622874853036086354469495683857942449225728 718982067131640121133672713525674342946846643850931732576848273967155195268940064503964208213896858558586290481902599692450680685349949733906858769149816290468532165294435720811996082339840 8627784805579681453604057042532521125556819142086789327877462613294980702052947679490644487151618844540525419605064887786474085553496800798232369096604071990125343976171602609287010212380672 103533417666956177443248683217075622590864717989697772645942491636680528287870844396007990011534830846306095863079298127727444519752736393244734267814816053590212707546779095808072710650593280 1242401012003474129318984198497131251847391856566761296810594311329928069443053088772272568152227587214991466259269787488920147194792067950908973366999089908891611538880742471738258243482288128 14908812144041689551827810381956593670565120215525334563815405436933283644149020644935618875161215181334840788103097300696724334083984751346905360583424187012183426720595525771029214398093721600 178905745728500274621933724583478375600814477414364364682625554718280582630690946370866455506712455853914334723319822595929832222986690344157530800349376503154991461334981860594864749066816847872 2146868948742003295463204695001740444839276481874710738684576714075623756476699914669700718497614293053463370452011425733455415027005190240556591810304875226110630064410435289750253170159276523520 25762427384904039545558456340020885332873776345238390394422676407028839808129433022554683893006126918542101391571818238349989766019992691729234620240834532479015121816957777890554027723691107811328 309149128618848474546701476080250623994052187689755839860589429870856190591753949107866062988659752639330261777707458954328920924381239834821028402766445725561988758557162714221110915157774942863360 3709789543426181694560417712963007487928590158239311341254366267865816796508897452030826910553299217473365228422393310793124471403586655312358191913187051318061682377415425018947869530432756118454272 44517474521114180334725012555556089855143078891035256200296336306841096767224090262931292439530372458497166248326211713129258441868957511856173790548243757701016673301879222931398979244238028155125760 534209694253370164016700150666673078261716946441770034412326364106464102474115526558388956733772034656034060272185998222852081701179649946283075110544758354235889786686958518735456463004110084089315328 6410516331040441968200401808000076939140603357280352659615313896646266808128338522317601934760215046301914395373921266813000062114051812672397650461867586355982651582498869545122033282055425487924101120 76926195972485303618404821696000923269687240287362491269272716553702593162409974951445967754952159774825431550496029309100898668843613086511855201303688576780554483501841048484822445695165614561660239872 923114351669823643420857860352011079236246883448349750177430011127260067237658858807654508437578382232838716839786432884822858853079606316012519365291036049742384024064747132979815852201195750465470464000 11077372220037883721050294324224132950834962601380196990041339917900689885959301235641046009199119958871975730263590034715841979139201629898639420462629663690939919140613853475021285768402616370229441200128 132928466640454604652603531890689595410019551216562363879488760663506076054770564405188318102718454454136868023845259819931601055745606754959213811224817400215781638925019315690194053849330418723140277370880 1595141599685455255831242382688275144920234614598748366553781184766131062442518351993717797731982204695281846224533299456124337444453546659191860798503913922249754884536702877781490198244339943201048910364672 19141699196225463069974908592259301739042815375184980398645367221927244261792326188852235071158733185613852107189265441941570809731401415376942437504030809160302089882560140457502812508269777228289534056202240 229700390354705556839698903107111620868513784502219764783744406080188070434214756429970789312102710454805431115645757457337856280143313555812195925708535030098067164529731660983710827610015468231964154268745728 2756404684256466682076386837285339450422165414026637177404932872913678606818302647339961469116749018143285107206863637167557525908666970717353758331474100804524676148185030763095669687779417130574610663357808640 33076856211077600184916642047424073405065984968319646128859194474960095095286942232261230295848614592109889614300623191650648915116249249278879050579603516357908436292706056726422297899724608192877914694638108672 396922274532931202218999704569088880860791819619835753546310333699520803794565582659149904605720677303184547732258999928611116865079344791402434769505401721853535595722013154681173763267226265200033525230186004480 4763067294395174426627996454829066570329501835438029042555724004394249617422380514899133450356609569488036728817162292612400346537925833646833874414277333956038980012014952895671094008245926096307527181836776112128 57156807532742093119535957457948798843954022025256348510668688052730995406725865639038712620536644954010592592141785369137893070468191145107840214403012383580284139549458667668011212169704380731849253255297525350400 685881690392905117434431489495385586127448264303076182128024256632771944880515162623485310714461183624806623759562744251137140921619383836406235382955455634305727706210610614759464386375682007746870949653008321871872 8230580284714861409213177873944627033529379171636914185536291079593263338566165682728075458512535990512402777835908040998769226399099363544800837329642076530947258977162086260675516789869786546209508055051886363934720 1185203560998940042926697613848026292828230600715715642717225915461429920753527841931111661170535427488766103323958032146516122161360945015997496074402178522493178808981354588468638875395675876235563765591265310314332160 14222442731987280515120371366176315513938767208588587712606710985537159049042334103163925145997657733454190354889401895685919151771710587684306473683342770844344603623590203345627650047539865932420777482845565214389174272 170669312783847366181444456394115786167265206503063052551280531826445908588508009237966317186301162185082700684922981540725006961746808656169372394265989635846670781642733602504532132532377704140515497485459314363554856960 2048031753406168394177333476729389434007182478036756630615366381917350903062096110855595740855141385336295109587929958388074581636002227341028943290364031995636260674559440826917468951385357392432141483799787816678565347328 24576381040874020730128001720752673208086189736441079567384396583008210836745153330267148884813323910628483206835897348981842854473280105047930359030966063644758145702617176389414884363374024121081194098428643470502443089920 294916572490488248761536020649032078497034276837292954808612758996098530040941839963205786617305855868091210306345829675142526576582799041988129561667142570378524666565398107211845717106050767403965620538879654118559288655872 3538998869885858985138432247788384941964411322047515457703353107953182360491302079558469439407632434495473641328176211225657019945902208318975301844447006661762414908629276619087054197334739415343503387413033843795422294835200 42467986438630307821661186973460619303572935864570185492440237295438188325895624954701633272891586060952215289075783389301546464436402218145630101058734187925917322146038361040090059167355383834663366977368612625076126773936128 509615837263563693859934243681527431642875230374842225909282847545258259910747499456419599274699032468677127768337539742834696091993957927607388419281924430776405227689334252615334494074876148586838847589124368709207776223559680 6115390047162764326319210924178329179714502764498106710911394170543099118928969993477035191296388389602229745245002821836617697980490589407110313298597852683955645845766750524728535077570731411589639374724550842611184502594076672 73384680565953171915830531090139950156574033173977280530936730046517189427147639921724422295556660675224932293942113224116295821172267330741642230605442128833687648741992234587854464359904795074787970263665864979509271630121533440 880616166791438062989966373081679401878888398087727366371240760558206273125771679060693067546679928102699035473222198636235290141184406323721066639850494537389770109786639417411846242604612209075431667977904650993125847694707785728 10567394001497256755879596476980152822546660777052728396454889126698475277509260148728316810560159137232388413007492786963726793384805975747554579667588033531292701177846567392471954300445826064586678017802682001187428054680930877440 126808728017967081070555157723761833870559929324632740757458669520381703330111121784739801726721909646788660955033982310508796796591887800625896771010171577299063702455859383241624268221115786071346927713804502863354963146366540316672 1521704736215604972846661892685142006446719151895592889089504034244580439961333461416877620720662915761463931460319793465017567832100504948482031403371985192165727036830454313443821286704703255630855365190668394264351709963914764615680 18260456834587259674159942712221704077360629822747114669074048410934965279536001537002531448647954989137567177523830188725120147841289213660198649353067982828036804659245463570871216279460715219468155401673438594497561532250936865456128 219125482015047116089919312546660448928327557872965376028888580931219583354432018444030377383775459869650806130285961653630184218583477493445584981612866140646612329262385563834583375423445605646276022405030047955914516804734905692979200 2629505784180565393079031750559925387139930694475584512346662971174635000253184221328364528605305518435809673563431539792639605826709063832140619878469064549985195507261246766097011236753840353006367115325772974206136183191629173591375872 31554069410166784716948381006719104645679168333707014148159955654095620003038210655940374343263666221229716082761178477507431719520817710478253571883221663838341166716811012859837635735352125326513993287781393390368231030094117608536145920 378648832922001416603380572080629255748150020004484169777919467849147440036458527871284492119163994654756592993134141730088827005049838271113423373710459373496637235654205158623607753898751007342371051778699397159409988763778958596220387328 4543785995064016999240566864967551068977800240053810037335033614189769280437502334455413905429967935857079115917609700761065894591498061398808945527118162432579358764104834653842089390541222546727136215704836322285835799865568298762460200960 54525431940768203990886802379610612827733602880645720448020403370277231365250028013464966865159615230284949391011316409132790732642218403631161335078967336686837281163945880241968305715141021432277191554654739497127772592945171318116840374272 654305183289218447890641628555327353932803234567748645376244840443326776383000336161579602381915382763419392692135796909593488791501974315811057186677070489200037788633574551603274938000746119759955595069706599268008083031555251795149360988160 7851662199470621374687699542663928247193638814812983744514938085319921316596004033938955228582984593161032712305629562915121865498006637912419113003935634407813619331491746618297603861793874592333852915537633334991303230705014121206604604899328 94219946393647456496252394511967138966323665777755804934179257023839055799152048407267462742995815117932392547667554754981462385976078233792586558277545178605214529133558363752826105058675238537607433801010029531876905954654032046117989614878720 1130639356723769477955028734143605667595883989333069659210151084286068669589824580887209552915949781415188710572010657059777548631712938687081335132849735273738528607699005148728351165597198591070422638846666890175187977054697873102719103241551872 13567672280685233735460344809723268011150607871996835910521813011432824035077894970646514634991397376982264526864127884717330583580555264235106879630323422712402006147229420516714750479240807736896666118929548226751644483456278601278404507887206400 162812067368222804825524137716679216133807294463962030926261756137193888420934739647758175619896768523787174322369534616607967002966663170820460127066891622501119045671323159428241550458562561563097626298218707516407182864708668559011335367062192128 1953744808418673657906289652600150593605687533567544371115141073646326661051216875773098107438761222285446091868434415399295604035599958049845452989094617015842786462381258755907870650895056811150532984984546500929835148465106799820108564510780948480 23444937701024083894875475831201807123268250402810532453381692883755919932614602509277177289265134667425353102421212984791547248427199496598145430157826397318932550708102220141125195481190040573172509275598384845385767527755331829267300485804874268672 281339252412289006738505709974421685479219004833726389440580314605071039191375230111326127471181616009104237229054555817498566981126393959177745161417974350587925534593853901282688241413484600114683954095162603714148189145245152803826438972298116464640 3376071028947468080862068519693060225750628058004716673286963775260852470296502761335913529654179392109250846748654669809982803773516727510132941936976030338951834325634299087024691054931748877479258602707616410033904851310623597883635503762797366345728 40512852347369616970344822236316722709007536696056600079443565303130229643558033136030962355850152705311010160983856037719793645282200730121595303243709058911746739233487260066932328672345147669426357495288535684195535430858123321623435898161503393546240 486154228168435403644137866835800672508090440352679200953322783637562755722696397632371548270201832463732121931806272452637523743386408761459143638924508431511321264745670093388407613735905452128089227798695523107328814938225033205066214932355368639004672 5833850738021224843729654402029608070097085284232150411439873403650753068672356771588458579242421989564785463181675269431650284920636905137509723667094101155183385209776693035042993003969845732211651811738949035196027645072694361239593327867799200994426880 70006208856254698124755852824355296841165023410785804937278480843809036824068281259061502950909063874777425558180103233179803419047642861650116684005129213860287916686722704080047757850899730478762703497380271985511338563023498498440019830136884976710320128 840074506275056377497070233892263562093980280929429659247341770125708441888819375108738035410908766497329106698161238798157641028571714339801400208061550566323295608088122647932200747694401897552837682114939337456399313324794579161577312952952894267588608000 10080894075300676529964842806707162745127763371153155910968101241508501302665832501304856424930905197967949280377934865577891692342860572077616802496738606795879534014378092625100711276789789864951359288724803388945980364111577666370619178351377254089985359872 120970728903608118359578113680485952941533160453837870931617214898102015631989990015658277099170862375615391364535218386934700308114326864931401629960863281550554407065647163238701393846848892303942753723309768278974196753023435556150071092126188925986401157120 1451648746843297420314937364165831435298397925446054451179406578777224187583879880187899325190050348507384696374422620643216403697371922379176819559530359378606652884695525129842541131039300992141023581534601563315325563734921601970442739851506738934912361955328 17419784962119569043779248369989977223580775105352653414152878945326690251006558562254791902280604182088616356493071447718596844368463068550121834714364312543279834616338614822358670606211371429400092189819792455114543031710612588253366368780246906537537972469760 209037419545434828525350980439879726682969301264231840969834547343920283012078702747057502827367250185063396277916857372623162132421556822601462016572371750519358015396062737306991395360681437113110090378787890602652069402768313839424400882909810048393671472054272 2508449034545217942304211765278556720195631615170782091638014568127043396144944432964690033928407002220760755335002288471477945589058681871217544198868461006232296184752752794303787356668689327020680166553867218993597962251739846304791477633046624511552658981519360 30101388414542615307650541183342680642347579382049385099656174817524520753739333195576280407140884026649129064020027461657735347068704182454610530386421532074787554217033033527197105831052647931053441922147107672236656641139088162343472620516403569466200957887971328 361216660974511383691806494200112167708170952584592621195874097810294249044871998346915364885690608319789548768240329539892824164824450189455326364637058384897450650604396402325994574768550806506541743059390350487199336451512242115345502686940163173205042248831467520 4334599931694136604301677930401346012498051431015111454350489173723530988538463980162984378628287299837474585218883954478713889977893402273463916375644700618769407807252756827911904005955602930689659286712152960714755325481300504064748018180010568106761392882158927872 52015199180329639251620135164816152149976617172181337452205870084682371862461567761955812543539447598049695022626607453744566679734720827281566996507736407425232893687033081934942845497194984605993507971379124591482760846447535515333693050321520868116828455077255577600 624182390163955671019441621977793825799719406066176049426470441016188462349538813143469750522473371176596340271519289444934800156816649927378803958092836889102794724244396983219314145751817127725065228700785602519701938235759753639550709673205033254971582439301345968128 7490188681967468052233299463733525909596632872794112593117645292194261548194465757721637006269680454119156083258231473339217601881799799128545647497114042669233536690932763798631769749003928642071878005496446905854915659502316154295904048834239297629456459353147341537280 89882264183609616626799593564802310915159594473529351117411743506331138578333589092659644075236165449429872999098777680070611222581597589542547769965368512030802440291193165583581236988045653963976794004381281176560528947417227110769289880407186479767627301411229030940672 1078587170203315399521595122777627730981915133682352213408940922075973662940003069111915728902833985393158475989185332160847334670979171074510573239584422144369629283494317987002974843856547723422647716214110700644251475788455844767499682006085930666229373432699203448995840 12943046042439784794259141473331532771782981604188226560907291064911683955280036829342988746834007824717901711870223985930168016051750052894126878875013065732435551401931815844035698126278572670726349776916123018274811470163090897163185201026464475737170635010370812644425728 155316552509277417531109697679978393261395779250258718730887492778940207463360441952115864962008093896614820542442687831162016192621000634729522546500156788789226616823181790128428377515342872047854078754855709103509720455348892495954321497063693151157915799609281449337815040 1863798630111329010373316372159740719136749351003104624770649913347282489560325303425390379544097126759377846509312253973944194311452007616754270558001881465470719401878181481541140530184114464574177101844257028649134310698636026762284866221826494434087645276935113366854172672 22365583561335948124479796465916888629640992212037255497247798960167389874723903641104684554529165521112534158111747047687330331737424091401051246696022577585648632822538177778493686362209373574890119235196583387073529867153169764214987812016673114594067797963356671733483438080 268387002736031377493757557591002663555691906544447065966973587522008678496686843693256214654349986253350409897340964572247963980849089096812614960352270931027783593870458133341924236346512482898681430323447792231822684917402165290835484528979640306910898246780291336746070704128 3220644032832376529925090691092031962668302878533364791603683050264104141960242124319074575852199835040204918768091574866975567770189069161751379524227251172333403126445497600103090836158149794784177163839797572747450579551456327500047116913153980593912619350631830313948204236800 38647728393988518359101088293104383552019634542400377499244196603169249703522905491828894910226398020482459025217098898403706813242268829941016554290727014068000837517345971201237090033897797537410125966074106211799871817996028458668067178171630958536199918906687658290128063823872 463772740727862220309213059517252602624235614508804529990930359238030996442274865901946738922716776245789508302605186780844481758907225959292198651488724168816010050208151654414845080406773570448921511592888985819834333887900554214739097952660720101718503067438510707358432566968320 5565272888734346643710556714207031231490827374105654359891164310856371957307298390823360867072601314949474099631262241370133781106886711511506383817864690025792120602497819852978140964881282845387058139114667805777864995994135668302762699749812070270562378812641983388957598787043328 66783274664812159724526680570484374777889928489267852318693971730276463487687580689880330404871215779393689195575146896441605373282640538138076605814376280309505447229973838235737691578575394144644697669376013667329367701041238771110310190690901795667576907585318788575879219443138560 801399295977745916694320166845812497334679141871214227824327660763317561852250968278563964858454589352724270346901762757299264479391686457656919269772515363714065366759686058828852298942904729735736372032512164007785328058254166149280152104431917960712658587843293378569582969484214272 9616791551732951000331842002149749968016149702454570733891931929159810742227011619342767578301455072232691244162821153087591173752700237491883031237270184364568784401116232705946227587314856756828836464390145968093410013002863268866024861071194773562943714362187809535806581661824450560 115401498620795412003982104025796999616193796429454848806703183149917728906724139432113210939617460866792294929953853837051094085032402849902596374847242212374825412813394792471354731047778281081946037572681751617120918995726343665981853585839171595924857223288592738512426612110894563328 1384817983449544944047785248309563995394325557153458185680438197799012746880689673185358531275409530401507539159446246044613129020388834198831156498166906548497904953760737509656256772573339372983352450872181019405451027852023789361748039301152128677195747733708307780822681648011484856320 16617815801394539328573422979714767944731906685841498228165258373588152962568276078224302375304914364818090469913354952535357548244666010385973877978002878581974859445128850115875081270880072475800229410466172232865412334216227777788473621303082383253523761225686792946428309968027880783872 199413789616734471942881075756577215336782880230097978737983100483057835550819312938691628503658972377817085638960259430424290578935992124631686535736034542983698313341546201390500975250560869709602752925594066794384948010594061858915641551444426668969549700410007106988519397132325407948800 2392965475400813663314572909078926584041394562761175744855797205796694026609831755264299542043907668533805027667523113165091486947231905495580238428832414515804379760098554416686011703006730436515233035107128801532619376127128686350775528458650406533461868452061899083164847738714237465264128 28715585704809763959774874908947119008496734753134108938269566469560328319317981063171594504526892022405660332010277357981097843366782865946962861145988974189652557121182653000232140436080765238182796421285545618391432513525544231546288660657247985610361360762004606814586724112331377297326080 344587028457717167517298498907365428101960817037609307259234797634723939831815772758059134054322704268867923984123328295773174120401394391363554333751867690275830685454191836002785685232969182858193557055426547420697190162306530778166879121149762752925071240755493766593091401951956571544092672 4135044341492606010207581986888385137223529804451311687110817571616687277981789273096709608651872451226415087809479939549278089444816732696362652005022412283309968225450302032033428222795630194298322684665118569048366281947678369337970167386569051945567582798366878406185267716140477195527127040 49620532097911272122490983842660621646682357653415740245329810859400247335781471277160515303822469414716981053713759274591337073337800792356351824060268947399719618705403624384401138673547562331579872215981422828580395383372140432055639310133226281589349887572844286974812226834745476207742025728 595446385174935265469891806111927459760188291840988882943957730312802968029377655325926183645869632976603772644565111295096044880053609508276221888723227368796635424464843492612813664082570747978958466591777073942964744600465685184667671496723248517259076892040168255872795806537034026981355683840 7145356622099223185638701673343129517122259502091866595327492763753635616352531863911114203750435595719245271734781335541152538560643314099314662664678728425559625093578121911353763968990848975747501599101324887315576935205588222216012057941939359968624495891245855471488137102154415683150305820672 85744279465190678227664420080117554205467114025102399143929913165043627396230382366933370445005227148630943260817376026493830462727719769191775951976144741106715501122937462936245167627890187708970019189215898647786923222467058666592144695301710684436953581793847252024608860844495488811084839649280 1028931353582288138731973040961410650465605368301228789727158957980523528754764588403200445340062725783571319129808512317925965552732637230301311423713736893280586013475249555234942011534682252507640230270590783773443078669604703999105736343620398076977897950784408439825868931435499407450791506608128 12347176242987457664783676491536927805587264419614745476725907495766282345057175060838405344080752709402855829557702147815111586632791646763615737084564842719367032161702994662819304138416187030091682763247089405281316944035256447989268836123444766079045979990184421395871307394001122351219312531865600 148166114915849491977404117898443133667047173035376945720710889949195388140686100730060864128969032512834269954692425773781339039593499761163388845014778112632404385940435935953831649660994244361100193158965072863375803328423077375871226033481337192044827693597277350093619095412744729003115901586767872 1777993378990193903728849414781317604004566076424523348648530679390344657688233208760730369547628390154011239456309109285376068475121997133960666140177337351588852631285231231445979795931930932333202317907580874360509639941076928510454712401776046304462621984310250225568692762176664353103097831641579520 21335920547882326844746192977375811248054792917094280183782368152684135892258798505128764434571540681848134873475709311424512821701463965607527993682128048219066231575422774777351757551183171187998427814890970492326115679292923142125456548821312555653545187950151579542194751780888616204325982897415651328 256031046574587922136954315728509734976657515005131362205388417832209630707105582061545173214858488182177618481708511737094153860417567587290335924185536578628794778905073297328221090614198054255981133778691645907913388151515077705505478585855750667842541732413354669242617891256894114782502528845464207360 3072372558895055065643451788742116819719890180061576346464661013986515568485266984738542078578301858186131421780502140845129846325010811047484031090226438943545537346860879567938653087370376651071773605344299750894960657818180932466065743030269008014110500745377884007139438100906581937417579573985276854272 36868470706740660787721421464905401836638682160738916157575932167838186821823203816862504942939622298233577061366025690141558155900129732569808373082717267322546448162330554815263837048444519812861283264131597010739527893818171189592788916363228096169326008940902743750358925828030970962346583990143297781760 442421648480887929452657057578864822039664185928866993890911186014058241861878445802350059315275467578802924736392308281698697870801556790837700476992607207870557377947966657783166044581334237754335399169579164128874334725818054275113466996358737154031912107290530269643030915654467650524270310306912904675328 5309059781770655153431884690946377864475970231146403926690934232168698902342541349628200711783305610945635096836707699380384374449618681490052405723911286494446688535375599893397992534976010853052024790034949969546492016709816651301361603956304845848382945287486338014436264638330119806205919665551720967045120 63708717381247861841182616291356534373711642773756847120291210786024386828110496195538408541399667331347621162040492392564612493395424177880628868686935437933360262424507198720775910419712130236624297480419399634557904200517799815616339247475658150180595343449836054071461833464167813341130592315109715447119872 764504608574974342094191395496278412484539713285082165443494529432292641937325954346460902496796007976171453944485908710775349920745090134567546424243225255200323149094086384649310925036545562839491569765032795614694850406213597787396070969707897802167144121398032648682394223053697624732455404142024007352320000 9174055302899692105130296745955340949814476559420985985321934353187511703247911452157530829961552095714057447333830904529304199048941081614810557090918703062403877789129036615791731100438546754073898837180393547376338204874563173448752851636494773626005729456776391784174135028434678485509372207734347040060080128 110088663634796305261563560951464091397773718713051831823863212238250140438974937425890369959538625148568689368005970854351650388587292979377726685091024436748846533469548439389500773205262561048886786046164722568516058458494758081385034219637937283512068753481316701410088404037198667408505792105981336060040314880 1321063963617555663138762731417569096773284624556621981886358546859001685267699249110684439514463501782824272416071650252219804663047515752532720221092293240986158401634581272674009278463150732586641432553976670822192701501937096976620410635655247402144825041775800416921060747087715886033935615739540130352093724672 15852767563410667957665152777010829161279415494679463782636302562308020223212390989328213274173562021393891268992859803026637655956570189030392642653107518891833900819614975272088111341557808791039697190647720049866312418023245163719444927627862968825737900501309605003052728956606034955501549564746795239027758858240 190233210760928015491981833324129949935352985936153565391635630747696242678548691871938559290082744256726695227914317636319651871478842268364711711837290226702006809835379703265057336098693705492476366287772640598395749016278941964633339131534355625908854806015715260036632747478568539826276454958284235674566659145728 2282798529131136185903781999889559399224235831233842784699627568972354912142584302463262711480992931080720342734971811635835822457746107220376540542047482720424081718024556439180688033184324465909716395453271687180748988195347303575600069578412267510906257672188583120439592969742763821278672281181187719161986039152640 27393582349573634230845383998674712790690829974806113416395530827668258945711011629559152537771915172968644112819661739630029869492953286644518486504569792645088980616294677270168256398211893590916596745439260246168987858344167642907200834940947210130875092066262997445275115636913160967291013609314400704199431313948672 328722988194883610770144607984096553488289959697673360996746369932019107348532139554709830453262982075623729353835940875560358433915439439734221838054837511741067767395536127242019076778542723090999160945271122954027854300130011714886410019291366521570501104795155969343301387642957931200154408831367820789914475671060480 3944675858338603329241735295809158641859479516372080331960956439184229288182385674656517965439155784907484752246031290506724301206985273276810662056658050140892813208746433526904228921342512677091989931343253475448334251601560140578636920231496398258846013257541871632119616651715495174367908093103046767173933816378032128 47336110300063239950900823549709903702313754196464963983531477270210751458188628095878215585269869418889817026952375486080691614483823279321727944679896601690713758504957202322850747056110152125103879176119041705380011019218721686943643042777956779106152159090502459585435399820585942092412068382830447282561785805563494400 568033323600758879410809882596518844427765050357579567802377727242529017498263537150538587023238433026677804323428505832968299373805879351860735336158759220288565102059486427874208964673321825501246550113428500464560132230624660243323716513335481349273825909086029515025224797847031305108944584866098191230447644667514191872 6816399883209106552929718591158226133133180604290954813628532726910348209979162445806463044278861196320133651881142069995619592485670552222328824033905110643462781224713837134490507576079861906014958601361142005574721586767495922919884598160025776191285910909032354180302697574164375661307334998749189363418680587260232990720 81796798598509278635156623093898713597598167251491457763542392722924178519749949349677556531346334355841603822573704839947435109828046626667945888406861327721553374696566045613886090912958342872179503216333704066896659041209951075038615177920309314295430930908388250163632370889972507935688019983353273283411942784726967779328 981561583182111343621879477126784563171178007017897493162508712675090142236999392196130678376156012270099245870884458079369221317936559520015350660882335932658640496358792547366633090955500114466154038596004448802759908494519412900463382135043711771545171170900659001963588450679670095228256239800102862811142294728190627676160 11778738998185336123462553725521414758054136084214769917950104552101081706843992706353568140513872147241190950450613496952430655815238714240184207930588031191903685956305510568399597091466001373593848463152053385633118901934232954805560585620524541258542054050807908023563061408156041142739074877601222985684557451847576449974272 141344867978224033481550644706256977096649633010577239015401254625212980482127912476242817686166465766894291405407361963429167869782864570882210495167056374302844231475666126820795165097592016483126181557824640627597426823210795457666727027446294495102504648609694896282756736897872493712868898531214674880877260248430024809512960 1696138415738688401778607736475083725159795596126926868184815055502555765785534949714913812233997589202731496864888343561150014437394374850586525942004676491634130777707993521849541981171104197797514178693895687531169121878529545492000724329355533941230055783316338755393080842774469924554426782374576098491582337216681889998307328 20353660988864260821343292837701004701917547153523122418217780666030669189426419396578965746807971070432777962378660122733800173248732498207038311304056117899609569332495922262194503774053250373570170144326748250374029462542354545904008691952266407294760669399796065064716970113293639094653121388494913181892409314453142812670033920 244243931866371129856119514052412056423010565842277469018613367992368030273117032758947588961695652845193335548543921472805602078984789978484459735648673414795314831989951067146334045288639004482842041731920979004488353550508254550848104303427196887537128032797552780776603641359523669135837456661938958182708363545758793763097935872 2930927182396453558273434168628944677076126790107329628223360415908416363277404393107371067540347834142320026582527057673667224947817479741813516827784080977543777983879412805756008543463668053794104500783051748053860242606099054610177251641126362650445536393570633369319243696314284029630049479943267498192500316863465615158096691200 35171126188757442699281210023547336124913521481287955538680324990900996359328852717288452810484174009707840318990324692084006699373809756901762201933408971730525335806552953669072102521564016645529254009396620976646322911273188655322127019693516351805346436722847600431830924355771408355560593759319209978310003798554450722730570416128 422053514265089312391374520282568033498962257775455466464163899890811956311946232607461433725810088116494083827883896305008080392485717082821146423200907660766304029678635444028865230258768199746351048112759451719755874935278263863865524236322196221664157240674171205181971092269256900266727125111830519739720045582336147284502962503680 5064642171181071748696494243390816401987547093305465597569966798689743475743354791289537204709721057397929005934606755660096964709828604993853757078410891929195648356143625328346382763105218396956212577353113420637070499223339166366386290835866354659969886888090054462183653107231082803200725501341966236876640546988007328965013559836672 60775706054172860984357930920689796823850565119665587170839601584276921708920257495474446456516652688775148071215281067921163576517943259926245084940930703150347780273723503940156593157262620763474550928237361047644845990680069996396635490030396255919638642657080653546203837286772993638408706016103594842519686563856085744376077552189440 729308472650074331812295171048277561886206781435987046050075219011323060507043089945693357478199832265301776854583372815053962918215319119114941019291168437804173363284682047281879117887151449161694611138848332571738151888160839956759625880364755071035663711884967842554446047441275923660904472193243138110236238766273028748912590195785728 8751701671800891981747542052579330742634481377231844552600902628135876726084517079348320289738397987183621322255000473780647555018583829429379292231494021253650080359416184567382549414645817389940335333666179990860857822657930079481115510564377060852427964542619614110653352569295311083930853666318917657322834865195276344971651053980221440 105020420061610703780970504630951968911613776526782134631210831537630520713014204952179843476860775846203455867060005685367770660223005953152551506777928255043800964312994214808590592975749808679284024003994159890330293871895160953773386126772524730229135574511435369327840230831543733007170243995827011887874018382343316139658537645398556672 1260245040739328445371646055571423626939365318321385615574529978451566248556170459426158121722329310154441470404720068224413247922676071437830618081335139060525611571755930577703087115708997704151408288047929918683963526462741931445280633521270296762749626894137224431934082769978524796086042927949924142654488220588119793675902345494585671680 15122940488871941344459752666857083523272383819856627386894359741418794982674045513113897460667951721853297644856640818692958975072112857253967416976021668726307338861071166932437045388507972449816899456575159024207562317552903177343367602255243561152995522729646693183208993239742297553032515135399089711853858647057437524110828137080844976128 181475285866463296133517032002285002279268605838279528642732316897025539792088546157366769528015420662239571738279689824315507700865354287047609003712260024715688066332854003189244544662095669397802793478901908290490747810634838128120411227062922733835946272755760318198507918876907570636390181624789076542246303764689250289329937644232291123200 2177703430397559553602204384027420027351223270059354343712787802764306477505062553888401234336185047946874860859356277891786092410384251444571308044547120296588256795994248038270934535945148032773633521746822899485888973727618057537444934724755072806031355273069123818382095026522890847636682179497468918506955645176271003471959251730726006095872 26132441164770714643226452608329040328214679240712252124553453633171677730060750646660814812034220575362498330312275334701433108924611017334855696534565443559059081551930976459251214431341776393283602260961874793830667684731416690449339216697060873672376263276829485820585140318274690171640186153969627022083467742115252041663511020768706949201920 313589293977248575718717431299948483938576150888547025494641443598060132760729007759929777744410646904349979963747304016417197307095332208018268358414785322708708978623171717511014573176101316719403227131542497525968012216777000285392070600364730484068515159321953829847021683819296282059682233847635524265001612905383024499962132249224482963427328 3763071527726982908624609175599381807262913810662564305935697323176721593128748093119157332932927762852199759564967648197006367685143986496219220300977423872504507743478060610132174878113215800632838725578509970311616146601324003424704847204376765808822181911863445958164260205831555384716186806171626291180019354864596293999545586990693795525544960 45156858332723794903495310107192581687154965727950771671228367878120659117544977117429887995195133154226397114779611778364076412221727837954630643611729086470054092921736727321586098537358589607594064706942119643739393759215888041096458166452521189705866182942361351497971122469978664616594241674059515494160232258375155527994547043888325546303574272 541882299992685538841943721286310980245859588735409260054740414537447909410539725409158655942341597850716765377355341340368916946660734055455567723340749037640649115060840727859033182448303075291128776483305435724872725110590656493157497997430254276470394195308336217975653469639743975399130900088714185929922787100501866335934564526659906555642644160 6502587599912226466103324655435731762950315064824911120656884974449374912926476704909903871308099174208601184528264096084427003359928808665466812680088988451687789380730088734308398189379636903493545317799665228698472701327087877917889975969163051317644730343700034615707841635676927704789570801064570231159073445206022396031214774319918878667711709328 78031051198946717593239895865228781155403780777898933447882619693392498955117720458918846455697190090503214214339169153013124040319145703985601752161067861420253472568761064811700778272555642841922543813595982744381672415925054535014679711629956615811736764124400415388494099628123132457474849612774842773908881342472268752374577291839026544012540510220 936372614387360611118878750382745373864845369334787201374591436320709987461412645507026157468366281086038570572070029836157488483829748447827221025932814337043041670825132777740409339270667714103070525763151792932580068991100654420176156539559479389740841169492804984661929195537477589489698195353298113286906576109667225028494927502068318528150486122497\n"}, {"input": "39939223824273992215667642551956428337968885602521915294176256205951300513174403629707995884994741403648\r\n", "output": "YES\n1\n142\n70\n45355564401187243044403261079976760837747312460747083211707271702186884595712 502690838779825277075469476969742432618366046439946838929755594699237970935808 6028825404188368188284186252304410966634175748688610553856172830913605264211968 72345616128496290331358447738375223414211257583547430686832332778840158971625472 868147369481808473315630390586396205288418520052509510245367848246738315642929152 10417768431776689428899175438513912257154179193050942484778029166869247821713768448 125013221181153188792549406158123376901991246729313045514155817918090006196731772928 1500158654173824341814406148972143558641906718786148357477938104010051660388795154432 18001903850085890941464858227255277956687714938603312940677596272203367556834543009792 216022846201030691200885964097029131751334648789337216342376350185113972984695266213888 2592274154412368294402573874611846730705272624599221384529703301797923806008233257074688 31107289852948419532830215020796118864270709565117921180058205213206465349614789923438592 373287478235381034393962524293341256212565801287242326207840276357780199168503811651141632 4479449738824572412727550286857077393704232722655726853831345134109970941269806267527856128 53753396865894868952730603441896343917713579597469457157587580094137702007841655254310453248 645040762390738427432767241302723744945334854080100213800351914336720594986816861388723453952 7740489148688861129193206895632682240838415907203741459596664718141236154082862086526097948672 92885869784266333550318482747592186665185524024631775756326013429869882933514433350801626759168 1114630437411196002603821792971106239963486666057096882262675997559453182625883207568993558724608 13375565248934352031245861515653274879560278357498622218251008957080189407129240991441203874496512 160506782987212224374950338187839298554723210153717921588270348900492835486852445439012219924774912 1926081395846546692499404058254071582656678510999926263640015706923874906059004474729956453549867008 23112976750158560309992848699048858991880142131095391097395252776429662279392784957547961593802784768 277355721001902723719914184388586307902561705573069382829885955341601210969937147095641246138233782272 3328268652022832684638970212663035694830740466876826318097060040934584970274014409114783762576522084352 479270685891287906588011710623477140055626627230262983486532702447643629563916696116523499847776603209728 5751248230695454879056140527481725680667519526763155801834760565036409223384152341111617627275639214047232 69014978768345458548673686329780708168010234321157869622016824125075634486327924092315522829732863899860992 828179745220145502584084235957368498016122811853894435464201864279627507486411597107700949898663132909273088 9938156942641746031009010831488421976193473742246733225570422369253756747641145540959070955112446658753855488 119257883311700952372108129977861063714321684906960798706845068430869933193177430356147739757710067327033147392 1431094599740411428465297559734332764571860218883529584482140821170424602669919471262492784450550866876230008832 17173135196884937141583570716811993174862322626602355013785689854045094015735016180732306739019779574094079459328 206077622362619245699002848601743918098347871519228260165428278248541128087461526045919546978705118986760563458048 2472931468351430948388034183220927017180174458230739121985139338982493537041091756874128885920333741515929395658752 29675177620217171380656410198651124206162093498768869463821672067789922444492397202849804491225327590997386300751872 356102131442606056567876922383813490473945121985226433565860064813479069333908707777561008716385707983035821738426368 4273225577311272678814523068605761885687341463822717202790320777761748832006904488442679050831768643870685459705233408 51278706927735272145774276823269142628248097565872606433483849333140985984082853860904810855500818738787746816366477312 615344483132823265749291321879229711538977170790471277201806191997691831808994246330823785453136457783147921904723034112 7384133797593879188991495862550756538467726049485655326421674303972301981707930955969882596703231379474249642865703518208 88609605571126550267897950350609078461612712593827863917060091647667623780495171471638590924710909377530701929389194477568 1063315266853518603214775404207308941539352551125934367004721099772011485365942057659663091076886923599021732003920396419072 12759783202242223238577304850487707298472230613511212404056653197264137824391304691915957092921006084110648559784648928919552 153117398426906678862927658205852487581666767362134548848679838367169653892695656302991485115051936592737981698727254161358848 1837408781122880146355131898470229850980001208345614586184158060406035846712347875635897821380623227744806630299836338854166528 22048905373474561756261582781642758211760014500147375034209896724872430160548174507630773856567478731990342134424295173659820032 264586864481694741075138993379713098541120174001768500410518760698469161926578094091569286278809744783805160827327063676201992192 3175042373780336892901667920556557182493442088021222004926225128381629943118937129098831435345716937405655351195777724247114252288 38100508485364042714820015046678686189921305056254664059114701540579559317427245549185977224148603248867863666121653770976428556288 457206101824368512577840180560144234279055660675055968709376418486954711809126946590231726689783238986414363947774205341718064136192 5486473221892422150934082166721730811348667928100671624512517021843456541709523359082780720277398867836972367369483327441450179756032 65837678662709065811208986000660769736184015137208059494150204262121478500514280308993368643328786414043668408433482667909138274582528 790052143952508789734507832007929236834208181646496713929802451145457742006171363707920423719945436968524020901201765576460637304782848 9480625727430105476814093984095150842010498179757960567157629413745492904074056364495045084639345243622288250814421184714323562491543552 113767508729161265721769127809141810104125978157095526805891552964945914848888676373940541015672142923467459009773054216388282409468035072 1365210104749935188661229533709701721249511737885146321670698635579350978186664116487286492188065715081609508117276650596644088885247213568 16382521256999222263934754404516420654994140854621755860048383626952211738239969397847437906256788580979314097407319807159727791620602462208 196590255083990667167217052854197047859929690255461070320580603523426540858879632774169254875081462971751769168887837685916733393197032538112 2359083061007888006006604634250364574319156283065532843846967242281118490306555593290031058500977555661021230026654052231000800709510207373312 28308996732094656072079255611004374891829875396786394126163606907373421883678667119480372702011730667932254760319848626772009608513384639889408 339707960785135872864951067332052498701958504761436729513963282888481062604144005433764472424140768015187057123838183521264115302160554191290368 4076495529421630474379412807984629984423502057137240754167559394661772751249728065205173669089689216182244685486058202255169383625926645171535872 48917946353059565692552953695815559813082024685646889050010712735941273014996736782462084029076270594186936225832698427062032603511119741631434752 587015356236714788310635444349786717756984296227762668600128552831295276179960841389545008348915247130243234709992381124744391242133436899541634048 7044184274840577459727625332197440613083811554733152023201542633975543314159530096674540100186982965562918816519908573496932694905601242794496643328 84530211298086929516731503986369287357005738656797824278418511607706519769914361160094481202243795586755025798238902881963192338867214913533959472832 1014362535577043154200778047836431448284068863881573891341022139292478237238972333921133774426925547041060309578866834583558308066406578962407513653392 12172350426924517850409336574037177379408826366578886696092265671509738846867668007053605293123106564492723714946402015002699696796878947548890163838988 146068205123094214204912038888446128552905916398946640353107188058116866162412016084643263517477278773912684579356824180032396361562547370586681966067713\n"}, {"input": "534209694253370164016700150666673078261716946440017215951188941496790293880319124083086138235686633476558210745002559111791618570768074789507112237681946907298794953650407945917970009859230454257811456\r\n", "output": "YES\n1\n320\n159\n50554692587527006811016813913001877943935300549388843963452019056173748475335030463044486274203260230695173885695025773713703350902463248988525065124622677582345979689959424 560314509511757658822103020869104147211949581089059687261593211205925712268296587632076389539086134223538177233119868991993545472502301009622819471797901343204334608230383616 6719912297346211370622728021588673234200455470943415710447465949682095274766582070091211887323087528303724467681170057879541637775167007283953876885766685219470030536427175936 80638625750088296402869193906660697432710220692810546813978620347452725524494570092636733915614888166113132473914351663719134577644099037004819859564549545058725201040264658944 967663482182887370164046698350561420744381377900517358291794196582038338146209473215935989593023477812229959592117245878726667842091029689857619426185873650906792815366770786304 11611961783959800759746028411162623136561898095605107532545201255018843860408869897933256473666752135398332212597502369370894768514289176382108081540181423736731687984641549008896 139343541407331371810100463269864468146045220610661198659962720968228991641794301793477579733880231491584284275961036384019585118372236518260615032517672996501267770332385279737856 1672122496887960941945634569433033033628151184283217709608671010444414805144605610106587498644052711721245102788598353937532425411816902085933656894715033950653587203531680581156864 20065469962655530010032983917379284688194114922811552792444811988568449903855523486994454695548423368473460707752935740361163888607748663686771072445288987240562910939008755075907584 240785639551866360012619587765566656948717404133023045199099473851424354866442969857743073405899396323999738449226041842093197895265146117462550135152526895206148253309490776586059776 2889427674622396320142453701583217820108807851684550243363340497049475838065663695627401015625735948879856712220395069851598310679179433588985709727314410996500395149884004795338981376 34673132095468755841708695973031648669366044137055292395441264865496408688426993352306685865405076652640935534213881052198053056144819676416114775736563272645840293141122233833759965184 416077585145625070100504289305882536934730892137733566201551943294365462480427172644745053191352273603864780992864000977541542784404058323105734497089491800140736480305342987362593931264 4992931021747500841206051466473049005958632235860558632539978049941419596283401342771696040196768229394058501462892797426428922255404218394444843730761462645721392177215105530130916704256 59915172260970010094472617597243459618398741957844016576989849493497787992610672385846582099186263831574342111683757301258474601135063580609769460582944848502326085661043848835052649578496 718982067131640121133671411166885421383026166421421308339420703329823518647762223319541170991637253068795908681382507926113472508126614047306936138313155456757385476227064734560088599035904 8627784805579681453604056934002622048759834102300996792524343649075203062334516192725275900716430544083042887788354880139279318205394856157682375544034350253982748418749321693766017922105344 103533417666956177443248683208031464334464969236382289934663065056328880151227641772110875962665231821267972318761238960423511622473727897858021768352101910112200824583660572398445961293070336 1242401012003474129318984198496377571992691877503985006584654359114898765431666155220281141981488453962904955963909949224978152786685483909626747325377197063601777215300482594787456014369161216 14908812144041689551827810381956530863910561883936769872963243774248697868814738400472952922980320253563833578911817314174729167883309202676798508413289029275075940526963837447949980879000961024 178905745728500274621933724583478370366926597553398650958387874579723533816079756183827900010697381276600084122553882597052999292469967381768355229335198573343565837485512553234608146273559117824 2146868948742003295463204695001740444403119158552963595874223574064077335742148982154114172206279703505353849568614264066882345616128796660357493846053693731959677929089646180803565119926505046016 25762427384904039545558456340020885332837429901628244799188480312027877606401553778178385014148515702746425598164868474877775343569086325597551362077146934021169209139014378798141803719505043521536 309149128618848474546701476080250623994049158819454994394319913529606110408276625837501371415421618371347288794923546474039569722510330970976721464586138425690501599167334097630076563157426104172544 3709789543426181694560417712963007487928589905833452937465510474837379289826941008424963186255529372951033314007161318086433692136764079573704499668338692376405725114132939300898616667766060381896704 44517474521114180334725012555556089855143078870001434666647264990755393641667260559297470462505558304786971922124942380403700876930055630544619316194506394455878676863272349121561541505682470177079296 6410516331040441968200401808000076939140603357280206591410219111428793990745522155444660033218707929536958074579989313553745023519850848075999653555795685402071227013079156997387242744293352185438142464 76926195972485303618404821696000923269687240287362479096922291988267803760961406920873222596490367515095018523763201646329294082294096339462155368228182585034395198121056072439177879817018775119786409984 923114351669823643420857860352011079236246883448349749163067475746807168120871478138440113007706566211194515754225363912925225137533813253758377712534743883763537416949681718309345471711350180511980978176 11077372220037883721050294324224132950834962601380196989956809706618985477699568953918611476246630640870172046839793278968183842996239480476784908658233306010441681923354264690465413236695129239399983742976 132928466640454604652603531890689595410019551216562363879481716479232600687415586715044781891639080344303384383559943423619296211067026575840725935241117703742406785823581016624814397805021461462237822582784 1595141599685455255831242382688275144920234614598748366553780597750774939495238770519539169714392256852795722587842856423098312040730331644265320142171938947543640313444916352859375226907314196762640372465664 19141699196225463069974908592259301739042815375184980398645367173009297918213386223729386852157267356626978263552874571688818640947757814125698559116003144579076580334969158247092636260658358416086333344710656 229700390354705556839698903107111620868513784502219764783744406076111574905583178099543885293852588302389858295342724884816793599411343255707925602509532724716298372067432412466176646256047849997613887542788096 2756404684256466682076386837285339450422165414026637177404932872913338898857583349145759227115228174630583809471838384453180770685272639859011735804540850612409528748813172492385875172666586495721748141130645504 33076856211077600184916642047424073405065984968319646128859194474960066786290215624078380109015154521817164506156037753924450852180966388374017215369025745508565507342758401870529815023465205639973509484452511744 396922274532931202218999704569088880860791819619835753546310333699520801435482522108468000423484555630660153973246951142133933693168071219660362949904520240949423684976184183443182723027537981653958158129337204736 4763067294395174426627996454829066570329501835438029042555724004394249617225790259853243291674756559348659696003911288546860581273599894182522035095977260499296970686119467148067928088225952072678687567911705378816 57156807532742093119535957457948798843954022025256348510668688052730995406709483117784888440646490536498977839407347785465764756696163983485814227793154044125555638772300710522377615009702716229880183287470436122624 685881690392905117434431489495385586127448264303076182128024256632771944880513797413380825366137004090013989196834874452497796895471714906271066550737967439351166997812514118330661586612348535705040193822356064436224 8230580284714861409213177873944627033529379171636914185536291079593263338566165568960566751400175642217836724955680718515549281063587057800622906593623952514701045584795578219306449889889508756872688825399332009148416 98766963416578336910558134487335524402352550059642970226435492955119160062793986827526800754052652006042179770684307140943722682622871900184589054788884792113286467151800722698288941249552548943173283113086239046107136 1185203560998940042926697613848026292828230600715715642717225915461429920753527841930321609026736036097458502170813030567887766467296115069429828172105400618854177099166129821051684923542203790973137815457726056464646144 14222442731987280515120371366176315513938767208588587712606710985537159049042334103163859308319007784171581388126639812221033455463871851855425834691484706019041353481105601281676237218218743258648908653667770276568367104 170669312783847366181444456394115786167265206503063052551280531826445908588508009237966311699827941355975816604359418033769599820387822094850299007683334797111228844130859885665869514796600943917701175083027831452069789696 2048031753406168394177333476729389434007182478036756630615366381917350903062096110855595740397935283600536202581216328095828297707555645127585687174815477425741640513100118017180913733240709329080240290266251859769274925056 24576381040874020730128001720752673208086189736441079567384396583008210836745153330267148884775223402150503297918671213124155664145909556530143421021337017430600260689162232821936838095195303449135202332300848807426668888064 294916572490488248761536020649032078497034276837292954808612758996098530040941839963205786617302680825718045313936060830487719310722184829611647316833006816527344842814276861914555879917035874014636787891702337896636307472384 3538998869885858985138432247788384941964411322047515457703353107953182360491302079558469439407632169908609210912142063821935786007080490467943928324044162015608149923316683181978946710902321507561059318025769067443595379736576 42467986438630307821661186973460619303572935864570185492440237295438188325895624954701633272891586038903309919874447210351236361608167074991377486598700617538737800063928978253664383543486015675681496638253007227046807864344576 509615837263563693859934243681527431642875230374842225909282847545258259910747499456419599274699032466839718987570761727922170250091604999011200701410254966577473600849158470716465687772887034573590358394198068259371999647760384 6115390047162764326319210924178329179714502764498106710911394170543099118928969993477035191296388389602076627846605590335374987493665393329727297655441880228605734876863402542903629343712232318755202000624973650907031521212760064 73384680565953171915830531090139950156574033173977280530936730046517189427147639921724422295556660675224919534158913454824525595298365231068526979301845797795741822827916955589369055548749920150385100482490900213533925548339757056 880616166791438062989966373081679401878888398087727366371240760558206273125771679060693067546679928102699034409906931988794309289028247815414973702241861509803274624293799810828639125203682636165064762162806737262627902187892637696 10567394001497256755879596476980152822546660777052728396454889126698475277509260148728316810560159137232388412918883181409773378313792962538529071922787314112327159887388830758590020373995748600177480775651423841709886559222029615104 126808728017967081070555157723761833870559929324632740757458669520381703330111121784739801726721909646788660955026598176712634012002636716191811312031438184014149907348321238522134107060578279615979494610291898016731834688411631878144 1521704736215604972846661892685142006446719151895592889089504034244580439961333461416877620720662915761463931460319178120534554266718067358112524281790424076058650887238159468050530439941325130092908079098709010527133115925751855579136 18260456834587259674159942712221704077360629822747114669074048410934965279536001537002531448647954989137567177523830137446413230044174010527667857092936186068361214980112772333755108708897100375673326461165775312519459982747756623036416 219125482015047116089919312546660448928327557872965376028888580931219583354432018444030377383775459869650806130285961649356958642100384559851207415591188490916639363455791172898157033125898637742626453326654409349083008342276307339444224 2629505784180565393079031750559925387139930694475584512346662971174635000253184221328364528605305518435809673563431539792283503695335472754341088414633924745841031093444030566852309041562378105681062984569241670988900224153090957061914624 31554069410166784716948381006719104645679168333707014148159955654095620003038210655940374343263666221229716082761178477507402044343203244555103610927902068854662486348992911509900577219086170139236884610218349115100128033507572757158690816 378648832922001416603380572080629255748150020004484169777919467849147440036458527871284492119163994654756592993134141730088824532118370398953160876964182740581330678956886983511112999022395511076764626055569143469804313514063413191938932736 4543785995064016999240566864967551068977800240053810037335033614189769280437502334455413905429967935857079115917609700761065894385420439076128923652389306046503083217713391472582714827634859588705002346894575467811701993594758669978770079744 54525431940768203990886802379610612827733602880645720448020403370277231365250028013464966865159615230284949391011316409132790732625045268437604666589406598654664258201746593310196691168232157852442013732253884425921594775755937182384866197504 654305183289218447890641628555327353932803234567748645376244840443326776383000336161579602381915382763419392692135796909593488791500543221211594130969607094364023370053391277692293970121837047794969330251173194678740901546789482283838363140096 7851662199470621374687699542663928247193638814812983744514938085319921316596004033938955228582984593161032712305629562915121865498006518654535824415960012458243951463276731345471688781137298836336770726802755551275530965581283640413995355078656 94219946393647456496252394511967138966323665777755804934179257023839055799152048407267462742995815117932392547667554754981462385976078223854429617561880543442750390144540445813423945468620523891274343618615456383233924932560387839385272177393664 1130639356723769477955028734143605667595883989333069659210151084286068669589824580887209552915949781415188710572010657059777548631712938686253155387790096554141656596116586988900067652298027364849894881331467342412801061969523402752158043455094784 13567672280685233735460344809723268011150607871996835910521813011432824035077894970646514634991397376982264526864127884717330583580555264235037864651568452819102266812930885670062393519799210134711622139136614931104778907199180728749191086238334976 162812067368222804825524137716679216133807294463962030926261756137193888420934739647758175619896768523787174322369534616607967002966663170820454375818662041676677400726798281524353854045275761762915539299902629741769944066687243736300567581924786176 1953744808418673657906289652600150593605687533567544371115141073646326661051216875773098107438761222285446091868434415399295604035599958049845452509823931217440749658635881682749213342860616244500517811068020161115282045231938347751549333862019497984 23444937701024083894875475831201807123268250402810532453381692883755919932614602509277177289265134667425353102421212984791547248427199496598145430117887173502399047641123438718361974038853837192618341344438674317067888102485901124928253883250810814464 281339252412289006738505709974421685479219004833726389440580314605071039191375230111326127471181616009104237229054555817498566981126393959177745161414646081936547742671605669497457972959956583166304440100899294503455032526472700245131518422085277843456 3376071028947468080862068519693060225750628058004716673286963775260852470296502761335913529654179392109250846748654669809982803773516727510132941936975752983230886176307445067709255199227288209400226976541427800933013754925725893503744260383612963127296 40512852347369616970344822236316722709007536696056600079443565303130229643558033136030962355850152705311010160983856037719793645282200730121595303243709035798769993554376688898656042351036442613753104859774686633437127839492715179591778294546571359944704 486154228168435403644137866835800672508090440352679200953322783637562755722696397632371548270201832463732121931806272452637523743386408761459143638924508429585239869272410879124384589875796393373449790079069369019765614305611249193230243465387457636204544 5833850738021224843729654402029608070097085284232150411439873403650753068672356771588458579242421989564785463181675269431650284920636905137509723667094101155022878426820588100520991085314836643982098525262313522355397378353309879238606996912218541744193536 70006208856254698124755852824355296841165023410785804937278480843809036824068281259061502950909063874777425558180103233179803419047642861650116684005129213860274541121476362002170924357678479721410240723507219026107952707463549791606604302557253255106134016 840074506275056377497070233892263562093980280929429659247341770125708441888819375108738035410908766497329106698161238798157641028571714339801400208061550566323294493457685452759044344903300126656391643550449916376449031170164583436007861658987924957454925824 10080894075300676529964842806707162745127763371153155910968101241508501302665832501304856424930905197967949280377934865577891692342860572077616802496738606795879533921492222858836281576557198050709988785511095937189317840598691833393488390743546839980807553024 120970728903608118359578113680485952941533160453837870931617214898102015631989990015658277099170862375615391364535218386934700308114326864931401629960863281550554407057906674091512691371829509652755972848041959324661141542730695070068643526492203058143969673216 1451648746843297420314937364165831435298397925446054451179406578777224187583879880187899325190050348507384696374422620643216403697371922379176819559530359378606652884694880089080275405833049376920091349794995912569132809134063873596602620887703906779258825998336 17419784962119569043779248369989977223580775105352653414152878945326690251006558562254791902280604182088616356493071447718596844368463068550121834714364312543279834616338561068961815129110850461465014503841491984219026968827207777555546358866596670524566844473344 209037419545434828525350980439879726682969301264231840969834547343920283012078702747057502827367250185063396277916857372623162132421556822601462016572371750519358015396062732827541657404256393699115500571623032230077443064194696771866249215417005862059257211387904 2508449034545217942304211765278556720195631615170782091638014568127043396144944432964690033928407002220760755335002288471477945589058681871217544198868461006232296184752752793930499878505653906736180617403270147462550076723525378215828298327422224162691457793130496 30101388414542615307650541183342680642347579382049385099656174817524520753739333195576280407140884026649129064020027461657735347068704182454610530386421532074787554217033033527165998541205728312696400293051224582942402650678403623336059022240934869437129191122272256 361216660974511383691806494200112167708170952584592621195874097810294249044871998346915364885690608319789548768240329539892824164824450189455326364637058384897450650604396402325991982494396896538345322923632360229758148618973851737094884887083874114869286268267659264 4334599931694136604301677930401346012498051431015111454350489173723530988538463980162984378628287299837474585218883954478713889977893402273463916375644700618769407807252756827911903789932756771525642918367506461526635226495255638199893800030022544018566746550445277184 52015199180329639251620135164816152149976617172181337452205870084682371862461567761955812543539447598049695022626607453744566679734720827281566996507736407425232893687033081934942845479193080759396506607350404049883750838198698443178288532142355199442812234549612773376 624182390163955671019441621977793825799719406066176049426470441016188462349538813143469750522473371176596340271519289444934800156816649927378803958092836889102794724244396983219314145750316969071182145253783209141235354068405683883537759296690102782582081087590709067776 7490188681967468052233299463733525909596632872794112593117645292194261548194465757721637006269680454119156083258231473339217601881799799128545647497114042669233536690932763798631769749003803628850721081875863373073376777488369981816236302969529720090090667573838121795584 89882264183609616626799593564802310915159594473529351117411743506331138578333589092659644075236165449429872999098777680070611222581597589542547769965368512030802440291193165583581236988045643546208364260746232548828734040582731596395984234918460681639346818762953262628864 1078587170203315399521595122777627730981915133682352213408940922075973662940003069111915728902833985393158475989185332160847334670979171074510573239584422144369629283494317987002974843856547722554500347068807779925273826212886303474635239868961870183052016725811847134969856 12943046042439784794259141473331532771782981604188226560907291064911683955280036829342988746834007824717901711870223985930168016051750052894126878875013065732435551401931815844035698126278572670654004162820681108214896666031793435388779830848370804030239188618130199618256896 155316552509277417531109697679978393261395779250258718730887492778940207463360441952115864962008093896614820542442687831162016192621000634729522546500156788789226616823181790128428377515342872047848049953681088944338060888337951040806454382882185345182338179076594731585634304 1863798630111329010373316372159740719136749351003104624770649913347282489560325303425390379544097126759377846509312253973944194311452007616754270558001881465470719401878181481541140530184114464574176599444159143635870005734718448307689210628978035450256347141890722807041490944 22365583561335948124479796465916888629640992212037255497247798960167389874723903641104684554529165521112534158111747047687330331737424091401051246696022577585648632822538177778493686362209373574890119193329908563322424508406176632677104840717269076345415189785436305853499047936 268387002736031377493757557591002663555691906544447065966973587522008678496686843693256214654349986253350409897340964572247963980849089096812614960352270931027783593870458133341924236346512482898681430319958902663176759470839915863207327614704689970390177196098797972922738671616 3220644032832376529925090691092031962668302878533364791603683050264104141960242124319074575852199835040204918768091574866975567770189069161751379524227251172333403126445497600103090836158149794784177163839506831950063419097576140047744770503631068065869225929741705866962926567424 38647728393988518359101088293104383552019634542400377499244196603169249703522905491828894910226398020482459025217098898403706813242268829941016554290727014068000837517345971201237090033897797537410125966074081983400089554624871776380375315970837382492196302788280147919545957351424 463772740727862220309213059517252602624235614508804529990930359238030996442274865901946738922716776245789508302605186780844481758907225959292198651488724168816010050208151654414845080406773570448921511592888983800801018699286291157881790297477320637048169432761976748160884058095616 5565272888734346643710556714207031231490827374105654359891164310856371957307298390823360867072601314949474099631262241370133781106886711511506383817864690025792120602497819852978140964881282845387058139114667805609612219728417813048024590778546786981839851009752272225691136411303936 66783274664812159724526680570484374777889928489267852318693971730276463487687580689880330404871215779393689195575146896441605373282640538138076605814376280309505447229973838235737691578575394144644697669376013667315346636352428949839082014943296355393516696935077979312273680911826944 801399295977745916694320166845812497334679141871214227824327660763317561852250968278563964858454589352724270346901762757299264479391686457656919269772515363714065366759686058828852298942904729735736372032512164007784159636196765330840883089786284174023153570289106644464282507939938304 9616791551732951000331842002149749968016149702454570733891931929159810742227011619342767578301455072232691244162821153087591173752700237491883031237270184364568784401116232705946227587314856756828836464390145968093409915634358485464488255319974304080719588944058293974631139956695760896 115401498620795412003982104025796999616193796429454848806703183149917728906724139432113210939617460866792294929953853837051094085032402849902596374847242212374825412813394792471354731047778281081946037572681751617120918987612301600698392202026569890134671879503748612215661991968800505856 1384817983449544944047785248309563995394325557153458185680438197799012746880689673185358531275409530401507539159446246044613129020388834198831156498166906548497904953760737509656256772573339372983352450872181019405451027851347619189641084185834411868379898955059570770297951262999643684864 16617815801394539328573422979714767944731906685841498228165258373588152962568276078224302375304914364818090469913354952535357548244666010385973877978002878581974859445128850115875081270880072475800229410466172232865412334216171430274131375043472573519455773827466064862217915769276894019584 199413789616734471942881075756577215336782880230097978737983100483057835550819312938691628503658972377817085638960259430424290578935992124631686535736034542983698313341546201390500975250560869709602752925594066794384948010594057163289446364256125851491710701460155379648168530949096159051776 2392965475400813663314572909078926584041394562761175744855797205796694026609831755264299542043907668533805027667523113165091486947231905495580238428832414515804379760098554416686011703006730436515233035107128801532619376127128685959473345526384714798672048535482744772553151833198968361189376 28715585704809763959774874908947119008496734753134108938269566469560328319317981063171594504526892022405660332010277357981097843366782865946962861145988974189652557121182653000232140436080765238182796421285545618391432513525544231513680145412892511299128875768956343955369082786871771538653184 344587028457717167517298498907365428101960817037609307259234797634723939831815772758059134054322704268867923984123328295773174120401394391363554333751867690275830685454191836002785685232969182858193557055426547420697190162306530778164161744879399796732468533672739744688156598508168271064203264 4135044341492606010207581986888385137223529804451311687110817571616687277981789273096709608651872451226415087809479939549278089444816732696362652005022412283309968225450302032033428222795630194298322684665118569048366281947678369337969940938546521699218199239443315571026523149186828170487136256 49620532097911272122490983842660621646682357653415740245329810859400247335781471277160515303822469414716981053713759274591337073337800792356351824060268947399719618705403624384401138673547562331579872215981422828580395383372140432055639291262557737402154105609600656738548998120832672122322026496 595446385174935265469891806111927459760188291840988882943957730312802968029377655325926183645869632976603772644565111295096044880053609508276221888723227368796635424464843492612813664082570747978958466591777073942964744600465685184667671495150692805243477243543231286686440537477541293307570683904 7145356622099223185638701673343129517122259502091866595327492763753635616352531863911114203750435595719245271734781335541152538560643314099314662664678728425559625093578121911353763968990848975747501599101324887315576935205588222216012057941808313659289862587204444057389274163066124622010823737344 85744279465190678227664420080117554205467114025102399143929913165043627396230382366933370445005227148630943260817376026493830462727719769191775951976144741106715501122937462936245167627890187708970019189215898647786923222467058666592144695301699763911175695685177134406767288932904797889323216142336 1028931353582288138731973040961410650465605368301228789727158957980523528754764588403200445340062725783571319129808512317925965552732637230301311423713736893280586013475249555234942011534682252507640230270590783773443078669604703999105736343620397166934083126942019263357715467109533516540644704649216 12347176242987457664783676491536927805587264419614745476725907495766282345057175060838405344080752709402855829557702147815111586632791646763615737084564842719367032161702994662819304138416187030091682763247089405281316944035256447989268836123444766003208995421530888964498961271973958526976800298369024 148166114915849491977404117898443133667047173035376945720710889949195388140686100730060864128969032512834269954692425773781339039593499761163388845014778112632404385940435935953831649660994244361100193158965072863375803328423077375871226033481337192038507944883222889057671399902575798684429025567309824 1777993378990193903728849414781317604004566076424523348648530679390344657688233208760730369547628390154011239456309109285376068475121997133960666140177337351588852631285231231445979795931930932333202317907580874360509639941076928510454712401776046304462095338584079020482363787550816942243207258639958016 21335920547882326844746192977375811248054792917094280183782368152684135892258798505128764434571540681848134873475709311424512821701463965607527993682128048219066231575422774777351757551183171187998427814890970492326115679292923142125456548821312555653545144063007731941770891033003128920087658682998849536 256031046574587922136954315728509734976657515005131362205388417832209630707105582061545173214858488182177618481708511737094153860417567587290335924185536578628794778905073297328221090614198054255981133778691645907913388151515077705505478585855750667842541728756092681942582569527903657508816001827596140544 3072372558895055065643451788742116819719890180061576346464661013986515568485266984738542078578301858186131421780502140845129846325010811047484031090226438943545537346860879567938653087370376651071773605344299750894960657818180932466065743030269008014110500745073112174864435157429166065978105696733787848704 36868470706740660787721421464905401836638682160738916157575932167838186821823203816862504942939622298233577061366025690141558155900129732569808373082717267322546448162330554815263837048444519812861283264131597010739527893818171189592788916363228096169326008940877346097669342249407852973059961167039007031296 442421648480887929452657057578864822039664185928866993890911186014058241861878445802350059315275467578802924736392308281698697870801556790837700476992607207870557377947966657783166044581334237754335399169579164128874334725818054275113466996358737154031912107290528153171973450356249057358496425071654213779456 5309059781770655153431884690946377864475970231146403926690934232168698902342541349628200711783305610945635096836707699380384374449618681490052405723911286494446688535375599893397992534976010853052024790034949969546492016709816651301361603956304845848382945287486337838063676516221934923442105175115449409470464 63708717381247861841182616291356534373711642773756847120291210786024386828110496195538408541399667331347621162040492392564612493395424177880628868686935437933360262424507198720775910419712130236624297480419399634557904200517799815616339247475658150180595343449836054056764117787325464600900274440906692817321984 764504608574974342094191395496278412484539713285082165443494529432292641937325954346460902496796007976171453944485908710775349920745090134567546424243225255200323149094086384649310925036545562839491569765032795614694850406213597787396070969707897802167144121398032648681169413413960762337436210985840422133170176 9174055302899692105130296745955340949814476559420985985321934353187511703247911452157530829961552095714057447333830904529304199048941081614810557090918703062403877789129036615791731100438546754073898837180393547376338204874563173448752851636494773626005729456776391784174032960964700413643120608304665074625150976 110088663634796305261563560951464091397773718713051831823863212238250140438974937425890369959538625148568689368005970854351650388587292979377726685091024436748846533469548439389500773205262561048886786046164722568516058458494758081385034219637937283512068753481316701410088395531576169235850271139362195896254070784 1321063963617555663138762731417569096773284624556621981886358546859001685267699249110684439514463501782824272416071650252219804663047515752532720221092293240986158401634581272674009278463150732586641432553976670822192701501937096976620410635655247402144825041775800416921060746378914011186214322325655202005111537664 15852767563410667957665152777010829161279415494679463782636302562308020223212390989328213274173562021393891268992859803026637655956570189030392642653107518891833900819614975272088111341557808791039697190647720049866312418023245163719444927627862968825737900501309605003052728956546968132597572790295638161665510342656 190233210760928015491981833324129949935352985936153565391635630747696242678548691871938559290082744256726695227914317636319651871478842268364711711837290226702006809835379703265057336098693705492476366287772640598395749016278941964633339131534355625908854806015715260036632747478563617591034456893746639251453138436096 2282798529131136185903781999889559399224235831233842784699627568972354912142584302463262711480992931080720342734971811635835822457746107220376540542047482720424081718024556439180688033184324465909716395453271687180748988195347303575600069578412267510906257672188583120439592969742763411092402114675809586126726579093504 27393582349573634230845383998674712790690829974806113416395530827668258945711011629559152537771915172968644112819661739630029869492953286644518486504569792645088980616294677270168256398211893590916596745439260246168987858344167642907200834940947210130875092066262997445275115636913160933108824428772285859779826358943744 328722988194883610770144607984096553488289959697673360996746369932019107348532139554709830453262982075623729353835940875560358433915439439734221838054837511741067767395536127242019076778542723090999160945271122954027854300130011714886410019291366521570501104795155969343301387642957931197305893066322644552879508591476736 3944675858338603329241735295809158641859479516372080331960956439184229288182385674656517965439155784907484752246031290506724301206985273276810662056658050140892813208746433526904228921342512677091989931343253475448334251601560140578636920231496398258846013257541871632119616651715495174367670716789293002487514235788066816 47336110300063239950900823549709903702313754196464963983531477270210751458188628095878215585269869418889817026952375486080691614483823279321727944679896601690713758504957202322850747056110152125103879176119041705380011019218721686943643042777956779106152159090502459585435399820585942092412048601470967802171250840514330624 568033323600758879410809882596518844427765050357579567802377727242529017498263537150538587023238433026677804323428505832968299373805879351860735336158759220288565102059486427874208964673321825501246550113428500464560132230624660243323716513335481349273825909086029515025224797847031305108944583217651567940415100087093428224 6816399883209106552929718591158226133133180604290954813628532726910348209979162445806463044278861196320133651881142069995619592485670552222328824033905110643462781224713837134490507576079861906014958601361142005574721586767495922919884598160025776191285910909032354180302697574164375661307334998611818811477844541878531260416 81796798598509278635156623093898713597598167251491457763542392722924178519749949349677556531346334355841603822573704839947435109828046626667945888406861327721553374696566045613886090912958342872179503216333704066896659041209951075038615177920309314295430930908388250163632370889972507935688019983341825737416873114278492635136 981561583182111343621879477126784563171178007017897493162508712675090142236999392196130678376156012270099245870884458079369221317936559520015350660882335932658640496358792547366633090955500114466154038596004448802759908494519412900463382135043711771545171170900659001963588450679670095228256239800101908848976038922319921414144 11778738998185336123462553725521414758054136084214769917950104552101081706843992706353568140513872147241190950450613496952430655815238714240184207930588031191903685956305510568399597091466001373593848463152053385633118901934232954805560585620524541258542054050807908023563061408156041142739074877601222906187710263863753891119104 141344867978224033481550644706256977096649633010577239015401254625212980482127912476242817686166465766894291405407361963429167869782864570882210495167056374302844231475666126820795165097592016483126181557824640627597426823210795457666727027446294495102504648609694896282756736897872493712868898531214674874252522982764706262941696 1696138415738688401778607736475083725159795596126926868184815055502555765785534949714913812233997589202731496864888343561150014437394374850586525942004676491634130777707993521849541981171104197797514178693895687531169121878529545492000724329355533941230055783316338755393080842774469924554426782374576098491030275777876446786093056 20353660988864260821343292837701004701917547153523122418217780666030669189426419396578965746807971070432777962378660122733800173248732498207038311304056117899609569332495922262194503774053250373570170144326748250374029462542354545904008691952266407294760669399796065064716970113293639094653121388494913181892363309333242359069016064 244243931866371129856119514052412056423010565842277469018613367992368030273117032758947588961695652845193335548543921472805602078984789978484459735648673414795314831989951067146334045288639004482842041731920979004488353550508254550848104303427196887537128032797552780776603641359523669135837456661938958182708359711998802058631184384 2930927182396453558273434168628944677076126790107329628223360415908416363277404393107371067540347834142320026582527057673667224947817479741813516827784080977543777983879412805756008543463668053794104500783051748053860242606099054610177251641126362650445536393570633369319243696314284029630049479943267498192500316543985615849391128576 35171126188757442699281210023547336124913521481287955538680324990900996359328852717288452810484174009707840318990324692084006699373809756901762201933408971730525335806552953669072102521564016645529254009396620976646322911273188655322127019693516351805346436722847600431830924355771408355560593759319209978310003798527827389454844952576 422053514265089312391374520282568033498962257775455466464163899890811956311946232607461433725810088116494083827883896305008080392485717082821146423200907660766304029678635444028865230258768199746351048112759451719755874935278263863865524236322196221664157240674171205181971092269256900266727125111830519739720045582333928673396652048384 5064642171181071748696494243390816401987547093305465597569966798689743475743354791289537204709721057397929005934606755660096964709828604993853757078410891929195648356143625328346382763105218396956212577353113420637070499223339166366386290835866354659969886888090054462183653107231082803200725501341966236876640546988007144080754700632064 60775706054172860984357930920689796823850565119665587170839601584276921708920257495474446456516652688775148071215281067921163576517943259926245084940930703150347780273723503940156593157262620763474550928237361047644845990680069996396635490030396255919638642657080653546203837286772993638408706016103594842519686563856085728969055980589056 729308472650074331812295171048277561886206781435987046050075219011323060507043089945693357478199832265301776854583372815053962918215319119114941019291168437804173363284682047281879117887151449161694611138848332571738151888160839956759625880364755071035663711884967842554446047441275923660904472193243138110236238766273028747628671731485696 8751701671800891981747542052579330742634481377231844552600902628135876726084517079348320289738397987183621322255000473780647555018583829429379292231494021253650080359416184567382549414645817389940335333666179990860857822657930079481115510564377060852427964542619614110653352569295311083930853666318917657322834865195276344971544060774863104 105020420061610703780970504630951968911613776526782134631210831537630520713014204952179843476860775846203455867060005685367770660223005953152551506777928255043800964312994214808590592975749808679284024003994159890330293871895160953773386126772524730229135574511435369327840230831543733007170243995827011887874018382343316139658528729298110144 1260245040739328445371646055571423626939365318321385615574529978451566248556170459426158121722329310154441470404720068224413247922676071437830618081335139060525611571755930577703087115708997704151408288047929918683963526462741931445280633521270296762749626894137224431934082769978524796086042927949924142654488220588119793675902344751577301136 15122940488871941344459752666857083523272383819856627386894359741418794982674045513113897460667951721853297644856640818692958975072112857253967416976021668726307338861071166932437045388507972449816899456575159024207562317552903177343367602255243561152995522729646693183208993239742297553032515135399089711853858647057437524110828137018927611916 181475285866463296133517032002285002279268605838279528642732316897025539792088546157366769528015420662239571738279689824315507700865354287047609003712260024715688066332854003189244544662095669397802793478901908290490747810634838128120411227062922733835946272755760318198507918876907570636390181624789076542246303764689250289329937644227131342849\n"}, {"input": "33076856211077600184916642047424073405065984968319646128859194474960066786290210137605158216593003587734997784425226405256522751509341875856995371912484035985206424562038124471661978051097836183269508308363378688\r\n", "output": "YES\n1\n210\n104\n223250757559504182840586419318555911273210194145830615179213968102586222093982117851845659727767422569730243821568 2474362562951171359816499480780661349944746318449622651569621479803663961541635139524622728649422266814510202355712 29675296878100483081608782306781102067225807820453776424620378912858353313200775818070678978119418301438934701309952 356102141380762999209622953392824321962367098178700175812593290383901438572967739328829414923626882208905950771806208 4273225578139452424034668571189846121644709961838840014644215213225950696110159407738618084682372075056174637124681728 51278706927804287124542622281817816314577878274040616667805007202763002806091458437512805774988369024719870914484764672 615344483132829016997522017334108767679504652516151944721332955153493666544161630045541118363093753640308932246232891392 7384133797593879668262181753838663126479436672962795382048301534235285467935861571279442374445727820795679727060829339648 88609605571126550307837174174883070677280355145784292255028977250189539071014165689581054239522784080974154436405454962688 1063315266853518603218103672859331774223991521338597402699551840238888311640151973844491629686454579824308686379505084792832 12759783202242223238577582206208709201195950527695600990364555758969710893247488851598026137805136722129422472649280986284032 153117398426906678862927681318829237740227077354983247897538830247311784981767004982964990868792280812572879524799306832805888 1837408781122880146355131900396311246826547900845018644438229643062714357636437154692562280193434923096459538452009009910120448 22048905373474561756261582781803264994747226724522325372397736023427153369791848614218829228135213039936313210103642896247816192 264586864481694741075138993379726474106369108353799746272034413973348722194015066933784957559773722642800658416967009319750991872 3175042373780336892901667920556558297123879499217224608748018099487869906474556876835682741285797268893904975994914386384076668928 38100508485364042714820015046678686282807174840520997609433184288171745981040213861497381499643609943158551134854915159487842091008 457206101824368512577840180560144234286796149823744829838569625382587394031094693949591010379407822877605254570168643790760681930752 5486473221892422150934082166721730811349312968863062362939949789084759265228020671362727327251534249827904941588016197312203731238912 65837678662709065811208986000660769736184068890604925389019156992724920394140821751683364193909964362542912789618360407065034403872768 790052143952508789734507832007929236834208186125946452754374863873008028830640242161477923349160535130898957932967172054723628648890368 9480625727430105476814093984095150842010498180131248045393010448139455427976095437699508209608446501802486162233734968587512145103552512 113767508729161265721769127809141810104125978157126634095744501384478745059213846296707579609419568028315808835724663698377714791352369152 1365210104749935188661229533709701721249511737885148913944853047947645380704191213980850412070878000507013537269439284720143208250404241408 16382521256999222263934754404516420654994140854621756076071229827982902938449763322638568232913689604764764433170000026670019384901032214528 196590255083990667167217052854197047859929690255461070338582507373512431792230448934568515735636204723733890030201394370875924359303735017472 2359083061007888006006604634250364574319156283065532843848467400935292314551001494636730996906023784140353073431763515288080733290019099246592 28308996732094656072079255611004374891829875396786394126163731920594603035699037611259264363545484520305532413936941082026766269561760380878848 339707960785135872864951067332052498701958504761436729513963293306249494366812369641412713395935247502884830261639607892535345023914585503039488 4076495529421630474379412807984629984423502057137240754167559395529920120563283762222477689170672089472886166580874987619441986102739481114181632 48917946353059565692552953695815559813082024685646889050010712736013618629106199757213526030749685833627823015923933159175721987050854144626655232 587015356236714788310635444349786717756984296227762668600128552831301304981136629970774295182388031733529975275833317352420532024095081433124569088 7044184274840577459727625332197440613083811554733152023201542633975543816559628079056309207423105697613192711567061984849239039970764713172295221248 84530211298086929516731503986369287357005738656797824278418511607706519811781035991959628627846805814425881956159498999575884534289311869398776020992 1014362535577043154200778047836431448284068863881573891341022139292478237242461223490455870045725797893366214258693550926692699082691753708729581699072 12172350426924517850409336574037177379408826366578886696092265671509738846867958747851048801091339918730415873669720908031294229381569378777750336176128 146068205123094214204912038888446128552905916398946640353107188058116866162412040313043050476474631553432492259250434087784779239277938239855753647095808 1752818461477130570458944466661353542634870996787359684237286256697402393948944195034752477789643791351912198925606357652701454911893517686145939566231552 21033821537725566845507333599936242511618451961448316210847435080368828727387330316356882722815054513948839911425159720882357800946102067134407682778202112 252405858452706802146088003199234910139421423537379794530169220964425944728647963794277580422892264918863236730795073603009121973186839793521280227337043968 3028870301432481625753056038390818921673057082448557534362030651573111336743775565531163880720466479922315270585681979648811199375061545437914395064211079168 36346443617189779509036672460689827060076684989382690412344367818877336040925306786373952644949411034142446282846195513820126203808806834247944326798546829312 436157323406277354108440069528277924720920219872592284948132413826528032491103681436487430579084916849298910647139180479011047096648021035058079553751563108352 5233887880875328249301280834339335096651042638471107419377588965918336389893244177237849166852326667561552724036752235274230026214021447339370516947699507396608 62806654570503938991615370012072021159812511661653289032531067591020036678718930126854190002219862316186129838130283662417935102989444467649002333564284151267328 753679854846047267899384440144864253917750139939839468390372811092240440144627161522250280026637676319687516153370842018942485801575099203419407680287400653750272 9044158258152567214792613281738371047013001679278073620684473733106885281735525938267003360319652059880038023681767390733137101666043004240335507136575140414881792 108529899097830806577511359380860452564156020151336883448213684797282623380826311259204040323835824713897438603334651796006464159329777868700634636886662212692738048 1302358789173969678930136312570325430769872241816042601378564217567391480569915735110448483886029896566380678433278608477678304823568772909225666355243926596289036288 15628305470087636147161635750843905169238466901792511216542770610808697766838988821325381806632358758796535759132115200642606385792126228117776167155644117492466450432 187539665641051633765939629010126862030861602821510134598513247329704373202067865855904581679588305105558426411079780065953815523497956483513903020108789159771013906432 2250475987692619605191275548121522344370339233858121615182158967956452478424814390270854980155059661266701116708081893929632664523141514614341885325825558229740618252288 27005711852311435262295306577458268132444070806297459382185907615477429741097772683250259761860715935200413400478243104917107547464462011773117211333616706116261456642048 324068542227737223147543678929499217589328849675569512586230891385729156893173272199003117142328591222404960805737355623818750200672441127644157751622042974008418649505792 3888822506732846677770524147153990611071946196106834151034770696628749882718079266388037405707943094668859529668848137349559457377327534947260455620766069229818797224886272 46665870080794160133246289765847887332863354353282009812417248359544998592616951196656448868495317136026314356026177637350024693108701939485086347665967960219635381151203328 559990440969529921598955477190174647994360252239384117749006980314539983111403414359877386421943805632315772272314131647296572251019487567164199578676346783424108725018820608 6719885291634359059187465726282095775932323026872609412988083763774479797336840972318528637063325667587789267267769579767483556673376772830415658561339889006155011712826212352 80638623499612308710249588715385149311187876322471312955857005165293757568042091667822343644759908011053471207213234957209796404218949850800358341370847312040948949471631245312 967663481995347704522995064584621791734254515869655755470284061983525090816505100013868123737118896132641654486558819486517556327638933924340580966336398464821978127736051335168 11611961783944172454275940775015461500811054190435869065643408743802301089798061200166417484845426753591699853838705833838210675888084835068314995001860634137891286760672322387968 139343541407330069451311289300185538009732650285230428787720904925627613077576734401997009818145121043100398246064470006058528110653386156484465608639479597368031070230387844186112 1672122496887960833415735471602226456116791803422765145452650859107531356930920812823964117817741452517204778952773640072702337327840331222452311109391851167392484145189847461527552 20065469962655530000988825659226717473401501641073181745431810309290376283171049753887569413812897430206457347433283680872428047934083949448147626963178722008624485684146935649271808 240785639551866360011865907910720609680818019692878180945181723711484515398052597046650832965754769162477488169199404170469136575209007391275998181362351039770153384538252291633840128 2889427674622396320142390894928647316169816236314538171342180684537814184776631164559809995589057229949729858030392850045629638902508088695136830397831896341880728910819734921592963072 34673132095468755841708690739143767794037794835774458056106168214453770217319573974717719947068686759396758296364714200547555666830097064341627369125773063091288654287866878010947796992 416077585145625070100504288869725213528453538029293496673274018573445242607834887696612639364824241112761099556376570406570668001961164772099527213205259282677857177067571707710692917248 4992931021747500841206051466436702562341442456351521960079288222881342911294018652359351672377890893353133194676518844878848016023533977265194326457104443269266152235278624590159924953088 59915172260970010094472617597240430748097309476218263520951458674576114935528223828312220068534690720237598336118226138546176192282407727182331917476806763554288148999215808756721733599232 718982067131640121133671411166885168977167713714619162251417504094913379226338685939746640822416288642851180033418713662554114307388892726187983009720977283011715648171912397886894356037632 8627784805579681453604056934002622027726012564575429947017010049138960550716064231276959689868995463714214160401024563950649371688666712714255796116651668739503942599744725665709918401855488 103533417666956177443248683208031464332712150774905159364204120589667526608592770775323516278427945564570569924812294767407792460264000552571069553399820019985994257432076856062774619666382848 1242401012003474129318984198496377571992545809298861912370449447076010319303113249303882195341135346774846839097747537208893509523168006630852834640797840239424593334704517285092816735900270592 14908812144041689551827810381956530863910549711586342948445393364912123831637358991646586344093624161298162069172970446506722114278016079570234015689574082873061175203580840338808760939128553472 178905745728500274621933724583478370366926596539036115381344720378945485979648307899759036129123489935577944830075645358080665371336192954842808188274888994476731273708563970142179711278569750528 2146868948742003295463204695001740444403119158468433384576136644547345831755779694797108433549481879226935337960907744296967984456034315458113698259298667933720775048774900465545862750343589265408 25762427384904039545558456340020885332837429901621200614913639734568149981069356337565301202593782550723224055530892931563615813472411785497364379111584015204649300565654816655203661855373133873152 309149128618848474546701476080250623994049158819454407378963676814817799772832276050783614431125390608678688666370715178763389761668941425968372549339008182455791606786220800784831718002081778368512 3709789543426181694560417712963007487928589905833452888547564121777813597273987312609403373173504687304144263996448582145160677140027297111620470592068098189469499281434513192828179597336448354746368 44517474521114180334725012555556089855143078870001434662570769461333763167287847751312840478082056247649731167957382985741928125680327565339445647104817178273633991377214146945889005083146669174816768 534209694253370164016700150666673078261716946440017215950849233536005158007454173015754085736984674971796774015488595828903137508163930784073347765257806139283607896526569762403330631824019137507622912 6410516331040441968200401808000076939140603357280206591410190802432061896089450076189049028843816099661561288185863149946837650097967169408880173183093673671403294758318837148761022796123751242375626752 76926195972485303618404821696000923269687240287362479096922289629184742753073400914268588346125793195938735458230357799362051801175606032906562078197124084056839537099826045785125694821337975041197867008 923114351669823643420857860352011079236246883448349749163067475550216913036880810971223060153509518351264825498764293592344621614107272394878744938365489008682074445197912549421507789628376780505431932928 11077372220037883721050294324224132950834962601380196989956809706602602956442569731654676721842114220215177905985171523108135459369287268738544939260385868104184893342374950593058093429854881456066104655872 132928466640454604652603531890689595410019551216562363879481716479231235477310836779856120662105370642582134871822058277297625512431447224862539271124630417250218720108499407116697121154451440813626665992192 1595141599685455255831242382688275144920234614598748366553780597750774825727730041358273447945264447710985618461864699327571506149177366698350471253495565007002624641301992885400365453853100028375256109416448 19141699196225463069974908592259301739042815375184980398645367173009297908732760496299281375343173372531827421542376391930858073790128400380205655041946780084031495695623914624804385446237173902054051322789888 229700390354705556839698903107111620868513784502219764783744406076111574904793125955591376504118080470381929058508516703170296885481540804562467860503361361008377948347486975497652625354846084621444530707628032 2756404684256466682076386837285339450422165414026637177404932872913338898857517511467096518049416965644583148702102200438043562625778489654749614326040336332100535380169843705971831504258153015273734028061048832 396922274532931202218999704569088880860791819619835753546310333699520801435482521651261898599116043052819973413102716863078273018112102510283944462949808431822477094744457493659943736613174034199232824697996443648 4763067294395174426627996454829066570329501835438029042555724004394249617225790259815142783189392516633839680957232602356939276217345230123407333555397701181869725136933489923919324839358088410390793790125760315392 57156807532742093119535957457948798843954022025256348510668688052730995406709483117781713398272710199606076171486791228283271314608142761480888002664772414182436701643201879087031898072297060924689525472654940700672 685881690392905117434431489495385586127448264303076182128024256632771944880513797413380560779272522395272914057841494739399255775297713137770656031977268970189240419718422549044382776867564731096274305671121439817728 8230580284714861409213177873944627033529379171636914185536291079593263338566165568960566729351270268743274968694097936872791069303572557653247872383727227642270885036621070588532593322410776773155291668053395790430208 98766963416578336910558134487335524402352550059642970226435492955119160062793986827526800752215243224919299624329175242473492831642870691838974468604726731707250620439452847062391119868929321277863500016640744361213952 1185203560998940042926697613848026292828230600715715642717225915461429920753527841930321609026582918699031595491950102909681913979714448302067693623256720780487007445273434164748693438427151855334362000199688931907571712 14222442731987280515120371366176315513938767208588587712606710985537159049042334103163859308318995024388379145903401234916182967756573379624812323479080649365844089343281209976984321261125822264012344002396267182855277568 170669312783847366181444456394115786167265206503063052551280531826445908588508009237966311699827940292660549750840814818994195613078880555497747881748967792390129072119374519723811855133509867168148128028755206194260365568 2048031753406168394177333476729389434007182478036756630615366381917350903062096110855595740397935283511926597010089777827930347356946566665972974580987613508681548865432494236685742261602118406017777536345062474331124139712 24576381040874020730128001720752673208086189736441079567384396583008210836745153330267148884775223402143119164121077333935164168283358799991675694971851362104178586385189930840228907139225420872213330436140749691973489655952 294916572490488248761536020649032078497034276837292954808612758996098530040941839963205786617302680825717429969452928007221970019400305599900108339662216345250143036622279170082746885670705050466559965233688996303681875869708 3538998869885858985138432247788384941964411322047515457703353107953182360491302079558469439407632169908609159633435136086663640232803667198801300075946596143001716439467350040992962628048460605598719582804267955644182510436353\n"}, {"input": "10567394001497256755879596476980152822546660777052728396454889126698475277509260148728316810560159137232388412918883181392600243116908025396945501205975320937464837260786475744804330519950654592948087094740219247266238669242815922176\r\n", "output": "YES\n1\n223\n111\n1230688966265646531498582643758459423077954341580942554403612383995383663617988492661647096153645316026683185908863205376 7435412504521614461137270139374025681095974147051527932855158153305442967692013809830784539261607117661210914866048532480 88613878796703861540576764873677684223498399935291686634262881968445385529327178376126999419924107355712948702055889895424 1063315622955650045820831972084231325352843025071056352231154665632076298845011391568370458451488023430536919234975954370560 12759783231917400858794476231144117497123354819673305902825522661085809892181227136408349373535556175763274825387236892082176 153117398429379610331279089154240521764887694379314723306910577489154793231678149840032517805103149100375700554194136491622400 1837408781123086223977494517715928853828602952263712934055677288666201274990596416763984574104794162120443106871125245715021824 22048905373474578929396779666579899795330731312140549896532523327227443946238028552724781085961159643188311840805235915898224640 264586864481694742506233593120124527006417733736101264982378979581998746408718915261993786881259218193071658302858808738055192576 3175042373780336893020925803868258134865550217999083068640546813288590741825782197529700143729254393523094225985405369668935352320 38100508485364042714829953203621327935952314067086152481090895014321806050652815971555216283180564703544316905687456074761580314624 457206101824368512577841008739889454424558244759291926077874434609766565703562410792095829944702569107637401717738022200366826782720 5486473221892422150934082235736709579694126476774357954293225189853690862867392981099602728881975478680407620516980312179670909976576 65837678662709065811208986006412017966879470016264200021631929942788998027277436110828103810712501131613954679529107416637323335434240 790052143952508789734507832008408507520099469553084725640425928285513368633401626691406651650560746528321544757126400972187986059853824 9480625727430105476814093984095190781234322453750176234800181370173830872959658886410335603633563186085604711135748237663967508221132800 113767508729161265721769127809141813432394630179928211444861765627981609679629143250766815225588327752006068714799831470800752738278834176 1365210104749935188661229533709701721526867458887049045390612819967937286089225822060355348372225397150654392259362215367845128079314780160 16382521256999222263934754404516420655017253831371914420358376475651260597231849539978526977605468554485067837752493604223994544886774759424 196590255083990667167217052854197047859931616336856916867273102927484794930462289452680178964360519636210581980583268835672088955969213562880 2359083061007888006006604634250364574319156443572315831059191617231456678145854148013240302175084143716392797760962004826813747006407889125376 28308996732094656072079255611004374891829875410161959375097958938619283399331941999040640138984572883603535724297707622821660687371459446702080 339707960785135872864951067332052498701958504762551359951374478891084884397115111673727828043888504866492997204169671770934919558732060425191424 4076495529421630474379412807984629984423502057137333640037343660995323069732475657391837282058001527586520180492752492942641950647307604024360960 48917946353059565692552953695815559813082024685646896790499861424802402208203632415144305996823629953470625850416589617952655317429568154869170176 587015356236714788310635444349786717756984296227762669245169315222033703612728082692268526846227527076850208845374372057318609801626640933978112000 7044184274840577459727625332197440613083811554733152023255296030841438183112260700116433726728425655558469397697857072741313879785559009797366349824 84530211298086929516731503986369287357005738656797824278422991057445344342327088710381305671122249144254655013337065256900224104273878060784198615040 1014362535577043154200778047836431448284068863881573891341022512579956472620006727883657676465998751504185278680125014781469727380190467558011700248576 12172350426924517850409336574037177379408826366578886696092265702617028699816087539883815618293029331531317462371506863352525648406360938265190512721920 146068205123094214204912038888446128552905916398946640353107188060709140316824384379045781044574772337832567391642249584061548524196670869813040328474624 1752818461477130570458944466661353542634870996787359684237286256697618416795145223706919372003652136417278871853305675610724519018970078738642380123013120 21033821537725566845507333599936242511618451961448316210847435080368846729291180402079563297332888542704287134169134664045526389621691780555449052824600576 252405858452706802146088003199234910139421423537379794530169220964425946228806617968087803804102084421259523999357071514939386022243138936306367008174243840 3028870301432481625753056038390818921673057082448557534362030651573111336868788786712314732668900631547514961191395479474805388045816237033146485629280845824 36346443617189779509036672460689827060076684989382690412344367818877336040935724554805715215945113880111212923730004972138959052864703058547547001012302643200 436157323406277354108440069528277924720920219872592284948132413826528032491104549583856744126667892086462974533879497933870949834069345720416379776602709426176 5233887880875328249301280834339335096651042638471107419377588965918336389893244249583463276314625248831316396027313928395468351442139891063150375299603769589760 62806654570503938991615370012072021159812511661653289032531067591020036678718930132882991178008387197958610144129497136844704963425121004625983988426942839783424 753679854846047267899384440144864253917750139939839468390372811092240440144627161522752680124620053393168556178870776475144716623278072248167489484859288877793280 9044158258152567214792613281738371047013001679278073620684473733106885281735525938267045226994483924636161443683892385271153954234518251994064513953622797766885376 108529899097830806577511359380860452564156020151336883448213684797282623380826311259204043812725394035960448888334828878884632230377150806013445387454749517472071680 1302358789173969678930136312570325430769872241816042601378564217567391480569915735110448484176770694009885929290361956567918152162822720654001733917791267205020647424 15628305470087636147161635750843905169238466901792511216542770610808697766838988821325381806656587158583494530036872146316793039737064057096507506119189729209860751360 187539665641051633765939629010126862030861602821510134598513247329704373202067865855904581679590324138874006308655176478093331077993367969262130631689084627414130098176 2250475987692619605191275548121522344370339233858121615182158967956452478424814390270854980155059829519477415032879843630644290819349465571487570960123916185377544601600 27005711852311435262295306577458268132444070806297459382185907615477429741097772683250259761860715949221478092005309600725525182989146007686212685136474902612564533837824 324068542227737223147543678929499217589328849675569512586230891385729156893173272199003117142328591223573382863364611165136118336966164793970249041105614490383110572605440 3888822506732846677770524147153990611071946196106834151034770696628749882718079266388037405707943094668956898173650408644669238055352011919454296561556366856183354885144576 46665870080794160133246289765847887332863354353282009812417248359544998592616951196656448868495317136026322470068244493291283841498537312566102501077700485021832427622891520 559990440969529921598955477190174647994360252239384117749006980314539983111403414359877386421943805632315772948484303885291677180051973848254284258127324493824291812224794624 6719885291634359059187465726282095775932323026872609412988083763774479797336840972318528637063325667587789267324117094120649815417462813353839832284627470482021693636760043520 80638623499612308710249588715385149311187876322471312955857005165293757568042091667822343644759908011053471207217930583405893592447623687510643689181121277163937839631959064576 967663481995347704522995064584621791734254515869655755470284061983525090816505100013868123737118896132641654486559210788700564426657990077399771411987254628582227201916078653440 11611961783944172454275940775015461500811054190435869065643408743802301089798061200166417484845426753591699853838705866446725926563003089747736594205664872151537974183520657997824 139343541407330069451311289300185538009732650285230428787720904925627613077576734401997009818145121043100398246064470008775904381542962677707750741906463283869168294182291872153600 1672122496887960833415735471602226456116791803422765145452650859107531356930920812823964117817741452517204778952773640072928785350414462599220918203830766474600912247185839463858176 20065469962655530000988825659226717473401501641073181745431810309290376283171049753887569413812897430206457347433283680872446918602631793729545010887715298284225188025979934982799360 240785639551866360011865907910720609680818019692878180945181723711484515398052597046650832965754769162477488169199404170469138147764719711632781296689395754459786776400071708244967424 2889427674622396320142390894928647316169816236314538171342180684537814184776631164559809995589057229949729858030392850045629639033554398055166562324109150068104865026808219872977223680 34673132095468755841708690739143767794037794835774458056106168214453770217319573974717719947068686759396758296364714200547555666841017590121629846786296167568473998964199251756896485376 416077585145625070100504288869725213528453538029293496673274018573445242607834887696612639364824241112761099556376570406570668001962074815914527419676969541384289289123932738856188641280 4992931021747500841206051466436702562341442456351521960079288222881342911294018652359351672377890893353133194676518844878848016023534053102178909807643752457491688244616654676088716263424 59915172260970010094472617597240430748097309476218263520951458674576114935528223828312220068534690720237598336118226138546176192282407733502080632756018372653306943666660644597215799541760 718982067131640121133671411166885168977167713714619162251417504094913379226338685939746640822416288642851180033418713662554114307388892726714628735994244917103300547727532800873602194866176 8627784805579681453604056934002622027726012564575429947017010049138960550716064231276959689868995463714214160401024563950649371688666712714299683260507774375678241341374360699292144055091200 103533417666956177443248683208031464332712150774905159364204120589667526608592770775323516278427945564570569924812294767407792460264000552571073210661808028789008782327212658982239805137485824 1242401012003474129318984198496377571992545809298861912370449447076010319303113249303882195341135346774846839097747537208893509523168006630852834945569672573491511211779111935336105501356195840 14908812144041689551827810381956530863910549711586342948445393364912123831637358991646586344093624161298162069172970446506722114278016079570234015714971735567566751693337056559662368336249880576 178905745728500274621933724583478370366926596539036115381344720378945485979648307899759036129123489935577944830075645358080665371336192954842808188277005465534606738416043654827250845228329861120 2146868948742003295463204695001740444403119158468433384576136644547345831755779694797108433549481879226935337960907744296967984456034315458113698259298844306308931337500523772602952011506069274624 25762427384904039545558456340020885332837429901621200614913639734568149981069356337565301202593782550723224055530892931563615813472411785497364379111584029902364980256381951930791752627136673873920 309149128618848474546701476080250623994049158819454407378963676814817799772832276050783614431125390608678688666370715178763389761668941425968372549339008183680601246760448062057797392233062073368576 3709789543426181694560417712963007487928589905833452888547564121777813597273987312609403373173504687304144263996448582145160677140027297111620470592068098189571566751432365464600926736855696712663040 44517474521114180334725012555556089855143078870001434662570769461333763167287847751312840478082056247649731167957382985741928125680327565339445647104817178273642496999713967968536734011439939871309824 534209694253370164016700150666673078261716946440017215950849233536005158007454173015754085736984674971796774015488595828903137508163930784073347765257806139283608605328444747488551275901376910065664000 6410516331040441968200401808000076939140603357280206591410190802432061896089450076189049028843816099661561288185863149946837650097967169408880173183093673671403294817385660064184791183130197723422130176 76926195972485303618404821696000923269687240287362479096922289629184742753073400914268588346125793195938735458230357799362051801175606032906562078197124084056839537104748281028077675520255178914618408960 923114351669823643420857860352011079236246883448349749163067475550216913036880810971223060153509518351264825498764293592344621614107272394878744938365489008682074445198322735691753788019953214161550311424 11077372220037883721050294324224132950834962601380196989956809706602602956442569731654676721842114220215177905985171523108135459369287268738544939260385868104184893342374984775247280596387512825537447854080 132928466640454604652603531890689595410019551216562363879481716479231235477310836779856120662105370642582134871822058277297625512431447224862539271124630417250218720108499409965212886751662493427749277925376 1595141599685455255831242382688275144920234614598748366553780597750774825727730041358273447945264447710985618461864699327571506149177366698350471253495565007002624641301992885637741767652867616093099660410880 19141699196225463069974908592259301739042815375184980398645367173009297908732760496299281375343173372531827421542376391930858073790128400380205655041946780084031495695623914624824166805720487867697204952039424 229700390354705556839698903107111620868513784502219764783744406076111574904793125955591376504118080470381929058508516703170296885481540804562467860503361361008377948347486975497654273801469694118581460176732160 2756404684256466682076386837285339450422165414026637177404932872913338898857517511467096518049416965644583148702102200438043562625778489654749614326040336332100535380169843705971831641628704982731828772183474176 33076856211077600184916642047424073405065984968319646128859194474960066786290210137605158216593003587734997784425226405256522751509341875856995371912484035985206424562038124471661978062545382180557682870373580800 396922274532931202218999704569088880860791819619835753546310333699520801435482521651261898599116043052819973413102716863078273018112102510283944462949808431822477094744457493659943736614127996365673505911497293824 4763067294395174426627996454829066570329501835438029042555724004394249617225790259815142783189392516633839680957232602356939276217345230123407333555397701181869725136933489923919324839358167907237997180226885386240 57156807532742093119535957457948798843954022025256348510668688052730995406709483117781713398272710199606076171486791228283271314608142761480888002664772414182436701643201879087031898072297067549426792421830034456576 685881690392905117434431489495385586127448264303076182128024256632771944880513797413380560779272522395272914057841494739399255775297713137770656031977268970189240419718422549044382776867564731648335744583552697630720 8230580284714861409213177873944627033529379171636914185536291079593263338566165568960566729351270268743274968694097936872791069303572557653247872383727227642270885036621070588532593322410776773201296787962765061914624 98766963416578336910558134487335524402352550059642970226435492955119160062793986827526800752215243224919299624329175242473492831642870691838974468604726731707250620439452847062391119868929321277867333776633191800504320 1185203560998940042926697613848026292828230600715715642717225915461429920753527841930321609026582918699031595491950102909681913979714448302067693623256720780487007445273434164748693438427151855334362319679688302527512576 14222442731987280515120371366176315513938767208588587712606710985537159049042334103163859308318995024388379145903401234916182967756573379624812323479080649365844089343281209976984321261125822264012344029019600463740272640 170669312783847366181444456394115786167265206503063052551280531826445908588508009237966311699827940292660549750840814818994195613078880555497747881748967792390129072119374519723811855133509867168148128030973817301000781824 2048031753406168394177333476729389434007182478036756630615366381917350903062096110855595740397935283511926597010089777827930347356946566665972974580987613508681548865432494236685742261602118406017777536345247358590019174400 24576381040874020730128001720752673208086189736441079567384396583008210836745153330267148884775223402143119164121077333935164168283358799991675694971851362104178586385189930840228907139225420872213330436140765098995064242176 294916572490488248761536020649032078497034276837292954808612758996098530040941839963205786617302680825717429969452928007221970019400305599900108339662216345250143036622279170082746885670705050466559965233688997587600340418560 3538998869885858985138432247788384941964411322047515457703353107953182360491302079558469439407632169908609159633435136086663640232803667198801300075946596143001716439467350040992962628048460605598719582804267955751175715815424 42467986438630307821661186973460619303572935864570185492440237295438188325895624954701633272891586038903309915601221633039963682793644006385615600911359153716020597273608200491915551536581527267184634993651215467739106225684480 509615837263563693859934243681527431642875230374842225909282847545258259910747499456419599274699032466839718987214659596479564193523728076627387210936309844592247167283298405902986618438978327206215619923814585612763024511205376 6115390047162764326319210924178329179714502764498106710911394170543099118928969993477035191296388389602076627846575915157754770322284736919528646531235718135106966007399580870835839421267739926474587439085775027353147439951380480 73384680565953171915830531090139950156574033173977280530936730046517189427147639921724422295556660675224919534158910981893057243867416843034343758374828617621283592088794970450030073055212879117695049269029300328237768541567975424 880616166791438062989966373081679401878888398087727366371240760558206273125771679060693067546679928102699034409906931782716686926409002116412125100497943411455403105065539645400360876662554549412340591228351603938853222437328322560 126808728017967081070555157723761833870559929324632740757458669520381703330111121784739801726721909646788660955026598176711202917402896304763346014471703851249578047129437708937651966239407855115377045136882630967194864030913364070400 1521704736215604972846661892685142006446719151895592889089504034244580439961333461416877620720662915761463931460319178120534435008834755657160152173660446214994936565553252507251823594872894261384524541642591571606338368370960333261824 18260456834587259674159942712221704077360629822747114669074048410934965279536001537002531448647954989137567177523830137446413220106017067885921826083925354579939238786639030087021883138474731136614294499711098859276060420451523996176640 219125482015047116089919312546660448928327557872965376028888580931219583354432018444030377383775459869650806130285961649356958641272204814631061913007104254959270865439668361044262597661696773639371533996533186311312725045418287953872576 2629505784180565393079031750559925387139930694475584512346662971174635000253184221328364528605305518435809673563431539792283503695266457775572742956085251059511250385276020332531151171940361283672458407958398235735752700545019455446450320 31554069410166784716948381006719104645679168333707014148159955654095620003038210655940374343263666221229716082761178477507402044343197493306872915473023012714135004623312243990373814063284335404069500895500778828829032406540233465357402124 378648832922001416603380572080629255748150020004484169777919467849147440036458527871284492119163994654756592993134141730088824532118369919682474985676276152569620055479746927884485768759412024848834010746009345945948388878482801584288825345\n"}, {"input": "14222442731987280515120371366176315513938767208588587712606710985537159049042334103163859308318995024388379145903401234916182967756573397626716173564971582716660249742542070531726073243246683577569028961587234032565878784\r\n", "output": "YES\n1\n284\n141\n1898886666600224784663856505549799671187776913186306324590393444755519260111356209100362425727204624060864899531638714340421152700313115817626865558880256 21045993888152491363357742936510279688997860787814895097543527346040338466234197984195683551809851250007919303142329083939667775761803700312031093277589504 252406872815242379189242203977282746570869707606243676104060561986565237206885202766597480491975164646868160013438171049930564471088148262952748844878659584 3028870385962692923839985555122322908042344439454296191159854929991622944450295335445523872392890054899649014192568904436054652916553321143700350782339547136 36346443624233963783877249920417452392274125602466501967077519842078878674900850100533482644255446332057224094813436090885729824937264482223426489775057534976 436157323406864369464676784316588560165270006590349269244360176495128161043934976712667391412360419790791808798136450527099847398408725839056036400666272333824 5233887880875377167247633893905027649604738454030920501402274612807386400605980118510864163588432959473343798882668674444904092905834839406370346684942399832064 62806654570503943068110899433702495539225319646283273456033124728260790846278324788626941251947871173845445761034110032348824608547095583654585652709054392303616 753679854846047268239092400930000126782701207271891967092331315853677169658590444410731342630781677057825792480279494216436726593704903463086539623549464840503296 9044158258152567214820922278470465703085080934889077995576303608503671675861689545174376782203330726608216213375676445082928288398720487928641101465180312430444544 108529899097830806577513718463921460452162026755971133812788003953565688913670158226446321442326131269458120119142477550535613424890834325674660103080712643694034944 1302358789173969678930136509160580514760539409033095455575612077497081736030986055691052007312570755446010735226262593957222400595698860947306835144093430798872477696 15628305470087636147161635767226426426237689165727265621059191265802838621460744681373765433584570497036504930531530532765901727106470402120949597888048242842681737216 187539665641051633765939629011492072135611538010171364132222949050953884939953012177575280315167656083745090508696398010297423468607485164680834139336489503550198513664 2250475987692619605191275548121636111879068395123843384309968109766556604402971485797660871708024607181550005382883278758327965185233975337772462919094533258388883636224 27005711852311435262295306577458277613069798236402936196279891710628271751595952441210826919490129680693317474534476553652832155852969716833403092799722454035315478757376 324068542227737223147543678929499218379380993628078302320738723393658393727381453845499831072131042367862702811908708411213393918038150103065848241744218453001673151348736 3888822506732846677770524147153990611137783874769543216845979682629410652454263281525245465202093298930981008169362416748509011020441344028545596494942917186401568433373184 46665870080794160133246289765847887332868840826503902234568182441711720323428299864584549540119829653048157812567887160633270489245628090241860109405482697549350612085243904 559990440969529921598955477190174647994360709445485942117519558154720543255637693415538061477912515008734259227025940774236842734030898079727264058821306344868251660929990656 6719885291634359059187465726282095775932323064973117898352126478594494844015527162239833693317989726702490807847328897194728579213627723706462580601351968969608690290818809856 80638623499612308710249588715385149311187876325646355329637342058195425488598648850315785732781130015979696335594864900328733489430637430040028918207514985371236756019797295104 967663481995347704522995064584621791734254515869920342334765756724600229809884813112409243911120664633052173247257288648444134418073241222610553514406120770932835444948398505984 11611961783944172454275940775015461500811054190435891114548782218364057351380842842924629244859926900966734063735430706268371224062287694009837492714199777663400524870440017985536 139343541407330069451311289300185538009732650285230430625129686048507759432708632872226860798146329388714984430222530412094374823001236394729592483448841192661823506739535152152576 1672122496887960833415735471602226456116791803422765145605768257534438035793848471029816605399408219879339327801453478439871991220535985408972738348959297967000300181565609737191424 20065469962655530000988825659226717473401501641073181745444570092492618506409627058738057121111369660819968559837340334069692185758475253963690995899809342575258470353844915838910464 240785639551866360011865907910720609680818019692878180945182787026751368916655811822055040274696308515028614103566408891568908586694373333318960128773736924817372883260727123316310016 2889427674622396320142390894928647316169816236314538171342180773147419755903181432457760346198135691562442451858256767105721286570131869190307077226782845165634663869046607824233168896 34673132095468755841708690739143767794037794835774458056106168221837904014913453163709215809619443297864484345850369526969229970802399046049558223028185642159934815534385784086167814144 416077585145625070100504288869725213528453538029293496673274018574060587090967710962361930686703470824300076727167041683772474193958856603908521451030460330933577690504781616550294585344 4992931021747500841206051466436702562341442456351521960079288222881394190000946387631497446654714162495761442774084717485281499872867118251178409310256543356620795611398392082563225092096 59915172260970010094472617597240430748097309476218263520951458674576119208753801139584898883057759325999484023459689961263378982603185488931163924381236105228234369280559122714422008610816 718982067131640121133671411166885168977167713714619162251417504094913379582440817382352697390293211026664670507363835647780547873248957539667052343629679728151211166528691007383369378955264 8627784805579681453604056934002622027726012564575429947017010049138960550745739408897176861249651873912865284607186657449418241152488384782045718561144060609932233892941123883167957987098624 103533417666956177443248683208031464332712150774905159364204120589667526608595243706791867709376333598753790851829474941866023199385985691910052046936861052641863281706509889247562789631819776 1242401012003474129318984198496377571992545809298861912370449447076010319303113455381504557960381045777695440841665635556765028751428172059131083181925926992145915753394053371191549083397390336 14908812144041689551827810381956530863910549711586342948445393364912123831637359008819721540978561302881732785984963621369044740880371093355923869734668090102454618738471635012650321968086646784 178905745728500274621933724583478370366926596539036115381344720378945485979648307901190130728863901364043242389809978122652525590219722539324949009445313495079180727336471536364999841364316258304 2146868948742003295463204695001740444403119158468433384576136644547345831755779694797227691432793580179307446090885605360682306140941276256820543327729536642104312503243892762731097761184068141056 25762427384904039545558456340020885332837429901621200614913639734568149981069356337565311140750725192469255064541724419985592006946154032230589949533953254263681262020193899346635764772943173779456 309149128618848474546701476080250623994049158819454407378963676814817799772832276050783615259305135828824191250454951136131887777791753279862808013540872285710710936907432391009117726578545948360704 3709789543426181694560417712963007487928589905833452888547564121777813597273987312609403373242519666072489722545122268474941385308037531432778340214084920198074075892277947492013536764717820368912384 44517474521114180334725012555556089855143078870001434662570769461333763167287847751312840478087807495880426622836439126269409851360995084866208802906651913441017706094784433137487784847095116842663936 534209694253370164016700150666673078261716946440017215950849233536005158007454173015754085736985154242482665303395183840613760985303986410700578028241292367214223206086367286252630530137681508146610176 6410516331040441968200401808000076939140603357280206591410190802432061896089450076189049028843816139600785112459855365614480202054395507377765775705008964190397512700782153609081797787649889773262209024 76926195972485303618404821696000923269687240287362479096922289629184742753073400914268588346125793199267004110253190484001022013838641727737302545073950358266755721928364655490152426070631819918771748864 923114351669823643420857860352011079236246883448349749163067475550216913036880810971223060153509518351542181219766196316064535798495858702781306643938557864866234127266957433563593350565817934245229756416 11077372220037883721050294324224132950834962601380196989956809706602602956442569731654676721842114220215201018961921681668445452217986317597536819402516957175533573315880704333403267226599668218877754474496 132928466640454604652603531890689595410019551216562363879481716479231235477310836779856120662105370642582136797903454123844318011835505478934121927803141341339497776772958219928392552304180173043860970143744 1595141599685455255831242382688275144920234614598748366553780597750774825727730041358273447945264447710985618622371482314783730524127704886189769808218774250676731229357364453134673406448910756061108968095744 19141699196225463069974908592259301739042815375184980398645367173009297908732760496299281375343173372531827421555751957179792425821374261895858929921507047521004337911295195588782244442286824796027872394346496 229700390354705556839698903107111620868513784502219764783744406076111574904793125955591376504118080470381929058509631333607708081484144626355438966743324716628125685198792915577984113604516888862609015796924416 2756404684256466682076386837285339450422165414026637177404932872913338898857517511467096518049416965644583148702102293323913346892112039973232361918226999945068847691574119200978525794945625582293831068485156864 33076856211077600184916642047424073405065984968319646128859194474960066786290210137605158216593003587734997784425226412997011900198203005050202267545166257952953783921321814096245869241988458897187849728398721024 396922274532931202218999704569088880860791819619835753546310333699520801435482521651261898599116043052819973413102716863723313780502840937716711704252531950319789374691064467795325727545748252758726019816332722176 4763067294395174426627996454829066570329501835438029042555724004394249617225790259815142783189392516633839680957232602356993029614211124992360064158839594808411167826929040505097273338602469595270751556385621671936 57156807532742093119535957457948798843954022025256348510668688052730995406709483117781713398272710199606076171486791228283275794057881586053300730215059238651315155200701508302130060447234092690096188619843262480384 685881690392905117434431489495385586127448264303076182128024256632771944880513797413380560779272522395272914057841494739399256148585191373151690425939792872228313624181547518145640957065476150410058194266720466632704 8230580284714861409213177873944627033529379171636914185536291079593263338566165568960566729351270268743274968694097936872791069334679847506196291916557437967440807803659664335957698170760602724764773658769695709331456 98766963416578336910558134487335524402352550059642970226435492955119160062793986827526800752215243224919299624329175242473492831645462965993386836899129249234348114003372729874676545272958473440497623515867102687789056 1185203560998940042926697613848026292828230600715715642717225915461429920753527841930321609026582918699031595491950102909681913979714664324913894653947920990280932236403760821649717223877487618014581510491291128434786304 170669312783847366181444456394115786167265206503063052551280531826445908588508009237966311699827940292660549750840814818994195613078880556997906535922792036836030418819312924770040334465353272277611185108687786765069582336 2048031753406168394177333476729389434007182478036756630615366381917350903062096110855595740397935283511926597010089777827930347356946566666097987802168765529052040644324155770439594634879772023110232791101723522712024907776 24576381040874020730128001720752673208086189736441079567384396583008210836745153330267148884775223402143119164121077333935164168283358799991686112740283124772542794033430902634708394836998558673637701707370471446005231386624 294916572490488248761536020649032078497034276837292954808612758996098530040941839963205786617302680825717429969452928007221970019400305599900109207809585658805840053926299251065620176312186145283345329506291473116517854347264 3538998869885858985138432247788384941964411322047515457703353107953182360491302079558469439407632169908609159633435136086663640232803667198801300148292210252464691190909351714408202068935250696833451696493651495378585508642816 42467986438630307821661186973460619303572935864570185492440237295438188325895624954701633272891586038903309915601221633039963682793644006385615600917387954891809178502895033964700154823322093108120862669791997429374723708420096 509615837263563693859934243681527431642875230374842225909282847545258259910747499456419599274699032466839718987214659596479564193523728076627387210936812244690229549052405642025718668712873374359626972230159650776232659301433344 6115390047162764326319210924178329179714502764498106710911394170543099118928969993477035191296388389602076627846575915157754770322284736919528646531235760001781797872547006473846067092123897847070705051777970449450103242850566144 73384680565953171915830531090139950156574033173977280530936730046517189427147639921724422295556660675224919534158910981893057243867416843034343758374828621110173161410890589250280925361117558944411392403420316613412514858476240896 880616166791438062989966373081679401878888398087727366371240760558206273125771679060693067546679928102699034409906931782716686926409002116412125100497943411746143902509047613633715114354713272731233619822884188629284451297070678016 10567394001497256755879596476980152822546660777052728396454889126698475277509260148728316810560159137232388412918883181392600243116908025396945501205975320937489065660573434742157110039758334486557994847123096962657107938314461118464 126808728017967081070555157723761833870559929324632740757458669520381703330111121784739801726721909646788660955026598176711202917402896304763346014471703851249580066162753288854098031199391828439844537449581204110144103136669334503424 1521704736215604972846661892685142006446719151895592889089504034244580439961333461416877620720662915761463931460319178120534435008834755657160152173660446214994936733806028805578194100286226259161563499335316452701584138296439997464576 18260456834587259674159942712221704077360629822747114669074048410934965279536001537002531448647954989137567177523830137446413220106017067885921826083925354579939238800660094778549080680592508803095714412852159266033997567945313968193536 219125482015047116089919312546660448928327557872965376028888580931219583354432018444030377383775459869650806130285961649356958641272204814631061913007104254959270865440836783101889864123539921778244985655961608011875886474376103784873984 2629505784180565393079031750559925387139930694475584512346662971174635000253184221328364528605305518435809673563431539792283503695266457775572742956085251059511250385276117701035953444145514879350697862263350604210799630664099273432367104 31554069410166784716948381006719104645679168333707014148159955654095620003038210655940374343263666221229716082761178477507402044343197493306872915473023012714135004623312252104415880919301431537042687516692858192868619650716823450189561856 378648832922001416603380572080629255748150020004484169777919467849147440036458527871284492119163994654756592993134141730088824532118369919682474985676276152569620055479746928560655940997413449526581776297775352559618354482164184083024838656 4543785995064016999240566864967551068977800240053810037335033614189769280437502334455413905429967935857079115917609700761065894385420439036189699828115313830835440665756963134670176739466111083575820442748092651902519830342100400886360571904 54525431940768203990886802379610612827733602880645720448020403370277231365250028013464966865159615230284949391011316409132790732625045268434276397937383765970025287989083557615370646327551428810347915240241677524595829595484882326627165405184 654305183289218447890641628555327353932803234567748645376244840443326776383000336161579602381915382763419392692135796909593488791500543221211316775248605191640303455869002691384391799718446987041461488710172177436963754448433561045858554740736 7851662199470621374687699542663928247193638814812983744514938085319921316596004033938955228582984593161032712305629562915121865498006518654535801302983262299683641470428032296612696933603682997940645073341005466505382869989753980310830371045376 94219946393647456496252394511967138966323665777755804934179257023839055799152048407267462742995815117932392547667554754981462385976078223854429615635799147596203697645136387559352362814659389238074666480826977209503079257927760367710008428724224 1130639356723769477955028734143605667595883989333069659210151084286068669589824580887209552915949781415188710572010657059777548631712938686253155387629589771154444371741636650712228353743530603628794908236651635814990158163304017129518438142705664 13567672280685233735460344809723268011150607871996835910521813011432824035077894970646514634991397376982264526864127884717330583580555264235037864651555077253853332460899639808546740244919668737943197141378713622221627998548662446613971119128969216 162812067368222804825524137716679216133807294463962030926261756137193888420934739647758175619896768523787174322369534616607967002966663170820454375818660927046239989530795677702560882939035799979851503883422804632696348157633033879455965917999005696 1953744808418673657906289652600150593605687533567544371115141073646326661051216875773098107438761222285446091868434415399295604035599958049845452509823931124554879874369548132430730595268429581018595808116646842356192578906183830263478950390025682944 23444937701024083894875475831201807123268250402810532453381692883755919932614602509277177289265134667425353102421212984791547248427199496598145430117887173494658558492434577589168767143221154970661514510859393207171297313625421581804248017961477996544 281339252412289006738505709974421685479219004833726389440580314605071039191375230111326127471181616009104237229054555817498566981126393959177745161414646081935902701909214931070025205718653859647808037864767687744296983294067660283204517933311166775296 3376071028947468080862068519693060225750628058004716673286963775260852470296502761335913529654179392109250846748654669809982803773516727510132941936975752983230832422910579172840302468623846315773685609688416833703083917489692140173583677009548453871616 40512852347369616970344822236316722709007536696056600079443565303130229643558033136030962355850152705311010160983856037719793645282200730121595303243709035798769989074926950074083629623486155789284226412536935719501300353039712366814264912598732650840064 486154228168435403644137866835800672508090440352679200953322783637562755722696397632371548270201832463732121931806272452637523743386408761459143638924508429585239868899123400889003555481833869471410716875132889776937628681740165625498784016891804410445824 5833850738021224843729654402029608070097085284232150411439873403650753068672356771588458579242421989564785463181675269431650284920636905137509723667094101155022878426789480810668042665782006433656928602495318815751828379551320622274629375291510570642046976 70006208856254698124755852824355296841165023410785804937278480843809036824068281259061502950909063874777425558180103233179803419047642861650116684005129213860274541121473769728016511989384077203883143229943302800557655290896717353526272834088860924180955136 840074506275056377497070233892263562093980280929429659247341770125708441888819375108738035410908766497329106698161238798157641028571714339801400208061550566323294493457685236736198143872608926446597718759319590024319839718784014066167834036615558929877827584 10080894075300676529964842806707162745127763371153155910968101241508501302665832501304856424930905197967949280377934865577891692342860572077616802496738606795879533921492222840834377726471307117359172625111835076659973741311076785946001721775015809478509461504 120970728903608118359578113680485952941533160453837870931617214898102015631989990015658277099170862375615391364535218386934700308114326864931401629960863281550554407057906674090012532717655685408310071501342020919617029534456727149448019637411492138935444832256 1451648746843297420314937364165831435298397925446054451179406578777224187583879880187899325190050348507384696374422620643216403697371922379176819559530359378606652884694880089080150392611868224899720858016104251035379133133374376269884235563613847535991448928256 17419784962119569043779248369989977223580775105352653414152878945326690251006558562254791902280604182088616356493071447718596844368463068550121834714364312543279834616338561068961804711342418698796650296193251012424547495827150319444986493422922498920961229717504 209037419545434828525350980439879726682969301264231840969834547343920283012078702747057502827367250185063396277916857372623162132421556822601462016572371750519358015396062732827541656536109024385559803554319012149094569774778025317023702559963366347758956743491584 2508449034545217942304211765278556720195631615170782091638014568127043396144944432964690033928407002220760755335002288471477945589058681871217544198868461006232296184752752793930499878433308292626717642651828145789134837282740655594591419439467754203166432754139136 30101388414542615307650541183342680642347579382049385099656174817524520753739333195576280407140884026649129064020027461657735347068704182454610530386421532074787554217033033527165998541199699511520611711821937749469618047391671563117622615666938663607168772369022976 361216660974511383691806494200112167708170952584592621195874097810294249044871998346915364885690608319789548768240329539892824164824450189455326364637058384897450650604396402325991982494396394138247340541863252993635416568699957398743348519869374431050122900038221824 4334599931694136604301677930401346012498051431015111454350489173723530988538463980162984378628287299837474585218883954478713889977893402273463916375644700618769407807252756827911903789932756729658968086502359035923624998824399480338364505332754669044915149603092824064 52015199180329639251620135164816152149976617172181337452205870084682371862461567761955812543539447598049695022626607453744566679734720827281566996507736407425232893687033081934942845479193080755907617038028308431083499985892793763356494424250916209861674601470666735616 624182390163955671019441621977793825799719406066176049426470441016188462349538813143469750522473371176596340271519289444934800156816649927378803958092836889102794724244396983219314145750316969070891404456339701173001999830713525160219276454365816200116986284834130231296 7490188681967468052233299463733525909596632872794112593117645292194261548194465757721637006269680454119156083258231473339217601881799799128545647497114042669233536690932763798631769749003803628850696853476076414076023997968562301922626429399336029541551909673608406892544 89882264183609616626799593564802310915159594473529351117411743506331138578333589092659644075236165449429872999098777680070611222581597589542547769965368512030802440291193165583581236988045643546208362241712916968912287975622747623071516745454277874093635255604600786386944 1078587170203315399521595122777627730981915133682352213408940922075973662940003069111915728902833985393158475989185332160847334670979171074510573239584422144369629283494317987002974843856547722554500346900555003626947455707472971476858200911506521615756540762215317761949696 12943046042439784794259141473331532771782981604188226560907291064911683955280036829342988746834007824717901711870223985930168016051750052894126878875013065732435551401931815844035698126278572670654004162806660043523369468489675657722298410935249524982964565621163822170505216 155316552509277417531109697679978393261395779250258718730887492778940207463360441952115864962008093896614820542442687831162016192621000634729522546500156788789226616823181790128428377515342872047848049953679920522280433621876107892667580931222758571928398627160180866798321664 1863798630111329010373316372159740719136749351003104624770649913347282489560325303425390379544097126759377846509312253973944194311452007616754270558001881465470719401878181481541140530184114464574176599444159046267365203462513294712010971174673083219151852179231021651642548224 22365583561335948124479796465916888629640992212037255497247798960167389874723903641104684554529165521112534158111747047687330331737424091401051246696022577585648632822538177778493686362209373574890119193329908555208382441550159536544131654096076996992823148538547997423882469376 268387002736031377493757557591002663555691906544447065966973587522008678496686843693256214654349986253350409897340964572247963980849089096812614960352270931027783593870458133341924236346512482898681430319958902662500589298601914438529579849152923963777461192661557280553603956736 3220644032832376529925090691092031962668302878533364791603683050264104141960242124319074575852199835040204918768091574866975567770189069161751379524227251172333403126445497600103090836158149794784177163839506831950007071583222973262354958189835087565318166262788602475932165341184 38647728393988518359101088293104383552019634542400377499244196603169249703522905491828894910226398020482459025217098898403706813242268829941016554290727014068000837517345971201237090033897797537410125966074081983400084858998675679148259498278021050783817047816034055970293393915904 463772740727862220309213059517252602624235614508804529990930359238030996442274865901946738922716776245789508302605186780844481758907225959292198651488724168816010050208151654414845080406773570448921511592888983800801018307984108149779113979336252609405804494847622907165113011142656 5565272888734346643710556714207031231490827374105654359891164310856371957307298390823360867072601314949474099631262241370133781106886711511506383817864690025792120602497819852978140964881282845387058139114667805609612219695809297797349367752035031312869653931592742738941488824057856 66783274664812159724526680570484374777889928489267852318693971730276463487687580689880330404871215779393689195575146896441605373282640538138076605814376280309505447229973838235737691578575394144644697669376013667315346636349711573568192413024420375754435847178564685188377876946223104 801399295977745916694320166845812497334679141871214227824327660763317561852250968278563964858454589352724270346901762757299264479391686457656919269772515363714065366759686058828852298942904729735736372032512164007784159636196538882818308956293044509053230166142730536620624524276137984 9616791551732951000331842002149749968016149702454570733891931929159810742227011619342767578301455072232691244162821153087591173752700237491883031237270184364568784401116232705946227587314856756828836464390145968093409915634358466593819707475516534108638761993712762632310835124723777536 115401498620795412003982104025796999616193796429454848806703183149917728906724139432113210939617460866792294929953853837051094085032402849902596374847242212374825412813394792471354731047778281081946037572681751617120918987612301599125836489706198409303665143924553151270468633232802840576 1384817983449544944047785248309563995394325557153458185680438197799012746880689673185358531275409530401507539159446246044613129020388834198831156498166906548497904953760737509656256772573339372983352450872181019405451027851347619189510037876474380911643981727094637815219185149771643879424 16617815801394539328573422979714767944731906685841498228165258373588152962568276078224302375304914364818090469913354952535357548244666010385973877978002878581974859445128850115875081270880072475800229410466172232865412334216171430274120454517692570939727780725135653782628018593174560702464 199413789616734471942881075756577215336782880230097978737983100483057835550819312938691628503658972377817085638960259430424290578935992124631686535736034542983698313341546201390500975250560869709602752925594066794384948010594057163289445454212310851276733368701627845391536039517754297942016 2392965475400813663314572909078926584041394562761175744855797205796694026609831755264299542043907668533805027667523113165091486947231905495580238428832414515804379760098554416686011703006730436515233035107128801532619376127128685959473345450547730215320800424419534144698432458913023206096896 28715585704809763959774874908947119008496734753134108938269566469560328319317981063171594504526892022405660332010277357981097843366782865946962861145988974189652557121182653000232140436080765238182796421285545618391432513525544231513680145406572762583849605093034409736381189505681276109062144 344587028457717167517298498907365428101960817037609307259234797634723939831815772758059134054322704268867923984123328295773174120401394391363554333751867690275830685454191836002785685232969182858193557055426547420697190162306530778164161744878873151006195261116412916836574274068069063111737344 4135044341492606010207581986888385137223529804451311687110817571616687277981789273096709608651872451226415087809479939549278089444816732696362652005022412283309968225450302032033428222795630194298322684665118569048366281947678369337969940938546477812074343133396955002038891288816819903157764096 49620532097911272122490983842660621646682357653415740245329810859400247335781471277160515303822469414716981053713759274591337073337800792356351824060268947399719618705403624384401138673547562331579872215981422828580395383372140432055639291262557733744892117600763460024466695465801838100044578816 595446385174935265469891806111927459760188291840988882943957730312802968029377655325926183645869632976603772644565111295096044880053609508276221888723227368796635424464843492612813664082570747978958466591777073942964744600465685184667671495150692804938705411209161520293600345589622057139047563264 7145356622099223185638701673343129517122259502091866595327492763753635616352531863911114203750435595719245271734781335541152538560643314099314662664678728425559625093578121911353763968990848975747501599101324887315576935205588222216012057941808313659264464934509938243523204147075464685663446810624 85744279465190678227664420080117554205467114025102399143929913165043627396230382366933370445005227148630943260817376026493830462727719769191775951976144741106715501122937462936245167627890187708970019189215898647786923222467058666592144695301699763911173579214119258922278449764905576227960934731776 1028931353582288138731973040961410650465605368301228789727158957980523528754764588403200445340062725783571319129808512317925965552732637230301311423713736893280586013475249555234942011534682252507640230270590783773443078669604703999105736343620397166934082950569431107067341397178866914735531181198336 12347176242987457664783676491536927805587264419614745476725907495766282345057175060838405344080752709402855829557702147815111586632791646763615737084564842719367032161702994662819304138416187030091682763247089405281316944035256447989268836123444766003208995406833173284808096766146402976826374171414784 148166114915849491977404117898443133667047173035376945720710889949195388140686100730060864128969032512834269954692425773781339039593499761163388845014778112632404385940435935953831649660994244361100193158965072863375803328423077375871226033481337192038507944881998079417697161193756835721916490056730304 1777993378990193903728849414781317604004566076424523348648530679390344657688233208760730369547628390154011239456309109285376068475121997133960666140177337351588852631285231231445979795931930932333202317907580874360509639941076928510454712401776046304462095338583976953012365934325082028662997880680743056 21335920547882326844746192977375811248054792917094280183782368152684135892258798505128764434571540681848134873475709311424512821701463965607527993682128048219066231575422774777351757551183171187998427814890970492326115679292923142125456548821312555653545144063007723436148391211900984343955974568168914956 256031046574587922136954315728509734976657515005131362205388417832209630707105582061545173214858488182177618481708511737094153860417567587290335924185536578628794778905073297328221090614198054255981133778691645907913388151515077705505478585855750667842541728756092681233780694542811812127471694818026979329\n"}, {"input": "753679854992115473022478654349776292806196268492745384789319451445347628202744027684662296111280935141538598830051410780606493649899116303384971691975593045262336\r\n", "output": "YES\n1\n292\n145\n39375313918622261134789728499080645981749742071831247946706398470450447377669082351905115259879315084526094556688060380562973022393692769594310684228940988416 436409729264730060910586157531477159631059641296129664742662583047492458435832329400281694130329075520164214669959335884572950998196761529670276750204095954944 5233908914696865974868126341672935032893554256923068867693799813353416758721971564568165355481597014117458166038653914891360184872483842380588200047403885133824 62806656323322400468745940471016487821166054296524285819890751828306293376121324075798383017938968178399121958297108802386029282877649667235770473822592849412096 9044158258164739565219537799588780383587038856657482447051052619802977547407035677113871028326705664781858947238157438129942435653403338998665970804215823114174464 108529899097831820940046936424014653342203856582785167517077566371173964402965603737441279296169745847639257013631017633289531270495391229930495508858965602917679104 1302358789173969763460347610657254947501376228185329958384302874365215758988427342816968253800391056660859163300803305630785227082832574022661488094574951878807781376 15628305470087636154205820025684482628966092233989951829626582165541849790040531455300925120791888855471075632871075592072031962647064878210562485633921702932676345856 187539665641051633766526644366363576819172238265859921316270231625932135870667994408735876955768265946947971400558026765239600988235868037688301879981978958557698064384 2250475987692619605191324466067875403936031786811817430741972049981138125313864400983590921428074658003483578790538414487906479978536340577189751897481657379639508598784 27005711852311435262295310653953797554074545185710267366815892038979486878338526850809654423633467184928478605651781148296963698752411580603354533547921381045419697504256 324068542227737223147543679269207178374464722540520579918283390087687661654610001712966400030809653826548966239501817127433738213279770258380010861806568363585848502910976 3888822506732846677770524147182299607804040852178913406645775071520579758114865660514201012615316516552538196788328509141527373045044812374821776713281446345616916379336704 46665870080794160133246289765850246415924362241288016417051498724119317748900016729500295835737598254516620911619467668332688686081011712604049791090344241645951891080740864 559990440969529921598955477190174844584615336230051284966059834511587843041093669820947707002547329058856631151946905816545127583767180048257446532295044806876301767512948736 6719885291634359059187465726282095792314844283871831676922838168290900452330981826940284497111709294540001005507738977614920936284439080537173429140808113841442694466367389696 80638623499612308710249588715385149312553086427221248144518234699003459289291603405707489966430606646632822185399899073697082852519871709775921488919136330777222923034426343424 967663481995347704522995064584621791734368283378384916736005831111334232626609225992025219263924787685606600401407708162891496864997344079255211228632089216383334292199617593344 11611961783944172454275940775015461500811063671061596495748885557896285184948903210664597242805993911221113599331609907894575170932864702581224547523718608367188066441044286242816 139343541407330069451311289300185538009732651075282572740229694660135445085505971236205191464641834972902849391522212012229891818573784478777208071349634428553805801870418841174016 1672122496887960833415735471602226456116791803488602824115359924918740342931581582560148132954949512011354983214895118573216617636833697749310039647951030736657965372826516711276544 20065469962655530000988825659226717473401501641078668218653702731441310365337771484698918081740998101830969864455127137414137571293166729992052437674725320306063275786449991420084224 240785639551866360011865907910720609680818019692878638151283548079997093238233157190885112021415444218446197545617891125180945702155597622987990248921646589628273283713444212948074496 2889427674622396320142390894928647316169816236314538209442689169901856899596646211238496185510362286204393917145094390625188956329753637881112829736795170971035572235751000915035815936 34673132095468755841708690739143767794037794835774458059281210588234107110221241895274277129562128847417980301290939328929185609949034193440458702404020002643718224564944483510401368064 416077585145625070100504288869725213528453538029293496673538605437926937348910026689992352463365361286762868056787089167269137163887742866191096490978446527640559641257328174835647381504 4992931021747500841206051466436702562341442456351521960079310271786716385855774913942133315136102653367633342051553054775572888453694525439701957230252208873013044107294437629087004491776 59915172260970010094472617597240430748097309476218263520951460511984896058408370183444118538764541700238806681732812322704236598318254439530207553374569077354600389988550459843298990227456 718982067131640121133671411166885168977167713714619162251417504248030777653245364802674299028268776224517947395553262511233952674558546618883639312712457475828408334921023618810775794089984 8627784805579681453604056934002622027726012564575429947017010049151720333918306454515536994719483171012686391014535776354706024885930850538647100808567625422238666990307151600786908521693184 103533417666956177443248683208031464332712150774905159364204120589668589923859624293926731053832152873512109277363420701774797181363772564056435495457479683042888817797957058224031035509702656 1242401012003474129318984198496377571992545809298861912370449447076010407912718820430432463239085697383925300710460131036757426583259654298476615135969311878012667881401673968606254770553880576 14908812144041689551827810381956530863910549711586342948445393364912123839021492789240465533085120023848918607640696495992377440699690383542535997397505038842943514749138936729101547442016354304 178905745728500274621933724583478370366926596539036115381344720378945485980263652382891859394872781257457174541614622528871136648537999146840500020083883240807554802004027144841370776820477067264 2146868948742003295463204695001740444403119158468433384576136644547345831755830973504036168821627653503758607103535992394533857062467799307446839245282750787581677009466189063437462005805414875136 25762427384904039545558456340020885332837429901621200614913639734568149981069360610790878513866461365246292661292778618905079636189614575818142140860416022109137709062379090705027961793328286007296 309149128618848474546701476080250623994049158819454407378963676814817799772832276406885745873731447176555611050184205652708511746895374991828437362818077516364498974160947823622317076330244707713024 3709789543426181694560417712963007487928589905833452888547564121777813597273987312639078550793721858684800674195099706351322770638796166575442142659858020633961891562049073778064636710530461932191744 44517474521114180334725012555556089855143078870001434662570769461333763167287847751315313409550407678598119202140603912759108300138558304461430786443799671810675024067265360327992043175912836972937216 534209694253370164016700150666673078261716946440017215950849233536005158007454173015754291814607037591042473018337197572821235856035450012333513193536054680411694649250740696851839218331749651490799616 6410516331040441968200401808000076939140603357280206591410190802432061896089450076189049046016951296546498429769433866758830824960289796011235186968783527716497301987712518059965065178332728785207558144 76926195972485303618404821696000923269687240287362479096922289629184742753073400914268588347556887795679146886695655359096384565747466251790091662679264905227264037702275519194392698353188723169767194624 923114351669823643420857860352011079236246883448349749163067475550216913036880810971223060153628776234576526451136401722322482677821594079785705737072334077112943153581450005538946706589364342849479376896 11077372220037883721050294324224132950834962601380196989956809706602602956442569731654676721842124158372120547731202532118966947791263462212287185993611438526554132401406912047734546672934963752928108609536 132928466640454604652603531890689595410019551216562363879481716479231235477310836779856120662105371470761880091967560861381861469799945240985351125019065881452082823363418737237920158924708114338365166321664 1595141599685455255831242382688275144920234614598748366553780597750774825727730041358273447945264447780000597230210157876245192478958074866360705574653434629019446649906569496243800707000621417835650984443904 19141699196225463069974908592259301739042815375184980398645367173009297908732760496299281375343173372537578669773071846809914214317610126060873174568709935885866230863007629342374671717332800684509084229042176 229700390354705556839698903107111620868513784502219764783744406076111574904793125955591376504118080470382408329194407991076884897192164281702523487130591623991864176278102285057450149210770720186649116783149056 2756404684256466682076386837285339450422165414026637177404932872913338898857517511467096518049416965644583188641326024712035778293421041611177952294925938854015825899164061648435147964579480068237501076900675584 33076856211077600184916642047424073405065984968319646128859194474960066786290210137605158216593003587734997787753495057279355436148312088520031066743224502862032698771954309300200587756124613437683155562433347584 396922274532931202218999704569088880860791819619835753546310333699520801435482521651261898599116043052819973413380072584080175741832016694672530770852370137395545950928617175728988620755259598970433961969168941056 4763067294395174426627996454829066570329501835438029042555724004394249617225790259815142783189392516633839680957255715333689434777655222972106382414389581324000814208282169897425078579703262207455060551565024690176 57156807532742093119535957457948798843954022025256348510668688052730995406709483117781713398272710199606076171486793154364667161154835260884946256736355070860947625732480935751490710883992492074444881036108212731904 685881690392905117434431489495385586127448264303076182128024256632771944880513797413380560779272522395272914057841494899906038762509937512720994219816567524912449663392529137099754344601872683692087251968075879153664 8230580284714861409213177873944627033529379171636914185536291079593263338566165568960566729351270268743274968694097936886166634552506909684493733899380502521831152473593912804203874286388635769204942746911475327041536 98766963416578336910558134487335524402352550059642970226435492955119160062793986827526800752215243224919299624329175242474607462080281887841578290397697837947213976059200583913697059949260809527534304273212250989264896 1185203560998940042926697613848026292828230600715715642717225915461429920753527841930321609026582918699031595491950102909682006865584232568401243941739468372673671058241746476152968933433846146021834567221069890793242624 14222442731987280515120371366176315513938767208588587712606710985537159049042334103163859308318995024388379145903401234916182975497062528313673452672287544998526311311028569336268010885709713454902966716314715596095750144 170669312783847366181444456394115786167265206503063052551280531826445908588508009237966311699827940292660549750840814818994195613723921317888486309181735033692852590616686799670418829268891858100722346588248410228697071616 2048031753406168394177333476729389434007182478036756630615366381917350903062096110855595740397935283511926597010089777827930347357000320062838869449940344112123442491973936926681292842780066905262158721225020241333993865216 24576381040874020730128001720752673208086189736441079567384396583008210836745153330267148884775223402143119164121077333935164168283363279441414519544264089654465410854068384397728536354323583247150362201547412839223728799744 294916572490488248761536020649032078497034276837292954808612758996098530040941839963205786617302680825717429969452928007221970019400305973187586575043250739212666938661352374545871854771963230664471384547472884899286062465024 3538998869885858985138432247788384941964411322047515457703353107953182360491302079558469439407632169908609159633435136086663640232803667229908589928895015675831926764637272808031556375473565453948545534413749946360482859319296 42467986438630307821661186973460619303572935864570185492440237295438188325895624954701633272891586038903309915601221633039963682793644006388207875065771522010423114800705694055835434348866952671213787156285338966956548487643136 509615837263563693859934243681527431642875230374842225909282847545258259910747499456419599274699032466839718987214659596479564193523728076627603233782510875283447377077223197033313275340002112656551382604034095904364478033035264 6115390047162764326319210924178329179714502764498106710911394170543099118928969993477035191296388389602076627846575915157754770322284736919528664533139568220997899358215741270096699976009491908595448752642459986544114227744866304 73384680565953171915830531090139950156574033173977280530936730046517189427147639921724422295556660675224919534158910981893057243867416843034343759874987271795107836534696317149968478101441358449538454378492357408170349107217432576 880616166791438062989966373081679401878888398087727366371240760558206273125771679060693067546679928102699034409906931782716686926409002116412125100622956632636555125436031424292022410416406922689994208320806858695514270817799110656 10567394001497256755879596476980152822546660777052728396454889126698475277509260148728316810560159137232388412918883181392600243116908025396945501205985738705896599929150683393045302314430142290721224896164590518495960423274521821184 126808728017967081070555157723761833870559929324632740757458669520381703330111121784739801726721909646788660955026598176711202917402896304763346014471704719396947360685134726241672047222281145756858139953667995239797340843749339561984 1521704736215604972846661892685142006446719151895592889089504034244580439961333461416877620720662915761463931460319178120534435008834755657160152173660446287340550675016227258693825268288133702271314632877323685295721908105363331219456 18260456834587259674159942712221704077360629822747114669074048410934965279536001537002531448647954989137567177523830137446413220106017067885921826083925354585968039962427611316308716611259334423354860340647326535416842382096057579339776 219125482015047116089919312546660448928327557872965376028888580931219583354432018444030377383775459869650806130285961649356958641272204814631061913007104254959773265537650742813369833784428823913266581149944538617657790208888665752469504 2629505784180565393079031750559925387139930694475584512346662971174635000253184221328364528605305518435809673563431539792283503695266457775572742956085251059511292251950852197678576774950588954528616328554515848427948122641975320263000064 31554069410166784716948381006719104645679168333707014148159955654095620003038210655940374343263666221229716082761178477507402044343197493306872915473023012714135008112201813312469432863535187709974180722217121963220048691714979787425447936 378648832922001416603380572080629255748150020004484169777919467849147440036458527871284492119163994654756592993134141730088824532118369919682474985676276152569620055770487725327993736992766262540992734064902374540480973568914030444461162496 4543785995064016999240566864967551068977800240053810037335033614189769280437502334455413905429967935857079115917609700761065894385420439036189699828115313830835440665781191534400788222465723817993688022562019903734258381932662888083146932224 54525431940768203990886802379610612827733602880645720448020403370277231365250028013464966865159615230284949391011316409132790732625045268434276397937383765970025287989085576648681530617801396538216070871892838128915141141450762533893564268544 654305183289218447890641628555327353932803234567748645376244840443326776383000336161579602381915382763419392692135796909593488791500543221211316775248605191640303455869002859637167706742634484352117168346143107487323697077264051063130754646016 7851662199470621374687699542663928247193638814812983744514938085319921316596004033938955228582984593161032712305629562915121865498006518654535801302983262299683641470428032310633761592522365289383199713310669710676246198542156521145603054370816 94219946393647456496252394511967138966323665777755804934179257023839055799152048407267462742995815117932392547667554754981462385976078223854429615635799147596203697645136387560520784869569279429028212700824449229850651201973793912779572819001344 1130639356723769477955028734143605667595883989333069659210151084286068669589824580887209552915949781415188710572010657059777548631712938686253155387629589771154444371741636650712325722248106427811374370421651425150019122491974519924940901841895424 13567672280685233735460344809723268011150607871996835910521813011432824035077894970646514634991397376982264526864127884717330583580555264235037864651555077253853332460899639808546748358961716723291745429894130271332880412242718321846922991103901696 162812067368222804825524137716679216133807294463962030926261756137193888420934739647758175619896768523787174322369534616607967002966663170820454375818660927046239989530795677702560883615205970645297216240799089353455619192107538535725378573996916736 1953744808418673657906289652600150593605687533567544371115141073646326661051216875773098107438761222285446091868434415399295604035599958049845452509823931124554879874369548132430730595324777095240716284146428199416255851492390038984834734778025508864 23444937701024083894875475831201807123268250402810532453381692883755919932614602509277177289265134667425353102421212984791547248427199496598145430117887173494658558492434577589168767143225850596846691217195208320259635919674272099197694333327144648704 281339252412289006738505709974421685479219004833726389440580314605071039191375230111326127471181616009104237229054555817498566981126393959177745161414646081935902701909214931070025205718654250949990135923629005670387678177905064492987305126258305662976 3376071028947468080862068519693060225750628058004716673286963775260852470296502761335913529654179392109250846748654669809982803773516727510132941936975752983230832422910579172840302468623846348382200784526655276863591475396678590524398909275627382112256 40512852347369616970344822236316722709007536696056600079443565303130229643558033136030962355850152705311010160983856037719793645282200730121595303243709035798769989074926950074083629623486155792001602677106788923098009316198627904343499515287572561526784 486154228168435403644137866835800672508090440352679200953322783637562755722696397632371548270201832463732121931806272452637523743386408761459143638924508429585239868899123400889003555481833869471637164897180377543904021095336741920292886900449207736336384 5833850738021224843729654402029608070097085284232150411439873403650753068672356771588458579242421989564785463181675269431650284920636905137509723667094101155022878426789480810668042665782006433656947473163822773065742245585787003632528883865140354252537856 70006208856254698124755852824355296841165023410785804937278480843809036824068281259061502950909063874777425558180103233179803419047642861650116684005129213860274541121473769728016511989384077203883144802499011463667148113066256218639431126469996739481829376 840074506275056377497070233892263562093980280929429659247341770125708441888819375108738035410908766497329106698161238798157641028571714339801400208061550566323294493457685236736198143872608926446597718890365899079578964120631475638260597227647320247819567104 10080894075300676529964842806707162745127763371153155910968101241508501302665832501304856424930905197967949280377934865577891692342860572077616802496738606795879533921492222840834377726471307117359172625122755602414578668344564074410342785374268456255004606464 120970728903608118359578113680485952941533160453837870931617214898102015631989990015658277099170862375615391364535218386934700308114326864931401629960863281550554407057906674090012532717655685408310071501342930963429913278376184423486714726044763192833486094336 1451648746843297420314937364165831435298397925446054451179406578777224187583879880187899325190050348507384696374422620643216403697371922379176819559530359378606652884694880089080150392611868224899720858016104326872363540112034331042720793487666620123816285700096 17419784962119569043779248369989977223580775105352653414152878945326690251006558562254791902280604182088616356493071447718596844368463068550121834714364312543279834616338561068961804711342418698796650296193251018744296196408705315676056206583260229969946632781824 209037419545434828525350980439879726682969301264231840969834547343920283012078702747057502827367250185063396277916857372623162132421556822601462016572371750519358015396062732827541656536109024385559803554319012149621215499826488233376291702726727825346372193746944 2508449034545217942304211765278556720195631615170782091638014568127043396144944432964690033928407002220760755335002288471477945589058681871217544198868461006232296184752752793930499878433308292626717642651828145789178724426494694170954135201364700992965384041660416 30101388414542615307650541183342680642347579382049385099656174817524520753739333195576280407140884026649129064020027461657735347068704182454610530386421532074787554217033033527165998541199699511520611711821937749469621704653651066332319508647096742506318684976316416 361216660974511383691806494200112167708170952584592621195874097810294249044871998346915364885690608319789548768240329539892824164824450189455326364637058384897450650604396402325991982494396394138247340541863252993635416873471789024011239927617720937625052059422162944 4334599931694136604301677930401346012498051431015111454350489173723530988538463980162984378628287299837474585218883954478713889977893402273463916375644700618769407807252756827911903789932756729658968086502359035923624998849797132973803496283400364587129727033041485824 52015199180329639251620135164816152149976617172181337452205870084682371862461567761955812543539447598049695022626607453744566679734720827281566996507736407425232893687033081934942845479193080755907617038028308431083499985894910234409447673496803351156859149589829124096 624182390163955671019441621977793825799719406066176049426470441016188462349538813143469750522473371176596340271519289444934800156816649927378803958092836889102794724244396983219314145750316969070891404456339701173001999830713701532807022558469640128558251663844060430336 7490188681967468052233299463733525909596632872794112593117645292194261548194465757721637006269680454119156083258231473339217601881799799128545647497114042669233536690932763798631769749003803628850696853476076414076023997968562316620342074908011348202255348455192567742464 89882264183609616626799593564802310915159594473529351117411743506331138578333589092659644075236165449429872999098777680070611222581597589542547769965368512030802440291193165583581236988045643546208362241712916968912287975622747624296326382580000817315360542169732799791104 1078587170203315399521595122777627730981915133682352213408940922075973662940003069111915728902833985393158475989185332160847334670979171074510573239584422144369629283494317987002974843856547722554500346900555003626947455707472971476960268381266998527691684536095745429733376 12943046042439784794259141473331532771782981604188226560907291064911683955280036829342988746834007824717901711870223985930168016051750052894126878875013065732435551401931815844035698126278572670654004162806660043523369468489675657722306916557729564725625827602320524476153856 155316552509277417531109697679978393261395779250258718730887492778940207463360441952115864962008093896614820542442687831162016192621000634729522546500156788789226616823181790128428377515342872047848049953679920522280433621876107892667581640024631908573620398991943925323792384 1863798630111329010373316372159740719136749351003104624770649913347282489560325303425390379544097126759377846509312253973944194311452007616754270558001881465470719401878181481541140530184114464574176599444159046267365203462513294712010971233739905997205620660217001906519670784 22365583561335948124479796465916888629640992212037255497247798960167389874723903641104684554529165521112534158111747047687330331737424091401051246696022577585648632822538177778493686362209373574890119193329908555208382441550159536544131654100999232224327629245296829111788896256 268387002736031377493757557591002663555691906544447065966973587522008678496686843693256214654349986253350409897340964572247963980849089096812614960352270931027783593870458133341924236346512482898681430319958902662500589298601914438529579849153334150046753232720453016527596158976 3220644032832376529925090691092031962668302878533364791603683050264104141960242124319074575852199835040204918768091574866975567770189069161751379524227251172333403126445497600103090836158149794784177163839506831950007071583222973262354958189835121747507273932793510453929998024704 38647728393988518359101088293104383552019634542400377499244196603169249703522905491828894910226398020482459025217098898403706813242268829941016554290727014068000837517345971201237090033897797537410125966074081983400084858998675679148259498278021053632332806788534464968459879972864 463772740727862220309213059517252602624235614508804529990930359238030996442274865901946738922716776245789508302605186780844481758907225959292198651488724168816010050208151654414845080406773570448921511592888983800801018307984108149779113979336252609643180808095331274581626884980736 5565272888734346643710556714207031231490827374105654359891164310856371957307298390823360867072601314949474099631262241370133781106886711511506383817864690025792120602497819852978140964881282845387058139114667805609612219695809297797349367752035031312889435291030051769559531646877696 66783274664812159724526680570484374777889928489267852318693971730276463487687580689880330404871215779393689195575146896441605373282640538138076605814376280309505447229973838235737691578575394144644697669376013667315346636349711573568192413024420375754437495625184460940929380514791424 801399295977745916694320166845812497334679141871214227824327660763317561852250968278563964858454589352724270346901762757299264479391686457656919269772515363714065366759686058828852298942904729735736372032512164007784159636196538882818308956293044509053230303513282184600003816240185344 9616791551732951000331842002149749968016149702454570733891931929159810742227011619342767578301455072232691244162821153087591173752700237491883031237270184364568784401116232705946227587314856756828836464390145968093409915634358466593819707475516534108638762005160308602975783399054114816 115401498620795412003982104025796999616193796429454848806703183149917728906724139432113210939617460866792294929953853837051094085032402849902596374847242212374825412813394792471354731047778281081946037572681751617120918987612301599125836489706198409303665143925507113434690712255663702016 1384817983449544944047785248309563995394325557153458185680438197799012746880689673185358531275409530401507539159446246044613129020388834198831156498166906548497904953760737509656256772573339372983352450872181019405451027851347619189510037876474380911643981727094717312066203656356882284544 16617815801394539328573422979714767944731906685841498228165258373588152962568276078224302375304914364818090469913354952535357548244666010385973877978002878581974859445128850115875081270880072475800229410466172232865412334216171430274120454517692570939727780725135660407365270135389997236224 199413789616734471942881075756577215336782880230097978737983100483057835550819312938691628503658972377817085638960259430424290578935992124631686535736034542983698313341546201390500975250560869709602752925594066794384948010594057163289445454212310851276733368701627845943597477146272250986496 2392965475400813663314572909078926584041394562761175744855797205796694026609831755264299542043907668533805027667523113165091486947231905495580238428832414515804379760098554416686011703006730436515233035107128801532619376127128685959473345450547730215320800424419534144744437578715399702183936 28715585704809763959774874908947119008496734753134108938269566469560328319317981063171594504526892022405660332010277357981097843366782865946962861145988974189652557121182653000232140436080765238182796421285545618391432513525544231513680145406572762583849605093034409736385023265664807483736064 344587028457717167517298498907365428101960817037609307259234797634723939831815772758059134054322704268867923984123328295773174120401394391363554333751867690275830685454191836002785685232969182858193557055426547420697190162306530778164161744878873151006195261116412916836574593548067690726293504 4135044341492606010207581986888385137223529804451311687110817571616687277981789273096709608651872451226415087809479939549278089444816732696362652005022412283309968225450302032033428222795630194298322684665118569048366281947678369337969940938546477812074343133396955002038891315440153122125643776 49620532097911272122490983842660621646682357653415740245329810859400247335781471277160515303822469414716981053713759274591337073337800792356351824060268947399719618705403624384401138673547562331579872215981422828580395383372140432055639291262557733744892117600763460024466695468020449201625235456 595446385174935265469891806111927459760188291840988882943957730312802968029377655325926183645869632976603772644565111295096044880053609508276221888723227368796635424464843492612813664082570747978958466591777073942964744600465685184667671495150692804938705411209161520293600345589806941397512617984 7145356622099223185638701673343129517122259502091866595327492763753635616352531863911114203750435595719245271734781335541152538560643314099314662664678728425559625093578121911353763968990848975747501599101324887315576935205588222216012057941808313659264464934509938243523204147075480092684985565184 85744279465190678227664420080117554205467114025102399143929913165043627396230382366933370445005227148630943260817376026493830462727719769191775951976144741106715501122937462936245167627890187708970019189215898647786923222467058666592144695301699763911173579214119258922278449764905577511879396294656 1028931353582288138731973040961410650465605368301228789727158957980523528754764588403200445340062725783571319129808512317925965552732637230301311423713736893280586013475249555234942011534682252507640230270590783773443078669604703999105736343620397166934082950569431107067341397178866914842524386328576 12347176242987457664783676491536927805587264419614745476725907495766282345057175060838405344080752709402855829557702147815111586632791646763615737084564842719367032161702994662819304138416187030091682763247089405281316944035256447989268836123444766003208995406833173284808096766146402976835290271842304 148166114915849491977404117898443133667047173035376945720710889949195388140686100730060864128969032512834269954692425773781339039593499761163388845014778112632404385940435935953831649660994244361100193158965072863375803328423077375871226033481337192038507944881998079417697161193756835721917233065099264 1777993378990193903728849414781317604004566076424523348648530679390344657688233208760730369547628390154011239456309109285376068475121997133960666140177337351588852631285231231445979795931930932333202317907580874360509639941076928510454712401776046304462095338583976953012365934325082028662997942598107136 21335920547882326844746192977375811248054792917094280183782368152684135892258798505128764434571540681848134873475709311424512821701463965607527993682128048219066231575422774777351757551183171187998427814890970492326115679292923142125456548821312555653545144063007723436148391211900984343955974573328695296 256031046574587922136954315728509734976657515005131362205388417832209630707105582061545173214858488182177618481708511737094153860417567587290335924185536578628794778905073297328221090614198054255981133778691645907913388151515077705505478585855750667842541728756092681233780694542811812127471694818456961024 3072372558895055065643451788742116819719890180061576346464661013986515568485266984738542078578301858186131421780502140845129846325010811047484031090226438943545537346860879567938653087370376651071773605344299750894960657818180932466065743030269008014110500745073112174805368334513741745529660337816359583744 36868470706740660787721421464905401836638682160738916157575932167838186821823203816862504942939622298233577061366025690141558155900129732569808373082717267322546448162330554815263837048444519812861283264131597010739527893818171189592788916363228096169326008940877346097664420014164900946355924053795888009216 442421648480887929452657057578864822039664185928866993890911186014058241861878445802350059315275467578802924736392308281698697870801556790837700476992607207870557377947966657783166044581334237754335399169579164128874334725818054275113466996358737154031912107290528153171973040169978811356271088645550620527616 5309059781770655153431884690946377864475970231146403926690934232168698902342541349628200711783305610945635096836707699380384374449618681490052405723911286494446688535375599893397992534976010853052024790034949969546492016709816651301361603956304845848382945287486337838063676482039745736275253063746607443366144 63708717381247861841182616291356534373711642773756847120291210786024386828110496195538408541399667331347621162040492392564612493395424177880628868686935437933360262424507198720775910419712130236624297480419399634557904200517799815616339247475658150180595343449836054056764117784476948835303036764959289320146624 764504608574974342094191395496278412484539713285082165443494529432292641937325954346460902496796007976171453944485908710775349920745090134567546424243225255200323149094086384649310925036545562839491569765032795614694850406213597787396070969707897802167144121398032648681169413413723386023636441179511471841738896 9174055302899692105130296745955340949814476559420985985321934353187511703247911452157530829961552095714057447333830904529304199048941081614810557090918703062403877789129036615791731100438546754073898837180393547376338204874563173448752851636494773626005729456776391784174032960964680632283637294154137662100865036 110088663634796305261563560951464091397773718713051831823863212238250140438974937425890369959538625148568689368005970854351650388587292979377726685091024436748846533469548439389500773205262561048886786046164722568516058458494758081385034219637937283512068753481316701410088395531576167587403647529849651945210380289\n"}, {"input": "2889427674622396320142390894928647316169816252697059428341402948472568589293051819553950850210813089998113484982604588285599036749945994951924186567506019510491717107585005090584395776\r\n", "output": "YES\n1\n300\n149\n816486509416551206890999810156936275077562651601492757422903878683260476823346091649104470028857477592733096727483620051353808592355613270307626348171320335794176 9049392146033442543041914562572710382109652721916544728103851322072803618125419182444241209486503709986125155396276788902504711898608047079242858692232133721718784 108530335255154212854865467820929980842080741071556756040498632929696449908858802362885476811266395684739612530977527579187244793515824955603876916182966962134974464 1302358825520413296119915821606997891459699301892727590761254629911759299447251776035755270259982444147284192927248848126276703209750943499800936545185285325409222656 15628305473116506448594117376596961207629285823465568298991328145170728418412100158069157372163521471094944385339946053946656252324308075666990773004805897386559799296 187539665641304039624392335812272950034060837731649556022050627124234542423032291800633229643382568664916627129930432637062486345708971637476337570596219308095521685504 2250475987692640639012813273688367851703939170100633233634120416272663325859894759099582367485375849896647633434652781643891720424992432543838754871699510742100993900544 27005711852311437015113768054588838591388537467651002017056904402837113978384029380652653710804908950919575610205457345559962468789616254933908617129106202158958154612736 324068542227737223293611884052593431794240888564015641139136807784675797246280460257119983304740607307048224323214623477205654777449537314574223702105000432011976707670016 3888822506732846677782696497580915128922355532680871328414179522995328769414171532059547144554810762675913134961971243004008366092058959629504627783306315684652427063066624 46665870080794160133247304128383464376017555131329846243865532428408880166508292218795741346732556108360235489800604562821228768834929558208606695346179647424204850304385024 559990440969529921598955561720385946081289768970888104118294337320278639909227692778388994128463575546676932366795333891085839257330006535391159607649697757357822847448252416 6719885291634359059187465733326280050772900486600234745185524376858291352069992995520071271038868981747319363942309679954465995590569316077767905230421001587316154556361998336 80638623499612308710249588715972164667424591110781948400206791883050741864269854336422472197591203287233432048602779965558711607462049229404304361926604071422712378041925894144 967663481995347704522995064584670709680607575435348308423979877543338172841190746902918134449854837405656651223341281570546632594575858872557576468049378194770458413450242555904 11611961783944172454275940775015465577306583612066343445056216728432285513300118337407171652404821415364451103566771039011879765576996245480666411293670049115386993451148504989696 139343541407330069451311289300185538349440611070366301652671972257680111779535239163433739332108403931581460850208475439823000534794128774018828226663797048616155712454594192736256 1672122496887960833415735471602226456145100800154859801524730114718535731822750688220750511943905059424578200836452307192182710029852059773913507994227210954996494532041864657240064 20065469962655530000988825659226717473403860724134189633437816913924626647745368910170634946656744397448738465923590236465718078992584926827436060036915001990924819883051270415581184 240785639551866360011865907910720609680818216283133264935848890928537369595100456976341088426825089743081011595740263050101910744463882472724272217451829063102011745721494319531032576 34673132095468755841708690739143767794037794837139668160856103403114999751029275695967231684953833081067456931944065178734219783317383556529692982139912573355339569970930650525030416384 416077585145625070100504288869725213528453538029407264182003179839167011735644029506716765342981336639566991109341516321419556678335105313115199347623104241866528086707827022086866468864 4992931021747500841206051466436702562341442456351531440705015652986819725388002747510193682876070651313700352305932590371752090079898472310278965801639263682531874811081979199691272749056 59915172260970010094472617597240430748097309476218264311003602627084904670036055836241456902742872366734312265920677284003918198453771435102755637422184665255393625880532754974182679248896 718982067131640121133671411166885168977167713714619162317255182757622445037547671940407410558600303780059239527568917924675592807903173035181351653049758774820141104578688810071682768175104 8627784805579681453604056934002622027726012564575429947022496522360852972866998313443681420680344131642314832025537080972492828230376236073338576836929067197154644721111957033391984102866944 103533417666956177443248683208031464332712150774905159364204577795769350977105348615504076422662224620231244980781004143826279414975809679517659785126509803190798482608857458676748125141467136 1242401012003474129318984198496377571992545809298861912370449485176518804667155964123897242019821536696151895352411596323595050102727324058098383826775064388024993686802582335310647861356527616 14908812144041689551827810381956530863910549711586342948445393368087166205417695884548254264650181343791604157194192451432947242659646022689171144788405518218777875232922345759660246866249908224 178905745728500274621933724583478370366926596539036115381344720379210072844130002640834175122503203034119065004077413858491184132034662116769386282366458280755540998711009095593917335105829863424 2146868948742003295463204695001740444403119158468433384576136644547367880661153169358864695132263521985147097975407891672002194352759187888274246433806298707577342525858437559333507552329194274816 25762427384904039545558456340020885332837429901621200614913639734568151818478137460445447557725681020953075035532101277178201997630472191533211091459459651102470681188745111413019298922205267623936 309149128618848474546701476080250623994049158819454407378963676814817799925949674477690293294053048814531176248037482540897938610348779793138026442034664485447276721838144992014649687757651122847744 3709789543426181694560417712963007487928589905833452888547564121777813597286747095811645596412081992154631971294920812758671889544083950308884608416459402881385456374355506875430664428149412466786304 44517474521114180334725012555556089855143078870001434662570769461333763167288911066579693996685271023053938476898922338293054060047332286439217658590183120331293654468290896419439212152381082850820096 534209694253370164016700150666673078261716946440017215950849233536005158007454261625359656863534942869747124624567057441615731336027847844164995432881586634455079535117492824859459815746455338647289856 6410516331040441968200401808000076939140603357280206591410190802432061896089450083573182826437695288653057150736619688414563699583622495830554477155395655379334250728201414070632366894783954259137265664 76926195972485303618404821696000923269687240287362479096922289629184742753073400914883932829258616461688026780109587510901028971966077310108368270194815915865833783430649593861948306829559658625928003584 923114351669823643420857860352011079236246883448349749163067475550216913036880810971274338860437253623410599775587562734972869711673145001312228787698629994666157299058814511761243007295728587470826110976 11077372220037883721050294324224132950834962601380196989956809706602602956442569731654680995067691531487856720508240128870021146710751091455747729581163629853016900246863359089919738031327160773313220837376 132928466640454604652603531890689595410019551216562363879481716479231235477310836779856121018207502085188191439698980661111115986376569210088972836984695230729288054017206774491435591537907464090063925673984 1595141599685455255831242382688275144920234614598748366553780597750774825727730041358273447974939625331202789842521109526222630355339460197119340717317237074792547085794385166014926993051721363648292547723264 19141699196225463069974908592259301739042815375184980398645367173009297908732760496299281375345646304000178852490764426114079000807308574838436394163931919423013989232664947314855598907837059013326804359315456 229700390354705556839698903107111620868513784502219764783744406076111574904793125955591376504118286548004291677754215706018898629399639152433987088763526789286626489475573728221823559809979408380717260127338496 2756404684256466682076386837285339450422165414026637177404932872913338898857517511467096518049416982817718345587039342021614279437771664517072240928395350117790389425263850935365512415462747458920340088846024704 33076856211077600184916642047424073405065984968319646128859194474960066786290210137605158216593003589166092384165637833721820311243674640428855590796013620467347245732462625074111451460364885720240058813428793344 396922274532931202218999704569088880860791819619835753546310333699520801435482521651261898599116043052939231296414417815450381148089963573998266147856769230529322163175326202043481192730612954993980370573418561536 4763067294395174426627996454829066570329501835438029042555724004394249617225790259815142783189392516633849619114175244102970285228176718545383527029139947915095295559302728982951286294034541653790356085615378825216 57156807532742093119535957457948798843954022025256348510668688052730995406709483117781713398272710199606076999666536448428773898692378718849386018787584268076872165845065982341951228193520098694972822330612408909824 685881690392905117434431489495385586127448264303076182128024256632771944880513797413380560779272522395272914126856473507744714323971399467551364199987503291347110041735244557648959387710999984243797913742617895501824 8230580284714861409213177873944627033529379171636914185536291079593263338566165568960566729351270268743274968699849185103486524182628698180729598064394747169034040838455805755916308039981063044250918635392687161737216 98766963416578336910558134487335524402352550059642970226435492955119160062793986827526800752215243224919299624329654513159384119549458703549597945744782358334480883422939074993006429428726845133788135597252351975489536 1185203560998940042926697613848026292828230600715715642717225915461429920753527841930321609026582918699031595491950142848905738253706663969710245579685058749372609967188724683742911380890468315655689053164739899208761344 14222442731987280515120371366176315513938767208588587712606710985537159049042334103163859308318995024388379145903401238244451619779406064263782536142116344196584556220107484186900506089664431969039121256810021430130376704 170669312783847366181444456394115786167265206503063052551280531826445908588508009237966311699827940292660549750840814819271551334080783279217662066137554100292690777692443375907971537202554751310233692799956352381533290496 2048031753406168394177333476729389434007182478036756630615366381917350903062096110855595740397935283511926597010089777827953460333696725226282967429686662367673429007563583308034422235107872146362951333409329236513396883456 24576381040874020730128001720752673208086189736441079567384396583008210836745153330267148884775223402143119164121077333935166094364754646538368194375909616175761243063700854929507963803684233683908761585896105255488679051264 294916572490488248761536020649032078497034276837292954808612758996098530040941839963205786617302680825717429969452928007221970179907088587112332714612554533089441591345488413756853473726076618200867917829501942600641474985984 3538998869885858985138432247788384941964411322047515457703353107953182360491302079558469439407632169908609159633435136086663640246179232447735652107192457658654991319027617477965804843719741569576578578853919034502262477029376 42467986438630307821661186973460619303572935864570185492440237295438188325895624954701633272891586038903309915601221633039963682794758636823026796913962975508991703513571556111663288387887467347516123243322019724301696789118976 509615837263563693859934243681527431642875230374842225909282847545258259910747499456419599274699032466839718987214659596479564193523820962497171477269860163074994759469962018871298929843253822212909910611287152634143240391491584 6115390047162764326319210924178329179714502764498106710911394170543099118928969993477035191296388389602076627846575915157754770322284744660017795220096847328313861640081802838583198780551429551058478629976397741271595791274737664 73384680565953171915830531090139950156574033173977280530936730046517189427147639921724422295556660675224919534158910981893057243867416843679384520765567045054050833391518488947342353001819853253077040201603518887730972570844921856 880616166791438062989966373081679401878888398087727366371240760558206273125771679060693067546679928102699034409906931782716686926409002116465878497363838280408133708507433271941803566658105130590289090472732788818810989439768068096 10567394001497256755879596476980152822546660777052728396454889126698475277509260148728316810560159137232388412918883181392600243116908025396949980655714145509877564811073300213682784077450283808046249469677251012672901816493019234304 126808728017967081070555157723761833870559929324632740757458669520381703330111121784739801726721909646788660955026598176711202917402896304763346387759182086630612441091961610976725170702532824216635225334794050280978752626517547679744 1521704736215604972846661892685142006446719151895592889089504034244580439961333461416877620720662915761463931460319178120534435008834755657160152204767736067943356098383462832421746361911488008809629389992417523215820359087260681895936 18260456834587259674159942712221704077360629822747114669074048410934965279536001537002531448647954989137567177523830137446413220106017067885921826086517628734351607081041547614119376702394613948899719903740251021910183919677882358562816 219125482015047116089919312546660448928327557872965376028888580931219583354432018444030377383775459869650806130285961649356958641272204814631061913007320277805471896130868570838187388792023430540395319446868948991532235337020484484071424 2629505784180565393079031750559925387139930694475584512346662971174635000253184221328364528605305518435809673563431539792283503695266457775572742956085269061415100471166953683347311571201221838414210390079259549292437659735986305157300224 31554069410166784716948381006719104645679168333707014148159955654095620003038210655940374343263666221229716082761178477507402044343197493306872915473023014214293658797136488436275160763222740450297980227344183938292089486472814036166639616 378648832922001416603380572080629255748150020004484169777919467849147440036458527871284492119163994654756592993134141730088824532118369919682474985676276152694633276660898948254977547651073558602686384023662963038403643635143849965189595136 4543785995064016999240566864967551068977800240053810037335033614189769280437502334455413905429967935857079115917609700761065894385420439036189699828115313830845858434188725802978036873353916092665495826725249952775751937771515373043207634944 54525431940768203990886802379610612827733602880645720448020403370277231365250028013464966865159615230284949391011316409132790732625045268434276397937383765970026156136452871171062968005375412561105388188906440633001932271104000240973569327104 654305183289218447890641628555327353932803234567748645376244840443326776383000336161579602381915382763419392692135796909593488791500543221211316775248605191640303528214616800847366159858265652354024611455894241029330929671401820872054088400896 7851662199470621374687699542663928247193638814812983744514938085319921316596004033938955228582984593161032712305629562915121865498006518654535801302983262299683641476456833472401278130282001220050025333569815638471413467925001335296346665517056 94219946393647456496252394511967138966323665777755804934179257023839055799152048407267462742995815117932392547667554754981462385976078223854429615635799147596203697645638787657334744581049249089917114835846044723833581807755697647292134786596864 1130639356723769477955028734143605667595883989333069659210151084286068669589824580887209552915949781415188710572010657059777548631712938686253155387629589771154444371741678517387060218890729758616448445599569891441184366709123011902816948672528384 13567672280685233735460344809723268011150607871996835910521813011432824035077894970646514634991397376982264526864127884717330583580555264235037864651555077253853332460899643297436309567015268667525501602825623476857144182594147362845079328339787776 162812067368222804825524137716679216133807294463962030926261756137193888420934739647758175619896768523787174322369534616607967002966663170820454375818660927046239989530795677993301680382543766640650029255210047120582641172970157622475224935433240576 1953744808418673657906289652600150593605687533567544371115141073646326661051216875773098107438761222285446091868434415399295604035599958049845452509823931124554879874369548132454958995055388578240329018564295779230183103324128590575397221974811869184 23444937701024083894875475831201807123268250402810532453381692883755919932614602509277177289265134667425353102421212984791547248427199496598145430117887173494658558492434577589170786176536734887096658945063363951910796523993583645163574540593543512064 281339252412289006738505709974421685479219004833726389440580314605071039191375230111326127471181616009104237229054555817498566981126393959177745161414646081935902701909214931070025373971430157974177633234284685306358608228265007121817795143530505568256 3376071028947468080862068519693060225750628058004716673286963775260852470296502761335913529654179392109250846748654669809982803773516727510132941936975752983230832422910579172840302482644911007300883075969209916833255719567541919076801450110400065437696 40512852347369616970344822236316722709007536696056600079443565303130229643558033136030962355850152705311010160983856037719793645282200730121595303243709035798769989074926950074083629624654577846911492868060335143095481336546199848389533060357136951803904 486154228168435403644137866835800672508090440352679200953322783637562755722696397632371548270201832463732121931806272452637523743386408761459143638924508429585239868899123400889003555481931237976212989079759839728903810430365706248963389695871671435526144 5833850738021224843729654402029608070097085284232150411439873403650753068672356771588458579242421989564785463181675269431650284920636905137509723667094101155022878426789480810668042665782014547698995458512371061581158894697039417326584759098092226227470336 70006208856254698124755852824355296841165023410785804937278480843809036824068281259061502950909063874777425558180103233179803419047642861650116684005129213860274541121473769728016511989384077880053315467944723821043432833825527253113935782739409395479740416 840074506275056377497070233892263562093980280929429659247341770125708441888819375108738035410908766497329106698161238798157641028571714339801400208061550566323294493457685236736198143872608926502945233112486375109360321180694748224466805949003104635819393024 10080894075300676529964842806707162745127763371153155910968101241508501302665832501304856424930905197967949280377934865577891692342860572077616802496738606795879533921492222840834377726471307117363868251307932308750393781432902680459193302767714771620671258624 120970728903608118359578113680485952941533160453837870931617214898102015631989990015658277099170862375615391364535218386934700308114326864931401629960863281550554407057906674090012532717655685408310462803525029022291231204466879307324118935827550385780624982016 1451648746843297420314937364165831435298397925446054451179406578777224187583879880187899325190050348507384696374422620643216403697371922379176819559530359378606652884694880089080150392611868224899720890624619501710601983272541888949707243838481852389895213940736 17419784962119569043779248369989977223580775105352653414152878945326690251006558562254791902280604182088616356493071447718596844368463068550121834714364312543279834616338561068961804711342418698796650298910627283314149400005414278834971744112494832658786543468544 209037419545434828525350980439879726682969301264231840969834547343920283012078702747057502827367250185063396277916857372623162132421556822601462016572371750519358015396062732827541656536109024385559803554545460171668703266792880646972867997520830708903775519637504 2508449034545217942304211765278556720195631615170782091638014568127043396144944432964690033928407002220760755335002288471477945589058681871217544198868461006232296184752752793930499878433308292626717642651847016457682681740408560205420516559264209566595167652151296 30101388414542615307650541183342680642347579382049385099656174817524520753739333195576280407140884026649129064020027461657735347068704182454610530386421532074787554217033033527165998541199699511520611711821939322025330367763143888501858373760255034887454500277190656 361216660974511383691806494200112167708170952584592621195874097810294249044871998346915364885690608319789548768240329539892824164824450189455326364637058384897450650604396402325991982494396394138247340541863253124681725928730913425858701499710484128656813377363902464 4334599931694136604301677930401346012498051431015111454350489173723530988538463980162984378628287299837474585218883954478713889977893402273463916375644700618769407807252756827911903789932756729658968086502359035934545524604402060007290784747741428186382373809536630784 52015199180329639251620135164816152149976617172181337452205870084682371862461567761955812543539447598049695022626607453744566679734720827281566996507736407425232893687033081934942845479193080755907617038028308431084410029707793978328904947535498439790130203487870386176 624182390163955671019441621977793825799719406066176049426470441016188462349538813143469750522473371176596340271519289444934800156816649927378803958092836889102794724244396983219314145750316969070891404456339701173002075667698108511466977331306198052611024251668897202176 7490188681967468052233299463733525909596632872794112593117645292194261548194465757721637006269680454119156083258231473339217601881799799128545647497114042669233536690932763798631769749003803628850696853476076414076024004288311017201897071139081061362593079504177970806784 89882264183609616626799593564802310915159594473529351117411743506331138578333589092659644075236165449429872999098777680070611222581597589542547769965368512030802440291193165583581236988045643546208362241712916968912287976149393349344789298932589960078722019757148250046464 1078587170203315399521595122777627730981915133682352213408940922075973662940003069111915728902833985393158475989185332160847334670979171074510573239584422144369629283494317987002974843856547722554500346900555003626947455707516858620714306957629714289588631325894696717254656 12943046042439784794259141473331532771782981604188226560907291064911683955280036829342988746834007824717901711870223985930168016051750052894126878875013065732435551401931815844035698126278572670654004162806660043523369468489679314984286419772426457705783906501470437083447296 155316552509277417531109697679978393261395779250258718730887492778940207463360441952115864962008093896614820542442687831162016192621000634729522546500156788789226616823181790128428377515342872047848049953679920522280433621876108197439413265292523316321966905566873084707733504 1863798630111329010373316372159740719136749351003104624770649913347282489560325303425390379544097126759377846509312253973944194311452007616754270558001881465470719401878181481541140530184114464574176599444159046267365203462513294737408623869178896947851316202431579336468332544 22365583561335948124479796465916888629640992212037255497247798960167389874723903641104684554529165521112534158111747047687330331737424091401051246696022577585648632822538177778493686362209373574890119193329908555208382441550159536546248125153952481470214770540481377230951284736 268387002736031377493757557591002663555691906544447065966973587522008678496686843693256214654349986253350409897340964572247963980849089096812614960352270931027783593870458133341924236346512482898681430319958902662500589298601914438529756221741080254150577161161718395537526358016 3220644032832376529925090691092031962668302878533364791603683050264104141960242124319074575852199835040204918768091574866975567770189069161751379524227251172333403126445497600103090836158149794784177163839506831950007071583222973262354972887550767256182592593496949235514158874624 38647728393988518359101088293104383552019634542400377499244196603169249703522905491828894910226398020482459025217098898403706813242268829941016554290727014068000837517345971201237090033897797537410125966074081983400084858998675679148259499502830690758055750010259751533591893377024 463772740727862220309213059517252602624235614508804529990930359238030996442274865901946738922716776245789508302605186780844481758907225959292198651488724168816010050208151654414845080406773570448921511592888983800801018307984108149779113979438320079403657720030475048462054552764416 5565272888734346643710556714207031231490827374105654359891164310856371957307298390823360867072601314949474099631262241370133781106886711511506383817864690025792120602497819852978140964881282845387058139114667805609612219695809297797349367752043536935369475033691313750716233952526336 66783274664812159724526680570484374777889928489267852318693971730276463487687580689880330404871215779393689195575146896441605373282640538138076605814376280309505447229973838235737691578575394144644697669376013667315346636349711573568192413024421084556310832270406232772692439040262144 801399295977745916694320166845812497334679141871214227824327660763317561852250968278563964858454589352724270346901762757299264479391686457656919269772515363714065366759686058828852298942904729735736372032512164007784159636196538882818308956293044568120053081567050665585984071117307904 9616791551732951000331842002149749968016149702454570733891931929159810742227011619342767578301455072232691244162821153087591173752700237491883031237270184364568784401116232705946227587314856756828836464390145968093409915634358466593819707475516534113560997236664789309724615086960541696 115401498620795412003982104025796999616193796429454848806703183149917728906724139432113210939617460866792294929953853837051094085032402849902596374847242212374825412813394792471354731047778281081946037572681751617120918987612301599125836489706198409304075330194799153493586448229655904256 1384817983449544944047785248309563995394325557153458185680438197799012746880689673185358531275409530401507539159446246044613129020388834198831156498166906548497904953760737509656256772573339372983352450872181019405451027851347619189510037876474380911644015909283824982071111634354714968064 16617815801394539328573422979714767944731906685841498228165258373588152962568276078224302375304914364818090469913354952535357548244666010385973877978002878581974859445128850115875081270880072475800229410466172232865412334216171430274120454517692570939727783573651419379865679133556483293184 199413789616734471942881075756577215336782880230097978737983100483057835550819312938691628503658972377817085638960259430424290578935992124631686535736034542983698313341546201390500975250560869709602752925594066794384948010594057163289445454212310851276733368939004159191305844562786124824576 2392965475400813663314572909078926584041394562761175744855797205796694026609831755264299542043907668533805027667523113165091486947231905495580238428832414515804379760098554416686011703006730436515233035107128801532619376127128685959473345450547730215320800424439315504181746609333442525003776 28715585704809763959774874908947119008496734753134108938269566469560328319317981063171594504526892022405660332010277357981097843366782865946962861145988974189652557121182653000232140436080765238182796421285545618391432513525544231513680145406572762583849605093036058183004799018216311052304384 344587028457717167517298498907365428101960817037609307259234797634723939831815772758059134054322704268867923984123328295773174120401394391363554333751867690275830685454191836002785685232969182858193557055426547420697190162306530778164161744878873151006195261116413054207126241527446982690340864 4135044341492606010207581986888385137223529804451311687110817571616687277981789273096709608651872451226415087809479939549278089444816732696362652005022412283309968225450302032033428222795630194298322684665118569048366281947678369337969940938546477812074343133396955013486437286105101396455981056 49620532097911272122490983842660621646682357653415740245329810859400247335781471277160515303822469414716981053713759274591337073337800792356351824060268947399719618705403624384401138673547562331579872215981422828580395383372140432055639291262557733744892117600763460025420657632242528224486096896 595446385174935265469891806111927459760188291840988882943957730312802968029377655325926183645869632976603772644565111295096044880053609508276221888723227368796635424464843492612813664082570747978958466591777073942964744600465685184667671495150692804938705411209161520293679842436825447982751023104 7145356622099223185638701673343129517122259502091866595327492763753635616352531863911114203750435595719245271734781335541152538560643314099314662664678728425559625093578121911353763968990848975747501599101324887315576935205588222216012057941808313659264464934509938243523210771812731634900422098944 85744279465190678227664420080117554205467114025102399143929913165043627396230382366933370445005227148630943260817376026493830462727719769191775951976144741106715501122937462936245167627890187708970019189215898647786923222467058666592144695301699763911173579214119258922278450316967015140397349339136 1028931353582288138731973040961410650465605368301228789727158957980523528754764588403200445340062725783571319129808512317925965552732637230301311423713736893280586013475249555234942011534682252507640230270590783773443078669604703999105736343620397166934082950569431107067341397224872034644900882415616 12347176242987457664783676491536927805587264419614745476725907495766282345057175060838405344080752709402855829557702147815111586632791646763615737084564842719367032161702994662819304138416187030091682763247089405281316944035256447989268836123444766003208995406833173284808096766150236736818821646516224 148166114915849491977404117898443133667047173035376945720710889949195388140686100730060864128969032512834269954692425773781339039593499761163388845014778112632404385940435935953831649660994244361100193158965072863375803328423077375871226033481337192038507944881998079417697161193757155201915860679655424 1777993378990193903728849414781317604004566076424523348648530679390344657688233208760730369547628390154011239456309109285376068475121997133960666140177337351588852631285231231445979795931930932333202317907580874360509639941076928510454712401776046304462095338583976953012365934325082055286331161565986816 21335920547882326844746192977375811248054792917094280183782368152684135892258798505128764434571540681848134873475709311424512821701463965607527993682128048219066231575422774777351757551183171187998427814890970492326115679292923142125456548821312555653545144063007723436148391211900984346174585674909351936 256031046574587922136954315728509734976657515005131362205388417832209630707105582061545173214858488182177618481708511737094153860417567587290335924185536578628794778905073297328221090614198054255981133778691645907913388151515077705505478585855750667842541728756092681233780694542811812127656579076922015744 3072372558895055065643451788742116819719890180061576346464661013986515568485266984738542078578301858186131421780502140845129846325010811047484031090226438943545537346860879567938653087370376651071773605344299750894960657818180932466065743030269008014110500745073112174805368334513741745529675744837898338304 36868470706740660787721421464905401836638682160738916157575932167838186821823203816862504942939622298233577061366025690141558155900129732569808373082717267322546448162330554815263837048444519812861283264131597010739527893818171189592788916363228096169326008940877346097664420014164900946355925337714349572096 442421648480887929452657057578864822039664185928866993890911186014058241861878445802350059315275467578802924736392308281698697870801556790837700476992607207870557377947966657783166044581334237754335399169579164128874334725818054275113466996358737154031912107290528153171973040169978811356271088752543825657856 5309059781770655153431884690946377864475970231146403926690934232168698902342541349628200711783305610945635096836707699380384374449618681490052405723911286494446688535375599893397992534976010853052024790034949969546492016709816651301361603956304845848382945287486337838063676482039745736275253063755523543793664 63708717381247861841182616291356534373711642773756847120291210786024386828110496195538408541399667331347621162040492392564612493395424177880628868686935437933360262424507198720775910419712130236624297480419399634557904200517799815616339247475658150180595343449836054056764117784476948835303036764960032328515584 764504608574974342094191395496278412484539713285082165443494529432292641937325954346460902496796007976171453944485908710775349920745090134567546424243225255200323149094086384649310925036545562839491569765032795614694850406213597787396070969707897802167144121398032648681169413413723386023636441179511533759102976 9174055302899692105130296745955340949814476559420985985321934353187511703247911452157530829961552095714057447333830904529304199048941081614810557090918703062403877789129036615791731100438546754073898837180393547376338204874563173448752851636494773626005729456776391784174032960964680632283637294154137667260645376 110088663634796305261563560951464091397773718713051831823863212238250140438974937425890369959538625148568689368005970854351650388587292979377726685091024436748846533469548439389500773205262561048886786046164722568516058458494758081385034219637937283512068753481316701410088395531576167587403647529849651945640361984 1321063963617555663138762731417569096773284624556621981886358546859001685267699249110684439514463501782824272416071650252219804663047515752532720221092293240986158401634581272674009278463150732586641432553976670822192701501937096976620410635655247402144825041775800416921060746378914011048843770358195823342560395264 15852767563410667957665152777010829161279415494679463782636302562308020223212390989328213274173562021393891268992859803026637655956570189030392642653107518891833900819614975272088111341557808791039697190647720049866312418023245163719444927627862968825737900501309605003052728956546968132586125244298349880110297747456 190233210760928015491981833324129949935352985936153565391635630747696242678548691871938559290082744256726695227914317636319651871478842268364711711837290226702006809835379703265057336098693705492476366287772640598395749016278941964633339131534355625908854806015715260036632747478563617591033502931580198561323537386496 2282798529131136185903781999889559399224235831233842784699627568972354912142584302463262711480992931080720342734971811635835822457746107220376540542047482720424081718024556439180688033184324465909716395453271687180748988195347303575600069578412267510906257672188583120439592969742763411092402035178962382735882445672704 27393582349573634230845383998674712790690829974806113416395530827668258945711011629559152537771915172968644112819661739630029869492953286644518486504569792645088980616294677270168256398211893590916596745439260246168987858344167642907200834940947210130875092066262997445275115636913160933108824422147548592830589347825344 328722988194883610770144607984096553488289959697673360996746369932019107348532139554709830453262982075623729353835940875560358433915439439734221838054837511741067767395536127242019076778542723090999160945271122954027854300130011714886410019291366521570501104795155969343301387642957931197305893065770583113967072173883536 3944675858338603329241735295809158641859479516372080331960956439184229288182385674656517965439155784907484752246031290506724301206985273276810662056658050140892813208746433526904228921342512677091989931343253475448334251601560140578636920231496398258846013257541871632119616651715495174367670716789246997367604866086600716 47336110300063239950900823549709903702313754196464963983531477270210751458188628095878215585269869418889817026952375486080691614483823279321727944679896601690713758504957202322850747056110152125103879176119041705380011019218721686943643042777956779106152159090502459585435399820585942092412048601470963968411258393039208449\n"}, {"input": "685881690392905117434431489495385586127448264303076182128024256632771944880513797413380560779272522395272914057841494739399255775297713137770656031977268970189240419718422549044382776867564731096274305671116280037388\r\n", "output": "YES\n1\n202\n100\n10766336687861891533593095067445790474209596554100627661034624233342313951291575899491013682859154252012453888 119326898290469297830656803664190844422489695141281956576467085252877312960148299552692068318355626293138030592 1431100350988642123920176615874860246297540886403056347637942655905591884317167043695538145163937996790072082432 17173135676155623032871477304823703798339462682228982244048673340273024622538953478435060519079228501586899632128 206077622402558469523276840817411560650304299857197145767950193539060122304695187487394776460376739730718298472448 2472931468354759217040057015905565987392837493925569862452016165256703453225861228660918488377139709911259206909952 29675177620217448736377412101374844120346482085076772025527245136646106604174461325498703624763394755030330451689472 356102131442606079680853672542373800466793821034085425446002195902550418013882213121115083644180546913371900417671168 4273225577311272680740604464452308578186745522076788785446999288685838111063568947221308557075751547114880132928503808 51278706927735272145934783606256354852623047904060445732038572542384660090670909232469696647687817314058096372468416512 615344483132823265749304697444478645891008416651986930476685752265128804651209917611787525935818707664420451034398195712 7384133797593879188991496977181193949663728653307448297527914267327921729444782261909962908410121566964355686959843115008 88609605571126550267897950443494948245879046144146346664652278311280592092806575747133597617353150226488210766397039443968 1063315266853518603214775404215049430688041412255127573900353781993979232725301341349287674967940443669768191073671050166272 12759783202242223238577304850488352339234621351938645171297955920782635136671251298890092474911927210783210764707128150065152 153117398426906678862927658205852541335063633257003501579283280260796195335385651853572663063551180019960695215804127429787648 1837408781122880146355131898470229855459450947170186998911708347230504725165905375265112919542998164697075189759592744959868928 22048905373474561756261582781642758212133301978382756068603859248774469233752637632599875114747676643403031181045941540835295232 264586864481694741075138993379713098541151281291621448830051590908794331849345132685316711383658094609756218247878867540133281792 3175042373780336892901667920556557182493444680295376417294519530899157040612501048981643720771120966557817939314157041235775193088 38100508485364042714820015046678686189921305272277510260145392740789353242218375875842878247934053584630543881798185380725483634688 457206101824368512577840180560144234279055660693057872559462309420305527969526207450786468441765359847727920632413916309197152059392 5486473221892422150934082166721730811348667928102171783166690846087902443056223297487826948756730711242081830426536636688740103749632 65837678662709065811208986000660769736184015137208184507371385414141848992293171970527122495702064067660760863688237110346412434915328 790052143952508789734507832007929236834208181646496724347570882908126106213819604679714903207643210106325445272472995113330410151477248 9480625727430105476814093984095150842010498179757960568025776783059048601091360384576027957929986724717105036178693787175729376895434752 113767508729161265721769127809141810104125978157095526805963898579055377823640118375613956255113029713558693741886743599926732894001692672 1365210104749935188661229533709701721249511737885146321670704664380526766767893403320759276791352455647450444344952791378605626425625018368 16382521256999222263934754404516420654994140854621755860048384129352309720621738505083560638307062476026467508759626152224891253082300612608 196590255083990667167217052854197047859929690255461070320580603565293215690744780199772265102752319129672365286500529881338830348318840717312 2359083061007888006006604634250364574319156283065532843846967242284607379875877688908831309353283460340847946369788443247285975455770358054912 28308996732094656072079255611004374891829875396786394126163606907373712624476110627448606056249422826655573653348443159356700039742239652446208 339707960785135872864951067332052498701958504761436729513963282888481086832543792392761825203660575695080667031590566398979506171429625442336768 4076495529421630474379412807984629984423502057137240754167559394661772753268761380785090115154649200155569152978370900828312332865032401109123072 48917946353059565692552953695815559813082024685646889050010712735941273015164989558760410399581683926184713264790391151943127849281045221292900352 587015356236714788310635444349786717756984296227762668600128552831295276179974862454236535546457364907909716129905522185151149179280930689513422848 7044184274840577459727625332197440613083811554733152023201542633975543314159531265096597727453444808711057689971568001918633258067030200610327625728 84530211298086929516731503986369287357005738656797824278418511607706519769914361257462986004516000740350704037693207834331667385797333993351945388032 1014362535577043154200778047836431448284068863881573891341022139292478237238972333929247816493781564137193282765488026662922347653650755552392345812992 12172350426924517850409336574037177379408826366578886696092265671509738846867668007054281463295344565917401462711953781009313366762482628931388899852288 146068205123094214204912038888446128552905916398946640353107188058116866162412016084643319864991631940698074391670620160532947500726347677368556860735488 1752818461477130570458944466661353542634870996787359684237286256697402393948944193015719166905353541384184330769974706492097135600347551805938673167368192 21033821537725566845507333599936242511618451961448316210847435080368828727387330316188629946908030326451529255745523749952307441003473236644390410578296832 252405858452706802146088003199234910139421423537379794530169220964425944728647963794263559358233346236571794176155103938764951109858287390980445454653718528 3028870301432481625753056038390818921673057082448557534362030651573111336743775565531162712298411570032124317039461982176790851803117499404369325499820802048 36346443617189779509036672460689827060076684989382690412344367818877336040925306786373952547580906458318263703384010514030791174844478163745148904334847639552 436157323406277354108440069528277924720920219872592284948132413826528032491103681436487430570970874801313562098850665062361935844234326979182846601879588175872 5233887880875328249301280834339335096651042638471107419377588965918336389893244177237849166851650497390887278324394858989509266942986972834714247535043509485568 62806654570503938991615370012072021159812511661653289032531067591020036678718930126854190002219805968671907717654253881060875039716858261440280977779896151441408 753679854846047267899384440144864253917750139939839468390372811092240440144627161522250280026637671624061330976664506203829397462969050352902014233972034987098112 9044158258152567214792613281738371047013001679278073620684473733106885281735525938267003360319652059488735841583708529415211010971159166836125724349382193275994112 108529899097830806577511359380860452564156020151336883448213684797282623380826311259204040323835824713864830088159813557563303651771870882250283821654396133764497408 1302358789173969678930136312570325430769872241816042601378564217567391480569915735110448483886029896566377961057014038624474708114605613993688137120641237756378349568 15628305470087636147161635750843905169238466901792511216542770610808697766838988821325381806632358758796535532684093153154839419399712631541481373052760560089140559872 187539665641051633765939629010126862030861602821510134598513247329704373202067865855904581679588305105558426392209111561996501609631922017132545120600215529987403415552 2250475987692619605191275548121522344370339233858121615182158967956452478424814390270854980155059661266701116706509338220969555030319345075476772167533177093925317378048 27005711852311435262295306577458268132444070806297459382185907615477429741097772683250259761860715935200413400478112058608052288340060164311545118570425674354943514902528 324068542227737223147543678929499217589328849675569512586230891385729156893173272199003117142328591222404960805737344703292995595745407640355693410558443721361642154360832 3888822506732846677770524147153990611071946196106834151034770696628749882718079266388037405707943094668859529668848136439515644493583615489986416925677435958764899183624192 46665870080794160133246289765847887332863354353282009812417248359544998592616951196656448868495317136026314356026177637274187708701723279530313511108043907447047556314431488 559990440969529921598955477190174647994360252239384117749006980314539983111403414359877386421943805632315772272314131647290252502318906012167968508963186445693059739615756288 6719885291634359059187465726282095775932323026872609412988083763774479797336840972318528637063325667587789267267769579767483030027651724367499305972197125644677424297375956992 80638623499612308710249588715385149311187876322471312955857005165293757568042091667822343644759908011053471207213234957209796360331806096761781978655085415094159150520343724032 967663481995347704522995064584621791734254515869655755470284061983525090816505100013868123737118896132641654486558819486517556323981671944837366269443418306743078977823444041728 11611961783944172454275940775015461500811054190435869065643408743802301089798061200166417484845426753591699853838705833838210675887780063236689727110452885791384711831512938446848 139343541407330069451311289300185538009732650285230428787720904925627613077576734401997009818145121043100398246064470006058528110653360758831830169648528951672488855652957895524352 1672122496887960833415735471602226456116791803422765145452650859107531356930920812823964117817741452517204778952773640072702337327840329105981258156142605280251188960641728299139072 20065469962655530000988825659226717473401501641073181745431810309290376283171049753887569413812897430206457347433283680872428047934083949271775039217074618184696044418767925719072768 240785639551866360011865907910720609680818019692878180945181723711484515398052597046650832965754769162477488169199404170469136575209007391261300465716842364451492681099470707472990208 2889427674622396320142390894928647316169816236314538171342180684537814184776631164559809995589057229949729858030392850045629638902508088695135605588194770618937507185533169789579558912 34673132095468755841708690739143767794037794835774458056106168214453770217319573974717719947068686759396758296364714200547555666830097064341627267058303302614376719144092997583280013312 416077585145625070100504288869725213528453538029293496673274018573445242607834887696612639364824241112761099556376570406570668001961164772099527204699636802638114515805590551008387268608 4992931021747500841206051466436702562341442456351521960079288222881342911294018652359351672377890893353133194676518844878848016023533977265194326456395641395929507013506792827101399482368 59915172260970010094472617597240430748097309476218263520951458674576114935528223828312220068534690720237598336118226138546176192282407727182331917476747696731510095230734822776466856476672 718982067131640121133671411166885168977167713714619162251417504094913379226338685939746640822416288642851180033418713662554114307388892726187983009720972360776484143691205649055206449610752 8627784805579681453604056934002622027726012564575429947017010049138960550716064231276959689868995463714214160401024563950649371688666712714255796116651668329317673307704666769973944409653248 103533417666956177443248683208031464332712150774905159364204120589667526608592770775323516278427945564570569924812294767407792460264000552571069553399820019951812068324406851154796621833699328 1242401012003474129318984198496377571992545809298861912370449447076010319303113249303882195341135346774846839097747537208893509523168006630852834640797840239421744818945544784683818569414213632 14908812144041689551827810381956530863910549711586342948445393364912123831637358991646586344093624161298162069172970446506722114278016079570234015689574082873060937827267592630441344425254715392 178905745728500274621933724583478370366926596539036115381344720378945485979648307899759036129123489935577944830075645358080665371336192954842808188274888994476731253927204532833149093235746930688 2146868948742003295463204695001740444403119158468433384576136644547345831755779694797108433549481879226935337960907744296967984456034315458113698259298667933720775047126453845770110198840020697088 25762427384904039545558456340020885332837429901621200614913639734568149981069356337565301202593782550723224055530892931563615813472411785497364379111584015204649300565517446103555682476081169825792 309149128618848474546701476080250623994049158819454407378963676814817799772832276050783614431125390608678688666370715178763389761668941425968372549339008182455791606786209353238861053053807448031232 3709789543426181694560417712963007487928589905833452888547564121777813597273987312609403373173504687304144263996448582145160677140027297111620470592068098189469499281434512238866015375257425493884928 44517474521114180334725012555556089855143078870001434662570769461333763167287847751312840478082056247649731167957382985741928125680327565339445647104817178273633991377214146866392158064640083936411648 534209694253370164016700150666673078261716946440017215950849233536005158007454173015754085736984674971796774015488595828903137508163930784073347765257806139283607896526569762396705894572476922071089152 6410516331040441968200401808000076939140603357280206591410190802432061896089450076189049028843816099661561288185863149946837650097967169408880173183093673671403294758318837148760470734686122724422582272 76926195972485303618404821696000923269687240287362479096922289629184742753073400914268588346125793195938735458230357799362051801175606032906562078197124084056839537099826045785125648816218172664701779968 923114351669823643420857860352011079236246883448349749163067475550216913036880810971223060153509518351264825498764293592344621614107272394878744938365489008682074445197912549421507785794616796974057259008 11077372220037883721050294324224132950834962601380196989956809706602602956442569731654676721842114220215177905985171523108135459369287268738544939260385868104184893342374950593058093429535401457438490099712 132928466640454604652603531890689595410019551216562363879481716479231235477310836779856120662105370642582134871822058277297625512431447224862539271124630417250218720108499407116697121154424817480407698112512 1595141599685455255831242382688275144920234614598748366553780597750774825727730041358273447945264447710985618461864699327571506149177366698350471253495565007002624641301992885400365453853097809764154528759808 19141699196225463069974908592259301739042815375184980398645367173009297908732760496299281375343173372531827421542376391930858073790128400380205655041946780084031495695623914624804385446237173717169792857735168 229700390354705556839698903107111620868513784502219764783744406076111574904793125955591376504118080470381929058508516703170296885481540804562467860503361361008377948347486975497652625354846084606037509168873472 2756404684256466682076386837285339450422165414026637177404932872913338898857517511467096518049416965644583148702102200438043562625778489654749614326040336332100535380169843705971831504258153015272450109599485952 33076856211077600184916642047424073405065984968319646128859194474960066786290210137605158216593003587734997784425226405256522751509341875856995371912484035985206424562038124471661978051097836183269401315158248448 396922274532931202218999704569088880860791819619835753546310333699520801435482521651261898599116043052819973413102716863078273018112102510283944462949808431822477094744457493659943736613174034199232815781896016128 4763067294395174426627996454829066570329501835438029042555724004394249617225790259815142783189392516633839680957232602356939276217345230123407333555397701181869725136933489923919324839358088410390793789382751946432 57156807532742093119535957457948798843954022025256348510668688052730995406709483117781713398272710199606076171486791228283271314608142761480888002664772414182436701643201879087031898072297060924689525472593023336592 8230580284714861409213177873944627033529379171636914185536291079593263338566165568960566729351270268743274968694097936872791069303572557653247872383727227642270885036621070588532593322410776773155291668053395360448513\n"}, {"input": "25\r\n", "output": "NO\r\n"}, {"input": "79360359146807441660707083821018832188095237636414144034857851003419752010124705615779249215657075053438039921073878645370211154334804568157886814559909\r\n", "output": "NO\r\n"}, {"input": "63730052926382178992698271572\r\n", "output": "NO\r\n"}, {"input": "781127467969689863953686682245136076127159921705034542049372816247984349746396880068864077830521695515007722284098436125466526268962707778595903329840419133974864831578401355678018910046595664462\r\n", "output": "NO\r\n"}, {"input": "6158324958633591462725987806787114657822761584945953440793358408\r\n", "output": "NO\r\n"}, {"input": "46865942276811740149949176718949673344632458696505595472917789224885825949034661409971763949176343056701403524645790892802371117466746709730235969308113002256137529699677021858777002204698794034488631496662175642982367736619451227\r\n", "output": "NO\r\n"}, {"input": "30237645054497458443810364460387991000047179363449854478913094584184671326397148735574822623728870964468880\r\n", "output": "NO\r\n"}, {"input": "188808426143782131983811729737047667239979348184409855460833141044812532916921011366813880911319644625405122800255947507577498497005580408229\r\n", "output": "NO\r\n"}, {"input": "11\r\n", "output": "NO\r\n"}, {"input": "837952166310387766556098005402621146120844433859027080340550200820\r\n", "output": "NO\r\n"}, {"input": "6658370691480968202384509492140362150472696196949673577340706113760133821635599667476781507918250717914609488172442814676\r\n", "output": "NO\r\n"}, {"input": "496620932866717074931903995027173085744596193421095444317407919730992986418713478580824584919587030125446806223296721174921873955469939680411818878465888018986191990428049489376\r\n", "output": "NO\r\n"}, {"input": "1055050055824280186133547527395898666709023463559337207019374080060005629519967890329878081184599905695126755199503698703340223998620951421943134090897041663457029971964336512111472968057533187306110300592753045593222495258017559167383354672\r\n", "output": "NO\r\n"}, {"input": "833488\r\n", "output": "NO\r\n"}, {"input": "6623739799588591251984406341341227075747347067457011846886851179047097\r\n", "output": "NO\r\n"}, {"input": "491137842784568289872893698937459777201151060689848471272003426250808340375567208957554901863756992593841404624991936090178731\r\n", "output": "NO\r\n"}, {"input": "921020945402270233565256424740666649108666245414796768645533036514715926608741510409618545180420952947917462937925573726593991655435868735899832746218676826629010574075553051352459309199055\r\n", "output": "NO\r\n"}, {"input": "73010581613999159726778758153209240813500342925961695523976131595080552126499402124287397930918281238199343324378719343080627189983992629778313739785259010389762036264197722427990331444297391895841265448905560880286941336214995793596526089977876\r\n", "output": "NO\r\n"}, {"input": "20046142930690780976270827075270\r\n", "output": "NO\r\n"}, {"input": "9685166910821197056344900917707673568669808490600751439157007968027004377622601634787545920946543261243701428886581331490848676434786296227674864970612484770201\r\n", "output": "NO\r\n"}, {"input": "4805043123239964766764344326469867688727869311599746349016084457204677169811854267718990063526979167327981002200329174783850464\r\n", "output": "NO\r\n"}, {"input": "2376595620091080825479292544658464163405755746884100218035485700973409491416884420742631899446144679322008453313773241425622490028383089317622842863337164723765526589656211098933400307364163919083790470365474085981340438888606855706394352678991102\r\n", "output": "NO\r\n"}, {"input": "145\r\n", "output": "YES\r\n1\r\n3\r\n1\r\n24\r\n"}, {"input": "24\r\n", "output": "YES\r\n1\r\n3\r\n1\r\n145\r\n"}]
| false |
stdio
| null | true |
197/B
|
197
|
B
|
Python 3
|
TESTS
| 10 | 248 | 921,600 |
39260593
|
""" *** Author--Saket Saumya ***
IIITM
"""
import math
import os
import random
import re
import sys
from collections import Counter
from itertools import permutations
sys.setrecursionlimit(3000)
def si():
return str(input())
def ii():
return int(input())
def mi():
return map(int, input().split())
def li():
return list(mi())
def debug(x):
return print(x)
n,m=mi()
a=li()
b=li()
if (n>m):
if (a[0]/b[0])>0:
print('Infinity')
else:
print('-Infinity')
if (n<m):
print('0/1')
if (n==m):
g=math.gcd(a[0],b[0])
if (b[0]<0):
print('-'+str(a[0]//g)+'/'+str(-b[0]//g))
else:
print(str(a[0]//g)+'/'+str(b[0]//g))
| 80 | 124 | 0 |
187657210
|
import math
x,y = map(int,input().split())
a,b = int(input().split()[0]), int(input().split()[0])
if y > x:
print("0/1")
elif x > y:
print(("-" if (int(a < 0) + int(b < 0))%2 == 1 else "") + "Infinity")
else:
if (int(a < 0)+int(b < 0))%2 == 1:
a = -abs(a)
b = abs(b)
else:
a = abs(a)
b = abs(b)
print(str(a//math.gcd(a,b))+"/"+str(b//math.gcd(a,b)))
|
Codeforces Round 124 (Div. 2)
|
CF
| 2,012 | 2 | 256 |
Limit
|
You are given two polynomials:
- P(x) = a0·xn + a1·xn - 1 + ... + an - 1·x + an and
- Q(x) = b0·xm + b1·xm - 1 + ... + bm - 1·x + bm.
Calculate limit $$\lim_{x \to +\infty} \frac{P(x)}{Q(x)}$$.
|
The first line contains two space-separated integers n and m (0 ≤ n, m ≤ 100) — degrees of polynomials P(x) and Q(x) correspondingly.
The second line contains n + 1 space-separated integers — the factors of polynomial P(x): a0, a1, ..., an - 1, an ( - 100 ≤ ai ≤ 100, a0 ≠ 0).
The third line contains m + 1 space-separated integers — the factors of polynomial Q(x): b0, b1, ..., bm - 1, bm ( - 100 ≤ bi ≤ 100, b0 ≠ 0).
|
If the limit equals + ∞, print "Infinity" (without quotes). If the limit equals - ∞, print "-Infinity" (without the quotes).
If the value of the limit equals zero, print "0/1" (without the quotes).
Otherwise, print an irreducible fraction — the value of limit $$\lim_{x \to +\infty} \frac{P(x)}{Q(x)}$$, in the format "p/q" (without the quotes), where p is the — numerator, q (q > 0) is the denominator of the fraction.
| null |
Let's consider all samples:
1. $$\lim_{x \to +\infty} \frac{x^2+x+1}{2x+5} = +\infty$$
2. $$\lim_{x \to +\infty} \frac{-x+3}{2} = -\infty$$
3. $$\lim_{x \to +\infty} \frac{1}{x} = 0$$
4. $$\lim_{x \to +\infty} \frac{2x^2+x+6}{4x^2+5x-7} = \frac{1}{2}$$
5. $$\lim_{x \to +\infty} \frac{9x}{-5x+2} = -\frac{9}{5}$$
You can learn more about the definition and properties of limits if you follow the link: http://en.wikipedia.org/wiki/Limit_of_a_function
|
[{"input": "2 1\n1 1 1\n2 5", "output": "Infinity"}, {"input": "1 0\n-1 3\n2", "output": "-Infinity"}, {"input": "0 1\n1\n1 0", "output": "0/1"}, {"input": "2 2\n2 1 6\n4 5 -7", "output": "1/2"}, {"input": "1 1\n9 0\n-5 2", "output": "-9/5"}]
| 1,400 |
["math"]
| 80 |
[{"input": "2 1\r\n1 1 1\r\n2 5\r\n", "output": "Infinity\r\n"}, {"input": "1 0\r\n-1 3\r\n2\r\n", "output": "-Infinity\r\n"}, {"input": "0 1\r\n1\r\n1 0\r\n", "output": "0/1\r\n"}, {"input": "2 2\r\n2 1 6\r\n4 5 -7\r\n", "output": "1/2\n"}, {"input": "1 1\r\n9 0\r\n-5 2\r\n", "output": "-9/5\n"}, {"input": "1 2\r\n5 3\r\n-3 2 -1\r\n", "output": "0/1\r\n"}, {"input": "1 2\r\n-4 8\r\n-2 5 -3\r\n", "output": "0/1\r\n"}, {"input": "3 2\r\n4 3 1 2\r\n-5 7 0\r\n", "output": "-Infinity\r\n"}, {"input": "2 1\r\n-3 5 1\r\n-8 0\r\n", "output": "Infinity\r\n"}, {"input": "1 1\r\n-5 7\r\n3 1\r\n", "output": "-5/3\n"}, {"input": "2 2\r\n-4 2 1\r\n-5 8 -19\r\n", "output": "4/5\n"}, {"input": "0 0\r\n36\r\n-54\r\n", "output": "-2/3\n"}, {"input": "0 0\r\n36\r\n-8\r\n", "output": "-9/2\n"}, {"input": "0 0\r\n-6\r\n-8\r\n", "output": "3/4\n"}, {"input": "0 2\r\n-3\r\n1 4 6\r\n", "output": "0/1\r\n"}, {"input": "0 0\r\n-21\r\n13\r\n", "output": "-21/13\n"}, {"input": "0 0\r\n-34\r\n21\r\n", "output": "-34/21\n"}, {"input": "0 0\r\n-55\r\n34\r\n", "output": "-55/34\n"}, {"input": "33 1\r\n-75 -83 87 -27 -48 47 -90 -84 -18 -4 14 -1 -83 -98 -68 -85 -86 28 2 45 96 -59 86 -25 -2 -64 -92 65 69 72 72 -58 -99 90\r\n-1 72\r\n", "output": "Infinity\r\n"}, {"input": "20 20\r\n5 4 91 -66 -57 55 -79 -2 -54 -72 -49 21 -23 -5 57 -48 70 -16 -86 -26 -19\r\n51 -60 64 -8 89 27 -96 4 95 -24 -2 -27 -41 -14 -88 -19 24 68 -31 34 -62\r\n", "output": "5/51\n"}, {"input": "0 0\r\n46\r\n-33\r\n", "output": "-46/33\n"}, {"input": "17 17\r\n-54 59 -95 87 3 -27 -30 49 -87 74 45 78 36 60 -95 41 -53 -70\r\n-27 16 -67 -24 10 -73 -41 12 -52 53 -73 -17 -56 -74 -33 -8 100 -39\r\n", "output": "2/1\n"}, {"input": "1 1\r\n36 -49\r\n-32 -40\r\n", "output": "-9/8\n"}, {"input": "1 1\r\n1 1\r\n1 1\r\n", "output": "1/1\n"}, {"input": "1 1\r\n-2 1\r\n4 1\r\n", "output": "-1/2\n"}, {"input": "0 0\r\n2\r\n1\r\n", "output": "2/1\n"}, {"input": "0 0\r\n4\r\n-3\r\n", "output": "-4/3\n"}, {"input": "0 0\r\n2\r\n2\r\n", "output": "1/1\n"}, {"input": "0 0\r\n17\r\n-10\r\n", "output": "-17/10\n"}, {"input": "0 0\r\n-1\r\n2\r\n", "output": "-1/2\n"}, {"input": "0 0\r\n1\r\n1\r\n", "output": "1/1\n"}, {"input": "0 0\r\n50\r\n20\r\n", "output": "5/2\n"}, {"input": "0 0\r\n20\r\n20\r\n", "output": "1/1\n"}, {"input": "0 0\r\n4\r\n-2\r\n", "output": "-2/1\n"}, {"input": "0 0\r\n4\r\n-6\r\n", "output": "-2/3\n"}, {"input": "0 0\r\n1\r\n-2\r\n", "output": "-1/2\n"}, {"input": "0 0\r\n4\r\n2\r\n", "output": "2/1\n"}, {"input": "0 0\r\n2\r\n-4\r\n", "output": "-1/2\n"}, {"input": "1 1\r\n4 1\r\n2 1\r\n", "output": "2/1\n"}, {"input": "2 2\r\n-13 1 3\r\n6 3 2\r\n", "output": "-13/6\n"}, {"input": "0 0\r\n5\r\n5\r\n", "output": "1/1\n"}, {"input": "0 0\r\n2\r\n-1\r\n", "output": "-2/1\n"}]
| false |
stdio
| null | true |
584/C
|
584
|
C
|
PyPy 3-64
|
TESTS
| 10 | 77 | 2,867,200 |
194545529
|
from string import ascii_lowercase
n, t = list(map(int, input().split()))
s1 = input()
s2 = input()
cnt1, cnt2 = 0, 0
ans = []
i = 0
while cnt1 < n - t or cnt2 < n - t:
if i == n:
print(-1)
break
c1, c2 = s1[i], s2[i]
if c1 == c2:
cnt1 += 1
cnt2 += 1
ans.append(c1)
elif cnt1 <= cnt2:
cnt1 += 1
ans.append(c1)
else:
cnt2 += 1
ans.append(c2)
i += 1
else:
for j in range(i, n):
ch = next(iter(ch for ch in ascii_lowercase if ch != s1[j] and ch != s2[j]))
ans.append(ch)
print("".join(ans))
| 78 | 124 | 1,433,600 |
13458463
|
def f(s1, s2):
return sum(0 if ch1 == ch2 else 1 for ch1, ch2 in zip(s1, s2))
def choose_different(ch1, ch2):
if ch1 != 'a' and ch2 != 'a':
return 'a'
if ch1 != 'b' and ch2 != 'b':
return 'b'
return 'c'
def calc_s3(s1, s2, in_match, out_match):
l3 = []
in_match_taken = 0
out_match_taken_1 = 0
out_match_taken_2 = 0
for ch1, ch2 in zip(s1, s2):
if ch1 == ch2:
if in_match_taken < in_match:
ch3 = ch1
in_match_taken += 1
else:
ch3 = choose_different(ch1, ch2)
else:
if out_match_taken_1 < out_match:
ch3 = ch1
out_match_taken_1 += 1
elif out_match_taken_2 < out_match:
ch3 = ch2
out_match_taken_2 += 1
else:
ch3 = choose_different(ch1, ch2)
l3.append(ch3)
return ''.join(l3)
def main():
n, t = [int(t) for t in input().split()]
s1 = input()
s2 = input()
dif_12 = f(s1, s2)
match_12 = n - dif_12
highest_match = match_12 + dif_12 // 2
match_require = n - t
if match_require > highest_match:
print(-1)
return
if match_12 >= match_require:
in_match = match_require
out_match = 0
else:
in_match = match_12
out_match = match_require - match_12
s3 = calc_s3(s1, s2, in_match, out_match)
print(s3)
if __name__ == '__main__':
main()
|
Codeforces Round 324 (Div. 2)
|
CF
| 2,015 | 1 | 256 |
Marina and Vasya
|
Marina loves strings of the same length and Vasya loves when there is a third string, different from them in exactly t characters. Help Vasya find at least one such string.
More formally, you are given two strings s1, s2 of length n and number t. Let's denote as f(a, b) the number of characters in which strings a and b are different. Then your task will be to find any string s3 of length n, such that f(s1, s3) = f(s2, s3) = t. If there is no such string, print - 1.
|
The first line contains two integers n and t (1 ≤ n ≤ 105, 0 ≤ t ≤ n).
The second line contains string s1 of length n, consisting of lowercase English letters.
The third line contain string s2 of length n, consisting of lowercase English letters.
|
Print a string of length n, differing from string s1 and from s2 in exactly t characters. Your string should consist only from lowercase English letters. If such string doesn't exist, print -1.
| null | null |
[{"input": "3 2\nabc\nxyc", "output": "ayd"}, {"input": "1 0\nc\nb", "output": "-1"}]
| 1,700 |
["constructive algorithms", "greedy", "strings"]
| 78 |
[{"input": "3 2\r\nabc\r\nxyc\r\n", "output": "bac"}, {"input": "1 0\r\nc\r\nb\r\n", "output": "-1\r\n"}, {"input": "1 1\r\na\r\na\r\n", "output": "b"}, {"input": "2 1\r\naa\r\naa\r\n", "output": "ab"}, {"input": "3 1\r\nbcb\r\nbca\r\n", "output": "bcc"}, {"input": "4 3\r\nccbb\r\ncaab\r\n", "output": "cbca"}, {"input": "4 2\r\nacbc\r\nacba\r\n", "output": "acab"}, {"input": "4 1\r\nbcbc\r\nacab\r\n", "output": "-1\r\n"}, {"input": "4 2\r\nacbb\r\nbabc\r\n", "output": "aaba"}, {"input": "5 2\r\nabaac\r\nbbbaa\r\n", "output": "abbab"}, {"input": "5 2\r\nabbab\r\nacbab\r\n", "output": "aabaa"}, {"input": "5 3\r\nbcaaa\r\ncbacc\r\n", "output": "bbabb"}, {"input": "5 3\r\ncbacb\r\ncbacb\r\n", "output": "cbbaa"}, {"input": "5 1\r\ncbabb\r\nbabaa\r\n", "output": "-1\r\n"}, {"input": "1 0\r\na\r\na\r\n", "output": "a"}, {"input": "2 2\r\nbb\r\ncb\r\n", "output": "aa"}, {"input": "2 1\r\ncc\r\nba\r\n", "output": "ca"}, {"input": "2 0\r\nbb\r\nab\r\n", "output": "-1\r\n"}, {"input": "3 3\r\naac\r\nabc\r\n", "output": "bca"}, {"input": "1 1\r\na\r\nc\r\n", "output": "b"}, {"input": "3 0\r\ncba\r\ncca\r\n", "output": "-1\r\n"}, {"input": "2 1\r\niy\r\niy\r\n", "output": "ia"}, {"input": "2 2\r\nfg\r\nfn\r\n", "output": "aa"}, {"input": "2 1\r\npd\r\nke\r\n", "output": "pe"}, {"input": "3 3\r\nyva\r\nyvq\r\n", "output": "aab"}, {"input": "3 2\r\npxn\r\ngxn\r\n", "output": "axa"}, {"input": "3 1\r\nlos\r\nlns\r\n", "output": "las"}, {"input": "4 2\r\nhbnx\r\nhwmm\r\n", "output": "hbma"}, {"input": "4 4\r\nqtto\r\nqtto\r\n", "output": "aaaa"}, {"input": "4 3\r\nchqt\r\nchet\r\n", "output": "caaa"}, {"input": "5 3\r\nwzcre\r\nwzcrp\r\n", "output": "wzaaa"}, {"input": "5 1\r\nicahj\r\nxdvch\r\n", "output": "-1\r\n"}, {"input": "5 1\r\npmesm\r\npzeaq\r\n", "output": "-1\r\n"}, {"input": "7 4\r\nycgdbph\r\nfdtapch\r\n", "output": "yctaaah"}, {"input": "10 6\r\nrnsssbuiaq\r\npfsbsbuoay\r\n", "output": "aasasbuaba"}, {"input": "20 5\r\ndsjceiztjkrqgpqpnakr\r\nyijdvcjtjnougpqprrkr\r\n", "output": "-1\r\n"}, {"input": "100 85\r\njknccpmanwhxqnxivdgguahjcuyhdrazmbfwoptatlgytakxsfvdzzcsglhmswfxafxyregdbeiwpawrjgwcqrkbhmrfcscgoszf\r\nhknccpmanwhxjnxivdggeahjcuyhdrazmbfwoqtatlgytdkxsfvdztcsglhmssfxsfxyrngdbeiwpawrjgwcqrkbhmrfcsckoskf\r\n", "output": "aknccpmanwhxanxivaaaabaaaaaaaabaaaaaaaabaaaaabaaaaaaaaaaaaaaaaaabaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaa"}, {"input": "1 0\r\nz\r\nz\r\n", "output": "z"}, {"input": "1 1\r\nz\r\ny\r\n", "output": "a"}, {"input": "1 1\r\nz\r\nz\r\n", "output": "a"}, {"input": "1 0\r\nz\r\ny\r\n", "output": "-1\r\n"}, {"input": "10 1\r\ngjsywvenzc\r\nfssywvenzc\r\n", "output": "gssywvenzc"}, {"input": "20 2\r\nywpcwcwgkhdeonzbeamf\r\ngdcmwcwgkhdeonzbeamf\r\n", "output": "ywcmwcwgkhdeonzbeamf"}]
| false |
stdio
|
import sys
def hamming(s1, s2):
return sum(c1 != c2 for c1, c2 in zip(s1, s2))
def solution_exists(n, t, s1, s2):
a = sum(c1 == c2 for c1, c2 in zip(s1, s2))
d = n - a
min_k = max(d - t, 0)
max_k = min(d // 2, a + d - t)
return min_k <= max_k
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(input_path) as f:
n, t = map(int, f.readline().split())
s1 = f.readline().strip()
s2 = f.readline().strip()
with open(submission_path) as f:
submission = f.read().strip()
if submission == "-1":
exists = solution_exists(n, t, s1, s2)
print(0 if exists else 1)
return
else:
if len(submission) != n:
print(0)
return
if any(c < 'a' or c > 'z' for c in submission):
print(0)
return
h1 = hamming(s1, submission)
h2 = hamming(s2, submission)
if h1 == t and h2 == t:
print(1)
else:
print(0)
if __name__ == "__main__":
main()
| true |
442/B
|
442
|
B
|
PyPy 3
|
TESTS
| 17 | 124 | 0 |
31239197
|
def dp(N, P):
Mem = []
for n in range(N + 1):
Mem.append((0.0, 0.0))
Mem[N] = (1.0, 0.0);
for i in reversed(range(N)):
p = Mem[i + 1];
noHelp, oneHelp = p[0], p[1]
useI, result = noHelp*P[i] + oneHelp*(1 - P[i]), oneHelp
Mem[i] = p
if(result < P[i]):
result = P[i]
Mem[i] = (1 - P[i], P[i])
if(result < useI):
Mem[i] = (noHelp*(1 - P[i]), useI)
result = P[i];
return Mem[0]
if __name__ == '__main__':
N = int(input())
P = list(map(float, input().split()))
print(dp(N, P)[1]);
| 60 | 61 | 0 |
156238870
|
input()
a,b,c = 1,0,0
for p in sorted(map(float, input().split()))[::-1]:
b = a*p + b*(1-p)
a *= 1-p
c = max(c, b)
print(c)
|
Codeforces Round 253 (Div. 1)
|
CF
| 2,014 | 2 | 256 |
Andrey and Problem
|
Andrey needs one more problem to conduct a programming contest. He has n friends who are always willing to help. He can ask some of them to come up with a contest problem. Andrey knows one value for each of his fiends — the probability that this friend will come up with a problem if Andrey asks him.
Help Andrey choose people to ask. As he needs only one problem, Andrey is going to be really upset if no one comes up with a problem or if he gets more than one problem from his friends. You need to choose such a set of people that maximizes the chances of Andrey not getting upset.
|
The first line contains a single integer n (1 ≤ n ≤ 100) — the number of Andrey's friends. The second line contains n real numbers pi (0.0 ≤ pi ≤ 1.0) — the probability that the i-th friend can come up with a problem. The probabilities are given with at most 6 digits after decimal point.
|
Print a single real number — the probability that Andrey won't get upset at the optimal choice of friends. The answer will be considered valid if it differs from the correct one by at most 10 - 9.
| null |
In the first sample the best strategy for Andrey is to ask only one of his friends, the most reliable one.
In the second sample the best strategy for Andrey is to ask all of his friends to come up with a problem. Then the probability that he will get exactly one problem is 0.1·0.8 + 0.9·0.2 = 0.26.
|
[{"input": "4\n0.1 0.2 0.3 0.8", "output": "0.800000000000"}, {"input": "2\n0.1 0.2", "output": "0.260000000000"}]
| 1,800 |
["greedy", "math", "probabilities"]
| 60 |
[{"input": "4\r\n0.1 0.2 0.3 0.8\r\n", "output": "0.800000000000\r\n"}, {"input": "2\r\n0.1 0.2\r\n", "output": "0.260000000000\r\n"}, {"input": "1\r\n0.217266\r\n", "output": "0.217266000000\r\n"}, {"input": "2\r\n0.608183 0.375030\r\n", "output": "0.608183000000\r\n"}, {"input": "3\r\n0.388818 0.399762 0.393874\r\n", "output": "0.478724284024\r\n"}, {"input": "4\r\n0.801024 0.610878 0.808545 0.732504\r\n", "output": "0.808545000000\r\n"}, {"input": "5\r\n0.239482 0.686259 0.543226 0.764939 0.401318\r\n", "output": "0.764939000000\r\n"}, {"input": "6\r\n0.462434 0.775020 0.479749 0.373861 0.492031 0.746333\r\n", "output": "0.775020000000\r\n"}, {"input": "7\r\n0.745337 0.892271 0.792853 0.892917 0.768246 0.901623 0.815793\r\n", "output": "0.901623000000\r\n"}, {"input": "1\r\n0.057695\r\n", "output": "0.057695000000\r\n"}, {"input": "2\r\n0.057750 0.013591\r\n", "output": "0.069771239500\r\n"}, {"input": "3\r\n0.087234 0.075148 0.033833\r\n", "output": "0.172781711023\r\n"}, {"input": "4\r\n0.016717 0.061051 0.036222 0.096258\r\n", "output": "0.181832937456\r\n"}, {"input": "5\r\n0.057095 0.046954 0.054676 0.025927 0.080810\r\n", "output": "0.214634688963\r\n"}, {"input": "6\r\n0.010924 0.032857 0.021824 0.020356 0.007107 0.082489\r\n", "output": "0.154629381329\r\n"}, {"input": "7\r\n0.016061 0.043107 0.088973 0.014785 0.044298 0.028315 0.086014\r\n", "output": "0.246482855791\r\n"}, {"input": "100\r\n0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01\r\n", "output": "0.369729637650\r\n"}, {"input": "1\r\n1.0\r\n", "output": "1.000000000000\r\n"}, {"input": "3\r\n0.1 0.1 0.1\r\n", "output": "0.243000000000\r\n"}, {"input": "3\r\n0.2 0.2 0.2\r\n", "output": "0.384000000000\r\n"}, {"input": "5\r\n0.01 0.01 0.01 0.01 0.01\r\n", "output": "0.048029800500\r\n"}, {"input": "3\r\n1.0 1.0 0\r\n", "output": "1.000000000000\r\n"}, {"input": "3\r\n0.1 0.2 0.3\r\n", "output": "0.398000000000\r\n"}, {"input": "7\r\n0.1 0.1 0.1 0.1 0.1 0.1 0.1\r\n", "output": "0.372008700000\r\n"}, {"input": "5\r\n0.5 0.5 0.5 1 0.5\r\n", "output": "1.000000000000\r\n"}, {"input": "3\r\n0.4 0.2 0.4\r\n", "output": "0.480000000000\r\n"}, {"input": "10\r\n0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1\r\n", "output": "0.387420489000\r\n"}, {"input": "2\r\n1.0 1.0\r\n", "output": "1.000000000000\r\n"}, {"input": "10\r\n0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01\r\n", "output": "0.091351724748\r\n"}, {"input": "5\r\n1.0 1.0 1.0 0.1 0\r\n", "output": "1.000000000000\r\n"}, {"input": "5\r\n0.0001 0.0001 0.0001 0.0001 0.0001\r\n", "output": "0.000499800030\r\n"}, {"input": "20\r\n0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1\r\n", "output": "0.387420489000\r\n"}, {"input": "2\r\n0.0 1.0\r\n", "output": "1.000000000000\r\n"}, {"input": "5\r\n0.00001 0.00001 0.00001 0.00001 0.00001\r\n", "output": "0.000049998000\r\n"}, {"input": "3\r\n0.2 0.8 1\r\n", "output": "1.000000000000\r\n"}, {"input": "4\r\n0.1 0.1 0.1 0.1\r\n", "output": "0.291600000000\r\n"}, {"input": "5\r\n0.31 0.21 0.05 0.37 0.18\r\n", "output": "0.450600000000\r\n"}, {"input": "5\r\n1 1 1 1 1\r\n", "output": "1.000000000000\r\n"}, {"input": "4\r\n1 1 1 1\r\n", "output": "1.000000000000\r\n"}, {"input": "7\r\n0.14 0.28 0.13 0.31 0.15 0.17 0.27\r\n", "output": "0.438108000000\r\n"}, {"input": "20\r\n0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001\r\n", "output": "0.019623400697\r\n"}, {"input": "100\r\n0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1\r\n", "output": "0.387420489000\r\n"}]
| false |
stdio
|
import sys
def main(input_path, output_path, submission_path):
# Read submission output
with open(submission_path, 'r') as f:
submission_lines = f.readlines()
if len(submission_lines) != 1:
print(0)
return
submission_str = submission_lines[0].strip()
try:
sub_val = float(submission_str)
except:
print(0)
return
# Read reference output
with open(output_path, 'r') as f:
ref_lines = f.readlines()
if len(ref_lines) != 1:
print(0)
return
ref_str = ref_lines[0].strip()
try:
ref_val = float(ref_str)
except:
print(0)
return
# Compute absolute difference
diff = abs(sub_val - ref_val)
if diff <= 1e-9:
print(1)
else:
print(0)
if __name__ == "__main__":
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
main(input_path, output_path, submission_path)
| true |
197/B
|
197
|
B
|
Python 3
|
TESTS
| 10 | 218 | 0 |
49733782
|
n,m=map(int,input().split())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
if n>m:
if (a[0]>=0 and b[0]>=0) or (a[0]<=0 and b[0]<=0):
print('Infinity')
else:
print('-Infinity')
elif n<m:
print('0/1')
else:
a1=a[0]
b1=b[0]
sign=None
if a1>=0 and b1<0 :
sign=-1
b1=-b1
elif a1<0 and b1>=0:
sign=-1
a1=-a1
from math import gcd
g=gcd(a1,b1)
if not sign:
print(str(a1//g)+'/'+str(b1//g))
else:
print('-'+str(a1//g)+'/'+str(b1//g))
| 80 | 124 | 0 |
211647410
|
import math
n, m = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
if n > m :
if a[0]*b[0] < 0 :
print("-Infinity")
else :
print("Infinity")
elif n == m :
hcf = math.gcd(a[0],b[0])
if a[0]*b[0] < 0 :
print('-', abs(a[0]//hcf),'/',abs(b[0]//hcf),sep="")
else :
print(abs(a[0]//hcf),'/',abs(b[0]//hcf),sep="")
else :
print("0/1")
|
Codeforces Round 124 (Div. 2)
|
CF
| 2,012 | 2 | 256 |
Limit
|
You are given two polynomials:
- P(x) = a0·xn + a1·xn - 1 + ... + an - 1·x + an and
- Q(x) = b0·xm + b1·xm - 1 + ... + bm - 1·x + bm.
Calculate limit $$\lim_{x \to +\infty} \frac{P(x)}{Q(x)}$$.
|
The first line contains two space-separated integers n and m (0 ≤ n, m ≤ 100) — degrees of polynomials P(x) and Q(x) correspondingly.
The second line contains n + 1 space-separated integers — the factors of polynomial P(x): a0, a1, ..., an - 1, an ( - 100 ≤ ai ≤ 100, a0 ≠ 0).
The third line contains m + 1 space-separated integers — the factors of polynomial Q(x): b0, b1, ..., bm - 1, bm ( - 100 ≤ bi ≤ 100, b0 ≠ 0).
|
If the limit equals + ∞, print "Infinity" (without quotes). If the limit equals - ∞, print "-Infinity" (without the quotes).
If the value of the limit equals zero, print "0/1" (without the quotes).
Otherwise, print an irreducible fraction — the value of limit $$\lim_{x \to +\infty} \frac{P(x)}{Q(x)}$$, in the format "p/q" (without the quotes), where p is the — numerator, q (q > 0) is the denominator of the fraction.
| null |
Let's consider all samples:
1. $$\lim_{x \to +\infty} \frac{x^2+x+1}{2x+5} = +\infty$$
2. $$\lim_{x \to +\infty} \frac{-x+3}{2} = -\infty$$
3. $$\lim_{x \to +\infty} \frac{1}{x} = 0$$
4. $$\lim_{x \to +\infty} \frac{2x^2+x+6}{4x^2+5x-7} = \frac{1}{2}$$
5. $$\lim_{x \to +\infty} \frac{9x}{-5x+2} = -\frac{9}{5}$$
You can learn more about the definition and properties of limits if you follow the link: http://en.wikipedia.org/wiki/Limit_of_a_function
|
[{"input": "2 1\n1 1 1\n2 5", "output": "Infinity"}, {"input": "1 0\n-1 3\n2", "output": "-Infinity"}, {"input": "0 1\n1\n1 0", "output": "0/1"}, {"input": "2 2\n2 1 6\n4 5 -7", "output": "1/2"}, {"input": "1 1\n9 0\n-5 2", "output": "-9/5"}]
| 1,400 |
["math"]
| 80 |
[{"input": "2 1\r\n1 1 1\r\n2 5\r\n", "output": "Infinity\r\n"}, {"input": "1 0\r\n-1 3\r\n2\r\n", "output": "-Infinity\r\n"}, {"input": "0 1\r\n1\r\n1 0\r\n", "output": "0/1\r\n"}, {"input": "2 2\r\n2 1 6\r\n4 5 -7\r\n", "output": "1/2\n"}, {"input": "1 1\r\n9 0\r\n-5 2\r\n", "output": "-9/5\n"}, {"input": "1 2\r\n5 3\r\n-3 2 -1\r\n", "output": "0/1\r\n"}, {"input": "1 2\r\n-4 8\r\n-2 5 -3\r\n", "output": "0/1\r\n"}, {"input": "3 2\r\n4 3 1 2\r\n-5 7 0\r\n", "output": "-Infinity\r\n"}, {"input": "2 1\r\n-3 5 1\r\n-8 0\r\n", "output": "Infinity\r\n"}, {"input": "1 1\r\n-5 7\r\n3 1\r\n", "output": "-5/3\n"}, {"input": "2 2\r\n-4 2 1\r\n-5 8 -19\r\n", "output": "4/5\n"}, {"input": "0 0\r\n36\r\n-54\r\n", "output": "-2/3\n"}, {"input": "0 0\r\n36\r\n-8\r\n", "output": "-9/2\n"}, {"input": "0 0\r\n-6\r\n-8\r\n", "output": "3/4\n"}, {"input": "0 2\r\n-3\r\n1 4 6\r\n", "output": "0/1\r\n"}, {"input": "0 0\r\n-21\r\n13\r\n", "output": "-21/13\n"}, {"input": "0 0\r\n-34\r\n21\r\n", "output": "-34/21\n"}, {"input": "0 0\r\n-55\r\n34\r\n", "output": "-55/34\n"}, {"input": "33 1\r\n-75 -83 87 -27 -48 47 -90 -84 -18 -4 14 -1 -83 -98 -68 -85 -86 28 2 45 96 -59 86 -25 -2 -64 -92 65 69 72 72 -58 -99 90\r\n-1 72\r\n", "output": "Infinity\r\n"}, {"input": "20 20\r\n5 4 91 -66 -57 55 -79 -2 -54 -72 -49 21 -23 -5 57 -48 70 -16 -86 -26 -19\r\n51 -60 64 -8 89 27 -96 4 95 -24 -2 -27 -41 -14 -88 -19 24 68 -31 34 -62\r\n", "output": "5/51\n"}, {"input": "0 0\r\n46\r\n-33\r\n", "output": "-46/33\n"}, {"input": "17 17\r\n-54 59 -95 87 3 -27 -30 49 -87 74 45 78 36 60 -95 41 -53 -70\r\n-27 16 -67 -24 10 -73 -41 12 -52 53 -73 -17 -56 -74 -33 -8 100 -39\r\n", "output": "2/1\n"}, {"input": "1 1\r\n36 -49\r\n-32 -40\r\n", "output": "-9/8\n"}, {"input": "1 1\r\n1 1\r\n1 1\r\n", "output": "1/1\n"}, {"input": "1 1\r\n-2 1\r\n4 1\r\n", "output": "-1/2\n"}, {"input": "0 0\r\n2\r\n1\r\n", "output": "2/1\n"}, {"input": "0 0\r\n4\r\n-3\r\n", "output": "-4/3\n"}, {"input": "0 0\r\n2\r\n2\r\n", "output": "1/1\n"}, {"input": "0 0\r\n17\r\n-10\r\n", "output": "-17/10\n"}, {"input": "0 0\r\n-1\r\n2\r\n", "output": "-1/2\n"}, {"input": "0 0\r\n1\r\n1\r\n", "output": "1/1\n"}, {"input": "0 0\r\n50\r\n20\r\n", "output": "5/2\n"}, {"input": "0 0\r\n20\r\n20\r\n", "output": "1/1\n"}, {"input": "0 0\r\n4\r\n-2\r\n", "output": "-2/1\n"}, {"input": "0 0\r\n4\r\n-6\r\n", "output": "-2/3\n"}, {"input": "0 0\r\n1\r\n-2\r\n", "output": "-1/2\n"}, {"input": "0 0\r\n4\r\n2\r\n", "output": "2/1\n"}, {"input": "0 0\r\n2\r\n-4\r\n", "output": "-1/2\n"}, {"input": "1 1\r\n4 1\r\n2 1\r\n", "output": "2/1\n"}, {"input": "2 2\r\n-13 1 3\r\n6 3 2\r\n", "output": "-13/6\n"}, {"input": "0 0\r\n5\r\n5\r\n", "output": "1/1\n"}, {"input": "0 0\r\n2\r\n-1\r\n", "output": "-2/1\n"}]
| false |
stdio
| null | true |
197/B
|
197
|
B
|
Python 3
|
TESTS
| 10 | 124 | 5,529,600 |
28170262
|
from sys import stdin, stdout
def GCD(a, b):
if not b:
return a
if a < b:
return GCD(b, a)
else:
return GCD(b, a % b)
n, m = map(int, stdin.readline().split())
a = list(map(int, stdin.readline().split()))
b = list(map(int, stdin.readline().split()))
if n > m:
if a[0] * b[0] > 0:
stdout.write('Infinity')
else:
stdout.write('-Infinity')
elif n < m:
stdout.write('0/1')
else:
gcd = GCD(abs(a[0]), abs(b[0]))
if a[0] * b[0] > 0:
stdout.write(str(a[0] // gcd) + '/' + str(b[0] // gcd))
else:
stdout.write('-' + str(abs(a[0]) // gcd) + '/' + str(abs(b[0]) // gcd))
| 80 | 124 | 0 |
225061724
|
def gcd(x,y):
if x%y==0:
return y
return gcd(y,x%y)
n,m = map(int,input().split())
lin,lim = [int(i) for i in input().split()],[int(i) for i in input().split()]
if n>m :
if lin[0]*lim[0]<0:
print("-Infinity")
else:
print("Infinity")
elif m>n:
print('0/1')
else:
x,y = max(abs(lin[0]),abs(lim[0])),min(abs(lin[0]),abs(lim[0]))
a = gcd(x,y)
if lin[0]*lim[0]<0:
print("-"+str(abs(lin[0])//a)+'/'+str(abs(lim[0])//a))
else:
print(str(abs(lin[0])//a)+'/'+str(abs(lim[0])//a))
|
Codeforces Round 124 (Div. 2)
|
CF
| 2,012 | 2 | 256 |
Limit
|
You are given two polynomials:
- P(x) = a0·xn + a1·xn - 1 + ... + an - 1·x + an and
- Q(x) = b0·xm + b1·xm - 1 + ... + bm - 1·x + bm.
Calculate limit $$\lim_{x \to +\infty} \frac{P(x)}{Q(x)}$$.
|
The first line contains two space-separated integers n and m (0 ≤ n, m ≤ 100) — degrees of polynomials P(x) and Q(x) correspondingly.
The second line contains n + 1 space-separated integers — the factors of polynomial P(x): a0, a1, ..., an - 1, an ( - 100 ≤ ai ≤ 100, a0 ≠ 0).
The third line contains m + 1 space-separated integers — the factors of polynomial Q(x): b0, b1, ..., bm - 1, bm ( - 100 ≤ bi ≤ 100, b0 ≠ 0).
|
If the limit equals + ∞, print "Infinity" (without quotes). If the limit equals - ∞, print "-Infinity" (without the quotes).
If the value of the limit equals zero, print "0/1" (without the quotes).
Otherwise, print an irreducible fraction — the value of limit $$\lim_{x \to +\infty} \frac{P(x)}{Q(x)}$$, in the format "p/q" (without the quotes), where p is the — numerator, q (q > 0) is the denominator of the fraction.
| null |
Let's consider all samples:
1. $$\lim_{x \to +\infty} \frac{x^2+x+1}{2x+5} = +\infty$$
2. $$\lim_{x \to +\infty} \frac{-x+3}{2} = -\infty$$
3. $$\lim_{x \to +\infty} \frac{1}{x} = 0$$
4. $$\lim_{x \to +\infty} \frac{2x^2+x+6}{4x^2+5x-7} = \frac{1}{2}$$
5. $$\lim_{x \to +\infty} \frac{9x}{-5x+2} = -\frac{9}{5}$$
You can learn more about the definition and properties of limits if you follow the link: http://en.wikipedia.org/wiki/Limit_of_a_function
|
[{"input": "2 1\n1 1 1\n2 5", "output": "Infinity"}, {"input": "1 0\n-1 3\n2", "output": "-Infinity"}, {"input": "0 1\n1\n1 0", "output": "0/1"}, {"input": "2 2\n2 1 6\n4 5 -7", "output": "1/2"}, {"input": "1 1\n9 0\n-5 2", "output": "-9/5"}]
| 1,400 |
["math"]
| 80 |
[{"input": "2 1\r\n1 1 1\r\n2 5\r\n", "output": "Infinity\r\n"}, {"input": "1 0\r\n-1 3\r\n2\r\n", "output": "-Infinity\r\n"}, {"input": "0 1\r\n1\r\n1 0\r\n", "output": "0/1\r\n"}, {"input": "2 2\r\n2 1 6\r\n4 5 -7\r\n", "output": "1/2\n"}, {"input": "1 1\r\n9 0\r\n-5 2\r\n", "output": "-9/5\n"}, {"input": "1 2\r\n5 3\r\n-3 2 -1\r\n", "output": "0/1\r\n"}, {"input": "1 2\r\n-4 8\r\n-2 5 -3\r\n", "output": "0/1\r\n"}, {"input": "3 2\r\n4 3 1 2\r\n-5 7 0\r\n", "output": "-Infinity\r\n"}, {"input": "2 1\r\n-3 5 1\r\n-8 0\r\n", "output": "Infinity\r\n"}, {"input": "1 1\r\n-5 7\r\n3 1\r\n", "output": "-5/3\n"}, {"input": "2 2\r\n-4 2 1\r\n-5 8 -19\r\n", "output": "4/5\n"}, {"input": "0 0\r\n36\r\n-54\r\n", "output": "-2/3\n"}, {"input": "0 0\r\n36\r\n-8\r\n", "output": "-9/2\n"}, {"input": "0 0\r\n-6\r\n-8\r\n", "output": "3/4\n"}, {"input": "0 2\r\n-3\r\n1 4 6\r\n", "output": "0/1\r\n"}, {"input": "0 0\r\n-21\r\n13\r\n", "output": "-21/13\n"}, {"input": "0 0\r\n-34\r\n21\r\n", "output": "-34/21\n"}, {"input": "0 0\r\n-55\r\n34\r\n", "output": "-55/34\n"}, {"input": "33 1\r\n-75 -83 87 -27 -48 47 -90 -84 -18 -4 14 -1 -83 -98 -68 -85 -86 28 2 45 96 -59 86 -25 -2 -64 -92 65 69 72 72 -58 -99 90\r\n-1 72\r\n", "output": "Infinity\r\n"}, {"input": "20 20\r\n5 4 91 -66 -57 55 -79 -2 -54 -72 -49 21 -23 -5 57 -48 70 -16 -86 -26 -19\r\n51 -60 64 -8 89 27 -96 4 95 -24 -2 -27 -41 -14 -88 -19 24 68 -31 34 -62\r\n", "output": "5/51\n"}, {"input": "0 0\r\n46\r\n-33\r\n", "output": "-46/33\n"}, {"input": "17 17\r\n-54 59 -95 87 3 -27 -30 49 -87 74 45 78 36 60 -95 41 -53 -70\r\n-27 16 -67 -24 10 -73 -41 12 -52 53 -73 -17 -56 -74 -33 -8 100 -39\r\n", "output": "2/1\n"}, {"input": "1 1\r\n36 -49\r\n-32 -40\r\n", "output": "-9/8\n"}, {"input": "1 1\r\n1 1\r\n1 1\r\n", "output": "1/1\n"}, {"input": "1 1\r\n-2 1\r\n4 1\r\n", "output": "-1/2\n"}, {"input": "0 0\r\n2\r\n1\r\n", "output": "2/1\n"}, {"input": "0 0\r\n4\r\n-3\r\n", "output": "-4/3\n"}, {"input": "0 0\r\n2\r\n2\r\n", "output": "1/1\n"}, {"input": "0 0\r\n17\r\n-10\r\n", "output": "-17/10\n"}, {"input": "0 0\r\n-1\r\n2\r\n", "output": "-1/2\n"}, {"input": "0 0\r\n1\r\n1\r\n", "output": "1/1\n"}, {"input": "0 0\r\n50\r\n20\r\n", "output": "5/2\n"}, {"input": "0 0\r\n20\r\n20\r\n", "output": "1/1\n"}, {"input": "0 0\r\n4\r\n-2\r\n", "output": "-2/1\n"}, {"input": "0 0\r\n4\r\n-6\r\n", "output": "-2/3\n"}, {"input": "0 0\r\n1\r\n-2\r\n", "output": "-1/2\n"}, {"input": "0 0\r\n4\r\n2\r\n", "output": "2/1\n"}, {"input": "0 0\r\n2\r\n-4\r\n", "output": "-1/2\n"}, {"input": "1 1\r\n4 1\r\n2 1\r\n", "output": "2/1\n"}, {"input": "2 2\r\n-13 1 3\r\n6 3 2\r\n", "output": "-13/6\n"}, {"input": "0 0\r\n5\r\n5\r\n", "output": "1/1\n"}, {"input": "0 0\r\n2\r\n-1\r\n", "output": "-2/1\n"}]
| false |
stdio
| null | true |
404/A
|
404
|
A
|
Python 3
|
TESTS
| 31 | 46 | 0 |
223984634
|
n = int(input())
pat = []
flag = True
for _ in range(n):
temp = input()
if not 3 > len(list(set(temp))) > 1:
flag = False
pat.append(temp)
if flag:
x = pat[0][0]
for i in range(n):
if i == n // 2:
if pat[i].count(x) != 1:
flag = False
print("NO")
break
else:
if pat[i].count(x) != 2:
flag = False
print("NO")
break
if flag:
print("YES")
else:
print("NO")
| 47 | 46 | 0 |
137385662
|
n=int(input())
a=[]
check=1
s=input()
if len(set(s))!=2:
check=0
else:
if s.count(s[0])!=2:
check=0
else:
if s[0]!=s[-1]:
check=0
a=list(set(s))
a.sort()
for i in range(1,n):
s1=input()
if len(set(s1))!=2:
check=0
else:
if i*2+1==n:
if s1.count(s[0])!=1:
check=0
else:
if sorted(list(set(s1)))!=a:
check=0
else:
if s1.count(s[0])!=2:
check=0
else:
if sorted(list(set(s1)))!=a:
check=0
if check==1:
print('YES')
else:
print('NO')
|
Codeforces Round 237 (Div. 2)
|
CF
| 2,014 | 1 | 256 |
Valera and X
|
Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the side equals n squares (n is an odd number) and each unit square contains some small letter of the English alphabet.
Valera needs to know if the letters written on the square piece of paper form letter "X". Valera's teacher thinks that the letters on the piece of paper form an "X", if:
- on both diagonals of the square paper all letters are the same;
- all other squares of the paper (they are not on the diagonals) contain the same letter that is different from the letters on the diagonals.
Help Valera, write the program that completes the described task for him.
|
The first line contains integer n (3 ≤ n < 300; n is odd). Each of the next n lines contains n small English letters — the description of Valera's paper.
|
Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes.
| null | null |
[{"input": "5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox", "output": "NO"}, {"input": "3\nwsw\nsws\nwsw", "output": "YES"}, {"input": "3\nxpx\npxp\nxpe", "output": "NO"}]
| 1,000 |
["implementation"]
| 47 |
[{"input": "5\r\nxooox\r\noxoxo\r\nsoxoo\r\noxoxo\r\nxooox\r\n", "output": "NO\r\n"}, {"input": "3\r\nwsw\r\nsws\r\nwsw\r\n", "output": "YES\r\n"}, {"input": "3\r\nxpx\r\npxp\r\nxpe\r\n", "output": "NO\r\n"}, {"input": "5\r\nliiil\r\nilili\r\niilii\r\nilili\r\nliiil\r\n", "output": "YES\r\n"}, {"input": "7\r\nbwccccb\r\nckcccbj\r\nccbcbcc\r\ncccbccc\r\nccbcbcc\r\ncbcccbc\r\nbccccdt\r\n", "output": "NO\r\n"}, {"input": "13\r\nsooooooooooos\r\nosoooooooooso\r\noosooooooosoo\r\nooosooooosooo\r\noooosooosoooo\r\nooooososooooo\r\noooooosoooooo\r\nooooososooooo\r\noooosooosoooo\r\nooosooooosooo\r\noosooooooosoo\r\nosoooooooooso\r\nsooooooooooos\r\n", "output": "YES\r\n"}, {"input": "3\r\naaa\r\naaa\r\naaa\r\n", "output": "NO\r\n"}, {"input": "3\r\naca\r\noec\r\nzba\r\n", "output": "NO\r\n"}, {"input": "15\r\nrxeeeeeeeeeeeer\r\nereeeeeeeeeeere\r\needeeeeeeeeeoee\r\neeereeeeeeeewee\r\neeeereeeeebeeee\r\nqeeeereeejedyee\r\neeeeeerereeeeee\r\neeeeeeereeeeeee\r\neeeeeerereeeeze\r\neeeeereeereeeee\r\neeeereeeeegeeee\r\neeereeeeeeereee\r\neereeeeeeqeeved\r\ncreeeeeeceeeere\r\nreeerneeeeeeeer\r\n", "output": "NO\r\n"}, {"input": "5\r\nxxxxx\r\nxxxxx\r\nxxxxx\r\nxxxxx\r\nxxxxx\r\n", "output": "NO\r\n"}, {"input": "5\r\nxxxxx\r\nxxxxx\r\nxoxxx\r\nxxxxx\r\nxxxxx\r\n", "output": "NO\r\n"}, {"input": "5\r\noxxxo\r\nxoxox\r\nxxxxx\r\nxoxox\r\noxxxo\r\n", "output": "NO\r\n"}, {"input": "5\r\noxxxo\r\nxoxox\r\nxxoox\r\nxoxox\r\noxxxo\r\n", "output": "NO\r\n"}, {"input": "5\r\noxxxo\r\nxoxox\r\nxxaxx\r\nxoxox\r\noxxxo\r\n", "output": "NO\r\n"}, {"input": "5\r\noxxxo\r\nxoxox\r\noxoxx\r\nxoxox\r\noxxxo\r\n", "output": "NO\r\n"}, {"input": "3\r\nxxx\r\naxa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\naxx\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\naxa\r\nxxx\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\nxxa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\naaa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\naax\r\naxa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxaa\r\naxa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\naxa\r\naax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\naxa\r\nxaa\r\n", "output": "NO\r\n"}, {"input": "3\r\nxfx\r\naxa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\nafa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\naxa\r\nxaf\r\n", "output": "NO\r\n"}, {"input": "3\r\nxox\r\nxxx\r\nxxx\r\n", "output": "NO\r\n"}, {"input": "3\r\naxa\r\naax\r\nxxa\r\n", "output": "NO\r\n"}, {"input": "3\r\nxox\r\noxx\r\nxox\r\n", "output": "NO\r\n"}, {"input": "3\r\nxox\r\nooo\r\nxox\r\n", "output": "NO\r\n"}, {"input": "3\r\naaa\r\naab\r\nbbb\r\n", "output": "NO\r\n"}, {"input": "3\r\nxxx\r\nsxs\r\nxsx\r\n", "output": "NO\r\n"}, {"input": "5\r\nabbba\r\nbabab\r\nbbbbb\r\nbaaab\r\nabbba\r\n", "output": "NO\r\n"}, {"input": "5\r\nabaaa\r\nbbbbb\r\nbbabb\r\nbabab\r\nabbba\r\n", "output": "NO\r\n"}, {"input": "5\r\nxoxox\r\noxoxo\r\nooxoo\r\noxoxo\r\nxooox\r\n", "output": "NO\r\n"}, {"input": "3\r\nxox\r\noxx\r\nxxx\r\n", "output": "NO\r\n"}, {"input": "5\r\nxoooo\r\noxooo\r\nooxoo\r\noooxo\r\noooox\r\n", "output": "NO\r\n"}, {"input": "5\r\nxoooo\r\noxoxx\r\nooxoo\r\noxoxo\r\noxoox\r\n", "output": "NO\r\n"}, {"input": "3\r\naaa\r\nbab\r\naba\r\n", "output": "NO\r\n"}]
| false |
stdio
| null | true |
404/A
|
404
|
A
|
Python 3
|
TESTS
| 44 | 109 | 0 |
146008646
|
n = int(input())
letters = []
checker_one = True
checker_two = True
checker_three = True
letter = [0]*26
for i in range(n):
letters.append(input())
letter_check = letters[0][0]
for i in range(n):
for j in range(n):
if j == i:
if letters[i][j] != letters[i-1][j-1]:
letter_check = letters[i][j]
checker_one = False
elif j - n + i == -1:
if letters[i][j] != letters[-i-1][-j-1]:
checker_two = False
else:
letter[int(ord(letters[i][j].lower()))-97] = 1
if letters[i][j] == letter_check:
checker_three = False
if letter.count(1) > 1:
checker_three = False
if checker_one and checker_two and checker_three:
print("YES")
else:
print("NO")
| 47 | 46 | 0 |
144132009
|
sq = int(input())
def main(sq: int) :
x_array = []
input_array= []
for i in range(sq):
input_array.append(str(input()))
a = input_array[0][0]
b = ""
for x in input_array[0]:
if x!=a:
b = x
break
last = sq-1
first = 0
for _ in range(sq):
temp = ""
for i in range(sq):
if i==first or i==last:
temp += a
elif not (i==first or i==last):
temp += b
first += 1
last -= 1
x_array.append(temp)
if x_array == input_array:
print("YES")
return
print("NO")
return
main(sq)
|
Codeforces Round 237 (Div. 2)
|
CF
| 2,014 | 1 | 256 |
Valera and X
|
Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the side equals n squares (n is an odd number) and each unit square contains some small letter of the English alphabet.
Valera needs to know if the letters written on the square piece of paper form letter "X". Valera's teacher thinks that the letters on the piece of paper form an "X", if:
- on both diagonals of the square paper all letters are the same;
- all other squares of the paper (they are not on the diagonals) contain the same letter that is different from the letters on the diagonals.
Help Valera, write the program that completes the described task for him.
|
The first line contains integer n (3 ≤ n < 300; n is odd). Each of the next n lines contains n small English letters — the description of Valera's paper.
|
Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes.
| null | null |
[{"input": "5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox", "output": "NO"}, {"input": "3\nwsw\nsws\nwsw", "output": "YES"}, {"input": "3\nxpx\npxp\nxpe", "output": "NO"}]
| 1,000 |
["implementation"]
| 47 |
[{"input": "5\r\nxooox\r\noxoxo\r\nsoxoo\r\noxoxo\r\nxooox\r\n", "output": "NO\r\n"}, {"input": "3\r\nwsw\r\nsws\r\nwsw\r\n", "output": "YES\r\n"}, {"input": "3\r\nxpx\r\npxp\r\nxpe\r\n", "output": "NO\r\n"}, {"input": "5\r\nliiil\r\nilili\r\niilii\r\nilili\r\nliiil\r\n", "output": "YES\r\n"}, {"input": "7\r\nbwccccb\r\nckcccbj\r\nccbcbcc\r\ncccbccc\r\nccbcbcc\r\ncbcccbc\r\nbccccdt\r\n", "output": "NO\r\n"}, {"input": "13\r\nsooooooooooos\r\nosoooooooooso\r\noosooooooosoo\r\nooosooooosooo\r\noooosooosoooo\r\nooooososooooo\r\noooooosoooooo\r\nooooososooooo\r\noooosooosoooo\r\nooosooooosooo\r\noosooooooosoo\r\nosoooooooooso\r\nsooooooooooos\r\n", "output": "YES\r\n"}, {"input": "3\r\naaa\r\naaa\r\naaa\r\n", "output": "NO\r\n"}, {"input": "3\r\naca\r\noec\r\nzba\r\n", "output": "NO\r\n"}, {"input": "15\r\nrxeeeeeeeeeeeer\r\nereeeeeeeeeeere\r\needeeeeeeeeeoee\r\neeereeeeeeeewee\r\neeeereeeeebeeee\r\nqeeeereeejedyee\r\neeeeeerereeeeee\r\neeeeeeereeeeeee\r\neeeeeerereeeeze\r\neeeeereeereeeee\r\neeeereeeeegeeee\r\neeereeeeeeereee\r\neereeeeeeqeeved\r\ncreeeeeeceeeere\r\nreeerneeeeeeeer\r\n", "output": "NO\r\n"}, {"input": "5\r\nxxxxx\r\nxxxxx\r\nxxxxx\r\nxxxxx\r\nxxxxx\r\n", "output": "NO\r\n"}, {"input": "5\r\nxxxxx\r\nxxxxx\r\nxoxxx\r\nxxxxx\r\nxxxxx\r\n", "output": "NO\r\n"}, {"input": "5\r\noxxxo\r\nxoxox\r\nxxxxx\r\nxoxox\r\noxxxo\r\n", "output": "NO\r\n"}, {"input": "5\r\noxxxo\r\nxoxox\r\nxxoox\r\nxoxox\r\noxxxo\r\n", "output": "NO\r\n"}, {"input": "5\r\noxxxo\r\nxoxox\r\nxxaxx\r\nxoxox\r\noxxxo\r\n", "output": "NO\r\n"}, {"input": "5\r\noxxxo\r\nxoxox\r\noxoxx\r\nxoxox\r\noxxxo\r\n", "output": "NO\r\n"}, {"input": "3\r\nxxx\r\naxa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\naxx\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\naxa\r\nxxx\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\nxxa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\naaa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\naax\r\naxa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxaa\r\naxa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\naxa\r\naax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\naxa\r\nxaa\r\n", "output": "NO\r\n"}, {"input": "3\r\nxfx\r\naxa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\nafa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\naxa\r\nxaf\r\n", "output": "NO\r\n"}, {"input": "3\r\nxox\r\nxxx\r\nxxx\r\n", "output": "NO\r\n"}, {"input": "3\r\naxa\r\naax\r\nxxa\r\n", "output": "NO\r\n"}, {"input": "3\r\nxox\r\noxx\r\nxox\r\n", "output": "NO\r\n"}, {"input": "3\r\nxox\r\nooo\r\nxox\r\n", "output": "NO\r\n"}, {"input": "3\r\naaa\r\naab\r\nbbb\r\n", "output": "NO\r\n"}, {"input": "3\r\nxxx\r\nsxs\r\nxsx\r\n", "output": "NO\r\n"}, {"input": "5\r\nabbba\r\nbabab\r\nbbbbb\r\nbaaab\r\nabbba\r\n", "output": "NO\r\n"}, {"input": "5\r\nabaaa\r\nbbbbb\r\nbbabb\r\nbabab\r\nabbba\r\n", "output": "NO\r\n"}, {"input": "5\r\nxoxox\r\noxoxo\r\nooxoo\r\noxoxo\r\nxooox\r\n", "output": "NO\r\n"}, {"input": "3\r\nxox\r\noxx\r\nxxx\r\n", "output": "NO\r\n"}, {"input": "5\r\nxoooo\r\noxooo\r\nooxoo\r\noooxo\r\noooox\r\n", "output": "NO\r\n"}, {"input": "5\r\nxoooo\r\noxoxx\r\nooxoo\r\noxoxo\r\noxoox\r\n", "output": "NO\r\n"}, {"input": "3\r\naaa\r\nbab\r\naba\r\n", "output": "NO\r\n"}]
| false |
stdio
| null | true |
404/A
|
404
|
A
|
Python 3
|
TESTS
| 42 | 139 | 8,396,800 |
86832622
|
z=int(input())
s=[]
d=[]
sd={}
c=0
q=0
for i in range(z):
x=input()
if len(x)==("".join(x)).count(x[0]):
c=1203
break
for o in x:
s.append(o)
sd[o]=ord(o)
q+=1
for u in range(len(x)):
d.append(x[len(x)-u-1])
if c==1203 or len(sd)>=3 :
print("NO")
elif s==d:
print("YES")
else:
print("NO")
| 47 | 46 | 0 |
148496276
|
num=int(input())
arr=[input() for i in range(num)]
c1,c2=arr[0][0],arr[0][1]
tmp=2
for i in range(num):
check1=len(arr[i].replace(c1,""))
check2=len(arr[i].replace(c2,""))
if i!=(num-1)/2:
if check1!=num-2 or check2!=2:
print("NO")
quit()
else:
if check1!=num-1 or check2!=1 :
print("NO")
quit()
print("YES")
|
Codeforces Round 237 (Div. 2)
|
CF
| 2,014 | 1 | 256 |
Valera and X
|
Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the side equals n squares (n is an odd number) and each unit square contains some small letter of the English alphabet.
Valera needs to know if the letters written on the square piece of paper form letter "X". Valera's teacher thinks that the letters on the piece of paper form an "X", if:
- on both diagonals of the square paper all letters are the same;
- all other squares of the paper (they are not on the diagonals) contain the same letter that is different from the letters on the diagonals.
Help Valera, write the program that completes the described task for him.
|
The first line contains integer n (3 ≤ n < 300; n is odd). Each of the next n lines contains n small English letters — the description of Valera's paper.
|
Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes.
| null | null |
[{"input": "5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox", "output": "NO"}, {"input": "3\nwsw\nsws\nwsw", "output": "YES"}, {"input": "3\nxpx\npxp\nxpe", "output": "NO"}]
| 1,000 |
["implementation"]
| 47 |
[{"input": "5\r\nxooox\r\noxoxo\r\nsoxoo\r\noxoxo\r\nxooox\r\n", "output": "NO\r\n"}, {"input": "3\r\nwsw\r\nsws\r\nwsw\r\n", "output": "YES\r\n"}, {"input": "3\r\nxpx\r\npxp\r\nxpe\r\n", "output": "NO\r\n"}, {"input": "5\r\nliiil\r\nilili\r\niilii\r\nilili\r\nliiil\r\n", "output": "YES\r\n"}, {"input": "7\r\nbwccccb\r\nckcccbj\r\nccbcbcc\r\ncccbccc\r\nccbcbcc\r\ncbcccbc\r\nbccccdt\r\n", "output": "NO\r\n"}, {"input": "13\r\nsooooooooooos\r\nosoooooooooso\r\noosooooooosoo\r\nooosooooosooo\r\noooosooosoooo\r\nooooososooooo\r\noooooosoooooo\r\nooooososooooo\r\noooosooosoooo\r\nooosooooosooo\r\noosooooooosoo\r\nosoooooooooso\r\nsooooooooooos\r\n", "output": "YES\r\n"}, {"input": "3\r\naaa\r\naaa\r\naaa\r\n", "output": "NO\r\n"}, {"input": "3\r\naca\r\noec\r\nzba\r\n", "output": "NO\r\n"}, {"input": "15\r\nrxeeeeeeeeeeeer\r\nereeeeeeeeeeere\r\needeeeeeeeeeoee\r\neeereeeeeeeewee\r\neeeereeeeebeeee\r\nqeeeereeejedyee\r\neeeeeerereeeeee\r\neeeeeeereeeeeee\r\neeeeeerereeeeze\r\neeeeereeereeeee\r\neeeereeeeegeeee\r\neeereeeeeeereee\r\neereeeeeeqeeved\r\ncreeeeeeceeeere\r\nreeerneeeeeeeer\r\n", "output": "NO\r\n"}, {"input": "5\r\nxxxxx\r\nxxxxx\r\nxxxxx\r\nxxxxx\r\nxxxxx\r\n", "output": "NO\r\n"}, {"input": "5\r\nxxxxx\r\nxxxxx\r\nxoxxx\r\nxxxxx\r\nxxxxx\r\n", "output": "NO\r\n"}, {"input": "5\r\noxxxo\r\nxoxox\r\nxxxxx\r\nxoxox\r\noxxxo\r\n", "output": "NO\r\n"}, {"input": "5\r\noxxxo\r\nxoxox\r\nxxoox\r\nxoxox\r\noxxxo\r\n", "output": "NO\r\n"}, {"input": "5\r\noxxxo\r\nxoxox\r\nxxaxx\r\nxoxox\r\noxxxo\r\n", "output": "NO\r\n"}, {"input": "5\r\noxxxo\r\nxoxox\r\noxoxx\r\nxoxox\r\noxxxo\r\n", "output": "NO\r\n"}, {"input": "3\r\nxxx\r\naxa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\naxx\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\naxa\r\nxxx\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\nxxa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\naaa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\naax\r\naxa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxaa\r\naxa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\naxa\r\naax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\naxa\r\nxaa\r\n", "output": "NO\r\n"}, {"input": "3\r\nxfx\r\naxa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\nafa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\naxa\r\nxaf\r\n", "output": "NO\r\n"}, {"input": "3\r\nxox\r\nxxx\r\nxxx\r\n", "output": "NO\r\n"}, {"input": "3\r\naxa\r\naax\r\nxxa\r\n", "output": "NO\r\n"}, {"input": "3\r\nxox\r\noxx\r\nxox\r\n", "output": "NO\r\n"}, {"input": "3\r\nxox\r\nooo\r\nxox\r\n", "output": "NO\r\n"}, {"input": "3\r\naaa\r\naab\r\nbbb\r\n", "output": "NO\r\n"}, {"input": "3\r\nxxx\r\nsxs\r\nxsx\r\n", "output": "NO\r\n"}, {"input": "5\r\nabbba\r\nbabab\r\nbbbbb\r\nbaaab\r\nabbba\r\n", "output": "NO\r\n"}, {"input": "5\r\nabaaa\r\nbbbbb\r\nbbabb\r\nbabab\r\nabbba\r\n", "output": "NO\r\n"}, {"input": "5\r\nxoxox\r\noxoxo\r\nooxoo\r\noxoxo\r\nxooox\r\n", "output": "NO\r\n"}, {"input": "3\r\nxox\r\noxx\r\nxxx\r\n", "output": "NO\r\n"}, {"input": "5\r\nxoooo\r\noxooo\r\nooxoo\r\noooxo\r\noooox\r\n", "output": "NO\r\n"}, {"input": "5\r\nxoooo\r\noxoxx\r\nooxoo\r\noxoxo\r\noxoox\r\n", "output": "NO\r\n"}, {"input": "3\r\naaa\r\nbab\r\naba\r\n", "output": "NO\r\n"}]
| false |
stdio
| null | true |
404/A
|
404
|
A
|
PyPy 3-64
|
TESTS
| 31 | 61 | 102,400 |
196599339
|
n = int(input())
p1 = 0
p2 = n - 1
word = ''
other= ''
mod_ = n // 2
flag = 'YES'
check = 1
for i in range(n):
s = input()
if i == 0:
if s[0] == s[-1]:
word = s[0]
other= s[1]
else:
flag = 'NO'
if len(set(s)) == 2:
if s[p1] == word and s[p2] == word:
if p1 == p2:
if s.count(word) != 1: flag = 'NO'
elif s.count(other)!= n-2 and s.count(word)!= 2: flag= 'NO'
# print(p1, p2)
if check and p1 < mod_ and p2 > mod_:
p1 += 1
p2 -= 1
else:
check = 0
p1 -= 1
p2 += 1
else:
flag = 'NO'
else:
flag = 'NO'
print(flag)
| 47 | 46 | 0 |
154174106
|
n = int(input())
matrix = []
for i in range(n):
matrix.append(input())
diag_letter = matrix[0][0]
off_diag_letter = matrix[0][1]
result = 'YES'
if (len(set(matrix)) == 1):
result = 'NO'
for i in range(n):
if (matrix[i][i] == matrix[i][n-i-1] == diag_letter):
chars = list(matrix[i])
chars[i] = chars[n-i-1] = off_diag_letter
matrix[i] = "".join(chars)
else:
result = 'NO'
break
if (result!='NO' and len(set(matrix))==1):
print('YES')
else:
print('NO')
|
Codeforces Round 237 (Div. 2)
|
CF
| 2,014 | 1 | 256 |
Valera and X
|
Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the side equals n squares (n is an odd number) and each unit square contains some small letter of the English alphabet.
Valera needs to know if the letters written on the square piece of paper form letter "X". Valera's teacher thinks that the letters on the piece of paper form an "X", if:
- on both diagonals of the square paper all letters are the same;
- all other squares of the paper (they are not on the diagonals) contain the same letter that is different from the letters on the diagonals.
Help Valera, write the program that completes the described task for him.
|
The first line contains integer n (3 ≤ n < 300; n is odd). Each of the next n lines contains n small English letters — the description of Valera's paper.
|
Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes.
| null | null |
[{"input": "5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox", "output": "NO"}, {"input": "3\nwsw\nsws\nwsw", "output": "YES"}, {"input": "3\nxpx\npxp\nxpe", "output": "NO"}]
| 1,000 |
["implementation"]
| 47 |
[{"input": "5\r\nxooox\r\noxoxo\r\nsoxoo\r\noxoxo\r\nxooox\r\n", "output": "NO\r\n"}, {"input": "3\r\nwsw\r\nsws\r\nwsw\r\n", "output": "YES\r\n"}, {"input": "3\r\nxpx\r\npxp\r\nxpe\r\n", "output": "NO\r\n"}, {"input": "5\r\nliiil\r\nilili\r\niilii\r\nilili\r\nliiil\r\n", "output": "YES\r\n"}, {"input": "7\r\nbwccccb\r\nckcccbj\r\nccbcbcc\r\ncccbccc\r\nccbcbcc\r\ncbcccbc\r\nbccccdt\r\n", "output": "NO\r\n"}, {"input": "13\r\nsooooooooooos\r\nosoooooooooso\r\noosooooooosoo\r\nooosooooosooo\r\noooosooosoooo\r\nooooososooooo\r\noooooosoooooo\r\nooooososooooo\r\noooosooosoooo\r\nooosooooosooo\r\noosooooooosoo\r\nosoooooooooso\r\nsooooooooooos\r\n", "output": "YES\r\n"}, {"input": "3\r\naaa\r\naaa\r\naaa\r\n", "output": "NO\r\n"}, {"input": "3\r\naca\r\noec\r\nzba\r\n", "output": "NO\r\n"}, {"input": "15\r\nrxeeeeeeeeeeeer\r\nereeeeeeeeeeere\r\needeeeeeeeeeoee\r\neeereeeeeeeewee\r\neeeereeeeebeeee\r\nqeeeereeejedyee\r\neeeeeerereeeeee\r\neeeeeeereeeeeee\r\neeeeeerereeeeze\r\neeeeereeereeeee\r\neeeereeeeegeeee\r\neeereeeeeeereee\r\neereeeeeeqeeved\r\ncreeeeeeceeeere\r\nreeerneeeeeeeer\r\n", "output": "NO\r\n"}, {"input": "5\r\nxxxxx\r\nxxxxx\r\nxxxxx\r\nxxxxx\r\nxxxxx\r\n", "output": "NO\r\n"}, {"input": "5\r\nxxxxx\r\nxxxxx\r\nxoxxx\r\nxxxxx\r\nxxxxx\r\n", "output": "NO\r\n"}, {"input": "5\r\noxxxo\r\nxoxox\r\nxxxxx\r\nxoxox\r\noxxxo\r\n", "output": "NO\r\n"}, {"input": "5\r\noxxxo\r\nxoxox\r\nxxoox\r\nxoxox\r\noxxxo\r\n", "output": "NO\r\n"}, {"input": "5\r\noxxxo\r\nxoxox\r\nxxaxx\r\nxoxox\r\noxxxo\r\n", "output": "NO\r\n"}, {"input": "5\r\noxxxo\r\nxoxox\r\noxoxx\r\nxoxox\r\noxxxo\r\n", "output": "NO\r\n"}, {"input": "3\r\nxxx\r\naxa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\naxx\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\naxa\r\nxxx\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\nxxa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\naaa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\naax\r\naxa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxaa\r\naxa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\naxa\r\naax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\naxa\r\nxaa\r\n", "output": "NO\r\n"}, {"input": "3\r\nxfx\r\naxa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\nafa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\naxa\r\nxaf\r\n", "output": "NO\r\n"}, {"input": "3\r\nxox\r\nxxx\r\nxxx\r\n", "output": "NO\r\n"}, {"input": "3\r\naxa\r\naax\r\nxxa\r\n", "output": "NO\r\n"}, {"input": "3\r\nxox\r\noxx\r\nxox\r\n", "output": "NO\r\n"}, {"input": "3\r\nxox\r\nooo\r\nxox\r\n", "output": "NO\r\n"}, {"input": "3\r\naaa\r\naab\r\nbbb\r\n", "output": "NO\r\n"}, {"input": "3\r\nxxx\r\nsxs\r\nxsx\r\n", "output": "NO\r\n"}, {"input": "5\r\nabbba\r\nbabab\r\nbbbbb\r\nbaaab\r\nabbba\r\n", "output": "NO\r\n"}, {"input": "5\r\nabaaa\r\nbbbbb\r\nbbabb\r\nbabab\r\nabbba\r\n", "output": "NO\r\n"}, {"input": "5\r\nxoxox\r\noxoxo\r\nooxoo\r\noxoxo\r\nxooox\r\n", "output": "NO\r\n"}, {"input": "3\r\nxox\r\noxx\r\nxxx\r\n", "output": "NO\r\n"}, {"input": "5\r\nxoooo\r\noxooo\r\nooxoo\r\noooxo\r\noooox\r\n", "output": "NO\r\n"}, {"input": "5\r\nxoooo\r\noxoxx\r\nooxoo\r\noxoxo\r\noxoox\r\n", "output": "NO\r\n"}, {"input": "3\r\naaa\r\nbab\r\naba\r\n", "output": "NO\r\n"}]
| false |
stdio
| null | true |
837/C
|
837
|
C
|
Python 3
|
TESTS
| 22 | 62 | 4,608,000 |
29171390
|
n,a,b = map(int,input().split())
def fit(x1,y1,x2,y2):
if a>=x1 and b>=y1:
if (a-x1>=x2 and b>=y2) or (a-x1>=y2 and b>=x2) or (a>=x2 and b-y1>=y2) or (a>=y2 and b-y1>=x2):
return True
elif a>=y1 and b>=x1:
if (a-y1>=x2 and b>=y2) or (a-y1>=y2 and b>=x2) or (a>=x2 and b-x1>=y2) or (a>=y2 and b-x1>=x2):
return True
return False
data=[ tuple(map(int,input().split())) for _ in range(n)]
m=0
for i in range(n):
for j in range(i+1,n):
x1,y1=data[i]
x2,y2=data[j]
if x1*y1+x2*y2>m and fit(x1,y1,x2,y2):
m=x1*y1+x2*y2
print(m)
| 51 | 62 | 4,915,200 |
29173478
|
import sys, math
n, a, b = map(int, input().split())
x=[0 for i in range(n)]
y=[0 for i in range(n)]
for i in range(n):
u,v = map(int, input().split())
x[i]=u
y[i]=v
m=0
for i in range(n):
for j in range (n):
if i!=j:
if (x[i]+x[j]<=a and max(y[i],y[j])<=b) or (x[i]+y[j]<=a and max(y[i],x[j])<=b) or (y[i]+x[j]<=a and max(x[i],y[j])<=b) or (y[i]+y[j]<=a and max(x[i],x[j])<=b) or (x[i] + x[j] <= b and max(y[i], y[j]) <= a) or (x[i] + y[j] <= b and max(y[i], x[j]) <= a) or (y[i] + x[j] <= b and max(x[i], y[j]) <= a) or (y[i] + y[j] <= b and max(x[i], x[j]) <= a):
if m<x[i]*y[i]+x[j]*y[j]: m=x[i]*y[i]+x[j]*y[j]
print(m)
|
Educational Codeforces Round 26
|
ICPC
| 2,017 | 1 | 256 |
Two Seals
|
One very important person has a piece of paper in the form of a rectangle a × b.
Also, he has n seals. Each seal leaves an impression on the paper in the form of a rectangle of the size xi × yi. Each impression must be parallel to the sides of the piece of paper (but seal can be rotated by 90 degrees).
A very important person wants to choose two different seals and put them two impressions. Each of the selected seals puts exactly one impression. Impressions should not overlap (but they can touch sides), and the total area occupied by them should be the largest possible. What is the largest area that can be occupied by two seals?
|
The first line contains three integer numbers n, a and b (1 ≤ n, a, b ≤ 100).
Each of the next n lines contain two numbers xi, yi (1 ≤ xi, yi ≤ 100).
|
Print the largest total area that can be occupied by two seals. If you can not select two seals, print 0.
| null |
In the first example you can rotate the second seal by 90 degrees. Then put impression of it right under the impression of the first seal. This will occupy all the piece of paper.
In the second example you can't choose the last seal because it doesn't fit. By choosing the first and the third seals you occupy the largest area.
In the third example there is no such pair of seals that they both can fit on a piece of paper.
|
[{"input": "2 2 2\n1 2\n2 1", "output": "4"}, {"input": "4 10 9\n2 3\n1 1\n5 10\n9 11", "output": "56"}, {"input": "3 10 10\n6 6\n7 7\n20 5", "output": "0"}]
| 1,500 |
["brute force", "implementation"]
| 51 |
[{"input": "2 2 2\r\n1 2\r\n2 1\r\n", "output": "4\r\n"}, {"input": "4 10 9\r\n2 3\r\n1 1\r\n5 10\r\n9 11\r\n", "output": "56\r\n"}, {"input": "3 10 10\r\n6 6\r\n7 7\r\n20 5\r\n", "output": "0\r\n"}, {"input": "2 1 1\r\n1 1\r\n1 1\r\n", "output": "0\r\n"}, {"input": "2 1 2\r\n1 1\r\n1 1\r\n", "output": "2\r\n"}, {"input": "2 100 100\r\n100 100\r\n1 1\r\n", "output": "0\r\n"}, {"input": "2 100 100\r\n50 100\r\n100 50\r\n", "output": "10000\r\n"}, {"input": "2 100 100\r\n100 100\r\n87 72\r\n", "output": "0\r\n"}, {"input": "5 100 100\r\n100 100\r\n100 100\r\n100 100\r\n100 100\r\n100 100\r\n", "output": "0\r\n"}, {"input": "15 50 50\r\n9 36\r\n28 14\r\n77 74\r\n35 2\r\n20 32\r\n83 85\r\n47 3\r\n41 50\r\n21 7\r\n38 46\r\n17 6\r\n79 90\r\n91 83\r\n9 33\r\n24 11\r\n", "output": "2374\r\n"}, {"input": "15 100 100\r\n100 100\r\n100 100\r\n100 100\r\n42 58\r\n80 22\r\n100 100\r\n100 100\r\n100 100\r\n100 100\r\n100 100\r\n48 42\r\n100 100\r\n100 100\r\n100 100\r\n100 100\r\n", "output": "4452\r\n"}, {"input": "30 100 100\r\n60 34\r\n29 82\r\n89 77\r\n39 1\r\n100 100\r\n82 12\r\n57 87\r\n93 43\r\n78 50\r\n38 55\r\n37 9\r\n67 5\r\n100 100\r\n100 100\r\n82 47\r\n3 71\r\n100 100\r\n19 26\r\n25 94\r\n89 5\r\n100 100\r\n32 1\r\n100 100\r\n34 3\r\n40 99\r\n100 100\r\n36 12\r\n100 100\r\n100 100\r\n100 100\r\n", "output": "8958\r\n"}, {"input": "3 100 1\r\n1 50\r\n1 60\r\n1 30\r\n", "output": "90\r\n"}, {"input": "3 1 60\r\n1 40\r\n2 2\r\n20 1\r\n", "output": "60\r\n"}, {"input": "4 1 100\r\n1 25\r\n25 1\r\n1 25\r\n2 100\r\n", "output": "50\r\n"}, {"input": "1 100 50\r\n4 20\r\n", "output": "0\r\n"}, {"input": "2 2 4\r\n3 1\r\n2 2\r\n", "output": "0\r\n"}, {"input": "2 2 4\r\n2 3\r\n2 1\r\n", "output": "8\r\n"}, {"input": "2 4 2\r\n1 2\r\n2 3\r\n", "output": "8\r\n"}, {"input": "2 1 4\r\n1 2\r\n1 2\r\n", "output": "4\r\n"}, {"input": "2 4 5\r\n2 4\r\n4 3\r\n", "output": "20\r\n"}, {"input": "2 1 4\r\n1 1\r\n3 3\r\n", "output": "0\r\n"}, {"input": "6 9 5\r\n4 5\r\n6 2\r\n1 4\r\n5 6\r\n3 7\r\n6 5\r\n", "output": "34\r\n"}, {"input": "6 8 5\r\n4 1\r\n3 3\r\n5 3\r\n6 7\r\n2 2\r\n5 4\r\n", "output": "35\r\n"}, {"input": "6 7 5\r\n6 4\r\n5 7\r\n4 7\r\n5 4\r\n1 1\r\n3 6\r\n", "output": "29\r\n"}, {"input": "6 9 7\r\n1 2\r\n1 5\r\n4 3\r\n4 7\r\n3 5\r\n6 7\r\n", "output": "57\r\n"}, {"input": "6 5 9\r\n2 3\r\n7 4\r\n1 5\r\n1 7\r\n2 5\r\n7 1\r\n", "output": "38\r\n"}, {"input": "2 4 2\r\n2 2\r\n1 3\r\n", "output": "0\r\n"}, {"input": "2 3 2\r\n3 2\r\n1 1\r\n", "output": "0\r\n"}, {"input": "6 7 5\r\n6 6\r\n4 7\r\n6 1\r\n4 1\r\n4 6\r\n1 5\r\n", "output": "34\r\n"}, {"input": "2 2 3\r\n1 2\r\n2 3\r\n", "output": "0\r\n"}, {"input": "2 2 2\r\n2 1\r\n1 1\r\n", "output": "3\r\n"}, {"input": "5 9 7\r\n6 7\r\n4 5\r\n2 7\r\n4 2\r\n5 8\r\n", "output": "56\r\n"}, {"input": "2 11 51\r\n1 10\r\n11 50\r\n", "output": "560\r\n"}, {"input": "5 9 7\r\n3 8\r\n7 6\r\n4 1\r\n5 8\r\n7 8\r\n", "output": "60\r\n"}, {"input": "2 4 6\r\n4 4\r\n4 2\r\n", "output": "24\r\n"}, {"input": "5 9 7\r\n1 6\r\n7 9\r\n1 5\r\n1 5\r\n7 3\r\n", "output": "27\r\n"}, {"input": "5 9 7\r\n5 2\r\n6 9\r\n1 4\r\n7 7\r\n6 4\r\n", "output": "59\r\n"}, {"input": "5 9 7\r\n6 7\r\n4 1\r\n1 2\r\n4 7\r\n5 6\r\n", "output": "58\r\n"}, {"input": "5 9 7\r\n2 8\r\n3 8\r\n2 8\r\n4 4\r\n2 2\r\n", "output": "40\r\n"}, {"input": "2 2 3\r\n1 4\r\n2 1\r\n", "output": "0\r\n"}, {"input": "5 9 7\r\n4 7\r\n3 9\r\n5 4\r\n3 4\r\n3 8\r\n", "output": "55\r\n"}, {"input": "5 9 7\r\n7 4\r\n6 9\r\n4 3\r\n7 5\r\n2 3\r\n", "output": "63\r\n"}, {"input": "2 2 3\r\n1 2\r\n2 2\r\n", "output": "6\r\n"}, {"input": "2 4 3\r\n2 1\r\n1 2\r\n", "output": "4\r\n"}, {"input": "2 4 6\r\n4 2\r\n4 4\r\n", "output": "24\r\n"}, {"input": "2 1 4\r\n3 2\r\n3 3\r\n", "output": "0\r\n"}]
| false |
stdio
| null | true |
404/A
|
404
|
A
|
PyPy 3
|
TESTS
| 31 | 155 | 1,945,600 |
91789842
|
t=[]
n=int(input())
for k in range(n):
a = list(input())
t.append(a)
u=[]
for j in range(n):
u.append(t[j][j])
t[j][j]='0'
i = n-1-j
if i!=j:
u.append(t[i][j])
t[i][j]='0'
if len(set(u))==1:
h=0
for j in t:
if u[0] not in j and len(set(j))==2:
pass
else:
print('NO')
h+=1
break
if h==0:
print('YES')
else:
print('NO')
| 47 | 46 | 0 |
155258387
|
import sys
input = sys.stdin.readline
n = int(input())
g = [input()[:-1] for _ in range(n)]
x = g[0][0]
y = g[0][1]
if x == y:
print("NO")
else:
w = []
for i in range(n-2, 0, -2):
s = (x + y*i + x).center(n,y)
w.append(s)
w.append(x.center(n,y))
for i in range(1, n, 2):
s = (x + y*i + x).center(n,y)
w.append(s)
for i in range(n):
if g[i] != w[i]:
print("NO")
break
else:
print("YES")
|
Codeforces Round 237 (Div. 2)
|
CF
| 2,014 | 1 | 256 |
Valera and X
|
Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the side equals n squares (n is an odd number) and each unit square contains some small letter of the English alphabet.
Valera needs to know if the letters written on the square piece of paper form letter "X". Valera's teacher thinks that the letters on the piece of paper form an "X", if:
- on both diagonals of the square paper all letters are the same;
- all other squares of the paper (they are not on the diagonals) contain the same letter that is different from the letters on the diagonals.
Help Valera, write the program that completes the described task for him.
|
The first line contains integer n (3 ≤ n < 300; n is odd). Each of the next n lines contains n small English letters — the description of Valera's paper.
|
Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes.
| null | null |
[{"input": "5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox", "output": "NO"}, {"input": "3\nwsw\nsws\nwsw", "output": "YES"}, {"input": "3\nxpx\npxp\nxpe", "output": "NO"}]
| 1,000 |
["implementation"]
| 47 |
[{"input": "5\r\nxooox\r\noxoxo\r\nsoxoo\r\noxoxo\r\nxooox\r\n", "output": "NO\r\n"}, {"input": "3\r\nwsw\r\nsws\r\nwsw\r\n", "output": "YES\r\n"}, {"input": "3\r\nxpx\r\npxp\r\nxpe\r\n", "output": "NO\r\n"}, {"input": "5\r\nliiil\r\nilili\r\niilii\r\nilili\r\nliiil\r\n", "output": "YES\r\n"}, {"input": "7\r\nbwccccb\r\nckcccbj\r\nccbcbcc\r\ncccbccc\r\nccbcbcc\r\ncbcccbc\r\nbccccdt\r\n", "output": "NO\r\n"}, {"input": "13\r\nsooooooooooos\r\nosoooooooooso\r\noosooooooosoo\r\nooosooooosooo\r\noooosooosoooo\r\nooooososooooo\r\noooooosoooooo\r\nooooososooooo\r\noooosooosoooo\r\nooosooooosooo\r\noosooooooosoo\r\nosoooooooooso\r\nsooooooooooos\r\n", "output": "YES\r\n"}, {"input": "3\r\naaa\r\naaa\r\naaa\r\n", "output": "NO\r\n"}, {"input": "3\r\naca\r\noec\r\nzba\r\n", "output": "NO\r\n"}, {"input": "15\r\nrxeeeeeeeeeeeer\r\nereeeeeeeeeeere\r\needeeeeeeeeeoee\r\neeereeeeeeeewee\r\neeeereeeeebeeee\r\nqeeeereeejedyee\r\neeeeeerereeeeee\r\neeeeeeereeeeeee\r\neeeeeerereeeeze\r\neeeeereeereeeee\r\neeeereeeeegeeee\r\neeereeeeeeereee\r\neereeeeeeqeeved\r\ncreeeeeeceeeere\r\nreeerneeeeeeeer\r\n", "output": "NO\r\n"}, {"input": "5\r\nxxxxx\r\nxxxxx\r\nxxxxx\r\nxxxxx\r\nxxxxx\r\n", "output": "NO\r\n"}, {"input": "5\r\nxxxxx\r\nxxxxx\r\nxoxxx\r\nxxxxx\r\nxxxxx\r\n", "output": "NO\r\n"}, {"input": "5\r\noxxxo\r\nxoxox\r\nxxxxx\r\nxoxox\r\noxxxo\r\n", "output": "NO\r\n"}, {"input": "5\r\noxxxo\r\nxoxox\r\nxxoox\r\nxoxox\r\noxxxo\r\n", "output": "NO\r\n"}, {"input": "5\r\noxxxo\r\nxoxox\r\nxxaxx\r\nxoxox\r\noxxxo\r\n", "output": "NO\r\n"}, {"input": "5\r\noxxxo\r\nxoxox\r\noxoxx\r\nxoxox\r\noxxxo\r\n", "output": "NO\r\n"}, {"input": "3\r\nxxx\r\naxa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\naxx\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\naxa\r\nxxx\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\nxxa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\naaa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\naax\r\naxa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxaa\r\naxa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\naxa\r\naax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\naxa\r\nxaa\r\n", "output": "NO\r\n"}, {"input": "3\r\nxfx\r\naxa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\nafa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\naxa\r\nxaf\r\n", "output": "NO\r\n"}, {"input": "3\r\nxox\r\nxxx\r\nxxx\r\n", "output": "NO\r\n"}, {"input": "3\r\naxa\r\naax\r\nxxa\r\n", "output": "NO\r\n"}, {"input": "3\r\nxox\r\noxx\r\nxox\r\n", "output": "NO\r\n"}, {"input": "3\r\nxox\r\nooo\r\nxox\r\n", "output": "NO\r\n"}, {"input": "3\r\naaa\r\naab\r\nbbb\r\n", "output": "NO\r\n"}, {"input": "3\r\nxxx\r\nsxs\r\nxsx\r\n", "output": "NO\r\n"}, {"input": "5\r\nabbba\r\nbabab\r\nbbbbb\r\nbaaab\r\nabbba\r\n", "output": "NO\r\n"}, {"input": "5\r\nabaaa\r\nbbbbb\r\nbbabb\r\nbabab\r\nabbba\r\n", "output": "NO\r\n"}, {"input": "5\r\nxoxox\r\noxoxo\r\nooxoo\r\noxoxo\r\nxooox\r\n", "output": "NO\r\n"}, {"input": "3\r\nxox\r\noxx\r\nxxx\r\n", "output": "NO\r\n"}, {"input": "5\r\nxoooo\r\noxooo\r\nooxoo\r\noooxo\r\noooox\r\n", "output": "NO\r\n"}, {"input": "5\r\nxoooo\r\noxoxx\r\nooxoo\r\noxoxo\r\noxoox\r\n", "output": "NO\r\n"}, {"input": "3\r\naaa\r\nbab\r\naba\r\n", "output": "NO\r\n"}]
| false |
stdio
| null | true |
404/A
|
404
|
A
|
Python 3
|
TESTS
| 31 | 46 | 307,200 |
161502179
|
def Diagonal1(paper):
x = 0
y = 0
while x < len(paper[0]) - 1:
if paper[x][y] != paper[x + 1][y + 1]:
return False
x += 1
y += 1
return True
def Diagonal2(paper, num):
x = len(paper[0]) - 1
y = 0
while x > 0:
if paper[x][y] != paper[x - 1][y + 1]:
return False
x -= 1
y += 1
flag = Verification(paper, num)
return flag
def Verification(paper, num):
sets = []
for t in paper:
sets.append(set(t))
for t in sets:
if len(t) != 2:
return False
sets = []
letters = set(paper[0])
for t in letters:
sets.append(t)
letter1 = 0
letter2 = 0
for t in paper:
letter1 += t.count(sets[0])
letter2 += t.count(sets[1])
if sets[0] == paper[0][0]:
if letter1 != (num*2) - 1:
return False
else:
if letter2 != (num*2) - 1:
return False
return True
def main():
from sys import stdin
num = int(stdin.readline().strip())
paper = []
for t in range(num):
row = list(stdin.readline().strip())
paper.append(row)
if Diagonal1(paper) == True and Diagonal2(paper, num) == True:
print("YES")
else:
print("NO")
main()
| 47 | 46 | 0 |
158060690
|
a=int(input())
s=""
for i in range(a):
s=s+input()
if s[::1]==s[::-1] and s.count(s[0])==(2*a)-1:
print('YES')
else:
print('NO')
|
Codeforces Round 237 (Div. 2)
|
CF
| 2,014 | 1 | 256 |
Valera and X
|
Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the side equals n squares (n is an odd number) and each unit square contains some small letter of the English alphabet.
Valera needs to know if the letters written on the square piece of paper form letter "X". Valera's teacher thinks that the letters on the piece of paper form an "X", if:
- on both diagonals of the square paper all letters are the same;
- all other squares of the paper (they are not on the diagonals) contain the same letter that is different from the letters on the diagonals.
Help Valera, write the program that completes the described task for him.
|
The first line contains integer n (3 ≤ n < 300; n is odd). Each of the next n lines contains n small English letters — the description of Valera's paper.
|
Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes.
| null | null |
[{"input": "5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox", "output": "NO"}, {"input": "3\nwsw\nsws\nwsw", "output": "YES"}, {"input": "3\nxpx\npxp\nxpe", "output": "NO"}]
| 1,000 |
["implementation"]
| 47 |
[{"input": "5\r\nxooox\r\noxoxo\r\nsoxoo\r\noxoxo\r\nxooox\r\n", "output": "NO\r\n"}, {"input": "3\r\nwsw\r\nsws\r\nwsw\r\n", "output": "YES\r\n"}, {"input": "3\r\nxpx\r\npxp\r\nxpe\r\n", "output": "NO\r\n"}, {"input": "5\r\nliiil\r\nilili\r\niilii\r\nilili\r\nliiil\r\n", "output": "YES\r\n"}, {"input": "7\r\nbwccccb\r\nckcccbj\r\nccbcbcc\r\ncccbccc\r\nccbcbcc\r\ncbcccbc\r\nbccccdt\r\n", "output": "NO\r\n"}, {"input": "13\r\nsooooooooooos\r\nosoooooooooso\r\noosooooooosoo\r\nooosooooosooo\r\noooosooosoooo\r\nooooososooooo\r\noooooosoooooo\r\nooooososooooo\r\noooosooosoooo\r\nooosooooosooo\r\noosooooooosoo\r\nosoooooooooso\r\nsooooooooooos\r\n", "output": "YES\r\n"}, {"input": "3\r\naaa\r\naaa\r\naaa\r\n", "output": "NO\r\n"}, {"input": "3\r\naca\r\noec\r\nzba\r\n", "output": "NO\r\n"}, {"input": "15\r\nrxeeeeeeeeeeeer\r\nereeeeeeeeeeere\r\needeeeeeeeeeoee\r\neeereeeeeeeewee\r\neeeereeeeebeeee\r\nqeeeereeejedyee\r\neeeeeerereeeeee\r\neeeeeeereeeeeee\r\neeeeeerereeeeze\r\neeeeereeereeeee\r\neeeereeeeegeeee\r\neeereeeeeeereee\r\neereeeeeeqeeved\r\ncreeeeeeceeeere\r\nreeerneeeeeeeer\r\n", "output": "NO\r\n"}, {"input": "5\r\nxxxxx\r\nxxxxx\r\nxxxxx\r\nxxxxx\r\nxxxxx\r\n", "output": "NO\r\n"}, {"input": "5\r\nxxxxx\r\nxxxxx\r\nxoxxx\r\nxxxxx\r\nxxxxx\r\n", "output": "NO\r\n"}, {"input": "5\r\noxxxo\r\nxoxox\r\nxxxxx\r\nxoxox\r\noxxxo\r\n", "output": "NO\r\n"}, {"input": "5\r\noxxxo\r\nxoxox\r\nxxoox\r\nxoxox\r\noxxxo\r\n", "output": "NO\r\n"}, {"input": "5\r\noxxxo\r\nxoxox\r\nxxaxx\r\nxoxox\r\noxxxo\r\n", "output": "NO\r\n"}, {"input": "5\r\noxxxo\r\nxoxox\r\noxoxx\r\nxoxox\r\noxxxo\r\n", "output": "NO\r\n"}, {"input": "3\r\nxxx\r\naxa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\naxx\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\naxa\r\nxxx\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\nxxa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\naaa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\naax\r\naxa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxaa\r\naxa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\naxa\r\naax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\naxa\r\nxaa\r\n", "output": "NO\r\n"}, {"input": "3\r\nxfx\r\naxa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\nafa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\naxa\r\nxaf\r\n", "output": "NO\r\n"}, {"input": "3\r\nxox\r\nxxx\r\nxxx\r\n", "output": "NO\r\n"}, {"input": "3\r\naxa\r\naax\r\nxxa\r\n", "output": "NO\r\n"}, {"input": "3\r\nxox\r\noxx\r\nxox\r\n", "output": "NO\r\n"}, {"input": "3\r\nxox\r\nooo\r\nxox\r\n", "output": "NO\r\n"}, {"input": "3\r\naaa\r\naab\r\nbbb\r\n", "output": "NO\r\n"}, {"input": "3\r\nxxx\r\nsxs\r\nxsx\r\n", "output": "NO\r\n"}, {"input": "5\r\nabbba\r\nbabab\r\nbbbbb\r\nbaaab\r\nabbba\r\n", "output": "NO\r\n"}, {"input": "5\r\nabaaa\r\nbbbbb\r\nbbabb\r\nbabab\r\nabbba\r\n", "output": "NO\r\n"}, {"input": "5\r\nxoxox\r\noxoxo\r\nooxoo\r\noxoxo\r\nxooox\r\n", "output": "NO\r\n"}, {"input": "3\r\nxox\r\noxx\r\nxxx\r\n", "output": "NO\r\n"}, {"input": "5\r\nxoooo\r\noxooo\r\nooxoo\r\noooxo\r\noooox\r\n", "output": "NO\r\n"}, {"input": "5\r\nxoooo\r\noxoxx\r\nooxoo\r\noxoxo\r\noxoox\r\n", "output": "NO\r\n"}, {"input": "3\r\naaa\r\nbab\r\naba\r\n", "output": "NO\r\n"}]
| false |
stdio
| null | true |
197/B
|
197
|
B
|
Python 3
|
TESTS
| 7 | 124 | 0 |
203414225
|
'''
Online Python Compiler.
Code, Compile, Run and Debug python program online.
Write your code in this editor and press "Run" button to execute it.
'''
import math
n,m=map(int,input().split())
l1=list(map(int,input().split()))
l2=list(map(int,input().split()))
if n==m:
num,den=l1[0],l2[0]
comdiv=math.gcd(abs(num),abs(den))
an,ad=str(int(abs(num)/comdiv)),str(int(abs(den)/comdiv))
if num*den<0:
print("-"+an+"/"+ad)
else:
print(an+"/"+ad)
elif n>m:
if l1[n-m-1]>0:
print("Infinity")
else:
print("-Infinity")
else:
print("0/1")
| 80 | 154 | 0 |
132206792
|
def gcd(a,b):
if b==0:
return a
return gcd(b,a%b)
n,m=map(int,input().split())
p=n-m
a=list(map(int,input().split()))
b=list(map(int,input().split()))
if p==0:
g=gcd(a[0],b[0])
print("%d/%d"%(a[0]/g,b[0]/g))
else:
if p<0:
print("0/1")
else:
if a[0]*b[0]>0:
print("Infinity")
else:
print("-Infinity")
|
Codeforces Round 124 (Div. 2)
|
CF
| 2,012 | 2 | 256 |
Limit
|
You are given two polynomials:
- P(x) = a0·xn + a1·xn - 1 + ... + an - 1·x + an and
- Q(x) = b0·xm + b1·xm - 1 + ... + bm - 1·x + bm.
Calculate limit $$\lim_{x \to +\infty} \frac{P(x)}{Q(x)}$$.
|
The first line contains two space-separated integers n and m (0 ≤ n, m ≤ 100) — degrees of polynomials P(x) and Q(x) correspondingly.
The second line contains n + 1 space-separated integers — the factors of polynomial P(x): a0, a1, ..., an - 1, an ( - 100 ≤ ai ≤ 100, a0 ≠ 0).
The third line contains m + 1 space-separated integers — the factors of polynomial Q(x): b0, b1, ..., bm - 1, bm ( - 100 ≤ bi ≤ 100, b0 ≠ 0).
|
If the limit equals + ∞, print "Infinity" (without quotes). If the limit equals - ∞, print "-Infinity" (without the quotes).
If the value of the limit equals zero, print "0/1" (without the quotes).
Otherwise, print an irreducible fraction — the value of limit $$\lim_{x \to +\infty} \frac{P(x)}{Q(x)}$$, in the format "p/q" (without the quotes), where p is the — numerator, q (q > 0) is the denominator of the fraction.
| null |
Let's consider all samples:
1. $$\lim_{x \to +\infty} \frac{x^2+x+1}{2x+5} = +\infty$$
2. $$\lim_{x \to +\infty} \frac{-x+3}{2} = -\infty$$
3. $$\lim_{x \to +\infty} \frac{1}{x} = 0$$
4. $$\lim_{x \to +\infty} \frac{2x^2+x+6}{4x^2+5x-7} = \frac{1}{2}$$
5. $$\lim_{x \to +\infty} \frac{9x}{-5x+2} = -\frac{9}{5}$$
You can learn more about the definition and properties of limits if you follow the link: http://en.wikipedia.org/wiki/Limit_of_a_function
|
[{"input": "2 1\n1 1 1\n2 5", "output": "Infinity"}, {"input": "1 0\n-1 3\n2", "output": "-Infinity"}, {"input": "0 1\n1\n1 0", "output": "0/1"}, {"input": "2 2\n2 1 6\n4 5 -7", "output": "1/2"}, {"input": "1 1\n9 0\n-5 2", "output": "-9/5"}]
| 1,400 |
["math"]
| 80 |
[{"input": "2 1\r\n1 1 1\r\n2 5\r\n", "output": "Infinity\r\n"}, {"input": "1 0\r\n-1 3\r\n2\r\n", "output": "-Infinity\r\n"}, {"input": "0 1\r\n1\r\n1 0\r\n", "output": "0/1\r\n"}, {"input": "2 2\r\n2 1 6\r\n4 5 -7\r\n", "output": "1/2\n"}, {"input": "1 1\r\n9 0\r\n-5 2\r\n", "output": "-9/5\n"}, {"input": "1 2\r\n5 3\r\n-3 2 -1\r\n", "output": "0/1\r\n"}, {"input": "1 2\r\n-4 8\r\n-2 5 -3\r\n", "output": "0/1\r\n"}, {"input": "3 2\r\n4 3 1 2\r\n-5 7 0\r\n", "output": "-Infinity\r\n"}, {"input": "2 1\r\n-3 5 1\r\n-8 0\r\n", "output": "Infinity\r\n"}, {"input": "1 1\r\n-5 7\r\n3 1\r\n", "output": "-5/3\n"}, {"input": "2 2\r\n-4 2 1\r\n-5 8 -19\r\n", "output": "4/5\n"}, {"input": "0 0\r\n36\r\n-54\r\n", "output": "-2/3\n"}, {"input": "0 0\r\n36\r\n-8\r\n", "output": "-9/2\n"}, {"input": "0 0\r\n-6\r\n-8\r\n", "output": "3/4\n"}, {"input": "0 2\r\n-3\r\n1 4 6\r\n", "output": "0/1\r\n"}, {"input": "0 0\r\n-21\r\n13\r\n", "output": "-21/13\n"}, {"input": "0 0\r\n-34\r\n21\r\n", "output": "-34/21\n"}, {"input": "0 0\r\n-55\r\n34\r\n", "output": "-55/34\n"}, {"input": "33 1\r\n-75 -83 87 -27 -48 47 -90 -84 -18 -4 14 -1 -83 -98 -68 -85 -86 28 2 45 96 -59 86 -25 -2 -64 -92 65 69 72 72 -58 -99 90\r\n-1 72\r\n", "output": "Infinity\r\n"}, {"input": "20 20\r\n5 4 91 -66 -57 55 -79 -2 -54 -72 -49 21 -23 -5 57 -48 70 -16 -86 -26 -19\r\n51 -60 64 -8 89 27 -96 4 95 -24 -2 -27 -41 -14 -88 -19 24 68 -31 34 -62\r\n", "output": "5/51\n"}, {"input": "0 0\r\n46\r\n-33\r\n", "output": "-46/33\n"}, {"input": "17 17\r\n-54 59 -95 87 3 -27 -30 49 -87 74 45 78 36 60 -95 41 -53 -70\r\n-27 16 -67 -24 10 -73 -41 12 -52 53 -73 -17 -56 -74 -33 -8 100 -39\r\n", "output": "2/1\n"}, {"input": "1 1\r\n36 -49\r\n-32 -40\r\n", "output": "-9/8\n"}, {"input": "1 1\r\n1 1\r\n1 1\r\n", "output": "1/1\n"}, {"input": "1 1\r\n-2 1\r\n4 1\r\n", "output": "-1/2\n"}, {"input": "0 0\r\n2\r\n1\r\n", "output": "2/1\n"}, {"input": "0 0\r\n4\r\n-3\r\n", "output": "-4/3\n"}, {"input": "0 0\r\n2\r\n2\r\n", "output": "1/1\n"}, {"input": "0 0\r\n17\r\n-10\r\n", "output": "-17/10\n"}, {"input": "0 0\r\n-1\r\n2\r\n", "output": "-1/2\n"}, {"input": "0 0\r\n1\r\n1\r\n", "output": "1/1\n"}, {"input": "0 0\r\n50\r\n20\r\n", "output": "5/2\n"}, {"input": "0 0\r\n20\r\n20\r\n", "output": "1/1\n"}, {"input": "0 0\r\n4\r\n-2\r\n", "output": "-2/1\n"}, {"input": "0 0\r\n4\r\n-6\r\n", "output": "-2/3\n"}, {"input": "0 0\r\n1\r\n-2\r\n", "output": "-1/2\n"}, {"input": "0 0\r\n4\r\n2\r\n", "output": "2/1\n"}, {"input": "0 0\r\n2\r\n-4\r\n", "output": "-1/2\n"}, {"input": "1 1\r\n4 1\r\n2 1\r\n", "output": "2/1\n"}, {"input": "2 2\r\n-13 1 3\r\n6 3 2\r\n", "output": "-13/6\n"}, {"input": "0 0\r\n5\r\n5\r\n", "output": "1/1\n"}, {"input": "0 0\r\n2\r\n-1\r\n", "output": "-2/1\n"}]
| false |
stdio
| null | true |
592/D
|
592
|
D
|
PyPy 3
|
TESTS
| 88 | 1,278 | 29,798,400 |
98083507
|
from heapq import *
INF = float('inf')
n, m = map(int, input().split())
adj = [[] for _ in range(n+1)]
wg = [0 for _ in range(n+1)]
for _ in range(n-1):
a, b = map(int, input().split())
adj[a].append(b)
adj[b].append(a)
aaa = set(map(int, input().split()))
rm = []
ng = [0] * (n+1)
for i in range(n+1):
ng[i] = len(adj[i])
if i not in aaa and ng[i] == 1: rm.append(i)
for a in aaa: ng[a] = 0
def remove_node(index):
while adj[index]:
nx = adj[index].pop()
adj[nx].remove(index)
ng[nx] -= 1
if ng[nx] == 1:
rm.append(nx)
ng[index] = 0
while rm:
remove_node(rm.pop())
state = [0 for _ in range(n+1)]
que = [(min(aaa), None)]
res = 0
for _ in range(2):
deep = [0 for _ in range(n + 1)]
while que:
res += 1
root, proot = que.pop()
for nx in adj[root]:
if proot == nx:
continue
if _: state[nx] = root
deep[nx] = deep[root] + 1
que.append((nx, root))
if _: break
start = max(1, deep.index(max(deep)))
que = [(start, None)]
end = max(1, deep.index(max(deep)))
i = end
path = 1
while i != start:
path += 1
i = state[i]
print(min(start,end))
print(res -1 - path)
| 89 | 280 | 21,094,400 |
204355691
|
import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def make_graph(n, m):
x, s = [0] * (2 * m), [0] * (n + 3)
for i in range(0, 2 * m, 2):
u, v = map(int, input().split())
s[u + 2] += 1
s[v + 2] += 1
x[i], x[i + 1] = u, v
for i in range(3, n + 3):
s[i] += s[i - 1]
G = [0] * (2 * m)
for i in range(2 * m):
j = x[i] + 1
G[s[j]] = x[i ^ 1]
s[j] += 1
return G, s
def bfs(s):
q, k = list(s), 0
dist = [inf] * (n + 1)
for i in s:
dist[i] = 0
parent = [-1] * (n + 1)
while len(q) ^ k:
i = q[k]
di = dist[i]
for v in range(s0[i], s0[i + 1]):
j = G[v]
if not ng[j] and dist[j] == inf:
q.append(j)
dist[j] = di + 1
parent[j] = i
k += 1
return q, dist, parent
n, m = map(int, input().split())
G, s0 = make_graph(n, n - 1)
x = list(map(int, input().split()))
y = [0] * (n + 1)
for i in x:
y[i] = 1
ng = [0] * (n + 1)
q, k = [], 0
cnt = [s0[i + 1] - s0[i] for i in range(n + 1)]
for i in range(1, n + 1):
if cnt[i] == 1 and not y[i]:
q.append(i)
ng[i] = 1
while len(q) ^ k:
i = q[k]
for v in range(s0[i], s0[i + 1]):
j = G[v]
cnt[j] -= 1
if cnt[j] == 1 and not y[j]:
q.append(j)
ng[j] = 1
k += 1
inf = pow(10, 9) + 1
q, _, _ = bfs([x[0]])
q, dist, parent = bfs([q[-1]])
u = q[-1]
m = dist[u]
for _ in range(m // 2):
u = parent[u]
_, dist, _ = bfs([u]) if not m % 2 else bfs([u, parent[u]])
ans = []
for i in range(1, n + 1):
if dist[i] == m // 2:
ans.append(i)
break
ans.append(2 * len(q) - m - 2)
sys.stdout.write("\n".join(map(str, ans)))
|
Codeforces Round 328 (Div. 2)
|
CF
| 2,015 | 2 | 256 |
Super M
|
Ari the monster is not an ordinary monster. She is the hidden identity of Super M, the Byteforces’ superhero. Byteforces is a country that consists of n cities, connected by n - 1 bidirectional roads. Every road connects exactly two distinct cities, and the whole road system is designed in a way that one is able to go from any city to any other city using only the given roads. There are m cities being attacked by humans. So Ari... we meant Super M have to immediately go to each of the cities being attacked to scare those bad humans. Super M can pass from one city to another only using the given roads. Moreover, passing through one road takes her exactly one kron - the time unit used in Byteforces.
However, Super M is not on Byteforces now - she is attending a training camp located in a nearby country Codeforces. Fortunately, there is a special device in Codeforces that allows her to instantly teleport from Codeforces to any city of Byteforces. The way back is too long, so for the purpose of this problem teleportation is used exactly once.
You are to help Super M, by calculating the city in which she should teleport at the beginning in order to end her job in the minimum time (measured in krons). Also, provide her with this time so she can plan her way back to Codeforces.
|
The first line of the input contains two integers n and m (1 ≤ m ≤ n ≤ 123456) - the number of cities in Byteforces, and the number of cities being attacked respectively.
Then follow n - 1 lines, describing the road system. Each line contains two city numbers ui and vi (1 ≤ ui, vi ≤ n) - the ends of the road i.
The last line contains m distinct integers - numbers of cities being attacked. These numbers are given in no particular order.
|
First print the number of the city Super M should teleport to. If there are many possible optimal answers, print the one with the lowest city number.
Then print the minimum possible time needed to scare all humans in cities being attacked, measured in Krons.
Note that the correct answer is always unique.
| null |
In the first sample, there are two possibilities to finish the Super M's job in 3 krons. They are:
$$2 \rightarrow 1 \rightarrow 3 \rightarrow 7$$ and $$7 \rightarrow 3 \rightarrow 1 \rightarrow 2$$.
However, you should choose the first one as it starts in the city with the lower number.
|
[{"input": "7 2\n1 2\n1 3\n1 4\n3 5\n3 6\n3 7\n2 7", "output": "2\n3"}, {"input": "6 4\n1 2\n2 3\n2 4\n4 5\n4 6\n2 4 5 6", "output": "2\n4"}]
| 2,200 |
["dfs and similar", "dp", "graphs", "trees"]
| 89 |
[{"input": "7 2\r\n1 2\r\n1 3\r\n1 4\r\n3 5\r\n3 6\r\n3 7\r\n2 7\r\n", "output": "2\r\n3\r\n"}, {"input": "6 4\r\n1 2\r\n2 3\r\n2 4\r\n4 5\r\n4 6\r\n2 4 5 6\r\n", "output": "2\r\n4\r\n"}, {"input": "2 1\r\n2 1\r\n1\r\n", "output": "1\r\n0\r\n"}, {"input": "1 1\r\n1\r\n", "output": "1\r\n0\r\n"}, {"input": "10 2\r\n6 9\r\n6 2\r\n1 6\r\n4 10\r\n3 7\r\n9 4\r\n9 5\r\n6 7\r\n2 8\r\n7 6\r\n", "output": "6\r\n1\r\n"}, {"input": "15 2\r\n7 12\r\n13 11\r\n6 8\r\n2 15\r\n10 9\r\n5 1\r\n13 5\r\n5 4\r\n14 3\r\n8 9\r\n8 4\r\n4 7\r\n12 14\r\n5 2\r\n7 4\r\n", "output": "4\r\n1\r\n"}, {"input": "20 2\r\n1 16\r\n12 5\r\n15 19\r\n18 9\r\n8 4\r\n10 16\r\n9 16\r\n20 15\r\n14 19\r\n7 4\r\n18 12\r\n17 12\r\n2 20\r\n6 14\r\n3 19\r\n7 19\r\n18 15\r\n19 13\r\n9 11\r\n12 18\r\n", "output": "12\r\n1\r\n"}, {"input": "4 2\r\n4 3\r\n3 1\r\n1 2\r\n3 4\r\n", "output": "3\r\n1\r\n"}, {"input": "8 5\r\n2 5\r\n1 8\r\n6 7\r\n3 4\r\n6 8\r\n8 5\r\n5 3\r\n1 6 7 3 8\r\n", "output": "3\r\n6\r\n"}, {"input": "16 8\r\n16 12\r\n16 15\r\n15 9\r\n15 13\r\n16 3\r\n15 2\r\n15 10\r\n1 2\r\n6 16\r\n5 15\r\n2 7\r\n15 4\r\n14 15\r\n11 16\r\n8 5\r\n5 10 14 6 8 3 1 9\r\n", "output": "1\r\n16\r\n"}, {"input": "32 28\r\n30 12\r\n30 27\r\n24 32\r\n6 13\r\n11 5\r\n4 30\r\n8 28\r\n9 20\r\n8 20\r\n7 20\r\n5 30\r\n18 5\r\n20 14\r\n23 20\r\n17 20\r\n8 26\r\n20 1\r\n15 2\r\n20 13\r\n24 20\r\n22 24\r\n25 16\r\n2 3\r\n19 5\r\n16 10\r\n31 2\r\n29 5\r\n20 16\r\n2 20\r\n5 21\r\n5 20\r\n32 11 6 12 22 30 23 21 14 13 1 20 7 25 9 29 10 27 5 19 24 31 15 26 8 3 28 17\r\n", "output": "3\r\n53\r\n"}, {"input": "10 3\r\n10 5\r\n3 2\r\n6 8\r\n1 5\r\n10 4\r\n6 1\r\n9 8\r\n2 9\r\n7 3\r\n3 9 1\r\n", "output": "1\r\n5\r\n"}, {"input": "7 5\r\n6 4\r\n5 6\r\n6 7\r\n2 3\r\n5 2\r\n2 1\r\n4 6 1 7 3\r\n", "output": "1\r\n8\r\n"}, {"input": "15 7\r\n5 4\r\n12 5\r\n7 13\r\n10 11\r\n3 8\r\n6 12\r\n3 15\r\n1 3\r\n5 14\r\n7 9\r\n1 10\r\n6 1\r\n12 7\r\n10 2\r\n4 10 8 13 1 7 9\r\n", "output": "4\r\n14\r\n"}, {"input": "31 16\r\n3 25\r\n8 1\r\n1 9\r\n1 23\r\n16 15\r\n10 6\r\n25 30\r\n20 29\r\n2 24\r\n3 7\r\n19 22\r\n2 12\r\n16 4\r\n7 26\r\n31 10\r\n17 13\r\n25 21\r\n7 18\r\n28 2\r\n6 27\r\n19 5\r\n13 3\r\n17 31\r\n10 16\r\n20 14\r\n8 19\r\n6 11\r\n28 20\r\n13 28\r\n31 8\r\n31 27 25 20 26 8 28 15 18 17 10 23 4 16 30 22\r\n", "output": "4\r\n34\r\n"}, {"input": "63 20\r\n35 26\r\n54 5\r\n32 56\r\n56 53\r\n59 46\r\n37 31\r\n46 8\r\n4 1\r\n2 47\r\n59 42\r\n55 11\r\n62 6\r\n30 7\r\n60 24\r\n41 36\r\n34 22\r\n24 34\r\n21 2\r\n12 52\r\n8 44\r\n60 21\r\n24 30\r\n48 35\r\n48 25\r\n32 57\r\n20 37\r\n11 54\r\n11 62\r\n42 58\r\n31 43\r\n12 23\r\n55 48\r\n51 55\r\n41 27\r\n25 33\r\n21 18\r\n42 12\r\n4 15\r\n51 60\r\n62 39\r\n46 41\r\n57 9\r\n30 61\r\n31 4\r\n58 13\r\n34 29\r\n37 32\r\n18 16\r\n57 45\r\n2 49\r\n40 51\r\n43 17\r\n40 20\r\n20 59\r\n8 19\r\n58 10\r\n43 63\r\n54 50\r\n18 14\r\n25 38\r\n56 28\r\n35 3\r\n41 36 18 28 54 22 20 6 23 38 33 52 48 44 29 56 63 4 27 50\r\n", "output": "6\r\n66\r\n"}, {"input": "4 2\r\n2 3\r\n2 1\r\n2 4\r\n3 4\r\n", "output": "3\r\n2\r\n"}, {"input": "13 11\r\n4 11\r\n2 7\r\n4 13\r\n8 12\r\n8 9\r\n8 6\r\n3 8\r\n4 1\r\n2 10\r\n2 5\r\n3 4\r\n3 2\r\n10 4 5 6 1 2 3 9 13 7 12\r\n", "output": "1\r\n18\r\n"}, {"input": "7 5\r\n1 5\r\n4 1\r\n1 3\r\n7 1\r\n1 6\r\n1 2\r\n2 4 1 3 7\r\n", "output": "2\r\n6\r\n"}, {"input": "12 9\r\n11 12\r\n1 10\r\n1 7\r\n5 6\r\n8 7\r\n9 8\r\n4 5\r\n1 4\r\n2 3\r\n1 2\r\n10 11\r\n4 9 11 3 5 12 8 6 7\r\n", "output": "6\r\n16\r\n"}, {"input": "56 34\r\n7 31\r\n47 6\r\n13 4\r\n51 29\r\n13 12\r\n10 52\r\n10 41\r\n1 47\r\n47 54\r\n9 1\r\n4 27\r\n4 40\r\n49 19\r\n21 26\r\n24 33\r\n56 49\r\n41 56\r\n7 23\r\n41 48\r\n16 34\r\n35 9\r\n56 51\r\n5 43\r\n44 46\r\n10 25\r\n49 2\r\n1 21\r\n9 32\r\n33 20\r\n16 5\r\n5 35\r\n55 50\r\n55 53\r\n37 44\r\n43 15\r\n4 55\r\n8 10\r\n8 24\r\n21 42\r\n37 8\r\n39 13\r\n49 38\r\n39 16\r\n50 3\r\n55 7\r\n51 45\r\n21 11\r\n51 28\r\n50 18\r\n50 30\r\n5 37\r\n7 17\r\n35 22\r\n47 36\r\n35 14\r\n3 38 47 22 34 10 54 50 9 52 36 1 21 29 28 6 13 39 4 40 53 51 35 55 45 18 44 20 42 31 11 46 41 12\r\n", "output": "3\r\n70\r\n"}, {"input": "26 22\r\n20 16\r\n2 7\r\n7 19\r\n5 9\r\n20 23\r\n22 18\r\n24 3\r\n8 22\r\n16 10\r\n5 2\r\n7 15\r\n22 14\r\n25 4\r\n25 11\r\n24 13\r\n8 24\r\n13 1\r\n20 8\r\n22 6\r\n7 26\r\n16 12\r\n16 5\r\n13 21\r\n25 17\r\n2 25\r\n16 4 7 24 10 12 2 23 20 1 26 14 8 9 3 6 21 13 11 18 22 17\r\n", "output": "1\r\n37\r\n"}, {"input": "43 13\r\n7 28\r\n17 27\r\n39 8\r\n21 3\r\n17 20\r\n17 2\r\n9 6\r\n35 23\r\n43 22\r\n7 41\r\n5 24\r\n26 11\r\n21 43\r\n41 17\r\n16 5\r\n25 15\r\n39 10\r\n18 7\r\n37 33\r\n39 13\r\n39 16\r\n10 12\r\n1 21\r\n2 25\r\n14 36\r\n12 7\r\n16 34\r\n24 4\r\n25 40\r\n5 29\r\n37 31\r\n3 32\r\n22 14\r\n16 35\r\n5 37\r\n10 38\r\n25 19\r\n9 1\r\n26 42\r\n43 26\r\n10 30\r\n33 9\r\n28 6 42 38 27 32 8 11 36 7 41 29 19\r\n", "output": "19\r\n41\r\n"}, {"input": "21 20\r\n16 9\r\n7 11\r\n4 12\r\n2 17\r\n17 7\r\n5 2\r\n2 8\r\n4 10\r\n8 19\r\n6 15\r\n2 6\r\n12 18\r\n16 5\r\n20 16\r\n6 14\r\n5 3\r\n5 21\r\n20 1\r\n17 13\r\n6 4\r\n6 4 18 11 14 1 19 15 10 8 9 17 16 3 20 13 2 5 12 21\r\n", "output": "1\r\n32\r\n"}, {"input": "29 6\r\n16 9\r\n20 13\r\n24 3\r\n24 28\r\n22 12\r\n10 11\r\n10 26\r\n22 4\r\n10 27\r\n5 1\r\n2 23\r\n23 5\r\n16 7\r\n8 24\r\n7 19\r\n19 17\r\n8 10\r\n20 16\r\n20 25\r\n24 20\r\n23 15\r\n22 29\r\n2 8\r\n7 22\r\n2 21\r\n23 14\r\n19 18\r\n19 6\r\n19 17 18 27 29 4\r\n", "output": "4\r\n16\r\n"}, {"input": "31 29\r\n10 14\r\n16 6\r\n23 22\r\n25 23\r\n2 27\r\n24 17\r\n20 8\r\n5 2\r\n8 24\r\n16 5\r\n10 26\r\n8 7\r\n5 29\r\n20 16\r\n13 9\r\n13 21\r\n24 30\r\n13 1\r\n10 15\r\n23 3\r\n25 10\r\n2 25\r\n20 13\r\n25 11\r\n8 12\r\n30 28\r\n20 18\r\n5 4\r\n23 19\r\n16 31\r\n13 14 3 30 5 6 26 22 25 1 23 7 31 12 16 28 17 2 8 18 24 4 20 21 15 11 9 29 10\r\n", "output": "3\r\n46\r\n"}, {"input": "54 8\r\n33 9\r\n39 36\r\n22 14\r\n24 13\r\n8 50\r\n34 52\r\n47 2\r\n35 44\r\n16 54\r\n34 25\r\n1 3\r\n39 11\r\n9 17\r\n43 19\r\n10 40\r\n47 38\r\n5 37\r\n21 47\r\n37 12\r\n16 6\r\n37 7\r\n32 26\r\n39 42\r\n44 10\r\n1 18\r\n37 8\r\n9 1\r\n8 24\r\n10 33\r\n33 53\r\n5 4\r\n21 30\r\n9 31\r\n24 28\r\n24 49\r\n16 5\r\n34 35\r\n21 48\r\n47 43\r\n13 34\r\n39 16\r\n10 27\r\n22 32\r\n43 22\r\n13 46\r\n33 23\r\n44 15\r\n1 21\r\n8 41\r\n43 45\r\n5 29\r\n35 20\r\n13 51\r\n40 50 33 14 48 25 44 9\r\n", "output": "14\r\n21\r\n"}, {"input": "17 12\r\n5 2\r\n4 3\r\n8 17\r\n2 4\r\n2 8\r\n17 12\r\n8 10\r\n6 11\r\n16 7\r\n4 14\r\n15 13\r\n6 9\r\n4 6\r\n15 16\r\n16 5\r\n9 1\r\n4 8 1 9 3 12 15 10 13 6 14 16\r\n", "output": "1\r\n20\r\n"}, {"input": "28 6\r\n25 21\r\n9 18\r\n25 1\r\n16 5\r\n9 11\r\n28 19\r\n5 2\r\n20 16\r\n20 13\r\n2 23\r\n5 25\r\n8 24\r\n14 27\r\n3 15\r\n24 28\r\n8 10\r\n22 14\r\n14 17\r\n13 9\r\n3 22\r\n22 26\r\n16 7\r\n2 8\r\n25 3\r\n3 12\r\n14 4\r\n9 6\r\n28 27 22 24 20 16\r\n", "output": "27\r\n13\r\n"}, {"input": "10 9\r\n3 9\r\n4 8\r\n10 1\r\n2 3\r\n5 6\r\n4 3\r\n1 2\r\n5 4\r\n6 7\r\n9 1 5 8 7 3 4 6 10\r\n", "output": "7\r\n11\r\n"}, {"input": "9 6\r\n1 6\r\n3 4\r\n9 7\r\n3 2\r\n8 7\r\n2 1\r\n6 7\r\n3 5\r\n2 5 1 6 3 9\r\n", "output": "5\r\n6\r\n"}, {"input": "19 11\r\n8 9\r\n10 13\r\n16 15\r\n6 4\r\n3 2\r\n17 16\r\n4 7\r\n1 14\r\n10 11\r\n15 14\r\n4 3\r\n10 12\r\n4 5\r\n2 1\r\n16 19\r\n8 1\r\n10 9\r\n18 16\r\n10 14 18 12 17 11 19 8 1 3 9\r\n", "output": "11\r\n18\r\n"}, {"input": "36 5\r\n36 33\r\n11 12\r\n14 12\r\n25 24\r\n27 26\r\n23 24\r\n20 19\r\n1 2\r\n3 2\r\n17 18\r\n33 34\r\n23 1\r\n32 31\r\n12 15\r\n25 26\r\n4 5\r\n5 8\r\n5 6\r\n26 29\r\n1 9\r\n35 33\r\n33 32\r\n16 1\r\n3 4\r\n31 30\r\n16 17\r\n19 21\r\n1 30\r\n7 5\r\n9 10\r\n13 12\r\n19 18\r\n10 11\r\n22 19\r\n28 26\r\n29 12 11 17 33\r\n", "output": "12\r\n21\r\n"}, {"input": "10 2\r\n5 1\r\n1 3\r\n3 4\r\n4 2\r\n5 10\r\n1 9\r\n3 8\r\n4 7\r\n2 6\r\n3 4\r\n", "output": "3\r\n1\r\n"}, {"input": "53 30\r\n41 42\r\n27 24\r\n13 11\r\n10 11\r\n32 33\r\n34 33\r\n37 40\r\n21 22\r\n21 20\r\n46 47\r\n2 1\r\n31 30\r\n29 30\r\n11 14\r\n42 43\r\n50 51\r\n34 35\r\n36 35\r\n24 23\r\n48 47\r\n41 1\r\n28 29\r\n45 44\r\n16 15\r\n5 4\r\n6 5\r\n18 19\r\n9 8\r\n37 38\r\n11 12\r\n39 37\r\n49 48\r\n50 49\r\n43 44\r\n50 53\r\n3 4\r\n50 52\r\n24 25\r\n7 6\r\n46 45\r\n2 3\r\n17 18\r\n31 32\r\n19 20\r\n7 8\r\n15 1\r\n36 37\r\n23 22\r\n9 10\r\n17 16\r\n24 26\r\n28 1\r\n38 52 41 35 53 43 3 29 36 4 23 20 46 5 40 30 49 25 16 48 17 27 21 9 45 44 15 13 14 2\r\n", "output": "13\r\n74\r\n"}, {"input": "10 4\r\n2 3\r\n4 2\r\n8 9\r\n6 5\r\n8 1\r\n5 1\r\n8 10\r\n7 5\r\n1 2\r\n4 10 2 5\r\n", "output": "4\r\n6\r\n"}, {"input": "10 5\r\n4 5\r\n9 1\r\n1 2\r\n7 1\r\n5 1\r\n10 1\r\n7 3\r\n6 3\r\n5 8\r\n5 2 7 10 1\r\n", "output": "2\r\n6\r\n"}, {"input": "10 4\r\n8 7\r\n7 6\r\n1 2\r\n3 2\r\n3 4\r\n6 5\r\n10 7\r\n7 9\r\n5 4\r\n9 5 10 4\r\n", "output": "4\r\n6\r\n"}, {"input": "5 4\r\n2 3\r\n2 1\r\n3 5\r\n4 3\r\n4 2 5 1\r\n", "output": "1\r\n5\r\n"}, {"input": "5 1\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n4\r\n", "output": "4\r\n0\r\n"}]
| false |
stdio
| null | true |
197/B
|
197
|
B
|
Python 3
|
TESTS
| 7 | 92 | 0 |
184176023
|
n,m = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
def computeGCD(x, y):
while(y):
x, y = y, x % y
return abs(x)
if n>m:
if A[0]>0:
print('Infinity')
else:
print('-Infinity')
elif n<m:
print('0/1')
else:
num = A[0]
den = B[0]
gcd = computeGCD(num,den)
num = num//gcd
den = den//gcd
s = (num//abs(num))*(den//abs(den))
if s>0:
print("{}/{}".format(abs(num),abs(den)))
else:
print("-{}/{}".format(abs(num),abs(den)))
| 80 | 154 | 135,270,400 |
177584015
|
from collections import defaultdict, deque
from functools import lru_cache
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
from random import randint
from fractions import Fraction as frac
import math
hpop = heappop
hpush = heappush
MOD = 10**9 + 7
def gcd(a,b):
if a < b: a,b = b,a
if b == 0: return a
return gcd(a%b,b)
#def calc(x,y,a,b)
def solution():
# zero / zero can never happend
n,m = map(int, input().split())
p = list(map(int, input().split()))[::-1]
q = list(map(int, input().split()))[::-1]
while p and p[-1] == 0:
p.pop()
while q and q[-1] == 0:
q.pop()
if len(p) == len(q):
up = p[-1]
down = q[-1]
sign = ("-" if up*down < 0 else "")
g = gcd(abs(up),abs(down))
up //= g
down //= g
return print(sign + str(abs(up))+"/"+str(abs(down)))
if len(p) < len(q):
return print("0/1")
if p[-1] * q[-1] < 0:
return print("-Infinity")
else:
return print("Infinity")
def test():
pass
def main():
#test()
t = 1
#t = int(input())
for _ in range(t):
solution()
import sys
import threading
sys.setrecursionlimit(1 << 30)
threading.stack_size(1 << 27)
thread = threading.Thread(target=main)
thread.start(); thread.join()
#main()
|
Codeforces Round 124 (Div. 2)
|
CF
| 2,012 | 2 | 256 |
Limit
|
You are given two polynomials:
- P(x) = a0·xn + a1·xn - 1 + ... + an - 1·x + an and
- Q(x) = b0·xm + b1·xm - 1 + ... + bm - 1·x + bm.
Calculate limit $$\lim_{x \to +\infty} \frac{P(x)}{Q(x)}$$.
|
The first line contains two space-separated integers n and m (0 ≤ n, m ≤ 100) — degrees of polynomials P(x) and Q(x) correspondingly.
The second line contains n + 1 space-separated integers — the factors of polynomial P(x): a0, a1, ..., an - 1, an ( - 100 ≤ ai ≤ 100, a0 ≠ 0).
The third line contains m + 1 space-separated integers — the factors of polynomial Q(x): b0, b1, ..., bm - 1, bm ( - 100 ≤ bi ≤ 100, b0 ≠ 0).
|
If the limit equals + ∞, print "Infinity" (without quotes). If the limit equals - ∞, print "-Infinity" (without the quotes).
If the value of the limit equals zero, print "0/1" (without the quotes).
Otherwise, print an irreducible fraction — the value of limit $$\lim_{x \to +\infty} \frac{P(x)}{Q(x)}$$, in the format "p/q" (without the quotes), where p is the — numerator, q (q > 0) is the denominator of the fraction.
| null |
Let's consider all samples:
1. $$\lim_{x \to +\infty} \frac{x^2+x+1}{2x+5} = +\infty$$
2. $$\lim_{x \to +\infty} \frac{-x+3}{2} = -\infty$$
3. $$\lim_{x \to +\infty} \frac{1}{x} = 0$$
4. $$\lim_{x \to +\infty} \frac{2x^2+x+6}{4x^2+5x-7} = \frac{1}{2}$$
5. $$\lim_{x \to +\infty} \frac{9x}{-5x+2} = -\frac{9}{5}$$
You can learn more about the definition and properties of limits if you follow the link: http://en.wikipedia.org/wiki/Limit_of_a_function
|
[{"input": "2 1\n1 1 1\n2 5", "output": "Infinity"}, {"input": "1 0\n-1 3\n2", "output": "-Infinity"}, {"input": "0 1\n1\n1 0", "output": "0/1"}, {"input": "2 2\n2 1 6\n4 5 -7", "output": "1/2"}, {"input": "1 1\n9 0\n-5 2", "output": "-9/5"}]
| 1,400 |
["math"]
| 80 |
[{"input": "2 1\r\n1 1 1\r\n2 5\r\n", "output": "Infinity\r\n"}, {"input": "1 0\r\n-1 3\r\n2\r\n", "output": "-Infinity\r\n"}, {"input": "0 1\r\n1\r\n1 0\r\n", "output": "0/1\r\n"}, {"input": "2 2\r\n2 1 6\r\n4 5 -7\r\n", "output": "1/2\n"}, {"input": "1 1\r\n9 0\r\n-5 2\r\n", "output": "-9/5\n"}, {"input": "1 2\r\n5 3\r\n-3 2 -1\r\n", "output": "0/1\r\n"}, {"input": "1 2\r\n-4 8\r\n-2 5 -3\r\n", "output": "0/1\r\n"}, {"input": "3 2\r\n4 3 1 2\r\n-5 7 0\r\n", "output": "-Infinity\r\n"}, {"input": "2 1\r\n-3 5 1\r\n-8 0\r\n", "output": "Infinity\r\n"}, {"input": "1 1\r\n-5 7\r\n3 1\r\n", "output": "-5/3\n"}, {"input": "2 2\r\n-4 2 1\r\n-5 8 -19\r\n", "output": "4/5\n"}, {"input": "0 0\r\n36\r\n-54\r\n", "output": "-2/3\n"}, {"input": "0 0\r\n36\r\n-8\r\n", "output": "-9/2\n"}, {"input": "0 0\r\n-6\r\n-8\r\n", "output": "3/4\n"}, {"input": "0 2\r\n-3\r\n1 4 6\r\n", "output": "0/1\r\n"}, {"input": "0 0\r\n-21\r\n13\r\n", "output": "-21/13\n"}, {"input": "0 0\r\n-34\r\n21\r\n", "output": "-34/21\n"}, {"input": "0 0\r\n-55\r\n34\r\n", "output": "-55/34\n"}, {"input": "33 1\r\n-75 -83 87 -27 -48 47 -90 -84 -18 -4 14 -1 -83 -98 -68 -85 -86 28 2 45 96 -59 86 -25 -2 -64 -92 65 69 72 72 -58 -99 90\r\n-1 72\r\n", "output": "Infinity\r\n"}, {"input": "20 20\r\n5 4 91 -66 -57 55 -79 -2 -54 -72 -49 21 -23 -5 57 -48 70 -16 -86 -26 -19\r\n51 -60 64 -8 89 27 -96 4 95 -24 -2 -27 -41 -14 -88 -19 24 68 -31 34 -62\r\n", "output": "5/51\n"}, {"input": "0 0\r\n46\r\n-33\r\n", "output": "-46/33\n"}, {"input": "17 17\r\n-54 59 -95 87 3 -27 -30 49 -87 74 45 78 36 60 -95 41 -53 -70\r\n-27 16 -67 -24 10 -73 -41 12 -52 53 -73 -17 -56 -74 -33 -8 100 -39\r\n", "output": "2/1\n"}, {"input": "1 1\r\n36 -49\r\n-32 -40\r\n", "output": "-9/8\n"}, {"input": "1 1\r\n1 1\r\n1 1\r\n", "output": "1/1\n"}, {"input": "1 1\r\n-2 1\r\n4 1\r\n", "output": "-1/2\n"}, {"input": "0 0\r\n2\r\n1\r\n", "output": "2/1\n"}, {"input": "0 0\r\n4\r\n-3\r\n", "output": "-4/3\n"}, {"input": "0 0\r\n2\r\n2\r\n", "output": "1/1\n"}, {"input": "0 0\r\n17\r\n-10\r\n", "output": "-17/10\n"}, {"input": "0 0\r\n-1\r\n2\r\n", "output": "-1/2\n"}, {"input": "0 0\r\n1\r\n1\r\n", "output": "1/1\n"}, {"input": "0 0\r\n50\r\n20\r\n", "output": "5/2\n"}, {"input": "0 0\r\n20\r\n20\r\n", "output": "1/1\n"}, {"input": "0 0\r\n4\r\n-2\r\n", "output": "-2/1\n"}, {"input": "0 0\r\n4\r\n-6\r\n", "output": "-2/3\n"}, {"input": "0 0\r\n1\r\n-2\r\n", "output": "-1/2\n"}, {"input": "0 0\r\n4\r\n2\r\n", "output": "2/1\n"}, {"input": "0 0\r\n2\r\n-4\r\n", "output": "-1/2\n"}, {"input": "1 1\r\n4 1\r\n2 1\r\n", "output": "2/1\n"}, {"input": "2 2\r\n-13 1 3\r\n6 3 2\r\n", "output": "-13/6\n"}, {"input": "0 0\r\n5\r\n5\r\n", "output": "1/1\n"}, {"input": "0 0\r\n2\r\n-1\r\n", "output": "-2/1\n"}]
| false |
stdio
| null | true |
672/B
|
672
|
B
|
Python 3
|
TESTS
| 31 | 61 | 102,400 |
144861085
|
n = int(input())
s = str(input())
set = {'#'}
for x in s:
set.add(x)
if(len(set)==27):
print("-1")
exit(0)
a=n-len(set)+1
if(a>26-len(set)+1):
print("-1")
else:
print(a)
| 47 | 46 | 0 |
156818113
|
n = int(input())
s = set(input())
ans = n - len(s)
if n > 26:
print(-1)
else:
print(ans)
|
Codeforces Round 352 (Div. 2)
|
CF
| 2,016 | 2 | 256 |
Different is Good
|
A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different.
Kerem recently got a string s consisting of lowercase English letters. Since Kerem likes it when things are different, he wants all substrings of his string s to be distinct. Substring is a string formed by some number of consecutive characters of the string. For example, string "aba" has substrings "" (empty substring), "a", "b", "a", "ab", "ba", "aba".
If string s has at least two equal substrings then Kerem will change characters at some positions to some other lowercase English letters. Changing characters is a very tiring job, so Kerem want to perform as few changes as possible.
Your task is to find the minimum number of changes needed to make all the substrings of the given string distinct, or determine that it is impossible.
|
The first line of the input contains an integer n (1 ≤ n ≤ 100 000) — the length of the string s.
The second line contains the string s of length n consisting of only lowercase English letters.
|
If it's impossible to change the string s such that all its substring are distinct print -1. Otherwise print the minimum required number of changes.
| null |
In the first sample one of the possible solutions is to change the first character to 'b'.
In the second sample, one may change the first character to 'a' and second character to 'b', so the string becomes "abko".
|
[{"input": "2\naa", "output": "1"}, {"input": "4\nkoko", "output": "2"}, {"input": "5\nmurat", "output": "0"}]
| 1,000 |
["constructive algorithms", "implementation", "strings"]
| 47 |
[{"input": "2\r\naa\r\n", "output": "1\r\n"}, {"input": "4\r\nkoko\r\n", "output": "2\r\n"}, {"input": "5\r\nmurat\r\n", "output": "0\r\n"}, {"input": "6\r\nacbead\r\n", "output": "1\r\n"}, {"input": "7\r\ncdaadad\r\n", "output": "4\r\n"}, {"input": "25\r\npeoaicnbisdocqofsqdpgobpn\r\n", "output": "12\r\n"}, {"input": "25\r\ntcqpchnqskqjacruoaqilgebu\r\n", "output": "7\r\n"}, {"input": "13\r\naebaecedabbee\r\n", "output": "8\r\n"}, {"input": "27\r\naaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n", "output": "-1\r\n"}, {"input": "10\r\nbababbdaee\r\n", "output": "6\r\n"}, {"input": "11\r\ndbadcdbdbca\r\n", "output": "7\r\n"}, {"input": "12\r\nacceaabddaaa\r\n", "output": "7\r\n"}, {"input": "13\r\nabddfbfaeecfa\r\n", "output": "7\r\n"}, {"input": "14\r\neeceecacdbcbbb\r\n", "output": "9\r\n"}, {"input": "15\r\ndcbceaaggabaheb\r\n", "output": "8\r\n"}, {"input": "16\r\nhgiegfbadgcicbhd\r\n", "output": "7\r\n"}, {"input": "17\r\nabhfibbdddfghgfdi\r\n", "output": "10\r\n"}, {"input": "26\r\nbbbbbabbaababaaabaaababbaa\r\n", "output": "24\r\n"}, {"input": "26\r\nahnxdnbfbcrirerssyzydihuee\r\n", "output": "11\r\n"}, {"input": "26\r\nhwqeqhkpxwulbsiwmnlfyhgknc\r\n", "output": "8\r\n"}, {"input": "26\r\nrvxmulriorilidecqwmfaemifj\r\n", "output": "10\r\n"}, {"input": "26\r\naowpmreooavnmamogdoopuisge\r\n", "output": "12\r\n"}, {"input": "26\r\ninimevtuefhvuefirdehmmfudh\r\n", "output": "15\r\n"}, {"input": "26\r\naaaaaaaaaaaaaaaaaaaaaaaaaa\r\n", "output": "25\r\n"}, {"input": "27\r\nqdcfjtblgglnilgassirrjekcjt\r\n", "output": "-1\r\n"}, {"input": "27\r\nabcdefghijklmnopqrstuvwxyza\r\n", "output": "-1\r\n"}, {"input": "26\r\nqwertyuiopasdfghjklzxcvbnm\r\n", "output": "0\r\n"}, {"input": "5\r\nzzzzz\r\n", "output": "4\r\n"}, {"input": "27\r\naaaaaaaaaaaaaaaaabaaaaaaaaa\r\n", "output": "-1\r\n"}, {"input": "1\r\nq\r\n", "output": "0\r\n"}, {"input": "27\r\nqwertyuioplkjhgfdsazxcvbnmm\r\n", "output": "-1\r\n"}, {"input": "9\r\nxxxyyyzzz\r\n", "output": "6\r\n"}, {"input": "45\r\naaabbbcccdddeeefffgghhiijjkkkkkkkkkkkkkkkkkkk\r\n", "output": "-1\r\n"}, {"input": "27\r\nqwertyuiopasdfghjklzxcvbnmm\r\n", "output": "-1\r\n"}, {"input": "26\r\nabcdefghijklmnopqrstuvwxyz\r\n", "output": "0\r\n"}, {"input": "26\r\nabcdefghijklmnopqrstuvwxya\r\n", "output": "1\r\n"}, {"input": "27\r\nabcdefghijklmnopqrstuvwxyzz\r\n", "output": "-1\r\n"}, {"input": "26\r\naaaaaaaaaaaaaaaaaaaaaaaaaa\r\n", "output": "25\r\n"}, {"input": "26\r\nqwertyuioplkjhgfdsazxcvbnm\r\n", "output": "0\r\n"}, {"input": "10\r\nzzzzzzzzzz\r\n", "output": "9\r\n"}, {"input": "1\r\na\r\n", "output": "0\r\n"}, {"input": "30\r\nabcdefghtyabcdefghtyabcdefghty\r\n", "output": "-1\r\n"}]
| false |
stdio
| null | true |
832/B
|
832
|
B
|
PyPy 3-64
|
TESTS
| 15 | 296 | 5,017,600 |
142002770
|
good_letters = input()
pattern = input()
if '*' in pattern:
index_of_ast = pattern.index('*')
result = []
number_of_words = int(input())
for i in range(number_of_words):
word = input()
matches = True
if '*' in pattern:
pattern_without_ast = pattern.replace('*', '')
word_without_ast = word[:index_of_ast] + word[index_of_ast + len(word) - len(pattern_without_ast):]
ast_part = word[index_of_ast: index_of_ast + len(word) - len(pattern_without_ast)]
if len(word_without_ast) != len(pattern_without_ast):
matches = False
for letter in ast_part:
if letter in good_letters:
matches = False
for j in range(len(word_without_ast)):
if not (word_without_ast[j] == pattern_without_ast[j] or (word_without_ast[j] in good_letters and pattern_without_ast[j] == '?')):
matches = False
else:
if len(word) != len(pattern):
matches = False
else:
for j in range(len(word)):
if not (word[j] == pattern[j] or (word[j] in good_letters and pattern[j] == '?')):
matches = False
if matches:
result.append('YES')
else:
result.append('NO')
for res in result:
print(res)
| 94 | 530 | 5,632,000 |
28843189
|
#!/usr/local/bin/python3
import sys
good_letters = set(input())
pattern = input()
input()
for line in sys.stdin:
query = line.strip()
diff = len(query) - len(pattern) + 1
if diff < 0:
print("NO")
continue
query_index = 0
pattern_index = 0
question = None
result = "NO"
while (pattern_index < len(pattern)) and (query_index < len(query)):
current_letter = query[query_index]
current_pattern = pattern[pattern_index]
if current_pattern == '*':
if diff == 0:
pattern_index += 1
else:
if current_letter in good_letters:
break
else:
query_index += 1
diff -= 1
elif current_pattern == '?':
if current_letter in good_letters:
query_index += 1
pattern_index += 1
else:
break
else:
if current_letter != current_pattern:
break
else:
query_index += 1
pattern_index += 1
if (query_index == len(query)) and (pattern_index == len(pattern) - 1) and (pattern[pattern_index] == '*'):
result = "YES"
if (query_index == len(query)) and (pattern_index == len(pattern)):
result = "YES"
print(result)
|
Codeforces Round 425 (Div. 2)
|
CF
| 2,017 | 2 | 256 |
Petya and Exam
|
It's hard times now. Today Petya needs to score 100 points on Informatics exam. The tasks seem easy to Petya, but he thinks he lacks time to finish them all, so he asks you to help with one..
There is a glob pattern in the statements (a string consisting of lowercase English letters, characters "?" and "*"). It is known that character "*" occurs no more than once in the pattern.
Also, n query strings are given, it is required to determine for each of them if the pattern matches it or not.
Everything seemed easy to Petya, but then he discovered that the special pattern characters differ from their usual meaning.
A pattern matches a string if it is possible to replace each character "?" with one good lowercase English letter, and the character "*" (if there is one) with any, including empty, string of bad lowercase English letters, so that the resulting string is the same as the given string.
The good letters are given to Petya. All the others are bad.
|
The first line contains a string with length from 1 to 26 consisting of distinct lowercase English letters. These letters are good letters, all the others are bad.
The second line contains the pattern — a string s of lowercase English letters, characters "?" and "*" (1 ≤ |s| ≤ 105). It is guaranteed that character "*" occurs in s no more than once.
The third line contains integer n (1 ≤ n ≤ 105) — the number of query strings.
n lines follow, each of them contains single non-empty string consisting of lowercase English letters — a query string.
It is guaranteed that the total length of all query strings is not greater than 105.
|
Print n lines: in the i-th of them print "YES" if the pattern matches the i-th query string, and "NO" otherwise.
You can choose the case (lower or upper) for each letter arbitrary.
| null |
In the first example we can replace "?" with good letters "a" and "b", so we can see that the answer for the first query is "YES", and the answer for the second query is "NO", because we can't match the third letter.
Explanation of the second example.
- The first query: "NO", because character "*" can be replaced with a string of bad letters only, but the only way to match the query string is to replace it with the string "ba", in which both letters are good.
- The second query: "YES", because characters "?" can be replaced with corresponding good letters, and character "*" can be replaced with empty string, and the strings will coincide.
- The third query: "NO", because characters "?" can't be replaced with bad letters.
- The fourth query: "YES", because characters "?" can be replaced with good letters "a", and character "*" can be replaced with a string of bad letters "x".
|
[{"input": "ab\na?a\n2\naaa\naab", "output": "YES\nNO"}, {"input": "abc\na?a?a*\n4\nabacaba\nabaca\napapa\naaaaax", "output": "NO\nYES\nNO\nYES"}]
| 1,600 |
["implementation", "strings"]
| 94 |
[{"input": "ab\r\na?a\r\n2\r\naaa\r\naab\r\n", "output": "YES\r\nNO\r\n"}, {"input": "abc\r\na?a?a*\r\n4\r\nabacaba\r\nabaca\r\napapa\r\naaaaax\r\n", "output": "NO\r\nYES\r\nNO\r\nYES\r\n"}, {"input": "x\r\n?aba*\r\n69\r\nc\r\naaacc\r\nbba\r\nbabcb\r\nac\r\nbccca\r\nca\r\nabbaa\r\nb\r\naacca\r\nccc\r\ncc\r\na\r\naabba\r\nb\r\na\r\nbaca\r\nabb\r\ncac\r\ncbbaa\r\nb\r\naba\r\nbccc\r\nccbbc\r\nb\r\ncbab\r\naaabb\r\nc\r\nbbccb\r\nbaaa\r\nac\r\nbaa\r\nc\r\nbba\r\naabab\r\ncccb\r\nc\r\ncb\r\ncbab\r\nbb\r\nb\r\nb\r\nc\r\nbaaca\r\nbaca\r\naaa\r\ncaaa\r\na\r\nbcca\r\na\r\naac\r\naa\r\ncba\r\naacb\r\nacbb\r\nacaca\r\nc\r\ncc\r\nab\r\ncc\r\na\r\naba\r\nbbbbc\r\ncbcbc\r\nacb\r\nbbcb\r\nbbbcc\r\ncaa\r\ncaaac\r\n", "output": "NO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\n"}, {"input": "k\r\n*\r\n89\r\nb\r\ncbbbc\r\ncabac\r\nbccbb\r\nccc\r\ncabaa\r\nabbaa\r\nccbaa\r\nccccb\r\ncabbb\r\nbbcbc\r\nbac\r\naaac\r\nabb\r\nbcbb\r\ncb\r\nbacc\r\nbbaba\r\nb\r\nacc\r\nbaac\r\naaba\r\nbcbba\r\nbaa\r\nbc\r\naaccb\r\nb\r\nab\r\nc\r\nbbbb\r\nabbcb\r\nacbb\r\ncba\r\nc\r\nbac\r\nc\r\nac\r\ncc\r\nb\r\nbbc\r\nbaab\r\nc\r\nbbc\r\nab\r\nb\r\nc\r\naa\r\naab\r\nab\r\naccbc\r\nacbaa\r\na\r\nccc\r\ncba\r\nb\r\nb\r\nbcccb\r\nca\r\nacabb\r\naa\r\nba\r\naaa\r\nac\r\ncb\r\nacb\r\nbcc\r\ncbc\r\nac\r\nc\r\nbba\r\naacb\r\nbcccb\r\na\r\ncbbb\r\naabc\r\ncbaab\r\nbcac\r\nc\r\nca\r\ncc\r\naccbc\r\nabab\r\nbaca\r\nacca\r\na\r\nab\r\nabb\r\nb\r\nac\r\n", "output": "YES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\n"}, {"input": "t\r\nabac*\r\n68\r\nbcab\r\nbab\r\nbc\r\nab\r\naa\r\nac\r\ncabb\r\naabcc\r\nbba\r\nccbbb\r\nccaa\r\nca\r\nbacc\r\ncbbaa\r\na\r\nbbac\r\nacb\r\naba\r\naaaa\r\ncbaa\r\na\r\nabc\r\nccaba\r\nc\r\nacb\r\naba\r\ncacb\r\ncb\r\nacb\r\nabcc\r\ncaa\r\nabbb\r\nbaab\r\nc\r\nab\r\nacac\r\nabcc\r\ncc\r\nccca\r\nca\r\nc\r\nabbb\r\nccabc\r\na\r\ncabab\r\nb\r\nac\r\nbbbc\r\nb\r\nbbca\r\ncaa\r\nbbc\r\naa\r\nbcaca\r\nbaabc\r\nbcbb\r\nbc\r\nccaa\r\nab\r\nabaaa\r\na\r\ncbb\r\nc\r\nbaa\r\ncaa\r\nc\r\ncc\r\na\r\n", "output": "NO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\n"}, {"input": "q\r\n?*a\r\n29\r\nbacb\r\nbcaac\r\ncbc\r\naccc\r\nca\r\ncbb\r\nab\r\nab\r\nbcbc\r\nb\r\nbcaca\r\nbcc\r\nbbc\r\nc\r\ncaaa\r\nbbb\r\nbc\r\nbabac\r\nbcbba\r\nbbaa\r\ncbaa\r\nb\r\nab\r\nab\r\nbcca\r\naaca\r\na\r\nbaac\r\nb\r\n", "output": "NO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\n"}, {"input": "b\r\na?a*\r\n49\r\naabc\r\nb\r\nbacbc\r\nacc\r\nc\r\nbcbb\r\naccc\r\nba\r\ncbab\r\nbca\r\naaaba\r\nacaba\r\nbb\r\nccac\r\naaa\r\nacc\r\na\r\nca\r\na\r\nccb\r\naaaac\r\nc\r\naaa\r\ncaabb\r\nabb\r\nbb\r\nc\r\naaccc\r\nbaaab\r\nbb\r\nba\r\naca\r\nac\r\ncbc\r\nacaa\r\nbcbc\r\ncbc\r\nbba\r\ncc\r\ncbcac\r\ncbcb\r\naabb\r\nab\r\nc\r\nbbb\r\nbcca\r\naab\r\ncb\r\nbacb\r\n", "output": "NO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\n"}, {"input": "l\r\na*?a\r\n69\r\nc\r\naac\r\nc\r\ncc\r\nca\r\nabcbb\r\ncbc\r\naabb\r\na\r\nca\r\ncaab\r\nbcaab\r\ncbb\r\naa\r\naaabc\r\ncb\r\nc\r\nab\r\nca\r\nbcaab\r\nccabb\r\ncaaa\r\nbab\r\nab\r\naa\r\ncab\r\nc\r\ncbab\r\nc\r\nabbca\r\ncc\r\nacbba\r\nbaa\r\ncaab\r\nbc\r\nbbbac\r\naab\r\nccaca\r\ncc\r\nbb\r\na\r\naaac\r\nbcac\r\nacbac\r\naaaac\r\nabc\r\nba\r\naacab\r\nc\r\na\r\nbabaa\r\nabac\r\nabaac\r\na\r\nc\r\nacc\r\nabbba\r\naa\r\ncccb\r\na\r\nccaab\r\nbbaca\r\nba\r\nb\r\naacbc\r\ncbcac\r\nc\r\nbc\r\nccbb\r\n", "output": "NO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\n"}, {"input": "v\r\n*a?b\r\n92\r\nbbcca\r\nacaca\r\ncca\r\ncac\r\nab\r\nccaba\r\nabcbb\r\nc\r\ncc\r\nccccb\r\ncc\r\ncbcc\r\na\r\naab\r\ncacb\r\nb\r\nb\r\ncbc\r\nbb\r\nac\r\ncca\r\nb\r\nacb\r\nbcbca\r\ncbbbb\r\naacb\r\nacabb\r\ncaa\r\nbc\r\nbca\r\nc\r\nab\r\nac\r\nc\r\ncb\r\nba\r\ncccbc\r\ncaac\r\ncabc\r\nc\r\nbbac\r\ncaa\r\ncbbac\r\nb\r\nac\r\na\r\nb\r\nba\r\ncba\r\ncba\r\nacbc\r\ncc\r\nca\r\nc\r\ncab\r\ncac\r\na\r\ncac\r\nb\r\nc\r\nb\r\nb\r\nbabb\r\nbcab\r\nc\r\nbb\r\nb\r\ncbc\r\nabba\r\nabccb\r\nccaaa\r\nabbc\r\na\r\naa\r\nab\r\nacbcc\r\nc\r\nbc\r\nb\r\nbbcac\r\naccc\r\nca\r\ncab\r\ncb\r\nabaac\r\nc\r\nbaac\r\ncc\r\naa\r\nca\r\naccac\r\nbbbc\r\n", "output": "NO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\n"}, {"input": "y\r\n*\r\n36\r\nbacc\r\nacab\r\naaac\r\ncbca\r\ncbbc\r\ncbaab\r\nbaba\r\nbb\r\nacac\r\nc\r\nb\r\nbacbb\r\ncbca\r\nbbba\r\naa\r\nbc\r\nbb\r\nababb\r\nab\r\nb\r\nc\r\nb\r\nbc\r\nabb\r\nccaca\r\ncbc\r\nacbb\r\nc\r\nbbbba\r\ncb\r\ncca\r\nb\r\nb\r\ncc\r\nbcbc\r\naac\r\n", "output": "YES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\n"}, {"input": "i\r\n*b?\r\n69\r\nc\r\nbcaac\r\ncaa\r\nbacb\r\nbbbca\r\ncbc\r\naabb\r\nbacc\r\nabbca\r\naaa\r\nabcaa\r\nbccb\r\ncabc\r\nac\r\nbb\r\nbac\r\ncbc\r\naaa\r\nbab\r\nbcb\r\nbb\r\nbaba\r\naac\r\nab\r\ncbcb\r\nbac\r\nacc\r\nbcb\r\naaccb\r\nbac\r\naaacc\r\nbacca\r\nbaba\r\nb\r\na\r\ncabca\r\naca\r\nb\r\naa\r\nbc\r\nbbaac\r\nac\r\nccaac\r\nbb\r\nba\r\nbcaba\r\nbbca\r\na\r\naab\r\na\r\naa\r\ncbcb\r\na\r\nababb\r\na\r\ncba\r\nca\r\nccb\r\nac\r\nbbc\r\nbcccb\r\nccac\r\nab\r\ncb\r\nbb\r\nc\r\ncac\r\na\r\ncabc\r\n", "output": "NO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\n"}, {"input": "f\r\n*?\r\n96\r\nc\r\nbbacb\r\naacbb\r\nbba\r\naabac\r\nc\r\nab\r\naaaab\r\ncac\r\naacb\r\nacc\r\naa\r\ncaaa\r\naca\r\nb\r\nc\r\ncbabb\r\ncc\r\nccbb\r\naaa\r\nbacbc\r\ncca\r\na\r\nbcb\r\nbba\r\nba\r\nbb\r\nabca\r\nbabab\r\nba\r\naaabc\r\ncbac\r\nbc\r\nac\r\nac\r\nccbbb\r\nbbc\r\nacaac\r\ncaab\r\nacbbb\r\nbb\r\nbbaac\r\naa\r\nbaacb\r\nbca\r\ncbcaa\r\na\r\nb\r\ncac\r\ncbc\r\ncbb\r\nbc\r\na\r\nb\r\nccbaa\r\ncaccb\r\nbac\r\nba\r\nb\r\nccb\r\ncaa\r\nccac\r\nbca\r\na\r\nbac\r\nac\r\nbbcab\r\nc\r\nacccb\r\nc\r\nab\r\na\r\nacba\r\ncacbb\r\nca\r\nbaa\r\ncacb\r\ncabbc\r\ncccbb\r\nabcbc\r\ncbbb\r\nac\r\nb\r\nccb\r\nbccc\r\nbb\r\nc\r\nbcc\r\nbcb\r\nab\r\nb\r\na\r\nbaab\r\naca\r\ncbbc\r\nb\r\n", "output": "NO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\n"}, {"input": "q\r\n*b\r\n58\r\ncb\r\nccbaa\r\nbbccb\r\ncab\r\nc\r\na\r\ncabab\r\naabbb\r\nbcb\r\nc\r\na\r\nccabc\r\nbbbac\r\nbcaa\r\nbbb\r\naca\r\nca\r\nbab\r\ncaaa\r\nab\r\ncba\r\ncbac\r\ncac\r\ncaac\r\nb\r\ncc\r\nc\r\naba\r\nbaba\r\nabaaa\r\nbcbbc\r\nccabb\r\na\r\naaca\r\naa\r\naac\r\nbbcbb\r\nccaac\r\nacbbc\r\naa\r\nca\r\naaaab\r\nac\r\naccab\r\ncbbaa\r\ncb\r\nacaa\r\naaaaa\r\na\r\nc\r\na\r\ncbbba\r\ncab\r\naaba\r\nc\r\nbab\r\nacc\r\nccbb\r\n", "output": "YES\r\nNO\r\nYES\r\nYES\r\nNO\r\nNO\r\nYES\r\nYES\r\nYES\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nYES\r\nNO\r\nNO\r\nYES\r\nNO\r\nYES\r\nNO\r\nNO\r\nNO\r\nNO\r\nYES\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nYES\r\nNO\r\nNO\r\nNO\r\nNO\r\nYES\r\nNO\r\nNO\r\nNO\r\nNO\r\nYES\r\nNO\r\nYES\r\nNO\r\nYES\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nYES\r\nNO\r\nNO\r\nYES\r\nNO\r\nYES\r\n"}, {"input": "z\r\ncb*c\r\n50\r\nbaca\r\naaca\r\nacba\r\nacbaa\r\nbc\r\nc\r\nac\r\na\r\nc\r\nbcca\r\ncc\r\nac\r\nbaa\r\nc\r\nbbac\r\naa\r\ncc\r\nbcaba\r\nca\r\nbcaba\r\ncbacc\r\naa\r\ncc\r\naba\r\nbcb\r\ncaa\r\nacaa\r\nca\r\ncba\r\ncb\r\nca\r\naab\r\nbc\r\nbaabc\r\nacaab\r\nbacc\r\nc\r\nc\r\na\r\ncb\r\ncbaa\r\ncaa\r\ncbcc\r\nc\r\ncba\r\naac\r\nbba\r\nbcaab\r\nc\r\na\r\n", "output": "NO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nYES\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nYES\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\n"}, {"input": "cba\r\n?*cbc\r\n88\r\ncccca\r\ncbc\r\nb\r\nbcb\r\naaa\r\ncaac\r\nbacb\r\nacbb\r\na\r\nab\r\ncbcca\r\nbccc\r\nabcc\r\naca\r\nba\r\nbbac\r\nacc\r\ncba\r\nbcba\r\nbc\r\naa\r\nab\r\ncaba\r\ncccab\r\ncba\r\ncbcc\r\nba\r\ncacbb\r\nabcc\r\na\r\nc\r\nbac\r\nccaba\r\nb\r\nac\r\nbbb\r\nac\r\nccaca\r\na\r\nba\r\nacbcc\r\nbbc\r\nacbc\r\nbbabc\r\nccbb\r\nb\r\nacaa\r\na\r\nba\r\nacb\r\na\r\nab\r\naa\r\nbbbb\r\naabb\r\nbcbc\r\nb\r\nca\r\nb\r\nccab\r\nab\r\nc\r\nb\r\naabab\r\nc\r\ncbbbc\r\nacbbb\r\nbacaa\r\nbcccc\r\ncbac\r\nc\r\nac\r\nb\r\nca\r\ncbb\r\nccbc\r\nc\r\nc\r\nbcb\r\nc\r\nbaaba\r\nc\r\nbac\r\nb\r\nba\r\ncb\r\ncc\r\nbaaca\r\n", "output": "NO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nYES\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nYES\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nYES\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\nNO\r\n"}, {"input": "a\r\naa\r\n1\r\naaa\r\n", "output": "NO\r\n"}, {"input": "a\r\naaa\r\n1\r\naaaa\r\n", "output": "NO\r\n"}, {"input": "a\r\naa*aa\r\n1\r\naaa\r\n", "output": "NO\r\n"}, {"input": "a\r\nbb*bb\r\n1\r\nbbbbbbbbbbbbbbbb\r\n", "output": "YES\r\n"}, {"input": "a\r\na*\r\n1\r\nabbbbbbb\r\n", "output": "YES\r\n"}, {"input": "a\r\na?a\r\n1\r\naaab\r\n", "output": "NO\r\n"}, {"input": "xy\r\ncab*aba\r\n1\r\ncaba\r\n", "output": "NO\r\n"}, {"input": "a\r\n*\r\n4\r\nb\r\na\r\nab\r\nba\r\n", "output": "YES\r\nNO\r\nNO\r\nNO\r\n"}, {"input": "abc\r\na?a?*a\r\n3\r\nababxa\r\nababca\r\nababa\r\n", "output": "YES\r\nNO\r\nYES\r\n"}, {"input": "abc\r\n??a*df?c\r\n6\r\nabadfcc\r\naaaadfac\r\nbbagthfac\r\nacadddfac\r\ndaagdffc\r\naaaadfcc\r\n", "output": "YES\r\nNO\r\nNO\r\nYES\r\nNO\r\nNO\r\n"}, {"input": "abc\r\nabc*a\r\n1\r\nabckka\r\n", "output": "YES\r\n"}, {"input": "b\r\n*a\r\n1\r\naba\r\n", "output": "NO\r\n"}, {"input": "a\r\nabc*g\r\n1\r\nabcdefg\r\n", "output": "YES\r\n"}, {"input": "a\r\nab\r\n1\r\na\r\n", "output": "NO\r\n"}, {"input": "abcdefghijklmnopqrstuvwxyz\r\n*a\r\n1\r\na\r\n", "output": "YES\r\n"}, {"input": "as\r\naba*aba\r\n1\r\naba\r\n", "output": "NO\r\n"}, {"input": "ab\r\naweerrtab\r\n4\r\naw\r\naweerrtabwqeqrw\r\naweerrtabxcvxcbcxbdsfdsfewrewrqweq\r\naweerrtabaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n", "output": "NO\r\nNO\r\nNO\r\nNO\r\n"}, {"input": "a\r\na\r\n1\r\nab\r\n", "output": "NO\r\n"}, {"input": "a\r\na*b\r\n1\r\nabb\r\n", "output": "YES\r\n"}, {"input": "a\r\nb*a\r\n1\r\nbbadd\r\n", "output": "NO\r\n"}, {"input": "a\r\naaaa\r\n1\r\naaa\r\n", "output": "NO\r\n"}, {"input": "z\r\n*abcd\r\n1\r\nggggggg\r\n", "output": "NO\r\n"}, {"input": "abc\r\n*??\r\n1\r\nqqqqqqqqab\r\n", "output": "YES\r\n"}, {"input": "b\r\naa\r\n1\r\na\r\n", "output": "NO\r\n"}, {"input": "ab\r\na*pa\r\n1\r\nappppa\r\n", "output": "YES\r\n"}, {"input": "a\r\nbbb\r\n1\r\nbbbbb\r\n", "output": "NO\r\n"}, {"input": "ab\r\nabcd?\r\n1\r\nabcd\r\n", "output": "NO\r\n"}, {"input": "c\r\na\r\n1\r\nab\r\n", "output": "NO\r\n"}]
| false |
stdio
| null | true |
837/C
|
837
|
C
|
Python 3
|
TESTS
| 22 | 62 | 0 |
29691917
|
# Task3 Codeforces 837c
def sm(obj1,obj2):
return obj1[0]*obj1[1]+obj2[0]*obj2[1]
def rotate(x,y,obj):
if obj[0] > x or obj[1] > y:
return -1
else:
return
def can_put(x,y,obj):
if obj[0] > x and obj[0] > y or obj[1] > x and obj[1] > y:
return False
else:
return True
def can_add(x,y,obj1,obj2):
if obj1[1]+obj2[1] <= y and obj2[0] <= x:
return True
elif obj1[0]+obj2[0] <= x and obj2[1] <= y:
return True
else:
return False
def add(x, y, obj1, obj2, ms):
if can_put(x,y,obj1) and can_put(x,y,obj2):
lm = sm(obj1,obj2)
if lm>x*y or lm<ms:
return False
if can_add(x, y, obj1[::rotate(x,y,obj1)], obj2):
return True
elif can_add(x, y, obj1[::rotate(x,y,obj1)], obj2[::-1]):
return True
else:
return False
else:
return False
lst,m = [],0
n,a,b=map(int, input().split())
for i in range(n):
lst += [[int(j) for j in input().split()]]
for i in range(n-1):
for j in range(i+1,n):
if add(a, b, lst[i], lst[j], m):
m = sm(lst[i],lst[j])
print(m)
| 51 | 62 | 4,915,200 |
29183668
|
n,w,h=map(int,input().split())
def chk(w1,h1,w2,h2):
if w1<=w and h1<=h:
if w-w1>=w2 and h>=h2 or w-w1>=h2 and h>=w2 or w>=w2 and h-h1>=h2 or w>=h2 and h-h1>=w2:
return True
if h1<=w and w1<=h:
if w-h1>=w2 and h>=h2 or w-h1>=h2 and h>=w2 or w>=w2 and h-w1>=h2 or w>=h2 and h-w1>=w2:
return True
return False
a,ans=[],0
for i in range(n):
x,y=map(int, input().split())
a.append([x,y])
for i in range(n):
for j in range(i+1,n):
if a[i][0]*a[i][1]+a[j][1]*a[j][0]>ans and chk(a[i][0],a[i][1],a[j][0],a[j][1]):
ans=a[i][0]*a[i][1]+a[j][1]*a[j][0]
print(ans)
|
Educational Codeforces Round 26
|
ICPC
| 2,017 | 1 | 256 |
Two Seals
|
One very important person has a piece of paper in the form of a rectangle a × b.
Also, he has n seals. Each seal leaves an impression on the paper in the form of a rectangle of the size xi × yi. Each impression must be parallel to the sides of the piece of paper (but seal can be rotated by 90 degrees).
A very important person wants to choose two different seals and put them two impressions. Each of the selected seals puts exactly one impression. Impressions should not overlap (but they can touch sides), and the total area occupied by them should be the largest possible. What is the largest area that can be occupied by two seals?
|
The first line contains three integer numbers n, a and b (1 ≤ n, a, b ≤ 100).
Each of the next n lines contain two numbers xi, yi (1 ≤ xi, yi ≤ 100).
|
Print the largest total area that can be occupied by two seals. If you can not select two seals, print 0.
| null |
In the first example you can rotate the second seal by 90 degrees. Then put impression of it right under the impression of the first seal. This will occupy all the piece of paper.
In the second example you can't choose the last seal because it doesn't fit. By choosing the first and the third seals you occupy the largest area.
In the third example there is no such pair of seals that they both can fit on a piece of paper.
|
[{"input": "2 2 2\n1 2\n2 1", "output": "4"}, {"input": "4 10 9\n2 3\n1 1\n5 10\n9 11", "output": "56"}, {"input": "3 10 10\n6 6\n7 7\n20 5", "output": "0"}]
| 1,500 |
["brute force", "implementation"]
| 51 |
[{"input": "2 2 2\r\n1 2\r\n2 1\r\n", "output": "4\r\n"}, {"input": "4 10 9\r\n2 3\r\n1 1\r\n5 10\r\n9 11\r\n", "output": "56\r\n"}, {"input": "3 10 10\r\n6 6\r\n7 7\r\n20 5\r\n", "output": "0\r\n"}, {"input": "2 1 1\r\n1 1\r\n1 1\r\n", "output": "0\r\n"}, {"input": "2 1 2\r\n1 1\r\n1 1\r\n", "output": "2\r\n"}, {"input": "2 100 100\r\n100 100\r\n1 1\r\n", "output": "0\r\n"}, {"input": "2 100 100\r\n50 100\r\n100 50\r\n", "output": "10000\r\n"}, {"input": "2 100 100\r\n100 100\r\n87 72\r\n", "output": "0\r\n"}, {"input": "5 100 100\r\n100 100\r\n100 100\r\n100 100\r\n100 100\r\n100 100\r\n", "output": "0\r\n"}, {"input": "15 50 50\r\n9 36\r\n28 14\r\n77 74\r\n35 2\r\n20 32\r\n83 85\r\n47 3\r\n41 50\r\n21 7\r\n38 46\r\n17 6\r\n79 90\r\n91 83\r\n9 33\r\n24 11\r\n", "output": "2374\r\n"}, {"input": "15 100 100\r\n100 100\r\n100 100\r\n100 100\r\n42 58\r\n80 22\r\n100 100\r\n100 100\r\n100 100\r\n100 100\r\n100 100\r\n48 42\r\n100 100\r\n100 100\r\n100 100\r\n100 100\r\n", "output": "4452\r\n"}, {"input": "30 100 100\r\n60 34\r\n29 82\r\n89 77\r\n39 1\r\n100 100\r\n82 12\r\n57 87\r\n93 43\r\n78 50\r\n38 55\r\n37 9\r\n67 5\r\n100 100\r\n100 100\r\n82 47\r\n3 71\r\n100 100\r\n19 26\r\n25 94\r\n89 5\r\n100 100\r\n32 1\r\n100 100\r\n34 3\r\n40 99\r\n100 100\r\n36 12\r\n100 100\r\n100 100\r\n100 100\r\n", "output": "8958\r\n"}, {"input": "3 100 1\r\n1 50\r\n1 60\r\n1 30\r\n", "output": "90\r\n"}, {"input": "3 1 60\r\n1 40\r\n2 2\r\n20 1\r\n", "output": "60\r\n"}, {"input": "4 1 100\r\n1 25\r\n25 1\r\n1 25\r\n2 100\r\n", "output": "50\r\n"}, {"input": "1 100 50\r\n4 20\r\n", "output": "0\r\n"}, {"input": "2 2 4\r\n3 1\r\n2 2\r\n", "output": "0\r\n"}, {"input": "2 2 4\r\n2 3\r\n2 1\r\n", "output": "8\r\n"}, {"input": "2 4 2\r\n1 2\r\n2 3\r\n", "output": "8\r\n"}, {"input": "2 1 4\r\n1 2\r\n1 2\r\n", "output": "4\r\n"}, {"input": "2 4 5\r\n2 4\r\n4 3\r\n", "output": "20\r\n"}, {"input": "2 1 4\r\n1 1\r\n3 3\r\n", "output": "0\r\n"}, {"input": "6 9 5\r\n4 5\r\n6 2\r\n1 4\r\n5 6\r\n3 7\r\n6 5\r\n", "output": "34\r\n"}, {"input": "6 8 5\r\n4 1\r\n3 3\r\n5 3\r\n6 7\r\n2 2\r\n5 4\r\n", "output": "35\r\n"}, {"input": "6 7 5\r\n6 4\r\n5 7\r\n4 7\r\n5 4\r\n1 1\r\n3 6\r\n", "output": "29\r\n"}, {"input": "6 9 7\r\n1 2\r\n1 5\r\n4 3\r\n4 7\r\n3 5\r\n6 7\r\n", "output": "57\r\n"}, {"input": "6 5 9\r\n2 3\r\n7 4\r\n1 5\r\n1 7\r\n2 5\r\n7 1\r\n", "output": "38\r\n"}, {"input": "2 4 2\r\n2 2\r\n1 3\r\n", "output": "0\r\n"}, {"input": "2 3 2\r\n3 2\r\n1 1\r\n", "output": "0\r\n"}, {"input": "6 7 5\r\n6 6\r\n4 7\r\n6 1\r\n4 1\r\n4 6\r\n1 5\r\n", "output": "34\r\n"}, {"input": "2 2 3\r\n1 2\r\n2 3\r\n", "output": "0\r\n"}, {"input": "2 2 2\r\n2 1\r\n1 1\r\n", "output": "3\r\n"}, {"input": "5 9 7\r\n6 7\r\n4 5\r\n2 7\r\n4 2\r\n5 8\r\n", "output": "56\r\n"}, {"input": "2 11 51\r\n1 10\r\n11 50\r\n", "output": "560\r\n"}, {"input": "5 9 7\r\n3 8\r\n7 6\r\n4 1\r\n5 8\r\n7 8\r\n", "output": "60\r\n"}, {"input": "2 4 6\r\n4 4\r\n4 2\r\n", "output": "24\r\n"}, {"input": "5 9 7\r\n1 6\r\n7 9\r\n1 5\r\n1 5\r\n7 3\r\n", "output": "27\r\n"}, {"input": "5 9 7\r\n5 2\r\n6 9\r\n1 4\r\n7 7\r\n6 4\r\n", "output": "59\r\n"}, {"input": "5 9 7\r\n6 7\r\n4 1\r\n1 2\r\n4 7\r\n5 6\r\n", "output": "58\r\n"}, {"input": "5 9 7\r\n2 8\r\n3 8\r\n2 8\r\n4 4\r\n2 2\r\n", "output": "40\r\n"}, {"input": "2 2 3\r\n1 4\r\n2 1\r\n", "output": "0\r\n"}, {"input": "5 9 7\r\n4 7\r\n3 9\r\n5 4\r\n3 4\r\n3 8\r\n", "output": "55\r\n"}, {"input": "5 9 7\r\n7 4\r\n6 9\r\n4 3\r\n7 5\r\n2 3\r\n", "output": "63\r\n"}, {"input": "2 2 3\r\n1 2\r\n2 2\r\n", "output": "6\r\n"}, {"input": "2 4 3\r\n2 1\r\n1 2\r\n", "output": "4\r\n"}, {"input": "2 4 6\r\n4 2\r\n4 4\r\n", "output": "24\r\n"}, {"input": "2 1 4\r\n3 2\r\n3 3\r\n", "output": "0\r\n"}]
| false |
stdio
| null | true |
837/C
|
837
|
C
|
Python 3
|
TESTS
| 19 | 61 | 4,915,200 |
29185995
|
k, n, m = map(int,input().split())
if n > m:
n ^= m
m ^= n
n ^= m
x, y = [],[]
for i in range(k):
q, p = map(int, input().split())
x.append(min(q, p))
y.append(max(q, p))
MAX = 0
for i in range(k):
for j in range(i+1,k):
if max(x[i], x[j]) <= n and y[i] + y[j] <= m:
MAX = max(MAX, x[i]*y[i] + x[j]*y[j])
elif x[i] + x[j] <= n and max(y[i], y[j]) <= m:
MAX = max(MAX, x[i]*y[i] + x[j]*y[j])
elif max(y[i], x[j]) <= n and x[i] + y[j] <= m:
MAX = max(MAX, x[i]*y[i] + x[j]*y[j])
elif y[i] + x[j] <= n and max(x[i] + y[j]) <= m:
MAX = max(MAX, x[i]*y[i] + x[j]*y[j])
print(MAX)
| 51 | 62 | 4,915,200 |
29186287
|
k, n, m = map(int,input().split())
x, y = [],[]
for i in range(k):
q, p = map(int, input().split())
x.append(min(q, p))
y.append(max(q, p))
MAX = 0
for i in range(k):
for j in range(i+1,k):
ok = False
if x[i] + x[j] <= n and y[i] <= m and y[j] <= m:
ok = True
elif x[i] + y[j] <= n and y[i] <= m and x[j] <= m:
ok = True
elif y[i] + y[j] <= m and x[i] <= n and x[j] <= n:
ok = True
elif y[i] + x[j] <= m and x[i] <= n and y[j] <= n:
ok = True
elif y[i] + y[j] <= n and x[i] <= m and x[j] <= m:
ok = True
elif y[i] + x[j] <= n and x[i] <= m and y[j] <= m:
ok = True
elif x[i] + x[j] <= m and y[i] <= n and y[j] <= n:
ok = True
elif x[i] + y[j] <= m and y[i] <= n and x[j] <= n:
ok = True
if ok:
MAX = max(MAX, x[i]*y[i] + x[j]*y[j])
print(MAX)
|
Educational Codeforces Round 26
|
ICPC
| 2,017 | 1 | 256 |
Two Seals
|
One very important person has a piece of paper in the form of a rectangle a × b.
Also, he has n seals. Each seal leaves an impression on the paper in the form of a rectangle of the size xi × yi. Each impression must be parallel to the sides of the piece of paper (but seal can be rotated by 90 degrees).
A very important person wants to choose two different seals and put them two impressions. Each of the selected seals puts exactly one impression. Impressions should not overlap (but they can touch sides), and the total area occupied by them should be the largest possible. What is the largest area that can be occupied by two seals?
|
The first line contains three integer numbers n, a and b (1 ≤ n, a, b ≤ 100).
Each of the next n lines contain two numbers xi, yi (1 ≤ xi, yi ≤ 100).
|
Print the largest total area that can be occupied by two seals. If you can not select two seals, print 0.
| null |
In the first example you can rotate the second seal by 90 degrees. Then put impression of it right under the impression of the first seal. This will occupy all the piece of paper.
In the second example you can't choose the last seal because it doesn't fit. By choosing the first and the third seals you occupy the largest area.
In the third example there is no such pair of seals that they both can fit on a piece of paper.
|
[{"input": "2 2 2\n1 2\n2 1", "output": "4"}, {"input": "4 10 9\n2 3\n1 1\n5 10\n9 11", "output": "56"}, {"input": "3 10 10\n6 6\n7 7\n20 5", "output": "0"}]
| 1,500 |
["brute force", "implementation"]
| 51 |
[{"input": "2 2 2\r\n1 2\r\n2 1\r\n", "output": "4\r\n"}, {"input": "4 10 9\r\n2 3\r\n1 1\r\n5 10\r\n9 11\r\n", "output": "56\r\n"}, {"input": "3 10 10\r\n6 6\r\n7 7\r\n20 5\r\n", "output": "0\r\n"}, {"input": "2 1 1\r\n1 1\r\n1 1\r\n", "output": "0\r\n"}, {"input": "2 1 2\r\n1 1\r\n1 1\r\n", "output": "2\r\n"}, {"input": "2 100 100\r\n100 100\r\n1 1\r\n", "output": "0\r\n"}, {"input": "2 100 100\r\n50 100\r\n100 50\r\n", "output": "10000\r\n"}, {"input": "2 100 100\r\n100 100\r\n87 72\r\n", "output": "0\r\n"}, {"input": "5 100 100\r\n100 100\r\n100 100\r\n100 100\r\n100 100\r\n100 100\r\n", "output": "0\r\n"}, {"input": "15 50 50\r\n9 36\r\n28 14\r\n77 74\r\n35 2\r\n20 32\r\n83 85\r\n47 3\r\n41 50\r\n21 7\r\n38 46\r\n17 6\r\n79 90\r\n91 83\r\n9 33\r\n24 11\r\n", "output": "2374\r\n"}, {"input": "15 100 100\r\n100 100\r\n100 100\r\n100 100\r\n42 58\r\n80 22\r\n100 100\r\n100 100\r\n100 100\r\n100 100\r\n100 100\r\n48 42\r\n100 100\r\n100 100\r\n100 100\r\n100 100\r\n", "output": "4452\r\n"}, {"input": "30 100 100\r\n60 34\r\n29 82\r\n89 77\r\n39 1\r\n100 100\r\n82 12\r\n57 87\r\n93 43\r\n78 50\r\n38 55\r\n37 9\r\n67 5\r\n100 100\r\n100 100\r\n82 47\r\n3 71\r\n100 100\r\n19 26\r\n25 94\r\n89 5\r\n100 100\r\n32 1\r\n100 100\r\n34 3\r\n40 99\r\n100 100\r\n36 12\r\n100 100\r\n100 100\r\n100 100\r\n", "output": "8958\r\n"}, {"input": "3 100 1\r\n1 50\r\n1 60\r\n1 30\r\n", "output": "90\r\n"}, {"input": "3 1 60\r\n1 40\r\n2 2\r\n20 1\r\n", "output": "60\r\n"}, {"input": "4 1 100\r\n1 25\r\n25 1\r\n1 25\r\n2 100\r\n", "output": "50\r\n"}, {"input": "1 100 50\r\n4 20\r\n", "output": "0\r\n"}, {"input": "2 2 4\r\n3 1\r\n2 2\r\n", "output": "0\r\n"}, {"input": "2 2 4\r\n2 3\r\n2 1\r\n", "output": "8\r\n"}, {"input": "2 4 2\r\n1 2\r\n2 3\r\n", "output": "8\r\n"}, {"input": "2 1 4\r\n1 2\r\n1 2\r\n", "output": "4\r\n"}, {"input": "2 4 5\r\n2 4\r\n4 3\r\n", "output": "20\r\n"}, {"input": "2 1 4\r\n1 1\r\n3 3\r\n", "output": "0\r\n"}, {"input": "6 9 5\r\n4 5\r\n6 2\r\n1 4\r\n5 6\r\n3 7\r\n6 5\r\n", "output": "34\r\n"}, {"input": "6 8 5\r\n4 1\r\n3 3\r\n5 3\r\n6 7\r\n2 2\r\n5 4\r\n", "output": "35\r\n"}, {"input": "6 7 5\r\n6 4\r\n5 7\r\n4 7\r\n5 4\r\n1 1\r\n3 6\r\n", "output": "29\r\n"}, {"input": "6 9 7\r\n1 2\r\n1 5\r\n4 3\r\n4 7\r\n3 5\r\n6 7\r\n", "output": "57\r\n"}, {"input": "6 5 9\r\n2 3\r\n7 4\r\n1 5\r\n1 7\r\n2 5\r\n7 1\r\n", "output": "38\r\n"}, {"input": "2 4 2\r\n2 2\r\n1 3\r\n", "output": "0\r\n"}, {"input": "2 3 2\r\n3 2\r\n1 1\r\n", "output": "0\r\n"}, {"input": "6 7 5\r\n6 6\r\n4 7\r\n6 1\r\n4 1\r\n4 6\r\n1 5\r\n", "output": "34\r\n"}, {"input": "2 2 3\r\n1 2\r\n2 3\r\n", "output": "0\r\n"}, {"input": "2 2 2\r\n2 1\r\n1 1\r\n", "output": "3\r\n"}, {"input": "5 9 7\r\n6 7\r\n4 5\r\n2 7\r\n4 2\r\n5 8\r\n", "output": "56\r\n"}, {"input": "2 11 51\r\n1 10\r\n11 50\r\n", "output": "560\r\n"}, {"input": "5 9 7\r\n3 8\r\n7 6\r\n4 1\r\n5 8\r\n7 8\r\n", "output": "60\r\n"}, {"input": "2 4 6\r\n4 4\r\n4 2\r\n", "output": "24\r\n"}, {"input": "5 9 7\r\n1 6\r\n7 9\r\n1 5\r\n1 5\r\n7 3\r\n", "output": "27\r\n"}, {"input": "5 9 7\r\n5 2\r\n6 9\r\n1 4\r\n7 7\r\n6 4\r\n", "output": "59\r\n"}, {"input": "5 9 7\r\n6 7\r\n4 1\r\n1 2\r\n4 7\r\n5 6\r\n", "output": "58\r\n"}, {"input": "5 9 7\r\n2 8\r\n3 8\r\n2 8\r\n4 4\r\n2 2\r\n", "output": "40\r\n"}, {"input": "2 2 3\r\n1 4\r\n2 1\r\n", "output": "0\r\n"}, {"input": "5 9 7\r\n4 7\r\n3 9\r\n5 4\r\n3 4\r\n3 8\r\n", "output": "55\r\n"}, {"input": "5 9 7\r\n7 4\r\n6 9\r\n4 3\r\n7 5\r\n2 3\r\n", "output": "63\r\n"}, {"input": "2 2 3\r\n1 2\r\n2 2\r\n", "output": "6\r\n"}, {"input": "2 4 3\r\n2 1\r\n1 2\r\n", "output": "4\r\n"}, {"input": "2 4 6\r\n4 2\r\n4 4\r\n", "output": "24\r\n"}, {"input": "2 1 4\r\n3 2\r\n3 3\r\n", "output": "0\r\n"}]
| false |
stdio
| null | true |
404/A
|
404
|
A
|
Python 3
|
TESTS
| 41 | 124 | 8,704,000 |
80209147
|
a = int(input())
mid = a//2
b=[]
c=[]
for i in range(a):
t = list(input())
b.append(t)
for j in t:
c.append(j)
if len(set(c))!=2:
print('NO')
elif c.count(c[0])!=2*a-1:
print('NO')
elif c.count(c[1])!=a**2-(2*a-1):
print('NO')
elif b[mid][mid]!=b[0][0] or b[a-1][a-1]!=b[0][0]:
print('NO')
elif b[a-1][0]!=b[mid][mid] or b[a-1][0]!=b[0][a-1]:
print('NO')
else:
print('YES')
| 47 | 46 | 0 |
159209670
|
n = int(input())
s1 = input()
s = ''.join(sorted(set(s1)))
c = 1
co = 1
mid = (n//2)-1
li = [s1]
for i in range(n-1):
ss1 = input()
li.append(ss1)
if i==mid:
if ss1 != ss1[::-1]:
c = 0
ss = ''.join(sorted(set(ss1)))
if ss!=s:
c = 0
if ss1 == s1:
co += 1
if co == n:
c = 0
if c:
for i in range(mid+1):
if li[i]!=li[n-1-i]:
c = 0
if c:
print("YES")
else:
print("NO")
else:
print("NO")
'''
0
0
1
'''
|
Codeforces Round 237 (Div. 2)
|
CF
| 2,014 | 1 | 256 |
Valera and X
|
Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the side equals n squares (n is an odd number) and each unit square contains some small letter of the English alphabet.
Valera needs to know if the letters written on the square piece of paper form letter "X". Valera's teacher thinks that the letters on the piece of paper form an "X", if:
- on both diagonals of the square paper all letters are the same;
- all other squares of the paper (they are not on the diagonals) contain the same letter that is different from the letters on the diagonals.
Help Valera, write the program that completes the described task for him.
|
The first line contains integer n (3 ≤ n < 300; n is odd). Each of the next n lines contains n small English letters — the description of Valera's paper.
|
Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes.
| null | null |
[{"input": "5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox", "output": "NO"}, {"input": "3\nwsw\nsws\nwsw", "output": "YES"}, {"input": "3\nxpx\npxp\nxpe", "output": "NO"}]
| 1,000 |
["implementation"]
| 47 |
[{"input": "5\r\nxooox\r\noxoxo\r\nsoxoo\r\noxoxo\r\nxooox\r\n", "output": "NO\r\n"}, {"input": "3\r\nwsw\r\nsws\r\nwsw\r\n", "output": "YES\r\n"}, {"input": "3\r\nxpx\r\npxp\r\nxpe\r\n", "output": "NO\r\n"}, {"input": "5\r\nliiil\r\nilili\r\niilii\r\nilili\r\nliiil\r\n", "output": "YES\r\n"}, {"input": "7\r\nbwccccb\r\nckcccbj\r\nccbcbcc\r\ncccbccc\r\nccbcbcc\r\ncbcccbc\r\nbccccdt\r\n", "output": "NO\r\n"}, {"input": "13\r\nsooooooooooos\r\nosoooooooooso\r\noosooooooosoo\r\nooosooooosooo\r\noooosooosoooo\r\nooooososooooo\r\noooooosoooooo\r\nooooososooooo\r\noooosooosoooo\r\nooosooooosooo\r\noosooooooosoo\r\nosoooooooooso\r\nsooooooooooos\r\n", "output": "YES\r\n"}, {"input": "3\r\naaa\r\naaa\r\naaa\r\n", "output": "NO\r\n"}, {"input": "3\r\naca\r\noec\r\nzba\r\n", "output": "NO\r\n"}, {"input": "15\r\nrxeeeeeeeeeeeer\r\nereeeeeeeeeeere\r\needeeeeeeeeeoee\r\neeereeeeeeeewee\r\neeeereeeeebeeee\r\nqeeeereeejedyee\r\neeeeeerereeeeee\r\neeeeeeereeeeeee\r\neeeeeerereeeeze\r\neeeeereeereeeee\r\neeeereeeeegeeee\r\neeereeeeeeereee\r\neereeeeeeqeeved\r\ncreeeeeeceeeere\r\nreeerneeeeeeeer\r\n", "output": "NO\r\n"}, {"input": "5\r\nxxxxx\r\nxxxxx\r\nxxxxx\r\nxxxxx\r\nxxxxx\r\n", "output": "NO\r\n"}, {"input": "5\r\nxxxxx\r\nxxxxx\r\nxoxxx\r\nxxxxx\r\nxxxxx\r\n", "output": "NO\r\n"}, {"input": "5\r\noxxxo\r\nxoxox\r\nxxxxx\r\nxoxox\r\noxxxo\r\n", "output": "NO\r\n"}, {"input": "5\r\noxxxo\r\nxoxox\r\nxxoox\r\nxoxox\r\noxxxo\r\n", "output": "NO\r\n"}, {"input": "5\r\noxxxo\r\nxoxox\r\nxxaxx\r\nxoxox\r\noxxxo\r\n", "output": "NO\r\n"}, {"input": "5\r\noxxxo\r\nxoxox\r\noxoxx\r\nxoxox\r\noxxxo\r\n", "output": "NO\r\n"}, {"input": "3\r\nxxx\r\naxa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\naxx\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\naxa\r\nxxx\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\nxxa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\naaa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\naax\r\naxa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxaa\r\naxa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\naxa\r\naax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\naxa\r\nxaa\r\n", "output": "NO\r\n"}, {"input": "3\r\nxfx\r\naxa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\nafa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\naxa\r\nxaf\r\n", "output": "NO\r\n"}, {"input": "3\r\nxox\r\nxxx\r\nxxx\r\n", "output": "NO\r\n"}, {"input": "3\r\naxa\r\naax\r\nxxa\r\n", "output": "NO\r\n"}, {"input": "3\r\nxox\r\noxx\r\nxox\r\n", "output": "NO\r\n"}, {"input": "3\r\nxox\r\nooo\r\nxox\r\n", "output": "NO\r\n"}, {"input": "3\r\naaa\r\naab\r\nbbb\r\n", "output": "NO\r\n"}, {"input": "3\r\nxxx\r\nsxs\r\nxsx\r\n", "output": "NO\r\n"}, {"input": "5\r\nabbba\r\nbabab\r\nbbbbb\r\nbaaab\r\nabbba\r\n", "output": "NO\r\n"}, {"input": "5\r\nabaaa\r\nbbbbb\r\nbbabb\r\nbabab\r\nabbba\r\n", "output": "NO\r\n"}, {"input": "5\r\nxoxox\r\noxoxo\r\nooxoo\r\noxoxo\r\nxooox\r\n", "output": "NO\r\n"}, {"input": "3\r\nxox\r\noxx\r\nxxx\r\n", "output": "NO\r\n"}, {"input": "5\r\nxoooo\r\noxooo\r\nooxoo\r\noooxo\r\noooox\r\n", "output": "NO\r\n"}, {"input": "5\r\nxoooo\r\noxoxx\r\nooxoo\r\noxoxo\r\noxoox\r\n", "output": "NO\r\n"}, {"input": "3\r\naaa\r\nbab\r\naba\r\n", "output": "NO\r\n"}]
| false |
stdio
| null | true |
350/A
|
350
|
A
|
PyPy 3
|
TESTS
| 22 | 280 | 0 |
94889590
|
n,m=map(int,input().split())
a=sorted(list(map(int,input().split())))
b=sorted(list(map(int,input().split())))
if max(a)<min(b):
if min(a)*2<max(a) and min(a)*2<min(b):
print(max(a))
elif min(a)*2>max(a) and min(a)*2<min(b):
print(min(a)*2)
else:
print(-1)
else:
print(-1)
| 45 | 62 | 0 |
221802631
|
nm=input().split()
n=int(nm[0])
m=int(nm[1])
correct=list(map(int,input().split()))
wrong=list(map(int,input().split()))
point4=True
TL=max(2*min(correct),max(correct))
if min(wrong)<=TL:
point4=False
if point4:
print(TL)
else:
print(-1)
|
Codeforces Round 203 (Div. 2)
|
CF
| 2,013 | 2 | 256 |
TL
|
Valera wanted to prepare a Codesecrof round. He's already got one problem and he wants to set a time limit (TL) on it.
Valera has written n correct solutions. For each correct solution, he knows its running time (in seconds). Valera has also wrote m wrong solutions and for each wrong solution he knows its running time (in seconds).
Let's suppose that Valera will set v seconds TL in the problem. Then we can say that a solution passes the system testing if its running time is at most v seconds. We can also say that a solution passes the system testing with some "extra" time if for its running time, a seconds, an inequality 2a ≤ v holds.
As a result, Valera decided to set v seconds TL, that the following conditions are met:
1. v is a positive integer;
2. all correct solutions pass the system testing;
3. at least one correct solution passes the system testing with some "extra" time;
4. all wrong solutions do not pass the system testing;
5. value v is minimum among all TLs, for which points 1, 2, 3, 4 hold.
Help Valera and find the most suitable TL or else state that such TL doesn't exist.
|
The first line contains two integers n, m (1 ≤ n, m ≤ 100). The second line contains n space-separated positive integers a1, a2, ..., an (1 ≤ ai ≤ 100) — the running time of each of the n correct solutions in seconds. The third line contains m space-separated positive integers b1, b2, ..., bm (1 ≤ bi ≤ 100) — the running time of each of m wrong solutions in seconds.
|
If there is a valid TL value, print it. Otherwise, print -1.
| null | null |
[{"input": "3 6\n4 5 2\n8 9 6 10 7 11", "output": "5"}, {"input": "3 1\n3 4 5\n6", "output": "-1"}]
| 1,200 |
["brute force", "greedy", "implementation"]
| 45 |
[{"input": "3 6\r\n4 5 2\r\n8 9 6 10 7 11\r\n", "output": "5"}, {"input": "3 1\r\n3 4 5\r\n6\r\n", "output": "-1\r\n"}, {"input": "2 5\r\n45 99\r\n49 41 77 83 45\r\n", "output": "-1\r\n"}, {"input": "50 50\r\n18 13 5 34 10 36 36 12 15 11 16 17 14 36 23 45 32 24 31 18 24 32 7 1 31 3 49 8 16 23 3 39 47 43 42 38 40 22 41 1 49 47 9 8 19 15 29 30 16 18\r\n91 58 86 51 94 94 73 84 98 69 74 56 52 80 88 61 53 99 88 50 55 95 65 84 87 79 51 52 69 60 74 73 93 61 73 59 64 56 95 78 86 72 79 70 93 78 54 61 71 50\r\n", "output": "49"}, {"input": "55 44\r\n93 17 74 15 34 16 41 80 26 54 94 94 86 93 20 44 63 72 39 43 67 4 37 49 76 94 5 51 64 74 11 47 77 97 57 30 42 72 71 26 8 14 67 64 49 57 30 23 40 4 76 78 87 78 79\r\n38 55 17 65 26 7 36 65 48 28 49 93 18 98 31 90 26 57 1 26 88 56 48 56 23 13 8 67 80 2 51 3 21 33 20 54 2 45 21 36 3 98 62 2\r\n", "output": "-1\r\n"}, {"input": "32 100\r\n30 8 4 35 18 41 18 12 33 39 39 18 39 19 33 46 45 33 34 27 14 39 40 21 38 9 42 35 27 10 14 14\r\n65 49 89 64 47 78 59 52 73 51 84 82 88 63 91 99 67 87 53 99 75 47 85 82 58 47 80 50 65 91 83 90 77 52 100 88 97 74 98 99 50 93 65 61 65 65 65 96 61 51 84 67 79 90 92 83 100 100 100 95 80 54 77 51 98 64 74 62 60 96 73 74 94 55 89 60 92 65 74 79 66 81 53 47 71 51 54 85 74 97 68 72 88 94 100 85 65 63 65 90\r\n", "output": "46"}, {"input": "1 50\r\n7\r\n65 52 99 78 71 19 96 72 80 15 50 94 20 35 79 95 44 41 45 53 77 50 74 66 59 96 26 84 27 48 56 84 36 78 89 81 67 34 79 74 99 47 93 92 90 96 72 28 78 66\r\n", "output": "14"}, {"input": "1 1\r\n4\r\n9\r\n", "output": "8"}, {"input": "1 1\r\n2\r\n4\r\n", "output": "-1\r\n"}, {"input": "22 56\r\n49 20 42 68 15 46 98 78 82 8 7 33 50 30 75 96 36 88 35 99 19 87\r\n15 18 81 24 35 89 25 32 23 3 48 24 52 69 18 32 23 61 48 98 50 38 5 17 70 20 38 32 49 54 68 11 51 81 46 22 19 59 29 38 45 83 18 13 91 17 84 62 25 60 97 32 23 13 83 58\r\n", "output": "-1\r\n"}, {"input": "1 1\r\n50\r\n100\r\n", "output": "-1\r\n"}, {"input": "1 1\r\n49\r\n100\r\n", "output": "98"}, {"input": "1 1\r\n100\r\n100\r\n", "output": "-1\r\n"}, {"input": "1 1\r\n99\r\n100\r\n", "output": "-1\r\n"}, {"input": "8 4\r\n1 2 49 99 99 95 78 98\r\n100 100 100 100\r\n", "output": "99"}, {"input": "68 85\r\n43 55 2 4 72 45 19 56 53 81 18 90 11 87 47 8 94 88 24 4 67 9 21 70 25 66 65 27 46 13 8 51 65 99 37 43 71 59 71 79 32 56 49 43 57 85 95 81 40 28 60 36 72 81 60 40 16 78 61 37 29 26 15 95 70 27 50 97\r\n6 6 48 72 54 31 1 50 29 64 93 9 29 93 66 63 25 90 52 1 66 13 70 30 24 87 32 90 84 72 44 13 25 45 31 16 92 60 87 40 62 7 20 63 86 78 73 88 5 36 74 100 64 34 9 5 62 29 58 48 81 46 84 56 27 1 60 14 54 88 31 93 62 7 9 69 27 48 10 5 33 10 53 66 2\r\n", "output": "-1\r\n"}, {"input": "5 100\r\n1 1 1 1 1\r\n77 53 38 29 97 33 64 17 78 100 27 12 42 44 20 24 44 68 58 57 65 90 8 24 4 6 74 68 61 43 25 69 8 62 36 85 67 48 69 30 35 41 42 12 87 66 50 92 53 76 38 67 85 7 80 78 53 76 94 8 37 50 4 100 4 71 10 48 34 47 83 42 25 81 64 72 25 51 53 75 43 98 53 77 94 38 81 15 89 91 72 76 7 36 27 41 88 18 19 75\r\n", "output": "2"}, {"input": "3 3\r\n2 3 4\r\n8 9 10\r\n", "output": "4"}, {"input": "2 1\r\n2 3\r\n15\r\n", "output": "4"}, {"input": "2 1\r\n2 4\r\n4\r\n", "output": "-1\r\n"}, {"input": "2 3\r\n4 5\r\n10 11 12\r\n", "output": "8"}, {"input": "3 1\r\n2 3 3\r\n5\r\n", "output": "4"}, {"input": "2 1\r\n9 10\r\n100\r\n", "output": "18"}, {"input": "3 3\r\n3 12 15\r\n7 8 9\r\n", "output": "-1\r\n"}, {"input": "2 2\r\n3 5\r\n7 8\r\n", "output": "6"}, {"input": "3 3\r\n4 5 6\r\n10 11 12\r\n", "output": "8"}, {"input": "3 5\r\n2 3 3\r\n6 6 6 6 2\r\n", "output": "-1\r\n"}, {"input": "3 6\r\n4 5 3\r\n8 9 7 10 7 11\r\n", "output": "6"}, {"input": "3 6\r\n4 5 2\r\n8 9 6 10 7 4\r\n", "output": "-1\r\n"}, {"input": "2 1\r\n4 6\r\n10\r\n", "output": "8"}, {"input": "1 2\r\n1\r\n3 1\r\n", "output": "-1\r\n"}, {"input": "2 1\r\n5 6\r\n20\r\n", "output": "10"}, {"input": "2 1\r\n1 5\r\n5\r\n", "output": "-1\r\n"}, {"input": "3 2\r\n10 20 30\r\n30 40\r\n", "output": "-1\r\n"}, {"input": "2 2\r\n5 6\r\n7 100\r\n", "output": "-1\r\n"}, {"input": "2 1\r\n2 5\r\n7\r\n", "output": "5"}, {"input": "1 1\r\n5\r\n20\r\n", "output": "10"}, {"input": "2 1\r\n10 11\r\n100\r\n", "output": "20"}, {"input": "1 1\r\n1\r\n10\r\n", "output": "2"}, {"input": "1 1\r\n10\r\n100\r\n", "output": "20"}]
| false |
stdio
| null | true |
350/A
|
350
|
A
|
PyPy 3
|
TESTS
| 22 | 312 | 0 |
67623801
|
n,m=map(int,input().split())
R=list(map(int,input().split()))
W=list(map(int,input().split()))
R.sort()
W.sort()
if max(R)<min(W):
for i in R:
if i*2<max(R):
print(max(R))
break
else:
for i in R:
if max(R)<i*2<min(W):
print(i*2)
break
else:
print(-1)
else:
print(-1)
| 45 | 92 | 0 |
4621548
|
import sys
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
b.sort()
ans = a[0] * 2
if ans < a[-1]:
ans = a[-1]
if ans >= b[0]:
print(-1)
sys.exit()
print(ans)
|
Codeforces Round 203 (Div. 2)
|
CF
| 2,013 | 2 | 256 |
TL
|
Valera wanted to prepare a Codesecrof round. He's already got one problem and he wants to set a time limit (TL) on it.
Valera has written n correct solutions. For each correct solution, he knows its running time (in seconds). Valera has also wrote m wrong solutions and for each wrong solution he knows its running time (in seconds).
Let's suppose that Valera will set v seconds TL in the problem. Then we can say that a solution passes the system testing if its running time is at most v seconds. We can also say that a solution passes the system testing with some "extra" time if for its running time, a seconds, an inequality 2a ≤ v holds.
As a result, Valera decided to set v seconds TL, that the following conditions are met:
1. v is a positive integer;
2. all correct solutions pass the system testing;
3. at least one correct solution passes the system testing with some "extra" time;
4. all wrong solutions do not pass the system testing;
5. value v is minimum among all TLs, for which points 1, 2, 3, 4 hold.
Help Valera and find the most suitable TL or else state that such TL doesn't exist.
|
The first line contains two integers n, m (1 ≤ n, m ≤ 100). The second line contains n space-separated positive integers a1, a2, ..., an (1 ≤ ai ≤ 100) — the running time of each of the n correct solutions in seconds. The third line contains m space-separated positive integers b1, b2, ..., bm (1 ≤ bi ≤ 100) — the running time of each of m wrong solutions in seconds.
|
If there is a valid TL value, print it. Otherwise, print -1.
| null | null |
[{"input": "3 6\n4 5 2\n8 9 6 10 7 11", "output": "5"}, {"input": "3 1\n3 4 5\n6", "output": "-1"}]
| 1,200 |
["brute force", "greedy", "implementation"]
| 45 |
[{"input": "3 6\r\n4 5 2\r\n8 9 6 10 7 11\r\n", "output": "5"}, {"input": "3 1\r\n3 4 5\r\n6\r\n", "output": "-1\r\n"}, {"input": "2 5\r\n45 99\r\n49 41 77 83 45\r\n", "output": "-1\r\n"}, {"input": "50 50\r\n18 13 5 34 10 36 36 12 15 11 16 17 14 36 23 45 32 24 31 18 24 32 7 1 31 3 49 8 16 23 3 39 47 43 42 38 40 22 41 1 49 47 9 8 19 15 29 30 16 18\r\n91 58 86 51 94 94 73 84 98 69 74 56 52 80 88 61 53 99 88 50 55 95 65 84 87 79 51 52 69 60 74 73 93 61 73 59 64 56 95 78 86 72 79 70 93 78 54 61 71 50\r\n", "output": "49"}, {"input": "55 44\r\n93 17 74 15 34 16 41 80 26 54 94 94 86 93 20 44 63 72 39 43 67 4 37 49 76 94 5 51 64 74 11 47 77 97 57 30 42 72 71 26 8 14 67 64 49 57 30 23 40 4 76 78 87 78 79\r\n38 55 17 65 26 7 36 65 48 28 49 93 18 98 31 90 26 57 1 26 88 56 48 56 23 13 8 67 80 2 51 3 21 33 20 54 2 45 21 36 3 98 62 2\r\n", "output": "-1\r\n"}, {"input": "32 100\r\n30 8 4 35 18 41 18 12 33 39 39 18 39 19 33 46 45 33 34 27 14 39 40 21 38 9 42 35 27 10 14 14\r\n65 49 89 64 47 78 59 52 73 51 84 82 88 63 91 99 67 87 53 99 75 47 85 82 58 47 80 50 65 91 83 90 77 52 100 88 97 74 98 99 50 93 65 61 65 65 65 96 61 51 84 67 79 90 92 83 100 100 100 95 80 54 77 51 98 64 74 62 60 96 73 74 94 55 89 60 92 65 74 79 66 81 53 47 71 51 54 85 74 97 68 72 88 94 100 85 65 63 65 90\r\n", "output": "46"}, {"input": "1 50\r\n7\r\n65 52 99 78 71 19 96 72 80 15 50 94 20 35 79 95 44 41 45 53 77 50 74 66 59 96 26 84 27 48 56 84 36 78 89 81 67 34 79 74 99 47 93 92 90 96 72 28 78 66\r\n", "output": "14"}, {"input": "1 1\r\n4\r\n9\r\n", "output": "8"}, {"input": "1 1\r\n2\r\n4\r\n", "output": "-1\r\n"}, {"input": "22 56\r\n49 20 42 68 15 46 98 78 82 8 7 33 50 30 75 96 36 88 35 99 19 87\r\n15 18 81 24 35 89 25 32 23 3 48 24 52 69 18 32 23 61 48 98 50 38 5 17 70 20 38 32 49 54 68 11 51 81 46 22 19 59 29 38 45 83 18 13 91 17 84 62 25 60 97 32 23 13 83 58\r\n", "output": "-1\r\n"}, {"input": "1 1\r\n50\r\n100\r\n", "output": "-1\r\n"}, {"input": "1 1\r\n49\r\n100\r\n", "output": "98"}, {"input": "1 1\r\n100\r\n100\r\n", "output": "-1\r\n"}, {"input": "1 1\r\n99\r\n100\r\n", "output": "-1\r\n"}, {"input": "8 4\r\n1 2 49 99 99 95 78 98\r\n100 100 100 100\r\n", "output": "99"}, {"input": "68 85\r\n43 55 2 4 72 45 19 56 53 81 18 90 11 87 47 8 94 88 24 4 67 9 21 70 25 66 65 27 46 13 8 51 65 99 37 43 71 59 71 79 32 56 49 43 57 85 95 81 40 28 60 36 72 81 60 40 16 78 61 37 29 26 15 95 70 27 50 97\r\n6 6 48 72 54 31 1 50 29 64 93 9 29 93 66 63 25 90 52 1 66 13 70 30 24 87 32 90 84 72 44 13 25 45 31 16 92 60 87 40 62 7 20 63 86 78 73 88 5 36 74 100 64 34 9 5 62 29 58 48 81 46 84 56 27 1 60 14 54 88 31 93 62 7 9 69 27 48 10 5 33 10 53 66 2\r\n", "output": "-1\r\n"}, {"input": "5 100\r\n1 1 1 1 1\r\n77 53 38 29 97 33 64 17 78 100 27 12 42 44 20 24 44 68 58 57 65 90 8 24 4 6 74 68 61 43 25 69 8 62 36 85 67 48 69 30 35 41 42 12 87 66 50 92 53 76 38 67 85 7 80 78 53 76 94 8 37 50 4 100 4 71 10 48 34 47 83 42 25 81 64 72 25 51 53 75 43 98 53 77 94 38 81 15 89 91 72 76 7 36 27 41 88 18 19 75\r\n", "output": "2"}, {"input": "3 3\r\n2 3 4\r\n8 9 10\r\n", "output": "4"}, {"input": "2 1\r\n2 3\r\n15\r\n", "output": "4"}, {"input": "2 1\r\n2 4\r\n4\r\n", "output": "-1\r\n"}, {"input": "2 3\r\n4 5\r\n10 11 12\r\n", "output": "8"}, {"input": "3 1\r\n2 3 3\r\n5\r\n", "output": "4"}, {"input": "2 1\r\n9 10\r\n100\r\n", "output": "18"}, {"input": "3 3\r\n3 12 15\r\n7 8 9\r\n", "output": "-1\r\n"}, {"input": "2 2\r\n3 5\r\n7 8\r\n", "output": "6"}, {"input": "3 3\r\n4 5 6\r\n10 11 12\r\n", "output": "8"}, {"input": "3 5\r\n2 3 3\r\n6 6 6 6 2\r\n", "output": "-1\r\n"}, {"input": "3 6\r\n4 5 3\r\n8 9 7 10 7 11\r\n", "output": "6"}, {"input": "3 6\r\n4 5 2\r\n8 9 6 10 7 4\r\n", "output": "-1\r\n"}, {"input": "2 1\r\n4 6\r\n10\r\n", "output": "8"}, {"input": "1 2\r\n1\r\n3 1\r\n", "output": "-1\r\n"}, {"input": "2 1\r\n5 6\r\n20\r\n", "output": "10"}, {"input": "2 1\r\n1 5\r\n5\r\n", "output": "-1\r\n"}, {"input": "3 2\r\n10 20 30\r\n30 40\r\n", "output": "-1\r\n"}, {"input": "2 2\r\n5 6\r\n7 100\r\n", "output": "-1\r\n"}, {"input": "2 1\r\n2 5\r\n7\r\n", "output": "5"}, {"input": "1 1\r\n5\r\n20\r\n", "output": "10"}, {"input": "2 1\r\n10 11\r\n100\r\n", "output": "20"}, {"input": "1 1\r\n1\r\n10\r\n", "output": "2"}, {"input": "1 1\r\n10\r\n100\r\n", "output": "20"}]
| false |
stdio
| null | true |
350/A
|
350
|
A
|
PyPy 3
|
TESTS
| 22 | 186 | 0 |
107026149
|
n,m = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
s = max(a)
t = min(a)
u = min(b)
if s>u:
print(-1)
elif n==1:
if s*2<u:
print(s*2)
else:
print(-1)
else:
if t*2>s and t*2<u:
print(t*2)
elif t*2<s and s<u:
print(s)
else:
print(-1)
| 45 | 92 | 0 |
4621819
|
n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
mi = min(a)
ma = max(a)
k = min(b)
if (2 * mi <= ma):
v = ma
else:
v = 2 * mi
if v >= k:
print(-1)
else:
print(v)
|
Codeforces Round 203 (Div. 2)
|
CF
| 2,013 | 2 | 256 |
TL
|
Valera wanted to prepare a Codesecrof round. He's already got one problem and he wants to set a time limit (TL) on it.
Valera has written n correct solutions. For each correct solution, he knows its running time (in seconds). Valera has also wrote m wrong solutions and for each wrong solution he knows its running time (in seconds).
Let's suppose that Valera will set v seconds TL in the problem. Then we can say that a solution passes the system testing if its running time is at most v seconds. We can also say that a solution passes the system testing with some "extra" time if for its running time, a seconds, an inequality 2a ≤ v holds.
As a result, Valera decided to set v seconds TL, that the following conditions are met:
1. v is a positive integer;
2. all correct solutions pass the system testing;
3. at least one correct solution passes the system testing with some "extra" time;
4. all wrong solutions do not pass the system testing;
5. value v is minimum among all TLs, for which points 1, 2, 3, 4 hold.
Help Valera and find the most suitable TL or else state that such TL doesn't exist.
|
The first line contains two integers n, m (1 ≤ n, m ≤ 100). The second line contains n space-separated positive integers a1, a2, ..., an (1 ≤ ai ≤ 100) — the running time of each of the n correct solutions in seconds. The third line contains m space-separated positive integers b1, b2, ..., bm (1 ≤ bi ≤ 100) — the running time of each of m wrong solutions in seconds.
|
If there is a valid TL value, print it. Otherwise, print -1.
| null | null |
[{"input": "3 6\n4 5 2\n8 9 6 10 7 11", "output": "5"}, {"input": "3 1\n3 4 5\n6", "output": "-1"}]
| 1,200 |
["brute force", "greedy", "implementation"]
| 45 |
[{"input": "3 6\r\n4 5 2\r\n8 9 6 10 7 11\r\n", "output": "5"}, {"input": "3 1\r\n3 4 5\r\n6\r\n", "output": "-1\r\n"}, {"input": "2 5\r\n45 99\r\n49 41 77 83 45\r\n", "output": "-1\r\n"}, {"input": "50 50\r\n18 13 5 34 10 36 36 12 15 11 16 17 14 36 23 45 32 24 31 18 24 32 7 1 31 3 49 8 16 23 3 39 47 43 42 38 40 22 41 1 49 47 9 8 19 15 29 30 16 18\r\n91 58 86 51 94 94 73 84 98 69 74 56 52 80 88 61 53 99 88 50 55 95 65 84 87 79 51 52 69 60 74 73 93 61 73 59 64 56 95 78 86 72 79 70 93 78 54 61 71 50\r\n", "output": "49"}, {"input": "55 44\r\n93 17 74 15 34 16 41 80 26 54 94 94 86 93 20 44 63 72 39 43 67 4 37 49 76 94 5 51 64 74 11 47 77 97 57 30 42 72 71 26 8 14 67 64 49 57 30 23 40 4 76 78 87 78 79\r\n38 55 17 65 26 7 36 65 48 28 49 93 18 98 31 90 26 57 1 26 88 56 48 56 23 13 8 67 80 2 51 3 21 33 20 54 2 45 21 36 3 98 62 2\r\n", "output": "-1\r\n"}, {"input": "32 100\r\n30 8 4 35 18 41 18 12 33 39 39 18 39 19 33 46 45 33 34 27 14 39 40 21 38 9 42 35 27 10 14 14\r\n65 49 89 64 47 78 59 52 73 51 84 82 88 63 91 99 67 87 53 99 75 47 85 82 58 47 80 50 65 91 83 90 77 52 100 88 97 74 98 99 50 93 65 61 65 65 65 96 61 51 84 67 79 90 92 83 100 100 100 95 80 54 77 51 98 64 74 62 60 96 73 74 94 55 89 60 92 65 74 79 66 81 53 47 71 51 54 85 74 97 68 72 88 94 100 85 65 63 65 90\r\n", "output": "46"}, {"input": "1 50\r\n7\r\n65 52 99 78 71 19 96 72 80 15 50 94 20 35 79 95 44 41 45 53 77 50 74 66 59 96 26 84 27 48 56 84 36 78 89 81 67 34 79 74 99 47 93 92 90 96 72 28 78 66\r\n", "output": "14"}, {"input": "1 1\r\n4\r\n9\r\n", "output": "8"}, {"input": "1 1\r\n2\r\n4\r\n", "output": "-1\r\n"}, {"input": "22 56\r\n49 20 42 68 15 46 98 78 82 8 7 33 50 30 75 96 36 88 35 99 19 87\r\n15 18 81 24 35 89 25 32 23 3 48 24 52 69 18 32 23 61 48 98 50 38 5 17 70 20 38 32 49 54 68 11 51 81 46 22 19 59 29 38 45 83 18 13 91 17 84 62 25 60 97 32 23 13 83 58\r\n", "output": "-1\r\n"}, {"input": "1 1\r\n50\r\n100\r\n", "output": "-1\r\n"}, {"input": "1 1\r\n49\r\n100\r\n", "output": "98"}, {"input": "1 1\r\n100\r\n100\r\n", "output": "-1\r\n"}, {"input": "1 1\r\n99\r\n100\r\n", "output": "-1\r\n"}, {"input": "8 4\r\n1 2 49 99 99 95 78 98\r\n100 100 100 100\r\n", "output": "99"}, {"input": "68 85\r\n43 55 2 4 72 45 19 56 53 81 18 90 11 87 47 8 94 88 24 4 67 9 21 70 25 66 65 27 46 13 8 51 65 99 37 43 71 59 71 79 32 56 49 43 57 85 95 81 40 28 60 36 72 81 60 40 16 78 61 37 29 26 15 95 70 27 50 97\r\n6 6 48 72 54 31 1 50 29 64 93 9 29 93 66 63 25 90 52 1 66 13 70 30 24 87 32 90 84 72 44 13 25 45 31 16 92 60 87 40 62 7 20 63 86 78 73 88 5 36 74 100 64 34 9 5 62 29 58 48 81 46 84 56 27 1 60 14 54 88 31 93 62 7 9 69 27 48 10 5 33 10 53 66 2\r\n", "output": "-1\r\n"}, {"input": "5 100\r\n1 1 1 1 1\r\n77 53 38 29 97 33 64 17 78 100 27 12 42 44 20 24 44 68 58 57 65 90 8 24 4 6 74 68 61 43 25 69 8 62 36 85 67 48 69 30 35 41 42 12 87 66 50 92 53 76 38 67 85 7 80 78 53 76 94 8 37 50 4 100 4 71 10 48 34 47 83 42 25 81 64 72 25 51 53 75 43 98 53 77 94 38 81 15 89 91 72 76 7 36 27 41 88 18 19 75\r\n", "output": "2"}, {"input": "3 3\r\n2 3 4\r\n8 9 10\r\n", "output": "4"}, {"input": "2 1\r\n2 3\r\n15\r\n", "output": "4"}, {"input": "2 1\r\n2 4\r\n4\r\n", "output": "-1\r\n"}, {"input": "2 3\r\n4 5\r\n10 11 12\r\n", "output": "8"}, {"input": "3 1\r\n2 3 3\r\n5\r\n", "output": "4"}, {"input": "2 1\r\n9 10\r\n100\r\n", "output": "18"}, {"input": "3 3\r\n3 12 15\r\n7 8 9\r\n", "output": "-1\r\n"}, {"input": "2 2\r\n3 5\r\n7 8\r\n", "output": "6"}, {"input": "3 3\r\n4 5 6\r\n10 11 12\r\n", "output": "8"}, {"input": "3 5\r\n2 3 3\r\n6 6 6 6 2\r\n", "output": "-1\r\n"}, {"input": "3 6\r\n4 5 3\r\n8 9 7 10 7 11\r\n", "output": "6"}, {"input": "3 6\r\n4 5 2\r\n8 9 6 10 7 4\r\n", "output": "-1\r\n"}, {"input": "2 1\r\n4 6\r\n10\r\n", "output": "8"}, {"input": "1 2\r\n1\r\n3 1\r\n", "output": "-1\r\n"}, {"input": "2 1\r\n5 6\r\n20\r\n", "output": "10"}, {"input": "2 1\r\n1 5\r\n5\r\n", "output": "-1\r\n"}, {"input": "3 2\r\n10 20 30\r\n30 40\r\n", "output": "-1\r\n"}, {"input": "2 2\r\n5 6\r\n7 100\r\n", "output": "-1\r\n"}, {"input": "2 1\r\n2 5\r\n7\r\n", "output": "5"}, {"input": "1 1\r\n5\r\n20\r\n", "output": "10"}, {"input": "2 1\r\n10 11\r\n100\r\n", "output": "20"}, {"input": "1 1\r\n1\r\n10\r\n", "output": "2"}, {"input": "1 1\r\n10\r\n100\r\n", "output": "20"}]
| false |
stdio
| null | true |
583/B
|
583
|
B
|
Python 3
|
TESTS
| 3 | 46 | 0 |
13511035
|
n = int(input())
computers = [int(item) for item in input().split()]
count = 0
turnCount = -1
index = 0
visited = []
step = 0
while count < n:
if index == n-1:
step = -1
if len(visited) < n-1 or n-1 in visited:
turnCount += 1
elif index == 0:
step = 1
if len(visited) < n-1 or 0 in visited:
turnCount += 1
if computers[index] <= count and index not in visited:
count += 1
visited.append(index)
index += step
print(turnCount)
| 56 | 93 | 1,536,000 |
197745534
|
n=int(input())
a=list(map(int,input().split()))
s=0
r=0
i=0
k=1
f=0
while s!=n:
if a[i]<=s:
s+=1
a[i]=9999
if (s!=n)and((i==n-1)or((i==0)and(f))):
r+=1
k*=-1
f=1
i+=k
print(r)
|
Codeforces Round 323 (Div. 2)
|
CF
| 2,015 | 1 | 256 |
Robot's Task
|
Robot Doc is located in the hall, with n computers stand in a line, numbered from left to right from 1 to n. Each computer contains exactly one piece of information, each of which Doc wants to get eventually. The computers are equipped with a security system, so to crack the i-th of them, the robot needs to collect at least ai any pieces of information from the other computers. Doc can hack the computer only if he is right next to it.
The robot is assembled using modern technologies and can move along the line of computers in either of the two possible directions, but the change of direction requires a large amount of resources from Doc. Tell the minimum number of changes of direction, which the robot will have to make to collect all n parts of information if initially it is next to computer with number 1.
It is guaranteed that there exists at least one sequence of the robot's actions, which leads to the collection of all information. Initially Doc doesn't have any pieces of information.
|
The first line contains number n (1 ≤ n ≤ 1000). The second line contains n non-negative integers a1, a2, ..., an (0 ≤ ai < n), separated by a space. It is guaranteed that there exists a way for robot to collect all pieces of the information.
|
Print a single number — the minimum number of changes in direction that the robot will have to make in order to collect all n parts of information.
| null |
In the first sample you can assemble all the pieces of information in the optimal manner by assembling first the piece of information in the first computer, then in the third one, then change direction and move to the second one, and then, having 2 pieces of information, collect the last piece.
In the second sample to collect all the pieces of information in the optimal manner, Doc can go to the fourth computer and get the piece of information, then go to the fifth computer with one piece and get another one, then go to the second computer in the same manner, then to the third one and finally, to the first one. Changes of direction will take place before moving from the fifth to the second computer, then from the second to the third computer, then from the third to the first computer.
In the third sample the optimal order of collecting parts from computers can look like that: 1->3->4->6->2->5->7.
|
[{"input": "3\n0 2 0", "output": "1"}, {"input": "5\n4 2 3 0 1", "output": "3"}, {"input": "7\n0 3 1 0 5 2 6", "output": "2"}]
| 1,200 |
["greedy", "implementation"]
| 56 |
[{"input": "3\r\n0 2 0\r\n", "output": "1\r\n"}, {"input": "5\r\n4 2 3 0 1\r\n", "output": "3\r\n"}, {"input": "7\r\n0 3 1 0 5 2 6\r\n", "output": "2\r\n"}, {"input": "1\r\n0\r\n", "output": "0\r\n"}, {"input": "2\r\n0 1\r\n", "output": "0\r\n"}, {"input": "10\r\n0 0 0 0 0 0 0 0 0 0\r\n", "output": "0\r\n"}, {"input": "3\r\n0 2 1\r\n", "output": "1\r\n"}, {"input": "10\r\n7 1 9 3 5 8 6 0 2 4\r\n", "output": "9\r\n"}, {"input": "10\r\n1 3 5 7 9 8 6 4 2 0\r\n", "output": "9\r\n"}, {"input": "10\r\n5 0 0 1 3 2 2 2 5 7\r\n", "output": "1\r\n"}, {"input": "10\r\n8 6 5 3 9 7 1 4 2 0\r\n", "output": "8\r\n"}, {"input": "10\r\n1 2 4 5 0 1 3 7 1 4\r\n", "output": "2\r\n"}, {"input": "10\r\n3 4 8 9 5 1 2 0 6 7\r\n", "output": "6\r\n"}, {"input": "10\r\n2 2 0 0 6 2 9 0 2 0\r\n", "output": "2\r\n"}, {"input": "10\r\n1 7 5 3 2 6 0 8 4 9\r\n", "output": "8\r\n"}, {"input": "9\r\n1 3 8 6 2 4 5 0 7\r\n", "output": "7\r\n"}, {"input": "9\r\n1 3 5 7 8 6 4 2 0\r\n", "output": "8\r\n"}, {"input": "9\r\n2 4 3 1 3 0 5 4 3\r\n", "output": "3\r\n"}, {"input": "9\r\n3 5 6 8 7 0 4 2 1\r\n", "output": "5\r\n"}, {"input": "9\r\n2 0 8 1 0 3 0 5 3\r\n", "output": "2\r\n"}, {"input": "9\r\n6 2 3 7 4 8 5 1 0\r\n", "output": "4\r\n"}, {"input": "9\r\n3 1 5 6 0 3 2 0 0\r\n", "output": "2\r\n"}, {"input": "9\r\n2 6 4 1 0 8 5 3 7\r\n", "output": "7\r\n"}, {"input": "100\r\n27 20 18 78 93 38 56 2 48 75 36 88 96 57 69 10 25 74 68 86 65 85 66 14 22 12 43 80 99 34 42 63 61 71 77 15 37 54 21 59 23 94 28 30 50 84 62 76 47 16 26 64 82 92 72 53 17 11 41 91 35 83 79 95 67 13 1 7 3 4 73 90 8 19 33 58 98 32 39 45 87 52 60 46 6 44 49 70 51 9 5 29 31 24 40 97 81 0 89 55\r\n", "output": "69\r\n"}, {"input": "100\r\n1 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 98 96 94 92 90 88 86 84 82 80 78 76 74 72 70 68 66 64 62 60 58 56 54 52 50 48 46 44 42 40 38 36 34 32 30 28 26 24 22 20 18 16 14 12 10 8 6 4 2 0\r\n", "output": "99\r\n"}, {"input": "100\r\n13 89 81 0 62 1 59 92 29 13 1 37 2 8 53 15 20 34 12 70 0 85 97 55 84 60 37 54 14 65 22 69 30 22 95 44 59 85 50 80 9 71 91 93 74 21 11 78 28 21 40 81 76 24 26 60 48 85 61 68 89 76 46 73 34 52 98 29 4 38 94 51 5 55 6 27 74 27 38 37 82 70 44 89 51 59 30 37 15 55 63 78 42 39 71 43 4 10 2 13\r\n", "output": "21\r\n"}, {"input": "100\r\n1 3 5 7 58 11 13 15 17 19 45 23 25 27 29 31 33 35 37 39 41 43 21 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 81 79 83 85 87 89 91 93 95 97 48 98 96 94 92 90 88 44 84 82 80 78 76 74 72 70 68 66 64 62 60 9 56 54 52 50 99 46 86 42 40 38 36 34 32 30 28 26 24 22 20 18 16 14 12 10 8 6 4 2 0\r\n", "output": "96\r\n"}, {"input": "100\r\n32 47 74 8 14 4 12 68 18 0 44 80 14 38 6 57 4 72 69 3 21 78 74 22 39 32 58 63 34 33 23 6 39 11 6 12 18 4 0 11 20 28 16 1 22 12 57 55 13 48 43 1 50 18 87 6 11 45 38 67 37 14 7 56 6 41 1 55 5 73 78 64 38 18 38 8 37 0 18 61 37 58 58 62 86 5 0 2 15 43 34 61 2 21 15 9 69 1 11 24\r\n", "output": "4\r\n"}, {"input": "100\r\n40 3 55 7 6 77 13 46 17 64 21 54 25 27 91 41 1 15 37 82 23 43 42 47 26 95 53 5 11 59 61 9 78 67 69 58 73 0 36 79 60 83 2 87 63 33 71 89 97 99 98 93 56 92 19 88 86 84 39 28 65 20 34 76 51 94 66 12 62 49 96 72 24 52 48 50 44 35 74 31 38 57 81 32 22 80 70 29 30 18 68 16 14 90 10 8 85 4 45 75\r\n", "output": "75\r\n"}, {"input": "100\r\n34 16 42 21 84 27 11 7 82 16 95 39 36 64 26 0 38 37 2 2 16 56 16 61 55 42 26 5 61 8 30 20 19 15 9 78 5 34 15 0 3 17 36 36 1 5 4 26 18 0 14 25 7 5 91 7 43 26 79 37 17 27 40 55 66 7 0 2 16 23 68 35 2 5 9 21 1 7 2 9 4 3 22 15 27 6 0 47 5 0 12 9 20 55 36 10 6 8 5 1\r\n", "output": "3\r\n"}, {"input": "100\r\n35 53 87 49 13 24 93 20 5 11 31 32 40 52 96 46 1 25 66 69 28 88 84 82 70 9 75 39 26 21 18 29 23 57 90 16 48 22 95 0 58 43 7 73 8 62 63 30 64 92 79 3 6 94 34 12 76 99 67 55 56 97 14 91 68 36 44 78 41 71 86 89 47 74 4 45 98 37 80 33 83 27 42 59 72 54 17 60 51 81 15 77 65 50 10 85 61 19 38 2\r\n", "output": "67\r\n"}, {"input": "99\r\n89 96 56 31 32 14 9 66 87 34 69 5 92 54 41 52 46 30 22 26 16 18 20 68 62 73 90 43 79 33 58 98 37 45 10 78 94 51 19 0 91 39 28 47 17 86 3 61 77 7 15 64 55 83 65 71 97 88 6 48 24 11 8 42 81 4 63 93 50 74 35 12 95 27 53 82 29 85 84 60 72 40 36 57 23 13 38 59 49 1 75 44 76 2 21 25 70 80 67\r\n", "output": "75\r\n"}, {"input": "99\r\n1 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 98 96 94 92 90 88 86 84 82 80 78 76 74 72 70 68 66 64 62 60 58 56 54 52 50 48 46 44 42 40 38 36 34 32 30 28 26 24 22 20 18 16 14 12 10 8 6 4 2 0\r\n", "output": "98\r\n"}, {"input": "99\r\n82 7 6 77 17 28 90 3 68 12 63 60 24 20 4 81 71 85 57 45 11 84 3 91 49 34 89 82 0 50 48 88 36 76 36 5 62 48 20 2 20 45 69 27 37 62 42 31 57 51 92 84 89 25 7 62 12 23 23 56 30 90 27 10 77 58 48 38 56 68 57 15 33 1 34 67 16 47 75 70 69 28 38 16 5 61 85 76 44 90 37 22 77 94 55 1 97 8 69\r\n", "output": "22\r\n"}, {"input": "99\r\n1 51 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 42 43 45 47 49 3 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 98 96 94 92 90 88 86 84 82 80 8 76 74 72 70 68 66 22 62 60 58 56 54 52 0 48 46 44 41 40 38 36 34 32 30 28 26 24 64 20 18 16 14 12 10 78 6 4 2 50\r\n", "output": "96\r\n"}, {"input": "99\r\n22 3 19 13 65 87 28 17 41 40 31 21 8 37 29 65 65 53 16 33 13 5 76 4 72 9 2 76 57 72 50 15 75 0 30 13 83 36 12 31 49 51 65 22 48 31 60 15 2 17 6 1 8 0 1 63 3 16 7 7 2 1 47 28 26 21 2 36 1 5 20 25 44 0 2 39 46 30 33 11 15 34 34 4 84 52 0 39 7 3 17 15 6 38 52 64 26 1 0\r\n", "output": "3\r\n"}, {"input": "99\r\n24 87 25 82 97 11 37 15 23 19 34 17 76 13 45 89 33 1 27 78 63 43 54 47 49 2 42 41 75 83 61 90 65 67 21 71 60 57 77 62 81 58 85 69 3 91 68 55 72 93 29 94 66 16 88 86 84 53 14 39 35 44 9 70 80 92 56 79 74 5 64 31 52 50 48 46 51 59 40 38 36 96 32 30 28 95 7 22 20 18 26 73 12 10 8 6 4 98 0\r\n", "output": "74\r\n"}, {"input": "99\r\n22 14 0 44 6 17 6 6 37 45 0 48 19 8 57 8 10 0 3 12 25 2 5 53 9 49 15 6 38 14 9 40 38 22 27 12 64 10 11 35 89 19 46 39 12 24 48 0 52 1 27 27 24 4 64 24 5 0 67 3 5 39 0 1 13 37 2 8 46 1 28 70 6 79 14 15 33 6 7 34 6 18 4 71 1 55 33 71 18 11 47 23 72 53 65 32 2 7 28\r\n", "output": "3\r\n"}, {"input": "99\r\n28 59 73 89 52 27 0 20 36 12 83 95 31 24 54 94 49 14 51 34 50 93 13 1 2 68 63 48 41 81 23 43 18 9 16 38 33 60 62 3 40 85 72 69 90 98 11 37 22 44 35 6 21 39 82 10 64 66 96 42 74 30 8 67 97 46 84 32 17 57 75 71 5 26 4 55 58 29 7 15 45 19 92 91 78 65 88 25 86 80 77 87 79 53 47 70 56 76 61\r\n", "output": "63\r\n"}]
| false |
stdio
| null | true |
899/A
|
899
|
A
|
Python 3
|
TESTS
| 18 | 108 | 9,113,600 |
34095135
|
# -*- coding: utf-8 -*-
"""
Created on Fri Jan 12 00:45:45 2018
@author: Sand Boa
"""
def validator(chunk:int)->int:
pass
if __name__ == "__main__":
test_case:int = int(input())
count:int = 0
group_conf:list = list(map(int,input().split()))
one_member:int= group_conf.count(1)
two_member:int= group_conf.count(2)
if two_member > 0 and one_member == 0:
print(0)
elif two_member > 0 and one_member > 0:
print(min(two_member, one_member))
elif two_member == 0 and one_member > 0:
print(one_member//3)
| 67 | 46 | 2,969,600 |
153637962
|
n=int(input())
s=input().split()
print(min(s.count('1'),s.count('2'))+((s.count('1')-min(s.count('1'),s.count('2')))//3))
|
Codeforces Round 452 (Div. 2)
|
CF
| 2,017 | 1 | 256 |
Splitting in Teams
|
There were n groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team.
The coach decided to form teams of exactly three people for this training. Determine the maximum number of teams of three people he can form. It is possible that he can't use all groups to form teams. For groups of two, either both students should write the contest, or both should not. If two students from a group of two will write the contest, they should be in the same team.
|
The first line contains single integer n (2 ≤ n ≤ 2·105) — the number of groups.
The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 2), where ai is the number of people in group i.
|
Print the maximum number of teams of three people the coach can form.
| null |
In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups.
In the second example he can't make a single team.
In the third example the coach can form three teams. For example, he can do this in the following way:
- The first group (of two people) and the seventh group (of one person),
- The second group (of two people) and the sixth group (of one person),
- The third group (of two people) and the fourth group (of one person).
|
[{"input": "4\n1 1 2 1", "output": "1"}, {"input": "2\n2 2", "output": "0"}, {"input": "7\n2 2 2 1 1 1 1", "output": "3"}, {"input": "3\n1 1 1", "output": "1"}]
| 800 |
["constructive algorithms", "greedy", "math"]
| 67 |
[{"input": "4\r\n1 1 2 1\r\n", "output": "1\r\n"}, {"input": "2\r\n2 2\r\n", "output": "0\r\n"}, {"input": "7\r\n2 2 2 1 1 1 1\r\n", "output": "3\r\n"}, {"input": "3\r\n1 1 1\r\n", "output": "1\r\n"}, {"input": "3\r\n2 2 2\r\n", "output": "0\r\n"}, {"input": "3\r\n1 2 1\r\n", "output": "1\r\n"}, {"input": "5\r\n2 2 1 1 1\r\n", "output": "2\r\n"}, {"input": "7\r\n1 1 2 2 1 2 1\r\n", "output": "3\r\n"}, {"input": "10\r\n1 2 2 1 2 2 1 2 1 1\r\n", "output": "5\r\n"}, {"input": "5\r\n2 2 2 1 2\r\n", "output": "1\r\n"}, {"input": "43\r\n1 2 2 2 1 1 2 2 1 1 2 2 2 2 1 2 2 2 2 2 1 2 1 2 1 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2\r\n", "output": "10\r\n"}, {"input": "72\r\n1 2 1 2 2 1 2 1 1 1 1 2 2 1 2 1 2 1 2 2 2 2 1 2 2 2 2 1 2 1 1 2 2 1 1 2 2 2 2 2 1 1 1 1 2 2 1 1 2 1 1 1 1 2 2 1 2 2 1 2 1 1 2 1 2 2 1 1 1 2 2 2\r\n", "output": "34\r\n"}, {"input": "64\r\n2 2 1 1 1 2 1 1 1 2 2 1 2 2 2 1 2 2 2 1 1 1 1 2 1 2 1 2 1 1 2 2 1 1 2 2 1 1 1 1 2 2 1 1 1 2 1 2 2 2 2 2 2 2 1 1 2 1 1 1 2 2 1 2\r\n", "output": "32\r\n"}, {"input": "20\r\n1 1 1 1 2 1 2 2 2 1 2 1 2 1 2 1 1 2 1 2\r\n", "output": "9\r\n"}, {"input": "23\r\n1 1 1 1 2 1 2 1 1 1 2 2 2 2 2 2 1 2 1 2 2 1 1\r\n", "output": "11\r\n"}, {"input": "201\r\n1 1 2 2 2 2 1 1 1 2 2 1 2 1 2 1 2 2 2 1 1 2 1 1 1 2 1 2 1 1 1 2 1 1 2 1 2 2 1 1 1 1 2 1 1 2 1 1 1 2 2 2 2 1 2 1 2 2 2 2 2 2 1 1 1 2 2 1 1 1 1 2 2 1 2 1 1 2 2 1 1 2 2 2 1 1 1 2 1 1 2 1 2 2 1 2 2 2 2 1 1 1 2 1 2 2 2 2 2 1 2 1 1 1 2 2 2 2 2 1 2 1 1 2 2 2 1 1 2 2 1 2 2 2 1 1 1 2 1 1 1 2 1 1 2 2 2 1 2 1 1 1 2 2 1 1 2 2 2 2 2 2 1 2 2 1 2 2 2 1 1 2 2 1 1 2 1 1 1 1 2 1 1 1 2 2 1 2 1 1 2 2 1 1 2 1 2 1 1 1 2\r\n", "output": "100\r\n"}, {"input": "247\r\n2 2 1 2 1 2 2 2 2 2 2 1 1 2 2 1 2 1 1 1 2 1 1 1 1 2 1 1 2 2 1 2 1 1 1 2 2 2 1 1 2 1 1 2 1 1 1 2 1 2 1 2 2 1 1 2 1 2 2 1 2 1 2 1 1 2 1 1 1 2 2 1 1 2 2 1 1 2 1 1 1 2 2 2 2 1 2 2 2 2 2 2 1 2 2 2 2 1 1 1 1 1 1 1 1 1 2 1 2 2 1 2 1 2 2 2 1 2 2 2 1 1 2 2 1 1 1 2 1 1 1 1 2 2 1 2 2 1 1 1 2 1 2 2 1 2 1 1 1 2 2 2 2 2 1 2 2 2 1 1 1 2 1 2 1 1 2 2 2 2 1 1 2 2 2 1 2 2 2 1 2 1 1 2 2 2 2 1 2 2 1 1 1 2 1 2 1 1 1 2 2 1 1 2 1 1 2 1 2 1 1 2 1 1 1 1 2 1 1 1 1 2 2 1 2 1 1 2 1 2 2 1 2 2 2 1 2 2 1 2 2 1 1 1 2 2 2\r\n", "output": "123\r\n"}, {"input": "4\r\n2 2 2 2\r\n", "output": "0\r\n"}, {"input": "4\r\n1 1 1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n1 1\r\n", "output": "0\r\n"}, {"input": "2\r\n2 1\r\n", "output": "1\r\n"}, {"input": "2\r\n1 2\r\n", "output": "1\r\n"}, {"input": "3\r\n1 1 2\r\n", "output": "1\r\n"}, {"input": "3\r\n1 2 2\r\n", "output": "1\r\n"}, {"input": "3\r\n2 1 1\r\n", "output": "1\r\n"}, {"input": "3\r\n2 1 2\r\n", "output": "1\r\n"}, {"input": "3\r\n2 2 1\r\n", "output": "1\r\n"}, {"input": "4\r\n1 1 1 2\r\n", "output": "1\r\n"}, {"input": "4\r\n1 1 2 2\r\n", "output": "2\r\n"}, {"input": "4\r\n1 2 2 2\r\n", "output": "1\r\n"}, {"input": "4\r\n2 1 1 1\r\n", "output": "1\r\n"}, {"input": "5\r\n1 1 1 1 2\r\n", "output": "2\r\n"}, {"input": "14\r\n1 2 2 2 2 2 2 2 2 2 2 2 2 2\r\n", "output": "1\r\n"}, {"input": "38\r\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1\r\n", "output": "1\r\n"}, {"input": "30\r\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1\r\n", "output": "1\r\n"}, {"input": "20\r\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1\r\n", "output": "1\r\n"}, {"input": "26\r\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2\r\n", "output": "1\r\n"}, {"input": "6\r\n1 1 1 2 2 2\r\n", "output": "3\r\n"}, {"input": "5\r\n2 1 1 1 1\r\n", "output": "2\r\n"}, {"input": "9\r\n1 1 1 1 1 1 2 2 2\r\n", "output": "4\r\n"}, {"input": "10\r\n2 2 1 1 1 1 1 1 1 1\r\n", "output": "4\r\n"}, {"input": "6\r\n1 1 1 1 1 1\r\n", "output": "2\r\n"}]
| false |
stdio
| null | true |
899/A
|
899
|
A
|
Python 3
|
TESTS
| 18 | 124 | 3,993,600 |
77999923
|
n = int(input())
l = list(map(int,input().split()))
if l.count(2)!=0 and l.count(1)!=0:
print(min(l.count(2),l.count(1)))
elif l.count(1)==0:
print(0)
elif l.count(2)==0:
print(l.count(1)//3)
| 67 | 61 | 4,505,600 |
205263420
|
n=int(input())
l=input().split()
c2=l.count("2")
c1=l.count("1")
r=min(c2,c1)
print(r+(c1-r)//3)
|
Codeforces Round 452 (Div. 2)
|
CF
| 2,017 | 1 | 256 |
Splitting in Teams
|
There were n groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team.
The coach decided to form teams of exactly three people for this training. Determine the maximum number of teams of three people he can form. It is possible that he can't use all groups to form teams. For groups of two, either both students should write the contest, or both should not. If two students from a group of two will write the contest, they should be in the same team.
|
The first line contains single integer n (2 ≤ n ≤ 2·105) — the number of groups.
The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 2), where ai is the number of people in group i.
|
Print the maximum number of teams of three people the coach can form.
| null |
In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups.
In the second example he can't make a single team.
In the third example the coach can form three teams. For example, he can do this in the following way:
- The first group (of two people) and the seventh group (of one person),
- The second group (of two people) and the sixth group (of one person),
- The third group (of two people) and the fourth group (of one person).
|
[{"input": "4\n1 1 2 1", "output": "1"}, {"input": "2\n2 2", "output": "0"}, {"input": "7\n2 2 2 1 1 1 1", "output": "3"}, {"input": "3\n1 1 1", "output": "1"}]
| 800 |
["constructive algorithms", "greedy", "math"]
| 67 |
[{"input": "4\r\n1 1 2 1\r\n", "output": "1\r\n"}, {"input": "2\r\n2 2\r\n", "output": "0\r\n"}, {"input": "7\r\n2 2 2 1 1 1 1\r\n", "output": "3\r\n"}, {"input": "3\r\n1 1 1\r\n", "output": "1\r\n"}, {"input": "3\r\n2 2 2\r\n", "output": "0\r\n"}, {"input": "3\r\n1 2 1\r\n", "output": "1\r\n"}, {"input": "5\r\n2 2 1 1 1\r\n", "output": "2\r\n"}, {"input": "7\r\n1 1 2 2 1 2 1\r\n", "output": "3\r\n"}, {"input": "10\r\n1 2 2 1 2 2 1 2 1 1\r\n", "output": "5\r\n"}, {"input": "5\r\n2 2 2 1 2\r\n", "output": "1\r\n"}, {"input": "43\r\n1 2 2 2 1 1 2 2 1 1 2 2 2 2 1 2 2 2 2 2 1 2 1 2 1 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2\r\n", "output": "10\r\n"}, {"input": "72\r\n1 2 1 2 2 1 2 1 1 1 1 2 2 1 2 1 2 1 2 2 2 2 1 2 2 2 2 1 2 1 1 2 2 1 1 2 2 2 2 2 1 1 1 1 2 2 1 1 2 1 1 1 1 2 2 1 2 2 1 2 1 1 2 1 2 2 1 1 1 2 2 2\r\n", "output": "34\r\n"}, {"input": "64\r\n2 2 1 1 1 2 1 1 1 2 2 1 2 2 2 1 2 2 2 1 1 1 1 2 1 2 1 2 1 1 2 2 1 1 2 2 1 1 1 1 2 2 1 1 1 2 1 2 2 2 2 2 2 2 1 1 2 1 1 1 2 2 1 2\r\n", "output": "32\r\n"}, {"input": "20\r\n1 1 1 1 2 1 2 2 2 1 2 1 2 1 2 1 1 2 1 2\r\n", "output": "9\r\n"}, {"input": "23\r\n1 1 1 1 2 1 2 1 1 1 2 2 2 2 2 2 1 2 1 2 2 1 1\r\n", "output": "11\r\n"}, {"input": "201\r\n1 1 2 2 2 2 1 1 1 2 2 1 2 1 2 1 2 2 2 1 1 2 1 1 1 2 1 2 1 1 1 2 1 1 2 1 2 2 1 1 1 1 2 1 1 2 1 1 1 2 2 2 2 1 2 1 2 2 2 2 2 2 1 1 1 2 2 1 1 1 1 2 2 1 2 1 1 2 2 1 1 2 2 2 1 1 1 2 1 1 2 1 2 2 1 2 2 2 2 1 1 1 2 1 2 2 2 2 2 1 2 1 1 1 2 2 2 2 2 1 2 1 1 2 2 2 1 1 2 2 1 2 2 2 1 1 1 2 1 1 1 2 1 1 2 2 2 1 2 1 1 1 2 2 1 1 2 2 2 2 2 2 1 2 2 1 2 2 2 1 1 2 2 1 1 2 1 1 1 1 2 1 1 1 2 2 1 2 1 1 2 2 1 1 2 1 2 1 1 1 2\r\n", "output": "100\r\n"}, {"input": "247\r\n2 2 1 2 1 2 2 2 2 2 2 1 1 2 2 1 2 1 1 1 2 1 1 1 1 2 1 1 2 2 1 2 1 1 1 2 2 2 1 1 2 1 1 2 1 1 1 2 1 2 1 2 2 1 1 2 1 2 2 1 2 1 2 1 1 2 1 1 1 2 2 1 1 2 2 1 1 2 1 1 1 2 2 2 2 1 2 2 2 2 2 2 1 2 2 2 2 1 1 1 1 1 1 1 1 1 2 1 2 2 1 2 1 2 2 2 1 2 2 2 1 1 2 2 1 1 1 2 1 1 1 1 2 2 1 2 2 1 1 1 2 1 2 2 1 2 1 1 1 2 2 2 2 2 1 2 2 2 1 1 1 2 1 2 1 1 2 2 2 2 1 1 2 2 2 1 2 2 2 1 2 1 1 2 2 2 2 1 2 2 1 1 1 2 1 2 1 1 1 2 2 1 1 2 1 1 2 1 2 1 1 2 1 1 1 1 2 1 1 1 1 2 2 1 2 1 1 2 1 2 2 1 2 2 2 1 2 2 1 2 2 1 1 1 2 2 2\r\n", "output": "123\r\n"}, {"input": "4\r\n2 2 2 2\r\n", "output": "0\r\n"}, {"input": "4\r\n1 1 1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n1 1\r\n", "output": "0\r\n"}, {"input": "2\r\n2 1\r\n", "output": "1\r\n"}, {"input": "2\r\n1 2\r\n", "output": "1\r\n"}, {"input": "3\r\n1 1 2\r\n", "output": "1\r\n"}, {"input": "3\r\n1 2 2\r\n", "output": "1\r\n"}, {"input": "3\r\n2 1 1\r\n", "output": "1\r\n"}, {"input": "3\r\n2 1 2\r\n", "output": "1\r\n"}, {"input": "3\r\n2 2 1\r\n", "output": "1\r\n"}, {"input": "4\r\n1 1 1 2\r\n", "output": "1\r\n"}, {"input": "4\r\n1 1 2 2\r\n", "output": "2\r\n"}, {"input": "4\r\n1 2 2 2\r\n", "output": "1\r\n"}, {"input": "4\r\n2 1 1 1\r\n", "output": "1\r\n"}, {"input": "5\r\n1 1 1 1 2\r\n", "output": "2\r\n"}, {"input": "14\r\n1 2 2 2 2 2 2 2 2 2 2 2 2 2\r\n", "output": "1\r\n"}, {"input": "38\r\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1\r\n", "output": "1\r\n"}, {"input": "30\r\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1\r\n", "output": "1\r\n"}, {"input": "20\r\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1\r\n", "output": "1\r\n"}, {"input": "26\r\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2\r\n", "output": "1\r\n"}, {"input": "6\r\n1 1 1 2 2 2\r\n", "output": "3\r\n"}, {"input": "5\r\n2 1 1 1 1\r\n", "output": "2\r\n"}, {"input": "9\r\n1 1 1 1 1 1 2 2 2\r\n", "output": "4\r\n"}, {"input": "10\r\n2 2 1 1 1 1 1 1 1 1\r\n", "output": "4\r\n"}, {"input": "6\r\n1 1 1 1 1 1\r\n", "output": "2\r\n"}]
| false |
stdio
| null | true |
899/A
|
899
|
A
|
Python 3
|
TESTS
| 18 | 77 | 3,686,400 |
158865077
|
a1=int(input())
a=list(map(int, input().split()))
a2=a.count(1)
a3=a.count(2)
if a2<a3 and a3!=0:
print(a2)
elif a3<a2 and a3==0:
print(a2//3)
elif a3<a2:
print(a3)
else:
print(a2)
| 67 | 62 | 1,228,800 |
112080410
|
a=int(input())
b=input()
c2=b.count('2')
c1=b.count('1')
sum=0
sum+=min(c2,c1)
c1-=c2
if c1>0:
sum+=c1//3
print(sum)
|
Codeforces Round 452 (Div. 2)
|
CF
| 2,017 | 1 | 256 |
Splitting in Teams
|
There were n groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team.
The coach decided to form teams of exactly three people for this training. Determine the maximum number of teams of three people he can form. It is possible that he can't use all groups to form teams. For groups of two, either both students should write the contest, or both should not. If two students from a group of two will write the contest, they should be in the same team.
|
The first line contains single integer n (2 ≤ n ≤ 2·105) — the number of groups.
The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 2), where ai is the number of people in group i.
|
Print the maximum number of teams of three people the coach can form.
| null |
In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups.
In the second example he can't make a single team.
In the third example the coach can form three teams. For example, he can do this in the following way:
- The first group (of two people) and the seventh group (of one person),
- The second group (of two people) and the sixth group (of one person),
- The third group (of two people) and the fourth group (of one person).
|
[{"input": "4\n1 1 2 1", "output": "1"}, {"input": "2\n2 2", "output": "0"}, {"input": "7\n2 2 2 1 1 1 1", "output": "3"}, {"input": "3\n1 1 1", "output": "1"}]
| 800 |
["constructive algorithms", "greedy", "math"]
| 67 |
[{"input": "4\r\n1 1 2 1\r\n", "output": "1\r\n"}, {"input": "2\r\n2 2\r\n", "output": "0\r\n"}, {"input": "7\r\n2 2 2 1 1 1 1\r\n", "output": "3\r\n"}, {"input": "3\r\n1 1 1\r\n", "output": "1\r\n"}, {"input": "3\r\n2 2 2\r\n", "output": "0\r\n"}, {"input": "3\r\n1 2 1\r\n", "output": "1\r\n"}, {"input": "5\r\n2 2 1 1 1\r\n", "output": "2\r\n"}, {"input": "7\r\n1 1 2 2 1 2 1\r\n", "output": "3\r\n"}, {"input": "10\r\n1 2 2 1 2 2 1 2 1 1\r\n", "output": "5\r\n"}, {"input": "5\r\n2 2 2 1 2\r\n", "output": "1\r\n"}, {"input": "43\r\n1 2 2 2 1 1 2 2 1 1 2 2 2 2 1 2 2 2 2 2 1 2 1 2 1 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2\r\n", "output": "10\r\n"}, {"input": "72\r\n1 2 1 2 2 1 2 1 1 1 1 2 2 1 2 1 2 1 2 2 2 2 1 2 2 2 2 1 2 1 1 2 2 1 1 2 2 2 2 2 1 1 1 1 2 2 1 1 2 1 1 1 1 2 2 1 2 2 1 2 1 1 2 1 2 2 1 1 1 2 2 2\r\n", "output": "34\r\n"}, {"input": "64\r\n2 2 1 1 1 2 1 1 1 2 2 1 2 2 2 1 2 2 2 1 1 1 1 2 1 2 1 2 1 1 2 2 1 1 2 2 1 1 1 1 2 2 1 1 1 2 1 2 2 2 2 2 2 2 1 1 2 1 1 1 2 2 1 2\r\n", "output": "32\r\n"}, {"input": "20\r\n1 1 1 1 2 1 2 2 2 1 2 1 2 1 2 1 1 2 1 2\r\n", "output": "9\r\n"}, {"input": "23\r\n1 1 1 1 2 1 2 1 1 1 2 2 2 2 2 2 1 2 1 2 2 1 1\r\n", "output": "11\r\n"}, {"input": "201\r\n1 1 2 2 2 2 1 1 1 2 2 1 2 1 2 1 2 2 2 1 1 2 1 1 1 2 1 2 1 1 1 2 1 1 2 1 2 2 1 1 1 1 2 1 1 2 1 1 1 2 2 2 2 1 2 1 2 2 2 2 2 2 1 1 1 2 2 1 1 1 1 2 2 1 2 1 1 2 2 1 1 2 2 2 1 1 1 2 1 1 2 1 2 2 1 2 2 2 2 1 1 1 2 1 2 2 2 2 2 1 2 1 1 1 2 2 2 2 2 1 2 1 1 2 2 2 1 1 2 2 1 2 2 2 1 1 1 2 1 1 1 2 1 1 2 2 2 1 2 1 1 1 2 2 1 1 2 2 2 2 2 2 1 2 2 1 2 2 2 1 1 2 2 1 1 2 1 1 1 1 2 1 1 1 2 2 1 2 1 1 2 2 1 1 2 1 2 1 1 1 2\r\n", "output": "100\r\n"}, {"input": "247\r\n2 2 1 2 1 2 2 2 2 2 2 1 1 2 2 1 2 1 1 1 2 1 1 1 1 2 1 1 2 2 1 2 1 1 1 2 2 2 1 1 2 1 1 2 1 1 1 2 1 2 1 2 2 1 1 2 1 2 2 1 2 1 2 1 1 2 1 1 1 2 2 1 1 2 2 1 1 2 1 1 1 2 2 2 2 1 2 2 2 2 2 2 1 2 2 2 2 1 1 1 1 1 1 1 1 1 2 1 2 2 1 2 1 2 2 2 1 2 2 2 1 1 2 2 1 1 1 2 1 1 1 1 2 2 1 2 2 1 1 1 2 1 2 2 1 2 1 1 1 2 2 2 2 2 1 2 2 2 1 1 1 2 1 2 1 1 2 2 2 2 1 1 2 2 2 1 2 2 2 1 2 1 1 2 2 2 2 1 2 2 1 1 1 2 1 2 1 1 1 2 2 1 1 2 1 1 2 1 2 1 1 2 1 1 1 1 2 1 1 1 1 2 2 1 2 1 1 2 1 2 2 1 2 2 2 1 2 2 1 2 2 1 1 1 2 2 2\r\n", "output": "123\r\n"}, {"input": "4\r\n2 2 2 2\r\n", "output": "0\r\n"}, {"input": "4\r\n1 1 1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n1 1\r\n", "output": "0\r\n"}, {"input": "2\r\n2 1\r\n", "output": "1\r\n"}, {"input": "2\r\n1 2\r\n", "output": "1\r\n"}, {"input": "3\r\n1 1 2\r\n", "output": "1\r\n"}, {"input": "3\r\n1 2 2\r\n", "output": "1\r\n"}, {"input": "3\r\n2 1 1\r\n", "output": "1\r\n"}, {"input": "3\r\n2 1 2\r\n", "output": "1\r\n"}, {"input": "3\r\n2 2 1\r\n", "output": "1\r\n"}, {"input": "4\r\n1 1 1 2\r\n", "output": "1\r\n"}, {"input": "4\r\n1 1 2 2\r\n", "output": "2\r\n"}, {"input": "4\r\n1 2 2 2\r\n", "output": "1\r\n"}, {"input": "4\r\n2 1 1 1\r\n", "output": "1\r\n"}, {"input": "5\r\n1 1 1 1 2\r\n", "output": "2\r\n"}, {"input": "14\r\n1 2 2 2 2 2 2 2 2 2 2 2 2 2\r\n", "output": "1\r\n"}, {"input": "38\r\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1\r\n", "output": "1\r\n"}, {"input": "30\r\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1\r\n", "output": "1\r\n"}, {"input": "20\r\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1\r\n", "output": "1\r\n"}, {"input": "26\r\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2\r\n", "output": "1\r\n"}, {"input": "6\r\n1 1 1 2 2 2\r\n", "output": "3\r\n"}, {"input": "5\r\n2 1 1 1 1\r\n", "output": "2\r\n"}, {"input": "9\r\n1 1 1 1 1 1 2 2 2\r\n", "output": "4\r\n"}, {"input": "10\r\n2 2 1 1 1 1 1 1 1 1\r\n", "output": "4\r\n"}, {"input": "6\r\n1 1 1 1 1 1\r\n", "output": "2\r\n"}]
| false |
stdio
| null | true |
899/A
|
899
|
A
|
Python 3
|
TESTS
| 18 | 78 | 4,096,000 |
110541185
|
n=int(input())
nums=list(map(int,input().split(' ')))
one=nums.count(1)
two=nums.count(2)
if one==0:
print(0)
elif two==0:
print(one//3)
else:
discard=max(one,two)-min(one,two)
form=len(nums)-discard
print(form//2)
| 67 | 62 | 1,331,200 |
221678496
|
n = int(input())
t = input()
ones = t.count('1')
twos = t.count('2')
threes = 0
threes += min(ones,twos)
ones -= min(ones,twos)
twos -= min(ones,twos)
threes += ones//3
print(threes)
|
Codeforces Round 452 (Div. 2)
|
CF
| 2,017 | 1 | 256 |
Splitting in Teams
|
There were n groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team.
The coach decided to form teams of exactly three people for this training. Determine the maximum number of teams of three people he can form. It is possible that he can't use all groups to form teams. For groups of two, either both students should write the contest, or both should not. If two students from a group of two will write the contest, they should be in the same team.
|
The first line contains single integer n (2 ≤ n ≤ 2·105) — the number of groups.
The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 2), where ai is the number of people in group i.
|
Print the maximum number of teams of three people the coach can form.
| null |
In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups.
In the second example he can't make a single team.
In the third example the coach can form three teams. For example, he can do this in the following way:
- The first group (of two people) and the seventh group (of one person),
- The second group (of two people) and the sixth group (of one person),
- The third group (of two people) and the fourth group (of one person).
|
[{"input": "4\n1 1 2 1", "output": "1"}, {"input": "2\n2 2", "output": "0"}, {"input": "7\n2 2 2 1 1 1 1", "output": "3"}, {"input": "3\n1 1 1", "output": "1"}]
| 800 |
["constructive algorithms", "greedy", "math"]
| 67 |
[{"input": "4\r\n1 1 2 1\r\n", "output": "1\r\n"}, {"input": "2\r\n2 2\r\n", "output": "0\r\n"}, {"input": "7\r\n2 2 2 1 1 1 1\r\n", "output": "3\r\n"}, {"input": "3\r\n1 1 1\r\n", "output": "1\r\n"}, {"input": "3\r\n2 2 2\r\n", "output": "0\r\n"}, {"input": "3\r\n1 2 1\r\n", "output": "1\r\n"}, {"input": "5\r\n2 2 1 1 1\r\n", "output": "2\r\n"}, {"input": "7\r\n1 1 2 2 1 2 1\r\n", "output": "3\r\n"}, {"input": "10\r\n1 2 2 1 2 2 1 2 1 1\r\n", "output": "5\r\n"}, {"input": "5\r\n2 2 2 1 2\r\n", "output": "1\r\n"}, {"input": "43\r\n1 2 2 2 1 1 2 2 1 1 2 2 2 2 1 2 2 2 2 2 1 2 1 2 1 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2\r\n", "output": "10\r\n"}, {"input": "72\r\n1 2 1 2 2 1 2 1 1 1 1 2 2 1 2 1 2 1 2 2 2 2 1 2 2 2 2 1 2 1 1 2 2 1 1 2 2 2 2 2 1 1 1 1 2 2 1 1 2 1 1 1 1 2 2 1 2 2 1 2 1 1 2 1 2 2 1 1 1 2 2 2\r\n", "output": "34\r\n"}, {"input": "64\r\n2 2 1 1 1 2 1 1 1 2 2 1 2 2 2 1 2 2 2 1 1 1 1 2 1 2 1 2 1 1 2 2 1 1 2 2 1 1 1 1 2 2 1 1 1 2 1 2 2 2 2 2 2 2 1 1 2 1 1 1 2 2 1 2\r\n", "output": "32\r\n"}, {"input": "20\r\n1 1 1 1 2 1 2 2 2 1 2 1 2 1 2 1 1 2 1 2\r\n", "output": "9\r\n"}, {"input": "23\r\n1 1 1 1 2 1 2 1 1 1 2 2 2 2 2 2 1 2 1 2 2 1 1\r\n", "output": "11\r\n"}, {"input": "201\r\n1 1 2 2 2 2 1 1 1 2 2 1 2 1 2 1 2 2 2 1 1 2 1 1 1 2 1 2 1 1 1 2 1 1 2 1 2 2 1 1 1 1 2 1 1 2 1 1 1 2 2 2 2 1 2 1 2 2 2 2 2 2 1 1 1 2 2 1 1 1 1 2 2 1 2 1 1 2 2 1 1 2 2 2 1 1 1 2 1 1 2 1 2 2 1 2 2 2 2 1 1 1 2 1 2 2 2 2 2 1 2 1 1 1 2 2 2 2 2 1 2 1 1 2 2 2 1 1 2 2 1 2 2 2 1 1 1 2 1 1 1 2 1 1 2 2 2 1 2 1 1 1 2 2 1 1 2 2 2 2 2 2 1 2 2 1 2 2 2 1 1 2 2 1 1 2 1 1 1 1 2 1 1 1 2 2 1 2 1 1 2 2 1 1 2 1 2 1 1 1 2\r\n", "output": "100\r\n"}, {"input": "247\r\n2 2 1 2 1 2 2 2 2 2 2 1 1 2 2 1 2 1 1 1 2 1 1 1 1 2 1 1 2 2 1 2 1 1 1 2 2 2 1 1 2 1 1 2 1 1 1 2 1 2 1 2 2 1 1 2 1 2 2 1 2 1 2 1 1 2 1 1 1 2 2 1 1 2 2 1 1 2 1 1 1 2 2 2 2 1 2 2 2 2 2 2 1 2 2 2 2 1 1 1 1 1 1 1 1 1 2 1 2 2 1 2 1 2 2 2 1 2 2 2 1 1 2 2 1 1 1 2 1 1 1 1 2 2 1 2 2 1 1 1 2 1 2 2 1 2 1 1 1 2 2 2 2 2 1 2 2 2 1 1 1 2 1 2 1 1 2 2 2 2 1 1 2 2 2 1 2 2 2 1 2 1 1 2 2 2 2 1 2 2 1 1 1 2 1 2 1 1 1 2 2 1 1 2 1 1 2 1 2 1 1 2 1 1 1 1 2 1 1 1 1 2 2 1 2 1 1 2 1 2 2 1 2 2 2 1 2 2 1 2 2 1 1 1 2 2 2\r\n", "output": "123\r\n"}, {"input": "4\r\n2 2 2 2\r\n", "output": "0\r\n"}, {"input": "4\r\n1 1 1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n1 1\r\n", "output": "0\r\n"}, {"input": "2\r\n2 1\r\n", "output": "1\r\n"}, {"input": "2\r\n1 2\r\n", "output": "1\r\n"}, {"input": "3\r\n1 1 2\r\n", "output": "1\r\n"}, {"input": "3\r\n1 2 2\r\n", "output": "1\r\n"}, {"input": "3\r\n2 1 1\r\n", "output": "1\r\n"}, {"input": "3\r\n2 1 2\r\n", "output": "1\r\n"}, {"input": "3\r\n2 2 1\r\n", "output": "1\r\n"}, {"input": "4\r\n1 1 1 2\r\n", "output": "1\r\n"}, {"input": "4\r\n1 1 2 2\r\n", "output": "2\r\n"}, {"input": "4\r\n1 2 2 2\r\n", "output": "1\r\n"}, {"input": "4\r\n2 1 1 1\r\n", "output": "1\r\n"}, {"input": "5\r\n1 1 1 1 2\r\n", "output": "2\r\n"}, {"input": "14\r\n1 2 2 2 2 2 2 2 2 2 2 2 2 2\r\n", "output": "1\r\n"}, {"input": "38\r\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1\r\n", "output": "1\r\n"}, {"input": "30\r\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1\r\n", "output": "1\r\n"}, {"input": "20\r\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1\r\n", "output": "1\r\n"}, {"input": "26\r\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2\r\n", "output": "1\r\n"}, {"input": "6\r\n1 1 1 2 2 2\r\n", "output": "3\r\n"}, {"input": "5\r\n2 1 1 1 1\r\n", "output": "2\r\n"}, {"input": "9\r\n1 1 1 1 1 1 2 2 2\r\n", "output": "4\r\n"}, {"input": "10\r\n2 2 1 1 1 1 1 1 1 1\r\n", "output": "4\r\n"}, {"input": "6\r\n1 1 1 1 1 1\r\n", "output": "2\r\n"}]
| false |
stdio
| null | true |
540/C
|
540
|
C
|
Python 3
|
TESTS
| 6 | 46 | 102,400 |
164631456
|
from collections import deque as dq
n, m = map(int, input().split())
matrix = [list(input()) for i in range(n)]
x, y = map(int, input().split())
start = (x-1, y-1)
x, y = map(int, input().split())
end = (x-1, y-1)
d = dq()
d.append([start[0], start[1], matrix[:]])
nb = 1
if matrix[end[0]][end[1]] == '.':
nb = 2
for i in range(nb):
imp = True
while len(d) > 0 and imp == True:
x, y, mtx = d.popleft()
rows = [1, 0, 0, -1]
cols = [0, 1, -1, 0]
for i in range(4):
a = x + rows[i]
b = y + cols[i]
if a == end[0] and b == end[1]:
matrix = mtx[:]
imp = False
start = end
break
elif 0 <= a <= n-1 and 0 <= b <= m-1 and mtx[a][b] == '.':
mid = mtx[:]
mid[a][b] = 'X'
d.append([a, b, mid])
if imp:
break
if imp:
print('NO')
else:
print('YES')
| 102 | 342 | 24,576,000 |
103383334
|
from collections import deque
directions = ((1, 0), (0, 1), (-1, 0), (0, -1))
n, m = map(int, input().split())
a = [list(input()) for _ in range(n)]
si, sj = map(lambda x:int(x)-1, input().split())
ti, tj = map(lambda x:int(x)-1, input().split())
def is_valid(i, j):
return 0 <= i < n and 0 <= j < m
def check(i, j):
r = 0
for di, dj in directions:
ni, nj = i + di, j + dj
if is_valid(ni, nj) and a[ni][nj] != 'X' or (ni, nj) == (si, sj):
r += 1
return r
if (si, sj) == (ti, tj):
print('YES' if check(si, sj) >= 1 else 'NO')
exit()
c = a[ti][tj]
a[ti][tj] = '.'
vis, q = set(), deque()
vis.add((si, sj))
q.append((si, sj))
while q:
i, j = q.popleft()
for di, dj in directions:
ni, nj = i + di, j + dj
if is_valid(ni, nj) and a[ni][nj] != 'X' and (ni, nj) not in vis:
vis.add((ni, nj))
q.append((ni, nj))
if (ti, tj) not in vis:
print('NO')
elif c == 'X':
print('YES')
else:
print('YES' if check(ti, tj) >= 2 else 'NO')
|
Codeforces Round 301 (Div. 2)
|
CF
| 2,015 | 2 | 256 |
Ice Cave
|
You play a computer game. Your character stands on some level of a multilevel ice cave. In order to move on forward, you need to descend one level lower and the only way to do this is to fall through the ice.
The level of the cave where you are is a rectangular square grid of n rows and m columns. Each cell consists either from intact or from cracked ice. From each cell you can move to cells that are side-adjacent with yours (due to some limitations of the game engine you cannot make jumps on the same place, i.e. jump from a cell to itself). If you move to the cell with cracked ice, then your character falls down through it and if you move to the cell with intact ice, then the ice on this cell becomes cracked.
Let's number the rows with integers from 1 to n from top to bottom and the columns with integers from 1 to m from left to right. Let's denote a cell on the intersection of the r-th row and the c-th column as (r, c).
You are staying in the cell (r1, c1) and this cell is cracked because you've just fallen here from a higher level. You need to fall down through the cell (r2, c2) since the exit to the next level is there. Can you do this?
|
The first line contains two integers, n and m (1 ≤ n, m ≤ 500) — the number of rows and columns in the cave description.
Each of the next n lines describes the initial state of the level of the cave, each line consists of m characters "." (that is, intact ice) and "X" (cracked ice).
The next line contains two integers, r1 and c1 (1 ≤ r1 ≤ n, 1 ≤ c1 ≤ m) — your initial coordinates. It is guaranteed that the description of the cave contains character 'X' in cell (r1, c1), that is, the ice on the starting cell is initially cracked.
The next line contains two integers r2 and c2 (1 ≤ r2 ≤ n, 1 ≤ c2 ≤ m) — the coordinates of the cell through which you need to fall. The final cell may coincide with the starting one.
|
If you can reach the destination, print 'YES', otherwise print 'NO'.
| null |
In the first sample test one possible path is:
$$(1,6)\rightarrow(2,6)\rightarrow(3,6)\rightarrow(4,5)\rightarrow(4,4)\rightarrow(4,3)\rightarrow(4,2)\rightarrow(4,1)\rightarrow(3,2)\rightarrow(2,3)\rightarrow(2,2)$$
After the first visit of cell (2, 2) the ice on it cracks and when you step there for the second time, your character falls through the ice as intended.
|
[{"input": "4 6\nX...XX\n...XX.\n.X..X.\n......\n1 6\n2 2", "output": "YES"}, {"input": "5 4\n.X..\n...X\nX.X.\n....\n.XX.\n5 3\n1 1", "output": "NO"}, {"input": "4 7\n..X.XX.\n.XX..X.\nX...X..\nX......\n2 2\n1 6", "output": "YES"}]
| 2,000 |
["dfs and similar"]
| 102 |
[{"input": "4 6\r\nX...XX\r\n...XX.\r\n.X..X.\r\n......\r\n1 6\r\n2 2\r\n", "output": "YES\r\n"}, {"input": "5 4\r\n.X..\r\n...X\r\nX.X.\r\n....\r\n.XX.\r\n5 3\r\n1 1\r\n", "output": "NO\r\n"}, {"input": "4 7\r\n..X.XX.\r\n.XX..X.\r\nX...X..\r\nX......\r\n2 2\r\n1 6\r\n", "output": "YES\r\n"}, {"input": "5 3\r\n.XX\r\n...\r\n.X.\r\n.X.\r\n...\r\n1 3\r\n4 1\r\n", "output": "YES\r\n"}, {"input": "1 1\r\nX\r\n1 1\r\n1 1\r\n", "output": "NO\r\n"}, {"input": "1 6\r\n.X...X\r\n1 2\r\n1 5\r\n", "output": "NO\r\n"}, {"input": "7 1\r\nX\r\n.\r\n.\r\n.\r\nX\r\n.\r\n.\r\n5 1\r\n3 1\r\n", "output": "YES\r\n"}, {"input": "1 2\r\nXX\r\n1 1\r\n1 1\r\n", "output": "NO\r\n"}, {"input": "2 1\r\n.\r\nX\r\n2 1\r\n2 1\r\n", "output": "YES\r\n"}, {"input": "3 4\r\n.X..\r\n..XX\r\n..X.\r\n1 2\r\n3 4\r\n", "output": "NO\r\n"}, {"input": "3 5\r\n.X.XX\r\nX...X\r\nX.X..\r\n2 1\r\n1 5\r\n", "output": "NO\r\n"}, {"input": "3 2\r\n..\r\nX.\r\n.X\r\n3 2\r\n3 1\r\n", "output": "NO\r\n"}, {"input": "3 4\r\nXX.X\r\nX...\r\n.X.X\r\n1 2\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "1 2\r\nX.\r\n1 1\r\n1 2\r\n", "output": "NO\r\n"}, {"input": "2 1\r\nX\r\nX\r\n2 1\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "2 2\r\nXX\r\nXX\r\n1 1\r\n2 2\r\n", "output": "NO\r\n"}, {"input": "2 2\r\n..\r\n.X\r\n2 2\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "2 2\r\n.X\r\n.X\r\n1 2\r\n2 2\r\n", "output": "YES\r\n"}, {"input": "2 2\r\n..\r\nXX\r\n2 1\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "4 2\r\nX.\r\n.X\r\n.X\r\nXX\r\n2 2\r\n3 1\r\n", "output": "NO\r\n"}, {"input": "2 4\r\nX.XX\r\n.X..\r\n2 2\r\n2 3\r\n", "output": "YES\r\n"}, {"input": "6 4\r\nX..X\r\n..X.\r\n.X..\r\n..X.\r\n.X..\r\nX..X\r\n1 1\r\n6 4\r\n", "output": "NO\r\n"}, {"input": "5 4\r\nX...\r\n..X.\r\n.X..\r\nX..X\r\n....\r\n4 4\r\n3 1\r\n", "output": "NO\r\n"}, {"input": "3 4\r\nX..X\r\n..XX\r\n.X..\r\n2 3\r\n3 1\r\n", "output": "NO\r\n"}, {"input": "20 20\r\n....................\r\n.......X...........X\r\n............X......X\r\n.X...XX..X....X.....\r\n....X.....X.........\r\nX..........X........\r\n......X........X....\r\n....................\r\n...................X\r\n......X.............\r\n..............X.....\r\n......X.X...........\r\n.X.........X.X......\r\n.........X......X..X\r\n..................X.\r\n...X........X.......\r\n....................\r\n....................\r\n..X.....X...........\r\n........X......X.X..\r\n20 16\r\n5 20\r\n", "output": "YES\r\n"}, {"input": "21 21\r\n.....X...X.........X.\r\n...X...XX......X.....\r\n..X........X.X...XX..\r\n.........X....X...X..\r\nX...X...........XX...\r\n...X...X....XX...XXX.\r\n.X............X......\r\n......X.X............\r\n.X...X.........X.X...\r\n......XX......X.X....\r\n....X.......X.XXX....\r\n.X.......X..XXX.X..X.\r\n..X........X....X...X\r\n.........X..........X\r\n.....XX.....X........\r\n...XX......X.........\r\n.....X...XX...X......\r\n..X.X....XX..XX.X....\r\nX........X.X..XX..X..\r\nX..X......X...X.X....\r\nX.....X.....X.X......\r\n20 4\r\n21 5\r\n", "output": "YES\r\n"}, {"input": "2 1\r\nX\r\nX\r\n2 1\r\n2 1\r\n", "output": "NO\r\n"}, {"input": "2 2\r\nXX\r\nX.\r\n1 1\r\n2 2\r\n", "output": "NO\r\n"}, {"input": "2 1\r\nX\r\nX\r\n1 1\r\n1 1\r\n", "output": "NO\r\n"}, {"input": "1 2\r\nXX\r\n1 2\r\n1 2\r\n", "output": "NO\r\n"}, {"input": "1 2\r\nXX\r\n1 1\r\n1 2\r\n", "output": "YES\r\n"}, {"input": "1 2\r\nXX\r\n1 2\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "2 1\r\nX\r\nX\r\n1 1\r\n2 1\r\n", "output": "YES\r\n"}, {"input": "2 1\r\n.\r\nX\r\n2 1\r\n1 1\r\n", "output": "NO\r\n"}, {"input": "2 1\r\nX\r\n.\r\n1 1\r\n2 1\r\n", "output": "NO\r\n"}, {"input": "1 2\r\n.X\r\n1 2\r\n1 1\r\n", "output": "NO\r\n"}, {"input": "2 1\r\nX\r\n.\r\n1 1\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "1 2\r\nX.\r\n1 1\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "1 2\r\n.X\r\n1 2\r\n1 2\r\n", "output": "YES\r\n"}, {"input": "2 2\r\nX.\r\n..\r\n1 1\r\n2 2\r\n", "output": "YES\r\n"}, {"input": "2 2\r\n..\r\nX.\r\n2 1\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "4 3\r\n..X\r\n..X\r\n.XX\r\n.XX\r\n4 2\r\n2 2\r\n", "output": "YES\r\n"}, {"input": "3 3\r\nXXX\r\nX..\r\nXXX\r\n2 1\r\n2 2\r\n", "output": "YES\r\n"}, {"input": "5 4\r\nXXXX\r\nX..X\r\nX..X\r\nXXXX\r\nXXXX\r\n4 2\r\n3 3\r\n", "output": "YES\r\n"}]
| false |
stdio
| null | true |
899/A
|
899
|
A
|
Python 3
|
TESTS
| 18 | 124 | 3,584,000 |
73123067
|
n=int(input())
li=list(map(int,input().split()))
one=li.count(1)
two=li.count(2)
print(max(min(one,two),int(one//3)))
| 67 | 62 | 2,969,600 |
153706523
|
n = int(input())
w = input().split()
a = w.count('1')
b = w.count('2')
print(min(a,b) + (a - min(a,b))//3)
|
Codeforces Round 452 (Div. 2)
|
CF
| 2,017 | 1 | 256 |
Splitting in Teams
|
There were n groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team.
The coach decided to form teams of exactly three people for this training. Determine the maximum number of teams of three people he can form. It is possible that he can't use all groups to form teams. For groups of two, either both students should write the contest, or both should not. If two students from a group of two will write the contest, they should be in the same team.
|
The first line contains single integer n (2 ≤ n ≤ 2·105) — the number of groups.
The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 2), where ai is the number of people in group i.
|
Print the maximum number of teams of three people the coach can form.
| null |
In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups.
In the second example he can't make a single team.
In the third example the coach can form three teams. For example, he can do this in the following way:
- The first group (of two people) and the seventh group (of one person),
- The second group (of two people) and the sixth group (of one person),
- The third group (of two people) and the fourth group (of one person).
|
[{"input": "4\n1 1 2 1", "output": "1"}, {"input": "2\n2 2", "output": "0"}, {"input": "7\n2 2 2 1 1 1 1", "output": "3"}, {"input": "3\n1 1 1", "output": "1"}]
| 800 |
["constructive algorithms", "greedy", "math"]
| 67 |
[{"input": "4\r\n1 1 2 1\r\n", "output": "1\r\n"}, {"input": "2\r\n2 2\r\n", "output": "0\r\n"}, {"input": "7\r\n2 2 2 1 1 1 1\r\n", "output": "3\r\n"}, {"input": "3\r\n1 1 1\r\n", "output": "1\r\n"}, {"input": "3\r\n2 2 2\r\n", "output": "0\r\n"}, {"input": "3\r\n1 2 1\r\n", "output": "1\r\n"}, {"input": "5\r\n2 2 1 1 1\r\n", "output": "2\r\n"}, {"input": "7\r\n1 1 2 2 1 2 1\r\n", "output": "3\r\n"}, {"input": "10\r\n1 2 2 1 2 2 1 2 1 1\r\n", "output": "5\r\n"}, {"input": "5\r\n2 2 2 1 2\r\n", "output": "1\r\n"}, {"input": "43\r\n1 2 2 2 1 1 2 2 1 1 2 2 2 2 1 2 2 2 2 2 1 2 1 2 1 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2\r\n", "output": "10\r\n"}, {"input": "72\r\n1 2 1 2 2 1 2 1 1 1 1 2 2 1 2 1 2 1 2 2 2 2 1 2 2 2 2 1 2 1 1 2 2 1 1 2 2 2 2 2 1 1 1 1 2 2 1 1 2 1 1 1 1 2 2 1 2 2 1 2 1 1 2 1 2 2 1 1 1 2 2 2\r\n", "output": "34\r\n"}, {"input": "64\r\n2 2 1 1 1 2 1 1 1 2 2 1 2 2 2 1 2 2 2 1 1 1 1 2 1 2 1 2 1 1 2 2 1 1 2 2 1 1 1 1 2 2 1 1 1 2 1 2 2 2 2 2 2 2 1 1 2 1 1 1 2 2 1 2\r\n", "output": "32\r\n"}, {"input": "20\r\n1 1 1 1 2 1 2 2 2 1 2 1 2 1 2 1 1 2 1 2\r\n", "output": "9\r\n"}, {"input": "23\r\n1 1 1 1 2 1 2 1 1 1 2 2 2 2 2 2 1 2 1 2 2 1 1\r\n", "output": "11\r\n"}, {"input": "201\r\n1 1 2 2 2 2 1 1 1 2 2 1 2 1 2 1 2 2 2 1 1 2 1 1 1 2 1 2 1 1 1 2 1 1 2 1 2 2 1 1 1 1 2 1 1 2 1 1 1 2 2 2 2 1 2 1 2 2 2 2 2 2 1 1 1 2 2 1 1 1 1 2 2 1 2 1 1 2 2 1 1 2 2 2 1 1 1 2 1 1 2 1 2 2 1 2 2 2 2 1 1 1 2 1 2 2 2 2 2 1 2 1 1 1 2 2 2 2 2 1 2 1 1 2 2 2 1 1 2 2 1 2 2 2 1 1 1 2 1 1 1 2 1 1 2 2 2 1 2 1 1 1 2 2 1 1 2 2 2 2 2 2 1 2 2 1 2 2 2 1 1 2 2 1 1 2 1 1 1 1 2 1 1 1 2 2 1 2 1 1 2 2 1 1 2 1 2 1 1 1 2\r\n", "output": "100\r\n"}, {"input": "247\r\n2 2 1 2 1 2 2 2 2 2 2 1 1 2 2 1 2 1 1 1 2 1 1 1 1 2 1 1 2 2 1 2 1 1 1 2 2 2 1 1 2 1 1 2 1 1 1 2 1 2 1 2 2 1 1 2 1 2 2 1 2 1 2 1 1 2 1 1 1 2 2 1 1 2 2 1 1 2 1 1 1 2 2 2 2 1 2 2 2 2 2 2 1 2 2 2 2 1 1 1 1 1 1 1 1 1 2 1 2 2 1 2 1 2 2 2 1 2 2 2 1 1 2 2 1 1 1 2 1 1 1 1 2 2 1 2 2 1 1 1 2 1 2 2 1 2 1 1 1 2 2 2 2 2 1 2 2 2 1 1 1 2 1 2 1 1 2 2 2 2 1 1 2 2 2 1 2 2 2 1 2 1 1 2 2 2 2 1 2 2 1 1 1 2 1 2 1 1 1 2 2 1 1 2 1 1 2 1 2 1 1 2 1 1 1 1 2 1 1 1 1 2 2 1 2 1 1 2 1 2 2 1 2 2 2 1 2 2 1 2 2 1 1 1 2 2 2\r\n", "output": "123\r\n"}, {"input": "4\r\n2 2 2 2\r\n", "output": "0\r\n"}, {"input": "4\r\n1 1 1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n1 1\r\n", "output": "0\r\n"}, {"input": "2\r\n2 1\r\n", "output": "1\r\n"}, {"input": "2\r\n1 2\r\n", "output": "1\r\n"}, {"input": "3\r\n1 1 2\r\n", "output": "1\r\n"}, {"input": "3\r\n1 2 2\r\n", "output": "1\r\n"}, {"input": "3\r\n2 1 1\r\n", "output": "1\r\n"}, {"input": "3\r\n2 1 2\r\n", "output": "1\r\n"}, {"input": "3\r\n2 2 1\r\n", "output": "1\r\n"}, {"input": "4\r\n1 1 1 2\r\n", "output": "1\r\n"}, {"input": "4\r\n1 1 2 2\r\n", "output": "2\r\n"}, {"input": "4\r\n1 2 2 2\r\n", "output": "1\r\n"}, {"input": "4\r\n2 1 1 1\r\n", "output": "1\r\n"}, {"input": "5\r\n1 1 1 1 2\r\n", "output": "2\r\n"}, {"input": "14\r\n1 2 2 2 2 2 2 2 2 2 2 2 2 2\r\n", "output": "1\r\n"}, {"input": "38\r\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1\r\n", "output": "1\r\n"}, {"input": "30\r\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1\r\n", "output": "1\r\n"}, {"input": "20\r\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1\r\n", "output": "1\r\n"}, {"input": "26\r\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2\r\n", "output": "1\r\n"}, {"input": "6\r\n1 1 1 2 2 2\r\n", "output": "3\r\n"}, {"input": "5\r\n2 1 1 1 1\r\n", "output": "2\r\n"}, {"input": "9\r\n1 1 1 1 1 1 2 2 2\r\n", "output": "4\r\n"}, {"input": "10\r\n2 2 1 1 1 1 1 1 1 1\r\n", "output": "4\r\n"}, {"input": "6\r\n1 1 1 1 1 1\r\n", "output": "2\r\n"}]
| false |
stdio
| null | true |
899/A
|
899
|
A
|
Python 3
|
TESTS
| 18 | 77 | 3,686,400 |
202008928
|
n = int(input())
group = list(map(int, input().split()))
n1 = group.count(1)
n2 = group.count(2)
if n1 == 0:
print(0)
elif n2 == 0:
print(n1 // 3)
else:
if n2 > n1:
print(n1)
else:
print(n2)
| 67 | 62 | 3,686,400 |
149513641
|
n=int(input());r=[*map(int,input().split())]
x=r.count(1);y=n-x
print(min(x,y)+max(0,x-y)//3)
|
Codeforces Round 452 (Div. 2)
|
CF
| 2,017 | 1 | 256 |
Splitting in Teams
|
There were n groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team.
The coach decided to form teams of exactly three people for this training. Determine the maximum number of teams of three people he can form. It is possible that he can't use all groups to form teams. For groups of two, either both students should write the contest, or both should not. If two students from a group of two will write the contest, they should be in the same team.
|
The first line contains single integer n (2 ≤ n ≤ 2·105) — the number of groups.
The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 2), where ai is the number of people in group i.
|
Print the maximum number of teams of three people the coach can form.
| null |
In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups.
In the second example he can't make a single team.
In the third example the coach can form three teams. For example, he can do this in the following way:
- The first group (of two people) and the seventh group (of one person),
- The second group (of two people) and the sixth group (of one person),
- The third group (of two people) and the fourth group (of one person).
|
[{"input": "4\n1 1 2 1", "output": "1"}, {"input": "2\n2 2", "output": "0"}, {"input": "7\n2 2 2 1 1 1 1", "output": "3"}, {"input": "3\n1 1 1", "output": "1"}]
| 800 |
["constructive algorithms", "greedy", "math"]
| 67 |
[{"input": "4\r\n1 1 2 1\r\n", "output": "1\r\n"}, {"input": "2\r\n2 2\r\n", "output": "0\r\n"}, {"input": "7\r\n2 2 2 1 1 1 1\r\n", "output": "3\r\n"}, {"input": "3\r\n1 1 1\r\n", "output": "1\r\n"}, {"input": "3\r\n2 2 2\r\n", "output": "0\r\n"}, {"input": "3\r\n1 2 1\r\n", "output": "1\r\n"}, {"input": "5\r\n2 2 1 1 1\r\n", "output": "2\r\n"}, {"input": "7\r\n1 1 2 2 1 2 1\r\n", "output": "3\r\n"}, {"input": "10\r\n1 2 2 1 2 2 1 2 1 1\r\n", "output": "5\r\n"}, {"input": "5\r\n2 2 2 1 2\r\n", "output": "1\r\n"}, {"input": "43\r\n1 2 2 2 1 1 2 2 1 1 2 2 2 2 1 2 2 2 2 2 1 2 1 2 1 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2\r\n", "output": "10\r\n"}, {"input": "72\r\n1 2 1 2 2 1 2 1 1 1 1 2 2 1 2 1 2 1 2 2 2 2 1 2 2 2 2 1 2 1 1 2 2 1 1 2 2 2 2 2 1 1 1 1 2 2 1 1 2 1 1 1 1 2 2 1 2 2 1 2 1 1 2 1 2 2 1 1 1 2 2 2\r\n", "output": "34\r\n"}, {"input": "64\r\n2 2 1 1 1 2 1 1 1 2 2 1 2 2 2 1 2 2 2 1 1 1 1 2 1 2 1 2 1 1 2 2 1 1 2 2 1 1 1 1 2 2 1 1 1 2 1 2 2 2 2 2 2 2 1 1 2 1 1 1 2 2 1 2\r\n", "output": "32\r\n"}, {"input": "20\r\n1 1 1 1 2 1 2 2 2 1 2 1 2 1 2 1 1 2 1 2\r\n", "output": "9\r\n"}, {"input": "23\r\n1 1 1 1 2 1 2 1 1 1 2 2 2 2 2 2 1 2 1 2 2 1 1\r\n", "output": "11\r\n"}, {"input": "201\r\n1 1 2 2 2 2 1 1 1 2 2 1 2 1 2 1 2 2 2 1 1 2 1 1 1 2 1 2 1 1 1 2 1 1 2 1 2 2 1 1 1 1 2 1 1 2 1 1 1 2 2 2 2 1 2 1 2 2 2 2 2 2 1 1 1 2 2 1 1 1 1 2 2 1 2 1 1 2 2 1 1 2 2 2 1 1 1 2 1 1 2 1 2 2 1 2 2 2 2 1 1 1 2 1 2 2 2 2 2 1 2 1 1 1 2 2 2 2 2 1 2 1 1 2 2 2 1 1 2 2 1 2 2 2 1 1 1 2 1 1 1 2 1 1 2 2 2 1 2 1 1 1 2 2 1 1 2 2 2 2 2 2 1 2 2 1 2 2 2 1 1 2 2 1 1 2 1 1 1 1 2 1 1 1 2 2 1 2 1 1 2 2 1 1 2 1 2 1 1 1 2\r\n", "output": "100\r\n"}, {"input": "247\r\n2 2 1 2 1 2 2 2 2 2 2 1 1 2 2 1 2 1 1 1 2 1 1 1 1 2 1 1 2 2 1 2 1 1 1 2 2 2 1 1 2 1 1 2 1 1 1 2 1 2 1 2 2 1 1 2 1 2 2 1 2 1 2 1 1 2 1 1 1 2 2 1 1 2 2 1 1 2 1 1 1 2 2 2 2 1 2 2 2 2 2 2 1 2 2 2 2 1 1 1 1 1 1 1 1 1 2 1 2 2 1 2 1 2 2 2 1 2 2 2 1 1 2 2 1 1 1 2 1 1 1 1 2 2 1 2 2 1 1 1 2 1 2 2 1 2 1 1 1 2 2 2 2 2 1 2 2 2 1 1 1 2 1 2 1 1 2 2 2 2 1 1 2 2 2 1 2 2 2 1 2 1 1 2 2 2 2 1 2 2 1 1 1 2 1 2 1 1 1 2 2 1 1 2 1 1 2 1 2 1 1 2 1 1 1 1 2 1 1 1 1 2 2 1 2 1 1 2 1 2 2 1 2 2 2 1 2 2 1 2 2 1 1 1 2 2 2\r\n", "output": "123\r\n"}, {"input": "4\r\n2 2 2 2\r\n", "output": "0\r\n"}, {"input": "4\r\n1 1 1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n1 1\r\n", "output": "0\r\n"}, {"input": "2\r\n2 1\r\n", "output": "1\r\n"}, {"input": "2\r\n1 2\r\n", "output": "1\r\n"}, {"input": "3\r\n1 1 2\r\n", "output": "1\r\n"}, {"input": "3\r\n1 2 2\r\n", "output": "1\r\n"}, {"input": "3\r\n2 1 1\r\n", "output": "1\r\n"}, {"input": "3\r\n2 1 2\r\n", "output": "1\r\n"}, {"input": "3\r\n2 2 1\r\n", "output": "1\r\n"}, {"input": "4\r\n1 1 1 2\r\n", "output": "1\r\n"}, {"input": "4\r\n1 1 2 2\r\n", "output": "2\r\n"}, {"input": "4\r\n1 2 2 2\r\n", "output": "1\r\n"}, {"input": "4\r\n2 1 1 1\r\n", "output": "1\r\n"}, {"input": "5\r\n1 1 1 1 2\r\n", "output": "2\r\n"}, {"input": "14\r\n1 2 2 2 2 2 2 2 2 2 2 2 2 2\r\n", "output": "1\r\n"}, {"input": "38\r\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1\r\n", "output": "1\r\n"}, {"input": "30\r\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1\r\n", "output": "1\r\n"}, {"input": "20\r\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1\r\n", "output": "1\r\n"}, {"input": "26\r\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2\r\n", "output": "1\r\n"}, {"input": "6\r\n1 1 1 2 2 2\r\n", "output": "3\r\n"}, {"input": "5\r\n2 1 1 1 1\r\n", "output": "2\r\n"}, {"input": "9\r\n1 1 1 1 1 1 2 2 2\r\n", "output": "4\r\n"}, {"input": "10\r\n2 2 1 1 1 1 1 1 1 1\r\n", "output": "4\r\n"}, {"input": "6\r\n1 1 1 1 1 1\r\n", "output": "2\r\n"}]
| false |
stdio
| null | true |
899/A
|
899
|
A
|
Python 3
|
TESTS
| 18 | 124 | 2,969,600 |
44864940
|
x=int(input())
y1=input().split()
s=y1.count("1")
s1=y1.count("2")
if (s!=0) and (s1==0):
print(s//3)
elif s>s1:
print(s1)
elif s<s1:
print(s)
elif s==s1:
print(s)
| 67 | 62 | 5,529,600 |
223284000
|
n = int(input())
a = list(map(int, input().split()))
groups1 = a.count(1)
groups2 = a.count(2)
max = 0
max += min(groups1, groups2)
groups1 -= max
groups2 -= max
max += groups1 // 3
print(max)
|
Codeforces Round 452 (Div. 2)
|
CF
| 2,017 | 1 | 256 |
Splitting in Teams
|
There were n groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team.
The coach decided to form teams of exactly three people for this training. Determine the maximum number of teams of three people he can form. It is possible that he can't use all groups to form teams. For groups of two, either both students should write the contest, or both should not. If two students from a group of two will write the contest, they should be in the same team.
|
The first line contains single integer n (2 ≤ n ≤ 2·105) — the number of groups.
The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 2), where ai is the number of people in group i.
|
Print the maximum number of teams of three people the coach can form.
| null |
In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups.
In the second example he can't make a single team.
In the third example the coach can form three teams. For example, he can do this in the following way:
- The first group (of two people) and the seventh group (of one person),
- The second group (of two people) and the sixth group (of one person),
- The third group (of two people) and the fourth group (of one person).
|
[{"input": "4\n1 1 2 1", "output": "1"}, {"input": "2\n2 2", "output": "0"}, {"input": "7\n2 2 2 1 1 1 1", "output": "3"}, {"input": "3\n1 1 1", "output": "1"}]
| 800 |
["constructive algorithms", "greedy", "math"]
| 67 |
[{"input": "4\r\n1 1 2 1\r\n", "output": "1\r\n"}, {"input": "2\r\n2 2\r\n", "output": "0\r\n"}, {"input": "7\r\n2 2 2 1 1 1 1\r\n", "output": "3\r\n"}, {"input": "3\r\n1 1 1\r\n", "output": "1\r\n"}, {"input": "3\r\n2 2 2\r\n", "output": "0\r\n"}, {"input": "3\r\n1 2 1\r\n", "output": "1\r\n"}, {"input": "5\r\n2 2 1 1 1\r\n", "output": "2\r\n"}, {"input": "7\r\n1 1 2 2 1 2 1\r\n", "output": "3\r\n"}, {"input": "10\r\n1 2 2 1 2 2 1 2 1 1\r\n", "output": "5\r\n"}, {"input": "5\r\n2 2 2 1 2\r\n", "output": "1\r\n"}, {"input": "43\r\n1 2 2 2 1 1 2 2 1 1 2 2 2 2 1 2 2 2 2 2 1 2 1 2 1 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2\r\n", "output": "10\r\n"}, {"input": "72\r\n1 2 1 2 2 1 2 1 1 1 1 2 2 1 2 1 2 1 2 2 2 2 1 2 2 2 2 1 2 1 1 2 2 1 1 2 2 2 2 2 1 1 1 1 2 2 1 1 2 1 1 1 1 2 2 1 2 2 1 2 1 1 2 1 2 2 1 1 1 2 2 2\r\n", "output": "34\r\n"}, {"input": "64\r\n2 2 1 1 1 2 1 1 1 2 2 1 2 2 2 1 2 2 2 1 1 1 1 2 1 2 1 2 1 1 2 2 1 1 2 2 1 1 1 1 2 2 1 1 1 2 1 2 2 2 2 2 2 2 1 1 2 1 1 1 2 2 1 2\r\n", "output": "32\r\n"}, {"input": "20\r\n1 1 1 1 2 1 2 2 2 1 2 1 2 1 2 1 1 2 1 2\r\n", "output": "9\r\n"}, {"input": "23\r\n1 1 1 1 2 1 2 1 1 1 2 2 2 2 2 2 1 2 1 2 2 1 1\r\n", "output": "11\r\n"}, {"input": "201\r\n1 1 2 2 2 2 1 1 1 2 2 1 2 1 2 1 2 2 2 1 1 2 1 1 1 2 1 2 1 1 1 2 1 1 2 1 2 2 1 1 1 1 2 1 1 2 1 1 1 2 2 2 2 1 2 1 2 2 2 2 2 2 1 1 1 2 2 1 1 1 1 2 2 1 2 1 1 2 2 1 1 2 2 2 1 1 1 2 1 1 2 1 2 2 1 2 2 2 2 1 1 1 2 1 2 2 2 2 2 1 2 1 1 1 2 2 2 2 2 1 2 1 1 2 2 2 1 1 2 2 1 2 2 2 1 1 1 2 1 1 1 2 1 1 2 2 2 1 2 1 1 1 2 2 1 1 2 2 2 2 2 2 1 2 2 1 2 2 2 1 1 2 2 1 1 2 1 1 1 1 2 1 1 1 2 2 1 2 1 1 2 2 1 1 2 1 2 1 1 1 2\r\n", "output": "100\r\n"}, {"input": "247\r\n2 2 1 2 1 2 2 2 2 2 2 1 1 2 2 1 2 1 1 1 2 1 1 1 1 2 1 1 2 2 1 2 1 1 1 2 2 2 1 1 2 1 1 2 1 1 1 2 1 2 1 2 2 1 1 2 1 2 2 1 2 1 2 1 1 2 1 1 1 2 2 1 1 2 2 1 1 2 1 1 1 2 2 2 2 1 2 2 2 2 2 2 1 2 2 2 2 1 1 1 1 1 1 1 1 1 2 1 2 2 1 2 1 2 2 2 1 2 2 2 1 1 2 2 1 1 1 2 1 1 1 1 2 2 1 2 2 1 1 1 2 1 2 2 1 2 1 1 1 2 2 2 2 2 1 2 2 2 1 1 1 2 1 2 1 1 2 2 2 2 1 1 2 2 2 1 2 2 2 1 2 1 1 2 2 2 2 1 2 2 1 1 1 2 1 2 1 1 1 2 2 1 1 2 1 1 2 1 2 1 1 2 1 1 1 1 2 1 1 1 1 2 2 1 2 1 1 2 1 2 2 1 2 2 2 1 2 2 1 2 2 1 1 1 2 2 2\r\n", "output": "123\r\n"}, {"input": "4\r\n2 2 2 2\r\n", "output": "0\r\n"}, {"input": "4\r\n1 1 1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n1 1\r\n", "output": "0\r\n"}, {"input": "2\r\n2 1\r\n", "output": "1\r\n"}, {"input": "2\r\n1 2\r\n", "output": "1\r\n"}, {"input": "3\r\n1 1 2\r\n", "output": "1\r\n"}, {"input": "3\r\n1 2 2\r\n", "output": "1\r\n"}, {"input": "3\r\n2 1 1\r\n", "output": "1\r\n"}, {"input": "3\r\n2 1 2\r\n", "output": "1\r\n"}, {"input": "3\r\n2 2 1\r\n", "output": "1\r\n"}, {"input": "4\r\n1 1 1 2\r\n", "output": "1\r\n"}, {"input": "4\r\n1 1 2 2\r\n", "output": "2\r\n"}, {"input": "4\r\n1 2 2 2\r\n", "output": "1\r\n"}, {"input": "4\r\n2 1 1 1\r\n", "output": "1\r\n"}, {"input": "5\r\n1 1 1 1 2\r\n", "output": "2\r\n"}, {"input": "14\r\n1 2 2 2 2 2 2 2 2 2 2 2 2 2\r\n", "output": "1\r\n"}, {"input": "38\r\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1\r\n", "output": "1\r\n"}, {"input": "30\r\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1\r\n", "output": "1\r\n"}, {"input": "20\r\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1\r\n", "output": "1\r\n"}, {"input": "26\r\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2\r\n", "output": "1\r\n"}, {"input": "6\r\n1 1 1 2 2 2\r\n", "output": "3\r\n"}, {"input": "5\r\n2 1 1 1 1\r\n", "output": "2\r\n"}, {"input": "9\r\n1 1 1 1 1 1 2 2 2\r\n", "output": "4\r\n"}, {"input": "10\r\n2 2 1 1 1 1 1 1 1 1\r\n", "output": "4\r\n"}, {"input": "6\r\n1 1 1 1 1 1\r\n", "output": "2\r\n"}]
| false |
stdio
| null | true |
899/A
|
899
|
A
|
PyPy 3
|
TESTS
| 18 | 108 | 20,172,800 |
129632760
|
n, lst, s1, s2 = int(input()), list(map(int, input().split())), 0, 0
for x in lst:
if x == 1: s1 += 1
else: s2 += 1
print(max(s1 // 3, min(s1, s2)))
| 67 | 62 | 6,860,800 |
33398911
|
if __name__ == '__main__':
n = input()
a = input()
num1 = a.count('1')
num2 = a.count('2')
ans = min(num1,num2) + max(num1-num2,0)//3
print(ans)
|
Codeforces Round 452 (Div. 2)
|
CF
| 2,017 | 1 | 256 |
Splitting in Teams
|
There were n groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team.
The coach decided to form teams of exactly three people for this training. Determine the maximum number of teams of three people he can form. It is possible that he can't use all groups to form teams. For groups of two, either both students should write the contest, or both should not. If two students from a group of two will write the contest, they should be in the same team.
|
The first line contains single integer n (2 ≤ n ≤ 2·105) — the number of groups.
The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 2), where ai is the number of people in group i.
|
Print the maximum number of teams of three people the coach can form.
| null |
In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups.
In the second example he can't make a single team.
In the third example the coach can form three teams. For example, he can do this in the following way:
- The first group (of two people) and the seventh group (of one person),
- The second group (of two people) and the sixth group (of one person),
- The third group (of two people) and the fourth group (of one person).
|
[{"input": "4\n1 1 2 1", "output": "1"}, {"input": "2\n2 2", "output": "0"}, {"input": "7\n2 2 2 1 1 1 1", "output": "3"}, {"input": "3\n1 1 1", "output": "1"}]
| 800 |
["constructive algorithms", "greedy", "math"]
| 67 |
[{"input": "4\r\n1 1 2 1\r\n", "output": "1\r\n"}, {"input": "2\r\n2 2\r\n", "output": "0\r\n"}, {"input": "7\r\n2 2 2 1 1 1 1\r\n", "output": "3\r\n"}, {"input": "3\r\n1 1 1\r\n", "output": "1\r\n"}, {"input": "3\r\n2 2 2\r\n", "output": "0\r\n"}, {"input": "3\r\n1 2 1\r\n", "output": "1\r\n"}, {"input": "5\r\n2 2 1 1 1\r\n", "output": "2\r\n"}, {"input": "7\r\n1 1 2 2 1 2 1\r\n", "output": "3\r\n"}, {"input": "10\r\n1 2 2 1 2 2 1 2 1 1\r\n", "output": "5\r\n"}, {"input": "5\r\n2 2 2 1 2\r\n", "output": "1\r\n"}, {"input": "43\r\n1 2 2 2 1 1 2 2 1 1 2 2 2 2 1 2 2 2 2 2 1 2 1 2 1 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2\r\n", "output": "10\r\n"}, {"input": "72\r\n1 2 1 2 2 1 2 1 1 1 1 2 2 1 2 1 2 1 2 2 2 2 1 2 2 2 2 1 2 1 1 2 2 1 1 2 2 2 2 2 1 1 1 1 2 2 1 1 2 1 1 1 1 2 2 1 2 2 1 2 1 1 2 1 2 2 1 1 1 2 2 2\r\n", "output": "34\r\n"}, {"input": "64\r\n2 2 1 1 1 2 1 1 1 2 2 1 2 2 2 1 2 2 2 1 1 1 1 2 1 2 1 2 1 1 2 2 1 1 2 2 1 1 1 1 2 2 1 1 1 2 1 2 2 2 2 2 2 2 1 1 2 1 1 1 2 2 1 2\r\n", "output": "32\r\n"}, {"input": "20\r\n1 1 1 1 2 1 2 2 2 1 2 1 2 1 2 1 1 2 1 2\r\n", "output": "9\r\n"}, {"input": "23\r\n1 1 1 1 2 1 2 1 1 1 2 2 2 2 2 2 1 2 1 2 2 1 1\r\n", "output": "11\r\n"}, {"input": "201\r\n1 1 2 2 2 2 1 1 1 2 2 1 2 1 2 1 2 2 2 1 1 2 1 1 1 2 1 2 1 1 1 2 1 1 2 1 2 2 1 1 1 1 2 1 1 2 1 1 1 2 2 2 2 1 2 1 2 2 2 2 2 2 1 1 1 2 2 1 1 1 1 2 2 1 2 1 1 2 2 1 1 2 2 2 1 1 1 2 1 1 2 1 2 2 1 2 2 2 2 1 1 1 2 1 2 2 2 2 2 1 2 1 1 1 2 2 2 2 2 1 2 1 1 2 2 2 1 1 2 2 1 2 2 2 1 1 1 2 1 1 1 2 1 1 2 2 2 1 2 1 1 1 2 2 1 1 2 2 2 2 2 2 1 2 2 1 2 2 2 1 1 2 2 1 1 2 1 1 1 1 2 1 1 1 2 2 1 2 1 1 2 2 1 1 2 1 2 1 1 1 2\r\n", "output": "100\r\n"}, {"input": "247\r\n2 2 1 2 1 2 2 2 2 2 2 1 1 2 2 1 2 1 1 1 2 1 1 1 1 2 1 1 2 2 1 2 1 1 1 2 2 2 1 1 2 1 1 2 1 1 1 2 1 2 1 2 2 1 1 2 1 2 2 1 2 1 2 1 1 2 1 1 1 2 2 1 1 2 2 1 1 2 1 1 1 2 2 2 2 1 2 2 2 2 2 2 1 2 2 2 2 1 1 1 1 1 1 1 1 1 2 1 2 2 1 2 1 2 2 2 1 2 2 2 1 1 2 2 1 1 1 2 1 1 1 1 2 2 1 2 2 1 1 1 2 1 2 2 1 2 1 1 1 2 2 2 2 2 1 2 2 2 1 1 1 2 1 2 1 1 2 2 2 2 1 1 2 2 2 1 2 2 2 1 2 1 1 2 2 2 2 1 2 2 1 1 1 2 1 2 1 1 1 2 2 1 1 2 1 1 2 1 2 1 1 2 1 1 1 1 2 1 1 1 1 2 2 1 2 1 1 2 1 2 2 1 2 2 2 1 2 2 1 2 2 1 1 1 2 2 2\r\n", "output": "123\r\n"}, {"input": "4\r\n2 2 2 2\r\n", "output": "0\r\n"}, {"input": "4\r\n1 1 1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n1 1\r\n", "output": "0\r\n"}, {"input": "2\r\n2 1\r\n", "output": "1\r\n"}, {"input": "2\r\n1 2\r\n", "output": "1\r\n"}, {"input": "3\r\n1 1 2\r\n", "output": "1\r\n"}, {"input": "3\r\n1 2 2\r\n", "output": "1\r\n"}, {"input": "3\r\n2 1 1\r\n", "output": "1\r\n"}, {"input": "3\r\n2 1 2\r\n", "output": "1\r\n"}, {"input": "3\r\n2 2 1\r\n", "output": "1\r\n"}, {"input": "4\r\n1 1 1 2\r\n", "output": "1\r\n"}, {"input": "4\r\n1 1 2 2\r\n", "output": "2\r\n"}, {"input": "4\r\n1 2 2 2\r\n", "output": "1\r\n"}, {"input": "4\r\n2 1 1 1\r\n", "output": "1\r\n"}, {"input": "5\r\n1 1 1 1 2\r\n", "output": "2\r\n"}, {"input": "14\r\n1 2 2 2 2 2 2 2 2 2 2 2 2 2\r\n", "output": "1\r\n"}, {"input": "38\r\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1\r\n", "output": "1\r\n"}, {"input": "30\r\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1\r\n", "output": "1\r\n"}, {"input": "20\r\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1\r\n", "output": "1\r\n"}, {"input": "26\r\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2\r\n", "output": "1\r\n"}, {"input": "6\r\n1 1 1 2 2 2\r\n", "output": "3\r\n"}, {"input": "5\r\n2 1 1 1 1\r\n", "output": "2\r\n"}, {"input": "9\r\n1 1 1 1 1 1 2 2 2\r\n", "output": "4\r\n"}, {"input": "10\r\n2 2 1 1 1 1 1 1 1 1\r\n", "output": "4\r\n"}, {"input": "6\r\n1 1 1 1 1 1\r\n", "output": "2\r\n"}]
| false |
stdio
| null | true |
899/A
|
899
|
A
|
Python 3
|
TESTS
| 18 | 140 | 3,993,600 |
60493630
|
n = int(input())
l = list(map(int,input().split()))
a = l.count(1)
b = l.count(2)
if b==0:
print(len(l)//3)
else:
print(min(a,b))
| 67 | 62 | 6,963,200 |
33332425
|
n = int(input())
A = input()
a = A.count('2')
b = A.count('1')
print(min(a,b)+(b-min(a,b))//3)
|
Codeforces Round 452 (Div. 2)
|
CF
| 2,017 | 1 | 256 |
Splitting in Teams
|
There were n groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team.
The coach decided to form teams of exactly three people for this training. Determine the maximum number of teams of three people he can form. It is possible that he can't use all groups to form teams. For groups of two, either both students should write the contest, or both should not. If two students from a group of two will write the contest, they should be in the same team.
|
The first line contains single integer n (2 ≤ n ≤ 2·105) — the number of groups.
The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 2), where ai is the number of people in group i.
|
Print the maximum number of teams of three people the coach can form.
| null |
In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups.
In the second example he can't make a single team.
In the third example the coach can form three teams. For example, he can do this in the following way:
- The first group (of two people) and the seventh group (of one person),
- The second group (of two people) and the sixth group (of one person),
- The third group (of two people) and the fourth group (of one person).
|
[{"input": "4\n1 1 2 1", "output": "1"}, {"input": "2\n2 2", "output": "0"}, {"input": "7\n2 2 2 1 1 1 1", "output": "3"}, {"input": "3\n1 1 1", "output": "1"}]
| 800 |
["constructive algorithms", "greedy", "math"]
| 67 |
[{"input": "4\r\n1 1 2 1\r\n", "output": "1\r\n"}, {"input": "2\r\n2 2\r\n", "output": "0\r\n"}, {"input": "7\r\n2 2 2 1 1 1 1\r\n", "output": "3\r\n"}, {"input": "3\r\n1 1 1\r\n", "output": "1\r\n"}, {"input": "3\r\n2 2 2\r\n", "output": "0\r\n"}, {"input": "3\r\n1 2 1\r\n", "output": "1\r\n"}, {"input": "5\r\n2 2 1 1 1\r\n", "output": "2\r\n"}, {"input": "7\r\n1 1 2 2 1 2 1\r\n", "output": "3\r\n"}, {"input": "10\r\n1 2 2 1 2 2 1 2 1 1\r\n", "output": "5\r\n"}, {"input": "5\r\n2 2 2 1 2\r\n", "output": "1\r\n"}, {"input": "43\r\n1 2 2 2 1 1 2 2 1 1 2 2 2 2 1 2 2 2 2 2 1 2 1 2 1 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2\r\n", "output": "10\r\n"}, {"input": "72\r\n1 2 1 2 2 1 2 1 1 1 1 2 2 1 2 1 2 1 2 2 2 2 1 2 2 2 2 1 2 1 1 2 2 1 1 2 2 2 2 2 1 1 1 1 2 2 1 1 2 1 1 1 1 2 2 1 2 2 1 2 1 1 2 1 2 2 1 1 1 2 2 2\r\n", "output": "34\r\n"}, {"input": "64\r\n2 2 1 1 1 2 1 1 1 2 2 1 2 2 2 1 2 2 2 1 1 1 1 2 1 2 1 2 1 1 2 2 1 1 2 2 1 1 1 1 2 2 1 1 1 2 1 2 2 2 2 2 2 2 1 1 2 1 1 1 2 2 1 2\r\n", "output": "32\r\n"}, {"input": "20\r\n1 1 1 1 2 1 2 2 2 1 2 1 2 1 2 1 1 2 1 2\r\n", "output": "9\r\n"}, {"input": "23\r\n1 1 1 1 2 1 2 1 1 1 2 2 2 2 2 2 1 2 1 2 2 1 1\r\n", "output": "11\r\n"}, {"input": "201\r\n1 1 2 2 2 2 1 1 1 2 2 1 2 1 2 1 2 2 2 1 1 2 1 1 1 2 1 2 1 1 1 2 1 1 2 1 2 2 1 1 1 1 2 1 1 2 1 1 1 2 2 2 2 1 2 1 2 2 2 2 2 2 1 1 1 2 2 1 1 1 1 2 2 1 2 1 1 2 2 1 1 2 2 2 1 1 1 2 1 1 2 1 2 2 1 2 2 2 2 1 1 1 2 1 2 2 2 2 2 1 2 1 1 1 2 2 2 2 2 1 2 1 1 2 2 2 1 1 2 2 1 2 2 2 1 1 1 2 1 1 1 2 1 1 2 2 2 1 2 1 1 1 2 2 1 1 2 2 2 2 2 2 1 2 2 1 2 2 2 1 1 2 2 1 1 2 1 1 1 1 2 1 1 1 2 2 1 2 1 1 2 2 1 1 2 1 2 1 1 1 2\r\n", "output": "100\r\n"}, {"input": "247\r\n2 2 1 2 1 2 2 2 2 2 2 1 1 2 2 1 2 1 1 1 2 1 1 1 1 2 1 1 2 2 1 2 1 1 1 2 2 2 1 1 2 1 1 2 1 1 1 2 1 2 1 2 2 1 1 2 1 2 2 1 2 1 2 1 1 2 1 1 1 2 2 1 1 2 2 1 1 2 1 1 1 2 2 2 2 1 2 2 2 2 2 2 1 2 2 2 2 1 1 1 1 1 1 1 1 1 2 1 2 2 1 2 1 2 2 2 1 2 2 2 1 1 2 2 1 1 1 2 1 1 1 1 2 2 1 2 2 1 1 1 2 1 2 2 1 2 1 1 1 2 2 2 2 2 1 2 2 2 1 1 1 2 1 2 1 1 2 2 2 2 1 1 2 2 2 1 2 2 2 1 2 1 1 2 2 2 2 1 2 2 1 1 1 2 1 2 1 1 1 2 2 1 1 2 1 1 2 1 2 1 1 2 1 1 1 1 2 1 1 1 1 2 2 1 2 1 1 2 1 2 2 1 2 2 2 1 2 2 1 2 2 1 1 1 2 2 2\r\n", "output": "123\r\n"}, {"input": "4\r\n2 2 2 2\r\n", "output": "0\r\n"}, {"input": "4\r\n1 1 1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n1 1\r\n", "output": "0\r\n"}, {"input": "2\r\n2 1\r\n", "output": "1\r\n"}, {"input": "2\r\n1 2\r\n", "output": "1\r\n"}, {"input": "3\r\n1 1 2\r\n", "output": "1\r\n"}, {"input": "3\r\n1 2 2\r\n", "output": "1\r\n"}, {"input": "3\r\n2 1 1\r\n", "output": "1\r\n"}, {"input": "3\r\n2 1 2\r\n", "output": "1\r\n"}, {"input": "3\r\n2 2 1\r\n", "output": "1\r\n"}, {"input": "4\r\n1 1 1 2\r\n", "output": "1\r\n"}, {"input": "4\r\n1 1 2 2\r\n", "output": "2\r\n"}, {"input": "4\r\n1 2 2 2\r\n", "output": "1\r\n"}, {"input": "4\r\n2 1 1 1\r\n", "output": "1\r\n"}, {"input": "5\r\n1 1 1 1 2\r\n", "output": "2\r\n"}, {"input": "14\r\n1 2 2 2 2 2 2 2 2 2 2 2 2 2\r\n", "output": "1\r\n"}, {"input": "38\r\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1\r\n", "output": "1\r\n"}, {"input": "30\r\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1\r\n", "output": "1\r\n"}, {"input": "20\r\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1\r\n", "output": "1\r\n"}, {"input": "26\r\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2\r\n", "output": "1\r\n"}, {"input": "6\r\n1 1 1 2 2 2\r\n", "output": "3\r\n"}, {"input": "5\r\n2 1 1 1 1\r\n", "output": "2\r\n"}, {"input": "9\r\n1 1 1 1 1 1 2 2 2\r\n", "output": "4\r\n"}, {"input": "10\r\n2 2 1 1 1 1 1 1 1 1\r\n", "output": "4\r\n"}, {"input": "6\r\n1 1 1 1 1 1\r\n", "output": "2\r\n"}]
| false |
stdio
| null | true |
404/A
|
404
|
A
|
Python 3
|
TESTS
| 31 | 46 | 0 |
206932343
|
n=int(input())
o="YES"
g=None
for i in range(n):
s=list(input())
if (g is None):
g=s[0]
if(s[i]==s[n-i-1] and s[i]==g and len(set(s))==2 ):
if (s==s[::-1]):
continue
else :
o="NO"
break
else:
o="NO"
break
print(o)
| 47 | 46 | 0 |
162679552
|
n = int(input())
l = 0
d = None
o = None
for i in range(n):
s = input()
for i in range(len(s)):
if not d:
d = s[i]
elif not o:
o = s[i]
if o == d:
print("NO")
quit()
elif l == i or n - l - 1 == i:
if s[i] != d or s[n - l - 1] != d:
print("NO")
quit()
else:
if s[i] != o:
print("NO")
quit()
l += 1
print("YES")
|
Codeforces Round 237 (Div. 2)
|
CF
| 2,014 | 1 | 256 |
Valera and X
|
Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the side equals n squares (n is an odd number) and each unit square contains some small letter of the English alphabet.
Valera needs to know if the letters written on the square piece of paper form letter "X". Valera's teacher thinks that the letters on the piece of paper form an "X", if:
- on both diagonals of the square paper all letters are the same;
- all other squares of the paper (they are not on the diagonals) contain the same letter that is different from the letters on the diagonals.
Help Valera, write the program that completes the described task for him.
|
The first line contains integer n (3 ≤ n < 300; n is odd). Each of the next n lines contains n small English letters — the description of Valera's paper.
|
Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes.
| null | null |
[{"input": "5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox", "output": "NO"}, {"input": "3\nwsw\nsws\nwsw", "output": "YES"}, {"input": "3\nxpx\npxp\nxpe", "output": "NO"}]
| 1,000 |
["implementation"]
| 47 |
[{"input": "5\r\nxooox\r\noxoxo\r\nsoxoo\r\noxoxo\r\nxooox\r\n", "output": "NO\r\n"}, {"input": "3\r\nwsw\r\nsws\r\nwsw\r\n", "output": "YES\r\n"}, {"input": "3\r\nxpx\r\npxp\r\nxpe\r\n", "output": "NO\r\n"}, {"input": "5\r\nliiil\r\nilili\r\niilii\r\nilili\r\nliiil\r\n", "output": "YES\r\n"}, {"input": "7\r\nbwccccb\r\nckcccbj\r\nccbcbcc\r\ncccbccc\r\nccbcbcc\r\ncbcccbc\r\nbccccdt\r\n", "output": "NO\r\n"}, {"input": "13\r\nsooooooooooos\r\nosoooooooooso\r\noosooooooosoo\r\nooosooooosooo\r\noooosooosoooo\r\nooooososooooo\r\noooooosoooooo\r\nooooososooooo\r\noooosooosoooo\r\nooosooooosooo\r\noosooooooosoo\r\nosoooooooooso\r\nsooooooooooos\r\n", "output": "YES\r\n"}, {"input": "3\r\naaa\r\naaa\r\naaa\r\n", "output": "NO\r\n"}, {"input": "3\r\naca\r\noec\r\nzba\r\n", "output": "NO\r\n"}, {"input": "15\r\nrxeeeeeeeeeeeer\r\nereeeeeeeeeeere\r\needeeeeeeeeeoee\r\neeereeeeeeeewee\r\neeeereeeeebeeee\r\nqeeeereeejedyee\r\neeeeeerereeeeee\r\neeeeeeereeeeeee\r\neeeeeerereeeeze\r\neeeeereeereeeee\r\neeeereeeeegeeee\r\neeereeeeeeereee\r\neereeeeeeqeeved\r\ncreeeeeeceeeere\r\nreeerneeeeeeeer\r\n", "output": "NO\r\n"}, {"input": "5\r\nxxxxx\r\nxxxxx\r\nxxxxx\r\nxxxxx\r\nxxxxx\r\n", "output": "NO\r\n"}, {"input": "5\r\nxxxxx\r\nxxxxx\r\nxoxxx\r\nxxxxx\r\nxxxxx\r\n", "output": "NO\r\n"}, {"input": "5\r\noxxxo\r\nxoxox\r\nxxxxx\r\nxoxox\r\noxxxo\r\n", "output": "NO\r\n"}, {"input": "5\r\noxxxo\r\nxoxox\r\nxxoox\r\nxoxox\r\noxxxo\r\n", "output": "NO\r\n"}, {"input": "5\r\noxxxo\r\nxoxox\r\nxxaxx\r\nxoxox\r\noxxxo\r\n", "output": "NO\r\n"}, {"input": "5\r\noxxxo\r\nxoxox\r\noxoxx\r\nxoxox\r\noxxxo\r\n", "output": "NO\r\n"}, {"input": "3\r\nxxx\r\naxa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\naxx\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\naxa\r\nxxx\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\nxxa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\naaa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\naax\r\naxa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxaa\r\naxa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\naxa\r\naax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\naxa\r\nxaa\r\n", "output": "NO\r\n"}, {"input": "3\r\nxfx\r\naxa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\nafa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\naxa\r\nxaf\r\n", "output": "NO\r\n"}, {"input": "3\r\nxox\r\nxxx\r\nxxx\r\n", "output": "NO\r\n"}, {"input": "3\r\naxa\r\naax\r\nxxa\r\n", "output": "NO\r\n"}, {"input": "3\r\nxox\r\noxx\r\nxox\r\n", "output": "NO\r\n"}, {"input": "3\r\nxox\r\nooo\r\nxox\r\n", "output": "NO\r\n"}, {"input": "3\r\naaa\r\naab\r\nbbb\r\n", "output": "NO\r\n"}, {"input": "3\r\nxxx\r\nsxs\r\nxsx\r\n", "output": "NO\r\n"}, {"input": "5\r\nabbba\r\nbabab\r\nbbbbb\r\nbaaab\r\nabbba\r\n", "output": "NO\r\n"}, {"input": "5\r\nabaaa\r\nbbbbb\r\nbbabb\r\nbabab\r\nabbba\r\n", "output": "NO\r\n"}, {"input": "5\r\nxoxox\r\noxoxo\r\nooxoo\r\noxoxo\r\nxooox\r\n", "output": "NO\r\n"}, {"input": "3\r\nxox\r\noxx\r\nxxx\r\n", "output": "NO\r\n"}, {"input": "5\r\nxoooo\r\noxooo\r\nooxoo\r\noooxo\r\noooox\r\n", "output": "NO\r\n"}, {"input": "5\r\nxoooo\r\noxoxx\r\nooxoo\r\noxoxo\r\noxoox\r\n", "output": "NO\r\n"}, {"input": "3\r\naaa\r\nbab\r\naba\r\n", "output": "NO\r\n"}]
| false |
stdio
| null | true |
404/A
|
404
|
A
|
PyPy 3-64
|
TESTS
| 35 | 62 | 1,945,600 |
204389810
|
n = int(input()) ; re = [] ; nn = n ; nnn = n
for _ in range(n) : re.append(input())
chk = re[0][0]
c = 0 ; i = 0 ; j = 0
while c < n :
if re[i][j] == chk : c+=1 ; i+=1 ; j+=1
else : print('NO') ; exit()
cc = 0 ; ii = nn-1 ; jj= nn-1
while cc <n :
if re[ii][jj] == chk : cc+=1 ; ii-=1 ; jj-=1
else : print('NO') ; exit()
zz = 0 ; chk2 = re[0][1]
for a in range(nnn) :
for b in range(nnn) :
if re[a][b] != chk and re[a][b] == chk2: zz+=1
if c+cc == 2*nnn and (c+cc+zz-1 == n*n) : print ('YES' )
else : print('NO')
| 47 | 46 | 0 |
172751795
|
n=int(input())
if n==1:
w=input()
print("YES")
else:
check=True
st=input()
l1=st[0]
l2=st[1]
if st[n-1]!=l1 or st.count(l2)!=n-2:
check=False
for i in range(1, n):
if not check:
break
st=input()
if st[i]==l1 and st[n-1-i]==l1 and (((i*2)+1==n and st.count(l2)==n-1) or ((i*2)+1!=n and st.count(l2)==n-2)):
check=check
else:
check=False
break
if check:
print("YES")
else:
print("NO")
|
Codeforces Round 237 (Div. 2)
|
CF
| 2,014 | 1 | 256 |
Valera and X
|
Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the side equals n squares (n is an odd number) and each unit square contains some small letter of the English alphabet.
Valera needs to know if the letters written on the square piece of paper form letter "X". Valera's teacher thinks that the letters on the piece of paper form an "X", if:
- on both diagonals of the square paper all letters are the same;
- all other squares of the paper (they are not on the diagonals) contain the same letter that is different from the letters on the diagonals.
Help Valera, write the program that completes the described task for him.
|
The first line contains integer n (3 ≤ n < 300; n is odd). Each of the next n lines contains n small English letters — the description of Valera's paper.
|
Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes.
| null | null |
[{"input": "5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox", "output": "NO"}, {"input": "3\nwsw\nsws\nwsw", "output": "YES"}, {"input": "3\nxpx\npxp\nxpe", "output": "NO"}]
| 1,000 |
["implementation"]
| 47 |
[{"input": "5\r\nxooox\r\noxoxo\r\nsoxoo\r\noxoxo\r\nxooox\r\n", "output": "NO\r\n"}, {"input": "3\r\nwsw\r\nsws\r\nwsw\r\n", "output": "YES\r\n"}, {"input": "3\r\nxpx\r\npxp\r\nxpe\r\n", "output": "NO\r\n"}, {"input": "5\r\nliiil\r\nilili\r\niilii\r\nilili\r\nliiil\r\n", "output": "YES\r\n"}, {"input": "7\r\nbwccccb\r\nckcccbj\r\nccbcbcc\r\ncccbccc\r\nccbcbcc\r\ncbcccbc\r\nbccccdt\r\n", "output": "NO\r\n"}, {"input": "13\r\nsooooooooooos\r\nosoooooooooso\r\noosooooooosoo\r\nooosooooosooo\r\noooosooosoooo\r\nooooososooooo\r\noooooosoooooo\r\nooooososooooo\r\noooosooosoooo\r\nooosooooosooo\r\noosooooooosoo\r\nosoooooooooso\r\nsooooooooooos\r\n", "output": "YES\r\n"}, {"input": "3\r\naaa\r\naaa\r\naaa\r\n", "output": "NO\r\n"}, {"input": "3\r\naca\r\noec\r\nzba\r\n", "output": "NO\r\n"}, {"input": "15\r\nrxeeeeeeeeeeeer\r\nereeeeeeeeeeere\r\needeeeeeeeeeoee\r\neeereeeeeeeewee\r\neeeereeeeebeeee\r\nqeeeereeejedyee\r\neeeeeerereeeeee\r\neeeeeeereeeeeee\r\neeeeeerereeeeze\r\neeeeereeereeeee\r\neeeereeeeegeeee\r\neeereeeeeeereee\r\neereeeeeeqeeved\r\ncreeeeeeceeeere\r\nreeerneeeeeeeer\r\n", "output": "NO\r\n"}, {"input": "5\r\nxxxxx\r\nxxxxx\r\nxxxxx\r\nxxxxx\r\nxxxxx\r\n", "output": "NO\r\n"}, {"input": "5\r\nxxxxx\r\nxxxxx\r\nxoxxx\r\nxxxxx\r\nxxxxx\r\n", "output": "NO\r\n"}, {"input": "5\r\noxxxo\r\nxoxox\r\nxxxxx\r\nxoxox\r\noxxxo\r\n", "output": "NO\r\n"}, {"input": "5\r\noxxxo\r\nxoxox\r\nxxoox\r\nxoxox\r\noxxxo\r\n", "output": "NO\r\n"}, {"input": "5\r\noxxxo\r\nxoxox\r\nxxaxx\r\nxoxox\r\noxxxo\r\n", "output": "NO\r\n"}, {"input": "5\r\noxxxo\r\nxoxox\r\noxoxx\r\nxoxox\r\noxxxo\r\n", "output": "NO\r\n"}, {"input": "3\r\nxxx\r\naxa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\naxx\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\naxa\r\nxxx\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\nxxa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\naaa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\naax\r\naxa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxaa\r\naxa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\naxa\r\naax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\naxa\r\nxaa\r\n", "output": "NO\r\n"}, {"input": "3\r\nxfx\r\naxa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\nafa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\naxa\r\nxaf\r\n", "output": "NO\r\n"}, {"input": "3\r\nxox\r\nxxx\r\nxxx\r\n", "output": "NO\r\n"}, {"input": "3\r\naxa\r\naax\r\nxxa\r\n", "output": "NO\r\n"}, {"input": "3\r\nxox\r\noxx\r\nxox\r\n", "output": "NO\r\n"}, {"input": "3\r\nxox\r\nooo\r\nxox\r\n", "output": "NO\r\n"}, {"input": "3\r\naaa\r\naab\r\nbbb\r\n", "output": "NO\r\n"}, {"input": "3\r\nxxx\r\nsxs\r\nxsx\r\n", "output": "NO\r\n"}, {"input": "5\r\nabbba\r\nbabab\r\nbbbbb\r\nbaaab\r\nabbba\r\n", "output": "NO\r\n"}, {"input": "5\r\nabaaa\r\nbbbbb\r\nbbabb\r\nbabab\r\nabbba\r\n", "output": "NO\r\n"}, {"input": "5\r\nxoxox\r\noxoxo\r\nooxoo\r\noxoxo\r\nxooox\r\n", "output": "NO\r\n"}, {"input": "3\r\nxox\r\noxx\r\nxxx\r\n", "output": "NO\r\n"}, {"input": "5\r\nxoooo\r\noxooo\r\nooxoo\r\noooxo\r\noooox\r\n", "output": "NO\r\n"}, {"input": "5\r\nxoooo\r\noxoxx\r\nooxoo\r\noxoxo\r\noxoox\r\n", "output": "NO\r\n"}, {"input": "3\r\naaa\r\nbab\r\naba\r\n", "output": "NO\r\n"}]
| false |
stdio
| null | true |
822/B
|
822
|
B
|
PyPy 3
|
TESTS
| 10 | 77 | 0 |
143743779
|
import math
n, m = map(int, input().split())
s = list(input())
t = list(input())
idx = -1
mv = math.inf
for i in range(m - n + 1):
cnt = 0
for j in range(n):
if s[j] != t[i + j]:
cnt += 1
if cnt < mv:
idx = i
mv = cnt
print(cnt)
for i in range(n):
if s[i] != t[idx + i]:
print(i + 1, end=' ')
| 113 | 77 | 3,072,000 |
155796365
|
n,m=map(int,input().split())
s,t=input(),input()
r=[0]*(m+1)
for i in range(m-n+1):
a=[j+1 for j,x in enumerate(zip(s,t[i:i+n])) if x[0]!=x[1]]
if len(a)<len(r):r=a
print(len(r))
print(*r)
|
Codeforces Round 422 (Div. 2)
|
CF
| 2,017 | 1 | 256 |
Crossword solving
|
Erelong Leha was bored by calculating of the greatest common divisor of two factorials. Therefore he decided to solve some crosswords. It's well known that it is a very interesting occupation though it can be very difficult from time to time. In the course of solving one of the crosswords, Leha had to solve a simple task. You are able to do it too, aren't you?
Leha has two strings s and t. The hacker wants to change the string s at such way, that it can be found in t as a substring. All the changes should be the following: Leha chooses one position in the string s and replaces the symbol in this position with the question mark "?". The hacker is sure that the question mark in comparison can play the role of an arbitrary symbol. For example, if he gets string s="ab?b" as a result, it will appear in t="aabrbb" as a substring.
Guaranteed that the length of the string s doesn't exceed the length of the string t. Help the hacker to replace in s as few symbols as possible so that the result of the replacements can be found in t as a substring. The symbol "?" should be considered equal to any other symbol.
|
The first line contains two integers n and m (1 ≤ n ≤ m ≤ 1000) — the length of the string s and the length of the string t correspondingly.
The second line contains n lowercase English letters — string s.
The third line contains m lowercase English letters — string t.
|
In the first line print single integer k — the minimal number of symbols that need to be replaced.
In the second line print k distinct integers denoting the positions of symbols in the string s which need to be replaced. Print the positions in any order. If there are several solutions print any of them. The numbering of the positions begins from one.
| null | null |
[{"input": "3 5\nabc\nxaybz", "output": "2\n2 3"}, {"input": "4 10\nabcd\nebceabazcd", "output": "1\n2"}]
| 1,000 |
["brute force", "implementation", "strings"]
| 113 |
[{"input": "3 5\r\nabc\r\nxaybz\r\n", "output": "2\r\n2 3 \r\n"}, {"input": "4 10\r\nabcd\r\nebceabazcd\r\n", "output": "1\r\n2 \r\n"}, {"input": "1 1\r\na\r\na\r\n", "output": "0\r\n\r\n"}, {"input": "1 1\r\na\r\nz\r\n", "output": "1\r\n1 \r\n"}, {"input": "3 5\r\naaa\r\naaaaa\r\n", "output": "0\r\n\r\n"}, {"input": "3 5\r\naaa\r\naabaa\r\n", "output": "1\r\n3 \r\n"}, {"input": "5 5\r\ncoder\r\ncored\r\n", "output": "2\r\n3 5 \r\n"}, {"input": "1 1\r\nz\r\nz\r\n", "output": "0\r\n\r\n"}, {"input": "1 2\r\nf\r\nrt\r\n", "output": "1\r\n1 \r\n"}, {"input": "1 2\r\nf\r\nfg\r\n", "output": "0\r\n\r\n"}, {"input": "1 2\r\nf\r\ngf\r\n", "output": "0\r\n\r\n"}, {"input": "2 5\r\naa\r\naabaa\r\n", "output": "0\r\n\r\n"}, {"input": "2 5\r\naa\r\navaca\r\n", "output": "1\r\n2 \r\n"}, {"input": "3 5\r\naaa\r\nbbbbb\r\n", "output": "3\r\n1 2 3 \r\n"}, {"input": "3 5\r\naba\r\ncbcbc\r\n", "output": "2\r\n1 3 \r\n"}, {"input": "3 5\r\naba\r\nbbbbb\r\n", "output": "2\r\n1 3 \r\n"}, {"input": "3 5\r\naaa\r\naabvd\r\n", "output": "1\r\n3 \r\n"}, {"input": "3 5\r\nvvv\r\nbqavv\r\n", "output": "1\r\n1 \r\n"}, {"input": "10 100\r\nmpmmpmmmpm\r\nmppppppmppmmpmpppmpppmmpppmpppppmpppmmmppmpmpmmmpmmpmppmmpppppmpmppppmmppmpmppmmmmpmmppmmmpmpmmmpppp\r\n", "output": "2\r\n5 6 \r\n"}, {"input": "26 26\r\nabcdefghijklmnopqrstuvwxyz\r\nffffffffffffffffffffffffff\r\n", "output": "25\r\n1 2 3 4 5 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 \r\n"}, {"input": "3 5\r\nabc\r\nxyzab\r\n", "output": "3\r\n1 2 3 \r\n"}, {"input": "4 4\r\nabcd\r\nxabc\r\n", "output": "4\r\n1 2 3 4 \r\n"}, {"input": "3 4\r\nabc\r\nabcd\r\n", "output": "0\r\n\r\n"}, {"input": "3 3\r\nabc\r\nxxa\r\n", "output": "3\r\n1 2 3 \r\n"}, {"input": "3 5\r\naab\r\nzfhka\r\n", "output": "3\r\n1 2 3 \r\n"}, {"input": "3 3\r\nabc\r\nxya\r\n", "output": "3\r\n1 2 3 \r\n"}, {"input": "3 3\r\nabc\r\ncab\r\n", "output": "3\r\n1 2 3 \r\n"}, {"input": "5 5\r\nabcde\r\nxxabc\r\n", "output": "5\r\n1 2 3 4 5 \r\n"}, {"input": "3 10\r\nass\r\nabcdefssss\r\n", "output": "1\r\n1 \r\n"}, {"input": "4 4\r\nabcd\r\neeab\r\n", "output": "4\r\n1 2 3 4 \r\n"}, {"input": "3 4\r\nabh\r\nbhaa\r\n", "output": "3\r\n1 2 3 \r\n"}, {"input": "2 3\r\nzb\r\naaz\r\n", "output": "2\r\n1 2 \r\n"}, {"input": "2 3\r\nab\r\ndda\r\n", "output": "2\r\n1 2 \r\n"}, {"input": "3 3\r\ncba\r\nbac\r\n", "output": "3\r\n1 2 3 \r\n"}, {"input": "3 4\r\nabc\r\nxxxa\r\n", "output": "3\r\n1 2 3 \r\n"}, {"input": "2 3\r\nab\r\nbbb\r\n", "output": "1\r\n1 \r\n"}, {"input": "10 15\r\nsdkjeaafww\r\nefjklffnkddkfey\r\n", "output": "9\r\n1 2 4 5 6 7 8 9 10 \r\n"}, {"input": "3 3\r\nabc\r\nzbc\r\n", "output": "1\r\n1 \r\n"}, {"input": "3 7\r\nabc\r\neeeeeab\r\n", "output": "3\r\n1 2 3 \r\n"}, {"input": "2 6\r\nab\r\nxyxbab\r\n", "output": "0\r\n\r\n"}, {"input": "4 7\r\nabcd\r\nzzzzabc\r\n", "output": "4\r\n1 2 3 4 \r\n"}, {"input": "3 5\r\nabc\r\nabzzz\r\n", "output": "1\r\n3 \r\n"}, {"input": "3 3\r\naaz\r\nzaa\r\n", "output": "2\r\n1 3 \r\n"}, {"input": "3 6\r\nabc\r\nxaybzd\r\n", "output": "2\r\n2 3 \r\n"}, {"input": "4 5\r\naaaa\r\naaaap\r\n", "output": "0\r\n\r\n"}]
| false |
stdio
| null | true |
825/C
|
825
|
C
|
Python 3
|
TESTS
| 6 | 46 | 5,632,000 |
34468709
|
n,k = map(int,input().split())
dif = list(map(int,input().split()))
c = 0
mx = 0
for elem in dif:
if elem>k*2 and elem>mx*2:
c+=1
break
if elem>mx: mx = elem
print(c)
| 61 | 46 | 0 |
186670111
|
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
jauap=0
for i in a:
while i>k*2:
jauap+=1
k=k*2
k=max(k,i)
print(jauap)
|
Educational Codeforces Round 25
|
ICPC
| 2,017 | 1 | 256 |
Multi-judge Solving
|
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 a1, a2, ..., an. He can solve these problems in arbitrary order. Though he can solve problem i with difficulty ai only if he had already solved some problem with difficulty $$d \geq \frac{a_i}{2}$$ (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 a1, a2, ..., an (1 ≤ ai ≤ 109).
|
Print minimum number of problems Makes should solve on other judges in order to solve all chosen problems on Decoforces.
| null |
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.
|
[{"input": "3 3\n2 1 9", "output": "1"}, {"input": "4 20\n10 3 6 3", "output": "0"}]
| 1,600 |
["greedy", "implementation"]
| 61 |
[{"input": "3 3\r\n2 1 9\r\n", "output": "1\r\n"}, {"input": "4 20\r\n10 3 6 3\r\n", "output": "0\r\n"}, {"input": "1 1000000000\r\n1\r\n", "output": "0\r\n"}, {"input": "1 1\r\n3\r\n", "output": "1\r\n"}, {"input": "50 100\r\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\r\n", "output": "0\r\n"}, {"input": "100 10\r\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\r\n", "output": "1\r\n"}, {"input": "2 1\r\n1 1000000000\r\n", "output": "29\r\n"}, {"input": "29 2\r\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\r\n", "output": "27\r\n"}, {"input": "1 1\r\n1000000000\r\n", "output": "29\r\n"}, {"input": "7 6\r\n4 20 16 14 3 17 4\r\n", "output": "1\r\n"}, {"input": "2 1\r\n3 6\r\n", "output": "1\r\n"}, {"input": "1 1\r\n20\r\n", "output": "4\r\n"}, {"input": "5 2\r\n86 81 53 25 18\r\n", "output": "4\r\n"}, {"input": "4 1\r\n88 55 14 39\r\n", "output": "4\r\n"}, {"input": "3 1\r\n2 3 6\r\n", "output": "0\r\n"}, {"input": "3 2\r\n4 9 18\r\n", "output": "1\r\n"}, {"input": "5 3\r\n6 6 6 13 27\r\n", "output": "2\r\n"}, {"input": "5 1\r\n23 8 83 26 18\r\n", "output": "4\r\n"}, {"input": "3 1\r\n4 5 6\r\n", "output": "1\r\n"}, {"input": "3 1\r\n1 3 6\r\n", "output": "1\r\n"}, {"input": "1 1\r\n2\r\n", "output": "0\r\n"}, {"input": "3 2\r\n4 5 6\r\n", "output": "0\r\n"}, {"input": "5 1\r\n100 200 400 1000 2000\r\n", "output": "7\r\n"}, {"input": "2 1\r\n1 4\r\n", "output": "1\r\n"}, {"input": "4 1\r\n2 4 8 32\r\n", "output": "1\r\n"}, {"input": "2 10\r\n21 42\r\n", "output": "1\r\n"}, {"input": "3 3\r\n1 7 13\r\n", "output": "1\r\n"}, {"input": "3 1\r\n1 4 6\r\n", "output": "1\r\n"}, {"input": "2 2\r\n2 8\r\n", "output": "1\r\n"}, {"input": "1 1\r\n4\r\n", "output": "1\r\n"}, {"input": "2 2\r\n8 16\r\n", "output": "1\r\n"}, {"input": "3 1\r\n4 8 16\r\n", "output": "1\r\n"}, {"input": "3 1\r\n3 6 9\r\n", "output": "1\r\n"}, {"input": "2 1\r\n4 8\r\n", "output": "1\r\n"}, {"input": "2 2\r\n7 14\r\n", "output": "1\r\n"}, {"input": "1 4\r\n9\r\n", "output": "1\r\n"}, {"input": "5 3\r\n1024 4096 16384 65536 536870913\r\n", "output": "24\r\n"}, {"input": "2 5\r\n10 11\r\n", "output": "0\r\n"}, {"input": "2 2\r\n3 6\r\n", "output": "0\r\n"}, {"input": "2 2\r\n8 11\r\n", "output": "1\r\n"}, {"input": "3 19905705\r\n263637263 417905394 108361057\r\n", "output": "3\r\n"}, {"input": "4 25\r\n100 11 1 13\r\n", "output": "1\r\n"}, {"input": "10 295206008\r\n67980321 440051990 883040288 135744260 96431758 242465794 576630162 972797687 356406646 547451696\r\n", "output": "0\r\n"}, {"input": "4 2\r\n45 44 35 38\r\n", "output": "4\r\n"}, {"input": "1 2\r\n9\r\n", "output": "2\r\n"}, {"input": "3 6\r\n13 26 52\r\n", "output": "1\r\n"}, {"input": "9 30111088\r\n824713578 11195876 458715185 731769293 680826358 189542586 550198537 860586039 101083021\r\n", "output": "2\r\n"}, {"input": "3 72014068\r\n430005292 807436976 828082746\r\n", "output": "2\r\n"}, {"input": "3 165219745\r\n737649884 652879952 506420386\r\n", "output": "1\r\n"}, {"input": "2 60669400\r\n95037700 337255240\r\n", "output": "1\r\n"}, {"input": "4 28\r\n34 1 86 90\r\n", "output": "1\r\n"}, {"input": "2 1\r\n5 10\r\n", "output": "2\r\n"}, {"input": "2 1\r\n4 1000000000\r\n", "output": "28\r\n"}, {"input": "2 1\r\n2 3\r\n", "output": "0\r\n"}, {"input": "2 1\r\n3 5\r\n", "output": "1\r\n"}, {"input": "3 3\r\n1 5 20\r\n", "output": "1\r\n"}, {"input": "9 1\r\n1 2 4 9 15 32 64 128 1024\r\n", "output": "4\r\n"}]
| false |
stdio
| null | true |
404/A
|
404
|
A
|
Python 3
|
TESTS
| 35 | 109 | 7,270,400 |
127673150
|
n = int(input())
lst1 = []
J = ""
H = 0
for i in range(n):
S = input()
lst1.append(S)
J = J + S
for j in range(n):
for k in range(n):
if j==k:
if lst1[j][k]==J[0] and lst1[n-j-1][n-k-1]==J[0]:
H = H + 1
Q = J.count(J[1])
if H == n:
if Q == (n*n - (2*n-1)) :
print("YES")
else:
print("NO")
else:
print("NO")
| 47 | 46 | 0 |
176497800
|
a=int(input())
s=''
c=0
for i in range(a):
x=input()
s+=x
if s==s[::-1] and s.count(s[0])==a*2-1:
print("YES")
else:
print("NO")
|
Codeforces Round 237 (Div. 2)
|
CF
| 2,014 | 1 | 256 |
Valera and X
|
Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the side equals n squares (n is an odd number) and each unit square contains some small letter of the English alphabet.
Valera needs to know if the letters written on the square piece of paper form letter "X". Valera's teacher thinks that the letters on the piece of paper form an "X", if:
- on both diagonals of the square paper all letters are the same;
- all other squares of the paper (they are not on the diagonals) contain the same letter that is different from the letters on the diagonals.
Help Valera, write the program that completes the described task for him.
|
The first line contains integer n (3 ≤ n < 300; n is odd). Each of the next n lines contains n small English letters — the description of Valera's paper.
|
Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes.
| null | null |
[{"input": "5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox", "output": "NO"}, {"input": "3\nwsw\nsws\nwsw", "output": "YES"}, {"input": "3\nxpx\npxp\nxpe", "output": "NO"}]
| 1,000 |
["implementation"]
| 47 |
[{"input": "5\r\nxooox\r\noxoxo\r\nsoxoo\r\noxoxo\r\nxooox\r\n", "output": "NO\r\n"}, {"input": "3\r\nwsw\r\nsws\r\nwsw\r\n", "output": "YES\r\n"}, {"input": "3\r\nxpx\r\npxp\r\nxpe\r\n", "output": "NO\r\n"}, {"input": "5\r\nliiil\r\nilili\r\niilii\r\nilili\r\nliiil\r\n", "output": "YES\r\n"}, {"input": "7\r\nbwccccb\r\nckcccbj\r\nccbcbcc\r\ncccbccc\r\nccbcbcc\r\ncbcccbc\r\nbccccdt\r\n", "output": "NO\r\n"}, {"input": "13\r\nsooooooooooos\r\nosoooooooooso\r\noosooooooosoo\r\nooosooooosooo\r\noooosooosoooo\r\nooooososooooo\r\noooooosoooooo\r\nooooososooooo\r\noooosooosoooo\r\nooosooooosooo\r\noosooooooosoo\r\nosoooooooooso\r\nsooooooooooos\r\n", "output": "YES\r\n"}, {"input": "3\r\naaa\r\naaa\r\naaa\r\n", "output": "NO\r\n"}, {"input": "3\r\naca\r\noec\r\nzba\r\n", "output": "NO\r\n"}, {"input": "15\r\nrxeeeeeeeeeeeer\r\nereeeeeeeeeeere\r\needeeeeeeeeeoee\r\neeereeeeeeeewee\r\neeeereeeeebeeee\r\nqeeeereeejedyee\r\neeeeeerereeeeee\r\neeeeeeereeeeeee\r\neeeeeerereeeeze\r\neeeeereeereeeee\r\neeeereeeeegeeee\r\neeereeeeeeereee\r\neereeeeeeqeeved\r\ncreeeeeeceeeere\r\nreeerneeeeeeeer\r\n", "output": "NO\r\n"}, {"input": "5\r\nxxxxx\r\nxxxxx\r\nxxxxx\r\nxxxxx\r\nxxxxx\r\n", "output": "NO\r\n"}, {"input": "5\r\nxxxxx\r\nxxxxx\r\nxoxxx\r\nxxxxx\r\nxxxxx\r\n", "output": "NO\r\n"}, {"input": "5\r\noxxxo\r\nxoxox\r\nxxxxx\r\nxoxox\r\noxxxo\r\n", "output": "NO\r\n"}, {"input": "5\r\noxxxo\r\nxoxox\r\nxxoox\r\nxoxox\r\noxxxo\r\n", "output": "NO\r\n"}, {"input": "5\r\noxxxo\r\nxoxox\r\nxxaxx\r\nxoxox\r\noxxxo\r\n", "output": "NO\r\n"}, {"input": "5\r\noxxxo\r\nxoxox\r\noxoxx\r\nxoxox\r\noxxxo\r\n", "output": "NO\r\n"}, {"input": "3\r\nxxx\r\naxa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\naxx\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\naxa\r\nxxx\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\nxxa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\naaa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\naax\r\naxa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxaa\r\naxa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\naxa\r\naax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\naxa\r\nxaa\r\n", "output": "NO\r\n"}, {"input": "3\r\nxfx\r\naxa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\nafa\r\nxax\r\n", "output": "NO\r\n"}, {"input": "3\r\nxax\r\naxa\r\nxaf\r\n", "output": "NO\r\n"}, {"input": "3\r\nxox\r\nxxx\r\nxxx\r\n", "output": "NO\r\n"}, {"input": "3\r\naxa\r\naax\r\nxxa\r\n", "output": "NO\r\n"}, {"input": "3\r\nxox\r\noxx\r\nxox\r\n", "output": "NO\r\n"}, {"input": "3\r\nxox\r\nooo\r\nxox\r\n", "output": "NO\r\n"}, {"input": "3\r\naaa\r\naab\r\nbbb\r\n", "output": "NO\r\n"}, {"input": "3\r\nxxx\r\nsxs\r\nxsx\r\n", "output": "NO\r\n"}, {"input": "5\r\nabbba\r\nbabab\r\nbbbbb\r\nbaaab\r\nabbba\r\n", "output": "NO\r\n"}, {"input": "5\r\nabaaa\r\nbbbbb\r\nbbabb\r\nbabab\r\nabbba\r\n", "output": "NO\r\n"}, {"input": "5\r\nxoxox\r\noxoxo\r\nooxoo\r\noxoxo\r\nxooox\r\n", "output": "NO\r\n"}, {"input": "3\r\nxox\r\noxx\r\nxxx\r\n", "output": "NO\r\n"}, {"input": "5\r\nxoooo\r\noxooo\r\nooxoo\r\noooxo\r\noooox\r\n", "output": "NO\r\n"}, {"input": "5\r\nxoooo\r\noxoxx\r\nooxoo\r\noxoxo\r\noxoox\r\n", "output": "NO\r\n"}, {"input": "3\r\naaa\r\nbab\r\naba\r\n", "output": "NO\r\n"}]
| false |
stdio
| null | true |
600/C
|
600
|
C
|
PyPy 3-64
|
TESTS
| 4 | 46 | 0 |
194303698
|
import sys
from collections import *
input = sys.stdin.readline
from math import *
def mrd(): return [int(x) for x in input().split()]
def rd(): return int(input())
MAXN = 2 * 10**5 + 5
INF = 10**16 * 2
mod = 10**9 + 7
#----------------------------------------------------------------------------------#
def solve():
s = input()
if s[-1] == '\n': s = s[:-1]
cnt = Counter(s)
n = len(s)
b = []
odd = 0
for ch, x in cnt.items():
if x & 1:
odd += 1
b.append(ch)
if n % 2 == 0:
b.sort(reverse = True)
for i in range(len(b) - 1):
cnt[b[i]] -= 1
cnt[b[-1]] += 1
# if odd & 1: sum(odd)+sum(even) != n
ans = ""
for x, y in cnt.items():
ans += x * (y // 2)
print(ans + ans[::-1])
else:
# one odd and some even
b.sort(reverse = True)
odd -= 1
for i in range(len(b) - 1):
if odd == 1: break
cnt[b[i]] -= 1
cnt[b[-1]] += 1
odd -= 1
ans = ""
ch = ''
for x, y in cnt.items():
ans += x * (y // 2)
if y & 1: ch = x
print(ans + ch + ans[::-1])
if __name__ == "__main__":
solve()
| 66 | 77 | 2,355,200 |
166596253
|
from collections import defaultdict
def main():
s = input()
l = defaultdict(int)
for c in s:
l[c] += 1
u = sorted(list(filter(lambda x: l[x] % 2, l.keys())))
for i in range(0, int(len(u) / 2)):
l[u[i]] += 1
l[u[-i-1]] -= 1
r = ""
for c in sorted(l.keys()):
r += c * int(l[c] / 2)
c = u[int(len(u) / 2)] if len(u) % 2 else ""
print(r + c + r[::-1])
main()
|
Educational Codeforces Round 2
|
ICPC
| 2,015 | 2 | 256 |
Make Palindrome
|
A string is called palindrome if it reads the same from left to right and from right to left. For example "kazak", "oo", "r" and "mikhailrubinchikkihcniburliahkim" are palindroms, but strings "abb" and "ij" are not.
You are given string s consisting of lowercase Latin letters. At once you can choose any position in the string and change letter in that position to any other lowercase letter. So after each changing the length of the string doesn't change. At first you can change some letters in s. Then you can permute the order of letters as you want. Permutation doesn't count as changes.
You should obtain palindrome with the minimal number of changes. If there are several ways to do that you should get the lexicographically (alphabetically) smallest palindrome. So firstly you should minimize the number of changes and then minimize the palindrome lexicographically.
|
The only line contains string s (1 ≤ |s| ≤ 2·105) consisting of only lowercase Latin letters.
|
Print the lexicographically smallest palindrome that can be obtained with the minimal number of changes.
| null | null |
[{"input": "aabc", "output": "abba"}, {"input": "aabcd", "output": "abcba"}]
| 1,800 |
["constructive algorithms", "greedy", "strings"]
| 66 |
[{"input": "aabc\r\n", "output": "abba\r\n"}, {"input": "aabcd\r\n", "output": "abcba\r\n"}, {"input": "u\r\n", "output": "u\r\n"}, {"input": "ttttt\r\n", "output": "ttttt\r\n"}, {"input": "xxxvvvxxvv\r\n", "output": "vvvxxxxvvv\r\n"}, {"input": "wrwrwfrrfrffrrwwwffffwrfrrwfrrfrwwfwfrwfwfwffwrrwfrrrwwwfrrrwfrrfwrwwrwrrrffffwrrrwrwfffwrffrwwwrwww\r\n", "output": "fffffffffffffffrrrrrrrrrrrrrrrrrrwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwrrrrrrrrrrrrrrrrrrfffffffffffffff\r\n"}, {"input": "aabbcccdd\r\n", "output": "abcdcdcba\r\n"}, {"input": "baaab\r\n", "output": "ababa\r\n"}, {"input": "aaabbbhhlhlugkjgckj\r\n", "output": "aabbghjklclkjhgbbaa\r\n"}, {"input": "aabcc\r\n", "output": "acbca\r\n"}, {"input": "bbbcccddd\r\n", "output": "bbcdcdcbb\r\n"}, {"input": "zzzozzozozozoza\r\n", "output": "aoozzzzozzzzooa\r\n"}, {"input": "aaabb\r\n", "output": "ababa\r\n"}, {"input": "zza\r\n", "output": "zaz\r\n"}, {"input": "azzzbbb\r\n", "output": "abzbzba\r\n"}, {"input": "bbaaccddc\r\n", "output": "abcdcdcba\r\n"}, {"input": "aaabbbccc\r\n", "output": "aabcbcbaa\r\n"}, {"input": "aaaaabbccdd\r\n", "output": "aabcdadcbaa\r\n"}, {"input": "aaabbbcccdd\r\n", "output": "aabcdbdcbaa\r\n"}, {"input": "aaaabbcccccdd\r\n", "output": "aabccdcdccbaa\r\n"}, {"input": "aaacccb\r\n", "output": "aacbcaa\r\n"}, {"input": "abcd\r\n", "output": "abba\r\n"}, {"input": "abb\r\n", "output": "bab\r\n"}, {"input": "abababccc\r\n", "output": "aabcbcbaa\r\n"}, {"input": "aaadd\r\n", "output": "adada\r\n"}, {"input": "qqqqaaaccdd\r\n", "output": "acdqqaqqdca\r\n"}, {"input": "affawwzzw\r\n", "output": "afwzwzwfa\r\n"}, {"input": "hack\r\n", "output": "acca\r\n"}, {"input": "bbaaa\r\n", "output": "ababa\r\n"}, {"input": "ababa\r\n", "output": "ababa\r\n"}, {"input": "aaazzzz\r\n", "output": "azzazza\r\n"}, {"input": "aabbbcc\r\n", "output": "abcbcba\r\n"}, {"input": "successfullhack\r\n", "output": "accelsufuslecca\r\n"}, {"input": "aaabbccdd\r\n", "output": "abcdadcba\r\n"}, {"input": "zaz\r\n", "output": "zaz\r\n"}, {"input": "aaabbbcccdddeee\r\n", "output": "aabbcdecedcbbaa\r\n"}, {"input": "zaaz\r\n", "output": "azza\r\n"}, {"input": "acc\r\n", "output": "cac\r\n"}, {"input": "abbbzzz\r\n", "output": "abzbzba\r\n"}, {"input": "zzzzazazazazazznnznznnznnznznzaajzjajjjjanaznnzanzppnzpaznnpanz\r\n", "output": "aaaaaaajjjnnnnnnnnppzzzzzzzzzzznzzzzzzzzzzzppnnnnnnnnjjjaaaaaaa\r\n"}, {"input": "aaaaabbbcccdddd\r\n", "output": "aaabcddbddcbaaa\r\n"}, {"input": "aaaaabbccdddd\r\n", "output": "aabcddaddcbaa\r\n"}, {"input": "abababa\r\n", "output": "aabbbaa\r\n"}, {"input": "azz\r\n", "output": "zaz\r\n"}, {"input": "abbbccc\r\n", "output": "abcbcba\r\n"}, {"input": "aaacccddd\r\n", "output": "aacdcdcaa\r\n"}, {"input": "asbbsha\r\n", "output": "abshsba\r\n"}, {"input": "bababab\r\n", "output": "abbabba\r\n"}, {"input": "aaabbccddbbccddaaaaaaaaaaaaaaaa\r\n", "output": "aaaaaaaaabbccddaddccbbaaaaaaaaa\r\n"}, {"input": "aaabbccddbbccddaaaaaaaaaaaaaa\r\n", "output": "aaaaaaaabbccddaddccbbaaaaaaaa\r\n"}, {"input": "aaabbccddbbccddaaaaaaaaaaaa\r\n", "output": "aaaaaaabbccddaddccbbaaaaaaa\r\n"}, {"input": "ooooo\r\n", "output": "ooooo\r\n"}, {"input": "aaabbccddbbccddaaaaaaaaaa\r\n", "output": "aaaaaabbccddaddccbbaaaaaa\r\n"}, {"input": "aaabbccddbbccddaaaaaaaa\r\n", "output": "aaaaabbccddaddccbbaaaaa\r\n"}, {"input": "aaabbccddbbccddaa\r\n", "output": "aabbccddaddccbbaa\r\n"}]
| false |
stdio
| null | true |
247/A
|
250
|
A
|
PyPy 3
|
TESTS
| 25 | 278 | 20,172,800 |
86347018
|
n=int(input())
a=list(map(int,input().split()))
po=0
ne=0
no=0
l=[]
for i in range(n):
if(a[i]<0):
ne=ne+1
if(a[i]>=0):
po=po+1
if(ne==2):
l.append(po+ne)
po=0
ne=0
if(len(l)>0):
if(po>0):
l[-1]=l[-1]+po
if(ne>0):
l.append(ne)
else:
l.append(po+ne)
print(len(l))
print(*l)
| 69 | 92 | 0 |
138867699
|
n = int(input())
massiv = list(map(int, input().split()))
result = [0]
count = 0
for num in massiv:
if num < 0:
if count == 2:
count = 0
result.append(0)
count += 1
result[-1] += 1
print(len(result))
print(*result)
|
CROC-MBTU 2012, Final Round
|
CF
| 2,012 | 2 | 256 |
Paper Work
|
Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as n days. Right now his task is to make a series of reports about the company's performance for the last n days. We know that the main information in a day report is value ai, the company's profit on the i-th day. If ai is negative, then the company suffered losses on the i-th day.
Polycarpus should sort the daily reports into folders. Each folder should include data on the company's performance for several consecutive days. Of course, the information on each of the n days should be exactly in one folder. Thus, Polycarpus puts information on the first few days in the first folder. The information on the several following days goes to the second folder, and so on.
It is known that the boss reads one daily report folder per day. If one folder has three or more reports for the days in which the company suffered losses (ai < 0), he loses his temper and his wrath is terrible.
Therefore, Polycarpus wants to prepare the folders so that none of them contains information on three or more days with the loss, and the number of folders is minimal.
Write a program that, given sequence ai, will print the minimum number of folders.
|
The first line contains integer n (1 ≤ n ≤ 100), n is the number of days. The second line contains a sequence of integers a1, a2, ..., an (|ai| ≤ 100), where ai means the company profit on the i-th day. It is possible that the company has no days with the negative ai.
|
Print an integer k — the required minimum number of folders. In the second line print a sequence of integers b1, b2, ..., bk, where bj is the number of day reports in the j-th folder.
If there are multiple ways to sort the reports into k days, print any of them.
| null |
Here goes a way to sort the reports from the first sample into three folders:
1 2 3 -4 -5 | -6 5 -5 | -6 -7 6
In the second sample you can put all five reports in one folder.
|
[{"input": "11\n1 2 3 -4 -5 -6 5 -5 -6 -7 6", "output": "3\n5 3 3"}, {"input": "5\n0 -1 100 -1 0", "output": "1\n5"}]
| 1,000 |
[]
| 69 |
[{"input": "11\r\n1 2 3 -4 -5 -6 5 -5 -6 -7 6\r\n", "output": "3\r\n5 3 3 "}, {"input": "5\r\n0 -1 100 -1 0\r\n", "output": "1\r\n5 "}, {"input": "1\r\n0\r\n", "output": "1\r\n1 "}, {"input": "1\r\n-1\r\n", "output": "1\r\n1 "}, {"input": "2\r\n0 0\r\n", "output": "1\r\n2 "}, {"input": "2\r\n-2 2\r\n", "output": "1\r\n2 "}, {"input": "2\r\n-2 -1\r\n", "output": "1\r\n2 "}, {"input": "12\r\n1 -12 -5 -8 0 -8 -1 -1 -6 12 -9 12\r\n", "output": "4\r\n3 3 2 4 "}, {"input": "4\r\n1 2 0 3\r\n", "output": "1\r\n4 "}, {"input": "4\r\n4 -3 3 3\r\n", "output": "1\r\n4 "}, {"input": "4\r\n0 -3 4 -3\r\n", "output": "1\r\n4 "}, {"input": "4\r\n-3 -2 4 -3\r\n", "output": "2\r\n1 3 "}, {"input": "4\r\n-3 -2 -1 -4\r\n", "output": "2\r\n2 2 "}, {"input": "5\r\n-2 -2 4 0 -1\r\n", "output": "2\r\n1 4 "}, {"input": "5\r\n-5 -3 -1 2 -1\r\n", "output": "2\r\n2 3 "}, {"input": "5\r\n-3 -2 -3 -2 -3\r\n", "output": "3\r\n1 2 2 "}, {"input": "10\r\n0 5 2 3 10 9 4 9 9 3\r\n", "output": "1\r\n10 "}, {"input": "10\r\n10 2 1 2 9 10 7 4 -4 5\r\n", "output": "1\r\n10 "}, {"input": "10\r\n1 -3 1 10 -7 -6 7 0 -5 3\r\n", "output": "2\r\n5 5 "}, {"input": "10\r\n6 5 -10 -4 -3 -7 5 -2 -6 -10\r\n", "output": "4\r\n3 2 3 2 "}, {"input": "10\r\n-2 -4 -1 -6 -5 -5 -7 0 -7 -8\r\n", "output": "5\r\n1 2 2 2 3 "}, {"input": "4\r\n1 2 3 4\r\n", "output": "1\r\n4 "}, {"input": "4\r\n1 2 3 -4\r\n", "output": "1\r\n4 "}, {"input": "4\r\n-4 2 1 2\r\n", "output": "1\r\n4 "}, {"input": "1\r\n-1\r\n", "output": "1\r\n1 "}, {"input": "2\r\n2 -1\r\n", "output": "1\r\n2 "}, {"input": "2\r\n-100 100\r\n", "output": "1\r\n2 "}, {"input": "3\r\n-100 0 -100\r\n", "output": "1\r\n3 "}, {"input": "5\r\n1 2 3 -1 -1\r\n", "output": "1\r\n5 "}, {"input": "5\r\n-1 -1 2 3 4\r\n", "output": "1\r\n5 "}, {"input": "3\r\n-3 -4 -5\r\n", "output": "2\r\n1 2 "}, {"input": "4\r\n-3 -4 1 -3\r\n", "output": "2\r\n1 3 "}, {"input": "1\r\n-1\r\n", "output": "1\r\n1 "}, {"input": "2\r\n-1 0\r\n", "output": "1\r\n2 "}, {"input": "4\r\n0 0 0 0\r\n", "output": "1\r\n4 "}, {"input": "3\r\n-1 -1 -1\r\n", "output": "2\r\n1 2 "}, {"input": "6\r\n-1 -1 0 -1 -1 -1\r\n", "output": "3\r\n1 3 2 "}, {"input": "2\r\n0 0\r\n", "output": "1\r\n2 "}, {"input": "6\r\n0 0 -1 -1 -1 0\r\n", "output": "2\r\n3 3 "}]
| false |
stdio
|
import sys
def read_input(input_path):
with open(input_path) as f:
n = int(f.readline())
a = list(map(int, f.readline().split()))
return n, a
def compute_min_k(n, a):
if n == 0:
return 0
folders = 0
current_neg = 0
current_size = 0
for ai in a:
current_size += 1
if ai < 0:
current_neg += 1
if current_neg >= 3:
folders += 1
current_size = 1
current_neg = 1 if ai < 0 else 0
folders += 1
return folders
def check_submission(n, a, k_sub, b):
if sum(b) != n or len(b) != k_sub:
return False
current = 0
for size in b:
if current + size > n:
return False
group = a[current: current + size]
current += size
if sum(1 for x in group if x < 0) >= 3:
return False
return current == n
def main(input_path, _, submission_path):
n, a = read_input(input_path)
min_k = compute_min_k(n, a)
try:
with open(submission_path) as f:
lines = [line.strip() for line in f.readlines()]
if len(lines) < 2:
print(0)
return
k_sub = int(lines[0])
b = list(map(int, lines[1].split()))
except:
print(0)
return
if k_sub != min_k or not check_submission(n, a, k_sub, b):
print(0)
else:
print(1)
if __name__ == "__main__":
input_path, output_path, submission_path = sys.argv[1:4]
main(input_path, output_path, submission_path)
| true |
192/B
|
192
|
B
|
Python 3
|
TESTS
| 14 | 124 | 0 |
139855045
|
n=int(input())
a=list(map(int,list(input().split())))
l=sorted(a)
if l[0]==a[0] or l[0]==a[-1]:
print(l[0])
else:
v=[]
for i in range(n):
v.append([a[i],i])
arr=[0]*(n+2)
v=sorted(v)
for i in range(len(v)):
arr[v[i][1]]="#"
if v[i][1]-1>=0:
if arr[v[i][1]]=="#" and arr[v[i][1]-1]=="#":
print(v[i][0])
break
if v[i][1]+1<=n-1:
if arr[v[i][1]]=="#" and arr[v[i][1]+1]=="#":
print(v[i][0])
break
| 85 | 92 | 0 |
156561148
|
n=int(input())
L=list(map(int,input().split()))
i=0
sol=[L[0]]
while i+2<len(L)-1:
if L[i+1]>L[i+2]:
sol.append(L[i+1])
i+=1
else:
sol.append(L[i+2])
i+=2
sol.append(L[len(L)-1])
print(min(sol))
|
Codeforces Round 121 (Div. 2)
|
CF
| 2,012 | 2 | 256 |
Walking in the Rain
|
In Berland the opposition is going to arrange mass walking on the boulevard. The boulevard consists of n tiles that are lain in a row and are numbered from 1 to n from right to left. The opposition should start walking on the tile number 1 and the finish on the tile number n. During the walk it is allowed to move from right to left between adjacent tiles in a row, and jump over a tile. More formally, if you are standing on the tile number i (i < n - 1), you can reach the tiles number i + 1 or the tile number i + 2 from it (if you stand on the tile number n - 1, you can only reach tile number n). We can assume that all the opposition movements occur instantaneously.
In order to thwart an opposition rally, the Berland bloody regime organized the rain. The tiles on the boulevard are of poor quality and they are rapidly destroyed in the rain. We know that the i-th tile is destroyed after ai days of rain (on day ai tile isn't destroyed yet, and on day ai + 1 it is already destroyed). Of course, no one is allowed to walk on the destroyed tiles! So the walk of the opposition is considered thwarted, if either the tile number 1 is broken, or the tile number n is broken, or it is impossible to reach the tile number n from the tile number 1 if we can walk on undestroyed tiles.
The opposition wants to gather more supporters for their walk. Therefore, the more time they have to pack, the better. Help the opposition to calculate how much time they still have and tell us for how many days the walk from the tile number 1 to the tile number n will be possible.
|
The first line contains integer n (1 ≤ n ≤ 103) — the boulevard's length in tiles.
The second line contains n space-separated integers ai — the number of days after which the i-th tile gets destroyed (1 ≤ ai ≤ 103).
|
Print a single number — the sought number of days.
| null |
In the first sample the second tile gets destroyed after day three, and the only path left is 1 → 3 → 4. After day five there is a two-tile gap between the first and the last tile, you can't jump over it.
In the second sample path 1 → 3 → 5 is available up to day five, inclusive. On day six the last tile is destroyed and the walk is thwarted.
|
[{"input": "4\n10 3 5 10", "output": "5"}, {"input": "5\n10 2 8 3 5", "output": "5"}]
| 1,100 |
["brute force", "implementation"]
| 85 |
[{"input": "4\r\n10 3 5 10\r\n", "output": "5\r\n"}, {"input": "5\r\n10 2 8 3 5\r\n", "output": "5\r\n"}, {"input": "10\r\n10 3 1 6 7 1 3 3 8 1\r\n", "output": "1\r\n"}, {"input": "10\r\n26 72 10 52 2 5 61 2 39 64\r\n", "output": "5\r\n"}, {"input": "100\r\n8 2 1 2 8 3 5 8 5 1 9 3 4 1 5 6 4 2 9 10 6 10 10 3 9 4 10 5 3 1 5 10 7 6 8 10 2 6 4 4 2 2 10 7 2 7 3 2 6 3 6 4 7 6 2 5 5 8 6 9 5 2 7 5 8 6 5 8 10 6 10 8 5 3 1 10 6 1 7 5 1 8 10 5 1 3 10 7 10 5 7 1 4 3 8 6 3 4 9 6\r\n", "output": "2\r\n"}, {"input": "100\r\n10 2 8 7 5 1 5 4 9 2 7 9 3 5 6 2 3 6 10 1 2 7 1 4 8 8 6 1 7 8 8 1 5 8 1 2 7 4 10 7 3 1 2 5 8 1 1 4 9 7 7 4 7 3 8 8 7 1 5 1 6 9 8 8 1 10 4 4 7 7 10 9 5 1 1 3 6 2 6 3 6 4 9 8 2 9 6 2 7 8 10 9 9 6 3 5 3 1 4 8\r\n", "output": "1\r\n"}, {"input": "5\r\n3 2 3 4 2\r\n", "output": "2\r\n"}, {"input": "5\r\n4 8 9 10 6\r\n", "output": "4\r\n"}, {"input": "5\r\n2 21 6 5 9\r\n", "output": "2\r\n"}, {"input": "5\r\n34 39 30 37 35\r\n", "output": "34\r\n"}, {"input": "5\r\n14 67 15 28 21\r\n", "output": "14\r\n"}, {"input": "5\r\n243 238 138 146 140\r\n", "output": "140\r\n"}, {"input": "5\r\n46 123 210 119 195\r\n", "output": "46\r\n"}, {"input": "5\r\n725 444 477 661 761\r\n", "output": "477\r\n"}, {"input": "10\r\n2 2 3 4 4 1 5 3 1 2\r\n", "output": "2\r\n"}, {"input": "10\r\n1 10 1 10 1 1 7 8 6 7\r\n", "output": "1\r\n"}, {"input": "10\r\n5 17 8 1 10 20 9 18 12 20\r\n", "output": "5\r\n"}, {"input": "10\r\n18 11 23 7 9 10 28 29 46 21\r\n", "output": "9\r\n"}, {"input": "10\r\n2 17 53 94 95 57 36 47 68 48\r\n", "output": "2\r\n"}, {"input": "10\r\n93 231 176 168 177 222 22 137 110 4\r\n", "output": "4\r\n"}, {"input": "10\r\n499 173 45 141 425 276 96 290 428 95\r\n", "output": "95\r\n"}, {"input": "10\r\n201 186 897 279 703 376 238 93 253 316\r\n", "output": "201\r\n"}, {"input": "25\r\n3 2 3 2 2 2 3 4 5 1 1 4 1 2 1 3 5 5 3 5 1 2 4 1 3\r\n", "output": "1\r\n"}, {"input": "25\r\n9 9 1 9 10 5 6 4 6 1 5 2 2 1 2 8 4 6 5 7 1 10 5 4 9\r\n", "output": "2\r\n"}, {"input": "25\r\n2 17 21 4 13 6 14 18 17 1 16 13 24 4 12 7 8 16 9 25 25 9 11 20 18\r\n", "output": "2\r\n"}, {"input": "25\r\n38 30 9 35 33 48 8 4 49 2 39 19 34 35 47 49 33 4 23 5 42 35 49 11 30\r\n", "output": "8\r\n"}, {"input": "25\r\n75 34 77 68 60 38 76 89 35 68 28 36 96 63 43 12 9 4 37 75 88 30 11 58 35\r\n", "output": "9\r\n"}, {"input": "25\r\n108 3 144 140 239 105 59 126 224 181 147 102 94 201 68 121 167 94 60 130 64 162 45 95 235\r\n", "output": "94\r\n"}, {"input": "25\r\n220 93 216 467 134 408 132 220 292 11 363 404 282 253 141 313 310 356 214 256 380 81 42 128 363\r\n", "output": "81\r\n"}, {"input": "25\r\n371 884 75 465 891 510 471 52 382 829 514 610 660 642 179 108 41 818 346 106 738 993 706 574 623\r\n", "output": "108\r\n"}, {"input": "50\r\n1 2 1 3 2 5 2 2 2 3 4 4 4 3 3 4 1 2 3 1 5 4 1 2 2 1 5 3 2 2 1 5 4 5 2 5 4 1 1 3 5 2 1 4 5 5 1 5 5 5\r\n", "output": "1\r\n"}, {"input": "50\r\n2 4 9 8 1 3 7 1 2 3 8 9 8 8 5 2 10 5 8 1 3 1 8 2 3 7 9 10 2 9 9 7 3 8 6 10 6 5 4 8 1 1 5 6 8 9 5 9 5 3\r\n", "output": "1\r\n"}, {"input": "50\r\n22 9 5 3 24 21 25 13 17 21 14 8 22 18 2 3 22 9 10 11 25 22 5 10 16 7 15 3 2 13 2 12 9 24 3 14 2 18 3 22 8 2 19 6 16 4 5 20 10 12\r\n", "output": "3\r\n"}, {"input": "50\r\n14 4 20 37 50 46 19 20 25 47 10 6 34 12 41 47 9 22 28 41 34 47 40 12 42 9 4 15 15 27 8 38 9 4 17 8 13 47 7 9 38 30 48 50 7 41 34 23 11 16\r\n", "output": "9\r\n"}, {"input": "50\r\n69 9 97 15 22 69 27 7 23 84 73 74 60 94 43 98 13 4 63 49 7 31 93 23 6 75 32 63 49 32 99 43 68 48 16 54 20 38 40 65 34 28 21 55 79 50 2 18 22 95\r\n", "output": "13\r\n"}, {"input": "50\r\n50 122 117 195 42 178 153 194 7 89 142 40 158 230 213 104 179 56 244 196 85 159 167 19 157 20 230 201 152 98 250 242 10 52 96 242 139 181 90 107 178 52 196 79 23 61 212 47 97 97\r\n", "output": "50\r\n"}, {"input": "50\r\n354 268 292 215 187 232 35 38 179 79 108 491 346 384 345 103 14 260 148 322 459 238 220 493 374 237 474 148 21 221 88 377 289 121 201 198 490 117 382 454 359 390 346 456 294 325 130 306 484 83\r\n", "output": "38\r\n"}, {"input": "50\r\n94 634 27 328 629 967 728 177 379 908 801 715 787 192 427 48 559 923 841 6 759 335 251 172 193 593 456 780 647 638 750 881 206 129 278 744 91 49 523 248 286 549 593 451 216 753 471 325 870 16\r\n", "output": "16\r\n"}, {"input": "100\r\n5 5 4 3 5 1 2 5 1 1 3 5 4 4 1 1 1 1 5 4 4 5 1 5 5 1 2 1 3 1 5 1 3 3 3 2 2 2 1 1 5 1 3 4 1 1 3 2 5 2 2 5 5 4 4 1 3 4 3 3 4 5 3 3 3 1 2 1 4 2 4 4 1 5 1 3 5 5 5 5 3 4 4 3 1 2 5 2 3 5 4 2 4 5 3 2 4 2 4 3\r\n", "output": "1\r\n"}, {"input": "100\r\n3 4 8 10 8 6 4 3 7 7 6 2 3 1 3 10 1 7 9 3 5 5 2 6 2 9 1 7 4 2 4 1 6 1 7 10 2 5 3 7 6 4 6 2 8 8 8 6 6 10 3 7 4 3 4 1 7 9 3 6 3 6 1 4 9 3 8 1 10 1 4 10 7 7 9 5 3 8 10 2 1 10 8 7 10 8 5 3 1 2 1 10 6 1 5 3 3 5 7 2\r\n", "output": "2\r\n"}, {"input": "1\r\n987\r\n", "output": "987\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "2\r\n1 2\r\n", "output": "1\r\n"}, {"input": "5\r\n2 5 5 5 5\r\n", "output": "2\r\n"}, {"input": "1\r\n500\r\n", "output": "500\r\n"}]
| false |
stdio
| null | true |
584/C
|
584
|
C
|
PyPy 3-64
|
TESTS
| 7 | 62 | 0 |
217503595
|
import sys
input = lambda: sys.stdin.readline().rstrip()
import math
from heapq import heappush , heappop
from collections import defaultdict,deque,Counter
ALPHA = 'abcdefghijklmnopqrstuvwxyz'
N,T = map(int, input().split())
s = input()
t = input()
def deal(diffs):
for a in ALPHA:
if a in diffs:continue
return a
return '*'
sames = 0
for i in range(N):
if s[i]==t[i]:
sames+=1
m = N-T
if m>sames and (m-sames)*2>N:
exit(print(-1))
ans = ['*']*N
pre = -1
A = []
for i in range(N):
if s[i]==t[i]:
if m>0:
ans[i] = s[i]
m-=1
else:
A.append(i)
for i in range(1,len(A)):
if m>0:
ans[A[i-1]] = s[A[i-1]]
ans[A[i]] = t[A[i]]
m-=1
if m==0:
for i in range(N):
if ans[i]=='*':
ans[i] = deal(s[i]+t[i])
print(''.join(ans))
else:
print(-1)
| 78 | 124 | 11,776,000 |
194575939
|
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from functools import lru_cache
from math import factorial, comb, sqrt, gcd, lcm
from copy import deepcopy
import heapq
from sys import stdin, stdout
# 加快读入速度, 但是注意后面的换行符(\n)
# 如果是使用 input().split() 或者 int(input()) 之类的, 换行符就去掉了
input = stdin.readline
def get_different(c1, c2=None):
if c2 is None:
if c1 != "z":
return chr(ord(c1) + 1)
else:
return "a"
else:
if c2 < c1:
c1, c2 = c2, c1
if ord(c2) - ord(c1) > 1:
return chr(ord(c1) + 1)
else:
if c2 == "z":
return "a"
else:
return chr(ord(c2) + 1)
def main():
n, t = map(int, input().split())
s1 = input()[:-1]
s2 = input()[:-1]
ans = [""] * n
same_index = []
different_index = []
for i in range(n):
if s1[i] == s2[i]:
same_index.append(i)
else:
different_index.append(i)
if len(different_index) > 2 * t:
print(-1)
elif len(different_index) <= t:
extra = t - len(different_index)
for i in range(len(different_index)):
index = different_index[i]
ans[index] = get_different(s1[index], s2[index])
for i in range(len(same_index)):
index = same_index[i]
if i < extra:
ans[index] = get_different(s1[index])
else:
ans[index] = s1[index]
print("".join(ans))
else:
all_different = 2 * t - len(different_index)
one_same = len(different_index) - t
for i in range(len(same_index)):
index = same_index[i]
ans[index] = s1[index]
for i in range(len(different_index)):
index = different_index[i]
if i < all_different:
ans[index] = get_different(s1[index], s2[index])
elif i < all_different + one_same:
ans[index] = s1[index]
else:
ans[index] = s2[index]
print("".join(ans))
if __name__ == "__main__":
main()
|
Codeforces Round 324 (Div. 2)
|
CF
| 2,015 | 1 | 256 |
Marina and Vasya
|
Marina loves strings of the same length and Vasya loves when there is a third string, different from them in exactly t characters. Help Vasya find at least one such string.
More formally, you are given two strings s1, s2 of length n and number t. Let's denote as f(a, b) the number of characters in which strings a and b are different. Then your task will be to find any string s3 of length n, such that f(s1, s3) = f(s2, s3) = t. If there is no such string, print - 1.
|
The first line contains two integers n and t (1 ≤ n ≤ 105, 0 ≤ t ≤ n).
The second line contains string s1 of length n, consisting of lowercase English letters.
The third line contain string s2 of length n, consisting of lowercase English letters.
|
Print a string of length n, differing from string s1 and from s2 in exactly t characters. Your string should consist only from lowercase English letters. If such string doesn't exist, print -1.
| null | null |
[{"input": "3 2\nabc\nxyc", "output": "ayd"}, {"input": "1 0\nc\nb", "output": "-1"}]
| 1,700 |
["constructive algorithms", "greedy", "strings"]
| 78 |
[{"input": "3 2\r\nabc\r\nxyc\r\n", "output": "bac"}, {"input": "1 0\r\nc\r\nb\r\n", "output": "-1\r\n"}, {"input": "1 1\r\na\r\na\r\n", "output": "b"}, {"input": "2 1\r\naa\r\naa\r\n", "output": "ab"}, {"input": "3 1\r\nbcb\r\nbca\r\n", "output": "bcc"}, {"input": "4 3\r\nccbb\r\ncaab\r\n", "output": "cbca"}, {"input": "4 2\r\nacbc\r\nacba\r\n", "output": "acab"}, {"input": "4 1\r\nbcbc\r\nacab\r\n", "output": "-1\r\n"}, {"input": "4 2\r\nacbb\r\nbabc\r\n", "output": "aaba"}, {"input": "5 2\r\nabaac\r\nbbbaa\r\n", "output": "abbab"}, {"input": "5 2\r\nabbab\r\nacbab\r\n", "output": "aabaa"}, {"input": "5 3\r\nbcaaa\r\ncbacc\r\n", "output": "bbabb"}, {"input": "5 3\r\ncbacb\r\ncbacb\r\n", "output": "cbbaa"}, {"input": "5 1\r\ncbabb\r\nbabaa\r\n", "output": "-1\r\n"}, {"input": "1 0\r\na\r\na\r\n", "output": "a"}, {"input": "2 2\r\nbb\r\ncb\r\n", "output": "aa"}, {"input": "2 1\r\ncc\r\nba\r\n", "output": "ca"}, {"input": "2 0\r\nbb\r\nab\r\n", "output": "-1\r\n"}, {"input": "3 3\r\naac\r\nabc\r\n", "output": "bca"}, {"input": "1 1\r\na\r\nc\r\n", "output": "b"}, {"input": "3 0\r\ncba\r\ncca\r\n", "output": "-1\r\n"}, {"input": "2 1\r\niy\r\niy\r\n", "output": "ia"}, {"input": "2 2\r\nfg\r\nfn\r\n", "output": "aa"}, {"input": "2 1\r\npd\r\nke\r\n", "output": "pe"}, {"input": "3 3\r\nyva\r\nyvq\r\n", "output": "aab"}, {"input": "3 2\r\npxn\r\ngxn\r\n", "output": "axa"}, {"input": "3 1\r\nlos\r\nlns\r\n", "output": "las"}, {"input": "4 2\r\nhbnx\r\nhwmm\r\n", "output": "hbma"}, {"input": "4 4\r\nqtto\r\nqtto\r\n", "output": "aaaa"}, {"input": "4 3\r\nchqt\r\nchet\r\n", "output": "caaa"}, {"input": "5 3\r\nwzcre\r\nwzcrp\r\n", "output": "wzaaa"}, {"input": "5 1\r\nicahj\r\nxdvch\r\n", "output": "-1\r\n"}, {"input": "5 1\r\npmesm\r\npzeaq\r\n", "output": "-1\r\n"}, {"input": "7 4\r\nycgdbph\r\nfdtapch\r\n", "output": "yctaaah"}, {"input": "10 6\r\nrnsssbuiaq\r\npfsbsbuoay\r\n", "output": "aasasbuaba"}, {"input": "20 5\r\ndsjceiztjkrqgpqpnakr\r\nyijdvcjtjnougpqprrkr\r\n", "output": "-1\r\n"}, {"input": "100 85\r\njknccpmanwhxqnxivdgguahjcuyhdrazmbfwoptatlgytakxsfvdzzcsglhmswfxafxyregdbeiwpawrjgwcqrkbhmrfcscgoszf\r\nhknccpmanwhxjnxivdggeahjcuyhdrazmbfwoqtatlgytdkxsfvdztcsglhmssfxsfxyrngdbeiwpawrjgwcqrkbhmrfcsckoskf\r\n", "output": "aknccpmanwhxanxivaaaabaaaaaaaabaaaaaaaabaaaaabaaaaaaaaaaaaaaaaaabaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaa"}, {"input": "1 0\r\nz\r\nz\r\n", "output": "z"}, {"input": "1 1\r\nz\r\ny\r\n", "output": "a"}, {"input": "1 1\r\nz\r\nz\r\n", "output": "a"}, {"input": "1 0\r\nz\r\ny\r\n", "output": "-1\r\n"}, {"input": "10 1\r\ngjsywvenzc\r\nfssywvenzc\r\n", "output": "gssywvenzc"}, {"input": "20 2\r\nywpcwcwgkhdeonzbeamf\r\ngdcmwcwgkhdeonzbeamf\r\n", "output": "ywcmwcwgkhdeonzbeamf"}]
| false |
stdio
|
import sys
def hamming(s1, s2):
return sum(c1 != c2 for c1, c2 in zip(s1, s2))
def solution_exists(n, t, s1, s2):
a = sum(c1 == c2 for c1, c2 in zip(s1, s2))
d = n - a
min_k = max(d - t, 0)
max_k = min(d // 2, a + d - t)
return min_k <= max_k
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(input_path) as f:
n, t = map(int, f.readline().split())
s1 = f.readline().strip()
s2 = f.readline().strip()
with open(submission_path) as f:
submission = f.read().strip()
if submission == "-1":
exists = solution_exists(n, t, s1, s2)
print(0 if exists else 1)
return
else:
if len(submission) != n:
print(0)
return
if any(c < 'a' or c > 'z' for c in submission):
print(0)
return
h1 = hamming(s1, submission)
h2 = hamming(s2, submission)
if h1 == t and h2 == t:
print(1)
else:
print(0)
if __name__ == "__main__":
main()
| true |
413/C
|
413
|
C
|
Python 3
|
TESTS
| 5 | 108 | 0 |
48322318
|
n, m = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
auc = []
k = 1
for i in b:
auc.append(a[i-k])
del(a[i-k])
k += 1
auc.sort()
auc = auc[::-1]
s = sum(a)
for i in auc:
if s<i:
s+=i
else:
s+=s
print(s)
| 67 | 62 | 0 |
6423998
|
n, m = list(map(int, input().split()))
prices = list(map(int, input().split()))
auci = list(map(int, input().split()))
scores = 0
# m auc
# n - m default
for i in range(len(prices)):
if (i+1) not in auci:
scores += prices[i]
prices[i] = 0
ra = []
for i in prices:
if i != 0:
ra.append(i)
ra.sort()
ra = ra[::-1]
for i in ra:
if i > scores:
scores += i
else:
scores *= 2
print(scores)
#print(ra)
|
Coder-Strike 2014 - Round 2
|
CF
| 2,014 | 1 | 256 |
Jeopardy!
|
'Jeopardy!' is an intellectual game where players answer questions and earn points. Company Q conducts a simplified 'Jeopardy!' tournament among the best IT companies. By a lucky coincidence, the old rivals made it to the finals: company R1 and company R2.
The finals will have n questions, m of them are auction questions and n - m of them are regular questions. Each question has a price. The price of the i-th question is ai points. During the game the players chose the questions. At that, if the question is an auction, then the player who chose it can change the price if the number of his current points is strictly larger than the price of the question. The new price of the question cannot be less than the original price and cannot be greater than the current number of points of the player who chose the question. The correct answer brings the player the points equal to the price of the question. The wrong answer to the question reduces the number of the player's points by the value of the question price.
The game will go as follows. First, the R2 company selects a question, then the questions are chosen by the one who answered the previous question correctly. If no one answered the question, then the person who chose last chooses again.
All R2 employees support their team. They want to calculate what maximum possible number of points the R2 team can get if luck is on their side during the whole game (they will always be the first to correctly answer questions). Perhaps you are not going to be surprised, but this problem was again entrusted for you to solve.
|
The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 100; m ≤ min(n, 30)) — the total number of questions and the number of auction questions, correspondingly. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 107) — the prices of the questions. The third line contains m distinct integers bi (1 ≤ bi ≤ n) — the numbers of auction questions. Assume that the questions are numbered from 1 to n.
|
In the single line, print the answer to the problem — the maximum points the R2 company can get if it plays optimally well. It is guaranteed that the answer fits into the integer 64-bit signed type.
| null | null |
[{"input": "4 1\n1 3 7 5\n3", "output": "18"}, {"input": "3 2\n10 3 8\n2 3", "output": "40"}, {"input": "2 2\n100 200\n1 2", "output": "400"}]
| 1,400 |
["greedy", "math"]
| 67 |
[{"input": "4 1\r\n1 3 7 5\r\n3\r\n", "output": "18\r\n"}, {"input": "3 2\r\n10 3 8\r\n2 3\r\n", "output": "40\r\n"}, {"input": "2 2\r\n100 200\r\n1 2\r\n", "output": "400\r\n"}, {"input": "1 1\r\n1\r\n1\r\n", "output": "1\r\n"}, {"input": "2 2\r\n1 5\r\n1 2\r\n", "output": "10\r\n"}, {"input": "5 3\r\n5 8 7 1 9\r\n2 5 3\r\n", "output": "60\r\n"}, {"input": "5 5\r\n9 1 6 2 1\r\n3 1 4 5 2\r\n", "output": "144\r\n"}, {"input": "25 5\r\n66 41 91 33 86 67 38 79 49 7 77 54 29 19 22 48 63 37 11 100 8 6 47 27 26\r\n12 14 1 23 18\r\n", "output": "29056\r\n"}, {"input": "50 10\r\n19098 20847 65754 94580 54808 57092 23130 15638 43645 52323 52822 65193 90139 69196 83680 70109 96772 35102 56685 6692 30738 74558 57144 24054 44447 51959 22847 18735 23534 821 5540 39948 7552 72425 23213 2770 98496 81096 84868 167 36408 26572 19351 82775 23225 35377 63193 58352 45111 60889\r\n8 20 32 17 11 44 39 30 36 16\r\n", "output": "1880325120\r\n"}, {"input": "2 1\r\n19 4\r\n1\r\n", "output": "23\r\n"}, {"input": "3 1\r\n65 81 6\r\n2\r\n", "output": "152\r\n"}, {"input": "5 1\r\n72 32 17 46 82\r\n2\r\n", "output": "434\r\n"}, {"input": "100 1\r\n9 9 72 55 14 8 55 58 35 67 3 18 73 92 41 49 15 60 18 66 9 26 97 47 43 88 71 97 19 34 48 96 79 53 8 24 69 49 12 23 77 12 21 88 66 9 29 13 61 69 54 77 41 13 4 68 37 74 7 6 29 76 55 72 89 4 78 27 29 82 18 83 12 4 32 69 89 85 66 13 92 54 38 5 26 56 17 55 29 4 17 39 29 94 3 67 85 98 21 14\r\n13\r\n", "output": "8834\r\n"}, {"input": "25 24\r\n1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 131072 262144 524288 1048576 2097152 4194304 8388608 1\r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24\r\n", "output": "70368752566272\r\n"}, {"input": "30 30\r\n6074511 9621540 9853685 9073323 6897794 9366449 1648254 3848902 8729661 9330982 9970280 1886362 5605123 3406494 501290 3140164 2406173 346072 1520895 441795 5271130 7576116 337766 6666108 953354 5085881 2876195 8036150 1251715 4952594\r\n30 5 10 28 21 18 6 13 29 23 17 24 14 25 3 27 20 26 12 2 4 11 16 15 22 7 8 19 1 9\r\n", "output": "5352753316495360\r\n"}, {"input": "50 30\r\n6015200 8643865 4116771 6555197 304415 8580071 8414182 3089212 5684567 7595481 1272699 7127763 3309618 1410297 4349070 2027355 136702 6863504 1800751 5585842 5924142 5188269 4805201 9313209 8941399 5137060 4983630 8467668 1646260 7804684 8646497 7067118 6896291 9109696 6197162 1366002 1703718 3852639 8427694 552915 5001315 5238093 9152085 7288325 8115109 3800240 5658858 4392321 8244056 3275379\r\n30 25 34 8 31 50 48 19 49 26 9 24 22 6 44 14 27 43 3 28 35 10 21 17 45 12 40 47 1 33\r\n", "output": "96888048737845248\r\n"}, {"input": "1 1\r\n1846236\r\n1\r\n", "output": "1846236\r\n"}, {"input": "2 1\r\n8912260 7309391\r\n1\r\n", "output": "16221651\r\n"}, {"input": "3 1\r\n9949628 37460 9989934\r\n3\r\n", "output": "19977022\r\n"}, {"input": "5 3\r\n1819638 2087365 162773 9531053 130978\r\n3 1 4\r\n", "output": "46997584\r\n"}, {"input": "10 4\r\n886062 1016649 67899 9999839 98342 64636 816991 263 1050987 1858\r\n1 9 7 4\r\n", "output": "89995888\r\n"}, {"input": "10 10\r\n1 652210 1 1 1 1 1 1 1 1\r\n10 1 6 7 9 8 4 3 5 2\r\n", "output": "333931520\r\n"}, {"input": "50 5\r\n223036 65304 301127 8945 10289 15638 260 246 68 14 23 6 3 2 8 2 1 392212 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 242747 1 1 1 243737 1 1 1 1 1 1 10000000 572890\r\n18 50 38 42 49\r\n", "output": "170000000\r\n"}, {"input": "50 10\r\n1103 17631 1582 250 6933 26 14434 6 2 1 1 1 1 1 3625 1 5909 1 1 1 1 1 1 1 1 1 1 1 1 7196 14842 1 1 1 1 1 1 12053 9999991 1 10502 1 1 1 1 1 1 1 1 1\r\n41 15 17 1 5 31 7 38 30 39\r\n", "output": "5129995264\r\n"}, {"input": "50 15\r\n369 139 49 15 4 5 1 1 1 365 1 1 1 1 484 165 105 1 1 1 382 105 1 1 1 72 1 1 91 96 1 1 1 1 1 133 9997031 1 1 31 1 1 1 291 558 1 1 1 464 1\r\n49 26 40 21 45 30 16 10 15 44 22 29 36 17 37\r\n", "output": "163801350144\r\n"}, {"input": "50 18\r\n20 23 54 4 1 1 15 50 56 1 1 71 1 1 1 1 1 15 8 1 12 1 1 1 1 1 76 1 19 11 55 42 1 1 1 1 1 9 1 30 5 1 1 1 20 1 1 1 1 9975634\r\n9 18 7 45 27 32 12 41 31 8 3 30 21 19 40 38 29 50\r\n", "output": "1307536261120\r\n"}, {"input": "100 1\r\n954110 7577191 694644 113513 467690 71415 25351 26000 37902 29150 2015 94 741 20 71 9 2 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 1 1 1 1 1 1 1 1 1 1 1 10000000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n78\r\n", "output": "20000000\r\n"}, {"input": "100 5\r\n502646 93620 4203 12132 2444 9620 6 201 4 20 10000000 1 6 9 472804 2 2 5 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 1 1 1 1 276285 518136 1 1 1 1 1 1 1 1 1 1 1 1 1 1 189005 1 1 1 1 1 1 1 1 1 1 1 1\r\n73 72 15 88 11\r\n", "output": "170000000\r\n"}, {"input": "100 10\r\n9999984 1396 8798 4760 3138 310 840 41 37 79 45 1 7 2 1 1 1 1 11032 1 1 1 11226 1 1 1 1 1 1 1 12147 1 1 1 1 1 1 16512 1 1 1 1 1 1 1 1 1 1 1 2658 1 1 1 1 7562 1 1 1 1 6207 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3334 1 1 1 1 1 1 1310 1 1 1 1 1 1 1 1 1\r\n19 55 91 50 31 23 60 84 38 1\r\n", "output": "5129991680\r\n"}, {"input": "100 15\r\n380 122 2 18 5 2 3 242 1 1 1 1 1 64 1 1 1 1 1 198 323 284 1 419 1 225 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 584 1 1 1 55 9999036 1 1 1 1 1 1 1 1 447 1 1 471 1 1 1 1 1 1 1 374 1 1 1 1 1 1 1 1 1 1 1 273 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 68 1\r\n22 45 49 24 26 62 70 82 21 20 59 14 99 8 50\r\n", "output": "163834200064\r\n"}, {"input": "100 16\r\n15 18 54 132 138 1 1 45 164 1 1 1 1 1 1 1 1 1 1 1 1 9999567 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 188 1 1 1 213 1 1 27 1 1 1 1 1 1 1 1 1 1 1 200 1 140 221 1 1 1 1 1 1 1 1 132 1 78 1 1 1 1 1 243 1 1 1 1 1 1 1 1 1 1 240 1 1 290 1 34 1 1 1 1 1 1\r\n92 46 8 58 94 39 9 89 61 60 4 70 78 72 43 22\r\n", "output": "327675805696\r\n"}, {"input": "3 1\r\n1 2 4\r\n1\r\n", "output": "12\r\n"}, {"input": "3 1\r\n1 2 4\r\n2\r\n", "output": "10\r\n"}, {"input": "3 1\r\n1 2 4\r\n3\r\n", "output": "7\r\n"}, {"input": "2 1\r\n1 2\r\n1\r\n", "output": "4\r\n"}, {"input": "2 1\r\n1 2\r\n2\r\n", "output": "3\r\n"}, {"input": "3 2\r\n1 2 4\r\n1 2\r\n", "output": "16\r\n"}, {"input": "3 2\r\n1 2 4\r\n3 2\r\n", "output": "10\r\n"}, {"input": "3 2\r\n1 2 4\r\n3 1\r\n", "output": "12\r\n"}, {"input": "3 3\r\n4 2 1\r\n1 3 2\r\n", "output": "16\r\n"}, {"input": "5 4\r\n1 2 2 4 8\r\n1 2 4 5\r\n", "output": "80\r\n"}, {"input": "3 2\r\n10 7 1000\r\n2 3\r\n", "output": "2020\r\n"}, {"input": "4 2\r\n2 2 4 8\r\n3 4\r\n", "output": "24\r\n"}, {"input": "3 2\r\n1 3 5\r\n1 3\r\n", "output": "16\r\n"}, {"input": "3 2\r\n10 1 12\r\n2 3\r\n", "output": "44\r\n"}, {"input": "4 2\r\n1 2 3 100\r\n2 4\r\n", "output": "208\r\n"}, {"input": "3 2\r\n10 5 200\r\n2 3\r\n", "output": "420\r\n"}, {"input": "3 2\r\n3 5 3\r\n2 3\r\n", "output": "16\r\n"}, {"input": "3 2\r\n5 4 100\r\n2 3\r\n", "output": "210\r\n"}, {"input": "5 4\r\n100 200 300 400 500\r\n1 2 3 5\r\n", "output": "7200\r\n"}, {"input": "3 2\r\n100 200 180\r\n1 2\r\n", "output": "760\r\n"}, {"input": "4 3\r\n2 5 17 4\r\n1 2 3\r\n", "output": "84\r\n"}, {"input": "5 2\r\n2 2 4 7 15\r\n4 5\r\n", "output": "46\r\n"}, {"input": "3 2\r\n200 100 1000\r\n2 3\r\n", "output": "2400\r\n"}, {"input": "4 2\r\n2 2 2 7\r\n1 4\r\n", "output": "22\r\n"}, {"input": "8 4\r\n2 2 2 2 1 2 3 9\r\n5 6 7 8\r\n", "output": "136\r\n"}, {"input": "3 2\r\n2 1 5\r\n2 3\r\n", "output": "14\r\n"}]
| false |
stdio
| null | true |
197/B
|
197
|
B
|
Python 3
|
TESTS
| 15 | 216 | 6,963,200 |
86123617
|
n,m=list(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
if n>m:
if a[0]/b[0]>0:
print("Infinity")
else:
print( "-Infinity")
elif n<m:
print('0/1')
else:
p=a[0]
q=b[0]
s=''
if p/q<0:
s='-'
p=abs(p)
q=abs(q)
for i in range(2,min(p,q)+1):
if p%i==0 and q%i==0:
p=p//i
q=q//i
print(s+str(p)+'/'+str(q))
| 80 | 156 | 6,963,200 |
122437646
|
import math
R=lambda:list(map(int,input().split()))
n,m=R()
a=R()[0]
b=R()[0]
if n>m: print(('-'if a*b<0 else'')+'Infinity')
elif n<m: print('0/1')
else:
g=math.gcd(abs(a),abs(b))
a//=g
b//=g
if b<0:a,b=-a,-b
print(str(a)+'/'+str(b))
|
Codeforces Round 124 (Div. 2)
|
CF
| 2,012 | 2 | 256 |
Limit
|
You are given two polynomials:
- P(x) = a0·xn + a1·xn - 1 + ... + an - 1·x + an and
- Q(x) = b0·xm + b1·xm - 1 + ... + bm - 1·x + bm.
Calculate limit $$\lim_{x \to +\infty} \frac{P(x)}{Q(x)}$$.
|
The first line contains two space-separated integers n and m (0 ≤ n, m ≤ 100) — degrees of polynomials P(x) and Q(x) correspondingly.
The second line contains n + 1 space-separated integers — the factors of polynomial P(x): a0, a1, ..., an - 1, an ( - 100 ≤ ai ≤ 100, a0 ≠ 0).
The third line contains m + 1 space-separated integers — the factors of polynomial Q(x): b0, b1, ..., bm - 1, bm ( - 100 ≤ bi ≤ 100, b0 ≠ 0).
|
If the limit equals + ∞, print "Infinity" (without quotes). If the limit equals - ∞, print "-Infinity" (without the quotes).
If the value of the limit equals zero, print "0/1" (without the quotes).
Otherwise, print an irreducible fraction — the value of limit $$\lim_{x \to +\infty} \frac{P(x)}{Q(x)}$$, in the format "p/q" (without the quotes), where p is the — numerator, q (q > 0) is the denominator of the fraction.
| null |
Let's consider all samples:
1. $$\lim_{x \to +\infty} \frac{x^2+x+1}{2x+5} = +\infty$$
2. $$\lim_{x \to +\infty} \frac{-x+3}{2} = -\infty$$
3. $$\lim_{x \to +\infty} \frac{1}{x} = 0$$
4. $$\lim_{x \to +\infty} \frac{2x^2+x+6}{4x^2+5x-7} = \frac{1}{2}$$
5. $$\lim_{x \to +\infty} \frac{9x}{-5x+2} = -\frac{9}{5}$$
You can learn more about the definition and properties of limits if you follow the link: http://en.wikipedia.org/wiki/Limit_of_a_function
|
[{"input": "2 1\n1 1 1\n2 5", "output": "Infinity"}, {"input": "1 0\n-1 3\n2", "output": "-Infinity"}, {"input": "0 1\n1\n1 0", "output": "0/1"}, {"input": "2 2\n2 1 6\n4 5 -7", "output": "1/2"}, {"input": "1 1\n9 0\n-5 2", "output": "-9/5"}]
| 1,400 |
["math"]
| 80 |
[{"input": "2 1\r\n1 1 1\r\n2 5\r\n", "output": "Infinity\r\n"}, {"input": "1 0\r\n-1 3\r\n2\r\n", "output": "-Infinity\r\n"}, {"input": "0 1\r\n1\r\n1 0\r\n", "output": "0/1\r\n"}, {"input": "2 2\r\n2 1 6\r\n4 5 -7\r\n", "output": "1/2\n"}, {"input": "1 1\r\n9 0\r\n-5 2\r\n", "output": "-9/5\n"}, {"input": "1 2\r\n5 3\r\n-3 2 -1\r\n", "output": "0/1\r\n"}, {"input": "1 2\r\n-4 8\r\n-2 5 -3\r\n", "output": "0/1\r\n"}, {"input": "3 2\r\n4 3 1 2\r\n-5 7 0\r\n", "output": "-Infinity\r\n"}, {"input": "2 1\r\n-3 5 1\r\n-8 0\r\n", "output": "Infinity\r\n"}, {"input": "1 1\r\n-5 7\r\n3 1\r\n", "output": "-5/3\n"}, {"input": "2 2\r\n-4 2 1\r\n-5 8 -19\r\n", "output": "4/5\n"}, {"input": "0 0\r\n36\r\n-54\r\n", "output": "-2/3\n"}, {"input": "0 0\r\n36\r\n-8\r\n", "output": "-9/2\n"}, {"input": "0 0\r\n-6\r\n-8\r\n", "output": "3/4\n"}, {"input": "0 2\r\n-3\r\n1 4 6\r\n", "output": "0/1\r\n"}, {"input": "0 0\r\n-21\r\n13\r\n", "output": "-21/13\n"}, {"input": "0 0\r\n-34\r\n21\r\n", "output": "-34/21\n"}, {"input": "0 0\r\n-55\r\n34\r\n", "output": "-55/34\n"}, {"input": "33 1\r\n-75 -83 87 -27 -48 47 -90 -84 -18 -4 14 -1 -83 -98 -68 -85 -86 28 2 45 96 -59 86 -25 -2 -64 -92 65 69 72 72 -58 -99 90\r\n-1 72\r\n", "output": "Infinity\r\n"}, {"input": "20 20\r\n5 4 91 -66 -57 55 -79 -2 -54 -72 -49 21 -23 -5 57 -48 70 -16 -86 -26 -19\r\n51 -60 64 -8 89 27 -96 4 95 -24 -2 -27 -41 -14 -88 -19 24 68 -31 34 -62\r\n", "output": "5/51\n"}, {"input": "0 0\r\n46\r\n-33\r\n", "output": "-46/33\n"}, {"input": "17 17\r\n-54 59 -95 87 3 -27 -30 49 -87 74 45 78 36 60 -95 41 -53 -70\r\n-27 16 -67 -24 10 -73 -41 12 -52 53 -73 -17 -56 -74 -33 -8 100 -39\r\n", "output": "2/1\n"}, {"input": "1 1\r\n36 -49\r\n-32 -40\r\n", "output": "-9/8\n"}, {"input": "1 1\r\n1 1\r\n1 1\r\n", "output": "1/1\n"}, {"input": "1 1\r\n-2 1\r\n4 1\r\n", "output": "-1/2\n"}, {"input": "0 0\r\n2\r\n1\r\n", "output": "2/1\n"}, {"input": "0 0\r\n4\r\n-3\r\n", "output": "-4/3\n"}, {"input": "0 0\r\n2\r\n2\r\n", "output": "1/1\n"}, {"input": "0 0\r\n17\r\n-10\r\n", "output": "-17/10\n"}, {"input": "0 0\r\n-1\r\n2\r\n", "output": "-1/2\n"}, {"input": "0 0\r\n1\r\n1\r\n", "output": "1/1\n"}, {"input": "0 0\r\n50\r\n20\r\n", "output": "5/2\n"}, {"input": "0 0\r\n20\r\n20\r\n", "output": "1/1\n"}, {"input": "0 0\r\n4\r\n-2\r\n", "output": "-2/1\n"}, {"input": "0 0\r\n4\r\n-6\r\n", "output": "-2/3\n"}, {"input": "0 0\r\n1\r\n-2\r\n", "output": "-1/2\n"}, {"input": "0 0\r\n4\r\n2\r\n", "output": "2/1\n"}, {"input": "0 0\r\n2\r\n-4\r\n", "output": "-1/2\n"}, {"input": "1 1\r\n4 1\r\n2 1\r\n", "output": "2/1\n"}, {"input": "2 2\r\n-13 1 3\r\n6 3 2\r\n", "output": "-13/6\n"}, {"input": "0 0\r\n5\r\n5\r\n", "output": "1/1\n"}, {"input": "0 0\r\n2\r\n-1\r\n", "output": "-2/1\n"}]
| false |
stdio
| null | true |
825/C
|
825
|
C
|
Python 3
|
TESTS
| 6 | 61 | 4,915,200 |
28971506
|
#!/bin/python3
import sys
n,k=map(int,input().split())
num=list(map(int,input().split()))
ans=0
if num[0]>2*k:
print(1)
else:
for i in range(1,n):
if num[i]>2*num[i-1] and num[i]>2*k:
ans=1
break
print (ans)
| 61 | 61 | 4,812,800 |
28607483
|
n,k = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
cnt = 0
for a in A:
while a > 2 * k:
cnt += 1
k *= 2
k = max(k, a)
print(cnt)
|
Educational Codeforces Round 25
|
ICPC
| 2,017 | 1 | 256 |
Multi-judge Solving
|
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 a1, a2, ..., an. He can solve these problems in arbitrary order. Though he can solve problem i with difficulty ai only if he had already solved some problem with difficulty $$d \geq \frac{a_i}{2}$$ (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 a1, a2, ..., an (1 ≤ ai ≤ 109).
|
Print minimum number of problems Makes should solve on other judges in order to solve all chosen problems on Decoforces.
| null |
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.
|
[{"input": "3 3\n2 1 9", "output": "1"}, {"input": "4 20\n10 3 6 3", "output": "0"}]
| 1,600 |
["greedy", "implementation"]
| 61 |
[{"input": "3 3\r\n2 1 9\r\n", "output": "1\r\n"}, {"input": "4 20\r\n10 3 6 3\r\n", "output": "0\r\n"}, {"input": "1 1000000000\r\n1\r\n", "output": "0\r\n"}, {"input": "1 1\r\n3\r\n", "output": "1\r\n"}, {"input": "50 100\r\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\r\n", "output": "0\r\n"}, {"input": "100 10\r\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\r\n", "output": "1\r\n"}, {"input": "2 1\r\n1 1000000000\r\n", "output": "29\r\n"}, {"input": "29 2\r\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\r\n", "output": "27\r\n"}, {"input": "1 1\r\n1000000000\r\n", "output": "29\r\n"}, {"input": "7 6\r\n4 20 16 14 3 17 4\r\n", "output": "1\r\n"}, {"input": "2 1\r\n3 6\r\n", "output": "1\r\n"}, {"input": "1 1\r\n20\r\n", "output": "4\r\n"}, {"input": "5 2\r\n86 81 53 25 18\r\n", "output": "4\r\n"}, {"input": "4 1\r\n88 55 14 39\r\n", "output": "4\r\n"}, {"input": "3 1\r\n2 3 6\r\n", "output": "0\r\n"}, {"input": "3 2\r\n4 9 18\r\n", "output": "1\r\n"}, {"input": "5 3\r\n6 6 6 13 27\r\n", "output": "2\r\n"}, {"input": "5 1\r\n23 8 83 26 18\r\n", "output": "4\r\n"}, {"input": "3 1\r\n4 5 6\r\n", "output": "1\r\n"}, {"input": "3 1\r\n1 3 6\r\n", "output": "1\r\n"}, {"input": "1 1\r\n2\r\n", "output": "0\r\n"}, {"input": "3 2\r\n4 5 6\r\n", "output": "0\r\n"}, {"input": "5 1\r\n100 200 400 1000 2000\r\n", "output": "7\r\n"}, {"input": "2 1\r\n1 4\r\n", "output": "1\r\n"}, {"input": "4 1\r\n2 4 8 32\r\n", "output": "1\r\n"}, {"input": "2 10\r\n21 42\r\n", "output": "1\r\n"}, {"input": "3 3\r\n1 7 13\r\n", "output": "1\r\n"}, {"input": "3 1\r\n1 4 6\r\n", "output": "1\r\n"}, {"input": "2 2\r\n2 8\r\n", "output": "1\r\n"}, {"input": "1 1\r\n4\r\n", "output": "1\r\n"}, {"input": "2 2\r\n8 16\r\n", "output": "1\r\n"}, {"input": "3 1\r\n4 8 16\r\n", "output": "1\r\n"}, {"input": "3 1\r\n3 6 9\r\n", "output": "1\r\n"}, {"input": "2 1\r\n4 8\r\n", "output": "1\r\n"}, {"input": "2 2\r\n7 14\r\n", "output": "1\r\n"}, {"input": "1 4\r\n9\r\n", "output": "1\r\n"}, {"input": "5 3\r\n1024 4096 16384 65536 536870913\r\n", "output": "24\r\n"}, {"input": "2 5\r\n10 11\r\n", "output": "0\r\n"}, {"input": "2 2\r\n3 6\r\n", "output": "0\r\n"}, {"input": "2 2\r\n8 11\r\n", "output": "1\r\n"}, {"input": "3 19905705\r\n263637263 417905394 108361057\r\n", "output": "3\r\n"}, {"input": "4 25\r\n100 11 1 13\r\n", "output": "1\r\n"}, {"input": "10 295206008\r\n67980321 440051990 883040288 135744260 96431758 242465794 576630162 972797687 356406646 547451696\r\n", "output": "0\r\n"}, {"input": "4 2\r\n45 44 35 38\r\n", "output": "4\r\n"}, {"input": "1 2\r\n9\r\n", "output": "2\r\n"}, {"input": "3 6\r\n13 26 52\r\n", "output": "1\r\n"}, {"input": "9 30111088\r\n824713578 11195876 458715185 731769293 680826358 189542586 550198537 860586039 101083021\r\n", "output": "2\r\n"}, {"input": "3 72014068\r\n430005292 807436976 828082746\r\n", "output": "2\r\n"}, {"input": "3 165219745\r\n737649884 652879952 506420386\r\n", "output": "1\r\n"}, {"input": "2 60669400\r\n95037700 337255240\r\n", "output": "1\r\n"}, {"input": "4 28\r\n34 1 86 90\r\n", "output": "1\r\n"}, {"input": "2 1\r\n5 10\r\n", "output": "2\r\n"}, {"input": "2 1\r\n4 1000000000\r\n", "output": "28\r\n"}, {"input": "2 1\r\n2 3\r\n", "output": "0\r\n"}, {"input": "2 1\r\n3 5\r\n", "output": "1\r\n"}, {"input": "3 3\r\n1 5 20\r\n", "output": "1\r\n"}, {"input": "9 1\r\n1 2 4 9 15 32 64 128 1024\r\n", "output": "4\r\n"}]
| false |
stdio
| null | true |
33/C
|
33
|
C
|
PyPy 3-64
|
TESTS
| 15 | 278 | 18,841,600 |
204088312
|
from logging import exception as ex
n = int(input())
a = list(map(int, input().split())) # original sequence
s1 = [] # commulative sum of a
for i, v in enumerate(a): s1.append(v + (s1[i-1] if i > 0 else 0))
mn = 0
p = -1 # pointer to the min value in s1
for i, v in enumerate(s1):
if v < mn: mn = v; p = i
a2 = [*a] # 'a' but after the first operation
if p < n - 1: # if p = n - 1: leave it for the next operation
for i in range(p + 1): a2[i] = -a2[i]
s2 = [*a] # commulative sum of a2 starting from the end
for i in range(n): s2[n - i - 1] = a2[n - i - 1] + (s2[n - i] if i > 0 else 0)
mn = 0
p2 = n # pointer to the min value in s2
for i in range(n):
if s2[n - i - 1] < mn: mn = s2[n - i - 1]; p2 = n - i - 1
a3 = [*a2] # 'a' but after the second operation
i = n - 1
while i >= p2: a3[i] = -a3[i]; i -= 1
print(sum(a3))
| 89 | 280 | 7,372,800 |
14919821
|
n = int(input())
values = list(map(int, input().split()))
best_infix = infix = 0
for x in values:
infix = max(0, infix + x)
best_infix = max(best_infix, infix)
print(2 * best_infix - sum(values))
|
Codeforces Beta Round 33 (Codeforces format)
|
CF
| 2,010 | 2 | 256 |
Wonderful Randomized Sum
|
Learn, learn and learn again — Valera has to do this every day. He is studying at mathematical school, where math is the main discipline. The mathematics teacher loves her discipline very much and tries to cultivate this love in children. That's why she always gives her students large and difficult homework. Despite that Valera is one of the best students, he failed to manage with the new homework. That's why he asks for your help. He has the following task. A sequence of n numbers is given. A prefix of a sequence is the part of the sequence (possibly empty), taken from the start of the sequence. A suffix of a sequence is the part of the sequence (possibly empty), taken from the end of the sequence. It is allowed to sequentially make two operations with the sequence. The first operation is to take some prefix of the sequence and multiply all numbers in this prefix by - 1. The second operation is to take some suffix and multiply all numbers in it by - 1. The chosen prefix and suffix may intersect. What is the maximum total sum of the sequence that can be obtained by applying the described operations?
|
The first line contains integer n (1 ≤ n ≤ 105) — amount of elements in the sequence. The second line contains n integers ai ( - 104 ≤ ai ≤ 104) — the sequence itself.
|
The first and the only line of the output should contain the answer to the problem.
| null | null |
[{"input": "3\n-1 -2 -3", "output": "6"}, {"input": "5\n-4 2 0 5 0", "output": "11"}, {"input": "5\n-1 10 -5 10 -2", "output": "18"}]
| 1,800 |
["greedy"]
| 89 |
[{"input": "3\r\n-1 -2 -3\r\n", "output": "6\r\n"}, {"input": "5\r\n-4 2 0 5 0\r\n", "output": "11\r\n"}, {"input": "5\r\n-1 10 -5 10 -2\r\n", "output": "18\r\n"}, {"input": "1\r\n-3\r\n", "output": "3\r\n"}, {"input": "4\r\n1 4 -5 -2\r\n", "output": "12\r\n"}, {"input": "7\r\n-17 6 5 0 1 4 -1\r\n", "output": "34\r\n"}, {"input": "3\r\n0 -2 3\r\n", "output": "5\r\n"}, {"input": "2\r\n0 3\r\n", "output": "3\r\n"}, {"input": "15\r\n14 0 -10 -5 0 19 -6 0 -11 -20 -18 -8 -3 19 -7\r\n", "output": "74\r\n"}, {"input": "15\r\n0 -35 32 24 0 27 10 0 -19 -38 30 -30 40 -3 22\r\n", "output": "130\r\n"}, {"input": "20\r\n0 2 3 1 0 3 -3 0 -1 0 2 -1 -1 3 0 0 1 -3 2 0\r\n", "output": "10\r\n"}, {"input": "100\r\n6 2 -3 6 -4 -6 -2 -1 -6 1 3 -4 -1 0 -3 1 -3 0 -2 -3 0 3 1 6 -5 0 4 -5 -5 -6 3 1 3 4 0 -1 3 -4 5 -1 -3 -2 -6 0 5 -6 -2 0 4 -4 -5 4 -2 0 -5 1 -5 0 5 -4 2 -3 -2 0 3 -6 3 2 -4 -3 5 5 1 -1 2 -6 6 0 2 -3 3 0 -1 -4 0 -6 0 0 -6 5 -4 1 6 -5 -1 -2 3 4 0 6\r\n", "output": "64\r\n"}, {"input": "30\r\n8 -1 3 -7 0 -1 9 3 0 0 3 -8 8 -8 9 -3 5 -9 -8 -10 4 -9 8 6 0 9 -6 1 5 -6\r\n", "output": "41\r\n"}, {"input": "1\r\n7500\r\n", "output": "7500\r\n"}, {"input": "2\r\n9944 -9293\r\n", "output": "19237\r\n"}, {"input": "3\r\n5 -5 7\r\n", "output": "7\r\n"}, {"input": "5\r\n-23 -11 -54 56 -40\r\n", "output": "184\r\n"}, {"input": "10\r\n-8 6 0 12 0 2 3 8 2 6\r\n", "output": "47\r\n"}, {"input": "8\r\n3 0 -5 -2 -4 0 -5 0\r\n", "output": "19\r\n"}, {"input": "16\r\n57 59 -27 24 28 -27 9 -90 3 -36 90 63 1 99 -46 50\r\n", "output": "257\r\n"}, {"input": "7\r\n2 -1 -2 -4 -3 0 -3\r\n", "output": "15\r\n"}, {"input": "8\r\n57 -82 -146 -13 -3 -115 55 -76\r\n", "output": "437\r\n"}, {"input": "6\r\n9721 6032 8572 9026 9563 7626\r\n", "output": "50540\r\n"}, {"input": "4\r\n26 9 -16 -24\r\n", "output": "75\r\n"}, {"input": "5\r\n-54 64 37 -71 -74\r\n", "output": "300\r\n"}, {"input": "100\r\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\r\n", "output": "0\r\n"}, {"input": "4\r\n-83 -87 42 -96\r\n", "output": "308\r\n"}, {"input": "8\r\n103 395 377 -205 -975 301 548 346\r\n", "output": "1500\r\n"}, {"input": "20\r\n18 1 10 0 14 17 -13 0 -20 -19 16 2 5 -2 4 9 1 16 12 4\r\n", "output": "75\r\n"}, {"input": "16\r\n-2 -11 -6 -2 -8 -2 0 3 -1 0 -5 2 -12 5 6 -9\r\n", "output": "64\r\n"}, {"input": "5\r\n81 26 21 28 88\r\n", "output": "244\r\n"}, {"input": "7\r\n2165 -8256 -9741 -9714 7347 5652 6199\r\n", "output": "44744\r\n"}, {"input": "8\r\n4609 9402 908 9322 5132 0 1962 1069\r\n", "output": "32404\r\n"}, {"input": "11\r\n100 233 -184 -200 -222 228 -385 -129 -126 -377 237\r\n", "output": "1491\r\n"}, {"input": "5\r\n-4 -4 -4 -4 -4\r\n", "output": "20\r\n"}, {"input": "5\r\n-7 17 2 -6 -1\r\n", "output": "33\r\n"}, {"input": "8\r\n-1 1 4 -5 -2 3 -10 3\r\n", "output": "17\r\n"}, {"input": "9\r\n1 2 -4 3 6 1 1 2 -8\r\n", "output": "22\r\n"}, {"input": "9\r\n1 1 2 -4 1 -4 2 1 1\r\n", "output": "7\r\n"}, {"input": "14\r\n1 1 1 1 -3 1 -5 -3 2 -3 1 1 1 1\r\n", "output": "11\r\n"}, {"input": "7\r\n-12 12 -12 13 -12 12 -12\r\n", "output": "37\r\n"}, {"input": "1\r\n2\r\n", "output": "2\r\n"}, {"input": "5\r\n-2 0 0 -4 1\r\n", "output": "7\r\n"}, {"input": "13\r\n-2 6 6 0 6 -17 6 5 0 1 4 -1 0\r\n", "output": "22\r\n"}]
| false |
stdio
| null | true |
245/E
|
245
|
E
|
PyPy 3
|
TESTS
| 19 | 280 | 0 |
76459792
|
def solve(s):
n = len(s)
if(n == 1):
return 1
else:
start = 0
prev = s[0]
ans = 0
f = 1
for i in range(1,n):
f = 1
if(s[i] == prev):
continue
else:
f = 0
ans = max(ans,i-start)
start = i
prev = s[i]
# print(ans)
if(f):
ans = max(ans,n-start)
start = i
prev = s[i]
return ans
def solve1(s):
st = []
ans = 0
maxx = 0
for i in s:
if(st):
ans = 0
if(i == '+'):
st.append('+')
else:
if(st):
st.pop()
else:
ans += 1
maxx = max(maxx,ans)
maxx = max(maxx,len(st))
# print(st)
maxx = max(maxx,len(st))
return maxx
l = input()
ans = solve(l)
ans1 = solve1(l)
print(max(ans,ans1))
| 30 | 92 | 0 |
4435266
|
#!/usr/bin/python3
inside = outside = 0
for c in list(input()):
if c == '+':
if outside:
outside -= 1
inside += 1
else:
if inside:
inside -= 1
outside += 1
print(inside + outside)
|
CROC-MBTU 2012, Elimination Round (ACM-ICPC)
|
ICPC
| 2,012 | 2 | 256 |
Mishap in Club
|
Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen.
On the burglary night Polycarpus kept a careful record of all club visitors. Each time a visitor entered the club, Polycarpus put down character "+" in his notes. Similarly, each time a visitor left the club, Polycarpus put character "-" in his notes. We know that all cases of going in and out happened consecutively, that is, no two events happened at the same time. Polycarpus doesn't remember whether there was somebody in the club at the moment when his shift begun and at the moment when it ended.
Right now the police wonders what minimum number of distinct people Polycarpus could have seen. Assume that he sees anybody coming in or out of the club. Each person could have come in or out an arbitrary number of times.
|
The only line of the input contains a sequence of characters "+" and "-", the characters are written one after another without any separators. The characters are written in the order, in which the corresponding events occurred. The given sequence has length from 1 to 300 characters, inclusive.
|
Print the sought minimum number of people
| null | null |
[{"input": "+-+-+", "output": "1"}, {"input": "---", "output": "3"}]
| 1,400 |
["greedy", "implementation"]
| 77 |
[{"input": "+-+-+\r\n", "output": "1\r\n"}, {"input": "---\r\n", "output": "3\r\n"}, {"input": "-\r\n", "output": "1\r\n"}, {"input": "--\r\n", "output": "2\r\n"}, {"input": "---\r\n", "output": "3\r\n"}, {"input": "----\r\n", "output": "4\r\n"}, {"input": "---+\r\n", "output": "3\r\n"}, {"input": "--+\r\n", "output": "2\r\n"}, {"input": "--+-\r\n", "output": "2\r\n"}, {"input": "--++\r\n", "output": "2\r\n"}, {"input": "-+\r\n", "output": "1\r\n"}, {"input": "-+-\r\n", "output": "1\r\n"}, {"input": "-+--\r\n", "output": "2\r\n"}, {"input": "-+-+\r\n", "output": "1\r\n"}, {"input": "-++\r\n", "output": "2\r\n"}, {"input": "-++-\r\n", "output": "2\r\n"}, {"input": "-+++\r\n", "output": "3\r\n"}, {"input": "+\r\n", "output": "1\r\n"}, {"input": "+-\r\n", "output": "1\r\n"}, {"input": "+--\r\n", "output": "2\r\n"}, {"input": "+---\r\n", "output": "3\r\n"}, {"input": "+--+\r\n", "output": "2\r\n"}, {"input": "+-+\r\n", "output": "1\r\n"}, {"input": "+-+-\r\n", "output": "1\r\n"}, {"input": "+-++\r\n", "output": "2\r\n"}, {"input": "++\r\n", "output": "2\r\n"}, {"input": "++-\r\n", "output": "2\r\n"}, {"input": "++--\r\n", "output": "2\r\n"}, {"input": "++-+\r\n", "output": "2\r\n"}, {"input": "+++\r\n", "output": "3\r\n"}, {"input": "+++-\r\n", "output": "3\r\n"}, {"input": "++++\r\n", "output": "4\r\n"}, {"input": "-+++--+-++--+-+--+-+\r\n", "output": "3\r\n"}, {"input": "++-++--+++++-+++++---+++-++-++-\r\n", "output": "12\r\n"}, {"input": "----+-+--++---++---++-+-----+--\r\n", "output": "11\r\n"}, {"input": "-------+-----+-+------+++-----+----+--++-\r\n", "output": "22\r\n"}, {"input": "-+++---+++++++++++++-++-++++++-++-+-+++-\r\n", "output": "22\r\n"}, {"input": "-------+--+------------+---+----+----+-+--+++----+-----------\r\n", "output": "39\r\n"}, {"input": "-++++-+++++++--+++++++++---++-+++++++++++++-+++++++++++++++-\r\n", "output": "42\r\n"}, {"input": "+-+-+-+-+-+-+-+-+-+-++--++-+--+-+-+-+-+-+-+-+-+-+-+-+-+-+-++-+-+--++--+-+-++-+--+-+++-+-+-+-+-+-+-+-+-++-++-+-+-+--+-+++-+-+-+-++-+-+-+-+-+-+-+-+-+--+-+-+-++++-+-+-+-+--+-++--+-+-+-+-+-++-+-+-+--+----\r\n", "output": "9\r\n"}, {"input": "++-+-+-+-+-+-+-+-++--+-++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-++--+-+-+-+-+-+-++-+--+-+++-+-++-++--+-+-+-+-+-+-+--+-+-+-+-+-+-+--+-+-+-+-+-++--++-+-+-+--+-+++-++--++--+-+---+-+-+++-+-+---+-+-+++-+-+-+-+-+-\r\n", "output": "7\r\n"}]
| false |
stdio
| null | true |
204/B
|
204
|
B
|
Python 3
|
TESTS
| 36 | 686 | 17,612,800 |
128172358
|
size = int(input())
fcards = []
bcards = []
for i in range(size):
front, back = input().split()
fcards.append(front)
bcards.append(back)
fcount = {}
bcount = {}
for i in range(size):
if fcards[i] not in fcount:
fcount[fcards[i]]= 1
else:
fcount[fcards[i]] += 1
if fcards[i] not in bcount:
bcount[fcards[i]] = 0
if bcards[i] not in fcount:
fcount[bcards[i]] = 0
if bcards[i] not in bcount:
bcount[bcards[i]] = 1
elif bcards[i]!=fcards[i]:
bcount[bcards[i]] += 1
total = {}
for i in range(size):
if fcards[i] not in total:
total[fcards[i]] = 1
else:
total[fcards[i]] = fcount[fcards[i]] + bcount[fcards[i]]
if bcards[i] not in total:
total[bcards[i]] = 1
else:
total[bcards[i]] = fcount[bcards[i]] + bcount[bcards[i]]
if max(fcount.values()) > size/2:
print("0")
elif max(total.values()) < size/2:
print("-1")
else:
maxele = ''
maxval = 0
flip = 0
req = size/2
for i in total:
if maxval < total[i]:
maxele = i
maxval = total[i]
if total[i] == maxval:
if(fcount[i] >= fcount[maxele]):
maxele = i
maxval = total[i]
availflip = bcount[maxele]
totalfront = fcount[maxele]
while totalfront < req:
flip += 1
totalfront += 1
print(flip)
| 90 | 466 | 27,238,400 |
163173392
|
import sys
input = sys.stdin.readline
M = int(1e9) + 7
def solve():
n = int(input())
d = dict()
for _ in range(n):
x, y = map(int, input().split())
if x not in d:
d[x] = [0, 0]
if y not in d:
d[y] = [0, 0]
d[x][0] += 1
if x != y:
d[y][1] += 1
half = (n + 1) // 2
ans = float('inf')
for i,j in d.values():
if i + j >= half:
ans = min(ans, max(0, half - i))
if ans == float('inf'):
return -1
return ans
for _ in range(1):
print(solve())
|
Codeforces Round 129 (Div. 1)
|
CF
| 2,012 | 2 | 256 |
Little Elephant and Cards
|
The Little Elephant loves to play with color cards.
He has n cards, each has exactly two colors (the color of the front side and the color of the back side). Initially, all the cards lay on the table with the front side up. In one move the Little Elephant can turn any card to the other side. The Little Elephant thinks that a set of cards on the table is funny if at least half of the cards have the same color (for each card the color of the upper side is considered).
Help the Little Elephant to find the minimum number of moves needed to make the set of n cards funny.
|
The first line contains a single integer n (1 ≤ n ≤ 105) — the number of the cards. The following n lines contain the description of all cards, one card per line. The cards are described by a pair of positive integers not exceeding 109 — colors of both sides. The first number in a line is the color of the front of the card, the second one — of the back. The color of the front of the card may coincide with the color of the back of the card.
The numbers in the lines are separated by single spaces.
|
On a single line print a single integer — the sought minimum number of moves. If it is impossible to make the set funny, print -1.
| null |
In the first sample there initially are three cards lying with colors 4, 4, 7. Since two of the three cards are of the same color 4, you do not need to change anything, so the answer is 0.
In the second sample, you can turn the first and the fourth cards. After that three of the five cards will be of color 7.
|
[{"input": "3\n4 7\n4 7\n7 4", "output": "0"}, {"input": "5\n4 7\n7 4\n2 11\n9 7\n1 1", "output": "2"}]
| 1,500 |
["binary search", "data structures"]
| 90 |
[{"input": "3\r\n4 7\r\n4 7\r\n7 4\r\n", "output": "0\r\n"}, {"input": "5\r\n4 7\r\n7 4\r\n2 11\r\n9 7\r\n1 1\r\n", "output": "2\r\n"}, {"input": "1\r\n1 1\r\n", "output": "0\r\n"}, {"input": "2\r\n1 1\r\n1 1\r\n", "output": "0\r\n"}, {"input": "7\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n5 6\r\n6 7\r\n7 8\r\n", "output": "-1\r\n"}, {"input": "2\r\n1 2\r\n2 1\r\n", "output": "0\r\n"}, {"input": "3\r\n7 7\r\n1 2\r\n2 1\r\n", "output": "1\r\n"}, {"input": "3\r\n1 1\r\n2 5\r\n3 6\r\n", "output": "-1\r\n"}, {"input": "4\r\n1000000000 1000000000\r\n999999999 1000000000\r\n999999997 999999998\r\n47 74\r\n", "output": "1\r\n"}, {"input": "6\r\n1 2\r\n3 1\r\n4 7\r\n4 1\r\n9 1\r\n7 2\r\n", "output": "2\r\n"}, {"input": "4\r\n1 2\r\n1 2\r\n2 1\r\n2 1\r\n", "output": "0\r\n"}, {"input": "7\r\n4 7\r\n7 4\r\n4 7\r\n1 1\r\n2 2\r\n3 3\r\n4 4\r\n", "output": "1\r\n"}, {"input": "10\r\n1000000000 999999999\r\n47 74\r\n47474 75785445\r\n8798878 458445\r\n1 2\r\n888888888 777777777\r\n99999999 1000000000\r\n9999999 1000000000\r\n999999 1000000000\r\n99999 1000000000\r\n", "output": "4\r\n"}, {"input": "10\r\n9 1000000000\r\n47 74\r\n47474 75785445\r\n8798878 458445\r\n1 2\r\n888888888 777777777\r\n99999999 1000000000\r\n9999999 1000000000\r\n999999 1000000000\r\n99999 1000000000\r\n", "output": "5\r\n"}, {"input": "10\r\n1 10\r\n1 10\r\n1 1\r\n7 8\r\n6 7\r\n9 5\r\n4 1\r\n2 3\r\n3 10\r\n2 8\r\n", "output": "-1\r\n"}, {"input": "10\r\n262253762 715261903\r\n414831157 8354405\r\n419984358 829693421\r\n376600467 175941985\r\n367533995 350629286\r\n681027822 408529849\r\n654503328 717740407\r\n539773033 704670473\r\n55322828 380422378\r\n46174018 186723478\r\n", "output": "-1\r\n"}, {"input": "10\r\n2 2\r\n1 1\r\n1 1\r\n1 2\r\n1 2\r\n2 2\r\n2 1\r\n1 1\r\n1 2\r\n1 1\r\n", "output": "0\r\n"}, {"input": "12\r\n1 1\r\n1 1\r\n1 1\r\n1 1\r\n1 1\r\n1 1\r\n1 1\r\n1 1\r\n1 1\r\n1 1\r\n1 1\r\n1 1\r\n", "output": "0\r\n"}, {"input": "7\r\n1 1\r\n1 1\r\n1 1\r\n2 3\r\n4 5\r\n6 7\r\n8 9\r\n", "output": "-1\r\n"}, {"input": "1\r\n1 2\r\n", "output": "0\r\n"}, {"input": "7\r\n1000000000 999999999\r\n1000000000 999999999\r\n1000000000 999999999\r\n1000000000 999999999\r\n1000000000 999999999\r\n1000000000 999999999\r\n1000000000 999999999\r\n", "output": "0\r\n"}, {"input": "2\r\n1 2\r\n2 3\r\n", "output": "0\r\n"}, {"input": "2\r\n47 74\r\n47 85874\r\n", "output": "0\r\n"}, {"input": "5\r\n5 8\r\n9 10\r\n5 17\r\n5 24\r\n1 147\r\n", "output": "0\r\n"}, {"input": "5\r\n1 7\r\n2 7\r\n3 7\r\n4 7\r\n5 7\r\n", "output": "3\r\n"}, {"input": "5\r\n1 10\r\n2 10\r\n3 10\r\n4 10\r\n5 10\r\n", "output": "3\r\n"}, {"input": "3\r\n2 1\r\n3 1\r\n4 1\r\n", "output": "2\r\n"}, {"input": "5\r\n1 2\r\n1 3\r\n4 1\r\n5 1\r\n6 7\r\n", "output": "1\r\n"}, {"input": "5\r\n4 7\r\n4 7\r\n2 7\r\n9 7\r\n1 1\r\n", "output": "3\r\n"}, {"input": "8\r\n1 2\r\n2 1\r\n2 1\r\n3 1\r\n4 2\r\n5 2\r\n6 2\r\n7 2\r\n", "output": "2\r\n"}, {"input": "3\r\n98751 197502\r\n296253 395004\r\n493755 592506\r\n", "output": "-1\r\n"}, {"input": "5\r\n1 5\r\n2 5\r\n3 5\r\n4 7\r\n2 5\r\n", "output": "3\r\n"}, {"input": "10\r\n1 10\r\n2 10\r\n3 10\r\n4 10\r\n5 10\r\n10 1\r\n10 2\r\n10 3\r\n10 4\r\n10 5\r\n", "output": "0\r\n"}, {"input": "7\r\n1 2\r\n1 2\r\n1 2\r\n3 1\r\n3 1\r\n3 1\r\n2 1\r\n", "output": "1\r\n"}, {"input": "5\r\n1 6\r\n2 6\r\n3 6\r\n4 6\r\n5 6\r\n", "output": "3\r\n"}, {"input": "5\r\n1 6\r\n2 6\r\n3 6\r\n4 4\r\n5 5\r\n", "output": "3\r\n"}, {"input": "5\r\n1 1\r\n1 1\r\n2 2\r\n2 2\r\n3 3\r\n", "output": "-1\r\n"}, {"input": "4\r\n1 5\r\n2 5\r\n3 5\r\n4 4\r\n", "output": "2\r\n"}]
| false |
stdio
| null | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.